aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorLuciano Coelho <coelho@ti.com>2011-12-08 06:08:10 -0500
committerLuciano Coelho <coelho@ti.com>2011-12-08 06:08:10 -0500
commitf589cf4f2ccdc670ef6d7c30d87f9a3e9dfa4d9d (patch)
tree4eddd981d5fb92e4570e6f1814a9aa192c5ad3e8 /drivers
parent0052d812599fb0327792b6c3f4257b26dcc13239 (diff)
parent1b04b739f4c1d053bebb29657fb69bf03f180a97 (diff)
Merge branch 'wl12xx-next' into for-linville
Diffstat (limited to 'drivers')
-rw-r--r--drivers/net/wireless/wl12xx/Kconfig10
-rw-r--r--drivers/net/wireless/wl12xx/Makefile3
-rw-r--r--drivers/net/wireless/wl12xx/acx.c146
-rw-r--r--drivers/net/wireless/wl12xx/acx.h83
-rw-r--r--drivers/net/wireless/wl12xx/boot.c15
-rw-r--r--drivers/net/wireless/wl12xx/cmd.c368
-rw-r--r--drivers/net/wireless/wl12xx/cmd.h50
-rw-r--r--drivers/net/wireless/wl12xx/conf.h4
-rw-r--r--drivers/net/wireless/wl12xx/debug.h101
-rw-r--r--drivers/net/wireless/wl12xx/debugfs.c141
-rw-r--r--drivers/net/wireless/wl12xx/event.c214
-rw-r--r--drivers/net/wireless/wl12xx/event.h3
-rw-r--r--drivers/net/wireless/wl12xx/init.c458
-rw-r--r--drivers/net/wireless/wl12xx/init.h7
-rw-r--r--drivers/net/wireless/wl12xx/io.c12
-rw-r--r--drivers/net/wireless/wl12xx/io.h23
-rw-r--r--drivers/net/wireless/wl12xx/main.c1949
-rw-r--r--drivers/net/wireless/wl12xx/ps.c56
-rw-r--r--drivers/net/wireless/wl12xx/ps.h9
-rw-r--r--drivers/net/wireless/wl12xx/reg.h2
-rw-r--r--drivers/net/wireless/wl12xx/rx.c34
-rw-r--r--drivers/net/wireless/wl12xx/scan.c102
-rw-r--r--drivers/net/wireless/wl12xx/scan.h8
-rw-r--r--drivers/net/wireless/wl12xx/sdio.c259
-rw-r--r--drivers/net/wireless/wl12xx/sdio_test.c543
-rw-r--r--drivers/net/wireless/wl12xx/spi.c214
-rw-r--r--drivers/net/wireless/wl12xx/testmode.c76
-rw-r--r--drivers/net/wireless/wl12xx/tx.c371
-rw-r--r--drivers/net/wireless/wl12xx/tx.h11
-rw-r--r--drivers/net/wireless/wl12xx/wl12xx.h377
-rw-r--r--drivers/net/wireless/wl12xx/wl12xx_80211.h5
-rw-r--r--drivers/net/wireless/wl12xx/wl12xx_platform_data.c4
32 files changed, 2942 insertions, 2716 deletions
diff --git a/drivers/net/wireless/wl12xx/Kconfig b/drivers/net/wireless/wl12xx/Kconfig
index 3fe388b87c2..af08c8609c6 100644
--- a/drivers/net/wireless/wl12xx/Kconfig
+++ b/drivers/net/wireless/wl12xx/Kconfig
@@ -42,16 +42,6 @@ config WL12XX_SDIO
42 If you choose to build a module, it'll be called wl12xx_sdio. 42 If you choose to build a module, it'll be called wl12xx_sdio.
43 Say N if unsure. 43 Say N if unsure.
44 44
45config WL12XX_SDIO_TEST
46 tristate "TI wl12xx SDIO testing support"
47 depends on WL12XX && MMC && WL12XX_SDIO
48 default n
49 ---help---
50 This module adds support for the SDIO bus testing with the
51 TI wl12xx chipsets. You probably don't want this unless you are
52 testing a new hardware platform. Select this if you want to test the
53 SDIO bus which is connected to the wl12xx chip.
54
55config WL12XX_PLATFORM_DATA 45config WL12XX_PLATFORM_DATA
56 bool 46 bool
57 depends on WL12XX_SDIO != n || WL1251_SDIO != n 47 depends on WL12XX_SDIO != n || WL1251_SDIO != n
diff --git a/drivers/net/wireless/wl12xx/Makefile b/drivers/net/wireless/wl12xx/Makefile
index 621b3483ca2..fe67262ba19 100644
--- a/drivers/net/wireless/wl12xx/Makefile
+++ b/drivers/net/wireless/wl12xx/Makefile
@@ -3,14 +3,11 @@ wl12xx-objs = main.o cmd.o io.o event.o tx.o rx.o ps.o acx.o \
3 3
4wl12xx_spi-objs = spi.o 4wl12xx_spi-objs = spi.o
5wl12xx_sdio-objs = sdio.o 5wl12xx_sdio-objs = sdio.o
6wl12xx_sdio_test-objs = sdio_test.o
7 6
8wl12xx-$(CONFIG_NL80211_TESTMODE) += testmode.o 7wl12xx-$(CONFIG_NL80211_TESTMODE) += testmode.o
9obj-$(CONFIG_WL12XX) += wl12xx.o 8obj-$(CONFIG_WL12XX) += wl12xx.o
10obj-$(CONFIG_WL12XX_SPI) += wl12xx_spi.o 9obj-$(CONFIG_WL12XX_SPI) += wl12xx_spi.o
11obj-$(CONFIG_WL12XX_SDIO) += wl12xx_sdio.o 10obj-$(CONFIG_WL12XX_SDIO) += wl12xx_sdio.o
12 11
13obj-$(CONFIG_WL12XX_SDIO_TEST) += wl12xx_sdio_test.o
14
15# small builtin driver bit 12# small builtin driver bit
16obj-$(CONFIG_WL12XX_PLATFORM_DATA) += wl12xx_platform_data.o 13obj-$(CONFIG_WL12XX_PLATFORM_DATA) += wl12xx_platform_data.o
diff --git a/drivers/net/wireless/wl12xx/acx.c b/drivers/net/wireless/wl12xx/acx.c
index ca044a74319..bde1d862bdd 100644
--- a/drivers/net/wireless/wl12xx/acx.c
+++ b/drivers/net/wireless/wl12xx/acx.c
@@ -29,11 +29,12 @@
29#include <linux/slab.h> 29#include <linux/slab.h>
30 30
31#include "wl12xx.h" 31#include "wl12xx.h"
32#include "debug.h"
32#include "wl12xx_80211.h" 33#include "wl12xx_80211.h"
33#include "reg.h" 34#include "reg.h"
34#include "ps.h" 35#include "ps.h"
35 36
36int wl1271_acx_wake_up_conditions(struct wl1271 *wl) 37int wl1271_acx_wake_up_conditions(struct wl1271 *wl, struct wl12xx_vif *wlvif)
37{ 38{
38 struct acx_wake_up_condition *wake_up; 39 struct acx_wake_up_condition *wake_up;
39 int ret; 40 int ret;
@@ -46,7 +47,7 @@ int wl1271_acx_wake_up_conditions(struct wl1271 *wl)
46 goto out; 47 goto out;
47 } 48 }
48 49
49 wake_up->role_id = wl->role_id; 50 wake_up->role_id = wlvif->role_id;
50 wake_up->wake_up_event = wl->conf.conn.wake_up_event; 51 wake_up->wake_up_event = wl->conf.conn.wake_up_event;
51 wake_up->listen_interval = wl->conf.conn.listen_interval; 52 wake_up->listen_interval = wl->conf.conn.listen_interval;
52 53
@@ -84,7 +85,8 @@ out:
84 return ret; 85 return ret;
85} 86}
86 87
87int wl1271_acx_tx_power(struct wl1271 *wl, int power) 88int wl1271_acx_tx_power(struct wl1271 *wl, struct wl12xx_vif *wlvif,
89 int power)
88{ 90{
89 struct acx_current_tx_power *acx; 91 struct acx_current_tx_power *acx;
90 int ret; 92 int ret;
@@ -100,7 +102,7 @@ int wl1271_acx_tx_power(struct wl1271 *wl, int power)
100 goto out; 102 goto out;
101 } 103 }
102 104
103 acx->role_id = wl->role_id; 105 acx->role_id = wlvif->role_id;
104 acx->current_tx_power = power * 10; 106 acx->current_tx_power = power * 10;
105 107
106 ret = wl1271_cmd_configure(wl, DOT11_CUR_TX_PWR, acx, sizeof(*acx)); 108 ret = wl1271_cmd_configure(wl, DOT11_CUR_TX_PWR, acx, sizeof(*acx));
@@ -114,7 +116,7 @@ out:
114 return ret; 116 return ret;
115} 117}
116 118
117int wl1271_acx_feature_cfg(struct wl1271 *wl) 119int wl1271_acx_feature_cfg(struct wl1271 *wl, struct wl12xx_vif *wlvif)
118{ 120{
119 struct acx_feature_config *feature; 121 struct acx_feature_config *feature;
120 int ret; 122 int ret;
@@ -128,7 +130,7 @@ int wl1271_acx_feature_cfg(struct wl1271 *wl)
128 } 130 }
129 131
130 /* DF_ENCRYPTION_DISABLE and DF_SNIFF_MODE_ENABLE are disabled */ 132 /* DF_ENCRYPTION_DISABLE and DF_SNIFF_MODE_ENABLE are disabled */
131 feature->role_id = wl->role_id; 133 feature->role_id = wlvif->role_id;
132 feature->data_flow_options = 0; 134 feature->data_flow_options = 0;
133 feature->options = 0; 135 feature->options = 0;
134 136
@@ -210,7 +212,8 @@ out:
210 return ret; 212 return ret;
211} 213}
212 214
213int wl1271_acx_slot(struct wl1271 *wl, enum acx_slot_type slot_time) 215int wl1271_acx_slot(struct wl1271 *wl, struct wl12xx_vif *wlvif,
216 enum acx_slot_type slot_time)
214{ 217{
215 struct acx_slot *slot; 218 struct acx_slot *slot;
216 int ret; 219 int ret;
@@ -223,7 +226,7 @@ int wl1271_acx_slot(struct wl1271 *wl, enum acx_slot_type slot_time)
223 goto out; 226 goto out;
224 } 227 }
225 228
226 slot->role_id = wl->role_id; 229 slot->role_id = wlvif->role_id;
227 slot->wone_index = STATION_WONE_INDEX; 230 slot->wone_index = STATION_WONE_INDEX;
228 slot->slot_time = slot_time; 231 slot->slot_time = slot_time;
229 232
@@ -238,8 +241,8 @@ out:
238 return ret; 241 return ret;
239} 242}
240 243
241int wl1271_acx_group_address_tbl(struct wl1271 *wl, bool enable, 244int wl1271_acx_group_address_tbl(struct wl1271 *wl, struct wl12xx_vif *wlvif,
242 void *mc_list, u32 mc_list_len) 245 bool enable, void *mc_list, u32 mc_list_len)
243{ 246{
244 struct acx_dot11_grp_addr_tbl *acx; 247 struct acx_dot11_grp_addr_tbl *acx;
245 int ret; 248 int ret;
@@ -253,7 +256,7 @@ int wl1271_acx_group_address_tbl(struct wl1271 *wl, bool enable,
253 } 256 }
254 257
255 /* MAC filtering */ 258 /* MAC filtering */
256 acx->role_id = wl->role_id; 259 acx->role_id = wlvif->role_id;
257 acx->enabled = enable; 260 acx->enabled = enable;
258 acx->num_groups = mc_list_len; 261 acx->num_groups = mc_list_len;
259 memcpy(acx->mac_table, mc_list, mc_list_len * ETH_ALEN); 262 memcpy(acx->mac_table, mc_list, mc_list_len * ETH_ALEN);
@@ -270,7 +273,8 @@ out:
270 return ret; 273 return ret;
271} 274}
272 275
273int wl1271_acx_service_period_timeout(struct wl1271 *wl) 276int wl1271_acx_service_period_timeout(struct wl1271 *wl,
277 struct wl12xx_vif *wlvif)
274{ 278{
275 struct acx_rx_timeout *rx_timeout; 279 struct acx_rx_timeout *rx_timeout;
276 int ret; 280 int ret;
@@ -283,7 +287,7 @@ int wl1271_acx_service_period_timeout(struct wl1271 *wl)
283 287
284 wl1271_debug(DEBUG_ACX, "acx service period timeout"); 288 wl1271_debug(DEBUG_ACX, "acx service period timeout");
285 289
286 rx_timeout->role_id = wl->role_id; 290 rx_timeout->role_id = wlvif->role_id;
287 rx_timeout->ps_poll_timeout = cpu_to_le16(wl->conf.rx.ps_poll_timeout); 291 rx_timeout->ps_poll_timeout = cpu_to_le16(wl->conf.rx.ps_poll_timeout);
288 rx_timeout->upsd_timeout = cpu_to_le16(wl->conf.rx.upsd_timeout); 292 rx_timeout->upsd_timeout = cpu_to_le16(wl->conf.rx.upsd_timeout);
289 293
@@ -300,7 +304,8 @@ out:
300 return ret; 304 return ret;
301} 305}
302 306
303int wl1271_acx_rts_threshold(struct wl1271 *wl, u32 rts_threshold) 307int wl1271_acx_rts_threshold(struct wl1271 *wl, struct wl12xx_vif *wlvif,
308 u32 rts_threshold)
304{ 309{
305 struct acx_rts_threshold *rts; 310 struct acx_rts_threshold *rts;
306 int ret; 311 int ret;
@@ -320,7 +325,7 @@ int wl1271_acx_rts_threshold(struct wl1271 *wl, u32 rts_threshold)
320 goto out; 325 goto out;
321 } 326 }
322 327
323 rts->role_id = wl->role_id; 328 rts->role_id = wlvif->role_id;
324 rts->threshold = cpu_to_le16((u16)rts_threshold); 329 rts->threshold = cpu_to_le16((u16)rts_threshold);
325 330
326 ret = wl1271_cmd_configure(wl, DOT11_RTS_THRESHOLD, rts, sizeof(*rts)); 331 ret = wl1271_cmd_configure(wl, DOT11_RTS_THRESHOLD, rts, sizeof(*rts));
@@ -363,7 +368,8 @@ out:
363 return ret; 368 return ret;
364} 369}
365 370
366int wl1271_acx_beacon_filter_opt(struct wl1271 *wl, bool enable_filter) 371int wl1271_acx_beacon_filter_opt(struct wl1271 *wl, struct wl12xx_vif *wlvif,
372 bool enable_filter)
367{ 373{
368 struct acx_beacon_filter_option *beacon_filter = NULL; 374 struct acx_beacon_filter_option *beacon_filter = NULL;
369 int ret = 0; 375 int ret = 0;
@@ -380,7 +386,7 @@ int wl1271_acx_beacon_filter_opt(struct wl1271 *wl, bool enable_filter)
380 goto out; 386 goto out;
381 } 387 }
382 388
383 beacon_filter->role_id = wl->role_id; 389 beacon_filter->role_id = wlvif->role_id;
384 beacon_filter->enable = enable_filter; 390 beacon_filter->enable = enable_filter;
385 391
386 /* 392 /*
@@ -401,7 +407,8 @@ out:
401 return ret; 407 return ret;
402} 408}
403 409
404int wl1271_acx_beacon_filter_table(struct wl1271 *wl) 410int wl1271_acx_beacon_filter_table(struct wl1271 *wl,
411 struct wl12xx_vif *wlvif)
405{ 412{
406 struct acx_beacon_filter_ie_table *ie_table; 413 struct acx_beacon_filter_ie_table *ie_table;
407 int i, idx = 0; 414 int i, idx = 0;
@@ -417,7 +424,7 @@ int wl1271_acx_beacon_filter_table(struct wl1271 *wl)
417 } 424 }
418 425
419 /* configure default beacon pass-through rules */ 426 /* configure default beacon pass-through rules */
420 ie_table->role_id = wl->role_id; 427 ie_table->role_id = wlvif->role_id;
421 ie_table->num_ie = 0; 428 ie_table->num_ie = 0;
422 for (i = 0; i < wl->conf.conn.bcn_filt_ie_count; i++) { 429 for (i = 0; i < wl->conf.conn.bcn_filt_ie_count; i++) {
423 struct conf_bcn_filt_rule *r = &(wl->conf.conn.bcn_filt_ie[i]); 430 struct conf_bcn_filt_rule *r = &(wl->conf.conn.bcn_filt_ie[i]);
@@ -458,7 +465,8 @@ out:
458 465
459#define ACX_CONN_MONIT_DISABLE_VALUE 0xffffffff 466#define ACX_CONN_MONIT_DISABLE_VALUE 0xffffffff
460 467
461int wl1271_acx_conn_monit_params(struct wl1271 *wl, bool enable) 468int wl1271_acx_conn_monit_params(struct wl1271 *wl, struct wl12xx_vif *wlvif,
469 bool enable)
462{ 470{
463 struct acx_conn_monit_params *acx; 471 struct acx_conn_monit_params *acx;
464 u32 threshold = ACX_CONN_MONIT_DISABLE_VALUE; 472 u32 threshold = ACX_CONN_MONIT_DISABLE_VALUE;
@@ -479,7 +487,7 @@ int wl1271_acx_conn_monit_params(struct wl1271 *wl, bool enable)
479 timeout = wl->conf.conn.bss_lose_timeout; 487 timeout = wl->conf.conn.bss_lose_timeout;
480 } 488 }
481 489
482 acx->role_id = wl->role_id; 490 acx->role_id = wlvif->role_id;
483 acx->synch_fail_thold = cpu_to_le32(threshold); 491 acx->synch_fail_thold = cpu_to_le32(threshold);
484 acx->bss_lose_timeout = cpu_to_le32(timeout); 492 acx->bss_lose_timeout = cpu_to_le32(timeout);
485 493
@@ -582,7 +590,7 @@ out:
582 return ret; 590 return ret;
583} 591}
584 592
585int wl1271_acx_bcn_dtim_options(struct wl1271 *wl) 593int wl1271_acx_bcn_dtim_options(struct wl1271 *wl, struct wl12xx_vif *wlvif)
586{ 594{
587 struct acx_beacon_broadcast *bb; 595 struct acx_beacon_broadcast *bb;
588 int ret; 596 int ret;
@@ -595,7 +603,7 @@ int wl1271_acx_bcn_dtim_options(struct wl1271 *wl)
595 goto out; 603 goto out;
596 } 604 }
597 605
598 bb->role_id = wl->role_id; 606 bb->role_id = wlvif->role_id;
599 bb->beacon_rx_timeout = cpu_to_le16(wl->conf.conn.beacon_rx_timeout); 607 bb->beacon_rx_timeout = cpu_to_le16(wl->conf.conn.beacon_rx_timeout);
600 bb->broadcast_timeout = cpu_to_le16(wl->conf.conn.broadcast_timeout); 608 bb->broadcast_timeout = cpu_to_le16(wl->conf.conn.broadcast_timeout);
601 bb->rx_broadcast_in_ps = wl->conf.conn.rx_broadcast_in_ps; 609 bb->rx_broadcast_in_ps = wl->conf.conn.rx_broadcast_in_ps;
@@ -612,7 +620,7 @@ out:
612 return ret; 620 return ret;
613} 621}
614 622
615int wl1271_acx_aid(struct wl1271 *wl, u16 aid) 623int wl1271_acx_aid(struct wl1271 *wl, struct wl12xx_vif *wlvif, u16 aid)
616{ 624{
617 struct acx_aid *acx_aid; 625 struct acx_aid *acx_aid;
618 int ret; 626 int ret;
@@ -625,7 +633,7 @@ int wl1271_acx_aid(struct wl1271 *wl, u16 aid)
625 goto out; 633 goto out;
626 } 634 }
627 635
628 acx_aid->role_id = wl->role_id; 636 acx_aid->role_id = wlvif->role_id;
629 acx_aid->aid = cpu_to_le16(aid); 637 acx_aid->aid = cpu_to_le16(aid);
630 638
631 ret = wl1271_cmd_configure(wl, ACX_AID, acx_aid, sizeof(*acx_aid)); 639 ret = wl1271_cmd_configure(wl, ACX_AID, acx_aid, sizeof(*acx_aid));
@@ -668,7 +676,8 @@ out:
668 return ret; 676 return ret;
669} 677}
670 678
671int wl1271_acx_set_preamble(struct wl1271 *wl, enum acx_preamble_type preamble) 679int wl1271_acx_set_preamble(struct wl1271 *wl, struct wl12xx_vif *wlvif,
680 enum acx_preamble_type preamble)
672{ 681{
673 struct acx_preamble *acx; 682 struct acx_preamble *acx;
674 int ret; 683 int ret;
@@ -681,7 +690,7 @@ int wl1271_acx_set_preamble(struct wl1271 *wl, enum acx_preamble_type preamble)
681 goto out; 690 goto out;
682 } 691 }
683 692
684 acx->role_id = wl->role_id; 693 acx->role_id = wlvif->role_id;
685 acx->preamble = preamble; 694 acx->preamble = preamble;
686 695
687 ret = wl1271_cmd_configure(wl, ACX_PREAMBLE_TYPE, acx, sizeof(*acx)); 696 ret = wl1271_cmd_configure(wl, ACX_PREAMBLE_TYPE, acx, sizeof(*acx));
@@ -695,7 +704,7 @@ out:
695 return ret; 704 return ret;
696} 705}
697 706
698int wl1271_acx_cts_protect(struct wl1271 *wl, 707int wl1271_acx_cts_protect(struct wl1271 *wl, struct wl12xx_vif *wlvif,
699 enum acx_ctsprotect_type ctsprotect) 708 enum acx_ctsprotect_type ctsprotect)
700{ 709{
701 struct acx_ctsprotect *acx; 710 struct acx_ctsprotect *acx;
@@ -709,7 +718,7 @@ int wl1271_acx_cts_protect(struct wl1271 *wl,
709 goto out; 718 goto out;
710 } 719 }
711 720
712 acx->role_id = wl->role_id; 721 acx->role_id = wlvif->role_id;
713 acx->ctsprotect = ctsprotect; 722 acx->ctsprotect = ctsprotect;
714 723
715 ret = wl1271_cmd_configure(wl, ACX_CTS_PROTECTION, acx, sizeof(*acx)); 724 ret = wl1271_cmd_configure(wl, ACX_CTS_PROTECTION, acx, sizeof(*acx));
@@ -739,7 +748,7 @@ int wl1271_acx_statistics(struct wl1271 *wl, struct acx_statistics *stats)
739 return 0; 748 return 0;
740} 749}
741 750
742int wl1271_acx_sta_rate_policies(struct wl1271 *wl) 751int wl1271_acx_sta_rate_policies(struct wl1271 *wl, struct wl12xx_vif *wlvif)
743{ 752{
744 struct acx_rate_policy *acx; 753 struct acx_rate_policy *acx;
745 struct conf_tx_rate_class *c = &wl->conf.tx.sta_rc_conf; 754 struct conf_tx_rate_class *c = &wl->conf.tx.sta_rc_conf;
@@ -755,11 +764,11 @@ int wl1271_acx_sta_rate_policies(struct wl1271 *wl)
755 } 764 }
756 765
757 wl1271_debug(DEBUG_ACX, "basic_rate: 0x%x, full_rate: 0x%x", 766 wl1271_debug(DEBUG_ACX, "basic_rate: 0x%x, full_rate: 0x%x",
758 wl->basic_rate, wl->rate_set); 767 wlvif->basic_rate, wlvif->rate_set);
759 768
760 /* configure one basic rate class */ 769 /* configure one basic rate class */
761 acx->rate_policy_idx = cpu_to_le32(ACX_TX_BASIC_RATE); 770 acx->rate_policy_idx = cpu_to_le32(wlvif->sta.basic_rate_idx);
762 acx->rate_policy.enabled_rates = cpu_to_le32(wl->basic_rate); 771 acx->rate_policy.enabled_rates = cpu_to_le32(wlvif->basic_rate);
763 acx->rate_policy.short_retry_limit = c->short_retry_limit; 772 acx->rate_policy.short_retry_limit = c->short_retry_limit;
764 acx->rate_policy.long_retry_limit = c->long_retry_limit; 773 acx->rate_policy.long_retry_limit = c->long_retry_limit;
765 acx->rate_policy.aflags = c->aflags; 774 acx->rate_policy.aflags = c->aflags;
@@ -771,8 +780,8 @@ int wl1271_acx_sta_rate_policies(struct wl1271 *wl)
771 } 780 }
772 781
773 /* configure one AP supported rate class */ 782 /* configure one AP supported rate class */
774 acx->rate_policy_idx = cpu_to_le32(ACX_TX_AP_FULL_RATE); 783 acx->rate_policy_idx = cpu_to_le32(wlvif->sta.ap_rate_idx);
775 acx->rate_policy.enabled_rates = cpu_to_le32(wl->rate_set); 784 acx->rate_policy.enabled_rates = cpu_to_le32(wlvif->rate_set);
776 acx->rate_policy.short_retry_limit = c->short_retry_limit; 785 acx->rate_policy.short_retry_limit = c->short_retry_limit;
777 acx->rate_policy.long_retry_limit = c->long_retry_limit; 786 acx->rate_policy.long_retry_limit = c->long_retry_limit;
778 acx->rate_policy.aflags = c->aflags; 787 acx->rate_policy.aflags = c->aflags;
@@ -788,7 +797,7 @@ int wl1271_acx_sta_rate_policies(struct wl1271 *wl)
788 * (p2p packets should always go out with OFDM rates, even 797 * (p2p packets should always go out with OFDM rates, even
789 * if we are currently connected to 11b AP) 798 * if we are currently connected to 11b AP)
790 */ 799 */
791 acx->rate_policy_idx = cpu_to_le32(ACX_TX_BASIC_RATE_P2P); 800 acx->rate_policy_idx = cpu_to_le32(wlvif->sta.p2p_rate_idx);
792 acx->rate_policy.enabled_rates = 801 acx->rate_policy.enabled_rates =
793 cpu_to_le32(CONF_TX_RATE_MASK_BASIC_P2P); 802 cpu_to_le32(CONF_TX_RATE_MASK_BASIC_P2P);
794 acx->rate_policy.short_retry_limit = c->short_retry_limit; 803 acx->rate_policy.short_retry_limit = c->short_retry_limit;
@@ -839,8 +848,8 @@ out:
839 return ret; 848 return ret;
840} 849}
841 850
842int wl1271_acx_ac_cfg(struct wl1271 *wl, u8 ac, u8 cw_min, u16 cw_max, 851int wl1271_acx_ac_cfg(struct wl1271 *wl, struct wl12xx_vif *wlvif,
843 u8 aifsn, u16 txop) 852 u8 ac, u8 cw_min, u16 cw_max, u8 aifsn, u16 txop)
844{ 853{
845 struct acx_ac_cfg *acx; 854 struct acx_ac_cfg *acx;
846 int ret = 0; 855 int ret = 0;
@@ -855,7 +864,7 @@ int wl1271_acx_ac_cfg(struct wl1271 *wl, u8 ac, u8 cw_min, u16 cw_max,
855 goto out; 864 goto out;
856 } 865 }
857 866
858 acx->role_id = wl->role_id; 867 acx->role_id = wlvif->role_id;
859 acx->ac = ac; 868 acx->ac = ac;
860 acx->cw_min = cw_min; 869 acx->cw_min = cw_min;
861 acx->cw_max = cpu_to_le16(cw_max); 870 acx->cw_max = cpu_to_le16(cw_max);
@@ -873,7 +882,8 @@ out:
873 return ret; 882 return ret;
874} 883}
875 884
876int wl1271_acx_tid_cfg(struct wl1271 *wl, u8 queue_id, u8 channel_type, 885int wl1271_acx_tid_cfg(struct wl1271 *wl, struct wl12xx_vif *wlvif,
886 u8 queue_id, u8 channel_type,
877 u8 tsid, u8 ps_scheme, u8 ack_policy, 887 u8 tsid, u8 ps_scheme, u8 ack_policy,
878 u32 apsd_conf0, u32 apsd_conf1) 888 u32 apsd_conf0, u32 apsd_conf1)
879{ 889{
@@ -889,7 +899,7 @@ int wl1271_acx_tid_cfg(struct wl1271 *wl, u8 queue_id, u8 channel_type,
889 goto out; 899 goto out;
890 } 900 }
891 901
892 acx->role_id = wl->role_id; 902 acx->role_id = wlvif->role_id;
893 acx->queue_id = queue_id; 903 acx->queue_id = queue_id;
894 acx->channel_type = channel_type; 904 acx->channel_type = channel_type;
895 acx->tsid = tsid; 905 acx->tsid = tsid;
@@ -1098,7 +1108,8 @@ out:
1098 return ret; 1108 return ret;
1099} 1109}
1100 1110
1101int wl1271_acx_bet_enable(struct wl1271 *wl, bool enable) 1111int wl1271_acx_bet_enable(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1112 bool enable)
1102{ 1113{
1103 struct wl1271_acx_bet_enable *acx = NULL; 1114 struct wl1271_acx_bet_enable *acx = NULL;
1104 int ret = 0; 1115 int ret = 0;
@@ -1114,7 +1125,7 @@ int wl1271_acx_bet_enable(struct wl1271 *wl, bool enable)
1114 goto out; 1125 goto out;
1115 } 1126 }
1116 1127
1117 acx->role_id = wl->role_id; 1128 acx->role_id = wlvif->role_id;
1118 acx->enable = enable ? CONF_BET_MODE_ENABLE : CONF_BET_MODE_DISABLE; 1129 acx->enable = enable ? CONF_BET_MODE_ENABLE : CONF_BET_MODE_DISABLE;
1119 acx->max_consecutive = wl->conf.conn.bet_max_consecutive; 1130 acx->max_consecutive = wl->conf.conn.bet_max_consecutive;
1120 1131
@@ -1129,7 +1140,8 @@ out:
1129 return ret; 1140 return ret;
1130} 1141}
1131 1142
1132int wl1271_acx_arp_ip_filter(struct wl1271 *wl, u8 enable, __be32 address) 1143int wl1271_acx_arp_ip_filter(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1144 u8 enable, __be32 address)
1133{ 1145{
1134 struct wl1271_acx_arp_filter *acx; 1146 struct wl1271_acx_arp_filter *acx;
1135 int ret; 1147 int ret;
@@ -1142,7 +1154,7 @@ int wl1271_acx_arp_ip_filter(struct wl1271 *wl, u8 enable, __be32 address)
1142 goto out; 1154 goto out;
1143 } 1155 }
1144 1156
1145 acx->role_id = wl->role_id; 1157 acx->role_id = wlvif->role_id;
1146 acx->version = ACX_IPV4_VERSION; 1158 acx->version = ACX_IPV4_VERSION;
1147 acx->enable = enable; 1159 acx->enable = enable;
1148 1160
@@ -1189,7 +1201,8 @@ out:
1189 return ret; 1201 return ret;
1190} 1202}
1191 1203
1192int wl1271_acx_keep_alive_mode(struct wl1271 *wl, bool enable) 1204int wl1271_acx_keep_alive_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1205 bool enable)
1193{ 1206{
1194 struct wl1271_acx_keep_alive_mode *acx = NULL; 1207 struct wl1271_acx_keep_alive_mode *acx = NULL;
1195 int ret = 0; 1208 int ret = 0;
@@ -1202,7 +1215,7 @@ int wl1271_acx_keep_alive_mode(struct wl1271 *wl, bool enable)
1202 goto out; 1215 goto out;
1203 } 1216 }
1204 1217
1205 acx->role_id = wl->role_id; 1218 acx->role_id = wlvif->role_id;
1206 acx->enabled = enable; 1219 acx->enabled = enable;
1207 1220
1208 ret = wl1271_cmd_configure(wl, ACX_KEEP_ALIVE_MODE, acx, sizeof(*acx)); 1221 ret = wl1271_cmd_configure(wl, ACX_KEEP_ALIVE_MODE, acx, sizeof(*acx));
@@ -1216,7 +1229,8 @@ out:
1216 return ret; 1229 return ret;
1217} 1230}
1218 1231
1219int wl1271_acx_keep_alive_config(struct wl1271 *wl, u8 index, u8 tpl_valid) 1232int wl1271_acx_keep_alive_config(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1233 u8 index, u8 tpl_valid)
1220{ 1234{
1221 struct wl1271_acx_keep_alive_config *acx = NULL; 1235 struct wl1271_acx_keep_alive_config *acx = NULL;
1222 int ret = 0; 1236 int ret = 0;
@@ -1229,7 +1243,7 @@ int wl1271_acx_keep_alive_config(struct wl1271 *wl, u8 index, u8 tpl_valid)
1229 goto out; 1243 goto out;
1230 } 1244 }
1231 1245
1232 acx->role_id = wl->role_id; 1246 acx->role_id = wlvif->role_id;
1233 acx->period = cpu_to_le32(wl->conf.conn.keep_alive_interval); 1247 acx->period = cpu_to_le32(wl->conf.conn.keep_alive_interval);
1234 acx->index = index; 1248 acx->index = index;
1235 acx->tpl_validation = tpl_valid; 1249 acx->tpl_validation = tpl_valid;
@@ -1247,8 +1261,8 @@ out:
1247 return ret; 1261 return ret;
1248} 1262}
1249 1263
1250int wl1271_acx_rssi_snr_trigger(struct wl1271 *wl, bool enable, 1264int wl1271_acx_rssi_snr_trigger(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1251 s16 thold, u8 hyst) 1265 bool enable, s16 thold, u8 hyst)
1252{ 1266{
1253 struct wl1271_acx_rssi_snr_trigger *acx = NULL; 1267 struct wl1271_acx_rssi_snr_trigger *acx = NULL;
1254 int ret = 0; 1268 int ret = 0;
@@ -1261,9 +1275,9 @@ int wl1271_acx_rssi_snr_trigger(struct wl1271 *wl, bool enable,
1261 goto out; 1275 goto out;
1262 } 1276 }
1263 1277
1264 wl->last_rssi_event = -1; 1278 wlvif->last_rssi_event = -1;
1265 1279
1266 acx->role_id = wl->role_id; 1280 acx->role_id = wlvif->role_id;
1267 acx->pacing = cpu_to_le16(wl->conf.roam_trigger.trigger_pacing); 1281 acx->pacing = cpu_to_le16(wl->conf.roam_trigger.trigger_pacing);
1268 acx->metric = WL1271_ACX_TRIG_METRIC_RSSI_BEACON; 1282 acx->metric = WL1271_ACX_TRIG_METRIC_RSSI_BEACON;
1269 acx->type = WL1271_ACX_TRIG_TYPE_EDGE; 1283 acx->type = WL1271_ACX_TRIG_TYPE_EDGE;
@@ -1288,7 +1302,8 @@ out:
1288 return ret; 1302 return ret;
1289} 1303}
1290 1304
1291int wl1271_acx_rssi_snr_avg_weights(struct wl1271 *wl) 1305int wl1271_acx_rssi_snr_avg_weights(struct wl1271 *wl,
1306 struct wl12xx_vif *wlvif)
1292{ 1307{
1293 struct wl1271_acx_rssi_snr_avg_weights *acx = NULL; 1308 struct wl1271_acx_rssi_snr_avg_weights *acx = NULL;
1294 struct conf_roam_trigger_settings *c = &wl->conf.roam_trigger; 1309 struct conf_roam_trigger_settings *c = &wl->conf.roam_trigger;
@@ -1302,7 +1317,7 @@ int wl1271_acx_rssi_snr_avg_weights(struct wl1271 *wl)
1302 goto out; 1317 goto out;
1303 } 1318 }
1304 1319
1305 acx->role_id = wl->role_id; 1320 acx->role_id = wlvif->role_id;
1306 acx->rssi_beacon = c->avg_weight_rssi_beacon; 1321 acx->rssi_beacon = c->avg_weight_rssi_beacon;
1307 acx->rssi_data = c->avg_weight_rssi_data; 1322 acx->rssi_data = c->avg_weight_rssi_data;
1308 acx->snr_beacon = c->avg_weight_snr_beacon; 1323 acx->snr_beacon = c->avg_weight_snr_beacon;
@@ -1367,6 +1382,7 @@ out:
1367} 1382}
1368 1383
1369int wl1271_acx_set_ht_information(struct wl1271 *wl, 1384int wl1271_acx_set_ht_information(struct wl1271 *wl,
1385 struct wl12xx_vif *wlvif,
1370 u16 ht_operation_mode) 1386 u16 ht_operation_mode)
1371{ 1387{
1372 struct wl1271_acx_ht_information *acx; 1388 struct wl1271_acx_ht_information *acx;
@@ -1380,7 +1396,7 @@ int wl1271_acx_set_ht_information(struct wl1271 *wl,
1380 goto out; 1396 goto out;
1381 } 1397 }
1382 1398
1383 acx->role_id = wl->role_id; 1399 acx->role_id = wlvif->role_id;
1384 acx->ht_protection = 1400 acx->ht_protection =
1385 (u8)(ht_operation_mode & IEEE80211_HT_OP_MODE_PROTECTION); 1401 (u8)(ht_operation_mode & IEEE80211_HT_OP_MODE_PROTECTION);
1386 acx->rifs_mode = 0; 1402 acx->rifs_mode = 0;
@@ -1402,7 +1418,8 @@ out:
1402} 1418}
1403 1419
1404/* Configure BA session initiator/receiver parameters setting in the FW. */ 1420/* Configure BA session initiator/receiver parameters setting in the FW. */
1405int wl12xx_acx_set_ba_initiator_policy(struct wl1271 *wl) 1421int wl12xx_acx_set_ba_initiator_policy(struct wl1271 *wl,
1422 struct wl12xx_vif *wlvif)
1406{ 1423{
1407 struct wl1271_acx_ba_initiator_policy *acx; 1424 struct wl1271_acx_ba_initiator_policy *acx;
1408 int ret; 1425 int ret;
@@ -1416,7 +1433,7 @@ int wl12xx_acx_set_ba_initiator_policy(struct wl1271 *wl)
1416 } 1433 }
1417 1434
1418 /* set for the current role */ 1435 /* set for the current role */
1419 acx->role_id = wl->role_id; 1436 acx->role_id = wlvif->role_id;
1420 acx->tid_bitmap = wl->conf.ht.tx_ba_tid_bitmap; 1437 acx->tid_bitmap = wl->conf.ht.tx_ba_tid_bitmap;
1421 acx->win_size = wl->conf.ht.tx_ba_win_size; 1438 acx->win_size = wl->conf.ht.tx_ba_win_size;
1422 acx->inactivity_timeout = wl->conf.ht.inactivity_timeout; 1439 acx->inactivity_timeout = wl->conf.ht.inactivity_timeout;
@@ -1494,7 +1511,8 @@ out:
1494 return ret; 1511 return ret;
1495} 1512}
1496 1513
1497int wl1271_acx_ps_rx_streaming(struct wl1271 *wl, bool enable) 1514int wl1271_acx_ps_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1515 bool enable)
1498{ 1516{
1499 struct wl1271_acx_ps_rx_streaming *rx_streaming; 1517 struct wl1271_acx_ps_rx_streaming *rx_streaming;
1500 u32 conf_queues, enable_queues; 1518 u32 conf_queues, enable_queues;
@@ -1523,7 +1541,7 @@ int wl1271_acx_ps_rx_streaming(struct wl1271 *wl, bool enable)
1523 if (!(conf_queues & BIT(i))) 1541 if (!(conf_queues & BIT(i)))
1524 continue; 1542 continue;
1525 1543
1526 rx_streaming->role_id = wl->role_id; 1544 rx_streaming->role_id = wlvif->role_id;
1527 rx_streaming->tid = i; 1545 rx_streaming->tid = i;
1528 rx_streaming->enable = enable_queues & BIT(i); 1546 rx_streaming->enable = enable_queues & BIT(i);
1529 rx_streaming->period = wl->conf.rx_streaming.interval; 1547 rx_streaming->period = wl->conf.rx_streaming.interval;
@@ -1542,7 +1560,7 @@ out:
1542 return ret; 1560 return ret;
1543} 1561}
1544 1562
1545int wl1271_acx_ap_max_tx_retry(struct wl1271 *wl) 1563int wl1271_acx_ap_max_tx_retry(struct wl1271 *wl, struct wl12xx_vif *wlvif)
1546{ 1564{
1547 struct wl1271_acx_ap_max_tx_retry *acx = NULL; 1565 struct wl1271_acx_ap_max_tx_retry *acx = NULL;
1548 int ret; 1566 int ret;
@@ -1553,7 +1571,7 @@ int wl1271_acx_ap_max_tx_retry(struct wl1271 *wl)
1553 if (!acx) 1571 if (!acx)
1554 return -ENOMEM; 1572 return -ENOMEM;
1555 1573
1556 acx->role_id = wl->role_id; 1574 acx->role_id = wlvif->role_id;
1557 acx->max_tx_retry = cpu_to_le16(wl->conf.tx.max_tx_retries); 1575 acx->max_tx_retry = cpu_to_le16(wl->conf.tx.max_tx_retries);
1558 1576
1559 ret = wl1271_cmd_configure(wl, ACX_MAX_TX_FAILURE, acx, sizeof(*acx)); 1577 ret = wl1271_cmd_configure(wl, ACX_MAX_TX_FAILURE, acx, sizeof(*acx));
@@ -1567,7 +1585,7 @@ out:
1567 return ret; 1585 return ret;
1568} 1586}
1569 1587
1570int wl1271_acx_config_ps(struct wl1271 *wl) 1588int wl12xx_acx_config_ps(struct wl1271 *wl, struct wl12xx_vif *wlvif)
1571{ 1589{
1572 struct wl1271_acx_config_ps *config_ps; 1590 struct wl1271_acx_config_ps *config_ps;
1573 int ret; 1591 int ret;
@@ -1582,7 +1600,7 @@ int wl1271_acx_config_ps(struct wl1271 *wl)
1582 1600
1583 config_ps->exit_retries = wl->conf.conn.psm_exit_retries; 1601 config_ps->exit_retries = wl->conf.conn.psm_exit_retries;
1584 config_ps->enter_retries = wl->conf.conn.psm_entry_retries; 1602 config_ps->enter_retries = wl->conf.conn.psm_entry_retries;
1585 config_ps->null_data_rate = cpu_to_le32(wl->basic_rate); 1603 config_ps->null_data_rate = cpu_to_le32(wlvif->basic_rate);
1586 1604
1587 ret = wl1271_cmd_configure(wl, ACX_CONFIG_PS, config_ps, 1605 ret = wl1271_cmd_configure(wl, ACX_CONFIG_PS, config_ps,
1588 sizeof(*config_ps)); 1606 sizeof(*config_ps));
diff --git a/drivers/net/wireless/wl12xx/acx.h b/drivers/net/wireless/wl12xx/acx.h
index e3f93b4b342..b2d85bea637 100644
--- a/drivers/net/wireless/wl12xx/acx.h
+++ b/drivers/net/wireless/wl12xx/acx.h
@@ -654,11 +654,6 @@ struct acx_rate_class {
654 u8 reserved; 654 u8 reserved;
655}; 655};
656 656
657#define ACX_TX_BASIC_RATE 0
658#define ACX_TX_AP_FULL_RATE 1
659#define ACX_TX_BASIC_RATE_P2P 2
660#define ACX_TX_AP_MODE_MGMT_RATE 4
661#define ACX_TX_AP_MODE_BCST_RATE 5
662struct acx_rate_policy { 657struct acx_rate_policy {
663 struct acx_header header; 658 struct acx_header header;
664 659
@@ -1234,39 +1229,49 @@ enum {
1234}; 1229};
1235 1230
1236 1231
1237int wl1271_acx_wake_up_conditions(struct wl1271 *wl); 1232int wl1271_acx_wake_up_conditions(struct wl1271 *wl,
1233 struct wl12xx_vif *wlvif);
1238int wl1271_acx_sleep_auth(struct wl1271 *wl, u8 sleep_auth); 1234int wl1271_acx_sleep_auth(struct wl1271 *wl, u8 sleep_auth);
1239int wl1271_acx_tx_power(struct wl1271 *wl, int power); 1235int wl1271_acx_tx_power(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1240int wl1271_acx_feature_cfg(struct wl1271 *wl); 1236 int power);
1237int wl1271_acx_feature_cfg(struct wl1271 *wl, struct wl12xx_vif *wlvif);
1241int wl1271_acx_mem_map(struct wl1271 *wl, 1238int wl1271_acx_mem_map(struct wl1271 *wl,
1242 struct acx_header *mem_map, size_t len); 1239 struct acx_header *mem_map, size_t len);
1243int wl1271_acx_rx_msdu_life_time(struct wl1271 *wl); 1240int wl1271_acx_rx_msdu_life_time(struct wl1271 *wl);
1244int wl1271_acx_pd_threshold(struct wl1271 *wl); 1241int wl1271_acx_pd_threshold(struct wl1271 *wl);
1245int wl1271_acx_slot(struct wl1271 *wl, enum acx_slot_type slot_time); 1242int wl1271_acx_slot(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1246int wl1271_acx_group_address_tbl(struct wl1271 *wl, bool enable, 1243 enum acx_slot_type slot_time);
1247 void *mc_list, u32 mc_list_len); 1244int wl1271_acx_group_address_tbl(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1248int wl1271_acx_service_period_timeout(struct wl1271 *wl); 1245 bool enable, void *mc_list, u32 mc_list_len);
1249int wl1271_acx_rts_threshold(struct wl1271 *wl, u32 rts_threshold); 1246int wl1271_acx_service_period_timeout(struct wl1271 *wl,
1247 struct wl12xx_vif *wlvif);
1248int wl1271_acx_rts_threshold(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1249 u32 rts_threshold);
1250int wl1271_acx_dco_itrim_params(struct wl1271 *wl); 1250int wl1271_acx_dco_itrim_params(struct wl1271 *wl);
1251int wl1271_acx_beacon_filter_opt(struct wl1271 *wl, bool enable_filter); 1251int wl1271_acx_beacon_filter_opt(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1252int wl1271_acx_beacon_filter_table(struct wl1271 *wl); 1252 bool enable_filter);
1253int wl1271_acx_conn_monit_params(struct wl1271 *wl, bool enable); 1253int wl1271_acx_beacon_filter_table(struct wl1271 *wl,
1254 struct wl12xx_vif *wlvif);
1255int wl1271_acx_conn_monit_params(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1256 bool enable);
1254int wl1271_acx_sg_enable(struct wl1271 *wl, bool enable); 1257int wl1271_acx_sg_enable(struct wl1271 *wl, bool enable);
1255int wl12xx_acx_sg_cfg(struct wl1271 *wl); 1258int wl12xx_acx_sg_cfg(struct wl1271 *wl);
1256int wl1271_acx_cca_threshold(struct wl1271 *wl); 1259int wl1271_acx_cca_threshold(struct wl1271 *wl);
1257int wl1271_acx_bcn_dtim_options(struct wl1271 *wl); 1260int wl1271_acx_bcn_dtim_options(struct wl1271 *wl, struct wl12xx_vif *wlvif);
1258int wl1271_acx_aid(struct wl1271 *wl, u16 aid); 1261int wl1271_acx_aid(struct wl1271 *wl, struct wl12xx_vif *wlvif, u16 aid);
1259int wl1271_acx_event_mbox_mask(struct wl1271 *wl, u32 event_mask); 1262int wl1271_acx_event_mbox_mask(struct wl1271 *wl, u32 event_mask);
1260int wl1271_acx_set_preamble(struct wl1271 *wl, enum acx_preamble_type preamble); 1263int wl1271_acx_set_preamble(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1261int wl1271_acx_cts_protect(struct wl1271 *wl, 1264 enum acx_preamble_type preamble);
1265int wl1271_acx_cts_protect(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1262 enum acx_ctsprotect_type ctsprotect); 1266 enum acx_ctsprotect_type ctsprotect);
1263int wl1271_acx_statistics(struct wl1271 *wl, struct acx_statistics *stats); 1267int wl1271_acx_statistics(struct wl1271 *wl, struct acx_statistics *stats);
1264int wl1271_acx_sta_rate_policies(struct wl1271 *wl); 1268int wl1271_acx_sta_rate_policies(struct wl1271 *wl, struct wl12xx_vif *wlvif);
1265int wl1271_acx_ap_rate_policy(struct wl1271 *wl, struct conf_tx_rate_class *c, 1269int wl1271_acx_ap_rate_policy(struct wl1271 *wl, struct conf_tx_rate_class *c,
1266 u8 idx); 1270 u8 idx);
1267int wl1271_acx_ac_cfg(struct wl1271 *wl, u8 ac, u8 cw_min, u16 cw_max, 1271int wl1271_acx_ac_cfg(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1268 u8 aifsn, u16 txop); 1272 u8 ac, u8 cw_min, u16 cw_max, u8 aifsn, u16 txop);
1269int wl1271_acx_tid_cfg(struct wl1271 *wl, u8 queue_id, u8 channel_type, 1273int wl1271_acx_tid_cfg(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1274 u8 queue_id, u8 channel_type,
1270 u8 tsid, u8 ps_scheme, u8 ack_policy, 1275 u8 tsid, u8 ps_scheme, u8 ack_policy,
1271 u32 apsd_conf0, u32 apsd_conf1); 1276 u32 apsd_conf0, u32 apsd_conf1);
1272int wl1271_acx_frag_threshold(struct wl1271 *wl, u32 frag_threshold); 1277int wl1271_acx_frag_threshold(struct wl1271 *wl, u32 frag_threshold);
@@ -1276,26 +1281,34 @@ int wl1271_acx_init_mem_config(struct wl1271 *wl);
1276int wl1271_acx_host_if_cfg_bitmap(struct wl1271 *wl, u32 host_cfg_bitmap); 1281int wl1271_acx_host_if_cfg_bitmap(struct wl1271 *wl, u32 host_cfg_bitmap);
1277int wl1271_acx_init_rx_interrupt(struct wl1271 *wl); 1282int wl1271_acx_init_rx_interrupt(struct wl1271 *wl);
1278int wl1271_acx_smart_reflex(struct wl1271 *wl); 1283int wl1271_acx_smart_reflex(struct wl1271 *wl);
1279int wl1271_acx_bet_enable(struct wl1271 *wl, bool enable); 1284int wl1271_acx_bet_enable(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1280int wl1271_acx_arp_ip_filter(struct wl1271 *wl, u8 enable, __be32 address); 1285 bool enable);
1286int wl1271_acx_arp_ip_filter(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1287 u8 enable, __be32 address);
1281int wl1271_acx_pm_config(struct wl1271 *wl); 1288int wl1271_acx_pm_config(struct wl1271 *wl);
1282int wl1271_acx_keep_alive_mode(struct wl1271 *wl, bool enable); 1289int wl1271_acx_keep_alive_mode(struct wl1271 *wl, struct wl12xx_vif *vif,
1283int wl1271_acx_keep_alive_config(struct wl1271 *wl, u8 index, u8 tpl_valid); 1290 bool enable);
1284int wl1271_acx_rssi_snr_trigger(struct wl1271 *wl, bool enable, 1291int wl1271_acx_keep_alive_config(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1285 s16 thold, u8 hyst); 1292 u8 index, u8 tpl_valid);
1286int wl1271_acx_rssi_snr_avg_weights(struct wl1271 *wl); 1293int wl1271_acx_rssi_snr_trigger(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1294 bool enable, s16 thold, u8 hyst);
1295int wl1271_acx_rssi_snr_avg_weights(struct wl1271 *wl,
1296 struct wl12xx_vif *wlvif);
1287int wl1271_acx_set_ht_capabilities(struct wl1271 *wl, 1297int wl1271_acx_set_ht_capabilities(struct wl1271 *wl,
1288 struct ieee80211_sta_ht_cap *ht_cap, 1298 struct ieee80211_sta_ht_cap *ht_cap,
1289 bool allow_ht_operation, u8 hlid); 1299 bool allow_ht_operation, u8 hlid);
1290int wl1271_acx_set_ht_information(struct wl1271 *wl, 1300int wl1271_acx_set_ht_information(struct wl1271 *wl,
1301 struct wl12xx_vif *wlvif,
1291 u16 ht_operation_mode); 1302 u16 ht_operation_mode);
1292int wl12xx_acx_set_ba_initiator_policy(struct wl1271 *wl); 1303int wl12xx_acx_set_ba_initiator_policy(struct wl1271 *wl,
1304 struct wl12xx_vif *wlvif);
1293int wl12xx_acx_set_ba_receiver_session(struct wl1271 *wl, u8 tid_index, 1305int wl12xx_acx_set_ba_receiver_session(struct wl1271 *wl, u8 tid_index,
1294 u16 ssn, bool enable, u8 peer_hlid); 1306 u16 ssn, bool enable, u8 peer_hlid);
1295int wl1271_acx_tsf_info(struct wl1271 *wl, u64 *mactime); 1307int wl1271_acx_tsf_info(struct wl1271 *wl, u64 *mactime);
1296int wl1271_acx_ps_rx_streaming(struct wl1271 *wl, bool enable); 1308int wl1271_acx_ps_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1297int wl1271_acx_ap_max_tx_retry(struct wl1271 *wl); 1309 bool enable);
1298int wl1271_acx_config_ps(struct wl1271 *wl); 1310int wl1271_acx_ap_max_tx_retry(struct wl1271 *wl, struct wl12xx_vif *wlvif);
1311int wl12xx_acx_config_ps(struct wl1271 *wl, struct wl12xx_vif *wlvif);
1299int wl1271_acx_set_inconnection_sta(struct wl1271 *wl, u8 *addr); 1312int wl1271_acx_set_inconnection_sta(struct wl1271 *wl, u8 *addr);
1300int wl1271_acx_fm_coex(struct wl1271 *wl); 1313int wl1271_acx_fm_coex(struct wl1271 *wl);
1301int wl12xx_acx_set_rate_mgmt_params(struct wl1271 *wl); 1314int wl12xx_acx_set_rate_mgmt_params(struct wl1271 *wl);
diff --git a/drivers/net/wireless/wl12xx/boot.c b/drivers/net/wireless/wl12xx/boot.c
index 68133791497..8f9cf5a816e 100644
--- a/drivers/net/wireless/wl12xx/boot.c
+++ b/drivers/net/wireless/wl12xx/boot.c
@@ -25,6 +25,7 @@
25#include <linux/wl12xx.h> 25#include <linux/wl12xx.h>
26#include <linux/export.h> 26#include <linux/export.h>
27 27
28#include "debug.h"
28#include "acx.h" 29#include "acx.h"
29#include "reg.h" 30#include "reg.h"
30#include "boot.h" 31#include "boot.h"
@@ -347,6 +348,9 @@ static int wl1271_boot_upload_nvs(struct wl1271 *wl)
347 nvs_ptr += 3; 348 nvs_ptr += 3;
348 349
349 for (i = 0; i < burst_len; i++) { 350 for (i = 0; i < burst_len; i++) {
351 if (nvs_ptr + 3 >= (u8 *) wl->nvs + nvs_len)
352 goto out_badnvs;
353
350 val = (nvs_ptr[0] | (nvs_ptr[1] << 8) 354 val = (nvs_ptr[0] | (nvs_ptr[1] << 8)
351 | (nvs_ptr[2] << 16) | (nvs_ptr[3] << 24)); 355 | (nvs_ptr[2] << 16) | (nvs_ptr[3] << 24));
352 356
@@ -358,6 +362,9 @@ static int wl1271_boot_upload_nvs(struct wl1271 *wl)
358 nvs_ptr += 4; 362 nvs_ptr += 4;
359 dest_addr += 4; 363 dest_addr += 4;
360 } 364 }
365
366 if (nvs_ptr >= (u8 *) wl->nvs + nvs_len)
367 goto out_badnvs;
361 } 368 }
362 369
363 /* 370 /*
@@ -369,6 +376,10 @@ static int wl1271_boot_upload_nvs(struct wl1271 *wl)
369 */ 376 */
370 nvs_ptr = (u8 *)wl->nvs + 377 nvs_ptr = (u8 *)wl->nvs +
371 ALIGN(nvs_ptr - (u8 *)wl->nvs + 7, 4); 378 ALIGN(nvs_ptr - (u8 *)wl->nvs + 7, 4);
379
380 if (nvs_ptr >= (u8 *) wl->nvs + nvs_len)
381 goto out_badnvs;
382
372 nvs_len -= nvs_ptr - (u8 *)wl->nvs; 383 nvs_len -= nvs_ptr - (u8 *)wl->nvs;
373 384
374 /* Now we must set the partition correctly */ 385 /* Now we must set the partition correctly */
@@ -384,6 +395,10 @@ static int wl1271_boot_upload_nvs(struct wl1271 *wl)
384 395
385 kfree(nvs_aligned); 396 kfree(nvs_aligned);
386 return 0; 397 return 0;
398
399out_badnvs:
400 wl1271_error("nvs data is malformed");
401 return -EILSEQ;
387} 402}
388 403
389static void wl1271_boot_enable_interrupts(struct wl1271 *wl) 404static void wl1271_boot_enable_interrupts(struct wl1271 *wl)
diff --git a/drivers/net/wireless/wl12xx/cmd.c b/drivers/net/wireless/wl12xx/cmd.c
index a52299e548f..e0d21797948 100644
--- a/drivers/net/wireless/wl12xx/cmd.c
+++ b/drivers/net/wireless/wl12xx/cmd.c
@@ -29,6 +29,7 @@
29#include <linux/slab.h> 29#include <linux/slab.h>
30 30
31#include "wl12xx.h" 31#include "wl12xx.h"
32#include "debug.h"
32#include "reg.h" 33#include "reg.h"
33#include "io.h" 34#include "io.h"
34#include "acx.h" 35#include "acx.h"
@@ -120,6 +121,11 @@ int wl1271_cmd_general_parms(struct wl1271 *wl)
120 if (!wl->nvs) 121 if (!wl->nvs)
121 return -ENODEV; 122 return -ENODEV;
122 123
124 if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) {
125 wl1271_warning("FEM index from INI out of bounds");
126 return -EINVAL;
127 }
128
123 gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL); 129 gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
124 if (!gen_parms) 130 if (!gen_parms)
125 return -ENOMEM; 131 return -ENOMEM;
@@ -143,6 +149,12 @@ int wl1271_cmd_general_parms(struct wl1271 *wl)
143 gp->tx_bip_fem_manufacturer = 149 gp->tx_bip_fem_manufacturer =
144 gen_parms->general_params.tx_bip_fem_manufacturer; 150 gen_parms->general_params.tx_bip_fem_manufacturer;
145 151
152 if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) {
153 wl1271_warning("FEM index from FW out of bounds");
154 ret = -EINVAL;
155 goto out;
156 }
157
146 wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n", 158 wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n",
147 answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer); 159 answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer);
148 160
@@ -162,6 +174,11 @@ int wl128x_cmd_general_parms(struct wl1271 *wl)
162 if (!wl->nvs) 174 if (!wl->nvs)
163 return -ENODEV; 175 return -ENODEV;
164 176
177 if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) {
178 wl1271_warning("FEM index from ini out of bounds");
179 return -EINVAL;
180 }
181
165 gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL); 182 gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
166 if (!gen_parms) 183 if (!gen_parms)
167 return -ENOMEM; 184 return -ENOMEM;
@@ -186,6 +203,12 @@ int wl128x_cmd_general_parms(struct wl1271 *wl)
186 gp->tx_bip_fem_manufacturer = 203 gp->tx_bip_fem_manufacturer =
187 gen_parms->general_params.tx_bip_fem_manufacturer; 204 gen_parms->general_params.tx_bip_fem_manufacturer;
188 205
206 if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) {
207 wl1271_warning("FEM index from FW out of bounds");
208 ret = -EINVAL;
209 goto out;
210 }
211
189 wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n", 212 wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n",
190 answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer); 213 answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer);
191 214
@@ -358,7 +381,8 @@ static int wl1271_cmd_wait_for_event(struct wl1271 *wl, u32 mask)
358 return 0; 381 return 0;
359} 382}
360 383
361int wl12xx_cmd_role_enable(struct wl1271 *wl, u8 role_type, u8 *role_id) 384int wl12xx_cmd_role_enable(struct wl1271 *wl, u8 *addr, u8 role_type,
385 u8 *role_id)
362{ 386{
363 struct wl12xx_cmd_role_enable *cmd; 387 struct wl12xx_cmd_role_enable *cmd;
364 int ret; 388 int ret;
@@ -381,7 +405,7 @@ int wl12xx_cmd_role_enable(struct wl1271 *wl, u8 role_type, u8 *role_id)
381 goto out_free; 405 goto out_free;
382 } 406 }
383 407
384 memcpy(cmd->mac_address, wl->mac_addr, ETH_ALEN); 408 memcpy(cmd->mac_address, addr, ETH_ALEN);
385 cmd->role_type = role_type; 409 cmd->role_type = role_type;
386 410
387 ret = wl1271_cmd_send(wl, CMD_ROLE_ENABLE, cmd, sizeof(*cmd), 0); 411 ret = wl1271_cmd_send(wl, CMD_ROLE_ENABLE, cmd, sizeof(*cmd), 0);
@@ -433,37 +457,41 @@ out:
433 return ret; 457 return ret;
434} 458}
435 459
436static int wl12xx_allocate_link(struct wl1271 *wl, u8 *hlid) 460int wl12xx_allocate_link(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 *hlid)
437{ 461{
438 u8 link = find_first_zero_bit(wl->links_map, WL12XX_MAX_LINKS); 462 u8 link = find_first_zero_bit(wl->links_map, WL12XX_MAX_LINKS);
439 if (link >= WL12XX_MAX_LINKS) 463 if (link >= WL12XX_MAX_LINKS)
440 return -EBUSY; 464 return -EBUSY;
441 465
442 __set_bit(link, wl->links_map); 466 __set_bit(link, wl->links_map);
467 __set_bit(link, wlvif->links_map);
443 *hlid = link; 468 *hlid = link;
444 return 0; 469 return 0;
445} 470}
446 471
447static void wl12xx_free_link(struct wl1271 *wl, u8 *hlid) 472void wl12xx_free_link(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 *hlid)
448{ 473{
449 if (*hlid == WL12XX_INVALID_LINK_ID) 474 if (*hlid == WL12XX_INVALID_LINK_ID)
450 return; 475 return;
451 476
452 __clear_bit(*hlid, wl->links_map); 477 __clear_bit(*hlid, wl->links_map);
478 __clear_bit(*hlid, wlvif->links_map);
453 *hlid = WL12XX_INVALID_LINK_ID; 479 *hlid = WL12XX_INVALID_LINK_ID;
454} 480}
455 481
456static int wl12xx_get_new_session_id(struct wl1271 *wl) 482static int wl12xx_get_new_session_id(struct wl1271 *wl,
483 struct wl12xx_vif *wlvif)
457{ 484{
458 if (wl->session_counter >= SESSION_COUNTER_MAX) 485 if (wlvif->session_counter >= SESSION_COUNTER_MAX)
459 wl->session_counter = 0; 486 wlvif->session_counter = 0;
460 487
461 wl->session_counter++; 488 wlvif->session_counter++;
462 489
463 return wl->session_counter; 490 return wlvif->session_counter;
464} 491}
465 492
466int wl12xx_cmd_role_start_dev(struct wl1271 *wl) 493static int wl12xx_cmd_role_start_dev(struct wl1271 *wl,
494 struct wl12xx_vif *wlvif)
467{ 495{
468 struct wl12xx_cmd_role_start *cmd; 496 struct wl12xx_cmd_role_start *cmd;
469 int ret; 497 int ret;
@@ -474,20 +502,20 @@ int wl12xx_cmd_role_start_dev(struct wl1271 *wl)
474 goto out; 502 goto out;
475 } 503 }
476 504
477 wl1271_debug(DEBUG_CMD, "cmd role start dev %d", wl->dev_role_id); 505 wl1271_debug(DEBUG_CMD, "cmd role start dev %d", wlvif->dev_role_id);
478 506
479 cmd->role_id = wl->dev_role_id; 507 cmd->role_id = wlvif->dev_role_id;
480 if (wl->band == IEEE80211_BAND_5GHZ) 508 if (wlvif->band == IEEE80211_BAND_5GHZ)
481 cmd->band = WL12XX_BAND_5GHZ; 509 cmd->band = WL12XX_BAND_5GHZ;
482 cmd->channel = wl->channel; 510 cmd->channel = wlvif->channel;
483 511
484 if (wl->dev_hlid == WL12XX_INVALID_LINK_ID) { 512 if (wlvif->dev_hlid == WL12XX_INVALID_LINK_ID) {
485 ret = wl12xx_allocate_link(wl, &wl->dev_hlid); 513 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->dev_hlid);
486 if (ret) 514 if (ret)
487 goto out_free; 515 goto out_free;
488 } 516 }
489 cmd->device.hlid = wl->dev_hlid; 517 cmd->device.hlid = wlvif->dev_hlid;
490 cmd->device.session = wl->session_counter; 518 cmd->device.session = wlvif->session_counter;
491 519
492 wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d", 520 wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d",
493 cmd->role_id, cmd->device.hlid, cmd->device.session); 521 cmd->role_id, cmd->device.hlid, cmd->device.session);
@@ -502,9 +530,7 @@ int wl12xx_cmd_role_start_dev(struct wl1271 *wl)
502 530
503err_hlid: 531err_hlid:
504 /* clear links on error */ 532 /* clear links on error */
505 __clear_bit(wl->dev_hlid, wl->links_map); 533 wl12xx_free_link(wl, wlvif, &wlvif->dev_hlid);
506 wl->dev_hlid = WL12XX_INVALID_LINK_ID;
507
508 534
509out_free: 535out_free:
510 kfree(cmd); 536 kfree(cmd);
@@ -513,12 +539,13 @@ out:
513 return ret; 539 return ret;
514} 540}
515 541
516int wl12xx_cmd_role_stop_dev(struct wl1271 *wl) 542static int wl12xx_cmd_role_stop_dev(struct wl1271 *wl,
543 struct wl12xx_vif *wlvif)
517{ 544{
518 struct wl12xx_cmd_role_stop *cmd; 545 struct wl12xx_cmd_role_stop *cmd;
519 int ret; 546 int ret;
520 547
521 if (WARN_ON(wl->dev_hlid == WL12XX_INVALID_LINK_ID)) 548 if (WARN_ON(wlvif->dev_hlid == WL12XX_INVALID_LINK_ID))
522 return -EINVAL; 549 return -EINVAL;
523 550
524 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 551 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
@@ -529,7 +556,7 @@ int wl12xx_cmd_role_stop_dev(struct wl1271 *wl)
529 556
530 wl1271_debug(DEBUG_CMD, "cmd role stop dev"); 557 wl1271_debug(DEBUG_CMD, "cmd role stop dev");
531 558
532 cmd->role_id = wl->dev_role_id; 559 cmd->role_id = wlvif->dev_role_id;
533 cmd->disc_type = DISCONNECT_IMMEDIATE; 560 cmd->disc_type = DISCONNECT_IMMEDIATE;
534 cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED); 561 cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED);
535 562
@@ -545,7 +572,7 @@ int wl12xx_cmd_role_stop_dev(struct wl1271 *wl)
545 goto out_free; 572 goto out_free;
546 } 573 }
547 574
548 wl12xx_free_link(wl, &wl->dev_hlid); 575 wl12xx_free_link(wl, wlvif, &wlvif->dev_hlid);
549 576
550out_free: 577out_free:
551 kfree(cmd); 578 kfree(cmd);
@@ -554,8 +581,9 @@ out:
554 return ret; 581 return ret;
555} 582}
556 583
557int wl12xx_cmd_role_start_sta(struct wl1271 *wl) 584int wl12xx_cmd_role_start_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif)
558{ 585{
586 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
559 struct wl12xx_cmd_role_start *cmd; 587 struct wl12xx_cmd_role_start *cmd;
560 int ret; 588 int ret;
561 589
@@ -565,33 +593,33 @@ int wl12xx_cmd_role_start_sta(struct wl1271 *wl)
565 goto out; 593 goto out;
566 } 594 }
567 595
568 wl1271_debug(DEBUG_CMD, "cmd role start sta %d", wl->role_id); 596 wl1271_debug(DEBUG_CMD, "cmd role start sta %d", wlvif->role_id);
569 597
570 cmd->role_id = wl->role_id; 598 cmd->role_id = wlvif->role_id;
571 if (wl->band == IEEE80211_BAND_5GHZ) 599 if (wlvif->band == IEEE80211_BAND_5GHZ)
572 cmd->band = WL12XX_BAND_5GHZ; 600 cmd->band = WL12XX_BAND_5GHZ;
573 cmd->channel = wl->channel; 601 cmd->channel = wlvif->channel;
574 cmd->sta.basic_rate_set = cpu_to_le32(wl->basic_rate_set); 602 cmd->sta.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
575 cmd->sta.beacon_interval = cpu_to_le16(wl->beacon_int); 603 cmd->sta.beacon_interval = cpu_to_le16(wlvif->beacon_int);
576 cmd->sta.ssid_type = WL12XX_SSID_TYPE_ANY; 604 cmd->sta.ssid_type = WL12XX_SSID_TYPE_ANY;
577 cmd->sta.ssid_len = wl->ssid_len; 605 cmd->sta.ssid_len = wlvif->ssid_len;
578 memcpy(cmd->sta.ssid, wl->ssid, wl->ssid_len); 606 memcpy(cmd->sta.ssid, wlvif->ssid, wlvif->ssid_len);
579 memcpy(cmd->sta.bssid, wl->bssid, ETH_ALEN); 607 memcpy(cmd->sta.bssid, vif->bss_conf.bssid, ETH_ALEN);
580 cmd->sta.local_rates = cpu_to_le32(wl->rate_set); 608 cmd->sta.local_rates = cpu_to_le32(wlvif->rate_set);
581 609
582 if (wl->sta_hlid == WL12XX_INVALID_LINK_ID) { 610 if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) {
583 ret = wl12xx_allocate_link(wl, &wl->sta_hlid); 611 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->sta.hlid);
584 if (ret) 612 if (ret)
585 goto out_free; 613 goto out_free;
586 } 614 }
587 cmd->sta.hlid = wl->sta_hlid; 615 cmd->sta.hlid = wlvif->sta.hlid;
588 cmd->sta.session = wl12xx_get_new_session_id(wl); 616 cmd->sta.session = wl12xx_get_new_session_id(wl, wlvif);
589 cmd->sta.remote_rates = cpu_to_le32(wl->rate_set); 617 cmd->sta.remote_rates = cpu_to_le32(wlvif->rate_set);
590 618
591 wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d " 619 wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d "
592 "basic_rate_set: 0x%x, remote_rates: 0x%x", 620 "basic_rate_set: 0x%x, remote_rates: 0x%x",
593 wl->role_id, cmd->sta.hlid, cmd->sta.session, 621 wlvif->role_id, cmd->sta.hlid, cmd->sta.session,
594 wl->basic_rate_set, wl->rate_set); 622 wlvif->basic_rate_set, wlvif->rate_set);
595 623
596 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0); 624 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
597 if (ret < 0) { 625 if (ret < 0) {
@@ -603,7 +631,7 @@ int wl12xx_cmd_role_start_sta(struct wl1271 *wl)
603 631
604err_hlid: 632err_hlid:
605 /* clear links on error. */ 633 /* clear links on error. */
606 wl12xx_free_link(wl, &wl->sta_hlid); 634 wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
607 635
608out_free: 636out_free:
609 kfree(cmd); 637 kfree(cmd);
@@ -613,12 +641,12 @@ out:
613} 641}
614 642
615/* use this function to stop ibss as well */ 643/* use this function to stop ibss as well */
616int wl12xx_cmd_role_stop_sta(struct wl1271 *wl) 644int wl12xx_cmd_role_stop_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif)
617{ 645{
618 struct wl12xx_cmd_role_stop *cmd; 646 struct wl12xx_cmd_role_stop *cmd;
619 int ret; 647 int ret;
620 648
621 if (WARN_ON(wl->sta_hlid == WL12XX_INVALID_LINK_ID)) 649 if (WARN_ON(wlvif->sta.hlid == WL12XX_INVALID_LINK_ID))
622 return -EINVAL; 650 return -EINVAL;
623 651
624 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 652 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
@@ -627,9 +655,9 @@ int wl12xx_cmd_role_stop_sta(struct wl1271 *wl)
627 goto out; 655 goto out;
628 } 656 }
629 657
630 wl1271_debug(DEBUG_CMD, "cmd role stop sta %d", wl->role_id); 658 wl1271_debug(DEBUG_CMD, "cmd role stop sta %d", wlvif->role_id);
631 659
632 cmd->role_id = wl->role_id; 660 cmd->role_id = wlvif->role_id;
633 cmd->disc_type = DISCONNECT_IMMEDIATE; 661 cmd->disc_type = DISCONNECT_IMMEDIATE;
634 cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED); 662 cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED);
635 663
@@ -639,7 +667,7 @@ int wl12xx_cmd_role_stop_sta(struct wl1271 *wl)
639 goto out_free; 667 goto out_free;
640 } 668 }
641 669
642 wl12xx_free_link(wl, &wl->sta_hlid); 670 wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
643 671
644out_free: 672out_free:
645 kfree(cmd); 673 kfree(cmd);
@@ -648,16 +676,17 @@ out:
648 return ret; 676 return ret;
649} 677}
650 678
651int wl12xx_cmd_role_start_ap(struct wl1271 *wl) 679int wl12xx_cmd_role_start_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif)
652{ 680{
653 struct wl12xx_cmd_role_start *cmd; 681 struct wl12xx_cmd_role_start *cmd;
654 struct ieee80211_bss_conf *bss_conf = &wl->vif->bss_conf; 682 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
683 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
655 int ret; 684 int ret;
656 685
657 wl1271_debug(DEBUG_CMD, "cmd role start ap %d", wl->role_id); 686 wl1271_debug(DEBUG_CMD, "cmd role start ap %d", wlvif->role_id);
658 687
659 /* trying to use hidden SSID with an old hostapd version */ 688 /* trying to use hidden SSID with an old hostapd version */
660 if (wl->ssid_len == 0 && !bss_conf->hidden_ssid) { 689 if (wlvif->ssid_len == 0 && !bss_conf->hidden_ssid) {
661 wl1271_error("got a null SSID from beacon/bss"); 690 wl1271_error("got a null SSID from beacon/bss");
662 ret = -EINVAL; 691 ret = -EINVAL;
663 goto out; 692 goto out;
@@ -669,30 +698,30 @@ int wl12xx_cmd_role_start_ap(struct wl1271 *wl)
669 goto out; 698 goto out;
670 } 699 }
671 700
672 ret = wl12xx_allocate_link(wl, &wl->ap_global_hlid); 701 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->ap.global_hlid);
673 if (ret < 0) 702 if (ret < 0)
674 goto out_free; 703 goto out_free;
675 704
676 ret = wl12xx_allocate_link(wl, &wl->ap_bcast_hlid); 705 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->ap.bcast_hlid);
677 if (ret < 0) 706 if (ret < 0)
678 goto out_free_global; 707 goto out_free_global;
679 708
680 cmd->role_id = wl->role_id; 709 cmd->role_id = wlvif->role_id;
681 cmd->ap.aging_period = cpu_to_le16(wl->conf.tx.ap_aging_period); 710 cmd->ap.aging_period = cpu_to_le16(wl->conf.tx.ap_aging_period);
682 cmd->ap.bss_index = WL1271_AP_BSS_INDEX; 711 cmd->ap.bss_index = WL1271_AP_BSS_INDEX;
683 cmd->ap.global_hlid = wl->ap_global_hlid; 712 cmd->ap.global_hlid = wlvif->ap.global_hlid;
684 cmd->ap.broadcast_hlid = wl->ap_bcast_hlid; 713 cmd->ap.broadcast_hlid = wlvif->ap.bcast_hlid;
685 cmd->ap.basic_rate_set = cpu_to_le32(wl->basic_rate_set); 714 cmd->ap.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
686 cmd->ap.beacon_interval = cpu_to_le16(wl->beacon_int); 715 cmd->ap.beacon_interval = cpu_to_le16(wlvif->beacon_int);
687 cmd->ap.dtim_interval = bss_conf->dtim_period; 716 cmd->ap.dtim_interval = bss_conf->dtim_period;
688 cmd->ap.beacon_expiry = WL1271_AP_DEF_BEACON_EXP; 717 cmd->ap.beacon_expiry = WL1271_AP_DEF_BEACON_EXP;
689 cmd->channel = wl->channel; 718 cmd->channel = wlvif->channel;
690 719
691 if (!bss_conf->hidden_ssid) { 720 if (!bss_conf->hidden_ssid) {
692 /* take the SSID from the beacon for backward compatibility */ 721 /* take the SSID from the beacon for backward compatibility */
693 cmd->ap.ssid_type = WL12XX_SSID_TYPE_PUBLIC; 722 cmd->ap.ssid_type = WL12XX_SSID_TYPE_PUBLIC;
694 cmd->ap.ssid_len = wl->ssid_len; 723 cmd->ap.ssid_len = wlvif->ssid_len;
695 memcpy(cmd->ap.ssid, wl->ssid, wl->ssid_len); 724 memcpy(cmd->ap.ssid, wlvif->ssid, wlvif->ssid_len);
696 } else { 725 } else {
697 cmd->ap.ssid_type = WL12XX_SSID_TYPE_HIDDEN; 726 cmd->ap.ssid_type = WL12XX_SSID_TYPE_HIDDEN;
698 cmd->ap.ssid_len = bss_conf->ssid_len; 727 cmd->ap.ssid_len = bss_conf->ssid_len;
@@ -701,7 +730,7 @@ int wl12xx_cmd_role_start_ap(struct wl1271 *wl)
701 730
702 cmd->ap.local_rates = cpu_to_le32(0xffffffff); 731 cmd->ap.local_rates = cpu_to_le32(0xffffffff);
703 732
704 switch (wl->band) { 733 switch (wlvif->band) {
705 case IEEE80211_BAND_2GHZ: 734 case IEEE80211_BAND_2GHZ:
706 cmd->band = RADIO_BAND_2_4GHZ; 735 cmd->band = RADIO_BAND_2_4GHZ;
707 break; 736 break;
@@ -709,7 +738,7 @@ int wl12xx_cmd_role_start_ap(struct wl1271 *wl)
709 cmd->band = RADIO_BAND_5GHZ; 738 cmd->band = RADIO_BAND_5GHZ;
710 break; 739 break;
711 default: 740 default:
712 wl1271_warning("ap start - unknown band: %d", (int)wl->band); 741 wl1271_warning("ap start - unknown band: %d", (int)wlvif->band);
713 cmd->band = RADIO_BAND_2_4GHZ; 742 cmd->band = RADIO_BAND_2_4GHZ;
714 break; 743 break;
715 } 744 }
@@ -723,10 +752,10 @@ int wl12xx_cmd_role_start_ap(struct wl1271 *wl)
723 goto out_free; 752 goto out_free;
724 753
725out_free_bcast: 754out_free_bcast:
726 wl12xx_free_link(wl, &wl->ap_bcast_hlid); 755 wl12xx_free_link(wl, wlvif, &wlvif->ap.bcast_hlid);
727 756
728out_free_global: 757out_free_global:
729 wl12xx_free_link(wl, &wl->ap_global_hlid); 758 wl12xx_free_link(wl, wlvif, &wlvif->ap.global_hlid);
730 759
731out_free: 760out_free:
732 kfree(cmd); 761 kfree(cmd);
@@ -735,7 +764,7 @@ out:
735 return ret; 764 return ret;
736} 765}
737 766
738int wl12xx_cmd_role_stop_ap(struct wl1271 *wl) 767int wl12xx_cmd_role_stop_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif)
739{ 768{
740 struct wl12xx_cmd_role_stop *cmd; 769 struct wl12xx_cmd_role_stop *cmd;
741 int ret; 770 int ret;
@@ -746,9 +775,9 @@ int wl12xx_cmd_role_stop_ap(struct wl1271 *wl)
746 goto out; 775 goto out;
747 } 776 }
748 777
749 wl1271_debug(DEBUG_CMD, "cmd role stop ap %d", wl->role_id); 778 wl1271_debug(DEBUG_CMD, "cmd role stop ap %d", wlvif->role_id);
750 779
751 cmd->role_id = wl->role_id; 780 cmd->role_id = wlvif->role_id;
752 781
753 ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0); 782 ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
754 if (ret < 0) { 783 if (ret < 0) {
@@ -756,8 +785,8 @@ int wl12xx_cmd_role_stop_ap(struct wl1271 *wl)
756 goto out_free; 785 goto out_free;
757 } 786 }
758 787
759 wl12xx_free_link(wl, &wl->ap_bcast_hlid); 788 wl12xx_free_link(wl, wlvif, &wlvif->ap.bcast_hlid);
760 wl12xx_free_link(wl, &wl->ap_global_hlid); 789 wl12xx_free_link(wl, wlvif, &wlvif->ap.global_hlid);
761 790
762out_free: 791out_free:
763 kfree(cmd); 792 kfree(cmd);
@@ -766,10 +795,11 @@ out:
766 return ret; 795 return ret;
767} 796}
768 797
769int wl12xx_cmd_role_start_ibss(struct wl1271 *wl) 798int wl12xx_cmd_role_start_ibss(struct wl1271 *wl, struct wl12xx_vif *wlvif)
770{ 799{
800 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
771 struct wl12xx_cmd_role_start *cmd; 801 struct wl12xx_cmd_role_start *cmd;
772 struct ieee80211_bss_conf *bss_conf = &wl->vif->bss_conf; 802 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
773 int ret; 803 int ret;
774 804
775 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 805 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
@@ -778,35 +808,36 @@ int wl12xx_cmd_role_start_ibss(struct wl1271 *wl)
778 goto out; 808 goto out;
779 } 809 }
780 810
781 wl1271_debug(DEBUG_CMD, "cmd role start ibss %d", wl->role_id); 811 wl1271_debug(DEBUG_CMD, "cmd role start ibss %d", wlvif->role_id);
782 812
783 cmd->role_id = wl->role_id; 813 cmd->role_id = wlvif->role_id;
784 if (wl->band == IEEE80211_BAND_5GHZ) 814 if (wlvif->band == IEEE80211_BAND_5GHZ)
785 cmd->band = WL12XX_BAND_5GHZ; 815 cmd->band = WL12XX_BAND_5GHZ;
786 cmd->channel = wl->channel; 816 cmd->channel = wlvif->channel;
787 cmd->ibss.basic_rate_set = cpu_to_le32(wl->basic_rate_set); 817 cmd->ibss.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
788 cmd->ibss.beacon_interval = cpu_to_le16(wl->beacon_int); 818 cmd->ibss.beacon_interval = cpu_to_le16(wlvif->beacon_int);
789 cmd->ibss.dtim_interval = bss_conf->dtim_period; 819 cmd->ibss.dtim_interval = bss_conf->dtim_period;
790 cmd->ibss.ssid_type = WL12XX_SSID_TYPE_ANY; 820 cmd->ibss.ssid_type = WL12XX_SSID_TYPE_ANY;
791 cmd->ibss.ssid_len = wl->ssid_len; 821 cmd->ibss.ssid_len = wlvif->ssid_len;
792 memcpy(cmd->ibss.ssid, wl->ssid, wl->ssid_len); 822 memcpy(cmd->ibss.ssid, wlvif->ssid, wlvif->ssid_len);
793 memcpy(cmd->ibss.bssid, wl->bssid, ETH_ALEN); 823 memcpy(cmd->ibss.bssid, vif->bss_conf.bssid, ETH_ALEN);
794 cmd->sta.local_rates = cpu_to_le32(wl->rate_set); 824 cmd->sta.local_rates = cpu_to_le32(wlvif->rate_set);
795 825
796 if (wl->sta_hlid == WL12XX_INVALID_LINK_ID) { 826 if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) {
797 ret = wl12xx_allocate_link(wl, &wl->sta_hlid); 827 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->sta.hlid);
798 if (ret) 828 if (ret)
799 goto out_free; 829 goto out_free;
800 } 830 }
801 cmd->ibss.hlid = wl->sta_hlid; 831 cmd->ibss.hlid = wlvif->sta.hlid;
802 cmd->ibss.remote_rates = cpu_to_le32(wl->rate_set); 832 cmd->ibss.remote_rates = cpu_to_le32(wlvif->rate_set);
803 833
804 wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d " 834 wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d "
805 "basic_rate_set: 0x%x, remote_rates: 0x%x", 835 "basic_rate_set: 0x%x, remote_rates: 0x%x",
806 wl->role_id, cmd->sta.hlid, cmd->sta.session, 836 wlvif->role_id, cmd->sta.hlid, cmd->sta.session,
807 wl->basic_rate_set, wl->rate_set); 837 wlvif->basic_rate_set, wlvif->rate_set);
808 838
809 wl1271_debug(DEBUG_CMD, "wl->bssid = %pM", wl->bssid); 839 wl1271_debug(DEBUG_CMD, "vif->bss_conf.bssid = %pM",
840 vif->bss_conf.bssid);
810 841
811 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0); 842 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
812 if (ret < 0) { 843 if (ret < 0) {
@@ -818,7 +849,7 @@ int wl12xx_cmd_role_start_ibss(struct wl1271 *wl)
818 849
819err_hlid: 850err_hlid:
820 /* clear links on error. */ 851 /* clear links on error. */
821 wl12xx_free_link(wl, &wl->sta_hlid); 852 wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
822 853
823out_free: 854out_free:
824 kfree(cmd); 855 kfree(cmd);
@@ -962,7 +993,8 @@ out:
962 return ret; 993 return ret;
963} 994}
964 995
965int wl1271_cmd_ps_mode(struct wl1271 *wl, u8 ps_mode) 996int wl1271_cmd_ps_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif,
997 u8 ps_mode)
966{ 998{
967 struct wl1271_cmd_ps_params *ps_params = NULL; 999 struct wl1271_cmd_ps_params *ps_params = NULL;
968 int ret = 0; 1000 int ret = 0;
@@ -975,7 +1007,7 @@ int wl1271_cmd_ps_mode(struct wl1271 *wl, u8 ps_mode)
975 goto out; 1007 goto out;
976 } 1008 }
977 1009
978 ps_params->role_id = wl->role_id; 1010 ps_params->role_id = wlvif->role_id;
979 ps_params->ps_mode = ps_mode; 1011 ps_params->ps_mode = ps_mode;
980 1012
981 ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params, 1013 ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params,
@@ -1030,7 +1062,7 @@ out:
1030 return ret; 1062 return ret;
1031} 1063}
1032 1064
1033int wl1271_cmd_build_null_data(struct wl1271 *wl) 1065int wl12xx_cmd_build_null_data(struct wl1271 *wl, struct wl12xx_vif *wlvif)
1034{ 1066{
1035 struct sk_buff *skb = NULL; 1067 struct sk_buff *skb = NULL;
1036 int size; 1068 int size;
@@ -1038,11 +1070,12 @@ int wl1271_cmd_build_null_data(struct wl1271 *wl)
1038 int ret = -ENOMEM; 1070 int ret = -ENOMEM;
1039 1071
1040 1072
1041 if (wl->bss_type == BSS_TYPE_IBSS) { 1073 if (wlvif->bss_type == BSS_TYPE_IBSS) {
1042 size = sizeof(struct wl12xx_null_data_template); 1074 size = sizeof(struct wl12xx_null_data_template);
1043 ptr = NULL; 1075 ptr = NULL;
1044 } else { 1076 } else {
1045 skb = ieee80211_nullfunc_get(wl->hw, wl->vif); 1077 skb = ieee80211_nullfunc_get(wl->hw,
1078 wl12xx_wlvif_to_vif(wlvif));
1046 if (!skb) 1079 if (!skb)
1047 goto out; 1080 goto out;
1048 size = skb->len; 1081 size = skb->len;
@@ -1050,7 +1083,7 @@ int wl1271_cmd_build_null_data(struct wl1271 *wl)
1050 } 1083 }
1051 1084
1052 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, ptr, size, 0, 1085 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, ptr, size, 0,
1053 wl->basic_rate); 1086 wlvif->basic_rate);
1054 1087
1055out: 1088out:
1056 dev_kfree_skb(skb); 1089 dev_kfree_skb(skb);
@@ -1061,19 +1094,21 @@ out:
1061 1094
1062} 1095}
1063 1096
1064int wl1271_cmd_build_klv_null_data(struct wl1271 *wl) 1097int wl12xx_cmd_build_klv_null_data(struct wl1271 *wl,
1098 struct wl12xx_vif *wlvif)
1065{ 1099{
1100 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
1066 struct sk_buff *skb = NULL; 1101 struct sk_buff *skb = NULL;
1067 int ret = -ENOMEM; 1102 int ret = -ENOMEM;
1068 1103
1069 skb = ieee80211_nullfunc_get(wl->hw, wl->vif); 1104 skb = ieee80211_nullfunc_get(wl->hw, vif);
1070 if (!skb) 1105 if (!skb)
1071 goto out; 1106 goto out;
1072 1107
1073 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV, 1108 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV,
1074 skb->data, skb->len, 1109 skb->data, skb->len,
1075 CMD_TEMPL_KLV_IDX_NULL_DATA, 1110 CMD_TEMPL_KLV_IDX_NULL_DATA,
1076 wl->basic_rate); 1111 wlvif->basic_rate);
1077 1112
1078out: 1113out:
1079 dev_kfree_skb(skb); 1114 dev_kfree_skb(skb);
@@ -1084,32 +1119,35 @@ out:
1084 1119
1085} 1120}
1086 1121
1087int wl1271_cmd_build_ps_poll(struct wl1271 *wl, u16 aid) 1122int wl1271_cmd_build_ps_poll(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1123 u16 aid)
1088{ 1124{
1125 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
1089 struct sk_buff *skb; 1126 struct sk_buff *skb;
1090 int ret = 0; 1127 int ret = 0;
1091 1128
1092 skb = ieee80211_pspoll_get(wl->hw, wl->vif); 1129 skb = ieee80211_pspoll_get(wl->hw, vif);
1093 if (!skb) 1130 if (!skb)
1094 goto out; 1131 goto out;
1095 1132
1096 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, skb->data, 1133 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, skb->data,
1097 skb->len, 0, wl->basic_rate_set); 1134 skb->len, 0, wlvif->basic_rate_set);
1098 1135
1099out: 1136out:
1100 dev_kfree_skb(skb); 1137 dev_kfree_skb(skb);
1101 return ret; 1138 return ret;
1102} 1139}
1103 1140
1104int wl1271_cmd_build_probe_req(struct wl1271 *wl, 1141int wl1271_cmd_build_probe_req(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1105 const u8 *ssid, size_t ssid_len, 1142 const u8 *ssid, size_t ssid_len,
1106 const u8 *ie, size_t ie_len, u8 band) 1143 const u8 *ie, size_t ie_len, u8 band)
1107{ 1144{
1145 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
1108 struct sk_buff *skb; 1146 struct sk_buff *skb;
1109 int ret; 1147 int ret;
1110 u32 rate; 1148 u32 rate;
1111 1149
1112 skb = ieee80211_probereq_get(wl->hw, wl->vif, ssid, ssid_len, 1150 skb = ieee80211_probereq_get(wl->hw, vif, ssid, ssid_len,
1113 ie, ie_len); 1151 ie, ie_len);
1114 if (!skb) { 1152 if (!skb) {
1115 ret = -ENOMEM; 1153 ret = -ENOMEM;
@@ -1118,7 +1156,7 @@ int wl1271_cmd_build_probe_req(struct wl1271 *wl,
1118 1156
1119 wl1271_dump(DEBUG_SCAN, "PROBE REQ: ", skb->data, skb->len); 1157 wl1271_dump(DEBUG_SCAN, "PROBE REQ: ", skb->data, skb->len);
1120 1158
1121 rate = wl1271_tx_min_rate_get(wl, wl->bitrate_masks[band]); 1159 rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[band]);
1122 if (band == IEEE80211_BAND_2GHZ) 1160 if (band == IEEE80211_BAND_2GHZ)
1123 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4, 1161 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4,
1124 skb->data, skb->len, 0, rate); 1162 skb->data, skb->len, 0, rate);
@@ -1132,20 +1170,22 @@ out:
1132} 1170}
1133 1171
1134struct sk_buff *wl1271_cmd_build_ap_probe_req(struct wl1271 *wl, 1172struct sk_buff *wl1271_cmd_build_ap_probe_req(struct wl1271 *wl,
1173 struct wl12xx_vif *wlvif,
1135 struct sk_buff *skb) 1174 struct sk_buff *skb)
1136{ 1175{
1176 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
1137 int ret; 1177 int ret;
1138 u32 rate; 1178 u32 rate;
1139 1179
1140 if (!skb) 1180 if (!skb)
1141 skb = ieee80211_ap_probereq_get(wl->hw, wl->vif); 1181 skb = ieee80211_ap_probereq_get(wl->hw, vif);
1142 if (!skb) 1182 if (!skb)
1143 goto out; 1183 goto out;
1144 1184
1145 wl1271_dump(DEBUG_SCAN, "AP PROBE REQ: ", skb->data, skb->len); 1185 wl1271_dump(DEBUG_SCAN, "AP PROBE REQ: ", skb->data, skb->len);
1146 1186
1147 rate = wl1271_tx_min_rate_get(wl, wl->bitrate_masks[wl->band]); 1187 rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[wlvif->band]);
1148 if (wl->band == IEEE80211_BAND_2GHZ) 1188 if (wlvif->band == IEEE80211_BAND_2GHZ)
1149 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4, 1189 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4,
1150 skb->data, skb->len, 0, rate); 1190 skb->data, skb->len, 0, rate);
1151 else 1191 else
@@ -1159,9 +1199,11 @@ out:
1159 return skb; 1199 return skb;
1160} 1200}
1161 1201
1162int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, __be32 ip_addr) 1202int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1203 __be32 ip_addr)
1163{ 1204{
1164 int ret; 1205 int ret;
1206 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
1165 struct wl12xx_arp_rsp_template tmpl; 1207 struct wl12xx_arp_rsp_template tmpl;
1166 struct ieee80211_hdr_3addr *hdr; 1208 struct ieee80211_hdr_3addr *hdr;
1167 struct arphdr *arp_hdr; 1209 struct arphdr *arp_hdr;
@@ -1173,8 +1215,8 @@ int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, __be32 ip_addr)
1173 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA | 1215 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
1174 IEEE80211_STYPE_DATA | 1216 IEEE80211_STYPE_DATA |
1175 IEEE80211_FCTL_TODS); 1217 IEEE80211_FCTL_TODS);
1176 memcpy(hdr->addr1, wl->vif->bss_conf.bssid, ETH_ALEN); 1218 memcpy(hdr->addr1, vif->bss_conf.bssid, ETH_ALEN);
1177 memcpy(hdr->addr2, wl->vif->addr, ETH_ALEN); 1219 memcpy(hdr->addr2, vif->addr, ETH_ALEN);
1178 memset(hdr->addr3, 0xff, ETH_ALEN); 1220 memset(hdr->addr3, 0xff, ETH_ALEN);
1179 1221
1180 /* llc layer */ 1222 /* llc layer */
@@ -1190,25 +1232,26 @@ int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, __be32 ip_addr)
1190 arp_hdr->ar_op = cpu_to_be16(ARPOP_REPLY); 1232 arp_hdr->ar_op = cpu_to_be16(ARPOP_REPLY);
1191 1233
1192 /* arp payload */ 1234 /* arp payload */
1193 memcpy(tmpl.sender_hw, wl->vif->addr, ETH_ALEN); 1235 memcpy(tmpl.sender_hw, vif->addr, ETH_ALEN);
1194 tmpl.sender_ip = ip_addr; 1236 tmpl.sender_ip = ip_addr;
1195 1237
1196 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_ARP_RSP, 1238 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_ARP_RSP,
1197 &tmpl, sizeof(tmpl), 0, 1239 &tmpl, sizeof(tmpl), 0,
1198 wl->basic_rate); 1240 wlvif->basic_rate);
1199 1241
1200 return ret; 1242 return ret;
1201} 1243}
1202 1244
1203int wl1271_build_qos_null_data(struct wl1271 *wl) 1245int wl1271_build_qos_null_data(struct wl1271 *wl, struct ieee80211_vif *vif)
1204{ 1246{
1247 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
1205 struct ieee80211_qos_hdr template; 1248 struct ieee80211_qos_hdr template;
1206 1249
1207 memset(&template, 0, sizeof(template)); 1250 memset(&template, 0, sizeof(template));
1208 1251
1209 memcpy(template.addr1, wl->bssid, ETH_ALEN); 1252 memcpy(template.addr1, vif->bss_conf.bssid, ETH_ALEN);
1210 memcpy(template.addr2, wl->mac_addr, ETH_ALEN); 1253 memcpy(template.addr2, vif->addr, ETH_ALEN);
1211 memcpy(template.addr3, wl->bssid, ETH_ALEN); 1254 memcpy(template.addr3, vif->bss_conf.bssid, ETH_ALEN);
1212 1255
1213 template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA | 1256 template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
1214 IEEE80211_STYPE_QOS_NULLFUNC | 1257 IEEE80211_STYPE_QOS_NULLFUNC |
@@ -1219,7 +1262,7 @@ int wl1271_build_qos_null_data(struct wl1271 *wl)
1219 1262
1220 return wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, &template, 1263 return wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, &template,
1221 sizeof(template), 0, 1264 sizeof(template), 0,
1222 wl->basic_rate); 1265 wlvif->basic_rate);
1223} 1266}
1224 1267
1225int wl12xx_cmd_set_default_wep_key(struct wl1271 *wl, u8 id, u8 hlid) 1268int wl12xx_cmd_set_default_wep_key(struct wl1271 *wl, u8 id, u8 hlid)
@@ -1253,7 +1296,8 @@ out:
1253 return ret; 1296 return ret;
1254} 1297}
1255 1298
1256int wl1271_cmd_set_sta_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type, 1299int wl1271_cmd_set_sta_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1300 u16 action, u8 id, u8 key_type,
1257 u8 key_size, const u8 *key, const u8 *addr, 1301 u8 key_size, const u8 *key, const u8 *addr,
1258 u32 tx_seq_32, u16 tx_seq_16) 1302 u32 tx_seq_32, u16 tx_seq_16)
1259{ 1303{
@@ -1261,7 +1305,7 @@ int wl1271_cmd_set_sta_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
1261 int ret = 0; 1305 int ret = 0;
1262 1306
1263 /* hlid might have already been deleted */ 1307 /* hlid might have already been deleted */
1264 if (wl->sta_hlid == WL12XX_INVALID_LINK_ID) 1308 if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID)
1265 return 0; 1309 return 0;
1266 1310
1267 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 1311 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
@@ -1270,7 +1314,7 @@ int wl1271_cmd_set_sta_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
1270 goto out; 1314 goto out;
1271 } 1315 }
1272 1316
1273 cmd->hlid = wl->sta_hlid; 1317 cmd->hlid = wlvif->sta.hlid;
1274 1318
1275 if (key_type == KEY_WEP) 1319 if (key_type == KEY_WEP)
1276 cmd->lid_key_type = WEP_DEFAULT_LID_TYPE; 1320 cmd->lid_key_type = WEP_DEFAULT_LID_TYPE;
@@ -1321,9 +1365,10 @@ out:
1321 * TODO: merge with sta/ibss into 1 set_key function. 1365 * TODO: merge with sta/ibss into 1 set_key function.
1322 * note there are slight diffs 1366 * note there are slight diffs
1323 */ 1367 */
1324int wl1271_cmd_set_ap_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type, 1368int wl1271_cmd_set_ap_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1325 u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32, 1369 u16 action, u8 id, u8 key_type,
1326 u16 tx_seq_16) 1370 u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32,
1371 u16 tx_seq_16)
1327{ 1372{
1328 struct wl1271_cmd_set_keys *cmd; 1373 struct wl1271_cmd_set_keys *cmd;
1329 int ret = 0; 1374 int ret = 0;
@@ -1333,7 +1378,7 @@ int wl1271_cmd_set_ap_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
1333 if (!cmd) 1378 if (!cmd)
1334 return -ENOMEM; 1379 return -ENOMEM;
1335 1380
1336 if (hlid == wl->ap_bcast_hlid) { 1381 if (hlid == wlvif->ap.bcast_hlid) {
1337 if (key_type == KEY_WEP) 1382 if (key_type == KEY_WEP)
1338 lid_type = WEP_DEFAULT_LID_TYPE; 1383 lid_type = WEP_DEFAULT_LID_TYPE;
1339 else 1384 else
@@ -1411,7 +1456,8 @@ out:
1411 return ret; 1456 return ret;
1412} 1457}
1413 1458
1414int wl12xx_cmd_add_peer(struct wl1271 *wl, struct ieee80211_sta *sta, u8 hlid) 1459int wl12xx_cmd_add_peer(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1460 struct ieee80211_sta *sta, u8 hlid)
1415{ 1461{
1416 struct wl12xx_cmd_add_peer *cmd; 1462 struct wl12xx_cmd_add_peer *cmd;
1417 int i, ret; 1463 int i, ret;
@@ -1438,13 +1484,13 @@ int wl12xx_cmd_add_peer(struct wl1271 *wl, struct ieee80211_sta *sta, u8 hlid)
1438 else 1484 else
1439 cmd->psd_type[i] = WL1271_PSD_LEGACY; 1485 cmd->psd_type[i] = WL1271_PSD_LEGACY;
1440 1486
1441 sta_rates = sta->supp_rates[wl->band]; 1487 sta_rates = sta->supp_rates[wlvif->band];
1442 if (sta->ht_cap.ht_supported) 1488 if (sta->ht_cap.ht_supported)
1443 sta_rates |= sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET; 1489 sta_rates |= sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET;
1444 1490
1445 cmd->supported_rates = 1491 cmd->supported_rates =
1446 cpu_to_le32(wl1271_tx_enabled_rates_get(wl, sta_rates, 1492 cpu_to_le32(wl1271_tx_enabled_rates_get(wl, sta_rates,
1447 wl->band)); 1493 wlvif->band));
1448 1494
1449 wl1271_debug(DEBUG_CMD, "new peer rates=0x%x queues=0x%x", 1495 wl1271_debug(DEBUG_CMD, "new peer rates=0x%x queues=0x%x",
1450 cmd->supported_rates, sta->uapsd_queues); 1496 cmd->supported_rates, sta->uapsd_queues);
@@ -1584,12 +1630,13 @@ out:
1584 return ret; 1630 return ret;
1585} 1631}
1586 1632
1587static int wl12xx_cmd_roc(struct wl1271 *wl, u8 role_id) 1633static int wl12xx_cmd_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1634 u8 role_id)
1588{ 1635{
1589 struct wl12xx_cmd_roc *cmd; 1636 struct wl12xx_cmd_roc *cmd;
1590 int ret = 0; 1637 int ret = 0;
1591 1638
1592 wl1271_debug(DEBUG_CMD, "cmd roc %d (%d)", wl->channel, role_id); 1639 wl1271_debug(DEBUG_CMD, "cmd roc %d (%d)", wlvif->channel, role_id);
1593 1640
1594 if (WARN_ON(role_id == WL12XX_INVALID_ROLE_ID)) 1641 if (WARN_ON(role_id == WL12XX_INVALID_ROLE_ID))
1595 return -EINVAL; 1642 return -EINVAL;
@@ -1601,8 +1648,8 @@ static int wl12xx_cmd_roc(struct wl1271 *wl, u8 role_id)
1601 } 1648 }
1602 1649
1603 cmd->role_id = role_id; 1650 cmd->role_id = role_id;
1604 cmd->channel = wl->channel; 1651 cmd->channel = wlvif->channel;
1605 switch (wl->band) { 1652 switch (wlvif->band) {
1606 case IEEE80211_BAND_2GHZ: 1653 case IEEE80211_BAND_2GHZ:
1607 cmd->band = RADIO_BAND_2_4GHZ; 1654 cmd->band = RADIO_BAND_2_4GHZ;
1608 break; 1655 break;
@@ -1610,7 +1657,7 @@ static int wl12xx_cmd_roc(struct wl1271 *wl, u8 role_id)
1610 cmd->band = RADIO_BAND_5GHZ; 1657 cmd->band = RADIO_BAND_5GHZ;
1611 break; 1658 break;
1612 default: 1659 default:
1613 wl1271_error("roc - unknown band: %d", (int)wl->band); 1660 wl1271_error("roc - unknown band: %d", (int)wlvif->band);
1614 ret = -EINVAL; 1661 ret = -EINVAL;
1615 goto out_free; 1662 goto out_free;
1616 } 1663 }
@@ -1657,14 +1704,14 @@ out:
1657 return ret; 1704 return ret;
1658} 1705}
1659 1706
1660int wl12xx_roc(struct wl1271 *wl, u8 role_id) 1707int wl12xx_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 role_id)
1661{ 1708{
1662 int ret = 0; 1709 int ret = 0;
1663 1710
1664 if (WARN_ON(test_bit(role_id, wl->roc_map))) 1711 if (WARN_ON(test_bit(role_id, wl->roc_map)))
1665 return 0; 1712 return 0;
1666 1713
1667 ret = wl12xx_cmd_roc(wl, role_id); 1714 ret = wl12xx_cmd_roc(wl, wlvif, role_id);
1668 if (ret < 0) 1715 if (ret < 0)
1669 goto out; 1716 goto out;
1670 1717
@@ -1753,3 +1800,50 @@ out_free:
1753out: 1800out:
1754 return ret; 1801 return ret;
1755} 1802}
1803
1804/* start dev role and roc on its channel */
1805int wl12xx_start_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif)
1806{
1807 int ret;
1808
1809 if (WARN_ON(!(wlvif->bss_type == BSS_TYPE_STA_BSS ||
1810 wlvif->bss_type == BSS_TYPE_IBSS)))
1811 return -EINVAL;
1812
1813 ret = wl12xx_cmd_role_start_dev(wl, wlvif);
1814 if (ret < 0)
1815 goto out;
1816
1817 ret = wl12xx_roc(wl, wlvif, wlvif->dev_role_id);
1818 if (ret < 0)
1819 goto out_stop;
1820
1821 return 0;
1822
1823out_stop:
1824 wl12xx_cmd_role_stop_dev(wl, wlvif);
1825out:
1826 return ret;
1827}
1828
1829/* croc dev hlid, and stop the role */
1830int wl12xx_stop_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif)
1831{
1832 int ret;
1833
1834 if (WARN_ON(!(wlvif->bss_type == BSS_TYPE_STA_BSS ||
1835 wlvif->bss_type == BSS_TYPE_IBSS)))
1836 return -EINVAL;
1837
1838 if (test_bit(wlvif->dev_role_id, wl->roc_map)) {
1839 ret = wl12xx_croc(wl, wlvif->dev_role_id);
1840 if (ret < 0)
1841 goto out;
1842 }
1843
1844 ret = wl12xx_cmd_role_stop_dev(wl, wlvif);
1845 if (ret < 0)
1846 goto out;
1847out:
1848 return ret;
1849}
diff --git a/drivers/net/wireless/wl12xx/cmd.h b/drivers/net/wireless/wl12xx/cmd.h
index b7bd42769aa..3f7d0b93c24 100644
--- a/drivers/net/wireless/wl12xx/cmd.h
+++ b/drivers/net/wireless/wl12xx/cmd.h
@@ -36,45 +36,54 @@ int wl128x_cmd_general_parms(struct wl1271 *wl);
36int wl1271_cmd_radio_parms(struct wl1271 *wl); 36int wl1271_cmd_radio_parms(struct wl1271 *wl);
37int wl128x_cmd_radio_parms(struct wl1271 *wl); 37int wl128x_cmd_radio_parms(struct wl1271 *wl);
38int wl1271_cmd_ext_radio_parms(struct wl1271 *wl); 38int wl1271_cmd_ext_radio_parms(struct wl1271 *wl);
39int wl12xx_cmd_role_enable(struct wl1271 *wl, u8 role_type, u8 *role_id); 39int wl12xx_cmd_role_enable(struct wl1271 *wl, u8 *addr, u8 role_type,
40 u8 *role_id);
40int wl12xx_cmd_role_disable(struct wl1271 *wl, u8 *role_id); 41int wl12xx_cmd_role_disable(struct wl1271 *wl, u8 *role_id);
41int wl12xx_cmd_role_start_dev(struct wl1271 *wl); 42int wl12xx_cmd_role_start_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif);
42int wl12xx_cmd_role_stop_dev(struct wl1271 *wl); 43int wl12xx_cmd_role_stop_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif);
43int wl12xx_cmd_role_start_sta(struct wl1271 *wl); 44int wl12xx_cmd_role_start_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif);
44int wl12xx_cmd_role_stop_sta(struct wl1271 *wl); 45int wl12xx_cmd_role_stop_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif);
45int wl12xx_cmd_role_start_ap(struct wl1271 *wl); 46int wl12xx_cmd_role_start_ibss(struct wl1271 *wl, struct wl12xx_vif *wlvif);
46int wl12xx_cmd_role_stop_ap(struct wl1271 *wl); 47int wl12xx_start_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif);
47int wl12xx_cmd_role_start_ibss(struct wl1271 *wl); 48int wl12xx_stop_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif);
48int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer); 49int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer);
49int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len); 50int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len);
50int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len); 51int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len);
51int wl1271_cmd_data_path(struct wl1271 *wl, bool enable); 52int wl1271_cmd_data_path(struct wl1271 *wl, bool enable);
52int wl1271_cmd_ps_mode(struct wl1271 *wl, u8 ps_mode); 53int wl1271_cmd_ps_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif,
54 u8 ps_mode);
53int wl1271_cmd_read_memory(struct wl1271 *wl, u32 addr, void *answer, 55int wl1271_cmd_read_memory(struct wl1271 *wl, u32 addr, void *answer,
54 size_t len); 56 size_t len);
55int wl1271_cmd_template_set(struct wl1271 *wl, u16 template_id, 57int wl1271_cmd_template_set(struct wl1271 *wl, u16 template_id,
56 void *buf, size_t buf_len, int index, u32 rates); 58 void *buf, size_t buf_len, int index, u32 rates);
57int wl1271_cmd_build_null_data(struct wl1271 *wl); 59int wl12xx_cmd_build_null_data(struct wl1271 *wl, struct wl12xx_vif *wlvif);
58int wl1271_cmd_build_ps_poll(struct wl1271 *wl, u16 aid); 60int wl1271_cmd_build_ps_poll(struct wl1271 *wl, struct wl12xx_vif *wlvif,
59int wl1271_cmd_build_probe_req(struct wl1271 *wl, 61 u16 aid);
62int wl1271_cmd_build_probe_req(struct wl1271 *wl, struct wl12xx_vif *wlvif,
60 const u8 *ssid, size_t ssid_len, 63 const u8 *ssid, size_t ssid_len,
61 const u8 *ie, size_t ie_len, u8 band); 64 const u8 *ie, size_t ie_len, u8 band);
62struct sk_buff *wl1271_cmd_build_ap_probe_req(struct wl1271 *wl, 65struct sk_buff *wl1271_cmd_build_ap_probe_req(struct wl1271 *wl,
66 struct wl12xx_vif *wlvif,
63 struct sk_buff *skb); 67 struct sk_buff *skb);
64int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, __be32 ip_addr); 68int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, struct wl12xx_vif *wlvif,
65int wl1271_build_qos_null_data(struct wl1271 *wl); 69 __be32 ip_addr);
66int wl1271_cmd_build_klv_null_data(struct wl1271 *wl); 70int wl1271_build_qos_null_data(struct wl1271 *wl, struct ieee80211_vif *vif);
71int wl12xx_cmd_build_klv_null_data(struct wl1271 *wl,
72 struct wl12xx_vif *wlvif);
67int wl12xx_cmd_set_default_wep_key(struct wl1271 *wl, u8 id, u8 hlid); 73int wl12xx_cmd_set_default_wep_key(struct wl1271 *wl, u8 id, u8 hlid);
68int wl1271_cmd_set_sta_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type, 74int wl1271_cmd_set_sta_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
75 u16 action, u8 id, u8 key_type,
69 u8 key_size, const u8 *key, const u8 *addr, 76 u8 key_size, const u8 *key, const u8 *addr,
70 u32 tx_seq_32, u16 tx_seq_16); 77 u32 tx_seq_32, u16 tx_seq_16);
71int wl1271_cmd_set_ap_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type, 78int wl1271_cmd_set_ap_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
79 u16 action, u8 id, u8 key_type,
72 u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32, 80 u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32,
73 u16 tx_seq_16); 81 u16 tx_seq_16);
74int wl12xx_cmd_set_peer_state(struct wl1271 *wl, u8 hlid); 82int wl12xx_cmd_set_peer_state(struct wl1271 *wl, u8 hlid);
75int wl12xx_roc(struct wl1271 *wl, u8 role_id); 83int wl12xx_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 role_id);
76int wl12xx_croc(struct wl1271 *wl, u8 role_id); 84int wl12xx_croc(struct wl1271 *wl, u8 role_id);
77int wl12xx_cmd_add_peer(struct wl1271 *wl, struct ieee80211_sta *sta, u8 hlid); 85int wl12xx_cmd_add_peer(struct wl1271 *wl, struct wl12xx_vif *wlvif,
86 struct ieee80211_sta *sta, u8 hlid);
78int wl12xx_cmd_remove_peer(struct wl1271 *wl, u8 hlid); 87int wl12xx_cmd_remove_peer(struct wl1271 *wl, u8 hlid);
79int wl12xx_cmd_config_fwlog(struct wl1271 *wl); 88int wl12xx_cmd_config_fwlog(struct wl1271 *wl);
80int wl12xx_cmd_start_fwlog(struct wl1271 *wl); 89int wl12xx_cmd_start_fwlog(struct wl1271 *wl);
@@ -82,6 +91,9 @@ int wl12xx_cmd_stop_fwlog(struct wl1271 *wl);
82int wl12xx_cmd_channel_switch(struct wl1271 *wl, 91int wl12xx_cmd_channel_switch(struct wl1271 *wl,
83 struct ieee80211_channel_switch *ch_switch); 92 struct ieee80211_channel_switch *ch_switch);
84int wl12xx_cmd_stop_channel_switch(struct wl1271 *wl); 93int wl12xx_cmd_stop_channel_switch(struct wl1271 *wl);
94int wl12xx_allocate_link(struct wl1271 *wl, struct wl12xx_vif *wlvif,
95 u8 *hlid);
96void wl12xx_free_link(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 *hlid);
85 97
86enum wl1271_commands { 98enum wl1271_commands {
87 CMD_INTERROGATE = 1, /*use this to read information elements*/ 99 CMD_INTERROGATE = 1, /*use this to read information elements*/
diff --git a/drivers/net/wireless/wl12xx/conf.h b/drivers/net/wireless/wl12xx/conf.h
index 04bb8fbf93f..1bcfb017058 100644
--- a/drivers/net/wireless/wl12xx/conf.h
+++ b/drivers/net/wireless/wl12xx/conf.h
@@ -440,6 +440,10 @@ struct conf_rx_settings {
440 CONF_HW_BIT_RATE_36MBPS | CONF_HW_BIT_RATE_48MBPS | \ 440 CONF_HW_BIT_RATE_36MBPS | CONF_HW_BIT_RATE_48MBPS | \
441 CONF_HW_BIT_RATE_54MBPS) 441 CONF_HW_BIT_RATE_54MBPS)
442 442
443#define CONF_TX_CCK_RATES (CONF_HW_BIT_RATE_1MBPS | \
444 CONF_HW_BIT_RATE_2MBPS | CONF_HW_BIT_RATE_5_5MBPS | \
445 CONF_HW_BIT_RATE_11MBPS)
446
443#define CONF_TX_OFDM_RATES (CONF_HW_BIT_RATE_6MBPS | \ 447#define CONF_TX_OFDM_RATES (CONF_HW_BIT_RATE_6MBPS | \
444 CONF_HW_BIT_RATE_12MBPS | CONF_HW_BIT_RATE_24MBPS | \ 448 CONF_HW_BIT_RATE_12MBPS | CONF_HW_BIT_RATE_24MBPS | \
445 CONF_HW_BIT_RATE_36MBPS | CONF_HW_BIT_RATE_48MBPS | \ 449 CONF_HW_BIT_RATE_36MBPS | CONF_HW_BIT_RATE_48MBPS | \
diff --git a/drivers/net/wireless/wl12xx/debug.h b/drivers/net/wireless/wl12xx/debug.h
new file mode 100644
index 00000000000..b85fd8c41e8
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/debug.h
@@ -0,0 +1,101 @@
1/*
2 * This file is part of wl12xx
3 *
4 * Copyright (C) 2011 Texas Instruments. All rights reserved.
5 * Copyright (C) 2008-2009 Nokia Corporation
6 *
7 * Contact: Luciano Coelho <coelho@ti.com>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */
24
25#ifndef __DEBUG_H__
26#define __DEBUG_H__
27
28#include <linux/bitops.h>
29#include <linux/printk.h>
30
31#define DRIVER_NAME "wl12xx"
32#define DRIVER_PREFIX DRIVER_NAME ": "
33
34enum {
35 DEBUG_NONE = 0,
36 DEBUG_IRQ = BIT(0),
37 DEBUG_SPI = BIT(1),
38 DEBUG_BOOT = BIT(2),
39 DEBUG_MAILBOX = BIT(3),
40 DEBUG_TESTMODE = BIT(4),
41 DEBUG_EVENT = BIT(5),
42 DEBUG_TX = BIT(6),
43 DEBUG_RX = BIT(7),
44 DEBUG_SCAN = BIT(8),
45 DEBUG_CRYPT = BIT(9),
46 DEBUG_PSM = BIT(10),
47 DEBUG_MAC80211 = BIT(11),
48 DEBUG_CMD = BIT(12),
49 DEBUG_ACX = BIT(13),
50 DEBUG_SDIO = BIT(14),
51 DEBUG_FILTERS = BIT(15),
52 DEBUG_ADHOC = BIT(16),
53 DEBUG_AP = BIT(17),
54 DEBUG_MASTER = (DEBUG_ADHOC | DEBUG_AP),
55 DEBUG_ALL = ~0,
56};
57
58extern u32 wl12xx_debug_level;
59
60#define DEBUG_DUMP_LIMIT 1024
61
62#define wl1271_error(fmt, arg...) \
63 pr_err(DRIVER_PREFIX "ERROR " fmt "\n", ##arg)
64
65#define wl1271_warning(fmt, arg...) \
66 pr_warning(DRIVER_PREFIX "WARNING " fmt "\n", ##arg)
67
68#define wl1271_notice(fmt, arg...) \
69 pr_info(DRIVER_PREFIX fmt "\n", ##arg)
70
71#define wl1271_info(fmt, arg...) \
72 pr_info(DRIVER_PREFIX fmt "\n", ##arg)
73
74#define wl1271_debug(level, fmt, arg...) \
75 do { \
76 if (level & wl12xx_debug_level) \
77 pr_debug(DRIVER_PREFIX fmt "\n", ##arg); \
78 } while (0)
79
80/* TODO: use pr_debug_hex_dump when it becomes available */
81#define wl1271_dump(level, prefix, buf, len) \
82 do { \
83 if (level & wl12xx_debug_level) \
84 print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
85 DUMP_PREFIX_OFFSET, 16, 1, \
86 buf, \
87 min_t(size_t, len, DEBUG_DUMP_LIMIT), \
88 0); \
89 } while (0)
90
91#define wl1271_dump_ascii(level, prefix, buf, len) \
92 do { \
93 if (level & wl12xx_debug_level) \
94 print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
95 DUMP_PREFIX_OFFSET, 16, 1, \
96 buf, \
97 min_t(size_t, len, DEBUG_DUMP_LIMIT), \
98 true); \
99 } while (0)
100
101#endif /* __DEBUG_H__ */
diff --git a/drivers/net/wireless/wl12xx/debugfs.c b/drivers/net/wireless/wl12xx/debugfs.c
index 3999fd52830..2e14b436101 100644
--- a/drivers/net/wireless/wl12xx/debugfs.c
+++ b/drivers/net/wireless/wl12xx/debugfs.c
@@ -27,6 +27,7 @@
27#include <linux/slab.h> 27#include <linux/slab.h>
28 28
29#include "wl12xx.h" 29#include "wl12xx.h"
30#include "debug.h"
30#include "acx.h" 31#include "acx.h"
31#include "ps.h" 32#include "ps.h"
32#include "io.h" 33#include "io.h"
@@ -346,29 +347,14 @@ static ssize_t driver_state_read(struct file *file, char __user *user_buf,
346 DRIVER_STATE_PRINT_INT(tx_results_count); 347 DRIVER_STATE_PRINT_INT(tx_results_count);
347 DRIVER_STATE_PRINT_LHEX(flags); 348 DRIVER_STATE_PRINT_LHEX(flags);
348 DRIVER_STATE_PRINT_INT(tx_blocks_freed); 349 DRIVER_STATE_PRINT_INT(tx_blocks_freed);
349 DRIVER_STATE_PRINT_INT(tx_security_last_seq_lsb);
350 DRIVER_STATE_PRINT_INT(rx_counter); 350 DRIVER_STATE_PRINT_INT(rx_counter);
351 DRIVER_STATE_PRINT_INT(session_counter);
352 DRIVER_STATE_PRINT_INT(state); 351 DRIVER_STATE_PRINT_INT(state);
353 DRIVER_STATE_PRINT_INT(bss_type);
354 DRIVER_STATE_PRINT_INT(channel); 352 DRIVER_STATE_PRINT_INT(channel);
355 DRIVER_STATE_PRINT_HEX(rate_set);
356 DRIVER_STATE_PRINT_HEX(basic_rate_set);
357 DRIVER_STATE_PRINT_HEX(basic_rate);
358 DRIVER_STATE_PRINT_INT(band); 353 DRIVER_STATE_PRINT_INT(band);
359 DRIVER_STATE_PRINT_INT(beacon_int);
360 DRIVER_STATE_PRINT_INT(psm_entry_retry);
361 DRIVER_STATE_PRINT_INT(ps_poll_failures);
362 DRIVER_STATE_PRINT_INT(power_level); 354 DRIVER_STATE_PRINT_INT(power_level);
363 DRIVER_STATE_PRINT_INT(rssi_thold);
364 DRIVER_STATE_PRINT_INT(last_rssi_event);
365 DRIVER_STATE_PRINT_INT(sg_enabled); 355 DRIVER_STATE_PRINT_INT(sg_enabled);
366 DRIVER_STATE_PRINT_INT(enable_11a); 356 DRIVER_STATE_PRINT_INT(enable_11a);
367 DRIVER_STATE_PRINT_INT(noise); 357 DRIVER_STATE_PRINT_INT(noise);
368 DRIVER_STATE_PRINT_LHEX(ap_hlid_map[0]);
369 DRIVER_STATE_PRINT_INT(last_tx_hlid);
370 DRIVER_STATE_PRINT_INT(ba_support);
371 DRIVER_STATE_PRINT_HEX(ba_rx_bitmap);
372 DRIVER_STATE_PRINT_HEX(ap_fw_ps_map); 358 DRIVER_STATE_PRINT_HEX(ap_fw_ps_map);
373 DRIVER_STATE_PRINT_LHEX(ap_ps_map); 359 DRIVER_STATE_PRINT_LHEX(ap_ps_map);
374 DRIVER_STATE_PRINT_HEX(quirks); 360 DRIVER_STATE_PRINT_HEX(quirks);
@@ -399,6 +385,115 @@ static const struct file_operations driver_state_ops = {
399 .llseek = default_llseek, 385 .llseek = default_llseek,
400}; 386};
401 387
388static ssize_t vifs_state_read(struct file *file, char __user *user_buf,
389 size_t count, loff_t *ppos)
390{
391 struct wl1271 *wl = file->private_data;
392 struct wl12xx_vif *wlvif;
393 int ret, res = 0;
394 const int buf_size = 4096;
395 char *buf;
396 char tmp_buf[64];
397
398 buf = kzalloc(buf_size, GFP_KERNEL);
399 if (!buf)
400 return -ENOMEM;
401
402 mutex_lock(&wl->mutex);
403
404#define VIF_STATE_PRINT(x, fmt) \
405 (res += scnprintf(buf + res, buf_size - res, \
406 #x " = " fmt "\n", wlvif->x))
407
408#define VIF_STATE_PRINT_LONG(x) VIF_STATE_PRINT(x, "%ld")
409#define VIF_STATE_PRINT_INT(x) VIF_STATE_PRINT(x, "%d")
410#define VIF_STATE_PRINT_STR(x) VIF_STATE_PRINT(x, "%s")
411#define VIF_STATE_PRINT_LHEX(x) VIF_STATE_PRINT(x, "0x%lx")
412#define VIF_STATE_PRINT_LLHEX(x) VIF_STATE_PRINT(x, "0x%llx")
413#define VIF_STATE_PRINT_HEX(x) VIF_STATE_PRINT(x, "0x%x")
414
415#define VIF_STATE_PRINT_NSTR(x, len) \
416 do { \
417 memset(tmp_buf, 0, sizeof(tmp_buf)); \
418 memcpy(tmp_buf, wlvif->x, \
419 min_t(u8, len, sizeof(tmp_buf) - 1)); \
420 res += scnprintf(buf + res, buf_size - res, \
421 #x " = %s\n", tmp_buf); \
422 } while (0)
423
424 wl12xx_for_each_wlvif(wl, wlvif) {
425 VIF_STATE_PRINT_INT(role_id);
426 VIF_STATE_PRINT_INT(bss_type);
427 VIF_STATE_PRINT_LHEX(flags);
428 VIF_STATE_PRINT_INT(p2p);
429 VIF_STATE_PRINT_INT(dev_role_id);
430 VIF_STATE_PRINT_INT(dev_hlid);
431
432 if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
433 wlvif->bss_type == BSS_TYPE_IBSS) {
434 VIF_STATE_PRINT_INT(sta.hlid);
435 VIF_STATE_PRINT_INT(sta.ba_rx_bitmap);
436 VIF_STATE_PRINT_INT(sta.basic_rate_idx);
437 VIF_STATE_PRINT_INT(sta.ap_rate_idx);
438 VIF_STATE_PRINT_INT(sta.p2p_rate_idx);
439 } else {
440 VIF_STATE_PRINT_INT(ap.global_hlid);
441 VIF_STATE_PRINT_INT(ap.bcast_hlid);
442 VIF_STATE_PRINT_LHEX(ap.sta_hlid_map[0]);
443 VIF_STATE_PRINT_INT(ap.mgmt_rate_idx);
444 VIF_STATE_PRINT_INT(ap.bcast_rate_idx);
445 VIF_STATE_PRINT_INT(ap.ucast_rate_idx[0]);
446 VIF_STATE_PRINT_INT(ap.ucast_rate_idx[1]);
447 VIF_STATE_PRINT_INT(ap.ucast_rate_idx[2]);
448 VIF_STATE_PRINT_INT(ap.ucast_rate_idx[3]);
449 }
450 VIF_STATE_PRINT_INT(last_tx_hlid);
451 VIF_STATE_PRINT_LHEX(links_map[0]);
452 VIF_STATE_PRINT_NSTR(ssid, wlvif->ssid_len);
453 VIF_STATE_PRINT_INT(band);
454 VIF_STATE_PRINT_INT(channel);
455 VIF_STATE_PRINT_HEX(bitrate_masks[0]);
456 VIF_STATE_PRINT_HEX(bitrate_masks[1]);
457 VIF_STATE_PRINT_HEX(basic_rate_set);
458 VIF_STATE_PRINT_HEX(basic_rate);
459 VIF_STATE_PRINT_HEX(rate_set);
460 VIF_STATE_PRINT_INT(beacon_int);
461 VIF_STATE_PRINT_INT(default_key);
462 VIF_STATE_PRINT_INT(aid);
463 VIF_STATE_PRINT_INT(session_counter);
464 VIF_STATE_PRINT_INT(ps_poll_failures);
465 VIF_STATE_PRINT_INT(psm_entry_retry);
466 VIF_STATE_PRINT_INT(power_level);
467 VIF_STATE_PRINT_INT(rssi_thold);
468 VIF_STATE_PRINT_INT(last_rssi_event);
469 VIF_STATE_PRINT_INT(ba_support);
470 VIF_STATE_PRINT_INT(ba_allowed);
471 VIF_STATE_PRINT_LLHEX(tx_security_seq);
472 VIF_STATE_PRINT_INT(tx_security_last_seq_lsb);
473 }
474
475#undef VIF_STATE_PRINT_INT
476#undef VIF_STATE_PRINT_LONG
477#undef VIF_STATE_PRINT_HEX
478#undef VIF_STATE_PRINT_LHEX
479#undef VIF_STATE_PRINT_LLHEX
480#undef VIF_STATE_PRINT_STR
481#undef VIF_STATE_PRINT_NSTR
482#undef VIF_STATE_PRINT
483
484 mutex_unlock(&wl->mutex);
485
486 ret = simple_read_from_buffer(user_buf, count, ppos, buf, res);
487 kfree(buf);
488 return ret;
489}
490
491static const struct file_operations vifs_state_ops = {
492 .read = vifs_state_read,
493 .open = wl1271_open_file_generic,
494 .llseek = default_llseek,
495};
496
402static ssize_t dtim_interval_read(struct file *file, char __user *user_buf, 497static ssize_t dtim_interval_read(struct file *file, char __user *user_buf,
403 size_t count, loff_t *ppos) 498 size_t count, loff_t *ppos)
404{ 499{
@@ -520,6 +615,7 @@ static ssize_t rx_streaming_interval_write(struct file *file,
520 size_t count, loff_t *ppos) 615 size_t count, loff_t *ppos)
521{ 616{
522 struct wl1271 *wl = file->private_data; 617 struct wl1271 *wl = file->private_data;
618 struct wl12xx_vif *wlvif;
523 unsigned long value; 619 unsigned long value;
524 int ret; 620 int ret;
525 621
@@ -543,7 +639,9 @@ static ssize_t rx_streaming_interval_write(struct file *file,
543 if (ret < 0) 639 if (ret < 0)
544 goto out; 640 goto out;
545 641
546 wl1271_recalc_rx_streaming(wl); 642 wl12xx_for_each_wlvif_sta(wl, wlvif) {
643 wl1271_recalc_rx_streaming(wl, wlvif);
644 }
547 645
548 wl1271_ps_elp_sleep(wl); 646 wl1271_ps_elp_sleep(wl);
549out: 647out:
@@ -572,6 +670,7 @@ static ssize_t rx_streaming_always_write(struct file *file,
572 size_t count, loff_t *ppos) 670 size_t count, loff_t *ppos)
573{ 671{
574 struct wl1271 *wl = file->private_data; 672 struct wl1271 *wl = file->private_data;
673 struct wl12xx_vif *wlvif;
575 unsigned long value; 674 unsigned long value;
576 int ret; 675 int ret;
577 676
@@ -595,7 +694,9 @@ static ssize_t rx_streaming_always_write(struct file *file,
595 if (ret < 0) 694 if (ret < 0)
596 goto out; 695 goto out;
597 696
598 wl1271_recalc_rx_streaming(wl); 697 wl12xx_for_each_wlvif_sta(wl, wlvif) {
698 wl1271_recalc_rx_streaming(wl, wlvif);
699 }
599 700
600 wl1271_ps_elp_sleep(wl); 701 wl1271_ps_elp_sleep(wl);
601out: 702out:
@@ -624,6 +725,7 @@ static ssize_t beacon_filtering_write(struct file *file,
624 size_t count, loff_t *ppos) 725 size_t count, loff_t *ppos)
625{ 726{
626 struct wl1271 *wl = file->private_data; 727 struct wl1271 *wl = file->private_data;
728 struct wl12xx_vif *wlvif;
627 char buf[10]; 729 char buf[10];
628 size_t len; 730 size_t len;
629 unsigned long value; 731 unsigned long value;
@@ -646,7 +748,9 @@ static ssize_t beacon_filtering_write(struct file *file,
646 if (ret < 0) 748 if (ret < 0)
647 goto out; 749 goto out;
648 750
649 ret = wl1271_acx_beacon_filter_opt(wl, !!value); 751 wl12xx_for_each_wlvif(wl, wlvif) {
752 ret = wl1271_acx_beacon_filter_opt(wl, wlvif, !!value);
753 }
650 754
651 wl1271_ps_elp_sleep(wl); 755 wl1271_ps_elp_sleep(wl);
652out: 756out:
@@ -770,6 +874,7 @@ static int wl1271_debugfs_add_files(struct wl1271 *wl,
770 DEBUGFS_ADD(gpio_power, rootdir); 874 DEBUGFS_ADD(gpio_power, rootdir);
771 DEBUGFS_ADD(start_recovery, rootdir); 875 DEBUGFS_ADD(start_recovery, rootdir);
772 DEBUGFS_ADD(driver_state, rootdir); 876 DEBUGFS_ADD(driver_state, rootdir);
877 DEBUGFS_ADD(vifs_state, rootdir);
773 DEBUGFS_ADD(dtim_interval, rootdir); 878 DEBUGFS_ADD(dtim_interval, rootdir);
774 DEBUGFS_ADD(beacon_interval, rootdir); 879 DEBUGFS_ADD(beacon_interval, rootdir);
775 DEBUGFS_ADD(beacon_filtering, rootdir); 880 DEBUGFS_ADD(beacon_filtering, rootdir);
diff --git a/drivers/net/wireless/wl12xx/event.c b/drivers/net/wireless/wl12xx/event.c
index 674ad2a9e40..00ce794eeba 100644
--- a/drivers/net/wireless/wl12xx/event.c
+++ b/drivers/net/wireless/wl12xx/event.c
@@ -22,6 +22,7 @@
22 */ 22 */
23 23
24#include "wl12xx.h" 24#include "wl12xx.h"
25#include "debug.h"
25#include "reg.h" 26#include "reg.h"
26#include "io.h" 27#include "io.h"
27#include "event.h" 28#include "event.h"
@@ -31,12 +32,16 @@
31 32
32void wl1271_pspoll_work(struct work_struct *work) 33void wl1271_pspoll_work(struct work_struct *work)
33{ 34{
35 struct ieee80211_vif *vif;
36 struct wl12xx_vif *wlvif;
34 struct delayed_work *dwork; 37 struct delayed_work *dwork;
35 struct wl1271 *wl; 38 struct wl1271 *wl;
36 int ret; 39 int ret;
37 40
38 dwork = container_of(work, struct delayed_work, work); 41 dwork = container_of(work, struct delayed_work, work);
39 wl = container_of(dwork, struct wl1271, pspoll_work); 42 wlvif = container_of(dwork, struct wl12xx_vif, pspoll_work);
43 vif = container_of((void *)wlvif, struct ieee80211_vif, drv_priv);
44 wl = wlvif->wl;
40 45
41 wl1271_debug(DEBUG_EVENT, "pspoll work"); 46 wl1271_debug(DEBUG_EVENT, "pspoll work");
42 47
@@ -45,10 +50,10 @@ void wl1271_pspoll_work(struct work_struct *work)
45 if (unlikely(wl->state == WL1271_STATE_OFF)) 50 if (unlikely(wl->state == WL1271_STATE_OFF))
46 goto out; 51 goto out;
47 52
48 if (!test_and_clear_bit(WL1271_FLAG_PSPOLL_FAILURE, &wl->flags)) 53 if (!test_and_clear_bit(WLVIF_FLAG_PSPOLL_FAILURE, &wlvif->flags))
49 goto out; 54 goto out;
50 55
51 if (!test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) 56 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
52 goto out; 57 goto out;
53 58
54 /* 59 /*
@@ -60,31 +65,33 @@ void wl1271_pspoll_work(struct work_struct *work)
60 if (ret < 0) 65 if (ret < 0)
61 goto out; 66 goto out;
62 67
63 wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE, wl->basic_rate, true); 68 wl1271_ps_set_mode(wl, wlvif, STATION_POWER_SAVE_MODE,
69 wlvif->basic_rate, true);
64 70
65 wl1271_ps_elp_sleep(wl); 71 wl1271_ps_elp_sleep(wl);
66out: 72out:
67 mutex_unlock(&wl->mutex); 73 mutex_unlock(&wl->mutex);
68}; 74};
69 75
70static void wl1271_event_pspoll_delivery_fail(struct wl1271 *wl) 76static void wl1271_event_pspoll_delivery_fail(struct wl1271 *wl,
77 struct wl12xx_vif *wlvif)
71{ 78{
72 int delay = wl->conf.conn.ps_poll_recovery_period; 79 int delay = wl->conf.conn.ps_poll_recovery_period;
73 int ret; 80 int ret;
74 81
75 wl->ps_poll_failures++; 82 wlvif->ps_poll_failures++;
76 if (wl->ps_poll_failures == 1) 83 if (wlvif->ps_poll_failures == 1)
77 wl1271_info("AP with dysfunctional ps-poll, " 84 wl1271_info("AP with dysfunctional ps-poll, "
78 "trying to work around it."); 85 "trying to work around it.");
79 86
80 /* force active mode receive data from the AP */ 87 /* force active mode receive data from the AP */
81 if (test_bit(WL1271_FLAG_PSM, &wl->flags)) { 88 if (test_bit(WLVIF_FLAG_PSM, &wlvif->flags)) {
82 ret = wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE, 89 ret = wl1271_ps_set_mode(wl, wlvif, STATION_ACTIVE_MODE,
83 wl->basic_rate, true); 90 wlvif->basic_rate, true);
84 if (ret < 0) 91 if (ret < 0)
85 return; 92 return;
86 set_bit(WL1271_FLAG_PSPOLL_FAILURE, &wl->flags); 93 set_bit(WLVIF_FLAG_PSPOLL_FAILURE, &wlvif->flags);
87 ieee80211_queue_delayed_work(wl->hw, &wl->pspoll_work, 94 ieee80211_queue_delayed_work(wl->hw, &wlvif->pspoll_work,
88 msecs_to_jiffies(delay)); 95 msecs_to_jiffies(delay));
89 } 96 }
90 97
@@ -97,6 +104,7 @@ static void wl1271_event_pspoll_delivery_fail(struct wl1271 *wl)
97} 104}
98 105
99static int wl1271_event_ps_report(struct wl1271 *wl, 106static int wl1271_event_ps_report(struct wl1271 *wl,
107 struct wl12xx_vif *wlvif,
100 struct event_mailbox *mbox, 108 struct event_mailbox *mbox,
101 bool *beacon_loss) 109 bool *beacon_loss)
102{ 110{
@@ -109,41 +117,37 @@ static int wl1271_event_ps_report(struct wl1271 *wl,
109 case EVENT_ENTER_POWER_SAVE_FAIL: 117 case EVENT_ENTER_POWER_SAVE_FAIL:
110 wl1271_debug(DEBUG_PSM, "PSM entry failed"); 118 wl1271_debug(DEBUG_PSM, "PSM entry failed");
111 119
112 if (!test_bit(WL1271_FLAG_PSM, &wl->flags)) { 120 if (!test_bit(WLVIF_FLAG_PSM, &wlvif->flags)) {
113 /* remain in active mode */ 121 /* remain in active mode */
114 wl->psm_entry_retry = 0; 122 wlvif->psm_entry_retry = 0;
115 break; 123 break;
116 } 124 }
117 125
118 if (wl->psm_entry_retry < total_retries) { 126 if (wlvif->psm_entry_retry < total_retries) {
119 wl->psm_entry_retry++; 127 wlvif->psm_entry_retry++;
120 ret = wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE, 128 ret = wl1271_ps_set_mode(wl, wlvif,
121 wl->basic_rate, true); 129 STATION_POWER_SAVE_MODE,
130 wlvif->basic_rate, true);
122 } else { 131 } else {
123 wl1271_info("No ack to nullfunc from AP."); 132 wl1271_info("No ack to nullfunc from AP.");
124 wl->psm_entry_retry = 0; 133 wlvif->psm_entry_retry = 0;
125 *beacon_loss = true; 134 *beacon_loss = true;
126 } 135 }
127 break; 136 break;
128 case EVENT_ENTER_POWER_SAVE_SUCCESS: 137 case EVENT_ENTER_POWER_SAVE_SUCCESS:
129 wl->psm_entry_retry = 0; 138 wlvif->psm_entry_retry = 0;
130
131 /* enable beacon filtering */
132 ret = wl1271_acx_beacon_filter_opt(wl, true);
133 if (ret < 0)
134 break;
135 139
136 /* 140 /*
137 * BET has only a minor effect in 5GHz and masks 141 * BET has only a minor effect in 5GHz and masks
138 * channel switch IEs, so we only enable BET on 2.4GHz 142 * channel switch IEs, so we only enable BET on 2.4GHz
139 */ 143 */
140 if (wl->band == IEEE80211_BAND_2GHZ) 144 if (wlvif->band == IEEE80211_BAND_2GHZ)
141 /* enable beacon early termination */ 145 /* enable beacon early termination */
142 ret = wl1271_acx_bet_enable(wl, true); 146 ret = wl1271_acx_bet_enable(wl, wlvif, true);
143 147
144 if (wl->ps_compl) { 148 if (wlvif->ps_compl) {
145 complete(wl->ps_compl); 149 complete(wlvif->ps_compl);
146 wl->ps_compl = NULL; 150 wlvif->ps_compl = NULL;
147 } 151 }
148 break; 152 break;
149 default: 153 default:
@@ -154,39 +158,44 @@ static int wl1271_event_ps_report(struct wl1271 *wl,
154} 158}
155 159
156static void wl1271_event_rssi_trigger(struct wl1271 *wl, 160static void wl1271_event_rssi_trigger(struct wl1271 *wl,
161 struct wl12xx_vif *wlvif,
157 struct event_mailbox *mbox) 162 struct event_mailbox *mbox)
158{ 163{
164 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
159 enum nl80211_cqm_rssi_threshold_event event; 165 enum nl80211_cqm_rssi_threshold_event event;
160 s8 metric = mbox->rssi_snr_trigger_metric[0]; 166 s8 metric = mbox->rssi_snr_trigger_metric[0];
161 167
162 wl1271_debug(DEBUG_EVENT, "RSSI trigger metric: %d", metric); 168 wl1271_debug(DEBUG_EVENT, "RSSI trigger metric: %d", metric);
163 169
164 if (metric <= wl->rssi_thold) 170 if (metric <= wlvif->rssi_thold)
165 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW; 171 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW;
166 else 172 else
167 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH; 173 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH;
168 174
169 if (event != wl->last_rssi_event) 175 if (event != wlvif->last_rssi_event)
170 ieee80211_cqm_rssi_notify(wl->vif, event, GFP_KERNEL); 176 ieee80211_cqm_rssi_notify(vif, event, GFP_KERNEL);
171 wl->last_rssi_event = event; 177 wlvif->last_rssi_event = event;
172} 178}
173 179
174static void wl1271_stop_ba_event(struct wl1271 *wl) 180static void wl1271_stop_ba_event(struct wl1271 *wl, struct wl12xx_vif *wlvif)
175{ 181{
176 if (wl->bss_type != BSS_TYPE_AP_BSS) { 182 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
177 if (!wl->ba_rx_bitmap) 183
184 if (wlvif->bss_type != BSS_TYPE_AP_BSS) {
185 if (!wlvif->sta.ba_rx_bitmap)
178 return; 186 return;
179 ieee80211_stop_rx_ba_session(wl->vif, wl->ba_rx_bitmap, 187 ieee80211_stop_rx_ba_session(vif, wlvif->sta.ba_rx_bitmap,
180 wl->bssid); 188 vif->bss_conf.bssid);
181 } else { 189 } else {
182 int i; 190 u8 hlid;
183 struct wl1271_link *lnk; 191 struct wl1271_link *lnk;
184 for (i = WL1271_AP_STA_HLID_START; i < AP_MAX_LINKS; i++) { 192 for_each_set_bit(hlid, wlvif->ap.sta_hlid_map,
185 lnk = &wl->links[i]; 193 WL12XX_MAX_LINKS) {
186 if (!wl1271_is_active_sta(wl, i) || !lnk->ba_bitmap) 194 lnk = &wl->links[hlid];
195 if (!lnk->ba_bitmap)
187 continue; 196 continue;
188 197
189 ieee80211_stop_rx_ba_session(wl->vif, 198 ieee80211_stop_rx_ba_session(vif,
190 lnk->ba_bitmap, 199 lnk->ba_bitmap,
191 lnk->addr); 200 lnk->addr);
192 } 201 }
@@ -196,14 +205,23 @@ static void wl1271_stop_ba_event(struct wl1271 *wl)
196static void wl12xx_event_soft_gemini_sense(struct wl1271 *wl, 205static void wl12xx_event_soft_gemini_sense(struct wl1271 *wl,
197 u8 enable) 206 u8 enable)
198{ 207{
208 struct ieee80211_vif *vif;
209 struct wl12xx_vif *wlvif;
210
199 if (enable) { 211 if (enable) {
200 /* disable dynamic PS when requested by the firmware */ 212 /* disable dynamic PS when requested by the firmware */
201 ieee80211_disable_dyn_ps(wl->vif); 213 wl12xx_for_each_wlvif_sta(wl, wlvif) {
214 vif = wl12xx_wlvif_to_vif(wlvif);
215 ieee80211_disable_dyn_ps(vif);
216 }
202 set_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags); 217 set_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
203 } else { 218 } else {
204 ieee80211_enable_dyn_ps(wl->vif);
205 clear_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags); 219 clear_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
206 wl1271_recalc_rx_streaming(wl); 220 wl12xx_for_each_wlvif_sta(wl, wlvif) {
221 vif = wl12xx_wlvif_to_vif(wlvif);
222 ieee80211_enable_dyn_ps(vif);
223 wl1271_recalc_rx_streaming(wl, wlvif);
224 }
207 } 225 }
208 226
209} 227}
@@ -217,10 +235,11 @@ static void wl1271_event_mbox_dump(struct event_mailbox *mbox)
217 235
218static int wl1271_event_process(struct wl1271 *wl, struct event_mailbox *mbox) 236static int wl1271_event_process(struct wl1271 *wl, struct event_mailbox *mbox)
219{ 237{
238 struct ieee80211_vif *vif;
239 struct wl12xx_vif *wlvif;
220 int ret; 240 int ret;
221 u32 vector; 241 u32 vector;
222 bool beacon_loss = false; 242 bool beacon_loss = false;
223 bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS);
224 bool disconnect_sta = false; 243 bool disconnect_sta = false;
225 unsigned long sta_bitmap = 0; 244 unsigned long sta_bitmap = 0;
226 245
@@ -234,7 +253,7 @@ static int wl1271_event_process(struct wl1271 *wl, struct event_mailbox *mbox)
234 wl1271_debug(DEBUG_EVENT, "status: 0x%x", 253 wl1271_debug(DEBUG_EVENT, "status: 0x%x",
235 mbox->scheduled_scan_status); 254 mbox->scheduled_scan_status);
236 255
237 wl1271_scan_stm(wl); 256 wl1271_scan_stm(wl, wl->scan_vif);
238 } 257 }
239 258
240 if (vector & PERIODIC_SCAN_REPORT_EVENT_ID) { 259 if (vector & PERIODIC_SCAN_REPORT_EVENT_ID) {
@@ -253,8 +272,7 @@ static int wl1271_event_process(struct wl1271 *wl, struct event_mailbox *mbox)
253 } 272 }
254 } 273 }
255 274
256 if (vector & SOFT_GEMINI_SENSE_EVENT_ID && 275 if (vector & SOFT_GEMINI_SENSE_EVENT_ID)
257 wl->bss_type == BSS_TYPE_STA_BSS)
258 wl12xx_event_soft_gemini_sense(wl, 276 wl12xx_event_soft_gemini_sense(wl,
259 mbox->soft_gemini_sense_info); 277 mbox->soft_gemini_sense_info);
260 278
@@ -267,40 +285,54 @@ static int wl1271_event_process(struct wl1271 *wl, struct event_mailbox *mbox)
267 * BSS_LOSE_EVENT, beacon loss has to be reported to the stack. 285 * BSS_LOSE_EVENT, beacon loss has to be reported to the stack.
268 * 286 *
269 */ 287 */
270 if ((vector & BSS_LOSE_EVENT_ID) && !is_ap) { 288 if (vector & BSS_LOSE_EVENT_ID) {
289 /* TODO: check for multi-role */
271 wl1271_info("Beacon loss detected."); 290 wl1271_info("Beacon loss detected.");
272 291
273 /* indicate to the stack, that beacons have been lost */ 292 /* indicate to the stack, that beacons have been lost */
274 beacon_loss = true; 293 beacon_loss = true;
275 } 294 }
276 295
277 if ((vector & PS_REPORT_EVENT_ID) && !is_ap) { 296 if (vector & PS_REPORT_EVENT_ID) {
278 wl1271_debug(DEBUG_EVENT, "PS_REPORT_EVENT"); 297 wl1271_debug(DEBUG_EVENT, "PS_REPORT_EVENT");
279 ret = wl1271_event_ps_report(wl, mbox, &beacon_loss); 298 wl12xx_for_each_wlvif_sta(wl, wlvif) {
280 if (ret < 0) 299 ret = wl1271_event_ps_report(wl, wlvif,
281 return ret; 300 mbox, &beacon_loss);
301 if (ret < 0)
302 return ret;
303 }
282 } 304 }
283 305
284 if ((vector & PSPOLL_DELIVERY_FAILURE_EVENT_ID) && !is_ap) 306 if (vector & PSPOLL_DELIVERY_FAILURE_EVENT_ID)
285 wl1271_event_pspoll_delivery_fail(wl); 307 wl12xx_for_each_wlvif_sta(wl, wlvif) {
308 wl1271_event_pspoll_delivery_fail(wl, wlvif);
309 }
286 310
287 if (vector & RSSI_SNR_TRIGGER_0_EVENT_ID) { 311 if (vector & RSSI_SNR_TRIGGER_0_EVENT_ID) {
312 /* TODO: check actual multi-role support */
288 wl1271_debug(DEBUG_EVENT, "RSSI_SNR_TRIGGER_0_EVENT"); 313 wl1271_debug(DEBUG_EVENT, "RSSI_SNR_TRIGGER_0_EVENT");
289 if (wl->vif) 314 wl12xx_for_each_wlvif_sta(wl, wlvif) {
290 wl1271_event_rssi_trigger(wl, mbox); 315 wl1271_event_rssi_trigger(wl, wlvif, mbox);
316 }
291 } 317 }
292 318
293 if ((vector & BA_SESSION_RX_CONSTRAINT_EVENT_ID)) { 319 if (vector & BA_SESSION_RX_CONSTRAINT_EVENT_ID) {
320 u8 role_id = mbox->role_id;
294 wl1271_debug(DEBUG_EVENT, "BA_SESSION_RX_CONSTRAINT_EVENT_ID. " 321 wl1271_debug(DEBUG_EVENT, "BA_SESSION_RX_CONSTRAINT_EVENT_ID. "
295 "ba_allowed = 0x%x", mbox->rx_ba_allowed); 322 "ba_allowed = 0x%x, role_id=%d",
323 mbox->rx_ba_allowed, role_id);
296 324
297 wl->ba_allowed = !!mbox->rx_ba_allowed; 325 wl12xx_for_each_wlvif(wl, wlvif) {
326 if (role_id != 0xff && role_id != wlvif->role_id)
327 continue;
298 328
299 if (wl->vif && !wl->ba_allowed) 329 wlvif->ba_allowed = !!mbox->rx_ba_allowed;
300 wl1271_stop_ba_event(wl); 330 if (!wlvif->ba_allowed)
331 wl1271_stop_ba_event(wl, wlvif);
332 }
301 } 333 }
302 334
303 if ((vector & CHANNEL_SWITCH_COMPLETE_EVENT_ID) && !is_ap) { 335 if (vector & CHANNEL_SWITCH_COMPLETE_EVENT_ID) {
304 wl1271_debug(DEBUG_EVENT, "CHANNEL_SWITCH_COMPLETE_EVENT_ID. " 336 wl1271_debug(DEBUG_EVENT, "CHANNEL_SWITCH_COMPLETE_EVENT_ID. "
305 "status = 0x%x", 337 "status = 0x%x",
306 mbox->channel_switch_status); 338 mbox->channel_switch_status);
@@ -309,50 +341,65 @@ static int wl1271_event_process(struct wl1271 *wl, struct event_mailbox *mbox)
309 * 1) channel switch complete with status=0 341 * 1) channel switch complete with status=0
310 * 2) channel switch failed status=1 342 * 2) channel switch failed status=1
311 */ 343 */
312 if (test_and_clear_bit(WL1271_FLAG_CS_PROGRESS, &wl->flags) && 344
313 (wl->vif)) 345 /* TODO: configure only the relevant vif */
314 ieee80211_chswitch_done(wl->vif, 346 wl12xx_for_each_wlvif_sta(wl, wlvif) {
315 mbox->channel_switch_status ? false : true); 347 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
348 bool success;
349
350 if (!test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS,
351 &wl->flags))
352 continue;
353
354 success = mbox->channel_switch_status ? false : true;
355 ieee80211_chswitch_done(vif, success);
356 }
316 } 357 }
317 358
318 if ((vector & DUMMY_PACKET_EVENT_ID)) { 359 if ((vector & DUMMY_PACKET_EVENT_ID)) {
319 wl1271_debug(DEBUG_EVENT, "DUMMY_PACKET_ID_EVENT_ID"); 360 wl1271_debug(DEBUG_EVENT, "DUMMY_PACKET_ID_EVENT_ID");
320 if (wl->vif) 361 wl1271_tx_dummy_packet(wl);
321 wl1271_tx_dummy_packet(wl);
322 } 362 }
323 363
324 /* 364 /*
325 * "TX retries exceeded" has a different meaning according to mode. 365 * "TX retries exceeded" has a different meaning according to mode.
326 * In AP mode the offending station is disconnected. 366 * In AP mode the offending station is disconnected.
327 */ 367 */
328 if ((vector & MAX_TX_RETRY_EVENT_ID) && is_ap) { 368 if (vector & MAX_TX_RETRY_EVENT_ID) {
329 wl1271_debug(DEBUG_EVENT, "MAX_TX_RETRY_EVENT_ID"); 369 wl1271_debug(DEBUG_EVENT, "MAX_TX_RETRY_EVENT_ID");
330 sta_bitmap |= le16_to_cpu(mbox->sta_tx_retry_exceeded); 370 sta_bitmap |= le16_to_cpu(mbox->sta_tx_retry_exceeded);
331 disconnect_sta = true; 371 disconnect_sta = true;
332 } 372 }
333 373
334 if ((vector & INACTIVE_STA_EVENT_ID) && is_ap) { 374 if (vector & INACTIVE_STA_EVENT_ID) {
335 wl1271_debug(DEBUG_EVENT, "INACTIVE_STA_EVENT_ID"); 375 wl1271_debug(DEBUG_EVENT, "INACTIVE_STA_EVENT_ID");
336 sta_bitmap |= le16_to_cpu(mbox->sta_aging_status); 376 sta_bitmap |= le16_to_cpu(mbox->sta_aging_status);
337 disconnect_sta = true; 377 disconnect_sta = true;
338 } 378 }
339 379
340 if (is_ap && disconnect_sta) { 380 if (disconnect_sta) {
341 u32 num_packets = wl->conf.tx.max_tx_retries; 381 u32 num_packets = wl->conf.tx.max_tx_retries;
342 struct ieee80211_sta *sta; 382 struct ieee80211_sta *sta;
343 const u8 *addr; 383 const u8 *addr;
344 int h; 384 int h;
345 385
346 for (h = find_first_bit(&sta_bitmap, AP_MAX_LINKS); 386 for_each_set_bit(h, &sta_bitmap, WL12XX_MAX_LINKS) {
347 h < AP_MAX_LINKS; 387 bool found = false;
348 h = find_next_bit(&sta_bitmap, AP_MAX_LINKS, h+1)) { 388 /* find the ap vif connected to this sta */
349 if (!wl1271_is_active_sta(wl, h)) 389 wl12xx_for_each_wlvif_ap(wl, wlvif) {
390 if (!test_bit(h, wlvif->ap.sta_hlid_map))
391 continue;
392 found = true;
393 break;
394 }
395 if (!found)
350 continue; 396 continue;
351 397
398 vif = wl12xx_wlvif_to_vif(wlvif);
352 addr = wl->links[h].addr; 399 addr = wl->links[h].addr;
353 400
354 rcu_read_lock(); 401 rcu_read_lock();
355 sta = ieee80211_find_sta(wl->vif, addr); 402 sta = ieee80211_find_sta(vif, addr);
356 if (sta) { 403 if (sta) {
357 wl1271_debug(DEBUG_EVENT, "remove sta %d", h); 404 wl1271_debug(DEBUG_EVENT, "remove sta %d", h);
358 ieee80211_report_low_ack(sta, num_packets); 405 ieee80211_report_low_ack(sta, num_packets);
@@ -361,8 +408,11 @@ static int wl1271_event_process(struct wl1271 *wl, struct event_mailbox *mbox)
361 } 408 }
362 } 409 }
363 410
364 if (wl->vif && beacon_loss) 411 if (beacon_loss)
365 ieee80211_connection_loss(wl->vif); 412 wl12xx_for_each_wlvif_sta(wl, wlvif) {
413 vif = wl12xx_wlvif_to_vif(wlvif);
414 ieee80211_connection_loss(vif);
415 }
366 416
367 return 0; 417 return 0;
368} 418}
diff --git a/drivers/net/wireless/wl12xx/event.h b/drivers/net/wireless/wl12xx/event.h
index 49c1a0ede5b..1d878ba47bf 100644
--- a/drivers/net/wireless/wl12xx/event.h
+++ b/drivers/net/wireless/wl12xx/event.h
@@ -132,7 +132,4 @@ void wl1271_event_mbox_config(struct wl1271 *wl);
132int wl1271_event_handle(struct wl1271 *wl, u8 mbox); 132int wl1271_event_handle(struct wl1271 *wl, u8 mbox);
133void wl1271_pspoll_work(struct work_struct *work); 133void wl1271_pspoll_work(struct work_struct *work);
134 134
135/* Functions from main.c */
136bool wl1271_is_active_sta(struct wl1271 *wl, u8 hlid);
137
138#endif 135#endif
diff --git a/drivers/net/wireless/wl12xx/init.c b/drivers/net/wireless/wl12xx/init.c
index 04db64c94e9..88891cdfdd4 100644
--- a/drivers/net/wireless/wl12xx/init.c
+++ b/drivers/net/wireless/wl12xx/init.c
@@ -25,6 +25,7 @@
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/slab.h> 26#include <linux/slab.h>
27 27
28#include "debug.h"
28#include "init.h" 29#include "init.h"
29#include "wl12xx_80211.h" 30#include "wl12xx_80211.h"
30#include "acx.h" 31#include "acx.h"
@@ -33,7 +34,7 @@
33#include "tx.h" 34#include "tx.h"
34#include "io.h" 35#include "io.h"
35 36
36int wl1271_sta_init_templates_config(struct wl1271 *wl) 37int wl1271_init_templates_config(struct wl1271 *wl)
37{ 38{
38 int ret, i; 39 int ret, i;
39 40
@@ -64,7 +65,7 @@ int wl1271_sta_init_templates_config(struct wl1271 *wl)
64 65
65 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, NULL, 66 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, NULL,
66 sizeof 67 sizeof
67 (struct wl12xx_qos_null_data_template), 68 (struct ieee80211_qos_hdr),
68 0, WL1271_RATE_AUTOMATIC); 69 0, WL1271_RATE_AUTOMATIC);
69 if (ret < 0) 70 if (ret < 0)
70 return ret; 71 return ret;
@@ -88,10 +89,33 @@ int wl1271_sta_init_templates_config(struct wl1271 *wl)
88 if (ret < 0) 89 if (ret < 0)
89 return ret; 90 return ret;
90 91
92 /*
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
91 for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) { 115 for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
92 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV, NULL, 116 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV, NULL,
93 WL1271_CMD_TEMPL_DFLT_SIZE, i, 117 sizeof(struct ieee80211_qos_hdr),
94 WL1271_RATE_AUTOMATIC); 118 i, WL1271_RATE_AUTOMATIC);
95 if (ret < 0) 119 if (ret < 0)
96 return ret; 120 return ret;
97 } 121 }
@@ -99,7 +123,8 @@ int wl1271_sta_init_templates_config(struct wl1271 *wl)
99 return 0; 123 return 0;
100} 124}
101 125
102static int wl1271_ap_init_deauth_template(struct wl1271 *wl) 126static int wl1271_ap_init_deauth_template(struct wl1271 *wl,
127 struct wl12xx_vif *wlvif)
103{ 128{
104 struct wl12xx_disconn_template *tmpl; 129 struct wl12xx_disconn_template *tmpl;
105 int ret; 130 int ret;
@@ -114,7 +139,7 @@ static int wl1271_ap_init_deauth_template(struct wl1271 *wl)
114 tmpl->header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_MGMT | 139 tmpl->header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_MGMT |
115 IEEE80211_STYPE_DEAUTH); 140 IEEE80211_STYPE_DEAUTH);
116 141
117 rate = wl1271_tx_min_rate_get(wl, wl->basic_rate_set); 142 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
118 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_DEAUTH_AP, 143 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_DEAUTH_AP,
119 tmpl, sizeof(*tmpl), 0, rate); 144 tmpl, sizeof(*tmpl), 0, rate);
120 145
@@ -123,8 +148,10 @@ out:
123 return ret; 148 return ret;
124} 149}
125 150
126static int wl1271_ap_init_null_template(struct wl1271 *wl) 151static int wl1271_ap_init_null_template(struct wl1271 *wl,
152 struct ieee80211_vif *vif)
127{ 153{
154 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
128 struct ieee80211_hdr_3addr *nullfunc; 155 struct ieee80211_hdr_3addr *nullfunc;
129 int ret; 156 int ret;
130 u32 rate; 157 u32 rate;
@@ -141,10 +168,10 @@ static int wl1271_ap_init_null_template(struct wl1271 *wl)
141 168
142 /* nullfunc->addr1 is filled by FW */ 169 /* nullfunc->addr1 is filled by FW */
143 170
144 memcpy(nullfunc->addr2, wl->mac_addr, ETH_ALEN); 171 memcpy(nullfunc->addr2, vif->addr, ETH_ALEN);
145 memcpy(nullfunc->addr3, wl->mac_addr, ETH_ALEN); 172 memcpy(nullfunc->addr3, vif->addr, ETH_ALEN);
146 173
147 rate = wl1271_tx_min_rate_get(wl, wl->basic_rate_set); 174 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
148 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, nullfunc, 175 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, nullfunc,
149 sizeof(*nullfunc), 0, rate); 176 sizeof(*nullfunc), 0, rate);
150 177
@@ -153,8 +180,10 @@ out:
153 return ret; 180 return ret;
154} 181}
155 182
156static int wl1271_ap_init_qos_null_template(struct wl1271 *wl) 183static int wl1271_ap_init_qos_null_template(struct wl1271 *wl,
184 struct ieee80211_vif *vif)
157{ 185{
186 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
158 struct ieee80211_qos_hdr *qosnull; 187 struct ieee80211_qos_hdr *qosnull;
159 int ret; 188 int ret;
160 u32 rate; 189 u32 rate;
@@ -171,10 +200,10 @@ static int wl1271_ap_init_qos_null_template(struct wl1271 *wl)
171 200
172 /* qosnull->addr1 is filled by FW */ 201 /* qosnull->addr1 is filled by FW */
173 202
174 memcpy(qosnull->addr2, wl->mac_addr, ETH_ALEN); 203 memcpy(qosnull->addr2, vif->addr, ETH_ALEN);
175 memcpy(qosnull->addr3, wl->mac_addr, ETH_ALEN); 204 memcpy(qosnull->addr3, vif->addr, ETH_ALEN);
176 205
177 rate = wl1271_tx_min_rate_get(wl, wl->basic_rate_set); 206 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
178 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, qosnull, 207 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, qosnull,
179 sizeof(*qosnull), 0, rate); 208 sizeof(*qosnull), 0, rate);
180 209
@@ -183,93 +212,59 @@ out:
183 return ret; 212 return ret;
184} 213}
185 214
186static int wl1271_ap_init_templates_config(struct wl1271 *wl) 215static int wl12xx_init_rx_config(struct wl1271 *wl)
187{ 216{
188 int ret; 217 int ret;
189 218
190 /* 219 ret = wl1271_acx_rx_msdu_life_time(wl);
191 * Put very large empty placeholders for all templates. These
192 * reserve memory for later.
193 */
194 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_AP_PROBE_RESPONSE, NULL,
195 WL1271_CMD_TEMPL_MAX_SIZE,
196 0, WL1271_RATE_AUTOMATIC);
197 if (ret < 0)
198 return ret;
199
200 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_AP_BEACON, NULL,
201 WL1271_CMD_TEMPL_MAX_SIZE,
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) 220 if (ret < 0)
224 return ret; 221 return ret;
225 222
226 return 0; 223 return 0;
227} 224}
228 225
229static int wl12xx_init_rx_config(struct wl1271 *wl) 226int wl1271_init_phy_config(struct wl1271 *wl)
230{ 227{
231 int ret; 228 int ret;
232 229
233 ret = wl1271_acx_rx_msdu_life_time(wl); 230 ret = wl1271_acx_pd_threshold(wl);
234 if (ret < 0) 231 if (ret < 0)
235 return ret; 232 return ret;
236 233
237 return 0; 234 return 0;
238} 235}
239 236
240int wl1271_init_phy_config(struct wl1271 *wl) 237static int wl12xx_init_phy_vif_config(struct wl1271 *wl,
238 struct wl12xx_vif *wlvif)
241{ 239{
242 int ret; 240 int ret;
243 241
244 ret = wl1271_acx_pd_threshold(wl); 242 ret = wl1271_acx_slot(wl, wlvif, DEFAULT_SLOT_TIME);
245 if (ret < 0)
246 return ret;
247
248 ret = wl1271_acx_slot(wl, DEFAULT_SLOT_TIME);
249 if (ret < 0) 243 if (ret < 0)
250 return ret; 244 return ret;
251 245
252 ret = wl1271_acx_service_period_timeout(wl); 246 ret = wl1271_acx_service_period_timeout(wl, wlvif);
253 if (ret < 0) 247 if (ret < 0)
254 return ret; 248 return ret;
255 249
256 ret = wl1271_acx_rts_threshold(wl, wl->hw->wiphy->rts_threshold); 250 ret = wl1271_acx_rts_threshold(wl, wlvif, wl->hw->wiphy->rts_threshold);
257 if (ret < 0) 251 if (ret < 0)
258 return ret; 252 return ret;
259 253
260 return 0; 254 return 0;
261} 255}
262 256
263static int wl1271_init_beacon_filter(struct wl1271 *wl) 257static int wl1271_init_sta_beacon_filter(struct wl1271 *wl,
258 struct wl12xx_vif *wlvif)
264{ 259{
265 int ret; 260 int ret;
266 261
267 /* disable beacon filtering at this stage */ 262 ret = wl1271_acx_beacon_filter_table(wl, wlvif);
268 ret = wl1271_acx_beacon_filter_opt(wl, false);
269 if (ret < 0) 263 if (ret < 0)
270 return ret; 264 return ret;
271 265
272 ret = wl1271_acx_beacon_filter_table(wl); 266 /* enable beacon filtering */
267 ret = wl1271_acx_beacon_filter_opt(wl, wlvif, true);
273 if (ret < 0) 268 if (ret < 0)
274 return ret; 269 return ret;
275 270
@@ -302,11 +297,12 @@ int wl1271_init_energy_detection(struct wl1271 *wl)
302 return 0; 297 return 0;
303} 298}
304 299
305static int wl1271_init_beacon_broadcast(struct wl1271 *wl) 300static int wl1271_init_beacon_broadcast(struct wl1271 *wl,
301 struct wl12xx_vif *wlvif)
306{ 302{
307 int ret; 303 int ret;
308 304
309 ret = wl1271_acx_bcn_dtim_options(wl); 305 ret = wl1271_acx_bcn_dtim_options(wl, wlvif);
310 if (ret < 0) 306 if (ret < 0)
311 return ret; 307 return ret;
312 308
@@ -327,7 +323,8 @@ static int wl12xx_init_fwlog(struct wl1271 *wl)
327 return 0; 323 return 0;
328} 324}
329 325
330static int wl1271_sta_hw_init(struct wl1271 *wl) 326/* generic sta initialization (non vif-specific) */
327static int wl1271_sta_hw_init(struct wl1271 *wl, struct wl12xx_vif *wlvif)
331{ 328{
332 int ret; 329 int ret;
333 330
@@ -338,25 +335,7 @@ static int wl1271_sta_hw_init(struct wl1271 *wl)
338 } 335 }
339 336
340 /* PS config */ 337 /* PS config */
341 ret = wl1271_acx_config_ps(wl); 338 ret = wl12xx_acx_config_ps(wl, wlvif);
342 if (ret < 0)
343 return ret;
344
345 ret = wl1271_sta_init_templates_config(wl);
346 if (ret < 0)
347 return ret;
348
349 ret = wl1271_acx_group_address_tbl(wl, true, NULL, 0);
350 if (ret < 0)
351 return ret;
352
353 /* Initialize connection monitoring thresholds */
354 ret = wl1271_acx_conn_monit_params(wl, false);
355 if (ret < 0)
356 return ret;
357
358 /* Beacon filtering */
359 ret = wl1271_init_beacon_filter(wl);
360 if (ret < 0) 339 if (ret < 0)
361 return ret; 340 return ret;
362 341
@@ -365,103 +344,61 @@ static int wl1271_sta_hw_init(struct wl1271 *wl)
365 if (ret < 0) 344 if (ret < 0)
366 return ret; 345 return ret;
367 346
368 /* Beacons and broadcast settings */ 347 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
369 ret = wl1271_init_beacon_broadcast(wl);
370 if (ret < 0)
371 return ret;
372
373 /* Configure for ELP power saving */
374 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);
375 if (ret < 0)
376 return ret;
377
378 /* Configure rssi/snr averaging weights */
379 ret = wl1271_acx_rssi_snr_avg_weights(wl);
380 if (ret < 0)
381 return ret;
382
383 ret = wl1271_acx_sta_rate_policies(wl);
384 if (ret < 0)
385 return ret;
386
387 ret = wl12xx_acx_mem_cfg(wl);
388 if (ret < 0)
389 return ret;
390
391 /* Configure the FW logger */
392 ret = wl12xx_init_fwlog(wl);
393 if (ret < 0) 348 if (ret < 0)
394 return ret; 349 return ret;
395 350
396 return 0; 351 return 0;
397} 352}
398 353
399static int wl1271_sta_hw_init_post_mem(struct wl1271 *wl) 354static int wl1271_sta_hw_init_post_mem(struct wl1271 *wl,
355 struct ieee80211_vif *vif)
400{ 356{
357 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
401 int ret, i; 358 int ret, i;
402 359
403 /* disable all keep-alive templates */ 360 /* disable all keep-alive templates */
404 for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) { 361 for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
405 ret = wl1271_acx_keep_alive_config(wl, i, 362 ret = wl1271_acx_keep_alive_config(wl, wlvif, i,
406 ACX_KEEP_ALIVE_TPL_INVALID); 363 ACX_KEEP_ALIVE_TPL_INVALID);
407 if (ret < 0) 364 if (ret < 0)
408 return ret; 365 return ret;
409 } 366 }
410 367
411 /* disable the keep-alive feature */ 368 /* disable the keep-alive feature */
412 ret = wl1271_acx_keep_alive_mode(wl, false); 369 ret = wl1271_acx_keep_alive_mode(wl, wlvif, false);
413 if (ret < 0) 370 if (ret < 0)
414 return ret; 371 return ret;
415 372
416 return 0; 373 return 0;
417} 374}
418 375
419static int wl1271_ap_hw_init(struct wl1271 *wl) 376/* generic ap initialization (non vif-specific) */
377static int wl1271_ap_hw_init(struct wl1271 *wl, struct wl12xx_vif *wlvif)
420{ 378{
421 int ret; 379 int ret;
422 380
423 ret = wl1271_ap_init_templates_config(wl); 381 ret = wl1271_init_ap_rates(wl, wlvif);
424 if (ret < 0)
425 return ret;
426
427 /* Configure for power always on */
428 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
429 if (ret < 0)
430 return ret;
431
432 ret = wl1271_init_ap_rates(wl);
433 if (ret < 0)
434 return ret;
435
436 ret = wl1271_acx_ap_max_tx_retry(wl);
437 if (ret < 0)
438 return ret;
439
440 ret = wl12xx_acx_mem_cfg(wl);
441 if (ret < 0)
442 return ret;
443
444 /* initialize Tx power */
445 ret = wl1271_acx_tx_power(wl, wl->power_level);
446 if (ret < 0) 382 if (ret < 0)
447 return ret; 383 return ret;
448 384
449 return 0; 385 return 0;
450} 386}
451 387
452int wl1271_ap_init_templates(struct wl1271 *wl) 388int wl1271_ap_init_templates(struct wl1271 *wl, struct ieee80211_vif *vif)
453{ 389{
390 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
454 int ret; 391 int ret;
455 392
456 ret = wl1271_ap_init_deauth_template(wl); 393 ret = wl1271_ap_init_deauth_template(wl, wlvif);
457 if (ret < 0) 394 if (ret < 0)
458 return ret; 395 return ret;
459 396
460 ret = wl1271_ap_init_null_template(wl); 397 ret = wl1271_ap_init_null_template(wl, vif);
461 if (ret < 0) 398 if (ret < 0)
462 return ret; 399 return ret;
463 400
464 ret = wl1271_ap_init_qos_null_template(wl); 401 ret = wl1271_ap_init_qos_null_template(wl, vif);
465 if (ret < 0) 402 if (ret < 0)
466 return ret; 403 return ret;
467 404
@@ -469,43 +406,45 @@ int wl1271_ap_init_templates(struct wl1271 *wl)
469 * when operating as AP we want to receive external beacons for 406 * when operating as AP we want to receive external beacons for
470 * configuring ERP protection. 407 * configuring ERP protection.
471 */ 408 */
472 ret = wl1271_acx_beacon_filter_opt(wl, false); 409 ret = wl1271_acx_beacon_filter_opt(wl, wlvif, false);
473 if (ret < 0) 410 if (ret < 0)
474 return ret; 411 return ret;
475 412
476 return 0; 413 return 0;
477} 414}
478 415
479static int wl1271_ap_hw_init_post_mem(struct wl1271 *wl) 416static int wl1271_ap_hw_init_post_mem(struct wl1271 *wl,
417 struct ieee80211_vif *vif)
480{ 418{
481 return wl1271_ap_init_templates(wl); 419 return wl1271_ap_init_templates(wl, vif);
482} 420}
483 421
484int wl1271_init_ap_rates(struct wl1271 *wl) 422int wl1271_init_ap_rates(struct wl1271 *wl, struct wl12xx_vif *wlvif)
485{ 423{
486 int i, ret; 424 int i, ret;
487 struct conf_tx_rate_class rc; 425 struct conf_tx_rate_class rc;
488 u32 supported_rates; 426 u32 supported_rates;
489 427
490 wl1271_debug(DEBUG_AP, "AP basic rate set: 0x%x", wl->basic_rate_set); 428 wl1271_debug(DEBUG_AP, "AP basic rate set: 0x%x",
429 wlvif->basic_rate_set);
491 430
492 if (wl->basic_rate_set == 0) 431 if (wlvif->basic_rate_set == 0)
493 return -EINVAL; 432 return -EINVAL;
494 433
495 rc.enabled_rates = wl->basic_rate_set; 434 rc.enabled_rates = wlvif->basic_rate_set;
496 rc.long_retry_limit = 10; 435 rc.long_retry_limit = 10;
497 rc.short_retry_limit = 10; 436 rc.short_retry_limit = 10;
498 rc.aflags = 0; 437 rc.aflags = 0;
499 ret = wl1271_acx_ap_rate_policy(wl, &rc, ACX_TX_AP_MODE_MGMT_RATE); 438 ret = wl1271_acx_ap_rate_policy(wl, &rc, wlvif->ap.mgmt_rate_idx);
500 if (ret < 0) 439 if (ret < 0)
501 return ret; 440 return ret;
502 441
503 /* use the min basic rate for AP broadcast/multicast */ 442 /* use the min basic rate for AP broadcast/multicast */
504 rc.enabled_rates = wl1271_tx_min_rate_get(wl, wl->basic_rate_set); 443 rc.enabled_rates = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
505 rc.short_retry_limit = 10; 444 rc.short_retry_limit = 10;
506 rc.long_retry_limit = 10; 445 rc.long_retry_limit = 10;
507 rc.aflags = 0; 446 rc.aflags = 0;
508 ret = wl1271_acx_ap_rate_policy(wl, &rc, ACX_TX_AP_MODE_BCST_RATE); 447 ret = wl1271_acx_ap_rate_policy(wl, &rc, wlvif->ap.bcast_rate_idx);
509 if (ret < 0) 448 if (ret < 0)
510 return ret; 449 return ret;
511 450
@@ -513,7 +452,7 @@ int wl1271_init_ap_rates(struct wl1271 *wl)
513 * If the basic rates contain OFDM rates, use OFDM only 452 * If the basic rates contain OFDM rates, use OFDM only
514 * rates for unicast TX as well. Else use all supported rates. 453 * rates for unicast TX as well. Else use all supported rates.
515 */ 454 */
516 if ((wl->basic_rate_set & CONF_TX_OFDM_RATES)) 455 if ((wlvif->basic_rate_set & CONF_TX_OFDM_RATES))
517 supported_rates = CONF_TX_OFDM_RATES; 456 supported_rates = CONF_TX_OFDM_RATES;
518 else 457 else
519 supported_rates = CONF_TX_AP_ENABLED_RATES; 458 supported_rates = CONF_TX_AP_ENABLED_RATES;
@@ -527,7 +466,8 @@ int wl1271_init_ap_rates(struct wl1271 *wl)
527 rc.short_retry_limit = 10; 466 rc.short_retry_limit = 10;
528 rc.long_retry_limit = 10; 467 rc.long_retry_limit = 10;
529 rc.aflags = 0; 468 rc.aflags = 0;
530 ret = wl1271_acx_ap_rate_policy(wl, &rc, i); 469 ret = wl1271_acx_ap_rate_policy(wl, &rc,
470 wlvif->ap.ucast_rate_idx[i]);
531 if (ret < 0) 471 if (ret < 0)
532 return ret; 472 return ret;
533 } 473 }
@@ -535,24 +475,23 @@ int wl1271_init_ap_rates(struct wl1271 *wl)
535 return 0; 475 return 0;
536} 476}
537 477
538static int wl1271_set_ba_policies(struct wl1271 *wl) 478static int wl1271_set_ba_policies(struct wl1271 *wl, struct wl12xx_vif *wlvif)
539{ 479{
540 /* Reset the BA RX indicators */ 480 /* Reset the BA RX indicators */
541 wl->ba_rx_bitmap = 0; 481 wlvif->ba_allowed = true;
542 wl->ba_allowed = true;
543 wl->ba_rx_session_count = 0; 482 wl->ba_rx_session_count = 0;
544 483
545 /* BA is supported in STA/AP modes */ 484 /* BA is supported in STA/AP modes */
546 if (wl->bss_type != BSS_TYPE_AP_BSS && 485 if (wlvif->bss_type != BSS_TYPE_AP_BSS &&
547 wl->bss_type != BSS_TYPE_STA_BSS) { 486 wlvif->bss_type != BSS_TYPE_STA_BSS) {
548 wl->ba_support = false; 487 wlvif->ba_support = false;
549 return 0; 488 return 0;
550 } 489 }
551 490
552 wl->ba_support = true; 491 wlvif->ba_support = true;
553 492
554 /* 802.11n initiator BA session setting */ 493 /* 802.11n initiator BA session setting */
555 return wl12xx_acx_set_ba_initiator_policy(wl); 494 return wl12xx_acx_set_ba_initiator_policy(wl, wlvif);
556} 495}
557 496
558int wl1271_chip_specific_init(struct wl1271 *wl) 497int wl1271_chip_specific_init(struct wl1271 *wl)
@@ -562,7 +501,7 @@ int wl1271_chip_specific_init(struct wl1271 *wl)
562 if (wl->chip.id == CHIP_ID_1283_PG20) { 501 if (wl->chip.id == CHIP_ID_1283_PG20) {
563 u32 host_cfg_bitmap = HOST_IF_CFG_RX_FIFO_ENABLE; 502 u32 host_cfg_bitmap = HOST_IF_CFG_RX_FIFO_ENABLE;
564 503
565 if (wl->quirks & WL12XX_QUIRK_BLOCKSIZE_ALIGNMENT) 504 if (!(wl->quirks & WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT))
566 /* Enable SDIO padding */ 505 /* Enable SDIO padding */
567 host_cfg_bitmap |= HOST_IF_CFG_TX_PAD_TO_SDIO_BLK; 506 host_cfg_bitmap |= HOST_IF_CFG_TX_PAD_TO_SDIO_BLK;
568 507
@@ -575,13 +514,150 @@ out:
575 return ret; 514 return ret;
576} 515}
577 516
517/* vif-specifc initialization */
518static int wl12xx_init_sta_role(struct wl1271 *wl, struct wl12xx_vif *wlvif)
519{
520 int ret;
578 521
579int wl1271_hw_init(struct wl1271 *wl) 522 ret = wl1271_acx_group_address_tbl(wl, wlvif, true, NULL, 0);
523 if (ret < 0)
524 return ret;
525
526 /* Initialize connection monitoring thresholds */
527 ret = wl1271_acx_conn_monit_params(wl, wlvif, false);
528 if (ret < 0)
529 return ret;
530
531 /* Beacon filtering */
532 ret = wl1271_init_sta_beacon_filter(wl, wlvif);
533 if (ret < 0)
534 return ret;
535
536 /* Beacons and broadcast settings */
537 ret = wl1271_init_beacon_broadcast(wl, wlvif);
538 if (ret < 0)
539 return ret;
540
541 /* Configure rssi/snr averaging weights */
542 ret = wl1271_acx_rssi_snr_avg_weights(wl, wlvif);
543 if (ret < 0)
544 return ret;
545
546 return 0;
547}
548
549/* vif-specific intialization */
550static int wl12xx_init_ap_role(struct wl1271 *wl, struct wl12xx_vif *wlvif)
551{
552 int ret;
553
554 ret = wl1271_acx_ap_max_tx_retry(wl, wlvif);
555 if (ret < 0)
556 return ret;
557
558 /* initialize Tx power */
559 ret = wl1271_acx_tx_power(wl, wlvif, wlvif->power_level);
560 if (ret < 0)
561 return ret;
562
563 return 0;
564}
565
566int wl1271_init_vif_specific(struct wl1271 *wl, struct ieee80211_vif *vif)
580{ 567{
568 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
581 struct conf_tx_ac_category *conf_ac; 569 struct conf_tx_ac_category *conf_ac;
582 struct conf_tx_tid *conf_tid; 570 struct conf_tx_tid *conf_tid;
571 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
583 int ret, i; 572 int ret, i;
584 bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS); 573
574 /*
575 * consider all existing roles before configuring psm.
576 * TODO: reconfigure on interface removal.
577 */
578 if (!wl->ap_count) {
579 if (is_ap) {
580 /* Configure for power always on */
581 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
582 if (ret < 0)
583 return ret;
584 } else if (!wl->sta_count) {
585 /* Configure for ELP power saving */
586 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);
587 if (ret < 0)
588 return ret;
589 }
590 }
591
592 /* Mode specific init */
593 if (is_ap) {
594 ret = wl1271_ap_hw_init(wl, wlvif);
595 if (ret < 0)
596 return ret;
597
598 ret = wl12xx_init_ap_role(wl, wlvif);
599 if (ret < 0)
600 return ret;
601 } else {
602 ret = wl1271_sta_hw_init(wl, wlvif);
603 if (ret < 0)
604 return ret;
605
606 ret = wl12xx_init_sta_role(wl, wlvif);
607 if (ret < 0)
608 return ret;
609 }
610
611 wl12xx_init_phy_vif_config(wl, wlvif);
612
613 /* Default TID/AC configuration */
614 BUG_ON(wl->conf.tx.tid_conf_count != wl->conf.tx.ac_conf_count);
615 for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
616 conf_ac = &wl->conf.tx.ac_conf[i];
617 ret = wl1271_acx_ac_cfg(wl, wlvif, conf_ac->ac,
618 conf_ac->cw_min, conf_ac->cw_max,
619 conf_ac->aifsn, conf_ac->tx_op_limit);
620 if (ret < 0)
621 return ret;
622
623 conf_tid = &wl->conf.tx.tid_conf[i];
624 ret = wl1271_acx_tid_cfg(wl, wlvif,
625 conf_tid->queue_id,
626 conf_tid->channel_type,
627 conf_tid->tsid,
628 conf_tid->ps_scheme,
629 conf_tid->ack_policy,
630 conf_tid->apsd_conf[0],
631 conf_tid->apsd_conf[1]);
632 if (ret < 0)
633 return ret;
634 }
635
636 /* Configure HW encryption */
637 ret = wl1271_acx_feature_cfg(wl, wlvif);
638 if (ret < 0)
639 return ret;
640
641 /* Mode specific init - post mem init */
642 if (is_ap)
643 ret = wl1271_ap_hw_init_post_mem(wl, vif);
644 else
645 ret = wl1271_sta_hw_init_post_mem(wl, vif);
646
647 if (ret < 0)
648 return ret;
649
650 /* Configure initiator BA sessions policies */
651 ret = wl1271_set_ba_policies(wl, wlvif);
652 if (ret < 0)
653 return ret;
654
655 return 0;
656}
657
658int wl1271_hw_init(struct wl1271 *wl)
659{
660 int ret;
585 661
586 if (wl->chip.id == CHIP_ID_1283_PG20) 662 if (wl->chip.id == CHIP_ID_1283_PG20)
587 ret = wl128x_cmd_general_parms(wl); 663 ret = wl128x_cmd_general_parms(wl);
@@ -602,12 +678,17 @@ int wl1271_hw_init(struct wl1271 *wl)
602 if (ret < 0) 678 if (ret < 0)
603 return ret; 679 return ret;
604 680
605 /* Mode specific init */ 681 /* Init templates */
606 if (is_ap) 682 ret = wl1271_init_templates_config(wl);
607 ret = wl1271_ap_hw_init(wl); 683 if (ret < 0)
608 else 684 return ret;
609 ret = wl1271_sta_hw_init(wl); 685
686 ret = wl12xx_acx_mem_cfg(wl);
687 if (ret < 0)
688 return ret;
610 689
690 /* Configure the FW logger */
691 ret = wl12xx_init_fwlog(wl);
611 if (ret < 0) 692 if (ret < 0)
612 return ret; 693 return ret;
613 694
@@ -655,61 +736,20 @@ int wl1271_hw_init(struct wl1271 *wl)
655 if (ret < 0) 736 if (ret < 0)
656 goto out_free_memmap; 737 goto out_free_memmap;
657 738
658 /* Default TID/AC configuration */
659 BUG_ON(wl->conf.tx.tid_conf_count != wl->conf.tx.ac_conf_count);
660 for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
661 conf_ac = &wl->conf.tx.ac_conf[i];
662 ret = wl1271_acx_ac_cfg(wl, conf_ac->ac, conf_ac->cw_min,
663 conf_ac->cw_max, conf_ac->aifsn,
664 conf_ac->tx_op_limit);
665 if (ret < 0)
666 goto out_free_memmap;
667
668 conf_tid = &wl->conf.tx.tid_conf[i];
669 ret = wl1271_acx_tid_cfg(wl, conf_tid->queue_id,
670 conf_tid->channel_type,
671 conf_tid->tsid,
672 conf_tid->ps_scheme,
673 conf_tid->ack_policy,
674 conf_tid->apsd_conf[0],
675 conf_tid->apsd_conf[1]);
676 if (ret < 0)
677 goto out_free_memmap;
678 }
679
680 /* Enable data path */ 739 /* Enable data path */
681 ret = wl1271_cmd_data_path(wl, 1); 740 ret = wl1271_cmd_data_path(wl, 1);
682 if (ret < 0) 741 if (ret < 0)
683 goto out_free_memmap; 742 goto out_free_memmap;
684 743
685 /* Configure HW encryption */
686 ret = wl1271_acx_feature_cfg(wl);
687 if (ret < 0)
688 goto out_free_memmap;
689
690 /* configure PM */ 744 /* configure PM */
691 ret = wl1271_acx_pm_config(wl); 745 ret = wl1271_acx_pm_config(wl);
692 if (ret < 0) 746 if (ret < 0)
693 goto out_free_memmap; 747 goto out_free_memmap;
694 748
695 /* Mode specific init - post mem init */
696 if (is_ap)
697 ret = wl1271_ap_hw_init_post_mem(wl);
698 else
699 ret = wl1271_sta_hw_init_post_mem(wl);
700
701 if (ret < 0)
702 goto out_free_memmap;
703
704 ret = wl12xx_acx_set_rate_mgmt_params(wl); 749 ret = wl12xx_acx_set_rate_mgmt_params(wl);
705 if (ret < 0) 750 if (ret < 0)
706 goto out_free_memmap; 751 goto out_free_memmap;
707 752
708 /* Configure initiator BA sessions policies */
709 ret = wl1271_set_ba_policies(wl);
710 if (ret < 0)
711 goto out_free_memmap;
712
713 /* configure hangover */ 753 /* configure hangover */
714 ret = wl12xx_acx_config_hangover(wl); 754 ret = wl12xx_acx_config_hangover(wl);
715 if (ret < 0) 755 if (ret < 0)
diff --git a/drivers/net/wireless/wl12xx/init.h b/drivers/net/wireless/wl12xx/init.h
index 3a3c230fd29..81140b81f65 100644
--- a/drivers/net/wireless/wl12xx/init.h
+++ b/drivers/net/wireless/wl12xx/init.h
@@ -27,13 +27,14 @@
27#include "wl12xx.h" 27#include "wl12xx.h"
28 28
29int wl1271_hw_init_power_auth(struct wl1271 *wl); 29int wl1271_hw_init_power_auth(struct wl1271 *wl);
30int wl1271_sta_init_templates_config(struct wl1271 *wl); 30int wl1271_init_templates_config(struct wl1271 *wl);
31int wl1271_init_phy_config(struct wl1271 *wl); 31int wl1271_init_phy_config(struct wl1271 *wl);
32int wl1271_init_pta(struct wl1271 *wl); 32int wl1271_init_pta(struct wl1271 *wl);
33int wl1271_init_energy_detection(struct wl1271 *wl); 33int wl1271_init_energy_detection(struct wl1271 *wl);
34int wl1271_chip_specific_init(struct wl1271 *wl); 34int wl1271_chip_specific_init(struct wl1271 *wl);
35int wl1271_hw_init(struct wl1271 *wl); 35int wl1271_hw_init(struct wl1271 *wl);
36int wl1271_init_ap_rates(struct wl1271 *wl); 36int wl1271_init_vif_specific(struct wl1271 *wl, struct ieee80211_vif *vif);
37int wl1271_ap_init_templates(struct wl1271 *wl); 37int wl1271_init_ap_rates(struct wl1271 *wl, struct wl12xx_vif *wlvif);
38int wl1271_ap_init_templates(struct wl1271 *wl, struct ieee80211_vif *vif);
38 39
39#endif 40#endif
diff --git a/drivers/net/wireless/wl12xx/io.c b/drivers/net/wireless/wl12xx/io.c
index c2da66f4504..079ad380e8f 100644
--- a/drivers/net/wireless/wl12xx/io.c
+++ b/drivers/net/wireless/wl12xx/io.c
@@ -24,8 +24,10 @@
24#include <linux/module.h> 24#include <linux/module.h>
25#include <linux/platform_device.h> 25#include <linux/platform_device.h>
26#include <linux/spi/spi.h> 26#include <linux/spi/spi.h>
27#include <linux/interrupt.h>
27 28
28#include "wl12xx.h" 29#include "wl12xx.h"
30#include "debug.h"
29#include "wl12xx_80211.h" 31#include "wl12xx_80211.h"
30#include "io.h" 32#include "io.h"
31#include "tx.h" 33#include "tx.h"
@@ -46,7 +48,7 @@
46bool wl1271_set_block_size(struct wl1271 *wl) 48bool wl1271_set_block_size(struct wl1271 *wl)
47{ 49{
48 if (wl->if_ops->set_block_size) { 50 if (wl->if_ops->set_block_size) {
49 wl->if_ops->set_block_size(wl, WL12XX_BUS_BLOCK_SIZE); 51 wl->if_ops->set_block_size(wl->dev, WL12XX_BUS_BLOCK_SIZE);
50 return true; 52 return true;
51 } 53 }
52 54
@@ -55,12 +57,12 @@ bool wl1271_set_block_size(struct wl1271 *wl)
55 57
56void wl1271_disable_interrupts(struct wl1271 *wl) 58void wl1271_disable_interrupts(struct wl1271 *wl)
57{ 59{
58 wl->if_ops->disable_irq(wl); 60 disable_irq(wl->irq);
59} 61}
60 62
61void wl1271_enable_interrupts(struct wl1271 *wl) 63void wl1271_enable_interrupts(struct wl1271 *wl)
62{ 64{
63 wl->if_ops->enable_irq(wl); 65 enable_irq(wl->irq);
64} 66}
65 67
66/* Set the SPI partitions to access the chip addresses 68/* Set the SPI partitions to access the chip addresses
@@ -128,13 +130,13 @@ EXPORT_SYMBOL_GPL(wl1271_set_partition);
128void wl1271_io_reset(struct wl1271 *wl) 130void wl1271_io_reset(struct wl1271 *wl)
129{ 131{
130 if (wl->if_ops->reset) 132 if (wl->if_ops->reset)
131 wl->if_ops->reset(wl); 133 wl->if_ops->reset(wl->dev);
132} 134}
133 135
134void wl1271_io_init(struct wl1271 *wl) 136void wl1271_io_init(struct wl1271 *wl)
135{ 137{
136 if (wl->if_ops->init) 138 if (wl->if_ops->init)
137 wl->if_ops->init(wl); 139 wl->if_ops->init(wl->dev);
138} 140}
139 141
140void wl1271_top_reg_write(struct wl1271 *wl, int addr, u16 val) 142void wl1271_top_reg_write(struct wl1271 *wl, int addr, u16 val)
diff --git a/drivers/net/wireless/wl12xx/io.h b/drivers/net/wireless/wl12xx/io.h
index e839341dfaf..d398cbcea98 100644
--- a/drivers/net/wireless/wl12xx/io.h
+++ b/drivers/net/wireless/wl12xx/io.h
@@ -51,23 +51,17 @@ void wl1271_enable_interrupts(struct wl1271 *wl);
51void wl1271_io_reset(struct wl1271 *wl); 51void wl1271_io_reset(struct wl1271 *wl);
52void wl1271_io_init(struct wl1271 *wl); 52void wl1271_io_init(struct wl1271 *wl);
53 53
54static inline struct device *wl1271_wl_to_dev(struct wl1271 *wl)
55{
56 return wl->if_ops->dev(wl);
57}
58
59
60/* Raw target IO, address is not translated */ 54/* Raw target IO, address is not translated */
61static inline void wl1271_raw_write(struct wl1271 *wl, int addr, void *buf, 55static inline void wl1271_raw_write(struct wl1271 *wl, int addr, void *buf,
62 size_t len, bool fixed) 56 size_t len, bool fixed)
63{ 57{
64 wl->if_ops->write(wl, addr, buf, len, fixed); 58 wl->if_ops->write(wl->dev, addr, buf, len, fixed);
65} 59}
66 60
67static inline void wl1271_raw_read(struct wl1271 *wl, int addr, void *buf, 61static inline void wl1271_raw_read(struct wl1271 *wl, int addr, void *buf,
68 size_t len, bool fixed) 62 size_t len, bool fixed)
69{ 63{
70 wl->if_ops->read(wl, addr, buf, len, fixed); 64 wl->if_ops->read(wl->dev, addr, buf, len, fixed);
71} 65}
72 66
73static inline u32 wl1271_raw_read32(struct wl1271 *wl, int addr) 67static inline u32 wl1271_raw_read32(struct wl1271 *wl, int addr)
@@ -155,13 +149,13 @@ static inline void wl1271_write32(struct wl1271 *wl, int addr, u32 val)
155 149
156static inline void wl1271_power_off(struct wl1271 *wl) 150static inline void wl1271_power_off(struct wl1271 *wl)
157{ 151{
158 wl->if_ops->power(wl, false); 152 wl->if_ops->power(wl->dev, false);
159 clear_bit(WL1271_FLAG_GPIO_POWER, &wl->flags); 153 clear_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
160} 154}
161 155
162static inline int wl1271_power_on(struct wl1271 *wl) 156static inline int wl1271_power_on(struct wl1271 *wl)
163{ 157{
164 int ret = wl->if_ops->power(wl, true); 158 int ret = wl->if_ops->power(wl->dev, true);
165 if (ret == 0) 159 if (ret == 0)
166 set_bit(WL1271_FLAG_GPIO_POWER, &wl->flags); 160 set_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
167 161
@@ -176,15 +170,10 @@ u16 wl1271_top_reg_read(struct wl1271 *wl, int addr);
176int wl1271_set_partition(struct wl1271 *wl, 170int wl1271_set_partition(struct wl1271 *wl,
177 struct wl1271_partition_set *p); 171 struct wl1271_partition_set *p);
178 172
173bool wl1271_set_block_size(struct wl1271 *wl);
174
179/* Functions from wl1271_main.c */ 175/* Functions from wl1271_main.c */
180 176
181int wl1271_register_hw(struct wl1271 *wl);
182void wl1271_unregister_hw(struct wl1271 *wl);
183int wl1271_init_ieee80211(struct wl1271 *wl);
184struct ieee80211_hw *wl1271_alloc_hw(void);
185int wl1271_free_hw(struct wl1271 *wl);
186irqreturn_t wl1271_irq(int irq, void *data);
187bool wl1271_set_block_size(struct wl1271 *wl);
188int wl1271_tx_dummy_packet(struct wl1271 *wl); 177int wl1271_tx_dummy_packet(struct wl1271 *wl);
189 178
190#endif 179#endif
diff --git a/drivers/net/wireless/wl12xx/main.c b/drivers/net/wireless/wl12xx/main.c
index 884f82b6321..2f7bfa86c8c 100644
--- a/drivers/net/wireless/wl12xx/main.c
+++ b/drivers/net/wireless/wl12xx/main.c
@@ -32,8 +32,10 @@
32#include <linux/slab.h> 32#include <linux/slab.h>
33#include <linux/wl12xx.h> 33#include <linux/wl12xx.h>
34#include <linux/sched.h> 34#include <linux/sched.h>
35#include <linux/interrupt.h>
35 36
36#include "wl12xx.h" 37#include "wl12xx.h"
38#include "debug.h"
37#include "wl12xx_80211.h" 39#include "wl12xx_80211.h"
38#include "reg.h" 40#include "reg.h"
39#include "io.h" 41#include "io.h"
@@ -377,42 +379,30 @@ static char *fwlog_param;
377static bool bug_on_recovery; 379static bool bug_on_recovery;
378 380
379static void __wl1271_op_remove_interface(struct wl1271 *wl, 381static void __wl1271_op_remove_interface(struct wl1271 *wl,
382 struct ieee80211_vif *vif,
380 bool reset_tx_queues); 383 bool reset_tx_queues);
381static void wl1271_free_ap_keys(struct wl1271 *wl); 384static void wl1271_op_stop(struct ieee80211_hw *hw);
382 385static void wl1271_free_ap_keys(struct wl1271 *wl, struct wl12xx_vif *wlvif);
383
384static void wl1271_device_release(struct device *dev)
385{
386
387}
388
389static struct platform_device wl1271_device = {
390 .name = "wl1271",
391 .id = -1,
392
393 /* device model insists to have a release function */
394 .dev = {
395 .release = wl1271_device_release,
396 },
397};
398 386
399static DEFINE_MUTEX(wl_list_mutex); 387static DEFINE_MUTEX(wl_list_mutex);
400static LIST_HEAD(wl_list); 388static LIST_HEAD(wl_list);
401 389
402static int wl1271_check_operstate(struct wl1271 *wl, unsigned char operstate) 390static int wl1271_check_operstate(struct wl1271 *wl, struct wl12xx_vif *wlvif,
391 unsigned char operstate)
403{ 392{
404 int ret; 393 int ret;
394
405 if (operstate != IF_OPER_UP) 395 if (operstate != IF_OPER_UP)
406 return 0; 396 return 0;
407 397
408 if (test_and_set_bit(WL1271_FLAG_STA_STATE_SENT, &wl->flags)) 398 if (test_and_set_bit(WLVIF_FLAG_STA_STATE_SENT, &wlvif->flags))
409 return 0; 399 return 0;
410 400
411 ret = wl12xx_cmd_set_peer_state(wl, wl->sta_hlid); 401 ret = wl12xx_cmd_set_peer_state(wl, wlvif->sta.hlid);
412 if (ret < 0) 402 if (ret < 0)
413 return ret; 403 return ret;
414 404
415 wl12xx_croc(wl, wl->role_id); 405 wl12xx_croc(wl, wlvif->role_id);
416 406
417 wl1271_info("Association completed."); 407 wl1271_info("Association completed.");
418 return 0; 408 return 0;
@@ -426,6 +416,7 @@ static int wl1271_dev_notify(struct notifier_block *me, unsigned long what,
426 struct ieee80211_hw *hw; 416 struct ieee80211_hw *hw;
427 struct wl1271 *wl; 417 struct wl1271 *wl;
428 struct wl1271 *wl_temp; 418 struct wl1271 *wl_temp;
419 struct wl12xx_vif *wlvif;
429 int ret = 0; 420 int ret = 0;
430 421
431 /* Check that this notification is for us. */ 422 /* Check that this notification is for us. */
@@ -459,17 +450,18 @@ static int wl1271_dev_notify(struct notifier_block *me, unsigned long what,
459 if (wl->state == WL1271_STATE_OFF) 450 if (wl->state == WL1271_STATE_OFF)
460 goto out; 451 goto out;
461 452
462 if (!test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) 453 wl12xx_for_each_wlvif_sta(wl, wlvif) {
463 goto out; 454 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
464 455 continue;
465 ret = wl1271_ps_elp_wakeup(wl);
466 if (ret < 0)
467 goto out;
468 456
469 wl1271_check_operstate(wl, dev->operstate); 457 ret = wl1271_ps_elp_wakeup(wl);
458 if (ret < 0)
459 goto out;
470 460
471 wl1271_ps_elp_sleep(wl); 461 wl1271_check_operstate(wl, wlvif, dev->operstate);
472 462
463 wl1271_ps_elp_sleep(wl);
464 }
473out: 465out:
474 mutex_unlock(&wl->mutex); 466 mutex_unlock(&wl->mutex);
475 467
@@ -498,19 +490,20 @@ static int wl1271_reg_notify(struct wiphy *wiphy,
498 return 0; 490 return 0;
499} 491}
500 492
501static int wl1271_set_rx_streaming(struct wl1271 *wl, bool enable) 493static int wl1271_set_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif,
494 bool enable)
502{ 495{
503 int ret = 0; 496 int ret = 0;
504 497
505 /* we should hold wl->mutex */ 498 /* we should hold wl->mutex */
506 ret = wl1271_acx_ps_rx_streaming(wl, enable); 499 ret = wl1271_acx_ps_rx_streaming(wl, wlvif, enable);
507 if (ret < 0) 500 if (ret < 0)
508 goto out; 501 goto out;
509 502
510 if (enable) 503 if (enable)
511 set_bit(WL1271_FLAG_RX_STREAMING_STARTED, &wl->flags); 504 set_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags);
512 else 505 else
513 clear_bit(WL1271_FLAG_RX_STREAMING_STARTED, &wl->flags); 506 clear_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags);
514out: 507out:
515 return ret; 508 return ret;
516} 509}
@@ -519,25 +512,25 @@ out:
519 * this function is being called when the rx_streaming interval 512 * this function is being called when the rx_streaming interval
520 * has beed changed or rx_streaming should be disabled 513 * has beed changed or rx_streaming should be disabled
521 */ 514 */
522int wl1271_recalc_rx_streaming(struct wl1271 *wl) 515int wl1271_recalc_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif)
523{ 516{
524 int ret = 0; 517 int ret = 0;
525 int period = wl->conf.rx_streaming.interval; 518 int period = wl->conf.rx_streaming.interval;
526 519
527 /* don't reconfigure if rx_streaming is disabled */ 520 /* don't reconfigure if rx_streaming is disabled */
528 if (!test_bit(WL1271_FLAG_RX_STREAMING_STARTED, &wl->flags)) 521 if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags))
529 goto out; 522 goto out;
530 523
531 /* reconfigure/disable according to new streaming_period */ 524 /* reconfigure/disable according to new streaming_period */
532 if (period && 525 if (period &&
533 test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags) && 526 test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) &&
534 (wl->conf.rx_streaming.always || 527 (wl->conf.rx_streaming.always ||
535 test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags))) 528 test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags)))
536 ret = wl1271_set_rx_streaming(wl, true); 529 ret = wl1271_set_rx_streaming(wl, wlvif, true);
537 else { 530 else {
538 ret = wl1271_set_rx_streaming(wl, false); 531 ret = wl1271_set_rx_streaming(wl, wlvif, false);
539 /* don't cancel_work_sync since we might deadlock */ 532 /* don't cancel_work_sync since we might deadlock */
540 del_timer_sync(&wl->rx_streaming_timer); 533 del_timer_sync(&wlvif->rx_streaming_timer);
541 } 534 }
542out: 535out:
543 return ret; 536 return ret;
@@ -546,13 +539,14 @@ out:
546static void wl1271_rx_streaming_enable_work(struct work_struct *work) 539static void wl1271_rx_streaming_enable_work(struct work_struct *work)
547{ 540{
548 int ret; 541 int ret;
549 struct wl1271 *wl = 542 struct wl12xx_vif *wlvif = container_of(work, struct wl12xx_vif,
550 container_of(work, struct wl1271, rx_streaming_enable_work); 543 rx_streaming_enable_work);
544 struct wl1271 *wl = wlvif->wl;
551 545
552 mutex_lock(&wl->mutex); 546 mutex_lock(&wl->mutex);
553 547
554 if (test_bit(WL1271_FLAG_RX_STREAMING_STARTED, &wl->flags) || 548 if (test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags) ||
555 !test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags) || 549 !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) ||
556 (!wl->conf.rx_streaming.always && 550 (!wl->conf.rx_streaming.always &&
557 !test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags))) 551 !test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags)))
558 goto out; 552 goto out;
@@ -564,12 +558,12 @@ static void wl1271_rx_streaming_enable_work(struct work_struct *work)
564 if (ret < 0) 558 if (ret < 0)
565 goto out; 559 goto out;
566 560
567 ret = wl1271_set_rx_streaming(wl, true); 561 ret = wl1271_set_rx_streaming(wl, wlvif, true);
568 if (ret < 0) 562 if (ret < 0)
569 goto out_sleep; 563 goto out_sleep;
570 564
571 /* stop it after some time of inactivity */ 565 /* stop it after some time of inactivity */
572 mod_timer(&wl->rx_streaming_timer, 566 mod_timer(&wlvif->rx_streaming_timer,
573 jiffies + msecs_to_jiffies(wl->conf.rx_streaming.duration)); 567 jiffies + msecs_to_jiffies(wl->conf.rx_streaming.duration));
574 568
575out_sleep: 569out_sleep:
@@ -581,19 +575,20 @@ out:
581static void wl1271_rx_streaming_disable_work(struct work_struct *work) 575static void wl1271_rx_streaming_disable_work(struct work_struct *work)
582{ 576{
583 int ret; 577 int ret;
584 struct wl1271 *wl = 578 struct wl12xx_vif *wlvif = container_of(work, struct wl12xx_vif,
585 container_of(work, struct wl1271, rx_streaming_disable_work); 579 rx_streaming_disable_work);
580 struct wl1271 *wl = wlvif->wl;
586 581
587 mutex_lock(&wl->mutex); 582 mutex_lock(&wl->mutex);
588 583
589 if (!test_bit(WL1271_FLAG_RX_STREAMING_STARTED, &wl->flags)) 584 if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags))
590 goto out; 585 goto out;
591 586
592 ret = wl1271_ps_elp_wakeup(wl); 587 ret = wl1271_ps_elp_wakeup(wl);
593 if (ret < 0) 588 if (ret < 0)
594 goto out; 589 goto out;
595 590
596 ret = wl1271_set_rx_streaming(wl, false); 591 ret = wl1271_set_rx_streaming(wl, wlvif, false);
597 if (ret) 592 if (ret)
598 goto out_sleep; 593 goto out_sleep;
599 594
@@ -605,8 +600,9 @@ out:
605 600
606static void wl1271_rx_streaming_timer(unsigned long data) 601static void wl1271_rx_streaming_timer(unsigned long data)
607{ 602{
608 struct wl1271 *wl = (struct wl1271 *)data; 603 struct wl12xx_vif *wlvif = (struct wl12xx_vif *)data;
609 ieee80211_queue_work(wl->hw, &wl->rx_streaming_disable_work); 604 struct wl1271 *wl = wlvif->wl;
605 ieee80211_queue_work(wl->hw, &wlvif->rx_streaming_disable_work);
610} 606}
611 607
612static void wl1271_conf_init(struct wl1271 *wl) 608static void wl1271_conf_init(struct wl1271 *wl)
@@ -645,9 +641,7 @@ static void wl1271_conf_init(struct wl1271 *wl)
645 641
646static int wl1271_plt_init(struct wl1271 *wl) 642static int wl1271_plt_init(struct wl1271 *wl)
647{ 643{
648 struct conf_tx_ac_category *conf_ac; 644 int ret;
649 struct conf_tx_tid *conf_tid;
650 int ret, i;
651 645
652 if (wl->chip.id == CHIP_ID_1283_PG20) 646 if (wl->chip.id == CHIP_ID_1283_PG20)
653 ret = wl128x_cmd_general_parms(wl); 647 ret = wl128x_cmd_general_parms(wl);
@@ -676,10 +670,6 @@ static int wl1271_plt_init(struct wl1271 *wl)
676 if (ret < 0) 670 if (ret < 0)
677 return ret; 671 return ret;
678 672
679 ret = wl1271_sta_init_templates_config(wl);
680 if (ret < 0)
681 return ret;
682
683 ret = wl1271_acx_init_mem_config(wl); 673 ret = wl1271_acx_init_mem_config(wl);
684 if (ret < 0) 674 if (ret < 0)
685 return ret; 675 return ret;
@@ -689,61 +679,10 @@ static int wl1271_plt_init(struct wl1271 *wl)
689 if (ret < 0) 679 if (ret < 0)
690 goto out_free_memmap; 680 goto out_free_memmap;
691 681
692 ret = wl1271_acx_dco_itrim_params(wl);
693 if (ret < 0)
694 goto out_free_memmap;
695
696 /* Initialize connection monitoring thresholds */
697 ret = wl1271_acx_conn_monit_params(wl, false);
698 if (ret < 0)
699 goto out_free_memmap;
700
701 /* Bluetooth WLAN coexistence */
702 ret = wl1271_init_pta(wl);
703 if (ret < 0)
704 goto out_free_memmap;
705
706 /* FM WLAN coexistence */
707 ret = wl1271_acx_fm_coex(wl);
708 if (ret < 0)
709 goto out_free_memmap;
710
711 /* Energy detection */
712 ret = wl1271_init_energy_detection(wl);
713 if (ret < 0)
714 goto out_free_memmap;
715
716 ret = wl12xx_acx_mem_cfg(wl); 682 ret = wl12xx_acx_mem_cfg(wl);
717 if (ret < 0) 683 if (ret < 0)
718 goto out_free_memmap; 684 goto out_free_memmap;
719 685
720 /* Default fragmentation threshold */
721 ret = wl1271_acx_frag_threshold(wl, wl->conf.tx.frag_threshold);
722 if (ret < 0)
723 goto out_free_memmap;
724
725 /* Default TID/AC configuration */
726 BUG_ON(wl->conf.tx.tid_conf_count != wl->conf.tx.ac_conf_count);
727 for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
728 conf_ac = &wl->conf.tx.ac_conf[i];
729 ret = wl1271_acx_ac_cfg(wl, conf_ac->ac, conf_ac->cw_min,
730 conf_ac->cw_max, conf_ac->aifsn,
731 conf_ac->tx_op_limit);
732 if (ret < 0)
733 goto out_free_memmap;
734
735 conf_tid = &wl->conf.tx.tid_conf[i];
736 ret = wl1271_acx_tid_cfg(wl, conf_tid->queue_id,
737 conf_tid->channel_type,
738 conf_tid->tsid,
739 conf_tid->ps_scheme,
740 conf_tid->ack_policy,
741 conf_tid->apsd_conf[0],
742 conf_tid->apsd_conf[1]);
743 if (ret < 0)
744 goto out_free_memmap;
745 }
746
747 /* Enable data path */ 686 /* Enable data path */
748 ret = wl1271_cmd_data_path(wl, 1); 687 ret = wl1271_cmd_data_path(wl, 1);
749 if (ret < 0) 688 if (ret < 0)
@@ -768,14 +707,12 @@ static int wl1271_plt_init(struct wl1271 *wl)
768 return ret; 707 return ret;
769} 708}
770 709
771static void wl12xx_irq_ps_regulate_link(struct wl1271 *wl, u8 hlid, u8 tx_pkts) 710static void wl12xx_irq_ps_regulate_link(struct wl1271 *wl,
711 struct wl12xx_vif *wlvif,
712 u8 hlid, u8 tx_pkts)
772{ 713{
773 bool fw_ps, single_sta; 714 bool fw_ps, single_sta;
774 715
775 /* only regulate station links */
776 if (hlid < WL1271_AP_STA_HLID_START)
777 return;
778
779 fw_ps = test_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map); 716 fw_ps = test_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map);
780 single_sta = (wl->active_sta_count == 1); 717 single_sta = (wl->active_sta_count == 1);
781 718
@@ -784,7 +721,7 @@ static void wl12xx_irq_ps_regulate_link(struct wl1271 *wl, u8 hlid, u8 tx_pkts)
784 * packets in FW or if the STA is awake. 721 * packets in FW or if the STA is awake.
785 */ 722 */
786 if (!fw_ps || tx_pkts < WL1271_PS_STA_MAX_PACKETS) 723 if (!fw_ps || tx_pkts < WL1271_PS_STA_MAX_PACKETS)
787 wl1271_ps_link_end(wl, hlid); 724 wl12xx_ps_link_end(wl, wlvif, hlid);
788 725
789 /* 726 /*
790 * Start high-level PS if the STA is asleep with enough blocks in FW. 727 * Start high-level PS if the STA is asleep with enough blocks in FW.
@@ -792,24 +729,14 @@ static void wl12xx_irq_ps_regulate_link(struct wl1271 *wl, u8 hlid, u8 tx_pkts)
792 * case FW-memory congestion is not a problem. 729 * case FW-memory congestion is not a problem.
793 */ 730 */
794 else if (!single_sta && fw_ps && tx_pkts >= WL1271_PS_STA_MAX_PACKETS) 731 else if (!single_sta && fw_ps && tx_pkts >= WL1271_PS_STA_MAX_PACKETS)
795 wl1271_ps_link_start(wl, hlid, true); 732 wl12xx_ps_link_start(wl, wlvif, hlid, true);
796}
797
798bool wl1271_is_active_sta(struct wl1271 *wl, u8 hlid)
799{
800 int id;
801
802 /* global/broadcast "stations" are always active */
803 if (hlid < WL1271_AP_STA_HLID_START)
804 return true;
805
806 id = hlid - WL1271_AP_STA_HLID_START;
807 return test_bit(id, wl->ap_hlid_map);
808} 733}
809 734
810static void wl12xx_irq_update_links_status(struct wl1271 *wl, 735static void wl12xx_irq_update_links_status(struct wl1271 *wl,
736 struct wl12xx_vif *wlvif,
811 struct wl12xx_fw_status *status) 737 struct wl12xx_fw_status *status)
812{ 738{
739 struct wl1271_link *lnk;
813 u32 cur_fw_ps_map; 740 u32 cur_fw_ps_map;
814 u8 hlid, cnt; 741 u8 hlid, cnt;
815 742
@@ -825,25 +752,22 @@ static void wl12xx_irq_update_links_status(struct wl1271 *wl,
825 wl->ap_fw_ps_map = cur_fw_ps_map; 752 wl->ap_fw_ps_map = cur_fw_ps_map;
826 } 753 }
827 754
828 for (hlid = WL1271_AP_STA_HLID_START; hlid < AP_MAX_LINKS; hlid++) { 755 for_each_set_bit(hlid, wlvif->ap.sta_hlid_map, WL12XX_MAX_LINKS) {
829 if (!wl1271_is_active_sta(wl, hlid)) 756 lnk = &wl->links[hlid];
830 continue; 757 cnt = status->tx_lnk_free_pkts[hlid] - lnk->prev_freed_pkts;
831
832 cnt = status->tx_lnk_free_pkts[hlid] -
833 wl->links[hlid].prev_freed_pkts;
834 758
835 wl->links[hlid].prev_freed_pkts = 759 lnk->prev_freed_pkts = status->tx_lnk_free_pkts[hlid];
836 status->tx_lnk_free_pkts[hlid]; 760 lnk->allocated_pkts -= cnt;
837 wl->links[hlid].allocated_pkts -= cnt;
838 761
839 wl12xx_irq_ps_regulate_link(wl, hlid, 762 wl12xx_irq_ps_regulate_link(wl, wlvif, hlid,
840 wl->links[hlid].allocated_pkts); 763 lnk->allocated_pkts);
841 } 764 }
842} 765}
843 766
844static void wl12xx_fw_status(struct wl1271 *wl, 767static void wl12xx_fw_status(struct wl1271 *wl,
845 struct wl12xx_fw_status *status) 768 struct wl12xx_fw_status *status)
846{ 769{
770 struct wl12xx_vif *wlvif;
847 struct timespec ts; 771 struct timespec ts;
848 u32 old_tx_blk_count = wl->tx_blocks_available; 772 u32 old_tx_blk_count = wl->tx_blocks_available;
849 int avail, freed_blocks; 773 int avail, freed_blocks;
@@ -898,8 +822,9 @@ static void wl12xx_fw_status(struct wl1271 *wl,
898 clear_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags); 822 clear_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags);
899 823
900 /* for AP update num of allocated TX blocks per link and ps status */ 824 /* for AP update num of allocated TX blocks per link and ps status */
901 if (wl->bss_type == BSS_TYPE_AP_BSS) 825 wl12xx_for_each_wlvif_ap(wl, wlvif) {
902 wl12xx_irq_update_links_status(wl, status); 826 wl12xx_irq_update_links_status(wl, wlvif, status);
827 }
903 828
904 /* update the host-chipset time offset */ 829 /* update the host-chipset time offset */
905 getnstimeofday(&ts); 830 getnstimeofday(&ts);
@@ -932,7 +857,7 @@ static void wl1271_netstack_work(struct work_struct *work)
932 857
933#define WL1271_IRQ_MAX_LOOPS 256 858#define WL1271_IRQ_MAX_LOOPS 256
934 859
935irqreturn_t wl1271_irq(int irq, void *cookie) 860static irqreturn_t wl1271_irq(int irq, void *cookie)
936{ 861{
937 int ret; 862 int ret;
938 u32 intr; 863 u32 intr;
@@ -1054,7 +979,6 @@ out:
1054 979
1055 return IRQ_HANDLED; 980 return IRQ_HANDLED;
1056} 981}
1057EXPORT_SYMBOL_GPL(wl1271_irq);
1058 982
1059static int wl1271_fetch_firmware(struct wl1271 *wl) 983static int wl1271_fetch_firmware(struct wl1271 *wl)
1060{ 984{
@@ -1069,10 +993,10 @@ static int wl1271_fetch_firmware(struct wl1271 *wl)
1069 993
1070 wl1271_debug(DEBUG_BOOT, "booting firmware %s", fw_name); 994 wl1271_debug(DEBUG_BOOT, "booting firmware %s", fw_name);
1071 995
1072 ret = request_firmware(&fw, fw_name, wl1271_wl_to_dev(wl)); 996 ret = request_firmware(&fw, fw_name, wl->dev);
1073 997
1074 if (ret < 0) { 998 if (ret < 0) {
1075 wl1271_error("could not get firmware: %d", ret); 999 wl1271_error("could not get firmware %s: %d", fw_name, ret);
1076 return ret; 1000 return ret;
1077 } 1001 }
1078 1002
@@ -1107,10 +1031,11 @@ static int wl1271_fetch_nvs(struct wl1271 *wl)
1107 const struct firmware *fw; 1031 const struct firmware *fw;
1108 int ret; 1032 int ret;
1109 1033
1110 ret = request_firmware(&fw, WL12XX_NVS_NAME, wl1271_wl_to_dev(wl)); 1034 ret = request_firmware(&fw, WL12XX_NVS_NAME, wl->dev);
1111 1035
1112 if (ret < 0) { 1036 if (ret < 0) {
1113 wl1271_error("could not get nvs file: %d", ret); 1037 wl1271_error("could not get nvs file %s: %d", WL12XX_NVS_NAME,
1038 ret);
1114 return ret; 1039 return ret;
1115 } 1040 }
1116 1041
@@ -1217,11 +1142,13 @@ static void wl1271_recovery_work(struct work_struct *work)
1217{ 1142{
1218 struct wl1271 *wl = 1143 struct wl1271 *wl =
1219 container_of(work, struct wl1271, recovery_work); 1144 container_of(work, struct wl1271, recovery_work);
1145 struct wl12xx_vif *wlvif;
1146 struct ieee80211_vif *vif;
1220 1147
1221 mutex_lock(&wl->mutex); 1148 mutex_lock(&wl->mutex);
1222 1149
1223 if (wl->state != WL1271_STATE_ON) 1150 if (wl->state != WL1271_STATE_ON)
1224 goto out; 1151 goto out_unlock;
1225 1152
1226 /* Avoid a recursive recovery */ 1153 /* Avoid a recursive recovery */
1227 set_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags); 1154 set_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags);
@@ -1238,9 +1165,12 @@ static void wl1271_recovery_work(struct work_struct *work)
1238 * in the firmware during recovery. This doens't hurt if the network is 1165 * in the firmware during recovery. This doens't hurt if the network is
1239 * not encrypted. 1166 * not encrypted.
1240 */ 1167 */
1241 if (test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags) || 1168 wl12xx_for_each_wlvif(wl, wlvif) {
1242 test_bit(WL1271_FLAG_AP_STARTED, &wl->flags)) 1169 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) ||
1243 wl->tx_security_seq += WL1271_TX_SQN_POST_RECOVERY_PADDING; 1170 test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags))
1171 wlvif->tx_security_seq +=
1172 WL1271_TX_SQN_POST_RECOVERY_PADDING;
1173 }
1244 1174
1245 /* Prevent spurious TX during FW restart */ 1175 /* Prevent spurious TX during FW restart */
1246 ieee80211_stop_queues(wl->hw); 1176 ieee80211_stop_queues(wl->hw);
@@ -1251,7 +1181,14 @@ static void wl1271_recovery_work(struct work_struct *work)
1251 } 1181 }
1252 1182
1253 /* reboot the chipset */ 1183 /* reboot the chipset */
1254 __wl1271_op_remove_interface(wl, false); 1184 while (!list_empty(&wl->wlvif_list)) {
1185 wlvif = list_first_entry(&wl->wlvif_list,
1186 struct wl12xx_vif, list);
1187 vif = wl12xx_wlvif_to_vif(wlvif);
1188 __wl1271_op_remove_interface(wl, vif, false);
1189 }
1190 mutex_unlock(&wl->mutex);
1191 wl1271_op_stop(wl->hw);
1255 1192
1256 clear_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags); 1193 clear_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags);
1257 1194
@@ -1262,8 +1199,8 @@ static void wl1271_recovery_work(struct work_struct *work)
1262 * to restart the HW. 1199 * to restart the HW.
1263 */ 1200 */
1264 ieee80211_wake_queues(wl->hw); 1201 ieee80211_wake_queues(wl->hw);
1265 1202 return;
1266out: 1203out_unlock:
1267 mutex_unlock(&wl->mutex); 1204 mutex_unlock(&wl->mutex);
1268} 1205}
1269 1206
@@ -1318,7 +1255,16 @@ static int wl1271_chip_wakeup(struct wl1271 *wl)
1318 /* 0. read chip id from CHIP_ID */ 1255 /* 0. read chip id from CHIP_ID */
1319 wl->chip.id = wl1271_read32(wl, CHIP_ID_B); 1256 wl->chip.id = wl1271_read32(wl, CHIP_ID_B);
1320 1257
1321 /* 1. check if chip id is valid */ 1258 /*
1259 * For wl127x based devices we could use the default block
1260 * size (512 bytes), but due to a bug in the sdio driver, we
1261 * need to set it explicitly after the chip is powered on. To
1262 * simplify the code and since the performance impact is
1263 * negligible, we use the same block size for all different
1264 * chip types.
1265 */
1266 if (!wl1271_set_block_size(wl))
1267 wl->quirks |= WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT;
1322 1268
1323 switch (wl->chip.id) { 1269 switch (wl->chip.id) {
1324 case CHIP_ID_1271_PG10: 1270 case CHIP_ID_1271_PG10:
@@ -1328,7 +1274,9 @@ static int wl1271_chip_wakeup(struct wl1271 *wl)
1328 ret = wl1271_setup(wl); 1274 ret = wl1271_setup(wl);
1329 if (ret < 0) 1275 if (ret < 0)
1330 goto out; 1276 goto out;
1277 wl->quirks |= WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT;
1331 break; 1278 break;
1279
1332 case CHIP_ID_1271_PG20: 1280 case CHIP_ID_1271_PG20:
1333 wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1271 PG20)", 1281 wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1271 PG20)",
1334 wl->chip.id); 1282 wl->chip.id);
@@ -1336,7 +1284,9 @@ static int wl1271_chip_wakeup(struct wl1271 *wl)
1336 ret = wl1271_setup(wl); 1284 ret = wl1271_setup(wl);
1337 if (ret < 0) 1285 if (ret < 0)
1338 goto out; 1286 goto out;
1287 wl->quirks |= WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT;
1339 break; 1288 break;
1289
1340 case CHIP_ID_1283_PG20: 1290 case CHIP_ID_1283_PG20:
1341 wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1283 PG20)", 1291 wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1283 PG20)",
1342 wl->chip.id); 1292 wl->chip.id);
@@ -1344,9 +1294,6 @@ static int wl1271_chip_wakeup(struct wl1271 *wl)
1344 ret = wl1271_setup(wl); 1294 ret = wl1271_setup(wl);
1345 if (ret < 0) 1295 if (ret < 0)
1346 goto out; 1296 goto out;
1347
1348 if (wl1271_set_block_size(wl))
1349 wl->quirks |= WL12XX_QUIRK_BLOCKSIZE_ALIGNMENT;
1350 break; 1297 break;
1351 case CHIP_ID_1283_PG10: 1298 case CHIP_ID_1283_PG10:
1352 default: 1299 default:
@@ -1389,8 +1336,6 @@ int wl1271_plt_start(struct wl1271 *wl)
1389 goto out; 1336 goto out;
1390 } 1337 }
1391 1338
1392 wl->bss_type = BSS_TYPE_STA_BSS;
1393
1394 while (retries) { 1339 while (retries) {
1395 retries--; 1340 retries--;
1396 ret = wl1271_chip_wakeup(wl); 1341 ret = wl1271_chip_wakeup(wl);
@@ -1482,33 +1427,34 @@ int wl1271_plt_stop(struct wl1271 *wl)
1482static void wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb) 1427static void wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
1483{ 1428{
1484 struct wl1271 *wl = hw->priv; 1429 struct wl1271 *wl = hw->priv;
1430 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1431 struct ieee80211_vif *vif = info->control.vif;
1432 struct wl12xx_vif *wlvif = NULL;
1485 unsigned long flags; 1433 unsigned long flags;
1486 int q, mapping; 1434 int q, mapping;
1487 u8 hlid = 0; 1435 u8 hlid;
1436
1437 if (vif)
1438 wlvif = wl12xx_vif_to_data(vif);
1488 1439
1489 mapping = skb_get_queue_mapping(skb); 1440 mapping = skb_get_queue_mapping(skb);
1490 q = wl1271_tx_get_queue(mapping); 1441 q = wl1271_tx_get_queue(mapping);
1491 1442
1492 if (wl->bss_type == BSS_TYPE_AP_BSS) 1443 hlid = wl12xx_tx_get_hlid(wl, wlvif, skb);
1493 hlid = wl12xx_tx_get_hlid_ap(wl, skb);
1494 1444
1495 spin_lock_irqsave(&wl->wl_lock, flags); 1445 spin_lock_irqsave(&wl->wl_lock, flags);
1496 1446
1497 /* queue the packet */ 1447 /* queue the packet */
1498 if (wl->bss_type == BSS_TYPE_AP_BSS) { 1448 if (hlid == WL12XX_INVALID_LINK_ID ||
1499 if (!wl1271_is_active_sta(wl, hlid)) { 1449 (wlvif && !test_bit(hlid, wlvif->links_map))) {
1500 wl1271_debug(DEBUG_TX, "DROP skb hlid %d q %d", 1450 wl1271_debug(DEBUG_TX, "DROP skb hlid %d q %d", hlid, q);
1501 hlid, q); 1451 dev_kfree_skb(skb);
1502 dev_kfree_skb(skb); 1452 goto out;
1503 goto out;
1504 }
1505
1506 wl1271_debug(DEBUG_TX, "queue skb hlid %d q %d", hlid, q);
1507 skb_queue_tail(&wl->links[hlid].tx_queue[q], skb);
1508 } else {
1509 skb_queue_tail(&wl->tx_queue[q], skb);
1510 } 1453 }
1511 1454
1455 wl1271_debug(DEBUG_TX, "queue skb hlid %d q %d", hlid, q);
1456 skb_queue_tail(&wl->links[hlid].tx_queue[q], skb);
1457
1512 wl->tx_queue_count[q]++; 1458 wl->tx_queue_count[q]++;
1513 1459
1514 /* 1460 /*
@@ -1609,13 +1555,14 @@ static struct notifier_block wl1271_dev_notifier = {
1609}; 1555};
1610 1556
1611#ifdef CONFIG_PM 1557#ifdef CONFIG_PM
1612static int wl1271_configure_suspend_sta(struct wl1271 *wl) 1558static int wl1271_configure_suspend_sta(struct wl1271 *wl,
1559 struct wl12xx_vif *wlvif)
1613{ 1560{
1614 int ret = 0; 1561 int ret = 0;
1615 1562
1616 mutex_lock(&wl->mutex); 1563 mutex_lock(&wl->mutex);
1617 1564
1618 if (!test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) 1565 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
1619 goto out_unlock; 1566 goto out_unlock;
1620 1567
1621 ret = wl1271_ps_elp_wakeup(wl); 1568 ret = wl1271_ps_elp_wakeup(wl);
@@ -1623,12 +1570,12 @@ static int wl1271_configure_suspend_sta(struct wl1271 *wl)
1623 goto out_unlock; 1570 goto out_unlock;
1624 1571
1625 /* enter psm if needed*/ 1572 /* enter psm if needed*/
1626 if (!test_bit(WL1271_FLAG_PSM, &wl->flags)) { 1573 if (!test_bit(WLVIF_FLAG_PSM, &wlvif->flags)) {
1627 DECLARE_COMPLETION_ONSTACK(compl); 1574 DECLARE_COMPLETION_ONSTACK(compl);
1628 1575
1629 wl->ps_compl = &compl; 1576 wlvif->ps_compl = &compl;
1630 ret = wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE, 1577 ret = wl1271_ps_set_mode(wl, wlvif, STATION_POWER_SAVE_MODE,
1631 wl->basic_rate, true); 1578 wlvif->basic_rate, true);
1632 if (ret < 0) 1579 if (ret < 0)
1633 goto out_sleep; 1580 goto out_sleep;
1634 1581
@@ -1660,20 +1607,21 @@ out:
1660 1607
1661} 1608}
1662 1609
1663static int wl1271_configure_suspend_ap(struct wl1271 *wl) 1610static int wl1271_configure_suspend_ap(struct wl1271 *wl,
1611 struct wl12xx_vif *wlvif)
1664{ 1612{
1665 int ret = 0; 1613 int ret = 0;
1666 1614
1667 mutex_lock(&wl->mutex); 1615 mutex_lock(&wl->mutex);
1668 1616
1669 if (!test_bit(WL1271_FLAG_AP_STARTED, &wl->flags)) 1617 if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags))
1670 goto out_unlock; 1618 goto out_unlock;
1671 1619
1672 ret = wl1271_ps_elp_wakeup(wl); 1620 ret = wl1271_ps_elp_wakeup(wl);
1673 if (ret < 0) 1621 if (ret < 0)
1674 goto out_unlock; 1622 goto out_unlock;
1675 1623
1676 ret = wl1271_acx_beacon_filter_opt(wl, true); 1624 ret = wl1271_acx_beacon_filter_opt(wl, wlvif, true);
1677 1625
1678 wl1271_ps_elp_sleep(wl); 1626 wl1271_ps_elp_sleep(wl);
1679out_unlock: 1627out_unlock:
@@ -1682,20 +1630,22 @@ out_unlock:
1682 1630
1683} 1631}
1684 1632
1685static int wl1271_configure_suspend(struct wl1271 *wl) 1633static int wl1271_configure_suspend(struct wl1271 *wl,
1634 struct wl12xx_vif *wlvif)
1686{ 1635{
1687 if (wl->bss_type == BSS_TYPE_STA_BSS) 1636 if (wlvif->bss_type == BSS_TYPE_STA_BSS)
1688 return wl1271_configure_suspend_sta(wl); 1637 return wl1271_configure_suspend_sta(wl, wlvif);
1689 if (wl->bss_type == BSS_TYPE_AP_BSS) 1638 if (wlvif->bss_type == BSS_TYPE_AP_BSS)
1690 return wl1271_configure_suspend_ap(wl); 1639 return wl1271_configure_suspend_ap(wl, wlvif);
1691 return 0; 1640 return 0;
1692} 1641}
1693 1642
1694static void wl1271_configure_resume(struct wl1271 *wl) 1643static void wl1271_configure_resume(struct wl1271 *wl,
1644 struct wl12xx_vif *wlvif)
1695{ 1645{
1696 int ret; 1646 int ret;
1697 bool is_sta = wl->bss_type == BSS_TYPE_STA_BSS; 1647 bool is_sta = wlvif->bss_type == BSS_TYPE_STA_BSS;
1698 bool is_ap = wl->bss_type == BSS_TYPE_AP_BSS; 1648 bool is_ap = wlvif->bss_type == BSS_TYPE_AP_BSS;
1699 1649
1700 if (!is_sta && !is_ap) 1650 if (!is_sta && !is_ap)
1701 return; 1651 return;
@@ -1707,11 +1657,11 @@ static void wl1271_configure_resume(struct wl1271 *wl)
1707 1657
1708 if (is_sta) { 1658 if (is_sta) {
1709 /* exit psm if it wasn't configured */ 1659 /* exit psm if it wasn't configured */
1710 if (!test_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags)) 1660 if (!test_bit(WLVIF_FLAG_PSM_REQUESTED, &wlvif->flags))
1711 wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE, 1661 wl1271_ps_set_mode(wl, wlvif, STATION_ACTIVE_MODE,
1712 wl->basic_rate, true); 1662 wlvif->basic_rate, true);
1713 } else if (is_ap) { 1663 } else if (is_ap) {
1714 wl1271_acx_beacon_filter_opt(wl, false); 1664 wl1271_acx_beacon_filter_opt(wl, wlvif, false);
1715 } 1665 }
1716 1666
1717 wl1271_ps_elp_sleep(wl); 1667 wl1271_ps_elp_sleep(wl);
@@ -1723,16 +1673,19 @@ static int wl1271_op_suspend(struct ieee80211_hw *hw,
1723 struct cfg80211_wowlan *wow) 1673 struct cfg80211_wowlan *wow)
1724{ 1674{
1725 struct wl1271 *wl = hw->priv; 1675 struct wl1271 *wl = hw->priv;
1676 struct wl12xx_vif *wlvif;
1726 int ret; 1677 int ret;
1727 1678
1728 wl1271_debug(DEBUG_MAC80211, "mac80211 suspend wow=%d", !!wow); 1679 wl1271_debug(DEBUG_MAC80211, "mac80211 suspend wow=%d", !!wow);
1729 WARN_ON(!wow || !wow->any); 1680 WARN_ON(!wow || !wow->any);
1730 1681
1731 wl->wow_enabled = true; 1682 wl->wow_enabled = true;
1732 ret = wl1271_configure_suspend(wl); 1683 wl12xx_for_each_wlvif(wl, wlvif) {
1733 if (ret < 0) { 1684 ret = wl1271_configure_suspend(wl, wlvif);
1734 wl1271_warning("couldn't prepare device to suspend"); 1685 if (ret < 0) {
1735 return ret; 1686 wl1271_warning("couldn't prepare device to suspend");
1687 return ret;
1688 }
1736 } 1689 }
1737 /* flush any remaining work */ 1690 /* flush any remaining work */
1738 wl1271_debug(DEBUG_MAC80211, "flushing remaining works"); 1691 wl1271_debug(DEBUG_MAC80211, "flushing remaining works");
@@ -1751,7 +1704,9 @@ static int wl1271_op_suspend(struct ieee80211_hw *hw,
1751 1704
1752 wl1271_enable_interrupts(wl); 1705 wl1271_enable_interrupts(wl);
1753 flush_work(&wl->tx_work); 1706 flush_work(&wl->tx_work);
1754 flush_delayed_work(&wl->pspoll_work); 1707 wl12xx_for_each_wlvif(wl, wlvif) {
1708 flush_delayed_work(&wlvif->pspoll_work);
1709 }
1755 flush_delayed_work(&wl->elp_work); 1710 flush_delayed_work(&wl->elp_work);
1756 1711
1757 return 0; 1712 return 0;
@@ -1760,6 +1715,7 @@ static int wl1271_op_suspend(struct ieee80211_hw *hw,
1760static int wl1271_op_resume(struct ieee80211_hw *hw) 1715static int wl1271_op_resume(struct ieee80211_hw *hw)
1761{ 1716{
1762 struct wl1271 *wl = hw->priv; 1717 struct wl1271 *wl = hw->priv;
1718 struct wl12xx_vif *wlvif;
1763 unsigned long flags; 1719 unsigned long flags;
1764 bool run_irq_work = false; 1720 bool run_irq_work = false;
1765 1721
@@ -1783,7 +1739,9 @@ static int wl1271_op_resume(struct ieee80211_hw *hw)
1783 wl1271_irq(0, wl); 1739 wl1271_irq(0, wl);
1784 wl1271_enable_interrupts(wl); 1740 wl1271_enable_interrupts(wl);
1785 } 1741 }
1786 wl1271_configure_resume(wl); 1742 wl12xx_for_each_wlvif(wl, wlvif) {
1743 wl1271_configure_resume(wl, wlvif);
1744 }
1787 wl->wow_enabled = false; 1745 wl->wow_enabled = false;
1788 1746
1789 return 0; 1747 return 0;
@@ -1810,20 +1768,119 @@ static int wl1271_op_start(struct ieee80211_hw *hw)
1810 1768
1811static void wl1271_op_stop(struct ieee80211_hw *hw) 1769static void wl1271_op_stop(struct ieee80211_hw *hw)
1812{ 1770{
1771 struct wl1271 *wl = hw->priv;
1772 int i;
1773
1813 wl1271_debug(DEBUG_MAC80211, "mac80211 stop"); 1774 wl1271_debug(DEBUG_MAC80211, "mac80211 stop");
1775
1776 mutex_lock(&wl->mutex);
1777 if (wl->state == WL1271_STATE_OFF) {
1778 mutex_unlock(&wl->mutex);
1779 return;
1780 }
1781 /*
1782 * this must be before the cancel_work calls below, so that the work
1783 * functions don't perform further work.
1784 */
1785 wl->state = WL1271_STATE_OFF;
1786 mutex_unlock(&wl->mutex);
1787
1788 mutex_lock(&wl_list_mutex);
1789 list_del(&wl->list);
1790 mutex_unlock(&wl_list_mutex);
1791
1792 wl1271_disable_interrupts(wl);
1793 wl1271_flush_deferred_work(wl);
1794 cancel_delayed_work_sync(&wl->scan_complete_work);
1795 cancel_work_sync(&wl->netstack_work);
1796 cancel_work_sync(&wl->tx_work);
1797 cancel_delayed_work_sync(&wl->elp_work);
1798
1799 /* let's notify MAC80211 about the remaining pending TX frames */
1800 wl12xx_tx_reset(wl, true);
1801 mutex_lock(&wl->mutex);
1802
1803 wl1271_power_off(wl);
1804
1805 wl->band = IEEE80211_BAND_2GHZ;
1806
1807 wl->rx_counter = 0;
1808 wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
1809 wl->tx_blocks_available = 0;
1810 wl->tx_allocated_blocks = 0;
1811 wl->tx_results_count = 0;
1812 wl->tx_packets_count = 0;
1813 wl->time_offset = 0;
1814 wl->tx_spare_blocks = TX_HW_BLOCK_SPARE_DEFAULT;
1815 wl->ap_fw_ps_map = 0;
1816 wl->ap_ps_map = 0;
1817 wl->sched_scanning = false;
1818 memset(wl->roles_map, 0, sizeof(wl->roles_map));
1819 memset(wl->links_map, 0, sizeof(wl->links_map));
1820 memset(wl->roc_map, 0, sizeof(wl->roc_map));
1821 wl->active_sta_count = 0;
1822
1823 /* The system link is always allocated */
1824 __set_bit(WL12XX_SYSTEM_HLID, wl->links_map);
1825
1826 /*
1827 * this is performed after the cancel_work calls and the associated
1828 * mutex_lock, so that wl1271_op_add_interface does not accidentally
1829 * get executed before all these vars have been reset.
1830 */
1831 wl->flags = 0;
1832
1833 wl->tx_blocks_freed = 0;
1834
1835 for (i = 0; i < NUM_TX_QUEUES; i++) {
1836 wl->tx_pkts_freed[i] = 0;
1837 wl->tx_allocated_pkts[i] = 0;
1838 }
1839
1840 wl1271_debugfs_reset(wl);
1841
1842 kfree(wl->fw_status);
1843 wl->fw_status = NULL;
1844 kfree(wl->tx_res_if);
1845 wl->tx_res_if = NULL;
1846 kfree(wl->target_mem_map);
1847 wl->target_mem_map = NULL;
1848
1849 mutex_unlock(&wl->mutex);
1814} 1850}
1815 1851
1816static u8 wl12xx_get_role_type(struct wl1271 *wl) 1852static int wl12xx_allocate_rate_policy(struct wl1271 *wl, u8 *idx)
1817{ 1853{
1818 switch (wl->bss_type) { 1854 u8 policy = find_first_zero_bit(wl->rate_policies_map,
1855 WL12XX_MAX_RATE_POLICIES);
1856 if (policy >= WL12XX_MAX_RATE_POLICIES)
1857 return -EBUSY;
1858
1859 __set_bit(policy, wl->rate_policies_map);
1860 *idx = policy;
1861 return 0;
1862}
1863
1864static void wl12xx_free_rate_policy(struct wl1271 *wl, u8 *idx)
1865{
1866 if (WARN_ON(*idx >= WL12XX_MAX_RATE_POLICIES))
1867 return;
1868
1869 __clear_bit(*idx, wl->rate_policies_map);
1870 *idx = WL12XX_MAX_RATE_POLICIES;
1871}
1872
1873static u8 wl12xx_get_role_type(struct wl1271 *wl, struct wl12xx_vif *wlvif)
1874{
1875 switch (wlvif->bss_type) {
1819 case BSS_TYPE_AP_BSS: 1876 case BSS_TYPE_AP_BSS:
1820 if (wl->p2p) 1877 if (wlvif->p2p)
1821 return WL1271_ROLE_P2P_GO; 1878 return WL1271_ROLE_P2P_GO;
1822 else 1879 else
1823 return WL1271_ROLE_AP; 1880 return WL1271_ROLE_AP;
1824 1881
1825 case BSS_TYPE_STA_BSS: 1882 case BSS_TYPE_STA_BSS:
1826 if (wl->p2p) 1883 if (wlvif->p2p)
1827 return WL1271_ROLE_P2P_CL; 1884 return WL1271_ROLE_P2P_CL;
1828 else 1885 else
1829 return WL1271_ROLE_STA; 1886 return WL1271_ROLE_STA;
@@ -1832,78 +1889,95 @@ static u8 wl12xx_get_role_type(struct wl1271 *wl)
1832 return WL1271_ROLE_IBSS; 1889 return WL1271_ROLE_IBSS;
1833 1890
1834 default: 1891 default:
1835 wl1271_error("invalid bss_type: %d", wl->bss_type); 1892 wl1271_error("invalid bss_type: %d", wlvif->bss_type);
1836 } 1893 }
1837 return WL12XX_INVALID_ROLE_TYPE; 1894 return WL12XX_INVALID_ROLE_TYPE;
1838} 1895}
1839 1896
1840static int wl1271_op_add_interface(struct ieee80211_hw *hw, 1897static int wl12xx_init_vif_data(struct wl1271 *wl, struct ieee80211_vif *vif)
1841 struct ieee80211_vif *vif)
1842{ 1898{
1843 struct wl1271 *wl = hw->priv; 1899 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
1844 struct wiphy *wiphy = hw->wiphy; 1900 int i;
1845 int retries = WL1271_BOOT_RETRIES;
1846 int ret = 0;
1847 u8 role_type;
1848 bool booted = false;
1849
1850 wl1271_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM",
1851 ieee80211_vif_type_p2p(vif), vif->addr);
1852
1853 mutex_lock(&wl->mutex);
1854 if (wl->vif) {
1855 wl1271_debug(DEBUG_MAC80211,
1856 "multiple vifs are not supported yet");
1857 ret = -EBUSY;
1858 goto out;
1859 }
1860 1901
1861 /* 1902 /* clear everything but the persistent data */
1862 * in some very corner case HW recovery scenarios its possible to 1903 memset(wlvif, 0, offsetof(struct wl12xx_vif, persistent));
1863 * get here before __wl1271_op_remove_interface is complete, so
1864 * opt out if that is the case.
1865 */
1866 if (test_bit(WL1271_FLAG_IF_INITIALIZED, &wl->flags)) {
1867 ret = -EBUSY;
1868 goto out;
1869 }
1870 1904
1871 switch (ieee80211_vif_type_p2p(vif)) { 1905 switch (ieee80211_vif_type_p2p(vif)) {
1872 case NL80211_IFTYPE_P2P_CLIENT: 1906 case NL80211_IFTYPE_P2P_CLIENT:
1873 wl->p2p = 1; 1907 wlvif->p2p = 1;
1874 /* fall-through */ 1908 /* fall-through */
1875 case NL80211_IFTYPE_STATION: 1909 case NL80211_IFTYPE_STATION:
1876 wl->bss_type = BSS_TYPE_STA_BSS; 1910 wlvif->bss_type = BSS_TYPE_STA_BSS;
1877 wl->set_bss_type = BSS_TYPE_STA_BSS;
1878 break; 1911 break;
1879 case NL80211_IFTYPE_ADHOC: 1912 case NL80211_IFTYPE_ADHOC:
1880 wl->bss_type = BSS_TYPE_IBSS; 1913 wlvif->bss_type = BSS_TYPE_IBSS;
1881 wl->set_bss_type = BSS_TYPE_STA_BSS;
1882 break; 1914 break;
1883 case NL80211_IFTYPE_P2P_GO: 1915 case NL80211_IFTYPE_P2P_GO:
1884 wl->p2p = 1; 1916 wlvif->p2p = 1;
1885 /* fall-through */ 1917 /* fall-through */
1886 case NL80211_IFTYPE_AP: 1918 case NL80211_IFTYPE_AP:
1887 wl->bss_type = BSS_TYPE_AP_BSS; 1919 wlvif->bss_type = BSS_TYPE_AP_BSS;
1888 break; 1920 break;
1889 default: 1921 default:
1890 ret = -EOPNOTSUPP; 1922 wlvif->bss_type = MAX_BSS_TYPE;
1891 goto out; 1923 return -EOPNOTSUPP;
1892 } 1924 }
1893 1925
1894 role_type = wl12xx_get_role_type(wl); 1926 wlvif->role_id = WL12XX_INVALID_ROLE_ID;
1895 if (role_type == WL12XX_INVALID_ROLE_TYPE) { 1927 wlvif->dev_role_id = WL12XX_INVALID_ROLE_ID;
1896 ret = -EINVAL; 1928 wlvif->dev_hlid = WL12XX_INVALID_LINK_ID;
1897 goto out; 1929
1930 if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
1931 wlvif->bss_type == BSS_TYPE_IBSS) {
1932 /* init sta/ibss data */
1933 wlvif->sta.hlid = WL12XX_INVALID_LINK_ID;
1934 wl12xx_allocate_rate_policy(wl, &wlvif->sta.basic_rate_idx);
1935 wl12xx_allocate_rate_policy(wl, &wlvif->sta.ap_rate_idx);
1936 wl12xx_allocate_rate_policy(wl, &wlvif->sta.p2p_rate_idx);
1937 } else {
1938 /* init ap data */
1939 wlvif->ap.bcast_hlid = WL12XX_INVALID_LINK_ID;
1940 wlvif->ap.global_hlid = WL12XX_INVALID_LINK_ID;
1941 wl12xx_allocate_rate_policy(wl, &wlvif->ap.mgmt_rate_idx);
1942 wl12xx_allocate_rate_policy(wl, &wlvif->ap.bcast_rate_idx);
1943 for (i = 0; i < CONF_TX_MAX_AC_COUNT; i++)
1944 wl12xx_allocate_rate_policy(wl,
1945 &wlvif->ap.ucast_rate_idx[i]);
1898 } 1946 }
1899 memcpy(wl->mac_addr, vif->addr, ETH_ALEN);
1900 1947
1901 if (wl->state != WL1271_STATE_OFF) { 1948 wlvif->bitrate_masks[IEEE80211_BAND_2GHZ] = wl->conf.tx.basic_rate;
1902 wl1271_error("cannot start because not in off state: %d", 1949 wlvif->bitrate_masks[IEEE80211_BAND_5GHZ] = wl->conf.tx.basic_rate_5;
1903 wl->state); 1950 wlvif->basic_rate_set = CONF_TX_RATE_MASK_BASIC;
1904 ret = -EBUSY; 1951 wlvif->basic_rate = CONF_TX_RATE_MASK_BASIC;
1905 goto out; 1952 wlvif->rate_set = CONF_TX_RATE_MASK_BASIC;
1906 } 1953 wlvif->beacon_int = WL1271_DEFAULT_BEACON_INT;
1954
1955 /*
1956 * mac80211 configures some values globally, while we treat them
1957 * per-interface. thus, on init, we have to copy them from wl
1958 */
1959 wlvif->band = wl->band;
1960 wlvif->channel = wl->channel;
1961 wlvif->power_level = wl->power_level;
1962
1963 INIT_WORK(&wlvif->rx_streaming_enable_work,
1964 wl1271_rx_streaming_enable_work);
1965 INIT_WORK(&wlvif->rx_streaming_disable_work,
1966 wl1271_rx_streaming_disable_work);
1967 INIT_DELAYED_WORK(&wlvif->pspoll_work, wl1271_pspoll_work);
1968 INIT_LIST_HEAD(&wlvif->list);
1969
1970 setup_timer(&wlvif->rx_streaming_timer, wl1271_rx_streaming_timer,
1971 (unsigned long) wlvif);
1972 return 0;
1973}
1974
1975static bool wl12xx_init_fw(struct wl1271 *wl)
1976{
1977 int retries = WL1271_BOOT_RETRIES;
1978 bool booted = false;
1979 struct wiphy *wiphy = wl->hw->wiphy;
1980 int ret;
1907 1981
1908 while (retries) { 1982 while (retries) {
1909 retries--; 1983 retries--;
@@ -1915,25 +1989,6 @@ static int wl1271_op_add_interface(struct ieee80211_hw *hw,
1915 if (ret < 0) 1989 if (ret < 0)
1916 goto power_off; 1990 goto power_off;
1917 1991
1918 if (wl->bss_type == BSS_TYPE_STA_BSS ||
1919 wl->bss_type == BSS_TYPE_IBSS) {
1920 /*
1921 * The device role is a special role used for
1922 * rx and tx frames prior to association (as
1923 * the STA role can get packets only from
1924 * its associated bssid)
1925 */
1926 ret = wl12xx_cmd_role_enable(wl,
1927 WL1271_ROLE_DEVICE,
1928 &wl->dev_role_id);
1929 if (ret < 0)
1930 goto irq_disable;
1931 }
1932
1933 ret = wl12xx_cmd_role_enable(wl, role_type, &wl->role_id);
1934 if (ret < 0)
1935 goto irq_disable;
1936
1937 ret = wl1271_hw_init(wl); 1992 ret = wl1271_hw_init(wl);
1938 if (ret < 0) 1993 if (ret < 0)
1939 goto irq_disable; 1994 goto irq_disable;
@@ -1964,9 +2019,6 @@ power_off:
1964 goto out; 2019 goto out;
1965 } 2020 }
1966 2021
1967 wl->vif = vif;
1968 wl->state = WL1271_STATE_ON;
1969 set_bit(WL1271_FLAG_IF_INITIALIZED, &wl->flags);
1970 wl1271_info("firmware booted (%s)", wl->chip.fw_ver_str); 2022 wl1271_info("firmware booted (%s)", wl->chip.fw_ver_str);
1971 2023
1972 /* update hw/fw version info in wiphy struct */ 2024 /* update hw/fw version info in wiphy struct */
@@ -1984,7 +2036,110 @@ power_off:
1984 wl1271_debug(DEBUG_MAC80211, "11a is %ssupported", 2036 wl1271_debug(DEBUG_MAC80211, "11a is %ssupported",
1985 wl->enable_11a ? "" : "not "); 2037 wl->enable_11a ? "" : "not ");
1986 2038
2039 wl->state = WL1271_STATE_ON;
1987out: 2040out:
2041 return booted;
2042}
2043
2044static int wl1271_op_add_interface(struct ieee80211_hw *hw,
2045 struct ieee80211_vif *vif)
2046{
2047 struct wl1271 *wl = hw->priv;
2048 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
2049 int ret = 0;
2050 u8 role_type;
2051 bool booted = false;
2052
2053 wl1271_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM",
2054 ieee80211_vif_type_p2p(vif), vif->addr);
2055
2056 mutex_lock(&wl->mutex);
2057 ret = wl1271_ps_elp_wakeup(wl);
2058 if (ret < 0)
2059 goto out_unlock;
2060
2061 if (wl->vif) {
2062 wl1271_debug(DEBUG_MAC80211,
2063 "multiple vifs are not supported yet");
2064 ret = -EBUSY;
2065 goto out;
2066 }
2067
2068 /*
2069 * in some very corner case HW recovery scenarios its possible to
2070 * get here before __wl1271_op_remove_interface is complete, so
2071 * opt out if that is the case.
2072 */
2073 if (test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags) ||
2074 test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)) {
2075 ret = -EBUSY;
2076 goto out;
2077 }
2078
2079 ret = wl12xx_init_vif_data(wl, vif);
2080 if (ret < 0)
2081 goto out;
2082
2083 wlvif->wl = wl;
2084 role_type = wl12xx_get_role_type(wl, wlvif);
2085 if (role_type == WL12XX_INVALID_ROLE_TYPE) {
2086 ret = -EINVAL;
2087 goto out;
2088 }
2089
2090 /*
2091 * TODO: after the nvs issue will be solved, move this block
2092 * to start(), and make sure here the driver is ON.
2093 */
2094 if (wl->state == WL1271_STATE_OFF) {
2095 /*
2096 * we still need this in order to configure the fw
2097 * while uploading the nvs
2098 */
2099 memcpy(wl->mac_addr, vif->addr, ETH_ALEN);
2100
2101 booted = wl12xx_init_fw(wl);
2102 if (!booted) {
2103 ret = -EINVAL;
2104 goto out;
2105 }
2106 }
2107
2108 if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
2109 wlvif->bss_type == BSS_TYPE_IBSS) {
2110 /*
2111 * The device role is a special role used for
2112 * rx and tx frames prior to association (as
2113 * the STA role can get packets only from
2114 * its associated bssid)
2115 */
2116 ret = wl12xx_cmd_role_enable(wl, vif->addr,
2117 WL1271_ROLE_DEVICE,
2118 &wlvif->dev_role_id);
2119 if (ret < 0)
2120 goto out;
2121 }
2122
2123 ret = wl12xx_cmd_role_enable(wl, vif->addr,
2124 role_type, &wlvif->role_id);
2125 if (ret < 0)
2126 goto out;
2127
2128 ret = wl1271_init_vif_specific(wl, vif);
2129 if (ret < 0)
2130 goto out;
2131
2132 wl->vif = vif;
2133 list_add(&wlvif->list, &wl->wlvif_list);
2134 set_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags);
2135
2136 if (wlvif->bss_type == BSS_TYPE_AP_BSS)
2137 wl->ap_count++;
2138 else
2139 wl->sta_count++;
2140out:
2141 wl1271_ps_elp_sleep(wl);
2142out_unlock:
1988 mutex_unlock(&wl->mutex); 2143 mutex_unlock(&wl->mutex);
1989 2144
1990 mutex_lock(&wl_list_mutex); 2145 mutex_lock(&wl_list_mutex);
@@ -1996,29 +2151,34 @@ out:
1996} 2151}
1997 2152
1998static void __wl1271_op_remove_interface(struct wl1271 *wl, 2153static void __wl1271_op_remove_interface(struct wl1271 *wl,
2154 struct ieee80211_vif *vif,
1999 bool reset_tx_queues) 2155 bool reset_tx_queues)
2000{ 2156{
2001 int ret, i; 2157 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
2158 int i, ret;
2002 2159
2003 wl1271_debug(DEBUG_MAC80211, "mac80211 remove interface"); 2160 wl1271_debug(DEBUG_MAC80211, "mac80211 remove interface");
2004 2161
2162 if (!test_and_clear_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))
2163 return;
2164
2165 wl->vif = NULL;
2166
2005 /* because of hardware recovery, we may get here twice */ 2167 /* because of hardware recovery, we may get here twice */
2006 if (wl->state != WL1271_STATE_ON) 2168 if (wl->state != WL1271_STATE_ON)
2007 return; 2169 return;
2008 2170
2009 wl1271_info("down"); 2171 wl1271_info("down");
2010 2172
2011 mutex_lock(&wl_list_mutex);
2012 list_del(&wl->list);
2013 mutex_unlock(&wl_list_mutex);
2014
2015 /* enable dyn ps just in case (if left on due to fw crash etc) */ 2173 /* enable dyn ps just in case (if left on due to fw crash etc) */
2016 if (wl->bss_type == BSS_TYPE_STA_BSS) 2174 if (wlvif->bss_type == BSS_TYPE_STA_BSS)
2017 ieee80211_enable_dyn_ps(wl->vif); 2175 ieee80211_enable_dyn_ps(vif);
2018 2176
2019 if (wl->scan.state != WL1271_SCAN_STATE_IDLE) { 2177 if (wl->scan.state != WL1271_SCAN_STATE_IDLE &&
2178 wl->scan_vif == vif) {
2020 wl->scan.state = WL1271_SCAN_STATE_IDLE; 2179 wl->scan.state = WL1271_SCAN_STATE_IDLE;
2021 memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch)); 2180 memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
2181 wl->scan_vif = NULL;
2022 wl->scan.req = NULL; 2182 wl->scan.req = NULL;
2023 ieee80211_scan_completed(wl->hw, true); 2183 ieee80211_scan_completed(wl->hw, true);
2024 } 2184 }
@@ -2029,13 +2189,13 @@ static void __wl1271_op_remove_interface(struct wl1271 *wl,
2029 if (ret < 0) 2189 if (ret < 0)
2030 goto deinit; 2190 goto deinit;
2031 2191
2032 if (wl->bss_type == BSS_TYPE_STA_BSS) { 2192 if (wlvif->bss_type == BSS_TYPE_STA_BSS) {
2033 ret = wl12xx_cmd_role_disable(wl, &wl->dev_role_id); 2193 ret = wl12xx_cmd_role_disable(wl, &wlvif->dev_role_id);
2034 if (ret < 0) 2194 if (ret < 0)
2035 goto deinit; 2195 goto deinit;
2036 } 2196 }
2037 2197
2038 ret = wl12xx_cmd_role_disable(wl, &wl->role_id); 2198 ret = wl12xx_cmd_role_disable(wl, &wlvif->role_id);
2039 if (ret < 0) 2199 if (ret < 0)
2040 goto deinit; 2200 goto deinit;
2041 2201
@@ -2043,120 +2203,82 @@ static void __wl1271_op_remove_interface(struct wl1271 *wl,
2043 } 2203 }
2044deinit: 2204deinit:
2045 /* clear all hlids (except system_hlid) */ 2205 /* clear all hlids (except system_hlid) */
2046 wl->sta_hlid = WL12XX_INVALID_LINK_ID; 2206 wlvif->dev_hlid = WL12XX_INVALID_LINK_ID;
2047 wl->dev_hlid = WL12XX_INVALID_LINK_ID; 2207
2048 wl->ap_bcast_hlid = WL12XX_INVALID_LINK_ID; 2208 if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
2049 wl->ap_global_hlid = WL12XX_INVALID_LINK_ID; 2209 wlvif->bss_type == BSS_TYPE_IBSS) {
2210 wlvif->sta.hlid = WL12XX_INVALID_LINK_ID;
2211 wl12xx_free_rate_policy(wl, &wlvif->sta.basic_rate_idx);
2212 wl12xx_free_rate_policy(wl, &wlvif->sta.ap_rate_idx);
2213 wl12xx_free_rate_policy(wl, &wlvif->sta.p2p_rate_idx);
2214 } else {
2215 wlvif->ap.bcast_hlid = WL12XX_INVALID_LINK_ID;
2216 wlvif->ap.global_hlid = WL12XX_INVALID_LINK_ID;
2217 wl12xx_free_rate_policy(wl, &wlvif->ap.mgmt_rate_idx);
2218 wl12xx_free_rate_policy(wl, &wlvif->ap.bcast_rate_idx);
2219 for (i = 0; i < CONF_TX_MAX_AC_COUNT; i++)
2220 wl12xx_free_rate_policy(wl,
2221 &wlvif->ap.ucast_rate_idx[i]);
2222 }
2050 2223
2051 /* 2224 wl12xx_tx_reset_wlvif(wl, wlvif);
2052 * this must be before the cancel_work calls below, so that the work 2225 wl1271_free_ap_keys(wl, wlvif);
2053 * functions don't perform further work. 2226 if (wl->last_wlvif == wlvif)
2054 */ 2227 wl->last_wlvif = NULL;
2055 wl->state = WL1271_STATE_OFF; 2228 list_del(&wlvif->list);
2229 memset(wlvif->ap.sta_hlid_map, 0, sizeof(wlvif->ap.sta_hlid_map));
2230 wlvif->role_id = WL12XX_INVALID_ROLE_ID;
2231 wlvif->dev_role_id = WL12XX_INVALID_ROLE_ID;
2232
2233 if (wlvif->bss_type == BSS_TYPE_AP_BSS)
2234 wl->ap_count--;
2235 else
2236 wl->sta_count--;
2056 2237
2057 mutex_unlock(&wl->mutex); 2238 mutex_unlock(&wl->mutex);
2058 2239 del_timer_sync(&wlvif->rx_streaming_timer);
2059 wl1271_disable_interrupts(wl); 2240 cancel_work_sync(&wlvif->rx_streaming_enable_work);
2060 wl1271_flush_deferred_work(wl); 2241 cancel_work_sync(&wlvif->rx_streaming_disable_work);
2061 cancel_delayed_work_sync(&wl->scan_complete_work); 2242 cancel_delayed_work_sync(&wlvif->pspoll_work);
2062 cancel_work_sync(&wl->netstack_work);
2063 cancel_work_sync(&wl->tx_work);
2064 del_timer_sync(&wl->rx_streaming_timer);
2065 cancel_work_sync(&wl->rx_streaming_enable_work);
2066 cancel_work_sync(&wl->rx_streaming_disable_work);
2067 cancel_delayed_work_sync(&wl->pspoll_work);
2068 cancel_delayed_work_sync(&wl->elp_work);
2069 2243
2070 mutex_lock(&wl->mutex); 2244 mutex_lock(&wl->mutex);
2071
2072 /* let's notify MAC80211 about the remaining pending TX frames */
2073 wl1271_tx_reset(wl, reset_tx_queues);
2074 wl1271_power_off(wl);
2075
2076 memset(wl->bssid, 0, ETH_ALEN);
2077 memset(wl->ssid, 0, IEEE80211_MAX_SSID_LEN + 1);
2078 wl->ssid_len = 0;
2079 wl->bss_type = MAX_BSS_TYPE;
2080 wl->set_bss_type = MAX_BSS_TYPE;
2081 wl->p2p = 0;
2082 wl->band = IEEE80211_BAND_2GHZ;
2083
2084 wl->rx_counter = 0;
2085 wl->psm_entry_retry = 0;
2086 wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
2087 wl->tx_blocks_available = 0;
2088 wl->tx_allocated_blocks = 0;
2089 wl->tx_results_count = 0;
2090 wl->tx_packets_count = 0;
2091 wl->time_offset = 0;
2092 wl->session_counter = 0;
2093 wl->rate_set = CONF_TX_RATE_MASK_BASIC;
2094 wl->bitrate_masks[IEEE80211_BAND_2GHZ] = wl->conf.tx.basic_rate;
2095 wl->bitrate_masks[IEEE80211_BAND_5GHZ] = wl->conf.tx.basic_rate_5;
2096 wl->vif = NULL;
2097 wl->tx_spare_blocks = TX_HW_BLOCK_SPARE_DEFAULT;
2098 wl1271_free_ap_keys(wl);
2099 memset(wl->ap_hlid_map, 0, sizeof(wl->ap_hlid_map));
2100 wl->ap_fw_ps_map = 0;
2101 wl->ap_ps_map = 0;
2102 wl->sched_scanning = false;
2103 wl->role_id = WL12XX_INVALID_ROLE_ID;
2104 wl->dev_role_id = WL12XX_INVALID_ROLE_ID;
2105 memset(wl->roles_map, 0, sizeof(wl->roles_map));
2106 memset(wl->links_map, 0, sizeof(wl->links_map));
2107 memset(wl->roc_map, 0, sizeof(wl->roc_map));
2108 wl->active_sta_count = 0;
2109
2110 /* The system link is always allocated */
2111 __set_bit(WL12XX_SYSTEM_HLID, wl->links_map);
2112
2113 /*
2114 * this is performed after the cancel_work calls and the associated
2115 * mutex_lock, so that wl1271_op_add_interface does not accidentally
2116 * get executed before all these vars have been reset.
2117 */
2118 wl->flags = 0;
2119
2120 wl->tx_blocks_freed = 0;
2121
2122 for (i = 0; i < NUM_TX_QUEUES; i++) {
2123 wl->tx_pkts_freed[i] = 0;
2124 wl->tx_allocated_pkts[i] = 0;
2125 }
2126
2127 wl1271_debugfs_reset(wl);
2128
2129 kfree(wl->fw_status);
2130 wl->fw_status = NULL;
2131 kfree(wl->tx_res_if);
2132 wl->tx_res_if = NULL;
2133 kfree(wl->target_mem_map);
2134 wl->target_mem_map = NULL;
2135} 2245}
2136 2246
2137static void wl1271_op_remove_interface(struct ieee80211_hw *hw, 2247static void wl1271_op_remove_interface(struct ieee80211_hw *hw,
2138 struct ieee80211_vif *vif) 2248 struct ieee80211_vif *vif)
2139{ 2249{
2140 struct wl1271 *wl = hw->priv; 2250 struct wl1271 *wl = hw->priv;
2251 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
2252 struct wl12xx_vif *iter;
2141 2253
2142 mutex_lock(&wl->mutex); 2254 mutex_lock(&wl->mutex);
2255
2256 if (wl->state == WL1271_STATE_OFF ||
2257 !test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))
2258 goto out;
2259
2143 /* 2260 /*
2144 * wl->vif can be null here if someone shuts down the interface 2261 * wl->vif can be null here if someone shuts down the interface
2145 * just when hardware recovery has been started. 2262 * just when hardware recovery has been started.
2146 */ 2263 */
2147 if (wl->vif) { 2264 wl12xx_for_each_wlvif(wl, iter) {
2148 WARN_ON(wl->vif != vif); 2265 if (iter != wlvif)
2149 __wl1271_op_remove_interface(wl, true); 2266 continue;
2150 }
2151 2267
2268 __wl1271_op_remove_interface(wl, vif, true);
2269 break;
2270 }
2271 WARN_ON(iter != wlvif);
2272out:
2152 mutex_unlock(&wl->mutex); 2273 mutex_unlock(&wl->mutex);
2153 cancel_work_sync(&wl->recovery_work); 2274 cancel_work_sync(&wl->recovery_work);
2154} 2275}
2155 2276
2156static int wl1271_join(struct wl1271 *wl, bool set_assoc) 2277static int wl1271_join(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2278 bool set_assoc)
2157{ 2279{
2158 int ret; 2280 int ret;
2159 bool is_ibss = (wl->bss_type == BSS_TYPE_IBSS); 2281 bool is_ibss = (wlvif->bss_type == BSS_TYPE_IBSS);
2160 2282
2161 /* 2283 /*
2162 * One of the side effects of the JOIN command is that is clears 2284 * One of the side effects of the JOIN command is that is clears
@@ -2167,20 +2289,20 @@ static int wl1271_join(struct wl1271 *wl, bool set_assoc)
2167 * Keep the below message for now, unless it starts bothering 2289 * Keep the below message for now, unless it starts bothering
2168 * users who really like to roam a lot :) 2290 * users who really like to roam a lot :)
2169 */ 2291 */
2170 if (test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) 2292 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
2171 wl1271_info("JOIN while associated."); 2293 wl1271_info("JOIN while associated.");
2172 2294
2173 if (set_assoc) 2295 if (set_assoc)
2174 set_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags); 2296 set_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags);
2175 2297
2176 if (is_ibss) 2298 if (is_ibss)
2177 ret = wl12xx_cmd_role_start_ibss(wl); 2299 ret = wl12xx_cmd_role_start_ibss(wl, wlvif);
2178 else 2300 else
2179 ret = wl12xx_cmd_role_start_sta(wl); 2301 ret = wl12xx_cmd_role_start_sta(wl, wlvif);
2180 if (ret < 0) 2302 if (ret < 0)
2181 goto out; 2303 goto out;
2182 2304
2183 if (!test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) 2305 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
2184 goto out; 2306 goto out;
2185 2307
2186 /* 2308 /*
@@ -2189,19 +2311,20 @@ static int wl1271_join(struct wl1271 *wl, bool set_assoc)
2189 * the join. The acx_aid starts the keep-alive process, and the order 2311 * the join. The acx_aid starts the keep-alive process, and the order
2190 * of the commands below is relevant. 2312 * of the commands below is relevant.
2191 */ 2313 */
2192 ret = wl1271_acx_keep_alive_mode(wl, true); 2314 ret = wl1271_acx_keep_alive_mode(wl, wlvif, true);
2193 if (ret < 0) 2315 if (ret < 0)
2194 goto out; 2316 goto out;
2195 2317
2196 ret = wl1271_acx_aid(wl, wl->aid); 2318 ret = wl1271_acx_aid(wl, wlvif, wlvif->aid);
2197 if (ret < 0) 2319 if (ret < 0)
2198 goto out; 2320 goto out;
2199 2321
2200 ret = wl1271_cmd_build_klv_null_data(wl); 2322 ret = wl12xx_cmd_build_klv_null_data(wl, wlvif);
2201 if (ret < 0) 2323 if (ret < 0)
2202 goto out; 2324 goto out;
2203 2325
2204 ret = wl1271_acx_keep_alive_config(wl, CMD_TEMPL_KLV_IDX_NULL_DATA, 2326 ret = wl1271_acx_keep_alive_config(wl, wlvif,
2327 CMD_TEMPL_KLV_IDX_NULL_DATA,
2205 ACX_KEEP_ALIVE_TPL_VALID); 2328 ACX_KEEP_ALIVE_TPL_VALID);
2206 if (ret < 0) 2329 if (ret < 0)
2207 goto out; 2330 goto out;
@@ -2210,34 +2333,34 @@ out:
2210 return ret; 2333 return ret;
2211} 2334}
2212 2335
2213static int wl1271_unjoin(struct wl1271 *wl) 2336static int wl1271_unjoin(struct wl1271 *wl, struct wl12xx_vif *wlvif)
2214{ 2337{
2215 int ret; 2338 int ret;
2216 2339
2217 if (test_and_clear_bit(WL1271_FLAG_CS_PROGRESS, &wl->flags)) { 2340 if (test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS, &wlvif->flags)) {
2341 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
2342
2218 wl12xx_cmd_stop_channel_switch(wl); 2343 wl12xx_cmd_stop_channel_switch(wl);
2219 ieee80211_chswitch_done(wl->vif, false); 2344 ieee80211_chswitch_done(vif, false);
2220 } 2345 }
2221 2346
2222 /* to stop listening to a channel, we disconnect */ 2347 /* to stop listening to a channel, we disconnect */
2223 ret = wl12xx_cmd_role_stop_sta(wl); 2348 ret = wl12xx_cmd_role_stop_sta(wl, wlvif);
2224 if (ret < 0) 2349 if (ret < 0)
2225 goto out; 2350 goto out;
2226 2351
2227 memset(wl->bssid, 0, ETH_ALEN);
2228
2229 /* reset TX security counters on a clean disconnect */ 2352 /* reset TX security counters on a clean disconnect */
2230 wl->tx_security_last_seq_lsb = 0; 2353 wlvif->tx_security_last_seq_lsb = 0;
2231 wl->tx_security_seq = 0; 2354 wlvif->tx_security_seq = 0;
2232 2355
2233out: 2356out:
2234 return ret; 2357 return ret;
2235} 2358}
2236 2359
2237static void wl1271_set_band_rate(struct wl1271 *wl) 2360static void wl1271_set_band_rate(struct wl1271 *wl, struct wl12xx_vif *wlvif)
2238{ 2361{
2239 wl->basic_rate_set = wl->bitrate_masks[wl->band]; 2362 wlvif->basic_rate_set = wlvif->bitrate_masks[wlvif->band];
2240 wl->rate_set = wl->basic_rate_set; 2363 wlvif->rate_set = wlvif->basic_rate_set;
2241} 2364}
2242 2365
2243static bool wl12xx_is_roc(struct wl1271 *wl) 2366static bool wl12xx_is_roc(struct wl1271 *wl)
@@ -2251,27 +2374,25 @@ static bool wl12xx_is_roc(struct wl1271 *wl)
2251 return true; 2374 return true;
2252} 2375}
2253 2376
2254static int wl1271_sta_handle_idle(struct wl1271 *wl, bool idle) 2377static int wl1271_sta_handle_idle(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2378 bool idle)
2255{ 2379{
2256 int ret; 2380 int ret;
2257 2381
2258 if (idle) { 2382 if (idle) {
2259 /* no need to croc if we weren't busy (e.g. during boot) */ 2383 /* no need to croc if we weren't busy (e.g. during boot) */
2260 if (wl12xx_is_roc(wl)) { 2384 if (wl12xx_is_roc(wl)) {
2261 ret = wl12xx_croc(wl, wl->dev_role_id); 2385 ret = wl12xx_stop_dev(wl, wlvif);
2262 if (ret < 0)
2263 goto out;
2264
2265 ret = wl12xx_cmd_role_stop_dev(wl);
2266 if (ret < 0) 2386 if (ret < 0)
2267 goto out; 2387 goto out;
2268 } 2388 }
2269 wl->rate_set = wl1271_tx_min_rate_get(wl, wl->basic_rate_set); 2389 wlvif->rate_set =
2270 ret = wl1271_acx_sta_rate_policies(wl); 2390 wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
2391 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
2271 if (ret < 0) 2392 if (ret < 0)
2272 goto out; 2393 goto out;
2273 ret = wl1271_acx_keep_alive_config( 2394 ret = wl1271_acx_keep_alive_config(
2274 wl, CMD_TEMPL_KLV_IDX_NULL_DATA, 2395 wl, wlvif, CMD_TEMPL_KLV_IDX_NULL_DATA,
2275 ACX_KEEP_ALIVE_TPL_INVALID); 2396 ACX_KEEP_ALIVE_TPL_INVALID);
2276 if (ret < 0) 2397 if (ret < 0)
2277 goto out; 2398 goto out;
@@ -2283,11 +2404,7 @@ static int wl1271_sta_handle_idle(struct wl1271 *wl, bool idle)
2283 ieee80211_sched_scan_stopped(wl->hw); 2404 ieee80211_sched_scan_stopped(wl->hw);
2284 } 2405 }
2285 2406
2286 ret = wl12xx_cmd_role_start_dev(wl); 2407 ret = wl12xx_start_dev(wl, wlvif);
2287 if (ret < 0)
2288 goto out;
2289
2290 ret = wl12xx_roc(wl, wl->dev_role_id);
2291 if (ret < 0) 2408 if (ret < 0)
2292 goto out; 2409 goto out;
2293 clear_bit(WL1271_FLAG_IDLE, &wl->flags); 2410 clear_bit(WL1271_FLAG_IDLE, &wl->flags);
@@ -2297,61 +2414,22 @@ out:
2297 return ret; 2414 return ret;
2298} 2415}
2299 2416
2300static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed) 2417static int wl12xx_config_vif(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2418 struct ieee80211_conf *conf, u32 changed)
2301{ 2419{
2302 struct wl1271 *wl = hw->priv; 2420 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
2303 struct ieee80211_conf *conf = &hw->conf; 2421 int channel, ret;
2304 int channel, ret = 0;
2305 bool is_ap;
2306 2422
2307 channel = ieee80211_frequency_to_channel(conf->channel->center_freq); 2423 channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
2308 2424
2309 wl1271_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d %s"
2310 " changed 0x%x",
2311 channel,
2312 conf->flags & IEEE80211_CONF_PS ? "on" : "off",
2313 conf->power_level,
2314 conf->flags & IEEE80211_CONF_IDLE ? "idle" : "in use",
2315 changed);
2316
2317 /*
2318 * mac80211 will go to idle nearly immediately after transmitting some
2319 * frames, such as the deauth. To make sure those frames reach the air,
2320 * wait here until the TX queue is fully flushed.
2321 */
2322 if ((changed & IEEE80211_CONF_CHANGE_IDLE) &&
2323 (conf->flags & IEEE80211_CONF_IDLE))
2324 wl1271_tx_flush(wl);
2325
2326 mutex_lock(&wl->mutex);
2327
2328 if (unlikely(wl->state == WL1271_STATE_OFF)) {
2329 /* we support configuring the channel and band while off */
2330 if ((changed & IEEE80211_CONF_CHANGE_CHANNEL)) {
2331 wl->band = conf->channel->band;
2332 wl->channel = channel;
2333 }
2334
2335 if ((changed & IEEE80211_CONF_CHANGE_POWER))
2336 wl->power_level = conf->power_level;
2337
2338 goto out;
2339 }
2340
2341 is_ap = (wl->bss_type == BSS_TYPE_AP_BSS);
2342
2343 ret = wl1271_ps_elp_wakeup(wl);
2344 if (ret < 0)
2345 goto out;
2346
2347 /* if the channel changes while joined, join again */ 2425 /* if the channel changes while joined, join again */
2348 if (changed & IEEE80211_CONF_CHANGE_CHANNEL && 2426 if (changed & IEEE80211_CONF_CHANGE_CHANNEL &&
2349 ((wl->band != conf->channel->band) || 2427 ((wlvif->band != conf->channel->band) ||
2350 (wl->channel != channel))) { 2428 (wlvif->channel != channel))) {
2351 /* send all pending packets */ 2429 /* send all pending packets */
2352 wl1271_tx_work_locked(wl); 2430 wl1271_tx_work_locked(wl);
2353 wl->band = conf->channel->band; 2431 wlvif->band = conf->channel->band;
2354 wl->channel = channel; 2432 wlvif->channel = channel;
2355 2433
2356 if (!is_ap) { 2434 if (!is_ap) {
2357 /* 2435 /*
@@ -2360,24 +2438,27 @@ static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed)
2360 * possible rate for the band as a fixed rate for 2438 * possible rate for the band as a fixed rate for
2361 * association frames and other control messages. 2439 * association frames and other control messages.
2362 */ 2440 */
2363 if (!test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) 2441 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
2364 wl1271_set_band_rate(wl); 2442 wl1271_set_band_rate(wl, wlvif);
2365 2443
2366 wl->basic_rate = 2444 wlvif->basic_rate =
2367 wl1271_tx_min_rate_get(wl, wl->basic_rate_set); 2445 wl1271_tx_min_rate_get(wl,
2368 ret = wl1271_acx_sta_rate_policies(wl); 2446 wlvif->basic_rate_set);
2447 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
2369 if (ret < 0) 2448 if (ret < 0)
2370 wl1271_warning("rate policy for channel " 2449 wl1271_warning("rate policy for channel "
2371 "failed %d", ret); 2450 "failed %d", ret);
2372 2451
2373 if (test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) { 2452 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED,
2453 &wlvif->flags)) {
2374 if (wl12xx_is_roc(wl)) { 2454 if (wl12xx_is_roc(wl)) {
2375 /* roaming */ 2455 /* roaming */
2376 ret = wl12xx_croc(wl, wl->dev_role_id); 2456 ret = wl12xx_croc(wl,
2457 wlvif->dev_role_id);
2377 if (ret < 0) 2458 if (ret < 0)
2378 goto out_sleep; 2459 return ret;
2379 } 2460 }
2380 ret = wl1271_join(wl, false); 2461 ret = wl1271_join(wl, wlvif, false);
2381 if (ret < 0) 2462 if (ret < 0)
2382 wl1271_warning("cmd join on channel " 2463 wl1271_warning("cmd join on channel "
2383 "failed %d", ret); 2464 "failed %d", ret);
@@ -2389,64 +2470,112 @@ static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed)
2389 */ 2470 */
2390 if (wl12xx_is_roc(wl) && 2471 if (wl12xx_is_roc(wl) &&
2391 !(conf->flags & IEEE80211_CONF_IDLE)) { 2472 !(conf->flags & IEEE80211_CONF_IDLE)) {
2392 ret = wl12xx_croc(wl, wl->dev_role_id); 2473 ret = wl12xx_stop_dev(wl, wlvif);
2393 if (ret < 0) 2474 if (ret < 0)
2394 goto out_sleep; 2475 return ret;
2395 2476
2396 ret = wl12xx_roc(wl, wl->dev_role_id); 2477 ret = wl12xx_start_dev(wl, wlvif);
2397 if (ret < 0) 2478 if (ret < 0)
2398 wl1271_warning("roc failed %d", 2479 return ret;
2399 ret);
2400 } 2480 }
2401 } 2481 }
2402 } 2482 }
2403 } 2483 }
2404 2484
2405 if (changed & IEEE80211_CONF_CHANGE_IDLE && !is_ap) {
2406 ret = wl1271_sta_handle_idle(wl,
2407 conf->flags & IEEE80211_CONF_IDLE);
2408 if (ret < 0)
2409 wl1271_warning("idle mode change failed %d", ret);
2410 }
2411
2412 /* 2485 /*
2413 * if mac80211 changes the PSM mode, make sure the mode is not 2486 * if mac80211 changes the PSM mode, make sure the mode is not
2414 * incorrectly changed after the pspoll failure active window. 2487 * incorrectly changed after the pspoll failure active window.
2415 */ 2488 */
2416 if (changed & IEEE80211_CONF_CHANGE_PS) 2489 if (changed & IEEE80211_CONF_CHANGE_PS)
2417 clear_bit(WL1271_FLAG_PSPOLL_FAILURE, &wl->flags); 2490 clear_bit(WLVIF_FLAG_PSPOLL_FAILURE, &wlvif->flags);
2418 2491
2419 if (conf->flags & IEEE80211_CONF_PS && 2492 if (conf->flags & IEEE80211_CONF_PS &&
2420 !test_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags)) { 2493 !test_bit(WLVIF_FLAG_PSM_REQUESTED, &wlvif->flags)) {
2421 set_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags); 2494 set_bit(WLVIF_FLAG_PSM_REQUESTED, &wlvif->flags);
2422 2495
2423 /* 2496 /*
2424 * We enter PSM only if we're already associated. 2497 * We enter PSM only if we're already associated.
2425 * If we're not, we'll enter it when joining an SSID, 2498 * If we're not, we'll enter it when joining an SSID,
2426 * through the bss_info_changed() hook. 2499 * through the bss_info_changed() hook.
2427 */ 2500 */
2428 if (test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) { 2501 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) {
2429 wl1271_debug(DEBUG_PSM, "psm enabled"); 2502 wl1271_debug(DEBUG_PSM, "psm enabled");
2430 ret = wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE, 2503 ret = wl1271_ps_set_mode(wl, wlvif,
2431 wl->basic_rate, true); 2504 STATION_POWER_SAVE_MODE,
2505 wlvif->basic_rate, true);
2432 } 2506 }
2433 } else if (!(conf->flags & IEEE80211_CONF_PS) && 2507 } else if (!(conf->flags & IEEE80211_CONF_PS) &&
2434 test_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags)) { 2508 test_bit(WLVIF_FLAG_PSM_REQUESTED, &wlvif->flags)) {
2435 wl1271_debug(DEBUG_PSM, "psm disabled"); 2509 wl1271_debug(DEBUG_PSM, "psm disabled");
2436 2510
2437 clear_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags); 2511 clear_bit(WLVIF_FLAG_PSM_REQUESTED, &wlvif->flags);
2438 2512
2439 if (test_bit(WL1271_FLAG_PSM, &wl->flags)) 2513 if (test_bit(WLVIF_FLAG_PSM, &wlvif->flags))
2440 ret = wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE, 2514 ret = wl1271_ps_set_mode(wl, wlvif,
2441 wl->basic_rate, true); 2515 STATION_ACTIVE_MODE,
2516 wlvif->basic_rate, true);
2442 } 2517 }
2443 2518
2444 if (conf->power_level != wl->power_level) { 2519 if (conf->power_level != wlvif->power_level) {
2445 ret = wl1271_acx_tx_power(wl, conf->power_level); 2520 ret = wl1271_acx_tx_power(wl, wlvif, conf->power_level);
2446 if (ret < 0) 2521 if (ret < 0)
2447 goto out_sleep; 2522 return ret;
2523
2524 wlvif->power_level = conf->power_level;
2525 }
2526
2527 return 0;
2528}
2529
2530static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed)
2531{
2532 struct wl1271 *wl = hw->priv;
2533 struct wl12xx_vif *wlvif;
2534 struct ieee80211_conf *conf = &hw->conf;
2535 int channel, ret = 0;
2536
2537 channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
2538
2539 wl1271_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d %s"
2540 " changed 0x%x",
2541 channel,
2542 conf->flags & IEEE80211_CONF_PS ? "on" : "off",
2543 conf->power_level,
2544 conf->flags & IEEE80211_CONF_IDLE ? "idle" : "in use",
2545 changed);
2546
2547 /*
2548 * mac80211 will go to idle nearly immediately after transmitting some
2549 * frames, such as the deauth. To make sure those frames reach the air,
2550 * wait here until the TX queue is fully flushed.
2551 */
2552 if ((changed & IEEE80211_CONF_CHANGE_IDLE) &&
2553 (conf->flags & IEEE80211_CONF_IDLE))
2554 wl1271_tx_flush(wl);
2555
2556 mutex_lock(&wl->mutex);
2448 2557
2558 /* we support configuring the channel and band even while off */
2559 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
2560 wl->band = conf->channel->band;
2561 wl->channel = channel;
2562 }
2563
2564 if (changed & IEEE80211_CONF_CHANGE_POWER)
2449 wl->power_level = conf->power_level; 2565 wl->power_level = conf->power_level;
2566
2567 if (unlikely(wl->state == WL1271_STATE_OFF))
2568 goto out;
2569
2570 ret = wl1271_ps_elp_wakeup(wl);
2571 if (ret < 0)
2572 goto out;
2573
2574 /* configure each interface */
2575 wl12xx_for_each_wlvif(wl, wlvif) {
2576 ret = wl12xx_config_vif(wl, wlvif, conf, changed);
2577 if (ret < 0)
2578 goto out_sleep;
2450 } 2579 }
2451 2580
2452out_sleep: 2581out_sleep:
@@ -2509,6 +2638,8 @@ static void wl1271_op_configure_filter(struct ieee80211_hw *hw,
2509{ 2638{
2510 struct wl1271_filter_params *fp = (void *)(unsigned long)multicast; 2639 struct wl1271_filter_params *fp = (void *)(unsigned long)multicast;
2511 struct wl1271 *wl = hw->priv; 2640 struct wl1271 *wl = hw->priv;
2641 struct wl12xx_vif *wlvif;
2642
2512 int ret; 2643 int ret;
2513 2644
2514 wl1271_debug(DEBUG_MAC80211, "mac80211 configure filter changed %x" 2645 wl1271_debug(DEBUG_MAC80211, "mac80211 configure filter changed %x"
@@ -2526,15 +2657,20 @@ static void wl1271_op_configure_filter(struct ieee80211_hw *hw,
2526 if (ret < 0) 2657 if (ret < 0)
2527 goto out; 2658 goto out;
2528 2659
2529 if (wl->bss_type != BSS_TYPE_AP_BSS) { 2660 wl12xx_for_each_wlvif(wl, wlvif) {
2530 if (*total & FIF_ALLMULTI) 2661 if (wlvif->bss_type != BSS_TYPE_AP_BSS) {
2531 ret = wl1271_acx_group_address_tbl(wl, false, NULL, 0); 2662 if (*total & FIF_ALLMULTI)
2532 else if (fp) 2663 ret = wl1271_acx_group_address_tbl(wl, wlvif,
2533 ret = wl1271_acx_group_address_tbl(wl, fp->enabled, 2664 false,
2534 fp->mc_list, 2665 NULL, 0);
2535 fp->mc_list_length); 2666 else if (fp)
2536 if (ret < 0) 2667 ret = wl1271_acx_group_address_tbl(wl, wlvif,
2537 goto out_sleep; 2668 fp->enabled,
2669 fp->mc_list,
2670 fp->mc_list_length);
2671 if (ret < 0)
2672 goto out_sleep;
2673 }
2538 } 2674 }
2539 2675
2540 /* 2676 /*
@@ -2551,9 +2687,10 @@ out:
2551 kfree(fp); 2687 kfree(fp);
2552} 2688}
2553 2689
2554static int wl1271_record_ap_key(struct wl1271 *wl, u8 id, u8 key_type, 2690static int wl1271_record_ap_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2555 u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32, 2691 u8 id, u8 key_type, u8 key_size,
2556 u16 tx_seq_16) 2692 const u8 *key, u8 hlid, u32 tx_seq_32,
2693 u16 tx_seq_16)
2557{ 2694{
2558 struct wl1271_ap_key *ap_key; 2695 struct wl1271_ap_key *ap_key;
2559 int i; 2696 int i;
@@ -2568,10 +2705,10 @@ static int wl1271_record_ap_key(struct wl1271 *wl, u8 id, u8 key_type,
2568 * an existing key. 2705 * an existing key.
2569 */ 2706 */
2570 for (i = 0; i < MAX_NUM_KEYS; i++) { 2707 for (i = 0; i < MAX_NUM_KEYS; i++) {
2571 if (wl->recorded_ap_keys[i] == NULL) 2708 if (wlvif->ap.recorded_keys[i] == NULL)
2572 break; 2709 break;
2573 2710
2574 if (wl->recorded_ap_keys[i]->id == id) { 2711 if (wlvif->ap.recorded_keys[i]->id == id) {
2575 wl1271_warning("trying to record key replacement"); 2712 wl1271_warning("trying to record key replacement");
2576 return -EINVAL; 2713 return -EINVAL;
2577 } 2714 }
@@ -2592,21 +2729,21 @@ static int wl1271_record_ap_key(struct wl1271 *wl, u8 id, u8 key_type,
2592 ap_key->tx_seq_32 = tx_seq_32; 2729 ap_key->tx_seq_32 = tx_seq_32;
2593 ap_key->tx_seq_16 = tx_seq_16; 2730 ap_key->tx_seq_16 = tx_seq_16;
2594 2731
2595 wl->recorded_ap_keys[i] = ap_key; 2732 wlvif->ap.recorded_keys[i] = ap_key;
2596 return 0; 2733 return 0;
2597} 2734}
2598 2735
2599static void wl1271_free_ap_keys(struct wl1271 *wl) 2736static void wl1271_free_ap_keys(struct wl1271 *wl, struct wl12xx_vif *wlvif)
2600{ 2737{
2601 int i; 2738 int i;
2602 2739
2603 for (i = 0; i < MAX_NUM_KEYS; i++) { 2740 for (i = 0; i < MAX_NUM_KEYS; i++) {
2604 kfree(wl->recorded_ap_keys[i]); 2741 kfree(wlvif->ap.recorded_keys[i]);
2605 wl->recorded_ap_keys[i] = NULL; 2742 wlvif->ap.recorded_keys[i] = NULL;
2606 } 2743 }
2607} 2744}
2608 2745
2609static int wl1271_ap_init_hwenc(struct wl1271 *wl) 2746static int wl1271_ap_init_hwenc(struct wl1271 *wl, struct wl12xx_vif *wlvif)
2610{ 2747{
2611 int i, ret = 0; 2748 int i, ret = 0;
2612 struct wl1271_ap_key *key; 2749 struct wl1271_ap_key *key;
@@ -2614,15 +2751,15 @@ static int wl1271_ap_init_hwenc(struct wl1271 *wl)
2614 2751
2615 for (i = 0; i < MAX_NUM_KEYS; i++) { 2752 for (i = 0; i < MAX_NUM_KEYS; i++) {
2616 u8 hlid; 2753 u8 hlid;
2617 if (wl->recorded_ap_keys[i] == NULL) 2754 if (wlvif->ap.recorded_keys[i] == NULL)
2618 break; 2755 break;
2619 2756
2620 key = wl->recorded_ap_keys[i]; 2757 key = wlvif->ap.recorded_keys[i];
2621 hlid = key->hlid; 2758 hlid = key->hlid;
2622 if (hlid == WL12XX_INVALID_LINK_ID) 2759 if (hlid == WL12XX_INVALID_LINK_ID)
2623 hlid = wl->ap_bcast_hlid; 2760 hlid = wlvif->ap.bcast_hlid;
2624 2761
2625 ret = wl1271_cmd_set_ap_key(wl, KEY_ADD_OR_REPLACE, 2762 ret = wl1271_cmd_set_ap_key(wl, wlvif, KEY_ADD_OR_REPLACE,
2626 key->id, key->key_type, 2763 key->id, key->key_type,
2627 key->key_size, key->key, 2764 key->key_size, key->key,
2628 hlid, key->tx_seq_32, 2765 hlid, key->tx_seq_32,
@@ -2635,23 +2772,24 @@ static int wl1271_ap_init_hwenc(struct wl1271 *wl)
2635 } 2772 }
2636 2773
2637 if (wep_key_added) { 2774 if (wep_key_added) {
2638 ret = wl12xx_cmd_set_default_wep_key(wl, wl->default_key, 2775 ret = wl12xx_cmd_set_default_wep_key(wl, wlvif->default_key,
2639 wl->ap_bcast_hlid); 2776 wlvif->ap.bcast_hlid);
2640 if (ret < 0) 2777 if (ret < 0)
2641 goto out; 2778 goto out;
2642 } 2779 }
2643 2780
2644out: 2781out:
2645 wl1271_free_ap_keys(wl); 2782 wl1271_free_ap_keys(wl, wlvif);
2646 return ret; 2783 return ret;
2647} 2784}
2648 2785
2649static int wl1271_set_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type, 2786static int wl1271_set_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2787 u16 action, u8 id, u8 key_type,
2650 u8 key_size, const u8 *key, u32 tx_seq_32, 2788 u8 key_size, const u8 *key, u32 tx_seq_32,
2651 u16 tx_seq_16, struct ieee80211_sta *sta) 2789 u16 tx_seq_16, struct ieee80211_sta *sta)
2652{ 2790{
2653 int ret; 2791 int ret;
2654 bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS); 2792 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
2655 2793
2656 if (is_ap) { 2794 if (is_ap) {
2657 struct wl1271_station *wl_sta; 2795 struct wl1271_station *wl_sta;
@@ -2661,10 +2799,10 @@ static int wl1271_set_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
2661 wl_sta = (struct wl1271_station *)sta->drv_priv; 2799 wl_sta = (struct wl1271_station *)sta->drv_priv;
2662 hlid = wl_sta->hlid; 2800 hlid = wl_sta->hlid;
2663 } else { 2801 } else {
2664 hlid = wl->ap_bcast_hlid; 2802 hlid = wlvif->ap.bcast_hlid;
2665 } 2803 }
2666 2804
2667 if (!test_bit(WL1271_FLAG_AP_STARTED, &wl->flags)) { 2805 if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
2668 /* 2806 /*
2669 * We do not support removing keys after AP shutdown. 2807 * We do not support removing keys after AP shutdown.
2670 * Pretend we do to make mac80211 happy. 2808 * Pretend we do to make mac80211 happy.
@@ -2672,12 +2810,12 @@ static int wl1271_set_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
2672 if (action != KEY_ADD_OR_REPLACE) 2810 if (action != KEY_ADD_OR_REPLACE)
2673 return 0; 2811 return 0;
2674 2812
2675 ret = wl1271_record_ap_key(wl, id, 2813 ret = wl1271_record_ap_key(wl, wlvif, id,
2676 key_type, key_size, 2814 key_type, key_size,
2677 key, hlid, tx_seq_32, 2815 key, hlid, tx_seq_32,
2678 tx_seq_16); 2816 tx_seq_16);
2679 } else { 2817 } else {
2680 ret = wl1271_cmd_set_ap_key(wl, action, 2818 ret = wl1271_cmd_set_ap_key(wl, wlvif, action,
2681 id, key_type, key_size, 2819 id, key_type, key_size,
2682 key, hlid, tx_seq_32, 2820 key, hlid, tx_seq_32,
2683 tx_seq_16); 2821 tx_seq_16);
@@ -2718,10 +2856,10 @@ static int wl1271_set_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
2718 2856
2719 /* don't remove key if hlid was already deleted */ 2857 /* don't remove key if hlid was already deleted */
2720 if (action == KEY_REMOVE && 2858 if (action == KEY_REMOVE &&
2721 wl->sta_hlid == WL12XX_INVALID_LINK_ID) 2859 wlvif->sta.hlid == WL12XX_INVALID_LINK_ID)
2722 return 0; 2860 return 0;
2723 2861
2724 ret = wl1271_cmd_set_sta_key(wl, action, 2862 ret = wl1271_cmd_set_sta_key(wl, wlvif, action,
2725 id, key_type, key_size, 2863 id, key_type, key_size,
2726 key, addr, tx_seq_32, 2864 key, addr, tx_seq_32,
2727 tx_seq_16); 2865 tx_seq_16);
@@ -2731,8 +2869,8 @@ static int wl1271_set_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
2731 /* the default WEP key needs to be configured at least once */ 2869 /* the default WEP key needs to be configured at least once */
2732 if (key_type == KEY_WEP) { 2870 if (key_type == KEY_WEP) {
2733 ret = wl12xx_cmd_set_default_wep_key(wl, 2871 ret = wl12xx_cmd_set_default_wep_key(wl,
2734 wl->default_key, 2872 wlvif->default_key,
2735 wl->sta_hlid); 2873 wlvif->sta.hlid);
2736 if (ret < 0) 2874 if (ret < 0)
2737 return ret; 2875 return ret;
2738 } 2876 }
@@ -2747,6 +2885,7 @@ static int wl1271_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2747 struct ieee80211_key_conf *key_conf) 2885 struct ieee80211_key_conf *key_conf)
2748{ 2886{
2749 struct wl1271 *wl = hw->priv; 2887 struct wl1271 *wl = hw->priv;
2888 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
2750 int ret; 2889 int ret;
2751 u32 tx_seq_32 = 0; 2890 u32 tx_seq_32 = 0;
2752 u16 tx_seq_16 = 0; 2891 u16 tx_seq_16 = 0;
@@ -2782,20 +2921,20 @@ static int wl1271_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2782 key_type = KEY_TKIP; 2921 key_type = KEY_TKIP;
2783 2922
2784 key_conf->hw_key_idx = key_conf->keyidx; 2923 key_conf->hw_key_idx = key_conf->keyidx;
2785 tx_seq_32 = WL1271_TX_SECURITY_HI32(wl->tx_security_seq); 2924 tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq);
2786 tx_seq_16 = WL1271_TX_SECURITY_LO16(wl->tx_security_seq); 2925 tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq);
2787 break; 2926 break;
2788 case WLAN_CIPHER_SUITE_CCMP: 2927 case WLAN_CIPHER_SUITE_CCMP:
2789 key_type = KEY_AES; 2928 key_type = KEY_AES;
2790 2929
2791 key_conf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; 2930 key_conf->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
2792 tx_seq_32 = WL1271_TX_SECURITY_HI32(wl->tx_security_seq); 2931 tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq);
2793 tx_seq_16 = WL1271_TX_SECURITY_LO16(wl->tx_security_seq); 2932 tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq);
2794 break; 2933 break;
2795 case WL1271_CIPHER_SUITE_GEM: 2934 case WL1271_CIPHER_SUITE_GEM:
2796 key_type = KEY_GEM; 2935 key_type = KEY_GEM;
2797 tx_seq_32 = WL1271_TX_SECURITY_HI32(wl->tx_security_seq); 2936 tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq);
2798 tx_seq_16 = WL1271_TX_SECURITY_LO16(wl->tx_security_seq); 2937 tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq);
2799 break; 2938 break;
2800 default: 2939 default:
2801 wl1271_error("Unknown key algo 0x%x", key_conf->cipher); 2940 wl1271_error("Unknown key algo 0x%x", key_conf->cipher);
@@ -2806,7 +2945,7 @@ static int wl1271_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2806 2945
2807 switch (cmd) { 2946 switch (cmd) {
2808 case SET_KEY: 2947 case SET_KEY:
2809 ret = wl1271_set_key(wl, KEY_ADD_OR_REPLACE, 2948 ret = wl1271_set_key(wl, wlvif, KEY_ADD_OR_REPLACE,
2810 key_conf->keyidx, key_type, 2949 key_conf->keyidx, key_type,
2811 key_conf->keylen, key_conf->key, 2950 key_conf->keylen, key_conf->key,
2812 tx_seq_32, tx_seq_16, sta); 2951 tx_seq_32, tx_seq_16, sta);
@@ -2817,7 +2956,7 @@ static int wl1271_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2817 break; 2956 break;
2818 2957
2819 case DISABLE_KEY: 2958 case DISABLE_KEY:
2820 ret = wl1271_set_key(wl, KEY_REMOVE, 2959 ret = wl1271_set_key(wl, wlvif, KEY_REMOVE,
2821 key_conf->keyidx, key_type, 2960 key_conf->keyidx, key_type,
2822 key_conf->keylen, key_conf->key, 2961 key_conf->keylen, key_conf->key,
2823 0, 0, sta); 2962 0, 0, sta);
@@ -2847,6 +2986,8 @@ static int wl1271_op_hw_scan(struct ieee80211_hw *hw,
2847 struct cfg80211_scan_request *req) 2986 struct cfg80211_scan_request *req)
2848{ 2987{
2849 struct wl1271 *wl = hw->priv; 2988 struct wl1271 *wl = hw->priv;
2989 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
2990
2850 int ret; 2991 int ret;
2851 u8 *ssid = NULL; 2992 u8 *ssid = NULL;
2852 size_t len = 0; 2993 size_t len = 0;
@@ -2876,16 +3017,15 @@ static int wl1271_op_hw_scan(struct ieee80211_hw *hw,
2876 3017
2877 /* cancel ROC before scanning */ 3018 /* cancel ROC before scanning */
2878 if (wl12xx_is_roc(wl)) { 3019 if (wl12xx_is_roc(wl)) {
2879 if (test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) { 3020 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) {
2880 /* don't allow scanning right now */ 3021 /* don't allow scanning right now */
2881 ret = -EBUSY; 3022 ret = -EBUSY;
2882 goto out_sleep; 3023 goto out_sleep;
2883 } 3024 }
2884 wl12xx_croc(wl, wl->dev_role_id); 3025 wl12xx_stop_dev(wl, wlvif);
2885 wl12xx_cmd_role_stop_dev(wl);
2886 } 3026 }
2887 3027
2888 ret = wl1271_scan(hw->priv, ssid, len, req); 3028 ret = wl1271_scan(hw->priv, vif, ssid, len, req);
2889out_sleep: 3029out_sleep:
2890 wl1271_ps_elp_sleep(wl); 3030 wl1271_ps_elp_sleep(wl);
2891out: 3031out:
@@ -2921,6 +3061,7 @@ static void wl1271_op_cancel_hw_scan(struct ieee80211_hw *hw,
2921 } 3061 }
2922 wl->scan.state = WL1271_SCAN_STATE_IDLE; 3062 wl->scan.state = WL1271_SCAN_STATE_IDLE;
2923 memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch)); 3063 memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
3064 wl->scan_vif = NULL;
2924 wl->scan.req = NULL; 3065 wl->scan.req = NULL;
2925 ieee80211_scan_completed(wl->hw, true); 3066 ieee80211_scan_completed(wl->hw, true);
2926 3067
@@ -2938,6 +3079,7 @@ static int wl1271_op_sched_scan_start(struct ieee80211_hw *hw,
2938 struct ieee80211_sched_scan_ies *ies) 3079 struct ieee80211_sched_scan_ies *ies)
2939{ 3080{
2940 struct wl1271 *wl = hw->priv; 3081 struct wl1271 *wl = hw->priv;
3082 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
2941 int ret; 3083 int ret;
2942 3084
2943 wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_start"); 3085 wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_start");
@@ -2948,11 +3090,11 @@ static int wl1271_op_sched_scan_start(struct ieee80211_hw *hw,
2948 if (ret < 0) 3090 if (ret < 0)
2949 goto out; 3091 goto out;
2950 3092
2951 ret = wl1271_scan_sched_scan_config(wl, req, ies); 3093 ret = wl1271_scan_sched_scan_config(wl, wlvif, req, ies);
2952 if (ret < 0) 3094 if (ret < 0)
2953 goto out_sleep; 3095 goto out_sleep;
2954 3096
2955 ret = wl1271_scan_sched_scan_start(wl); 3097 ret = wl1271_scan_sched_scan_start(wl, wlvif);
2956 if (ret < 0) 3098 if (ret < 0)
2957 goto out_sleep; 3099 goto out_sleep;
2958 3100
@@ -3017,6 +3159,7 @@ out:
3017static int wl1271_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value) 3159static int wl1271_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3018{ 3160{
3019 struct wl1271 *wl = hw->priv; 3161 struct wl1271 *wl = hw->priv;
3162 struct wl12xx_vif *wlvif;
3020 int ret = 0; 3163 int ret = 0;
3021 3164
3022 mutex_lock(&wl->mutex); 3165 mutex_lock(&wl->mutex);
@@ -3030,10 +3173,11 @@ static int wl1271_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3030 if (ret < 0) 3173 if (ret < 0)
3031 goto out; 3174 goto out;
3032 3175
3033 ret = wl1271_acx_rts_threshold(wl, value); 3176 wl12xx_for_each_wlvif(wl, wlvif) {
3034 if (ret < 0) 3177 ret = wl1271_acx_rts_threshold(wl, wlvif, value);
3035 wl1271_warning("wl1271_op_set_rts_threshold failed: %d", ret); 3178 if (ret < 0)
3036 3179 wl1271_warning("set rts threshold failed: %d", ret);
3180 }
3037 wl1271_ps_elp_sleep(wl); 3181 wl1271_ps_elp_sleep(wl);
3038 3182
3039out: 3183out:
@@ -3042,9 +3186,10 @@ out:
3042 return ret; 3186 return ret;
3043} 3187}
3044 3188
3045static int wl1271_ssid_set(struct wl1271 *wl, struct sk_buff *skb, 3189static int wl1271_ssid_set(struct ieee80211_vif *vif, struct sk_buff *skb,
3046 int offset) 3190 int offset)
3047{ 3191{
3192 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3048 u8 ssid_len; 3193 u8 ssid_len;
3049 const u8 *ptr = cfg80211_find_ie(WLAN_EID_SSID, skb->data + offset, 3194 const u8 *ptr = cfg80211_find_ie(WLAN_EID_SSID, skb->data + offset,
3050 skb->len - offset); 3195 skb->len - offset);
@@ -3060,8 +3205,8 @@ static int wl1271_ssid_set(struct wl1271 *wl, struct sk_buff *skb,
3060 return -EINVAL; 3205 return -EINVAL;
3061 } 3206 }
3062 3207
3063 wl->ssid_len = ssid_len; 3208 wlvif->ssid_len = ssid_len;
3064 memcpy(wl->ssid, ptr+2, ssid_len); 3209 memcpy(wlvif->ssid, ptr+2, ssid_len);
3065 return 0; 3210 return 0;
3066} 3211}
3067 3212
@@ -3096,18 +3241,40 @@ static void wl12xx_remove_vendor_ie(struct sk_buff *skb,
3096 skb_trim(skb, skb->len - len); 3241 skb_trim(skb, skb->len - len);
3097} 3242}
3098 3243
3099static int wl1271_ap_set_probe_resp_tmpl(struct wl1271 *wl, 3244static int wl1271_ap_set_probe_resp_tmpl(struct wl1271 *wl, u32 rates,
3100 u8 *probe_rsp_data, 3245 struct ieee80211_vif *vif)
3101 size_t probe_rsp_len, 3246{
3102 u32 rates) 3247 struct sk_buff *skb;
3248 int ret;
3249
3250 skb = ieee80211_proberesp_get(wl->hw, vif);
3251 if (!skb)
3252 return -EOPNOTSUPP;
3253
3254 ret = wl1271_cmd_template_set(wl,
3255 CMD_TEMPL_AP_PROBE_RESPONSE,
3256 skb->data,
3257 skb->len, 0,
3258 rates);
3259
3260 dev_kfree_skb(skb);
3261 return ret;
3262}
3263
3264static int wl1271_ap_set_probe_resp_tmpl_legacy(struct wl1271 *wl,
3265 struct ieee80211_vif *vif,
3266 u8 *probe_rsp_data,
3267 size_t probe_rsp_len,
3268 u32 rates)
3103{ 3269{
3104 struct ieee80211_bss_conf *bss_conf = &wl->vif->bss_conf; 3270 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3271 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
3105 u8 probe_rsp_templ[WL1271_CMD_TEMPL_MAX_SIZE]; 3272 u8 probe_rsp_templ[WL1271_CMD_TEMPL_MAX_SIZE];
3106 int ssid_ie_offset, ie_offset, templ_len; 3273 int ssid_ie_offset, ie_offset, templ_len;
3107 const u8 *ptr; 3274 const u8 *ptr;
3108 3275
3109 /* no need to change probe response if the SSID is set correctly */ 3276 /* no need to change probe response if the SSID is set correctly */
3110 if (wl->ssid_len > 0) 3277 if (wlvif->ssid_len > 0)
3111 return wl1271_cmd_template_set(wl, 3278 return wl1271_cmd_template_set(wl,
3112 CMD_TEMPL_AP_PROBE_RESPONSE, 3279 CMD_TEMPL_AP_PROBE_RESPONSE,
3113 probe_rsp_data, 3280 probe_rsp_data,
@@ -3153,16 +3320,18 @@ static int wl1271_ap_set_probe_resp_tmpl(struct wl1271 *wl,
3153} 3320}
3154 3321
3155static int wl1271_bss_erp_info_changed(struct wl1271 *wl, 3322static int wl1271_bss_erp_info_changed(struct wl1271 *wl,
3323 struct ieee80211_vif *vif,
3156 struct ieee80211_bss_conf *bss_conf, 3324 struct ieee80211_bss_conf *bss_conf,
3157 u32 changed) 3325 u32 changed)
3158{ 3326{
3327 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3159 int ret = 0; 3328 int ret = 0;
3160 3329
3161 if (changed & BSS_CHANGED_ERP_SLOT) { 3330 if (changed & BSS_CHANGED_ERP_SLOT) {
3162 if (bss_conf->use_short_slot) 3331 if (bss_conf->use_short_slot)
3163 ret = wl1271_acx_slot(wl, SLOT_TIME_SHORT); 3332 ret = wl1271_acx_slot(wl, wlvif, SLOT_TIME_SHORT);
3164 else 3333 else
3165 ret = wl1271_acx_slot(wl, SLOT_TIME_LONG); 3334 ret = wl1271_acx_slot(wl, wlvif, SLOT_TIME_LONG);
3166 if (ret < 0) { 3335 if (ret < 0) {
3167 wl1271_warning("Set slot time failed %d", ret); 3336 wl1271_warning("Set slot time failed %d", ret);
3168 goto out; 3337 goto out;
@@ -3171,16 +3340,18 @@ static int wl1271_bss_erp_info_changed(struct wl1271 *wl,
3171 3340
3172 if (changed & BSS_CHANGED_ERP_PREAMBLE) { 3341 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
3173 if (bss_conf->use_short_preamble) 3342 if (bss_conf->use_short_preamble)
3174 wl1271_acx_set_preamble(wl, ACX_PREAMBLE_SHORT); 3343 wl1271_acx_set_preamble(wl, wlvif, ACX_PREAMBLE_SHORT);
3175 else 3344 else
3176 wl1271_acx_set_preamble(wl, ACX_PREAMBLE_LONG); 3345 wl1271_acx_set_preamble(wl, wlvif, ACX_PREAMBLE_LONG);
3177 } 3346 }
3178 3347
3179 if (changed & BSS_CHANGED_ERP_CTS_PROT) { 3348 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
3180 if (bss_conf->use_cts_prot) 3349 if (bss_conf->use_cts_prot)
3181 ret = wl1271_acx_cts_protect(wl, CTSPROTECT_ENABLE); 3350 ret = wl1271_acx_cts_protect(wl, wlvif,
3351 CTSPROTECT_ENABLE);
3182 else 3352 else
3183 ret = wl1271_acx_cts_protect(wl, CTSPROTECT_DISABLE); 3353 ret = wl1271_acx_cts_protect(wl, wlvif,
3354 CTSPROTECT_DISABLE);
3184 if (ret < 0) { 3355 if (ret < 0) {
3185 wl1271_warning("Set ctsprotect failed %d", ret); 3356 wl1271_warning("Set ctsprotect failed %d", ret);
3186 goto out; 3357 goto out;
@@ -3196,14 +3367,23 @@ static int wl1271_bss_beacon_info_changed(struct wl1271 *wl,
3196 struct ieee80211_bss_conf *bss_conf, 3367 struct ieee80211_bss_conf *bss_conf,
3197 u32 changed) 3368 u32 changed)
3198{ 3369{
3199 bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS); 3370 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3371 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
3200 int ret = 0; 3372 int ret = 0;
3201 3373
3202 if ((changed & BSS_CHANGED_BEACON_INT)) { 3374 if ((changed & BSS_CHANGED_BEACON_INT)) {
3203 wl1271_debug(DEBUG_MASTER, "beacon interval updated: %d", 3375 wl1271_debug(DEBUG_MASTER, "beacon interval updated: %d",
3204 bss_conf->beacon_int); 3376 bss_conf->beacon_int);
3205 3377
3206 wl->beacon_int = bss_conf->beacon_int; 3378 wlvif->beacon_int = bss_conf->beacon_int;
3379 }
3380
3381 if ((changed & BSS_CHANGED_AP_PROBE_RESP) && is_ap) {
3382 u32 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
3383 if (!wl1271_ap_set_probe_resp_tmpl(wl, rate, vif)) {
3384 wl1271_debug(DEBUG_AP, "probe response updated");
3385 set_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, &wlvif->flags);
3386 }
3207 } 3387 }
3208 3388
3209 if ((changed & BSS_CHANGED_BEACON)) { 3389 if ((changed & BSS_CHANGED_BEACON)) {
@@ -3214,17 +3394,19 @@ static int wl1271_bss_beacon_info_changed(struct wl1271 *wl,
3214 struct sk_buff *beacon = ieee80211_beacon_get(wl->hw, vif); 3394 struct sk_buff *beacon = ieee80211_beacon_get(wl->hw, vif);
3215 u16 tmpl_id; 3395 u16 tmpl_id;
3216 3396
3217 if (!beacon) 3397 if (!beacon) {
3398 ret = -EINVAL;
3218 goto out; 3399 goto out;
3400 }
3219 3401
3220 wl1271_debug(DEBUG_MASTER, "beacon updated"); 3402 wl1271_debug(DEBUG_MASTER, "beacon updated");
3221 3403
3222 ret = wl1271_ssid_set(wl, beacon, ieoffset); 3404 ret = wl1271_ssid_set(vif, beacon, ieoffset);
3223 if (ret < 0) { 3405 if (ret < 0) {
3224 dev_kfree_skb(beacon); 3406 dev_kfree_skb(beacon);
3225 goto out; 3407 goto out;
3226 } 3408 }
3227 min_rate = wl1271_tx_min_rate_get(wl, wl->basic_rate_set); 3409 min_rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
3228 tmpl_id = is_ap ? CMD_TEMPL_AP_BEACON : 3410 tmpl_id = is_ap ? CMD_TEMPL_AP_BEACON :
3229 CMD_TEMPL_BEACON; 3411 CMD_TEMPL_BEACON;
3230 ret = wl1271_cmd_template_set(wl, tmpl_id, 3412 ret = wl1271_cmd_template_set(wl, tmpl_id,
@@ -3236,6 +3418,13 @@ static int wl1271_bss_beacon_info_changed(struct wl1271 *wl,
3236 goto out; 3418 goto out;
3237 } 3419 }
3238 3420
3421 /*
3422 * In case we already have a probe-resp beacon set explicitly
3423 * by usermode, don't use the beacon data.
3424 */
3425 if (test_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, &wlvif->flags))
3426 goto end_bcn;
3427
3239 /* remove TIM ie from probe response */ 3428 /* remove TIM ie from probe response */
3240 wl12xx_remove_ie(beacon, WLAN_EID_TIM, ieoffset); 3429 wl12xx_remove_ie(beacon, WLAN_EID_TIM, ieoffset);
3241 3430
@@ -3254,7 +3443,7 @@ static int wl1271_bss_beacon_info_changed(struct wl1271 *wl,
3254 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 3443 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
3255 IEEE80211_STYPE_PROBE_RESP); 3444 IEEE80211_STYPE_PROBE_RESP);
3256 if (is_ap) 3445 if (is_ap)
3257 ret = wl1271_ap_set_probe_resp_tmpl(wl, 3446 ret = wl1271_ap_set_probe_resp_tmpl_legacy(wl, vif,
3258 beacon->data, 3447 beacon->data,
3259 beacon->len, 3448 beacon->len,
3260 min_rate); 3449 min_rate);
@@ -3264,12 +3453,15 @@ static int wl1271_bss_beacon_info_changed(struct wl1271 *wl,
3264 beacon->data, 3453 beacon->data,
3265 beacon->len, 0, 3454 beacon->len, 0,
3266 min_rate); 3455 min_rate);
3456end_bcn:
3267 dev_kfree_skb(beacon); 3457 dev_kfree_skb(beacon);
3268 if (ret < 0) 3458 if (ret < 0)
3269 goto out; 3459 goto out;
3270 } 3460 }
3271 3461
3272out: 3462out:
3463 if (ret != 0)
3464 wl1271_error("beacon info change failed: %d", ret);
3273 return ret; 3465 return ret;
3274} 3466}
3275 3467
@@ -3279,23 +3471,24 @@ static void wl1271_bss_info_changed_ap(struct wl1271 *wl,
3279 struct ieee80211_bss_conf *bss_conf, 3471 struct ieee80211_bss_conf *bss_conf,
3280 u32 changed) 3472 u32 changed)
3281{ 3473{
3474 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3282 int ret = 0; 3475 int ret = 0;
3283 3476
3284 if ((changed & BSS_CHANGED_BASIC_RATES)) { 3477 if ((changed & BSS_CHANGED_BASIC_RATES)) {
3285 u32 rates = bss_conf->basic_rates; 3478 u32 rates = bss_conf->basic_rates;
3286 3479
3287 wl->basic_rate_set = wl1271_tx_enabled_rates_get(wl, rates, 3480 wlvif->basic_rate_set = wl1271_tx_enabled_rates_get(wl, rates,
3288 wl->band); 3481 wlvif->band);
3289 wl->basic_rate = wl1271_tx_min_rate_get(wl, 3482 wlvif->basic_rate = wl1271_tx_min_rate_get(wl,
3290 wl->basic_rate_set); 3483 wlvif->basic_rate_set);
3291 3484
3292 ret = wl1271_init_ap_rates(wl); 3485 ret = wl1271_init_ap_rates(wl, wlvif);
3293 if (ret < 0) { 3486 if (ret < 0) {
3294 wl1271_error("AP rate policy change failed %d", ret); 3487 wl1271_error("AP rate policy change failed %d", ret);
3295 goto out; 3488 goto out;
3296 } 3489 }
3297 3490
3298 ret = wl1271_ap_init_templates(wl); 3491 ret = wl1271_ap_init_templates(wl, vif);
3299 if (ret < 0) 3492 if (ret < 0)
3300 goto out; 3493 goto out;
3301 } 3494 }
@@ -3306,38 +3499,40 @@ static void wl1271_bss_info_changed_ap(struct wl1271 *wl,
3306 3499
3307 if ((changed & BSS_CHANGED_BEACON_ENABLED)) { 3500 if ((changed & BSS_CHANGED_BEACON_ENABLED)) {
3308 if (bss_conf->enable_beacon) { 3501 if (bss_conf->enable_beacon) {
3309 if (!test_bit(WL1271_FLAG_AP_STARTED, &wl->flags)) { 3502 if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
3310 ret = wl12xx_cmd_role_start_ap(wl); 3503 ret = wl12xx_cmd_role_start_ap(wl, wlvif);
3311 if (ret < 0) 3504 if (ret < 0)
3312 goto out; 3505 goto out;
3313 3506
3314 ret = wl1271_ap_init_hwenc(wl); 3507 ret = wl1271_ap_init_hwenc(wl, wlvif);
3315 if (ret < 0) 3508 if (ret < 0)
3316 goto out; 3509 goto out;
3317 3510
3318 set_bit(WL1271_FLAG_AP_STARTED, &wl->flags); 3511 set_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags);
3319 wl1271_debug(DEBUG_AP, "started AP"); 3512 wl1271_debug(DEBUG_AP, "started AP");
3320 } 3513 }
3321 } else { 3514 } else {
3322 if (test_bit(WL1271_FLAG_AP_STARTED, &wl->flags)) { 3515 if (test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
3323 ret = wl12xx_cmd_role_stop_ap(wl); 3516 ret = wl12xx_cmd_role_stop_ap(wl, wlvif);
3324 if (ret < 0) 3517 if (ret < 0)
3325 goto out; 3518 goto out;
3326 3519
3327 clear_bit(WL1271_FLAG_AP_STARTED, &wl->flags); 3520 clear_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags);
3521 clear_bit(WLVIF_FLAG_AP_PROBE_RESP_SET,
3522 &wlvif->flags);
3328 wl1271_debug(DEBUG_AP, "stopped AP"); 3523 wl1271_debug(DEBUG_AP, "stopped AP");
3329 } 3524 }
3330 } 3525 }
3331 } 3526 }
3332 3527
3333 ret = wl1271_bss_erp_info_changed(wl, bss_conf, changed); 3528 ret = wl1271_bss_erp_info_changed(wl, vif, bss_conf, changed);
3334 if (ret < 0) 3529 if (ret < 0)
3335 goto out; 3530 goto out;
3336 3531
3337 /* Handle HT information change */ 3532 /* Handle HT information change */
3338 if ((changed & BSS_CHANGED_HT) && 3533 if ((changed & BSS_CHANGED_HT) &&
3339 (bss_conf->channel_type != NL80211_CHAN_NO_HT)) { 3534 (bss_conf->channel_type != NL80211_CHAN_NO_HT)) {
3340 ret = wl1271_acx_set_ht_information(wl, 3535 ret = wl1271_acx_set_ht_information(wl, wlvif,
3341 bss_conf->ht_operation_mode); 3536 bss_conf->ht_operation_mode);
3342 if (ret < 0) { 3537 if (ret < 0) {
3343 wl1271_warning("Set ht information failed %d", ret); 3538 wl1271_warning("Set ht information failed %d", ret);
@@ -3355,8 +3550,9 @@ static void wl1271_bss_info_changed_sta(struct wl1271 *wl,
3355 struct ieee80211_bss_conf *bss_conf, 3550 struct ieee80211_bss_conf *bss_conf,
3356 u32 changed) 3551 u32 changed)
3357{ 3552{
3553 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3358 bool do_join = false, set_assoc = false; 3554 bool do_join = false, set_assoc = false;
3359 bool is_ibss = (wl->bss_type == BSS_TYPE_IBSS); 3555 bool is_ibss = (wlvif->bss_type == BSS_TYPE_IBSS);
3360 bool ibss_joined = false; 3556 bool ibss_joined = false;
3361 u32 sta_rate_set = 0; 3557 u32 sta_rate_set = 0;
3362 int ret; 3558 int ret;
@@ -3373,14 +3569,13 @@ static void wl1271_bss_info_changed_sta(struct wl1271 *wl,
3373 3569
3374 if (changed & BSS_CHANGED_IBSS) { 3570 if (changed & BSS_CHANGED_IBSS) {
3375 if (bss_conf->ibss_joined) { 3571 if (bss_conf->ibss_joined) {
3376 set_bit(WL1271_FLAG_IBSS_JOINED, &wl->flags); 3572 set_bit(WLVIF_FLAG_IBSS_JOINED, &wlvif->flags);
3377 ibss_joined = true; 3573 ibss_joined = true;
3378 } else { 3574 } else {
3379 if (test_and_clear_bit(WL1271_FLAG_IBSS_JOINED, 3575 if (test_and_clear_bit(WLVIF_FLAG_IBSS_JOINED,
3380 &wl->flags)) { 3576 &wlvif->flags)) {
3381 wl1271_unjoin(wl); 3577 wl1271_unjoin(wl, wlvif);
3382 wl12xx_cmd_role_start_dev(wl); 3578 wl12xx_start_dev(wl, wlvif);
3383 wl12xx_roc(wl, wl->dev_role_id);
3384 } 3579 }
3385 } 3580 }
3386 } 3581 }
@@ -3396,46 +3591,40 @@ static void wl1271_bss_info_changed_sta(struct wl1271 *wl,
3396 wl1271_debug(DEBUG_ADHOC, "ad-hoc beaconing: %s", 3591 wl1271_debug(DEBUG_ADHOC, "ad-hoc beaconing: %s",
3397 bss_conf->enable_beacon ? "enabled" : "disabled"); 3592 bss_conf->enable_beacon ? "enabled" : "disabled");
3398 3593
3399 if (bss_conf->enable_beacon)
3400 wl->set_bss_type = BSS_TYPE_IBSS;
3401 else
3402 wl->set_bss_type = BSS_TYPE_STA_BSS;
3403 do_join = true; 3594 do_join = true;
3404 } 3595 }
3405 3596
3597 if (changed & BSS_CHANGED_IDLE) {
3598 ret = wl1271_sta_handle_idle(wl, wlvif, bss_conf->idle);
3599 if (ret < 0)
3600 wl1271_warning("idle mode change failed %d", ret);
3601 }
3602
3406 if ((changed & BSS_CHANGED_CQM)) { 3603 if ((changed & BSS_CHANGED_CQM)) {
3407 bool enable = false; 3604 bool enable = false;
3408 if (bss_conf->cqm_rssi_thold) 3605 if (bss_conf->cqm_rssi_thold)
3409 enable = true; 3606 enable = true;
3410 ret = wl1271_acx_rssi_snr_trigger(wl, enable, 3607 ret = wl1271_acx_rssi_snr_trigger(wl, wlvif, enable,
3411 bss_conf->cqm_rssi_thold, 3608 bss_conf->cqm_rssi_thold,
3412 bss_conf->cqm_rssi_hyst); 3609 bss_conf->cqm_rssi_hyst);
3413 if (ret < 0) 3610 if (ret < 0)
3414 goto out; 3611 goto out;
3415 wl->rssi_thold = bss_conf->cqm_rssi_thold; 3612 wlvif->rssi_thold = bss_conf->cqm_rssi_thold;
3416 } 3613 }
3417 3614
3418 if ((changed & BSS_CHANGED_BSSID) && 3615 if (changed & BSS_CHANGED_BSSID)
3419 /* 3616 if (!is_zero_ether_addr(bss_conf->bssid)) {
3420 * Now we know the correct bssid, so we send a new join command 3617 ret = wl12xx_cmd_build_null_data(wl, wlvif);
3421 * and enable the BSSID filter
3422 */
3423 memcmp(wl->bssid, bss_conf->bssid, ETH_ALEN)) {
3424 memcpy(wl->bssid, bss_conf->bssid, ETH_ALEN);
3425
3426 if (!is_zero_ether_addr(wl->bssid)) {
3427 ret = wl1271_cmd_build_null_data(wl);
3428 if (ret < 0) 3618 if (ret < 0)
3429 goto out; 3619 goto out;
3430 3620
3431 ret = wl1271_build_qos_null_data(wl); 3621 ret = wl1271_build_qos_null_data(wl, vif);
3432 if (ret < 0) 3622 if (ret < 0)
3433 goto out; 3623 goto out;
3434 3624
3435 /* Need to update the BSSID (for filtering etc) */ 3625 /* Need to update the BSSID (for filtering etc) */
3436 do_join = true; 3626 do_join = true;
3437 } 3627 }
3438 }
3439 3628
3440 if (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_HT)) { 3629 if (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_HT)) {
3441 rcu_read_lock(); 3630 rcu_read_lock();
@@ -3459,26 +3648,28 @@ sta_not_found:
3459 if (bss_conf->assoc) { 3648 if (bss_conf->assoc) {
3460 u32 rates; 3649 u32 rates;
3461 int ieoffset; 3650 int ieoffset;
3462 wl->aid = bss_conf->aid; 3651 wlvif->aid = bss_conf->aid;
3463 set_assoc = true; 3652 set_assoc = true;
3464 3653
3465 wl->ps_poll_failures = 0; 3654 wlvif->ps_poll_failures = 0;
3466 3655
3467 /* 3656 /*
3468 * use basic rates from AP, and determine lowest rate 3657 * use basic rates from AP, and determine lowest rate
3469 * to use with control frames. 3658 * to use with control frames.
3470 */ 3659 */
3471 rates = bss_conf->basic_rates; 3660 rates = bss_conf->basic_rates;
3472 wl->basic_rate_set = 3661 wlvif->basic_rate_set =
3473 wl1271_tx_enabled_rates_get(wl, rates, 3662 wl1271_tx_enabled_rates_get(wl, rates,
3474 wl->band); 3663 wlvif->band);
3475 wl->basic_rate = 3664 wlvif->basic_rate =
3476 wl1271_tx_min_rate_get(wl, wl->basic_rate_set); 3665 wl1271_tx_min_rate_get(wl,
3666 wlvif->basic_rate_set);
3477 if (sta_rate_set) 3667 if (sta_rate_set)
3478 wl->rate_set = wl1271_tx_enabled_rates_get(wl, 3668 wlvif->rate_set =
3669 wl1271_tx_enabled_rates_get(wl,
3479 sta_rate_set, 3670 sta_rate_set,
3480 wl->band); 3671 wlvif->band);
3481 ret = wl1271_acx_sta_rate_policies(wl); 3672 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
3482 if (ret < 0) 3673 if (ret < 0)
3483 goto out; 3674 goto out;
3484 3675
@@ -3488,53 +3679,56 @@ sta_not_found:
3488 * updates it by itself when the first beacon is 3679 * updates it by itself when the first beacon is
3489 * received after a join. 3680 * received after a join.
3490 */ 3681 */
3491 ret = wl1271_cmd_build_ps_poll(wl, wl->aid); 3682 ret = wl1271_cmd_build_ps_poll(wl, wlvif, wlvif->aid);
3492 if (ret < 0) 3683 if (ret < 0)
3493 goto out; 3684 goto out;
3494 3685
3495 /* 3686 /*
3496 * Get a template for hardware connection maintenance 3687 * Get a template for hardware connection maintenance
3497 */ 3688 */
3498 dev_kfree_skb(wl->probereq); 3689 dev_kfree_skb(wlvif->probereq);
3499 wl->probereq = wl1271_cmd_build_ap_probe_req(wl, NULL); 3690 wlvif->probereq = wl1271_cmd_build_ap_probe_req(wl,
3691 wlvif,
3692 NULL);
3500 ieoffset = offsetof(struct ieee80211_mgmt, 3693 ieoffset = offsetof(struct ieee80211_mgmt,
3501 u.probe_req.variable); 3694 u.probe_req.variable);
3502 wl1271_ssid_set(wl, wl->probereq, ieoffset); 3695 wl1271_ssid_set(vif, wlvif->probereq, ieoffset);
3503 3696
3504 /* enable the connection monitoring feature */ 3697 /* enable the connection monitoring feature */
3505 ret = wl1271_acx_conn_monit_params(wl, true); 3698 ret = wl1271_acx_conn_monit_params(wl, wlvif, true);
3506 if (ret < 0) 3699 if (ret < 0)
3507 goto out; 3700 goto out;
3508 } else { 3701 } else {
3509 /* use defaults when not associated */ 3702 /* use defaults when not associated */
3510 bool was_assoc = 3703 bool was_assoc =
3511 !!test_and_clear_bit(WL1271_FLAG_STA_ASSOCIATED, 3704 !!test_and_clear_bit(WLVIF_FLAG_STA_ASSOCIATED,
3512 &wl->flags); 3705 &wlvif->flags);
3513 bool was_ifup = 3706 bool was_ifup =
3514 !!test_and_clear_bit(WL1271_FLAG_STA_STATE_SENT, 3707 !!test_and_clear_bit(WLVIF_FLAG_STA_STATE_SENT,
3515 &wl->flags); 3708 &wlvif->flags);
3516 wl->aid = 0; 3709 wlvif->aid = 0;
3517 3710
3518 /* free probe-request template */ 3711 /* free probe-request template */
3519 dev_kfree_skb(wl->probereq); 3712 dev_kfree_skb(wlvif->probereq);
3520 wl->probereq = NULL; 3713 wlvif->probereq = NULL;
3521 3714
3522 /* re-enable dynamic ps - just in case */ 3715 /* re-enable dynamic ps - just in case */
3523 ieee80211_enable_dyn_ps(wl->vif); 3716 ieee80211_enable_dyn_ps(vif);
3524 3717
3525 /* revert back to minimum rates for the current band */ 3718 /* revert back to minimum rates for the current band */
3526 wl1271_set_band_rate(wl); 3719 wl1271_set_band_rate(wl, wlvif);
3527 wl->basic_rate = 3720 wlvif->basic_rate =
3528 wl1271_tx_min_rate_get(wl, wl->basic_rate_set); 3721 wl1271_tx_min_rate_get(wl,
3529 ret = wl1271_acx_sta_rate_policies(wl); 3722 wlvif->basic_rate_set);
3723 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
3530 if (ret < 0) 3724 if (ret < 0)
3531 goto out; 3725 goto out;
3532 3726
3533 /* disable connection monitor features */ 3727 /* disable connection monitor features */
3534 ret = wl1271_acx_conn_monit_params(wl, false); 3728 ret = wl1271_acx_conn_monit_params(wl, wlvif, false);
3535 3729
3536 /* Disable the keep-alive feature */ 3730 /* Disable the keep-alive feature */
3537 ret = wl1271_acx_keep_alive_mode(wl, false); 3731 ret = wl1271_acx_keep_alive_mode(wl, wlvif, false);
3538 if (ret < 0) 3732 if (ret < 0)
3539 goto out; 3733 goto out;
3540 3734
@@ -3546,7 +3740,7 @@ sta_not_found:
3546 * no IF_OPER_UP notification. 3740 * no IF_OPER_UP notification.
3547 */ 3741 */
3548 if (!was_ifup) { 3742 if (!was_ifup) {
3549 ret = wl12xx_croc(wl, wl->role_id); 3743 ret = wl12xx_croc(wl, wlvif->role_id);
3550 if (ret < 0) 3744 if (ret < 0)
3551 goto out; 3745 goto out;
3552 } 3746 }
@@ -3555,17 +3749,16 @@ sta_not_found:
3555 * roaming on the same channel. until we will 3749 * roaming on the same channel. until we will
3556 * have a better flow...) 3750 * have a better flow...)
3557 */ 3751 */
3558 if (test_bit(wl->dev_role_id, wl->roc_map)) { 3752 if (test_bit(wlvif->dev_role_id, wl->roc_map)) {
3559 ret = wl12xx_croc(wl, wl->dev_role_id); 3753 ret = wl12xx_croc(wl,
3754 wlvif->dev_role_id);
3560 if (ret < 0) 3755 if (ret < 0)
3561 goto out; 3756 goto out;
3562 } 3757 }
3563 3758
3564 wl1271_unjoin(wl); 3759 wl1271_unjoin(wl, wlvif);
3565 if (!(conf_flags & IEEE80211_CONF_IDLE)) { 3760 if (!(conf_flags & IEEE80211_CONF_IDLE))
3566 wl12xx_cmd_role_start_dev(wl); 3761 wl12xx_start_dev(wl, wlvif);
3567 wl12xx_roc(wl, wl->dev_role_id);
3568 }
3569 } 3762 }
3570 } 3763 }
3571 } 3764 }
@@ -3576,27 +3769,28 @@ sta_not_found:
3576 3769
3577 if (bss_conf->ibss_joined) { 3770 if (bss_conf->ibss_joined) {
3578 u32 rates = bss_conf->basic_rates; 3771 u32 rates = bss_conf->basic_rates;
3579 wl->basic_rate_set = 3772 wlvif->basic_rate_set =
3580 wl1271_tx_enabled_rates_get(wl, rates, 3773 wl1271_tx_enabled_rates_get(wl, rates,
3581 wl->band); 3774 wlvif->band);
3582 wl->basic_rate = 3775 wlvif->basic_rate =
3583 wl1271_tx_min_rate_get(wl, wl->basic_rate_set); 3776 wl1271_tx_min_rate_get(wl,
3777 wlvif->basic_rate_set);
3584 3778
3585 /* by default, use 11b + OFDM rates */ 3779 /* by default, use 11b + OFDM rates */
3586 wl->rate_set = CONF_TX_IBSS_DEFAULT_RATES; 3780 wlvif->rate_set = CONF_TX_IBSS_DEFAULT_RATES;
3587 ret = wl1271_acx_sta_rate_policies(wl); 3781 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
3588 if (ret < 0) 3782 if (ret < 0)
3589 goto out; 3783 goto out;
3590 } 3784 }
3591 } 3785 }
3592 3786
3593 ret = wl1271_bss_erp_info_changed(wl, bss_conf, changed); 3787 ret = wl1271_bss_erp_info_changed(wl, vif, bss_conf, changed);
3594 if (ret < 0) 3788 if (ret < 0)
3595 goto out; 3789 goto out;
3596 3790
3597 if (changed & BSS_CHANGED_ARP_FILTER) { 3791 if (changed & BSS_CHANGED_ARP_FILTER) {
3598 __be32 addr = bss_conf->arp_addr_list[0]; 3792 __be32 addr = bss_conf->arp_addr_list[0];
3599 WARN_ON(wl->bss_type != BSS_TYPE_STA_BSS); 3793 WARN_ON(wlvif->bss_type != BSS_TYPE_STA_BSS);
3600 3794
3601 if (bss_conf->arp_addr_cnt == 1 && 3795 if (bss_conf->arp_addr_cnt == 1 &&
3602 bss_conf->arp_filter_enabled) { 3796 bss_conf->arp_filter_enabled) {
@@ -3606,24 +3800,24 @@ sta_not_found:
3606 * isn't being set (when sending), so we have to 3800 * isn't being set (when sending), so we have to
3607 * reconfigure the template upon every ip change. 3801 * reconfigure the template upon every ip change.
3608 */ 3802 */
3609 ret = wl1271_cmd_build_arp_rsp(wl, addr); 3803 ret = wl1271_cmd_build_arp_rsp(wl, wlvif, addr);
3610 if (ret < 0) { 3804 if (ret < 0) {
3611 wl1271_warning("build arp rsp failed: %d", ret); 3805 wl1271_warning("build arp rsp failed: %d", ret);
3612 goto out; 3806 goto out;
3613 } 3807 }
3614 3808
3615 ret = wl1271_acx_arp_ip_filter(wl, 3809 ret = wl1271_acx_arp_ip_filter(wl, wlvif,
3616 ACX_ARP_FILTER_ARP_FILTERING, 3810 ACX_ARP_FILTER_ARP_FILTERING,
3617 addr); 3811 addr);
3618 } else 3812 } else
3619 ret = wl1271_acx_arp_ip_filter(wl, 0, addr); 3813 ret = wl1271_acx_arp_ip_filter(wl, wlvif, 0, addr);
3620 3814
3621 if (ret < 0) 3815 if (ret < 0)
3622 goto out; 3816 goto out;
3623 } 3817 }
3624 3818
3625 if (do_join) { 3819 if (do_join) {
3626 ret = wl1271_join(wl, set_assoc); 3820 ret = wl1271_join(wl, wlvif, set_assoc);
3627 if (ret < 0) { 3821 if (ret < 0) {
3628 wl1271_warning("cmd join failed %d", ret); 3822 wl1271_warning("cmd join failed %d", ret);
3629 goto out; 3823 goto out;
@@ -3631,35 +3825,31 @@ sta_not_found:
3631 3825
3632 /* ROC until connected (after EAPOL exchange) */ 3826 /* ROC until connected (after EAPOL exchange) */
3633 if (!is_ibss) { 3827 if (!is_ibss) {
3634 ret = wl12xx_roc(wl, wl->role_id); 3828 ret = wl12xx_roc(wl, wlvif, wlvif->role_id);
3635 if (ret < 0) 3829 if (ret < 0)
3636 goto out; 3830 goto out;
3637 3831
3638 wl1271_check_operstate(wl, 3832 wl1271_check_operstate(wl, wlvif,
3639 ieee80211_get_operstate(vif)); 3833 ieee80211_get_operstate(vif));
3640 } 3834 }
3641 /* 3835 /*
3642 * stop device role if started (we might already be in 3836 * stop device role if started (we might already be in
3643 * STA role). TODO: make it better. 3837 * STA role). TODO: make it better.
3644 */ 3838 */
3645 if (wl->dev_role_id != WL12XX_INVALID_ROLE_ID) { 3839 if (wlvif->dev_role_id != WL12XX_INVALID_ROLE_ID) {
3646 ret = wl12xx_croc(wl, wl->dev_role_id); 3840 ret = wl12xx_stop_dev(wl, wlvif);
3647 if (ret < 0)
3648 goto out;
3649
3650 ret = wl12xx_cmd_role_stop_dev(wl);
3651 if (ret < 0) 3841 if (ret < 0)
3652 goto out; 3842 goto out;
3653 } 3843 }
3654 3844
3655 /* If we want to go in PSM but we're not there yet */ 3845 /* If we want to go in PSM but we're not there yet */
3656 if (test_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags) && 3846 if (test_bit(WLVIF_FLAG_PSM_REQUESTED, &wlvif->flags) &&
3657 !test_bit(WL1271_FLAG_PSM, &wl->flags)) { 3847 !test_bit(WLVIF_FLAG_PSM, &wlvif->flags)) {
3658 enum wl1271_cmd_ps_mode mode; 3848 enum wl1271_cmd_ps_mode mode;
3659 3849
3660 mode = STATION_POWER_SAVE_MODE; 3850 mode = STATION_POWER_SAVE_MODE;
3661 ret = wl1271_ps_set_mode(wl, mode, 3851 ret = wl1271_ps_set_mode(wl, wlvif, mode,
3662 wl->basic_rate, 3852 wlvif->basic_rate,
3663 true); 3853 true);
3664 if (ret < 0) 3854 if (ret < 0)
3665 goto out; 3855 goto out;
@@ -3673,7 +3863,7 @@ sta_not_found:
3673 ret = wl1271_acx_set_ht_capabilities(wl, 3863 ret = wl1271_acx_set_ht_capabilities(wl,
3674 &sta_ht_cap, 3864 &sta_ht_cap,
3675 true, 3865 true,
3676 wl->sta_hlid); 3866 wlvif->sta.hlid);
3677 if (ret < 0) { 3867 if (ret < 0) {
3678 wl1271_warning("Set ht cap true failed %d", 3868 wl1271_warning("Set ht cap true failed %d",
3679 ret); 3869 ret);
@@ -3685,7 +3875,7 @@ sta_not_found:
3685 ret = wl1271_acx_set_ht_capabilities(wl, 3875 ret = wl1271_acx_set_ht_capabilities(wl,
3686 &sta_ht_cap, 3876 &sta_ht_cap,
3687 false, 3877 false,
3688 wl->sta_hlid); 3878 wlvif->sta.hlid);
3689 if (ret < 0) { 3879 if (ret < 0) {
3690 wl1271_warning("Set ht cap false failed %d", 3880 wl1271_warning("Set ht cap false failed %d",
3691 ret); 3881 ret);
@@ -3697,7 +3887,7 @@ sta_not_found:
3697 /* Handle HT information change. Done after join. */ 3887 /* Handle HT information change. Done after join. */
3698 if ((changed & BSS_CHANGED_HT) && 3888 if ((changed & BSS_CHANGED_HT) &&
3699 (bss_conf->channel_type != NL80211_CHAN_NO_HT)) { 3889 (bss_conf->channel_type != NL80211_CHAN_NO_HT)) {
3700 ret = wl1271_acx_set_ht_information(wl, 3890 ret = wl1271_acx_set_ht_information(wl, wlvif,
3701 bss_conf->ht_operation_mode); 3891 bss_conf->ht_operation_mode);
3702 if (ret < 0) { 3892 if (ret < 0) {
3703 wl1271_warning("Set ht information failed %d", ret); 3893 wl1271_warning("Set ht information failed %d", ret);
@@ -3715,7 +3905,8 @@ static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw,
3715 u32 changed) 3905 u32 changed)
3716{ 3906{
3717 struct wl1271 *wl = hw->priv; 3907 struct wl1271 *wl = hw->priv;
3718 bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS); 3908 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3909 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
3719 int ret; 3910 int ret;
3720 3911
3721 wl1271_debug(DEBUG_MAC80211, "mac80211 bss info changed 0x%x", 3912 wl1271_debug(DEBUG_MAC80211, "mac80211 bss info changed 0x%x",
@@ -3726,6 +3917,9 @@ static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw,
3726 if (unlikely(wl->state == WL1271_STATE_OFF)) 3917 if (unlikely(wl->state == WL1271_STATE_OFF))
3727 goto out; 3918 goto out;
3728 3919
3920 if (unlikely(!test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)))
3921 goto out;
3922
3729 ret = wl1271_ps_elp_wakeup(wl); 3923 ret = wl1271_ps_elp_wakeup(wl);
3730 if (ret < 0) 3924 if (ret < 0)
3731 goto out; 3925 goto out;
@@ -3746,6 +3940,7 @@ static int wl1271_op_conf_tx(struct ieee80211_hw *hw,
3746 const struct ieee80211_tx_queue_params *params) 3940 const struct ieee80211_tx_queue_params *params)
3747{ 3941{
3748 struct wl1271 *wl = hw->priv; 3942 struct wl1271 *wl = hw->priv;
3943 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3749 u8 ps_scheme; 3944 u8 ps_scheme;
3750 int ret = 0; 3945 int ret = 0;
3751 3946
@@ -3792,13 +3987,13 @@ static int wl1271_op_conf_tx(struct ieee80211_hw *hw,
3792 * the txop is confed in units of 32us by the mac80211, 3987 * the txop is confed in units of 32us by the mac80211,
3793 * we need us 3988 * we need us
3794 */ 3989 */
3795 ret = wl1271_acx_ac_cfg(wl, wl1271_tx_get_queue(queue), 3990 ret = wl1271_acx_ac_cfg(wl, wlvif, wl1271_tx_get_queue(queue),
3796 params->cw_min, params->cw_max, 3991 params->cw_min, params->cw_max,
3797 params->aifs, params->txop << 5); 3992 params->aifs, params->txop << 5);
3798 if (ret < 0) 3993 if (ret < 0)
3799 goto out_sleep; 3994 goto out_sleep;
3800 3995
3801 ret = wl1271_acx_tid_cfg(wl, wl1271_tx_get_queue(queue), 3996 ret = wl1271_acx_tid_cfg(wl, wlvif, wl1271_tx_get_queue(queue),
3802 CONF_CHANNEL_TYPE_EDCF, 3997 CONF_CHANNEL_TYPE_EDCF,
3803 wl1271_tx_get_queue(queue), 3998 wl1271_tx_get_queue(queue),
3804 ps_scheme, CONF_ACK_POLICY_LEGACY, 3999 ps_scheme, CONF_ACK_POLICY_LEGACY,
@@ -3861,43 +4056,43 @@ static int wl1271_op_get_survey(struct ieee80211_hw *hw, int idx,
3861} 4056}
3862 4057
3863static int wl1271_allocate_sta(struct wl1271 *wl, 4058static int wl1271_allocate_sta(struct wl1271 *wl,
3864 struct ieee80211_sta *sta, 4059 struct wl12xx_vif *wlvif,
3865 u8 *hlid) 4060 struct ieee80211_sta *sta)
3866{ 4061{
3867 struct wl1271_station *wl_sta; 4062 struct wl1271_station *wl_sta;
3868 int id; 4063 int ret;
3869 4064
3870 id = find_first_zero_bit(wl->ap_hlid_map, AP_MAX_STATIONS); 4065
3871 if (id >= AP_MAX_STATIONS) { 4066 if (wl->active_sta_count >= AP_MAX_STATIONS) {
3872 wl1271_warning("could not allocate HLID - too much stations"); 4067 wl1271_warning("could not allocate HLID - too much stations");
3873 return -EBUSY; 4068 return -EBUSY;
3874 } 4069 }
3875 4070
3876 wl_sta = (struct wl1271_station *)sta->drv_priv; 4071 wl_sta = (struct wl1271_station *)sta->drv_priv;
3877 set_bit(id, wl->ap_hlid_map); 4072 ret = wl12xx_allocate_link(wl, wlvif, &wl_sta->hlid);
3878 wl_sta->hlid = WL1271_AP_STA_HLID_START + id; 4073 if (ret < 0) {
3879 *hlid = wl_sta->hlid; 4074 wl1271_warning("could not allocate HLID - too many links");
4075 return -EBUSY;
4076 }
4077
4078 set_bit(wl_sta->hlid, wlvif->ap.sta_hlid_map);
3880 memcpy(wl->links[wl_sta->hlid].addr, sta->addr, ETH_ALEN); 4079 memcpy(wl->links[wl_sta->hlid].addr, sta->addr, ETH_ALEN);
3881 wl->active_sta_count++; 4080 wl->active_sta_count++;
3882 return 0; 4081 return 0;
3883} 4082}
3884 4083
3885void wl1271_free_sta(struct wl1271 *wl, u8 hlid) 4084void wl1271_free_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 hlid)
3886{ 4085{
3887 int id = hlid - WL1271_AP_STA_HLID_START; 4086 if (!test_bit(hlid, wlvif->ap.sta_hlid_map))
3888
3889 if (hlid < WL1271_AP_STA_HLID_START)
3890 return;
3891
3892 if (!test_bit(id, wl->ap_hlid_map))
3893 return; 4087 return;
3894 4088
3895 clear_bit(id, wl->ap_hlid_map); 4089 clear_bit(hlid, wlvif->ap.sta_hlid_map);
3896 memset(wl->links[hlid].addr, 0, ETH_ALEN); 4090 memset(wl->links[hlid].addr, 0, ETH_ALEN);
3897 wl->links[hlid].ba_bitmap = 0; 4091 wl->links[hlid].ba_bitmap = 0;
3898 wl1271_tx_reset_link_queues(wl, hlid); 4092 wl1271_tx_reset_link_queues(wl, hlid);
3899 __clear_bit(hlid, &wl->ap_ps_map); 4093 __clear_bit(hlid, &wl->ap_ps_map);
3900 __clear_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map); 4094 __clear_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map);
4095 wl12xx_free_link(wl, wlvif, &hlid);
3901 wl->active_sta_count--; 4096 wl->active_sta_count--;
3902} 4097}
3903 4098
@@ -3906,6 +4101,8 @@ static int wl1271_op_sta_add(struct ieee80211_hw *hw,
3906 struct ieee80211_sta *sta) 4101 struct ieee80211_sta *sta)
3907{ 4102{
3908 struct wl1271 *wl = hw->priv; 4103 struct wl1271 *wl = hw->priv;
4104 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
4105 struct wl1271_station *wl_sta;
3909 int ret = 0; 4106 int ret = 0;
3910 u8 hlid; 4107 u8 hlid;
3911 4108
@@ -3914,20 +4111,23 @@ static int wl1271_op_sta_add(struct ieee80211_hw *hw,
3914 if (unlikely(wl->state == WL1271_STATE_OFF)) 4111 if (unlikely(wl->state == WL1271_STATE_OFF))
3915 goto out; 4112 goto out;
3916 4113
3917 if (wl->bss_type != BSS_TYPE_AP_BSS) 4114 if (wlvif->bss_type != BSS_TYPE_AP_BSS)
3918 goto out; 4115 goto out;
3919 4116
3920 wl1271_debug(DEBUG_MAC80211, "mac80211 add sta %d", (int)sta->aid); 4117 wl1271_debug(DEBUG_MAC80211, "mac80211 add sta %d", (int)sta->aid);
3921 4118
3922 ret = wl1271_allocate_sta(wl, sta, &hlid); 4119 ret = wl1271_allocate_sta(wl, wlvif, sta);
3923 if (ret < 0) 4120 if (ret < 0)
3924 goto out; 4121 goto out;
3925 4122
4123 wl_sta = (struct wl1271_station *)sta->drv_priv;
4124 hlid = wl_sta->hlid;
4125
3926 ret = wl1271_ps_elp_wakeup(wl); 4126 ret = wl1271_ps_elp_wakeup(wl);
3927 if (ret < 0) 4127 if (ret < 0)
3928 goto out_free_sta; 4128 goto out_free_sta;
3929 4129
3930 ret = wl12xx_cmd_add_peer(wl, sta, hlid); 4130 ret = wl12xx_cmd_add_peer(wl, wlvif, sta, hlid);
3931 if (ret < 0) 4131 if (ret < 0)
3932 goto out_sleep; 4132 goto out_sleep;
3933 4133
@@ -3944,7 +4144,7 @@ out_sleep:
3944 4144
3945out_free_sta: 4145out_free_sta:
3946 if (ret < 0) 4146 if (ret < 0)
3947 wl1271_free_sta(wl, hlid); 4147 wl1271_free_sta(wl, wlvif, hlid);
3948 4148
3949out: 4149out:
3950 mutex_unlock(&wl->mutex); 4150 mutex_unlock(&wl->mutex);
@@ -3956,6 +4156,7 @@ static int wl1271_op_sta_remove(struct ieee80211_hw *hw,
3956 struct ieee80211_sta *sta) 4156 struct ieee80211_sta *sta)
3957{ 4157{
3958 struct wl1271 *wl = hw->priv; 4158 struct wl1271 *wl = hw->priv;
4159 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3959 struct wl1271_station *wl_sta; 4160 struct wl1271_station *wl_sta;
3960 int ret = 0, id; 4161 int ret = 0, id;
3961 4162
@@ -3964,14 +4165,14 @@ static int wl1271_op_sta_remove(struct ieee80211_hw *hw,
3964 if (unlikely(wl->state == WL1271_STATE_OFF)) 4165 if (unlikely(wl->state == WL1271_STATE_OFF))
3965 goto out; 4166 goto out;
3966 4167
3967 if (wl->bss_type != BSS_TYPE_AP_BSS) 4168 if (wlvif->bss_type != BSS_TYPE_AP_BSS)
3968 goto out; 4169 goto out;
3969 4170
3970 wl1271_debug(DEBUG_MAC80211, "mac80211 remove sta %d", (int)sta->aid); 4171 wl1271_debug(DEBUG_MAC80211, "mac80211 remove sta %d", (int)sta->aid);
3971 4172
3972 wl_sta = (struct wl1271_station *)sta->drv_priv; 4173 wl_sta = (struct wl1271_station *)sta->drv_priv;
3973 id = wl_sta->hlid - WL1271_AP_STA_HLID_START; 4174 id = wl_sta->hlid;
3974 if (WARN_ON(!test_bit(id, wl->ap_hlid_map))) 4175 if (WARN_ON(!test_bit(id, wlvif->ap.sta_hlid_map)))
3975 goto out; 4176 goto out;
3976 4177
3977 ret = wl1271_ps_elp_wakeup(wl); 4178 ret = wl1271_ps_elp_wakeup(wl);
@@ -3982,7 +4183,7 @@ static int wl1271_op_sta_remove(struct ieee80211_hw *hw,
3982 if (ret < 0) 4183 if (ret < 0)
3983 goto out_sleep; 4184 goto out_sleep;
3984 4185
3985 wl1271_free_sta(wl, wl_sta->hlid); 4186 wl1271_free_sta(wl, wlvif, wl_sta->hlid);
3986 4187
3987out_sleep: 4188out_sleep:
3988 wl1271_ps_elp_sleep(wl); 4189 wl1271_ps_elp_sleep(wl);
@@ -3999,6 +4200,7 @@ static int wl1271_op_ampdu_action(struct ieee80211_hw *hw,
3999 u8 buf_size) 4200 u8 buf_size)
4000{ 4201{
4001 struct wl1271 *wl = hw->priv; 4202 struct wl1271 *wl = hw->priv;
4203 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
4002 int ret; 4204 int ret;
4003 u8 hlid, *ba_bitmap; 4205 u8 hlid, *ba_bitmap;
4004 4206
@@ -4016,10 +4218,10 @@ static int wl1271_op_ampdu_action(struct ieee80211_hw *hw,
4016 goto out; 4218 goto out;
4017 } 4219 }
4018 4220
4019 if (wl->bss_type == BSS_TYPE_STA_BSS) { 4221 if (wlvif->bss_type == BSS_TYPE_STA_BSS) {
4020 hlid = wl->sta_hlid; 4222 hlid = wlvif->sta.hlid;
4021 ba_bitmap = &wl->ba_rx_bitmap; 4223 ba_bitmap = &wlvif->sta.ba_rx_bitmap;
4022 } else if (wl->bss_type == BSS_TYPE_AP_BSS) { 4224 } else if (wlvif->bss_type == BSS_TYPE_AP_BSS) {
4023 struct wl1271_station *wl_sta; 4225 struct wl1271_station *wl_sta;
4024 4226
4025 wl_sta = (struct wl1271_station *)sta->drv_priv; 4227 wl_sta = (struct wl1271_station *)sta->drv_priv;
@@ -4039,7 +4241,7 @@ static int wl1271_op_ampdu_action(struct ieee80211_hw *hw,
4039 4241
4040 switch (action) { 4242 switch (action) {
4041 case IEEE80211_AMPDU_RX_START: 4243 case IEEE80211_AMPDU_RX_START:
4042 if (!wl->ba_support || !wl->ba_allowed) { 4244 if (!wlvif->ba_support || !wlvif->ba_allowed) {
4043 ret = -ENOTSUPP; 4245 ret = -ENOTSUPP;
4044 break; 4246 break;
4045 } 4247 }
@@ -4108,8 +4310,9 @@ static int wl12xx_set_bitrate_mask(struct ieee80211_hw *hw,
4108 struct ieee80211_vif *vif, 4310 struct ieee80211_vif *vif,
4109 const struct cfg80211_bitrate_mask *mask) 4311 const struct cfg80211_bitrate_mask *mask)
4110{ 4312{
4313 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
4111 struct wl1271 *wl = hw->priv; 4314 struct wl1271 *wl = hw->priv;
4112 int i; 4315 int i, ret = 0;
4113 4316
4114 wl1271_debug(DEBUG_MAC80211, "mac80211 set_bitrate_mask 0x%x 0x%x", 4317 wl1271_debug(DEBUG_MAC80211, "mac80211 set_bitrate_mask 0x%x 0x%x",
4115 mask->control[NL80211_BAND_2GHZ].legacy, 4318 mask->control[NL80211_BAND_2GHZ].legacy,
@@ -4118,19 +4321,39 @@ static int wl12xx_set_bitrate_mask(struct ieee80211_hw *hw,
4118 mutex_lock(&wl->mutex); 4321 mutex_lock(&wl->mutex);
4119 4322
4120 for (i = 0; i < IEEE80211_NUM_BANDS; i++) 4323 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
4121 wl->bitrate_masks[i] = 4324 wlvif->bitrate_masks[i] =
4122 wl1271_tx_enabled_rates_get(wl, 4325 wl1271_tx_enabled_rates_get(wl,
4123 mask->control[i].legacy, 4326 mask->control[i].legacy,
4124 i); 4327 i);
4328
4329 if (unlikely(wl->state == WL1271_STATE_OFF))
4330 goto out;
4331
4332 if (wlvif->bss_type == BSS_TYPE_STA_BSS &&
4333 !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) {
4334
4335 ret = wl1271_ps_elp_wakeup(wl);
4336 if (ret < 0)
4337 goto out;
4338
4339 wl1271_set_band_rate(wl, wlvif);
4340 wlvif->basic_rate =
4341 wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
4342 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
4343
4344 wl1271_ps_elp_sleep(wl);
4345 }
4346out:
4125 mutex_unlock(&wl->mutex); 4347 mutex_unlock(&wl->mutex);
4126 4348
4127 return 0; 4349 return ret;
4128} 4350}
4129 4351
4130static void wl12xx_op_channel_switch(struct ieee80211_hw *hw, 4352static void wl12xx_op_channel_switch(struct ieee80211_hw *hw,
4131 struct ieee80211_channel_switch *ch_switch) 4353 struct ieee80211_channel_switch *ch_switch)
4132{ 4354{
4133 struct wl1271 *wl = hw->priv; 4355 struct wl1271 *wl = hw->priv;
4356 struct wl12xx_vif *wlvif;
4134 int ret; 4357 int ret;
4135 4358
4136 wl1271_debug(DEBUG_MAC80211, "mac80211 channel switch"); 4359 wl1271_debug(DEBUG_MAC80211, "mac80211 channel switch");
@@ -4138,19 +4361,24 @@ static void wl12xx_op_channel_switch(struct ieee80211_hw *hw,
4138 mutex_lock(&wl->mutex); 4361 mutex_lock(&wl->mutex);
4139 4362
4140 if (unlikely(wl->state == WL1271_STATE_OFF)) { 4363 if (unlikely(wl->state == WL1271_STATE_OFF)) {
4141 mutex_unlock(&wl->mutex); 4364 wl12xx_for_each_wlvif_sta(wl, wlvif) {
4142 ieee80211_chswitch_done(wl->vif, false); 4365 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
4143 return; 4366 ieee80211_chswitch_done(vif, false);
4367 }
4368 goto out;
4144 } 4369 }
4145 4370
4146 ret = wl1271_ps_elp_wakeup(wl); 4371 ret = wl1271_ps_elp_wakeup(wl);
4147 if (ret < 0) 4372 if (ret < 0)
4148 goto out; 4373 goto out;
4149 4374
4150 ret = wl12xx_cmd_channel_switch(wl, ch_switch); 4375 /* TODO: change mac80211 to pass vif as param */
4376 wl12xx_for_each_wlvif_sta(wl, wlvif) {
4377 ret = wl12xx_cmd_channel_switch(wl, ch_switch);
4151 4378
4152 if (!ret) 4379 if (!ret)
4153 set_bit(WL1271_FLAG_CS_PROGRESS, &wl->flags); 4380 set_bit(WLVIF_FLAG_CS_PROGRESS, &wlvif->flags);
4381 }
4154 4382
4155 wl1271_ps_elp_sleep(wl); 4383 wl1271_ps_elp_sleep(wl);
4156 4384
@@ -4170,10 +4398,6 @@ static bool wl1271_tx_frames_pending(struct ieee80211_hw *hw)
4170 4398
4171 /* packets are considered pending if in the TX queue or the FW */ 4399 /* packets are considered pending if in the TX queue or the FW */
4172 ret = (wl1271_tx_total_queue_count(wl) > 0) || (wl->tx_frames_cnt > 0); 4400 ret = (wl1271_tx_total_queue_count(wl) > 0) || (wl->tx_frames_cnt > 0);
4173
4174 /* the above is appropriate for STA mode for PS purposes */
4175 WARN_ON(wl->bss_type != BSS_TYPE_STA_BSS);
4176
4177out: 4401out:
4178 mutex_unlock(&wl->mutex); 4402 mutex_unlock(&wl->mutex);
4179 4403
@@ -4604,7 +4828,7 @@ static struct bin_attribute fwlog_attr = {
4604 .read = wl1271_sysfs_read_fwlog, 4828 .read = wl1271_sysfs_read_fwlog,
4605}; 4829};
4606 4830
4607int wl1271_register_hw(struct wl1271 *wl) 4831static int wl1271_register_hw(struct wl1271 *wl)
4608{ 4832{
4609 int ret; 4833 int ret;
4610 4834
@@ -4645,9 +4869,8 @@ int wl1271_register_hw(struct wl1271 *wl)
4645 4869
4646 return 0; 4870 return 0;
4647} 4871}
4648EXPORT_SYMBOL_GPL(wl1271_register_hw);
4649 4872
4650void wl1271_unregister_hw(struct wl1271 *wl) 4873static void wl1271_unregister_hw(struct wl1271 *wl)
4651{ 4874{
4652 if (wl->state == WL1271_STATE_PLT) 4875 if (wl->state == WL1271_STATE_PLT)
4653 __wl1271_plt_stop(wl); 4876 __wl1271_plt_stop(wl);
@@ -4657,9 +4880,8 @@ void wl1271_unregister_hw(struct wl1271 *wl)
4657 wl->mac80211_registered = false; 4880 wl->mac80211_registered = false;
4658 4881
4659} 4882}
4660EXPORT_SYMBOL_GPL(wl1271_unregister_hw);
4661 4883
4662int wl1271_init_ieee80211(struct wl1271 *wl) 4884static int wl1271_init_ieee80211(struct wl1271 *wl)
4663{ 4885{
4664 static const u32 cipher_suites[] = { 4886 static const u32 cipher_suites[] = {
4665 WLAN_CIPHER_SUITE_WEP40, 4887 WLAN_CIPHER_SUITE_WEP40,
@@ -4736,27 +4958,33 @@ int wl1271_init_ieee80211(struct wl1271 *wl)
4736 4958
4737 wl->hw->wiphy->reg_notifier = wl1271_reg_notify; 4959 wl->hw->wiphy->reg_notifier = wl1271_reg_notify;
4738 4960
4739 SET_IEEE80211_DEV(wl->hw, wl1271_wl_to_dev(wl)); 4961 /* the FW answers probe-requests in AP-mode */
4962 wl->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
4963 wl->hw->wiphy->probe_resp_offload =
4964 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
4965 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
4966 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
4967
4968 SET_IEEE80211_DEV(wl->hw, wl->dev);
4740 4969
4741 wl->hw->sta_data_size = sizeof(struct wl1271_station); 4970 wl->hw->sta_data_size = sizeof(struct wl1271_station);
4971 wl->hw->vif_data_size = sizeof(struct wl12xx_vif);
4742 4972
4743 wl->hw->max_rx_aggregation_subframes = 8; 4973 wl->hw->max_rx_aggregation_subframes = 8;
4744 4974
4745 return 0; 4975 return 0;
4746} 4976}
4747EXPORT_SYMBOL_GPL(wl1271_init_ieee80211);
4748 4977
4749#define WL1271_DEFAULT_CHANNEL 0 4978#define WL1271_DEFAULT_CHANNEL 0
4750 4979
4751struct ieee80211_hw *wl1271_alloc_hw(void) 4980static struct ieee80211_hw *wl1271_alloc_hw(void)
4752{ 4981{
4753 struct ieee80211_hw *hw; 4982 struct ieee80211_hw *hw;
4754 struct platform_device *plat_dev = NULL;
4755 struct wl1271 *wl; 4983 struct wl1271 *wl;
4756 int i, j, ret; 4984 int i, j, ret;
4757 unsigned int order; 4985 unsigned int order;
4758 4986
4759 BUILD_BUG_ON(AP_MAX_LINKS > WL12XX_MAX_LINKS); 4987 BUILD_BUG_ON(AP_MAX_STATIONS > WL12XX_MAX_LINKS);
4760 4988
4761 hw = ieee80211_alloc_hw(sizeof(*wl), &wl1271_ops); 4989 hw = ieee80211_alloc_hw(sizeof(*wl), &wl1271_ops);
4762 if (!hw) { 4990 if (!hw) {
@@ -4765,41 +4993,26 @@ struct ieee80211_hw *wl1271_alloc_hw(void)
4765 goto err_hw_alloc; 4993 goto err_hw_alloc;
4766 } 4994 }
4767 4995
4768 plat_dev = kmemdup(&wl1271_device, sizeof(wl1271_device), GFP_KERNEL);
4769 if (!plat_dev) {
4770 wl1271_error("could not allocate platform_device");
4771 ret = -ENOMEM;
4772 goto err_plat_alloc;
4773 }
4774
4775 wl = hw->priv; 4996 wl = hw->priv;
4776 memset(wl, 0, sizeof(*wl)); 4997 memset(wl, 0, sizeof(*wl));
4777 4998
4778 INIT_LIST_HEAD(&wl->list); 4999 INIT_LIST_HEAD(&wl->list);
5000 INIT_LIST_HEAD(&wl->wlvif_list);
4779 5001
4780 wl->hw = hw; 5002 wl->hw = hw;
4781 wl->plat_dev = plat_dev;
4782
4783 for (i = 0; i < NUM_TX_QUEUES; i++)
4784 skb_queue_head_init(&wl->tx_queue[i]);
4785 5003
4786 for (i = 0; i < NUM_TX_QUEUES; i++) 5004 for (i = 0; i < NUM_TX_QUEUES; i++)
4787 for (j = 0; j < AP_MAX_LINKS; j++) 5005 for (j = 0; j < WL12XX_MAX_LINKS; j++)
4788 skb_queue_head_init(&wl->links[j].tx_queue[i]); 5006 skb_queue_head_init(&wl->links[j].tx_queue[i]);
4789 5007
4790 skb_queue_head_init(&wl->deferred_rx_queue); 5008 skb_queue_head_init(&wl->deferred_rx_queue);
4791 skb_queue_head_init(&wl->deferred_tx_queue); 5009 skb_queue_head_init(&wl->deferred_tx_queue);
4792 5010
4793 INIT_DELAYED_WORK(&wl->elp_work, wl1271_elp_work); 5011 INIT_DELAYED_WORK(&wl->elp_work, wl1271_elp_work);
4794 INIT_DELAYED_WORK(&wl->pspoll_work, wl1271_pspoll_work);
4795 INIT_WORK(&wl->netstack_work, wl1271_netstack_work); 5012 INIT_WORK(&wl->netstack_work, wl1271_netstack_work);
4796 INIT_WORK(&wl->tx_work, wl1271_tx_work); 5013 INIT_WORK(&wl->tx_work, wl1271_tx_work);
4797 INIT_WORK(&wl->recovery_work, wl1271_recovery_work); 5014 INIT_WORK(&wl->recovery_work, wl1271_recovery_work);
4798 INIT_DELAYED_WORK(&wl->scan_complete_work, wl1271_scan_complete_work); 5015 INIT_DELAYED_WORK(&wl->scan_complete_work, wl1271_scan_complete_work);
4799 INIT_WORK(&wl->rx_streaming_enable_work,
4800 wl1271_rx_streaming_enable_work);
4801 INIT_WORK(&wl->rx_streaming_disable_work,
4802 wl1271_rx_streaming_disable_work);
4803 5016
4804 wl->freezable_wq = create_freezable_workqueue("wl12xx_wq"); 5017 wl->freezable_wq = create_freezable_workqueue("wl12xx_wq");
4805 if (!wl->freezable_wq) { 5018 if (!wl->freezable_wq) {
@@ -4808,41 +5021,21 @@ struct ieee80211_hw *wl1271_alloc_hw(void)
4808 } 5021 }
4809 5022
4810 wl->channel = WL1271_DEFAULT_CHANNEL; 5023 wl->channel = WL1271_DEFAULT_CHANNEL;
4811 wl->beacon_int = WL1271_DEFAULT_BEACON_INT;
4812 wl->default_key = 0;
4813 wl->rx_counter = 0; 5024 wl->rx_counter = 0;
4814 wl->psm_entry_retry = 0;
4815 wl->power_level = WL1271_DEFAULT_POWER_LEVEL; 5025 wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
4816 wl->basic_rate_set = CONF_TX_RATE_MASK_BASIC;
4817 wl->basic_rate = CONF_TX_RATE_MASK_BASIC;
4818 wl->rate_set = CONF_TX_RATE_MASK_BASIC;
4819 wl->band = IEEE80211_BAND_2GHZ; 5026 wl->band = IEEE80211_BAND_2GHZ;
4820 wl->vif = NULL; 5027 wl->vif = NULL;
4821 wl->flags = 0; 5028 wl->flags = 0;
4822 wl->sg_enabled = true; 5029 wl->sg_enabled = true;
4823 wl->hw_pg_ver = -1; 5030 wl->hw_pg_ver = -1;
4824 wl->bss_type = MAX_BSS_TYPE;
4825 wl->set_bss_type = MAX_BSS_TYPE;
4826 wl->last_tx_hlid = 0;
4827 wl->ap_ps_map = 0; 5031 wl->ap_ps_map = 0;
4828 wl->ap_fw_ps_map = 0; 5032 wl->ap_fw_ps_map = 0;
4829 wl->quirks = 0; 5033 wl->quirks = 0;
4830 wl->platform_quirks = 0; 5034 wl->platform_quirks = 0;
4831 wl->sched_scanning = false; 5035 wl->sched_scanning = false;
4832 wl->tx_security_seq = 0;
4833 wl->tx_security_last_seq_lsb = 0;
4834 wl->tx_spare_blocks = TX_HW_BLOCK_SPARE_DEFAULT; 5036 wl->tx_spare_blocks = TX_HW_BLOCK_SPARE_DEFAULT;
4835 wl->role_id = WL12XX_INVALID_ROLE_ID;
4836 wl->system_hlid = WL12XX_SYSTEM_HLID; 5037 wl->system_hlid = WL12XX_SYSTEM_HLID;
4837 wl->sta_hlid = WL12XX_INVALID_LINK_ID;
4838 wl->dev_role_id = WL12XX_INVALID_ROLE_ID;
4839 wl->dev_hlid = WL12XX_INVALID_LINK_ID;
4840 wl->session_counter = 0;
4841 wl->ap_bcast_hlid = WL12XX_INVALID_LINK_ID;
4842 wl->ap_global_hlid = WL12XX_INVALID_LINK_ID;
4843 wl->active_sta_count = 0; 5038 wl->active_sta_count = 0;
4844 setup_timer(&wl->rx_streaming_timer, wl1271_rx_streaming_timer,
4845 (unsigned long) wl);
4846 wl->fwlog_size = 0; 5039 wl->fwlog_size = 0;
4847 init_waitqueue_head(&wl->fwlog_waitq); 5040 init_waitqueue_head(&wl->fwlog_waitq);
4848 5041
@@ -4860,8 +5053,6 @@ struct ieee80211_hw *wl1271_alloc_hw(void)
4860 5053
4861 /* Apply default driver configuration. */ 5054 /* Apply default driver configuration. */
4862 wl1271_conf_init(wl); 5055 wl1271_conf_init(wl);
4863 wl->bitrate_masks[IEEE80211_BAND_2GHZ] = wl->conf.tx.basic_rate;
4864 wl->bitrate_masks[IEEE80211_BAND_5GHZ] = wl->conf.tx.basic_rate_5;
4865 5056
4866 order = get_order(WL1271_AGGR_BUFFER_SIZE); 5057 order = get_order(WL1271_AGGR_BUFFER_SIZE);
4867 wl->aggr_buf = (u8 *)__get_free_pages(GFP_KERNEL, order); 5058 wl->aggr_buf = (u8 *)__get_free_pages(GFP_KERNEL, order);
@@ -4883,49 +5074,8 @@ struct ieee80211_hw *wl1271_alloc_hw(void)
4883 goto err_dummy_packet; 5074 goto err_dummy_packet;
4884 } 5075 }
4885 5076
4886 /* Register platform device */
4887 ret = platform_device_register(wl->plat_dev);
4888 if (ret) {
4889 wl1271_error("couldn't register platform device");
4890 goto err_fwlog;
4891 }
4892 dev_set_drvdata(&wl->plat_dev->dev, wl);
4893
4894 /* Create sysfs file to control bt coex state */
4895 ret = device_create_file(&wl->plat_dev->dev, &dev_attr_bt_coex_state);
4896 if (ret < 0) {
4897 wl1271_error("failed to create sysfs file bt_coex_state");
4898 goto err_platform;
4899 }
4900
4901 /* Create sysfs file to get HW PG version */
4902 ret = device_create_file(&wl->plat_dev->dev, &dev_attr_hw_pg_ver);
4903 if (ret < 0) {
4904 wl1271_error("failed to create sysfs file hw_pg_ver");
4905 goto err_bt_coex_state;
4906 }
4907
4908 /* Create sysfs file for the FW log */
4909 ret = device_create_bin_file(&wl->plat_dev->dev, &fwlog_attr);
4910 if (ret < 0) {
4911 wl1271_error("failed to create sysfs file fwlog");
4912 goto err_hw_pg_ver;
4913 }
4914
4915 return hw; 5077 return hw;
4916 5078
4917err_hw_pg_ver:
4918 device_remove_file(&wl->plat_dev->dev, &dev_attr_hw_pg_ver);
4919
4920err_bt_coex_state:
4921 device_remove_file(&wl->plat_dev->dev, &dev_attr_bt_coex_state);
4922
4923err_platform:
4924 platform_device_unregister(wl->plat_dev);
4925
4926err_fwlog:
4927 free_page((unsigned long)wl->fwlog);
4928
4929err_dummy_packet: 5079err_dummy_packet:
4930 dev_kfree_skb(wl->dummy_packet); 5080 dev_kfree_skb(wl->dummy_packet);
4931 5081
@@ -4937,18 +5087,14 @@ err_wq:
4937 5087
4938err_hw: 5088err_hw:
4939 wl1271_debugfs_exit(wl); 5089 wl1271_debugfs_exit(wl);
4940 kfree(plat_dev);
4941
4942err_plat_alloc:
4943 ieee80211_free_hw(hw); 5090 ieee80211_free_hw(hw);
4944 5091
4945err_hw_alloc: 5092err_hw_alloc:
4946 5093
4947 return ERR_PTR(ret); 5094 return ERR_PTR(ret);
4948} 5095}
4949EXPORT_SYMBOL_GPL(wl1271_alloc_hw);
4950 5096
4951int wl1271_free_hw(struct wl1271 *wl) 5097static int wl1271_free_hw(struct wl1271 *wl)
4952{ 5098{
4953 /* Unblock any fwlog readers */ 5099 /* Unblock any fwlog readers */
4954 mutex_lock(&wl->mutex); 5100 mutex_lock(&wl->mutex);
@@ -4956,17 +5102,15 @@ int wl1271_free_hw(struct wl1271 *wl)
4956 wake_up_interruptible_all(&wl->fwlog_waitq); 5102 wake_up_interruptible_all(&wl->fwlog_waitq);
4957 mutex_unlock(&wl->mutex); 5103 mutex_unlock(&wl->mutex);
4958 5104
4959 device_remove_bin_file(&wl->plat_dev->dev, &fwlog_attr); 5105 device_remove_bin_file(wl->dev, &fwlog_attr);
4960 5106
4961 device_remove_file(&wl->plat_dev->dev, &dev_attr_hw_pg_ver); 5107 device_remove_file(wl->dev, &dev_attr_hw_pg_ver);
4962 5108
4963 device_remove_file(&wl->plat_dev->dev, &dev_attr_bt_coex_state); 5109 device_remove_file(wl->dev, &dev_attr_bt_coex_state);
4964 platform_device_unregister(wl->plat_dev);
4965 free_page((unsigned long)wl->fwlog); 5110 free_page((unsigned long)wl->fwlog);
4966 dev_kfree_skb(wl->dummy_packet); 5111 dev_kfree_skb(wl->dummy_packet);
4967 free_pages((unsigned long)wl->aggr_buf, 5112 free_pages((unsigned long)wl->aggr_buf,
4968 get_order(WL1271_AGGR_BUFFER_SIZE)); 5113 get_order(WL1271_AGGR_BUFFER_SIZE));
4969 kfree(wl->plat_dev);
4970 5114
4971 wl1271_debugfs_exit(wl); 5115 wl1271_debugfs_exit(wl);
4972 5116
@@ -4983,7 +5127,174 @@ int wl1271_free_hw(struct wl1271 *wl)
4983 5127
4984 return 0; 5128 return 0;
4985} 5129}
4986EXPORT_SYMBOL_GPL(wl1271_free_hw); 5130
5131static irqreturn_t wl12xx_hardirq(int irq, void *cookie)
5132{
5133 struct wl1271 *wl = cookie;
5134 unsigned long flags;
5135
5136 wl1271_debug(DEBUG_IRQ, "IRQ");
5137
5138 /* complete the ELP completion */
5139 spin_lock_irqsave(&wl->wl_lock, flags);
5140 set_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags);
5141 if (wl->elp_compl) {
5142 complete(wl->elp_compl);
5143 wl->elp_compl = NULL;
5144 }
5145
5146 if (test_bit(WL1271_FLAG_SUSPENDED, &wl->flags)) {
5147 /* don't enqueue a work right now. mark it as pending */
5148 set_bit(WL1271_FLAG_PENDING_WORK, &wl->flags);
5149 wl1271_debug(DEBUG_IRQ, "should not enqueue work");
5150 disable_irq_nosync(wl->irq);
5151 pm_wakeup_event(wl->dev, 0);
5152 spin_unlock_irqrestore(&wl->wl_lock, flags);
5153 return IRQ_HANDLED;
5154 }
5155 spin_unlock_irqrestore(&wl->wl_lock, flags);
5156
5157 return IRQ_WAKE_THREAD;
5158}
5159
5160static int __devinit wl12xx_probe(struct platform_device *pdev)
5161{
5162 struct wl12xx_platform_data *pdata = pdev->dev.platform_data;
5163 struct ieee80211_hw *hw;
5164 struct wl1271 *wl;
5165 unsigned long irqflags;
5166 int ret = -ENODEV;
5167
5168 hw = wl1271_alloc_hw();
5169 if (IS_ERR(hw)) {
5170 wl1271_error("can't allocate hw");
5171 ret = PTR_ERR(hw);
5172 goto out;
5173 }
5174
5175 wl = hw->priv;
5176 wl->irq = platform_get_irq(pdev, 0);
5177 wl->ref_clock = pdata->board_ref_clock;
5178 wl->tcxo_clock = pdata->board_tcxo_clock;
5179 wl->platform_quirks = pdata->platform_quirks;
5180 wl->set_power = pdata->set_power;
5181 wl->dev = &pdev->dev;
5182 wl->if_ops = pdata->ops;
5183
5184 platform_set_drvdata(pdev, wl);
5185
5186 if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ)
5187 irqflags = IRQF_TRIGGER_RISING;
5188 else
5189 irqflags = IRQF_TRIGGER_HIGH | IRQF_ONESHOT;
5190
5191 ret = request_threaded_irq(wl->irq, wl12xx_hardirq, wl1271_irq,
5192 irqflags,
5193 pdev->name, wl);
5194 if (ret < 0) {
5195 wl1271_error("request_irq() failed: %d", ret);
5196 goto out_free_hw;
5197 }
5198
5199 ret = enable_irq_wake(wl->irq);
5200 if (!ret) {
5201 wl->irq_wake_enabled = true;
5202 device_init_wakeup(wl->dev, 1);
5203 if (pdata->pwr_in_suspend)
5204 hw->wiphy->wowlan.flags = WIPHY_WOWLAN_ANY;
5205
5206 }
5207 disable_irq(wl->irq);
5208
5209 ret = wl1271_init_ieee80211(wl);
5210 if (ret)
5211 goto out_irq;
5212
5213 ret = wl1271_register_hw(wl);
5214 if (ret)
5215 goto out_irq;
5216
5217 /* Create sysfs file to control bt coex state */
5218 ret = device_create_file(wl->dev, &dev_attr_bt_coex_state);
5219 if (ret < 0) {
5220 wl1271_error("failed to create sysfs file bt_coex_state");
5221 goto out_irq;
5222 }
5223
5224 /* Create sysfs file to get HW PG version */
5225 ret = device_create_file(wl->dev, &dev_attr_hw_pg_ver);
5226 if (ret < 0) {
5227 wl1271_error("failed to create sysfs file hw_pg_ver");
5228 goto out_bt_coex_state;
5229 }
5230
5231 /* Create sysfs file for the FW log */
5232 ret = device_create_bin_file(wl->dev, &fwlog_attr);
5233 if (ret < 0) {
5234 wl1271_error("failed to create sysfs file fwlog");
5235 goto out_hw_pg_ver;
5236 }
5237
5238 return 0;
5239
5240out_hw_pg_ver:
5241 device_remove_file(wl->dev, &dev_attr_hw_pg_ver);
5242
5243out_bt_coex_state:
5244 device_remove_file(wl->dev, &dev_attr_bt_coex_state);
5245
5246out_irq:
5247 free_irq(wl->irq, wl);
5248
5249out_free_hw:
5250 wl1271_free_hw(wl);
5251
5252out:
5253 return ret;
5254}
5255
5256static int __devexit wl12xx_remove(struct platform_device *pdev)
5257{
5258 struct wl1271 *wl = platform_get_drvdata(pdev);
5259
5260 if (wl->irq_wake_enabled) {
5261 device_init_wakeup(wl->dev, 0);
5262 disable_irq_wake(wl->irq);
5263 }
5264 wl1271_unregister_hw(wl);
5265 free_irq(wl->irq, wl);
5266 wl1271_free_hw(wl);
5267
5268 return 0;
5269}
5270
5271static const struct platform_device_id wl12xx_id_table[] __devinitconst = {
5272 { "wl12xx", 0 },
5273 { } /* Terminating Entry */
5274};
5275MODULE_DEVICE_TABLE(platform, wl12xx_id_table);
5276
5277static struct platform_driver wl12xx_driver = {
5278 .probe = wl12xx_probe,
5279 .remove = __devexit_p(wl12xx_remove),
5280 .id_table = wl12xx_id_table,
5281 .driver = {
5282 .name = "wl12xx_driver",
5283 .owner = THIS_MODULE,
5284 }
5285};
5286
5287static int __init wl12xx_init(void)
5288{
5289 return platform_driver_register(&wl12xx_driver);
5290}
5291module_init(wl12xx_init);
5292
5293static void __exit wl12xx_exit(void)
5294{
5295 platform_driver_unregister(&wl12xx_driver);
5296}
5297module_exit(wl12xx_exit);
4987 5298
4988u32 wl12xx_debug_level = DEBUG_NONE; 5299u32 wl12xx_debug_level = DEBUG_NONE;
4989EXPORT_SYMBOL_GPL(wl12xx_debug_level); 5300EXPORT_SYMBOL_GPL(wl12xx_debug_level);
diff --git a/drivers/net/wireless/wl12xx/ps.c b/drivers/net/wireless/wl12xx/ps.c
index c15ebf2efd4..a7a11088dd3 100644
--- a/drivers/net/wireless/wl12xx/ps.c
+++ b/drivers/net/wireless/wl12xx/ps.c
@@ -25,6 +25,7 @@
25#include "ps.h" 25#include "ps.h"
26#include "io.h" 26#include "io.h"
27#include "tx.h" 27#include "tx.h"
28#include "debug.h"
28 29
29#define WL1271_WAKEUP_TIMEOUT 500 30#define WL1271_WAKEUP_TIMEOUT 500
30 31
@@ -32,6 +33,7 @@ void wl1271_elp_work(struct work_struct *work)
32{ 33{
33 struct delayed_work *dwork; 34 struct delayed_work *dwork;
34 struct wl1271 *wl; 35 struct wl1271 *wl;
36 struct wl12xx_vif *wlvif;
35 37
36 dwork = container_of(work, struct delayed_work, work); 38 dwork = container_of(work, struct delayed_work, work);
37 wl = container_of(dwork, struct wl1271, elp_work); 39 wl = container_of(dwork, struct wl1271, elp_work);
@@ -47,11 +49,15 @@ void wl1271_elp_work(struct work_struct *work)
47 if (unlikely(!test_bit(WL1271_FLAG_ELP_REQUESTED, &wl->flags))) 49 if (unlikely(!test_bit(WL1271_FLAG_ELP_REQUESTED, &wl->flags)))
48 goto out; 50 goto out;
49 51
50 if (test_bit(WL1271_FLAG_IN_ELP, &wl->flags) || 52 if (test_bit(WL1271_FLAG_IN_ELP, &wl->flags))
51 (!test_bit(WL1271_FLAG_PSM, &wl->flags) &&
52 !test_bit(WL1271_FLAG_IDLE, &wl->flags)))
53 goto out; 53 goto out;
54 54
55 wl12xx_for_each_wlvif(wl, wlvif) {
56 if (!test_bit(WLVIF_FLAG_PSM, &wlvif->flags) &&
57 !test_bit(WL1271_FLAG_IDLE, &wl->flags))
58 goto out;
59 }
60
55 wl1271_debug(DEBUG_PSM, "chip to elp"); 61 wl1271_debug(DEBUG_PSM, "chip to elp");
56 wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_SLEEP); 62 wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_SLEEP);
57 set_bit(WL1271_FLAG_IN_ELP, &wl->flags); 63 set_bit(WL1271_FLAG_IN_ELP, &wl->flags);
@@ -65,13 +71,17 @@ out:
65/* Routines to toggle sleep mode while in ELP */ 71/* Routines to toggle sleep mode while in ELP */
66void wl1271_ps_elp_sleep(struct wl1271 *wl) 72void wl1271_ps_elp_sleep(struct wl1271 *wl)
67{ 73{
74 struct wl12xx_vif *wlvif;
75
68 /* we shouldn't get consecutive sleep requests */ 76 /* we shouldn't get consecutive sleep requests */
69 if (WARN_ON(test_and_set_bit(WL1271_FLAG_ELP_REQUESTED, &wl->flags))) 77 if (WARN_ON(test_and_set_bit(WL1271_FLAG_ELP_REQUESTED, &wl->flags)))
70 return; 78 return;
71 79
72 if (!test_bit(WL1271_FLAG_PSM, &wl->flags) && 80 wl12xx_for_each_wlvif(wl, wlvif) {
73 !test_bit(WL1271_FLAG_IDLE, &wl->flags)) 81 if (!test_bit(WLVIF_FLAG_PSM, &wlvif->flags) &&
74 return; 82 !test_bit(WL1271_FLAG_IDLE, &wl->flags))
83 return;
84 }
75 85
76 ieee80211_queue_delayed_work(wl->hw, &wl->elp_work, 86 ieee80211_queue_delayed_work(wl->hw, &wl->elp_work,
77 msecs_to_jiffies(ELP_ENTRY_DELAY)); 87 msecs_to_jiffies(ELP_ENTRY_DELAY));
@@ -143,8 +153,8 @@ out:
143 return 0; 153 return 0;
144} 154}
145 155
146int wl1271_ps_set_mode(struct wl1271 *wl, enum wl1271_cmd_ps_mode mode, 156int wl1271_ps_set_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif,
147 u32 rates, bool send) 157 enum wl1271_cmd_ps_mode mode, u32 rates, bool send)
148{ 158{
149 int ret; 159 int ret;
150 160
@@ -152,39 +162,34 @@ int wl1271_ps_set_mode(struct wl1271 *wl, enum wl1271_cmd_ps_mode mode,
152 case STATION_POWER_SAVE_MODE: 162 case STATION_POWER_SAVE_MODE:
153 wl1271_debug(DEBUG_PSM, "entering psm"); 163 wl1271_debug(DEBUG_PSM, "entering psm");
154 164
155 ret = wl1271_acx_wake_up_conditions(wl); 165 ret = wl1271_acx_wake_up_conditions(wl, wlvif);
156 if (ret < 0) { 166 if (ret < 0) {
157 wl1271_error("couldn't set wake up conditions"); 167 wl1271_error("couldn't set wake up conditions");
158 return ret; 168 return ret;
159 } 169 }
160 170
161 ret = wl1271_cmd_ps_mode(wl, STATION_POWER_SAVE_MODE); 171 ret = wl1271_cmd_ps_mode(wl, wlvif, STATION_POWER_SAVE_MODE);
162 if (ret < 0) 172 if (ret < 0)
163 return ret; 173 return ret;
164 174
165 set_bit(WL1271_FLAG_PSM, &wl->flags); 175 set_bit(WLVIF_FLAG_PSM, &wlvif->flags);
166 break; 176 break;
167 case STATION_ACTIVE_MODE: 177 case STATION_ACTIVE_MODE:
168 default: 178 default:
169 wl1271_debug(DEBUG_PSM, "leaving psm"); 179 wl1271_debug(DEBUG_PSM, "leaving psm");
170 180
171 /* disable beacon early termination */ 181 /* disable beacon early termination */
172 if (wl->band == IEEE80211_BAND_2GHZ) { 182 if (wlvif->band == IEEE80211_BAND_2GHZ) {
173 ret = wl1271_acx_bet_enable(wl, false); 183 ret = wl1271_acx_bet_enable(wl, wlvif, false);
174 if (ret < 0) 184 if (ret < 0)
175 return ret; 185 return ret;
176 } 186 }
177 187
178 /* disable beacon filtering */ 188 ret = wl1271_cmd_ps_mode(wl, wlvif, STATION_ACTIVE_MODE);
179 ret = wl1271_acx_beacon_filter_opt(wl, false);
180 if (ret < 0)
181 return ret;
182
183 ret = wl1271_cmd_ps_mode(wl, STATION_ACTIVE_MODE);
184 if (ret < 0) 189 if (ret < 0)
185 return ret; 190 return ret;
186 191
187 clear_bit(WL1271_FLAG_PSM, &wl->flags); 192 clear_bit(WLVIF_FLAG_PSM, &wlvif->flags);
188 break; 193 break;
189 } 194 }
190 195
@@ -223,9 +228,11 @@ static void wl1271_ps_filter_frames(struct wl1271 *wl, u8 hlid)
223 wl1271_handle_tx_low_watermark(wl); 228 wl1271_handle_tx_low_watermark(wl);
224} 229}
225 230
226void wl1271_ps_link_start(struct wl1271 *wl, u8 hlid, bool clean_queues) 231void wl12xx_ps_link_start(struct wl1271 *wl, struct wl12xx_vif *wlvif,
232 u8 hlid, bool clean_queues)
227{ 233{
228 struct ieee80211_sta *sta; 234 struct ieee80211_sta *sta;
235 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
229 236
230 if (test_bit(hlid, &wl->ap_ps_map)) 237 if (test_bit(hlid, &wl->ap_ps_map))
231 return; 238 return;
@@ -235,7 +242,7 @@ void wl1271_ps_link_start(struct wl1271 *wl, u8 hlid, bool clean_queues)
235 clean_queues); 242 clean_queues);
236 243
237 rcu_read_lock(); 244 rcu_read_lock();
238 sta = ieee80211_find_sta(wl->vif, wl->links[hlid].addr); 245 sta = ieee80211_find_sta(vif, wl->links[hlid].addr);
239 if (!sta) { 246 if (!sta) {
240 wl1271_error("could not find sta %pM for starting ps", 247 wl1271_error("could not find sta %pM for starting ps",
241 wl->links[hlid].addr); 248 wl->links[hlid].addr);
@@ -253,9 +260,10 @@ void wl1271_ps_link_start(struct wl1271 *wl, u8 hlid, bool clean_queues)
253 __set_bit(hlid, &wl->ap_ps_map); 260 __set_bit(hlid, &wl->ap_ps_map);
254} 261}
255 262
256void wl1271_ps_link_end(struct wl1271 *wl, u8 hlid) 263void wl12xx_ps_link_end(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 hlid)
257{ 264{
258 struct ieee80211_sta *sta; 265 struct ieee80211_sta *sta;
266 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
259 267
260 if (!test_bit(hlid, &wl->ap_ps_map)) 268 if (!test_bit(hlid, &wl->ap_ps_map))
261 return; 269 return;
@@ -265,7 +273,7 @@ void wl1271_ps_link_end(struct wl1271 *wl, u8 hlid)
265 __clear_bit(hlid, &wl->ap_ps_map); 273 __clear_bit(hlid, &wl->ap_ps_map);
266 274
267 rcu_read_lock(); 275 rcu_read_lock();
268 sta = ieee80211_find_sta(wl->vif, wl->links[hlid].addr); 276 sta = ieee80211_find_sta(vif, wl->links[hlid].addr);
269 if (!sta) { 277 if (!sta) {
270 wl1271_error("could not find sta %pM for ending ps", 278 wl1271_error("could not find sta %pM for ending ps",
271 wl->links[hlid].addr); 279 wl->links[hlid].addr);
diff --git a/drivers/net/wireless/wl12xx/ps.h b/drivers/net/wireless/wl12xx/ps.h
index 25eb9bc9b62..a12052f0202 100644
--- a/drivers/net/wireless/wl12xx/ps.h
+++ b/drivers/net/wireless/wl12xx/ps.h
@@ -27,13 +27,14 @@
27#include "wl12xx.h" 27#include "wl12xx.h"
28#include "acx.h" 28#include "acx.h"
29 29
30int wl1271_ps_set_mode(struct wl1271 *wl, enum wl1271_cmd_ps_mode mode, 30int wl1271_ps_set_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif,
31 u32 rates, bool send); 31 enum wl1271_cmd_ps_mode mode, u32 rates, bool send);
32void wl1271_ps_elp_sleep(struct wl1271 *wl); 32void wl1271_ps_elp_sleep(struct wl1271 *wl);
33int wl1271_ps_elp_wakeup(struct wl1271 *wl); 33int wl1271_ps_elp_wakeup(struct wl1271 *wl);
34void wl1271_elp_work(struct work_struct *work); 34void wl1271_elp_work(struct work_struct *work);
35void wl1271_ps_link_start(struct wl1271 *wl, u8 hlid, bool clean_queues); 35void wl12xx_ps_link_start(struct wl1271 *wl, struct wl12xx_vif *wlvif,
36void wl1271_ps_link_end(struct wl1271 *wl, u8 hlid); 36 u8 hlid, bool clean_queues);
37void wl12xx_ps_link_end(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 hlid);
37 38
38#define WL1271_PS_COMPLETE_TIMEOUT 500 39#define WL1271_PS_COMPLETE_TIMEOUT 500
39 40
diff --git a/drivers/net/wireless/wl12xx/reg.h b/drivers/net/wireless/wl12xx/reg.h
index 3f570f39758..df34d5977b9 100644
--- a/drivers/net/wireless/wl12xx/reg.h
+++ b/drivers/net/wireless/wl12xx/reg.h
@@ -408,7 +408,7 @@
408 408
409 409
410/* Firmware image load chunk size */ 410/* Firmware image load chunk size */
411#define CHUNK_SIZE 512 411#define CHUNK_SIZE 16384
412 412
413/* Firmware image header size */ 413/* Firmware image header size */
414#define FW_HDR_SIZE 8 414#define FW_HDR_SIZE 8
diff --git a/drivers/net/wireless/wl12xx/rx.c b/drivers/net/wireless/wl12xx/rx.c
index dee4cfe9ccc..8c277c0cb37 100644
--- a/drivers/net/wireless/wl12xx/rx.c
+++ b/drivers/net/wireless/wl12xx/rx.c
@@ -25,9 +25,11 @@
25#include <linux/sched.h> 25#include <linux/sched.h>
26 26
27#include "wl12xx.h" 27#include "wl12xx.h"
28#include "debug.h"
28#include "acx.h" 29#include "acx.h"
29#include "reg.h" 30#include "reg.h"
30#include "rx.h" 31#include "rx.h"
32#include "tx.h"
31#include "io.h" 33#include "io.h"
32 34
33static u8 wl12xx_rx_get_mem_block(struct wl12xx_fw_status *status, 35static u8 wl12xx_rx_get_mem_block(struct wl12xx_fw_status *status,
@@ -96,7 +98,7 @@ static void wl1271_rx_status(struct wl1271 *wl,
96} 98}
97 99
98static int wl1271_rx_handle_data(struct wl1271 *wl, u8 *data, u32 length, 100static int wl1271_rx_handle_data(struct wl1271 *wl, u8 *data, u32 length,
99 bool unaligned) 101 bool unaligned, u8 *hlid)
100{ 102{
101 struct wl1271_rx_descriptor *desc; 103 struct wl1271_rx_descriptor *desc;
102 struct sk_buff *skb; 104 struct sk_buff *skb;
@@ -159,6 +161,7 @@ static int wl1271_rx_handle_data(struct wl1271 *wl, u8 *data, u32 length,
159 * payload aligned to 4 bytes. 161 * payload aligned to 4 bytes.
160 */ 162 */
161 memcpy(buf, data + sizeof(*desc), length - sizeof(*desc)); 163 memcpy(buf, data + sizeof(*desc), length - sizeof(*desc));
164 *hlid = desc->hlid;
162 165
163 hdr = (struct ieee80211_hdr *)skb->data; 166 hdr = (struct ieee80211_hdr *)skb->data;
164 if (ieee80211_is_beacon(hdr->frame_control)) 167 if (ieee80211_is_beacon(hdr->frame_control))
@@ -169,10 +172,10 @@ static int wl1271_rx_handle_data(struct wl1271 *wl, u8 *data, u32 length,
169 wl1271_rx_status(wl, desc, IEEE80211_SKB_RXCB(skb), beacon); 172 wl1271_rx_status(wl, desc, IEEE80211_SKB_RXCB(skb), beacon);
170 173
171 seq_num = (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4; 174 seq_num = (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4;
172 wl1271_debug(DEBUG_RX, "rx skb 0x%p: %d B %s seq %d", skb, 175 wl1271_debug(DEBUG_RX, "rx skb 0x%p: %d B %s seq %d hlid %d", skb,
173 skb->len - desc->pad_len, 176 skb->len - desc->pad_len,
174 beacon ? "beacon" : "", 177 beacon ? "beacon" : "",
175 seq_num); 178 seq_num, *hlid);
176 179
177 skb_trim(skb, skb->len - desc->pad_len); 180 skb_trim(skb, skb->len - desc->pad_len);
178 181
@@ -185,6 +188,7 @@ static int wl1271_rx_handle_data(struct wl1271 *wl, u8 *data, u32 length,
185void wl12xx_rx(struct wl1271 *wl, struct wl12xx_fw_status *status) 188void wl12xx_rx(struct wl1271 *wl, struct wl12xx_fw_status *status)
186{ 189{
187 struct wl1271_acx_mem_map *wl_mem_map = wl->target_mem_map; 190 struct wl1271_acx_mem_map *wl_mem_map = wl->target_mem_map;
191 unsigned long active_hlids[BITS_TO_LONGS(WL12XX_MAX_LINKS)] = {0};
188 u32 buf_size; 192 u32 buf_size;
189 u32 fw_rx_counter = status->fw_rx_counter & NUM_RX_PKT_DESC_MOD_MASK; 193 u32 fw_rx_counter = status->fw_rx_counter & NUM_RX_PKT_DESC_MOD_MASK;
190 u32 drv_rx_counter = wl->rx_counter & NUM_RX_PKT_DESC_MOD_MASK; 194 u32 drv_rx_counter = wl->rx_counter & NUM_RX_PKT_DESC_MOD_MASK;
@@ -192,8 +196,7 @@ void wl12xx_rx(struct wl1271 *wl, struct wl12xx_fw_status *status)
192 u32 mem_block; 196 u32 mem_block;
193 u32 pkt_length; 197 u32 pkt_length;
194 u32 pkt_offset; 198 u32 pkt_offset;
195 bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS); 199 u8 hlid;
196 bool had_data = false;
197 bool unaligned = false; 200 bool unaligned = false;
198 201
199 while (drv_rx_counter != fw_rx_counter) { 202 while (drv_rx_counter != fw_rx_counter) {
@@ -253,8 +256,11 @@ void wl12xx_rx(struct wl1271 *wl, struct wl12xx_fw_status *status)
253 */ 256 */
254 if (wl1271_rx_handle_data(wl, 257 if (wl1271_rx_handle_data(wl,
255 wl->aggr_buf + pkt_offset, 258 wl->aggr_buf + pkt_offset,
256 pkt_length, unaligned) == 1) 259 pkt_length, unaligned,
257 had_data = true; 260 &hlid) == 1) {
261 WARN_ON(hlid >= WL12XX_MAX_LINKS);
262 __set_bit(hlid, active_hlids);
263 }
258 264
259 wl->rx_counter++; 265 wl->rx_counter++;
260 drv_rx_counter++; 266 drv_rx_counter++;
@@ -270,17 +276,5 @@ void wl12xx_rx(struct wl1271 *wl, struct wl12xx_fw_status *status)
270 if (wl->quirks & WL12XX_QUIRK_END_OF_TRANSACTION) 276 if (wl->quirks & WL12XX_QUIRK_END_OF_TRANSACTION)
271 wl1271_write32(wl, RX_DRIVER_COUNTER_ADDRESS, wl->rx_counter); 277 wl1271_write32(wl, RX_DRIVER_COUNTER_ADDRESS, wl->rx_counter);
272 278
273 if (!is_ap && wl->conf.rx_streaming.interval && had_data && 279 wl12xx_rearm_rx_streaming(wl, active_hlids);
274 (wl->conf.rx_streaming.always ||
275 test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags))) {
276 u32 timeout = wl->conf.rx_streaming.duration;
277
278 /* restart rx streaming */
279 if (!test_bit(WL1271_FLAG_RX_STREAMING_STARTED, &wl->flags))
280 ieee80211_queue_work(wl->hw,
281 &wl->rx_streaming_enable_work);
282
283 mod_timer(&wl->rx_streaming_timer,
284 jiffies + msecs_to_jiffies(timeout));
285 }
286} 280}
diff --git a/drivers/net/wireless/wl12xx/scan.c b/drivers/net/wireless/wl12xx/scan.c
index fc29c671cf3..8599dab1fe2 100644
--- a/drivers/net/wireless/wl12xx/scan.c
+++ b/drivers/net/wireless/wl12xx/scan.c
@@ -24,6 +24,7 @@
24#include <linux/ieee80211.h> 24#include <linux/ieee80211.h>
25 25
26#include "wl12xx.h" 26#include "wl12xx.h"
27#include "debug.h"
27#include "cmd.h" 28#include "cmd.h"
28#include "scan.h" 29#include "scan.h"
29#include "acx.h" 30#include "acx.h"
@@ -34,6 +35,8 @@ void wl1271_scan_complete_work(struct work_struct *work)
34{ 35{
35 struct delayed_work *dwork; 36 struct delayed_work *dwork;
36 struct wl1271 *wl; 37 struct wl1271 *wl;
38 struct ieee80211_vif *vif;
39 struct wl12xx_vif *wlvif;
37 int ret; 40 int ret;
38 bool is_sta, is_ibss; 41 bool is_sta, is_ibss;
39 42
@@ -50,28 +53,31 @@ void wl1271_scan_complete_work(struct work_struct *work)
50 if (wl->scan.state == WL1271_SCAN_STATE_IDLE) 53 if (wl->scan.state == WL1271_SCAN_STATE_IDLE)
51 goto out; 54 goto out;
52 55
56 vif = wl->scan_vif;
57 wlvif = wl12xx_vif_to_data(vif);
58
53 wl->scan.state = WL1271_SCAN_STATE_IDLE; 59 wl->scan.state = WL1271_SCAN_STATE_IDLE;
54 memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch)); 60 memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
55 wl->scan.req = NULL; 61 wl->scan.req = NULL;
62 wl->scan_vif = NULL;
56 63
57 ret = wl1271_ps_elp_wakeup(wl); 64 ret = wl1271_ps_elp_wakeup(wl);
58 if (ret < 0) 65 if (ret < 0)
59 goto out; 66 goto out;
60 67
61 if (test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) { 68 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) {
62 /* restore hardware connection monitoring template */ 69 /* restore hardware connection monitoring template */
63 wl1271_cmd_build_ap_probe_req(wl, wl->probereq); 70 wl1271_cmd_build_ap_probe_req(wl, wlvif, wlvif->probereq);
64 } 71 }
65 72
66 /* return to ROC if needed */ 73 /* return to ROC if needed */
67 is_sta = (wl->bss_type == BSS_TYPE_STA_BSS); 74 is_sta = (wlvif->bss_type == BSS_TYPE_STA_BSS);
68 is_ibss = (wl->bss_type == BSS_TYPE_IBSS); 75 is_ibss = (wlvif->bss_type == BSS_TYPE_IBSS);
69 if (((is_sta && !test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) || 76 if (((is_sta && !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) ||
70 (is_ibss && !test_bit(WL1271_FLAG_IBSS_JOINED, &wl->flags))) && 77 (is_ibss && !test_bit(WLVIF_FLAG_IBSS_JOINED, &wlvif->flags))) &&
71 !test_bit(wl->dev_role_id, wl->roc_map)) { 78 !test_bit(wlvif->dev_role_id, wl->roc_map)) {
72 /* restore remain on channel */ 79 /* restore remain on channel */
73 wl12xx_cmd_role_start_dev(wl); 80 wl12xx_start_dev(wl, wlvif);
74 wl12xx_roc(wl, wl->dev_role_id);
75 } 81 }
76 wl1271_ps_elp_sleep(wl); 82 wl1271_ps_elp_sleep(wl);
77 83
@@ -155,9 +161,11 @@ static int wl1271_get_scan_channels(struct wl1271 *wl,
155 161
156#define WL1271_NOTHING_TO_SCAN 1 162#define WL1271_NOTHING_TO_SCAN 1
157 163
158static int wl1271_scan_send(struct wl1271 *wl, enum ieee80211_band band, 164static int wl1271_scan_send(struct wl1271 *wl, struct ieee80211_vif *vif,
159 bool passive, u32 basic_rate) 165 enum ieee80211_band band,
166 bool passive, u32 basic_rate)
160{ 167{
168 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
161 struct wl1271_cmd_scan *cmd; 169 struct wl1271_cmd_scan *cmd;
162 struct wl1271_cmd_trigger_scan_to *trigger; 170 struct wl1271_cmd_trigger_scan_to *trigger;
163 int ret; 171 int ret;
@@ -177,11 +185,11 @@ static int wl1271_scan_send(struct wl1271 *wl, enum ieee80211_band band,
177 if (passive) 185 if (passive)
178 scan_options |= WL1271_SCAN_OPT_PASSIVE; 186 scan_options |= WL1271_SCAN_OPT_PASSIVE;
179 187
180 if (WARN_ON(wl->role_id == WL12XX_INVALID_ROLE_ID)) { 188 if (WARN_ON(wlvif->role_id == WL12XX_INVALID_ROLE_ID)) {
181 ret = -EINVAL; 189 ret = -EINVAL;
182 goto out; 190 goto out;
183 } 191 }
184 cmd->params.role_id = wl->role_id; 192 cmd->params.role_id = wlvif->role_id;
185 cmd->params.scan_options = cpu_to_le16(scan_options); 193 cmd->params.scan_options = cpu_to_le16(scan_options);
186 194
187 cmd->params.n_ch = wl1271_get_scan_channels(wl, wl->scan.req, 195 cmd->params.n_ch = wl1271_get_scan_channels(wl, wl->scan.req,
@@ -194,7 +202,6 @@ static int wl1271_scan_send(struct wl1271 *wl, enum ieee80211_band band,
194 202
195 cmd->params.tx_rate = cpu_to_le32(basic_rate); 203 cmd->params.tx_rate = cpu_to_le32(basic_rate);
196 cmd->params.n_probe_reqs = wl->conf.scan.num_probe_reqs; 204 cmd->params.n_probe_reqs = wl->conf.scan.num_probe_reqs;
197 cmd->params.tx_rate = cpu_to_le32(basic_rate);
198 cmd->params.tid_trigger = 0; 205 cmd->params.tid_trigger = 0;
199 cmd->params.scan_tag = WL1271_SCAN_DEFAULT_TAG; 206 cmd->params.scan_tag = WL1271_SCAN_DEFAULT_TAG;
200 207
@@ -208,11 +215,11 @@ static int wl1271_scan_send(struct wl1271 *wl, enum ieee80211_band band,
208 memcpy(cmd->params.ssid, wl->scan.ssid, wl->scan.ssid_len); 215 memcpy(cmd->params.ssid, wl->scan.ssid, wl->scan.ssid_len);
209 } 216 }
210 217
211 memcpy(cmd->addr, wl->mac_addr, ETH_ALEN); 218 memcpy(cmd->addr, vif->addr, ETH_ALEN);
212 219
213 ret = wl1271_cmd_build_probe_req(wl, wl->scan.ssid, wl->scan.ssid_len, 220 ret = wl1271_cmd_build_probe_req(wl, wlvif, wl->scan.ssid,
214 wl->scan.req->ie, wl->scan.req->ie_len, 221 wl->scan.ssid_len, wl->scan.req->ie,
215 band); 222 wl->scan.req->ie_len, band);
216 if (ret < 0) { 223 if (ret < 0) {
217 wl1271_error("PROBE request template failed"); 224 wl1271_error("PROBE request template failed");
218 goto out; 225 goto out;
@@ -241,11 +248,12 @@ out:
241 return ret; 248 return ret;
242} 249}
243 250
244void wl1271_scan_stm(struct wl1271 *wl) 251void wl1271_scan_stm(struct wl1271 *wl, struct ieee80211_vif *vif)
245{ 252{
253 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
246 int ret = 0; 254 int ret = 0;
247 enum ieee80211_band band; 255 enum ieee80211_band band;
248 u32 rate; 256 u32 rate, mask;
249 257
250 switch (wl->scan.state) { 258 switch (wl->scan.state) {
251 case WL1271_SCAN_STATE_IDLE: 259 case WL1271_SCAN_STATE_IDLE:
@@ -253,47 +261,59 @@ void wl1271_scan_stm(struct wl1271 *wl)
253 261
254 case WL1271_SCAN_STATE_2GHZ_ACTIVE: 262 case WL1271_SCAN_STATE_2GHZ_ACTIVE:
255 band = IEEE80211_BAND_2GHZ; 263 band = IEEE80211_BAND_2GHZ;
256 rate = wl1271_tx_min_rate_get(wl, wl->bitrate_masks[band]); 264 mask = wlvif->bitrate_masks[band];
257 ret = wl1271_scan_send(wl, band, false, rate); 265 if (wl->scan.req->no_cck) {
266 mask &= ~CONF_TX_CCK_RATES;
267 if (!mask)
268 mask = CONF_TX_RATE_MASK_BASIC_P2P;
269 }
270 rate = wl1271_tx_min_rate_get(wl, mask);
271 ret = wl1271_scan_send(wl, vif, band, false, rate);
258 if (ret == WL1271_NOTHING_TO_SCAN) { 272 if (ret == WL1271_NOTHING_TO_SCAN) {
259 wl->scan.state = WL1271_SCAN_STATE_2GHZ_PASSIVE; 273 wl->scan.state = WL1271_SCAN_STATE_2GHZ_PASSIVE;
260 wl1271_scan_stm(wl); 274 wl1271_scan_stm(wl, vif);
261 } 275 }
262 276
263 break; 277 break;
264 278
265 case WL1271_SCAN_STATE_2GHZ_PASSIVE: 279 case WL1271_SCAN_STATE_2GHZ_PASSIVE:
266 band = IEEE80211_BAND_2GHZ; 280 band = IEEE80211_BAND_2GHZ;
267 rate = wl1271_tx_min_rate_get(wl, wl->bitrate_masks[band]); 281 mask = wlvif->bitrate_masks[band];
268 ret = wl1271_scan_send(wl, band, true, rate); 282 if (wl->scan.req->no_cck) {
283 mask &= ~CONF_TX_CCK_RATES;
284 if (!mask)
285 mask = CONF_TX_RATE_MASK_BASIC_P2P;
286 }
287 rate = wl1271_tx_min_rate_get(wl, mask);
288 ret = wl1271_scan_send(wl, vif, band, true, rate);
269 if (ret == WL1271_NOTHING_TO_SCAN) { 289 if (ret == WL1271_NOTHING_TO_SCAN) {
270 if (wl->enable_11a) 290 if (wl->enable_11a)
271 wl->scan.state = WL1271_SCAN_STATE_5GHZ_ACTIVE; 291 wl->scan.state = WL1271_SCAN_STATE_5GHZ_ACTIVE;
272 else 292 else
273 wl->scan.state = WL1271_SCAN_STATE_DONE; 293 wl->scan.state = WL1271_SCAN_STATE_DONE;
274 wl1271_scan_stm(wl); 294 wl1271_scan_stm(wl, vif);
275 } 295 }
276 296
277 break; 297 break;
278 298
279 case WL1271_SCAN_STATE_5GHZ_ACTIVE: 299 case WL1271_SCAN_STATE_5GHZ_ACTIVE:
280 band = IEEE80211_BAND_5GHZ; 300 band = IEEE80211_BAND_5GHZ;
281 rate = wl1271_tx_min_rate_get(wl, wl->bitrate_masks[band]); 301 rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[band]);
282 ret = wl1271_scan_send(wl, band, false, rate); 302 ret = wl1271_scan_send(wl, vif, band, false, rate);
283 if (ret == WL1271_NOTHING_TO_SCAN) { 303 if (ret == WL1271_NOTHING_TO_SCAN) {
284 wl->scan.state = WL1271_SCAN_STATE_5GHZ_PASSIVE; 304 wl->scan.state = WL1271_SCAN_STATE_5GHZ_PASSIVE;
285 wl1271_scan_stm(wl); 305 wl1271_scan_stm(wl, vif);
286 } 306 }
287 307
288 break; 308 break;
289 309
290 case WL1271_SCAN_STATE_5GHZ_PASSIVE: 310 case WL1271_SCAN_STATE_5GHZ_PASSIVE:
291 band = IEEE80211_BAND_5GHZ; 311 band = IEEE80211_BAND_5GHZ;
292 rate = wl1271_tx_min_rate_get(wl, wl->bitrate_masks[band]); 312 rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[band]);
293 ret = wl1271_scan_send(wl, band, true, rate); 313 ret = wl1271_scan_send(wl, vif, band, true, rate);
294 if (ret == WL1271_NOTHING_TO_SCAN) { 314 if (ret == WL1271_NOTHING_TO_SCAN) {
295 wl->scan.state = WL1271_SCAN_STATE_DONE; 315 wl->scan.state = WL1271_SCAN_STATE_DONE;
296 wl1271_scan_stm(wl); 316 wl1271_scan_stm(wl, vif);
297 } 317 }
298 318
299 break; 319 break;
@@ -317,7 +337,8 @@ void wl1271_scan_stm(struct wl1271 *wl)
317 } 337 }
318} 338}
319 339
320int wl1271_scan(struct wl1271 *wl, const u8 *ssid, size_t ssid_len, 340int wl1271_scan(struct wl1271 *wl, struct ieee80211_vif *vif,
341 const u8 *ssid, size_t ssid_len,
321 struct cfg80211_scan_request *req) 342 struct cfg80211_scan_request *req)
322{ 343{
323 /* 344 /*
@@ -338,6 +359,7 @@ int wl1271_scan(struct wl1271 *wl, const u8 *ssid, size_t ssid_len,
338 wl->scan.ssid_len = 0; 359 wl->scan.ssid_len = 0;
339 } 360 }
340 361
362 wl->scan_vif = vif;
341 wl->scan.req = req; 363 wl->scan.req = req;
342 memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch)); 364 memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
343 365
@@ -346,7 +368,7 @@ int wl1271_scan(struct wl1271 *wl, const u8 *ssid, size_t ssid_len,
346 ieee80211_queue_delayed_work(wl->hw, &wl->scan_complete_work, 368 ieee80211_queue_delayed_work(wl->hw, &wl->scan_complete_work,
347 msecs_to_jiffies(WL1271_SCAN_TIMEOUT)); 369 msecs_to_jiffies(WL1271_SCAN_TIMEOUT));
348 370
349 wl1271_scan_stm(wl); 371 wl1271_scan_stm(wl, vif);
350 372
351 return 0; 373 return 0;
352} 374}
@@ -550,6 +572,9 @@ wl12xx_scan_sched_scan_ssid_list(struct wl1271 *wl,
550 * so they're used in probe requests. 572 * so they're used in probe requests.
551 */ 573 */
552 for (i = 0; i < req->n_ssids; i++) { 574 for (i = 0; i < req->n_ssids; i++) {
575 if (!req->ssids[i].ssid_len)
576 continue;
577
553 for (j = 0; j < cmd->n_ssids; j++) 578 for (j = 0; j < cmd->n_ssids; j++)
554 if (!memcmp(req->ssids[i].ssid, 579 if (!memcmp(req->ssids[i].ssid,
555 cmd->ssids[j].ssid, 580 cmd->ssids[j].ssid,
@@ -585,6 +610,7 @@ out:
585} 610}
586 611
587int wl1271_scan_sched_scan_config(struct wl1271 *wl, 612int wl1271_scan_sched_scan_config(struct wl1271 *wl,
613 struct wl12xx_vif *wlvif,
588 struct cfg80211_sched_scan_request *req, 614 struct cfg80211_sched_scan_request *req,
589 struct ieee80211_sched_scan_ies *ies) 615 struct ieee80211_sched_scan_ies *ies)
590{ 616{
@@ -631,7 +657,7 @@ int wl1271_scan_sched_scan_config(struct wl1271 *wl,
631 } 657 }
632 658
633 if (!force_passive && cfg->active[0]) { 659 if (!force_passive && cfg->active[0]) {
634 ret = wl1271_cmd_build_probe_req(wl, req->ssids[0].ssid, 660 ret = wl1271_cmd_build_probe_req(wl, wlvif, req->ssids[0].ssid,
635 req->ssids[0].ssid_len, 661 req->ssids[0].ssid_len,
636 ies->ie[IEEE80211_BAND_2GHZ], 662 ies->ie[IEEE80211_BAND_2GHZ],
637 ies->len[IEEE80211_BAND_2GHZ], 663 ies->len[IEEE80211_BAND_2GHZ],
@@ -643,7 +669,7 @@ int wl1271_scan_sched_scan_config(struct wl1271 *wl,
643 } 669 }
644 670
645 if (!force_passive && cfg->active[1]) { 671 if (!force_passive && cfg->active[1]) {
646 ret = wl1271_cmd_build_probe_req(wl, req->ssids[0].ssid, 672 ret = wl1271_cmd_build_probe_req(wl, wlvif, req->ssids[0].ssid,
647 req->ssids[0].ssid_len, 673 req->ssids[0].ssid_len,
648 ies->ie[IEEE80211_BAND_5GHZ], 674 ies->ie[IEEE80211_BAND_5GHZ],
649 ies->len[IEEE80211_BAND_5GHZ], 675 ies->len[IEEE80211_BAND_5GHZ],
@@ -667,14 +693,14 @@ out:
667 return ret; 693 return ret;
668} 694}
669 695
670int wl1271_scan_sched_scan_start(struct wl1271 *wl) 696int wl1271_scan_sched_scan_start(struct wl1271 *wl, struct wl12xx_vif *wlvif)
671{ 697{
672 struct wl1271_cmd_sched_scan_start *start; 698 struct wl1271_cmd_sched_scan_start *start;
673 int ret = 0; 699 int ret = 0;
674 700
675 wl1271_debug(DEBUG_CMD, "cmd periodic scan start"); 701 wl1271_debug(DEBUG_CMD, "cmd periodic scan start");
676 702
677 if (wl->bss_type != BSS_TYPE_STA_BSS) 703 if (wlvif->bss_type != BSS_TYPE_STA_BSS)
678 return -EOPNOTSUPP; 704 return -EOPNOTSUPP;
679 705
680 if (!test_bit(WL1271_FLAG_IDLE, &wl->flags)) 706 if (!test_bit(WL1271_FLAG_IDLE, &wl->flags))
diff --git a/drivers/net/wireless/wl12xx/scan.h b/drivers/net/wireless/wl12xx/scan.h
index 92115156522..a7ed43dc08c 100644
--- a/drivers/net/wireless/wl12xx/scan.h
+++ b/drivers/net/wireless/wl12xx/scan.h
@@ -26,18 +26,20 @@
26 26
27#include "wl12xx.h" 27#include "wl12xx.h"
28 28
29int wl1271_scan(struct wl1271 *wl, const u8 *ssid, size_t ssid_len, 29int wl1271_scan(struct wl1271 *wl, struct ieee80211_vif *vif,
30 const u8 *ssid, size_t ssid_len,
30 struct cfg80211_scan_request *req); 31 struct cfg80211_scan_request *req);
31int wl1271_scan_stop(struct wl1271 *wl); 32int wl1271_scan_stop(struct wl1271 *wl);
32int wl1271_scan_build_probe_req(struct wl1271 *wl, 33int wl1271_scan_build_probe_req(struct wl1271 *wl,
33 const u8 *ssid, size_t ssid_len, 34 const u8 *ssid, size_t ssid_len,
34 const u8 *ie, size_t ie_len, u8 band); 35 const u8 *ie, size_t ie_len, u8 band);
35void wl1271_scan_stm(struct wl1271 *wl); 36void wl1271_scan_stm(struct wl1271 *wl, struct ieee80211_vif *vif);
36void wl1271_scan_complete_work(struct work_struct *work); 37void wl1271_scan_complete_work(struct work_struct *work);
37int wl1271_scan_sched_scan_config(struct wl1271 *wl, 38int wl1271_scan_sched_scan_config(struct wl1271 *wl,
39 struct wl12xx_vif *wlvif,
38 struct cfg80211_sched_scan_request *req, 40 struct cfg80211_sched_scan_request *req,
39 struct ieee80211_sched_scan_ies *ies); 41 struct ieee80211_sched_scan_ies *ies);
40int wl1271_scan_sched_scan_start(struct wl1271 *wl); 42int wl1271_scan_sched_scan_start(struct wl1271 *wl, struct wl12xx_vif *wlvif);
41void wl1271_scan_sched_scan_stop(struct wl1271 *wl); 43void wl1271_scan_sched_scan_stop(struct wl1271 *wl);
42void wl1271_scan_sched_scan_results(struct wl1271 *wl); 44void wl1271_scan_sched_scan_results(struct wl1271 *wl);
43 45
diff --git a/drivers/net/wireless/wl12xx/sdio.c b/drivers/net/wireless/wl12xx/sdio.c
index 516a8980723..468a50553fa 100644
--- a/drivers/net/wireless/wl12xx/sdio.c
+++ b/drivers/net/wireless/wl12xx/sdio.c
@@ -24,6 +24,7 @@
24#include <linux/irq.h> 24#include <linux/irq.h>
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/vmalloc.h> 26#include <linux/vmalloc.h>
27#include <linux/platform_device.h>
27#include <linux/mmc/sdio_func.h> 28#include <linux/mmc/sdio_func.h>
28#include <linux/mmc/sdio_ids.h> 29#include <linux/mmc/sdio_ids.h>
29#include <linux/mmc/card.h> 30#include <linux/mmc/card.h>
@@ -44,107 +45,67 @@
44#define SDIO_DEVICE_ID_TI_WL1271 0x4076 45#define SDIO_DEVICE_ID_TI_WL1271 0x4076
45#endif 46#endif
46 47
48struct wl12xx_sdio_glue {
49 struct device *dev;
50 struct platform_device *core;
51};
52
47static const struct sdio_device_id wl1271_devices[] __devinitconst = { 53static const struct sdio_device_id wl1271_devices[] __devinitconst = {
48 { SDIO_DEVICE(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1271) }, 54 { SDIO_DEVICE(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1271) },
49 {} 55 {}
50}; 56};
51MODULE_DEVICE_TABLE(sdio, wl1271_devices); 57MODULE_DEVICE_TABLE(sdio, wl1271_devices);
52 58
53static void wl1271_sdio_set_block_size(struct wl1271 *wl, unsigned int blksz) 59static void wl1271_sdio_set_block_size(struct device *child,
54{ 60 unsigned int blksz)
55 sdio_claim_host(wl->if_priv);
56 sdio_set_block_size(wl->if_priv, blksz);
57 sdio_release_host(wl->if_priv);
58}
59
60static inline struct sdio_func *wl_to_func(struct wl1271 *wl)
61{
62 return wl->if_priv;
63}
64
65static struct device *wl1271_sdio_wl_to_dev(struct wl1271 *wl)
66{
67 return &(wl_to_func(wl)->dev);
68}
69
70static irqreturn_t wl1271_hardirq(int irq, void *cookie)
71{ 61{
72 struct wl1271 *wl = cookie; 62 struct wl12xx_sdio_glue *glue = dev_get_drvdata(child->parent);
73 unsigned long flags; 63 struct sdio_func *func = dev_to_sdio_func(glue->dev);
74 64
75 wl1271_debug(DEBUG_IRQ, "IRQ"); 65 sdio_claim_host(func);
76 66 sdio_set_block_size(func, blksz);
77 /* complete the ELP completion */ 67 sdio_release_host(func);
78 spin_lock_irqsave(&wl->wl_lock, flags);
79 set_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags);
80 if (wl->elp_compl) {
81 complete(wl->elp_compl);
82 wl->elp_compl = NULL;
83 }
84
85 if (test_bit(WL1271_FLAG_SUSPENDED, &wl->flags)) {
86 /* don't enqueue a work right now. mark it as pending */
87 set_bit(WL1271_FLAG_PENDING_WORK, &wl->flags);
88 wl1271_debug(DEBUG_IRQ, "should not enqueue work");
89 disable_irq_nosync(wl->irq);
90 pm_wakeup_event(wl1271_sdio_wl_to_dev(wl), 0);
91 spin_unlock_irqrestore(&wl->wl_lock, flags);
92 return IRQ_HANDLED;
93 }
94 spin_unlock_irqrestore(&wl->wl_lock, flags);
95
96 return IRQ_WAKE_THREAD;
97}
98
99static void wl1271_sdio_disable_interrupts(struct wl1271 *wl)
100{
101 disable_irq(wl->irq);
102}
103
104static void wl1271_sdio_enable_interrupts(struct wl1271 *wl)
105{
106 enable_irq(wl->irq);
107} 68}
108 69
109static void wl1271_sdio_raw_read(struct wl1271 *wl, int addr, void *buf, 70static void wl12xx_sdio_raw_read(struct device *child, int addr, void *buf,
110 size_t len, bool fixed) 71 size_t len, bool fixed)
111{ 72{
112 int ret; 73 int ret;
113 struct sdio_func *func = wl_to_func(wl); 74 struct wl12xx_sdio_glue *glue = dev_get_drvdata(child->parent);
75 struct sdio_func *func = dev_to_sdio_func(glue->dev);
114 76
115 if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG_ADDR)) { 77 if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG_ADDR)) {
116 ((u8 *)buf)[0] = sdio_f0_readb(func, addr, &ret); 78 ((u8 *)buf)[0] = sdio_f0_readb(func, addr, &ret);
117 wl1271_debug(DEBUG_SDIO, "sdio read 52 addr 0x%x, byte 0x%02x", 79 dev_dbg(child->parent, "sdio read 52 addr 0x%x, byte 0x%02x\n",
118 addr, ((u8 *)buf)[0]); 80 addr, ((u8 *)buf)[0]);
119 } else { 81 } else {
120 if (fixed) 82 if (fixed)
121 ret = sdio_readsb(func, buf, addr, len); 83 ret = sdio_readsb(func, buf, addr, len);
122 else 84 else
123 ret = sdio_memcpy_fromio(func, buf, addr, len); 85 ret = sdio_memcpy_fromio(func, buf, addr, len);
124 86
125 wl1271_debug(DEBUG_SDIO, "sdio read 53 addr 0x%x, %zu bytes", 87 dev_dbg(child->parent, "sdio read 53 addr 0x%x, %zu bytes\n",
126 addr, len); 88 addr, len);
127 wl1271_dump_ascii(DEBUG_SDIO, "data: ", buf, len);
128 } 89 }
129 90
130 if (ret) 91 if (ret)
131 wl1271_error("sdio read failed (%d)", ret); 92 dev_err(child->parent, "sdio read failed (%d)\n", ret);
132} 93}
133 94
134static void wl1271_sdio_raw_write(struct wl1271 *wl, int addr, void *buf, 95static void wl12xx_sdio_raw_write(struct device *child, int addr, void *buf,
135 size_t len, bool fixed) 96 size_t len, bool fixed)
136{ 97{
137 int ret; 98 int ret;
138 struct sdio_func *func = wl_to_func(wl); 99 struct wl12xx_sdio_glue *glue = dev_get_drvdata(child->parent);
100 struct sdio_func *func = dev_to_sdio_func(glue->dev);
139 101
140 if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG_ADDR)) { 102 if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG_ADDR)) {
141 sdio_f0_writeb(func, ((u8 *)buf)[0], addr, &ret); 103 sdio_f0_writeb(func, ((u8 *)buf)[0], addr, &ret);
142 wl1271_debug(DEBUG_SDIO, "sdio write 52 addr 0x%x, byte 0x%02x", 104 dev_dbg(child->parent, "sdio write 52 addr 0x%x, byte 0x%02x\n",
143 addr, ((u8 *)buf)[0]); 105 addr, ((u8 *)buf)[0]);
144 } else { 106 } else {
145 wl1271_debug(DEBUG_SDIO, "sdio write 53 addr 0x%x, %zu bytes", 107 dev_dbg(child->parent, "sdio write 53 addr 0x%x, %zu bytes\n",
146 addr, len); 108 addr, len);
147 wl1271_dump_ascii(DEBUG_SDIO, "data: ", buf, len);
148 109
149 if (fixed) 110 if (fixed)
150 ret = sdio_writesb(func, addr, buf, len); 111 ret = sdio_writesb(func, addr, buf, len);
@@ -153,13 +114,13 @@ static void wl1271_sdio_raw_write(struct wl1271 *wl, int addr, void *buf,
153 } 114 }
154 115
155 if (ret) 116 if (ret)
156 wl1271_error("sdio write failed (%d)", ret); 117 dev_err(child->parent, "sdio write failed (%d)\n", ret);
157} 118}
158 119
159static int wl1271_sdio_power_on(struct wl1271 *wl) 120static int wl12xx_sdio_power_on(struct wl12xx_sdio_glue *glue)
160{ 121{
161 struct sdio_func *func = wl_to_func(wl);
162 int ret; 122 int ret;
123 struct sdio_func *func = dev_to_sdio_func(glue->dev);
163 124
164 /* If enabled, tell runtime PM not to power off the card */ 125 /* If enabled, tell runtime PM not to power off the card */
165 if (pm_runtime_enabled(&func->dev)) { 126 if (pm_runtime_enabled(&func->dev)) {
@@ -180,10 +141,10 @@ out:
180 return ret; 141 return ret;
181} 142}
182 143
183static int wl1271_sdio_power_off(struct wl1271 *wl) 144static int wl12xx_sdio_power_off(struct wl12xx_sdio_glue *glue)
184{ 145{
185 struct sdio_func *func = wl_to_func(wl);
186 int ret; 146 int ret;
147 struct sdio_func *func = dev_to_sdio_func(glue->dev);
187 148
188 sdio_disable_func(func); 149 sdio_disable_func(func);
189 sdio_release_host(func); 150 sdio_release_host(func);
@@ -200,46 +161,43 @@ static int wl1271_sdio_power_off(struct wl1271 *wl)
200 return ret; 161 return ret;
201} 162}
202 163
203static int wl1271_sdio_set_power(struct wl1271 *wl, bool enable) 164static int wl12xx_sdio_set_power(struct device *child, bool enable)
204{ 165{
166 struct wl12xx_sdio_glue *glue = dev_get_drvdata(child->parent);
167
205 if (enable) 168 if (enable)
206 return wl1271_sdio_power_on(wl); 169 return wl12xx_sdio_power_on(glue);
207 else 170 else
208 return wl1271_sdio_power_off(wl); 171 return wl12xx_sdio_power_off(glue);
209} 172}
210 173
211static struct wl1271_if_operations sdio_ops = { 174static struct wl1271_if_operations sdio_ops = {
212 .read = wl1271_sdio_raw_read, 175 .read = wl12xx_sdio_raw_read,
213 .write = wl1271_sdio_raw_write, 176 .write = wl12xx_sdio_raw_write,
214 .power = wl1271_sdio_set_power, 177 .power = wl12xx_sdio_set_power,
215 .dev = wl1271_sdio_wl_to_dev,
216 .enable_irq = wl1271_sdio_enable_interrupts,
217 .disable_irq = wl1271_sdio_disable_interrupts,
218 .set_block_size = wl1271_sdio_set_block_size, 178 .set_block_size = wl1271_sdio_set_block_size,
219}; 179};
220 180
221static int __devinit wl1271_probe(struct sdio_func *func, 181static int __devinit wl1271_probe(struct sdio_func *func,
222 const struct sdio_device_id *id) 182 const struct sdio_device_id *id)
223{ 183{
224 struct ieee80211_hw *hw; 184 struct wl12xx_platform_data *wlan_data;
225 const struct wl12xx_platform_data *wlan_data; 185 struct wl12xx_sdio_glue *glue;
226 struct wl1271 *wl; 186 struct resource res[1];
227 unsigned long irqflags;
228 mmc_pm_flag_t mmcflags; 187 mmc_pm_flag_t mmcflags;
229 int ret; 188 int ret = -ENOMEM;
230 189
231 /* We are only able to handle the wlan function */ 190 /* We are only able to handle the wlan function */
232 if (func->num != 0x02) 191 if (func->num != 0x02)
233 return -ENODEV; 192 return -ENODEV;
234 193
235 hw = wl1271_alloc_hw(); 194 glue = kzalloc(sizeof(*glue), GFP_KERNEL);
236 if (IS_ERR(hw)) 195 if (!glue) {
237 return PTR_ERR(hw); 196 dev_err(&func->dev, "can't allocate glue\n");
238 197 goto out;
239 wl = hw->priv; 198 }
240 199
241 wl->if_priv = func; 200 glue->dev = &func->dev;
242 wl->if_ops = &sdio_ops;
243 201
244 /* Grab access to FN0 for ELP reg. */ 202 /* Grab access to FN0 for ELP reg. */
245 func->card->quirks |= MMC_QUIRK_LENIENT_FN0; 203 func->card->quirks |= MMC_QUIRK_LENIENT_FN0;
@@ -250,80 +208,79 @@ static int __devinit wl1271_probe(struct sdio_func *func,
250 wlan_data = wl12xx_get_platform_data(); 208 wlan_data = wl12xx_get_platform_data();
251 if (IS_ERR(wlan_data)) { 209 if (IS_ERR(wlan_data)) {
252 ret = PTR_ERR(wlan_data); 210 ret = PTR_ERR(wlan_data);
253 wl1271_error("missing wlan platform data: %d", ret); 211 dev_err(glue->dev, "missing wlan platform data: %d\n", ret);
254 goto out_free; 212 goto out_free_glue;
255 } 213 }
256 214
257 wl->irq = wlan_data->irq; 215 /* if sdio can keep power while host is suspended, enable wow */
258 wl->ref_clock = wlan_data->board_ref_clock; 216 mmcflags = sdio_get_host_pm_caps(func);
259 wl->tcxo_clock = wlan_data->board_tcxo_clock; 217 dev_dbg(glue->dev, "sdio PM caps = 0x%x\n", mmcflags);
260 wl->platform_quirks = wlan_data->platform_quirks;
261 218
262 if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ) 219 if (mmcflags & MMC_PM_KEEP_POWER)
263 irqflags = IRQF_TRIGGER_RISING; 220 wlan_data->pwr_in_suspend = true;
264 else 221
265 irqflags = IRQF_TRIGGER_HIGH | IRQF_ONESHOT; 222 wlan_data->ops = &sdio_ops;
266
267 ret = request_threaded_irq(wl->irq, wl1271_hardirq, wl1271_irq,
268 irqflags,
269 DRIVER_NAME, wl);
270 if (ret < 0) {
271 wl1271_error("request_irq() failed: %d", ret);
272 goto out_free;
273 }
274 223
275 ret = enable_irq_wake(wl->irq); 224 sdio_set_drvdata(func, glue);
276 if (!ret) {
277 wl->irq_wake_enabled = true;
278 device_init_wakeup(wl1271_sdio_wl_to_dev(wl), 1);
279 225
280 /* if sdio can keep power while host is suspended, enable wow */ 226 /* Tell PM core that we don't need the card to be powered now */
281 mmcflags = sdio_get_host_pm_caps(func); 227 pm_runtime_put_noidle(&func->dev);
282 wl1271_debug(DEBUG_SDIO, "sdio PM caps = 0x%x", mmcflags);
283 228
284 if (mmcflags & MMC_PM_KEEP_POWER) 229 glue->core = platform_device_alloc("wl12xx", -1);
285 hw->wiphy->wowlan.flags = WIPHY_WOWLAN_ANY; 230 if (!glue->core) {
231 dev_err(glue->dev, "can't allocate platform_device");
232 ret = -ENOMEM;
233 goto out_free_glue;
286 } 234 }
287 disable_irq(wl->irq);
288 235
289 ret = wl1271_init_ieee80211(wl); 236 glue->core->dev.parent = &func->dev;
290 if (ret)
291 goto out_irq;
292 237
293 ret = wl1271_register_hw(wl); 238 memset(res, 0x00, sizeof(res));
294 if (ret)
295 goto out_irq;
296 239
297 sdio_set_drvdata(func, wl); 240 res[0].start = wlan_data->irq;
241 res[0].flags = IORESOURCE_IRQ;
242 res[0].name = "irq";
298 243
299 /* Tell PM core that we don't need the card to be powered now */ 244 ret = platform_device_add_resources(glue->core, res, ARRAY_SIZE(res));
300 pm_runtime_put_noidle(&func->dev); 245 if (ret) {
246 dev_err(glue->dev, "can't add resources\n");
247 goto out_dev_put;
248 }
301 249
250 ret = platform_device_add_data(glue->core, wlan_data,
251 sizeof(*wlan_data));
252 if (ret) {
253 dev_err(glue->dev, "can't add platform data\n");
254 goto out_dev_put;
255 }
256
257 ret = platform_device_add(glue->core);
258 if (ret) {
259 dev_err(glue->dev, "can't add platform device\n");
260 goto out_dev_put;
261 }
302 return 0; 262 return 0;
303 263
304 out_irq: 264out_dev_put:
305 free_irq(wl->irq, wl); 265 platform_device_put(glue->core);
306 266
307 out_free: 267out_free_glue:
308 wl1271_free_hw(wl); 268 kfree(glue);
309 269
270out:
310 return ret; 271 return ret;
311} 272}
312 273
313static void __devexit wl1271_remove(struct sdio_func *func) 274static void __devexit wl1271_remove(struct sdio_func *func)
314{ 275{
315 struct wl1271 *wl = sdio_get_drvdata(func); 276 struct wl12xx_sdio_glue *glue = sdio_get_drvdata(func);
316 277
317 /* Undo decrement done above in wl1271_probe */ 278 /* Undo decrement done above in wl1271_probe */
318 pm_runtime_get_noresume(&func->dev); 279 pm_runtime_get_noresume(&func->dev);
319 280
320 wl1271_unregister_hw(wl); 281 platform_device_del(glue->core);
321 if (wl->irq_wake_enabled) { 282 platform_device_put(glue->core);
322 device_init_wakeup(wl1271_sdio_wl_to_dev(wl), 0); 283 kfree(glue);
323 disable_irq_wake(wl->irq);
324 }
325 free_irq(wl->irq, wl);
326 wl1271_free_hw(wl);
327} 284}
328 285
329#ifdef CONFIG_PM 286#ifdef CONFIG_PM
@@ -332,20 +289,21 @@ static int wl1271_suspend(struct device *dev)
332 /* Tell MMC/SDIO core it's OK to power down the card 289 /* Tell MMC/SDIO core it's OK to power down the card
333 * (if it isn't already), but not to remove it completely */ 290 * (if it isn't already), but not to remove it completely */
334 struct sdio_func *func = dev_to_sdio_func(dev); 291 struct sdio_func *func = dev_to_sdio_func(dev);
335 struct wl1271 *wl = sdio_get_drvdata(func); 292 struct wl12xx_sdio_glue *glue = sdio_get_drvdata(func);
293 struct wl1271 *wl = platform_get_drvdata(glue->core);
336 mmc_pm_flag_t sdio_flags; 294 mmc_pm_flag_t sdio_flags;
337 int ret = 0; 295 int ret = 0;
338 296
339 wl1271_debug(DEBUG_MAC80211, "wl1271 suspend. wow_enabled: %d", 297 dev_dbg(dev, "wl1271 suspend. wow_enabled: %d\n",
340 wl->wow_enabled); 298 wl->wow_enabled);
341 299
342 /* check whether sdio should keep power */ 300 /* check whether sdio should keep power */
343 if (wl->wow_enabled) { 301 if (wl->wow_enabled) {
344 sdio_flags = sdio_get_host_pm_caps(func); 302 sdio_flags = sdio_get_host_pm_caps(func);
345 303
346 if (!(sdio_flags & MMC_PM_KEEP_POWER)) { 304 if (!(sdio_flags & MMC_PM_KEEP_POWER)) {
347 wl1271_error("can't keep power while host " 305 dev_err(dev, "can't keep power while host "
348 "is suspended"); 306 "is suspended\n");
349 ret = -EINVAL; 307 ret = -EINVAL;
350 goto out; 308 goto out;
351 } 309 }
@@ -353,7 +311,7 @@ static int wl1271_suspend(struct device *dev)
353 /* keep power while host suspended */ 311 /* keep power while host suspended */
354 ret = sdio_set_host_pm_flags(func, MMC_PM_KEEP_POWER); 312 ret = sdio_set_host_pm_flags(func, MMC_PM_KEEP_POWER);
355 if (ret) { 313 if (ret) {
356 wl1271_error("error while trying to keep power"); 314 dev_err(dev, "error while trying to keep power\n");
357 goto out; 315 goto out;
358 } 316 }
359 317
@@ -367,9 +325,10 @@ out:
367static int wl1271_resume(struct device *dev) 325static int wl1271_resume(struct device *dev)
368{ 326{
369 struct sdio_func *func = dev_to_sdio_func(dev); 327 struct sdio_func *func = dev_to_sdio_func(dev);
370 struct wl1271 *wl = sdio_get_drvdata(func); 328 struct wl12xx_sdio_glue *glue = sdio_get_drvdata(func);
329 struct wl1271 *wl = platform_get_drvdata(glue->core);
371 330
372 wl1271_debug(DEBUG_MAC80211, "wl1271 resume"); 331 dev_dbg(dev, "wl1271 resume\n");
373 if (wl->wow_enabled) { 332 if (wl->wow_enabled) {
374 /* claim back host */ 333 /* claim back host */
375 sdio_claim_host(func); 334 sdio_claim_host(func);
diff --git a/drivers/net/wireless/wl12xx/sdio_test.c b/drivers/net/wireless/wl12xx/sdio_test.c
deleted file mode 100644
index f25d5d9212e..00000000000
--- a/drivers/net/wireless/wl12xx/sdio_test.c
+++ /dev/null
@@ -1,543 +0,0 @@
1/*
2 * SDIO testing driver for wl12xx
3 *
4 * Copyright (C) 2010 Nokia Corporation
5 *
6 * Contact: Roger Quadros <roger.quadros@nokia.com>
7 *
8 * wl12xx read/write routines taken from the main module
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * version 2 as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22 * 02110-1301 USA
23 *
24 */
25
26#include <linux/irq.h>
27#include <linux/module.h>
28#include <linux/crc7.h>
29#include <linux/vmalloc.h>
30#include <linux/mmc/sdio_func.h>
31#include <linux/mmc/sdio_ids.h>
32#include <linux/mmc/card.h>
33#include <linux/mmc/host.h>
34#include <linux/gpio.h>
35#include <linux/wl12xx.h>
36#include <linux/kthread.h>
37#include <linux/firmware.h>
38#include <linux/pm_runtime.h>
39
40#include "wl12xx.h"
41#include "io.h"
42#include "boot.h"
43
44#ifndef SDIO_VENDOR_ID_TI
45#define SDIO_VENDOR_ID_TI 0x0097
46#endif
47
48#ifndef SDIO_DEVICE_ID_TI_WL1271
49#define SDIO_DEVICE_ID_TI_WL1271 0x4076
50#endif
51
52static bool rx, tx;
53
54module_param(rx, bool, S_IRUGO | S_IWUSR);
55MODULE_PARM_DESC(rx, "Perform rx test. Default (0). "
56 "This test continuously reads data from the SDIO device.\n");
57
58module_param(tx, bool, S_IRUGO | S_IWUSR);
59MODULE_PARM_DESC(tx, "Perform tx test. Default (0). "
60 "This test continuously writes data to the SDIO device.\n");
61
62struct wl1271_test {
63 struct wl1271 wl;
64 struct task_struct *test_task;
65};
66
67static const struct sdio_device_id wl1271_devices[] = {
68 { SDIO_DEVICE(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1271) },
69 {}
70};
71
72static inline struct sdio_func *wl_to_func(struct wl1271 *wl)
73{
74 return wl->if_priv;
75}
76
77static struct device *wl1271_sdio_wl_to_dev(struct wl1271 *wl)
78{
79 return &(wl_to_func(wl)->dev);
80}
81
82static void wl1271_sdio_raw_read(struct wl1271 *wl, int addr, void *buf,
83 size_t len, bool fixed)
84{
85 int ret = 0;
86 struct sdio_func *func = wl_to_func(wl);
87
88 if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG_ADDR)) {
89 ((u8 *)buf)[0] = sdio_f0_readb(func, addr, &ret);
90 wl1271_debug(DEBUG_SDIO, "sdio read 52 addr 0x%x, byte 0x%02x",
91 addr, ((u8 *)buf)[0]);
92 } else {
93 if (fixed)
94 ret = sdio_readsb(func, buf, addr, len);
95 else
96 ret = sdio_memcpy_fromio(func, buf, addr, len);
97
98 wl1271_debug(DEBUG_SDIO, "sdio read 53 addr 0x%x, %zu bytes",
99 addr, len);
100 wl1271_dump_ascii(DEBUG_SDIO, "data: ", buf, len);
101 }
102
103 if (ret)
104 wl1271_error("sdio read failed (%d)", ret);
105}
106
107static void wl1271_sdio_raw_write(struct wl1271 *wl, int addr, void *buf,
108 size_t len, bool fixed)
109{
110 int ret = 0;
111 struct sdio_func *func = wl_to_func(wl);
112
113 if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG_ADDR)) {
114 sdio_f0_writeb(func, ((u8 *)buf)[0], addr, &ret);
115 wl1271_debug(DEBUG_SDIO, "sdio write 52 addr 0x%x, byte 0x%02x",
116 addr, ((u8 *)buf)[0]);
117 } else {
118 wl1271_debug(DEBUG_SDIO, "sdio write 53 addr 0x%x, %zu bytes",
119 addr, len);
120 wl1271_dump_ascii(DEBUG_SDIO, "data: ", buf, len);
121
122 if (fixed)
123 ret = sdio_writesb(func, addr, buf, len);
124 else
125 ret = sdio_memcpy_toio(func, addr, buf, len);
126 }
127 if (ret)
128 wl1271_error("sdio write failed (%d)", ret);
129
130}
131
132static int wl1271_sdio_set_power(struct wl1271 *wl, bool enable)
133{
134 struct sdio_func *func = wl_to_func(wl);
135 int ret;
136
137 /* Let the SDIO stack handle wlan_enable control, so we
138 * keep host claimed while wlan is in use to keep wl1271
139 * alive.
140 */
141 if (enable) {
142 /* Power up the card */
143 ret = pm_runtime_get_sync(&func->dev);
144 if (ret < 0)
145 goto out;
146
147 /* Runtime PM might be disabled, power up the card manually */
148 ret = mmc_power_restore_host(func->card->host);
149 if (ret < 0)
150 goto out;
151
152 sdio_claim_host(func);
153 sdio_enable_func(func);
154 } else {
155 sdio_disable_func(func);
156 sdio_release_host(func);
157
158 /* Runtime PM might be disabled, power off the card manually */
159 ret = mmc_power_save_host(func->card->host);
160 if (ret < 0)
161 goto out;
162
163 /* Power down the card */
164 ret = pm_runtime_put_sync(&func->dev);
165 }
166
167out:
168 return ret;
169}
170
171static void wl1271_sdio_disable_interrupts(struct wl1271 *wl)
172{
173}
174
175static void wl1271_sdio_enable_interrupts(struct wl1271 *wl)
176{
177}
178
179
180static struct wl1271_if_operations sdio_ops = {
181 .read = wl1271_sdio_raw_read,
182 .write = wl1271_sdio_raw_write,
183 .power = wl1271_sdio_set_power,
184 .dev = wl1271_sdio_wl_to_dev,
185 .enable_irq = wl1271_sdio_enable_interrupts,
186 .disable_irq = wl1271_sdio_disable_interrupts,
187};
188
189static void wl1271_fw_wakeup(struct wl1271 *wl)
190{
191 u32 elp_reg;
192
193 elp_reg = ELPCTRL_WAKE_UP;
194 wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg);
195}
196
197static int wl1271_fetch_firmware(struct wl1271 *wl)
198{
199 const struct firmware *fw;
200 int ret;
201
202 if (wl->chip.id == CHIP_ID_1283_PG20)
203 ret = request_firmware(&fw, WL128X_FW_NAME,
204 wl1271_wl_to_dev(wl));
205 else
206 ret = request_firmware(&fw, WL127X_FW_NAME,
207 wl1271_wl_to_dev(wl));
208
209 if (ret < 0) {
210 wl1271_error("could not get firmware: %d", ret);
211 return ret;
212 }
213
214 if (fw->size % 4) {
215 wl1271_error("firmware size is not multiple of 32 bits: %zu",
216 fw->size);
217 ret = -EILSEQ;
218 goto out;
219 }
220
221 wl->fw_len = fw->size;
222 wl->fw = vmalloc(wl->fw_len);
223
224 if (!wl->fw) {
225 wl1271_error("could not allocate memory for the firmware");
226 ret = -ENOMEM;
227 goto out;
228 }
229
230 memcpy(wl->fw, fw->data, wl->fw_len);
231
232 ret = 0;
233
234out:
235 release_firmware(fw);
236
237 return ret;
238}
239
240static int wl1271_fetch_nvs(struct wl1271 *wl)
241{
242 const struct firmware *fw;
243 int ret;
244
245 ret = request_firmware(&fw, WL12XX_NVS_NAME, wl1271_wl_to_dev(wl));
246
247 if (ret < 0) {
248 wl1271_error("could not get nvs file: %d", ret);
249 return ret;
250 }
251
252 wl->nvs = kmemdup(fw->data, fw->size, GFP_KERNEL);
253
254 if (!wl->nvs) {
255 wl1271_error("could not allocate memory for the nvs file");
256 ret = -ENOMEM;
257 goto out;
258 }
259
260 wl->nvs_len = fw->size;
261
262out:
263 release_firmware(fw);
264
265 return ret;
266}
267
268static int wl1271_chip_wakeup(struct wl1271 *wl)
269{
270 struct wl1271_partition_set partition;
271 int ret;
272
273 msleep(WL1271_PRE_POWER_ON_SLEEP);
274 ret = wl1271_power_on(wl);
275 if (ret)
276 return ret;
277
278 msleep(WL1271_POWER_ON_SLEEP);
279
280 /* We don't need a real memory partition here, because we only want
281 * to use the registers at this point. */
282 memset(&partition, 0, sizeof(partition));
283 partition.reg.start = REGISTERS_BASE;
284 partition.reg.size = REGISTERS_DOWN_SIZE;
285 wl1271_set_partition(wl, &partition);
286
287 /* ELP module wake up */
288 wl1271_fw_wakeup(wl);
289
290 /* whal_FwCtrl_BootSm() */
291
292 /* 0. read chip id from CHIP_ID */
293 wl->chip.id = wl1271_read32(wl, CHIP_ID_B);
294
295 /* 1. check if chip id is valid */
296
297 switch (wl->chip.id) {
298 case CHIP_ID_1271_PG10:
299 wl1271_warning("chip id 0x%x (1271 PG10) support is obsolete",
300 wl->chip.id);
301 break;
302 case CHIP_ID_1271_PG20:
303 wl1271_notice("chip id 0x%x (1271 PG20)",
304 wl->chip.id);
305 break;
306 case CHIP_ID_1283_PG20:
307 wl1271_notice("chip id 0x%x (1283 PG20)",
308 wl->chip.id);
309 break;
310 case CHIP_ID_1283_PG10:
311 default:
312 wl1271_warning("unsupported chip id: 0x%x", wl->chip.id);
313 return -ENODEV;
314 }
315
316 return ret;
317}
318
319static struct wl1271_partition_set part_down = {
320 .mem = {
321 .start = 0x00000000,
322 .size = 0x000177c0
323 },
324 .reg = {
325 .start = REGISTERS_BASE,
326 .size = 0x00008800
327 },
328 .mem2 = {
329 .start = 0x00000000,
330 .size = 0x00000000
331 },
332 .mem3 = {
333 .start = 0x00000000,
334 .size = 0x00000000
335 },
336};
337
338static int tester(void *data)
339{
340 struct wl1271 *wl = data;
341 struct sdio_func *func = wl_to_func(wl);
342 struct device *pdev = &func->dev;
343 int ret = 0;
344 bool rx_started = 0;
345 bool tx_started = 0;
346 uint8_t *tx_buf, *rx_buf;
347 int test_size = PAGE_SIZE;
348 u32 addr = 0;
349 struct wl1271_partition_set partition;
350
351 /* We assume chip is powered up and firmware fetched */
352
353 memcpy(&partition, &part_down, sizeof(partition));
354 partition.mem.start = addr;
355 wl1271_set_partition(wl, &partition);
356
357 tx_buf = kmalloc(test_size, GFP_KERNEL);
358 rx_buf = kmalloc(test_size, GFP_KERNEL);
359 if (!tx_buf || !rx_buf) {
360 dev_err(pdev,
361 "Could not allocate memory. Test will not run.\n");
362 ret = -ENOMEM;
363 goto free;
364 }
365
366 memset(tx_buf, 0x5a, test_size);
367
368 /* write something in data area so we can read it back */
369 wl1271_write(wl, addr, tx_buf, test_size, false);
370
371 while (!kthread_should_stop()) {
372 if (rx && !rx_started) {
373 dev_info(pdev, "starting rx test\n");
374 rx_started = 1;
375 } else if (!rx && rx_started) {
376 dev_info(pdev, "stopping rx test\n");
377 rx_started = 0;
378 }
379
380 if (tx && !tx_started) {
381 dev_info(pdev, "starting tx test\n");
382 tx_started = 1;
383 } else if (!tx && tx_started) {
384 dev_info(pdev, "stopping tx test\n");
385 tx_started = 0;
386 }
387
388 if (rx_started)
389 wl1271_read(wl, addr, rx_buf, test_size, false);
390
391 if (tx_started)
392 wl1271_write(wl, addr, tx_buf, test_size, false);
393
394 if (!rx_started && !tx_started)
395 msleep(100);
396 }
397
398free:
399 kfree(tx_buf);
400 kfree(rx_buf);
401 return ret;
402}
403
404static int __devinit wl1271_probe(struct sdio_func *func,
405 const struct sdio_device_id *id)
406{
407 const struct wl12xx_platform_data *wlan_data;
408 struct wl1271 *wl;
409 struct wl1271_test *wl_test;
410 int ret = 0;
411
412 /* wl1271 has 2 sdio functions we handle just the wlan part */
413 if (func->num != 0x02)
414 return -ENODEV;
415
416 wl_test = kzalloc(sizeof(struct wl1271_test), GFP_KERNEL);
417 if (!wl_test) {
418 dev_err(&func->dev, "Could not allocate memory\n");
419 return -ENOMEM;
420 }
421
422 wl = &wl_test->wl;
423
424 wl->if_priv = func;
425 wl->if_ops = &sdio_ops;
426
427 /* Grab access to FN0 for ELP reg. */
428 func->card->quirks |= MMC_QUIRK_LENIENT_FN0;
429
430 /* Use block mode for transferring over one block size of data */
431 func->card->quirks |= MMC_QUIRK_BLKSZ_FOR_BYTE_MODE;
432
433 wlan_data = wl12xx_get_platform_data();
434 if (IS_ERR(wlan_data)) {
435 ret = PTR_ERR(wlan_data);
436 dev_err(&func->dev, "missing wlan platform data: %d\n", ret);
437 goto out_free;
438 }
439
440 wl->irq = wlan_data->irq;
441 wl->ref_clock = wlan_data->board_ref_clock;
442 wl->tcxo_clock = wlan_data->board_tcxo_clock;
443
444 sdio_set_drvdata(func, wl_test);
445
446 /* power up the device */
447 ret = wl1271_chip_wakeup(wl);
448 if (ret) {
449 dev_err(&func->dev, "could not wake up chip\n");
450 goto out_free;
451 }
452
453 if (wl->fw == NULL) {
454 ret = wl1271_fetch_firmware(wl);
455 if (ret < 0) {
456 dev_err(&func->dev, "firmware fetch error\n");
457 goto out_off;
458 }
459 }
460
461 /* fetch NVS */
462 if (wl->nvs == NULL) {
463 ret = wl1271_fetch_nvs(wl);
464 if (ret < 0) {
465 dev_err(&func->dev, "NVS fetch error\n");
466 goto out_off;
467 }
468 }
469
470 ret = wl1271_load_firmware(wl);
471 if (ret < 0) {
472 dev_err(&func->dev, "firmware load error: %d\n", ret);
473 goto out_free;
474 }
475
476 dev_info(&func->dev, "initialized\n");
477
478 /* I/O testing will be done in the tester thread */
479
480 wl_test->test_task = kthread_run(tester, wl, "sdio_tester");
481 if (IS_ERR(wl_test->test_task)) {
482 dev_err(&func->dev, "unable to create kernel thread\n");
483 ret = PTR_ERR(wl_test->test_task);
484 goto out_free;
485 }
486
487 return 0;
488
489out_off:
490 /* power off the chip */
491 wl1271_power_off(wl);
492
493out_free:
494 kfree(wl_test);
495 return ret;
496}
497
498static void __devexit wl1271_remove(struct sdio_func *func)
499{
500 struct wl1271_test *wl_test = sdio_get_drvdata(func);
501
502 /* stop the I/O test thread */
503 kthread_stop(wl_test->test_task);
504
505 /* power off the chip */
506 wl1271_power_off(&wl_test->wl);
507
508 vfree(wl_test->wl.fw);
509 wl_test->wl.fw = NULL;
510 kfree(wl_test->wl.nvs);
511 wl_test->wl.nvs = NULL;
512
513 kfree(wl_test);
514}
515
516static struct sdio_driver wl1271_sdio_driver = {
517 .name = "wl12xx_sdio_test",
518 .id_table = wl1271_devices,
519 .probe = wl1271_probe,
520 .remove = __devexit_p(wl1271_remove),
521};
522
523static int __init wl1271_init(void)
524{
525 int ret;
526
527 ret = sdio_register_driver(&wl1271_sdio_driver);
528 if (ret < 0)
529 pr_err("failed to register sdio driver: %d\n", ret);
530
531 return ret;
532}
533module_init(wl1271_init);
534
535static void __exit wl1271_exit(void)
536{
537 sdio_unregister_driver(&wl1271_sdio_driver);
538}
539module_exit(wl1271_exit);
540
541MODULE_LICENSE("GPL");
542MODULE_AUTHOR("Roger Quadros <roger.quadros@nokia.com>");
543
diff --git a/drivers/net/wireless/wl12xx/spi.c b/drivers/net/wireless/wl12xx/spi.c
index 12421a64d89..92caa7ce605 100644
--- a/drivers/net/wireless/wl12xx/spi.c
+++ b/drivers/net/wireless/wl12xx/spi.c
@@ -27,6 +27,7 @@
27#include <linux/crc7.h> 27#include <linux/crc7.h>
28#include <linux/spi/spi.h> 28#include <linux/spi/spi.h>
29#include <linux/wl12xx.h> 29#include <linux/wl12xx.h>
30#include <linux/platform_device.h>
30#include <linux/slab.h> 31#include <linux/slab.h>
31 32
32#include "wl12xx.h" 33#include "wl12xx.h"
@@ -69,35 +70,22 @@
69 70
70#define WSPI_MAX_NUM_OF_CHUNKS (WL1271_AGGR_BUFFER_SIZE / WSPI_MAX_CHUNK_SIZE) 71#define WSPI_MAX_NUM_OF_CHUNKS (WL1271_AGGR_BUFFER_SIZE / WSPI_MAX_CHUNK_SIZE)
71 72
72static inline struct spi_device *wl_to_spi(struct wl1271 *wl) 73struct wl12xx_spi_glue {
73{ 74 struct device *dev;
74 return wl->if_priv; 75 struct platform_device *core;
75} 76};
76
77static struct device *wl1271_spi_wl_to_dev(struct wl1271 *wl)
78{
79 return &(wl_to_spi(wl)->dev);
80}
81
82static void wl1271_spi_disable_interrupts(struct wl1271 *wl)
83{
84 disable_irq(wl->irq);
85}
86
87static void wl1271_spi_enable_interrupts(struct wl1271 *wl)
88{
89 enable_irq(wl->irq);
90}
91 77
92static void wl1271_spi_reset(struct wl1271 *wl) 78static void wl12xx_spi_reset(struct device *child)
93{ 79{
80 struct wl12xx_spi_glue *glue = dev_get_drvdata(child->parent);
94 u8 *cmd; 81 u8 *cmd;
95 struct spi_transfer t; 82 struct spi_transfer t;
96 struct spi_message m; 83 struct spi_message m;
97 84
98 cmd = kzalloc(WSPI_INIT_CMD_LEN, GFP_KERNEL); 85 cmd = kzalloc(WSPI_INIT_CMD_LEN, GFP_KERNEL);
99 if (!cmd) { 86 if (!cmd) {
100 wl1271_error("could not allocate cmd for spi reset"); 87 dev_err(child->parent,
88 "could not allocate cmd for spi reset\n");
101 return; 89 return;
102 } 90 }
103 91
@@ -110,21 +98,22 @@ static void wl1271_spi_reset(struct wl1271 *wl)
110 t.len = WSPI_INIT_CMD_LEN; 98 t.len = WSPI_INIT_CMD_LEN;
111 spi_message_add_tail(&t, &m); 99 spi_message_add_tail(&t, &m);
112 100
113 spi_sync(wl_to_spi(wl), &m); 101 spi_sync(to_spi_device(glue->dev), &m);
114 102
115 wl1271_dump(DEBUG_SPI, "spi reset -> ", cmd, WSPI_INIT_CMD_LEN);
116 kfree(cmd); 103 kfree(cmd);
117} 104}
118 105
119static void wl1271_spi_init(struct wl1271 *wl) 106static void wl12xx_spi_init(struct device *child)
120{ 107{
108 struct wl12xx_spi_glue *glue = dev_get_drvdata(child->parent);
121 u8 crc[WSPI_INIT_CMD_CRC_LEN], *cmd; 109 u8 crc[WSPI_INIT_CMD_CRC_LEN], *cmd;
122 struct spi_transfer t; 110 struct spi_transfer t;
123 struct spi_message m; 111 struct spi_message m;
124 112
125 cmd = kzalloc(WSPI_INIT_CMD_LEN, GFP_KERNEL); 113 cmd = kzalloc(WSPI_INIT_CMD_LEN, GFP_KERNEL);
126 if (!cmd) { 114 if (!cmd) {
127 wl1271_error("could not allocate cmd for spi init"); 115 dev_err(child->parent,
116 "could not allocate cmd for spi init\n");
128 return; 117 return;
129 } 118 }
130 119
@@ -165,15 +154,16 @@ static void wl1271_spi_init(struct wl1271 *wl)
165 t.len = WSPI_INIT_CMD_LEN; 154 t.len = WSPI_INIT_CMD_LEN;
166 spi_message_add_tail(&t, &m); 155 spi_message_add_tail(&t, &m);
167 156
168 spi_sync(wl_to_spi(wl), &m); 157 spi_sync(to_spi_device(glue->dev), &m);
169 wl1271_dump(DEBUG_SPI, "spi init -> ", cmd, WSPI_INIT_CMD_LEN);
170 kfree(cmd); 158 kfree(cmd);
171} 159}
172 160
173#define WL1271_BUSY_WORD_TIMEOUT 1000 161#define WL1271_BUSY_WORD_TIMEOUT 1000
174 162
175static int wl1271_spi_read_busy(struct wl1271 *wl) 163static int wl12xx_spi_read_busy(struct device *child)
176{ 164{
165 struct wl12xx_spi_glue *glue = dev_get_drvdata(child->parent);
166 struct wl1271 *wl = dev_get_drvdata(child);
177 struct spi_transfer t[1]; 167 struct spi_transfer t[1];
178 struct spi_message m; 168 struct spi_message m;
179 u32 *busy_buf; 169 u32 *busy_buf;
@@ -194,20 +184,22 @@ static int wl1271_spi_read_busy(struct wl1271 *wl)
194 t[0].len = sizeof(u32); 184 t[0].len = sizeof(u32);
195 t[0].cs_change = true; 185 t[0].cs_change = true;
196 spi_message_add_tail(&t[0], &m); 186 spi_message_add_tail(&t[0], &m);
197 spi_sync(wl_to_spi(wl), &m); 187 spi_sync(to_spi_device(glue->dev), &m);
198 188
199 if (*busy_buf & 0x1) 189 if (*busy_buf & 0x1)
200 return 0; 190 return 0;
201 } 191 }
202 192
203 /* The SPI bus is unresponsive, the read failed. */ 193 /* The SPI bus is unresponsive, the read failed. */
204 wl1271_error("SPI read busy-word timeout!\n"); 194 dev_err(child->parent, "SPI read busy-word timeout!\n");
205 return -ETIMEDOUT; 195 return -ETIMEDOUT;
206} 196}
207 197
208static void wl1271_spi_raw_read(struct wl1271 *wl, int addr, void *buf, 198static void wl12xx_spi_raw_read(struct device *child, int addr, void *buf,
209 size_t len, bool fixed) 199 size_t len, bool fixed)
210{ 200{
201 struct wl12xx_spi_glue *glue = dev_get_drvdata(child->parent);
202 struct wl1271 *wl = dev_get_drvdata(child);
211 struct spi_transfer t[2]; 203 struct spi_transfer t[2];
212 struct spi_message m; 204 struct spi_message m;
213 u32 *busy_buf; 205 u32 *busy_buf;
@@ -243,10 +235,10 @@ static void wl1271_spi_raw_read(struct wl1271 *wl, int addr, void *buf,
243 t[1].cs_change = true; 235 t[1].cs_change = true;
244 spi_message_add_tail(&t[1], &m); 236 spi_message_add_tail(&t[1], &m);
245 237
246 spi_sync(wl_to_spi(wl), &m); 238 spi_sync(to_spi_device(glue->dev), &m);
247 239
248 if (!(busy_buf[WL1271_BUSY_WORD_CNT - 1] & 0x1) && 240 if (!(busy_buf[WL1271_BUSY_WORD_CNT - 1] & 0x1) &&
249 wl1271_spi_read_busy(wl)) { 241 wl12xx_spi_read_busy(child)) {
250 memset(buf, 0, chunk_len); 242 memset(buf, 0, chunk_len);
251 return; 243 return;
252 } 244 }
@@ -259,10 +251,7 @@ static void wl1271_spi_raw_read(struct wl1271 *wl, int addr, void *buf,
259 t[0].cs_change = true; 251 t[0].cs_change = true;
260 spi_message_add_tail(&t[0], &m); 252 spi_message_add_tail(&t[0], &m);
261 253
262 spi_sync(wl_to_spi(wl), &m); 254 spi_sync(to_spi_device(glue->dev), &m);
263
264 wl1271_dump(DEBUG_SPI, "spi_read cmd -> ", cmd, sizeof(*cmd));
265 wl1271_dump(DEBUG_SPI, "spi_read buf <- ", buf, chunk_len);
266 255
267 if (!fixed) 256 if (!fixed)
268 addr += chunk_len; 257 addr += chunk_len;
@@ -271,9 +260,10 @@ static void wl1271_spi_raw_read(struct wl1271 *wl, int addr, void *buf,
271 } 260 }
272} 261}
273 262
274static void wl1271_spi_raw_write(struct wl1271 *wl, int addr, void *buf, 263static void wl12xx_spi_raw_write(struct device *child, int addr, void *buf,
275 size_t len, bool fixed) 264 size_t len, bool fixed)
276{ 265{
266 struct wl12xx_spi_glue *glue = dev_get_drvdata(child->parent);
277 struct spi_transfer t[2 * WSPI_MAX_NUM_OF_CHUNKS]; 267 struct spi_transfer t[2 * WSPI_MAX_NUM_OF_CHUNKS];
278 struct spi_message m; 268 struct spi_message m;
279 u32 commands[WSPI_MAX_NUM_OF_CHUNKS]; 269 u32 commands[WSPI_MAX_NUM_OF_CHUNKS];
@@ -308,9 +298,6 @@ static void wl1271_spi_raw_write(struct wl1271 *wl, int addr, void *buf,
308 t[i].len = chunk_len; 298 t[i].len = chunk_len;
309 spi_message_add_tail(&t[i++], &m); 299 spi_message_add_tail(&t[i++], &m);
310 300
311 wl1271_dump(DEBUG_SPI, "spi_write cmd -> ", cmd, sizeof(*cmd));
312 wl1271_dump(DEBUG_SPI, "spi_write buf -> ", buf, chunk_len);
313
314 if (!fixed) 301 if (!fixed)
315 addr += chunk_len; 302 addr += chunk_len;
316 buf += chunk_len; 303 buf += chunk_len;
@@ -318,72 +305,41 @@ static void wl1271_spi_raw_write(struct wl1271 *wl, int addr, void *buf,
318 cmd++; 305 cmd++;
319 } 306 }
320 307
321 spi_sync(wl_to_spi(wl), &m); 308 spi_sync(to_spi_device(glue->dev), &m);
322}
323
324static irqreturn_t wl1271_hardirq(int irq, void *cookie)
325{
326 struct wl1271 *wl = cookie;
327 unsigned long flags;
328
329 wl1271_debug(DEBUG_IRQ, "IRQ");
330
331 /* complete the ELP completion */
332 spin_lock_irqsave(&wl->wl_lock, flags);
333 set_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags);
334 if (wl->elp_compl) {
335 complete(wl->elp_compl);
336 wl->elp_compl = NULL;
337 }
338 spin_unlock_irqrestore(&wl->wl_lock, flags);
339
340 return IRQ_WAKE_THREAD;
341}
342
343static int wl1271_spi_set_power(struct wl1271 *wl, bool enable)
344{
345 if (wl->set_power)
346 wl->set_power(enable);
347
348 return 0;
349} 309}
350 310
351static struct wl1271_if_operations spi_ops = { 311static struct wl1271_if_operations spi_ops = {
352 .read = wl1271_spi_raw_read, 312 .read = wl12xx_spi_raw_read,
353 .write = wl1271_spi_raw_write, 313 .write = wl12xx_spi_raw_write,
354 .reset = wl1271_spi_reset, 314 .reset = wl12xx_spi_reset,
355 .init = wl1271_spi_init, 315 .init = wl12xx_spi_init,
356 .power = wl1271_spi_set_power,
357 .dev = wl1271_spi_wl_to_dev,
358 .enable_irq = wl1271_spi_enable_interrupts,
359 .disable_irq = wl1271_spi_disable_interrupts,
360 .set_block_size = NULL, 316 .set_block_size = NULL,
361}; 317};
362 318
363static int __devinit wl1271_probe(struct spi_device *spi) 319static int __devinit wl1271_probe(struct spi_device *spi)
364{ 320{
321 struct wl12xx_spi_glue *glue;
365 struct wl12xx_platform_data *pdata; 322 struct wl12xx_platform_data *pdata;
366 struct ieee80211_hw *hw; 323 struct resource res[1];
367 struct wl1271 *wl; 324 int ret = -ENOMEM;
368 unsigned long irqflags;
369 int ret;
370 325
371 pdata = spi->dev.platform_data; 326 pdata = spi->dev.platform_data;
372 if (!pdata) { 327 if (!pdata) {
373 wl1271_error("no platform data"); 328 dev_err(&spi->dev, "no platform data\n");
374 return -ENODEV; 329 return -ENODEV;
375 } 330 }
376 331
377 hw = wl1271_alloc_hw(); 332 pdata->ops = &spi_ops;
378 if (IS_ERR(hw))
379 return PTR_ERR(hw);
380 333
381 wl = hw->priv; 334 glue = kzalloc(sizeof(*glue), GFP_KERNEL);
335 if (!glue) {
336 dev_err(&spi->dev, "can't allocate glue\n");
337 goto out;
338 }
382 339
383 dev_set_drvdata(&spi->dev, wl); 340 glue->dev = &spi->dev;
384 wl->if_priv = spi;
385 341
386 wl->if_ops = &spi_ops; 342 spi_set_drvdata(spi, glue);
387 343
388 /* This is the only SPI value that we need to set here, the rest 344 /* This is the only SPI value that we need to set here, the rest
389 * comes from the board-peripherals file */ 345 * comes from the board-peripherals file */
@@ -391,69 +347,61 @@ static int __devinit wl1271_probe(struct spi_device *spi)
391 347
392 ret = spi_setup(spi); 348 ret = spi_setup(spi);
393 if (ret < 0) { 349 if (ret < 0) {
394 wl1271_error("spi_setup failed"); 350 dev_err(glue->dev, "spi_setup failed\n");
395 goto out_free; 351 goto out_free_glue;
396 } 352 }
397 353
398 wl->set_power = pdata->set_power; 354 glue->core = platform_device_alloc("wl12xx", -1);
399 if (!wl->set_power) { 355 if (!glue->core) {
400 wl1271_error("set power function missing in platform data"); 356 dev_err(glue->dev, "can't allocate platform_device\n");
401 ret = -ENODEV; 357 ret = -ENOMEM;
402 goto out_free; 358 goto out_free_glue;
403 } 359 }
404 360
405 wl->ref_clock = pdata->board_ref_clock; 361 glue->core->dev.parent = &spi->dev;
406 wl->tcxo_clock = pdata->board_tcxo_clock;
407 wl->platform_quirks = pdata->platform_quirks;
408 362
409 if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ) 363 memset(res, 0x00, sizeof(res));
410 irqflags = IRQF_TRIGGER_RISING;
411 else
412 irqflags = IRQF_TRIGGER_HIGH | IRQF_ONESHOT;
413 364
414 wl->irq = spi->irq; 365 res[0].start = spi->irq;
415 if (wl->irq < 0) { 366 res[0].flags = IORESOURCE_IRQ;
416 wl1271_error("irq missing in platform data"); 367 res[0].name = "irq";
417 ret = -ENODEV;
418 goto out_free;
419 }
420 368
421 ret = request_threaded_irq(wl->irq, wl1271_hardirq, wl1271_irq, 369 ret = platform_device_add_resources(glue->core, res, ARRAY_SIZE(res));
422 irqflags, 370 if (ret) {
423 DRIVER_NAME, wl); 371 dev_err(glue->dev, "can't add resources\n");
424 if (ret < 0) { 372 goto out_dev_put;
425 wl1271_error("request_irq() failed: %d", ret);
426 goto out_free;
427 } 373 }
428 374
429 disable_irq(wl->irq); 375 ret = platform_device_add_data(glue->core, pdata, sizeof(*pdata));
430 376 if (ret) {
431 ret = wl1271_init_ieee80211(wl); 377 dev_err(glue->dev, "can't add platform data\n");
432 if (ret) 378 goto out_dev_put;
433 goto out_irq; 379 }
434 380
435 ret = wl1271_register_hw(wl); 381 ret = platform_device_add(glue->core);
436 if (ret) 382 if (ret) {
437 goto out_irq; 383 dev_err(glue->dev, "can't register platform device\n");
384 goto out_dev_put;
385 }
438 386
439 return 0; 387 return 0;
440 388
441 out_irq: 389out_dev_put:
442 free_irq(wl->irq, wl); 390 platform_device_put(glue->core);
443
444 out_free:
445 wl1271_free_hw(wl);
446 391
392out_free_glue:
393 kfree(glue);
394out:
447 return ret; 395 return ret;
448} 396}
449 397
450static int __devexit wl1271_remove(struct spi_device *spi) 398static int __devexit wl1271_remove(struct spi_device *spi)
451{ 399{
452 struct wl1271 *wl = dev_get_drvdata(&spi->dev); 400 struct wl12xx_spi_glue *glue = spi_get_drvdata(spi);
453 401
454 wl1271_unregister_hw(wl); 402 platform_device_del(glue->core);
455 free_irq(wl->irq, wl); 403 platform_device_put(glue->core);
456 wl1271_free_hw(wl); 404 kfree(glue);
457 405
458 return 0; 406 return 0;
459} 407}
diff --git a/drivers/net/wireless/wl12xx/testmode.c b/drivers/net/wireless/wl12xx/testmode.c
index 4ae8effaee2..978cf2de713 100644
--- a/drivers/net/wireless/wl12xx/testmode.c
+++ b/drivers/net/wireless/wl12xx/testmode.c
@@ -26,8 +26,10 @@
26#include <net/genetlink.h> 26#include <net/genetlink.h>
27 27
28#include "wl12xx.h" 28#include "wl12xx.h"
29#include "debug.h"
29#include "acx.h" 30#include "acx.h"
30#include "reg.h" 31#include "reg.h"
32#include "ps.h"
31 33
32#define WL1271_TM_MAX_DATA_LENGTH 1024 34#define WL1271_TM_MAX_DATA_LENGTH 1024
33 35
@@ -87,31 +89,47 @@ static int wl1271_tm_cmd_test(struct wl1271 *wl, struct nlattr *tb[])
87 return -EMSGSIZE; 89 return -EMSGSIZE;
88 90
89 mutex_lock(&wl->mutex); 91 mutex_lock(&wl->mutex);
90 ret = wl1271_cmd_test(wl, buf, buf_len, answer);
91 mutex_unlock(&wl->mutex);
92 92
93 if (wl->state == WL1271_STATE_OFF) {
94 ret = -EINVAL;
95 goto out;
96 }
97
98 ret = wl1271_ps_elp_wakeup(wl);
99 if (ret < 0)
100 goto out;
101
102 ret = wl1271_cmd_test(wl, buf, buf_len, answer);
93 if (ret < 0) { 103 if (ret < 0) {
94 wl1271_warning("testmode cmd test failed: %d", ret); 104 wl1271_warning("testmode cmd test failed: %d", ret);
95 return ret; 105 goto out_sleep;
96 } 106 }
97 107
98 if (answer) { 108 if (answer) {
99 len = nla_total_size(buf_len); 109 len = nla_total_size(buf_len);
100 skb = cfg80211_testmode_alloc_reply_skb(wl->hw->wiphy, len); 110 skb = cfg80211_testmode_alloc_reply_skb(wl->hw->wiphy, len);
101 if (!skb) 111 if (!skb) {
102 return -ENOMEM; 112 ret = -ENOMEM;
113 goto out_sleep;
114 }
103 115
104 NLA_PUT(skb, WL1271_TM_ATTR_DATA, buf_len, buf); 116 NLA_PUT(skb, WL1271_TM_ATTR_DATA, buf_len, buf);
105 ret = cfg80211_testmode_reply(skb); 117 ret = cfg80211_testmode_reply(skb);
106 if (ret < 0) 118 if (ret < 0)
107 return ret; 119 goto out_sleep;
108 } 120 }
109 121
110 return 0; 122out_sleep:
123 wl1271_ps_elp_sleep(wl);
124out:
125 mutex_unlock(&wl->mutex);
126
127 return ret;
111 128
112nla_put_failure: 129nla_put_failure:
113 kfree_skb(skb); 130 kfree_skb(skb);
114 return -EMSGSIZE; 131 ret = -EMSGSIZE;
132 goto out_sleep;
115} 133}
116 134
117static int wl1271_tm_cmd_interrogate(struct wl1271 *wl, struct nlattr *tb[]) 135static int wl1271_tm_cmd_interrogate(struct wl1271 *wl, struct nlattr *tb[])
@@ -128,33 +146,53 @@ static int wl1271_tm_cmd_interrogate(struct wl1271 *wl, struct nlattr *tb[])
128 146
129 ie_id = nla_get_u8(tb[WL1271_TM_ATTR_IE_ID]); 147 ie_id = nla_get_u8(tb[WL1271_TM_ATTR_IE_ID]);
130 148
149 mutex_lock(&wl->mutex);
150
151 if (wl->state == WL1271_STATE_OFF) {
152 ret = -EINVAL;
153 goto out;
154 }
155
156 ret = wl1271_ps_elp_wakeup(wl);
157 if (ret < 0)
158 goto out;
159
131 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 160 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
132 if (!cmd) 161 if (!cmd) {
133 return -ENOMEM; 162 ret = -ENOMEM;
163 goto out_sleep;
164 }
134 165
135 mutex_lock(&wl->mutex);
136 ret = wl1271_cmd_interrogate(wl, ie_id, cmd, sizeof(*cmd)); 166 ret = wl1271_cmd_interrogate(wl, ie_id, cmd, sizeof(*cmd));
137 mutex_unlock(&wl->mutex);
138
139 if (ret < 0) { 167 if (ret < 0) {
140 wl1271_warning("testmode cmd interrogate failed: %d", ret); 168 wl1271_warning("testmode cmd interrogate failed: %d", ret);
141 kfree(cmd); 169 goto out_free;
142 return ret;
143 } 170 }
144 171
145 skb = cfg80211_testmode_alloc_reply_skb(wl->hw->wiphy, sizeof(*cmd)); 172 skb = cfg80211_testmode_alloc_reply_skb(wl->hw->wiphy, sizeof(*cmd));
146 if (!skb) { 173 if (!skb) {
147 kfree(cmd); 174 ret = -ENOMEM;
148 return -ENOMEM; 175 goto out_free;
149 } 176 }
150 177
151 NLA_PUT(skb, WL1271_TM_ATTR_DATA, sizeof(*cmd), cmd); 178 NLA_PUT(skb, WL1271_TM_ATTR_DATA, sizeof(*cmd), cmd);
179 ret = cfg80211_testmode_reply(skb);
180 if (ret < 0)
181 goto out_free;
182
183out_free:
184 kfree(cmd);
185out_sleep:
186 wl1271_ps_elp_sleep(wl);
187out:
188 mutex_unlock(&wl->mutex);
152 189
153 return 0; 190 return ret;
154 191
155nla_put_failure: 192nla_put_failure:
156 kfree_skb(skb); 193 kfree_skb(skb);
157 return -EMSGSIZE; 194 ret = -EMSGSIZE;
195 goto out_free;
158} 196}
159 197
160static int wl1271_tm_cmd_configure(struct wl1271 *wl, struct nlattr *tb[]) 198static int wl1271_tm_cmd_configure(struct wl1271 *wl, struct nlattr *tb[])
diff --git a/drivers/net/wireless/wl12xx/tx.c b/drivers/net/wireless/wl12xx/tx.c
index bad9e29d49b..36eb0d66fd6 100644
--- a/drivers/net/wireless/wl12xx/tx.c
+++ b/drivers/net/wireless/wl12xx/tx.c
@@ -26,22 +26,24 @@
26#include <linux/etherdevice.h> 26#include <linux/etherdevice.h>
27 27
28#include "wl12xx.h" 28#include "wl12xx.h"
29#include "debug.h"
29#include "io.h" 30#include "io.h"
30#include "reg.h" 31#include "reg.h"
31#include "ps.h" 32#include "ps.h"
32#include "tx.h" 33#include "tx.h"
33#include "event.h" 34#include "event.h"
34 35
35static int wl1271_set_default_wep_key(struct wl1271 *wl, u8 id) 36static int wl1271_set_default_wep_key(struct wl1271 *wl,
37 struct wl12xx_vif *wlvif, u8 id)
36{ 38{
37 int ret; 39 int ret;
38 bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS); 40 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
39 41
40 if (is_ap) 42 if (is_ap)
41 ret = wl12xx_cmd_set_default_wep_key(wl, id, 43 ret = wl12xx_cmd_set_default_wep_key(wl, id,
42 wl->ap_bcast_hlid); 44 wlvif->ap.bcast_hlid);
43 else 45 else
44 ret = wl12xx_cmd_set_default_wep_key(wl, id, wl->sta_hlid); 46 ret = wl12xx_cmd_set_default_wep_key(wl, id, wlvif->sta.hlid);
45 47
46 if (ret < 0) 48 if (ret < 0)
47 return ret; 49 return ret;
@@ -76,7 +78,8 @@ static void wl1271_free_tx_id(struct wl1271 *wl, int id)
76} 78}
77 79
78static int wl1271_tx_update_filters(struct wl1271 *wl, 80static int wl1271_tx_update_filters(struct wl1271 *wl,
79 struct sk_buff *skb) 81 struct wl12xx_vif *wlvif,
82 struct sk_buff *skb)
80{ 83{
81 struct ieee80211_hdr *hdr; 84 struct ieee80211_hdr *hdr;
82 int ret; 85 int ret;
@@ -92,15 +95,11 @@ static int wl1271_tx_update_filters(struct wl1271 *wl,
92 if (!ieee80211_is_auth(hdr->frame_control)) 95 if (!ieee80211_is_auth(hdr->frame_control))
93 return 0; 96 return 0;
94 97
95 if (wl->dev_hlid != WL12XX_INVALID_LINK_ID) 98 if (wlvif->dev_hlid != WL12XX_INVALID_LINK_ID)
96 goto out; 99 goto out;
97 100
98 wl1271_debug(DEBUG_CMD, "starting device role for roaming"); 101 wl1271_debug(DEBUG_CMD, "starting device role for roaming");
99 ret = wl12xx_cmd_role_start_dev(wl); 102 ret = wl12xx_start_dev(wl, wlvif);
100 if (ret < 0)
101 goto out;
102
103 ret = wl12xx_roc(wl, wl->dev_role_id);
104 if (ret < 0) 103 if (ret < 0)
105 goto out; 104 goto out;
106out: 105out:
@@ -123,18 +122,16 @@ static void wl1271_tx_ap_update_inconnection_sta(struct wl1271 *wl,
123 wl1271_acx_set_inconnection_sta(wl, hdr->addr1); 122 wl1271_acx_set_inconnection_sta(wl, hdr->addr1);
124} 123}
125 124
126static void wl1271_tx_regulate_link(struct wl1271 *wl, u8 hlid) 125static void wl1271_tx_regulate_link(struct wl1271 *wl,
126 struct wl12xx_vif *wlvif,
127 u8 hlid)
127{ 128{
128 bool fw_ps, single_sta; 129 bool fw_ps, single_sta;
129 u8 tx_pkts; 130 u8 tx_pkts;
130 131
131 /* only regulate station links */ 132 if (WARN_ON(!test_bit(hlid, wlvif->links_map)))
132 if (hlid < WL1271_AP_STA_HLID_START)
133 return; 133 return;
134 134
135 if (WARN_ON(!wl1271_is_active_sta(wl, hlid)))
136 return;
137
138 fw_ps = test_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map); 135 fw_ps = test_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map);
139 tx_pkts = wl->links[hlid].allocated_pkts; 136 tx_pkts = wl->links[hlid].allocated_pkts;
140 single_sta = (wl->active_sta_count == 1); 137 single_sta = (wl->active_sta_count == 1);
@@ -146,7 +143,7 @@ static void wl1271_tx_regulate_link(struct wl1271 *wl, u8 hlid)
146 * case FW-memory congestion is not a problem. 143 * case FW-memory congestion is not a problem.
147 */ 144 */
148 if (!single_sta && fw_ps && tx_pkts >= WL1271_PS_STA_MAX_PACKETS) 145 if (!single_sta && fw_ps && tx_pkts >= WL1271_PS_STA_MAX_PACKETS)
149 wl1271_ps_link_start(wl, hlid, true); 146 wl12xx_ps_link_start(wl, wlvif, hlid, true);
150} 147}
151 148
152bool wl12xx_is_dummy_packet(struct wl1271 *wl, struct sk_buff *skb) 149bool wl12xx_is_dummy_packet(struct wl1271 *wl, struct sk_buff *skb)
@@ -154,7 +151,8 @@ bool wl12xx_is_dummy_packet(struct wl1271 *wl, struct sk_buff *skb)
154 return wl->dummy_packet == skb; 151 return wl->dummy_packet == skb;
155} 152}
156 153
157u8 wl12xx_tx_get_hlid_ap(struct wl1271 *wl, struct sk_buff *skb) 154u8 wl12xx_tx_get_hlid_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif,
155 struct sk_buff *skb)
158{ 156{
159 struct ieee80211_tx_info *control = IEEE80211_SKB_CB(skb); 157 struct ieee80211_tx_info *control = IEEE80211_SKB_CB(skb);
160 158
@@ -167,49 +165,51 @@ u8 wl12xx_tx_get_hlid_ap(struct wl1271 *wl, struct sk_buff *skb)
167 } else { 165 } else {
168 struct ieee80211_hdr *hdr; 166 struct ieee80211_hdr *hdr;
169 167
170 if (!test_bit(WL1271_FLAG_AP_STARTED, &wl->flags)) 168 if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags))
171 return wl->system_hlid; 169 return wl->system_hlid;
172 170
173 hdr = (struct ieee80211_hdr *)skb->data; 171 hdr = (struct ieee80211_hdr *)skb->data;
174 if (ieee80211_is_mgmt(hdr->frame_control)) 172 if (ieee80211_is_mgmt(hdr->frame_control))
175 return wl->ap_global_hlid; 173 return wlvif->ap.global_hlid;
176 else 174 else
177 return wl->ap_bcast_hlid; 175 return wlvif->ap.bcast_hlid;
178 } 176 }
179} 177}
180 178
181static u8 wl1271_tx_get_hlid(struct wl1271 *wl, struct sk_buff *skb) 179u8 wl12xx_tx_get_hlid(struct wl1271 *wl, struct wl12xx_vif *wlvif,
180 struct sk_buff *skb)
182{ 181{
183 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 182 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
184 183
185 if (wl12xx_is_dummy_packet(wl, skb)) 184 if (!wlvif || wl12xx_is_dummy_packet(wl, skb))
186 return wl->system_hlid; 185 return wl->system_hlid;
187 186
188 if (wl->bss_type == BSS_TYPE_AP_BSS) 187 if (wlvif->bss_type == BSS_TYPE_AP_BSS)
189 return wl12xx_tx_get_hlid_ap(wl, skb); 188 return wl12xx_tx_get_hlid_ap(wl, wlvif, skb);
190 189
191 wl1271_tx_update_filters(wl, skb); 190 wl1271_tx_update_filters(wl, wlvif, skb);
192 191
193 if ((test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags) || 192 if ((test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) ||
194 test_bit(WL1271_FLAG_IBSS_JOINED, &wl->flags)) && 193 test_bit(WLVIF_FLAG_IBSS_JOINED, &wlvif->flags)) &&
195 !ieee80211_is_auth(hdr->frame_control) && 194 !ieee80211_is_auth(hdr->frame_control) &&
196 !ieee80211_is_assoc_req(hdr->frame_control)) 195 !ieee80211_is_assoc_req(hdr->frame_control))
197 return wl->sta_hlid; 196 return wlvif->sta.hlid;
198 else 197 else
199 return wl->dev_hlid; 198 return wlvif->dev_hlid;
200} 199}
201 200
202static unsigned int wl12xx_calc_packet_alignment(struct wl1271 *wl, 201static unsigned int wl12xx_calc_packet_alignment(struct wl1271 *wl,
203 unsigned int packet_length) 202 unsigned int packet_length)
204{ 203{
205 if (wl->quirks & WL12XX_QUIRK_BLOCKSIZE_ALIGNMENT) 204 if (wl->quirks & WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT)
206 return ALIGN(packet_length, WL12XX_BUS_BLOCK_SIZE);
207 else
208 return ALIGN(packet_length, WL1271_TX_ALIGN_TO); 205 return ALIGN(packet_length, WL1271_TX_ALIGN_TO);
206 else
207 return ALIGN(packet_length, WL12XX_BUS_BLOCK_SIZE);
209} 208}
210 209
211static int wl1271_tx_allocate(struct wl1271 *wl, struct sk_buff *skb, u32 extra, 210static int wl1271_tx_allocate(struct wl1271 *wl, struct wl12xx_vif *wlvif,
212 u32 buf_offset, u8 hlid) 211 struct sk_buff *skb, u32 extra, u32 buf_offset,
212 u8 hlid)
213{ 213{
214 struct wl1271_tx_hw_descr *desc; 214 struct wl1271_tx_hw_descr *desc;
215 u32 total_len = skb->len + sizeof(struct wl1271_tx_hw_descr) + extra; 215 u32 total_len = skb->len + sizeof(struct wl1271_tx_hw_descr) + extra;
@@ -217,6 +217,7 @@ static int wl1271_tx_allocate(struct wl1271 *wl, struct sk_buff *skb, u32 extra,
217 u32 total_blocks; 217 u32 total_blocks;
218 int id, ret = -EBUSY, ac; 218 int id, ret = -EBUSY, ac;
219 u32 spare_blocks = wl->tx_spare_blocks; 219 u32 spare_blocks = wl->tx_spare_blocks;
220 bool is_dummy = false;
220 221
221 if (buf_offset + total_len > WL1271_AGGR_BUFFER_SIZE) 222 if (buf_offset + total_len > WL1271_AGGR_BUFFER_SIZE)
222 return -EAGAIN; 223 return -EAGAIN;
@@ -231,8 +232,10 @@ static int wl1271_tx_allocate(struct wl1271 *wl, struct sk_buff *skb, u32 extra,
231 len = wl12xx_calc_packet_alignment(wl, total_len); 232 len = wl12xx_calc_packet_alignment(wl, total_len);
232 233
233 /* in case of a dummy packet, use default amount of spare mem blocks */ 234 /* in case of a dummy packet, use default amount of spare mem blocks */
234 if (unlikely(wl12xx_is_dummy_packet(wl, skb))) 235 if (unlikely(wl12xx_is_dummy_packet(wl, skb))) {
236 is_dummy = true;
235 spare_blocks = TX_HW_BLOCK_SPARE_DEFAULT; 237 spare_blocks = TX_HW_BLOCK_SPARE_DEFAULT;
238 }
236 239
237 total_blocks = (len + TX_HW_BLOCK_SIZE - 1) / TX_HW_BLOCK_SIZE + 240 total_blocks = (len + TX_HW_BLOCK_SIZE - 1) / TX_HW_BLOCK_SIZE +
238 spare_blocks; 241 spare_blocks;
@@ -257,8 +260,9 @@ static int wl1271_tx_allocate(struct wl1271 *wl, struct sk_buff *skb, u32 extra,
257 ac = wl1271_tx_get_queue(skb_get_queue_mapping(skb)); 260 ac = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
258 wl->tx_allocated_pkts[ac]++; 261 wl->tx_allocated_pkts[ac]++;
259 262
260 if (wl->bss_type == BSS_TYPE_AP_BSS && 263 if (!is_dummy && wlvif &&
261 hlid >= WL1271_AP_STA_HLID_START) 264 wlvif->bss_type == BSS_TYPE_AP_BSS &&
265 test_bit(hlid, wlvif->ap.sta_hlid_map))
262 wl->links[hlid].allocated_pkts++; 266 wl->links[hlid].allocated_pkts++;
263 267
264 ret = 0; 268 ret = 0;
@@ -273,15 +277,16 @@ static int wl1271_tx_allocate(struct wl1271 *wl, struct sk_buff *skb, u32 extra,
273 return ret; 277 return ret;
274} 278}
275 279
276static void wl1271_tx_fill_hdr(struct wl1271 *wl, struct sk_buff *skb, 280static void wl1271_tx_fill_hdr(struct wl1271 *wl, struct wl12xx_vif *wlvif,
277 u32 extra, struct ieee80211_tx_info *control, 281 struct sk_buff *skb, u32 extra,
278 u8 hlid) 282 struct ieee80211_tx_info *control, u8 hlid)
279{ 283{
280 struct timespec ts; 284 struct timespec ts;
281 struct wl1271_tx_hw_descr *desc; 285 struct wl1271_tx_hw_descr *desc;
282 int aligned_len, ac, rate_idx; 286 int aligned_len, ac, rate_idx;
283 s64 hosttime; 287 s64 hosttime;
284 u16 tx_attr; 288 u16 tx_attr;
289 bool is_dummy;
285 290
286 desc = (struct wl1271_tx_hw_descr *) skb->data; 291 desc = (struct wl1271_tx_hw_descr *) skb->data;
287 292
@@ -298,7 +303,8 @@ static void wl1271_tx_fill_hdr(struct wl1271 *wl, struct sk_buff *skb,
298 hosttime = (timespec_to_ns(&ts) >> 10); 303 hosttime = (timespec_to_ns(&ts) >> 10);
299 desc->start_time = cpu_to_le32(hosttime - wl->time_offset); 304 desc->start_time = cpu_to_le32(hosttime - wl->time_offset);
300 305
301 if (wl->bss_type != BSS_TYPE_AP_BSS) 306 is_dummy = wl12xx_is_dummy_packet(wl, skb);
307 if (is_dummy || !wlvif || wlvif->bss_type != BSS_TYPE_AP_BSS)
302 desc->life_time = cpu_to_le16(TX_HW_MGMT_PKT_LIFETIME_TU); 308 desc->life_time = cpu_to_le16(TX_HW_MGMT_PKT_LIFETIME_TU);
303 else 309 else
304 desc->life_time = cpu_to_le16(TX_HW_AP_MODE_PKT_LIFETIME_TU); 310 desc->life_time = cpu_to_le16(TX_HW_AP_MODE_PKT_LIFETIME_TU);
@@ -307,39 +313,42 @@ static void wl1271_tx_fill_hdr(struct wl1271 *wl, struct sk_buff *skb,
307 ac = wl1271_tx_get_queue(skb_get_queue_mapping(skb)); 313 ac = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
308 desc->tid = skb->priority; 314 desc->tid = skb->priority;
309 315
310 if (wl12xx_is_dummy_packet(wl, skb)) { 316 if (is_dummy) {
311 /* 317 /*
312 * FW expects the dummy packet to have an invalid session id - 318 * FW expects the dummy packet to have an invalid session id -
313 * any session id that is different than the one set in the join 319 * any session id that is different than the one set in the join
314 */ 320 */
315 tx_attr = ((~wl->session_counter) << 321 tx_attr = (SESSION_COUNTER_INVALID <<
316 TX_HW_ATTR_OFST_SESSION_COUNTER) & 322 TX_HW_ATTR_OFST_SESSION_COUNTER) &
317 TX_HW_ATTR_SESSION_COUNTER; 323 TX_HW_ATTR_SESSION_COUNTER;
318 324
319 tx_attr |= TX_HW_ATTR_TX_DUMMY_REQ; 325 tx_attr |= TX_HW_ATTR_TX_DUMMY_REQ;
320 } else { 326 } else if (wlvif) {
321 /* configure the tx attributes */ 327 /* configure the tx attributes */
322 tx_attr = 328 tx_attr = wlvif->session_counter <<
323 wl->session_counter << TX_HW_ATTR_OFST_SESSION_COUNTER; 329 TX_HW_ATTR_OFST_SESSION_COUNTER;
324 } 330 }
325 331
326 desc->hlid = hlid; 332 desc->hlid = hlid;
327 333 if (is_dummy || !wlvif)
328 if (wl->bss_type != BSS_TYPE_AP_BSS) { 334 rate_idx = 0;
335 else if (wlvif->bss_type != BSS_TYPE_AP_BSS) {
329 /* if the packets are destined for AP (have a STA entry) 336 /* if the packets are destined for AP (have a STA entry)
330 send them with AP rate policies, otherwise use default 337 send them with AP rate policies, otherwise use default
331 basic rates */ 338 basic rates */
332 if (control->control.sta) 339 if (control->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
333 rate_idx = ACX_TX_AP_FULL_RATE; 340 rate_idx = wlvif->sta.p2p_rate_idx;
341 else if (control->control.sta)
342 rate_idx = wlvif->sta.ap_rate_idx;
334 else 343 else
335 rate_idx = ACX_TX_BASIC_RATE; 344 rate_idx = wlvif->sta.basic_rate_idx;
336 } else { 345 } else {
337 if (hlid == wl->ap_global_hlid) 346 if (hlid == wlvif->ap.global_hlid)
338 rate_idx = ACX_TX_AP_MODE_MGMT_RATE; 347 rate_idx = wlvif->ap.mgmt_rate_idx;
339 else if (hlid == wl->ap_bcast_hlid) 348 else if (hlid == wlvif->ap.bcast_hlid)
340 rate_idx = ACX_TX_AP_MODE_BCST_RATE; 349 rate_idx = wlvif->ap.bcast_rate_idx;
341 else 350 else
342 rate_idx = ac; 351 rate_idx = wlvif->ap.ucast_rate_idx[ac];
343 } 352 }
344 353
345 tx_attr |= rate_idx << TX_HW_ATTR_OFST_RATE_POLICY; 354 tx_attr |= rate_idx << TX_HW_ATTR_OFST_RATE_POLICY;
@@ -379,20 +388,24 @@ static void wl1271_tx_fill_hdr(struct wl1271 *wl, struct sk_buff *skb,
379} 388}
380 389
381/* caller must hold wl->mutex */ 390/* caller must hold wl->mutex */
382static int wl1271_prepare_tx_frame(struct wl1271 *wl, struct sk_buff *skb, 391static int wl1271_prepare_tx_frame(struct wl1271 *wl, struct wl12xx_vif *wlvif,
383 u32 buf_offset) 392 struct sk_buff *skb, u32 buf_offset)
384{ 393{
385 struct ieee80211_tx_info *info; 394 struct ieee80211_tx_info *info;
386 u32 extra = 0; 395 u32 extra = 0;
387 int ret = 0; 396 int ret = 0;
388 u32 total_len; 397 u32 total_len;
389 u8 hlid; 398 u8 hlid;
399 bool is_dummy;
390 400
391 if (!skb) 401 if (!skb)
392 return -EINVAL; 402 return -EINVAL;
393 403
394 info = IEEE80211_SKB_CB(skb); 404 info = IEEE80211_SKB_CB(skb);
395 405
406 /* TODO: handle dummy packets on multi-vifs */
407 is_dummy = wl12xx_is_dummy_packet(wl, skb);
408
396 if (info->control.hw_key && 409 if (info->control.hw_key &&
397 info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP) 410 info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP)
398 extra = WL1271_TKIP_IV_SPACE; 411 extra = WL1271_TKIP_IV_SPACE;
@@ -405,29 +418,28 @@ static int wl1271_prepare_tx_frame(struct wl1271 *wl, struct sk_buff *skb,
405 is_wep = (cipher == WLAN_CIPHER_SUITE_WEP40) || 418 is_wep = (cipher == WLAN_CIPHER_SUITE_WEP40) ||
406 (cipher == WLAN_CIPHER_SUITE_WEP104); 419 (cipher == WLAN_CIPHER_SUITE_WEP104);
407 420
408 if (unlikely(is_wep && wl->default_key != idx)) { 421 if (unlikely(is_wep && wlvif->default_key != idx)) {
409 ret = wl1271_set_default_wep_key(wl, idx); 422 ret = wl1271_set_default_wep_key(wl, wlvif, idx);
410 if (ret < 0) 423 if (ret < 0)
411 return ret; 424 return ret;
412 wl->default_key = idx; 425 wlvif->default_key = idx;
413 } 426 }
414 } 427 }
415 428 hlid = wl12xx_tx_get_hlid(wl, wlvif, skb);
416 hlid = wl1271_tx_get_hlid(wl, skb);
417 if (hlid == WL12XX_INVALID_LINK_ID) { 429 if (hlid == WL12XX_INVALID_LINK_ID) {
418 wl1271_error("invalid hlid. dropping skb 0x%p", skb); 430 wl1271_error("invalid hlid. dropping skb 0x%p", skb);
419 return -EINVAL; 431 return -EINVAL;
420 } 432 }
421 433
422 ret = wl1271_tx_allocate(wl, skb, extra, buf_offset, hlid); 434 ret = wl1271_tx_allocate(wl, wlvif, skb, extra, buf_offset, hlid);
423 if (ret < 0) 435 if (ret < 0)
424 return ret; 436 return ret;
425 437
426 wl1271_tx_fill_hdr(wl, skb, extra, info, hlid); 438 wl1271_tx_fill_hdr(wl, wlvif, skb, extra, info, hlid);
427 439
428 if (wl->bss_type == BSS_TYPE_AP_BSS) { 440 if (!is_dummy && wlvif && wlvif->bss_type == BSS_TYPE_AP_BSS) {
429 wl1271_tx_ap_update_inconnection_sta(wl, skb); 441 wl1271_tx_ap_update_inconnection_sta(wl, skb);
430 wl1271_tx_regulate_link(wl, hlid); 442 wl1271_tx_regulate_link(wl, wlvif, hlid);
431 } 443 }
432 444
433 /* 445 /*
@@ -444,7 +456,7 @@ static int wl1271_prepare_tx_frame(struct wl1271 *wl, struct sk_buff *skb,
444 memset(wl->aggr_buf + buf_offset + skb->len, 0, total_len - skb->len); 456 memset(wl->aggr_buf + buf_offset + skb->len, 0, total_len - skb->len);
445 457
446 /* Revert side effects in the dummy packet skb, so it can be reused */ 458 /* Revert side effects in the dummy packet skb, so it can be reused */
447 if (wl12xx_is_dummy_packet(wl, skb)) 459 if (is_dummy)
448 skb_pull(skb, sizeof(struct wl1271_tx_hw_descr)); 460 skb_pull(skb, sizeof(struct wl1271_tx_hw_descr));
449 461
450 return total_len; 462 return total_len;
@@ -522,19 +534,18 @@ static struct sk_buff_head *wl1271_select_queue(struct wl1271 *wl,
522 return &queues[q]; 534 return &queues[q];
523} 535}
524 536
525static struct sk_buff *wl1271_sta_skb_dequeue(struct wl1271 *wl) 537static struct sk_buff *wl12xx_lnk_skb_dequeue(struct wl1271 *wl,
538 struct wl1271_link *lnk)
526{ 539{
527 struct sk_buff *skb = NULL; 540 struct sk_buff *skb;
528 unsigned long flags; 541 unsigned long flags;
529 struct sk_buff_head *queue; 542 struct sk_buff_head *queue;
530 543
531 queue = wl1271_select_queue(wl, wl->tx_queue); 544 queue = wl1271_select_queue(wl, lnk->tx_queue);
532 if (!queue) 545 if (!queue)
533 goto out; 546 return NULL;
534 547
535 skb = skb_dequeue(queue); 548 skb = skb_dequeue(queue);
536
537out:
538 if (skb) { 549 if (skb) {
539 int q = wl1271_tx_get_queue(skb_get_queue_mapping(skb)); 550 int q = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
540 spin_lock_irqsave(&wl->wl_lock, flags); 551 spin_lock_irqsave(&wl->wl_lock, flags);
@@ -545,43 +556,33 @@ out:
545 return skb; 556 return skb;
546} 557}
547 558
548static struct sk_buff *wl1271_ap_skb_dequeue(struct wl1271 *wl) 559static struct sk_buff *wl12xx_vif_skb_dequeue(struct wl1271 *wl,
560 struct wl12xx_vif *wlvif)
549{ 561{
550 struct sk_buff *skb = NULL; 562 struct sk_buff *skb = NULL;
551 unsigned long flags;
552 int i, h, start_hlid; 563 int i, h, start_hlid;
553 struct sk_buff_head *queue;
554 564
555 /* start from the link after the last one */ 565 /* start from the link after the last one */
556 start_hlid = (wl->last_tx_hlid + 1) % AP_MAX_LINKS; 566 start_hlid = (wlvif->last_tx_hlid + 1) % WL12XX_MAX_LINKS;
557 567
558 /* dequeue according to AC, round robin on each link */ 568 /* dequeue according to AC, round robin on each link */
559 for (i = 0; i < AP_MAX_LINKS; i++) { 569 for (i = 0; i < WL12XX_MAX_LINKS; i++) {
560 h = (start_hlid + i) % AP_MAX_LINKS; 570 h = (start_hlid + i) % WL12XX_MAX_LINKS;
561 571
562 /* only consider connected stations */ 572 /* only consider connected stations */
563 if (h >= WL1271_AP_STA_HLID_START && 573 if (!test_bit(h, wlvif->links_map))
564 !test_bit(h - WL1271_AP_STA_HLID_START, wl->ap_hlid_map))
565 continue; 574 continue;
566 575
567 queue = wl1271_select_queue(wl, wl->links[h].tx_queue); 576 skb = wl12xx_lnk_skb_dequeue(wl, &wl->links[h]);
568 if (!queue) 577 if (!skb)
569 continue; 578 continue;
570 579
571 skb = skb_dequeue(queue); 580 wlvif->last_tx_hlid = h;
572 if (skb) 581 break;
573 break;
574 } 582 }
575 583
576 if (skb) { 584 if (!skb)
577 int q = wl1271_tx_get_queue(skb_get_queue_mapping(skb)); 585 wlvif->last_tx_hlid = 0;
578 wl->last_tx_hlid = h;
579 spin_lock_irqsave(&wl->wl_lock, flags);
580 wl->tx_queue_count[q]--;
581 spin_unlock_irqrestore(&wl->wl_lock, flags);
582 } else {
583 wl->last_tx_hlid = 0;
584 }
585 586
586 return skb; 587 return skb;
587} 588}
@@ -589,12 +590,32 @@ static struct sk_buff *wl1271_ap_skb_dequeue(struct wl1271 *wl)
589static struct sk_buff *wl1271_skb_dequeue(struct wl1271 *wl) 590static struct sk_buff *wl1271_skb_dequeue(struct wl1271 *wl)
590{ 591{
591 unsigned long flags; 592 unsigned long flags;
593 struct wl12xx_vif *wlvif = wl->last_wlvif;
592 struct sk_buff *skb = NULL; 594 struct sk_buff *skb = NULL;
593 595
594 if (wl->bss_type == BSS_TYPE_AP_BSS) 596 if (wlvif) {
595 skb = wl1271_ap_skb_dequeue(wl); 597 wl12xx_for_each_wlvif_continue(wl, wlvif) {
596 else 598 skb = wl12xx_vif_skb_dequeue(wl, wlvif);
597 skb = wl1271_sta_skb_dequeue(wl); 599 if (skb) {
600 wl->last_wlvif = wlvif;
601 break;
602 }
603 }
604 }
605
606 /* do another pass */
607 if (!skb) {
608 wl12xx_for_each_wlvif(wl, wlvif) {
609 skb = wl12xx_vif_skb_dequeue(wl, wlvif);
610 if (skb) {
611 wl->last_wlvif = wlvif;
612 break;
613 }
614 }
615 }
616
617 if (!skb)
618 skb = wl12xx_lnk_skb_dequeue(wl, &wl->links[wl->system_hlid]);
598 619
599 if (!skb && 620 if (!skb &&
600 test_and_clear_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags)) { 621 test_and_clear_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags)) {
@@ -610,21 +631,21 @@ static struct sk_buff *wl1271_skb_dequeue(struct wl1271 *wl)
610 return skb; 631 return skb;
611} 632}
612 633
613static void wl1271_skb_queue_head(struct wl1271 *wl, struct sk_buff *skb) 634static void wl1271_skb_queue_head(struct wl1271 *wl, struct wl12xx_vif *wlvif,
635 struct sk_buff *skb)
614{ 636{
615 unsigned long flags; 637 unsigned long flags;
616 int q = wl1271_tx_get_queue(skb_get_queue_mapping(skb)); 638 int q = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
617 639
618 if (wl12xx_is_dummy_packet(wl, skb)) { 640 if (wl12xx_is_dummy_packet(wl, skb)) {
619 set_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags); 641 set_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags);
620 } else if (wl->bss_type == BSS_TYPE_AP_BSS) { 642 } else {
621 u8 hlid = wl1271_tx_get_hlid(wl, skb); 643 u8 hlid = wl12xx_tx_get_hlid(wl, wlvif, skb);
622 skb_queue_head(&wl->links[hlid].tx_queue[q], skb); 644 skb_queue_head(&wl->links[hlid].tx_queue[q], skb);
623 645
624 /* make sure we dequeue the same packet next time */ 646 /* make sure we dequeue the same packet next time */
625 wl->last_tx_hlid = (hlid + AP_MAX_LINKS - 1) % AP_MAX_LINKS; 647 wlvif->last_tx_hlid = (hlid + WL12XX_MAX_LINKS - 1) %
626 } else { 648 WL12XX_MAX_LINKS;
627 skb_queue_head(&wl->tx_queue[q], skb);
628 } 649 }
629 650
630 spin_lock_irqsave(&wl->wl_lock, flags); 651 spin_lock_irqsave(&wl->wl_lock, flags);
@@ -639,29 +660,71 @@ static bool wl1271_tx_is_data_present(struct sk_buff *skb)
639 return ieee80211_is_data_present(hdr->frame_control); 660 return ieee80211_is_data_present(hdr->frame_control);
640} 661}
641 662
663void wl12xx_rearm_rx_streaming(struct wl1271 *wl, unsigned long *active_hlids)
664{
665 struct wl12xx_vif *wlvif;
666 u32 timeout;
667 u8 hlid;
668
669 if (!wl->conf.rx_streaming.interval)
670 return;
671
672 if (!wl->conf.rx_streaming.always &&
673 !test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags))
674 return;
675
676 timeout = wl->conf.rx_streaming.duration;
677 wl12xx_for_each_wlvif_sta(wl, wlvif) {
678 bool found = false;
679 for_each_set_bit(hlid, active_hlids, WL12XX_MAX_LINKS) {
680 if (test_bit(hlid, wlvif->links_map)) {
681 found = true;
682 break;
683 }
684 }
685
686 if (!found)
687 continue;
688
689 /* enable rx streaming */
690 if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags))
691 ieee80211_queue_work(wl->hw,
692 &wlvif->rx_streaming_enable_work);
693
694 mod_timer(&wlvif->rx_streaming_timer,
695 jiffies + msecs_to_jiffies(timeout));
696 }
697}
698
642void wl1271_tx_work_locked(struct wl1271 *wl) 699void wl1271_tx_work_locked(struct wl1271 *wl)
643{ 700{
701 struct wl12xx_vif *wlvif;
644 struct sk_buff *skb; 702 struct sk_buff *skb;
703 struct wl1271_tx_hw_descr *desc;
645 u32 buf_offset = 0; 704 u32 buf_offset = 0;
646 bool sent_packets = false; 705 bool sent_packets = false;
647 bool had_data = false; 706 unsigned long active_hlids[BITS_TO_LONGS(WL12XX_MAX_LINKS)] = {0};
648 bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS);
649 int ret; 707 int ret;
650 708
651 if (unlikely(wl->state == WL1271_STATE_OFF)) 709 if (unlikely(wl->state == WL1271_STATE_OFF))
652 return; 710 return;
653 711
654 while ((skb = wl1271_skb_dequeue(wl))) { 712 while ((skb = wl1271_skb_dequeue(wl))) {
655 if (wl1271_tx_is_data_present(skb)) 713 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
656 had_data = true; 714 bool has_data = false;
657 715
658 ret = wl1271_prepare_tx_frame(wl, skb, buf_offset); 716 wlvif = NULL;
717 if (!wl12xx_is_dummy_packet(wl, skb) && info->control.vif)
718 wlvif = wl12xx_vif_to_data(info->control.vif);
719
720 has_data = wlvif && wl1271_tx_is_data_present(skb);
721 ret = wl1271_prepare_tx_frame(wl, wlvif, skb, buf_offset);
659 if (ret == -EAGAIN) { 722 if (ret == -EAGAIN) {
660 /* 723 /*
661 * Aggregation buffer is full. 724 * Aggregation buffer is full.
662 * Flush buffer and try again. 725 * Flush buffer and try again.
663 */ 726 */
664 wl1271_skb_queue_head(wl, skb); 727 wl1271_skb_queue_head(wl, wlvif, skb);
665 wl1271_write(wl, WL1271_SLV_MEM_DATA, wl->aggr_buf, 728 wl1271_write(wl, WL1271_SLV_MEM_DATA, wl->aggr_buf,
666 buf_offset, true); 729 buf_offset, true);
667 sent_packets = true; 730 sent_packets = true;
@@ -672,7 +735,7 @@ void wl1271_tx_work_locked(struct wl1271 *wl)
672 * Firmware buffer is full. 735 * Firmware buffer is full.
673 * Queue back last skb, and stop aggregating. 736 * Queue back last skb, and stop aggregating.
674 */ 737 */
675 wl1271_skb_queue_head(wl, skb); 738 wl1271_skb_queue_head(wl, wlvif, skb);
676 /* No work left, avoid scheduling redundant tx work */ 739 /* No work left, avoid scheduling redundant tx work */
677 set_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags); 740 set_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags);
678 goto out_ack; 741 goto out_ack;
@@ -682,6 +745,10 @@ void wl1271_tx_work_locked(struct wl1271 *wl)
682 } 745 }
683 buf_offset += ret; 746 buf_offset += ret;
684 wl->tx_packets_count++; 747 wl->tx_packets_count++;
748 if (has_data) {
749 desc = (struct wl1271_tx_hw_descr *) skb->data;
750 __set_bit(desc->hlid, active_hlids);
751 }
685 } 752 }
686 753
687out_ack: 754out_ack:
@@ -701,19 +768,7 @@ out_ack:
701 768
702 wl1271_handle_tx_low_watermark(wl); 769 wl1271_handle_tx_low_watermark(wl);
703 } 770 }
704 if (!is_ap && wl->conf.rx_streaming.interval && had_data && 771 wl12xx_rearm_rx_streaming(wl, active_hlids);
705 (wl->conf.rx_streaming.always ||
706 test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags))) {
707 u32 timeout = wl->conf.rx_streaming.duration;
708
709 /* enable rx streaming */
710 if (!test_bit(WL1271_FLAG_RX_STREAMING_STARTED, &wl->flags))
711 ieee80211_queue_work(wl->hw,
712 &wl->rx_streaming_enable_work);
713
714 mod_timer(&wl->rx_streaming_timer,
715 jiffies + msecs_to_jiffies(timeout));
716 }
717} 772}
718 773
719void wl1271_tx_work(struct work_struct *work) 774void wl1271_tx_work(struct work_struct *work)
@@ -737,6 +792,8 @@ static void wl1271_tx_complete_packet(struct wl1271 *wl,
737 struct wl1271_tx_hw_res_descr *result) 792 struct wl1271_tx_hw_res_descr *result)
738{ 793{
739 struct ieee80211_tx_info *info; 794 struct ieee80211_tx_info *info;
795 struct ieee80211_vif *vif;
796 struct wl12xx_vif *wlvif;
740 struct sk_buff *skb; 797 struct sk_buff *skb;
741 int id = result->id; 798 int id = result->id;
742 int rate = -1; 799 int rate = -1;
@@ -756,11 +813,16 @@ static void wl1271_tx_complete_packet(struct wl1271 *wl,
756 return; 813 return;
757 } 814 }
758 815
816 /* info->control is valid as long as we don't update info->status */
817 vif = info->control.vif;
818 wlvif = wl12xx_vif_to_data(vif);
819
759 /* update the TX status info */ 820 /* update the TX status info */
760 if (result->status == TX_SUCCESS) { 821 if (result->status == TX_SUCCESS) {
761 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) 822 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
762 info->flags |= IEEE80211_TX_STAT_ACK; 823 info->flags |= IEEE80211_TX_STAT_ACK;
763 rate = wl1271_rate_to_idx(result->rate_class_index, wl->band); 824 rate = wl1271_rate_to_idx(result->rate_class_index,
825 wlvif->band);
764 retries = result->ack_failures; 826 retries = result->ack_failures;
765 } else if (result->status == TX_RETRY_EXCEEDED) { 827 } else if (result->status == TX_RETRY_EXCEEDED) {
766 wl->stats.excessive_retries++; 828 wl->stats.excessive_retries++;
@@ -783,14 +845,14 @@ static void wl1271_tx_complete_packet(struct wl1271 *wl,
783 info->control.hw_key->cipher == WLAN_CIPHER_SUITE_CCMP || 845 info->control.hw_key->cipher == WLAN_CIPHER_SUITE_CCMP ||
784 info->control.hw_key->cipher == WL1271_CIPHER_SUITE_GEM)) { 846 info->control.hw_key->cipher == WL1271_CIPHER_SUITE_GEM)) {
785 u8 fw_lsb = result->tx_security_sequence_number_lsb; 847 u8 fw_lsb = result->tx_security_sequence_number_lsb;
786 u8 cur_lsb = wl->tx_security_last_seq_lsb; 848 u8 cur_lsb = wlvif->tx_security_last_seq_lsb;
787 849
788 /* 850 /*
789 * update security sequence number, taking care of potential 851 * update security sequence number, taking care of potential
790 * wrap-around 852 * wrap-around
791 */ 853 */
792 wl->tx_security_seq += (fw_lsb - cur_lsb + 256) % 256; 854 wlvif->tx_security_seq += (fw_lsb - cur_lsb) & 0xff;
793 wl->tx_security_last_seq_lsb = fw_lsb; 855 wlvif->tx_security_last_seq_lsb = fw_lsb;
794 } 856 }
795 857
796 /* remove private header from packet */ 858 /* remove private header from packet */
@@ -886,39 +948,30 @@ void wl1271_tx_reset_link_queues(struct wl1271 *wl, u8 hlid)
886} 948}
887 949
888/* caller must hold wl->mutex and TX must be stopped */ 950/* caller must hold wl->mutex and TX must be stopped */
889void wl1271_tx_reset(struct wl1271 *wl, bool reset_tx_queues) 951void wl12xx_tx_reset_wlvif(struct wl1271 *wl, struct wl12xx_vif *wlvif)
890{ 952{
891 int i; 953 int i;
892 struct sk_buff *skb;
893 struct ieee80211_tx_info *info;
894 954
895 /* TX failure */ 955 /* TX failure */
896 if (wl->bss_type == BSS_TYPE_AP_BSS) { 956 for_each_set_bit(i, wlvif->links_map, WL12XX_MAX_LINKS) {
897 for (i = 0; i < AP_MAX_LINKS; i++) { 957 if (wlvif->bss_type == BSS_TYPE_AP_BSS)
898 wl1271_free_sta(wl, i); 958 wl1271_free_sta(wl, wlvif, i);
899 wl1271_tx_reset_link_queues(wl, i); 959 else
900 wl->links[i].allocated_pkts = 0; 960 wlvif->sta.ba_rx_bitmap = 0;
901 wl->links[i].prev_freed_pkts = 0;
902 }
903
904 wl->last_tx_hlid = 0;
905 } else {
906 for (i = 0; i < NUM_TX_QUEUES; i++) {
907 while ((skb = skb_dequeue(&wl->tx_queue[i]))) {
908 wl1271_debug(DEBUG_TX, "freeing skb 0x%p",
909 skb);
910
911 if (!wl12xx_is_dummy_packet(wl, skb)) {
912 info = IEEE80211_SKB_CB(skb);
913 info->status.rates[0].idx = -1;
914 info->status.rates[0].count = 0;
915 ieee80211_tx_status_ni(wl->hw, skb);
916 }
917 }
918 }
919 961
920 wl->ba_rx_bitmap = 0; 962 wl1271_tx_reset_link_queues(wl, i);
963 wl->links[i].allocated_pkts = 0;
964 wl->links[i].prev_freed_pkts = 0;
921 } 965 }
966 wlvif->last_tx_hlid = 0;
967
968}
969/* caller must hold wl->mutex and TX must be stopped */
970void wl12xx_tx_reset(struct wl1271 *wl, bool reset_tx_queues)
971{
972 int i;
973 struct sk_buff *skb;
974 struct ieee80211_tx_info *info;
922 975
923 for (i = 0; i < NUM_TX_QUEUES; i++) 976 for (i = 0; i < NUM_TX_QUEUES; i++)
924 wl->tx_queue_count[i] = 0; 977 wl->tx_queue_count[i] = 0;
diff --git a/drivers/net/wireless/wl12xx/tx.h b/drivers/net/wireless/wl12xx/tx.h
index dc4f09adf08..2dbb24e6d54 100644
--- a/drivers/net/wireless/wl12xx/tx.h
+++ b/drivers/net/wireless/wl12xx/tx.h
@@ -206,18 +206,23 @@ static inline int wl1271_tx_total_queue_count(struct wl1271 *wl)
206void wl1271_tx_work(struct work_struct *work); 206void wl1271_tx_work(struct work_struct *work);
207void wl1271_tx_work_locked(struct wl1271 *wl); 207void wl1271_tx_work_locked(struct wl1271 *wl);
208void wl1271_tx_complete(struct wl1271 *wl); 208void wl1271_tx_complete(struct wl1271 *wl);
209void wl1271_tx_reset(struct wl1271 *wl, bool reset_tx_queues); 209void wl12xx_tx_reset_wlvif(struct wl1271 *wl, struct wl12xx_vif *wlvif);
210void wl12xx_tx_reset(struct wl1271 *wl, bool reset_tx_queues);
210void wl1271_tx_flush(struct wl1271 *wl); 211void wl1271_tx_flush(struct wl1271 *wl);
211u8 wl1271_rate_to_idx(int rate, enum ieee80211_band band); 212u8 wl1271_rate_to_idx(int rate, enum ieee80211_band band);
212u32 wl1271_tx_enabled_rates_get(struct wl1271 *wl, u32 rate_set, 213u32 wl1271_tx_enabled_rates_get(struct wl1271 *wl, u32 rate_set,
213 enum ieee80211_band rate_band); 214 enum ieee80211_band rate_band);
214u32 wl1271_tx_min_rate_get(struct wl1271 *wl, u32 rate_set); 215u32 wl1271_tx_min_rate_get(struct wl1271 *wl, u32 rate_set);
215u8 wl12xx_tx_get_hlid_ap(struct wl1271 *wl, struct sk_buff *skb); 216u8 wl12xx_tx_get_hlid_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif,
217 struct sk_buff *skb);
218u8 wl12xx_tx_get_hlid(struct wl1271 *wl, struct wl12xx_vif *wlvif,
219 struct sk_buff *skb);
216void wl1271_tx_reset_link_queues(struct wl1271 *wl, u8 hlid); 220void wl1271_tx_reset_link_queues(struct wl1271 *wl, u8 hlid);
217void wl1271_handle_tx_low_watermark(struct wl1271 *wl); 221void wl1271_handle_tx_low_watermark(struct wl1271 *wl);
218bool wl12xx_is_dummy_packet(struct wl1271 *wl, struct sk_buff *skb); 222bool wl12xx_is_dummy_packet(struct wl1271 *wl, struct sk_buff *skb);
223void wl12xx_rearm_rx_streaming(struct wl1271 *wl, unsigned long *active_hlids);
219 224
220/* from main.c */ 225/* from main.c */
221void wl1271_free_sta(struct wl1271 *wl, u8 hlid); 226void wl1271_free_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 hlid);
222 227
223#endif 228#endif
diff --git a/drivers/net/wireless/wl12xx/wl12xx.h b/drivers/net/wireless/wl12xx/wl12xx.h
index 1ec90fc7505..f1c911774bf 100644
--- a/drivers/net/wireless/wl12xx/wl12xx.h
+++ b/drivers/net/wireless/wl12xx/wl12xx.h
@@ -35,9 +35,6 @@
35#include "conf.h" 35#include "conf.h"
36#include "ini.h" 36#include "ini.h"
37 37
38#define DRIVER_NAME "wl1271"
39#define DRIVER_PREFIX DRIVER_NAME ": "
40
41/* 38/*
42 * FW versions support BA 11n 39 * FW versions support BA 11n
43 * versions marks x.x.x.50-60.x 40 * versions marks x.x.x.50-60.x
@@ -45,73 +42,6 @@
45#define WL12XX_BA_SUPPORT_FW_COST_VER2_START 50 42#define WL12XX_BA_SUPPORT_FW_COST_VER2_START 50
46#define WL12XX_BA_SUPPORT_FW_COST_VER2_END 60 43#define WL12XX_BA_SUPPORT_FW_COST_VER2_END 60
47 44
48enum {
49 DEBUG_NONE = 0,
50 DEBUG_IRQ = BIT(0),
51 DEBUG_SPI = BIT(1),
52 DEBUG_BOOT = BIT(2),
53 DEBUG_MAILBOX = BIT(3),
54 DEBUG_TESTMODE = BIT(4),
55 DEBUG_EVENT = BIT(5),
56 DEBUG_TX = BIT(6),
57 DEBUG_RX = BIT(7),
58 DEBUG_SCAN = BIT(8),
59 DEBUG_CRYPT = BIT(9),
60 DEBUG_PSM = BIT(10),
61 DEBUG_MAC80211 = BIT(11),
62 DEBUG_CMD = BIT(12),
63 DEBUG_ACX = BIT(13),
64 DEBUG_SDIO = BIT(14),
65 DEBUG_FILTERS = BIT(15),
66 DEBUG_ADHOC = BIT(16),
67 DEBUG_AP = BIT(17),
68 DEBUG_MASTER = (DEBUG_ADHOC | DEBUG_AP),
69 DEBUG_ALL = ~0,
70};
71
72extern u32 wl12xx_debug_level;
73
74#define DEBUG_DUMP_LIMIT 1024
75
76#define wl1271_error(fmt, arg...) \
77 pr_err(DRIVER_PREFIX "ERROR " fmt "\n", ##arg)
78
79#define wl1271_warning(fmt, arg...) \
80 pr_warning(DRIVER_PREFIX "WARNING " fmt "\n", ##arg)
81
82#define wl1271_notice(fmt, arg...) \
83 pr_info(DRIVER_PREFIX fmt "\n", ##arg)
84
85#define wl1271_info(fmt, arg...) \
86 pr_info(DRIVER_PREFIX fmt "\n", ##arg)
87
88#define wl1271_debug(level, fmt, arg...) \
89 do { \
90 if (level & wl12xx_debug_level) \
91 pr_debug(DRIVER_PREFIX fmt "\n", ##arg); \
92 } while (0)
93
94/* TODO: use pr_debug_hex_dump when it will be available */
95#define wl1271_dump(level, prefix, buf, len) \
96 do { \
97 if (level & wl12xx_debug_level) \
98 print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
99 DUMP_PREFIX_OFFSET, 16, 1, \
100 buf, \
101 min_t(size_t, len, DEBUG_DUMP_LIMIT), \
102 0); \
103 } while (0)
104
105#define wl1271_dump_ascii(level, prefix, buf, len) \
106 do { \
107 if (level & wl12xx_debug_level) \
108 print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
109 DUMP_PREFIX_OFFSET, 16, 1, \
110 buf, \
111 min_t(size_t, len, DEBUG_DUMP_LIMIT), \
112 true); \
113 } while (0)
114
115#define WL127X_FW_NAME "ti-connectivity/wl127x-fw-3.bin" 45#define WL127X_FW_NAME "ti-connectivity/wl127x-fw-3.bin"
116#define WL128X_FW_NAME "ti-connectivity/wl128x-fw-3.bin" 46#define WL128X_FW_NAME "ti-connectivity/wl128x-fw-3.bin"
117 47
@@ -142,16 +72,12 @@ extern u32 wl12xx_debug_level;
142#define WL12XX_INVALID_ROLE_ID 0xff 72#define WL12XX_INVALID_ROLE_ID 0xff
143#define WL12XX_INVALID_LINK_ID 0xff 73#define WL12XX_INVALID_LINK_ID 0xff
144 74
75#define WL12XX_MAX_RATE_POLICIES 16
76
145/* Defined by FW as 0. Will not be freed or allocated. */ 77/* Defined by FW as 0. Will not be freed or allocated. */
146#define WL12XX_SYSTEM_HLID 0 78#define WL12XX_SYSTEM_HLID 0
147 79
148/* 80/*
149 * TODO: we currently don't support multirole. remove
150 * this constant from the code when we do.
151 */
152#define WL1271_AP_STA_HLID_START 3
153
154/*
155 * When in AP-mode, we allow (at least) this number of packets 81 * When in AP-mode, we allow (at least) this number of packets
156 * to be transmitted to FW for a STA in PS-mode. Only when packets are 82 * to be transmitted to FW for a STA in PS-mode. Only when packets are
157 * present in the FW buffers it will wake the sleeping STA. We want to put 83 * present in the FW buffers it will wake the sleeping STA. We want to put
@@ -236,13 +162,6 @@ struct wl1271_stats {
236 162
237#define AP_MAX_STATIONS 8 163#define AP_MAX_STATIONS 8
238 164
239/* Broadcast and Global links + system link + links to stations */
240/*
241 * TODO: when WL1271_AP_STA_HLID_START is no longer constant, change all
242 * the places that use this.
243 */
244#define AP_MAX_LINKS (AP_MAX_STATIONS + WL1271_AP_STA_HLID_START)
245
246/* FW status registers */ 165/* FW status registers */
247struct wl12xx_fw_status { 166struct wl12xx_fw_status {
248 __le32 intr; 167 __le32 intr;
@@ -299,17 +218,14 @@ struct wl1271_scan {
299}; 218};
300 219
301struct wl1271_if_operations { 220struct wl1271_if_operations {
302 void (*read)(struct wl1271 *wl, int addr, void *buf, size_t len, 221 void (*read)(struct device *child, int addr, void *buf, size_t len,
303 bool fixed); 222 bool fixed);
304 void (*write)(struct wl1271 *wl, int addr, void *buf, size_t len, 223 void (*write)(struct device *child, int addr, void *buf, size_t len,
305 bool fixed); 224 bool fixed);
306 void (*reset)(struct wl1271 *wl); 225 void (*reset)(struct device *child);
307 void (*init)(struct wl1271 *wl); 226 void (*init)(struct device *child);
308 int (*power)(struct wl1271 *wl, bool enable); 227 int (*power)(struct device *child, bool enable);
309 struct device* (*dev)(struct wl1271 *wl); 228 void (*set_block_size) (struct device *child, unsigned int blksz);
310 void (*enable_irq)(struct wl1271 *wl);
311 void (*disable_irq)(struct wl1271 *wl);
312 void (*set_block_size) (struct wl1271 *wl, unsigned int blksz);
313}; 229};
314 230
315#define MAX_NUM_KEYS 14 231#define MAX_NUM_KEYS 14
@@ -326,29 +242,33 @@ struct wl1271_ap_key {
326}; 242};
327 243
328enum wl12xx_flags { 244enum wl12xx_flags {
329 WL1271_FLAG_STA_ASSOCIATED,
330 WL1271_FLAG_IBSS_JOINED,
331 WL1271_FLAG_GPIO_POWER, 245 WL1271_FLAG_GPIO_POWER,
332 WL1271_FLAG_TX_QUEUE_STOPPED, 246 WL1271_FLAG_TX_QUEUE_STOPPED,
333 WL1271_FLAG_TX_PENDING, 247 WL1271_FLAG_TX_PENDING,
334 WL1271_FLAG_IN_ELP, 248 WL1271_FLAG_IN_ELP,
335 WL1271_FLAG_ELP_REQUESTED, 249 WL1271_FLAG_ELP_REQUESTED,
336 WL1271_FLAG_PSM,
337 WL1271_FLAG_PSM_REQUESTED,
338 WL1271_FLAG_IRQ_RUNNING, 250 WL1271_FLAG_IRQ_RUNNING,
339 WL1271_FLAG_IDLE, 251 WL1271_FLAG_IDLE,
340 WL1271_FLAG_PSPOLL_FAILURE,
341 WL1271_FLAG_STA_STATE_SENT,
342 WL1271_FLAG_FW_TX_BUSY, 252 WL1271_FLAG_FW_TX_BUSY,
343 WL1271_FLAG_AP_STARTED,
344 WL1271_FLAG_IF_INITIALIZED,
345 WL1271_FLAG_DUMMY_PACKET_PENDING, 253 WL1271_FLAG_DUMMY_PACKET_PENDING,
346 WL1271_FLAG_SUSPENDED, 254 WL1271_FLAG_SUSPENDED,
347 WL1271_FLAG_PENDING_WORK, 255 WL1271_FLAG_PENDING_WORK,
348 WL1271_FLAG_SOFT_GEMINI, 256 WL1271_FLAG_SOFT_GEMINI,
349 WL1271_FLAG_RX_STREAMING_STARTED,
350 WL1271_FLAG_RECOVERY_IN_PROGRESS, 257 WL1271_FLAG_RECOVERY_IN_PROGRESS,
351 WL1271_FLAG_CS_PROGRESS, 258};
259
260enum wl12xx_vif_flags {
261 WLVIF_FLAG_INITIALIZED,
262 WLVIF_FLAG_STA_ASSOCIATED,
263 WLVIF_FLAG_IBSS_JOINED,
264 WLVIF_FLAG_AP_STARTED,
265 WLVIF_FLAG_PSM,
266 WLVIF_FLAG_PSM_REQUESTED,
267 WLVIF_FLAG_STA_STATE_SENT,
268 WLVIF_FLAG_RX_STREAMING_STARTED,
269 WLVIF_FLAG_PSPOLL_FAILURE,
270 WLVIF_FLAG_CS_PROGRESS,
271 WLVIF_FLAG_AP_PROBE_RESP_SET,
352}; 272};
353 273
354struct wl1271_link { 274struct wl1271_link {
@@ -366,10 +286,11 @@ struct wl1271_link {
366}; 286};
367 287
368struct wl1271 { 288struct wl1271 {
369 struct platform_device *plat_dev;
370 struct ieee80211_hw *hw; 289 struct ieee80211_hw *hw;
371 bool mac80211_registered; 290 bool mac80211_registered;
372 291
292 struct device *dev;
293
373 void *if_priv; 294 void *if_priv;
374 295
375 struct wl1271_if_operations *if_ops; 296 struct wl1271_if_operations *if_ops;
@@ -399,25 +320,20 @@ struct wl1271 {
399 320
400 s8 hw_pg_ver; 321 s8 hw_pg_ver;
401 322
402 u8 bssid[ETH_ALEN];
403 u8 mac_addr[ETH_ALEN]; 323 u8 mac_addr[ETH_ALEN];
404 u8 bss_type;
405 u8 set_bss_type;
406 u8 p2p; /* we are using p2p role */
407 u8 ssid[IEEE80211_MAX_SSID_LEN + 1];
408 u8 ssid_len;
409 int channel; 324 int channel;
410 u8 role_id;
411 u8 dev_role_id;
412 u8 system_hlid; 325 u8 system_hlid;
413 u8 sta_hlid;
414 u8 dev_hlid;
415 u8 ap_global_hlid;
416 u8 ap_bcast_hlid;
417 326
418 unsigned long links_map[BITS_TO_LONGS(WL12XX_MAX_LINKS)]; 327 unsigned long links_map[BITS_TO_LONGS(WL12XX_MAX_LINKS)];
419 unsigned long roles_map[BITS_TO_LONGS(WL12XX_MAX_ROLES)]; 328 unsigned long roles_map[BITS_TO_LONGS(WL12XX_MAX_ROLES)];
420 unsigned long roc_map[BITS_TO_LONGS(WL12XX_MAX_ROLES)]; 329 unsigned long roc_map[BITS_TO_LONGS(WL12XX_MAX_ROLES)];
330 unsigned long rate_policies_map[
331 BITS_TO_LONGS(WL12XX_MAX_RATE_POLICIES)];
332
333 struct list_head wlvif_list;
334
335 u8 sta_count;
336 u8 ap_count;
421 337
422 struct wl1271_acx_mem_map *target_mem_map; 338 struct wl1271_acx_mem_map *target_mem_map;
423 339
@@ -440,11 +356,7 @@ struct wl1271 {
440 /* Time-offset between host and chipset clocks */ 356 /* Time-offset between host and chipset clocks */
441 s64 time_offset; 357 s64 time_offset;
442 358
443 /* Session counter for the chipset */
444 int session_counter;
445
446 /* Frames scheduled for transmission, not handled yet */ 359 /* Frames scheduled for transmission, not handled yet */
447 struct sk_buff_head tx_queue[NUM_TX_QUEUES];
448 int tx_queue_count[NUM_TX_QUEUES]; 360 int tx_queue_count[NUM_TX_QUEUES];
449 long stopped_queues_map; 361 long stopped_queues_map;
450 362
@@ -462,17 +374,6 @@ struct wl1271 {
462 struct sk_buff *tx_frames[ACX_TX_DESCRIPTORS]; 374 struct sk_buff *tx_frames[ACX_TX_DESCRIPTORS];
463 int tx_frames_cnt; 375 int tx_frames_cnt;
464 376
465 /*
466 * Security sequence number
467 * bits 0-15: lower 16 bits part of sequence number
468 * bits 16-47: higher 32 bits part of sequence number
469 * bits 48-63: not in use
470 */
471 u64 tx_security_seq;
472
473 /* 8 bits of the last sequence number in use */
474 u8 tx_security_last_seq_lsb;
475
476 /* FW Rx counter */ 377 /* FW Rx counter */
477 u32 rx_counter; 378 u32 rx_counter;
478 379
@@ -507,59 +408,21 @@ struct wl1271 {
507 u32 mbox_ptr[2]; 408 u32 mbox_ptr[2];
508 409
509 /* Are we currently scanning */ 410 /* Are we currently scanning */
411 struct ieee80211_vif *scan_vif;
510 struct wl1271_scan scan; 412 struct wl1271_scan scan;
511 struct delayed_work scan_complete_work; 413 struct delayed_work scan_complete_work;
512 414
513 bool sched_scanning; 415 bool sched_scanning;
514 416
515 /* probe-req template for the current AP */
516 struct sk_buff *probereq;
517
518 /* Our association ID */
519 u16 aid;
520
521 /*
522 * currently configured rate set:
523 * bits 0-15 - 802.11abg rates
524 * bits 16-23 - 802.11n MCS index mask
525 * support only 1 stream, thus only 8 bits for the MCS rates (0-7).
526 */
527 u32 basic_rate_set;
528 u32 basic_rate;
529 u32 rate_set;
530 u32 bitrate_masks[IEEE80211_NUM_BANDS];
531
532 /* The current band */ 417 /* The current band */
533 enum ieee80211_band band; 418 enum ieee80211_band band;
534 419
535 /* Beaconing interval (needed for ad-hoc) */
536 u32 beacon_int;
537
538 /* Default key (for WEP) */
539 u32 default_key;
540
541 /* Rx Streaming */
542 struct work_struct rx_streaming_enable_work;
543 struct work_struct rx_streaming_disable_work;
544 struct timer_list rx_streaming_timer;
545
546 struct completion *elp_compl; 420 struct completion *elp_compl;
547 struct completion *ps_compl;
548 struct delayed_work elp_work; 421 struct delayed_work elp_work;
549 struct delayed_work pspoll_work;
550
551 /* counter for ps-poll delivery failures */
552 int ps_poll_failures;
553
554 /* retry counter for PSM entries */
555 u8 psm_entry_retry;
556 422
557 /* in dBm */ 423 /* in dBm */
558 int power_level; 424 int power_level;
559 425
560 int rssi_thold;
561 int last_rssi_event;
562
563 struct wl1271_stats stats; 426 struct wl1271_stats stats;
564 427
565 __le32 buffer_32; 428 __le32 buffer_32;
@@ -583,20 +446,9 @@ struct wl1271 {
583 /* Most recently reported noise in dBm */ 446 /* Most recently reported noise in dBm */
584 s8 noise; 447 s8 noise;
585 448
586 /* map for HLIDs of associated stations - when operating in AP mode */
587 unsigned long ap_hlid_map[BITS_TO_LONGS(AP_MAX_STATIONS)];
588
589 /* recoreded keys for AP-mode - set here before AP startup */
590 struct wl1271_ap_key *recorded_ap_keys[MAX_NUM_KEYS];
591
592 /* bands supported by this instance of wl12xx */ 449 /* bands supported by this instance of wl12xx */
593 struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS]; 450 struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
594 451
595 /* RX BA constraint value */
596 bool ba_support;
597 u8 ba_rx_bitmap;
598 bool ba_allowed;
599
600 int tcxo_clock; 452 int tcxo_clock;
601 453
602 /* 454 /*
@@ -610,10 +462,7 @@ struct wl1271 {
610 * AP-mode - links indexed by HLID. The global and broadcast links 462 * AP-mode - links indexed by HLID. The global and broadcast links
611 * are always active. 463 * are always active.
612 */ 464 */
613 struct wl1271_link links[AP_MAX_LINKS]; 465 struct wl1271_link links[WL12XX_MAX_LINKS];
614
615 /* the hlid of the link where the last transmitted skb came from */
616 int last_tx_hlid;
617 466
618 /* AP-mode - a bitmap of links currently in PS mode according to FW */ 467 /* AP-mode - a bitmap of links currently in PS mode according to FW */
619 u32 ap_fw_ps_map; 468 u32 ap_fw_ps_map;
@@ -632,21 +481,173 @@ struct wl1271 {
632 481
633 /* AP-mode - number of currently connected stations */ 482 /* AP-mode - number of currently connected stations */
634 int active_sta_count; 483 int active_sta_count;
484
485 /* last wlvif we transmitted from */
486 struct wl12xx_vif *last_wlvif;
635}; 487};
636 488
637struct wl1271_station { 489struct wl1271_station {
638 u8 hlid; 490 u8 hlid;
639}; 491};
640 492
493struct wl12xx_vif {
494 struct wl1271 *wl;
495 struct list_head list;
496 unsigned long flags;
497 u8 bss_type;
498 u8 p2p; /* we are using p2p role */
499 u8 role_id;
500
501 /* sta/ibss specific */
502 u8 dev_role_id;
503 u8 dev_hlid;
504
505 union {
506 struct {
507 u8 hlid;
508 u8 ba_rx_bitmap;
509
510 u8 basic_rate_idx;
511 u8 ap_rate_idx;
512 u8 p2p_rate_idx;
513 } sta;
514 struct {
515 u8 global_hlid;
516 u8 bcast_hlid;
517
518 /* HLIDs bitmap of associated stations */
519 unsigned long sta_hlid_map[BITS_TO_LONGS(
520 WL12XX_MAX_LINKS)];
521
522 /* recoreded keys - set here before AP startup */
523 struct wl1271_ap_key *recorded_keys[MAX_NUM_KEYS];
524
525 u8 mgmt_rate_idx;
526 u8 bcast_rate_idx;
527 u8 ucast_rate_idx[CONF_TX_MAX_AC_COUNT];
528 } ap;
529 };
530
531 /* the hlid of the last transmitted skb */
532 int last_tx_hlid;
533
534 unsigned long links_map[BITS_TO_LONGS(WL12XX_MAX_LINKS)];
535
536 u8 ssid[IEEE80211_MAX_SSID_LEN + 1];
537 u8 ssid_len;
538
539 /* The current band */
540 enum ieee80211_band band;
541 int channel;
542
543 u32 bitrate_masks[IEEE80211_NUM_BANDS];
544 u32 basic_rate_set;
545
546 /*
547 * currently configured rate set:
548 * bits 0-15 - 802.11abg rates
549 * bits 16-23 - 802.11n MCS index mask
550 * support only 1 stream, thus only 8 bits for the MCS rates (0-7).
551 */
552 u32 basic_rate;
553 u32 rate_set;
554
555 /* probe-req template for the current AP */
556 struct sk_buff *probereq;
557
558 /* Beaconing interval (needed for ad-hoc) */
559 u32 beacon_int;
560
561 /* Default key (for WEP) */
562 u32 default_key;
563
564 /* Our association ID */
565 u16 aid;
566
567 /* Session counter for the chipset */
568 int session_counter;
569
570 struct completion *ps_compl;
571 struct delayed_work pspoll_work;
572
573 /* counter for ps-poll delivery failures */
574 int ps_poll_failures;
575
576 /* retry counter for PSM entries */
577 u8 psm_entry_retry;
578
579 /* in dBm */
580 int power_level;
581
582 int rssi_thold;
583 int last_rssi_event;
584
585 /* RX BA constraint value */
586 bool ba_support;
587 bool ba_allowed;
588
589 /* Rx Streaming */
590 struct work_struct rx_streaming_enable_work;
591 struct work_struct rx_streaming_disable_work;
592 struct timer_list rx_streaming_timer;
593
594 /*
595 * This struct must be last!
596 * data that has to be saved acrossed reconfigs (e.g. recovery)
597 * should be declared in this struct.
598 */
599 struct {
600 u8 persistent[0];
601 /*
602 * Security sequence number
603 * bits 0-15: lower 16 bits part of sequence number
604 * bits 16-47: higher 32 bits part of sequence number
605 * bits 48-63: not in use
606 */
607 u64 tx_security_seq;
608
609 /* 8 bits of the last sequence number in use */
610 u8 tx_security_last_seq_lsb;
611 };
612};
613
614static inline struct wl12xx_vif *wl12xx_vif_to_data(struct ieee80211_vif *vif)
615{
616 return (struct wl12xx_vif *)vif->drv_priv;
617}
618
619static inline
620struct ieee80211_vif *wl12xx_wlvif_to_vif(struct wl12xx_vif *wlvif)
621{
622 return container_of((void *)wlvif, struct ieee80211_vif, drv_priv);
623}
624
625#define wl12xx_for_each_wlvif(wl, wlvif) \
626 list_for_each_entry(wlvif, &wl->wlvif_list, list)
627
628#define wl12xx_for_each_wlvif_continue(wl, wlvif) \
629 list_for_each_entry_continue(wlvif, &wl->wlvif_list, list)
630
631#define wl12xx_for_each_wlvif_bss_type(wl, wlvif, _bss_type) \
632 wl12xx_for_each_wlvif(wl, wlvif) \
633 if (wlvif->bss_type == _bss_type)
634
635#define wl12xx_for_each_wlvif_sta(wl, wlvif) \
636 wl12xx_for_each_wlvif_bss_type(wl, wlvif, BSS_TYPE_STA_BSS)
637
638#define wl12xx_for_each_wlvif_ap(wl, wlvif) \
639 wl12xx_for_each_wlvif_bss_type(wl, wlvif, BSS_TYPE_AP_BSS)
640
641int wl1271_plt_start(struct wl1271 *wl); 641int wl1271_plt_start(struct wl1271 *wl);
642int wl1271_plt_stop(struct wl1271 *wl); 642int wl1271_plt_stop(struct wl1271 *wl);
643int wl1271_recalc_rx_streaming(struct wl1271 *wl); 643int wl1271_recalc_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif);
644void wl12xx_queue_recovery_work(struct wl1271 *wl); 644void wl12xx_queue_recovery_work(struct wl1271 *wl);
645size_t wl12xx_copy_fwlog(struct wl1271 *wl, u8 *memblock, size_t maxlen); 645size_t wl12xx_copy_fwlog(struct wl1271 *wl, u8 *memblock, size_t maxlen);
646 646
647#define JOIN_TIMEOUT 5000 /* 5000 milliseconds to join */ 647#define JOIN_TIMEOUT 5000 /* 5000 milliseconds to join */
648 648
649#define SESSION_COUNTER_MAX 7 /* maximum value for the session counter */ 649#define SESSION_COUNTER_MAX 6 /* maximum value for the session counter */
650#define SESSION_COUNTER_INVALID 7 /* used with dummy_packet */
650 651
651#define WL1271_DEFAULT_POWER_LEVEL 0 652#define WL1271_DEFAULT_POWER_LEVEL 0
652 653
@@ -669,8 +670,8 @@ size_t wl12xx_copy_fwlog(struct wl1271 *wl, u8 *memblock, size_t maxlen);
669/* Each RX/TX transaction requires an end-of-transaction transfer */ 670/* Each RX/TX transaction requires an end-of-transaction transfer */
670#define WL12XX_QUIRK_END_OF_TRANSACTION BIT(0) 671#define WL12XX_QUIRK_END_OF_TRANSACTION BIT(0)
671 672
672/* WL128X requires aggregated packets to be aligned to the SDIO block size */ 673/* wl127x and SPI don't support SDIO block size alignment */
673#define WL12XX_QUIRK_BLOCKSIZE_ALIGNMENT BIT(2) 674#define WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT BIT(2)
674 675
675/* Older firmwares did not implement the FW logger over bus feature */ 676/* Older firmwares did not implement the FW logger over bus feature */
676#define WL12XX_QUIRK_FWLOG_NOT_IMPLEMENTED BIT(4) 677#define WL12XX_QUIRK_FWLOG_NOT_IMPLEMENTED BIT(4)
diff --git a/drivers/net/wireless/wl12xx/wl12xx_80211.h b/drivers/net/wireless/wl12xx/wl12xx_80211.h
index f7971d3b089..8f0ffaf6230 100644
--- a/drivers/net/wireless/wl12xx/wl12xx_80211.h
+++ b/drivers/net/wireless/wl12xx/wl12xx_80211.h
@@ -116,11 +116,6 @@ struct wl12xx_ps_poll_template {
116 u8 ta[ETH_ALEN]; 116 u8 ta[ETH_ALEN];
117} __packed; 117} __packed;
118 118
119struct wl12xx_qos_null_data_template {
120 struct ieee80211_header header;
121 __le16 qos_ctl;
122} __packed;
123
124struct wl12xx_arp_rsp_template { 119struct wl12xx_arp_rsp_template {
125 struct ieee80211_hdr_3addr hdr; 120 struct ieee80211_hdr_3addr hdr;
126 121
diff --git a/drivers/net/wireless/wl12xx/wl12xx_platform_data.c b/drivers/net/wireless/wl12xx/wl12xx_platform_data.c
index 973b11060a8..3c96b332184 100644
--- a/drivers/net/wireless/wl12xx/wl12xx_platform_data.c
+++ b/drivers/net/wireless/wl12xx/wl12xx_platform_data.c
@@ -2,7 +2,7 @@
2#include <linux/err.h> 2#include <linux/err.h>
3#include <linux/wl12xx.h> 3#include <linux/wl12xx.h>
4 4
5static const struct wl12xx_platform_data *platform_data; 5static struct wl12xx_platform_data *platform_data;
6 6
7int __init wl12xx_set_platform_data(const struct wl12xx_platform_data *data) 7int __init wl12xx_set_platform_data(const struct wl12xx_platform_data *data)
8{ 8{
@@ -18,7 +18,7 @@ int __init wl12xx_set_platform_data(const struct wl12xx_platform_data *data)
18 return 0; 18 return 0;
19} 19}
20 20
21const struct wl12xx_platform_data *wl12xx_get_platform_data(void) 21struct wl12xx_platform_data *wl12xx_get_platform_data(void)
22{ 22{
23 if (!platform_data) 23 if (!platform_data)
24 return ERR_PTR(-ENODEV); 24 return ERR_PTR(-ENODEV);