aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2009-05-08 15:46:17 -0400
committerDavid S. Miller <davem@davemloft.net>2009-05-08 15:46:17 -0400
commita8679be2073392cf22a910bc25da0c7d36459845 (patch)
tree0d25750ea4ba3a85fe683f285261083d77080976 /drivers
parent22f6dacdfcfdc792d068e9c41234808860498d04 (diff)
parent9dfd6ba353b993d648dcda72480c7ce92cd27c7e (diff)
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-next-2.6
Diffstat (limited to 'drivers')
-rw-r--r--drivers/net/wireless/Kconfig1
-rw-r--r--drivers/net/wireless/Makefile2
-rw-r--r--drivers/net/wireless/adm8211.c14
-rw-r--r--drivers/net/wireless/at76c50x-usb.c15
-rw-r--r--drivers/net/wireless/ath/ar9170/hw.h2
-rw-r--r--drivers/net/wireless/ath/ar9170/mac.c33
-rw-r--r--drivers/net/wireless/ath/ar9170/main.c48
-rw-r--r--drivers/net/wireless/ath/ar9170/usb.c6
-rw-r--r--drivers/net/wireless/ath/ath5k/ath5k.h37
-rw-r--r--drivers/net/wireless/ath/ath5k/attach.c1
-rw-r--r--drivers/net/wireless/ath/ath5k/base.c210
-rw-r--r--drivers/net/wireless/ath/ath5k/eeprom.c73
-rw-r--r--drivers/net/wireless/ath/ath5k/eeprom.h46
-rw-r--r--drivers/net/wireless/ath/ath5k/led.c6
-rw-r--r--drivers/net/wireless/ath/ath5k/pcu.c6
-rw-r--r--drivers/net/wireless/ath/ath5k/phy.c493
-rw-r--r--drivers/net/wireless/ath/ath5k/qcu.c7
-rw-r--r--drivers/net/wireless/ath/ath5k/reg.h9
-rw-r--r--drivers/net/wireless/ath/ath5k/reset.c70
-rw-r--r--drivers/net/wireless/ath/ath9k/ath9k.h39
-rw-r--r--drivers/net/wireless/ath/ath9k/beacon.c11
-rw-r--r--drivers/net/wireless/ath/ath9k/calib.c6
-rw-r--r--drivers/net/wireless/ath/ath9k/hw.c37
-rw-r--r--drivers/net/wireless/ath/ath9k/hw.h3
-rw-r--r--drivers/net/wireless/ath/ath9k/main.c206
-rw-r--r--drivers/net/wireless/ath/ath9k/rc.c70
-rw-r--r--drivers/net/wireless/ath/ath9k/xmit.c10
-rw-r--r--drivers/net/wireless/atmel_cs.c2
-rw-r--r--drivers/net/wireless/b43/main.c76
-rw-r--r--drivers/net/wireless/b43legacy/main.c73
-rw-r--r--drivers/net/wireless/ipw2x00/ipw2100.c8
-rw-r--r--drivers/net/wireless/ipw2x00/ipw2200.c47
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945-rs.c7
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-rs.c31
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn.c24
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-core.c168
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-core.h3
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-sta.c2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl3945-base.c69
-rw-r--r--drivers/net/wireless/libertas_tf/main.c56
-rw-r--r--drivers/net/wireless/mac80211_hwsim.c45
-rw-r--r--drivers/net/wireless/mwl8k.c18
-rw-r--r--drivers/net/wireless/p54/p54.h4
-rw-r--r--drivers/net/wireless/p54/p54common.c86
-rw-r--r--drivers/net/wireless/p54/p54usb.c314
-rw-r--r--drivers/net/wireless/p54/p54usb.h16
-rw-r--r--drivers/net/wireless/rt2x00/Kconfig17
-rw-r--r--drivers/net/wireless/rt2x00/Makefile2
-rw-r--r--drivers/net/wireless/rt2x00/rt2400pci.c1
-rw-r--r--drivers/net/wireless/rt2x00/rt2500pci.c1
-rw-r--r--drivers/net/wireless/rt2x00/rt2500usb.c3
-rw-r--r--drivers/net/wireless/rt2x00/rt2800usb.c3071
-rw-r--r--drivers/net/wireless/rt2x00/rt2800usb.h1945
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00.h32
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00config.c5
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00crypto.c87
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00dev.c125
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00ht.c69
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00lib.h65
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00mac.c88
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00queue.c48
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00queue.h53
-rw-r--r--drivers/net/wireless/rt2x00/rt61pci.c1
-rw-r--r--drivers/net/wireless/rt2x00/rt73usb.c4
-rw-r--r--drivers/net/wireless/rtl818x/rtl8180_dev.c33
-rw-r--r--drivers/net/wireless/rtl818x/rtl8187_dev.c48
-rw-r--r--drivers/net/wireless/wl12xx/Kconfig11
-rw-r--r--drivers/net/wireless/wl12xx/Makefile4
-rw-r--r--drivers/net/wireless/wl12xx/acx.c689
-rw-r--r--drivers/net/wireless/wl12xx/acx.h1245
-rw-r--r--drivers/net/wireless/wl12xx/boot.c295
-rw-r--r--drivers/net/wireless/wl12xx/boot.h40
-rw-r--r--drivers/net/wireless/wl12xx/cmd.c353
-rw-r--r--drivers/net/wireless/wl12xx/cmd.h265
-rw-r--r--drivers/net/wireless/wl12xx/debugfs.c508
-rw-r--r--drivers/net/wireless/wl12xx/debugfs.h33
-rw-r--r--drivers/net/wireless/wl12xx/event.c127
-rw-r--r--drivers/net/wireless/wl12xx/event.h121
-rw-r--r--drivers/net/wireless/wl12xx/init.c200
-rw-r--r--drivers/net/wireless/wl12xx/init.h40
-rw-r--r--drivers/net/wireless/wl12xx/main.c1358
-rw-r--r--drivers/net/wireless/wl12xx/ps.c151
-rw-r--r--drivers/net/wireless/wl12xx/ps.h36
-rw-r--r--drivers/net/wireless/wl12xx/reg.h745
-rw-r--r--drivers/net/wireless/wl12xx/rx.c208
-rw-r--r--drivers/net/wireless/wl12xx/rx.h122
-rw-r--r--drivers/net/wireless/wl12xx/spi.c358
-rw-r--r--drivers/net/wireless/wl12xx/spi.h109
-rw-r--r--drivers/net/wireless/wl12xx/tx.c557
-rw-r--r--drivers/net/wireless/wl12xx/tx.h215
-rw-r--r--drivers/net/wireless/wl12xx/wl1251.c709
-rw-r--r--drivers/net/wireless/wl12xx/wl1251.h165
-rw-r--r--drivers/net/wireless/wl12xx/wl12xx.h409
-rw-r--r--drivers/net/wireless/wl12xx/wl12xx_80211.h156
-rw-r--r--drivers/net/wireless/zd1211rw/zd_mac.c80
95 files changed, 16237 insertions, 1280 deletions
diff --git a/drivers/net/wireless/Kconfig b/drivers/net/wireless/Kconfig
index 2d8434f409b6..91be3e7bf133 100644
--- a/drivers/net/wireless/Kconfig
+++ b/drivers/net/wireless/Kconfig
@@ -500,5 +500,6 @@ source "drivers/net/wireless/b43legacy/Kconfig"
500source "drivers/net/wireless/zd1211rw/Kconfig" 500source "drivers/net/wireless/zd1211rw/Kconfig"
501source "drivers/net/wireless/rt2x00/Kconfig" 501source "drivers/net/wireless/rt2x00/Kconfig"
502source "drivers/net/wireless/orinoco/Kconfig" 502source "drivers/net/wireless/orinoco/Kconfig"
503source "drivers/net/wireless/wl12xx/Kconfig"
503 504
504endmenu 505endmenu
diff --git a/drivers/net/wireless/Makefile b/drivers/net/wireless/Makefile
index 0625e91b5995..f2b1861e6bcb 100644
--- a/drivers/net/wireless/Makefile
+++ b/drivers/net/wireless/Makefile
@@ -58,3 +58,5 @@ obj-$(CONFIG_P54_COMMON) += p54/
58obj-$(CONFIG_ATH_COMMON) += ath/ 58obj-$(CONFIG_ATH_COMMON) += ath/
59 59
60obj-$(CONFIG_MAC80211_HWSIM) += mac80211_hwsim.o 60obj-$(CONFIG_MAC80211_HWSIM) += mac80211_hwsim.o
61
62obj-$(CONFIG_WL12XX) += wl12xx/
diff --git a/drivers/net/wireless/adm8211.c b/drivers/net/wireless/adm8211.c
index f71821795018..2b9e379994a1 100644
--- a/drivers/net/wireless/adm8211.c
+++ b/drivers/net/wireless/adm8211.c
@@ -1311,18 +1311,20 @@ static int adm8211_config(struct ieee80211_hw *dev, u32 changed)
1311 return 0; 1311 return 0;
1312} 1312}
1313 1313
1314static int adm8211_config_interface(struct ieee80211_hw *dev, 1314static void adm8211_bss_info_changed(struct ieee80211_hw *dev,
1315 struct ieee80211_vif *vif, 1315 struct ieee80211_vif *vif,
1316 struct ieee80211_if_conf *conf) 1316 struct ieee80211_bss_conf *conf,
1317 u32 changes)
1317{ 1318{
1318 struct adm8211_priv *priv = dev->priv; 1319 struct adm8211_priv *priv = dev->priv;
1319 1320
1321 if (!(changes & BSS_CHANGED_BSSID))
1322 return;
1323
1320 if (memcmp(conf->bssid, priv->bssid, ETH_ALEN)) { 1324 if (memcmp(conf->bssid, priv->bssid, ETH_ALEN)) {
1321 adm8211_set_bssid(dev, conf->bssid); 1325 adm8211_set_bssid(dev, conf->bssid);
1322 memcpy(priv->bssid, conf->bssid, ETH_ALEN); 1326 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
1323 } 1327 }
1324
1325 return 0;
1326} 1328}
1327 1329
1328static void adm8211_configure_filter(struct ieee80211_hw *dev, 1330static void adm8211_configure_filter(struct ieee80211_hw *dev,
@@ -1753,7 +1755,7 @@ static const struct ieee80211_ops adm8211_ops = {
1753 .add_interface = adm8211_add_interface, 1755 .add_interface = adm8211_add_interface,
1754 .remove_interface = adm8211_remove_interface, 1756 .remove_interface = adm8211_remove_interface,
1755 .config = adm8211_config, 1757 .config = adm8211_config,
1756 .config_interface = adm8211_config_interface, 1758 .bss_info_changed = adm8211_bss_info_changed,
1757 .configure_filter = adm8211_configure_filter, 1759 .configure_filter = adm8211_configure_filter,
1758 .get_stats = adm8211_get_stats, 1760 .get_stats = adm8211_get_stats,
1759 .get_tx_stats = adm8211_get_tx_stats, 1761 .get_tx_stats = adm8211_get_tx_stats,
diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
index 55f947ac56d1..cea7f1466c54 100644
--- a/drivers/net/wireless/at76c50x-usb.c
+++ b/drivers/net/wireless/at76c50x-usb.c
@@ -1965,13 +1965,18 @@ static int at76_config(struct ieee80211_hw *hw, u32 changed)
1965 return 0; 1965 return 0;
1966} 1966}
1967 1967
1968static int at76_config_interface(struct ieee80211_hw *hw, 1968static void at76_bss_info_changed(struct ieee80211_hw *hw,
1969 struct ieee80211_vif *vif, 1969 struct ieee80211_vif *vif,
1970 struct ieee80211_if_conf *conf) 1970 struct ieee80211_bss_conf *conf,
1971 u32 changed)
1971{ 1972{
1972 struct at76_priv *priv = hw->priv; 1973 struct at76_priv *priv = hw->priv;
1973 1974
1974 at76_dbg(DBG_MAC80211, "%s():", __func__); 1975 at76_dbg(DBG_MAC80211, "%s():", __func__);
1976
1977 if (!(changed & BSS_CHANGED_BSSID))
1978 return;
1979
1975 at76_dbg_dump(DBG_MAC80211, conf->bssid, ETH_ALEN, "bssid:"); 1980 at76_dbg_dump(DBG_MAC80211, conf->bssid, ETH_ALEN, "bssid:");
1976 1981
1977 mutex_lock(&priv->mtx); 1982 mutex_lock(&priv->mtx);
@@ -1983,8 +1988,6 @@ static int at76_config_interface(struct ieee80211_hw *hw,
1983 at76_join(priv); 1988 at76_join(priv);
1984 1989
1985 mutex_unlock(&priv->mtx); 1990 mutex_unlock(&priv->mtx);
1986
1987 return 0;
1988} 1991}
1989 1992
1990/* must be atomic */ 1993/* must be atomic */
@@ -2076,7 +2079,7 @@ static const struct ieee80211_ops at76_ops = {
2076 .add_interface = at76_add_interface, 2079 .add_interface = at76_add_interface,
2077 .remove_interface = at76_remove_interface, 2080 .remove_interface = at76_remove_interface,
2078 .config = at76_config, 2081 .config = at76_config,
2079 .config_interface = at76_config_interface, 2082 .bss_info_changed = at76_bss_info_changed,
2080 .configure_filter = at76_configure_filter, 2083 .configure_filter = at76_configure_filter,
2081 .start = at76_mac80211_start, 2084 .start = at76_mac80211_start,
2082 .stop = at76_mac80211_stop, 2085 .stop = at76_mac80211_stop,
diff --git a/drivers/net/wireless/ath/ar9170/hw.h b/drivers/net/wireless/ath/ar9170/hw.h
index 95bf812d6fcc..3293e0fb24fb 100644
--- a/drivers/net/wireless/ath/ar9170/hw.h
+++ b/drivers/net/wireless/ath/ar9170/hw.h
@@ -207,6 +207,8 @@ enum ar9170_cmd {
207#define AR9170_MAC_REG_AC1_AC0_TXOP (AR9170_MAC_REG_BASE + 0xB44) 207#define AR9170_MAC_REG_AC1_AC0_TXOP (AR9170_MAC_REG_BASE + 0xB44)
208#define AR9170_MAC_REG_AC3_AC2_TXOP (AR9170_MAC_REG_BASE + 0xB48) 208#define AR9170_MAC_REG_AC3_AC2_TXOP (AR9170_MAC_REG_BASE + 0xB48)
209 209
210#define AR9170_MAC_REG_AMPDU_SET (AR9170_MAC_REG_BASE + 0xba0)
211
210#define AR9170_MAC_REG_ACK_TABLE (AR9170_MAC_REG_BASE + 0xC00) 212#define AR9170_MAC_REG_ACK_TABLE (AR9170_MAC_REG_BASE + 0xC00)
211#define AR9170_MAC_REG_AMPDU_RX_THRESH (AR9170_MAC_REG_BASE + 0xC50) 213#define AR9170_MAC_REG_AMPDU_RX_THRESH (AR9170_MAC_REG_BASE + 0xC50)
212 214
diff --git a/drivers/net/wireless/ath/ar9170/mac.c b/drivers/net/wireless/ath/ar9170/mac.c
index c8fa3073169f..43aeb69685d3 100644
--- a/drivers/net/wireless/ath/ar9170/mac.c
+++ b/drivers/net/wireless/ath/ar9170/mac.c
@@ -72,6 +72,24 @@ int ar9170_set_qos(struct ar9170 *ar)
72 return ar9170_regwrite_result(); 72 return ar9170_regwrite_result();
73} 73}
74 74
75static int ar9170_set_ampdu_density(struct ar9170 *ar, u8 mpdudensity)
76{
77 u32 val;
78
79 /* don't allow AMPDU density > 8us */
80 if (mpdudensity > 6)
81 return -EINVAL;
82
83 /* Watch out! Otus uses slightly different density values. */
84 val = 0x140a00 | (mpdudensity ? (mpdudensity + 1) : 0);
85
86 ar9170_regwrite_begin(ar);
87 ar9170_regwrite(AR9170_MAC_REG_AMPDU_SET, val);
88 ar9170_regwrite_finish();
89
90 return ar9170_regwrite_result();
91}
92
75int ar9170_init_mac(struct ar9170 *ar) 93int ar9170_init_mac(struct ar9170 *ar)
76{ 94{
77 ar9170_regwrite_begin(ar); 95 ar9170_regwrite_begin(ar);
@@ -265,9 +283,9 @@ int ar9170_set_operating_mode(struct ar9170 *ar)
265 case NL80211_IFTYPE_ADHOC: 283 case NL80211_IFTYPE_ADHOC:
266 pm_mode |= AR9170_MAC_REG_POWERMGT_IBSS; 284 pm_mode |= AR9170_MAC_REG_POWERMGT_IBSS;
267 break; 285 break;
268/* case NL80211_IFTYPE_AP: 286 case NL80211_IFTYPE_AP:
269 pm_mode |= AR9170_MAC_REG_POWERMGT_AP; 287 pm_mode |= AR9170_MAC_REG_POWERMGT_AP;
270 break;*/ 288 break;
271 case NL80211_IFTYPE_WDS: 289 case NL80211_IFTYPE_WDS:
272 pm_mode |= AR9170_MAC_REG_POWERMGT_AP_WDS; 290 pm_mode |= AR9170_MAC_REG_POWERMGT_AP_WDS;
273 break; 291 break;
@@ -296,6 +314,11 @@ int ar9170_set_operating_mode(struct ar9170 *ar)
296 if (err) 314 if (err)
297 return err; 315 return err;
298 316
317 /* set AMPDU density to 8us. */
318 err = ar9170_set_ampdu_density(ar, 6);
319 if (err)
320 return err;
321
299 ar9170_regwrite_begin(ar); 322 ar9170_regwrite_begin(ar);
300 323
301 ar9170_regwrite(AR9170_MAC_REG_POWERMANAGEMENT, pm_mode); 324 ar9170_regwrite(AR9170_MAC_REG_POWERMANAGEMENT, pm_mode);
@@ -316,9 +339,9 @@ int ar9170_set_beacon_timers(struct ar9170 *ar)
316 u32 v = 0; 339 u32 v = 0;
317 u32 pretbtt = 0; 340 u32 pretbtt = 0;
318 341
319 v |= ar->hw->conf.beacon_int;
320
321 if (ar->vif) { 342 if (ar->vif) {
343 v |= ar->vif->bss_conf.beacon_int;
344
322 switch (ar->vif->type) { 345 switch (ar->vif->type) {
323 case NL80211_IFTYPE_MESH_POINT: 346 case NL80211_IFTYPE_MESH_POINT:
324 case NL80211_IFTYPE_ADHOC: 347 case NL80211_IFTYPE_ADHOC:
@@ -326,7 +349,7 @@ int ar9170_set_beacon_timers(struct ar9170 *ar)
326 break; 349 break;
327 case NL80211_IFTYPE_AP: 350 case NL80211_IFTYPE_AP:
328 v |= BIT(24); 351 v |= BIT(24);
329 pretbtt = (ar->hw->conf.beacon_int - 6) << 16; 352 pretbtt = (ar->vif->bss_conf.beacon_int - 6) << 16;
330 break; 353 break;
331 default: 354 default:
332 break; 355 break;
diff --git a/drivers/net/wireless/ath/ar9170/main.c b/drivers/net/wireless/ath/ar9170/main.c
index 1b60906b80c9..4ef1d2fc859c 100644
--- a/drivers/net/wireless/ath/ar9170/main.c
+++ b/drivers/net/wireless/ath/ar9170/main.c
@@ -151,8 +151,8 @@ static struct ieee80211_channel ar9170_5ghz_chantable[] = {
151 IEEE80211_HT_CAP_SGI_40 | \ 151 IEEE80211_HT_CAP_SGI_40 | \
152 IEEE80211_HT_CAP_DSSSCCK40 | \ 152 IEEE80211_HT_CAP_DSSSCCK40 | \
153 IEEE80211_HT_CAP_SM_PS, \ 153 IEEE80211_HT_CAP_SM_PS, \
154 .ampdu_factor = 3, /* ?? */ \ 154 .ampdu_factor = 3, \
155 .ampdu_density = 7, /* ?? */ \ 155 .ampdu_density = 6, \
156 .mcs = { \ 156 .mcs = { \
157 .rx_mask = { 0xFF, 0xFF, 0, 0, 0, 0, 0, 0, 0, 0, }, \ 157 .rx_mask = { 0xFF, 0xFF, 0, 0, 0, 0, 0, 0, 0, 0, }, \
158 }, \ 158 }, \
@@ -1337,7 +1337,7 @@ static int ar9170_op_config(struct ieee80211_hw *hw, u32 changed)
1337 goto out; 1337 goto out;
1338 } 1338 }
1339 1339
1340 if (changed & IEEE80211_CONF_CHANGE_BEACON_INTERVAL) { 1340 if (changed & BSS_CHANGED_BEACON_INT) {
1341 err = ar9170_set_beacon_timers(ar); 1341 err = ar9170_set_beacon_timers(ar);
1342 if (err) 1342 if (err)
1343 goto out; 1343 goto out;
@@ -1360,33 +1360,6 @@ out:
1360 return err; 1360 return err;
1361} 1361}
1362 1362
1363static int ar9170_op_config_interface(struct ieee80211_hw *hw,
1364 struct ieee80211_vif *vif,
1365 struct ieee80211_if_conf *conf)
1366{
1367 struct ar9170 *ar = hw->priv;
1368 int err = 0;
1369
1370 mutex_lock(&ar->mutex);
1371
1372 if (conf->changed & IEEE80211_IFCC_BSSID) {
1373 memcpy(ar->bssid, conf->bssid, ETH_ALEN);
1374 err = ar9170_set_operating_mode(ar);
1375 }
1376
1377 if (conf->changed & IEEE80211_IFCC_BEACON) {
1378 err = ar9170_update_beacon(ar);
1379
1380 if (err)
1381 goto out;
1382 err = ar9170_set_beacon_timers(ar);
1383 }
1384
1385out:
1386 mutex_unlock(&ar->mutex);
1387 return err;
1388}
1389
1390static void ar9170_set_filters(struct work_struct *work) 1363static void ar9170_set_filters(struct work_struct *work)
1391{ 1364{
1392 struct ar9170 *ar = container_of(work, struct ar9170, 1365 struct ar9170 *ar = container_of(work, struct ar9170,
@@ -1488,6 +1461,17 @@ static void ar9170_op_bss_info_changed(struct ieee80211_hw *hw,
1488 1461
1489 mutex_lock(&ar->mutex); 1462 mutex_lock(&ar->mutex);
1490 1463
1464 if (changed & BSS_CHANGED_BSSID) {
1465 memcpy(ar->bssid, bss_conf->bssid, ETH_ALEN);
1466 err = ar9170_set_operating_mode(ar);
1467 }
1468
1469 if (changed & (BSS_CHANGED_BEACON | BSS_CHANGED_BEACON_ENABLED)) {
1470 err = ar9170_update_beacon(ar);
1471 if (!err)
1472 ar9170_set_beacon_timers(ar);
1473 }
1474
1491 ar9170_regwrite_begin(ar); 1475 ar9170_regwrite_begin(ar);
1492 1476
1493 if (changed & BSS_CHANGED_ASSOC) { 1477 if (changed & BSS_CHANGED_ASSOC) {
@@ -1499,6 +1483,9 @@ static void ar9170_op_bss_info_changed(struct ieee80211_hw *hw,
1499#endif /* CONFIG_AR9170_LEDS */ 1483#endif /* CONFIG_AR9170_LEDS */
1500 } 1484 }
1501 1485
1486 if (changed & BSS_CHANGED_BEACON_INT)
1487 err = ar9170_set_beacon_timers(ar);
1488
1502 if (changed & BSS_CHANGED_HT) { 1489 if (changed & BSS_CHANGED_HT) {
1503 /* TODO */ 1490 /* TODO */
1504 err = 0; 1491 err = 0;
@@ -1793,7 +1780,6 @@ static const struct ieee80211_ops ar9170_ops = {
1793 .add_interface = ar9170_op_add_interface, 1780 .add_interface = ar9170_op_add_interface,
1794 .remove_interface = ar9170_op_remove_interface, 1781 .remove_interface = ar9170_op_remove_interface,
1795 .config = ar9170_op_config, 1782 .config = ar9170_op_config,
1796 .config_interface = ar9170_op_config_interface,
1797 .configure_filter = ar9170_op_configure_filter, 1783 .configure_filter = ar9170_op_configure_filter,
1798 .conf_tx = ar9170_conf_tx, 1784 .conf_tx = ar9170_conf_tx,
1799 .bss_info_changed = ar9170_op_bss_info_changed, 1785 .bss_info_changed = ar9170_op_bss_info_changed,
diff --git a/drivers/net/wireless/ath/ar9170/usb.c b/drivers/net/wireless/ath/ar9170/usb.c
index fddda477095c..d7c13c0177ca 100644
--- a/drivers/net/wireless/ath/ar9170/usb.c
+++ b/drivers/net/wireless/ath/ar9170/usb.c
@@ -350,7 +350,7 @@ static int ar9170_usb_exec_cmd(struct ar9170 *ar, enum ar9170_cmd cmd,
350 goto err_unbuf; 350 goto err_unbuf;
351 } 351 }
352 352
353 if (outlen >= 0 && aru->readlen != outlen) { 353 if (aru->readlen != outlen) {
354 err = -EMSGSIZE; 354 err = -EMSGSIZE;
355 goto err_unbuf; 355 goto err_unbuf;
356 } 356 }
@@ -689,6 +689,9 @@ static int ar9170_usb_probe(struct usb_interface *intf,
689 aru->common.exec_cmd = ar9170_usb_exec_cmd; 689 aru->common.exec_cmd = ar9170_usb_exec_cmd;
690 aru->common.callback_cmd = ar9170_usb_callback_cmd; 690 aru->common.callback_cmd = ar9170_usb_callback_cmd;
691 691
692#ifdef CONFIG_PM
693 udev->reset_resume = 1;
694#endif
692 err = ar9170_usb_reset(aru); 695 err = ar9170_usb_reset(aru);
693 if (err) 696 if (err)
694 goto err_freehw; 697 goto err_freehw;
@@ -805,6 +808,7 @@ static struct usb_driver ar9170_driver = {
805#ifdef CONFIG_PM 808#ifdef CONFIG_PM
806 .suspend = ar9170_suspend, 809 .suspend = ar9170_suspend,
807 .resume = ar9170_resume, 810 .resume = ar9170_resume,
811 .reset_resume = ar9170_resume,
808#endif /* CONFIG_PM */ 812#endif /* CONFIG_PM */
809}; 813};
810 814
diff --git a/drivers/net/wireless/ath/ath5k/ath5k.h b/drivers/net/wireless/ath/ath5k/ath5k.h
index 60c6d2edc4b9..813718210338 100644
--- a/drivers/net/wireless/ath/ath5k/ath5k.h
+++ b/drivers/net/wireless/ath/ath5k/ath5k.h
@@ -209,7 +209,6 @@
209#define AR5K_TUNE_MAX_TXPOWER 63 209#define AR5K_TUNE_MAX_TXPOWER 63
210#define AR5K_TUNE_DEFAULT_TXPOWER 25 210#define AR5K_TUNE_DEFAULT_TXPOWER 25
211#define AR5K_TUNE_TPC_TXPOWER false 211#define AR5K_TUNE_TPC_TXPOWER false
212#define AR5K_TUNE_ANT_DIVERSITY true
213#define AR5K_TUNE_HWTXTRIES 4 212#define AR5K_TUNE_HWTXTRIES 4
214 213
215#define AR5K_INIT_CARR_SENSE_EN 1 214#define AR5K_INIT_CARR_SENSE_EN 1
@@ -420,6 +419,17 @@ enum ath5k_driver_mode {
420 AR5K_MODE_MAX = 5 419 AR5K_MODE_MAX = 5
421}; 420};
422 421
422enum ath5k_ant_mode {
423 AR5K_ANTMODE_DEFAULT = 0, /* default antenna setup */
424 AR5K_ANTMODE_FIXED_A = 1, /* only antenna A is present */
425 AR5K_ANTMODE_FIXED_B = 2, /* only antenna B is present */
426 AR5K_ANTMODE_SINGLE_AP = 3, /* sta locked on a single ap */
427 AR5K_ANTMODE_SECTOR_AP = 4, /* AP with tx antenna set on tx desc */
428 AR5K_ANTMODE_SECTOR_STA = 5, /* STA with tx antenna set on tx desc */
429 AR5K_ANTMODE_DEBUG = 6, /* Debug mode -A -> Rx, B-> Tx- */
430 AR5K_ANTMODE_MAX,
431};
432
423 433
424/****************\ 434/****************\
425 TX DEFINITIONS 435 TX DEFINITIONS
@@ -1051,8 +1061,11 @@ struct ath5k_hw {
1051 bool ah_software_retry; 1061 bool ah_software_retry;
1052 u32 ah_limit_tx_retries; 1062 u32 ah_limit_tx_retries;
1053 1063
1054 u32 ah_antenna[AR5K_EEPROM_N_MODES][AR5K_ANT_MAX]; 1064 /* Antenna Control */
1055 bool ah_ant_diversity; 1065 u32 ah_ant_ctl[AR5K_EEPROM_N_MODES][AR5K_ANT_MAX];
1066 u8 ah_ant_mode;
1067 u8 ah_tx_ant;
1068 u8 ah_def_ant;
1056 1069
1057 u8 ah_sta_id[ETH_ALEN]; 1070 u8 ah_sta_id[ETH_ALEN];
1058 1071
@@ -1100,11 +1113,12 @@ struct ath5k_hw {
1100 /* Values in 0.25dB units */ 1113 /* Values in 0.25dB units */
1101 s16 txp_min_pwr; 1114 s16 txp_min_pwr;
1102 s16 txp_max_pwr; 1115 s16 txp_max_pwr;
1116 /* Values in 0.5dB units */
1103 s16 txp_offset; 1117 s16 txp_offset;
1104 s16 txp_ofdm; 1118 s16 txp_ofdm;
1105 /* Values in dB units */
1106 s16 txp_cck_ofdm_pwr_delta;
1107 s16 txp_cck_ofdm_gainf_delta; 1119 s16 txp_cck_ofdm_gainf_delta;
1120 /* Value in dB units */
1121 s16 txp_cck_ofdm_pwr_delta;
1108 } ah_txpower; 1122 } ah_txpower;
1109 1123
1110 struct { 1124 struct {
@@ -1264,14 +1278,21 @@ extern int ath5k_hw_channel(struct ath5k_hw *ah, struct ieee80211_channel *chann
1264/* PHY calibration */ 1278/* PHY calibration */
1265extern int ath5k_hw_phy_calibrate(struct ath5k_hw *ah, struct ieee80211_channel *channel); 1279extern int ath5k_hw_phy_calibrate(struct ath5k_hw *ah, struct ieee80211_channel *channel);
1266extern int ath5k_hw_noise_floor_calibration(struct ath5k_hw *ah, short freq); 1280extern int ath5k_hw_noise_floor_calibration(struct ath5k_hw *ah, short freq);
1281/* Spur mitigation */
1282bool ath5k_hw_chan_has_spur_noise(struct ath5k_hw *ah,
1283 struct ieee80211_channel *channel);
1284void ath5k_hw_set_spur_mitigation_filter(struct ath5k_hw *ah,
1285 struct ieee80211_channel *channel);
1267/* Misc PHY functions */ 1286/* Misc PHY functions */
1268extern u16 ath5k_hw_radio_revision(struct ath5k_hw *ah, unsigned int chan); 1287extern u16 ath5k_hw_radio_revision(struct ath5k_hw *ah, unsigned int chan);
1269extern void ath5k_hw_set_def_antenna(struct ath5k_hw *ah, unsigned int ant);
1270extern unsigned int ath5k_hw_get_def_antenna(struct ath5k_hw *ah);
1271extern int ath5k_hw_phy_disable(struct ath5k_hw *ah); 1288extern int ath5k_hw_phy_disable(struct ath5k_hw *ah);
1289/* Antenna control */
1290extern void ath5k_hw_set_antenna_mode(struct ath5k_hw *ah, u8 ant_mode);
1291extern void ath5k_hw_set_def_antenna(struct ath5k_hw *ah, u8 ant);
1292extern unsigned int ath5k_hw_get_def_antenna(struct ath5k_hw *ah);
1272/* TX power setup */ 1293/* TX power setup */
1273extern int ath5k_hw_txpower(struct ath5k_hw *ah, struct ieee80211_channel *channel, u8 ee_mode, u8 txpower); 1294extern int ath5k_hw_txpower(struct ath5k_hw *ah, struct ieee80211_channel *channel, u8 ee_mode, u8 txpower);
1274extern int ath5k_hw_set_txpower_limit(struct ath5k_hw *ah, u8 ee_mode, u8 txpower); 1295extern int ath5k_hw_set_txpower_limit(struct ath5k_hw *ah, u8 txpower);
1275 1296
1276/* 1297/*
1277 * Functions used internaly 1298 * Functions used internaly
diff --git a/drivers/net/wireless/ath/ath5k/attach.c b/drivers/net/wireless/ath/ath5k/attach.c
index 70d376c63aac..c41ef58393e7 100644
--- a/drivers/net/wireless/ath/ath5k/attach.c
+++ b/drivers/net/wireless/ath/ath5k/attach.c
@@ -133,7 +133,6 @@ struct ath5k_hw *ath5k_hw_attach(struct ath5k_softc *sc, u8 mac_version)
133 ah->ah_cw_min = AR5K_TUNE_CWMIN; 133 ah->ah_cw_min = AR5K_TUNE_CWMIN;
134 ah->ah_limit_tx_retries = AR5K_INIT_TX_RETRY; 134 ah->ah_limit_tx_retries = AR5K_INIT_TX_RETRY;
135 ah->ah_software_retry = false; 135 ah->ah_software_retry = false;
136 ah->ah_ant_diversity = AR5K_TUNE_ANT_DIVERSITY;
137 136
138 /* 137 /*
139 * Set the mac version based on the pci id 138 * Set the mac version based on the pci id
diff --git a/drivers/net/wireless/ath/ath5k/base.c b/drivers/net/wireless/ath/ath5k/base.c
index c8c658bfcf9d..6789c5dfcc76 100644
--- a/drivers/net/wireless/ath/ath5k/base.c
+++ b/drivers/net/wireless/ath/ath5k/base.c
@@ -227,9 +227,6 @@ static int ath5k_add_interface(struct ieee80211_hw *hw,
227static void ath5k_remove_interface(struct ieee80211_hw *hw, 227static void ath5k_remove_interface(struct ieee80211_hw *hw,
228 struct ieee80211_if_init_conf *conf); 228 struct ieee80211_if_init_conf *conf);
229static int ath5k_config(struct ieee80211_hw *hw, u32 changed); 229static int ath5k_config(struct ieee80211_hw *hw, u32 changed);
230static int ath5k_config_interface(struct ieee80211_hw *hw,
231 struct ieee80211_vif *vif,
232 struct ieee80211_if_conf *conf);
233static void ath5k_configure_filter(struct ieee80211_hw *hw, 230static void ath5k_configure_filter(struct ieee80211_hw *hw,
234 unsigned int changed_flags, 231 unsigned int changed_flags,
235 unsigned int *new_flags, 232 unsigned int *new_flags,
@@ -259,7 +256,6 @@ static const struct ieee80211_ops ath5k_hw_ops = {
259 .add_interface = ath5k_add_interface, 256 .add_interface = ath5k_add_interface,
260 .remove_interface = ath5k_remove_interface, 257 .remove_interface = ath5k_remove_interface,
261 .config = ath5k_config, 258 .config = ath5k_config,
262 .config_interface = ath5k_config_interface,
263 .configure_filter = ath5k_configure_filter, 259 .configure_filter = ath5k_configure_filter,
264 .set_key = ath5k_set_key, 260 .set_key = ath5k_set_key,
265 .get_stats = ath5k_get_stats, 261 .get_stats = ath5k_get_stats,
@@ -520,6 +516,7 @@ ath5k_pci_probe(struct pci_dev *pdev,
520 IEEE80211_HW_NOISE_DBM; 516 IEEE80211_HW_NOISE_DBM;
521 517
522 hw->wiphy->interface_modes = 518 hw->wiphy->interface_modes =
519 BIT(NL80211_IFTYPE_AP) |
523 BIT(NL80211_IFTYPE_STATION) | 520 BIT(NL80211_IFTYPE_STATION) |
524 BIT(NL80211_IFTYPE_ADHOC) | 521 BIT(NL80211_IFTYPE_ADHOC) |
525 BIT(NL80211_IFTYPE_MESH_POINT); 522 BIT(NL80211_IFTYPE_MESH_POINT);
@@ -1282,7 +1279,7 @@ ath5k_txbuf_setup(struct ath5k_softc *sc, struct ath5k_buf *bf)
1282 ieee80211_get_hdrlen_from_skb(skb), AR5K_PKT_TYPE_NORMAL, 1279 ieee80211_get_hdrlen_from_skb(skb), AR5K_PKT_TYPE_NORMAL,
1283 (sc->power_level * 2), 1280 (sc->power_level * 2),
1284 hw_rate, 1281 hw_rate,
1285 info->control.rates[0].count, keyidx, 0, flags, 1282 info->control.rates[0].count, keyidx, ah->ah_tx_ant, flags,
1286 cts_rate, duration); 1283 cts_rate, duration);
1287 if (ret) 1284 if (ret)
1288 goto err_unmap; 1285 goto err_unmap;
@@ -1742,35 +1739,6 @@ ath5k_check_ibss_tsf(struct ath5k_softc *sc, struct sk_buff *skb,
1742 } 1739 }
1743} 1740}
1744 1741
1745static void ath5k_tasklet_beacon(unsigned long data)
1746{
1747 struct ath5k_softc *sc = (struct ath5k_softc *) data;
1748
1749 /*
1750 * Software beacon alert--time to send a beacon.
1751 *
1752 * In IBSS mode we use this interrupt just to
1753 * keep track of the next TBTT (target beacon
1754 * transmission time) in order to detect wether
1755 * automatic TSF updates happened.
1756 */
1757 if (sc->opmode == NL80211_IFTYPE_ADHOC) {
1758 /* XXX: only if VEOL suppported */
1759 u64 tsf = ath5k_hw_get_tsf64(sc->ah);
1760 sc->nexttbtt += sc->bintval;
1761 ATH5K_DBG(sc, ATH5K_DEBUG_BEACON,
1762 "SWBA nexttbtt: %x hw_tu: %x "
1763 "TSF: %llx\n",
1764 sc->nexttbtt,
1765 TSF_TO_TU(tsf),
1766 (unsigned long long) tsf);
1767 } else {
1768 spin_lock(&sc->block);
1769 ath5k_beacon_send(sc);
1770 spin_unlock(&sc->block);
1771 }
1772}
1773
1774static void 1742static void
1775ath5k_tasklet_rx(unsigned long data) 1743ath5k_tasklet_rx(unsigned long data)
1776{ 1744{
@@ -2041,7 +2009,8 @@ ath5k_beacon_setup(struct ath5k_softc *sc, struct ath5k_buf *bf)
2041 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 2009 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2042 struct ath5k_hw *ah = sc->ah; 2010 struct ath5k_hw *ah = sc->ah;
2043 struct ath5k_desc *ds; 2011 struct ath5k_desc *ds;
2044 int ret, antenna = 0; 2012 int ret = 0;
2013 u8 antenna;
2045 u32 flags; 2014 u32 flags;
2046 2015
2047 bf->skbaddr = pci_map_single(sc->pdev, skb->data, skb->len, 2016 bf->skbaddr = pci_map_single(sc->pdev, skb->data, skb->len,
@@ -2055,23 +2024,35 @@ ath5k_beacon_setup(struct ath5k_softc *sc, struct ath5k_buf *bf)
2055 } 2024 }
2056 2025
2057 ds = bf->desc; 2026 ds = bf->desc;
2027 antenna = ah->ah_tx_ant;
2058 2028
2059 flags = AR5K_TXDESC_NOACK; 2029 flags = AR5K_TXDESC_NOACK;
2060 if (sc->opmode == NL80211_IFTYPE_ADHOC && ath5k_hw_hasveol(ah)) { 2030 if (sc->opmode == NL80211_IFTYPE_ADHOC && ath5k_hw_hasveol(ah)) {
2061 ds->ds_link = bf->daddr; /* self-linked */ 2031 ds->ds_link = bf->daddr; /* self-linked */
2062 flags |= AR5K_TXDESC_VEOL; 2032 flags |= AR5K_TXDESC_VEOL;
2063 /* 2033 } else
2064 * Let hardware handle antenna switching if txantenna is not set
2065 */
2066 } else {
2067 ds->ds_link = 0; 2034 ds->ds_link = 0;
2068 /* 2035
2069 * Switch antenna every 4 beacons if txantenna is not set 2036 /*
2070 * XXX assumes two antennas 2037 * If we use multiple antennas on AP and use
2071 */ 2038 * the Sectored AP scenario, switch antenna every
2072 if (antenna == 0) 2039 * 4 beacons to make sure everybody hears our AP.
2073 antenna = sc->bsent & 4 ? 2 : 1; 2040 * When a client tries to associate, hw will keep
2074 } 2041 * track of the tx antenna to be used for this client
2042 * automaticaly, based on ACKed packets.
2043 *
2044 * Note: AP still listens and transmits RTS on the
2045 * default antenna which is supposed to be an omni.
2046 *
2047 * Note2: On sectored scenarios it's possible to have
2048 * multiple antennas (1omni -the default- and 14 sectors)
2049 * so if we choose to actually support this mode we need
2050 * to allow user to set how many antennas we have and tweak
2051 * the code below to send beacons on all of them.
2052 */
2053 if (ah->ah_ant_mode == AR5K_ANTMODE_SECTOR_AP)
2054 antenna = sc->bsent & 4 ? 2 : 1;
2055
2075 2056
2076 /* FIXME: If we are in g mode and rate is a CCK rate 2057 /* FIXME: If we are in g mode and rate is a CCK rate
2077 * subtract ah->ah_txpower.txp_cck_ofdm_pwr_delta 2058 * subtract ah->ah_txpower.txp_cck_ofdm_pwr_delta
@@ -2124,7 +2105,7 @@ ath5k_beacon_send(struct ath5k_softc *sc)
2124 sc->bmisscount++; 2105 sc->bmisscount++;
2125 ATH5K_DBG(sc, ATH5K_DEBUG_BEACON, 2106 ATH5K_DBG(sc, ATH5K_DEBUG_BEACON,
2126 "missed %u consecutive beacons\n", sc->bmisscount); 2107 "missed %u consecutive beacons\n", sc->bmisscount);
2127 if (sc->bmisscount > 3) { /* NB: 3 is a guess */ 2108 if (sc->bmisscount > 10) { /* NB: 10 is a guess */
2128 ATH5K_DBG(sc, ATH5K_DEBUG_BEACON, 2109 ATH5K_DBG(sc, ATH5K_DEBUG_BEACON,
2129 "stuck beacon time (%u missed)\n", 2110 "stuck beacon time (%u missed)\n",
2130 sc->bmisscount); 2111 sc->bmisscount);
@@ -2145,10 +2126,12 @@ ath5k_beacon_send(struct ath5k_softc *sc)
2145 * are still pending on the queue. 2126 * are still pending on the queue.
2146 */ 2127 */
2147 if (unlikely(ath5k_hw_stop_tx_dma(ah, sc->bhalq))) { 2128 if (unlikely(ath5k_hw_stop_tx_dma(ah, sc->bhalq))) {
2148 ATH5K_WARN(sc, "beacon queue %u didn't stop?\n", sc->bhalq); 2129 ATH5K_WARN(sc, "beacon queue %u didn't start/stop ?\n", sc->bhalq);
2149 /* NB: hw still stops DMA, so proceed */ 2130 /* NB: hw still stops DMA, so proceed */
2150 } 2131 }
2151 2132
2133 /* Note: Beacon buffer is updated on beacon_update when mac80211
2134 * calls config_interface */
2152 ath5k_hw_set_txdp(ah, sc->bhalq, bf->daddr); 2135 ath5k_hw_set_txdp(ah, sc->bhalq, bf->daddr);
2153 ath5k_hw_start_tx_dma(ah, sc->bhalq); 2136 ath5k_hw_start_tx_dma(ah, sc->bhalq);
2154 ATH5K_DBG(sc, ATH5K_DEBUG_BEACON, "TXDP[%u] = %llx (%p)\n", 2137 ATH5K_DBG(sc, ATH5K_DEBUG_BEACON, "TXDP[%u] = %llx (%p)\n",
@@ -2305,6 +2288,35 @@ ath5k_beacon_config(struct ath5k_softc *sc)
2305 ath5k_hw_set_imr(ah, sc->imask); 2288 ath5k_hw_set_imr(ah, sc->imask);
2306} 2289}
2307 2290
2291static void ath5k_tasklet_beacon(unsigned long data)
2292{
2293 struct ath5k_softc *sc = (struct ath5k_softc *) data;
2294
2295 /*
2296 * Software beacon alert--time to send a beacon.
2297 *
2298 * In IBSS mode we use this interrupt just to
2299 * keep track of the next TBTT (target beacon
2300 * transmission time) in order to detect wether
2301 * automatic TSF updates happened.
2302 */
2303 if (sc->opmode == NL80211_IFTYPE_ADHOC) {
2304 /* XXX: only if VEOL suppported */
2305 u64 tsf = ath5k_hw_get_tsf64(sc->ah);
2306 sc->nexttbtt += sc->bintval;
2307 ATH5K_DBG(sc, ATH5K_DEBUG_BEACON,
2308 "SWBA nexttbtt: %x hw_tu: %x "
2309 "TSF: %llx\n",
2310 sc->nexttbtt,
2311 TSF_TO_TU(tsf),
2312 (unsigned long long) tsf);
2313 } else {
2314 spin_lock(&sc->block);
2315 ath5k_beacon_send(sc);
2316 spin_unlock(&sc->block);
2317 }
2318}
2319
2308 2320
2309/********************\ 2321/********************\
2310* Interrupt handling * 2322* Interrupt handling *
@@ -2509,7 +2521,7 @@ ath5k_intr(int irq, void *dev_id)
2509 ath5k_hw_update_mib_counters(ah, &sc->ll_stats); 2521 ath5k_hw_update_mib_counters(ah, &sc->ll_stats);
2510 } 2522 }
2511 } 2523 }
2512 } while (ath5k_hw_is_intr_pending(ah) && counter-- > 0); 2524 } while (ath5k_hw_is_intr_pending(ah) && --counter > 0);
2513 2525
2514 if (unlikely(!counter)) 2526 if (unlikely(!counter))
2515 ATH5K_WARN(sc, "too many interrupts, giving up for now\n"); 2527 ATH5K_WARN(sc, "too many interrupts, giving up for now\n");
@@ -2751,56 +2763,47 @@ static int
2751ath5k_config(struct ieee80211_hw *hw, u32 changed) 2763ath5k_config(struct ieee80211_hw *hw, u32 changed)
2752{ 2764{
2753 struct ath5k_softc *sc = hw->priv; 2765 struct ath5k_softc *sc = hw->priv;
2766 struct ath5k_hw *ah = sc->ah;
2754 struct ieee80211_conf *conf = &hw->conf; 2767 struct ieee80211_conf *conf = &hw->conf;
2755 int ret; 2768 int ret = 0;
2756 2769
2757 mutex_lock(&sc->lock); 2770 mutex_lock(&sc->lock);
2758 2771
2759 sc->bintval = conf->beacon_int; 2772 sc->bintval = conf->beacon_int;
2760 sc->power_level = conf->power_level;
2761 2773
2762 ret = ath5k_chan_set(sc, conf->channel); 2774 ret = ath5k_chan_set(sc, conf->channel);
2775 if (ret < 0)
2776 return ret;
2763 2777
2764 mutex_unlock(&sc->lock); 2778 if ((changed & IEEE80211_CONF_CHANGE_POWER) &&
2765 return ret; 2779 (sc->power_level != conf->power_level)) {
2766} 2780 sc->power_level = conf->power_level;
2767
2768static int
2769ath5k_config_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2770 struct ieee80211_if_conf *conf)
2771{
2772 struct ath5k_softc *sc = hw->priv;
2773 struct ath5k_hw *ah = sc->ah;
2774 int ret = 0;
2775 2781
2776 mutex_lock(&sc->lock); 2782 /* Half dB steps */
2777 if (sc->vif != vif) { 2783 ath5k_hw_set_txpower_limit(ah, (conf->power_level * 2));
2778 ret = -EIO;
2779 goto unlock;
2780 }
2781 if (conf->changed & IEEE80211_IFCC_BSSID && conf->bssid) {
2782 /* Cache for later use during resets */
2783 memcpy(ah->ah_bssid, conf->bssid, ETH_ALEN);
2784 /* XXX: assoc id is set to 0 for now, mac80211 doesn't have
2785 * a clean way of letting us retrieve this yet. */
2786 ath5k_hw_set_associd(ah, ah->ah_bssid, 0);
2787 mmiowb();
2788 }
2789 if (conf->changed & IEEE80211_IFCC_BEACON &&
2790 (vif->type == NL80211_IFTYPE_ADHOC ||
2791 vif->type == NL80211_IFTYPE_MESH_POINT ||
2792 vif->type == NL80211_IFTYPE_AP)) {
2793 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
2794 if (!beacon) {
2795 ret = -ENOMEM;
2796 goto unlock;
2797 }
2798 ath5k_beacon_update(sc, beacon);
2799 } 2784 }
2800 2785
2801unlock: 2786 /* TODO:
2787 * 1) Move this on config_interface and handle each case
2788 * separately eg. when we have only one STA vif, use
2789 * AR5K_ANTMODE_SINGLE_AP
2790 *
2791 * 2) Allow the user to change antenna mode eg. when only
2792 * one antenna is present
2793 *
2794 * 3) Allow the user to set default/tx antenna when possible
2795 *
2796 * 4) Default mode should handle 90% of the cases, together
2797 * with fixed a/b and single AP modes we should be able to
2798 * handle 99%. Sectored modes are extreme cases and i still
2799 * haven't found a usage for them. If we decide to support them,
2800 * then we must allow the user to set how many tx antennas we
2801 * have available
2802 */
2803 ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_DEFAULT);
2804
2802 mutex_unlock(&sc->lock); 2805 mutex_unlock(&sc->lock);
2803 return ret; 2806 return 0;
2804} 2807}
2805 2808
2806#define SUPPORTED_FIF_FLAGS \ 2809#define SUPPORTED_FIF_FLAGS \
@@ -3083,11 +3086,40 @@ static void ath5k_bss_info_changed(struct ieee80211_hw *hw,
3083 u32 changes) 3086 u32 changes)
3084{ 3087{
3085 struct ath5k_softc *sc = hw->priv; 3088 struct ath5k_softc *sc = hw->priv;
3089 struct ath5k_hw *ah = sc->ah;
3090
3091 mutex_lock(&sc->lock);
3092 if (WARN_ON(sc->vif != vif))
3093 goto unlock;
3094
3095 if (changes & BSS_CHANGED_BSSID) {
3096 /* Cache for later use during resets */
3097 memcpy(ah->ah_bssid, bss_conf->bssid, ETH_ALEN);
3098 /* XXX: assoc id is set to 0 for now, mac80211 doesn't have
3099 * a clean way of letting us retrieve this yet. */
3100 ath5k_hw_set_associd(ah, ah->ah_bssid, 0);
3101 mmiowb();
3102 }
3103
3104 if (changes & BSS_CHANGED_BEACON_INT)
3105 sc->bintval = bss_conf->beacon_int;
3106
3086 if (changes & BSS_CHANGED_ASSOC) { 3107 if (changes & BSS_CHANGED_ASSOC) {
3087 mutex_lock(&sc->lock);
3088 sc->assoc = bss_conf->assoc; 3108 sc->assoc = bss_conf->assoc;
3089 if (sc->opmode == NL80211_IFTYPE_STATION) 3109 if (sc->opmode == NL80211_IFTYPE_STATION)
3090 set_beacon_filter(hw, sc->assoc); 3110 set_beacon_filter(hw, sc->assoc);
3091 mutex_unlock(&sc->lock);
3092 } 3111 }
3112
3113 if (changes & BSS_CHANGED_BEACON &&
3114 (vif->type == NL80211_IFTYPE_ADHOC ||
3115 vif->type == NL80211_IFTYPE_MESH_POINT ||
3116 vif->type == NL80211_IFTYPE_AP)) {
3117 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
3118
3119 if (beacon)
3120 ath5k_beacon_update(sc, beacon);
3121 }
3122
3123 unlock:
3124 mutex_unlock(&sc->lock);
3093} 3125}
diff --git a/drivers/net/wireless/ath/ath5k/eeprom.c b/drivers/net/wireless/ath/ath5k/eeprom.c
index c0fb3b09ba45..c56b494d417a 100644
--- a/drivers/net/wireless/ath/ath5k/eeprom.c
+++ b/drivers/net/wireless/ath/ath5k/eeprom.c
@@ -156,6 +156,17 @@ ath5k_eeprom_init_header(struct ath5k_hw *ah)
156 ee->ee_db[AR5K_EEPROM_MODE_11G][0] = (val >> 3) & 0x7; 156 ee->ee_db[AR5K_EEPROM_MODE_11G][0] = (val >> 3) & 0x7;
157 } 157 }
158 158
159 AR5K_EEPROM_READ(AR5K_EEPROM_IS_HB63, val);
160
161 if ((ah->ah_mac_version == (AR5K_SREV_AR2425 >> 4)) && val)
162 ee->ee_is_hb63 = true;
163 else
164 ee->ee_is_hb63 = false;
165
166 AR5K_EEPROM_READ(AR5K_EEPROM_RFKILL, val);
167 ee->ee_rfkill_pin = (u8) AR5K_REG_MS(val, AR5K_EEPROM_RFKILL_GPIO_SEL);
168 ee->ee_rfkill_pol = val & AR5K_EEPROM_RFKILL_POLARITY ? true : false;
169
159 return 0; 170 return 0;
160} 171}
161 172
@@ -197,16 +208,16 @@ static int ath5k_eeprom_read_ants(struct ath5k_hw *ah, u32 *offset,
197 ee->ee_ant_control[mode][i++] = (val >> 6) & 0x3f; 208 ee->ee_ant_control[mode][i++] = (val >> 6) & 0x3f;
198 ee->ee_ant_control[mode][i++] = val & 0x3f; 209 ee->ee_ant_control[mode][i++] = val & 0x3f;
199 210
200 /* Get antenna modes */ 211 /* Get antenna switch tables */
201 ah->ah_antenna[mode][0] = 212 ah->ah_ant_ctl[mode][AR5K_ANT_CTL] =
202 (ee->ee_ant_control[mode][0] << 4); 213 (ee->ee_ant_control[mode][0] << 4);
203 ah->ah_antenna[mode][AR5K_ANT_FIXED_A] = 214 ah->ah_ant_ctl[mode][AR5K_ANT_SWTABLE_A] =
204 ee->ee_ant_control[mode][1] | 215 ee->ee_ant_control[mode][1] |
205 (ee->ee_ant_control[mode][2] << 6) | 216 (ee->ee_ant_control[mode][2] << 6) |
206 (ee->ee_ant_control[mode][3] << 12) | 217 (ee->ee_ant_control[mode][3] << 12) |
207 (ee->ee_ant_control[mode][4] << 18) | 218 (ee->ee_ant_control[mode][4] << 18) |
208 (ee->ee_ant_control[mode][5] << 24); 219 (ee->ee_ant_control[mode][5] << 24);
209 ah->ah_antenna[mode][AR5K_ANT_FIXED_B] = 220 ah->ah_ant_ctl[mode][AR5K_ANT_SWTABLE_B] =
210 ee->ee_ant_control[mode][6] | 221 ee->ee_ant_control[mode][6] |
211 (ee->ee_ant_control[mode][7] << 6) | 222 (ee->ee_ant_control[mode][7] << 6) |
212 (ee->ee_ant_control[mode][8] << 12) | 223 (ee->ee_ant_control[mode][8] << 12) |
@@ -640,9 +651,9 @@ ath5k_eeprom_init_11bg_2413(struct ath5k_hw *ah, unsigned int mode, int offset)
640static inline void 651static inline void
641ath5k_get_pcdac_intercepts(struct ath5k_hw *ah, u8 min, u8 max, u8 *vp) 652ath5k_get_pcdac_intercepts(struct ath5k_hw *ah, u8 min, u8 max, u8 *vp)
642{ 653{
643 const static u16 intercepts3[] = 654 static const u16 intercepts3[] =
644 { 0, 5, 10, 20, 30, 50, 70, 85, 90, 95, 100 }; 655 { 0, 5, 10, 20, 30, 50, 70, 85, 90, 95, 100 };
645 const static u16 intercepts3_2[] = 656 static const u16 intercepts3_2[] =
646 { 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 }; 657 { 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 };
647 const u16 *ip; 658 const u16 *ip;
648 int i; 659 int i;
@@ -1694,9 +1705,40 @@ ath5k_eeprom_read_ctl_info(struct ath5k_hw *ah)
1694 return 0; 1705 return 0;
1695} 1706}
1696 1707
1708static int
1709ath5k_eeprom_read_spur_chans(struct ath5k_hw *ah)
1710{
1711 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1712 u32 offset;
1713 u16 val;
1714 int ret = 0, i;
1715
1716 offset = AR5K_EEPROM_CTL(ee->ee_version) +
1717 AR5K_EEPROM_N_CTLS(ee->ee_version);
1718
1719 if (ee->ee_version < AR5K_EEPROM_VERSION_5_3) {
1720 /* No spur info for 5GHz */
1721 ee->ee_spur_chans[0][0] = AR5K_EEPROM_NO_SPUR;
1722 /* 2 channels for 2GHz (2464/2420) */
1723 ee->ee_spur_chans[0][1] = AR5K_EEPROM_5413_SPUR_CHAN_1;
1724 ee->ee_spur_chans[1][1] = AR5K_EEPROM_5413_SPUR_CHAN_2;
1725 ee->ee_spur_chans[2][1] = AR5K_EEPROM_NO_SPUR;
1726 } else if (ee->ee_version >= AR5K_EEPROM_VERSION_5_3) {
1727 for (i = 0; i < AR5K_EEPROM_N_SPUR_CHANS; i++) {
1728 AR5K_EEPROM_READ(offset, val);
1729 ee->ee_spur_chans[i][0] = val;
1730 AR5K_EEPROM_READ(offset + AR5K_EEPROM_N_SPUR_CHANS,
1731 val);
1732 ee->ee_spur_chans[i][1] = val;
1733 offset++;
1734 }
1735 }
1736
1737 return ret;
1738}
1697 1739
1698/* 1740/*
1699 * Initialize eeprom power tables 1741 * Initialize eeprom data structure
1700 */ 1742 */
1701int 1743int
1702ath5k_eeprom_init(struct ath5k_hw *ah) 1744ath5k_eeprom_init(struct ath5k_hw *ah)
@@ -1719,6 +1761,10 @@ ath5k_eeprom_init(struct ath5k_hw *ah)
1719 if (err < 0) 1761 if (err < 0)
1720 return err; 1762 return err;
1721 1763
1764 err = ath5k_eeprom_read_spur_chans(ah);
1765 if (err < 0)
1766 return err;
1767
1722 return 0; 1768 return 0;
1723} 1769}
1724 1770
@@ -1754,16 +1800,3 @@ int ath5k_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac)
1754 1800
1755 return 0; 1801 return 0;
1756} 1802}
1757
1758bool ath5k_eeprom_is_hb63(struct ath5k_hw *ah)
1759{
1760 u16 data;
1761
1762 ath5k_hw_eeprom_read(ah, AR5K_EEPROM_IS_HB63, &data);
1763
1764 if ((ah->ah_mac_version == (AR5K_SREV_AR2425 >> 4)) && data)
1765 return true;
1766 else
1767 return false;
1768}
1769
diff --git a/drivers/net/wireless/ath/ath5k/eeprom.h b/drivers/net/wireless/ath/ath5k/eeprom.h
index b0c0606dea0b..64be73a5edae 100644
--- a/drivers/net/wireless/ath/ath5k/eeprom.h
+++ b/drivers/net/wireless/ath/ath5k/eeprom.h
@@ -26,6 +26,13 @@
26#define AR5K_EEPROM_MAGIC_5210 0x0000145a /* 5210 */ 26#define AR5K_EEPROM_MAGIC_5210 0x0000145a /* 5210 */
27 27
28#define AR5K_EEPROM_IS_HB63 0x000b /* Talon detect */ 28#define AR5K_EEPROM_IS_HB63 0x000b /* Talon detect */
29
30#define AR5K_EEPROM_RFKILL 0x0f
31#define AR5K_EEPROM_RFKILL_GPIO_SEL 0x0000001c
32#define AR5K_EEPROM_RFKILL_GPIO_SEL_S 2
33#define AR5K_EEPROM_RFKILL_POLARITY 0x00000002
34#define AR5K_EEPROM_RFKILL_POLARITY_S 1
35
29#define AR5K_EEPROM_REG_DOMAIN 0x00bf /* EEPROM regdom */ 36#define AR5K_EEPROM_REG_DOMAIN 0x00bf /* EEPROM regdom */
30#define AR5K_EEPROM_CHECKSUM 0x00c0 /* EEPROM checksum */ 37#define AR5K_EEPROM_CHECKSUM 0x00c0 /* EEPROM checksum */
31#define AR5K_EEPROM_INFO_BASE 0x00c0 /* EEPROM header */ 38#define AR5K_EEPROM_INFO_BASE 0x00c0 /* EEPROM header */
@@ -66,11 +73,6 @@
66#define AR5K_EEPROM_HDR_RFKILL(_v) (((_v) >> 14) & 0x1) /* Device has RFKill support */ 73#define AR5K_EEPROM_HDR_RFKILL(_v) (((_v) >> 14) & 0x1) /* Device has RFKill support */
67#define AR5K_EEPROM_HDR_T_5GHZ_DIS(_v) (((_v) >> 15) & 0x1) /* Disable turbo for 5Ghz */ 74#define AR5K_EEPROM_HDR_T_5GHZ_DIS(_v) (((_v) >> 15) & 0x1) /* Disable turbo for 5Ghz */
68 75
69#define AR5K_EEPROM_RFKILL_GPIO_SEL 0x0000001c
70#define AR5K_EEPROM_RFKILL_GPIO_SEL_S 2
71#define AR5K_EEPROM_RFKILL_POLARITY 0x00000002
72#define AR5K_EEPROM_RFKILL_POLARITY_S 1
73
74/* Newer EEPROMs are using a different offset */ 76/* Newer EEPROMs are using a different offset */
75#define AR5K_EEPROM_OFF(_v, _v3_0, _v3_3) \ 77#define AR5K_EEPROM_OFF(_v, _v3_0, _v3_3) \
76 (((_v) >= AR5K_EEPROM_VERSION_3_3) ? _v3_3 : _v3_0) 78 (((_v) >= AR5K_EEPROM_VERSION_3_3) ? _v3_3 : _v3_0)
@@ -211,6 +213,23 @@
211#define AR5K_EEPROM_I_GAIN 10 213#define AR5K_EEPROM_I_GAIN 10
212#define AR5K_EEPROM_CCK_OFDM_DELTA 15 214#define AR5K_EEPROM_CCK_OFDM_DELTA 15
213#define AR5K_EEPROM_N_IQ_CAL 2 215#define AR5K_EEPROM_N_IQ_CAL 2
216/* 5GHz/2GHz */
217enum ath5k_eeprom_freq_bands{
218 AR5K_EEPROM_BAND_5GHZ = 0,
219 AR5K_EEPROM_BAND_2GHZ = 1,
220 AR5K_EEPROM_N_FREQ_BANDS,
221};
222/* Spur chans per freq band */
223#define AR5K_EEPROM_N_SPUR_CHANS 5
224/* fbin value for chan 2464 x2 */
225#define AR5K_EEPROM_5413_SPUR_CHAN_1 1640
226/* fbin value for chan 2420 x2 */
227#define AR5K_EEPROM_5413_SPUR_CHAN_2 1200
228#define AR5K_EEPROM_SPUR_CHAN_MASK 0x3FFF
229#define AR5K_EEPROM_NO_SPUR 0x8000
230#define AR5K_SPUR_CHAN_WIDTH 87
231#define AR5K_SPUR_SYMBOL_WIDTH_BASE_100Hz 3125
232#define AR5K_SPUR_SYMBOL_WIDTH_TURBO_100Hz 6250
214 233
215#define AR5K_EEPROM_READ(_o, _v) do { \ 234#define AR5K_EEPROM_READ(_o, _v) do { \
216 ret = ath5k_hw_eeprom_read(ah, (_o), &(_v)); \ 235 ret = ath5k_hw_eeprom_read(ah, (_o), &(_v)); \
@@ -221,11 +240,11 @@
221#define AR5K_EEPROM_READ_HDR(_o, _v) \ 240#define AR5K_EEPROM_READ_HDR(_o, _v) \
222 AR5K_EEPROM_READ(_o, ah->ah_capabilities.cap_eeprom._v); \ 241 AR5K_EEPROM_READ(_o, ah->ah_capabilities.cap_eeprom._v); \
223 242
224enum ath5k_ant_setting { 243enum ath5k_ant_table {
225 AR5K_ANT_VARIABLE = 0, /* variable by programming */ 244 AR5K_ANT_CTL = 0, /* Idle switch table settings */
226 AR5K_ANT_FIXED_A = 1, /* fixed to 11a frequencies */ 245 AR5K_ANT_SWTABLE_A = 1, /* Switch table for antenna A */
227 AR5K_ANT_FIXED_B = 2, /* fixed to 11b frequencies */ 246 AR5K_ANT_SWTABLE_B = 2, /* Switch table for antenna B */
228 AR5K_ANT_MAX = 3, 247 AR5K_ANT_MAX,
229}; 248};
230 249
231enum ath5k_ctl_mode { 250enum ath5k_ctl_mode {
@@ -369,6 +388,9 @@ struct ath5k_eeprom_info {
369 u16 ee_version; 388 u16 ee_version;
370 u16 ee_header; 389 u16 ee_header;
371 u16 ee_ant_gain; 390 u16 ee_ant_gain;
391 u8 ee_rfkill_pin;
392 bool ee_rfkill_pol;
393 bool ee_is_hb63;
372 u16 ee_misc0; 394 u16 ee_misc0;
373 u16 ee_misc1; 395 u16 ee_misc1;
374 u16 ee_misc2; 396 u16 ee_misc2;
@@ -436,6 +458,10 @@ struct ath5k_eeprom_info {
436 s8 ee_pga_desired_size_turbo[AR5K_EEPROM_N_MODES]; 458 s8 ee_pga_desired_size_turbo[AR5K_EEPROM_N_MODES];
437 s8 ee_pd_gain_overlap; 459 s8 ee_pd_gain_overlap;
438 460
461 /* Spur mitigation data (fbin values for spur channels) */
462 u16 ee_spur_chans[AR5K_EEPROM_N_SPUR_CHANS][AR5K_EEPROM_N_FREQ_BANDS];
463
464 /* Antenna raw switch tables */
439 u32 ee_antenna[AR5K_EEPROM_N_MODES][AR5K_ANT_MAX]; 465 u32 ee_antenna[AR5K_EEPROM_N_MODES][AR5K_ANT_MAX];
440}; 466};
441 467
diff --git a/drivers/net/wireless/ath/ath5k/led.c b/drivers/net/wireless/ath/ath5k/led.c
index cbdc0b308429..876725f08b6c 100644
--- a/drivers/net/wireless/ath/ath5k/led.c
+++ b/drivers/net/wireless/ath/ath5k/led.c
@@ -53,8 +53,6 @@
53 53
54/* Devices we match on for LED config info (typically laptops) */ 54/* Devices we match on for LED config info (typically laptops) */
55static const struct pci_device_id ath5k_led_devices[] = { 55static const struct pci_device_id ath5k_led_devices[] = {
56 /* IBM-specific AR5212 */
57 { PCI_VDEVICE(ATHEROS, PCI_DEVICE_ID_ATHEROS_AR5212_IBM), ATH_LED(0, 0) },
58 /* AR5211 */ 56 /* AR5211 */
59 { PCI_VDEVICE(ATHEROS, PCI_DEVICE_ID_ATHEROS_AR5211), ATH_LED(0, 0) }, 57 { PCI_VDEVICE(ATHEROS, PCI_DEVICE_ID_ATHEROS_AR5211), ATH_LED(0, 0) },
60 /* HP Compaq nc6xx, nc4000, nx6000 */ 58 /* HP Compaq nc6xx, nc4000, nx6000 */
@@ -69,6 +67,10 @@ static const struct pci_device_id ath5k_led_devices[] = {
69 { ATH_SDEVICE(PCI_VENDOR_ID_QMI, 0x0105), ATH_LED(3, 0) }, 67 { ATH_SDEVICE(PCI_VENDOR_ID_QMI, 0x0105), ATH_LED(3, 0) },
70 /* Fukato Datacask Jupiter 1014a (mrb74@gmx.at) */ 68 /* Fukato Datacask Jupiter 1014a (mrb74@gmx.at) */
71 { ATH_SDEVICE(PCI_VENDOR_ID_AZWAVE, 0x1026), ATH_LED(3, 0) }, 69 { ATH_SDEVICE(PCI_VENDOR_ID_AZWAVE, 0x1026), ATH_LED(3, 0) },
70 /* IBM ThinkPad AR5BXB6 (legovini@spiro.fisica.unipd.it) */
71 { ATH_SDEVICE(PCI_VENDOR_ID_IBM, 0x058a), ATH_LED(1, 0) },
72 /* IBM-specific AR5212 (all others) */
73 { PCI_VDEVICE(ATHEROS, PCI_DEVICE_ID_ATHEROS_AR5212_IBM), ATH_LED(0, 0) },
72 { } 74 { }
73}; 75};
74 76
diff --git a/drivers/net/wireless/ath/ath5k/pcu.c b/drivers/net/wireless/ath/ath5k/pcu.c
index 55122f1e1986..579aa0a96ab8 100644
--- a/drivers/net/wireless/ath/ath5k/pcu.c
+++ b/drivers/net/wireless/ath/ath5k/pcu.c
@@ -736,8 +736,8 @@ void ath5k_hw_init_beacon(struct ath5k_hw *ah, u32 next_beacon, u32 interval)
736 /* When in AP mode zero timer0 to start TSF */ 736 /* When in AP mode zero timer0 to start TSF */
737 if (ah->ah_op_mode == NL80211_IFTYPE_AP) 737 if (ah->ah_op_mode == NL80211_IFTYPE_AP)
738 ath5k_hw_reg_write(ah, 0, AR5K_TIMER0); 738 ath5k_hw_reg_write(ah, 0, AR5K_TIMER0);
739 else 739
740 ath5k_hw_reg_write(ah, next_beacon, AR5K_TIMER0); 740 ath5k_hw_reg_write(ah, next_beacon, AR5K_TIMER0);
741 ath5k_hw_reg_write(ah, timer1, AR5K_TIMER1); 741 ath5k_hw_reg_write(ah, timer1, AR5K_TIMER1);
742 ath5k_hw_reg_write(ah, timer2, AR5K_TIMER2); 742 ath5k_hw_reg_write(ah, timer2, AR5K_TIMER2);
743 ath5k_hw_reg_write(ah, timer3, AR5K_TIMER3); 743 ath5k_hw_reg_write(ah, timer3, AR5K_TIMER3);
@@ -1003,7 +1003,7 @@ int ath5k_hw_reset_key(struct ath5k_hw *ah, u16 entry)
1003 * Note2: Windows driver (ndiswrapper) sets this to 1003 * Note2: Windows driver (ndiswrapper) sets this to
1004 * 0x00000714 instead of 0x00000007 1004 * 0x00000714 instead of 0x00000007
1005 */ 1005 */
1006 if (ah->ah_version > AR5K_AR5211) { 1006 if (ah->ah_version >= AR5K_AR5211) {
1007 ath5k_hw_reg_write(ah, AR5K_KEYTABLE_TYPE_NULL, 1007 ath5k_hw_reg_write(ah, AR5K_KEYTABLE_TYPE_NULL,
1008 AR5K_KEYTABLE_TYPE(entry)); 1008 AR5K_KEYTABLE_TYPE(entry));
1009 1009
diff --git a/drivers/net/wireless/ath/ath5k/phy.c b/drivers/net/wireless/ath/ath5k/phy.c
index b48b29dca3d2..d0d1c350025a 100644
--- a/drivers/net/wireless/ath/ath5k/phy.c
+++ b/drivers/net/wireless/ath/ath5k/phy.c
@@ -168,9 +168,6 @@ int ath5k_hw_rfgain_opt_init(struct ath5k_hw *ah)
168 * tx power and a Peak to Average Power Detector (PAPD) will try 168 * tx power and a Peak to Average Power Detector (PAPD) will try
169 * to measure the gain. 169 * to measure the gain.
170 * 170 *
171 * TODO: Use propper tx power setting for the probe packet so
172 * that we don't observe a serious power drop on the receiver
173 *
174 * XXX: How about forcing a tx packet (bypassing PCU arbitrator etc) 171 * XXX: How about forcing a tx packet (bypassing PCU arbitrator etc)
175 * just after we enable the probe so that we don't mess with 172 * just after we enable the probe so that we don't mess with
176 * standard traffic ? Maybe it's time to use sw interrupts and 173 * standard traffic ? Maybe it's time to use sw interrupts and
@@ -186,7 +183,7 @@ static void ath5k_hw_request_rfgain_probe(struct ath5k_hw *ah)
186 183
187 /* Send the packet with 2dB below max power as 184 /* Send the packet with 2dB below max power as
188 * patent doc suggest */ 185 * patent doc suggest */
189 ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txpower.txp_max_pwr - 4, 186 ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txpower.txp_ofdm - 4,
190 AR5K_PHY_PAPD_PROBE_TXPOWER) | 187 AR5K_PHY_PAPD_PROBE_TXPOWER) |
191 AR5K_PHY_PAPD_PROBE_TX_NEXT, AR5K_PHY_PAPD_PROBE); 188 AR5K_PHY_PAPD_PROBE_TX_NEXT, AR5K_PHY_PAPD_PROBE);
192 189
@@ -1356,6 +1353,257 @@ int ath5k_hw_phy_calibrate(struct ath5k_hw *ah,
1356 return ret; 1353 return ret;
1357} 1354}
1358 1355
1356/***************************\
1357* Spur mitigation functions *
1358\***************************/
1359
1360bool ath5k_hw_chan_has_spur_noise(struct ath5k_hw *ah,
1361 struct ieee80211_channel *channel)
1362{
1363 u8 refclk_freq;
1364
1365 if ((ah->ah_radio == AR5K_RF5112) ||
1366 (ah->ah_radio == AR5K_RF5413) ||
1367 (ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4)))
1368 refclk_freq = 40;
1369 else
1370 refclk_freq = 32;
1371
1372 if ((channel->center_freq % refclk_freq != 0) &&
1373 ((channel->center_freq % refclk_freq < 10) ||
1374 (channel->center_freq % refclk_freq > 22)))
1375 return true;
1376 else
1377 return false;
1378}
1379
1380void
1381ath5k_hw_set_spur_mitigation_filter(struct ath5k_hw *ah,
1382 struct ieee80211_channel *channel)
1383{
1384 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1385 u32 mag_mask[4] = {0, 0, 0, 0};
1386 u32 pilot_mask[2] = {0, 0};
1387 /* Note: fbin values are scaled up by 2 */
1388 u16 spur_chan_fbin, chan_fbin, symbol_width, spur_detection_window;
1389 s32 spur_delta_phase, spur_freq_sigma_delta;
1390 s32 spur_offset, num_symbols_x16;
1391 u8 num_symbol_offsets, i, freq_band;
1392
1393 /* Convert current frequency to fbin value (the same way channels
1394 * are stored on EEPROM, check out ath5k_eeprom_bin2freq) and scale
1395 * up by 2 so we can compare it later */
1396 if (channel->hw_value & CHANNEL_2GHZ) {
1397 chan_fbin = (channel->center_freq - 2300) * 10;
1398 freq_band = AR5K_EEPROM_BAND_2GHZ;
1399 } else {
1400 chan_fbin = (channel->center_freq - 4900) * 10;
1401 freq_band = AR5K_EEPROM_BAND_5GHZ;
1402 }
1403
1404 /* Check if any spur_chan_fbin from EEPROM is
1405 * within our current channel's spur detection range */
1406 spur_chan_fbin = AR5K_EEPROM_NO_SPUR;
1407 spur_detection_window = AR5K_SPUR_CHAN_WIDTH;
1408 /* XXX: Half/Quarter channels ?*/
1409 if (channel->hw_value & CHANNEL_TURBO)
1410 spur_detection_window *= 2;
1411
1412 for (i = 0; i < AR5K_EEPROM_N_SPUR_CHANS; i++) {
1413 spur_chan_fbin = ee->ee_spur_chans[i][freq_band];
1414
1415 /* Note: mask cleans AR5K_EEPROM_NO_SPUR flag
1416 * so it's zero if we got nothing from EEPROM */
1417 if (spur_chan_fbin == AR5K_EEPROM_NO_SPUR) {
1418 spur_chan_fbin &= AR5K_EEPROM_SPUR_CHAN_MASK;
1419 break;
1420 }
1421
1422 if ((chan_fbin - spur_detection_window <=
1423 (spur_chan_fbin & AR5K_EEPROM_SPUR_CHAN_MASK)) &&
1424 (chan_fbin + spur_detection_window >=
1425 (spur_chan_fbin & AR5K_EEPROM_SPUR_CHAN_MASK))) {
1426 spur_chan_fbin &= AR5K_EEPROM_SPUR_CHAN_MASK;
1427 break;
1428 }
1429 }
1430
1431 /* We need to enable spur filter for this channel */
1432 if (spur_chan_fbin) {
1433 spur_offset = spur_chan_fbin - chan_fbin;
1434 /*
1435 * Calculate deltas:
1436 * spur_freq_sigma_delta -> spur_offset / sample_freq << 21
1437 * spur_delta_phase -> spur_offset / chip_freq << 11
1438 * Note: Both values have 100KHz resolution
1439 */
1440 /* XXX: Half/Quarter rate channels ? */
1441 switch (channel->hw_value) {
1442 case CHANNEL_A:
1443 /* Both sample_freq and chip_freq are 40MHz */
1444 spur_delta_phase = (spur_offset << 17) / 25;
1445 spur_freq_sigma_delta = (spur_delta_phase >> 10);
1446 symbol_width = AR5K_SPUR_SYMBOL_WIDTH_BASE_100Hz;
1447 break;
1448 case CHANNEL_G:
1449 /* sample_freq -> 40MHz chip_freq -> 44MHz
1450 * (for b compatibility) */
1451 spur_freq_sigma_delta = (spur_offset << 8) / 55;
1452 spur_delta_phase = (spur_offset << 17) / 25;
1453 symbol_width = AR5K_SPUR_SYMBOL_WIDTH_BASE_100Hz;
1454 break;
1455 case CHANNEL_T:
1456 case CHANNEL_TG:
1457 /* Both sample_freq and chip_freq are 80MHz */
1458 spur_delta_phase = (spur_offset << 16) / 25;
1459 spur_freq_sigma_delta = (spur_delta_phase >> 10);
1460 symbol_width = AR5K_SPUR_SYMBOL_WIDTH_TURBO_100Hz;
1461 break;
1462 default:
1463 return;
1464 }
1465
1466 /* Calculate pilot and magnitude masks */
1467
1468 /* Scale up spur_offset by 1000 to switch to 100HZ resolution
1469 * and divide by symbol_width to find how many symbols we have
1470 * Note: number of symbols is scaled up by 16 */
1471 num_symbols_x16 = ((spur_offset * 1000) << 4) / symbol_width;
1472
1473 /* Spur is on a symbol if num_symbols_x16 % 16 is zero */
1474 if (!(num_symbols_x16 & 0xF))
1475 /* _X_ */
1476 num_symbol_offsets = 3;
1477 else
1478 /* _xx_ */
1479 num_symbol_offsets = 4;
1480
1481 for (i = 0; i < num_symbol_offsets; i++) {
1482
1483 /* Calculate pilot mask */
1484 s32 curr_sym_off =
1485 (num_symbols_x16 / 16) + i + 25;
1486
1487 /* Pilot magnitude mask seems to be a way to
1488 * declare the boundaries for our detection
1489 * window or something, it's 2 for the middle
1490 * value(s) where the symbol is expected to be
1491 * and 1 on the boundary values */
1492 u8 plt_mag_map =
1493 (i == 0 || i == (num_symbol_offsets - 1))
1494 ? 1 : 2;
1495
1496 if (curr_sym_off >= 0 && curr_sym_off <= 32) {
1497 if (curr_sym_off <= 25)
1498 pilot_mask[0] |= 1 << curr_sym_off;
1499 else if (curr_sym_off >= 27)
1500 pilot_mask[0] |= 1 << (curr_sym_off - 1);
1501 } else if (curr_sym_off >= 33 && curr_sym_off <= 52)
1502 pilot_mask[1] |= 1 << (curr_sym_off - 33);
1503
1504 /* Calculate magnitude mask (for viterbi decoder) */
1505 if (curr_sym_off >= -1 && curr_sym_off <= 14)
1506 mag_mask[0] |=
1507 plt_mag_map << (curr_sym_off + 1) * 2;
1508 else if (curr_sym_off >= 15 && curr_sym_off <= 30)
1509 mag_mask[1] |=
1510 plt_mag_map << (curr_sym_off - 15) * 2;
1511 else if (curr_sym_off >= 31 && curr_sym_off <= 46)
1512 mag_mask[2] |=
1513 plt_mag_map << (curr_sym_off - 31) * 2;
1514 else if (curr_sym_off >= 46 && curr_sym_off <= 53)
1515 mag_mask[3] |=
1516 plt_mag_map << (curr_sym_off - 47) * 2;
1517
1518 }
1519
1520 /* Write settings on hw to enable spur filter */
1521 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_BIN_MASK_CTL,
1522 AR5K_PHY_BIN_MASK_CTL_RATE, 0xff);
1523 /* XXX: Self correlator also ? */
1524 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_IQ,
1525 AR5K_PHY_IQ_PILOT_MASK_EN |
1526 AR5K_PHY_IQ_CHAN_MASK_EN |
1527 AR5K_PHY_IQ_SPUR_FILT_EN);
1528
1529 /* Set delta phase and freq sigma delta */
1530 ath5k_hw_reg_write(ah,
1531 AR5K_REG_SM(spur_delta_phase,
1532 AR5K_PHY_TIMING_11_SPUR_DELTA_PHASE) |
1533 AR5K_REG_SM(spur_freq_sigma_delta,
1534 AR5K_PHY_TIMING_11_SPUR_FREQ_SD) |
1535 AR5K_PHY_TIMING_11_USE_SPUR_IN_AGC,
1536 AR5K_PHY_TIMING_11);
1537
1538 /* Write pilot masks */
1539 ath5k_hw_reg_write(ah, pilot_mask[0], AR5K_PHY_TIMING_7);
1540 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_TIMING_8,
1541 AR5K_PHY_TIMING_8_PILOT_MASK_2,
1542 pilot_mask[1]);
1543
1544 ath5k_hw_reg_write(ah, pilot_mask[0], AR5K_PHY_TIMING_9);
1545 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_TIMING_10,
1546 AR5K_PHY_TIMING_10_PILOT_MASK_2,
1547 pilot_mask[1]);
1548
1549 /* Write magnitude masks */
1550 ath5k_hw_reg_write(ah, mag_mask[0], AR5K_PHY_BIN_MASK_1);
1551 ath5k_hw_reg_write(ah, mag_mask[1], AR5K_PHY_BIN_MASK_2);
1552 ath5k_hw_reg_write(ah, mag_mask[2], AR5K_PHY_BIN_MASK_3);
1553 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_BIN_MASK_CTL,
1554 AR5K_PHY_BIN_MASK_CTL_MASK_4,
1555 mag_mask[3]);
1556
1557 ath5k_hw_reg_write(ah, mag_mask[0], AR5K_PHY_BIN_MASK2_1);
1558 ath5k_hw_reg_write(ah, mag_mask[1], AR5K_PHY_BIN_MASK2_2);
1559 ath5k_hw_reg_write(ah, mag_mask[2], AR5K_PHY_BIN_MASK2_3);
1560 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_BIN_MASK2_4,
1561 AR5K_PHY_BIN_MASK2_4_MASK_4,
1562 mag_mask[3]);
1563
1564 } else if (ath5k_hw_reg_read(ah, AR5K_PHY_IQ) &
1565 AR5K_PHY_IQ_SPUR_FILT_EN) {
1566 /* Clean up spur mitigation settings and disable fliter */
1567 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_BIN_MASK_CTL,
1568 AR5K_PHY_BIN_MASK_CTL_RATE, 0);
1569 AR5K_REG_DISABLE_BITS(ah, AR5K_PHY_IQ,
1570 AR5K_PHY_IQ_PILOT_MASK_EN |
1571 AR5K_PHY_IQ_CHAN_MASK_EN |
1572 AR5K_PHY_IQ_SPUR_FILT_EN);
1573 ath5k_hw_reg_write(ah, 0, AR5K_PHY_TIMING_11);
1574
1575 /* Clear pilot masks */
1576 ath5k_hw_reg_write(ah, 0, AR5K_PHY_TIMING_7);
1577 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_TIMING_8,
1578 AR5K_PHY_TIMING_8_PILOT_MASK_2,
1579 0);
1580
1581 ath5k_hw_reg_write(ah, 0, AR5K_PHY_TIMING_9);
1582 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_TIMING_10,
1583 AR5K_PHY_TIMING_10_PILOT_MASK_2,
1584 0);
1585
1586 /* Clear magnitude masks */
1587 ath5k_hw_reg_write(ah, 0, AR5K_PHY_BIN_MASK_1);
1588 ath5k_hw_reg_write(ah, 0, AR5K_PHY_BIN_MASK_2);
1589 ath5k_hw_reg_write(ah, 0, AR5K_PHY_BIN_MASK_3);
1590 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_BIN_MASK_CTL,
1591 AR5K_PHY_BIN_MASK_CTL_MASK_4,
1592 0);
1593
1594 ath5k_hw_reg_write(ah, 0, AR5K_PHY_BIN_MASK2_1);
1595 ath5k_hw_reg_write(ah, 0, AR5K_PHY_BIN_MASK2_2);
1596 ath5k_hw_reg_write(ah, 0, AR5K_PHY_BIN_MASK2_3);
1597 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_BIN_MASK2_4,
1598 AR5K_PHY_BIN_MASK2_4_MASK_4,
1599 0);
1600 }
1601}
1602
1603/********************\
1604 Misc PHY functions
1605\********************/
1606
1359int ath5k_hw_phy_disable(struct ath5k_hw *ah) 1607int ath5k_hw_phy_disable(struct ath5k_hw *ah)
1360{ 1608{
1361 ATH5K_TRACE(ah->ah_sc); 1609 ATH5K_TRACE(ah->ah_sc);
@@ -1365,10 +1613,6 @@ int ath5k_hw_phy_disable(struct ath5k_hw *ah)
1365 return 0; 1613 return 0;
1366} 1614}
1367 1615
1368/********************\
1369 Misc PHY functions
1370\********************/
1371
1372/* 1616/*
1373 * Get the PHY Chip revision 1617 * Get the PHY Chip revision
1374 */ 1618 */
@@ -1417,25 +1661,189 @@ u16 ath5k_hw_radio_revision(struct ath5k_hw *ah, unsigned int chan)
1417 return ret; 1661 return ret;
1418} 1662}
1419 1663
1664/*****************\
1665* Antenna control *
1666\*****************/
1667
1420void /*TODO:Boundary check*/ 1668void /*TODO:Boundary check*/
1421ath5k_hw_set_def_antenna(struct ath5k_hw *ah, unsigned int ant) 1669ath5k_hw_set_def_antenna(struct ath5k_hw *ah, u8 ant)
1422{ 1670{
1423 ATH5K_TRACE(ah->ah_sc); 1671 ATH5K_TRACE(ah->ah_sc);
1424 /*Just a try M.F.*/ 1672
1425 if (ah->ah_version != AR5K_AR5210) 1673 if (ah->ah_version != AR5K_AR5210)
1426 ath5k_hw_reg_write(ah, ant, AR5K_DEFAULT_ANTENNA); 1674 ath5k_hw_reg_write(ah, ant & 0x7, AR5K_DEFAULT_ANTENNA);
1427} 1675}
1428 1676
1429unsigned int ath5k_hw_get_def_antenna(struct ath5k_hw *ah) 1677unsigned int ath5k_hw_get_def_antenna(struct ath5k_hw *ah)
1430{ 1678{
1431 ATH5K_TRACE(ah->ah_sc); 1679 ATH5K_TRACE(ah->ah_sc);
1432 /*Just a try M.F.*/ 1680
1433 if (ah->ah_version != AR5K_AR5210) 1681 if (ah->ah_version != AR5K_AR5210)
1434 return ath5k_hw_reg_read(ah, AR5K_DEFAULT_ANTENNA); 1682 return ath5k_hw_reg_read(ah, AR5K_DEFAULT_ANTENNA) & 0x7;
1435 1683
1436 return false; /*XXX: What do we return for 5210 ?*/ 1684 return false; /*XXX: What do we return for 5210 ?*/
1437} 1685}
1438 1686
1687/*
1688 * Enable/disable fast rx antenna diversity
1689 */
1690static void
1691ath5k_hw_set_fast_div(struct ath5k_hw *ah, u8 ee_mode, bool enable)
1692{
1693 switch (ee_mode) {
1694 case AR5K_EEPROM_MODE_11G:
1695 /* XXX: This is set to
1696 * disabled on initvals !!! */
1697 case AR5K_EEPROM_MODE_11A:
1698 if (enable)
1699 AR5K_REG_DISABLE_BITS(ah, AR5K_PHY_AGCCTL,
1700 AR5K_PHY_AGCCTL_OFDM_DIV_DIS);
1701 else
1702 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_AGCCTL,
1703 AR5K_PHY_AGCCTL_OFDM_DIV_DIS);
1704 break;
1705 case AR5K_EEPROM_MODE_11B:
1706 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_AGCCTL,
1707 AR5K_PHY_AGCCTL_OFDM_DIV_DIS);
1708 break;
1709 default:
1710 return;
1711 }
1712
1713 if (enable) {
1714 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_RESTART,
1715 AR5K_PHY_RESTART_DIV_GC, 0xc);
1716
1717 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_FAST_ANT_DIV,
1718 AR5K_PHY_FAST_ANT_DIV_EN);
1719 } else {
1720 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_RESTART,
1721 AR5K_PHY_RESTART_DIV_GC, 0x8);
1722
1723 AR5K_REG_DISABLE_BITS(ah, AR5K_PHY_FAST_ANT_DIV,
1724 AR5K_PHY_FAST_ANT_DIV_EN);
1725 }
1726}
1727
1728/*
1729 * Set antenna operating mode
1730 */
1731void
1732ath5k_hw_set_antenna_mode(struct ath5k_hw *ah, u8 ant_mode)
1733{
1734 struct ieee80211_channel *channel = &ah->ah_current_channel;
1735 bool use_def_for_tx, update_def_on_tx, use_def_for_rts, fast_div;
1736 bool use_def_for_sg;
1737 u8 def_ant, tx_ant, ee_mode;
1738 u32 sta_id1 = 0;
1739
1740 def_ant = ah->ah_def_ant;
1741
1742 ATH5K_TRACE(ah->ah_sc);
1743
1744 switch (channel->hw_value & CHANNEL_MODES) {
1745 case CHANNEL_A:
1746 case CHANNEL_T:
1747 case CHANNEL_XR:
1748 ee_mode = AR5K_EEPROM_MODE_11A;
1749 break;
1750 case CHANNEL_G:
1751 case CHANNEL_TG:
1752 ee_mode = AR5K_EEPROM_MODE_11G;
1753 break;
1754 case CHANNEL_B:
1755 ee_mode = AR5K_EEPROM_MODE_11B;
1756 break;
1757 default:
1758 ATH5K_ERR(ah->ah_sc,
1759 "invalid channel: %d\n", channel->center_freq);
1760 return;
1761 }
1762
1763 switch (ant_mode) {
1764 case AR5K_ANTMODE_DEFAULT:
1765 tx_ant = 0;
1766 use_def_for_tx = false;
1767 update_def_on_tx = false;
1768 use_def_for_rts = false;
1769 use_def_for_sg = false;
1770 fast_div = true;
1771 break;
1772 case AR5K_ANTMODE_FIXED_A:
1773 def_ant = 1;
1774 tx_ant = 0;
1775 use_def_for_tx = true;
1776 update_def_on_tx = false;
1777 use_def_for_rts = true;
1778 use_def_for_sg = true;
1779 fast_div = false;
1780 break;
1781 case AR5K_ANTMODE_FIXED_B:
1782 def_ant = 2;
1783 tx_ant = 0;
1784 use_def_for_tx = true;
1785 update_def_on_tx = false;
1786 use_def_for_rts = true;
1787 use_def_for_sg = true;
1788 fast_div = false;
1789 break;
1790 case AR5K_ANTMODE_SINGLE_AP:
1791 def_ant = 1; /* updated on tx */
1792 tx_ant = 0;
1793 use_def_for_tx = true;
1794 update_def_on_tx = true;
1795 use_def_for_rts = true;
1796 use_def_for_sg = true;
1797 fast_div = true;
1798 break;
1799 case AR5K_ANTMODE_SECTOR_AP:
1800 tx_ant = 1; /* variable */
1801 use_def_for_tx = false;
1802 update_def_on_tx = false;
1803 use_def_for_rts = true;
1804 use_def_for_sg = false;
1805 fast_div = false;
1806 break;
1807 case AR5K_ANTMODE_SECTOR_STA:
1808 tx_ant = 1; /* variable */
1809 use_def_for_tx = true;
1810 update_def_on_tx = false;
1811 use_def_for_rts = true;
1812 use_def_for_sg = false;
1813 fast_div = true;
1814 break;
1815 case AR5K_ANTMODE_DEBUG:
1816 def_ant = 1;
1817 tx_ant = 2;
1818 use_def_for_tx = false;
1819 update_def_on_tx = false;
1820 use_def_for_rts = false;
1821 use_def_for_sg = false;
1822 fast_div = false;
1823 break;
1824 default:
1825 return;
1826 }
1827
1828 ah->ah_tx_ant = tx_ant;
1829 ah->ah_ant_mode = ant_mode;
1830
1831 sta_id1 |= use_def_for_tx ? AR5K_STA_ID1_DEFAULT_ANTENNA : 0;
1832 sta_id1 |= update_def_on_tx ? AR5K_STA_ID1_DESC_ANTENNA : 0;
1833 sta_id1 |= use_def_for_rts ? AR5K_STA_ID1_RTS_DEF_ANTENNA : 0;
1834 sta_id1 |= use_def_for_sg ? AR5K_STA_ID1_SELFGEN_DEF_ANT : 0;
1835
1836 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1, AR5K_STA_ID1_ANTENNA_SETTINGS);
1837
1838 if (sta_id1)
1839 AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1, sta_id1);
1840
1841 /* Note: set diversity before default antenna
1842 * because it won't work correctly */
1843 ath5k_hw_set_fast_div(ah, ee_mode, fast_div);
1844 ath5k_hw_set_def_antenna(ah, def_ant);
1845}
1846
1439 1847
1440/****************\ 1848/****************\
1441* TX power setup * 1849* TX power setup *
@@ -1750,8 +2158,6 @@ done:
1750 * Get the max edge power for this channel if 2158 * Get the max edge power for this channel if
1751 * we have such data from EEPROM's Conformance Test 2159 * we have such data from EEPROM's Conformance Test
1752 * Limits (CTL), and limit max power if needed. 2160 * Limits (CTL), and limit max power if needed.
1753 *
1754 * FIXME: Only works for world regulatory domains
1755 */ 2161 */
1756static void 2162static void
1757ath5k_get_max_ctl_power(struct ath5k_hw *ah, 2163ath5k_get_max_ctl_power(struct ath5k_hw *ah,
@@ -1767,26 +2173,23 @@ ath5k_get_max_ctl_power(struct ath5k_hw *ah,
1767 u8 ctl_idx = 0xFF; 2173 u8 ctl_idx = 0xFF;
1768 u32 target = channel->center_freq; 2174 u32 target = channel->center_freq;
1769 2175
1770 /* Find out a CTL for our mode that's not mapped 2176 ctl_mode = ath_regd_get_band_ctl(&ah->ah_regulatory, channel->band);
1771 * on a specific reg domain. 2177
1772 *
1773 * TODO: Map our current reg domain to one of the 3 available
1774 * reg domain ids so that we can support more CTLs. */
1775 switch (channel->hw_value & CHANNEL_MODES) { 2178 switch (channel->hw_value & CHANNEL_MODES) {
1776 case CHANNEL_A: 2179 case CHANNEL_A:
1777 ctl_mode = AR5K_CTL_11A | AR5K_CTL_NO_REGDOMAIN; 2180 ctl_mode |= AR5K_CTL_11A;
1778 break; 2181 break;
1779 case CHANNEL_G: 2182 case CHANNEL_G:
1780 ctl_mode = AR5K_CTL_11G | AR5K_CTL_NO_REGDOMAIN; 2183 ctl_mode |= AR5K_CTL_11G;
1781 break; 2184 break;
1782 case CHANNEL_B: 2185 case CHANNEL_B:
1783 ctl_mode = AR5K_CTL_11B | AR5K_CTL_NO_REGDOMAIN; 2186 ctl_mode |= AR5K_CTL_11B;
1784 break; 2187 break;
1785 case CHANNEL_T: 2188 case CHANNEL_T:
1786 ctl_mode = AR5K_CTL_TURBO | AR5K_CTL_NO_REGDOMAIN; 2189 ctl_mode |= AR5K_CTL_TURBO;
1787 break; 2190 break;
1788 case CHANNEL_TG: 2191 case CHANNEL_TG:
1789 ctl_mode = AR5K_CTL_TURBOG | AR5K_CTL_NO_REGDOMAIN; 2192 ctl_mode |= AR5K_CTL_TURBOG;
1790 break; 2193 break;
1791 case CHANNEL_XR: 2194 case CHANNEL_XR:
1792 /* Fall through */ 2195 /* Fall through */
@@ -2482,8 +2885,19 @@ ath5k_setup_rate_powertable(struct ath5k_hw *ah, u16 max_pwr,
2482 for (i = 8; i <= 15; i++) 2885 for (i = 8; i <= 15; i++)
2483 rates[i] -= ah->ah_txpower.txp_cck_ofdm_gainf_delta; 2886 rates[i] -= ah->ah_txpower.txp_cck_ofdm_gainf_delta;
2484 2887
2485 ah->ah_txpower.txp_min_pwr = rates[7]; 2888 /* Now that we have all rates setup use table offset to
2486 ah->ah_txpower.txp_max_pwr = rates[0]; 2889 * match the power range set by user with the power indices
2890 * on PCDAC/PDADC table */
2891 for (i = 0; i < 16; i++) {
2892 rates[i] += ah->ah_txpower.txp_offset;
2893 /* Don't get out of bounds */
2894 if (rates[i] > 63)
2895 rates[i] = 63;
2896 }
2897
2898 /* Min/max in 0.25dB units */
2899 ah->ah_txpower.txp_min_pwr = 2 * rates[7];
2900 ah->ah_txpower.txp_max_pwr = 2 * rates[0];
2487 ah->ah_txpower.txp_ofdm = rates[7]; 2901 ah->ah_txpower.txp_ofdm = rates[7];
2488} 2902}
2489 2903
@@ -2591,16 +3005,37 @@ ath5k_hw_txpower(struct ath5k_hw *ah, struct ieee80211_channel *channel,
2591 return 0; 3005 return 0;
2592} 3006}
2593 3007
2594int ath5k_hw_set_txpower_limit(struct ath5k_hw *ah, u8 mode, u8 txpower) 3008int ath5k_hw_set_txpower_limit(struct ath5k_hw *ah, u8 txpower)
2595{ 3009{
2596 /*Just a try M.F.*/ 3010 /*Just a try M.F.*/
2597 struct ieee80211_channel *channel = &ah->ah_current_channel; 3011 struct ieee80211_channel *channel = &ah->ah_current_channel;
3012 u8 ee_mode;
2598 3013
2599 ATH5K_TRACE(ah->ah_sc); 3014 ATH5K_TRACE(ah->ah_sc);
3015
3016 switch (channel->hw_value & CHANNEL_MODES) {
3017 case CHANNEL_A:
3018 case CHANNEL_T:
3019 case CHANNEL_XR:
3020 ee_mode = AR5K_EEPROM_MODE_11A;
3021 break;
3022 case CHANNEL_G:
3023 case CHANNEL_TG:
3024 ee_mode = AR5K_EEPROM_MODE_11G;
3025 break;
3026 case CHANNEL_B:
3027 ee_mode = AR5K_EEPROM_MODE_11B;
3028 break;
3029 default:
3030 ATH5K_ERR(ah->ah_sc,
3031 "invalid channel: %d\n", channel->center_freq);
3032 return -EINVAL;
3033 }
3034
2600 ATH5K_DBG(ah->ah_sc, ATH5K_DEBUG_TXPOWER, 3035 ATH5K_DBG(ah->ah_sc, ATH5K_DEBUG_TXPOWER,
2601 "changing txpower to %d\n", txpower); 3036 "changing txpower to %d\n", txpower);
2602 3037
2603 return ath5k_hw_txpower(ah, channel, mode, txpower); 3038 return ath5k_hw_txpower(ah, channel, ee_mode, txpower);
2604} 3039}
2605 3040
2606#undef _ATH5K_PHY 3041#undef _ATH5K_PHY
diff --git a/drivers/net/wireless/ath/ath5k/qcu.c b/drivers/net/wireless/ath/ath5k/qcu.c
index 5094c394a4b2..73407b3f53ef 100644
--- a/drivers/net/wireless/ath/ath5k/qcu.c
+++ b/drivers/net/wireless/ath/ath5k/qcu.c
@@ -160,7 +160,8 @@ u32 ath5k_hw_num_tx_pending(struct ath5k_hw *ah, unsigned int queue)
160 if (ah->ah_version == AR5K_AR5210) 160 if (ah->ah_version == AR5K_AR5210)
161 return false; 161 return false;
162 162
163 pending = (AR5K_QUEUE_STATUS(queue) & AR5K_QCU_STS_FRMPENDCNT); 163 pending = ath5k_hw_reg_read(ah, AR5K_QUEUE_STATUS(queue));
164 pending &= AR5K_QCU_STS_FRMPENDCNT;
164 165
165 /* It's possible to have no frames pending even if TXE 166 /* It's possible to have no frames pending even if TXE
166 * is set. To indicate that q has not stopped return 167 * is set. To indicate that q has not stopped return
@@ -401,14 +402,16 @@ int ath5k_hw_reset_tx_queue(struct ath5k_hw *ah, unsigned int queue)
401 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_DFS_MISC(queue), 402 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_DFS_MISC(queue),
402 (AR5K_DCU_MISC_ARBLOCK_CTL_GLOBAL << 403 (AR5K_DCU_MISC_ARBLOCK_CTL_GLOBAL <<
403 AR5K_DCU_MISC_ARBLOCK_CTL_S) | 404 AR5K_DCU_MISC_ARBLOCK_CTL_S) |
405 AR5K_DCU_MISC_ARBLOCK_IGNORE |
404 AR5K_DCU_MISC_POST_FR_BKOFF_DIS | 406 AR5K_DCU_MISC_POST_FR_BKOFF_DIS |
405 AR5K_DCU_MISC_BCN_ENABLE); 407 AR5K_DCU_MISC_BCN_ENABLE);
406 break; 408 break;
407 409
408 case AR5K_TX_QUEUE_CAB: 410 case AR5K_TX_QUEUE_CAB:
409 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue), 411 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
410 AR5K_QCU_MISC_FRSHED_DBA_GT | 412 AR5K_QCU_MISC_FRSHED_BCN_SENT_GT |
411 AR5K_QCU_MISC_CBREXP_DIS | 413 AR5K_QCU_MISC_CBREXP_DIS |
414 AR5K_QCU_MISC_RDY_VEOL_POLICY |
412 AR5K_QCU_MISC_CBREXP_BCN_DIS); 415 AR5K_QCU_MISC_CBREXP_BCN_DIS);
413 416
414 ath5k_hw_reg_write(ah, ((AR5K_TUNE_BEACON_INTERVAL - 417 ath5k_hw_reg_write(ah, ((AR5K_TUNE_BEACON_INTERVAL -
diff --git a/drivers/net/wireless/ath/ath5k/reg.h b/drivers/net/wireless/ath/ath5k/reg.h
index 7070d1543cdc..6809b54a2ad7 100644
--- a/drivers/net/wireless/ath/ath5k/reg.h
+++ b/drivers/net/wireless/ath/ath5k/reg.h
@@ -1148,6 +1148,11 @@
1148#define AR5K_STA_ID1_CBCIV_ENDIAN 0x40000000 /* ??? */ 1148#define AR5K_STA_ID1_CBCIV_ENDIAN 0x40000000 /* ??? */
1149#define AR5K_STA_ID1_KEYSRCH_MCAST 0x80000000 /* Do key cache search for mcast frames */ 1149#define AR5K_STA_ID1_KEYSRCH_MCAST 0x80000000 /* Do key cache search for mcast frames */
1150 1150
1151#define AR5K_STA_ID1_ANTENNA_SETTINGS (AR5K_STA_ID1_DEFAULT_ANTENNA | \
1152 AR5K_STA_ID1_DESC_ANTENNA | \
1153 AR5K_STA_ID1_RTS_DEF_ANTENNA | \
1154 AR5K_STA_ID1_SELFGEN_DEF_ANT)
1155
1151/* 1156/*
1152 * First BSSID register (MAC address, lower 32bits) 1157 * First BSSID register (MAC address, lower 32bits)
1153 */ 1158 */
@@ -2028,7 +2033,9 @@
2028#define AR5K_PHY_AGCCTL 0x9860 /* Register address */ 2033#define AR5K_PHY_AGCCTL 0x9860 /* Register address */
2029#define AR5K_PHY_AGCCTL_CAL 0x00000001 /* Enable PHY calibration */ 2034#define AR5K_PHY_AGCCTL_CAL 0x00000001 /* Enable PHY calibration */
2030#define AR5K_PHY_AGCCTL_NF 0x00000002 /* Enable Noise Floor calibration */ 2035#define AR5K_PHY_AGCCTL_NF 0x00000002 /* Enable Noise Floor calibration */
2036#define AR5K_PHY_AGCCTL_OFDM_DIV_DIS 0x00000008 /* Disable antenna diversity on OFDM modes */
2031#define AR5K_PHY_AGCCTL_NF_EN 0x00008000 /* Enable nf calibration to happen (?) */ 2037#define AR5K_PHY_AGCCTL_NF_EN 0x00008000 /* Enable nf calibration to happen (?) */
2038#define AR5K_PHY_AGCTL_FLTR_CAL 0x00010000 /* Allow filter calibration (?) */
2032#define AR5K_PHY_AGCCTL_NF_NOUPDATE 0x00020000 /* Don't update nf automaticaly */ 2039#define AR5K_PHY_AGCCTL_NF_NOUPDATE 0x00020000 /* Don't update nf automaticaly */
2033 2040
2034/* 2041/*
@@ -2528,7 +2535,7 @@
2528 * PHY CCK Cross-correlator Barker RSSI threshold register [5212+] 2535 * PHY CCK Cross-correlator Barker RSSI threshold register [5212+]
2529 */ 2536 */
2530#define AR5K_PHY_CCK_CROSSCORR 0xa208 2537#define AR5K_PHY_CCK_CROSSCORR 0xa208
2531#define AR5K_PHY_CCK_CROSSCORR_WEAK_SIG_THR 0x0000000f 2538#define AR5K_PHY_CCK_CROSSCORR_WEAK_SIG_THR 0x0000003f
2532#define AR5K_PHY_CCK_CROSSCORR_WEAK_SIG_THR_S 0 2539#define AR5K_PHY_CCK_CROSSCORR_WEAK_SIG_THR_S 0
2533 2540
2534/* Same address is used for antenna diversity activation */ 2541/* Same address is used for antenna diversity activation */
diff --git a/drivers/net/wireless/ath/ath5k/reset.c b/drivers/net/wireless/ath/ath5k/reset.c
index 775fdf78554b..c1862f8a2e7b 100644
--- a/drivers/net/wireless/ath/ath5k/reset.c
+++ b/drivers/net/wireless/ath/ath5k/reset.c
@@ -507,7 +507,7 @@ static void ath5k_hw_set_sleep_clock(struct ath5k_hw *ah, bool enable)
507 507
508 if (ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4)) 508 if (ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4))
509 scal = AR5K_PHY_SCAL_32MHZ_2417; 509 scal = AR5K_PHY_SCAL_32MHZ_2417;
510 else if (ath5k_eeprom_is_hb63(ah)) 510 else if (ee->ee_is_hb63)
511 scal = AR5K_PHY_SCAL_32MHZ_HB63; 511 scal = AR5K_PHY_SCAL_32MHZ_HB63;
512 else 512 else
513 scal = AR5K_PHY_SCAL_32MHZ; 513 scal = AR5K_PHY_SCAL_32MHZ;
@@ -536,26 +536,6 @@ static void ath5k_hw_set_sleep_clock(struct ath5k_hw *ah, bool enable)
536 return; 536 return;
537} 537}
538 538
539static bool ath5k_hw_chan_has_spur_noise(struct ath5k_hw *ah,
540 struct ieee80211_channel *channel)
541{
542 u8 refclk_freq;
543
544 if ((ah->ah_radio == AR5K_RF5112) ||
545 (ah->ah_radio == AR5K_RF5413) ||
546 (ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4)))
547 refclk_freq = 40;
548 else
549 refclk_freq = 32;
550
551 if ((channel->center_freq % refclk_freq != 0) &&
552 ((channel->center_freq % refclk_freq < 10) ||
553 (channel->center_freq % refclk_freq > 22)))
554 return true;
555 else
556 return false;
557}
558
559/* TODO: Half/Quarter rate */ 539/* TODO: Half/Quarter rate */
560static void ath5k_hw_tweak_initval_settings(struct ath5k_hw *ah, 540static void ath5k_hw_tweak_initval_settings(struct ath5k_hw *ah,
561 struct ieee80211_channel *channel) 541 struct ieee80211_channel *channel)
@@ -598,9 +578,10 @@ static void ath5k_hw_tweak_initval_settings(struct ath5k_hw *ah,
598 /* Set DAC/ADC delays */ 578 /* Set DAC/ADC delays */
599 if (ah->ah_version == AR5K_AR5212) { 579 if (ah->ah_version == AR5K_AR5212) {
600 u32 scal; 580 u32 scal;
581 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
601 if (ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4)) 582 if (ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4))
602 scal = AR5K_PHY_SCAL_32MHZ_2417; 583 scal = AR5K_PHY_SCAL_32MHZ_2417;
603 else if (ath5k_eeprom_is_hb63(ah)) 584 else if (ee->ee_is_hb63)
604 scal = AR5K_PHY_SCAL_32MHZ_HB63; 585 scal = AR5K_PHY_SCAL_32MHZ_HB63;
605 else 586 else
606 scal = AR5K_PHY_SCAL_32MHZ; 587 scal = AR5K_PHY_SCAL_32MHZ;
@@ -697,13 +678,13 @@ static void ath5k_hw_commit_eeprom_settings(struct ath5k_hw *ah,
697 /* Set antenna idle switch table */ 678 /* Set antenna idle switch table */
698 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_ANT_CTL, 679 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_ANT_CTL,
699 AR5K_PHY_ANT_CTL_SWTABLE_IDLE, 680 AR5K_PHY_ANT_CTL_SWTABLE_IDLE,
700 (ah->ah_antenna[ee_mode][0] | 681 (ah->ah_ant_ctl[ee_mode][0] |
701 AR5K_PHY_ANT_CTL_TXRX_EN)); 682 AR5K_PHY_ANT_CTL_TXRX_EN));
702 683
703 /* Set antenna switch table */ 684 /* Set antenna switch tables */
704 ath5k_hw_reg_write(ah, ah->ah_antenna[ee_mode][ant[0]], 685 ath5k_hw_reg_write(ah, ah->ah_ant_ctl[ee_mode][ant[0]],
705 AR5K_PHY_ANT_SWITCH_TABLE_0); 686 AR5K_PHY_ANT_SWITCH_TABLE_0);
706 ath5k_hw_reg_write(ah, ah->ah_antenna[ee_mode][ant[1]], 687 ath5k_hw_reg_write(ah, ah->ah_ant_ctl[ee_mode][ant[1]],
707 AR5K_PHY_ANT_SWITCH_TABLE_1); 688 AR5K_PHY_ANT_SWITCH_TABLE_1);
708 689
709 /* Noise floor threshold */ 690 /* Noise floor threshold */
@@ -997,10 +978,10 @@ int ath5k_hw_reset(struct ath5k_hw *ah, enum nl80211_iftype op_mode,
997 ath5k_hw_tweak_initval_settings(ah, channel); 978 ath5k_hw_tweak_initval_settings(ah, channel);
998 979
999 /* 980 /*
1000 * Set TX power (FIXME) 981 * Set TX power
1001 */ 982 */
1002 ret = ath5k_hw_txpower(ah, channel, ee_mode, 983 ret = ath5k_hw_txpower(ah, channel, ee_mode,
1003 AR5K_TUNE_DEFAULT_TXPOWER); 984 ah->ah_txpower.txp_max_pwr / 2);
1004 if (ret) 985 if (ret)
1005 return ret; 986 return ret;
1006 987
@@ -1023,9 +1004,22 @@ int ath5k_hw_reset(struct ath5k_hw *ah, enum nl80211_iftype op_mode,
1023 /* Write OFDM timings on 5212*/ 1004 /* Write OFDM timings on 5212*/
1024 if (ah->ah_version == AR5K_AR5212 && 1005 if (ah->ah_version == AR5K_AR5212 &&
1025 channel->hw_value & CHANNEL_OFDM) { 1006 channel->hw_value & CHANNEL_OFDM) {
1007 struct ath5k_eeprom_info *ee =
1008 &ah->ah_capabilities.cap_eeprom;
1009
1026 ret = ath5k_hw_write_ofdm_timings(ah, channel); 1010 ret = ath5k_hw_write_ofdm_timings(ah, channel);
1027 if (ret) 1011 if (ret)
1028 return ret; 1012 return ret;
1013
1014 /* Note: According to docs we can have a newer
1015 * EEPROM on old hardware, so we need to verify
1016 * that our hardware is new enough to have spur
1017 * mitigation registers (delta phase etc) */
1018 if (ah->ah_mac_srev >= AR5K_SREV_AR5424 ||
1019 (ah->ah_mac_srev >= AR5K_SREV_AR5424 &&
1020 ee->ee_version >= AR5K_EEPROM_VERSION_5_3))
1021 ath5k_hw_set_spur_mitigation_filter(ah,
1022 channel);
1029 } 1023 }
1030 1024
1031 /*Enable/disable 802.11b mode on 5111 1025 /*Enable/disable 802.11b mode on 5111
@@ -1041,17 +1035,15 @@ int ath5k_hw_reset(struct ath5k_hw *ah, enum nl80211_iftype op_mode,
1041 1035
1042 /* 1036 /*
1043 * In case a fixed antenna was set as default 1037 * In case a fixed antenna was set as default
1044 * write the same settings on both AR5K_PHY_ANT_SWITCH_TABLE 1038 * use the same switch table twice.
1045 * registers.
1046 */ 1039 */
1047 if (s_ant != 0) { 1040 if (ah->ah_ant_mode == AR5K_ANTMODE_FIXED_A)
1048 if (s_ant == AR5K_ANT_FIXED_A) /* 1 - Main */ 1041 ant[0] = ant[1] = AR5K_ANT_SWTABLE_A;
1049 ant[0] = ant[1] = AR5K_ANT_FIXED_A; 1042 else if (ah->ah_ant_mode == AR5K_ANTMODE_FIXED_B)
1050 else /* 2 - Aux */ 1043 ant[0] = ant[1] = AR5K_ANT_SWTABLE_B;
1051 ant[0] = ant[1] = AR5K_ANT_FIXED_B; 1044 else {
1052 } else { 1045 ant[0] = AR5K_ANT_SWTABLE_A;
1053 ant[0] = AR5K_ANT_FIXED_A; 1046 ant[1] = AR5K_ANT_SWTABLE_B;
1054 ant[1] = AR5K_ANT_FIXED_B;
1055 } 1047 }
1056 1048
1057 /* Commit values from EEPROM */ 1049 /* Commit values from EEPROM */
@@ -1259,6 +1251,8 @@ int ath5k_hw_reset(struct ath5k_hw *ah, enum nl80211_iftype op_mode,
1259 */ 1251 */
1260 ath5k_hw_noise_floor_calibration(ah, channel->center_freq); 1252 ath5k_hw_noise_floor_calibration(ah, channel->center_freq);
1261 1253
1254 /* Restore antenna mode */
1255 ath5k_hw_set_antenna_mode(ah, ah->ah_ant_mode);
1262 1256
1263 /* 1257 /*
1264 * Configure QCUs/DCUs 1258 * Configure QCUs/DCUs
diff --git a/drivers/net/wireless/ath/ath9k/ath9k.h b/drivers/net/wireless/ath/ath9k/ath9k.h
index c92d46fa9d51..10ffc9442859 100644
--- a/drivers/net/wireless/ath/ath9k/ath9k.h
+++ b/drivers/net/wireless/ath/ath9k/ath9k.h
@@ -576,8 +576,8 @@ struct ath_softc {
576 struct ath_tx tx; 576 struct ath_tx tx;
577 struct ath_beacon beacon; 577 struct ath_beacon beacon;
578 struct ieee80211_rate rates[IEEE80211_NUM_BANDS][ATH_RATE_MAX]; 578 struct ieee80211_rate rates[IEEE80211_NUM_BANDS][ATH_RATE_MAX];
579 struct ath_rate_table *hw_rate_table[ATH9K_MODE_MAX]; 579 const struct ath_rate_table *hw_rate_table[ATH9K_MODE_MAX];
580 struct ath_rate_table *cur_rate_table; 580 const struct ath_rate_table *cur_rate_table;
581 struct ieee80211_supported_band sbands[IEEE80211_NUM_BANDS]; 581 struct ieee80211_supported_band sbands[IEEE80211_NUM_BANDS];
582 582
583 struct ath_led radio_led; 583 struct ath_led radio_led;
@@ -590,6 +590,8 @@ struct ath_softc {
590 int led_on_cnt; 590 int led_on_cnt;
591 int led_off_cnt; 591 int led_off_cnt;
592 592
593 int beacon_interval;
594
593 struct ath_rfkill rf_kill; 595 struct ath_rfkill rf_kill;
594 struct ath_ani ani; 596 struct ath_ani ani;
595 struct ath9k_node_stats nodestats; 597 struct ath9k_node_stats nodestats;
@@ -695,36 +697,7 @@ void ath9k_wiphy_pause_all_forced(struct ath_softc *sc,
695bool ath9k_wiphy_scanning(struct ath_softc *sc); 697bool ath9k_wiphy_scanning(struct ath_softc *sc);
696void ath9k_wiphy_work(struct work_struct *work); 698void ath9k_wiphy_work(struct work_struct *work);
697 699
698/* 700void ath9k_iowrite32(struct ath_hw *ah, u32 reg_offset, u32 val);
699 * Read and write, they both share the same lock. We do this to serialize 701unsigned int ath9k_ioread32(struct ath_hw *ah, u32 reg_offset);
700 * reads and writes on Atheros 802.11n PCI devices only. This is required
701 * as the FIFO on these devices can only accept sanely 2 requests. After
702 * that the device goes bananas. Serializing the reads/writes prevents this
703 * from happening.
704 */
705
706static inline void ath9k_iowrite32(struct ath_hw *ah, u32 reg_offset, u32 val)
707{
708 if (ah->config.serialize_regmode == SER_REG_MODE_ON) {
709 unsigned long flags;
710 spin_lock_irqsave(&ah->ah_sc->sc_serial_rw, flags);
711 iowrite32(val, ah->ah_sc->mem + reg_offset);
712 spin_unlock_irqrestore(&ah->ah_sc->sc_serial_rw, flags);
713 } else
714 iowrite32(val, ah->ah_sc->mem + reg_offset);
715}
716
717static inline unsigned int ath9k_ioread32(struct ath_hw *ah, u32 reg_offset)
718{
719 u32 val;
720 if (ah->config.serialize_regmode == SER_REG_MODE_ON) {
721 unsigned long flags;
722 spin_lock_irqsave(&ah->ah_sc->sc_serial_rw, flags);
723 val = ioread32(ah->ah_sc->mem + reg_offset);
724 spin_unlock_irqrestore(&ah->ah_sc->sc_serial_rw, flags);
725 } else
726 val = ioread32(ah->ah_sc->mem + reg_offset);
727 return val;
728}
729 702
730#endif /* ATH9K_H */ 703#endif /* ATH9K_H */
diff --git a/drivers/net/wireless/ath/ath9k/beacon.c b/drivers/net/wireless/ath/ath9k/beacon.c
index eb4759fc6a0d..3a7154beeae1 100644
--- a/drivers/net/wireless/ath/ath9k/beacon.c
+++ b/drivers/net/wireless/ath/ath9k/beacon.c
@@ -63,7 +63,7 @@ static void ath_beacon_setup(struct ath_softc *sc, struct ath_vif *avp,
63 struct ath_hw *ah = sc->sc_ah; 63 struct ath_hw *ah = sc->sc_ah;
64 struct ath_desc *ds; 64 struct ath_desc *ds;
65 struct ath9k_11n_rate_series series[4]; 65 struct ath9k_11n_rate_series series[4];
66 struct ath_rate_table *rt; 66 const struct ath_rate_table *rt;
67 int flags, antenna, ctsrate = 0, ctsduration = 0; 67 int flags, antenna, ctsrate = 0, ctsduration = 0;
68 u8 rate; 68 u8 rate;
69 69
@@ -320,8 +320,7 @@ int ath_beacon_alloc(struct ath_wiphy *aphy, struct ieee80211_vif *vif)
320 u64 tsfadjust; 320 u64 tsfadjust;
321 int intval; 321 int intval;
322 322
323 intval = sc->hw->conf.beacon_int ? 323 intval = sc->beacon_interval ? : ATH_DEFAULT_BINTVAL;
324 sc->hw->conf.beacon_int : ATH_DEFAULT_BINTVAL;
325 324
326 /* 325 /*
327 * Calculate the TSF offset for this beacon slot, i.e., the 326 * Calculate the TSF offset for this beacon slot, i.e., the
@@ -431,8 +430,7 @@ void ath_beacon_tasklet(unsigned long data)
431 * on the tsf to safeguard against missing an swba. 430 * on the tsf to safeguard against missing an swba.
432 */ 431 */
433 432
434 intval = sc->hw->conf.beacon_int ? 433 intval = sc->beacon_interval ? : ATH_DEFAULT_BINTVAL;
435 sc->hw->conf.beacon_int : ATH_DEFAULT_BINTVAL;
436 434
437 tsf = ath9k_hw_gettsf64(ah); 435 tsf = ath9k_hw_gettsf64(ah);
438 tsftu = TSF_TO_TU(tsf>>32, tsf); 436 tsftu = TSF_TO_TU(tsf>>32, tsf);
@@ -711,8 +709,7 @@ void ath_beacon_config(struct ath_softc *sc, struct ieee80211_vif *vif)
711 /* Setup the beacon configuration parameters */ 709 /* Setup the beacon configuration parameters */
712 710
713 memset(&conf, 0, sizeof(struct ath_beacon_config)); 711 memset(&conf, 0, sizeof(struct ath_beacon_config));
714 conf.beacon_interval = sc->hw->conf.beacon_int ? 712 conf.beacon_interval = sc->beacon_interval ? : ATH_DEFAULT_BINTVAL;
715 sc->hw->conf.beacon_int : ATH_DEFAULT_BINTVAL;
716 conf.listen_interval = 1; 713 conf.listen_interval = 1;
717 conf.dtim_period = conf.beacon_interval; 714 conf.dtim_period = conf.beacon_interval;
718 conf.dtim_count = 1; 715 conf.dtim_count = 1;
diff --git a/drivers/net/wireless/ath/ath9k/calib.c b/drivers/net/wireless/ath/ath9k/calib.c
index a197041d76b5..a32d7e7fecbe 100644
--- a/drivers/net/wireless/ath/ath9k/calib.c
+++ b/drivers/net/wireless/ath/ath9k/calib.c
@@ -863,7 +863,7 @@ bool ath9k_hw_calibrate(struct ath_hw *ah, struct ath9k_channel *chan,
863 } 863 }
864 864
865 if (longcal) { 865 if (longcal) {
866 if (AR_SREV_9285(ah) && AR_SREV_9285_11_OR_LATER(ah)) 866 if (AR_SREV_9285_11_OR_LATER(ah))
867 ath9k_hw_9285_pa_cal(ah); 867 ath9k_hw_9285_pa_cal(ah);
868 868
869 if (OLC_FOR_AR9280_20_LATER) 869 if (OLC_FOR_AR9280_20_LATER)
@@ -917,7 +917,7 @@ static bool ar9285_clc(struct ath_hw *ah, struct ath9k_channel *chan)
917 917
918bool ath9k_hw_init_cal(struct ath_hw *ah, struct ath9k_channel *chan) 918bool ath9k_hw_init_cal(struct ath_hw *ah, struct ath9k_channel *chan)
919{ 919{
920 if (AR_SREV_9285(ah) && AR_SREV_9285_12_OR_LATER(ah)) { 920 if (AR_SREV_9285_12_OR_LATER(ah)) {
921 if (!ar9285_clc(ah, chan)) 921 if (!ar9285_clc(ah, chan))
922 return false; 922 return false;
923 } else { 923 } else {
@@ -947,7 +947,7 @@ bool ath9k_hw_init_cal(struct ath_hw *ah, struct ath9k_channel *chan)
947 } 947 }
948 948
949 /* Do PA Calibration */ 949 /* Do PA Calibration */
950 if (AR_SREV_9285(ah) && AR_SREV_9285_11_OR_LATER(ah)) 950 if (AR_SREV_9285_11_OR_LATER(ah))
951 ath9k_hw_9285_pa_cal(ah); 951 ath9k_hw_9285_pa_cal(ah);
952 952
953 /* Do NF Calibration after DC offset and other calibrations */ 953 /* Do NF Calibration after DC offset and other calibrations */
diff --git a/drivers/net/wireless/ath/ath9k/hw.c b/drivers/net/wireless/ath/ath9k/hw.c
index ec2a7a40b00d..5879c731e9e7 100644
--- a/drivers/net/wireless/ath/ath9k/hw.c
+++ b/drivers/net/wireless/ath/ath9k/hw.c
@@ -84,6 +84,38 @@ static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs)
84 return ath9k_hw_mac_clks(ah, usecs); 84 return ath9k_hw_mac_clks(ah, usecs);
85} 85}
86 86
87/*
88 * Read and write, they both share the same lock. We do this to serialize
89 * reads and writes on Atheros 802.11n PCI devices only. This is required
90 * as the FIFO on these devices can only accept sanely 2 requests. After
91 * that the device goes bananas. Serializing the reads/writes prevents this
92 * from happening.
93 */
94
95void ath9k_iowrite32(struct ath_hw *ah, u32 reg_offset, u32 val)
96{
97 if (ah->config.serialize_regmode == SER_REG_MODE_ON) {
98 unsigned long flags;
99 spin_lock_irqsave(&ah->ah_sc->sc_serial_rw, flags);
100 iowrite32(val, ah->ah_sc->mem + reg_offset);
101 spin_unlock_irqrestore(&ah->ah_sc->sc_serial_rw, flags);
102 } else
103 iowrite32(val, ah->ah_sc->mem + reg_offset);
104}
105
106unsigned int ath9k_ioread32(struct ath_hw *ah, u32 reg_offset)
107{
108 u32 val;
109 if (ah->config.serialize_regmode == SER_REG_MODE_ON) {
110 unsigned long flags;
111 spin_lock_irqsave(&ah->ah_sc->sc_serial_rw, flags);
112 val = ioread32(ah->ah_sc->mem + reg_offset);
113 spin_unlock_irqrestore(&ah->ah_sc->sc_serial_rw, flags);
114 } else
115 val = ioread32(ah->ah_sc->mem + reg_offset);
116 return val;
117}
118
87bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout) 119bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout)
88{ 120{
89 int i; 121 int i;
@@ -136,7 +168,7 @@ bool ath9k_get_channel_edges(struct ath_hw *ah,
136} 168}
137 169
138u16 ath9k_hw_computetxtime(struct ath_hw *ah, 170u16 ath9k_hw_computetxtime(struct ath_hw *ah,
139 struct ath_rate_table *rates, 171 const struct ath_rate_table *rates,
140 u32 frameLen, u16 rateix, 172 u32 frameLen, u16 rateix,
141 bool shortPreamble) 173 bool shortPreamble)
142{ 174{
@@ -1313,8 +1345,7 @@ static int ath9k_hw_process_ini(struct ath_hw *ah,
1313 if (AR_SREV_9280(ah)) 1345 if (AR_SREV_9280(ah))
1314 REG_WRITE_ARRAY(&ah->iniModesRxGain, modesIndex, regWrites); 1346 REG_WRITE_ARRAY(&ah->iniModesRxGain, modesIndex, regWrites);
1315 1347
1316 if (AR_SREV_9280(ah) || (AR_SREV_9285(ah) && 1348 if (AR_SREV_9280(ah) || AR_SREV_9285_12_OR_LATER(ah))
1317 AR_SREV_9285_12_OR_LATER(ah)))
1318 REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites); 1349 REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
1319 1350
1320 for (i = 0; i < ah->iniCommon.ia_rows; i++) { 1351 for (i = 0; i < ah->iniCommon.ia_rows; i++) {
diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
index ab3412672e36..ddb24c47ebcf 100644
--- a/drivers/net/wireless/ath/ath9k/hw.h
+++ b/drivers/net/wireless/ath/ath9k/hw.h
@@ -580,7 +580,8 @@ bool ath9k_hw_setantennaswitch(struct ath_hw *ah,
580bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout); 580bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout);
581u32 ath9k_hw_reverse_bits(u32 val, u32 n); 581u32 ath9k_hw_reverse_bits(u32 val, u32 n);
582bool ath9k_get_channel_edges(struct ath_hw *ah, u16 flags, u16 *low, u16 *high); 582bool ath9k_get_channel_edges(struct ath_hw *ah, u16 flags, u16 *low, u16 *high);
583u16 ath9k_hw_computetxtime(struct ath_hw *ah, struct ath_rate_table *rates, 583u16 ath9k_hw_computetxtime(struct ath_hw *ah,
584 const struct ath_rate_table *rates,
584 u32 frameLen, u16 rateix, bool shortPreamble); 585 u32 frameLen, u16 rateix, bool shortPreamble);
585void ath9k_hw_get_channel_centers(struct ath_hw *ah, 586void ath9k_hw_get_channel_centers(struct ath_hw *ah,
586 struct ath9k_channel *chan, 587 struct ath9k_channel *chan,
diff --git a/drivers/net/wireless/ath/ath9k/main.c b/drivers/net/wireless/ath/ath9k/main.c
index 2398d4f45f28..bbbfdcde2727 100644
--- a/drivers/net/wireless/ath/ath9k/main.c
+++ b/drivers/net/wireless/ath/ath9k/main.c
@@ -189,7 +189,7 @@ static u8 parse_mpdudensity(u8 mpdudensity)
189 189
190static void ath_setup_rates(struct ath_softc *sc, enum ieee80211_band band) 190static void ath_setup_rates(struct ath_softc *sc, enum ieee80211_band band)
191{ 191{
192 struct ath_rate_table *rate_table = NULL; 192 const struct ath_rate_table *rate_table = NULL;
193 struct ieee80211_supported_band *sband; 193 struct ieee80211_supported_band *sband;
194 struct ieee80211_rate *rate; 194 struct ieee80211_rate *rate;
195 int i, maxrates; 195 int i, maxrates;
@@ -2358,114 +2358,6 @@ skip_chan_change:
2358 if (changed & IEEE80211_CONF_CHANGE_POWER) 2358 if (changed & IEEE80211_CONF_CHANGE_POWER)
2359 sc->config.txpowlimit = 2 * conf->power_level; 2359 sc->config.txpowlimit = 2 * conf->power_level;
2360 2360
2361 /*
2362 * The HW TSF has to be reset when the beacon interval changes.
2363 * We set the flag here, and ath_beacon_config_ap() would take this
2364 * into account when it gets called through the subsequent
2365 * config_interface() call - with IFCC_BEACON in the changed field.
2366 */
2367
2368 if (changed & IEEE80211_CONF_CHANGE_BEACON_INTERVAL)
2369 sc->sc_flags |= SC_OP_TSF_RESET;
2370
2371 mutex_unlock(&sc->mutex);
2372
2373 return 0;
2374}
2375
2376static int ath9k_config_interface(struct ieee80211_hw *hw,
2377 struct ieee80211_vif *vif,
2378 struct ieee80211_if_conf *conf)
2379{
2380 struct ath_wiphy *aphy = hw->priv;
2381 struct ath_softc *sc = aphy->sc;
2382 struct ath_hw *ah = sc->sc_ah;
2383 struct ath_vif *avp = (void *)vif->drv_priv;
2384 u32 rfilt = 0;
2385 int error, i;
2386
2387 mutex_lock(&sc->mutex);
2388
2389 /* TODO: Need to decide which hw opmode to use for multi-interface
2390 * cases */
2391 if (vif->type == NL80211_IFTYPE_AP &&
2392 ah->opmode != NL80211_IFTYPE_AP) {
2393 ah->opmode = NL80211_IFTYPE_STATION;
2394 ath9k_hw_setopmode(ah);
2395 memcpy(sc->curbssid, sc->sc_ah->macaddr, ETH_ALEN);
2396 sc->curaid = 0;
2397 ath9k_hw_write_associd(sc);
2398 /* Request full reset to get hw opmode changed properly */
2399 sc->sc_flags |= SC_OP_FULL_RESET;
2400 }
2401
2402 if ((conf->changed & IEEE80211_IFCC_BSSID) &&
2403 !is_zero_ether_addr(conf->bssid)) {
2404 switch (vif->type) {
2405 case NL80211_IFTYPE_STATION:
2406 case NL80211_IFTYPE_ADHOC:
2407 case NL80211_IFTYPE_MESH_POINT:
2408 /* Set BSSID */
2409 memcpy(sc->curbssid, conf->bssid, ETH_ALEN);
2410 memcpy(avp->bssid, conf->bssid, ETH_ALEN);
2411 sc->curaid = 0;
2412 ath9k_hw_write_associd(sc);
2413
2414 /* Set aggregation protection mode parameters */
2415 sc->config.ath_aggr_prot = 0;
2416
2417 DPRINTF(sc, ATH_DBG_CONFIG,
2418 "RX filter 0x%x bssid %pM aid 0x%x\n",
2419 rfilt, sc->curbssid, sc->curaid);
2420
2421 /* need to reconfigure the beacon */
2422 sc->sc_flags &= ~SC_OP_BEACONS ;
2423
2424 break;
2425 default:
2426 break;
2427 }
2428 }
2429
2430 if ((vif->type == NL80211_IFTYPE_ADHOC) ||
2431 (vif->type == NL80211_IFTYPE_AP) ||
2432 (vif->type == NL80211_IFTYPE_MESH_POINT)) {
2433 if ((conf->changed & IEEE80211_IFCC_BEACON) ||
2434 (conf->changed & IEEE80211_IFCC_BEACON_ENABLED &&
2435 conf->enable_beacon)) {
2436 /*
2437 * Allocate and setup the beacon frame.
2438 *
2439 * Stop any previous beacon DMA. This may be
2440 * necessary, for example, when an ibss merge
2441 * causes reconfiguration; we may be called
2442 * with beacon transmission active.
2443 */
2444 ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
2445
2446 error = ath_beacon_alloc(aphy, vif);
2447 if (error != 0) {
2448 mutex_unlock(&sc->mutex);
2449 return error;
2450 }
2451
2452 ath_beacon_config(sc, vif);
2453 }
2454 }
2455
2456 /* Check for WLAN_CAPABILITY_PRIVACY ? */
2457 if ((avp->av_opmode != NL80211_IFTYPE_STATION)) {
2458 for (i = 0; i < IEEE80211_WEP_NKID; i++)
2459 if (ath9k_hw_keyisvalid(sc->sc_ah, (u16)i))
2460 ath9k_hw_keysetmac(sc->sc_ah,
2461 (u16)i,
2462 sc->curbssid);
2463 }
2464
2465 /* Only legacy IBSS for now */
2466 if (vif->type == NL80211_IFTYPE_ADHOC)
2467 ath_update_chainmask(sc, 0);
2468
2469 mutex_unlock(&sc->mutex); 2361 mutex_unlock(&sc->mutex);
2470 2362
2471 return 0; 2363 return 0;
@@ -2607,9 +2499,92 @@ static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
2607{ 2499{
2608 struct ath_wiphy *aphy = hw->priv; 2500 struct ath_wiphy *aphy = hw->priv;
2609 struct ath_softc *sc = aphy->sc; 2501 struct ath_softc *sc = aphy->sc;
2502 struct ath_hw *ah = sc->sc_ah;
2503 struct ath_vif *avp = (void *)vif->drv_priv;
2504 u32 rfilt = 0;
2505 int error, i;
2610 2506
2611 mutex_lock(&sc->mutex); 2507 mutex_lock(&sc->mutex);
2612 2508
2509 /*
2510 * TODO: Need to decide which hw opmode to use for
2511 * multi-interface cases
2512 * XXX: This belongs into add_interface!
2513 */
2514 if (vif->type == NL80211_IFTYPE_AP &&
2515 ah->opmode != NL80211_IFTYPE_AP) {
2516 ah->opmode = NL80211_IFTYPE_STATION;
2517 ath9k_hw_setopmode(ah);
2518 memcpy(sc->curbssid, sc->sc_ah->macaddr, ETH_ALEN);
2519 sc->curaid = 0;
2520 ath9k_hw_write_associd(sc);
2521 /* Request full reset to get hw opmode changed properly */
2522 sc->sc_flags |= SC_OP_FULL_RESET;
2523 }
2524
2525 if ((changed & BSS_CHANGED_BSSID) &&
2526 !is_zero_ether_addr(bss_conf->bssid)) {
2527 switch (vif->type) {
2528 case NL80211_IFTYPE_STATION:
2529 case NL80211_IFTYPE_ADHOC:
2530 case NL80211_IFTYPE_MESH_POINT:
2531 /* Set BSSID */
2532 memcpy(sc->curbssid, bss_conf->bssid, ETH_ALEN);
2533 memcpy(avp->bssid, bss_conf->bssid, ETH_ALEN);
2534 sc->curaid = 0;
2535 ath9k_hw_write_associd(sc);
2536
2537 /* Set aggregation protection mode parameters */
2538 sc->config.ath_aggr_prot = 0;
2539
2540 DPRINTF(sc, ATH_DBG_CONFIG,
2541 "RX filter 0x%x bssid %pM aid 0x%x\n",
2542 rfilt, sc->curbssid, sc->curaid);
2543
2544 /* need to reconfigure the beacon */
2545 sc->sc_flags &= ~SC_OP_BEACONS ;
2546
2547 break;
2548 default:
2549 break;
2550 }
2551 }
2552
2553 if ((vif->type == NL80211_IFTYPE_ADHOC) ||
2554 (vif->type == NL80211_IFTYPE_AP) ||
2555 (vif->type == NL80211_IFTYPE_MESH_POINT)) {
2556 if ((changed & BSS_CHANGED_BEACON) ||
2557 (changed & BSS_CHANGED_BEACON_ENABLED &&
2558 bss_conf->enable_beacon)) {
2559 /*
2560 * Allocate and setup the beacon frame.
2561 *
2562 * Stop any previous beacon DMA. This may be
2563 * necessary, for example, when an ibss merge
2564 * causes reconfiguration; we may be called
2565 * with beacon transmission active.
2566 */
2567 ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
2568
2569 error = ath_beacon_alloc(aphy, vif);
2570 if (!error)
2571 ath_beacon_config(sc, vif);
2572 }
2573 }
2574
2575 /* Check for WLAN_CAPABILITY_PRIVACY ? */
2576 if ((avp->av_opmode != NL80211_IFTYPE_STATION)) {
2577 for (i = 0; i < IEEE80211_WEP_NKID; i++)
2578 if (ath9k_hw_keyisvalid(sc->sc_ah, (u16)i))
2579 ath9k_hw_keysetmac(sc->sc_ah,
2580 (u16)i,
2581 sc->curbssid);
2582 }
2583
2584 /* Only legacy IBSS for now */
2585 if (vif->type == NL80211_IFTYPE_ADHOC)
2586 ath_update_chainmask(sc, 0);
2587
2613 if (changed & BSS_CHANGED_ERP_PREAMBLE) { 2588 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
2614 DPRINTF(sc, ATH_DBG_CONFIG, "BSS Changed PREAMBLE %d\n", 2589 DPRINTF(sc, ATH_DBG_CONFIG, "BSS Changed PREAMBLE %d\n",
2615 bss_conf->use_short_preamble); 2590 bss_conf->use_short_preamble);
@@ -2635,6 +2610,18 @@ static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
2635 ath9k_bss_assoc_info(sc, vif, bss_conf); 2610 ath9k_bss_assoc_info(sc, vif, bss_conf);
2636 } 2611 }
2637 2612
2613 /*
2614 * The HW TSF has to be reset when the beacon interval changes.
2615 * We set the flag here, and ath_beacon_config_ap() would take this
2616 * into account when it gets called through the subsequent
2617 * config_interface() call - with IFCC_BEACON in the changed field.
2618 */
2619
2620 if (changed & BSS_CHANGED_BEACON_INT) {
2621 sc->sc_flags |= SC_OP_TSF_RESET;
2622 sc->beacon_interval = bss_conf->beacon_int;
2623 }
2624
2638 mutex_unlock(&sc->mutex); 2625 mutex_unlock(&sc->mutex);
2639} 2626}
2640 2627
@@ -2755,7 +2742,6 @@ struct ieee80211_ops ath9k_ops = {
2755 .add_interface = ath9k_add_interface, 2742 .add_interface = ath9k_add_interface,
2756 .remove_interface = ath9k_remove_interface, 2743 .remove_interface = ath9k_remove_interface,
2757 .config = ath9k_config, 2744 .config = ath9k_config,
2758 .config_interface = ath9k_config_interface,
2759 .configure_filter = ath9k_configure_filter, 2745 .configure_filter = ath9k_configure_filter,
2760 .sta_notify = ath9k_sta_notify, 2746 .sta_notify = ath9k_sta_notify,
2761 .conf_tx = ath9k_conf_tx, 2747 .conf_tx = ath9k_conf_tx,
diff --git a/drivers/net/wireless/ath/ath9k/rc.c b/drivers/net/wireless/ath/ath9k/rc.c
index 8f3cf10f65c4..ba06e78b2f50 100644
--- a/drivers/net/wireless/ath/ath9k/rc.c
+++ b/drivers/net/wireless/ath/ath9k/rc.c
@@ -17,7 +17,7 @@
17 17
18#include "ath9k.h" 18#include "ath9k.h"
19 19
20static struct ath_rate_table ar5416_11na_ratetable = { 20static const struct ath_rate_table ar5416_11na_ratetable = {
21 42, 21 42,
22 { 22 {
23 { VALID, VALID, WLAN_RC_PHY_OFDM, 6000, /* 6 Mb */ 23 { VALID, VALID, WLAN_RC_PHY_OFDM, 6000, /* 6 Mb */
@@ -155,7 +155,7 @@ static struct ath_rate_table ar5416_11na_ratetable = {
155/* 4ms frame limit not used for NG mode. The values filled 155/* 4ms frame limit not used for NG mode. The values filled
156 * for HT are the 64K max aggregate limit */ 156 * for HT are the 64K max aggregate limit */
157 157
158static struct ath_rate_table ar5416_11ng_ratetable = { 158static const struct ath_rate_table ar5416_11ng_ratetable = {
159 46, 159 46,
160 { 160 {
161 { VALID_ALL, VALID_ALL, WLAN_RC_PHY_CCK, 1000, /* 1 Mb */ 161 { VALID_ALL, VALID_ALL, WLAN_RC_PHY_CCK, 1000, /* 1 Mb */
@@ -302,7 +302,7 @@ static struct ath_rate_table ar5416_11ng_ratetable = {
302 WLAN_RC_HT_FLAG, /* Phy rates allowed initially */ 302 WLAN_RC_HT_FLAG, /* Phy rates allowed initially */
303}; 303};
304 304
305static struct ath_rate_table ar5416_11a_ratetable = { 305static const struct ath_rate_table ar5416_11a_ratetable = {
306 8, 306 8,
307 { 307 {
308 { VALID, VALID, WLAN_RC_PHY_OFDM, 6000, /* 6 Mb */ 308 { VALID, VALID, WLAN_RC_PHY_OFDM, 6000, /* 6 Mb */
@@ -335,7 +335,7 @@ static struct ath_rate_table ar5416_11a_ratetable = {
335 0, /* Phy rates allowed initially */ 335 0, /* Phy rates allowed initially */
336}; 336};
337 337
338static struct ath_rate_table ar5416_11g_ratetable = { 338static const struct ath_rate_table ar5416_11g_ratetable = {
339 12, 339 12,
340 { 340 {
341 { VALID, VALID, WLAN_RC_PHY_CCK, 1000, /* 1 Mb */ 341 { VALID, VALID, WLAN_RC_PHY_CCK, 1000, /* 1 Mb */
@@ -380,7 +380,7 @@ static struct ath_rate_table ar5416_11g_ratetable = {
380 0, /* Phy rates allowed initially */ 380 0, /* Phy rates allowed initially */
381}; 381};
382 382
383static struct ath_rate_table ar5416_11b_ratetable = { 383static const struct ath_rate_table ar5416_11b_ratetable = {
384 4, 384 4,
385 { 385 {
386 { VALID, VALID, WLAN_RC_PHY_CCK, 1000, /* 1 Mb */ 386 { VALID, VALID, WLAN_RC_PHY_CCK, 1000, /* 1 Mb */
@@ -420,7 +420,7 @@ static inline int8_t median(int8_t a, int8_t b, int8_t c)
420 } 420 }
421} 421}
422 422
423static void ath_rc_sort_validrates(struct ath_rate_table *rate_table, 423static void ath_rc_sort_validrates(const struct ath_rate_table *rate_table,
424 struct ath_rate_priv *ath_rc_priv) 424 struct ath_rate_priv *ath_rc_priv)
425{ 425{
426 u8 i, j, idx, idx_next; 426 u8 i, j, idx, idx_next;
@@ -461,10 +461,11 @@ static inline int ath_rc_isvalid_txmask(struct ath_rate_priv *ath_rc_priv,
461 return ath_rc_priv->valid_rate_index[index]; 461 return ath_rc_priv->valid_rate_index[index];
462} 462}
463 463
464static inline int ath_rc_get_nextvalid_txrate(struct ath_rate_table *rate_table, 464static inline
465 struct ath_rate_priv *ath_rc_priv, 465int ath_rc_get_nextvalid_txrate(const struct ath_rate_table *rate_table,
466 u8 cur_valid_txrate, 466 struct ath_rate_priv *ath_rc_priv,
467 u8 *next_idx) 467 u8 cur_valid_txrate,
468 u8 *next_idx)
468{ 469{
469 u8 i; 470 u8 i;
470 471
@@ -500,7 +501,7 @@ static int ath_rc_valid_phyrate(u32 phy, u32 capflag, int ignore_cw)
500} 501}
501 502
502static inline int 503static inline int
503ath_rc_get_nextlowervalid_txrate(struct ath_rate_table *rate_table, 504ath_rc_get_nextlowervalid_txrate(const struct ath_rate_table *rate_table,
504 struct ath_rate_priv *ath_rc_priv, 505 struct ath_rate_priv *ath_rc_priv,
505 u8 cur_valid_txrate, u8 *next_idx) 506 u8 cur_valid_txrate, u8 *next_idx)
506{ 507{
@@ -517,7 +518,7 @@ ath_rc_get_nextlowervalid_txrate(struct ath_rate_table *rate_table,
517} 518}
518 519
519static u8 ath_rc_init_validrates(struct ath_rate_priv *ath_rc_priv, 520static u8 ath_rc_init_validrates(struct ath_rate_priv *ath_rc_priv,
520 struct ath_rate_table *rate_table, 521 const struct ath_rate_table *rate_table,
521 u32 capflag) 522 u32 capflag)
522{ 523{
523 u8 i, hi = 0; 524 u8 i, hi = 0;
@@ -547,7 +548,7 @@ static u8 ath_rc_init_validrates(struct ath_rate_priv *ath_rc_priv,
547} 548}
548 549
549static u8 ath_rc_setvalid_rates(struct ath_rate_priv *ath_rc_priv, 550static u8 ath_rc_setvalid_rates(struct ath_rate_priv *ath_rc_priv,
550 struct ath_rate_table *rate_table, 551 const struct ath_rate_table *rate_table,
551 struct ath_rateset *rateset, 552 struct ath_rateset *rateset,
552 u32 capflag) 553 u32 capflag)
553{ 554{
@@ -592,7 +593,7 @@ static u8 ath_rc_setvalid_rates(struct ath_rate_priv *ath_rc_priv,
592} 593}
593 594
594static u8 ath_rc_setvalid_htrates(struct ath_rate_priv *ath_rc_priv, 595static u8 ath_rc_setvalid_htrates(struct ath_rate_priv *ath_rc_priv,
595 struct ath_rate_table *rate_table, 596 const struct ath_rate_table *rate_table,
596 u8 *mcs_set, u32 capflag) 597 u8 *mcs_set, u32 capflag)
597{ 598{
598 struct ath_rateset *rateset = (struct ath_rateset *)mcs_set; 599 struct ath_rateset *rateset = (struct ath_rateset *)mcs_set;
@@ -630,7 +631,7 @@ static u8 ath_rc_setvalid_htrates(struct ath_rate_priv *ath_rc_priv,
630 631
631static u8 ath_rc_ratefind_ht(struct ath_softc *sc, 632static u8 ath_rc_ratefind_ht(struct ath_softc *sc,
632 struct ath_rate_priv *ath_rc_priv, 633 struct ath_rate_priv *ath_rc_priv,
633 struct ath_rate_table *rate_table, 634 const struct ath_rate_table *rate_table,
634 int *is_probing) 635 int *is_probing)
635{ 636{
636 u32 dt, best_thruput, this_thruput, now_msec; 637 u32 dt, best_thruput, this_thruput, now_msec;
@@ -748,7 +749,7 @@ static u8 ath_rc_ratefind_ht(struct ath_softc *sc,
748 return rate; 749 return rate;
749} 750}
750 751
751static void ath_rc_rate_set_series(struct ath_rate_table *rate_table, 752static void ath_rc_rate_set_series(const struct ath_rate_table *rate_table,
752 struct ieee80211_tx_rate *rate, 753 struct ieee80211_tx_rate *rate,
753 struct ieee80211_tx_rate_control *txrc, 754 struct ieee80211_tx_rate_control *txrc,
754 u8 tries, u8 rix, int rtsctsenable) 755 u8 tries, u8 rix, int rtsctsenable)
@@ -769,7 +770,7 @@ static void ath_rc_rate_set_series(struct ath_rate_table *rate_table,
769} 770}
770 771
771static void ath_rc_rate_set_rtscts(struct ath_softc *sc, 772static void ath_rc_rate_set_rtscts(struct ath_softc *sc,
772 struct ath_rate_table *rate_table, 773 const struct ath_rate_table *rate_table,
773 struct ieee80211_tx_info *tx_info) 774 struct ieee80211_tx_info *tx_info)
774{ 775{
775 struct ieee80211_tx_rate *rates = tx_info->control.rates; 776 struct ieee80211_tx_rate *rates = tx_info->control.rates;
@@ -807,7 +808,7 @@ static void ath_rc_rate_set_rtscts(struct ath_softc *sc,
807 808
808static u8 ath_rc_rate_getidx(struct ath_softc *sc, 809static u8 ath_rc_rate_getidx(struct ath_softc *sc,
809 struct ath_rate_priv *ath_rc_priv, 810 struct ath_rate_priv *ath_rc_priv,
810 struct ath_rate_table *rate_table, 811 const struct ath_rate_table *rate_table,
811 u8 rix, u16 stepdown, 812 u8 rix, u16 stepdown,
812 u16 min_rate) 813 u16 min_rate)
813{ 814{
@@ -838,7 +839,7 @@ static void ath_rc_ratefind(struct ath_softc *sc,
838 struct ath_rate_priv *ath_rc_priv, 839 struct ath_rate_priv *ath_rc_priv,
839 struct ieee80211_tx_rate_control *txrc) 840 struct ieee80211_tx_rate_control *txrc)
840{ 841{
841 struct ath_rate_table *rate_table; 842 const struct ath_rate_table *rate_table;
842 struct sk_buff *skb = txrc->skb; 843 struct sk_buff *skb = txrc->skb;
843 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); 844 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
844 struct ieee80211_tx_rate *rates = tx_info->control.rates; 845 struct ieee80211_tx_rate *rates = tx_info->control.rates;
@@ -937,7 +938,7 @@ static void ath_rc_ratefind(struct ath_softc *sc,
937} 938}
938 939
939static bool ath_rc_update_per(struct ath_softc *sc, 940static bool ath_rc_update_per(struct ath_softc *sc,
940 struct ath_rate_table *rate_table, 941 const struct ath_rate_table *rate_table,
941 struct ath_rate_priv *ath_rc_priv, 942 struct ath_rate_priv *ath_rc_priv,
942 struct ath_tx_info_priv *tx_info_priv, 943 struct ath_tx_info_priv *tx_info_priv,
943 int tx_rate, int xretries, int retries, 944 int tx_rate, int xretries, int retries,
@@ -1142,7 +1143,7 @@ static void ath_rc_update_ht(struct ath_softc *sc,
1142 int rate; 1143 int rate;
1143 u8 last_per; 1144 u8 last_per;
1144 bool state_change = false; 1145 bool state_change = false;
1145 struct ath_rate_table *rate_table = sc->cur_rate_table; 1146 const struct ath_rate_table *rate_table = sc->cur_rate_table;
1146 int size = ath_rc_priv->rate_table_size; 1147 int size = ath_rc_priv->rate_table_size;
1147 1148
1148 if ((tx_rate < 0) || (tx_rate > rate_table->rate_cnt)) 1149 if ((tx_rate < 0) || (tx_rate > rate_table->rate_cnt))
@@ -1276,7 +1277,7 @@ static void ath_rc_update_ht(struct ath_softc *sc,
1276#undef CHK_RSSI 1277#undef CHK_RSSI
1277} 1278}
1278 1279
1279static int ath_rc_get_rateindex(struct ath_rate_table *rate_table, 1280static int ath_rc_get_rateindex(const struct ath_rate_table *rate_table,
1280 struct ieee80211_tx_rate *rate) 1281 struct ieee80211_tx_rate *rate)
1281{ 1282{
1282 int rix; 1283 int rix;
@@ -1300,7 +1301,7 @@ static void ath_rc_tx_status(struct ath_softc *sc,
1300 int final_ts_idx, int xretries, int long_retry) 1301 int final_ts_idx, int xretries, int long_retry)
1301{ 1302{
1302 struct ath_tx_info_priv *tx_info_priv = ATH_TX_INFO_PRIV(tx_info); 1303 struct ath_tx_info_priv *tx_info_priv = ATH_TX_INFO_PRIV(tx_info);
1303 struct ath_rate_table *rate_table; 1304 const struct ath_rate_table *rate_table;
1304 struct ieee80211_tx_rate *rates = tx_info->status.rates; 1305 struct ieee80211_tx_rate *rates = tx_info->status.rates;
1305 u8 flags; 1306 u8 flags;
1306 u32 i = 0, rix; 1307 u32 i = 0, rix;
@@ -1354,9 +1355,11 @@ static void ath_rc_tx_status(struct ath_softc *sc,
1354 xretries, long_retry); 1355 xretries, long_retry);
1355} 1356}
1356 1357
1357static struct ath_rate_table *ath_choose_rate_table(struct ath_softc *sc, 1358static const
1358 enum ieee80211_band band, 1359struct ath_rate_table *ath_choose_rate_table(struct ath_softc *sc,
1359 bool is_ht, bool is_cw_40) 1360 enum ieee80211_band band,
1361 bool is_ht,
1362 bool is_cw_40)
1360{ 1363{
1361 int mode = 0; 1364 int mode = 0;
1362 1365
@@ -1390,7 +1393,7 @@ static void ath_rc_init(struct ath_softc *sc,
1390 struct ath_rate_priv *ath_rc_priv, 1393 struct ath_rate_priv *ath_rc_priv,
1391 struct ieee80211_supported_band *sband, 1394 struct ieee80211_supported_band *sband,
1392 struct ieee80211_sta *sta, 1395 struct ieee80211_sta *sta,
1393 struct ath_rate_table *rate_table) 1396 const struct ath_rate_table *rate_table)
1394{ 1397{
1395 struct ath_rateset *rateset = &ath_rc_priv->neg_rates; 1398 struct ath_rateset *rateset = &ath_rc_priv->neg_rates;
1396 u8 *ht_mcs = (u8 *)&ath_rc_priv->neg_ht_rates; 1399 u8 *ht_mcs = (u8 *)&ath_rc_priv->neg_ht_rates;
@@ -1568,12 +1571,13 @@ static void ath_get_rate(void *priv, struct ieee80211_sta *sta, void *priv_sta,
1568 struct ath_rate_priv *ath_rc_priv = priv_sta; 1571 struct ath_rate_priv *ath_rc_priv = priv_sta;
1569 __le16 fc = hdr->frame_control; 1572 __le16 fc = hdr->frame_control;
1570 1573
1571 /* lowest rate for management and multicast/broadcast frames */ 1574 /* lowest rate for management and NO_ACK frames */
1572 if (!ieee80211_is_data(fc) || is_multicast_ether_addr(hdr->addr1) || 1575 if (!ieee80211_is_data(fc) ||
1573 !sta) { 1576 tx_info->flags & IEEE80211_TX_CTL_NO_ACK || !sta) {
1574 tx_info->control.rates[0].idx = rate_lowest_index(sband, sta); 1577 tx_info->control.rates[0].idx = rate_lowest_index(sband, sta);
1575 tx_info->control.rates[0].count = 1578 tx_info->control.rates[0].count =
1576 is_multicast_ether_addr(hdr->addr1) ? 1 : ATH_MGT_TXMAXTRY; 1579 (tx_info->flags & IEEE80211_TX_CTL_NO_ACK) ?
1580 1 : ATH_MGT_TXMAXTRY;
1577 return; 1581 return;
1578 } 1582 }
1579 1583
@@ -1586,7 +1590,7 @@ static void ath_rate_init(void *priv, struct ieee80211_supported_band *sband,
1586{ 1590{
1587 struct ath_softc *sc = priv; 1591 struct ath_softc *sc = priv;
1588 struct ath_rate_priv *ath_rc_priv = priv_sta; 1592 struct ath_rate_priv *ath_rc_priv = priv_sta;
1589 struct ath_rate_table *rate_table = NULL; 1593 const struct ath_rate_table *rate_table = NULL;
1590 bool is_cw40, is_sgi40; 1594 bool is_cw40, is_sgi40;
1591 int i, j = 0; 1595 int i, j = 0;
1592 1596
@@ -1635,7 +1639,7 @@ static void ath_rate_update(void *priv, struct ieee80211_supported_band *sband,
1635{ 1639{
1636 struct ath_softc *sc = priv; 1640 struct ath_softc *sc = priv;
1637 struct ath_rate_priv *ath_rc_priv = priv_sta; 1641 struct ath_rate_priv *ath_rc_priv = priv_sta;
1638 struct ath_rate_table *rate_table = NULL; 1642 const struct ath_rate_table *rate_table = NULL;
1639 bool oper_cw40 = false, oper_sgi40; 1643 bool oper_cw40 = false, oper_sgi40;
1640 bool local_cw40 = (ath_rc_priv->ht_cap & WLAN_RC_40_FLAG) ? 1644 bool local_cw40 = (ath_rc_priv->ht_cap & WLAN_RC_40_FLAG) ?
1641 true : false; 1645 true : false;
diff --git a/drivers/net/wireless/ath/ath9k/xmit.c b/drivers/net/wireless/ath/ath9k/xmit.c
index faf2cab49ea3..41c42824a5ca 100644
--- a/drivers/net/wireless/ath/ath9k/xmit.c
+++ b/drivers/net/wireless/ath/ath9k/xmit.c
@@ -434,7 +434,7 @@ static void ath_tx_complete_aggr(struct ath_softc *sc, struct ath_txq *txq,
434static u32 ath_lookup_rate(struct ath_softc *sc, struct ath_buf *bf, 434static u32 ath_lookup_rate(struct ath_softc *sc, struct ath_buf *bf,
435 struct ath_atx_tid *tid) 435 struct ath_atx_tid *tid)
436{ 436{
437 struct ath_rate_table *rate_table = sc->cur_rate_table; 437 const struct ath_rate_table *rate_table = sc->cur_rate_table;
438 struct sk_buff *skb; 438 struct sk_buff *skb;
439 struct ieee80211_tx_info *tx_info; 439 struct ieee80211_tx_info *tx_info;
440 struct ieee80211_tx_rate *rates; 440 struct ieee80211_tx_rate *rates;
@@ -497,7 +497,7 @@ static u32 ath_lookup_rate(struct ath_softc *sc, struct ath_buf *bf,
497static int ath_compute_num_delims(struct ath_softc *sc, struct ath_atx_tid *tid, 497static int ath_compute_num_delims(struct ath_softc *sc, struct ath_atx_tid *tid,
498 struct ath_buf *bf, u16 frmlen) 498 struct ath_buf *bf, u16 frmlen)
499{ 499{
500 struct ath_rate_table *rt = sc->cur_rate_table; 500 const struct ath_rate_table *rt = sc->cur_rate_table;
501 struct sk_buff *skb = bf->bf_mpdu; 501 struct sk_buff *skb = bf->bf_mpdu;
502 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); 502 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
503 u32 nsymbits, nsymbols, mpdudensity; 503 u32 nsymbits, nsymbols, mpdudensity;
@@ -971,7 +971,7 @@ int ath_cabq_update(struct ath_softc *sc)
971 else if (sc->config.cabqReadytime > ATH9K_READY_TIME_HI_BOUND) 971 else if (sc->config.cabqReadytime > ATH9K_READY_TIME_HI_BOUND)
972 sc->config.cabqReadytime = ATH9K_READY_TIME_HI_BOUND; 972 sc->config.cabqReadytime = ATH9K_READY_TIME_HI_BOUND;
973 973
974 qi.tqi_readyTime = (sc->hw->conf.beacon_int * 974 qi.tqi_readyTime = (sc->beacon_interval *
975 sc->config.cabqReadytime) / 100; 975 sc->config.cabqReadytime) / 100;
976 ath_txq_update(sc, qnum, &qi); 976 ath_txq_update(sc, qnum, &qi);
977 977
@@ -1407,7 +1407,7 @@ static int setup_tx_flags(struct ath_softc *sc, struct sk_buff *skb,
1407static u32 ath_pkt_duration(struct ath_softc *sc, u8 rix, struct ath_buf *bf, 1407static u32 ath_pkt_duration(struct ath_softc *sc, u8 rix, struct ath_buf *bf,
1408 int width, int half_gi, bool shortPreamble) 1408 int width, int half_gi, bool shortPreamble)
1409{ 1409{
1410 struct ath_rate_table *rate_table = sc->cur_rate_table; 1410 const struct ath_rate_table *rate_table = sc->cur_rate_table;
1411 u32 nbits, nsymbits, duration, nsymbols; 1411 u32 nbits, nsymbits, duration, nsymbols;
1412 u8 rc; 1412 u8 rc;
1413 int streams, pktlen; 1413 int streams, pktlen;
@@ -1439,7 +1439,7 @@ static u32 ath_pkt_duration(struct ath_softc *sc, u8 rix, struct ath_buf *bf,
1439 1439
1440static void ath_buf_set_rate(struct ath_softc *sc, struct ath_buf *bf) 1440static void ath_buf_set_rate(struct ath_softc *sc, struct ath_buf *bf)
1441{ 1441{
1442 struct ath_rate_table *rt = sc->cur_rate_table; 1442 const struct ath_rate_table *rt = sc->cur_rate_table;
1443 struct ath9k_11n_rate_series series[4]; 1443 struct ath9k_11n_rate_series series[4];
1444 struct sk_buff *skb; 1444 struct sk_buff *skb;
1445 struct ieee80211_tx_info *tx_info; 1445 struct ieee80211_tx_info *tx_info;
diff --git a/drivers/net/wireless/atmel_cs.c b/drivers/net/wireless/atmel_cs.c
index 77406245dc7b..ddaa859c3491 100644
--- a/drivers/net/wireless/atmel_cs.c
+++ b/drivers/net/wireless/atmel_cs.c
@@ -279,7 +279,7 @@ static int atmel_config(struct pcmcia_device *link)
279 struct pcmcia_device_id *did; 279 struct pcmcia_device_id *did;
280 280
281 dev = link->priv; 281 dev = link->priv;
282 did = handle_to_dev(link).driver_data; 282 did = dev_get_drvdata(&handle_to_dev(link));
283 283
284 DEBUG(0, "atmel_config(0x%p)\n", link); 284 DEBUG(0, "atmel_config(0x%p)\n", link);
285 285
diff --git a/drivers/net/wireless/b43/main.c b/drivers/net/wireless/b43/main.c
index a97c6ff0f12e..2615aaf7df6a 100644
--- a/drivers/net/wireless/b43/main.c
+++ b/drivers/net/wireless/b43/main.c
@@ -3468,11 +3468,6 @@ static int b43_op_config(struct ieee80211_hw *hw, u32 changed)
3468 if (phy->ops->set_rx_antenna) 3468 if (phy->ops->set_rx_antenna)
3469 phy->ops->set_rx_antenna(dev, antenna); 3469 phy->ops->set_rx_antenna(dev, antenna);
3470 3470
3471 /* Update templates for AP/mesh mode. */
3472 if (b43_is_mode(wl, NL80211_IFTYPE_AP) ||
3473 b43_is_mode(wl, NL80211_IFTYPE_MESH_POINT))
3474 b43_set_beacon_int(dev, conf->beacon_int);
3475
3476 if (!!conf->radio_enabled != phy->radio_on) { 3471 if (!!conf->radio_enabled != phy->radio_on) {
3477 if (conf->radio_enabled) { 3472 if (conf->radio_enabled) {
3478 b43_software_rfkill(dev, RFKILL_STATE_UNBLOCKED); 3473 b43_software_rfkill(dev, RFKILL_STATE_UNBLOCKED);
@@ -3548,14 +3543,47 @@ static void b43_op_bss_info_changed(struct ieee80211_hw *hw,
3548{ 3543{
3549 struct b43_wl *wl = hw_to_b43_wl(hw); 3544 struct b43_wl *wl = hw_to_b43_wl(hw);
3550 struct b43_wldev *dev; 3545 struct b43_wldev *dev;
3546 unsigned long flags;
3551 3547
3552 mutex_lock(&wl->mutex); 3548 mutex_lock(&wl->mutex);
3553 3549
3554 dev = wl->current_dev; 3550 dev = wl->current_dev;
3555 if (!dev || b43_status(dev) < B43_STAT_STARTED) 3551 if (!dev || b43_status(dev) < B43_STAT_STARTED)
3556 goto out_unlock_mutex; 3552 goto out_unlock_mutex;
3553
3554 B43_WARN_ON(wl->vif != vif);
3555
3556 if (changed & BSS_CHANGED_BSSID) {
3557 spin_lock_irqsave(&wl->irq_lock, flags);
3558 if (conf->bssid)
3559 memcpy(wl->bssid, conf->bssid, ETH_ALEN);
3560 else
3561 memset(wl->bssid, 0, ETH_ALEN);
3562
3563 if (b43_status(dev) >= B43_STAT_INITIALIZED) {
3564 if (b43_is_mode(wl, NL80211_IFTYPE_AP) ||
3565 b43_is_mode(wl, NL80211_IFTYPE_MESH_POINT)) {
3566 B43_WARN_ON(vif->type != wl->if_type);
3567 if (changed & BSS_CHANGED_BEACON)
3568 b43_update_templates(wl);
3569 } else if (b43_is_mode(wl, NL80211_IFTYPE_ADHOC)) {
3570 if (changed & BSS_CHANGED_BEACON)
3571 b43_update_templates(wl);
3572 }
3573 b43_write_mac_bssid_templates(dev);
3574 }
3575 spin_unlock_irqrestore(&wl->irq_lock, flags);
3576 }
3577
3557 b43_mac_suspend(dev); 3578 b43_mac_suspend(dev);
3558 3579
3580 /* Update templates for AP/mesh mode. */
3581 if (changed & BSS_CHANGED_BEACON_INT &&
3582 (b43_is_mode(wl, NL80211_IFTYPE_AP) ||
3583 b43_is_mode(wl, NL80211_IFTYPE_MESH_POINT) ||
3584 b43_is_mode(wl, NL80211_IFTYPE_ADHOC)))
3585 b43_set_beacon_int(dev, conf->beacon_int);
3586
3559 if (changed & BSS_CHANGED_BASIC_RATES) 3587 if (changed & BSS_CHANGED_BASIC_RATES)
3560 b43_update_basic_rates(dev, conf->basic_rates); 3588 b43_update_basic_rates(dev, conf->basic_rates);
3561 3589
@@ -3569,8 +3597,6 @@ static void b43_op_bss_info_changed(struct ieee80211_hw *hw,
3569 b43_mac_enable(dev); 3597 b43_mac_enable(dev);
3570out_unlock_mutex: 3598out_unlock_mutex:
3571 mutex_unlock(&wl->mutex); 3599 mutex_unlock(&wl->mutex);
3572
3573 return;
3574} 3600}
3575 3601
3576static int b43_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, 3602static int b43_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
@@ -3728,41 +3754,6 @@ static void b43_op_configure_filter(struct ieee80211_hw *hw,
3728 spin_unlock_irqrestore(&wl->irq_lock, flags); 3754 spin_unlock_irqrestore(&wl->irq_lock, flags);
3729} 3755}
3730 3756
3731static int b43_op_config_interface(struct ieee80211_hw *hw,
3732 struct ieee80211_vif *vif,
3733 struct ieee80211_if_conf *conf)
3734{
3735 struct b43_wl *wl = hw_to_b43_wl(hw);
3736 struct b43_wldev *dev = wl->current_dev;
3737 unsigned long flags;
3738
3739 if (!dev)
3740 return -ENODEV;
3741 mutex_lock(&wl->mutex);
3742 spin_lock_irqsave(&wl->irq_lock, flags);
3743 B43_WARN_ON(wl->vif != vif);
3744 if (conf->bssid)
3745 memcpy(wl->bssid, conf->bssid, ETH_ALEN);
3746 else
3747 memset(wl->bssid, 0, ETH_ALEN);
3748 if (b43_status(dev) >= B43_STAT_INITIALIZED) {
3749 if (b43_is_mode(wl, NL80211_IFTYPE_AP) ||
3750 b43_is_mode(wl, NL80211_IFTYPE_MESH_POINT)) {
3751 B43_WARN_ON(vif->type != wl->if_type);
3752 if (conf->changed & IEEE80211_IFCC_BEACON)
3753 b43_update_templates(wl);
3754 } else if (b43_is_mode(wl, NL80211_IFTYPE_ADHOC)) {
3755 if (conf->changed & IEEE80211_IFCC_BEACON)
3756 b43_update_templates(wl);
3757 }
3758 b43_write_mac_bssid_templates(dev);
3759 }
3760 spin_unlock_irqrestore(&wl->irq_lock, flags);
3761 mutex_unlock(&wl->mutex);
3762
3763 return 0;
3764}
3765
3766/* Locking: wl->mutex */ 3757/* Locking: wl->mutex */
3767static void b43_wireless_core_stop(struct b43_wldev *dev) 3758static void b43_wireless_core_stop(struct b43_wldev *dev)
3768{ 3759{
@@ -4432,7 +4423,6 @@ static const struct ieee80211_ops b43_hw_ops = {
4432 .remove_interface = b43_op_remove_interface, 4423 .remove_interface = b43_op_remove_interface,
4433 .config = b43_op_config, 4424 .config = b43_op_config,
4434 .bss_info_changed = b43_op_bss_info_changed, 4425 .bss_info_changed = b43_op_bss_info_changed,
4435 .config_interface = b43_op_config_interface,
4436 .configure_filter = b43_op_configure_filter, 4426 .configure_filter = b43_op_configure_filter,
4437 .set_key = b43_op_set_key, 4427 .set_key = b43_op_set_key,
4438 .get_stats = b43_op_get_stats, 4428 .get_stats = b43_op_get_stats,
diff --git a/drivers/net/wireless/b43legacy/main.c b/drivers/net/wireless/b43legacy/main.c
index ee202b4f77b5..07c7898c87ac 100644
--- a/drivers/net/wireless/b43legacy/main.c
+++ b/drivers/net/wireless/b43legacy/main.c
@@ -2721,11 +2721,6 @@ static int b43legacy_op_dev_config(struct ieee80211_hw *hw,
2721 /* Antennas for RX and management frame TX. */ 2721 /* Antennas for RX and management frame TX. */
2722 b43legacy_mgmtframe_txantenna(dev, antenna_tx); 2722 b43legacy_mgmtframe_txantenna(dev, antenna_tx);
2723 2723
2724 /* Update templates for AP mode. */
2725 if (b43legacy_is_mode(wl, NL80211_IFTYPE_AP))
2726 b43legacy_set_beacon_int(dev, conf->beacon_int);
2727
2728
2729 if (!!conf->radio_enabled != phy->radio_on) { 2724 if (!!conf->radio_enabled != phy->radio_on) {
2730 if (conf->radio_enabled) { 2725 if (conf->radio_enabled) {
2731 b43legacy_radio_turn_on(dev); 2726 b43legacy_radio_turn_on(dev);
@@ -2809,6 +2804,7 @@ static void b43legacy_op_bss_info_changed(struct ieee80211_hw *hw,
2809 u32 savedirqs; 2804 u32 savedirqs;
2810 2805
2811 mutex_lock(&wl->mutex); 2806 mutex_lock(&wl->mutex);
2807 B43legacy_WARN_ON(wl->vif != vif);
2812 2808
2813 dev = wl->current_dev; 2809 dev = wl->current_dev;
2814 phy = &dev->phy; 2810 phy = &dev->phy;
@@ -2822,11 +2818,37 @@ static void b43legacy_op_bss_info_changed(struct ieee80211_hw *hw,
2822 goto out_unlock_mutex; 2818 goto out_unlock_mutex;
2823 } 2819 }
2824 savedirqs = b43legacy_interrupt_disable(dev, B43legacy_IRQ_ALL); 2820 savedirqs = b43legacy_interrupt_disable(dev, B43legacy_IRQ_ALL);
2825 spin_unlock_irqrestore(&wl->irq_lock, flags); 2821
2826 b43legacy_synchronize_irq(dev); 2822 if (changed & BSS_CHANGED_BSSID) {
2823 spin_unlock_irqrestore(&wl->irq_lock, flags);
2824 b43legacy_synchronize_irq(dev);
2825
2826 if (conf->bssid)
2827 memcpy(wl->bssid, conf->bssid, ETH_ALEN);
2828 else
2829 memset(wl->bssid, 0, ETH_ALEN);
2830
2831 if (b43legacy_status(dev) >= B43legacy_STAT_INITIALIZED) {
2832 if (b43legacy_is_mode(wl, NL80211_IFTYPE_AP)) {
2833 B43legacy_WARN_ON(vif->type != NL80211_IFTYPE_AP);
2834 if (changed & BSS_CHANGED_BEACON)
2835 b43legacy_update_templates(wl);
2836 } else if (b43legacy_is_mode(wl, NL80211_IFTYPE_ADHOC)) {
2837 if (changed & BSS_CHANGED_BEACON)
2838 b43legacy_update_templates(wl);
2839 }
2840 b43legacy_write_mac_bssid_templates(dev);
2841 }
2842 spin_unlock_irqrestore(&wl->irq_lock, flags);
2843 }
2827 2844
2828 b43legacy_mac_suspend(dev); 2845 b43legacy_mac_suspend(dev);
2829 2846
2847 if (changed & BSS_CHANGED_BEACON_INT &&
2848 (b43legacy_is_mode(wl, NL80211_IFTYPE_AP) ||
2849 b43legacy_is_mode(wl, NL80211_IFTYPE_ADHOC)))
2850 b43legacy_set_beacon_int(dev, conf->beacon_int);
2851
2830 if (changed & BSS_CHANGED_BASIC_RATES) 2852 if (changed & BSS_CHANGED_BASIC_RATES)
2831 b43legacy_update_basic_rates(dev, conf->basic_rates); 2853 b43legacy_update_basic_rates(dev, conf->basic_rates);
2832 2854
@@ -2846,8 +2868,6 @@ static void b43legacy_op_bss_info_changed(struct ieee80211_hw *hw,
2846 spin_unlock_irqrestore(&wl->irq_lock, flags); 2868 spin_unlock_irqrestore(&wl->irq_lock, flags);
2847 out_unlock_mutex: 2869 out_unlock_mutex:
2848 mutex_unlock(&wl->mutex); 2870 mutex_unlock(&wl->mutex);
2849
2850 return;
2851} 2871}
2852 2872
2853static void b43legacy_op_configure_filter(struct ieee80211_hw *hw, 2873static void b43legacy_op_configure_filter(struct ieee80211_hw *hw,
@@ -2889,40 +2909,6 @@ static void b43legacy_op_configure_filter(struct ieee80211_hw *hw,
2889 spin_unlock_irqrestore(&wl->irq_lock, flags); 2909 spin_unlock_irqrestore(&wl->irq_lock, flags);
2890} 2910}
2891 2911
2892static int b43legacy_op_config_interface(struct ieee80211_hw *hw,
2893 struct ieee80211_vif *vif,
2894 struct ieee80211_if_conf *conf)
2895{
2896 struct b43legacy_wl *wl = hw_to_b43legacy_wl(hw);
2897 struct b43legacy_wldev *dev = wl->current_dev;
2898 unsigned long flags;
2899
2900 if (!dev)
2901 return -ENODEV;
2902 mutex_lock(&wl->mutex);
2903 spin_lock_irqsave(&wl->irq_lock, flags);
2904 B43legacy_WARN_ON(wl->vif != vif);
2905 if (conf->bssid)
2906 memcpy(wl->bssid, conf->bssid, ETH_ALEN);
2907 else
2908 memset(wl->bssid, 0, ETH_ALEN);
2909 if (b43legacy_status(dev) >= B43legacy_STAT_INITIALIZED) {
2910 if (b43legacy_is_mode(wl, NL80211_IFTYPE_AP)) {
2911 B43legacy_WARN_ON(vif->type != NL80211_IFTYPE_AP);
2912 if (conf->changed & IEEE80211_IFCC_BEACON)
2913 b43legacy_update_templates(wl);
2914 } else if (b43legacy_is_mode(wl, NL80211_IFTYPE_ADHOC)) {
2915 if (conf->changed & IEEE80211_IFCC_BEACON)
2916 b43legacy_update_templates(wl);
2917 }
2918 b43legacy_write_mac_bssid_templates(dev);
2919 }
2920 spin_unlock_irqrestore(&wl->irq_lock, flags);
2921 mutex_unlock(&wl->mutex);
2922
2923 return 0;
2924}
2925
2926/* Locking: wl->mutex */ 2912/* Locking: wl->mutex */
2927static void b43legacy_wireless_core_stop(struct b43legacy_wldev *dev) 2913static void b43legacy_wireless_core_stop(struct b43legacy_wldev *dev)
2928{ 2914{
@@ -3563,7 +3549,6 @@ static const struct ieee80211_ops b43legacy_hw_ops = {
3563 .remove_interface = b43legacy_op_remove_interface, 3549 .remove_interface = b43legacy_op_remove_interface,
3564 .config = b43legacy_op_dev_config, 3550 .config = b43legacy_op_dev_config,
3565 .bss_info_changed = b43legacy_op_bss_info_changed, 3551 .bss_info_changed = b43legacy_op_bss_info_changed,
3566 .config_interface = b43legacy_op_config_interface,
3567 .configure_filter = b43legacy_op_configure_filter, 3552 .configure_filter = b43legacy_op_configure_filter,
3568 .get_stats = b43legacy_op_get_stats, 3553 .get_stats = b43legacy_op_get_stats,
3569 .get_tx_stats = b43legacy_op_get_tx_stats, 3554 .get_tx_stats = b43legacy_op_get_tx_stats,
diff --git a/drivers/net/wireless/ipw2x00/ipw2100.c b/drivers/net/wireless/ipw2x00/ipw2100.c
index 97e5647ff050..742432388ca3 100644
--- a/drivers/net/wireless/ipw2x00/ipw2100.c
+++ b/drivers/net/wireless/ipw2x00/ipw2100.c
@@ -3488,7 +3488,7 @@ static DEVICE_ATTR(pci, S_IRUGO, show_pci, NULL);
3488static ssize_t show_cfg(struct device *d, struct device_attribute *attr, 3488static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
3489 char *buf) 3489 char *buf)
3490{ 3490{
3491 struct ipw2100_priv *p = d->driver_data; 3491 struct ipw2100_priv *p = dev_get_drvdata(d);
3492 return sprintf(buf, "0x%08x\n", (int)p->config); 3492 return sprintf(buf, "0x%08x\n", (int)p->config);
3493} 3493}
3494 3494
@@ -3497,7 +3497,7 @@ static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
3497static ssize_t show_status(struct device *d, struct device_attribute *attr, 3497static ssize_t show_status(struct device *d, struct device_attribute *attr,
3498 char *buf) 3498 char *buf)
3499{ 3499{
3500 struct ipw2100_priv *p = d->driver_data; 3500 struct ipw2100_priv *p = dev_get_drvdata(d);
3501 return sprintf(buf, "0x%08x\n", (int)p->status); 3501 return sprintf(buf, "0x%08x\n", (int)p->status);
3502} 3502}
3503 3503
@@ -3506,7 +3506,7 @@ static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
3506static ssize_t show_capability(struct device *d, struct device_attribute *attr, 3506static ssize_t show_capability(struct device *d, struct device_attribute *attr,
3507 char *buf) 3507 char *buf)
3508{ 3508{
3509 struct ipw2100_priv *p = d->driver_data; 3509 struct ipw2100_priv *p = dev_get_drvdata(d);
3510 return sprintf(buf, "0x%08x\n", (int)p->capability); 3510 return sprintf(buf, "0x%08x\n", (int)p->capability);
3511} 3511}
3512 3512
@@ -4224,7 +4224,7 @@ static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
4224 1 - SW based RF kill active (sysfs) 4224 1 - SW based RF kill active (sysfs)
4225 2 - HW based RF kill active 4225 2 - HW based RF kill active
4226 3 - Both HW and SW baed RF kill active */ 4226 3 - Both HW and SW baed RF kill active */
4227 struct ipw2100_priv *priv = (struct ipw2100_priv *)d->driver_data; 4227 struct ipw2100_priv *priv = dev_get_drvdata(d);
4228 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) | 4228 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
4229 (rf_kill_active(priv) ? 0x2 : 0x0); 4229 (rf_kill_active(priv) ? 0x2 : 0x0);
4230 return sprintf(buf, "%i\n", val); 4230 return sprintf(buf, "%i\n", val);
diff --git a/drivers/net/wireless/ipw2x00/ipw2200.c b/drivers/net/wireless/ipw2x00/ipw2200.c
index 9a123fbcc359..c3b3dfe43d1a 100644
--- a/drivers/net/wireless/ipw2x00/ipw2200.c
+++ b/drivers/net/wireless/ipw2x00/ipw2200.c
@@ -1527,7 +1527,7 @@ static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led);
1527static ssize_t show_status(struct device *d, 1527static ssize_t show_status(struct device *d,
1528 struct device_attribute *attr, char *buf) 1528 struct device_attribute *attr, char *buf)
1529{ 1529{
1530 struct ipw_priv *p = d->driver_data; 1530 struct ipw_priv *p = dev_get_drvdata(d);
1531 return sprintf(buf, "0x%08x\n", (int)p->status); 1531 return sprintf(buf, "0x%08x\n", (int)p->status);
1532} 1532}
1533 1533
@@ -1536,7 +1536,7 @@ static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
1536static ssize_t show_cfg(struct device *d, struct device_attribute *attr, 1536static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
1537 char *buf) 1537 char *buf)
1538{ 1538{
1539 struct ipw_priv *p = d->driver_data; 1539 struct ipw_priv *p = dev_get_drvdata(d);
1540 return sprintf(buf, "0x%08x\n", (int)p->config); 1540 return sprintf(buf, "0x%08x\n", (int)p->config);
1541} 1541}
1542 1542
@@ -1545,7 +1545,7 @@ static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
1545static ssize_t show_nic_type(struct device *d, 1545static ssize_t show_nic_type(struct device *d,
1546 struct device_attribute *attr, char *buf) 1546 struct device_attribute *attr, char *buf)
1547{ 1547{
1548 struct ipw_priv *priv = d->driver_data; 1548 struct ipw_priv *priv = dev_get_drvdata(d);
1549 return sprintf(buf, "TYPE: %d\n", priv->nic_type); 1549 return sprintf(buf, "TYPE: %d\n", priv->nic_type);
1550} 1550}
1551 1551
@@ -1555,7 +1555,7 @@ static ssize_t show_ucode_version(struct device *d,
1555 struct device_attribute *attr, char *buf) 1555 struct device_attribute *attr, char *buf)
1556{ 1556{
1557 u32 len = sizeof(u32), tmp = 0; 1557 u32 len = sizeof(u32), tmp = 0;
1558 struct ipw_priv *p = d->driver_data; 1558 struct ipw_priv *p = dev_get_drvdata(d);
1559 1559
1560 if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len)) 1560 if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len))
1561 return 0; 1561 return 0;
@@ -1569,7 +1569,7 @@ static ssize_t show_rtc(struct device *d, struct device_attribute *attr,
1569 char *buf) 1569 char *buf)
1570{ 1570{
1571 u32 len = sizeof(u32), tmp = 0; 1571 u32 len = sizeof(u32), tmp = 0;
1572 struct ipw_priv *p = d->driver_data; 1572 struct ipw_priv *p = dev_get_drvdata(d);
1573 1573
1574 if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len)) 1574 if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len))
1575 return 0; 1575 return 0;
@@ -1586,14 +1586,15 @@ static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL);
1586static ssize_t show_eeprom_delay(struct device *d, 1586static ssize_t show_eeprom_delay(struct device *d,
1587 struct device_attribute *attr, char *buf) 1587 struct device_attribute *attr, char *buf)
1588{ 1588{
1589 int n = ((struct ipw_priv *)d->driver_data)->eeprom_delay; 1589 struct ipw_priv *p = dev_get_drvdata(d);
1590 int n = p->eeprom_delay;
1590 return sprintf(buf, "%i\n", n); 1591 return sprintf(buf, "%i\n", n);
1591} 1592}
1592static ssize_t store_eeprom_delay(struct device *d, 1593static ssize_t store_eeprom_delay(struct device *d,
1593 struct device_attribute *attr, 1594 struct device_attribute *attr,
1594 const char *buf, size_t count) 1595 const char *buf, size_t count)
1595{ 1596{
1596 struct ipw_priv *p = d->driver_data; 1597 struct ipw_priv *p = dev_get_drvdata(d);
1597 sscanf(buf, "%i", &p->eeprom_delay); 1598 sscanf(buf, "%i", &p->eeprom_delay);
1598 return strnlen(buf, count); 1599 return strnlen(buf, count);
1599} 1600}
@@ -1605,7 +1606,7 @@ static ssize_t show_command_event_reg(struct device *d,
1605 struct device_attribute *attr, char *buf) 1606 struct device_attribute *attr, char *buf)
1606{ 1607{
1607 u32 reg = 0; 1608 u32 reg = 0;
1608 struct ipw_priv *p = d->driver_data; 1609 struct ipw_priv *p = dev_get_drvdata(d);
1609 1610
1610 reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT); 1611 reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT);
1611 return sprintf(buf, "0x%08x\n", reg); 1612 return sprintf(buf, "0x%08x\n", reg);
@@ -1615,7 +1616,7 @@ static ssize_t store_command_event_reg(struct device *d,
1615 const char *buf, size_t count) 1616 const char *buf, size_t count)
1616{ 1617{
1617 u32 reg; 1618 u32 reg;
1618 struct ipw_priv *p = d->driver_data; 1619 struct ipw_priv *p = dev_get_drvdata(d);
1619 1620
1620 sscanf(buf, "%x", &reg); 1621 sscanf(buf, "%x", &reg);
1621 ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg); 1622 ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg);
@@ -1629,7 +1630,7 @@ static ssize_t show_mem_gpio_reg(struct device *d,
1629 struct device_attribute *attr, char *buf) 1630 struct device_attribute *attr, char *buf)
1630{ 1631{
1631 u32 reg = 0; 1632 u32 reg = 0;
1632 struct ipw_priv *p = d->driver_data; 1633 struct ipw_priv *p = dev_get_drvdata(d);
1633 1634
1634 reg = ipw_read_reg32(p, 0x301100); 1635 reg = ipw_read_reg32(p, 0x301100);
1635 return sprintf(buf, "0x%08x\n", reg); 1636 return sprintf(buf, "0x%08x\n", reg);
@@ -1639,7 +1640,7 @@ static ssize_t store_mem_gpio_reg(struct device *d,
1639 const char *buf, size_t count) 1640 const char *buf, size_t count)
1640{ 1641{
1641 u32 reg; 1642 u32 reg;
1642 struct ipw_priv *p = d->driver_data; 1643 struct ipw_priv *p = dev_get_drvdata(d);
1643 1644
1644 sscanf(buf, "%x", &reg); 1645 sscanf(buf, "%x", &reg);
1645 ipw_write_reg32(p, 0x301100, reg); 1646 ipw_write_reg32(p, 0x301100, reg);
@@ -1653,7 +1654,7 @@ static ssize_t show_indirect_dword(struct device *d,
1653 struct device_attribute *attr, char *buf) 1654 struct device_attribute *attr, char *buf)
1654{ 1655{
1655 u32 reg = 0; 1656 u32 reg = 0;
1656 struct ipw_priv *priv = d->driver_data; 1657 struct ipw_priv *priv = dev_get_drvdata(d);
1657 1658
1658 if (priv->status & STATUS_INDIRECT_DWORD) 1659 if (priv->status & STATUS_INDIRECT_DWORD)
1659 reg = ipw_read_reg32(priv, priv->indirect_dword); 1660 reg = ipw_read_reg32(priv, priv->indirect_dword);
@@ -1666,7 +1667,7 @@ static ssize_t store_indirect_dword(struct device *d,
1666 struct device_attribute *attr, 1667 struct device_attribute *attr,
1667 const char *buf, size_t count) 1668 const char *buf, size_t count)
1668{ 1669{
1669 struct ipw_priv *priv = d->driver_data; 1670 struct ipw_priv *priv = dev_get_drvdata(d);
1670 1671
1671 sscanf(buf, "%x", &priv->indirect_dword); 1672 sscanf(buf, "%x", &priv->indirect_dword);
1672 priv->status |= STATUS_INDIRECT_DWORD; 1673 priv->status |= STATUS_INDIRECT_DWORD;
@@ -1680,7 +1681,7 @@ static ssize_t show_indirect_byte(struct device *d,
1680 struct device_attribute *attr, char *buf) 1681 struct device_attribute *attr, char *buf)
1681{ 1682{
1682 u8 reg = 0; 1683 u8 reg = 0;
1683 struct ipw_priv *priv = d->driver_data; 1684 struct ipw_priv *priv = dev_get_drvdata(d);
1684 1685
1685 if (priv->status & STATUS_INDIRECT_BYTE) 1686 if (priv->status & STATUS_INDIRECT_BYTE)
1686 reg = ipw_read_reg8(priv, priv->indirect_byte); 1687 reg = ipw_read_reg8(priv, priv->indirect_byte);
@@ -1693,7 +1694,7 @@ static ssize_t store_indirect_byte(struct device *d,
1693 struct device_attribute *attr, 1694 struct device_attribute *attr,
1694 const char *buf, size_t count) 1695 const char *buf, size_t count)
1695{ 1696{
1696 struct ipw_priv *priv = d->driver_data; 1697 struct ipw_priv *priv = dev_get_drvdata(d);
1697 1698
1698 sscanf(buf, "%x", &priv->indirect_byte); 1699 sscanf(buf, "%x", &priv->indirect_byte);
1699 priv->status |= STATUS_INDIRECT_BYTE; 1700 priv->status |= STATUS_INDIRECT_BYTE;
@@ -1707,7 +1708,7 @@ static ssize_t show_direct_dword(struct device *d,
1707 struct device_attribute *attr, char *buf) 1708 struct device_attribute *attr, char *buf)
1708{ 1709{
1709 u32 reg = 0; 1710 u32 reg = 0;
1710 struct ipw_priv *priv = d->driver_data; 1711 struct ipw_priv *priv = dev_get_drvdata(d);
1711 1712
1712 if (priv->status & STATUS_DIRECT_DWORD) 1713 if (priv->status & STATUS_DIRECT_DWORD)
1713 reg = ipw_read32(priv, priv->direct_dword); 1714 reg = ipw_read32(priv, priv->direct_dword);
@@ -1720,7 +1721,7 @@ static ssize_t store_direct_dword(struct device *d,
1720 struct device_attribute *attr, 1721 struct device_attribute *attr,
1721 const char *buf, size_t count) 1722 const char *buf, size_t count)
1722{ 1723{
1723 struct ipw_priv *priv = d->driver_data; 1724 struct ipw_priv *priv = dev_get_drvdata(d);
1724 1725
1725 sscanf(buf, "%x", &priv->direct_dword); 1726 sscanf(buf, "%x", &priv->direct_dword);
1726 priv->status |= STATUS_DIRECT_DWORD; 1727 priv->status |= STATUS_DIRECT_DWORD;
@@ -1747,7 +1748,7 @@ static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
1747 1 - SW based RF kill active (sysfs) 1748 1 - SW based RF kill active (sysfs)
1748 2 - HW based RF kill active 1749 2 - HW based RF kill active
1749 3 - Both HW and SW baed RF kill active */ 1750 3 - Both HW and SW baed RF kill active */
1750 struct ipw_priv *priv = d->driver_data; 1751 struct ipw_priv *priv = dev_get_drvdata(d);
1751 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) | 1752 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
1752 (rf_kill_active(priv) ? 0x2 : 0x0); 1753 (rf_kill_active(priv) ? 0x2 : 0x0);
1753 return sprintf(buf, "%i\n", val); 1754 return sprintf(buf, "%i\n", val);
@@ -1791,7 +1792,7 @@ static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio)
1791static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr, 1792static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
1792 const char *buf, size_t count) 1793 const char *buf, size_t count)
1793{ 1794{
1794 struct ipw_priv *priv = d->driver_data; 1795 struct ipw_priv *priv = dev_get_drvdata(d);
1795 1796
1796 ipw_radio_kill_sw(priv, buf[0] == '1'); 1797 ipw_radio_kill_sw(priv, buf[0] == '1');
1797 1798
@@ -1803,7 +1804,7 @@ static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
1803static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr, 1804static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr,
1804 char *buf) 1805 char *buf)
1805{ 1806{
1806 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data; 1807 struct ipw_priv *priv = dev_get_drvdata(d);
1807 int pos = 0, len = 0; 1808 int pos = 0, len = 0;
1808 if (priv->config & CFG_SPEED_SCAN) { 1809 if (priv->config & CFG_SPEED_SCAN) {
1809 while (priv->speed_scan[pos] != 0) 1810 while (priv->speed_scan[pos] != 0)
@@ -1818,7 +1819,7 @@ static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr,
1818static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr, 1819static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr,
1819 const char *buf, size_t count) 1820 const char *buf, size_t count)
1820{ 1821{
1821 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data; 1822 struct ipw_priv *priv = dev_get_drvdata(d);
1822 int channel, pos = 0; 1823 int channel, pos = 0;
1823 const char *p = buf; 1824 const char *p = buf;
1824 1825
@@ -1857,14 +1858,14 @@ static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan,
1857static ssize_t show_net_stats(struct device *d, struct device_attribute *attr, 1858static ssize_t show_net_stats(struct device *d, struct device_attribute *attr,
1858 char *buf) 1859 char *buf)
1859{ 1860{
1860 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data; 1861 struct ipw_priv *priv = dev_get_drvdata(d);
1861 return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0'); 1862 return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0');
1862} 1863}
1863 1864
1864static ssize_t store_net_stats(struct device *d, struct device_attribute *attr, 1865static ssize_t store_net_stats(struct device *d, struct device_attribute *attr,
1865 const char *buf, size_t count) 1866 const char *buf, size_t count)
1866{ 1867{
1867 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data; 1868 struct ipw_priv *priv = dev_get_drvdata(d);
1868 if (buf[0] == '1') 1869 if (buf[0] == '1')
1869 priv->config |= CFG_NET_STATS; 1870 priv->config |= CFG_NET_STATS;
1870 else 1871 else
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945-rs.c b/drivers/net/wireless/iwlwifi/iwl-3945-rs.c
index f63a9c5ba262..814afaf6d10b 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945-rs.c
+++ b/drivers/net/wireless/iwlwifi/iwl-3945-rs.c
@@ -683,11 +683,10 @@ static void rs_get_rate(void *priv_r, struct ieee80211_sta *sta,
683 if (sta) 683 if (sta)
684 rate_mask = sta->supp_rates[sband->band]; 684 rate_mask = sta->supp_rates[sband->band];
685 685
686 /* Send management frames and broadcast/multicast data using lowest 686 /* Send management frames and NO_ACK data using lowest rate. */
687 * rate. */
688 fc = le16_to_cpu(hdr->frame_control); 687 fc = le16_to_cpu(hdr->frame_control);
689 if ((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA || 688 if ((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA ||
690 is_multicast_ether_addr(hdr->addr1) || 689 info->flags & IEEE80211_TX_CTL_NO_ACK ||
691 !sta || !priv_sta) { 690 !sta || !priv_sta) {
692 IWL_DEBUG_RATE(priv, "leave: No STA priv data to update!\n"); 691 IWL_DEBUG_RATE(priv, "leave: No STA priv data to update!\n");
693 if (!rate_mask) 692 if (!rate_mask)
@@ -696,6 +695,8 @@ static void rs_get_rate(void *priv_r, struct ieee80211_sta *sta,
696 else 695 else
697 info->control.rates[0].idx = 696 info->control.rates[0].idx =
698 rate_lowest_index(sband, sta); 697 rate_lowest_index(sband, sta);
698 if (info->flags & IEEE80211_TX_CTL_NO_ACK)
699 info->control.rates[0].count = 1;
699 return; 700 return;
700 } 701 }
701 702
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
index 3504279c7586..0a71bb55d0ee 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
@@ -172,7 +172,7 @@ struct iwl_lq_sta {
172}; 172};
173 173
174static void rs_rate_scale_perform(struct iwl_priv *priv, 174static void rs_rate_scale_perform(struct iwl_priv *priv,
175 struct ieee80211_hdr *hdr, 175 struct sk_buff *skb,
176 struct ieee80211_sta *sta, 176 struct ieee80211_sta *sta,
177 struct iwl_lq_sta *lq_sta); 177 struct iwl_lq_sta *lq_sta);
178static void rs_fill_link_cmd(const struct iwl_priv *priv, 178static void rs_fill_link_cmd(const struct iwl_priv *priv,
@@ -829,7 +829,7 @@ static void rs_tx_status(void *priv_r, struct ieee80211_supported_band *sband,
829 IWL_DEBUG_RATE_LIMIT(priv, "get frame ack response, update rate scale window\n"); 829 IWL_DEBUG_RATE_LIMIT(priv, "get frame ack response, update rate scale window\n");
830 830
831 if (!ieee80211_is_data(hdr->frame_control) || 831 if (!ieee80211_is_data(hdr->frame_control) ||
832 is_multicast_ether_addr(hdr->addr1)) 832 info->flags & IEEE80211_TX_CTL_NO_ACK)
833 return; 833 return;
834 834
835 /* This packet was aggregated but doesn't carry rate scale info */ 835 /* This packet was aggregated but doesn't carry rate scale info */
@@ -995,7 +995,7 @@ static void rs_tx_status(void *priv_r, struct ieee80211_supported_band *sband,
995 995
996 /* See if there's a better rate or modulation mode to try. */ 996 /* See if there's a better rate or modulation mode to try. */
997 if (sta && sta->supp_rates[sband->band]) 997 if (sta && sta->supp_rates[sband->band])
998 rs_rate_scale_perform(priv, hdr, sta, lq_sta); 998 rs_rate_scale_perform(priv, skb, sta, lq_sta);
999out: 999out:
1000 return; 1000 return;
1001} 1001}
@@ -1207,8 +1207,7 @@ static int rs_switch_to_mimo2(struct iwl_priv *priv,
1207 tbl->action = 0; 1207 tbl->action = 0;
1208 rate_mask = lq_sta->active_mimo2_rate; 1208 rate_mask = lq_sta->active_mimo2_rate;
1209 1209
1210 if (priv->current_ht_config.supported_chan_width 1210 if (iwl_is_fat_tx_allowed(priv, &sta->ht_cap))
1211 == IWL_CHANNEL_WIDTH_40MHZ)
1212 tbl->is_fat = 1; 1211 tbl->is_fat = 1;
1213 else 1212 else
1214 tbl->is_fat = 0; 1213 tbl->is_fat = 0;
@@ -1273,8 +1272,7 @@ static int rs_switch_to_mimo3(struct iwl_priv *priv,
1273 tbl->action = 0; 1272 tbl->action = 0;
1274 rate_mask = lq_sta->active_mimo3_rate; 1273 rate_mask = lq_sta->active_mimo3_rate;
1275 1274
1276 if (priv->current_ht_config.supported_chan_width 1275 if (iwl_is_fat_tx_allowed(priv, &sta->ht_cap))
1277 == IWL_CHANNEL_WIDTH_40MHZ)
1278 tbl->is_fat = 1; 1276 tbl->is_fat = 1;
1279 else 1277 else
1280 tbl->is_fat = 0; 1278 tbl->is_fat = 0;
@@ -1332,8 +1330,7 @@ static int rs_switch_to_siso(struct iwl_priv *priv,
1332 tbl->action = 0; 1330 tbl->action = 0;
1333 rate_mask = lq_sta->active_siso_rate; 1331 rate_mask = lq_sta->active_siso_rate;
1334 1332
1335 if (priv->current_ht_config.supported_chan_width 1333 if (iwl_is_fat_tx_allowed(priv, &sta->ht_cap))
1336 == IWL_CHANNEL_WIDTH_40MHZ)
1337 tbl->is_fat = 1; 1334 tbl->is_fat = 1;
1338 else 1335 else
1339 tbl->is_fat = 0; 1336 tbl->is_fat = 0;
@@ -1975,12 +1972,14 @@ static void rs_stay_in_table(struct iwl_lq_sta *lq_sta)
1975 * Do rate scaling and search for new modulation mode. 1972 * Do rate scaling and search for new modulation mode.
1976 */ 1973 */
1977static void rs_rate_scale_perform(struct iwl_priv *priv, 1974static void rs_rate_scale_perform(struct iwl_priv *priv,
1978 struct ieee80211_hdr *hdr, 1975 struct sk_buff *skb,
1979 struct ieee80211_sta *sta, 1976 struct ieee80211_sta *sta,
1980 struct iwl_lq_sta *lq_sta) 1977 struct iwl_lq_sta *lq_sta)
1981{ 1978{
1982 struct ieee80211_hw *hw = priv->hw; 1979 struct ieee80211_hw *hw = priv->hw;
1983 struct ieee80211_conf *conf = &hw->conf; 1980 struct ieee80211_conf *conf = &hw->conf;
1981 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1982 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1984 int low = IWL_RATE_INVALID; 1983 int low = IWL_RATE_INVALID;
1985 int high = IWL_RATE_INVALID; 1984 int high = IWL_RATE_INVALID;
1986 int index; 1985 int index;
@@ -2006,11 +2005,10 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
2006 2005
2007 IWL_DEBUG_RATE(priv, "rate scale calculate new rate for skb\n"); 2006 IWL_DEBUG_RATE(priv, "rate scale calculate new rate for skb\n");
2008 2007
2009 /* Send management frames and broadcast/multicast data using 2008 /* Send management frames and NO_ACK data using lowest rate. */
2010 * lowest rate. */
2011 /* TODO: this could probably be improved.. */ 2009 /* TODO: this could probably be improved.. */
2012 if (!ieee80211_is_data(hdr->frame_control) || 2010 if (!ieee80211_is_data(hdr->frame_control) ||
2013 is_multicast_ether_addr(hdr->addr1)) 2011 info->flags & IEEE80211_TX_CTL_NO_ACK)
2014 return; 2012 return;
2015 2013
2016 if (!sta || !lq_sta) 2014 if (!sta || !lq_sta)
@@ -2450,16 +2448,17 @@ static void rs_get_rate(void *priv_r, struct ieee80211_sta *sta, void *priv_sta,
2450 if (sta) 2448 if (sta)
2451 mask_bit = sta->supp_rates[sband->band]; 2449 mask_bit = sta->supp_rates[sband->band];
2452 2450
2453 /* Send management frames and broadcast/multicast data using lowest 2451 /* Send management frames and NO_ACK data using lowest rate. */
2454 * rate. */
2455 if (!ieee80211_is_data(hdr->frame_control) || 2452 if (!ieee80211_is_data(hdr->frame_control) ||
2456 is_multicast_ether_addr(hdr->addr1) || !sta || !lq_sta) { 2453 info->flags & IEEE80211_TX_CTL_NO_ACK || !sta || !lq_sta) {
2457 if (!mask_bit) 2454 if (!mask_bit)
2458 info->control.rates[0].idx = 2455 info->control.rates[0].idx =
2459 rate_lowest_index(sband, NULL); 2456 rate_lowest_index(sband, NULL);
2460 else 2457 else
2461 info->control.rates[0].idx = 2458 info->control.rates[0].idx =
2462 rate_lowest_index(sband, sta); 2459 rate_lowest_index(sband, sta);
2460 if (info->flags & IEEE80211_TX_CTL_NO_ACK)
2461 info->control.rates[0].count = 1;
2463 return; 2462 return;
2464 } 2463 }
2465 2464
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.c b/drivers/net/wireless/iwlwifi/iwl-agn.c
index 277dfc57fde9..6cdee0b4b486 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn.c
@@ -567,7 +567,8 @@ static void iwl_setup_rxon_timing(struct iwl_priv *priv)
567 beacon_int = iwl_adjust_beacon_interval(priv->beacon_int); 567 beacon_int = iwl_adjust_beacon_interval(priv->beacon_int);
568 priv->rxon_timing.atim_window = 0; 568 priv->rxon_timing.atim_window = 0;
569 } else { 569 } else {
570 beacon_int = iwl_adjust_beacon_interval(conf->beacon_int); 570 beacon_int = iwl_adjust_beacon_interval(
571 priv->vif->bss_conf.beacon_int);
571 572
572 /* TODO: we need to get atim_window from upper stack 573 /* TODO: we need to get atim_window from upper stack
573 * for now we set to 0 */ 574 * for now we set to 0 */
@@ -2267,7 +2268,7 @@ static int iwl_mac_get_stats(struct ieee80211_hw *hw,
2267static ssize_t show_debug_level(struct device *d, 2268static ssize_t show_debug_level(struct device *d,
2268 struct device_attribute *attr, char *buf) 2269 struct device_attribute *attr, char *buf)
2269{ 2270{
2270 struct iwl_priv *priv = d->driver_data; 2271 struct iwl_priv *priv = dev_get_drvdata(d);
2271 2272
2272 return sprintf(buf, "0x%08X\n", priv->debug_level); 2273 return sprintf(buf, "0x%08X\n", priv->debug_level);
2273} 2274}
@@ -2275,7 +2276,7 @@ static ssize_t store_debug_level(struct device *d,
2275 struct device_attribute *attr, 2276 struct device_attribute *attr,
2276 const char *buf, size_t count) 2277 const char *buf, size_t count)
2277{ 2278{
2278 struct iwl_priv *priv = d->driver_data; 2279 struct iwl_priv *priv = dev_get_drvdata(d);
2279 unsigned long val; 2280 unsigned long val;
2280 int ret; 2281 int ret;
2281 2282
@@ -2298,7 +2299,7 @@ static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
2298static ssize_t show_version(struct device *d, 2299static ssize_t show_version(struct device *d,
2299 struct device_attribute *attr, char *buf) 2300 struct device_attribute *attr, char *buf)
2300{ 2301{
2301 struct iwl_priv *priv = d->driver_data; 2302 struct iwl_priv *priv = dev_get_drvdata(d);
2302 struct iwl_alive_resp *palive = &priv->card_alive; 2303 struct iwl_alive_resp *palive = &priv->card_alive;
2303 ssize_t pos = 0; 2304 ssize_t pos = 0;
2304 u16 eeprom_ver; 2305 u16 eeprom_ver;
@@ -2329,7 +2330,7 @@ static DEVICE_ATTR(version, S_IWUSR | S_IRUGO, show_version, NULL);
2329static ssize_t show_temperature(struct device *d, 2330static ssize_t show_temperature(struct device *d,
2330 struct device_attribute *attr, char *buf) 2331 struct device_attribute *attr, char *buf)
2331{ 2332{
2332 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; 2333 struct iwl_priv *priv = dev_get_drvdata(d);
2333 2334
2334 if (!iwl_is_alive(priv)) 2335 if (!iwl_is_alive(priv))
2335 return -EAGAIN; 2336 return -EAGAIN;
@@ -2342,7 +2343,7 @@ static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
2342static ssize_t show_tx_power(struct device *d, 2343static ssize_t show_tx_power(struct device *d,
2343 struct device_attribute *attr, char *buf) 2344 struct device_attribute *attr, char *buf)
2344{ 2345{
2345 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; 2346 struct iwl_priv *priv = dev_get_drvdata(d);
2346 2347
2347 if (!iwl_is_ready_rf(priv)) 2348 if (!iwl_is_ready_rf(priv))
2348 return sprintf(buf, "off\n"); 2349 return sprintf(buf, "off\n");
@@ -2354,7 +2355,7 @@ static ssize_t store_tx_power(struct device *d,
2354 struct device_attribute *attr, 2355 struct device_attribute *attr,
2355 const char *buf, size_t count) 2356 const char *buf, size_t count)
2356{ 2357{
2357 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; 2358 struct iwl_priv *priv = dev_get_drvdata(d);
2358 unsigned long val; 2359 unsigned long val;
2359 int ret; 2360 int ret;
2360 2361
@@ -2372,7 +2373,7 @@ static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
2372static ssize_t show_flags(struct device *d, 2373static ssize_t show_flags(struct device *d,
2373 struct device_attribute *attr, char *buf) 2374 struct device_attribute *attr, char *buf)
2374{ 2375{
2375 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; 2376 struct iwl_priv *priv = dev_get_drvdata(d);
2376 2377
2377 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags); 2378 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
2378} 2379}
@@ -2381,7 +2382,7 @@ static ssize_t store_flags(struct device *d,
2381 struct device_attribute *attr, 2382 struct device_attribute *attr,
2382 const char *buf, size_t count) 2383 const char *buf, size_t count)
2383{ 2384{
2384 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; 2385 struct iwl_priv *priv = dev_get_drvdata(d);
2385 unsigned long val; 2386 unsigned long val;
2386 u32 flags; 2387 u32 flags;
2387 int ret = strict_strtoul(buf, 0, &val); 2388 int ret = strict_strtoul(buf, 0, &val);
@@ -2410,7 +2411,7 @@ static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
2410static ssize_t show_filter_flags(struct device *d, 2411static ssize_t show_filter_flags(struct device *d,
2411 struct device_attribute *attr, char *buf) 2412 struct device_attribute *attr, char *buf)
2412{ 2413{
2413 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; 2414 struct iwl_priv *priv = dev_get_drvdata(d);
2414 2415
2415 return sprintf(buf, "0x%04X\n", 2416 return sprintf(buf, "0x%04X\n",
2416 le32_to_cpu(priv->active_rxon.filter_flags)); 2417 le32_to_cpu(priv->active_rxon.filter_flags));
@@ -2420,7 +2421,7 @@ static ssize_t store_filter_flags(struct device *d,
2420 struct device_attribute *attr, 2421 struct device_attribute *attr,
2421 const char *buf, size_t count) 2422 const char *buf, size_t count)
2422{ 2423{
2423 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; 2424 struct iwl_priv *priv = dev_get_drvdata(d);
2424 unsigned long val; 2425 unsigned long val;
2425 u32 filter_flags; 2426 u32 filter_flags;
2426 int ret = strict_strtoul(buf, 0, &val); 2427 int ret = strict_strtoul(buf, 0, &val);
@@ -2622,7 +2623,6 @@ static struct ieee80211_ops iwl_hw_ops = {
2622 .add_interface = iwl_mac_add_interface, 2623 .add_interface = iwl_mac_add_interface,
2623 .remove_interface = iwl_mac_remove_interface, 2624 .remove_interface = iwl_mac_remove_interface,
2624 .config = iwl_mac_config, 2625 .config = iwl_mac_config,
2625 .config_interface = iwl_mac_config_interface,
2626 .configure_filter = iwl_configure_filter, 2626 .configure_filter = iwl_configure_filter,
2627 .set_key = iwl_mac_set_key, 2627 .set_key = iwl_mac_set_key,
2628 .update_tkip_key = iwl_mac_update_tkip_key, 2628 .update_tkip_key = iwl_mac_update_tkip_key,
diff --git a/drivers/net/wireless/iwlwifi/iwl-core.c b/drivers/net/wireless/iwlwifi/iwl-core.c
index 3dec2d25fa3d..1366222bb50a 100644
--- a/drivers/net/wireless/iwlwifi/iwl-core.c
+++ b/drivers/net/wireless/iwlwifi/iwl-core.c
@@ -1298,8 +1298,7 @@ int iwl_setup_mac(struct iwl_priv *priv)
1298 hw->flags = IEEE80211_HW_SIGNAL_DBM | 1298 hw->flags = IEEE80211_HW_SIGNAL_DBM |
1299 IEEE80211_HW_NOISE_DBM | 1299 IEEE80211_HW_NOISE_DBM |
1300 IEEE80211_HW_AMPDU_AGGREGATION | 1300 IEEE80211_HW_AMPDU_AGGREGATION |
1301 IEEE80211_HW_SPECTRUM_MGMT | 1301 IEEE80211_HW_SPECTRUM_MGMT;
1302 IEEE80211_HW_SUPPORTS_PS;
1303 hw->wiphy->interface_modes = 1302 hw->wiphy->interface_modes =
1304 BIT(NL80211_IFTYPE_STATION) | 1303 BIT(NL80211_IFTYPE_STATION) |
1305 BIT(NL80211_IFTYPE_ADHOC); 1304 BIT(NL80211_IFTYPE_ADHOC);
@@ -1313,7 +1312,6 @@ int iwl_setup_mac(struct iwl_priv *priv)
1313 /* Default value; 4 EDCA QOS priorities */ 1312 /* Default value; 4 EDCA QOS priorities */
1314 hw->queues = 4; 1313 hw->queues = 4;
1315 1314
1316 hw->conf.beacon_int = 100;
1317 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL; 1315 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
1318 1316
1319 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels) 1317 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
@@ -2239,15 +2237,69 @@ static void iwl_ht_conf(struct iwl_priv *priv,
2239 2237
2240#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6) 2238#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
2241void iwl_bss_info_changed(struct ieee80211_hw *hw, 2239void iwl_bss_info_changed(struct ieee80211_hw *hw,
2242 struct ieee80211_vif *vif, 2240 struct ieee80211_vif *vif,
2243 struct ieee80211_bss_conf *bss_conf, 2241 struct ieee80211_bss_conf *bss_conf,
2244 u32 changes) 2242 u32 changes)
2245{ 2243{
2246 struct iwl_priv *priv = hw->priv; 2244 struct iwl_priv *priv = hw->priv;
2247 int ret; 2245 int ret;
2248 2246
2249 IWL_DEBUG_MAC80211(priv, "changes = 0x%X\n", changes); 2247 IWL_DEBUG_MAC80211(priv, "changes = 0x%X\n", changes);
2250 2248
2249 if (!iwl_is_alive(priv))
2250 return;
2251
2252 mutex_lock(&priv->mutex);
2253
2254 if (changes & BSS_CHANGED_BEACON &&
2255 priv->iw_mode == NL80211_IFTYPE_AP) {
2256 dev_kfree_skb(priv->ibss_beacon);
2257 priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
2258 }
2259
2260 if ((changes & BSS_CHANGED_BSSID) && !iwl_is_rfkill(priv)) {
2261 /* If there is currently a HW scan going on in the background
2262 * then we need to cancel it else the RXON below will fail. */
2263 if (iwl_scan_cancel_timeout(priv, 100)) {
2264 IWL_WARN(priv, "Aborted scan still in progress "
2265 "after 100ms\n");
2266 IWL_DEBUG_MAC80211(priv, "leaving - scan abort failed.\n");
2267 mutex_unlock(&priv->mutex);
2268 return;
2269 }
2270 memcpy(priv->staging_rxon.bssid_addr,
2271 bss_conf->bssid, ETH_ALEN);
2272
2273 /* TODO: Audit driver for usage of these members and see
2274 * if mac80211 deprecates them (priv->bssid looks like it
2275 * shouldn't be there, but I haven't scanned the IBSS code
2276 * to verify) - jpk */
2277 memcpy(priv->bssid, bss_conf->bssid, ETH_ALEN);
2278
2279 if (priv->iw_mode == NL80211_IFTYPE_AP)
2280 iwlcore_config_ap(priv);
2281 else {
2282 int rc = iwlcore_commit_rxon(priv);
2283 if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc)
2284 iwl_rxon_add_station(
2285 priv, priv->active_rxon.bssid_addr, 1);
2286 }
2287 } else if (!iwl_is_rfkill(priv)) {
2288 iwl_scan_cancel_timeout(priv, 100);
2289 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2290 iwlcore_commit_rxon(priv);
2291 }
2292
2293 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
2294 changes & BSS_CHANGED_BEACON) {
2295 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
2296
2297 if (beacon)
2298 iwl_mac_beacon_update(hw, beacon);
2299 }
2300
2301 mutex_unlock(&priv->mutex);
2302
2251 if (changes & BSS_CHANGED_ERP_PREAMBLE) { 2303 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
2252 IWL_DEBUG_MAC80211(priv, "ERP_PREAMBLE %d\n", 2304 IWL_DEBUG_MAC80211(priv, "ERP_PREAMBLE %d\n",
2253 bss_conf->use_short_preamble); 2305 bss_conf->use_short_preamble);
@@ -2306,7 +2358,7 @@ void iwl_bss_info_changed(struct ieee80211_hw *hw,
2306 &priv->staging_rxon, 2358 &priv->staging_rxon,
2307 sizeof(struct iwl_rxon_cmd)); 2359 sizeof(struct iwl_rxon_cmd));
2308 } 2360 }
2309 2361 IWL_DEBUG_MAC80211(priv, "leave\n");
2310} 2362}
2311EXPORT_SYMBOL(iwl_bss_info_changed); 2363EXPORT_SYMBOL(iwl_bss_info_changed);
2312 2364
@@ -2590,106 +2642,6 @@ out:
2590} 2642}
2591EXPORT_SYMBOL(iwl_mac_config); 2643EXPORT_SYMBOL(iwl_mac_config);
2592 2644
2593int iwl_mac_config_interface(struct ieee80211_hw *hw,
2594 struct ieee80211_vif *vif,
2595 struct ieee80211_if_conf *conf)
2596{
2597 struct iwl_priv *priv = hw->priv;
2598 int rc;
2599
2600 if (conf == NULL)
2601 return -EIO;
2602
2603 if (priv->vif != vif) {
2604 IWL_DEBUG_MAC80211(priv, "leave - priv->vif != vif\n");
2605 return 0;
2606 }
2607
2608 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
2609 conf->changed & IEEE80211_IFCC_BEACON) {
2610 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
2611 if (!beacon)
2612 return -ENOMEM;
2613 mutex_lock(&priv->mutex);
2614 rc = iwl_mac_beacon_update(hw, beacon);
2615 mutex_unlock(&priv->mutex);
2616 if (rc)
2617 return rc;
2618 }
2619
2620 if (!iwl_is_alive(priv))
2621 return -EAGAIN;
2622
2623 mutex_lock(&priv->mutex);
2624
2625 if (conf->bssid)
2626 IWL_DEBUG_MAC80211(priv, "bssid: %pM\n", conf->bssid);
2627
2628/*
2629 * very dubious code was here; the probe filtering flag is never set:
2630 *
2631 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
2632 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
2633 */
2634
2635 if (priv->iw_mode == NL80211_IFTYPE_AP) {
2636 if (!conf->bssid) {
2637 conf->bssid = priv->mac_addr;
2638 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
2639 IWL_DEBUG_MAC80211(priv, "bssid was set to: %pM\n",
2640 conf->bssid);
2641 }
2642 if (priv->ibss_beacon)
2643 dev_kfree_skb(priv->ibss_beacon);
2644
2645 priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
2646 }
2647
2648 if (iwl_is_rfkill(priv))
2649 goto done;
2650
2651 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
2652 !is_multicast_ether_addr(conf->bssid)) {
2653 /* If there is currently a HW scan going on in the background
2654 * then we need to cancel it else the RXON below will fail. */
2655 if (iwl_scan_cancel_timeout(priv, 100)) {
2656 IWL_WARN(priv, "Aborted scan still in progress "
2657 "after 100ms\n");
2658 IWL_DEBUG_MAC80211(priv, "leaving - scan abort failed.\n");
2659 mutex_unlock(&priv->mutex);
2660 return -EAGAIN;
2661 }
2662 memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
2663
2664 /* TODO: Audit driver for usage of these members and see
2665 * if mac80211 deprecates them (priv->bssid looks like it
2666 * shouldn't be there, but I haven't scanned the IBSS code
2667 * to verify) - jpk */
2668 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
2669
2670 if (priv->iw_mode == NL80211_IFTYPE_AP)
2671 iwlcore_config_ap(priv);
2672 else {
2673 rc = iwlcore_commit_rxon(priv);
2674 if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc)
2675 iwl_rxon_add_station(
2676 priv, priv->active_rxon.bssid_addr, 1);
2677 }
2678
2679 } else {
2680 iwl_scan_cancel_timeout(priv, 100);
2681 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2682 iwlcore_commit_rxon(priv);
2683 }
2684
2685 done:
2686 IWL_DEBUG_MAC80211(priv, "leave\n");
2687 mutex_unlock(&priv->mutex);
2688
2689 return 0;
2690}
2691EXPORT_SYMBOL(iwl_mac_config_interface);
2692
2693int iwl_mac_get_tx_stats(struct ieee80211_hw *hw, 2645int iwl_mac_get_tx_stats(struct ieee80211_hw *hw,
2694 struct ieee80211_tx_queue_stats *stats) 2646 struct ieee80211_tx_queue_stats *stats)
2695{ 2647{
@@ -2751,7 +2703,7 @@ void iwl_mac_reset_tsf(struct ieee80211_hw *hw)
2751 2703
2752 priv->ibss_beacon = NULL; 2704 priv->ibss_beacon = NULL;
2753 2705
2754 priv->beacon_int = priv->hw->conf.beacon_int; 2706 priv->beacon_int = priv->vif->bss_conf.beacon_int;
2755 priv->timestamp = 0; 2707 priv->timestamp = 0;
2756 if ((priv->iw_mode == NL80211_IFTYPE_STATION)) 2708 if ((priv->iw_mode == NL80211_IFTYPE_STATION))
2757 priv->beacon_int = 0; 2709 priv->beacon_int = 0;
diff --git a/drivers/net/wireless/iwlwifi/iwl-core.h b/drivers/net/wireless/iwlwifi/iwl-core.h
index d4c60afa2891..bd7f9d9616bc 100644
--- a/drivers/net/wireless/iwlwifi/iwl-core.h
+++ b/drivers/net/wireless/iwlwifi/iwl-core.h
@@ -281,9 +281,6 @@ void iwl_mac_remove_interface(struct ieee80211_hw *hw,
281 struct ieee80211_if_init_conf *conf); 281 struct ieee80211_if_init_conf *conf);
282int iwl_mac_config(struct ieee80211_hw *hw, u32 changed); 282int iwl_mac_config(struct ieee80211_hw *hw, u32 changed);
283void iwl_config_ap(struct iwl_priv *priv); 283void iwl_config_ap(struct iwl_priv *priv);
284int iwl_mac_config_interface(struct ieee80211_hw *hw,
285 struct ieee80211_vif *vif,
286 struct ieee80211_if_conf *conf);
287int iwl_mac_get_tx_stats(struct ieee80211_hw *hw, 284int iwl_mac_get_tx_stats(struct ieee80211_hw *hw,
288 struct ieee80211_tx_queue_stats *stats); 285 struct ieee80211_tx_queue_stats *stats);
289void iwl_mac_reset_tsf(struct ieee80211_hw *hw); 286void iwl_mac_reset_tsf(struct ieee80211_hw *hw);
diff --git a/drivers/net/wireless/iwlwifi/iwl-sta.c b/drivers/net/wireless/iwlwifi/iwl-sta.c
index 0072ea2c5361..0eb939c40ac1 100644
--- a/drivers/net/wireless/iwlwifi/iwl-sta.c
+++ b/drivers/net/wireless/iwlwifi/iwl-sta.c
@@ -490,7 +490,7 @@ void iwl_clear_stations_table(struct iwl_priv *priv)
490 /* keep track of static keys */ 490 /* keep track of static keys */
491 for (i = 0; i < WEP_KEYS_MAX ; i++) { 491 for (i = 0; i < WEP_KEYS_MAX ; i++) {
492 if (priv->wep_keys[i].key_size) 492 if (priv->wep_keys[i].key_size)
493 test_and_set_bit(i, &priv->ucode_key_table); 493 set_bit(i, &priv->ucode_key_table);
494 } 494 }
495 495
496 spin_unlock_irqrestore(&priv->sta_lock, flags); 496 spin_unlock_irqrestore(&priv->sta_lock, flags);
diff --git a/drivers/net/wireless/iwlwifi/iwl3945-base.c b/drivers/net/wireless/iwlwifi/iwl3945-base.c
index 6b42ea2a1f1d..f6c1489a0c4a 100644
--- a/drivers/net/wireless/iwlwifi/iwl3945-base.c
+++ b/drivers/net/wireless/iwlwifi/iwl3945-base.c
@@ -551,7 +551,8 @@ static void iwl3945_setup_rxon_timing(struct iwl_priv *priv)
551 priv->rxon_timing.atim_window = 0; 551 priv->rxon_timing.atim_window = 0;
552 } else { 552 } else {
553 priv->rxon_timing.beacon_interval = 553 priv->rxon_timing.beacon_interval =
554 iwl3945_adjust_beacon_interval(conf->beacon_int); 554 iwl3945_adjust_beacon_interval(
555 priv->vif->bss_conf.beacon_int);
555 /* TODO: we need to get atim_window from upper stack 556 /* TODO: we need to get atim_window from upper stack
556 * for now we set to 0 */ 557 * for now we set to 0 */
557 priv->rxon_timing.atim_window = 0; 558 priv->rxon_timing.atim_window = 0;
@@ -1343,15 +1344,24 @@ static void iwl3945_rx_allocate(struct iwl_priv *priv)
1343 struct list_head *element; 1344 struct list_head *element;
1344 struct iwl_rx_mem_buffer *rxb; 1345 struct iwl_rx_mem_buffer *rxb;
1345 unsigned long flags; 1346 unsigned long flags;
1346 spin_lock_irqsave(&rxq->lock, flags); 1347
1347 while (!list_empty(&rxq->rx_used)) { 1348 while (1) {
1349 spin_lock_irqsave(&rxq->lock, flags);
1350
1351 if (list_empty(&rxq->rx_used)) {
1352 spin_unlock_irqrestore(&rxq->lock, flags);
1353 return;
1354 }
1355
1348 element = rxq->rx_used.next; 1356 element = rxq->rx_used.next;
1349 rxb = list_entry(element, struct iwl_rx_mem_buffer, list); 1357 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
1358 list_del(element);
1359 spin_unlock_irqrestore(&rxq->lock, flags);
1350 1360
1351 /* Alloc a new receive buffer */ 1361 /* Alloc a new receive buffer */
1352 rxb->skb = 1362 rxb->skb =
1353 alloc_skb(priv->hw_params.rx_buf_size, 1363 alloc_skb(priv->hw_params.rx_buf_size,
1354 __GFP_NOWARN | GFP_ATOMIC); 1364 GFP_KERNEL);
1355 if (!rxb->skb) { 1365 if (!rxb->skb) {
1356 if (net_ratelimit()) 1366 if (net_ratelimit())
1357 IWL_CRIT(priv, ": Can not allocate SKB buffers\n"); 1367 IWL_CRIT(priv, ": Can not allocate SKB buffers\n");
@@ -1369,18 +1379,18 @@ static void iwl3945_rx_allocate(struct iwl_priv *priv)
1369 */ 1379 */
1370 skb_reserve(rxb->skb, 4); 1380 skb_reserve(rxb->skb, 4);
1371 1381
1372 priv->alloc_rxb_skb++;
1373 list_del(element);
1374
1375 /* Get physical address of RB/SKB */ 1382 /* Get physical address of RB/SKB */
1376 rxb->real_dma_addr = pci_map_single(priv->pci_dev, 1383 rxb->real_dma_addr = pci_map_single(priv->pci_dev,
1377 rxb->skb->data, 1384 rxb->skb->data,
1378 priv->hw_params.rx_buf_size, 1385 priv->hw_params.rx_buf_size,
1379 PCI_DMA_FROMDEVICE); 1386 PCI_DMA_FROMDEVICE);
1387
1388 spin_lock_irqsave(&rxq->lock, flags);
1380 list_add_tail(&rxb->list, &rxq->rx_free); 1389 list_add_tail(&rxb->list, &rxq->rx_free);
1390 priv->alloc_rxb_skb++;
1381 rxq->free_count++; 1391 rxq->free_count++;
1392 spin_unlock_irqrestore(&rxq->lock, flags);
1382 } 1393 }
1383 spin_unlock_irqrestore(&rxq->lock, flags);
1384} 1394}
1385 1395
1386void iwl3945_rx_queue_reset(struct iwl_priv *priv, struct iwl_rx_queue *rxq) 1396void iwl3945_rx_queue_reset(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
@@ -1413,18 +1423,6 @@ void iwl3945_rx_queue_reset(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
1413 spin_unlock_irqrestore(&rxq->lock, flags); 1423 spin_unlock_irqrestore(&rxq->lock, flags);
1414} 1424}
1415 1425
1416/*
1417 * this should be called while priv->lock is locked
1418 */
1419static void __iwl3945_rx_replenish(void *data)
1420{
1421 struct iwl_priv *priv = data;
1422
1423 iwl3945_rx_allocate(priv);
1424 iwl3945_rx_queue_restock(priv);
1425}
1426
1427
1428void iwl3945_rx_replenish(void *data) 1426void iwl3945_rx_replenish(void *data)
1429{ 1427{
1430 struct iwl_priv *priv = data; 1428 struct iwl_priv *priv = data;
@@ -1642,7 +1640,7 @@ static void iwl3945_rx_handle(struct iwl_priv *priv)
1642 count++; 1640 count++;
1643 if (count >= 8) { 1641 if (count >= 8) {
1644 priv->rxq.read = i; 1642 priv->rxq.read = i;
1645 __iwl3945_rx_replenish(priv); 1643 iwl3945_rx_queue_restock(priv);
1646 count = 0; 1644 count = 0;
1647 } 1645 }
1648 } 1646 }
@@ -3596,7 +3594,7 @@ static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3596static ssize_t show_debug_level(struct device *d, 3594static ssize_t show_debug_level(struct device *d,
3597 struct device_attribute *attr, char *buf) 3595 struct device_attribute *attr, char *buf)
3598{ 3596{
3599 struct iwl_priv *priv = d->driver_data; 3597 struct iwl_priv *priv = dev_get_drvdata(d);
3600 3598
3601 return sprintf(buf, "0x%08X\n", priv->debug_level); 3599 return sprintf(buf, "0x%08X\n", priv->debug_level);
3602} 3600}
@@ -3604,7 +3602,7 @@ static ssize_t store_debug_level(struct device *d,
3604 struct device_attribute *attr, 3602 struct device_attribute *attr,
3605 const char *buf, size_t count) 3603 const char *buf, size_t count)
3606{ 3604{
3607 struct iwl_priv *priv = d->driver_data; 3605 struct iwl_priv *priv = dev_get_drvdata(d);
3608 unsigned long val; 3606 unsigned long val;
3609 int ret; 3607 int ret;
3610 3608
@@ -3625,7 +3623,7 @@ static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
3625static ssize_t show_temperature(struct device *d, 3623static ssize_t show_temperature(struct device *d,
3626 struct device_attribute *attr, char *buf) 3624 struct device_attribute *attr, char *buf)
3627{ 3625{
3628 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; 3626 struct iwl_priv *priv = dev_get_drvdata(d);
3629 3627
3630 if (!iwl_is_alive(priv)) 3628 if (!iwl_is_alive(priv))
3631 return -EAGAIN; 3629 return -EAGAIN;
@@ -3638,7 +3636,7 @@ static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
3638static ssize_t show_tx_power(struct device *d, 3636static ssize_t show_tx_power(struct device *d,
3639 struct device_attribute *attr, char *buf) 3637 struct device_attribute *attr, char *buf)
3640{ 3638{
3641 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; 3639 struct iwl_priv *priv = dev_get_drvdata(d);
3642 return sprintf(buf, "%d\n", priv->tx_power_user_lmt); 3640 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
3643} 3641}
3644 3642
@@ -3646,7 +3644,7 @@ static ssize_t store_tx_power(struct device *d,
3646 struct device_attribute *attr, 3644 struct device_attribute *attr,
3647 const char *buf, size_t count) 3645 const char *buf, size_t count)
3648{ 3646{
3649 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; 3647 struct iwl_priv *priv = dev_get_drvdata(d);
3650 char *p = (char *)buf; 3648 char *p = (char *)buf;
3651 u32 val; 3649 u32 val;
3652 3650
@@ -3664,7 +3662,7 @@ static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
3664static ssize_t show_flags(struct device *d, 3662static ssize_t show_flags(struct device *d,
3665 struct device_attribute *attr, char *buf) 3663 struct device_attribute *attr, char *buf)
3666{ 3664{
3667 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; 3665 struct iwl_priv *priv = dev_get_drvdata(d);
3668 3666
3669 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags); 3667 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
3670} 3668}
@@ -3673,7 +3671,7 @@ static ssize_t store_flags(struct device *d,
3673 struct device_attribute *attr, 3671 struct device_attribute *attr,
3674 const char *buf, size_t count) 3672 const char *buf, size_t count)
3675{ 3673{
3676 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; 3674 struct iwl_priv *priv = dev_get_drvdata(d);
3677 u32 flags = simple_strtoul(buf, NULL, 0); 3675 u32 flags = simple_strtoul(buf, NULL, 0);
3678 3676
3679 mutex_lock(&priv->mutex); 3677 mutex_lock(&priv->mutex);
@@ -3698,7 +3696,7 @@ static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
3698static ssize_t show_filter_flags(struct device *d, 3696static ssize_t show_filter_flags(struct device *d,
3699 struct device_attribute *attr, char *buf) 3697 struct device_attribute *attr, char *buf)
3700{ 3698{
3701 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; 3699 struct iwl_priv *priv = dev_get_drvdata(d);
3702 3700
3703 return sprintf(buf, "0x%04X\n", 3701 return sprintf(buf, "0x%04X\n",
3704 le32_to_cpu(priv->active_rxon.filter_flags)); 3702 le32_to_cpu(priv->active_rxon.filter_flags));
@@ -3708,7 +3706,7 @@ static ssize_t store_filter_flags(struct device *d,
3708 struct device_attribute *attr, 3706 struct device_attribute *attr,
3709 const char *buf, size_t count) 3707 const char *buf, size_t count)
3710{ 3708{
3711 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; 3709 struct iwl_priv *priv = dev_get_drvdata(d);
3712 u32 filter_flags = simple_strtoul(buf, NULL, 0); 3710 u32 filter_flags = simple_strtoul(buf, NULL, 0);
3713 3711
3714 mutex_lock(&priv->mutex); 3712 mutex_lock(&priv->mutex);
@@ -3993,7 +3991,7 @@ static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
3993static ssize_t show_status(struct device *d, 3991static ssize_t show_status(struct device *d,
3994 struct device_attribute *attr, char *buf) 3992 struct device_attribute *attr, char *buf)
3995{ 3993{
3996 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; 3994 struct iwl_priv *priv = dev_get_drvdata(d);
3997 if (!iwl_is_alive(priv)) 3995 if (!iwl_is_alive(priv))
3998 return -EAGAIN; 3996 return -EAGAIN;
3999 return sprintf(buf, "0x%08x\n", (int)priv->status); 3997 return sprintf(buf, "0x%08x\n", (int)priv->status);
@@ -4005,10 +4003,11 @@ static ssize_t dump_error_log(struct device *d,
4005 struct device_attribute *attr, 4003 struct device_attribute *attr,
4006 const char *buf, size_t count) 4004 const char *buf, size_t count)
4007{ 4005{
4006 struct iwl_priv *priv = dev_get_drvdata(d);
4008 char *p = (char *)buf; 4007 char *p = (char *)buf;
4009 4008
4010 if (p[0] == '1') 4009 if (p[0] == '1')
4011 iwl3945_dump_nic_error_log((struct iwl_priv *)d->driver_data); 4010 iwl3945_dump_nic_error_log(priv);
4012 4011
4013 return strnlen(buf, count); 4012 return strnlen(buf, count);
4014} 4013}
@@ -4019,10 +4018,11 @@ static ssize_t dump_event_log(struct device *d,
4019 struct device_attribute *attr, 4018 struct device_attribute *attr,
4020 const char *buf, size_t count) 4019 const char *buf, size_t count)
4021{ 4020{
4021 struct iwl_priv *priv = dev_get_drvdata(d);
4022 char *p = (char *)buf; 4022 char *p = (char *)buf;
4023 4023
4024 if (p[0] == '1') 4024 if (p[0] == '1')
4025 iwl3945_dump_nic_event_log((struct iwl_priv *)d->driver_data); 4025 iwl3945_dump_nic_event_log(priv);
4026 4026
4027 return strnlen(buf, count); 4027 return strnlen(buf, count);
4028} 4028}
@@ -4104,7 +4104,6 @@ static struct ieee80211_ops iwl3945_hw_ops = {
4104 .add_interface = iwl_mac_add_interface, 4104 .add_interface = iwl_mac_add_interface,
4105 .remove_interface = iwl_mac_remove_interface, 4105 .remove_interface = iwl_mac_remove_interface,
4106 .config = iwl_mac_config, 4106 .config = iwl_mac_config,
4107 .config_interface = iwl_mac_config_interface,
4108 .configure_filter = iwl_configure_filter, 4107 .configure_filter = iwl_configure_filter,
4109 .set_key = iwl3945_mac_set_key, 4108 .set_key = iwl3945_mac_set_key,
4110 .get_tx_stats = iwl_mac_get_tx_stats, 4109 .get_tx_stats = iwl_mac_get_tx_stats,
@@ -4210,8 +4209,6 @@ static int iwl3945_setup_mac(struct iwl_priv *priv)
4210 /* Default value; 4 EDCA QOS priorities */ 4209 /* Default value; 4 EDCA QOS priorities */
4211 hw->queues = 4; 4210 hw->queues = 4;
4212 4211
4213 hw->conf.beacon_int = 100;
4214
4215 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels) 4212 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
4216 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = 4213 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
4217 &priv->bands[IEEE80211_BAND_2GHZ]; 4214 &priv->bands[IEEE80211_BAND_2GHZ];
diff --git a/drivers/net/wireless/libertas_tf/main.c b/drivers/net/wireless/libertas_tf/main.c
index e7289e2e7f16..10a99e26d392 100644
--- a/drivers/net/wireless/libertas_tf/main.c
+++ b/drivers/net/wireless/libertas_tf/main.c
@@ -366,36 +366,6 @@ static int lbtf_op_config(struct ieee80211_hw *hw, u32 changed)
366 return 0; 366 return 0;
367} 367}
368 368
369static int lbtf_op_config_interface(struct ieee80211_hw *hw,
370 struct ieee80211_vif *vif,
371 struct ieee80211_if_conf *conf)
372{
373 struct lbtf_private *priv = hw->priv;
374 struct sk_buff *beacon;
375
376 switch (priv->vif->type) {
377 case NL80211_IFTYPE_AP:
378 case NL80211_IFTYPE_MESH_POINT:
379 beacon = ieee80211_beacon_get(hw, vif);
380 if (beacon) {
381 lbtf_beacon_set(priv, beacon);
382 kfree_skb(beacon);
383 lbtf_beacon_ctrl(priv, 1, hw->conf.beacon_int);
384 }
385 break;
386 default:
387 break;
388 }
389
390 if (conf->bssid) {
391 u8 null_bssid[ETH_ALEN] = {0};
392 bool activate = compare_ether_addr(conf->bssid, null_bssid);
393 lbtf_set_bssid(priv, activate, conf->bssid);
394 }
395
396 return 0;
397}
398
399#define SUPPORTED_FIF_FLAGS (FIF_PROMISC_IN_BSS | FIF_ALLMULTI) 369#define SUPPORTED_FIF_FLAGS (FIF_PROMISC_IN_BSS | FIF_ALLMULTI)
400static void lbtf_op_configure_filter(struct ieee80211_hw *hw, 370static void lbtf_op_configure_filter(struct ieee80211_hw *hw,
401 unsigned int changed_flags, 371 unsigned int changed_flags,
@@ -451,6 +421,29 @@ static void lbtf_op_bss_info_changed(struct ieee80211_hw *hw,
451 u32 changes) 421 u32 changes)
452{ 422{
453 struct lbtf_private *priv = hw->priv; 423 struct lbtf_private *priv = hw->priv;
424 struct sk_buff *beacon;
425
426 if (changes & (BSS_CHANGED_BEACON | BSS_CHANGED_BEACON_INT)) {
427 switch (priv->vif->type) {
428 case NL80211_IFTYPE_AP:
429 case NL80211_IFTYPE_MESH_POINT:
430 beacon = ieee80211_beacon_get(hw, vif);
431 if (beacon) {
432 lbtf_beacon_set(priv, beacon);
433 kfree_skb(beacon);
434 lbtf_beacon_ctrl(priv, 1,
435 bss_conf->beacon_int);
436 }
437 break;
438 default:
439 break;
440 }
441 }
442
443 if (changes & BSS_CHANGED_BSSID) {
444 bool activate = !is_zero_ether_addr(bss_conf->bssid);
445 lbtf_set_bssid(priv, activate, bss_conf->bssid);
446 }
454 447
455 if (changes & BSS_CHANGED_ERP_PREAMBLE) { 448 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
456 if (bss_conf->use_short_preamble) 449 if (bss_conf->use_short_preamble)
@@ -459,8 +452,6 @@ static void lbtf_op_bss_info_changed(struct ieee80211_hw *hw,
459 priv->preamble = CMD_TYPE_LONG_PREAMBLE; 452 priv->preamble = CMD_TYPE_LONG_PREAMBLE;
460 lbtf_set_radio_control(priv); 453 lbtf_set_radio_control(priv);
461 } 454 }
462
463 return;
464} 455}
465 456
466static const struct ieee80211_ops lbtf_ops = { 457static const struct ieee80211_ops lbtf_ops = {
@@ -470,7 +461,6 @@ static const struct ieee80211_ops lbtf_ops = {
470 .add_interface = lbtf_op_add_interface, 461 .add_interface = lbtf_op_add_interface,
471 .remove_interface = lbtf_op_remove_interface, 462 .remove_interface = lbtf_op_remove_interface,
472 .config = lbtf_op_config, 463 .config = lbtf_op_config,
473 .config_interface = lbtf_op_config_interface,
474 .configure_filter = lbtf_op_configure_filter, 464 .configure_filter = lbtf_op_configure_filter,
475 .bss_info_changed = lbtf_op_bss_info_changed, 465 .bss_info_changed = lbtf_op_bss_info_changed,
476}; 466};
diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
index d4fdc8b7d7d8..b1213b6a6b9f 100644
--- a/drivers/net/wireless/mac80211_hwsim.c
+++ b/drivers/net/wireless/mac80211_hwsim.c
@@ -553,18 +553,15 @@ static int mac80211_hwsim_config(struct ieee80211_hw *hw, u32 changed)
553 struct mac80211_hwsim_data *data = hw->priv; 553 struct mac80211_hwsim_data *data = hw->priv;
554 struct ieee80211_conf *conf = &hw->conf; 554 struct ieee80211_conf *conf = &hw->conf;
555 555
556 printk(KERN_DEBUG "%s:%s (freq=%d radio_enabled=%d beacon_int=%d)\n", 556 printk(KERN_DEBUG "%s:%s (freq=%d radio_enabled=%d idle=%d ps=%d)\n",
557 wiphy_name(hw->wiphy), __func__, 557 wiphy_name(hw->wiphy), __func__,
558 conf->channel->center_freq, conf->radio_enabled, 558 conf->channel->center_freq, conf->radio_enabled,
559 conf->beacon_int); 559 !!(conf->flags & IEEE80211_CONF_IDLE),
560 !!(conf->flags & IEEE80211_CONF_PS));
560 561
561 data->channel = conf->channel; 562 data->channel = conf->channel;
562 data->radio_enabled = conf->radio_enabled; 563 data->radio_enabled = conf->radio_enabled;
563 data->beacon_int = 1024 * conf->beacon_int / 1000 * HZ / 1000; 564 if (!data->started || !data->radio_enabled || !data->beacon_int)
564 if (data->beacon_int < 1)
565 data->beacon_int = 1;
566
567 if (!data->started || !data->radio_enabled)
568 del_timer(&data->beacon_timer); 565 del_timer(&data->beacon_timer);
569 else 566 else
570 mod_timer(&data->beacon_timer, jiffies + data->beacon_int); 567 mod_timer(&data->beacon_timer, jiffies + data->beacon_int);
@@ -592,35 +589,26 @@ static void mac80211_hwsim_configure_filter(struct ieee80211_hw *hw,
592 *total_flags = data->rx_filter; 589 *total_flags = data->rx_filter;
593} 590}
594 591
595static int mac80211_hwsim_config_interface(struct ieee80211_hw *hw,
596 struct ieee80211_vif *vif,
597 struct ieee80211_if_conf *conf)
598{
599 struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
600
601 hwsim_check_magic(vif);
602 if (conf->changed & IEEE80211_IFCC_BSSID) {
603 DECLARE_MAC_BUF(mac);
604 printk(KERN_DEBUG "%s:%s: BSSID changed: %pM\n",
605 wiphy_name(hw->wiphy), __func__,
606 conf->bssid);
607 memcpy(vp->bssid, conf->bssid, ETH_ALEN);
608 }
609 return 0;
610}
611
612static void mac80211_hwsim_bss_info_changed(struct ieee80211_hw *hw, 592static void mac80211_hwsim_bss_info_changed(struct ieee80211_hw *hw,
613 struct ieee80211_vif *vif, 593 struct ieee80211_vif *vif,
614 struct ieee80211_bss_conf *info, 594 struct ieee80211_bss_conf *info,
615 u32 changed) 595 u32 changed)
616{ 596{
617 struct hwsim_vif_priv *vp = (void *)vif->drv_priv; 597 struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
598 struct mac80211_hwsim_data *data = hw->priv;
618 599
619 hwsim_check_magic(vif); 600 hwsim_check_magic(vif);
620 601
621 printk(KERN_DEBUG "%s:%s(changed=0x%x)\n", 602 printk(KERN_DEBUG "%s:%s(changed=0x%x)\n",
622 wiphy_name(hw->wiphy), __func__, changed); 603 wiphy_name(hw->wiphy), __func__, changed);
623 604
605 if (changed & BSS_CHANGED_BSSID) {
606 printk(KERN_DEBUG "%s:%s: BSSID changed: %pM\n",
607 wiphy_name(hw->wiphy), __func__,
608 info->bssid);
609 memcpy(vp->bssid, info->bssid, ETH_ALEN);
610 }
611
624 if (changed & BSS_CHANGED_ASSOC) { 612 if (changed & BSS_CHANGED_ASSOC) {
625 printk(KERN_DEBUG " %s: ASSOC: assoc=%d aid=%d\n", 613 printk(KERN_DEBUG " %s: ASSOC: assoc=%d aid=%d\n",
626 wiphy_name(hw->wiphy), info->assoc, info->aid); 614 wiphy_name(hw->wiphy), info->assoc, info->aid);
@@ -628,6 +616,14 @@ static void mac80211_hwsim_bss_info_changed(struct ieee80211_hw *hw,
628 vp->aid = info->aid; 616 vp->aid = info->aid;
629 } 617 }
630 618
619 if (changed & BSS_CHANGED_BEACON_INT) {
620 printk(KERN_DEBUG " %s: BCNINT: %d\n",
621 wiphy_name(hw->wiphy), info->beacon_int);
622 data->beacon_int = 1024 * info->beacon_int / 1000 * HZ / 1000;
623 if (WARN_ON(!data->beacon_int))
624 data->beacon_int = 1;
625 }
626
631 if (changed & BSS_CHANGED_ERP_CTS_PROT) { 627 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
632 printk(KERN_DEBUG " %s: ERP_CTS_PROT: %d\n", 628 printk(KERN_DEBUG " %s: ERP_CTS_PROT: %d\n",
633 wiphy_name(hw->wiphy), info->use_cts_prot); 629 wiphy_name(hw->wiphy), info->use_cts_prot);
@@ -704,7 +700,6 @@ static const struct ieee80211_ops mac80211_hwsim_ops =
704 .remove_interface = mac80211_hwsim_remove_interface, 700 .remove_interface = mac80211_hwsim_remove_interface,
705 .config = mac80211_hwsim_config, 701 .config = mac80211_hwsim_config,
706 .configure_filter = mac80211_hwsim_configure_filter, 702 .configure_filter = mac80211_hwsim_configure_filter,
707 .config_interface = mac80211_hwsim_config_interface,
708 .bss_info_changed = mac80211_hwsim_bss_info_changed, 703 .bss_info_changed = mac80211_hwsim_bss_info_changed,
709 .sta_notify = mac80211_hwsim_sta_notify, 704 .sta_notify = mac80211_hwsim_sta_notify,
710 .set_tim = mac80211_hwsim_set_tim, 705 .set_tim = mac80211_hwsim_set_tim,
diff --git a/drivers/net/wireless/mwl8k.c b/drivers/net/wireless/mwl8k.c
index a9a970469c2a..46b288dc8f4d 100644
--- a/drivers/net/wireless/mwl8k.c
+++ b/drivers/net/wireless/mwl8k.c
@@ -3089,19 +3089,6 @@ static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
3089 return rc ? -EINVAL : 0; 3089 return rc ? -EINVAL : 0;
3090} 3090}
3091 3091
3092static int mwl8k_config_interface(struct ieee80211_hw *hw,
3093 struct ieee80211_vif *vif,
3094 struct ieee80211_if_conf *conf)
3095{
3096 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
3097 u32 changed = conf->changed;
3098
3099 if (changed & IEEE80211_IFCC_BSSID)
3100 memcpy(mv_vif->bssid, conf->bssid, IEEE80211_ADDR_LEN);
3101
3102 return 0;
3103}
3104
3105struct mwl8k_bss_info_changed_worker { 3092struct mwl8k_bss_info_changed_worker {
3106 struct mwl8k_work_struct header; 3093 struct mwl8k_work_struct header;
3107 struct ieee80211_vif *vif; 3094 struct ieee80211_vif *vif;
@@ -3183,8 +3170,12 @@ static void mwl8k_bss_info_changed(struct ieee80211_hw *hw,
3183{ 3170{
3184 struct mwl8k_bss_info_changed_worker *worker; 3171 struct mwl8k_bss_info_changed_worker *worker;
3185 struct mwl8k_priv *priv = hw->priv; 3172 struct mwl8k_priv *priv = hw->priv;
3173 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
3186 int rc; 3174 int rc;
3187 3175
3176 if (changed & BSS_CHANGED_BSSID)
3177 memcpy(mv_vif->bssid, info->bssid, IEEE80211_ADDR_LEN);
3178
3188 if ((changed & BSS_CHANGED_ASSOC) == 0) 3179 if ((changed & BSS_CHANGED_ASSOC) == 0)
3189 return; 3180 return;
3190 3181
@@ -3442,7 +3433,6 @@ static const struct ieee80211_ops mwl8k_ops = {
3442 .add_interface = mwl8k_add_interface, 3433 .add_interface = mwl8k_add_interface,
3443 .remove_interface = mwl8k_remove_interface, 3434 .remove_interface = mwl8k_remove_interface,
3444 .config = mwl8k_config, 3435 .config = mwl8k_config,
3445 .config_interface = mwl8k_config_interface,
3446 .bss_info_changed = mwl8k_bss_info_changed, 3436 .bss_info_changed = mwl8k_bss_info_changed,
3447 .configure_filter = mwl8k_configure_filter, 3437 .configure_filter = mwl8k_configure_filter,
3448 .set_rts_threshold = mwl8k_set_rts_threshold, 3438 .set_rts_threshold = mwl8k_set_rts_threshold,
diff --git a/drivers/net/wireless/p54/p54.h b/drivers/net/wireless/p54/p54.h
index 7fda1a9e263b..db3df947d8ed 100644
--- a/drivers/net/wireless/p54/p54.h
+++ b/drivers/net/wireless/p54/p54.h
@@ -189,10 +189,10 @@ struct p54_common {
189 unsigned long *used_rxkeys; 189 unsigned long *used_rxkeys;
190 190
191 /* LED management */ 191 /* LED management */
192#ifdef CONFIG_MAC80211_LEDS 192#ifdef CONFIG_P54_LEDS
193 struct p54_led_dev leds[4]; 193 struct p54_led_dev leds[4];
194 struct delayed_work led_work; 194 struct delayed_work led_work;
195#endif /* CONFIG_MAC80211_LEDS */ 195#endif /* CONFIG_P54_LEDS */
196 u16 softled_state; /* bit field of glowing LEDs */ 196 u16 softled_state; /* bit field of glowing LEDs */
197 197
198 /* statistics */ 198 /* statistics */
diff --git a/drivers/net/wireless/p54/p54common.c b/drivers/net/wireless/p54/p54common.c
index 71394968d450..48d81d98e12d 100644
--- a/drivers/net/wireless/p54/p54common.c
+++ b/drivers/net/wireless/p54/p54common.c
@@ -822,7 +822,6 @@ void p54_free_skb(struct ieee80211_hw *dev, struct sk_buff *skb)
822 struct ieee80211_tx_info *info; 822 struct ieee80211_tx_info *info;
823 struct p54_tx_info *range; 823 struct p54_tx_info *range;
824 unsigned long flags; 824 unsigned long flags;
825 u32 freed = 0, last_addr = priv->rx_start;
826 825
827 if (unlikely(!skb || !dev || !skb_queue_len(&priv->tx_queue))) 826 if (unlikely(!skb || !dev || !skb_queue_len(&priv->tx_queue)))
828 return; 827 return;
@@ -842,7 +841,6 @@ void p54_free_skb(struct ieee80211_hw *dev, struct sk_buff *skb)
842 841
843 ni = IEEE80211_SKB_CB(skb->prev); 842 ni = IEEE80211_SKB_CB(skb->prev);
844 mr = (struct p54_tx_info *)ni->rate_driver_data; 843 mr = (struct p54_tx_info *)ni->rate_driver_data;
845 last_addr = mr->end_addr;
846 } 844 }
847 if (skb->next != (struct sk_buff *)&priv->tx_queue) { 845 if (skb->next != (struct sk_buff *)&priv->tx_queue) {
848 struct ieee80211_tx_info *ni; 846 struct ieee80211_tx_info *ni;
@@ -850,16 +848,11 @@ void p54_free_skb(struct ieee80211_hw *dev, struct sk_buff *skb)
850 848
851 ni = IEEE80211_SKB_CB(skb->next); 849 ni = IEEE80211_SKB_CB(skb->next);
852 mr = (struct p54_tx_info *)ni->rate_driver_data; 850 mr = (struct p54_tx_info *)ni->rate_driver_data;
853 freed = mr->start_addr - last_addr; 851 }
854 } else
855 freed = priv->rx_end - last_addr;
856 __skb_unlink(skb, &priv->tx_queue); 852 __skb_unlink(skb, &priv->tx_queue);
857 spin_unlock_irqrestore(&priv->tx_queue.lock, flags); 853 spin_unlock_irqrestore(&priv->tx_queue.lock, flags);
858 dev_kfree_skb_any(skb); 854 dev_kfree_skb_any(skb);
859 855 p54_wake_free_queues(dev);
860 if (freed >= priv->headroom + sizeof(struct p54_hdr) + 48 +
861 IEEE80211_MAX_RTS_THRESHOLD + priv->tailroom)
862 p54_wake_free_queues(dev);
863} 856}
864EXPORT_SYMBOL_GPL(p54_free_skb); 857EXPORT_SYMBOL_GPL(p54_free_skb);
865 858
@@ -893,8 +886,6 @@ static void p54_rx_frame_sent(struct ieee80211_hw *dev, struct sk_buff *skb)
893 struct sk_buff *entry; 886 struct sk_buff *entry;
894 u32 addr = le32_to_cpu(hdr->req_id) - priv->headroom; 887 u32 addr = le32_to_cpu(hdr->req_id) - priv->headroom;
895 struct p54_tx_info *range = NULL; 888 struct p54_tx_info *range = NULL;
896 u32 freed = 0;
897 u32 last_addr = priv->rx_start;
898 unsigned long flags; 889 unsigned long flags;
899 int count, idx; 890 int count, idx;
900 891
@@ -908,7 +899,6 @@ static void p54_rx_frame_sent(struct ieee80211_hw *dev, struct sk_buff *skb)
908 899
909 range = (void *)info->rate_driver_data; 900 range = (void *)info->rate_driver_data;
910 if (range->start_addr != addr) { 901 if (range->start_addr != addr) {
911 last_addr = range->end_addr;
912 entry = entry->next; 902 entry = entry->next;
913 continue; 903 continue;
914 } 904 }
@@ -919,11 +909,8 @@ static void p54_rx_frame_sent(struct ieee80211_hw *dev, struct sk_buff *skb)
919 909
920 ni = IEEE80211_SKB_CB(entry->next); 910 ni = IEEE80211_SKB_CB(entry->next);
921 mr = (struct p54_tx_info *)ni->rate_driver_data; 911 mr = (struct p54_tx_info *)ni->rate_driver_data;
922 freed = mr->start_addr - last_addr; 912 }
923 } else
924 freed = priv->rx_end - last_addr;
925 913
926 last_addr = range->end_addr;
927 __skb_unlink(entry, &priv->tx_queue); 914 __skb_unlink(entry, &priv->tx_queue);
928 spin_unlock_irqrestore(&priv->tx_queue.lock, flags); 915 spin_unlock_irqrestore(&priv->tx_queue.lock, flags);
929 916
@@ -1010,9 +997,7 @@ static void p54_rx_frame_sent(struct ieee80211_hw *dev, struct sk_buff *skb)
1010 spin_unlock_irqrestore(&priv->tx_queue.lock, flags); 997 spin_unlock_irqrestore(&priv->tx_queue.lock, flags);
1011 998
1012out: 999out:
1013 if (freed >= priv->headroom + sizeof(struct p54_hdr) + 48 + 1000 p54_wake_free_queues(dev);
1014 IEEE80211_MAX_RTS_THRESHOLD + priv->tailroom)
1015 p54_wake_free_queues(dev);
1016} 1001}
1017 1002
1018static void p54_rx_eeprom_readback(struct ieee80211_hw *dev, 1003static void p54_rx_eeprom_readback(struct ieee80211_hw *dev,
@@ -2204,41 +2189,6 @@ out:
2204 return ret; 2189 return ret;
2205} 2190}
2206 2191
2207static int p54_config_interface(struct ieee80211_hw *dev,
2208 struct ieee80211_vif *vif,
2209 struct ieee80211_if_conf *conf)
2210{
2211 struct p54_common *priv = dev->priv;
2212 int ret = 0;
2213
2214 mutex_lock(&priv->conf_mutex);
2215 if (conf->changed & IEEE80211_IFCC_BSSID) {
2216 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
2217 ret = p54_setup_mac(dev);
2218 if (ret)
2219 goto out;
2220 }
2221
2222 if (conf->changed & IEEE80211_IFCC_BEACON) {
2223 ret = p54_scan(dev, P54_SCAN_EXIT, 0);
2224 if (ret)
2225 goto out;
2226 ret = p54_setup_mac(dev);
2227 if (ret)
2228 goto out;
2229 ret = p54_beacon_update(dev, vif);
2230 if (ret)
2231 goto out;
2232 ret = p54_set_edcf(dev);
2233 if (ret)
2234 goto out;
2235 }
2236
2237out:
2238 mutex_unlock(&priv->conf_mutex);
2239 return ret;
2240}
2241
2242static void p54_configure_filter(struct ieee80211_hw *dev, 2192static void p54_configure_filter(struct ieee80211_hw *dev,
2243 unsigned int changed_flags, 2193 unsigned int changed_flags,
2244 unsigned int *total_flags, 2194 unsigned int *total_flags,
@@ -2342,8 +2292,32 @@ static void p54_bss_info_changed(struct ieee80211_hw *dev,
2342 u32 changed) 2292 u32 changed)
2343{ 2293{
2344 struct p54_common *priv = dev->priv; 2294 struct p54_common *priv = dev->priv;
2295 int ret;
2296
2297 mutex_lock(&priv->conf_mutex);
2298 if (changed & BSS_CHANGED_BSSID) {
2299 memcpy(priv->bssid, info->bssid, ETH_ALEN);
2300 ret = p54_setup_mac(dev);
2301 if (ret)
2302 goto out;
2303 }
2304
2305 if (changed & BSS_CHANGED_BEACON) {
2306 ret = p54_scan(dev, P54_SCAN_EXIT, 0);
2307 if (ret)
2308 goto out;
2309 ret = p54_setup_mac(dev);
2310 if (ret)
2311 goto out;
2312 ret = p54_beacon_update(dev, vif);
2313 if (ret)
2314 goto out;
2315 }
2316 /* XXX: this mimics having two callbacks... clean up */
2317 out:
2318 mutex_unlock(&priv->conf_mutex);
2345 2319
2346 if (changed & BSS_CHANGED_ERP_SLOT) { 2320 if (changed & (BSS_CHANGED_ERP_SLOT | BSS_CHANGED_BEACON)) {
2347 priv->use_short_slot = info->use_short_slot; 2321 priv->use_short_slot = info->use_short_slot;
2348 p54_set_edcf(dev); 2322 p54_set_edcf(dev);
2349 } 2323 }
@@ -2364,7 +2338,6 @@ static void p54_bss_info_changed(struct ieee80211_hw *dev,
2364 p54_setup_mac(dev); 2338 p54_setup_mac(dev);
2365 } 2339 }
2366 } 2340 }
2367
2368} 2341}
2369 2342
2370static int p54_set_key(struct ieee80211_hw *dev, enum set_key_cmd cmd, 2343static int p54_set_key(struct ieee80211_hw *dev, enum set_key_cmd cmd,
@@ -2619,7 +2592,6 @@ static const struct ieee80211_ops p54_ops = {
2619 .sta_notify = p54_sta_notify, 2592 .sta_notify = p54_sta_notify,
2620 .set_key = p54_set_key, 2593 .set_key = p54_set_key,
2621 .config = p54_config, 2594 .config = p54_config,
2622 .config_interface = p54_config_interface,
2623 .bss_info_changed = p54_bss_info_changed, 2595 .bss_info_changed = p54_bss_info_changed,
2624 .configure_filter = p54_configure_filter, 2596 .configure_filter = p54_configure_filter,
2625 .conf_tx = p54_conf_tx, 2597 .conf_tx = p54_conf_tx,
diff --git a/drivers/net/wireless/p54/p54usb.c b/drivers/net/wireless/p54/p54usb.c
index 6cc6cbc9234f..f40c0f468b27 100644
--- a/drivers/net/wireless/p54/p54usb.c
+++ b/drivers/net/wireless/p54/p54usb.c
@@ -81,6 +81,29 @@ static struct usb_device_id p54u_table[] __devinitdata = {
81 81
82MODULE_DEVICE_TABLE(usb, p54u_table); 82MODULE_DEVICE_TABLE(usb, p54u_table);
83 83
84static const struct {
85 u32 intf;
86 enum p54u_hw_type type;
87 char fw[FIRMWARE_NAME_MAX];
88 char fw_legacy[FIRMWARE_NAME_MAX];
89 char hw[20];
90} p54u_fwlist[__NUM_P54U_HWTYPES] = {
91 {
92 .type = P54U_NET2280,
93 .intf = FW_LM86,
94 .fw = "isl3886usb",
95 .fw_legacy = "isl3890usb",
96 .hw = "ISL3886 + net2280",
97 },
98 {
99 .type = P54U_3887,
100 .intf = FW_LM87,
101 .fw = "isl3887usb",
102 .fw_legacy = "isl3887usb_bare",
103 .hw = "ISL3887",
104 },
105};
106
84static void p54u_rx_cb(struct urb *urb) 107static void p54u_rx_cb(struct urb *urb)
85{ 108{
86 struct sk_buff *skb = (struct sk_buff *) urb->context; 109 struct sk_buff *skb = (struct sk_buff *) urb->context;
@@ -125,11 +148,7 @@ static void p54u_rx_cb(struct urb *urb)
125 } 148 }
126 skb_reset_tail_pointer(skb); 149 skb_reset_tail_pointer(skb);
127 skb_trim(skb, 0); 150 skb_trim(skb, 0);
128 if (urb->transfer_buffer != skb_tail_pointer(skb)) { 151 urb->transfer_buffer = skb_tail_pointer(skb);
129 /* this should not happen */
130 WARN_ON(1);
131 urb->transfer_buffer = skb_tail_pointer(skb);
132 }
133 } 152 }
134 skb_queue_tail(&priv->rx_queue, skb); 153 skb_queue_tail(&priv->rx_queue, skb);
135 usb_anchor_urb(urb, &priv->submitted); 154 usb_anchor_urb(urb, &priv->submitted);
@@ -206,53 +225,6 @@ static int p54u_init_urbs(struct ieee80211_hw *dev)
206 return ret; 225 return ret;
207} 226}
208 227
209static void p54u_tx_3887(struct ieee80211_hw *dev, struct sk_buff *skb)
210{
211 struct p54u_priv *priv = dev->priv;
212 struct urb *addr_urb, *data_urb;
213 int err = 0;
214
215 addr_urb = usb_alloc_urb(0, GFP_ATOMIC);
216 if (!addr_urb)
217 return;
218
219 data_urb = usb_alloc_urb(0, GFP_ATOMIC);
220 if (!data_urb) {
221 usb_free_urb(addr_urb);
222 return;
223 }
224
225 usb_fill_bulk_urb(addr_urb, priv->udev,
226 usb_sndbulkpipe(priv->udev, P54U_PIPE_DATA),
227 &((struct p54_hdr *)skb->data)->req_id, 4,
228 p54u_tx_dummy_cb, dev);
229 usb_fill_bulk_urb(data_urb, priv->udev,
230 usb_sndbulkpipe(priv->udev, P54U_PIPE_DATA),
231 skb->data, skb->len, FREE_AFTER_TX(skb) ?
232 p54u_tx_cb : p54u_tx_dummy_cb, skb);
233 addr_urb->transfer_flags |= URB_ZERO_PACKET;
234 data_urb->transfer_flags |= URB_ZERO_PACKET;
235
236 usb_anchor_urb(addr_urb, &priv->submitted);
237 err = usb_submit_urb(addr_urb, GFP_ATOMIC);
238 if (err) {
239 usb_unanchor_urb(addr_urb);
240 goto out;
241 }
242
243 usb_anchor_urb(data_urb, &priv->submitted);
244 err = usb_submit_urb(data_urb, GFP_ATOMIC);
245 if (err)
246 usb_unanchor_urb(data_urb);
247
248 out:
249 usb_free_urb(addr_urb);
250 usb_free_urb(data_urb);
251
252 if (err)
253 p54_free_skb(dev, skb);
254}
255
256static __le32 p54u_lm87_chksum(const __le32 *data, size_t length) 228static __le32 p54u_lm87_chksum(const __le32 *data, size_t length)
257{ 229{
258 u32 chk = 0; 230 u32 chk = 0;
@@ -425,20 +397,16 @@ static int p54u_bulk_msg(struct p54u_priv *priv, unsigned int ep,
425 data, len, &alen, 2000); 397 data, len, &alen, 2000);
426} 398}
427 399
428static const char p54u_romboot_3887[] = "~~~~"; 400static int p54u_device_reset(struct ieee80211_hw *dev)
429static const char p54u_firmware_upload_3887[] = "<\r";
430
431static int p54u_device_reset_3887(struct ieee80211_hw *dev)
432{ 401{
433 struct p54u_priv *priv = dev->priv; 402 struct p54u_priv *priv = dev->priv;
434 int ret, lock = (priv->intf->condition != USB_INTERFACE_BINDING); 403 int ret, lock = (priv->intf->condition != USB_INTERFACE_BINDING);
435 u8 buf[4];
436 404
437 if (lock) { 405 if (lock) {
438 ret = usb_lock_device_for_reset(priv->udev, priv->intf); 406 ret = usb_lock_device_for_reset(priv->udev, priv->intf);
439 if (ret < 0) { 407 if (ret < 0) {
440 dev_err(&priv->udev->dev, "(p54usb) unable to lock " 408 dev_err(&priv->udev->dev, "(p54usb) unable to lock "
441 " device for reset: %d\n", ret); 409 "device for reset (%d)!\n", ret);
442 return ret; 410 return ret;
443 } 411 }
444 } 412 }
@@ -447,26 +415,34 @@ static int p54u_device_reset_3887(struct ieee80211_hw *dev)
447 if (lock) 415 if (lock)
448 usb_unlock_device(priv->udev); 416 usb_unlock_device(priv->udev);
449 417
450 if (ret) { 418 if (ret)
451 dev_err(&priv->udev->dev, "(p54usb) unable to reset " 419 dev_err(&priv->udev->dev, "(p54usb) unable to reset "
452 "device: %d\n", ret); 420 "device (%d)!\n", ret);
453 return ret; 421
454 } 422 return ret;
423}
424
425static const char p54u_romboot_3887[] = "~~~~";
426static int p54u_firmware_reset_3887(struct ieee80211_hw *dev)
427{
428 struct p54u_priv *priv = dev->priv;
429 u8 buf[4];
430 int ret;
455 431
456 memcpy(&buf, p54u_romboot_3887, sizeof(buf)); 432 memcpy(&buf, p54u_romboot_3887, sizeof(buf));
457 ret = p54u_bulk_msg(priv, P54U_PIPE_DATA, 433 ret = p54u_bulk_msg(priv, P54U_PIPE_DATA,
458 buf, sizeof(buf)); 434 buf, sizeof(buf));
459 if (ret) 435 if (ret)
460 dev_err(&priv->udev->dev, "(p54usb) unable to jump to " 436 dev_err(&priv->udev->dev, "(p54usb) unable to jump to "
461 "boot ROM: %d\n", ret); 437 "boot ROM (%d)!\n", ret);
462 438
463 return ret; 439 return ret;
464} 440}
465 441
442static const char p54u_firmware_upload_3887[] = "<\r";
466static int p54u_upload_firmware_3887(struct ieee80211_hw *dev) 443static int p54u_upload_firmware_3887(struct ieee80211_hw *dev)
467{ 444{
468 struct p54u_priv *priv = dev->priv; 445 struct p54u_priv *priv = dev->priv;
469 const struct firmware *fw_entry = NULL;
470 int err, alen; 446 int err, alen;
471 u8 carry = 0; 447 u8 carry = 0;
472 u8 *buf, *tmp; 448 u8 *buf, *tmp;
@@ -475,51 +451,29 @@ static int p54u_upload_firmware_3887(struct ieee80211_hw *dev)
475 struct x2_header *hdr; 451 struct x2_header *hdr;
476 unsigned long timeout; 452 unsigned long timeout;
477 453
454 err = p54u_firmware_reset_3887(dev);
455 if (err)
456 return err;
457
478 tmp = buf = kmalloc(P54U_FW_BLOCK, GFP_KERNEL); 458 tmp = buf = kmalloc(P54U_FW_BLOCK, GFP_KERNEL);
479 if (!buf) { 459 if (!buf) {
480 dev_err(&priv->udev->dev, "(p54usb) cannot allocate firmware" 460 dev_err(&priv->udev->dev, "(p54usb) cannot allocate firmware"
481 "upload buffer!\n"); 461 "upload buffer!\n");
482 err = -ENOMEM; 462 return -ENOMEM;
483 goto err_bufalloc;
484 }
485
486 err = p54u_device_reset_3887(dev);
487 if (err)
488 goto err_reset;
489
490 err = request_firmware(&fw_entry, "isl3887usb", &priv->udev->dev);
491 if (err) {
492 dev_err(&priv->udev->dev, "p54usb: cannot find firmware "
493 "(isl3887usb)\n");
494 err = request_firmware(&fw_entry, "isl3887usb_bare",
495 &priv->udev->dev);
496 if (err)
497 goto err_req_fw_failed;
498 }
499
500 err = p54_parse_firmware(dev, fw_entry);
501 if (err)
502 goto err_upload_failed;
503
504 if (priv->common.fw_interface != FW_LM87) {
505 dev_err(&priv->udev->dev, "wrong firmware, "
506 "please get a LM87 firmware and try again.\n");
507 err = -EINVAL;
508 goto err_upload_failed;
509 } 463 }
510 464
511 left = block_size = min((size_t)P54U_FW_BLOCK, fw_entry->size); 465 left = block_size = min((size_t)P54U_FW_BLOCK, priv->fw->size);
512 strcpy(buf, p54u_firmware_upload_3887); 466 strcpy(buf, p54u_firmware_upload_3887);
513 left -= strlen(p54u_firmware_upload_3887); 467 left -= strlen(p54u_firmware_upload_3887);
514 tmp += strlen(p54u_firmware_upload_3887); 468 tmp += strlen(p54u_firmware_upload_3887);
515 469
516 data = fw_entry->data; 470 data = priv->fw->data;
517 remains = fw_entry->size; 471 remains = priv->fw->size;
518 472
519 hdr = (struct x2_header *)(buf + strlen(p54u_firmware_upload_3887)); 473 hdr = (struct x2_header *)(buf + strlen(p54u_firmware_upload_3887));
520 memcpy(hdr->signature, X2_SIGNATURE, X2_SIGNATURE_SIZE); 474 memcpy(hdr->signature, X2_SIGNATURE, X2_SIGNATURE_SIZE);
521 hdr->fw_load_addr = cpu_to_le32(ISL38XX_DEV_FIRMWARE_ADDR); 475 hdr->fw_load_addr = cpu_to_le32(ISL38XX_DEV_FIRMWARE_ADDR);
522 hdr->fw_length = cpu_to_le32(fw_entry->size); 476 hdr->fw_length = cpu_to_le32(priv->fw->size);
523 hdr->crc = cpu_to_le32(~crc32_le(~0, (void *)&hdr->fw_load_addr, 477 hdr->crc = cpu_to_le32(~crc32_le(~0, (void *)&hdr->fw_load_addr,
524 sizeof(u32)*2)); 478 sizeof(u32)*2));
525 left -= sizeof(*hdr); 479 left -= sizeof(*hdr);
@@ -561,7 +515,8 @@ static int p54u_upload_firmware_3887(struct ieee80211_hw *dev)
561 left = block_size = min((unsigned int)P54U_FW_BLOCK, remains); 515 left = block_size = min((unsigned int)P54U_FW_BLOCK, remains);
562 } 516 }
563 517
564 *((__le32 *)buf) = cpu_to_le32(~crc32_le(~0, fw_entry->data, fw_entry->size)); 518 *((__le32 *)buf) = cpu_to_le32(~crc32_le(~0, priv->fw->data,
519 priv->fw->size));
565 err = p54u_bulk_msg(priv, P54U_PIPE_DATA, buf, sizeof(u32)); 520 err = p54u_bulk_msg(priv, P54U_PIPE_DATA, buf, sizeof(u32));
566 if (err) { 521 if (err) {
567 dev_err(&priv->udev->dev, "(p54usb) firmware upload failed!\n"); 522 dev_err(&priv->udev->dev, "(p54usb) firmware upload failed!\n");
@@ -612,19 +567,14 @@ static int p54u_upload_firmware_3887(struct ieee80211_hw *dev)
612 if (err) 567 if (err)
613 goto err_upload_failed; 568 goto err_upload_failed;
614 569
615 err_upload_failed: 570err_upload_failed:
616 release_firmware(fw_entry);
617 err_req_fw_failed:
618 err_reset:
619 kfree(buf); 571 kfree(buf);
620 err_bufalloc:
621 return err; 572 return err;
622} 573}
623 574
624static int p54u_upload_firmware_net2280(struct ieee80211_hw *dev) 575static int p54u_upload_firmware_net2280(struct ieee80211_hw *dev)
625{ 576{
626 struct p54u_priv *priv = dev->priv; 577 struct p54u_priv *priv = dev->priv;
627 const struct firmware *fw_entry = NULL;
628 const struct p54p_csr *devreg = (const struct p54p_csr *) P54U_DEV_BASE; 578 const struct p54p_csr *devreg = (const struct p54p_csr *) P54U_DEV_BASE;
629 int err, alen; 579 int err, alen;
630 void *buf; 580 void *buf;
@@ -639,33 +589,6 @@ static int p54u_upload_firmware_net2280(struct ieee80211_hw *dev)
639 return -ENOMEM; 589 return -ENOMEM;
640 } 590 }
641 591
642 err = request_firmware(&fw_entry, "isl3886usb", &priv->udev->dev);
643 if (err) {
644 dev_err(&priv->udev->dev, "(p54usb) cannot find firmware "
645 "(isl3886usb)\n");
646 err = request_firmware(&fw_entry, "isl3890usb",
647 &priv->udev->dev);
648 if (err) {
649 kfree(buf);
650 return err;
651 }
652 }
653
654 err = p54_parse_firmware(dev, fw_entry);
655 if (err) {
656 kfree(buf);
657 release_firmware(fw_entry);
658 return err;
659 }
660
661 if (priv->common.fw_interface != FW_LM86) {
662 dev_err(&priv->udev->dev, "wrong firmware, "
663 "please get a LM86(USB) firmware and try again.\n");
664 kfree(buf);
665 release_firmware(fw_entry);
666 return -EINVAL;
667 }
668
669#define P54U_WRITE(type, addr, data) \ 592#define P54U_WRITE(type, addr, data) \
670 do {\ 593 do {\
671 err = p54u_write(priv, buf, type,\ 594 err = p54u_write(priv, buf, type,\
@@ -765,8 +688,8 @@ static int p54u_upload_firmware_net2280(struct ieee80211_hw *dev)
765 P54U_WRITE(NET2280_DEV_U32, &devreg->int_ack, reg); 688 P54U_WRITE(NET2280_DEV_U32, &devreg->int_ack, reg);
766 689
767 /* finally, we can upload firmware now! */ 690 /* finally, we can upload firmware now! */
768 remains = fw_entry->size; 691 remains = priv->fw->size;
769 data = fw_entry->data; 692 data = priv->fw->data;
770 offset = ISL38XX_DEV_FIRMWARE_ADDR; 693 offset = ISL38XX_DEV_FIRMWARE_ADDR;
771 694
772 while (remains) { 695 while (remains) {
@@ -875,12 +798,54 @@ static int p54u_upload_firmware_net2280(struct ieee80211_hw *dev)
875#undef P54U_WRITE 798#undef P54U_WRITE
876#undef P54U_READ 799#undef P54U_READ
877 800
878 fail: 801fail:
879 release_firmware(fw_entry);
880 kfree(buf); 802 kfree(buf);
881 return err; 803 return err;
882} 804}
883 805
806static int p54u_load_firmware(struct ieee80211_hw *dev)
807{
808 struct p54u_priv *priv = dev->priv;
809 int err, i;
810
811 BUILD_BUG_ON(ARRAY_SIZE(p54u_fwlist) != __NUM_P54U_HWTYPES);
812
813 for (i = 0; i < __NUM_P54U_HWTYPES; i++)
814 if (p54u_fwlist[i].type == priv->hw_type)
815 break;
816
817 if (i == __NUM_P54U_HWTYPES)
818 return -EOPNOTSUPP;
819
820 err = request_firmware(&priv->fw, p54u_fwlist[i].fw, &priv->udev->dev);
821 if (err) {
822 dev_err(&priv->udev->dev, "(p54usb) cannot load firmware %s "
823 "(%d)!\n", p54u_fwlist[i].fw, err);
824
825 err = request_firmware(&priv->fw, p54u_fwlist[i].fw_legacy,
826 &priv->udev->dev);
827 if (err)
828 return err;
829 }
830
831 err = p54_parse_firmware(dev, priv->fw);
832 if (err)
833 goto out;
834
835 if (priv->common.fw_interface != p54u_fwlist[i].intf) {
836 dev_err(&priv->udev->dev, "wrong firmware, please get "
837 "a firmware for \"%s\" and try again.\n",
838 p54u_fwlist[i].hw);
839 err = -EINVAL;
840 }
841
842out:
843 if (err)
844 release_firmware(priv->fw);
845
846 return err;
847}
848
884static int p54u_open(struct ieee80211_hw *dev) 849static int p54u_open(struct ieee80211_hw *dev)
885{ 850{
886 struct p54u_priv *priv = dev->priv; 851 struct p54u_priv *priv = dev->priv;
@@ -922,6 +887,7 @@ static int __devinit p54u_probe(struct usb_interface *intf,
922 } 887 }
923 888
924 priv = dev->priv; 889 priv = dev->priv;
890 priv->hw_type = P54U_INVALID_HW;
925 891
926 SET_IEEE80211_DEV(dev, &intf->dev); 892 SET_IEEE80211_DEV(dev, &intf->dev);
927 usb_set_intfdata(intf, dev); 893 usb_set_intfdata(intf, dev);
@@ -953,37 +919,48 @@ static int __devinit p54u_probe(struct usb_interface *intf,
953 priv->common.open = p54u_open; 919 priv->common.open = p54u_open;
954 priv->common.stop = p54u_stop; 920 priv->common.stop = p54u_stop;
955 if (recognized_pipes < P54U_PIPE_NUMBER) { 921 if (recognized_pipes < P54U_PIPE_NUMBER) {
922#ifdef CONFIG_PM
923 /* ISL3887 needs a full reset on resume */
924 udev->reset_resume = 1;
925 err = p54u_device_reset(dev);
926#endif
927
956 priv->hw_type = P54U_3887; 928 priv->hw_type = P54U_3887;
957 err = p54u_upload_firmware_3887(dev); 929 dev->extra_tx_headroom += sizeof(struct lm87_tx_hdr);
958 if (priv->common.fw_interface == FW_LM87) { 930 priv->common.tx_hdr_len = sizeof(struct lm87_tx_hdr);
959 dev->extra_tx_headroom += sizeof(struct lm87_tx_hdr); 931 priv->common.tx = p54u_tx_lm87;
960 priv->common.tx_hdr_len = sizeof(struct lm87_tx_hdr); 932 priv->upload_fw = p54u_upload_firmware_3887;
961 priv->common.tx = p54u_tx_lm87;
962 } else
963 priv->common.tx = p54u_tx_3887;
964 } else { 933 } else {
965 priv->hw_type = P54U_NET2280; 934 priv->hw_type = P54U_NET2280;
966 dev->extra_tx_headroom += sizeof(struct net2280_tx_hdr); 935 dev->extra_tx_headroom += sizeof(struct net2280_tx_hdr);
967 priv->common.tx_hdr_len = sizeof(struct net2280_tx_hdr); 936 priv->common.tx_hdr_len = sizeof(struct net2280_tx_hdr);
968 priv->common.tx = p54u_tx_net2280; 937 priv->common.tx = p54u_tx_net2280;
969 err = p54u_upload_firmware_net2280(dev); 938 priv->upload_fw = p54u_upload_firmware_net2280;
970 } 939 }
940 err = p54u_load_firmware(dev);
971 if (err) 941 if (err)
972 goto err_free_dev; 942 goto err_free_dev;
973 943
944 err = priv->upload_fw(dev);
945 if (err)
946 goto err_free_fw;
947
974 p54u_open(dev); 948 p54u_open(dev);
975 err = p54_read_eeprom(dev); 949 err = p54_read_eeprom(dev);
976 p54u_stop(dev); 950 p54u_stop(dev);
977 if (err) 951 if (err)
978 goto err_free_dev; 952 goto err_free_fw;
979 953
980 err = p54_register_common(dev, &udev->dev); 954 err = p54_register_common(dev, &udev->dev);
981 if (err) 955 if (err)
982 goto err_free_dev; 956 goto err_free_fw;
983 957
984 return 0; 958 return 0;
985 959
986 err_free_dev: 960err_free_fw:
961 release_firmware(priv->fw);
962
963err_free_dev:
987 ieee80211_free_hw(dev); 964 ieee80211_free_hw(dev);
988 usb_set_intfdata(intf, NULL); 965 usb_set_intfdata(intf, NULL);
989 usb_put_dev(udev); 966 usb_put_dev(udev);
@@ -1002,20 +979,64 @@ static void __devexit p54u_disconnect(struct usb_interface *intf)
1002 979
1003 priv = dev->priv; 980 priv = dev->priv;
1004 usb_put_dev(interface_to_usbdev(intf)); 981 usb_put_dev(interface_to_usbdev(intf));
982 release_firmware(priv->fw);
1005 p54_free_common(dev); 983 p54_free_common(dev);
1006 ieee80211_free_hw(dev); 984 ieee80211_free_hw(dev);
1007} 985}
1008 986
1009static int p54u_pre_reset(struct usb_interface *intf) 987static int p54u_pre_reset(struct usb_interface *intf)
1010{ 988{
989 struct ieee80211_hw *dev = usb_get_intfdata(intf);
990
991 if (!dev)
992 return -ENODEV;
993
994 p54u_stop(dev);
1011 return 0; 995 return 0;
1012} 996}
1013 997
998static int p54u_resume(struct usb_interface *intf)
999{
1000 struct ieee80211_hw *dev = usb_get_intfdata(intf);
1001 struct p54u_priv *priv;
1002
1003 if (!dev)
1004 return -ENODEV;
1005
1006 priv = dev->priv;
1007 if (unlikely(!(priv->upload_fw && priv->fw)))
1008 return 0;
1009
1010 return priv->upload_fw(dev);
1011}
1012
1014static int p54u_post_reset(struct usb_interface *intf) 1013static int p54u_post_reset(struct usb_interface *intf)
1015{ 1014{
1015 struct ieee80211_hw *dev = usb_get_intfdata(intf);
1016 struct p54u_priv *priv;
1017 int err;
1018
1019 err = p54u_resume(intf);
1020 if (err)
1021 return err;
1022
1023 /* reinitialize old device state */
1024 priv = dev->priv;
1025 if (priv->common.mode != NL80211_IFTYPE_UNSPECIFIED)
1026 ieee80211_restart_hw(dev);
1027
1016 return 0; 1028 return 0;
1017} 1029}
1018 1030
1031#ifdef CONFIG_PM
1032
1033static int p54u_suspend(struct usb_interface *intf, pm_message_t message)
1034{
1035 return p54u_pre_reset(intf);
1036}
1037
1038#endif /* CONFIG_PM */
1039
1019static struct usb_driver p54u_driver = { 1040static struct usb_driver p54u_driver = {
1020 .name = "p54usb", 1041 .name = "p54usb",
1021 .id_table = p54u_table, 1042 .id_table = p54u_table,
@@ -1023,6 +1044,11 @@ static struct usb_driver p54u_driver = {
1023 .disconnect = p54u_disconnect, 1044 .disconnect = p54u_disconnect,
1024 .pre_reset = p54u_pre_reset, 1045 .pre_reset = p54u_pre_reset,
1025 .post_reset = p54u_post_reset, 1046 .post_reset = p54u_post_reset,
1047#ifdef CONFIG_PM
1048 .suspend = p54u_suspend,
1049 .resume = p54u_resume,
1050 .reset_resume = p54u_resume,
1051#endif /* CONFIG_PM */
1026 .soft_unbind = 1, 1052 .soft_unbind = 1,
1027}; 1053};
1028 1054
diff --git a/drivers/net/wireless/p54/p54usb.h b/drivers/net/wireless/p54/p54usb.h
index 8bc58982d8dd..e935b79f7f75 100644
--- a/drivers/net/wireless/p54/p54usb.h
+++ b/drivers/net/wireless/p54/p54usb.h
@@ -123,18 +123,26 @@ struct p54u_rx_info {
123 struct ieee80211_hw *dev; 123 struct ieee80211_hw *dev;
124}; 124};
125 125
126enum p54u_hw_type {
127 P54U_INVALID_HW,
128 P54U_NET2280,
129 P54U_3887,
130
131 /* keep last */
132 __NUM_P54U_HWTYPES,
133};
134
126struct p54u_priv { 135struct p54u_priv {
127 struct p54_common common; 136 struct p54_common common;
128 struct usb_device *udev; 137 struct usb_device *udev;
129 struct usb_interface *intf; 138 struct usb_interface *intf;
130 enum { 139 int (*upload_fw)(struct ieee80211_hw *dev);
131 P54U_NET2280 = 0,
132 P54U_3887
133 } hw_type;
134 140
141 enum p54u_hw_type hw_type;
135 spinlock_t lock; 142 spinlock_t lock;
136 struct sk_buff_head rx_queue; 143 struct sk_buff_head rx_queue;
137 struct usb_anchor submitted; 144 struct usb_anchor submitted;
145 const struct firmware *fw;
138}; 146};
139 147
140#endif /* P54USB_H */ 148#endif /* P54USB_H */
diff --git a/drivers/net/wireless/rt2x00/Kconfig b/drivers/net/wireless/rt2x00/Kconfig
index bfc5d9cf716e..18ee7d6c4028 100644
--- a/drivers/net/wireless/rt2x00/Kconfig
+++ b/drivers/net/wireless/rt2x00/Kconfig
@@ -77,6 +77,20 @@ config RT73USB
77 77
78 When compiled as a module, this driver will be called "rt73usb.ko". 78 When compiled as a module, this driver will be called "rt73usb.ko".
79 79
80config RT2800USB
81 tristate "Ralink rt2800 (USB) support"
82 depends on USB
83 select RT2X00_LIB_USB
84 select RT2X00_LIB_HT
85 select RT2X00_LIB_FIRMWARE
86 select RT2X00_LIB_CRYPTO
87 select CRC_CCITT
88 ---help---
89 This adds support for rt2800 wireless chipset family.
90 Supported chips: RT2770, RT2870 & RT3070.
91
92 When compiled as a module, this driver will be called "rt2800usb.ko".
93
80config RT2X00_LIB_PCI 94config RT2X00_LIB_PCI
81 tristate 95 tristate
82 select RT2X00_LIB 96 select RT2X00_LIB
@@ -88,6 +102,9 @@ config RT2X00_LIB_USB
88config RT2X00_LIB 102config RT2X00_LIB
89 tristate 103 tristate
90 104
105config RT2X00_LIB_HT
106 boolean
107
91config RT2X00_LIB_FIRMWARE 108config RT2X00_LIB_FIRMWARE
92 boolean 109 boolean
93 select FW_LOADER 110 select FW_LOADER
diff --git a/drivers/net/wireless/rt2x00/Makefile b/drivers/net/wireless/rt2x00/Makefile
index f22d808d8c51..bfc7226f0afe 100644
--- a/drivers/net/wireless/rt2x00/Makefile
+++ b/drivers/net/wireless/rt2x00/Makefile
@@ -8,6 +8,7 @@ rt2x00lib-$(CONFIG_RT2X00_LIB_CRYPTO) += rt2x00crypto.o
8rt2x00lib-$(CONFIG_RT2X00_LIB_RFKILL) += rt2x00rfkill.o 8rt2x00lib-$(CONFIG_RT2X00_LIB_RFKILL) += rt2x00rfkill.o
9rt2x00lib-$(CONFIG_RT2X00_LIB_FIRMWARE) += rt2x00firmware.o 9rt2x00lib-$(CONFIG_RT2X00_LIB_FIRMWARE) += rt2x00firmware.o
10rt2x00lib-$(CONFIG_RT2X00_LIB_LEDS) += rt2x00leds.o 10rt2x00lib-$(CONFIG_RT2X00_LIB_LEDS) += rt2x00leds.o
11rt2x00lib-$(CONFIG_RT2X00_LIB_HT) += rt2x00ht.o
11 12
12obj-$(CONFIG_RT2X00_LIB) += rt2x00lib.o 13obj-$(CONFIG_RT2X00_LIB) += rt2x00lib.o
13obj-$(CONFIG_RT2X00_LIB_PCI) += rt2x00pci.o 14obj-$(CONFIG_RT2X00_LIB_PCI) += rt2x00pci.o
@@ -17,3 +18,4 @@ obj-$(CONFIG_RT2500PCI) += rt2500pci.o
17obj-$(CONFIG_RT61PCI) += rt61pci.o 18obj-$(CONFIG_RT61PCI) += rt61pci.o
18obj-$(CONFIG_RT2500USB) += rt2500usb.o 19obj-$(CONFIG_RT2500USB) += rt2500usb.o
19obj-$(CONFIG_RT73USB) += rt73usb.o 20obj-$(CONFIG_RT73USB) += rt73usb.o
21obj-$(CONFIG_RT2800USB) += rt2800usb.o
diff --git a/drivers/net/wireless/rt2x00/rt2400pci.c b/drivers/net/wireless/rt2x00/rt2400pci.c
index 411eb9cbb4e5..6f39ba662188 100644
--- a/drivers/net/wireless/rt2x00/rt2400pci.c
+++ b/drivers/net/wireless/rt2x00/rt2400pci.c
@@ -1580,7 +1580,6 @@ static const struct ieee80211_ops rt2400pci_mac80211_ops = {
1580 .add_interface = rt2x00mac_add_interface, 1580 .add_interface = rt2x00mac_add_interface,
1581 .remove_interface = rt2x00mac_remove_interface, 1581 .remove_interface = rt2x00mac_remove_interface,
1582 .config = rt2x00mac_config, 1582 .config = rt2x00mac_config,
1583 .config_interface = rt2x00mac_config_interface,
1584 .configure_filter = rt2x00mac_configure_filter, 1583 .configure_filter = rt2x00mac_configure_filter,
1585 .get_stats = rt2x00mac_get_stats, 1584 .get_stats = rt2x00mac_get_stats,
1586 .bss_info_changed = rt2x00mac_bss_info_changed, 1585 .bss_info_changed = rt2x00mac_bss_info_changed,
diff --git a/drivers/net/wireless/rt2x00/rt2500pci.c b/drivers/net/wireless/rt2x00/rt2500pci.c
index e1be67ca23d8..906960f67b6c 100644
--- a/drivers/net/wireless/rt2x00/rt2500pci.c
+++ b/drivers/net/wireless/rt2x00/rt2500pci.c
@@ -1879,7 +1879,6 @@ static const struct ieee80211_ops rt2500pci_mac80211_ops = {
1879 .add_interface = rt2x00mac_add_interface, 1879 .add_interface = rt2x00mac_add_interface,
1880 .remove_interface = rt2x00mac_remove_interface, 1880 .remove_interface = rt2x00mac_remove_interface,
1881 .config = rt2x00mac_config, 1881 .config = rt2x00mac_config,
1882 .config_interface = rt2x00mac_config_interface,
1883 .configure_filter = rt2x00mac_configure_filter, 1882 .configure_filter = rt2x00mac_configure_filter,
1884 .get_stats = rt2x00mac_get_stats, 1883 .get_stats = rt2x00mac_get_stats,
1885 .bss_info_changed = rt2x00mac_bss_info_changed, 1884 .bss_info_changed = rt2x00mac_bss_info_changed,
diff --git a/drivers/net/wireless/rt2x00/rt2500usb.c b/drivers/net/wireless/rt2x00/rt2500usb.c
index 9e630e70fc97..1debb88bc60e 100644
--- a/drivers/net/wireless/rt2x00/rt2500usb.c
+++ b/drivers/net/wireless/rt2x00/rt2500usb.c
@@ -1559,7 +1559,7 @@ static int rt2500usb_init_eeprom(struct rt2x00_dev *rt2x00dev)
1559 rt2500usb_register_read(rt2x00dev, MAC_CSR0, &reg); 1559 rt2500usb_register_read(rt2x00dev, MAC_CSR0, &reg);
1560 rt2x00_set_chip(rt2x00dev, RT2570, value, reg); 1560 rt2x00_set_chip(rt2x00dev, RT2570, value, reg);
1561 1561
1562 if (!rt2x00_check_rev(&rt2x00dev->chip, 0)) { 1562 if (!rt2x00_check_rev(&rt2x00dev->chip, 0x000ffff0, 0)) {
1563 ERROR(rt2x00dev, "Invalid RT chipset detected.\n"); 1563 ERROR(rt2x00dev, "Invalid RT chipset detected.\n");
1564 return -ENODEV; 1564 return -ENODEV;
1565 } 1565 }
@@ -1908,7 +1908,6 @@ static const struct ieee80211_ops rt2500usb_mac80211_ops = {
1908 .add_interface = rt2x00mac_add_interface, 1908 .add_interface = rt2x00mac_add_interface,
1909 .remove_interface = rt2x00mac_remove_interface, 1909 .remove_interface = rt2x00mac_remove_interface,
1910 .config = rt2x00mac_config, 1910 .config = rt2x00mac_config,
1911 .config_interface = rt2x00mac_config_interface,
1912 .configure_filter = rt2x00mac_configure_filter, 1911 .configure_filter = rt2x00mac_configure_filter,
1913 .set_key = rt2x00mac_set_key, 1912 .set_key = rt2x00mac_set_key,
1914 .get_stats = rt2x00mac_get_stats, 1913 .get_stats = rt2x00mac_get_stats,
diff --git a/drivers/net/wireless/rt2x00/rt2800usb.c b/drivers/net/wireless/rt2x00/rt2800usb.c
new file mode 100644
index 000000000000..257bfb5483c9
--- /dev/null
+++ b/drivers/net/wireless/rt2x00/rt2800usb.c
@@ -0,0 +1,3071 @@
1/*
2 Copyright (C) 2004 - 2009 rt2x00 SourceForge Project
3 <http://rt2x00.serialmonkey.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the
17 Free Software Foundation, Inc.,
18 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21/*
22 Module: rt2800usb
23 Abstract: rt2800usb device specific routines.
24 Supported chipsets: RT2800U.
25 */
26
27#include <linux/crc-ccitt.h>
28#include <linux/delay.h>
29#include <linux/etherdevice.h>
30#include <linux/init.h>
31#include <linux/kernel.h>
32#include <linux/module.h>
33#include <linux/usb.h>
34
35#include "rt2x00.h"
36#include "rt2x00usb.h"
37#include "rt2800usb.h"
38
39/*
40 * Allow hardware encryption to be disabled.
41 */
42static int modparam_nohwcrypt = 1;
43module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO);
44MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
45
46/*
47 * Register access.
48 * All access to the CSR registers will go through the methods
49 * rt2x00usb_register_read and rt2x00usb_register_write.
50 * BBP and RF register require indirect register access,
51 * and use the CSR registers BBPCSR and RFCSR to achieve this.
52 * These indirect registers work with busy bits,
53 * and we will try maximal REGISTER_BUSY_COUNT times to access
54 * the register while taking a REGISTER_BUSY_DELAY us delay
55 * between each attampt. When the busy bit is still set at that time,
56 * the access attempt is considered to have failed,
57 * and we will print an error.
58 * The _lock versions must be used if you already hold the csr_mutex
59 */
60#define WAIT_FOR_BBP(__dev, __reg) \
61 rt2x00usb_regbusy_read((__dev), BBP_CSR_CFG, BBP_CSR_CFG_BUSY, (__reg))
62#define WAIT_FOR_RFCSR(__dev, __reg) \
63 rt2x00usb_regbusy_read((__dev), RF_CSR_CFG, RF_CSR_CFG_BUSY, (__reg))
64#define WAIT_FOR_RF(__dev, __reg) \
65 rt2x00usb_regbusy_read((__dev), RF_CSR_CFG0, RF_CSR_CFG0_BUSY, (__reg))
66#define WAIT_FOR_MCU(__dev, __reg) \
67 rt2x00usb_regbusy_read((__dev), H2M_MAILBOX_CSR, \
68 H2M_MAILBOX_CSR_OWNER, (__reg))
69
70static void rt2800usb_bbp_write(struct rt2x00_dev *rt2x00dev,
71 const unsigned int word, const u8 value)
72{
73 u32 reg;
74
75 mutex_lock(&rt2x00dev->csr_mutex);
76
77 /*
78 * Wait until the BBP becomes available, afterwards we
79 * can safely write the new data into the register.
80 */
81 if (WAIT_FOR_BBP(rt2x00dev, &reg)) {
82 reg = 0;
83 rt2x00_set_field32(&reg, BBP_CSR_CFG_VALUE, value);
84 rt2x00_set_field32(&reg, BBP_CSR_CFG_REGNUM, word);
85 rt2x00_set_field32(&reg, BBP_CSR_CFG_BUSY, 1);
86 rt2x00_set_field32(&reg, BBP_CSR_CFG_READ_CONTROL, 0);
87
88 rt2x00usb_register_write_lock(rt2x00dev, BBP_CSR_CFG, reg);
89 }
90
91 mutex_unlock(&rt2x00dev->csr_mutex);
92}
93
94static void rt2800usb_bbp_read(struct rt2x00_dev *rt2x00dev,
95 const unsigned int word, u8 *value)
96{
97 u32 reg;
98
99 mutex_lock(&rt2x00dev->csr_mutex);
100
101 /*
102 * Wait until the BBP becomes available, afterwards we
103 * can safely write the read request into the register.
104 * After the data has been written, we wait until hardware
105 * returns the correct value, if at any time the register
106 * doesn't become available in time, reg will be 0xffffffff
107 * which means we return 0xff to the caller.
108 */
109 if (WAIT_FOR_BBP(rt2x00dev, &reg)) {
110 reg = 0;
111 rt2x00_set_field32(&reg, BBP_CSR_CFG_REGNUM, word);
112 rt2x00_set_field32(&reg, BBP_CSR_CFG_BUSY, 1);
113 rt2x00_set_field32(&reg, BBP_CSR_CFG_READ_CONTROL, 1);
114
115 rt2x00usb_register_write_lock(rt2x00dev, BBP_CSR_CFG, reg);
116
117 WAIT_FOR_BBP(rt2x00dev, &reg);
118 }
119
120 *value = rt2x00_get_field32(reg, BBP_CSR_CFG_VALUE);
121
122 mutex_unlock(&rt2x00dev->csr_mutex);
123}
124
125static void rt2800usb_rfcsr_write(struct rt2x00_dev *rt2x00dev,
126 const unsigned int word, const u8 value)
127{
128 u32 reg;
129
130 mutex_lock(&rt2x00dev->csr_mutex);
131
132 /*
133 * Wait until the RFCSR becomes available, afterwards we
134 * can safely write the new data into the register.
135 */
136 if (WAIT_FOR_RFCSR(rt2x00dev, &reg)) {
137 reg = 0;
138 rt2x00_set_field32(&reg, RF_CSR_CFG_DATA, value);
139 rt2x00_set_field32(&reg, RF_CSR_CFG_REGNUM, word);
140 rt2x00_set_field32(&reg, RF_CSR_CFG_WRITE, 1);
141 rt2x00_set_field32(&reg, RF_CSR_CFG_BUSY, 1);
142
143 rt2x00usb_register_write_lock(rt2x00dev, RF_CSR_CFG, reg);
144 }
145
146 mutex_unlock(&rt2x00dev->csr_mutex);
147}
148
149static void rt2800usb_rfcsr_read(struct rt2x00_dev *rt2x00dev,
150 const unsigned int word, u8 *value)
151{
152 u32 reg;
153
154 mutex_lock(&rt2x00dev->csr_mutex);
155
156 /*
157 * Wait until the RFCSR becomes available, afterwards we
158 * can safely write the read request into the register.
159 * After the data has been written, we wait until hardware
160 * returns the correct value, if at any time the register
161 * doesn't become available in time, reg will be 0xffffffff
162 * which means we return 0xff to the caller.
163 */
164 if (WAIT_FOR_RFCSR(rt2x00dev, &reg)) {
165 reg = 0;
166 rt2x00_set_field32(&reg, RF_CSR_CFG_REGNUM, word);
167 rt2x00_set_field32(&reg, RF_CSR_CFG_WRITE, 0);
168 rt2x00_set_field32(&reg, RF_CSR_CFG_BUSY, 1);
169
170 rt2x00usb_register_write_lock(rt2x00dev, BBP_CSR_CFG, reg);
171
172 WAIT_FOR_RFCSR(rt2x00dev, &reg);
173 }
174
175 *value = rt2x00_get_field32(reg, RF_CSR_CFG_DATA);
176
177 mutex_unlock(&rt2x00dev->csr_mutex);
178}
179
180static void rt2800usb_rf_write(struct rt2x00_dev *rt2x00dev,
181 const unsigned int word, const u32 value)
182{
183 u32 reg;
184
185 mutex_lock(&rt2x00dev->csr_mutex);
186
187 /*
188 * Wait until the RF becomes available, afterwards we
189 * can safely write the new data into the register.
190 */
191 if (WAIT_FOR_RF(rt2x00dev, &reg)) {
192 reg = 0;
193 rt2x00_set_field32(&reg, RF_CSR_CFG0_REG_VALUE_BW, value);
194 rt2x00_set_field32(&reg, RF_CSR_CFG0_STANDBYMODE, 0);
195 rt2x00_set_field32(&reg, RF_CSR_CFG0_SEL, 0);
196 rt2x00_set_field32(&reg, RF_CSR_CFG0_BUSY, 1);
197
198 rt2x00usb_register_write_lock(rt2x00dev, RF_CSR_CFG0, reg);
199 rt2x00_rf_write(rt2x00dev, word, value);
200 }
201
202 mutex_unlock(&rt2x00dev->csr_mutex);
203}
204
205static void rt2800usb_mcu_request(struct rt2x00_dev *rt2x00dev,
206 const u8 command, const u8 token,
207 const u8 arg0, const u8 arg1)
208{
209 u32 reg;
210
211 mutex_lock(&rt2x00dev->csr_mutex);
212
213 /*
214 * Wait until the MCU becomes available, afterwards we
215 * can safely write the new data into the register.
216 */
217 if (WAIT_FOR_MCU(rt2x00dev, &reg)) {
218 rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_OWNER, 1);
219 rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_CMD_TOKEN, token);
220 rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_ARG0, arg0);
221 rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_ARG1, arg1);
222 rt2x00usb_register_write_lock(rt2x00dev, H2M_MAILBOX_CSR, reg);
223
224 reg = 0;
225 rt2x00_set_field32(&reg, HOST_CMD_CSR_HOST_COMMAND, command);
226 rt2x00usb_register_write_lock(rt2x00dev, HOST_CMD_CSR, reg);
227 }
228
229 mutex_unlock(&rt2x00dev->csr_mutex);
230}
231
232#ifdef CONFIG_RT2X00_LIB_DEBUGFS
233static const struct rt2x00debug rt2800usb_rt2x00debug = {
234 .owner = THIS_MODULE,
235 .csr = {
236 .read = rt2x00usb_register_read,
237 .write = rt2x00usb_register_write,
238 .flags = RT2X00DEBUGFS_OFFSET,
239 .word_base = CSR_REG_BASE,
240 .word_size = sizeof(u32),
241 .word_count = CSR_REG_SIZE / sizeof(u32),
242 },
243 .eeprom = {
244 .read = rt2x00_eeprom_read,
245 .write = rt2x00_eeprom_write,
246 .word_base = EEPROM_BASE,
247 .word_size = sizeof(u16),
248 .word_count = EEPROM_SIZE / sizeof(u16),
249 },
250 .bbp = {
251 .read = rt2800usb_bbp_read,
252 .write = rt2800usb_bbp_write,
253 .word_base = BBP_BASE,
254 .word_size = sizeof(u8),
255 .word_count = BBP_SIZE / sizeof(u8),
256 },
257 .rf = {
258 .read = rt2x00_rf_read,
259 .write = rt2800usb_rf_write,
260 .word_base = RF_BASE,
261 .word_size = sizeof(u32),
262 .word_count = RF_SIZE / sizeof(u32),
263 },
264};
265#endif /* CONFIG_RT2X00_LIB_DEBUGFS */
266
267#ifdef CONFIG_RT2X00_LIB_RFKILL
268static int rt2800usb_rfkill_poll(struct rt2x00_dev *rt2x00dev)
269{
270 u32 reg;
271
272 rt2x00usb_register_read(rt2x00dev, GPIO_CTRL_CFG, &reg);
273 return rt2x00_get_field32(reg, GPIO_CTRL_CFG_BIT2);
274}
275#else
276#define rt2800usb_rfkill_poll NULL
277#endif /* CONFIG_RT2X00_LIB_RFKILL */
278
279#ifdef CONFIG_RT2X00_LIB_LEDS
280static void rt2800usb_brightness_set(struct led_classdev *led_cdev,
281 enum led_brightness brightness)
282{
283 struct rt2x00_led *led =
284 container_of(led_cdev, struct rt2x00_led, led_dev);
285 unsigned int enabled = brightness != LED_OFF;
286 unsigned int bg_mode =
287 (enabled && led->rt2x00dev->curr_band == IEEE80211_BAND_2GHZ);
288 unsigned int polarity =
289 rt2x00_get_field16(led->rt2x00dev->led_mcu_reg,
290 EEPROM_FREQ_LED_POLARITY);
291 unsigned int ledmode =
292 rt2x00_get_field16(led->rt2x00dev->led_mcu_reg,
293 EEPROM_FREQ_LED_MODE);
294
295 if (led->type == LED_TYPE_RADIO) {
296 rt2800usb_mcu_request(led->rt2x00dev, MCU_LED, 0xff, ledmode,
297 enabled ? 0x20 : 0);
298 } else if (led->type == LED_TYPE_ASSOC) {
299 rt2800usb_mcu_request(led->rt2x00dev, MCU_LED, 0xff, ledmode,
300 enabled ? (bg_mode ? 0x60 : 0xa0) : 0x20);
301 } else if (led->type == LED_TYPE_QUALITY) {
302 /*
303 * The brightness is divided into 6 levels (0 - 5),
304 * The specs tell us the following levels:
305 * 0, 1 ,3, 7, 15, 31
306 * to determine the level in a simple way we can simply
307 * work with bitshifting:
308 * (1 << level) - 1
309 */
310 rt2800usb_mcu_request(led->rt2x00dev, MCU_LED_STRENGTH, 0xff,
311 (1 << brightness / (LED_FULL / 6)) - 1,
312 polarity);
313 }
314}
315
316static int rt2800usb_blink_set(struct led_classdev *led_cdev,
317 unsigned long *delay_on,
318 unsigned long *delay_off)
319{
320 struct rt2x00_led *led =
321 container_of(led_cdev, struct rt2x00_led, led_dev);
322 u32 reg;
323
324 rt2x00usb_register_read(led->rt2x00dev, LED_CFG, &reg);
325 rt2x00_set_field32(&reg, LED_CFG_ON_PERIOD, *delay_on);
326 rt2x00_set_field32(&reg, LED_CFG_OFF_PERIOD, *delay_off);
327 rt2x00_set_field32(&reg, LED_CFG_SLOW_BLINK_PERIOD, 3);
328 rt2x00_set_field32(&reg, LED_CFG_R_LED_MODE, 3);
329 rt2x00_set_field32(&reg, LED_CFG_G_LED_MODE, 12);
330 rt2x00_set_field32(&reg, LED_CFG_Y_LED_MODE, 3);
331 rt2x00_set_field32(&reg, LED_CFG_LED_POLAR, 1);
332 rt2x00usb_register_write(led->rt2x00dev, LED_CFG, reg);
333
334 return 0;
335}
336
337static void rt2800usb_init_led(struct rt2x00_dev *rt2x00dev,
338 struct rt2x00_led *led,
339 enum led_type type)
340{
341 led->rt2x00dev = rt2x00dev;
342 led->type = type;
343 led->led_dev.brightness_set = rt2800usb_brightness_set;
344 led->led_dev.blink_set = rt2800usb_blink_set;
345 led->flags = LED_INITIALIZED;
346}
347#endif /* CONFIG_RT2X00_LIB_LEDS */
348
349/*
350 * Configuration handlers.
351 */
352static void rt2800usb_config_wcid_attr(struct rt2x00_dev *rt2x00dev,
353 struct rt2x00lib_crypto *crypto,
354 struct ieee80211_key_conf *key)
355{
356 struct mac_wcid_entry wcid_entry;
357 struct mac_iveiv_entry iveiv_entry;
358 u32 offset;
359 u32 reg;
360
361 offset = MAC_WCID_ATTR_ENTRY(key->hw_key_idx);
362
363 rt2x00usb_register_read(rt2x00dev, offset, &reg);
364 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_KEYTAB,
365 !!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE));
366 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_CIPHER,
367 (crypto->cmd == SET_KEY) * crypto->cipher);
368 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_BSS_IDX,
369 (crypto->cmd == SET_KEY) * crypto->bssidx);
370 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_RX_WIUDF, crypto->cipher);
371 rt2x00usb_register_write(rt2x00dev, offset, reg);
372
373 offset = MAC_IVEIV_ENTRY(key->hw_key_idx);
374
375 memset(&iveiv_entry, 0, sizeof(iveiv_entry));
376 if ((crypto->cipher == CIPHER_TKIP) ||
377 (crypto->cipher == CIPHER_TKIP_NO_MIC) ||
378 (crypto->cipher == CIPHER_AES))
379 iveiv_entry.iv[3] |= 0x20;
380 iveiv_entry.iv[3] |= key->keyidx << 6;
381 rt2x00usb_register_multiwrite(rt2x00dev, offset,
382 &iveiv_entry, sizeof(iveiv_entry));
383
384 offset = MAC_WCID_ENTRY(key->hw_key_idx);
385
386 memset(&wcid_entry, 0, sizeof(wcid_entry));
387 if (crypto->cmd == SET_KEY)
388 memcpy(&wcid_entry, crypto->address, ETH_ALEN);
389 rt2x00usb_register_multiwrite(rt2x00dev, offset,
390 &wcid_entry, sizeof(wcid_entry));
391}
392
393static int rt2800usb_config_shared_key(struct rt2x00_dev *rt2x00dev,
394 struct rt2x00lib_crypto *crypto,
395 struct ieee80211_key_conf *key)
396{
397 struct hw_key_entry key_entry;
398 struct rt2x00_field32 field;
399 int timeout;
400 u32 offset;
401 u32 reg;
402
403 if (crypto->cmd == SET_KEY) {
404 key->hw_key_idx = (4 * crypto->bssidx) + key->keyidx;
405
406 memcpy(key_entry.key, crypto->key,
407 sizeof(key_entry.key));
408 memcpy(key_entry.tx_mic, crypto->tx_mic,
409 sizeof(key_entry.tx_mic));
410 memcpy(key_entry.rx_mic, crypto->rx_mic,
411 sizeof(key_entry.rx_mic));
412
413 offset = SHARED_KEY_ENTRY(key->hw_key_idx);
414 timeout = REGISTER_TIMEOUT32(sizeof(key_entry));
415 rt2x00usb_vendor_request_large_buff(rt2x00dev, USB_MULTI_WRITE,
416 USB_VENDOR_REQUEST_OUT,
417 offset, &key_entry,
418 sizeof(key_entry),
419 timeout);
420 }
421
422 /*
423 * The cipher types are stored over multiple registers
424 * starting with SHARED_KEY_MODE_BASE each word will have
425 * 32 bits and contains the cipher types for 2 bssidx each.
426 * Using the correct defines correctly will cause overhead,
427 * so just calculate the correct offset.
428 */
429 field.bit_offset = 4 * (key->hw_key_idx % 8);
430 field.bit_mask = 0x7 << field.bit_offset;
431
432 offset = SHARED_KEY_MODE_ENTRY(key->hw_key_idx / 8);
433
434 rt2x00usb_register_read(rt2x00dev, offset, &reg);
435 rt2x00_set_field32(&reg, field,
436 (crypto->cmd == SET_KEY) * crypto->cipher);
437 rt2x00usb_register_write(rt2x00dev, offset, reg);
438
439 /*
440 * Update WCID information
441 */
442 rt2800usb_config_wcid_attr(rt2x00dev, crypto, key);
443
444 return 0;
445}
446
447static int rt2800usb_config_pairwise_key(struct rt2x00_dev *rt2x00dev,
448 struct rt2x00lib_crypto *crypto,
449 struct ieee80211_key_conf *key)
450{
451 struct hw_key_entry key_entry;
452 int timeout;
453 u32 offset;
454
455 if (crypto->cmd == SET_KEY) {
456 /*
457 * 1 pairwise key is possible per AID, this means that the AID
458 * equals our hw_key_idx. Make sure the WCID starts _after_ the
459 * last possible shared key entry.
460 */
461 if (crypto->aid > (256 - 32))
462 return -ENOSPC;
463
464 key->hw_key_idx = 32 + crypto->aid;
465
466 memcpy(key_entry.key, crypto->key,
467 sizeof(key_entry.key));
468 memcpy(key_entry.tx_mic, crypto->tx_mic,
469 sizeof(key_entry.tx_mic));
470 memcpy(key_entry.rx_mic, crypto->rx_mic,
471 sizeof(key_entry.rx_mic));
472
473 offset = PAIRWISE_KEY_ENTRY(key->hw_key_idx);
474 timeout = REGISTER_TIMEOUT32(sizeof(key_entry));
475 rt2x00usb_vendor_request_large_buff(rt2x00dev, USB_MULTI_WRITE,
476 USB_VENDOR_REQUEST_OUT,
477 offset, &key_entry,
478 sizeof(key_entry),
479 timeout);
480 }
481
482 /*
483 * Update WCID information
484 */
485 rt2800usb_config_wcid_attr(rt2x00dev, crypto, key);
486
487 return 0;
488}
489
490static void rt2800usb_config_filter(struct rt2x00_dev *rt2x00dev,
491 const unsigned int filter_flags)
492{
493 u32 reg;
494
495 /*
496 * Start configuration steps.
497 * Note that the version error will always be dropped
498 * and broadcast frames will always be accepted since
499 * there is no filter for it at this time.
500 */
501 rt2x00usb_register_read(rt2x00dev, RX_FILTER_CFG, &reg);
502 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CRC_ERROR,
503 !(filter_flags & FIF_FCSFAIL));
504 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_PHY_ERROR,
505 !(filter_flags & FIF_PLCPFAIL));
506 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_NOT_TO_ME,
507 !(filter_flags & FIF_PROMISC_IN_BSS));
508 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_NOT_MY_BSSD, 0);
509 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_VER_ERROR, 1);
510 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_MULTICAST,
511 !(filter_flags & FIF_ALLMULTI));
512 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_BROADCAST, 0);
513 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_DUPLICATE, 1);
514 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CF_END_ACK,
515 !(filter_flags & FIF_CONTROL));
516 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CF_END,
517 !(filter_flags & FIF_CONTROL));
518 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_ACK,
519 !(filter_flags & FIF_CONTROL));
520 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CTS,
521 !(filter_flags & FIF_CONTROL));
522 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_RTS,
523 !(filter_flags & FIF_CONTROL));
524 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_PSPOLL,
525 !(filter_flags & FIF_CONTROL));
526 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_BA, 1);
527 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_BAR, 0);
528 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CNTL,
529 !(filter_flags & FIF_CONTROL));
530 rt2x00usb_register_write(rt2x00dev, RX_FILTER_CFG, reg);
531}
532
533static void rt2800usb_config_intf(struct rt2x00_dev *rt2x00dev,
534 struct rt2x00_intf *intf,
535 struct rt2x00intf_conf *conf,
536 const unsigned int flags)
537{
538 unsigned int beacon_base;
539 u32 reg;
540
541 if (flags & CONFIG_UPDATE_TYPE) {
542 /*
543 * Clear current synchronisation setup.
544 * For the Beacon base registers we only need to clear
545 * the first byte since that byte contains the VALID and OWNER
546 * bits which (when set to 0) will invalidate the entire beacon.
547 */
548 beacon_base = HW_BEACON_OFFSET(intf->beacon->entry_idx);
549 rt2x00usb_register_write(rt2x00dev, beacon_base, 0);
550
551 /*
552 * Enable synchronisation.
553 */
554 rt2x00usb_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
555 rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 1);
556 rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_SYNC, conf->sync);
557 rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 1);
558 rt2x00usb_register_write(rt2x00dev, BCN_TIME_CFG, reg);
559 }
560
561 if (flags & CONFIG_UPDATE_MAC) {
562 reg = le32_to_cpu(conf->mac[1]);
563 rt2x00_set_field32(&reg, MAC_ADDR_DW1_UNICAST_TO_ME_MASK, 0xff);
564 conf->mac[1] = cpu_to_le32(reg);
565
566 rt2x00usb_register_multiwrite(rt2x00dev, MAC_ADDR_DW0,
567 conf->mac, sizeof(conf->mac));
568 }
569
570 if (flags & CONFIG_UPDATE_BSSID) {
571 reg = le32_to_cpu(conf->bssid[1]);
572 rt2x00_set_field32(&reg, MAC_BSSID_DW1_BSS_ID_MASK, 0);
573 rt2x00_set_field32(&reg, MAC_BSSID_DW1_BSS_BCN_NUM, 0);
574 conf->bssid[1] = cpu_to_le32(reg);
575
576 rt2x00usb_register_multiwrite(rt2x00dev, MAC_BSSID_DW0,
577 conf->bssid, sizeof(conf->bssid));
578 }
579}
580
581static void rt2800usb_config_erp(struct rt2x00_dev *rt2x00dev,
582 struct rt2x00lib_erp *erp)
583{
584 u32 reg;
585
586 rt2x00usb_register_read(rt2x00dev, TX_TIMEOUT_CFG, &reg);
587 rt2x00_set_field32(&reg, TX_TIMEOUT_CFG_RX_ACK_TIMEOUT,
588 DIV_ROUND_UP(erp->ack_timeout, erp->slot_time));
589 rt2x00usb_register_write(rt2x00dev, TX_TIMEOUT_CFG, reg);
590
591 rt2x00usb_register_read(rt2x00dev, AUTO_RSP_CFG, &reg);
592 rt2x00_set_field32(&reg, AUTO_RSP_CFG_BAC_ACK_POLICY,
593 !!erp->short_preamble);
594 rt2x00_set_field32(&reg, AUTO_RSP_CFG_AR_PREAMBLE,
595 !!erp->short_preamble);
596 rt2x00usb_register_write(rt2x00dev, AUTO_RSP_CFG, reg);
597
598 rt2x00usb_register_read(rt2x00dev, OFDM_PROT_CFG, &reg);
599 rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_CTRL,
600 erp->cts_protection ? 2 : 0);
601 rt2x00usb_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
602
603 rt2x00usb_register_write(rt2x00dev, LEGACY_BASIC_RATE,
604 erp->basic_rates);
605 rt2x00usb_register_write(rt2x00dev, HT_BASIC_RATE, 0x00008003);
606
607 rt2x00usb_register_read(rt2x00dev, BKOFF_SLOT_CFG, &reg);
608 rt2x00_set_field32(&reg, BKOFF_SLOT_CFG_SLOT_TIME, erp->slot_time);
609 rt2x00_set_field32(&reg, BKOFF_SLOT_CFG_CC_DELAY_TIME, 2);
610 rt2x00usb_register_write(rt2x00dev, BKOFF_SLOT_CFG, reg);
611
612 rt2x00usb_register_read(rt2x00dev, XIFS_TIME_CFG, &reg);
613 rt2x00_set_field32(&reg, XIFS_TIME_CFG_CCKM_SIFS_TIME, erp->sifs);
614 rt2x00_set_field32(&reg, XIFS_TIME_CFG_OFDM_SIFS_TIME, erp->sifs);
615 rt2x00_set_field32(&reg, XIFS_TIME_CFG_OFDM_XIFS_TIME, 4);
616 rt2x00_set_field32(&reg, XIFS_TIME_CFG_EIFS, erp->eifs);
617 rt2x00_set_field32(&reg, XIFS_TIME_CFG_BB_RXEND_ENABLE, 1);
618 rt2x00usb_register_write(rt2x00dev, XIFS_TIME_CFG, reg);
619}
620
621static void rt2800usb_config_ant(struct rt2x00_dev *rt2x00dev,
622 struct antenna_setup *ant)
623{
624 u8 r1;
625 u8 r3;
626
627 rt2800usb_bbp_read(rt2x00dev, 1, &r1);
628 rt2800usb_bbp_read(rt2x00dev, 3, &r3);
629
630 /*
631 * Configure the TX antenna.
632 */
633 switch ((int)ant->tx) {
634 case 1:
635 rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 0);
636 break;
637 case 2:
638 rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 2);
639 break;
640 case 3:
641 /* Do nothing */
642 break;
643 }
644
645 /*
646 * Configure the RX antenna.
647 */
648 switch ((int)ant->rx) {
649 case 1:
650 rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 0);
651 break;
652 case 2:
653 rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 1);
654 break;
655 case 3:
656 rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 2);
657 break;
658 }
659
660 rt2800usb_bbp_write(rt2x00dev, 3, r3);
661 rt2800usb_bbp_write(rt2x00dev, 1, r1);
662}
663
664static void rt2800usb_config_lna_gain(struct rt2x00_dev *rt2x00dev,
665 struct rt2x00lib_conf *libconf)
666{
667 u16 eeprom;
668 short lna_gain;
669
670 if (libconf->rf.channel <= 14) {
671 rt2x00_eeprom_read(rt2x00dev, EEPROM_LNA, &eeprom);
672 lna_gain = rt2x00_get_field16(eeprom, EEPROM_LNA_BG);
673 } else if (libconf->rf.channel <= 64) {
674 rt2x00_eeprom_read(rt2x00dev, EEPROM_LNA, &eeprom);
675 lna_gain = rt2x00_get_field16(eeprom, EEPROM_LNA_A0);
676 } else if (libconf->rf.channel <= 128) {
677 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &eeprom);
678 lna_gain = rt2x00_get_field16(eeprom, EEPROM_RSSI_BG2_LNA_A1);
679 } else {
680 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &eeprom);
681 lna_gain = rt2x00_get_field16(eeprom, EEPROM_RSSI_A2_LNA_A2);
682 }
683
684 rt2x00dev->lna_gain = lna_gain;
685}
686
687static void rt2800usb_config_channel_rt2x(struct rt2x00_dev *rt2x00dev,
688 struct ieee80211_conf *conf,
689 struct rf_channel *rf,
690 struct channel_info *info)
691{
692 rt2x00_set_field32(&rf->rf4, RF4_FREQ_OFFSET, rt2x00dev->freq_offset);
693
694 if (rt2x00dev->default_ant.tx == 1)
695 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_TX1, 1);
696
697 if (rt2x00dev->default_ant.rx == 1) {
698 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX1, 1);
699 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1);
700 } else if (rt2x00dev->default_ant.rx == 2)
701 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1);
702
703 if (rf->channel > 14) {
704 /*
705 * When TX power is below 0, we should increase it by 7 to
706 * make it a positive value (Minumum value is -7).
707 * However this means that values between 0 and 7 have
708 * double meaning, and we should set a 7DBm boost flag.
709 */
710 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_A_7DBM_BOOST,
711 (info->tx_power1 >= 0));
712
713 if (info->tx_power1 < 0)
714 info->tx_power1 += 7;
715
716 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_A,
717 TXPOWER_A_TO_DEV(info->tx_power1));
718
719 rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_A_7DBM_BOOST,
720 (info->tx_power2 >= 0));
721
722 if (info->tx_power2 < 0)
723 info->tx_power2 += 7;
724
725 rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_A,
726 TXPOWER_A_TO_DEV(info->tx_power2));
727 } else {
728 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_G,
729 TXPOWER_G_TO_DEV(info->tx_power1));
730 rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_G,
731 TXPOWER_G_TO_DEV(info->tx_power2));
732 }
733
734 rt2x00_set_field32(&rf->rf4, RF4_HT40, conf_is_ht40(conf));
735
736 rt2800usb_rf_write(rt2x00dev, 1, rf->rf1);
737 rt2800usb_rf_write(rt2x00dev, 2, rf->rf2);
738 rt2800usb_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
739 rt2800usb_rf_write(rt2x00dev, 4, rf->rf4);
740
741 udelay(200);
742
743 rt2800usb_rf_write(rt2x00dev, 1, rf->rf1);
744 rt2800usb_rf_write(rt2x00dev, 2, rf->rf2);
745 rt2800usb_rf_write(rt2x00dev, 3, rf->rf3 | 0x00000004);
746 rt2800usb_rf_write(rt2x00dev, 4, rf->rf4);
747
748 udelay(200);
749
750 rt2800usb_rf_write(rt2x00dev, 1, rf->rf1);
751 rt2800usb_rf_write(rt2x00dev, 2, rf->rf2);
752 rt2800usb_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
753 rt2800usb_rf_write(rt2x00dev, 4, rf->rf4);
754}
755
756static void rt2800usb_config_channel_rt3x(struct rt2x00_dev *rt2x00dev,
757 struct ieee80211_conf *conf,
758 struct rf_channel *rf,
759 struct channel_info *info)
760{
761 u8 rfcsr;
762
763 rt2800usb_rfcsr_write(rt2x00dev, 2, rf->rf1);
764 rt2800usb_rfcsr_write(rt2x00dev, 2, rf->rf3);
765
766 rt2800usb_rfcsr_read(rt2x00dev, 6, &rfcsr);
767 rt2x00_set_field8(&rfcsr, RFCSR6_R, rf->rf2);
768 rt2800usb_rfcsr_write(rt2x00dev, 6, rfcsr);
769
770 rt2800usb_rfcsr_read(rt2x00dev, 12, &rfcsr);
771 rt2x00_set_field8(&rfcsr, RFCSR12_TX_POWER,
772 TXPOWER_G_TO_DEV(info->tx_power1));
773 rt2800usb_rfcsr_write(rt2x00dev, 12, rfcsr);
774
775 rt2800usb_rfcsr_read(rt2x00dev, 23, &rfcsr);
776 rt2x00_set_field8(&rfcsr, RFCSR23_FREQ_OFFSET, rt2x00dev->freq_offset);
777 rt2800usb_rfcsr_write(rt2x00dev, 23, rfcsr);
778
779 rt2800usb_rfcsr_write(rt2x00dev, 24,
780 rt2x00dev->calibration[conf_is_ht40(conf)]);
781
782 rt2800usb_rfcsr_read(rt2x00dev, 23, &rfcsr);
783 rt2x00_set_field8(&rfcsr, RFCSR7_RF_TUNING, 1);
784 rt2800usb_rfcsr_write(rt2x00dev, 23, rfcsr);
785}
786
787static void rt2800usb_config_channel(struct rt2x00_dev *rt2x00dev,
788 struct ieee80211_conf *conf,
789 struct rf_channel *rf,
790 struct channel_info *info)
791{
792 u32 reg;
793 unsigned int tx_pin;
794 u8 bbp;
795
796 if (rt2x00_rev(&rt2x00dev->chip) != RT3070_VERSION)
797 rt2800usb_config_channel_rt2x(rt2x00dev, conf, rf, info);
798 else
799 rt2800usb_config_channel_rt3x(rt2x00dev, conf, rf, info);
800
801 /*
802 * Change BBP settings
803 */
804 rt2800usb_bbp_write(rt2x00dev, 62, 0x37 - rt2x00dev->lna_gain);
805 rt2800usb_bbp_write(rt2x00dev, 63, 0x37 - rt2x00dev->lna_gain);
806 rt2800usb_bbp_write(rt2x00dev, 64, 0x37 - rt2x00dev->lna_gain);
807 rt2800usb_bbp_write(rt2x00dev, 86, 0);
808
809 if (rf->channel <= 14) {
810 if (test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags)) {
811 rt2800usb_bbp_write(rt2x00dev, 82, 0x62);
812 rt2800usb_bbp_write(rt2x00dev, 75, 0x46);
813 } else {
814 rt2800usb_bbp_write(rt2x00dev, 82, 0x84);
815 rt2800usb_bbp_write(rt2x00dev, 75, 0x50);
816 }
817 } else {
818 rt2800usb_bbp_write(rt2x00dev, 82, 0xf2);
819
820 if (test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags))
821 rt2800usb_bbp_write(rt2x00dev, 75, 0x46);
822 else
823 rt2800usb_bbp_write(rt2x00dev, 75, 0x50);
824 }
825
826 rt2x00usb_register_read(rt2x00dev, TX_BAND_CFG, &reg);
827 rt2x00_set_field32(&reg, TX_BAND_CFG_HT40_PLUS, conf_is_ht40_plus(conf));
828 rt2x00_set_field32(&reg, TX_BAND_CFG_A, rf->channel > 14);
829 rt2x00_set_field32(&reg, TX_BAND_CFG_BG, rf->channel <= 14);
830 rt2x00usb_register_write(rt2x00dev, TX_BAND_CFG, reg);
831
832 tx_pin = 0;
833
834 /* Turn on unused PA or LNA when not using 1T or 1R */
835 if (rt2x00dev->default_ant.tx != 1) {
836 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A1_EN, 1);
837 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G1_EN, 1);
838 }
839
840 /* Turn on unused PA or LNA when not using 1T or 1R */
841 if (rt2x00dev->default_ant.rx != 1) {
842 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A1_EN, 1);
843 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G1_EN, 1);
844 }
845
846 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A0_EN, 1);
847 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G0_EN, 1);
848 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_RFTR_EN, 1);
849 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_TRSW_EN, 1);
850 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G0_EN, rf->channel <= 14);
851 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A0_EN, rf->channel > 14);
852
853 rt2x00usb_register_write(rt2x00dev, TX_PIN_CFG, tx_pin);
854
855 rt2800usb_bbp_read(rt2x00dev, 4, &bbp);
856 rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 2 * conf_is_ht40(conf));
857 rt2800usb_bbp_write(rt2x00dev, 4, bbp);
858
859 rt2800usb_bbp_read(rt2x00dev, 3, &bbp);
860 rt2x00_set_field8(&bbp, BBP3_HT40_PLUS, conf_is_ht40_plus(conf));
861 rt2800usb_bbp_write(rt2x00dev, 3, bbp);
862
863 if (rt2x00_rev(&rt2x00dev->chip) == RT2860C_VERSION) {
864 if (conf_is_ht40(conf)) {
865 rt2800usb_bbp_write(rt2x00dev, 69, 0x1a);
866 rt2800usb_bbp_write(rt2x00dev, 70, 0x0a);
867 rt2800usb_bbp_write(rt2x00dev, 73, 0x16);
868 } else {
869 rt2800usb_bbp_write(rt2x00dev, 69, 0x16);
870 rt2800usb_bbp_write(rt2x00dev, 70, 0x08);
871 rt2800usb_bbp_write(rt2x00dev, 73, 0x11);
872 }
873 }
874
875 msleep(1);
876}
877
878static void rt2800usb_config_txpower(struct rt2x00_dev *rt2x00dev,
879 const int txpower)
880{
881 u32 reg;
882 u32 value = TXPOWER_G_TO_DEV(txpower);
883 u8 r1;
884
885 rt2800usb_bbp_read(rt2x00dev, 1, &r1);
886 rt2x00_set_field8(&reg, BBP1_TX_POWER, 0);
887 rt2800usb_bbp_write(rt2x00dev, 1, r1);
888
889 rt2x00usb_register_read(rt2x00dev, TX_PWR_CFG_0, &reg);
890 rt2x00_set_field32(&reg, TX_PWR_CFG_0_1MBS, value);
891 rt2x00_set_field32(&reg, TX_PWR_CFG_0_2MBS, value);
892 rt2x00_set_field32(&reg, TX_PWR_CFG_0_55MBS, value);
893 rt2x00_set_field32(&reg, TX_PWR_CFG_0_11MBS, value);
894 rt2x00_set_field32(&reg, TX_PWR_CFG_0_6MBS, value);
895 rt2x00_set_field32(&reg, TX_PWR_CFG_0_9MBS, value);
896 rt2x00_set_field32(&reg, TX_PWR_CFG_0_12MBS, value);
897 rt2x00_set_field32(&reg, TX_PWR_CFG_0_18MBS, value);
898 rt2x00usb_register_write(rt2x00dev, TX_PWR_CFG_0, reg);
899
900 rt2x00usb_register_read(rt2x00dev, TX_PWR_CFG_1, &reg);
901 rt2x00_set_field32(&reg, TX_PWR_CFG_1_24MBS, value);
902 rt2x00_set_field32(&reg, TX_PWR_CFG_1_36MBS, value);
903 rt2x00_set_field32(&reg, TX_PWR_CFG_1_48MBS, value);
904 rt2x00_set_field32(&reg, TX_PWR_CFG_1_54MBS, value);
905 rt2x00_set_field32(&reg, TX_PWR_CFG_1_MCS0, value);
906 rt2x00_set_field32(&reg, TX_PWR_CFG_1_MCS1, value);
907 rt2x00_set_field32(&reg, TX_PWR_CFG_1_MCS2, value);
908 rt2x00_set_field32(&reg, TX_PWR_CFG_1_MCS3, value);
909 rt2x00usb_register_write(rt2x00dev, TX_PWR_CFG_1, reg);
910
911 rt2x00usb_register_read(rt2x00dev, TX_PWR_CFG_2, &reg);
912 rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS4, value);
913 rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS5, value);
914 rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS6, value);
915 rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS7, value);
916 rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS8, value);
917 rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS9, value);
918 rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS10, value);
919 rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS11, value);
920 rt2x00usb_register_write(rt2x00dev, TX_PWR_CFG_2, reg);
921
922 rt2x00usb_register_read(rt2x00dev, TX_PWR_CFG_3, &reg);
923 rt2x00_set_field32(&reg, TX_PWR_CFG_3_MCS12, value);
924 rt2x00_set_field32(&reg, TX_PWR_CFG_3_MCS13, value);
925 rt2x00_set_field32(&reg, TX_PWR_CFG_3_MCS14, value);
926 rt2x00_set_field32(&reg, TX_PWR_CFG_3_MCS15, value);
927 rt2x00_set_field32(&reg, TX_PWR_CFG_3_UKNOWN1, value);
928 rt2x00_set_field32(&reg, TX_PWR_CFG_3_UKNOWN2, value);
929 rt2x00_set_field32(&reg, TX_PWR_CFG_3_UKNOWN3, value);
930 rt2x00_set_field32(&reg, TX_PWR_CFG_3_UKNOWN4, value);
931 rt2x00usb_register_write(rt2x00dev, TX_PWR_CFG_3, reg);
932
933 rt2x00usb_register_read(rt2x00dev, TX_PWR_CFG_4, &reg);
934 rt2x00_set_field32(&reg, TX_PWR_CFG_4_UKNOWN5, value);
935 rt2x00_set_field32(&reg, TX_PWR_CFG_4_UKNOWN6, value);
936 rt2x00_set_field32(&reg, TX_PWR_CFG_4_UKNOWN7, value);
937 rt2x00_set_field32(&reg, TX_PWR_CFG_4_UKNOWN8, value);
938 rt2x00usb_register_write(rt2x00dev, TX_PWR_CFG_4, reg);
939}
940
941static void rt2800usb_config_retry_limit(struct rt2x00_dev *rt2x00dev,
942 struct rt2x00lib_conf *libconf)
943{
944 u32 reg;
945
946 rt2x00usb_register_read(rt2x00dev, TX_RTY_CFG, &reg);
947 rt2x00_set_field32(&reg, TX_RTY_CFG_SHORT_RTY_LIMIT,
948 libconf->conf->short_frame_max_tx_count);
949 rt2x00_set_field32(&reg, TX_RTY_CFG_LONG_RTY_LIMIT,
950 libconf->conf->long_frame_max_tx_count);
951 rt2x00_set_field32(&reg, TX_RTY_CFG_LONG_RTY_THRE, 2000);
952 rt2x00_set_field32(&reg, TX_RTY_CFG_NON_AGG_RTY_MODE, 0);
953 rt2x00_set_field32(&reg, TX_RTY_CFG_AGG_RTY_MODE, 0);
954 rt2x00_set_field32(&reg, TX_RTY_CFG_TX_AUTO_FB_ENABLE, 1);
955 rt2x00usb_register_write(rt2x00dev, TX_RTY_CFG, reg);
956}
957
958static void rt2800usb_config_duration(struct rt2x00_dev *rt2x00dev,
959 struct rt2x00lib_conf *libconf)
960{
961 u32 reg;
962
963 rt2x00usb_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
964 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_INTERVAL,
965 libconf->conf->beacon_int * 16);
966 rt2x00usb_register_write(rt2x00dev, BCN_TIME_CFG, reg);
967}
968
969static void rt2800usb_config_ps(struct rt2x00_dev *rt2x00dev,
970 struct rt2x00lib_conf *libconf)
971{
972 enum dev_state state =
973 (libconf->conf->flags & IEEE80211_CONF_PS) ?
974 STATE_SLEEP : STATE_AWAKE;
975 u32 reg;
976
977 if (state == STATE_SLEEP) {
978 rt2x00usb_register_write(rt2x00dev, AUTOWAKEUP_CFG, 0);
979
980 rt2x00usb_register_read(rt2x00dev, AUTOWAKEUP_CFG, &reg);
981 rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTO_LEAD_TIME, 5);
982 rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_TBCN_BEFORE_WAKE,
983 libconf->conf->listen_interval - 1);
984 rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTOWAKE, 1);
985 rt2x00usb_register_write(rt2x00dev, AUTOWAKEUP_CFG, reg);
986
987 rt2x00dev->ops->lib->set_device_state(rt2x00dev, state);
988 } else {
989 rt2x00dev->ops->lib->set_device_state(rt2x00dev, state);
990
991 rt2x00usb_register_read(rt2x00dev, AUTOWAKEUP_CFG, &reg);
992 rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTO_LEAD_TIME, 0);
993 rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_TBCN_BEFORE_WAKE, 0);
994 rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTOWAKE, 0);
995 rt2x00usb_register_write(rt2x00dev, AUTOWAKEUP_CFG, reg);
996 }
997}
998
999static void rt2800usb_config(struct rt2x00_dev *rt2x00dev,
1000 struct rt2x00lib_conf *libconf,
1001 const unsigned int flags)
1002{
1003 /* Always recalculate LNA gain before changing configuration */
1004 rt2800usb_config_lna_gain(rt2x00dev, libconf);
1005
1006 if (flags & IEEE80211_CONF_CHANGE_CHANNEL)
1007 rt2800usb_config_channel(rt2x00dev, libconf->conf,
1008 &libconf->rf, &libconf->channel);
1009 if (flags & IEEE80211_CONF_CHANGE_POWER)
1010 rt2800usb_config_txpower(rt2x00dev, libconf->conf->power_level);
1011 if (flags & IEEE80211_CONF_CHANGE_RETRY_LIMITS)
1012 rt2800usb_config_retry_limit(rt2x00dev, libconf);
1013 if (flags & IEEE80211_CONF_CHANGE_BEACON_INTERVAL)
1014 rt2800usb_config_duration(rt2x00dev, libconf);
1015 if (flags & IEEE80211_CONF_CHANGE_PS)
1016 rt2800usb_config_ps(rt2x00dev, libconf);
1017}
1018
1019/*
1020 * Link tuning
1021 */
1022static void rt2800usb_link_stats(struct rt2x00_dev *rt2x00dev,
1023 struct link_qual *qual)
1024{
1025 u32 reg;
1026
1027 /*
1028 * Update FCS error count from register.
1029 */
1030 rt2x00usb_register_read(rt2x00dev, RX_STA_CNT0, &reg);
1031 qual->rx_failed = rt2x00_get_field32(reg, RX_STA_CNT0_CRC_ERR);
1032}
1033
1034static u8 rt2800usb_get_default_vgc(struct rt2x00_dev *rt2x00dev)
1035{
1036 if (rt2x00dev->curr_band == IEEE80211_BAND_2GHZ) {
1037 if (rt2x00_rev(&rt2x00dev->chip) == RT3070_VERSION)
1038 return 0x1c + (2 * rt2x00dev->lna_gain);
1039 else
1040 return 0x2e + rt2x00dev->lna_gain;
1041 }
1042
1043 if (!test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags))
1044 return 0x32 + (rt2x00dev->lna_gain * 5) / 3;
1045 else
1046 return 0x3a + (rt2x00dev->lna_gain * 5) / 3;
1047}
1048
1049static inline void rt2800usb_set_vgc(struct rt2x00_dev *rt2x00dev,
1050 struct link_qual *qual, u8 vgc_level)
1051{
1052 if (qual->vgc_level != vgc_level) {
1053 rt2800usb_bbp_write(rt2x00dev, 66, vgc_level);
1054 qual->vgc_level = vgc_level;
1055 qual->vgc_level_reg = vgc_level;
1056 }
1057}
1058
1059static void rt2800usb_reset_tuner(struct rt2x00_dev *rt2x00dev,
1060 struct link_qual *qual)
1061{
1062 rt2800usb_set_vgc(rt2x00dev, qual,
1063 rt2800usb_get_default_vgc(rt2x00dev));
1064}
1065
1066static void rt2800usb_link_tuner(struct rt2x00_dev *rt2x00dev,
1067 struct link_qual *qual, const u32 count)
1068{
1069 if (rt2x00_rev(&rt2x00dev->chip) == RT2860C_VERSION)
1070 return;
1071
1072 /*
1073 * When RSSI is better then -80 increase VGC level with 0x10
1074 */
1075 rt2800usb_set_vgc(rt2x00dev, qual,
1076 rt2800usb_get_default_vgc(rt2x00dev) +
1077 ((qual->rssi > -80) * 0x10));
1078}
1079
1080/*
1081 * Firmware functions
1082 */
1083static char *rt2800usb_get_firmware_name(struct rt2x00_dev *rt2x00dev)
1084{
1085 return FIRMWARE_RT2870;
1086}
1087
1088static bool rt2800usb_check_crc(const u8 *data, const size_t len)
1089{
1090 u16 fw_crc;
1091 u16 crc;
1092
1093 /*
1094 * The last 2 bytes in the firmware array are the crc checksum itself,
1095 * this means that we should never pass those 2 bytes to the crc
1096 * algorithm.
1097 */
1098 fw_crc = (data[len - 2] << 8 | data[len - 1]);
1099
1100 /*
1101 * Use the crc ccitt algorithm.
1102 * This will return the same value as the legacy driver which
1103 * used bit ordering reversion on the both the firmware bytes
1104 * before input input as well as on the final output.
1105 * Obviously using crc ccitt directly is much more efficient.
1106 */
1107 crc = crc_ccitt(~0, data, len - 2);
1108
1109 /*
1110 * There is a small difference between the crc-itu-t + bitrev and
1111 * the crc-ccitt crc calculation. In the latter method the 2 bytes
1112 * will be swapped, use swab16 to convert the crc to the correct
1113 * value.
1114 */
1115 crc = swab16(crc);
1116
1117 return fw_crc == crc;
1118}
1119
1120static int rt2800usb_check_firmware(struct rt2x00_dev *rt2x00dev,
1121 const u8 *data, const size_t len)
1122{
1123 u16 chipset = (rt2x00_rev(&rt2x00dev->chip) >> 16) & 0xffff;
1124 size_t offset = 0;
1125
1126 /*
1127 * Firmware files:
1128 * There are 2 variations of the rt2870 firmware.
1129 * a) size: 4kb
1130 * b) size: 8kb
1131 * Note that (b) contains 2 seperate firmware blobs of 4k
1132 * within the file. The first blob is the same firmware as (a),
1133 * but the second blob is for the additional chipsets.
1134 */
1135 if (len != 4096 && len != 8192)
1136 return FW_BAD_LENGTH;
1137
1138 /*
1139 * Check if we need the upper 4kb firmware data or not.
1140 */
1141 if ((len == 4096) &&
1142 (chipset != 0x2860) &&
1143 (chipset != 0x2872) &&
1144 (chipset != 0x3070))
1145 return FW_BAD_VERSION;
1146
1147 /*
1148 * 8kb firmware files must be checked as if it were
1149 * 2 seperate firmware files.
1150 */
1151 while (offset < len) {
1152 if (!rt2800usb_check_crc(data + offset, 4096))
1153 return FW_BAD_CRC;
1154
1155 offset += 4096;
1156 }
1157
1158 return FW_OK;
1159}
1160
1161static int rt2800usb_load_firmware(struct rt2x00_dev *rt2x00dev,
1162 const u8 *data, const size_t len)
1163{
1164 unsigned int i;
1165 int status;
1166 u32 reg;
1167 u32 offset;
1168 u32 length;
1169 u16 chipset = (rt2x00_rev(&rt2x00dev->chip) >> 16) & 0xffff;
1170
1171 /*
1172 * Check which section of the firmware we need.
1173 */
1174 if ((chipset == 0x2860) ||
1175 (chipset == 0x2872) ||
1176 (chipset == 0x3070)) {
1177 offset = 0;
1178 length = 4096;
1179 } else {
1180 offset = 4096;
1181 length = 4096;
1182 }
1183
1184 /*
1185 * Wait for stable hardware.
1186 */
1187 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
1188 rt2x00usb_register_read(rt2x00dev, MAC_CSR0, &reg);
1189 if (reg && reg != ~0)
1190 break;
1191 msleep(1);
1192 }
1193
1194 if (i == REGISTER_BUSY_COUNT) {
1195 ERROR(rt2x00dev, "Unstable hardware.\n");
1196 return -EBUSY;
1197 }
1198
1199 /*
1200 * Write firmware to device.
1201 */
1202 rt2x00usb_vendor_request_large_buff(rt2x00dev, USB_MULTI_WRITE,
1203 USB_VENDOR_REQUEST_OUT,
1204 FIRMWARE_IMAGE_BASE,
1205 data + offset, length,
1206 REGISTER_TIMEOUT32(length));
1207
1208 rt2x00usb_register_write(rt2x00dev, H2M_MAILBOX_CID, ~0);
1209 rt2x00usb_register_write(rt2x00dev, H2M_MAILBOX_STATUS, ~0);
1210
1211 /*
1212 * Send firmware request to device to load firmware,
1213 * we need to specify a long timeout time.
1214 */
1215 status = rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE,
1216 0, USB_MODE_FIRMWARE,
1217 REGISTER_TIMEOUT_FIRMWARE);
1218 if (status < 0) {
1219 ERROR(rt2x00dev, "Failed to write Firmware to device.\n");
1220 return status;
1221 }
1222
1223 msleep(10);
1224 rt2x00usb_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
1225
1226 /*
1227 * Send signal to firmware during boot time.
1228 */
1229 rt2800usb_mcu_request(rt2x00dev, MCU_BOOT_SIGNAL, 0xff, 0, 0);
1230
1231 if ((chipset == 0x3070) ||
1232 (chipset == 0x3071) ||
1233 (chipset == 0x3572)) {
1234 udelay(200);
1235 rt2800usb_mcu_request(rt2x00dev, MCU_CURRENT, 0, 0, 0);
1236 udelay(10);
1237 }
1238
1239 /*
1240 * Wait for device to stabilize.
1241 */
1242 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
1243 rt2x00usb_register_read(rt2x00dev, PBF_SYS_CTRL, &reg);
1244 if (rt2x00_get_field32(reg, PBF_SYS_CTRL_READY))
1245 break;
1246 msleep(1);
1247 }
1248
1249 if (i == REGISTER_BUSY_COUNT) {
1250 ERROR(rt2x00dev, "PBF system register not ready.\n");
1251 return -EBUSY;
1252 }
1253
1254 /*
1255 * Initialize firmware.
1256 */
1257 rt2x00usb_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
1258 rt2x00usb_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
1259 msleep(1);
1260
1261 return 0;
1262}
1263
1264/*
1265 * Initialization functions.
1266 */
1267static int rt2800usb_init_registers(struct rt2x00_dev *rt2x00dev)
1268{
1269 u32 reg;
1270 unsigned int i;
1271
1272 /*
1273 * Wait untill BBP and RF are ready.
1274 */
1275 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
1276 rt2x00usb_register_read(rt2x00dev, MAC_CSR0, &reg);
1277 if (reg && reg != ~0)
1278 break;
1279 msleep(1);
1280 }
1281
1282 if (i == REGISTER_BUSY_COUNT) {
1283 ERROR(rt2x00dev, "Unstable hardware.\n");
1284 return -EBUSY;
1285 }
1286
1287 rt2x00usb_register_read(rt2x00dev, PBF_SYS_CTRL, &reg);
1288 rt2x00usb_register_write(rt2x00dev, PBF_SYS_CTRL, reg & ~0x00002000);
1289
1290 rt2x00usb_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
1291 rt2x00_set_field32(&reg, MAC_SYS_CTRL_RESET_CSR, 1);
1292 rt2x00_set_field32(&reg, MAC_SYS_CTRL_RESET_BBP, 1);
1293 rt2x00usb_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
1294
1295 rt2x00usb_register_write(rt2x00dev, USB_DMA_CFG, 0x00000000);
1296
1297 rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE, 0,
1298 USB_MODE_RESET, REGISTER_TIMEOUT);
1299
1300 rt2x00usb_register_write(rt2x00dev, MAC_SYS_CTRL, 0x00000000);
1301
1302 rt2x00usb_register_read(rt2x00dev, BCN_OFFSET0, &reg);
1303 rt2x00_set_field32(&reg, BCN_OFFSET0_BCN0, 0xe0); /* 0x3800 */
1304 rt2x00_set_field32(&reg, BCN_OFFSET0_BCN1, 0xe8); /* 0x3a00 */
1305 rt2x00_set_field32(&reg, BCN_OFFSET0_BCN2, 0xf0); /* 0x3c00 */
1306 rt2x00_set_field32(&reg, BCN_OFFSET0_BCN3, 0xf8); /* 0x3e00 */
1307 rt2x00usb_register_write(rt2x00dev, BCN_OFFSET0, reg);
1308
1309 rt2x00usb_register_read(rt2x00dev, BCN_OFFSET1, &reg);
1310 rt2x00_set_field32(&reg, BCN_OFFSET1_BCN4, 0xc8); /* 0x3200 */
1311 rt2x00_set_field32(&reg, BCN_OFFSET1_BCN5, 0xd0); /* 0x3400 */
1312 rt2x00_set_field32(&reg, BCN_OFFSET1_BCN6, 0x77); /* 0x1dc0 */
1313 rt2x00_set_field32(&reg, BCN_OFFSET1_BCN7, 0x6f); /* 0x1bc0 */
1314 rt2x00usb_register_write(rt2x00dev, BCN_OFFSET1, reg);
1315
1316 rt2x00usb_register_write(rt2x00dev, LEGACY_BASIC_RATE, 0x0000013f);
1317 rt2x00usb_register_write(rt2x00dev, HT_BASIC_RATE, 0x00008003);
1318
1319 rt2x00usb_register_write(rt2x00dev, MAC_SYS_CTRL, 0x00000000);
1320
1321 rt2x00usb_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
1322 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_INTERVAL, 0);
1323 rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 0);
1324 rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_SYNC, 0);
1325 rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 0);
1326 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 0);
1327 rt2x00_set_field32(&reg, BCN_TIME_CFG_TX_TIME_COMPENSATE, 0);
1328 rt2x00usb_register_write(rt2x00dev, BCN_TIME_CFG, reg);
1329
1330 if (rt2x00_rev(&rt2x00dev->chip) == RT3070_VERSION) {
1331 rt2x00usb_register_write(rt2x00dev, TX_SW_CFG0, 0x00000400);
1332 rt2x00usb_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000);
1333 rt2x00usb_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000);
1334 } else {
1335 rt2x00usb_register_write(rt2x00dev, TX_SW_CFG0, 0x00000000);
1336 rt2x00usb_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606);
1337 }
1338
1339 rt2x00usb_register_read(rt2x00dev, TX_LINK_CFG, &reg);
1340 rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_MFB_LIFETIME, 32);
1341 rt2x00_set_field32(&reg, TX_LINK_CFG_MFB_ENABLE, 0);
1342 rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_UMFS_ENABLE, 0);
1343 rt2x00_set_field32(&reg, TX_LINK_CFG_TX_MRQ_EN, 0);
1344 rt2x00_set_field32(&reg, TX_LINK_CFG_TX_RDG_EN, 0);
1345 rt2x00_set_field32(&reg, TX_LINK_CFG_TX_CF_ACK_EN, 1);
1346 rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_MFB, 0);
1347 rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_MFS, 0);
1348 rt2x00usb_register_write(rt2x00dev, TX_LINK_CFG, reg);
1349
1350 rt2x00usb_register_read(rt2x00dev, TX_TIMEOUT_CFG, &reg);
1351 rt2x00_set_field32(&reg, TX_TIMEOUT_CFG_MPDU_LIFETIME, 9);
1352 rt2x00_set_field32(&reg, TX_TIMEOUT_CFG_TX_OP_TIMEOUT, 10);
1353 rt2x00usb_register_write(rt2x00dev, TX_TIMEOUT_CFG, reg);
1354
1355 rt2x00usb_register_read(rt2x00dev, MAX_LEN_CFG, &reg);
1356 rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_MPDU, AGGREGATION_SIZE);
1357 if (rt2x00_rev(&rt2x00dev->chip) >= RT2880E_VERSION &&
1358 rt2x00_rev(&rt2x00dev->chip) < RT3070_VERSION)
1359 rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_PSDU, 2);
1360 else
1361 rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_PSDU, 1);
1362 rt2x00_set_field32(&reg, MAX_LEN_CFG_MIN_PSDU, 0);
1363 rt2x00_set_field32(&reg, MAX_LEN_CFG_MIN_MPDU, 0);
1364 rt2x00usb_register_write(rt2x00dev, MAX_LEN_CFG, reg);
1365
1366 rt2x00usb_register_write(rt2x00dev, PBF_MAX_PCNT, 0x1f3fbf9f);
1367
1368 rt2x00usb_register_read(rt2x00dev, AUTO_RSP_CFG, &reg);
1369 rt2x00_set_field32(&reg, AUTO_RSP_CFG_AUTORESPONDER, 1);
1370 rt2x00_set_field32(&reg, AUTO_RSP_CFG_CTS_40_MMODE, 0);
1371 rt2x00_set_field32(&reg, AUTO_RSP_CFG_CTS_40_MREF, 0);
1372 rt2x00_set_field32(&reg, AUTO_RSP_CFG_DUAL_CTS_EN, 0);
1373 rt2x00_set_field32(&reg, AUTO_RSP_CFG_ACK_CTS_PSM_BIT, 0);
1374 rt2x00usb_register_write(rt2x00dev, AUTO_RSP_CFG, reg);
1375
1376 rt2x00usb_register_read(rt2x00dev, CCK_PROT_CFG, &reg);
1377 rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_RATE, 8);
1378 rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_CTRL, 0);
1379 rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_NAV, 1);
1380 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_CCK, 1);
1381 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
1382 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_MM20, 1);
1383 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_MM40, 1);
1384 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_GF20, 1);
1385 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_GF40, 1);
1386 rt2x00usb_register_write(rt2x00dev, CCK_PROT_CFG, reg);
1387
1388 rt2x00usb_register_read(rt2x00dev, OFDM_PROT_CFG, &reg);
1389 rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_RATE, 8);
1390 rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_CTRL, 0);
1391 rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_NAV, 1);
1392 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_CCK, 1);
1393 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
1394 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_MM20, 1);
1395 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_MM40, 1);
1396 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_GF20, 1);
1397 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_GF40, 1);
1398 rt2x00usb_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
1399
1400 rt2x00usb_register_read(rt2x00dev, MM20_PROT_CFG, &reg);
1401 rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_RATE, 0x4004);
1402 rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_CTRL, 0);
1403 rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_NAV, 1);
1404 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_CCK, 1);
1405 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
1406 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_MM20, 1);
1407 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_MM40, 0);
1408 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_GF20, 1);
1409 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_GF40, 0);
1410 rt2x00usb_register_write(rt2x00dev, MM20_PROT_CFG, reg);
1411
1412 rt2x00usb_register_read(rt2x00dev, MM40_PROT_CFG, &reg);
1413 rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_RATE, 0x4084);
1414 rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_CTRL, 0);
1415 rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_NAV, 1);
1416 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_CCK, 1);
1417 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
1418 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_MM20, 1);
1419 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_MM40, 1);
1420 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_GF20, 1);
1421 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_GF40, 1);
1422 rt2x00usb_register_write(rt2x00dev, MM40_PROT_CFG, reg);
1423
1424 rt2x00usb_register_read(rt2x00dev, GF20_PROT_CFG, &reg);
1425 rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_RATE, 0x4004);
1426 rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_CTRL, 0);
1427 rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_NAV, 1);
1428 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_CCK, 1);
1429 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
1430 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_MM20, 1);
1431 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_MM40, 0);
1432 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_GF20, 1);
1433 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_GF40, 0);
1434 rt2x00usb_register_write(rt2x00dev, GF20_PROT_CFG, reg);
1435
1436 rt2x00usb_register_read(rt2x00dev, GF40_PROT_CFG, &reg);
1437 rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_RATE, 0x4084);
1438 rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_CTRL, 0);
1439 rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_NAV, 1);
1440 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_CCK, 1);
1441 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
1442 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_MM20, 1);
1443 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_MM40, 1);
1444 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_GF20, 1);
1445 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_GF40, 1);
1446 rt2x00usb_register_write(rt2x00dev, GF40_PROT_CFG, reg);
1447
1448 rt2x00usb_register_write(rt2x00dev, PBF_CFG, 0xf40006);
1449
1450 rt2x00usb_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
1451 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
1452 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_DMA_BUSY, 0);
1453 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
1454 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_RX_DMA_BUSY, 0);
1455 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_WP_DMA_BURST_SIZE, 3);
1456 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 0);
1457 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_BIG_ENDIAN, 0);
1458 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_RX_HDR_SCATTER, 0);
1459 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_HDR_SEG_LEN, 0);
1460 rt2x00usb_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
1461
1462 rt2x00usb_register_write(rt2x00dev, TXOP_CTRL_CFG, 0x0000583f);
1463 rt2x00usb_register_write(rt2x00dev, TXOP_HLDR_ET, 0x00000002);
1464
1465 rt2x00usb_register_read(rt2x00dev, TX_RTS_CFG, &reg);
1466 rt2x00_set_field32(&reg, TX_RTS_CFG_AUTO_RTS_RETRY_LIMIT, 32);
1467 rt2x00_set_field32(&reg, TX_RTS_CFG_RTS_THRES,
1468 IEEE80211_MAX_RTS_THRESHOLD);
1469 rt2x00_set_field32(&reg, TX_RTS_CFG_RTS_FBK_EN, 0);
1470 rt2x00usb_register_write(rt2x00dev, TX_RTS_CFG, reg);
1471
1472 rt2x00usb_register_write(rt2x00dev, EXP_ACK_TIME, 0x002400ca);
1473 rt2x00usb_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000003);
1474
1475 /*
1476 * ASIC will keep garbage value after boot, clear encryption keys.
1477 */
1478 for (i = 0; i < 256; i++) {
1479 u32 wcid[2] = { 0xffffffff, 0x00ffffff };
1480 rt2x00usb_register_multiwrite(rt2x00dev, MAC_WCID_ENTRY(i),
1481 wcid, sizeof(wcid));
1482
1483 rt2x00usb_register_write(rt2x00dev, MAC_WCID_ATTR_ENTRY(i), 1);
1484 rt2x00usb_register_write(rt2x00dev, MAC_IVEIV_ENTRY(i), 0);
1485 }
1486
1487 for (i = 0; i < 16; i++)
1488 rt2x00usb_register_write(rt2x00dev,
1489 SHARED_KEY_MODE_ENTRY(i), 0);
1490
1491 /*
1492 * Clear all beacons
1493 * For the Beacon base registers we only need to clear
1494 * the first byte since that byte contains the VALID and OWNER
1495 * bits which (when set to 0) will invalidate the entire beacon.
1496 */
1497 rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE0, 0);
1498 rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE1, 0);
1499 rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE2, 0);
1500 rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE3, 0);
1501 rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE4, 0);
1502 rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE5, 0);
1503 rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE6, 0);
1504 rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE7, 0);
1505
1506 rt2x00usb_register_read(rt2x00dev, USB_CYC_CFG, &reg);
1507 rt2x00_set_field32(&reg, USB_CYC_CFG_CLOCK_CYCLE, 30);
1508 rt2x00usb_register_write(rt2x00dev, USB_CYC_CFG, reg);
1509
1510 rt2x00usb_register_read(rt2x00dev, HT_FBK_CFG0, &reg);
1511 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS0FBK, 0);
1512 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS1FBK, 0);
1513 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS2FBK, 1);
1514 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS3FBK, 2);
1515 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS4FBK, 3);
1516 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS5FBK, 4);
1517 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS6FBK, 5);
1518 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS7FBK, 6);
1519 rt2x00usb_register_write(rt2x00dev, HT_FBK_CFG0, reg);
1520
1521 rt2x00usb_register_read(rt2x00dev, HT_FBK_CFG1, &reg);
1522 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS8FBK, 8);
1523 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS9FBK, 8);
1524 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS10FBK, 9);
1525 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS11FBK, 10);
1526 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS12FBK, 11);
1527 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS13FBK, 12);
1528 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS14FBK, 13);
1529 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS15FBK, 14);
1530 rt2x00usb_register_write(rt2x00dev, HT_FBK_CFG1, reg);
1531
1532 rt2x00usb_register_read(rt2x00dev, LG_FBK_CFG0, &reg);
1533 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS0FBK, 8);
1534 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS1FBK, 8);
1535 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS2FBK, 3);
1536 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS3FBK, 10);
1537 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS4FBK, 11);
1538 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS5FBK, 12);
1539 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS6FBK, 13);
1540 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS7FBK, 14);
1541 rt2x00usb_register_write(rt2x00dev, LG_FBK_CFG0, reg);
1542
1543 rt2x00usb_register_read(rt2x00dev, LG_FBK_CFG1, &reg);
1544 rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS0FBK, 0);
1545 rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS1FBK, 0);
1546 rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS2FBK, 1);
1547 rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS3FBK, 2);
1548 rt2x00usb_register_write(rt2x00dev, LG_FBK_CFG1, reg);
1549
1550 /*
1551 * We must clear the error counters.
1552 * These registers are cleared on read,
1553 * so we may pass a useless variable to store the value.
1554 */
1555 rt2x00usb_register_read(rt2x00dev, RX_STA_CNT0, &reg);
1556 rt2x00usb_register_read(rt2x00dev, RX_STA_CNT1, &reg);
1557 rt2x00usb_register_read(rt2x00dev, RX_STA_CNT2, &reg);
1558 rt2x00usb_register_read(rt2x00dev, TX_STA_CNT0, &reg);
1559 rt2x00usb_register_read(rt2x00dev, TX_STA_CNT1, &reg);
1560 rt2x00usb_register_read(rt2x00dev, TX_STA_CNT2, &reg);
1561
1562 return 0;
1563}
1564
1565static int rt2800usb_wait_bbp_rf_ready(struct rt2x00_dev *rt2x00dev)
1566{
1567 unsigned int i;
1568 u32 reg;
1569
1570 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
1571 rt2x00usb_register_read(rt2x00dev, MAC_STATUS_CFG, &reg);
1572 if (!rt2x00_get_field32(reg, MAC_STATUS_CFG_BBP_RF_BUSY))
1573 return 0;
1574
1575 udelay(REGISTER_BUSY_DELAY);
1576 }
1577
1578 ERROR(rt2x00dev, "BBP/RF register access failed, aborting.\n");
1579 return -EACCES;
1580}
1581
1582static int rt2800usb_wait_bbp_ready(struct rt2x00_dev *rt2x00dev)
1583{
1584 unsigned int i;
1585 u8 value;
1586
1587 /*
1588 * BBP was enabled after firmware was loaded,
1589 * but we need to reactivate it now.
1590 */
1591 rt2x00usb_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
1592 rt2x00usb_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
1593 msleep(1);
1594
1595 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
1596 rt2800usb_bbp_read(rt2x00dev, 0, &value);
1597 if ((value != 0xff) && (value != 0x00))
1598 return 0;
1599 udelay(REGISTER_BUSY_DELAY);
1600 }
1601
1602 ERROR(rt2x00dev, "BBP register access failed, aborting.\n");
1603 return -EACCES;
1604}
1605
1606static int rt2800usb_init_bbp(struct rt2x00_dev *rt2x00dev)
1607{
1608 unsigned int i;
1609 u16 eeprom;
1610 u8 reg_id;
1611 u8 value;
1612
1613 if (unlikely(rt2800usb_wait_bbp_rf_ready(rt2x00dev) ||
1614 rt2800usb_wait_bbp_ready(rt2x00dev)))
1615 return -EACCES;
1616
1617 rt2800usb_bbp_write(rt2x00dev, 65, 0x2c);
1618 rt2800usb_bbp_write(rt2x00dev, 66, 0x38);
1619 rt2800usb_bbp_write(rt2x00dev, 69, 0x12);
1620 rt2800usb_bbp_write(rt2x00dev, 70, 0x0a);
1621 rt2800usb_bbp_write(rt2x00dev, 73, 0x10);
1622 rt2800usb_bbp_write(rt2x00dev, 81, 0x37);
1623 rt2800usb_bbp_write(rt2x00dev, 82, 0x62);
1624 rt2800usb_bbp_write(rt2x00dev, 83, 0x6a);
1625 rt2800usb_bbp_write(rt2x00dev, 84, 0x99);
1626 rt2800usb_bbp_write(rt2x00dev, 86, 0x00);
1627 rt2800usb_bbp_write(rt2x00dev, 91, 0x04);
1628 rt2800usb_bbp_write(rt2x00dev, 92, 0x00);
1629 rt2800usb_bbp_write(rt2x00dev, 103, 0x00);
1630 rt2800usb_bbp_write(rt2x00dev, 105, 0x05);
1631
1632 if (rt2x00_rev(&rt2x00dev->chip) == RT2860C_VERSION) {
1633 rt2800usb_bbp_write(rt2x00dev, 69, 0x16);
1634 rt2800usb_bbp_write(rt2x00dev, 73, 0x12);
1635 }
1636
1637 if (rt2x00_rev(&rt2x00dev->chip) > RT2860D_VERSION) {
1638 rt2800usb_bbp_write(rt2x00dev, 84, 0x19);
1639 }
1640
1641 if (rt2x00_rev(&rt2x00dev->chip) == RT3070_VERSION) {
1642 rt2800usb_bbp_write(rt2x00dev, 70, 0x0a);
1643 rt2800usb_bbp_write(rt2x00dev, 84, 0x99);
1644 rt2800usb_bbp_write(rt2x00dev, 105, 0x05);
1645 }
1646
1647 for (i = 0; i < EEPROM_BBP_SIZE; i++) {
1648 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBP_START + i, &eeprom);
1649
1650 if (eeprom != 0xffff && eeprom != 0x0000) {
1651 reg_id = rt2x00_get_field16(eeprom, EEPROM_BBP_REG_ID);
1652 value = rt2x00_get_field16(eeprom, EEPROM_BBP_VALUE);
1653 rt2800usb_bbp_write(rt2x00dev, reg_id, value);
1654 }
1655 }
1656
1657 return 0;
1658}
1659
1660static u8 rt2800usb_init_rx_filter(struct rt2x00_dev *rt2x00dev,
1661 bool bw40, u8 rfcsr24, u8 filter_target)
1662{
1663 unsigned int i;
1664 u8 bbp;
1665 u8 rfcsr;
1666 u8 passband;
1667 u8 stopband;
1668 u8 overtuned = 0;
1669
1670 rt2800usb_rfcsr_write(rt2x00dev, 24, rfcsr24);
1671
1672 rt2800usb_bbp_read(rt2x00dev, 4, &bbp);
1673 rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 2 * bw40);
1674 rt2800usb_bbp_write(rt2x00dev, 4, bbp);
1675
1676 rt2800usb_rfcsr_read(rt2x00dev, 22, &rfcsr);
1677 rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 1);
1678 rt2800usb_rfcsr_write(rt2x00dev, 22, rfcsr);
1679
1680 /*
1681 * Set power & frequency of passband test tone
1682 */
1683 rt2800usb_bbp_write(rt2x00dev, 24, 0);
1684
1685 for (i = 0; i < 100; i++) {
1686 rt2800usb_bbp_write(rt2x00dev, 25, 0x90);
1687 msleep(1);
1688
1689 rt2800usb_bbp_read(rt2x00dev, 55, &passband);
1690 if (passband)
1691 break;
1692 }
1693
1694 /*
1695 * Set power & frequency of stopband test tone
1696 */
1697 rt2800usb_bbp_write(rt2x00dev, 24, 0x06);
1698
1699 for (i = 0; i < 100; i++) {
1700 rt2800usb_bbp_write(rt2x00dev, 25, 0x90);
1701 msleep(1);
1702
1703 rt2800usb_bbp_read(rt2x00dev, 55, &stopband);
1704
1705 if ((passband - stopband) <= filter_target) {
1706 rfcsr24++;
1707 overtuned += ((passband - stopband) == filter_target);
1708 } else
1709 break;
1710
1711 rt2800usb_rfcsr_write(rt2x00dev, 24, rfcsr24);
1712 }
1713
1714 rfcsr24 -= !!overtuned;
1715
1716 rt2800usb_rfcsr_write(rt2x00dev, 24, rfcsr24);
1717 return rfcsr24;
1718}
1719
1720static int rt2800usb_init_rfcsr(struct rt2x00_dev *rt2x00dev)
1721{
1722 u8 rfcsr;
1723 u8 bbp;
1724
1725 if (rt2x00_rev(&rt2x00dev->chip) != RT3070_VERSION)
1726 return 0;
1727
1728 /*
1729 * Init RF calibration.
1730 */
1731 rt2800usb_rfcsr_read(rt2x00dev, 30, &rfcsr);
1732 rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 1);
1733 rt2800usb_rfcsr_write(rt2x00dev, 30, rfcsr);
1734 msleep(1);
1735 rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 0);
1736 rt2800usb_rfcsr_write(rt2x00dev, 30, rfcsr);
1737
1738 rt2800usb_rfcsr_write(rt2x00dev, 4, 0x40);
1739 rt2800usb_rfcsr_write(rt2x00dev, 5, 0x03);
1740 rt2800usb_rfcsr_write(rt2x00dev, 6, 0x02);
1741 rt2800usb_rfcsr_write(rt2x00dev, 7, 0x70);
1742 rt2800usb_rfcsr_write(rt2x00dev, 9, 0x0f);
1743 rt2800usb_rfcsr_write(rt2x00dev, 10, 0x71);
1744 rt2800usb_rfcsr_write(rt2x00dev, 11, 0x21);
1745 rt2800usb_rfcsr_write(rt2x00dev, 12, 0x7b);
1746 rt2800usb_rfcsr_write(rt2x00dev, 14, 0x90);
1747 rt2800usb_rfcsr_write(rt2x00dev, 15, 0x58);
1748 rt2800usb_rfcsr_write(rt2x00dev, 16, 0xb3);
1749 rt2800usb_rfcsr_write(rt2x00dev, 17, 0x92);
1750 rt2800usb_rfcsr_write(rt2x00dev, 18, 0x2c);
1751 rt2800usb_rfcsr_write(rt2x00dev, 19, 0x02);
1752 rt2800usb_rfcsr_write(rt2x00dev, 20, 0xba);
1753 rt2800usb_rfcsr_write(rt2x00dev, 21, 0xdb);
1754 rt2800usb_rfcsr_write(rt2x00dev, 24, 0x16);
1755 rt2800usb_rfcsr_write(rt2x00dev, 25, 0x01);
1756 rt2800usb_rfcsr_write(rt2x00dev, 27, 0x03);
1757 rt2800usb_rfcsr_write(rt2x00dev, 29, 0x1f);
1758
1759 /*
1760 * Set RX Filter calibration for 20MHz and 40MHz
1761 */
1762 rt2x00dev->calibration[0] =
1763 rt2800usb_init_rx_filter(rt2x00dev, false, 0x07, 0x16);
1764 rt2x00dev->calibration[1] =
1765 rt2800usb_init_rx_filter(rt2x00dev, true, 0x27, 0x19);
1766
1767 /*
1768 * Set back to initial state
1769 */
1770 rt2800usb_bbp_write(rt2x00dev, 24, 0);
1771
1772 rt2800usb_rfcsr_read(rt2x00dev, 22, &rfcsr);
1773 rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 0);
1774 rt2800usb_rfcsr_write(rt2x00dev, 22, rfcsr);
1775
1776 /*
1777 * set BBP back to BW20
1778 */
1779 rt2800usb_bbp_read(rt2x00dev, 4, &bbp);
1780 rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 0);
1781 rt2800usb_bbp_write(rt2x00dev, 4, bbp);
1782
1783 return 0;
1784}
1785
1786/*
1787 * Device state switch handlers.
1788 */
1789static void rt2800usb_toggle_rx(struct rt2x00_dev *rt2x00dev,
1790 enum dev_state state)
1791{
1792 u32 reg;
1793
1794 rt2x00usb_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
1795 rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX,
1796 (state == STATE_RADIO_RX_ON) ||
1797 (state == STATE_RADIO_RX_ON_LINK));
1798 rt2x00usb_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
1799}
1800
1801static int rt2800usb_wait_wpdma_ready(struct rt2x00_dev *rt2x00dev)
1802{
1803 unsigned int i;
1804 u32 reg;
1805
1806 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
1807 rt2x00usb_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
1808 if (!rt2x00_get_field32(reg, WPDMA_GLO_CFG_TX_DMA_BUSY) &&
1809 !rt2x00_get_field32(reg, WPDMA_GLO_CFG_RX_DMA_BUSY))
1810 return 0;
1811
1812 msleep(1);
1813 }
1814
1815 ERROR(rt2x00dev, "WPDMA TX/RX busy, aborting.\n");
1816 return -EACCES;
1817}
1818
1819static int rt2800usb_enable_radio(struct rt2x00_dev *rt2x00dev)
1820{
1821 u32 reg;
1822 u16 word;
1823
1824 /*
1825 * Initialize all registers.
1826 */
1827 if (unlikely(rt2800usb_wait_wpdma_ready(rt2x00dev) ||
1828 rt2800usb_init_registers(rt2x00dev) ||
1829 rt2800usb_init_bbp(rt2x00dev) ||
1830 rt2800usb_init_rfcsr(rt2x00dev)))
1831 return -EIO;
1832
1833 rt2x00usb_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
1834 rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_TX, 1);
1835 rt2x00usb_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
1836
1837 udelay(50);
1838
1839 rt2x00usb_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
1840 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1);
1841 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 1);
1842 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 1);
1843 rt2x00usb_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
1844
1845
1846 rt2x00usb_register_read(rt2x00dev, USB_DMA_CFG, &reg);
1847 rt2x00_set_field32(&reg, USB_DMA_CFG_PHY_CLEAR, 0);
1848 /* Don't use bulk in aggregation when working with USB 1.1 */
1849 rt2x00_set_field32(&reg, USB_DMA_CFG_RX_BULK_AGG_EN,
1850 (rt2x00dev->rx->usb_maxpacket == 512));
1851 rt2x00_set_field32(&reg, USB_DMA_CFG_RX_BULK_AGG_TIMEOUT, 128);
1852 /*
1853 * Total room for RX frames in kilobytes, PBF might still exceed
1854 * this limit so reduce the number to prevent errors.
1855 */
1856 rt2x00_set_field32(&reg, USB_DMA_CFG_RX_BULK_AGG_LIMIT,
1857 ((RX_ENTRIES * DATA_FRAME_SIZE) / 1024) - 3);
1858 rt2x00_set_field32(&reg, USB_DMA_CFG_RX_BULK_EN, 1);
1859 rt2x00_set_field32(&reg, USB_DMA_CFG_TX_BULK_EN, 1);
1860 rt2x00usb_register_write(rt2x00dev, USB_DMA_CFG, reg);
1861
1862 rt2x00usb_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
1863 rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_TX, 1);
1864 rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX, 1);
1865 rt2x00usb_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
1866
1867 /*
1868 * Initialize LED control
1869 */
1870 rt2x00_eeprom_read(rt2x00dev, EEPROM_LED1, &word);
1871 rt2800usb_mcu_request(rt2x00dev, MCU_LED_1, 0xff,
1872 word & 0xff, (word >> 8) & 0xff);
1873
1874 rt2x00_eeprom_read(rt2x00dev, EEPROM_LED2, &word);
1875 rt2800usb_mcu_request(rt2x00dev, MCU_LED_2, 0xff,
1876 word & 0xff, (word >> 8) & 0xff);
1877
1878 rt2x00_eeprom_read(rt2x00dev, EEPROM_LED3, &word);
1879 rt2800usb_mcu_request(rt2x00dev, MCU_LED_3, 0xff,
1880 word & 0xff, (word >> 8) & 0xff);
1881
1882 return 0;
1883}
1884
1885static void rt2800usb_disable_radio(struct rt2x00_dev *rt2x00dev)
1886{
1887 u32 reg;
1888
1889 rt2x00usb_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
1890 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
1891 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
1892 rt2x00usb_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
1893
1894 rt2x00usb_register_write(rt2x00dev, MAC_SYS_CTRL, 0);
1895 rt2x00usb_register_write(rt2x00dev, PWR_PIN_CFG, 0);
1896 rt2x00usb_register_write(rt2x00dev, TX_PIN_CFG, 0);
1897
1898 /* Wait for DMA, ignore error */
1899 rt2800usb_wait_wpdma_ready(rt2x00dev);
1900
1901 rt2x00usb_disable_radio(rt2x00dev);
1902}
1903
1904static int rt2800usb_set_state(struct rt2x00_dev *rt2x00dev,
1905 enum dev_state state)
1906{
1907 if (state == STATE_AWAKE)
1908 rt2800usb_mcu_request(rt2x00dev, MCU_WAKEUP, 0xff, 0, 0);
1909 else
1910 rt2800usb_mcu_request(rt2x00dev, MCU_SLEEP, 0xff, 0, 2);
1911
1912 return 0;
1913}
1914
1915static int rt2800usb_set_device_state(struct rt2x00_dev *rt2x00dev,
1916 enum dev_state state)
1917{
1918 int retval = 0;
1919
1920 switch (state) {
1921 case STATE_RADIO_ON:
1922 /*
1923 * Before the radio can be enabled, the device first has
1924 * to be woken up. After that it needs a bit of time
1925 * to be fully awake and the radio can be enabled.
1926 */
1927 rt2800usb_set_state(rt2x00dev, STATE_AWAKE);
1928 msleep(1);
1929 retval = rt2800usb_enable_radio(rt2x00dev);
1930 break;
1931 case STATE_RADIO_OFF:
1932 /*
1933 * After the radio has been disablee, the device should
1934 * be put to sleep for powersaving.
1935 */
1936 rt2800usb_disable_radio(rt2x00dev);
1937 rt2800usb_set_state(rt2x00dev, STATE_SLEEP);
1938 break;
1939 case STATE_RADIO_RX_ON:
1940 case STATE_RADIO_RX_ON_LINK:
1941 case STATE_RADIO_RX_OFF:
1942 case STATE_RADIO_RX_OFF_LINK:
1943 rt2800usb_toggle_rx(rt2x00dev, state);
1944 break;
1945 case STATE_RADIO_IRQ_ON:
1946 case STATE_RADIO_IRQ_OFF:
1947 /* No support, but no error either */
1948 break;
1949 case STATE_DEEP_SLEEP:
1950 case STATE_SLEEP:
1951 case STATE_STANDBY:
1952 case STATE_AWAKE:
1953 retval = rt2800usb_set_state(rt2x00dev, state);
1954 break;
1955 default:
1956 retval = -ENOTSUPP;
1957 break;
1958 }
1959
1960 if (unlikely(retval))
1961 ERROR(rt2x00dev, "Device failed to enter state %d (%d).\n",
1962 state, retval);
1963
1964 return retval;
1965}
1966
1967/*
1968 * TX descriptor initialization
1969 */
1970static void rt2800usb_write_tx_desc(struct rt2x00_dev *rt2x00dev,
1971 struct sk_buff *skb,
1972 struct txentry_desc *txdesc)
1973{
1974 struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb);
1975 __le32 *txi = skbdesc->desc;
1976 __le32 *txwi = &txi[TXINFO_DESC_SIZE / sizeof(__le32)];
1977 u32 word;
1978
1979 /*
1980 * Initialize TX Info descriptor
1981 */
1982 rt2x00_desc_read(txwi, 0, &word);
1983 rt2x00_set_field32(&word, TXWI_W0_FRAG,
1984 test_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags));
1985 rt2x00_set_field32(&word, TXWI_W0_MIMO_PS, 0);
1986 rt2x00_set_field32(&word, TXWI_W0_CF_ACK, 0);
1987 rt2x00_set_field32(&word, TXWI_W0_TS,
1988 test_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc->flags));
1989 rt2x00_set_field32(&word, TXWI_W0_AMPDU,
1990 test_bit(ENTRY_TXD_HT_AMPDU, &txdesc->flags));
1991 rt2x00_set_field32(&word, TXWI_W0_MPDU_DENSITY, txdesc->mpdu_density);
1992 rt2x00_set_field32(&word, TXWI_W0_TX_OP, txdesc->ifs);
1993 rt2x00_set_field32(&word, TXWI_W0_MCS, txdesc->mcs);
1994 rt2x00_set_field32(&word, TXWI_W0_BW,
1995 test_bit(ENTRY_TXD_HT_BW_40, &txdesc->flags));
1996 rt2x00_set_field32(&word, TXWI_W0_SHORT_GI,
1997 test_bit(ENTRY_TXD_HT_SHORT_GI, &txdesc->flags));
1998 rt2x00_set_field32(&word, TXWI_W0_STBC, txdesc->stbc);
1999 rt2x00_set_field32(&word, TXWI_W0_PHYMODE, txdesc->rate_mode);
2000 rt2x00_desc_write(txwi, 0, word);
2001
2002 rt2x00_desc_read(txwi, 1, &word);
2003 rt2x00_set_field32(&word, TXWI_W1_ACK,
2004 test_bit(ENTRY_TXD_ACK, &txdesc->flags));
2005 rt2x00_set_field32(&word, TXWI_W1_NSEQ,
2006 test_bit(ENTRY_TXD_GENERATE_SEQ, &txdesc->flags));
2007 rt2x00_set_field32(&word, TXWI_W1_BW_WIN_SIZE, txdesc->ba_size);
2008 rt2x00_set_field32(&word, TXWI_W1_WIRELESS_CLI_ID,
2009 test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags) ?
2010 txdesc->key_idx : 0xff);
2011 rt2x00_set_field32(&word, TXWI_W1_MPDU_TOTAL_BYTE_COUNT,
2012 skb->len - txdesc->l2pad);
2013 rt2x00_set_field32(&word, TXWI_W1_PACKETID,
2014 skbdesc->entry->entry_idx);
2015 rt2x00_desc_write(txwi, 1, word);
2016
2017 /*
2018 * Always write 0 to IV/EIV fields, hardware will insert the IV
2019 * from the IVEIV register when TXINFO_W0_WIV is set to 0.
2020 * When TXINFO_W0_WIV is set to 1 it will use the IV data
2021 * from the descriptor. The TXWI_W1_WIRELESS_CLI_ID indicates which
2022 * crypto entry in the registers should be used to encrypt the frame.
2023 */
2024 _rt2x00_desc_write(txwi, 2, 0 /* skbdesc->iv[0] */);
2025 _rt2x00_desc_write(txwi, 3, 0 /* skbdesc->iv[1] */);
2026
2027 /*
2028 * Initialize TX descriptor
2029 */
2030 rt2x00_desc_read(txi, 0, &word);
2031 rt2x00_set_field32(&word, TXINFO_W0_USB_DMA_TX_PKT_LEN,
2032 skb->len + TXWI_DESC_SIZE);
2033 rt2x00_set_field32(&word, TXINFO_W0_WIV,
2034 !test_bit(ENTRY_TXD_ENCRYPT_IV, &txdesc->flags));
2035 rt2x00_set_field32(&word, TXINFO_W0_QSEL, 2);
2036 rt2x00_set_field32(&word, TXINFO_W0_SW_USE_LAST_ROUND, 0);
2037 rt2x00_set_field32(&word, TXINFO_W0_USB_DMA_NEXT_VALID, 0);
2038 rt2x00_set_field32(&word, TXINFO_W0_USB_DMA_TX_BURST,
2039 test_bit(ENTRY_TXD_BURST, &txdesc->flags));
2040 rt2x00_desc_write(txi, 0, word);
2041}
2042
2043/*
2044 * TX data initialization
2045 */
2046static void rt2800usb_write_beacon(struct queue_entry *entry)
2047{
2048 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
2049 struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
2050 unsigned int beacon_base;
2051 u32 reg;
2052
2053 /*
2054 * Add the descriptor in front of the skb.
2055 */
2056 skb_push(entry->skb, entry->queue->desc_size);
2057 memcpy(entry->skb->data, skbdesc->desc, skbdesc->desc_len);
2058 skbdesc->desc = entry->skb->data;
2059
2060 /*
2061 * Disable beaconing while we are reloading the beacon data,
2062 * otherwise we might be sending out invalid data.
2063 */
2064 rt2x00usb_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
2065 rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 0);
2066 rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 0);
2067 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 0);
2068 rt2x00usb_register_write(rt2x00dev, BCN_TIME_CFG, reg);
2069
2070 /*
2071 * Write entire beacon with descriptor to register.
2072 */
2073 beacon_base = HW_BEACON_OFFSET(entry->entry_idx);
2074 rt2x00usb_vendor_request_large_buff(rt2x00dev, USB_MULTI_WRITE,
2075 USB_VENDOR_REQUEST_OUT, beacon_base,
2076 entry->skb->data, entry->skb->len,
2077 REGISTER_TIMEOUT32(entry->skb->len));
2078
2079 /*
2080 * Clean up the beacon skb.
2081 */
2082 dev_kfree_skb(entry->skb);
2083 entry->skb = NULL;
2084}
2085
2086static int rt2800usb_get_tx_data_len(struct queue_entry *entry)
2087{
2088 int length;
2089
2090 /*
2091 * The length _must_ include 4 bytes padding,
2092 * it should always be multiple of 4,
2093 * but it must _not_ be a multiple of the USB packet size.
2094 */
2095 length = roundup(entry->skb->len + 4, 4);
2096 length += (4 * !(length % entry->queue->usb_maxpacket));
2097
2098 return length;
2099}
2100
2101static void rt2800usb_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
2102 const enum data_queue_qid queue)
2103{
2104 u32 reg;
2105
2106 if (queue != QID_BEACON) {
2107 rt2x00usb_kick_tx_queue(rt2x00dev, queue);
2108 return;
2109 }
2110
2111 rt2x00usb_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
2112 if (!rt2x00_get_field32(reg, BCN_TIME_CFG_BEACON_GEN)) {
2113 rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 1);
2114 rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 1);
2115 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 1);
2116 rt2x00usb_register_write(rt2x00dev, BCN_TIME_CFG, reg);
2117 }
2118}
2119
2120/*
2121 * RX control handlers
2122 */
2123static void rt2800usb_fill_rxdone(struct queue_entry *entry,
2124 struct rxdone_entry_desc *rxdesc)
2125{
2126 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
2127 struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
2128 __le32 *rxd = (__le32 *)entry->skb->data;
2129 __le32 *rxwi;
2130 u32 rxd0;
2131 u32 rxwi0;
2132 u32 rxwi1;
2133 u32 rxwi2;
2134 u32 rxwi3;
2135
2136 /*
2137 * Copy descriptor to the skbdesc->desc buffer, making it safe from
2138 * moving of frame data in rt2x00usb.
2139 */
2140 memcpy(skbdesc->desc, rxd, skbdesc->desc_len);
2141 rxd = (__le32 *)skbdesc->desc;
2142 rxwi = &rxd[RXD_DESC_SIZE / sizeof(__le32)];
2143
2144 /*
2145 * It is now safe to read the descriptor on all architectures.
2146 */
2147 rt2x00_desc_read(rxd, 0, &rxd0);
2148 rt2x00_desc_read(rxwi, 0, &rxwi0);
2149 rt2x00_desc_read(rxwi, 1, &rxwi1);
2150 rt2x00_desc_read(rxwi, 2, &rxwi2);
2151 rt2x00_desc_read(rxwi, 3, &rxwi3);
2152
2153 if (rt2x00_get_field32(rxd0, RXD_W0_CRC_ERROR))
2154 rxdesc->flags |= RX_FLAG_FAILED_FCS_CRC;
2155
2156 if (test_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags)) {
2157 rxdesc->cipher = rt2x00_get_field32(rxwi0, RXWI_W0_UDF);
2158 rxdesc->cipher_status =
2159 rt2x00_get_field32(rxd0, RXD_W0_CIPHER_ERROR);
2160 }
2161
2162 if (rt2x00_get_field32(rxd0, RXD_W0_DECRYPTED)) {
2163 /*
2164 * Hardware has stripped IV/EIV data from 802.11 frame during
2165 * decryption. Unfortunately the descriptor doesn't contain
2166 * any fields with the EIV/IV data either, so they can't
2167 * be restored by rt2x00lib.
2168 */
2169 rxdesc->flags |= RX_FLAG_IV_STRIPPED;
2170
2171 if (rxdesc->cipher_status == RX_CRYPTO_SUCCESS)
2172 rxdesc->flags |= RX_FLAG_DECRYPTED;
2173 else if (rxdesc->cipher_status == RX_CRYPTO_FAIL_MIC)
2174 rxdesc->flags |= RX_FLAG_MMIC_ERROR;
2175 }
2176
2177 if (rt2x00_get_field32(rxd0, RXD_W0_MY_BSS))
2178 rxdesc->dev_flags |= RXDONE_MY_BSS;
2179
2180 if (rt2x00_get_field32(rxd0, RXD_W0_L2PAD))
2181 rxdesc->dev_flags |= RXDONE_L2PAD;
2182
2183 if (rt2x00_get_field32(rxwi1, RXWI_W1_SHORT_GI))
2184 rxdesc->flags |= RX_FLAG_SHORT_GI;
2185
2186 if (rt2x00_get_field32(rxwi1, RXWI_W1_BW))
2187 rxdesc->flags |= RX_FLAG_40MHZ;
2188
2189 /*
2190 * Detect RX rate, always use MCS as signal type.
2191 */
2192 rxdesc->dev_flags |= RXDONE_SIGNAL_MCS;
2193 rxdesc->rate_mode = rt2x00_get_field32(rxwi1, RXWI_W1_PHYMODE);
2194 rxdesc->signal = rt2x00_get_field32(rxwi1, RXWI_W1_MCS);
2195
2196 /*
2197 * Mask of 0x8 bit to remove the short preamble flag.
2198 */
2199 if (rxdesc->rate_mode == RATE_MODE_CCK)
2200 rxdesc->signal &= ~0x8;
2201
2202 rxdesc->rssi =
2203 (rt2x00_get_field32(rxwi2, RXWI_W2_RSSI0) +
2204 rt2x00_get_field32(rxwi2, RXWI_W2_RSSI1)) / 2;
2205
2206 rxdesc->noise =
2207 (rt2x00_get_field32(rxwi3, RXWI_W3_SNR0) +
2208 rt2x00_get_field32(rxwi3, RXWI_W3_SNR1)) / 2;
2209
2210 rxdesc->size = rt2x00_get_field32(rxwi0, RXWI_W0_MPDU_TOTAL_BYTE_COUNT);
2211
2212 /*
2213 * Remove RXWI descriptor from start of buffer.
2214 */
2215 skb_pull(entry->skb, skbdesc->desc_len);
2216 skb_trim(entry->skb, rxdesc->size);
2217}
2218
2219/*
2220 * Device probe functions.
2221 */
2222static int rt2800usb_validate_eeprom(struct rt2x00_dev *rt2x00dev)
2223{
2224 u16 word;
2225 u8 *mac;
2226 u8 default_lna_gain;
2227
2228 rt2x00usb_eeprom_read(rt2x00dev, rt2x00dev->eeprom, EEPROM_SIZE);
2229
2230 /*
2231 * Start validation of the data that has been read.
2232 */
2233 mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
2234 if (!is_valid_ether_addr(mac)) {
2235 DECLARE_MAC_BUF(macbuf);
2236
2237 random_ether_addr(mac);
2238 EEPROM(rt2x00dev, "MAC: %s\n", print_mac(macbuf, mac));
2239 }
2240
2241 rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &word);
2242 if (word == 0xffff) {
2243 rt2x00_set_field16(&word, EEPROM_ANTENNA_RXPATH, 2);
2244 rt2x00_set_field16(&word, EEPROM_ANTENNA_TXPATH, 1);
2245 rt2x00_set_field16(&word, EEPROM_ANTENNA_RF_TYPE, RF2820);
2246 rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word);
2247 EEPROM(rt2x00dev, "Antenna: 0x%04x\n", word);
2248 } else if (rt2x00_rev(&rt2x00dev->chip) < RT2883_VERSION) {
2249 /*
2250 * There is a max of 2 RX streams for RT2870 series
2251 */
2252 if (rt2x00_get_field16(word, EEPROM_ANTENNA_RXPATH) > 2)
2253 rt2x00_set_field16(&word, EEPROM_ANTENNA_RXPATH, 2);
2254 rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word);
2255 }
2256
2257 rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &word);
2258 if (word == 0xffff) {
2259 rt2x00_set_field16(&word, EEPROM_NIC_HW_RADIO, 0);
2260 rt2x00_set_field16(&word, EEPROM_NIC_DYNAMIC_TX_AGC, 0);
2261 rt2x00_set_field16(&word, EEPROM_NIC_EXTERNAL_LNA_BG, 0);
2262 rt2x00_set_field16(&word, EEPROM_NIC_EXTERNAL_LNA_A, 0);
2263 rt2x00_set_field16(&word, EEPROM_NIC_CARDBUS_ACCEL, 0);
2264 rt2x00_set_field16(&word, EEPROM_NIC_BW40M_SB_BG, 0);
2265 rt2x00_set_field16(&word, EEPROM_NIC_BW40M_SB_A, 0);
2266 rt2x00_set_field16(&word, EEPROM_NIC_WPS_PBC, 0);
2267 rt2x00_set_field16(&word, EEPROM_NIC_BW40M_BG, 0);
2268 rt2x00_set_field16(&word, EEPROM_NIC_BW40M_A, 0);
2269 rt2x00_eeprom_write(rt2x00dev, EEPROM_NIC, word);
2270 EEPROM(rt2x00dev, "NIC: 0x%04x\n", word);
2271 }
2272
2273 rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &word);
2274 if ((word & 0x00ff) == 0x00ff) {
2275 rt2x00_set_field16(&word, EEPROM_FREQ_OFFSET, 0);
2276 rt2x00_set_field16(&word, EEPROM_FREQ_LED_MODE,
2277 LED_MODE_TXRX_ACTIVITY);
2278 rt2x00_set_field16(&word, EEPROM_FREQ_LED_POLARITY, 0);
2279 rt2x00_eeprom_write(rt2x00dev, EEPROM_FREQ, word);
2280 rt2x00_eeprom_write(rt2x00dev, EEPROM_LED1, 0x5555);
2281 rt2x00_eeprom_write(rt2x00dev, EEPROM_LED2, 0x2221);
2282 rt2x00_eeprom_write(rt2x00dev, EEPROM_LED3, 0xa9f8);
2283 EEPROM(rt2x00dev, "Freq: 0x%04x\n", word);
2284 }
2285
2286 /*
2287 * During the LNA validation we are going to use
2288 * lna0 as correct value. Note that EEPROM_LNA
2289 * is never validated.
2290 */
2291 rt2x00_eeprom_read(rt2x00dev, EEPROM_LNA, &word);
2292 default_lna_gain = rt2x00_get_field16(word, EEPROM_LNA_A0);
2293
2294 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG, &word);
2295 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG_OFFSET0)) > 10)
2296 rt2x00_set_field16(&word, EEPROM_RSSI_BG_OFFSET0, 0);
2297 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG_OFFSET1)) > 10)
2298 rt2x00_set_field16(&word, EEPROM_RSSI_BG_OFFSET1, 0);
2299 rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_BG, word);
2300
2301 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &word);
2302 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG2_OFFSET2)) > 10)
2303 rt2x00_set_field16(&word, EEPROM_RSSI_BG2_OFFSET2, 0);
2304 if (rt2x00_get_field16(word, EEPROM_RSSI_BG2_LNA_A1) == 0x00 ||
2305 rt2x00_get_field16(word, EEPROM_RSSI_BG2_LNA_A1) == 0xff)
2306 rt2x00_set_field16(&word, EEPROM_RSSI_BG2_LNA_A1,
2307 default_lna_gain);
2308 rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_BG2, word);
2309
2310 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A, &word);
2311 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A_OFFSET0)) > 10)
2312 rt2x00_set_field16(&word, EEPROM_RSSI_A_OFFSET0, 0);
2313 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A_OFFSET1)) > 10)
2314 rt2x00_set_field16(&word, EEPROM_RSSI_A_OFFSET1, 0);
2315 rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_A, word);
2316
2317 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &word);
2318 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A2_OFFSET2)) > 10)
2319 rt2x00_set_field16(&word, EEPROM_RSSI_A2_OFFSET2, 0);
2320 if (rt2x00_get_field16(word, EEPROM_RSSI_A2_LNA_A2) == 0x00 ||
2321 rt2x00_get_field16(word, EEPROM_RSSI_A2_LNA_A2) == 0xff)
2322 rt2x00_set_field16(&word, EEPROM_RSSI_A2_LNA_A2,
2323 default_lna_gain);
2324 rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_A2, word);
2325
2326 return 0;
2327}
2328
2329static int rt2800usb_init_eeprom(struct rt2x00_dev *rt2x00dev)
2330{
2331 u32 reg;
2332 u16 value;
2333 u16 eeprom;
2334
2335 /*
2336 * Read EEPROM word for configuration.
2337 */
2338 rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
2339
2340 /*
2341 * Identify RF chipset.
2342 */
2343 value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE);
2344 rt2x00usb_register_read(rt2x00dev, MAC_CSR0, &reg);
2345 rt2x00_set_chip(rt2x00dev, RT2870, value, reg);
2346
2347 /*
2348 * The check for rt2860 is not a typo, some rt2870 hardware
2349 * identifies itself as rt2860 in the CSR register.
2350 */
2351 if (!rt2x00_check_rev(&rt2x00dev->chip, 0xfff00000, 0x28600000) &&
2352 !rt2x00_check_rev(&rt2x00dev->chip, 0xfff00000, 0x28700000) &&
2353 !rt2x00_check_rev(&rt2x00dev->chip, 0xfff00000, 0x28800000) &&
2354 !rt2x00_check_rev(&rt2x00dev->chip, 0xffff0000, 0x30700000)) {
2355 ERROR(rt2x00dev, "Invalid RT chipset detected.\n");
2356 return -ENODEV;
2357 }
2358
2359 if (!rt2x00_rf(&rt2x00dev->chip, RF2820) &&
2360 !rt2x00_rf(&rt2x00dev->chip, RF2850) &&
2361 !rt2x00_rf(&rt2x00dev->chip, RF2720) &&
2362 !rt2x00_rf(&rt2x00dev->chip, RF2750) &&
2363 !rt2x00_rf(&rt2x00dev->chip, RF3020) &&
2364 !rt2x00_rf(&rt2x00dev->chip, RF2020)) {
2365 ERROR(rt2x00dev, "Invalid RF chipset detected.\n");
2366 return -ENODEV;
2367 }
2368
2369 /*
2370 * Identify default antenna configuration.
2371 */
2372 rt2x00dev->default_ant.tx =
2373 rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TXPATH);
2374 rt2x00dev->default_ant.rx =
2375 rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RXPATH);
2376
2377 /*
2378 * Read frequency offset and RF programming sequence.
2379 */
2380 rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &eeprom);
2381 rt2x00dev->freq_offset = rt2x00_get_field16(eeprom, EEPROM_FREQ_OFFSET);
2382
2383 /*
2384 * Read external LNA informations.
2385 */
2386 rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &eeprom);
2387
2388 if (rt2x00_get_field16(eeprom, EEPROM_NIC_EXTERNAL_LNA_A))
2389 __set_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags);
2390 if (rt2x00_get_field16(eeprom, EEPROM_NIC_EXTERNAL_LNA_BG))
2391 __set_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags);
2392
2393 /*
2394 * Detect if this device has an hardware controlled radio.
2395 */
2396#ifdef CONFIG_RT2X00_LIB_RFKILL
2397 if (rt2x00_get_field16(eeprom, EEPROM_NIC_HW_RADIO))
2398 __set_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags);
2399#endif /* CONFIG_RT2X00_LIB_RFKILL */
2400
2401 /*
2402 * Store led settings, for correct led behaviour.
2403 */
2404#ifdef CONFIG_RT2X00_LIB_LEDS
2405 rt2800usb_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO);
2406 rt2800usb_init_led(rt2x00dev, &rt2x00dev->led_assoc, LED_TYPE_ASSOC);
2407 rt2800usb_init_led(rt2x00dev, &rt2x00dev->led_qual, LED_TYPE_QUALITY);
2408
2409 rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ,
2410 &rt2x00dev->led_mcu_reg);
2411#endif /* CONFIG_RT2X00_LIB_LEDS */
2412
2413 return 0;
2414}
2415
2416/*
2417 * RF value list for rt2870
2418 * Supports: 2.4 GHz (all) & 5.2 GHz (RF2850 & RF2750)
2419 */
2420static const struct rf_channel rf_vals[] = {
2421 { 1, 0x18402ecc, 0x184c0786, 0x1816b455, 0x1800510b },
2422 { 2, 0x18402ecc, 0x184c0786, 0x18168a55, 0x1800519f },
2423 { 3, 0x18402ecc, 0x184c078a, 0x18168a55, 0x1800518b },
2424 { 4, 0x18402ecc, 0x184c078a, 0x18168a55, 0x1800519f },
2425 { 5, 0x18402ecc, 0x184c078e, 0x18168a55, 0x1800518b },
2426 { 6, 0x18402ecc, 0x184c078e, 0x18168a55, 0x1800519f },
2427 { 7, 0x18402ecc, 0x184c0792, 0x18168a55, 0x1800518b },
2428 { 8, 0x18402ecc, 0x184c0792, 0x18168a55, 0x1800519f },
2429 { 9, 0x18402ecc, 0x184c0796, 0x18168a55, 0x1800518b },
2430 { 10, 0x18402ecc, 0x184c0796, 0x18168a55, 0x1800519f },
2431 { 11, 0x18402ecc, 0x184c079a, 0x18168a55, 0x1800518b },
2432 { 12, 0x18402ecc, 0x184c079a, 0x18168a55, 0x1800519f },
2433 { 13, 0x18402ecc, 0x184c079e, 0x18168a55, 0x1800518b },
2434 { 14, 0x18402ecc, 0x184c07a2, 0x18168a55, 0x18005193 },
2435
2436 /* 802.11 UNI / HyperLan 2 */
2437 { 36, 0x18402ecc, 0x184c099a, 0x18158a55, 0x180ed1a3 },
2438 { 38, 0x18402ecc, 0x184c099e, 0x18158a55, 0x180ed193 },
2439 { 40, 0x18402ec8, 0x184c0682, 0x18158a55, 0x180ed183 },
2440 { 44, 0x18402ec8, 0x184c0682, 0x18158a55, 0x180ed1a3 },
2441 { 46, 0x18402ec8, 0x184c0686, 0x18158a55, 0x180ed18b },
2442 { 48, 0x18402ec8, 0x184c0686, 0x18158a55, 0x180ed19b },
2443 { 52, 0x18402ec8, 0x184c068a, 0x18158a55, 0x180ed193 },
2444 { 54, 0x18402ec8, 0x184c068a, 0x18158a55, 0x180ed1a3 },
2445 { 56, 0x18402ec8, 0x184c068e, 0x18158a55, 0x180ed18b },
2446 { 60, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed183 },
2447 { 62, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed193 },
2448 { 64, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed1a3 },
2449
2450 /* 802.11 HyperLan 2 */
2451 { 100, 0x18402ec8, 0x184c06b2, 0x18178a55, 0x180ed783 },
2452 { 102, 0x18402ec8, 0x184c06b2, 0x18578a55, 0x180ed793 },
2453 { 104, 0x18402ec8, 0x185c06b2, 0x18578a55, 0x180ed1a3 },
2454 { 108, 0x18402ecc, 0x185c0a32, 0x18578a55, 0x180ed193 },
2455 { 110, 0x18402ecc, 0x184c0a36, 0x18178a55, 0x180ed183 },
2456 { 112, 0x18402ecc, 0x184c0a36, 0x18178a55, 0x180ed19b },
2457 { 116, 0x18402ecc, 0x184c0a3a, 0x18178a55, 0x180ed1a3 },
2458 { 118, 0x18402ecc, 0x184c0a3e, 0x18178a55, 0x180ed193 },
2459 { 120, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed183 },
2460 { 124, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed193 },
2461 { 126, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed15b },
2462 { 128, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed1a3 },
2463 { 132, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed18b },
2464 { 134, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed193 },
2465 { 136, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed19b },
2466 { 140, 0x18402ec4, 0x184c038a, 0x18178a55, 0x180ed183 },
2467
2468 /* 802.11 UNII */
2469 { 149, 0x18402ec4, 0x184c038a, 0x18178a55, 0x180ed1a7 },
2470 { 151, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed187 },
2471 { 153, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed18f },
2472 { 157, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed19f },
2473 { 159, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed1a7 },
2474 { 161, 0x18402ec4, 0x184c0392, 0x18178a55, 0x180ed187 },
2475 { 165, 0x18402ec4, 0x184c0392, 0x18178a55, 0x180ed197 },
2476 { 167, 0x18402ec4, 0x184c03d2, 0x18179855, 0x1815531f },
2477 { 169, 0x18402ec4, 0x184c03d2, 0x18179855, 0x18155327 },
2478 { 171, 0x18402ec4, 0x184c03d6, 0x18179855, 0x18155307 },
2479 { 173, 0x18402ec4, 0x184c03d6, 0x18179855, 0x1815530f },
2480
2481 /* 802.11 Japan */
2482 { 184, 0x15002ccc, 0x1500491e, 0x1509be55, 0x150c0a0b },
2483 { 188, 0x15002ccc, 0x15004922, 0x1509be55, 0x150c0a13 },
2484 { 192, 0x15002ccc, 0x15004926, 0x1509be55, 0x150c0a1b },
2485 { 196, 0x15002ccc, 0x1500492a, 0x1509be55, 0x150c0a23 },
2486 { 208, 0x15002ccc, 0x1500493a, 0x1509be55, 0x150c0a13 },
2487 { 212, 0x15002ccc, 0x1500493e, 0x1509be55, 0x150c0a1b },
2488 { 216, 0x15002ccc, 0x15004982, 0x1509be55, 0x150c0a23 },
2489};
2490
2491/*
2492 * RF value list for rt3070
2493 * Supports: 2.4 GHz
2494 */
2495static const struct rf_channel rf_vals_3070[] = {
2496 {1, 241, 2, 2 },
2497 {2, 241, 2, 7 },
2498 {3, 242, 2, 2 },
2499 {4, 242, 2, 7 },
2500 {5, 243, 2, 2 },
2501 {6, 243, 2, 7 },
2502 {7, 244, 2, 2 },
2503 {8, 244, 2, 7 },
2504 {9, 245, 2, 2 },
2505 {10, 245, 2, 7 },
2506 {11, 246, 2, 2 },
2507 {12, 246, 2, 7 },
2508 {13, 247, 2, 2 },
2509 {14, 248, 2, 4 },
2510};
2511
2512static int rt2800usb_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
2513{
2514 struct hw_mode_spec *spec = &rt2x00dev->spec;
2515 struct channel_info *info;
2516 char *tx_power1;
2517 char *tx_power2;
2518 unsigned int i;
2519 u16 eeprom;
2520
2521 /*
2522 * Initialize all hw fields.
2523 */
2524 rt2x00dev->hw->flags =
2525 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
2526 IEEE80211_HW_SIGNAL_DBM |
2527 IEEE80211_HW_SUPPORTS_PS |
2528 IEEE80211_HW_PS_NULLFUNC_STACK;
2529 rt2x00dev->hw->extra_tx_headroom = TXINFO_DESC_SIZE + TXWI_DESC_SIZE;
2530
2531 SET_IEEE80211_DEV(rt2x00dev->hw, rt2x00dev->dev);
2532 SET_IEEE80211_PERM_ADDR(rt2x00dev->hw,
2533 rt2x00_eeprom_addr(rt2x00dev,
2534 EEPROM_MAC_ADDR_0));
2535
2536 rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
2537
2538 /*
2539 * Initialize HT information.
2540 */
2541 spec->ht.ht_supported = true;
2542 spec->ht.cap =
2543 IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
2544 IEEE80211_HT_CAP_GRN_FLD |
2545 IEEE80211_HT_CAP_SGI_20 |
2546 IEEE80211_HT_CAP_SGI_40 |
2547 IEEE80211_HT_CAP_TX_STBC |
2548 IEEE80211_HT_CAP_RX_STBC |
2549 IEEE80211_HT_CAP_PSMP_SUPPORT;
2550 spec->ht.ampdu_factor = 3;
2551 spec->ht.ampdu_density = 4;
2552 spec->ht.mcs.tx_params =
2553 IEEE80211_HT_MCS_TX_DEFINED |
2554 IEEE80211_HT_MCS_TX_RX_DIFF |
2555 ((rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TXPATH) - 1) <<
2556 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
2557
2558 switch (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RXPATH)) {
2559 case 3:
2560 spec->ht.mcs.rx_mask[2] = 0xff;
2561 case 2:
2562 spec->ht.mcs.rx_mask[1] = 0xff;
2563 case 1:
2564 spec->ht.mcs.rx_mask[0] = 0xff;
2565 spec->ht.mcs.rx_mask[4] = 0x1; /* MCS32 */
2566 break;
2567 }
2568
2569 /*
2570 * Initialize hw_mode information.
2571 */
2572 spec->supported_bands = SUPPORT_BAND_2GHZ;
2573 spec->supported_rates = SUPPORT_RATE_CCK | SUPPORT_RATE_OFDM;
2574
2575 if (rt2x00_rf(&rt2x00dev->chip, RF2820) ||
2576 rt2x00_rf(&rt2x00dev->chip, RF2720)) {
2577 spec->num_channels = 14;
2578 spec->channels = rf_vals;
2579 } else if (rt2x00_rf(&rt2x00dev->chip, RF2850) ||
2580 rt2x00_rf(&rt2x00dev->chip, RF2750)) {
2581 spec->supported_bands |= SUPPORT_BAND_5GHZ;
2582 spec->num_channels = ARRAY_SIZE(rf_vals);
2583 spec->channels = rf_vals;
2584 } else if (rt2x00_rf(&rt2x00dev->chip, RF3020) ||
2585 rt2x00_rf(&rt2x00dev->chip, RF2020)) {
2586 spec->num_channels = ARRAY_SIZE(rf_vals_3070);
2587 spec->channels = rf_vals_3070;
2588 }
2589
2590 /*
2591 * Create channel information array
2592 */
2593 info = kzalloc(spec->num_channels * sizeof(*info), GFP_KERNEL);
2594 if (!info)
2595 return -ENOMEM;
2596
2597 spec->channels_info = info;
2598
2599 tx_power1 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_BG1);
2600 tx_power2 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_BG2);
2601
2602 for (i = 0; i < 14; i++) {
2603 info[i].tx_power1 = TXPOWER_G_FROM_DEV(tx_power1[i]);
2604 info[i].tx_power2 = TXPOWER_G_FROM_DEV(tx_power2[i]);
2605 }
2606
2607 if (spec->num_channels > 14) {
2608 tx_power1 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_A1);
2609 tx_power2 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_A2);
2610
2611 for (i = 14; i < spec->num_channels; i++) {
2612 info[i].tx_power1 = TXPOWER_A_FROM_DEV(tx_power1[i]);
2613 info[i].tx_power2 = TXPOWER_A_FROM_DEV(tx_power2[i]);
2614 }
2615 }
2616
2617 return 0;
2618}
2619
2620static int rt2800usb_probe_hw(struct rt2x00_dev *rt2x00dev)
2621{
2622 int retval;
2623
2624 /*
2625 * Allocate eeprom data.
2626 */
2627 retval = rt2800usb_validate_eeprom(rt2x00dev);
2628 if (retval)
2629 return retval;
2630
2631 retval = rt2800usb_init_eeprom(rt2x00dev);
2632 if (retval)
2633 return retval;
2634
2635 /*
2636 * Initialize hw specifications.
2637 */
2638 retval = rt2800usb_probe_hw_mode(rt2x00dev);
2639 if (retval)
2640 return retval;
2641
2642 /*
2643 * This device requires firmware.
2644 */
2645 __set_bit(DRIVER_REQUIRE_FIRMWARE, &rt2x00dev->flags);
2646 __set_bit(DRIVER_REQUIRE_SCHEDULED, &rt2x00dev->flags);
2647 __set_bit(DRIVER_REQUIRE_L2PAD, &rt2x00dev->flags);
2648 if (!modparam_nohwcrypt)
2649 __set_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags);
2650
2651 /*
2652 * Set the rssi offset.
2653 */
2654 rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET;
2655
2656 return 0;
2657}
2658
2659/*
2660 * IEEE80211 stack callback functions.
2661 */
2662static void rt2800usb_get_tkip_seq(struct ieee80211_hw *hw, u8 hw_key_idx,
2663 u32 *iv32, u16 *iv16)
2664{
2665 struct rt2x00_dev *rt2x00dev = hw->priv;
2666 struct mac_iveiv_entry iveiv_entry;
2667 u32 offset;
2668
2669 offset = MAC_IVEIV_ENTRY(hw_key_idx);
2670 rt2x00usb_register_multiread(rt2x00dev, offset,
2671 &iveiv_entry, sizeof(iveiv_entry));
2672
2673 memcpy(&iveiv_entry.iv[0], iv16, sizeof(iv16));
2674 memcpy(&iveiv_entry.iv[4], iv32, sizeof(iv32));
2675}
2676
2677static int rt2800usb_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
2678{
2679 struct rt2x00_dev *rt2x00dev = hw->priv;
2680 u32 reg;
2681 bool enabled = (value < IEEE80211_MAX_RTS_THRESHOLD);
2682
2683 rt2x00usb_register_read(rt2x00dev, TX_RTS_CFG, &reg);
2684 rt2x00_set_field32(&reg, TX_RTS_CFG_RTS_THRES, value);
2685 rt2x00usb_register_write(rt2x00dev, TX_RTS_CFG, reg);
2686
2687 rt2x00usb_register_read(rt2x00dev, CCK_PROT_CFG, &reg);
2688 rt2x00_set_field32(&reg, CCK_PROT_CFG_RTS_TH_EN, enabled);
2689 rt2x00usb_register_write(rt2x00dev, CCK_PROT_CFG, reg);
2690
2691 rt2x00usb_register_read(rt2x00dev, OFDM_PROT_CFG, &reg);
2692 rt2x00_set_field32(&reg, OFDM_PROT_CFG_RTS_TH_EN, enabled);
2693 rt2x00usb_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
2694
2695 rt2x00usb_register_read(rt2x00dev, MM20_PROT_CFG, &reg);
2696 rt2x00_set_field32(&reg, MM20_PROT_CFG_RTS_TH_EN, enabled);
2697 rt2x00usb_register_write(rt2x00dev, MM20_PROT_CFG, reg);
2698
2699 rt2x00usb_register_read(rt2x00dev, MM40_PROT_CFG, &reg);
2700 rt2x00_set_field32(&reg, MM40_PROT_CFG_RTS_TH_EN, enabled);
2701 rt2x00usb_register_write(rt2x00dev, MM40_PROT_CFG, reg);
2702
2703 rt2x00usb_register_read(rt2x00dev, GF20_PROT_CFG, &reg);
2704 rt2x00_set_field32(&reg, GF20_PROT_CFG_RTS_TH_EN, enabled);
2705 rt2x00usb_register_write(rt2x00dev, GF20_PROT_CFG, reg);
2706
2707 rt2x00usb_register_read(rt2x00dev, GF40_PROT_CFG, &reg);
2708 rt2x00_set_field32(&reg, GF40_PROT_CFG_RTS_TH_EN, enabled);
2709 rt2x00usb_register_write(rt2x00dev, GF40_PROT_CFG, reg);
2710
2711 return 0;
2712}
2713
2714static int rt2800usb_conf_tx(struct ieee80211_hw *hw, u16 queue_idx,
2715 const struct ieee80211_tx_queue_params *params)
2716{
2717 struct rt2x00_dev *rt2x00dev = hw->priv;
2718 struct data_queue *queue;
2719 struct rt2x00_field32 field;
2720 int retval;
2721 u32 reg;
2722 u32 offset;
2723
2724 /*
2725 * First pass the configuration through rt2x00lib, that will
2726 * update the queue settings and validate the input. After that
2727 * we are free to update the registers based on the value
2728 * in the queue parameter.
2729 */
2730 retval = rt2x00mac_conf_tx(hw, queue_idx, params);
2731 if (retval)
2732 return retval;
2733
2734 /*
2735 * We only need to perform additional register initialization
2736 * for WMM queues/
2737 */
2738 if (queue_idx >= 4)
2739 return 0;
2740
2741 queue = rt2x00queue_get_queue(rt2x00dev, queue_idx);
2742
2743 /* Update WMM TXOP register */
2744 offset = WMM_TXOP0_CFG + (sizeof(u32) * (!!(queue_idx & 2)));
2745 field.bit_offset = (queue_idx & 1) * 16;
2746 field.bit_mask = 0xffff << field.bit_offset;
2747
2748 rt2x00usb_register_read(rt2x00dev, offset, &reg);
2749 rt2x00_set_field32(&reg, field, queue->txop);
2750 rt2x00usb_register_write(rt2x00dev, offset, reg);
2751
2752 /* Update WMM registers */
2753 field.bit_offset = queue_idx * 4;
2754 field.bit_mask = 0xf << field.bit_offset;
2755
2756 rt2x00usb_register_read(rt2x00dev, WMM_AIFSN_CFG, &reg);
2757 rt2x00_set_field32(&reg, field, queue->aifs);
2758 rt2x00usb_register_write(rt2x00dev, WMM_AIFSN_CFG, reg);
2759
2760 rt2x00usb_register_read(rt2x00dev, WMM_CWMIN_CFG, &reg);
2761 rt2x00_set_field32(&reg, field, queue->cw_min);
2762 rt2x00usb_register_write(rt2x00dev, WMM_CWMIN_CFG, reg);
2763
2764 rt2x00usb_register_read(rt2x00dev, WMM_CWMAX_CFG, &reg);
2765 rt2x00_set_field32(&reg, field, queue->cw_max);
2766 rt2x00usb_register_write(rt2x00dev, WMM_CWMAX_CFG, reg);
2767
2768 /* Update EDCA registers */
2769 offset = EDCA_AC0_CFG + (sizeof(u32) * queue_idx);
2770
2771 rt2x00usb_register_read(rt2x00dev, offset, &reg);
2772 rt2x00_set_field32(&reg, EDCA_AC0_CFG_TX_OP, queue->txop);
2773 rt2x00_set_field32(&reg, EDCA_AC0_CFG_AIFSN, queue->aifs);
2774 rt2x00_set_field32(&reg, EDCA_AC0_CFG_CWMIN, queue->cw_min);
2775 rt2x00_set_field32(&reg, EDCA_AC0_CFG_CWMAX, queue->cw_max);
2776 rt2x00usb_register_write(rt2x00dev, offset, reg);
2777
2778 return 0;
2779}
2780
2781static u64 rt2800usb_get_tsf(struct ieee80211_hw *hw)
2782{
2783 struct rt2x00_dev *rt2x00dev = hw->priv;
2784 u64 tsf;
2785 u32 reg;
2786
2787 rt2x00usb_register_read(rt2x00dev, TSF_TIMER_DW1, &reg);
2788 tsf = (u64) rt2x00_get_field32(reg, TSF_TIMER_DW1_HIGH_WORD) << 32;
2789 rt2x00usb_register_read(rt2x00dev, TSF_TIMER_DW0, &reg);
2790 tsf |= rt2x00_get_field32(reg, TSF_TIMER_DW0_LOW_WORD);
2791
2792 return tsf;
2793}
2794
2795static const struct ieee80211_ops rt2800usb_mac80211_ops = {
2796 .tx = rt2x00mac_tx,
2797 .start = rt2x00mac_start,
2798 .stop = rt2x00mac_stop,
2799 .add_interface = rt2x00mac_add_interface,
2800 .remove_interface = rt2x00mac_remove_interface,
2801 .config = rt2x00mac_config,
2802 .configure_filter = rt2x00mac_configure_filter,
2803 .set_key = rt2x00mac_set_key,
2804 .get_stats = rt2x00mac_get_stats,
2805 .get_tkip_seq = rt2800usb_get_tkip_seq,
2806 .set_rts_threshold = rt2800usb_set_rts_threshold,
2807 .bss_info_changed = rt2x00mac_bss_info_changed,
2808 .conf_tx = rt2800usb_conf_tx,
2809 .get_tx_stats = rt2x00mac_get_tx_stats,
2810 .get_tsf = rt2800usb_get_tsf,
2811};
2812
2813static const struct rt2x00lib_ops rt2800usb_rt2x00_ops = {
2814 .probe_hw = rt2800usb_probe_hw,
2815 .get_firmware_name = rt2800usb_get_firmware_name,
2816 .check_firmware = rt2800usb_check_firmware,
2817 .load_firmware = rt2800usb_load_firmware,
2818 .initialize = rt2x00usb_initialize,
2819 .uninitialize = rt2x00usb_uninitialize,
2820 .clear_entry = rt2x00usb_clear_entry,
2821 .set_device_state = rt2800usb_set_device_state,
2822 .rfkill_poll = rt2800usb_rfkill_poll,
2823 .link_stats = rt2800usb_link_stats,
2824 .reset_tuner = rt2800usb_reset_tuner,
2825 .link_tuner = rt2800usb_link_tuner,
2826 .write_tx_desc = rt2800usb_write_tx_desc,
2827 .write_tx_data = rt2x00usb_write_tx_data,
2828 .write_beacon = rt2800usb_write_beacon,
2829 .get_tx_data_len = rt2800usb_get_tx_data_len,
2830 .kick_tx_queue = rt2800usb_kick_tx_queue,
2831 .kill_tx_queue = rt2x00usb_kill_tx_queue,
2832 .fill_rxdone = rt2800usb_fill_rxdone,
2833 .config_shared_key = rt2800usb_config_shared_key,
2834 .config_pairwise_key = rt2800usb_config_pairwise_key,
2835 .config_filter = rt2800usb_config_filter,
2836 .config_intf = rt2800usb_config_intf,
2837 .config_erp = rt2800usb_config_erp,
2838 .config_ant = rt2800usb_config_ant,
2839 .config = rt2800usb_config,
2840};
2841
2842static const struct data_queue_desc rt2800usb_queue_rx = {
2843 .entry_num = RX_ENTRIES,
2844 .data_size = AGGREGATION_SIZE,
2845 .desc_size = RXD_DESC_SIZE + RXWI_DESC_SIZE,
2846 .priv_size = sizeof(struct queue_entry_priv_usb),
2847};
2848
2849static const struct data_queue_desc rt2800usb_queue_tx = {
2850 .entry_num = TX_ENTRIES,
2851 .data_size = AGGREGATION_SIZE,
2852 .desc_size = TXINFO_DESC_SIZE + TXWI_DESC_SIZE,
2853 .priv_size = sizeof(struct queue_entry_priv_usb),
2854};
2855
2856static const struct data_queue_desc rt2800usb_queue_bcn = {
2857 .entry_num = 8 * BEACON_ENTRIES,
2858 .data_size = MGMT_FRAME_SIZE,
2859 .desc_size = TXINFO_DESC_SIZE + TXWI_DESC_SIZE,
2860 .priv_size = sizeof(struct queue_entry_priv_usb),
2861};
2862
2863static const struct rt2x00_ops rt2800usb_ops = {
2864 .name = KBUILD_MODNAME,
2865 .max_sta_intf = 1,
2866 .max_ap_intf = 8,
2867 .eeprom_size = EEPROM_SIZE,
2868 .rf_size = RF_SIZE,
2869 .tx_queues = NUM_TX_QUEUES,
2870 .rx = &rt2800usb_queue_rx,
2871 .tx = &rt2800usb_queue_tx,
2872 .bcn = &rt2800usb_queue_bcn,
2873 .lib = &rt2800usb_rt2x00_ops,
2874 .hw = &rt2800usb_mac80211_ops,
2875#ifdef CONFIG_RT2X00_LIB_DEBUGFS
2876 .debugfs = &rt2800usb_rt2x00debug,
2877#endif /* CONFIG_RT2X00_LIB_DEBUGFS */
2878};
2879
2880/*
2881 * rt2800usb module information.
2882 */
2883static struct usb_device_id rt2800usb_device_table[] = {
2884 /* ??? */
2885 { USB_DEVICE(0x177f, 0x0302), USB_DEVICE_DATA(&rt2800usb_ops) },
2886 /* Abocom */
2887 { USB_DEVICE(0x07b8, 0x2870), USB_DEVICE_DATA(&rt2800usb_ops) },
2888 { USB_DEVICE(0x07b8, 0x2770), USB_DEVICE_DATA(&rt2800usb_ops) },
2889 { USB_DEVICE(0x07b8, 0x3070), USB_DEVICE_DATA(&rt2800usb_ops) },
2890 { USB_DEVICE(0x07b8, 0x3071), USB_DEVICE_DATA(&rt2800usb_ops) },
2891 { USB_DEVICE(0x07b8, 0x3072), USB_DEVICE_DATA(&rt2800usb_ops) },
2892 { USB_DEVICE(0x1482, 0x3c09), USB_DEVICE_DATA(&rt2800usb_ops) },
2893 /* AirTies */
2894 { USB_DEVICE(0x1eda, 0x2310), USB_DEVICE_DATA(&rt2800usb_ops) },
2895 /* Amigo */
2896 { USB_DEVICE(0x0e0b, 0x9031), USB_DEVICE_DATA(&rt2800usb_ops) },
2897 { USB_DEVICE(0x0e0b, 0x9041), USB_DEVICE_DATA(&rt2800usb_ops) },
2898 /* Amit */
2899 { USB_DEVICE(0x15c5, 0x0008), USB_DEVICE_DATA(&rt2800usb_ops) },
2900 /* ASUS */
2901 { USB_DEVICE(0x0b05, 0x1731), USB_DEVICE_DATA(&rt2800usb_ops) },
2902 { USB_DEVICE(0x0b05, 0x1732), USB_DEVICE_DATA(&rt2800usb_ops) },
2903 { USB_DEVICE(0x0b05, 0x1742), USB_DEVICE_DATA(&rt2800usb_ops) },
2904 { USB_DEVICE(0x0b05, 0x1760), USB_DEVICE_DATA(&rt2800usb_ops) },
2905 { USB_DEVICE(0x0b05, 0x1761), USB_DEVICE_DATA(&rt2800usb_ops) },
2906 /* AzureWave */
2907 { USB_DEVICE(0x13d3, 0x3247), USB_DEVICE_DATA(&rt2800usb_ops) },
2908 { USB_DEVICE(0x13d3, 0x3262), USB_DEVICE_DATA(&rt2800usb_ops) },
2909 { USB_DEVICE(0x13d3, 0x3273), USB_DEVICE_DATA(&rt2800usb_ops) },
2910 { USB_DEVICE(0x13d3, 0x3284), USB_DEVICE_DATA(&rt2800usb_ops) },
2911 /* Belkin */
2912 { USB_DEVICE(0x050d, 0x8053), USB_DEVICE_DATA(&rt2800usb_ops) },
2913 { USB_DEVICE(0x050d, 0x805c), USB_DEVICE_DATA(&rt2800usb_ops) },
2914 { USB_DEVICE(0x050d, 0x815c), USB_DEVICE_DATA(&rt2800usb_ops) },
2915 /* Buffalo */
2916 { USB_DEVICE(0x0411, 0x00e8), USB_DEVICE_DATA(&rt2800usb_ops) },
2917 { USB_DEVICE(0x0411, 0x012e), USB_DEVICE_DATA(&rt2800usb_ops) },
2918 /* Conceptronic */
2919 { USB_DEVICE(0x14b2, 0x3c06), USB_DEVICE_DATA(&rt2800usb_ops) },
2920 { USB_DEVICE(0x14b2, 0x3c07), USB_DEVICE_DATA(&rt2800usb_ops) },
2921 { USB_DEVICE(0x14b2, 0x3c08), USB_DEVICE_DATA(&rt2800usb_ops) },
2922 { USB_DEVICE(0x14b2, 0x3c09), USB_DEVICE_DATA(&rt2800usb_ops) },
2923 { USB_DEVICE(0x14b2, 0x3c11), USB_DEVICE_DATA(&rt2800usb_ops) },
2924 { USB_DEVICE(0x14b2, 0x3c12), USB_DEVICE_DATA(&rt2800usb_ops) },
2925 { USB_DEVICE(0x14b2, 0x3c23), USB_DEVICE_DATA(&rt2800usb_ops) },
2926 { USB_DEVICE(0x14b2, 0x3c25), USB_DEVICE_DATA(&rt2800usb_ops) },
2927 { USB_DEVICE(0x14b2, 0x3c27), USB_DEVICE_DATA(&rt2800usb_ops) },
2928 { USB_DEVICE(0x14b2, 0x3c28), USB_DEVICE_DATA(&rt2800usb_ops) },
2929 /* Corega */
2930 { USB_DEVICE(0x07aa, 0x002f), USB_DEVICE_DATA(&rt2800usb_ops) },
2931 { USB_DEVICE(0x07aa, 0x003c), USB_DEVICE_DATA(&rt2800usb_ops) },
2932 { USB_DEVICE(0x07aa, 0x003f), USB_DEVICE_DATA(&rt2800usb_ops) },
2933 { USB_DEVICE(0x18c5, 0x0008), USB_DEVICE_DATA(&rt2800usb_ops) },
2934 { USB_DEVICE(0x18c5, 0x0012), USB_DEVICE_DATA(&rt2800usb_ops) },
2935 /* D-Link */
2936 { USB_DEVICE(0x07d1, 0x3c09), USB_DEVICE_DATA(&rt2800usb_ops) },
2937 { USB_DEVICE(0x07d1, 0x3c0a), USB_DEVICE_DATA(&rt2800usb_ops) },
2938 { USB_DEVICE(0x07d1, 0x3c0b), USB_DEVICE_DATA(&rt2800usb_ops) },
2939 { USB_DEVICE(0x07d1, 0x3c11), USB_DEVICE_DATA(&rt2800usb_ops) },
2940 { USB_DEVICE(0x07d1, 0x3c13), USB_DEVICE_DATA(&rt2800usb_ops) },
2941 /* Edimax */
2942 { USB_DEVICE(0x7392, 0x7711), USB_DEVICE_DATA(&rt2800usb_ops) },
2943 { USB_DEVICE(0x7392, 0x7717), USB_DEVICE_DATA(&rt2800usb_ops) },
2944 { USB_DEVICE(0x7392, 0x7718), USB_DEVICE_DATA(&rt2800usb_ops) },
2945 /* EnGenius */
2946 { USB_DEVICE(0X1740, 0x9701), USB_DEVICE_DATA(&rt2800usb_ops) },
2947 { USB_DEVICE(0x1740, 0x9702), USB_DEVICE_DATA(&rt2800usb_ops) },
2948 { USB_DEVICE(0x1740, 0x9703), USB_DEVICE_DATA(&rt2800usb_ops) },
2949 { USB_DEVICE(0x1740, 0x9705), USB_DEVICE_DATA(&rt2800usb_ops) },
2950 { USB_DEVICE(0x1740, 0x9706), USB_DEVICE_DATA(&rt2800usb_ops) },
2951 { USB_DEVICE(0x1740, 0x9801), USB_DEVICE_DATA(&rt2800usb_ops) },
2952 /* Gemtek */
2953 { USB_DEVICE(0x15a9, 0x0010), USB_DEVICE_DATA(&rt2800usb_ops) },
2954 /* Gigabyte */
2955 { USB_DEVICE(0x1044, 0x800b), USB_DEVICE_DATA(&rt2800usb_ops) },
2956 { USB_DEVICE(0x1044, 0x800c), USB_DEVICE_DATA(&rt2800usb_ops) },
2957 { USB_DEVICE(0x1044, 0x800d), USB_DEVICE_DATA(&rt2800usb_ops) },
2958 /* Hawking */
2959 { USB_DEVICE(0x0e66, 0x0001), USB_DEVICE_DATA(&rt2800usb_ops) },
2960 { USB_DEVICE(0x0e66, 0x0003), USB_DEVICE_DATA(&rt2800usb_ops) },
2961 { USB_DEVICE(0x0e66, 0x0009), USB_DEVICE_DATA(&rt2800usb_ops) },
2962 { USB_DEVICE(0x0e66, 0x000b), USB_DEVICE_DATA(&rt2800usb_ops) },
2963 /* LevelOne */
2964 { USB_DEVICE(0x1740, 0x0605), USB_DEVICE_DATA(&rt2800usb_ops) },
2965 { USB_DEVICE(0x1740, 0x0615), USB_DEVICE_DATA(&rt2800usb_ops) },
2966 /* Linksys */
2967 { USB_DEVICE(0x1737, 0x0070), USB_DEVICE_DATA(&rt2800usb_ops) },
2968 { USB_DEVICE(0x1737, 0x0071), USB_DEVICE_DATA(&rt2800usb_ops) },
2969 { USB_DEVICE(0x1737, 0x0077), USB_DEVICE_DATA(&rt2800usb_ops) },
2970 /* Logitec */
2971 { USB_DEVICE(0x0789, 0x0162), USB_DEVICE_DATA(&rt2800usb_ops) },
2972 { USB_DEVICE(0x0789, 0x0163), USB_DEVICE_DATA(&rt2800usb_ops) },
2973 { USB_DEVICE(0x0789, 0x0164), USB_DEVICE_DATA(&rt2800usb_ops) },
2974 /* Motorola */
2975 { USB_DEVICE(0x100d, 0x9031), USB_DEVICE_DATA(&rt2800usb_ops) },
2976 { USB_DEVICE(0x100d, 0x9032), USB_DEVICE_DATA(&rt2800usb_ops) },
2977 /* Ovislink */
2978 { USB_DEVICE(0x1b75, 0x3072), USB_DEVICE_DATA(&rt2800usb_ops) },
2979 /* Pegatron */
2980 { USB_DEVICE(0x1d4d, 0x0002), USB_DEVICE_DATA(&rt2800usb_ops) },
2981 { USB_DEVICE(0x1d4d, 0x000c), USB_DEVICE_DATA(&rt2800usb_ops) },
2982 /* Philips */
2983 { USB_DEVICE(0x0471, 0x200f), USB_DEVICE_DATA(&rt2800usb_ops) },
2984 /* Planex */
2985 { USB_DEVICE(0x2019, 0xed06), USB_DEVICE_DATA(&rt2800usb_ops) },
2986 { USB_DEVICE(0x2019, 0xab24), USB_DEVICE_DATA(&rt2800usb_ops) },
2987 { USB_DEVICE(0x2019, 0xab25), USB_DEVICE_DATA(&rt2800usb_ops) },
2988 /* Qcom */
2989 { USB_DEVICE(0x18e8, 0x6259), USB_DEVICE_DATA(&rt2800usb_ops) },
2990 /* Quanta */
2991 { USB_DEVICE(0x1a32, 0x0304), USB_DEVICE_DATA(&rt2800usb_ops) },
2992 /* Ralink */
2993 { USB_DEVICE(0x0db0, 0x6899), USB_DEVICE_DATA(&rt2800usb_ops) },
2994 { USB_DEVICE(0x148f, 0x2070), USB_DEVICE_DATA(&rt2800usb_ops) },
2995 { USB_DEVICE(0x148f, 0x2770), USB_DEVICE_DATA(&rt2800usb_ops) },
2996 { USB_DEVICE(0x148f, 0x2870), USB_DEVICE_DATA(&rt2800usb_ops) },
2997 { USB_DEVICE(0x148f, 0x3070), USB_DEVICE_DATA(&rt2800usb_ops) },
2998 { USB_DEVICE(0x148f, 0x3071), USB_DEVICE_DATA(&rt2800usb_ops) },
2999 { USB_DEVICE(0x148f, 0x3072), USB_DEVICE_DATA(&rt2800usb_ops) },
3000 { USB_DEVICE(0x148f, 0x3572), USB_DEVICE_DATA(&rt2800usb_ops) },
3001 /* Samsung */
3002 { USB_DEVICE(0x04e8, 0x2018), USB_DEVICE_DATA(&rt2800usb_ops) },
3003 /* Siemens */
3004 { USB_DEVICE(0x129b, 0x1828), USB_DEVICE_DATA(&rt2800usb_ops) },
3005 /* Sitecom */
3006 { USB_DEVICE(0x0df6, 0x0017), USB_DEVICE_DATA(&rt2800usb_ops) },
3007 { USB_DEVICE(0x0df6, 0x002b), USB_DEVICE_DATA(&rt2800usb_ops) },
3008 { USB_DEVICE(0x0df6, 0x002c), USB_DEVICE_DATA(&rt2800usb_ops) },
3009 { USB_DEVICE(0x0df6, 0x002d), USB_DEVICE_DATA(&rt2800usb_ops) },
3010 { USB_DEVICE(0x0df6, 0x0039), USB_DEVICE_DATA(&rt2800usb_ops) },
3011 { USB_DEVICE(0x0df6, 0x003b), USB_DEVICE_DATA(&rt2800usb_ops) },
3012 { USB_DEVICE(0x0df6, 0x003c), USB_DEVICE_DATA(&rt2800usb_ops) },
3013 { USB_DEVICE(0x0df6, 0x003d), USB_DEVICE_DATA(&rt2800usb_ops) },
3014 { USB_DEVICE(0x0df6, 0x003e), USB_DEVICE_DATA(&rt2800usb_ops) },
3015 { USB_DEVICE(0x0df6, 0x003f), USB_DEVICE_DATA(&rt2800usb_ops) },
3016 { USB_DEVICE(0x0df6, 0x0040), USB_DEVICE_DATA(&rt2800usb_ops) },
3017 /* SMC */
3018 { USB_DEVICE(0x083a, 0x6618), USB_DEVICE_DATA(&rt2800usb_ops) },
3019 { USB_DEVICE(0x083a, 0x7511), USB_DEVICE_DATA(&rt2800usb_ops) },
3020 { USB_DEVICE(0x083a, 0x7512), USB_DEVICE_DATA(&rt2800usb_ops) },
3021 { USB_DEVICE(0x083a, 0x7522), USB_DEVICE_DATA(&rt2800usb_ops) },
3022 { USB_DEVICE(0x083a, 0x8522), USB_DEVICE_DATA(&rt2800usb_ops) },
3023 { USB_DEVICE(0x083a, 0xa512), USB_DEVICE_DATA(&rt2800usb_ops) },
3024 { USB_DEVICE(0x083a, 0xa618), USB_DEVICE_DATA(&rt2800usb_ops) },
3025 { USB_DEVICE(0x083a, 0xb522), USB_DEVICE_DATA(&rt2800usb_ops) },
3026 { USB_DEVICE(0x083a, 0xc522), USB_DEVICE_DATA(&rt2800usb_ops) },
3027 /* Sparklan */
3028 { USB_DEVICE(0x15a9, 0x0006), USB_DEVICE_DATA(&rt2800usb_ops) },
3029 /* U-Media*/
3030 { USB_DEVICE(0x157e, 0x300e), USB_DEVICE_DATA(&rt2800usb_ops) },
3031 /* ZCOM */
3032 { USB_DEVICE(0x0cde, 0x0022), USB_DEVICE_DATA(&rt2800usb_ops) },
3033 { USB_DEVICE(0x0cde, 0x0025), USB_DEVICE_DATA(&rt2800usb_ops) },
3034 /* Zinwell */
3035 { USB_DEVICE(0x5a57, 0x0280), USB_DEVICE_DATA(&rt2800usb_ops) },
3036 { USB_DEVICE(0x5a57, 0x0282), USB_DEVICE_DATA(&rt2800usb_ops) },
3037 /* Zyxel */
3038 { USB_DEVICE(0x0586, 0x3416), USB_DEVICE_DATA(&rt2800usb_ops) },
3039 { USB_DEVICE(0x0586, 0x341a), USB_DEVICE_DATA(&rt2800usb_ops) },
3040 { 0, }
3041};
3042
3043MODULE_AUTHOR(DRV_PROJECT);
3044MODULE_VERSION(DRV_VERSION);
3045MODULE_DESCRIPTION("Ralink RT2800 USB Wireless LAN driver.");
3046MODULE_SUPPORTED_DEVICE("Ralink RT2870 USB chipset based cards");
3047MODULE_DEVICE_TABLE(usb, rt2800usb_device_table);
3048MODULE_FIRMWARE(FIRMWARE_RT2870);
3049MODULE_LICENSE("GPL");
3050
3051static struct usb_driver rt2800usb_driver = {
3052 .name = KBUILD_MODNAME,
3053 .id_table = rt2800usb_device_table,
3054 .probe = rt2x00usb_probe,
3055 .disconnect = rt2x00usb_disconnect,
3056 .suspend = rt2x00usb_suspend,
3057 .resume = rt2x00usb_resume,
3058};
3059
3060static int __init rt2800usb_init(void)
3061{
3062 return usb_register(&rt2800usb_driver);
3063}
3064
3065static void __exit rt2800usb_exit(void)
3066{
3067 usb_deregister(&rt2800usb_driver);
3068}
3069
3070module_init(rt2800usb_init);
3071module_exit(rt2800usb_exit);
diff --git a/drivers/net/wireless/rt2x00/rt2800usb.h b/drivers/net/wireless/rt2x00/rt2800usb.h
new file mode 100644
index 000000000000..61a8be61d3f5
--- /dev/null
+++ b/drivers/net/wireless/rt2x00/rt2800usb.h
@@ -0,0 +1,1945 @@
1/*
2 Copyright (C) 2004 - 2009 rt2x00 SourceForge Project
3 <http://rt2x00.serialmonkey.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the
17 Free Software Foundation, Inc.,
18 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21/*
22 Module: rt2800usb
23 Abstract: Data structures and registers for the rt2800usb module.
24 Supported chipsets: RT2800U.
25 */
26
27#ifndef RT2800USB_H
28#define RT2800USB_H
29
30/*
31 * RF chip defines.
32 *
33 * RF2820 2.4G 2T3R
34 * RF2850 2.4G/5G 2T3R
35 * RF2720 2.4G 1T2R
36 * RF2750 2.4G/5G 1T2R
37 * RF3020 2.4G 1T1R
38 * RF2020 2.4G B/G
39 */
40#define RF2820 0x0001
41#define RF2850 0x0002
42#define RF2720 0x0003
43#define RF2750 0x0004
44#define RF3020 0x0005
45#define RF2020 0x0006
46
47/*
48 * RT2870 version
49 */
50#define RT2860C_VERSION 0x28600100
51#define RT2860D_VERSION 0x28600101
52#define RT2880E_VERSION 0x28720200
53#define RT2883_VERSION 0x28830300
54#define RT3070_VERSION 0x30700200
55
56/*
57 * Signal information.
58 * Defaul offset is required for RSSI <-> dBm conversion.
59 */
60#define DEFAULT_RSSI_OFFSET 120 /* FIXME */
61
62/*
63 * Register layout information.
64 */
65#define CSR_REG_BASE 0x1000
66#define CSR_REG_SIZE 0x0800
67#define EEPROM_BASE 0x0000
68#define EEPROM_SIZE 0x0110
69#define BBP_BASE 0x0000
70#define BBP_SIZE 0x0080
71#define RF_BASE 0x0004
72#define RF_SIZE 0x0010
73
74/*
75 * Number of TX queues.
76 */
77#define NUM_TX_QUEUES 4
78
79/*
80 * USB registers.
81 */
82
83/*
84 * HOST-MCU shared memory
85 */
86#define HOST_CMD_CSR 0x0404
87#define HOST_CMD_CSR_HOST_COMMAND FIELD32(0x000000ff)
88
89/*
90 * INT_SOURCE_CSR: Interrupt source register.
91 * Write one to clear corresponding bit.
92 * TX_FIFO_STATUS: FIFO Statistics is full, sw should read 0x171c
93 */
94#define INT_SOURCE_CSR 0x0200
95#define INT_SOURCE_CSR_RXDELAYINT FIELD32(0x00000001)
96#define INT_SOURCE_CSR_TXDELAYINT FIELD32(0x00000002)
97#define INT_SOURCE_CSR_RX_DONE FIELD32(0x00000004)
98#define INT_SOURCE_CSR_AC0_DMA_DONE FIELD32(0x00000008)
99#define INT_SOURCE_CSR_AC1_DMA_DONE FIELD32(0x00000010)
100#define INT_SOURCE_CSR_AC2_DMA_DONE FIELD32(0x00000020)
101#define INT_SOURCE_CSR_AC3_DMA_DONE FIELD32(0x00000040)
102#define INT_SOURCE_CSR_HCCA_DMA_DONE FIELD32(0x00000080)
103#define INT_SOURCE_CSR_MGMT_DMA_DONE FIELD32(0x00000100)
104#define INT_SOURCE_CSR_MCU_COMMAND FIELD32(0x00000200)
105#define INT_SOURCE_CSR_RXTX_COHERENT FIELD32(0x00000400)
106#define INT_SOURCE_CSR_TBTT FIELD32(0x00000800)
107#define INT_SOURCE_CSR_PRE_TBTT FIELD32(0x00001000)
108#define INT_SOURCE_CSR_TX_FIFO_STATUS FIELD32(0x00002000)
109#define INT_SOURCE_CSR_AUTO_WAKEUP FIELD32(0x00004000)
110#define INT_SOURCE_CSR_GPTIMER FIELD32(0x00008000)
111#define INT_SOURCE_CSR_RX_COHERENT FIELD32(0x00010000)
112#define INT_SOURCE_CSR_TX_COHERENT FIELD32(0x00020000)
113
114/*
115 * INT_MASK_CSR: Interrupt MASK register. 1: the interrupt is mask OFF.
116 */
117#define INT_MASK_CSR 0x0204
118#define INT_MASK_CSR_RXDELAYINT FIELD32(0x00000001)
119#define INT_MASK_CSR_TXDELAYINT FIELD32(0x00000002)
120#define INT_MASK_CSR_RX_DONE FIELD32(0x00000004)
121#define INT_MASK_CSR_AC0_DMA_DONE FIELD32(0x00000008)
122#define INT_MASK_CSR_AC1_DMA_DONE FIELD32(0x00000010)
123#define INT_MASK_CSR_AC2_DMA_DONE FIELD32(0x00000020)
124#define INT_MASK_CSR_AC3_DMA_DONE FIELD32(0x00000040)
125#define INT_MASK_CSR_HCCA_DMA_DONE FIELD32(0x00000080)
126#define INT_MASK_CSR_MGMT_DMA_DONE FIELD32(0x00000100)
127#define INT_MASK_CSR_MCU_COMMAND FIELD32(0x00000200)
128#define INT_MASK_CSR_RXTX_COHERENT FIELD32(0x00000400)
129#define INT_MASK_CSR_TBTT FIELD32(0x00000800)
130#define INT_MASK_CSR_PRE_TBTT FIELD32(0x00001000)
131#define INT_MASK_CSR_TX_FIFO_STATUS FIELD32(0x00002000)
132#define INT_MASK_CSR_AUTO_WAKEUP FIELD32(0x00004000)
133#define INT_MASK_CSR_GPTIMER FIELD32(0x00008000)
134#define INT_MASK_CSR_RX_COHERENT FIELD32(0x00010000)
135#define INT_MASK_CSR_TX_COHERENT FIELD32(0x00020000)
136
137/*
138 * WPDMA_GLO_CFG
139 */
140#define WPDMA_GLO_CFG 0x0208
141#define WPDMA_GLO_CFG_ENABLE_TX_DMA FIELD32(0x00000001)
142#define WPDMA_GLO_CFG_TX_DMA_BUSY FIELD32(0x00000002)
143#define WPDMA_GLO_CFG_ENABLE_RX_DMA FIELD32(0x00000004)
144#define WPDMA_GLO_CFG_RX_DMA_BUSY FIELD32(0x00000008)
145#define WPDMA_GLO_CFG_WP_DMA_BURST_SIZE FIELD32(0x00000030)
146#define WPDMA_GLO_CFG_TX_WRITEBACK_DONE FIELD32(0x00000040)
147#define WPDMA_GLO_CFG_BIG_ENDIAN FIELD32(0x00000080)
148#define WPDMA_GLO_CFG_RX_HDR_SCATTER FIELD32(0x0000ff00)
149#define WPDMA_GLO_CFG_HDR_SEG_LEN FIELD32(0xffff0000)
150
151/*
152 * WPDMA_RST_IDX
153 */
154#define WPDMA_RST_IDX 0x020c
155#define WPDMA_RST_IDX_DTX_IDX0 FIELD32(0x00000001)
156#define WPDMA_RST_IDX_DTX_IDX1 FIELD32(0x00000002)
157#define WPDMA_RST_IDX_DTX_IDX2 FIELD32(0x00000004)
158#define WPDMA_RST_IDX_DTX_IDX3 FIELD32(0x00000008)
159#define WPDMA_RST_IDX_DTX_IDX4 FIELD32(0x00000010)
160#define WPDMA_RST_IDX_DTX_IDX5 FIELD32(0x00000020)
161#define WPDMA_RST_IDX_DRX_IDX0 FIELD32(0x00010000)
162
163/*
164 * DELAY_INT_CFG
165 */
166#define DELAY_INT_CFG 0x0210
167#define DELAY_INT_CFG_RXMAX_PTIME FIELD32(0x000000ff)
168#define DELAY_INT_CFG_RXMAX_PINT FIELD32(0x00007f00)
169#define DELAY_INT_CFG_RXDLY_INT_EN FIELD32(0x00008000)
170#define DELAY_INT_CFG_TXMAX_PTIME FIELD32(0x00ff0000)
171#define DELAY_INT_CFG_TXMAX_PINT FIELD32(0x7f000000)
172#define DELAY_INT_CFG_TXDLY_INT_EN FIELD32(0x80000000)
173
174/*
175 * WMM_AIFSN_CFG: Aifsn for each EDCA AC
176 * AIFSN0: AC_BE
177 * AIFSN1: AC_BK
178 * AIFSN1: AC_VI
179 * AIFSN1: AC_VO
180 */
181#define WMM_AIFSN_CFG 0x0214
182#define WMM_AIFSN_CFG_AIFSN0 FIELD32(0x0000000f)
183#define WMM_AIFSN_CFG_AIFSN1 FIELD32(0x000000f0)
184#define WMM_AIFSN_CFG_AIFSN2 FIELD32(0x00000f00)
185#define WMM_AIFSN_CFG_AIFSN3 FIELD32(0x0000f000)
186
187/*
188 * WMM_CWMIN_CSR: CWmin for each EDCA AC
189 * CWMIN0: AC_BE
190 * CWMIN1: AC_BK
191 * CWMIN1: AC_VI
192 * CWMIN1: AC_VO
193 */
194#define WMM_CWMIN_CFG 0x0218
195#define WMM_CWMIN_CFG_CWMIN0 FIELD32(0x0000000f)
196#define WMM_CWMIN_CFG_CWMIN1 FIELD32(0x000000f0)
197#define WMM_CWMIN_CFG_CWMIN2 FIELD32(0x00000f00)
198#define WMM_CWMIN_CFG_CWMIN3 FIELD32(0x0000f000)
199
200/*
201 * WMM_CWMAX_CSR: CWmax for each EDCA AC
202 * CWMAX0: AC_BE
203 * CWMAX1: AC_BK
204 * CWMAX1: AC_VI
205 * CWMAX1: AC_VO
206 */
207#define WMM_CWMAX_CFG 0x021c
208#define WMM_CWMAX_CFG_CWMAX0 FIELD32(0x0000000f)
209#define WMM_CWMAX_CFG_CWMAX1 FIELD32(0x000000f0)
210#define WMM_CWMAX_CFG_CWMAX2 FIELD32(0x00000f00)
211#define WMM_CWMAX_CFG_CWMAX3 FIELD32(0x0000f000)
212
213/*
214 * AC_TXOP0: AC_BK/AC_BE TXOP register
215 * AC0TXOP: AC_BK in unit of 32us
216 * AC1TXOP: AC_BE in unit of 32us
217 */
218#define WMM_TXOP0_CFG 0x0220
219#define WMM_TXOP0_CFG_AC0TXOP FIELD32(0x0000ffff)
220#define WMM_TXOP0_CFG_AC1TXOP FIELD32(0xffff0000)
221
222/*
223 * AC_TXOP1: AC_VO/AC_VI TXOP register
224 * AC2TXOP: AC_VI in unit of 32us
225 * AC3TXOP: AC_VO in unit of 32us
226 */
227#define WMM_TXOP1_CFG 0x0224
228#define WMM_TXOP1_CFG_AC2TXOP FIELD32(0x0000ffff)
229#define WMM_TXOP1_CFG_AC3TXOP FIELD32(0xffff0000)
230
231/*
232 * GPIO_CTRL_CFG:
233 */
234#define GPIO_CTRL_CFG 0x0228
235#define GPIO_CTRL_CFG_BIT0 FIELD32(0x00000001)
236#define GPIO_CTRL_CFG_BIT1 FIELD32(0x00000002)
237#define GPIO_CTRL_CFG_BIT2 FIELD32(0x00000004)
238#define GPIO_CTRL_CFG_BIT3 FIELD32(0x00000008)
239#define GPIO_CTRL_CFG_BIT4 FIELD32(0x00000010)
240#define GPIO_CTRL_CFG_BIT5 FIELD32(0x00000020)
241#define GPIO_CTRL_CFG_BIT6 FIELD32(0x00000040)
242#define GPIO_CTRL_CFG_BIT7 FIELD32(0x00000080)
243#define GPIO_CTRL_CFG_BIT8 FIELD32(0x00000100)
244
245/*
246 * MCU_CMD_CFG
247 */
248#define MCU_CMD_CFG 0x022c
249
250/*
251 * AC_BK register offsets
252 */
253#define TX_BASE_PTR0 0x0230
254#define TX_MAX_CNT0 0x0234
255#define TX_CTX_IDX0 0x0238
256#define TX_DTX_IDX0 0x023c
257
258/*
259 * AC_BE register offsets
260 */
261#define TX_BASE_PTR1 0x0240
262#define TX_MAX_CNT1 0x0244
263#define TX_CTX_IDX1 0x0248
264#define TX_DTX_IDX1 0x024c
265
266/*
267 * AC_VI register offsets
268 */
269#define TX_BASE_PTR2 0x0250
270#define TX_MAX_CNT2 0x0254
271#define TX_CTX_IDX2 0x0258
272#define TX_DTX_IDX2 0x025c
273
274/*
275 * AC_VO register offsets
276 */
277#define TX_BASE_PTR3 0x0260
278#define TX_MAX_CNT3 0x0264
279#define TX_CTX_IDX3 0x0268
280#define TX_DTX_IDX3 0x026c
281
282/*
283 * HCCA register offsets
284 */
285#define TX_BASE_PTR4 0x0270
286#define TX_MAX_CNT4 0x0274
287#define TX_CTX_IDX4 0x0278
288#define TX_DTX_IDX4 0x027c
289
290/*
291 * MGMT register offsets
292 */
293#define TX_BASE_PTR5 0x0280
294#define TX_MAX_CNT5 0x0284
295#define TX_CTX_IDX5 0x0288
296#define TX_DTX_IDX5 0x028c
297
298/*
299 * RX register offsets
300 */
301#define RX_BASE_PTR 0x0290
302#define RX_MAX_CNT 0x0294
303#define RX_CRX_IDX 0x0298
304#define RX_DRX_IDX 0x029c
305
306/*
307 * USB_DMA_CFG
308 * RX_BULK_AGG_TIMEOUT: Rx Bulk Aggregation TimeOut in unit of 33ns.
309 * RX_BULK_AGG_LIMIT: Rx Bulk Aggregation Limit in unit of 256 bytes.
310 * PHY_CLEAR: phy watch dog enable.
311 * TX_CLEAR: Clear USB DMA TX path.
312 * TXOP_HALT: Halt TXOP count down when TX buffer is full.
313 * RX_BULK_AGG_EN: Enable Rx Bulk Aggregation.
314 * RX_BULK_EN: Enable USB DMA Rx.
315 * TX_BULK_EN: Enable USB DMA Tx.
316 * EP_OUT_VALID: OUT endpoint data valid.
317 * RX_BUSY: USB DMA RX FSM busy.
318 * TX_BUSY: USB DMA TX FSM busy.
319 */
320#define USB_DMA_CFG 0x02a0
321#define USB_DMA_CFG_RX_BULK_AGG_TIMEOUT FIELD32(0x000000ff)
322#define USB_DMA_CFG_RX_BULK_AGG_LIMIT FIELD32(0x0000ff00)
323#define USB_DMA_CFG_PHY_CLEAR FIELD32(0x00010000)
324#define USB_DMA_CFG_TX_CLEAR FIELD32(0x00080000)
325#define USB_DMA_CFG_TXOP_HALT FIELD32(0x00100000)
326#define USB_DMA_CFG_RX_BULK_AGG_EN FIELD32(0x00200000)
327#define USB_DMA_CFG_RX_BULK_EN FIELD32(0x00400000)
328#define USB_DMA_CFG_TX_BULK_EN FIELD32(0x00800000)
329#define USB_DMA_CFG_EP_OUT_VALID FIELD32(0x3f000000)
330#define USB_DMA_CFG_RX_BUSY FIELD32(0x40000000)
331#define USB_DMA_CFG_TX_BUSY FIELD32(0x80000000)
332
333/*
334 * USB_CYC_CFG
335 */
336#define USB_CYC_CFG 0x02a4
337#define USB_CYC_CFG_CLOCK_CYCLE FIELD32(0x000000ff)
338
339/*
340 * PBF_SYS_CTRL
341 * HOST_RAM_WRITE: enable Host program ram write selection
342 */
343#define PBF_SYS_CTRL 0x0400
344#define PBF_SYS_CTRL_READY FIELD32(0x00000080)
345#define PBF_SYS_CTRL_HOST_RAM_WRITE FIELD32(0x00010000)
346
347/*
348 * PBF registers
349 * Most are for debug. Driver doesn't touch PBF register.
350 */
351#define PBF_CFG 0x0408
352#define PBF_MAX_PCNT 0x040c
353#define PBF_CTRL 0x0410
354#define PBF_INT_STA 0x0414
355#define PBF_INT_ENA 0x0418
356
357/*
358 * BCN_OFFSET0:
359 */
360#define BCN_OFFSET0 0x042c
361#define BCN_OFFSET0_BCN0 FIELD32(0x000000ff)
362#define BCN_OFFSET0_BCN1 FIELD32(0x0000ff00)
363#define BCN_OFFSET0_BCN2 FIELD32(0x00ff0000)
364#define BCN_OFFSET0_BCN3 FIELD32(0xff000000)
365
366/*
367 * BCN_OFFSET1:
368 */
369#define BCN_OFFSET1 0x0430
370#define BCN_OFFSET1_BCN4 FIELD32(0x000000ff)
371#define BCN_OFFSET1_BCN5 FIELD32(0x0000ff00)
372#define BCN_OFFSET1_BCN6 FIELD32(0x00ff0000)
373#define BCN_OFFSET1_BCN7 FIELD32(0xff000000)
374
375/*
376 * PBF registers
377 * Most are for debug. Driver doesn't touch PBF register.
378 */
379#define TXRXQ_PCNT 0x0438
380#define PBF_DBG 0x043c
381
382/*
383 * RF registers
384 */
385#define RF_CSR_CFG 0x0500
386#define RF_CSR_CFG_DATA FIELD32(0x000000ff)
387#define RF_CSR_CFG_REGNUM FIELD32(0x00001f00)
388#define RF_CSR_CFG_WRITE FIELD32(0x00010000)
389#define RF_CSR_CFG_BUSY FIELD32(0x00020000)
390
391/*
392 * MAC Control/Status Registers(CSR).
393 * Some values are set in TU, whereas 1 TU == 1024 us.
394 */
395
396/*
397 * MAC_CSR0: ASIC revision number.
398 * ASIC_REV: 0
399 * ASIC_VER: 2870
400 */
401#define MAC_CSR0 0x1000
402#define MAC_CSR0_ASIC_REV FIELD32(0x0000ffff)
403#define MAC_CSR0_ASIC_VER FIELD32(0xffff0000)
404
405/*
406 * MAC_SYS_CTRL:
407 */
408#define MAC_SYS_CTRL 0x1004
409#define MAC_SYS_CTRL_RESET_CSR FIELD32(0x00000001)
410#define MAC_SYS_CTRL_RESET_BBP FIELD32(0x00000002)
411#define MAC_SYS_CTRL_ENABLE_TX FIELD32(0x00000004)
412#define MAC_SYS_CTRL_ENABLE_RX FIELD32(0x00000008)
413#define MAC_SYS_CTRL_CONTINUOUS_TX FIELD32(0x00000010)
414#define MAC_SYS_CTRL_LOOPBACK FIELD32(0x00000020)
415#define MAC_SYS_CTRL_WLAN_HALT FIELD32(0x00000040)
416#define MAC_SYS_CTRL_RX_TIMESTAMP FIELD32(0x00000080)
417
418/*
419 * MAC_ADDR_DW0: STA MAC register 0
420 */
421#define MAC_ADDR_DW0 0x1008
422#define MAC_ADDR_DW0_BYTE0 FIELD32(0x000000ff)
423#define MAC_ADDR_DW0_BYTE1 FIELD32(0x0000ff00)
424#define MAC_ADDR_DW0_BYTE2 FIELD32(0x00ff0000)
425#define MAC_ADDR_DW0_BYTE3 FIELD32(0xff000000)
426
427/*
428 * MAC_ADDR_DW1: STA MAC register 1
429 * UNICAST_TO_ME_MASK:
430 * Used to mask off bits from byte 5 of the MAC address
431 * to determine the UNICAST_TO_ME bit for RX frames.
432 * The full mask is complemented by BSS_ID_MASK:
433 * MASK = BSS_ID_MASK & UNICAST_TO_ME_MASK
434 */
435#define MAC_ADDR_DW1 0x100c
436#define MAC_ADDR_DW1_BYTE4 FIELD32(0x000000ff)
437#define MAC_ADDR_DW1_BYTE5 FIELD32(0x0000ff00)
438#define MAC_ADDR_DW1_UNICAST_TO_ME_MASK FIELD32(0x00ff0000)
439
440/*
441 * MAC_BSSID_DW0: BSSID register 0
442 */
443#define MAC_BSSID_DW0 0x1010
444#define MAC_BSSID_DW0_BYTE0 FIELD32(0x000000ff)
445#define MAC_BSSID_DW0_BYTE1 FIELD32(0x0000ff00)
446#define MAC_BSSID_DW0_BYTE2 FIELD32(0x00ff0000)
447#define MAC_BSSID_DW0_BYTE3 FIELD32(0xff000000)
448
449/*
450 * MAC_BSSID_DW1: BSSID register 1
451 * BSS_ID_MASK:
452 * 0: 1-BSSID mode (BSS index = 0)
453 * 1: 2-BSSID mode (BSS index: Byte5, bit 0)
454 * 2: 4-BSSID mode (BSS index: byte5, bit 0 - 1)
455 * 3: 8-BSSID mode (BSS index: byte5, bit 0 - 2)
456 * This mask is used to mask off bits 0, 1 and 2 of byte 5 of the
457 * BSSID. This will make sure that those bits will be ignored
458 * when determining the MY_BSS of RX frames.
459 */
460#define MAC_BSSID_DW1 0x1014
461#define MAC_BSSID_DW1_BYTE4 FIELD32(0x000000ff)
462#define MAC_BSSID_DW1_BYTE5 FIELD32(0x0000ff00)
463#define MAC_BSSID_DW1_BSS_ID_MASK FIELD32(0x00030000)
464#define MAC_BSSID_DW1_BSS_BCN_NUM FIELD32(0x001c0000)
465
466/*
467 * MAX_LEN_CFG: Maximum frame length register.
468 * MAX_MPDU: rt2860b max 16k bytes
469 * MAX_PSDU: Maximum PSDU length
470 * (power factor) 0:2^13, 1:2^14, 2:2^15, 3:2^16
471 */
472#define MAX_LEN_CFG 0x1018
473#define MAX_LEN_CFG_MAX_MPDU FIELD32(0x00000fff)
474#define MAX_LEN_CFG_MAX_PSDU FIELD32(0x00003000)
475#define MAX_LEN_CFG_MIN_PSDU FIELD32(0x0000c000)
476#define MAX_LEN_CFG_MIN_MPDU FIELD32(0x000f0000)
477
478/*
479 * BBP_CSR_CFG: BBP serial control register
480 * VALUE: Register value to program into BBP
481 * REG_NUM: Selected BBP register
482 * READ_CONTROL: 0 write BBP, 1 read BBP
483 * BUSY: ASIC is busy executing BBP commands
484 * BBP_PAR_DUR: 0 4 MAC clocks, 1 8 MAC clocks
485 * BBP_RW_MODE: 0 serial, 1 paralell
486 */
487#define BBP_CSR_CFG 0x101c
488#define BBP_CSR_CFG_VALUE FIELD32(0x000000ff)
489#define BBP_CSR_CFG_REGNUM FIELD32(0x0000ff00)
490#define BBP_CSR_CFG_READ_CONTROL FIELD32(0x00010000)
491#define BBP_CSR_CFG_BUSY FIELD32(0x00020000)
492#define BBP_CSR_CFG_BBP_PAR_DUR FIELD32(0x00040000)
493#define BBP_CSR_CFG_BBP_RW_MODE FIELD32(0x00080000)
494
495/*
496 * RF_CSR_CFG0: RF control register
497 * REGID_AND_VALUE: Register value to program into RF
498 * BITWIDTH: Selected RF register
499 * STANDBYMODE: 0 high when standby, 1 low when standby
500 * SEL: 0 RF_LE0 activate, 1 RF_LE1 activate
501 * BUSY: ASIC is busy executing RF commands
502 */
503#define RF_CSR_CFG0 0x1020
504#define RF_CSR_CFG0_REGID_AND_VALUE FIELD32(0x00ffffff)
505#define RF_CSR_CFG0_BITWIDTH FIELD32(0x1f000000)
506#define RF_CSR_CFG0_REG_VALUE_BW FIELD32(0x1fffffff)
507#define RF_CSR_CFG0_STANDBYMODE FIELD32(0x20000000)
508#define RF_CSR_CFG0_SEL FIELD32(0x40000000)
509#define RF_CSR_CFG0_BUSY FIELD32(0x80000000)
510
511/*
512 * RF_CSR_CFG1: RF control register
513 * REGID_AND_VALUE: Register value to program into RF
514 * RFGAP: Gap between BB_CONTROL_RF and RF_LE
515 * 0: 3 system clock cycle (37.5usec)
516 * 1: 5 system clock cycle (62.5usec)
517 */
518#define RF_CSR_CFG1 0x1024
519#define RF_CSR_CFG1_REGID_AND_VALUE FIELD32(0x00ffffff)
520#define RF_CSR_CFG1_RFGAP FIELD32(0x1f000000)
521
522/*
523 * RF_CSR_CFG2: RF control register
524 * VALUE: Register value to program into RF
525 * RFGAP: Gap between BB_CONTROL_RF and RF_LE
526 * 0: 3 system clock cycle (37.5usec)
527 * 1: 5 system clock cycle (62.5usec)
528 */
529#define RF_CSR_CFG2 0x1028
530#define RF_CSR_CFG2_VALUE FIELD32(0x00ffffff)
531
532/*
533 * LED_CFG: LED control
534 * color LED's:
535 * 0: off
536 * 1: blinking upon TX2
537 * 2: periodic slow blinking
538 * 3: always on
539 * LED polarity:
540 * 0: active low
541 * 1: active high
542 */
543#define LED_CFG 0x102c
544#define LED_CFG_ON_PERIOD FIELD32(0x000000ff)
545#define LED_CFG_OFF_PERIOD FIELD32(0x0000ff00)
546#define LED_CFG_SLOW_BLINK_PERIOD FIELD32(0x003f0000)
547#define LED_CFG_R_LED_MODE FIELD32(0x03000000)
548#define LED_CFG_G_LED_MODE FIELD32(0x0c000000)
549#define LED_CFG_Y_LED_MODE FIELD32(0x30000000)
550#define LED_CFG_LED_POLAR FIELD32(0x40000000)
551
552/*
553 * XIFS_TIME_CFG: MAC timing
554 * CCKM_SIFS_TIME: unit 1us. Applied after CCK RX/TX
555 * OFDM_SIFS_TIME: unit 1us. Applied after OFDM RX/TX
556 * OFDM_XIFS_TIME: unit 1us. Applied after OFDM RX
557 * when MAC doesn't reference BBP signal BBRXEND
558 * EIFS: unit 1us
559 * BB_RXEND_ENABLE: reference RXEND signal to begin XIFS defer
560 *
561 */
562#define XIFS_TIME_CFG 0x1100
563#define XIFS_TIME_CFG_CCKM_SIFS_TIME FIELD32(0x000000ff)
564#define XIFS_TIME_CFG_OFDM_SIFS_TIME FIELD32(0x0000ff00)
565#define XIFS_TIME_CFG_OFDM_XIFS_TIME FIELD32(0x000f0000)
566#define XIFS_TIME_CFG_EIFS FIELD32(0x1ff00000)
567#define XIFS_TIME_CFG_BB_RXEND_ENABLE FIELD32(0x20000000)
568
569/*
570 * BKOFF_SLOT_CFG:
571 */
572#define BKOFF_SLOT_CFG 0x1104
573#define BKOFF_SLOT_CFG_SLOT_TIME FIELD32(0x000000ff)
574#define BKOFF_SLOT_CFG_CC_DELAY_TIME FIELD32(0x0000ff00)
575
576/*
577 * NAV_TIME_CFG:
578 */
579#define NAV_TIME_CFG 0x1108
580#define NAV_TIME_CFG_SIFS FIELD32(0x000000ff)
581#define NAV_TIME_CFG_SLOT_TIME FIELD32(0x0000ff00)
582#define NAV_TIME_CFG_EIFS FIELD32(0x01ff0000)
583#define NAV_TIME_ZERO_SIFS FIELD32(0x02000000)
584
585/*
586 * CH_TIME_CFG: count as channel busy
587 */
588#define CH_TIME_CFG 0x110c
589
590/*
591 * PBF_LIFE_TIMER: TX/RX MPDU timestamp timer (free run) Unit: 1us
592 */
593#define PBF_LIFE_TIMER 0x1110
594
595/*
596 * BCN_TIME_CFG:
597 * BEACON_INTERVAL: in unit of 1/16 TU
598 * TSF_TICKING: Enable TSF auto counting
599 * TSF_SYNC: Enable TSF sync, 00: disable, 01: infra mode, 10: ad-hoc mode
600 * BEACON_GEN: Enable beacon generator
601 */
602#define BCN_TIME_CFG 0x1114
603#define BCN_TIME_CFG_BEACON_INTERVAL FIELD32(0x0000ffff)
604#define BCN_TIME_CFG_TSF_TICKING FIELD32(0x00010000)
605#define BCN_TIME_CFG_TSF_SYNC FIELD32(0x00060000)
606#define BCN_TIME_CFG_TBTT_ENABLE FIELD32(0x00080000)
607#define BCN_TIME_CFG_BEACON_GEN FIELD32(0x00100000)
608#define BCN_TIME_CFG_TX_TIME_COMPENSATE FIELD32(0xf0000000)
609
610/*
611 * TBTT_SYNC_CFG:
612 */
613#define TBTT_SYNC_CFG 0x1118
614
615/*
616 * TSF_TIMER_DW0: Local lsb TSF timer, read-only
617 */
618#define TSF_TIMER_DW0 0x111c
619#define TSF_TIMER_DW0_LOW_WORD FIELD32(0xffffffff)
620
621/*
622 * TSF_TIMER_DW1: Local msb TSF timer, read-only
623 */
624#define TSF_TIMER_DW1 0x1120
625#define TSF_TIMER_DW1_HIGH_WORD FIELD32(0xffffffff)
626
627/*
628 * TBTT_TIMER: TImer remains till next TBTT, read-only
629 */
630#define TBTT_TIMER 0x1124
631
632/*
633 * INT_TIMER_CFG:
634 */
635#define INT_TIMER_CFG 0x1128
636
637/*
638 * INT_TIMER_EN: GP-timer and pre-tbtt Int enable
639 */
640#define INT_TIMER_EN 0x112c
641
642/*
643 * CH_IDLE_STA: channel idle time
644 */
645#define CH_IDLE_STA 0x1130
646
647/*
648 * CH_BUSY_STA: channel busy time
649 */
650#define CH_BUSY_STA 0x1134
651
652/*
653 * MAC_STATUS_CFG:
654 * BBP_RF_BUSY: When set to 0, BBP and RF are stable.
655 * if 1 or higher one of the 2 registers is busy.
656 */
657#define MAC_STATUS_CFG 0x1200
658#define MAC_STATUS_CFG_BBP_RF_BUSY FIELD32(0x00000003)
659
660/*
661 * PWR_PIN_CFG:
662 */
663#define PWR_PIN_CFG 0x1204
664
665/*
666 * AUTOWAKEUP_CFG: Manual power control / status register
667 * TBCN_BEFORE_WAKE: ForceWake has high privilege than PutToSleep when both set
668 * AUTOWAKE: 0:sleep, 1:awake
669 */
670#define AUTOWAKEUP_CFG 0x1208
671#define AUTOWAKEUP_CFG_AUTO_LEAD_TIME FIELD32(0x000000ff)
672#define AUTOWAKEUP_CFG_TBCN_BEFORE_WAKE FIELD32(0x00007f00)
673#define AUTOWAKEUP_CFG_AUTOWAKE FIELD32(0x00008000)
674
675/*
676 * EDCA_AC0_CFG:
677 */
678#define EDCA_AC0_CFG 0x1300
679#define EDCA_AC0_CFG_TX_OP FIELD32(0x000000ff)
680#define EDCA_AC0_CFG_AIFSN FIELD32(0x00000f00)
681#define EDCA_AC0_CFG_CWMIN FIELD32(0x0000f000)
682#define EDCA_AC0_CFG_CWMAX FIELD32(0x000f0000)
683
684/*
685 * EDCA_AC1_CFG:
686 */
687#define EDCA_AC1_CFG 0x1304
688#define EDCA_AC1_CFG_TX_OP FIELD32(0x000000ff)
689#define EDCA_AC1_CFG_AIFSN FIELD32(0x00000f00)
690#define EDCA_AC1_CFG_CWMIN FIELD32(0x0000f000)
691#define EDCA_AC1_CFG_CWMAX FIELD32(0x000f0000)
692
693/*
694 * EDCA_AC2_CFG:
695 */
696#define EDCA_AC2_CFG 0x1308
697#define EDCA_AC2_CFG_TX_OP FIELD32(0x000000ff)
698#define EDCA_AC2_CFG_AIFSN FIELD32(0x00000f00)
699#define EDCA_AC2_CFG_CWMIN FIELD32(0x0000f000)
700#define EDCA_AC2_CFG_CWMAX FIELD32(0x000f0000)
701
702/*
703 * EDCA_AC3_CFG:
704 */
705#define EDCA_AC3_CFG 0x130c
706#define EDCA_AC3_CFG_TX_OP FIELD32(0x000000ff)
707#define EDCA_AC3_CFG_AIFSN FIELD32(0x00000f00)
708#define EDCA_AC3_CFG_CWMIN FIELD32(0x0000f000)
709#define EDCA_AC3_CFG_CWMAX FIELD32(0x000f0000)
710
711/*
712 * EDCA_TID_AC_MAP:
713 */
714#define EDCA_TID_AC_MAP 0x1310
715
716/*
717 * TX_PWR_CFG_0:
718 */
719#define TX_PWR_CFG_0 0x1314
720#define TX_PWR_CFG_0_1MBS FIELD32(0x0000000f)
721#define TX_PWR_CFG_0_2MBS FIELD32(0x000000f0)
722#define TX_PWR_CFG_0_55MBS FIELD32(0x00000f00)
723#define TX_PWR_CFG_0_11MBS FIELD32(0x0000f000)
724#define TX_PWR_CFG_0_6MBS FIELD32(0x000f0000)
725#define TX_PWR_CFG_0_9MBS FIELD32(0x00f00000)
726#define TX_PWR_CFG_0_12MBS FIELD32(0x0f000000)
727#define TX_PWR_CFG_0_18MBS FIELD32(0xf0000000)
728
729/*
730 * TX_PWR_CFG_1:
731 */
732#define TX_PWR_CFG_1 0x1318
733#define TX_PWR_CFG_1_24MBS FIELD32(0x0000000f)
734#define TX_PWR_CFG_1_36MBS FIELD32(0x000000f0)
735#define TX_PWR_CFG_1_48MBS FIELD32(0x00000f00)
736#define TX_PWR_CFG_1_54MBS FIELD32(0x0000f000)
737#define TX_PWR_CFG_1_MCS0 FIELD32(0x000f0000)
738#define TX_PWR_CFG_1_MCS1 FIELD32(0x00f00000)
739#define TX_PWR_CFG_1_MCS2 FIELD32(0x0f000000)
740#define TX_PWR_CFG_1_MCS3 FIELD32(0xf0000000)
741
742/*
743 * TX_PWR_CFG_2:
744 */
745#define TX_PWR_CFG_2 0x131c
746#define TX_PWR_CFG_2_MCS4 FIELD32(0x0000000f)
747#define TX_PWR_CFG_2_MCS5 FIELD32(0x000000f0)
748#define TX_PWR_CFG_2_MCS6 FIELD32(0x00000f00)
749#define TX_PWR_CFG_2_MCS7 FIELD32(0x0000f000)
750#define TX_PWR_CFG_2_MCS8 FIELD32(0x000f0000)
751#define TX_PWR_CFG_2_MCS9 FIELD32(0x00f00000)
752#define TX_PWR_CFG_2_MCS10 FIELD32(0x0f000000)
753#define TX_PWR_CFG_2_MCS11 FIELD32(0xf0000000)
754
755/*
756 * TX_PWR_CFG_3:
757 */
758#define TX_PWR_CFG_3 0x1320
759#define TX_PWR_CFG_3_MCS12 FIELD32(0x0000000f)
760#define TX_PWR_CFG_3_MCS13 FIELD32(0x000000f0)
761#define TX_PWR_CFG_3_MCS14 FIELD32(0x00000f00)
762#define TX_PWR_CFG_3_MCS15 FIELD32(0x0000f000)
763#define TX_PWR_CFG_3_UKNOWN1 FIELD32(0x000f0000)
764#define TX_PWR_CFG_3_UKNOWN2 FIELD32(0x00f00000)
765#define TX_PWR_CFG_3_UKNOWN3 FIELD32(0x0f000000)
766#define TX_PWR_CFG_3_UKNOWN4 FIELD32(0xf0000000)
767
768/*
769 * TX_PWR_CFG_4:
770 */
771#define TX_PWR_CFG_4 0x1324
772#define TX_PWR_CFG_4_UKNOWN5 FIELD32(0x0000000f)
773#define TX_PWR_CFG_4_UKNOWN6 FIELD32(0x000000f0)
774#define TX_PWR_CFG_4_UKNOWN7 FIELD32(0x00000f00)
775#define TX_PWR_CFG_4_UKNOWN8 FIELD32(0x0000f000)
776
777/*
778 * TX_PIN_CFG:
779 */
780#define TX_PIN_CFG 0x1328
781#define TX_PIN_CFG_PA_PE_A0_EN FIELD32(0x00000001)
782#define TX_PIN_CFG_PA_PE_G0_EN FIELD32(0x00000002)
783#define TX_PIN_CFG_PA_PE_A1_EN FIELD32(0x00000004)
784#define TX_PIN_CFG_PA_PE_G1_EN FIELD32(0x00000008)
785#define TX_PIN_CFG_PA_PE_A0_POL FIELD32(0x00000010)
786#define TX_PIN_CFG_PA_PE_G0_POL FIELD32(0x00000020)
787#define TX_PIN_CFG_PA_PE_A1_POL FIELD32(0x00000040)
788#define TX_PIN_CFG_PA_PE_G1_POL FIELD32(0x00000080)
789#define TX_PIN_CFG_LNA_PE_A0_EN FIELD32(0x00000100)
790#define TX_PIN_CFG_LNA_PE_G0_EN FIELD32(0x00000200)
791#define TX_PIN_CFG_LNA_PE_A1_EN FIELD32(0x00000400)
792#define TX_PIN_CFG_LNA_PE_G1_EN FIELD32(0x00000800)
793#define TX_PIN_CFG_LNA_PE_A0_POL FIELD32(0x00001000)
794#define TX_PIN_CFG_LNA_PE_G0_POL FIELD32(0x00002000)
795#define TX_PIN_CFG_LNA_PE_A1_POL FIELD32(0x00004000)
796#define TX_PIN_CFG_LNA_PE_G1_POL FIELD32(0x00008000)
797#define TX_PIN_CFG_RFTR_EN FIELD32(0x00010000)
798#define TX_PIN_CFG_RFTR_POL FIELD32(0x00020000)
799#define TX_PIN_CFG_TRSW_EN FIELD32(0x00040000)
800#define TX_PIN_CFG_TRSW_POL FIELD32(0x00080000)
801
802/*
803 * TX_BAND_CFG: 0x1 use upper 20MHz, 0x0 use lower 20MHz
804 */
805#define TX_BAND_CFG 0x132c
806#define TX_BAND_CFG_HT40_PLUS FIELD32(0x00000001)
807#define TX_BAND_CFG_A FIELD32(0x00000002)
808#define TX_BAND_CFG_BG FIELD32(0x00000004)
809
810/*
811 * TX_SW_CFG0:
812 */
813#define TX_SW_CFG0 0x1330
814
815/*
816 * TX_SW_CFG1:
817 */
818#define TX_SW_CFG1 0x1334
819
820/*
821 * TX_SW_CFG2:
822 */
823#define TX_SW_CFG2 0x1338
824
825/*
826 * TXOP_THRES_CFG:
827 */
828#define TXOP_THRES_CFG 0x133c
829
830/*
831 * TXOP_CTRL_CFG:
832 */
833#define TXOP_CTRL_CFG 0x1340
834
835/*
836 * TX_RTS_CFG:
837 * RTS_THRES: unit:byte
838 * RTS_FBK_EN: enable rts rate fallback
839 */
840#define TX_RTS_CFG 0x1344
841#define TX_RTS_CFG_AUTO_RTS_RETRY_LIMIT FIELD32(0x000000ff)
842#define TX_RTS_CFG_RTS_THRES FIELD32(0x00ffff00)
843#define TX_RTS_CFG_RTS_FBK_EN FIELD32(0x01000000)
844
845/*
846 * TX_TIMEOUT_CFG:
847 * MPDU_LIFETIME: expiration time = 2^(9+MPDU LIFE TIME) us
848 * RX_ACK_TIMEOUT: unit:slot. Used for TX procedure
849 * TX_OP_TIMEOUT: TXOP timeout value for TXOP truncation.
850 * it is recommended that:
851 * (SLOT_TIME) > (TX_OP_TIMEOUT) > (RX_ACK_TIMEOUT)
852 */
853#define TX_TIMEOUT_CFG 0x1348
854#define TX_TIMEOUT_CFG_MPDU_LIFETIME FIELD32(0x000000f0)
855#define TX_TIMEOUT_CFG_RX_ACK_TIMEOUT FIELD32(0x0000ff00)
856#define TX_TIMEOUT_CFG_TX_OP_TIMEOUT FIELD32(0x00ff0000)
857
858/*
859 * TX_RTY_CFG:
860 * SHORT_RTY_LIMIT: short retry limit
861 * LONG_RTY_LIMIT: long retry limit
862 * LONG_RTY_THRE: Long retry threshoold
863 * NON_AGG_RTY_MODE: Non-Aggregate MPDU retry mode
864 * 0:expired by retry limit, 1: expired by mpdu life timer
865 * AGG_RTY_MODE: Aggregate MPDU retry mode
866 * 0:expired by retry limit, 1: expired by mpdu life timer
867 * TX_AUTO_FB_ENABLE: Tx retry PHY rate auto fallback enable
868 */
869#define TX_RTY_CFG 0x134c
870#define TX_RTY_CFG_SHORT_RTY_LIMIT FIELD32(0x000000ff)
871#define TX_RTY_CFG_LONG_RTY_LIMIT FIELD32(0x0000ff00)
872#define TX_RTY_CFG_LONG_RTY_THRE FIELD32(0x0fff0000)
873#define TX_RTY_CFG_NON_AGG_RTY_MODE FIELD32(0x10000000)
874#define TX_RTY_CFG_AGG_RTY_MODE FIELD32(0x20000000)
875#define TX_RTY_CFG_TX_AUTO_FB_ENABLE FIELD32(0x40000000)
876
877/*
878 * TX_LINK_CFG:
879 * REMOTE_MFB_LIFETIME: remote MFB life time. unit: 32us
880 * MFB_ENABLE: TX apply remote MFB 1:enable
881 * REMOTE_UMFS_ENABLE: remote unsolicit MFB enable
882 * 0: not apply remote remote unsolicit (MFS=7)
883 * TX_MRQ_EN: MCS request TX enable
884 * TX_RDG_EN: RDG TX enable
885 * TX_CF_ACK_EN: Piggyback CF-ACK enable
886 * REMOTE_MFB: remote MCS feedback
887 * REMOTE_MFS: remote MCS feedback sequence number
888 */
889#define TX_LINK_CFG 0x1350
890#define TX_LINK_CFG_REMOTE_MFB_LIFETIME FIELD32(0x000000ff)
891#define TX_LINK_CFG_MFB_ENABLE FIELD32(0x00000100)
892#define TX_LINK_CFG_REMOTE_UMFS_ENABLE FIELD32(0x00000200)
893#define TX_LINK_CFG_TX_MRQ_EN FIELD32(0x00000400)
894#define TX_LINK_CFG_TX_RDG_EN FIELD32(0x00000800)
895#define TX_LINK_CFG_TX_CF_ACK_EN FIELD32(0x00001000)
896#define TX_LINK_CFG_REMOTE_MFB FIELD32(0x00ff0000)
897#define TX_LINK_CFG_REMOTE_MFS FIELD32(0xff000000)
898
899/*
900 * HT_FBK_CFG0:
901 */
902#define HT_FBK_CFG0 0x1354
903#define HT_FBK_CFG0_HTMCS0FBK FIELD32(0x0000000f)
904#define HT_FBK_CFG0_HTMCS1FBK FIELD32(0x000000f0)
905#define HT_FBK_CFG0_HTMCS2FBK FIELD32(0x00000f00)
906#define HT_FBK_CFG0_HTMCS3FBK FIELD32(0x0000f000)
907#define HT_FBK_CFG0_HTMCS4FBK FIELD32(0x000f0000)
908#define HT_FBK_CFG0_HTMCS5FBK FIELD32(0x00f00000)
909#define HT_FBK_CFG0_HTMCS6FBK FIELD32(0x0f000000)
910#define HT_FBK_CFG0_HTMCS7FBK FIELD32(0xf0000000)
911
912/*
913 * HT_FBK_CFG1:
914 */
915#define HT_FBK_CFG1 0x1358
916#define HT_FBK_CFG1_HTMCS8FBK FIELD32(0x0000000f)
917#define HT_FBK_CFG1_HTMCS9FBK FIELD32(0x000000f0)
918#define HT_FBK_CFG1_HTMCS10FBK FIELD32(0x00000f00)
919#define HT_FBK_CFG1_HTMCS11FBK FIELD32(0x0000f000)
920#define HT_FBK_CFG1_HTMCS12FBK FIELD32(0x000f0000)
921#define HT_FBK_CFG1_HTMCS13FBK FIELD32(0x00f00000)
922#define HT_FBK_CFG1_HTMCS14FBK FIELD32(0x0f000000)
923#define HT_FBK_CFG1_HTMCS15FBK FIELD32(0xf0000000)
924
925/*
926 * LG_FBK_CFG0:
927 */
928#define LG_FBK_CFG0 0x135c
929#define LG_FBK_CFG0_OFDMMCS0FBK FIELD32(0x0000000f)
930#define LG_FBK_CFG0_OFDMMCS1FBK FIELD32(0x000000f0)
931#define LG_FBK_CFG0_OFDMMCS2FBK FIELD32(0x00000f00)
932#define LG_FBK_CFG0_OFDMMCS3FBK FIELD32(0x0000f000)
933#define LG_FBK_CFG0_OFDMMCS4FBK FIELD32(0x000f0000)
934#define LG_FBK_CFG0_OFDMMCS5FBK FIELD32(0x00f00000)
935#define LG_FBK_CFG0_OFDMMCS6FBK FIELD32(0x0f000000)
936#define LG_FBK_CFG0_OFDMMCS7FBK FIELD32(0xf0000000)
937
938/*
939 * LG_FBK_CFG1:
940 */
941#define LG_FBK_CFG1 0x1360
942#define LG_FBK_CFG0_CCKMCS0FBK FIELD32(0x0000000f)
943#define LG_FBK_CFG0_CCKMCS1FBK FIELD32(0x000000f0)
944#define LG_FBK_CFG0_CCKMCS2FBK FIELD32(0x00000f00)
945#define LG_FBK_CFG0_CCKMCS3FBK FIELD32(0x0000f000)
946
947/*
948 * CCK_PROT_CFG: CCK Protection
949 * PROTECT_RATE: Protection control frame rate for CCK TX(RTS/CTS/CFEnd)
950 * PROTECT_CTRL: Protection control frame type for CCK TX
951 * 0:none, 1:RTS/CTS, 2:CTS-to-self
952 * PROTECT_NAV: TXOP protection type for CCK TX
953 * 0:none, 1:ShortNAVprotect, 2:LongNAVProtect
954 * TX_OP_ALLOW_CCK: CCK TXOP allowance, 0:disallow
955 * TX_OP_ALLOW_OFDM: CCK TXOP allowance, 0:disallow
956 * TX_OP_ALLOW_MM20: CCK TXOP allowance, 0:disallow
957 * TX_OP_ALLOW_MM40: CCK TXOP allowance, 0:disallow
958 * TX_OP_ALLOW_GF20: CCK TXOP allowance, 0:disallow
959 * TX_OP_ALLOW_GF40: CCK TXOP allowance, 0:disallow
960 * RTS_TH_EN: RTS threshold enable on CCK TX
961 */
962#define CCK_PROT_CFG 0x1364
963#define CCK_PROT_CFG_PROTECT_RATE FIELD32(0x0000ffff)
964#define CCK_PROT_CFG_PROTECT_CTRL FIELD32(0x00030000)
965#define CCK_PROT_CFG_PROTECT_NAV FIELD32(0x000c0000)
966#define CCK_PROT_CFG_TX_OP_ALLOW_CCK FIELD32(0x00100000)
967#define CCK_PROT_CFG_TX_OP_ALLOW_OFDM FIELD32(0x00200000)
968#define CCK_PROT_CFG_TX_OP_ALLOW_MM20 FIELD32(0x00400000)
969#define CCK_PROT_CFG_TX_OP_ALLOW_MM40 FIELD32(0x00800000)
970#define CCK_PROT_CFG_TX_OP_ALLOW_GF20 FIELD32(0x01000000)
971#define CCK_PROT_CFG_TX_OP_ALLOW_GF40 FIELD32(0x02000000)
972#define CCK_PROT_CFG_RTS_TH_EN FIELD32(0x04000000)
973
974/*
975 * OFDM_PROT_CFG: OFDM Protection
976 */
977#define OFDM_PROT_CFG 0x1368
978#define OFDM_PROT_CFG_PROTECT_RATE FIELD32(0x0000ffff)
979#define OFDM_PROT_CFG_PROTECT_CTRL FIELD32(0x00030000)
980#define OFDM_PROT_CFG_PROTECT_NAV FIELD32(0x000c0000)
981#define OFDM_PROT_CFG_TX_OP_ALLOW_CCK FIELD32(0x00100000)
982#define OFDM_PROT_CFG_TX_OP_ALLOW_OFDM FIELD32(0x00200000)
983#define OFDM_PROT_CFG_TX_OP_ALLOW_MM20 FIELD32(0x00400000)
984#define OFDM_PROT_CFG_TX_OP_ALLOW_MM40 FIELD32(0x00800000)
985#define OFDM_PROT_CFG_TX_OP_ALLOW_GF20 FIELD32(0x01000000)
986#define OFDM_PROT_CFG_TX_OP_ALLOW_GF40 FIELD32(0x02000000)
987#define OFDM_PROT_CFG_RTS_TH_EN FIELD32(0x04000000)
988
989/*
990 * MM20_PROT_CFG: MM20 Protection
991 */
992#define MM20_PROT_CFG 0x136c
993#define MM20_PROT_CFG_PROTECT_RATE FIELD32(0x0000ffff)
994#define MM20_PROT_CFG_PROTECT_CTRL FIELD32(0x00030000)
995#define MM20_PROT_CFG_PROTECT_NAV FIELD32(0x000c0000)
996#define MM20_PROT_CFG_TX_OP_ALLOW_CCK FIELD32(0x00100000)
997#define MM20_PROT_CFG_TX_OP_ALLOW_OFDM FIELD32(0x00200000)
998#define MM20_PROT_CFG_TX_OP_ALLOW_MM20 FIELD32(0x00400000)
999#define MM20_PROT_CFG_TX_OP_ALLOW_MM40 FIELD32(0x00800000)
1000#define MM20_PROT_CFG_TX_OP_ALLOW_GF20 FIELD32(0x01000000)
1001#define MM20_PROT_CFG_TX_OP_ALLOW_GF40 FIELD32(0x02000000)
1002#define MM20_PROT_CFG_RTS_TH_EN FIELD32(0x04000000)
1003
1004/*
1005 * MM40_PROT_CFG: MM40 Protection
1006 */
1007#define MM40_PROT_CFG 0x1370
1008#define MM40_PROT_CFG_PROTECT_RATE FIELD32(0x0000ffff)
1009#define MM40_PROT_CFG_PROTECT_CTRL FIELD32(0x00030000)
1010#define MM40_PROT_CFG_PROTECT_NAV FIELD32(0x000c0000)
1011#define MM40_PROT_CFG_TX_OP_ALLOW_CCK FIELD32(0x00100000)
1012#define MM40_PROT_CFG_TX_OP_ALLOW_OFDM FIELD32(0x00200000)
1013#define MM40_PROT_CFG_TX_OP_ALLOW_MM20 FIELD32(0x00400000)
1014#define MM40_PROT_CFG_TX_OP_ALLOW_MM40 FIELD32(0x00800000)
1015#define MM40_PROT_CFG_TX_OP_ALLOW_GF20 FIELD32(0x01000000)
1016#define MM40_PROT_CFG_TX_OP_ALLOW_GF40 FIELD32(0x02000000)
1017#define MM40_PROT_CFG_RTS_TH_EN FIELD32(0x04000000)
1018
1019/*
1020 * GF20_PROT_CFG: GF20 Protection
1021 */
1022#define GF20_PROT_CFG 0x1374
1023#define GF20_PROT_CFG_PROTECT_RATE FIELD32(0x0000ffff)
1024#define GF20_PROT_CFG_PROTECT_CTRL FIELD32(0x00030000)
1025#define GF20_PROT_CFG_PROTECT_NAV FIELD32(0x000c0000)
1026#define GF20_PROT_CFG_TX_OP_ALLOW_CCK FIELD32(0x00100000)
1027#define GF20_PROT_CFG_TX_OP_ALLOW_OFDM FIELD32(0x00200000)
1028#define GF20_PROT_CFG_TX_OP_ALLOW_MM20 FIELD32(0x00400000)
1029#define GF20_PROT_CFG_TX_OP_ALLOW_MM40 FIELD32(0x00800000)
1030#define GF20_PROT_CFG_TX_OP_ALLOW_GF20 FIELD32(0x01000000)
1031#define GF20_PROT_CFG_TX_OP_ALLOW_GF40 FIELD32(0x02000000)
1032#define GF20_PROT_CFG_RTS_TH_EN FIELD32(0x04000000)
1033
1034/*
1035 * GF40_PROT_CFG: GF40 Protection
1036 */
1037#define GF40_PROT_CFG 0x1378
1038#define GF40_PROT_CFG_PROTECT_RATE FIELD32(0x0000ffff)
1039#define GF40_PROT_CFG_PROTECT_CTRL FIELD32(0x00030000)
1040#define GF40_PROT_CFG_PROTECT_NAV FIELD32(0x000c0000)
1041#define GF40_PROT_CFG_TX_OP_ALLOW_CCK FIELD32(0x00100000)
1042#define GF40_PROT_CFG_TX_OP_ALLOW_OFDM FIELD32(0x00200000)
1043#define GF40_PROT_CFG_TX_OP_ALLOW_MM20 FIELD32(0x00400000)
1044#define GF40_PROT_CFG_TX_OP_ALLOW_MM40 FIELD32(0x00800000)
1045#define GF40_PROT_CFG_TX_OP_ALLOW_GF20 FIELD32(0x01000000)
1046#define GF40_PROT_CFG_TX_OP_ALLOW_GF40 FIELD32(0x02000000)
1047#define GF40_PROT_CFG_RTS_TH_EN FIELD32(0x04000000)
1048
1049/*
1050 * EXP_CTS_TIME:
1051 */
1052#define EXP_CTS_TIME 0x137c
1053
1054/*
1055 * EXP_ACK_TIME:
1056 */
1057#define EXP_ACK_TIME 0x1380
1058
1059/*
1060 * RX_FILTER_CFG: RX configuration register.
1061 */
1062#define RX_FILTER_CFG 0x1400
1063#define RX_FILTER_CFG_DROP_CRC_ERROR FIELD32(0x00000001)
1064#define RX_FILTER_CFG_DROP_PHY_ERROR FIELD32(0x00000002)
1065#define RX_FILTER_CFG_DROP_NOT_TO_ME FIELD32(0x00000004)
1066#define RX_FILTER_CFG_DROP_NOT_MY_BSSD FIELD32(0x00000008)
1067#define RX_FILTER_CFG_DROP_VER_ERROR FIELD32(0x00000010)
1068#define RX_FILTER_CFG_DROP_MULTICAST FIELD32(0x00000020)
1069#define RX_FILTER_CFG_DROP_BROADCAST FIELD32(0x00000040)
1070#define RX_FILTER_CFG_DROP_DUPLICATE FIELD32(0x00000080)
1071#define RX_FILTER_CFG_DROP_CF_END_ACK FIELD32(0x00000100)
1072#define RX_FILTER_CFG_DROP_CF_END FIELD32(0x00000200)
1073#define RX_FILTER_CFG_DROP_ACK FIELD32(0x00000400)
1074#define RX_FILTER_CFG_DROP_CTS FIELD32(0x00000800)
1075#define RX_FILTER_CFG_DROP_RTS FIELD32(0x00001000)
1076#define RX_FILTER_CFG_DROP_PSPOLL FIELD32(0x00002000)
1077#define RX_FILTER_CFG_DROP_BA FIELD32(0x00004000)
1078#define RX_FILTER_CFG_DROP_BAR FIELD32(0x00008000)
1079#define RX_FILTER_CFG_DROP_CNTL FIELD32(0x00010000)
1080
1081/*
1082 * AUTO_RSP_CFG:
1083 * AUTORESPONDER: 0: disable, 1: enable
1084 * BAC_ACK_POLICY: 0:long, 1:short preamble
1085 * CTS_40_MMODE: Response CTS 40MHz duplicate mode
1086 * CTS_40_MREF: Response CTS 40MHz duplicate mode
1087 * AR_PREAMBLE: Auto responder preamble 0:long, 1:short preamble
1088 * DUAL_CTS_EN: Power bit value in control frame
1089 * ACK_CTS_PSM_BIT:Power bit value in control frame
1090 */
1091#define AUTO_RSP_CFG 0x1404
1092#define AUTO_RSP_CFG_AUTORESPONDER FIELD32(0x00000001)
1093#define AUTO_RSP_CFG_BAC_ACK_POLICY FIELD32(0x00000002)
1094#define AUTO_RSP_CFG_CTS_40_MMODE FIELD32(0x00000004)
1095#define AUTO_RSP_CFG_CTS_40_MREF FIELD32(0x00000008)
1096#define AUTO_RSP_CFG_AR_PREAMBLE FIELD32(0x00000010)
1097#define AUTO_RSP_CFG_DUAL_CTS_EN FIELD32(0x00000040)
1098#define AUTO_RSP_CFG_ACK_CTS_PSM_BIT FIELD32(0x00000080)
1099
1100/*
1101 * LEGACY_BASIC_RATE:
1102 */
1103#define LEGACY_BASIC_RATE 0x1408
1104
1105/*
1106 * HT_BASIC_RATE:
1107 */
1108#define HT_BASIC_RATE 0x140c
1109
1110/*
1111 * HT_CTRL_CFG:
1112 */
1113#define HT_CTRL_CFG 0x1410
1114
1115/*
1116 * SIFS_COST_CFG:
1117 */
1118#define SIFS_COST_CFG 0x1414
1119
1120/*
1121 * RX_PARSER_CFG:
1122 * Set NAV for all received frames
1123 */
1124#define RX_PARSER_CFG 0x1418
1125
1126/*
1127 * TX_SEC_CNT0:
1128 */
1129#define TX_SEC_CNT0 0x1500
1130
1131/*
1132 * RX_SEC_CNT0:
1133 */
1134#define RX_SEC_CNT0 0x1504
1135
1136/*
1137 * CCMP_FC_MUTE:
1138 */
1139#define CCMP_FC_MUTE 0x1508
1140
1141/*
1142 * TXOP_HLDR_ADDR0:
1143 */
1144#define TXOP_HLDR_ADDR0 0x1600
1145
1146/*
1147 * TXOP_HLDR_ADDR1:
1148 */
1149#define TXOP_HLDR_ADDR1 0x1604
1150
1151/*
1152 * TXOP_HLDR_ET:
1153 */
1154#define TXOP_HLDR_ET 0x1608
1155
1156/*
1157 * QOS_CFPOLL_RA_DW0:
1158 */
1159#define QOS_CFPOLL_RA_DW0 0x160c
1160
1161/*
1162 * QOS_CFPOLL_RA_DW1:
1163 */
1164#define QOS_CFPOLL_RA_DW1 0x1610
1165
1166/*
1167 * QOS_CFPOLL_QC:
1168 */
1169#define QOS_CFPOLL_QC 0x1614
1170
1171/*
1172 * RX_STA_CNT0: RX PLCP error count & RX CRC error count
1173 */
1174#define RX_STA_CNT0 0x1700
1175#define RX_STA_CNT0_CRC_ERR FIELD32(0x0000ffff)
1176#define RX_STA_CNT0_PHY_ERR FIELD32(0xffff0000)
1177
1178/*
1179 * RX_STA_CNT1: RX False CCA count & RX LONG frame count
1180 */
1181#define RX_STA_CNT1 0x1704
1182#define RX_STA_CNT1_FALSE_CCA FIELD32(0x0000ffff)
1183#define RX_STA_CNT1_PLCP_ERR FIELD32(0xffff0000)
1184
1185/*
1186 * RX_STA_CNT2:
1187 */
1188#define RX_STA_CNT2 0x1708
1189#define RX_STA_CNT2_RX_DUPLI_COUNT FIELD32(0x0000ffff)
1190#define RX_STA_CNT2_RX_FIFO_OVERFLOW FIELD32(0xffff0000)
1191
1192/*
1193 * TX_STA_CNT0: TX Beacon count
1194 */
1195#define TX_STA_CNT0 0x170c
1196#define TX_STA_CNT0_TX_FAIL_COUNT FIELD32(0x0000ffff)
1197#define TX_STA_CNT0_TX_BEACON_COUNT FIELD32(0xffff0000)
1198
1199/*
1200 * TX_STA_CNT1: TX tx count
1201 */
1202#define TX_STA_CNT1 0x1710
1203#define TX_STA_CNT1_TX_SUCCESS FIELD32(0x0000ffff)
1204#define TX_STA_CNT1_TX_RETRANSMIT FIELD32(0xffff0000)
1205
1206/*
1207 * TX_STA_CNT2: TX tx count
1208 */
1209#define TX_STA_CNT2 0x1714
1210#define TX_STA_CNT2_TX_ZERO_LEN_COUNT FIELD32(0x0000ffff)
1211#define TX_STA_CNT2_TX_UNDER_FLOW_COUNT FIELD32(0xffff0000)
1212
1213/*
1214 * TX_STA_FIFO: TX Result for specific PID status fifo register
1215 */
1216#define TX_STA_FIFO 0x1718
1217#define TX_STA_FIFO_VALID FIELD32(0x00000001)
1218#define TX_STA_FIFO_PID_TYPE FIELD32(0x0000001e)
1219#define TX_STA_FIFO_TX_SUCCESS FIELD32(0x00000020)
1220#define TX_STA_FIFO_TX_AGGRE FIELD32(0x00000040)
1221#define TX_STA_FIFO_TX_ACK_REQUIRED FIELD32(0x00000080)
1222#define TX_STA_FIFO_WCID FIELD32(0x0000ff00)
1223#define TX_STA_FIFO_SUCCESS_RATE FIELD32(0xffff0000)
1224
1225/*
1226 * TX_AGG_CNT: Debug counter
1227 */
1228#define TX_AGG_CNT 0x171c
1229#define TX_AGG_CNT_NON_AGG_TX_COUNT FIELD32(0x0000ffff)
1230#define TX_AGG_CNT_AGG_TX_COUNT FIELD32(0xffff0000)
1231
1232/*
1233 * TX_AGG_CNT0:
1234 */
1235#define TX_AGG_CNT0 0x1720
1236#define TX_AGG_CNT0_AGG_SIZE_1_COUNT FIELD32(0x0000ffff)
1237#define TX_AGG_CNT0_AGG_SIZE_2_COUNT FIELD32(0xffff0000)
1238
1239/*
1240 * TX_AGG_CNT1:
1241 */
1242#define TX_AGG_CNT1 0x1724
1243#define TX_AGG_CNT1_AGG_SIZE_3_COUNT FIELD32(0x0000ffff)
1244#define TX_AGG_CNT1_AGG_SIZE_4_COUNT FIELD32(0xffff0000)
1245
1246/*
1247 * TX_AGG_CNT2:
1248 */
1249#define TX_AGG_CNT2 0x1728
1250#define TX_AGG_CNT2_AGG_SIZE_5_COUNT FIELD32(0x0000ffff)
1251#define TX_AGG_CNT2_AGG_SIZE_6_COUNT FIELD32(0xffff0000)
1252
1253/*
1254 * TX_AGG_CNT3:
1255 */
1256#define TX_AGG_CNT3 0x172c
1257#define TX_AGG_CNT3_AGG_SIZE_7_COUNT FIELD32(0x0000ffff)
1258#define TX_AGG_CNT3_AGG_SIZE_8_COUNT FIELD32(0xffff0000)
1259
1260/*
1261 * TX_AGG_CNT4:
1262 */
1263#define TX_AGG_CNT4 0x1730
1264#define TX_AGG_CNT4_AGG_SIZE_9_COUNT FIELD32(0x0000ffff)
1265#define TX_AGG_CNT4_AGG_SIZE_10_COUNT FIELD32(0xffff0000)
1266
1267/*
1268 * TX_AGG_CNT5:
1269 */
1270#define TX_AGG_CNT5 0x1734
1271#define TX_AGG_CNT5_AGG_SIZE_11_COUNT FIELD32(0x0000ffff)
1272#define TX_AGG_CNT5_AGG_SIZE_12_COUNT FIELD32(0xffff0000)
1273
1274/*
1275 * TX_AGG_CNT6:
1276 */
1277#define TX_AGG_CNT6 0x1738
1278#define TX_AGG_CNT6_AGG_SIZE_13_COUNT FIELD32(0x0000ffff)
1279#define TX_AGG_CNT6_AGG_SIZE_14_COUNT FIELD32(0xffff0000)
1280
1281/*
1282 * TX_AGG_CNT7:
1283 */
1284#define TX_AGG_CNT7 0x173c
1285#define TX_AGG_CNT7_AGG_SIZE_15_COUNT FIELD32(0x0000ffff)
1286#define TX_AGG_CNT7_AGG_SIZE_16_COUNT FIELD32(0xffff0000)
1287
1288/*
1289 * MPDU_DENSITY_CNT:
1290 * TX_ZERO_DEL: TX zero length delimiter count
1291 * RX_ZERO_DEL: RX zero length delimiter count
1292 */
1293#define MPDU_DENSITY_CNT 0x1740
1294#define MPDU_DENSITY_CNT_TX_ZERO_DEL FIELD32(0x0000ffff)
1295#define MPDU_DENSITY_CNT_RX_ZERO_DEL FIELD32(0xffff0000)
1296
1297/*
1298 * Security key table memory.
1299 * MAC_WCID_BASE: 8-bytes (use only 6 bytes) * 256 entry
1300 * PAIRWISE_KEY_TABLE_BASE: 32-byte * 256 entry
1301 * MAC_IVEIV_TABLE_BASE: 8-byte * 256-entry
1302 * MAC_WCID_ATTRIBUTE_BASE: 4-byte * 256-entry
1303 * SHARED_KEY_TABLE_BASE: 32-byte * 16-entry
1304 * SHARED_KEY_MODE_BASE: 4-byte * 16-entry
1305 */
1306#define MAC_WCID_BASE 0x1800
1307#define PAIRWISE_KEY_TABLE_BASE 0x4000
1308#define MAC_IVEIV_TABLE_BASE 0x6000
1309#define MAC_WCID_ATTRIBUTE_BASE 0x6800
1310#define SHARED_KEY_TABLE_BASE 0x6c00
1311#define SHARED_KEY_MODE_BASE 0x7000
1312
1313#define MAC_WCID_ENTRY(__idx) \
1314 ( MAC_WCID_BASE + ((__idx) * sizeof(struct mac_wcid_entry)) )
1315#define PAIRWISE_KEY_ENTRY(__idx) \
1316 ( PAIRWISE_KEY_TABLE_BASE + ((__idx) * sizeof(struct hw_key_entry)) )
1317#define MAC_IVEIV_ENTRY(__idx) \
1318 ( MAC_IVEIV_TABLE_BASE + ((__idx) & sizeof(struct mac_iveiv_entry)) )
1319#define MAC_WCID_ATTR_ENTRY(__idx) \
1320 ( MAC_WCID_ATTRIBUTE_BASE + ((__idx) * sizeof(u32)) )
1321#define SHARED_KEY_ENTRY(__idx) \
1322 ( SHARED_KEY_TABLE_BASE + ((__idx) * sizeof(struct hw_key_entry)) )
1323#define SHARED_KEY_MODE_ENTRY(__idx) \
1324 ( SHARED_KEY_MODE_BASE + ((__idx) * sizeof(u32)) )
1325
1326struct mac_wcid_entry {
1327 u8 mac[6];
1328 u8 reserved[2];
1329} __attribute__ ((packed));
1330
1331struct hw_key_entry {
1332 u8 key[16];
1333 u8 tx_mic[8];
1334 u8 rx_mic[8];
1335} __attribute__ ((packed));
1336
1337struct mac_iveiv_entry {
1338 u8 iv[8];
1339} __attribute__ ((packed));
1340
1341/*
1342 * MAC_WCID_ATTRIBUTE:
1343 */
1344#define MAC_WCID_ATTRIBUTE_KEYTAB FIELD32(0x00000001)
1345#define MAC_WCID_ATTRIBUTE_CIPHER FIELD32(0x0000000e)
1346#define MAC_WCID_ATTRIBUTE_BSS_IDX FIELD32(0x00000070)
1347#define MAC_WCID_ATTRIBUTE_RX_WIUDF FIELD32(0x00000380)
1348
1349/*
1350 * SHARED_KEY_MODE:
1351 */
1352#define SHARED_KEY_MODE_BSS0_KEY0 FIELD32(0x00000007)
1353#define SHARED_KEY_MODE_BSS0_KEY1 FIELD32(0x00000070)
1354#define SHARED_KEY_MODE_BSS0_KEY2 FIELD32(0x00000700)
1355#define SHARED_KEY_MODE_BSS0_KEY3 FIELD32(0x00007000)
1356#define SHARED_KEY_MODE_BSS1_KEY0 FIELD32(0x00070000)
1357#define SHARED_KEY_MODE_BSS1_KEY1 FIELD32(0x00700000)
1358#define SHARED_KEY_MODE_BSS1_KEY2 FIELD32(0x07000000)
1359#define SHARED_KEY_MODE_BSS1_KEY3 FIELD32(0x70000000)
1360
1361/*
1362 * HOST-MCU communication
1363 */
1364
1365/*
1366 * H2M_MAILBOX_CSR: Host-to-MCU Mailbox.
1367 */
1368#define H2M_MAILBOX_CSR 0x7010
1369#define H2M_MAILBOX_CSR_ARG0 FIELD32(0x000000ff)
1370#define H2M_MAILBOX_CSR_ARG1 FIELD32(0x0000ff00)
1371#define H2M_MAILBOX_CSR_CMD_TOKEN FIELD32(0x00ff0000)
1372#define H2M_MAILBOX_CSR_OWNER FIELD32(0xff000000)
1373
1374/*
1375 * H2M_MAILBOX_CID:
1376 */
1377#define H2M_MAILBOX_CID 0x7014
1378#define H2M_MAILBOX_CID_CMD0 FIELD32(0x000000ff)
1379#define H2M_MAILBOX_CID_CMD1 FIELD32(0x0000ff00)
1380#define H2M_MAILBOX_CID_CMD2 FIELD32(0x00ff0000)
1381#define H2M_MAILBOX_CID_CMD3 FIELD32(0xff000000)
1382
1383/*
1384 * H2M_MAILBOX_STATUS:
1385 */
1386#define H2M_MAILBOX_STATUS 0x701c
1387
1388/*
1389 * H2M_INT_SRC:
1390 */
1391#define H2M_INT_SRC 0x7024
1392
1393/*
1394 * H2M_BBP_AGENT:
1395 */
1396#define H2M_BBP_AGENT 0x7028
1397
1398/*
1399 * MCU_LEDCS: LED control for MCU Mailbox.
1400 */
1401#define MCU_LEDCS_LED_MODE FIELD8(0x1f)
1402#define MCU_LEDCS_POLARITY FIELD8(0x01)
1403
1404/*
1405 * HW_CS_CTS_BASE:
1406 * Carrier-sense CTS frame base address.
1407 * It's where mac stores carrier-sense frame for carrier-sense function.
1408 */
1409#define HW_CS_CTS_BASE 0x7700
1410
1411/*
1412 * HW_DFS_CTS_BASE:
1413 * FS CTS frame base address. It's where mac stores CTS frame for DFS.
1414 */
1415#define HW_DFS_CTS_BASE 0x7780
1416
1417/*
1418 * TXRX control registers - base address 0x3000
1419 */
1420
1421/*
1422 * TXRX_CSR1:
1423 * rt2860b UNKNOWN reg use R/O Reg Addr 0x77d0 first..
1424 */
1425#define TXRX_CSR1 0x77d0
1426
1427/*
1428 * HW_DEBUG_SETTING_BASE:
1429 * since NULL frame won't be that long (256 byte)
1430 * We steal 16 tail bytes to save debugging settings
1431 */
1432#define HW_DEBUG_SETTING_BASE 0x77f0
1433#define HW_DEBUG_SETTING_BASE2 0x7770
1434
1435/*
1436 * HW_BEACON_BASE
1437 * In order to support maximum 8 MBSS and its maximum length
1438 * is 512 bytes for each beacon
1439 * Three section discontinue memory segments will be used.
1440 * 1. The original region for BCN 0~3
1441 * 2. Extract memory from FCE table for BCN 4~5
1442 * 3. Extract memory from Pair-wise key table for BCN 6~7
1443 * It occupied those memory of wcid 238~253 for BCN 6
1444 * and wcid 222~237 for BCN 7
1445 *
1446 * IMPORTANT NOTE: Not sure why legacy driver does this,
1447 * but HW_BEACON_BASE7 is 0x0200 bytes below HW_BEACON_BASE6.
1448 */
1449#define HW_BEACON_BASE0 0x7800
1450#define HW_BEACON_BASE1 0x7a00
1451#define HW_BEACON_BASE2 0x7c00
1452#define HW_BEACON_BASE3 0x7e00
1453#define HW_BEACON_BASE4 0x7200
1454#define HW_BEACON_BASE5 0x7400
1455#define HW_BEACON_BASE6 0x5dc0
1456#define HW_BEACON_BASE7 0x5bc0
1457
1458#define HW_BEACON_OFFSET(__index) \
1459 ( ((__index) < 4) ? ( HW_BEACON_BASE0 + (__index * 0x0200) ) : \
1460 (((__index) < 6) ? ( HW_BEACON_BASE4 + ((__index - 4) * 0x0200) ) : \
1461 (HW_BEACON_BASE6 - ((__index - 6) * 0x0200))) )
1462
1463/*
1464 * 8051 firmware image.
1465 */
1466#define FIRMWARE_RT2870 "rt2870.bin"
1467#define FIRMWARE_IMAGE_BASE 0x3000
1468
1469/*
1470 * BBP registers.
1471 * The wordsize of the BBP is 8 bits.
1472 */
1473
1474/*
1475 * BBP 1: TX Antenna
1476 */
1477#define BBP1_TX_POWER FIELD8(0x07)
1478#define BBP1_TX_ANTENNA FIELD8(0x18)
1479
1480/*
1481 * BBP 3: RX Antenna
1482 */
1483#define BBP3_RX_ANTENNA FIELD8(0x18)
1484#define BBP3_HT40_PLUS FIELD8(0x20)
1485
1486/*
1487 * BBP 4: Bandwidth
1488 */
1489#define BBP4_TX_BF FIELD8(0x01)
1490#define BBP4_BANDWIDTH FIELD8(0x18)
1491
1492/*
1493 * RFCSR registers
1494 * The wordsize of the RFCSR is 8 bits.
1495 */
1496
1497/*
1498 * RFCSR 6:
1499 */
1500#define RFCSR6_R FIELD8(0x03)
1501
1502/*
1503 * RFCSR 7:
1504 */
1505#define RFCSR7_RF_TUNING FIELD8(0x01)
1506
1507/*
1508 * RFCSR 12:
1509 */
1510#define RFCSR12_TX_POWER FIELD8(0x1f)
1511
1512/*
1513 * RFCSR 22:
1514 */
1515#define RFCSR22_BASEBAND_LOOPBACK FIELD8(0x01)
1516
1517/*
1518 * RFCSR 23:
1519 */
1520#define RFCSR23_FREQ_OFFSET FIELD8(0x7f)
1521
1522/*
1523 * RFCSR 30:
1524 */
1525#define RFCSR30_RF_CALIBRATION FIELD8(0x80)
1526
1527/*
1528 * RF registers
1529 */
1530
1531/*
1532 * RF 2
1533 */
1534#define RF2_ANTENNA_RX2 FIELD32(0x00000040)
1535#define RF2_ANTENNA_TX1 FIELD32(0x00004000)
1536#define RF2_ANTENNA_RX1 FIELD32(0x00020000)
1537
1538/*
1539 * RF 3
1540 */
1541#define RF3_TXPOWER_G FIELD32(0x00003e00)
1542#define RF3_TXPOWER_A_7DBM_BOOST FIELD32(0x00000200)
1543#define RF3_TXPOWER_A FIELD32(0x00003c00)
1544
1545/*
1546 * RF 4
1547 */
1548#define RF4_TXPOWER_G FIELD32(0x000007c0)
1549#define RF4_TXPOWER_A_7DBM_BOOST FIELD32(0x00000040)
1550#define RF4_TXPOWER_A FIELD32(0x00000780)
1551#define RF4_FREQ_OFFSET FIELD32(0x001f8000)
1552#define RF4_HT40 FIELD32(0x00200000)
1553
1554/*
1555 * EEPROM content.
1556 * The wordsize of the EEPROM is 16 bits.
1557 */
1558
1559/*
1560 * EEPROM Version
1561 */
1562#define EEPROM_VERSION 0x0001
1563#define EEPROM_VERSION_FAE FIELD16(0x00ff)
1564#define EEPROM_VERSION_VERSION FIELD16(0xff00)
1565
1566/*
1567 * HW MAC address.
1568 */
1569#define EEPROM_MAC_ADDR_0 0x0002
1570#define EEPROM_MAC_ADDR_BYTE0 FIELD16(0x00ff)
1571#define EEPROM_MAC_ADDR_BYTE1 FIELD16(0xff00)
1572#define EEPROM_MAC_ADDR_1 0x0003
1573#define EEPROM_MAC_ADDR_BYTE2 FIELD16(0x00ff)
1574#define EEPROM_MAC_ADDR_BYTE3 FIELD16(0xff00)
1575#define EEPROM_MAC_ADDR_2 0x0004
1576#define EEPROM_MAC_ADDR_BYTE4 FIELD16(0x00ff)
1577#define EEPROM_MAC_ADDR_BYTE5 FIELD16(0xff00)
1578
1579/*
1580 * EEPROM ANTENNA config
1581 * RXPATH: 1: 1R, 2: 2R, 3: 3R
1582 * TXPATH: 1: 1T, 2: 2T
1583 */
1584#define EEPROM_ANTENNA 0x001a
1585#define EEPROM_ANTENNA_RXPATH FIELD16(0x000f)
1586#define EEPROM_ANTENNA_TXPATH FIELD16(0x00f0)
1587#define EEPROM_ANTENNA_RF_TYPE FIELD16(0x0f00)
1588
1589/*
1590 * EEPROM NIC config
1591 * CARDBUS_ACCEL: 0 - enable, 1 - disable
1592 */
1593#define EEPROM_NIC 0x001b
1594#define EEPROM_NIC_HW_RADIO FIELD16(0x0001)
1595#define EEPROM_NIC_DYNAMIC_TX_AGC FIELD16(0x0002)
1596#define EEPROM_NIC_EXTERNAL_LNA_BG FIELD16(0x0004)
1597#define EEPROM_NIC_EXTERNAL_LNA_A FIELD16(0x0008)
1598#define EEPROM_NIC_CARDBUS_ACCEL FIELD16(0x0010)
1599#define EEPROM_NIC_BW40M_SB_BG FIELD16(0x0020)
1600#define EEPROM_NIC_BW40M_SB_A FIELD16(0x0040)
1601#define EEPROM_NIC_WPS_PBC FIELD16(0x0080)
1602#define EEPROM_NIC_BW40M_BG FIELD16(0x0100)
1603#define EEPROM_NIC_BW40M_A FIELD16(0x0200)
1604
1605/*
1606 * EEPROM frequency
1607 */
1608#define EEPROM_FREQ 0x001d
1609#define EEPROM_FREQ_OFFSET FIELD16(0x00ff)
1610#define EEPROM_FREQ_LED_MODE FIELD16(0x7f00)
1611#define EEPROM_FREQ_LED_POLARITY FIELD16(0x1000)
1612
1613/*
1614 * EEPROM LED
1615 * POLARITY_RDY_G: Polarity RDY_G setting.
1616 * POLARITY_RDY_A: Polarity RDY_A setting.
1617 * POLARITY_ACT: Polarity ACT setting.
1618 * POLARITY_GPIO_0: Polarity GPIO0 setting.
1619 * POLARITY_GPIO_1: Polarity GPIO1 setting.
1620 * POLARITY_GPIO_2: Polarity GPIO2 setting.
1621 * POLARITY_GPIO_3: Polarity GPIO3 setting.
1622 * POLARITY_GPIO_4: Polarity GPIO4 setting.
1623 * LED_MODE: Led mode.
1624 */
1625#define EEPROM_LED1 0x001e
1626#define EEPROM_LED2 0x001f
1627#define EEPROM_LED3 0x0020
1628#define EEPROM_LED_POLARITY_RDY_BG FIELD16(0x0001)
1629#define EEPROM_LED_POLARITY_RDY_A FIELD16(0x0002)
1630#define EEPROM_LED_POLARITY_ACT FIELD16(0x0004)
1631#define EEPROM_LED_POLARITY_GPIO_0 FIELD16(0x0008)
1632#define EEPROM_LED_POLARITY_GPIO_1 FIELD16(0x0010)
1633#define EEPROM_LED_POLARITY_GPIO_2 FIELD16(0x0020)
1634#define EEPROM_LED_POLARITY_GPIO_3 FIELD16(0x0040)
1635#define EEPROM_LED_POLARITY_GPIO_4 FIELD16(0x0080)
1636#define EEPROM_LED_LED_MODE FIELD16(0x1f00)
1637
1638/*
1639 * EEPROM LNA
1640 */
1641#define EEPROM_LNA 0x0022
1642#define EEPROM_LNA_BG FIELD16(0x00ff)
1643#define EEPROM_LNA_A0 FIELD16(0xff00)
1644
1645/*
1646 * EEPROM RSSI BG offset
1647 */
1648#define EEPROM_RSSI_BG 0x0023
1649#define EEPROM_RSSI_BG_OFFSET0 FIELD16(0x00ff)
1650#define EEPROM_RSSI_BG_OFFSET1 FIELD16(0xff00)
1651
1652/*
1653 * EEPROM RSSI BG2 offset
1654 */
1655#define EEPROM_RSSI_BG2 0x0024
1656#define EEPROM_RSSI_BG2_OFFSET2 FIELD16(0x00ff)
1657#define EEPROM_RSSI_BG2_LNA_A1 FIELD16(0xff00)
1658
1659/*
1660 * EEPROM RSSI A offset
1661 */
1662#define EEPROM_RSSI_A 0x0025
1663#define EEPROM_RSSI_A_OFFSET0 FIELD16(0x00ff)
1664#define EEPROM_RSSI_A_OFFSET1 FIELD16(0xff00)
1665
1666/*
1667 * EEPROM RSSI A2 offset
1668 */
1669#define EEPROM_RSSI_A2 0x0026
1670#define EEPROM_RSSI_A2_OFFSET2 FIELD16(0x00ff)
1671#define EEPROM_RSSI_A2_LNA_A2 FIELD16(0xff00)
1672
1673/*
1674 * EEPROM TXpower delta: 20MHZ AND 40 MHZ use different power.
1675 * This is delta in 40MHZ.
1676 * VALUE: Tx Power dalta value (MAX=4)
1677 * TYPE: 1: Plus the delta value, 0: minus the delta value
1678 * TXPOWER: Enable:
1679 */
1680#define EEPROM_TXPOWER_DELTA 0x0028
1681#define EEPROM_TXPOWER_DELTA_VALUE FIELD16(0x003f)
1682#define EEPROM_TXPOWER_DELTA_TYPE FIELD16(0x0040)
1683#define EEPROM_TXPOWER_DELTA_TXPOWER FIELD16(0x0080)
1684
1685/*
1686 * EEPROM TXPOWER 802.11BG
1687 */
1688#define EEPROM_TXPOWER_BG1 0x0029
1689#define EEPROM_TXPOWER_BG2 0x0030
1690#define EEPROM_TXPOWER_BG_SIZE 7
1691#define EEPROM_TXPOWER_BG_1 FIELD16(0x00ff)
1692#define EEPROM_TXPOWER_BG_2 FIELD16(0xff00)
1693
1694/*
1695 * EEPROM TXPOWER 802.11A
1696 */
1697#define EEPROM_TXPOWER_A1 0x003c
1698#define EEPROM_TXPOWER_A2 0x0053
1699#define EEPROM_TXPOWER_A_SIZE 6
1700#define EEPROM_TXPOWER_A_1 FIELD16(0x00ff)
1701#define EEPROM_TXPOWER_A_2 FIELD16(0xff00)
1702
1703/*
1704 * EEPROM TXpower byrate: 20MHZ power
1705 */
1706#define EEPROM_TXPOWER_BYRATE 0x006f
1707
1708/*
1709 * EEPROM BBP.
1710 */
1711#define EEPROM_BBP_START 0x0078
1712#define EEPROM_BBP_SIZE 16
1713#define EEPROM_BBP_VALUE FIELD16(0x00ff)
1714#define EEPROM_BBP_REG_ID FIELD16(0xff00)
1715
1716/*
1717 * MCU mailbox commands.
1718 */
1719#define MCU_SLEEP 0x30
1720#define MCU_WAKEUP 0x31
1721#define MCU_RADIO_OFF 0x35
1722#define MCU_CURRENT 0x36
1723#define MCU_LED 0x50
1724#define MCU_LED_STRENGTH 0x51
1725#define MCU_LED_1 0x52
1726#define MCU_LED_2 0x53
1727#define MCU_LED_3 0x54
1728#define MCU_RADAR 0x60
1729#define MCU_BOOT_SIGNAL 0x72
1730#define MCU_BBP_SIGNAL 0x80
1731#define MCU_POWER_SAVE 0x83
1732
1733/*
1734 * MCU mailbox tokens
1735 */
1736#define TOKEN_WAKUP 3
1737
1738/*
1739 * DMA descriptor defines.
1740 */
1741#define TXD_DESC_SIZE ( 4 * sizeof(__le32) )
1742#define TXINFO_DESC_SIZE ( 1 * sizeof(__le32) )
1743#define TXWI_DESC_SIZE ( 4 * sizeof(__le32) )
1744#define RXD_DESC_SIZE ( 1 * sizeof(__le32) )
1745#define RXWI_DESC_SIZE ( 4 * sizeof(__le32) )
1746
1747/*
1748 * TX descriptor format for TX, PRIO and Beacon Ring.
1749 */
1750
1751/*
1752 * Word0
1753 */
1754#define TXD_W0_SD_PTR0 FIELD32(0xffffffff)
1755
1756/*
1757 * Word1
1758 */
1759#define TXD_W1_SD_LEN1 FIELD32(0x00003fff)
1760#define TXD_W1_LAST_SEC1 FIELD32(0x00004000)
1761#define TXD_W1_BURST FIELD32(0x00008000)
1762#define TXD_W1_SD_LEN0 FIELD32(0x3fff0000)
1763#define TXD_W1_LAST_SEC0 FIELD32(0x40000000)
1764#define TXD_W1_DMA_DONE FIELD32(0x80000000)
1765
1766/*
1767 * Word2
1768 */
1769#define TXD_W2_SD_PTR1 FIELD32(0xffffffff)
1770
1771/*
1772 * Word3
1773 * WIV: Wireless Info Valid. 1: Driver filled WI, 0: DMA needs to copy WI
1774 * QSEL: Select on-chip FIFO ID for 2nd-stage output scheduler.
1775 * 0:MGMT, 1:HCCA 2:EDCA
1776 */
1777#define TXD_W3_WIV FIELD32(0x01000000)
1778#define TXD_W3_QSEL FIELD32(0x06000000)
1779#define TXD_W3_TCO FIELD32(0x20000000)
1780#define TXD_W3_UCO FIELD32(0x40000000)
1781#define TXD_W3_ICO FIELD32(0x80000000)
1782
1783/*
1784 * TX Info structure
1785 */
1786
1787/*
1788 * Word0
1789 * WIV: Wireless Info Valid. 1: Driver filled WI, 0: DMA needs to copy WI
1790 * QSEL: Select on-chip FIFO ID for 2nd-stage output scheduler.
1791 * 0:MGMT, 1:HCCA 2:EDCA
1792 * USB_DMA_NEXT_VALID: Used ONLY in USB bulk Aggregation, NextValid
1793 * DMA_TX_BURST: used ONLY in USB bulk Aggregation.
1794 * Force USB DMA transmit frame from current selected endpoint
1795 */
1796#define TXINFO_W0_USB_DMA_TX_PKT_LEN FIELD32(0x0000ffff)
1797#define TXINFO_W0_WIV FIELD32(0x01000000)
1798#define TXINFO_W0_QSEL FIELD32(0x06000000)
1799#define TXINFO_W0_SW_USE_LAST_ROUND FIELD32(0x08000000)
1800#define TXINFO_W0_USB_DMA_NEXT_VALID FIELD32(0x40000000)
1801#define TXINFO_W0_USB_DMA_TX_BURST FIELD32(0x80000000)
1802
1803/*
1804 * TX WI structure
1805 */
1806
1807/*
1808 * Word0
1809 * FRAG: 1 To inform TKIP engine this is a fragment.
1810 * MIMO_PS: The remote peer is in dynamic MIMO-PS mode
1811 * TX_OP: 0:HT TXOP rule , 1:PIFS TX ,2:Backoff, 3:sifs
1812 * BW: Channel bandwidth 20MHz or 40 MHz
1813 * STBC: 1: STBC support MCS =0-7, 2,3 : RESERVED
1814 */
1815#define TXWI_W0_FRAG FIELD32(0x00000001)
1816#define TXWI_W0_MIMO_PS FIELD32(0x00000002)
1817#define TXWI_W0_CF_ACK FIELD32(0x00000004)
1818#define TXWI_W0_TS FIELD32(0x00000008)
1819#define TXWI_W0_AMPDU FIELD32(0x00000010)
1820#define TXWI_W0_MPDU_DENSITY FIELD32(0x000000e0)
1821#define TXWI_W0_TX_OP FIELD32(0x00000300)
1822#define TXWI_W0_MCS FIELD32(0x007f0000)
1823#define TXWI_W0_BW FIELD32(0x00800000)
1824#define TXWI_W0_SHORT_GI FIELD32(0x01000000)
1825#define TXWI_W0_STBC FIELD32(0x06000000)
1826#define TXWI_W0_IFS FIELD32(0x08000000)
1827#define TXWI_W0_PHYMODE FIELD32(0xc0000000)
1828
1829/*
1830 * Word1
1831 */
1832#define TXWI_W1_ACK FIELD32(0x00000001)
1833#define TXWI_W1_NSEQ FIELD32(0x00000002)
1834#define TXWI_W1_BW_WIN_SIZE FIELD32(0x000000fc)
1835#define TXWI_W1_WIRELESS_CLI_ID FIELD32(0x0000ff00)
1836#define TXWI_W1_MPDU_TOTAL_BYTE_COUNT FIELD32(0x0fff0000)
1837#define TXWI_W1_PACKETID FIELD32(0xf0000000)
1838
1839/*
1840 * Word2
1841 */
1842#define TXWI_W2_IV FIELD32(0xffffffff)
1843
1844/*
1845 * Word3
1846 */
1847#define TXWI_W3_EIV FIELD32(0xffffffff)
1848
1849/*
1850 * RX descriptor format for RX Ring.
1851 */
1852
1853/*
1854 * Word0
1855 * UNICAST_TO_ME: This RX frame is unicast to me.
1856 * MULTICAST: This is a multicast frame.
1857 * BROADCAST: This is a broadcast frame.
1858 * MY_BSS: this frame belongs to the same BSSID.
1859 * CRC_ERROR: CRC error.
1860 * CIPHER_ERROR: 0: decryption okay, 1:ICV error, 2:MIC error, 3:KEY not valid.
1861 * AMSDU: rx with 802.3 header, not 802.11 header.
1862 */
1863
1864#define RXD_W0_BA FIELD32(0x00000001)
1865#define RXD_W0_DATA FIELD32(0x00000002)
1866#define RXD_W0_NULLDATA FIELD32(0x00000004)
1867#define RXD_W0_FRAG FIELD32(0x00000008)
1868#define RXD_W0_UNICAST_TO_ME FIELD32(0x00000010)
1869#define RXD_W0_MULTICAST FIELD32(0x00000020)
1870#define RXD_W0_BROADCAST FIELD32(0x00000040)
1871#define RXD_W0_MY_BSS FIELD32(0x00000080)
1872#define RXD_W0_CRC_ERROR FIELD32(0x00000100)
1873#define RXD_W0_CIPHER_ERROR FIELD32(0x00000600)
1874#define RXD_W0_AMSDU FIELD32(0x00000800)
1875#define RXD_W0_HTC FIELD32(0x00001000)
1876#define RXD_W0_RSSI FIELD32(0x00002000)
1877#define RXD_W0_L2PAD FIELD32(0x00004000)
1878#define RXD_W0_AMPDU FIELD32(0x00008000)
1879#define RXD_W0_DECRYPTED FIELD32(0x00010000)
1880#define RXD_W0_PLCP_RSSI FIELD32(0x00020000)
1881#define RXD_W0_CIPHER_ALG FIELD32(0x00040000)
1882#define RXD_W0_LAST_AMSDU FIELD32(0x00080000)
1883#define RXD_W0_PLCP_SIGNAL FIELD32(0xfff00000)
1884
1885/*
1886 * RX WI structure
1887 */
1888
1889/*
1890 * Word0
1891 */
1892#define RXWI_W0_WIRELESS_CLI_ID FIELD32(0x000000ff)
1893#define RXWI_W0_KEY_INDEX FIELD32(0x00000300)
1894#define RXWI_W0_BSSID FIELD32(0x00001c00)
1895#define RXWI_W0_UDF FIELD32(0x0000e000)
1896#define RXWI_W0_MPDU_TOTAL_BYTE_COUNT FIELD32(0x0fff0000)
1897#define RXWI_W0_TID FIELD32(0xf0000000)
1898
1899/*
1900 * Word1
1901 */
1902#define RXWI_W1_FRAG FIELD32(0x0000000f)
1903#define RXWI_W1_SEQUENCE FIELD32(0x0000fff0)
1904#define RXWI_W1_MCS FIELD32(0x007f0000)
1905#define RXWI_W1_BW FIELD32(0x00800000)
1906#define RXWI_W1_SHORT_GI FIELD32(0x01000000)
1907#define RXWI_W1_STBC FIELD32(0x06000000)
1908#define RXWI_W1_PHYMODE FIELD32(0xc0000000)
1909
1910/*
1911 * Word2
1912 */
1913#define RXWI_W2_RSSI0 FIELD32(0x000000ff)
1914#define RXWI_W2_RSSI1 FIELD32(0x0000ff00)
1915#define RXWI_W2_RSSI2 FIELD32(0x00ff0000)
1916
1917/*
1918 * Word3
1919 */
1920#define RXWI_W3_SNR0 FIELD32(0x000000ff)
1921#define RXWI_W3_SNR1 FIELD32(0x0000ff00)
1922
1923/*
1924 * Macro's for converting txpower from EEPROM to mac80211 value
1925 * and from mac80211 value to register value.
1926 */
1927#define MIN_G_TXPOWER 0
1928#define MIN_A_TXPOWER -7
1929#define MAX_G_TXPOWER 31
1930#define MAX_A_TXPOWER 15
1931#define DEFAULT_TXPOWER 5
1932
1933#define TXPOWER_G_FROM_DEV(__txpower) \
1934 ((__txpower) > MAX_G_TXPOWER) ? DEFAULT_TXPOWER : (__txpower)
1935
1936#define TXPOWER_G_TO_DEV(__txpower) \
1937 clamp_t(char, __txpower, MIN_G_TXPOWER, MAX_G_TXPOWER)
1938
1939#define TXPOWER_A_FROM_DEV(__txpower) \
1940 ((__txpower) > MAX_A_TXPOWER) ? DEFAULT_TXPOWER : (__txpower)
1941
1942#define TXPOWER_A_TO_DEV(__txpower) \
1943 clamp_t(char, __txpower, MIN_A_TXPOWER, MAX_A_TXPOWER)
1944
1945#endif /* RT2800USB_H */
diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
index e03d69975ea4..419b1b9f998e 100644
--- a/drivers/net/wireless/rt2x00/rt2x00.h
+++ b/drivers/net/wireless/rt2x00/rt2x00.h
@@ -103,6 +103,15 @@
103#define GET_DURATION_RES(__size, __rate)(((__size) * 8 * 10) % (__rate)) 103#define GET_DURATION_RES(__size, __rate)(((__size) * 8 * 10) % (__rate))
104 104
105/* 105/*
106 * Determine the alignment requirement,
107 * to make sure the 802.11 payload is padded to a 4-byte boundrary
108 * we must determine the address of the payload and calculate the
109 * amount of bytes needed to move the data.
110 */
111#define ALIGN_SIZE(__skb, __header) \
112 ( ((unsigned long)((__skb)->data + (__header))) & 3 )
113
114/*
106 * Standard timing and size defines. 115 * Standard timing and size defines.
107 * These values should follow the ieee80211 specifications. 116 * These values should follow the ieee80211 specifications.
108 */ 117 */
@@ -138,6 +147,7 @@ struct rt2x00_chip {
138#define RT2561 0x0302 147#define RT2561 0x0302
139#define RT2661 0x0401 148#define RT2661 0x0401
140#define RT2571 0x1300 149#define RT2571 0x1300
150#define RT2870 0x1600
141 151
142 u16 rf; 152 u16 rf;
143 u32 rev; 153 u32 rev;
@@ -357,6 +367,7 @@ static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
357 * for @tx_power_a, @tx_power_bg and @channels. 367 * for @tx_power_a, @tx_power_bg and @channels.
358 * @channels: Device/chipset specific channel values (See &struct rf_channel). 368 * @channels: Device/chipset specific channel values (See &struct rf_channel).
359 * @channels_info: Additional information for channels (See &struct channel_info). 369 * @channels_info: Additional information for channels (See &struct channel_info).
370 * @ht: Driver HT Capabilities (See &ieee80211_sta_ht_cap).
360 */ 371 */
361struct hw_mode_spec { 372struct hw_mode_spec {
362 unsigned int supported_bands; 373 unsigned int supported_bands;
@@ -370,6 +381,8 @@ struct hw_mode_spec {
370 unsigned int num_channels; 381 unsigned int num_channels;
371 const struct rf_channel *channels; 382 const struct rf_channel *channels;
372 const struct channel_info *channels_info; 383 const struct channel_info *channels_info;
384
385 struct ieee80211_sta_ht_cap ht;
373}; 386};
374 387
375/* 388/*
@@ -590,6 +603,7 @@ enum rt2x00_flags {
590 DRIVER_REQUIRE_SCHEDULED, 603 DRIVER_REQUIRE_SCHEDULED,
591 DRIVER_REQUIRE_DMA, 604 DRIVER_REQUIRE_DMA,
592 DRIVER_REQUIRE_COPY_IV, 605 DRIVER_REQUIRE_COPY_IV,
606 DRIVER_REQUIRE_L2PAD,
593 607
594 /* 608 /*
595 * Driver features 609 * Driver features
@@ -606,6 +620,7 @@ enum rt2x00_flags {
606 CONFIG_EXTERNAL_LNA_BG, 620 CONFIG_EXTERNAL_LNA_BG,
607 CONFIG_DOUBLE_ANTENNA, 621 CONFIG_DOUBLE_ANTENNA,
608 CONFIG_DISABLE_LINK_TUNING, 622 CONFIG_DISABLE_LINK_TUNING,
623 CONFIG_CHANNEL_HT40,
609}; 624};
610 625
611/* 626/*
@@ -778,6 +793,13 @@ struct rt2x00_dev {
778 u8 freq_offset; 793 u8 freq_offset;
779 794
780 /* 795 /*
796 * Calibration information (for rt2800usb & rt2800pci).
797 * [0] -> BW20
798 * [1] -> BW40
799 */
800 u8 calibration[2];
801
802 /*
781 * Low level statistics which will have 803 * Low level statistics which will have
782 * to be kept up to date while device is running. 804 * to be kept up to date while device is running.
783 */ 805 */
@@ -893,11 +915,10 @@ static inline u32 rt2x00_rev(const struct rt2x00_chip *chipset)
893 return chipset->rev; 915 return chipset->rev;
894} 916}
895 917
896static inline u16 rt2x00_check_rev(const struct rt2x00_chip *chipset, 918static inline bool rt2x00_check_rev(const struct rt2x00_chip *chipset,
897 const u32 rev) 919 const u32 mask, const u32 rev)
898{ 920{
899 return (((chipset->rev & 0xffff0) == rev) && 921 return ((chipset->rev & mask) == rev);
900 !!(chipset->rev & 0x0000f));
901} 922}
902 923
903/** 924/**
@@ -943,9 +964,6 @@ int rt2x00mac_add_interface(struct ieee80211_hw *hw,
943void rt2x00mac_remove_interface(struct ieee80211_hw *hw, 964void rt2x00mac_remove_interface(struct ieee80211_hw *hw,
944 struct ieee80211_if_init_conf *conf); 965 struct ieee80211_if_init_conf *conf);
945int rt2x00mac_config(struct ieee80211_hw *hw, u32 changed); 966int rt2x00mac_config(struct ieee80211_hw *hw, u32 changed);
946int rt2x00mac_config_interface(struct ieee80211_hw *hw,
947 struct ieee80211_vif *vif,
948 struct ieee80211_if_conf *conf);
949void rt2x00mac_configure_filter(struct ieee80211_hw *hw, 967void rt2x00mac_configure_filter(struct ieee80211_hw *hw,
950 unsigned int changed_flags, 968 unsigned int changed_flags,
951 unsigned int *total_flags, 969 unsigned int *total_flags,
diff --git a/drivers/net/wireless/rt2x00/rt2x00config.c b/drivers/net/wireless/rt2x00/rt2x00config.c
index 9c2f5517af2a..863e399d4fa6 100644
--- a/drivers/net/wireless/rt2x00/rt2x00config.c
+++ b/drivers/net/wireless/rt2x00/rt2x00config.c
@@ -173,6 +173,11 @@ void rt2x00lib_config(struct rt2x00_dev *rt2x00dev,
173 libconf.conf = conf; 173 libconf.conf = conf;
174 174
175 if (ieee80211_flags & IEEE80211_CONF_CHANGE_CHANNEL) { 175 if (ieee80211_flags & IEEE80211_CONF_CHANGE_CHANNEL) {
176 if (conf_is_ht40(conf))
177 __set_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags);
178 else
179 __clear_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags);
180
176 memcpy(&libconf.rf, 181 memcpy(&libconf.rf,
177 &rt2x00dev->spec.channels[conf->channel->hw_value], 182 &rt2x00dev->spec.channels[conf->channel->hw_value],
178 sizeof(libconf.rf)); 183 sizeof(libconf.rf));
diff --git a/drivers/net/wireless/rt2x00/rt2x00crypto.c b/drivers/net/wireless/rt2x00/rt2x00crypto.c
index 0b41845d9543..57ab42cfed34 100644
--- a/drivers/net/wireless/rt2x00/rt2x00crypto.c
+++ b/drivers/net/wireless/rt2x00/rt2x00crypto.c
@@ -65,7 +65,8 @@ void rt2x00crypto_create_tx_descriptor(struct queue_entry *entry,
65 __set_bit(ENTRY_TXD_ENCRYPT_PAIRWISE, &txdesc->flags); 65 __set_bit(ENTRY_TXD_ENCRYPT_PAIRWISE, &txdesc->flags);
66 66
67 txdesc->key_idx = hw_key->hw_key_idx; 67 txdesc->key_idx = hw_key->hw_key_idx;
68 txdesc->iv_offset = ieee80211_get_hdrlen_from_skb(entry->skb); 68 txdesc->iv_offset = txdesc->header_length;
69 txdesc->iv_len = hw_key->iv_len;
69 70
70 if (!(hw_key->flags & IEEE80211_KEY_FLAG_GENERATE_IV)) 71 if (!(hw_key->flags & IEEE80211_KEY_FLAG_GENERATE_IV))
71 __set_bit(ENTRY_TXD_ENCRYPT_IV, &txdesc->flags); 72 __set_bit(ENTRY_TXD_ENCRYPT_IV, &txdesc->flags);
@@ -103,47 +104,44 @@ unsigned int rt2x00crypto_tx_overhead(struct rt2x00_dev *rt2x00dev,
103 return overhead; 104 return overhead;
104} 105}
105 106
106void rt2x00crypto_tx_copy_iv(struct sk_buff *skb, unsigned int iv_len) 107void rt2x00crypto_tx_copy_iv(struct sk_buff *skb, struct txentry_desc *txdesc)
107{ 108{
108 struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb); 109 struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb);
109 unsigned int header_length = ieee80211_get_hdrlen_from_skb(skb);
110 110
111 if (unlikely(!iv_len)) 111 if (unlikely(!txdesc->iv_len))
112 return; 112 return;
113 113
114 /* Copy IV/EIV data */ 114 /* Copy IV/EIV data */
115 memcpy(skbdesc->iv, skb->data + header_length, iv_len); 115 memcpy(skbdesc->iv, skb->data + txdesc->iv_offset, txdesc->iv_len);
116} 116}
117 117
118void rt2x00crypto_tx_remove_iv(struct sk_buff *skb, unsigned int iv_len) 118void rt2x00crypto_tx_remove_iv(struct sk_buff *skb, struct txentry_desc *txdesc)
119{ 119{
120 struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb); 120 struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb);
121 unsigned int header_length = ieee80211_get_hdrlen_from_skb(skb);
122 121
123 if (unlikely(!iv_len)) 122 if (unlikely(!txdesc->iv_len))
124 return; 123 return;
125 124
126 /* Copy IV/EIV data */ 125 /* Copy IV/EIV data */
127 memcpy(skbdesc->iv, skb->data + header_length, iv_len); 126 memcpy(skbdesc->iv, skb->data + txdesc->iv_offset, txdesc->iv_len);
128 127
129 /* Move ieee80211 header */ 128 /* Move ieee80211 header */
130 memmove(skb->data + iv_len, skb->data, header_length); 129 memmove(skb->data + txdesc->iv_len, skb->data, txdesc->iv_offset);
131 130
132 /* Pull buffer to correct size */ 131 /* Pull buffer to correct size */
133 skb_pull(skb, iv_len); 132 skb_pull(skb, txdesc->iv_len);
134 133
135 /* IV/EIV data has officially be stripped */ 134 /* IV/EIV data has officially be stripped */
136 skbdesc->flags |= FRAME_DESC_IV_STRIPPED; 135 skbdesc->flags |= SKBDESC_IV_STRIPPED;
137} 136}
138 137
139void rt2x00crypto_tx_insert_iv(struct sk_buff *skb) 138void rt2x00crypto_tx_insert_iv(struct sk_buff *skb, unsigned int header_length)
140{ 139{
141 struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb); 140 struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb);
142 unsigned int header_length = ieee80211_get_hdrlen_from_skb(skb);
143 const unsigned int iv_len = 141 const unsigned int iv_len =
144 ((!!(skbdesc->iv[0])) * 4) + ((!!(skbdesc->iv[1])) * 4); 142 ((!!(skbdesc->iv[0])) * 4) + ((!!(skbdesc->iv[1])) * 4);
145 143
146 if (!(skbdesc->flags & FRAME_DESC_IV_STRIPPED)) 144 if (!(skbdesc->flags & SKBDESC_IV_STRIPPED))
147 return; 145 return;
148 146
149 skb_push(skb, iv_len); 147 skb_push(skb, iv_len);
@@ -155,14 +153,15 @@ void rt2x00crypto_tx_insert_iv(struct sk_buff *skb)
155 memcpy(skb->data + header_length, skbdesc->iv, iv_len); 153 memcpy(skb->data + header_length, skbdesc->iv, iv_len);
156 154
157 /* IV/EIV data has returned into the frame */ 155 /* IV/EIV data has returned into the frame */
158 skbdesc->flags &= ~FRAME_DESC_IV_STRIPPED; 156 skbdesc->flags &= ~SKBDESC_IV_STRIPPED;
159} 157}
160 158
161void rt2x00crypto_rx_insert_iv(struct sk_buff *skb, unsigned int align, 159void rt2x00crypto_rx_insert_iv(struct sk_buff *skb, bool l2pad,
162 unsigned int header_length, 160 unsigned int header_length,
163 struct rxdone_entry_desc *rxdesc) 161 struct rxdone_entry_desc *rxdesc)
164{ 162{
165 unsigned int payload_len = rxdesc->size - header_length; 163 unsigned int payload_len = rxdesc->size - header_length;
164 unsigned int align = ALIGN_SIZE(skb, header_length);
166 unsigned int iv_len; 165 unsigned int iv_len;
167 unsigned int icv_len; 166 unsigned int icv_len;
168 unsigned int transfer = 0; 167 unsigned int transfer = 0;
@@ -192,32 +191,48 @@ void rt2x00crypto_rx_insert_iv(struct sk_buff *skb, unsigned int align,
192 } 191 }
193 192
194 /* 193 /*
195 * Make room for new data, note that we increase both 194 * Make room for new data. There are 2 possibilities
196 * headsize and tailsize when required. The tailsize is 195 * either the alignment is already present between
197 * only needed when ICV data needs to be inserted and 196 * the 802.11 header and payload. In that case we
198 * the padding is smaller than the ICV data. 197 * we have to move the header less then the iv_len
199 * When alignment requirements is greater than the 198 * since we can use the already available l2pad bytes
200 * ICV data we must trim the skb to the correct size 199 * for the iv data.
201 * because we need to remove the extra bytes. 200 * When the alignment must be added manually we must
201 * move the header more then iv_len since we must
202 * make room for the payload move as well.
202 */ 203 */
203 skb_push(skb, iv_len + align); 204 if (l2pad) {
204 if (align < icv_len) 205 skb_push(skb, iv_len - align);
205 skb_put(skb, icv_len - align); 206 skb_put(skb, icv_len);
206 else if (align > icv_len)
207 skb_trim(skb, rxdesc->size + iv_len + icv_len);
208 207
209 /* Move ieee80211 header */ 208 /* Move ieee80211 header */
210 memmove(skb->data + transfer, 209 memmove(skb->data + transfer,
211 skb->data + transfer + iv_len + align, 210 skb->data + transfer + (iv_len - align),
212 header_length); 211 header_length);
213 transfer += header_length; 212 transfer += header_length;
213 } else {
214 skb_push(skb, iv_len + align);
215 if (align < icv_len)
216 skb_put(skb, icv_len - align);
217 else if (align > icv_len)
218 skb_trim(skb, rxdesc->size + iv_len + icv_len);
219
220 /* Move ieee80211 header */
221 memmove(skb->data + transfer,
222 skb->data + transfer + iv_len + align,
223 header_length);
224 transfer += header_length;
225 }
214 226
215 /* Copy IV/EIV data */ 227 /* Copy IV/EIV data */
216 memcpy(skb->data + transfer, rxdesc->iv, iv_len); 228 memcpy(skb->data + transfer, rxdesc->iv, iv_len);
217 transfer += iv_len; 229 transfer += iv_len;
218 230
219 /* Move payload */ 231 /*
220 if (align) { 232 * Move payload for alignment purposes. Note that
233 * this is only needed when no l2 padding is present.
234 */
235 if (!l2pad) {
221 memmove(skb->data + transfer, 236 memmove(skb->data + transfer,
222 skb->data + transfer + align, 237 skb->data + transfer + align,
223 payload_len); 238 payload_len);
diff --git a/drivers/net/wireless/rt2x00/rt2x00dev.c b/drivers/net/wireless/rt2x00/rt2x00dev.c
index 5752aaae906b..f2270845072a 100644
--- a/drivers/net/wireless/rt2x00/rt2x00dev.c
+++ b/drivers/net/wireless/rt2x00/rt2x00dev.c
@@ -227,6 +227,7 @@ void rt2x00lib_txdone(struct queue_entry *entry,
227 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(entry->skb); 227 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(entry->skb);
228 struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb); 228 struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
229 enum data_queue_qid qid = skb_get_queue_mapping(entry->skb); 229 enum data_queue_qid qid = skb_get_queue_mapping(entry->skb);
230 unsigned int header_length = ieee80211_get_hdrlen_from_skb(entry->skb);
230 u8 rate_idx, rate_flags; 231 u8 rate_idx, rate_flags;
231 232
232 /* 233 /*
@@ -235,13 +236,19 @@ void rt2x00lib_txdone(struct queue_entry *entry,
235 rt2x00queue_unmap_skb(rt2x00dev, entry->skb); 236 rt2x00queue_unmap_skb(rt2x00dev, entry->skb);
236 237
237 /* 238 /*
239 * Remove L2 padding which was added during
240 */
241 if (test_bit(DRIVER_REQUIRE_L2PAD, &rt2x00dev->flags))
242 rt2x00queue_payload_align(entry->skb, true, header_length);
243
244 /*
238 * If the IV/EIV data was stripped from the frame before it was 245 * If the IV/EIV data was stripped from the frame before it was
239 * passed to the hardware, we should now reinsert it again because 246 * passed to the hardware, we should now reinsert it again because
240 * mac80211 will expect the the same data to be present it the 247 * mac80211 will expect the the same data to be present it the
241 * frame as it was passed to us. 248 * frame as it was passed to us.
242 */ 249 */
243 if (test_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags)) 250 if (test_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags))
244 rt2x00crypto_tx_insert_iv(entry->skb); 251 rt2x00crypto_tx_insert_iv(entry->skb, header_length);
245 252
246 /* 253 /*
247 * Send frame to debugfs immediately, after this call is completed 254 * Send frame to debugfs immediately, after this call is completed
@@ -316,19 +323,54 @@ void rt2x00lib_txdone(struct queue_entry *entry,
316} 323}
317EXPORT_SYMBOL_GPL(rt2x00lib_txdone); 324EXPORT_SYMBOL_GPL(rt2x00lib_txdone);
318 325
326static int rt2x00lib_rxdone_read_signal(struct rt2x00_dev *rt2x00dev,
327 struct rxdone_entry_desc *rxdesc)
328{
329 struct ieee80211_supported_band *sband;
330 const struct rt2x00_rate *rate;
331 unsigned int i;
332 int signal;
333 int type;
334
335 /*
336 * For non-HT rates the MCS value needs to contain the
337 * actually used rate modulation (CCK or OFDM).
338 */
339 if (rxdesc->dev_flags & RXDONE_SIGNAL_MCS)
340 signal = RATE_MCS(rxdesc->rate_mode, rxdesc->signal);
341 else
342 signal = rxdesc->signal;
343
344 type = (rxdesc->dev_flags & RXDONE_SIGNAL_MASK);
345
346 sband = &rt2x00dev->bands[rt2x00dev->curr_band];
347 for (i = 0; i < sband->n_bitrates; i++) {
348 rate = rt2x00_get_rate(sband->bitrates[i].hw_value);
349
350 if (((type == RXDONE_SIGNAL_PLCP) &&
351 (rate->plcp == signal)) ||
352 ((type == RXDONE_SIGNAL_BITRATE) &&
353 (rate->bitrate == signal)) ||
354 ((type == RXDONE_SIGNAL_MCS) &&
355 (rate->mcs == signal))) {
356 return i;
357 }
358 }
359
360 WARNING(rt2x00dev, "Frame received with unrecognized signal, "
361 "signal=0x%.4x, type=%d.\n", signal, type);
362 return 0;
363}
364
319void rt2x00lib_rxdone(struct rt2x00_dev *rt2x00dev, 365void rt2x00lib_rxdone(struct rt2x00_dev *rt2x00dev,
320 struct queue_entry *entry) 366 struct queue_entry *entry)
321{ 367{
322 struct rxdone_entry_desc rxdesc; 368 struct rxdone_entry_desc rxdesc;
323 struct sk_buff *skb; 369 struct sk_buff *skb;
324 struct ieee80211_rx_status *rx_status = &rt2x00dev->rx_status; 370 struct ieee80211_rx_status *rx_status = &rt2x00dev->rx_status;
325 struct ieee80211_supported_band *sband;
326 const struct rt2x00_rate *rate;
327 unsigned int header_length; 371 unsigned int header_length;
328 unsigned int align; 372 bool l2pad;
329 unsigned int i; 373 int rate_idx;
330 int idx = -1;
331
332 /* 374 /*
333 * Allocate a new sk_buffer. If no new buffer available, drop the 375 * Allocate a new sk_buffer. If no new buffer available, drop the
334 * received frame and reuse the existing buffer. 376 * received frame and reuse the existing buffer.
@@ -348,12 +390,15 @@ void rt2x00lib_rxdone(struct rt2x00_dev *rt2x00dev,
348 memset(&rxdesc, 0, sizeof(rxdesc)); 390 memset(&rxdesc, 0, sizeof(rxdesc));
349 rt2x00dev->ops->lib->fill_rxdone(entry, &rxdesc); 391 rt2x00dev->ops->lib->fill_rxdone(entry, &rxdesc);
350 392
393 /* Trim buffer to correct size */
394 skb_trim(entry->skb, rxdesc.size);
395
351 /* 396 /*
352 * The data behind the ieee80211 header must be 397 * The data behind the ieee80211 header must be
353 * aligned on a 4 byte boundary. 398 * aligned on a 4 byte boundary.
354 */ 399 */
355 header_length = ieee80211_get_hdrlen_from_skb(entry->skb); 400 header_length = ieee80211_get_hdrlen_from_skb(entry->skb);
356 align = ((unsigned long)(entry->skb->data + header_length)) & 3; 401 l2pad = !!(rxdesc.dev_flags & RXDONE_L2PAD);
357 402
358 /* 403 /*
359 * Hardware might have stripped the IV/EIV/ICV data, 404 * Hardware might have stripped the IV/EIV/ICV data,
@@ -362,40 +407,24 @@ void rt2x00lib_rxdone(struct rt2x00_dev *rt2x00dev,
362 * in which case we should reinsert the data into the frame. 407 * in which case we should reinsert the data into the frame.
363 */ 408 */
364 if ((rxdesc.dev_flags & RXDONE_CRYPTO_IV) && 409 if ((rxdesc.dev_flags & RXDONE_CRYPTO_IV) &&
365 (rxdesc.flags & RX_FLAG_IV_STRIPPED)) { 410 (rxdesc.flags & RX_FLAG_IV_STRIPPED))
366 rt2x00crypto_rx_insert_iv(entry->skb, align, 411 rt2x00crypto_rx_insert_iv(entry->skb, l2pad, header_length,
367 header_length, &rxdesc); 412 &rxdesc);
368 } else if (align) { 413 else
369 skb_push(entry->skb, align); 414 rt2x00queue_payload_align(entry->skb, l2pad, header_length);
370 /* Move entire frame in 1 command */
371 memmove(entry->skb->data, entry->skb->data + align,
372 rxdesc.size);
373 }
374
375 /* Update data pointers, trim buffer to correct size */
376 skb_trim(entry->skb, rxdesc.size);
377 415
378 /* 416 /*
379 * Update RX statistics. 417 * Check if the frame was received using HT. In that case,
418 * the rate is the MCS index and should be passed to mac80211
419 * directly. Otherwise we need to translate the signal to
420 * the correct bitrate index.
380 */ 421 */
381 sband = &rt2x00dev->bands[rt2x00dev->curr_band]; 422 if (rxdesc.rate_mode == RATE_MODE_CCK ||
382 for (i = 0; i < sband->n_bitrates; i++) { 423 rxdesc.rate_mode == RATE_MODE_OFDM) {
383 rate = rt2x00_get_rate(sband->bitrates[i].hw_value); 424 rate_idx = rt2x00lib_rxdone_read_signal(rt2x00dev, &rxdesc);
384 425 } else {
385 if (((rxdesc.dev_flags & RXDONE_SIGNAL_PLCP) && 426 rxdesc.flags |= RX_FLAG_HT;
386 (rate->plcp == rxdesc.signal)) || 427 rate_idx = rxdesc.signal;
387 ((rxdesc.dev_flags & RXDONE_SIGNAL_BITRATE) &&
388 (rate->bitrate == rxdesc.signal))) {
389 idx = i;
390 break;
391 }
392 }
393
394 if (idx < 0) {
395 WARNING(rt2x00dev, "Frame received with unrecognized signal,"
396 "signal=0x%.2x, type=%d.\n", rxdesc.signal,
397 (rxdesc.dev_flags & RXDONE_SIGNAL_MASK));
398 idx = 0;
399 } 428 }
400 429
401 /* 430 /*
@@ -405,7 +434,7 @@ void rt2x00lib_rxdone(struct rt2x00_dev *rt2x00dev,
405 rt2x00debug_update_crypto(rt2x00dev, &rxdesc); 434 rt2x00debug_update_crypto(rt2x00dev, &rxdesc);
406 435
407 rx_status->mactime = rxdesc.timestamp; 436 rx_status->mactime = rxdesc.timestamp;
408 rx_status->rate_idx = idx; 437 rx_status->rate_idx = rate_idx;
409 rx_status->qual = rt2x00link_calculate_signal(rt2x00dev, rxdesc.rssi); 438 rx_status->qual = rt2x00link_calculate_signal(rt2x00dev, rxdesc.rssi);
410 rx_status->signal = rxdesc.rssi; 439 rx_status->signal = rxdesc.rssi;
411 rx_status->noise = rxdesc.noise; 440 rx_status->noise = rxdesc.noise;
@@ -440,72 +469,84 @@ const struct rt2x00_rate rt2x00_supported_rates[12] = {
440 .bitrate = 10, 469 .bitrate = 10,
441 .ratemask = BIT(0), 470 .ratemask = BIT(0),
442 .plcp = 0x00, 471 .plcp = 0x00,
472 .mcs = RATE_MCS(RATE_MODE_CCK, 0),
443 }, 473 },
444 { 474 {
445 .flags = DEV_RATE_CCK | DEV_RATE_SHORT_PREAMBLE, 475 .flags = DEV_RATE_CCK | DEV_RATE_SHORT_PREAMBLE,
446 .bitrate = 20, 476 .bitrate = 20,
447 .ratemask = BIT(1), 477 .ratemask = BIT(1),
448 .plcp = 0x01, 478 .plcp = 0x01,
479 .mcs = RATE_MCS(RATE_MODE_CCK, 1),
449 }, 480 },
450 { 481 {
451 .flags = DEV_RATE_CCK | DEV_RATE_SHORT_PREAMBLE, 482 .flags = DEV_RATE_CCK | DEV_RATE_SHORT_PREAMBLE,
452 .bitrate = 55, 483 .bitrate = 55,
453 .ratemask = BIT(2), 484 .ratemask = BIT(2),
454 .plcp = 0x02, 485 .plcp = 0x02,
486 .mcs = RATE_MCS(RATE_MODE_CCK, 2),
455 }, 487 },
456 { 488 {
457 .flags = DEV_RATE_CCK | DEV_RATE_SHORT_PREAMBLE, 489 .flags = DEV_RATE_CCK | DEV_RATE_SHORT_PREAMBLE,
458 .bitrate = 110, 490 .bitrate = 110,
459 .ratemask = BIT(3), 491 .ratemask = BIT(3),
460 .plcp = 0x03, 492 .plcp = 0x03,
493 .mcs = RATE_MCS(RATE_MODE_CCK, 3),
461 }, 494 },
462 { 495 {
463 .flags = DEV_RATE_OFDM, 496 .flags = DEV_RATE_OFDM,
464 .bitrate = 60, 497 .bitrate = 60,
465 .ratemask = BIT(4), 498 .ratemask = BIT(4),
466 .plcp = 0x0b, 499 .plcp = 0x0b,
500 .mcs = RATE_MCS(RATE_MODE_OFDM, 0),
467 }, 501 },
468 { 502 {
469 .flags = DEV_RATE_OFDM, 503 .flags = DEV_RATE_OFDM,
470 .bitrate = 90, 504 .bitrate = 90,
471 .ratemask = BIT(5), 505 .ratemask = BIT(5),
472 .plcp = 0x0f, 506 .plcp = 0x0f,
507 .mcs = RATE_MCS(RATE_MODE_OFDM, 1),
473 }, 508 },
474 { 509 {
475 .flags = DEV_RATE_OFDM, 510 .flags = DEV_RATE_OFDM,
476 .bitrate = 120, 511 .bitrate = 120,
477 .ratemask = BIT(6), 512 .ratemask = BIT(6),
478 .plcp = 0x0a, 513 .plcp = 0x0a,
514 .mcs = RATE_MCS(RATE_MODE_OFDM, 2),
479 }, 515 },
480 { 516 {
481 .flags = DEV_RATE_OFDM, 517 .flags = DEV_RATE_OFDM,
482 .bitrate = 180, 518 .bitrate = 180,
483 .ratemask = BIT(7), 519 .ratemask = BIT(7),
484 .plcp = 0x0e, 520 .plcp = 0x0e,
521 .mcs = RATE_MCS(RATE_MODE_OFDM, 3),
485 }, 522 },
486 { 523 {
487 .flags = DEV_RATE_OFDM, 524 .flags = DEV_RATE_OFDM,
488 .bitrate = 240, 525 .bitrate = 240,
489 .ratemask = BIT(8), 526 .ratemask = BIT(8),
490 .plcp = 0x09, 527 .plcp = 0x09,
528 .mcs = RATE_MCS(RATE_MODE_OFDM, 4),
491 }, 529 },
492 { 530 {
493 .flags = DEV_RATE_OFDM, 531 .flags = DEV_RATE_OFDM,
494 .bitrate = 360, 532 .bitrate = 360,
495 .ratemask = BIT(9), 533 .ratemask = BIT(9),
496 .plcp = 0x0d, 534 .plcp = 0x0d,
535 .mcs = RATE_MCS(RATE_MODE_OFDM, 5),
497 }, 536 },
498 { 537 {
499 .flags = DEV_RATE_OFDM, 538 .flags = DEV_RATE_OFDM,
500 .bitrate = 480, 539 .bitrate = 480,
501 .ratemask = BIT(10), 540 .ratemask = BIT(10),
502 .plcp = 0x08, 541 .plcp = 0x08,
542 .mcs = RATE_MCS(RATE_MODE_OFDM, 6),
503 }, 543 },
504 { 544 {
505 .flags = DEV_RATE_OFDM, 545 .flags = DEV_RATE_OFDM,
506 .bitrate = 540, 546 .bitrate = 540,
507 .ratemask = BIT(11), 547 .ratemask = BIT(11),
508 .plcp = 0x0c, 548 .plcp = 0x0c,
549 .mcs = RATE_MCS(RATE_MODE_OFDM, 7),
509 }, 550 },
510}; 551};
511 552
@@ -581,6 +622,8 @@ static int rt2x00lib_probe_hw_modes(struct rt2x00_dev *rt2x00dev,
581 rt2x00dev->bands[IEEE80211_BAND_2GHZ].bitrates = rates; 622 rt2x00dev->bands[IEEE80211_BAND_2GHZ].bitrates = rates;
582 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = 623 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
583 &rt2x00dev->bands[IEEE80211_BAND_2GHZ]; 624 &rt2x00dev->bands[IEEE80211_BAND_2GHZ];
625 memcpy(&rt2x00dev->bands[IEEE80211_BAND_2GHZ].ht_cap,
626 &spec->ht, sizeof(spec->ht));
584 } 627 }
585 628
586 /* 629 /*
@@ -597,6 +640,8 @@ static int rt2x00lib_probe_hw_modes(struct rt2x00_dev *rt2x00dev,
597 rt2x00dev->bands[IEEE80211_BAND_5GHZ].bitrates = &rates[4]; 640 rt2x00dev->bands[IEEE80211_BAND_5GHZ].bitrates = &rates[4];
598 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = 641 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
599 &rt2x00dev->bands[IEEE80211_BAND_5GHZ]; 642 &rt2x00dev->bands[IEEE80211_BAND_5GHZ];
643 memcpy(&rt2x00dev->bands[IEEE80211_BAND_5GHZ].ht_cap,
644 &spec->ht, sizeof(spec->ht));
600 } 645 }
601 646
602 return 0; 647 return 0;
diff --git a/drivers/net/wireless/rt2x00/rt2x00ht.c b/drivers/net/wireless/rt2x00/rt2x00ht.c
new file mode 100644
index 000000000000..e3cec839e540
--- /dev/null
+++ b/drivers/net/wireless/rt2x00/rt2x00ht.c
@@ -0,0 +1,69 @@
1/*
2 Copyright (C) 2004 - 2009 rt2x00 SourceForge Project
3 <http://rt2x00.serialmonkey.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the
17 Free Software Foundation, Inc.,
18 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21/*
22 Module: rt2x00lib
23 Abstract: rt2x00 HT specific routines.
24 */
25
26#include <linux/kernel.h>
27#include <linux/module.h>
28
29#include "rt2x00.h"
30#include "rt2x00lib.h"
31
32void rt2x00ht_create_tx_descriptor(struct queue_entry *entry,
33 struct txentry_desc *txdesc,
34 const struct rt2x00_rate *hwrate)
35{
36 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(entry->skb);
37 struct ieee80211_tx_rate *txrate = &tx_info->control.rates[0];
38
39 if (tx_info->control.sta)
40 txdesc->mpdu_density =
41 tx_info->control.sta->ht_cap.ampdu_density;
42 else
43 txdesc->mpdu_density = 0;
44
45 txdesc->ba_size = 7; /* FIXME: What value is needed? */
46 txdesc->stbc = 0; /* FIXME: What value is needed? */
47
48 txdesc->mcs = rt2x00_get_rate_mcs(hwrate->mcs);
49 if (txrate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
50 txdesc->mcs |= 0x08;
51
52 /*
53 * Convert flags
54 */
55 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
56 __set_bit(ENTRY_TXD_HT_AMPDU, &txdesc->flags);
57
58 /*
59 * Determine HT Mix/Greenfield rate mode
60 */
61 if (txrate->flags & IEEE80211_TX_RC_MCS)
62 txdesc->rate_mode = RATE_MODE_HT_MIX;
63 if (txrate->flags & IEEE80211_TX_RC_GREEN_FIELD)
64 txdesc->rate_mode = RATE_MODE_HT_GREENFIELD;
65 if (txrate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
66 __set_bit(ENTRY_TXD_HT_BW_40, &txdesc->flags);
67 if (txrate->flags & IEEE80211_TX_RC_SHORT_GI)
68 __set_bit(ENTRY_TXD_HT_SHORT_GI, &txdesc->flags);
69}
diff --git a/drivers/net/wireless/rt2x00/rt2x00lib.h b/drivers/net/wireless/rt2x00/rt2x00lib.h
index a631613177d0..39e00b3d7811 100644
--- a/drivers/net/wireless/rt2x00/rt2x00lib.h
+++ b/drivers/net/wireless/rt2x00/rt2x00lib.h
@@ -32,8 +32,8 @@
32 * Interval defines 32 * Interval defines
33 * Both the link tuner as the rfkill will be called once per second. 33 * Both the link tuner as the rfkill will be called once per second.
34 */ 34 */
35#define LINK_TUNE_INTERVAL ( round_jiffies_relative(HZ) ) 35#define LINK_TUNE_INTERVAL round_jiffies_relative(HZ)
36#define RFKILL_POLL_INTERVAL ( 1000 ) 36#define RFKILL_POLL_INTERVAL 1000
37 37
38/* 38/*
39 * rt2x00_rate: Per rate device information 39 * rt2x00_rate: Per rate device information
@@ -48,6 +48,7 @@ struct rt2x00_rate {
48 unsigned short ratemask; 48 unsigned short ratemask;
49 49
50 unsigned short plcp; 50 unsigned short plcp;
51 unsigned short mcs;
51}; 52};
52 53
53extern const struct rt2x00_rate rt2x00_supported_rates[12]; 54extern const struct rt2x00_rate rt2x00_supported_rates[12];
@@ -57,6 +58,14 @@ static inline const struct rt2x00_rate *rt2x00_get_rate(const u16 hw_value)
57 return &rt2x00_supported_rates[hw_value & 0xff]; 58 return &rt2x00_supported_rates[hw_value & 0xff];
58} 59}
59 60
61#define RATE_MCS(__mode, __mcs) \
62 ( (((__mode) & 0x00ff) << 8) | ((__mcs) & 0x00ff) )
63
64static inline int rt2x00_get_rate_mcs(const u16 mcs_value)
65{
66 return (mcs_value & 0x00ff);
67}
68
60/* 69/*
61 * Radio control handlers. 70 * Radio control handlers.
62 */ 71 */
@@ -113,6 +122,23 @@ void rt2x00queue_unmap_skb(struct rt2x00_dev *rt2x00dev, struct sk_buff *skb);
113void rt2x00queue_free_skb(struct rt2x00_dev *rt2x00dev, struct sk_buff *skb); 122void rt2x00queue_free_skb(struct rt2x00_dev *rt2x00dev, struct sk_buff *skb);
114 123
115/** 124/**
125 * rt2x00queue_payload_align - Align 802.11 payload to 4-byte boundary
126 * @skb: The skb to align
127 * @l2pad: Should L2 padding be used
128 * @header_length: Length of 802.11 header
129 *
130 * This function prepares the @skb to be send to the device or mac80211.
131 * If @l2pad is set to true padding will occur between the 802.11 header
132 * and payload. Otherwise the padding will be done in front of the 802.11
133 * header.
134 * When @l2pad is set the function will check for the &SKBDESC_L2_PADDED
135 * flag in &skb_frame_desc. If that flag is set, the padding is removed
136 * and the flag cleared. Otherwise the padding is added and the flag is set.
137 */
138void rt2x00queue_payload_align(struct sk_buff *skb,
139 bool l2pad, unsigned int header_length);
140
141/**
116 * rt2x00queue_write_tx_frame - Write TX frame to hardware 142 * rt2x00queue_write_tx_frame - Write TX frame to hardware
117 * @queue: Queue over which the frame should be send 143 * @queue: Queue over which the frame should be send
118 * @skb: The skb to send 144 * @skb: The skb to send
@@ -295,10 +321,12 @@ void rt2x00crypto_create_tx_descriptor(struct queue_entry *entry,
295 struct txentry_desc *txdesc); 321 struct txentry_desc *txdesc);
296unsigned int rt2x00crypto_tx_overhead(struct rt2x00_dev *rt2x00dev, 322unsigned int rt2x00crypto_tx_overhead(struct rt2x00_dev *rt2x00dev,
297 struct sk_buff *skb); 323 struct sk_buff *skb);
298void rt2x00crypto_tx_copy_iv(struct sk_buff *skb, unsigned int iv_len); 324void rt2x00crypto_tx_copy_iv(struct sk_buff *skb,
299void rt2x00crypto_tx_remove_iv(struct sk_buff *skb, unsigned int iv_len); 325 struct txentry_desc *txdesc);
300void rt2x00crypto_tx_insert_iv(struct sk_buff *skb); 326void rt2x00crypto_tx_remove_iv(struct sk_buff *skb,
301void rt2x00crypto_rx_insert_iv(struct sk_buff *skb, unsigned int align, 327 struct txentry_desc *txdesc);
328void rt2x00crypto_tx_insert_iv(struct sk_buff *skb, unsigned int header_length);
329void rt2x00crypto_rx_insert_iv(struct sk_buff *skb, bool l2pad,
302 unsigned int header_length, 330 unsigned int header_length,
303 struct rxdone_entry_desc *rxdesc); 331 struct rxdone_entry_desc *rxdesc);
304#else 332#else
@@ -319,21 +347,21 @@ static inline unsigned int rt2x00crypto_tx_overhead(struct rt2x00_dev *rt2x00dev
319} 347}
320 348
321static inline void rt2x00crypto_tx_copy_iv(struct sk_buff *skb, 349static inline void rt2x00crypto_tx_copy_iv(struct sk_buff *skb,
322 unsigned int iv_len) 350 struct txentry_desc *txdesc)
323{ 351{
324} 352}
325 353
326static inline void rt2x00crypto_tx_remove_iv(struct sk_buff *skb, 354static inline void rt2x00crypto_tx_remove_iv(struct sk_buff *skb,
327 unsigned int iv_len) 355 struct txentry_desc *txdesc)
328{ 356{
329} 357}
330 358
331static inline void rt2x00crypto_tx_insert_iv(struct sk_buff *skb) 359static inline void rt2x00crypto_tx_insert_iv(struct sk_buff *skb,
360 unsigned int header_length)
332{ 361{
333} 362}
334 363
335static inline void rt2x00crypto_rx_insert_iv(struct sk_buff *skb, 364static inline void rt2x00crypto_rx_insert_iv(struct sk_buff *skb, bool l2pad,
336 unsigned int align,
337 unsigned int header_length, 365 unsigned int header_length,
338 struct rxdone_entry_desc *rxdesc) 366 struct rxdone_entry_desc *rxdesc)
339{ 367{
@@ -341,6 +369,21 @@ static inline void rt2x00crypto_rx_insert_iv(struct sk_buff *skb,
341#endif /* CONFIG_RT2X00_LIB_CRYPTO */ 369#endif /* CONFIG_RT2X00_LIB_CRYPTO */
342 370
343/* 371/*
372 * HT handlers.
373 */
374#ifdef CONFIG_RT2X00_LIB_HT
375void rt2x00ht_create_tx_descriptor(struct queue_entry *entry,
376 struct txentry_desc *txdesc,
377 const struct rt2x00_rate *hwrate);
378#else
379static inline void rt2x00ht_create_tx_descriptor(struct queue_entry *entry,
380 struct txentry_desc *txdesc,
381 const struct rt2x00_rate *hwrate)
382{
383}
384#endif /* CONFIG_RT2X00_LIB_HT */
385
386/*
344 * RFkill handlers. 387 * RFkill handlers.
345 */ 388 */
346#ifdef CONFIG_RT2X00_LIB_RFKILL 389#ifdef CONFIG_RT2X00_LIB_RFKILL
diff --git a/drivers/net/wireless/rt2x00/rt2x00mac.c b/drivers/net/wireless/rt2x00/rt2x00mac.c
index c41a0b9e473d..c4c06b4e1f08 100644
--- a/drivers/net/wireless/rt2x00/rt2x00mac.c
+++ b/drivers/net/wireless/rt2x00/rt2x00mac.c
@@ -390,56 +390,6 @@ int rt2x00mac_config(struct ieee80211_hw *hw, u32 changed)
390} 390}
391EXPORT_SYMBOL_GPL(rt2x00mac_config); 391EXPORT_SYMBOL_GPL(rt2x00mac_config);
392 392
393int rt2x00mac_config_interface(struct ieee80211_hw *hw,
394 struct ieee80211_vif *vif,
395 struct ieee80211_if_conf *conf)
396{
397 struct rt2x00_dev *rt2x00dev = hw->priv;
398 struct rt2x00_intf *intf = vif_to_intf(vif);
399 int update_bssid = 0;
400 int status = 0;
401
402 /*
403 * Mac80211 might be calling this function while we are trying
404 * to remove the device or perhaps suspending it.
405 */
406 if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags))
407 return 0;
408
409 spin_lock(&intf->lock);
410
411 /*
412 * conf->bssid can be NULL if coming from the internal
413 * beacon update routine.
414 */
415 if (conf->changed & IEEE80211_IFCC_BSSID && conf->bssid) {
416 update_bssid = 1;
417 memcpy(&intf->bssid, conf->bssid, ETH_ALEN);
418 }
419
420 spin_unlock(&intf->lock);
421
422 /*
423 * Call rt2x00_config_intf() outside of the spinlock context since
424 * the call will sleep for USB drivers. By using the ieee80211_if_conf
425 * values as arguments we make keep access to rt2x00_intf thread safe
426 * even without the lock.
427 */
428 rt2x00lib_config_intf(rt2x00dev, intf, vif->type, NULL,
429 update_bssid ? conf->bssid : NULL);
430
431 /*
432 * Update the beacon.
433 */
434 if (conf->changed & (IEEE80211_IFCC_BEACON |
435 IEEE80211_IFCC_BEACON_ENABLED))
436 status = rt2x00queue_update_beacon(rt2x00dev, vif,
437 conf->enable_beacon);
438
439 return status;
440}
441EXPORT_SYMBOL_GPL(rt2x00mac_config_interface);
442
443void rt2x00mac_configure_filter(struct ieee80211_hw *hw, 393void rt2x00mac_configure_filter(struct ieee80211_hw *hw,
444 unsigned int changed_flags, 394 unsigned int changed_flags,
445 unsigned int *total_flags, 395 unsigned int *total_flags,
@@ -623,6 +573,44 @@ void rt2x00mac_bss_info_changed(struct ieee80211_hw *hw,
623 struct rt2x00_dev *rt2x00dev = hw->priv; 573 struct rt2x00_dev *rt2x00dev = hw->priv;
624 struct rt2x00_intf *intf = vif_to_intf(vif); 574 struct rt2x00_intf *intf = vif_to_intf(vif);
625 unsigned int delayed = 0; 575 unsigned int delayed = 0;
576 int update_bssid = 0;
577
578 /*
579 * Mac80211 might be calling this function while we are trying
580 * to remove the device or perhaps suspending it.
581 */
582 if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags))
583 return;
584
585 spin_lock(&intf->lock);
586
587 /*
588 * conf->bssid can be NULL if coming from the internal
589 * beacon update routine.
590 */
591 if (changes & BSS_CHANGED_BSSID) {
592 update_bssid = 1;
593 memcpy(&intf->bssid, bss_conf->bssid, ETH_ALEN);
594 }
595
596 spin_unlock(&intf->lock);
597
598 /*
599 * Call rt2x00_config_intf() outside of the spinlock context since
600 * the call will sleep for USB drivers. By using the ieee80211_if_conf
601 * values as arguments we make keep access to rt2x00_intf thread safe
602 * even without the lock.
603 */
604 if (changes & BSS_CHANGED_BSSID)
605 rt2x00lib_config_intf(rt2x00dev, intf, vif->type, NULL,
606 update_bssid ? bss_conf->bssid : NULL);
607
608 /*
609 * Update the beacon.
610 */
611 if (changes & (BSS_CHANGED_BEACON | BSS_CHANGED_BEACON_ENABLED))
612 rt2x00queue_update_beacon(rt2x00dev, vif,
613 bss_conf->enable_beacon);
626 614
627 /* 615 /*
628 * When the association status has changed we must reset the link 616 * When the association status has changed we must reset the link
diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
index a5664bd8493e..44e5b3279ca7 100644
--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
@@ -148,6 +148,35 @@ void rt2x00queue_free_skb(struct rt2x00_dev *rt2x00dev, struct sk_buff *skb)
148 dev_kfree_skb_any(skb); 148 dev_kfree_skb_any(skb);
149} 149}
150 150
151void rt2x00queue_payload_align(struct sk_buff *skb,
152 bool l2pad, unsigned int header_length)
153{
154 struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb);
155 unsigned int frame_length = skb->len;
156 unsigned int align = ALIGN_SIZE(skb, header_length);
157
158 if (!align)
159 return;
160
161 if (l2pad) {
162 if (skbdesc->flags & SKBDESC_L2_PADDED) {
163 /* Remove L2 padding */
164 memmove(skb->data + align, skb->data, header_length);
165 skb_pull(skb, align);
166 skbdesc->flags &= ~SKBDESC_L2_PADDED;
167 } else {
168 /* Add L2 padding */
169 skb_push(skb, align);
170 memmove(skb->data, skb->data + align, header_length);
171 skbdesc->flags |= SKBDESC_L2_PADDED;
172 }
173 } else {
174 /* Generic payload alignment to 4-byte boundary */
175 skb_push(skb, align);
176 memmove(skb->data, skb->data + align, frame_length);
177 }
178}
179
151static void rt2x00queue_create_tx_descriptor_seq(struct queue_entry *entry, 180static void rt2x00queue_create_tx_descriptor_seq(struct queue_entry *entry,
152 struct txentry_desc *txdesc) 181 struct txentry_desc *txdesc)
153{ 182{
@@ -259,6 +288,12 @@ static void rt2x00queue_create_tx_descriptor(struct queue_entry *entry,
259 txdesc->aifs = entry->queue->aifs; 288 txdesc->aifs = entry->queue->aifs;
260 289
261 /* 290 /*
291 * Header and alignment information.
292 */
293 txdesc->header_length = ieee80211_get_hdrlen_from_skb(entry->skb);
294 txdesc->l2pad = ALIGN_SIZE(entry->skb, txdesc->header_length);
295
296 /*
262 * Check whether this frame is to be acked. 297 * Check whether this frame is to be acked.
263 */ 298 */
264 if (!(tx_info->flags & IEEE80211_TX_CTL_NO_ACK)) 299 if (!(tx_info->flags & IEEE80211_TX_CTL_NO_ACK))
@@ -326,6 +361,7 @@ static void rt2x00queue_create_tx_descriptor(struct queue_entry *entry,
326 * Apply TX descriptor handling by components 361 * Apply TX descriptor handling by components
327 */ 362 */
328 rt2x00crypto_create_tx_descriptor(entry, txdesc); 363 rt2x00crypto_create_tx_descriptor(entry, txdesc);
364 rt2x00ht_create_tx_descriptor(entry, txdesc, hwrate);
329 rt2x00queue_create_tx_descriptor_seq(entry, txdesc); 365 rt2x00queue_create_tx_descriptor_seq(entry, txdesc);
330 rt2x00queue_create_tx_descriptor_plcp(entry, txdesc, hwrate); 366 rt2x00queue_create_tx_descriptor_plcp(entry, txdesc, hwrate);
331} 367}
@@ -368,7 +404,6 @@ int rt2x00queue_write_tx_frame(struct data_queue *queue, struct sk_buff *skb)
368 struct queue_entry *entry = rt2x00queue_get_entry(queue, Q_INDEX); 404 struct queue_entry *entry = rt2x00queue_get_entry(queue, Q_INDEX);
369 struct txentry_desc txdesc; 405 struct txentry_desc txdesc;
370 struct skb_frame_desc *skbdesc; 406 struct skb_frame_desc *skbdesc;
371 unsigned int iv_len = 0;
372 u8 rate_idx, rate_flags; 407 u8 rate_idx, rate_flags;
373 408
374 if (unlikely(rt2x00queue_full(queue))) 409 if (unlikely(rt2x00queue_full(queue)))
@@ -390,9 +425,6 @@ int rt2x00queue_write_tx_frame(struct data_queue *queue, struct sk_buff *skb)
390 entry->skb = skb; 425 entry->skb = skb;
391 rt2x00queue_create_tx_descriptor(entry, &txdesc); 426 rt2x00queue_create_tx_descriptor(entry, &txdesc);
392 427
393 if (IEEE80211_SKB_CB(skb)->control.hw_key != NULL)
394 iv_len = IEEE80211_SKB_CB(skb)->control.hw_key->iv_len;
395
396 /* 428 /*
397 * All information is retrieved from the skb->cb array, 429 * All information is retrieved from the skb->cb array,
398 * now we should claim ownership of the driver part of that 430 * now we should claim ownership of the driver part of that
@@ -415,11 +447,15 @@ int rt2x00queue_write_tx_frame(struct data_queue *queue, struct sk_buff *skb)
415 if (test_bit(ENTRY_TXD_ENCRYPT, &txdesc.flags) && 447 if (test_bit(ENTRY_TXD_ENCRYPT, &txdesc.flags) &&
416 !test_bit(ENTRY_TXD_ENCRYPT_IV, &txdesc.flags)) { 448 !test_bit(ENTRY_TXD_ENCRYPT_IV, &txdesc.flags)) {
417 if (test_bit(DRIVER_REQUIRE_COPY_IV, &queue->rt2x00dev->flags)) 449 if (test_bit(DRIVER_REQUIRE_COPY_IV, &queue->rt2x00dev->flags))
418 rt2x00crypto_tx_copy_iv(skb, iv_len); 450 rt2x00crypto_tx_copy_iv(skb, &txdesc);
419 else 451 else
420 rt2x00crypto_tx_remove_iv(skb, iv_len); 452 rt2x00crypto_tx_remove_iv(skb, &txdesc);
421 } 453 }
422 454
455 if (test_bit(DRIVER_REQUIRE_L2PAD, &queue->rt2x00dev->flags))
456 rt2x00queue_payload_align(entry->skb, true,
457 txdesc.header_length);
458
423 /* 459 /*
424 * It could be possible that the queue was corrupted and this 460 * It could be possible that the queue was corrupted and this
425 * call failed. Since we always return NETDEV_TX_OK to mac80211, 461 * call failed. Since we always return NETDEV_TX_OK to mac80211,
diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.h b/drivers/net/wireless/rt2x00/rt2x00queue.h
index 97e2ab08f080..b5e06347c8a7 100644
--- a/drivers/net/wireless/rt2x00/rt2x00queue.h
+++ b/drivers/net/wireless/rt2x00/rt2x00queue.h
@@ -35,9 +35,12 @@
35 * for USB devices this restriction does not apply, but the value of 35 * for USB devices this restriction does not apply, but the value of
36 * 2432 makes sense since it is big enough to contain the maximum fragment 36 * 2432 makes sense since it is big enough to contain the maximum fragment
37 * size according to the ieee802.11 specs. 37 * size according to the ieee802.11 specs.
38 * The aggregation size depends on support from the driver, but should
39 * be something around 3840 bytes.
38 */ 40 */
39#define DATA_FRAME_SIZE 2432 41#define DATA_FRAME_SIZE 2432
40#define MGMT_FRAME_SIZE 256 42#define MGMT_FRAME_SIZE 256
43#define AGGREGATION_SIZE 3840
41 44
42/** 45/**
43 * DOC: Number of entries per queue 46 * DOC: Number of entries per queue
@@ -87,13 +90,16 @@ enum data_queue_qid {
87 * 90 *
88 * @SKBDESC_DMA_MAPPED_RX: &skb_dma field has been mapped for RX 91 * @SKBDESC_DMA_MAPPED_RX: &skb_dma field has been mapped for RX
89 * @SKBDESC_DMA_MAPPED_TX: &skb_dma field has been mapped for TX 92 * @SKBDESC_DMA_MAPPED_TX: &skb_dma field has been mapped for TX
90 * @FRAME_DESC_IV_STRIPPED: Frame contained a IV/EIV provided by 93 * @SKBDESC_IV_STRIPPED: Frame contained a IV/EIV provided by
91 * mac80211 but was stripped for processing by the driver. 94 * mac80211 but was stripped for processing by the driver.
95 * @SKBDESC_L2_PADDED: Payload has been padded for 4-byte alignment,
96 * the padded bytes are located between header and payload.
92 */ 97 */
93enum skb_frame_desc_flags { 98enum skb_frame_desc_flags {
94 SKBDESC_DMA_MAPPED_RX = 1 << 0, 99 SKBDESC_DMA_MAPPED_RX = 1 << 0,
95 SKBDESC_DMA_MAPPED_TX = 1 << 1, 100 SKBDESC_DMA_MAPPED_TX = 1 << 1,
96 FRAME_DESC_IV_STRIPPED = 1 << 2, 101 SKBDESC_IV_STRIPPED = 1 << 2,
102 SKBDESC_L2_PADDED = 1 << 3
97}; 103};
98 104
99/** 105/**
@@ -145,16 +151,20 @@ static inline struct skb_frame_desc* get_skb_frame_desc(struct sk_buff *skb)
145 * 151 *
146 * @RXDONE_SIGNAL_PLCP: Signal field contains the plcp value. 152 * @RXDONE_SIGNAL_PLCP: Signal field contains the plcp value.
147 * @RXDONE_SIGNAL_BITRATE: Signal field contains the bitrate value. 153 * @RXDONE_SIGNAL_BITRATE: Signal field contains the bitrate value.
154 * @RXDONE_SIGNAL_MCS: Signal field contains the mcs value.
148 * @RXDONE_MY_BSS: Does this frame originate from device's BSS. 155 * @RXDONE_MY_BSS: Does this frame originate from device's BSS.
149 * @RXDONE_CRYPTO_IV: Driver provided IV/EIV data. 156 * @RXDONE_CRYPTO_IV: Driver provided IV/EIV data.
150 * @RXDONE_CRYPTO_ICV: Driver provided ICV data. 157 * @RXDONE_CRYPTO_ICV: Driver provided ICV data.
158 * @RXDONE_L2PAD: 802.11 payload has been padded to 4-byte boundary.
151 */ 159 */
152enum rxdone_entry_desc_flags { 160enum rxdone_entry_desc_flags {
153 RXDONE_SIGNAL_PLCP = 1 << 0, 161 RXDONE_SIGNAL_PLCP = BIT(0),
154 RXDONE_SIGNAL_BITRATE = 1 << 1, 162 RXDONE_SIGNAL_BITRATE = BIT(1),
155 RXDONE_MY_BSS = 1 << 2, 163 RXDONE_SIGNAL_MCS = BIT(2),
156 RXDONE_CRYPTO_IV = 1 << 3, 164 RXDONE_MY_BSS = BIT(3),
157 RXDONE_CRYPTO_ICV = 1 << 4, 165 RXDONE_CRYPTO_IV = BIT(4),
166 RXDONE_CRYPTO_ICV = BIT(5),
167 RXDONE_L2PAD = BIT(6),
158}; 168};
159 169
160/** 170/**
@@ -163,7 +173,7 @@ enum rxdone_entry_desc_flags {
163 * from &rxdone_entry_desc to a signal value type. 173 * from &rxdone_entry_desc to a signal value type.
164 */ 174 */
165#define RXDONE_SIGNAL_MASK \ 175#define RXDONE_SIGNAL_MASK \
166 ( RXDONE_SIGNAL_PLCP | RXDONE_SIGNAL_BITRATE ) 176 ( RXDONE_SIGNAL_PLCP | RXDONE_SIGNAL_BITRATE | RXDONE_SIGNAL_MCS )
167 177
168/** 178/**
169 * struct rxdone_entry_desc: RX Entry descriptor 179 * struct rxdone_entry_desc: RX Entry descriptor
@@ -177,6 +187,7 @@ enum rxdone_entry_desc_flags {
177 * @size: Data size of the received frame. 187 * @size: Data size of the received frame.
178 * @flags: MAC80211 receive flags (See &enum mac80211_rx_flags). 188 * @flags: MAC80211 receive flags (See &enum mac80211_rx_flags).
179 * @dev_flags: Ralink receive flags (See &enum rxdone_entry_desc_flags). 189 * @dev_flags: Ralink receive flags (See &enum rxdone_entry_desc_flags).
190 * @rate_mode: Rate mode (See @enum rate_modulation).
180 * @cipher: Cipher type used during decryption. 191 * @cipher: Cipher type used during decryption.
181 * @cipher_status: Decryption status. 192 * @cipher_status: Decryption status.
182 * @iv: IV/EIV data used during decryption. 193 * @iv: IV/EIV data used during decryption.
@@ -190,6 +201,7 @@ struct rxdone_entry_desc {
190 int size; 201 int size;
191 int flags; 202 int flags;
192 int dev_flags; 203 int dev_flags;
204 u16 rate_mode;
193 u8 cipher; 205 u8 cipher;
194 u8 cipher_status; 206 u8 cipher_status;
195 207
@@ -243,6 +255,9 @@ struct txdone_entry_desc {
243 * @ENTRY_TXD_ENCRYPT_PAIRWISE: Use pairwise key table (instead of shared). 255 * @ENTRY_TXD_ENCRYPT_PAIRWISE: Use pairwise key table (instead of shared).
244 * @ENTRY_TXD_ENCRYPT_IV: Generate IV/EIV in hardware. 256 * @ENTRY_TXD_ENCRYPT_IV: Generate IV/EIV in hardware.
245 * @ENTRY_TXD_ENCRYPT_MMIC: Generate MIC in hardware. 257 * @ENTRY_TXD_ENCRYPT_MMIC: Generate MIC in hardware.
258 * @ENTRY_TXD_HT_AMPDU: This frame is part of an AMPDU.
259 * @ENTRY_TXD_HT_BW_40: Use 40MHz Bandwidth.
260 * @ENTRY_TXD_HT_SHORT_GI: Use short GI.
246 */ 261 */
247enum txentry_desc_flags { 262enum txentry_desc_flags {
248 ENTRY_TXD_RTS_FRAME, 263 ENTRY_TXD_RTS_FRAME,
@@ -258,6 +273,9 @@ enum txentry_desc_flags {
258 ENTRY_TXD_ENCRYPT_PAIRWISE, 273 ENTRY_TXD_ENCRYPT_PAIRWISE,
259 ENTRY_TXD_ENCRYPT_IV, 274 ENTRY_TXD_ENCRYPT_IV,
260 ENTRY_TXD_ENCRYPT_MMIC, 275 ENTRY_TXD_ENCRYPT_MMIC,
276 ENTRY_TXD_HT_AMPDU,
277 ENTRY_TXD_HT_BW_40,
278 ENTRY_TXD_HT_SHORT_GI,
261}; 279};
262 280
263/** 281/**
@@ -267,11 +285,17 @@ enum txentry_desc_flags {
267 * 285 *
268 * @flags: Descriptor flags (See &enum queue_entry_flags). 286 * @flags: Descriptor flags (See &enum queue_entry_flags).
269 * @queue: Queue identification (See &enum data_queue_qid). 287 * @queue: Queue identification (See &enum data_queue_qid).
288 * @header_length: Length of 802.11 header.
289 * @l2pad: Amount of padding to align 802.11 payload to 4-byte boundrary.
270 * @length_high: PLCP length high word. 290 * @length_high: PLCP length high word.
271 * @length_low: PLCP length low word. 291 * @length_low: PLCP length low word.
272 * @signal: PLCP signal. 292 * @signal: PLCP signal.
273 * @service: PLCP service. 293 * @service: PLCP service.
294 * @msc: MCS.
295 * @stbc: STBC.
296 * @ba_size: BA size.
274 * @rate_mode: Rate mode (See @enum rate_modulation). 297 * @rate_mode: Rate mode (See @enum rate_modulation).
298 * @mpdu_density: MDPU density.
275 * @retry_limit: Max number of retries. 299 * @retry_limit: Max number of retries.
276 * @aifs: AIFS value. 300 * @aifs: AIFS value.
277 * @ifs: IFS value. 301 * @ifs: IFS value.
@@ -280,18 +304,26 @@ enum txentry_desc_flags {
280 * @cipher: Cipher type used for encryption. 304 * @cipher: Cipher type used for encryption.
281 * @key_idx: Key index used for encryption. 305 * @key_idx: Key index used for encryption.
282 * @iv_offset: Position where IV should be inserted by hardware. 306 * @iv_offset: Position where IV should be inserted by hardware.
307 * @iv_len: Length of IV data.
283 */ 308 */
284struct txentry_desc { 309struct txentry_desc {
285 unsigned long flags; 310 unsigned long flags;
286 311
287 enum data_queue_qid queue; 312 enum data_queue_qid queue;
288 313
314 u16 header_length;
315 u16 l2pad;
316
289 u16 length_high; 317 u16 length_high;
290 u16 length_low; 318 u16 length_low;
291 u16 signal; 319 u16 signal;
292 u16 service; 320 u16 service;
293 321
322 u16 mcs;
323 u16 stbc;
324 u16 ba_size;
294 u16 rate_mode; 325 u16 rate_mode;
326 u16 mpdu_density;
295 327
296 short retry_limit; 328 short retry_limit;
297 short aifs; 329 short aifs;
@@ -302,6 +334,7 @@ struct txentry_desc {
302 enum cipher cipher; 334 enum cipher cipher;
303 u16 key_idx; 335 u16 key_idx;
304 u16 iv_offset; 336 u16 iv_offset;
337 u16 iv_len;
305}; 338};
306 339
307/** 340/**
diff --git a/drivers/net/wireless/rt2x00/rt61pci.c b/drivers/net/wireless/rt2x00/rt61pci.c
index 4346cd1494bc..cb521ee7a8f0 100644
--- a/drivers/net/wireless/rt2x00/rt61pci.c
+++ b/drivers/net/wireless/rt2x00/rt61pci.c
@@ -2735,7 +2735,6 @@ static const struct ieee80211_ops rt61pci_mac80211_ops = {
2735 .add_interface = rt2x00mac_add_interface, 2735 .add_interface = rt2x00mac_add_interface,
2736 .remove_interface = rt2x00mac_remove_interface, 2736 .remove_interface = rt2x00mac_remove_interface,
2737 .config = rt2x00mac_config, 2737 .config = rt2x00mac_config,
2738 .config_interface = rt2x00mac_config_interface,
2739 .configure_filter = rt2x00mac_configure_filter, 2738 .configure_filter = rt2x00mac_configure_filter,
2740 .set_key = rt2x00mac_set_key, 2739 .set_key = rt2x00mac_set_key,
2741 .get_stats = rt2x00mac_get_stats, 2740 .get_stats = rt2x00mac_get_stats,
diff --git a/drivers/net/wireless/rt2x00/rt73usb.c b/drivers/net/wireless/rt2x00/rt73usb.c
index 853b2b279b64..d10af3687a8e 100644
--- a/drivers/net/wireless/rt2x00/rt73usb.c
+++ b/drivers/net/wireless/rt2x00/rt73usb.c
@@ -1846,7 +1846,8 @@ static int rt73usb_init_eeprom(struct rt2x00_dev *rt2x00dev)
1846 rt2x00usb_register_read(rt2x00dev, MAC_CSR0, &reg); 1846 rt2x00usb_register_read(rt2x00dev, MAC_CSR0, &reg);
1847 rt2x00_set_chip(rt2x00dev, RT2571, value, reg); 1847 rt2x00_set_chip(rt2x00dev, RT2571, value, reg);
1848 1848
1849 if (!rt2x00_check_rev(&rt2x00dev->chip, 0x25730)) { 1849 if (!rt2x00_check_rev(&rt2x00dev->chip, 0x000ffff0, 0x25730) ||
1850 !rt2x00_check_rev(&rt2x00dev->chip, 0x0000000f, 0)) {
1850 ERROR(rt2x00dev, "Invalid RT chipset detected.\n"); 1851 ERROR(rt2x00dev, "Invalid RT chipset detected.\n");
1851 return -ENODEV; 1852 return -ENODEV;
1852 } 1853 }
@@ -2259,7 +2260,6 @@ static const struct ieee80211_ops rt73usb_mac80211_ops = {
2259 .add_interface = rt2x00mac_add_interface, 2260 .add_interface = rt2x00mac_add_interface,
2260 .remove_interface = rt2x00mac_remove_interface, 2261 .remove_interface = rt2x00mac_remove_interface,
2261 .config = rt2x00mac_config, 2262 .config = rt2x00mac_config,
2262 .config_interface = rt2x00mac_config_interface,
2263 .configure_filter = rt2x00mac_configure_filter, 2263 .configure_filter = rt2x00mac_configure_filter,
2264 .set_key = rt2x00mac_set_key, 2264 .set_key = rt2x00mac_set_key,
2265 .get_stats = rt2x00mac_get_stats, 2265 .get_stats = rt2x00mac_get_stats,
diff --git a/drivers/net/wireless/rtl818x/rtl8180_dev.c b/drivers/net/wireless/rtl818x/rtl8180_dev.c
index 387c133ec0f2..7e65d7c31802 100644
--- a/drivers/net/wireless/rtl818x/rtl8180_dev.c
+++ b/drivers/net/wireless/rtl818x/rtl8180_dev.c
@@ -702,30 +702,26 @@ static int rtl8180_config(struct ieee80211_hw *dev, u32 changed)
702 return 0; 702 return 0;
703} 703}
704 704
705static int rtl8180_config_interface(struct ieee80211_hw *dev,
706 struct ieee80211_vif *vif,
707 struct ieee80211_if_conf *conf)
708{
709 struct rtl8180_priv *priv = dev->priv;
710 int i;
711
712 for (i = 0; i < ETH_ALEN; i++)
713 rtl818x_iowrite8(priv, &priv->map->BSSID[i], conf->bssid[i]);
714
715 if (is_valid_ether_addr(conf->bssid))
716 rtl818x_iowrite8(priv, &priv->map->MSR, RTL818X_MSR_INFRA);
717 else
718 rtl818x_iowrite8(priv, &priv->map->MSR, RTL818X_MSR_NO_LINK);
719
720 return 0;
721}
722
723static void rtl8180_bss_info_changed(struct ieee80211_hw *dev, 705static void rtl8180_bss_info_changed(struct ieee80211_hw *dev,
724 struct ieee80211_vif *vif, 706 struct ieee80211_vif *vif,
725 struct ieee80211_bss_conf *info, 707 struct ieee80211_bss_conf *info,
726 u32 changed) 708 u32 changed)
727{ 709{
728 struct rtl8180_priv *priv = dev->priv; 710 struct rtl8180_priv *priv = dev->priv;
711 int i;
712
713 if (changed & BSS_CHANGED_BSSID) {
714 for (i = 0; i < ETH_ALEN; i++)
715 rtl818x_iowrite8(priv, &priv->map->BSSID[i],
716 info->bssid[i]);
717
718 if (is_valid_ether_addr(info->bssid))
719 rtl818x_iowrite8(priv, &priv->map->MSR,
720 RTL818X_MSR_INFRA);
721 else
722 rtl818x_iowrite8(priv, &priv->map->MSR,
723 RTL818X_MSR_NO_LINK);
724 }
729 725
730 if (changed & BSS_CHANGED_ERP_SLOT && priv->rf->conf_erp) 726 if (changed & BSS_CHANGED_ERP_SLOT && priv->rf->conf_erp)
731 priv->rf->conf_erp(dev, info); 727 priv->rf->conf_erp(dev, info);
@@ -770,7 +766,6 @@ static const struct ieee80211_ops rtl8180_ops = {
770 .add_interface = rtl8180_add_interface, 766 .add_interface = rtl8180_add_interface,
771 .remove_interface = rtl8180_remove_interface, 767 .remove_interface = rtl8180_remove_interface,
772 .config = rtl8180_config, 768 .config = rtl8180_config,
773 .config_interface = rtl8180_config_interface,
774 .bss_info_changed = rtl8180_bss_info_changed, 769 .bss_info_changed = rtl8180_bss_info_changed,
775 .configure_filter = rtl8180_configure_filter, 770 .configure_filter = rtl8180_configure_filter,
776}; 771};
diff --git a/drivers/net/wireless/rtl818x/rtl8187_dev.c b/drivers/net/wireless/rtl818x/rtl8187_dev.c
index ac558da92aac..158827e50c55 100644
--- a/drivers/net/wireless/rtl818x/rtl8187_dev.c
+++ b/drivers/net/wireless/rtl818x/rtl8187_dev.c
@@ -1090,32 +1090,6 @@ static int rtl8187_config(struct ieee80211_hw *dev, u32 changed)
1090 return 0; 1090 return 0;
1091} 1091}
1092 1092
1093static int rtl8187_config_interface(struct ieee80211_hw *dev,
1094 struct ieee80211_vif *vif,
1095 struct ieee80211_if_conf *conf)
1096{
1097 struct rtl8187_priv *priv = dev->priv;
1098 int i;
1099 u8 reg;
1100
1101 mutex_lock(&priv->conf_mutex);
1102 for (i = 0; i < ETH_ALEN; i++)
1103 rtl818x_iowrite8(priv, &priv->map->BSSID[i], conf->bssid[i]);
1104
1105 if (is_valid_ether_addr(conf->bssid)) {
1106 reg = RTL818X_MSR_INFRA;
1107 if (priv->is_rtl8187b)
1108 reg |= RTL818X_MSR_ENEDCA;
1109 rtl818x_iowrite8(priv, &priv->map->MSR, reg);
1110 } else {
1111 reg = RTL818X_MSR_NO_LINK;
1112 rtl818x_iowrite8(priv, &priv->map->MSR, reg);
1113 }
1114
1115 mutex_unlock(&priv->conf_mutex);
1116 return 0;
1117}
1118
1119/* 1093/*
1120 * With 8187B, AC_*_PARAM clashes with FEMR definition in struct rtl818x_csr for 1094 * With 8187B, AC_*_PARAM clashes with FEMR definition in struct rtl818x_csr for
1121 * example. Thus we have to use raw values for AC_*_PARAM register addresses. 1095 * example. Thus we have to use raw values for AC_*_PARAM register addresses.
@@ -1193,6 +1167,27 @@ static void rtl8187_bss_info_changed(struct ieee80211_hw *dev,
1193 u32 changed) 1167 u32 changed)
1194{ 1168{
1195 struct rtl8187_priv *priv = dev->priv; 1169 struct rtl8187_priv *priv = dev->priv;
1170 int i;
1171 u8 reg;
1172
1173 if (changed & BSS_CHANGED_BSSID) {
1174 mutex_lock(&priv->conf_mutex);
1175 for (i = 0; i < ETH_ALEN; i++)
1176 rtl818x_iowrite8(priv, &priv->map->BSSID[i],
1177 info->bssid[i]);
1178
1179 if (is_valid_ether_addr(info->bssid)) {
1180 reg = RTL818X_MSR_INFRA;
1181 if (priv->is_rtl8187b)
1182 reg |= RTL818X_MSR_ENEDCA;
1183 rtl818x_iowrite8(priv, &priv->map->MSR, reg);
1184 } else {
1185 reg = RTL818X_MSR_NO_LINK;
1186 rtl818x_iowrite8(priv, &priv->map->MSR, reg);
1187 }
1188
1189 mutex_unlock(&priv->conf_mutex);
1190 }
1196 1191
1197 if (changed & (BSS_CHANGED_ERP_SLOT | BSS_CHANGED_ERP_PREAMBLE)) 1192 if (changed & (BSS_CHANGED_ERP_SLOT | BSS_CHANGED_ERP_PREAMBLE))
1198 rtl8187_conf_erp(priv, info->use_short_slot, 1193 rtl8187_conf_erp(priv, info->use_short_slot,
@@ -1274,7 +1269,6 @@ static const struct ieee80211_ops rtl8187_ops = {
1274 .add_interface = rtl8187_add_interface, 1269 .add_interface = rtl8187_add_interface,
1275 .remove_interface = rtl8187_remove_interface, 1270 .remove_interface = rtl8187_remove_interface,
1276 .config = rtl8187_config, 1271 .config = rtl8187_config,
1277 .config_interface = rtl8187_config_interface,
1278 .bss_info_changed = rtl8187_bss_info_changed, 1272 .bss_info_changed = rtl8187_bss_info_changed,
1279 .configure_filter = rtl8187_configure_filter, 1273 .configure_filter = rtl8187_configure_filter,
1280 .conf_tx = rtl8187_conf_tx 1274 .conf_tx = rtl8187_conf_tx
diff --git a/drivers/net/wireless/wl12xx/Kconfig b/drivers/net/wireless/wl12xx/Kconfig
new file mode 100644
index 000000000000..20a9633569f2
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/Kconfig
@@ -0,0 +1,11 @@
1config WL12XX
2 tristate "TI wl1251/wl1271 support"
3 depends on MAC80211 && WLAN_80211 && SPI_MASTER && EXPERIMENTAL
4 select FW_LOADER
5 select CRC7
6 ---help---
7 This module adds support for wireless adapters based on
8 TI wl1251/wl1271 chipsets.
9
10 If you choose to build a module, it'll be called wl12xx. Say N if
11 unsure.
diff --git a/drivers/net/wireless/wl12xx/Makefile b/drivers/net/wireless/wl12xx/Makefile
new file mode 100644
index 000000000000..d43de27dc54c
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/Makefile
@@ -0,0 +1,4 @@
1wl12xx-objs = main.o spi.o event.o tx.o rx.o \
2 ps.o cmd.o acx.o boot.o init.o wl1251.o \
3 debugfs.o
4obj-$(CONFIG_WL12XX) += wl12xx.o
diff --git a/drivers/net/wireless/wl12xx/acx.c b/drivers/net/wireless/wl12xx/acx.c
new file mode 100644
index 000000000000..1cfd458ad5ab
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/acx.c
@@ -0,0 +1,689 @@
1#include "acx.h"
2
3#include <linux/module.h>
4#include <linux/crc7.h>
5#include <linux/spi/spi.h>
6
7#include "wl12xx.h"
8#include "wl12xx_80211.h"
9#include "reg.h"
10#include "spi.h"
11#include "ps.h"
12
13int wl12xx_acx_frame_rates(struct wl12xx *wl, u8 ctrl_rate, u8 ctrl_mod,
14 u8 mgt_rate, u8 mgt_mod)
15{
16 int ret;
17 struct acx_fw_gen_frame_rates rates;
18
19 wl12xx_debug(DEBUG_ACX, "acx frame rates");
20
21 rates.header.id = ACX_FW_GEN_FRAME_RATES;
22 rates.header.len = sizeof(struct acx_fw_gen_frame_rates) -
23 sizeof(struct acx_header);
24
25 rates.tx_ctrl_frame_rate = ctrl_rate;
26 rates.tx_ctrl_frame_mod = ctrl_mod;
27 rates.tx_mgt_frame_rate = mgt_rate;
28 rates.tx_mgt_frame_mod = mgt_mod;
29
30 ret = wl12xx_cmd_configure(wl, &rates, sizeof(rates));
31 if (ret < 0) {
32 wl12xx_error("Failed to set FW rates and modulation");
33 return ret;
34 }
35
36 return 0;
37}
38
39
40int wl12xx_acx_station_id(struct wl12xx *wl)
41{
42 int ret, i;
43 struct dot11_station_id mac;
44
45 wl12xx_debug(DEBUG_ACX, "acx dot11_station_id");
46
47 mac.header.id = DOT11_STATION_ID;
48 mac.header.len = sizeof(mac) - sizeof(struct acx_header);
49
50 for (i = 0; i < ETH_ALEN; i++)
51 mac.mac[i] = wl->mac_addr[ETH_ALEN - 1 - i];
52
53 ret = wl12xx_cmd_configure(wl, &mac, sizeof(mac));
54 if (ret < 0)
55 return ret;
56
57 return 0;
58}
59
60int wl12xx_acx_default_key(struct wl12xx *wl, u8 key_id)
61{
62 struct acx_dot11_default_key default_key;
63 int ret;
64
65 wl12xx_debug(DEBUG_ACX, "acx dot11_default_key (%d)", key_id);
66
67 default_key.header.id = DOT11_DEFAULT_KEY;
68 default_key.header.len = sizeof(default_key) -
69 sizeof(struct acx_header);
70
71 default_key.id = key_id;
72
73 ret = wl12xx_cmd_configure(wl, &default_key, sizeof(default_key));
74 if (ret < 0) {
75 wl12xx_error("Couldnt set default key");
76 return ret;
77 }
78
79 wl->default_key = key_id;
80
81 return 0;
82}
83
84int wl12xx_acx_wake_up_conditions(struct wl12xx *wl, u8 listen_interval)
85{
86 struct acx_wake_up_condition wake_up;
87
88 wl12xx_debug(DEBUG_ACX, "acx wake up conditions");
89
90 wake_up.header.id = ACX_WAKE_UP_CONDITIONS;
91 wake_up.header.len = sizeof(wake_up) - sizeof(struct acx_header);
92
93 wake_up.wake_up_event = WAKE_UP_EVENT_DTIM_BITMAP;
94 wake_up.listen_interval = listen_interval;
95
96 return wl12xx_cmd_configure(wl, &wake_up, sizeof(wake_up));
97}
98
99int wl12xx_acx_sleep_auth(struct wl12xx *wl, u8 sleep_auth)
100{
101 int ret;
102 struct acx_sleep_auth auth;
103
104 wl12xx_debug(DEBUG_ACX, "acx sleep auth");
105
106 auth.header.id = ACX_SLEEP_AUTH;
107 auth.header.len = sizeof(auth) - sizeof(struct acx_header);
108
109 auth.sleep_auth = sleep_auth;
110
111 ret = wl12xx_cmd_configure(wl, &auth, sizeof(auth));
112 if (ret < 0)
113 return ret;
114
115 return 0;
116}
117
118int wl12xx_acx_fw_version(struct wl12xx *wl, char *buf, size_t len)
119{
120 struct wl12xx_command cmd;
121 struct acx_revision *rev;
122 int ret;
123
124 wl12xx_debug(DEBUG_ACX, "acx fw rev");
125
126 memset(&cmd, 0, sizeof(cmd));
127
128 ret = wl12xx_cmd_interrogate(wl, ACX_FW_REV, sizeof(*rev), &cmd);
129 if (ret < 0) {
130 wl12xx_warning("ACX_FW_REV interrogate failed");
131 return ret;
132 }
133
134 rev = (struct acx_revision *) &cmd.parameters;
135
136 /* be careful with the buffer sizes */
137 strncpy(buf, rev->fw_version, min(len, sizeof(rev->fw_version)));
138
139 /*
140 * if the firmware version string is exactly
141 * sizeof(rev->fw_version) long or fw_len is less than
142 * sizeof(rev->fw_version) it won't be null terminated
143 */
144 buf[min(len, sizeof(rev->fw_version)) - 1] = '\0';
145
146 return 0;
147}
148
149int wl12xx_acx_tx_power(struct wl12xx *wl, int power)
150{
151 struct acx_current_tx_power ie;
152 int ret;
153
154 wl12xx_debug(DEBUG_ACX, "acx dot11_cur_tx_pwr");
155
156 if (power < 0 || power > 25)
157 return -EINVAL;
158
159 memset(&ie, 0, sizeof(ie));
160
161 ie.header.id = DOT11_CUR_TX_PWR;
162 ie.header.len = sizeof(ie) - sizeof(struct acx_header);
163 ie.current_tx_power = power * 10;
164
165 ret = wl12xx_cmd_configure(wl, &ie, sizeof(ie));
166 if (ret < 0) {
167 wl12xx_warning("configure of tx power failed: %d", ret);
168 return ret;
169 }
170
171 return 0;
172}
173
174int wl12xx_acx_feature_cfg(struct wl12xx *wl)
175{
176 struct acx_feature_config feature;
177 int ret;
178
179 wl12xx_debug(DEBUG_ACX, "acx feature cfg");
180
181 memset(&feature, 0, sizeof(feature));
182
183 feature.header.id = ACX_FEATURE_CFG;
184 feature.header.len = sizeof(feature) - sizeof(struct acx_header);
185
186 /* DF_ENCRYPTION_DISABLE and DF_SNIFF_MODE_ENABLE are disabled */
187 feature.data_flow_options = 0;
188 feature.options = 0;
189
190 ret = wl12xx_cmd_configure(wl, &feature, sizeof(feature));
191 if (ret < 0)
192 wl12xx_error("Couldnt set HW encryption");
193
194 return ret;
195}
196
197int wl12xx_acx_mem_map(struct wl12xx *wl, void *mem_map, size_t len)
198{
199 struct wl12xx_command cmd;
200 int ret;
201
202 wl12xx_debug(DEBUG_ACX, "acx mem map");
203
204 ret = wl12xx_cmd_interrogate(wl, ACX_MEM_MAP, len, &cmd);
205 if (ret < 0)
206 return ret;
207 else if (cmd.status != CMD_STATUS_SUCCESS)
208 return -EIO;
209
210 memcpy(mem_map, &cmd.parameters, len);
211
212 return 0;
213}
214
215int wl12xx_acx_data_path_params(struct wl12xx *wl,
216 struct acx_data_path_params_resp *data_path)
217{
218 struct acx_data_path_params params;
219 struct wl12xx_command cmd;
220 int ret;
221
222 wl12xx_debug(DEBUG_ACX, "acx data path params");
223
224 params.rx_packet_ring_chunk_size = DP_RX_PACKET_RING_CHUNK_SIZE;
225 params.tx_packet_ring_chunk_size = DP_TX_PACKET_RING_CHUNK_SIZE;
226
227 params.rx_packet_ring_chunk_num = DP_RX_PACKET_RING_CHUNK_NUM;
228 params.tx_packet_ring_chunk_num = DP_TX_PACKET_RING_CHUNK_NUM;
229
230 params.tx_complete_threshold = 1;
231
232 params.tx_complete_ring_depth = FW_TX_CMPLT_BLOCK_SIZE;
233
234 params.tx_complete_timeout = DP_TX_COMPLETE_TIME_OUT;
235
236 params.header.id = ACX_DATA_PATH_PARAMS;
237 params.header.len = sizeof(params) - sizeof(struct acx_header);
238
239 ret = wl12xx_cmd_configure(wl, &params, sizeof(params));
240 if (ret < 0)
241 return ret;
242
243
244 ret = wl12xx_cmd_interrogate(wl, ACX_DATA_PATH_PARAMS,
245 sizeof(struct acx_data_path_params_resp),
246 &cmd);
247
248 if (ret < 0) {
249 wl12xx_warning("failed to read data path parameters: %d", ret);
250 return ret;
251 } else if (cmd.status != CMD_STATUS_SUCCESS) {
252 wl12xx_warning("data path parameter acx status failed");
253 return -EIO;
254 }
255
256 memcpy(data_path, &cmd.parameters, sizeof(*data_path));
257
258 return 0;
259}
260
261int wl12xx_acx_rx_msdu_life_time(struct wl12xx *wl, u32 life_time)
262{
263 struct rx_msdu_lifetime msdu_lifetime;
264 int ret;
265
266 wl12xx_debug(DEBUG_ACX, "acx rx msdu life time");
267
268 msdu_lifetime.header.id = DOT11_RX_MSDU_LIFE_TIME;
269 msdu_lifetime.header.len = sizeof(msdu_lifetime) -
270 sizeof(struct acx_header);
271 msdu_lifetime.lifetime = life_time;
272
273 ret = wl12xx_cmd_configure(wl, &msdu_lifetime, sizeof(msdu_lifetime));
274 if (ret < 0) {
275 wl12xx_warning("failed to set rx msdu life time: %d", ret);
276 return ret;
277 }
278
279 return 0;
280}
281
282int wl12xx_acx_rx_config(struct wl12xx *wl, u32 config, u32 filter)
283{
284 struct acx_rx_config rx_config;
285 int ret;
286
287 wl12xx_debug(DEBUG_ACX, "acx rx config");
288
289 rx_config.header.id = ACX_RX_CFG;
290 rx_config.header.len = sizeof(rx_config) - sizeof(struct acx_header);
291 rx_config.config_options = config;
292 rx_config.filter_options = filter;
293
294 ret = wl12xx_cmd_configure(wl, &rx_config, sizeof(rx_config));
295 if (ret < 0) {
296 wl12xx_warning("failed to set rx config: %d", ret);
297 return ret;
298 }
299
300 return 0;
301}
302
303int wl12xx_acx_pd_threshold(struct wl12xx *wl)
304{
305 struct acx_packet_detection packet_detection;
306 int ret;
307
308 wl12xx_debug(DEBUG_ACX, "acx data pd threshold");
309
310 /* FIXME: threshold value not set */
311 packet_detection.header.id = ACX_PD_THRESHOLD;
312 packet_detection.header.len = sizeof(packet_detection) -
313 sizeof(struct acx_header);
314
315 ret = wl12xx_cmd_configure(wl, &packet_detection,
316 sizeof(packet_detection));
317 if (ret < 0) {
318 wl12xx_warning("failed to set pd threshold: %d", ret);
319 return ret;
320 }
321
322 return 0;
323}
324
325int wl12xx_acx_slot(struct wl12xx *wl, enum acx_slot_type slot_time)
326{
327 struct acx_slot slot;
328 int ret;
329
330 wl12xx_debug(DEBUG_ACX, "acx slot");
331
332 slot.header.id = ACX_SLOT;
333 slot.header.len = sizeof(slot) - sizeof(struct acx_header);
334
335 slot.wone_index = STATION_WONE_INDEX;
336 slot.slot_time = slot_time;
337
338 ret = wl12xx_cmd_configure(wl, &slot, sizeof(slot));
339 if (ret < 0) {
340 wl12xx_warning("failed to set slot time: %d", ret);
341 return ret;
342 }
343
344 return 0;
345}
346
347int wl12xx_acx_group_address_tbl(struct wl12xx *wl)
348{
349 struct multicast_grp_addr_start multicast;
350 int ret;
351
352 wl12xx_debug(DEBUG_ACX, "acx group address tbl");
353
354 /* MAC filtering */
355 multicast.header.id = DOT11_GROUP_ADDRESS_TBL;
356 multicast.header.len = sizeof(multicast) - sizeof(struct acx_header);
357
358 multicast.enabled = 0;
359 multicast.num_groups = 0;
360 memset(multicast.mac_table, 0, ADDRESS_GROUP_MAX_LEN);
361
362 ret = wl12xx_cmd_configure(wl, &multicast, sizeof(multicast));
363 if (ret < 0) {
364 wl12xx_warning("failed to set group addr table: %d", ret);
365 return ret;
366 }
367
368 return 0;
369}
370
371int wl12xx_acx_service_period_timeout(struct wl12xx *wl)
372{
373 struct acx_rx_timeout rx_timeout;
374 int ret;
375
376 wl12xx_debug(DEBUG_ACX, "acx service period timeout");
377
378 /* RX timeout */
379 rx_timeout.header.id = ACX_SERVICE_PERIOD_TIMEOUT;
380 rx_timeout.header.len = sizeof(rx_timeout) - sizeof(struct acx_header);
381
382 rx_timeout.ps_poll_timeout = RX_TIMEOUT_PS_POLL_DEF;
383 rx_timeout.upsd_timeout = RX_TIMEOUT_UPSD_DEF;
384
385 ret = wl12xx_cmd_configure(wl, &rx_timeout, sizeof(rx_timeout));
386 if (ret < 0) {
387 wl12xx_warning("failed to set service period timeout: %d",
388 ret);
389 return ret;
390 }
391
392 return 0;
393}
394
395int wl12xx_acx_rts_threshold(struct wl12xx *wl, u16 rts_threshold)
396{
397 struct acx_rts_threshold rts;
398 int ret;
399
400 wl12xx_debug(DEBUG_ACX, "acx rts threshold");
401
402 rts.header.id = DOT11_RTS_THRESHOLD;
403 rts.header.len = sizeof(rts) - sizeof(struct acx_header);
404
405 rts.threshold = rts_threshold;
406
407 ret = wl12xx_cmd_configure(wl, &rts, sizeof(rts));
408 if (ret < 0) {
409 wl12xx_warning("failed to set rts threshold: %d", ret);
410 return ret;
411 }
412
413 return 0;
414}
415
416int wl12xx_acx_beacon_filter_opt(struct wl12xx *wl)
417{
418 struct acx_beacon_filter_option beacon_filter;
419 int ret;
420
421 wl12xx_debug(DEBUG_ACX, "acx beacon filter opt");
422
423 beacon_filter.header.id = ACX_BEACON_FILTER_OPT;
424 beacon_filter.header.len = sizeof(beacon_filter) -
425 sizeof(struct acx_header);
426
427 beacon_filter.enable = 0;
428 beacon_filter.max_num_beacons = 0;
429
430 ret = wl12xx_cmd_configure(wl, &beacon_filter, sizeof(beacon_filter));
431 if (ret < 0) {
432 wl12xx_warning("failed to set beacon filter opt: %d", ret);
433 return ret;
434 }
435
436 return 0;
437}
438
439int wl12xx_acx_beacon_filter_table(struct wl12xx *wl)
440{
441 struct acx_beacon_filter_ie_table ie_table;
442 int ret;
443
444 wl12xx_debug(DEBUG_ACX, "acx beacon filter table");
445
446 ie_table.header.id = ACX_BEACON_FILTER_TABLE;
447 ie_table.header.len = sizeof(ie_table) - sizeof(struct acx_header);
448
449 ie_table.num_ie = 0;
450 memset(ie_table.table, 0, BEACON_FILTER_TABLE_MAX_SIZE);
451
452 ret = wl12xx_cmd_configure(wl, &ie_table, sizeof(ie_table));
453 if (ret < 0) {
454 wl12xx_warning("failed to set beacon filter table: %d", ret);
455 return ret;
456 }
457
458 return 0;
459}
460
461int wl12xx_acx_sg_enable(struct wl12xx *wl)
462{
463 struct acx_bt_wlan_coex pta;
464 int ret;
465
466 wl12xx_debug(DEBUG_ACX, "acx sg enable");
467
468 pta.header.id = ACX_SG_ENABLE;
469 pta.header.len = sizeof(pta) - sizeof(struct acx_header);
470
471 pta.enable = SG_ENABLE;
472
473 ret = wl12xx_cmd_configure(wl, &pta, sizeof(pta));
474 if (ret < 0) {
475 wl12xx_warning("failed to set softgemini enable: %d", ret);
476 return ret;
477 }
478
479 return 0;
480}
481
482int wl12xx_acx_sg_cfg(struct wl12xx *wl)
483{
484 struct acx_bt_wlan_coex_param param;
485 int ret;
486
487 wl12xx_debug(DEBUG_ACX, "acx sg cfg");
488
489 /* BT-WLAN coext parameters */
490 param.header.id = ACX_SG_CFG;
491 param.header.len = sizeof(param) - sizeof(struct acx_header);
492
493 param.min_rate = RATE_INDEX_24MBPS;
494 param.bt_hp_max_time = PTA_BT_HP_MAXTIME_DEF;
495 param.wlan_hp_max_time = PTA_WLAN_HP_MAX_TIME_DEF;
496 param.sense_disable_timer = PTA_SENSE_DISABLE_TIMER_DEF;
497 param.rx_time_bt_hp = PTA_PROTECTIVE_RX_TIME_DEF;
498 param.tx_time_bt_hp = PTA_PROTECTIVE_TX_TIME_DEF;
499 param.rx_time_bt_hp_fast = PTA_PROTECTIVE_RX_TIME_FAST_DEF;
500 param.tx_time_bt_hp_fast = PTA_PROTECTIVE_TX_TIME_FAST_DEF;
501 param.wlan_cycle_fast = PTA_CYCLE_TIME_FAST_DEF;
502 param.bt_anti_starvation_period = PTA_ANTI_STARVE_PERIOD_DEF;
503 param.next_bt_lp_packet = PTA_TIMEOUT_NEXT_BT_LP_PACKET_DEF;
504 param.wake_up_beacon = PTA_TIME_BEFORE_BEACON_DEF;
505 param.hp_dm_max_guard_time = PTA_HPDM_MAX_TIME_DEF;
506 param.next_wlan_packet = PTA_TIME_OUT_NEXT_WLAN_DEF;
507 param.antenna_type = PTA_ANTENNA_TYPE_DEF;
508 param.signal_type = PTA_SIGNALING_TYPE_DEF;
509 param.afh_leverage_on = PTA_AFH_LEVERAGE_ON_DEF;
510 param.quiet_cycle_num = PTA_NUMBER_QUIET_CYCLE_DEF;
511 param.max_cts = PTA_MAX_NUM_CTS_DEF;
512 param.wlan_packets_num = PTA_NUMBER_OF_WLAN_PACKETS_DEF;
513 param.bt_packets_num = PTA_NUMBER_OF_BT_PACKETS_DEF;
514 param.missed_rx_avalanche = PTA_RX_FOR_AVALANCHE_DEF;
515 param.wlan_elp_hp = PTA_ELP_HP_DEF;
516 param.bt_anti_starvation_cycles = PTA_ANTI_STARVE_NUM_CYCLE_DEF;
517 param.ack_mode_dual_ant = PTA_ACK_MODE_DEF;
518 param.pa_sd_enable = PTA_ALLOW_PA_SD_DEF;
519 param.pta_auto_mode_enable = PTA_AUTO_MODE_NO_CTS_DEF;
520 param.bt_hp_respected_num = PTA_BT_HP_RESPECTED_DEF;
521
522 ret = wl12xx_cmd_configure(wl, &param, sizeof(param));
523 if (ret < 0) {
524 wl12xx_warning("failed to set sg config: %d", ret);
525 return ret;
526 }
527
528 return 0;
529}
530
531int wl12xx_acx_cca_threshold(struct wl12xx *wl)
532{
533 struct acx_energy_detection detection;
534 int ret;
535
536 wl12xx_debug(DEBUG_ACX, "acx cca threshold");
537
538 detection.header.id = ACX_CCA_THRESHOLD;
539 detection.header.len = sizeof(detection) - sizeof(struct acx_header);
540
541 detection.rx_cca_threshold = CCA_THRSH_DISABLE_ENERGY_D;
542 detection.tx_energy_detection = 0;
543
544 ret = wl12xx_cmd_configure(wl, &detection, sizeof(detection));
545 if (ret < 0) {
546 wl12xx_warning("failed to set cca threshold: %d", ret);
547 return ret;
548 }
549
550 return 0;
551}
552
553int wl12xx_acx_bcn_dtim_options(struct wl12xx *wl)
554{
555 struct acx_beacon_broadcast bb;
556 int ret;
557
558 wl12xx_debug(DEBUG_ACX, "acx bcn dtim options");
559
560 bb.header.id = ACX_BCN_DTIM_OPTIONS;
561 bb.header.len = sizeof(bb) - sizeof(struct acx_header);
562
563 bb.beacon_rx_timeout = BCN_RX_TIMEOUT_DEF_VALUE;
564 bb.broadcast_timeout = BROADCAST_RX_TIMEOUT_DEF_VALUE;
565 bb.rx_broadcast_in_ps = RX_BROADCAST_IN_PS_DEF_VALUE;
566 bb.ps_poll_threshold = CONSECUTIVE_PS_POLL_FAILURE_DEF;
567
568 ret = wl12xx_cmd_configure(wl, &bb, sizeof(bb));
569 if (ret < 0) {
570 wl12xx_warning("failed to set rx config: %d", ret);
571 return ret;
572 }
573
574 return 0;
575}
576
577int wl12xx_acx_aid(struct wl12xx *wl, u16 aid)
578{
579 struct acx_aid acx_aid;
580 int ret;
581
582 wl12xx_debug(DEBUG_ACX, "acx aid");
583
584 acx_aid.header.id = ACX_AID;
585 acx_aid.header.len = sizeof(acx_aid) - sizeof(struct acx_header);
586
587 acx_aid.aid = aid;
588
589 ret = wl12xx_cmd_configure(wl, &acx_aid, sizeof(acx_aid));
590 if (ret < 0) {
591 wl12xx_warning("failed to set aid: %d", ret);
592 return ret;
593 }
594
595 return 0;
596}
597
598int wl12xx_acx_event_mbox_mask(struct wl12xx *wl, u32 event_mask)
599{
600 struct acx_event_mask mask;
601 int ret;
602
603 wl12xx_debug(DEBUG_ACX, "acx event mbox mask");
604
605 mask.header.id = ACX_EVENT_MBOX_MASK;
606 mask.header.len = sizeof(mask) - sizeof(struct acx_header);
607
608 /* high event mask is unused */
609 mask.high_event_mask = 0xffffffff;
610
611 mask.event_mask = event_mask;
612
613 ret = wl12xx_cmd_configure(wl, &mask, sizeof(mask));
614 if (ret < 0) {
615 wl12xx_warning("failed to set aid: %d", ret);
616 return ret;
617 }
618
619 return 0;
620}
621
622int wl12xx_acx_set_preamble(struct wl12xx *wl, enum acx_preamble_type preamble)
623{
624 struct acx_preamble ie;
625 int ret;
626
627 wl12xx_debug(DEBUG_ACX, "acx_set_preamble");
628
629 memset(&ie, 0, sizeof(ie));
630
631 ie.header.id = ACX_PREAMBLE_TYPE;
632 ie.header.len = sizeof(ie) - sizeof(struct acx_header);
633 ie.preamble = preamble;
634 ret = wl12xx_cmd_configure(wl, &ie, sizeof(ie));
635 if (ret < 0) {
636 wl12xx_warning("Setting of preamble failed: %d", ret);
637 return ret;
638 }
639 return 0;
640}
641
642int wl12xx_acx_cts_protect(struct wl12xx *wl,
643 enum acx_ctsprotect_type ctsprotect)
644{
645 struct acx_ctsprotect ie;
646 int ret;
647
648 wl12xx_debug(DEBUG_ACX, "acx_set_ctsprotect");
649
650 memset(&ie, 0, sizeof(ie));
651
652 ie.header.id = ACX_CTS_PROTECTION;
653 ie.header.len = sizeof(ie) - sizeof(struct acx_header);
654 ie.ctsprotect = ctsprotect;
655 ret = wl12xx_cmd_configure(wl, &ie, sizeof(ie));
656 if (ret < 0) {
657 wl12xx_warning("Setting of ctsprotect failed: %d", ret);
658 return ret;
659 }
660 return 0;
661}
662
663int wl12xx_acx_statistics(struct wl12xx *wl, struct acx_statistics *stats)
664{
665 struct wl12xx_command *answer;
666 int ret;
667
668 wl12xx_debug(DEBUG_ACX, "acx statistics");
669
670 answer = kmalloc(sizeof(*answer), GFP_KERNEL);
671 if (!answer) {
672 wl12xx_warning("could not allocate memory for acx statistics");
673 ret = -ENOMEM;
674 goto out;
675 }
676
677 ret = wl12xx_cmd_interrogate(wl, ACX_STATISTICS, sizeof(*answer),
678 answer);
679 if (ret < 0) {
680 wl12xx_warning("acx statistics failed: %d", ret);
681 goto out;
682 }
683
684 memcpy(stats, answer->parameters, sizeof(*stats));
685
686out:
687 kfree(answer);
688 return ret;
689}
diff --git a/drivers/net/wireless/wl12xx/acx.h b/drivers/net/wireless/wl12xx/acx.h
new file mode 100644
index 000000000000..fb2d2340993c
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/acx.h
@@ -0,0 +1,1245 @@
1/*
2 * This file is part of wl12xx
3 *
4 * Copyright (c) 1998-2007 Texas Instruments Incorporated
5 * Copyright (C) 2008 Nokia Corporation
6 *
7 * Contact: Kalle Valo <kalle.valo@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 __WL12XX_ACX_H__
26#define __WL12XX_ACX_H__
27
28#include "wl12xx.h"
29
30/* Target's information element */
31struct acx_header {
32 u16 id;
33 u16 len;
34};
35
36struct acx_error_counter {
37 struct acx_header header;
38
39 /* The number of PLCP errors since the last time this */
40 /* information element was interrogated. This field is */
41 /* automatically cleared when it is interrogated.*/
42 u32 PLCP_error;
43
44 /* The number of FCS errors since the last time this */
45 /* information element was interrogated. This field is */
46 /* automatically cleared when it is interrogated.*/
47 u32 FCS_error;
48
49 /* The number of MPDUs without PLCP header errors received*/
50 /* since the last time this information element was interrogated. */
51 /* This field is automatically cleared when it is interrogated.*/
52 u32 valid_frame;
53
54 /* the number of missed sequence numbers in the squentially */
55 /* values of frames seq numbers */
56 u32 seq_num_miss;
57} __attribute__ ((packed));
58
59struct acx_revision {
60 struct acx_header header;
61
62 /*
63 * The WiLink firmware version, an ASCII string x.x.x.x,
64 * that uniquely identifies the current firmware.
65 * The left most digit is incremented each time a
66 * significant change is made to the firmware, such as
67 * code redesign or new platform support.
68 * The second digit is incremented when major enhancements
69 * are added or major fixes are made.
70 * The third digit is incremented for each GA release.
71 * The fourth digit is incremented for each build.
72 * The first two digits identify a firmware release version,
73 * in other words, a unique set of features.
74 * The first three digits identify a GA release.
75 */
76 char fw_version[20];
77
78 /*
79 * This 4 byte field specifies the WiLink hardware version.
80 * bits 0 - 15: Reserved.
81 * bits 16 - 23: Version ID - The WiLink version ID
82 * (1 = first spin, 2 = second spin, and so on).
83 * bits 24 - 31: Chip ID - The WiLink chip ID.
84 */
85 u32 hw_version;
86} __attribute__ ((packed));
87
88enum wl12xx_psm_mode {
89 /* Active mode */
90 WL12XX_PSM_CAM = 0,
91
92 /* Power save mode */
93 WL12XX_PSM_PS = 1,
94
95 /* Extreme low power */
96 WL12XX_PSM_ELP = 2,
97};
98
99struct acx_sleep_auth {
100 struct acx_header header;
101
102 /* The sleep level authorization of the device. */
103 /* 0 - Always active*/
104 /* 1 - Power down mode: light / fast sleep*/
105 /* 2 - ELP mode: Deep / Max sleep*/
106 u8 sleep_auth;
107 u8 padding[3];
108} __attribute__ ((packed));
109
110#define TIM_ELE_ID 5
111#define PARTIAL_VBM_MAX 251
112
113struct tim {
114 u8 identity;
115 u8 length;
116 u8 dtim_count;
117 u8 dtim_period;
118 u8 bitmap_ctrl;
119 u8 pvb_field[PARTIAL_VBM_MAX]; /* Partial Virtual Bitmap */
120} __attribute__ ((packed));
121
122/* Virtual Bit Map update */
123struct vbm_update_request {
124 __le16 len;
125 u8 padding[2];
126 struct tim tim;
127} __attribute__ ((packed));
128
129enum {
130 HOSTIF_PCI_MASTER_HOST_INDIRECT,
131 HOSTIF_PCI_MASTER_HOST_DIRECT,
132 HOSTIF_SLAVE,
133 HOSTIF_PKT_RING,
134 HOSTIF_DONTCARE = 0xFF
135};
136
137#define DEFAULT_UCAST_PRIORITY 0
138#define DEFAULT_RX_Q_PRIORITY 0
139#define DEFAULT_NUM_STATIONS 1
140#define DEFAULT_RXQ_PRIORITY 0 /* low 0 .. 15 high */
141#define DEFAULT_RXQ_TYPE 0x07 /* All frames, Data/Ctrl/Mgmt */
142#define TRACE_BUFFER_MAX_SIZE 256
143
144#define DP_RX_PACKET_RING_CHUNK_SIZE 1600
145#define DP_TX_PACKET_RING_CHUNK_SIZE 1600
146#define DP_RX_PACKET_RING_CHUNK_NUM 2
147#define DP_TX_PACKET_RING_CHUNK_NUM 2
148#define DP_TX_COMPLETE_TIME_OUT 20
149#define FW_TX_CMPLT_BLOCK_SIZE 16
150
151struct acx_data_path_params {
152 struct acx_header header;
153
154 u16 rx_packet_ring_chunk_size;
155 u16 tx_packet_ring_chunk_size;
156
157 u8 rx_packet_ring_chunk_num;
158 u8 tx_packet_ring_chunk_num;
159
160 /*
161 * Maximum number of packets that can be gathered
162 * in the TX complete ring before an interrupt
163 * is generated.
164 */
165 u8 tx_complete_threshold;
166
167 /* Number of pending TX complete entries in cyclic ring.*/
168 u8 tx_complete_ring_depth;
169
170 /*
171 * Max num microseconds since a packet enters the TX
172 * complete ring until an interrupt is generated.
173 */
174 u32 tx_complete_timeout;
175} __attribute__ ((packed));
176
177
178struct acx_data_path_params_resp {
179 struct acx_header header;
180
181 u16 rx_packet_ring_chunk_size;
182 u16 tx_packet_ring_chunk_size;
183
184 u8 rx_packet_ring_chunk_num;
185 u8 tx_packet_ring_chunk_num;
186
187 u8 pad[2];
188
189 u32 rx_packet_ring_addr;
190 u32 tx_packet_ring_addr;
191
192 u32 rx_control_addr;
193 u32 tx_control_addr;
194
195 u32 tx_complete_addr;
196} __attribute__ ((packed));
197
198#define TX_MSDU_LIFETIME_MIN 0
199#define TX_MSDU_LIFETIME_MAX 3000
200#define TX_MSDU_LIFETIME_DEF 512
201#define RX_MSDU_LIFETIME_MIN 0
202#define RX_MSDU_LIFETIME_MAX 0xFFFFFFFF
203#define RX_MSDU_LIFETIME_DEF 512000
204
205struct rx_msdu_lifetime {
206 struct acx_header header;
207
208 /*
209 * The maximum amount of time, in TU, before the
210 * firmware discards the MSDU.
211 */
212 u32 lifetime;
213} __attribute__ ((packed));
214
215/*
216 * RX Config Options Table
217 * Bit Definition
218 * === ==========
219 * 31:14 Reserved
220 * 13 Copy RX Status - when set, write three receive status words
221 * to top of rx'd MPDUs.
222 * When cleared, do not write three status words (added rev 1.5)
223 * 12 Reserved
224 * 11 RX Complete upon FCS error - when set, give rx complete
225 * interrupt for FCS errors, after the rx filtering, e.g. unicast
226 * frames not to us with FCS error will not generate an interrupt.
227 * 10 SSID Filter Enable - When set, the WiLink discards all beacon,
228 * probe request, and probe response frames with an SSID that does
229 * not match the SSID specified by the host in the START/JOIN
230 * command.
231 * When clear, the WiLink receives frames with any SSID.
232 * 9 Broadcast Filter Enable - When set, the WiLink discards all
233 * broadcast frames. When clear, the WiLink receives all received
234 * broadcast frames.
235 * 8:6 Reserved
236 * 5 BSSID Filter Enable - When set, the WiLink discards any frames
237 * with a BSSID that does not match the BSSID specified by the
238 * host.
239 * When clear, the WiLink receives frames from any BSSID.
240 * 4 MAC Addr Filter - When set, the WiLink discards any frames
241 * with a destination address that does not match the MAC address
242 * of the adaptor.
243 * When clear, the WiLink receives frames destined to any MAC
244 * address.
245 * 3 Promiscuous - When set, the WiLink receives all valid frames
246 * (i.e., all frames that pass the FCS check).
247 * When clear, only frames that pass the other filters specified
248 * are received.
249 * 2 FCS - When set, the WiLink includes the FCS with the received
250 * frame.
251 * When cleared, the FCS is discarded.
252 * 1 PLCP header - When set, write all data from baseband to frame
253 * buffer including PHY header.
254 * 0 Reserved - Always equal to 0.
255 *
256 * RX Filter Options Table
257 * Bit Definition
258 * === ==========
259 * 31:12 Reserved - Always equal to 0.
260 * 11 Association - When set, the WiLink receives all association
261 * related frames (association request/response, reassocation
262 * request/response, and disassociation). When clear, these frames
263 * are discarded.
264 * 10 Auth/De auth - When set, the WiLink receives all authentication
265 * and de-authentication frames. When clear, these frames are
266 * discarded.
267 * 9 Beacon - When set, the WiLink receives all beacon frames.
268 * When clear, these frames are discarded.
269 * 8 Contention Free - When set, the WiLink receives all contention
270 * free frames.
271 * When clear, these frames are discarded.
272 * 7 Control - When set, the WiLink receives all control frames.
273 * When clear, these frames are discarded.
274 * 6 Data - When set, the WiLink receives all data frames.
275 * When clear, these frames are discarded.
276 * 5 FCS Error - When set, the WiLink receives frames that have FCS
277 * errors.
278 * When clear, these frames are discarded.
279 * 4 Management - When set, the WiLink receives all management
280 * frames.
281 * When clear, these frames are discarded.
282 * 3 Probe Request - When set, the WiLink receives all probe request
283 * frames.
284 * When clear, these frames are discarded.
285 * 2 Probe Response - When set, the WiLink receives all probe
286 * response frames.
287 * When clear, these frames are discarded.
288 * 1 RTS/CTS/ACK - When set, the WiLink receives all RTS, CTS and ACK
289 * frames.
290 * When clear, these frames are discarded.
291 * 0 Rsvd Type/Sub Type - When set, the WiLink receives all frames
292 * that have reserved frame types and sub types as defined by the
293 * 802.11 specification.
294 * When clear, these frames are discarded.
295 */
296struct acx_rx_config {
297 struct acx_header header;
298
299 u32 config_options;
300 u32 filter_options;
301} __attribute__ ((packed));
302
303enum {
304 QOS_AC_BE = 0,
305 QOS_AC_BK,
306 QOS_AC_VI,
307 QOS_AC_VO,
308 QOS_HIGHEST_AC_INDEX = QOS_AC_VO,
309};
310
311#define MAX_NUM_OF_AC (QOS_HIGHEST_AC_INDEX+1)
312#define FIRST_AC_INDEX QOS_AC_BE
313#define MAX_NUM_OF_802_1d_TAGS 8
314#define AC_PARAMS_MAX_TSID 15
315#define MAX_APSD_CONF 0xffff
316
317#define QOS_TX_HIGH_MIN (0)
318#define QOS_TX_HIGH_MAX (100)
319
320#define QOS_TX_HIGH_BK_DEF (25)
321#define QOS_TX_HIGH_BE_DEF (35)
322#define QOS_TX_HIGH_VI_DEF (35)
323#define QOS_TX_HIGH_VO_DEF (35)
324
325#define QOS_TX_LOW_BK_DEF (15)
326#define QOS_TX_LOW_BE_DEF (25)
327#define QOS_TX_LOW_VI_DEF (25)
328#define QOS_TX_LOW_VO_DEF (25)
329
330struct acx_tx_queue_qos_config {
331 struct acx_header header;
332
333 u8 qid;
334 u8 pad[3];
335
336 /* Max number of blocks allowd in the queue */
337 u16 high_threshold;
338
339 /* Lowest memory blocks guaranteed for this queue */
340 u16 low_threshold;
341} __attribute__ ((packed));
342
343struct acx_packet_detection {
344 struct acx_header header;
345
346 u32 threshold;
347} __attribute__ ((packed));
348
349
350enum acx_slot_type {
351 SLOT_TIME_LONG = 0,
352 SLOT_TIME_SHORT = 1,
353 DEFAULT_SLOT_TIME = SLOT_TIME_SHORT,
354 MAX_SLOT_TIMES = 0xFF
355};
356
357#define STATION_WONE_INDEX 0
358
359struct acx_slot {
360 struct acx_header header;
361
362 u8 wone_index; /* Reserved */
363 u8 slot_time;
364 u8 reserved[6];
365} __attribute__ ((packed));
366
367
368#define ADDRESS_GROUP_MAX (8)
369#define ADDRESS_GROUP_MAX_LEN (ETH_ALEN * ADDRESS_GROUP_MAX)
370
371struct multicast_grp_addr_start {
372 struct acx_header header;
373
374 u8 enabled;
375 u8 num_groups;
376 u8 pad[2];
377 u8 mac_table[ADDRESS_GROUP_MAX_LEN];
378} __attribute__ ((packed));
379
380
381#define RX_TIMEOUT_PS_POLL_MIN 0
382#define RX_TIMEOUT_PS_POLL_MAX (200000)
383#define RX_TIMEOUT_PS_POLL_DEF (15)
384#define RX_TIMEOUT_UPSD_MIN 0
385#define RX_TIMEOUT_UPSD_MAX (200000)
386#define RX_TIMEOUT_UPSD_DEF (15)
387
388struct acx_rx_timeout {
389 struct acx_header header;
390
391 /*
392 * The longest time the STA will wait to receive
393 * traffic from the AP after a PS-poll has been
394 * transmitted.
395 */
396 u16 ps_poll_timeout;
397
398 /*
399 * The longest time the STA will wait to receive
400 * traffic from the AP after a frame has been sent
401 * from an UPSD enabled queue.
402 */
403 u16 upsd_timeout;
404} __attribute__ ((packed));
405
406#define RTS_THRESHOLD_MIN 0
407#define RTS_THRESHOLD_MAX 4096
408#define RTS_THRESHOLD_DEF 2347
409
410struct acx_rts_threshold {
411 struct acx_header header;
412
413 u16 threshold;
414 u8 pad[2];
415} __attribute__ ((packed));
416
417struct acx_beacon_filter_option {
418 struct acx_header header;
419
420 u8 enable;
421
422 /*
423 * The number of beacons without the unicast TIM
424 * bit set that the firmware buffers before
425 * signaling the host about ready frames.
426 * When set to 0 and the filter is enabled, beacons
427 * without the unicast TIM bit set are dropped.
428 */
429 u8 max_num_beacons;
430 u8 pad[2];
431} __attribute__ ((packed));
432
433/*
434 * ACXBeaconFilterEntry (not 221)
435 * Byte Offset Size (Bytes) Definition
436 * =========== ============ ==========
437 * 0 1 IE identifier
438 * 1 1 Treatment bit mask
439 *
440 * ACXBeaconFilterEntry (221)
441 * Byte Offset Size (Bytes) Definition
442 * =========== ============ ==========
443 * 0 1 IE identifier
444 * 1 1 Treatment bit mask
445 * 2 3 OUI
446 * 5 1 Type
447 * 6 2 Version
448 *
449 *
450 * Treatment bit mask - The information element handling:
451 * bit 0 - The information element is compared and transferred
452 * in case of change.
453 * bit 1 - The information element is transferred to the host
454 * with each appearance or disappearance.
455 * Note that both bits can be set at the same time.
456 */
457#define BEACON_FILTER_TABLE_MAX_IE_NUM (32)
458#define BEACON_FILTER_TABLE_MAX_VENDOR_SPECIFIC_IE_NUM (6)
459#define BEACON_FILTER_TABLE_IE_ENTRY_SIZE (2)
460#define BEACON_FILTER_TABLE_EXTRA_VENDOR_SPECIFIC_IE_SIZE (6)
461#define BEACON_FILTER_TABLE_MAX_SIZE ((BEACON_FILTER_TABLE_MAX_IE_NUM * \
462 BEACON_FILTER_TABLE_IE_ENTRY_SIZE) + \
463 (BEACON_FILTER_TABLE_MAX_VENDOR_SPECIFIC_IE_NUM * \
464 BEACON_FILTER_TABLE_EXTRA_VENDOR_SPECIFIC_IE_SIZE))
465
466struct acx_beacon_filter_ie_table {
467 struct acx_header header;
468
469 u8 num_ie;
470 u8 table[BEACON_FILTER_TABLE_MAX_SIZE];
471 u8 pad[3];
472} __attribute__ ((packed));
473
474enum {
475 SG_ENABLE = 0,
476 SG_DISABLE,
477 SG_SENSE_NO_ACTIVITY,
478 SG_SENSE_ACTIVE
479};
480
481struct acx_bt_wlan_coex {
482 struct acx_header header;
483
484 /*
485 * 0 -> PTA enabled
486 * 1 -> PTA disabled
487 * 2 -> sense no active mode, i.e.
488 * an interrupt is sent upon
489 * BT activity.
490 * 3 -> PTA is switched on in response
491 * to the interrupt sending.
492 */
493 u8 enable;
494 u8 pad[3];
495} __attribute__ ((packed));
496
497#define PTA_ANTENNA_TYPE_DEF (0)
498#define PTA_BT_HP_MAXTIME_DEF (2000)
499#define PTA_WLAN_HP_MAX_TIME_DEF (5000)
500#define PTA_SENSE_DISABLE_TIMER_DEF (1350)
501#define PTA_PROTECTIVE_RX_TIME_DEF (1500)
502#define PTA_PROTECTIVE_TX_TIME_DEF (1500)
503#define PTA_TIMEOUT_NEXT_BT_LP_PACKET_DEF (3000)
504#define PTA_SIGNALING_TYPE_DEF (1)
505#define PTA_AFH_LEVERAGE_ON_DEF (0)
506#define PTA_NUMBER_QUIET_CYCLE_DEF (0)
507#define PTA_MAX_NUM_CTS_DEF (3)
508#define PTA_NUMBER_OF_WLAN_PACKETS_DEF (2)
509#define PTA_NUMBER_OF_BT_PACKETS_DEF (2)
510#define PTA_PROTECTIVE_RX_TIME_FAST_DEF (1500)
511#define PTA_PROTECTIVE_TX_TIME_FAST_DEF (3000)
512#define PTA_CYCLE_TIME_FAST_DEF (8700)
513#define PTA_RX_FOR_AVALANCHE_DEF (5)
514#define PTA_ELP_HP_DEF (0)
515#define PTA_ANTI_STARVE_PERIOD_DEF (500)
516#define PTA_ANTI_STARVE_NUM_CYCLE_DEF (4)
517#define PTA_ALLOW_PA_SD_DEF (1)
518#define PTA_TIME_BEFORE_BEACON_DEF (6300)
519#define PTA_HPDM_MAX_TIME_DEF (1600)
520#define PTA_TIME_OUT_NEXT_WLAN_DEF (2550)
521#define PTA_AUTO_MODE_NO_CTS_DEF (0)
522#define PTA_BT_HP_RESPECTED_DEF (3)
523#define PTA_WLAN_RX_MIN_RATE_DEF (24)
524#define PTA_ACK_MODE_DEF (1)
525
526struct acx_bt_wlan_coex_param {
527 struct acx_header header;
528
529 /*
530 * The minimum rate of a received WLAN packet in the STA,
531 * during protective mode, of which a new BT-HP request
532 * during this Rx will always be respected and gain the antenna.
533 */
534 u32 min_rate;
535
536 /* Max time the BT HP will be respected. */
537 u16 bt_hp_max_time;
538
539 /* Max time the WLAN HP will be respected. */
540 u16 wlan_hp_max_time;
541
542 /*
543 * The time between the last BT activity
544 * and the moment when the sense mode returns
545 * to SENSE_INACTIVE.
546 */
547 u16 sense_disable_timer;
548
549 /* Time before the next BT HP instance */
550 u16 rx_time_bt_hp;
551 u16 tx_time_bt_hp;
552
553 /* range: 10-20000 default: 1500 */
554 u16 rx_time_bt_hp_fast;
555 u16 tx_time_bt_hp_fast;
556
557 /* range: 2000-65535 default: 8700 */
558 u16 wlan_cycle_fast;
559
560 /* range: 0 - 15000 (Msec) default: 1000 */
561 u16 bt_anti_starvation_period;
562
563 /* range 400-10000(Usec) default: 3000 */
564 u16 next_bt_lp_packet;
565
566 /* Deafult: worst case for BT DH5 traffic */
567 u16 wake_up_beacon;
568
569 /* range: 0-50000(Usec) default: 1050 */
570 u16 hp_dm_max_guard_time;
571
572 /*
573 * This is to prevent both BT & WLAN antenna
574 * starvation.
575 * Range: 100-50000(Usec) default:2550
576 */
577 u16 next_wlan_packet;
578
579 /* 0 -> shared antenna */
580 u8 antenna_type;
581
582 /*
583 * 0 -> TI legacy
584 * 1 -> Palau
585 */
586 u8 signal_type;
587
588 /*
589 * BT AFH status
590 * 0 -> no AFH
591 * 1 -> from dedicated GPIO
592 * 2 -> AFH on (from host)
593 */
594 u8 afh_leverage_on;
595
596 /*
597 * The number of cycles during which no
598 * TX will be sent after 1 cycle of RX
599 * transaction in protective mode
600 */
601 u8 quiet_cycle_num;
602
603 /*
604 * The maximum number of CTSs that will
605 * be sent for receiving RX packet in
606 * protective mode
607 */
608 u8 max_cts;
609
610 /*
611 * The number of WLAN packets
612 * transferred in common mode before
613 * switching to BT.
614 */
615 u8 wlan_packets_num;
616
617 /*
618 * The number of BT packets
619 * transferred in common mode before
620 * switching to WLAN.
621 */
622 u8 bt_packets_num;
623
624 /* range: 1-255 default: 5 */
625 u8 missed_rx_avalanche;
626
627 /* range: 0-1 default: 1 */
628 u8 wlan_elp_hp;
629
630 /* range: 0 - 15 default: 4 */
631 u8 bt_anti_starvation_cycles;
632
633 u8 ack_mode_dual_ant;
634
635 /*
636 * Allow PA_SD assertion/de-assertion
637 * during enabled BT activity.
638 */
639 u8 pa_sd_enable;
640
641 /*
642 * Enable/Disable PTA in auto mode:
643 * Support Both Active & P.S modes
644 */
645 u8 pta_auto_mode_enable;
646
647 /* range: 0 - 20 default: 1 */
648 u8 bt_hp_respected_num;
649} __attribute__ ((packed));
650
651#define CCA_THRSH_ENABLE_ENERGY_D 0x140A
652#define CCA_THRSH_DISABLE_ENERGY_D 0xFFEF
653
654struct acx_energy_detection {
655 struct acx_header header;
656
657 /* The RX Clear Channel Assessment threshold in the PHY */
658 u16 rx_cca_threshold;
659 u8 tx_energy_detection;
660 u8 pad;
661} __attribute__ ((packed));
662
663#define BCN_RX_TIMEOUT_DEF_VALUE 10000
664#define BROADCAST_RX_TIMEOUT_DEF_VALUE 20000
665#define RX_BROADCAST_IN_PS_DEF_VALUE 1
666#define CONSECUTIVE_PS_POLL_FAILURE_DEF 4
667
668struct acx_beacon_broadcast {
669 struct acx_header header;
670
671 u16 beacon_rx_timeout;
672 u16 broadcast_timeout;
673
674 /* Enables receiving of broadcast packets in PS mode */
675 u8 rx_broadcast_in_ps;
676
677 /* Consecutive PS Poll failures before updating the host */
678 u8 ps_poll_threshold;
679 u8 pad[2];
680} __attribute__ ((packed));
681
682struct acx_event_mask {
683 struct acx_header header;
684
685 u32 event_mask;
686 u32 high_event_mask; /* Unused */
687} __attribute__ ((packed));
688
689#define CFG_RX_FCS BIT(2)
690#define CFG_RX_ALL_GOOD BIT(3)
691#define CFG_UNI_FILTER_EN BIT(4)
692#define CFG_BSSID_FILTER_EN BIT(5)
693#define CFG_MC_FILTER_EN BIT(6)
694#define CFG_MC_ADDR0_EN BIT(7)
695#define CFG_MC_ADDR1_EN BIT(8)
696#define CFG_BC_REJECT_EN BIT(9)
697#define CFG_SSID_FILTER_EN BIT(10)
698#define CFG_RX_INT_FCS_ERROR BIT(11)
699#define CFG_RX_INT_ENCRYPTED BIT(12)
700#define CFG_RX_WR_RX_STATUS BIT(13)
701#define CFG_RX_FILTER_NULTI BIT(14)
702#define CFG_RX_RESERVE BIT(15)
703#define CFG_RX_TIMESTAMP_TSF BIT(16)
704
705#define CFG_RX_RSV_EN BIT(0)
706#define CFG_RX_RCTS_ACK BIT(1)
707#define CFG_RX_PRSP_EN BIT(2)
708#define CFG_RX_PREQ_EN BIT(3)
709#define CFG_RX_MGMT_EN BIT(4)
710#define CFG_RX_FCS_ERROR BIT(5)
711#define CFG_RX_DATA_EN BIT(6)
712#define CFG_RX_CTL_EN BIT(7)
713#define CFG_RX_CF_EN BIT(8)
714#define CFG_RX_BCN_EN BIT(9)
715#define CFG_RX_AUTH_EN BIT(10)
716#define CFG_RX_ASSOC_EN BIT(11)
717
718#define SCAN_PASSIVE BIT(0)
719#define SCAN_5GHZ_BAND BIT(1)
720#define SCAN_TRIGGERED BIT(2)
721#define SCAN_PRIORITY_HIGH BIT(3)
722
723struct acx_fw_gen_frame_rates {
724 struct acx_header header;
725
726 u8 tx_ctrl_frame_rate; /* RATE_* */
727 u8 tx_ctrl_frame_mod; /* CCK_* or PBCC_* */
728 u8 tx_mgt_frame_rate;
729 u8 tx_mgt_frame_mod;
730} __attribute__ ((packed));
731
732/* STA MAC */
733struct dot11_station_id {
734 struct acx_header header;
735
736 u8 mac[ETH_ALEN];
737 u8 pad[2];
738} __attribute__ ((packed));
739
740/* HW encryption keys */
741#define NUM_ACCESS_CATEGORIES_COPY 4
742#define MAX_KEY_SIZE 32
743
744/* When set, disable HW encryption */
745#define DF_ENCRYPTION_DISABLE 0x01
746/* When set, disable HW decryption */
747#define DF_SNIFF_MODE_ENABLE 0x80
748
749struct acx_feature_config {
750 struct acx_header header;
751
752 u32 options;
753 u32 data_flow_options;
754} __attribute__ ((packed));
755
756enum acx_key_action {
757 KEY_ADD_OR_REPLACE = 1,
758 KEY_REMOVE = 2,
759 KEY_SET_ID = 3,
760 MAX_KEY_ACTION = 0xffff,
761};
762
763enum acx_key_type {
764 KEY_WEP_DEFAULT = 0,
765 KEY_WEP_ADDR = 1,
766 KEY_AES_GROUP = 4,
767 KEY_AES_PAIRWISE = 5,
768 KEY_WEP_GROUP = 6,
769 KEY_TKIP_MIC_GROUP = 10,
770 KEY_TKIP_MIC_PAIRWISE = 11,
771};
772
773/*
774 *
775 * key_type_e key size key format
776 * ---------- --------- ----------
777 * 0x00 5, 13, 29 Key data
778 * 0x01 5, 13, 29 Key data
779 * 0x04 16 16 bytes of key data
780 * 0x05 16 16 bytes of key data
781 * 0x0a 32 16 bytes of TKIP key data
782 * 8 bytes of RX MIC key data
783 * 8 bytes of TX MIC key data
784 * 0x0b 32 16 bytes of TKIP key data
785 * 8 bytes of RX MIC key data
786 * 8 bytes of TX MIC key data
787 *
788 */
789
790struct acx_set_key {
791 /* Ignored for default WEP key */
792 u8 addr[ETH_ALEN];
793
794 /* key_action_e */
795 u16 key_action;
796
797 u16 reserved_1;
798
799 /* key size in bytes */
800 u8 key_size;
801
802 /* key_type_e */
803 u8 key_type;
804 u8 ssid_profile;
805
806 /*
807 * TKIP, AES: frame's key id field.
808 * For WEP default key: key id;
809 */
810 u8 id;
811 u8 reserved_2[6];
812 u8 key[MAX_KEY_SIZE];
813 u16 ac_seq_num16[NUM_ACCESS_CATEGORIES_COPY];
814 u32 ac_seq_num32[NUM_ACCESS_CATEGORIES_COPY];
815} __attribute__ ((packed));
816
817struct acx_current_tx_power {
818 struct acx_header header;
819
820 u8 current_tx_power;
821 u8 padding[3];
822} __attribute__ ((packed));
823
824struct acx_dot11_default_key {
825 struct acx_header header;
826
827 u8 id;
828 u8 pad[3];
829} __attribute__ ((packed));
830
831struct acx_tsf_info {
832 struct acx_header header;
833
834 u32 current_tsf_msb;
835 u32 current_tsf_lsb;
836 u32 last_TBTT_msb;
837 u32 last_TBTT_lsb;
838 u8 last_dtim_count;
839 u8 pad[3];
840} __attribute__ ((packed));
841
842/* 802.11 PS */
843enum acx_ps_mode {
844 STATION_ACTIVE_MODE,
845 STATION_POWER_SAVE_MODE
846};
847
848struct acx_ps_params {
849 u8 ps_mode; /* STATION_* */
850 u8 send_null_data; /* Do we have to send NULL data packet ? */
851 u8 retries; /* Number of retires for the initial NULL data packet */
852
853 /*
854 * TUs during which the target stays awake after switching
855 * to power save mode.
856 */
857 u8 hang_over_period;
858 u16 null_data_rate;
859 u8 pad[2];
860} __attribute__ ((packed));
861
862enum acx_wake_up_event {
863 WAKE_UP_EVENT_BEACON_BITMAP = 0x01, /* Wake on every Beacon*/
864 WAKE_UP_EVENT_DTIM_BITMAP = 0x02, /* Wake on every DTIM*/
865 WAKE_UP_EVENT_N_DTIM_BITMAP = 0x04, /* Wake on every Nth DTIM */
866 WAKE_UP_EVENT_N_BEACONS_BITMAP = 0x08, /* Wake on every Nth Beacon */
867 WAKE_UP_EVENT_BITS_MASK = 0x0F
868};
869
870struct acx_wake_up_condition {
871 struct acx_header header;
872
873 u8 wake_up_event; /* Only one bit can be set */
874 u8 listen_interval;
875 u8 pad[2];
876} __attribute__ ((packed));
877
878struct acx_aid {
879 struct acx_header header;
880
881 /*
882 * To be set when associated with an AP.
883 */
884 u16 aid;
885 u8 pad[2];
886} __attribute__ ((packed));
887
888enum acx_preamble_type {
889 ACX_PREAMBLE_LONG = 0,
890 ACX_PREAMBLE_SHORT = 1
891};
892
893struct acx_preamble {
894 struct acx_header header;
895 /*
896 * When set, the WiLink transmits the frames with a short preamble and
897 * when cleared, the WiLink transmits the frames with a long preamble.
898 */
899 u8 preamble;
900 u8 padding[3];
901} __attribute__ ((packed));
902
903enum acx_ctsprotect_type {
904 CTSPROTECT_DISABLE = 0,
905 CTSPROTECT_ENABLE = 1
906};
907
908struct acx_ctsprotect {
909 struct acx_header header;
910 u8 ctsprotect;
911 u8 padding[3];
912} __attribute__ ((packed));
913
914struct acx_tx_statistics {
915 u32 internal_desc_overflow;
916} __attribute__ ((packed));
917
918struct acx_rx_statistics {
919 u32 out_of_mem;
920 u32 hdr_overflow;
921 u32 hw_stuck;
922 u32 dropped;
923 u32 fcs_err;
924 u32 xfr_hint_trig;
925 u32 path_reset;
926 u32 reset_counter;
927} __attribute__ ((packed));
928
929struct acx_dma_statistics {
930 u32 rx_requested;
931 u32 rx_errors;
932 u32 tx_requested;
933 u32 tx_errors;
934} __attribute__ ((packed));
935
936struct acx_isr_statistics {
937 /* host command complete */
938 u32 cmd_cmplt;
939
940 /* fiqisr() */
941 u32 fiqs;
942
943 /* (INT_STS_ND & INT_TRIG_RX_HEADER) */
944 u32 rx_headers;
945
946 /* (INT_STS_ND & INT_TRIG_RX_CMPLT) */
947 u32 rx_completes;
948
949 /* (INT_STS_ND & INT_TRIG_NO_RX_BUF) */
950 u32 rx_mem_overflow;
951
952 /* (INT_STS_ND & INT_TRIG_S_RX_RDY) */
953 u32 rx_rdys;
954
955 /* irqisr() */
956 u32 irqs;
957
958 /* (INT_STS_ND & INT_TRIG_TX_PROC) */
959 u32 tx_procs;
960
961 /* (INT_STS_ND & INT_TRIG_DECRYPT_DONE) */
962 u32 decrypt_done;
963
964 /* (INT_STS_ND & INT_TRIG_DMA0) */
965 u32 dma0_done;
966
967 /* (INT_STS_ND & INT_TRIG_DMA1) */
968 u32 dma1_done;
969
970 /* (INT_STS_ND & INT_TRIG_TX_EXC_CMPLT) */
971 u32 tx_exch_complete;
972
973 /* (INT_STS_ND & INT_TRIG_COMMAND) */
974 u32 commands;
975
976 /* (INT_STS_ND & INT_TRIG_RX_PROC) */
977 u32 rx_procs;
978
979 /* (INT_STS_ND & INT_TRIG_PM_802) */
980 u32 hw_pm_mode_changes;
981
982 /* (INT_STS_ND & INT_TRIG_ACKNOWLEDGE) */
983 u32 host_acknowledges;
984
985 /* (INT_STS_ND & INT_TRIG_PM_PCI) */
986 u32 pci_pm;
987
988 /* (INT_STS_ND & INT_TRIG_ACM_WAKEUP) */
989 u32 wakeups;
990
991 /* (INT_STS_ND & INT_TRIG_LOW_RSSI) */
992 u32 low_rssi;
993} __attribute__ ((packed));
994
995struct acx_wep_statistics {
996 /* WEP address keys configured */
997 u32 addr_key_count;
998
999 /* default keys configured */
1000 u32 default_key_count;
1001
1002 u32 reserved;
1003
1004 /* number of times that WEP key not found on lookup */
1005 u32 key_not_found;
1006
1007 /* number of times that WEP key decryption failed */
1008 u32 decrypt_fail;
1009
1010 /* WEP packets decrypted */
1011 u32 packets;
1012
1013 /* WEP decrypt interrupts */
1014 u32 interrupt;
1015} __attribute__ ((packed));
1016
1017#define ACX_MISSED_BEACONS_SPREAD 10
1018
1019struct acx_pwr_statistics {
1020 /* the amount of enters into power save mode (both PD & ELP) */
1021 u32 ps_enter;
1022
1023 /* the amount of enters into ELP mode */
1024 u32 elp_enter;
1025
1026 /* the amount of missing beacon interrupts to the host */
1027 u32 missing_bcns;
1028
1029 /* the amount of wake on host-access times */
1030 u32 wake_on_host;
1031
1032 /* the amount of wake on timer-expire */
1033 u32 wake_on_timer_exp;
1034
1035 /* the number of packets that were transmitted with PS bit set */
1036 u32 tx_with_ps;
1037
1038 /* the number of packets that were transmitted with PS bit clear */
1039 u32 tx_without_ps;
1040
1041 /* the number of received beacons */
1042 u32 rcvd_beacons;
1043
1044 /* the number of entering into PowerOn (power save off) */
1045 u32 power_save_off;
1046
1047 /* the number of entries into power save mode */
1048 u16 enable_ps;
1049
1050 /*
1051 * the number of exits from power save, not including failed PS
1052 * transitions
1053 */
1054 u16 disable_ps;
1055
1056 /*
1057 * the number of times the TSF counter was adjusted because
1058 * of drift
1059 */
1060 u32 fix_tsf_ps;
1061
1062 /* Gives statistics about the spread continuous missed beacons.
1063 * The 16 LSB are dedicated for the PS mode.
1064 * The 16 MSB are dedicated for the PS mode.
1065 * cont_miss_bcns_spread[0] - single missed beacon.
1066 * cont_miss_bcns_spread[1] - two continuous missed beacons.
1067 * cont_miss_bcns_spread[2] - three continuous missed beacons.
1068 * ...
1069 * cont_miss_bcns_spread[9] - ten and more continuous missed beacons.
1070 */
1071 u32 cont_miss_bcns_spread[ACX_MISSED_BEACONS_SPREAD];
1072
1073 /* the number of beacons in awake mode */
1074 u32 rcvd_awake_beacons;
1075} __attribute__ ((packed));
1076
1077struct acx_mic_statistics {
1078 u32 rx_pkts;
1079 u32 calc_failure;
1080} __attribute__ ((packed));
1081
1082struct acx_aes_statistics {
1083 u32 encrypt_fail;
1084 u32 decrypt_fail;
1085 u32 encrypt_packets;
1086 u32 decrypt_packets;
1087 u32 encrypt_interrupt;
1088 u32 decrypt_interrupt;
1089} __attribute__ ((packed));
1090
1091struct acx_event_statistics {
1092 u32 heart_beat;
1093 u32 calibration;
1094 u32 rx_mismatch;
1095 u32 rx_mem_empty;
1096 u32 rx_pool;
1097 u32 oom_late;
1098 u32 phy_transmit_error;
1099 u32 tx_stuck;
1100} __attribute__ ((packed));
1101
1102struct acx_ps_statistics {
1103 u32 pspoll_timeouts;
1104 u32 upsd_timeouts;
1105 u32 upsd_max_sptime;
1106 u32 upsd_max_apturn;
1107 u32 pspoll_max_apturn;
1108 u32 pspoll_utilization;
1109 u32 upsd_utilization;
1110} __attribute__ ((packed));
1111
1112struct acx_rxpipe_statistics {
1113 u32 rx_prep_beacon_drop;
1114 u32 descr_host_int_trig_rx_data;
1115 u32 beacon_buffer_thres_host_int_trig_rx_data;
1116 u32 missed_beacon_host_int_trig_rx_data;
1117 u32 tx_xfr_host_int_trig_rx_data;
1118} __attribute__ ((packed));
1119
1120struct acx_statistics {
1121 struct acx_header header;
1122
1123 struct acx_tx_statistics tx;
1124 struct acx_rx_statistics rx;
1125 struct acx_dma_statistics dma;
1126 struct acx_isr_statistics isr;
1127 struct acx_wep_statistics wep;
1128 struct acx_pwr_statistics pwr;
1129 struct acx_aes_statistics aes;
1130 struct acx_mic_statistics mic;
1131 struct acx_event_statistics event;
1132 struct acx_ps_statistics ps;
1133 struct acx_rxpipe_statistics rxpipe;
1134} __attribute__ ((packed));
1135
1136enum {
1137 ACX_WAKE_UP_CONDITIONS = 0x0002,
1138 ACX_MEM_CFG = 0x0003,
1139 ACX_SLOT = 0x0004,
1140 ACX_QUEUE_HEAD = 0x0005, /* for MASTER mode only */
1141 ACX_AC_CFG = 0x0007,
1142 ACX_MEM_MAP = 0x0008,
1143 ACX_AID = 0x000A,
1144 ACX_RADIO_PARAM = 0x000B, /* Not used */
1145 ACX_CFG = 0x000C, /* Not used */
1146 ACX_FW_REV = 0x000D,
1147 ACX_MEDIUM_USAGE = 0x000F,
1148 ACX_RX_CFG = 0x0010,
1149 ACX_TX_QUEUE_CFG = 0x0011, /* FIXME: only used by wl1251 */
1150 ACX_BSS_IN_PS = 0x0012, /* for AP only */
1151 ACX_STATISTICS = 0x0013, /* Debug API */
1152 ACX_FEATURE_CFG = 0x0015,
1153 ACX_MISC_CFG = 0x0017, /* Not used */
1154 ACX_TID_CFG = 0x001A,
1155 ACX_BEACON_FILTER_OPT = 0x001F,
1156 ACX_LOW_RSSI = 0x0020,
1157 ACX_NOISE_HIST = 0x0021,
1158 ACX_HDK_VERSION = 0x0022, /* ??? */
1159 ACX_PD_THRESHOLD = 0x0023,
1160 ACX_DATA_PATH_PARAMS = 0x0024, /* WO */
1161 ACX_DATA_PATH_RESP_PARAMS = 0x0024, /* RO */
1162 ACX_CCA_THRESHOLD = 0x0025,
1163 ACX_EVENT_MBOX_MASK = 0x0026,
1164#ifdef FW_RUNNING_AS_AP
1165 ACX_DTIM_PERIOD = 0x0027, /* for AP only */
1166#else
1167 ACX_WR_TBTT_AND_DTIM = 0x0027, /* STA only */
1168#endif
1169 ACX_ACI_OPTION_CFG = 0x0029, /* OBSOLETE (for 1251)*/
1170 ACX_GPIO_CFG = 0x002A, /* Not used */
1171 ACX_GPIO_SET = 0x002B, /* Not used */
1172 ACX_PM_CFG = 0x002C, /* To Be Documented */
1173 ACX_CONN_MONIT_PARAMS = 0x002D,
1174 ACX_AVERAGE_RSSI = 0x002E, /* Not used */
1175 ACX_CONS_TX_FAILURE = 0x002F,
1176 ACX_BCN_DTIM_OPTIONS = 0x0031,
1177 ACX_SG_ENABLE = 0x0032,
1178 ACX_SG_CFG = 0x0033,
1179 ACX_ANTENNA_DIVERSITY_CFG = 0x0035, /* To Be Documented */
1180 ACX_LOW_SNR = 0x0037, /* To Be Documented */
1181 ACX_BEACON_FILTER_TABLE = 0x0038,
1182 ACX_ARP_IP_FILTER = 0x0039,
1183 ACX_ROAMING_STATISTICS_TBL = 0x003B,
1184 ACX_RATE_POLICY = 0x003D,
1185 ACX_CTS_PROTECTION = 0x003E,
1186 ACX_SLEEP_AUTH = 0x003F,
1187 ACX_PREAMBLE_TYPE = 0x0040,
1188 ACX_ERROR_CNT = 0x0041,
1189 ACX_FW_GEN_FRAME_RATES = 0x0042,
1190 ACX_IBSS_FILTER = 0x0044,
1191 ACX_SERVICE_PERIOD_TIMEOUT = 0x0045,
1192 ACX_TSF_INFO = 0x0046,
1193 ACX_CONFIG_PS_WMM = 0x0049,
1194 ACX_ENABLE_RX_DATA_FILTER = 0x004A,
1195 ACX_SET_RX_DATA_FILTER = 0x004B,
1196 ACX_GET_DATA_FILTER_STATISTICS = 0x004C,
1197 ACX_POWER_LEVEL_TABLE = 0x004D,
1198 ACX_BET_ENABLE = 0x0050,
1199 DOT11_STATION_ID = 0x1001,
1200 DOT11_RX_MSDU_LIFE_TIME = 0x1004,
1201 DOT11_CUR_TX_PWR = 0x100D,
1202 DOT11_DEFAULT_KEY = 0x1010,
1203 DOT11_RX_DOT11_MODE = 0x1012,
1204 DOT11_RTS_THRESHOLD = 0x1013,
1205 DOT11_GROUP_ADDRESS_TBL = 0x1014,
1206
1207 MAX_DOT11_IE = DOT11_GROUP_ADDRESS_TBL,
1208
1209 MAX_IE = 0xFFFF
1210};
1211
1212
1213int wl12xx_acx_frame_rates(struct wl12xx *wl, u8 ctrl_rate, u8 ctrl_mod,
1214 u8 mgt_rate, u8 mgt_mod);
1215int wl12xx_acx_station_id(struct wl12xx *wl);
1216int wl12xx_acx_default_key(struct wl12xx *wl, u8 key_id);
1217int wl12xx_acx_wake_up_conditions(struct wl12xx *wl, u8 listen_interval);
1218int wl12xx_acx_sleep_auth(struct wl12xx *wl, u8 sleep_auth);
1219int wl12xx_acx_fw_version(struct wl12xx *wl, char *buf, size_t len);
1220int wl12xx_acx_tx_power(struct wl12xx *wl, int power);
1221int wl12xx_acx_feature_cfg(struct wl12xx *wl);
1222int wl12xx_acx_mem_map(struct wl12xx *wl, void *mem_map, size_t len);
1223int wl12xx_acx_data_path_params(struct wl12xx *wl,
1224 struct acx_data_path_params_resp *data_path);
1225int wl12xx_acx_rx_msdu_life_time(struct wl12xx *wl, u32 life_time);
1226int wl12xx_acx_rx_config(struct wl12xx *wl, u32 config, u32 filter);
1227int wl12xx_acx_pd_threshold(struct wl12xx *wl);
1228int wl12xx_acx_slot(struct wl12xx *wl, enum acx_slot_type slot_time);
1229int wl12xx_acx_group_address_tbl(struct wl12xx *wl);
1230int wl12xx_acx_service_period_timeout(struct wl12xx *wl);
1231int wl12xx_acx_rts_threshold(struct wl12xx *wl, u16 rts_threshold);
1232int wl12xx_acx_beacon_filter_opt(struct wl12xx *wl);
1233int wl12xx_acx_beacon_filter_table(struct wl12xx *wl);
1234int wl12xx_acx_sg_enable(struct wl12xx *wl);
1235int wl12xx_acx_sg_cfg(struct wl12xx *wl);
1236int wl12xx_acx_cca_threshold(struct wl12xx *wl);
1237int wl12xx_acx_bcn_dtim_options(struct wl12xx *wl);
1238int wl12xx_acx_aid(struct wl12xx *wl, u16 aid);
1239int wl12xx_acx_event_mbox_mask(struct wl12xx *wl, u32 event_mask);
1240int wl12xx_acx_set_preamble(struct wl12xx *wl, enum acx_preamble_type preamble);
1241int wl12xx_acx_cts_protect(struct wl12xx *wl,
1242 enum acx_ctsprotect_type ctsprotect);
1243int wl12xx_acx_statistics(struct wl12xx *wl, struct acx_statistics *stats);
1244
1245#endif /* __WL12XX_ACX_H__ */
diff --git a/drivers/net/wireless/wl12xx/boot.c b/drivers/net/wireless/wl12xx/boot.c
new file mode 100644
index 000000000000..48ac08c429bd
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/boot.c
@@ -0,0 +1,295 @@
1/*
2 * This file is part of wl12xx
3 *
4 * Copyright (C) 2008 Nokia Corporation
5 *
6 * Contact: Kalle Valo <kalle.valo@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/gpio.h>
25
26#include "reg.h"
27#include "boot.h"
28#include "spi.h"
29#include "event.h"
30
31static void wl12xx_boot_enable_interrupts(struct wl12xx *wl)
32{
33 enable_irq(wl->irq);
34}
35
36void wl12xx_boot_target_enable_interrupts(struct wl12xx *wl)
37{
38 wl12xx_reg_write32(wl, ACX_REG_INTERRUPT_MASK, ~(wl->intr_mask));
39 wl12xx_reg_write32(wl, HI_CFG, HI_CFG_DEF_VAL);
40}
41
42int wl12xx_boot_soft_reset(struct wl12xx *wl)
43{
44 unsigned long timeout;
45 u32 boot_data;
46
47 /* perform soft reset */
48 wl12xx_reg_write32(wl, ACX_REG_SLV_SOFT_RESET, ACX_SLV_SOFT_RESET_BIT);
49
50 /* SOFT_RESET is self clearing */
51 timeout = jiffies + usecs_to_jiffies(SOFT_RESET_MAX_TIME);
52 while (1) {
53 boot_data = wl12xx_reg_read32(wl, ACX_REG_SLV_SOFT_RESET);
54 wl12xx_debug(DEBUG_BOOT, "soft reset bootdata 0x%x", boot_data);
55 if ((boot_data & ACX_SLV_SOFT_RESET_BIT) == 0)
56 break;
57
58 if (time_after(jiffies, timeout)) {
59 /* 1.2 check pWhalBus->uSelfClearTime if the
60 * timeout was reached */
61 wl12xx_error("soft reset timeout");
62 return -1;
63 }
64
65 udelay(SOFT_RESET_STALL_TIME);
66 }
67
68 /* disable Rx/Tx */
69 wl12xx_reg_write32(wl, ENABLE, 0x0);
70
71 /* disable auto calibration on start*/
72 wl12xx_reg_write32(wl, SPARE_A2, 0xffff);
73
74 return 0;
75}
76
77int wl12xx_boot_init_seq(struct wl12xx *wl)
78{
79 u32 scr_pad6, init_data, tmp, elp_cmd, ref_freq;
80
81 /*
82 * col #1: INTEGER_DIVIDER
83 * col #2: FRACTIONAL_DIVIDER
84 * col #3: ATTN_BB
85 * col #4: ALPHA_BB
86 * col #5: STOP_TIME_BB
87 * col #6: BB_PLL_LOOP_FILTER
88 */
89 static const u32 LUT[REF_FREQ_NUM][LUT_PARAM_NUM] = {
90
91 { 83, 87381, 0xB, 5, 0xF00, 3}, /* REF_FREQ_19_2*/
92 { 61, 141154, 0xB, 5, 0x1450, 2}, /* REF_FREQ_26_0*/
93 { 41, 174763, 0xC, 6, 0x2D00, 1}, /* REF_FREQ_38_4*/
94 { 40, 0, 0xC, 6, 0x2EE0, 1}, /* REF_FREQ_40_0*/
95 { 47, 162280, 0xC, 6, 0x2760, 1} /* REF_FREQ_33_6 */
96 };
97
98 /* read NVS params */
99 scr_pad6 = wl12xx_reg_read32(wl, SCR_PAD6);
100 wl12xx_debug(DEBUG_BOOT, "scr_pad6 0x%x", scr_pad6);
101
102 /* read ELP_CMD */
103 elp_cmd = wl12xx_reg_read32(wl, ELP_CMD);
104 wl12xx_debug(DEBUG_BOOT, "elp_cmd 0x%x", elp_cmd);
105
106 /* set the BB calibration time to be 300 usec (PLL_CAL_TIME) */
107 ref_freq = scr_pad6 & 0x000000FF;
108 wl12xx_debug(DEBUG_BOOT, "ref_freq 0x%x", ref_freq);
109
110 wl12xx_reg_write32(wl, PLL_CAL_TIME, 0x9);
111
112 /*
113 * PG 1.2: set the clock buffer time to be 210 usec (CLK_BUF_TIME)
114 */
115 wl12xx_reg_write32(wl, CLK_BUF_TIME, 0x6);
116
117 /*
118 * set the clock detect feature to work in the restart wu procedure
119 * (ELP_CFG_MODE[14]) and Select the clock source type
120 * (ELP_CFG_MODE[13:12])
121 */
122 tmp = ((scr_pad6 & 0x0000FF00) << 4) | 0x00004000;
123 wl12xx_reg_write32(wl, ELP_CFG_MODE, tmp);
124
125 /* PG 1.2: enable the BB PLL fix. Enable the PLL_LIMP_CLK_EN_CMD */
126 elp_cmd |= 0x00000040;
127 wl12xx_reg_write32(wl, ELP_CMD, elp_cmd);
128
129 /* PG 1.2: Set the BB PLL stable time to be 1000usec
130 * (PLL_STABLE_TIME) */
131 wl12xx_reg_write32(wl, CFG_PLL_SYNC_CNT, 0x20);
132
133 /* PG 1.2: read clock request time */
134 init_data = wl12xx_reg_read32(wl, CLK_REQ_TIME);
135
136 /*
137 * PG 1.2: set the clock request time to be ref_clk_settling_time -
138 * 1ms = 4ms
139 */
140 if (init_data > 0x21)
141 tmp = init_data - 0x21;
142 else
143 tmp = 0;
144 wl12xx_reg_write32(wl, CLK_REQ_TIME, tmp);
145
146 /* set BB PLL configurations in RF AFE */
147 wl12xx_reg_write32(wl, 0x003058cc, 0x4B5);
148
149 /* set RF_AFE_REG_5 */
150 wl12xx_reg_write32(wl, 0x003058d4, 0x50);
151
152 /* set RF_AFE_CTRL_REG_2 */
153 wl12xx_reg_write32(wl, 0x00305948, 0x11c001);
154
155 /*
156 * change RF PLL and BB PLL divider for VCO clock and adjust VCO
157 * bais current(RF_AFE_REG_13)
158 */
159 wl12xx_reg_write32(wl, 0x003058f4, 0x1e);
160
161 /* set BB PLL configurations */
162 tmp = LUT[ref_freq][LUT_PARAM_INTEGER_DIVIDER] | 0x00017000;
163 wl12xx_reg_write32(wl, 0x00305840, tmp);
164
165 /* set fractional divider according to Appendix C-BB PLL
166 * Calculations
167 */
168 tmp = LUT[ref_freq][LUT_PARAM_FRACTIONAL_DIVIDER];
169 wl12xx_reg_write32(wl, 0x00305844, tmp);
170
171 /* set the initial data for the sigma delta */
172 wl12xx_reg_write32(wl, 0x00305848, 0x3039);
173
174 /*
175 * set the accumulator attenuation value, calibration loop1
176 * (alpha), calibration loop2 (beta), calibration loop3 (gamma) and
177 * the VCO gain
178 */
179 tmp = (LUT[ref_freq][LUT_PARAM_ATTN_BB] << 16) |
180 (LUT[ref_freq][LUT_PARAM_ALPHA_BB] << 12) | 0x1;
181 wl12xx_reg_write32(wl, 0x00305854, tmp);
182
183 /*
184 * set the calibration stop time after holdoff time expires and set
185 * settling time HOLD_OFF_TIME_BB
186 */
187 tmp = LUT[ref_freq][LUT_PARAM_STOP_TIME_BB] | 0x000A0000;
188 wl12xx_reg_write32(wl, 0x00305858, tmp);
189
190 /*
191 * set BB PLL Loop filter capacitor3- BB_C3[2:0] and set BB PLL
192 * constant leakage current to linearize PFD to 0uA -
193 * BB_ILOOPF[7:3]
194 */
195 tmp = LUT[ref_freq][LUT_PARAM_BB_PLL_LOOP_FILTER] | 0x00000030;
196 wl12xx_reg_write32(wl, 0x003058f8, tmp);
197
198 /*
199 * set regulator output voltage for n divider to
200 * 1.35-BB_REFDIV[1:0], set charge pump current- BB_CPGAIN[4:2],
201 * set BB PLL Loop filter capacitor2- BB_C2[7:5], set gain of BB
202 * PLL auto-call to normal mode- BB_CALGAIN_3DB[8]
203 */
204 wl12xx_reg_write32(wl, 0x003058f0, 0x29);
205
206 /* enable restart wakeup sequence (ELP_CMD[0]) */
207 wl12xx_reg_write32(wl, ELP_CMD, elp_cmd | 0x1);
208
209 /* restart sequence completed */
210 udelay(2000);
211
212 return 0;
213}
214
215int wl12xx_boot_run_firmware(struct wl12xx *wl)
216{
217 int loop, ret;
218 u32 chip_id, interrupt;
219
220 wl->chip.op_set_ecpu_ctrl(wl, ECPU_CONTROL_HALT);
221
222 chip_id = wl12xx_reg_read32(wl, CHIP_ID_B);
223
224 wl12xx_debug(DEBUG_BOOT, "chip id after firmware boot: 0x%x", chip_id);
225
226 if (chip_id != wl->chip.id) {
227 wl12xx_error("chip id doesn't match after firmware boot");
228 return -EIO;
229 }
230
231 /* wait for init to complete */
232 loop = 0;
233 while (loop++ < INIT_LOOP) {
234 udelay(INIT_LOOP_DELAY);
235 interrupt = wl12xx_reg_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
236
237 if (interrupt == 0xffffffff) {
238 wl12xx_error("error reading hardware complete "
239 "init indication");
240 return -EIO;
241 }
242 /* check that ACX_INTR_INIT_COMPLETE is enabled */
243 else if (interrupt & wl->chip.intr_init_complete) {
244 wl12xx_reg_write32(wl, ACX_REG_INTERRUPT_ACK,
245 wl->chip.intr_init_complete);
246 break;
247 }
248 }
249
250 if (loop >= INIT_LOOP) {
251 wl12xx_error("timeout waiting for the hardware to "
252 "complete initialization");
253 return -EIO;
254 }
255
256 /* get hardware config command mail box */
257 wl->cmd_box_addr = wl12xx_reg_read32(wl, REG_COMMAND_MAILBOX_PTR);
258
259 /* get hardware config event mail box */
260 wl->event_box_addr = wl12xx_reg_read32(wl, REG_EVENT_MAILBOX_PTR);
261
262 /* set the working partition to its "running" mode offset */
263 wl12xx_set_partition(wl,
264 wl->chip.p_table[PART_WORK].mem.start,
265 wl->chip.p_table[PART_WORK].mem.size,
266 wl->chip.p_table[PART_WORK].reg.start,
267 wl->chip.p_table[PART_WORK].reg.size);
268
269 wl12xx_debug(DEBUG_MAILBOX, "cmd_box_addr 0x%x event_box_addr 0x%x",
270 wl->cmd_box_addr, wl->event_box_addr);
271
272 /*
273 * in case of full asynchronous mode the firmware event must be
274 * ready to receive event from the command mailbox
275 */
276
277 /* enable gpio interrupts */
278 wl12xx_boot_enable_interrupts(wl);
279
280 wl->chip.op_target_enable_interrupts(wl);
281
282 /* unmask all mbox events */
283 wl->event_mask = 0xffffffff;
284
285 ret = wl12xx_event_unmask(wl);
286 if (ret < 0) {
287 wl12xx_error("EVENT mask setting failed");
288 return ret;
289 }
290
291 wl12xx_event_mbox_config(wl);
292
293 /* firmware startup completed */
294 return 0;
295}
diff --git a/drivers/net/wireless/wl12xx/boot.h b/drivers/net/wireless/wl12xx/boot.h
new file mode 100644
index 000000000000..4fa73132baae
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/boot.h
@@ -0,0 +1,40 @@
1/*
2 * This file is part of wl12xx
3 *
4 * Copyright (C) 2008 Nokia Corporation
5 *
6 * Contact: Kalle Valo <kalle.valo@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 __BOOT_H__
25#define __BOOT_H__
26
27#include "wl12xx.h"
28
29int wl12xx_boot_soft_reset(struct wl12xx *wl);
30int wl12xx_boot_init_seq(struct wl12xx *wl);
31int wl12xx_boot_run_firmware(struct wl12xx *wl);
32void wl12xx_boot_target_enable_interrupts(struct wl12xx *wl);
33
34/* number of times we try to read the INIT interrupt */
35#define INIT_LOOP 20000
36
37/* delay between retries */
38#define INIT_LOOP_DELAY 50
39
40#endif
diff --git a/drivers/net/wireless/wl12xx/cmd.c b/drivers/net/wireless/wl12xx/cmd.c
new file mode 100644
index 000000000000..f73ab602b7ae
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/cmd.c
@@ -0,0 +1,353 @@
1#include "cmd.h"
2
3#include <linux/module.h>
4#include <linux/crc7.h>
5#include <linux/spi/spi.h>
6
7#include "wl12xx.h"
8#include "wl12xx_80211.h"
9#include "reg.h"
10#include "spi.h"
11#include "ps.h"
12
13int wl12xx_cmd_send(struct wl12xx *wl, u16 type, void *buf, size_t buf_len)
14{
15 struct wl12xx_command cmd;
16 unsigned long timeout;
17 size_t cmd_len;
18 u32 intr;
19 int ret = 0;
20
21 memset(&cmd, 0, sizeof(cmd));
22 cmd.id = type;
23 cmd.status = 0;
24 memcpy(cmd.parameters, buf, buf_len);
25 cmd_len = ALIGN(buf_len, 4) + CMDMBOX_HEADER_LEN;
26
27 wl12xx_ps_elp_wakeup(wl);
28
29 wl12xx_spi_mem_write(wl, wl->cmd_box_addr, &cmd, cmd_len);
30
31 wl12xx_reg_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_CMD);
32
33 timeout = jiffies + msecs_to_jiffies(WL12XX_COMMAND_TIMEOUT);
34
35 intr = wl12xx_reg_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
36 while (!(intr & wl->chip.intr_cmd_complete)) {
37 if (time_after(jiffies, timeout)) {
38 wl12xx_error("command complete timeout");
39 ret = -ETIMEDOUT;
40 goto out;
41 }
42
43 msleep(1);
44
45 intr = wl12xx_reg_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
46 }
47
48 wl12xx_reg_write32(wl, ACX_REG_INTERRUPT_ACK,
49 wl->chip.intr_cmd_complete);
50
51out:
52 wl12xx_ps_elp_sleep(wl);
53
54 return ret;
55}
56
57int wl12xx_cmd_test(struct wl12xx *wl, void *buf, size_t buf_len, u8 answer)
58{
59 int ret;
60
61 wl12xx_debug(DEBUG_CMD, "cmd test");
62
63 ret = wl12xx_cmd_send(wl, CMD_TEST, buf, buf_len);
64 if (ret < 0) {
65 wl12xx_warning("TEST command failed");
66 return ret;
67 }
68
69 if (answer) {
70 struct wl12xx_command *cmd_answer;
71
72 /*
73 * The test command got in, we can read the answer.
74 * The answer would be a wl12xx_command, where the
75 * parameter array contains the actual answer.
76 */
77
78 wl12xx_ps_elp_wakeup(wl);
79
80 wl12xx_spi_mem_read(wl, wl->cmd_box_addr, buf, buf_len);
81
82 wl12xx_ps_elp_sleep(wl);
83
84 cmd_answer = buf;
85 if (cmd_answer->status != CMD_STATUS_SUCCESS)
86 wl12xx_error("TEST command answer error: %d",
87 cmd_answer->status);
88 }
89
90 return 0;
91}
92
93
94int wl12xx_cmd_interrogate(struct wl12xx *wl, u16 ie_id, u16 ie_len,
95 void *answer)
96{
97 struct wl12xx_command *cmd;
98 struct acx_header header;
99 int ret;
100
101 wl12xx_debug(DEBUG_CMD, "cmd interrogate");
102
103 header.id = ie_id;
104 header.len = ie_len - sizeof(header);
105
106 ret = wl12xx_cmd_send(wl, CMD_INTERROGATE, &header, sizeof(header));
107 if (ret < 0) {
108 wl12xx_error("INTERROGATE command failed");
109 return ret;
110 }
111
112 wl12xx_ps_elp_wakeup(wl);
113
114 /* the interrogate command got in, we can read the answer */
115 wl12xx_spi_mem_read(wl, wl->cmd_box_addr, answer,
116 CMDMBOX_HEADER_LEN + ie_len);
117
118 wl12xx_ps_elp_sleep(wl);
119
120 cmd = answer;
121 if (cmd->status != CMD_STATUS_SUCCESS)
122 wl12xx_error("INTERROGATE command error: %d",
123 cmd->status);
124
125 return 0;
126
127}
128
129int wl12xx_cmd_configure(struct wl12xx *wl, void *ie, int ie_len)
130{
131 int ret;
132
133 wl12xx_debug(DEBUG_CMD, "cmd configure");
134
135 ret = wl12xx_cmd_send(wl, CMD_CONFIGURE, ie,
136 ie_len);
137 if (ret < 0) {
138 wl12xx_warning("CONFIGURE command NOK");
139 return ret;
140 }
141
142 return 0;
143
144}
145
146int wl12xx_cmd_vbm(struct wl12xx *wl, u8 identity,
147 void *bitmap, u16 bitmap_len, u8 bitmap_control)
148{
149 struct vbm_update_request vbm;
150 int ret;
151
152 wl12xx_debug(DEBUG_CMD, "cmd vbm");
153
154 /* Count and period will be filled by the target */
155 vbm.tim.bitmap_ctrl = bitmap_control;
156 if (bitmap_len > PARTIAL_VBM_MAX) {
157 wl12xx_warning("cmd vbm len is %d B, truncating to %d",
158 bitmap_len, PARTIAL_VBM_MAX);
159 bitmap_len = PARTIAL_VBM_MAX;
160 }
161 memcpy(vbm.tim.pvb_field, bitmap, bitmap_len);
162 vbm.tim.identity = identity;
163 vbm.tim.length = bitmap_len + 3;
164
165 vbm.len = cpu_to_le16(bitmap_len + 5);
166
167 ret = wl12xx_cmd_send(wl, CMD_VBM, &vbm, sizeof(vbm));
168 if (ret < 0) {
169 wl12xx_error("VBM command failed");
170 return ret;
171 }
172
173 return 0;
174}
175
176int wl12xx_cmd_data_path(struct wl12xx *wl, u8 channel, u8 enable)
177{
178 int ret;
179 u16 cmd_rx, cmd_tx;
180
181 wl12xx_debug(DEBUG_CMD, "cmd data path");
182
183 if (enable) {
184 cmd_rx = CMD_ENABLE_RX;
185 cmd_tx = CMD_ENABLE_TX;
186 } else {
187 cmd_rx = CMD_DISABLE_RX;
188 cmd_tx = CMD_DISABLE_TX;
189 }
190
191 ret = wl12xx_cmd_send(wl, cmd_rx, &channel, sizeof(channel));
192 if (ret < 0) {
193 wl12xx_error("rx %s cmd for channel %d failed",
194 enable ? "start" : "stop", channel);
195 return ret;
196 }
197
198 wl12xx_debug(DEBUG_BOOT, "rx %s cmd channel %d",
199 enable ? "start" : "stop", channel);
200
201 ret = wl12xx_cmd_send(wl, cmd_tx, &channel, sizeof(channel));
202 if (ret < 0) {
203 wl12xx_error("tx %s cmd for channel %d failed",
204 enable ? "start" : "stop", channel);
205 return ret;
206 }
207
208 wl12xx_debug(DEBUG_BOOT, "tx %s cmd channel %d",
209 enable ? "start" : "stop", channel);
210
211 return 0;
212}
213
214int wl12xx_cmd_join(struct wl12xx *wl, u8 bss_type, u8 dtim_interval,
215 u16 beacon_interval, u8 wait)
216{
217 unsigned long timeout;
218 struct cmd_join join = {};
219 int ret, i;
220 u8 *bssid;
221
222 /* FIXME: this should be in main.c */
223 ret = wl12xx_acx_frame_rates(wl, DEFAULT_HW_GEN_TX_RATE,
224 DEFAULT_HW_GEN_MODULATION_TYPE,
225 wl->tx_mgmt_frm_rate,
226 wl->tx_mgmt_frm_mod);
227 if (ret < 0)
228 return ret;
229
230 wl12xx_debug(DEBUG_CMD, "cmd join");
231
232 /* Reverse order BSSID */
233 bssid = (u8 *)&join.bssid_lsb;
234 for (i = 0; i < ETH_ALEN; i++)
235 bssid[i] = wl->bssid[ETH_ALEN - i - 1];
236
237 join.rx_config_options = wl->rx_config;
238 join.rx_filter_options = wl->rx_filter;
239
240 join.basic_rate_set = RATE_MASK_1MBPS | RATE_MASK_2MBPS |
241 RATE_MASK_5_5MBPS | RATE_MASK_11MBPS;
242
243 join.beacon_interval = beacon_interval;
244 join.dtim_interval = dtim_interval;
245 join.bss_type = bss_type;
246 join.channel = wl->channel;
247 join.ctrl = JOIN_CMD_CTRL_TX_FLUSH;
248
249 ret = wl12xx_cmd_send(wl, CMD_START_JOIN, &join, sizeof(join));
250 if (ret < 0) {
251 wl12xx_error("failed to initiate cmd join");
252 return ret;
253 }
254
255 timeout = msecs_to_jiffies(JOIN_TIMEOUT);
256
257 /*
258 * ugly hack: we should wait for JOIN_EVENT_COMPLETE_ID but to
259 * simplify locking we just sleep instead, for now
260 */
261 if (wait)
262 msleep(10);
263
264 return 0;
265}
266
267int wl12xx_cmd_ps_mode(struct wl12xx *wl, u8 ps_mode)
268{
269 int ret;
270 struct acx_ps_params ps_params;
271
272 /* FIXME: this should be in ps.c */
273 ret = wl12xx_acx_wake_up_conditions(wl, wl->listen_int);
274 if (ret < 0) {
275 wl12xx_error("Couldnt set wake up conditions");
276 return ret;
277 }
278
279 wl12xx_debug(DEBUG_CMD, "cmd set ps mode");
280
281 ps_params.ps_mode = ps_mode;
282 ps_params.send_null_data = 1;
283 ps_params.retries = 5;
284 ps_params.hang_over_period = 128;
285 ps_params.null_data_rate = 1; /* 1 Mbps */
286
287 ret = wl12xx_cmd_send(wl, CMD_SET_PS_MODE, &ps_params,
288 sizeof(ps_params));
289 if (ret < 0) {
290 wl12xx_error("cmd set_ps_mode failed");
291 return ret;
292 }
293
294 return 0;
295}
296
297int wl12xx_cmd_read_memory(struct wl12xx *wl, u32 addr, u32 len, void *answer)
298{
299 struct cmd_read_write_memory mem_cmd, *mem_answer;
300 struct wl12xx_command cmd;
301 int ret;
302
303 wl12xx_debug(DEBUG_CMD, "cmd read memory");
304
305 memset(&mem_cmd, 0, sizeof(mem_cmd));
306 mem_cmd.addr = addr;
307 mem_cmd.size = len;
308
309 ret = wl12xx_cmd_send(wl, CMD_READ_MEMORY, &mem_cmd, sizeof(mem_cmd));
310 if (ret < 0) {
311 wl12xx_error("read memory command failed: %d", ret);
312 return ret;
313 }
314
315 /* the read command got in, we can now read the answer */
316 wl12xx_spi_mem_read(wl, wl->cmd_box_addr, &cmd,
317 CMDMBOX_HEADER_LEN + sizeof(mem_cmd));
318
319 if (cmd.status != CMD_STATUS_SUCCESS)
320 wl12xx_error("error in read command result: %d", cmd.status);
321
322 mem_answer = (struct cmd_read_write_memory *) cmd.parameters;
323 memcpy(answer, mem_answer->value, len);
324
325 return 0;
326}
327
328int wl12xx_cmd_template_set(struct wl12xx *wl, u16 cmd_id,
329 void *buf, size_t buf_len)
330{
331 struct wl12xx_cmd_packet_template template;
332 int ret;
333
334 wl12xx_debug(DEBUG_CMD, "cmd template %d", cmd_id);
335
336 memset(&template, 0, sizeof(template));
337
338 WARN_ON(buf_len > WL12XX_MAX_TEMPLATE_SIZE);
339 buf_len = min_t(size_t, buf_len, WL12XX_MAX_TEMPLATE_SIZE);
340 template.size = cpu_to_le16(buf_len);
341
342 if (buf)
343 memcpy(template.template, buf, buf_len);
344
345 ret = wl12xx_cmd_send(wl, cmd_id, &template,
346 sizeof(template.size) + buf_len);
347 if (ret < 0) {
348 wl12xx_warning("cmd set_template failed: %d", ret);
349 return ret;
350 }
351
352 return 0;
353}
diff --git a/drivers/net/wireless/wl12xx/cmd.h b/drivers/net/wireless/wl12xx/cmd.h
new file mode 100644
index 000000000000..aa307dcd081f
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/cmd.h
@@ -0,0 +1,265 @@
1/*
2 * This file is part of wl12xx
3 *
4 * Copyright (c) 1998-2007 Texas Instruments Incorporated
5 * Copyright (C) 2008 Nokia Corporation
6 *
7 * Contact: Kalle Valo <kalle.valo@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 __WL12XX_CMD_H__
26#define __WL12XX_CMD_H__
27
28#include "wl12xx.h"
29
30int wl12xx_cmd_send(struct wl12xx *wl, u16 type, void *buf, size_t buf_len);
31int wl12xx_cmd_test(struct wl12xx *wl, void *buf, size_t buf_len, u8 answer);
32int wl12xx_cmd_interrogate(struct wl12xx *wl, u16 ie_id, u16 ie_len,
33 void *answer);
34int wl12xx_cmd_configure(struct wl12xx *wl, void *ie, int ie_len);
35int wl12xx_cmd_vbm(struct wl12xx *wl, u8 identity,
36 void *bitmap, u16 bitmap_len, u8 bitmap_control);
37int wl12xx_cmd_data_path(struct wl12xx *wl, u8 channel, u8 enable);
38int wl12xx_cmd_join(struct wl12xx *wl, u8 bss_type, u8 dtim_interval,
39 u16 beacon_interval, u8 wait);
40int wl12xx_cmd_ps_mode(struct wl12xx *wl, u8 ps_mode);
41int wl12xx_cmd_read_memory(struct wl12xx *wl, u32 addr, u32 len, void *answer);
42int wl12xx_cmd_template_set(struct wl12xx *wl, u16 cmd_id,
43 void *buf, size_t buf_len);
44
45/* unit ms */
46#define WL12XX_COMMAND_TIMEOUT 2000
47
48#define WL12XX_MAX_TEMPLATE_SIZE 300
49
50struct wl12xx_cmd_packet_template {
51 __le16 size;
52 u8 template[WL12XX_MAX_TEMPLATE_SIZE];
53} __attribute__ ((packed));
54
55enum wl12xx_commands {
56 CMD_RESET = 0,
57 CMD_INTERROGATE = 1, /*use this to read information elements*/
58 CMD_CONFIGURE = 2, /*use this to write information elements*/
59 CMD_ENABLE_RX = 3,
60 CMD_ENABLE_TX = 4,
61 CMD_DISABLE_RX = 5,
62 CMD_DISABLE_TX = 6,
63 CMD_SCAN = 8,
64 CMD_STOP_SCAN = 9,
65 CMD_VBM = 10,
66 CMD_START_JOIN = 11,
67 CMD_SET_KEYS = 12,
68 CMD_READ_MEMORY = 13,
69 CMD_WRITE_MEMORY = 14,
70 CMD_BEACON = 19,
71 CMD_PROBE_RESP = 20,
72 CMD_NULL_DATA = 21,
73 CMD_PROBE_REQ = 22,
74 CMD_TEST = 23,
75 CMD_RADIO_CALIBRATE = 25, /* OBSOLETE */
76 CMD_ENABLE_RX_PATH = 27, /* OBSOLETE */
77 CMD_NOISE_HIST = 28,
78 CMD_RX_RESET = 29,
79 CMD_PS_POLL = 30,
80 CMD_QOS_NULL_DATA = 31,
81 CMD_LNA_CONTROL = 32,
82 CMD_SET_BCN_MODE = 33,
83 CMD_MEASUREMENT = 34,
84 CMD_STOP_MEASUREMENT = 35,
85 CMD_DISCONNECT = 36,
86 CMD_SET_PS_MODE = 37,
87 CMD_CHANNEL_SWITCH = 38,
88 CMD_STOP_CHANNEL_SWICTH = 39,
89 CMD_AP_DISCOVERY = 40,
90 CMD_STOP_AP_DISCOVERY = 41,
91 CMD_SPS_SCAN = 42,
92 CMD_STOP_SPS_SCAN = 43,
93 CMD_HEALTH_CHECK = 45,
94 CMD_DEBUG = 46,
95 CMD_TRIGGER_SCAN_TO = 47,
96
97 NUM_COMMANDS,
98 MAX_COMMAND_ID = 0xFFFF,
99};
100
101#define MAX_CMD_PARAMS 572
102
103struct wl12xx_command {
104 u16 id;
105 u16 status;
106 u8 parameters[MAX_CMD_PARAMS];
107};
108
109enum {
110 CMD_MAILBOX_IDLE = 0,
111 CMD_STATUS_SUCCESS = 1,
112 CMD_STATUS_UNKNOWN_CMD = 2,
113 CMD_STATUS_UNKNOWN_IE = 3,
114 CMD_STATUS_REJECT_MEAS_SG_ACTIVE = 11,
115 CMD_STATUS_RX_BUSY = 13,
116 CMD_STATUS_INVALID_PARAM = 14,
117 CMD_STATUS_TEMPLATE_TOO_LARGE = 15,
118 CMD_STATUS_OUT_OF_MEMORY = 16,
119 CMD_STATUS_STA_TABLE_FULL = 17,
120 CMD_STATUS_RADIO_ERROR = 18,
121 CMD_STATUS_WRONG_NESTING = 19,
122 CMD_STATUS_TIMEOUT = 21, /* Driver internal use.*/
123 CMD_STATUS_FW_RESET = 22, /* Driver internal use.*/
124 MAX_COMMAND_STATUS = 0xff
125};
126
127
128/*
129 * CMD_READ_MEMORY
130 *
131 * The host issues this command to read the WiLink device memory/registers.
132 *
133 * Note: The Base Band address has special handling (16 bits registers and
134 * addresses). For more information, see the hardware specification.
135 */
136/*
137 * CMD_WRITE_MEMORY
138 *
139 * The host issues this command to write the WiLink device memory/registers.
140 *
141 * The Base Band address has special handling (16 bits registers and
142 * addresses). For more information, see the hardware specification.
143 */
144#define MAX_READ_SIZE 256
145
146struct cmd_read_write_memory {
147 /* The address of the memory to read from or write to.*/
148 u32 addr;
149
150 /* The amount of data in bytes to read from or write to the WiLink
151 * device.*/
152 u32 size;
153
154 /* The actual value read from or written to the Wilink. The source
155 of this field is the Host in WRITE command or the Wilink in READ
156 command. */
157 u8 value[MAX_READ_SIZE];
158};
159
160#define CMDMBOX_HEADER_LEN 4
161#define CMDMBOX_INFO_ELEM_HEADER_LEN 4
162
163
164struct basic_scan_parameters {
165 u32 rx_config_options;
166 u32 rx_filter_options;
167
168 /*
169 * Scan options:
170 * bit 0: When this bit is set, passive scan.
171 * bit 1: Band, when this bit is set we scan
172 * in the 5Ghz band.
173 * bit 2: voice mode, 0 for normal scan.
174 * bit 3: scan priority, 1 for high priority.
175 */
176 u16 scan_options;
177
178 /* Number of channels to scan */
179 u8 num_channels;
180
181 /* Number opf probe requests to send, per channel */
182 u8 num_probe_requests;
183
184 /* Rate and modulation for probe requests */
185 u16 tx_rate;
186
187 u8 tid_trigger;
188 u8 ssid_len;
189 u32 ssid[8];
190
191} __attribute__ ((packed));
192
193struct basic_scan_channel_parameters {
194 u32 min_duration; /* in TU */
195 u32 max_duration; /* in TU */
196 u32 bssid_lsb;
197 u16 bssid_msb;
198
199 /*
200 * bits 0-3: Early termination count.
201 * bits 4-5: Early termination condition.
202 */
203 u8 early_termination;
204
205 u8 tx_power_att;
206 u8 channel;
207 u8 pad[3];
208} __attribute__ ((packed));
209
210/* SCAN parameters */
211#define SCAN_MAX_NUM_OF_CHANNELS 16
212
213struct cmd_scan {
214 struct basic_scan_parameters params;
215 struct basic_scan_channel_parameters channels[SCAN_MAX_NUM_OF_CHANNELS];
216} __attribute__ ((packed));
217
218enum {
219 BSS_TYPE_IBSS = 0,
220 BSS_TYPE_STA_BSS = 2,
221 BSS_TYPE_AP_BSS = 3,
222 MAX_BSS_TYPE = 0xFF
223};
224
225#define JOIN_CMD_CTRL_TX_FLUSH 0x80 /* Firmware flushes all Tx */
226#define JOIN_CMD_CTRL_EARLY_WAKEUP_ENABLE 0x01 /* Early wakeup time */
227
228
229struct cmd_join {
230 u32 bssid_lsb;
231 u16 bssid_msb;
232 u16 beacon_interval; /* in TBTTs */
233 u32 rx_config_options;
234 u32 rx_filter_options;
235
236 /*
237 * The target uses this field to determine the rate at
238 * which to transmit control frame responses (such as
239 * ACK or CTS frames).
240 */
241 u16 basic_rate_set;
242 u8 dtim_interval;
243 u8 tx_ctrl_frame_rate; /* OBSOLETE */
244 u8 tx_ctrl_frame_mod; /* OBSOLETE */
245 /*
246 * bits 0-2: This bitwise field specifies the type
247 * of BSS to start or join (BSS_TYPE_*).
248 * bit 4: Band - The radio band in which to join
249 * or start.
250 * 0 - 2.4GHz band
251 * 1 - 5GHz band
252 * bits 3, 5-7: Reserved
253 */
254 u8 bss_type;
255 u8 channel;
256 u8 ssid_len;
257 u8 ssid[IW_ESSID_MAX_SIZE];
258 u8 ctrl; /* JOIN_CMD_CTRL_* */
259 u8 tx_mgt_frame_rate; /* OBSOLETE */
260 u8 tx_mgt_frame_mod; /* OBSOLETE */
261 u8 reserved;
262} __attribute__ ((packed));
263
264
265#endif /* __WL12XX_CMD_H__ */
diff --git a/drivers/net/wireless/wl12xx/debugfs.c b/drivers/net/wireless/wl12xx/debugfs.c
new file mode 100644
index 000000000000..cdb368ce4dae
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/debugfs.c
@@ -0,0 +1,508 @@
1/*
2 * This file is part of wl12xx
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 *
6 * Contact: Kalle Valo <kalle.valo@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 "debugfs.h"
25
26#include <linux/skbuff.h>
27
28#include "wl12xx.h"
29#include "acx.h"
30
31/* ms */
32#define WL12XX_DEBUGFS_STATS_LIFETIME 1000
33
34/* debugfs macros idea from mac80211 */
35
36#define DEBUGFS_READONLY_FILE(name, buflen, fmt, value...) \
37static ssize_t name## _read(struct file *file, char __user *userbuf, \
38 size_t count, loff_t *ppos) \
39{ \
40 struct wl12xx *wl = file->private_data; \
41 char buf[buflen]; \
42 int res; \
43 \
44 res = scnprintf(buf, buflen, fmt "\n", ##value); \
45 return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
46} \
47 \
48static const struct file_operations name## _ops = { \
49 .read = name## _read, \
50 .open = wl12xx_open_file_generic, \
51};
52
53#define DEBUGFS_ADD(name, parent) \
54 wl->debugfs.name = debugfs_create_file(#name, 0400, parent, \
55 wl, &name## _ops); \
56 if (IS_ERR(wl->debugfs.name)) { \
57 ret = PTR_ERR(wl->debugfs.name); \
58 wl->debugfs.name = NULL; \
59 goto out; \
60 }
61
62#define DEBUGFS_DEL(name) \
63 do { \
64 debugfs_remove(wl->debugfs.name); \
65 wl->debugfs.name = NULL; \
66 } while (0)
67
68#define DEBUGFS_FWSTATS_FILE(sub, name, buflen, fmt) \
69static ssize_t sub## _ ##name## _read(struct file *file, \
70 char __user *userbuf, \
71 size_t count, loff_t *ppos) \
72{ \
73 struct wl12xx *wl = file->private_data; \
74 char buf[buflen]; \
75 int res; \
76 \
77 wl12xx_debugfs_update_stats(wl); \
78 \
79 res = scnprintf(buf, buflen, fmt "\n", \
80 wl->stats.fw_stats->sub.name); \
81 return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
82} \
83 \
84static const struct file_operations sub## _ ##name## _ops = { \
85 .read = sub## _ ##name## _read, \
86 .open = wl12xx_open_file_generic, \
87};
88
89#define DEBUGFS_FWSTATS_ADD(sub, name) \
90 DEBUGFS_ADD(sub## _ ##name, wl->debugfs.fw_statistics)
91
92#define DEBUGFS_FWSTATS_DEL(sub, name) \
93 DEBUGFS_DEL(sub## _ ##name)
94
95static void wl12xx_debugfs_update_stats(struct wl12xx *wl)
96{
97 mutex_lock(&wl->mutex);
98
99 if (wl->state == WL12XX_STATE_ON &&
100 time_after(jiffies, wl->stats.fw_stats_update +
101 msecs_to_jiffies(WL12XX_DEBUGFS_STATS_LIFETIME))) {
102 wl12xx_acx_statistics(wl, wl->stats.fw_stats);
103 wl->stats.fw_stats_update = jiffies;
104 }
105
106 mutex_unlock(&wl->mutex);
107}
108
109static int wl12xx_open_file_generic(struct inode *inode, struct file *file)
110{
111 file->private_data = inode->i_private;
112 return 0;
113}
114
115DEBUGFS_FWSTATS_FILE(tx, internal_desc_overflow, 20, "%u");
116
117DEBUGFS_FWSTATS_FILE(rx, out_of_mem, 20, "%u");
118DEBUGFS_FWSTATS_FILE(rx, hdr_overflow, 20, "%u");
119DEBUGFS_FWSTATS_FILE(rx, hw_stuck, 20, "%u");
120DEBUGFS_FWSTATS_FILE(rx, dropped, 20, "%u");
121DEBUGFS_FWSTATS_FILE(rx, fcs_err, 20, "%u");
122DEBUGFS_FWSTATS_FILE(rx, xfr_hint_trig, 20, "%u");
123DEBUGFS_FWSTATS_FILE(rx, path_reset, 20, "%u");
124DEBUGFS_FWSTATS_FILE(rx, reset_counter, 20, "%u");
125
126DEBUGFS_FWSTATS_FILE(dma, rx_requested, 20, "%u");
127DEBUGFS_FWSTATS_FILE(dma, rx_errors, 20, "%u");
128DEBUGFS_FWSTATS_FILE(dma, tx_requested, 20, "%u");
129DEBUGFS_FWSTATS_FILE(dma, tx_errors, 20, "%u");
130
131DEBUGFS_FWSTATS_FILE(isr, cmd_cmplt, 20, "%u");
132DEBUGFS_FWSTATS_FILE(isr, fiqs, 20, "%u");
133DEBUGFS_FWSTATS_FILE(isr, rx_headers, 20, "%u");
134DEBUGFS_FWSTATS_FILE(isr, rx_mem_overflow, 20, "%u");
135DEBUGFS_FWSTATS_FILE(isr, rx_rdys, 20, "%u");
136DEBUGFS_FWSTATS_FILE(isr, irqs, 20, "%u");
137DEBUGFS_FWSTATS_FILE(isr, tx_procs, 20, "%u");
138DEBUGFS_FWSTATS_FILE(isr, decrypt_done, 20, "%u");
139DEBUGFS_FWSTATS_FILE(isr, dma0_done, 20, "%u");
140DEBUGFS_FWSTATS_FILE(isr, dma1_done, 20, "%u");
141DEBUGFS_FWSTATS_FILE(isr, tx_exch_complete, 20, "%u");
142DEBUGFS_FWSTATS_FILE(isr, commands, 20, "%u");
143DEBUGFS_FWSTATS_FILE(isr, rx_procs, 20, "%u");
144DEBUGFS_FWSTATS_FILE(isr, hw_pm_mode_changes, 20, "%u");
145DEBUGFS_FWSTATS_FILE(isr, host_acknowledges, 20, "%u");
146DEBUGFS_FWSTATS_FILE(isr, pci_pm, 20, "%u");
147DEBUGFS_FWSTATS_FILE(isr, wakeups, 20, "%u");
148DEBUGFS_FWSTATS_FILE(isr, low_rssi, 20, "%u");
149
150DEBUGFS_FWSTATS_FILE(wep, addr_key_count, 20, "%u");
151DEBUGFS_FWSTATS_FILE(wep, default_key_count, 20, "%u");
152/* skipping wep.reserved */
153DEBUGFS_FWSTATS_FILE(wep, key_not_found, 20, "%u");
154DEBUGFS_FWSTATS_FILE(wep, decrypt_fail, 20, "%u");
155DEBUGFS_FWSTATS_FILE(wep, packets, 20, "%u");
156DEBUGFS_FWSTATS_FILE(wep, interrupt, 20, "%u");
157
158DEBUGFS_FWSTATS_FILE(pwr, ps_enter, 20, "%u");
159DEBUGFS_FWSTATS_FILE(pwr, elp_enter, 20, "%u");
160DEBUGFS_FWSTATS_FILE(pwr, missing_bcns, 20, "%u");
161DEBUGFS_FWSTATS_FILE(pwr, wake_on_host, 20, "%u");
162DEBUGFS_FWSTATS_FILE(pwr, wake_on_timer_exp, 20, "%u");
163DEBUGFS_FWSTATS_FILE(pwr, tx_with_ps, 20, "%u");
164DEBUGFS_FWSTATS_FILE(pwr, tx_without_ps, 20, "%u");
165DEBUGFS_FWSTATS_FILE(pwr, rcvd_beacons, 20, "%u");
166DEBUGFS_FWSTATS_FILE(pwr, power_save_off, 20, "%u");
167DEBUGFS_FWSTATS_FILE(pwr, enable_ps, 20, "%u");
168DEBUGFS_FWSTATS_FILE(pwr, disable_ps, 20, "%u");
169DEBUGFS_FWSTATS_FILE(pwr, fix_tsf_ps, 20, "%u");
170/* skipping cont_miss_bcns_spread for now */
171DEBUGFS_FWSTATS_FILE(pwr, rcvd_awake_beacons, 20, "%u");
172
173DEBUGFS_FWSTATS_FILE(mic, rx_pkts, 20, "%u");
174DEBUGFS_FWSTATS_FILE(mic, calc_failure, 20, "%u");
175
176DEBUGFS_FWSTATS_FILE(aes, encrypt_fail, 20, "%u");
177DEBUGFS_FWSTATS_FILE(aes, decrypt_fail, 20, "%u");
178DEBUGFS_FWSTATS_FILE(aes, encrypt_packets, 20, "%u");
179DEBUGFS_FWSTATS_FILE(aes, decrypt_packets, 20, "%u");
180DEBUGFS_FWSTATS_FILE(aes, encrypt_interrupt, 20, "%u");
181DEBUGFS_FWSTATS_FILE(aes, decrypt_interrupt, 20, "%u");
182
183DEBUGFS_FWSTATS_FILE(event, heart_beat, 20, "%u");
184DEBUGFS_FWSTATS_FILE(event, calibration, 20, "%u");
185DEBUGFS_FWSTATS_FILE(event, rx_mismatch, 20, "%u");
186DEBUGFS_FWSTATS_FILE(event, rx_mem_empty, 20, "%u");
187DEBUGFS_FWSTATS_FILE(event, rx_pool, 20, "%u");
188DEBUGFS_FWSTATS_FILE(event, oom_late, 20, "%u");
189DEBUGFS_FWSTATS_FILE(event, phy_transmit_error, 20, "%u");
190DEBUGFS_FWSTATS_FILE(event, tx_stuck, 20, "%u");
191
192DEBUGFS_FWSTATS_FILE(ps, pspoll_timeouts, 20, "%u");
193DEBUGFS_FWSTATS_FILE(ps, upsd_timeouts, 20, "%u");
194DEBUGFS_FWSTATS_FILE(ps, upsd_max_sptime, 20, "%u");
195DEBUGFS_FWSTATS_FILE(ps, upsd_max_apturn, 20, "%u");
196DEBUGFS_FWSTATS_FILE(ps, pspoll_max_apturn, 20, "%u");
197DEBUGFS_FWSTATS_FILE(ps, pspoll_utilization, 20, "%u");
198DEBUGFS_FWSTATS_FILE(ps, upsd_utilization, 20, "%u");
199
200DEBUGFS_FWSTATS_FILE(rxpipe, rx_prep_beacon_drop, 20, "%u");
201DEBUGFS_FWSTATS_FILE(rxpipe, descr_host_int_trig_rx_data, 20, "%u");
202DEBUGFS_FWSTATS_FILE(rxpipe, beacon_buffer_thres_host_int_trig_rx_data,
203 20, "%u");
204DEBUGFS_FWSTATS_FILE(rxpipe, missed_beacon_host_int_trig_rx_data, 20, "%u");
205DEBUGFS_FWSTATS_FILE(rxpipe, tx_xfr_host_int_trig_rx_data, 20, "%u");
206
207DEBUGFS_READONLY_FILE(retry_count, 20, "%u", wl->stats.retry_count);
208DEBUGFS_READONLY_FILE(excessive_retries, 20, "%u",
209 wl->stats.excessive_retries);
210
211static ssize_t tx_queue_len_read(struct file *file, char __user *userbuf,
212 size_t count, loff_t *ppos)
213{
214 struct wl12xx *wl = file->private_data;
215 u32 queue_len;
216 char buf[20];
217 int res;
218
219 queue_len = skb_queue_len(&wl->tx_queue);
220
221 res = scnprintf(buf, sizeof(buf), "%u\n", queue_len);
222 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
223}
224
225static const struct file_operations tx_queue_len_ops = {
226 .read = tx_queue_len_read,
227 .open = wl12xx_open_file_generic,
228};
229
230static void wl12xx_debugfs_delete_files(struct wl12xx *wl)
231{
232 DEBUGFS_FWSTATS_DEL(tx, internal_desc_overflow);
233
234 DEBUGFS_FWSTATS_DEL(rx, out_of_mem);
235 DEBUGFS_FWSTATS_DEL(rx, hdr_overflow);
236 DEBUGFS_FWSTATS_DEL(rx, hw_stuck);
237 DEBUGFS_FWSTATS_DEL(rx, dropped);
238 DEBUGFS_FWSTATS_DEL(rx, fcs_err);
239 DEBUGFS_FWSTATS_DEL(rx, xfr_hint_trig);
240 DEBUGFS_FWSTATS_DEL(rx, path_reset);
241 DEBUGFS_FWSTATS_DEL(rx, reset_counter);
242
243 DEBUGFS_FWSTATS_DEL(dma, rx_requested);
244 DEBUGFS_FWSTATS_DEL(dma, rx_errors);
245 DEBUGFS_FWSTATS_DEL(dma, tx_requested);
246 DEBUGFS_FWSTATS_DEL(dma, tx_errors);
247
248 DEBUGFS_FWSTATS_DEL(isr, cmd_cmplt);
249 DEBUGFS_FWSTATS_DEL(isr, fiqs);
250 DEBUGFS_FWSTATS_DEL(isr, rx_headers);
251 DEBUGFS_FWSTATS_DEL(isr, rx_mem_overflow);
252 DEBUGFS_FWSTATS_DEL(isr, rx_rdys);
253 DEBUGFS_FWSTATS_DEL(isr, irqs);
254 DEBUGFS_FWSTATS_DEL(isr, tx_procs);
255 DEBUGFS_FWSTATS_DEL(isr, decrypt_done);
256 DEBUGFS_FWSTATS_DEL(isr, dma0_done);
257 DEBUGFS_FWSTATS_DEL(isr, dma1_done);
258 DEBUGFS_FWSTATS_DEL(isr, tx_exch_complete);
259 DEBUGFS_FWSTATS_DEL(isr, commands);
260 DEBUGFS_FWSTATS_DEL(isr, rx_procs);
261 DEBUGFS_FWSTATS_DEL(isr, hw_pm_mode_changes);
262 DEBUGFS_FWSTATS_DEL(isr, host_acknowledges);
263 DEBUGFS_FWSTATS_DEL(isr, pci_pm);
264 DEBUGFS_FWSTATS_DEL(isr, wakeups);
265 DEBUGFS_FWSTATS_DEL(isr, low_rssi);
266
267 DEBUGFS_FWSTATS_DEL(wep, addr_key_count);
268 DEBUGFS_FWSTATS_DEL(wep, default_key_count);
269 /* skipping wep.reserved */
270 DEBUGFS_FWSTATS_DEL(wep, key_not_found);
271 DEBUGFS_FWSTATS_DEL(wep, decrypt_fail);
272 DEBUGFS_FWSTATS_DEL(wep, packets);
273 DEBUGFS_FWSTATS_DEL(wep, interrupt);
274
275 DEBUGFS_FWSTATS_DEL(pwr, ps_enter);
276 DEBUGFS_FWSTATS_DEL(pwr, elp_enter);
277 DEBUGFS_FWSTATS_DEL(pwr, missing_bcns);
278 DEBUGFS_FWSTATS_DEL(pwr, wake_on_host);
279 DEBUGFS_FWSTATS_DEL(pwr, wake_on_timer_exp);
280 DEBUGFS_FWSTATS_DEL(pwr, tx_with_ps);
281 DEBUGFS_FWSTATS_DEL(pwr, tx_without_ps);
282 DEBUGFS_FWSTATS_DEL(pwr, rcvd_beacons);
283 DEBUGFS_FWSTATS_DEL(pwr, power_save_off);
284 DEBUGFS_FWSTATS_DEL(pwr, enable_ps);
285 DEBUGFS_FWSTATS_DEL(pwr, disable_ps);
286 DEBUGFS_FWSTATS_DEL(pwr, fix_tsf_ps);
287 /* skipping cont_miss_bcns_spread for now */
288 DEBUGFS_FWSTATS_DEL(pwr, rcvd_awake_beacons);
289
290 DEBUGFS_FWSTATS_DEL(mic, rx_pkts);
291 DEBUGFS_FWSTATS_DEL(mic, calc_failure);
292
293 DEBUGFS_FWSTATS_DEL(aes, encrypt_fail);
294 DEBUGFS_FWSTATS_DEL(aes, decrypt_fail);
295 DEBUGFS_FWSTATS_DEL(aes, encrypt_packets);
296 DEBUGFS_FWSTATS_DEL(aes, decrypt_packets);
297 DEBUGFS_FWSTATS_DEL(aes, encrypt_interrupt);
298 DEBUGFS_FWSTATS_DEL(aes, decrypt_interrupt);
299
300 DEBUGFS_FWSTATS_DEL(event, heart_beat);
301 DEBUGFS_FWSTATS_DEL(event, calibration);
302 DEBUGFS_FWSTATS_DEL(event, rx_mismatch);
303 DEBUGFS_FWSTATS_DEL(event, rx_mem_empty);
304 DEBUGFS_FWSTATS_DEL(event, rx_pool);
305 DEBUGFS_FWSTATS_DEL(event, oom_late);
306 DEBUGFS_FWSTATS_DEL(event, phy_transmit_error);
307 DEBUGFS_FWSTATS_DEL(event, tx_stuck);
308
309 DEBUGFS_FWSTATS_DEL(ps, pspoll_timeouts);
310 DEBUGFS_FWSTATS_DEL(ps, upsd_timeouts);
311 DEBUGFS_FWSTATS_DEL(ps, upsd_max_sptime);
312 DEBUGFS_FWSTATS_DEL(ps, upsd_max_apturn);
313 DEBUGFS_FWSTATS_DEL(ps, pspoll_max_apturn);
314 DEBUGFS_FWSTATS_DEL(ps, pspoll_utilization);
315 DEBUGFS_FWSTATS_DEL(ps, upsd_utilization);
316
317 DEBUGFS_FWSTATS_DEL(rxpipe, rx_prep_beacon_drop);
318 DEBUGFS_FWSTATS_DEL(rxpipe, descr_host_int_trig_rx_data);
319 DEBUGFS_FWSTATS_DEL(rxpipe, beacon_buffer_thres_host_int_trig_rx_data);
320 DEBUGFS_FWSTATS_DEL(rxpipe, missed_beacon_host_int_trig_rx_data);
321 DEBUGFS_FWSTATS_DEL(rxpipe, tx_xfr_host_int_trig_rx_data);
322
323 DEBUGFS_DEL(tx_queue_len);
324 DEBUGFS_DEL(retry_count);
325 DEBUGFS_DEL(excessive_retries);
326}
327
328static int wl12xx_debugfs_add_files(struct wl12xx *wl)
329{
330 int ret = 0;
331
332 DEBUGFS_FWSTATS_ADD(tx, internal_desc_overflow);
333
334 DEBUGFS_FWSTATS_ADD(rx, out_of_mem);
335 DEBUGFS_FWSTATS_ADD(rx, hdr_overflow);
336 DEBUGFS_FWSTATS_ADD(rx, hw_stuck);
337 DEBUGFS_FWSTATS_ADD(rx, dropped);
338 DEBUGFS_FWSTATS_ADD(rx, fcs_err);
339 DEBUGFS_FWSTATS_ADD(rx, xfr_hint_trig);
340 DEBUGFS_FWSTATS_ADD(rx, path_reset);
341 DEBUGFS_FWSTATS_ADD(rx, reset_counter);
342
343 DEBUGFS_FWSTATS_ADD(dma, rx_requested);
344 DEBUGFS_FWSTATS_ADD(dma, rx_errors);
345 DEBUGFS_FWSTATS_ADD(dma, tx_requested);
346 DEBUGFS_FWSTATS_ADD(dma, tx_errors);
347
348 DEBUGFS_FWSTATS_ADD(isr, cmd_cmplt);
349 DEBUGFS_FWSTATS_ADD(isr, fiqs);
350 DEBUGFS_FWSTATS_ADD(isr, rx_headers);
351 DEBUGFS_FWSTATS_ADD(isr, rx_mem_overflow);
352 DEBUGFS_FWSTATS_ADD(isr, rx_rdys);
353 DEBUGFS_FWSTATS_ADD(isr, irqs);
354 DEBUGFS_FWSTATS_ADD(isr, tx_procs);
355 DEBUGFS_FWSTATS_ADD(isr, decrypt_done);
356 DEBUGFS_FWSTATS_ADD(isr, dma0_done);
357 DEBUGFS_FWSTATS_ADD(isr, dma1_done);
358 DEBUGFS_FWSTATS_ADD(isr, tx_exch_complete);
359 DEBUGFS_FWSTATS_ADD(isr, commands);
360 DEBUGFS_FWSTATS_ADD(isr, rx_procs);
361 DEBUGFS_FWSTATS_ADD(isr, hw_pm_mode_changes);
362 DEBUGFS_FWSTATS_ADD(isr, host_acknowledges);
363 DEBUGFS_FWSTATS_ADD(isr, pci_pm);
364 DEBUGFS_FWSTATS_ADD(isr, wakeups);
365 DEBUGFS_FWSTATS_ADD(isr, low_rssi);
366
367 DEBUGFS_FWSTATS_ADD(wep, addr_key_count);
368 DEBUGFS_FWSTATS_ADD(wep, default_key_count);
369 /* skipping wep.reserved */
370 DEBUGFS_FWSTATS_ADD(wep, key_not_found);
371 DEBUGFS_FWSTATS_ADD(wep, decrypt_fail);
372 DEBUGFS_FWSTATS_ADD(wep, packets);
373 DEBUGFS_FWSTATS_ADD(wep, interrupt);
374
375 DEBUGFS_FWSTATS_ADD(pwr, ps_enter);
376 DEBUGFS_FWSTATS_ADD(pwr, elp_enter);
377 DEBUGFS_FWSTATS_ADD(pwr, missing_bcns);
378 DEBUGFS_FWSTATS_ADD(pwr, wake_on_host);
379 DEBUGFS_FWSTATS_ADD(pwr, wake_on_timer_exp);
380 DEBUGFS_FWSTATS_ADD(pwr, tx_with_ps);
381 DEBUGFS_FWSTATS_ADD(pwr, tx_without_ps);
382 DEBUGFS_FWSTATS_ADD(pwr, rcvd_beacons);
383 DEBUGFS_FWSTATS_ADD(pwr, power_save_off);
384 DEBUGFS_FWSTATS_ADD(pwr, enable_ps);
385 DEBUGFS_FWSTATS_ADD(pwr, disable_ps);
386 DEBUGFS_FWSTATS_ADD(pwr, fix_tsf_ps);
387 /* skipping cont_miss_bcns_spread for now */
388 DEBUGFS_FWSTATS_ADD(pwr, rcvd_awake_beacons);
389
390 DEBUGFS_FWSTATS_ADD(mic, rx_pkts);
391 DEBUGFS_FWSTATS_ADD(mic, calc_failure);
392
393 DEBUGFS_FWSTATS_ADD(aes, encrypt_fail);
394 DEBUGFS_FWSTATS_ADD(aes, decrypt_fail);
395 DEBUGFS_FWSTATS_ADD(aes, encrypt_packets);
396 DEBUGFS_FWSTATS_ADD(aes, decrypt_packets);
397 DEBUGFS_FWSTATS_ADD(aes, encrypt_interrupt);
398 DEBUGFS_FWSTATS_ADD(aes, decrypt_interrupt);
399
400 DEBUGFS_FWSTATS_ADD(event, heart_beat);
401 DEBUGFS_FWSTATS_ADD(event, calibration);
402 DEBUGFS_FWSTATS_ADD(event, rx_mismatch);
403 DEBUGFS_FWSTATS_ADD(event, rx_mem_empty);
404 DEBUGFS_FWSTATS_ADD(event, rx_pool);
405 DEBUGFS_FWSTATS_ADD(event, oom_late);
406 DEBUGFS_FWSTATS_ADD(event, phy_transmit_error);
407 DEBUGFS_FWSTATS_ADD(event, tx_stuck);
408
409 DEBUGFS_FWSTATS_ADD(ps, pspoll_timeouts);
410 DEBUGFS_FWSTATS_ADD(ps, upsd_timeouts);
411 DEBUGFS_FWSTATS_ADD(ps, upsd_max_sptime);
412 DEBUGFS_FWSTATS_ADD(ps, upsd_max_apturn);
413 DEBUGFS_FWSTATS_ADD(ps, pspoll_max_apturn);
414 DEBUGFS_FWSTATS_ADD(ps, pspoll_utilization);
415 DEBUGFS_FWSTATS_ADD(ps, upsd_utilization);
416
417 DEBUGFS_FWSTATS_ADD(rxpipe, rx_prep_beacon_drop);
418 DEBUGFS_FWSTATS_ADD(rxpipe, descr_host_int_trig_rx_data);
419 DEBUGFS_FWSTATS_ADD(rxpipe, beacon_buffer_thres_host_int_trig_rx_data);
420 DEBUGFS_FWSTATS_ADD(rxpipe, missed_beacon_host_int_trig_rx_data);
421 DEBUGFS_FWSTATS_ADD(rxpipe, tx_xfr_host_int_trig_rx_data);
422
423 DEBUGFS_ADD(tx_queue_len, wl->debugfs.rootdir);
424 DEBUGFS_ADD(retry_count, wl->debugfs.rootdir);
425 DEBUGFS_ADD(excessive_retries, wl->debugfs.rootdir);
426
427out:
428 if (ret < 0)
429 wl12xx_debugfs_delete_files(wl);
430
431 return ret;
432}
433
434void wl12xx_debugfs_reset(struct wl12xx *wl)
435{
436 memset(wl->stats.fw_stats, 0, sizeof(*wl->stats.fw_stats));
437 wl->stats.retry_count = 0;
438 wl->stats.excessive_retries = 0;
439}
440
441int wl12xx_debugfs_init(struct wl12xx *wl)
442{
443 int ret;
444
445 wl->debugfs.rootdir = debugfs_create_dir(KBUILD_MODNAME, NULL);
446
447 if (IS_ERR(wl->debugfs.rootdir)) {
448 ret = PTR_ERR(wl->debugfs.rootdir);
449 wl->debugfs.rootdir = NULL;
450 goto err;
451 }
452
453 wl->debugfs.fw_statistics = debugfs_create_dir("fw-statistics",
454 wl->debugfs.rootdir);
455
456 if (IS_ERR(wl->debugfs.fw_statistics)) {
457 ret = PTR_ERR(wl->debugfs.fw_statistics);
458 wl->debugfs.fw_statistics = NULL;
459 goto err_root;
460 }
461
462 wl->stats.fw_stats = kzalloc(sizeof(*wl->stats.fw_stats),
463 GFP_KERNEL);
464
465 if (!wl->stats.fw_stats) {
466 ret = -ENOMEM;
467 goto err_fw;
468 }
469
470 wl->stats.fw_stats_update = jiffies;
471
472 ret = wl12xx_debugfs_add_files(wl);
473
474 if (ret < 0)
475 goto err_file;
476
477 return 0;
478
479err_file:
480 kfree(wl->stats.fw_stats);
481 wl->stats.fw_stats = NULL;
482
483err_fw:
484 debugfs_remove(wl->debugfs.fw_statistics);
485 wl->debugfs.fw_statistics = NULL;
486
487err_root:
488 debugfs_remove(wl->debugfs.rootdir);
489 wl->debugfs.rootdir = NULL;
490
491err:
492 return ret;
493}
494
495void wl12xx_debugfs_exit(struct wl12xx *wl)
496{
497 wl12xx_debugfs_delete_files(wl);
498
499 kfree(wl->stats.fw_stats);
500 wl->stats.fw_stats = NULL;
501
502 debugfs_remove(wl->debugfs.fw_statistics);
503 wl->debugfs.fw_statistics = NULL;
504
505 debugfs_remove(wl->debugfs.rootdir);
506 wl->debugfs.rootdir = NULL;
507
508}
diff --git a/drivers/net/wireless/wl12xx/debugfs.h b/drivers/net/wireless/wl12xx/debugfs.h
new file mode 100644
index 000000000000..562cdcbcc874
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/debugfs.h
@@ -0,0 +1,33 @@
1/*
2 * This file is part of wl12xx
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 *
6 * Contact: Kalle Valo <kalle.valo@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 WL12XX_DEBUGFS_H
25#define WL12XX_DEBUGFS_H
26
27#include "wl12xx.h"
28
29int wl12xx_debugfs_init(struct wl12xx *wl);
30void wl12xx_debugfs_exit(struct wl12xx *wl);
31void wl12xx_debugfs_reset(struct wl12xx *wl);
32
33#endif /* WL12XX_DEBUGFS_H */
diff --git a/drivers/net/wireless/wl12xx/event.c b/drivers/net/wireless/wl12xx/event.c
new file mode 100644
index 000000000000..99529ca89a7e
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/event.c
@@ -0,0 +1,127 @@
1/*
2 * This file is part of wl12xx
3 *
4 * Copyright (c) 1998-2007 Texas Instruments Incorporated
5 * Copyright (C) 2008 Nokia Corporation
6 *
7 * Contact: Kalle Valo <kalle.valo@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#include "wl12xx.h"
26#include "reg.h"
27#include "spi.h"
28#include "event.h"
29#include "ps.h"
30
31static int wl12xx_event_scan_complete(struct wl12xx *wl,
32 struct event_mailbox *mbox)
33{
34 wl12xx_debug(DEBUG_EVENT, "status: 0x%x, channels: %d",
35 mbox->scheduled_scan_status,
36 mbox->scheduled_scan_channels);
37
38 if (wl->scanning) {
39 mutex_unlock(&wl->mutex);
40 ieee80211_scan_completed(wl->hw, false);
41 mutex_lock(&wl->mutex);
42 wl->scanning = false;
43 }
44
45 return 0;
46}
47
48static void wl12xx_event_mbox_dump(struct event_mailbox *mbox)
49{
50 wl12xx_debug(DEBUG_EVENT, "MBOX DUMP:");
51 wl12xx_debug(DEBUG_EVENT, "\tvector: 0x%x", mbox->events_vector);
52 wl12xx_debug(DEBUG_EVENT, "\tmask: 0x%x", mbox->events_mask);
53}
54
55static int wl12xx_event_process(struct wl12xx *wl, struct event_mailbox *mbox)
56{
57 int ret;
58 u32 vector;
59
60 wl12xx_event_mbox_dump(mbox);
61
62 vector = mbox->events_vector & ~(mbox->events_mask);
63 wl12xx_debug(DEBUG_EVENT, "vector: 0x%x", vector);
64
65 if (vector & SCAN_COMPLETE_EVENT_ID) {
66 ret = wl12xx_event_scan_complete(wl, mbox);
67 if (ret < 0)
68 return ret;
69 }
70
71 if (vector & BSS_LOSE_EVENT_ID) {
72 wl12xx_debug(DEBUG_EVENT, "BSS_LOSE_EVENT");
73
74 if (wl->psm_requested && wl->psm) {
75 ret = wl12xx_ps_set_mode(wl, STATION_ACTIVE_MODE);
76 if (ret < 0)
77 return ret;
78 }
79 }
80
81 return 0;
82}
83
84int wl12xx_event_unmask(struct wl12xx *wl)
85{
86 int ret;
87
88 ret = wl12xx_acx_event_mbox_mask(wl, ~(wl->event_mask));
89 if (ret < 0)
90 return ret;
91
92 return 0;
93}
94
95void wl12xx_event_mbox_config(struct wl12xx *wl)
96{
97 wl->mbox_ptr[0] = wl12xx_reg_read32(wl, REG_EVENT_MAILBOX_PTR);
98 wl->mbox_ptr[1] = wl->mbox_ptr[0] + sizeof(struct event_mailbox);
99
100 wl12xx_debug(DEBUG_EVENT, "MBOX ptrs: 0x%x 0x%x",
101 wl->mbox_ptr[0], wl->mbox_ptr[1]);
102}
103
104int wl12xx_event_handle(struct wl12xx *wl, u8 mbox_num)
105{
106 struct event_mailbox mbox;
107 int ret;
108
109 wl12xx_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num);
110
111 if (mbox_num > 1)
112 return -EINVAL;
113
114 /* first we read the mbox descriptor */
115 wl12xx_spi_mem_read(wl, wl->mbox_ptr[mbox_num], &mbox,
116 sizeof(struct event_mailbox));
117
118 /* process the descriptor */
119 ret = wl12xx_event_process(wl, &mbox);
120 if (ret < 0)
121 return ret;
122
123 /* then we let the firmware know it can go on...*/
124 wl12xx_reg_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_EVENT_ACK);
125
126 return 0;
127}
diff --git a/drivers/net/wireless/wl12xx/event.h b/drivers/net/wireless/wl12xx/event.h
new file mode 100644
index 000000000000..1f4c2f7438a7
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/event.h
@@ -0,0 +1,121 @@
1/*
2 * This file is part of wl12xx
3 *
4 * Copyright (c) 1998-2007 Texas Instruments Incorporated
5 * Copyright (C) 2008 Nokia Corporation
6 *
7 * Contact: Kalle Valo <kalle.valo@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 __WL12XX_EVENT_H__
26#define __WL12XX_EVENT_H__
27
28/*
29 * Mbox events
30 *
31 * The event mechanism is based on a pair of event buffers (buffers A and
32 * B) at fixed locations in the target's memory. The host processes one
33 * buffer while the other buffer continues to collect events. If the host
34 * is not processing events, an interrupt is issued to signal that a buffer
35 * is ready. Once the host is done with processing events from one buffer,
36 * it signals the target (with an ACK interrupt) that the event buffer is
37 * free.
38 */
39
40enum {
41 RESERVED1_EVENT_ID = BIT(0),
42 RESERVED2_EVENT_ID = BIT(1),
43 MEASUREMENT_START_EVENT_ID = BIT(2),
44 SCAN_COMPLETE_EVENT_ID = BIT(3),
45 CALIBRATION_COMPLETE_EVENT_ID = BIT(4),
46 ROAMING_TRIGGER_LOW_RSSI_EVENT_ID = BIT(5),
47 PS_REPORT_EVENT_ID = BIT(6),
48 SYNCHRONIZATION_TIMEOUT_EVENT_ID = BIT(7),
49 HEALTH_REPORT_EVENT_ID = BIT(8),
50 ACI_DETECTION_EVENT_ID = BIT(9),
51 DEBUG_REPORT_EVENT_ID = BIT(10),
52 MAC_STATUS_EVENT_ID = BIT(11),
53 DISCONNECT_EVENT_COMPLETE_ID = BIT(12),
54 JOIN_EVENT_COMPLETE_ID = BIT(13),
55 CHANNEL_SWITCH_COMPLETE_EVENT_ID = BIT(14),
56 BSS_LOSE_EVENT_ID = BIT(15),
57 ROAMING_TRIGGER_MAX_TX_RETRY_EVENT_ID = BIT(16),
58 MEASUREMENT_COMPLETE_EVENT_ID = BIT(17),
59 AP_DISCOVERY_COMPLETE_EVENT_ID = BIT(18),
60 SCHEDULED_SCAN_COMPLETE_EVENT_ID = BIT(19),
61 PSPOLL_DELIVERY_FAILURE_EVENT_ID = BIT(20),
62 RESET_BSS_EVENT_ID = BIT(21),
63 REGAINED_BSS_EVENT_ID = BIT(22),
64 ROAMING_TRIGGER_REGAINED_RSSI_EVENT_ID = BIT(23),
65 ROAMING_TRIGGER_LOW_SNR_EVENT_ID = BIT(24),
66 ROAMING_TRIGGER_REGAINED_SNR_EVENT_ID = BIT(25),
67
68 DBG_EVENT_ID = BIT(26),
69 BT_PTA_SENSE_EVENT_ID = BIT(27),
70 BT_PTA_PREDICTION_EVENT_ID = BIT(28),
71 BT_PTA_AVALANCHE_EVENT_ID = BIT(29),
72
73 PLT_RX_CALIBRATION_COMPLETE_EVENT_ID = BIT(30),
74
75 EVENT_MBOX_ALL_EVENT_ID = 0x7fffffff,
76};
77
78struct event_debug_report {
79 u8 debug_event_id;
80 u8 num_params;
81 u16 pad;
82 u32 report_1;
83 u32 report_2;
84 u32 report_3;
85} __attribute__ ((packed));
86
87struct event_mailbox {
88 u32 events_vector;
89 u32 events_mask;
90 u32 reserved_1;
91 u32 reserved_2;
92
93 char average_rssi_level;
94 u8 ps_status;
95 u8 channel_switch_status;
96 u8 scheduled_scan_status;
97
98 /* Channels scanned by the scheduled scan */
99 u16 scheduled_scan_channels;
100
101 /* If bit 0 is set -> target's fatal error */
102 u16 health_report;
103 u16 bad_fft_counter;
104 u8 bt_pta_sense_info;
105 u8 bt_pta_protective_info;
106 u32 reserved;
107 u32 debug_report[2];
108
109 /* Number of FCS errors since last event */
110 u32 fcs_err_counter;
111
112 struct event_debug_report report;
113 u8 average_snr_level;
114 u8 padding[19];
115} __attribute__ ((packed));
116
117int wl12xx_event_unmask(struct wl12xx *wl);
118void wl12xx_event_mbox_config(struct wl12xx *wl);
119int wl12xx_event_handle(struct wl12xx *wl, u8 mbox);
120
121#endif
diff --git a/drivers/net/wireless/wl12xx/init.c b/drivers/net/wireless/wl12xx/init.c
new file mode 100644
index 000000000000..2a573a6010bd
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/init.c
@@ -0,0 +1,200 @@
1/*
2 * This file is part of wl12xx
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 *
6 * Contact: Kalle Valo <kalle.valo@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
24#include <linux/kernel.h>
25#include <linux/module.h>
26
27#include "init.h"
28#include "wl12xx_80211.h"
29#include "acx.h"
30#include "cmd.h"
31
32int wl12xx_hw_init_hwenc_config(struct wl12xx *wl)
33{
34 int ret;
35
36 ret = wl12xx_acx_feature_cfg(wl);
37 if (ret < 0) {
38 wl12xx_warning("couldn't set feature config");
39 return ret;
40 }
41
42 ret = wl12xx_acx_default_key(wl, wl->default_key);
43 if (ret < 0) {
44 wl12xx_warning("couldn't set default key");
45 return ret;
46 }
47
48 return 0;
49}
50
51int wl12xx_hw_init_templates_config(struct wl12xx *wl)
52{
53 int ret;
54 u8 partial_vbm[PARTIAL_VBM_MAX];
55
56 /* send empty templates for fw memory reservation */
57 ret = wl12xx_cmd_template_set(wl, CMD_PROBE_REQ, NULL,
58 sizeof(struct wl12xx_probe_req_template));
59 if (ret < 0)
60 return ret;
61
62 ret = wl12xx_cmd_template_set(wl, CMD_NULL_DATA, NULL,
63 sizeof(struct wl12xx_null_data_template));
64 if (ret < 0)
65 return ret;
66
67 ret = wl12xx_cmd_template_set(wl, CMD_PS_POLL, NULL,
68 sizeof(struct wl12xx_ps_poll_template));
69 if (ret < 0)
70 return ret;
71
72 ret = wl12xx_cmd_template_set(wl, CMD_QOS_NULL_DATA, NULL,
73 sizeof
74 (struct wl12xx_qos_null_data_template));
75 if (ret < 0)
76 return ret;
77
78 ret = wl12xx_cmd_template_set(wl, CMD_PROBE_RESP, NULL,
79 sizeof
80 (struct wl12xx_probe_resp_template));
81 if (ret < 0)
82 return ret;
83
84 ret = wl12xx_cmd_template_set(wl, CMD_BEACON, NULL,
85 sizeof
86 (struct wl12xx_beacon_template));
87 if (ret < 0)
88 return ret;
89
90 /* tim templates, first reserve space then allocate an empty one */
91 memset(partial_vbm, 0, PARTIAL_VBM_MAX);
92 ret = wl12xx_cmd_vbm(wl, TIM_ELE_ID, partial_vbm, PARTIAL_VBM_MAX, 0);
93 if (ret < 0)
94 return ret;
95
96 ret = wl12xx_cmd_vbm(wl, TIM_ELE_ID, partial_vbm, 1, 0);
97 if (ret < 0)
98 return ret;
99
100 return 0;
101}
102
103int wl12xx_hw_init_rx_config(struct wl12xx *wl, u32 config, u32 filter)
104{
105 int ret;
106
107 ret = wl12xx_acx_rx_msdu_life_time(wl, RX_MSDU_LIFETIME_DEF);
108 if (ret < 0)
109 return ret;
110
111 ret = wl12xx_acx_rx_config(wl, config, filter);
112 if (ret < 0)
113 return ret;
114
115 return 0;
116}
117
118int wl12xx_hw_init_phy_config(struct wl12xx *wl)
119{
120 int ret;
121
122 ret = wl12xx_acx_pd_threshold(wl);
123 if (ret < 0)
124 return ret;
125
126 ret = wl12xx_acx_slot(wl, DEFAULT_SLOT_TIME);
127 if (ret < 0)
128 return ret;
129
130 ret = wl12xx_acx_group_address_tbl(wl);
131 if (ret < 0)
132 return ret;
133
134 ret = wl12xx_acx_service_period_timeout(wl);
135 if (ret < 0)
136 return ret;
137
138 ret = wl12xx_acx_rts_threshold(wl, RTS_THRESHOLD_DEF);
139 if (ret < 0)
140 return ret;
141
142 return 0;
143}
144
145int wl12xx_hw_init_beacon_filter(struct wl12xx *wl)
146{
147 int ret;
148
149 ret = wl12xx_acx_beacon_filter_opt(wl);
150 if (ret < 0)
151 return ret;
152
153 ret = wl12xx_acx_beacon_filter_table(wl);
154 if (ret < 0)
155 return ret;
156
157 return 0;
158}
159
160int wl12xx_hw_init_pta(struct wl12xx *wl)
161{
162 int ret;
163
164 ret = wl12xx_acx_sg_enable(wl);
165 if (ret < 0)
166 return ret;
167
168 ret = wl12xx_acx_sg_cfg(wl);
169 if (ret < 0)
170 return ret;
171
172 return 0;
173}
174
175int wl12xx_hw_init_energy_detection(struct wl12xx *wl)
176{
177 int ret;
178
179 ret = wl12xx_acx_cca_threshold(wl);
180 if (ret < 0)
181 return ret;
182
183 return 0;
184}
185
186int wl12xx_hw_init_beacon_broadcast(struct wl12xx *wl)
187{
188 int ret;
189
190 ret = wl12xx_acx_bcn_dtim_options(wl);
191 if (ret < 0)
192 return ret;
193
194 return 0;
195}
196
197int wl12xx_hw_init_power_auth(struct wl12xx *wl)
198{
199 return wl12xx_acx_sleep_auth(wl, WL12XX_PSM_CAM);
200}
diff --git a/drivers/net/wireless/wl12xx/init.h b/drivers/net/wireless/wl12xx/init.h
new file mode 100644
index 000000000000..c8b6cd0b7c3e
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/init.h
@@ -0,0 +1,40 @@
1/*
2 * This file is part of wl12xx
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 *
6 * Contact: Kalle Valo <kalle.valo@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 __WL12XX_INIT_H__
25#define __WL12XX_INIT_H__
26
27#include "wl12xx.h"
28
29int wl12xx_hw_init_hwenc_config(struct wl12xx *wl);
30int wl12xx_hw_init_templates_config(struct wl12xx *wl);
31int wl12xx_hw_init_mem_config(struct wl12xx *wl);
32int wl12xx_hw_init_rx_config(struct wl12xx *wl, u32 config, u32 filter);
33int wl12xx_hw_init_phy_config(struct wl12xx *wl);
34int wl12xx_hw_init_beacon_filter(struct wl12xx *wl);
35int wl12xx_hw_init_pta(struct wl12xx *wl);
36int wl12xx_hw_init_energy_detection(struct wl12xx *wl);
37int wl12xx_hw_init_beacon_broadcast(struct wl12xx *wl);
38int wl12xx_hw_init_power_auth(struct wl12xx *wl);
39
40#endif
diff --git a/drivers/net/wireless/wl12xx/main.c b/drivers/net/wireless/wl12xx/main.c
new file mode 100644
index 000000000000..603d6114882e
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/main.c
@@ -0,0 +1,1358 @@
1/*
2 * This file is part of wl12xx
3 *
4 * Copyright (C) 2008-2009 Nokia Corporation
5 *
6 * Contact: Kalle Valo <kalle.valo@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/interrupt.h>
26#include <linux/firmware.h>
27#include <linux/delay.h>
28#include <linux/irq.h>
29#include <linux/spi/spi.h>
30#include <linux/crc32.h>
31#include <linux/etherdevice.h>
32#include <linux/spi/wl12xx.h>
33
34#include "wl12xx.h"
35#include "wl12xx_80211.h"
36#include "reg.h"
37#include "wl1251.h"
38#include "spi.h"
39#include "event.h"
40#include "tx.h"
41#include "rx.h"
42#include "ps.h"
43#include "init.h"
44#include "debugfs.h"
45
46static void wl12xx_disable_interrupts(struct wl12xx *wl)
47{
48 disable_irq(wl->irq);
49}
50
51static void wl12xx_power_off(struct wl12xx *wl)
52{
53 wl->set_power(false);
54}
55
56static void wl12xx_power_on(struct wl12xx *wl)
57{
58 wl->set_power(true);
59}
60
61static irqreturn_t wl12xx_irq(int irq, void *cookie)
62{
63 struct wl12xx *wl;
64
65 wl12xx_debug(DEBUG_IRQ, "IRQ");
66
67 wl = cookie;
68
69 schedule_work(&wl->irq_work);
70
71 return IRQ_HANDLED;
72}
73
74static int wl12xx_fetch_firmware(struct wl12xx *wl)
75{
76 const struct firmware *fw;
77 int ret;
78
79 ret = request_firmware(&fw, wl->chip.fw_filename, &wl->spi->dev);
80
81 if (ret < 0) {
82 wl12xx_error("could not get firmware: %d", ret);
83 return ret;
84 }
85
86 if (fw->size % 4) {
87 wl12xx_error("firmware size is not multiple of 32 bits: %zu",
88 fw->size);
89 ret = -EILSEQ;
90 goto out;
91 }
92
93 wl->fw_len = fw->size;
94 wl->fw = kmalloc(wl->fw_len, GFP_KERNEL);
95
96 if (!wl->fw) {
97 wl12xx_error("could not allocate memory for the firmware");
98 ret = -ENOMEM;
99 goto out;
100 }
101
102 memcpy(wl->fw, fw->data, wl->fw_len);
103
104 ret = 0;
105
106out:
107 release_firmware(fw);
108
109 return ret;
110}
111
112static int wl12xx_fetch_nvs(struct wl12xx *wl)
113{
114 const struct firmware *fw;
115 int ret;
116
117 ret = request_firmware(&fw, wl->chip.nvs_filename, &wl->spi->dev);
118
119 if (ret < 0) {
120 wl12xx_error("could not get nvs file: %d", ret);
121 return ret;
122 }
123
124 if (fw->size % 4) {
125 wl12xx_error("nvs size is not multiple of 32 bits: %zu",
126 fw->size);
127 ret = -EILSEQ;
128 goto out;
129 }
130
131 wl->nvs_len = fw->size;
132 wl->nvs = kmalloc(wl->nvs_len, GFP_KERNEL);
133
134 if (!wl->nvs) {
135 wl12xx_error("could not allocate memory for the nvs file");
136 ret = -ENOMEM;
137 goto out;
138 }
139
140 memcpy(wl->nvs, fw->data, wl->nvs_len);
141
142 ret = 0;
143
144out:
145 release_firmware(fw);
146
147 return ret;
148}
149
150static void wl12xx_fw_wakeup(struct wl12xx *wl)
151{
152 u32 elp_reg;
153
154 elp_reg = ELPCTRL_WAKE_UP;
155 wl12xx_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg);
156 elp_reg = wl12xx_read32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR);
157
158 if (!(elp_reg & ELPCTRL_WLAN_READY)) {
159 wl12xx_warning("WLAN not ready");
160 elp_reg = ELPCTRL_WAKE_UP_WLAN_READY;
161 wl12xx_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg);
162 }
163}
164
165static int wl12xx_chip_wakeup(struct wl12xx *wl)
166{
167 int ret = 0;
168
169 wl12xx_power_on(wl);
170 msleep(wl->chip.power_on_sleep);
171 wl12xx_spi_reset(wl);
172 wl12xx_spi_init(wl);
173
174 /* We don't need a real memory partition here, because we only want
175 * to use the registers at this point. */
176 wl12xx_set_partition(wl,
177 0x00000000,
178 0x00000000,
179 REGISTERS_BASE,
180 REGISTERS_DOWN_SIZE);
181
182 /* ELP module wake up */
183 wl12xx_fw_wakeup(wl);
184
185 /* whal_FwCtrl_BootSm() */
186
187 /* 0. read chip id from CHIP_ID */
188 wl->chip.id = wl12xx_reg_read32(wl, CHIP_ID_B);
189
190 /* 1. check if chip id is valid */
191
192 switch (wl->chip.id) {
193 case CHIP_ID_1251_PG12:
194 wl12xx_debug(DEBUG_BOOT, "chip id 0x%x (1251 PG12)",
195 wl->chip.id);
196
197 wl1251_setup(wl);
198
199 break;
200 case CHIP_ID_1271_PG10:
201 case CHIP_ID_1251_PG10:
202 case CHIP_ID_1251_PG11:
203 default:
204 wl12xx_error("unsupported chip id: 0x%x", wl->chip.id);
205 ret = -ENODEV;
206 goto out;
207 }
208
209 if (wl->fw == NULL) {
210 ret = wl12xx_fetch_firmware(wl);
211 if (ret < 0)
212 goto out;
213 }
214
215 /* No NVS from netlink, try to get it from the filesystem */
216 if (wl->nvs == NULL) {
217 ret = wl12xx_fetch_nvs(wl);
218 if (ret < 0)
219 goto out;
220 }
221
222out:
223 return ret;
224}
225
226static void wl12xx_filter_work(struct work_struct *work)
227{
228 struct wl12xx *wl =
229 container_of(work, struct wl12xx, filter_work);
230 int ret;
231
232 mutex_lock(&wl->mutex);
233
234 if (wl->state == WL12XX_STATE_OFF)
235 goto out;
236
237 ret = wl12xx_cmd_join(wl, wl->bss_type, 1, 100, 0);
238 if (ret < 0)
239 goto out;
240
241out:
242 mutex_unlock(&wl->mutex);
243}
244
245int wl12xx_plt_start(struct wl12xx *wl)
246{
247 int ret;
248
249 wl12xx_notice("power up");
250
251 if (wl->state != WL12XX_STATE_OFF) {
252 wl12xx_error("cannot go into PLT state because not "
253 "in off state: %d", wl->state);
254 return -EBUSY;
255 }
256
257 wl->state = WL12XX_STATE_PLT;
258
259 ret = wl12xx_chip_wakeup(wl);
260 if (ret < 0)
261 return ret;
262
263 ret = wl->chip.op_boot(wl);
264 if (ret < 0)
265 return ret;
266
267 wl12xx_notice("firmware booted in PLT mode (%s)", wl->chip.fw_ver);
268
269 ret = wl->chip.op_plt_init(wl);
270 if (ret < 0)
271 return ret;
272
273 return 0;
274}
275
276int wl12xx_plt_stop(struct wl12xx *wl)
277{
278 wl12xx_notice("power down");
279
280 if (wl->state != WL12XX_STATE_PLT) {
281 wl12xx_error("cannot power down because not in PLT "
282 "state: %d", wl->state);
283 return -EBUSY;
284 }
285
286 wl12xx_disable_interrupts(wl);
287 wl12xx_power_off(wl);
288
289 wl->state = WL12XX_STATE_OFF;
290
291 return 0;
292}
293
294
295static int wl12xx_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
296{
297 struct wl12xx *wl = hw->priv;
298
299 skb_queue_tail(&wl->tx_queue, skb);
300
301 schedule_work(&wl->tx_work);
302
303 /*
304 * The workqueue is slow to process the tx_queue and we need stop
305 * the queue here, otherwise the queue will get too long.
306 */
307 if (skb_queue_len(&wl->tx_queue) >= WL12XX_TX_QUEUE_MAX_LENGTH) {
308 ieee80211_stop_queues(wl->hw);
309
310 /*
311 * FIXME: this is racy, the variable is not properly
312 * protected. Maybe fix this by removing the stupid
313 * variable altogether and checking the real queue state?
314 */
315 wl->tx_queue_stopped = true;
316 }
317
318 return NETDEV_TX_OK;
319}
320
321static int wl12xx_op_start(struct ieee80211_hw *hw)
322{
323 struct wl12xx *wl = hw->priv;
324 int ret = 0;
325
326 wl12xx_debug(DEBUG_MAC80211, "mac80211 start");
327
328 mutex_lock(&wl->mutex);
329
330 if (wl->state != WL12XX_STATE_OFF) {
331 wl12xx_error("cannot start because not in off state: %d",
332 wl->state);
333 ret = -EBUSY;
334 goto out;
335 }
336
337 ret = wl12xx_chip_wakeup(wl);
338 if (ret < 0)
339 return ret;
340
341 ret = wl->chip.op_boot(wl);
342 if (ret < 0)
343 goto out;
344
345 ret = wl->chip.op_hw_init(wl);
346 if (ret < 0)
347 goto out;
348
349 ret = wl12xx_acx_station_id(wl);
350 if (ret < 0)
351 goto out;
352
353 wl->state = WL12XX_STATE_ON;
354
355 wl12xx_info("firmware booted (%s)", wl->chip.fw_ver);
356
357out:
358 if (ret < 0)
359 wl12xx_power_off(wl);
360
361 mutex_unlock(&wl->mutex);
362
363 return ret;
364}
365
366static void wl12xx_op_stop(struct ieee80211_hw *hw)
367{
368 struct wl12xx *wl = hw->priv;
369
370 wl12xx_info("down");
371
372 wl12xx_debug(DEBUG_MAC80211, "mac80211 stop");
373
374 mutex_lock(&wl->mutex);
375
376 WARN_ON(wl->state != WL12XX_STATE_ON);
377
378 if (wl->scanning) {
379 mutex_unlock(&wl->mutex);
380 ieee80211_scan_completed(wl->hw, true);
381 mutex_lock(&wl->mutex);
382 wl->scanning = false;
383 }
384
385 wl->state = WL12XX_STATE_OFF;
386
387 wl12xx_disable_interrupts(wl);
388
389 mutex_unlock(&wl->mutex);
390
391 cancel_work_sync(&wl->irq_work);
392 cancel_work_sync(&wl->tx_work);
393 cancel_work_sync(&wl->filter_work);
394
395 mutex_lock(&wl->mutex);
396
397 /* let's notify MAC80211 about the remaining pending TX frames */
398 wl12xx_tx_flush(wl);
399
400 wl12xx_power_off(wl);
401
402 memset(wl->bssid, 0, ETH_ALEN);
403 wl->listen_int = 1;
404 wl->bss_type = MAX_BSS_TYPE;
405
406 wl->data_in_count = 0;
407 wl->rx_counter = 0;
408 wl->rx_handled = 0;
409 wl->rx_current_buffer = 0;
410 wl->rx_last_id = 0;
411 wl->next_tx_complete = 0;
412 wl->elp = false;
413 wl->psm = 0;
414 wl->tx_queue_stopped = false;
415 wl->power_level = WL12XX_DEFAULT_POWER_LEVEL;
416
417 wl12xx_debugfs_reset(wl);
418
419 mutex_unlock(&wl->mutex);
420}
421
422static int wl12xx_op_add_interface(struct ieee80211_hw *hw,
423 struct ieee80211_if_init_conf *conf)
424{
425 struct wl12xx *wl = hw->priv;
426 DECLARE_MAC_BUF(mac);
427 int ret = 0;
428
429 wl12xx_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %s",
430 conf->type, print_mac(mac, conf->mac_addr));
431
432 mutex_lock(&wl->mutex);
433
434 switch (conf->type) {
435 case NL80211_IFTYPE_STATION:
436 wl->bss_type = BSS_TYPE_STA_BSS;
437 break;
438 case NL80211_IFTYPE_ADHOC:
439 wl->bss_type = BSS_TYPE_IBSS;
440 break;
441 default:
442 ret = -EOPNOTSUPP;
443 goto out;
444 }
445
446 if (memcmp(wl->mac_addr, conf->mac_addr, ETH_ALEN)) {
447 memcpy(wl->mac_addr, conf->mac_addr, ETH_ALEN);
448 SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr);
449 ret = wl12xx_acx_station_id(wl);
450 if (ret < 0)
451 goto out;
452 }
453
454out:
455 mutex_unlock(&wl->mutex);
456 return ret;
457}
458
459static void wl12xx_op_remove_interface(struct ieee80211_hw *hw,
460 struct ieee80211_if_init_conf *conf)
461{
462 wl12xx_debug(DEBUG_MAC80211, "mac80211 remove interface");
463}
464
465static int wl12xx_build_null_data(struct wl12xx *wl)
466{
467 struct wl12xx_null_data_template template;
468
469 if (!is_zero_ether_addr(wl->bssid)) {
470 memcpy(template.header.da, wl->bssid, ETH_ALEN);
471 memcpy(template.header.bssid, wl->bssid, ETH_ALEN);
472 } else {
473 memset(template.header.da, 0xff, ETH_ALEN);
474 memset(template.header.bssid, 0xff, ETH_ALEN);
475 }
476
477 memcpy(template.header.sa, wl->mac_addr, ETH_ALEN);
478 template.header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_DATA |
479 IEEE80211_STYPE_NULLFUNC);
480
481 return wl12xx_cmd_template_set(wl, CMD_NULL_DATA, &template,
482 sizeof(template));
483
484}
485
486static int wl12xx_build_ps_poll(struct wl12xx *wl, u16 aid)
487{
488 struct wl12xx_ps_poll_template template;
489
490 memcpy(template.bssid, wl->bssid, ETH_ALEN);
491 memcpy(template.ta, wl->mac_addr, ETH_ALEN);
492 template.aid = aid;
493 template.fc = cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL);
494
495 return wl12xx_cmd_template_set(wl, CMD_PS_POLL, &template,
496 sizeof(template));
497
498}
499
500static int wl12xx_op_config(struct ieee80211_hw *hw, u32 changed)
501{
502 struct wl12xx *wl = hw->priv;
503 struct ieee80211_conf *conf = &hw->conf;
504 int channel, ret = 0;
505
506 channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
507
508 wl12xx_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d",
509 channel,
510 conf->flags & IEEE80211_CONF_PS ? "on" : "off",
511 conf->power_level);
512
513 mutex_lock(&wl->mutex);
514
515 if (channel != wl->channel) {
516 /* FIXME: use beacon interval provided by mac80211 */
517 ret = wl12xx_cmd_join(wl, wl->bss_type, 1, 100, 0);
518 if (ret < 0)
519 goto out;
520
521 wl->channel = channel;
522 }
523
524 ret = wl12xx_build_null_data(wl);
525 if (ret < 0)
526 goto out;
527
528 if (conf->flags & IEEE80211_CONF_PS && !wl->psm_requested) {
529 wl12xx_info("psm enabled");
530
531 wl->psm_requested = true;
532
533 /*
534 * We enter PSM only if we're already associated.
535 * If we're not, we'll enter it when joining an SSID,
536 * through the bss_info_changed() hook.
537 */
538 ret = wl12xx_ps_set_mode(wl, STATION_POWER_SAVE_MODE);
539 } else if (!(conf->flags & IEEE80211_CONF_PS) &&
540 wl->psm_requested) {
541 wl12xx_info("psm disabled");
542
543 wl->psm_requested = false;
544
545 if (wl->psm)
546 ret = wl12xx_ps_set_mode(wl, STATION_ACTIVE_MODE);
547 }
548
549 if (conf->power_level != wl->power_level) {
550 ret = wl12xx_acx_tx_power(wl, conf->power_level);
551 if (ret < 0)
552 goto out;
553
554 wl->power_level = conf->power_level;
555 }
556
557out:
558 mutex_unlock(&wl->mutex);
559 return ret;
560}
561
562#define WL12XX_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \
563 FIF_ALLMULTI | \
564 FIF_FCSFAIL | \
565 FIF_BCN_PRBRESP_PROMISC | \
566 FIF_CONTROL | \
567 FIF_OTHER_BSS)
568
569static void wl12xx_op_configure_filter(struct ieee80211_hw *hw,
570 unsigned int changed,
571 unsigned int *total,
572 int mc_count,
573 struct dev_addr_list *mc_list)
574{
575 struct wl12xx *wl = hw->priv;
576
577 wl12xx_debug(DEBUG_MAC80211, "mac80211 configure filter");
578
579 *total &= WL12XX_SUPPORTED_FILTERS;
580 changed &= WL12XX_SUPPORTED_FILTERS;
581
582 if (changed == 0)
583 /* no filters which we support changed */
584 return;
585
586 /* FIXME: wl->rx_config and wl->rx_filter are not protected */
587
588 wl->rx_config = WL12XX_DEFAULT_RX_CONFIG;
589 wl->rx_filter = WL12XX_DEFAULT_RX_FILTER;
590
591 if (*total & FIF_PROMISC_IN_BSS) {
592 wl->rx_config |= CFG_BSSID_FILTER_EN;
593 wl->rx_config |= CFG_RX_ALL_GOOD;
594 }
595 if (*total & FIF_ALLMULTI)
596 /*
597 * CFG_MC_FILTER_EN in rx_config needs to be 0 to receive
598 * all multicast frames
599 */
600 wl->rx_config &= ~CFG_MC_FILTER_EN;
601 if (*total & FIF_FCSFAIL)
602 wl->rx_filter |= CFG_RX_FCS_ERROR;
603 if (*total & FIF_BCN_PRBRESP_PROMISC) {
604 wl->rx_config &= ~CFG_BSSID_FILTER_EN;
605 wl->rx_config &= ~CFG_SSID_FILTER_EN;
606 }
607 if (*total & FIF_CONTROL)
608 wl->rx_filter |= CFG_RX_CTL_EN;
609 if (*total & FIF_OTHER_BSS)
610 wl->rx_filter &= ~CFG_BSSID_FILTER_EN;
611
612 /*
613 * FIXME: workqueues need to be properly cancelled on stop(), for
614 * now let's just disable changing the filter settings. They will
615 * be updated any on config().
616 */
617 /* schedule_work(&wl->filter_work); */
618}
619
620/* HW encryption */
621static int wl12xx_set_key_type(struct wl12xx *wl, struct acx_set_key *key,
622 enum set_key_cmd cmd,
623 struct ieee80211_key_conf *mac80211_key,
624 const u8 *addr)
625{
626 switch (mac80211_key->alg) {
627 case ALG_WEP:
628 if (is_broadcast_ether_addr(addr))
629 key->key_type = KEY_WEP_DEFAULT;
630 else
631 key->key_type = KEY_WEP_ADDR;
632
633 mac80211_key->hw_key_idx = mac80211_key->keyidx;
634 break;
635 case ALG_TKIP:
636 if (is_broadcast_ether_addr(addr))
637 key->key_type = KEY_TKIP_MIC_GROUP;
638 else
639 key->key_type = KEY_TKIP_MIC_PAIRWISE;
640
641 mac80211_key->hw_key_idx = mac80211_key->keyidx;
642 break;
643 case ALG_CCMP:
644 if (is_broadcast_ether_addr(addr))
645 key->key_type = KEY_AES_GROUP;
646 else
647 key->key_type = KEY_AES_PAIRWISE;
648 mac80211_key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
649 break;
650 default:
651 wl12xx_error("Unknown key algo 0x%x", mac80211_key->alg);
652 return -EOPNOTSUPP;
653 }
654
655 return 0;
656}
657
658static int wl12xx_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
659 struct ieee80211_vif *vif,
660 struct ieee80211_sta *sta,
661 struct ieee80211_key_conf *key)
662{
663 struct wl12xx *wl = hw->priv;
664 struct acx_set_key wl_key;
665 const u8 *addr;
666 int ret;
667
668 static const u8 bcast_addr[ETH_ALEN] =
669 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
670
671 wl12xx_debug(DEBUG_MAC80211, "mac80211 set key");
672
673 memset(&wl_key, 0, sizeof(wl_key));
674
675 addr = sta ? sta->addr : bcast_addr;
676
677 wl12xx_debug(DEBUG_CRYPT, "CMD: 0x%x", cmd);
678 wl12xx_dump(DEBUG_CRYPT, "ADDR: ", addr, ETH_ALEN);
679 wl12xx_debug(DEBUG_CRYPT, "Key: algo:0x%x, id:%d, len:%d flags 0x%x",
680 key->alg, key->keyidx, key->keylen, key->flags);
681 wl12xx_dump(DEBUG_CRYPT, "KEY: ", key->key, key->keylen);
682
683 mutex_lock(&wl->mutex);
684
685 switch (cmd) {
686 case SET_KEY:
687 wl_key.key_action = KEY_ADD_OR_REPLACE;
688 break;
689 case DISABLE_KEY:
690 wl_key.key_action = KEY_REMOVE;
691 break;
692 default:
693 wl12xx_error("Unsupported key cmd 0x%x", cmd);
694 break;
695 }
696
697 ret = wl12xx_set_key_type(wl, &wl_key, cmd, key, addr);
698 if (ret < 0) {
699 wl12xx_error("Set KEY type failed");
700 goto out;
701 }
702
703 if (wl_key.key_type != KEY_WEP_DEFAULT)
704 memcpy(wl_key.addr, addr, ETH_ALEN);
705
706 if ((wl_key.key_type == KEY_TKIP_MIC_GROUP) ||
707 (wl_key.key_type == KEY_TKIP_MIC_PAIRWISE)) {
708 /*
709 * We get the key in the following form:
710 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
711 * but the target is expecting:
712 * TKIP - RX MIC - TX MIC
713 */
714 memcpy(wl_key.key, key->key, 16);
715 memcpy(wl_key.key + 16, key->key + 24, 8);
716 memcpy(wl_key.key + 24, key->key + 16, 8);
717
718 } else {
719 memcpy(wl_key.key, key->key, key->keylen);
720 }
721 wl_key.key_size = key->keylen;
722
723 wl_key.id = key->keyidx;
724 wl_key.ssid_profile = 0;
725
726 wl12xx_dump(DEBUG_CRYPT, "TARGET KEY: ", &wl_key, sizeof(wl_key));
727
728 if (wl12xx_cmd_send(wl, CMD_SET_KEYS, &wl_key, sizeof(wl_key)) < 0) {
729 wl12xx_error("Set KEY failed");
730 ret = -EOPNOTSUPP;
731 goto out;
732 }
733
734out:
735 mutex_unlock(&wl->mutex);
736 return ret;
737}
738
739static int wl12xx_build_basic_rates(char *rates)
740{
741 u8 index = 0;
742
743 rates[index++] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
744 rates[index++] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
745 rates[index++] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_5MB;
746 rates[index++] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_11MB;
747
748 return index;
749}
750
751static int wl12xx_build_extended_rates(char *rates)
752{
753 u8 index = 0;
754
755 rates[index++] = IEEE80211_OFDM_RATE_6MB;
756 rates[index++] = IEEE80211_OFDM_RATE_9MB;
757 rates[index++] = IEEE80211_OFDM_RATE_12MB;
758 rates[index++] = IEEE80211_OFDM_RATE_18MB;
759 rates[index++] = IEEE80211_OFDM_RATE_24MB;
760 rates[index++] = IEEE80211_OFDM_RATE_36MB;
761 rates[index++] = IEEE80211_OFDM_RATE_48MB;
762 rates[index++] = IEEE80211_OFDM_RATE_54MB;
763
764 return index;
765}
766
767
768static int wl12xx_build_probe_req(struct wl12xx *wl, u8 *ssid, size_t ssid_len)
769{
770 struct wl12xx_probe_req_template template;
771 struct wl12xx_ie_rates *rates;
772 char *ptr;
773 u16 size;
774
775 ptr = (char *)&template;
776 size = sizeof(struct ieee80211_header);
777
778 memset(template.header.da, 0xff, ETH_ALEN);
779 memset(template.header.bssid, 0xff, ETH_ALEN);
780 memcpy(template.header.sa, wl->mac_addr, ETH_ALEN);
781 template.header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
782
783 /* IEs */
784 /* SSID */
785 template.ssid.header.id = WLAN_EID_SSID;
786 template.ssid.header.len = ssid_len;
787 if (ssid_len && ssid)
788 memcpy(template.ssid.ssid, ssid, ssid_len);
789 size += sizeof(struct wl12xx_ie_header) + ssid_len;
790 ptr += size;
791
792 /* Basic Rates */
793 rates = (struct wl12xx_ie_rates *)ptr;
794 rates->header.id = WLAN_EID_SUPP_RATES;
795 rates->header.len = wl12xx_build_basic_rates(rates->rates);
796 size += sizeof(struct wl12xx_ie_header) + rates->header.len;
797 ptr += sizeof(struct wl12xx_ie_header) + rates->header.len;
798
799 /* Extended rates */
800 rates = (struct wl12xx_ie_rates *)ptr;
801 rates->header.id = WLAN_EID_EXT_SUPP_RATES;
802 rates->header.len = wl12xx_build_extended_rates(rates->rates);
803 size += sizeof(struct wl12xx_ie_header) + rates->header.len;
804
805 wl12xx_dump(DEBUG_SCAN, "PROBE REQ: ", &template, size);
806
807 return wl12xx_cmd_template_set(wl, CMD_PROBE_REQ, &template,
808 size);
809}
810
811static int wl12xx_hw_scan(struct wl12xx *wl, u8 *ssid, size_t len,
812 u8 active_scan, u8 high_prio, u8 num_channels,
813 u8 probe_requests)
814{
815 int i, ret;
816 u32 split_scan = 0;
817 u16 scan_options = 0;
818 struct cmd_scan *params;
819 struct wl12xx_command *cmd_answer;
820
821 if (wl->scanning)
822 return -EINVAL;
823
824 params = kzalloc(sizeof(*params), GFP_KERNEL);
825 if (!params)
826 return -ENOMEM;
827
828 params->params.rx_config_options = cpu_to_le32(CFG_RX_ALL_GOOD);
829 params->params.rx_filter_options =
830 cpu_to_le32(CFG_RX_PRSP_EN | CFG_RX_MGMT_EN | CFG_RX_BCN_EN);
831
832 /* High priority scan */
833 if (!active_scan)
834 scan_options |= SCAN_PASSIVE;
835 if (high_prio)
836 scan_options |= SCAN_PRIORITY_HIGH;
837 params->params.scan_options = scan_options;
838
839 params->params.num_channels = num_channels;
840 params->params.num_probe_requests = probe_requests;
841 params->params.tx_rate = cpu_to_le16(1 << 1); /* 2 Mbps */
842 params->params.tid_trigger = 0;
843
844 for (i = 0; i < num_channels; i++) {
845 params->channels[i].min_duration = cpu_to_le32(30000);
846 params->channels[i].max_duration = cpu_to_le32(60000);
847 memset(&params->channels[i].bssid_lsb, 0xff, 4);
848 memset(&params->channels[i].bssid_msb, 0xff, 2);
849 params->channels[i].early_termination = 0;
850 params->channels[i].tx_power_att = 0;
851 params->channels[i].channel = i + 1;
852 memset(params->channels[i].pad, 0, 3);
853 }
854
855 for (i = num_channels; i < SCAN_MAX_NUM_OF_CHANNELS; i++)
856 memset(&params->channels[i], 0,
857 sizeof(struct basic_scan_channel_parameters));
858
859 if (len && ssid) {
860 params->params.ssid_len = len;
861 memcpy(params->params.ssid, ssid, len);
862 } else {
863 params->params.ssid_len = 0;
864 memset(params->params.ssid, 0, 32);
865 }
866
867 ret = wl12xx_build_probe_req(wl, ssid, len);
868 if (ret < 0) {
869 wl12xx_error("PROBE request template failed");
870 goto out;
871 }
872
873 ret = wl12xx_cmd_send(wl, CMD_TRIGGER_SCAN_TO, &split_scan,
874 sizeof(u32));
875 if (ret < 0) {
876 wl12xx_error("Split SCAN failed");
877 goto out;
878 }
879
880 wl12xx_dump(DEBUG_SCAN, "SCAN: ", params, sizeof(*params));
881
882 wl->scanning = true;
883
884 ret = wl12xx_cmd_send(wl, CMD_SCAN, params, sizeof(*params));
885 if (ret < 0)
886 wl12xx_error("SCAN failed");
887
888 wl12xx_spi_mem_read(wl, wl->cmd_box_addr, params, sizeof(*params));
889
890 cmd_answer = (struct wl12xx_command *) params;
891 if (cmd_answer->status != CMD_STATUS_SUCCESS) {
892 wl12xx_error("TEST command answer error: %d",
893 cmd_answer->status);
894 wl->scanning = false;
895 ret = -EIO;
896 goto out;
897 }
898
899out:
900 kfree(params);
901 return ret;
902
903}
904
905static int wl12xx_op_hw_scan(struct ieee80211_hw *hw,
906 struct cfg80211_scan_request *req)
907{
908 struct wl12xx *wl = hw->priv;
909 int ret;
910 u8 *ssid = NULL;
911 size_t ssid_len = 0;
912
913 wl12xx_debug(DEBUG_MAC80211, "mac80211 hw scan");
914
915 if (req->n_ssids) {
916 ssid = req->ssids[0].ssid;
917 ssid_len = req->ssids[0].ssid_len;
918 }
919
920 mutex_lock(&wl->mutex);
921 ret = wl12xx_hw_scan(hw->priv, ssid, ssid_len, 1, 0, 13, 3);
922 mutex_unlock(&wl->mutex);
923
924 return ret;
925}
926
927static int wl12xx_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
928{
929 struct wl12xx *wl = hw->priv;
930 int ret;
931
932 ret = wl12xx_acx_rts_threshold(wl, (u16) value);
933
934 if (ret < 0)
935 wl12xx_warning("wl12xx_op_set_rts_threshold failed: %d", ret);
936
937 return ret;
938}
939
940static void wl12xx_op_bss_info_changed(struct ieee80211_hw *hw,
941 struct ieee80211_vif *vif,
942 struct ieee80211_bss_conf *bss_conf,
943 u32 changed)
944{
945 enum acx_ps_mode mode;
946 struct wl12xx *wl = hw->priv;
947 struct sk_buff *beacon;
948 int ret;
949
950 wl12xx_debug(DEBUG_MAC80211, "mac80211 bss info changed");
951
952 mutex_lock(&wl->mutex);
953
954 if (changed & BSS_CHANGED_ASSOC) {
955 if (bss_conf->assoc) {
956 wl->aid = bss_conf->aid;
957
958 ret = wl12xx_build_ps_poll(wl, wl->aid);
959 if (ret < 0)
960 goto out;
961
962 ret = wl12xx_acx_aid(wl, wl->aid);
963 if (ret < 0)
964 goto out;
965
966 /* If we want to go in PSM but we're not there yet */
967 if (wl->psm_requested && !wl->psm) {
968 mode = STATION_POWER_SAVE_MODE;
969 ret = wl12xx_ps_set_mode(wl, mode);
970 if (ret < 0)
971 goto out;
972 }
973 }
974 }
975 if (changed & BSS_CHANGED_ERP_SLOT) {
976 if (bss_conf->use_short_slot)
977 ret = wl12xx_acx_slot(wl, SLOT_TIME_SHORT);
978 else
979 ret = wl12xx_acx_slot(wl, SLOT_TIME_LONG);
980 if (ret < 0) {
981 wl12xx_warning("Set slot time failed %d", ret);
982 goto out;
983 }
984 }
985
986 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
987 if (bss_conf->use_short_preamble)
988 wl12xx_acx_set_preamble(wl, ACX_PREAMBLE_SHORT);
989 else
990 wl12xx_acx_set_preamble(wl, ACX_PREAMBLE_LONG);
991 }
992
993 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
994 if (bss_conf->use_cts_prot)
995 ret = wl12xx_acx_cts_protect(wl, CTSPROTECT_ENABLE);
996 else
997 ret = wl12xx_acx_cts_protect(wl, CTSPROTECT_DISABLE);
998 if (ret < 0) {
999 wl12xx_warning("Set ctsprotect failed %d", ret);
1000 goto out;
1001 }
1002 }
1003
1004 if (changed & BSS_CHANGED_BSSID) {
1005 memcpy(wl->bssid, bss_conf->bssid, ETH_ALEN);
1006
1007 ret = wl12xx_build_null_data(wl);
1008 if (ret < 0)
1009 goto out;
1010
1011 if (wl->bss_type != BSS_TYPE_IBSS) {
1012 ret = wl12xx_cmd_join(wl, wl->bss_type, 5, 100, 1);
1013 if (ret < 0)
1014 goto out;
1015 }
1016 }
1017
1018 if (changed & BSS_CHANGED_BEACON) {
1019 beacon = ieee80211_beacon_get(hw, vif);
1020 ret = wl12xx_cmd_template_set(wl, CMD_BEACON, beacon->data,
1021 beacon->len);
1022
1023 if (ret < 0) {
1024 dev_kfree_skb(beacon);
1025 goto out;
1026 }
1027
1028 ret = wl12xx_cmd_template_set(wl, CMD_PROBE_RESP, beacon->data,
1029 beacon->len);
1030
1031 dev_kfree_skb(beacon);
1032
1033 if (ret < 0)
1034 goto out;
1035
1036 ret = wl12xx_cmd_join(wl, wl->bss_type, 1, 100, 0);
1037
1038 if (ret < 0)
1039 goto out;
1040 }
1041
1042out:
1043 mutex_unlock(&wl->mutex);
1044}
1045
1046
1047/* can't be const, mac80211 writes to this */
1048static struct ieee80211_rate wl12xx_rates[] = {
1049 { .bitrate = 10,
1050 .hw_value = 0x1,
1051 .hw_value_short = 0x1, },
1052 { .bitrate = 20,
1053 .hw_value = 0x2,
1054 .hw_value_short = 0x2,
1055 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
1056 { .bitrate = 55,
1057 .hw_value = 0x4,
1058 .hw_value_short = 0x4,
1059 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
1060 { .bitrate = 110,
1061 .hw_value = 0x20,
1062 .hw_value_short = 0x20,
1063 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
1064 { .bitrate = 60,
1065 .hw_value = 0x8,
1066 .hw_value_short = 0x8, },
1067 { .bitrate = 90,
1068 .hw_value = 0x10,
1069 .hw_value_short = 0x10, },
1070 { .bitrate = 120,
1071 .hw_value = 0x40,
1072 .hw_value_short = 0x40, },
1073 { .bitrate = 180,
1074 .hw_value = 0x80,
1075 .hw_value_short = 0x80, },
1076 { .bitrate = 240,
1077 .hw_value = 0x200,
1078 .hw_value_short = 0x200, },
1079 { .bitrate = 360,
1080 .hw_value = 0x400,
1081 .hw_value_short = 0x400, },
1082 { .bitrate = 480,
1083 .hw_value = 0x800,
1084 .hw_value_short = 0x800, },
1085 { .bitrate = 540,
1086 .hw_value = 0x1000,
1087 .hw_value_short = 0x1000, },
1088};
1089
1090/* can't be const, mac80211 writes to this */
1091static struct ieee80211_channel wl12xx_channels[] = {
1092 { .hw_value = 1, .center_freq = 2412},
1093 { .hw_value = 2, .center_freq = 2417},
1094 { .hw_value = 3, .center_freq = 2422},
1095 { .hw_value = 4, .center_freq = 2427},
1096 { .hw_value = 5, .center_freq = 2432},
1097 { .hw_value = 6, .center_freq = 2437},
1098 { .hw_value = 7, .center_freq = 2442},
1099 { .hw_value = 8, .center_freq = 2447},
1100 { .hw_value = 9, .center_freq = 2452},
1101 { .hw_value = 10, .center_freq = 2457},
1102 { .hw_value = 11, .center_freq = 2462},
1103 { .hw_value = 12, .center_freq = 2467},
1104 { .hw_value = 13, .center_freq = 2472},
1105};
1106
1107/* can't be const, mac80211 writes to this */
1108static struct ieee80211_supported_band wl12xx_band_2ghz = {
1109 .channels = wl12xx_channels,
1110 .n_channels = ARRAY_SIZE(wl12xx_channels),
1111 .bitrates = wl12xx_rates,
1112 .n_bitrates = ARRAY_SIZE(wl12xx_rates),
1113};
1114
1115static const struct ieee80211_ops wl12xx_ops = {
1116 .start = wl12xx_op_start,
1117 .stop = wl12xx_op_stop,
1118 .add_interface = wl12xx_op_add_interface,
1119 .remove_interface = wl12xx_op_remove_interface,
1120 .config = wl12xx_op_config,
1121 .configure_filter = wl12xx_op_configure_filter,
1122 .tx = wl12xx_op_tx,
1123 .set_key = wl12xx_op_set_key,
1124 .hw_scan = wl12xx_op_hw_scan,
1125 .bss_info_changed = wl12xx_op_bss_info_changed,
1126 .set_rts_threshold = wl12xx_op_set_rts_threshold,
1127};
1128
1129static int wl12xx_register_hw(struct wl12xx *wl)
1130{
1131 int ret;
1132
1133 if (wl->mac80211_registered)
1134 return 0;
1135
1136 SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr);
1137
1138 ret = ieee80211_register_hw(wl->hw);
1139 if (ret < 0) {
1140 wl12xx_error("unable to register mac80211 hw: %d", ret);
1141 return ret;
1142 }
1143
1144 wl->mac80211_registered = true;
1145
1146 wl12xx_notice("loaded");
1147
1148 return 0;
1149}
1150
1151static int wl12xx_init_ieee80211(struct wl12xx *wl)
1152{
1153 /* The tx descriptor buffer and the TKIP space */
1154 wl->hw->extra_tx_headroom = sizeof(struct tx_double_buffer_desc)
1155 + WL12XX_TKIP_IV_SPACE;
1156
1157 /* unit us */
1158 /* FIXME: find a proper value */
1159 wl->hw->channel_change_time = 10000;
1160
1161 wl->hw->flags = IEEE80211_HW_SIGNAL_DBM |
1162 IEEE80211_HW_NOISE_DBM;
1163
1164 wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
1165 wl->hw->wiphy->max_scan_ssids = 1;
1166 wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl12xx_band_2ghz;
1167
1168 SET_IEEE80211_DEV(wl->hw, &wl->spi->dev);
1169
1170 return 0;
1171}
1172
1173#define WL12XX_DEFAULT_CHANNEL 1
1174static int __devinit wl12xx_probe(struct spi_device *spi)
1175{
1176 struct wl12xx_platform_data *pdata;
1177 struct ieee80211_hw *hw;
1178 struct wl12xx *wl;
1179 int ret, i;
1180 static const u8 nokia_oui[3] = {0x00, 0x1f, 0xdf};
1181
1182 pdata = spi->dev.platform_data;
1183 if (!pdata) {
1184 wl12xx_error("no platform data");
1185 return -ENODEV;
1186 }
1187
1188 hw = ieee80211_alloc_hw(sizeof(*wl), &wl12xx_ops);
1189 if (!hw) {
1190 wl12xx_error("could not alloc ieee80211_hw");
1191 return -ENOMEM;
1192 }
1193
1194 wl = hw->priv;
1195 memset(wl, 0, sizeof(*wl));
1196
1197 wl->hw = hw;
1198 dev_set_drvdata(&spi->dev, wl);
1199 wl->spi = spi;
1200
1201 wl->data_in_count = 0;
1202
1203 skb_queue_head_init(&wl->tx_queue);
1204
1205 INIT_WORK(&wl->tx_work, wl12xx_tx_work);
1206 INIT_WORK(&wl->filter_work, wl12xx_filter_work);
1207 wl->channel = WL12XX_DEFAULT_CHANNEL;
1208 wl->scanning = false;
1209 wl->default_key = 0;
1210 wl->listen_int = 1;
1211 wl->rx_counter = 0;
1212 wl->rx_handled = 0;
1213 wl->rx_current_buffer = 0;
1214 wl->rx_last_id = 0;
1215 wl->rx_config = WL12XX_DEFAULT_RX_CONFIG;
1216 wl->rx_filter = WL12XX_DEFAULT_RX_FILTER;
1217 wl->elp = false;
1218 wl->psm = 0;
1219 wl->psm_requested = false;
1220 wl->tx_queue_stopped = false;
1221 wl->power_level = WL12XX_DEFAULT_POWER_LEVEL;
1222
1223 /* We use the default power on sleep time until we know which chip
1224 * we're using */
1225 wl->chip.power_on_sleep = WL12XX_DEFAULT_POWER_ON_SLEEP;
1226
1227 for (i = 0; i < FW_TX_CMPLT_BLOCK_SIZE; i++)
1228 wl->tx_frames[i] = NULL;
1229
1230 wl->next_tx_complete = 0;
1231
1232 /*
1233 * In case our MAC address is not correctly set,
1234 * we use a random but Nokia MAC.
1235 */
1236 memcpy(wl->mac_addr, nokia_oui, 3);
1237 get_random_bytes(wl->mac_addr + 3, 3);
1238
1239 wl->state = WL12XX_STATE_OFF;
1240 mutex_init(&wl->mutex);
1241
1242 wl->tx_mgmt_frm_rate = DEFAULT_HW_GEN_TX_RATE;
1243 wl->tx_mgmt_frm_mod = DEFAULT_HW_GEN_MODULATION_TYPE;
1244
1245 /* This is the only SPI value that we need to set here, the rest
1246 * comes from the board-peripherals file */
1247 spi->bits_per_word = 32;
1248
1249 ret = spi_setup(spi);
1250 if (ret < 0) {
1251 wl12xx_error("spi_setup failed");
1252 goto out_free;
1253 }
1254
1255 wl->set_power = pdata->set_power;
1256 if (!wl->set_power) {
1257 wl12xx_error("set power function missing in platform data");
1258 return -ENODEV;
1259 }
1260
1261 wl->irq = spi->irq;
1262 if (wl->irq < 0) {
1263 wl12xx_error("irq missing in platform data");
1264 return -ENODEV;
1265 }
1266
1267 ret = request_irq(wl->irq, wl12xx_irq, 0, DRIVER_NAME, wl);
1268 if (ret < 0) {
1269 wl12xx_error("request_irq() failed: %d", ret);
1270 goto out_free;
1271 }
1272
1273 set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
1274
1275 disable_irq(wl->irq);
1276
1277 ret = wl12xx_init_ieee80211(wl);
1278 if (ret)
1279 goto out_irq;
1280
1281 ret = wl12xx_register_hw(wl);
1282 if (ret)
1283 goto out_irq;
1284
1285 wl12xx_debugfs_init(wl);
1286
1287 wl12xx_notice("initialized");
1288
1289 return 0;
1290
1291 out_irq:
1292 free_irq(wl->irq, wl);
1293
1294 out_free:
1295 ieee80211_free_hw(hw);
1296
1297 return ret;
1298}
1299
1300static int __devexit wl12xx_remove(struct spi_device *spi)
1301{
1302 struct wl12xx *wl = dev_get_drvdata(&spi->dev);
1303
1304 ieee80211_unregister_hw(wl->hw);
1305
1306 wl12xx_debugfs_exit(wl);
1307
1308 free_irq(wl->irq, wl);
1309 kfree(wl->target_mem_map);
1310 kfree(wl->data_path);
1311 kfree(wl->fw);
1312 wl->fw = NULL;
1313 kfree(wl->nvs);
1314 wl->nvs = NULL;
1315 ieee80211_free_hw(wl->hw);
1316
1317 return 0;
1318}
1319
1320
1321static struct spi_driver wl12xx_spi_driver = {
1322 .driver = {
1323 .name = "wl12xx",
1324 .bus = &spi_bus_type,
1325 .owner = THIS_MODULE,
1326 },
1327
1328 .probe = wl12xx_probe,
1329 .remove = __devexit_p(wl12xx_remove),
1330};
1331
1332static int __init wl12xx_init(void)
1333{
1334 int ret;
1335
1336 ret = spi_register_driver(&wl12xx_spi_driver);
1337 if (ret < 0) {
1338 wl12xx_error("failed to register spi driver: %d", ret);
1339 goto out;
1340 }
1341
1342out:
1343 return ret;
1344}
1345
1346static void __exit wl12xx_exit(void)
1347{
1348 spi_unregister_driver(&wl12xx_spi_driver);
1349
1350 wl12xx_notice("unloaded");
1351}
1352
1353module_init(wl12xx_init);
1354module_exit(wl12xx_exit);
1355
1356MODULE_LICENSE("GPL");
1357MODULE_AUTHOR("Kalle Valo <Kalle.Valo@nokia.com>, "
1358 "Luciano Coelho <luciano.coelho@nokia.com>");
diff --git a/drivers/net/wireless/wl12xx/ps.c b/drivers/net/wireless/wl12xx/ps.c
new file mode 100644
index 000000000000..83a10117330b
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/ps.c
@@ -0,0 +1,151 @@
1/*
2 * This file is part of wl12xx
3 *
4 * Copyright (C) 2008 Nokia Corporation
5 *
6 * Contact: Kalle Valo <kalle.valo@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 "reg.h"
25#include "ps.h"
26#include "spi.h"
27
28#define WL12XX_WAKEUP_TIMEOUT 2000
29
30/* Routines to toggle sleep mode while in ELP */
31void wl12xx_ps_elp_sleep(struct wl12xx *wl)
32{
33 if (wl->elp || !wl->psm)
34 return;
35
36 wl12xx_debug(DEBUG_PSM, "chip to elp");
37
38 wl12xx_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_SLEEP);
39
40 wl->elp = true;
41}
42
43int wl12xx_ps_elp_wakeup(struct wl12xx *wl)
44{
45 unsigned long timeout;
46 u32 elp_reg;
47
48 if (!wl->elp)
49 return 0;
50
51 wl12xx_debug(DEBUG_PSM, "waking up chip from elp");
52
53 timeout = jiffies + msecs_to_jiffies(WL12XX_WAKEUP_TIMEOUT);
54
55 wl12xx_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_WAKE_UP);
56
57 elp_reg = wl12xx_read32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR);
58
59 /*
60 * FIXME: we should wait for irq from chip but, as a temporary
61 * solution to simplify locking, let's poll instead
62 */
63 while (!(elp_reg & ELPCTRL_WLAN_READY)) {
64 if (time_after(jiffies, timeout)) {
65 wl12xx_error("elp wakeup timeout");
66 return -ETIMEDOUT;
67 }
68 msleep(1);
69 elp_reg = wl12xx_read32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR);
70 }
71
72 wl12xx_debug(DEBUG_PSM, "wakeup time: %u ms",
73 jiffies_to_msecs(jiffies) -
74 (jiffies_to_msecs(timeout) - WL12XX_WAKEUP_TIMEOUT));
75
76 wl->elp = false;
77
78 return 0;
79}
80
81static int wl12xx_ps_set_elp(struct wl12xx *wl, bool enable)
82{
83 int ret;
84
85 if (enable) {
86 wl12xx_debug(DEBUG_PSM, "sleep auth psm/elp");
87
88 /*
89 * FIXME: we should PSM_ELP, but because of firmware wakeup
90 * problems let's use only PSM_PS
91 */
92 ret = wl12xx_acx_sleep_auth(wl, WL12XX_PSM_PS);
93 if (ret < 0)
94 return ret;
95
96 wl12xx_ps_elp_sleep(wl);
97 } else {
98 wl12xx_debug(DEBUG_PSM, "sleep auth cam");
99
100 /*
101 * When the target is in ELP, we can only
102 * access the ELP control register. Thus,
103 * we have to wake the target up before
104 * changing the power authorization.
105 */
106
107 wl12xx_ps_elp_wakeup(wl);
108
109 ret = wl12xx_acx_sleep_auth(wl, WL12XX_PSM_CAM);
110 if (ret < 0)
111 return ret;
112 }
113
114 return 0;
115}
116
117int wl12xx_ps_set_mode(struct wl12xx *wl, enum acx_ps_mode mode)
118{
119 int ret;
120
121 switch (mode) {
122 case STATION_POWER_SAVE_MODE:
123 wl12xx_debug(DEBUG_PSM, "entering psm");
124 ret = wl12xx_cmd_ps_mode(wl, STATION_POWER_SAVE_MODE);
125 if (ret < 0)
126 return ret;
127
128 ret = wl12xx_ps_set_elp(wl, true);
129 if (ret < 0)
130 return ret;
131
132 wl->psm = 1;
133 break;
134 case STATION_ACTIVE_MODE:
135 default:
136 wl12xx_debug(DEBUG_PSM, "leaving psm");
137 ret = wl12xx_ps_set_elp(wl, false);
138 if (ret < 0)
139 return ret;
140
141 ret = wl12xx_cmd_ps_mode(wl, STATION_ACTIVE_MODE);
142 if (ret < 0)
143 return ret;
144
145 wl->psm = 0;
146 break;
147 }
148
149 return ret;
150}
151
diff --git a/drivers/net/wireless/wl12xx/ps.h b/drivers/net/wireless/wl12xx/ps.h
new file mode 100644
index 000000000000..5d7c52553830
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/ps.h
@@ -0,0 +1,36 @@
1#ifndef __WL12XX_PS_H__
2#define __WL12XX_PS_H__
3
4/*
5 * This file is part of wl12xx
6 *
7 * Copyright (c) 1998-2007 Texas Instruments Incorporated
8 * Copyright (C) 2008 Nokia Corporation
9 *
10 * Contact: Kalle Valo <kalle.valo@nokia.com>
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * version 2 as published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
24 * 02110-1301 USA
25 *
26 */
27
28#include "wl12xx.h"
29#include "acx.h"
30
31int wl12xx_ps_set_mode(struct wl12xx *wl, enum acx_ps_mode mode);
32void wl12xx_ps_elp_sleep(struct wl12xx *wl);
33int wl12xx_ps_elp_wakeup(struct wl12xx *wl);
34
35
36#endif /* __WL12XX_PS_H__ */
diff --git a/drivers/net/wireless/wl12xx/reg.h b/drivers/net/wireless/wl12xx/reg.h
new file mode 100644
index 000000000000..e421643215cd
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/reg.h
@@ -0,0 +1,745 @@
1/*
2 * This file is part of wl12xx
3 *
4 * Copyright (c) 1998-2007 Texas Instruments Incorporated
5 * Copyright (C) 2008 Nokia Corporation
6 *
7 * Contact: Kalle Valo <kalle.valo@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 __REG_H__
26#define __REG_H__
27
28#include <linux/bitops.h>
29#include "wl12xx.h"
30
31#define REGISTERS_BASE 0x00300000
32#define DRPW_BASE 0x00310000
33
34#define REGISTERS_DOWN_SIZE 0x00008800
35#define REGISTERS_WORK_SIZE 0x0000b000
36
37#define HW_ACCESS_ELP_CTRL_REG_ADDR 0x1FFFC
38
39/* ELP register commands */
40#define ELPCTRL_WAKE_UP 0x1
41#define ELPCTRL_WAKE_UP_WLAN_READY 0x5
42#define ELPCTRL_SLEEP 0x0
43/* ELP WLAN_READY bit */
44#define ELPCTRL_WLAN_READY 0x2
45
46/*
47 * Interrupt registers.
48 * 64 bit interrupt sources registers ws ced.
49 * sme interupts were removed and new ones were added.
50 * Order was changed.
51 */
52#define FIQ_MASK (REGISTERS_BASE + 0x0400)
53#define FIQ_MASK_L (REGISTERS_BASE + 0x0400)
54#define FIQ_MASK_H (REGISTERS_BASE + 0x0404)
55#define FIQ_MASK_SET (REGISTERS_BASE + 0x0408)
56#define FIQ_MASK_SET_L (REGISTERS_BASE + 0x0408)
57#define FIQ_MASK_SET_H (REGISTERS_BASE + 0x040C)
58#define FIQ_MASK_CLR (REGISTERS_BASE + 0x0410)
59#define FIQ_MASK_CLR_L (REGISTERS_BASE + 0x0410)
60#define FIQ_MASK_CLR_H (REGISTERS_BASE + 0x0414)
61#define IRQ_MASK (REGISTERS_BASE + 0x0418)
62#define IRQ_MASK_L (REGISTERS_BASE + 0x0418)
63#define IRQ_MASK_H (REGISTERS_BASE + 0x041C)
64#define IRQ_MASK_SET (REGISTERS_BASE + 0x0420)
65#define IRQ_MASK_SET_L (REGISTERS_BASE + 0x0420)
66#define IRQ_MASK_SET_H (REGISTERS_BASE + 0x0424)
67#define IRQ_MASK_CLR (REGISTERS_BASE + 0x0428)
68#define IRQ_MASK_CLR_L (REGISTERS_BASE + 0x0428)
69#define IRQ_MASK_CLR_H (REGISTERS_BASE + 0x042C)
70#define ECPU_MASK (REGISTERS_BASE + 0x0448)
71#define FIQ_STS_L (REGISTERS_BASE + 0x044C)
72#define FIQ_STS_H (REGISTERS_BASE + 0x0450)
73#define IRQ_STS_L (REGISTERS_BASE + 0x0454)
74#define IRQ_STS_H (REGISTERS_BASE + 0x0458)
75#define INT_STS_ND (REGISTERS_BASE + 0x0464)
76#define INT_STS_RAW_L (REGISTERS_BASE + 0x0464)
77#define INT_STS_RAW_H (REGISTERS_BASE + 0x0468)
78#define INT_STS_CLR (REGISTERS_BASE + 0x04B4)
79#define INT_STS_CLR_L (REGISTERS_BASE + 0x04B4)
80#define INT_STS_CLR_H (REGISTERS_BASE + 0x04B8)
81#define INT_ACK (REGISTERS_BASE + 0x046C)
82#define INT_ACK_L (REGISTERS_BASE + 0x046C)
83#define INT_ACK_H (REGISTERS_BASE + 0x0470)
84#define INT_TRIG (REGISTERS_BASE + 0x0474)
85#define INT_TRIG_L (REGISTERS_BASE + 0x0474)
86#define INT_TRIG_H (REGISTERS_BASE + 0x0478)
87#define HOST_STS_L (REGISTERS_BASE + 0x045C)
88#define HOST_STS_H (REGISTERS_BASE + 0x0460)
89#define HOST_MASK (REGISTERS_BASE + 0x0430)
90#define HOST_MASK_L (REGISTERS_BASE + 0x0430)
91#define HOST_MASK_H (REGISTERS_BASE + 0x0434)
92#define HOST_MASK_SET (REGISTERS_BASE + 0x0438)
93#define HOST_MASK_SET_L (REGISTERS_BASE + 0x0438)
94#define HOST_MASK_SET_H (REGISTERS_BASE + 0x043C)
95#define HOST_MASK_CLR (REGISTERS_BASE + 0x0440)
96#define HOST_MASK_CLR_L (REGISTERS_BASE + 0x0440)
97#define HOST_MASK_CLR_H (REGISTERS_BASE + 0x0444)
98
99/* Host Interrupts*/
100#define HINT_MASK (REGISTERS_BASE + 0x0494)
101#define HINT_MASK_SET (REGISTERS_BASE + 0x0498)
102#define HINT_MASK_CLR (REGISTERS_BASE + 0x049C)
103#define HINT_STS_ND_MASKED (REGISTERS_BASE + 0x04A0)
104/*1150 spec calls this HINT_STS_RAW*/
105#define HINT_STS_ND (REGISTERS_BASE + 0x04B0)
106#define HINT_STS_CLR (REGISTERS_BASE + 0x04A4)
107#define HINT_ACK (REGISTERS_BASE + 0x04A8)
108#define HINT_TRIG (REGISTERS_BASE + 0x04AC)
109
110/* Device Configuration registers*/
111#define SOR_CFG (REGISTERS_BASE + 0x0800)
112#define ECPU_CTRL (REGISTERS_BASE + 0x0804)
113#define HI_CFG (REGISTERS_BASE + 0x0808)
114#define EE_START (REGISTERS_BASE + 0x080C)
115
116#define CHIP_ID_B (REGISTERS_BASE + 0x5674)
117
118#define CHIP_ID_1251_PG10 (0x7010101)
119#define CHIP_ID_1251_PG11 (0x7020101)
120#define CHIP_ID_1251_PG12 (0x7030101)
121
122#define ENABLE (REGISTERS_BASE + 0x5450)
123
124/* Power Management registers */
125#define ELP_CFG_MODE (REGISTERS_BASE + 0x5804)
126#define ELP_CMD (REGISTERS_BASE + 0x5808)
127#define PLL_CAL_TIME (REGISTERS_BASE + 0x5810)
128#define CLK_REQ_TIME (REGISTERS_BASE + 0x5814)
129#define CLK_BUF_TIME (REGISTERS_BASE + 0x5818)
130
131#define CFG_PLL_SYNC_CNT (REGISTERS_BASE + 0x5820)
132
133/* Scratch Pad registers*/
134#define SCR_PAD0 (REGISTERS_BASE + 0x5608)
135#define SCR_PAD1 (REGISTERS_BASE + 0x560C)
136#define SCR_PAD2 (REGISTERS_BASE + 0x5610)
137#define SCR_PAD3 (REGISTERS_BASE + 0x5614)
138#define SCR_PAD4 (REGISTERS_BASE + 0x5618)
139#define SCR_PAD4_SET (REGISTERS_BASE + 0x561C)
140#define SCR_PAD4_CLR (REGISTERS_BASE + 0x5620)
141#define SCR_PAD5 (REGISTERS_BASE + 0x5624)
142#define SCR_PAD5_SET (REGISTERS_BASE + 0x5628)
143#define SCR_PAD5_CLR (REGISTERS_BASE + 0x562C)
144#define SCR_PAD6 (REGISTERS_BASE + 0x5630)
145#define SCR_PAD7 (REGISTERS_BASE + 0x5634)
146#define SCR_PAD8 (REGISTERS_BASE + 0x5638)
147#define SCR_PAD9 (REGISTERS_BASE + 0x563C)
148
149/* Spare registers*/
150#define SPARE_A1 (REGISTERS_BASE + 0x0994)
151#define SPARE_A2 (REGISTERS_BASE + 0x0998)
152#define SPARE_A3 (REGISTERS_BASE + 0x099C)
153#define SPARE_A4 (REGISTERS_BASE + 0x09A0)
154#define SPARE_A5 (REGISTERS_BASE + 0x09A4)
155#define SPARE_A6 (REGISTERS_BASE + 0x09A8)
156#define SPARE_A7 (REGISTERS_BASE + 0x09AC)
157#define SPARE_A8 (REGISTERS_BASE + 0x09B0)
158#define SPARE_B1 (REGISTERS_BASE + 0x5420)
159#define SPARE_B2 (REGISTERS_BASE + 0x5424)
160#define SPARE_B3 (REGISTERS_BASE + 0x5428)
161#define SPARE_B4 (REGISTERS_BASE + 0x542C)
162#define SPARE_B5 (REGISTERS_BASE + 0x5430)
163#define SPARE_B6 (REGISTERS_BASE + 0x5434)
164#define SPARE_B7 (REGISTERS_BASE + 0x5438)
165#define SPARE_B8 (REGISTERS_BASE + 0x543C)
166
167enum wl12xx_acx_int_reg {
168 ACX_REG_INTERRUPT_TRIG,
169 ACX_REG_INTERRUPT_TRIG_H,
170
171/*=============================================
172 Host Interrupt Mask Register - 32bit (RW)
173 ------------------------------------------
174 Setting a bit in this register masks the
175 corresponding interrupt to the host.
176 0 - RX0 - Rx first dubble buffer Data Interrupt
177 1 - TXD - Tx Data Interrupt
178 2 - TXXFR - Tx Transfer Interrupt
179 3 - RX1 - Rx second dubble buffer Data Interrupt
180 4 - RXXFR - Rx Transfer Interrupt
181 5 - EVENT_A - Event Mailbox interrupt
182 6 - EVENT_B - Event Mailbox interrupt
183 7 - WNONHST - Wake On Host Interrupt
184 8 - TRACE_A - Debug Trace interrupt
185 9 - TRACE_B - Debug Trace interrupt
186 10 - CDCMP - Command Complete Interrupt
187 11 -
188 12 -
189 13 -
190 14 - ICOMP - Initialization Complete Interrupt
191 16 - SG SE - Soft Gemini - Sense enable interrupt
192 17 - SG SD - Soft Gemini - Sense disable interrupt
193 18 - -
194 19 - -
195 20 - -
196 21- -
197 Default: 0x0001
198*==============================================*/
199 ACX_REG_INTERRUPT_MASK,
200
201/*=============================================
202 Host Interrupt Mask Set 16bit, (Write only)
203 ------------------------------------------
204 Setting a bit in this register sets
205 the corresponding bin in ACX_HINT_MASK register
206 without effecting the mask
207 state of other bits (0 = no effect).
208==============================================*/
209 ACX_REG_HINT_MASK_SET,
210
211/*=============================================
212 Host Interrupt Mask Clear 16bit,(Write only)
213 ------------------------------------------
214 Setting a bit in this register clears
215 the corresponding bin in ACX_HINT_MASK register
216 without effecting the mask
217 state of other bits (0 = no effect).
218=============================================*/
219 ACX_REG_HINT_MASK_CLR,
220
221/*=============================================
222 Host Interrupt Status Nondestructive Read
223 16bit,(Read only)
224 ------------------------------------------
225 The host can read this register to determine
226 which interrupts are active.
227 Reading this register doesn't
228 effect its content.
229=============================================*/
230 ACX_REG_INTERRUPT_NO_CLEAR,
231
232/*=============================================
233 Host Interrupt Status Clear on Read Register
234 16bit,(Read only)
235 ------------------------------------------
236 The host can read this register to determine
237 which interrupts are active.
238 Reading this register clears it,
239 thus making all interrupts inactive.
240==============================================*/
241 ACX_REG_INTERRUPT_CLEAR,
242
243/*=============================================
244 Host Interrupt Acknowledge Register
245 16bit,(Write only)
246 ------------------------------------------
247 The host can set individual bits in this
248 register to clear (acknowledge) the corresp.
249 interrupt status bits in the HINT_STS_CLR and
250 HINT_STS_ND registers, thus making the
251 assotiated interrupt inactive. (0-no effect)
252==============================================*/
253 ACX_REG_INTERRUPT_ACK,
254
255/*===============================================
256 Host Software Reset - 32bit RW
257 ------------------------------------------
258 [31:1] Reserved
259 0 SOFT_RESET Soft Reset - When this bit is set,
260 it holds the Wlan hardware in a soft reset state.
261 This reset disables all MAC and baseband processor
262 clocks except the CardBus/PCI interface clock.
263 It also initializes all MAC state machines except
264 the host interface. It does not reload the
265 contents of the EEPROM. When this bit is cleared
266 (not self-clearing), the Wlan hardware
267 exits the software reset state.
268===============================================*/
269 ACX_REG_SLV_SOFT_RESET,
270
271/*===============================================
272 EEPROM Burst Read Start - 32bit RW
273 ------------------------------------------
274 [31:1] Reserved
275 0 ACX_EE_START - EEPROM Burst Read Start 0
276 Setting this bit starts a burst read from
277 the external EEPROM.
278 If this bit is set (after reset) before an EEPROM read/write,
279 the burst read starts at EEPROM address 0.
280 Otherwise, it starts at the address
281 following the address of the previous access.
282 TheWlan hardware hardware clears this bit automatically.
283
284 Default: 0x00000000
285*================================================*/
286 ACX_REG_EE_START,
287
288/* Embedded ARM CPU Control */
289
290/*===============================================
291 Halt eCPU - 32bit RW
292 ------------------------------------------
293 0 HALT_ECPU Halt Embedded CPU - This bit is the
294 compliment of bit 1 (MDATA2) in the SOR_CFG register.
295 During a hardware reset, this bit holds
296 the inverse of MDATA2.
297 When downloading firmware from the host,
298 set this bit (pull down MDATA2).
299 The host clears this bit after downloading the firmware into
300 zero-wait-state SSRAM.
301 When loading firmware from Flash, clear this bit (pull up MDATA2)
302 so that the eCPU can run the bootloader code in Flash
303 HALT_ECPU eCPU State
304 --------------------
305 1 halt eCPU
306 0 enable eCPU
307 ===============================================*/
308 ACX_REG_ECPU_CONTROL,
309
310 ACX_REG_TABLE_LEN
311};
312
313#define ACX_SLV_SOFT_RESET_BIT BIT(1)
314#define ACX_REG_EEPROM_START_BIT BIT(1)
315
316/* Command/Information Mailbox Pointers */
317
318/*===============================================
319 Command Mailbox Pointer - 32bit RW
320 ------------------------------------------
321 This register holds the start address of
322 the command mailbox located in the Wlan hardware memory.
323 The host must read this pointer after a reset to
324 find the location of the command mailbox.
325 The Wlan hardware initializes the command mailbox
326 pointer with the default address of the command mailbox.
327 The command mailbox pointer is not valid until after
328 the host receives the Init Complete interrupt from
329 the Wlan hardware.
330 ===============================================*/
331#define REG_COMMAND_MAILBOX_PTR (SCR_PAD0)
332
333/*===============================================
334 Information Mailbox Pointer - 32bit RW
335 ------------------------------------------
336 This register holds the start address of
337 the information mailbox located in the Wlan hardware memory.
338 The host must read this pointer after a reset to find
339 the location of the information mailbox.
340 The Wlan hardware initializes the information mailbox pointer
341 with the default address of the information mailbox.
342 The information mailbox pointer is not valid
343 until after the host receives the Init Complete interrupt from
344 the Wlan hardware.
345 ===============================================*/
346#define REG_EVENT_MAILBOX_PTR (SCR_PAD1)
347
348
349/* Misc */
350
351#define REG_ENABLE_TX_RX (ENABLE)
352/*
353 * Rx configuration (filter) information element
354 * ---------------------------------------------
355 */
356#define REG_RX_CONFIG (RX_CFG)
357#define REG_RX_FILTER (RX_FILTER_CFG)
358
359
360#define RX_CFG_ENABLE_PHY_HEADER_PLCP 0x0002
361
362/* promiscuous - receives all valid frames */
363#define RX_CFG_PROMISCUOUS 0x0008
364
365/* receives frames from any BSSID */
366#define RX_CFG_BSSID 0x0020
367
368/* receives frames destined to any MAC address */
369#define RX_CFG_MAC 0x0010
370
371#define RX_CFG_ENABLE_ONLY_MY_DEST_MAC 0x0010
372#define RX_CFG_ENABLE_ANY_DEST_MAC 0x0000
373#define RX_CFG_ENABLE_ONLY_MY_BSSID 0x0020
374#define RX_CFG_ENABLE_ANY_BSSID 0x0000
375
376/* discards all broadcast frames */
377#define RX_CFG_DISABLE_BCAST 0x0200
378
379#define RX_CFG_ENABLE_ONLY_MY_SSID 0x0400
380#define RX_CFG_ENABLE_RX_CMPLT_FCS_ERROR 0x0800
381#define RX_CFG_COPY_RX_STATUS 0x2000
382#define RX_CFG_TSF 0x10000
383
384#define RX_CONFIG_OPTION_ANY_DST_MY_BSS (RX_CFG_ENABLE_ANY_DEST_MAC | \
385 RX_CFG_ENABLE_ONLY_MY_BSSID)
386
387#define RX_CONFIG_OPTION_MY_DST_ANY_BSS (RX_CFG_ENABLE_ONLY_MY_DEST_MAC\
388 | RX_CFG_ENABLE_ANY_BSSID)
389
390#define RX_CONFIG_OPTION_ANY_DST_ANY_BSS (RX_CFG_ENABLE_ANY_DEST_MAC | \
391 RX_CFG_ENABLE_ANY_BSSID)
392
393#define RX_CONFIG_OPTION_MY_DST_MY_BSS (RX_CFG_ENABLE_ONLY_MY_DEST_MAC\
394 | RX_CFG_ENABLE_ONLY_MY_BSSID)
395
396#define RX_CONFIG_OPTION_FOR_SCAN (RX_CFG_ENABLE_PHY_HEADER_PLCP \
397 | RX_CFG_ENABLE_RX_CMPLT_FCS_ERROR \
398 | RX_CFG_COPY_RX_STATUS | RX_CFG_TSF)
399
400#define RX_CONFIG_OPTION_FOR_MEASUREMENT (RX_CFG_ENABLE_ANY_DEST_MAC)
401
402#define RX_CONFIG_OPTION_FOR_JOIN (RX_CFG_ENABLE_ONLY_MY_BSSID | \
403 RX_CFG_ENABLE_ONLY_MY_DEST_MAC)
404
405#define RX_CONFIG_OPTION_FOR_IBSS_JOIN (RX_CFG_ENABLE_ONLY_MY_SSID | \
406 RX_CFG_ENABLE_ONLY_MY_DEST_MAC)
407
408#define RX_FILTER_OPTION_DEF (CFG_RX_MGMT_EN | CFG_RX_DATA_EN\
409 | CFG_RX_CTL_EN | CFG_RX_BCN_EN\
410 | CFG_RX_AUTH_EN | CFG_RX_ASSOC_EN)
411
412#define RX_FILTER_OPTION_FILTER_ALL 0
413
414#define RX_FILTER_OPTION_DEF_PRSP_BCN (CFG_RX_PRSP_EN | CFG_RX_MGMT_EN\
415 | CFG_RX_RCTS_ACK | CFG_RX_BCN_EN)
416
417#define RX_FILTER_OPTION_JOIN (CFG_RX_MGMT_EN | CFG_RX_DATA_EN\
418 | CFG_RX_BCN_EN | CFG_RX_AUTH_EN\
419 | CFG_RX_ASSOC_EN | CFG_RX_RCTS_ACK\
420 | CFG_RX_PRSP_EN)
421
422
423/*===============================================
424 Phy regs
425 ===============================================*/
426#define ACX_PHY_ADDR_REG SBB_ADDR
427#define ACX_PHY_DATA_REG SBB_DATA
428#define ACX_PHY_CTRL_REG SBB_CTL
429#define ACX_PHY_REG_WR_MASK 0x00000001ul
430#define ACX_PHY_REG_RD_MASK 0x00000002ul
431
432
433/*===============================================
434 EEPROM Read/Write Request 32bit RW
435 ------------------------------------------
436 1 EE_READ - EEPROM Read Request 1 - Setting this bit
437 loads a single byte of data into the EE_DATA
438 register from the EEPROM location specified in
439 the EE_ADDR register.
440 The Wlan hardware hardware clears this bit automatically.
441 EE_DATA is valid when this bit is cleared.
442
443 0 EE_WRITE - EEPROM Write Request - Setting this bit
444 writes a single byte of data from the EE_DATA register into the
445 EEPROM location specified in the EE_ADDR register.
446 The Wlan hardware hardware clears this bit automatically.
447*===============================================*/
448#define ACX_EE_CTL_REG EE_CTL
449#define EE_WRITE 0x00000001ul
450#define EE_READ 0x00000002ul
451
452/*===============================================
453 EEPROM Address - 32bit RW
454 ------------------------------------------
455 This register specifies the address
456 within the EEPROM from/to which to read/write data.
457 ===============================================*/
458#define ACX_EE_ADDR_REG EE_ADDR
459
460/*===============================================
461 EEPROM Data - 32bit RW
462 ------------------------------------------
463 This register either holds the read 8 bits of
464 data from the EEPROM or the write data
465 to be written to the EEPROM.
466 ===============================================*/
467#define ACX_EE_DATA_REG EE_DATA
468
469/*===============================================
470 EEPROM Base Address - 32bit RW
471 ------------------------------------------
472 This register holds the upper nine bits
473 [23:15] of the 24-bit Wlan hardware memory
474 address for burst reads from EEPROM accesses.
475 The EEPROM provides the lower 15 bits of this address.
476 The MSB of the address from the EEPROM is ignored.
477 ===============================================*/
478#define ACX_EE_CFG EE_CFG
479
480/*===============================================
481 GPIO Output Values -32bit, RW
482 ------------------------------------------
483 [31:16] Reserved
484 [15: 0] Specify the output values (at the output driver inputs) for
485 GPIO[15:0], respectively.
486 ===============================================*/
487#define ACX_GPIO_OUT_REG GPIO_OUT
488#define ACX_MAX_GPIO_LINES 15
489
490/*===============================================
491 Contention window -32bit, RW
492 ------------------------------------------
493 [31:26] Reserved
494 [25:16] Max (0x3ff)
495 [15:07] Reserved
496 [06:00] Current contention window value - default is 0x1F
497 ===============================================*/
498#define ACX_CONT_WIND_CFG_REG CONT_WIND_CFG
499#define ACX_CONT_WIND_MIN_MASK 0x0000007f
500#define ACX_CONT_WIND_MAX 0x03ff0000
501
502/*
503 * Indirect slave register/memory registers
504 * ----------------------------------------
505 */
506#define HW_SLAVE_REG_ADDR_REG 0x00000004
507#define HW_SLAVE_REG_DATA_REG 0x00000008
508#define HW_SLAVE_REG_CTRL_REG 0x0000000c
509
510#define SLAVE_AUTO_INC 0x00010000
511#define SLAVE_NO_AUTO_INC 0x00000000
512#define SLAVE_HOST_LITTLE_ENDIAN 0x00000000
513
514#define HW_SLAVE_MEM_ADDR_REG SLV_MEM_ADDR
515#define HW_SLAVE_MEM_DATA_REG SLV_MEM_DATA
516#define HW_SLAVE_MEM_CTRL_REG SLV_MEM_CTL
517#define HW_SLAVE_MEM_ENDIAN_REG SLV_END_CTL
518
519#define HW_FUNC_EVENT_INT_EN 0x8000
520#define HW_FUNC_EVENT_MASK_REG 0x00000034
521
522#define ACX_MAC_TIMESTAMP_REG (MAC_TIMESTAMP)
523
524/*===============================================
525 HI_CFG Interface Configuration Register Values
526 ------------------------------------------
527 ===============================================*/
528#define HI_CFG_UART_ENABLE 0x00000004
529#define HI_CFG_RST232_ENABLE 0x00000008
530#define HI_CFG_CLOCK_REQ_SELECT 0x00000010
531#define HI_CFG_HOST_INT_ENABLE 0x00000020
532#define HI_CFG_VLYNQ_OUTPUT_ENABLE 0x00000040
533#define HI_CFG_HOST_INT_ACTIVE_LOW 0x00000080
534#define HI_CFG_UART_TX_OUT_GPIO_15 0x00000100
535#define HI_CFG_UART_TX_OUT_GPIO_14 0x00000200
536#define HI_CFG_UART_TX_OUT_GPIO_7 0x00000400
537
538/*
539 * NOTE: USE_ACTIVE_HIGH compilation flag should be defined in makefile
540 * for platforms using active high interrupt level
541 */
542#ifdef USE_ACTIVE_HIGH
543#define HI_CFG_DEF_VAL \
544 (HI_CFG_UART_ENABLE | \
545 HI_CFG_RST232_ENABLE | \
546 HI_CFG_CLOCK_REQ_SELECT | \
547 HI_CFG_HOST_INT_ENABLE)
548#else
549#define HI_CFG_DEF_VAL \
550 (HI_CFG_UART_ENABLE | \
551 HI_CFG_RST232_ENABLE | \
552 HI_CFG_CLOCK_REQ_SELECT | \
553 HI_CFG_HOST_INT_ENABLE)
554
555#endif
556
557#define REF_FREQ_19_2 0
558#define REF_FREQ_26_0 1
559#define REF_FREQ_38_4 2
560#define REF_FREQ_40_0 3
561#define REF_FREQ_33_6 4
562#define REF_FREQ_NUM 5
563
564#define LUT_PARAM_INTEGER_DIVIDER 0
565#define LUT_PARAM_FRACTIONAL_DIVIDER 1
566#define LUT_PARAM_ATTN_BB 2
567#define LUT_PARAM_ALPHA_BB 3
568#define LUT_PARAM_STOP_TIME_BB 4
569#define LUT_PARAM_BB_PLL_LOOP_FILTER 5
570#define LUT_PARAM_NUM 6
571
572#define ACX_EEPROMLESS_IND_REG (SCR_PAD4)
573#define USE_EEPROM 0
574#define SOFT_RESET_MAX_TIME 1000000
575#define SOFT_RESET_STALL_TIME 1000
576#define NVS_DATA_BUNDARY_ALIGNMENT 4
577
578
579/* Firmware image load chunk size */
580#define CHUNK_SIZE 512
581
582/* Firmware image header size */
583#define FW_HDR_SIZE 8
584
585#define ECPU_CONTROL_HALT 0x00000101
586
587
588/******************************************************************************
589
590 CHANNELS, BAND & REG DOMAINS definitions
591
592******************************************************************************/
593
594
595enum {
596 RADIO_BAND_2_4GHZ = 0, /* 2.4 Ghz band */
597 RADIO_BAND_5GHZ = 1, /* 5 Ghz band */
598 RADIO_BAND_JAPAN_4_9_GHZ = 2,
599 DEFAULT_BAND = RADIO_BAND_2_4GHZ,
600 INVALID_BAND = 0xFE,
601 MAX_RADIO_BANDS = 0xFF
602};
603
604enum {
605 NO_RATE = 0,
606 RATE_1MBPS = 0x0A,
607 RATE_2MBPS = 0x14,
608 RATE_5_5MBPS = 0x37,
609 RATE_6MBPS = 0x0B,
610 RATE_9MBPS = 0x0F,
611 RATE_11MBPS = 0x6E,
612 RATE_12MBPS = 0x0A,
613 RATE_18MBPS = 0x0E,
614 RATE_22MBPS = 0xDC,
615 RATE_24MBPS = 0x09,
616 RATE_36MBPS = 0x0D,
617 RATE_48MBPS = 0x08,
618 RATE_54MBPS = 0x0C
619};
620
621enum {
622 RATE_INDEX_1MBPS = 0,
623 RATE_INDEX_2MBPS = 1,
624 RATE_INDEX_5_5MBPS = 2,
625 RATE_INDEX_6MBPS = 3,
626 RATE_INDEX_9MBPS = 4,
627 RATE_INDEX_11MBPS = 5,
628 RATE_INDEX_12MBPS = 6,
629 RATE_INDEX_18MBPS = 7,
630 RATE_INDEX_22MBPS = 8,
631 RATE_INDEX_24MBPS = 9,
632 RATE_INDEX_36MBPS = 10,
633 RATE_INDEX_48MBPS = 11,
634 RATE_INDEX_54MBPS = 12,
635 RATE_INDEX_MAX = RATE_INDEX_54MBPS,
636 MAX_RATE_INDEX,
637 INVALID_RATE_INDEX = MAX_RATE_INDEX,
638 RATE_INDEX_ENUM_MAX_SIZE = 0x7FFFFFFF
639};
640
641enum {
642 RATE_MASK_1MBPS = 0x1,
643 RATE_MASK_2MBPS = 0x2,
644 RATE_MASK_5_5MBPS = 0x4,
645 RATE_MASK_11MBPS = 0x20,
646};
647
648#define SHORT_PREAMBLE_BIT BIT(0) /* CCK or Barker depending on the rate */
649#define OFDM_RATE_BIT BIT(6)
650#define PBCC_RATE_BIT BIT(7)
651
652enum {
653 CCK_LONG = 0,
654 CCK_SHORT = SHORT_PREAMBLE_BIT,
655 PBCC_LONG = PBCC_RATE_BIT,
656 PBCC_SHORT = PBCC_RATE_BIT | SHORT_PREAMBLE_BIT,
657 OFDM = OFDM_RATE_BIT
658};
659
660/******************************************************************************
661
662Transmit-Descriptor RATE-SET field definitions...
663
664Define a new "Rate-Set" for TX path that incorporates the
665Rate & Modulation info into a single 16-bit field.
666
667TxdRateSet_t:
668b15 - Indicates Preamble type (1=SHORT, 0=LONG).
669 Notes:
670 Must be LONG (0) for 1Mbps rate.
671 Does not apply (set to 0) for RevG-OFDM rates.
672b14 - Indicates PBCC encoding (1=PBCC, 0=not).
673 Notes:
674 Does not apply (set to 0) for rates 1 and 2 Mbps.
675 Does not apply (set to 0) for RevG-OFDM rates.
676b13 - Unused (set to 0).
677b12-b0 - Supported Rate indicator bits as defined below.
678
679******************************************************************************/
680
681
682#define TNETW1251_CHIP_ID_PG1_0 0x07010101
683#define TNETW1251_CHIP_ID_PG1_1 0x07020101
684#define TNETW1251_CHIP_ID_PG1_2 0x07030101
685
686/*************************************************************************
687
688 Interrupt Trigger Register (Host -> WiLink)
689
690**************************************************************************/
691
692/* Hardware to Embedded CPU Interrupts - first 32-bit register set */
693
694/*
695 * Host Command Interrupt. Setting this bit masks
696 * the interrupt that the host issues to inform
697 * the FW that it has sent a command
698 * to the Wlan hardware Command Mailbox.
699 */
700#define INTR_TRIG_CMD BIT(0)
701
702/*
703 * Host Event Acknowlegde Interrupt. The host
704 * sets this bit to acknowledge that it received
705 * the unsolicited information from the event
706 * mailbox.
707 */
708#define INTR_TRIG_EVENT_ACK BIT(1)
709
710/*
711 * The host sets this bit to inform the Wlan
712 * FW that a TX packet is in the XFER
713 * Buffer #0.
714 */
715#define INTR_TRIG_TX_PROC0 BIT(2)
716
717/*
718 * The host sets this bit to inform the FW
719 * that it read a packet from RX XFER
720 * Buffer #0.
721 */
722#define INTR_TRIG_RX_PROC0 BIT(3)
723
724#define INTR_TRIG_DEBUG_ACK BIT(4)
725
726#define INTR_TRIG_STATE_CHANGED BIT(5)
727
728
729/* Hardware to Embedded CPU Interrupts - second 32-bit register set */
730
731/*
732 * The host sets this bit to inform the FW
733 * that it read a packet from RX XFER
734 * Buffer #1.
735 */
736#define INTR_TRIG_RX_PROC1 BIT(17)
737
738/*
739 * The host sets this bit to inform the Wlan
740 * hardware that a TX packet is in the XFER
741 * Buffer #1.
742 */
743#define INTR_TRIG_TX_PROC1 BIT(18)
744
745#endif
diff --git a/drivers/net/wireless/wl12xx/rx.c b/drivers/net/wireless/wl12xx/rx.c
new file mode 100644
index 000000000000..981ea259eb89
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/rx.c
@@ -0,0 +1,208 @@
1/*
2 * This file is part of wl12xx
3 *
4 * Copyright (c) 1998-2007 Texas Instruments Incorporated
5 * Copyright (C) 2008 Nokia Corporation
6 *
7 * Contact: Kalle Valo <kalle.valo@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#include <linux/skbuff.h>
26#include <net/mac80211.h>
27
28#include "wl12xx.h"
29#include "reg.h"
30#include "spi.h"
31#include "rx.h"
32
33static void wl12xx_rx_header(struct wl12xx *wl,
34 struct wl12xx_rx_descriptor *desc)
35{
36 u32 rx_packet_ring_addr;
37
38 rx_packet_ring_addr = wl->data_path->rx_packet_ring_addr;
39 if (wl->rx_current_buffer)
40 rx_packet_ring_addr += wl->data_path->rx_packet_ring_chunk_size;
41
42 wl12xx_spi_mem_read(wl, rx_packet_ring_addr, desc,
43 sizeof(struct wl12xx_rx_descriptor));
44}
45
46static void wl12xx_rx_status(struct wl12xx *wl,
47 struct wl12xx_rx_descriptor *desc,
48 struct ieee80211_rx_status *status,
49 u8 beacon)
50{
51 memset(status, 0, sizeof(struct ieee80211_rx_status));
52
53 status->band = IEEE80211_BAND_2GHZ;
54 status->mactime = desc->timestamp;
55
56 /*
57 * The rx status timestamp is a 32 bits value while the TSF is a
58 * 64 bits one.
59 * For IBSS merging, TSF is mandatory, so we have to get it
60 * somehow, so we ask for ACX_TSF_INFO.
61 * That could be moved to the get_tsf() hook, but unfortunately,
62 * this one must be atomic, while our SPI routines can sleep.
63 */
64 if ((wl->bss_type == BSS_TYPE_IBSS) && beacon) {
65 u64 mactime;
66 int ret;
67 struct wl12xx_command cmd;
68 struct acx_tsf_info *tsf_info;
69
70 memset(&cmd, 0, sizeof(cmd));
71
72 ret = wl12xx_cmd_interrogate(wl, ACX_TSF_INFO,
73 sizeof(struct acx_tsf_info),
74 &cmd);
75 if (ret < 0) {
76 wl12xx_warning("ACX_FW_REV interrogate failed");
77 return;
78 }
79
80 tsf_info = (struct acx_tsf_info *)&(cmd.parameters);
81
82 mactime = tsf_info->current_tsf_lsb |
83 (tsf_info->current_tsf_msb << 31);
84
85 status->mactime = mactime;
86 }
87
88 status->signal = desc->rssi;
89 status->qual = (desc->rssi - WL12XX_RX_MIN_RSSI) * 100 /
90 (WL12XX_RX_MAX_RSSI - WL12XX_RX_MIN_RSSI);
91 status->qual = min(status->qual, 100);
92 status->qual = max(status->qual, 0);
93
94 /*
95 * FIXME: guessing that snr needs to be divided by two, otherwise
96 * the values don't make any sense
97 */
98 status->noise = desc->rssi - desc->snr / 2;
99
100 status->freq = ieee80211_channel_to_frequency(desc->channel);
101
102 status->flag |= RX_FLAG_TSFT;
103
104 if (desc->flags & RX_DESC_ENCRYPTION_MASK) {
105 status->flag |= RX_FLAG_IV_STRIPPED | RX_FLAG_MMIC_STRIPPED;
106
107 if (likely(!(desc->flags & RX_DESC_DECRYPT_FAIL)))
108 status->flag |= RX_FLAG_DECRYPTED;
109
110 if (unlikely(desc->flags & RX_DESC_MIC_FAIL))
111 status->flag |= RX_FLAG_MMIC_ERROR;
112 }
113
114 if (unlikely(!(desc->flags & RX_DESC_VALID_FCS)))
115 status->flag |= RX_FLAG_FAILED_FCS_CRC;
116
117
118 /* FIXME: set status->rate_idx */
119}
120
121static void wl12xx_rx_body(struct wl12xx *wl,
122 struct wl12xx_rx_descriptor *desc)
123{
124 struct sk_buff *skb;
125 struct ieee80211_rx_status status;
126 u8 *rx_buffer, beacon = 0;
127 u16 length, *fc;
128 u32 curr_id, last_id_inc, rx_packet_ring_addr;
129
130 length = WL12XX_RX_ALIGN(desc->length - PLCP_HEADER_LENGTH);
131 curr_id = (desc->flags & RX_DESC_SEQNUM_MASK) >> RX_DESC_PACKETID_SHIFT;
132 last_id_inc = (wl->rx_last_id + 1) % (RX_MAX_PACKET_ID + 1);
133
134 if (last_id_inc != curr_id) {
135 wl12xx_warning("curr ID:%d, last ID inc:%d",
136 curr_id, last_id_inc);
137 wl->rx_last_id = curr_id;
138 } else {
139 wl->rx_last_id = last_id_inc;
140 }
141
142 rx_packet_ring_addr = wl->data_path->rx_packet_ring_addr +
143 sizeof(struct wl12xx_rx_descriptor) + 20;
144 if (wl->rx_current_buffer)
145 rx_packet_ring_addr += wl->data_path->rx_packet_ring_chunk_size;
146
147 skb = dev_alloc_skb(length);
148 if (!skb) {
149 wl12xx_error("Couldn't allocate RX frame");
150 return;
151 }
152
153 rx_buffer = skb_put(skb, length);
154 wl12xx_spi_mem_read(wl, rx_packet_ring_addr, rx_buffer, length);
155
156 /* The actual lenght doesn't include the target's alignment */
157 skb->len = desc->length - PLCP_HEADER_LENGTH;
158
159 fc = (u16 *)skb->data;
160
161 if ((*fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON)
162 beacon = 1;
163
164 wl12xx_rx_status(wl, desc, &status, beacon);
165
166 wl12xx_debug(DEBUG_RX, "rx skb 0x%p: %d B %s", skb, skb->len,
167 beacon ? "beacon" : "");
168
169 ieee80211_rx(wl->hw, skb, &status);
170}
171
172static void wl12xx_rx_ack(struct wl12xx *wl)
173{
174 u32 data, addr;
175
176 if (wl->rx_current_buffer) {
177 addr = ACX_REG_INTERRUPT_TRIG_H;
178 data = INTR_TRIG_RX_PROC1;
179 } else {
180 addr = ACX_REG_INTERRUPT_TRIG;
181 data = INTR_TRIG_RX_PROC0;
182 }
183
184 wl12xx_reg_write32(wl, addr, data);
185
186 /* Toggle buffer ring */
187 wl->rx_current_buffer = !wl->rx_current_buffer;
188}
189
190
191void wl12xx_rx(struct wl12xx *wl)
192{
193 struct wl12xx_rx_descriptor rx_desc;
194
195 if (wl->state != WL12XX_STATE_ON)
196 return;
197
198 /* We first read the frame's header */
199 wl12xx_rx_header(wl, &rx_desc);
200
201 /* Now we can read the body */
202 wl12xx_rx_body(wl, &rx_desc);
203
204 /* Finally, we need to ACK the RX */
205 wl12xx_rx_ack(wl);
206
207 return;
208}
diff --git a/drivers/net/wireless/wl12xx/rx.h b/drivers/net/wireless/wl12xx/rx.h
new file mode 100644
index 000000000000..8a23fdea5016
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/rx.h
@@ -0,0 +1,122 @@
1/*
2 * This file is part of wl12xx
3 *
4 * Copyright (c) 1998-2007 Texas Instruments Incorporated
5 * Copyright (C) 2008 Nokia Corporation
6 *
7 * Contact: Kalle Valo <kalle.valo@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 __WL12XX_RX_H__
26#define __WL12XX_RX_H__
27
28#include <linux/bitops.h>
29
30/*
31 * RX PATH
32 *
33 * The Rx path uses a double buffer and an rx_contro structure, each located
34 * at a fixed address in the device memory. The host keeps track of which
35 * buffer is available and alternates between them on a per packet basis.
36 * The size of each of the two buffers is large enough to hold the longest
37 * 802.3 packet.
38 * The RX path goes like that:
39 * 1) The target generates an interrupt each time a new packet is received.
40 * There are 2 RX interrupts, one for each buffer.
41 * 2) The host reads the received packet from one of the double buffers.
42 * 3) The host triggers a target interrupt.
43 * 4) The target prepares the next RX packet.
44 */
45
46#define WL12XX_RX_MAX_RSSI -30
47#define WL12XX_RX_MIN_RSSI -95
48
49#define WL12XX_RX_ALIGN_TO 4
50#define WL12XX_RX_ALIGN(len) (((len) + WL12XX_RX_ALIGN_TO - 1) & \
51 ~(WL12XX_RX_ALIGN_TO - 1))
52
53#define SHORT_PREAMBLE_BIT BIT(0)
54#define OFDM_RATE_BIT BIT(6)
55#define PBCC_RATE_BIT BIT(7)
56
57#define PLCP_HEADER_LENGTH 8
58#define RX_DESC_PACKETID_SHIFT 11
59#define RX_MAX_PACKET_ID 3
60
61#define RX_DESC_VALID_FCS 0x0001
62#define RX_DESC_MATCH_RXADDR1 0x0002
63#define RX_DESC_MCAST 0x0004
64#define RX_DESC_STAINTIM 0x0008
65#define RX_DESC_VIRTUAL_BM 0x0010
66#define RX_DESC_BCAST 0x0020
67#define RX_DESC_MATCH_SSID 0x0040
68#define RX_DESC_MATCH_BSSID 0x0080
69#define RX_DESC_ENCRYPTION_MASK 0x0300
70#define RX_DESC_MEASURMENT 0x0400
71#define RX_DESC_SEQNUM_MASK 0x1800
72#define RX_DESC_MIC_FAIL 0x2000
73#define RX_DESC_DECRYPT_FAIL 0x4000
74
75struct wl12xx_rx_descriptor {
76 u32 timestamp; /* In microseconds */
77 u16 length; /* Paylod length, including headers */
78 u16 flags;
79
80 /*
81 * 0 - 802.11
82 * 1 - 802.3
83 * 2 - IP
84 * 3 - Raw Codec
85 */
86 u8 type;
87
88 /*
89 * Recevied Rate:
90 * 0x0A - 1MBPS
91 * 0x14 - 2MBPS
92 * 0x37 - 5_5MBPS
93 * 0x0B - 6MBPS
94 * 0x0F - 9MBPS
95 * 0x6E - 11MBPS
96 * 0x0A - 12MBPS
97 * 0x0E - 18MBPS
98 * 0xDC - 22MBPS
99 * 0x09 - 24MBPS
100 * 0x0D - 36MBPS
101 * 0x08 - 48MBPS
102 * 0x0C - 54MBPS
103 */
104 u8 rate;
105
106 u8 mod_pre; /* Modulation and preamble */
107 u8 channel;
108
109 /*
110 * 0 - 2.4 Ghz
111 * 1 - 5 Ghz
112 */
113 u8 band;
114
115 s8 rssi; /* in dB */
116 u8 rcpi; /* in dB */
117 u8 snr; /* in dB */
118} __attribute__ ((packed));
119
120void wl12xx_rx(struct wl12xx *wl);
121
122#endif
diff --git a/drivers/net/wireless/wl12xx/spi.c b/drivers/net/wireless/wl12xx/spi.c
new file mode 100644
index 000000000000..abdf171a47e7
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/spi.c
@@ -0,0 +1,358 @@
1/*
2 * This file is part of wl12xx
3 *
4 * Copyright (C) 2008 Nokia Corporation
5 *
6 * Contact: Kalle Valo <kalle.valo@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/crc7.h>
26#include <linux/spi/spi.h>
27
28#include "wl12xx.h"
29#include "wl12xx_80211.h"
30#include "reg.h"
31#include "spi.h"
32#include "ps.h"
33
34static int wl12xx_translate_reg_addr(struct wl12xx *wl, int addr)
35{
36 /* If the address is lower than REGISTERS_BASE, it means that this is
37 * a chip-specific register address, so look it up in the registers
38 * table */
39 if (addr < REGISTERS_BASE) {
40 /* Make sure we don't go over the table */
41 if (addr >= ACX_REG_TABLE_LEN) {
42 wl12xx_error("address out of range (%d)", addr);
43 return -EINVAL;
44 }
45 addr = wl->chip.acx_reg_table[addr];
46 }
47
48 return addr - wl->physical_reg_addr + wl->virtual_reg_addr;
49}
50
51static int wl12xx_translate_mem_addr(struct wl12xx *wl, int addr)
52{
53 return addr - wl->physical_mem_addr + wl->virtual_mem_addr;
54}
55
56
57void wl12xx_spi_reset(struct wl12xx *wl)
58{
59 u8 *cmd;
60 struct spi_transfer t;
61 struct spi_message m;
62
63 cmd = kzalloc(WSPI_INIT_CMD_LEN, GFP_KERNEL);
64 if (!cmd) {
65 wl12xx_error("could not allocate cmd for spi reset");
66 return;
67 }
68
69 memset(&t, 0, sizeof(t));
70 spi_message_init(&m);
71
72 memset(cmd, 0xff, WSPI_INIT_CMD_LEN);
73
74 t.tx_buf = cmd;
75 t.len = WSPI_INIT_CMD_LEN;
76 spi_message_add_tail(&t, &m);
77
78 spi_sync(wl->spi, &m);
79
80 wl12xx_dump(DEBUG_SPI, "spi reset -> ", cmd, WSPI_INIT_CMD_LEN);
81}
82
83void wl12xx_spi_init(struct wl12xx *wl)
84{
85 u8 crc[WSPI_INIT_CMD_CRC_LEN], *cmd;
86 struct spi_transfer t;
87 struct spi_message m;
88
89 cmd = kzalloc(WSPI_INIT_CMD_LEN, GFP_KERNEL);
90 if (!cmd) {
91 wl12xx_error("could not allocate cmd for spi init");
92 return;
93 }
94
95 memset(crc, 0, sizeof(crc));
96 memset(&t, 0, sizeof(t));
97 spi_message_init(&m);
98
99 /*
100 * Set WSPI_INIT_COMMAND
101 * the data is being send from the MSB to LSB
102 */
103 cmd[2] = 0xff;
104 cmd[3] = 0xff;
105 cmd[1] = WSPI_INIT_CMD_START | WSPI_INIT_CMD_TX;
106 cmd[0] = 0;
107 cmd[7] = 0;
108 cmd[6] |= HW_ACCESS_WSPI_INIT_CMD_MASK << 3;
109 cmd[6] |= HW_ACCESS_WSPI_FIXED_BUSY_LEN & WSPI_INIT_CMD_FIXEDBUSY_LEN;
110
111 if (HW_ACCESS_WSPI_FIXED_BUSY_LEN == 0)
112 cmd[5] |= WSPI_INIT_CMD_DIS_FIXEDBUSY;
113 else
114 cmd[5] |= WSPI_INIT_CMD_EN_FIXEDBUSY;
115
116 cmd[5] |= WSPI_INIT_CMD_IOD | WSPI_INIT_CMD_IP | WSPI_INIT_CMD_CS
117 | WSPI_INIT_CMD_WSPI | WSPI_INIT_CMD_WS;
118
119 crc[0] = cmd[1];
120 crc[1] = cmd[0];
121 crc[2] = cmd[7];
122 crc[3] = cmd[6];
123 crc[4] = cmd[5];
124
125 cmd[4] |= crc7(0, crc, WSPI_INIT_CMD_CRC_LEN) << 1;
126 cmd[4] |= WSPI_INIT_CMD_END;
127
128 t.tx_buf = cmd;
129 t.len = WSPI_INIT_CMD_LEN;
130 spi_message_add_tail(&t, &m);
131
132 spi_sync(wl->spi, &m);
133
134 wl12xx_dump(DEBUG_SPI, "spi init -> ", cmd, WSPI_INIT_CMD_LEN);
135}
136
137/* Set the SPI partitions to access the chip addresses
138 *
139 * There are two VIRTUAL (SPI) partitions (the memory partition and the
140 * registers partition), which are mapped to two different areas of the
141 * PHYSICAL (hardware) memory. This function also makes other checks to
142 * ensure that the partitions are not overlapping. In the diagram below, the
143 * memory partition comes before the register partition, but the opposite is
144 * also supported.
145 *
146 * PHYSICAL address
147 * space
148 *
149 * | |
150 * ...+----+--> mem_start
151 * VIRTUAL address ... | |
152 * space ... | | [PART_0]
153 * ... | |
154 * 0x00000000 <--+----+... ...+----+--> mem_start + mem_size
155 * | | ... | |
156 * |MEM | ... | |
157 * | | ... | |
158 * part_size <--+----+... | | {unused area)
159 * | | ... | |
160 * |REG | ... | |
161 * part_size | | ... | |
162 * + <--+----+... ...+----+--> reg_start
163 * reg_size ... | |
164 * ... | | [PART_1]
165 * ... | |
166 * ...+----+--> reg_start + reg_size
167 * | |
168 *
169 */
170void wl12xx_set_partition(struct wl12xx *wl,
171 u32 mem_start, u32 mem_size,
172 u32 reg_start, u32 reg_size)
173{
174 u8 tx_buf[sizeof(u32) + 2 * sizeof(struct wl12xx_partition)];
175 struct wl12xx_partition *partition;
176 struct spi_transfer t;
177 struct spi_message m;
178 u32 *cmd;
179 size_t len;
180 int addr;
181
182 spi_message_init(&m);
183 memset(&t, 0, sizeof(t));
184 memset(tx_buf, 0, sizeof(tx_buf));
185
186 cmd = (u32 *) tx_buf;
187 partition = (struct wl12xx_partition *) (tx_buf + sizeof(u32));
188 addr = HW_ACCESS_PART0_SIZE_ADDR;
189 len = 2 * sizeof(struct wl12xx_partition);
190
191 *cmd |= WSPI_CMD_WRITE;
192 *cmd |= (len << WSPI_CMD_BYTE_LENGTH_OFFSET) & WSPI_CMD_BYTE_LENGTH;
193 *cmd |= addr & WSPI_CMD_BYTE_ADDR;
194
195 wl12xx_debug(DEBUG_SPI, "mem_start %08X mem_size %08X",
196 mem_start, mem_size);
197 wl12xx_debug(DEBUG_SPI, "reg_start %08X reg_size %08X",
198 reg_start, reg_size);
199
200 /* Make sure that the two partitions together don't exceed the
201 * address range */
202 if ((mem_size + reg_size) > HW_ACCESS_MEMORY_MAX_RANGE) {
203 wl12xx_debug(DEBUG_SPI, "Total size exceeds maximum virtual"
204 " address range. Truncating partition[0].");
205 mem_size = HW_ACCESS_MEMORY_MAX_RANGE - reg_size;
206 wl12xx_debug(DEBUG_SPI, "mem_start %08X mem_size %08X",
207 mem_start, mem_size);
208 wl12xx_debug(DEBUG_SPI, "reg_start %08X reg_size %08X",
209 reg_start, reg_size);
210 }
211
212 if ((mem_start < reg_start) &&
213 ((mem_start + mem_size) > reg_start)) {
214 /* Guarantee that the memory partition doesn't overlap the
215 * registers partition */
216 wl12xx_debug(DEBUG_SPI, "End of partition[0] is "
217 "overlapping partition[1]. Adjusted.");
218 mem_size = reg_start - mem_start;
219 wl12xx_debug(DEBUG_SPI, "mem_start %08X mem_size %08X",
220 mem_start, mem_size);
221 wl12xx_debug(DEBUG_SPI, "reg_start %08X reg_size %08X",
222 reg_start, reg_size);
223 } else if ((reg_start < mem_start) &&
224 ((reg_start + reg_size) > mem_start)) {
225 /* Guarantee that the register partition doesn't overlap the
226 * memory partition */
227 wl12xx_debug(DEBUG_SPI, "End of partition[1] is"
228 " overlapping partition[0]. Adjusted.");
229 reg_size = mem_start - reg_start;
230 wl12xx_debug(DEBUG_SPI, "mem_start %08X mem_size %08X",
231 mem_start, mem_size);
232 wl12xx_debug(DEBUG_SPI, "reg_start %08X reg_size %08X",
233 reg_start, reg_size);
234 }
235
236 partition[0].start = mem_start;
237 partition[0].size = mem_size;
238 partition[1].start = reg_start;
239 partition[1].size = reg_size;
240
241 wl->physical_mem_addr = mem_start;
242 wl->physical_reg_addr = reg_start;
243
244 wl->virtual_mem_addr = 0;
245 wl->virtual_reg_addr = mem_size;
246
247 t.tx_buf = tx_buf;
248 t.len = sizeof(tx_buf);
249 spi_message_add_tail(&t, &m);
250
251 spi_sync(wl->spi, &m);
252}
253
254void wl12xx_spi_read(struct wl12xx *wl, int addr, void *buf,
255 size_t len)
256{
257 struct spi_transfer t[3];
258 struct spi_message m;
259 char busy_buf[TNETWIF_READ_OFFSET_BYTES];
260 u32 cmd;
261
262 cmd = 0;
263 cmd |= WSPI_CMD_READ;
264 cmd |= (len << WSPI_CMD_BYTE_LENGTH_OFFSET) & WSPI_CMD_BYTE_LENGTH;
265 cmd |= addr & WSPI_CMD_BYTE_ADDR;
266
267 spi_message_init(&m);
268 memset(t, 0, sizeof(t));
269
270 t[0].tx_buf = &cmd;
271 t[0].len = 4;
272 spi_message_add_tail(&t[0], &m);
273
274 /* Busy and non busy words read */
275 t[1].rx_buf = busy_buf;
276 t[1].len = TNETWIF_READ_OFFSET_BYTES;
277 spi_message_add_tail(&t[1], &m);
278
279 t[2].rx_buf = buf;
280 t[2].len = len;
281 spi_message_add_tail(&t[2], &m);
282
283 spi_sync(wl->spi, &m);
284
285 /* FIXME: check busy words */
286
287 wl12xx_dump(DEBUG_SPI, "spi_read cmd -> ", &cmd, sizeof(cmd));
288 wl12xx_dump(DEBUG_SPI, "spi_read buf <- ", buf, len);
289}
290
291void wl12xx_spi_write(struct wl12xx *wl, int addr, void *buf,
292 size_t len)
293{
294 struct spi_transfer t[2];
295 struct spi_message m;
296 u32 cmd;
297
298 cmd = 0;
299 cmd |= WSPI_CMD_WRITE;
300 cmd |= (len << WSPI_CMD_BYTE_LENGTH_OFFSET) & WSPI_CMD_BYTE_LENGTH;
301 cmd |= addr & WSPI_CMD_BYTE_ADDR;
302
303 spi_message_init(&m);
304 memset(t, 0, sizeof(t));
305
306 t[0].tx_buf = &cmd;
307 t[0].len = sizeof(cmd);
308 spi_message_add_tail(&t[0], &m);
309
310 t[1].tx_buf = buf;
311 t[1].len = len;
312 spi_message_add_tail(&t[1], &m);
313
314 spi_sync(wl->spi, &m);
315
316 wl12xx_dump(DEBUG_SPI, "spi_write cmd -> ", &cmd, sizeof(cmd));
317 wl12xx_dump(DEBUG_SPI, "spi_write buf -> ", buf, len);
318}
319
320void wl12xx_spi_mem_read(struct wl12xx *wl, int addr, void *buf,
321 size_t len)
322{
323 int physical;
324
325 physical = wl12xx_translate_mem_addr(wl, addr);
326
327 wl12xx_spi_read(wl, physical, buf, len);
328}
329
330void wl12xx_spi_mem_write(struct wl12xx *wl, int addr, void *buf,
331 size_t len)
332{
333 int physical;
334
335 physical = wl12xx_translate_mem_addr(wl, addr);
336
337 wl12xx_spi_write(wl, physical, buf, len);
338}
339
340u32 wl12xx_mem_read32(struct wl12xx *wl, int addr)
341{
342 return wl12xx_read32(wl, wl12xx_translate_mem_addr(wl, addr));
343}
344
345void wl12xx_mem_write32(struct wl12xx *wl, int addr, u32 val)
346{
347 wl12xx_write32(wl, wl12xx_translate_mem_addr(wl, addr), val);
348}
349
350u32 wl12xx_reg_read32(struct wl12xx *wl, int addr)
351{
352 return wl12xx_read32(wl, wl12xx_translate_reg_addr(wl, addr));
353}
354
355void wl12xx_reg_write32(struct wl12xx *wl, int addr, u32 val)
356{
357 wl12xx_write32(wl, wl12xx_translate_reg_addr(wl, addr), val);
358}
diff --git a/drivers/net/wireless/wl12xx/spi.h b/drivers/net/wireless/wl12xx/spi.h
new file mode 100644
index 000000000000..fd3227e904a8
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/spi.h
@@ -0,0 +1,109 @@
1/*
2 * This file is part of wl12xx
3 *
4 * Copyright (c) 1998-2007 Texas Instruments Incorporated
5 * Copyright (C) 2008 Nokia Corporation
6 *
7 * Contact: Kalle Valo <kalle.valo@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 __WL12XX_SPI_H__
26#define __WL12XX_SPI_H__
27
28#include "cmd.h"
29#include "acx.h"
30#include "reg.h"
31
32#define HW_ACCESS_MEMORY_MAX_RANGE 0x1FFC0
33
34#define HW_ACCESS_PART0_SIZE_ADDR 0x1FFC0
35#define HW_ACCESS_PART0_START_ADDR 0x1FFC4
36#define HW_ACCESS_PART1_SIZE_ADDR 0x1FFC8
37#define HW_ACCESS_PART1_START_ADDR 0x1FFCC
38
39#define HW_ACCESS_REGISTER_SIZE 4
40
41#define HW_ACCESS_PRAM_MAX_RANGE 0x3c000
42
43#define WSPI_CMD_READ 0x40000000
44#define WSPI_CMD_WRITE 0x00000000
45#define WSPI_CMD_FIXED 0x20000000
46#define WSPI_CMD_BYTE_LENGTH 0x1FFE0000
47#define WSPI_CMD_BYTE_LENGTH_OFFSET 17
48#define WSPI_CMD_BYTE_ADDR 0x0001FFFF
49
50#define WSPI_INIT_CMD_CRC_LEN 5
51
52#define WSPI_INIT_CMD_START 0x00
53#define WSPI_INIT_CMD_TX 0x40
54/* the extra bypass bit is sampled by the TNET as '1' */
55#define WSPI_INIT_CMD_BYPASS_BIT 0x80
56#define WSPI_INIT_CMD_FIXEDBUSY_LEN 0x07
57#define WSPI_INIT_CMD_EN_FIXEDBUSY 0x80
58#define WSPI_INIT_CMD_DIS_FIXEDBUSY 0x00
59#define WSPI_INIT_CMD_IOD 0x40
60#define WSPI_INIT_CMD_IP 0x20
61#define WSPI_INIT_CMD_CS 0x10
62#define WSPI_INIT_CMD_WS 0x08
63#define WSPI_INIT_CMD_WSPI 0x01
64#define WSPI_INIT_CMD_END 0x01
65
66#define WSPI_INIT_CMD_LEN 8
67
68#define TNETWIF_READ_OFFSET_BYTES 8
69#define HW_ACCESS_WSPI_FIXED_BUSY_LEN \
70 ((TNETWIF_READ_OFFSET_BYTES - 4) / sizeof(u32))
71#define HW_ACCESS_WSPI_INIT_CMD_MASK 0
72
73
74/* Raw target IO, address is not translated */
75void wl12xx_spi_read(struct wl12xx *wl, int addr, void *buf, size_t len);
76void wl12xx_spi_write(struct wl12xx *wl, int addr, void *buf, size_t len);
77
78/* Memory target IO, address is tranlated to partition 0 */
79void wl12xx_spi_mem_read(struct wl12xx *wl, int addr, void *buf, size_t len);
80void wl12xx_spi_mem_write(struct wl12xx *wl, int addr, void *buf, size_t len);
81u32 wl12xx_mem_read32(struct wl12xx *wl, int addr);
82void wl12xx_mem_write32(struct wl12xx *wl, int addr, u32 val);
83
84/* Registers IO */
85u32 wl12xx_reg_read32(struct wl12xx *wl, int addr);
86void wl12xx_reg_write32(struct wl12xx *wl, int addr, u32 val);
87
88/* INIT and RESET words */
89void wl12xx_spi_reset(struct wl12xx *wl);
90void wl12xx_spi_init(struct wl12xx *wl);
91void wl12xx_set_partition(struct wl12xx *wl,
92 u32 part_start, u32 part_size,
93 u32 reg_start, u32 reg_size);
94
95static inline u32 wl12xx_read32(struct wl12xx *wl, int addr)
96{
97 u32 response;
98
99 wl12xx_spi_read(wl, addr, &response, sizeof(u32));
100
101 return response;
102}
103
104static inline void wl12xx_write32(struct wl12xx *wl, int addr, u32 val)
105{
106 wl12xx_spi_write(wl, addr, &val, sizeof(u32));
107}
108
109#endif /* __WL12XX_SPI_H__ */
diff --git a/drivers/net/wireless/wl12xx/tx.c b/drivers/net/wireless/wl12xx/tx.c
new file mode 100644
index 000000000000..62145e205a8c
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/tx.c
@@ -0,0 +1,557 @@
1/*
2 * This file is part of wl12xx
3 *
4 * Copyright (c) 1998-2007 Texas Instruments Incorporated
5 * Copyright (C) 2008 Nokia Corporation
6 *
7 * Contact: Kalle Valo <kalle.valo@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#include <linux/kernel.h>
26#include <linux/module.h>
27
28#include "wl12xx.h"
29#include "reg.h"
30#include "spi.h"
31#include "tx.h"
32#include "ps.h"
33
34static bool wl12xx_tx_double_buffer_busy(struct wl12xx *wl, u32 data_out_count)
35{
36 int used, data_in_count;
37
38 data_in_count = wl->data_in_count;
39
40 if (data_in_count < data_out_count)
41 /* data_in_count has wrapped */
42 data_in_count += TX_STATUS_DATA_OUT_COUNT_MASK + 1;
43
44 used = data_in_count - data_out_count;
45
46 WARN_ON(used < 0);
47 WARN_ON(used > DP_TX_PACKET_RING_CHUNK_NUM);
48
49 if (used >= DP_TX_PACKET_RING_CHUNK_NUM)
50 return true;
51 else
52 return false;
53}
54
55static int wl12xx_tx_path_status(struct wl12xx *wl)
56{
57 u32 status, addr, data_out_count;
58 bool busy;
59
60 addr = wl->data_path->tx_control_addr;
61 status = wl12xx_mem_read32(wl, addr);
62 data_out_count = status & TX_STATUS_DATA_OUT_COUNT_MASK;
63 busy = wl12xx_tx_double_buffer_busy(wl, data_out_count);
64
65 if (busy)
66 return -EBUSY;
67
68 return 0;
69}
70
71static int wl12xx_tx_id(struct wl12xx *wl, struct sk_buff *skb)
72{
73 int i;
74
75 for (i = 0; i < FW_TX_CMPLT_BLOCK_SIZE; i++)
76 if (wl->tx_frames[i] == NULL) {
77 wl->tx_frames[i] = skb;
78 return i;
79 }
80
81 return -EBUSY;
82}
83
84static void wl12xx_tx_control(struct tx_double_buffer_desc *tx_hdr,
85 struct ieee80211_tx_info *control, u16 fc)
86{
87 *(u16 *)&tx_hdr->control = 0;
88
89 tx_hdr->control.rate_policy = 0;
90
91 /* 802.11 packets */
92 tx_hdr->control.packet_type = 0;
93
94 if (control->flags & IEEE80211_TX_CTL_NO_ACK)
95 tx_hdr->control.ack_policy = 1;
96
97 tx_hdr->control.tx_complete = 1;
98
99 if ((fc & IEEE80211_FTYPE_DATA) &&
100 ((fc & IEEE80211_STYPE_QOS_DATA) ||
101 (fc & IEEE80211_STYPE_QOS_NULLFUNC)))
102 tx_hdr->control.qos = 1;
103}
104
105/* RSN + MIC = 8 + 8 = 16 bytes (worst case - AES). */
106#define MAX_MSDU_SECURITY_LENGTH 16
107#define MAX_MPDU_SECURITY_LENGTH 16
108#define WLAN_QOS_HDR_LEN 26
109#define MAX_MPDU_HEADER_AND_SECURITY (MAX_MPDU_SECURITY_LENGTH + \
110 WLAN_QOS_HDR_LEN)
111#define HW_BLOCK_SIZE 252
112static void wl12xx_tx_frag_block_num(struct tx_double_buffer_desc *tx_hdr)
113{
114 u16 payload_len, frag_threshold, mem_blocks;
115 u16 num_mpdus, mem_blocks_per_frag;
116
117 frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
118 tx_hdr->frag_threshold = cpu_to_le16(frag_threshold);
119
120 payload_len = tx_hdr->length + MAX_MSDU_SECURITY_LENGTH;
121
122 if (payload_len > frag_threshold) {
123 mem_blocks_per_frag =
124 ((frag_threshold + MAX_MPDU_HEADER_AND_SECURITY) /
125 HW_BLOCK_SIZE) + 1;
126 num_mpdus = payload_len / frag_threshold;
127 mem_blocks = num_mpdus * mem_blocks_per_frag;
128 payload_len -= num_mpdus * frag_threshold;
129 num_mpdus++;
130
131 } else {
132 mem_blocks_per_frag = 0;
133 mem_blocks = 0;
134 num_mpdus = 1;
135 }
136
137 mem_blocks += (payload_len / HW_BLOCK_SIZE) + 1;
138
139 if (num_mpdus > 1)
140 mem_blocks += min(num_mpdus, mem_blocks_per_frag);
141
142 tx_hdr->num_mem_blocks = mem_blocks;
143}
144
145static int wl12xx_tx_fill_hdr(struct wl12xx *wl, struct sk_buff *skb,
146 struct ieee80211_tx_info *control)
147{
148 struct tx_double_buffer_desc *tx_hdr;
149 struct ieee80211_rate *rate;
150 int id;
151 u16 fc;
152
153 if (!skb)
154 return -EINVAL;
155
156 id = wl12xx_tx_id(wl, skb);
157 if (id < 0)
158 return id;
159
160 fc = *(u16 *)skb->data;
161 tx_hdr = (struct tx_double_buffer_desc *) skb_push(skb,
162 sizeof(*tx_hdr));
163
164 tx_hdr->length = cpu_to_le16(skb->len - sizeof(*tx_hdr));
165 rate = ieee80211_get_tx_rate(wl->hw, control);
166 tx_hdr->rate = cpu_to_le16(rate->hw_value);
167 tx_hdr->expiry_time = cpu_to_le32(1 << 16);
168 tx_hdr->id = id;
169
170 /* FIXME: how to get the correct queue id? */
171 tx_hdr->xmit_queue = 0;
172
173 wl12xx_tx_control(tx_hdr, control, fc);
174 wl12xx_tx_frag_block_num(tx_hdr);
175
176 return 0;
177}
178
179/* We copy the packet to the target */
180static int wl12xx_tx_send_packet(struct wl12xx *wl, struct sk_buff *skb,
181 struct ieee80211_tx_info *control)
182{
183 struct tx_double_buffer_desc *tx_hdr;
184 int len;
185 u32 addr;
186
187 if (!skb)
188 return -EINVAL;
189
190 tx_hdr = (struct tx_double_buffer_desc *) skb->data;
191
192 if (control->control.hw_key &&
193 control->control.hw_key->alg == ALG_TKIP) {
194 int hdrlen;
195 u16 fc;
196 u8 *pos;
197
198 fc = *(u16 *)(skb->data + sizeof(*tx_hdr));
199 tx_hdr->length += WL12XX_TKIP_IV_SPACE;
200
201 hdrlen = ieee80211_hdrlen(fc);
202
203 pos = skb_push(skb, WL12XX_TKIP_IV_SPACE);
204 memmove(pos, pos + WL12XX_TKIP_IV_SPACE,
205 sizeof(*tx_hdr) + hdrlen);
206 }
207
208 /* Revisit. This is a workaround for getting non-aligned packets.
209 This happens at least with EAPOL packets from the user space.
210 Our DMA requires packets to be aligned on a 4-byte boundary.
211 */
212 if (unlikely((long)skb->data & 0x03)) {
213 int offset = (4 - (long)skb->data) & 0x03;
214 wl12xx_debug(DEBUG_TX, "skb offset %d", offset);
215
216 /* check whether the current skb can be used */
217 if (!skb_cloned(skb) && (skb_tailroom(skb) >= offset)) {
218 unsigned char *src = skb->data;
219
220 /* align the buffer on a 4-byte boundary */
221 skb_reserve(skb, offset);
222 memmove(skb->data, src, skb->len);
223 } else {
224 wl12xx_info("No handler, fixme!");
225 return -EINVAL;
226 }
227 }
228
229 /* Our skb->data at this point includes the HW header */
230 len = WL12XX_TX_ALIGN(skb->len);
231
232 if (wl->data_in_count & 0x1)
233 addr = wl->data_path->tx_packet_ring_addr +
234 wl->data_path->tx_packet_ring_chunk_size;
235 else
236 addr = wl->data_path->tx_packet_ring_addr;
237
238 wl12xx_spi_mem_write(wl, addr, skb->data, len);
239
240 wl12xx_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);
242
243 return 0;
244}
245
246static void wl12xx_tx_trigger(struct wl12xx *wl)
247{
248 u32 data, addr;
249
250 if (wl->data_in_count & 0x1) {
251 addr = ACX_REG_INTERRUPT_TRIG_H;
252 data = INTR_TRIG_TX_PROC1;
253 } else {
254 addr = ACX_REG_INTERRUPT_TRIG;
255 data = INTR_TRIG_TX_PROC0;
256 }
257
258 wl12xx_reg_write32(wl, addr, data);
259
260 /* Bumping data in */
261 wl->data_in_count = (wl->data_in_count + 1) &
262 TX_STATUS_DATA_OUT_COUNT_MASK;
263}
264
265/* caller must hold wl->mutex */
266static int wl12xx_tx_frame(struct wl12xx *wl, struct sk_buff *skb)
267{
268 struct ieee80211_tx_info *info;
269 int ret = 0;
270 u8 idx;
271
272 info = IEEE80211_SKB_CB(skb);
273
274 if (info->control.hw_key) {
275 idx = info->control.hw_key->hw_key_idx;
276 if (unlikely(wl->default_key != idx)) {
277 ret = wl12xx_acx_default_key(wl, idx);
278 if (ret < 0)
279 return ret;
280 }
281 }
282
283 ret = wl12xx_tx_path_status(wl);
284 if (ret < 0)
285 return ret;
286
287 ret = wl12xx_tx_fill_hdr(wl, skb, info);
288 if (ret < 0)
289 return ret;
290
291 ret = wl12xx_tx_send_packet(wl, skb, info);
292 if (ret < 0)
293 return ret;
294
295 wl12xx_tx_trigger(wl);
296
297 return ret;
298}
299
300void wl12xx_tx_work(struct work_struct *work)
301{
302 struct wl12xx *wl = container_of(work, struct wl12xx, tx_work);
303 struct sk_buff *skb;
304 bool woken_up = false;
305 int ret;
306
307 mutex_lock(&wl->mutex);
308
309 if (unlikely(wl->state == WL12XX_STATE_OFF))
310 goto out;
311
312 while ((skb = skb_dequeue(&wl->tx_queue))) {
313 if (!woken_up) {
314 wl12xx_ps_elp_wakeup(wl);
315 woken_up = true;
316 }
317
318 ret = wl12xx_tx_frame(wl, skb);
319 if (ret == -EBUSY) {
320 /* firmware buffer is full, stop queues */
321 wl12xx_debug(DEBUG_TX, "tx_work: fw buffer full, "
322 "stop queues");
323 ieee80211_stop_queues(wl->hw);
324 wl->tx_queue_stopped = true;
325 skb_queue_head(&wl->tx_queue, skb);
326 goto out;
327 } else if (ret < 0) {
328 dev_kfree_skb(skb);
329 goto out;
330 }
331 }
332
333out:
334 if (woken_up)
335 wl12xx_ps_elp_sleep(wl);
336
337 mutex_unlock(&wl->mutex);
338}
339
340static const char *wl12xx_tx_parse_status(u8 status)
341{
342 /* 8 bit status field, one character per bit plus null */
343 static char buf[9];
344 int i = 0;
345
346 memset(buf, 0, sizeof(buf));
347
348 if (status & TX_DMA_ERROR)
349 buf[i++] = 'm';
350 if (status & TX_DISABLED)
351 buf[i++] = 'd';
352 if (status & TX_RETRY_EXCEEDED)
353 buf[i++] = 'r';
354 if (status & TX_TIMEOUT)
355 buf[i++] = 't';
356 if (status & TX_KEY_NOT_FOUND)
357 buf[i++] = 'k';
358 if (status & TX_ENCRYPT_FAIL)
359 buf[i++] = 'e';
360 if (status & TX_UNAVAILABLE_PRIORITY)
361 buf[i++] = 'p';
362
363 /* bit 0 is unused apparently */
364
365 return buf;
366}
367
368static void wl12xx_tx_packet_cb(struct wl12xx *wl,
369 struct tx_result *result)
370{
371 struct ieee80211_tx_info *info;
372 struct sk_buff *skb;
373 int hdrlen, ret;
374 u8 *frame;
375
376 skb = wl->tx_frames[result->id];
377 if (skb == NULL) {
378 wl12xx_error("SKB for packet %d is NULL", result->id);
379 return;
380 }
381
382 info = IEEE80211_SKB_CB(skb);
383
384 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK) &&
385 (result->status == TX_SUCCESS))
386 info->flags |= IEEE80211_TX_STAT_ACK;
387
388 info->status.rates[0].count = result->ack_failures + 1;
389 wl->stats.retry_count += result->ack_failures;
390
391 /*
392 * We have to remove our private TX header before pushing
393 * the skb back to mac80211.
394 */
395 frame = skb_pull(skb, sizeof(struct tx_double_buffer_desc));
396 if (info->control.hw_key &&
397 info->control.hw_key->alg == ALG_TKIP) {
398 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
399 memmove(frame + WL12XX_TKIP_IV_SPACE, frame, hdrlen);
400 skb_pull(skb, WL12XX_TKIP_IV_SPACE);
401 }
402
403 wl12xx_debug(DEBUG_TX, "tx status id %u skb 0x%p failures %u rate 0x%x"
404 " status 0x%x (%s)",
405 result->id, skb, result->ack_failures, result->rate,
406 result->status, wl12xx_tx_parse_status(result->status));
407
408
409 ieee80211_tx_status(wl->hw, skb);
410
411 wl->tx_frames[result->id] = NULL;
412
413 if (wl->tx_queue_stopped) {
414 wl12xx_debug(DEBUG_TX, "cb: queue was stopped");
415
416 skb = skb_dequeue(&wl->tx_queue);
417
418 /* The skb can be NULL because tx_work might have been
419 scheduled before the queue was stopped making the
420 queue empty */
421
422 if (skb) {
423 ret = wl12xx_tx_frame(wl, skb);
424 if (ret == -EBUSY) {
425 /* firmware buffer is still full */
426 wl12xx_debug(DEBUG_TX, "cb: fw buffer "
427 "still full");
428 skb_queue_head(&wl->tx_queue, skb);
429 return;
430 } else if (ret < 0) {
431 dev_kfree_skb(skb);
432 return;
433 }
434 }
435
436 wl12xx_debug(DEBUG_TX, "cb: waking queues");
437 ieee80211_wake_queues(wl->hw);
438 wl->tx_queue_stopped = false;
439 }
440}
441
442/* Called upon reception of a TX complete interrupt */
443void wl12xx_tx_complete(struct wl12xx *wl)
444{
445 int i, result_index, num_complete = 0;
446 struct tx_result result[FW_TX_CMPLT_BLOCK_SIZE], *result_ptr;
447
448 if (unlikely(wl->state != WL12XX_STATE_ON))
449 return;
450
451 /* First we read the result */
452 wl12xx_spi_mem_read(wl, wl->data_path->tx_complete_addr,
453 result, sizeof(result));
454
455 result_index = wl->next_tx_complete;
456
457 for (i = 0; i < ARRAY_SIZE(result); i++) {
458 result_ptr = &result[result_index];
459
460 if (result_ptr->done_1 == 1 &&
461 result_ptr->done_2 == 1) {
462 wl12xx_tx_packet_cb(wl, result_ptr);
463
464 result_ptr->done_1 = 0;
465 result_ptr->done_2 = 0;
466
467 result_index = (result_index + 1) &
468 (FW_TX_CMPLT_BLOCK_SIZE - 1);
469 num_complete++;
470 } else {
471 break;
472 }
473 }
474
475 /* Every completed frame needs to be acknowledged */
476 if (num_complete) {
477 /*
478 * If we've wrapped, we have to clear
479 * the results in 2 steps.
480 */
481 if (result_index > wl->next_tx_complete) {
482 /* Only 1 write is needed */
483 wl12xx_spi_mem_write(wl,
484 wl->data_path->tx_complete_addr +
485 (wl->next_tx_complete *
486 sizeof(struct tx_result)),
487 &result[wl->next_tx_complete],
488 num_complete *
489 sizeof(struct tx_result));
490
491
492 } else if (result_index < wl->next_tx_complete) {
493 /* 2 writes are needed */
494 wl12xx_spi_mem_write(wl,
495 wl->data_path->tx_complete_addr +
496 (wl->next_tx_complete *
497 sizeof(struct tx_result)),
498 &result[wl->next_tx_complete],
499 (FW_TX_CMPLT_BLOCK_SIZE -
500 wl->next_tx_complete) *
501 sizeof(struct tx_result));
502
503 wl12xx_spi_mem_write(wl,
504 wl->data_path->tx_complete_addr,
505 result,
506 (num_complete -
507 FW_TX_CMPLT_BLOCK_SIZE +
508 wl->next_tx_complete) *
509 sizeof(struct tx_result));
510
511 } else {
512 /* We have to write the whole array */
513 wl12xx_spi_mem_write(wl,
514 wl->data_path->tx_complete_addr,
515 result,
516 FW_TX_CMPLT_BLOCK_SIZE *
517 sizeof(struct tx_result));
518 }
519
520 }
521
522 wl->next_tx_complete = result_index;
523}
524
525/* caller must hold wl->mutex */
526void wl12xx_tx_flush(struct wl12xx *wl)
527{
528 int i;
529 struct sk_buff *skb;
530 struct ieee80211_tx_info *info;
531
532 /* TX failure */
533/* control->flags = 0; FIXME */
534
535 while ((skb = skb_dequeue(&wl->tx_queue))) {
536 info = IEEE80211_SKB_CB(skb);
537
538 wl12xx_debug(DEBUG_TX, "flushing skb 0x%p", skb);
539
540 if (!(info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS))
541 continue;
542
543 ieee80211_tx_status(wl->hw, skb);
544 }
545
546 for (i = 0; i < FW_TX_CMPLT_BLOCK_SIZE; i++)
547 if (wl->tx_frames[i] != NULL) {
548 skb = wl->tx_frames[i];
549 info = IEEE80211_SKB_CB(skb);
550
551 if (!(info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS))
552 continue;
553
554 ieee80211_tx_status(wl->hw, skb);
555 wl->tx_frames[i] = NULL;
556 }
557}
diff --git a/drivers/net/wireless/wl12xx/tx.h b/drivers/net/wireless/wl12xx/tx.h
new file mode 100644
index 000000000000..dc82691f4c14
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/tx.h
@@ -0,0 +1,215 @@
1/*
2 * This file is part of wl12xx
3 *
4 * Copyright (c) 1998-2007 Texas Instruments Incorporated
5 * Copyright (C) 2008 Nokia Corporation
6 *
7 * Contact: Kalle Valo <kalle.valo@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 __WL12XX_TX_H__
26#define __WL12XX_TX_H__
27
28#include <linux/bitops.h>
29
30/*
31 *
32 * TX PATH
33 *
34 * The Tx path uses a double buffer and a tx_control structure, each located
35 * at a fixed address in the device's memory. On startup, the host retrieves
36 * the pointers to these addresses. A double buffer allows for continuous data
37 * flow towards the device. The host keeps track of which buffer is available
38 * and alternates between these two buffers on a per packet basis.
39 *
40 * The size of each of the two buffers is large enough to hold the longest
41 * 802.3 packet - maximum size Ethernet packet + header + descriptor.
42 * TX complete indication will be received a-synchronously in a TX done cyclic
43 * buffer which is composed of 16 tx_result descriptors structures and is used
44 * in a cyclic manner.
45 *
46 * The TX (HOST) procedure is as follows:
47 * 1. Read the Tx path status, that will give the data_out_count.
48 * 2. goto 1, if not possible.
49 * i.e. if data_in_count - data_out_count >= HwBuffer size (2 for double
50 * buffer).
51 * 3. Copy the packet (preceded by double_buffer_desc), if possible.
52 * i.e. if data_in_count - data_out_count < HwBuffer size (2 for double
53 * buffer).
54 * 4. increment data_in_count.
55 * 5. Inform the firmware by generating a firmware internal interrupt.
56 * 6. FW will increment data_out_count after it reads the buffer.
57 *
58 * The TX Complete procedure:
59 * 1. To get a TX complete indication the host enables the tx_complete flag in
60 * the TX descriptor Structure.
61 * 2. For each packet with a Tx Complete field set, the firmware adds the
62 * transmit results to the cyclic buffer (txDoneRing) and sets both done_1
63 * and done_2 to 1 to indicate driver ownership.
64 * 3. The firmware sends a Tx Complete interrupt to the host to trigger the
65 * host to process the new data. Note: interrupt will be send per packet if
66 * TX complete indication was requested in tx_control or per crossing
67 * aggregation threshold.
68 * 4. After receiving the Tx Complete interrupt, the host reads the
69 * TxDescriptorDone information in a cyclic manner and clears both done_1
70 * and done_2 fields.
71 *
72 */
73
74#define TX_COMPLETE_REQUIRED_BIT 0x80
75#define TX_STATUS_DATA_OUT_COUNT_MASK 0xf
76#define WL12XX_TX_ALIGN_TO 4
77#define WL12XX_TX_ALIGN(len) (((len) + WL12XX_TX_ALIGN_TO - 1) & \
78 ~(WL12XX_TX_ALIGN_TO - 1))
79#define WL12XX_TKIP_IV_SPACE 4
80
81struct tx_control {
82 /* Rate Policy (class) index */
83 unsigned rate_policy:3;
84
85 /* When set, no ack policy is expected */
86 unsigned ack_policy:1;
87
88 /*
89 * Packet type:
90 * 0 -> 802.11
91 * 1 -> 802.3
92 * 2 -> IP
93 * 3 -> raw codec
94 */
95 unsigned packet_type:2;
96
97 /* If set, this is a QoS-Null or QoS-Data frame */
98 unsigned qos:1;
99
100 /*
101 * If set, the target triggers the tx complete INT
102 * upon frame sending completion.
103 */
104 unsigned tx_complete:1;
105
106 /* 2 bytes padding before packet header */
107 unsigned xfer_pad:1;
108
109 unsigned reserved:7;
110} __attribute__ ((packed));
111
112
113struct tx_double_buffer_desc {
114 /* Length of payload, including headers. */
115 u16 length;
116
117 /*
118 * A bit mask that specifies the initial rate to be used
119 * Possible values are:
120 * 0x0001 - 1Mbits
121 * 0x0002 - 2Mbits
122 * 0x0004 - 5.5Mbits
123 * 0x0008 - 6Mbits
124 * 0x0010 - 9Mbits
125 * 0x0020 - 11Mbits
126 * 0x0040 - 12Mbits
127 * 0x0080 - 18Mbits
128 * 0x0100 - 22Mbits
129 * 0x0200 - 24Mbits
130 * 0x0400 - 36Mbits
131 * 0x0800 - 48Mbits
132 * 0x1000 - 54Mbits
133 */
134 u16 rate;
135
136 /* Time in us that a packet can spend in the target */
137 u32 expiry_time;
138
139 /* index of the TX queue used for this packet */
140 u8 xmit_queue;
141
142 /* Used to identify a packet */
143 u8 id;
144
145 struct tx_control control;
146
147 /*
148 * The FW should cut the packet into fragments
149 * of this size.
150 */
151 u16 frag_threshold;
152
153 /* Numbers of HW queue blocks to be allocated */
154 u8 num_mem_blocks;
155
156 u8 reserved;
157} __attribute__ ((packed));
158
159enum {
160 TX_SUCCESS = 0,
161 TX_DMA_ERROR = BIT(7),
162 TX_DISABLED = BIT(6),
163 TX_RETRY_EXCEEDED = BIT(5),
164 TX_TIMEOUT = BIT(4),
165 TX_KEY_NOT_FOUND = BIT(3),
166 TX_ENCRYPT_FAIL = BIT(2),
167 TX_UNAVAILABLE_PRIORITY = BIT(1),
168};
169
170struct tx_result {
171 /*
172 * Ownership synchronization between the host and
173 * the firmware. If done_1 and done_2 are cleared,
174 * owned by the FW (no info ready).
175 */
176 u8 done_1;
177
178 /* same as double_buffer_desc->id */
179 u8 id;
180
181 /*
182 * Total air access duration consumed by this
183 * packet, including all retries and overheads.
184 */
185 u16 medium_usage;
186
187 /* Total media delay (from 1st EDCA AIFS counter until TX Complete). */
188 u32 medium_delay;
189
190 /* Time between host xfer and tx complete */
191 u32 fw_hnadling_time;
192
193 /* The LS-byte of the last TKIP sequence number. */
194 u8 lsb_seq_num;
195
196 /* Retry count */
197 u8 ack_failures;
198
199 /* At which rate we got a ACK */
200 u16 rate;
201
202 u16 reserved;
203
204 /* TX_* */
205 u8 status;
206
207 /* See done_1 */
208 u8 done_2;
209} __attribute__ ((packed));
210
211void wl12xx_tx_work(struct work_struct *work);
212void wl12xx_tx_complete(struct wl12xx *wl);
213void wl12xx_tx_flush(struct wl12xx *wl);
214
215#endif
diff --git a/drivers/net/wireless/wl12xx/wl1251.c b/drivers/net/wireless/wl12xx/wl1251.c
new file mode 100644
index 000000000000..ce1561a41fa4
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/wl1251.c
@@ -0,0 +1,709 @@
1/*
2 * This file is part of wl12xx
3 *
4 * Copyright (C) 2008-2009 Nokia Corporation
5 *
6 * Contact: Kalle Valo <kalle.valo@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
24#include <linux/kernel.h>
25#include <linux/module.h>
26
27#include "wl1251.h"
28#include "reg.h"
29#include "spi.h"
30#include "boot.h"
31#include "event.h"
32#include "acx.h"
33#include "tx.h"
34#include "rx.h"
35#include "ps.h"
36#include "init.h"
37
38static struct wl12xx_partition_set wl1251_part_table[PART_TABLE_LEN] = {
39 [PART_DOWN] = {
40 .mem = {
41 .start = 0x00000000,
42 .size = 0x00016800
43 },
44 .reg = {
45 .start = REGISTERS_BASE,
46 .size = REGISTERS_DOWN_SIZE
47 },
48 },
49
50 [PART_WORK] = {
51 .mem = {
52 .start = 0x00028000,
53 .size = 0x00014000
54 },
55 .reg = {
56 .start = REGISTERS_BASE,
57 .size = REGISTERS_WORK_SIZE
58 },
59 },
60
61 /* WL1251 doesn't use the DRPW partition, so we don't set it here */
62};
63
64static enum wl12xx_acx_int_reg wl1251_acx_reg_table[ACX_REG_TABLE_LEN] = {
65 [ACX_REG_INTERRUPT_TRIG] = (REGISTERS_BASE + 0x0474),
66 [ACX_REG_INTERRUPT_TRIG_H] = (REGISTERS_BASE + 0x0478),
67 [ACX_REG_INTERRUPT_MASK] = (REGISTERS_BASE + 0x0494),
68 [ACX_REG_HINT_MASK_SET] = (REGISTERS_BASE + 0x0498),
69 [ACX_REG_HINT_MASK_CLR] = (REGISTERS_BASE + 0x049C),
70 [ACX_REG_INTERRUPT_NO_CLEAR] = (REGISTERS_BASE + 0x04B0),
71 [ACX_REG_INTERRUPT_CLEAR] = (REGISTERS_BASE + 0x04A4),
72 [ACX_REG_INTERRUPT_ACK] = (REGISTERS_BASE + 0x04A8),
73 [ACX_REG_SLV_SOFT_RESET] = (REGISTERS_BASE + 0x0000),
74 [ACX_REG_EE_START] = (REGISTERS_BASE + 0x080C),
75 [ACX_REG_ECPU_CONTROL] = (REGISTERS_BASE + 0x0804)
76};
77
78static int wl1251_upload_firmware(struct wl12xx *wl)
79{
80 struct wl12xx_partition_set *p_table = wl->chip.p_table;
81 int addr, chunk_num, partition_limit;
82 size_t fw_data_len;
83 u8 *p;
84
85 /* whal_FwCtrl_LoadFwImageSm() */
86
87 wl12xx_debug(DEBUG_BOOT, "chip id before fw upload: 0x%x",
88 wl12xx_reg_read32(wl, CHIP_ID_B));
89
90 /* 10.0 check firmware length and set partition */
91 fw_data_len = (wl->fw[4] << 24) | (wl->fw[5] << 16) |
92 (wl->fw[6] << 8) | (wl->fw[7]);
93
94 wl12xx_debug(DEBUG_BOOT, "fw_data_len %zu chunk_size %d", fw_data_len,
95 CHUNK_SIZE);
96
97 if ((fw_data_len % 4) != 0) {
98 wl12xx_error("firmware length not multiple of four");
99 return -EIO;
100 }
101
102 wl12xx_set_partition(wl,
103 p_table[PART_DOWN].mem.start,
104 p_table[PART_DOWN].mem.size,
105 p_table[PART_DOWN].reg.start,
106 p_table[PART_DOWN].reg.size);
107
108 /* 10.1 set partition limit and chunk num */
109 chunk_num = 0;
110 partition_limit = p_table[PART_DOWN].mem.size;
111
112 while (chunk_num < fw_data_len / CHUNK_SIZE) {
113 /* 10.2 update partition, if needed */
114 addr = p_table[PART_DOWN].mem.start +
115 (chunk_num + 2) * CHUNK_SIZE;
116 if (addr > partition_limit) {
117 addr = p_table[PART_DOWN].mem.start +
118 chunk_num * CHUNK_SIZE;
119 partition_limit = chunk_num * CHUNK_SIZE +
120 p_table[PART_DOWN].mem.size;
121 wl12xx_set_partition(wl,
122 addr,
123 p_table[PART_DOWN].mem.size,
124 p_table[PART_DOWN].reg.start,
125 p_table[PART_DOWN].reg.size);
126 }
127
128 /* 10.3 upload the chunk */
129 addr = p_table[PART_DOWN].mem.start + chunk_num * CHUNK_SIZE;
130 p = wl->fw + FW_HDR_SIZE + chunk_num * CHUNK_SIZE;
131 wl12xx_debug(DEBUG_BOOT, "uploading fw chunk 0x%p to 0x%x",
132 p, addr);
133 wl12xx_spi_mem_write(wl, addr, p, CHUNK_SIZE);
134
135 chunk_num++;
136 }
137
138 /* 10.4 upload the last chunk */
139 addr = p_table[PART_DOWN].mem.start + chunk_num * CHUNK_SIZE;
140 p = wl->fw + FW_HDR_SIZE + chunk_num * CHUNK_SIZE;
141 wl12xx_debug(DEBUG_BOOT, "uploading fw last chunk (%zu B) 0x%p to 0x%x",
142 fw_data_len % CHUNK_SIZE, p, addr);
143 wl12xx_spi_mem_write(wl, addr, p, fw_data_len % CHUNK_SIZE);
144
145 return 0;
146}
147
148static int wl1251_upload_nvs(struct wl12xx *wl)
149{
150 size_t nvs_len, nvs_bytes_written, burst_len;
151 int nvs_start, i;
152 u32 dest_addr, val;
153 u8 *nvs_ptr, *nvs;
154
155 nvs = wl->nvs;
156 if (nvs == NULL)
157 return -ENODEV;
158
159 nvs_ptr = nvs;
160
161 nvs_len = wl->nvs_len;
162 nvs_start = wl->fw_len;
163
164 /*
165 * Layout before the actual NVS tables:
166 * 1 byte : burst length.
167 * 2 bytes: destination address.
168 * n bytes: data to burst copy.
169 *
170 * This is ended by a 0 length, then the NVS tables.
171 */
172
173 while (nvs_ptr[0]) {
174 burst_len = nvs_ptr[0];
175 dest_addr = (nvs_ptr[1] & 0xfe) | ((u32)(nvs_ptr[2] << 8));
176
177 /* We move our pointer to the data */
178 nvs_ptr += 3;
179
180 for (i = 0; i < burst_len; i++) {
181 val = (nvs_ptr[0] | (nvs_ptr[1] << 8)
182 | (nvs_ptr[2] << 16) | (nvs_ptr[3] << 24));
183
184 wl12xx_debug(DEBUG_BOOT,
185 "nvs burst write 0x%x: 0x%x",
186 dest_addr, val);
187 wl12xx_mem_write32(wl, dest_addr, val);
188
189 nvs_ptr += 4;
190 dest_addr += 4;
191 }
192 }
193
194 /*
195 * We've reached the first zero length, the first NVS table
196 * is 7 bytes further.
197 */
198 nvs_ptr += 7;
199 nvs_len -= nvs_ptr - nvs;
200 nvs_len = ALIGN(nvs_len, 4);
201
202 /* Now we must set the partition correctly */
203 wl12xx_set_partition(wl, nvs_start,
204 wl->chip.p_table[PART_DOWN].mem.size,
205 wl->chip.p_table[PART_DOWN].reg.start,
206 wl->chip.p_table[PART_DOWN].reg.size);
207
208 /* And finally we upload the NVS tables */
209 nvs_bytes_written = 0;
210 while (nvs_bytes_written < nvs_len) {
211 val = (nvs_ptr[0] | (nvs_ptr[1] << 8)
212 | (nvs_ptr[2] << 16) | (nvs_ptr[3] << 24));
213
214 val = cpu_to_le32(val);
215
216 wl12xx_debug(DEBUG_BOOT,
217 "nvs write table 0x%x: 0x%x",
218 nvs_start, val);
219 wl12xx_mem_write32(wl, nvs_start, val);
220
221 nvs_ptr += 4;
222 nvs_bytes_written += 4;
223 nvs_start += 4;
224 }
225
226 return 0;
227}
228
229static int wl1251_boot(struct wl12xx *wl)
230{
231 int ret = 0, minor_minor_e2_ver;
232 u32 tmp, boot_data;
233
234 ret = wl12xx_boot_soft_reset(wl);
235 if (ret < 0)
236 goto out;
237
238 /* 2. start processing NVS file */
239 ret = wl->chip.op_upload_nvs(wl);
240 if (ret < 0)
241 goto out;
242
243 /* write firmware's last address (ie. it's length) to
244 * ACX_EEPROMLESS_IND_REG */
245 wl12xx_reg_write32(wl, ACX_EEPROMLESS_IND_REG, wl->fw_len);
246
247 /* 6. read the EEPROM parameters */
248 tmp = wl12xx_reg_read32(wl, SCR_PAD2);
249
250 /* 7. read bootdata */
251 wl->boot_attr.radio_type = (tmp & 0x0000FF00) >> 8;
252 wl->boot_attr.major = (tmp & 0x00FF0000) >> 16;
253 tmp = wl12xx_reg_read32(wl, SCR_PAD3);
254
255 /* 8. check bootdata and call restart sequence */
256 wl->boot_attr.minor = (tmp & 0x00FF0000) >> 16;
257 minor_minor_e2_ver = (tmp & 0xFF000000) >> 24;
258
259 wl12xx_debug(DEBUG_BOOT, "radioType 0x%x majorE2Ver 0x%x "
260 "minorE2Ver 0x%x minor_minor_e2_ver 0x%x",
261 wl->boot_attr.radio_type, wl->boot_attr.major,
262 wl->boot_attr.minor, minor_minor_e2_ver);
263
264 ret = wl12xx_boot_init_seq(wl);
265 if (ret < 0)
266 goto out;
267
268 /* 9. NVS processing done */
269 boot_data = wl12xx_reg_read32(wl, ACX_REG_ECPU_CONTROL);
270
271 wl12xx_debug(DEBUG_BOOT, "halt boot_data 0x%x", boot_data);
272
273 /* 10. check that ECPU_CONTROL_HALT bits are set in
274 * pWhalBus->uBootData and start uploading firmware
275 */
276 if ((boot_data & ECPU_CONTROL_HALT) == 0) {
277 wl12xx_error("boot failed, ECPU_CONTROL_HALT not set");
278 ret = -EIO;
279 goto out;
280 }
281
282 ret = wl->chip.op_upload_fw(wl);
283 if (ret < 0)
284 goto out;
285
286 /* 10.5 start firmware */
287 ret = wl12xx_boot_run_firmware(wl);
288 if (ret < 0)
289 goto out;
290
291 /* Get and save the firmware version */
292 wl12xx_acx_fw_version(wl, wl->chip.fw_ver, sizeof(wl->chip.fw_ver));
293
294out:
295 return ret;
296}
297
298static int wl1251_mem_cfg(struct wl12xx *wl)
299{
300 struct wl1251_acx_config_memory mem_conf;
301 int ret, i;
302
303 wl12xx_debug(DEBUG_ACX, "wl1251 mem cfg");
304
305 /* memory config */
306 mem_conf.mem_config.num_stations = cpu_to_le16(DEFAULT_NUM_STATIONS);
307 mem_conf.mem_config.rx_mem_block_num = 35;
308 mem_conf.mem_config.tx_min_mem_block_num = 64;
309 mem_conf.mem_config.num_tx_queues = MAX_TX_QUEUES;
310 mem_conf.mem_config.host_if_options = HOSTIF_PKT_RING;
311 mem_conf.mem_config.num_ssid_profiles = 1;
312 mem_conf.mem_config.debug_buffer_size =
313 cpu_to_le16(TRACE_BUFFER_MAX_SIZE);
314
315 /* RX queue config */
316 mem_conf.rx_queue_config.dma_address = 0;
317 mem_conf.rx_queue_config.num_descs = ACX_RX_DESC_DEF;
318 mem_conf.rx_queue_config.priority = DEFAULT_RXQ_PRIORITY;
319 mem_conf.rx_queue_config.type = DEFAULT_RXQ_TYPE;
320
321 /* TX queue config */
322 for (i = 0; i < MAX_TX_QUEUES; i++) {
323 mem_conf.tx_queue_config[i].num_descs = ACX_TX_DESC_DEF;
324 mem_conf.tx_queue_config[i].attributes = i;
325 }
326
327 mem_conf.header.id = ACX_MEM_CFG;
328 mem_conf.header.len = sizeof(struct wl1251_acx_config_memory) -
329 sizeof(struct acx_header);
330 mem_conf.header.len -=
331 (MAX_TX_QUEUE_CONFIGS - mem_conf.mem_config.num_tx_queues) *
332 sizeof(struct wl1251_acx_tx_queue_config);
333
334 ret = wl12xx_cmd_configure(wl, &mem_conf,
335 sizeof(struct wl1251_acx_config_memory));
336 if (ret < 0)
337 wl12xx_warning("wl1251 mem config failed: %d", ret);
338
339 return ret;
340}
341
342static int wl1251_hw_init_mem_config(struct wl12xx *wl)
343{
344 int ret;
345
346 ret = wl1251_mem_cfg(wl);
347 if (ret < 0)
348 return ret;
349
350 wl->target_mem_map = kzalloc(sizeof(struct wl1251_acx_mem_map),
351 GFP_KERNEL);
352 if (!wl->target_mem_map) {
353 wl12xx_error("couldn't allocate target memory map");
354 return -ENOMEM;
355 }
356
357 /* we now ask for the firmware built memory map */
358 ret = wl12xx_acx_mem_map(wl, wl->target_mem_map,
359 sizeof(struct wl1251_acx_mem_map));
360 if (ret < 0) {
361 wl12xx_error("couldn't retrieve firmware memory map");
362 kfree(wl->target_mem_map);
363 wl->target_mem_map = NULL;
364 return ret;
365 }
366
367 return 0;
368}
369
370static void wl1251_set_ecpu_ctrl(struct wl12xx *wl, u32 flag)
371{
372 u32 cpu_ctrl;
373
374 /* 10.5.0 run the firmware (I) */
375 cpu_ctrl = wl12xx_reg_read32(wl, ACX_REG_ECPU_CONTROL);
376
377 /* 10.5.1 run the firmware (II) */
378 cpu_ctrl &= ~flag;
379 wl12xx_reg_write32(wl, ACX_REG_ECPU_CONTROL, cpu_ctrl);
380}
381
382static void wl1251_target_enable_interrupts(struct wl12xx *wl)
383{
384 /* Enable target's interrupts */
385 wl->intr_mask = WL1251_ACX_INTR_RX0_DATA |
386 WL1251_ACX_INTR_RX1_DATA |
387 WL1251_ACX_INTR_TX_RESULT |
388 WL1251_ACX_INTR_EVENT_A |
389 WL1251_ACX_INTR_EVENT_B |
390 WL1251_ACX_INTR_INIT_COMPLETE;
391 wl12xx_boot_target_enable_interrupts(wl);
392}
393
394static void wl1251_irq_work(struct work_struct *work)
395{
396 u32 intr;
397 struct wl12xx *wl =
398 container_of(work, struct wl12xx, irq_work);
399
400 mutex_lock(&wl->mutex);
401
402 wl12xx_debug(DEBUG_IRQ, "IRQ work");
403
404 if (wl->state == WL12XX_STATE_OFF)
405 goto out;
406
407 wl12xx_ps_elp_wakeup(wl);
408
409 wl12xx_reg_write32(wl, ACX_REG_INTERRUPT_MASK, WL1251_ACX_INTR_ALL);
410
411 intr = wl12xx_reg_read32(wl, ACX_REG_INTERRUPT_CLEAR);
412 wl12xx_debug(DEBUG_IRQ, "intr: 0x%x", intr);
413
414 if (wl->data_path) {
415 wl12xx_spi_mem_read(wl, wl->data_path->rx_control_addr,
416 &wl->rx_counter, sizeof(u32));
417
418 /* We handle a frmware bug here */
419 switch ((wl->rx_counter - wl->rx_handled) & 0xf) {
420 case 0:
421 wl12xx_debug(DEBUG_IRQ, "RX: FW and host in sync");
422 intr &= ~WL1251_ACX_INTR_RX0_DATA;
423 intr &= ~WL1251_ACX_INTR_RX1_DATA;
424 break;
425 case 1:
426 wl12xx_debug(DEBUG_IRQ, "RX: FW +1");
427 intr |= WL1251_ACX_INTR_RX0_DATA;
428 intr &= ~WL1251_ACX_INTR_RX1_DATA;
429 break;
430 case 2:
431 wl12xx_debug(DEBUG_IRQ, "RX: FW +2");
432 intr |= WL1251_ACX_INTR_RX0_DATA;
433 intr |= WL1251_ACX_INTR_RX1_DATA;
434 break;
435 default:
436 wl12xx_warning("RX: FW and host out of sync: %d",
437 wl->rx_counter - wl->rx_handled);
438 break;
439 }
440
441 wl->rx_handled = wl->rx_counter;
442
443
444 wl12xx_debug(DEBUG_IRQ, "RX counter: %d", wl->rx_counter);
445 }
446
447 intr &= wl->intr_mask;
448
449 if (intr == 0) {
450 wl12xx_debug(DEBUG_IRQ, "INTR is 0");
451 wl12xx_reg_write32(wl, ACX_REG_INTERRUPT_MASK,
452 ~(wl->intr_mask));
453
454 goto out_sleep;
455 }
456
457 if (intr & WL1251_ACX_INTR_RX0_DATA) {
458 wl12xx_debug(DEBUG_IRQ, "WL1251_ACX_INTR_RX0_DATA");
459 wl12xx_rx(wl);
460 }
461
462 if (intr & WL1251_ACX_INTR_RX1_DATA) {
463 wl12xx_debug(DEBUG_IRQ, "WL1251_ACX_INTR_RX1_DATA");
464 wl12xx_rx(wl);
465 }
466
467 if (intr & WL1251_ACX_INTR_TX_RESULT) {
468 wl12xx_debug(DEBUG_IRQ, "WL1251_ACX_INTR_TX_RESULT");
469 wl12xx_tx_complete(wl);
470 }
471
472 if (intr & (WL1251_ACX_INTR_EVENT_A | WL1251_ACX_INTR_EVENT_B)) {
473 wl12xx_debug(DEBUG_IRQ, "WL1251_ACX_INTR_EVENT (0x%x)", intr);
474 if (intr & WL1251_ACX_INTR_EVENT_A)
475 wl12xx_event_handle(wl, 0);
476 else
477 wl12xx_event_handle(wl, 1);
478 }
479
480 if (intr & WL1251_ACX_INTR_INIT_COMPLETE)
481 wl12xx_debug(DEBUG_IRQ, "WL1251_ACX_INTR_INIT_COMPLETE");
482
483 wl12xx_reg_write32(wl, ACX_REG_INTERRUPT_MASK, ~(wl->intr_mask));
484
485out_sleep:
486 wl12xx_ps_elp_sleep(wl);
487out:
488 mutex_unlock(&wl->mutex);
489}
490
491static int wl1251_hw_init_txq_fill(u8 qid,
492 struct acx_tx_queue_qos_config *config,
493 u32 num_blocks)
494{
495 config->qid = qid;
496
497 switch (qid) {
498 case QOS_AC_BE:
499 config->high_threshold =
500 (QOS_TX_HIGH_BE_DEF * num_blocks) / 100;
501 config->low_threshold =
502 (QOS_TX_LOW_BE_DEF * num_blocks) / 100;
503 break;
504 case QOS_AC_BK:
505 config->high_threshold =
506 (QOS_TX_HIGH_BK_DEF * num_blocks) / 100;
507 config->low_threshold =
508 (QOS_TX_LOW_BK_DEF * num_blocks) / 100;
509 break;
510 case QOS_AC_VI:
511 config->high_threshold =
512 (QOS_TX_HIGH_VI_DEF * num_blocks) / 100;
513 config->low_threshold =
514 (QOS_TX_LOW_VI_DEF * num_blocks) / 100;
515 break;
516 case QOS_AC_VO:
517 config->high_threshold =
518 (QOS_TX_HIGH_VO_DEF * num_blocks) / 100;
519 config->low_threshold =
520 (QOS_TX_LOW_VO_DEF * num_blocks) / 100;
521 break;
522 default:
523 wl12xx_error("Invalid TX queue id: %d", qid);
524 return -EINVAL;
525 }
526
527 return 0;
528}
529
530static int wl1251_hw_init_tx_queue_config(struct wl12xx *wl)
531{
532 struct acx_tx_queue_qos_config config;
533 struct wl1251_acx_mem_map *wl_mem_map = wl->target_mem_map;
534 int ret, i;
535
536 wl12xx_debug(DEBUG_ACX, "acx tx queue config");
537
538 config.header.id = ACX_TX_QUEUE_CFG;
539 config.header.len = sizeof(struct acx_tx_queue_qos_config) -
540 sizeof(struct acx_header);
541
542 for (i = 0; i < MAX_NUM_OF_AC; i++) {
543 ret = wl1251_hw_init_txq_fill(i, &config,
544 wl_mem_map->num_tx_mem_blocks);
545 if (ret < 0)
546 return ret;
547
548 ret = wl12xx_cmd_configure(wl, &config, sizeof(config));
549 if (ret < 0)
550 return ret;
551 }
552
553 return 0;
554}
555
556static int wl1251_hw_init_data_path_config(struct wl12xx *wl)
557{
558 int ret;
559
560 /* asking for the data path parameters */
561 wl->data_path = kzalloc(sizeof(struct acx_data_path_params_resp),
562 GFP_KERNEL);
563 if (!wl->data_path) {
564 wl12xx_error("Couldnt allocate data path parameters");
565 return -ENOMEM;
566 }
567
568 ret = wl12xx_acx_data_path_params(wl, wl->data_path);
569 if (ret < 0) {
570 kfree(wl->data_path);
571 wl->data_path = NULL;
572 return ret;
573 }
574
575 return 0;
576}
577
578static int wl1251_hw_init(struct wl12xx *wl)
579{
580 struct wl1251_acx_mem_map *wl_mem_map;
581 int ret;
582
583 ret = wl12xx_hw_init_hwenc_config(wl);
584 if (ret < 0)
585 return ret;
586
587 /* Template settings */
588 ret = wl12xx_hw_init_templates_config(wl);
589 if (ret < 0)
590 return ret;
591
592 /* Default memory configuration */
593 ret = wl1251_hw_init_mem_config(wl);
594 if (ret < 0)
595 return ret;
596
597 /* Default data path configuration */
598 ret = wl1251_hw_init_data_path_config(wl);
599 if (ret < 0)
600 goto out_free_memmap;
601
602 /* RX config */
603 ret = wl12xx_hw_init_rx_config(wl,
604 RX_CFG_PROMISCUOUS | RX_CFG_TSF,
605 RX_FILTER_OPTION_DEF);
606 /* RX_CONFIG_OPTION_ANY_DST_ANY_BSS,
607 RX_FILTER_OPTION_FILTER_ALL); */
608 if (ret < 0)
609 goto out_free_data_path;
610
611 /* TX queues config */
612 ret = wl1251_hw_init_tx_queue_config(wl);
613 if (ret < 0)
614 goto out_free_data_path;
615
616 /* PHY layer config */
617 ret = wl12xx_hw_init_phy_config(wl);
618 if (ret < 0)
619 goto out_free_data_path;
620
621 /* Beacon filtering */
622 ret = wl12xx_hw_init_beacon_filter(wl);
623 if (ret < 0)
624 goto out_free_data_path;
625
626 /* Bluetooth WLAN coexistence */
627 ret = wl12xx_hw_init_pta(wl);
628 if (ret < 0)
629 goto out_free_data_path;
630
631 /* Energy detection */
632 ret = wl12xx_hw_init_energy_detection(wl);
633 if (ret < 0)
634 goto out_free_data_path;
635
636 /* Beacons and boradcast settings */
637 ret = wl12xx_hw_init_beacon_broadcast(wl);
638 if (ret < 0)
639 goto out_free_data_path;
640
641 /* Enable data path */
642 ret = wl12xx_cmd_data_path(wl, wl->channel, 1);
643 if (ret < 0)
644 goto out_free_data_path;
645
646 /* Default power state */
647 ret = wl12xx_hw_init_power_auth(wl);
648 if (ret < 0)
649 goto out_free_data_path;
650
651 wl_mem_map = wl->target_mem_map;
652 wl12xx_info("%d tx blocks at 0x%x, %d rx blocks at 0x%x",
653 wl_mem_map->num_tx_mem_blocks,
654 wl->data_path->tx_control_addr,
655 wl_mem_map->num_rx_mem_blocks,
656 wl->data_path->rx_control_addr);
657
658 return 0;
659
660 out_free_data_path:
661 kfree(wl->data_path);
662
663 out_free_memmap:
664 kfree(wl->target_mem_map);
665
666 return ret;
667}
668
669static int wl1251_plt_init(struct wl12xx *wl)
670{
671 int ret;
672
673 ret = wl1251_hw_init_mem_config(wl);
674 if (ret < 0)
675 return ret;
676
677 ret = wl12xx_cmd_data_path(wl, wl->channel, 1);
678 if (ret < 0)
679 return ret;
680
681 return 0;
682}
683
684void wl1251_setup(struct wl12xx *wl)
685{
686 /* FIXME: Is it better to use strncpy here or is this ok? */
687 wl->chip.fw_filename = WL1251_FW_NAME;
688 wl->chip.nvs_filename = WL1251_NVS_NAME;
689
690 /* Now we know what chip we're using, so adjust the power on sleep
691 * time accordingly */
692 wl->chip.power_on_sleep = WL1251_POWER_ON_SLEEP;
693
694 wl->chip.intr_cmd_complete = WL1251_ACX_INTR_CMD_COMPLETE;
695 wl->chip.intr_init_complete = WL1251_ACX_INTR_INIT_COMPLETE;
696
697 wl->chip.op_upload_nvs = wl1251_upload_nvs;
698 wl->chip.op_upload_fw = wl1251_upload_firmware;
699 wl->chip.op_boot = wl1251_boot;
700 wl->chip.op_set_ecpu_ctrl = wl1251_set_ecpu_ctrl;
701 wl->chip.op_target_enable_interrupts = wl1251_target_enable_interrupts;
702 wl->chip.op_hw_init = wl1251_hw_init;
703 wl->chip.op_plt_init = wl1251_plt_init;
704
705 wl->chip.p_table = wl1251_part_table;
706 wl->chip.acx_reg_table = wl1251_acx_reg_table;
707
708 INIT_WORK(&wl->irq_work, wl1251_irq_work);
709}
diff --git a/drivers/net/wireless/wl12xx/wl1251.h b/drivers/net/wireless/wl12xx/wl1251.h
new file mode 100644
index 000000000000..1f4a44330394
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/wl1251.h
@@ -0,0 +1,165 @@
1/*
2 * This file is part of wl12xx
3 *
4 * Copyright (C) 2008 Nokia Corporation
5 *
6 * Contact: Kalle Valo <kalle.valo@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 __WL1251_H__
25#define __WL1251_H__
26
27#include <linux/bitops.h>
28
29#include "wl12xx.h"
30#include "acx.h"
31
32#define WL1251_FW_NAME "wl1251-fw.bin"
33#define WL1251_NVS_NAME "wl1251-nvs.bin"
34
35#define WL1251_POWER_ON_SLEEP 10 /* in miliseconds */
36
37void wl1251_setup(struct wl12xx *wl);
38
39
40struct wl1251_acx_memory {
41 __le16 num_stations; /* number of STAs to be supported. */
42 u16 reserved_1;
43
44 /*
45 * Nmber of memory buffers for the RX mem pool.
46 * The actual number may be less if there are
47 * not enough blocks left for the minimum num
48 * of TX ones.
49 */
50 u8 rx_mem_block_num;
51 u8 reserved_2;
52 u8 num_tx_queues; /* From 1 to 16 */
53 u8 host_if_options; /* HOST_IF* */
54 u8 tx_min_mem_block_num;
55 u8 num_ssid_profiles;
56 __le16 debug_buffer_size;
57} __attribute__ ((packed));
58
59
60#define ACX_RX_DESC_MIN 1
61#define ACX_RX_DESC_MAX 127
62#define ACX_RX_DESC_DEF 32
63struct wl1251_acx_rx_queue_config {
64 u8 num_descs;
65 u8 pad;
66 u8 type;
67 u8 priority;
68 __le32 dma_address;
69} __attribute__ ((packed));
70
71#define ACX_TX_DESC_MIN 1
72#define ACX_TX_DESC_MAX 127
73#define ACX_TX_DESC_DEF 16
74struct wl1251_acx_tx_queue_config {
75 u8 num_descs;
76 u8 pad[2];
77 u8 attributes;
78} __attribute__ ((packed));
79
80#define MAX_TX_QUEUE_CONFIGS 5
81#define MAX_TX_QUEUES 4
82struct wl1251_acx_config_memory {
83 struct acx_header header;
84
85 struct wl1251_acx_memory mem_config;
86 struct wl1251_acx_rx_queue_config rx_queue_config;
87 struct wl1251_acx_tx_queue_config tx_queue_config[MAX_TX_QUEUE_CONFIGS];
88} __attribute__ ((packed));
89
90struct wl1251_acx_mem_map {
91 struct acx_header header;
92
93 void *code_start;
94 void *code_end;
95
96 void *wep_defkey_start;
97 void *wep_defkey_end;
98
99 void *sta_table_start;
100 void *sta_table_end;
101
102 void *packet_template_start;
103 void *packet_template_end;
104
105 void *queue_memory_start;
106 void *queue_memory_end;
107
108 void *packet_memory_pool_start;
109 void *packet_memory_pool_end;
110
111 void *debug_buffer1_start;
112 void *debug_buffer1_end;
113
114 void *debug_buffer2_start;
115 void *debug_buffer2_end;
116
117 /* Number of blocks FW allocated for TX packets */
118 u32 num_tx_mem_blocks;
119
120 /* Number of blocks FW allocated for RX packets */
121 u32 num_rx_mem_blocks;
122} __attribute__ ((packed));
123
124/*************************************************************************
125
126 Host Interrupt Register (WiLink -> Host)
127
128**************************************************************************/
129
130/* RX packet is ready in Xfer buffer #0 */
131#define WL1251_ACX_INTR_RX0_DATA BIT(0)
132
133/* TX result(s) are in the TX complete buffer */
134#define WL1251_ACX_INTR_TX_RESULT BIT(1)
135
136/* OBSOLETE */
137#define WL1251_ACX_INTR_TX_XFR BIT(2)
138
139/* RX packet is ready in Xfer buffer #1 */
140#define WL1251_ACX_INTR_RX1_DATA BIT(3)
141
142/* Event was entered to Event MBOX #A */
143#define WL1251_ACX_INTR_EVENT_A BIT(4)
144
145/* Event was entered to Event MBOX #B */
146#define WL1251_ACX_INTR_EVENT_B BIT(5)
147
148/* OBSOLETE */
149#define WL1251_ACX_INTR_WAKE_ON_HOST BIT(6)
150
151/* Trace meassge on MBOX #A */
152#define WL1251_ACX_INTR_TRACE_A BIT(7)
153
154/* Trace meassge on MBOX #B */
155#define WL1251_ACX_INTR_TRACE_B BIT(8)
156
157/* Command processing completion */
158#define WL1251_ACX_INTR_CMD_COMPLETE BIT(9)
159
160/* Init sequence is done */
161#define WL1251_ACX_INTR_INIT_COMPLETE BIT(14)
162
163#define WL1251_ACX_INTR_ALL 0xFFFFFFFF
164
165#endif
diff --git a/drivers/net/wireless/wl12xx/wl12xx.h b/drivers/net/wireless/wl12xx/wl12xx.h
new file mode 100644
index 000000000000..48641437414b
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/wl12xx.h
@@ -0,0 +1,409 @@
1/*
2 * This file is part of wl12xx
3 *
4 * Copyright (c) 1998-2007 Texas Instruments Incorporated
5 * Copyright (C) 2008-2009 Nokia Corporation
6 *
7 * Contact: Kalle Valo <kalle.valo@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 __WL12XX_H__
26#define __WL12XX_H__
27
28#include <linux/mutex.h>
29#include <linux/list.h>
30#include <linux/bitops.h>
31#include <net/mac80211.h>
32
33#define DRIVER_NAME "wl12xx"
34#define DRIVER_PREFIX DRIVER_NAME ": "
35
36enum {
37 DEBUG_NONE = 0,
38 DEBUG_IRQ = BIT(0),
39 DEBUG_SPI = BIT(1),
40 DEBUG_BOOT = BIT(2),
41 DEBUG_MAILBOX = BIT(3),
42 DEBUG_NETLINK = BIT(4),
43 DEBUG_EVENT = BIT(5),
44 DEBUG_TX = BIT(6),
45 DEBUG_RX = BIT(7),
46 DEBUG_SCAN = BIT(8),
47 DEBUG_CRYPT = BIT(9),
48 DEBUG_PSM = BIT(10),
49 DEBUG_MAC80211 = BIT(11),
50 DEBUG_CMD = BIT(12),
51 DEBUG_ACX = BIT(13),
52 DEBUG_ALL = ~0,
53};
54
55#define DEBUG_LEVEL (DEBUG_NONE)
56
57#define DEBUG_DUMP_LIMIT 1024
58
59#define wl12xx_error(fmt, arg...) \
60 printk(KERN_ERR DRIVER_PREFIX "ERROR " fmt "\n", ##arg)
61
62#define wl12xx_warning(fmt, arg...) \
63 printk(KERN_WARNING DRIVER_PREFIX "WARNING " fmt "\n", ##arg)
64
65#define wl12xx_notice(fmt, arg...) \
66 printk(KERN_INFO DRIVER_PREFIX fmt "\n", ##arg)
67
68#define wl12xx_info(fmt, arg...) \
69 printk(KERN_DEBUG DRIVER_PREFIX fmt "\n", ##arg)
70
71#define wl12xx_debug(level, fmt, arg...) \
72 do { \
73 if (level & DEBUG_LEVEL) \
74 printk(KERN_DEBUG DRIVER_PREFIX fmt "\n", ##arg); \
75 } while (0)
76
77#define wl12xx_dump(level, prefix, buf, len) \
78 do { \
79 if (level & DEBUG_LEVEL) \
80 print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
81 DUMP_PREFIX_OFFSET, 16, 1, \
82 buf, \
83 min_t(size_t, len, DEBUG_DUMP_LIMIT), \
84 0); \
85 } while (0)
86
87#define wl12xx_dump_ascii(level, prefix, buf, len) \
88 do { \
89 if (level & DEBUG_LEVEL) \
90 print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
91 DUMP_PREFIX_OFFSET, 16, 1, \
92 buf, \
93 min_t(size_t, len, DEBUG_DUMP_LIMIT), \
94 true); \
95 } while (0)
96
97#define WL12XX_DEFAULT_RX_CONFIG (CFG_UNI_FILTER_EN | \
98 CFG_BSSID_FILTER_EN)
99
100#define WL12XX_DEFAULT_RX_FILTER (CFG_RX_PRSP_EN | \
101 CFG_RX_MGMT_EN | \
102 CFG_RX_DATA_EN | \
103 CFG_RX_CTL_EN | \
104 CFG_RX_BCN_EN | \
105 CFG_RX_AUTH_EN | \
106 CFG_RX_ASSOC_EN)
107
108
109struct boot_attr {
110 u32 radio_type;
111 u8 mac_clock;
112 u8 arm_clock;
113 int firmware_debug;
114 u32 minor;
115 u32 major;
116 u32 bugfix;
117};
118
119enum wl12xx_state {
120 WL12XX_STATE_OFF,
121 WL12XX_STATE_ON,
122 WL12XX_STATE_PLT,
123};
124
125enum wl12xx_partition_type {
126 PART_DOWN,
127 PART_WORK,
128 PART_DRPW,
129
130 PART_TABLE_LEN
131};
132
133struct wl12xx_partition {
134 u32 size;
135 u32 start;
136};
137
138struct wl12xx_partition_set {
139 struct wl12xx_partition mem;
140 struct wl12xx_partition reg;
141};
142
143struct wl12xx;
144
145/* FIXME: I'm not sure about this structure name */
146struct wl12xx_chip {
147 u32 id;
148
149 const char *fw_filename;
150 const char *nvs_filename;
151
152 char fw_ver[21];
153
154 unsigned int power_on_sleep;
155 int intr_cmd_complete;
156 int intr_init_complete;
157
158 int (*op_upload_fw)(struct wl12xx *wl);
159 int (*op_upload_nvs)(struct wl12xx *wl);
160 int (*op_boot)(struct wl12xx *wl);
161 void (*op_set_ecpu_ctrl)(struct wl12xx *wl, u32 flag);
162 void (*op_target_enable_interrupts)(struct wl12xx *wl);
163 int (*op_hw_init)(struct wl12xx *wl);
164 int (*op_plt_init)(struct wl12xx *wl);
165
166 struct wl12xx_partition_set *p_table;
167 enum wl12xx_acx_int_reg *acx_reg_table;
168};
169
170struct wl12xx_stats {
171 struct acx_statistics *fw_stats;
172 unsigned long fw_stats_update;
173
174 unsigned int retry_count;
175 unsigned int excessive_retries;
176};
177
178struct wl12xx_debugfs {
179 struct dentry *rootdir;
180 struct dentry *fw_statistics;
181
182 struct dentry *tx_internal_desc_overflow;
183
184 struct dentry *rx_out_of_mem;
185 struct dentry *rx_hdr_overflow;
186 struct dentry *rx_hw_stuck;
187 struct dentry *rx_dropped;
188 struct dentry *rx_fcs_err;
189 struct dentry *rx_xfr_hint_trig;
190 struct dentry *rx_path_reset;
191 struct dentry *rx_reset_counter;
192
193 struct dentry *dma_rx_requested;
194 struct dentry *dma_rx_errors;
195 struct dentry *dma_tx_requested;
196 struct dentry *dma_tx_errors;
197
198 struct dentry *isr_cmd_cmplt;
199 struct dentry *isr_fiqs;
200 struct dentry *isr_rx_headers;
201 struct dentry *isr_rx_mem_overflow;
202 struct dentry *isr_rx_rdys;
203 struct dentry *isr_irqs;
204 struct dentry *isr_tx_procs;
205 struct dentry *isr_decrypt_done;
206 struct dentry *isr_dma0_done;
207 struct dentry *isr_dma1_done;
208 struct dentry *isr_tx_exch_complete;
209 struct dentry *isr_commands;
210 struct dentry *isr_rx_procs;
211 struct dentry *isr_hw_pm_mode_changes;
212 struct dentry *isr_host_acknowledges;
213 struct dentry *isr_pci_pm;
214 struct dentry *isr_wakeups;
215 struct dentry *isr_low_rssi;
216
217 struct dentry *wep_addr_key_count;
218 struct dentry *wep_default_key_count;
219 /* skipping wep.reserved */
220 struct dentry *wep_key_not_found;
221 struct dentry *wep_decrypt_fail;
222 struct dentry *wep_packets;
223 struct dentry *wep_interrupt;
224
225 struct dentry *pwr_ps_enter;
226 struct dentry *pwr_elp_enter;
227 struct dentry *pwr_missing_bcns;
228 struct dentry *pwr_wake_on_host;
229 struct dentry *pwr_wake_on_timer_exp;
230 struct dentry *pwr_tx_with_ps;
231 struct dentry *pwr_tx_without_ps;
232 struct dentry *pwr_rcvd_beacons;
233 struct dentry *pwr_power_save_off;
234 struct dentry *pwr_enable_ps;
235 struct dentry *pwr_disable_ps;
236 struct dentry *pwr_fix_tsf_ps;
237 /* skipping cont_miss_bcns_spread for now */
238 struct dentry *pwr_rcvd_awake_beacons;
239
240 struct dentry *mic_rx_pkts;
241 struct dentry *mic_calc_failure;
242
243 struct dentry *aes_encrypt_fail;
244 struct dentry *aes_decrypt_fail;
245 struct dentry *aes_encrypt_packets;
246 struct dentry *aes_decrypt_packets;
247 struct dentry *aes_encrypt_interrupt;
248 struct dentry *aes_decrypt_interrupt;
249
250 struct dentry *event_heart_beat;
251 struct dentry *event_calibration;
252 struct dentry *event_rx_mismatch;
253 struct dentry *event_rx_mem_empty;
254 struct dentry *event_rx_pool;
255 struct dentry *event_oom_late;
256 struct dentry *event_phy_transmit_error;
257 struct dentry *event_tx_stuck;
258
259 struct dentry *ps_pspoll_timeouts;
260 struct dentry *ps_upsd_timeouts;
261 struct dentry *ps_upsd_max_sptime;
262 struct dentry *ps_upsd_max_apturn;
263 struct dentry *ps_pspoll_max_apturn;
264 struct dentry *ps_pspoll_utilization;
265 struct dentry *ps_upsd_utilization;
266
267 struct dentry *rxpipe_rx_prep_beacon_drop;
268 struct dentry *rxpipe_descr_host_int_trig_rx_data;
269 struct dentry *rxpipe_beacon_buffer_thres_host_int_trig_rx_data;
270 struct dentry *rxpipe_missed_beacon_host_int_trig_rx_data;
271 struct dentry *rxpipe_tx_xfr_host_int_trig_rx_data;
272
273 struct dentry *tx_queue_len;
274
275 struct dentry *retry_count;
276 struct dentry *excessive_retries;
277};
278
279struct wl12xx {
280 struct ieee80211_hw *hw;
281 bool mac80211_registered;
282
283 struct spi_device *spi;
284
285 void (*set_power)(bool enable);
286 int irq;
287
288 enum wl12xx_state state;
289 struct mutex mutex;
290
291 int physical_mem_addr;
292 int physical_reg_addr;
293 int virtual_mem_addr;
294 int virtual_reg_addr;
295
296 struct wl12xx_chip chip;
297
298 int cmd_box_addr;
299 int event_box_addr;
300 struct boot_attr boot_attr;
301
302 u8 *fw;
303 size_t fw_len;
304 u8 *nvs;
305 size_t nvs_len;
306
307 u8 bssid[ETH_ALEN];
308 u8 mac_addr[ETH_ALEN];
309 u8 bss_type;
310 u8 listen_int;
311 int channel;
312
313 void *target_mem_map;
314 struct acx_data_path_params_resp *data_path;
315
316 /* Number of TX packets transferred to the FW, modulo 16 */
317 u32 data_in_count;
318
319 /* Frames scheduled for transmission, not handled yet */
320 struct sk_buff_head tx_queue;
321 bool tx_queue_stopped;
322
323 struct work_struct tx_work;
324 struct work_struct filter_work;
325
326 /* Pending TX frames */
327 struct sk_buff *tx_frames[16];
328
329 /*
330 * Index pointing to the next TX complete entry
331 * in the cyclic XT complete array we get from
332 * the FW.
333 */
334 u32 next_tx_complete;
335
336 /* FW Rx counter */
337 u32 rx_counter;
338
339 /* Rx frames handled */
340 u32 rx_handled;
341
342 /* Current double buffer */
343 u32 rx_current_buffer;
344 u32 rx_last_id;
345
346 /* The target interrupt mask */
347 u32 intr_mask;
348 struct work_struct irq_work;
349
350 /* The mbox event mask */
351 u32 event_mask;
352
353 /* Mailbox pointers */
354 u32 mbox_ptr[2];
355
356 /* Are we currently scanning */
357 bool scanning;
358
359 /* Our association ID */
360 u16 aid;
361
362 /* Default key (for WEP) */
363 u32 default_key;
364
365 unsigned int tx_mgmt_frm_rate;
366 unsigned int tx_mgmt_frm_mod;
367
368 unsigned int rx_config;
369 unsigned int rx_filter;
370
371 /* is firmware in elp mode */
372 bool elp;
373
374 /* we can be in psm, but not in elp, we have to differentiate */
375 bool psm;
376
377 /* PSM mode requested */
378 bool psm_requested;
379
380 /* in dBm */
381 int power_level;
382
383 struct wl12xx_stats stats;
384 struct wl12xx_debugfs debugfs;
385};
386
387int wl12xx_plt_start(struct wl12xx *wl);
388int wl12xx_plt_stop(struct wl12xx *wl);
389
390#define DEFAULT_HW_GEN_MODULATION_TYPE CCK_LONG /* Long Preamble */
391#define DEFAULT_HW_GEN_TX_RATE RATE_2MBPS
392#define JOIN_TIMEOUT 5000 /* 5000 milliseconds to join */
393
394#define WL12XX_DEFAULT_POWER_LEVEL 20
395
396#define WL12XX_TX_QUEUE_MAX_LENGTH 20
397
398/* Different chips need different sleep times after power on. WL1271 needs
399 * 200ms, WL1251 needs only 10ms. By default we use 200ms, but as soon as we
400 * know the chip ID, we change the sleep value in the wl12xx chip structure,
401 * so in subsequent power ons, we don't waste more time then needed. */
402#define WL12XX_DEFAULT_POWER_ON_SLEEP 200
403
404#define CHIP_ID_1251_PG10 (0x7010101)
405#define CHIP_ID_1251_PG11 (0x7020101)
406#define CHIP_ID_1251_PG12 (0x7030101)
407#define CHIP_ID_1271_PG10 (0x4030101)
408
409#endif
diff --git a/drivers/net/wireless/wl12xx/wl12xx_80211.h b/drivers/net/wireless/wl12xx/wl12xx_80211.h
new file mode 100644
index 000000000000..657c2dbcb7d3
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/wl12xx_80211.h
@@ -0,0 +1,156 @@
1#ifndef __WL12XX_80211_H__
2#define __WL12XX_80211_H__
3
4#include <linux/if_ether.h> /* ETH_ALEN */
5
6/* RATES */
7#define IEEE80211_CCK_RATE_1MB 0x02
8#define IEEE80211_CCK_RATE_2MB 0x04
9#define IEEE80211_CCK_RATE_5MB 0x0B
10#define IEEE80211_CCK_RATE_11MB 0x16
11#define IEEE80211_OFDM_RATE_6MB 0x0C
12#define IEEE80211_OFDM_RATE_9MB 0x12
13#define IEEE80211_OFDM_RATE_12MB 0x18
14#define IEEE80211_OFDM_RATE_18MB 0x24
15#define IEEE80211_OFDM_RATE_24MB 0x30
16#define IEEE80211_OFDM_RATE_36MB 0x48
17#define IEEE80211_OFDM_RATE_48MB 0x60
18#define IEEE80211_OFDM_RATE_54MB 0x6C
19#define IEEE80211_BASIC_RATE_MASK 0x80
20
21#define IEEE80211_CCK_RATE_1MB_MASK (1<<0)
22#define IEEE80211_CCK_RATE_2MB_MASK (1<<1)
23#define IEEE80211_CCK_RATE_5MB_MASK (1<<2)
24#define IEEE80211_CCK_RATE_11MB_MASK (1<<3)
25#define IEEE80211_OFDM_RATE_6MB_MASK (1<<4)
26#define IEEE80211_OFDM_RATE_9MB_MASK (1<<5)
27#define IEEE80211_OFDM_RATE_12MB_MASK (1<<6)
28#define IEEE80211_OFDM_RATE_18MB_MASK (1<<7)
29#define IEEE80211_OFDM_RATE_24MB_MASK (1<<8)
30#define IEEE80211_OFDM_RATE_36MB_MASK (1<<9)
31#define IEEE80211_OFDM_RATE_48MB_MASK (1<<10)
32#define IEEE80211_OFDM_RATE_54MB_MASK (1<<11)
33
34#define IEEE80211_CCK_RATES_MASK 0x0000000F
35#define IEEE80211_CCK_BASIC_RATES_MASK (IEEE80211_CCK_RATE_1MB_MASK | \
36 IEEE80211_CCK_RATE_2MB_MASK)
37#define IEEE80211_CCK_DEFAULT_RATES_MASK (IEEE80211_CCK_BASIC_RATES_MASK | \
38 IEEE80211_CCK_RATE_5MB_MASK | \
39 IEEE80211_CCK_RATE_11MB_MASK)
40
41#define IEEE80211_OFDM_RATES_MASK 0x00000FF0
42#define IEEE80211_OFDM_BASIC_RATES_MASK (IEEE80211_OFDM_RATE_6MB_MASK | \
43 IEEE80211_OFDM_RATE_12MB_MASK | \
44 IEEE80211_OFDM_RATE_24MB_MASK)
45#define IEEE80211_OFDM_DEFAULT_RATES_MASK (IEEE80211_OFDM_BASIC_RATES_MASK | \
46 IEEE80211_OFDM_RATE_9MB_MASK | \
47 IEEE80211_OFDM_RATE_18MB_MASK | \
48 IEEE80211_OFDM_RATE_36MB_MASK | \
49 IEEE80211_OFDM_RATE_48MB_MASK | \
50 IEEE80211_OFDM_RATE_54MB_MASK)
51#define IEEE80211_DEFAULT_RATES_MASK (IEEE80211_OFDM_DEFAULT_RATES_MASK | \
52 IEEE80211_CCK_DEFAULT_RATES_MASK)
53
54
55/* This really should be 8, but not for our firmware */
56#define MAX_SUPPORTED_RATES 32
57#define COUNTRY_STRING_LEN 3
58#define MAX_COUNTRY_TRIPLETS 32
59
60/* Headers */
61struct ieee80211_header {
62 __le16 frame_ctl;
63 __le16 duration_id;
64 u8 da[ETH_ALEN];
65 u8 sa[ETH_ALEN];
66 u8 bssid[ETH_ALEN];
67 __le16 seq_ctl;
68 u8 payload[0];
69} __attribute__ ((packed));
70
71struct wl12xx_ie_header {
72 u8 id;
73 u8 len;
74} __attribute__ ((packed));
75
76/* IEs */
77
78struct wl12xx_ie_ssid {
79 struct wl12xx_ie_header header;
80 char ssid[IW_ESSID_MAX_SIZE];
81} __attribute__ ((packed));
82
83struct wl12xx_ie_rates {
84 struct wl12xx_ie_header header;
85 u8 rates[MAX_SUPPORTED_RATES];
86} __attribute__ ((packed));
87
88struct wl12xx_ie_ds_params {
89 struct wl12xx_ie_header header;
90 u8 channel;
91} __attribute__ ((packed));
92
93struct country_triplet {
94 u8 channel;
95 u8 num_channels;
96 u8 max_tx_power;
97} __attribute__ ((packed));
98
99struct wl12xx_ie_country {
100 struct wl12xx_ie_header header;
101 u8 country_string[COUNTRY_STRING_LEN];
102 struct country_triplet triplets[MAX_COUNTRY_TRIPLETS];
103} __attribute__ ((packed));
104
105
106/* Templates */
107
108struct wl12xx_beacon_template {
109 struct ieee80211_header header;
110 __le32 time_stamp[2];
111 __le16 beacon_interval;
112 __le16 capability;
113 struct wl12xx_ie_ssid ssid;
114 struct wl12xx_ie_rates rates;
115 struct wl12xx_ie_rates ext_rates;
116 struct wl12xx_ie_ds_params ds_params;
117 struct wl12xx_ie_country country;
118} __attribute__ ((packed));
119
120struct wl12xx_null_data_template {
121 struct ieee80211_header header;
122} __attribute__ ((packed));
123
124struct wl12xx_ps_poll_template {
125 u16 fc;
126 u16 aid;
127 u8 bssid[ETH_ALEN];
128 u8 ta[ETH_ALEN];
129} __attribute__ ((packed));
130
131struct wl12xx_qos_null_data_template {
132 struct ieee80211_header header;
133 __le16 qos_ctl;
134} __attribute__ ((packed));
135
136struct wl12xx_probe_req_template {
137 struct ieee80211_header header;
138 struct wl12xx_ie_ssid ssid;
139 struct wl12xx_ie_rates rates;
140 struct wl12xx_ie_rates ext_rates;
141} __attribute__ ((packed));
142
143
144struct wl12xx_probe_resp_template {
145 struct ieee80211_header header;
146 __le32 time_stamp[2];
147 __le16 beacon_interval;
148 __le16 capability;
149 struct wl12xx_ie_ssid ssid;
150 struct wl12xx_ie_rates rates;
151 struct wl12xx_ie_rates ext_rates;
152 struct wl12xx_ie_ds_params ds_params;
153 struct wl12xx_ie_country country;
154} __attribute__ ((packed));
155
156#endif
diff --git a/drivers/net/wireless/zd1211rw/zd_mac.c b/drivers/net/wireless/zd1211rw/zd_mac.c
index c3a51266de20..6bdb1704083b 100644
--- a/drivers/net/wireless/zd1211rw/zd_mac.c
+++ b/drivers/net/wireless/zd1211rw/zd_mac.c
@@ -755,52 +755,6 @@ static int zd_op_config(struct ieee80211_hw *hw, u32 changed)
755 return zd_chip_set_channel(&mac->chip, conf->channel->hw_value); 755 return zd_chip_set_channel(&mac->chip, conf->channel->hw_value);
756} 756}
757 757
758static int zd_op_config_interface(struct ieee80211_hw *hw,
759 struct ieee80211_vif *vif,
760 struct ieee80211_if_conf *conf)
761{
762 struct zd_mac *mac = zd_hw_mac(hw);
763 int associated;
764 int r;
765
766 if (mac->type == NL80211_IFTYPE_MESH_POINT ||
767 mac->type == NL80211_IFTYPE_ADHOC) {
768 associated = true;
769 if (conf->changed & IEEE80211_IFCC_BEACON) {
770 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
771
772 if (!beacon)
773 return -ENOMEM;
774 r = zd_mac_config_beacon(hw, beacon);
775 kfree_skb(beacon);
776
777 if (r < 0)
778 return r;
779 }
780
781 if (conf->changed & IEEE80211_IFCC_BEACON_ENABLED) {
782 u32 interval;
783
784 if (conf->enable_beacon)
785 interval = BCN_MODE_IBSS | hw->conf.beacon_int;
786 else
787 interval = 0;
788
789 r = zd_set_beacon_interval(&mac->chip, interval);
790 if (r < 0)
791 return r;
792 }
793 } else
794 associated = is_valid_ether_addr(conf->bssid);
795
796 spin_lock_irq(&mac->lock);
797 mac->associated = associated;
798 spin_unlock_irq(&mac->lock);
799
800 /* TODO: do hardware bssid filtering */
801 return 0;
802}
803
804static void zd_process_intr(struct work_struct *work) 758static void zd_process_intr(struct work_struct *work)
805{ 759{
806 u16 int_status; 760 u16 int_status;
@@ -923,9 +877,42 @@ static void zd_op_bss_info_changed(struct ieee80211_hw *hw,
923{ 877{
924 struct zd_mac *mac = zd_hw_mac(hw); 878 struct zd_mac *mac = zd_hw_mac(hw);
925 unsigned long flags; 879 unsigned long flags;
880 int associated;
926 881
927 dev_dbg_f(zd_mac_dev(mac), "changes: %x\n", changes); 882 dev_dbg_f(zd_mac_dev(mac), "changes: %x\n", changes);
928 883
884 if (mac->type == NL80211_IFTYPE_MESH_POINT ||
885 mac->type == NL80211_IFTYPE_ADHOC) {
886 associated = true;
887 if (changes & BSS_CHANGED_BEACON) {
888 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
889
890 if (beacon) {
891 zd_mac_config_beacon(hw, beacon);
892 kfree_skb(beacon);
893 }
894 }
895
896 if (changes & BSS_CHANGED_BEACON_ENABLED) {
897 u32 interval;
898
899 if (bss_conf->enable_beacon)
900 interval = BCN_MODE_IBSS |
901 bss_conf->beacon_int;
902 else
903 interval = 0;
904
905 zd_set_beacon_interval(&mac->chip, interval);
906 }
907 } else
908 associated = is_valid_ether_addr(bss_conf->bssid);
909
910 spin_lock_irq(&mac->lock);
911 mac->associated = associated;
912 spin_unlock_irq(&mac->lock);
913
914 /* TODO: do hardware bssid filtering */
915
929 if (changes & BSS_CHANGED_ERP_PREAMBLE) { 916 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
930 spin_lock_irqsave(&mac->lock, flags); 917 spin_lock_irqsave(&mac->lock, flags);
931 mac->short_preamble = bss_conf->use_short_preamble; 918 mac->short_preamble = bss_conf->use_short_preamble;
@@ -952,7 +939,6 @@ static const struct ieee80211_ops zd_ops = {
952 .add_interface = zd_op_add_interface, 939 .add_interface = zd_op_add_interface,
953 .remove_interface = zd_op_remove_interface, 940 .remove_interface = zd_op_remove_interface,
954 .config = zd_op_config, 941 .config = zd_op_config,
955 .config_interface = zd_op_config_interface,
956 .configure_filter = zd_op_configure_filter, 942 .configure_filter = zd_op_configure_filter,
957 .bss_info_changed = zd_op_bss_info_changed, 943 .bss_info_changed = zd_op_bss_info_changed,
958 .get_tsf = zd_op_get_tsf, 944 .get_tsf = zd_op_get_tsf,