aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/wl12xx
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless/wl12xx')
-rw-r--r--drivers/net/wireless/wl12xx/Kconfig3
-rw-r--r--drivers/net/wireless/wl12xx/Makefile4
-rw-r--r--drivers/net/wireless/wl12xx/wl1251.h9
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_acx.c138
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_acx.h123
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_boot.c58
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_cmd.c84
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_cmd.h22
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_debugfs.c27
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_event.c15
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_init.c14
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_init.h47
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_main.c559
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_ps.c53
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_ps.h1
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_reg.h6
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_rx.c9
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_spi.c5
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_tx.c9
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_tx.h17
-rw-r--r--drivers/net/wireless/wl12xx/wl1271.h150
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_acx.c414
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_acx.h602
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_boot.c251
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_boot.h22
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_cmd.c473
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_cmd.h151
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_conf.h795
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_debugfs.c63
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_event.c157
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_event.h35
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_init.c184
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_init.h87
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_io.c213
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_io.h68
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_main.c1439
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_ps.c77
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_ps.h5
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_reg.h146
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_rx.c91
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_rx.h4
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_spi.c254
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_spi.h61
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_testmode.c284
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_testmode.h (renamed from drivers/net/wireless/wl12xx/wl1251_netlink.h)17
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_tx.c135
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_tx.h54
-rw-r--r--drivers/net/wireless/wl12xx/wl12xx_80211.h4
48 files changed, 5202 insertions, 2237 deletions
diff --git a/drivers/net/wireless/wl12xx/Kconfig b/drivers/net/wireless/wl12xx/Kconfig
index 88060e117541..785e0244e305 100644
--- a/drivers/net/wireless/wl12xx/Kconfig
+++ b/drivers/net/wireless/wl12xx/Kconfig
@@ -1,6 +1,6 @@
1menuconfig WL12XX 1menuconfig WL12XX
2 tristate "TI wl12xx driver support" 2 tristate "TI wl12xx driver support"
3 depends on MAC80211 && WLAN_80211 && EXPERIMENTAL 3 depends on MAC80211 && EXPERIMENTAL
4 ---help--- 4 ---help---
5 This will enable TI wl12xx driver support. The drivers make 5 This will enable TI wl12xx driver support. The drivers make
6 use of the mac80211 stack. 6 use of the mac80211 stack.
@@ -42,6 +42,7 @@ config WL1251_SDIO
42config WL1271 42config WL1271
43 tristate "TI wl1271 support" 43 tristate "TI wl1271 support"
44 depends on WL12XX && SPI_MASTER && GENERIC_HARDIRQS 44 depends on WL12XX && SPI_MASTER && GENERIC_HARDIRQS
45 depends on INET
45 select FW_LOADER 46 select FW_LOADER
46 select CRC7 47 select CRC7
47 ---help--- 48 ---help---
diff --git a/drivers/net/wireless/wl12xx/Makefile b/drivers/net/wireless/wl12xx/Makefile
index 62e37ad01cc0..f47ec94c16dc 100644
--- a/drivers/net/wireless/wl12xx/Makefile
+++ b/drivers/net/wireless/wl12xx/Makefile
@@ -10,5 +10,7 @@ obj-$(CONFIG_WL1251_SDIO) += wl1251_sdio.o
10wl1271-objs = wl1271_main.o wl1271_spi.o wl1271_cmd.o \ 10wl1271-objs = wl1271_main.o wl1271_spi.o wl1271_cmd.o \
11 wl1271_event.o wl1271_tx.o wl1271_rx.o \ 11 wl1271_event.o wl1271_tx.o wl1271_rx.o \
12 wl1271_ps.o wl1271_acx.o wl1271_boot.o \ 12 wl1271_ps.o wl1271_acx.o wl1271_boot.o \
13 wl1271_init.o wl1271_debugfs.o 13 wl1271_init.o wl1271_debugfs.o wl1271_io.o
14
15wl1271-$(CONFIG_NL80211_TESTMODE) += wl1271_testmode.o
14obj-$(CONFIG_WL1271) += wl1271.o 16obj-$(CONFIG_WL1271) += wl1271.o
diff --git a/drivers/net/wireless/wl12xx/wl1251.h b/drivers/net/wireless/wl12xx/wl1251.h
index 998e4b6252bd..37c61c19cae5 100644
--- a/drivers/net/wireless/wl12xx/wl1251.h
+++ b/drivers/net/wireless/wl12xx/wl1251.h
@@ -247,6 +247,7 @@ struct wl1251_debugfs {
247 struct dentry *rxpipe_tx_xfr_host_int_trig_rx_data; 247 struct dentry *rxpipe_tx_xfr_host_int_trig_rx_data;
248 248
249 struct dentry *tx_queue_len; 249 struct dentry *tx_queue_len;
250 struct dentry *tx_queue_status;
250 251
251 struct dentry *retry_count; 252 struct dentry *retry_count;
252 struct dentry *excessive_retries; 253 struct dentry *excessive_retries;
@@ -269,6 +270,7 @@ struct wl1251 {
269 270
270 void (*set_power)(bool enable); 271 void (*set_power)(bool enable);
271 int irq; 272 int irq;
273 bool use_eeprom;
272 274
273 enum wl1251_state state; 275 enum wl1251_state state;
274 struct mutex mutex; 276 struct mutex mutex;
@@ -339,9 +341,6 @@ struct wl1251 {
339 /* Are we currently scanning */ 341 /* Are we currently scanning */
340 bool scanning; 342 bool scanning;
341 343
342 /* Our association ID */
343 u16 aid;
344
345 /* Default key (for WEP) */ 344 /* Default key (for WEP) */
346 u32 default_key; 345 u32 default_key;
347 346
@@ -354,6 +353,8 @@ struct wl1251 {
354 /* is firmware in elp mode */ 353 /* is firmware in elp mode */
355 bool elp; 354 bool elp;
356 355
356 struct delayed_work elp_work;
357
357 /* we can be in psm, but not in elp, we have to differentiate */ 358 /* we can be in psm, but not in elp, we have to differentiate */
358 bool psm; 359 bool psm;
359 360
@@ -374,6 +375,8 @@ struct wl1251 {
374 u8 buffer_busyword[WL1251_BUSY_WORD_LEN]; 375 u8 buffer_busyword[WL1251_BUSY_WORD_LEN];
375 struct wl1251_rx_descriptor *rx_descriptor; 376 struct wl1251_rx_descriptor *rx_descriptor;
376 377
378 struct ieee80211_vif *vif;
379
377 u32 chip_id; 380 u32 chip_id;
378 char fw_ver[21]; 381 char fw_ver[21];
379}; 382};
diff --git a/drivers/net/wireless/wl12xx/wl1251_acx.c b/drivers/net/wireless/wl12xx/wl1251_acx.c
index 10b26c4532c9..91891f928070 100644
--- a/drivers/net/wireless/wl12xx/wl1251_acx.c
+++ b/drivers/net/wireless/wl12xx/wl1251_acx.c
@@ -1,6 +1,7 @@
1#include "wl1251_acx.h" 1#include "wl1251_acx.h"
2 2
3#include <linux/module.h> 3#include <linux/module.h>
4#include <linux/slab.h>
4#include <linux/crc7.h> 5#include <linux/crc7.h>
5 6
6#include "wl1251.h" 7#include "wl1251.h"
@@ -494,7 +495,7 @@ out:
494 return ret; 495 return ret;
495} 496}
496 497
497int wl1251_acx_beacon_filter_opt(struct wl1251 *wl) 498int wl1251_acx_beacon_filter_opt(struct wl1251 *wl, bool enable_filter)
498{ 499{
499 struct acx_beacon_filter_option *beacon_filter; 500 struct acx_beacon_filter_option *beacon_filter;
500 int ret; 501 int ret;
@@ -507,7 +508,7 @@ int wl1251_acx_beacon_filter_opt(struct wl1251 *wl)
507 goto out; 508 goto out;
508 } 509 }
509 510
510 beacon_filter->enable = 0; 511 beacon_filter->enable = enable_filter;
511 beacon_filter->max_num_beacons = 0; 512 beacon_filter->max_num_beacons = 0;
512 513
513 ret = wl1251_cmd_configure(wl, ACX_BEACON_FILTER_OPT, 514 ret = wl1251_cmd_configure(wl, ACX_BEACON_FILTER_OPT,
@@ -525,6 +526,7 @@ out:
525int wl1251_acx_beacon_filter_table(struct wl1251 *wl) 526int wl1251_acx_beacon_filter_table(struct wl1251 *wl)
526{ 527{
527 struct acx_beacon_filter_ie_table *ie_table; 528 struct acx_beacon_filter_ie_table *ie_table;
529 int idx = 0;
528 int ret; 530 int ret;
529 531
530 wl1251_debug(DEBUG_ACX, "acx beacon filter table"); 532 wl1251_debug(DEBUG_ACX, "acx beacon filter table");
@@ -535,8 +537,10 @@ int wl1251_acx_beacon_filter_table(struct wl1251 *wl)
535 goto out; 537 goto out;
536 } 538 }
537 539
538 ie_table->num_ie = 0; 540 /* configure default beacon pass-through rules */
539 memset(ie_table->table, 0, BEACON_FILTER_TABLE_MAX_SIZE); 541 ie_table->num_ie = 1;
542 ie_table->table[idx++] = BEACON_FILTER_IE_ID_CHANNEL_SWITCH_ANN;
543 ie_table->table[idx++] = BEACON_RULE_PASS_ON_APPEARANCE;
540 544
541 ret = wl1251_cmd_configure(wl, ACX_BEACON_FILTER_TABLE, 545 ret = wl1251_cmd_configure(wl, ACX_BEACON_FILTER_TABLE,
542 ie_table, sizeof(*ie_table)); 546 ie_table, sizeof(*ie_table));
@@ -550,6 +554,35 @@ out:
550 return ret; 554 return ret;
551} 555}
552 556
557int wl1251_acx_conn_monit_params(struct wl1251 *wl)
558{
559 struct acx_conn_monit_params *acx;
560 int ret;
561
562 wl1251_debug(DEBUG_ACX, "acx connection monitor parameters");
563
564 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
565 if (!acx) {
566 ret = -ENOMEM;
567 goto out;
568 }
569
570 acx->synch_fail_thold = SYNCH_FAIL_DEFAULT_THRESHOLD;
571 acx->bss_lose_timeout = NO_BEACON_DEFAULT_TIMEOUT;
572
573 ret = wl1251_cmd_configure(wl, ACX_CONN_MONIT_PARAMS,
574 acx, sizeof(*acx));
575 if (ret < 0) {
576 wl1251_warning("failed to set connection monitor "
577 "parameters: %d", ret);
578 goto out;
579 }
580
581out:
582 kfree(acx);
583 return ret;
584}
585
553int wl1251_acx_sg_enable(struct wl1251 *wl) 586int wl1251_acx_sg_enable(struct wl1251 *wl)
554{ 587{
555 struct acx_bt_wlan_coex *pta; 588 struct acx_bt_wlan_coex *pta;
@@ -916,3 +949,100 @@ out:
916 kfree(mem_conf); 949 kfree(mem_conf);
917 return ret; 950 return ret;
918} 951}
952
953int wl1251_acx_wr_tbtt_and_dtim(struct wl1251 *wl, u16 tbtt, u8 dtim)
954{
955 struct wl1251_acx_wr_tbtt_and_dtim *acx;
956 int ret;
957
958 wl1251_debug(DEBUG_ACX, "acx tbtt and dtim");
959
960 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
961 if (!acx) {
962 ret = -ENOMEM;
963 goto out;
964 }
965
966 acx->tbtt = tbtt;
967 acx->dtim = dtim;
968
969 ret = wl1251_cmd_configure(wl, ACX_WR_TBTT_AND_DTIM,
970 acx, sizeof(*acx));
971 if (ret < 0) {
972 wl1251_warning("failed to set tbtt and dtim: %d", ret);
973 goto out;
974 }
975
976out:
977 kfree(acx);
978 return ret;
979}
980
981int wl1251_acx_ac_cfg(struct wl1251 *wl, u8 ac, u8 cw_min, u16 cw_max,
982 u8 aifs, u16 txop)
983{
984 struct wl1251_acx_ac_cfg *acx;
985 int ret = 0;
986
987 wl1251_debug(DEBUG_ACX, "acx ac cfg %d cw_ming %d cw_max %d "
988 "aifs %d txop %d", ac, cw_min, cw_max, aifs, txop);
989
990 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
991
992 if (!acx) {
993 ret = -ENOMEM;
994 goto out;
995 }
996
997 acx->ac = ac;
998 acx->cw_min = cw_min;
999 acx->cw_max = cw_max;
1000 acx->aifsn = aifs;
1001 acx->txop_limit = txop;
1002
1003 ret = wl1251_cmd_configure(wl, ACX_AC_CFG, acx, sizeof(*acx));
1004 if (ret < 0) {
1005 wl1251_warning("acx ac cfg failed: %d", ret);
1006 goto out;
1007 }
1008
1009out:
1010 kfree(acx);
1011 return ret;
1012}
1013
1014int wl1251_acx_tid_cfg(struct wl1251 *wl, u8 queue,
1015 enum wl1251_acx_channel_type type,
1016 u8 tsid, enum wl1251_acx_ps_scheme ps_scheme,
1017 enum wl1251_acx_ack_policy ack_policy)
1018{
1019 struct wl1251_acx_tid_cfg *acx;
1020 int ret = 0;
1021
1022 wl1251_debug(DEBUG_ACX, "acx tid cfg %d type %d tsid %d "
1023 "ps_scheme %d ack_policy %d", queue, type, tsid,
1024 ps_scheme, ack_policy);
1025
1026 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1027
1028 if (!acx) {
1029 ret = -ENOMEM;
1030 goto out;
1031 }
1032
1033 acx->queue = queue;
1034 acx->type = type;
1035 acx->tsid = tsid;
1036 acx->ps_scheme = ps_scheme;
1037 acx->ack_policy = ack_policy;
1038
1039 ret = wl1251_cmd_configure(wl, ACX_TID_CFG, acx, sizeof(*acx));
1040 if (ret < 0) {
1041 wl1251_warning("acx tid cfg failed: %d", ret);
1042 goto out;
1043 }
1044
1045out:
1046 kfree(acx);
1047 return ret;
1048}
diff --git a/drivers/net/wireless/wl12xx/wl1251_acx.h b/drivers/net/wireless/wl12xx/wl1251_acx.h
index cafb91459504..26160c45784c 100644
--- a/drivers/net/wireless/wl12xx/wl1251_acx.h
+++ b/drivers/net/wireless/wl12xx/wl1251_acx.h
@@ -450,6 +450,11 @@ struct acx_beacon_filter_option {
450 (BEACON_FILTER_TABLE_MAX_VENDOR_SPECIFIC_IE_NUM * \ 450 (BEACON_FILTER_TABLE_MAX_VENDOR_SPECIFIC_IE_NUM * \
451 BEACON_FILTER_TABLE_EXTRA_VENDOR_SPECIFIC_IE_SIZE)) 451 BEACON_FILTER_TABLE_EXTRA_VENDOR_SPECIFIC_IE_SIZE))
452 452
453#define BEACON_RULE_PASS_ON_CHANGE BIT(0)
454#define BEACON_RULE_PASS_ON_APPEARANCE BIT(1)
455
456#define BEACON_FILTER_IE_ID_CHANNEL_SWITCH_ANN (37)
457
453struct acx_beacon_filter_ie_table { 458struct acx_beacon_filter_ie_table {
454 struct acx_header header; 459 struct acx_header header;
455 460
@@ -458,6 +463,16 @@ struct acx_beacon_filter_ie_table {
458 u8 pad[3]; 463 u8 pad[3];
459} __attribute__ ((packed)); 464} __attribute__ ((packed));
460 465
466#define SYNCH_FAIL_DEFAULT_THRESHOLD 10 /* number of beacons */
467#define NO_BEACON_DEFAULT_TIMEOUT (500) /* in microseconds */
468
469struct acx_conn_monit_params {
470 struct acx_header header;
471
472 u32 synch_fail_thold; /* number of beacons missed */
473 u32 bss_lose_timeout; /* number of TU's from synch fail */
474};
475
461enum { 476enum {
462 SG_ENABLE = 0, 477 SG_ENABLE = 0,
463 SG_DISABLE, 478 SG_DISABLE,
@@ -1134,6 +1149,104 @@ struct wl1251_acx_mem_map {
1134 u32 num_rx_mem_blocks; 1149 u32 num_rx_mem_blocks;
1135} __attribute__ ((packed)); 1150} __attribute__ ((packed));
1136 1151
1152
1153struct wl1251_acx_wr_tbtt_and_dtim {
1154
1155 struct acx_header header;
1156
1157 /* Time in TUs between two consecutive beacons */
1158 u16 tbtt;
1159
1160 /*
1161 * DTIM period
1162 * For BSS: Number of TBTTs in a DTIM period (range: 1-10)
1163 * For IBSS: value shall be set to 1
1164 */
1165 u8 dtim;
1166 u8 padding;
1167} __attribute__ ((packed));
1168
1169struct wl1251_acx_ac_cfg {
1170 struct acx_header header;
1171
1172 /*
1173 * Access Category - The TX queue's access category
1174 * (refer to AccessCategory_enum)
1175 */
1176 u8 ac;
1177
1178 /*
1179 * The contention window minimum size (in slots) for
1180 * the access class.
1181 */
1182 u8 cw_min;
1183
1184 /*
1185 * The contention window maximum size (in slots) for
1186 * the access class.
1187 */
1188 u16 cw_max;
1189
1190 /* The AIF value (in slots) for the access class. */
1191 u8 aifsn;
1192
1193 u8 reserved;
1194
1195 /* The TX Op Limit (in microseconds) for the access class. */
1196 u16 txop_limit;
1197} __attribute__ ((packed));
1198
1199
1200enum wl1251_acx_channel_type {
1201 CHANNEL_TYPE_DCF = 0,
1202 CHANNEL_TYPE_EDCF = 1,
1203 CHANNEL_TYPE_HCCA = 2,
1204};
1205
1206enum wl1251_acx_ps_scheme {
1207 /* regular ps: simple sending of packets */
1208 WL1251_ACX_PS_SCHEME_LEGACY = 0,
1209
1210 /* sending a packet triggers a unscheduled apsd downstream */
1211 WL1251_ACX_PS_SCHEME_UPSD_TRIGGER = 1,
1212
1213 /* a pspoll packet will be sent before every data packet */
1214 WL1251_ACX_PS_SCHEME_LEGACY_PSPOLL = 2,
1215
1216 /* scheduled apsd mode */
1217 WL1251_ACX_PS_SCHEME_SAPSD = 3,
1218};
1219
1220enum wl1251_acx_ack_policy {
1221 WL1251_ACX_ACK_POLICY_LEGACY = 0,
1222 WL1251_ACX_ACK_POLICY_NO_ACK = 1,
1223 WL1251_ACX_ACK_POLICY_BLOCK = 2,
1224};
1225
1226struct wl1251_acx_tid_cfg {
1227 struct acx_header header;
1228
1229 /* tx queue id number (0-7) */
1230 u8 queue;
1231
1232 /* channel access type for the queue, enum wl1251_acx_channel_type */
1233 u8 type;
1234
1235 /* EDCA: ac index (0-3), HCCA: traffic stream id (8-15) */
1236 u8 tsid;
1237
1238 /* ps scheme of the specified queue, enum wl1251_acx_ps_scheme */
1239 u8 ps_scheme;
1240
1241 /* the tx queue ack policy, enum wl1251_acx_ack_policy */
1242 u8 ack_policy;
1243
1244 u8 padding[3];
1245
1246 /* not supported */
1247 u32 apsdconf[2];
1248} __attribute__ ((packed));
1249
1137/************************************************************************* 1250/*************************************************************************
1138 1251
1139 Host Interrupt Register (WiLink -> Host) 1252 Host Interrupt Register (WiLink -> Host)
@@ -1273,8 +1386,9 @@ int wl1251_acx_slot(struct wl1251 *wl, enum acx_slot_type slot_time);
1273int wl1251_acx_group_address_tbl(struct wl1251 *wl); 1386int wl1251_acx_group_address_tbl(struct wl1251 *wl);
1274int wl1251_acx_service_period_timeout(struct wl1251 *wl); 1387int wl1251_acx_service_period_timeout(struct wl1251 *wl);
1275int wl1251_acx_rts_threshold(struct wl1251 *wl, u16 rts_threshold); 1388int wl1251_acx_rts_threshold(struct wl1251 *wl, u16 rts_threshold);
1276int wl1251_acx_beacon_filter_opt(struct wl1251 *wl); 1389int wl1251_acx_beacon_filter_opt(struct wl1251 *wl, bool enable_filter);
1277int wl1251_acx_beacon_filter_table(struct wl1251 *wl); 1390int wl1251_acx_beacon_filter_table(struct wl1251 *wl);
1391int wl1251_acx_conn_monit_params(struct wl1251 *wl);
1278int wl1251_acx_sg_enable(struct wl1251 *wl); 1392int wl1251_acx_sg_enable(struct wl1251 *wl);
1279int wl1251_acx_sg_cfg(struct wl1251 *wl); 1393int wl1251_acx_sg_cfg(struct wl1251 *wl);
1280int wl1251_acx_cca_threshold(struct wl1251 *wl); 1394int wl1251_acx_cca_threshold(struct wl1251 *wl);
@@ -1288,5 +1402,12 @@ int wl1251_acx_statistics(struct wl1251 *wl, struct acx_statistics *stats);
1288int wl1251_acx_tsf_info(struct wl1251 *wl, u64 *mactime); 1402int wl1251_acx_tsf_info(struct wl1251 *wl, u64 *mactime);
1289int wl1251_acx_rate_policies(struct wl1251 *wl); 1403int wl1251_acx_rate_policies(struct wl1251 *wl);
1290int wl1251_acx_mem_cfg(struct wl1251 *wl); 1404int wl1251_acx_mem_cfg(struct wl1251 *wl);
1405int wl1251_acx_wr_tbtt_and_dtim(struct wl1251 *wl, u16 tbtt, u8 dtim);
1406int wl1251_acx_ac_cfg(struct wl1251 *wl, u8 ac, u8 cw_min, u16 cw_max,
1407 u8 aifs, u16 txop);
1408int wl1251_acx_tid_cfg(struct wl1251 *wl, u8 queue,
1409 enum wl1251_acx_channel_type type,
1410 u8 tsid, enum wl1251_acx_ps_scheme ps_scheme,
1411 enum wl1251_acx_ack_policy ack_policy);
1291 1412
1292#endif /* __WL1251_ACX_H__ */ 1413#endif /* __WL1251_ACX_H__ */
diff --git a/drivers/net/wireless/wl12xx/wl1251_boot.c b/drivers/net/wireless/wl12xx/wl1251_boot.c
index 452d748e42c6..d5ac79aeaa73 100644
--- a/drivers/net/wireless/wl12xx/wl1251_boot.c
+++ b/drivers/net/wireless/wl12xx/wl1251_boot.c
@@ -22,6 +22,7 @@
22 */ 22 */
23 23
24#include <linux/gpio.h> 24#include <linux/gpio.h>
25#include <linux/slab.h>
25 26
26#include "wl1251_reg.h" 27#include "wl1251_reg.h"
27#include "wl1251_boot.h" 28#include "wl1251_boot.h"
@@ -256,7 +257,7 @@ int wl1251_boot_run_firmware(struct wl1251 *wl)
256 } 257 }
257 } 258 }
258 259
259 if (loop >= INIT_LOOP) { 260 if (loop > INIT_LOOP) {
260 wl1251_error("timeout waiting for the hardware to " 261 wl1251_error("timeout waiting for the hardware to "
261 "complete initialization"); 262 "complete initialization");
262 return -EIO; 263 return -EIO;
@@ -296,8 +297,12 @@ int wl1251_boot_run_firmware(struct wl1251 *wl)
296 WL1251_ACX_INTR_INIT_COMPLETE; 297 WL1251_ACX_INTR_INIT_COMPLETE;
297 wl1251_boot_target_enable_interrupts(wl); 298 wl1251_boot_target_enable_interrupts(wl);
298 299
299 /* unmask all mbox events */ 300 wl->event_mask = SCAN_COMPLETE_EVENT_ID | BSS_LOSE_EVENT_ID |
300 wl->event_mask = 0xffffffff; 301 SYNCHRONIZATION_TIMEOUT_EVENT_ID |
302 ROAMING_TRIGGER_LOW_RSSI_EVENT_ID |
303 ROAMING_TRIGGER_REGAINED_RSSI_EVENT_ID |
304 REGAINED_BSS_EVENT_ID | BT_PTA_SENSE_EVENT_ID |
305 BT_PTA_PREDICTION_EVENT_ID;
301 306
302 ret = wl1251_event_unmask(wl); 307 ret = wl1251_event_unmask(wl);
303 if (ret < 0) { 308 if (ret < 0) {
@@ -314,8 +319,8 @@ int wl1251_boot_run_firmware(struct wl1251 *wl)
314static int wl1251_boot_upload_firmware(struct wl1251 *wl) 319static int wl1251_boot_upload_firmware(struct wl1251 *wl)
315{ 320{
316 int addr, chunk_num, partition_limit; 321 int addr, chunk_num, partition_limit;
317 size_t fw_data_len; 322 size_t fw_data_len, len;
318 u8 *p; 323 u8 *p, *buf;
319 324
320 /* whal_FwCtrl_LoadFwImageSm() */ 325 /* whal_FwCtrl_LoadFwImageSm() */
321 326
@@ -334,6 +339,12 @@ static int wl1251_boot_upload_firmware(struct wl1251 *wl)
334 return -EIO; 339 return -EIO;
335 } 340 }
336 341
342 buf = kmalloc(CHUNK_SIZE, GFP_KERNEL);
343 if (!buf) {
344 wl1251_error("allocation for firmware upload chunk failed");
345 return -ENOMEM;
346 }
347
337 wl1251_set_partition(wl, WL1251_PART_DOWN_MEM_START, 348 wl1251_set_partition(wl, WL1251_PART_DOWN_MEM_START,
338 WL1251_PART_DOWN_MEM_SIZE, 349 WL1251_PART_DOWN_MEM_SIZE,
339 WL1251_PART_DOWN_REG_START, 350 WL1251_PART_DOWN_REG_START,
@@ -364,7 +375,11 @@ static int wl1251_boot_upload_firmware(struct wl1251 *wl)
364 p = wl->fw + FW_HDR_SIZE + chunk_num * CHUNK_SIZE; 375 p = wl->fw + FW_HDR_SIZE + chunk_num * CHUNK_SIZE;
365 wl1251_debug(DEBUG_BOOT, "uploading fw chunk 0x%p to 0x%x", 376 wl1251_debug(DEBUG_BOOT, "uploading fw chunk 0x%p to 0x%x",
366 p, addr); 377 p, addr);
367 wl1251_mem_write(wl, addr, p, CHUNK_SIZE); 378
379 /* need to copy the chunk for dma */
380 len = CHUNK_SIZE;
381 memcpy(buf, p, len);
382 wl1251_mem_write(wl, addr, buf, len);
368 383
369 chunk_num++; 384 chunk_num++;
370 } 385 }
@@ -372,9 +387,16 @@ static int wl1251_boot_upload_firmware(struct wl1251 *wl)
372 /* 10.4 upload the last chunk */ 387 /* 10.4 upload the last chunk */
373 addr = WL1251_PART_DOWN_MEM_START + chunk_num * CHUNK_SIZE; 388 addr = WL1251_PART_DOWN_MEM_START + chunk_num * CHUNK_SIZE;
374 p = wl->fw + FW_HDR_SIZE + chunk_num * CHUNK_SIZE; 389 p = wl->fw + FW_HDR_SIZE + chunk_num * CHUNK_SIZE;
390
391 /* need to copy the chunk for dma */
392 len = fw_data_len % CHUNK_SIZE;
393 memcpy(buf, p, len);
394
375 wl1251_debug(DEBUG_BOOT, "uploading fw last chunk (%zu B) 0x%p to 0x%x", 395 wl1251_debug(DEBUG_BOOT, "uploading fw last chunk (%zu B) 0x%p to 0x%x",
376 fw_data_len % CHUNK_SIZE, p, addr); 396 len, p, addr);
377 wl1251_mem_write(wl, addr, p, fw_data_len % CHUNK_SIZE); 397 wl1251_mem_write(wl, addr, buf, len);
398
399 kfree(buf);
378 400
379 return 0; 401 return 0;
380} 402}
@@ -473,13 +495,19 @@ int wl1251_boot(struct wl1251 *wl)
473 goto out; 495 goto out;
474 496
475 /* 2. start processing NVS file */ 497 /* 2. start processing NVS file */
476 ret = wl1251_boot_upload_nvs(wl); 498 if (wl->use_eeprom) {
477 if (ret < 0) 499 wl1251_reg_write32(wl, ACX_REG_EE_START, START_EEPROM_MGR);
478 goto out; 500 msleep(4000);
479 501 wl1251_reg_write32(wl, ACX_EEPROMLESS_IND_REG, USE_EEPROM);
480 /* write firmware's last address (ie. it's length) to 502 } else {
481 * ACX_EEPROMLESS_IND_REG */ 503 ret = wl1251_boot_upload_nvs(wl);
482 wl1251_reg_write32(wl, ACX_EEPROMLESS_IND_REG, wl->fw_len); 504 if (ret < 0)
505 goto out;
506
507 /* write firmware's last address (ie. it's length) to
508 * ACX_EEPROMLESS_IND_REG */
509 wl1251_reg_write32(wl, ACX_EEPROMLESS_IND_REG, wl->fw_len);
510 }
483 511
484 /* 6. read the EEPROM parameters */ 512 /* 6. read the EEPROM parameters */
485 tmp = wl1251_reg_read32(wl, SCR_PAD2); 513 tmp = wl1251_reg_read32(wl, SCR_PAD2);
diff --git a/drivers/net/wireless/wl12xx/wl1251_cmd.c b/drivers/net/wireless/wl12xx/wl1251_cmd.c
index 770f260726bd..a37b30cef489 100644
--- a/drivers/net/wireless/wl12xx/wl1251_cmd.c
+++ b/drivers/net/wireless/wl12xx/wl1251_cmd.c
@@ -1,6 +1,7 @@
1#include "wl1251_cmd.h" 1#include "wl1251_cmd.h"
2 2
3#include <linux/module.h> 3#include <linux/module.h>
4#include <linux/slab.h>
4#include <linux/crc7.h> 5#include <linux/crc7.h>
5 6
6#include "wl1251.h" 7#include "wl1251.h"
@@ -410,3 +411,86 @@ out:
410 kfree(cmd); 411 kfree(cmd);
411 return ret; 412 return ret;
412} 413}
414
415int wl1251_cmd_scan(struct wl1251 *wl, u8 *ssid, size_t ssid_len,
416 struct ieee80211_channel *channels[],
417 unsigned int n_channels, unsigned int n_probes)
418{
419 struct wl1251_cmd_scan *cmd;
420 int i, ret = 0;
421
422 wl1251_debug(DEBUG_CMD, "cmd scan");
423
424 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
425 if (!cmd)
426 return -ENOMEM;
427
428 cmd->params.rx_config_options = cpu_to_le32(CFG_RX_ALL_GOOD);
429 cmd->params.rx_filter_options = cpu_to_le32(CFG_RX_PRSP_EN |
430 CFG_RX_MGMT_EN |
431 CFG_RX_BCN_EN);
432 cmd->params.scan_options = 0;
433 cmd->params.num_channels = n_channels;
434 cmd->params.num_probe_requests = n_probes;
435 cmd->params.tx_rate = cpu_to_le16(1 << 1); /* 2 Mbps */
436 cmd->params.tid_trigger = 0;
437
438 for (i = 0; i < n_channels; i++) {
439 cmd->channels[i].min_duration =
440 cpu_to_le32(WL1251_SCAN_MIN_DURATION);
441 cmd->channels[i].max_duration =
442 cpu_to_le32(WL1251_SCAN_MAX_DURATION);
443 memset(&cmd->channels[i].bssid_lsb, 0xff, 4);
444 memset(&cmd->channels[i].bssid_msb, 0xff, 2);
445 cmd->channels[i].early_termination = 0;
446 cmd->channels[i].tx_power_att = 0;
447 cmd->channels[i].channel = channels[i]->hw_value;
448 }
449
450 cmd->params.ssid_len = ssid_len;
451 if (ssid)
452 memcpy(cmd->params.ssid, ssid, ssid_len);
453
454 ret = wl1251_cmd_send(wl, CMD_SCAN, cmd, sizeof(*cmd));
455 if (ret < 0) {
456 wl1251_error("cmd scan failed: %d", ret);
457 goto out;
458 }
459
460 wl1251_mem_read(wl, wl->cmd_box_addr, cmd, sizeof(*cmd));
461
462 if (cmd->header.status != CMD_STATUS_SUCCESS) {
463 wl1251_error("cmd scan status wasn't success: %d",
464 cmd->header.status);
465 ret = -EIO;
466 goto out;
467 }
468
469out:
470 kfree(cmd);
471 return ret;
472}
473
474int wl1251_cmd_trigger_scan_to(struct wl1251 *wl, u32 timeout)
475{
476 struct wl1251_cmd_trigger_scan_to *cmd;
477 int ret;
478
479 wl1251_debug(DEBUG_CMD, "cmd trigger scan to");
480
481 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
482 if (!cmd)
483 return -ENOMEM;
484
485 cmd->timeout = timeout;
486
487 ret = wl1251_cmd_send(wl, CMD_SCAN, cmd, sizeof(*cmd));
488 if (ret < 0) {
489 wl1251_error("cmd trigger scan to failed: %d", ret);
490 goto out;
491 }
492
493out:
494 kfree(cmd);
495 return ret;
496}
diff --git a/drivers/net/wireless/wl12xx/wl1251_cmd.h b/drivers/net/wireless/wl12xx/wl1251_cmd.h
index dff798ad0ef5..4ad67cae94d2 100644
--- a/drivers/net/wireless/wl12xx/wl1251_cmd.h
+++ b/drivers/net/wireless/wl12xx/wl1251_cmd.h
@@ -27,6 +27,8 @@
27 27
28#include "wl1251.h" 28#include "wl1251.h"
29 29
30#include <net/cfg80211.h>
31
30struct acx_header; 32struct acx_header;
31 33
32int wl1251_cmd_send(struct wl1251 *wl, u16 type, void *buf, size_t buf_len); 34int wl1251_cmd_send(struct wl1251 *wl, u16 type, void *buf, size_t buf_len);
@@ -43,6 +45,10 @@ int wl1251_cmd_read_memory(struct wl1251 *wl, u32 addr, void *answer,
43 size_t len); 45 size_t len);
44int wl1251_cmd_template_set(struct wl1251 *wl, u16 cmd_id, 46int wl1251_cmd_template_set(struct wl1251 *wl, u16 cmd_id,
45 void *buf, size_t buf_len); 47 void *buf, size_t buf_len);
48int wl1251_cmd_scan(struct wl1251 *wl, u8 *ssid, size_t ssid_len,
49 struct ieee80211_channel *channels[],
50 unsigned int n_channels, unsigned int n_probes);
51int wl1251_cmd_trigger_scan_to(struct wl1251 *wl, u32 timeout);
46 52
47/* unit ms */ 53/* unit ms */
48#define WL1251_COMMAND_TIMEOUT 2000 54#define WL1251_COMMAND_TIMEOUT 2000
@@ -163,8 +169,12 @@ struct cmd_read_write_memory {
163#define CMDMBOX_HEADER_LEN 4 169#define CMDMBOX_HEADER_LEN 4
164#define CMDMBOX_INFO_ELEM_HEADER_LEN 4 170#define CMDMBOX_INFO_ELEM_HEADER_LEN 4
165 171
172#define WL1251_SCAN_MIN_DURATION 30000
173#define WL1251_SCAN_MAX_DURATION 60000
174
175#define WL1251_SCAN_NUM_PROBES 3
166 176
167struct basic_scan_parameters { 177struct wl1251_scan_parameters {
168 u32 rx_config_options; 178 u32 rx_config_options;
169 u32 rx_filter_options; 179 u32 rx_filter_options;
170 180
@@ -189,11 +199,11 @@ struct basic_scan_parameters {
189 199
190 u8 tid_trigger; 200 u8 tid_trigger;
191 u8 ssid_len; 201 u8 ssid_len;
192 u32 ssid[8]; 202 u8 ssid[32];
193 203
194} __attribute__ ((packed)); 204} __attribute__ ((packed));
195 205
196struct basic_scan_channel_parameters { 206struct wl1251_scan_ch_parameters {
197 u32 min_duration; /* in TU */ 207 u32 min_duration; /* in TU */
198 u32 max_duration; /* in TU */ 208 u32 max_duration; /* in TU */
199 u32 bssid_lsb; 209 u32 bssid_lsb;
@@ -213,11 +223,11 @@ struct basic_scan_channel_parameters {
213/* SCAN parameters */ 223/* SCAN parameters */
214#define SCAN_MAX_NUM_OF_CHANNELS 16 224#define SCAN_MAX_NUM_OF_CHANNELS 16
215 225
216struct cmd_scan { 226struct wl1251_cmd_scan {
217 struct wl1251_cmd_header header; 227 struct wl1251_cmd_header header;
218 228
219 struct basic_scan_parameters params; 229 struct wl1251_scan_parameters params;
220 struct basic_scan_channel_parameters channels[SCAN_MAX_NUM_OF_CHANNELS]; 230 struct wl1251_scan_ch_parameters channels[SCAN_MAX_NUM_OF_CHANNELS];
221} __attribute__ ((packed)); 231} __attribute__ ((packed));
222 232
223enum { 233enum {
diff --git a/drivers/net/wireless/wl12xx/wl1251_debugfs.c b/drivers/net/wireless/wl12xx/wl1251_debugfs.c
index a00723059f83..5e4465ac08fa 100644
--- a/drivers/net/wireless/wl12xx/wl1251_debugfs.c
+++ b/drivers/net/wireless/wl12xx/wl1251_debugfs.c
@@ -24,6 +24,7 @@
24#include "wl1251_debugfs.h" 24#include "wl1251_debugfs.h"
25 25
26#include <linux/skbuff.h> 26#include <linux/skbuff.h>
27#include <linux/slab.h>
27 28
28#include "wl1251.h" 29#include "wl1251.h"
29#include "wl1251_acx.h" 30#include "wl1251_acx.h"
@@ -237,6 +238,27 @@ static const struct file_operations tx_queue_len_ops = {
237 .open = wl1251_open_file_generic, 238 .open = wl1251_open_file_generic,
238}; 239};
239 240
241static ssize_t tx_queue_status_read(struct file *file, char __user *userbuf,
242 size_t count, loff_t *ppos)
243{
244 struct wl1251 *wl = file->private_data;
245 char buf[3], status;
246 int len;
247
248 if (wl->tx_queue_stopped)
249 status = 's';
250 else
251 status = 'r';
252
253 len = scnprintf(buf, sizeof(buf), "%c\n", status);
254 return simple_read_from_buffer(userbuf, count, ppos, buf, len);
255}
256
257static const struct file_operations tx_queue_status_ops = {
258 .read = tx_queue_status_read,
259 .open = wl1251_open_file_generic,
260};
261
240static void wl1251_debugfs_delete_files(struct wl1251 *wl) 262static void wl1251_debugfs_delete_files(struct wl1251 *wl)
241{ 263{
242 DEBUGFS_FWSTATS_DEL(tx, internal_desc_overflow); 264 DEBUGFS_FWSTATS_DEL(tx, internal_desc_overflow);
@@ -331,6 +353,7 @@ static void wl1251_debugfs_delete_files(struct wl1251 *wl)
331 DEBUGFS_FWSTATS_DEL(rxpipe, tx_xfr_host_int_trig_rx_data); 353 DEBUGFS_FWSTATS_DEL(rxpipe, tx_xfr_host_int_trig_rx_data);
332 354
333 DEBUGFS_DEL(tx_queue_len); 355 DEBUGFS_DEL(tx_queue_len);
356 DEBUGFS_DEL(tx_queue_status);
334 DEBUGFS_DEL(retry_count); 357 DEBUGFS_DEL(retry_count);
335 DEBUGFS_DEL(excessive_retries); 358 DEBUGFS_DEL(excessive_retries);
336} 359}
@@ -431,6 +454,7 @@ static int wl1251_debugfs_add_files(struct wl1251 *wl)
431 DEBUGFS_FWSTATS_ADD(rxpipe, tx_xfr_host_int_trig_rx_data); 454 DEBUGFS_FWSTATS_ADD(rxpipe, tx_xfr_host_int_trig_rx_data);
432 455
433 DEBUGFS_ADD(tx_queue_len, wl->debugfs.rootdir); 456 DEBUGFS_ADD(tx_queue_len, wl->debugfs.rootdir);
457 DEBUGFS_ADD(tx_queue_status, wl->debugfs.rootdir);
434 DEBUGFS_ADD(retry_count, wl->debugfs.rootdir); 458 DEBUGFS_ADD(retry_count, wl->debugfs.rootdir);
435 DEBUGFS_ADD(excessive_retries, wl->debugfs.rootdir); 459 DEBUGFS_ADD(excessive_retries, wl->debugfs.rootdir);
436 460
@@ -443,7 +467,8 @@ out:
443 467
444void wl1251_debugfs_reset(struct wl1251 *wl) 468void wl1251_debugfs_reset(struct wl1251 *wl)
445{ 469{
446 memset(wl->stats.fw_stats, 0, sizeof(*wl->stats.fw_stats)); 470 if (wl->stats.fw_stats != NULL)
471 memset(wl->stats.fw_stats, 0, sizeof(*wl->stats.fw_stats));
447 wl->stats.retry_count = 0; 472 wl->stats.retry_count = 0;
448 wl->stats.excessive_retries = 0; 473 wl->stats.excessive_retries = 0;
449} 474}
diff --git a/drivers/net/wireless/wl12xx/wl1251_event.c b/drivers/net/wireless/wl12xx/wl1251_event.c
index 00076c4a8a21..020d764f9c13 100644
--- a/drivers/net/wireless/wl12xx/wl1251_event.c
+++ b/drivers/net/wireless/wl12xx/wl1251_event.c
@@ -79,6 +79,21 @@ static int wl1251_event_process(struct wl1251 *wl, struct event_mailbox *mbox)
79 } 79 }
80 } 80 }
81 81
82 if (vector & SYNCHRONIZATION_TIMEOUT_EVENT_ID && wl->psm) {
83 wl1251_debug(DEBUG_EVENT, "SYNCHRONIZATION_TIMEOUT_EVENT");
84
85 /* indicate to the stack, that beacons have been lost */
86 ieee80211_beacon_loss(wl->vif);
87 }
88
89 if (vector & REGAINED_BSS_EVENT_ID) {
90 if (wl->psm_requested) {
91 ret = wl1251_ps_set_mode(wl, STATION_POWER_SAVE_MODE);
92 if (ret < 0)
93 return ret;
94 }
95 }
96
82 return 0; 97 return 0;
83} 98}
84 99
diff --git a/drivers/net/wireless/wl12xx/wl1251_init.c b/drivers/net/wireless/wl12xx/wl1251_init.c
index b2ee4f468fc4..b538bdd7b320 100644
--- a/drivers/net/wireless/wl12xx/wl1251_init.c
+++ b/drivers/net/wireless/wl12xx/wl1251_init.c
@@ -23,6 +23,7 @@
23 23
24#include <linux/kernel.h> 24#include <linux/kernel.h>
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/slab.h>
26 27
27#include "wl1251_init.h" 28#include "wl1251_init.h"
28#include "wl12xx_80211.h" 29#include "wl12xx_80211.h"
@@ -147,7 +148,8 @@ int wl1251_hw_init_beacon_filter(struct wl1251 *wl)
147{ 148{
148 int ret; 149 int ret;
149 150
150 ret = wl1251_acx_beacon_filter_opt(wl); 151 /* disable beacon filtering at this stage */
152 ret = wl1251_acx_beacon_filter_opt(wl, false);
151 if (ret < 0) 153 if (ret < 0)
152 return ret; 154 return ret;
153 155
@@ -293,6 +295,11 @@ static int wl1251_hw_init_tx_queue_config(struct wl1251 *wl)
293 goto out; 295 goto out;
294 } 296 }
295 297
298 wl1251_acx_ac_cfg(wl, AC_BE, CWMIN_BE, CWMAX_BE, AIFS_DIFS, TXOP_BE);
299 wl1251_acx_ac_cfg(wl, AC_BK, CWMIN_BK, CWMAX_BK, AIFS_DIFS, TXOP_BK);
300 wl1251_acx_ac_cfg(wl, AC_VI, CWMIN_VI, CWMAX_VI, AIFS_DIFS, TXOP_VI);
301 wl1251_acx_ac_cfg(wl, AC_VO, CWMIN_VO, CWMAX_VO, AIFS_DIFS, TXOP_VO);
302
296out: 303out:
297 kfree(config); 304 kfree(config);
298 return ret; 305 return ret;
@@ -364,6 +371,11 @@ int wl1251_hw_init(struct wl1251 *wl)
364 if (ret < 0) 371 if (ret < 0)
365 goto out_free_data_path; 372 goto out_free_data_path;
366 373
374 /* Initialize connection monitoring thresholds */
375 ret = wl1251_acx_conn_monit_params(wl);
376 if (ret < 0)
377 goto out_free_data_path;
378
367 /* Beacon filtering */ 379 /* Beacon filtering */
368 ret = wl1251_hw_init_beacon_filter(wl); 380 ret = wl1251_hw_init_beacon_filter(wl);
369 if (ret < 0) 381 if (ret < 0)
diff --git a/drivers/net/wireless/wl12xx/wl1251_init.h b/drivers/net/wireless/wl12xx/wl1251_init.h
index b3b25ec885ea..269cefb3e7d4 100644
--- a/drivers/net/wireless/wl12xx/wl1251_init.h
+++ b/drivers/net/wireless/wl12xx/wl1251_init.h
@@ -26,6 +26,53 @@
26 26
27#include "wl1251.h" 27#include "wl1251.h"
28 28
29enum {
30 /* best effort/legacy */
31 AC_BE = 0,
32
33 /* background */
34 AC_BK = 1,
35
36 /* video */
37 AC_VI = 2,
38
39 /* voice */
40 AC_VO = 3,
41
42 /* broadcast dummy access category */
43 AC_BCAST = 4,
44
45 NUM_ACCESS_CATEGORIES = 4
46};
47
48/* following are defult values for the IE fields*/
49#define CWMIN_BK 15
50#define CWMIN_BE 15
51#define CWMIN_VI 7
52#define CWMIN_VO 3
53#define CWMAX_BK 1023
54#define CWMAX_BE 63
55#define CWMAX_VI 15
56#define CWMAX_VO 7
57
58/* slot number setting to start transmission at PIFS interval */
59#define AIFS_PIFS 1
60
61/*
62 * slot number setting to start transmission at DIFS interval - normal DCF
63 * access
64 */
65#define AIFS_DIFS 2
66
67#define AIFSN_BK 7
68#define AIFSN_BE 3
69#define AIFSN_VI AIFS_PIFS
70#define AIFSN_VO AIFS_PIFS
71#define TXOP_BK 0
72#define TXOP_BE 0
73#define TXOP_VI 3008
74#define TXOP_VO 1504
75
29int wl1251_hw_init_hwenc_config(struct wl1251 *wl); 76int wl1251_hw_init_hwenc_config(struct wl1251 *wl);
30int wl1251_hw_init_templates_config(struct wl1251 *wl); 77int wl1251_hw_init_templates_config(struct wl1251 *wl);
31int wl1251_hw_init_rx_config(struct wl1251 *wl, u32 config, u32 filter); 78int wl1251_hw_init_rx_config(struct wl1251 *wl, u32 config, u32 filter);
diff --git a/drivers/net/wireless/wl12xx/wl1251_main.c b/drivers/net/wireless/wl12xx/wl1251_main.c
index 1103256ad989..1c8226eee409 100644
--- a/drivers/net/wireless/wl12xx/wl1251_main.c
+++ b/drivers/net/wireless/wl12xx/wl1251_main.c
@@ -28,6 +28,8 @@
28#include <linux/irq.h> 28#include <linux/irq.h>
29#include <linux/crc32.h> 29#include <linux/crc32.h>
30#include <linux/etherdevice.h> 30#include <linux/etherdevice.h>
31#include <linux/vmalloc.h>
32#include <linux/slab.h>
31 33
32#include "wl1251.h" 34#include "wl1251.h"
33#include "wl12xx_80211.h" 35#include "wl12xx_80211.h"
@@ -83,7 +85,7 @@ static int wl1251_fetch_firmware(struct wl1251 *wl)
83 } 85 }
84 86
85 wl->fw_len = fw->size; 87 wl->fw_len = fw->size;
86 wl->fw = kmalloc(wl->fw_len, GFP_KERNEL); 88 wl->fw = vmalloc(wl->fw_len);
87 89
88 if (!wl->fw) { 90 if (!wl->fw) {
89 wl1251_error("could not allocate memory for the firmware"); 91 wl1251_error("could not allocate memory for the firmware");
@@ -183,8 +185,11 @@ static int wl1251_chip_wakeup(struct wl1251 *wl)
183 wl1251_debug(DEBUG_BOOT, "chip id 0x%x (1251 PG12)", 185 wl1251_debug(DEBUG_BOOT, "chip id 0x%x (1251 PG12)",
184 wl->chip_id); 186 wl->chip_id);
185 break; 187 break;
186 case CHIP_ID_1251_PG10:
187 case CHIP_ID_1251_PG11: 188 case CHIP_ID_1251_PG11:
189 wl1251_debug(DEBUG_BOOT, "chip id 0x%x (1251 PG11)",
190 wl->chip_id);
191 break;
192 case CHIP_ID_1251_PG10:
188 default: 193 default:
189 wl1251_error("unsupported chip id: 0x%x", wl->chip_id); 194 wl1251_error("unsupported chip id: 0x%x", wl->chip_id);
190 ret = -ENODEV; 195 ret = -ENODEV;
@@ -208,9 +213,10 @@ out:
208 return ret; 213 return ret;
209} 214}
210 215
216#define WL1251_IRQ_LOOP_COUNT 10
211static void wl1251_irq_work(struct work_struct *work) 217static void wl1251_irq_work(struct work_struct *work)
212{ 218{
213 u32 intr; 219 u32 intr, ctr = WL1251_IRQ_LOOP_COUNT;
214 struct wl1251 *wl = 220 struct wl1251 *wl =
215 container_of(work, struct wl1251, irq_work); 221 container_of(work, struct wl1251, irq_work);
216 int ret; 222 int ret;
@@ -231,78 +237,86 @@ static void wl1251_irq_work(struct work_struct *work)
231 intr = wl1251_reg_read32(wl, ACX_REG_INTERRUPT_CLEAR); 237 intr = wl1251_reg_read32(wl, ACX_REG_INTERRUPT_CLEAR);
232 wl1251_debug(DEBUG_IRQ, "intr: 0x%x", intr); 238 wl1251_debug(DEBUG_IRQ, "intr: 0x%x", intr);
233 239
234 if (wl->data_path) { 240 do {
235 wl->rx_counter = 241 if (wl->data_path) {
236 wl1251_mem_read32(wl, wl->data_path->rx_control_addr); 242 wl->rx_counter = wl1251_mem_read32(
237 243 wl, wl->data_path->rx_control_addr);
238 /* We handle a frmware bug here */ 244
239 switch ((wl->rx_counter - wl->rx_handled) & 0xf) { 245 /* We handle a frmware bug here */
240 case 0: 246 switch ((wl->rx_counter - wl->rx_handled) & 0xf) {
241 wl1251_debug(DEBUG_IRQ, "RX: FW and host in sync"); 247 case 0:
242 intr &= ~WL1251_ACX_INTR_RX0_DATA; 248 wl1251_debug(DEBUG_IRQ,
243 intr &= ~WL1251_ACX_INTR_RX1_DATA; 249 "RX: FW and host in sync");
244 break; 250 intr &= ~WL1251_ACX_INTR_RX0_DATA;
245 case 1: 251 intr &= ~WL1251_ACX_INTR_RX1_DATA;
246 wl1251_debug(DEBUG_IRQ, "RX: FW +1"); 252 break;
247 intr |= WL1251_ACX_INTR_RX0_DATA; 253 case 1:
248 intr &= ~WL1251_ACX_INTR_RX1_DATA; 254 wl1251_debug(DEBUG_IRQ, "RX: FW +1");
249 break; 255 intr |= WL1251_ACX_INTR_RX0_DATA;
250 case 2: 256 intr &= ~WL1251_ACX_INTR_RX1_DATA;
251 wl1251_debug(DEBUG_IRQ, "RX: FW +2"); 257 break;
252 intr |= WL1251_ACX_INTR_RX0_DATA; 258 case 2:
253 intr |= WL1251_ACX_INTR_RX1_DATA; 259 wl1251_debug(DEBUG_IRQ, "RX: FW +2");
254 break; 260 intr |= WL1251_ACX_INTR_RX0_DATA;
255 default: 261 intr |= WL1251_ACX_INTR_RX1_DATA;
256 wl1251_warning("RX: FW and host out of sync: %d", 262 break;
257 wl->rx_counter - wl->rx_handled); 263 default:
258 break; 264 wl1251_warning(
259 } 265 "RX: FW and host out of sync: %d",
260 266 wl->rx_counter - wl->rx_handled);
261 wl->rx_handled = wl->rx_counter; 267 break;
268 }
262 269
270 wl->rx_handled = wl->rx_counter;
263 271
264 wl1251_debug(DEBUG_IRQ, "RX counter: %d", wl->rx_counter); 272 wl1251_debug(DEBUG_IRQ, "RX counter: %d",
265 } 273 wl->rx_counter);
274 }
266 275
267 intr &= wl->intr_mask; 276 intr &= wl->intr_mask;
268 277
269 if (intr == 0) { 278 if (intr == 0) {
270 wl1251_debug(DEBUG_IRQ, "INTR is 0"); 279 wl1251_debug(DEBUG_IRQ, "INTR is 0");
271 wl1251_reg_write32(wl, ACX_REG_INTERRUPT_MASK, 280 goto out_sleep;
272 ~(wl->intr_mask)); 281 }
273 282
274 goto out_sleep; 283 if (intr & WL1251_ACX_INTR_RX0_DATA) {
275 } 284 wl1251_debug(DEBUG_IRQ, "WL1251_ACX_INTR_RX0_DATA");
285 wl1251_rx(wl);
286 }
276 287
277 if (intr & WL1251_ACX_INTR_RX0_DATA) { 288 if (intr & WL1251_ACX_INTR_RX1_DATA) {
278 wl1251_debug(DEBUG_IRQ, "WL1251_ACX_INTR_RX0_DATA"); 289 wl1251_debug(DEBUG_IRQ, "WL1251_ACX_INTR_RX1_DATA");
279 wl1251_rx(wl); 290 wl1251_rx(wl);
280 } 291 }
281 292
282 if (intr & WL1251_ACX_INTR_RX1_DATA) { 293 if (intr & WL1251_ACX_INTR_TX_RESULT) {
283 wl1251_debug(DEBUG_IRQ, "WL1251_ACX_INTR_RX1_DATA"); 294 wl1251_debug(DEBUG_IRQ, "WL1251_ACX_INTR_TX_RESULT");
284 wl1251_rx(wl); 295 wl1251_tx_complete(wl);
285 } 296 }
286 297
287 if (intr & WL1251_ACX_INTR_TX_RESULT) { 298 if (intr & (WL1251_ACX_INTR_EVENT_A |
288 wl1251_debug(DEBUG_IRQ, "WL1251_ACX_INTR_TX_RESULT"); 299 WL1251_ACX_INTR_EVENT_B)) {
289 wl1251_tx_complete(wl); 300 wl1251_debug(DEBUG_IRQ, "WL1251_ACX_INTR_EVENT (0x%x)",
290 } 301 intr);
302 if (intr & WL1251_ACX_INTR_EVENT_A)
303 wl1251_event_handle(wl, 0);
304 else
305 wl1251_event_handle(wl, 1);
306 }
291 307
292 if (intr & (WL1251_ACX_INTR_EVENT_A | WL1251_ACX_INTR_EVENT_B)) { 308 if (intr & WL1251_ACX_INTR_INIT_COMPLETE)
293 wl1251_debug(DEBUG_IRQ, "WL1251_ACX_INTR_EVENT (0x%x)", intr); 309 wl1251_debug(DEBUG_IRQ,
294 if (intr & WL1251_ACX_INTR_EVENT_A) 310 "WL1251_ACX_INTR_INIT_COMPLETE");
295 wl1251_event_handle(wl, 0);
296 else
297 wl1251_event_handle(wl, 1);
298 }
299 311
300 if (intr & WL1251_ACX_INTR_INIT_COMPLETE) 312 if (--ctr == 0)
301 wl1251_debug(DEBUG_IRQ, "WL1251_ACX_INTR_INIT_COMPLETE"); 313 break;
302 314
303 wl1251_reg_write32(wl, ACX_REG_INTERRUPT_MASK, ~(wl->intr_mask)); 315 intr = wl1251_reg_read32(wl, ACX_REG_INTERRUPT_CLEAR);
316 } while (intr);
304 317
305out_sleep: 318out_sleep:
319 wl1251_reg_write32(wl, ACX_REG_INTERRUPT_MASK, ~(wl->intr_mask));
306 wl1251_ps_elp_sleep(wl); 320 wl1251_ps_elp_sleep(wl);
307 321
308out: 322out:
@@ -382,6 +396,7 @@ static int wl1251_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
382 * the queue here, otherwise the queue will get too long. 396 * the queue here, otherwise the queue will get too long.
383 */ 397 */
384 if (skb_queue_len(&wl->tx_queue) >= WL1251_TX_QUEUE_MAX_LENGTH) { 398 if (skb_queue_len(&wl->tx_queue) >= WL1251_TX_QUEUE_MAX_LENGTH) {
399 wl1251_debug(DEBUG_TX, "op_tx: tx_queue full, stop queues");
385 ieee80211_stop_queues(wl->hw); 400 ieee80211_stop_queues(wl->hw);
386 401
387 /* 402 /*
@@ -497,17 +512,23 @@ static void wl1251_op_stop(struct ieee80211_hw *hw)
497} 512}
498 513
499static int wl1251_op_add_interface(struct ieee80211_hw *hw, 514static int wl1251_op_add_interface(struct ieee80211_hw *hw,
500 struct ieee80211_if_init_conf *conf) 515 struct ieee80211_vif *vif)
501{ 516{
502 struct wl1251 *wl = hw->priv; 517 struct wl1251 *wl = hw->priv;
503 int ret = 0; 518 int ret = 0;
504 519
505 wl1251_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM", 520 wl1251_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM",
506 conf->type, conf->mac_addr); 521 vif->type, vif->addr);
507 522
508 mutex_lock(&wl->mutex); 523 mutex_lock(&wl->mutex);
524 if (wl->vif) {
525 ret = -EBUSY;
526 goto out;
527 }
528
529 wl->vif = vif;
509 530
510 switch (conf->type) { 531 switch (vif->type) {
511 case NL80211_IFTYPE_STATION: 532 case NL80211_IFTYPE_STATION:
512 wl->bss_type = BSS_TYPE_STA_BSS; 533 wl->bss_type = BSS_TYPE_STA_BSS;
513 break; 534 break;
@@ -519,8 +540,8 @@ static int wl1251_op_add_interface(struct ieee80211_hw *hw,
519 goto out; 540 goto out;
520 } 541 }
521 542
522 if (memcmp(wl->mac_addr, conf->mac_addr, ETH_ALEN)) { 543 if (memcmp(wl->mac_addr, vif->addr, ETH_ALEN)) {
523 memcpy(wl->mac_addr, conf->mac_addr, ETH_ALEN); 544 memcpy(wl->mac_addr, vif->addr, ETH_ALEN);
524 SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr); 545 SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr);
525 ret = wl1251_acx_station_id(wl); 546 ret = wl1251_acx_station_id(wl);
526 if (ret < 0) 547 if (ret < 0)
@@ -533,44 +554,35 @@ out:
533} 554}
534 555
535static void wl1251_op_remove_interface(struct ieee80211_hw *hw, 556static void wl1251_op_remove_interface(struct ieee80211_hw *hw,
536 struct ieee80211_if_init_conf *conf) 557 struct ieee80211_vif *vif)
537{ 558{
559 struct wl1251 *wl = hw->priv;
560
561 mutex_lock(&wl->mutex);
538 wl1251_debug(DEBUG_MAC80211, "mac80211 remove interface"); 562 wl1251_debug(DEBUG_MAC80211, "mac80211 remove interface");
563 wl->vif = NULL;
564 mutex_unlock(&wl->mutex);
539} 565}
540 566
541static int wl1251_build_null_data(struct wl1251 *wl) 567static int wl1251_build_qos_null_data(struct wl1251 *wl)
542{ 568{
543 struct wl12xx_null_data_template template; 569 struct ieee80211_qos_hdr template;
544 570
545 if (!is_zero_ether_addr(wl->bssid)) { 571 memset(&template, 0, sizeof(template));
546 memcpy(template.header.da, wl->bssid, ETH_ALEN);
547 memcpy(template.header.bssid, wl->bssid, ETH_ALEN);
548 } else {
549 memset(template.header.da, 0xff, ETH_ALEN);
550 memset(template.header.bssid, 0xff, ETH_ALEN);
551 }
552
553 memcpy(template.header.sa, wl->mac_addr, ETH_ALEN);
554 template.header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_DATA |
555 IEEE80211_STYPE_NULLFUNC);
556 572
557 return wl1251_cmd_template_set(wl, CMD_NULL_DATA, &template, 573 memcpy(template.addr1, wl->bssid, ETH_ALEN);
558 sizeof(template)); 574 memcpy(template.addr2, wl->mac_addr, ETH_ALEN);
559 575 memcpy(template.addr3, wl->bssid, ETH_ALEN);
560}
561 576
562static int wl1251_build_ps_poll(struct wl1251 *wl, u16 aid) 577 template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
563{ 578 IEEE80211_STYPE_QOS_NULLFUNC |
564 struct wl12xx_ps_poll_template template; 579 IEEE80211_FCTL_TODS);
565 580
566 memcpy(template.bssid, wl->bssid, ETH_ALEN); 581 /* FIXME: not sure what priority to use here */
567 memcpy(template.ta, wl->mac_addr, ETH_ALEN); 582 template.qos_ctrl = cpu_to_le16(0);
568 template.aid = aid;
569 template.fc = cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL);
570 583
571 return wl1251_cmd_template_set(wl, CMD_PS_POLL, &template, 584 return wl1251_cmd_template_set(wl, CMD_QOS_NULL_DATA, &template,
572 sizeof(template)); 585 sizeof(template));
573
574} 586}
575 587
576static int wl1251_op_config(struct ieee80211_hw *hw, u32 changed) 588static int wl1251_op_config(struct ieee80211_hw *hw, u32 changed)
@@ -601,35 +613,39 @@ static int wl1251_op_config(struct ieee80211_hw *hw, u32 changed)
601 goto out_sleep; 613 goto out_sleep;
602 } 614 }
603 615
604 ret = wl1251_build_null_data(wl);
605 if (ret < 0)
606 goto out_sleep;
607
608 if (conf->flags & IEEE80211_CONF_PS && !wl->psm_requested) { 616 if (conf->flags & IEEE80211_CONF_PS && !wl->psm_requested) {
609 wl1251_debug(DEBUG_PSM, "psm enabled"); 617 wl1251_debug(DEBUG_PSM, "psm enabled");
610 618
611 wl->psm_requested = true; 619 wl->psm_requested = true;
612 620
621 wl->dtim_period = conf->ps_dtim_period;
622
623 ret = wl1251_acx_wr_tbtt_and_dtim(wl, wl->beacon_int,
624 wl->dtim_period);
625
613 /* 626 /*
614 * We enter PSM only if we're already associated. 627 * mac80211 enables PSM only if we're already associated.
615 * If we're not, we'll enter it when joining an SSID,
616 * through the bss_info_changed() hook.
617 */ 628 */
618 ret = wl1251_ps_set_mode(wl, STATION_POWER_SAVE_MODE); 629 ret = wl1251_ps_set_mode(wl, STATION_POWER_SAVE_MODE);
630 if (ret < 0)
631 goto out_sleep;
619 } else if (!(conf->flags & IEEE80211_CONF_PS) && 632 } else if (!(conf->flags & IEEE80211_CONF_PS) &&
620 wl->psm_requested) { 633 wl->psm_requested) {
621 wl1251_debug(DEBUG_PSM, "psm disabled"); 634 wl1251_debug(DEBUG_PSM, "psm disabled");
622 635
623 wl->psm_requested = false; 636 wl->psm_requested = false;
624 637
625 if (wl->psm) 638 if (wl->psm) {
626 ret = wl1251_ps_set_mode(wl, STATION_ACTIVE_MODE); 639 ret = wl1251_ps_set_mode(wl, STATION_ACTIVE_MODE);
640 if (ret < 0)
641 goto out_sleep;
642 }
627 } 643 }
628 644
629 if (conf->power_level != wl->power_level) { 645 if (conf->power_level != wl->power_level) {
630 ret = wl1251_acx_tx_power(wl, conf->power_level); 646 ret = wl1251_acx_tx_power(wl, conf->power_level);
631 if (ret < 0) 647 if (ret < 0)
632 goto out; 648 goto out_sleep;
633 649
634 wl->power_level = conf->power_level; 650 wl->power_level = conf->power_level;
635 } 651 }
@@ -840,199 +856,61 @@ out:
840 return ret; 856 return ret;
841} 857}
842 858
843static int wl1251_build_basic_rates(char *rates) 859static int wl1251_op_hw_scan(struct ieee80211_hw *hw,
844{ 860 struct cfg80211_scan_request *req)
845 u8 index = 0;
846
847 rates[index++] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
848 rates[index++] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
849 rates[index++] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_5MB;
850 rates[index++] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_11MB;
851
852 return index;
853}
854
855static int wl1251_build_extended_rates(char *rates)
856{ 861{
857 u8 index = 0; 862 struct wl1251 *wl = hw->priv;
858 863 struct sk_buff *skb;
859 rates[index++] = IEEE80211_OFDM_RATE_6MB; 864 size_t ssid_len = 0;
860 rates[index++] = IEEE80211_OFDM_RATE_9MB; 865 u8 *ssid = NULL;
861 rates[index++] = IEEE80211_OFDM_RATE_12MB; 866 int ret;
862 rates[index++] = IEEE80211_OFDM_RATE_18MB;
863 rates[index++] = IEEE80211_OFDM_RATE_24MB;
864 rates[index++] = IEEE80211_OFDM_RATE_36MB;
865 rates[index++] = IEEE80211_OFDM_RATE_48MB;
866 rates[index++] = IEEE80211_OFDM_RATE_54MB;
867
868 return index;
869}
870
871 867
872static int wl1251_build_probe_req(struct wl1251 *wl, u8 *ssid, size_t ssid_len) 868 wl1251_debug(DEBUG_MAC80211, "mac80211 hw scan");
873{
874 struct wl12xx_probe_req_template template;
875 struct wl12xx_ie_rates *rates;
876 char *ptr;
877 u16 size;
878
879 ptr = (char *)&template;
880 size = sizeof(struct ieee80211_header);
881
882 memset(template.header.da, 0xff, ETH_ALEN);
883 memset(template.header.bssid, 0xff, ETH_ALEN);
884 memcpy(template.header.sa, wl->mac_addr, ETH_ALEN);
885 template.header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
886
887 /* IEs */
888 /* SSID */
889 template.ssid.header.id = WLAN_EID_SSID;
890 template.ssid.header.len = ssid_len;
891 if (ssid_len && ssid)
892 memcpy(template.ssid.ssid, ssid, ssid_len);
893 size += sizeof(struct wl12xx_ie_header) + ssid_len;
894 ptr += size;
895
896 /* Basic Rates */
897 rates = (struct wl12xx_ie_rates *)ptr;
898 rates->header.id = WLAN_EID_SUPP_RATES;
899 rates->header.len = wl1251_build_basic_rates(rates->rates);
900 size += sizeof(struct wl12xx_ie_header) + rates->header.len;
901 ptr += sizeof(struct wl12xx_ie_header) + rates->header.len;
902
903 /* Extended rates */
904 rates = (struct wl12xx_ie_rates *)ptr;
905 rates->header.id = WLAN_EID_EXT_SUPP_RATES;
906 rates->header.len = wl1251_build_extended_rates(rates->rates);
907 size += sizeof(struct wl12xx_ie_header) + rates->header.len;
908
909 wl1251_dump(DEBUG_SCAN, "PROBE REQ: ", &template, size);
910
911 return wl1251_cmd_template_set(wl, CMD_PROBE_REQ, &template,
912 size);
913}
914 869
915static int wl1251_hw_scan(struct wl1251 *wl, u8 *ssid, size_t len, 870 if (req->n_ssids) {
916 u8 active_scan, u8 high_prio, u8 num_channels, 871 ssid = req->ssids[0].ssid;
917 u8 probe_requests) 872 ssid_len = req->ssids[0].ssid_len;
918{
919 struct wl1251_cmd_trigger_scan_to *trigger = NULL;
920 struct cmd_scan *params = NULL;
921 int i, ret;
922 u16 scan_options = 0;
923
924 if (wl->scanning)
925 return -EINVAL;
926
927 params = kzalloc(sizeof(*params), GFP_KERNEL);
928 if (!params)
929 return -ENOMEM;
930
931 params->params.rx_config_options = cpu_to_le32(CFG_RX_ALL_GOOD);
932 params->params.rx_filter_options =
933 cpu_to_le32(CFG_RX_PRSP_EN | CFG_RX_MGMT_EN | CFG_RX_BCN_EN);
934
935 /* High priority scan */
936 if (!active_scan)
937 scan_options |= SCAN_PASSIVE;
938 if (high_prio)
939 scan_options |= SCAN_PRIORITY_HIGH;
940 params->params.scan_options = scan_options;
941
942 params->params.num_channels = num_channels;
943 params->params.num_probe_requests = probe_requests;
944 params->params.tx_rate = cpu_to_le16(1 << 1); /* 2 Mbps */
945 params->params.tid_trigger = 0;
946
947 for (i = 0; i < num_channels; i++) {
948 params->channels[i].min_duration = cpu_to_le32(30000);
949 params->channels[i].max_duration = cpu_to_le32(60000);
950 memset(&params->channels[i].bssid_lsb, 0xff, 4);
951 memset(&params->channels[i].bssid_msb, 0xff, 2);
952 params->channels[i].early_termination = 0;
953 params->channels[i].tx_power_att = 0;
954 params->channels[i].channel = i + 1;
955 memset(params->channels[i].pad, 0, 3);
956 } 873 }
957 874
958 for (i = num_channels; i < SCAN_MAX_NUM_OF_CHANNELS; i++) 875 mutex_lock(&wl->mutex);
959 memset(&params->channels[i], 0,
960 sizeof(struct basic_scan_channel_parameters));
961
962 if (len && ssid) {
963 params->params.ssid_len = len;
964 memcpy(params->params.ssid, ssid, len);
965 } else {
966 params->params.ssid_len = 0;
967 memset(params->params.ssid, 0, 32);
968 }
969 876
970 ret = wl1251_build_probe_req(wl, ssid, len); 877 if (wl->scanning) {
971 if (ret < 0) { 878 wl1251_debug(DEBUG_SCAN, "scan already in progress");
972 wl1251_error("PROBE request template failed"); 879 ret = -EINVAL;
973 goto out; 880 goto out;
974 } 881 }
975 882
976 trigger = kzalloc(sizeof(*trigger), GFP_KERNEL); 883 ret = wl1251_ps_elp_wakeup(wl);
977 if (!trigger) 884 if (ret < 0)
978 goto out; 885 goto out;
979 886
980 trigger->timeout = 0; 887 skb = ieee80211_probereq_get(wl->hw, wl->vif, ssid, ssid_len,
981 888 req->ie, req->ie_len);
982 ret = wl1251_cmd_send(wl, CMD_TRIGGER_SCAN_TO, trigger, 889 if (!skb) {
983 sizeof(*trigger)); 890 ret = -ENOMEM;
984 if (ret < 0) {
985 wl1251_error("trigger scan to failed for hw scan");
986 goto out; 891 goto out;
987 } 892 }
988 893
989 wl1251_dump(DEBUG_SCAN, "SCAN: ", params, sizeof(*params)); 894 ret = wl1251_cmd_template_set(wl, CMD_PROBE_REQ, skb->data,
990 895 skb->len);
991 wl->scanning = true; 896 dev_kfree_skb(skb);
897 if (ret < 0)
898 goto out_sleep;
992 899
993 ret = wl1251_cmd_send(wl, CMD_SCAN, params, sizeof(*params)); 900 ret = wl1251_cmd_trigger_scan_to(wl, 0);
994 if (ret < 0) 901 if (ret < 0)
995 wl1251_error("SCAN failed"); 902 goto out_sleep;
996 903
997 wl1251_mem_read(wl, wl->cmd_box_addr, params, sizeof(*params)); 904 wl->scanning = true;
998 905
999 if (params->header.status != CMD_STATUS_SUCCESS) { 906 ret = wl1251_cmd_scan(wl, ssid, ssid_len, req->channels,
1000 wl1251_error("TEST command answer error: %d", 907 req->n_channels, WL1251_SCAN_NUM_PROBES);
1001 params->header.status); 908 if (ret < 0) {
1002 wl->scanning = false; 909 wl->scanning = false;
1003 ret = -EIO; 910 goto out_sleep;
1004 goto out;
1005 }
1006
1007out:
1008 kfree(params);
1009 return ret;
1010
1011}
1012
1013static int wl1251_op_hw_scan(struct ieee80211_hw *hw,
1014 struct cfg80211_scan_request *req)
1015{
1016 struct wl1251 *wl = hw->priv;
1017 int ret;
1018 u8 *ssid = NULL;
1019 size_t ssid_len = 0;
1020
1021 wl1251_debug(DEBUG_MAC80211, "mac80211 hw scan");
1022
1023 if (req->n_ssids) {
1024 ssid = req->ssids[0].ssid;
1025 ssid_len = req->ssids[0].ssid_len;
1026 } 911 }
1027 912
1028 mutex_lock(&wl->mutex); 913out_sleep:
1029
1030 ret = wl1251_ps_elp_wakeup(wl);
1031 if (ret < 0)
1032 goto out;
1033
1034 ret = wl1251_hw_scan(hw->priv, ssid, ssid_len, 1, 0, 13, 3);
1035
1036 wl1251_ps_elp_sleep(wl); 914 wl1251_ps_elp_sleep(wl);
1037 915
1038out: 916out:
@@ -1069,9 +947,8 @@ static void wl1251_op_bss_info_changed(struct ieee80211_hw *hw,
1069 struct ieee80211_bss_conf *bss_conf, 947 struct ieee80211_bss_conf *bss_conf,
1070 u32 changed) 948 u32 changed)
1071{ 949{
1072 enum wl1251_cmd_ps_mode mode;
1073 struct wl1251 *wl = hw->priv; 950 struct wl1251 *wl = hw->priv;
1074 struct sk_buff *beacon; 951 struct sk_buff *beacon, *skb;
1075 int ret; 952 int ret;
1076 953
1077 wl1251_debug(DEBUG_MAC80211, "mac80211 bss info changed"); 954 wl1251_debug(DEBUG_MAC80211, "mac80211 bss info changed");
@@ -1082,30 +959,49 @@ static void wl1251_op_bss_info_changed(struct ieee80211_hw *hw,
1082 if (ret < 0) 959 if (ret < 0)
1083 goto out; 960 goto out;
1084 961
962 if (changed & BSS_CHANGED_BSSID) {
963 memcpy(wl->bssid, bss_conf->bssid, ETH_ALEN);
964
965 skb = ieee80211_nullfunc_get(wl->hw, wl->vif);
966 if (!skb)
967 goto out_sleep;
968
969 ret = wl1251_cmd_template_set(wl, CMD_NULL_DATA,
970 skb->data, skb->len);
971 dev_kfree_skb(skb);
972 if (ret < 0)
973 goto out_sleep;
974
975 ret = wl1251_build_qos_null_data(wl);
976 if (ret < 0)
977 goto out;
978
979 if (wl->bss_type != BSS_TYPE_IBSS) {
980 ret = wl1251_join(wl, wl->bss_type, wl->channel,
981 wl->beacon_int, wl->dtim_period);
982 if (ret < 0)
983 goto out_sleep;
984 }
985 }
986
1085 if (changed & BSS_CHANGED_ASSOC) { 987 if (changed & BSS_CHANGED_ASSOC) {
1086 if (bss_conf->assoc) { 988 if (bss_conf->assoc) {
1087 wl->beacon_int = bss_conf->beacon_int; 989 wl->beacon_int = bss_conf->beacon_int;
1088 wl->dtim_period = bss_conf->dtim_period;
1089
1090 /* FIXME: call join */
1091 990
1092 wl->aid = bss_conf->aid; 991 skb = ieee80211_pspoll_get(wl->hw, wl->vif);
992 if (!skb)
993 goto out_sleep;
1093 994
1094 ret = wl1251_build_ps_poll(wl, wl->aid); 995 ret = wl1251_cmd_template_set(wl, CMD_PS_POLL,
996 skb->data,
997 skb->len);
998 dev_kfree_skb(skb);
1095 if (ret < 0) 999 if (ret < 0)
1096 goto out_sleep; 1000 goto out_sleep;
1097 1001
1098 ret = wl1251_acx_aid(wl, wl->aid); 1002 ret = wl1251_acx_aid(wl, bss_conf->aid);
1099 if (ret < 0) 1003 if (ret < 0)
1100 goto out_sleep; 1004 goto out_sleep;
1101
1102 /* If we want to go in PSM but we're not there yet */
1103 if (wl->psm_requested && !wl->psm) {
1104 mode = STATION_POWER_SAVE_MODE;
1105 ret = wl1251_ps_set_mode(wl, mode);
1106 if (ret < 0)
1107 goto out_sleep;
1108 }
1109 } else { 1005 } else {
1110 /* use defaults when not associated */ 1006 /* use defaults when not associated */
1111 wl->beacon_int = WL1251_DEFAULT_BEACON_INT; 1007 wl->beacon_int = WL1251_DEFAULT_BEACON_INT;
@@ -1137,23 +1033,6 @@ static void wl1251_op_bss_info_changed(struct ieee80211_hw *hw,
1137 ret = wl1251_acx_cts_protect(wl, CTSPROTECT_DISABLE); 1033 ret = wl1251_acx_cts_protect(wl, CTSPROTECT_DISABLE);
1138 if (ret < 0) { 1034 if (ret < 0) {
1139 wl1251_warning("Set ctsprotect failed %d", ret); 1035 wl1251_warning("Set ctsprotect failed %d", ret);
1140 goto out;
1141 }
1142 }
1143
1144 if (changed & BSS_CHANGED_BSSID) {
1145 memcpy(wl->bssid, bss_conf->bssid, ETH_ALEN);
1146
1147 ret = wl1251_build_null_data(wl);
1148 if (ret < 0)
1149 goto out;
1150
1151 if (wl->bss_type != BSS_TYPE_IBSS) {
1152 ret = wl1251_join(wl, wl->bss_type, wl->channel,
1153 wl->beacon_int, wl->dtim_period);
1154 if (ret < 0)
1155 goto out_sleep;
1156 wl1251_warning("Set ctsprotect failed %d", ret);
1157 goto out_sleep; 1036 goto out_sleep;
1158 } 1037 }
1159 } 1038 }
@@ -1165,7 +1044,7 @@ static void wl1251_op_bss_info_changed(struct ieee80211_hw *hw,
1165 1044
1166 if (ret < 0) { 1045 if (ret < 0) {
1167 dev_kfree_skb(beacon); 1046 dev_kfree_skb(beacon);
1168 goto out; 1047 goto out_sleep;
1169 } 1048 }
1170 1049
1171 ret = wl1251_cmd_template_set(wl, CMD_PROBE_RESP, beacon->data, 1050 ret = wl1251_cmd_template_set(wl, CMD_PROBE_RESP, beacon->data,
@@ -1174,13 +1053,13 @@ static void wl1251_op_bss_info_changed(struct ieee80211_hw *hw,
1174 dev_kfree_skb(beacon); 1053 dev_kfree_skb(beacon);
1175 1054
1176 if (ret < 0) 1055 if (ret < 0)
1177 goto out; 1056 goto out_sleep;
1178 1057
1179 ret = wl1251_join(wl, wl->bss_type, wl->beacon_int, 1058 ret = wl1251_join(wl, wl->bss_type, wl->beacon_int,
1180 wl->channel, wl->dtim_period); 1059 wl->channel, wl->dtim_period);
1181 1060
1182 if (ret < 0) 1061 if (ret < 0)
1183 goto out; 1062 goto out_sleep;
1184 } 1063 }
1185 1064
1186out_sleep: 1065out_sleep:
@@ -1251,6 +1130,49 @@ static struct ieee80211_channel wl1251_channels[] = {
1251 { .hw_value = 13, .center_freq = 2472}, 1130 { .hw_value = 13, .center_freq = 2472},
1252}; 1131};
1253 1132
1133static int wl1251_op_conf_tx(struct ieee80211_hw *hw, u16 queue,
1134 const struct ieee80211_tx_queue_params *params)
1135{
1136 enum wl1251_acx_ps_scheme ps_scheme;
1137 struct wl1251 *wl = hw->priv;
1138 int ret;
1139
1140 mutex_lock(&wl->mutex);
1141
1142 wl1251_debug(DEBUG_MAC80211, "mac80211 conf tx %d", queue);
1143
1144 ret = wl1251_ps_elp_wakeup(wl);
1145 if (ret < 0)
1146 goto out;
1147
1148 /* mac80211 uses units of 32 usec */
1149 ret = wl1251_acx_ac_cfg(wl, wl1251_tx_get_queue(queue),
1150 params->cw_min, params->cw_max,
1151 params->aifs, params->txop * 32);
1152 if (ret < 0)
1153 goto out_sleep;
1154
1155 if (params->uapsd)
1156 ps_scheme = WL1251_ACX_PS_SCHEME_UPSD_TRIGGER;
1157 else
1158 ps_scheme = WL1251_ACX_PS_SCHEME_LEGACY;
1159
1160 ret = wl1251_acx_tid_cfg(wl, wl1251_tx_get_queue(queue),
1161 CHANNEL_TYPE_EDCF,
1162 wl1251_tx_get_queue(queue), ps_scheme,
1163 WL1251_ACX_ACK_POLICY_LEGACY);
1164 if (ret < 0)
1165 goto out_sleep;
1166
1167out_sleep:
1168 wl1251_ps_elp_sleep(wl);
1169
1170out:
1171 mutex_unlock(&wl->mutex);
1172
1173 return ret;
1174}
1175
1254/* can't be const, mac80211 writes to this */ 1176/* can't be const, mac80211 writes to this */
1255static struct ieee80211_supported_band wl1251_band_2ghz = { 1177static struct ieee80211_supported_band wl1251_band_2ghz = {
1256 .channels = wl1251_channels, 1178 .channels = wl1251_channels,
@@ -1271,6 +1193,7 @@ static const struct ieee80211_ops wl1251_ops = {
1271 .hw_scan = wl1251_op_hw_scan, 1193 .hw_scan = wl1251_op_hw_scan,
1272 .bss_info_changed = wl1251_op_bss_info_changed, 1194 .bss_info_changed = wl1251_op_bss_info_changed,
1273 .set_rts_threshold = wl1251_op_set_rts_threshold, 1195 .set_rts_threshold = wl1251_op_set_rts_threshold,
1196 .conf_tx = wl1251_op_conf_tx,
1274}; 1197};
1275 1198
1276static int wl1251_register_hw(struct wl1251 *wl) 1199static int wl1251_register_hw(struct wl1251 *wl)
@@ -1308,12 +1231,17 @@ int wl1251_init_ieee80211(struct wl1251 *wl)
1308 wl->hw->channel_change_time = 10000; 1231 wl->hw->channel_change_time = 10000;
1309 1232
1310 wl->hw->flags = IEEE80211_HW_SIGNAL_DBM | 1233 wl->hw->flags = IEEE80211_HW_SIGNAL_DBM |
1311 IEEE80211_HW_NOISE_DBM; 1234 IEEE80211_HW_NOISE_DBM |
1235 IEEE80211_HW_SUPPORTS_PS |
1236 IEEE80211_HW_BEACON_FILTER |
1237 IEEE80211_HW_SUPPORTS_UAPSD;
1312 1238
1313 wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION); 1239 wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
1314 wl->hw->wiphy->max_scan_ssids = 1; 1240 wl->hw->wiphy->max_scan_ssids = 1;
1315 wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl1251_band_2ghz; 1241 wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl1251_band_2ghz;
1316 1242
1243 wl->hw->queues = 4;
1244
1317 ret = wl1251_register_hw(wl); 1245 ret = wl1251_register_hw(wl);
1318 if (ret) 1246 if (ret)
1319 goto out; 1247 goto out;
@@ -1351,6 +1279,7 @@ struct ieee80211_hw *wl1251_alloc_hw(void)
1351 skb_queue_head_init(&wl->tx_queue); 1279 skb_queue_head_init(&wl->tx_queue);
1352 1280
1353 INIT_WORK(&wl->filter_work, wl1251_filter_work); 1281 INIT_WORK(&wl->filter_work, wl1251_filter_work);
1282 INIT_DELAYED_WORK(&wl->elp_work, wl1251_elp_work);
1354 wl->channel = WL1251_DEFAULT_CHANNEL; 1283 wl->channel = WL1251_DEFAULT_CHANNEL;
1355 wl->scanning = false; 1284 wl->scanning = false;
1356 wl->default_key = 0; 1285 wl->default_key = 0;
@@ -1368,6 +1297,7 @@ struct ieee80211_hw *wl1251_alloc_hw(void)
1368 wl->power_level = WL1251_DEFAULT_POWER_LEVEL; 1297 wl->power_level = WL1251_DEFAULT_POWER_LEVEL;
1369 wl->beacon_int = WL1251_DEFAULT_BEACON_INT; 1298 wl->beacon_int = WL1251_DEFAULT_BEACON_INT;
1370 wl->dtim_period = WL1251_DEFAULT_DTIM_PERIOD; 1299 wl->dtim_period = WL1251_DEFAULT_DTIM_PERIOD;
1300 wl->vif = NULL;
1371 1301
1372 for (i = 0; i < FW_TX_CMPLT_BLOCK_SIZE; i++) 1302 for (i = 0; i < FW_TX_CMPLT_BLOCK_SIZE; i++)
1373 wl->tx_frames[i] = NULL; 1303 wl->tx_frames[i] = NULL;
@@ -1409,7 +1339,7 @@ int wl1251_free_hw(struct wl1251 *wl)
1409 1339
1410 kfree(wl->target_mem_map); 1340 kfree(wl->target_mem_map);
1411 kfree(wl->data_path); 1341 kfree(wl->data_path);
1412 kfree(wl->fw); 1342 vfree(wl->fw);
1413 wl->fw = NULL; 1343 wl->fw = NULL;
1414 kfree(wl->nvs); 1344 kfree(wl->nvs);
1415 wl->nvs = NULL; 1345 wl->nvs = NULL;
@@ -1426,4 +1356,5 @@ EXPORT_SYMBOL_GPL(wl1251_free_hw);
1426MODULE_DESCRIPTION("TI wl1251 Wireles LAN Driver Core"); 1356MODULE_DESCRIPTION("TI wl1251 Wireles LAN Driver Core");
1427MODULE_LICENSE("GPL"); 1357MODULE_LICENSE("GPL");
1428MODULE_AUTHOR("Kalle Valo <kalle.valo@nokia.com>"); 1358MODULE_AUTHOR("Kalle Valo <kalle.valo@nokia.com>");
1429MODULE_ALIAS("spi:wl12xx"); 1359MODULE_ALIAS("spi:wl1251");
1360MODULE_FIRMWARE(WL1251_FW_NAME);
diff --git a/drivers/net/wireless/wl12xx/wl1251_ps.c b/drivers/net/wireless/wl12xx/wl1251_ps.c
index c53e28727ed4..851dfb65e474 100644
--- a/drivers/net/wireless/wl12xx/wl1251_ps.c
+++ b/drivers/net/wireless/wl12xx/wl1251_ps.c
@@ -26,24 +26,49 @@
26#include "wl1251_cmd.h" 26#include "wl1251_cmd.h"
27#include "wl1251_io.h" 27#include "wl1251_io.h"
28 28
29#define WL1251_WAKEUP_TIMEOUT 2000 29/* in ms */
30#define WL1251_WAKEUP_TIMEOUT 100
30 31
31/* Routines to toggle sleep mode while in ELP */ 32void wl1251_elp_work(struct work_struct *work)
32void wl1251_ps_elp_sleep(struct wl1251 *wl)
33{ 33{
34 struct delayed_work *dwork;
35 struct wl1251 *wl;
36
37 dwork = container_of(work, struct delayed_work, work);
38 wl = container_of(dwork, struct wl1251, elp_work);
39
40 wl1251_debug(DEBUG_PSM, "elp work");
41
42 mutex_lock(&wl->mutex);
43
34 if (wl->elp || !wl->psm) 44 if (wl->elp || !wl->psm)
35 return; 45 goto out;
36 46
37 wl1251_debug(DEBUG_PSM, "chip to elp"); 47 wl1251_debug(DEBUG_PSM, "chip to elp");
38
39 wl1251_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_SLEEP); 48 wl1251_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_SLEEP);
40
41 wl->elp = true; 49 wl->elp = true;
50
51out:
52 mutex_unlock(&wl->mutex);
53}
54
55#define ELP_ENTRY_DELAY 5
56
57/* Routines to toggle sleep mode while in ELP */
58void wl1251_ps_elp_sleep(struct wl1251 *wl)
59{
60 unsigned long delay;
61
62 if (wl->psm) {
63 cancel_delayed_work(&wl->elp_work);
64 delay = msecs_to_jiffies(ELP_ENTRY_DELAY);
65 ieee80211_queue_delayed_work(wl->hw, &wl->elp_work, delay);
66 }
42} 67}
43 68
44int wl1251_ps_elp_wakeup(struct wl1251 *wl) 69int wl1251_ps_elp_wakeup(struct wl1251 *wl)
45{ 70{
46 unsigned long timeout; 71 unsigned long timeout, start;
47 u32 elp_reg; 72 u32 elp_reg;
48 73
49 if (!wl->elp) 74 if (!wl->elp)
@@ -51,6 +76,7 @@ int wl1251_ps_elp_wakeup(struct wl1251 *wl)
51 76
52 wl1251_debug(DEBUG_PSM, "waking up chip from elp"); 77 wl1251_debug(DEBUG_PSM, "waking up chip from elp");
53 78
79 start = jiffies;
54 timeout = jiffies + msecs_to_jiffies(WL1251_WAKEUP_TIMEOUT); 80 timeout = jiffies + msecs_to_jiffies(WL1251_WAKEUP_TIMEOUT);
55 81
56 wl1251_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_WAKE_UP); 82 wl1251_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_WAKE_UP);
@@ -71,8 +97,7 @@ int wl1251_ps_elp_wakeup(struct wl1251 *wl)
71 } 97 }
72 98
73 wl1251_debug(DEBUG_PSM, "wakeup time: %u ms", 99 wl1251_debug(DEBUG_PSM, "wakeup time: %u ms",
74 jiffies_to_msecs(jiffies) - 100 jiffies_to_msecs(jiffies - start));
75 (jiffies_to_msecs(timeout) - WL1251_WAKEUP_TIMEOUT));
76 101
77 wl->elp = false; 102 wl->elp = false;
78 103
@@ -119,6 +144,11 @@ int wl1251_ps_set_mode(struct wl1251 *wl, enum wl1251_cmd_ps_mode mode)
119 case STATION_POWER_SAVE_MODE: 144 case STATION_POWER_SAVE_MODE:
120 wl1251_debug(DEBUG_PSM, "entering psm"); 145 wl1251_debug(DEBUG_PSM, "entering psm");
121 146
147 /* enable beacon filtering */
148 ret = wl1251_acx_beacon_filter_opt(wl, true);
149 if (ret < 0)
150 return ret;
151
122 ret = wl1251_acx_wake_up_conditions(wl, 152 ret = wl1251_acx_wake_up_conditions(wl,
123 WAKE_UP_EVENT_DTIM_BITMAP, 153 WAKE_UP_EVENT_DTIM_BITMAP,
124 wl->listen_int); 154 wl->listen_int);
@@ -142,6 +172,11 @@ int wl1251_ps_set_mode(struct wl1251 *wl, enum wl1251_cmd_ps_mode mode)
142 if (ret < 0) 172 if (ret < 0)
143 return ret; 173 return ret;
144 174
175 /* disable beacon filtering */
176 ret = wl1251_acx_beacon_filter_opt(wl, false);
177 if (ret < 0)
178 return ret;
179
145 ret = wl1251_acx_wake_up_conditions(wl, 180 ret = wl1251_acx_wake_up_conditions(wl,
146 WAKE_UP_EVENT_DTIM_BITMAP, 181 WAKE_UP_EVENT_DTIM_BITMAP,
147 wl->listen_int); 182 wl->listen_int);
diff --git a/drivers/net/wireless/wl12xx/wl1251_ps.h b/drivers/net/wireless/wl12xx/wl1251_ps.h
index db036fe12f25..c688ac57aee4 100644
--- a/drivers/net/wireless/wl12xx/wl1251_ps.h
+++ b/drivers/net/wireless/wl12xx/wl1251_ps.h
@@ -31,6 +31,7 @@
31int wl1251_ps_set_mode(struct wl1251 *wl, enum wl1251_cmd_ps_mode mode); 31int wl1251_ps_set_mode(struct wl1251 *wl, enum wl1251_cmd_ps_mode mode);
32void wl1251_ps_elp_sleep(struct wl1251 *wl); 32void wl1251_ps_elp_sleep(struct wl1251 *wl);
33int wl1251_ps_elp_wakeup(struct wl1251 *wl); 33int wl1251_ps_elp_wakeup(struct wl1251 *wl);
34void wl1251_elp_work(struct work_struct *work);
34 35
35 36
36#endif /* __WL1251_PS_H__ */ 37#endif /* __WL1251_PS_H__ */
diff --git a/drivers/net/wireless/wl12xx/wl1251_reg.h b/drivers/net/wireless/wl12xx/wl1251_reg.h
index 06e1bd94a739..0ca3b4326056 100644
--- a/drivers/net/wireless/wl12xx/wl1251_reg.h
+++ b/drivers/net/wireless/wl12xx/wl1251_reg.h
@@ -370,6 +370,7 @@ enum wl12xx_acx_int_reg {
370 EEPROM location specified in the EE_ADDR register. 370 EEPROM location specified in the EE_ADDR register.
371 The Wlan hardware hardware clears this bit automatically. 371 The Wlan hardware hardware clears this bit automatically.
372*===============================================*/ 372*===============================================*/
373#define EE_CTL (REGISTERS_BASE + 0x2000)
373#define ACX_EE_CTL_REG EE_CTL 374#define ACX_EE_CTL_REG EE_CTL
374#define EE_WRITE 0x00000001ul 375#define EE_WRITE 0x00000001ul
375#define EE_READ 0x00000002ul 376#define EE_READ 0x00000002ul
@@ -380,6 +381,7 @@ enum wl12xx_acx_int_reg {
380 This register specifies the address 381 This register specifies the address
381 within the EEPROM from/to which to read/write data. 382 within the EEPROM from/to which to read/write data.
382 ===============================================*/ 383 ===============================================*/
384#define EE_ADDR (REGISTERS_BASE + 0x2008)
383#define ACX_EE_ADDR_REG EE_ADDR 385#define ACX_EE_ADDR_REG EE_ADDR
384 386
385/*=============================================== 387/*===============================================
@@ -389,8 +391,12 @@ enum wl12xx_acx_int_reg {
389 data from the EEPROM or the write data 391 data from the EEPROM or the write data
390 to be written to the EEPROM. 392 to be written to the EEPROM.
391 ===============================================*/ 393 ===============================================*/
394#define EE_DATA (REGISTERS_BASE + 0x2004)
392#define ACX_EE_DATA_REG EE_DATA 395#define ACX_EE_DATA_REG EE_DATA
393 396
397#define EEPROM_ACCESS_TO 10000 /* timeout counter */
398#define START_EEPROM_MGR 0x00000001
399
394/*=============================================== 400/*===============================================
395 EEPROM Base Address - 32bit RW 401 EEPROM Base Address - 32bit RW
396 ------------------------------------------ 402 ------------------------------------------
diff --git a/drivers/net/wireless/wl12xx/wl1251_rx.c b/drivers/net/wireless/wl12xx/wl1251_rx.c
index 17c54b59ef86..6f229e0990f4 100644
--- a/drivers/net/wireless/wl12xx/wl1251_rx.c
+++ b/drivers/net/wireless/wl12xx/wl1251_rx.c
@@ -23,6 +23,7 @@
23 */ 23 */
24 24
25#include <linux/skbuff.h> 25#include <linux/skbuff.h>
26#include <linux/gfp.h>
26#include <net/mac80211.h> 27#include <net/mac80211.h>
27 28
28#include "wl1251.h" 29#include "wl1251.h"
@@ -72,10 +73,6 @@ static void wl1251_rx_status(struct wl1251 *wl,
72 } 73 }
73 74
74 status->signal = desc->rssi; 75 status->signal = desc->rssi;
75 status->qual = (desc->rssi - WL1251_RX_MIN_RSSI) * 100 /
76 (WL1251_RX_MAX_RSSI - WL1251_RX_MIN_RSSI);
77 status->qual = min(status->qual, 100);
78 status->qual = max(status->qual, 0);
79 76
80 /* 77 /*
81 * FIXME: guessing that snr needs to be divided by two, otherwise 78 * FIXME: guessing that snr needs to be divided by two, otherwise
@@ -130,7 +127,7 @@ static void wl1251_rx_body(struct wl1251 *wl,
130 if (wl->rx_current_buffer) 127 if (wl->rx_current_buffer)
131 rx_packet_ring_addr += wl->data_path->rx_packet_ring_chunk_size; 128 rx_packet_ring_addr += wl->data_path->rx_packet_ring_chunk_size;
132 129
133 skb = dev_alloc_skb(length); 130 skb = __dev_alloc_skb(length, GFP_KERNEL);
134 if (!skb) { 131 if (!skb) {
135 wl1251_error("Couldn't allocate RX frame"); 132 wl1251_error("Couldn't allocate RX frame");
136 return; 133 return;
@@ -153,7 +150,7 @@ static void wl1251_rx_body(struct wl1251 *wl,
153 beacon ? "beacon" : ""); 150 beacon ? "beacon" : "");
154 151
155 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status)); 152 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
156 ieee80211_rx(wl->hw, skb); 153 ieee80211_rx_ni(wl->hw, skb);
157} 154}
158 155
159static void wl1251_rx_ack(struct wl1251 *wl) 156static void wl1251_rx_ack(struct wl1251 *wl)
diff --git a/drivers/net/wireless/wl12xx/wl1251_spi.c b/drivers/net/wireless/wl12xx/wl1251_spi.c
index 14eff2b3d4c6..3bfb59bd4635 100644
--- a/drivers/net/wireless/wl12xx/wl1251_spi.c
+++ b/drivers/net/wireless/wl12xx/wl1251_spi.c
@@ -23,6 +23,7 @@
23 23
24#include <linux/irq.h> 24#include <linux/irq.h>
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/slab.h>
26#include <linux/crc7.h> 27#include <linux/crc7.h>
27#include <linux/spi/spi.h> 28#include <linux/spi/spi.h>
28#include <linux/spi/wl12xx.h> 29#include <linux/spi/wl12xx.h>
@@ -270,6 +271,8 @@ static int __devinit wl1251_spi_probe(struct spi_device *spi)
270 return -ENODEV; 271 return -ENODEV;
271 } 272 }
272 273
274 wl->use_eeprom = pdata->use_eeprom;
275
273 ret = request_irq(wl->irq, wl1251_irq, 0, DRIVER_NAME, wl); 276 ret = request_irq(wl->irq, wl1251_irq, 0, DRIVER_NAME, wl);
274 if (ret < 0) { 277 if (ret < 0) {
275 wl1251_error("request_irq() failed: %d", ret); 278 wl1251_error("request_irq() failed: %d", ret);
@@ -307,7 +310,7 @@ static int __devexit wl1251_spi_remove(struct spi_device *spi)
307 310
308static struct spi_driver wl1251_spi_driver = { 311static struct spi_driver wl1251_spi_driver = {
309 .driver = { 312 .driver = {
310 .name = "wl12xx", 313 .name = "wl1251",
311 .bus = &spi_bus_type, 314 .bus = &spi_bus_type,
312 .owner = THIS_MODULE, 315 .owner = THIS_MODULE,
313 }, 316 },
diff --git a/drivers/net/wireless/wl12xx/wl1251_tx.c b/drivers/net/wireless/wl12xx/wl1251_tx.c
index f85970615849..c8223185efd2 100644
--- a/drivers/net/wireless/wl12xx/wl1251_tx.c
+++ b/drivers/net/wireless/wl12xx/wl1251_tx.c
@@ -167,8 +167,7 @@ static int wl1251_tx_fill_hdr(struct wl1251 *wl, struct sk_buff *skb,
167 tx_hdr->expiry_time = cpu_to_le32(1 << 16); 167 tx_hdr->expiry_time = cpu_to_le32(1 << 16);
168 tx_hdr->id = id; 168 tx_hdr->id = id;
169 169
170 /* FIXME: how to get the correct queue id? */ 170 tx_hdr->xmit_queue = wl1251_tx_get_queue(skb_get_queue_mapping(skb));
171 tx_hdr->xmit_queue = 0;
172 171
173 wl1251_tx_control(tx_hdr, control, fc); 172 wl1251_tx_control(tx_hdr, control, fc);
174 wl1251_tx_frag_block_num(tx_hdr); 173 wl1251_tx_frag_block_num(tx_hdr);
@@ -220,6 +219,7 @@ static int wl1251_tx_send_packet(struct wl1251 *wl, struct sk_buff *skb,
220 /* align the buffer on a 4-byte boundary */ 219 /* align the buffer on a 4-byte boundary */
221 skb_reserve(skb, offset); 220 skb_reserve(skb, offset);
222 memmove(skb->data, src, skb->len); 221 memmove(skb->data, src, skb->len);
222 tx_hdr = (struct tx_double_buffer_desc *) skb->data;
223 } else { 223 } else {
224 wl1251_info("No handler, fixme!"); 224 wl1251_info("No handler, fixme!");
225 return -EINVAL; 225 return -EINVAL;
@@ -237,8 +237,9 @@ static int wl1251_tx_send_packet(struct wl1251 *wl, struct sk_buff *skb,
237 237
238 wl1251_mem_write(wl, addr, skb->data, len); 238 wl1251_mem_write(wl, addr, skb->data, len);
239 239
240 wl1251_debug(DEBUG_TX, "tx id %u skb 0x%p payload %u rate 0x%x", 240 wl1251_debug(DEBUG_TX, "tx id %u skb 0x%p payload %u rate 0x%x "
241 tx_hdr->id, skb, tx_hdr->length, tx_hdr->rate); 241 "queue %d", tx_hdr->id, skb, tx_hdr->length,
242 tx_hdr->rate, tx_hdr->xmit_queue);
242 243
243 return 0; 244 return 0;
244} 245}
diff --git a/drivers/net/wireless/wl12xx/wl1251_tx.h b/drivers/net/wireless/wl12xx/wl1251_tx.h
index 7c1c1665c810..55856c6bb97a 100644
--- a/drivers/net/wireless/wl12xx/wl1251_tx.h
+++ b/drivers/net/wireless/wl12xx/wl1251_tx.h
@@ -26,6 +26,7 @@
26#define __WL1251_TX_H__ 26#define __WL1251_TX_H__
27 27
28#include <linux/bitops.h> 28#include <linux/bitops.h>
29#include "wl1251_acx.h"
29 30
30/* 31/*
31 * 32 *
@@ -209,6 +210,22 @@ struct tx_result {
209 u8 done_2; 210 u8 done_2;
210} __attribute__ ((packed)); 211} __attribute__ ((packed));
211 212
213static inline int wl1251_tx_get_queue(int queue)
214{
215 switch (queue) {
216 case 0:
217 return QOS_AC_VO;
218 case 1:
219 return QOS_AC_VI;
220 case 2:
221 return QOS_AC_BE;
222 case 3:
223 return QOS_AC_BK;
224 default:
225 return QOS_AC_BE;
226 }
227}
228
212void wl1251_tx_work(struct work_struct *work); 229void wl1251_tx_work(struct work_struct *work);
213void wl1251_tx_complete(struct wl1251 *wl); 230void wl1251_tx_complete(struct wl1251 *wl);
214void wl1251_tx_flush(struct wl1251 *wl); 231void wl1251_tx_flush(struct wl1251 *wl);
diff --git a/drivers/net/wireless/wl12xx/wl1271.h b/drivers/net/wireless/wl12xx/wl1271.h
index 55818f94017b..97ea5096bc8c 100644
--- a/drivers/net/wireless/wl12xx/wl1271.h
+++ b/drivers/net/wireless/wl12xx/wl1271.h
@@ -32,6 +32,8 @@
32#include <linux/bitops.h> 32#include <linux/bitops.h>
33#include <net/mac80211.h> 33#include <net/mac80211.h>
34 34
35#include "wl1271_conf.h"
36
35#define DRIVER_NAME "wl1271" 37#define DRIVER_NAME "wl1271"
36#define DRIVER_PREFIX DRIVER_NAME ": " 38#define DRIVER_PREFIX DRIVER_NAME ": "
37 39
@@ -41,7 +43,7 @@ enum {
41 DEBUG_SPI = BIT(1), 43 DEBUG_SPI = BIT(1),
42 DEBUG_BOOT = BIT(2), 44 DEBUG_BOOT = BIT(2),
43 DEBUG_MAILBOX = BIT(3), 45 DEBUG_MAILBOX = BIT(3),
44 DEBUG_NETLINK = BIT(4), 46 DEBUG_TESTMODE = BIT(4),
45 DEBUG_EVENT = BIT(5), 47 DEBUG_EVENT = BIT(5),
46 DEBUG_TX = BIT(6), 48 DEBUG_TX = BIT(6),
47 DEBUG_RX = BIT(7), 49 DEBUG_RX = BIT(7),
@@ -97,7 +99,8 @@ enum {
97 } while (0) 99 } while (0)
98 100
99#define WL1271_DEFAULT_RX_CONFIG (CFG_UNI_FILTER_EN | \ 101#define WL1271_DEFAULT_RX_CONFIG (CFG_UNI_FILTER_EN | \
100 CFG_BSSID_FILTER_EN) 102 CFG_BSSID_FILTER_EN | \
103 CFG_MC_FILTER_EN)
101 104
102#define WL1271_DEFAULT_RX_FILTER (CFG_RX_RCTS_ACK | CFG_RX_PRSP_EN | \ 105#define WL1271_DEFAULT_RX_FILTER (CFG_RX_RCTS_ACK | CFG_RX_PRSP_EN | \
103 CFG_RX_MGMT_EN | CFG_RX_DATA_EN | \ 106 CFG_RX_MGMT_EN | CFG_RX_DATA_EN | \
@@ -107,11 +110,56 @@ enum {
107#define WL1271_FW_NAME "wl1271-fw.bin" 110#define WL1271_FW_NAME "wl1271-fw.bin"
108#define WL1271_NVS_NAME "wl1271-nvs.bin" 111#define WL1271_NVS_NAME "wl1271-nvs.bin"
109 112
110#define WL1271_BUSY_WORD_LEN 8 113/* NVS data structure */
114#define WL1271_NVS_SECTION_SIZE 468
115
116#define WL1271_NVS_GENERAL_PARAMS_SIZE 57
117#define WL1271_NVS_GENERAL_PARAMS_SIZE_PADDED \
118 (WL1271_NVS_GENERAL_PARAMS_SIZE + 1)
119#define WL1271_NVS_STAT_RADIO_PARAMS_SIZE 17
120#define WL1271_NVS_STAT_RADIO_PARAMS_SIZE_PADDED \
121 (WL1271_NVS_STAT_RADIO_PARAMS_SIZE + 1)
122#define WL1271_NVS_DYN_RADIO_PARAMS_SIZE 65
123#define WL1271_NVS_DYN_RADIO_PARAMS_SIZE_PADDED \
124 (WL1271_NVS_DYN_RADIO_PARAMS_SIZE + 1)
125#define WL1271_NVS_FEM_COUNT 2
126#define WL1271_NVS_INI_SPARE_SIZE 124
127
128struct wl1271_nvs_file {
129 /* NVS section */
130 u8 nvs[WL1271_NVS_SECTION_SIZE];
131
132 /* INI section */
133 u8 general_params[WL1271_NVS_GENERAL_PARAMS_SIZE_PADDED];
134 u8 stat_radio_params[WL1271_NVS_STAT_RADIO_PARAMS_SIZE_PADDED];
135 u8 dyn_radio_params[WL1271_NVS_FEM_COUNT]
136 [WL1271_NVS_DYN_RADIO_PARAMS_SIZE_PADDED];
137 u8 ini_spare[WL1271_NVS_INI_SPARE_SIZE];
138} __attribute__ ((packed));
139
140/*
141 * Enable/disable 802.11a support for WL1273
142 */
143#undef WL1271_80211A_ENABLED
144
145/*
146 * FIXME: for the wl1271, a busy word count of 1 here will result in a more
147 * optimal SPI interface. There is some SPI bug however, causing RXS time outs
148 * with this mode occasionally on boot, so lets have three for now. A value of
149 * three should make sure, that the chipset will always be ready, though this
150 * will impact throughput and latencies slightly.
151 */
152#define WL1271_BUSY_WORD_CNT 3
153#define WL1271_BUSY_WORD_LEN (WL1271_BUSY_WORD_CNT * sizeof(u32))
111 154
112#define WL1271_ELP_HW_STATE_ASLEEP 0 155#define WL1271_ELP_HW_STATE_ASLEEP 0
113#define WL1271_ELP_HW_STATE_IRQ 1 156#define WL1271_ELP_HW_STATE_IRQ 1
114 157
158#define WL1271_DEFAULT_BEACON_INT 100
159#define WL1271_DEFAULT_DTIM_PERIOD 1
160
161#define ACX_TX_DESCRIPTORS 32
162
115enum wl1271_state { 163enum wl1271_state {
116 WL1271_STATE_OFF, 164 WL1271_STATE_OFF,
117 WL1271_STATE_ON, 165 WL1271_STATE_ON,
@@ -134,6 +182,8 @@ struct wl1271_partition {
134struct wl1271_partition_set { 182struct wl1271_partition_set {
135 struct wl1271_partition mem; 183 struct wl1271_partition mem;
136 struct wl1271_partition reg; 184 struct wl1271_partition reg;
185 struct wl1271_partition mem2;
186 struct wl1271_partition mem3;
137}; 187};
138 188
139struct wl1271; 189struct wl1271;
@@ -251,6 +301,7 @@ struct wl1271_debugfs {
251 301
252 struct dentry *retry_count; 302 struct dentry *retry_count;
253 struct dentry *excessive_retries; 303 struct dentry *excessive_retries;
304 struct dentry *gpio_power;
254}; 305};
255 306
256#define NUM_TX_QUEUES 4 307#define NUM_TX_QUEUES 4
@@ -258,15 +309,15 @@ struct wl1271_debugfs {
258 309
259/* FW status registers */ 310/* FW status registers */
260struct wl1271_fw_status { 311struct wl1271_fw_status {
261 u32 intr; 312 __le32 intr;
262 u8 fw_rx_counter; 313 u8 fw_rx_counter;
263 u8 drv_rx_counter; 314 u8 drv_rx_counter;
264 u8 reserved; 315 u8 reserved;
265 u8 tx_results_counter; 316 u8 tx_results_counter;
266 u32 rx_pkt_descs[NUM_RX_PKT_DESC]; 317 __le32 rx_pkt_descs[NUM_RX_PKT_DESC];
267 u32 tx_released_blks[NUM_TX_QUEUES]; 318 __le32 tx_released_blks[NUM_TX_QUEUES];
268 u32 fw_localtime; 319 __le32 fw_localtime;
269 u32 padding[2]; 320 __le32 padding[2];
270} __attribute__ ((packed)); 321} __attribute__ ((packed));
271 322
272struct wl1271_rx_mem_pool_addr { 323struct wl1271_rx_mem_pool_addr {
@@ -274,6 +325,15 @@ struct wl1271_rx_mem_pool_addr {
274 u32 addr_extra; 325 u32 addr_extra;
275}; 326};
276 327
328struct wl1271_scan {
329 u8 state;
330 u8 ssid[IW_ESSID_MAX_SIZE+1];
331 size_t ssid_len;
332 u8 active;
333 u8 high_prio;
334 u8 probe_requests;
335};
336
277struct wl1271 { 337struct wl1271 {
278 struct ieee80211_hw *hw; 338 struct ieee80211_hw *hw;
279 bool mac80211_registered; 339 bool mac80211_registered;
@@ -288,10 +348,18 @@ struct wl1271 {
288 enum wl1271_state state; 348 enum wl1271_state state;
289 struct mutex mutex; 349 struct mutex mutex;
290 350
291 int physical_mem_addr; 351#define WL1271_FLAG_STA_RATES_CHANGED (0)
292 int physical_reg_addr; 352#define WL1271_FLAG_STA_ASSOCIATED (1)
293 int virtual_mem_addr; 353#define WL1271_FLAG_JOINED (2)
294 int virtual_reg_addr; 354#define WL1271_FLAG_GPIO_POWER (3)
355#define WL1271_FLAG_TX_QUEUE_STOPPED (4)
356#define WL1271_FLAG_SCANNING (5)
357#define WL1271_FLAG_IN_ELP (6)
358#define WL1271_FLAG_PSM (7)
359#define WL1271_FLAG_PSM_REQUESTED (8)
360 unsigned long flags;
361
362 struct wl1271_partition_set part;
295 363
296 struct wl1271_chip chip; 364 struct wl1271_chip chip;
297 365
@@ -300,15 +368,13 @@ struct wl1271 {
300 368
301 u8 *fw; 369 u8 *fw;
302 size_t fw_len; 370 size_t fw_len;
303 u8 *nvs; 371 struct wl1271_nvs_file *nvs;
304 size_t nvs_len;
305 372
306 u8 bssid[ETH_ALEN]; 373 u8 bssid[ETH_ALEN];
307 u8 mac_addr[ETH_ALEN]; 374 u8 mac_addr[ETH_ALEN];
308 u8 bss_type; 375 u8 bss_type;
309 u8 ssid[IW_ESSID_MAX_SIZE + 1]; 376 u8 ssid[IW_ESSID_MAX_SIZE + 1];
310 u8 ssid_len; 377 u8 ssid_len;
311 u8 listen_int;
312 int channel; 378 int channel;
313 379
314 struct wl1271_acx_mem_map *target_mem_map; 380 struct wl1271_acx_mem_map *target_mem_map;
@@ -329,13 +395,16 @@ struct wl1271 {
329 395
330 /* Frames scheduled for transmission, not handled yet */ 396 /* Frames scheduled for transmission, not handled yet */
331 struct sk_buff_head tx_queue; 397 struct sk_buff_head tx_queue;
332 bool tx_queue_stopped;
333 398
334 struct work_struct tx_work; 399 struct work_struct tx_work;
335 struct work_struct filter_work;
336 400
337 /* Pending TX frames */ 401 /* Pending TX frames */
338 struct sk_buff *tx_frames[16]; 402 struct sk_buff *tx_frames[ACX_TX_DESCRIPTORS];
403
404 /* Security sequence number counters */
405 u8 tx_security_last_seq;
406 u16 tx_security_seq_16;
407 u32 tx_security_seq_32;
339 408
340 /* FW Rx counter */ 409 /* FW Rx counter */
341 u32 rx_counter; 410 u32 rx_counter;
@@ -353,27 +422,30 @@ struct wl1271 {
353 u32 mbox_ptr[2]; 422 u32 mbox_ptr[2];
354 423
355 /* Are we currently scanning */ 424 /* Are we currently scanning */
356 bool scanning; 425 struct wl1271_scan scan;
357 426
358 /* Our association ID */ 427 /* Our association ID */
359 u16 aid; 428 u16 aid;
360 429
430 /* currently configured rate set */
431 u32 sta_rate_set;
432 u32 basic_rate_set;
433 u32 rate_set;
434
435 /* The current band */
436 enum ieee80211_band band;
437
361 /* Default key (for WEP) */ 438 /* Default key (for WEP) */
362 u32 default_key; 439 u32 default_key;
363 440
364 unsigned int rx_config; 441 unsigned int rx_config;
365 unsigned int rx_filter; 442 unsigned int rx_filter;
366 443
367 /* is firmware in elp mode */
368 bool elp;
369
370 struct completion *elp_compl; 444 struct completion *elp_compl;
445 struct delayed_work elp_work;
371 446
372 /* we can be in psm, but not in elp, we have to differentiate */ 447 /* retry counter for PSM entries */
373 bool psm; 448 u8 psm_entry_retry;
374
375 /* PSM mode requested */
376 bool psm_requested;
377 449
378 /* in dBm */ 450 /* in dBm */
379 int power_level; 451 int power_level;
@@ -383,11 +455,17 @@ struct wl1271 {
383 455
384 u32 buffer_32; 456 u32 buffer_32;
385 u32 buffer_cmd; 457 u32 buffer_cmd;
386 u8 buffer_busyword[WL1271_BUSY_WORD_LEN]; 458 u32 buffer_busyword[WL1271_BUSY_WORD_CNT];
387 struct wl1271_rx_descriptor *rx_descriptor;
388 459
389 struct wl1271_fw_status *fw_status; 460 struct wl1271_fw_status *fw_status;
390 struct wl1271_tx_hw_res_if *tx_res_if; 461 struct wl1271_tx_hw_res_if *tx_res_if;
462
463 struct ieee80211_vif *vif;
464
465 /* Current chipset configuration */
466 struct conf_drv_settings conf;
467
468 struct list_head list;
391}; 469};
392 470
393int wl1271_plt_start(struct wl1271 *wl); 471int wl1271_plt_start(struct wl1271 *wl);
@@ -401,7 +479,19 @@ int wl1271_plt_stop(struct wl1271 *wl);
401 479
402#define WL1271_TX_QUEUE_MAX_LENGTH 20 480#define WL1271_TX_QUEUE_MAX_LENGTH 20
403 481
404/* WL1271 needs a 200ms sleep after power on */ 482/* WL1271 needs a 200ms sleep after power on, and a 20ms sleep before power
483 on in case is has been shut down shortly before */
484#define WL1271_PRE_POWER_ON_SLEEP 20 /* in miliseconds */
405#define WL1271_POWER_ON_SLEEP 200 /* in miliseconds */ 485#define WL1271_POWER_ON_SLEEP 200 /* in miliseconds */
406 486
487static inline bool wl1271_11a_enabled(void)
488{
489 /* FIXME: this could be determined based on the NVS-INI file */
490#ifdef WL1271_80211A_ENABLED
491 return true;
492#else
493 return false;
494#endif
495}
496
407#endif 497#endif
diff --git a/drivers/net/wireless/wl12xx/wl1271_acx.c b/drivers/net/wireless/wl12xx/wl1271_acx.c
index f622a4092615..308782421fce 100644
--- a/drivers/net/wireless/wl12xx/wl1271_acx.c
+++ b/drivers/net/wireless/wl12xx/wl1271_acx.c
@@ -27,6 +27,7 @@
27#include <linux/platform_device.h> 27#include <linux/platform_device.h>
28#include <linux/crc7.h> 28#include <linux/crc7.h>
29#include <linux/spi/spi.h> 29#include <linux/spi/spi.h>
30#include <linux/slab.h>
30 31
31#include "wl1271.h" 32#include "wl1271.h"
32#include "wl12xx_80211.h" 33#include "wl12xx_80211.h"
@@ -34,8 +35,7 @@
34#include "wl1271_spi.h" 35#include "wl1271_spi.h"
35#include "wl1271_ps.h" 36#include "wl1271_ps.h"
36 37
37int wl1271_acx_wake_up_conditions(struct wl1271 *wl, u8 wake_up_event, 38int wl1271_acx_wake_up_conditions(struct wl1271 *wl)
38 u8 listen_interval)
39{ 39{
40 struct acx_wake_up_condition *wake_up; 40 struct acx_wake_up_condition *wake_up;
41 int ret; 41 int ret;
@@ -48,8 +48,8 @@ int wl1271_acx_wake_up_conditions(struct wl1271 *wl, u8 wake_up_event,
48 goto out; 48 goto out;
49 } 49 }
50 50
51 wake_up->wake_up_event = wake_up_event; 51 wake_up->wake_up_event = wl->conf.conn.wake_up_event;
52 wake_up->listen_interval = listen_interval; 52 wake_up->listen_interval = wl->conf.conn.listen_interval;
53 53
54 ret = wl1271_cmd_configure(wl, ACX_WAKE_UP_CONDITIONS, 54 ret = wl1271_cmd_configure(wl, ACX_WAKE_UP_CONDITIONS,
55 wake_up, sizeof(*wake_up)); 55 wake_up, sizeof(*wake_up));
@@ -137,7 +137,12 @@ int wl1271_acx_tx_power(struct wl1271 *wl, int power)
137 goto out; 137 goto out;
138 } 138 }
139 139
140 acx->current_tx_power = power * 10; 140 /*
141 * FIXME: This is a workaround needed while we don't the correct
142 * calibration, to avoid distortions
143 */
144 /* acx->current_tx_power = power * 10; */
145 acx->current_tx_power = 120;
141 146
142 ret = wl1271_cmd_configure(wl, DOT11_CUR_TX_PWR, acx, sizeof(*acx)); 147 ret = wl1271_cmd_configure(wl, DOT11_CUR_TX_PWR, acx, sizeof(*acx));
143 if (ret < 0) { 148 if (ret < 0) {
@@ -193,7 +198,7 @@ int wl1271_acx_mem_map(struct wl1271 *wl, struct acx_header *mem_map,
193 return 0; 198 return 0;
194} 199}
195 200
196int wl1271_acx_rx_msdu_life_time(struct wl1271 *wl, u32 life_time) 201int wl1271_acx_rx_msdu_life_time(struct wl1271 *wl)
197{ 202{
198 struct acx_rx_msdu_lifetime *acx; 203 struct acx_rx_msdu_lifetime *acx;
199 int ret; 204 int ret;
@@ -206,7 +211,7 @@ int wl1271_acx_rx_msdu_life_time(struct wl1271 *wl, u32 life_time)
206 goto out; 211 goto out;
207 } 212 }
208 213
209 acx->lifetime = life_time; 214 acx->lifetime = cpu_to_le32(wl->conf.rx.rx_msdu_life_time);
210 ret = wl1271_cmd_configure(wl, DOT11_RX_MSDU_LIFE_TIME, 215 ret = wl1271_cmd_configure(wl, DOT11_RX_MSDU_LIFE_TIME,
211 acx, sizeof(*acx)); 216 acx, sizeof(*acx));
212 if (ret < 0) { 217 if (ret < 0) {
@@ -232,8 +237,8 @@ int wl1271_acx_rx_config(struct wl1271 *wl, u32 config, u32 filter)
232 goto out; 237 goto out;
233 } 238 }
234 239
235 rx_config->config_options = config; 240 rx_config->config_options = cpu_to_le32(config);
236 rx_config->filter_options = filter; 241 rx_config->filter_options = cpu_to_le32(filter);
237 242
238 ret = wl1271_cmd_configure(wl, ACX_RX_CFG, 243 ret = wl1271_cmd_configure(wl, ACX_RX_CFG,
239 rx_config, sizeof(*rx_config)); 244 rx_config, sizeof(*rx_config));
@@ -260,7 +265,7 @@ int wl1271_acx_pd_threshold(struct wl1271 *wl)
260 goto out; 265 goto out;
261 } 266 }
262 267
263 /* FIXME: threshold value not set */ 268 pd->threshold = cpu_to_le32(wl->conf.rx.packet_detection_threshold);
264 269
265 ret = wl1271_cmd_configure(wl, ACX_PD_THRESHOLD, pd, sizeof(*pd)); 270 ret = wl1271_cmd_configure(wl, ACX_PD_THRESHOLD, pd, sizeof(*pd));
266 if (ret < 0) { 271 if (ret < 0) {
@@ -300,7 +305,8 @@ out:
300 return ret; 305 return ret;
301} 306}
302 307
303int wl1271_acx_group_address_tbl(struct wl1271 *wl) 308int wl1271_acx_group_address_tbl(struct wl1271 *wl, bool enable,
309 void *mc_list, u32 mc_list_len)
304{ 310{
305 struct acx_dot11_grp_addr_tbl *acx; 311 struct acx_dot11_grp_addr_tbl *acx;
306 int ret; 312 int ret;
@@ -314,9 +320,9 @@ int wl1271_acx_group_address_tbl(struct wl1271 *wl)
314 } 320 }
315 321
316 /* MAC filtering */ 322 /* MAC filtering */
317 acx->enabled = 0; 323 acx->enabled = enable;
318 acx->num_groups = 0; 324 acx->num_groups = mc_list_len;
319 memset(acx->mac_table, 0, ADDRESS_GROUP_MAX_LEN); 325 memcpy(acx->mac_table, mc_list, mc_list_len * ETH_ALEN);
320 326
321 ret = wl1271_cmd_configure(wl, DOT11_GROUP_ADDRESS_TBL, 327 ret = wl1271_cmd_configure(wl, DOT11_GROUP_ADDRESS_TBL,
322 acx, sizeof(*acx)); 328 acx, sizeof(*acx));
@@ -343,8 +349,8 @@ int wl1271_acx_service_period_timeout(struct wl1271 *wl)
343 349
344 wl1271_debug(DEBUG_ACX, "acx service period timeout"); 350 wl1271_debug(DEBUG_ACX, "acx service period timeout");
345 351
346 rx_timeout->ps_poll_timeout = RX_TIMEOUT_PS_POLL_DEF; 352 rx_timeout->ps_poll_timeout = cpu_to_le16(wl->conf.rx.ps_poll_timeout);
347 rx_timeout->upsd_timeout = RX_TIMEOUT_UPSD_DEF; 353 rx_timeout->upsd_timeout = cpu_to_le16(wl->conf.rx.upsd_timeout);
348 354
349 ret = wl1271_cmd_configure(wl, ACX_SERVICE_PERIOD_TIMEOUT, 355 ret = wl1271_cmd_configure(wl, ACX_SERVICE_PERIOD_TIMEOUT,
350 rx_timeout, sizeof(*rx_timeout)); 356 rx_timeout, sizeof(*rx_timeout));
@@ -372,7 +378,7 @@ int wl1271_acx_rts_threshold(struct wl1271 *wl, u16 rts_threshold)
372 goto out; 378 goto out;
373 } 379 }
374 380
375 rts->threshold = rts_threshold; 381 rts->threshold = cpu_to_le16(rts_threshold);
376 382
377 ret = wl1271_cmd_configure(wl, DOT11_RTS_THRESHOLD, rts, sizeof(*rts)); 383 ret = wl1271_cmd_configure(wl, DOT11_RTS_THRESHOLD, rts, sizeof(*rts));
378 if (ret < 0) { 384 if (ret < 0) {
@@ -385,20 +391,58 @@ out:
385 return ret; 391 return ret;
386} 392}
387 393
388int wl1271_acx_beacon_filter_opt(struct wl1271 *wl) 394int wl1271_acx_dco_itrim_params(struct wl1271 *wl)
389{ 395{
390 struct acx_beacon_filter_option *beacon_filter; 396 struct acx_dco_itrim_params *dco;
397 struct conf_itrim_settings *c = &wl->conf.itrim;
391 int ret; 398 int ret;
392 399
400 wl1271_debug(DEBUG_ACX, "acx dco itrim parameters");
401
402 dco = kzalloc(sizeof(*dco), GFP_KERNEL);
403 if (!dco) {
404 ret = -ENOMEM;
405 goto out;
406 }
407
408 dco->enable = c->enable;
409 dco->timeout = cpu_to_le32(c->timeout);
410
411 ret = wl1271_cmd_configure(wl, ACX_SET_DCO_ITRIM_PARAMS,
412 dco, sizeof(*dco));
413 if (ret < 0) {
414 wl1271_warning("failed to set dco itrim parameters: %d", ret);
415 goto out;
416 }
417
418out:
419 kfree(dco);
420 return ret;
421}
422
423int wl1271_acx_beacon_filter_opt(struct wl1271 *wl, bool enable_filter)
424{
425 struct acx_beacon_filter_option *beacon_filter = NULL;
426 int ret = 0;
427
393 wl1271_debug(DEBUG_ACX, "acx beacon filter opt"); 428 wl1271_debug(DEBUG_ACX, "acx beacon filter opt");
394 429
430 if (enable_filter &&
431 wl->conf.conn.bcn_filt_mode == CONF_BCN_FILT_MODE_DISABLED)
432 goto out;
433
395 beacon_filter = kzalloc(sizeof(*beacon_filter), GFP_KERNEL); 434 beacon_filter = kzalloc(sizeof(*beacon_filter), GFP_KERNEL);
396 if (!beacon_filter) { 435 if (!beacon_filter) {
397 ret = -ENOMEM; 436 ret = -ENOMEM;
398 goto out; 437 goto out;
399 } 438 }
400 439
401 beacon_filter->enable = 0; 440 beacon_filter->enable = enable_filter;
441
442 /*
443 * When set to zero, and the filter is enabled, beacons
444 * without the unicast TIM bit set are dropped.
445 */
402 beacon_filter->max_num_beacons = 0; 446 beacon_filter->max_num_beacons = 0;
403 447
404 ret = wl1271_cmd_configure(wl, ACX_BEACON_FILTER_OPT, 448 ret = wl1271_cmd_configure(wl, ACX_BEACON_FILTER_OPT,
@@ -416,7 +460,9 @@ out:
416int wl1271_acx_beacon_filter_table(struct wl1271 *wl) 460int wl1271_acx_beacon_filter_table(struct wl1271 *wl)
417{ 461{
418 struct acx_beacon_filter_ie_table *ie_table; 462 struct acx_beacon_filter_ie_table *ie_table;
463 int i, idx = 0;
419 int ret; 464 int ret;
465 bool vendor_spec = false;
420 466
421 wl1271_debug(DEBUG_ACX, "acx beacon filter table"); 467 wl1271_debug(DEBUG_ACX, "acx beacon filter table");
422 468
@@ -426,8 +472,32 @@ int wl1271_acx_beacon_filter_table(struct wl1271 *wl)
426 goto out; 472 goto out;
427 } 473 }
428 474
475 /* configure default beacon pass-through rules */
429 ie_table->num_ie = 0; 476 ie_table->num_ie = 0;
430 memset(ie_table->table, 0, BEACON_FILTER_TABLE_MAX_SIZE); 477 for (i = 0; i < wl->conf.conn.bcn_filt_ie_count; i++) {
478 struct conf_bcn_filt_rule *r = &(wl->conf.conn.bcn_filt_ie[i]);
479 ie_table->table[idx++] = r->ie;
480 ie_table->table[idx++] = r->rule;
481
482 if (r->ie == WLAN_EID_VENDOR_SPECIFIC) {
483 /* only one vendor specific ie allowed */
484 if (vendor_spec)
485 continue;
486
487 /* for vendor specific rules configure the
488 additional fields */
489 memcpy(&(ie_table->table[idx]), r->oui,
490 CONF_BCN_IE_OUI_LEN);
491 idx += CONF_BCN_IE_OUI_LEN;
492 ie_table->table[idx++] = r->type;
493 memcpy(&(ie_table->table[idx]), r->version,
494 CONF_BCN_IE_VER_LEN);
495 idx += CONF_BCN_IE_VER_LEN;
496 vendor_spec = true;
497 }
498
499 ie_table->num_ie++;
500 }
431 501
432 ret = wl1271_cmd_configure(wl, ACX_BEACON_FILTER_TABLE, 502 ret = wl1271_cmd_configure(wl, ACX_BEACON_FILTER_TABLE,
433 ie_table, sizeof(*ie_table)); 503 ie_table, sizeof(*ie_table));
@@ -441,6 +511,36 @@ out:
441 return ret; 511 return ret;
442} 512}
443 513
514int wl1271_acx_conn_monit_params(struct wl1271 *wl)
515{
516 struct acx_conn_monit_params *acx;
517 int ret;
518
519 wl1271_debug(DEBUG_ACX, "acx connection monitor parameters");
520
521 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
522 if (!acx) {
523 ret = -ENOMEM;
524 goto out;
525 }
526
527 acx->synch_fail_thold = cpu_to_le32(wl->conf.conn.synch_fail_thold);
528 acx->bss_lose_timeout = cpu_to_le32(wl->conf.conn.bss_lose_timeout);
529
530 ret = wl1271_cmd_configure(wl, ACX_CONN_MONIT_PARAMS,
531 acx, sizeof(*acx));
532 if (ret < 0) {
533 wl1271_warning("failed to set connection monitor "
534 "parameters: %d", ret);
535 goto out;
536 }
537
538out:
539 kfree(acx);
540 return ret;
541}
542
543
444int wl1271_acx_sg_enable(struct wl1271 *wl) 544int wl1271_acx_sg_enable(struct wl1271 *wl)
445{ 545{
446 struct acx_bt_wlan_coex *pta; 546 struct acx_bt_wlan_coex *pta;
@@ -470,6 +570,7 @@ out:
470int wl1271_acx_sg_cfg(struct wl1271 *wl) 570int wl1271_acx_sg_cfg(struct wl1271 *wl)
471{ 571{
472 struct acx_bt_wlan_coex_param *param; 572 struct acx_bt_wlan_coex_param *param;
573 struct conf_sg_settings *c = &wl->conf.sg;
473 int ret; 574 int ret;
474 575
475 wl1271_debug(DEBUG_ACX, "acx sg cfg"); 576 wl1271_debug(DEBUG_ACX, "acx sg cfg");
@@ -481,34 +582,19 @@ int wl1271_acx_sg_cfg(struct wl1271 *wl)
481 } 582 }
482 583
483 /* BT-WLAN coext parameters */ 584 /* BT-WLAN coext parameters */
484 param->min_rate = RATE_INDEX_24MBPS; 585 param->per_threshold = cpu_to_le32(c->per_threshold);
485 param->bt_hp_max_time = PTA_BT_HP_MAXTIME_DEF; 586 param->max_scan_compensation_time =
486 param->wlan_hp_max_time = PTA_WLAN_HP_MAX_TIME_DEF; 587 cpu_to_le32(c->max_scan_compensation_time);
487 param->sense_disable_timer = PTA_SENSE_DISABLE_TIMER_DEF; 588 param->nfs_sample_interval = cpu_to_le16(c->nfs_sample_interval);
488 param->rx_time_bt_hp = PTA_PROTECTIVE_RX_TIME_DEF; 589 param->load_ratio = c->load_ratio;
489 param->tx_time_bt_hp = PTA_PROTECTIVE_TX_TIME_DEF; 590 param->auto_ps_mode = c->auto_ps_mode;
490 param->rx_time_bt_hp_fast = PTA_PROTECTIVE_RX_TIME_FAST_DEF; 591 param->probe_req_compensation = c->probe_req_compensation;
491 param->tx_time_bt_hp_fast = PTA_PROTECTIVE_TX_TIME_FAST_DEF; 592 param->scan_window_compensation = c->scan_window_compensation;
492 param->wlan_cycle_fast = PTA_CYCLE_TIME_FAST_DEF; 593 param->antenna_config = c->antenna_config;
493 param->bt_anti_starvation_period = PTA_ANTI_STARVE_PERIOD_DEF; 594 param->beacon_miss_threshold = c->beacon_miss_threshold;
494 param->next_bt_lp_packet = PTA_TIMEOUT_NEXT_BT_LP_PACKET_DEF; 595 param->rate_adaptation_threshold =
495 param->wake_up_beacon = PTA_TIME_BEFORE_BEACON_DEF; 596 cpu_to_le32(c->rate_adaptation_threshold);
496 param->hp_dm_max_guard_time = PTA_HPDM_MAX_TIME_DEF; 597 param->rate_adaptation_snr = c->rate_adaptation_snr;
497 param->next_wlan_packet = PTA_TIME_OUT_NEXT_WLAN_DEF;
498 param->antenna_type = PTA_ANTENNA_TYPE_DEF;
499 param->signal_type = PTA_SIGNALING_TYPE_DEF;
500 param->afh_leverage_on = PTA_AFH_LEVERAGE_ON_DEF;
501 param->quiet_cycle_num = PTA_NUMBER_QUIET_CYCLE_DEF;
502 param->max_cts = PTA_MAX_NUM_CTS_DEF;
503 param->wlan_packets_num = PTA_NUMBER_OF_WLAN_PACKETS_DEF;
504 param->bt_packets_num = PTA_NUMBER_OF_BT_PACKETS_DEF;
505 param->missed_rx_avalanche = PTA_RX_FOR_AVALANCHE_DEF;
506 param->wlan_elp_hp = PTA_ELP_HP_DEF;
507 param->bt_anti_starvation_cycles = PTA_ANTI_STARVE_NUM_CYCLE_DEF;
508 param->ack_mode_dual_ant = PTA_ACK_MODE_DEF;
509 param->pa_sd_enable = PTA_ALLOW_PA_SD_DEF;
510 param->pta_auto_mode_enable = PTA_AUTO_MODE_NO_CTS_DEF;
511 param->bt_hp_respected_num = PTA_BT_HP_RESPECTED_DEF;
512 598
513 ret = wl1271_cmd_configure(wl, ACX_SG_CFG, param, sizeof(*param)); 599 ret = wl1271_cmd_configure(wl, ACX_SG_CFG, param, sizeof(*param));
514 if (ret < 0) { 600 if (ret < 0) {
@@ -534,8 +620,8 @@ int wl1271_acx_cca_threshold(struct wl1271 *wl)
534 goto out; 620 goto out;
535 } 621 }
536 622
537 detection->rx_cca_threshold = CCA_THRSH_DISABLE_ENERGY_D; 623 detection->rx_cca_threshold = cpu_to_le16(wl->conf.rx.rx_cca_threshold);
538 detection->tx_energy_detection = 0; 624 detection->tx_energy_detection = wl->conf.tx.tx_energy_detection;
539 625
540 ret = wl1271_cmd_configure(wl, ACX_CCA_THRESHOLD, 626 ret = wl1271_cmd_configure(wl, ACX_CCA_THRESHOLD,
541 detection, sizeof(*detection)); 627 detection, sizeof(*detection));
@@ -562,10 +648,10 @@ int wl1271_acx_bcn_dtim_options(struct wl1271 *wl)
562 goto out; 648 goto out;
563 } 649 }
564 650
565 bb->beacon_rx_timeout = BCN_RX_TIMEOUT_DEF_VALUE; 651 bb->beacon_rx_timeout = cpu_to_le16(wl->conf.conn.beacon_rx_timeout);
566 bb->broadcast_timeout = BROADCAST_RX_TIMEOUT_DEF_VALUE; 652 bb->broadcast_timeout = cpu_to_le16(wl->conf.conn.broadcast_timeout);
567 bb->rx_broadcast_in_ps = RX_BROADCAST_IN_PS_DEF_VALUE; 653 bb->rx_broadcast_in_ps = wl->conf.conn.rx_broadcast_in_ps;
568 bb->ps_poll_threshold = CONSECUTIVE_PS_POLL_FAILURE_DEF; 654 bb->ps_poll_threshold = wl->conf.conn.ps_poll_threshold;
569 655
570 ret = wl1271_cmd_configure(wl, ACX_BCN_DTIM_OPTIONS, bb, sizeof(*bb)); 656 ret = wl1271_cmd_configure(wl, ACX_BCN_DTIM_OPTIONS, bb, sizeof(*bb));
571 if (ret < 0) { 657 if (ret < 0) {
@@ -591,7 +677,7 @@ int wl1271_acx_aid(struct wl1271 *wl, u16 aid)
591 goto out; 677 goto out;
592 } 678 }
593 679
594 acx_aid->aid = aid; 680 acx_aid->aid = cpu_to_le16(aid);
595 681
596 ret = wl1271_cmd_configure(wl, ACX_AID, acx_aid, sizeof(*acx_aid)); 682 ret = wl1271_cmd_configure(wl, ACX_AID, acx_aid, sizeof(*acx_aid));
597 if (ret < 0) { 683 if (ret < 0) {
@@ -618,9 +704,8 @@ int wl1271_acx_event_mbox_mask(struct wl1271 *wl, u32 event_mask)
618 } 704 }
619 705
620 /* high event mask is unused */ 706 /* high event mask is unused */
621 mask->high_event_mask = 0xffffffff; 707 mask->high_event_mask = cpu_to_le32(0xffffffff);
622 708 mask->event_mask = cpu_to_le32(event_mask);
623 mask->event_mask = event_mask;
624 709
625 ret = wl1271_cmd_configure(wl, ACX_EVENT_MBOX_MASK, 710 ret = wl1271_cmd_configure(wl, ACX_EVENT_MBOX_MASK,
626 mask, sizeof(*mask)); 711 mask, sizeof(*mask));
@@ -706,6 +791,8 @@ int wl1271_acx_statistics(struct wl1271 *wl, struct acx_statistics *stats)
706int wl1271_acx_rate_policies(struct wl1271 *wl) 791int wl1271_acx_rate_policies(struct wl1271 *wl)
707{ 792{
708 struct acx_rate_policy *acx; 793 struct acx_rate_policy *acx;
794 struct conf_tx_rate_class *c = &wl->conf.tx.rc_conf;
795 int idx = 0;
709 int ret = 0; 796 int ret = 0;
710 797
711 wl1271_debug(DEBUG_ACX, "acx rate policies"); 798 wl1271_debug(DEBUG_ACX, "acx rate policies");
@@ -717,12 +804,21 @@ int wl1271_acx_rate_policies(struct wl1271 *wl)
717 goto out; 804 goto out;
718 } 805 }
719 806
720 /* configure one default (one-size-fits-all) rate class */ 807 /* configure one basic rate class */
721 acx->rate_class_cnt = 1; 808 idx = ACX_TX_BASIC_RATE;
722 acx->rate_class[0].enabled_rates = ACX_RATE_MASK_ALL; 809 acx->rate_class[idx].enabled_rates = cpu_to_le32(wl->basic_rate_set);
723 acx->rate_class[0].short_retry_limit = ACX_RATE_RETRY_LIMIT; 810 acx->rate_class[idx].short_retry_limit = c->short_retry_limit;
724 acx->rate_class[0].long_retry_limit = ACX_RATE_RETRY_LIMIT; 811 acx->rate_class[idx].long_retry_limit = c->long_retry_limit;
725 acx->rate_class[0].aflags = 0; 812 acx->rate_class[idx].aflags = c->aflags;
813
814 /* configure one AP supported rate class */
815 idx = ACX_TX_AP_FULL_RATE;
816 acx->rate_class[idx].enabled_rates = cpu_to_le32(wl->rate_set);
817 acx->rate_class[idx].short_retry_limit = c->short_retry_limit;
818 acx->rate_class[idx].long_retry_limit = c->long_retry_limit;
819 acx->rate_class[idx].aflags = c->aflags;
820
821 acx->rate_class_cnt = cpu_to_le32(ACX_TX_RATE_POLICY_CNT);
726 822
727 ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx)); 823 ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
728 if (ret < 0) { 824 if (ret < 0) {
@@ -735,12 +831,14 @@ out:
735 return ret; 831 return ret;
736} 832}
737 833
738int wl1271_acx_ac_cfg(struct wl1271 *wl) 834int wl1271_acx_ac_cfg(struct wl1271 *wl, u8 ac, u8 cw_min, u16 cw_max,
835 u8 aifsn, u16 txop)
739{ 836{
740 struct acx_ac_cfg *acx; 837 struct acx_ac_cfg *acx;
741 int i, ret = 0; 838 int ret = 0;
742 839
743 wl1271_debug(DEBUG_ACX, "acx access category config"); 840 wl1271_debug(DEBUG_ACX, "acx ac cfg %d cw_ming %d cw_max %d "
841 "aifs %d txop %d", ac, cw_min, cw_max, aifsn, txop);
744 842
745 acx = kzalloc(sizeof(*acx), GFP_KERNEL); 843 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
746 844
@@ -749,29 +847,16 @@ int wl1271_acx_ac_cfg(struct wl1271 *wl)
749 goto out; 847 goto out;
750 } 848 }
751 849
752 /* 850 acx->ac = ac;
753 * FIXME: Configure each AC with appropriate values (most suitable 851 acx->cw_min = cw_min;
754 * values will probably be different for each AC. 852 acx->cw_max = cpu_to_le16(cw_max);
755 */ 853 acx->aifsn = aifsn;
756 for (i = 0; i < WL1271_ACX_AC_COUNT; i++) { 854 acx->tx_op_limit = cpu_to_le16(txop);
757 acx->ac = i; 855
758 856 ret = wl1271_cmd_configure(wl, ACX_AC_CFG, acx, sizeof(*acx));
759 /* 857 if (ret < 0) {
760 * FIXME: The following default values originate from 858 wl1271_warning("acx ac cfg failed: %d", ret);
761 * the TI reference driver. What do they mean? 859 goto out;
762 */
763 acx->cw_min = 15;
764 acx->cw_max = 63;
765 acx->aifsn = 3;
766 acx->reserved = 0;
767 acx->tx_op_limit = 0;
768
769 ret = wl1271_cmd_configure(wl, ACX_AC_CFG, acx, sizeof(*acx));
770 if (ret < 0) {
771 wl1271_warning("Setting of access category "
772 "config: %d", ret);
773 goto out;
774 }
775 } 860 }
776 861
777out: 862out:
@@ -779,10 +864,12 @@ out:
779 return ret; 864 return ret;
780} 865}
781 866
782int wl1271_acx_tid_cfg(struct wl1271 *wl) 867int wl1271_acx_tid_cfg(struct wl1271 *wl, u8 queue_id, u8 channel_type,
868 u8 tsid, u8 ps_scheme, u8 ack_policy,
869 u32 apsd_conf0, u32 apsd_conf1)
783{ 870{
784 struct acx_tid_config *acx; 871 struct acx_tid_config *acx;
785 int i, ret = 0; 872 int ret = 0;
786 873
787 wl1271_debug(DEBUG_ACX, "acx tid config"); 874 wl1271_debug(DEBUG_ACX, "acx tid config");
788 875
@@ -793,18 +880,18 @@ int wl1271_acx_tid_cfg(struct wl1271 *wl)
793 goto out; 880 goto out;
794 } 881 }
795 882
796 /* FIXME: configure each TID with a different AC reference */ 883 acx->queue_id = queue_id;
797 for (i = 0; i < WL1271_ACX_TID_COUNT; i++) { 884 acx->channel_type = channel_type;
798 acx->queue_id = i; 885 acx->tsid = tsid;
799 acx->tsid = WL1271_ACX_AC_BE; 886 acx->ps_scheme = ps_scheme;
800 acx->ps_scheme = WL1271_ACX_PS_SCHEME_LEGACY; 887 acx->ack_policy = ack_policy;
801 acx->ack_policy = WL1271_ACX_ACK_POLICY_LEGACY; 888 acx->apsd_conf[0] = cpu_to_le32(apsd_conf0);
889 acx->apsd_conf[1] = cpu_to_le32(apsd_conf1);
802 890
803 ret = wl1271_cmd_configure(wl, ACX_TID_CFG, acx, sizeof(*acx)); 891 ret = wl1271_cmd_configure(wl, ACX_TID_CFG, acx, sizeof(*acx));
804 if (ret < 0) { 892 if (ret < 0) {
805 wl1271_warning("Setting of tid config failed: %d", ret); 893 wl1271_warning("Setting of tid config failed: %d", ret);
806 goto out; 894 goto out;
807 }
808 } 895 }
809 896
810out: 897out:
@@ -826,7 +913,7 @@ int wl1271_acx_frag_threshold(struct wl1271 *wl)
826 goto out; 913 goto out;
827 } 914 }
828 915
829 acx->frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD; 916 acx->frag_threshold = cpu_to_le16(wl->conf.tx.frag_threshold);
830 ret = wl1271_cmd_configure(wl, ACX_FRAG_CFG, acx, sizeof(*acx)); 917 ret = wl1271_cmd_configure(wl, ACX_FRAG_CFG, acx, sizeof(*acx));
831 if (ret < 0) { 918 if (ret < 0) {
832 wl1271_warning("Setting of frag threshold failed: %d", ret); 919 wl1271_warning("Setting of frag threshold failed: %d", ret);
@@ -852,8 +939,8 @@ int wl1271_acx_tx_config_options(struct wl1271 *wl)
852 goto out; 939 goto out;
853 } 940 }
854 941
855 acx->tx_compl_timeout = WL1271_ACX_TX_COMPL_TIMEOUT; 942 acx->tx_compl_timeout = cpu_to_le16(wl->conf.tx.tx_compl_timeout);
856 acx->tx_compl_threshold = WL1271_ACX_TX_COMPL_THRESHOLD; 943 acx->tx_compl_threshold = cpu_to_le16(wl->conf.tx.tx_compl_threshold);
857 ret = wl1271_cmd_configure(wl, ACX_TX_CONFIG_OPT, acx, sizeof(*acx)); 944 ret = wl1271_cmd_configure(wl, ACX_TX_CONFIG_OPT, acx, sizeof(*acx));
858 if (ret < 0) { 945 if (ret < 0) {
859 wl1271_warning("Setting of tx options failed: %d", ret); 946 wl1271_warning("Setting of tx options failed: %d", ret);
@@ -879,11 +966,11 @@ int wl1271_acx_mem_cfg(struct wl1271 *wl)
879 } 966 }
880 967
881 /* memory config */ 968 /* memory config */
882 mem_conf->num_stations = cpu_to_le16(DEFAULT_NUM_STATIONS); 969 mem_conf->num_stations = DEFAULT_NUM_STATIONS;
883 mem_conf->rx_mem_block_num = ACX_RX_MEM_BLOCKS; 970 mem_conf->rx_mem_block_num = ACX_RX_MEM_BLOCKS;
884 mem_conf->tx_min_mem_block_num = ACX_TX_MIN_MEM_BLOCKS; 971 mem_conf->tx_min_mem_block_num = ACX_TX_MIN_MEM_BLOCKS;
885 mem_conf->num_ssid_profiles = ACX_NUM_SSID_PROFILES; 972 mem_conf->num_ssid_profiles = ACX_NUM_SSID_PROFILES;
886 mem_conf->total_tx_descriptors = ACX_TX_DESCRIPTORS; 973 mem_conf->total_tx_descriptors = cpu_to_le32(ACX_TX_DESCRIPTORS);
887 974
888 ret = wl1271_cmd_configure(wl, ACX_MEM_CFG, mem_conf, 975 ret = wl1271_cmd_configure(wl, ACX_MEM_CFG, mem_conf,
889 sizeof(*mem_conf)); 976 sizeof(*mem_conf));
@@ -906,7 +993,7 @@ int wl1271_acx_init_mem_config(struct wl1271 *wl)
906 return ret; 993 return ret;
907 994
908 wl->target_mem_map = kzalloc(sizeof(struct wl1271_acx_mem_map), 995 wl->target_mem_map = kzalloc(sizeof(struct wl1271_acx_mem_map),
909 GFP_KERNEL); 996 GFP_KERNEL);
910 if (!wl->target_mem_map) { 997 if (!wl->target_mem_map) {
911 wl1271_error("couldn't allocate target memory map"); 998 wl1271_error("couldn't allocate target memory map");
912 return -ENOMEM; 999 return -ENOMEM;
@@ -923,7 +1010,8 @@ int wl1271_acx_init_mem_config(struct wl1271 *wl)
923 } 1010 }
924 1011
925 /* initialize TX block book keeping */ 1012 /* initialize TX block book keeping */
926 wl->tx_blocks_available = wl->target_mem_map->num_tx_mem_blocks; 1013 wl->tx_blocks_available =
1014 le32_to_cpu(wl->target_mem_map->num_tx_mem_blocks);
927 wl1271_debug(DEBUG_TX, "available tx blocks: %d", 1015 wl1271_debug(DEBUG_TX, "available tx blocks: %d",
928 wl->tx_blocks_available); 1016 wl->tx_blocks_available);
929 1017
@@ -943,10 +1031,10 @@ int wl1271_acx_init_rx_interrupt(struct wl1271 *wl)
943 goto out; 1031 goto out;
944 } 1032 }
945 1033
946 rx_conf->threshold = WL1271_RX_INTR_THRESHOLD_DEF; 1034 rx_conf->threshold = cpu_to_le16(wl->conf.rx.irq_pkt_threshold);
947 rx_conf->timeout = WL1271_RX_INTR_TIMEOUT_DEF; 1035 rx_conf->timeout = cpu_to_le16(wl->conf.rx.irq_timeout);
948 rx_conf->mblk_threshold = USHORT_MAX; /* Disabled */ 1036 rx_conf->mblk_threshold = cpu_to_le16(wl->conf.rx.irq_blk_threshold);
949 rx_conf->queue_type = RX_QUEUE_TYPE_RX_LOW_PRIORITY; 1037 rx_conf->queue_type = wl->conf.rx.queue_type;
950 1038
951 ret = wl1271_cmd_configure(wl, ACX_RX_CONFIG_OPT, rx_conf, 1039 ret = wl1271_cmd_configure(wl, ACX_RX_CONFIG_OPT, rx_conf,
952 sizeof(*rx_conf)); 1040 sizeof(*rx_conf));
@@ -959,3 +1047,99 @@ out:
959 kfree(rx_conf); 1047 kfree(rx_conf);
960 return ret; 1048 return ret;
961} 1049}
1050
1051int wl1271_acx_bet_enable(struct wl1271 *wl, bool enable)
1052{
1053 struct wl1271_acx_bet_enable *acx = NULL;
1054 int ret = 0;
1055
1056 wl1271_debug(DEBUG_ACX, "acx bet enable");
1057
1058 if (enable && wl->conf.conn.bet_enable == CONF_BET_MODE_DISABLE)
1059 goto out;
1060
1061 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1062 if (!acx) {
1063 ret = -ENOMEM;
1064 goto out;
1065 }
1066
1067 acx->enable = enable ? CONF_BET_MODE_ENABLE : CONF_BET_MODE_DISABLE;
1068 acx->max_consecutive = wl->conf.conn.bet_max_consecutive;
1069
1070 ret = wl1271_cmd_configure(wl, ACX_BET_ENABLE, acx, sizeof(*acx));
1071 if (ret < 0) {
1072 wl1271_warning("acx bet enable failed: %d", ret);
1073 goto out;
1074 }
1075
1076out:
1077 kfree(acx);
1078 return ret;
1079}
1080
1081int wl1271_acx_arp_ip_filter(struct wl1271 *wl, bool enable, u8 *address,
1082 u8 version)
1083{
1084 struct wl1271_acx_arp_filter *acx;
1085 int ret;
1086
1087 wl1271_debug(DEBUG_ACX, "acx arp ip filter, enable: %d", enable);
1088
1089 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1090 if (!acx) {
1091 ret = -ENOMEM;
1092 goto out;
1093 }
1094
1095 acx->version = version;
1096 acx->enable = enable;
1097
1098 if (enable == true) {
1099 if (version == ACX_IPV4_VERSION)
1100 memcpy(acx->address, address, ACX_IPV4_ADDR_SIZE);
1101 else if (version == ACX_IPV6_VERSION)
1102 memcpy(acx->address, address, sizeof(acx->address));
1103 else
1104 wl1271_error("Invalid IP version");
1105 }
1106
1107 ret = wl1271_cmd_configure(wl, ACX_ARP_IP_FILTER,
1108 acx, sizeof(*acx));
1109 if (ret < 0) {
1110 wl1271_warning("failed to set arp ip filter: %d", ret);
1111 goto out;
1112 }
1113
1114out:
1115 kfree(acx);
1116 return ret;
1117}
1118
1119int wl1271_acx_pm_config(struct wl1271 *wl)
1120{
1121 struct wl1271_acx_pm_config *acx = NULL;
1122 struct conf_pm_config_settings *c = &wl->conf.pm_config;
1123 int ret = 0;
1124
1125 wl1271_debug(DEBUG_ACX, "acx pm config");
1126
1127 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1128 if (!acx) {
1129 ret = -ENOMEM;
1130 goto out;
1131 }
1132
1133 acx->host_clk_settling_time = cpu_to_le32(c->host_clk_settling_time);
1134 acx->host_fast_wakeup_support = c->host_fast_wakeup_support;
1135
1136 ret = wl1271_cmd_configure(wl, ACX_PM_CONFIG, acx, sizeof(*acx));
1137 if (ret < 0) {
1138 wl1271_warning("acx pm config failed: %d", ret);
1139 goto out;
1140 }
1141
1142out:
1143 kfree(acx);
1144 return ret;
1145}
diff --git a/drivers/net/wireless/wl12xx/wl1271_acx.h b/drivers/net/wireless/wl12xx/wl1271_acx.h
index 9068daaf0ddf..aeccc98581eb 100644
--- a/drivers/net/wireless/wl12xx/wl1271_acx.h
+++ b/drivers/net/wireless/wl12xx/wl1271_acx.h
@@ -2,7 +2,7 @@
2 * This file is part of wl1271 2 * This file is part of wl1271
3 * 3 *
4 * Copyright (C) 1998-2009 Texas Instruments. All rights reserved. 4 * Copyright (C) 1998-2009 Texas Instruments. All rights reserved.
5 * Copyright (C) 2008-2009 Nokia Corporation 5 * Copyright (C) 2008-2010 Nokia Corporation
6 * 6 *
7 * Contact: Luciano Coelho <luciano.coelho@nokia.com> 7 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
8 * 8 *
@@ -61,8 +61,9 @@
61 WL1271_ACX_INTR_HW_AVAILABLE | \ 61 WL1271_ACX_INTR_HW_AVAILABLE | \
62 WL1271_ACX_INTR_DATA) 62 WL1271_ACX_INTR_DATA)
63 63
64#define WL1271_INTR_MASK (WL1271_ACX_INTR_EVENT_A | \ 64#define WL1271_INTR_MASK (WL1271_ACX_INTR_EVENT_A | \
65 WL1271_ACX_INTR_EVENT_B | \ 65 WL1271_ACX_INTR_EVENT_B | \
66 WL1271_ACX_INTR_HW_AVAILABLE | \
66 WL1271_ACX_INTR_DATA) 67 WL1271_ACX_INTR_DATA)
67 68
68/* Target's information element */ 69/* Target's information element */
@@ -70,11 +71,11 @@ struct acx_header {
70 struct wl1271_cmd_header cmd; 71 struct wl1271_cmd_header cmd;
71 72
72 /* acx (or information element) header */ 73 /* acx (or information element) header */
73 u16 id; 74 __le16 id;
74 75
75 /* payload length (not including headers */ 76 /* payload length (not including headers */
76 u16 len; 77 __le16 len;
77}; 78} __attribute__ ((packed));
78 79
79struct acx_error_counter { 80struct acx_error_counter {
80 struct acx_header header; 81 struct acx_header header;
@@ -82,21 +83,21 @@ struct acx_error_counter {
82 /* The number of PLCP errors since the last time this */ 83 /* The number of PLCP errors since the last time this */
83 /* information element was interrogated. This field is */ 84 /* information element was interrogated. This field is */
84 /* automatically cleared when it is interrogated.*/ 85 /* automatically cleared when it is interrogated.*/
85 u32 PLCP_error; 86 __le32 PLCP_error;
86 87
87 /* The number of FCS errors since the last time this */ 88 /* The number of FCS errors since the last time this */
88 /* information element was interrogated. This field is */ 89 /* information element was interrogated. This field is */
89 /* automatically cleared when it is interrogated.*/ 90 /* automatically cleared when it is interrogated.*/
90 u32 FCS_error; 91 __le32 FCS_error;
91 92
92 /* The number of MPDUs without PLCP header errors received*/ 93 /* The number of MPDUs without PLCP header errors received*/
93 /* since the last time this information element was interrogated. */ 94 /* since the last time this information element was interrogated. */
94 /* This field is automatically cleared when it is interrogated.*/ 95 /* This field is automatically cleared when it is interrogated.*/
95 u32 valid_frame; 96 __le32 valid_frame;
96 97
97 /* the number of missed sequence numbers in the squentially */ 98 /* the number of missed sequence numbers in the squentially */
98 /* values of frames seq numbers */ 99 /* values of frames seq numbers */
99 u32 seq_num_miss; 100 __le32 seq_num_miss;
100} __attribute__ ((packed)); 101} __attribute__ ((packed));
101 102
102struct acx_revision { 103struct acx_revision {
@@ -125,7 +126,7 @@ struct acx_revision {
125 * (1 = first spin, 2 = second spin, and so on). 126 * (1 = first spin, 2 = second spin, and so on).
126 * bits 24 - 31: Chip ID - The WiLink chip ID. 127 * bits 24 - 31: Chip ID - The WiLink chip ID.
127 */ 128 */
128 u32 hw_version; 129 __le32 hw_version;
129} __attribute__ ((packed)); 130} __attribute__ ((packed));
130 131
131enum wl1271_psm_mode { 132enum wl1271_psm_mode {
@@ -170,7 +171,6 @@ enum {
170#define DP_RX_PACKET_RING_CHUNK_NUM 2 171#define DP_RX_PACKET_RING_CHUNK_NUM 2
171#define DP_TX_PACKET_RING_CHUNK_NUM 2 172#define DP_TX_PACKET_RING_CHUNK_NUM 2
172#define DP_TX_COMPLETE_TIME_OUT 20 173#define DP_TX_COMPLETE_TIME_OUT 20
173#define FW_TX_CMPLT_BLOCK_SIZE 16
174 174
175#define TX_MSDU_LIFETIME_MIN 0 175#define TX_MSDU_LIFETIME_MIN 0
176#define TX_MSDU_LIFETIME_MAX 3000 176#define TX_MSDU_LIFETIME_MAX 3000
@@ -186,7 +186,7 @@ struct acx_rx_msdu_lifetime {
186 * The maximum amount of time, in TU, before the 186 * The maximum amount of time, in TU, before the
187 * firmware discards the MSDU. 187 * firmware discards the MSDU.
188 */ 188 */
189 u32 lifetime; 189 __le32 lifetime;
190} __attribute__ ((packed)); 190} __attribute__ ((packed));
191 191
192/* 192/*
@@ -273,14 +273,14 @@ struct acx_rx_msdu_lifetime {
273struct acx_rx_config { 273struct acx_rx_config {
274 struct acx_header header; 274 struct acx_header header;
275 275
276 u32 config_options; 276 __le32 config_options;
277 u32 filter_options; 277 __le32 filter_options;
278} __attribute__ ((packed)); 278} __attribute__ ((packed));
279 279
280struct acx_packet_detection { 280struct acx_packet_detection {
281 struct acx_header header; 281 struct acx_header header;
282 282
283 u32 threshold; 283 __le32 threshold;
284} __attribute__ ((packed)); 284} __attribute__ ((packed));
285 285
286 286
@@ -302,8 +302,8 @@ struct acx_slot {
302} __attribute__ ((packed)); 302} __attribute__ ((packed));
303 303
304 304
305#define ADDRESS_GROUP_MAX (8) 305#define ACX_MC_ADDRESS_GROUP_MAX (8)
306#define ADDRESS_GROUP_MAX_LEN (ETH_ALEN * ADDRESS_GROUP_MAX) 306#define ADDRESS_GROUP_MAX_LEN (ETH_ALEN * ACX_MC_ADDRESS_GROUP_MAX)
307 307
308struct acx_dot11_grp_addr_tbl { 308struct acx_dot11_grp_addr_tbl {
309 struct acx_header header; 309 struct acx_header header;
@@ -314,40 +314,17 @@ struct acx_dot11_grp_addr_tbl {
314 u8 mac_table[ADDRESS_GROUP_MAX_LEN]; 314 u8 mac_table[ADDRESS_GROUP_MAX_LEN];
315} __attribute__ ((packed)); 315} __attribute__ ((packed));
316 316
317
318#define RX_TIMEOUT_PS_POLL_MIN 0
319#define RX_TIMEOUT_PS_POLL_MAX (200000)
320#define RX_TIMEOUT_PS_POLL_DEF (15)
321#define RX_TIMEOUT_UPSD_MIN 0
322#define RX_TIMEOUT_UPSD_MAX (200000)
323#define RX_TIMEOUT_UPSD_DEF (15)
324
325struct acx_rx_timeout { 317struct acx_rx_timeout {
326 struct acx_header header; 318 struct acx_header header;
327 319
328 /* 320 __le16 ps_poll_timeout;
329 * The longest time the STA will wait to receive 321 __le16 upsd_timeout;
330 * traffic from the AP after a PS-poll has been
331 * transmitted.
332 */
333 u16 ps_poll_timeout;
334
335 /*
336 * The longest time the STA will wait to receive
337 * traffic from the AP after a frame has been sent
338 * from an UPSD enabled queue.
339 */
340 u16 upsd_timeout;
341} __attribute__ ((packed)); 322} __attribute__ ((packed));
342 323
343#define RTS_THRESHOLD_MIN 0
344#define RTS_THRESHOLD_MAX 4096
345#define RTS_THRESHOLD_DEF 2347
346
347struct acx_rts_threshold { 324struct acx_rts_threshold {
348 struct acx_header header; 325 struct acx_header header;
349 326
350 u16 threshold; 327 __le16 threshold;
351 u8 pad[2]; 328 u8 pad[2];
352} __attribute__ ((packed)); 329} __attribute__ ((packed));
353 330
@@ -371,7 +348,7 @@ struct acx_beacon_filter_option {
371 * ACXBeaconFilterEntry (not 221) 348 * ACXBeaconFilterEntry (not 221)
372 * Byte Offset Size (Bytes) Definition 349 * Byte Offset Size (Bytes) Definition
373 * =========== ============ ========== 350 * =========== ============ ==========
374 * 0 1 IE identifier 351 * 0 1 IE identifier
375 * 1 1 Treatment bit mask 352 * 1 1 Treatment bit mask
376 * 353 *
377 * ACXBeaconFilterEntry (221) 354 * ACXBeaconFilterEntry (221)
@@ -404,8 +381,15 @@ struct acx_beacon_filter_ie_table {
404 struct acx_header header; 381 struct acx_header header;
405 382
406 u8 num_ie; 383 u8 num_ie;
407 u8 table[BEACON_FILTER_TABLE_MAX_SIZE];
408 u8 pad[3]; 384 u8 pad[3];
385 u8 table[BEACON_FILTER_TABLE_MAX_SIZE];
386} __attribute__ ((packed));
387
388struct acx_conn_monit_params {
389 struct acx_header header;
390
391 __le32 synch_fail_thold; /* number of beacons missed */
392 __le32 bss_lose_timeout; /* number of TU's from synch fail */
409} __attribute__ ((packed)); 393} __attribute__ ((packed));
410 394
411enum { 395enum {
@@ -431,6 +415,14 @@ struct acx_bt_wlan_coex {
431 u8 pad[3]; 415 u8 pad[3];
432} __attribute__ ((packed)); 416} __attribute__ ((packed));
433 417
418struct acx_dco_itrim_params {
419 struct acx_header header;
420
421 u8 enable;
422 u8 padding[3];
423 __le32 timeout;
424} __attribute__ ((packed));
425
434#define PTA_ANTENNA_TYPE_DEF (0) 426#define PTA_ANTENNA_TYPE_DEF (0)
435#define PTA_BT_HP_MAXTIME_DEF (2000) 427#define PTA_BT_HP_MAXTIME_DEF (2000)
436#define PTA_WLAN_HP_MAX_TIME_DEF (5000) 428#define PTA_WLAN_HP_MAX_TIME_DEF (5000)
@@ -463,150 +455,34 @@ struct acx_bt_wlan_coex {
463struct acx_bt_wlan_coex_param { 455struct acx_bt_wlan_coex_param {
464 struct acx_header header; 456 struct acx_header header;
465 457
466 /* 458 __le32 per_threshold;
467 * The minimum rate of a received WLAN packet in the STA, 459 __le32 max_scan_compensation_time;
468 * during protective mode, of which a new BT-HP request 460 __le16 nfs_sample_interval;
469 * during this Rx will always be respected and gain the antenna. 461 u8 load_ratio;
470 */ 462 u8 auto_ps_mode;
471 u32 min_rate; 463 u8 probe_req_compensation;
472 464 u8 scan_window_compensation;
473 /* Max time the BT HP will be respected. */ 465 u8 antenna_config;
474 u16 bt_hp_max_time; 466 u8 beacon_miss_threshold;
475 467 __le32 rate_adaptation_threshold;
476 /* Max time the WLAN HP will be respected. */ 468 s8 rate_adaptation_snr;
477 u16 wlan_hp_max_time; 469 u8 padding[3];
478
479 /*
480 * The time between the last BT activity
481 * and the moment when the sense mode returns
482 * to SENSE_INACTIVE.
483 */
484 u16 sense_disable_timer;
485
486 /* Time before the next BT HP instance */
487 u16 rx_time_bt_hp;
488 u16 tx_time_bt_hp;
489
490 /* range: 10-20000 default: 1500 */
491 u16 rx_time_bt_hp_fast;
492 u16 tx_time_bt_hp_fast;
493
494 /* range: 2000-65535 default: 8700 */
495 u16 wlan_cycle_fast;
496
497 /* range: 0 - 15000 (Msec) default: 1000 */
498 u16 bt_anti_starvation_period;
499
500 /* range 400-10000(Usec) default: 3000 */
501 u16 next_bt_lp_packet;
502
503 /* Deafult: worst case for BT DH5 traffic */
504 u16 wake_up_beacon;
505
506 /* range: 0-50000(Usec) default: 1050 */
507 u16 hp_dm_max_guard_time;
508
509 /*
510 * This is to prevent both BT & WLAN antenna
511 * starvation.
512 * Range: 100-50000(Usec) default:2550
513 */
514 u16 next_wlan_packet;
515
516 /* 0 -> shared antenna */
517 u8 antenna_type;
518
519 /*
520 * 0 -> TI legacy
521 * 1 -> Palau
522 */
523 u8 signal_type;
524
525 /*
526 * BT AFH status
527 * 0 -> no AFH
528 * 1 -> from dedicated GPIO
529 * 2 -> AFH on (from host)
530 */
531 u8 afh_leverage_on;
532
533 /*
534 * The number of cycles during which no
535 * TX will be sent after 1 cycle of RX
536 * transaction in protective mode
537 */
538 u8 quiet_cycle_num;
539
540 /*
541 * The maximum number of CTSs that will
542 * be sent for receiving RX packet in
543 * protective mode
544 */
545 u8 max_cts;
546
547 /*
548 * The number of WLAN packets
549 * transferred in common mode before
550 * switching to BT.
551 */
552 u8 wlan_packets_num;
553
554 /*
555 * The number of BT packets
556 * transferred in common mode before
557 * switching to WLAN.
558 */
559 u8 bt_packets_num;
560
561 /* range: 1-255 default: 5 */
562 u8 missed_rx_avalanche;
563
564 /* range: 0-1 default: 1 */
565 u8 wlan_elp_hp;
566
567 /* range: 0 - 15 default: 4 */
568 u8 bt_anti_starvation_cycles;
569
570 u8 ack_mode_dual_ant;
571
572 /*
573 * Allow PA_SD assertion/de-assertion
574 * during enabled BT activity.
575 */
576 u8 pa_sd_enable;
577
578 /*
579 * Enable/Disable PTA in auto mode:
580 * Support Both Active & P.S modes
581 */
582 u8 pta_auto_mode_enable;
583
584 /* range: 0 - 20 default: 1 */
585 u8 bt_hp_respected_num;
586} __attribute__ ((packed)); 470} __attribute__ ((packed));
587 471
588#define CCA_THRSH_ENABLE_ENERGY_D 0x140A
589#define CCA_THRSH_DISABLE_ENERGY_D 0xFFEF
590
591struct acx_energy_detection { 472struct acx_energy_detection {
592 struct acx_header header; 473 struct acx_header header;
593 474
594 /* The RX Clear Channel Assessment threshold in the PHY */ 475 /* The RX Clear Channel Assessment threshold in the PHY */
595 u16 rx_cca_threshold; 476 __le16 rx_cca_threshold;
596 u8 tx_energy_detection; 477 u8 tx_energy_detection;
597 u8 pad; 478 u8 pad;
598} __attribute__ ((packed)); 479} __attribute__ ((packed));
599 480
600#define BCN_RX_TIMEOUT_DEF_VALUE 10000
601#define BROADCAST_RX_TIMEOUT_DEF_VALUE 20000
602#define RX_BROADCAST_IN_PS_DEF_VALUE 1
603#define CONSECUTIVE_PS_POLL_FAILURE_DEF 4
604
605struct acx_beacon_broadcast { 481struct acx_beacon_broadcast {
606 struct acx_header header; 482 struct acx_header header;
607 483
608 u16 beacon_rx_timeout; 484 __le16 beacon_rx_timeout;
609 u16 broadcast_timeout; 485 __le16 broadcast_timeout;
610 486
611 /* Enables receiving of broadcast packets in PS mode */ 487 /* Enables receiving of broadcast packets in PS mode */
612 u8 rx_broadcast_in_ps; 488 u8 rx_broadcast_in_ps;
@@ -619,8 +495,8 @@ struct acx_beacon_broadcast {
619struct acx_event_mask { 495struct acx_event_mask {
620 struct acx_header header; 496 struct acx_header header;
621 497
622 u32 event_mask; 498 __le32 event_mask;
623 u32 high_event_mask; /* Unused */ 499 __le32 high_event_mask; /* Unused */
624} __attribute__ ((packed)); 500} __attribute__ ((packed));
625 501
626#define CFG_RX_FCS BIT(2) 502#define CFG_RX_FCS BIT(2)
@@ -657,11 +533,15 @@ struct acx_event_mask {
657#define SCAN_TRIGGERED BIT(2) 533#define SCAN_TRIGGERED BIT(2)
658#define SCAN_PRIORITY_HIGH BIT(3) 534#define SCAN_PRIORITY_HIGH BIT(3)
659 535
536/* When set, disable HW encryption */
537#define DF_ENCRYPTION_DISABLE 0x01
538#define DF_SNIFF_MODE_ENABLE 0x80
539
660struct acx_feature_config { 540struct acx_feature_config {
661 struct acx_header header; 541 struct acx_header header;
662 542
663 u32 options; 543 __le32 options;
664 u32 data_flow_options; 544 __le32 data_flow_options;
665} __attribute__ ((packed)); 545} __attribute__ ((packed));
666 546
667struct acx_current_tx_power { 547struct acx_current_tx_power {
@@ -671,14 +551,6 @@ struct acx_current_tx_power {
671 u8 padding[3]; 551 u8 padding[3];
672} __attribute__ ((packed)); 552} __attribute__ ((packed));
673 553
674enum acx_wake_up_event {
675 WAKE_UP_EVENT_BEACON_BITMAP = 0x01, /* Wake on every Beacon*/
676 WAKE_UP_EVENT_DTIM_BITMAP = 0x02, /* Wake on every DTIM*/
677 WAKE_UP_EVENT_N_DTIM_BITMAP = 0x04, /* Wake on every Nth DTIM */
678 WAKE_UP_EVENT_N_BEACONS_BITMAP = 0x08, /* Wake on every Nth Beacon */
679 WAKE_UP_EVENT_BITS_MASK = 0x0F
680};
681
682struct acx_wake_up_condition { 554struct acx_wake_up_condition {
683 struct acx_header header; 555 struct acx_header header;
684 556
@@ -693,7 +565,7 @@ struct acx_aid {
693 /* 565 /*
694 * To be set when associated with an AP. 566 * To be set when associated with an AP.
695 */ 567 */
696 u16 aid; 568 __le16 aid;
697 u8 pad[2]; 569 u8 pad[2];
698} __attribute__ ((packed)); 570} __attribute__ ((packed));
699 571
@@ -725,152 +597,152 @@ struct acx_ctsprotect {
725} __attribute__ ((packed)); 597} __attribute__ ((packed));
726 598
727struct acx_tx_statistics { 599struct acx_tx_statistics {
728 u32 internal_desc_overflow; 600 __le32 internal_desc_overflow;
729} __attribute__ ((packed)); 601} __attribute__ ((packed));
730 602
731struct acx_rx_statistics { 603struct acx_rx_statistics {
732 u32 out_of_mem; 604 __le32 out_of_mem;
733 u32 hdr_overflow; 605 __le32 hdr_overflow;
734 u32 hw_stuck; 606 __le32 hw_stuck;
735 u32 dropped; 607 __le32 dropped;
736 u32 fcs_err; 608 __le32 fcs_err;
737 u32 xfr_hint_trig; 609 __le32 xfr_hint_trig;
738 u32 path_reset; 610 __le32 path_reset;
739 u32 reset_counter; 611 __le32 reset_counter;
740} __attribute__ ((packed)); 612} __attribute__ ((packed));
741 613
742struct acx_dma_statistics { 614struct acx_dma_statistics {
743 u32 rx_requested; 615 __le32 rx_requested;
744 u32 rx_errors; 616 __le32 rx_errors;
745 u32 tx_requested; 617 __le32 tx_requested;
746 u32 tx_errors; 618 __le32 tx_errors;
747} __attribute__ ((packed)); 619} __attribute__ ((packed));
748 620
749struct acx_isr_statistics { 621struct acx_isr_statistics {
750 /* host command complete */ 622 /* host command complete */
751 u32 cmd_cmplt; 623 __le32 cmd_cmplt;
752 624
753 /* fiqisr() */ 625 /* fiqisr() */
754 u32 fiqs; 626 __le32 fiqs;
755 627
756 /* (INT_STS_ND & INT_TRIG_RX_HEADER) */ 628 /* (INT_STS_ND & INT_TRIG_RX_HEADER) */
757 u32 rx_headers; 629 __le32 rx_headers;
758 630
759 /* (INT_STS_ND & INT_TRIG_RX_CMPLT) */ 631 /* (INT_STS_ND & INT_TRIG_RX_CMPLT) */
760 u32 rx_completes; 632 __le32 rx_completes;
761 633
762 /* (INT_STS_ND & INT_TRIG_NO_RX_BUF) */ 634 /* (INT_STS_ND & INT_TRIG_NO_RX_BUF) */
763 u32 rx_mem_overflow; 635 __le32 rx_mem_overflow;
764 636
765 /* (INT_STS_ND & INT_TRIG_S_RX_RDY) */ 637 /* (INT_STS_ND & INT_TRIG_S_RX_RDY) */
766 u32 rx_rdys; 638 __le32 rx_rdys;
767 639
768 /* irqisr() */ 640 /* irqisr() */
769 u32 irqs; 641 __le32 irqs;
770 642
771 /* (INT_STS_ND & INT_TRIG_TX_PROC) */ 643 /* (INT_STS_ND & INT_TRIG_TX_PROC) */
772 u32 tx_procs; 644 __le32 tx_procs;
773 645
774 /* (INT_STS_ND & INT_TRIG_DECRYPT_DONE) */ 646 /* (INT_STS_ND & INT_TRIG_DECRYPT_DONE) */
775 u32 decrypt_done; 647 __le32 decrypt_done;
776 648
777 /* (INT_STS_ND & INT_TRIG_DMA0) */ 649 /* (INT_STS_ND & INT_TRIG_DMA0) */
778 u32 dma0_done; 650 __le32 dma0_done;
779 651
780 /* (INT_STS_ND & INT_TRIG_DMA1) */ 652 /* (INT_STS_ND & INT_TRIG_DMA1) */
781 u32 dma1_done; 653 __le32 dma1_done;
782 654
783 /* (INT_STS_ND & INT_TRIG_TX_EXC_CMPLT) */ 655 /* (INT_STS_ND & INT_TRIG_TX_EXC_CMPLT) */
784 u32 tx_exch_complete; 656 __le32 tx_exch_complete;
785 657
786 /* (INT_STS_ND & INT_TRIG_COMMAND) */ 658 /* (INT_STS_ND & INT_TRIG_COMMAND) */
787 u32 commands; 659 __le32 commands;
788 660
789 /* (INT_STS_ND & INT_TRIG_RX_PROC) */ 661 /* (INT_STS_ND & INT_TRIG_RX_PROC) */
790 u32 rx_procs; 662 __le32 rx_procs;
791 663
792 /* (INT_STS_ND & INT_TRIG_PM_802) */ 664 /* (INT_STS_ND & INT_TRIG_PM_802) */
793 u32 hw_pm_mode_changes; 665 __le32 hw_pm_mode_changes;
794 666
795 /* (INT_STS_ND & INT_TRIG_ACKNOWLEDGE) */ 667 /* (INT_STS_ND & INT_TRIG_ACKNOWLEDGE) */
796 u32 host_acknowledges; 668 __le32 host_acknowledges;
797 669
798 /* (INT_STS_ND & INT_TRIG_PM_PCI) */ 670 /* (INT_STS_ND & INT_TRIG_PM_PCI) */
799 u32 pci_pm; 671 __le32 pci_pm;
800 672
801 /* (INT_STS_ND & INT_TRIG_ACM_WAKEUP) */ 673 /* (INT_STS_ND & INT_TRIG_ACM_WAKEUP) */
802 u32 wakeups; 674 __le32 wakeups;
803 675
804 /* (INT_STS_ND & INT_TRIG_LOW_RSSI) */ 676 /* (INT_STS_ND & INT_TRIG_LOW_RSSI) */
805 u32 low_rssi; 677 __le32 low_rssi;
806} __attribute__ ((packed)); 678} __attribute__ ((packed));
807 679
808struct acx_wep_statistics { 680struct acx_wep_statistics {
809 /* WEP address keys configured */ 681 /* WEP address keys configured */
810 u32 addr_key_count; 682 __le32 addr_key_count;
811 683
812 /* default keys configured */ 684 /* default keys configured */
813 u32 default_key_count; 685 __le32 default_key_count;
814 686
815 u32 reserved; 687 __le32 reserved;
816 688
817 /* number of times that WEP key not found on lookup */ 689 /* number of times that WEP key not found on lookup */
818 u32 key_not_found; 690 __le32 key_not_found;
819 691
820 /* number of times that WEP key decryption failed */ 692 /* number of times that WEP key decryption failed */
821 u32 decrypt_fail; 693 __le32 decrypt_fail;
822 694
823 /* WEP packets decrypted */ 695 /* WEP packets decrypted */
824 u32 packets; 696 __le32 packets;
825 697
826 /* WEP decrypt interrupts */ 698 /* WEP decrypt interrupts */
827 u32 interrupt; 699 __le32 interrupt;
828} __attribute__ ((packed)); 700} __attribute__ ((packed));
829 701
830#define ACX_MISSED_BEACONS_SPREAD 10 702#define ACX_MISSED_BEACONS_SPREAD 10
831 703
832struct acx_pwr_statistics { 704struct acx_pwr_statistics {
833 /* the amount of enters into power save mode (both PD & ELP) */ 705 /* the amount of enters into power save mode (both PD & ELP) */
834 u32 ps_enter; 706 __le32 ps_enter;
835 707
836 /* the amount of enters into ELP mode */ 708 /* the amount of enters into ELP mode */
837 u32 elp_enter; 709 __le32 elp_enter;
838 710
839 /* the amount of missing beacon interrupts to the host */ 711 /* the amount of missing beacon interrupts to the host */
840 u32 missing_bcns; 712 __le32 missing_bcns;
841 713
842 /* the amount of wake on host-access times */ 714 /* the amount of wake on host-access times */
843 u32 wake_on_host; 715 __le32 wake_on_host;
844 716
845 /* the amount of wake on timer-expire */ 717 /* the amount of wake on timer-expire */
846 u32 wake_on_timer_exp; 718 __le32 wake_on_timer_exp;
847 719
848 /* the number of packets that were transmitted with PS bit set */ 720 /* the number of packets that were transmitted with PS bit set */
849 u32 tx_with_ps; 721 __le32 tx_with_ps;
850 722
851 /* the number of packets that were transmitted with PS bit clear */ 723 /* the number of packets that were transmitted with PS bit clear */
852 u32 tx_without_ps; 724 __le32 tx_without_ps;
853 725
854 /* the number of received beacons */ 726 /* the number of received beacons */
855 u32 rcvd_beacons; 727 __le32 rcvd_beacons;
856 728
857 /* the number of entering into PowerOn (power save off) */ 729 /* the number of entering into PowerOn (power save off) */
858 u32 power_save_off; 730 __le32 power_save_off;
859 731
860 /* the number of entries into power save mode */ 732 /* the number of entries into power save mode */
861 u16 enable_ps; 733 __le16 enable_ps;
862 734
863 /* 735 /*
864 * the number of exits from power save, not including failed PS 736 * the number of exits from power save, not including failed PS
865 * transitions 737 * transitions
866 */ 738 */
867 u16 disable_ps; 739 __le16 disable_ps;
868 740
869 /* 741 /*
870 * the number of times the TSF counter was adjusted because 742 * the number of times the TSF counter was adjusted because
871 * of drift 743 * of drift
872 */ 744 */
873 u32 fix_tsf_ps; 745 __le32 fix_tsf_ps;
874 746
875 /* Gives statistics about the spread continuous missed beacons. 747 /* Gives statistics about the spread continuous missed beacons.
876 * The 16 LSB are dedicated for the PS mode. 748 * The 16 LSB are dedicated for the PS mode.
@@ -881,53 +753,53 @@ struct acx_pwr_statistics {
881 * ... 753 * ...
882 * cont_miss_bcns_spread[9] - ten and more continuous missed beacons. 754 * cont_miss_bcns_spread[9] - ten and more continuous missed beacons.
883 */ 755 */
884 u32 cont_miss_bcns_spread[ACX_MISSED_BEACONS_SPREAD]; 756 __le32 cont_miss_bcns_spread[ACX_MISSED_BEACONS_SPREAD];
885 757
886 /* the number of beacons in awake mode */ 758 /* the number of beacons in awake mode */
887 u32 rcvd_awake_beacons; 759 __le32 rcvd_awake_beacons;
888} __attribute__ ((packed)); 760} __attribute__ ((packed));
889 761
890struct acx_mic_statistics { 762struct acx_mic_statistics {
891 u32 rx_pkts; 763 __le32 rx_pkts;
892 u32 calc_failure; 764 __le32 calc_failure;
893} __attribute__ ((packed)); 765} __attribute__ ((packed));
894 766
895struct acx_aes_statistics { 767struct acx_aes_statistics {
896 u32 encrypt_fail; 768 __le32 encrypt_fail;
897 u32 decrypt_fail; 769 __le32 decrypt_fail;
898 u32 encrypt_packets; 770 __le32 encrypt_packets;
899 u32 decrypt_packets; 771 __le32 decrypt_packets;
900 u32 encrypt_interrupt; 772 __le32 encrypt_interrupt;
901 u32 decrypt_interrupt; 773 __le32 decrypt_interrupt;
902} __attribute__ ((packed)); 774} __attribute__ ((packed));
903 775
904struct acx_event_statistics { 776struct acx_event_statistics {
905 u32 heart_beat; 777 __le32 heart_beat;
906 u32 calibration; 778 __le32 calibration;
907 u32 rx_mismatch; 779 __le32 rx_mismatch;
908 u32 rx_mem_empty; 780 __le32 rx_mem_empty;
909 u32 rx_pool; 781 __le32 rx_pool;
910 u32 oom_late; 782 __le32 oom_late;
911 u32 phy_transmit_error; 783 __le32 phy_transmit_error;
912 u32 tx_stuck; 784 __le32 tx_stuck;
913} __attribute__ ((packed)); 785} __attribute__ ((packed));
914 786
915struct acx_ps_statistics { 787struct acx_ps_statistics {
916 u32 pspoll_timeouts; 788 __le32 pspoll_timeouts;
917 u32 upsd_timeouts; 789 __le32 upsd_timeouts;
918 u32 upsd_max_sptime; 790 __le32 upsd_max_sptime;
919 u32 upsd_max_apturn; 791 __le32 upsd_max_apturn;
920 u32 pspoll_max_apturn; 792 __le32 pspoll_max_apturn;
921 u32 pspoll_utilization; 793 __le32 pspoll_utilization;
922 u32 upsd_utilization; 794 __le32 upsd_utilization;
923} __attribute__ ((packed)); 795} __attribute__ ((packed));
924 796
925struct acx_rxpipe_statistics { 797struct acx_rxpipe_statistics {
926 u32 rx_prep_beacon_drop; 798 __le32 rx_prep_beacon_drop;
927 u32 descr_host_int_trig_rx_data; 799 __le32 descr_host_int_trig_rx_data;
928 u32 beacon_buffer_thres_host_int_trig_rx_data; 800 __le32 beacon_buffer_thres_host_int_trig_rx_data;
929 u32 missed_beacon_host_int_trig_rx_data; 801 __le32 missed_beacon_host_int_trig_rx_data;
930 u32 tx_xfr_host_int_trig_rx_data; 802 __le32 tx_xfr_host_int_trig_rx_data;
931} __attribute__ ((packed)); 803} __attribute__ ((packed));
932 804
933struct acx_statistics { 805struct acx_statistics {
@@ -946,63 +818,34 @@ struct acx_statistics {
946 struct acx_rxpipe_statistics rxpipe; 818 struct acx_rxpipe_statistics rxpipe;
947} __attribute__ ((packed)); 819} __attribute__ ((packed));
948 820
949#define ACX_MAX_RATE_CLASSES 8
950#define ACX_RATE_MASK_UNSPECIFIED 0
951#define ACX_RATE_MASK_ALL 0x1eff
952#define ACX_RATE_RETRY_LIMIT 10
953
954struct acx_rate_class { 821struct acx_rate_class {
955 u32 enabled_rates; 822 __le32 enabled_rates;
956 u8 short_retry_limit; 823 u8 short_retry_limit;
957 u8 long_retry_limit; 824 u8 long_retry_limit;
958 u8 aflags; 825 u8 aflags;
959 u8 reserved; 826 u8 reserved;
960}; 827};
961 828
829#define ACX_TX_BASIC_RATE 0
830#define ACX_TX_AP_FULL_RATE 1
831#define ACX_TX_RATE_POLICY_CNT 2
962struct acx_rate_policy { 832struct acx_rate_policy {
963 struct acx_header header; 833 struct acx_header header;
964 834
965 u32 rate_class_cnt; 835 __le32 rate_class_cnt;
966 struct acx_rate_class rate_class[ACX_MAX_RATE_CLASSES]; 836 struct acx_rate_class rate_class[CONF_TX_MAX_RATE_CLASSES];
967} __attribute__ ((packed)); 837} __attribute__ ((packed));
968 838
969#define WL1271_ACX_AC_COUNT 4
970
971struct acx_ac_cfg { 839struct acx_ac_cfg {
972 struct acx_header header; 840 struct acx_header header;
973 u8 ac; 841 u8 ac;
974 u8 cw_min; 842 u8 cw_min;
975 u16 cw_max; 843 __le16 cw_max;
976 u8 aifsn; 844 u8 aifsn;
977 u8 reserved; 845 u8 reserved;
978 u16 tx_op_limit; 846 __le16 tx_op_limit;
979} __attribute__ ((packed)); 847} __attribute__ ((packed));
980 848
981enum wl1271_acx_ac {
982 WL1271_ACX_AC_BE = 0,
983 WL1271_ACX_AC_BK = 1,
984 WL1271_ACX_AC_VI = 2,
985 WL1271_ACX_AC_VO = 3,
986 WL1271_ACX_AC_CTS2SELF = 4,
987 WL1271_ACX_AC_ANY_TID = 0x1F,
988 WL1271_ACX_AC_INVALID = 0xFF,
989};
990
991enum wl1271_acx_ps_scheme {
992 WL1271_ACX_PS_SCHEME_LEGACY = 0,
993 WL1271_ACX_PS_SCHEME_UPSD_TRIGGER = 1,
994 WL1271_ACX_PS_SCHEME_LEGACY_PSPOLL = 2,
995 WL1271_ACX_PS_SCHEME_SAPSD = 3,
996};
997
998enum wl1271_acx_ack_policy {
999 WL1271_ACX_ACK_POLICY_LEGACY = 0,
1000 WL1271_ACX_ACK_POLICY_NO_ACK = 1,
1001 WL1271_ACX_ACK_POLICY_BLOCK = 2,
1002};
1003
1004#define WL1271_ACX_TID_COUNT 7
1005
1006struct acx_tid_config { 849struct acx_tid_config {
1007 struct acx_header header; 850 struct acx_header header;
1008 u8 queue_id; 851 u8 queue_id;
@@ -1011,26 +854,23 @@ struct acx_tid_config {
1011 u8 ps_scheme; 854 u8 ps_scheme;
1012 u8 ack_policy; 855 u8 ack_policy;
1013 u8 padding[3]; 856 u8 padding[3];
1014 u32 apsd_conf[2]; 857 __le32 apsd_conf[2];
1015} __attribute__ ((packed)); 858} __attribute__ ((packed));
1016 859
1017struct acx_frag_threshold { 860struct acx_frag_threshold {
1018 struct acx_header header; 861 struct acx_header header;
1019 u16 frag_threshold; 862 __le16 frag_threshold;
1020 u8 padding[2]; 863 u8 padding[2];
1021} __attribute__ ((packed)); 864} __attribute__ ((packed));
1022 865
1023#define WL1271_ACX_TX_COMPL_TIMEOUT 5
1024#define WL1271_ACX_TX_COMPL_THRESHOLD 5
1025
1026struct acx_tx_config_options { 866struct acx_tx_config_options {
1027 struct acx_header header; 867 struct acx_header header;
1028 u16 tx_compl_timeout; /* msec */ 868 __le16 tx_compl_timeout; /* msec */
1029 u16 tx_compl_threshold; /* number of packets */ 869 __le16 tx_compl_threshold; /* number of packets */
1030} __attribute__ ((packed)); 870} __attribute__ ((packed));
1031 871
1032#define ACX_RX_MEM_BLOCKS 64 872#define ACX_RX_MEM_BLOCKS 70
1033#define ACX_TX_MIN_MEM_BLOCKS 64 873#define ACX_TX_MIN_MEM_BLOCKS 40
1034#define ACX_TX_DESCRIPTORS 32 874#define ACX_TX_DESCRIPTORS 32
1035#define ACX_NUM_SSID_PROFILES 1 875#define ACX_NUM_SSID_PROFILES 1
1036 876
@@ -1041,79 +881,94 @@ struct wl1271_acx_config_memory {
1041 u8 tx_min_mem_block_num; 881 u8 tx_min_mem_block_num;
1042 u8 num_stations; 882 u8 num_stations;
1043 u8 num_ssid_profiles; 883 u8 num_ssid_profiles;
1044 u32 total_tx_descriptors; 884 __le32 total_tx_descriptors;
1045} __attribute__ ((packed)); 885} __attribute__ ((packed));
1046 886
1047struct wl1271_acx_mem_map { 887struct wl1271_acx_mem_map {
1048 struct acx_header header; 888 struct acx_header header;
1049 889
1050 void *code_start; 890 __le32 code_start;
1051 void *code_end; 891 __le32 code_end;
1052 892
1053 void *wep_defkey_start; 893 __le32 wep_defkey_start;
1054 void *wep_defkey_end; 894 __le32 wep_defkey_end;
1055 895
1056 void *sta_table_start; 896 __le32 sta_table_start;
1057 void *sta_table_end; 897 __le32 sta_table_end;
1058 898
1059 void *packet_template_start; 899 __le32 packet_template_start;
1060 void *packet_template_end; 900 __le32 packet_template_end;
1061 901
1062 /* Address of the TX result interface (control block) */ 902 /* Address of the TX result interface (control block) */
1063 u32 tx_result; 903 __le32 tx_result;
1064 u32 tx_result_queue_start; 904 __le32 tx_result_queue_start;
1065 905
1066 void *queue_memory_start; 906 __le32 queue_memory_start;
1067 void *queue_memory_end; 907 __le32 queue_memory_end;
1068 908
1069 u32 packet_memory_pool_start; 909 __le32 packet_memory_pool_start;
1070 u32 packet_memory_pool_end; 910 __le32 packet_memory_pool_end;
1071 911
1072 void *debug_buffer1_start; 912 __le32 debug_buffer1_start;
1073 void *debug_buffer1_end; 913 __le32 debug_buffer1_end;
1074 914
1075 void *debug_buffer2_start; 915 __le32 debug_buffer2_start;
1076 void *debug_buffer2_end; 916 __le32 debug_buffer2_end;
1077 917
1078 /* Number of blocks FW allocated for TX packets */ 918 /* Number of blocks FW allocated for TX packets */
1079 u32 num_tx_mem_blocks; 919 __le32 num_tx_mem_blocks;
1080 920
1081 /* Number of blocks FW allocated for RX packets */ 921 /* Number of blocks FW allocated for RX packets */
1082 u32 num_rx_mem_blocks; 922 __le32 num_rx_mem_blocks;
1083 923
1084 /* the following 4 fields are valid in SLAVE mode only */ 924 /* the following 4 fields are valid in SLAVE mode only */
1085 u8 *tx_cbuf; 925 u8 *tx_cbuf;
1086 u8 *rx_cbuf; 926 u8 *rx_cbuf;
1087 void *rx_ctrl; 927 __le32 rx_ctrl;
1088 void *tx_ctrl; 928 __le32 tx_ctrl;
1089} __attribute__ ((packed)); 929} __attribute__ ((packed));
1090 930
1091enum wl1271_acx_rx_queue_type {
1092 RX_QUEUE_TYPE_RX_LOW_PRIORITY, /* All except the high priority */
1093 RX_QUEUE_TYPE_RX_HIGH_PRIORITY, /* Management and voice packets */
1094 RX_QUEUE_TYPE_NUM,
1095 RX_QUEUE_TYPE_MAX = USHORT_MAX
1096};
1097
1098#define WL1271_RX_INTR_THRESHOLD_DEF 0 /* no pacing, send interrupt on
1099 * every event */
1100#define WL1271_RX_INTR_THRESHOLD_MIN 0
1101#define WL1271_RX_INTR_THRESHOLD_MAX 15
1102
1103#define WL1271_RX_INTR_TIMEOUT_DEF 5
1104#define WL1271_RX_INTR_TIMEOUT_MIN 1
1105#define WL1271_RX_INTR_TIMEOUT_MAX 100
1106
1107struct wl1271_acx_rx_config_opt { 931struct wl1271_acx_rx_config_opt {
1108 struct acx_header header; 932 struct acx_header header;
1109 933
1110 u16 mblk_threshold; 934 __le16 mblk_threshold;
1111 u16 threshold; 935 __le16 threshold;
1112 u16 timeout; 936 __le16 timeout;
1113 u8 queue_type; 937 u8 queue_type;
1114 u8 reserved; 938 u8 reserved;
1115} __attribute__ ((packed)); 939} __attribute__ ((packed));
1116 940
941
942struct wl1271_acx_bet_enable {
943 struct acx_header header;
944
945 u8 enable;
946 u8 max_consecutive;
947 u8 padding[2];
948} __attribute__ ((packed));
949
950#define ACX_IPV4_VERSION 4
951#define ACX_IPV6_VERSION 6
952#define ACX_IPV4_ADDR_SIZE 4
953struct wl1271_acx_arp_filter {
954 struct acx_header header;
955 u8 version; /* ACX_IPV4_VERSION, ACX_IPV6_VERSION */
956 u8 enable; /* 1 to enable ARP filtering, 0 to disable */
957 u8 padding[2];
958 u8 address[16]; /* The configured device IP address - all ARP
959 requests directed to this IP address will pass
960 through. For IPv4, the first four bytes are
961 used. */
962} __attribute__((packed));
963
964struct wl1271_acx_pm_config {
965 struct acx_header header;
966
967 __le32 host_clk_settling_time;
968 u8 host_fast_wakeup_support;
969 u8 padding[3];
970} __attribute__ ((packed));
971
1117enum { 972enum {
1118 ACX_WAKE_UP_CONDITIONS = 0x0002, 973 ACX_WAKE_UP_CONDITIONS = 0x0002,
1119 ACX_MEM_CFG = 0x0003, 974 ACX_MEM_CFG = 0x0003,
@@ -1170,11 +1025,14 @@ enum {
1170 ACX_PEER_HT_CAP = 0x0057, 1025 ACX_PEER_HT_CAP = 0x0057,
1171 ACX_HT_BSS_OPERATION = 0x0058, 1026 ACX_HT_BSS_OPERATION = 0x0058,
1172 ACX_COEX_ACTIVITY = 0x0059, 1027 ACX_COEX_ACTIVITY = 0x0059,
1028 ACX_SET_SMART_REFLEX_DEBUG = 0x005A,
1029 ACX_SET_DCO_ITRIM_PARAMS = 0x0061,
1173 DOT11_RX_MSDU_LIFE_TIME = 0x1004, 1030 DOT11_RX_MSDU_LIFE_TIME = 0x1004,
1174 DOT11_CUR_TX_PWR = 0x100D, 1031 DOT11_CUR_TX_PWR = 0x100D,
1175 DOT11_RX_DOT11_MODE = 0x1012, 1032 DOT11_RX_DOT11_MODE = 0x1012,
1176 DOT11_RTS_THRESHOLD = 0x1013, 1033 DOT11_RTS_THRESHOLD = 0x1013,
1177 DOT11_GROUP_ADDRESS_TBL = 0x1014, 1034 DOT11_GROUP_ADDRESS_TBL = 0x1014,
1035 ACX_PM_CONFIG = 0x1016,
1178 1036
1179 MAX_DOT11_IE = DOT11_GROUP_ADDRESS_TBL, 1037 MAX_DOT11_IE = DOT11_GROUP_ADDRESS_TBL,
1180 1038
@@ -1182,23 +1040,25 @@ enum {
1182}; 1040};
1183 1041
1184 1042
1185int wl1271_acx_wake_up_conditions(struct wl1271 *wl, u8 wake_up_event, 1043int wl1271_acx_wake_up_conditions(struct wl1271 *wl);
1186 u8 listen_interval);
1187int wl1271_acx_sleep_auth(struct wl1271 *wl, u8 sleep_auth); 1044int wl1271_acx_sleep_auth(struct wl1271 *wl, u8 sleep_auth);
1188int wl1271_acx_fw_version(struct wl1271 *wl, char *buf, size_t len); 1045int wl1271_acx_fw_version(struct wl1271 *wl, char *buf, size_t len);
1189int wl1271_acx_tx_power(struct wl1271 *wl, int power); 1046int wl1271_acx_tx_power(struct wl1271 *wl, int power);
1190int wl1271_acx_feature_cfg(struct wl1271 *wl); 1047int wl1271_acx_feature_cfg(struct wl1271 *wl);
1191int wl1271_acx_mem_map(struct wl1271 *wl, 1048int wl1271_acx_mem_map(struct wl1271 *wl,
1192 struct acx_header *mem_map, size_t len); 1049 struct acx_header *mem_map, size_t len);
1193int wl1271_acx_rx_msdu_life_time(struct wl1271 *wl, u32 life_time); 1050int wl1271_acx_rx_msdu_life_time(struct wl1271 *wl);
1194int wl1271_acx_rx_config(struct wl1271 *wl, u32 config, u32 filter); 1051int wl1271_acx_rx_config(struct wl1271 *wl, u32 config, u32 filter);
1195int wl1271_acx_pd_threshold(struct wl1271 *wl); 1052int wl1271_acx_pd_threshold(struct wl1271 *wl);
1196int wl1271_acx_slot(struct wl1271 *wl, enum acx_slot_type slot_time); 1053int wl1271_acx_slot(struct wl1271 *wl, enum acx_slot_type slot_time);
1197int wl1271_acx_group_address_tbl(struct wl1271 *wl); 1054int wl1271_acx_group_address_tbl(struct wl1271 *wl, bool enable,
1055 void *mc_list, u32 mc_list_len);
1198int wl1271_acx_service_period_timeout(struct wl1271 *wl); 1056int wl1271_acx_service_period_timeout(struct wl1271 *wl);
1199int wl1271_acx_rts_threshold(struct wl1271 *wl, u16 rts_threshold); 1057int wl1271_acx_rts_threshold(struct wl1271 *wl, u16 rts_threshold);
1200int wl1271_acx_beacon_filter_opt(struct wl1271 *wl); 1058int wl1271_acx_dco_itrim_params(struct wl1271 *wl);
1059int wl1271_acx_beacon_filter_opt(struct wl1271 *wl, bool enable_filter);
1201int wl1271_acx_beacon_filter_table(struct wl1271 *wl); 1060int wl1271_acx_beacon_filter_table(struct wl1271 *wl);
1061int wl1271_acx_conn_monit_params(struct wl1271 *wl);
1202int wl1271_acx_sg_enable(struct wl1271 *wl); 1062int wl1271_acx_sg_enable(struct wl1271 *wl);
1203int wl1271_acx_sg_cfg(struct wl1271 *wl); 1063int wl1271_acx_sg_cfg(struct wl1271 *wl);
1204int wl1271_acx_cca_threshold(struct wl1271 *wl); 1064int wl1271_acx_cca_threshold(struct wl1271 *wl);
@@ -1207,15 +1067,23 @@ int wl1271_acx_aid(struct wl1271 *wl, u16 aid);
1207int wl1271_acx_event_mbox_mask(struct wl1271 *wl, u32 event_mask); 1067int wl1271_acx_event_mbox_mask(struct wl1271 *wl, u32 event_mask);
1208int wl1271_acx_set_preamble(struct wl1271 *wl, enum acx_preamble_type preamble); 1068int wl1271_acx_set_preamble(struct wl1271 *wl, enum acx_preamble_type preamble);
1209int wl1271_acx_cts_protect(struct wl1271 *wl, 1069int wl1271_acx_cts_protect(struct wl1271 *wl,
1210 enum acx_ctsprotect_type ctsprotect); 1070 enum acx_ctsprotect_type ctsprotect);
1211int wl1271_acx_statistics(struct wl1271 *wl, struct acx_statistics *stats); 1071int wl1271_acx_statistics(struct wl1271 *wl, struct acx_statistics *stats);
1212int wl1271_acx_rate_policies(struct wl1271 *wl); 1072int wl1271_acx_rate_policies(struct wl1271 *wl);
1213int wl1271_acx_ac_cfg(struct wl1271 *wl); 1073int wl1271_acx_ac_cfg(struct wl1271 *wl, u8 ac, u8 cw_min, u16 cw_max,
1214int wl1271_acx_tid_cfg(struct wl1271 *wl); 1074 u8 aifsn, u16 txop);
1075int wl1271_acx_tid_cfg(struct wl1271 *wl, u8 queue_id, u8 channel_type,
1076 u8 tsid, u8 ps_scheme, u8 ack_policy,
1077 u32 apsd_conf0, u32 apsd_conf1);
1215int wl1271_acx_frag_threshold(struct wl1271 *wl); 1078int wl1271_acx_frag_threshold(struct wl1271 *wl);
1216int wl1271_acx_tx_config_options(struct wl1271 *wl); 1079int wl1271_acx_tx_config_options(struct wl1271 *wl);
1217int wl1271_acx_mem_cfg(struct wl1271 *wl); 1080int wl1271_acx_mem_cfg(struct wl1271 *wl);
1218int wl1271_acx_init_mem_config(struct wl1271 *wl); 1081int wl1271_acx_init_mem_config(struct wl1271 *wl);
1219int wl1271_acx_init_rx_interrupt(struct wl1271 *wl); 1082int wl1271_acx_init_rx_interrupt(struct wl1271 *wl);
1083int wl1271_acx_smart_reflex(struct wl1271 *wl);
1084int wl1271_acx_bet_enable(struct wl1271 *wl, bool enable);
1085int wl1271_acx_arp_ip_filter(struct wl1271 *wl, bool enable, u8 *address,
1086 u8 version);
1087int wl1271_acx_pm_config(struct wl1271 *wl);
1220 1088
1221#endif /* __WL1271_ACX_H__ */ 1089#endif /* __WL1271_ACX_H__ */
diff --git a/drivers/net/wireless/wl12xx/wl1271_boot.c b/drivers/net/wireless/wl12xx/wl1271_boot.c
index 8228ef474a7e..024356263065 100644
--- a/drivers/net/wireless/wl12xx/wl1271_boot.c
+++ b/drivers/net/wireless/wl12xx/wl1271_boot.c
@@ -22,11 +22,13 @@
22 */ 22 */
23 23
24#include <linux/gpio.h> 24#include <linux/gpio.h>
25#include <linux/slab.h>
25 26
26#include "wl1271_acx.h" 27#include "wl1271_acx.h"
27#include "wl1271_reg.h" 28#include "wl1271_reg.h"
28#include "wl1271_boot.h" 29#include "wl1271_boot.h"
29#include "wl1271_spi.h" 30#include "wl1271_spi.h"
31#include "wl1271_io.h"
30#include "wl1271_event.h" 32#include "wl1271_event.h"
31 33
32static struct wl1271_partition_set part_table[PART_TABLE_LEN] = { 34static struct wl1271_partition_set part_table[PART_TABLE_LEN] = {
@@ -39,6 +41,14 @@ static struct wl1271_partition_set part_table[PART_TABLE_LEN] = {
39 .start = REGISTERS_BASE, 41 .start = REGISTERS_BASE,
40 .size = 0x00008800 42 .size = 0x00008800
41 }, 43 },
44 .mem2 = {
45 .start = 0x00000000,
46 .size = 0x00000000
47 },
48 .mem3 = {
49 .start = 0x00000000,
50 .size = 0x00000000
51 },
42 }, 52 },
43 53
44 [PART_WORK] = { 54 [PART_WORK] = {
@@ -48,7 +58,15 @@ static struct wl1271_partition_set part_table[PART_TABLE_LEN] = {
48 }, 58 },
49 .reg = { 59 .reg = {
50 .start = REGISTERS_BASE, 60 .start = REGISTERS_BASE,
51 .size = 0x0000b000 61 .size = 0x0000a000
62 },
63 .mem2 = {
64 .start = 0x003004f8,
65 .size = 0x00000004
66 },
67 .mem3 = {
68 .start = 0x00040404,
69 .size = 0x00000000
52 }, 70 },
53 }, 71 },
54 72
@@ -60,6 +78,14 @@ static struct wl1271_partition_set part_table[PART_TABLE_LEN] = {
60 .reg = { 78 .reg = {
61 .start = DRPW_BASE, 79 .start = DRPW_BASE,
62 .size = 0x00006000 80 .size = 0x00006000
81 },
82 .mem2 = {
83 .start = 0x00000000,
84 .size = 0x00000000
85 },
86 .mem3 = {
87 .start = 0x00000000,
88 .size = 0x00000000
63 } 89 }
64 } 90 }
65}; 91};
@@ -69,19 +95,19 @@ static void wl1271_boot_set_ecpu_ctrl(struct wl1271 *wl, u32 flag)
69 u32 cpu_ctrl; 95 u32 cpu_ctrl;
70 96
71 /* 10.5.0 run the firmware (I) */ 97 /* 10.5.0 run the firmware (I) */
72 cpu_ctrl = wl1271_reg_read32(wl, ACX_REG_ECPU_CONTROL); 98 cpu_ctrl = wl1271_read32(wl, ACX_REG_ECPU_CONTROL);
73 99
74 /* 10.5.1 run the firmware (II) */ 100 /* 10.5.1 run the firmware (II) */
75 cpu_ctrl |= flag; 101 cpu_ctrl |= flag;
76 wl1271_reg_write32(wl, ACX_REG_ECPU_CONTROL, cpu_ctrl); 102 wl1271_write32(wl, ACX_REG_ECPU_CONTROL, cpu_ctrl);
77} 103}
78 104
79static void wl1271_boot_fw_version(struct wl1271 *wl) 105static void wl1271_boot_fw_version(struct wl1271 *wl)
80{ 106{
81 struct wl1271_static_data static_data; 107 struct wl1271_static_data static_data;
82 108
83 wl1271_spi_mem_read(wl, wl->cmd_box_addr, 109 wl1271_read(wl, wl->cmd_box_addr, &static_data, sizeof(static_data),
84 &static_data, sizeof(static_data)); 110 false);
85 111
86 strncpy(wl->chip.fw_ver, static_data.fw_version, 112 strncpy(wl->chip.fw_ver, static_data.fw_version,
87 sizeof(wl->chip.fw_ver)); 113 sizeof(wl->chip.fw_ver));
@@ -93,8 +119,9 @@ static void wl1271_boot_fw_version(struct wl1271 *wl)
93static int wl1271_boot_upload_firmware_chunk(struct wl1271 *wl, void *buf, 119static int wl1271_boot_upload_firmware_chunk(struct wl1271 *wl, void *buf,
94 size_t fw_data_len, u32 dest) 120 size_t fw_data_len, u32 dest)
95{ 121{
122 struct wl1271_partition_set partition;
96 int addr, chunk_num, partition_limit; 123 int addr, chunk_num, partition_limit;
97 u8 *p; 124 u8 *p, *chunk;
98 125
99 /* whal_FwCtrl_LoadFwImageSm() */ 126 /* whal_FwCtrl_LoadFwImageSm() */
100 127
@@ -103,16 +130,20 @@ static int wl1271_boot_upload_firmware_chunk(struct wl1271 *wl, void *buf,
103 wl1271_debug(DEBUG_BOOT, "fw_data_len %zd chunk_size %d", 130 wl1271_debug(DEBUG_BOOT, "fw_data_len %zd chunk_size %d",
104 fw_data_len, CHUNK_SIZE); 131 fw_data_len, CHUNK_SIZE);
105 132
106
107 if ((fw_data_len % 4) != 0) { 133 if ((fw_data_len % 4) != 0) {
108 wl1271_error("firmware length not multiple of four"); 134 wl1271_error("firmware length not multiple of four");
109 return -EIO; 135 return -EIO;
110 } 136 }
111 137
112 wl1271_set_partition(wl, dest, 138 chunk = kmalloc(CHUNK_SIZE, GFP_KERNEL);
113 part_table[PART_DOWN].mem.size, 139 if (!chunk) {
114 part_table[PART_DOWN].reg.start, 140 wl1271_error("allocation for firmware upload chunk failed");
115 part_table[PART_DOWN].reg.size); 141 return -ENOMEM;
142 }
143
144 memcpy(&partition, &part_table[PART_DOWN], sizeof(partition));
145 partition.mem.start = dest;
146 wl1271_set_partition(wl, &partition);
116 147
117 /* 10.1 set partition limit and chunk num */ 148 /* 10.1 set partition limit and chunk num */
118 chunk_num = 0; 149 chunk_num = 0;
@@ -125,21 +156,17 @@ static int wl1271_boot_upload_firmware_chunk(struct wl1271 *wl, void *buf,
125 addr = dest + chunk_num * CHUNK_SIZE; 156 addr = dest + chunk_num * CHUNK_SIZE;
126 partition_limit = chunk_num * CHUNK_SIZE + 157 partition_limit = chunk_num * CHUNK_SIZE +
127 part_table[PART_DOWN].mem.size; 158 part_table[PART_DOWN].mem.size;
128 159 partition.mem.start = addr;
129 /* FIXME: Over 80 chars! */ 160 wl1271_set_partition(wl, &partition);
130 wl1271_set_partition(wl,
131 addr,
132 part_table[PART_DOWN].mem.size,
133 part_table[PART_DOWN].reg.start,
134 part_table[PART_DOWN].reg.size);
135 } 161 }
136 162
137 /* 10.3 upload the chunk */ 163 /* 10.3 upload the chunk */
138 addr = dest + chunk_num * CHUNK_SIZE; 164 addr = dest + chunk_num * CHUNK_SIZE;
139 p = buf + chunk_num * CHUNK_SIZE; 165 p = buf + chunk_num * CHUNK_SIZE;
166 memcpy(chunk, p, CHUNK_SIZE);
140 wl1271_debug(DEBUG_BOOT, "uploading fw chunk 0x%p to 0x%x", 167 wl1271_debug(DEBUG_BOOT, "uploading fw chunk 0x%p to 0x%x",
141 p, addr); 168 p, addr);
142 wl1271_spi_mem_write(wl, addr, p, CHUNK_SIZE); 169 wl1271_write(wl, addr, chunk, CHUNK_SIZE, false);
143 170
144 chunk_num++; 171 chunk_num++;
145 } 172 }
@@ -147,28 +174,31 @@ static int wl1271_boot_upload_firmware_chunk(struct wl1271 *wl, void *buf,
147 /* 10.4 upload the last chunk */ 174 /* 10.4 upload the last chunk */
148 addr = dest + chunk_num * CHUNK_SIZE; 175 addr = dest + chunk_num * CHUNK_SIZE;
149 p = buf + chunk_num * CHUNK_SIZE; 176 p = buf + chunk_num * CHUNK_SIZE;
177 memcpy(chunk, p, fw_data_len % CHUNK_SIZE);
150 wl1271_debug(DEBUG_BOOT, "uploading fw last chunk (%zd B) 0x%p to 0x%x", 178 wl1271_debug(DEBUG_BOOT, "uploading fw last chunk (%zd B) 0x%p to 0x%x",
151 fw_data_len % CHUNK_SIZE, p, addr); 179 fw_data_len % CHUNK_SIZE, p, addr);
152 wl1271_spi_mem_write(wl, addr, p, fw_data_len % CHUNK_SIZE); 180 wl1271_write(wl, addr, chunk, fw_data_len % CHUNK_SIZE, false);
153 181
182 kfree(chunk);
154 return 0; 183 return 0;
155} 184}
156 185
157static int wl1271_boot_upload_firmware(struct wl1271 *wl) 186static int wl1271_boot_upload_firmware(struct wl1271 *wl)
158{ 187{
159 u32 chunks, addr, len; 188 u32 chunks, addr, len;
189 int ret = 0;
160 u8 *fw; 190 u8 *fw;
161 191
162 fw = wl->fw; 192 fw = wl->fw;
163 chunks = be32_to_cpup((u32 *) fw); 193 chunks = be32_to_cpup((__be32 *) fw);
164 fw += sizeof(u32); 194 fw += sizeof(u32);
165 195
166 wl1271_debug(DEBUG_BOOT, "firmware chunks to be uploaded: %u", chunks); 196 wl1271_debug(DEBUG_BOOT, "firmware chunks to be uploaded: %u", chunks);
167 197
168 while (chunks--) { 198 while (chunks--) {
169 addr = be32_to_cpup((u32 *) fw); 199 addr = be32_to_cpup((__be32 *) fw);
170 fw += sizeof(u32); 200 fw += sizeof(u32);
171 len = be32_to_cpup((u32 *) fw); 201 len = be32_to_cpup((__be32 *) fw);
172 fw += sizeof(u32); 202 fw += sizeof(u32);
173 203
174 if (len > 300000) { 204 if (len > 300000) {
@@ -177,11 +207,13 @@ static int wl1271_boot_upload_firmware(struct wl1271 *wl)
177 } 207 }
178 wl1271_debug(DEBUG_BOOT, "chunk %d addr 0x%x len %u", 208 wl1271_debug(DEBUG_BOOT, "chunk %d addr 0x%x len %u",
179 chunks, addr, len); 209 chunks, addr, len);
180 wl1271_boot_upload_firmware_chunk(wl, fw, len, addr); 210 ret = wl1271_boot_upload_firmware_chunk(wl, fw, len, addr);
211 if (ret != 0)
212 break;
181 fw += len; 213 fw += len;
182 } 214 }
183 215
184 return 0; 216 return ret;
185} 217}
186 218
187static int wl1271_boot_upload_nvs(struct wl1271 *wl) 219static int wl1271_boot_upload_nvs(struct wl1271 *wl)
@@ -189,23 +221,14 @@ static int wl1271_boot_upload_nvs(struct wl1271 *wl)
189 size_t nvs_len, burst_len; 221 size_t nvs_len, burst_len;
190 int i; 222 int i;
191 u32 dest_addr, val; 223 u32 dest_addr, val;
192 u8 *nvs_ptr, *nvs, *nvs_aligned; 224 u8 *nvs_ptr, *nvs_aligned;
193 225
194 nvs = wl->nvs; 226 if (wl->nvs == NULL)
195 if (nvs == NULL)
196 return -ENODEV; 227 return -ENODEV;
197 228
198 nvs_ptr = nvs; 229 /* only the first part of the NVS needs to be uploaded */
199 230 nvs_len = sizeof(wl->nvs->nvs);
200 nvs_len = wl->nvs_len; 231 nvs_ptr = (u8 *)wl->nvs->nvs;
201
202 /* Update the device MAC address into the nvs */
203 nvs[11] = wl->mac_addr[0];
204 nvs[10] = wl->mac_addr[1];
205 nvs[6] = wl->mac_addr[2];
206 nvs[5] = wl->mac_addr[3];
207 nvs[4] = wl->mac_addr[4];
208 nvs[3] = wl->mac_addr[5];
209 232
210 /* 233 /*
211 * Layout before the actual NVS tables: 234 * Layout before the actual NVS tables:
@@ -235,7 +258,7 @@ static int wl1271_boot_upload_nvs(struct wl1271 *wl)
235 wl1271_debug(DEBUG_BOOT, 258 wl1271_debug(DEBUG_BOOT,
236 "nvs burst write 0x%x: 0x%x", 259 "nvs burst write 0x%x: 0x%x",
237 dest_addr, val); 260 dest_addr, val);
238 wl1271_reg_write32(wl, dest_addr, val); 261 wl1271_write32(wl, dest_addr, val);
239 262
240 nvs_ptr += 4; 263 nvs_ptr += 4;
241 dest_addr += 4; 264 dest_addr += 4;
@@ -247,26 +270,29 @@ static int wl1271_boot_upload_nvs(struct wl1271 *wl)
247 * is 7 bytes further. 270 * is 7 bytes further.
248 */ 271 */
249 nvs_ptr += 7; 272 nvs_ptr += 7;
250 nvs_len -= nvs_ptr - nvs; 273 nvs_len -= nvs_ptr - (u8 *)wl->nvs->nvs;
251 nvs_len = ALIGN(nvs_len, 4); 274 nvs_len = ALIGN(nvs_len, 4);
252 275
253 /* FIXME: The driver sets the partition here, but this is not needed, 276 /* FIXME: The driver sets the partition here, but this is not needed,
254 since it sets to the same one as currently in use */ 277 since it sets to the same one as currently in use */
255 /* Now we must set the partition correctly */ 278 /* Now we must set the partition correctly */
256 wl1271_set_partition(wl, 279 wl1271_set_partition(wl, &part_table[PART_WORK]);
257 part_table[PART_WORK].mem.start,
258 part_table[PART_WORK].mem.size,
259 part_table[PART_WORK].reg.start,
260 part_table[PART_WORK].reg.size);
261 280
262 /* Copy the NVS tables to a new block to ensure alignment */ 281 /* Copy the NVS tables to a new block to ensure alignment */
263 nvs_aligned = kmemdup(nvs_ptr, nvs_len, GFP_KERNEL); 282 /* FIXME: We jump 3 more bytes before uploading the NVS. It seems
283 that our NVS files have three extra zeros here. I'm not sure whether
284 the problem is in our NVS generation or we should really jumpt these
285 3 bytes here */
286 nvs_ptr += 3;
287
288 nvs_aligned = kmemdup(nvs_ptr, nvs_len, GFP_KERNEL); if
289 (!nvs_aligned) return -ENOMEM;
264 290
265 /* And finally we upload the NVS tables */ 291 /* And finally we upload the NVS tables */
266 /* FIXME: In wl1271, we upload everything at once. 292 /* FIXME: In wl1271, we upload everything at once.
267 No endianness handling needed here?! The ref driver doesn't do 293 No endianness handling needed here?! The ref driver doesn't do
268 anything about it at this point */ 294 anything about it at this point */
269 wl1271_spi_mem_write(wl, CMD_MBOX_ADDRESS, nvs_aligned, nvs_len); 295 wl1271_write(wl, CMD_MBOX_ADDRESS, nvs_aligned, nvs_len, false);
270 296
271 kfree(nvs_aligned); 297 kfree(nvs_aligned);
272 return 0; 298 return 0;
@@ -275,9 +301,9 @@ static int wl1271_boot_upload_nvs(struct wl1271 *wl)
275static void wl1271_boot_enable_interrupts(struct wl1271 *wl) 301static void wl1271_boot_enable_interrupts(struct wl1271 *wl)
276{ 302{
277 enable_irq(wl->irq); 303 enable_irq(wl->irq);
278 wl1271_reg_write32(wl, ACX_REG_INTERRUPT_MASK, 304 wl1271_write32(wl, ACX_REG_INTERRUPT_MASK,
279 WL1271_ACX_INTR_ALL & ~(WL1271_INTR_MASK)); 305 WL1271_ACX_INTR_ALL & ~(WL1271_INTR_MASK));
280 wl1271_reg_write32(wl, HI_CFG, HI_CFG_DEF_VAL); 306 wl1271_write32(wl, HI_CFG, HI_CFG_DEF_VAL);
281} 307}
282 308
283static int wl1271_boot_soft_reset(struct wl1271 *wl) 309static int wl1271_boot_soft_reset(struct wl1271 *wl)
@@ -286,12 +312,12 @@ static int wl1271_boot_soft_reset(struct wl1271 *wl)
286 u32 boot_data; 312 u32 boot_data;
287 313
288 /* perform soft reset */ 314 /* perform soft reset */
289 wl1271_reg_write32(wl, ACX_REG_SLV_SOFT_RESET, ACX_SLV_SOFT_RESET_BIT); 315 wl1271_write32(wl, ACX_REG_SLV_SOFT_RESET, ACX_SLV_SOFT_RESET_BIT);
290 316
291 /* SOFT_RESET is self clearing */ 317 /* SOFT_RESET is self clearing */
292 timeout = jiffies + usecs_to_jiffies(SOFT_RESET_MAX_TIME); 318 timeout = jiffies + usecs_to_jiffies(SOFT_RESET_MAX_TIME);
293 while (1) { 319 while (1) {
294 boot_data = wl1271_reg_read32(wl, ACX_REG_SLV_SOFT_RESET); 320 boot_data = wl1271_read32(wl, ACX_REG_SLV_SOFT_RESET);
295 wl1271_debug(DEBUG_BOOT, "soft reset bootdata 0x%x", boot_data); 321 wl1271_debug(DEBUG_BOOT, "soft reset bootdata 0x%x", boot_data);
296 if ((boot_data & ACX_SLV_SOFT_RESET_BIT) == 0) 322 if ((boot_data & ACX_SLV_SOFT_RESET_BIT) == 0)
297 break; 323 break;
@@ -307,10 +333,10 @@ static int wl1271_boot_soft_reset(struct wl1271 *wl)
307 } 333 }
308 334
309 /* disable Rx/Tx */ 335 /* disable Rx/Tx */
310 wl1271_reg_write32(wl, ENABLE, 0x0); 336 wl1271_write32(wl, ENABLE, 0x0);
311 337
312 /* disable auto calibration on start*/ 338 /* disable auto calibration on start*/
313 wl1271_reg_write32(wl, SPARE_A2, 0xffff); 339 wl1271_write32(wl, SPARE_A2, 0xffff);
314 340
315 return 0; 341 return 0;
316} 342}
@@ -322,7 +348,7 @@ static int wl1271_boot_run_firmware(struct wl1271 *wl)
322 348
323 wl1271_boot_set_ecpu_ctrl(wl, ECPU_CONTROL_HALT); 349 wl1271_boot_set_ecpu_ctrl(wl, ECPU_CONTROL_HALT);
324 350
325 chip_id = wl1271_reg_read32(wl, CHIP_ID_B); 351 chip_id = wl1271_read32(wl, CHIP_ID_B);
326 352
327 wl1271_debug(DEBUG_BOOT, "chip id after firmware boot: 0x%x", chip_id); 353 wl1271_debug(DEBUG_BOOT, "chip id after firmware boot: 0x%x", chip_id);
328 354
@@ -335,7 +361,7 @@ static int wl1271_boot_run_firmware(struct wl1271 *wl)
335 loop = 0; 361 loop = 0;
336 while (loop++ < INIT_LOOP) { 362 while (loop++ < INIT_LOOP) {
337 udelay(INIT_LOOP_DELAY); 363 udelay(INIT_LOOP_DELAY);
338 interrupt = wl1271_reg_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR); 364 interrupt = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
339 365
340 if (interrupt == 0xffffffff) { 366 if (interrupt == 0xffffffff) {
341 wl1271_error("error reading hardware complete " 367 wl1271_error("error reading hardware complete "
@@ -344,30 +370,26 @@ static int wl1271_boot_run_firmware(struct wl1271 *wl)
344 } 370 }
345 /* check that ACX_INTR_INIT_COMPLETE is enabled */ 371 /* check that ACX_INTR_INIT_COMPLETE is enabled */
346 else if (interrupt & WL1271_ACX_INTR_INIT_COMPLETE) { 372 else if (interrupt & WL1271_ACX_INTR_INIT_COMPLETE) {
347 wl1271_reg_write32(wl, ACX_REG_INTERRUPT_ACK, 373 wl1271_write32(wl, ACX_REG_INTERRUPT_ACK,
348 WL1271_ACX_INTR_INIT_COMPLETE); 374 WL1271_ACX_INTR_INIT_COMPLETE);
349 break; 375 break;
350 } 376 }
351 } 377 }
352 378
353 if (loop >= INIT_LOOP) { 379 if (loop > INIT_LOOP) {
354 wl1271_error("timeout waiting for the hardware to " 380 wl1271_error("timeout waiting for the hardware to "
355 "complete initialization"); 381 "complete initialization");
356 return -EIO; 382 return -EIO;
357 } 383 }
358 384
359 /* get hardware config command mail box */ 385 /* get hardware config command mail box */
360 wl->cmd_box_addr = wl1271_reg_read32(wl, REG_COMMAND_MAILBOX_PTR); 386 wl->cmd_box_addr = wl1271_read32(wl, REG_COMMAND_MAILBOX_PTR);
361 387
362 /* get hardware config event mail box */ 388 /* get hardware config event mail box */
363 wl->event_box_addr = wl1271_reg_read32(wl, REG_EVENT_MAILBOX_PTR); 389 wl->event_box_addr = wl1271_read32(wl, REG_EVENT_MAILBOX_PTR);
364 390
365 /* set the working partition to its "running" mode offset */ 391 /* set the working partition to its "running" mode offset */
366 wl1271_set_partition(wl, 392 wl1271_set_partition(wl, &part_table[PART_WORK]);
367 part_table[PART_WORK].mem.start,
368 part_table[PART_WORK].mem.size,
369 part_table[PART_WORK].reg.start,
370 part_table[PART_WORK].reg.size);
371 393
372 wl1271_debug(DEBUG_MAILBOX, "cmd_box_addr 0x%x event_box_addr 0x%x", 394 wl1271_debug(DEBUG_MAILBOX, "cmd_box_addr 0x%x event_box_addr 0x%x",
373 wl->cmd_box_addr, wl->event_box_addr); 395 wl->cmd_box_addr, wl->event_box_addr);
@@ -379,11 +401,10 @@ static int wl1271_boot_run_firmware(struct wl1271 *wl)
379 * ready to receive event from the command mailbox 401 * ready to receive event from the command mailbox
380 */ 402 */
381 403
382 /* enable gpio interrupts */ 404 /* unmask required mbox events */
383 wl1271_boot_enable_interrupts(wl); 405 wl->event_mask = BSS_LOSE_EVENT_ID |
384 406 SCAN_COMPLETE_EVENT_ID |
385 /* unmask all mbox events */ 407 PS_REPORT_EVENT_ID;
386 wl->event_mask = 0xffffffff;
387 408
388 ret = wl1271_event_unmask(wl); 409 ret = wl1271_event_unmask(wl);
389 if (ret < 0) { 410 if (ret < 0) {
@@ -399,34 +420,13 @@ static int wl1271_boot_run_firmware(struct wl1271 *wl)
399 420
400static int wl1271_boot_write_irq_polarity(struct wl1271 *wl) 421static int wl1271_boot_write_irq_polarity(struct wl1271 *wl)
401{ 422{
402 u32 polarity, status, i; 423 u32 polarity;
403
404 wl1271_reg_write32(wl, OCP_POR_CTR, OCP_REG_POLARITY);
405 wl1271_reg_write32(wl, OCP_CMD, OCP_CMD_READ);
406
407 /* Wait until the command is complete (ie. bit 18 is set) */
408 for (i = 0; i < OCP_CMD_LOOP; i++) {
409 polarity = wl1271_reg_read32(wl, OCP_DATA_READ);
410 if (polarity & OCP_READY_MASK)
411 break;
412 }
413 if (i == OCP_CMD_LOOP) {
414 wl1271_error("OCP command timeout!");
415 return -EIO;
416 }
417 424
418 status = polarity & OCP_STATUS_MASK; 425 polarity = wl1271_top_reg_read(wl, OCP_REG_POLARITY);
419 if (status != OCP_STATUS_OK) {
420 wl1271_error("OCP command failed (%d)", status);
421 return -EIO;
422 }
423 426
424 /* We use HIGH polarity, so unset the LOW bit */ 427 /* We use HIGH polarity, so unset the LOW bit */
425 polarity &= ~POLARITY_LOW; 428 polarity &= ~POLARITY_LOW;
426 429 wl1271_top_reg_write(wl, OCP_REG_POLARITY, polarity);
427 wl1271_reg_write32(wl, OCP_POR_CTR, OCP_REG_POLARITY);
428 wl1271_reg_write32(wl, OCP_DATA_WRITE, polarity);
429 wl1271_reg_write32(wl, OCP_CMD, OCP_CMD_WRITE);
430 430
431 return 0; 431 return 0;
432} 432}
@@ -436,16 +436,32 @@ int wl1271_boot(struct wl1271 *wl)
436 int ret = 0; 436 int ret = 0;
437 u32 tmp, clk, pause; 437 u32 tmp, clk, pause;
438 438
439 if (REF_CLOCK == 0 || REF_CLOCK == 2) 439 if (REF_CLOCK == 0 || REF_CLOCK == 2 || REF_CLOCK == 4)
440 /* ref clk: 19.2/38.4 */ 440 /* ref clk: 19.2/38.4/38.4-XTAL */
441 clk = 0x3; 441 clk = 0x3;
442 else if (REF_CLOCK == 1 || REF_CLOCK == 3) 442 else if (REF_CLOCK == 1 || REF_CLOCK == 3)
443 /* ref clk: 26/52 */ 443 /* ref clk: 26/52 */
444 clk = 0x5; 444 clk = 0x5;
445 445
446 wl1271_reg_write32(wl, PLL_PARAMETERS, clk); 446 if (REF_CLOCK != 0) {
447 u16 val;
448 /* Set clock type */
449 val = wl1271_top_reg_read(wl, OCP_REG_CLK_TYPE);
450 val &= FREF_CLK_TYPE_BITS;
451 val |= CLK_REQ_PRCM;
452 wl1271_top_reg_write(wl, OCP_REG_CLK_TYPE, val);
453 } else {
454 u16 val;
455 /* Set clock polarity */
456 val = wl1271_top_reg_read(wl, OCP_REG_CLK_POLARITY);
457 val &= FREF_CLK_POLARITY_BITS;
458 val |= CLK_REQ_OUTN_SEL;
459 wl1271_top_reg_write(wl, OCP_REG_CLK_POLARITY, val);
460 }
461
462 wl1271_write32(wl, PLL_PARAMETERS, clk);
447 463
448 pause = wl1271_reg_read32(wl, PLL_PARAMETERS); 464 pause = wl1271_read32(wl, PLL_PARAMETERS);
449 465
450 wl1271_debug(DEBUG_BOOT, "pause1 0x%x", pause); 466 wl1271_debug(DEBUG_BOOT, "pause1 0x%x", pause);
451 467
@@ -454,39 +470,31 @@ int wl1271_boot(struct wl1271 *wl)
454 * 0x3ff (magic number ). How does 470 * 0x3ff (magic number ). How does
455 * this work?! */ 471 * this work?! */
456 pause |= WU_COUNTER_PAUSE_VAL; 472 pause |= WU_COUNTER_PAUSE_VAL;
457 wl1271_reg_write32(wl, WU_COUNTER_PAUSE, pause); 473 wl1271_write32(wl, WU_COUNTER_PAUSE, pause);
458 474
459 /* Continue the ELP wake up sequence */ 475 /* Continue the ELP wake up sequence */
460 wl1271_reg_write32(wl, WELP_ARM_COMMAND, WELP_ARM_COMMAND_VAL); 476 wl1271_write32(wl, WELP_ARM_COMMAND, WELP_ARM_COMMAND_VAL);
461 udelay(500); 477 udelay(500);
462 478
463 wl1271_set_partition(wl, 479 wl1271_set_partition(wl, &part_table[PART_DRPW]);
464 part_table[PART_DRPW].mem.start,
465 part_table[PART_DRPW].mem.size,
466 part_table[PART_DRPW].reg.start,
467 part_table[PART_DRPW].reg.size);
468 480
469 /* Read-modify-write DRPW_SCRATCH_START register (see next state) 481 /* Read-modify-write DRPW_SCRATCH_START register (see next state)
470 to be used by DRPw FW. The RTRIM value will be added by the FW 482 to be used by DRPw FW. The RTRIM value will be added by the FW
471 before taking DRPw out of reset */ 483 before taking DRPw out of reset */
472 484
473 wl1271_debug(DEBUG_BOOT, "DRPW_SCRATCH_START %08x", DRPW_SCRATCH_START); 485 wl1271_debug(DEBUG_BOOT, "DRPW_SCRATCH_START %08x", DRPW_SCRATCH_START);
474 clk = wl1271_reg_read32(wl, DRPW_SCRATCH_START); 486 clk = wl1271_read32(wl, DRPW_SCRATCH_START);
475 487
476 wl1271_debug(DEBUG_BOOT, "clk2 0x%x", clk); 488 wl1271_debug(DEBUG_BOOT, "clk2 0x%x", clk);
477 489
478 /* 2 */ 490 /* 2 */
479 clk |= (REF_CLOCK << 1) << 4; 491 clk |= (REF_CLOCK << 1) << 4;
480 wl1271_reg_write32(wl, DRPW_SCRATCH_START, clk); 492 wl1271_write32(wl, DRPW_SCRATCH_START, clk);
481 493
482 wl1271_set_partition(wl, 494 wl1271_set_partition(wl, &part_table[PART_WORK]);
483 part_table[PART_WORK].mem.start,
484 part_table[PART_WORK].mem.size,
485 part_table[PART_WORK].reg.start,
486 part_table[PART_WORK].reg.size);
487 495
488 /* Disable interrupts */ 496 /* Disable interrupts */
489 wl1271_reg_write32(wl, ACX_REG_INTERRUPT_MASK, WL1271_ACX_INTR_ALL); 497 wl1271_write32(wl, ACX_REG_INTERRUPT_MASK, WL1271_ACX_INTR_ALL);
490 498
491 ret = wl1271_boot_soft_reset(wl); 499 ret = wl1271_boot_soft_reset(wl);
492 if (ret < 0) 500 if (ret < 0)
@@ -501,22 +509,22 @@ int wl1271_boot(struct wl1271 *wl)
501 * ACX_EEPROMLESS_IND_REG */ 509 * ACX_EEPROMLESS_IND_REG */
502 wl1271_debug(DEBUG_BOOT, "ACX_EEPROMLESS_IND_REG"); 510 wl1271_debug(DEBUG_BOOT, "ACX_EEPROMLESS_IND_REG");
503 511
504 wl1271_reg_write32(wl, ACX_EEPROMLESS_IND_REG, ACX_EEPROMLESS_IND_REG); 512 wl1271_write32(wl, ACX_EEPROMLESS_IND_REG, ACX_EEPROMLESS_IND_REG);
505 513
506 tmp = wl1271_reg_read32(wl, CHIP_ID_B); 514 tmp = wl1271_read32(wl, CHIP_ID_B);
507 515
508 wl1271_debug(DEBUG_BOOT, "chip id 0x%x", tmp); 516 wl1271_debug(DEBUG_BOOT, "chip id 0x%x", tmp);
509 517
510 /* 6. read the EEPROM parameters */ 518 /* 6. read the EEPROM parameters */
511 tmp = wl1271_reg_read32(wl, SCR_PAD2); 519 tmp = wl1271_read32(wl, SCR_PAD2);
512 520
513 ret = wl1271_boot_write_irq_polarity(wl); 521 ret = wl1271_boot_write_irq_polarity(wl);
514 if (ret < 0) 522 if (ret < 0)
515 goto out; 523 goto out;
516 524
517 /* FIXME: Need to check whether this is really what we want */ 525 /* FIXME: Need to check whether this is really what we want */
518 wl1271_reg_write32(wl, ACX_REG_INTERRUPT_MASK, 526 wl1271_write32(wl, ACX_REG_INTERRUPT_MASK,
519 WL1271_ACX_ALL_EVENTS_VECTOR); 527 WL1271_ACX_ALL_EVENTS_VECTOR);
520 528
521 /* WL1271: The reference driver skips steps 7 to 10 (jumps directly 529 /* WL1271: The reference driver skips steps 7 to 10 (jumps directly
522 * to upload_fw) */ 530 * to upload_fw) */
@@ -530,6 +538,9 @@ int wl1271_boot(struct wl1271 *wl)
530 if (ret < 0) 538 if (ret < 0)
531 goto out; 539 goto out;
532 540
541 /* Enable firmware interrupts now */
542 wl1271_boot_enable_interrupts(wl);
543
533 /* set the wl1271 default filters */ 544 /* set the wl1271 default filters */
534 wl->rx_config = WL1271_DEFAULT_RX_CONFIG; 545 wl->rx_config = WL1271_DEFAULT_RX_CONFIG;
535 wl->rx_filter = WL1271_DEFAULT_RX_FILTER; 546 wl->rx_filter = WL1271_DEFAULT_RX_FILTER;
diff --git a/drivers/net/wireless/wl12xx/wl1271_boot.h b/drivers/net/wireless/wl12xx/wl1271_boot.h
index b0d8fb46a439..412443ee655a 100644
--- a/drivers/net/wireless/wl12xx/wl1271_boot.h
+++ b/drivers/net/wireless/wl12xx/wl1271_boot.h
@@ -50,23 +50,17 @@ struct wl1271_static_data {
50#define WU_COUNTER_PAUSE_VAL 0x3FF 50#define WU_COUNTER_PAUSE_VAL 0x3FF
51#define WELP_ARM_COMMAND_VAL 0x4 51#define WELP_ARM_COMMAND_VAL 0x4
52 52
53#define OCP_CMD_LOOP 32 53#define OCP_REG_POLARITY 0x0064
54 54#define OCP_REG_CLK_TYPE 0x0448
55#define OCP_CMD_WRITE 0x1 55#define OCP_REG_CLK_POLARITY 0x0cb2
56#define OCP_CMD_READ 0x2
57
58#define OCP_READY_MASK BIT(18)
59#define OCP_STATUS_MASK (BIT(16) | BIT(17))
60
61#define OCP_STATUS_NO_RESP 0x00000
62#define OCP_STATUS_OK 0x10000
63#define OCP_STATUS_REQ_FAILED 0x20000
64#define OCP_STATUS_RESP_ERROR 0x30000
65
66#define OCP_REG_POLARITY 0x30032
67 56
68#define CMD_MBOX_ADDRESS 0x407B4 57#define CMD_MBOX_ADDRESS 0x407B4
69 58
70#define POLARITY_LOW BIT(1) 59#define POLARITY_LOW BIT(1)
71 60
61#define FREF_CLK_TYPE_BITS 0xfffffe7f
62#define CLK_REQ_PRCM 0x100
63#define FREF_CLK_POLARITY_BITS 0xfffff8ff
64#define CLK_REQ_OUTN_SEL 0x700
65
72#endif 66#endif
diff --git a/drivers/net/wireless/wl12xx/wl1271_cmd.c b/drivers/net/wireless/wl12xx/wl1271_cmd.c
index 2a4351ff54dc..e7832f3318eb 100644
--- a/drivers/net/wireless/wl12xx/wl1271_cmd.c
+++ b/drivers/net/wireless/wl12xx/wl1271_cmd.c
@@ -26,10 +26,12 @@
26#include <linux/crc7.h> 26#include <linux/crc7.h>
27#include <linux/spi/spi.h> 27#include <linux/spi/spi.h>
28#include <linux/etherdevice.h> 28#include <linux/etherdevice.h>
29#include <linux/slab.h>
29 30
30#include "wl1271.h" 31#include "wl1271.h"
31#include "wl1271_reg.h" 32#include "wl1271_reg.h"
32#include "wl1271_spi.h" 33#include "wl1271_spi.h"
34#include "wl1271_io.h"
33#include "wl1271_acx.h" 35#include "wl1271_acx.h"
34#include "wl12xx_80211.h" 36#include "wl12xx_80211.h"
35#include "wl1271_cmd.h" 37#include "wl1271_cmd.h"
@@ -42,26 +44,28 @@
42 * @buf: buffer containing the command, must work with dma 44 * @buf: buffer containing the command, must work with dma
43 * @len: length of the buffer 45 * @len: length of the buffer
44 */ 46 */
45int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len) 47int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len,
48 size_t res_len)
46{ 49{
47 struct wl1271_cmd_header *cmd; 50 struct wl1271_cmd_header *cmd;
48 unsigned long timeout; 51 unsigned long timeout;
49 u32 intr; 52 u32 intr;
50 int ret = 0; 53 int ret = 0;
54 u16 status;
51 55
52 cmd = buf; 56 cmd = buf;
53 cmd->id = id; 57 cmd->id = cpu_to_le16(id);
54 cmd->status = 0; 58 cmd->status = 0;
55 59
56 WARN_ON(len % 4 != 0); 60 WARN_ON(len % 4 != 0);
57 61
58 wl1271_spi_mem_write(wl, wl->cmd_box_addr, buf, len); 62 wl1271_write(wl, wl->cmd_box_addr, buf, len, false);
59 63
60 wl1271_reg_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_CMD); 64 wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_CMD);
61 65
62 timeout = jiffies + msecs_to_jiffies(WL1271_COMMAND_TIMEOUT); 66 timeout = jiffies + msecs_to_jiffies(WL1271_COMMAND_TIMEOUT);
63 67
64 intr = wl1271_reg_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR); 68 intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
65 while (!(intr & WL1271_ACX_INTR_CMD_COMPLETE)) { 69 while (!(intr & WL1271_ACX_INTR_CMD_COMPLETE)) {
66 if (time_after(jiffies, timeout)) { 70 if (time_after(jiffies, timeout)) {
67 wl1271_error("command complete timeout"); 71 wl1271_error("command complete timeout");
@@ -71,17 +75,28 @@ int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len)
71 75
72 msleep(1); 76 msleep(1);
73 77
74 intr = wl1271_reg_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR); 78 intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
75 } 79 }
76 80
77 wl1271_reg_write32(wl, ACX_REG_INTERRUPT_ACK, 81 /* read back the status code of the command */
78 WL1271_ACX_INTR_CMD_COMPLETE); 82 if (res_len == 0)
83 res_len = sizeof(struct wl1271_cmd_header);
84 wl1271_read(wl, wl->cmd_box_addr, cmd, res_len, false);
85
86 status = le16_to_cpu(cmd->status);
87 if (status != CMD_STATUS_SUCCESS) {
88 wl1271_error("command execute failure %d", status);
89 ret = -EIO;
90 }
91
92 wl1271_write32(wl, ACX_REG_INTERRUPT_ACK,
93 WL1271_ACX_INTR_CMD_COMPLETE);
79 94
80out: 95out:
81 return ret; 96 return ret;
82} 97}
83 98
84int wl1271_cmd_cal_channel_tune(struct wl1271 *wl) 99static int wl1271_cmd_cal_channel_tune(struct wl1271 *wl)
85{ 100{
86 struct wl1271_cmd_cal_channel_tune *cmd; 101 struct wl1271_cmd_cal_channel_tune *cmd;
87 int ret = 0; 102 int ret = 0;
@@ -104,7 +119,7 @@ int wl1271_cmd_cal_channel_tune(struct wl1271 *wl)
104 return ret; 119 return ret;
105} 120}
106 121
107int wl1271_cmd_cal_update_ref_point(struct wl1271 *wl) 122static int wl1271_cmd_cal_update_ref_point(struct wl1271 *wl)
108{ 123{
109 struct wl1271_cmd_cal_update_ref_point *cmd; 124 struct wl1271_cmd_cal_update_ref_point *cmd;
110 int ret = 0; 125 int ret = 0;
@@ -129,7 +144,7 @@ int wl1271_cmd_cal_update_ref_point(struct wl1271 *wl)
129 return ret; 144 return ret;
130} 145}
131 146
132int wl1271_cmd_cal_p2g(struct wl1271 *wl) 147static int wl1271_cmd_cal_p2g(struct wl1271 *wl)
133{ 148{
134 struct wl1271_cmd_cal_p2g *cmd; 149 struct wl1271_cmd_cal_p2g *cmd;
135 int ret = 0; 150 int ret = 0;
@@ -150,7 +165,7 @@ int wl1271_cmd_cal_p2g(struct wl1271 *wl)
150 return ret; 165 return ret;
151} 166}
152 167
153int wl1271_cmd_cal(struct wl1271 *wl) 168static int wl1271_cmd_cal(struct wl1271 *wl)
154{ 169{
155 /* 170 /*
156 * FIXME: we must make sure that we're not sleeping when calibration 171 * FIXME: we must make sure that we're not sleeping when calibration
@@ -175,11 +190,68 @@ int wl1271_cmd_cal(struct wl1271 *wl)
175 return ret; 190 return ret;
176} 191}
177 192
178int wl1271_cmd_join(struct wl1271 *wl, u8 bss_type, u8 dtim_interval, 193int wl1271_cmd_general_parms(struct wl1271 *wl)
179 u16 beacon_interval, u8 wait) 194{
195 struct wl1271_general_parms_cmd *gen_parms;
196 int ret;
197
198 if (!wl->nvs)
199 return -ENODEV;
200
201 gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
202 if (!gen_parms)
203 return -ENOMEM;
204
205 gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM;
206
207 memcpy(gen_parms->params, wl->nvs->general_params,
208 WL1271_NVS_GENERAL_PARAMS_SIZE);
209
210 ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), 0);
211 if (ret < 0)
212 wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
213
214 kfree(gen_parms);
215 return ret;
216}
217
218int wl1271_cmd_radio_parms(struct wl1271 *wl)
219{
220 struct wl1271_radio_parms_cmd *radio_parms;
221 struct conf_radio_parms *rparam = &wl->conf.init.radioparam;
222 int ret;
223
224 if (!wl->nvs)
225 return -ENODEV;
226
227 radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
228 if (!radio_parms)
229 return -ENOMEM;
230
231 radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM;
232
233 memcpy(radio_parms->stat_radio_params, wl->nvs->stat_radio_params,
234 WL1271_NVS_STAT_RADIO_PARAMS_SIZE);
235 memcpy(radio_parms->dyn_radio_params,
236 wl->nvs->dyn_radio_params[rparam->fem],
237 WL1271_NVS_DYN_RADIO_PARAMS_SIZE);
238
239 /* FIXME: current NVS is missing 5GHz parameters */
240
241 wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
242 radio_parms, sizeof(*radio_parms));
243
244 ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
245 if (ret < 0)
246 wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
247
248 kfree(radio_parms);
249 return ret;
250}
251
252int wl1271_cmd_join(struct wl1271 *wl)
180{ 253{
181 static bool do_cal = true; 254 static bool do_cal = true;
182 unsigned long timeout;
183 struct wl1271_cmd_join *join; 255 struct wl1271_cmd_join *join;
184 int ret, i; 256 int ret, i;
185 u8 *bssid; 257 u8 *bssid;
@@ -193,7 +265,6 @@ int wl1271_cmd_join(struct wl1271 *wl, u8 bss_type, u8 dtim_interval,
193 do_cal = false; 265 do_cal = false;
194 } 266 }
195 267
196
197 join = kzalloc(sizeof(*join), GFP_KERNEL); 268 join = kzalloc(sizeof(*join), GFP_KERNEL);
198 if (!join) { 269 if (!join) {
199 ret = -ENOMEM; 270 ret = -ENOMEM;
@@ -207,15 +278,34 @@ int wl1271_cmd_join(struct wl1271 *wl, u8 bss_type, u8 dtim_interval,
207 for (i = 0; i < ETH_ALEN; i++) 278 for (i = 0; i < ETH_ALEN; i++)
208 bssid[i] = wl->bssid[ETH_ALEN - i - 1]; 279 bssid[i] = wl->bssid[ETH_ALEN - i - 1];
209 280
210 join->rx_config_options = wl->rx_config; 281 join->rx_config_options = cpu_to_le32(wl->rx_config);
211 join->rx_filter_options = wl->rx_filter; 282 join->rx_filter_options = cpu_to_le32(wl->rx_filter);
283 join->bss_type = wl->bss_type;
284
285 /*
286 * FIXME: disable temporarily all filters because after commit
287 * 9cef8737 "mac80211: fix managed mode BSSID handling" broke
288 * association. The filter logic needs to be implemented properly
289 * and once that is done, this hack can be removed.
290 */
291 join->rx_config_options = cpu_to_le32(0);
292 join->rx_filter_options = cpu_to_le32(WL1271_DEFAULT_RX_FILTER);
293
294 if (wl->band == IEEE80211_BAND_2GHZ)
295 join->basic_rate_set = cpu_to_le32(CONF_HW_BIT_RATE_1MBPS |
296 CONF_HW_BIT_RATE_2MBPS |
297 CONF_HW_BIT_RATE_5_5MBPS |
298 CONF_HW_BIT_RATE_11MBPS);
299 else {
300 join->bss_type |= WL1271_JOIN_CMD_BSS_TYPE_5GHZ;
301 join->basic_rate_set = cpu_to_le32(CONF_HW_BIT_RATE_6MBPS |
302 CONF_HW_BIT_RATE_12MBPS |
303 CONF_HW_BIT_RATE_24MBPS);
304 }
212 305
213 join->basic_rate_set = RATE_MASK_1MBPS | RATE_MASK_2MBPS | 306 join->beacon_interval = cpu_to_le16(WL1271_DEFAULT_BEACON_INT);
214 RATE_MASK_5_5MBPS | RATE_MASK_11MBPS; 307 join->dtim_interval = WL1271_DEFAULT_DTIM_PERIOD;
215 308
216 join->beacon_interval = beacon_interval;
217 join->dtim_interval = dtim_interval;
218 join->bss_type = bss_type;
219 join->channel = wl->channel; 309 join->channel = wl->channel;
220 join->ssid_len = wl->ssid_len; 310 join->ssid_len = wl->ssid_len;
221 memcpy(join->ssid, wl->ssid, wl->ssid_len); 311 memcpy(join->ssid, wl->ssid, wl->ssid_len);
@@ -228,21 +318,22 @@ int wl1271_cmd_join(struct wl1271 *wl, u8 bss_type, u8 dtim_interval,
228 318
229 join->ctrl |= wl->session_counter << WL1271_JOIN_CMD_TX_SESSION_OFFSET; 319 join->ctrl |= wl->session_counter << WL1271_JOIN_CMD_TX_SESSION_OFFSET;
230 320
321 /* reset TX security counters */
322 wl->tx_security_last_seq = 0;
323 wl->tx_security_seq_16 = 0;
324 wl->tx_security_seq_32 = 0;
231 325
232 ret = wl1271_cmd_send(wl, CMD_START_JOIN, join, sizeof(*join)); 326 ret = wl1271_cmd_send(wl, CMD_START_JOIN, join, sizeof(*join), 0);
233 if (ret < 0) { 327 if (ret < 0) {
234 wl1271_error("failed to initiate cmd join"); 328 wl1271_error("failed to initiate cmd join");
235 goto out_free; 329 goto out_free;
236 } 330 }
237 331
238 timeout = msecs_to_jiffies(JOIN_TIMEOUT);
239
240 /* 332 /*
241 * ugly hack: we should wait for JOIN_EVENT_COMPLETE_ID but to 333 * ugly hack: we should wait for JOIN_EVENT_COMPLETE_ID but to
242 * simplify locking we just sleep instead, for now 334 * simplify locking we just sleep instead, for now
243 */ 335 */
244 if (wait) 336 msleep(10);
245 msleep(10);
246 337
247out_free: 338out_free:
248 kfree(join); 339 kfree(join);
@@ -262,34 +353,21 @@ out:
262int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer) 353int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer)
263{ 354{
264 int ret; 355 int ret;
356 size_t res_len = 0;
265 357
266 wl1271_debug(DEBUG_CMD, "cmd test"); 358 wl1271_debug(DEBUG_CMD, "cmd test");
267 359
268 ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len); 360 if (answer)
361 res_len = buf_len;
362
363 ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len, res_len);
269 364
270 if (ret < 0) { 365 if (ret < 0) {
271 wl1271_warning("TEST command failed"); 366 wl1271_warning("TEST command failed");
272 return ret; 367 return ret;
273 } 368 }
274 369
275 if (answer) { 370 return ret;
276 struct wl1271_command *cmd_answer;
277
278 /*
279 * The test command got in, we can read the answer.
280 * The answer would be a wl1271_command, where the
281 * parameter array contains the actual answer.
282 */
283 wl1271_spi_mem_read(wl, wl->cmd_box_addr, buf, buf_len);
284
285 cmd_answer = buf;
286
287 if (cmd_answer->header.status != CMD_STATUS_SUCCESS)
288 wl1271_error("TEST command answer error: %d",
289 cmd_answer->header.status);
290 }
291
292 return 0;
293} 371}
294 372
295/** 373/**
@@ -307,26 +385,15 @@ int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len)
307 385
308 wl1271_debug(DEBUG_CMD, "cmd interrogate"); 386 wl1271_debug(DEBUG_CMD, "cmd interrogate");
309 387
310 acx->id = id; 388 acx->id = cpu_to_le16(id);
311 389
312 /* payload length, does not include any headers */ 390 /* payload length, does not include any headers */
313 acx->len = len - sizeof(*acx); 391 acx->len = cpu_to_le16(len - sizeof(*acx));
314 392
315 ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx)); 393 ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx), len);
316 if (ret < 0) { 394 if (ret < 0)
317 wl1271_error("INTERROGATE command failed"); 395 wl1271_error("INTERROGATE command failed");
318 goto out;
319 }
320
321 /* the interrogate command got in, we can read the answer */
322 wl1271_spi_mem_read(wl, wl->cmd_box_addr, buf, len);
323
324 acx = buf;
325 if (acx->cmd.status != CMD_STATUS_SUCCESS)
326 wl1271_error("INTERROGATE command error: %d",
327 acx->cmd.status);
328 396
329out:
330 return ret; 397 return ret;
331} 398}
332 399
@@ -345,12 +412,12 @@ int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len)
345 412
346 wl1271_debug(DEBUG_CMD, "cmd configure"); 413 wl1271_debug(DEBUG_CMD, "cmd configure");
347 414
348 acx->id = id; 415 acx->id = cpu_to_le16(id);
349 416
350 /* payload length, does not include any headers */ 417 /* payload length, does not include any headers */
351 acx->len = len - sizeof(*acx); 418 acx->len = cpu_to_le16(len - sizeof(*acx));
352 419
353 ret = wl1271_cmd_send(wl, CMD_CONFIGURE, acx, len); 420 ret = wl1271_cmd_send(wl, CMD_CONFIGURE, acx, len, 0);
354 if (ret < 0) { 421 if (ret < 0) {
355 wl1271_warning("CONFIGURE command NOK"); 422 wl1271_warning("CONFIGURE command NOK");
356 return ret; 423 return ret;
@@ -359,7 +426,7 @@ int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len)
359 return 0; 426 return 0;
360} 427}
361 428
362int wl1271_cmd_data_path(struct wl1271 *wl, u8 channel, bool enable) 429int wl1271_cmd_data_path(struct wl1271 *wl, bool enable)
363{ 430{
364 struct cmd_enabledisable_path *cmd; 431 struct cmd_enabledisable_path *cmd;
365 int ret; 432 int ret;
@@ -373,7 +440,8 @@ int wl1271_cmd_data_path(struct wl1271 *wl, u8 channel, bool enable)
373 goto out; 440 goto out;
374 } 441 }
375 442
376 cmd->channel = channel; 443 /* the channel here is only used for calibration, so hardcoded to 1 */
444 cmd->channel = 1;
377 445
378 if (enable) { 446 if (enable) {
379 cmd_rx = CMD_ENABLE_RX; 447 cmd_rx = CMD_ENABLE_RX;
@@ -383,39 +451,38 @@ int wl1271_cmd_data_path(struct wl1271 *wl, u8 channel, bool enable)
383 cmd_tx = CMD_DISABLE_TX; 451 cmd_tx = CMD_DISABLE_TX;
384 } 452 }
385 453
386 ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd)); 454 ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd), 0);
387 if (ret < 0) { 455 if (ret < 0) {
388 wl1271_error("rx %s cmd for channel %d failed", 456 wl1271_error("rx %s cmd for channel %d failed",
389 enable ? "start" : "stop", channel); 457 enable ? "start" : "stop", cmd->channel);
390 goto out; 458 goto out;
391 } 459 }
392 460
393 wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d", 461 wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d",
394 enable ? "start" : "stop", channel); 462 enable ? "start" : "stop", cmd->channel);
395 463
396 ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd)); 464 ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd), 0);
397 if (ret < 0) { 465 if (ret < 0) {
398 wl1271_error("tx %s cmd for channel %d failed", 466 wl1271_error("tx %s cmd for channel %d failed",
399 enable ? "start" : "stop", channel); 467 enable ? "start" : "stop", cmd->channel);
400 return ret; 468 return ret;
401 } 469 }
402 470
403 wl1271_debug(DEBUG_BOOT, "tx %s cmd channel %d", 471 wl1271_debug(DEBUG_BOOT, "tx %s cmd channel %d",
404 enable ? "start" : "stop", channel); 472 enable ? "start" : "stop", cmd->channel);
405 473
406out: 474out:
407 kfree(cmd); 475 kfree(cmd);
408 return ret; 476 return ret;
409} 477}
410 478
411int wl1271_cmd_ps_mode(struct wl1271 *wl, u8 ps_mode) 479int wl1271_cmd_ps_mode(struct wl1271 *wl, u8 ps_mode, bool send)
412{ 480{
413 struct wl1271_cmd_ps_params *ps_params = NULL; 481 struct wl1271_cmd_ps_params *ps_params = NULL;
414 int ret = 0; 482 int ret = 0;
415 483
416 /* FIXME: this should be in ps.c */ 484 /* FIXME: this should be in ps.c */
417 ret = wl1271_acx_wake_up_conditions(wl, WAKE_UP_EVENT_DTIM_BITMAP, 485 ret = wl1271_acx_wake_up_conditions(wl);
418 wl->listen_int);
419 if (ret < 0) { 486 if (ret < 0) {
420 wl1271_error("couldn't set wake up conditions"); 487 wl1271_error("couldn't set wake up conditions");
421 goto out; 488 goto out;
@@ -430,13 +497,13 @@ int wl1271_cmd_ps_mode(struct wl1271 *wl, u8 ps_mode)
430 } 497 }
431 498
432 ps_params->ps_mode = ps_mode; 499 ps_params->ps_mode = ps_mode;
433 ps_params->send_null_data = 1; 500 ps_params->send_null_data = send;
434 ps_params->retries = 5; 501 ps_params->retries = 5;
435 ps_params->hang_over_period = 128; 502 ps_params->hang_over_period = 128;
436 ps_params->null_data_rate = 1; /* 1 Mbps */ 503 ps_params->null_data_rate = cpu_to_le32(1); /* 1 Mbps */
437 504
438 ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params, 505 ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params,
439 sizeof(*ps_params)); 506 sizeof(*ps_params), 0);
440 if (ret < 0) { 507 if (ret < 0) {
441 wl1271_error("cmd set_ps_mode failed"); 508 wl1271_error("cmd set_ps_mode failed");
442 goto out; 509 goto out;
@@ -464,22 +531,17 @@ int wl1271_cmd_read_memory(struct wl1271 *wl, u32 addr, void *answer,
464 WARN_ON(len > MAX_READ_SIZE); 531 WARN_ON(len > MAX_READ_SIZE);
465 len = min_t(size_t, len, MAX_READ_SIZE); 532 len = min_t(size_t, len, MAX_READ_SIZE);
466 533
467 cmd->addr = addr; 534 cmd->addr = cpu_to_le32(addr);
468 cmd->size = len; 535 cmd->size = cpu_to_le32(len);
469 536
470 ret = wl1271_cmd_send(wl, CMD_READ_MEMORY, cmd, sizeof(*cmd)); 537 ret = wl1271_cmd_send(wl, CMD_READ_MEMORY, cmd, sizeof(*cmd),
538 sizeof(*cmd));
471 if (ret < 0) { 539 if (ret < 0) {
472 wl1271_error("read memory command failed: %d", ret); 540 wl1271_error("read memory command failed: %d", ret);
473 goto out; 541 goto out;
474 } 542 }
475 543
476 /* the read command got in, we can now read the answer */ 544 /* the read command got in */
477 wl1271_spi_mem_read(wl, wl->cmd_box_addr, cmd, sizeof(*cmd));
478
479 if (cmd->header.status != CMD_STATUS_SUCCESS)
480 wl1271_error("error in read command result: %d",
481 cmd->header.status);
482
483 memcpy(answer, cmd->value, len); 545 memcpy(answer, cmd->value, len);
484 546
485out: 547out:
@@ -488,16 +550,33 @@ out:
488} 550}
489 551
490int wl1271_cmd_scan(struct wl1271 *wl, u8 *ssid, size_t len, 552int wl1271_cmd_scan(struct wl1271 *wl, u8 *ssid, size_t len,
491 u8 active_scan, u8 high_prio, u8 num_channels, 553 u8 active_scan, u8 high_prio, u8 band,
492 u8 probe_requests) 554 u8 probe_requests)
493{ 555{
494 556
495 struct wl1271_cmd_trigger_scan_to *trigger = NULL; 557 struct wl1271_cmd_trigger_scan_to *trigger = NULL;
496 struct wl1271_cmd_scan *params = NULL; 558 struct wl1271_cmd_scan *params = NULL;
497 int i, ret; 559 struct ieee80211_channel *channels;
560 int i, j, n_ch, ret;
498 u16 scan_options = 0; 561 u16 scan_options = 0;
562 u8 ieee_band;
563
564 if (band == WL1271_SCAN_BAND_2_4_GHZ)
565 ieee_band = IEEE80211_BAND_2GHZ;
566 else if (band == WL1271_SCAN_BAND_DUAL && wl1271_11a_enabled())
567 ieee_band = IEEE80211_BAND_2GHZ;
568 else if (band == WL1271_SCAN_BAND_5_GHZ && wl1271_11a_enabled())
569 ieee_band = IEEE80211_BAND_5GHZ;
570 else
571 return -EINVAL;
572
573 if (wl->hw->wiphy->bands[ieee_band]->channels == NULL)
574 return -EINVAL;
499 575
500 if (wl->scanning) 576 channels = wl->hw->wiphy->bands[ieee_band]->channels;
577 n_ch = wl->hw->wiphy->bands[ieee_band]->n_channels;
578
579 if (test_bit(WL1271_FLAG_SCANNING, &wl->flags))
501 return -EINVAL; 580 return -EINVAL;
502 581
503 params = kzalloc(sizeof(*params), GFP_KERNEL); 582 params = kzalloc(sizeof(*params), GFP_KERNEL);
@@ -512,32 +591,43 @@ int wl1271_cmd_scan(struct wl1271 *wl, u8 *ssid, size_t len,
512 scan_options |= WL1271_SCAN_OPT_PASSIVE; 591 scan_options |= WL1271_SCAN_OPT_PASSIVE;
513 if (high_prio) 592 if (high_prio)
514 scan_options |= WL1271_SCAN_OPT_PRIORITY_HIGH; 593 scan_options |= WL1271_SCAN_OPT_PRIORITY_HIGH;
515 params->params.scan_options = scan_options; 594 params->params.scan_options = cpu_to_le16(scan_options);
516 595
517 params->params.num_channels = num_channels;
518 params->params.num_probe_requests = probe_requests; 596 params->params.num_probe_requests = probe_requests;
519 params->params.tx_rate = cpu_to_le32(RATE_MASK_2MBPS); 597 /* Let the fw autodetect suitable tx_rate for probes */
598 params->params.tx_rate = 0;
520 params->params.tid_trigger = 0; 599 params->params.tid_trigger = 0;
521 params->params.scan_tag = WL1271_SCAN_DEFAULT_TAG; 600 params->params.scan_tag = WL1271_SCAN_DEFAULT_TAG;
522 601
523 for (i = 0; i < num_channels; i++) { 602 if (band == WL1271_SCAN_BAND_DUAL)
524 params->channels[i].min_duration = 603 params->params.band = WL1271_SCAN_BAND_2_4_GHZ;
525 cpu_to_le32(WL1271_SCAN_CHAN_MIN_DURATION); 604 else
526 params->channels[i].max_duration = 605 params->params.band = band;
527 cpu_to_le32(WL1271_SCAN_CHAN_MAX_DURATION); 606
528 memset(&params->channels[i].bssid_lsb, 0xff, 4); 607 for (i = 0, j = 0; i < n_ch && i < WL1271_SCAN_MAX_CHANNELS; i++) {
529 memset(&params->channels[i].bssid_msb, 0xff, 2); 608 if (!(channels[i].flags & IEEE80211_CHAN_DISABLED)) {
530 params->channels[i].early_termination = 0; 609 params->channels[j].min_duration =
531 params->channels[i].tx_power_att = WL1271_SCAN_CURRENT_TX_PWR; 610 cpu_to_le32(WL1271_SCAN_CHAN_MIN_DURATION);
532 params->channels[i].channel = i + 1; 611 params->channels[j].max_duration =
612 cpu_to_le32(WL1271_SCAN_CHAN_MAX_DURATION);
613 memset(&params->channels[j].bssid_lsb, 0xff, 4);
614 memset(&params->channels[j].bssid_msb, 0xff, 2);
615 params->channels[j].early_termination = 0;
616 params->channels[j].tx_power_att =
617 WL1271_SCAN_CURRENT_TX_PWR;
618 params->channels[j].channel = channels[i].hw_value;
619 j++;
620 }
533 } 621 }
534 622
623 params->params.num_channels = j;
624
535 if (len && ssid) { 625 if (len && ssid) {
536 params->params.ssid_len = len; 626 params->params.ssid_len = len;
537 memcpy(params->params.ssid, ssid, len); 627 memcpy(params->params.ssid, ssid, len);
538 } 628 }
539 629
540 ret = wl1271_cmd_build_probe_req(wl, ssid, len); 630 ret = wl1271_cmd_build_probe_req(wl, ssid, len, ieee_band);
541 if (ret < 0) { 631 if (ret < 0) {
542 wl1271_error("PROBE request template failed"); 632 wl1271_error("PROBE request template failed");
543 goto out; 633 goto out;
@@ -553,7 +643,7 @@ int wl1271_cmd_scan(struct wl1271 *wl, u8 *ssid, size_t len,
553 trigger->timeout = 0; 643 trigger->timeout = 0;
554 644
555 ret = wl1271_cmd_send(wl, CMD_TRIGGER_SCAN_TO, trigger, 645 ret = wl1271_cmd_send(wl, CMD_TRIGGER_SCAN_TO, trigger,
556 sizeof(*trigger)); 646 sizeof(*trigger), 0);
557 if (ret < 0) { 647 if (ret < 0) {
558 wl1271_error("trigger scan to failed for hw scan"); 648 wl1271_error("trigger scan to failed for hw scan");
559 goto out; 649 goto out;
@@ -561,21 +651,25 @@ int wl1271_cmd_scan(struct wl1271 *wl, u8 *ssid, size_t len,
561 651
562 wl1271_dump(DEBUG_SCAN, "SCAN: ", params, sizeof(*params)); 652 wl1271_dump(DEBUG_SCAN, "SCAN: ", params, sizeof(*params));
563 653
564 wl->scanning = true; 654 set_bit(WL1271_FLAG_SCANNING, &wl->flags);
655 if (wl1271_11a_enabled()) {
656 wl->scan.state = band;
657 if (band == WL1271_SCAN_BAND_DUAL) {
658 wl->scan.active = active_scan;
659 wl->scan.high_prio = high_prio;
660 wl->scan.probe_requests = probe_requests;
661 if (len && ssid) {
662 wl->scan.ssid_len = len;
663 memcpy(wl->scan.ssid, ssid, len);
664 } else
665 wl->scan.ssid_len = 0;
666 }
667 }
565 668
566 ret = wl1271_cmd_send(wl, CMD_SCAN, params, sizeof(*params)); 669 ret = wl1271_cmd_send(wl, CMD_SCAN, params, sizeof(*params), 0);
567 if (ret < 0) { 670 if (ret < 0) {
568 wl1271_error("SCAN failed"); 671 wl1271_error("SCAN failed");
569 goto out; 672 clear_bit(WL1271_FLAG_SCANNING, &wl->flags);
570 }
571
572 wl1271_spi_mem_read(wl, wl->cmd_box_addr, params, sizeof(*params));
573
574 if (params->header.status != CMD_STATUS_SUCCESS) {
575 wl1271_error("Scan command error: %d",
576 params->header.status);
577 wl->scanning = false;
578 ret = -EIO;
579 goto out; 673 goto out;
580 } 674 }
581 675
@@ -603,14 +697,14 @@ int wl1271_cmd_template_set(struct wl1271 *wl, u16 template_id,
603 697
604 cmd->len = cpu_to_le16(buf_len); 698 cmd->len = cpu_to_le16(buf_len);
605 cmd->template_type = template_id; 699 cmd->template_type = template_id;
606 cmd->enabled_rates = ACX_RATE_MASK_UNSPECIFIED; 700 cmd->enabled_rates = cpu_to_le32(wl->conf.tx.rc_conf.enabled_rates);
607 cmd->short_retry_limit = ACX_RATE_RETRY_LIMIT; 701 cmd->short_retry_limit = wl->conf.tx.rc_conf.short_retry_limit;
608 cmd->long_retry_limit = ACX_RATE_RETRY_LIMIT; 702 cmd->long_retry_limit = wl->conf.tx.rc_conf.long_retry_limit;
609 703
610 if (buf) 704 if (buf)
611 memcpy(cmd->template_data, buf, buf_len); 705 memcpy(cmd->template_data, buf, buf_len);
612 706
613 ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd)); 707 ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd), 0);
614 if (ret < 0) { 708 if (ret < 0) {
615 wl1271_warning("cmd set_template failed: %d", ret); 709 wl1271_warning("cmd set_template failed: %d", ret);
616 goto out_free; 710 goto out_free;
@@ -623,30 +717,62 @@ out:
623 return ret; 717 return ret;
624} 718}
625 719
626static int wl1271_build_basic_rates(char *rates) 720static int wl1271_build_basic_rates(u8 *rates, u8 band)
627{ 721{
628 u8 index = 0; 722 u8 index = 0;
629 723
630 rates[index++] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB; 724 if (band == IEEE80211_BAND_2GHZ) {
631 rates[index++] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB; 725 rates[index++] =
632 rates[index++] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_5MB; 726 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
633 rates[index++] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_11MB; 727 rates[index++] =
728 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
729 rates[index++] =
730 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_5MB;
731 rates[index++] =
732 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_11MB;
733 } else if (band == IEEE80211_BAND_5GHZ) {
734 rates[index++] =
735 IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_6MB;
736 rates[index++] =
737 IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_12MB;
738 rates[index++] =
739 IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_24MB;
740 } else {
741 wl1271_error("build_basic_rates invalid band: %d", band);
742 }
634 743
635 return index; 744 return index;
636} 745}
637 746
638static int wl1271_build_extended_rates(char *rates) 747static int wl1271_build_extended_rates(u8 *rates, u8 band)
639{ 748{
640 u8 index = 0; 749 u8 index = 0;
641 750
642 rates[index++] = IEEE80211_OFDM_RATE_6MB; 751 if (band == IEEE80211_BAND_2GHZ) {
643 rates[index++] = IEEE80211_OFDM_RATE_9MB; 752 rates[index++] = IEEE80211_OFDM_RATE_6MB;
644 rates[index++] = IEEE80211_OFDM_RATE_12MB; 753 rates[index++] = IEEE80211_OFDM_RATE_9MB;
645 rates[index++] = IEEE80211_OFDM_RATE_18MB; 754 rates[index++] = IEEE80211_OFDM_RATE_12MB;
646 rates[index++] = IEEE80211_OFDM_RATE_24MB; 755 rates[index++] = IEEE80211_OFDM_RATE_18MB;
647 rates[index++] = IEEE80211_OFDM_RATE_36MB; 756 rates[index++] = IEEE80211_OFDM_RATE_24MB;
648 rates[index++] = IEEE80211_OFDM_RATE_48MB; 757 rates[index++] = IEEE80211_OFDM_RATE_36MB;
649 rates[index++] = IEEE80211_OFDM_RATE_54MB; 758 rates[index++] = IEEE80211_OFDM_RATE_48MB;
759 rates[index++] = IEEE80211_OFDM_RATE_54MB;
760 } else if (band == IEEE80211_BAND_5GHZ) {
761 rates[index++] =
762 IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_9MB;
763 rates[index++] =
764 IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_18MB;
765 rates[index++] =
766 IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_24MB;
767 rates[index++] =
768 IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_36MB;
769 rates[index++] =
770 IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_48MB;
771 rates[index++] =
772 IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_54MB;
773 } else {
774 wl1271_error("build_basic_rates invalid band: %d", band);
775 }
650 776
651 return index; 777 return index;
652} 778}
@@ -665,7 +791,8 @@ int wl1271_cmd_build_null_data(struct wl1271 *wl)
665 791
666 memcpy(template.header.sa, wl->mac_addr, ETH_ALEN); 792 memcpy(template.header.sa, wl->mac_addr, ETH_ALEN);
667 template.header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_DATA | 793 template.header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_DATA |
668 IEEE80211_STYPE_NULLFUNC); 794 IEEE80211_STYPE_NULLFUNC |
795 IEEE80211_FCTL_TODS);
669 796
670 return wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, &template, 797 return wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, &template,
671 sizeof(template)); 798 sizeof(template));
@@ -678,7 +805,10 @@ int wl1271_cmd_build_ps_poll(struct wl1271 *wl, u16 aid)
678 805
679 memcpy(template.bssid, wl->bssid, ETH_ALEN); 806 memcpy(template.bssid, wl->bssid, ETH_ALEN);
680 memcpy(template.ta, wl->mac_addr, ETH_ALEN); 807 memcpy(template.ta, wl->mac_addr, ETH_ALEN);
681 template.aid = aid; 808
809 /* aid in PS-Poll has its two MSBs each set to 1 */
810 template.aid = cpu_to_le16(1 << 15 | 1 << 14 | aid);
811
682 template.fc = cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL); 812 template.fc = cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL);
683 813
684 return wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, &template, 814 return wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, &template,
@@ -686,12 +816,14 @@ int wl1271_cmd_build_ps_poll(struct wl1271 *wl, u16 aid)
686 816
687} 817}
688 818
689int wl1271_cmd_build_probe_req(struct wl1271 *wl, u8 *ssid, size_t ssid_len) 819int wl1271_cmd_build_probe_req(struct wl1271 *wl, u8 *ssid, size_t ssid_len,
820 u8 band)
690{ 821{
691 struct wl12xx_probe_req_template template; 822 struct wl12xx_probe_req_template template;
692 struct wl12xx_ie_rates *rates; 823 struct wl12xx_ie_rates *rates;
693 char *ptr; 824 char *ptr;
694 u16 size; 825 u16 size;
826 int ret;
695 827
696 ptr = (char *)&template; 828 ptr = (char *)&template;
697 size = sizeof(struct ieee80211_header); 829 size = sizeof(struct ieee80211_header);
@@ -713,20 +845,25 @@ int wl1271_cmd_build_probe_req(struct wl1271 *wl, u8 *ssid, size_t ssid_len)
713 /* Basic Rates */ 845 /* Basic Rates */
714 rates = (struct wl12xx_ie_rates *)ptr; 846 rates = (struct wl12xx_ie_rates *)ptr;
715 rates->header.id = WLAN_EID_SUPP_RATES; 847 rates->header.id = WLAN_EID_SUPP_RATES;
716 rates->header.len = wl1271_build_basic_rates(rates->rates); 848 rates->header.len = wl1271_build_basic_rates(rates->rates, band);
717 size += sizeof(struct wl12xx_ie_header) + rates->header.len; 849 size += sizeof(struct wl12xx_ie_header) + rates->header.len;
718 ptr += sizeof(struct wl12xx_ie_header) + rates->header.len; 850 ptr += sizeof(struct wl12xx_ie_header) + rates->header.len;
719 851
720 /* Extended rates */ 852 /* Extended rates */
721 rates = (struct wl12xx_ie_rates *)ptr; 853 rates = (struct wl12xx_ie_rates *)ptr;
722 rates->header.id = WLAN_EID_EXT_SUPP_RATES; 854 rates->header.id = WLAN_EID_EXT_SUPP_RATES;
723 rates->header.len = wl1271_build_extended_rates(rates->rates); 855 rates->header.len = wl1271_build_extended_rates(rates->rates, band);
724 size += sizeof(struct wl12xx_ie_header) + rates->header.len; 856 size += sizeof(struct wl12xx_ie_header) + rates->header.len;
725 857
726 wl1271_dump(DEBUG_SCAN, "PROBE REQ: ", &template, size); 858 wl1271_dump(DEBUG_SCAN, "PROBE REQ: ", &template, size);
727 859
728 return wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4, 860 if (band == IEEE80211_BAND_2GHZ)
729 &template, size); 861 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4,
862 &template, size);
863 else
864 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
865 &template, size);
866 return ret;
730} 867}
731 868
732int wl1271_cmd_set_default_wep_key(struct wl1271 *wl, u8 id) 869int wl1271_cmd_set_default_wep_key(struct wl1271 *wl, u8 id)
@@ -743,10 +880,10 @@ int wl1271_cmd_set_default_wep_key(struct wl1271 *wl, u8 id)
743 } 880 }
744 881
745 cmd->id = id; 882 cmd->id = id;
746 cmd->key_action = KEY_SET_ID; 883 cmd->key_action = cpu_to_le16(KEY_SET_ID);
747 cmd->key_type = KEY_WEP; 884 cmd->key_type = KEY_WEP;
748 885
749 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd)); 886 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
750 if (ret < 0) { 887 if (ret < 0) {
751 wl1271_warning("cmd set_default_wep_key failed: %d", ret); 888 wl1271_warning("cmd set_default_wep_key failed: %d", ret);
752 goto out; 889 goto out;
@@ -759,7 +896,8 @@ out:
759} 896}
760 897
761int wl1271_cmd_set_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type, 898int wl1271_cmd_set_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
762 u8 key_size, const u8 *key, const u8 *addr) 899 u8 key_size, const u8 *key, const u8 *addr,
900 u32 tx_seq_32, u16 tx_seq_16)
763{ 901{
764 struct wl1271_cmd_set_keys *cmd; 902 struct wl1271_cmd_set_keys *cmd;
765 int ret = 0; 903 int ret = 0;
@@ -773,16 +911,18 @@ int wl1271_cmd_set_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
773 if (key_type != KEY_WEP) 911 if (key_type != KEY_WEP)
774 memcpy(cmd->addr, addr, ETH_ALEN); 912 memcpy(cmd->addr, addr, ETH_ALEN);
775 913
776 cmd->key_action = action; 914 cmd->key_action = cpu_to_le16(action);
777 cmd->key_size = key_size; 915 cmd->key_size = key_size;
778 cmd->key_type = key_type; 916 cmd->key_type = key_type;
779 917
918 cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
919 cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
920
780 /* we have only one SSID profile */ 921 /* we have only one SSID profile */
781 cmd->ssid_profile = 0; 922 cmd->ssid_profile = 0;
782 923
783 cmd->id = id; 924 cmd->id = id;
784 925
785 /* FIXME: this is from wl1251, needs to be checked */
786 if (key_type == KEY_TKIP) { 926 if (key_type == KEY_TKIP) {
787 /* 927 /*
788 * We get the key in the following form: 928 * We get the key in the following form:
@@ -800,10 +940,10 @@ int wl1271_cmd_set_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
800 940
801 wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd)); 941 wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd));
802 942
803 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd)); 943 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
804 if (ret < 0) { 944 if (ret < 0) {
805 wl1271_warning("could not set keys"); 945 wl1271_warning("could not set keys");
806 goto out; 946 goto out;
807 } 947 }
808 948
809out: 949out:
@@ -811,3 +951,34 @@ out:
811 951
812 return ret; 952 return ret;
813} 953}
954
955int wl1271_cmd_disconnect(struct wl1271 *wl)
956{
957 struct wl1271_cmd_disconnect *cmd;
958 int ret = 0;
959
960 wl1271_debug(DEBUG_CMD, "cmd disconnect");
961
962 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
963 if (!cmd) {
964 ret = -ENOMEM;
965 goto out;
966 }
967
968 cmd->rx_config_options = cpu_to_le32(wl->rx_config);
969 cmd->rx_filter_options = cpu_to_le32(wl->rx_filter);
970 /* disconnect reason is not used in immediate disconnections */
971 cmd->type = DISCONNECT_IMMEDIATE;
972
973 ret = wl1271_cmd_send(wl, CMD_DISCONNECT, cmd, sizeof(*cmd), 0);
974 if (ret < 0) {
975 wl1271_error("failed to send disconnect command");
976 goto out_free;
977 }
978
979out_free:
980 kfree(cmd);
981
982out:
983 return ret;
984}
diff --git a/drivers/net/wireless/wl12xx/wl1271_cmd.h b/drivers/net/wireless/wl12xx/wl1271_cmd.h
index 951a8447a516..2dc06c73532b 100644
--- a/drivers/net/wireless/wl12xx/wl1271_cmd.h
+++ b/drivers/net/wireless/wl12xx/wl1271_cmd.h
@@ -29,27 +29,32 @@
29 29
30struct acx_header; 30struct acx_header;
31 31
32int wl1271_cmd_send(struct wl1271 *wl, u16 type, void *buf, size_t buf_len); 32int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len,
33int wl1271_cmd_join(struct wl1271 *wl, u8 bss_type, u8 dtim_interval, 33 size_t res_len);
34 u16 beacon_interval, u8 wait); 34int wl1271_cmd_general_parms(struct wl1271 *wl);
35int wl1271_cmd_radio_parms(struct wl1271 *wl);
36int wl1271_cmd_join(struct wl1271 *wl);
35int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer); 37int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer);
36int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len); 38int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len);
37int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len); 39int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len);
38int wl1271_cmd_data_path(struct wl1271 *wl, u8 channel, bool enable); 40int wl1271_cmd_data_path(struct wl1271 *wl, bool enable);
39int wl1271_cmd_ps_mode(struct wl1271 *wl, u8 ps_mode); 41int wl1271_cmd_ps_mode(struct wl1271 *wl, u8 ps_mode, bool send);
40int wl1271_cmd_read_memory(struct wl1271 *wl, u32 addr, void *answer, 42int wl1271_cmd_read_memory(struct wl1271 *wl, u32 addr, void *answer,
41 size_t len); 43 size_t len);
42int wl1271_cmd_scan(struct wl1271 *wl, u8 *ssid, size_t len, 44int wl1271_cmd_scan(struct wl1271 *wl, u8 *ssid, size_t len,
43 u8 active_scan, u8 high_prio, u8 num_channels, 45 u8 active_scan, u8 high_prio, u8 band,
44 u8 probe_requests); 46 u8 probe_requests);
45int wl1271_cmd_template_set(struct wl1271 *wl, u16 template_id, 47int wl1271_cmd_template_set(struct wl1271 *wl, u16 template_id,
46 void *buf, size_t buf_len); 48 void *buf, size_t buf_len);
47int wl1271_cmd_build_null_data(struct wl1271 *wl); 49int wl1271_cmd_build_null_data(struct wl1271 *wl);
48int wl1271_cmd_build_ps_poll(struct wl1271 *wl, u16 aid); 50int wl1271_cmd_build_ps_poll(struct wl1271 *wl, u16 aid);
49int wl1271_cmd_build_probe_req(struct wl1271 *wl, u8 *ssid, size_t ssid_len); 51int wl1271_cmd_build_probe_req(struct wl1271 *wl, u8 *ssid, size_t ssid_len,
52 u8 band);
50int wl1271_cmd_set_default_wep_key(struct wl1271 *wl, u8 id); 53int wl1271_cmd_set_default_wep_key(struct wl1271 *wl, u8 id);
51int wl1271_cmd_set_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type, 54int wl1271_cmd_set_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
52 u8 key_size, const u8 *key, const u8 *addr); 55 u8 key_size, const u8 *key, const u8 *addr,
56 u32 tx_seq_32, u16 tx_seq_16);
57int wl1271_cmd_disconnect(struct wl1271 *wl);
53 58
54enum wl1271_commands { 59enum wl1271_commands {
55 CMD_INTERROGATE = 1, /*use this to read information elements*/ 60 CMD_INTERROGATE = 1, /*use this to read information elements*/
@@ -118,8 +123,8 @@ enum cmd_templ {
118#define WL1271_CMD_TEMPL_MAX_SIZE 252 123#define WL1271_CMD_TEMPL_MAX_SIZE 252
119 124
120struct wl1271_cmd_header { 125struct wl1271_cmd_header {
121 u16 id; 126 __le16 id;
122 u16 status; 127 __le16 status;
123 /* payload */ 128 /* payload */
124 u8 data[0]; 129 u8 data[0];
125} __attribute__ ((packed)); 130} __attribute__ ((packed));
@@ -172,17 +177,17 @@ struct cmd_read_write_memory {
172 struct wl1271_cmd_header header; 177 struct wl1271_cmd_header header;
173 178
174 /* The address of the memory to read from or write to.*/ 179 /* The address of the memory to read from or write to.*/
175 u32 addr; 180 __le32 addr;
176 181
177 /* The amount of data in bytes to read from or write to the WiLink 182 /* The amount of data in bytes to read from or write to the WiLink
178 * device.*/ 183 * device.*/
179 u32 size; 184 __le32 size;
180 185
181 /* The actual value read from or written to the Wilink. The source 186 /* The actual value read from or written to the Wilink. The source
182 of this field is the Host in WRITE command or the Wilink in READ 187 of this field is the Host in WRITE command or the Wilink in READ
183 command. */ 188 command. */
184 u8 value[MAX_READ_SIZE]; 189 u8 value[MAX_READ_SIZE];
185}; 190} __attribute__ ((packed));
186 191
187#define CMDMBOX_HEADER_LEN 4 192#define CMDMBOX_HEADER_LEN 4
188#define CMDMBOX_INFO_ELEM_HEADER_LEN 4 193#define CMDMBOX_INFO_ELEM_HEADER_LEN 4
@@ -196,22 +201,23 @@ enum {
196 201
197#define WL1271_JOIN_CMD_CTRL_TX_FLUSH 0x80 /* Firmware flushes all Tx */ 202#define WL1271_JOIN_CMD_CTRL_TX_FLUSH 0x80 /* Firmware flushes all Tx */
198#define WL1271_JOIN_CMD_TX_SESSION_OFFSET 1 203#define WL1271_JOIN_CMD_TX_SESSION_OFFSET 1
204#define WL1271_JOIN_CMD_BSS_TYPE_5GHZ 0x10
199 205
200struct wl1271_cmd_join { 206struct wl1271_cmd_join {
201 struct wl1271_cmd_header header; 207 struct wl1271_cmd_header header;
202 208
203 u32 bssid_lsb; 209 __le32 bssid_lsb;
204 u16 bssid_msb; 210 __le16 bssid_msb;
205 u16 beacon_interval; /* in TBTTs */ 211 __le16 beacon_interval; /* in TBTTs */
206 u32 rx_config_options; 212 __le32 rx_config_options;
207 u32 rx_filter_options; 213 __le32 rx_filter_options;
208 214
209 /* 215 /*
210 * The target uses this field to determine the rate at 216 * The target uses this field to determine the rate at
211 * which to transmit control frame responses (such as 217 * which to transmit control frame responses (such as
212 * ACK or CTS frames). 218 * ACK or CTS frames).
213 */ 219 */
214 u32 basic_rate_set; 220 __le32 basic_rate_set;
215 u8 dtim_interval; 221 u8 dtim_interval;
216 /* 222 /*
217 * bits 0-2: This bitwise field specifies the type 223 * bits 0-2: This bitwise field specifies the type
@@ -240,10 +246,10 @@ struct cmd_enabledisable_path {
240struct wl1271_cmd_template_set { 246struct wl1271_cmd_template_set {
241 struct wl1271_cmd_header header; 247 struct wl1271_cmd_header header;
242 248
243 u16 len; 249 __le16 len;
244 u8 template_type; 250 u8 template_type;
245 u8 index; /* relevant only for KLV_TEMPLATE type */ 251 u8 index; /* relevant only for KLV_TEMPLATE type */
246 u32 enabled_rates; 252 __le32 enabled_rates;
247 u8 short_retry_limit; 253 u8 short_retry_limit;
248 u8 long_retry_limit; 254 u8 long_retry_limit;
249 u8 aflags; 255 u8 aflags;
@@ -280,18 +286,13 @@ struct wl1271_cmd_ps_params {
280 * to power save mode. 286 * to power save mode.
281 */ 287 */
282 u8 hang_over_period; 288 u8 hang_over_period;
283 u32 null_data_rate; 289 __le32 null_data_rate;
284} __attribute__ ((packed)); 290} __attribute__ ((packed));
285 291
286/* HW encryption keys */ 292/* HW encryption keys */
287#define NUM_ACCESS_CATEGORIES_COPY 4 293#define NUM_ACCESS_CATEGORIES_COPY 4
288#define MAX_KEY_SIZE 32 294#define MAX_KEY_SIZE 32
289 295
290/* When set, disable HW encryption */
291#define DF_ENCRYPTION_DISABLE 0x01
292/* When set, disable HW decryption */
293#define DF_SNIFF_MODE_ENABLE 0x80
294
295enum wl1271_cmd_key_action { 296enum wl1271_cmd_key_action {
296 KEY_ADD_OR_REPLACE = 1, 297 KEY_ADD_OR_REPLACE = 1,
297 KEY_REMOVE = 2, 298 KEY_REMOVE = 2,
@@ -316,9 +317,9 @@ struct wl1271_cmd_set_keys {
316 u8 addr[ETH_ALEN]; 317 u8 addr[ETH_ALEN];
317 318
318 /* key_action_e */ 319 /* key_action_e */
319 u16 key_action; 320 __le16 key_action;
320 321
321 u16 reserved_1; 322 __le16 reserved_1;
322 323
323 /* key size in bytes */ 324 /* key size in bytes */
324 u8 key_size; 325 u8 key_size;
@@ -334,8 +335,8 @@ struct wl1271_cmd_set_keys {
334 u8 id; 335 u8 id;
335 u8 reserved_2[6]; 336 u8 reserved_2[6];
336 u8 key[MAX_KEY_SIZE]; 337 u8 key[MAX_KEY_SIZE];
337 u16 ac_seq_num16[NUM_ACCESS_CATEGORIES_COPY]; 338 __le16 ac_seq_num16[NUM_ACCESS_CATEGORIES_COPY];
338 u32 ac_seq_num32[NUM_ACCESS_CATEGORIES_COPY]; 339 __le32 ac_seq_num32[NUM_ACCESS_CATEGORIES_COPY];
339} __attribute__ ((packed)); 340} __attribute__ ((packed));
340 341
341 342
@@ -347,19 +348,22 @@ struct wl1271_cmd_set_keys {
347#define WL1271_SCAN_OPT_PRIORITY_HIGH 4 348#define WL1271_SCAN_OPT_PRIORITY_HIGH 4
348#define WL1271_SCAN_CHAN_MIN_DURATION 30000 /* TU */ 349#define WL1271_SCAN_CHAN_MIN_DURATION 30000 /* TU */
349#define WL1271_SCAN_CHAN_MAX_DURATION 60000 /* TU */ 350#define WL1271_SCAN_CHAN_MAX_DURATION 60000 /* TU */
351#define WL1271_SCAN_BAND_2_4_GHZ 0
352#define WL1271_SCAN_BAND_5_GHZ 1
353#define WL1271_SCAN_BAND_DUAL 2
350 354
351struct basic_scan_params { 355struct basic_scan_params {
352 u32 rx_config_options; 356 __le32 rx_config_options;
353 u32 rx_filter_options; 357 __le32 rx_filter_options;
354 /* Scan option flags (WL1271_SCAN_OPT_*) */ 358 /* Scan option flags (WL1271_SCAN_OPT_*) */
355 u16 scan_options; 359 __le16 scan_options;
356 /* Number of scan channels in the list (maximum 30) */ 360 /* Number of scan channels in the list (maximum 30) */
357 u8 num_channels; 361 u8 num_channels;
358 /* This field indicates the number of probe requests to send 362 /* This field indicates the number of probe requests to send
359 per channel for an active scan */ 363 per channel for an active scan */
360 u8 num_probe_requests; 364 u8 num_probe_requests;
361 /* Rate bit field for sending the probes */ 365 /* Rate bit field for sending the probes */
362 u32 tx_rate; 366 __le32 tx_rate;
363 u8 tid_trigger; 367 u8 tid_trigger;
364 u8 ssid_len; 368 u8 ssid_len;
365 /* in order to align */ 369 /* in order to align */
@@ -374,10 +378,10 @@ struct basic_scan_params {
374 378
375struct basic_scan_channel_params { 379struct basic_scan_channel_params {
376 /* Duration in TU to wait for frames on a channel for active scan */ 380 /* Duration in TU to wait for frames on a channel for active scan */
377 u32 min_duration; 381 __le32 min_duration;
378 u32 max_duration; 382 __le32 max_duration;
379 u32 bssid_lsb; 383 __le32 bssid_lsb;
380 u16 bssid_msb; 384 __le16 bssid_msb;
381 u8 early_termination; 385 u8 early_termination;
382 u8 tx_power_att; 386 u8 tx_power_att;
383 u8 channel; 387 u8 channel;
@@ -397,13 +401,13 @@ struct wl1271_cmd_scan {
397struct wl1271_cmd_trigger_scan_to { 401struct wl1271_cmd_trigger_scan_to {
398 struct wl1271_cmd_header header; 402 struct wl1271_cmd_header header;
399 403
400 u32 timeout; 404 __le32 timeout;
401}; 405} __attribute__ ((packed));
402 406
403struct wl1271_cmd_test_header { 407struct wl1271_cmd_test_header {
404 u8 id; 408 u8 id;
405 u8 padding[3]; 409 u8 padding[3];
406}; 410} __attribute__ ((packed));
407 411
408enum wl1271_channel_tune_bands { 412enum wl1271_channel_tune_bands {
409 WL1271_CHANNEL_TUNE_BAND_2_4, 413 WL1271_CHANNEL_TUNE_BAND_2_4,
@@ -416,6 +420,33 @@ enum wl1271_channel_tune_bands {
416#define TEST_CMD_P2G_CAL 0x02 420#define TEST_CMD_P2G_CAL 0x02
417#define TEST_CMD_CHANNEL_TUNE 0x0d 421#define TEST_CMD_CHANNEL_TUNE 0x0d
418#define TEST_CMD_UPDATE_PD_REFERENCE_POINT 0x1d 422#define TEST_CMD_UPDATE_PD_REFERENCE_POINT 0x1d
423#define TEST_CMD_INI_FILE_RADIO_PARAM 0x19
424#define TEST_CMD_INI_FILE_GENERAL_PARAM 0x1E
425
426struct wl1271_general_parms_cmd {
427 struct wl1271_cmd_header header;
428
429 struct wl1271_cmd_test_header test;
430
431 u8 params[WL1271_NVS_GENERAL_PARAMS_SIZE];
432 s8 reserved[23];
433} __attribute__ ((packed));
434
435#define WL1271_STAT_RADIO_PARAMS_5_SIZE 29
436#define WL1271_DYN_RADIO_PARAMS_5_SIZE 104
437
438struct wl1271_radio_parms_cmd {
439 struct wl1271_cmd_header header;
440
441 struct wl1271_cmd_test_header test;
442
443 u8 stat_radio_params[WL1271_NVS_STAT_RADIO_PARAMS_SIZE];
444 u8 stat_radio_params_5[WL1271_STAT_RADIO_PARAMS_5_SIZE];
445
446 u8 dyn_radio_params[WL1271_NVS_DYN_RADIO_PARAMS_SIZE];
447 u8 reserved;
448 u8 dyn_radio_params_5[WL1271_DYN_RADIO_PARAMS_5_SIZE];
449} __attribute__ ((packed));
419 450
420struct wl1271_cmd_cal_channel_tune { 451struct wl1271_cmd_cal_channel_tune {
421 struct wl1271_cmd_header header; 452 struct wl1271_cmd_header header;
@@ -425,7 +456,7 @@ struct wl1271_cmd_cal_channel_tune {
425 u8 band; 456 u8 band;
426 u8 channel; 457 u8 channel;
427 458
428 u16 radio_status; 459 __le16 radio_status;
429} __attribute__ ((packed)); 460} __attribute__ ((packed));
430 461
431struct wl1271_cmd_cal_update_ref_point { 462struct wl1271_cmd_cal_update_ref_point {
@@ -433,8 +464,8 @@ struct wl1271_cmd_cal_update_ref_point {
433 464
434 struct wl1271_cmd_test_header test; 465 struct wl1271_cmd_test_header test;
435 466
436 s32 ref_power; 467 __le32 ref_power;
437 s32 ref_detector; 468 __le32 ref_detector;
438 u8 sub_band; 469 u8 sub_band;
439 u8 padding[3]; 470 u8 padding[3];
440} __attribute__ ((packed)); 471} __attribute__ ((packed));
@@ -449,16 +480,42 @@ struct wl1271_cmd_cal_p2g {
449 480
450 struct wl1271_cmd_test_header test; 481 struct wl1271_cmd_test_header test;
451 482
452 u16 len; 483 __le16 len;
453 u8 buf[MAX_TLV_LENGTH]; 484 u8 buf[MAX_TLV_LENGTH];
454 u8 type; 485 u8 type;
455 u8 padding; 486 u8 padding;
456 487
457 s16 radio_status; 488 __le16 radio_status;
458 u8 nvs_version[MAX_NVS_VERSION_LENGTH]; 489 u8 nvs_version[MAX_NVS_VERSION_LENGTH];
459 490
460 u8 sub_band_mask; 491 u8 sub_band_mask;
461 u8 padding2; 492 u8 padding2;
462} __attribute__ ((packed)); 493} __attribute__ ((packed));
463 494
495
496/*
497 * There are three types of disconnections:
498 *
499 * DISCONNECT_IMMEDIATE: the fw doesn't send any frames
500 * DISCONNECT_DEAUTH: the fw generates a DEAUTH request with the reason
501 * we have passed
502 * DISCONNECT_DISASSOC: the fw generates a DESASSOC request with the reason
503 * we have passed
504 */
505enum wl1271_disconnect_type {
506 DISCONNECT_IMMEDIATE,
507 DISCONNECT_DEAUTH,
508 DISCONNECT_DISASSOC
509};
510
511struct wl1271_cmd_disconnect {
512 __le32 rx_config_options;
513 __le32 rx_filter_options;
514
515 __le16 reason;
516 u8 type;
517
518 u8 padding;
519} __attribute__ ((packed));
520
464#endif /* __WL1271_CMD_H__ */ 521#endif /* __WL1271_CMD_H__ */
diff --git a/drivers/net/wireless/wl12xx/wl1271_conf.h b/drivers/net/wireless/wl12xx/wl1271_conf.h
new file mode 100644
index 000000000000..6f9e75cc5640
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/wl1271_conf.h
@@ -0,0 +1,795 @@
1/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 *
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
24#ifndef __WL1271_CONF_H__
25#define __WL1271_CONF_H__
26
27enum {
28 CONF_HW_BIT_RATE_1MBPS = BIT(0),
29 CONF_HW_BIT_RATE_2MBPS = BIT(1),
30 CONF_HW_BIT_RATE_5_5MBPS = BIT(2),
31 CONF_HW_BIT_RATE_6MBPS = BIT(3),
32 CONF_HW_BIT_RATE_9MBPS = BIT(4),
33 CONF_HW_BIT_RATE_11MBPS = BIT(5),
34 CONF_HW_BIT_RATE_12MBPS = BIT(6),
35 CONF_HW_BIT_RATE_18MBPS = BIT(7),
36 CONF_HW_BIT_RATE_22MBPS = BIT(8),
37 CONF_HW_BIT_RATE_24MBPS = BIT(9),
38 CONF_HW_BIT_RATE_36MBPS = BIT(10),
39 CONF_HW_BIT_RATE_48MBPS = BIT(11),
40 CONF_HW_BIT_RATE_54MBPS = BIT(12),
41 CONF_HW_BIT_RATE_MCS_0 = BIT(13),
42 CONF_HW_BIT_RATE_MCS_1 = BIT(14),
43 CONF_HW_BIT_RATE_MCS_2 = BIT(15),
44 CONF_HW_BIT_RATE_MCS_3 = BIT(16),
45 CONF_HW_BIT_RATE_MCS_4 = BIT(17),
46 CONF_HW_BIT_RATE_MCS_5 = BIT(18),
47 CONF_HW_BIT_RATE_MCS_6 = BIT(19),
48 CONF_HW_BIT_RATE_MCS_7 = BIT(20)
49};
50
51enum {
52 CONF_HW_RATE_INDEX_1MBPS = 0,
53 CONF_HW_RATE_INDEX_2MBPS = 1,
54 CONF_HW_RATE_INDEX_5_5MBPS = 2,
55 CONF_HW_RATE_INDEX_6MBPS = 3,
56 CONF_HW_RATE_INDEX_9MBPS = 4,
57 CONF_HW_RATE_INDEX_11MBPS = 5,
58 CONF_HW_RATE_INDEX_12MBPS = 6,
59 CONF_HW_RATE_INDEX_18MBPS = 7,
60 CONF_HW_RATE_INDEX_22MBPS = 8,
61 CONF_HW_RATE_INDEX_24MBPS = 9,
62 CONF_HW_RATE_INDEX_36MBPS = 10,
63 CONF_HW_RATE_INDEX_48MBPS = 11,
64 CONF_HW_RATE_INDEX_54MBPS = 12,
65 CONF_HW_RATE_INDEX_MAX = CONF_HW_RATE_INDEX_54MBPS,
66};
67
68struct conf_sg_settings {
69 /*
70 * Defines the PER threshold in PPM of the BT voice of which reaching
71 * this value will trigger raising the priority of the BT voice by
72 * the BT IP until next NFS sample interval time as defined in
73 * nfs_sample_interval.
74 *
75 * Unit: PER value in PPM (parts per million)
76 * #Error_packets / #Total_packets
77
78 * Range: u32
79 */
80 u32 per_threshold;
81
82 /*
83 * This value is an absolute time in micro-seconds to limit the
84 * maximum scan duration compensation while in SG
85 */
86 u32 max_scan_compensation_time;
87
88 /* Defines the PER threshold of the BT voice of which reaching this
89 * value will trigger raising the priority of the BT voice until next
90 * NFS sample interval time as defined in sample_interval.
91 *
92 * Unit: msec
93 * Range: 1-65000
94 */
95 u16 nfs_sample_interval;
96
97 /*
98 * Defines the load ratio for the BT.
99 * The WLAN ratio is: 100 - load_ratio
100 *
101 * Unit: Percent
102 * Range: 0-100
103 */
104 u8 load_ratio;
105
106 /*
107 * true - Co-ex is allowed to enter/exit P.S automatically and
108 * transparently to the host
109 *
110 * false - Co-ex is disallowed to enter/exit P.S and will trigger an
111 * event to the host to notify for the need to enter/exit P.S
112 * due to BT change state
113 *
114 */
115 u8 auto_ps_mode;
116
117 /*
118 * This parameter defines the compensation percentage of num of probe
119 * requests in case scan is initiated during BT voice/BT ACL
120 * guaranteed link.
121 *
122 * Unit: Percent
123 * Range: 0-255 (0 - No compensation)
124 */
125 u8 probe_req_compensation;
126
127 /*
128 * This parameter defines the compensation percentage of scan window
129 * size in case scan is initiated during BT voice/BT ACL Guaranteed
130 * link.
131 *
132 * Unit: Percent
133 * Range: 0-255 (0 - No compensation)
134 */
135 u8 scan_window_compensation;
136
137 /*
138 * Defines the antenna configuration.
139 *
140 * Range: 0 - Single Antenna; 1 - Dual Antenna
141 */
142 u8 antenna_config;
143
144 /*
145 * The percent out of the Max consecutive beacon miss roaming trigger
146 * which is the threshold for raising the priority of beacon
147 * reception.
148 *
149 * Range: 1-100
150 * N = MaxConsecutiveBeaconMiss
151 * P = coexMaxConsecutiveBeaconMissPrecent
152 * Threshold = MIN( N-1, round(N * P / 100))
153 */
154 u8 beacon_miss_threshold;
155
156 /*
157 * The RX rate threshold below which rate adaptation is assumed to be
158 * occurring at the AP which will raise priority for ACTIVE_RX and RX
159 * SP.
160 *
161 * Range: HW_BIT_RATE_*
162 */
163 u32 rate_adaptation_threshold;
164
165 /*
166 * The SNR above which the RX rate threshold indicating AP rate
167 * adaptation is valid
168 *
169 * Range: -128 - 127
170 */
171 s8 rate_adaptation_snr;
172};
173
174enum conf_rx_queue_type {
175 CONF_RX_QUEUE_TYPE_LOW_PRIORITY, /* All except the high priority */
176 CONF_RX_QUEUE_TYPE_HIGH_PRIORITY, /* Management and voice packets */
177};
178
179struct conf_rx_settings {
180 /*
181 * The maximum amount of time, in TU, before the
182 * firmware discards the MSDU.
183 *
184 * Range: 0 - 0xFFFFFFFF
185 */
186 u32 rx_msdu_life_time;
187
188 /*
189 * Packet detection threshold in the PHY.
190 *
191 * FIXME: details unknown.
192 */
193 u32 packet_detection_threshold;
194
195 /*
196 * The longest time the STA will wait to receive traffic from the AP
197 * after a PS-poll has been transmitted.
198 *
199 * Range: 0 - 200000
200 */
201 u16 ps_poll_timeout;
202 /*
203 * The longest time the STA will wait to receive traffic from the AP
204 * after a frame has been sent from an UPSD enabled queue.
205 *
206 * Range: 0 - 200000
207 */
208 u16 upsd_timeout;
209
210 /*
211 * The number of octets in an MPDU, below which an RTS/CTS
212 * handshake is not performed.
213 *
214 * Range: 0 - 4096
215 */
216 u16 rts_threshold;
217
218 /*
219 * The RX Clear Channel Assessment threshold in the PHY
220 * (the energy threshold).
221 *
222 * Range: ENABLE_ENERGY_D == 0x140A
223 * DISABLE_ENERGY_D == 0xFFEF
224 */
225 u16 rx_cca_threshold;
226
227 /*
228 * Occupied Rx mem-blocks number which requires interrupting the host
229 * (0 = no buffering, 0xffff = disabled).
230 *
231 * Range: u16
232 */
233 u16 irq_blk_threshold;
234
235 /*
236 * Rx packets number which requires interrupting the host
237 * (0 = no buffering).
238 *
239 * Range: u16
240 */
241 u16 irq_pkt_threshold;
242
243 /*
244 * Max time in msec the FW may delay RX-Complete interrupt.
245 *
246 * Range: 1 - 100
247 */
248 u16 irq_timeout;
249
250 /*
251 * The RX queue type.
252 *
253 * Range: RX_QUEUE_TYPE_RX_LOW_PRIORITY, RX_QUEUE_TYPE_RX_HIGH_PRIORITY,
254 */
255 u8 queue_type;
256};
257
258#define CONF_TX_MAX_RATE_CLASSES 8
259
260#define CONF_TX_RATE_MASK_UNSPECIFIED 0
261#define CONF_TX_RATE_MASK_BASIC (CONF_HW_BIT_RATE_1MBPS | \
262 CONF_HW_BIT_RATE_2MBPS)
263#define CONF_TX_RATE_RETRY_LIMIT 10
264
265struct conf_tx_rate_class {
266
267 /*
268 * The rates enabled for this rate class.
269 *
270 * Range: CONF_HW_BIT_RATE_* bit mask
271 */
272 u32 enabled_rates;
273
274 /*
275 * The dot11 short retry limit used for TX retries.
276 *
277 * Range: u8
278 */
279 u8 short_retry_limit;
280
281 /*
282 * The dot11 long retry limit used for TX retries.
283 *
284 * Range: u8
285 */
286 u8 long_retry_limit;
287
288 /*
289 * Flags controlling the attributes of TX transmission.
290 *
291 * Range: bit 0: Truncate - when set, FW attempts to send a frame stop
292 * when the total valid per-rate attempts have
293 * been exhausted; otherwise transmissions
294 * will continue at the lowest available rate
295 * until the appropriate one of the
296 * short_retry_limit, long_retry_limit,
297 * dot11_max_transmit_msdu_life_time, or
298 * max_tx_life_time, is exhausted.
299 * 1: Preamble Override - indicates if the preamble type
300 * should be used in TX.
301 * 2: Preamble Type - the type of the preamble to be used by
302 * the policy (0 - long preamble, 1 - short preamble.
303 */
304 u8 aflags;
305};
306
307#define CONF_TX_MAX_AC_COUNT 4
308
309/* Slot number setting to start transmission at PIFS interval */
310#define CONF_TX_AIFS_PIFS 1
311/* Slot number setting to start transmission at DIFS interval normal
312 * DCF access */
313#define CONF_TX_AIFS_DIFS 2
314
315
316enum conf_tx_ac {
317 CONF_TX_AC_BE = 0, /* best effort / legacy */
318 CONF_TX_AC_BK = 1, /* background */
319 CONF_TX_AC_VI = 2, /* video */
320 CONF_TX_AC_VO = 3, /* voice */
321 CONF_TX_AC_CTS2SELF = 4, /* fictious AC, follows AC_VO */
322 CONF_TX_AC_ANY_TID = 0x1f
323};
324
325struct conf_tx_ac_category {
326 /*
327 * The AC class identifier.
328 *
329 * Range: enum conf_tx_ac
330 */
331 u8 ac;
332
333 /*
334 * The contention window minimum size (in slots) for the access
335 * class.
336 *
337 * Range: u8
338 */
339 u8 cw_min;
340
341 /*
342 * The contention window maximum size (in slots) for the access
343 * class.
344 *
345 * Range: u8
346 */
347 u16 cw_max;
348
349 /*
350 * The AIF value (in slots) for the access class.
351 *
352 * Range: u8
353 */
354 u8 aifsn;
355
356 /*
357 * The TX Op Limit (in microseconds) for the access class.
358 *
359 * Range: u16
360 */
361 u16 tx_op_limit;
362};
363
364#define CONF_TX_MAX_TID_COUNT 7
365
366enum {
367 CONF_CHANNEL_TYPE_DCF = 0, /* DC/LEGACY*/
368 CONF_CHANNEL_TYPE_EDCF = 1, /* EDCA*/
369 CONF_CHANNEL_TYPE_HCCA = 2, /* HCCA*/
370};
371
372enum {
373 CONF_PS_SCHEME_LEGACY = 0,
374 CONF_PS_SCHEME_UPSD_TRIGGER = 1,
375 CONF_PS_SCHEME_LEGACY_PSPOLL = 2,
376 CONF_PS_SCHEME_SAPSD = 3,
377};
378
379enum {
380 CONF_ACK_POLICY_LEGACY = 0,
381 CONF_ACK_POLICY_NO_ACK = 1,
382 CONF_ACK_POLICY_BLOCK = 2,
383};
384
385
386struct conf_tx_tid {
387 u8 queue_id;
388 u8 channel_type;
389 u8 tsid;
390 u8 ps_scheme;
391 u8 ack_policy;
392 u32 apsd_conf[2];
393};
394
395struct conf_tx_settings {
396 /*
397 * The TX ED value for TELEC Enable/Disable.
398 *
399 * Range: 0, 1
400 */
401 u8 tx_energy_detection;
402
403 /*
404 * Configuration for rate classes for TX (currently only one
405 * rate class supported.)
406 */
407 struct conf_tx_rate_class rc_conf;
408
409 /*
410 * Configuration for access categories for TX rate control.
411 */
412 u8 ac_conf_count;
413 struct conf_tx_ac_category ac_conf[CONF_TX_MAX_AC_COUNT];
414
415 /*
416 * Configuration for TID parameters.
417 */
418 u8 tid_conf_count;
419 struct conf_tx_tid tid_conf[CONF_TX_MAX_TID_COUNT];
420
421 /*
422 * The TX fragmentation threshold.
423 *
424 * Range: u16
425 */
426 u16 frag_threshold;
427
428 /*
429 * Max time in msec the FW may delay frame TX-Complete interrupt.
430 *
431 * Range: u16
432 */
433 u16 tx_compl_timeout;
434
435 /*
436 * Completed TX packet count which requires to issue the TX-Complete
437 * interrupt.
438 *
439 * Range: u16
440 */
441 u16 tx_compl_threshold;
442
443};
444
445enum {
446 CONF_WAKE_UP_EVENT_BEACON = 0x01, /* Wake on every Beacon*/
447 CONF_WAKE_UP_EVENT_DTIM = 0x02, /* Wake on every DTIM*/
448 CONF_WAKE_UP_EVENT_N_DTIM = 0x04, /* Wake every Nth DTIM */
449 CONF_WAKE_UP_EVENT_N_BEACONS = 0x08, /* Wake every Nth beacon */
450 CONF_WAKE_UP_EVENT_BITS_MASK = 0x0F
451};
452
453#define CONF_MAX_BCN_FILT_IE_COUNT 32
454
455#define CONF_BCN_RULE_PASS_ON_CHANGE BIT(0)
456#define CONF_BCN_RULE_PASS_ON_APPEARANCE BIT(1)
457
458#define CONF_BCN_IE_OUI_LEN 3
459#define CONF_BCN_IE_VER_LEN 2
460
461struct conf_bcn_filt_rule {
462 /*
463 * IE number to which to associate a rule.
464 *
465 * Range: u8
466 */
467 u8 ie;
468
469 /*
470 * Rule to associate with the specific ie.
471 *
472 * Range: CONF_BCN_RULE_PASS_ON_*
473 */
474 u8 rule;
475
476 /*
477 * OUI for the vendor specifie IE (221)
478 */
479 u8 oui[CONF_BCN_IE_OUI_LEN];
480
481 /*
482 * Type for the vendor specifie IE (221)
483 */
484 u8 type;
485
486 /*
487 * Version for the vendor specifie IE (221)
488 */
489 u8 version[CONF_BCN_IE_VER_LEN];
490};
491
492#define CONF_MAX_RSSI_SNR_TRIGGERS 8
493
494enum {
495 CONF_TRIG_METRIC_RSSI_BEACON = 0,
496 CONF_TRIG_METRIC_RSSI_DATA,
497 CONF_TRIG_METRIC_SNR_BEACON,
498 CONF_TRIG_METRIC_SNR_DATA
499};
500
501enum {
502 CONF_TRIG_EVENT_TYPE_LEVEL = 0,
503 CONF_TRIG_EVENT_TYPE_EDGE
504};
505
506enum {
507 CONF_TRIG_EVENT_DIR_LOW = 0,
508 CONF_TRIG_EVENT_DIR_HIGH,
509 CONF_TRIG_EVENT_DIR_BIDIR
510};
511
512
513struct conf_sig_trigger {
514 /*
515 * The RSSI / SNR threshold value.
516 *
517 * FIXME: what is the range?
518 */
519 s16 threshold;
520
521 /*
522 * Minimum delay between two trigger events for this trigger in ms.
523 *
524 * Range: 0 - 60000
525 */
526 u16 pacing;
527
528 /*
529 * The measurement data source for this trigger.
530 *
531 * Range: CONF_TRIG_METRIC_*
532 */
533 u8 metric;
534
535 /*
536 * The trigger type of this trigger.
537 *
538 * Range: CONF_TRIG_EVENT_TYPE_*
539 */
540 u8 type;
541
542 /*
543 * The direction of the trigger.
544 *
545 * Range: CONF_TRIG_EVENT_DIR_*
546 */
547 u8 direction;
548
549 /*
550 * Hysteresis range of the trigger around the threshold (in dB)
551 *
552 * Range: u8
553 */
554 u8 hysteresis;
555
556 /*
557 * Index of the trigger rule.
558 *
559 * Range: 0 - CONF_MAX_RSSI_SNR_TRIGGERS-1
560 */
561 u8 index;
562
563 /*
564 * Enable / disable this rule (to use for clearing rules.)
565 *
566 * Range: 1 - Enabled, 2 - Not enabled
567 */
568 u8 enable;
569};
570
571struct conf_sig_weights {
572
573 /*
574 * RSSI from beacons average weight.
575 *
576 * Range: u8
577 */
578 u8 rssi_bcn_avg_weight;
579
580 /*
581 * RSSI from data average weight.
582 *
583 * Range: u8
584 */
585 u8 rssi_pkt_avg_weight;
586
587 /*
588 * SNR from beacons average weight.
589 *
590 * Range: u8
591 */
592 u8 snr_bcn_avg_weight;
593
594 /*
595 * SNR from data average weight.
596 *
597 * Range: u8
598 */
599 u8 snr_pkt_avg_weight;
600};
601
602enum conf_bcn_filt_mode {
603 CONF_BCN_FILT_MODE_DISABLED = 0,
604 CONF_BCN_FILT_MODE_ENABLED = 1
605};
606
607enum conf_bet_mode {
608 CONF_BET_MODE_DISABLE = 0,
609 CONF_BET_MODE_ENABLE = 1,
610};
611
612struct conf_conn_settings {
613 /*
614 * Firmware wakeup conditions configuration. The host may set only
615 * one bit.
616 *
617 * Range: CONF_WAKE_UP_EVENT_*
618 */
619 u8 wake_up_event;
620
621 /*
622 * Listen interval for beacons or Dtims.
623 *
624 * Range: 0 for beacon and Dtim wakeup
625 * 1-10 for x Dtims
626 * 1-255 for x beacons
627 */
628 u8 listen_interval;
629
630 /*
631 * Enable or disable the beacon filtering.
632 *
633 * Range: CONF_BCN_FILT_MODE_*
634 */
635 enum conf_bcn_filt_mode bcn_filt_mode;
636
637 /*
638 * Configure Beacon filter pass-thru rules.
639 */
640 u8 bcn_filt_ie_count;
641 struct conf_bcn_filt_rule bcn_filt_ie[CONF_MAX_BCN_FILT_IE_COUNT];
642
643 /*
644 * The number of consequtive beacons to lose, before the firmware
645 * becomes out of synch.
646 *
647 * Range: u32
648 */
649 u32 synch_fail_thold;
650
651 /*
652 * After out-of-synch, the number of TU's to wait without a further
653 * received beacon (or probe response) before issuing the BSS_EVENT_LOSE
654 * event.
655 *
656 * Range: u32
657 */
658 u32 bss_lose_timeout;
659
660 /*
661 * Beacon receive timeout.
662 *
663 * Range: u32
664 */
665 u32 beacon_rx_timeout;
666
667 /*
668 * Broadcast receive timeout.
669 *
670 * Range: u32
671 */
672 u32 broadcast_timeout;
673
674 /*
675 * Enable/disable reception of broadcast packets in power save mode
676 *
677 * Range: 1 - enable, 0 - disable
678 */
679 u8 rx_broadcast_in_ps;
680
681 /*
682 * Consequtive PS Poll failures before sending event to driver
683 *
684 * Range: u8
685 */
686 u8 ps_poll_threshold;
687
688 /*
689 * Configuration of signal (rssi/snr) triggers.
690 */
691 u8 sig_trigger_count;
692 struct conf_sig_trigger sig_trigger[CONF_MAX_RSSI_SNR_TRIGGERS];
693
694 /*
695 * Configuration of signal average weights.
696 */
697 struct conf_sig_weights sig_weights;
698
699 /*
700 * Specifies if beacon early termination procedure is enabled or
701 * disabled.
702 *
703 * Range: CONF_BET_MODE_*
704 */
705 u8 bet_enable;
706
707 /*
708 * Specifies the maximum number of consecutive beacons that may be
709 * early terminated. After this number is reached at least one full
710 * beacon must be correctly received in FW before beacon ET
711 * resumes.
712 *
713 * Range 0 - 255
714 */
715 u8 bet_max_consecutive;
716
717 /*
718 * Specifies the maximum number of times to try PSM entry if it fails
719 * (if sending the appropriate null-func message fails.)
720 *
721 * Range 0 - 255
722 */
723 u8 psm_entry_retries;
724};
725
726enum {
727 CONF_REF_CLK_19_2_E,
728 CONF_REF_CLK_26_E,
729 CONF_REF_CLK_38_4_E,
730 CONF_REF_CLK_52_E
731};
732
733enum single_dual_band_enum {
734 CONF_SINGLE_BAND,
735 CONF_DUAL_BAND
736};
737
738#define CONF_RSSI_AND_PROCESS_COMPENSATION_SIZE 15
739#define CONF_NUMBER_OF_SUB_BANDS_5 7
740#define CONF_NUMBER_OF_RATE_GROUPS 6
741#define CONF_NUMBER_OF_CHANNELS_2_4 14
742#define CONF_NUMBER_OF_CHANNELS_5 35
743
744struct conf_radio_parms {
745 /*
746 * FEM parameter set to use
747 *
748 * Range: 0 or 1
749 */
750 u8 fem;
751};
752
753struct conf_init_settings {
754 /*
755 * Configure radio parameters.
756 */
757 struct conf_radio_parms radioparam;
758
759};
760
761struct conf_itrim_settings {
762 /* enable dco itrim */
763 u8 enable;
764
765 /* moderation timeout in microsecs from the last TX */
766 u32 timeout;
767};
768
769struct conf_pm_config_settings {
770 /*
771 * Host clock settling time
772 *
773 * Range: 0 - 30000 us
774 */
775 u32 host_clk_settling_time;
776
777 /*
778 * Host fast wakeup support
779 *
780 * Range: true, false
781 */
782 bool host_fast_wakeup_support;
783};
784
785struct conf_drv_settings {
786 struct conf_sg_settings sg;
787 struct conf_rx_settings rx;
788 struct conf_tx_settings tx;
789 struct conf_conn_settings conn;
790 struct conf_init_settings init;
791 struct conf_itrim_settings itrim;
792 struct conf_pm_config_settings pm_config;
793};
794
795#endif
diff --git a/drivers/net/wireless/wl12xx/wl1271_debugfs.c b/drivers/net/wireless/wl12xx/wl1271_debugfs.c
index c1805e5f8964..3f7ff8d0cf5a 100644
--- a/drivers/net/wireless/wl12xx/wl1271_debugfs.c
+++ b/drivers/net/wireless/wl12xx/wl1271_debugfs.c
@@ -24,6 +24,7 @@
24#include "wl1271_debugfs.h" 24#include "wl1271_debugfs.h"
25 25
26#include <linux/skbuff.h> 26#include <linux/skbuff.h>
27#include <linux/slab.h>
27 28
28#include "wl1271.h" 29#include "wl1271.h"
29#include "wl1271_acx.h" 30#include "wl1271_acx.h"
@@ -237,6 +238,64 @@ static const struct file_operations tx_queue_len_ops = {
237 .open = wl1271_open_file_generic, 238 .open = wl1271_open_file_generic,
238}; 239};
239 240
241static ssize_t gpio_power_read(struct file *file, char __user *user_buf,
242 size_t count, loff_t *ppos)
243{
244 struct wl1271 *wl = file->private_data;
245 bool state = test_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
246
247 int res;
248 char buf[10];
249
250 res = scnprintf(buf, sizeof(buf), "%d\n", state);
251
252 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
253}
254
255static ssize_t gpio_power_write(struct file *file,
256 const char __user *user_buf,
257 size_t count, loff_t *ppos)
258{
259 struct wl1271 *wl = file->private_data;
260 char buf[10];
261 size_t len;
262 unsigned long value;
263 int ret;
264
265 mutex_lock(&wl->mutex);
266
267 len = min(count, sizeof(buf) - 1);
268 if (copy_from_user(buf, user_buf, len)) {
269 ret = -EFAULT;
270 goto out;
271 }
272 buf[len] = '\0';
273
274 ret = strict_strtoul(buf, 0, &value);
275 if (ret < 0) {
276 wl1271_warning("illegal value in gpio_power");
277 goto out;
278 }
279
280 if (value) {
281 wl->set_power(true);
282 set_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
283 } else {
284 wl->set_power(false);
285 clear_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
286 }
287
288out:
289 mutex_unlock(&wl->mutex);
290 return count;
291}
292
293static const struct file_operations gpio_power_ops = {
294 .read = gpio_power_read,
295 .write = gpio_power_write,
296 .open = wl1271_open_file_generic
297};
298
240static void wl1271_debugfs_delete_files(struct wl1271 *wl) 299static void wl1271_debugfs_delete_files(struct wl1271 *wl)
241{ 300{
242 DEBUGFS_FWSTATS_DEL(tx, internal_desc_overflow); 301 DEBUGFS_FWSTATS_DEL(tx, internal_desc_overflow);
@@ -333,6 +392,8 @@ static void wl1271_debugfs_delete_files(struct wl1271 *wl)
333 DEBUGFS_DEL(tx_queue_len); 392 DEBUGFS_DEL(tx_queue_len);
334 DEBUGFS_DEL(retry_count); 393 DEBUGFS_DEL(retry_count);
335 DEBUGFS_DEL(excessive_retries); 394 DEBUGFS_DEL(excessive_retries);
395
396 DEBUGFS_DEL(gpio_power);
336} 397}
337 398
338static int wl1271_debugfs_add_files(struct wl1271 *wl) 399static int wl1271_debugfs_add_files(struct wl1271 *wl)
@@ -434,6 +495,8 @@ static int wl1271_debugfs_add_files(struct wl1271 *wl)
434 DEBUGFS_ADD(retry_count, wl->debugfs.rootdir); 495 DEBUGFS_ADD(retry_count, wl->debugfs.rootdir);
435 DEBUGFS_ADD(excessive_retries, wl->debugfs.rootdir); 496 DEBUGFS_ADD(excessive_retries, wl->debugfs.rootdir);
436 497
498 DEBUGFS_ADD(gpio_power, wl->debugfs.rootdir);
499
437out: 500out:
438 if (ret < 0) 501 if (ret < 0)
439 wl1271_debugfs_delete_files(wl); 502 wl1271_debugfs_delete_files(wl);
diff --git a/drivers/net/wireless/wl12xx/wl1271_event.c b/drivers/net/wireless/wl12xx/wl1271_event.c
index f3afd4a6ff33..7468ef10194b 100644
--- a/drivers/net/wireless/wl12xx/wl1271_event.c
+++ b/drivers/net/wireless/wl12xx/wl1271_event.c
@@ -24,25 +24,125 @@
24#include "wl1271.h" 24#include "wl1271.h"
25#include "wl1271_reg.h" 25#include "wl1271_reg.h"
26#include "wl1271_spi.h" 26#include "wl1271_spi.h"
27#include "wl1271_io.h"
27#include "wl1271_event.h" 28#include "wl1271_event.h"
28#include "wl1271_ps.h" 29#include "wl1271_ps.h"
30#include "wl12xx_80211.h"
29 31
30static int wl1271_event_scan_complete(struct wl1271 *wl, 32static int wl1271_event_scan_complete(struct wl1271 *wl,
31 struct event_mailbox *mbox) 33 struct event_mailbox *mbox)
32{ 34{
35 int size = sizeof(struct wl12xx_probe_req_template);
33 wl1271_debug(DEBUG_EVENT, "status: 0x%x", 36 wl1271_debug(DEBUG_EVENT, "status: 0x%x",
34 mbox->scheduled_scan_status); 37 mbox->scheduled_scan_status);
35 38
36 if (wl->scanning) { 39 if (test_bit(WL1271_FLAG_SCANNING, &wl->flags)) {
37 mutex_unlock(&wl->mutex); 40 if (wl->scan.state == WL1271_SCAN_BAND_DUAL) {
38 ieee80211_scan_completed(wl->hw, false); 41 wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4,
39 mutex_lock(&wl->mutex); 42 NULL, size);
40 wl->scanning = false; 43 /* 2.4 GHz band scanned, scan 5 GHz band, pretend
44 * to the wl1271_cmd_scan function that we are not
45 * scanning as it checks that.
46 */
47 clear_bit(WL1271_FLAG_SCANNING, &wl->flags);
48 wl1271_cmd_scan(wl, wl->scan.ssid, wl->scan.ssid_len,
49 wl->scan.active,
50 wl->scan.high_prio,
51 WL1271_SCAN_BAND_5_GHZ,
52 wl->scan.probe_requests);
53 } else {
54 if (wl->scan.state == WL1271_SCAN_BAND_2_4_GHZ)
55 wl1271_cmd_template_set(wl,
56 CMD_TEMPL_CFG_PROBE_REQ_2_4,
57 NULL, size);
58 else
59 wl1271_cmd_template_set(wl,
60 CMD_TEMPL_CFG_PROBE_REQ_5,
61 NULL, size);
62
63 mutex_unlock(&wl->mutex);
64 ieee80211_scan_completed(wl->hw, false);
65 mutex_lock(&wl->mutex);
66 clear_bit(WL1271_FLAG_SCANNING, &wl->flags);
67 }
41 } 68 }
42
43 return 0; 69 return 0;
44} 70}
45 71
72static int wl1271_event_ps_report(struct wl1271 *wl,
73 struct event_mailbox *mbox,
74 bool *beacon_loss)
75{
76 int ret = 0;
77
78 wl1271_debug(DEBUG_EVENT, "ps_status: 0x%x", mbox->ps_status);
79
80 switch (mbox->ps_status) {
81 case EVENT_ENTER_POWER_SAVE_FAIL:
82 wl1271_debug(DEBUG_PSM, "PSM entry failed");
83
84 if (!test_bit(WL1271_FLAG_PSM, &wl->flags)) {
85 /* remain in active mode */
86 wl->psm_entry_retry = 0;
87 break;
88 }
89
90 if (wl->psm_entry_retry < wl->conf.conn.psm_entry_retries) {
91 wl->psm_entry_retry++;
92 ret = wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE,
93 true);
94 } else {
95 wl1271_error("PSM entry failed, giving up.\n");
96 /* FIXME: this may need to be reconsidered. for now it
97 is not possible to indicate to the mac80211
98 afterwards that PSM entry failed. To maximize
99 functionality (receiving data and remaining
100 associated) make sure that we are in sync with the
101 AP in regard of PSM mode. */
102 ret = wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE,
103 false);
104 wl->psm_entry_retry = 0;
105 }
106 break;
107 case EVENT_ENTER_POWER_SAVE_SUCCESS:
108 wl->psm_entry_retry = 0;
109
110 /* enable beacon filtering */
111 ret = wl1271_acx_beacon_filter_opt(wl, true);
112 if (ret < 0)
113 break;
114
115 /* enable beacon early termination */
116 ret = wl1271_acx_bet_enable(wl, true);
117 if (ret < 0)
118 break;
119
120 /* go to extremely low power mode */
121 wl1271_ps_elp_sleep(wl);
122 if (ret < 0)
123 break;
124 break;
125 case EVENT_EXIT_POWER_SAVE_FAIL:
126 wl1271_debug(DEBUG_PSM, "PSM exit failed");
127
128 if (test_bit(WL1271_FLAG_PSM, &wl->flags)) {
129 wl->psm_entry_retry = 0;
130 break;
131 }
132
133 /* make sure the firmware goes to active mode - the frame to
134 be sent next will indicate to the AP, that we are active. */
135 ret = wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE,
136 false);
137 break;
138 case EVENT_EXIT_POWER_SAVE_SUCCESS:
139 default:
140 break;
141 }
142
143 return ret;
144}
145
46static void wl1271_event_mbox_dump(struct event_mailbox *mbox) 146static void wl1271_event_mbox_dump(struct event_mailbox *mbox)
47{ 147{
48 wl1271_debug(DEBUG_EVENT, "MBOX DUMP:"); 148 wl1271_debug(DEBUG_EVENT, "MBOX DUMP:");
@@ -54,10 +154,12 @@ static int wl1271_event_process(struct wl1271 *wl, struct event_mailbox *mbox)
54{ 154{
55 int ret; 155 int ret;
56 u32 vector; 156 u32 vector;
157 bool beacon_loss = false;
57 158
58 wl1271_event_mbox_dump(mbox); 159 wl1271_event_mbox_dump(mbox);
59 160
60 vector = mbox->events_vector & ~(mbox->events_mask); 161 vector = le32_to_cpu(mbox->events_vector);
162 vector &= ~(le32_to_cpu(mbox->events_mask));
61 wl1271_debug(DEBUG_EVENT, "vector: 0x%x", vector); 163 wl1271_debug(DEBUG_EVENT, "vector: 0x%x", vector);
62 164
63 if (vector & SCAN_COMPLETE_EVENT_ID) { 165 if (vector & SCAN_COMPLETE_EVENT_ID) {
@@ -66,14 +168,35 @@ static int wl1271_event_process(struct wl1271 *wl, struct event_mailbox *mbox)
66 return ret; 168 return ret;
67 } 169 }
68 170
69 if (vector & BSS_LOSE_EVENT_ID) { 171 /*
172 * The BSS_LOSE_EVENT_ID is only needed while psm (and hence beacon
173 * filtering) is enabled. Without PSM, the stack will receive all
174 * beacons and can detect beacon loss by itself.
175 */
176 if (vector & BSS_LOSE_EVENT_ID &&
177 test_bit(WL1271_FLAG_PSM, &wl->flags)) {
70 wl1271_debug(DEBUG_EVENT, "BSS_LOSE_EVENT"); 178 wl1271_debug(DEBUG_EVENT, "BSS_LOSE_EVENT");
71 179
72 if (wl->psm_requested && wl->psm) { 180 /* indicate to the stack, that beacons have been lost */
73 ret = wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE); 181 beacon_loss = true;
74 if (ret < 0) 182 }
75 return ret; 183
76 } 184 if (vector & PS_REPORT_EVENT_ID) {
185 wl1271_debug(DEBUG_EVENT, "PS_REPORT_EVENT");
186 ret = wl1271_event_ps_report(wl, mbox, &beacon_loss);
187 if (ret < 0)
188 return ret;
189 }
190
191 if (wl->vif && beacon_loss) {
192 /* Obviously, it's dangerous to release the mutex while
193 we are holding many of the variables in the wl struct.
194 That's why it's done last in the function, and care must
195 be taken that nothing more is done after this function
196 returns. */
197 mutex_unlock(&wl->mutex);
198 ieee80211_beacon_loss(wl->vif);
199 mutex_lock(&wl->mutex);
77 } 200 }
78 201
79 return 0; 202 return 0;
@@ -92,7 +215,7 @@ int wl1271_event_unmask(struct wl1271 *wl)
92 215
93void wl1271_event_mbox_config(struct wl1271 *wl) 216void wl1271_event_mbox_config(struct wl1271 *wl)
94{ 217{
95 wl->mbox_ptr[0] = wl1271_reg_read32(wl, REG_EVENT_MAILBOX_PTR); 218 wl->mbox_ptr[0] = wl1271_read32(wl, REG_EVENT_MAILBOX_PTR);
96 wl->mbox_ptr[1] = wl->mbox_ptr[0] + sizeof(struct event_mailbox); 219 wl->mbox_ptr[1] = wl->mbox_ptr[0] + sizeof(struct event_mailbox);
97 220
98 wl1271_debug(DEBUG_EVENT, "MBOX ptrs: 0x%x 0x%x", 221 wl1271_debug(DEBUG_EVENT, "MBOX ptrs: 0x%x 0x%x",
@@ -110,8 +233,8 @@ int wl1271_event_handle(struct wl1271 *wl, u8 mbox_num)
110 return -EINVAL; 233 return -EINVAL;
111 234
112 /* first we read the mbox descriptor */ 235 /* first we read the mbox descriptor */
113 wl1271_spi_mem_read(wl, wl->mbox_ptr[mbox_num], &mbox, 236 wl1271_read(wl, wl->mbox_ptr[mbox_num], &mbox,
114 sizeof(struct event_mailbox)); 237 sizeof(struct event_mailbox), false);
115 238
116 /* process the descriptor */ 239 /* process the descriptor */
117 ret = wl1271_event_process(wl, &mbox); 240 ret = wl1271_event_process(wl, &mbox);
@@ -119,7 +242,7 @@ int wl1271_event_handle(struct wl1271 *wl, u8 mbox_num)
119 return ret; 242 return ret;
120 243
121 /* then we let the firmware know it can go on...*/ 244 /* then we let the firmware know it can go on...*/
122 wl1271_reg_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_EVENT_ACK); 245 wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_EVENT_ACK);
123 246
124 return 0; 247 return 0;
125} 248}
diff --git a/drivers/net/wireless/wl12xx/wl1271_event.h b/drivers/net/wireless/wl12xx/wl1271_event.h
index 2cdce7c34bf0..278f9206aa56 100644
--- a/drivers/net/wireless/wl12xx/wl1271_event.h
+++ b/drivers/net/wireless/wl12xx/wl1271_event.h
@@ -63,36 +63,43 @@ enum {
63 EVENT_MBOX_ALL_EVENT_ID = 0x7fffffff, 63 EVENT_MBOX_ALL_EVENT_ID = 0x7fffffff,
64}; 64};
65 65
66enum {
67 EVENT_ENTER_POWER_SAVE_FAIL = 0,
68 EVENT_ENTER_POWER_SAVE_SUCCESS,
69 EVENT_EXIT_POWER_SAVE_FAIL,
70 EVENT_EXIT_POWER_SAVE_SUCCESS,
71};
72
66struct event_debug_report { 73struct event_debug_report {
67 u8 debug_event_id; 74 u8 debug_event_id;
68 u8 num_params; 75 u8 num_params;
69 u16 pad; 76 __le16 pad;
70 u32 report_1; 77 __le32 report_1;
71 u32 report_2; 78 __le32 report_2;
72 u32 report_3; 79 __le32 report_3;
73} __attribute__ ((packed)); 80} __attribute__ ((packed));
74 81
75#define NUM_OF_RSSI_SNR_TRIGGERS 8 82#define NUM_OF_RSSI_SNR_TRIGGERS 8
76 83
77struct event_mailbox { 84struct event_mailbox {
78 u32 events_vector; 85 __le32 events_vector;
79 u32 events_mask; 86 __le32 events_mask;
80 u32 reserved_1; 87 __le32 reserved_1;
81 u32 reserved_2; 88 __le32 reserved_2;
82 89
83 u8 dbg_event_id; 90 u8 dbg_event_id;
84 u8 num_relevant_params; 91 u8 num_relevant_params;
85 u16 reserved_3; 92 __le16 reserved_3;
86 u32 event_report_p1; 93 __le32 event_report_p1;
87 u32 event_report_p2; 94 __le32 event_report_p2;
88 u32 event_report_p3; 95 __le32 event_report_p3;
89 96
90 u8 number_of_scan_results; 97 u8 number_of_scan_results;
91 u8 scan_tag; 98 u8 scan_tag;
92 u8 reserved_4[2]; 99 u8 reserved_4[2];
93 u32 compl_scheduled_scan_status; 100 __le32 compl_scheduled_scan_status;
94 101
95 u16 scheduled_scan_attended_channels; 102 __le16 scheduled_scan_attended_channels;
96 u8 soft_gemini_sense_info; 103 u8 soft_gemini_sense_info;
97 u8 soft_gemini_protective_info; 104 u8 soft_gemini_protective_info;
98 s8 rssi_snr_trigger_metric[NUM_OF_RSSI_SNR_TRIGGERS]; 105 s8 rssi_snr_trigger_metric[NUM_OF_RSSI_SNR_TRIGGERS];
diff --git a/drivers/net/wireless/wl12xx/wl1271_init.c b/drivers/net/wireless/wl12xx/wl1271_init.c
index 490df217605a..d189e8fe05a6 100644
--- a/drivers/net/wireless/wl12xx/wl1271_init.c
+++ b/drivers/net/wireless/wl12xx/wl1271_init.c
@@ -23,6 +23,7 @@
23 23
24#include <linux/kernel.h> 24#include <linux/kernel.h>
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/slab.h>
26 27
27#include "wl1271_init.h" 28#include "wl1271_init.h"
28#include "wl12xx_80211.h" 29#include "wl12xx_80211.h"
@@ -49,7 +50,7 @@ static int wl1271_init_hwenc_config(struct wl1271 *wl)
49 return 0; 50 return 0;
50} 51}
51 52
52static int wl1271_init_templates_config(struct wl1271 *wl) 53int wl1271_init_templates_config(struct wl1271 *wl)
53{ 54{
54 int ret; 55 int ret;
55 56
@@ -59,6 +60,14 @@ static int wl1271_init_templates_config(struct wl1271 *wl)
59 if (ret < 0) 60 if (ret < 0)
60 return ret; 61 return ret;
61 62
63 if (wl1271_11a_enabled()) {
64 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
65 NULL,
66 sizeof(struct wl12xx_probe_req_template));
67 if (ret < 0)
68 return ret;
69 }
70
62 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, NULL, 71 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, NULL,
63 sizeof(struct wl12xx_null_data_template)); 72 sizeof(struct wl12xx_null_data_template));
64 if (ret < 0) 73 if (ret < 0)
@@ -94,7 +103,7 @@ static int wl1271_init_rx_config(struct wl1271 *wl, u32 config, u32 filter)
94{ 103{
95 int ret; 104 int ret;
96 105
97 ret = wl1271_acx_rx_msdu_life_time(wl, RX_MSDU_LIFETIME_DEF); 106 ret = wl1271_acx_rx_msdu_life_time(wl);
98 if (ret < 0) 107 if (ret < 0)
99 return ret; 108 return ret;
100 109
@@ -105,7 +114,7 @@ static int wl1271_init_rx_config(struct wl1271 *wl, u32 config, u32 filter)
105 return 0; 114 return 0;
106} 115}
107 116
108static int wl1271_init_phy_config(struct wl1271 *wl) 117int wl1271_init_phy_config(struct wl1271 *wl)
109{ 118{
110 int ret; 119 int ret;
111 120
@@ -117,7 +126,7 @@ static int wl1271_init_phy_config(struct wl1271 *wl)
117 if (ret < 0) 126 if (ret < 0)
118 return ret; 127 return ret;
119 128
120 ret = wl1271_acx_group_address_tbl(wl); 129 ret = wl1271_acx_group_address_tbl(wl, true, NULL, 0);
121 if (ret < 0) 130 if (ret < 0)
122 return ret; 131 return ret;
123 132
@@ -125,7 +134,7 @@ static int wl1271_init_phy_config(struct wl1271 *wl)
125 if (ret < 0) 134 if (ret < 0)
126 return ret; 135 return ret;
127 136
128 ret = wl1271_acx_rts_threshold(wl, RTS_THRESHOLD_DEF); 137 ret = wl1271_acx_rts_threshold(wl, wl->conf.rx.rts_threshold);
129 if (ret < 0) 138 if (ret < 0)
130 return ret; 139 return ret;
131 140
@@ -136,7 +145,8 @@ static int wl1271_init_beacon_filter(struct wl1271 *wl)
136{ 145{
137 int ret; 146 int ret;
138 147
139 ret = wl1271_acx_beacon_filter_opt(wl); 148 /* disable beacon filtering at this stage */
149 ret = wl1271_acx_beacon_filter_opt(wl, false);
140 if (ret < 0) 150 if (ret < 0)
141 return ret; 151 return ret;
142 152
@@ -147,7 +157,7 @@ static int wl1271_init_beacon_filter(struct wl1271 *wl)
147 return 0; 157 return 0;
148} 158}
149 159
150static int wl1271_init_pta(struct wl1271 *wl) 160int wl1271_init_pta(struct wl1271 *wl)
151{ 161{
152 int ret; 162 int ret;
153 163
@@ -162,7 +172,7 @@ static int wl1271_init_pta(struct wl1271 *wl)
162 return 0; 172 return 0;
163} 173}
164 174
165static int wl1271_init_energy_detection(struct wl1271 *wl) 175int wl1271_init_energy_detection(struct wl1271 *wl)
166{ 176{
167 int ret; 177 int ret;
168 178
@@ -184,118 +194,17 @@ static int wl1271_init_beacon_broadcast(struct wl1271 *wl)
184 return 0; 194 return 0;
185} 195}
186 196
187static int wl1271_init_general_parms(struct wl1271 *wl)
188{
189 struct wl1271_general_parms *gen_parms;
190 int ret;
191
192 gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
193 if (!gen_parms)
194 return -ENOMEM;
195
196 gen_parms->id = TEST_CMD_INI_FILE_GENERAL_PARAM;
197
198 gen_parms->ref_clk = REF_CLK_38_4_E;
199 /* FIXME: magic numbers */
200 gen_parms->settling_time = 5;
201 gen_parms->clk_valid_on_wakeup = 0;
202 gen_parms->dc2dcmode = 0;
203 gen_parms->single_dual_band = 0;
204 gen_parms->tx_bip_fem_autodetect = 1;
205 gen_parms->tx_bip_fem_manufacturer = 1;
206 gen_parms->settings = 1;
207
208 ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), 0);
209 if (ret < 0) {
210 wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
211 return ret;
212 }
213
214 kfree(gen_parms);
215 return 0;
216}
217
218static int wl1271_init_radio_parms(struct wl1271 *wl)
219{
220 /*
221 * FIXME: All these magic numbers should be moved to some place where
222 * they can be configured (separate file?)
223 */
224
225 struct wl1271_radio_parms *radio_parms;
226 int ret;
227 u8 compensation[] = { 0xec, 0xf6, 0x00, 0x0c, 0x18, 0xf8, 0xfc, 0x00,
228 0x08, 0x10, 0xf0, 0xf8, 0x00, 0x0a, 0x14 };
229
230 u8 tx_rate_limits_normal[] = { 0x1e, 0x1f, 0x22, 0x24, 0x28, 0x29 };
231 u8 tx_rate_limits_degraded[] = { 0x1b, 0x1c, 0x1e, 0x20, 0x24, 0x25 };
232
233 u8 tx_channel_limits_11b[] = { 0x22, 0x50, 0x50, 0x50,
234 0x50, 0x50, 0x50, 0x50,
235 0x50, 0x50, 0x22, 0x50,
236 0x22, 0x50 };
237
238 u8 tx_channel_limits_ofdm[] = { 0x20, 0x50, 0x50, 0x50,
239 0x50, 0x50, 0x50, 0x50,
240 0x50, 0x50, 0x20, 0x50,
241 0x20, 0x50 };
242
243 u8 tx_pdv_rate_offsets[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
244
245 u8 tx_ibias[] = { 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x27 };
246
247 radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
248 if (!radio_parms)
249 return -ENOMEM;
250
251 radio_parms->id = TEST_CMD_INI_FILE_RADIO_PARAM;
252
253 /* Static radio parameters */
254 radio_parms->rx_trace_loss = 10;
255 radio_parms->tx_trace_loss = 10;
256 memcpy(radio_parms->rx_rssi_and_proc_compens, compensation,
257 sizeof(compensation));
258
259 /* We don't set the 5GHz -- N/A */
260
261 /* Dynamic radio parameters */
262 radio_parms->tx_ref_pd_voltage = cpu_to_le16(0x24e);
263 radio_parms->tx_ref_power = 0x78;
264 radio_parms->tx_offset_db = 0x0;
265
266 memcpy(radio_parms->tx_rate_limits_normal, tx_rate_limits_normal,
267 sizeof(tx_rate_limits_normal));
268 memcpy(radio_parms->tx_rate_limits_degraded, tx_rate_limits_degraded,
269 sizeof(tx_rate_limits_degraded));
270
271 memcpy(radio_parms->tx_channel_limits_11b, tx_channel_limits_11b,
272 sizeof(tx_channel_limits_11b));
273 memcpy(radio_parms->tx_channel_limits_ofdm, tx_channel_limits_ofdm,
274 sizeof(tx_channel_limits_ofdm));
275 memcpy(radio_parms->tx_pdv_rate_offsets, tx_pdv_rate_offsets,
276 sizeof(tx_pdv_rate_offsets));
277 memcpy(radio_parms->tx_ibias, tx_ibias,
278 sizeof(tx_ibias));
279
280 radio_parms->rx_fem_insertion_loss = 0x14;
281
282 ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
283 if (ret < 0)
284 wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
285
286 kfree(radio_parms);
287 return ret;
288}
289
290int wl1271_hw_init(struct wl1271 *wl) 197int wl1271_hw_init(struct wl1271 *wl)
291{ 198{
292 int ret; 199 struct conf_tx_ac_category *conf_ac;
200 struct conf_tx_tid *conf_tid;
201 int ret, i;
293 202
294 ret = wl1271_init_general_parms(wl); 203 ret = wl1271_cmd_general_parms(wl);
295 if (ret < 0) 204 if (ret < 0)
296 return ret; 205 return ret;
297 206
298 ret = wl1271_init_radio_parms(wl); 207 ret = wl1271_cmd_radio_parms(wl);
299 if (ret < 0) 208 if (ret < 0)
300 return ret; 209 return ret;
301 210
@@ -311,8 +220,8 @@ int wl1271_hw_init(struct wl1271 *wl)
311 220
312 /* RX config */ 221 /* RX config */
313 ret = wl1271_init_rx_config(wl, 222 ret = wl1271_init_rx_config(wl,
314 RX_CFG_PROMISCUOUS | RX_CFG_TSF, 223 RX_CFG_PROMISCUOUS | RX_CFG_TSF,
315 RX_FILTER_OPTION_DEF); 224 RX_FILTER_OPTION_DEF);
316 /* RX_CONFIG_OPTION_ANY_DST_ANY_BSS, 225 /* RX_CONFIG_OPTION_ANY_DST_ANY_BSS,
317 RX_FILTER_OPTION_FILTER_ALL); */ 226 RX_FILTER_OPTION_FILTER_ALL); */
318 if (ret < 0) 227 if (ret < 0)
@@ -323,6 +232,15 @@ int wl1271_hw_init(struct wl1271 *wl)
323 if (ret < 0) 232 if (ret < 0)
324 goto out_free_memmap; 233 goto out_free_memmap;
325 234
235 ret = wl1271_acx_dco_itrim_params(wl);
236 if (ret < 0)
237 goto out_free_memmap;
238
239 /* Initialize connection monitoring thresholds */
240 ret = wl1271_acx_conn_monit_params(wl);
241 if (ret < 0)
242 goto out_free_memmap;
243
326 /* Beacon filtering */ 244 /* Beacon filtering */
327 ret = wl1271_init_beacon_filter(wl); 245 ret = wl1271_init_beacon_filter(wl);
328 if (ret < 0) 246 if (ret < 0)
@@ -359,14 +277,28 @@ int wl1271_hw_init(struct wl1271 *wl)
359 goto out_free_memmap; 277 goto out_free_memmap;
360 278
361 /* Default TID configuration */ 279 /* Default TID configuration */
362 ret = wl1271_acx_tid_cfg(wl); 280 for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
363 if (ret < 0) 281 conf_tid = &wl->conf.tx.tid_conf[i];
364 goto out_free_memmap; 282 ret = wl1271_acx_tid_cfg(wl, conf_tid->queue_id,
283 conf_tid->channel_type,
284 conf_tid->tsid,
285 conf_tid->ps_scheme,
286 conf_tid->ack_policy,
287 conf_tid->apsd_conf[0],
288 conf_tid->apsd_conf[1]);
289 if (ret < 0)
290 goto out_free_memmap;
291 }
365 292
366 /* Default AC configuration */ 293 /* Default AC configuration */
367 ret = wl1271_acx_ac_cfg(wl); 294 for (i = 0; i < wl->conf.tx.ac_conf_count; i++) {
368 if (ret < 0) 295 conf_ac = &wl->conf.tx.ac_conf[i];
369 goto out_free_memmap; 296 ret = wl1271_acx_ac_cfg(wl, conf_ac->ac, conf_ac->cw_min,
297 conf_ac->cw_max, conf_ac->aifsn,
298 conf_ac->tx_op_limit);
299 if (ret < 0)
300 goto out_free_memmap;
301 }
370 302
371 /* Configure TX rate classes */ 303 /* Configure TX rate classes */
372 ret = wl1271_acx_rate_policies(wl); 304 ret = wl1271_acx_rate_policies(wl);
@@ -374,7 +306,7 @@ int wl1271_hw_init(struct wl1271 *wl)
374 goto out_free_memmap; 306 goto out_free_memmap;
375 307
376 /* Enable data path */ 308 /* Enable data path */
377 ret = wl1271_cmd_data_path(wl, wl->channel, 1); 309 ret = wl1271_cmd_data_path(wl, 1);
378 if (ret < 0) 310 if (ret < 0)
379 goto out_free_memmap; 311 goto out_free_memmap;
380 312
@@ -388,10 +320,16 @@ int wl1271_hw_init(struct wl1271 *wl)
388 if (ret < 0) 320 if (ret < 0)
389 goto out_free_memmap; 321 goto out_free_memmap;
390 322
323 /* configure PM */
324 ret = wl1271_acx_pm_config(wl);
325 if (ret < 0)
326 goto out_free_memmap;
327
391 return 0; 328 return 0;
392 329
393 out_free_memmap: 330 out_free_memmap:
394 kfree(wl->target_mem_map); 331 kfree(wl->target_mem_map);
332 wl->target_mem_map = NULL;
395 333
396 return ret; 334 return ret;
397} 335}
diff --git a/drivers/net/wireless/wl12xx/wl1271_init.h b/drivers/net/wireless/wl12xx/wl1271_init.h
index bd8ff0fa2272..bc26f8c53b91 100644
--- a/drivers/net/wireless/wl12xx/wl1271_init.h
+++ b/drivers/net/wireless/wl12xx/wl1271_init.h
@@ -27,89 +27,10 @@
27#include "wl1271.h" 27#include "wl1271.h"
28 28
29int wl1271_hw_init_power_auth(struct wl1271 *wl); 29int wl1271_hw_init_power_auth(struct wl1271 *wl);
30int wl1271_init_templates_config(struct wl1271 *wl);
31int wl1271_init_phy_config(struct wl1271 *wl);
32int wl1271_init_pta(struct wl1271 *wl);
33int wl1271_init_energy_detection(struct wl1271 *wl);
30int wl1271_hw_init(struct wl1271 *wl); 34int wl1271_hw_init(struct wl1271 *wl);
31 35
32/* These are not really a TEST_CMD, but the ref driver uses them as such */
33#define TEST_CMD_INI_FILE_RADIO_PARAM 0x19
34#define TEST_CMD_INI_FILE_GENERAL_PARAM 0x1E
35
36struct wl1271_general_parms {
37 u8 id;
38 u8 padding[3];
39
40 u8 ref_clk;
41 u8 settling_time;
42 u8 clk_valid_on_wakeup;
43 u8 dc2dcmode;
44 u8 single_dual_band;
45
46 u8 tx_bip_fem_autodetect;
47 u8 tx_bip_fem_manufacturer;
48 u8 settings;
49} __attribute__ ((packed));
50
51enum ref_clk_enum {
52 REF_CLK_19_2_E,
53 REF_CLK_26_E,
54 REF_CLK_38_4_E,
55 REF_CLK_52_E
56};
57
58#define RSSI_AND_PROCESS_COMPENSATION_SIZE 15
59#define NUMBER_OF_SUB_BANDS_5 7
60#define NUMBER_OF_RATE_GROUPS 6
61#define NUMBER_OF_CHANNELS_2_4 14
62#define NUMBER_OF_CHANNELS_5 35
63
64struct wl1271_radio_parms {
65 u8 id;
66 u8 padding[3];
67
68 /* Static radio parameters */
69 /* 2.4GHz */
70 u8 rx_trace_loss;
71 u8 tx_trace_loss;
72 s8 rx_rssi_and_proc_compens[RSSI_AND_PROCESS_COMPENSATION_SIZE];
73
74 /* 5GHz */
75 u8 rx_trace_loss_5[NUMBER_OF_SUB_BANDS_5];
76 u8 tx_trace_loss_5[NUMBER_OF_SUB_BANDS_5];
77 s8 rx_rssi_and_proc_compens_5[RSSI_AND_PROCESS_COMPENSATION_SIZE];
78
79 /* Dynamic radio parameters */
80 /* 2.4GHz */
81 s16 tx_ref_pd_voltage;
82 s8 tx_ref_power;
83 s8 tx_offset_db;
84
85 s8 tx_rate_limits_normal[NUMBER_OF_RATE_GROUPS];
86 s8 tx_rate_limits_degraded[NUMBER_OF_RATE_GROUPS];
87
88 s8 tx_channel_limits_11b[NUMBER_OF_CHANNELS_2_4];
89 s8 tx_channel_limits_ofdm[NUMBER_OF_CHANNELS_2_4];
90 s8 tx_pdv_rate_offsets[NUMBER_OF_RATE_GROUPS];
91
92 u8 tx_ibias[NUMBER_OF_RATE_GROUPS];
93 u8 rx_fem_insertion_loss;
94
95 u8 padding2;
96
97 /* 5GHz */
98 s16 tx_ref_pd_voltage_5[NUMBER_OF_SUB_BANDS_5];
99 s8 tx_ref_power_5[NUMBER_OF_SUB_BANDS_5];
100 s8 tx_offset_db_5[NUMBER_OF_SUB_BANDS_5];
101
102 s8 tx_rate_limits_normal_5[NUMBER_OF_RATE_GROUPS];
103 s8 tx_rate_limits_degraded_5[NUMBER_OF_RATE_GROUPS];
104
105 s8 tx_channel_limits_ofdm_5[NUMBER_OF_CHANNELS_5];
106 s8 tx_pdv_rate_offsets_5[NUMBER_OF_RATE_GROUPS];
107
108 /* FIXME: this is inconsistent with the types for 2.4GHz */
109 s8 tx_ibias_5[NUMBER_OF_RATE_GROUPS];
110 s8 rx_fem_insertion_loss_5[NUMBER_OF_SUB_BANDS_5];
111
112 u8 padding3[2];
113} __attribute__ ((packed));
114
115#endif 36#endif
diff --git a/drivers/net/wireless/wl12xx/wl1271_io.c b/drivers/net/wireless/wl12xx/wl1271_io.c
new file mode 100644
index 000000000000..5cd94d5666c2
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/wl1271_io.c
@@ -0,0 +1,213 @@
1/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 2008-2010 Nokia Corporation
5 *
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
24#include <linux/module.h>
25#include <linux/platform_device.h>
26#include <linux/crc7.h>
27#include <linux/spi/spi.h>
28
29#include "wl1271.h"
30#include "wl12xx_80211.h"
31#include "wl1271_spi.h"
32#include "wl1271_io.h"
33
34static int wl1271_translate_addr(struct wl1271 *wl, int addr)
35{
36 /*
37 * To translate, first check to which window of addresses the
38 * particular address belongs. Then subtract the starting address
39 * of that window from the address. Then, add offset of the
40 * translated region.
41 *
42 * The translated regions occur next to each other in physical device
43 * memory, so just add the sizes of the preceeding address regions to
44 * get the offset to the new region.
45 *
46 * Currently, only the two first regions are addressed, and the
47 * assumption is that all addresses will fall into either of those
48 * two.
49 */
50 if ((addr >= wl->part.reg.start) &&
51 (addr < wl->part.reg.start + wl->part.reg.size))
52 return addr - wl->part.reg.start + wl->part.mem.size;
53 else
54 return addr - wl->part.mem.start;
55}
56
57/* Set the SPI partitions to access the chip addresses
58 *
59 * To simplify driver code, a fixed (virtual) memory map is defined for
60 * register and memory addresses. Because in the chipset, in different stages
61 * of operation, those addresses will move around, an address translation
62 * mechanism is required.
63 *
64 * There are four partitions (three memory and one register partition),
65 * which are mapped to two different areas of the hardware memory.
66 *
67 * Virtual address
68 * space
69 *
70 * | |
71 * ...+----+--> mem.start
72 * Physical address ... | |
73 * space ... | | [PART_0]
74 * ... | |
75 * 00000000 <--+----+... ...+----+--> mem.start + mem.size
76 * | | ... | |
77 * |MEM | ... | |
78 * | | ... | |
79 * mem.size <--+----+... | | {unused area)
80 * | | ... | |
81 * |REG | ... | |
82 * mem.size | | ... | |
83 * + <--+----+... ...+----+--> reg.start
84 * reg.size | | ... | |
85 * |MEM2| ... | | [PART_1]
86 * | | ... | |
87 * ...+----+--> reg.start + reg.size
88 * | |
89 *
90 */
91int wl1271_set_partition(struct wl1271 *wl,
92 struct wl1271_partition_set *p)
93{
94 /* copy partition info */
95 memcpy(&wl->part, p, sizeof(*p));
96
97 wl1271_debug(DEBUG_SPI, "mem_start %08X mem_size %08X",
98 p->mem.start, p->mem.size);
99 wl1271_debug(DEBUG_SPI, "reg_start %08X reg_size %08X",
100 p->reg.start, p->reg.size);
101 wl1271_debug(DEBUG_SPI, "mem2_start %08X mem2_size %08X",
102 p->mem2.start, p->mem2.size);
103 wl1271_debug(DEBUG_SPI, "mem3_start %08X mem3_size %08X",
104 p->mem3.start, p->mem3.size);
105
106 /* write partition info to the chipset */
107 wl1271_raw_write32(wl, HW_PART0_START_ADDR, p->mem.start);
108 wl1271_raw_write32(wl, HW_PART0_SIZE_ADDR, p->mem.size);
109 wl1271_raw_write32(wl, HW_PART1_START_ADDR, p->reg.start);
110 wl1271_raw_write32(wl, HW_PART1_SIZE_ADDR, p->reg.size);
111 wl1271_raw_write32(wl, HW_PART2_START_ADDR, p->mem2.start);
112 wl1271_raw_write32(wl, HW_PART2_SIZE_ADDR, p->mem2.size);
113 wl1271_raw_write32(wl, HW_PART3_START_ADDR, p->mem3.start);
114
115 return 0;
116}
117
118void wl1271_io_reset(struct wl1271 *wl)
119{
120 wl1271_spi_reset(wl);
121}
122
123void wl1271_io_init(struct wl1271 *wl)
124{
125 wl1271_spi_init(wl);
126}
127
128void wl1271_raw_write(struct wl1271 *wl, int addr, void *buf,
129 size_t len, bool fixed)
130{
131 wl1271_spi_raw_write(wl, addr, buf, len, fixed);
132}
133
134void wl1271_raw_read(struct wl1271 *wl, int addr, void *buf,
135 size_t len, bool fixed)
136{
137 wl1271_spi_raw_read(wl, addr, buf, len, fixed);
138}
139
140void wl1271_read(struct wl1271 *wl, int addr, void *buf, size_t len,
141 bool fixed)
142{
143 int physical;
144
145 physical = wl1271_translate_addr(wl, addr);
146
147 wl1271_spi_raw_read(wl, physical, buf, len, fixed);
148}
149
150void wl1271_write(struct wl1271 *wl, int addr, void *buf, size_t len,
151 bool fixed)
152{
153 int physical;
154
155 physical = wl1271_translate_addr(wl, addr);
156
157 wl1271_spi_raw_write(wl, physical, buf, len, fixed);
158}
159
160u32 wl1271_read32(struct wl1271 *wl, int addr)
161{
162 return wl1271_raw_read32(wl, wl1271_translate_addr(wl, addr));
163}
164
165void wl1271_write32(struct wl1271 *wl, int addr, u32 val)
166{
167 wl1271_raw_write32(wl, wl1271_translate_addr(wl, addr), val);
168}
169
170void wl1271_top_reg_write(struct wl1271 *wl, int addr, u16 val)
171{
172 /* write address >> 1 + 0x30000 to OCP_POR_CTR */
173 addr = (addr >> 1) + 0x30000;
174 wl1271_write32(wl, OCP_POR_CTR, addr);
175
176 /* write value to OCP_POR_WDATA */
177 wl1271_write32(wl, OCP_DATA_WRITE, val);
178
179 /* write 1 to OCP_CMD */
180 wl1271_write32(wl, OCP_CMD, OCP_CMD_WRITE);
181}
182
183u16 wl1271_top_reg_read(struct wl1271 *wl, int addr)
184{
185 u32 val;
186 int timeout = OCP_CMD_LOOP;
187
188 /* write address >> 1 + 0x30000 to OCP_POR_CTR */
189 addr = (addr >> 1) + 0x30000;
190 wl1271_write32(wl, OCP_POR_CTR, addr);
191
192 /* write 2 to OCP_CMD */
193 wl1271_write32(wl, OCP_CMD, OCP_CMD_READ);
194
195 /* poll for data ready */
196 do {
197 val = wl1271_read32(wl, OCP_DATA_READ);
198 } while (!(val & OCP_READY_MASK) && --timeout);
199
200 if (!timeout) {
201 wl1271_warning("Top register access timed out.");
202 return 0xffff;
203 }
204
205 /* check data status and return if OK */
206 if ((val & OCP_STATUS_MASK) == OCP_STATUS_OK)
207 return val & 0xffff;
208 else {
209 wl1271_warning("Top register access returned error.");
210 return 0xffff;
211 }
212}
213
diff --git a/drivers/net/wireless/wl12xx/wl1271_io.h b/drivers/net/wireless/wl12xx/wl1271_io.h
new file mode 100644
index 000000000000..fa9a0b35788f
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/wl1271_io.h
@@ -0,0 +1,68 @@
1/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 1998-2009 Texas Instruments. All rights reserved.
5 * Copyright (C) 2008-2010 Nokia Corporation
6 *
7 * Contact: Luciano Coelho <luciano.coelho@nokia.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 __WL1271_IO_H__
26#define __WL1271_IO_H__
27
28struct wl1271;
29
30void wl1271_io_reset(struct wl1271 *wl);
31void wl1271_io_init(struct wl1271 *wl);
32
33/* Raw target IO, address is not translated */
34void wl1271_raw_write(struct wl1271 *wl, int addr, void *buf,
35 size_t len, bool fixed);
36void wl1271_raw_read(struct wl1271 *wl, int addr, void *buf,
37 size_t len, bool fixed);
38
39/* Translated target IO */
40void wl1271_read(struct wl1271 *wl, int addr, void *buf, size_t len,
41 bool fixed);
42void wl1271_write(struct wl1271 *wl, int addr, void *buf, size_t len,
43 bool fixed);
44u32 wl1271_read32(struct wl1271 *wl, int addr);
45void wl1271_write32(struct wl1271 *wl, int addr, u32 val);
46
47/* Top Register IO */
48void wl1271_top_reg_write(struct wl1271 *wl, int addr, u16 val);
49u16 wl1271_top_reg_read(struct wl1271 *wl, int addr);
50
51int wl1271_set_partition(struct wl1271 *wl,
52 struct wl1271_partition_set *p);
53
54static inline u32 wl1271_raw_read32(struct wl1271 *wl, int addr)
55{
56 wl1271_raw_read(wl, addr, &wl->buffer_32,
57 sizeof(wl->buffer_32), false);
58
59 return wl->buffer_32;
60}
61
62static inline void wl1271_raw_write32(struct wl1271 *wl, int addr, u32 val)
63{
64 wl->buffer_32 = val;
65 wl1271_raw_write(wl, addr, &wl->buffer_32,
66 sizeof(wl->buffer_32), false);
67}
68#endif
diff --git a/drivers/net/wireless/wl12xx/wl1271_main.c b/drivers/net/wireless/wl12xx/wl1271_main.c
index 27298b19d5bd..65a1aeba2419 100644
--- a/drivers/net/wireless/wl12xx/wl1271_main.c
+++ b/drivers/net/wireless/wl12xx/wl1271_main.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * This file is part of wl1271 2 * This file is part of wl1271
3 * 3 *
4 * Copyright (C) 2008-2009 Nokia Corporation 4 * Copyright (C) 2008-2010 Nokia Corporation
5 * 5 *
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com> 6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
7 * 7 *
@@ -30,12 +30,16 @@
30#include <linux/spi/spi.h> 30#include <linux/spi/spi.h>
31#include <linux/crc32.h> 31#include <linux/crc32.h>
32#include <linux/etherdevice.h> 32#include <linux/etherdevice.h>
33#include <linux/vmalloc.h>
33#include <linux/spi/wl12xx.h> 34#include <linux/spi/wl12xx.h>
35#include <linux/inetdevice.h>
36#include <linux/slab.h>
34 37
35#include "wl1271.h" 38#include "wl1271.h"
36#include "wl12xx_80211.h" 39#include "wl12xx_80211.h"
37#include "wl1271_reg.h" 40#include "wl1271_reg.h"
38#include "wl1271_spi.h" 41#include "wl1271_spi.h"
42#include "wl1271_io.h"
39#include "wl1271_event.h" 43#include "wl1271_event.h"
40#include "wl1271_tx.h" 44#include "wl1271_tx.h"
41#include "wl1271_rx.h" 45#include "wl1271_rx.h"
@@ -44,20 +48,321 @@
44#include "wl1271_debugfs.h" 48#include "wl1271_debugfs.h"
45#include "wl1271_cmd.h" 49#include "wl1271_cmd.h"
46#include "wl1271_boot.h" 50#include "wl1271_boot.h"
51#include "wl1271_testmode.h"
52
53#define WL1271_BOOT_RETRIES 3
54
55static struct conf_drv_settings default_conf = {
56 .sg = {
57 .per_threshold = 7500,
58 .max_scan_compensation_time = 120000,
59 .nfs_sample_interval = 400,
60 .load_ratio = 50,
61 .auto_ps_mode = 0,
62 .probe_req_compensation = 170,
63 .scan_window_compensation = 50,
64 .antenna_config = 0,
65 .beacon_miss_threshold = 60,
66 .rate_adaptation_threshold = CONF_HW_BIT_RATE_12MBPS,
67 .rate_adaptation_snr = 0
68 },
69 .rx = {
70 .rx_msdu_life_time = 512000,
71 .packet_detection_threshold = 0,
72 .ps_poll_timeout = 15,
73 .upsd_timeout = 15,
74 .rts_threshold = 2347,
75 .rx_cca_threshold = 0,
76 .irq_blk_threshold = 0xFFFF,
77 .irq_pkt_threshold = 0,
78 .irq_timeout = 600,
79 .queue_type = CONF_RX_QUEUE_TYPE_LOW_PRIORITY,
80 },
81 .tx = {
82 .tx_energy_detection = 0,
83 .rc_conf = {
84 .enabled_rates = CONF_HW_BIT_RATE_1MBPS |
85 CONF_HW_BIT_RATE_2MBPS,
86 .short_retry_limit = 10,
87 .long_retry_limit = 10,
88 .aflags = 0
89 },
90 .ac_conf_count = 4,
91 .ac_conf = {
92 [0] = {
93 .ac = CONF_TX_AC_BE,
94 .cw_min = 15,
95 .cw_max = 63,
96 .aifsn = 3,
97 .tx_op_limit = 0,
98 },
99 [1] = {
100 .ac = CONF_TX_AC_BK,
101 .cw_min = 15,
102 .cw_max = 63,
103 .aifsn = 7,
104 .tx_op_limit = 0,
105 },
106 [2] = {
107 .ac = CONF_TX_AC_VI,
108 .cw_min = 15,
109 .cw_max = 63,
110 .aifsn = CONF_TX_AIFS_PIFS,
111 .tx_op_limit = 3008,
112 },
113 [3] = {
114 .ac = CONF_TX_AC_VO,
115 .cw_min = 15,
116 .cw_max = 63,
117 .aifsn = CONF_TX_AIFS_PIFS,
118 .tx_op_limit = 1504,
119 },
120 },
121 .tid_conf_count = 7,
122 .tid_conf = {
123 [0] = {
124 .queue_id = 0,
125 .channel_type = CONF_CHANNEL_TYPE_DCF,
126 .tsid = CONF_TX_AC_BE,
127 .ps_scheme = CONF_PS_SCHEME_LEGACY,
128 .ack_policy = CONF_ACK_POLICY_LEGACY,
129 .apsd_conf = {0, 0},
130 },
131 [1] = {
132 .queue_id = 1,
133 .channel_type = CONF_CHANNEL_TYPE_DCF,
134 .tsid = CONF_TX_AC_BE,
135 .ps_scheme = CONF_PS_SCHEME_LEGACY,
136 .ack_policy = CONF_ACK_POLICY_LEGACY,
137 .apsd_conf = {0, 0},
138 },
139 [2] = {
140 .queue_id = 2,
141 .channel_type = CONF_CHANNEL_TYPE_DCF,
142 .tsid = CONF_TX_AC_BE,
143 .ps_scheme = CONF_PS_SCHEME_LEGACY,
144 .ack_policy = CONF_ACK_POLICY_LEGACY,
145 .apsd_conf = {0, 0},
146 },
147 [3] = {
148 .queue_id = 3,
149 .channel_type = CONF_CHANNEL_TYPE_DCF,
150 .tsid = CONF_TX_AC_BE,
151 .ps_scheme = CONF_PS_SCHEME_LEGACY,
152 .ack_policy = CONF_ACK_POLICY_LEGACY,
153 .apsd_conf = {0, 0},
154 },
155 [4] = {
156 .queue_id = 4,
157 .channel_type = CONF_CHANNEL_TYPE_DCF,
158 .tsid = CONF_TX_AC_BE,
159 .ps_scheme = CONF_PS_SCHEME_LEGACY,
160 .ack_policy = CONF_ACK_POLICY_LEGACY,
161 .apsd_conf = {0, 0},
162 },
163 [5] = {
164 .queue_id = 5,
165 .channel_type = CONF_CHANNEL_TYPE_DCF,
166 .tsid = CONF_TX_AC_BE,
167 .ps_scheme = CONF_PS_SCHEME_LEGACY,
168 .ack_policy = CONF_ACK_POLICY_LEGACY,
169 .apsd_conf = {0, 0},
170 },
171 [6] = {
172 .queue_id = 6,
173 .channel_type = CONF_CHANNEL_TYPE_DCF,
174 .tsid = CONF_TX_AC_BE,
175 .ps_scheme = CONF_PS_SCHEME_LEGACY,
176 .ack_policy = CONF_ACK_POLICY_LEGACY,
177 .apsd_conf = {0, 0},
178 }
179 },
180 .frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD,
181 .tx_compl_timeout = 700,
182 .tx_compl_threshold = 4
183 },
184 .conn = {
185 .wake_up_event = CONF_WAKE_UP_EVENT_DTIM,
186 .listen_interval = 0,
187 .bcn_filt_mode = CONF_BCN_FILT_MODE_ENABLED,
188 .bcn_filt_ie_count = 1,
189 .bcn_filt_ie = {
190 [0] = {
191 .ie = WLAN_EID_CHANNEL_SWITCH,
192 .rule = CONF_BCN_RULE_PASS_ON_APPEARANCE,
193 }
194 },
195 .synch_fail_thold = 10,
196 .bss_lose_timeout = 100,
197 .beacon_rx_timeout = 10000,
198 .broadcast_timeout = 20000,
199 .rx_broadcast_in_ps = 1,
200 .ps_poll_threshold = 20,
201 .sig_trigger_count = 2,
202 .sig_trigger = {
203 [0] = {
204 .threshold = -75,
205 .pacing = 500,
206 .metric = CONF_TRIG_METRIC_RSSI_BEACON,
207 .type = CONF_TRIG_EVENT_TYPE_EDGE,
208 .direction = CONF_TRIG_EVENT_DIR_LOW,
209 .hysteresis = 2,
210 .index = 0,
211 .enable = 1
212 },
213 [1] = {
214 .threshold = -75,
215 .pacing = 500,
216 .metric = CONF_TRIG_METRIC_RSSI_BEACON,
217 .type = CONF_TRIG_EVENT_TYPE_EDGE,
218 .direction = CONF_TRIG_EVENT_DIR_HIGH,
219 .hysteresis = 2,
220 .index = 1,
221 .enable = 1
222 }
223 },
224 .sig_weights = {
225 .rssi_bcn_avg_weight = 10,
226 .rssi_pkt_avg_weight = 10,
227 .snr_bcn_avg_weight = 10,
228 .snr_pkt_avg_weight = 10
229 },
230 .bet_enable = CONF_BET_MODE_ENABLE,
231 .bet_max_consecutive = 10,
232 .psm_entry_retries = 3
233 },
234 .init = {
235 .radioparam = {
236 .fem = 1,
237 }
238 },
239 .itrim = {
240 .enable = false,
241 .timeout = 50000,
242 },
243 .pm_config = {
244 .host_clk_settling_time = 5000,
245 .host_fast_wakeup_support = false
246 }
247};
248
249static LIST_HEAD(wl_list);
250
251static void wl1271_conf_init(struct wl1271 *wl)
252{
253
254 /*
255 * This function applies the default configuration to the driver. This
256 * function is invoked upon driver load (spi probe.)
257 *
258 * The configuration is stored in a run-time structure in order to
259 * facilitate for run-time adjustment of any of the parameters. Making
260 * changes to the configuration structure will apply the new values on
261 * the next interface up (wl1271_op_start.)
262 */
263
264 /* apply driver default configuration */
265 memcpy(&wl->conf, &default_conf, sizeof(default_conf));
266}
267
47 268
48static int wl1271_plt_init(struct wl1271 *wl) 269static int wl1271_plt_init(struct wl1271 *wl)
49{ 270{
50 int ret; 271 struct conf_tx_ac_category *conf_ac;
272 struct conf_tx_tid *conf_tid;
273 int ret, i;
51 274
52 ret = wl1271_acx_init_mem_config(wl); 275 ret = wl1271_cmd_general_parms(wl);
276 if (ret < 0)
277 return ret;
278
279 ret = wl1271_cmd_radio_parms(wl);
53 if (ret < 0) 280 if (ret < 0)
54 return ret; 281 return ret;
55 282
56 ret = wl1271_cmd_data_path(wl, wl->channel, 1); 283 ret = wl1271_init_templates_config(wl);
57 if (ret < 0) 284 if (ret < 0)
58 return ret; 285 return ret;
59 286
287 ret = wl1271_acx_init_mem_config(wl);
288 if (ret < 0)
289 return ret;
290
291 /* PHY layer config */
292 ret = wl1271_init_phy_config(wl);
293 if (ret < 0)
294 goto out_free_memmap;
295
296 ret = wl1271_acx_dco_itrim_params(wl);
297 if (ret < 0)
298 goto out_free_memmap;
299
300 /* Initialize connection monitoring thresholds */
301 ret = wl1271_acx_conn_monit_params(wl);
302 if (ret < 0)
303 goto out_free_memmap;
304
305 /* Bluetooth WLAN coexistence */
306 ret = wl1271_init_pta(wl);
307 if (ret < 0)
308 goto out_free_memmap;
309
310 /* Energy detection */
311 ret = wl1271_init_energy_detection(wl);
312 if (ret < 0)
313 goto out_free_memmap;
314
315 /* Default fragmentation threshold */
316 ret = wl1271_acx_frag_threshold(wl);
317 if (ret < 0)
318 goto out_free_memmap;
319
320 /* Default TID configuration */
321 for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
322 conf_tid = &wl->conf.tx.tid_conf[i];
323 ret = wl1271_acx_tid_cfg(wl, conf_tid->queue_id,
324 conf_tid->channel_type,
325 conf_tid->tsid,
326 conf_tid->ps_scheme,
327 conf_tid->ack_policy,
328 conf_tid->apsd_conf[0],
329 conf_tid->apsd_conf[1]);
330 if (ret < 0)
331 goto out_free_memmap;
332 }
333
334 /* Default AC configuration */
335 for (i = 0; i < wl->conf.tx.ac_conf_count; i++) {
336 conf_ac = &wl->conf.tx.ac_conf[i];
337 ret = wl1271_acx_ac_cfg(wl, conf_ac->ac, conf_ac->cw_min,
338 conf_ac->cw_max, conf_ac->aifsn,
339 conf_ac->tx_op_limit);
340 if (ret < 0)
341 goto out_free_memmap;
342 }
343
344 /* Enable data path */
345 ret = wl1271_cmd_data_path(wl, 1);
346 if (ret < 0)
347 goto out_free_memmap;
348
349 /* Configure for CAM power saving (ie. always active) */
350 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
351 if (ret < 0)
352 goto out_free_memmap;
353
354 /* configure PM */
355 ret = wl1271_acx_pm_config(wl);
356 if (ret < 0)
357 goto out_free_memmap;
358
60 return 0; 359 return 0;
360
361 out_free_memmap:
362 kfree(wl->target_mem_map);
363 wl->target_mem_map = NULL;
364
365 return ret;
61} 366}
62 367
63static void wl1271_disable_interrupts(struct wl1271 *wl) 368static void wl1271_disable_interrupts(struct wl1271 *wl)
@@ -68,27 +373,22 @@ static void wl1271_disable_interrupts(struct wl1271 *wl)
68static void wl1271_power_off(struct wl1271 *wl) 373static void wl1271_power_off(struct wl1271 *wl)
69{ 374{
70 wl->set_power(false); 375 wl->set_power(false);
376 clear_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
71} 377}
72 378
73static void wl1271_power_on(struct wl1271 *wl) 379static void wl1271_power_on(struct wl1271 *wl)
74{ 380{
75 wl->set_power(true); 381 wl->set_power(true);
382 set_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
76} 383}
77 384
78static void wl1271_fw_status(struct wl1271 *wl, struct wl1271_fw_status *status) 385static void wl1271_fw_status(struct wl1271 *wl,
386 struct wl1271_fw_status *status)
79{ 387{
80 u32 total = 0; 388 u32 total = 0;
81 int i; 389 int i;
82 390
83 /* 391 wl1271_read(wl, FW_STATUS_ADDR, status, sizeof(*status), false);
84 * FIXME: Reading the FW status directly from the registers seems to
85 * be the right thing to do, but it doesn't work. And in the
86 * reference driver, there is a workaround called
87 * USE_SDIO_24M_WORKAROUND, which reads the status from memory
88 * instead, so we do the same here.
89 */
90
91 wl1271_spi_mem_read(wl, STATUS_MEM_ADDRESS, status, sizeof(*status));
92 392
93 wl1271_debug(DEBUG_IRQ, "intr: 0x%x (fw_rx_counter = %d, " 393 wl1271_debug(DEBUG_IRQ, "intr: 0x%x (fw_rx_counter = %d, "
94 "drv_rx_counter = %d, tx_results_counter = %d)", 394 "drv_rx_counter = %d, tx_results_counter = %d)",
@@ -99,25 +399,28 @@ static void wl1271_fw_status(struct wl1271 *wl, struct wl1271_fw_status *status)
99 399
100 /* update number of available TX blocks */ 400 /* update number of available TX blocks */
101 for (i = 0; i < NUM_TX_QUEUES; i++) { 401 for (i = 0; i < NUM_TX_QUEUES; i++) {
102 u32 cnt = status->tx_released_blks[i] - wl->tx_blocks_freed[i]; 402 u32 cnt = le32_to_cpu(status->tx_released_blks[i]) -
103 wl->tx_blocks_freed[i] = status->tx_released_blks[i]; 403 wl->tx_blocks_freed[i];
404
405 wl->tx_blocks_freed[i] =
406 le32_to_cpu(status->tx_released_blks[i]);
104 wl->tx_blocks_available += cnt; 407 wl->tx_blocks_available += cnt;
105 total += cnt; 408 total += cnt;
106 } 409 }
107 410
108 /* if more blocks are available now, schedule some tx work */ 411 /* if more blocks are available now, schedule some tx work */
109 if (total && !skb_queue_empty(&wl->tx_queue)) 412 if (total && !skb_queue_empty(&wl->tx_queue))
110 schedule_work(&wl->tx_work); 413 ieee80211_queue_work(wl->hw, &wl->tx_work);
111 414
112 /* update the host-chipset time offset */ 415 /* update the host-chipset time offset */
113 wl->time_offset = jiffies_to_usecs(jiffies) - status->fw_localtime; 416 wl->time_offset = jiffies_to_usecs(jiffies) -
417 le32_to_cpu(status->fw_localtime);
114} 418}
115 419
116#define WL1271_IRQ_MAX_LOOPS 10
117static void wl1271_irq_work(struct work_struct *work) 420static void wl1271_irq_work(struct work_struct *work)
118{ 421{
119 u32 intr, ctr = WL1271_IRQ_MAX_LOOPS;
120 int ret; 422 int ret;
423 u32 intr;
121 struct wl1271 *wl = 424 struct wl1271 *wl =
122 container_of(work, struct wl1271, irq_work); 425 container_of(work, struct wl1271, irq_work);
123 426
@@ -132,9 +435,10 @@ static void wl1271_irq_work(struct work_struct *work)
132 if (ret < 0) 435 if (ret < 0)
133 goto out; 436 goto out;
134 437
135 wl1271_reg_write32(wl, ACX_REG_INTERRUPT_MASK, WL1271_ACX_INTR_ALL); 438 wl1271_write32(wl, ACX_REG_INTERRUPT_MASK, WL1271_ACX_INTR_ALL);
136 439
137 intr = wl1271_reg_read32(wl, ACX_REG_INTERRUPT_CLEAR); 440 wl1271_fw_status(wl, wl->fw_status);
441 intr = le32_to_cpu(wl->fw_status->intr);
138 if (!intr) { 442 if (!intr) {
139 wl1271_debug(DEBUG_IRQ, "Zero interrupt received."); 443 wl1271_debug(DEBUG_IRQ, "Zero interrupt received.");
140 goto out_sleep; 444 goto out_sleep;
@@ -142,47 +446,39 @@ static void wl1271_irq_work(struct work_struct *work)
142 446
143 intr &= WL1271_INTR_MASK; 447 intr &= WL1271_INTR_MASK;
144 448
145 do { 449 if (intr & WL1271_ACX_INTR_EVENT_A) {
146 wl1271_fw_status(wl, wl->fw_status); 450 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_A");
147 451 wl1271_event_handle(wl, 0);
452 }
148 453
149 if (intr & (WL1271_ACX_INTR_EVENT_A | 454 if (intr & WL1271_ACX_INTR_EVENT_B) {
150 WL1271_ACX_INTR_EVENT_B)) { 455 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_B");
151 wl1271_debug(DEBUG_IRQ, 456 wl1271_event_handle(wl, 1);
152 "WL1271_ACX_INTR_EVENT (0x%x)", intr); 457 }
153 if (intr & WL1271_ACX_INTR_EVENT_A)
154 wl1271_event_handle(wl, 0);
155 else
156 wl1271_event_handle(wl, 1);
157 }
158 458
159 if (intr & WL1271_ACX_INTR_INIT_COMPLETE) 459 if (intr & WL1271_ACX_INTR_INIT_COMPLETE)
160 wl1271_debug(DEBUG_IRQ, 460 wl1271_debug(DEBUG_IRQ,
161 "WL1271_ACX_INTR_INIT_COMPLETE"); 461 "WL1271_ACX_INTR_INIT_COMPLETE");
162 462
163 if (intr & WL1271_ACX_INTR_HW_AVAILABLE) 463 if (intr & WL1271_ACX_INTR_HW_AVAILABLE)
164 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_HW_AVAILABLE"); 464 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_HW_AVAILABLE");
165 465
166 if (intr & WL1271_ACX_INTR_DATA) { 466 if (intr & WL1271_ACX_INTR_DATA) {
167 u8 tx_res_cnt = wl->fw_status->tx_results_counter - 467 u8 tx_res_cnt = wl->fw_status->tx_results_counter -
168 wl->tx_results_count; 468 wl->tx_results_count;
169 469
170 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_DATA"); 470 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_DATA");
171 471
172 /* check for tx results */ 472 /* check for tx results */
173 if (tx_res_cnt) 473 if (tx_res_cnt)
174 wl1271_tx_complete(wl, tx_res_cnt); 474 wl1271_tx_complete(wl, tx_res_cnt);
175 475
176 wl1271_rx(wl, wl->fw_status); 476 wl1271_rx(wl, wl->fw_status);
177 } 477 }
178
179 intr = wl1271_reg_read32(wl, ACX_REG_INTERRUPT_CLEAR);
180 intr &= WL1271_INTR_MASK;
181 } while (intr && --ctr);
182 478
183out_sleep: 479out_sleep:
184 wl1271_reg_write32(wl, ACX_REG_INTERRUPT_MASK, 480 wl1271_write32(wl, ACX_REG_INTERRUPT_MASK,
185 WL1271_ACX_INTR_ALL & ~(WL1271_INTR_MASK)); 481 WL1271_ACX_INTR_ALL & ~(WL1271_INTR_MASK));
186 wl1271_ps_elp_sleep(wl); 482 wl1271_ps_elp_sleep(wl);
187 483
188out: 484out:
@@ -205,7 +501,7 @@ static irqreturn_t wl1271_irq(int irq, void *cookie)
205 wl->elp_compl = NULL; 501 wl->elp_compl = NULL;
206 } 502 }
207 503
208 schedule_work(&wl->irq_work); 504 ieee80211_queue_work(wl->hw, &wl->irq_work);
209 spin_unlock_irqrestore(&wl->wl_lock, flags); 505 spin_unlock_irqrestore(&wl->wl_lock, flags);
210 506
211 return IRQ_HANDLED; 507 return IRQ_HANDLED;
@@ -231,7 +527,7 @@ static int wl1271_fetch_firmware(struct wl1271 *wl)
231 } 527 }
232 528
233 wl->fw_len = fw->size; 529 wl->fw_len = fw->size;
234 wl->fw = kmalloc(wl->fw_len, GFP_KERNEL); 530 wl->fw = vmalloc(wl->fw_len);
235 531
236 if (!wl->fw) { 532 if (!wl->fw) {
237 wl1271_error("could not allocate memory for the firmware"); 533 wl1271_error("could not allocate memory for the firmware");
@@ -249,6 +545,40 @@ out:
249 return ret; 545 return ret;
250} 546}
251 547
548static int wl1271_update_mac_addr(struct wl1271 *wl)
549{
550 int ret = 0;
551 u8 *nvs_ptr = (u8 *)wl->nvs->nvs;
552
553 /* get mac address from the NVS */
554 wl->mac_addr[0] = nvs_ptr[11];
555 wl->mac_addr[1] = nvs_ptr[10];
556 wl->mac_addr[2] = nvs_ptr[6];
557 wl->mac_addr[3] = nvs_ptr[5];
558 wl->mac_addr[4] = nvs_ptr[4];
559 wl->mac_addr[5] = nvs_ptr[3];
560
561 /* FIXME: if it is a zero-address, we should bail out. Now, instead,
562 we randomize an address */
563 if (is_zero_ether_addr(wl->mac_addr)) {
564 static const u8 nokia_oui[3] = {0x00, 0x1f, 0xdf};
565 memcpy(wl->mac_addr, nokia_oui, 3);
566 get_random_bytes(wl->mac_addr + 3, 3);
567
568 /* update this address to the NVS */
569 nvs_ptr[11] = wl->mac_addr[0];
570 nvs_ptr[10] = wl->mac_addr[1];
571 nvs_ptr[6] = wl->mac_addr[2];
572 nvs_ptr[5] = wl->mac_addr[3];
573 nvs_ptr[4] = wl->mac_addr[4];
574 nvs_ptr[3] = wl->mac_addr[5];
575 }
576
577 SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr);
578
579 return ret;
580}
581
252static int wl1271_fetch_nvs(struct wl1271 *wl) 582static int wl1271_fetch_nvs(struct wl1271 *wl)
253{ 583{
254 const struct firmware *fw; 584 const struct firmware *fw;
@@ -261,15 +591,14 @@ static int wl1271_fetch_nvs(struct wl1271 *wl)
261 return ret; 591 return ret;
262 } 592 }
263 593
264 if (fw->size % 4) { 594 if (fw->size != sizeof(struct wl1271_nvs_file)) {
265 wl1271_error("nvs size is not multiple of 32 bits: %zu", 595 wl1271_error("nvs size is not as expected: %zu != %zu",
266 fw->size); 596 fw->size, sizeof(struct wl1271_nvs_file));
267 ret = -EILSEQ; 597 ret = -EILSEQ;
268 goto out; 598 goto out;
269 } 599 }
270 600
271 wl->nvs_len = fw->size; 601 wl->nvs = kmalloc(sizeof(struct wl1271_nvs_file), GFP_KERNEL);
272 wl->nvs = kmalloc(wl->nvs_len, GFP_KERNEL);
273 602
274 if (!wl->nvs) { 603 if (!wl->nvs) {
275 wl1271_error("could not allocate memory for the nvs file"); 604 wl1271_error("could not allocate memory for the nvs file");
@@ -277,9 +606,9 @@ static int wl1271_fetch_nvs(struct wl1271 *wl)
277 goto out; 606 goto out;
278 } 607 }
279 608
280 memcpy(wl->nvs, fw->data, wl->nvs_len); 609 memcpy(wl->nvs, fw->data, sizeof(struct wl1271_nvs_file));
281 610
282 ret = 0; 611 ret = wl1271_update_mac_addr(wl);
283 612
284out: 613out:
285 release_firmware(fw); 614 release_firmware(fw);
@@ -292,7 +621,7 @@ static void wl1271_fw_wakeup(struct wl1271 *wl)
292 u32 elp_reg; 621 u32 elp_reg;
293 622
294 elp_reg = ELPCTRL_WAKE_UP; 623 elp_reg = ELPCTRL_WAKE_UP;
295 wl1271_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg); 624 wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg);
296} 625}
297 626
298static int wl1271_setup(struct wl1271 *wl) 627static int wl1271_setup(struct wl1271 *wl)
@@ -314,20 +643,21 @@ static int wl1271_setup(struct wl1271 *wl)
314 643
315static int wl1271_chip_wakeup(struct wl1271 *wl) 644static int wl1271_chip_wakeup(struct wl1271 *wl)
316{ 645{
646 struct wl1271_partition_set partition;
317 int ret = 0; 647 int ret = 0;
318 648
649 msleep(WL1271_PRE_POWER_ON_SLEEP);
319 wl1271_power_on(wl); 650 wl1271_power_on(wl);
320 msleep(WL1271_POWER_ON_SLEEP); 651 msleep(WL1271_POWER_ON_SLEEP);
321 wl1271_spi_reset(wl); 652 wl1271_io_reset(wl);
322 wl1271_spi_init(wl); 653 wl1271_io_init(wl);
323 654
324 /* We don't need a real memory partition here, because we only want 655 /* We don't need a real memory partition here, because we only want
325 * to use the registers at this point. */ 656 * to use the registers at this point. */
326 wl1271_set_partition(wl, 657 memset(&partition, 0, sizeof(partition));
327 0x00000000, 658 partition.reg.start = REGISTERS_BASE;
328 0x00000000, 659 partition.reg.size = REGISTERS_DOWN_SIZE;
329 REGISTERS_BASE, 660 wl1271_set_partition(wl, &partition);
330 REGISTERS_DOWN_SIZE);
331 661
332 /* ELP module wake up */ 662 /* ELP module wake up */
333 wl1271_fw_wakeup(wl); 663 wl1271_fw_wakeup(wl);
@@ -335,7 +665,7 @@ static int wl1271_chip_wakeup(struct wl1271 *wl)
335 /* whal_FwCtrl_BootSm() */ 665 /* whal_FwCtrl_BootSm() */
336 666
337 /* 0. read chip id from CHIP_ID */ 667 /* 0. read chip id from CHIP_ID */
338 wl->chip.id = wl1271_reg_read32(wl, CHIP_ID_B); 668 wl->chip.id = wl1271_read32(wl, CHIP_ID_B);
339 669
340 /* 1. check if chip id is valid */ 670 /* 1. check if chip id is valid */
341 671
@@ -357,7 +687,7 @@ static int wl1271_chip_wakeup(struct wl1271 *wl)
357 goto out; 687 goto out;
358 break; 688 break;
359 default: 689 default:
360 wl1271_error("unsupported chip id: 0x%x", wl->chip.id); 690 wl1271_warning("unsupported chip id: 0x%x", wl->chip.id);
361 ret = -ENODEV; 691 ret = -ENODEV;
362 goto out; 692 goto out;
363 } 693 }
@@ -379,35 +709,9 @@ out:
379 return ret; 709 return ret;
380} 710}
381 711
382static void wl1271_filter_work(struct work_struct *work)
383{
384 struct wl1271 *wl =
385 container_of(work, struct wl1271, filter_work);
386 int ret;
387
388 mutex_lock(&wl->mutex);
389
390 if (wl->state == WL1271_STATE_OFF)
391 goto out;
392
393 ret = wl1271_ps_elp_wakeup(wl, false);
394 if (ret < 0)
395 goto out;
396
397 /* FIXME: replace the magic numbers with proper definitions */
398 ret = wl1271_cmd_join(wl, wl->bss_type, 1, 100, 0);
399 if (ret < 0)
400 goto out_sleep;
401
402out_sleep:
403 wl1271_ps_elp_sleep(wl);
404
405out:
406 mutex_unlock(&wl->mutex);
407}
408
409int wl1271_plt_start(struct wl1271 *wl) 712int wl1271_plt_start(struct wl1271 *wl)
410{ 713{
714 int retries = WL1271_BOOT_RETRIES;
411 int ret; 715 int ret;
412 716
413 mutex_lock(&wl->mutex); 717 mutex_lock(&wl->mutex);
@@ -421,22 +725,43 @@ int wl1271_plt_start(struct wl1271 *wl)
421 goto out; 725 goto out;
422 } 726 }
423 727
424 wl->state = WL1271_STATE_PLT; 728 while (retries) {
425 729 retries--;
426 ret = wl1271_chip_wakeup(wl); 730 ret = wl1271_chip_wakeup(wl);
427 if (ret < 0) 731 if (ret < 0)
428 goto out; 732 goto power_off;
429 733
430 ret = wl1271_boot(wl); 734 ret = wl1271_boot(wl);
431 if (ret < 0) 735 if (ret < 0)
432 goto out; 736 goto power_off;
433 737
434 wl1271_notice("firmware booted in PLT mode (%s)", wl->chip.fw_ver); 738 ret = wl1271_plt_init(wl);
739 if (ret < 0)
740 goto irq_disable;
435 741
436 ret = wl1271_plt_init(wl); 742 wl->state = WL1271_STATE_PLT;
437 if (ret < 0) 743 wl1271_notice("firmware booted in PLT mode (%s)",
744 wl->chip.fw_ver);
438 goto out; 745 goto out;
439 746
747irq_disable:
748 wl1271_disable_interrupts(wl);
749 mutex_unlock(&wl->mutex);
750 /* Unlocking the mutex in the middle of handling is
751 inherently unsafe. In this case we deem it safe to do,
752 because we need to let any possibly pending IRQ out of
753 the system (and while we are WL1271_STATE_OFF the IRQ
754 work function will not do anything.) Also, any other
755 possible concurrent operations will fail due to the
756 current state, hence the wl1271 struct should be safe. */
757 cancel_work_sync(&wl->irq_work);
758 mutex_lock(&wl->mutex);
759power_off:
760 wl1271_power_off(wl);
761 }
762
763 wl1271_error("firmware boot in PLT mode failed despite %d retries",
764 WL1271_BOOT_RETRIES);
440out: 765out:
441 mutex_unlock(&wl->mutex); 766 mutex_unlock(&wl->mutex);
442 767
@@ -462,6 +787,7 @@ int wl1271_plt_stop(struct wl1271 *wl)
462 wl1271_power_off(wl); 787 wl1271_power_off(wl);
463 788
464 wl->state = WL1271_STATE_OFF; 789 wl->state = WL1271_STATE_OFF;
790 wl->rx_counter = 0;
465 791
466out: 792out:
467 mutex_unlock(&wl->mutex); 793 mutex_unlock(&wl->mutex);
@@ -473,7 +799,20 @@ out:
473static int wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb) 799static int wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
474{ 800{
475 struct wl1271 *wl = hw->priv; 801 struct wl1271 *wl = hw->priv;
802 struct ieee80211_conf *conf = &hw->conf;
803 struct ieee80211_tx_info *txinfo = IEEE80211_SKB_CB(skb);
804 struct ieee80211_sta *sta = txinfo->control.sta;
805 unsigned long flags;
476 806
807 /* peek into the rates configured in the STA entry */
808 spin_lock_irqsave(&wl->wl_lock, flags);
809 if (sta && sta->supp_rates[conf->channel->band] != wl->sta_rate_set) {
810 wl->sta_rate_set = sta->supp_rates[conf->channel->band];
811 set_bit(WL1271_FLAG_STA_RATES_CHANGED, &wl->flags);
812 }
813 spin_unlock_irqrestore(&wl->wl_lock, flags);
814
815 /* queue the packet */
477 skb_queue_tail(&wl->tx_queue, skb); 816 skb_queue_tail(&wl->tx_queue, skb);
478 817
479 /* 818 /*
@@ -481,7 +820,7 @@ static int wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
481 * before that, the tx_work will not be initialized! 820 * before that, the tx_work will not be initialized!
482 */ 821 */
483 822
484 schedule_work(&wl->tx_work); 823 ieee80211_queue_work(wl->hw, &wl->tx_work);
485 824
486 /* 825 /*
487 * The workqueue is slow to process the tx_queue and we need stop 826 * The workqueue is slow to process the tx_queue and we need stop
@@ -495,15 +834,103 @@ static int wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
495 * protected. Maybe fix this by removing the stupid 834 * protected. Maybe fix this by removing the stupid
496 * variable altogether and checking the real queue state? 835 * variable altogether and checking the real queue state?
497 */ 836 */
498 wl->tx_queue_stopped = true; 837 set_bit(WL1271_FLAG_TX_QUEUE_STOPPED, &wl->flags);
499 } 838 }
500 839
501 return NETDEV_TX_OK; 840 return NETDEV_TX_OK;
502} 841}
503 842
843static int wl1271_dev_notify(struct notifier_block *me, unsigned long what,
844 void *arg)
845{
846 struct net_device *dev;
847 struct wireless_dev *wdev;
848 struct wiphy *wiphy;
849 struct ieee80211_hw *hw;
850 struct wl1271 *wl;
851 struct wl1271 *wl_temp;
852 struct in_device *idev;
853 struct in_ifaddr *ifa = arg;
854 int ret = 0;
855
856 /* FIXME: this ugly function should probably be implemented in the
857 * mac80211, and here should only be a simple callback handling actual
858 * setting of the filters. Now we need to dig up references to
859 * various structures to gain access to what we need.
860 * Also, because of this, there is no "initial" setting of the filter
861 * in "op_start", because we don't want to dig up struct net_device
862 * there - the filter will be set upon first change of the interface
863 * IP address. */
864
865 dev = ifa->ifa_dev->dev;
866
867 wdev = dev->ieee80211_ptr;
868 if (wdev == NULL)
869 return NOTIFY_DONE;
870
871 wiphy = wdev->wiphy;
872 if (wiphy == NULL)
873 return NOTIFY_DONE;
874
875 hw = wiphy_priv(wiphy);
876 if (hw == NULL)
877 return NOTIFY_DONE;
878
879 /* Check that the interface is one supported by this driver. */
880 wl_temp = hw->priv;
881 list_for_each_entry(wl, &wl_list, list) {
882 if (wl == wl_temp)
883 break;
884 }
885 if (wl == NULL)
886 return NOTIFY_DONE;
887
888 /* Get the interface IP address for the device. "ifa" will become
889 NULL if:
890 - there is no IPV4 protocol address configured
891 - there are multiple (virtual) IPV4 addresses configured
892 When "ifa" is NULL, filtering will be disabled.
893 */
894 ifa = NULL;
895 idev = dev->ip_ptr;
896 if (idev)
897 ifa = idev->ifa_list;
898
899 if (ifa && ifa->ifa_next)
900 ifa = NULL;
901
902 mutex_lock(&wl->mutex);
903
904 if (wl->state == WL1271_STATE_OFF)
905 goto out;
906
907 ret = wl1271_ps_elp_wakeup(wl, false);
908 if (ret < 0)
909 goto out;
910 if (ifa)
911 ret = wl1271_acx_arp_ip_filter(wl, true,
912 (u8 *)&ifa->ifa_address,
913 ACX_IPV4_VERSION);
914 else
915 ret = wl1271_acx_arp_ip_filter(wl, false, NULL,
916 ACX_IPV4_VERSION);
917 wl1271_ps_elp_sleep(wl);
918
919out:
920 mutex_unlock(&wl->mutex);
921
922 return NOTIFY_OK;
923}
924
925static struct notifier_block wl1271_dev_notifier = {
926 .notifier_call = wl1271_dev_notify,
927};
928
929
504static int wl1271_op_start(struct ieee80211_hw *hw) 930static int wl1271_op_start(struct ieee80211_hw *hw)
505{ 931{
506 struct wl1271 *wl = hw->priv; 932 struct wl1271 *wl = hw->priv;
933 int retries = WL1271_BOOT_RETRIES;
507 int ret = 0; 934 int ret = 0;
508 935
509 wl1271_debug(DEBUG_MAC80211, "mac80211 start"); 936 wl1271_debug(DEBUG_MAC80211, "mac80211 start");
@@ -517,28 +944,50 @@ static int wl1271_op_start(struct ieee80211_hw *hw)
517 goto out; 944 goto out;
518 } 945 }
519 946
520 ret = wl1271_chip_wakeup(wl); 947 while (retries) {
521 if (ret < 0) 948 retries--;
522 goto out; 949 ret = wl1271_chip_wakeup(wl);
523 950 if (ret < 0)
524 ret = wl1271_boot(wl); 951 goto power_off;
525 if (ret < 0)
526 goto out;
527 952
528 ret = wl1271_hw_init(wl); 953 ret = wl1271_boot(wl);
529 if (ret < 0) 954 if (ret < 0)
530 goto out; 955 goto power_off;
531 956
532 wl->state = WL1271_STATE_ON; 957 ret = wl1271_hw_init(wl);
958 if (ret < 0)
959 goto irq_disable;
533 960
534 wl1271_info("firmware booted (%s)", wl->chip.fw_ver); 961 wl->state = WL1271_STATE_ON;
962 wl1271_info("firmware booted (%s)", wl->chip.fw_ver);
963 goto out;
535 964
536out: 965irq_disable:
537 if (ret < 0) 966 wl1271_disable_interrupts(wl);
967 mutex_unlock(&wl->mutex);
968 /* Unlocking the mutex in the middle of handling is
969 inherently unsafe. In this case we deem it safe to do,
970 because we need to let any possibly pending IRQ out of
971 the system (and while we are WL1271_STATE_OFF the IRQ
972 work function will not do anything.) Also, any other
973 possible concurrent operations will fail due to the
974 current state, hence the wl1271 struct should be safe. */
975 cancel_work_sync(&wl->irq_work);
976 mutex_lock(&wl->mutex);
977power_off:
538 wl1271_power_off(wl); 978 wl1271_power_off(wl);
979 }
539 980
981 wl1271_error("firmware boot failed despite %d retries",
982 WL1271_BOOT_RETRIES);
983out:
540 mutex_unlock(&wl->mutex); 984 mutex_unlock(&wl->mutex);
541 985
986 if (!ret) {
987 list_add(&wl->list, &wl_list);
988 register_inetaddr_notifier(&wl1271_dev_notifier);
989 }
990
542 return ret; 991 return ret;
543} 992}
544 993
@@ -551,15 +1000,17 @@ static void wl1271_op_stop(struct ieee80211_hw *hw)
551 1000
552 wl1271_debug(DEBUG_MAC80211, "mac80211 stop"); 1001 wl1271_debug(DEBUG_MAC80211, "mac80211 stop");
553 1002
1003 unregister_inetaddr_notifier(&wl1271_dev_notifier);
1004 list_del(&wl->list);
1005
554 mutex_lock(&wl->mutex); 1006 mutex_lock(&wl->mutex);
555 1007
556 WARN_ON(wl->state != WL1271_STATE_ON); 1008 WARN_ON(wl->state != WL1271_STATE_ON);
557 1009
558 if (wl->scanning) { 1010 if (test_and_clear_bit(WL1271_FLAG_SCANNING, &wl->flags)) {
559 mutex_unlock(&wl->mutex); 1011 mutex_unlock(&wl->mutex);
560 ieee80211_scan_completed(wl->hw, true); 1012 ieee80211_scan_completed(wl->hw, true);
561 mutex_lock(&wl->mutex); 1013 mutex_lock(&wl->mutex);
562 wl->scanning = false;
563 } 1014 }
564 1015
565 wl->state = WL1271_STATE_OFF; 1016 wl->state = WL1271_STATE_OFF;
@@ -570,7 +1021,6 @@ static void wl1271_op_stop(struct ieee80211_hw *hw)
570 1021
571 cancel_work_sync(&wl->irq_work); 1022 cancel_work_sync(&wl->irq_work);
572 cancel_work_sync(&wl->tx_work); 1023 cancel_work_sync(&wl->tx_work);
573 cancel_work_sync(&wl->filter_work);
574 1024
575 mutex_lock(&wl->mutex); 1025 mutex_lock(&wl->mutex);
576 1026
@@ -581,19 +1031,24 @@ static void wl1271_op_stop(struct ieee80211_hw *hw)
581 memset(wl->bssid, 0, ETH_ALEN); 1031 memset(wl->bssid, 0, ETH_ALEN);
582 memset(wl->ssid, 0, IW_ESSID_MAX_SIZE + 1); 1032 memset(wl->ssid, 0, IW_ESSID_MAX_SIZE + 1);
583 wl->ssid_len = 0; 1033 wl->ssid_len = 0;
584 wl->listen_int = 1;
585 wl->bss_type = MAX_BSS_TYPE; 1034 wl->bss_type = MAX_BSS_TYPE;
1035 wl->band = IEEE80211_BAND_2GHZ;
586 1036
587 wl->rx_counter = 0; 1037 wl->rx_counter = 0;
588 wl->elp = false; 1038 wl->psm_entry_retry = 0;
589 wl->psm = 0;
590 wl->tx_queue_stopped = false;
591 wl->power_level = WL1271_DEFAULT_POWER_LEVEL; 1039 wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
592 wl->tx_blocks_available = 0; 1040 wl->tx_blocks_available = 0;
593 wl->tx_results_count = 0; 1041 wl->tx_results_count = 0;
594 wl->tx_packets_count = 0; 1042 wl->tx_packets_count = 0;
1043 wl->tx_security_last_seq = 0;
1044 wl->tx_security_seq_16 = 0;
1045 wl->tx_security_seq_32 = 0;
595 wl->time_offset = 0; 1046 wl->time_offset = 0;
596 wl->session_counter = 0; 1047 wl->session_counter = 0;
1048 wl->rate_set = CONF_TX_RATE_MASK_BASIC;
1049 wl->sta_rate_set = 0;
1050 wl->flags = 0;
1051
597 for (i = 0; i < NUM_TX_QUEUES; i++) 1052 for (i = 0; i < NUM_TX_QUEUES; i++)
598 wl->tx_blocks_freed[i] = 0; 1053 wl->tx_blocks_freed[i] = 0;
599 1054
@@ -602,17 +1057,23 @@ static void wl1271_op_stop(struct ieee80211_hw *hw)
602} 1057}
603 1058
604static int wl1271_op_add_interface(struct ieee80211_hw *hw, 1059static int wl1271_op_add_interface(struct ieee80211_hw *hw,
605 struct ieee80211_if_init_conf *conf) 1060 struct ieee80211_vif *vif)
606{ 1061{
607 struct wl1271 *wl = hw->priv; 1062 struct wl1271 *wl = hw->priv;
608 int ret = 0; 1063 int ret = 0;
609 1064
610 wl1271_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM", 1065 wl1271_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM",
611 conf->type, conf->mac_addr); 1066 vif->type, vif->addr);
612 1067
613 mutex_lock(&wl->mutex); 1068 mutex_lock(&wl->mutex);
1069 if (wl->vif) {
1070 ret = -EBUSY;
1071 goto out;
1072 }
1073
1074 wl->vif = vif;
614 1075
615 switch (conf->type) { 1076 switch (vif->type) {
616 case NL80211_IFTYPE_STATION: 1077 case NL80211_IFTYPE_STATION:
617 wl->bss_type = BSS_TYPE_STA_BSS; 1078 wl->bss_type = BSS_TYPE_STA_BSS;
618 break; 1079 break;
@@ -632,9 +1093,14 @@ out:
632} 1093}
633 1094
634static void wl1271_op_remove_interface(struct ieee80211_hw *hw, 1095static void wl1271_op_remove_interface(struct ieee80211_hw *hw,
635 struct ieee80211_if_init_conf *conf) 1096 struct ieee80211_vif *vif)
636{ 1097{
1098 struct wl1271 *wl = hw->priv;
1099
1100 mutex_lock(&wl->mutex);
637 wl1271_debug(DEBUG_MAC80211, "mac80211 remove interface"); 1101 wl1271_debug(DEBUG_MAC80211, "mac80211 remove interface");
1102 wl->vif = NULL;
1103 mutex_unlock(&wl->mutex);
638} 1104}
639 1105
640#if 0 1106#if 0
@@ -657,23 +1123,24 @@ static int wl1271_op_config_interface(struct ieee80211_hw *hw,
657 if (ret < 0) 1123 if (ret < 0)
658 goto out; 1124 goto out;
659 1125
660 memcpy(wl->bssid, conf->bssid, ETH_ALEN); 1126 if (memcmp(wl->bssid, conf->bssid, ETH_ALEN)) {
1127 wl1271_debug(DEBUG_MAC80211, "bssid changed");
661 1128
662 ret = wl1271_cmd_build_null_data(wl); 1129 memcpy(wl->bssid, conf->bssid, ETH_ALEN);
663 if (ret < 0)
664 goto out_sleep;
665 1130
666 wl->ssid_len = conf->ssid_len; 1131 ret = wl1271_cmd_join(wl);
667 if (wl->ssid_len) 1132 if (ret < 0)
668 memcpy(wl->ssid, conf->ssid, wl->ssid_len); 1133 goto out_sleep;
669 1134
670 if (wl->bss_type != BSS_TYPE_IBSS) { 1135 ret = wl1271_cmd_build_null_data(wl);
671 /* FIXME: replace the magic numbers with proper definitions */
672 ret = wl1271_cmd_join(wl, wl->bss_type, 5, 100, 1);
673 if (ret < 0) 1136 if (ret < 0)
674 goto out_sleep; 1137 goto out_sleep;
675 } 1138 }
676 1139
1140 wl->ssid_len = conf->ssid_len;
1141 if (wl->ssid_len)
1142 memcpy(wl->ssid, conf->ssid, wl->ssid_len);
1143
677 if (conf->changed & IEEE80211_IFCC_BEACON) { 1144 if (conf->changed & IEEE80211_IFCC_BEACON) {
678 beacon = ieee80211_beacon_get(hw, vif); 1145 beacon = ieee80211_beacon_get(hw, vif);
679 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_BEACON, 1146 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_BEACON,
@@ -691,12 +1158,6 @@ static int wl1271_op_config_interface(struct ieee80211_hw *hw,
691 1158
692 if (ret < 0) 1159 if (ret < 0)
693 goto out_sleep; 1160 goto out_sleep;
694
695 /* FIXME: replace the magic numbers with proper definitions */
696 ret = wl1271_cmd_join(wl, wl->bss_type, 1, 100, 0);
697
698 if (ret < 0)
699 goto out_sleep;
700 } 1161 }
701 1162
702out_sleep: 1163out_sleep:
@@ -709,6 +1170,51 @@ out:
709} 1170}
710#endif 1171#endif
711 1172
1173static int wl1271_join_channel(struct wl1271 *wl, int channel)
1174{
1175 int ret = 0;
1176 /* we need to use a dummy BSSID for now */
1177 static const u8 dummy_bssid[ETH_ALEN] = { 0x0b, 0xad, 0xde,
1178 0xad, 0xbe, 0xef };
1179
1180 /* the dummy join is not required for ad-hoc */
1181 if (wl->bss_type == BSS_TYPE_IBSS)
1182 goto out;
1183
1184 /* disable mac filter, so we hear everything */
1185 wl->rx_config &= ~CFG_BSSID_FILTER_EN;
1186
1187 wl->channel = channel;
1188 memcpy(wl->bssid, dummy_bssid, ETH_ALEN);
1189
1190 ret = wl1271_cmd_join(wl);
1191 if (ret < 0)
1192 goto out;
1193
1194 set_bit(WL1271_FLAG_JOINED, &wl->flags);
1195
1196out:
1197 return ret;
1198}
1199
1200static int wl1271_unjoin_channel(struct wl1271 *wl)
1201{
1202 int ret;
1203
1204 /* to stop listening to a channel, we disconnect */
1205 ret = wl1271_cmd_disconnect(wl);
1206 if (ret < 0)
1207 goto out;
1208
1209 clear_bit(WL1271_FLAG_JOINED, &wl->flags);
1210 wl->channel = 0;
1211 memset(wl->bssid, 0, ETH_ALEN);
1212 wl->rx_config = WL1271_DEFAULT_RX_CONFIG;
1213
1214out:
1215 return ret;
1216}
1217
712static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed) 1218static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed)
713{ 1219{
714 struct wl1271 *wl = hw->priv; 1220 struct wl1271 *wl = hw->priv;
@@ -717,58 +1223,75 @@ static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed)
717 1223
718 channel = ieee80211_frequency_to_channel(conf->channel->center_freq); 1224 channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
719 1225
720 wl1271_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d", 1226 wl1271_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d %s",
721 channel, 1227 channel,
722 conf->flags & IEEE80211_CONF_PS ? "on" : "off", 1228 conf->flags & IEEE80211_CONF_PS ? "on" : "off",
723 conf->power_level); 1229 conf->power_level,
1230 conf->flags & IEEE80211_CONF_IDLE ? "idle" : "in use");
724 1231
725 mutex_lock(&wl->mutex); 1232 mutex_lock(&wl->mutex);
726 1233
1234 wl->band = conf->channel->band;
1235
727 ret = wl1271_ps_elp_wakeup(wl, false); 1236 ret = wl1271_ps_elp_wakeup(wl, false);
728 if (ret < 0) 1237 if (ret < 0)
729 goto out; 1238 goto out;
730 1239
731 if (channel != wl->channel) { 1240 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
732 u8 old_channel = wl->channel; 1241 if (conf->flags & IEEE80211_CONF_IDLE &&
733 wl->channel = channel; 1242 test_bit(WL1271_FLAG_JOINED, &wl->flags))
734 1243 wl1271_unjoin_channel(wl);
735 /* FIXME: use beacon interval provided by mac80211 */ 1244 else if (!(conf->flags & IEEE80211_CONF_IDLE))
736 ret = wl1271_cmd_join(wl, wl->bss_type, 1, 100, 0); 1245 wl1271_join_channel(wl, channel);
737 if (ret < 0) { 1246
738 wl->channel = old_channel; 1247 if (conf->flags & IEEE80211_CONF_IDLE) {
739 goto out_sleep; 1248 wl->rate_set = CONF_TX_RATE_MASK_BASIC;
1249 wl->sta_rate_set = 0;
1250 wl1271_acx_rate_policies(wl);
740 } 1251 }
741 } 1252 }
742 1253
743 ret = wl1271_cmd_build_null_data(wl); 1254 /* if the channel changes while joined, join again */
744 if (ret < 0) 1255 if (channel != wl->channel &&
745 goto out_sleep; 1256 test_bit(WL1271_FLAG_JOINED, &wl->flags)) {
746 1257 wl->channel = channel;
747 if (conf->flags & IEEE80211_CONF_PS && !wl->psm_requested) { 1258 /* FIXME: maybe use CMD_CHANNEL_SWITCH for this? */
748 wl1271_info("psm enabled"); 1259 ret = wl1271_cmd_join(wl);
1260 if (ret < 0)
1261 wl1271_warning("cmd join to update channel failed %d",
1262 ret);
1263 } else
1264 wl->channel = channel;
749 1265
750 wl->psm_requested = true; 1266 if (conf->flags & IEEE80211_CONF_PS &&
1267 !test_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags)) {
1268 set_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags);
751 1269
752 /* 1270 /*
753 * We enter PSM only if we're already associated. 1271 * We enter PSM only if we're already associated.
754 * If we're not, we'll enter it when joining an SSID, 1272 * If we're not, we'll enter it when joining an SSID,
755 * through the bss_info_changed() hook. 1273 * through the bss_info_changed() hook.
756 */ 1274 */
757 ret = wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE); 1275 if (test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) {
1276 wl1271_info("psm enabled");
1277 ret = wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE,
1278 true);
1279 }
758 } else if (!(conf->flags & IEEE80211_CONF_PS) && 1280 } else if (!(conf->flags & IEEE80211_CONF_PS) &&
759 wl->psm_requested) { 1281 test_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags)) {
760 wl1271_info("psm disabled"); 1282 wl1271_info("psm disabled");
761 1283
762 wl->psm_requested = false; 1284 clear_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags);
763 1285
764 if (wl->psm) 1286 if (test_bit(WL1271_FLAG_PSM, &wl->flags))
765 ret = wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE); 1287 ret = wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE,
1288 true);
766 } 1289 }
767 1290
768 if (conf->power_level != wl->power_level) { 1291 if (conf->power_level != wl->power_level) {
769 ret = wl1271_acx_tx_power(wl, conf->power_level); 1292 ret = wl1271_acx_tx_power(wl, conf->power_level);
770 if (ret < 0) 1293 if (ret < 0)
771 goto out; 1294 goto out_sleep;
772 1295
773 wl->power_level = conf->power_level; 1296 wl->power_level = conf->power_level;
774 } 1297 }
@@ -782,6 +1305,45 @@ out:
782 return ret; 1305 return ret;
783} 1306}
784 1307
1308struct wl1271_filter_params {
1309 bool enabled;
1310 int mc_list_length;
1311 u8 mc_list[ACX_MC_ADDRESS_GROUP_MAX][ETH_ALEN];
1312};
1313
1314static u64 wl1271_op_prepare_multicast(struct ieee80211_hw *hw, int mc_count,
1315 struct dev_addr_list *mc_list)
1316{
1317 struct wl1271_filter_params *fp;
1318 int i;
1319
1320 fp = kzalloc(sizeof(*fp), GFP_ATOMIC);
1321 if (!fp) {
1322 wl1271_error("Out of memory setting filters.");
1323 return 0;
1324 }
1325
1326 /* update multicast filtering parameters */
1327 fp->enabled = true;
1328 if (mc_count > ACX_MC_ADDRESS_GROUP_MAX) {
1329 mc_count = 0;
1330 fp->enabled = false;
1331 }
1332
1333 fp->mc_list_length = 0;
1334 for (i = 0; i < mc_count; i++) {
1335 if (mc_list->da_addrlen == ETH_ALEN) {
1336 memcpy(fp->mc_list[fp->mc_list_length],
1337 mc_list->da_addr, ETH_ALEN);
1338 fp->mc_list_length++;
1339 } else
1340 wl1271_warning("Unknown mc address length.");
1341 mc_list = mc_list->next;
1342 }
1343
1344 return (u64)(unsigned long)fp;
1345}
1346
785#define WL1271_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \ 1347#define WL1271_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \
786 FIF_ALLMULTI | \ 1348 FIF_ALLMULTI | \
787 FIF_FCSFAIL | \ 1349 FIF_FCSFAIL | \
@@ -791,28 +1353,53 @@ out:
791 1353
792static void wl1271_op_configure_filter(struct ieee80211_hw *hw, 1354static void wl1271_op_configure_filter(struct ieee80211_hw *hw,
793 unsigned int changed, 1355 unsigned int changed,
794 unsigned int *total,u64 multicast) 1356 unsigned int *total, u64 multicast)
795{ 1357{
1358 struct wl1271_filter_params *fp = (void *)(unsigned long)multicast;
796 struct wl1271 *wl = hw->priv; 1359 struct wl1271 *wl = hw->priv;
1360 int ret;
797 1361
798 wl1271_debug(DEBUG_MAC80211, "mac80211 configure filter"); 1362 wl1271_debug(DEBUG_MAC80211, "mac80211 configure filter");
799 1363
1364 mutex_lock(&wl->mutex);
1365
1366 if (wl->state == WL1271_STATE_OFF)
1367 goto out;
1368
1369 ret = wl1271_ps_elp_wakeup(wl, false);
1370 if (ret < 0)
1371 goto out;
1372
800 *total &= WL1271_SUPPORTED_FILTERS; 1373 *total &= WL1271_SUPPORTED_FILTERS;
801 changed &= WL1271_SUPPORTED_FILTERS; 1374 changed &= WL1271_SUPPORTED_FILTERS;
802 1375
1376 if (*total & FIF_ALLMULTI)
1377 ret = wl1271_acx_group_address_tbl(wl, false, NULL, 0);
1378 else if (fp)
1379 ret = wl1271_acx_group_address_tbl(wl, fp->enabled,
1380 fp->mc_list,
1381 fp->mc_list_length);
1382 if (ret < 0)
1383 goto out_sleep;
1384
1385 kfree(fp);
1386
1387 /* FIXME: We still need to set our filters properly */
1388
1389 /* determine, whether supported filter values have changed */
803 if (changed == 0) 1390 if (changed == 0)
804 return; 1391 goto out_sleep;
805 1392
806 /* FIXME: wl->rx_config and wl->rx_filter are not protected */ 1393 /* apply configured filters */
807 wl->rx_config = WL1271_DEFAULT_RX_CONFIG; 1394 ret = wl1271_acx_rx_config(wl, wl->rx_config, wl->rx_filter);
808 wl->rx_filter = WL1271_DEFAULT_RX_FILTER; 1395 if (ret < 0)
1396 goto out_sleep;
809 1397
810 /* 1398out_sleep:
811 * FIXME: workqueues need to be properly cancelled on stop(), for 1399 wl1271_ps_elp_sleep(wl);
812 * now let's just disable changing the filter settings. They will 1400
813 * be updated any on config(). 1401out:
814 */ 1402 mutex_unlock(&wl->mutex);
815 /* schedule_work(&wl->filter_work); */
816} 1403}
817 1404
818static int wl1271_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, 1405static int wl1271_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
@@ -823,6 +1410,8 @@ static int wl1271_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
823 struct wl1271 *wl = hw->priv; 1410 struct wl1271 *wl = hw->priv;
824 const u8 *addr; 1411 const u8 *addr;
825 int ret; 1412 int ret;
1413 u32 tx_seq_32 = 0;
1414 u16 tx_seq_16 = 0;
826 u8 key_type; 1415 u8 key_type;
827 1416
828 static const u8 bcast_addr[ETH_ALEN] = 1417 static const u8 bcast_addr[ETH_ALEN] =
@@ -861,11 +1450,15 @@ static int wl1271_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
861 key_type = KEY_TKIP; 1450 key_type = KEY_TKIP;
862 1451
863 key_conf->hw_key_idx = key_conf->keyidx; 1452 key_conf->hw_key_idx = key_conf->keyidx;
1453 tx_seq_32 = wl->tx_security_seq_32;
1454 tx_seq_16 = wl->tx_security_seq_16;
864 break; 1455 break;
865 case ALG_CCMP: 1456 case ALG_CCMP:
866 key_type = KEY_AES; 1457 key_type = KEY_AES;
867 1458
868 key_conf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; 1459 key_conf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1460 tx_seq_32 = wl->tx_security_seq_32;
1461 tx_seq_16 = wl->tx_security_seq_16;
869 break; 1462 break;
870 default: 1463 default:
871 wl1271_error("Unknown key algo 0x%x", key_conf->alg); 1464 wl1271_error("Unknown key algo 0x%x", key_conf->alg);
@@ -879,18 +1472,33 @@ static int wl1271_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
879 ret = wl1271_cmd_set_key(wl, KEY_ADD_OR_REPLACE, 1472 ret = wl1271_cmd_set_key(wl, KEY_ADD_OR_REPLACE,
880 key_conf->keyidx, key_type, 1473 key_conf->keyidx, key_type,
881 key_conf->keylen, key_conf->key, 1474 key_conf->keylen, key_conf->key,
882 addr); 1475 addr, tx_seq_32, tx_seq_16);
883 if (ret < 0) { 1476 if (ret < 0) {
884 wl1271_error("Could not add or replace key"); 1477 wl1271_error("Could not add or replace key");
885 goto out_sleep; 1478 goto out_sleep;
886 } 1479 }
1480
1481 /* the default WEP key needs to be configured at least once */
1482 if (key_type == KEY_WEP) {
1483 ret = wl1271_cmd_set_default_wep_key(wl,
1484 wl->default_key);
1485 if (ret < 0)
1486 goto out_sleep;
1487 }
887 break; 1488 break;
888 1489
889 case DISABLE_KEY: 1490 case DISABLE_KEY:
1491 /* The wl1271 does not allow to remove unicast keys - they
1492 will be cleared automatically on next CMD_JOIN. Ignore the
1493 request silently, as we dont want the mac80211 to emit
1494 an error message. */
1495 if (!is_broadcast_ether_addr(addr))
1496 break;
1497
890 ret = wl1271_cmd_set_key(wl, KEY_REMOVE, 1498 ret = wl1271_cmd_set_key(wl, KEY_REMOVE,
891 key_conf->keyidx, key_type, 1499 key_conf->keyidx, key_type,
892 key_conf->keylen, key_conf->key, 1500 key_conf->keylen, key_conf->key,
893 addr); 1501 addr, 0, 0);
894 if (ret < 0) { 1502 if (ret < 0) {
895 wl1271_error("Could not remove key"); 1503 wl1271_error("Could not remove key");
896 goto out_sleep; 1504 goto out_sleep;
@@ -921,13 +1529,13 @@ static int wl1271_op_hw_scan(struct ieee80211_hw *hw,
921 struct wl1271 *wl = hw->priv; 1529 struct wl1271 *wl = hw->priv;
922 int ret; 1530 int ret;
923 u8 *ssid = NULL; 1531 u8 *ssid = NULL;
924 size_t ssid_len = 0; 1532 size_t len = 0;
925 1533
926 wl1271_debug(DEBUG_MAC80211, "mac80211 hw scan"); 1534 wl1271_debug(DEBUG_MAC80211, "mac80211 hw scan");
927 1535
928 if (req->n_ssids) { 1536 if (req->n_ssids) {
929 ssid = req->ssids[0].ssid; 1537 ssid = req->ssids[0].ssid;
930 ssid_len = req->ssids[0].ssid_len; 1538 len = req->ssids[0].ssid_len;
931 } 1539 }
932 1540
933 mutex_lock(&wl->mutex); 1541 mutex_lock(&wl->mutex);
@@ -936,7 +1544,12 @@ static int wl1271_op_hw_scan(struct ieee80211_hw *hw,
936 if (ret < 0) 1544 if (ret < 0)
937 goto out; 1545 goto out;
938 1546
939 ret = wl1271_cmd_scan(hw->priv, ssid, ssid_len, 1, 0, 13, 3); 1547 if (wl1271_11a_enabled())
1548 ret = wl1271_cmd_scan(hw->priv, ssid, len, 1, 0,
1549 WL1271_SCAN_BAND_DUAL, 3);
1550 else
1551 ret = wl1271_cmd_scan(hw->priv, ssid, len, 1, 0,
1552 WL1271_SCAN_BAND_2_4_GHZ, 3);
940 1553
941 wl1271_ps_elp_sleep(wl); 1554 wl1271_ps_elp_sleep(wl);
942 1555
@@ -969,6 +1582,23 @@ out:
969 return ret; 1582 return ret;
970} 1583}
971 1584
1585static void wl1271_ssid_set(struct wl1271 *wl, struct sk_buff *beacon)
1586{
1587 u8 *ptr = beacon->data +
1588 offsetof(struct ieee80211_mgmt, u.beacon.variable);
1589
1590 /* find the location of the ssid in the beacon */
1591 while (ptr < beacon->data + beacon->len) {
1592 if (ptr[0] == WLAN_EID_SSID) {
1593 wl->ssid_len = ptr[1];
1594 memcpy(wl->ssid, ptr+2, wl->ssid_len);
1595 return;
1596 }
1597 ptr += ptr[1];
1598 }
1599 wl1271_error("ad-hoc beacon template has no SSID!\n");
1600}
1601
972static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw, 1602static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw,
973 struct ieee80211_vif *vif, 1603 struct ieee80211_vif *vif,
974 struct ieee80211_bss_conf *bss_conf, 1604 struct ieee80211_bss_conf *bss_conf,
@@ -976,6 +1606,7 @@ static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw,
976{ 1606{
977 enum wl1271_cmd_ps_mode mode; 1607 enum wl1271_cmd_ps_mode mode;
978 struct wl1271 *wl = hw->priv; 1608 struct wl1271 *wl = hw->priv;
1609 bool do_join = false;
979 int ret; 1610 int ret;
980 1611
981 wl1271_debug(DEBUG_MAC80211, "mac80211 bss info changed"); 1612 wl1271_debug(DEBUG_MAC80211, "mac80211 bss info changed");
@@ -986,10 +1617,74 @@ static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw,
986 if (ret < 0) 1617 if (ret < 0)
987 goto out; 1618 goto out;
988 1619
1620 if (wl->bss_type == BSS_TYPE_IBSS) {
1621 /* FIXME: This implements rudimentary ad-hoc support -
1622 proper templates are on the wish list and notification
1623 on when they change. This patch will update the templates
1624 on every call to this function. */
1625 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
1626
1627 if (beacon) {
1628 struct ieee80211_hdr *hdr;
1629
1630 wl1271_ssid_set(wl, beacon);
1631 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_BEACON,
1632 beacon->data,
1633 beacon->len);
1634
1635 if (ret < 0) {
1636 dev_kfree_skb(beacon);
1637 goto out_sleep;
1638 }
1639
1640 hdr = (struct ieee80211_hdr *) beacon->data;
1641 hdr->frame_control = cpu_to_le16(
1642 IEEE80211_FTYPE_MGMT |
1643 IEEE80211_STYPE_PROBE_RESP);
1644
1645 ret = wl1271_cmd_template_set(wl,
1646 CMD_TEMPL_PROBE_RESPONSE,
1647 beacon->data,
1648 beacon->len);
1649 dev_kfree_skb(beacon);
1650 if (ret < 0)
1651 goto out_sleep;
1652
1653 /* Need to update the SSID (for filtering etc) */
1654 do_join = true;
1655 }
1656 }
1657
1658 if ((changed & BSS_CHANGED_BSSID) &&
1659 /*
1660 * Now we know the correct bssid, so we send a new join command
1661 * and enable the BSSID filter
1662 */
1663 memcmp(wl->bssid, bss_conf->bssid, ETH_ALEN)) {
1664 wl->rx_config |= CFG_BSSID_FILTER_EN;
1665 memcpy(wl->bssid, bss_conf->bssid, ETH_ALEN);
1666 ret = wl1271_cmd_build_null_data(wl);
1667 if (ret < 0) {
1668 wl1271_warning("cmd buld null data failed %d",
1669 ret);
1670 goto out_sleep;
1671 }
1672
1673 /* Need to update the BSSID (for filtering etc) */
1674 do_join = true;
1675 }
1676
989 if (changed & BSS_CHANGED_ASSOC) { 1677 if (changed & BSS_CHANGED_ASSOC) {
990 if (bss_conf->assoc) { 1678 if (bss_conf->assoc) {
991 wl->aid = bss_conf->aid; 1679 wl->aid = bss_conf->aid;
992 1680 set_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags);
1681
1682 /*
1683 * with wl1271, we don't need to update the
1684 * beacon_int and dtim_period, because the firmware
1685 * updates it by itself when the first beacon is
1686 * received after a join.
1687 */
993 ret = wl1271_cmd_build_ps_poll(wl, wl->aid); 1688 ret = wl1271_cmd_build_ps_poll(wl, wl->aid);
994 if (ret < 0) 1689 if (ret < 0)
995 goto out_sleep; 1690 goto out_sleep;
@@ -999,14 +1694,21 @@ static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw,
999 goto out_sleep; 1694 goto out_sleep;
1000 1695
1001 /* If we want to go in PSM but we're not there yet */ 1696 /* If we want to go in PSM but we're not there yet */
1002 if (wl->psm_requested && !wl->psm) { 1697 if (test_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags) &&
1698 !test_bit(WL1271_FLAG_PSM, &wl->flags)) {
1003 mode = STATION_POWER_SAVE_MODE; 1699 mode = STATION_POWER_SAVE_MODE;
1004 ret = wl1271_ps_set_mode(wl, mode); 1700 ret = wl1271_ps_set_mode(wl, mode, true);
1005 if (ret < 0) 1701 if (ret < 0)
1006 goto out_sleep; 1702 goto out_sleep;
1007 } 1703 }
1704 } else {
1705 /* use defaults when not associated */
1706 clear_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags);
1707 wl->aid = 0;
1008 } 1708 }
1709
1009 } 1710 }
1711
1010 if (changed & BSS_CHANGED_ERP_SLOT) { 1712 if (changed & BSS_CHANGED_ERP_SLOT) {
1011 if (bss_conf->use_short_slot) 1713 if (bss_conf->use_short_slot)
1012 ret = wl1271_acx_slot(wl, SLOT_TIME_SHORT); 1714 ret = wl1271_acx_slot(wl, SLOT_TIME_SHORT);
@@ -1036,72 +1738,118 @@ static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw,
1036 } 1738 }
1037 } 1739 }
1038 1740
1741 if (do_join) {
1742 ret = wl1271_cmd_join(wl);
1743 if (ret < 0) {
1744 wl1271_warning("cmd join failed %d", ret);
1745 goto out_sleep;
1746 }
1747 set_bit(WL1271_FLAG_JOINED, &wl->flags);
1748 }
1749
1750out_sleep:
1751 wl1271_ps_elp_sleep(wl);
1752
1753out:
1754 mutex_unlock(&wl->mutex);
1755}
1756
1757static int wl1271_op_conf_tx(struct ieee80211_hw *hw, u16 queue,
1758 const struct ieee80211_tx_queue_params *params)
1759{
1760 struct wl1271 *wl = hw->priv;
1761 int ret;
1762
1763 mutex_lock(&wl->mutex);
1764
1765 wl1271_debug(DEBUG_MAC80211, "mac80211 conf tx %d", queue);
1766
1767 ret = wl1271_ps_elp_wakeup(wl, false);
1768 if (ret < 0)
1769 goto out;
1770
1771 ret = wl1271_acx_ac_cfg(wl, wl1271_tx_get_queue(queue),
1772 params->cw_min, params->cw_max,
1773 params->aifs, params->txop);
1774 if (ret < 0)
1775 goto out_sleep;
1776
1777 ret = wl1271_acx_tid_cfg(wl, wl1271_tx_get_queue(queue),
1778 CONF_CHANNEL_TYPE_EDCF,
1779 wl1271_tx_get_queue(queue),
1780 CONF_PS_SCHEME_LEGACY_PSPOLL,
1781 CONF_ACK_POLICY_LEGACY, 0, 0);
1782 if (ret < 0)
1783 goto out_sleep;
1784
1039out_sleep: 1785out_sleep:
1040 wl1271_ps_elp_sleep(wl); 1786 wl1271_ps_elp_sleep(wl);
1041 1787
1042out: 1788out:
1043 mutex_unlock(&wl->mutex); 1789 mutex_unlock(&wl->mutex);
1790
1791 return ret;
1044} 1792}
1045 1793
1046 1794
1047/* can't be const, mac80211 writes to this */ 1795/* can't be const, mac80211 writes to this */
1048static struct ieee80211_rate wl1271_rates[] = { 1796static struct ieee80211_rate wl1271_rates[] = {
1049 { .bitrate = 10, 1797 { .bitrate = 10,
1050 .hw_value = 0x1, 1798 .hw_value = CONF_HW_BIT_RATE_1MBPS,
1051 .hw_value_short = 0x1, }, 1799 .hw_value_short = CONF_HW_BIT_RATE_1MBPS, },
1052 { .bitrate = 20, 1800 { .bitrate = 20,
1053 .hw_value = 0x2, 1801 .hw_value = CONF_HW_BIT_RATE_2MBPS,
1054 .hw_value_short = 0x2, 1802 .hw_value_short = CONF_HW_BIT_RATE_2MBPS,
1055 .flags = IEEE80211_RATE_SHORT_PREAMBLE }, 1803 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
1056 { .bitrate = 55, 1804 { .bitrate = 55,
1057 .hw_value = 0x4, 1805 .hw_value = CONF_HW_BIT_RATE_5_5MBPS,
1058 .hw_value_short = 0x4, 1806 .hw_value_short = CONF_HW_BIT_RATE_5_5MBPS,
1059 .flags = IEEE80211_RATE_SHORT_PREAMBLE }, 1807 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
1060 { .bitrate = 110, 1808 { .bitrate = 110,
1061 .hw_value = 0x20, 1809 .hw_value = CONF_HW_BIT_RATE_11MBPS,
1062 .hw_value_short = 0x20, 1810 .hw_value_short = CONF_HW_BIT_RATE_11MBPS,
1063 .flags = IEEE80211_RATE_SHORT_PREAMBLE }, 1811 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
1064 { .bitrate = 60, 1812 { .bitrate = 60,
1065 .hw_value = 0x8, 1813 .hw_value = CONF_HW_BIT_RATE_6MBPS,
1066 .hw_value_short = 0x8, }, 1814 .hw_value_short = CONF_HW_BIT_RATE_6MBPS, },
1067 { .bitrate = 90, 1815 { .bitrate = 90,
1068 .hw_value = 0x10, 1816 .hw_value = CONF_HW_BIT_RATE_9MBPS,
1069 .hw_value_short = 0x10, }, 1817 .hw_value_short = CONF_HW_BIT_RATE_9MBPS, },
1070 { .bitrate = 120, 1818 { .bitrate = 120,
1071 .hw_value = 0x40, 1819 .hw_value = CONF_HW_BIT_RATE_12MBPS,
1072 .hw_value_short = 0x40, }, 1820 .hw_value_short = CONF_HW_BIT_RATE_12MBPS, },
1073 { .bitrate = 180, 1821 { .bitrate = 180,
1074 .hw_value = 0x80, 1822 .hw_value = CONF_HW_BIT_RATE_18MBPS,
1075 .hw_value_short = 0x80, }, 1823 .hw_value_short = CONF_HW_BIT_RATE_18MBPS, },
1076 { .bitrate = 240, 1824 { .bitrate = 240,
1077 .hw_value = 0x200, 1825 .hw_value = CONF_HW_BIT_RATE_24MBPS,
1078 .hw_value_short = 0x200, }, 1826 .hw_value_short = CONF_HW_BIT_RATE_24MBPS, },
1079 { .bitrate = 360, 1827 { .bitrate = 360,
1080 .hw_value = 0x400, 1828 .hw_value = CONF_HW_BIT_RATE_36MBPS,
1081 .hw_value_short = 0x400, }, 1829 .hw_value_short = CONF_HW_BIT_RATE_36MBPS, },
1082 { .bitrate = 480, 1830 { .bitrate = 480,
1083 .hw_value = 0x800, 1831 .hw_value = CONF_HW_BIT_RATE_48MBPS,
1084 .hw_value_short = 0x800, }, 1832 .hw_value_short = CONF_HW_BIT_RATE_48MBPS, },
1085 { .bitrate = 540, 1833 { .bitrate = 540,
1086 .hw_value = 0x1000, 1834 .hw_value = CONF_HW_BIT_RATE_54MBPS,
1087 .hw_value_short = 0x1000, }, 1835 .hw_value_short = CONF_HW_BIT_RATE_54MBPS, },
1088}; 1836};
1089 1837
1090/* can't be const, mac80211 writes to this */ 1838/* can't be const, mac80211 writes to this */
1091static struct ieee80211_channel wl1271_channels[] = { 1839static struct ieee80211_channel wl1271_channels[] = {
1092 { .hw_value = 1, .center_freq = 2412}, 1840 { .hw_value = 1, .center_freq = 2412, .max_power = 25 },
1093 { .hw_value = 2, .center_freq = 2417}, 1841 { .hw_value = 2, .center_freq = 2417, .max_power = 25 },
1094 { .hw_value = 3, .center_freq = 2422}, 1842 { .hw_value = 3, .center_freq = 2422, .max_power = 25 },
1095 { .hw_value = 4, .center_freq = 2427}, 1843 { .hw_value = 4, .center_freq = 2427, .max_power = 25 },
1096 { .hw_value = 5, .center_freq = 2432}, 1844 { .hw_value = 5, .center_freq = 2432, .max_power = 25 },
1097 { .hw_value = 6, .center_freq = 2437}, 1845 { .hw_value = 6, .center_freq = 2437, .max_power = 25 },
1098 { .hw_value = 7, .center_freq = 2442}, 1846 { .hw_value = 7, .center_freq = 2442, .max_power = 25 },
1099 { .hw_value = 8, .center_freq = 2447}, 1847 { .hw_value = 8, .center_freq = 2447, .max_power = 25 },
1100 { .hw_value = 9, .center_freq = 2452}, 1848 { .hw_value = 9, .center_freq = 2452, .max_power = 25 },
1101 { .hw_value = 10, .center_freq = 2457}, 1849 { .hw_value = 10, .center_freq = 2457, .max_power = 25 },
1102 { .hw_value = 11, .center_freq = 2462}, 1850 { .hw_value = 11, .center_freq = 2462, .max_power = 25 },
1103 { .hw_value = 12, .center_freq = 2467}, 1851 { .hw_value = 12, .center_freq = 2467, .max_power = 25 },
1104 { .hw_value = 13, .center_freq = 2472}, 1852 { .hw_value = 13, .center_freq = 2472, .max_power = 25 },
1105}; 1853};
1106 1854
1107/* can't be const, mac80211 writes to this */ 1855/* can't be const, mac80211 writes to this */
@@ -1112,6 +1860,88 @@ static struct ieee80211_supported_band wl1271_band_2ghz = {
1112 .n_bitrates = ARRAY_SIZE(wl1271_rates), 1860 .n_bitrates = ARRAY_SIZE(wl1271_rates),
1113}; 1861};
1114 1862
1863/* 5 GHz data rates for WL1273 */
1864static struct ieee80211_rate wl1271_rates_5ghz[] = {
1865 { .bitrate = 60,
1866 .hw_value = CONF_HW_BIT_RATE_6MBPS,
1867 .hw_value_short = CONF_HW_BIT_RATE_6MBPS, },
1868 { .bitrate = 90,
1869 .hw_value = CONF_HW_BIT_RATE_9MBPS,
1870 .hw_value_short = CONF_HW_BIT_RATE_9MBPS, },
1871 { .bitrate = 120,
1872 .hw_value = CONF_HW_BIT_RATE_12MBPS,
1873 .hw_value_short = CONF_HW_BIT_RATE_12MBPS, },
1874 { .bitrate = 180,
1875 .hw_value = CONF_HW_BIT_RATE_18MBPS,
1876 .hw_value_short = CONF_HW_BIT_RATE_18MBPS, },
1877 { .bitrate = 240,
1878 .hw_value = CONF_HW_BIT_RATE_24MBPS,
1879 .hw_value_short = CONF_HW_BIT_RATE_24MBPS, },
1880 { .bitrate = 360,
1881 .hw_value = CONF_HW_BIT_RATE_36MBPS,
1882 .hw_value_short = CONF_HW_BIT_RATE_36MBPS, },
1883 { .bitrate = 480,
1884 .hw_value = CONF_HW_BIT_RATE_48MBPS,
1885 .hw_value_short = CONF_HW_BIT_RATE_48MBPS, },
1886 { .bitrate = 540,
1887 .hw_value = CONF_HW_BIT_RATE_54MBPS,
1888 .hw_value_short = CONF_HW_BIT_RATE_54MBPS, },
1889};
1890
1891/* 5 GHz band channels for WL1273 */
1892static struct ieee80211_channel wl1271_channels_5ghz[] = {
1893 { .hw_value = 183, .center_freq = 4915},
1894 { .hw_value = 184, .center_freq = 4920},
1895 { .hw_value = 185, .center_freq = 4925},
1896 { .hw_value = 187, .center_freq = 4935},
1897 { .hw_value = 188, .center_freq = 4940},
1898 { .hw_value = 189, .center_freq = 4945},
1899 { .hw_value = 192, .center_freq = 4960},
1900 { .hw_value = 196, .center_freq = 4980},
1901 { .hw_value = 7, .center_freq = 5035},
1902 { .hw_value = 8, .center_freq = 5040},
1903 { .hw_value = 9, .center_freq = 5045},
1904 { .hw_value = 11, .center_freq = 5055},
1905 { .hw_value = 12, .center_freq = 5060},
1906 { .hw_value = 16, .center_freq = 5080},
1907 { .hw_value = 34, .center_freq = 5170},
1908 { .hw_value = 36, .center_freq = 5180},
1909 { .hw_value = 38, .center_freq = 5190},
1910 { .hw_value = 40, .center_freq = 5200},
1911 { .hw_value = 42, .center_freq = 5210},
1912 { .hw_value = 44, .center_freq = 5220},
1913 { .hw_value = 46, .center_freq = 5230},
1914 { .hw_value = 48, .center_freq = 5240},
1915 { .hw_value = 52, .center_freq = 5260},
1916 { .hw_value = 56, .center_freq = 5280},
1917 { .hw_value = 60, .center_freq = 5300},
1918 { .hw_value = 64, .center_freq = 5320},
1919 { .hw_value = 100, .center_freq = 5500},
1920 { .hw_value = 104, .center_freq = 5520},
1921 { .hw_value = 108, .center_freq = 5540},
1922 { .hw_value = 112, .center_freq = 5560},
1923 { .hw_value = 116, .center_freq = 5580},
1924 { .hw_value = 120, .center_freq = 5600},
1925 { .hw_value = 124, .center_freq = 5620},
1926 { .hw_value = 128, .center_freq = 5640},
1927 { .hw_value = 132, .center_freq = 5660},
1928 { .hw_value = 136, .center_freq = 5680},
1929 { .hw_value = 140, .center_freq = 5700},
1930 { .hw_value = 149, .center_freq = 5745},
1931 { .hw_value = 153, .center_freq = 5765},
1932 { .hw_value = 157, .center_freq = 5785},
1933 { .hw_value = 161, .center_freq = 5805},
1934 { .hw_value = 165, .center_freq = 5825},
1935};
1936
1937
1938static struct ieee80211_supported_band wl1271_band_5ghz = {
1939 .channels = wl1271_channels_5ghz,
1940 .n_channels = ARRAY_SIZE(wl1271_channels_5ghz),
1941 .bitrates = wl1271_rates_5ghz,
1942 .n_bitrates = ARRAY_SIZE(wl1271_rates_5ghz),
1943};
1944
1115static const struct ieee80211_ops wl1271_ops = { 1945static const struct ieee80211_ops wl1271_ops = {
1116 .start = wl1271_op_start, 1946 .start = wl1271_op_start,
1117 .stop = wl1271_op_stop, 1947 .stop = wl1271_op_stop,
@@ -1119,12 +1949,15 @@ static const struct ieee80211_ops wl1271_ops = {
1119 .remove_interface = wl1271_op_remove_interface, 1949 .remove_interface = wl1271_op_remove_interface,
1120 .config = wl1271_op_config, 1950 .config = wl1271_op_config,
1121/* .config_interface = wl1271_op_config_interface, */ 1951/* .config_interface = wl1271_op_config_interface, */
1952 .prepare_multicast = wl1271_op_prepare_multicast,
1122 .configure_filter = wl1271_op_configure_filter, 1953 .configure_filter = wl1271_op_configure_filter,
1123 .tx = wl1271_op_tx, 1954 .tx = wl1271_op_tx,
1124 .set_key = wl1271_op_set_key, 1955 .set_key = wl1271_op_set_key,
1125 .hw_scan = wl1271_op_hw_scan, 1956 .hw_scan = wl1271_op_hw_scan,
1126 .bss_info_changed = wl1271_op_bss_info_changed, 1957 .bss_info_changed = wl1271_op_bss_info_changed,
1127 .set_rts_threshold = wl1271_op_set_rts_threshold, 1958 .set_rts_threshold = wl1271_op_set_rts_threshold,
1959 .conf_tx = wl1271_op_conf_tx,
1960 CFG80211_TESTMODE_CMD(wl1271_tm_cmd)
1128}; 1961};
1129 1962
1130static int wl1271_register_hw(struct wl1271 *wl) 1963static int wl1271_register_hw(struct wl1271 *wl)
@@ -1151,24 +1984,27 @@ static int wl1271_register_hw(struct wl1271 *wl)
1151 1984
1152static int wl1271_init_ieee80211(struct wl1271 *wl) 1985static int wl1271_init_ieee80211(struct wl1271 *wl)
1153{ 1986{
1154 /* 1987 /* The tx descriptor buffer and the TKIP space. */
1155 * The tx descriptor buffer and the TKIP space. 1988 wl->hw->extra_tx_headroom = WL1271_TKIP_IV_SPACE +
1156 * 1989 sizeof(struct wl1271_tx_hw_descr);
1157 * FIXME: add correct 1271 descriptor size
1158 */
1159 wl->hw->extra_tx_headroom = WL1271_TKIP_IV_SPACE;
1160 1990
1161 /* unit us */ 1991 /* unit us */
1162 /* FIXME: find a proper value */ 1992 /* FIXME: find a proper value */
1163 wl->hw->channel_change_time = 10000; 1993 wl->hw->channel_change_time = 10000;
1164 1994
1165 wl->hw->flags = IEEE80211_HW_SIGNAL_DBM | 1995 wl->hw->flags = IEEE80211_HW_SIGNAL_DBM |
1166 IEEE80211_HW_NOISE_DBM; 1996 IEEE80211_HW_NOISE_DBM |
1997 IEEE80211_HW_BEACON_FILTER |
1998 IEEE80211_HW_SUPPORTS_PS;
1167 1999
1168 wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION); 2000 wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
2001 BIT(NL80211_IFTYPE_ADHOC);
1169 wl->hw->wiphy->max_scan_ssids = 1; 2002 wl->hw->wiphy->max_scan_ssids = 1;
1170 wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl1271_band_2ghz; 2003 wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl1271_band_2ghz;
1171 2004
2005 if (wl1271_11a_enabled())
2006 wl->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &wl1271_band_5ghz;
2007
1172 SET_IEEE80211_DEV(wl->hw, &wl->spi->dev); 2008 SET_IEEE80211_DEV(wl->hw, &wl->spi->dev);
1173 2009
1174 return 0; 2010 return 0;
@@ -1190,73 +2026,99 @@ static struct platform_device wl1271_device = {
1190}; 2026};
1191 2027
1192#define WL1271_DEFAULT_CHANNEL 0 2028#define WL1271_DEFAULT_CHANNEL 0
1193static int __devinit wl1271_probe(struct spi_device *spi) 2029
2030static struct ieee80211_hw *wl1271_alloc_hw(void)
1194{ 2031{
1195 struct wl12xx_platform_data *pdata;
1196 struct ieee80211_hw *hw; 2032 struct ieee80211_hw *hw;
1197 struct wl1271 *wl; 2033 struct wl1271 *wl;
1198 int ret, i; 2034 int i;
1199 static const u8 nokia_oui[3] = {0x00, 0x1f, 0xdf};
1200
1201 pdata = spi->dev.platform_data;
1202 if (!pdata) {
1203 wl1271_error("no platform data");
1204 return -ENODEV;
1205 }
1206 2035
1207 hw = ieee80211_alloc_hw(sizeof(*wl), &wl1271_ops); 2036 hw = ieee80211_alloc_hw(sizeof(*wl), &wl1271_ops);
1208 if (!hw) { 2037 if (!hw) {
1209 wl1271_error("could not alloc ieee80211_hw"); 2038 wl1271_error("could not alloc ieee80211_hw");
1210 return -ENOMEM; 2039 return ERR_PTR(-ENOMEM);
1211 } 2040 }
1212 2041
1213 wl = hw->priv; 2042 wl = hw->priv;
1214 memset(wl, 0, sizeof(*wl)); 2043 memset(wl, 0, sizeof(*wl));
1215 2044
2045 INIT_LIST_HEAD(&wl->list);
2046
1216 wl->hw = hw; 2047 wl->hw = hw;
1217 dev_set_drvdata(&spi->dev, wl);
1218 wl->spi = spi;
1219 2048
1220 skb_queue_head_init(&wl->tx_queue); 2049 skb_queue_head_init(&wl->tx_queue);
1221 2050
1222 INIT_WORK(&wl->filter_work, wl1271_filter_work); 2051 INIT_DELAYED_WORK(&wl->elp_work, wl1271_elp_work);
1223 wl->channel = WL1271_DEFAULT_CHANNEL; 2052 wl->channel = WL1271_DEFAULT_CHANNEL;
1224 wl->scanning = false;
1225 wl->default_key = 0; 2053 wl->default_key = 0;
1226 wl->listen_int = 1;
1227 wl->rx_counter = 0; 2054 wl->rx_counter = 0;
1228 wl->rx_config = WL1271_DEFAULT_RX_CONFIG; 2055 wl->rx_config = WL1271_DEFAULT_RX_CONFIG;
1229 wl->rx_filter = WL1271_DEFAULT_RX_FILTER; 2056 wl->rx_filter = WL1271_DEFAULT_RX_FILTER;
1230 wl->elp = false; 2057 wl->psm_entry_retry = 0;
1231 wl->psm = 0;
1232 wl->psm_requested = false;
1233 wl->tx_queue_stopped = false;
1234 wl->power_level = WL1271_DEFAULT_POWER_LEVEL; 2058 wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
1235 2059 wl->basic_rate_set = CONF_TX_RATE_MASK_BASIC;
1236 /* We use the default power on sleep time until we know which chip 2060 wl->rate_set = CONF_TX_RATE_MASK_BASIC;
1237 * we're using */ 2061 wl->sta_rate_set = 0;
1238 for (i = 0; i < FW_TX_CMPLT_BLOCK_SIZE; i++) 2062 wl->band = IEEE80211_BAND_2GHZ;
2063 wl->vif = NULL;
2064 wl->flags = 0;
2065
2066 for (i = 0; i < ACX_TX_DESCRIPTORS; i++)
1239 wl->tx_frames[i] = NULL; 2067 wl->tx_frames[i] = NULL;
1240 2068
1241 spin_lock_init(&wl->wl_lock); 2069 spin_lock_init(&wl->wl_lock);
1242 2070
1243 /*
1244 * In case our MAC address is not correctly set,
1245 * we use a random but Nokia MAC.
1246 */
1247 memcpy(wl->mac_addr, nokia_oui, 3);
1248 get_random_bytes(wl->mac_addr + 3, 3);
1249
1250 wl->state = WL1271_STATE_OFF; 2071 wl->state = WL1271_STATE_OFF;
1251 mutex_init(&wl->mutex); 2072 mutex_init(&wl->mutex);
1252 2073
1253 wl->rx_descriptor = kmalloc(sizeof(*wl->rx_descriptor), GFP_KERNEL); 2074 /* Apply default driver configuration. */
1254 if (!wl->rx_descriptor) { 2075 wl1271_conf_init(wl);
1255 wl1271_error("could not allocate memory for rx descriptor"); 2076
1256 ret = -ENOMEM; 2077 return hw;
1257 goto out_free; 2078}
2079
2080int wl1271_free_hw(struct wl1271 *wl)
2081{
2082 ieee80211_unregister_hw(wl->hw);
2083
2084 wl1271_debugfs_exit(wl);
2085
2086 kfree(wl->target_mem_map);
2087 vfree(wl->fw);
2088 wl->fw = NULL;
2089 kfree(wl->nvs);
2090 wl->nvs = NULL;
2091
2092 kfree(wl->fw_status);
2093 kfree(wl->tx_res_if);
2094
2095 ieee80211_free_hw(wl->hw);
2096
2097 return 0;
2098}
2099
2100static int __devinit wl1271_probe(struct spi_device *spi)
2101{
2102 struct wl12xx_platform_data *pdata;
2103 struct ieee80211_hw *hw;
2104 struct wl1271 *wl;
2105 int ret;
2106
2107 pdata = spi->dev.platform_data;
2108 if (!pdata) {
2109 wl1271_error("no platform data");
2110 return -ENODEV;
1258 } 2111 }
1259 2112
2113 hw = wl1271_alloc_hw();
2114 if (IS_ERR(hw))
2115 return PTR_ERR(hw);
2116
2117 wl = hw->priv;
2118
2119 dev_set_drvdata(&spi->dev, wl);
2120 wl->spi = spi;
2121
1260 /* This is the only SPI value that we need to set here, the rest 2122 /* This is the only SPI value that we need to set here, the rest
1261 * comes from the board-peripherals file */ 2123 * comes from the board-peripherals file */
1262 spi->bits_per_word = 32; 2124 spi->bits_per_word = 32;
@@ -1319,9 +2181,6 @@ static int __devinit wl1271_probe(struct spi_device *spi)
1319 free_irq(wl->irq, wl); 2181 free_irq(wl->irq, wl);
1320 2182
1321 out_free: 2183 out_free:
1322 kfree(wl->rx_descriptor);
1323 wl->rx_descriptor = NULL;
1324
1325 ieee80211_free_hw(hw); 2184 ieee80211_free_hw(hw);
1326 2185
1327 return ret; 2186 return ret;
@@ -1331,24 +2190,10 @@ static int __devexit wl1271_remove(struct spi_device *spi)
1331{ 2190{
1332 struct wl1271 *wl = dev_get_drvdata(&spi->dev); 2191 struct wl1271 *wl = dev_get_drvdata(&spi->dev);
1333 2192
1334 ieee80211_unregister_hw(wl->hw);
1335
1336 wl1271_debugfs_exit(wl);
1337 platform_device_unregister(&wl1271_device); 2193 platform_device_unregister(&wl1271_device);
1338 free_irq(wl->irq, wl); 2194 free_irq(wl->irq, wl);
1339 kfree(wl->target_mem_map);
1340 kfree(wl->fw);
1341 wl->fw = NULL;
1342 kfree(wl->nvs);
1343 wl->nvs = NULL;
1344
1345 kfree(wl->rx_descriptor);
1346 wl->rx_descriptor = NULL;
1347
1348 kfree(wl->fw_status);
1349 kfree(wl->tx_res_if);
1350 2195
1351 ieee80211_free_hw(wl->hw); 2196 wl1271_free_hw(wl);
1352 2197
1353 return 0; 2198 return 0;
1354} 2199}
@@ -1391,3 +2236,5 @@ module_exit(wl1271_exit);
1391 2236
1392MODULE_LICENSE("GPL"); 2237MODULE_LICENSE("GPL");
1393MODULE_AUTHOR("Luciano Coelho <luciano.coelho@nokia.com>"); 2238MODULE_AUTHOR("Luciano Coelho <luciano.coelho@nokia.com>");
2239MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>");
2240MODULE_FIRMWARE(WL1271_FW_NAME);
diff --git a/drivers/net/wireless/wl12xx/wl1271_ps.c b/drivers/net/wireless/wl12xx/wl1271_ps.c
index 1dc74b0c7736..e2b1ebf096e8 100644
--- a/drivers/net/wireless/wl12xx/wl1271_ps.c
+++ b/drivers/net/wireless/wl12xx/wl1271_ps.c
@@ -24,28 +24,43 @@
24#include "wl1271_reg.h" 24#include "wl1271_reg.h"
25#include "wl1271_ps.h" 25#include "wl1271_ps.h"
26#include "wl1271_spi.h" 26#include "wl1271_spi.h"
27#include "wl1271_io.h"
27 28
28#define WL1271_WAKEUP_TIMEOUT 500 29#define WL1271_WAKEUP_TIMEOUT 500
29 30
31void wl1271_elp_work(struct work_struct *work)
32{
33 struct delayed_work *dwork;
34 struct wl1271 *wl;
35
36 dwork = container_of(work, struct delayed_work, work);
37 wl = container_of(dwork, struct wl1271, elp_work);
38
39 wl1271_debug(DEBUG_PSM, "elp work");
40
41 mutex_lock(&wl->mutex);
42
43 if (test_bit(WL1271_FLAG_IN_ELP, &wl->flags) ||
44 !test_bit(WL1271_FLAG_PSM, &wl->flags))
45 goto out;
46
47 wl1271_debug(DEBUG_PSM, "chip to elp");
48 wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_SLEEP);
49 set_bit(WL1271_FLAG_IN_ELP, &wl->flags);
50
51out:
52 mutex_unlock(&wl->mutex);
53}
54
55#define ELP_ENTRY_DELAY 5
56
30/* Routines to toggle sleep mode while in ELP */ 57/* Routines to toggle sleep mode while in ELP */
31void wl1271_ps_elp_sleep(struct wl1271 *wl) 58void wl1271_ps_elp_sleep(struct wl1271 *wl)
32{ 59{
33 /* 60 if (test_bit(WL1271_FLAG_PSM, &wl->flags)) {
34 * FIXME: due to a problem in the firmware (causing a firmware 61 cancel_delayed_work(&wl->elp_work);
35 * crash), ELP entry is prevented below. Remove the "true" to 62 ieee80211_queue_delayed_work(wl->hw, &wl->elp_work,
36 * re-enable ELP entry. 63 msecs_to_jiffies(ELP_ENTRY_DELAY));
37 */
38 if (true || wl->elp || !wl->psm)
39 return;
40
41 /*
42 * Go to ELP unless there is work already pending - pending work
43 * will immediately wakeup the chipset anyway.
44 */
45 if (!work_pending(&wl->irq_work) && !work_pending(&wl->tx_work)) {
46 wl1271_debug(DEBUG_PSM, "chip to elp");
47 wl1271_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_SLEEP);
48 wl->elp = true;
49 } 64 }
50} 65}
51 66
@@ -57,7 +72,7 @@ int wl1271_ps_elp_wakeup(struct wl1271 *wl, bool chip_awake)
57 u32 start_time = jiffies; 72 u32 start_time = jiffies;
58 bool pending = false; 73 bool pending = false;
59 74
60 if (!wl->elp) 75 if (!test_bit(WL1271_FLAG_IN_ELP, &wl->flags))
61 return 0; 76 return 0;
62 77
63 wl1271_debug(DEBUG_PSM, "waking up chip from elp"); 78 wl1271_debug(DEBUG_PSM, "waking up chip from elp");
@@ -73,7 +88,7 @@ int wl1271_ps_elp_wakeup(struct wl1271 *wl, bool chip_awake)
73 wl->elp_compl = &compl; 88 wl->elp_compl = &compl;
74 spin_unlock_irqrestore(&wl->wl_lock, flags); 89 spin_unlock_irqrestore(&wl->wl_lock, flags);
75 90
76 wl1271_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_WAKE_UP); 91 wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_WAKE_UP);
77 92
78 if (!pending) { 93 if (!pending) {
79 ret = wait_for_completion_timeout( 94 ret = wait_for_completion_timeout(
@@ -88,7 +103,7 @@ int wl1271_ps_elp_wakeup(struct wl1271 *wl, bool chip_awake)
88 } 103 }
89 } 104 }
90 105
91 wl->elp = false; 106 clear_bit(WL1271_FLAG_IN_ELP, &wl->flags);
92 107
93 wl1271_debug(DEBUG_PSM, "wakeup time: %u ms", 108 wl1271_debug(DEBUG_PSM, "wakeup time: %u ms",
94 jiffies_to_msecs(jiffies - start_time)); 109 jiffies_to_msecs(jiffies - start_time));
@@ -104,22 +119,20 @@ out:
104 return 0; 119 return 0;
105} 120}
106 121
107int wl1271_ps_set_mode(struct wl1271 *wl, enum wl1271_cmd_ps_mode mode) 122int wl1271_ps_set_mode(struct wl1271 *wl, enum wl1271_cmd_ps_mode mode,
123 bool send)
108{ 124{
109 int ret; 125 int ret;
110 126
111 switch (mode) { 127 switch (mode) {
112 case STATION_POWER_SAVE_MODE: 128 case STATION_POWER_SAVE_MODE:
113 wl1271_debug(DEBUG_PSM, "entering psm"); 129 wl1271_debug(DEBUG_PSM, "entering psm");
114 ret = wl1271_cmd_ps_mode(wl, STATION_POWER_SAVE_MODE);
115 if (ret < 0)
116 return ret;
117 130
118 wl1271_ps_elp_sleep(wl); 131 ret = wl1271_cmd_ps_mode(wl, STATION_POWER_SAVE_MODE, send);
119 if (ret < 0) 132 if (ret < 0)
120 return ret; 133 return ret;
121 134
122 wl->psm = 1; 135 set_bit(WL1271_FLAG_PSM, &wl->flags);
123 break; 136 break;
124 case STATION_ACTIVE_MODE: 137 case STATION_ACTIVE_MODE:
125 default: 138 default:
@@ -128,11 +141,21 @@ int wl1271_ps_set_mode(struct wl1271 *wl, enum wl1271_cmd_ps_mode mode)
128 if (ret < 0) 141 if (ret < 0)
129 return ret; 142 return ret;
130 143
131 ret = wl1271_cmd_ps_mode(wl, STATION_ACTIVE_MODE); 144 /* disable beacon early termination */
145 ret = wl1271_acx_bet_enable(wl, false);
146 if (ret < 0)
147 return ret;
148
149 /* disable beacon filtering */
150 ret = wl1271_acx_beacon_filter_opt(wl, false);
151 if (ret < 0)
152 return ret;
153
154 ret = wl1271_cmd_ps_mode(wl, STATION_ACTIVE_MODE, send);
132 if (ret < 0) 155 if (ret < 0)
133 return ret; 156 return ret;
134 157
135 wl->psm = 0; 158 clear_bit(WL1271_FLAG_PSM, &wl->flags);
136 break; 159 break;
137 } 160 }
138 161
diff --git a/drivers/net/wireless/wl12xx/wl1271_ps.h b/drivers/net/wireless/wl12xx/wl1271_ps.h
index de2bd3c7dc9c..940276f517a4 100644
--- a/drivers/net/wireless/wl12xx/wl1271_ps.h
+++ b/drivers/net/wireless/wl12xx/wl1271_ps.h
@@ -27,9 +27,10 @@
27#include "wl1271.h" 27#include "wl1271.h"
28#include "wl1271_acx.h" 28#include "wl1271_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, enum wl1271_cmd_ps_mode mode,
31 bool send);
31void wl1271_ps_elp_sleep(struct wl1271 *wl); 32void wl1271_ps_elp_sleep(struct wl1271 *wl);
32int wl1271_ps_elp_wakeup(struct wl1271 *wl, bool chip_awake); 33int wl1271_ps_elp_wakeup(struct wl1271 *wl, bool chip_awake);
33 34void wl1271_elp_work(struct work_struct *work);
34 35
35#endif /* __WL1271_PS_H__ */ 36#endif /* __WL1271_PS_H__ */
diff --git a/drivers/net/wireless/wl12xx/wl1271_reg.h b/drivers/net/wireless/wl12xx/wl1271_reg.h
index f8ed4a4fc691..990960771528 100644
--- a/drivers/net/wireless/wl12xx/wl1271_reg.h
+++ b/drivers/net/wireless/wl12xx/wl1271_reg.h
@@ -34,7 +34,7 @@
34#define REGISTERS_WORK_SIZE 0x0000b000 34#define REGISTERS_WORK_SIZE 0x0000b000
35 35
36#define HW_ACCESS_ELP_CTRL_REG_ADDR 0x1FFFC 36#define HW_ACCESS_ELP_CTRL_REG_ADDR 0x1FFFC
37#define STATUS_MEM_ADDRESS 0x40400 37#define FW_STATUS_ADDR (0x14FC0 + 0xA000)
38 38
39/* ELP register commands */ 39/* ELP register commands */
40#define ELPCTRL_WAKE_UP 0x1 40#define ELPCTRL_WAKE_UP 0x1
@@ -62,73 +62,10 @@
62#define WL1271_SLV_REG_DATA (REGISTERS_BASE + 0x0008) 62#define WL1271_SLV_REG_DATA (REGISTERS_BASE + 0x0008)
63#define WL1271_SLV_REG_ADATA (REGISTERS_BASE + 0x000c) 63#define WL1271_SLV_REG_ADATA (REGISTERS_BASE + 0x000c)
64#define WL1271_SLV_MEM_DATA (REGISTERS_BASE + 0x0018) 64#define WL1271_SLV_MEM_DATA (REGISTERS_BASE + 0x0018)
65/*
66 * Interrupt registers.
67 * 64 bit interrupt sources registers ws ced.
68 * sme interupts were removed and new ones were added.
69 * Order was changed.
70 */
71#define FIQ_MASK (REGISTERS_BASE + 0x0400)
72#define FIQ_MASK_L (REGISTERS_BASE + 0x0400)
73#define FIQ_MASK_H (REGISTERS_BASE + 0x0404)
74#define FIQ_MASK_SET (REGISTERS_BASE + 0x0408)
75#define FIQ_MASK_SET_L (REGISTERS_BASE + 0x0408)
76#define FIQ_MASK_SET_H (REGISTERS_BASE + 0x040C)
77#define FIQ_MASK_CLR (REGISTERS_BASE + 0x0410)
78#define FIQ_MASK_CLR_L (REGISTERS_BASE + 0x0410)
79#define FIQ_MASK_CLR_H (REGISTERS_BASE + 0x0414)
80#define IRQ_MASK (REGISTERS_BASE + 0x0418)
81#define IRQ_MASK_L (REGISTERS_BASE + 0x0418)
82#define IRQ_MASK_H (REGISTERS_BASE + 0x041C)
83#define IRQ_MASK_SET (REGISTERS_BASE + 0x0420)
84#define IRQ_MASK_SET_L (REGISTERS_BASE + 0x0420)
85#define IRQ_MASK_SET_H (REGISTERS_BASE + 0x0424)
86#define IRQ_MASK_CLR (REGISTERS_BASE + 0x0428)
87#define IRQ_MASK_CLR_L (REGISTERS_BASE + 0x0428)
88#define IRQ_MASK_CLR_H (REGISTERS_BASE + 0x042C)
89#define ECPU_MASK (REGISTERS_BASE + 0x0448)
90#define FIQ_STS_L (REGISTERS_BASE + 0x044C)
91#define FIQ_STS_H (REGISTERS_BASE + 0x0450)
92#define IRQ_STS_L (REGISTERS_BASE + 0x0454)
93#define IRQ_STS_H (REGISTERS_BASE + 0x0458)
94#define INT_STS_ND (REGISTERS_BASE + 0x0464)
95#define INT_STS_RAW_L (REGISTERS_BASE + 0x0464)
96#define INT_STS_RAW_H (REGISTERS_BASE + 0x0468)
97#define INT_STS_CLR (REGISTERS_BASE + 0x04B4)
98#define INT_STS_CLR_L (REGISTERS_BASE + 0x04B4)
99#define INT_STS_CLR_H (REGISTERS_BASE + 0x04B8)
100#define INT_ACK (REGISTERS_BASE + 0x046C)
101#define INT_ACK_L (REGISTERS_BASE + 0x046C)
102#define INT_ACK_H (REGISTERS_BASE + 0x0470)
103#define INT_TRIG (REGISTERS_BASE + 0x0474)
104#define INT_TRIG_L (REGISTERS_BASE + 0x0474)
105#define INT_TRIG_H (REGISTERS_BASE + 0x0478)
106#define HOST_STS_L (REGISTERS_BASE + 0x045C)
107#define HOST_STS_H (REGISTERS_BASE + 0x0460)
108#define HOST_MASK (REGISTERS_BASE + 0x0430)
109#define HOST_MASK_L (REGISTERS_BASE + 0x0430)
110#define HOST_MASK_H (REGISTERS_BASE + 0x0434)
111#define HOST_MASK_SET (REGISTERS_BASE + 0x0438)
112#define HOST_MASK_SET_L (REGISTERS_BASE + 0x0438)
113#define HOST_MASK_SET_H (REGISTERS_BASE + 0x043C)
114#define HOST_MASK_CLR (REGISTERS_BASE + 0x0440)
115#define HOST_MASK_CLR_L (REGISTERS_BASE + 0x0440)
116#define HOST_MASK_CLR_H (REGISTERS_BASE + 0x0444)
117 65
118#define ACX_REG_INTERRUPT_TRIG (REGISTERS_BASE + 0x0474) 66#define ACX_REG_INTERRUPT_TRIG (REGISTERS_BASE + 0x0474)
119#define ACX_REG_INTERRUPT_TRIG_H (REGISTERS_BASE + 0x0478) 67#define ACX_REG_INTERRUPT_TRIG_H (REGISTERS_BASE + 0x0478)
120 68
121/* Host Interrupts*/
122#define HINT_MASK (REGISTERS_BASE + 0x0494)
123#define HINT_MASK_SET (REGISTERS_BASE + 0x0498)
124#define HINT_MASK_CLR (REGISTERS_BASE + 0x049C)
125#define HINT_STS_ND_MASKED (REGISTERS_BASE + 0x04A0)
126/*1150 spec calls this HINT_STS_RAW*/
127#define HINT_STS_ND (REGISTERS_BASE + 0x04B0)
128#define HINT_STS_CLR (REGISTERS_BASE + 0x04A4)
129#define HINT_ACK (REGISTERS_BASE + 0x04A8)
130#define HINT_TRIG (REGISTERS_BASE + 0x04AC)
131
132/*============================================= 69/*=============================================
133 Host Interrupt Mask Register - 32bit (RW) 70 Host Interrupt Mask Register - 32bit (RW)
134 ------------------------------------------ 71 ------------------------------------------
@@ -213,7 +150,6 @@
213==============================================*/ 150==============================================*/
214#define ACX_REG_INTERRUPT_ACK (REGISTERS_BASE + 0x04F0) 151#define ACX_REG_INTERRUPT_ACK (REGISTERS_BASE + 0x04F0)
215 152
216#define RX_DRIVER_DUMMY_WRITE_ADDRESS (REGISTERS_BASE + 0x0534)
217#define RX_DRIVER_COUNTER_ADDRESS (REGISTERS_BASE + 0x0538) 153#define RX_DRIVER_COUNTER_ADDRESS (REGISTERS_BASE + 0x0538)
218 154
219/* Device Configuration registers*/ 155/* Device Configuration registers*/
@@ -434,16 +370,6 @@
434 370
435 371
436/*=============================================== 372/*===============================================
437 Phy regs
438 ===============================================*/
439#define ACX_PHY_ADDR_REG SBB_ADDR
440#define ACX_PHY_DATA_REG SBB_DATA
441#define ACX_PHY_CTRL_REG SBB_CTL
442#define ACX_PHY_REG_WR_MASK 0x00000001ul
443#define ACX_PHY_REG_RD_MASK 0x00000002ul
444
445
446/*===============================================
447 EEPROM Read/Write Request 32bit RW 373 EEPROM Read/Write Request 32bit RW
448 ------------------------------------------ 374 ------------------------------------------
449 1 EE_READ - EEPROM Read Request 1 - Setting this bit 375 1 EE_READ - EEPROM Read Request 1 - Setting this bit
@@ -512,28 +438,6 @@
512#define ACX_CONT_WIND_MIN_MASK 0x0000007f 438#define ACX_CONT_WIND_MIN_MASK 0x0000007f
513#define ACX_CONT_WIND_MAX 0x03ff0000 439#define ACX_CONT_WIND_MAX 0x03ff0000
514 440
515/*
516 * Indirect slave register/memory registers
517 * ----------------------------------------
518 */
519#define HW_SLAVE_REG_ADDR_REG 0x00000004
520#define HW_SLAVE_REG_DATA_REG 0x00000008
521#define HW_SLAVE_REG_CTRL_REG 0x0000000c
522
523#define SLAVE_AUTO_INC 0x00010000
524#define SLAVE_NO_AUTO_INC 0x00000000
525#define SLAVE_HOST_LITTLE_ENDIAN 0x00000000
526
527#define HW_SLAVE_MEM_ADDR_REG SLV_MEM_ADDR
528#define HW_SLAVE_MEM_DATA_REG SLV_MEM_DATA
529#define HW_SLAVE_MEM_CTRL_REG SLV_MEM_CTL
530#define HW_SLAVE_MEM_ENDIAN_REG SLV_END_CTL
531
532#define HW_FUNC_EVENT_INT_EN 0x8000
533#define HW_FUNC_EVENT_MASK_REG 0x00000034
534
535#define ACX_MAC_TIMESTAMP_REG (MAC_TIMESTAMP)
536
537/*=============================================== 441/*===============================================
538 HI_CFG Interface Configuration Register Values 442 HI_CFG Interface Configuration Register Values
539 ------------------------------------------ 443 ------------------------------------------
@@ -614,50 +518,6 @@ enum {
614 MAX_RADIO_BANDS = 0xFF 518 MAX_RADIO_BANDS = 0xFF
615}; 519};
616 520
617enum {
618 NO_RATE = 0,
619 RATE_1MBPS = 0x0A,
620 RATE_2MBPS = 0x14,
621 RATE_5_5MBPS = 0x37,
622 RATE_6MBPS = 0x0B,
623 RATE_9MBPS = 0x0F,
624 RATE_11MBPS = 0x6E,
625 RATE_12MBPS = 0x0A,
626 RATE_18MBPS = 0x0E,
627 RATE_22MBPS = 0xDC,
628 RATE_24MBPS = 0x09,
629 RATE_36MBPS = 0x0D,
630 RATE_48MBPS = 0x08,
631 RATE_54MBPS = 0x0C
632};
633
634enum {
635 RATE_INDEX_1MBPS = 0,
636 RATE_INDEX_2MBPS = 1,
637 RATE_INDEX_5_5MBPS = 2,
638 RATE_INDEX_6MBPS = 3,
639 RATE_INDEX_9MBPS = 4,
640 RATE_INDEX_11MBPS = 5,
641 RATE_INDEX_12MBPS = 6,
642 RATE_INDEX_18MBPS = 7,
643 RATE_INDEX_22MBPS = 8,
644 RATE_INDEX_24MBPS = 9,
645 RATE_INDEX_36MBPS = 10,
646 RATE_INDEX_48MBPS = 11,
647 RATE_INDEX_54MBPS = 12,
648 RATE_INDEX_MAX = RATE_INDEX_54MBPS,
649 MAX_RATE_INDEX,
650 INVALID_RATE_INDEX = MAX_RATE_INDEX,
651 RATE_INDEX_ENUM_MAX_SIZE = 0x7FFFFFFF
652};
653
654enum {
655 RATE_MASK_1MBPS = 0x1,
656 RATE_MASK_2MBPS = 0x2,
657 RATE_MASK_5_5MBPS = 0x4,
658 RATE_MASK_11MBPS = 0x20,
659};
660
661#define SHORT_PREAMBLE_BIT BIT(0) /* CCK or Barker depending on the rate */ 521#define SHORT_PREAMBLE_BIT BIT(0) /* CCK or Barker depending on the rate */
662#define OFDM_RATE_BIT BIT(6) 522#define OFDM_RATE_BIT BIT(6)
663#define PBCC_RATE_BIT BIT(7) 523#define PBCC_RATE_BIT BIT(7)
@@ -692,10 +552,6 @@ b12-b0 - Supported Rate indicator bits as defined below.
692******************************************************************************/ 552******************************************************************************/
693 553
694 554
695#define TNETW1251_CHIP_ID_PG1_0 0x07010101
696#define TNETW1251_CHIP_ID_PG1_1 0x07020101
697#define TNETW1251_CHIP_ID_PG1_2 0x07030101
698
699/************************************************************************* 555/*************************************************************************
700 556
701 Interrupt Trigger Register (Host -> WiLink) 557 Interrupt Trigger Register (Host -> WiLink)
diff --git a/drivers/net/wireless/wl12xx/wl1271_rx.c b/drivers/net/wireless/wl12xx/wl1271_rx.c
index ad8b6904c5eb..c723d9c7e131 100644
--- a/drivers/net/wireless/wl12xx/wl1271_rx.c
+++ b/drivers/net/wireless/wl12xx/wl1271_rx.c
@@ -21,23 +21,27 @@
21 * 21 *
22 */ 22 */
23 23
24#include <linux/gfp.h>
25
24#include "wl1271.h" 26#include "wl1271.h"
25#include "wl1271_acx.h" 27#include "wl1271_acx.h"
26#include "wl1271_reg.h" 28#include "wl1271_reg.h"
27#include "wl1271_rx.h" 29#include "wl1271_rx.h"
28#include "wl1271_spi.h" 30#include "wl1271_spi.h"
31#include "wl1271_io.h"
29 32
30static u8 wl1271_rx_get_mem_block(struct wl1271_fw_status *status, 33static u8 wl1271_rx_get_mem_block(struct wl1271_fw_status *status,
31 u32 drv_rx_counter) 34 u32 drv_rx_counter)
32{ 35{
33 return status->rx_pkt_descs[drv_rx_counter] & RX_MEM_BLOCK_MASK; 36 return le32_to_cpu(status->rx_pkt_descs[drv_rx_counter]) &
37 RX_MEM_BLOCK_MASK;
34} 38}
35 39
36static u32 wl1271_rx_get_buf_size(struct wl1271_fw_status *status, 40static u32 wl1271_rx_get_buf_size(struct wl1271_fw_status *status,
37 u32 drv_rx_counter) 41 u32 drv_rx_counter)
38{ 42{
39 return (status->rx_pkt_descs[drv_rx_counter] & RX_BUF_SIZE_MASK) >> 43 return (le32_to_cpu(status->rx_pkt_descs[drv_rx_counter]) &
40 RX_BUF_SIZE_SHIFT_DIV; 44 RX_BUF_SIZE_MASK) >> RX_BUF_SIZE_SHIFT_DIV;
41} 45}
42 46
43/* The values of this table must match the wl1271_rates[] array */ 47/* The values of this table must match the wl1271_rates[] array */
@@ -70,6 +74,36 @@ static u8 wl1271_rx_rate_to_idx[] = {
70 0 /* WL1271_RATE_1 */ 74 0 /* WL1271_RATE_1 */
71}; 75};
72 76
77/* The values of this table must match the wl1271_rates[] array */
78static u8 wl1271_5_ghz_rx_rate_to_idx[] = {
79 /* MCS rates are used only with 11n */
80 WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS7 */
81 WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS6 */
82 WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS5 */
83 WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS4 */
84 WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS3 */
85 WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS2 */
86 WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS1 */
87 WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS0 */
88
89 7, /* WL1271_RATE_54 */
90 6, /* WL1271_RATE_48 */
91 5, /* WL1271_RATE_36 */
92 4, /* WL1271_RATE_24 */
93
94 /* TI-specific rate */
95 WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_22 */
96
97 3, /* WL1271_RATE_18 */
98 2, /* WL1271_RATE_12 */
99 WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_11 */
100 1, /* WL1271_RATE_9 */
101 0, /* WL1271_RATE_6 */
102 WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_5_5 */
103 WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_2 */
104 WL1271_RX_RATE_UNSUPPORTED /* WL1271_RATE_1 */
105};
106
73static void wl1271_rx_status(struct wl1271 *wl, 107static void wl1271_rx_status(struct wl1271 *wl,
74 struct wl1271_rx_descriptor *desc, 108 struct wl1271_rx_descriptor *desc,
75 struct ieee80211_rx_status *status, 109 struct ieee80211_rx_status *status,
@@ -77,12 +111,21 @@ static void wl1271_rx_status(struct wl1271 *wl,
77{ 111{
78 memset(status, 0, sizeof(struct ieee80211_rx_status)); 112 memset(status, 0, sizeof(struct ieee80211_rx_status));
79 113
80 if ((desc->flags & WL1271_RX_DESC_BAND_MASK) == WL1271_RX_DESC_BAND_BG) 114 if ((desc->flags & WL1271_RX_DESC_BAND_MASK) ==
115 WL1271_RX_DESC_BAND_BG) {
81 status->band = IEEE80211_BAND_2GHZ; 116 status->band = IEEE80211_BAND_2GHZ;
82 else 117 status->rate_idx = wl1271_rx_rate_to_idx[desc->rate];
118 } else if ((desc->flags & WL1271_RX_DESC_BAND_MASK) ==
119 WL1271_RX_DESC_BAND_A) {
120 status->band = IEEE80211_BAND_5GHZ;
121 status->rate_idx = wl1271_5_ghz_rx_rate_to_idx[desc->rate];
122 } else
83 wl1271_warning("unsupported band 0x%x", 123 wl1271_warning("unsupported band 0x%x",
84 desc->flags & WL1271_RX_DESC_BAND_MASK); 124 desc->flags & WL1271_RX_DESC_BAND_MASK);
85 125
126 if (unlikely(status->rate_idx == WL1271_RX_RATE_UNSUPPORTED))
127 wl1271_warning("unsupported rate");
128
86 /* 129 /*
87 * FIXME: Add mactime handling. For IBSS (ad-hoc) we need to get the 130 * FIXME: Add mactime handling. For IBSS (ad-hoc) we need to get the
88 * timestamp from the beacon (acx_tsf_info). In BSS mode (infra) we 131 * timestamp from the beacon (acx_tsf_info). In BSS mode (infra) we
@@ -91,12 +134,6 @@ static void wl1271_rx_status(struct wl1271 *wl,
91 */ 134 */
92 status->signal = desc->rssi; 135 status->signal = desc->rssi;
93 136
94 /* FIXME: Should this be optimized? */
95 status->qual = (desc->rssi - WL1271_RX_MIN_RSSI) * 100 /
96 (WL1271_RX_MAX_RSSI - WL1271_RX_MIN_RSSI);
97 status->qual = min(status->qual, 100);
98 status->qual = max(status->qual, 0);
99
100 /* 137 /*
101 * FIXME: In wl1251, the SNR should be divided by two. In wl1271 we 138 * FIXME: In wl1251, the SNR should be divided by two. In wl1271 we
102 * need to divide by two for now, but TI has been discussing about 139 * need to divide by two for now, but TI has been discussing about
@@ -109,17 +146,11 @@ static void wl1271_rx_status(struct wl1271 *wl,
109 if (desc->flags & WL1271_RX_DESC_ENCRYPT_MASK) { 146 if (desc->flags & WL1271_RX_DESC_ENCRYPT_MASK) {
110 status->flag |= RX_FLAG_IV_STRIPPED | RX_FLAG_MMIC_STRIPPED; 147 status->flag |= RX_FLAG_IV_STRIPPED | RX_FLAG_MMIC_STRIPPED;
111 148
112 if (likely(!(desc->flags & WL1271_RX_DESC_DECRYPT_FAIL))) 149 if (likely(!(desc->status & WL1271_RX_DESC_DECRYPT_FAIL)))
113 status->flag |= RX_FLAG_DECRYPTED; 150 status->flag |= RX_FLAG_DECRYPTED;
114 151 if (unlikely(desc->status & WL1271_RX_DESC_MIC_FAIL))
115 if (unlikely(desc->flags & WL1271_RX_DESC_MIC_FAIL))
116 status->flag |= RX_FLAG_MMIC_ERROR; 152 status->flag |= RX_FLAG_MMIC_ERROR;
117 } 153 }
118
119 status->rate_idx = wl1271_rx_rate_to_idx[desc->rate];
120
121 if (status->rate_idx == WL1271_RX_RATE_UNSUPPORTED)
122 wl1271_warning("unsupported rate");
123} 154}
124 155
125static void wl1271_rx_handle_data(struct wl1271 *wl, u32 length) 156static void wl1271_rx_handle_data(struct wl1271 *wl, u32 length)
@@ -131,14 +162,14 @@ static void wl1271_rx_handle_data(struct wl1271 *wl, u32 length)
131 u8 *buf; 162 u8 *buf;
132 u8 beacon = 0; 163 u8 beacon = 0;
133 164
134 skb = dev_alloc_skb(length); 165 skb = __dev_alloc_skb(length, GFP_KERNEL);
135 if (!skb) { 166 if (!skb) {
136 wl1271_error("Couldn't allocate RX frame"); 167 wl1271_error("Couldn't allocate RX frame");
137 return; 168 return;
138 } 169 }
139 170
140 buf = skb_put(skb, length); 171 buf = skb_put(skb, length);
141 wl1271_spi_reg_read(wl, WL1271_SLV_MEM_DATA, buf, length, true); 172 wl1271_read(wl, WL1271_SLV_MEM_DATA, buf, length, true);
142 173
143 /* the data read starts with the descriptor */ 174 /* the data read starts with the descriptor */
144 desc = (struct wl1271_rx_descriptor *) buf; 175 desc = (struct wl1271_rx_descriptor *) buf;
@@ -156,7 +187,7 @@ static void wl1271_rx_handle_data(struct wl1271 *wl, u32 length)
156 beacon ? "beacon" : ""); 187 beacon ? "beacon" : "");
157 188
158 memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status)); 189 memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status));
159 ieee80211_rx(wl->hw, skb); 190 ieee80211_rx_ni(wl->hw, skb);
160} 191}
161 192
162void wl1271_rx(struct wl1271 *wl, struct wl1271_fw_status *status) 193void wl1271_rx(struct wl1271 *wl, struct wl1271_fw_status *status)
@@ -176,25 +207,19 @@ void wl1271_rx(struct wl1271 *wl, struct wl1271_fw_status *status)
176 break; 207 break;
177 } 208 }
178 209
179 wl->rx_mem_pool_addr.addr = 210 wl->rx_mem_pool_addr.addr = (mem_block << 8) +
180 (mem_block << 8) + wl_mem_map->packet_memory_pool_start; 211 le32_to_cpu(wl_mem_map->packet_memory_pool_start);
181 wl->rx_mem_pool_addr.addr_extra = 212 wl->rx_mem_pool_addr.addr_extra =
182 wl->rx_mem_pool_addr.addr + 4; 213 wl->rx_mem_pool_addr.addr + 4;
183 214
184 /* Choose the block we want to read */ 215 /* Choose the block we want to read */
185 wl1271_spi_reg_write(wl, WL1271_SLV_REG_DATA, 216 wl1271_write(wl, WL1271_SLV_REG_DATA, &wl->rx_mem_pool_addr,
186 &wl->rx_mem_pool_addr, 217 sizeof(wl->rx_mem_pool_addr), false);
187 sizeof(wl->rx_mem_pool_addr), false);
188 218
189 wl1271_rx_handle_data(wl, buf_size); 219 wl1271_rx_handle_data(wl, buf_size);
190 220
191 wl->rx_counter++; 221 wl->rx_counter++;
192 drv_rx_counter = wl->rx_counter & NUM_RX_PKT_DESC_MOD_MASK; 222 drv_rx_counter = wl->rx_counter & NUM_RX_PKT_DESC_MOD_MASK;
223 wl1271_write32(wl, RX_DRIVER_COUNTER_ADDRESS, wl->rx_counter);
193 } 224 }
194
195 wl1271_reg_write32(wl, RX_DRIVER_COUNTER_ADDRESS, wl->rx_counter);
196
197 /* This is a workaround for some problems in the chip */
198 wl1271_reg_write32(wl, RX_DRIVER_DUMMY_WRITE_ADDRESS, 0x1);
199
200} 225}
diff --git a/drivers/net/wireless/wl12xx/wl1271_rx.h b/drivers/net/wireless/wl12xx/wl1271_rx.h
index d1ca60e43a25..1ae6d1783ed4 100644
--- a/drivers/net/wireless/wl12xx/wl1271_rx.h
+++ b/drivers/net/wireless/wl12xx/wl1271_rx.h
@@ -102,14 +102,14 @@
102#define RX_BUF_SIZE_SHIFT_DIV 6 102#define RX_BUF_SIZE_SHIFT_DIV 6
103 103
104struct wl1271_rx_descriptor { 104struct wl1271_rx_descriptor {
105 u16 length; 105 __le16 length;
106 u8 status; 106 u8 status;
107 u8 flags; 107 u8 flags;
108 u8 rate; 108 u8 rate;
109 u8 channel; 109 u8 channel;
110 s8 rssi; 110 s8 rssi;
111 u8 snr; 111 u8 snr;
112 u32 timestamp; 112 __le32 timestamp;
113 u8 packet_class; 113 u8 packet_class;
114 u8 process_id; 114 u8 process_id;
115 u8 pad_len; 115 u8 pad_len;
diff --git a/drivers/net/wireless/wl12xx/wl1271_spi.c b/drivers/net/wireless/wl12xx/wl1271_spi.c
index 4a12880c16a8..053c84aceb49 100644
--- a/drivers/net/wireless/wl12xx/wl1271_spi.c
+++ b/drivers/net/wireless/wl12xx/wl1271_spi.c
@@ -25,21 +25,12 @@
25#include <linux/platform_device.h> 25#include <linux/platform_device.h>
26#include <linux/crc7.h> 26#include <linux/crc7.h>
27#include <linux/spi/spi.h> 27#include <linux/spi/spi.h>
28#include <linux/slab.h>
28 29
29#include "wl1271.h" 30#include "wl1271.h"
30#include "wl12xx_80211.h" 31#include "wl12xx_80211.h"
31#include "wl1271_spi.h" 32#include "wl1271_spi.h"
32 33
33static int wl1271_translate_reg_addr(struct wl1271 *wl, int addr)
34{
35 return addr - wl->physical_reg_addr + wl->virtual_reg_addr;
36}
37
38static int wl1271_translate_mem_addr(struct wl1271 *wl, int addr)
39{
40 return addr - wl->physical_mem_addr + wl->virtual_mem_addr;
41}
42
43 34
44void wl1271_spi_reset(struct wl1271 *wl) 35void wl1271_spi_reset(struct wl1271 *wl)
45{ 36{
@@ -121,135 +112,78 @@ void wl1271_spi_init(struct wl1271 *wl)
121 wl1271_dump(DEBUG_SPI, "spi init -> ", cmd, WSPI_INIT_CMD_LEN); 112 wl1271_dump(DEBUG_SPI, "spi init -> ", cmd, WSPI_INIT_CMD_LEN);
122} 113}
123 114
124/* Set the SPI partitions to access the chip addresses 115#define WL1271_BUSY_WORD_TIMEOUT 1000
125 * 116
126 * There are two VIRTUAL (SPI) partitions (the memory partition and the 117/* FIXME: Check busy words, removed due to SPI bug */
127 * registers partition), which are mapped to two different areas of the 118#if 0
128 * PHYSICAL (hardware) memory. This function also makes other checks to 119static void wl1271_spi_read_busy(struct wl1271 *wl, void *buf, size_t len)
129 * ensure that the partitions are not overlapping. In the diagram below, the
130 * memory partition comes before the register partition, but the opposite is
131 * also supported.
132 *
133 * PHYSICAL address
134 * space
135 *
136 * | |
137 * ...+----+--> mem_start
138 * VIRTUAL address ... | |
139 * space ... | | [PART_0]
140 * ... | |
141 * 0x00000000 <--+----+... ...+----+--> mem_start + mem_size
142 * | | ... | |
143 * |MEM | ... | |
144 * | | ... | |
145 * part_size <--+----+... | | {unused area)
146 * | | ... | |
147 * |REG | ... | |
148 * part_size | | ... | |
149 * + <--+----+... ...+----+--> reg_start
150 * reg_size ... | |
151 * ... | | [PART_1]
152 * ... | |
153 * ...+----+--> reg_start + reg_size
154 * | |
155 *
156 */
157int wl1271_set_partition(struct wl1271 *wl,
158 u32 mem_start, u32 mem_size,
159 u32 reg_start, u32 reg_size)
160{ 120{
161 struct wl1271_partition *partition; 121 struct spi_transfer t[1];
162 struct spi_transfer t;
163 struct spi_message m; 122 struct spi_message m;
164 size_t len, cmd_len; 123 u32 *busy_buf;
165 u32 *cmd; 124 int num_busy_bytes = 0;
166 int addr;
167
168 cmd_len = sizeof(u32) + 2 * sizeof(struct wl1271_partition);
169 cmd = kzalloc(cmd_len, GFP_KERNEL);
170 if (!cmd)
171 return -ENOMEM;
172
173 spi_message_init(&m);
174 memset(&t, 0, sizeof(t));
175 125
176 partition = (struct wl1271_partition *) (cmd + 1); 126 wl1271_info("spi read BUSY!");
177 addr = HW_ACCESS_PART0_SIZE_ADDR;
178 len = 2 * sizeof(struct wl1271_partition);
179 127
180 *cmd |= WSPI_CMD_WRITE; 128 /*
181 *cmd |= (len << WSPI_CMD_BYTE_LENGTH_OFFSET) & WSPI_CMD_BYTE_LENGTH; 129 * Look for the non-busy word in the read buffer, and if found,
182 *cmd |= addr & WSPI_CMD_BYTE_ADDR; 130 * read in the remaining data into the buffer.
183 131 */
184 wl1271_debug(DEBUG_SPI, "mem_start %08X mem_size %08X", 132 busy_buf = (u32 *)buf;
185 mem_start, mem_size); 133 for (; (u32)busy_buf < (u32)buf + len; busy_buf++) {
186 wl1271_debug(DEBUG_SPI, "reg_start %08X reg_size %08X", 134 num_busy_bytes += sizeof(u32);
187 reg_start, reg_size); 135 if (*busy_buf & 0x1) {
188 136 spi_message_init(&m);
189 /* Make sure that the two partitions together don't exceed the 137 memset(t, 0, sizeof(t));
190 * address range */ 138 memmove(buf, busy_buf, len - num_busy_bytes);
191 if ((mem_size + reg_size) > HW_ACCESS_MEMORY_MAX_RANGE) { 139 t[0].rx_buf = buf + (len - num_busy_bytes);
192 wl1271_debug(DEBUG_SPI, "Total size exceeds maximum virtual" 140 t[0].len = num_busy_bytes;
193 " address range. Truncating partition[0]."); 141 spi_message_add_tail(&t[0], &m);
194 mem_size = HW_ACCESS_MEMORY_MAX_RANGE - reg_size; 142 spi_sync(wl->spi, &m);
195 wl1271_debug(DEBUG_SPI, "mem_start %08X mem_size %08X", 143 return;
196 mem_start, mem_size); 144 }
197 wl1271_debug(DEBUG_SPI, "reg_start %08X reg_size %08X",
198 reg_start, reg_size);
199 }
200
201 if ((mem_start < reg_start) &&
202 ((mem_start + mem_size) > reg_start)) {
203 /* Guarantee that the memory partition doesn't overlap the
204 * registers partition */
205 wl1271_debug(DEBUG_SPI, "End of partition[0] is "
206 "overlapping partition[1]. Adjusted.");
207 mem_size = reg_start - mem_start;
208 wl1271_debug(DEBUG_SPI, "mem_start %08X mem_size %08X",
209 mem_start, mem_size);
210 wl1271_debug(DEBUG_SPI, "reg_start %08X reg_size %08X",
211 reg_start, reg_size);
212 } else if ((reg_start < mem_start) &&
213 ((reg_start + reg_size) > mem_start)) {
214 /* Guarantee that the register partition doesn't overlap the
215 * memory partition */
216 wl1271_debug(DEBUG_SPI, "End of partition[1] is"
217 " overlapping partition[0]. Adjusted.");
218 reg_size = mem_start - reg_start;
219 wl1271_debug(DEBUG_SPI, "mem_start %08X mem_size %08X",
220 mem_start, mem_size);
221 wl1271_debug(DEBUG_SPI, "reg_start %08X reg_size %08X",
222 reg_start, reg_size);
223 } 145 }
224 146
225 partition[0].start = mem_start; 147 /*
226 partition[0].size = mem_size; 148 * Read further busy words from SPI until a non-busy word is
227 partition[1].start = reg_start; 149 * encountered, then read the data itself into the buffer.
228 partition[1].size = reg_size; 150 */
229 151 wl1271_info("spi read BUSY-polling needed!");
230 wl->physical_mem_addr = mem_start;
231 wl->physical_reg_addr = reg_start;
232
233 wl->virtual_mem_addr = 0;
234 wl->virtual_reg_addr = mem_size;
235
236 t.tx_buf = cmd;
237 t.len = cmd_len;
238 spi_message_add_tail(&t, &m);
239
240 spi_sync(wl->spi, &m);
241 152
242 kfree(cmd); 153 num_busy_bytes = WL1271_BUSY_WORD_TIMEOUT;
154 busy_buf = wl->buffer_busyword;
155 while (num_busy_bytes) {
156 num_busy_bytes--;
157 spi_message_init(&m);
158 memset(t, 0, sizeof(t));
159 t[0].rx_buf = busy_buf;
160 t[0].len = sizeof(u32);
161 spi_message_add_tail(&t[0], &m);
162 spi_sync(wl->spi, &m);
163
164 if (*busy_buf & 0x1) {
165 spi_message_init(&m);
166 memset(t, 0, sizeof(t));
167 t[0].rx_buf = buf;
168 t[0].len = len;
169 spi_message_add_tail(&t[0], &m);
170 spi_sync(wl->spi, &m);
171 return;
172 }
173 }
243 174
244 return 0; 175 /* The SPI bus is unresponsive, the read failed. */
176 memset(buf, 0, len);
177 wl1271_error("SPI read busy-word timeout!\n");
245} 178}
179#endif
246 180
247void wl1271_spi_read(struct wl1271 *wl, int addr, void *buf, 181void wl1271_spi_raw_read(struct wl1271 *wl, int addr, void *buf,
248 size_t len, bool fixed) 182 size_t len, bool fixed)
249{ 183{
250 struct spi_transfer t[3]; 184 struct spi_transfer t[3];
251 struct spi_message m; 185 struct spi_message m;
252 u8 *busy_buf; 186 u32 *busy_buf;
253 u32 *cmd; 187 u32 *cmd;
254 188
255 cmd = &wl->buffer_cmd; 189 cmd = &wl->buffer_cmd;
@@ -281,14 +215,16 @@ void wl1271_spi_read(struct wl1271 *wl, int addr, void *buf,
281 215
282 spi_sync(wl->spi, &m); 216 spi_sync(wl->spi, &m);
283 217
284 /* FIXME: check busy words */ 218 /* FIXME: Check busy words, removed due to SPI bug */
219 /* if (!(busy_buf[WL1271_BUSY_WORD_CNT - 1] & 0x1))
220 wl1271_spi_read_busy(wl, buf, len); */
285 221
286 wl1271_dump(DEBUG_SPI, "spi_read cmd -> ", cmd, sizeof(*cmd)); 222 wl1271_dump(DEBUG_SPI, "spi_read cmd -> ", cmd, sizeof(*cmd));
287 wl1271_dump(DEBUG_SPI, "spi_read buf <- ", buf, len); 223 wl1271_dump(DEBUG_SPI, "spi_read buf <- ", buf, len);
288} 224}
289 225
290void wl1271_spi_write(struct wl1271 *wl, int addr, void *buf, 226void wl1271_spi_raw_write(struct wl1271 *wl, int addr, void *buf,
291 size_t len, bool fixed) 227 size_t len, bool fixed)
292{ 228{
293 struct spi_transfer t[2]; 229 struct spi_transfer t[2];
294 struct spi_message m; 230 struct spi_message m;
@@ -320,63 +256,3 @@ void wl1271_spi_write(struct wl1271 *wl, int addr, void *buf,
320 wl1271_dump(DEBUG_SPI, "spi_write cmd -> ", cmd, sizeof(*cmd)); 256 wl1271_dump(DEBUG_SPI, "spi_write cmd -> ", cmd, sizeof(*cmd));
321 wl1271_dump(DEBUG_SPI, "spi_write buf -> ", buf, len); 257 wl1271_dump(DEBUG_SPI, "spi_write buf -> ", buf, len);
322} 258}
323
324void wl1271_spi_mem_read(struct wl1271 *wl, int addr, void *buf,
325 size_t len)
326{
327 int physical;
328
329 physical = wl1271_translate_mem_addr(wl, addr);
330
331 wl1271_spi_read(wl, physical, buf, len, false);
332}
333
334void wl1271_spi_mem_write(struct wl1271 *wl, int addr, void *buf,
335 size_t len)
336{
337 int physical;
338
339 physical = wl1271_translate_mem_addr(wl, addr);
340
341 wl1271_spi_write(wl, physical, buf, len, false);
342}
343
344void wl1271_spi_reg_read(struct wl1271 *wl, int addr, void *buf, size_t len,
345 bool fixed)
346{
347 int physical;
348
349 physical = wl1271_translate_reg_addr(wl, addr);
350
351 wl1271_spi_read(wl, physical, buf, len, fixed);
352}
353
354void wl1271_spi_reg_write(struct wl1271 *wl, int addr, void *buf, size_t len,
355 bool fixed)
356{
357 int physical;
358
359 physical = wl1271_translate_reg_addr(wl, addr);
360
361 wl1271_spi_write(wl, physical, buf, len, fixed);
362}
363
364u32 wl1271_mem_read32(struct wl1271 *wl, int addr)
365{
366 return wl1271_read32(wl, wl1271_translate_mem_addr(wl, addr));
367}
368
369void wl1271_mem_write32(struct wl1271 *wl, int addr, u32 val)
370{
371 wl1271_write32(wl, wl1271_translate_mem_addr(wl, addr), val);
372}
373
374u32 wl1271_reg_read32(struct wl1271 *wl, int addr)
375{
376 return wl1271_read32(wl, wl1271_translate_reg_addr(wl, addr));
377}
378
379void wl1271_reg_write32(struct wl1271 *wl, int addr, u32 val)
380{
381 wl1271_write32(wl, wl1271_translate_reg_addr(wl, addr), val);
382}
diff --git a/drivers/net/wireless/wl12xx/wl1271_spi.h b/drivers/net/wireless/wl12xx/wl1271_spi.h
index 2c9968458646..a803596dad4a 100644
--- a/drivers/net/wireless/wl12xx/wl1271_spi.h
+++ b/drivers/net/wireless/wl12xx/wl1271_spi.h
@@ -29,10 +29,14 @@
29 29
30#define HW_ACCESS_MEMORY_MAX_RANGE 0x1FFC0 30#define HW_ACCESS_MEMORY_MAX_RANGE 0x1FFC0
31 31
32#define HW_ACCESS_PART0_SIZE_ADDR 0x1FFC0 32#define HW_PARTITION_REGISTERS_ADDR 0x1ffc0
33#define HW_ACCESS_PART0_START_ADDR 0x1FFC4 33#define HW_PART0_SIZE_ADDR (HW_PARTITION_REGISTERS_ADDR)
34#define HW_ACCESS_PART1_SIZE_ADDR 0x1FFC8 34#define HW_PART0_START_ADDR (HW_PARTITION_REGISTERS_ADDR + 4)
35#define HW_ACCESS_PART1_START_ADDR 0x1FFCC 35#define HW_PART1_SIZE_ADDR (HW_PARTITION_REGISTERS_ADDR + 8)
36#define HW_PART1_START_ADDR (HW_PARTITION_REGISTERS_ADDR + 12)
37#define HW_PART2_SIZE_ADDR (HW_PARTITION_REGISTERS_ADDR + 16)
38#define HW_PART2_START_ADDR (HW_PARTITION_REGISTERS_ADDR + 20)
39#define HW_PART3_START_ADDR (HW_PARTITION_REGISTERS_ADDR + 24)
36 40
37#define HW_ACCESS_REGISTER_SIZE 4 41#define HW_ACCESS_REGISTER_SIZE 4
38 42
@@ -67,47 +71,26 @@
67 ((WL1271_BUSY_WORD_LEN - 4) / sizeof(u32)) 71 ((WL1271_BUSY_WORD_LEN - 4) / sizeof(u32))
68#define HW_ACCESS_WSPI_INIT_CMD_MASK 0 72#define HW_ACCESS_WSPI_INIT_CMD_MASK 0
69 73
74#define OCP_CMD_LOOP 32
75
76#define OCP_CMD_WRITE 0x1
77#define OCP_CMD_READ 0x2
78
79#define OCP_READY_MASK BIT(18)
80#define OCP_STATUS_MASK (BIT(16) | BIT(17))
81
82#define OCP_STATUS_NO_RESP 0x00000
83#define OCP_STATUS_OK 0x10000
84#define OCP_STATUS_REQ_FAILED 0x20000
85#define OCP_STATUS_RESP_ERROR 0x30000
70 86
71/* Raw target IO, address is not translated */ 87/* Raw target IO, address is not translated */
72void wl1271_spi_write(struct wl1271 *wl, int addr, void *buf, 88void wl1271_spi_raw_write(struct wl1271 *wl, int addr, void *buf,
73 size_t len, bool fixed); 89 size_t len, bool fixed);
74void wl1271_spi_read(struct wl1271 *wl, int addr, void *buf, 90void wl1271_spi_raw_read(struct wl1271 *wl, int addr, void *buf,
75 size_t len, bool fixed); 91 size_t len, bool fixed);
76 92
77/* Memory target IO, address is tranlated to partition 0 */
78void wl1271_spi_mem_read(struct wl1271 *wl, int addr, void *buf, size_t len);
79void wl1271_spi_mem_write(struct wl1271 *wl, int addr, void *buf, size_t len);
80u32 wl1271_mem_read32(struct wl1271 *wl, int addr);
81void wl1271_mem_write32(struct wl1271 *wl, int addr, u32 val);
82
83/* Registers IO */
84void wl1271_spi_reg_read(struct wl1271 *wl, int addr, void *buf, size_t len,
85 bool fixed);
86void wl1271_spi_reg_write(struct wl1271 *wl, int addr, void *buf, size_t len,
87 bool fixed);
88u32 wl1271_reg_read32(struct wl1271 *wl, int addr);
89void wl1271_reg_write32(struct wl1271 *wl, int addr, u32 val);
90
91/* INIT and RESET words */ 93/* INIT and RESET words */
92void wl1271_spi_reset(struct wl1271 *wl); 94void wl1271_spi_reset(struct wl1271 *wl);
93void wl1271_spi_init(struct wl1271 *wl); 95void wl1271_spi_init(struct wl1271 *wl);
94int wl1271_set_partition(struct wl1271 *wl,
95 u32 part_start, u32 part_size,
96 u32 reg_start, u32 reg_size);
97
98static inline u32 wl1271_read32(struct wl1271 *wl, int addr)
99{
100 wl1271_spi_read(wl, addr, &wl->buffer_32,
101 sizeof(wl->buffer_32), false);
102
103 return wl->buffer_32;
104}
105
106static inline void wl1271_write32(struct wl1271 *wl, int addr, u32 val)
107{
108 wl->buffer_32 = val;
109 wl1271_spi_write(wl, addr, &wl->buffer_32,
110 sizeof(wl->buffer_32), false);
111}
112
113#endif /* __WL1271_SPI_H__ */ 96#endif /* __WL1271_SPI_H__ */
diff --git a/drivers/net/wireless/wl12xx/wl1271_testmode.c b/drivers/net/wireless/wl12xx/wl1271_testmode.c
new file mode 100644
index 000000000000..5c1c4f565fd8
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/wl1271_testmode.c
@@ -0,0 +1,284 @@
1/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 2010 Nokia Corporation
5 *
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23#include "wl1271_testmode.h"
24
25#include <linux/slab.h>
26#include <net/genetlink.h>
27
28#include "wl1271.h"
29#include "wl1271_spi.h"
30#include "wl1271_acx.h"
31
32#define WL1271_TM_MAX_DATA_LENGTH 1024
33
34enum wl1271_tm_commands {
35 WL1271_TM_CMD_UNSPEC,
36 WL1271_TM_CMD_TEST,
37 WL1271_TM_CMD_INTERROGATE,
38 WL1271_TM_CMD_CONFIGURE,
39 WL1271_TM_CMD_NVS_PUSH,
40 WL1271_TM_CMD_SET_PLT_MODE,
41
42 __WL1271_TM_CMD_AFTER_LAST
43};
44#define WL1271_TM_CMD_MAX (__WL1271_TM_CMD_AFTER_LAST - 1)
45
46enum wl1271_tm_attrs {
47 WL1271_TM_ATTR_UNSPEC,
48 WL1271_TM_ATTR_CMD_ID,
49 WL1271_TM_ATTR_ANSWER,
50 WL1271_TM_ATTR_DATA,
51 WL1271_TM_ATTR_IE_ID,
52 WL1271_TM_ATTR_PLT_MODE,
53
54 __WL1271_TM_ATTR_AFTER_LAST
55};
56#define WL1271_TM_ATTR_MAX (__WL1271_TM_ATTR_AFTER_LAST - 1)
57
58static struct nla_policy wl1271_tm_policy[WL1271_TM_ATTR_MAX + 1] = {
59 [WL1271_TM_ATTR_CMD_ID] = { .type = NLA_U32 },
60 [WL1271_TM_ATTR_ANSWER] = { .type = NLA_U8 },
61 [WL1271_TM_ATTR_DATA] = { .type = NLA_BINARY,
62 .len = WL1271_TM_MAX_DATA_LENGTH },
63 [WL1271_TM_ATTR_IE_ID] = { .type = NLA_U32 },
64 [WL1271_TM_ATTR_PLT_MODE] = { .type = NLA_U32 },
65};
66
67
68static int wl1271_tm_cmd_test(struct wl1271 *wl, struct nlattr *tb[])
69{
70 int buf_len, ret, len;
71 struct sk_buff *skb;
72 void *buf;
73 u8 answer = 0;
74
75 wl1271_debug(DEBUG_TESTMODE, "testmode cmd test");
76
77 if (!tb[WL1271_TM_ATTR_DATA])
78 return -EINVAL;
79
80 buf = nla_data(tb[WL1271_TM_ATTR_DATA]);
81 buf_len = nla_len(tb[WL1271_TM_ATTR_DATA]);
82
83 if (tb[WL1271_TM_ATTR_ANSWER])
84 answer = nla_get_u8(tb[WL1271_TM_ATTR_ANSWER]);
85
86 if (buf_len > sizeof(struct wl1271_command))
87 return -EMSGSIZE;
88
89 mutex_lock(&wl->mutex);
90 ret = wl1271_cmd_test(wl, buf, buf_len, answer);
91 mutex_unlock(&wl->mutex);
92
93 if (ret < 0) {
94 wl1271_warning("testmode cmd test failed: %d", ret);
95 return ret;
96 }
97
98 if (answer) {
99 len = nla_total_size(buf_len);
100 skb = cfg80211_testmode_alloc_reply_skb(wl->hw->wiphy, len);
101 if (!skb)
102 return -ENOMEM;
103
104 NLA_PUT(skb, WL1271_TM_ATTR_DATA, buf_len, buf);
105 ret = cfg80211_testmode_reply(skb);
106 if (ret < 0)
107 return ret;
108 }
109
110 return 0;
111
112nla_put_failure:
113 kfree_skb(skb);
114 return -EMSGSIZE;
115}
116
117static int wl1271_tm_cmd_interrogate(struct wl1271 *wl, struct nlattr *tb[])
118{
119 int ret;
120 struct wl1271_command *cmd;
121 struct sk_buff *skb;
122 u8 ie_id;
123
124 wl1271_debug(DEBUG_TESTMODE, "testmode cmd interrogate");
125
126 if (!tb[WL1271_TM_ATTR_IE_ID])
127 return -EINVAL;
128
129 ie_id = nla_get_u8(tb[WL1271_TM_ATTR_IE_ID]);
130
131 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
132 if (!cmd)
133 return -ENOMEM;
134
135 mutex_lock(&wl->mutex);
136 ret = wl1271_cmd_interrogate(wl, ie_id, cmd, sizeof(*cmd));
137 mutex_unlock(&wl->mutex);
138
139 if (ret < 0) {
140 wl1271_warning("testmode cmd interrogate failed: %d", ret);
141 return ret;
142 }
143
144 skb = cfg80211_testmode_alloc_reply_skb(wl->hw->wiphy, sizeof(*cmd));
145 if (!skb)
146 return -ENOMEM;
147
148 NLA_PUT(skb, WL1271_TM_ATTR_DATA, sizeof(*cmd), cmd);
149
150 return 0;
151
152nla_put_failure:
153 kfree_skb(skb);
154 return -EMSGSIZE;
155}
156
157static int wl1271_tm_cmd_configure(struct wl1271 *wl, struct nlattr *tb[])
158{
159 int buf_len, ret;
160 void *buf;
161 u8 ie_id;
162
163 wl1271_debug(DEBUG_TESTMODE, "testmode cmd configure");
164
165 if (!tb[WL1271_TM_ATTR_DATA])
166 return -EINVAL;
167 if (!tb[WL1271_TM_ATTR_IE_ID])
168 return -EINVAL;
169
170 ie_id = nla_get_u8(tb[WL1271_TM_ATTR_IE_ID]);
171 buf = nla_data(tb[WL1271_TM_ATTR_DATA]);
172 buf_len = nla_len(tb[WL1271_TM_ATTR_DATA]);
173
174 if (buf_len > sizeof(struct wl1271_command))
175 return -EMSGSIZE;
176
177 mutex_lock(&wl->mutex);
178 ret = wl1271_cmd_configure(wl, ie_id, buf, buf_len);
179 mutex_unlock(&wl->mutex);
180
181 if (ret < 0) {
182 wl1271_warning("testmode cmd configure failed: %d", ret);
183 return ret;
184 }
185
186 return 0;
187}
188
189static int wl1271_tm_cmd_nvs_push(struct wl1271 *wl, struct nlattr *tb[])
190{
191 int ret = 0;
192 size_t len;
193 void *buf;
194
195 wl1271_debug(DEBUG_TESTMODE, "testmode cmd nvs push");
196
197 if (!tb[WL1271_TM_ATTR_DATA])
198 return -EINVAL;
199
200 buf = nla_data(tb[WL1271_TM_ATTR_DATA]);
201 len = nla_len(tb[WL1271_TM_ATTR_DATA]);
202
203 if (len != sizeof(struct wl1271_nvs_file)) {
204 wl1271_error("nvs size is not as expected: %zu != %zu",
205 len, sizeof(struct wl1271_nvs_file));
206 return -EMSGSIZE;
207 }
208
209 mutex_lock(&wl->mutex);
210
211 kfree(wl->nvs);
212
213 wl->nvs = kmalloc(sizeof(struct wl1271_nvs_file), GFP_KERNEL);
214 if (!wl->nvs) {
215 wl1271_error("could not allocate memory for the nvs file");
216 ret = -ENOMEM;
217 goto out;
218 }
219
220 memcpy(wl->nvs, buf, len);
221
222 wl1271_debug(DEBUG_TESTMODE, "testmode pushed nvs");
223
224out:
225 mutex_unlock(&wl->mutex);
226
227 return ret;
228}
229
230static int wl1271_tm_cmd_set_plt_mode(struct wl1271 *wl, struct nlattr *tb[])
231{
232 u32 val;
233 int ret;
234
235 wl1271_debug(DEBUG_TESTMODE, "testmode cmd set plt mode");
236
237 if (!tb[WL1271_TM_ATTR_PLT_MODE])
238 return -EINVAL;
239
240 val = nla_get_u32(tb[WL1271_TM_ATTR_PLT_MODE]);
241
242 switch (val) {
243 case 0:
244 ret = wl1271_plt_stop(wl);
245 break;
246 case 1:
247 ret = wl1271_plt_start(wl);
248 break;
249 default:
250 ret = -EINVAL;
251 break;
252 }
253
254 return ret;
255}
256
257int wl1271_tm_cmd(struct ieee80211_hw *hw, void *data, int len)
258{
259 struct wl1271 *wl = hw->priv;
260 struct nlattr *tb[WL1271_TM_ATTR_MAX + 1];
261 int err;
262
263 err = nla_parse(tb, WL1271_TM_ATTR_MAX, data, len, wl1271_tm_policy);
264 if (err)
265 return err;
266
267 if (!tb[WL1271_TM_ATTR_CMD_ID])
268 return -EINVAL;
269
270 switch (nla_get_u32(tb[WL1271_TM_ATTR_CMD_ID])) {
271 case WL1271_TM_CMD_TEST:
272 return wl1271_tm_cmd_test(wl, tb);
273 case WL1271_TM_CMD_INTERROGATE:
274 return wl1271_tm_cmd_interrogate(wl, tb);
275 case WL1271_TM_CMD_CONFIGURE:
276 return wl1271_tm_cmd_configure(wl, tb);
277 case WL1271_TM_CMD_NVS_PUSH:
278 return wl1271_tm_cmd_nvs_push(wl, tb);
279 case WL1271_TM_CMD_SET_PLT_MODE:
280 return wl1271_tm_cmd_set_plt_mode(wl, tb);
281 default:
282 return -EOPNOTSUPP;
283 }
284}
diff --git a/drivers/net/wireless/wl12xx/wl1251_netlink.h b/drivers/net/wireless/wl12xx/wl1271_testmode.h
index ee36695e134e..c196d28f9d9d 100644
--- a/drivers/net/wireless/wl12xx/wl1251_netlink.h
+++ b/drivers/net/wireless/wl12xx/wl1271_testmode.h
@@ -1,9 +1,9 @@
1/* 1/*
2 * This file is part of wl1251 2 * This file is part of wl1271
3 * 3 *
4 * Copyright (C) 2009 Nokia Corporation 4 * Copyright (C) 2010 Nokia Corporation
5 * 5 *
6 * Contact: Kalle Valo <kalle.valo@nokia.com> 6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
7 * 7 *
8 * This program is free software; you can redistribute it and/or 8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License 9 * modify it under the terms of the GNU General Public License
@@ -21,10 +21,11 @@
21 * 21 *
22 */ 22 */
23 23
24#ifndef __WL1251_NETLINK_H__ 24#ifndef __WL1271_TESTMODE_H__
25#define __WL1251_NETLINK_H__ 25#define __WL1271_TESTMODE_H__
26 26
27int wl1251_nl_register(void); 27#include <net/mac80211.h>
28void wl1251_nl_unregister(void);
29 28
30#endif /* __WL1251_NETLINK_H__ */ 29int wl1271_tm_cmd(struct ieee80211_hw *hw, void *data, int len);
30
31#endif /* __WL1271_TESTMODE_H__ */
diff --git a/drivers/net/wireless/wl12xx/wl1271_tx.c b/drivers/net/wireless/wl12xx/wl1271_tx.c
index ff221258b941..811e739d05bf 100644
--- a/drivers/net/wireless/wl12xx/wl1271_tx.c
+++ b/drivers/net/wireless/wl12xx/wl1271_tx.c
@@ -26,6 +26,7 @@
26 26
27#include "wl1271.h" 27#include "wl1271.h"
28#include "wl1271_spi.h" 28#include "wl1271_spi.h"
29#include "wl1271_io.h"
29#include "wl1271_reg.h" 30#include "wl1271_reg.h"
30#include "wl1271_ps.h" 31#include "wl1271_ps.h"
31#include "wl1271_tx.h" 32#include "wl1271_tx.h"
@@ -33,8 +34,7 @@
33static int wl1271_tx_id(struct wl1271 *wl, struct sk_buff *skb) 34static int wl1271_tx_id(struct wl1271 *wl, struct sk_buff *skb)
34{ 35{
35 int i; 36 int i;
36 37 for (i = 0; i < ACX_TX_DESCRIPTORS; i++)
37 for (i = 0; i < FW_TX_CMPLT_BLOCK_SIZE; i++)
38 if (wl->tx_frames[i] == NULL) { 38 if (wl->tx_frames[i] == NULL) {
39 wl->tx_frames[i] = skb; 39 wl->tx_frames[i] = skb;
40 return i; 40 return i;
@@ -58,8 +58,8 @@ static int wl1271_tx_allocate(struct wl1271 *wl, struct sk_buff *skb, u32 extra)
58 /* approximate the number of blocks required for this packet 58 /* approximate the number of blocks required for this packet
59 in the firmware */ 59 in the firmware */
60 /* FIXME: try to figure out what is done here and make it cleaner */ 60 /* FIXME: try to figure out what is done here and make it cleaner */
61 total_blocks = (skb->len) >> TX_HW_BLOCK_SHIFT_DIV; 61 total_blocks = (total_len + 20) >> TX_HW_BLOCK_SHIFT_DIV;
62 excluded = (total_blocks << 2) + (skb->len & 0xff) + 34; 62 excluded = (total_blocks << 2) + ((total_len + 20) & 0xff) + 34;
63 total_blocks += (excluded > 252) ? 2 : 1; 63 total_blocks += (excluded > 252) ? 2 : 1;
64 total_blocks += TX_HW_BLOCK_SPARE; 64 total_blocks += TX_HW_BLOCK_SPARE;
65 65
@@ -88,29 +88,48 @@ static int wl1271_tx_fill_hdr(struct wl1271 *wl, struct sk_buff *skb,
88 u32 extra, struct ieee80211_tx_info *control) 88 u32 extra, struct ieee80211_tx_info *control)
89{ 89{
90 struct wl1271_tx_hw_descr *desc; 90 struct wl1271_tx_hw_descr *desc;
91 int pad; 91 int pad, ac;
92 u16 tx_attr;
92 93
93 desc = (struct wl1271_tx_hw_descr *) skb->data; 94 desc = (struct wl1271_tx_hw_descr *) skb->data;
94 95
96 /* relocate space for security header */
97 if (extra) {
98 void *framestart = skb->data + sizeof(*desc);
99 u16 fc = *(u16 *)(framestart + extra);
100 int hdrlen = ieee80211_hdrlen(cpu_to_le16(fc));
101 memmove(framestart, framestart + extra, hdrlen);
102 }
103
95 /* configure packet life time */ 104 /* configure packet life time */
96 desc->start_time = jiffies_to_usecs(jiffies) - wl->time_offset; 105 desc->start_time = cpu_to_le32(jiffies_to_usecs(jiffies) -
97 desc->life_time = TX_HW_MGMT_PKT_LIFETIME_TU; 106 wl->time_offset);
107 desc->life_time = cpu_to_le16(TX_HW_MGMT_PKT_LIFETIME_TU);
98 108
99 /* configure the tx attributes */ 109 /* configure the tx attributes */
100 desc->tx_attr = wl->session_counter << TX_HW_ATTR_OFST_SESSION_COUNTER; 110 tx_attr = wl->session_counter << TX_HW_ATTR_OFST_SESSION_COUNTER;
101 /* FIXME: do we know the packet priority? can we identify mgmt 111
102 packets, and use max prio for them at least? */ 112 /* queue */
103 desc->tid = 0; 113 ac = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
114 desc->tid = wl1271_tx_ac_to_tid(ac);
115
104 desc->aid = TX_HW_DEFAULT_AID; 116 desc->aid = TX_HW_DEFAULT_AID;
105 desc->reserved = 0; 117 desc->reserved = 0;
106 118
107 /* align the length (and store in terms of words) */ 119 /* align the length (and store in terms of words) */
108 pad = WL1271_TX_ALIGN(skb->len); 120 pad = WL1271_TX_ALIGN(skb->len);
109 desc->length = pad >> 2; 121 desc->length = cpu_to_le16(pad >> 2);
110 122
111 /* calculate number of padding bytes */ 123 /* calculate number of padding bytes */
112 pad = pad - skb->len; 124 pad = pad - skb->len;
113 desc->tx_attr |= pad << TX_HW_ATTR_OFST_LAST_WORD_PAD; 125 tx_attr |= pad << TX_HW_ATTR_OFST_LAST_WORD_PAD;
126
127 /* if the packets are destined for AP (have a STA entry) send them
128 with AP rate policies, otherwise use default basic rates */
129 if (control->control.sta)
130 tx_attr |= ACX_TX_AP_FULL_RATE << TX_HW_ATTR_OFST_RATE_POLICY;
131
132 desc->tx_attr = cpu_to_le16(tx_attr);
114 133
115 wl1271_debug(DEBUG_TX, "tx_fill_hdr: pad: %d", pad); 134 wl1271_debug(DEBUG_TX, "tx_fill_hdr: pad: %d", pad);
116 return 0; 135 return 0;
@@ -147,11 +166,11 @@ static int wl1271_tx_send_packet(struct wl1271 *wl, struct sk_buff *skb,
147 len = WL1271_TX_ALIGN(skb->len); 166 len = WL1271_TX_ALIGN(skb->len);
148 167
149 /* perform a fixed address block write with the packet */ 168 /* perform a fixed address block write with the packet */
150 wl1271_spi_reg_write(wl, WL1271_SLV_MEM_DATA, skb->data, len, true); 169 wl1271_write(wl, WL1271_SLV_MEM_DATA, skb->data, len, true);
151 170
152 /* write packet new counter into the write access register */ 171 /* write packet new counter into the write access register */
153 wl->tx_packets_count++; 172 wl->tx_packets_count++;
154 wl1271_reg_write32(wl, WL1271_HOST_WR_ACCESS, wl->tx_packets_count); 173 wl1271_write32(wl, WL1271_HOST_WR_ACCESS, wl->tx_packets_count);
155 174
156 desc = (struct wl1271_tx_hw_descr *) skb->data; 175 desc = (struct wl1271_tx_hw_descr *) skb->data;
157 wl1271_debug(DEBUG_TX, "tx id %u skb 0x%p payload %u (%u words)", 176 wl1271_debug(DEBUG_TX, "tx id %u skb 0x%p payload %u (%u words)",
@@ -185,6 +204,7 @@ static int wl1271_tx_frame(struct wl1271 *wl, struct sk_buff *skb)
185 ret = wl1271_cmd_set_default_wep_key(wl, idx); 204 ret = wl1271_cmd_set_default_wep_key(wl, idx);
186 if (ret < 0) 205 if (ret < 0)
187 return ret; 206 return ret;
207 wl->default_key = idx;
188 } 208 }
189 } 209 }
190 210
@@ -203,18 +223,50 @@ static int wl1271_tx_frame(struct wl1271 *wl, struct sk_buff *skb)
203 return ret; 223 return ret;
204} 224}
205 225
226static u32 wl1271_tx_enabled_rates_get(struct wl1271 *wl, u32 rate_set)
227{
228 struct ieee80211_supported_band *band;
229 u32 enabled_rates = 0;
230 int bit;
231
232 band = wl->hw->wiphy->bands[wl->band];
233 for (bit = 0; bit < band->n_bitrates; bit++) {
234 if (rate_set & 0x1)
235 enabled_rates |= band->bitrates[bit].hw_value;
236 rate_set >>= 1;
237 }
238
239 return enabled_rates;
240}
241
206void wl1271_tx_work(struct work_struct *work) 242void wl1271_tx_work(struct work_struct *work)
207{ 243{
208 struct wl1271 *wl = container_of(work, struct wl1271, tx_work); 244 struct wl1271 *wl = container_of(work, struct wl1271, tx_work);
209 struct sk_buff *skb; 245 struct sk_buff *skb;
210 bool woken_up = false; 246 bool woken_up = false;
247 u32 sta_rates = 0;
211 int ret; 248 int ret;
212 249
250 /* check if the rates supported by the AP have changed */
251 if (unlikely(test_and_clear_bit(WL1271_FLAG_STA_RATES_CHANGED,
252 &wl->flags))) {
253 unsigned long flags;
254 spin_lock_irqsave(&wl->wl_lock, flags);
255 sta_rates = wl->sta_rate_set;
256 spin_unlock_irqrestore(&wl->wl_lock, flags);
257 }
258
213 mutex_lock(&wl->mutex); 259 mutex_lock(&wl->mutex);
214 260
215 if (unlikely(wl->state == WL1271_STATE_OFF)) 261 if (unlikely(wl->state == WL1271_STATE_OFF))
216 goto out; 262 goto out;
217 263
264 /* if rates have changed, re-configure the rate policy */
265 if (unlikely(sta_rates)) {
266 wl->rate_set = wl1271_tx_enabled_rates_get(wl, sta_rates);
267 wl1271_acx_rate_policies(wl);
268 }
269
218 while ((skb = skb_dequeue(&wl->tx_queue))) { 270 while ((skb = skb_dequeue(&wl->tx_queue))) {
219 if (!woken_up) { 271 if (!woken_up) {
220 ret = wl1271_ps_elp_wakeup(wl, false); 272 ret = wl1271_ps_elp_wakeup(wl, false);
@@ -229,18 +281,18 @@ void wl1271_tx_work(struct work_struct *work)
229 wl1271_debug(DEBUG_TX, "tx_work: fw buffer full, " 281 wl1271_debug(DEBUG_TX, "tx_work: fw buffer full, "
230 "stop queues"); 282 "stop queues");
231 ieee80211_stop_queues(wl->hw); 283 ieee80211_stop_queues(wl->hw);
232 wl->tx_queue_stopped = true; 284 set_bit(WL1271_FLAG_TX_QUEUE_STOPPED, &wl->flags);
233 skb_queue_head(&wl->tx_queue, skb); 285 skb_queue_head(&wl->tx_queue, skb);
234 goto out; 286 goto out;
235 } else if (ret < 0) { 287 } else if (ret < 0) {
236 dev_kfree_skb(skb); 288 dev_kfree_skb(skb);
237 goto out; 289 goto out;
238 } else if (wl->tx_queue_stopped) { 290 } else if (test_and_clear_bit(WL1271_FLAG_TX_QUEUE_STOPPED,
291 &wl->flags)) {
239 /* firmware buffer has space, restart queues */ 292 /* firmware buffer has space, restart queues */
240 wl1271_debug(DEBUG_TX, 293 wl1271_debug(DEBUG_TX,
241 "complete_packet: waking queues"); 294 "complete_packet: waking queues");
242 ieee80211_wake_queues(wl->hw); 295 ieee80211_wake_queues(wl->hw);
243 wl->tx_queue_stopped = false;
244 } 296 }
245 } 297 }
246 298
@@ -254,14 +306,13 @@ out:
254static void wl1271_tx_complete_packet(struct wl1271 *wl, 306static void wl1271_tx_complete_packet(struct wl1271 *wl,
255 struct wl1271_tx_hw_res_descr *result) 307 struct wl1271_tx_hw_res_descr *result)
256{ 308{
257
258 struct ieee80211_tx_info *info; 309 struct ieee80211_tx_info *info;
259 struct sk_buff *skb; 310 struct sk_buff *skb;
260 u32 header_len; 311 u16 seq;
261 int id = result->id; 312 int id = result->id;
262 313
263 /* check for id legality */ 314 /* check for id legality */
264 if (id >= TX_HW_RESULT_QUEUE_LEN || wl->tx_frames[id] == NULL) { 315 if (id >= ACX_TX_DESCRIPTORS || wl->tx_frames[id] == NULL) {
265 wl1271_warning("TX result illegal id: %d", id); 316 wl1271_warning("TX result illegal id: %d", id);
266 return; 317 return;
267 } 318 }
@@ -284,22 +335,32 @@ static void wl1271_tx_complete_packet(struct wl1271 *wl,
284 /* info->status.retry_count = result->ack_failures; */ 335 /* info->status.retry_count = result->ack_failures; */
285 wl->stats.retry_count += result->ack_failures; 336 wl->stats.retry_count += result->ack_failures;
286 337
287 /* get header len */ 338 /* update security sequence number */
339 seq = wl->tx_security_seq_16 +
340 (result->lsb_security_sequence_number -
341 wl->tx_security_last_seq);
342 wl->tx_security_last_seq = result->lsb_security_sequence_number;
343
344 if (seq < wl->tx_security_seq_16)
345 wl->tx_security_seq_32++;
346 wl->tx_security_seq_16 = seq;
347
348 /* remove private header from packet */
349 skb_pull(skb, sizeof(struct wl1271_tx_hw_descr));
350
351 /* remove TKIP header space if present */
288 if (info->control.hw_key && 352 if (info->control.hw_key &&
289 info->control.hw_key->alg == ALG_TKIP) 353 info->control.hw_key->alg == ALG_TKIP) {
290 header_len = WL1271_TKIP_IV_SPACE + 354 int hdrlen = ieee80211_get_hdrlen_from_skb(skb);
291 sizeof(struct wl1271_tx_hw_descr); 355 memmove(skb->data + WL1271_TKIP_IV_SPACE, skb->data, hdrlen);
292 else 356 skb_pull(skb, WL1271_TKIP_IV_SPACE);
293 header_len = sizeof(struct wl1271_tx_hw_descr); 357 }
294 358
295 wl1271_debug(DEBUG_TX, "tx status id %u skb 0x%p failures %u rate 0x%x" 359 wl1271_debug(DEBUG_TX, "tx status id %u skb 0x%p failures %u rate 0x%x"
296 " status 0x%x", 360 " status 0x%x",
297 result->id, skb, result->ack_failures, 361 result->id, skb, result->ack_failures,
298 result->rate_class_index, result->status); 362 result->rate_class_index, result->status);
299 363
300 /* remove private header from packet */
301 skb_pull(skb, header_len);
302
303 /* return the packet to the stack */ 364 /* return the packet to the stack */
304 ieee80211_tx_status(wl->hw, skb); 365 ieee80211_tx_status(wl->hw, skb);
305 wl->tx_frames[result->id] = NULL; 366 wl->tx_frames[result->id] = NULL;
@@ -315,8 +376,8 @@ void wl1271_tx_complete(struct wl1271 *wl, u32 count)
315 wl1271_debug(DEBUG_TX, "tx_complete received, packets: %d", count); 376 wl1271_debug(DEBUG_TX, "tx_complete received, packets: %d", count);
316 377
317 /* read the tx results from the chipset */ 378 /* read the tx results from the chipset */
318 wl1271_spi_mem_read(wl, memmap->tx_result, 379 wl1271_read(wl, le32_to_cpu(memmap->tx_result),
319 wl->tx_res_if, sizeof(*wl->tx_res_if)); 380 wl->tx_res_if, sizeof(*wl->tx_res_if), false);
320 381
321 /* verify that the result buffer is not getting overrun */ 382 /* verify that the result buffer is not getting overrun */
322 if (count > TX_HW_RESULT_QUEUE_LEN) { 383 if (count > TX_HW_RESULT_QUEUE_LEN) {
@@ -337,10 +398,10 @@ void wl1271_tx_complete(struct wl1271 *wl, u32 count)
337 } 398 }
338 399
339 /* write host counter to chipset (to ack) */ 400 /* write host counter to chipset (to ack) */
340 wl1271_mem_write32(wl, memmap->tx_result + 401 wl1271_write32(wl, le32_to_cpu(memmap->tx_result) +
341 offsetof(struct wl1271_tx_hw_res_if, 402 offsetof(struct wl1271_tx_hw_res_if,
342 tx_result_host_counter), 403 tx_result_host_counter),
343 wl->tx_res_if->tx_result_fw_counter); 404 le32_to_cpu(wl->tx_res_if->tx_result_fw_counter));
344} 405}
345 406
346/* caller must hold wl->mutex */ 407/* caller must hold wl->mutex */
@@ -364,7 +425,7 @@ void wl1271_tx_flush(struct wl1271 *wl)
364 ieee80211_tx_status(wl->hw, skb); 425 ieee80211_tx_status(wl->hw, skb);
365 } 426 }
366 427
367 for (i = 0; i < FW_TX_CMPLT_BLOCK_SIZE; i++) 428 for (i = 0; i < ACX_TX_DESCRIPTORS; i++)
368 if (wl->tx_frames[i] != NULL) { 429 if (wl->tx_frames[i] != NULL) {
369 skb = wl->tx_frames[i]; 430 skb = wl->tx_frames[i];
370 info = IEEE80211_SKB_CB(skb); 431 info = IEEE80211_SKB_CB(skb);
diff --git a/drivers/net/wireless/wl12xx/wl1271_tx.h b/drivers/net/wireless/wl12xx/wl1271_tx.h
index 4a614067ddba..17e405a09caa 100644
--- a/drivers/net/wireless/wl12xx/wl1271_tx.h
+++ b/drivers/net/wireless/wl12xx/wl1271_tx.h
@@ -58,7 +58,7 @@
58 58
59struct wl1271_tx_hw_descr { 59struct wl1271_tx_hw_descr {
60 /* Length of packet in words, including descriptor+header+data */ 60 /* Length of packet in words, including descriptor+header+data */
61 u16 length; 61 __le16 length;
62 /* Number of extra memory blocks to allocate for this packet in 62 /* Number of extra memory blocks to allocate for this packet in
63 addition to the number of blocks derived from the packet length */ 63 addition to the number of blocks derived from the packet length */
64 u8 extra_mem_blocks; 64 u8 extra_mem_blocks;
@@ -67,12 +67,12 @@ struct wl1271_tx_hw_descr {
67 HW!! */ 67 HW!! */
68 u8 total_mem_blocks; 68 u8 total_mem_blocks;
69 /* Device time (in us) when the packet arrived to the driver */ 69 /* Device time (in us) when the packet arrived to the driver */
70 u32 start_time; 70 __le32 start_time;
71 /* Max delay in TUs until transmission. The last device time the 71 /* Max delay in TUs until transmission. The last device time the
72 packet can be transmitted is: startTime+(1024*LifeTime) */ 72 packet can be transmitted is: startTime+(1024*LifeTime) */
73 u16 life_time; 73 __le16 life_time;
74 /* Bitwise fields - see TX_ATTR... definitions above. */ 74 /* Bitwise fields - see TX_ATTR... definitions above. */
75 u16 tx_attr; 75 __le16 tx_attr;
76 /* Packet identifier used also in the Tx-Result. */ 76 /* Packet identifier used also in the Tx-Result. */
77 u8 id; 77 u8 id;
78 /* The packet TID value (as User-Priority) */ 78 /* The packet TID value (as User-Priority) */
@@ -100,12 +100,12 @@ struct wl1271_tx_hw_res_descr {
100 several possible reasons for failure. */ 100 several possible reasons for failure. */
101 u8 status; 101 u8 status;
102 /* Total air access duration including all retrys and overheads.*/ 102 /* Total air access duration including all retrys and overheads.*/
103 u16 medium_usage; 103 __le16 medium_usage;
104 /* The time passed from host xfer to Tx-complete.*/ 104 /* The time passed from host xfer to Tx-complete.*/
105 u32 fw_handling_time; 105 __le32 fw_handling_time;
106 /* Total media delay 106 /* Total media delay
107 (from 1st EDCA AIFS counter until TX Complete). */ 107 (from 1st EDCA AIFS counter until TX Complete). */
108 u32 medium_delay; 108 __le32 medium_delay;
109 /* LS-byte of last TKIP seq-num (saved per AC for recovery). */ 109 /* LS-byte of last TKIP seq-num (saved per AC for recovery). */
110 u8 lsb_security_sequence_number; 110 u8 lsb_security_sequence_number;
111 /* Retry count - number of transmissions without successful ACK.*/ 111 /* Retry count - number of transmissions without successful ACK.*/
@@ -118,11 +118,47 @@ struct wl1271_tx_hw_res_descr {
118} __attribute__ ((packed)); 118} __attribute__ ((packed));
119 119
120struct wl1271_tx_hw_res_if { 120struct wl1271_tx_hw_res_if {
121 u32 tx_result_fw_counter; 121 __le32 tx_result_fw_counter;
122 u32 tx_result_host_counter; 122 __le32 tx_result_host_counter;
123 struct wl1271_tx_hw_res_descr tx_results_queue[TX_HW_RESULT_QUEUE_LEN]; 123 struct wl1271_tx_hw_res_descr tx_results_queue[TX_HW_RESULT_QUEUE_LEN];
124} __attribute__ ((packed)); 124} __attribute__ ((packed));
125 125
126static inline int wl1271_tx_get_queue(int queue)
127{
128 /* FIXME: use best effort until WMM is enabled */
129 return CONF_TX_AC_BE;
130
131 switch (queue) {
132 case 0:
133 return CONF_TX_AC_VO;
134 case 1:
135 return CONF_TX_AC_VI;
136 case 2:
137 return CONF_TX_AC_BE;
138 case 3:
139 return CONF_TX_AC_BK;
140 default:
141 return CONF_TX_AC_BE;
142 }
143}
144
145/* wl1271 tx descriptor needs the tid and we need to convert it from ac */
146static inline int wl1271_tx_ac_to_tid(int ac)
147{
148 switch (ac) {
149 case 0:
150 return 0;
151 case 1:
152 return 2;
153 case 2:
154 return 4;
155 case 3:
156 return 6;
157 default:
158 return 0;
159 }
160}
161
126void wl1271_tx_work(struct work_struct *work); 162void wl1271_tx_work(struct work_struct *work);
127void wl1271_tx_complete(struct wl1271 *wl, u32 count); 163void wl1271_tx_complete(struct wl1271 *wl, u32 count);
128void wl1271_tx_flush(struct wl1271 *wl); 164void wl1271_tx_flush(struct wl1271 *wl);
diff --git a/drivers/net/wireless/wl12xx/wl12xx_80211.h b/drivers/net/wireless/wl12xx/wl12xx_80211.h
index 657c2dbcb7d3..055d7bc6f592 100644
--- a/drivers/net/wireless/wl12xx/wl12xx_80211.h
+++ b/drivers/net/wireless/wl12xx/wl12xx_80211.h
@@ -122,8 +122,8 @@ struct wl12xx_null_data_template {
122} __attribute__ ((packed)); 122} __attribute__ ((packed));
123 123
124struct wl12xx_ps_poll_template { 124struct wl12xx_ps_poll_template {
125 u16 fc; 125 __le16 fc;
126 u16 aid; 126 __le16 aid;
127 u8 bssid[ETH_ALEN]; 127 u8 bssid[ETH_ALEN];
128 u8 ta[ETH_ALEN]; 128 u8 ta[ETH_ALEN];
129} __attribute__ ((packed)); 129} __attribute__ ((packed));