aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2008-11-10 16:24:44 -0500
committerDavid S. Miller <davem@davemloft.net>2008-11-10 16:24:44 -0500
commit23779897546c1effb546ff89b89803d9d955d517 (patch)
treed4b5d52b5d716a72755ba018382d4b87eae763a4
parentf574179b63e48f5285468b5ee40f3c480221f708 (diff)
parentc4832467a5c8c2ae96d6dad882be4d4ab9eefad7 (diff)
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-next-2.6
-rw-r--r--drivers/net/ps3_gelic_wireless.c17
-rw-r--r--drivers/net/ps3_gelic_wireless.h4
-rw-r--r--drivers/net/wireless/Makefile9
-rw-r--r--drivers/net/wireless/adm8211.c23
-rw-r--r--drivers/net/wireless/adm8211.h2
-rw-r--r--drivers/net/wireless/airo.c50
-rw-r--r--drivers/net/wireless/ath5k/ath5k.h3
-rw-r--r--drivers/net/wireless/ath5k/base.c12
-rw-r--r--drivers/net/wireless/ath5k/pcu.c184
-rw-r--r--drivers/net/wireless/ath5k/reg.h12
-rw-r--r--drivers/net/wireless/ath9k/Makefile4
-rw-r--r--drivers/net/wireless/ath9k/ani.c854
-rw-r--r--drivers/net/wireless/ath9k/ath9k.h376
-rw-r--r--drivers/net/wireless/ath9k/beacon.c42
-rw-r--r--drivers/net/wireless/ath9k/calib.c930
-rw-r--r--drivers/net/wireless/ath9k/core.c483
-rw-r--r--drivers/net/wireless/ath9k/core.h157
-rw-r--r--drivers/net/wireless/ath9k/eeprom.c1605
-rw-r--r--drivers/net/wireless/ath9k/hw.c8492
-rw-r--r--drivers/net/wireless/ath9k/hw.h2
-rw-r--r--drivers/net/wireless/ath9k/mac.c1031
-rw-r--r--drivers/net/wireless/ath9k/main.c437
-rw-r--r--drivers/net/wireless/ath9k/phy.c10
-rw-r--r--drivers/net/wireless/ath9k/rc.c90
-rw-r--r--drivers/net/wireless/ath9k/recv.c536
-rw-r--r--drivers/net/wireless/ath9k/xmit.c1002
-rw-r--r--drivers/net/wireless/atmel.c70
-rw-r--r--drivers/net/wireless/b43/b43.h1
-rw-r--r--drivers/net/wireless/b43/main.c132
-rw-r--r--drivers/net/wireless/b43legacy/dma.c2
-rw-r--r--drivers/net/wireless/b43legacy/main.c24
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945.h2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-4965.c4
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-5000.c12
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-rs.c6
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-rs.h8
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn.c434
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-commands.h6
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-dev.h6
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-fh.h52
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-scan.c7
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-sta.c2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-tx.c4
-rw-r--r--drivers/net/wireless/iwlwifi/iwl3945-base.c65
-rw-r--r--drivers/net/wireless/libertas/assoc.c18
-rw-r--r--drivers/net/wireless/libertas/cmd.c5
-rw-r--r--drivers/net/wireless/libertas/dev.h7
-rw-r--r--drivers/net/wireless/libertas/main.c39
-rw-r--r--drivers/net/wireless/libertas/persistcfg.c2
-rw-r--r--drivers/net/wireless/libertas/scan.c77
-rw-r--r--drivers/net/wireless/libertas/scan.h4
-rw-r--r--drivers/net/wireless/libertas/types.h5
-rw-r--r--drivers/net/wireless/libertas/wext.c1
-rw-r--r--drivers/net/wireless/libertas_tf/if_usb.c2
-rw-r--r--drivers/net/wireless/mac80211_hwsim.c234
-rw-r--r--drivers/net/wireless/orinoco/Makefile12
-rw-r--r--drivers/net/wireless/orinoco/airport.c (renamed from drivers/net/wireless/airport.c)0
-rw-r--r--drivers/net/wireless/orinoco/hermes.c (renamed from drivers/net/wireless/hermes.c)0
-rw-r--r--drivers/net/wireless/orinoco/hermes.h (renamed from drivers/net/wireless/hermes.h)0
-rw-r--r--drivers/net/wireless/orinoco/hermes_dld.c (renamed from drivers/net/wireless/hermes_dld.c)0
-rw-r--r--drivers/net/wireless/orinoco/hermes_dld.h (renamed from drivers/net/wireless/hermes_dld.h)0
-rw-r--r--drivers/net/wireless/orinoco/hermes_rid.h (renamed from drivers/net/wireless/hermes_rid.h)0
-rw-r--r--drivers/net/wireless/orinoco/orinoco.c (renamed from drivers/net/wireless/orinoco.c)30
-rw-r--r--drivers/net/wireless/orinoco/orinoco.h (renamed from drivers/net/wireless/orinoco.h)0
-rw-r--r--drivers/net/wireless/orinoco/orinoco_cs.c (renamed from drivers/net/wireless/orinoco_cs.c)0
-rw-r--r--drivers/net/wireless/orinoco/orinoco_nortel.c (renamed from drivers/net/wireless/orinoco_nortel.c)0
-rw-r--r--drivers/net/wireless/orinoco/orinoco_pci.c (renamed from drivers/net/wireless/orinoco_pci.c)0
-rw-r--r--drivers/net/wireless/orinoco/orinoco_pci.h (renamed from drivers/net/wireless/orinoco_pci.h)0
-rw-r--r--drivers/net/wireless/orinoco/orinoco_plx.c (renamed from drivers/net/wireless/orinoco_plx.c)0
-rw-r--r--drivers/net/wireless/orinoco/orinoco_tmd.c (renamed from drivers/net/wireless/orinoco_tmd.c)0
-rw-r--r--drivers/net/wireless/orinoco/spectrum_cs.c (renamed from drivers/net/wireless/spectrum_cs.c)0
-rw-r--r--drivers/net/wireless/p54/p54.h1
-rw-r--r--drivers/net/wireless/p54/p54common.c452
-rw-r--r--drivers/net/wireless/p54/p54common.h31
-rw-r--r--drivers/net/wireless/p54/p54pci.c9
-rw-r--r--drivers/net/wireless/p54/p54usb.c23
-rw-r--r--drivers/net/wireless/rndis_wlan.c24
-rw-r--r--drivers/net/wireless/rt2x00/rt2400pci.c190
-rw-r--r--drivers/net/wireless/rt2x00/rt2400pci.h2
-rw-r--r--drivers/net/wireless/rt2x00/rt2500pci.c229
-rw-r--r--drivers/net/wireless/rt2x00/rt2500pci.h2
-rw-r--r--drivers/net/wireless/rt2x00/rt2500usb.c135
-rw-r--r--drivers/net/wireless/rt2x00/rt2500usb.h2
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00.h44
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00config.c164
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00debug.c22
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00debug.h13
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00dev.c16
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00lib.h3
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00mac.c12
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00pci.h8
-rw-r--r--drivers/net/wireless/rt2x00/rt61pci.c254
-rw-r--r--drivers/net/wireless/rt2x00/rt61pci.h2
-rw-r--r--drivers/net/wireless/rt2x00/rt73usb.c239
-rw-r--r--drivers/net/wireless/rt2x00/rt73usb.h2
-rw-r--r--drivers/net/wireless/rtl8187_dev.c5
-rw-r--r--drivers/net/wireless/rtl8187_rtl8225.c383
-rw-r--r--drivers/net/wireless/wl3501.h4
-rw-r--r--drivers/net/wireless/zd1201.c4
-rw-r--r--include/linux/ieee80211.h10
-rw-r--r--include/linux/nl80211.h49
-rw-r--r--include/net/cfg80211.h50
-rw-r--r--include/net/mac80211.h13
-rw-r--r--include/net/wireless.h16
-rw-r--r--net/ieee80211/ieee80211_wx.c4
-rw-r--r--net/mac80211/cfg.c45
-rw-r--r--net/mac80211/ht.c10
-rw-r--r--net/mac80211/ieee80211_i.h3
-rw-r--r--net/mac80211/main.c15
-rw-r--r--net/mac80211/mesh.c2
-rw-r--r--net/mac80211/mesh.h5
-rw-r--r--net/mac80211/mlme.c38
-rw-r--r--net/mac80211/rc80211_minstrel.c2
-rw-r--r--net/mac80211/scan.c2
-rw-r--r--net/mac80211/tx.c1
-rw-r--r--net/mac80211/wext.c16
-rw-r--r--net/wireless/nl80211.c75
-rw-r--r--net/wireless/reg.c192
-rw-r--r--net/wireless/util.c19
119 files changed, 10031 insertions, 10451 deletions
diff --git a/drivers/net/ps3_gelic_wireless.c b/drivers/net/ps3_gelic_wireless.c
index d10dc3ea9c79..ec2314246682 100644
--- a/drivers/net/ps3_gelic_wireless.c
+++ b/drivers/net/ps3_gelic_wireless.c
@@ -30,10 +30,11 @@
30#include <linux/ip.h> 30#include <linux/ip.h>
31#include <linux/tcp.h> 31#include <linux/tcp.h>
32#include <linux/wireless.h> 32#include <linux/wireless.h>
33#include <linux/ieee80211.h>
34#include <linux/if_arp.h>
33#include <linux/ctype.h> 35#include <linux/ctype.h>
34#include <linux/string.h> 36#include <linux/string.h>
35#include <net/iw_handler.h> 37#include <net/iw_handler.h>
36#include <net/ieee80211.h>
37 38
38#include <linux/dma-mapping.h> 39#include <linux/dma-mapping.h>
39#include <net/checksum.h> 40#include <net/checksum.h>
@@ -449,9 +450,9 @@ static size_t gelic_wl_synthesize_ie(u8 *buf,
449 450
450 /* element id */ 451 /* element id */
451 if (rsn) 452 if (rsn)
452 *buf++ = MFIE_TYPE_RSN; 453 *buf++ = WLAN_EID_RSN;
453 else 454 else
454 *buf++ = MFIE_TYPE_GENERIC; 455 *buf++ = WLAN_EID_GENERIC;
455 456
456 /* length filed; set later */ 457 /* length filed; set later */
457 buf++; 458 buf++;
@@ -539,7 +540,7 @@ static void gelic_wl_parse_ie(u8 *data, size_t len,
539 break; 540 break;
540 541
541 switch (item_id) { 542 switch (item_id) {
542 case MFIE_TYPE_GENERIC: 543 case WLAN_EID_GENERIC:
543 if ((OUI_LEN + 1 <= item_len) && 544 if ((OUI_LEN + 1 <= item_len) &&
544 !memcmp(pos, wpa_oui, OUI_LEN) && 545 !memcmp(pos, wpa_oui, OUI_LEN) &&
545 pos[OUI_LEN] == 0x01) { 546 pos[OUI_LEN] == 0x01) {
@@ -547,7 +548,7 @@ static void gelic_wl_parse_ie(u8 *data, size_t len,
547 ie_info->wpa.len = item_len + 2; 548 ie_info->wpa.len = item_len + 2;
548 } 549 }
549 break; 550 break;
550 case MFIE_TYPE_RSN: 551 case WLAN_EID_RSN:
551 ie_info->rsn.data = pos - 2; 552 ie_info->rsn.data = pos - 2;
552 /* length includes the header */ 553 /* length includes the header */
553 ie_info->rsn.len = item_len + 2; 554 ie_info->rsn.len = item_len + 2;
@@ -581,7 +582,7 @@ static char *gelic_wl_translate_scan(struct net_device *netdev,
581 char *tmp; 582 char *tmp;
582 u8 rate; 583 u8 rate;
583 unsigned int i, j, len; 584 unsigned int i, j, len;
584 u8 buf[MAX_WPA_IE_LEN]; 585 u8 buf[64]; /* arbitrary size large enough */
585 586
586 pr_debug("%s: <-\n", __func__); 587 pr_debug("%s: <-\n", __func__);
587 588
@@ -1734,14 +1735,14 @@ static void gelic_wl_scan_complete_event(struct gelic_wl_info *wl)
1734 target->essid_len = strnlen(scan_info->essid, 1735 target->essid_len = strnlen(scan_info->essid,
1735 sizeof(scan_info->essid)); 1736 sizeof(scan_info->essid));
1736 target->rate_len = 0; 1737 target->rate_len = 0;
1737 for (r = 0; r < MAX_RATES_LENGTH; r++) 1738 for (r = 0; r < 12; r++)
1738 if (scan_info->rate[r]) 1739 if (scan_info->rate[r])
1739 target->rate_len++; 1740 target->rate_len++;
1740 if (8 < target->rate_len) 1741 if (8 < target->rate_len)
1741 pr_info("%s: AP returns %d rates\n", __func__, 1742 pr_info("%s: AP returns %d rates\n", __func__,
1742 target->rate_len); 1743 target->rate_len);
1743 target->rate_ext_len = 0; 1744 target->rate_ext_len = 0;
1744 for (r = 0; r < MAX_RATES_EX_LENGTH; r++) 1745 for (r = 0; r < 16; r++)
1745 if (scan_info->ext_rate[r]) 1746 if (scan_info->ext_rate[r])
1746 target->rate_ext_len++; 1747 target->rate_ext_len++;
1747 list_move_tail(&target->list, &wl->network_list); 1748 list_move_tail(&target->list, &wl->network_list);
diff --git a/drivers/net/ps3_gelic_wireless.h b/drivers/net/ps3_gelic_wireless.h
index 5339e0078d18..5b631c6c9775 100644
--- a/drivers/net/ps3_gelic_wireless.h
+++ b/drivers/net/ps3_gelic_wireless.h
@@ -164,8 +164,8 @@ struct gelic_eurus_scan_info {
164 __be16 security; 164 __be16 security;
165 u8 bssid[8]; /* last ETH_ALEN are valid. bssid[0],[1] are unused */ 165 u8 bssid[8]; /* last ETH_ALEN are valid. bssid[0],[1] are unused */
166 u8 essid[32]; /* IW_ESSID_MAX_SIZE */ 166 u8 essid[32]; /* IW_ESSID_MAX_SIZE */
167 u8 rate[16]; /* first MAX_RATES_LENGTH(12) are valid */ 167 u8 rate[16]; /* first 12 are valid */
168 u8 ext_rate[16]; /* first MAX_RATES_EX_LENGTH(16) are valid */ 168 u8 ext_rate[16]; /* first 16 are valid */
169 __be32 reserved1; 169 __be32 reserved1;
170 __be32 reserved2; 170 __be32 reserved2;
171 __be32 reserved3; 171 __be32 reserved3;
diff --git a/drivers/net/wireless/Makefile b/drivers/net/wireless/Makefile
index 59d2d805f60b..78820840fe21 100644
--- a/drivers/net/wireless/Makefile
+++ b/drivers/net/wireless/Makefile
@@ -16,14 +16,7 @@ obj-$(CONFIG_WAVELAN) += wavelan.o
16obj-$(CONFIG_PCMCIA_NETWAVE) += netwave_cs.o 16obj-$(CONFIG_PCMCIA_NETWAVE) += netwave_cs.o
17obj-$(CONFIG_PCMCIA_WAVELAN) += wavelan_cs.o 17obj-$(CONFIG_PCMCIA_WAVELAN) += wavelan_cs.o
18 18
19obj-$(CONFIG_HERMES) += orinoco.o hermes.o hermes_dld.o 19obj-$(CONFIG_HERMES) += orinoco/
20obj-$(CONFIG_PCMCIA_HERMES) += orinoco_cs.o
21obj-$(CONFIG_APPLE_AIRPORT) += airport.o
22obj-$(CONFIG_PLX_HERMES) += orinoco_plx.o
23obj-$(CONFIG_PCI_HERMES) += orinoco_pci.o
24obj-$(CONFIG_TMD_HERMES) += orinoco_tmd.o
25obj-$(CONFIG_NORTEL_HERMES) += orinoco_nortel.o
26obj-$(CONFIG_PCMCIA_SPECTRUM) += spectrum_cs.o
27 20
28obj-$(CONFIG_AIRO) += airo.o 21obj-$(CONFIG_AIRO) += airo.o
29obj-$(CONFIG_AIRO_CS) += airo_cs.o airo.o 22obj-$(CONFIG_AIRO_CS) += airo_cs.o airo.o
diff --git a/drivers/net/wireless/adm8211.c b/drivers/net/wireless/adm8211.c
index b96ebfe4ef3e..fc0897fb2239 100644
--- a/drivers/net/wireless/adm8211.c
+++ b/drivers/net/wireless/adm8211.c
@@ -1297,22 +1297,6 @@ static void adm8211_set_bssid(struct ieee80211_hw *dev, const u8 *bssid)
1297 ADM8211_CSR_WRITE(ABDA1, reg); 1297 ADM8211_CSR_WRITE(ABDA1, reg);
1298} 1298}
1299 1299
1300static int adm8211_set_ssid(struct ieee80211_hw *dev, u8 *ssid, size_t ssid_len)
1301{
1302 struct adm8211_priv *priv = dev->priv;
1303 u8 buf[36];
1304
1305 if (ssid_len > 32)
1306 return -EINVAL;
1307
1308 memset(buf, 0, sizeof(buf));
1309 buf[0] = ssid_len;
1310 memcpy(buf + 1, ssid, ssid_len);
1311 adm8211_write_sram_bytes(dev, ADM8211_SRAM_SSID, buf, 33);
1312 /* TODO: configure beacon for adhoc? */
1313 return 0;
1314}
1315
1316static int adm8211_config(struct ieee80211_hw *dev, u32 changed) 1300static int adm8211_config(struct ieee80211_hw *dev, u32 changed)
1317{ 1301{
1318 struct adm8211_priv *priv = dev->priv; 1302 struct adm8211_priv *priv = dev->priv;
@@ -1338,13 +1322,6 @@ static int adm8211_config_interface(struct ieee80211_hw *dev,
1338 memcpy(priv->bssid, conf->bssid, ETH_ALEN); 1322 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
1339 } 1323 }
1340 1324
1341 if (conf->ssid_len != priv->ssid_len ||
1342 memcmp(conf->ssid, priv->ssid, conf->ssid_len)) {
1343 adm8211_set_ssid(dev, conf->ssid, conf->ssid_len);
1344 priv->ssid_len = conf->ssid_len;
1345 memcpy(priv->ssid, conf->ssid, conf->ssid_len);
1346 }
1347
1348 return 0; 1325 return 0;
1349} 1326}
1350 1327
diff --git a/drivers/net/wireless/adm8211.h b/drivers/net/wireless/adm8211.h
index 9b190ee26e90..4f6ab1322189 100644
--- a/drivers/net/wireless/adm8211.h
+++ b/drivers/net/wireless/adm8211.h
@@ -553,8 +553,6 @@ struct adm8211_priv {
553 553
554 int channel; 554 int channel;
555 u8 bssid[ETH_ALEN]; 555 u8 bssid[ETH_ALEN];
556 u8 ssid[32];
557 size_t ssid_len;
558 556
559 u8 soft_rx_crc; 557 u8 soft_rx_crc;
560 u8 retry_limit; 558 u8 retry_limit;
diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
index c8dc6568cec9..67d504e32290 100644
--- a/drivers/net/wireless/airo.c
+++ b/drivers/net/wireless/airo.c
@@ -47,10 +47,11 @@
47#include <linux/ioport.h> 47#include <linux/ioport.h>
48#include <linux/pci.h> 48#include <linux/pci.h>
49#include <asm/uaccess.h> 49#include <asm/uaccess.h>
50#include <net/ieee80211.h>
51#include <linux/kthread.h> 50#include <linux/kthread.h>
52#include <linux/freezer.h> 51#include <linux/freezer.h>
53 52
53#include <linux/ieee80211.h>
54
54#include "airo.h" 55#include "airo.h"
55 56
56#define DRV_NAME "airo" 57#define DRV_NAME "airo"
@@ -7265,56 +7266,53 @@ static inline char *airo_translate_scan(struct net_device *dev,
7265 if (test_bit(FLAG_WPA_CAPABLE, &ai->flags)) { 7266 if (test_bit(FLAG_WPA_CAPABLE, &ai->flags)) {
7266 unsigned int num_null_ies = 0; 7267 unsigned int num_null_ies = 0;
7267 u16 length = sizeof (bss->extra.iep); 7268 u16 length = sizeof (bss->extra.iep);
7268 struct ieee80211_info_element *info_element = 7269 u8 *ie = (void *)&bss->extra.iep;
7269 (struct ieee80211_info_element *) &bss->extra.iep;
7270 7270
7271 while ((length >= sizeof(*info_element)) && (num_null_ies < 2)) { 7271 while ((length >= 2) && (num_null_ies < 2)) {
7272 if (sizeof(*info_element) + info_element->len > length) { 7272 if (2 + ie[1] > length) {
7273 /* Invalid element, don't continue parsing IE */ 7273 /* Invalid element, don't continue parsing IE */
7274 break; 7274 break;
7275 } 7275 }
7276 7276
7277 switch (info_element->id) { 7277 switch (ie[0]) {
7278 case MFIE_TYPE_SSID: 7278 case WLAN_EID_SSID:
7279 /* Two zero-length SSID elements 7279 /* Two zero-length SSID elements
7280 * mean we're done parsing elements */ 7280 * mean we're done parsing elements */
7281 if (!info_element->len) 7281 if (!ie[1])
7282 num_null_ies++; 7282 num_null_ies++;
7283 break; 7283 break;
7284 7284
7285 case MFIE_TYPE_GENERIC: 7285 case WLAN_EID_GENERIC:
7286 if (info_element->len >= 4 && 7286 if (ie[1] >= 4 &&
7287 info_element->data[0] == 0x00 && 7287 ie[2] == 0x00 &&
7288 info_element->data[1] == 0x50 && 7288 ie[3] == 0x50 &&
7289 info_element->data[2] == 0xf2 && 7289 ie[4] == 0xf2 &&
7290 info_element->data[3] == 0x01) { 7290 ie[5] == 0x01) {
7291 iwe.cmd = IWEVGENIE; 7291 iwe.cmd = IWEVGENIE;
7292 iwe.u.data.length = min(info_element->len + 2, 7292 /* 64 is an arbitrary cut-off */
7293 MAX_WPA_IE_LEN); 7293 iwe.u.data.length = min(ie[1] + 2,
7294 64);
7294 current_ev = iwe_stream_add_point( 7295 current_ev = iwe_stream_add_point(
7295 info, current_ev, 7296 info, current_ev,
7296 end_buf, &iwe, 7297 end_buf, &iwe, ie);
7297 (char *) info_element);
7298 } 7298 }
7299 break; 7299 break;
7300 7300
7301 case MFIE_TYPE_RSN: 7301 case WLAN_EID_RSN:
7302 iwe.cmd = IWEVGENIE; 7302 iwe.cmd = IWEVGENIE;
7303 iwe.u.data.length = min(info_element->len + 2, 7303 /* 64 is an arbitrary cut-off */
7304 MAX_WPA_IE_LEN); 7304 iwe.u.data.length = min(ie[1] + 2, 64);
7305 current_ev = iwe_stream_add_point( 7305 current_ev = iwe_stream_add_point(
7306 info, current_ev, end_buf, 7306 info, current_ev, end_buf,
7307 &iwe, (char *) info_element); 7307 &iwe, ie);
7308 break; 7308 break;
7309 7309
7310 default: 7310 default:
7311 break; 7311 break;
7312 } 7312 }
7313 7313
7314 length -= sizeof(*info_element) + info_element->len; 7314 length -= 2 + ie[1];
7315 info_element = 7315 ie += 2 + ie[1];
7316 (struct ieee80211_info_element *)&info_element->
7317 data[info_element->len];
7318 } 7316 }
7319 } 7317 }
7320 return current_ev; 7318 return current_ev;
diff --git a/drivers/net/wireless/ath5k/ath5k.h b/drivers/net/wireless/ath5k/ath5k.h
index b11792039911..a725bb94a52d 100644
--- a/drivers/net/wireless/ath5k/ath5k.h
+++ b/drivers/net/wireless/ath5k/ath5k.h
@@ -1093,10 +1093,11 @@ struct ath5k_hw {
1093 1093
1094 u8 ah_sta_id[ETH_ALEN]; 1094 u8 ah_sta_id[ETH_ALEN];
1095 1095
1096 /* Current BSSID we are trying to assoc to / creating. 1096 /* Current BSSID we are trying to assoc to / create.
1097 * This is passed by mac80211 on config_interface() and cached here for 1097 * This is passed by mac80211 on config_interface() and cached here for
1098 * use in resets */ 1098 * use in resets */
1099 u8 ah_bssid[ETH_ALEN]; 1099 u8 ah_bssid[ETH_ALEN];
1100 u8 ah_bssid_mask[ETH_ALEN];
1100 1101
1101 u32 ah_gpio[AR5K_MAX_GPIO]; 1102 u32 ah_gpio[AR5K_MAX_GPIO];
1102 int ah_gpio_npins; 1103 int ah_gpio_npins;
diff --git a/drivers/net/wireless/ath5k/base.c b/drivers/net/wireless/ath5k/base.c
index 6f368e8cdf17..c7ffcbb9062d 100644
--- a/drivers/net/wireless/ath5k/base.c
+++ b/drivers/net/wireless/ath5k/base.c
@@ -60,6 +60,9 @@
60#include "debug.h" 60#include "debug.h"
61 61
62static int ath5k_calinterval = 10; /* Calibrate PHY every 10 secs (TODO: Fixme) */ 62static int ath5k_calinterval = 10; /* Calibrate PHY every 10 secs (TODO: Fixme) */
63static int modparam_nohwcrypt;
64module_param_named(nohwcrypt, modparam_nohwcrypt, int, 0444);
65MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
63 66
64 67
65/******************\ 68/******************\
@@ -2975,12 +2978,13 @@ ath5k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2975 struct ath5k_softc *sc = hw->priv; 2978 struct ath5k_softc *sc = hw->priv;
2976 int ret = 0; 2979 int ret = 0;
2977 2980
2981 if (modparam_nohwcrypt)
2982 return -EOPNOTSUPP;
2983
2978 switch (key->alg) { 2984 switch (key->alg) {
2979 case ALG_WEP: 2985 case ALG_WEP:
2980 /* XXX: fix hardware encryption, its not working. For now
2981 * allow software encryption */
2982 /* break; */
2983 case ALG_TKIP: 2986 case ALG_TKIP:
2987 break;
2984 case ALG_CCMP: 2988 case ALG_CCMP:
2985 return -EOPNOTSUPP; 2989 return -EOPNOTSUPP;
2986 default: 2990 default:
@@ -2999,6 +3003,8 @@ ath5k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2999 } 3003 }
3000 __set_bit(key->keyidx, sc->keymap); 3004 __set_bit(key->keyidx, sc->keymap);
3001 key->hw_key_idx = key->keyidx; 3005 key->hw_key_idx = key->keyidx;
3006 key->flags |= (IEEE80211_KEY_FLAG_GENERATE_IV |
3007 IEEE80211_KEY_FLAG_GENERATE_MMIC);
3002 break; 3008 break;
3003 case DISABLE_KEY: 3009 case DISABLE_KEY:
3004 ath5k_hw_reset_key(sc->ah, key->keyidx); 3010 ath5k_hw_reset_key(sc->ah, key->keyidx);
diff --git a/drivers/net/wireless/ath5k/pcu.c b/drivers/net/wireless/ath5k/pcu.c
index a47df9a24aa1..d7f0c1017bda 100644
--- a/drivers/net/wireless/ath5k/pcu.c
+++ b/drivers/net/wireless/ath5k/pcu.c
@@ -46,34 +46,45 @@ int ath5k_hw_set_opmode(struct ath5k_hw *ah)
46{ 46{
47 u32 pcu_reg, beacon_reg, low_id, high_id; 47 u32 pcu_reg, beacon_reg, low_id, high_id;
48 48
49 pcu_reg = 0; 49
50 /* Preserve rest settings */
51 pcu_reg = ath5k_hw_reg_read(ah, AR5K_STA_ID1) & 0xffff0000;
52 pcu_reg &= ~(AR5K_STA_ID1_ADHOC | AR5K_STA_ID1_AP
53 | AR5K_STA_ID1_KEYSRCH_MODE
54 | (ah->ah_version == AR5K_AR5210 ?
55 (AR5K_STA_ID1_PWR_SV | AR5K_STA_ID1_NO_PSPOLL) : 0));
56
50 beacon_reg = 0; 57 beacon_reg = 0;
51 58
52 ATH5K_TRACE(ah->ah_sc); 59 ATH5K_TRACE(ah->ah_sc);
53 60
54 switch (ah->ah_op_mode) { 61 switch (ah->ah_op_mode) {
55 case NL80211_IFTYPE_ADHOC: 62 case NL80211_IFTYPE_ADHOC:
56 pcu_reg |= AR5K_STA_ID1_ADHOC | AR5K_STA_ID1_DESC_ANTENNA | 63 pcu_reg |= AR5K_STA_ID1_ADHOC | AR5K_STA_ID1_KEYSRCH_MODE;
57 (ah->ah_version == AR5K_AR5210 ?
58 AR5K_STA_ID1_NO_PSPOLL : 0);
59 beacon_reg |= AR5K_BCR_ADHOC; 64 beacon_reg |= AR5K_BCR_ADHOC;
65 if (ah->ah_version == AR5K_AR5210)
66 pcu_reg |= AR5K_STA_ID1_NO_PSPOLL;
67 else
68 AR5K_REG_DISABLE_BITS(ah, AR5K_CFG, AR5K_CFG_ADHOC);
60 break; 69 break;
61 70
62 case NL80211_IFTYPE_AP: 71 case NL80211_IFTYPE_AP:
63 case NL80211_IFTYPE_MESH_POINT: 72 case NL80211_IFTYPE_MESH_POINT:
64 pcu_reg |= AR5K_STA_ID1_AP | AR5K_STA_ID1_RTS_DEF_ANTENNA | 73 pcu_reg |= AR5K_STA_ID1_AP | AR5K_STA_ID1_KEYSRCH_MODE;
65 (ah->ah_version == AR5K_AR5210 ?
66 AR5K_STA_ID1_NO_PSPOLL : 0);
67 beacon_reg |= AR5K_BCR_AP; 74 beacon_reg |= AR5K_BCR_AP;
75 if (ah->ah_version == AR5K_AR5210)
76 pcu_reg |= AR5K_STA_ID1_NO_PSPOLL;
77 else
78 AR5K_REG_ENABLE_BITS(ah, AR5K_CFG, AR5K_CFG_ADHOC);
68 break; 79 break;
69 80
70 case NL80211_IFTYPE_STATION: 81 case NL80211_IFTYPE_STATION:
71 pcu_reg |= AR5K_STA_ID1_DEFAULT_ANTENNA | 82 pcu_reg |= AR5K_STA_ID1_KEYSRCH_MODE
72 (ah->ah_version == AR5K_AR5210 ? 83 | (ah->ah_version == AR5K_AR5210 ?
73 AR5K_STA_ID1_PWR_SV : 0); 84 AR5K_STA_ID1_PWR_SV : 0);
74 case NL80211_IFTYPE_MONITOR: 85 case NL80211_IFTYPE_MONITOR:
75 pcu_reg |= AR5K_STA_ID1_DEFAULT_ANTENNA | 86 pcu_reg |= AR5K_STA_ID1_KEYSRCH_MODE
76 (ah->ah_version == AR5K_AR5210 ? 87 | (ah->ah_version == AR5K_AR5210 ?
77 AR5K_STA_ID1_NO_PSPOLL : 0); 88 AR5K_STA_ID1_NO_PSPOLL : 0);
78 break; 89 break;
79 90
@@ -130,6 +141,8 @@ void ath5k_hw_update_mib_counters(struct ath5k_hw *ah,
130 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_RXCLR); 141 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_RXCLR);
131 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_CYCLE); 142 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_CYCLE);
132 } 143 }
144
145 /* TODO: Handle ANI stats */
133} 146}
134 147
135/** 148/**
@@ -254,6 +267,10 @@ void ath5k_hw_get_lladdr(struct ath5k_hw *ah, u8 *mac)
254 * @mac: The card's mac address 267 * @mac: The card's mac address
255 * 268 *
256 * Set station id on hw using the provided mac address 269 * Set station id on hw using the provided mac address
270 *
271 * NOTE: This is only called during attach, don't call it
272 * on reset because it overwrites all AR5K_STA_ID1 settings.
273 * We have set_opmode (above) for reset.
257 */ 274 */
258int ath5k_hw_set_lladdr(struct ath5k_hw *ah, const u8 *mac) 275int ath5k_hw_set_lladdr(struct ath5k_hw *ah, const u8 *mac)
259{ 276{
@@ -290,8 +307,10 @@ void ath5k_hw_set_associd(struct ath5k_hw *ah, const u8 *bssid, u16 assoc_id)
290 * Set simple BSSID mask on 5212 307 * Set simple BSSID mask on 5212
291 */ 308 */
292 if (ah->ah_version == AR5K_AR5212) { 309 if (ah->ah_version == AR5K_AR5212) {
293 ath5k_hw_reg_write(ah, 0xffffffff, AR5K_BSS_IDM0); 310 ath5k_hw_reg_write(ah, AR5K_LOW_ID(ah->ah_bssid_mask),
294 ath5k_hw_reg_write(ah, 0xffffffff, AR5K_BSS_IDM1); 311 AR5K_BSS_IDM0);
312 ath5k_hw_reg_write(ah, AR5K_HIGH_ID(ah->ah_bssid_mask),
313 AR5K_BSS_IDM1);
295 } 314 }
296 315
297 /* 316 /*
@@ -415,6 +434,9 @@ int ath5k_hw_set_bssid_mask(struct ath5k_hw *ah, const u8 *mask)
415 u32 low_id, high_id; 434 u32 low_id, high_id;
416 ATH5K_TRACE(ah->ah_sc); 435 ATH5K_TRACE(ah->ah_sc);
417 436
437 /* Cache bssid mask so that we can restore it
438 * on reset */
439 memcpy(ah->ah_bssid_mask, mask, ETH_ALEN);
418 if (ah->ah_version == AR5K_AR5212) { 440 if (ah->ah_version == AR5K_AR5212) {
419 low_id = AR5K_LOW_ID(mask); 441 low_id = AR5K_LOW_ID(mask);
420 high_id = AR5K_HIGH_ID(mask); 442 high_id = AR5K_HIGH_ID(mask);
@@ -576,7 +598,7 @@ void ath5k_hw_set_rx_filter(struct ath5k_hw *ah, u32 filter)
576 filter |= AR5K_RX_FILTER_PROM; 598 filter |= AR5K_RX_FILTER_PROM;
577 } 599 }
578 600
579 /*Zero length DMA*/ 601 /*Zero length DMA (phy error reporting) */
580 if (data) 602 if (data)
581 AR5K_REG_ENABLE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_ZLFDMA); 603 AR5K_REG_ENABLE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_ZLFDMA);
582 else 604 else
@@ -661,7 +683,12 @@ void ath5k_hw_init_beacon(struct ath5k_hw *ah, u32 next_beacon, u32 interval)
661 * Set the additional timers by mode 683 * Set the additional timers by mode
662 */ 684 */
663 switch (ah->ah_op_mode) { 685 switch (ah->ah_op_mode) {
686 case NL80211_IFTYPE_MONITOR:
664 case NL80211_IFTYPE_STATION: 687 case NL80211_IFTYPE_STATION:
688 /* In STA mode timer1 is used as next wakeup
689 * timer and timer2 as next CFP duration start
690 * timer. Both in 1/8TUs. */
691 /* TODO: PCF handling */
665 if (ah->ah_version == AR5K_AR5210) { 692 if (ah->ah_version == AR5K_AR5210) {
666 timer1 = 0xffffffff; 693 timer1 = 0xffffffff;
667 timer2 = 0xffffffff; 694 timer2 = 0xffffffff;
@@ -669,27 +696,60 @@ void ath5k_hw_init_beacon(struct ath5k_hw *ah, u32 next_beacon, u32 interval)
669 timer1 = 0x0000ffff; 696 timer1 = 0x0000ffff;
670 timer2 = 0x0007ffff; 697 timer2 = 0x0007ffff;
671 } 698 }
699 /* Mark associated AP as PCF incapable for now */
700 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1, AR5K_STA_ID1_PCF);
672 break; 701 break;
673 702 case NL80211_IFTYPE_ADHOC:
703 AR5K_REG_ENABLE_BITS(ah, AR5K_TXCFG, AR5K_TXCFG_ADHOC_BCN_ATIM);
674 default: 704 default:
705 /* On non-STA modes timer1 is used as next DMA
706 * beacon alert (DBA) timer and timer2 as next
707 * software beacon alert. Both in 1/8TUs. */
675 timer1 = (next_beacon - AR5K_TUNE_DMA_BEACON_RESP) << 3; 708 timer1 = (next_beacon - AR5K_TUNE_DMA_BEACON_RESP) << 3;
676 timer2 = (next_beacon - AR5K_TUNE_SW_BEACON_RESP) << 3; 709 timer2 = (next_beacon - AR5K_TUNE_SW_BEACON_RESP) << 3;
710 break;
677 } 711 }
678 712
713 /* Timer3 marks the end of our ATIM window
714 * a zero length window is not allowed because
715 * we 'll get no beacons */
679 timer3 = next_beacon + (ah->ah_atim_window ? ah->ah_atim_window : 1); 716 timer3 = next_beacon + (ah->ah_atim_window ? ah->ah_atim_window : 1);
680 717
681 /* 718 /*
682 * Set the beacon register and enable all timers. 719 * Set the beacon register and enable all timers.
683 * (next beacon, DMA beacon, software beacon, ATIM window time)
684 */ 720 */
685 ath5k_hw_reg_write(ah, next_beacon, AR5K_TIMER0); 721 /* When in AP mode zero timer0 to start TSF */
722 if (ah->ah_op_mode == NL80211_IFTYPE_AP)
723 ath5k_hw_reg_write(ah, 0, AR5K_TIMER0);
724 else
725 ath5k_hw_reg_write(ah, next_beacon, AR5K_TIMER0);
686 ath5k_hw_reg_write(ah, timer1, AR5K_TIMER1); 726 ath5k_hw_reg_write(ah, timer1, AR5K_TIMER1);
687 ath5k_hw_reg_write(ah, timer2, AR5K_TIMER2); 727 ath5k_hw_reg_write(ah, timer2, AR5K_TIMER2);
688 ath5k_hw_reg_write(ah, timer3, AR5K_TIMER3); 728 ath5k_hw_reg_write(ah, timer3, AR5K_TIMER3);
689 729
730 /* Force a TSF reset if requested and enable beacons */
731 if (interval & AR5K_BEACON_RESET_TSF)
732 ath5k_hw_reset_tsf(ah);
733
690 ath5k_hw_reg_write(ah, interval & (AR5K_BEACON_PERIOD | 734 ath5k_hw_reg_write(ah, interval & (AR5K_BEACON_PERIOD |
691 AR5K_BEACON_RESET_TSF | AR5K_BEACON_ENABLE), 735 AR5K_BEACON_ENABLE),
692 AR5K_BEACON); 736 AR5K_BEACON);
737
738 /* Flush any pending BMISS interrupts on ISR by
739 * performing a clear-on-write operation on PISR
740 * register for the BMISS bit (writing a bit on
741 * ISR togles a reset for that bit and leaves
742 * the rest bits intact) */
743 if (ah->ah_version == AR5K_AR5210)
744 ath5k_hw_reg_write(ah, AR5K_ISR_BMISS, AR5K_ISR);
745 else
746 ath5k_hw_reg_write(ah, AR5K_ISR_BMISS, AR5K_PISR);
747
748 /* TODO: Set enchanced sleep registers on AR5212
749 * based on vif->bss_conf params, until then
750 * disable power save reporting.*/
751 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1, AR5K_STA_ID1_PWR_SV);
752
693} 753}
694 754
695#if 0 755#if 0
@@ -899,14 +959,26 @@ int ath5k_hw_beaconq_finish(struct ath5k_hw *ah, unsigned long phys_addr)
899 */ 959 */
900int ath5k_hw_reset_key(struct ath5k_hw *ah, u16 entry) 960int ath5k_hw_reset_key(struct ath5k_hw *ah, u16 entry)
901{ 961{
902 unsigned int i; 962 unsigned int i, type;
963 u16 micentry = entry + AR5K_KEYTABLE_MIC_OFFSET;
903 964
904 ATH5K_TRACE(ah->ah_sc); 965 ATH5K_TRACE(ah->ah_sc);
905 AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE); 966 AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
906 967
968 type = ath5k_hw_reg_read(ah, AR5K_KEYTABLE_TYPE(entry));
969
907 for (i = 0; i < AR5K_KEYCACHE_SIZE; i++) 970 for (i = 0; i < AR5K_KEYCACHE_SIZE; i++)
908 ath5k_hw_reg_write(ah, 0, AR5K_KEYTABLE_OFF(entry, i)); 971 ath5k_hw_reg_write(ah, 0, AR5K_KEYTABLE_OFF(entry, i));
909 972
973 /* Reset associated MIC entry if TKIP
974 * is enabled located at offset (entry + 64) */
975 if (type == AR5K_KEYTABLE_TYPE_TKIP) {
976 AR5K_ASSERT_ENTRY(micentry, AR5K_KEYTABLE_SIZE);
977 for (i = 0; i < AR5K_KEYCACHE_SIZE / 2 ; i++)
978 ath5k_hw_reg_write(ah, 0,
979 AR5K_KEYTABLE_OFF(micentry, i));
980 }
981
910 /* 982 /*
911 * Set NULL encryption on AR5212+ 983 * Set NULL encryption on AR5212+
912 * 984 *
@@ -916,10 +988,16 @@ int ath5k_hw_reset_key(struct ath5k_hw *ah, u16 entry)
916 * Note2: Windows driver (ndiswrapper) sets this to 988 * Note2: Windows driver (ndiswrapper) sets this to
917 * 0x00000714 instead of 0x00000007 989 * 0x00000714 instead of 0x00000007
918 */ 990 */
919 if (ah->ah_version > AR5K_AR5211) 991 if (ah->ah_version > AR5K_AR5211) {
920 ath5k_hw_reg_write(ah, AR5K_KEYTABLE_TYPE_NULL, 992 ath5k_hw_reg_write(ah, AR5K_KEYTABLE_TYPE_NULL,
921 AR5K_KEYTABLE_TYPE(entry)); 993 AR5K_KEYTABLE_TYPE(entry));
922 994
995 if (type == AR5K_KEYTABLE_TYPE_TKIP) {
996 ath5k_hw_reg_write(ah, AR5K_KEYTABLE_TYPE_NULL,
997 AR5K_KEYTABLE_TYPE(micentry));
998 }
999 }
1000
923 return 0; 1001 return 0;
924} 1002}
925 1003
@@ -943,17 +1021,29 @@ int ath5k_hw_set_key(struct ath5k_hw *ah, u16 entry,
943 const struct ieee80211_key_conf *key, const u8 *mac) 1021 const struct ieee80211_key_conf *key, const u8 *mac)
944{ 1022{
945 unsigned int i; 1023 unsigned int i;
1024 int keylen;
946 __le32 key_v[5] = {}; 1025 __le32 key_v[5] = {};
1026 __le32 key0 = 0, key1 = 0;
1027 __le32 *rxmic, *txmic;
947 u32 keytype; 1028 u32 keytype;
1029 u16 micentry = entry + AR5K_KEYTABLE_MIC_OFFSET;
1030 bool is_tkip;
948 1031
949 ATH5K_TRACE(ah->ah_sc); 1032 ATH5K_TRACE(ah->ah_sc);
950 1033
951 /* key->keylen comes in from mac80211 in bytes */ 1034 is_tkip = (key->alg == ALG_TKIP);
1035
1036 /*
1037 * key->keylen comes in from mac80211 in bytes.
1038 * TKIP is 128 bit + 128 bit mic
1039 */
1040 keylen = (is_tkip) ? (128 / 8) : key->keylen;
952 1041
953 if (key->keylen > AR5K_KEYTABLE_SIZE / 8) 1042 if (entry > AR5K_KEYTABLE_SIZE ||
1043 (is_tkip && micentry > AR5K_KEYTABLE_SIZE))
954 return -EOPNOTSUPP; 1044 return -EOPNOTSUPP;
955 1045
956 switch (key->keylen) { 1046 switch (keylen) {
957 /* WEP 40-bit = 40-bit entered key + 24 bit IV = 64-bit */ 1047 /* WEP 40-bit = 40-bit entered key + 24 bit IV = 64-bit */
958 case 40 / 8: 1048 case 40 / 8:
959 memcpy(&key_v[0], key->key, 5); 1049 memcpy(&key_v[0], key->key, 5);
@@ -967,24 +1057,66 @@ int ath5k_hw_set_key(struct ath5k_hw *ah, u16 entry,
967 memcpy(&key_v[4], &key->key[12], 1); 1057 memcpy(&key_v[4], &key->key[12], 1);
968 keytype = AR5K_KEYTABLE_TYPE_104; 1058 keytype = AR5K_KEYTABLE_TYPE_104;
969 break; 1059 break;
970 /* WEP 128-bit = 128-bit entered key + 24 bit IV = 152-bit */ 1060 /* WEP/TKIP 128-bit = 128-bit entered key + 24 bit IV = 152-bit */
971 case 128 / 8: 1061 case 128 / 8:
972 memcpy(&key_v[0], &key->key[0], 6); 1062 memcpy(&key_v[0], &key->key[0], 6);
973 memcpy(&key_v[2], &key->key[6], 6); 1063 memcpy(&key_v[2], &key->key[6], 6);
974 memcpy(&key_v[4], &key->key[12], 4); 1064 memcpy(&key_v[4], &key->key[12], 4);
975 keytype = AR5K_KEYTABLE_TYPE_128; 1065 keytype = is_tkip ?
1066 AR5K_KEYTABLE_TYPE_TKIP :
1067 AR5K_KEYTABLE_TYPE_128;
976 break; 1068 break;
977 1069
978 default: 1070 default:
979 return -EINVAL; /* shouldn't happen */ 1071 return -EINVAL; /* shouldn't happen */
980 } 1072 }
981 1073
1074 /* intentionally corrupt key until mic is installed */
1075 if (is_tkip) {
1076 key0 = key_v[0] = ~key_v[0];
1077 key1 = key_v[1] = ~key_v[1];
1078 }
1079
982 for (i = 0; i < ARRAY_SIZE(key_v); i++) 1080 for (i = 0; i < ARRAY_SIZE(key_v); i++)
983 ath5k_hw_reg_write(ah, le32_to_cpu(key_v[i]), 1081 ath5k_hw_reg_write(ah, le32_to_cpu(key_v[i]),
984 AR5K_KEYTABLE_OFF(entry, i)); 1082 AR5K_KEYTABLE_OFF(entry, i));
985 1083
986 ath5k_hw_reg_write(ah, keytype, AR5K_KEYTABLE_TYPE(entry)); 1084 ath5k_hw_reg_write(ah, keytype, AR5K_KEYTABLE_TYPE(entry));
987 1085
1086 if (is_tkip) {
1087 /* Install rx/tx MIC */
1088 rxmic = (__le32 *) &key->key[16];
1089 txmic = (__le32 *) &key->key[24];
1090#if 0
1091 /* MISC_MODE register & 0x04 - for mac srev >= griffin */
1092 key_v[0] = rxmic[0];
1093 key_v[1] = (txmic[0] >> 16) & 0xffff;
1094 key_v[2] = rxmic[1];
1095 key_v[3] = txmic[0] & 0xffff;
1096 key_v[4] = txmic[1];
1097#else
1098 key_v[0] = rxmic[0];
1099 key_v[1] = 0;
1100 key_v[2] = rxmic[1];
1101 key_v[3] = 0;
1102 key_v[4] = 0;
1103#endif
1104 for (i = 0; i < ARRAY_SIZE(key_v); i++)
1105 ath5k_hw_reg_write(ah, le32_to_cpu(key_v[i]),
1106 AR5K_KEYTABLE_OFF(micentry, i));
1107
1108 ath5k_hw_reg_write(ah, AR5K_KEYTABLE_TYPE_NULL,
1109 AR5K_KEYTABLE_TYPE(micentry));
1110 ath5k_hw_reg_write(ah, 0, AR5K_KEYTABLE_MAC0(micentry));
1111 ath5k_hw_reg_write(ah, 0, AR5K_KEYTABLE_MAC1(micentry));
1112
1113 /* restore first 2 words of key */
1114 ath5k_hw_reg_write(ah, le32_to_cpu(~key0),
1115 AR5K_KEYTABLE_OFF(entry, 0));
1116 ath5k_hw_reg_write(ah, le32_to_cpu(~key1),
1117 AR5K_KEYTABLE_OFF(entry, 1));
1118 }
1119
988 return ath5k_hw_set_key_lladdr(ah, entry, mac); 1120 return ath5k_hw_set_key_lladdr(ah, entry, mac);
989} 1121}
990 1122
diff --git a/drivers/net/wireless/ath5k/reg.h b/drivers/net/wireless/ath5k/reg.h
index 0dae54d00f03..69755fc2f9be 100644
--- a/drivers/net/wireless/ath5k/reg.h
+++ b/drivers/net/wireless/ath5k/reg.h
@@ -1114,14 +1114,16 @@
1114#define AR5K_PCU_MAX 0x8fff 1114#define AR5K_PCU_MAX 0x8fff
1115 1115
1116/* 1116/*
1117 * First station id register (MAC address in lower 32 bits) 1117 * First station id register (Lower 32 bits of MAC address)
1118 */ 1118 */
1119#define AR5K_STA_ID0 0x8000 1119#define AR5K_STA_ID0 0x8000
1120#define AR5K_STA_ID0_ARRD_L32 0xffffffff
1120 1121
1121/* 1122/*
1122 * Second station id register (MAC address in upper 16 bits) 1123 * Second station id register (Upper 16 bits of MAC address + PCU settings)
1123 */ 1124 */
1124#define AR5K_STA_ID1 0x8004 /* Register Address */ 1125#define AR5K_STA_ID1 0x8004 /* Register Address */
1126#define AR5K_STA_ID1_ADDR_U16 0x0000ffff /* Upper 16 bits of MAC addres */
1125#define AR5K_STA_ID1_AP 0x00010000 /* Set AP mode */ 1127#define AR5K_STA_ID1_AP 0x00010000 /* Set AP mode */
1126#define AR5K_STA_ID1_ADHOC 0x00020000 /* Set Ad-Hoc mode */ 1128#define AR5K_STA_ID1_ADHOC 0x00020000 /* Set Ad-Hoc mode */
1127#define AR5K_STA_ID1_PWR_SV 0x00040000 /* Power save reporting */ 1129#define AR5K_STA_ID1_PWR_SV 0x00040000 /* Power save reporting */
@@ -1811,6 +1813,10 @@
1811#define AR5K_KEYTABLE_MAC1(_n) AR5K_KEYTABLE_OFF(_n, 7) 1813#define AR5K_KEYTABLE_MAC1(_n) AR5K_KEYTABLE_OFF(_n, 7)
1812#define AR5K_KEYTABLE_VALID 0x00008000 1814#define AR5K_KEYTABLE_VALID 0x00008000
1813 1815
1816/* If key type is TKIP and MIC is enabled
1817 * MIC key goes in offset entry + 64 */
1818#define AR5K_KEYTABLE_MIC_OFFSET 64
1819
1814/* WEP 40-bit = 40-bit entered key + 24 bit IV = 64-bit 1820/* WEP 40-bit = 40-bit entered key + 24 bit IV = 64-bit
1815 * WEP 104-bit = 104-bit entered key + 24-bit IV = 128-bit 1821 * WEP 104-bit = 104-bit entered key + 24-bit IV = 128-bit
1816 * WEP 128-bit = 128-bit entered key + 24 bit IV = 152-bit 1822 * WEP 128-bit = 128-bit entered key + 24 bit IV = 152-bit
diff --git a/drivers/net/wireless/ath9k/Makefile b/drivers/net/wireless/ath9k/Makefile
index a6411517e5f8..c58cfdeb49c9 100644
--- a/drivers/net/wireless/ath9k/Makefile
+++ b/drivers/net/wireless/ath9k/Makefile
@@ -1,4 +1,8 @@
1ath9k-y += hw.o \ 1ath9k-y += hw.o \
2 eeprom.o \
3 mac.o \
4 calib.o \
5 ani.o \
2 phy.o \ 6 phy.o \
3 regd.o \ 7 regd.o \
4 beacon.o \ 8 beacon.o \
diff --git a/drivers/net/wireless/ath9k/ani.c b/drivers/net/wireless/ath9k/ani.c
new file mode 100644
index 000000000000..ada12e9aa7f9
--- /dev/null
+++ b/drivers/net/wireless/ath9k/ani.c
@@ -0,0 +1,854 @@
1/*
2 * Copyright (c) 2008 Atheros Communications Inc.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#include "core.h"
18#include "hw.h"
19#include "reg.h"
20#include "phy.h"
21
22static int ath9k_hw_get_ani_channel_idx(struct ath_hal *ah,
23 struct ath9k_channel *chan)
24{
25 struct ath_hal_5416 *ahp = AH5416(ah);
26 int i;
27
28 for (i = 0; i < ARRAY_SIZE(ahp->ah_ani); i++) {
29 if (ahp->ah_ani[i].c.channel == chan->channel)
30 return i;
31 if (ahp->ah_ani[i].c.channel == 0) {
32 ahp->ah_ani[i].c.channel = chan->channel;
33 ahp->ah_ani[i].c.channelFlags = chan->channelFlags;
34 return i;
35 }
36 }
37
38 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
39 "No more channel states left. Using channel 0\n");
40
41 return 0;
42}
43
44static bool ath9k_hw_ani_control(struct ath_hal *ah,
45 enum ath9k_ani_cmd cmd, int param)
46{
47 struct ath_hal_5416 *ahp = AH5416(ah);
48 struct ar5416AniState *aniState = ahp->ah_curani;
49
50 switch (cmd & ahp->ah_ani_function) {
51 case ATH9K_ANI_NOISE_IMMUNITY_LEVEL:{
52 u32 level = param;
53
54 if (level >= ARRAY_SIZE(ahp->ah_totalSizeDesired)) {
55 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
56 "%s: level out of range (%u > %u)\n",
57 __func__, level,
58 (unsigned)ARRAY_SIZE(ahp->ah_totalSizeDesired));
59 return false;
60 }
61
62 REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ,
63 AR_PHY_DESIRED_SZ_TOT_DES,
64 ahp->ah_totalSizeDesired[level]);
65 REG_RMW_FIELD(ah, AR_PHY_AGC_CTL1,
66 AR_PHY_AGC_CTL1_COARSE_LOW,
67 ahp->ah_coarseLow[level]);
68 REG_RMW_FIELD(ah, AR_PHY_AGC_CTL1,
69 AR_PHY_AGC_CTL1_COARSE_HIGH,
70 ahp->ah_coarseHigh[level]);
71 REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
72 AR_PHY_FIND_SIG_FIRPWR,
73 ahp->ah_firpwr[level]);
74
75 if (level > aniState->noiseImmunityLevel)
76 ahp->ah_stats.ast_ani_niup++;
77 else if (level < aniState->noiseImmunityLevel)
78 ahp->ah_stats.ast_ani_nidown++;
79 aniState->noiseImmunityLevel = level;
80 break;
81 }
82 case ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION:{
83 const int m1ThreshLow[] = { 127, 50 };
84 const int m2ThreshLow[] = { 127, 40 };
85 const int m1Thresh[] = { 127, 0x4d };
86 const int m2Thresh[] = { 127, 0x40 };
87 const int m2CountThr[] = { 31, 16 };
88 const int m2CountThrLow[] = { 63, 48 };
89 u32 on = param ? 1 : 0;
90
91 REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
92 AR_PHY_SFCORR_LOW_M1_THRESH_LOW,
93 m1ThreshLow[on]);
94 REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
95 AR_PHY_SFCORR_LOW_M2_THRESH_LOW,
96 m2ThreshLow[on]);
97 REG_RMW_FIELD(ah, AR_PHY_SFCORR,
98 AR_PHY_SFCORR_M1_THRESH,
99 m1Thresh[on]);
100 REG_RMW_FIELD(ah, AR_PHY_SFCORR,
101 AR_PHY_SFCORR_M2_THRESH,
102 m2Thresh[on]);
103 REG_RMW_FIELD(ah, AR_PHY_SFCORR,
104 AR_PHY_SFCORR_M2COUNT_THR,
105 m2CountThr[on]);
106 REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
107 AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW,
108 m2CountThrLow[on]);
109
110 REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
111 AR_PHY_SFCORR_EXT_M1_THRESH_LOW,
112 m1ThreshLow[on]);
113 REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
114 AR_PHY_SFCORR_EXT_M2_THRESH_LOW,
115 m2ThreshLow[on]);
116 REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
117 AR_PHY_SFCORR_EXT_M1_THRESH,
118 m1Thresh[on]);
119 REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
120 AR_PHY_SFCORR_EXT_M2_THRESH,
121 m2Thresh[on]);
122
123 if (on)
124 REG_SET_BIT(ah, AR_PHY_SFCORR_LOW,
125 AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
126 else
127 REG_CLR_BIT(ah, AR_PHY_SFCORR_LOW,
128 AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
129
130 if (!on != aniState->ofdmWeakSigDetectOff) {
131 if (on)
132 ahp->ah_stats.ast_ani_ofdmon++;
133 else
134 ahp->ah_stats.ast_ani_ofdmoff++;
135 aniState->ofdmWeakSigDetectOff = !on;
136 }
137 break;
138 }
139 case ATH9K_ANI_CCK_WEAK_SIGNAL_THR:{
140 const int weakSigThrCck[] = { 8, 6 };
141 u32 high = param ? 1 : 0;
142
143 REG_RMW_FIELD(ah, AR_PHY_CCK_DETECT,
144 AR_PHY_CCK_DETECT_WEAK_SIG_THR_CCK,
145 weakSigThrCck[high]);
146 if (high != aniState->cckWeakSigThreshold) {
147 if (high)
148 ahp->ah_stats.ast_ani_cckhigh++;
149 else
150 ahp->ah_stats.ast_ani_ccklow++;
151 aniState->cckWeakSigThreshold = high;
152 }
153 break;
154 }
155 case ATH9K_ANI_FIRSTEP_LEVEL:{
156 const int firstep[] = { 0, 4, 8 };
157 u32 level = param;
158
159 if (level >= ARRAY_SIZE(firstep)) {
160 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
161 "%s: level out of range (%u > %u)\n",
162 __func__, level,
163 (unsigned) ARRAY_SIZE(firstep));
164 return false;
165 }
166 REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
167 AR_PHY_FIND_SIG_FIRSTEP,
168 firstep[level]);
169 if (level > aniState->firstepLevel)
170 ahp->ah_stats.ast_ani_stepup++;
171 else if (level < aniState->firstepLevel)
172 ahp->ah_stats.ast_ani_stepdown++;
173 aniState->firstepLevel = level;
174 break;
175 }
176 case ATH9K_ANI_SPUR_IMMUNITY_LEVEL:{
177 const int cycpwrThr1[] =
178 { 2, 4, 6, 8, 10, 12, 14, 16 };
179 u32 level = param;
180
181 if (level >= ARRAY_SIZE(cycpwrThr1)) {
182 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
183 "%s: level out of range (%u > %u)\n",
184 __func__, level,
185 (unsigned)
186 ARRAY_SIZE(cycpwrThr1));
187 return false;
188 }
189 REG_RMW_FIELD(ah, AR_PHY_TIMING5,
190 AR_PHY_TIMING5_CYCPWR_THR1,
191 cycpwrThr1[level]);
192 if (level > aniState->spurImmunityLevel)
193 ahp->ah_stats.ast_ani_spurup++;
194 else if (level < aniState->spurImmunityLevel)
195 ahp->ah_stats.ast_ani_spurdown++;
196 aniState->spurImmunityLevel = level;
197 break;
198 }
199 case ATH9K_ANI_PRESENT:
200 break;
201 default:
202 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
203 "%s: invalid cmd %u\n", __func__, cmd);
204 return false;
205 }
206
207 DPRINTF(ah->ah_sc, ATH_DBG_ANI, "%s: ANI parameters:\n", __func__);
208 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
209 "noiseImmunityLevel=%d, spurImmunityLevel=%d, "
210 "ofdmWeakSigDetectOff=%d\n",
211 aniState->noiseImmunityLevel, aniState->spurImmunityLevel,
212 !aniState->ofdmWeakSigDetectOff);
213 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
214 "cckWeakSigThreshold=%d, "
215 "firstepLevel=%d, listenTime=%d\n",
216 aniState->cckWeakSigThreshold, aniState->firstepLevel,
217 aniState->listenTime);
218 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
219 "cycleCount=%d, ofdmPhyErrCount=%d, cckPhyErrCount=%d\n\n",
220 aniState->cycleCount, aniState->ofdmPhyErrCount,
221 aniState->cckPhyErrCount);
222
223 return true;
224}
225
226static void ath9k_hw_update_mibstats(struct ath_hal *ah,
227 struct ath9k_mib_stats *stats)
228{
229 stats->ackrcv_bad += REG_READ(ah, AR_ACK_FAIL);
230 stats->rts_bad += REG_READ(ah, AR_RTS_FAIL);
231 stats->fcs_bad += REG_READ(ah, AR_FCS_FAIL);
232 stats->rts_good += REG_READ(ah, AR_RTS_OK);
233 stats->beacons += REG_READ(ah, AR_BEACON_CNT);
234}
235
236static void ath9k_ani_restart(struct ath_hal *ah)
237{
238 struct ath_hal_5416 *ahp = AH5416(ah);
239 struct ar5416AniState *aniState;
240
241 if (!DO_ANI(ah))
242 return;
243
244 aniState = ahp->ah_curani;
245
246 aniState->listenTime = 0;
247 if (ahp->ah_hasHwPhyCounters) {
248 if (aniState->ofdmTrigHigh > AR_PHY_COUNTMAX) {
249 aniState->ofdmPhyErrBase = 0;
250 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
251 "OFDM Trigger is too high for hw counters\n");
252 } else {
253 aniState->ofdmPhyErrBase =
254 AR_PHY_COUNTMAX - aniState->ofdmTrigHigh;
255 }
256 if (aniState->cckTrigHigh > AR_PHY_COUNTMAX) {
257 aniState->cckPhyErrBase = 0;
258 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
259 "CCK Trigger is too high for hw counters\n");
260 } else {
261 aniState->cckPhyErrBase =
262 AR_PHY_COUNTMAX - aniState->cckTrigHigh;
263 }
264 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
265 "%s: Writing ofdmbase=%u cckbase=%u\n",
266 __func__, aniState->ofdmPhyErrBase,
267 aniState->cckPhyErrBase);
268 REG_WRITE(ah, AR_PHY_ERR_1, aniState->ofdmPhyErrBase);
269 REG_WRITE(ah, AR_PHY_ERR_2, aniState->cckPhyErrBase);
270 REG_WRITE(ah, AR_PHY_ERR_MASK_1, AR_PHY_ERR_OFDM_TIMING);
271 REG_WRITE(ah, AR_PHY_ERR_MASK_2, AR_PHY_ERR_CCK_TIMING);
272
273 ath9k_hw_update_mibstats(ah, &ahp->ah_mibStats);
274 }
275 aniState->ofdmPhyErrCount = 0;
276 aniState->cckPhyErrCount = 0;
277}
278
279static void ath9k_hw_ani_ofdm_err_trigger(struct ath_hal *ah)
280{
281 struct ath_hal_5416 *ahp = AH5416(ah);
282 struct ath9k_channel *chan = ah->ah_curchan;
283 struct ar5416AniState *aniState;
284 enum wireless_mode mode;
285 int32_t rssi;
286
287 if (!DO_ANI(ah))
288 return;
289
290 aniState = ahp->ah_curani;
291
292 if (aniState->noiseImmunityLevel < HAL_NOISE_IMMUNE_MAX) {
293 if (ath9k_hw_ani_control(ah, ATH9K_ANI_NOISE_IMMUNITY_LEVEL,
294 aniState->noiseImmunityLevel + 1)) {
295 return;
296 }
297 }
298
299 if (aniState->spurImmunityLevel < HAL_SPUR_IMMUNE_MAX) {
300 if (ath9k_hw_ani_control(ah, ATH9K_ANI_SPUR_IMMUNITY_LEVEL,
301 aniState->spurImmunityLevel + 1)) {
302 return;
303 }
304 }
305
306 if (ah->ah_opmode == ATH9K_M_HOSTAP) {
307 if (aniState->firstepLevel < HAL_FIRST_STEP_MAX) {
308 ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
309 aniState->firstepLevel + 1);
310 }
311 return;
312 }
313 rssi = BEACON_RSSI(ahp);
314 if (rssi > aniState->rssiThrHigh) {
315 if (!aniState->ofdmWeakSigDetectOff) {
316 if (ath9k_hw_ani_control(ah,
317 ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
318 false)) {
319 ath9k_hw_ani_control(ah,
320 ATH9K_ANI_SPUR_IMMUNITY_LEVEL, 0);
321 return;
322 }
323 }
324 if (aniState->firstepLevel < HAL_FIRST_STEP_MAX) {
325 ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
326 aniState->firstepLevel + 1);
327 return;
328 }
329 } else if (rssi > aniState->rssiThrLow) {
330 if (aniState->ofdmWeakSigDetectOff)
331 ath9k_hw_ani_control(ah,
332 ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
333 true);
334 if (aniState->firstepLevel < HAL_FIRST_STEP_MAX)
335 ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
336 aniState->firstepLevel + 1);
337 return;
338 } else {
339 mode = ath9k_hw_chan2wmode(ah, chan);
340 if (mode == ATH9K_MODE_11G || mode == ATH9K_MODE_11B) {
341 if (!aniState->ofdmWeakSigDetectOff)
342 ath9k_hw_ani_control(ah,
343 ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
344 false);
345 if (aniState->firstepLevel > 0)
346 ath9k_hw_ani_control(ah,
347 ATH9K_ANI_FIRSTEP_LEVEL, 0);
348 return;
349 }
350 }
351}
352
353static void ath9k_hw_ani_cck_err_trigger(struct ath_hal *ah)
354{
355 struct ath_hal_5416 *ahp = AH5416(ah);
356 struct ath9k_channel *chan = ah->ah_curchan;
357 struct ar5416AniState *aniState;
358 enum wireless_mode mode;
359 int32_t rssi;
360
361 if (!DO_ANI(ah))
362 return;
363
364 aniState = ahp->ah_curani;
365 if (aniState->noiseImmunityLevel < HAL_NOISE_IMMUNE_MAX) {
366 if (ath9k_hw_ani_control(ah, ATH9K_ANI_NOISE_IMMUNITY_LEVEL,
367 aniState->noiseImmunityLevel + 1)) {
368 return;
369 }
370 }
371 if (ah->ah_opmode == ATH9K_M_HOSTAP) {
372 if (aniState->firstepLevel < HAL_FIRST_STEP_MAX) {
373 ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
374 aniState->firstepLevel + 1);
375 }
376 return;
377 }
378 rssi = BEACON_RSSI(ahp);
379 if (rssi > aniState->rssiThrLow) {
380 if (aniState->firstepLevel < HAL_FIRST_STEP_MAX)
381 ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
382 aniState->firstepLevel + 1);
383 } else {
384 mode = ath9k_hw_chan2wmode(ah, chan);
385 if (mode == ATH9K_MODE_11G || mode == ATH9K_MODE_11B) {
386 if (aniState->firstepLevel > 0)
387 ath9k_hw_ani_control(ah,
388 ATH9K_ANI_FIRSTEP_LEVEL, 0);
389 }
390 }
391}
392
393static void ath9k_hw_ani_lower_immunity(struct ath_hal *ah)
394{
395 struct ath_hal_5416 *ahp = AH5416(ah);
396 struct ar5416AniState *aniState;
397 int32_t rssi;
398
399 aniState = ahp->ah_curani;
400
401 if (ah->ah_opmode == ATH9K_M_HOSTAP) {
402 if (aniState->firstepLevel > 0) {
403 if (ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
404 aniState->firstepLevel - 1))
405 return;
406 }
407 } else {
408 rssi = BEACON_RSSI(ahp);
409 if (rssi > aniState->rssiThrHigh) {
410 /* XXX: Handle me */
411 } else if (rssi > aniState->rssiThrLow) {
412 if (aniState->ofdmWeakSigDetectOff) {
413 if (ath9k_hw_ani_control(ah,
414 ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
415 true) == true)
416 return;
417 }
418 if (aniState->firstepLevel > 0) {
419 if (ath9k_hw_ani_control(ah,
420 ATH9K_ANI_FIRSTEP_LEVEL,
421 aniState->firstepLevel - 1) == true)
422 return;
423 }
424 } else {
425 if (aniState->firstepLevel > 0) {
426 if (ath9k_hw_ani_control(ah,
427 ATH9K_ANI_FIRSTEP_LEVEL,
428 aniState->firstepLevel - 1) == true)
429 return;
430 }
431 }
432 }
433
434 if (aniState->spurImmunityLevel > 0) {
435 if (ath9k_hw_ani_control(ah, ATH9K_ANI_SPUR_IMMUNITY_LEVEL,
436 aniState->spurImmunityLevel - 1))
437 return;
438 }
439
440 if (aniState->noiseImmunityLevel > 0) {
441 ath9k_hw_ani_control(ah, ATH9K_ANI_NOISE_IMMUNITY_LEVEL,
442 aniState->noiseImmunityLevel - 1);
443 return;
444 }
445}
446
447static int32_t ath9k_hw_ani_get_listen_time(struct ath_hal *ah)
448{
449 struct ath_hal_5416 *ahp = AH5416(ah);
450 struct ar5416AniState *aniState;
451 u32 txFrameCount, rxFrameCount, cycleCount;
452 int32_t listenTime;
453
454 txFrameCount = REG_READ(ah, AR_TFCNT);
455 rxFrameCount = REG_READ(ah, AR_RFCNT);
456 cycleCount = REG_READ(ah, AR_CCCNT);
457
458 aniState = ahp->ah_curani;
459 if (aniState->cycleCount == 0 || aniState->cycleCount > cycleCount) {
460
461 listenTime = 0;
462 ahp->ah_stats.ast_ani_lzero++;
463 } else {
464 int32_t ccdelta = cycleCount - aniState->cycleCount;
465 int32_t rfdelta = rxFrameCount - aniState->rxFrameCount;
466 int32_t tfdelta = txFrameCount - aniState->txFrameCount;
467 listenTime = (ccdelta - rfdelta - tfdelta) / 44000;
468 }
469 aniState->cycleCount = cycleCount;
470 aniState->txFrameCount = txFrameCount;
471 aniState->rxFrameCount = rxFrameCount;
472
473 return listenTime;
474}
475
476void ath9k_ani_reset(struct ath_hal *ah)
477{
478 struct ath_hal_5416 *ahp = AH5416(ah);
479 struct ar5416AniState *aniState;
480 struct ath9k_channel *chan = ah->ah_curchan;
481 int index;
482
483 if (!DO_ANI(ah))
484 return;
485
486 index = ath9k_hw_get_ani_channel_idx(ah, chan);
487 aniState = &ahp->ah_ani[index];
488 ahp->ah_curani = aniState;
489
490 if (DO_ANI(ah) && ah->ah_opmode != ATH9K_M_STA
491 && ah->ah_opmode != ATH9K_M_IBSS) {
492 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
493 "%s: Reset ANI state opmode %u\n", __func__,
494 ah->ah_opmode);
495 ahp->ah_stats.ast_ani_reset++;
496
497 ath9k_hw_ani_control(ah, ATH9K_ANI_NOISE_IMMUNITY_LEVEL, 0);
498 ath9k_hw_ani_control(ah, ATH9K_ANI_SPUR_IMMUNITY_LEVEL, 0);
499 ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL, 0);
500 ath9k_hw_ani_control(ah, ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
501 !ATH9K_ANI_USE_OFDM_WEAK_SIG);
502 ath9k_hw_ani_control(ah, ATH9K_ANI_CCK_WEAK_SIGNAL_THR,
503 ATH9K_ANI_CCK_WEAK_SIG_THR);
504
505 ath9k_hw_setrxfilter(ah, ath9k_hw_getrxfilter(ah) |
506 ATH9K_RX_FILTER_PHYERR);
507
508 if (ah->ah_opmode == ATH9K_M_HOSTAP) {
509 ahp->ah_curani->ofdmTrigHigh =
510 ah->ah_config.ofdm_trig_high;
511 ahp->ah_curani->ofdmTrigLow =
512 ah->ah_config.ofdm_trig_low;
513 ahp->ah_curani->cckTrigHigh =
514 ah->ah_config.cck_trig_high;
515 ahp->ah_curani->cckTrigLow =
516 ah->ah_config.cck_trig_low;
517 }
518 ath9k_ani_restart(ah);
519 return;
520 }
521
522 if (aniState->noiseImmunityLevel != 0)
523 ath9k_hw_ani_control(ah, ATH9K_ANI_NOISE_IMMUNITY_LEVEL,
524 aniState->noiseImmunityLevel);
525 if (aniState->spurImmunityLevel != 0)
526 ath9k_hw_ani_control(ah, ATH9K_ANI_SPUR_IMMUNITY_LEVEL,
527 aniState->spurImmunityLevel);
528 if (aniState->ofdmWeakSigDetectOff)
529 ath9k_hw_ani_control(ah, ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
530 !aniState->ofdmWeakSigDetectOff);
531 if (aniState->cckWeakSigThreshold)
532 ath9k_hw_ani_control(ah, ATH9K_ANI_CCK_WEAK_SIGNAL_THR,
533 aniState->cckWeakSigThreshold);
534 if (aniState->firstepLevel != 0)
535 ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
536 aniState->firstepLevel);
537 if (ahp->ah_hasHwPhyCounters) {
538 ath9k_hw_setrxfilter(ah, ath9k_hw_getrxfilter(ah) &
539 ~ATH9K_RX_FILTER_PHYERR);
540 ath9k_ani_restart(ah);
541 REG_WRITE(ah, AR_PHY_ERR_MASK_1, AR_PHY_ERR_OFDM_TIMING);
542 REG_WRITE(ah, AR_PHY_ERR_MASK_2, AR_PHY_ERR_CCK_TIMING);
543
544 } else {
545 ath9k_ani_restart(ah);
546 ath9k_hw_setrxfilter(ah, ath9k_hw_getrxfilter(ah) |
547 ATH9K_RX_FILTER_PHYERR);
548 }
549}
550
551void ath9k_hw_ani_monitor(struct ath_hal *ah,
552 const struct ath9k_node_stats *stats,
553 struct ath9k_channel *chan)
554{
555 struct ath_hal_5416 *ahp = AH5416(ah);
556 struct ar5416AniState *aniState;
557 int32_t listenTime;
558
559 aniState = ahp->ah_curani;
560 ahp->ah_stats.ast_nodestats = *stats;
561
562 listenTime = ath9k_hw_ani_get_listen_time(ah);
563 if (listenTime < 0) {
564 ahp->ah_stats.ast_ani_lneg++;
565 ath9k_ani_restart(ah);
566 return;
567 }
568
569 aniState->listenTime += listenTime;
570
571 if (ahp->ah_hasHwPhyCounters) {
572 u32 phyCnt1, phyCnt2;
573 u32 ofdmPhyErrCnt, cckPhyErrCnt;
574
575 ath9k_hw_update_mibstats(ah, &ahp->ah_mibStats);
576
577 phyCnt1 = REG_READ(ah, AR_PHY_ERR_1);
578 phyCnt2 = REG_READ(ah, AR_PHY_ERR_2);
579
580 if (phyCnt1 < aniState->ofdmPhyErrBase ||
581 phyCnt2 < aniState->cckPhyErrBase) {
582 if (phyCnt1 < aniState->ofdmPhyErrBase) {
583 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
584 "%s: phyCnt1 0x%x, resetting "
585 "counter value to 0x%x\n",
586 __func__, phyCnt1,
587 aniState->ofdmPhyErrBase);
588 REG_WRITE(ah, AR_PHY_ERR_1,
589 aniState->ofdmPhyErrBase);
590 REG_WRITE(ah, AR_PHY_ERR_MASK_1,
591 AR_PHY_ERR_OFDM_TIMING);
592 }
593 if (phyCnt2 < aniState->cckPhyErrBase) {
594 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
595 "%s: phyCnt2 0x%x, resetting "
596 "counter value to 0x%x\n",
597 __func__, phyCnt2,
598 aniState->cckPhyErrBase);
599 REG_WRITE(ah, AR_PHY_ERR_2,
600 aniState->cckPhyErrBase);
601 REG_WRITE(ah, AR_PHY_ERR_MASK_2,
602 AR_PHY_ERR_CCK_TIMING);
603 }
604 return;
605 }
606
607 ofdmPhyErrCnt = phyCnt1 - aniState->ofdmPhyErrBase;
608 ahp->ah_stats.ast_ani_ofdmerrs +=
609 ofdmPhyErrCnt - aniState->ofdmPhyErrCount;
610 aniState->ofdmPhyErrCount = ofdmPhyErrCnt;
611
612 cckPhyErrCnt = phyCnt2 - aniState->cckPhyErrBase;
613 ahp->ah_stats.ast_ani_cckerrs +=
614 cckPhyErrCnt - aniState->cckPhyErrCount;
615 aniState->cckPhyErrCount = cckPhyErrCnt;
616 }
617
618 if (!DO_ANI(ah))
619 return;
620
621 if (aniState->listenTime > 5 * ahp->ah_aniPeriod) {
622 if (aniState->ofdmPhyErrCount <= aniState->listenTime *
623 aniState->ofdmTrigLow / 1000 &&
624 aniState->cckPhyErrCount <= aniState->listenTime *
625 aniState->cckTrigLow / 1000)
626 ath9k_hw_ani_lower_immunity(ah);
627 ath9k_ani_restart(ah);
628 } else if (aniState->listenTime > ahp->ah_aniPeriod) {
629 if (aniState->ofdmPhyErrCount > aniState->listenTime *
630 aniState->ofdmTrigHigh / 1000) {
631 ath9k_hw_ani_ofdm_err_trigger(ah);
632 ath9k_ani_restart(ah);
633 } else if (aniState->cckPhyErrCount >
634 aniState->listenTime * aniState->cckTrigHigh /
635 1000) {
636 ath9k_hw_ani_cck_err_trigger(ah);
637 ath9k_ani_restart(ah);
638 }
639 }
640}
641
642bool ath9k_hw_phycounters(struct ath_hal *ah)
643{
644 struct ath_hal_5416 *ahp = AH5416(ah);
645
646 return ahp->ah_hasHwPhyCounters ? true : false;
647}
648
649void ath9k_enable_mib_counters(struct ath_hal *ah)
650{
651 struct ath_hal_5416 *ahp = AH5416(ah);
652
653 DPRINTF(ah->ah_sc, ATH_DBG_ANI, "Enable MIB counters\n");
654
655 ath9k_hw_update_mibstats(ah, &ahp->ah_mibStats);
656
657 REG_WRITE(ah, AR_FILT_OFDM, 0);
658 REG_WRITE(ah, AR_FILT_CCK, 0);
659 REG_WRITE(ah, AR_MIBC,
660 ~(AR_MIBC_COW | AR_MIBC_FMC | AR_MIBC_CMC | AR_MIBC_MCS)
661 & 0x0f);
662 REG_WRITE(ah, AR_PHY_ERR_MASK_1, AR_PHY_ERR_OFDM_TIMING);
663 REG_WRITE(ah, AR_PHY_ERR_MASK_2, AR_PHY_ERR_CCK_TIMING);
664}
665
666void ath9k_hw_disable_mib_counters(struct ath_hal *ah)
667{
668 struct ath_hal_5416 *ahp = AH5416(ah);
669
670 DPRINTF(ah->ah_sc, ATH_DBG_ANI, "Disable MIB counters\n");
671
672 REG_WRITE(ah, AR_MIBC, AR_MIBC_FMC | AR_MIBC_CMC);
673
674 ath9k_hw_update_mibstats(ah, &ahp->ah_mibStats);
675
676 REG_WRITE(ah, AR_FILT_OFDM, 0);
677 REG_WRITE(ah, AR_FILT_CCK, 0);
678}
679
680u32 ath9k_hw_GetMibCycleCountsPct(struct ath_hal *ah,
681 u32 *rxc_pcnt,
682 u32 *rxf_pcnt,
683 u32 *txf_pcnt)
684{
685 static u32 cycles, rx_clear, rx_frame, tx_frame;
686 u32 good = 1;
687
688 u32 rc = REG_READ(ah, AR_RCCNT);
689 u32 rf = REG_READ(ah, AR_RFCNT);
690 u32 tf = REG_READ(ah, AR_TFCNT);
691 u32 cc = REG_READ(ah, AR_CCCNT);
692
693 if (cycles == 0 || cycles > cc) {
694 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
695 "%s: cycle counter wrap. ExtBusy = 0\n",
696 __func__);
697 good = 0;
698 } else {
699 u32 cc_d = cc - cycles;
700 u32 rc_d = rc - rx_clear;
701 u32 rf_d = rf - rx_frame;
702 u32 tf_d = tf - tx_frame;
703
704 if (cc_d != 0) {
705 *rxc_pcnt = rc_d * 100 / cc_d;
706 *rxf_pcnt = rf_d * 100 / cc_d;
707 *txf_pcnt = tf_d * 100 / cc_d;
708 } else {
709 good = 0;
710 }
711 }
712
713 cycles = cc;
714 rx_frame = rf;
715 rx_clear = rc;
716 tx_frame = tf;
717
718 return good;
719}
720
721/*
722 * Process a MIB interrupt. We may potentially be invoked because
723 * any of the MIB counters overflow/trigger so don't assume we're
724 * here because a PHY error counter triggered.
725 */
726void ath9k_hw_procmibevent(struct ath_hal *ah,
727 const struct ath9k_node_stats *stats)
728{
729 struct ath_hal_5416 *ahp = AH5416(ah);
730 u32 phyCnt1, phyCnt2;
731
732 /* Reset these counters regardless */
733 REG_WRITE(ah, AR_FILT_OFDM, 0);
734 REG_WRITE(ah, AR_FILT_CCK, 0);
735 if (!(REG_READ(ah, AR_SLP_MIB_CTRL) & AR_SLP_MIB_PENDING))
736 REG_WRITE(ah, AR_SLP_MIB_CTRL, AR_SLP_MIB_CLEAR);
737
738 /* Clear the mib counters and save them in the stats */
739 ath9k_hw_update_mibstats(ah, &ahp->ah_mibStats);
740 ahp->ah_stats.ast_nodestats = *stats;
741
742 if (!DO_ANI(ah))
743 return;
744
745 /* NB: these are not reset-on-read */
746 phyCnt1 = REG_READ(ah, AR_PHY_ERR_1);
747 phyCnt2 = REG_READ(ah, AR_PHY_ERR_2);
748 if (((phyCnt1 & AR_MIBCNT_INTRMASK) == AR_MIBCNT_INTRMASK) ||
749 ((phyCnt2 & AR_MIBCNT_INTRMASK) == AR_MIBCNT_INTRMASK)) {
750 struct ar5416AniState *aniState = ahp->ah_curani;
751 u32 ofdmPhyErrCnt, cckPhyErrCnt;
752
753 /* NB: only use ast_ani_*errs with AH_PRIVATE_DIAG */
754 ofdmPhyErrCnt = phyCnt1 - aniState->ofdmPhyErrBase;
755 ahp->ah_stats.ast_ani_ofdmerrs +=
756 ofdmPhyErrCnt - aniState->ofdmPhyErrCount;
757 aniState->ofdmPhyErrCount = ofdmPhyErrCnt;
758
759 cckPhyErrCnt = phyCnt2 - aniState->cckPhyErrBase;
760 ahp->ah_stats.ast_ani_cckerrs +=
761 cckPhyErrCnt - aniState->cckPhyErrCount;
762 aniState->cckPhyErrCount = cckPhyErrCnt;
763
764 /*
765 * NB: figure out which counter triggered. If both
766 * trigger we'll only deal with one as the processing
767 * clobbers the error counter so the trigger threshold
768 * check will never be true.
769 */
770 if (aniState->ofdmPhyErrCount > aniState->ofdmTrigHigh)
771 ath9k_hw_ani_ofdm_err_trigger(ah);
772 if (aniState->cckPhyErrCount > aniState->cckTrigHigh)
773 ath9k_hw_ani_cck_err_trigger(ah);
774 /* NB: always restart to insure the h/w counters are reset */
775 ath9k_ani_restart(ah);
776 }
777}
778
779void ath9k_hw_ani_setup(struct ath_hal *ah)
780{
781 struct ath_hal_5416 *ahp = AH5416(ah);
782 int i;
783
784 const int totalSizeDesired[] = { -55, -55, -55, -55, -62 };
785 const int coarseHigh[] = { -14, -14, -14, -14, -12 };
786 const int coarseLow[] = { -64, -64, -64, -64, -70 };
787 const int firpwr[] = { -78, -78, -78, -78, -80 };
788
789 for (i = 0; i < 5; i++) {
790 ahp->ah_totalSizeDesired[i] = totalSizeDesired[i];
791 ahp->ah_coarseHigh[i] = coarseHigh[i];
792 ahp->ah_coarseLow[i] = coarseLow[i];
793 ahp->ah_firpwr[i] = firpwr[i];
794 }
795}
796
797void ath9k_hw_ani_attach(struct ath_hal *ah)
798{
799 struct ath_hal_5416 *ahp = AH5416(ah);
800 int i;
801
802 DPRINTF(ah->ah_sc, ATH_DBG_ANI, "Attach ANI\n");
803
804 ahp->ah_hasHwPhyCounters = 1;
805
806 memset(ahp->ah_ani, 0, sizeof(ahp->ah_ani));
807 for (i = 0; i < ARRAY_SIZE(ahp->ah_ani); i++) {
808 ahp->ah_ani[i].ofdmTrigHigh = ATH9K_ANI_OFDM_TRIG_HIGH;
809 ahp->ah_ani[i].ofdmTrigLow = ATH9K_ANI_OFDM_TRIG_LOW;
810 ahp->ah_ani[i].cckTrigHigh = ATH9K_ANI_CCK_TRIG_HIGH;
811 ahp->ah_ani[i].cckTrigLow = ATH9K_ANI_CCK_TRIG_LOW;
812 ahp->ah_ani[i].rssiThrHigh = ATH9K_ANI_RSSI_THR_HIGH;
813 ahp->ah_ani[i].rssiThrLow = ATH9K_ANI_RSSI_THR_LOW;
814 ahp->ah_ani[i].ofdmWeakSigDetectOff =
815 !ATH9K_ANI_USE_OFDM_WEAK_SIG;
816 ahp->ah_ani[i].cckWeakSigThreshold =
817 ATH9K_ANI_CCK_WEAK_SIG_THR;
818 ahp->ah_ani[i].spurImmunityLevel = ATH9K_ANI_SPUR_IMMUNE_LVL;
819 ahp->ah_ani[i].firstepLevel = ATH9K_ANI_FIRSTEP_LVL;
820 if (ahp->ah_hasHwPhyCounters) {
821 ahp->ah_ani[i].ofdmPhyErrBase =
822 AR_PHY_COUNTMAX - ATH9K_ANI_OFDM_TRIG_HIGH;
823 ahp->ah_ani[i].cckPhyErrBase =
824 AR_PHY_COUNTMAX - ATH9K_ANI_CCK_TRIG_HIGH;
825 }
826 }
827 if (ahp->ah_hasHwPhyCounters) {
828 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
829 "Setting OfdmErrBase = 0x%08x\n",
830 ahp->ah_ani[0].ofdmPhyErrBase);
831 DPRINTF(ah->ah_sc, ATH_DBG_ANI, "Setting cckErrBase = 0x%08x\n",
832 ahp->ah_ani[0].cckPhyErrBase);
833
834 REG_WRITE(ah, AR_PHY_ERR_1, ahp->ah_ani[0].ofdmPhyErrBase);
835 REG_WRITE(ah, AR_PHY_ERR_2, ahp->ah_ani[0].cckPhyErrBase);
836 ath9k_enable_mib_counters(ah);
837 }
838 ahp->ah_aniPeriod = ATH9K_ANI_PERIOD;
839 if (ah->ah_config.enable_ani)
840 ahp->ah_procPhyErr |= HAL_PROCESS_ANI;
841}
842
843void ath9k_hw_ani_detach(struct ath_hal *ah)
844{
845 struct ath_hal_5416 *ahp = AH5416(ah);
846
847 DPRINTF(ah->ah_sc, ATH_DBG_ANI, "Detach ANI\n");
848
849 if (ahp->ah_hasHwPhyCounters) {
850 ath9k_hw_disable_mib_counters(ah);
851 REG_WRITE(ah, AR_PHY_ERR_1, 0);
852 REG_WRITE(ah, AR_PHY_ERR_2, 0);
853 }
854}
diff --git a/drivers/net/wireless/ath9k/ath9k.h b/drivers/net/wireless/ath9k/ath9k.h
index a6063dea0fa2..3a180ce1770b 100644
--- a/drivers/net/wireless/ath9k/ath9k.h
+++ b/drivers/net/wireless/ath9k/ath9k.h
@@ -828,195 +828,251 @@ struct chan_centers {
828 u16 ext_center; 828 u16 ext_center;
829}; 829};
830 830
831int ath_hal_getcapability(struct ath_hal *ah, 831/* Helpers */
832 enum ath9k_capability_type type, 832
833 u32 capability, 833enum wireless_mode ath9k_hw_chan2wmode(struct ath_hal *ah,
834 u32 *result); 834 const struct ath9k_channel *chan);
835const struct ath9k_rate_table *ath9k_hw_getratetable(struct ath_hal *ah, 835bool ath9k_hw_wait(struct ath_hal *ah, u32 reg, u32 mask, u32 val);
836 u32 mode); 836u32 ath9k_hw_reverse_bits(u32 val, u32 n);
837void ath9k_hw_detach(struct ath_hal *ah); 837bool ath9k_get_channel_edges(struct ath_hal *ah,
838struct ath_hal *ath9k_hw_attach(u16 devid, 838 u16 flags, u16 *low,
839 struct ath_softc *sc, 839 u16 *high);
840 void __iomem *mem, 840u16 ath9k_hw_computetxtime(struct ath_hal *ah,
841 int *error); 841 const struct ath9k_rate_table *rates,
842bool ath9k_regd_init_channels(struct ath_hal *ah, 842 u32 frameLen, u16 rateix,
843 u32 maxchans, u32 *nchans, 843 bool shortPreamble);
844 u8 *regclassids,
845 u32 maxregids, u32 *nregids,
846 u16 cc,
847 bool enableOutdoor,
848 bool enableExtendedChannels);
849u32 ath9k_hw_mhz2ieee(struct ath_hal *ah, u32 freq, u32 flags); 844u32 ath9k_hw_mhz2ieee(struct ath_hal *ah, u32 freq, u32 flags);
850enum ath9k_int ath9k_hw_set_interrupts(struct ath_hal *ah, 845void ath9k_hw_get_channel_centers(struct ath_hal *ah,
851 enum ath9k_int ints); 846 struct ath9k_channel *chan,
852bool ath9k_hw_reset(struct ath_hal *ah, 847 struct chan_centers *centers);
853 struct ath9k_channel *chan, 848
849/* Attach, Detach */
850
851const char *ath9k_hw_probe(u16 vendorid, u16 devid);
852void ath9k_hw_detach(struct ath_hal *ah);
853struct ath_hal *ath9k_hw_attach(u16 devid, struct ath_softc *sc,
854 void __iomem *mem, int *error);
855void ath9k_hw_rfdetach(struct ath_hal *ah);
856
857
858/* HW Reset */
859
860bool ath9k_hw_reset(struct ath_hal *ah, struct ath9k_channel *chan,
854 enum ath9k_ht_macmode macmode, 861 enum ath9k_ht_macmode macmode,
855 u8 txchainmask, u8 rxchainmask, 862 u8 txchainmask, u8 rxchainmask,
856 enum ath9k_ht_extprotspacing extprotspacing, 863 enum ath9k_ht_extprotspacing extprotspacing,
857 bool bChannelChange, 864 bool bChannelChange, int *status);
858 int *status); 865
859bool ath9k_hw_phy_disable(struct ath_hal *ah); 866/* Key Cache Management */
860void ath9k_hw_reset_calvalid(struct ath_hal *ah, struct ath9k_channel *chan, 867
861 bool *isCalDone);
862void ath9k_hw_ani_monitor(struct ath_hal *ah,
863 const struct ath9k_node_stats *stats,
864 struct ath9k_channel *chan);
865bool ath9k_hw_calibrate(struct ath_hal *ah,
866 struct ath9k_channel *chan,
867 u8 rxchainmask,
868 bool longcal,
869 bool *isCalDone);
870s16 ath9k_hw_getchan_noise(struct ath_hal *ah,
871 struct ath9k_channel *chan);
872void ath9k_hw_write_associd(struct ath_hal *ah, const u8 *bssid,
873 u16 assocId);
874void ath9k_hw_setrxfilter(struct ath_hal *ah, u32 bits);
875void ath9k_hw_write_associd(struct ath_hal *ah, const u8 *bssid,
876 u16 assocId);
877bool ath9k_hw_stoptxdma(struct ath_hal *ah, u32 q);
878void ath9k_hw_reset_tsf(struct ath_hal *ah);
879bool ath9k_hw_keyisvalid(struct ath_hal *ah, u16 entry);
880bool ath9k_hw_keysetmac(struct ath_hal *ah, u16 entry,
881 const u8 *mac);
882bool ath9k_hw_set_keycache_entry(struct ath_hal *ah,
883 u16 entry,
884 const struct ath9k_keyval *k,
885 const u8 *mac,
886 int xorKey);
887bool ath9k_hw_set_tsfadjust(struct ath_hal *ah,
888 u32 setting);
889void ath9k_hw_configpcipowersave(struct ath_hal *ah, int restore);
890bool ath9k_hw_intrpend(struct ath_hal *ah);
891bool ath9k_hw_getisr(struct ath_hal *ah, enum ath9k_int *masked);
892bool ath9k_hw_updatetxtriglevel(struct ath_hal *ah,
893 bool bIncTrigLevel);
894void ath9k_hw_procmibevent(struct ath_hal *ah,
895 const struct ath9k_node_stats *stats);
896bool ath9k_hw_setrxabort(struct ath_hal *ah, bool set);
897void ath9k_hw_set11nmac2040(struct ath_hal *ah, enum ath9k_ht_macmode mode);
898bool ath9k_hw_phycounters(struct ath_hal *ah);
899bool ath9k_hw_keyreset(struct ath_hal *ah, u16 entry); 868bool ath9k_hw_keyreset(struct ath_hal *ah, u16 entry);
900bool ath9k_hw_getcapability(struct ath_hal *ah, 869bool ath9k_hw_keysetmac(struct ath_hal *ah, u16 entry, const u8 *mac);
901 enum ath9k_capability_type type, 870bool ath9k_hw_set_keycache_entry(struct ath_hal *ah, u16 entry,
902 u32 capability, 871 const struct ath9k_keyval *k,
903 u32 *result); 872 const u8 *mac, int xorKey);
904bool ath9k_hw_setcapability(struct ath_hal *ah, 873bool ath9k_hw_keyisvalid(struct ath_hal *ah, u16 entry);
905 enum ath9k_capability_type type, 874
906 u32 capability, 875/* Power Management */
907 u32 setting, 876
908 int *status);
909u32 ath9k_hw_getdefantenna(struct ath_hal *ah);
910void ath9k_hw_getmac(struct ath_hal *ah, u8 *mac);
911void ath9k_hw_getbssidmask(struct ath_hal *ah, u8 *mask);
912bool ath9k_hw_setbssidmask(struct ath_hal *ah,
913 const u8 *mask);
914bool ath9k_hw_setpower(struct ath_hal *ah, 877bool ath9k_hw_setpower(struct ath_hal *ah,
915 enum ath9k_power_mode mode); 878 enum ath9k_power_mode mode);
916enum ath9k_int ath9k_hw_intrget(struct ath_hal *ah); 879void ath9k_hw_configpcipowersave(struct ath_hal *ah, int restore);
917u64 ath9k_hw_gettsf64(struct ath_hal *ah); 880
881/* Beacon timers */
882
883void ath9k_hw_beaconinit(struct ath_hal *ah, u32 next_beacon, u32 beacon_period);
884void ath9k_hw_set_sta_beacon_timers(struct ath_hal *ah,
885 const struct ath9k_beacon_state *bs);
886
887/* Rate table */
888
889const struct ath9k_rate_table *ath9k_hw_getratetable(struct ath_hal *ah,
890 u32 mode);
891
892/* HW Capabilities */
893
894bool ath9k_hw_fill_cap_info(struct ath_hal *ah);
895bool ath9k_hw_getcapability(struct ath_hal *ah, enum ath9k_capability_type type,
896 u32 capability, u32 *result);
897bool ath9k_hw_setcapability(struct ath_hal *ah, enum ath9k_capability_type type,
898 u32 capability, u32 setting, int *status);
899
900/* GPIO / RFKILL / Antennae */
901
902void ath9k_hw_cfg_gpio_input(struct ath_hal *ah, u32 gpio);
903u32 ath9k_hw_gpio_get(struct ath_hal *ah, u32 gpio);
904void ath9k_hw_cfg_output(struct ath_hal *ah, u32 gpio,
905 u32 ah_signal_type);
906void ath9k_hw_set_gpio(struct ath_hal *ah, u32 gpio, u32 val);
907#ifdef CONFIG_RFKILL
908void ath9k_enable_rfkill(struct ath_hal *ah);
909#endif
910int ath9k_hw_select_antconfig(struct ath_hal *ah, u32 cfg);
918u32 ath9k_hw_getdefantenna(struct ath_hal *ah); 911u32 ath9k_hw_getdefantenna(struct ath_hal *ah);
919bool ath9k_hw_setslottime(struct ath_hal *ah, u32 us); 912void ath9k_hw_setantenna(struct ath_hal *ah, u32 antenna);
920bool ath9k_hw_setantennaswitch(struct ath_hal *ah, 913bool ath9k_hw_setantennaswitch(struct ath_hal *ah,
921 enum ath9k_ant_setting settings, 914 enum ath9k_ant_setting settings,
922 struct ath9k_channel *chan, 915 struct ath9k_channel *chan,
923 u8 *tx_chainmask, 916 u8 *tx_chainmask,
924 u8 *rx_chainmask, 917 u8 *rx_chainmask,
925 u8 *antenna_cfgd); 918 u8 *antenna_cfgd);
926void ath9k_hw_setantenna(struct ath_hal *ah, u32 antenna); 919
927int ath9k_hw_select_antconfig(struct ath_hal *ah, 920/* General Operation */
928 u32 cfg); 921
929bool ath9k_hw_puttxbuf(struct ath_hal *ah, u32 q, 922u32 ath9k_hw_getrxfilter(struct ath_hal *ah);
930 u32 txdp); 923void ath9k_hw_setrxfilter(struct ath_hal *ah, u32 bits);
924bool ath9k_hw_phy_disable(struct ath_hal *ah);
925bool ath9k_hw_disable(struct ath_hal *ah);
926bool ath9k_hw_set_txpowerlimit(struct ath_hal *ah, u32 limit);
927void ath9k_hw_getmac(struct ath_hal *ah, u8 *mac);
928bool ath9k_hw_setmac(struct ath_hal *ah, const u8 *mac);
929void ath9k_hw_setopmode(struct ath_hal *ah);
930void ath9k_hw_setmcastfilter(struct ath_hal *ah, u32 filter0, u32 filter1);
931void ath9k_hw_getbssidmask(struct ath_hal *ah, u8 *mask);
932bool ath9k_hw_setbssidmask(struct ath_hal *ah, const u8 *mask);
933void ath9k_hw_write_associd(struct ath_hal *ah, const u8 *bssid, u16 assocId);
934u64 ath9k_hw_gettsf64(struct ath_hal *ah);
935void ath9k_hw_reset_tsf(struct ath_hal *ah);
936bool ath9k_hw_set_tsfadjust(struct ath_hal *ah, u32 setting);
937bool ath9k_hw_setslottime(struct ath_hal *ah, u32 us);
938void ath9k_hw_set11nmac2040(struct ath_hal *ah, enum ath9k_ht_macmode mode);
939
940/* Regulatory */
941
942bool ath9k_regd_is_public_safety_sku(struct ath_hal *ah);
943struct ath9k_channel* ath9k_regd_check_channel(struct ath_hal *ah,
944 const struct ath9k_channel *c);
945u32 ath9k_regd_get_ctl(struct ath_hal *ah, struct ath9k_channel *chan);
946u32 ath9k_regd_get_antenna_allowed(struct ath_hal *ah,
947 struct ath9k_channel *chan);
948bool ath9k_regd_init_channels(struct ath_hal *ah,
949 u32 maxchans, u32 *nchans, u8 *regclassids,
950 u32 maxregids, u32 *nregids, u16 cc,
951 bool enableOutdoor, bool enableExtendedChannels);
952
953/* ANI */
954
955void ath9k_ani_reset(struct ath_hal *ah);
956void ath9k_hw_ani_monitor(struct ath_hal *ah,
957 const struct ath9k_node_stats *stats,
958 struct ath9k_channel *chan);
959bool ath9k_hw_phycounters(struct ath_hal *ah);
960void ath9k_enable_mib_counters(struct ath_hal *ah);
961void ath9k_hw_disable_mib_counters(struct ath_hal *ah);
962u32 ath9k_hw_GetMibCycleCountsPct(struct ath_hal *ah,
963 u32 *rxc_pcnt,
964 u32 *rxf_pcnt,
965 u32 *txf_pcnt);
966void ath9k_hw_procmibevent(struct ath_hal *ah,
967 const struct ath9k_node_stats *stats);
968void ath9k_hw_ani_setup(struct ath_hal *ah);
969void ath9k_hw_ani_attach(struct ath_hal *ah);
970void ath9k_hw_ani_detach(struct ath_hal *ah);
971
972/* Calibration */
973
974void ath9k_hw_reset_calvalid(struct ath_hal *ah, struct ath9k_channel *chan,
975 bool *isCalDone);
976void ath9k_hw_start_nfcal(struct ath_hal *ah);
977void ath9k_hw_loadnf(struct ath_hal *ah, struct ath9k_channel *chan);
978int16_t ath9k_hw_getnf(struct ath_hal *ah,
979 struct ath9k_channel *chan);
980void ath9k_init_nfcal_hist_buffer(struct ath_hal *ah);
981s16 ath9k_hw_getchan_noise(struct ath_hal *ah, struct ath9k_channel *chan);
982bool ath9k_hw_calibrate(struct ath_hal *ah, struct ath9k_channel *chan,
983 u8 rxchainmask, bool longcal,
984 bool *isCalDone);
985bool ath9k_hw_init_cal(struct ath_hal *ah,
986 struct ath9k_channel *chan);
987
988
989/* EEPROM */
990
991int ath9k_hw_set_txpower(struct ath_hal *ah,
992 struct ath9k_channel *chan,
993 u16 cfgCtl,
994 u8 twiceAntennaReduction,
995 u8 twiceMaxRegulatoryPower,
996 u8 powerLimit);
997void ath9k_hw_set_addac(struct ath_hal *ah, struct ath9k_channel *chan);
998bool ath9k_hw_set_power_per_rate_table(struct ath_hal *ah,
999 struct ath9k_channel *chan,
1000 int16_t *ratesArray,
1001 u16 cfgCtl,
1002 u8 AntennaReduction,
1003 u8 twiceMaxRegulatoryPower,
1004 u8 powerLimit);
1005bool ath9k_hw_set_power_cal_table(struct ath_hal *ah,
1006 struct ath9k_channel *chan,
1007 int16_t *pTxPowerIndexOffset);
1008bool ath9k_hw_eeprom_set_board_values(struct ath_hal *ah,
1009 struct ath9k_channel *chan);
1010int ath9k_hw_get_eeprom_antenna_cfg(struct ath_hal *ah,
1011 struct ath9k_channel *chan,
1012 u8 index, u16 *config);
1013u8 ath9k_hw_get_num_ant_config(struct ath_hal *ah,
1014 enum ieee80211_band freq_band);
1015u16 ath9k_hw_eeprom_get_spur_chan(struct ath_hal *ah, u16 i, bool is2GHz);
1016int ath9k_hw_eeprom_attach(struct ath_hal *ah);
1017
1018/* Interrupt Handling */
1019
1020bool ath9k_hw_intrpend(struct ath_hal *ah);
1021bool ath9k_hw_getisr(struct ath_hal *ah, enum ath9k_int *masked);
1022enum ath9k_int ath9k_hw_intrget(struct ath_hal *ah);
1023enum ath9k_int ath9k_hw_set_interrupts(struct ath_hal *ah, enum ath9k_int ints);
1024
1025/* MAC (PCU/QCU) */
1026
1027void ath9k_hw_dmaRegDump(struct ath_hal *ah);
1028u32 ath9k_hw_gettxbuf(struct ath_hal *ah, u32 q);
1029bool ath9k_hw_puttxbuf(struct ath_hal *ah, u32 q, u32 txdp);
931bool ath9k_hw_txstart(struct ath_hal *ah, u32 q); 1030bool ath9k_hw_txstart(struct ath_hal *ah, u32 q);
932u16 ath9k_hw_computetxtime(struct ath_hal *ah, 1031u32 ath9k_hw_numtxpending(struct ath_hal *ah, u32 q);
933 const struct ath9k_rate_table *rates, 1032bool ath9k_hw_updatetxtriglevel(struct ath_hal *ah, bool bIncTrigLevel);
934 u32 frameLen, u16 rateix, 1033bool ath9k_hw_stoptxdma(struct ath_hal *ah, u32 q);
935 bool shortPreamble); 1034bool ath9k_hw_filltxdesc(struct ath_hal *ah, struct ath_desc *ds,
1035 u32 segLen, bool firstSeg,
1036 bool lastSeg, const struct ath_desc *ds0);
1037void ath9k_hw_cleartxdesc(struct ath_hal *ah, struct ath_desc *ds);
1038int ath9k_hw_txprocdesc(struct ath_hal *ah, struct ath_desc *ds);
1039void ath9k_hw_set11n_txdesc(struct ath_hal *ah, struct ath_desc *ds,
1040 u32 pktLen, enum ath9k_pkt_type type, u32 txPower,
1041 u32 keyIx, enum ath9k_key_type keyType, u32 flags);
936void ath9k_hw_set11n_ratescenario(struct ath_hal *ah, struct ath_desc *ds, 1042void ath9k_hw_set11n_ratescenario(struct ath_hal *ah, struct ath_desc *ds,
937 struct ath_desc *lastds, 1043 struct ath_desc *lastds,
938 u32 durUpdateEn, u32 rtsctsRate, 1044 u32 durUpdateEn, u32 rtsctsRate,
939 u32 rtsctsDuration, 1045 u32 rtsctsDuration,
940 struct ath9k_11n_rate_series series[], 1046 struct ath9k_11n_rate_series series[],
941 u32 nseries, u32 flags); 1047 u32 nseries, u32 flags);
942void ath9k_hw_set11n_burstduration(struct ath_hal *ah, 1048void ath9k_hw_set11n_aggr_first(struct ath_hal *ah, struct ath_desc *ds,
943 struct ath_desc *ds, 1049 u32 aggrLen);
1050void ath9k_hw_set11n_aggr_middle(struct ath_hal *ah, struct ath_desc *ds,
1051 u32 numDelims);
1052void ath9k_hw_set11n_aggr_last(struct ath_hal *ah, struct ath_desc *ds);
1053void ath9k_hw_clr11n_aggr(struct ath_hal *ah, struct ath_desc *ds);
1054void ath9k_hw_set11n_burstduration(struct ath_hal *ah, struct ath_desc *ds,
944 u32 burstDuration); 1055 u32 burstDuration);
945void ath9k_hw_cleartxdesc(struct ath_hal *ah, struct ath_desc *ds); 1056void ath9k_hw_set11n_virtualmorefrag(struct ath_hal *ah, struct ath_desc *ds,
946u32 ath9k_hw_reverse_bits(u32 val, u32 n); 1057 u32 vmf);
947bool ath9k_hw_resettxqueue(struct ath_hal *ah, u32 q); 1058void ath9k_hw_gettxintrtxqs(struct ath_hal *ah, u32 *txqs);
948u32 ath9k_regd_get_ctl(struct ath_hal *ah, struct ath9k_channel *chan);
949u32 ath9k_regd_get_antenna_allowed(struct ath_hal *ah,
950 struct ath9k_channel *chan);
951u32 ath9k_hw_mhz2ieee(struct ath_hal *ah, u32 freq, u32 flags);
952bool ath9k_hw_get_txq_props(struct ath_hal *ah, int q,
953 struct ath9k_tx_queue_info *qinfo);
954bool ath9k_hw_set_txq_props(struct ath_hal *ah, int q, 1059bool ath9k_hw_set_txq_props(struct ath_hal *ah, int q,
955 const struct ath9k_tx_queue_info *qinfo); 1060 const struct ath9k_tx_queue_info *qinfo);
956struct ath9k_channel *ath9k_regd_check_channel(struct ath_hal *ah, 1061bool ath9k_hw_get_txq_props(struct ath_hal *ah, int q,
957 const struct ath9k_channel *c); 1062 struct ath9k_tx_queue_info *qinfo);
958void ath9k_hw_set11n_txdesc(struct ath_hal *ah, struct ath_desc *ds, 1063int ath9k_hw_setuptxqueue(struct ath_hal *ah, enum ath9k_tx_queue type,
959 u32 pktLen, enum ath9k_pkt_type type, 1064 const struct ath9k_tx_queue_info *qinfo);
960 u32 txPower, u32 keyIx, 1065bool ath9k_hw_releasetxqueue(struct ath_hal *ah, u32 q);
961 enum ath9k_key_type keyType, u32 flags); 1066bool ath9k_hw_resettxqueue(struct ath_hal *ah, u32 q);
962bool ath9k_hw_filltxdesc(struct ath_hal *ah, struct ath_desc *ds, 1067int ath9k_hw_rxprocdesc(struct ath_hal *ah, struct ath_desc *ds,
963 u32 segLen, bool firstSeg, 1068 u32 pa, struct ath_desc *nds, u64 tsf);
964 bool lastSeg,
965 const struct ath_desc *ds0);
966u32 ath9k_hw_GetMibCycleCountsPct(struct ath_hal *ah,
967 u32 *rxc_pcnt,
968 u32 *rxf_pcnt,
969 u32 *txf_pcnt);
970void ath9k_hw_dmaRegDump(struct ath_hal *ah);
971void ath9k_hw_beaconinit(struct ath_hal *ah,
972 u32 next_beacon, u32 beacon_period);
973void ath9k_hw_set_sta_beacon_timers(struct ath_hal *ah,
974 const struct ath9k_beacon_state *bs);
975bool ath9k_hw_setuprxdesc(struct ath_hal *ah, struct ath_desc *ds, 1069bool ath9k_hw_setuprxdesc(struct ath_hal *ah, struct ath_desc *ds,
976 u32 size, u32 flags); 1070 u32 size, u32 flags);
1071bool ath9k_hw_setrxabort(struct ath_hal *ah, bool set);
977void ath9k_hw_putrxbuf(struct ath_hal *ah, u32 rxdp); 1072void ath9k_hw_putrxbuf(struct ath_hal *ah, u32 rxdp);
978void ath9k_hw_rxena(struct ath_hal *ah); 1073void ath9k_hw_rxena(struct ath_hal *ah);
979void ath9k_hw_setopmode(struct ath_hal *ah);
980bool ath9k_hw_setmac(struct ath_hal *ah, const u8 *mac);
981void ath9k_hw_setmcastfilter(struct ath_hal *ah, u32 filter0,
982 u32 filter1);
983u32 ath9k_hw_getrxfilter(struct ath_hal *ah);
984void ath9k_hw_startpcureceive(struct ath_hal *ah); 1074void ath9k_hw_startpcureceive(struct ath_hal *ah);
985void ath9k_hw_stoppcurecv(struct ath_hal *ah); 1075void ath9k_hw_stoppcurecv(struct ath_hal *ah);
986bool ath9k_hw_stopdmarecv(struct ath_hal *ah); 1076bool ath9k_hw_stopdmarecv(struct ath_hal *ah);
987int ath9k_hw_rxprocdesc(struct ath_hal *ah, 1077
988 struct ath_desc *ds, u32 pa,
989 struct ath_desc *nds, u64 tsf);
990u32 ath9k_hw_gettxbuf(struct ath_hal *ah, u32 q);
991int ath9k_hw_txprocdesc(struct ath_hal *ah,
992 struct ath_desc *ds);
993void ath9k_hw_set11n_aggr_middle(struct ath_hal *ah, struct ath_desc *ds,
994 u32 numDelims);
995void ath9k_hw_set11n_aggr_first(struct ath_hal *ah, struct ath_desc *ds,
996 u32 aggrLen);
997void ath9k_hw_set11n_aggr_last(struct ath_hal *ah, struct ath_desc *ds);
998bool ath9k_hw_releasetxqueue(struct ath_hal *ah, u32 q);
999void ath9k_hw_gettxintrtxqs(struct ath_hal *ah, u32 *txqs);
1000void ath9k_hw_clr11n_aggr(struct ath_hal *ah, struct ath_desc *ds);
1001void ath9k_hw_set11n_virtualmorefrag(struct ath_hal *ah,
1002 struct ath_desc *ds, u32 vmf);
1003bool ath9k_hw_set_txpowerlimit(struct ath_hal *ah, u32 limit);
1004bool ath9k_regd_is_public_safety_sku(struct ath_hal *ah);
1005int ath9k_hw_setuptxqueue(struct ath_hal *ah, enum ath9k_tx_queue type,
1006 const struct ath9k_tx_queue_info *qinfo);
1007u32 ath9k_hw_numtxpending(struct ath_hal *ah, u32 q);
1008const char *ath9k_hw_probe(u16 vendorid, u16 devid);
1009bool ath9k_hw_disable(struct ath_hal *ah);
1010void ath9k_hw_rfdetach(struct ath_hal *ah);
1011void ath9k_hw_get_channel_centers(struct ath_hal *ah,
1012 struct ath9k_channel *chan,
1013 struct chan_centers *centers);
1014bool ath9k_get_channel_edges(struct ath_hal *ah,
1015 u16 flags, u16 *low,
1016 u16 *high);
1017void ath9k_hw_cfg_output(struct ath_hal *ah, u32 gpio,
1018 u32 ah_signal_type);
1019void ath9k_hw_set_gpio(struct ath_hal *ah, u32 gpio, u32 value);
1020u32 ath9k_hw_gpio_get(struct ath_hal *ah, u32 gpio);
1021void ath9k_hw_cfg_gpio_input(struct ath_hal *ah, u32 gpio);
1022#endif 1078#endif
diff --git a/drivers/net/wireless/ath9k/beacon.c b/drivers/net/wireless/ath9k/beacon.c
index 9e15c30bbc06..d186cd41c235 100644
--- a/drivers/net/wireless/ath9k/beacon.c
+++ b/drivers/net/wireless/ath9k/beacon.c
@@ -114,7 +114,7 @@ static void ath_beacon_setup(struct ath_softc *sc,
114 ath9k_hw_set11n_txdesc(ah, ds, 114 ath9k_hw_set11n_txdesc(ah, ds,
115 skb->len + FCS_LEN, /* frame length */ 115 skb->len + FCS_LEN, /* frame length */
116 ATH9K_PKT_TYPE_BEACON, /* Atheros packet type */ 116 ATH9K_PKT_TYPE_BEACON, /* Atheros packet type */
117 avp->av_btxctl.txpower, /* txpower XXX */ 117 MAX_RATE_POWER, /* FIXME */
118 ATH9K_TXKEYIX_INVALID, /* no encryption */ 118 ATH9K_TXKEYIX_INVALID, /* no encryption */
119 ATH9K_KEY_TYPE_CLEAR, /* no encryption */ 119 ATH9K_KEY_TYPE_CLEAR, /* no encryption */
120 flags /* no ack, 120 flags /* no ack,
@@ -152,12 +152,14 @@ static struct ath_buf *ath_beacon_generate(struct ath_softc *sc, int if_id)
152 struct ath_vap *avp; 152 struct ath_vap *avp;
153 struct sk_buff *skb; 153 struct sk_buff *skb;
154 struct ath_txq *cabq; 154 struct ath_txq *cabq;
155 struct ieee80211_vif *vif;
155 struct ieee80211_tx_info *info; 156 struct ieee80211_tx_info *info;
156 int cabq_depth; 157 int cabq_depth;
157 158
158 avp = sc->sc_vaps[if_id]; 159 vif = sc->sc_vaps[if_id];
159 ASSERT(avp); 160 ASSERT(vif);
160 161
162 avp = (void *)vif->drv_priv;
161 cabq = sc->sc_cabq; 163 cabq = sc->sc_cabq;
162 164
163 if (avp->av_bcbuf == NULL) { 165 if (avp->av_bcbuf == NULL) {
@@ -174,7 +176,7 @@ static struct ath_buf *ath_beacon_generate(struct ath_softc *sc, int if_id)
174 PCI_DMA_TODEVICE); 176 PCI_DMA_TODEVICE);
175 } 177 }
176 178
177 skb = ieee80211_beacon_get(sc->hw, avp->av_if_data); 179 skb = ieee80211_beacon_get(sc->hw, vif);
178 bf->bf_mpdu = skb; 180 bf->bf_mpdu = skb;
179 if (skb == NULL) 181 if (skb == NULL)
180 return NULL; 182 return NULL;
@@ -196,7 +198,7 @@ static struct ath_buf *ath_beacon_generate(struct ath_softc *sc, int if_id)
196 skb_end_pointer(skb) - skb->head, 198 skb_end_pointer(skb) - skb->head,
197 PCI_DMA_TODEVICE); 199 PCI_DMA_TODEVICE);
198 200
199 skb = ieee80211_get_buffered_bc(sc->hw, avp->av_if_data); 201 skb = ieee80211_get_buffered_bc(sc->hw, vif);
200 202
201 /* 203 /*
202 * if the CABQ traffic from previous DTIM is pending and the current 204 * if the CABQ traffic from previous DTIM is pending and the current
@@ -232,7 +234,7 @@ static struct ath_buf *ath_beacon_generate(struct ath_softc *sc, int if_id)
232 */ 234 */
233 while (skb) { 235 while (skb) {
234 ath_tx_cabq(sc, skb); 236 ath_tx_cabq(sc, skb);
235 skb = ieee80211_get_buffered_bc(sc->hw, avp->av_if_data); 237 skb = ieee80211_get_buffered_bc(sc->hw, vif);
236 } 238 }
237 239
238 return bf; 240 return bf;
@@ -244,13 +246,16 @@ static struct ath_buf *ath_beacon_generate(struct ath_softc *sc, int if_id)
244*/ 246*/
245static void ath_beacon_start_adhoc(struct ath_softc *sc, int if_id) 247static void ath_beacon_start_adhoc(struct ath_softc *sc, int if_id)
246{ 248{
249 struct ieee80211_vif *vif;
247 struct ath_hal *ah = sc->sc_ah; 250 struct ath_hal *ah = sc->sc_ah;
248 struct ath_buf *bf; 251 struct ath_buf *bf;
249 struct ath_vap *avp; 252 struct ath_vap *avp;
250 struct sk_buff *skb; 253 struct sk_buff *skb;
251 254
252 avp = sc->sc_vaps[if_id]; 255 vif = sc->sc_vaps[if_id];
253 ASSERT(avp); 256 ASSERT(vif);
257
258 avp = (void *)vif->drv_priv;
254 259
255 if (avp->av_bcbuf == NULL) { 260 if (avp->av_bcbuf == NULL) {
256 DPRINTF(sc, ATH_DBG_BEACON, "%s: avp=%p av_bcbuf=%p\n", 261 DPRINTF(sc, ATH_DBG_BEACON, "%s: avp=%p av_bcbuf=%p\n",
@@ -300,14 +305,17 @@ int ath_beaconq_setup(struct ath_hal *ah)
300*/ 305*/
301int ath_beacon_alloc(struct ath_softc *sc, int if_id) 306int ath_beacon_alloc(struct ath_softc *sc, int if_id)
302{ 307{
308 struct ieee80211_vif *vif;
303 struct ath_vap *avp; 309 struct ath_vap *avp;
304 struct ieee80211_hdr *hdr; 310 struct ieee80211_hdr *hdr;
305 struct ath_buf *bf; 311 struct ath_buf *bf;
306 struct sk_buff *skb; 312 struct sk_buff *skb;
307 __le64 tstamp; 313 __le64 tstamp;
308 314
309 avp = sc->sc_vaps[if_id]; 315 vif = sc->sc_vaps[if_id];
310 ASSERT(avp); 316 ASSERT(vif);
317
318 avp = (void *)vif->drv_priv;
311 319
312 /* Allocate a beacon descriptor if we haven't done so. */ 320 /* Allocate a beacon descriptor if we haven't done so. */
313 if (!avp->av_bcbuf) { 321 if (!avp->av_bcbuf) {
@@ -363,7 +371,7 @@ int ath_beacon_alloc(struct ath_softc *sc, int if_id)
363 * FIXME: Fill avp->av_btxctl.txpower and 371 * FIXME: Fill avp->av_btxctl.txpower and
364 * avp->av_btxctl.shortPreamble 372 * avp->av_btxctl.shortPreamble
365 */ 373 */
366 skb = ieee80211_beacon_get(sc->hw, avp->av_if_data); 374 skb = ieee80211_beacon_get(sc->hw, vif);
367 if (skb == NULL) { 375 if (skb == NULL) {
368 DPRINTF(sc, ATH_DBG_BEACON, "%s: cannot get skb\n", 376 DPRINTF(sc, ATH_DBG_BEACON, "%s: cannot get skb\n",
369 __func__); 377 __func__);
@@ -652,15 +660,21 @@ void ath_bstuck_process(struct ath_softc *sc)
652 */ 660 */
653void ath_beacon_config(struct ath_softc *sc, int if_id) 661void ath_beacon_config(struct ath_softc *sc, int if_id)
654{ 662{
663 struct ieee80211_vif *vif;
655 struct ath_hal *ah = sc->sc_ah; 664 struct ath_hal *ah = sc->sc_ah;
656 struct ath_beacon_config conf; 665 struct ath_beacon_config conf;
666 struct ath_vap *avp;
657 enum ath9k_opmode av_opmode; 667 enum ath9k_opmode av_opmode;
658 u32 nexttbtt, intval; 668 u32 nexttbtt, intval;
659 669
660 if (if_id != ATH_IF_ID_ANY) 670 if (if_id != ATH_IF_ID_ANY) {
661 av_opmode = sc->sc_vaps[if_id]->av_opmode; 671 vif = sc->sc_vaps[if_id];
662 else 672 ASSERT(vif);
673 avp = (void *)vif->drv_priv;
674 av_opmode = avp->av_opmode;
675 } else {
663 av_opmode = sc->sc_ah->ah_opmode; 676 av_opmode = sc->sc_ah->ah_opmode;
677 }
664 678
665 memset(&conf, 0, sizeof(struct ath_beacon_config)); 679 memset(&conf, 0, sizeof(struct ath_beacon_config));
666 680
diff --git a/drivers/net/wireless/ath9k/calib.c b/drivers/net/wireless/ath9k/calib.c
new file mode 100644
index 000000000000..1690759fe7b8
--- /dev/null
+++ b/drivers/net/wireless/ath9k/calib.c
@@ -0,0 +1,930 @@
1/*
2 * Copyright (c) 2008 Atheros Communications Inc.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#include "core.h"
18#include "hw.h"
19#include "reg.h"
20#include "phy.h"
21
22static const int16_t NOISE_FLOOR[] = { -96, -93, -98, -96, -93, -96 };
23
24/* We can tune this as we go by monitoring really low values */
25#define ATH9K_NF_TOO_LOW -60
26
27/* AR5416 may return very high value (like -31 dBm), in those cases the nf
28 * is incorrect and we should use the static NF value. Later we can try to
29 * find out why they are reporting these values */
30
31static bool ath9k_hw_nf_in_range(struct ath_hal *ah, s16 nf)
32{
33 if (nf > ATH9K_NF_TOO_LOW) {
34 DPRINTF(ah->ah_sc, ATH_DBG_NF_CAL,
35 "%s: noise floor value detected (%d) is "
36 "lower than what we think is a "
37 "reasonable value (%d)\n",
38 __func__, nf, ATH9K_NF_TOO_LOW);
39 return false;
40 }
41 return true;
42}
43
44static int16_t ath9k_hw_get_nf_hist_mid(int16_t *nfCalBuffer)
45{
46 int16_t nfval;
47 int16_t sort[ATH9K_NF_CAL_HIST_MAX];
48 int i, j;
49
50 for (i = 0; i < ATH9K_NF_CAL_HIST_MAX; i++)
51 sort[i] = nfCalBuffer[i];
52
53 for (i = 0; i < ATH9K_NF_CAL_HIST_MAX - 1; i++) {
54 for (j = 1; j < ATH9K_NF_CAL_HIST_MAX - i; j++) {
55 if (sort[j] > sort[j - 1]) {
56 nfval = sort[j];
57 sort[j] = sort[j - 1];
58 sort[j - 1] = nfval;
59 }
60 }
61 }
62 nfval = sort[(ATH9K_NF_CAL_HIST_MAX - 1) >> 1];
63
64 return nfval;
65}
66
67static void ath9k_hw_update_nfcal_hist_buffer(struct ath9k_nfcal_hist *h,
68 int16_t *nfarray)
69{
70 int i;
71
72 for (i = 0; i < NUM_NF_READINGS; i++) {
73 h[i].nfCalBuffer[h[i].currIndex] = nfarray[i];
74
75 if (++h[i].currIndex >= ATH9K_NF_CAL_HIST_MAX)
76 h[i].currIndex = 0;
77
78 if (h[i].invalidNFcount > 0) {
79 if (nfarray[i] < AR_PHY_CCA_MIN_BAD_VALUE ||
80 nfarray[i] > AR_PHY_CCA_MAX_HIGH_VALUE) {
81 h[i].invalidNFcount = ATH9K_NF_CAL_HIST_MAX;
82 } else {
83 h[i].invalidNFcount--;
84 h[i].privNF = nfarray[i];
85 }
86 } else {
87 h[i].privNF =
88 ath9k_hw_get_nf_hist_mid(h[i].nfCalBuffer);
89 }
90 }
91 return;
92}
93
94static void ath9k_hw_do_getnf(struct ath_hal *ah,
95 int16_t nfarray[NUM_NF_READINGS])
96{
97 int16_t nf;
98
99 if (AR_SREV_9280_10_OR_LATER(ah))
100 nf = MS(REG_READ(ah, AR_PHY_CCA), AR9280_PHY_MINCCA_PWR);
101 else
102 nf = MS(REG_READ(ah, AR_PHY_CCA), AR_PHY_MINCCA_PWR);
103
104 if (nf & 0x100)
105 nf = 0 - ((nf ^ 0x1ff) + 1);
106 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
107 "NF calibrated [ctl] [chain 0] is %d\n", nf);
108 nfarray[0] = nf;
109
110 if (AR_SREV_9280_10_OR_LATER(ah))
111 nf = MS(REG_READ(ah, AR_PHY_CH1_CCA),
112 AR9280_PHY_CH1_MINCCA_PWR);
113 else
114 nf = MS(REG_READ(ah, AR_PHY_CH1_CCA),
115 AR_PHY_CH1_MINCCA_PWR);
116
117 if (nf & 0x100)
118 nf = 0 - ((nf ^ 0x1ff) + 1);
119 DPRINTF(ah->ah_sc, ATH_DBG_NF_CAL,
120 "NF calibrated [ctl] [chain 1] is %d\n", nf);
121 nfarray[1] = nf;
122
123 if (!AR_SREV_9280(ah)) {
124 nf = MS(REG_READ(ah, AR_PHY_CH2_CCA),
125 AR_PHY_CH2_MINCCA_PWR);
126 if (nf & 0x100)
127 nf = 0 - ((nf ^ 0x1ff) + 1);
128 DPRINTF(ah->ah_sc, ATH_DBG_NF_CAL,
129 "NF calibrated [ctl] [chain 2] is %d\n", nf);
130 nfarray[2] = nf;
131 }
132
133 if (AR_SREV_9280_10_OR_LATER(ah))
134 nf = MS(REG_READ(ah, AR_PHY_EXT_CCA),
135 AR9280_PHY_EXT_MINCCA_PWR);
136 else
137 nf = MS(REG_READ(ah, AR_PHY_EXT_CCA),
138 AR_PHY_EXT_MINCCA_PWR);
139
140 if (nf & 0x100)
141 nf = 0 - ((nf ^ 0x1ff) + 1);
142 DPRINTF(ah->ah_sc, ATH_DBG_NF_CAL,
143 "NF calibrated [ext] [chain 0] is %d\n", nf);
144 nfarray[3] = nf;
145
146 if (AR_SREV_9280_10_OR_LATER(ah))
147 nf = MS(REG_READ(ah, AR_PHY_CH1_EXT_CCA),
148 AR9280_PHY_CH1_EXT_MINCCA_PWR);
149 else
150 nf = MS(REG_READ(ah, AR_PHY_CH1_EXT_CCA),
151 AR_PHY_CH1_EXT_MINCCA_PWR);
152
153 if (nf & 0x100)
154 nf = 0 - ((nf ^ 0x1ff) + 1);
155 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
156 "NF calibrated [ext] [chain 1] is %d\n", nf);
157 nfarray[4] = nf;
158
159 if (!AR_SREV_9280(ah)) {
160 nf = MS(REG_READ(ah, AR_PHY_CH2_EXT_CCA),
161 AR_PHY_CH2_EXT_MINCCA_PWR);
162 if (nf & 0x100)
163 nf = 0 - ((nf ^ 0x1ff) + 1);
164 DPRINTF(ah->ah_sc, ATH_DBG_NF_CAL,
165 "NF calibrated [ext] [chain 2] is %d\n", nf);
166 nfarray[5] = nf;
167 }
168}
169
170static bool getNoiseFloorThresh(struct ath_hal *ah,
171 const struct ath9k_channel *chan,
172 int16_t *nft)
173{
174 switch (chan->chanmode) {
175 case CHANNEL_A:
176 case CHANNEL_A_HT20:
177 case CHANNEL_A_HT40PLUS:
178 case CHANNEL_A_HT40MINUS:
179 *nft = (int16_t)ath9k_hw_get_eeprom(ah, EEP_NFTHRESH_5);
180 break;
181 case CHANNEL_B:
182 case CHANNEL_G:
183 case CHANNEL_G_HT20:
184 case CHANNEL_G_HT40PLUS:
185 case CHANNEL_G_HT40MINUS:
186 *nft = (int16_t)ath9k_hw_get_eeprom(ah, EEP_NFTHRESH_2);
187 break;
188 default:
189 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
190 "%s: invalid channel flags 0x%x\n", __func__,
191 chan->channelFlags);
192 return false;
193 }
194
195 return true;
196}
197
198static void ath9k_hw_setup_calibration(struct ath_hal *ah,
199 struct hal_cal_list *currCal)
200{
201 REG_RMW_FIELD(ah, AR_PHY_TIMING_CTRL4(0),
202 AR_PHY_TIMING_CTRL4_IQCAL_LOG_COUNT_MAX,
203 currCal->calData->calCountMax);
204
205 switch (currCal->calData->calType) {
206 case IQ_MISMATCH_CAL:
207 REG_WRITE(ah, AR_PHY_CALMODE, AR_PHY_CALMODE_IQ);
208 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
209 "%s: starting IQ Mismatch Calibration\n",
210 __func__);
211 break;
212 case ADC_GAIN_CAL:
213 REG_WRITE(ah, AR_PHY_CALMODE, AR_PHY_CALMODE_ADC_GAIN);
214 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
215 "%s: starting ADC Gain Calibration\n", __func__);
216 break;
217 case ADC_DC_CAL:
218 REG_WRITE(ah, AR_PHY_CALMODE, AR_PHY_CALMODE_ADC_DC_PER);
219 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
220 "%s: starting ADC DC Calibration\n", __func__);
221 break;
222 case ADC_DC_INIT_CAL:
223 REG_WRITE(ah, AR_PHY_CALMODE, AR_PHY_CALMODE_ADC_DC_INIT);
224 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
225 "%s: starting Init ADC DC Calibration\n",
226 __func__);
227 break;
228 }
229
230 REG_SET_BIT(ah, AR_PHY_TIMING_CTRL4(0),
231 AR_PHY_TIMING_CTRL4_DO_CAL);
232}
233
234static void ath9k_hw_reset_calibration(struct ath_hal *ah,
235 struct hal_cal_list *currCal)
236{
237 struct ath_hal_5416 *ahp = AH5416(ah);
238 int i;
239
240 ath9k_hw_setup_calibration(ah, currCal);
241
242 currCal->calState = CAL_RUNNING;
243
244 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
245 ahp->ah_Meas0.sign[i] = 0;
246 ahp->ah_Meas1.sign[i] = 0;
247 ahp->ah_Meas2.sign[i] = 0;
248 ahp->ah_Meas3.sign[i] = 0;
249 }
250
251 ahp->ah_CalSamples = 0;
252}
253
254static void ath9k_hw_per_calibration(struct ath_hal *ah,
255 struct ath9k_channel *ichan,
256 u8 rxchainmask,
257 struct hal_cal_list *currCal,
258 bool *isCalDone)
259{
260 struct ath_hal_5416 *ahp = AH5416(ah);
261
262 *isCalDone = false;
263
264 if (currCal->calState == CAL_RUNNING) {
265 if (!(REG_READ(ah, AR_PHY_TIMING_CTRL4(0)) &
266 AR_PHY_TIMING_CTRL4_DO_CAL)) {
267
268 currCal->calData->calCollect(ah);
269 ahp->ah_CalSamples++;
270
271 if (ahp->ah_CalSamples >= currCal->calData->calNumSamples) {
272 int i, numChains = 0;
273 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
274 if (rxchainmask & (1 << i))
275 numChains++;
276 }
277
278 currCal->calData->calPostProc(ah, numChains);
279 ichan->CalValid |= currCal->calData->calType;
280 currCal->calState = CAL_DONE;
281 *isCalDone = true;
282 } else {
283 ath9k_hw_setup_calibration(ah, currCal);
284 }
285 }
286 } else if (!(ichan->CalValid & currCal->calData->calType)) {
287 ath9k_hw_reset_calibration(ah, currCal);
288 }
289}
290
291static bool ath9k_hw_iscal_supported(struct ath_hal *ah,
292 struct ath9k_channel *chan,
293 enum hal_cal_types calType)
294{
295 struct ath_hal_5416 *ahp = AH5416(ah);
296 bool retval = false;
297
298 switch (calType & ahp->ah_suppCals) {
299 case IQ_MISMATCH_CAL:
300 if (!IS_CHAN_B(chan))
301 retval = true;
302 break;
303 case ADC_GAIN_CAL:
304 case ADC_DC_CAL:
305 if (!IS_CHAN_B(chan)
306 && !(IS_CHAN_2GHZ(chan) && IS_CHAN_HT20(chan)))
307 retval = true;
308 break;
309 }
310
311 return retval;
312}
313
314static void ath9k_hw_iqcal_collect(struct ath_hal *ah)
315{
316 struct ath_hal_5416 *ahp = AH5416(ah);
317 int i;
318
319 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
320 ahp->ah_totalPowerMeasI[i] +=
321 REG_READ(ah, AR_PHY_CAL_MEAS_0(i));
322 ahp->ah_totalPowerMeasQ[i] +=
323 REG_READ(ah, AR_PHY_CAL_MEAS_1(i));
324 ahp->ah_totalIqCorrMeas[i] +=
325 (int32_t) REG_READ(ah, AR_PHY_CAL_MEAS_2(i));
326 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
327 "%d: Chn %d pmi=0x%08x;pmq=0x%08x;iqcm=0x%08x;\n",
328 ahp->ah_CalSamples, i, ahp->ah_totalPowerMeasI[i],
329 ahp->ah_totalPowerMeasQ[i],
330 ahp->ah_totalIqCorrMeas[i]);
331 }
332}
333
334static void ath9k_hw_adc_gaincal_collect(struct ath_hal *ah)
335{
336 struct ath_hal_5416 *ahp = AH5416(ah);
337 int i;
338
339 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
340 ahp->ah_totalAdcIOddPhase[i] +=
341 REG_READ(ah, AR_PHY_CAL_MEAS_0(i));
342 ahp->ah_totalAdcIEvenPhase[i] +=
343 REG_READ(ah, AR_PHY_CAL_MEAS_1(i));
344 ahp->ah_totalAdcQOddPhase[i] +=
345 REG_READ(ah, AR_PHY_CAL_MEAS_2(i));
346 ahp->ah_totalAdcQEvenPhase[i] +=
347 REG_READ(ah, AR_PHY_CAL_MEAS_3(i));
348
349 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
350 "%d: Chn %d oddi=0x%08x; eveni=0x%08x; "
351 "oddq=0x%08x; evenq=0x%08x;\n",
352 ahp->ah_CalSamples, i,
353 ahp->ah_totalAdcIOddPhase[i],
354 ahp->ah_totalAdcIEvenPhase[i],
355 ahp->ah_totalAdcQOddPhase[i],
356 ahp->ah_totalAdcQEvenPhase[i]);
357 }
358}
359
360static void ath9k_hw_adc_dccal_collect(struct ath_hal *ah)
361{
362 struct ath_hal_5416 *ahp = AH5416(ah);
363 int i;
364
365 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
366 ahp->ah_totalAdcDcOffsetIOddPhase[i] +=
367 (int32_t) REG_READ(ah, AR_PHY_CAL_MEAS_0(i));
368 ahp->ah_totalAdcDcOffsetIEvenPhase[i] +=
369 (int32_t) REG_READ(ah, AR_PHY_CAL_MEAS_1(i));
370 ahp->ah_totalAdcDcOffsetQOddPhase[i] +=
371 (int32_t) REG_READ(ah, AR_PHY_CAL_MEAS_2(i));
372 ahp->ah_totalAdcDcOffsetQEvenPhase[i] +=
373 (int32_t) REG_READ(ah, AR_PHY_CAL_MEAS_3(i));
374
375 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
376 "%d: Chn %d oddi=0x%08x; eveni=0x%08x; "
377 "oddq=0x%08x; evenq=0x%08x;\n",
378 ahp->ah_CalSamples, i,
379 ahp->ah_totalAdcDcOffsetIOddPhase[i],
380 ahp->ah_totalAdcDcOffsetIEvenPhase[i],
381 ahp->ah_totalAdcDcOffsetQOddPhase[i],
382 ahp->ah_totalAdcDcOffsetQEvenPhase[i]);
383 }
384}
385
386static void ath9k_hw_iqcalibrate(struct ath_hal *ah, u8 numChains)
387{
388 struct ath_hal_5416 *ahp = AH5416(ah);
389 u32 powerMeasQ, powerMeasI, iqCorrMeas;
390 u32 qCoffDenom, iCoffDenom;
391 int32_t qCoff, iCoff;
392 int iqCorrNeg, i;
393
394 for (i = 0; i < numChains; i++) {
395 powerMeasI = ahp->ah_totalPowerMeasI[i];
396 powerMeasQ = ahp->ah_totalPowerMeasQ[i];
397 iqCorrMeas = ahp->ah_totalIqCorrMeas[i];
398
399 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
400 "Starting IQ Cal and Correction for Chain %d\n",
401 i);
402
403 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
404 "Orignal: Chn %diq_corr_meas = 0x%08x\n",
405 i, ahp->ah_totalIqCorrMeas[i]);
406
407 iqCorrNeg = 0;
408
409 if (iqCorrMeas > 0x80000000) {
410 iqCorrMeas = (0xffffffff - iqCorrMeas) + 1;
411 iqCorrNeg = 1;
412 }
413
414 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
415 "Chn %d pwr_meas_i = 0x%08x\n", i, powerMeasI);
416 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
417 "Chn %d pwr_meas_q = 0x%08x\n", i, powerMeasQ);
418 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE, "iqCorrNeg is 0x%08x\n",
419 iqCorrNeg);
420
421 iCoffDenom = (powerMeasI / 2 + powerMeasQ / 2) / 128;
422 qCoffDenom = powerMeasQ / 64;
423
424 if (powerMeasQ != 0) {
425 iCoff = iqCorrMeas / iCoffDenom;
426 qCoff = powerMeasI / qCoffDenom - 64;
427 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
428 "Chn %d iCoff = 0x%08x\n", i, iCoff);
429 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
430 "Chn %d qCoff = 0x%08x\n", i, qCoff);
431
432 iCoff = iCoff & 0x3f;
433 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
434 "New: Chn %d iCoff = 0x%08x\n", i, iCoff);
435 if (iqCorrNeg == 0x0)
436 iCoff = 0x40 - iCoff;
437
438 if (qCoff > 15)
439 qCoff = 15;
440 else if (qCoff <= -16)
441 qCoff = 16;
442
443 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
444 "Chn %d : iCoff = 0x%x qCoff = 0x%x\n",
445 i, iCoff, qCoff);
446
447 REG_RMW_FIELD(ah, AR_PHY_TIMING_CTRL4(i),
448 AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF,
449 iCoff);
450 REG_RMW_FIELD(ah, AR_PHY_TIMING_CTRL4(i),
451 AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF,
452 qCoff);
453 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
454 "IQ Cal and Correction done for Chain %d\n",
455 i);
456 }
457 }
458
459 REG_SET_BIT(ah, AR_PHY_TIMING_CTRL4(0),
460 AR_PHY_TIMING_CTRL4_IQCORR_ENABLE);
461}
462
463static void ath9k_hw_adc_gaincal_calibrate(struct ath_hal *ah, u8 numChains)
464{
465 struct ath_hal_5416 *ahp = AH5416(ah);
466 u32 iOddMeasOffset, iEvenMeasOffset, qOddMeasOffset, qEvenMeasOffset;
467 u32 qGainMismatch, iGainMismatch, val, i;
468
469 for (i = 0; i < numChains; i++) {
470 iOddMeasOffset = ahp->ah_totalAdcIOddPhase[i];
471 iEvenMeasOffset = ahp->ah_totalAdcIEvenPhase[i];
472 qOddMeasOffset = ahp->ah_totalAdcQOddPhase[i];
473 qEvenMeasOffset = ahp->ah_totalAdcQEvenPhase[i];
474
475 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
476 "Starting ADC Gain Cal for Chain %d\n", i);
477
478 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
479 "Chn %d pwr_meas_odd_i = 0x%08x\n", i,
480 iOddMeasOffset);
481 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
482 "Chn %d pwr_meas_even_i = 0x%08x\n", i,
483 iEvenMeasOffset);
484 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
485 "Chn %d pwr_meas_odd_q = 0x%08x\n", i,
486 qOddMeasOffset);
487 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
488 "Chn %d pwr_meas_even_q = 0x%08x\n", i,
489 qEvenMeasOffset);
490
491 if (iOddMeasOffset != 0 && qEvenMeasOffset != 0) {
492 iGainMismatch =
493 ((iEvenMeasOffset * 32) /
494 iOddMeasOffset) & 0x3f;
495 qGainMismatch =
496 ((qOddMeasOffset * 32) /
497 qEvenMeasOffset) & 0x3f;
498
499 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
500 "Chn %d gain_mismatch_i = 0x%08x\n", i,
501 iGainMismatch);
502 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
503 "Chn %d gain_mismatch_q = 0x%08x\n", i,
504 qGainMismatch);
505
506 val = REG_READ(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(i));
507 val &= 0xfffff000;
508 val |= (qGainMismatch) | (iGainMismatch << 6);
509 REG_WRITE(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(i), val);
510
511 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
512 "ADC Gain Cal done for Chain %d\n", i);
513 }
514 }
515
516 REG_WRITE(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(0),
517 REG_READ(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(0)) |
518 AR_PHY_NEW_ADC_GAIN_CORR_ENABLE);
519}
520
521static void ath9k_hw_adc_dccal_calibrate(struct ath_hal *ah, u8 numChains)
522{
523 struct ath_hal_5416 *ahp = AH5416(ah);
524 u32 iOddMeasOffset, iEvenMeasOffset, val, i;
525 int32_t qOddMeasOffset, qEvenMeasOffset, qDcMismatch, iDcMismatch;
526 const struct hal_percal_data *calData =
527 ahp->ah_cal_list_curr->calData;
528 u32 numSamples =
529 (1 << (calData->calCountMax + 5)) * calData->calNumSamples;
530
531 for (i = 0; i < numChains; i++) {
532 iOddMeasOffset = ahp->ah_totalAdcDcOffsetIOddPhase[i];
533 iEvenMeasOffset = ahp->ah_totalAdcDcOffsetIEvenPhase[i];
534 qOddMeasOffset = ahp->ah_totalAdcDcOffsetQOddPhase[i];
535 qEvenMeasOffset = ahp->ah_totalAdcDcOffsetQEvenPhase[i];
536
537 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
538 "Starting ADC DC Offset Cal for Chain %d\n", i);
539
540 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
541 "Chn %d pwr_meas_odd_i = %d\n", i,
542 iOddMeasOffset);
543 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
544 "Chn %d pwr_meas_even_i = %d\n", i,
545 iEvenMeasOffset);
546 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
547 "Chn %d pwr_meas_odd_q = %d\n", i,
548 qOddMeasOffset);
549 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
550 "Chn %d pwr_meas_even_q = %d\n", i,
551 qEvenMeasOffset);
552
553 iDcMismatch = (((iEvenMeasOffset - iOddMeasOffset) * 2) /
554 numSamples) & 0x1ff;
555 qDcMismatch = (((qOddMeasOffset - qEvenMeasOffset) * 2) /
556 numSamples) & 0x1ff;
557
558 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
559 "Chn %d dc_offset_mismatch_i = 0x%08x\n", i,
560 iDcMismatch);
561 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
562 "Chn %d dc_offset_mismatch_q = 0x%08x\n", i,
563 qDcMismatch);
564
565 val = REG_READ(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(i));
566 val &= 0xc0000fff;
567 val |= (qDcMismatch << 12) | (iDcMismatch << 21);
568 REG_WRITE(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(i), val);
569
570 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
571 "ADC DC Offset Cal done for Chain %d\n", i);
572 }
573
574 REG_WRITE(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(0),
575 REG_READ(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(0)) |
576 AR_PHY_NEW_ADC_DC_OFFSET_CORR_ENABLE);
577}
578
579void ath9k_hw_reset_calvalid(struct ath_hal *ah, struct ath9k_channel *chan,
580 bool *isCalDone)
581{
582 struct ath_hal_5416 *ahp = AH5416(ah);
583 struct ath9k_channel *ichan =
584 ath9k_regd_check_channel(ah, chan);
585 struct hal_cal_list *currCal = ahp->ah_cal_list_curr;
586
587 *isCalDone = true;
588
589 if (!AR_SREV_9100(ah) && !AR_SREV_9160_10_OR_LATER(ah))
590 return;
591
592 if (currCal == NULL)
593 return;
594
595 if (ichan == NULL) {
596 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
597 "%s: invalid channel %u/0x%x; no mapping\n",
598 __func__, chan->channel, chan->channelFlags);
599 return;
600 }
601
602
603 if (currCal->calState != CAL_DONE) {
604 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
605 "%s: Calibration state incorrect, %d\n",
606 __func__, currCal->calState);
607 return;
608 }
609
610
611 if (!ath9k_hw_iscal_supported(ah, chan, currCal->calData->calType))
612 return;
613
614 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
615 "%s: Resetting Cal %d state for channel %u/0x%x\n",
616 __func__, currCal->calData->calType, chan->channel,
617 chan->channelFlags);
618
619 ichan->CalValid &= ~currCal->calData->calType;
620 currCal->calState = CAL_WAITING;
621
622 *isCalDone = false;
623}
624
625void ath9k_hw_start_nfcal(struct ath_hal *ah)
626{
627 REG_SET_BIT(ah, AR_PHY_AGC_CONTROL,
628 AR_PHY_AGC_CONTROL_ENABLE_NF);
629 REG_SET_BIT(ah, AR_PHY_AGC_CONTROL,
630 AR_PHY_AGC_CONTROL_NO_UPDATE_NF);
631 REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_NF);
632}
633
634void ath9k_hw_loadnf(struct ath_hal *ah, struct ath9k_channel *chan)
635{
636 struct ath9k_nfcal_hist *h;
637 int i, j;
638 int32_t val;
639 const u32 ar5416_cca_regs[6] = {
640 AR_PHY_CCA,
641 AR_PHY_CH1_CCA,
642 AR_PHY_CH2_CCA,
643 AR_PHY_EXT_CCA,
644 AR_PHY_CH1_EXT_CCA,
645 AR_PHY_CH2_EXT_CCA
646 };
647 u8 chainmask;
648
649 if (AR_SREV_9280(ah))
650 chainmask = 0x1B;
651 else
652 chainmask = 0x3F;
653
654#ifdef ATH_NF_PER_CHAN
655 h = chan->nfCalHist;
656#else
657 h = ah->nfCalHist;
658#endif
659
660 for (i = 0; i < NUM_NF_READINGS; i++) {
661 if (chainmask & (1 << i)) {
662 val = REG_READ(ah, ar5416_cca_regs[i]);
663 val &= 0xFFFFFE00;
664 val |= (((u32) (h[i].privNF) << 1) & 0x1ff);
665 REG_WRITE(ah, ar5416_cca_regs[i], val);
666 }
667 }
668
669 REG_CLR_BIT(ah, AR_PHY_AGC_CONTROL,
670 AR_PHY_AGC_CONTROL_ENABLE_NF);
671 REG_CLR_BIT(ah, AR_PHY_AGC_CONTROL,
672 AR_PHY_AGC_CONTROL_NO_UPDATE_NF);
673 REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_NF);
674
675 for (j = 0; j < 1000; j++) {
676 if ((REG_READ(ah, AR_PHY_AGC_CONTROL) &
677 AR_PHY_AGC_CONTROL_NF) == 0)
678 break;
679 udelay(10);
680 }
681
682 for (i = 0; i < NUM_NF_READINGS; i++) {
683 if (chainmask & (1 << i)) {
684 val = REG_READ(ah, ar5416_cca_regs[i]);
685 val &= 0xFFFFFE00;
686 val |= (((u32) (-50) << 1) & 0x1ff);
687 REG_WRITE(ah, ar5416_cca_regs[i], val);
688 }
689 }
690}
691
692int16_t ath9k_hw_getnf(struct ath_hal *ah,
693 struct ath9k_channel *chan)
694{
695 int16_t nf, nfThresh;
696 int16_t nfarray[NUM_NF_READINGS] = { 0 };
697 struct ath9k_nfcal_hist *h;
698 u8 chainmask;
699
700 if (AR_SREV_9280(ah))
701 chainmask = 0x1B;
702 else
703 chainmask = 0x3F;
704
705 chan->channelFlags &= (~CHANNEL_CW_INT);
706 if (REG_READ(ah, AR_PHY_AGC_CONTROL) & AR_PHY_AGC_CONTROL_NF) {
707 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
708 "%s: NF did not complete in calibration window\n",
709 __func__);
710 nf = 0;
711 chan->rawNoiseFloor = nf;
712 return chan->rawNoiseFloor;
713 } else {
714 ath9k_hw_do_getnf(ah, nfarray);
715 nf = nfarray[0];
716 if (getNoiseFloorThresh(ah, chan, &nfThresh)
717 && nf > nfThresh) {
718 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
719 "%s: noise floor failed detected; "
720 "detected %d, threshold %d\n", __func__,
721 nf, nfThresh);
722 chan->channelFlags |= CHANNEL_CW_INT;
723 }
724 }
725
726#ifdef ATH_NF_PER_CHAN
727 h = chan->nfCalHist;
728#else
729 h = ah->nfCalHist;
730#endif
731
732 ath9k_hw_update_nfcal_hist_buffer(h, nfarray);
733 chan->rawNoiseFloor = h[0].privNF;
734
735 return chan->rawNoiseFloor;
736}
737
738void ath9k_init_nfcal_hist_buffer(struct ath_hal *ah)
739{
740 int i, j;
741
742 for (i = 0; i < NUM_NF_READINGS; i++) {
743 ah->nfCalHist[i].currIndex = 0;
744 ah->nfCalHist[i].privNF = AR_PHY_CCA_MAX_GOOD_VALUE;
745 ah->nfCalHist[i].invalidNFcount =
746 AR_PHY_CCA_FILTERWINDOW_LENGTH;
747 for (j = 0; j < ATH9K_NF_CAL_HIST_MAX; j++) {
748 ah->nfCalHist[i].nfCalBuffer[j] =
749 AR_PHY_CCA_MAX_GOOD_VALUE;
750 }
751 }
752 return;
753}
754
755s16 ath9k_hw_getchan_noise(struct ath_hal *ah, struct ath9k_channel *chan)
756{
757 struct ath9k_channel *ichan;
758 s16 nf;
759
760 ichan = ath9k_regd_check_channel(ah, chan);
761 if (ichan == NULL) {
762 DPRINTF(ah->ah_sc, ATH_DBG_NF_CAL,
763 "%s: invalid channel %u/0x%x; no mapping\n",
764 __func__, chan->channel, chan->channelFlags);
765 return ATH_DEFAULT_NOISE_FLOOR;
766 }
767 if (ichan->rawNoiseFloor == 0) {
768 enum wireless_mode mode = ath9k_hw_chan2wmode(ah, chan);
769 nf = NOISE_FLOOR[mode];
770 } else
771 nf = ichan->rawNoiseFloor;
772
773 if (!ath9k_hw_nf_in_range(ah, nf))
774 nf = ATH_DEFAULT_NOISE_FLOOR;
775
776 return nf;
777}
778
779bool ath9k_hw_calibrate(struct ath_hal *ah, struct ath9k_channel *chan,
780 u8 rxchainmask, bool longcal,
781 bool *isCalDone)
782{
783 struct ath_hal_5416 *ahp = AH5416(ah);
784 struct hal_cal_list *currCal = ahp->ah_cal_list_curr;
785 struct ath9k_channel *ichan = ath9k_regd_check_channel(ah, chan);
786
787 *isCalDone = true;
788
789 if (ichan == NULL) {
790 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
791 "%s: invalid channel %u/0x%x; no mapping\n",
792 __func__, chan->channel, chan->channelFlags);
793 return false;
794 }
795
796 if (currCal &&
797 (currCal->calState == CAL_RUNNING ||
798 currCal->calState == CAL_WAITING)) {
799 ath9k_hw_per_calibration(ah, ichan, rxchainmask, currCal,
800 isCalDone);
801 if (*isCalDone) {
802 ahp->ah_cal_list_curr = currCal = currCal->calNext;
803
804 if (currCal->calState == CAL_WAITING) {
805 *isCalDone = false;
806 ath9k_hw_reset_calibration(ah, currCal);
807 }
808 }
809 }
810
811 if (longcal) {
812 ath9k_hw_getnf(ah, ichan);
813 ath9k_hw_loadnf(ah, ah->ah_curchan);
814 ath9k_hw_start_nfcal(ah);
815
816 if ((ichan->channelFlags & CHANNEL_CW_INT) != 0) {
817 chan->channelFlags |= CHANNEL_CW_INT;
818 ichan->channelFlags &= ~CHANNEL_CW_INT;
819 }
820 }
821
822 return true;
823}
824
825bool ath9k_hw_init_cal(struct ath_hal *ah,
826 struct ath9k_channel *chan)
827{
828 struct ath_hal_5416 *ahp = AH5416(ah);
829 struct ath9k_channel *ichan = ath9k_regd_check_channel(ah, chan);
830
831 REG_WRITE(ah, AR_PHY_AGC_CONTROL,
832 REG_READ(ah, AR_PHY_AGC_CONTROL) |
833 AR_PHY_AGC_CONTROL_CAL);
834
835 if (!ath9k_hw_wait(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_CAL, 0)) {
836 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
837 "%s: offset calibration failed to complete in 1ms; "
838 "noisy environment?\n", __func__);
839 return false;
840 }
841
842 REG_WRITE(ah, AR_PHY_AGC_CONTROL,
843 REG_READ(ah, AR_PHY_AGC_CONTROL) |
844 AR_PHY_AGC_CONTROL_NF);
845
846 ahp->ah_cal_list = ahp->ah_cal_list_last = ahp->ah_cal_list_curr = NULL;
847
848 if (AR_SREV_9100(ah) || AR_SREV_9160_10_OR_LATER(ah)) {
849 if (ath9k_hw_iscal_supported(ah, chan, ADC_GAIN_CAL)) {
850 INIT_CAL(&ahp->ah_adcGainCalData);
851 INSERT_CAL(ahp, &ahp->ah_adcGainCalData);
852 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
853 "%s: enabling ADC Gain Calibration.\n",
854 __func__);
855 }
856 if (ath9k_hw_iscal_supported(ah, chan, ADC_DC_CAL)) {
857 INIT_CAL(&ahp->ah_adcDcCalData);
858 INSERT_CAL(ahp, &ahp->ah_adcDcCalData);
859 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
860 "%s: enabling ADC DC Calibration.\n",
861 __func__);
862 }
863 if (ath9k_hw_iscal_supported(ah, chan, IQ_MISMATCH_CAL)) {
864 INIT_CAL(&ahp->ah_iqCalData);
865 INSERT_CAL(ahp, &ahp->ah_iqCalData);
866 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
867 "%s: enabling IQ Calibration.\n",
868 __func__);
869 }
870
871 ahp->ah_cal_list_curr = ahp->ah_cal_list;
872
873 if (ahp->ah_cal_list_curr)
874 ath9k_hw_reset_calibration(ah, ahp->ah_cal_list_curr);
875 }
876
877 ichan->CalValid = 0;
878
879 return true;
880}
881
882const struct hal_percal_data iq_cal_multi_sample = {
883 IQ_MISMATCH_CAL,
884 MAX_CAL_SAMPLES,
885 PER_MIN_LOG_COUNT,
886 ath9k_hw_iqcal_collect,
887 ath9k_hw_iqcalibrate
888};
889const struct hal_percal_data iq_cal_single_sample = {
890 IQ_MISMATCH_CAL,
891 MIN_CAL_SAMPLES,
892 PER_MAX_LOG_COUNT,
893 ath9k_hw_iqcal_collect,
894 ath9k_hw_iqcalibrate
895};
896const struct hal_percal_data adc_gain_cal_multi_sample = {
897 ADC_GAIN_CAL,
898 MAX_CAL_SAMPLES,
899 PER_MIN_LOG_COUNT,
900 ath9k_hw_adc_gaincal_collect,
901 ath9k_hw_adc_gaincal_calibrate
902};
903const struct hal_percal_data adc_gain_cal_single_sample = {
904 ADC_GAIN_CAL,
905 MIN_CAL_SAMPLES,
906 PER_MAX_LOG_COUNT,
907 ath9k_hw_adc_gaincal_collect,
908 ath9k_hw_adc_gaincal_calibrate
909};
910const struct hal_percal_data adc_dc_cal_multi_sample = {
911 ADC_DC_CAL,
912 MAX_CAL_SAMPLES,
913 PER_MIN_LOG_COUNT,
914 ath9k_hw_adc_dccal_collect,
915 ath9k_hw_adc_dccal_calibrate
916};
917const struct hal_percal_data adc_dc_cal_single_sample = {
918 ADC_DC_CAL,
919 MIN_CAL_SAMPLES,
920 PER_MAX_LOG_COUNT,
921 ath9k_hw_adc_dccal_collect,
922 ath9k_hw_adc_dccal_calibrate
923};
924const struct hal_percal_data adc_init_dc_cal = {
925 ADC_DC_INIT_CAL,
926 MIN_CAL_SAMPLES,
927 INIT_LOG_COUNT,
928 ath9k_hw_adc_dccal_collect,
929 ath9k_hw_adc_dccal_calibrate
930};
diff --git a/drivers/net/wireless/ath9k/core.c b/drivers/net/wireless/ath9k/core.c
index 0089e023c609..5f5184acb274 100644
--- a/drivers/net/wireless/ath9k/core.c
+++ b/drivers/net/wireless/ath9k/core.c
@@ -14,13 +14,9 @@
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */ 15 */
16 16
17 /* Implementation of the main "ATH" layer. */
18
19#include "core.h" 17#include "core.h"
20#include "regd.h" 18#include "regd.h"
21 19
22static int ath_outdoor; /* enable outdoor use */
23
24static u32 ath_chainmask_sel_up_rssi_thres = 20static u32 ath_chainmask_sel_up_rssi_thres =
25 ATH_CHAINMASK_SEL_UP_RSSI_THRES; 21 ATH_CHAINMASK_SEL_UP_RSSI_THRES;
26static u32 ath_chainmask_sel_down_rssi_thres = 22static u32 ath_chainmask_sel_down_rssi_thres =
@@ -47,6 +43,41 @@ static void bus_read_cachesize(struct ath_softc *sc, int *csz)
47 *csz = DEFAULT_CACHELINE >> 2; /* Use the default size */ 43 *csz = DEFAULT_CACHELINE >> 2; /* Use the default size */
48} 44}
49 45
46static u8 parse_mpdudensity(u8 mpdudensity)
47{
48 /*
49 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
50 * 0 for no restriction
51 * 1 for 1/4 us
52 * 2 for 1/2 us
53 * 3 for 1 us
54 * 4 for 2 us
55 * 5 for 4 us
56 * 6 for 8 us
57 * 7 for 16 us
58 */
59 switch (mpdudensity) {
60 case 0:
61 return 0;
62 case 1:
63 case 2:
64 case 3:
65 /* Our lower layer calculations limit our precision to
66 1 microsecond */
67 return 1;
68 case 4:
69 return 2;
70 case 5:
71 return 4;
72 case 6:
73 return 8;
74 case 7:
75 return 16;
76 default:
77 return 0;
78 }
79}
80
50/* 81/*
51 * Set current operating mode 82 * Set current operating mode
52 * 83 *
@@ -155,17 +186,10 @@ static int ath_setup_channels(struct ath_softc *sc)
155 struct ath9k_channel *c; 186 struct ath9k_channel *c;
156 187
157 /* Fill in ah->ah_channels */ 188 /* Fill in ah->ah_channels */
158 if (!ath9k_regd_init_channels(ah, 189 if (!ath9k_regd_init_channels(ah, ATH_CHAN_MAX, (u32 *)&nchan,
159 ATH_CHAN_MAX, 190 regclassids, ATH_REGCLASSIDS_MAX,
160 (u32 *)&nchan, 191 &nregclass, CTRY_DEFAULT, false, 1)) {
161 regclassids,
162 ATH_REGCLASSIDS_MAX,
163 &nregclass,
164 CTRY_DEFAULT,
165 false,
166 1)) {
167 u32 rd = ah->ah_currentRD; 192 u32 rd = ah->ah_currentRD;
168
169 DPRINTF(sc, ATH_DBG_FATAL, 193 DPRINTF(sc, ATH_DBG_FATAL,
170 "%s: unable to collect channel list; " 194 "%s: unable to collect channel list; "
171 "regdomain likely %u country code %u\n", 195 "regdomain likely %u country code %u\n",
@@ -186,40 +210,32 @@ static int ath_setup_channels(struct ath_softc *sc)
186 chan_2ghz[a].max_power = c->maxTxPower; 210 chan_2ghz[a].max_power = c->maxTxPower;
187 211
188 if (c->privFlags & CHANNEL_DISALLOW_ADHOC) 212 if (c->privFlags & CHANNEL_DISALLOW_ADHOC)
189 chan_2ghz[a].flags |= 213 chan_2ghz[a].flags |= IEEE80211_CHAN_NO_IBSS;
190 IEEE80211_CHAN_NO_IBSS;
191 if (c->channelFlags & CHANNEL_PASSIVE) 214 if (c->channelFlags & CHANNEL_PASSIVE)
192 chan_2ghz[a].flags |= 215 chan_2ghz[a].flags |= IEEE80211_CHAN_PASSIVE_SCAN;
193 IEEE80211_CHAN_PASSIVE_SCAN;
194 216
195 band_2ghz->n_channels = ++a; 217 band_2ghz->n_channels = ++a;
196 218
197 DPRINTF(sc, ATH_DBG_CONFIG, 219 DPRINTF(sc, ATH_DBG_CONFIG,
198 "%s: 2MHz channel: %d, " 220 "%s: 2MHz channel: %d, "
199 "channelFlags: 0x%x\n", 221 "channelFlags: 0x%x\n",
200 __func__, 222 __func__, c->channel, c->channelFlags);
201 c->channel,
202 c->channelFlags);
203 } else if (IS_CHAN_5GHZ(c)) { 223 } else if (IS_CHAN_5GHZ(c)) {
204 chan_5ghz[b].band = IEEE80211_BAND_5GHZ; 224 chan_5ghz[b].band = IEEE80211_BAND_5GHZ;
205 chan_5ghz[b].center_freq = c->channel; 225 chan_5ghz[b].center_freq = c->channel;
206 chan_5ghz[b].max_power = c->maxTxPower; 226 chan_5ghz[b].max_power = c->maxTxPower;
207 227
208 if (c->privFlags & CHANNEL_DISALLOW_ADHOC) 228 if (c->privFlags & CHANNEL_DISALLOW_ADHOC)
209 chan_5ghz[b].flags |= 229 chan_5ghz[b].flags |= IEEE80211_CHAN_NO_IBSS;
210 IEEE80211_CHAN_NO_IBSS;
211 if (c->channelFlags & CHANNEL_PASSIVE) 230 if (c->channelFlags & CHANNEL_PASSIVE)
212 chan_5ghz[b].flags |= 231 chan_5ghz[b].flags |= IEEE80211_CHAN_PASSIVE_SCAN;
213 IEEE80211_CHAN_PASSIVE_SCAN;
214 232
215 band_5ghz->n_channels = ++b; 233 band_5ghz->n_channels = ++b;
216 234
217 DPRINTF(sc, ATH_DBG_CONFIG, 235 DPRINTF(sc, ATH_DBG_CONFIG,
218 "%s: 5MHz channel: %d, " 236 "%s: 5MHz channel: %d, "
219 "channelFlags: 0x%x\n", 237 "channelFlags: 0x%x\n",
220 __func__, 238 __func__, c->channel, c->channelFlags);
221 c->channel,
222 c->channelFlags);
223 } 239 }
224 } 240 }
225 241
@@ -261,44 +277,6 @@ static enum wireless_mode ath_chan2mode(struct ath9k_channel *chan)
261} 277}
262 278
263/* 279/*
264 * Stop the device, grabbing the top-level lock to protect
265 * against concurrent entry through ath_init (which can happen
266 * if another thread does a system call and the thread doing the
267 * stop is preempted).
268 */
269
270static int ath_stop(struct ath_softc *sc)
271{
272 struct ath_hal *ah = sc->sc_ah;
273
274 DPRINTF(sc, ATH_DBG_CONFIG, "%s: invalid %ld\n",
275 __func__, sc->sc_flags & SC_OP_INVALID);
276
277 /*
278 * Shutdown the hardware and driver:
279 * stop output from above
280 * turn off timers
281 * disable interrupts
282 * clear transmit machinery
283 * clear receive machinery
284 * turn off the radio
285 * reclaim beacon resources
286 *
287 * Note that some of this work is not possible if the
288 * hardware is gone (invalid).
289 */
290
291 ath_draintxq(sc, false);
292 if (!(sc->sc_flags & SC_OP_INVALID)) {
293 ath_stoprecv(sc);
294 ath9k_hw_phy_disable(ah);
295 } else
296 sc->sc_rxlink = NULL;
297
298 return 0;
299}
300
301/*
302 * Set the current channel 280 * Set the current channel
303 * 281 *
304 * Set/change channels. If the channel is really being changed, it's done 282 * Set/change channels. If the channel is really being changed, it's done
@@ -606,114 +584,6 @@ static void ath_ani_calibrate(unsigned long data)
606 mod_timer(&sc->sc_ani.timer, jiffies + msecs_to_jiffies(cal_interval)); 584 mod_timer(&sc->sc_ani.timer, jiffies + msecs_to_jiffies(cal_interval));
607} 585}
608 586
609/******************/
610/* VAP management */
611/******************/
612
613int ath_vap_attach(struct ath_softc *sc,
614 int if_id,
615 struct ieee80211_vif *if_data,
616 enum ath9k_opmode opmode)
617{
618 struct ath_vap *avp;
619
620 if (if_id >= ATH_BCBUF || sc->sc_vaps[if_id] != NULL) {
621 DPRINTF(sc, ATH_DBG_FATAL,
622 "%s: Invalid interface id = %u\n", __func__, if_id);
623 return -EINVAL;
624 }
625
626 switch (opmode) {
627 case ATH9K_M_STA:
628 case ATH9K_M_IBSS:
629 case ATH9K_M_MONITOR:
630 break;
631 case ATH9K_M_HOSTAP:
632 /* XXX not right, beacon buffer is allocated on RUN trans */
633 if (list_empty(&sc->sc_bbuf))
634 return -ENOMEM;
635 break;
636 default:
637 return -EINVAL;
638 }
639
640 /* create ath_vap */
641 avp = kmalloc(sizeof(struct ath_vap), GFP_KERNEL);
642 if (avp == NULL)
643 return -ENOMEM;
644
645 memset(avp, 0, sizeof(struct ath_vap));
646 avp->av_if_data = if_data;
647 /* Set the VAP opmode */
648 avp->av_opmode = opmode;
649 avp->av_bslot = -1;
650
651 if (opmode == ATH9K_M_HOSTAP)
652 ath9k_hw_set_tsfadjust(sc->sc_ah, 1);
653
654 sc->sc_vaps[if_id] = avp;
655 sc->sc_nvaps++;
656 /* Set the device opmode */
657 sc->sc_ah->ah_opmode = opmode;
658
659 /* default VAP configuration */
660 avp->av_config.av_fixed_rateset = IEEE80211_FIXED_RATE_NONE;
661 avp->av_config.av_fixed_retryset = 0x03030303;
662
663 return 0;
664}
665
666int ath_vap_detach(struct ath_softc *sc, int if_id)
667{
668 struct ath_hal *ah = sc->sc_ah;
669 struct ath_vap *avp;
670
671 avp = sc->sc_vaps[if_id];
672 if (avp == NULL) {
673 DPRINTF(sc, ATH_DBG_FATAL, "%s: invalid interface id %u\n",
674 __func__, if_id);
675 return -EINVAL;
676 }
677
678 /*
679 * Quiesce the hardware while we remove the vap. In
680 * particular we need to reclaim all references to the
681 * vap state by any frames pending on the tx queues.
682 *
683 * XXX can we do this w/o affecting other vap's?
684 */
685 ath9k_hw_set_interrupts(ah, 0); /* disable interrupts */
686 ath_draintxq(sc, false); /* stop xmit side */
687 ath_stoprecv(sc); /* stop recv side */
688 ath_flushrecv(sc); /* flush recv queue */
689
690 kfree(avp);
691 sc->sc_vaps[if_id] = NULL;
692 sc->sc_nvaps--;
693
694 return 0;
695}
696
697int ath_vap_config(struct ath_softc *sc,
698 int if_id, struct ath_vap_config *if_config)
699{
700 struct ath_vap *avp;
701
702 if (if_id >= ATH_BCBUF) {
703 DPRINTF(sc, ATH_DBG_FATAL,
704 "%s: Invalid interface id = %u\n", __func__, if_id);
705 return -EINVAL;
706 }
707
708 avp = sc->sc_vaps[if_id];
709 ASSERT(avp != NULL);
710
711 if (avp)
712 memcpy(&avp->av_config, if_config, sizeof(avp->av_config));
713
714 return 0;
715}
716
717/********/ 587/********/
718/* Core */ 588/* Core */
719/********/ 589/********/
@@ -727,16 +597,6 @@ int ath_open(struct ath_softc *sc, struct ath9k_channel *initial_chan)
727 DPRINTF(sc, ATH_DBG_CONFIG, "%s: mode %d\n", 597 DPRINTF(sc, ATH_DBG_CONFIG, "%s: mode %d\n",
728 __func__, sc->sc_ah->ah_opmode); 598 __func__, sc->sc_ah->ah_opmode);
729 599
730 /*
731 * Stop anything previously setup. This is safe
732 * whether this is the first time through or not.
733 */
734 ath_stop(sc);
735
736 /* Initialize chanmask selection */
737 sc->sc_tx_chainmask = ah->ah_caps.tx_chainmask;
738 sc->sc_rx_chainmask = ah->ah_caps.rx_chainmask;
739
740 /* Reset SERDES registers */ 600 /* Reset SERDES registers */
741 ath9k_hw_configpcipowersave(ah, 0); 601 ath9k_hw_configpcipowersave(ah, 0);
742 602
@@ -762,6 +622,7 @@ int ath_open(struct ath_softc *sc, struct ath9k_channel *initial_chan)
762 goto done; 622 goto done;
763 } 623 }
764 spin_unlock_bh(&sc->sc_resetlock); 624 spin_unlock_bh(&sc->sc_resetlock);
625
765 /* 626 /*
766 * This is needed only to setup initial state 627 * This is needed only to setup initial state
767 * but it's best done after a reset. 628 * but it's best done after a reset.
@@ -781,6 +642,7 @@ int ath_open(struct ath_softc *sc, struct ath9k_channel *initial_chan)
781 error = -EIO; 642 error = -EIO;
782 goto done; 643 goto done;
783 } 644 }
645
784 /* Setup our intr mask. */ 646 /* Setup our intr mask. */
785 sc->sc_imask = ATH9K_INT_RX | ATH9K_INT_TX 647 sc->sc_imask = ATH9K_INT_RX | ATH9K_INT_TX
786 | ATH9K_INT_RXEOL | ATH9K_INT_RXORN 648 | ATH9K_INT_RXEOL | ATH9K_INT_RXORN
@@ -810,30 +672,60 @@ int ath_open(struct ath_softc *sc, struct ath9k_channel *initial_chan)
810 (sc->sc_ah->ah_opmode == ATH9K_M_STA) && 672 (sc->sc_ah->ah_opmode == ATH9K_M_STA) &&
811 !sc->sc_config.swBeaconProcess) 673 !sc->sc_config.swBeaconProcess)
812 sc->sc_imask |= ATH9K_INT_TIM; 674 sc->sc_imask |= ATH9K_INT_TIM;
813 /* 675
814 * Don't enable interrupts here as we've not yet built our
815 * vap and node data structures, which will be needed as soon
816 * as we start receiving.
817 */
818 ath_setcurmode(sc, ath_chan2mode(initial_chan)); 676 ath_setcurmode(sc, ath_chan2mode(initial_chan));
819 677
820 /* XXX: we must make sure h/w is ready and clear invalid flag
821 * before turning on interrupt. */
822 sc->sc_flags &= ~SC_OP_INVALID; 678 sc->sc_flags &= ~SC_OP_INVALID;
679
680 /* Disable BMISS interrupt when we're not associated */
681 sc->sc_imask &= ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS);
682 ath9k_hw_set_interrupts(sc->sc_ah,sc->sc_imask);
683
684 ieee80211_wake_queues(sc->hw);
823done: 685done:
824 return error; 686 return error;
825} 687}
826 688
689void ath_stop(struct ath_softc *sc)
690{
691 struct ath_hal *ah = sc->sc_ah;
692
693 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Cleaning up\n", __func__);
694
695 ieee80211_stop_queues(sc->hw);
696
697 /* make sure h/w will not generate any interrupt
698 * before setting the invalid flag. */
699 ath9k_hw_set_interrupts(ah, 0);
700
701 if (!(sc->sc_flags & SC_OP_INVALID)) {
702 ath_draintxq(sc, false);
703 ath_stoprecv(sc);
704 ath9k_hw_phy_disable(ah);
705 } else
706 sc->sc_rxlink = NULL;
707
708#ifdef CONFIG_RFKILL
709 if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
710 cancel_delayed_work_sync(&sc->rf_kill.rfkill_poll);
711#endif
712 /* disable HAL and put h/w to sleep */
713 ath9k_hw_disable(sc->sc_ah);
714 ath9k_hw_configpcipowersave(sc->sc_ah, 1);
715
716 sc->sc_flags |= SC_OP_INVALID;
717}
718
827int ath_reset(struct ath_softc *sc, bool retry_tx) 719int ath_reset(struct ath_softc *sc, bool retry_tx)
828{ 720{
829 struct ath_hal *ah = sc->sc_ah; 721 struct ath_hal *ah = sc->sc_ah;
830 int status; 722 int status;
831 int error = 0; 723 int error = 0;
832 724
833 ath9k_hw_set_interrupts(ah, 0); /* disable interrupts */ 725 ath9k_hw_set_interrupts(ah, 0);
834 ath_draintxq(sc, retry_tx); /* stop xmit */ 726 ath_draintxq(sc, retry_tx);
835 ath_stoprecv(sc); /* stop recv */ 727 ath_stoprecv(sc);
836 ath_flushrecv(sc); /* flush recv queue */ 728 ath_flushrecv(sc);
837 729
838 /* Reset chip */ 730 /* Reset chip */
839 spin_lock_bh(&sc->sc_resetlock); 731 spin_lock_bh(&sc->sc_resetlock);
@@ -848,7 +740,7 @@ int ath_reset(struct ath_softc *sc, bool retry_tx)
848 } 740 }
849 spin_unlock_bh(&sc->sc_resetlock); 741 spin_unlock_bh(&sc->sc_resetlock);
850 742
851 if (ath_startrecv(sc) != 0) /* restart recv */ 743 if (ath_startrecv(sc) != 0)
852 DPRINTF(sc, ATH_DBG_FATAL, 744 DPRINTF(sc, ATH_DBG_FATAL,
853 "%s: unable to start recv logic\n", __func__); 745 "%s: unable to start recv logic\n", __func__);
854 746
@@ -881,29 +773,6 @@ int ath_reset(struct ath_softc *sc, bool retry_tx)
881 return error; 773 return error;
882} 774}
883 775
884int ath_suspend(struct ath_softc *sc)
885{
886 struct ath_hal *ah = sc->sc_ah;
887
888 /* No I/O if device has been surprise removed */
889 if (sc->sc_flags & SC_OP_INVALID)
890 return -EIO;
891
892 /* Shut off the interrupt before setting sc->sc_invalid to '1' */
893 ath9k_hw_set_interrupts(ah, 0);
894
895 /* XXX: we must make sure h/w will not generate any interrupt
896 * before setting the invalid flag. */
897 sc->sc_flags |= SC_OP_INVALID;
898
899 /* disable HAL and put h/w to sleep */
900 ath9k_hw_disable(sc->sc_ah);
901
902 ath9k_hw_configpcipowersave(sc->sc_ah, 1);
903
904 return 0;
905}
906
907/* Interrupt handler. Most of the actual processing is deferred. 776/* Interrupt handler. Most of the actual processing is deferred.
908 * It's the caller's responsibility to ensure the chip is awake. */ 777 * It's the caller's responsibility to ensure the chip is awake. */
909 778
@@ -1071,11 +940,9 @@ int ath_init(u16 devid, struct ath_softc *sc)
1071 940
1072 /* XXX: hardware will not be ready until ath_open() being called */ 941 /* XXX: hardware will not be ready until ath_open() being called */
1073 sc->sc_flags |= SC_OP_INVALID; 942 sc->sc_flags |= SC_OP_INVALID;
1074
1075 sc->sc_debug = DBG_DEFAULT; 943 sc->sc_debug = DBG_DEFAULT;
1076 DPRINTF(sc, ATH_DBG_CONFIG, "%s: devid 0x%x\n", __func__, devid);
1077 944
1078 /* Initialize tasklet */ 945 spin_lock_init(&sc->sc_resetlock);
1079 tasklet_init(&sc->intr_tq, ath9k_tasklet, (unsigned long)sc); 946 tasklet_init(&sc->intr_tq, ath9k_tasklet, (unsigned long)sc);
1080 tasklet_init(&sc->bcon_tasklet, ath9k_beacon_tasklet, 947 tasklet_init(&sc->bcon_tasklet, ath9k_beacon_tasklet,
1081 (unsigned long)sc); 948 (unsigned long)sc);
@@ -1088,8 +955,6 @@ int ath_init(u16 devid, struct ath_softc *sc)
1088 /* XXX assert csz is non-zero */ 955 /* XXX assert csz is non-zero */
1089 sc->sc_cachelsz = csz << 2; /* convert to bytes */ 956 sc->sc_cachelsz = csz << 2; /* convert to bytes */
1090 957
1091 spin_lock_init(&sc->sc_resetlock);
1092
1093 ah = ath9k_hw_attach(devid, sc, sc->mem, &status); 958 ah = ath9k_hw_attach(devid, sc, sc->mem, &status);
1094 if (ah == NULL) { 959 if (ah == NULL) {
1095 DPRINTF(sc, ATH_DBG_FATAL, 960 DPRINTF(sc, ATH_DBG_FATAL,
@@ -1100,10 +965,6 @@ int ath_init(u16 devid, struct ath_softc *sc)
1100 } 965 }
1101 sc->sc_ah = ah; 966 sc->sc_ah = ah;
1102 967
1103 /* Initializes the noise floor to a reasonable default value.
1104 * Later on this will be updated during ANI processing. */
1105 sc->sc_ani.sc_noise_floor = ATH_DEFAULT_NOISE_FLOOR;
1106
1107 /* Get the hardware key cache size. */ 968 /* Get the hardware key cache size. */
1108 sc->sc_keymax = ah->ah_caps.keycache_size; 969 sc->sc_keymax = ah->ah_caps.keycache_size;
1109 if (sc->sc_keymax > ATH_KEYMAX) { 970 if (sc->sc_keymax > ATH_KEYMAX) {
@@ -1131,17 +992,14 @@ int ath_init(u16 devid, struct ath_softc *sc)
1131 set_bit(i + 64, sc->sc_keymap); 992 set_bit(i + 64, sc->sc_keymap);
1132 set_bit(i + 32 + 64, sc->sc_keymap); 993 set_bit(i + 32 + 64, sc->sc_keymap);
1133 } 994 }
1134 /* 995
1135 * Collect the channel list using the default country 996 /* Collect the channel list using the default country code */
1136 * code and including outdoor channels. The 802.11 layer 997
1137 * is resposible for filtering this list based on settings
1138 * like the phy mode.
1139 */
1140 error = ath_setup_channels(sc); 998 error = ath_setup_channels(sc);
1141 if (error) 999 if (error)
1142 goto bad; 1000 goto bad;
1143 1001
1144 /* default to STA mode */ 1002 /* default to MONITOR mode */
1145 sc->sc_ah->ah_opmode = ATH9K_M_MONITOR; 1003 sc->sc_ah->ah_opmode = ATH9K_M_MONITOR;
1146 1004
1147 /* Setup rate tables */ 1005 /* Setup rate tables */
@@ -1211,6 +1069,10 @@ int ath_init(u16 devid, struct ath_softc *sc)
1211 goto bad2; 1069 goto bad2;
1212 } 1070 }
1213 1071
1072 /* Initializes the noise floor to a reasonable default value.
1073 * Later on this will be updated during ANI processing. */
1074
1075 sc->sc_ani.sc_noise_floor = ATH_DEFAULT_NOISE_FLOOR;
1214 setup_timer(&sc->sc_ani.timer, ath_ani_calibrate, (unsigned long)sc); 1076 setup_timer(&sc->sc_ani.timer, ath_ani_calibrate, (unsigned long)sc);
1215 1077
1216 sc->sc_rc = ath_rate_attach(ah); 1078 sc->sc_rc = ath_rate_attach(ah);
@@ -1271,6 +1133,7 @@ int ath_init(u16 devid, struct ath_softc *sc)
1271 ATH_SET_VAP_BSSID_MASK(sc->sc_bssidmask); 1133 ATH_SET_VAP_BSSID_MASK(sc->sc_bssidmask);
1272 ath9k_hw_setbssidmask(ah, sc->sc_bssidmask); 1134 ath9k_hw_setbssidmask(ah, sc->sc_bssidmask);
1273 } 1135 }
1136
1274 sc->sc_slottime = ATH9K_SLOT_TIME_9; /* default to short slot time */ 1137 sc->sc_slottime = ATH9K_SLOT_TIME_9; /* default to short slot time */
1275 1138
1276 /* initialize beacon slots */ 1139 /* initialize beacon slots */
@@ -1285,6 +1148,22 @@ int ath_init(u16 devid, struct ath_softc *sc)
1285 ath_slow_ant_div_init(&sc->sc_antdiv, sc, 0x127); 1148 ath_slow_ant_div_init(&sc->sc_antdiv, sc, 0x127);
1286#endif 1149#endif
1287 1150
1151 /* setup channels and rates */
1152
1153 sc->sbands[IEEE80211_BAND_2GHZ].channels =
1154 sc->channels[IEEE80211_BAND_2GHZ];
1155 sc->sbands[IEEE80211_BAND_2GHZ].bitrates =
1156 sc->rates[IEEE80211_BAND_2GHZ];
1157 sc->sbands[IEEE80211_BAND_2GHZ].band = IEEE80211_BAND_2GHZ;
1158
1159 if (test_bit(ATH9K_MODE_11A, sc->sc_ah->ah_caps.wireless_modes)) {
1160 sc->sbands[IEEE80211_BAND_5GHZ].channels =
1161 sc->channels[IEEE80211_BAND_5GHZ];
1162 sc->sbands[IEEE80211_BAND_5GHZ].bitrates =
1163 sc->rates[IEEE80211_BAND_5GHZ];
1164 sc->sbands[IEEE80211_BAND_5GHZ].band = IEEE80211_BAND_5GHZ;
1165 }
1166
1288 return 0; 1167 return 0;
1289bad2: 1168bad2:
1290 /* cleanup tx queues */ 1169 /* cleanup tx queues */
@@ -1294,125 +1173,39 @@ bad2:
1294bad: 1173bad:
1295 if (ah) 1174 if (ah)
1296 ath9k_hw_detach(ah); 1175 ath9k_hw_detach(ah);
1297 return error;
1298}
1299
1300void ath_deinit(struct ath_softc *sc)
1301{
1302 struct ath_hal *ah = sc->sc_ah;
1303 int i;
1304 1176
1305 DPRINTF(sc, ATH_DBG_CONFIG, "%s\n", __func__); 1177 return error;
1306
1307 tasklet_kill(&sc->intr_tq);
1308 tasklet_kill(&sc->bcon_tasklet);
1309 ath_stop(sc);
1310 if (!(sc->sc_flags & SC_OP_INVALID))
1311 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE);
1312 ath_rate_detach(sc->sc_rc);
1313 /* cleanup tx queues */
1314 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
1315 if (ATH_TXQ_SETUP(sc, i))
1316 ath_tx_cleanupq(sc, &sc->sc_txq[i]);
1317 ath9k_hw_detach(ah);
1318} 1178}
1319 1179
1320/*******************/ 1180/*******************/
1321/* Node Management */ 1181/* Node Management */
1322/*******************/ 1182/*******************/
1323 1183
1324struct ath_node *ath_node_attach(struct ath_softc *sc, u8 *addr, int if_id) 1184void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta)
1325{ 1185{
1326 struct ath_vap *avp;
1327 struct ath_node *an; 1186 struct ath_node *an;
1328 1187
1329 avp = sc->sc_vaps[if_id]; 1188 an = (struct ath_node *)sta->drv_priv;
1330 ASSERT(avp != NULL);
1331 1189
1332 /* mac80211 sta_notify callback is from an IRQ context, so no sleep */ 1190 if (sc->sc_flags & SC_OP_TXAGGR)
1333 an = kmalloc(sizeof(struct ath_node), GFP_ATOMIC); 1191 ath_tx_node_init(sc, an);
1334 if (an == NULL)
1335 return NULL;
1336 memset(an, 0, sizeof(*an));
1337 1192
1338 an->an_sc = sc; 1193 an->maxampdu = 1 << (IEEE80211_HTCAP_MAXRXAMPDU_FACTOR +
1339 memcpy(an->an_addr, addr, ETH_ALEN); 1194 sta->ht_cap.ampdu_factor);
1340 atomic_set(&an->an_refcnt, 1); 1195 an->mpdudensity = parse_mpdudensity(sta->ht_cap.ampdu_density);
1341
1342 /* set up per-node tx/rx state */
1343 ath_tx_node_init(sc, an);
1344 ath_rx_node_init(sc, an);
1345 1196
1346 ath_chainmask_sel_init(sc, an); 1197 ath_chainmask_sel_init(sc, an);
1347 ath_chainmask_sel_timerstart(&an->an_chainmask_sel); 1198 ath_chainmask_sel_timerstart(&an->an_chainmask_sel);
1348 list_add(&an->list, &sc->node_list);
1349
1350 return an;
1351} 1199}
1352 1200
1353void ath_node_detach(struct ath_softc *sc, struct ath_node *an, bool bh_flag) 1201void ath_node_detach(struct ath_softc *sc, struct ieee80211_sta *sta)
1354{ 1202{
1355 unsigned long flags; 1203 struct ath_node *an = (struct ath_node *)sta->drv_priv;
1356 1204
1357 ath_chainmask_sel_timerstop(&an->an_chainmask_sel); 1205 ath_chainmask_sel_timerstop(&an->an_chainmask_sel);
1358 an->an_flags |= ATH_NODE_CLEAN;
1359 ath_tx_node_cleanup(sc, an, bh_flag);
1360 ath_rx_node_cleanup(sc, an);
1361
1362 ath_tx_node_free(sc, an);
1363 ath_rx_node_free(sc, an);
1364
1365 spin_lock_irqsave(&sc->node_lock, flags);
1366
1367 list_del(&an->list);
1368
1369 spin_unlock_irqrestore(&sc->node_lock, flags);
1370 1206
1371 kfree(an); 1207 if (sc->sc_flags & SC_OP_TXAGGR)
1372} 1208 ath_tx_node_cleanup(sc, an);
1373
1374/* Finds a node and increases the refcnt if found */
1375
1376struct ath_node *ath_node_get(struct ath_softc *sc, u8 *addr)
1377{
1378 struct ath_node *an = NULL, *an_found = NULL;
1379
1380 if (list_empty(&sc->node_list)) /* FIXME */
1381 goto out;
1382 list_for_each_entry(an, &sc->node_list, list) {
1383 if (!compare_ether_addr(an->an_addr, addr)) {
1384 atomic_inc(&an->an_refcnt);
1385 an_found = an;
1386 break;
1387 }
1388 }
1389out:
1390 return an_found;
1391}
1392
1393/* Decrements the refcnt and if it drops to zero, detach the node */
1394
1395void ath_node_put(struct ath_softc *sc, struct ath_node *an, bool bh_flag)
1396{
1397 if (atomic_dec_and_test(&an->an_refcnt))
1398 ath_node_detach(sc, an, bh_flag);
1399}
1400
1401/* Finds a node, doesn't increment refcnt. Caller must hold sc->node_lock */
1402struct ath_node *ath_node_find(struct ath_softc *sc, u8 *addr)
1403{
1404 struct ath_node *an = NULL, *an_found = NULL;
1405
1406 if (list_empty(&sc->node_list))
1407 return NULL;
1408
1409 list_for_each_entry(an, &sc->node_list, list)
1410 if (!compare_ether_addr(an->an_addr, addr)) {
1411 an_found = an;
1412 break;
1413 }
1414
1415 return an_found;
1416} 1209}
1417 1210
1418/* 1211/*
@@ -1433,11 +1226,8 @@ void ath_newassoc(struct ath_softc *sc,
1433 for (tidno = 0; tidno < WME_NUM_TID; tidno++) { 1226 for (tidno = 0; tidno < WME_NUM_TID; tidno++) {
1434 if (sc->sc_flags & SC_OP_TXAGGR) 1227 if (sc->sc_flags & SC_OP_TXAGGR)
1435 ath_tx_aggr_teardown(sc, an, tidno); 1228 ath_tx_aggr_teardown(sc, an, tidno);
1436 if (sc->sc_flags & SC_OP_RXAGGR)
1437 ath_rx_aggr_teardown(sc, an, tidno);
1438 } 1229 }
1439 } 1230 }
1440 an->an_flags = 0;
1441} 1231}
1442 1232
1443/**************/ 1233/**************/
@@ -1488,27 +1278,6 @@ void ath_update_txpow(struct ath_softc *sc)
1488 } 1278 }
1489} 1279}
1490 1280
1491/* Return the current country and domain information */
1492void ath_get_currentCountry(struct ath_softc *sc,
1493 struct ath9k_country_entry *ctry)
1494{
1495 ath9k_regd_get_current_country(sc->sc_ah, ctry);
1496
1497 /* If HAL not specific yet, since it is band dependent,
1498 * use the one we passed in. */
1499 if (ctry->countryCode == CTRY_DEFAULT) {
1500 ctry->iso[0] = 0;
1501 ctry->iso[1] = 0;
1502 } else if (ctry->iso[0] && ctry->iso[1]) {
1503 if (!ctry->iso[2]) {
1504 if (ath_outdoor)
1505 ctry->iso[2] = 'O';
1506 else
1507 ctry->iso[2] = 'I';
1508 }
1509 }
1510}
1511
1512/**************************/ 1281/**************************/
1513/* Slow Antenna Diversity */ 1282/* Slow Antenna Diversity */
1514/**************************/ 1283/**************************/
diff --git a/drivers/net/wireless/ath9k/core.h b/drivers/net/wireless/ath9k/core.h
index fbff9aa4c28f..69e8d3e41131 100644
--- a/drivers/net/wireless/ath9k/core.h
+++ b/drivers/net/wireless/ath9k/core.h
@@ -84,9 +84,6 @@ struct ath_node;
84#define TSF_TO_TU(_h,_l) \ 84#define TSF_TO_TU(_h,_l) \
85 ((((u32)(_h)) << 22) | (((u32)(_l)) >> 10)) 85 ((((u32)(_h)) << 22) | (((u32)(_l)) >> 10))
86 86
87#define ATH9K_BH_STATUS_INTACT 0
88#define ATH9K_BH_STATUS_CHANGE 1
89
90#define ATH_TXQ_SETUP(sc, i) ((sc)->sc_txqsetup & (1<<i)) 87#define ATH_TXQ_SETUP(sc, i) ((sc)->sc_txqsetup & (1<<i))
91 88
92static inline unsigned long get_timestamp(void) 89static inline unsigned long get_timestamp(void)
@@ -209,6 +206,7 @@ struct ath_buf_state {
209 struct ath_rc_series bfs_rcs[4]; /* rate series */ 206 struct ath_rc_series bfs_rcs[4]; /* rate series */
210 u32 bf_type; /* BUF_* (enum buffer_type) */ 207 u32 bf_type; /* BUF_* (enum buffer_type) */
211 /* key type use to encrypt this frame */ 208 /* key type use to encrypt this frame */
209 u32 bfs_keyix;
212 enum ath9k_key_type bfs_keytype; 210 enum ath9k_key_type bfs_keytype;
213}; 211};
214 212
@@ -219,6 +217,7 @@ struct ath_buf_state {
219#define bf_seqno bf_state.bfs_seqno 217#define bf_seqno bf_state.bfs_seqno
220#define bf_tidno bf_state.bfs_tidno 218#define bf_tidno bf_state.bfs_tidno
221#define bf_rcs bf_state.bfs_rcs 219#define bf_rcs bf_state.bfs_rcs
220#define bf_keyix bf_state.bfs_keyix
222#define bf_keytype bf_state.bfs_keytype 221#define bf_keytype bf_state.bfs_keytype
223#define bf_isdata(bf) (bf->bf_state.bf_type & BUF_DATA) 222#define bf_isdata(bf) (bf->bf_state.bf_type & BUF_DATA)
224#define bf_isaggr(bf) (bf->bf_state.bf_type & BUF_AGGR) 223#define bf_isaggr(bf) (bf->bf_state.bf_type & BUF_AGGR)
@@ -244,7 +243,6 @@ struct ath_buf {
244 struct ath_buf *bf_next; /* next subframe in the aggregate */ 243 struct ath_buf *bf_next; /* next subframe in the aggregate */
245 struct ath_buf *bf_rifslast; /* last buf for RIFS burst */ 244 struct ath_buf *bf_rifslast; /* last buf for RIFS burst */
246 void *bf_mpdu; /* enclosing frame structure */ 245 void *bf_mpdu; /* enclosing frame structure */
247 void *bf_node; /* pointer to the node */
248 struct ath_desc *bf_desc; /* virtual addr of desc */ 246 struct ath_desc *bf_desc; /* virtual addr of desc */
249 dma_addr_t bf_daddr; /* physical addr of desc */ 247 dma_addr_t bf_daddr; /* physical addr of desc */
250 dma_addr_t bf_buf_addr; /* physical addr of data buffer */ 248 dma_addr_t bf_buf_addr; /* physical addr of data buffer */
@@ -306,15 +304,7 @@ void ath_descdma_cleanup(struct ath_softc *sc,
306 304
307#define ATH_MAX_ANTENNA 3 305#define ATH_MAX_ANTENNA 3
308#define ATH_RXBUF 512 306#define ATH_RXBUF 512
309#define ATH_RX_TIMEOUT 40 /* 40 milliseconds */
310#define WME_NUM_TID 16 307#define WME_NUM_TID 16
311#define IEEE80211_BAR_CTL_TID_M 0xF000 /* tid mask */
312#define IEEE80211_BAR_CTL_TID_S 12 /* tid shift */
313
314enum ATH_RX_TYPE {
315 ATH_RX_NON_CONSUMED = 0,
316 ATH_RX_CONSUMED
317};
318 308
319/* per frame rx status block */ 309/* per frame rx status block */
320struct ath_recv_status { 310struct ath_recv_status {
@@ -348,48 +338,18 @@ struct ath_rxbuf {
348 struct ath_recv_status rx_status; /* cached rx status */ 338 struct ath_recv_status rx_status; /* cached rx status */
349}; 339};
350 340
351/* Per-TID aggregate receiver state for a node */
352struct ath_arx_tid {
353 struct ath_node *an;
354 struct ath_rxbuf *rxbuf; /* re-ordering buffer */
355 struct timer_list timer;
356 spinlock_t tidlock;
357 int baw_head; /* seq_next at head */
358 int baw_tail; /* tail of block-ack window */
359 int seq_reset; /* need to reset start sequence */
360 int addba_exchangecomplete;
361 u16 seq_next; /* next expected sequence */
362 u16 baw_size; /* block-ack window size */
363};
364
365/* Per-node receiver aggregate state */
366struct ath_arx {
367 struct ath_arx_tid tid[WME_NUM_TID];
368};
369
370int ath_startrecv(struct ath_softc *sc); 341int ath_startrecv(struct ath_softc *sc);
371bool ath_stoprecv(struct ath_softc *sc); 342bool ath_stoprecv(struct ath_softc *sc);
372void ath_flushrecv(struct ath_softc *sc); 343void ath_flushrecv(struct ath_softc *sc);
373u32 ath_calcrxfilter(struct ath_softc *sc); 344u32 ath_calcrxfilter(struct ath_softc *sc);
374void ath_rx_node_init(struct ath_softc *sc, struct ath_node *an);
375void ath_rx_node_free(struct ath_softc *sc, struct ath_node *an);
376void ath_rx_node_cleanup(struct ath_softc *sc, struct ath_node *an);
377void ath_handle_rx_intr(struct ath_softc *sc); 345void ath_handle_rx_intr(struct ath_softc *sc);
378int ath_rx_init(struct ath_softc *sc, int nbufs); 346int ath_rx_init(struct ath_softc *sc, int nbufs);
379void ath_rx_cleanup(struct ath_softc *sc); 347void ath_rx_cleanup(struct ath_softc *sc);
380int ath_rx_tasklet(struct ath_softc *sc, int flush); 348int ath_rx_tasklet(struct ath_softc *sc, int flush);
381int ath_rx_input(struct ath_softc *sc,
382 struct ath_node *node,
383 struct sk_buff *skb,
384 struct ath_recv_status *rx_status,
385 enum ATH_RX_TYPE *status);
386int _ath_rx_indicate(struct ath_softc *sc, 349int _ath_rx_indicate(struct ath_softc *sc,
387 struct sk_buff *skb, 350 struct sk_buff *skb,
388 struct ath_recv_status *status, 351 struct ath_recv_status *status,
389 u16 keyix); 352 u16 keyix);
390int ath_rx_subframe(struct ath_node *an, struct sk_buff *skb,
391 struct ath_recv_status *status);
392
393/******/ 353/******/
394/* TX */ 354/* TX */
395/******/ 355/******/
@@ -418,12 +378,6 @@ int ath_rx_subframe(struct ath_node *an, struct sk_buff *skb,
418#define WME_AC_VO 3 /* voice */ 378#define WME_AC_VO 3 /* voice */
419#define WME_NUM_AC 4 379#define WME_NUM_AC 4
420 380
421enum ATH_SM_PWRSAV{
422 ATH_SM_ENABLE,
423 ATH_SM_PWRSAV_STATIC,
424 ATH_SM_PWRSAV_DYNAMIC,
425};
426
427/* 381/*
428 * Data transmit queue state. One of these exists for each 382 * Data transmit queue state. One of these exists for each
429 * hardware transmit queue. Packets sent to us from above 383 * hardware transmit queue. Packets sent to us from above
@@ -456,6 +410,10 @@ struct ath_txq {
456 struct list_head axq_acq; 410 struct list_head axq_acq;
457}; 411};
458 412
413#define AGGR_CLEANUP BIT(1)
414#define AGGR_ADDBA_COMPLETE BIT(2)
415#define AGGR_ADDBA_PROGRESS BIT(3)
416
459/* per TID aggregate tx state for a destination */ 417/* per TID aggregate tx state for a destination */
460struct ath_atx_tid { 418struct ath_atx_tid {
461 struct list_head list; /* round-robin tid entry */ 419 struct list_head list; /* round-robin tid entry */
@@ -471,9 +429,7 @@ struct ath_atx_tid {
471 int baw_tail; /* next unused tx buffer slot */ 429 int baw_tail; /* next unused tx buffer slot */
472 int sched; 430 int sched;
473 int paused; 431 int paused;
474 int cleanup_inprogress; 432 u8 state;
475 u32 addba_exchangecomplete:1;
476 int32_t addba_exchangeinprogress;
477 int addba_exchangeattempts; 433 int addba_exchangeattempts;
478}; 434};
479 435
@@ -494,24 +450,8 @@ struct ath_atx {
494 450
495/* per-frame tx control block */ 451/* per-frame tx control block */
496struct ath_tx_control { 452struct ath_tx_control {
497 struct ath_node *an; 453 struct ath_txq *txq;
498 int if_id; 454 int if_id;
499 int qnum;
500 u32 ht:1;
501 u32 ps:1;
502 u32 use_minrate:1;
503 enum ath9k_pkt_type atype;
504 enum ath9k_key_type keytype;
505 u32 flags;
506 u16 seqno;
507 u16 tidno;
508 u16 txpower;
509 u16 frmlen;
510 u32 keyix;
511 int min_rate;
512 int mcast_rate;
513 struct ath_softc *dev;
514 dma_addr_t dmacontext;
515}; 455};
516 456
517/* per frame tx status block */ 457/* per frame tx status block */
@@ -546,33 +486,29 @@ void ath_draintxq(struct ath_softc *sc, bool retry_tx);
546void ath_tx_draintxq(struct ath_softc *sc, 486void ath_tx_draintxq(struct ath_softc *sc,
547 struct ath_txq *txq, bool retry_tx); 487 struct ath_txq *txq, bool retry_tx);
548void ath_tx_node_init(struct ath_softc *sc, struct ath_node *an); 488void ath_tx_node_init(struct ath_softc *sc, struct ath_node *an);
549void ath_tx_node_cleanup(struct ath_softc *sc, 489void ath_tx_node_cleanup(struct ath_softc *sc, struct ath_node *an);
550 struct ath_node *an, bool bh_flag);
551void ath_tx_node_free(struct ath_softc *sc, struct ath_node *an); 490void ath_tx_node_free(struct ath_softc *sc, struct ath_node *an);
552void ath_txq_schedule(struct ath_softc *sc, struct ath_txq *txq); 491void ath_txq_schedule(struct ath_softc *sc, struct ath_txq *txq);
553int ath_tx_init(struct ath_softc *sc, int nbufs); 492int ath_tx_init(struct ath_softc *sc, int nbufs);
554int ath_tx_cleanup(struct ath_softc *sc); 493int ath_tx_cleanup(struct ath_softc *sc);
555int ath_tx_get_qnum(struct ath_softc *sc, int qtype, int haltype); 494int ath_tx_get_qnum(struct ath_softc *sc, int qtype, int haltype);
495struct ath_txq *ath_test_get_txq(struct ath_softc *sc, struct sk_buff *skb);
556int ath_txq_update(struct ath_softc *sc, int qnum, 496int ath_txq_update(struct ath_softc *sc, int qnum,
557 struct ath9k_tx_queue_info *q); 497 struct ath9k_tx_queue_info *q);
558int ath_tx_start(struct ath_softc *sc, struct sk_buff *skb); 498int ath_tx_start(struct ath_softc *sc, struct sk_buff *skb,
499 struct ath_tx_control *txctl);
559void ath_tx_tasklet(struct ath_softc *sc); 500void ath_tx_tasklet(struct ath_softc *sc);
560u32 ath_txq_depth(struct ath_softc *sc, int qnum); 501u32 ath_txq_depth(struct ath_softc *sc, int qnum);
561u32 ath_txq_aggr_depth(struct ath_softc *sc, int qnum); 502u32 ath_txq_aggr_depth(struct ath_softc *sc, int qnum);
562void ath_notify_txq_status(struct ath_softc *sc, u16 queue_depth); 503void ath_notify_txq_status(struct ath_softc *sc, u16 queue_depth);
563void ath_tx_complete(struct ath_softc *sc, struct sk_buff *skb, 504void ath_tx_complete(struct ath_softc *sc, struct sk_buff *skb,
564 struct ath_xmit_status *tx_status, struct ath_node *an); 505 struct ath_xmit_status *tx_status);
565void ath_tx_cabq(struct ath_softc *sc, struct sk_buff *skb); 506void ath_tx_cabq(struct ath_softc *sc, struct sk_buff *skb);
566 507
567/**********************/ 508/**********************/
568/* Node / Aggregation */ 509/* Node / Aggregation */
569/**********************/ 510/**********************/
570 511
571/* indicates the node is clened up */
572#define ATH_NODE_CLEAN 0x1
573/* indicates the node is 80211 power save */
574#define ATH_NODE_PWRSAVE 0x2
575
576#define ADDBA_EXCHANGE_ATTEMPTS 10 512#define ADDBA_EXCHANGE_ATTEMPTS 10
577#define ATH_AGGR_DELIM_SZ 4 /* delimiter size */ 513#define ATH_AGGR_DELIM_SZ 4 /* delimiter size */
578#define ATH_AGGR_MINPLEN 256 /* in bytes, minimum packet length */ 514#define ATH_AGGR_MINPLEN 256 /* in bytes, minimum packet length */
@@ -584,6 +520,7 @@ void ath_tx_cabq(struct ath_softc *sc, struct sk_buff *skb);
584#define IEEE80211_SEQ_SEQ_SHIFT 4 520#define IEEE80211_SEQ_SEQ_SHIFT 4
585#define IEEE80211_SEQ_MAX 4096 521#define IEEE80211_SEQ_MAX 4096
586#define IEEE80211_MIN_AMPDU_BUF 0x8 522#define IEEE80211_MIN_AMPDU_BUF 0x8
523#define IEEE80211_HTCAP_MAXRXAMPDU_FACTOR 13
587 524
588/* return whether a bit at index _n in bitmap _bm is set 525/* return whether a bit at index _n in bitmap _bm is set
589 * _sz is the size of the bitmap */ 526 * _sz is the size of the bitmap */
@@ -614,14 +551,6 @@ enum ATH_AGGR_STATUS {
614 ATH_AGGR_8K_LIMITED, 551 ATH_AGGR_8K_LIMITED,
615}; 552};
616 553
617enum ATH_AGGR_CHECK {
618 AGGR_NOT_REQUIRED,
619 AGGR_REQUIRED,
620 AGGR_CLEANUP_PROGRESS,
621 AGGR_EXCHANGE_PROGRESS,
622 AGGR_EXCHANGE_DONE
623};
624
625struct aggr_rifs_param { 554struct aggr_rifs_param {
626 int param_max_frames; 555 int param_max_frames;
627 int param_max_len; 556 int param_max_len;
@@ -633,54 +562,30 @@ struct aggr_rifs_param {
633/* Per-node aggregation state */ 562/* Per-node aggregation state */
634struct ath_node_aggr { 563struct ath_node_aggr {
635 struct ath_atx tx; /* node transmit state */ 564 struct ath_atx tx; /* node transmit state */
636 struct ath_arx rx; /* node receive state */
637}; 565};
638 566
639/* driver-specific node state */ 567/* driver-specific node state */
640struct ath_node { 568struct ath_node {
641 struct list_head list;
642 struct ath_softc *an_sc; 569 struct ath_softc *an_sc;
643 atomic_t an_refcnt;
644 struct ath_chainmask_sel an_chainmask_sel; 570 struct ath_chainmask_sel an_chainmask_sel;
645 struct ath_node_aggr an_aggr; 571 struct ath_node_aggr an_aggr;
646 u8 an_smmode; /* SM Power save mode */
647 u8 an_flags;
648 u8 an_addr[ETH_ALEN];
649
650 u16 maxampdu; 572 u16 maxampdu;
651 u8 mpdudensity; 573 u8 mpdudensity;
652}; 574};
653 575
654void ath_tx_resume_tid(struct ath_softc *sc, 576void ath_tx_resume_tid(struct ath_softc *sc,
655 struct ath_atx_tid *tid); 577 struct ath_atx_tid *tid);
656enum ATH_AGGR_CHECK ath_tx_aggr_check(struct ath_softc *sc, 578bool ath_tx_aggr_check(struct ath_softc *sc, struct ath_node *an, u8 tidno);
657 struct ath_node *an, u8 tidno);
658void ath_tx_aggr_teardown(struct ath_softc *sc, 579void ath_tx_aggr_teardown(struct ath_softc *sc,
659 struct ath_node *an, u8 tidno); 580 struct ath_node *an, u8 tidno);
660void ath_rx_aggr_teardown(struct ath_softc *sc, 581int ath_tx_aggr_start(struct ath_softc *sc, struct ieee80211_sta *sta,
661 struct ath_node *an, u8 tidno); 582 u16 tid, u16 *ssn);
662int ath_rx_aggr_start(struct ath_softc *sc, 583int ath_tx_aggr_stop(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid);
663 const u8 *addr, 584void ath_tx_aggr_resume(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid);
664 u16 tid,
665 u16 *ssn);
666int ath_rx_aggr_stop(struct ath_softc *sc,
667 const u8 *addr,
668 u16 tid);
669int ath_tx_aggr_start(struct ath_softc *sc,
670 const u8 *addr,
671 u16 tid,
672 u16 *ssn);
673int ath_tx_aggr_stop(struct ath_softc *sc,
674 const u8 *addr,
675 u16 tid);
676void ath_newassoc(struct ath_softc *sc, 585void ath_newassoc(struct ath_softc *sc,
677 struct ath_node *node, int isnew, int isuapsd); 586 struct ath_node *node, int isnew, int isuapsd);
678struct ath_node *ath_node_attach(struct ath_softc *sc, 587void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta);
679 u8 addr[ETH_ALEN], int if_id); 588void ath_node_detach(struct ath_softc *sc, struct ieee80211_sta *sta);
680void ath_node_detach(struct ath_softc *sc, struct ath_node *an, bool bh_flag);
681struct ath_node *ath_node_get(struct ath_softc *sc, u8 addr[ETH_ALEN]);
682void ath_node_put(struct ath_softc *sc, struct ath_node *an, bool bh_flag);
683struct ath_node *ath_node_find(struct ath_softc *sc, u8 *addr);
684 589
685/*******************/ 590/*******************/
686/* Beacon Handling */ 591/* Beacon Handling */
@@ -744,23 +649,14 @@ struct ath_vap_config {
744 649
745/* driver-specific vap state */ 650/* driver-specific vap state */
746struct ath_vap { 651struct ath_vap {
747 struct ieee80211_vif *av_if_data; 652 int av_bslot; /* beacon slot index */
748 enum ath9k_opmode av_opmode; /* VAP operational mode */ 653 enum ath9k_opmode av_opmode; /* VAP operational mode */
749 struct ath_buf *av_bcbuf; /* beacon buffer */ 654 struct ath_buf *av_bcbuf; /* beacon buffer */
750 struct ath_tx_control av_btxctl; /* txctl information for beacon */ 655 struct ath_tx_control av_btxctl; /* txctl information for beacon */
751 int av_bslot; /* beacon slot index */
752 struct ath_vap_config av_config;/* vap configuration parameters*/ 656 struct ath_vap_config av_config;/* vap configuration parameters*/
753 struct ath_rate_node *rc_node; 657 struct ath_rate_node *rc_node;
754}; 658};
755 659
756int ath_vap_attach(struct ath_softc *sc,
757 int if_id,
758 struct ieee80211_vif *if_data,
759 enum ath9k_opmode opmode);
760int ath_vap_detach(struct ath_softc *sc, int if_id);
761int ath_vap_config(struct ath_softc *sc,
762 int if_id, struct ath_vap_config *if_config);
763
764/*********************/ 660/*********************/
765/* Antenna diversity */ 661/* Antenna diversity */
766/*********************/ 662/*********************/
@@ -968,14 +864,13 @@ struct ath_softc {
968 864
969 u8 sc_nbcnvaps; /* # of vaps sending beacons */ 865 u8 sc_nbcnvaps; /* # of vaps sending beacons */
970 u16 sc_nvaps; /* # of active virtual ap's */ 866 u16 sc_nvaps; /* # of active virtual ap's */
971 struct ath_vap *sc_vaps[ATH_BCBUF]; 867 struct ieee80211_vif *sc_vaps[ATH_BCBUF];
972 868
973 u8 sc_mcastantenna; 869 u8 sc_mcastantenna;
974 u8 sc_defant; /* current default antenna */ 870 u8 sc_defant; /* current default antenna */
975 u8 sc_rxotherant; /* rx's on non-default antenna */ 871 u8 sc_rxotherant; /* rx's on non-default antenna */
976 872
977 struct ath9k_node_stats sc_halstats; /* station-mode rssi stats */ 873 struct ath9k_node_stats sc_halstats; /* station-mode rssi stats */
978 struct list_head node_list;
979 struct ath_ht_info sc_ht_info; 874 struct ath_ht_info sc_ht_info;
980 enum ath9k_ht_extprotspacing sc_ht_extprotspacing; 875 enum ath9k_ht_extprotspacing sc_ht_extprotspacing;
981 876
@@ -1036,7 +931,6 @@ struct ath_softc {
1036 spinlock_t sc_rxbuflock; 931 spinlock_t sc_rxbuflock;
1037 spinlock_t sc_txbuflock; 932 spinlock_t sc_txbuflock;
1038 spinlock_t sc_resetlock; 933 spinlock_t sc_resetlock;
1039 spinlock_t node_lock;
1040 934
1041 /* LEDs */ 935 /* LEDs */
1042 struct ath_led radio_led; 936 struct ath_led radio_led;
@@ -1052,9 +946,8 @@ struct ath_softc {
1052}; 946};
1053 947
1054int ath_init(u16 devid, struct ath_softc *sc); 948int ath_init(u16 devid, struct ath_softc *sc);
1055void ath_deinit(struct ath_softc *sc);
1056int ath_open(struct ath_softc *sc, struct ath9k_channel *initial_chan); 949int ath_open(struct ath_softc *sc, struct ath9k_channel *initial_chan);
1057int ath_suspend(struct ath_softc *sc); 950void ath_stop(struct ath_softc *sc);
1058irqreturn_t ath_isr(int irq, void *dev); 951irqreturn_t ath_isr(int irq, void *dev);
1059int ath_reset(struct ath_softc *sc, bool retry_tx); 952int ath_reset(struct ath_softc *sc, bool retry_tx);
1060int ath_set_channel(struct ath_softc *sc, struct ath9k_channel *hchan); 953int ath_set_channel(struct ath_softc *sc, struct ath9k_channel *hchan);
@@ -1073,8 +966,6 @@ int ath_get_mac80211_qnum(u32 queue, struct ath_softc *sc);
1073void ath_setslottime(struct ath_softc *sc); 966void ath_setslottime(struct ath_softc *sc);
1074void ath_update_txpow(struct ath_softc *sc); 967void ath_update_txpow(struct ath_softc *sc);
1075int ath_cabq_update(struct ath_softc *); 968int ath_cabq_update(struct ath_softc *);
1076void ath_get_currentCountry(struct ath_softc *sc,
1077 struct ath9k_country_entry *ctry);
1078u64 ath_extend_tsf(struct ath_softc *sc, u32 rstamp); 969u64 ath_extend_tsf(struct ath_softc *sc, u32 rstamp);
1079 970
1080#endif /* CORE_H */ 971#endif /* CORE_H */
diff --git a/drivers/net/wireless/ath9k/eeprom.c b/drivers/net/wireless/ath9k/eeprom.c
new file mode 100644
index 000000000000..f5fd03c0edd7
--- /dev/null
+++ b/drivers/net/wireless/ath9k/eeprom.c
@@ -0,0 +1,1605 @@
1/*
2 * Copyright (c) 2008 Atheros Communications Inc.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#include "core.h"
18#include "hw.h"
19#include "reg.h"
20#include "phy.h"
21
22static void ath9k_hw_analog_shift_rmw(struct ath_hal *ah,
23 u32 reg, u32 mask,
24 u32 shift, u32 val)
25{
26 u32 regVal;
27
28 regVal = REG_READ(ah, reg) & ~mask;
29 regVal |= (val << shift) & mask;
30
31 REG_WRITE(ah, reg, regVal);
32
33 if (ah->ah_config.analog_shiftreg)
34 udelay(100);
35
36 return;
37}
38
39static inline u16 ath9k_hw_fbin2freq(u8 fbin, bool is2GHz)
40{
41
42 if (fbin == AR5416_BCHAN_UNUSED)
43 return fbin;
44
45 return (u16) ((is2GHz) ? (2300 + fbin) : (4800 + 5 * fbin));
46}
47
48static inline int16_t ath9k_hw_interpolate(u16 target,
49 u16 srcLeft, u16 srcRight,
50 int16_t targetLeft,
51 int16_t targetRight)
52{
53 int16_t rv;
54
55 if (srcRight == srcLeft) {
56 rv = targetLeft;
57 } else {
58 rv = (int16_t) (((target - srcLeft) * targetRight +
59 (srcRight - target) * targetLeft) /
60 (srcRight - srcLeft));
61 }
62 return rv;
63}
64
65static inline bool ath9k_hw_get_lower_upper_index(u8 target, u8 *pList,
66 u16 listSize, u16 *indexL,
67 u16 *indexR)
68{
69 u16 i;
70
71 if (target <= pList[0]) {
72 *indexL = *indexR = 0;
73 return true;
74 }
75 if (target >= pList[listSize - 1]) {
76 *indexL = *indexR = (u16) (listSize - 1);
77 return true;
78 }
79
80 for (i = 0; i < listSize - 1; i++) {
81 if (pList[i] == target) {
82 *indexL = *indexR = i;
83 return true;
84 }
85 if (target < pList[i + 1]) {
86 *indexL = i;
87 *indexR = (u16) (i + 1);
88 return false;
89 }
90 }
91 return false;
92}
93
94static bool ath9k_hw_eeprom_read(struct ath_hal *ah, u32 off, u16 *data)
95{
96 (void)REG_READ(ah, AR5416_EEPROM_OFFSET + (off << AR5416_EEPROM_S));
97
98 if (!ath9k_hw_wait(ah,
99 AR_EEPROM_STATUS_DATA,
100 AR_EEPROM_STATUS_DATA_BUSY |
101 AR_EEPROM_STATUS_DATA_PROT_ACCESS, 0)) {
102 return false;
103 }
104
105 *data = MS(REG_READ(ah, AR_EEPROM_STATUS_DATA),
106 AR_EEPROM_STATUS_DATA_VAL);
107
108 return true;
109}
110
111static int ath9k_hw_flash_map(struct ath_hal *ah)
112{
113 struct ath_hal_5416 *ahp = AH5416(ah);
114
115 ahp->ah_cal_mem = ioremap(AR5416_EEPROM_START_ADDR, AR5416_EEPROM_MAX);
116
117 if (!ahp->ah_cal_mem) {
118 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
119 "%s: cannot remap eeprom region \n", __func__);
120 return -EIO;
121 }
122
123 return 0;
124}
125
126static bool ath9k_hw_flash_read(struct ath_hal *ah, u32 off, u16 *data)
127{
128 struct ath_hal_5416 *ahp = AH5416(ah);
129
130 *data = ioread16(ahp->ah_cal_mem + off);
131
132 return true;
133}
134
135static inline bool ath9k_hw_nvram_read(struct ath_hal *ah, u32 off, u16 *data)
136{
137 if (ath9k_hw_use_flash(ah))
138 return ath9k_hw_flash_read(ah, off, data);
139 else
140 return ath9k_hw_eeprom_read(ah, off, data);
141}
142
143static bool ath9k_hw_fill_eeprom(struct ath_hal *ah)
144{
145 struct ath_hal_5416 *ahp = AH5416(ah);
146 struct ar5416_eeprom *eep = &ahp->ah_eeprom;
147 u16 *eep_data;
148 int addr, ar5416_eep_start_loc = 0;
149
150 if (!ath9k_hw_use_flash(ah)) {
151 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
152 "%s: Reading from EEPROM, not flash\n", __func__);
153 ar5416_eep_start_loc = 256;
154 }
155
156 if (AR_SREV_9100(ah))
157 ar5416_eep_start_loc = 256;
158
159 eep_data = (u16 *)eep;
160
161 for (addr = 0; addr < sizeof(struct ar5416_eeprom) / sizeof(u16); addr++) {
162 if (!ath9k_hw_nvram_read(ah, addr + ar5416_eep_start_loc,
163 eep_data)) {
164 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
165 "%s: Unable to read eeprom region \n",
166 __func__);
167 return false;
168 }
169 eep_data++;
170 }
171 return true;
172}
173
174static int ath9k_hw_check_eeprom(struct ath_hal *ah)
175{
176 struct ath_hal_5416 *ahp = AH5416(ah);
177 struct ar5416_eeprom *eep =
178 (struct ar5416_eeprom *) &ahp->ah_eeprom;
179 u16 *eepdata, temp, magic, magic2;
180 u32 sum = 0, el;
181 bool need_swap = false;
182 int i, addr, size;
183
184 if (!ath9k_hw_use_flash(ah)) {
185 if (!ath9k_hw_nvram_read(ah, AR5416_EEPROM_MAGIC_OFFSET,
186 &magic)) {
187 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
188 "%s: Reading Magic # failed\n", __func__);
189 return false;
190 }
191
192 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, "%s: Read Magic = 0x%04X\n",
193 __func__, magic);
194
195 if (magic != AR5416_EEPROM_MAGIC) {
196 magic2 = swab16(magic);
197
198 if (magic2 == AR5416_EEPROM_MAGIC) {
199 size = sizeof(struct ar5416_eeprom);
200 need_swap = true;
201 eepdata = (u16 *) (&ahp->ah_eeprom);
202
203 for (addr = 0; addr < size / sizeof(u16); addr++) {
204 temp = swab16(*eepdata);
205 *eepdata = temp;
206 eepdata++;
207
208 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
209 "0x%04X ", *eepdata);
210
211 if (((addr + 1) % 6) == 0)
212 DPRINTF(ah->ah_sc,
213 ATH_DBG_EEPROM, "\n");
214 }
215 } else {
216 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
217 "Invalid EEPROM Magic. "
218 "endianness mismatch.\n");
219 return -EINVAL;
220 }
221 }
222 }
223
224 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, "need_swap = %s.\n",
225 need_swap ? "True" : "False");
226
227 if (need_swap)
228 el = swab16(ahp->ah_eeprom.baseEepHeader.length);
229 else
230 el = ahp->ah_eeprom.baseEepHeader.length;
231
232 if (el > sizeof(struct ar5416_eeprom))
233 el = sizeof(struct ar5416_eeprom) / sizeof(u16);
234 else
235 el = el / sizeof(u16);
236
237 eepdata = (u16 *)(&ahp->ah_eeprom);
238
239 for (i = 0; i < el; i++)
240 sum ^= *eepdata++;
241
242 if (need_swap) {
243 u32 integer, j;
244 u16 word;
245
246 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
247 "EEPROM Endianness is not native.. Changing \n");
248
249 word = swab16(eep->baseEepHeader.length);
250 eep->baseEepHeader.length = word;
251
252 word = swab16(eep->baseEepHeader.checksum);
253 eep->baseEepHeader.checksum = word;
254
255 word = swab16(eep->baseEepHeader.version);
256 eep->baseEepHeader.version = word;
257
258 word = swab16(eep->baseEepHeader.regDmn[0]);
259 eep->baseEepHeader.regDmn[0] = word;
260
261 word = swab16(eep->baseEepHeader.regDmn[1]);
262 eep->baseEepHeader.regDmn[1] = word;
263
264 word = swab16(eep->baseEepHeader.rfSilent);
265 eep->baseEepHeader.rfSilent = word;
266
267 word = swab16(eep->baseEepHeader.blueToothOptions);
268 eep->baseEepHeader.blueToothOptions = word;
269
270 word = swab16(eep->baseEepHeader.deviceCap);
271 eep->baseEepHeader.deviceCap = word;
272
273 for (j = 0; j < ARRAY_SIZE(eep->modalHeader); j++) {
274 struct modal_eep_header *pModal =
275 &eep->modalHeader[j];
276 integer = swab32(pModal->antCtrlCommon);
277 pModal->antCtrlCommon = integer;
278
279 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
280 integer = swab32(pModal->antCtrlChain[i]);
281 pModal->antCtrlChain[i] = integer;
282 }
283
284 for (i = 0; i < AR5416_EEPROM_MODAL_SPURS; i++) {
285 word = swab16(pModal->spurChans[i].spurChan);
286 pModal->spurChans[i].spurChan = word;
287 }
288 }
289 }
290
291 if (sum != 0xffff || ar5416_get_eep_ver(ahp) != AR5416_EEP_VER ||
292 ar5416_get_eep_rev(ahp) < AR5416_EEP_NO_BACK_VER) {
293 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
294 "Bad EEPROM checksum 0x%x or revision 0x%04x\n",
295 sum, ar5416_get_eep_ver(ahp));
296 return -EINVAL;
297 }
298
299 return 0;
300}
301
302static inline bool ath9k_hw_fill_vpd_table(u8 pwrMin, u8 pwrMax, u8 *pPwrList,
303 u8 *pVpdList, u16 numIntercepts,
304 u8 *pRetVpdList)
305{
306 u16 i, k;
307 u8 currPwr = pwrMin;
308 u16 idxL = 0, idxR = 0;
309
310 for (i = 0; i <= (pwrMax - pwrMin) / 2; i++) {
311 ath9k_hw_get_lower_upper_index(currPwr, pPwrList,
312 numIntercepts, &(idxL),
313 &(idxR));
314 if (idxR < 1)
315 idxR = 1;
316 if (idxL == numIntercepts - 1)
317 idxL = (u16) (numIntercepts - 2);
318 if (pPwrList[idxL] == pPwrList[idxR])
319 k = pVpdList[idxL];
320 else
321 k = (u16)(((currPwr - pPwrList[idxL]) * pVpdList[idxR] +
322 (pPwrList[idxR] - currPwr) * pVpdList[idxL]) /
323 (pPwrList[idxR] - pPwrList[idxL]));
324 pRetVpdList[i] = (u8) k;
325 currPwr += 2;
326 }
327
328 return true;
329}
330
331static void ath9k_hw_get_gain_boundaries_pdadcs(struct ath_hal *ah,
332 struct ath9k_channel *chan,
333 struct cal_data_per_freq *pRawDataSet,
334 u8 *bChans, u16 availPiers,
335 u16 tPdGainOverlap, int16_t *pMinCalPower,
336 u16 *pPdGainBoundaries, u8 *pPDADCValues,
337 u16 numXpdGains)
338{
339 int i, j, k;
340 int16_t ss;
341 u16 idxL = 0, idxR = 0, numPiers;
342 static u8 vpdTableL[AR5416_NUM_PD_GAINS]
343 [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
344 static u8 vpdTableR[AR5416_NUM_PD_GAINS]
345 [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
346 static u8 vpdTableI[AR5416_NUM_PD_GAINS]
347 [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
348
349 u8 *pVpdL, *pVpdR, *pPwrL, *pPwrR;
350 u8 minPwrT4[AR5416_NUM_PD_GAINS];
351 u8 maxPwrT4[AR5416_NUM_PD_GAINS];
352 int16_t vpdStep;
353 int16_t tmpVal;
354 u16 sizeCurrVpdTable, maxIndex, tgtIndex;
355 bool match;
356 int16_t minDelta = 0;
357 struct chan_centers centers;
358
359 ath9k_hw_get_channel_centers(ah, chan, &centers);
360
361 for (numPiers = 0; numPiers < availPiers; numPiers++) {
362 if (bChans[numPiers] == AR5416_BCHAN_UNUSED)
363 break;
364 }
365
366 match = ath9k_hw_get_lower_upper_index((u8)FREQ2FBIN(centers.synth_center,
367 IS_CHAN_2GHZ(chan)),
368 bChans, numPiers, &idxL, &idxR);
369
370 if (match) {
371 for (i = 0; i < numXpdGains; i++) {
372 minPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][0];
373 maxPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][4];
374 ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
375 pRawDataSet[idxL].pwrPdg[i],
376 pRawDataSet[idxL].vpdPdg[i],
377 AR5416_PD_GAIN_ICEPTS,
378 vpdTableI[i]);
379 }
380 } else {
381 for (i = 0; i < numXpdGains; i++) {
382 pVpdL = pRawDataSet[idxL].vpdPdg[i];
383 pPwrL = pRawDataSet[idxL].pwrPdg[i];
384 pVpdR = pRawDataSet[idxR].vpdPdg[i];
385 pPwrR = pRawDataSet[idxR].pwrPdg[i];
386
387 minPwrT4[i] = max(pPwrL[0], pPwrR[0]);
388
389 maxPwrT4[i] =
390 min(pPwrL[AR5416_PD_GAIN_ICEPTS - 1],
391 pPwrR[AR5416_PD_GAIN_ICEPTS - 1]);
392
393
394 ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
395 pPwrL, pVpdL,
396 AR5416_PD_GAIN_ICEPTS,
397 vpdTableL[i]);
398 ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
399 pPwrR, pVpdR,
400 AR5416_PD_GAIN_ICEPTS,
401 vpdTableR[i]);
402
403 for (j = 0; j <= (maxPwrT4[i] - minPwrT4[i]) / 2; j++) {
404 vpdTableI[i][j] =
405 (u8)(ath9k_hw_interpolate((u16)
406 FREQ2FBIN(centers.
407 synth_center,
408 IS_CHAN_2GHZ
409 (chan)),
410 bChans[idxL], bChans[idxR],
411 vpdTableL[i][j], vpdTableR[i][j]));
412 }
413 }
414 }
415
416 *pMinCalPower = (int16_t)(minPwrT4[0] / 2);
417
418 k = 0;
419
420 for (i = 0; i < numXpdGains; i++) {
421 if (i == (numXpdGains - 1))
422 pPdGainBoundaries[i] =
423 (u16)(maxPwrT4[i] / 2);
424 else
425 pPdGainBoundaries[i] =
426 (u16)((maxPwrT4[i] + minPwrT4[i + 1]) / 4);
427
428 pPdGainBoundaries[i] =
429 min((u16)AR5416_MAX_RATE_POWER, pPdGainBoundaries[i]);
430
431 if ((i == 0) && !AR_SREV_5416_V20_OR_LATER(ah)) {
432 minDelta = pPdGainBoundaries[0] - 23;
433 pPdGainBoundaries[0] = 23;
434 } else {
435 minDelta = 0;
436 }
437
438 if (i == 0) {
439 if (AR_SREV_9280_10_OR_LATER(ah))
440 ss = (int16_t)(0 - (minPwrT4[i] / 2));
441 else
442 ss = 0;
443 } else {
444 ss = (int16_t)((pPdGainBoundaries[i - 1] -
445 (minPwrT4[i] / 2)) -
446 tPdGainOverlap + 1 + minDelta);
447 }
448 vpdStep = (int16_t)(vpdTableI[i][1] - vpdTableI[i][0]);
449 vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
450
451 while ((ss < 0) && (k < (AR5416_NUM_PDADC_VALUES - 1))) {
452 tmpVal = (int16_t)(vpdTableI[i][0] + ss * vpdStep);
453 pPDADCValues[k++] = (u8)((tmpVal < 0) ? 0 : tmpVal);
454 ss++;
455 }
456
457 sizeCurrVpdTable = (u8) ((maxPwrT4[i] - minPwrT4[i]) / 2 + 1);
458 tgtIndex = (u8)(pPdGainBoundaries[i] + tPdGainOverlap -
459 (minPwrT4[i] / 2));
460 maxIndex = (tgtIndex < sizeCurrVpdTable) ?
461 tgtIndex : sizeCurrVpdTable;
462
463 while ((ss < maxIndex) && (k < (AR5416_NUM_PDADC_VALUES - 1))) {
464 pPDADCValues[k++] = vpdTableI[i][ss++];
465 }
466
467 vpdStep = (int16_t)(vpdTableI[i][sizeCurrVpdTable - 1] -
468 vpdTableI[i][sizeCurrVpdTable - 2]);
469 vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
470
471 if (tgtIndex > maxIndex) {
472 while ((ss <= tgtIndex) &&
473 (k < (AR5416_NUM_PDADC_VALUES - 1))) {
474 tmpVal = (int16_t)((vpdTableI[i][sizeCurrVpdTable - 1] +
475 (ss - maxIndex + 1) * vpdStep));
476 pPDADCValues[k++] = (u8)((tmpVal > 255) ?
477 255 : tmpVal);
478 ss++;
479 }
480 }
481 }
482
483 while (i < AR5416_PD_GAINS_IN_MASK) {
484 pPdGainBoundaries[i] = pPdGainBoundaries[i - 1];
485 i++;
486 }
487
488 while (k < AR5416_NUM_PDADC_VALUES) {
489 pPDADCValues[k] = pPDADCValues[k - 1];
490 k++;
491 }
492
493 return;
494}
495
496static void ath9k_hw_get_legacy_target_powers(struct ath_hal *ah,
497 struct ath9k_channel *chan,
498 struct cal_target_power_leg *powInfo,
499 u16 numChannels,
500 struct cal_target_power_leg *pNewPower,
501 u16 numRates, bool isExtTarget)
502{
503 struct chan_centers centers;
504 u16 clo, chi;
505 int i;
506 int matchIndex = -1, lowIndex = -1;
507 u16 freq;
508
509 ath9k_hw_get_channel_centers(ah, chan, &centers);
510 freq = (isExtTarget) ? centers.ext_center : centers.ctl_center;
511
512 if (freq <= ath9k_hw_fbin2freq(powInfo[0].bChannel,
513 IS_CHAN_2GHZ(chan))) {
514 matchIndex = 0;
515 } else {
516 for (i = 0; (i < numChannels) &&
517 (powInfo[i].bChannel != AR5416_BCHAN_UNUSED); i++) {
518 if (freq == ath9k_hw_fbin2freq(powInfo[i].bChannel,
519 IS_CHAN_2GHZ(chan))) {
520 matchIndex = i;
521 break;
522 } else if ((freq < ath9k_hw_fbin2freq(powInfo[i].bChannel,
523 IS_CHAN_2GHZ(chan))) &&
524 (freq > ath9k_hw_fbin2freq(powInfo[i - 1].bChannel,
525 IS_CHAN_2GHZ(chan)))) {
526 lowIndex = i - 1;
527 break;
528 }
529 }
530 if ((matchIndex == -1) && (lowIndex == -1))
531 matchIndex = i - 1;
532 }
533
534 if (matchIndex != -1) {
535 *pNewPower = powInfo[matchIndex];
536 } else {
537 clo = ath9k_hw_fbin2freq(powInfo[lowIndex].bChannel,
538 IS_CHAN_2GHZ(chan));
539 chi = ath9k_hw_fbin2freq(powInfo[lowIndex + 1].bChannel,
540 IS_CHAN_2GHZ(chan));
541
542 for (i = 0; i < numRates; i++) {
543 pNewPower->tPow2x[i] =
544 (u8)ath9k_hw_interpolate(freq, clo, chi,
545 powInfo[lowIndex].tPow2x[i],
546 powInfo[lowIndex + 1].tPow2x[i]);
547 }
548 }
549}
550
551static void ath9k_hw_get_target_powers(struct ath_hal *ah,
552 struct ath9k_channel *chan,
553 struct cal_target_power_ht *powInfo,
554 u16 numChannels,
555 struct cal_target_power_ht *pNewPower,
556 u16 numRates, bool isHt40Target)
557{
558 struct chan_centers centers;
559 u16 clo, chi;
560 int i;
561 int matchIndex = -1, lowIndex = -1;
562 u16 freq;
563
564 ath9k_hw_get_channel_centers(ah, chan, &centers);
565 freq = isHt40Target ? centers.synth_center : centers.ctl_center;
566
567 if (freq <= ath9k_hw_fbin2freq(powInfo[0].bChannel, IS_CHAN_2GHZ(chan))) {
568 matchIndex = 0;
569 } else {
570 for (i = 0; (i < numChannels) &&
571 (powInfo[i].bChannel != AR5416_BCHAN_UNUSED); i++) {
572 if (freq == ath9k_hw_fbin2freq(powInfo[i].bChannel,
573 IS_CHAN_2GHZ(chan))) {
574 matchIndex = i;
575 break;
576 } else
577 if ((freq < ath9k_hw_fbin2freq(powInfo[i].bChannel,
578 IS_CHAN_2GHZ(chan))) &&
579 (freq > ath9k_hw_fbin2freq(powInfo[i - 1].bChannel,
580 IS_CHAN_2GHZ(chan)))) {
581 lowIndex = i - 1;
582 break;
583 }
584 }
585 if ((matchIndex == -1) && (lowIndex == -1))
586 matchIndex = i - 1;
587 }
588
589 if (matchIndex != -1) {
590 *pNewPower = powInfo[matchIndex];
591 } else {
592 clo = ath9k_hw_fbin2freq(powInfo[lowIndex].bChannel,
593 IS_CHAN_2GHZ(chan));
594 chi = ath9k_hw_fbin2freq(powInfo[lowIndex + 1].bChannel,
595 IS_CHAN_2GHZ(chan));
596
597 for (i = 0; i < numRates; i++) {
598 pNewPower->tPow2x[i] = (u8)ath9k_hw_interpolate(freq,
599 clo, chi,
600 powInfo[lowIndex].tPow2x[i],
601 powInfo[lowIndex + 1].tPow2x[i]);
602 }
603 }
604}
605
606static u16 ath9k_hw_get_max_edge_power(u16 freq,
607 struct cal_ctl_edges *pRdEdgesPower,
608 bool is2GHz)
609{
610 u16 twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
611 int i;
612
613 for (i = 0; (i < AR5416_NUM_BAND_EDGES) &&
614 (pRdEdgesPower[i].bChannel != AR5416_BCHAN_UNUSED); i++) {
615 if (freq == ath9k_hw_fbin2freq(pRdEdgesPower[i].bChannel, is2GHz)) {
616 twiceMaxEdgePower = pRdEdgesPower[i].tPower;
617 break;
618 } else if ((i > 0) &&
619 (freq < ath9k_hw_fbin2freq(pRdEdgesPower[i].bChannel,
620 is2GHz))) {
621 if (ath9k_hw_fbin2freq(pRdEdgesPower[i - 1].bChannel,
622 is2GHz) < freq &&
623 pRdEdgesPower[i - 1].flag) {
624 twiceMaxEdgePower =
625 pRdEdgesPower[i - 1].tPower;
626 }
627 break;
628 }
629 }
630
631 return twiceMaxEdgePower;
632}
633
634int ath9k_hw_set_txpower(struct ath_hal *ah,
635 struct ath9k_channel *chan,
636 u16 cfgCtl,
637 u8 twiceAntennaReduction,
638 u8 twiceMaxRegulatoryPower,
639 u8 powerLimit)
640{
641 struct ath_hal_5416 *ahp = AH5416(ah);
642 struct ar5416_eeprom *pEepData = &ahp->ah_eeprom;
643 struct modal_eep_header *pModal =
644 &(pEepData->modalHeader[IS_CHAN_2GHZ(chan)]);
645 int16_t ratesArray[Ar5416RateSize];
646 int16_t txPowerIndexOffset = 0;
647 u8 ht40PowerIncForPdadc = 2;
648 int i;
649
650 memset(ratesArray, 0, sizeof(ratesArray));
651
652 if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
653 AR5416_EEP_MINOR_VER_2) {
654 ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
655 }
656
657 if (!ath9k_hw_set_power_per_rate_table(ah, chan,
658 &ratesArray[0], cfgCtl,
659 twiceAntennaReduction,
660 twiceMaxRegulatoryPower,
661 powerLimit)) {
662 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
663 "ath9k_hw_set_txpower: unable to set "
664 "tx power per rate table\n");
665 return -EIO;
666 }
667
668 if (!ath9k_hw_set_power_cal_table(ah, chan, &txPowerIndexOffset)) {
669 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
670 "ath9k_hw_set_txpower: unable to set power table\n");
671 return -EIO;
672 }
673
674 for (i = 0; i < ARRAY_SIZE(ratesArray); i++) {
675 ratesArray[i] = (int16_t)(txPowerIndexOffset + ratesArray[i]);
676 if (ratesArray[i] > AR5416_MAX_RATE_POWER)
677 ratesArray[i] = AR5416_MAX_RATE_POWER;
678 }
679
680 if (AR_SREV_9280_10_OR_LATER(ah)) {
681 for (i = 0; i < Ar5416RateSize; i++)
682 ratesArray[i] -= AR5416_PWR_TABLE_OFFSET * 2;
683 }
684
685 REG_WRITE(ah, AR_PHY_POWER_TX_RATE1,
686 ATH9K_POW_SM(ratesArray[rate18mb], 24)
687 | ATH9K_POW_SM(ratesArray[rate12mb], 16)
688 | ATH9K_POW_SM(ratesArray[rate9mb], 8)
689 | ATH9K_POW_SM(ratesArray[rate6mb], 0));
690 REG_WRITE(ah, AR_PHY_POWER_TX_RATE2,
691 ATH9K_POW_SM(ratesArray[rate54mb], 24)
692 | ATH9K_POW_SM(ratesArray[rate48mb], 16)
693 | ATH9K_POW_SM(ratesArray[rate36mb], 8)
694 | ATH9K_POW_SM(ratesArray[rate24mb], 0));
695
696 if (IS_CHAN_2GHZ(chan)) {
697 REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
698 ATH9K_POW_SM(ratesArray[rate2s], 24)
699 | ATH9K_POW_SM(ratesArray[rate2l], 16)
700 | ATH9K_POW_SM(ratesArray[rateXr], 8)
701 | ATH9K_POW_SM(ratesArray[rate1l], 0));
702 REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
703 ATH9K_POW_SM(ratesArray[rate11s], 24)
704 | ATH9K_POW_SM(ratesArray[rate11l], 16)
705 | ATH9K_POW_SM(ratesArray[rate5_5s], 8)
706 | ATH9K_POW_SM(ratesArray[rate5_5l], 0));
707 }
708
709 REG_WRITE(ah, AR_PHY_POWER_TX_RATE5,
710 ATH9K_POW_SM(ratesArray[rateHt20_3], 24)
711 | ATH9K_POW_SM(ratesArray[rateHt20_2], 16)
712 | ATH9K_POW_SM(ratesArray[rateHt20_1], 8)
713 | ATH9K_POW_SM(ratesArray[rateHt20_0], 0));
714 REG_WRITE(ah, AR_PHY_POWER_TX_RATE6,
715 ATH9K_POW_SM(ratesArray[rateHt20_7], 24)
716 | ATH9K_POW_SM(ratesArray[rateHt20_6], 16)
717 | ATH9K_POW_SM(ratesArray[rateHt20_5], 8)
718 | ATH9K_POW_SM(ratesArray[rateHt20_4], 0));
719
720 if (IS_CHAN_HT40(chan)) {
721 REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
722 ATH9K_POW_SM(ratesArray[rateHt40_3] +
723 ht40PowerIncForPdadc, 24)
724 | ATH9K_POW_SM(ratesArray[rateHt40_2] +
725 ht40PowerIncForPdadc, 16)
726 | ATH9K_POW_SM(ratesArray[rateHt40_1] +
727 ht40PowerIncForPdadc, 8)
728 | ATH9K_POW_SM(ratesArray[rateHt40_0] +
729 ht40PowerIncForPdadc, 0));
730 REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
731 ATH9K_POW_SM(ratesArray[rateHt40_7] +
732 ht40PowerIncForPdadc, 24)
733 | ATH9K_POW_SM(ratesArray[rateHt40_6] +
734 ht40PowerIncForPdadc, 16)
735 | ATH9K_POW_SM(ratesArray[rateHt40_5] +
736 ht40PowerIncForPdadc, 8)
737 | ATH9K_POW_SM(ratesArray[rateHt40_4] +
738 ht40PowerIncForPdadc, 0));
739
740 REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
741 ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
742 | ATH9K_POW_SM(ratesArray[rateExtCck], 16)
743 | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
744 | ATH9K_POW_SM(ratesArray[rateDupCck], 0));
745 }
746
747 REG_WRITE(ah, AR_PHY_POWER_TX_SUB,
748 ATH9K_POW_SM(pModal->pwrDecreaseFor3Chain, 6)
749 | ATH9K_POW_SM(pModal->pwrDecreaseFor2Chain, 0));
750
751 i = rate6mb;
752
753 if (IS_CHAN_HT40(chan))
754 i = rateHt40_0;
755 else if (IS_CHAN_HT20(chan))
756 i = rateHt20_0;
757
758 if (AR_SREV_9280_10_OR_LATER(ah))
759 ah->ah_maxPowerLevel =
760 ratesArray[i] + AR5416_PWR_TABLE_OFFSET * 2;
761 else
762 ah->ah_maxPowerLevel = ratesArray[i];
763
764 return 0;
765}
766
767void ath9k_hw_set_addac(struct ath_hal *ah, struct ath9k_channel *chan)
768{
769 struct modal_eep_header *pModal;
770 struct ath_hal_5416 *ahp = AH5416(ah);
771 struct ar5416_eeprom *eep = &ahp->ah_eeprom;
772 u8 biaslevel;
773
774 if (ah->ah_macVersion != AR_SREV_VERSION_9160)
775 return;
776
777 if (ar5416_get_eep_rev(ahp) < AR5416_EEP_MINOR_VER_7)
778 return;
779
780 pModal = &(eep->modalHeader[IS_CHAN_2GHZ(chan)]);
781
782 if (pModal->xpaBiasLvl != 0xff) {
783 biaslevel = pModal->xpaBiasLvl;
784 } else {
785 u16 resetFreqBin, freqBin, freqCount = 0;
786 struct chan_centers centers;
787
788 ath9k_hw_get_channel_centers(ah, chan, &centers);
789
790 resetFreqBin = FREQ2FBIN(centers.synth_center, IS_CHAN_2GHZ(chan));
791 freqBin = pModal->xpaBiasLvlFreq[0] & 0xff;
792 biaslevel = (u8) (pModal->xpaBiasLvlFreq[0] >> 14);
793
794 freqCount++;
795
796 while (freqCount < 3) {
797 if (pModal->xpaBiasLvlFreq[freqCount] == 0x0)
798 break;
799
800 freqBin = pModal->xpaBiasLvlFreq[freqCount] & 0xff;
801 if (resetFreqBin >= freqBin) {
802 biaslevel = (u8)(pModal->xpaBiasLvlFreq[freqCount] >> 14);
803 } else {
804 break;
805 }
806 freqCount++;
807 }
808 }
809
810 if (IS_CHAN_2GHZ(chan)) {
811 INI_RA(&ahp->ah_iniAddac, 7, 1) =
812 (INI_RA(&ahp->ah_iniAddac, 7, 1) & (~0x18)) | biaslevel << 3;
813 } else {
814 INI_RA(&ahp->ah_iniAddac, 6, 1) =
815 (INI_RA(&ahp->ah_iniAddac, 6, 1) & (~0xc0)) | biaslevel << 6;
816 }
817}
818
819bool ath9k_hw_set_power_per_rate_table(struct ath_hal *ah,
820 struct ath9k_channel *chan,
821 int16_t *ratesArray,
822 u16 cfgCtl,
823 u8 AntennaReduction,
824 u8 twiceMaxRegulatoryPower,
825 u8 powerLimit)
826{
827 struct ath_hal_5416 *ahp = AH5416(ah);
828 struct ar5416_eeprom *pEepData = &ahp->ah_eeprom;
829 u8 twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
830 static const u16 tpScaleReductionTable[5] =
831 { 0, 3, 6, 9, AR5416_MAX_RATE_POWER };
832
833 int i;
834 int8_t twiceLargestAntenna;
835 struct cal_ctl_data *rep;
836 struct cal_target_power_leg targetPowerOfdm, targetPowerCck = {
837 0, { 0, 0, 0, 0}
838 };
839 struct cal_target_power_leg targetPowerOfdmExt = {
840 0, { 0, 0, 0, 0} }, targetPowerCckExt = {
841 0, { 0, 0, 0, 0 }
842 };
843 struct cal_target_power_ht targetPowerHt20, targetPowerHt40 = {
844 0, {0, 0, 0, 0}
845 };
846 u8 scaledPower = 0, minCtlPower, maxRegAllowedPower;
847 u16 ctlModesFor11a[] =
848 { CTL_11A, CTL_5GHT20, CTL_11A_EXT, CTL_5GHT40 };
849 u16 ctlModesFor11g[] =
850 { CTL_11B, CTL_11G, CTL_2GHT20, CTL_11B_EXT, CTL_11G_EXT,
851 CTL_2GHT40
852 };
853 u16 numCtlModes, *pCtlMode, ctlMode, freq;
854 struct chan_centers centers;
855 int tx_chainmask;
856 u8 twiceMinEdgePower;
857
858 tx_chainmask = ahp->ah_txchainmask;
859
860 ath9k_hw_get_channel_centers(ah, chan, &centers);
861
862 twiceLargestAntenna = max(
863 pEepData->modalHeader
864 [IS_CHAN_2GHZ(chan)].antennaGainCh[0],
865 pEepData->modalHeader
866 [IS_CHAN_2GHZ(chan)].antennaGainCh[1]);
867
868 twiceLargestAntenna = max((u8)twiceLargestAntenna,
869 pEepData->modalHeader
870 [IS_CHAN_2GHZ(chan)].antennaGainCh[2]);
871
872 twiceLargestAntenna = (int8_t)min(AntennaReduction - twiceLargestAntenna, 0);
873
874 maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna;
875
876 if (ah->ah_tpScale != ATH9K_TP_SCALE_MAX) {
877 maxRegAllowedPower -=
878 (tpScaleReductionTable[(ah->ah_tpScale)] * 2);
879 }
880
881 scaledPower = min(powerLimit, maxRegAllowedPower);
882
883 switch (ar5416_get_ntxchains(tx_chainmask)) {
884 case 1:
885 break;
886 case 2:
887 scaledPower -=
888 pEepData->modalHeader[IS_CHAN_2GHZ(chan)].pwrDecreaseFor2Chain;
889 break;
890 case 3:
891 scaledPower -=
892 pEepData->modalHeader[IS_CHAN_2GHZ(chan)].pwrDecreaseFor3Chain;
893 break;
894 }
895
896 scaledPower = max(0, (int32_t) scaledPower);
897
898 if (IS_CHAN_2GHZ(chan)) {
899 numCtlModes = ARRAY_SIZE(ctlModesFor11g) -
900 SUB_NUM_CTL_MODES_AT_2G_40;
901 pCtlMode = ctlModesFor11g;
902
903 ath9k_hw_get_legacy_target_powers(ah, chan,
904 pEepData->calTargetPowerCck,
905 AR5416_NUM_2G_CCK_TARGET_POWERS,
906 &targetPowerCck, 4, false);
907 ath9k_hw_get_legacy_target_powers(ah, chan,
908 pEepData->calTargetPower2G,
909 AR5416_NUM_2G_20_TARGET_POWERS,
910 &targetPowerOfdm, 4, false);
911 ath9k_hw_get_target_powers(ah, chan,
912 pEepData->calTargetPower2GHT20,
913 AR5416_NUM_2G_20_TARGET_POWERS,
914 &targetPowerHt20, 8, false);
915
916 if (IS_CHAN_HT40(chan)) {
917 numCtlModes = ARRAY_SIZE(ctlModesFor11g);
918 ath9k_hw_get_target_powers(ah, chan,
919 pEepData->calTargetPower2GHT40,
920 AR5416_NUM_2G_40_TARGET_POWERS,
921 &targetPowerHt40, 8, true);
922 ath9k_hw_get_legacy_target_powers(ah, chan,
923 pEepData->calTargetPowerCck,
924 AR5416_NUM_2G_CCK_TARGET_POWERS,
925 &targetPowerCckExt, 4, true);
926 ath9k_hw_get_legacy_target_powers(ah, chan,
927 pEepData->calTargetPower2G,
928 AR5416_NUM_2G_20_TARGET_POWERS,
929 &targetPowerOfdmExt, 4, true);
930 }
931 } else {
932 numCtlModes = ARRAY_SIZE(ctlModesFor11a) -
933 SUB_NUM_CTL_MODES_AT_5G_40;
934 pCtlMode = ctlModesFor11a;
935
936 ath9k_hw_get_legacy_target_powers(ah, chan,
937 pEepData->calTargetPower5G,
938 AR5416_NUM_5G_20_TARGET_POWERS,
939 &targetPowerOfdm, 4, false);
940 ath9k_hw_get_target_powers(ah, chan,
941 pEepData->calTargetPower5GHT20,
942 AR5416_NUM_5G_20_TARGET_POWERS,
943 &targetPowerHt20, 8, false);
944
945 if (IS_CHAN_HT40(chan)) {
946 numCtlModes = ARRAY_SIZE(ctlModesFor11a);
947 ath9k_hw_get_target_powers(ah, chan,
948 pEepData->calTargetPower5GHT40,
949 AR5416_NUM_5G_40_TARGET_POWERS,
950 &targetPowerHt40, 8, true);
951 ath9k_hw_get_legacy_target_powers(ah, chan,
952 pEepData->calTargetPower5G,
953 AR5416_NUM_5G_20_TARGET_POWERS,
954 &targetPowerOfdmExt, 4, true);
955 }
956 }
957
958 for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) {
959 bool isHt40CtlMode = (pCtlMode[ctlMode] == CTL_5GHT40) ||
960 (pCtlMode[ctlMode] == CTL_2GHT40);
961 if (isHt40CtlMode)
962 freq = centers.synth_center;
963 else if (pCtlMode[ctlMode] & EXT_ADDITIVE)
964 freq = centers.ext_center;
965 else
966 freq = centers.ctl_center;
967
968 if (ar5416_get_eep_ver(ahp) == 14 && ar5416_get_eep_rev(ahp) <= 2)
969 twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
970
971 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
972 "LOOP-Mode ctlMode %d < %d, isHt40CtlMode %d, "
973 "EXT_ADDITIVE %d\n",
974 ctlMode, numCtlModes, isHt40CtlMode,
975 (pCtlMode[ctlMode] & EXT_ADDITIVE));
976
977 for (i = 0; (i < AR5416_NUM_CTLS) && pEepData->ctlIndex[i]; i++) {
978 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
979 " LOOP-Ctlidx %d: cfgCtl 0x%2.2x "
980 "pCtlMode 0x%2.2x ctlIndex 0x%2.2x "
981 "chan %d\n",
982 i, cfgCtl, pCtlMode[ctlMode],
983 pEepData->ctlIndex[i], chan->channel);
984
985 if ((((cfgCtl & ~CTL_MODE_M) |
986 (pCtlMode[ctlMode] & CTL_MODE_M)) ==
987 pEepData->ctlIndex[i]) ||
988 (((cfgCtl & ~CTL_MODE_M) |
989 (pCtlMode[ctlMode] & CTL_MODE_M)) ==
990 ((pEepData->ctlIndex[i] & CTL_MODE_M) | SD_NO_CTL))) {
991 rep = &(pEepData->ctlData[i]);
992
993 twiceMinEdgePower = ath9k_hw_get_max_edge_power(freq,
994 rep->ctlEdges[ar5416_get_ntxchains(tx_chainmask) - 1],
995 IS_CHAN_2GHZ(chan));
996
997 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
998 " MATCH-EE_IDX %d: ch %d is2 %d "
999 "2xMinEdge %d chainmask %d chains %d\n",
1000 i, freq, IS_CHAN_2GHZ(chan),
1001 twiceMinEdgePower, tx_chainmask,
1002 ar5416_get_ntxchains
1003 (tx_chainmask));
1004 if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) {
1005 twiceMaxEdgePower = min(twiceMaxEdgePower,
1006 twiceMinEdgePower);
1007 } else {
1008 twiceMaxEdgePower = twiceMinEdgePower;
1009 break;
1010 }
1011 }
1012 }
1013
1014 minCtlPower = min(twiceMaxEdgePower, scaledPower);
1015
1016 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
1017 " SEL-Min ctlMode %d pCtlMode %d "
1018 "2xMaxEdge %d sP %d minCtlPwr %d\n",
1019 ctlMode, pCtlMode[ctlMode], twiceMaxEdgePower,
1020 scaledPower, minCtlPower);
1021
1022 switch (pCtlMode[ctlMode]) {
1023 case CTL_11B:
1024 for (i = 0; i < ARRAY_SIZE(targetPowerCck.tPow2x); i++) {
1025 targetPowerCck.tPow2x[i] =
1026 min(targetPowerCck.tPow2x[i],
1027 minCtlPower);
1028 }
1029 break;
1030 case CTL_11A:
1031 case CTL_11G:
1032 for (i = 0; i < ARRAY_SIZE(targetPowerOfdm.tPow2x); i++) {
1033 targetPowerOfdm.tPow2x[i] =
1034 min(targetPowerOfdm.tPow2x[i],
1035 minCtlPower);
1036 }
1037 break;
1038 case CTL_5GHT20:
1039 case CTL_2GHT20:
1040 for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++) {
1041 targetPowerHt20.tPow2x[i] =
1042 min(targetPowerHt20.tPow2x[i],
1043 minCtlPower);
1044 }
1045 break;
1046 case CTL_11B_EXT:
1047 targetPowerCckExt.tPow2x[0] =
1048 min(targetPowerCckExt.tPow2x[0], minCtlPower);
1049 break;
1050 case CTL_11A_EXT:
1051 case CTL_11G_EXT:
1052 targetPowerOfdmExt.tPow2x[0] =
1053 min(targetPowerOfdmExt.tPow2x[0], minCtlPower);
1054 break;
1055 case CTL_5GHT40:
1056 case CTL_2GHT40:
1057 for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
1058 targetPowerHt40.tPow2x[i] =
1059 min(targetPowerHt40.tPow2x[i],
1060 minCtlPower);
1061 }
1062 break;
1063 default:
1064 break;
1065 }
1066 }
1067
1068 ratesArray[rate6mb] = ratesArray[rate9mb] = ratesArray[rate12mb] =
1069 ratesArray[rate18mb] = ratesArray[rate24mb] =
1070 targetPowerOfdm.tPow2x[0];
1071 ratesArray[rate36mb] = targetPowerOfdm.tPow2x[1];
1072 ratesArray[rate48mb] = targetPowerOfdm.tPow2x[2];
1073 ratesArray[rate54mb] = targetPowerOfdm.tPow2x[3];
1074 ratesArray[rateXr] = targetPowerOfdm.tPow2x[0];
1075
1076 for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++)
1077 ratesArray[rateHt20_0 + i] = targetPowerHt20.tPow2x[i];
1078
1079 if (IS_CHAN_2GHZ(chan)) {
1080 ratesArray[rate1l] = targetPowerCck.tPow2x[0];
1081 ratesArray[rate2s] = ratesArray[rate2l] =
1082 targetPowerCck.tPow2x[1];
1083 ratesArray[rate5_5s] = ratesArray[rate5_5l] =
1084 targetPowerCck.tPow2x[2];
1085 ;
1086 ratesArray[rate11s] = ratesArray[rate11l] =
1087 targetPowerCck.tPow2x[3];
1088 ;
1089 }
1090 if (IS_CHAN_HT40(chan)) {
1091 for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
1092 ratesArray[rateHt40_0 + i] =
1093 targetPowerHt40.tPow2x[i];
1094 }
1095 ratesArray[rateDupOfdm] = targetPowerHt40.tPow2x[0];
1096 ratesArray[rateDupCck] = targetPowerHt40.tPow2x[0];
1097 ratesArray[rateExtOfdm] = targetPowerOfdmExt.tPow2x[0];
1098 if (IS_CHAN_2GHZ(chan)) {
1099 ratesArray[rateExtCck] =
1100 targetPowerCckExt.tPow2x[0];
1101 }
1102 }
1103 return true;
1104}
1105
1106bool ath9k_hw_set_power_cal_table(struct ath_hal *ah,
1107 struct ath9k_channel *chan,
1108 int16_t *pTxPowerIndexOffset)
1109{
1110 struct ath_hal_5416 *ahp = AH5416(ah);
1111 struct ar5416_eeprom *pEepData = &ahp->ah_eeprom;
1112 struct cal_data_per_freq *pRawDataset;
1113 u8 *pCalBChans = NULL;
1114 u16 pdGainOverlap_t2;
1115 static u8 pdadcValues[AR5416_NUM_PDADC_VALUES];
1116 u16 gainBoundaries[AR5416_PD_GAINS_IN_MASK];
1117 u16 numPiers, i, j;
1118 int16_t tMinCalPower;
1119 u16 numXpdGain, xpdMask;
1120 u16 xpdGainValues[AR5416_NUM_PD_GAINS] = { 0, 0, 0, 0 };
1121 u32 reg32, regOffset, regChainOffset;
1122 int16_t modalIdx;
1123
1124 modalIdx = IS_CHAN_2GHZ(chan) ? 1 : 0;
1125 xpdMask = pEepData->modalHeader[modalIdx].xpdGain;
1126
1127 if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
1128 AR5416_EEP_MINOR_VER_2) {
1129 pdGainOverlap_t2 =
1130 pEepData->modalHeader[modalIdx].pdGainOverlap;
1131 } else {
1132 pdGainOverlap_t2 = (u16)(MS(REG_READ(ah, AR_PHY_TPCRG5),
1133 AR_PHY_TPCRG5_PD_GAIN_OVERLAP));
1134 }
1135
1136 if (IS_CHAN_2GHZ(chan)) {
1137 pCalBChans = pEepData->calFreqPier2G;
1138 numPiers = AR5416_NUM_2G_CAL_PIERS;
1139 } else {
1140 pCalBChans = pEepData->calFreqPier5G;
1141 numPiers = AR5416_NUM_5G_CAL_PIERS;
1142 }
1143
1144 numXpdGain = 0;
1145
1146 for (i = 1; i <= AR5416_PD_GAINS_IN_MASK; i++) {
1147 if ((xpdMask >> (AR5416_PD_GAINS_IN_MASK - i)) & 1) {
1148 if (numXpdGain >= AR5416_NUM_PD_GAINS)
1149 break;
1150 xpdGainValues[numXpdGain] =
1151 (u16)(AR5416_PD_GAINS_IN_MASK - i);
1152 numXpdGain++;
1153 }
1154 }
1155
1156 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
1157 (numXpdGain - 1) & 0x3);
1158 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1,
1159 xpdGainValues[0]);
1160 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2,
1161 xpdGainValues[1]);
1162 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3,
1163 xpdGainValues[2]);
1164
1165 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
1166 if (AR_SREV_5416_V20_OR_LATER(ah) &&
1167 (ahp->ah_rxchainmask == 5 || ahp->ah_txchainmask == 5) &&
1168 (i != 0)) {
1169 regChainOffset = (i == 1) ? 0x2000 : 0x1000;
1170 } else
1171 regChainOffset = i * 0x1000;
1172
1173 if (pEepData->baseEepHeader.txMask & (1 << i)) {
1174 if (IS_CHAN_2GHZ(chan))
1175 pRawDataset = pEepData->calPierData2G[i];
1176 else
1177 pRawDataset = pEepData->calPierData5G[i];
1178
1179 ath9k_hw_get_gain_boundaries_pdadcs(ah, chan,
1180 pRawDataset, pCalBChans,
1181 numPiers, pdGainOverlap_t2,
1182 &tMinCalPower, gainBoundaries,
1183 pdadcValues, numXpdGain);
1184
1185 if ((i == 0) || AR_SREV_5416_V20_OR_LATER(ah)) {
1186 REG_WRITE(ah,
1187 AR_PHY_TPCRG5 + regChainOffset,
1188 SM(pdGainOverlap_t2,
1189 AR_PHY_TPCRG5_PD_GAIN_OVERLAP)
1190 | SM(gainBoundaries[0],
1191 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_1)
1192 | SM(gainBoundaries[1],
1193 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_2)
1194 | SM(gainBoundaries[2],
1195 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_3)
1196 | SM(gainBoundaries[3],
1197 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_4));
1198 }
1199
1200 regOffset = AR_PHY_BASE + (672 << 2) + regChainOffset;
1201 for (j = 0; j < 32; j++) {
1202 reg32 = ((pdadcValues[4 * j + 0] & 0xFF) << 0) |
1203 ((pdadcValues[4 * j + 1] & 0xFF) << 8) |
1204 ((pdadcValues[4 * j + 2] & 0xFF) << 16) |
1205 ((pdadcValues[4 * j + 3] & 0xFF) << 24);
1206 REG_WRITE(ah, regOffset, reg32);
1207
1208 DPRINTF(ah->ah_sc, ATH_DBG_PHY_IO,
1209 "PDADC (%d,%4x): %4.4x %8.8x\n",
1210 i, regChainOffset, regOffset,
1211 reg32);
1212 DPRINTF(ah->ah_sc, ATH_DBG_PHY_IO,
1213 "PDADC: Chain %d | PDADC %3d Value %3d | "
1214 "PDADC %3d Value %3d | PDADC %3d Value %3d | "
1215 "PDADC %3d Value %3d |\n",
1216 i, 4 * j, pdadcValues[4 * j],
1217 4 * j + 1, pdadcValues[4 * j + 1],
1218 4 * j + 2, pdadcValues[4 * j + 2],
1219 4 * j + 3,
1220 pdadcValues[4 * j + 3]);
1221
1222 regOffset += 4;
1223 }
1224 }
1225 }
1226
1227 *pTxPowerIndexOffset = 0;
1228
1229 return true;
1230}
1231
1232/* XXX: Clean me up, make me more legible */
1233bool ath9k_hw_eeprom_set_board_values(struct ath_hal *ah,
1234 struct ath9k_channel *chan)
1235{
1236 struct modal_eep_header *pModal;
1237 struct ath_hal_5416 *ahp = AH5416(ah);
1238 struct ar5416_eeprom *eep = &ahp->ah_eeprom;
1239 int i, regChainOffset;
1240 u8 txRxAttenLocal;
1241 u16 ant_config;
1242
1243 pModal = &(eep->modalHeader[IS_CHAN_2GHZ(chan)]);
1244
1245 txRxAttenLocal = IS_CHAN_2GHZ(chan) ? 23 : 44;
1246
1247 ath9k_hw_get_eeprom_antenna_cfg(ah, chan, 1, &ant_config);
1248 REG_WRITE(ah, AR_PHY_SWITCH_COM, ant_config);
1249
1250 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
1251 if (AR_SREV_9280(ah)) {
1252 if (i >= 2)
1253 break;
1254 }
1255
1256 if (AR_SREV_5416_V20_OR_LATER(ah) &&
1257 (ahp->ah_rxchainmask == 5 || ahp->ah_txchainmask == 5)
1258 && (i != 0))
1259 regChainOffset = (i == 1) ? 0x2000 : 0x1000;
1260 else
1261 regChainOffset = i * 0x1000;
1262
1263 REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
1264 pModal->antCtrlChain[i]);
1265
1266 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset,
1267 (REG_READ(ah,
1268 AR_PHY_TIMING_CTRL4(0) +
1269 regChainOffset) &
1270 ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF |
1271 AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) |
1272 SM(pModal->iqCalICh[i],
1273 AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) |
1274 SM(pModal->iqCalQCh[i],
1275 AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF));
1276
1277 if ((i == 0) || AR_SREV_5416_V20_OR_LATER(ah)) {
1278 if ((eep->baseEepHeader.version &
1279 AR5416_EEP_VER_MINOR_MASK) >=
1280 AR5416_EEP_MINOR_VER_3) {
1281 txRxAttenLocal = pModal->txRxAttenCh[i];
1282 if (AR_SREV_9280_10_OR_LATER(ah)) {
1283 REG_RMW_FIELD(ah,
1284 AR_PHY_GAIN_2GHZ +
1285 regChainOffset,
1286 AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN,
1287 pModal->
1288 bswMargin[i]);
1289 REG_RMW_FIELD(ah,
1290 AR_PHY_GAIN_2GHZ +
1291 regChainOffset,
1292 AR_PHY_GAIN_2GHZ_XATTEN1_DB,
1293 pModal->
1294 bswAtten[i]);
1295 REG_RMW_FIELD(ah,
1296 AR_PHY_GAIN_2GHZ +
1297 regChainOffset,
1298 AR_PHY_GAIN_2GHZ_XATTEN2_MARGIN,
1299 pModal->
1300 xatten2Margin[i]);
1301 REG_RMW_FIELD(ah,
1302 AR_PHY_GAIN_2GHZ +
1303 regChainOffset,
1304 AR_PHY_GAIN_2GHZ_XATTEN2_DB,
1305 pModal->
1306 xatten2Db[i]);
1307 } else {
1308 REG_WRITE(ah,
1309 AR_PHY_GAIN_2GHZ +
1310 regChainOffset,
1311 (REG_READ(ah,
1312 AR_PHY_GAIN_2GHZ +
1313 regChainOffset) &
1314 ~AR_PHY_GAIN_2GHZ_BSW_MARGIN)
1315 | SM(pModal->
1316 bswMargin[i],
1317 AR_PHY_GAIN_2GHZ_BSW_MARGIN));
1318 REG_WRITE(ah,
1319 AR_PHY_GAIN_2GHZ +
1320 regChainOffset,
1321 (REG_READ(ah,
1322 AR_PHY_GAIN_2GHZ +
1323 regChainOffset) &
1324 ~AR_PHY_GAIN_2GHZ_BSW_ATTEN)
1325 | SM(pModal->bswAtten[i],
1326 AR_PHY_GAIN_2GHZ_BSW_ATTEN));
1327 }
1328 }
1329 if (AR_SREV_9280_10_OR_LATER(ah)) {
1330 REG_RMW_FIELD(ah,
1331 AR_PHY_RXGAIN +
1332 regChainOffset,
1333 AR9280_PHY_RXGAIN_TXRX_ATTEN,
1334 txRxAttenLocal);
1335 REG_RMW_FIELD(ah,
1336 AR_PHY_RXGAIN +
1337 regChainOffset,
1338 AR9280_PHY_RXGAIN_TXRX_MARGIN,
1339 pModal->rxTxMarginCh[i]);
1340 } else {
1341 REG_WRITE(ah,
1342 AR_PHY_RXGAIN + regChainOffset,
1343 (REG_READ(ah,
1344 AR_PHY_RXGAIN +
1345 regChainOffset) &
1346 ~AR_PHY_RXGAIN_TXRX_ATTEN) |
1347 SM(txRxAttenLocal,
1348 AR_PHY_RXGAIN_TXRX_ATTEN));
1349 REG_WRITE(ah,
1350 AR_PHY_GAIN_2GHZ +
1351 regChainOffset,
1352 (REG_READ(ah,
1353 AR_PHY_GAIN_2GHZ +
1354 regChainOffset) &
1355 ~AR_PHY_GAIN_2GHZ_RXTX_MARGIN) |
1356 SM(pModal->rxTxMarginCh[i],
1357 AR_PHY_GAIN_2GHZ_RXTX_MARGIN));
1358 }
1359 }
1360 }
1361
1362 if (AR_SREV_9280_10_OR_LATER(ah)) {
1363 if (IS_CHAN_2GHZ(chan)) {
1364 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH0,
1365 AR_AN_RF2G1_CH0_OB,
1366 AR_AN_RF2G1_CH0_OB_S,
1367 pModal->ob);
1368 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH0,
1369 AR_AN_RF2G1_CH0_DB,
1370 AR_AN_RF2G1_CH0_DB_S,
1371 pModal->db);
1372 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH1,
1373 AR_AN_RF2G1_CH1_OB,
1374 AR_AN_RF2G1_CH1_OB_S,
1375 pModal->ob_ch1);
1376 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH1,
1377 AR_AN_RF2G1_CH1_DB,
1378 AR_AN_RF2G1_CH1_DB_S,
1379 pModal->db_ch1);
1380 } else {
1381 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH0,
1382 AR_AN_RF5G1_CH0_OB5,
1383 AR_AN_RF5G1_CH0_OB5_S,
1384 pModal->ob);
1385 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH0,
1386 AR_AN_RF5G1_CH0_DB5,
1387 AR_AN_RF5G1_CH0_DB5_S,
1388 pModal->db);
1389 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH1,
1390 AR_AN_RF5G1_CH1_OB5,
1391 AR_AN_RF5G1_CH1_OB5_S,
1392 pModal->ob_ch1);
1393 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH1,
1394 AR_AN_RF5G1_CH1_DB5,
1395 AR_AN_RF5G1_CH1_DB5_S,
1396 pModal->db_ch1);
1397 }
1398 ath9k_hw_analog_shift_rmw(ah, AR_AN_TOP2,
1399 AR_AN_TOP2_XPABIAS_LVL,
1400 AR_AN_TOP2_XPABIAS_LVL_S,
1401 pModal->xpaBiasLvl);
1402 ath9k_hw_analog_shift_rmw(ah, AR_AN_TOP2,
1403 AR_AN_TOP2_LOCALBIAS,
1404 AR_AN_TOP2_LOCALBIAS_S,
1405 pModal->local_bias);
1406 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, "ForceXPAon: %d\n",
1407 pModal->force_xpaon);
1408 REG_RMW_FIELD(ah, AR_PHY_XPA_CFG, AR_PHY_FORCE_XPA_CFG,
1409 pModal->force_xpaon);
1410 }
1411
1412 REG_RMW_FIELD(ah, AR_PHY_SETTLING, AR_PHY_SETTLING_SWITCH,
1413 pModal->switchSettling);
1414 REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ, AR_PHY_DESIRED_SZ_ADC,
1415 pModal->adcDesiredSize);
1416
1417 if (!AR_SREV_9280_10_OR_LATER(ah))
1418 REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ,
1419 AR_PHY_DESIRED_SZ_PGA,
1420 pModal->pgaDesiredSize);
1421
1422 REG_WRITE(ah, AR_PHY_RF_CTL4,
1423 SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF)
1424 | SM(pModal->txEndToXpaOff,
1425 AR_PHY_RF_CTL4_TX_END_XPAB_OFF)
1426 | SM(pModal->txFrameToXpaOn,
1427 AR_PHY_RF_CTL4_FRAME_XPAA_ON)
1428 | SM(pModal->txFrameToXpaOn,
1429 AR_PHY_RF_CTL4_FRAME_XPAB_ON));
1430
1431 REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_A2_RX_ON,
1432 pModal->txEndToRxOn);
1433 if (AR_SREV_9280_10_OR_LATER(ah)) {
1434 REG_RMW_FIELD(ah, AR_PHY_CCA, AR9280_PHY_CCA_THRESH62,
1435 pModal->thresh62);
1436 REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0,
1437 AR_PHY_EXT_CCA0_THRESH62,
1438 pModal->thresh62);
1439 } else {
1440 REG_RMW_FIELD(ah, AR_PHY_CCA, AR_PHY_CCA_THRESH62,
1441 pModal->thresh62);
1442 REG_RMW_FIELD(ah, AR_PHY_EXT_CCA,
1443 AR_PHY_EXT_CCA_THRESH62,
1444 pModal->thresh62);
1445 }
1446
1447 if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
1448 AR5416_EEP_MINOR_VER_2) {
1449 REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
1450 AR_PHY_TX_END_DATA_START,
1451 pModal->txFrameToDataStart);
1452 REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_PA_ON,
1453 pModal->txFrameToPaOn);
1454 }
1455
1456 if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
1457 AR5416_EEP_MINOR_VER_3) {
1458 if (IS_CHAN_HT40(chan))
1459 REG_RMW_FIELD(ah, AR_PHY_SETTLING,
1460 AR_PHY_SETTLING_SWITCH,
1461 pModal->swSettleHt40);
1462 }
1463
1464 return true;
1465}
1466
1467int ath9k_hw_get_eeprom_antenna_cfg(struct ath_hal *ah,
1468 struct ath9k_channel *chan,
1469 u8 index, u16 *config)
1470{
1471 struct ath_hal_5416 *ahp = AH5416(ah);
1472 struct ar5416_eeprom *eep = &ahp->ah_eeprom;
1473 struct modal_eep_header *pModal =
1474 &(eep->modalHeader[IS_CHAN_2GHZ(chan)]);
1475 struct base_eep_header *pBase = &eep->baseEepHeader;
1476
1477 switch (index) {
1478 case 0:
1479 *config = pModal->antCtrlCommon & 0xFFFF;
1480 return 0;
1481 case 1:
1482 if (pBase->version >= 0x0E0D) {
1483 if (pModal->useAnt1) {
1484 *config =
1485 ((pModal->antCtrlCommon & 0xFFFF0000) >> 16);
1486 return 0;
1487 }
1488 }
1489 break;
1490 default:
1491 break;
1492 }
1493
1494 return -EINVAL;
1495}
1496
1497u8 ath9k_hw_get_num_ant_config(struct ath_hal *ah,
1498 enum ieee80211_band freq_band)
1499{
1500 struct ath_hal_5416 *ahp = AH5416(ah);
1501 struct ar5416_eeprom *eep = &ahp->ah_eeprom;
1502 struct modal_eep_header *pModal =
1503 &(eep->modalHeader[IEEE80211_BAND_5GHZ == freq_band]);
1504 struct base_eep_header *pBase = &eep->baseEepHeader;
1505 u8 num_ant_config;
1506
1507 num_ant_config = 1;
1508
1509 if (pBase->version >= 0x0E0D)
1510 if (pModal->useAnt1)
1511 num_ant_config += 1;
1512
1513 return num_ant_config;
1514}
1515
1516u16 ath9k_hw_eeprom_get_spur_chan(struct ath_hal *ah, u16 i, bool is2GHz)
1517{
1518 struct ath_hal_5416 *ahp = AH5416(ah);
1519 struct ar5416_eeprom *eep =
1520 (struct ar5416_eeprom *) &ahp->ah_eeprom;
1521 u16 spur_val = AR_NO_SPUR;
1522
1523 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
1524 "Getting spur idx %d is2Ghz. %d val %x\n",
1525 i, is2GHz, ah->ah_config.spurchans[i][is2GHz]);
1526
1527 switch (ah->ah_config.spurmode) {
1528 case SPUR_DISABLE:
1529 break;
1530 case SPUR_ENABLE_IOCTL:
1531 spur_val = ah->ah_config.spurchans[i][is2GHz];
1532 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
1533 "Getting spur val from new loc. %d\n", spur_val);
1534 break;
1535 case SPUR_ENABLE_EEPROM:
1536 spur_val = eep->modalHeader[is2GHz].spurChans[i].spurChan;
1537 break;
1538
1539 }
1540
1541 return spur_val;
1542}
1543
1544u32 ath9k_hw_get_eeprom(struct ath_hal *ah,
1545 enum eeprom_param param)
1546{
1547 struct ath_hal_5416 *ahp = AH5416(ah);
1548 struct ar5416_eeprom *eep = &ahp->ah_eeprom;
1549 struct modal_eep_header *pModal = eep->modalHeader;
1550 struct base_eep_header *pBase = &eep->baseEepHeader;
1551
1552 switch (param) {
1553 case EEP_NFTHRESH_5:
1554 return -pModal[0].noiseFloorThreshCh[0];
1555 case EEP_NFTHRESH_2:
1556 return -pModal[1].noiseFloorThreshCh[0];
1557 case AR_EEPROM_MAC(0):
1558 return pBase->macAddr[0] << 8 | pBase->macAddr[1];
1559 case AR_EEPROM_MAC(1):
1560 return pBase->macAddr[2] << 8 | pBase->macAddr[3];
1561 case AR_EEPROM_MAC(2):
1562 return pBase->macAddr[4] << 8 | pBase->macAddr[5];
1563 case EEP_REG_0:
1564 return pBase->regDmn[0];
1565 case EEP_REG_1:
1566 return pBase->regDmn[1];
1567 case EEP_OP_CAP:
1568 return pBase->deviceCap;
1569 case EEP_OP_MODE:
1570 return pBase->opCapFlags;
1571 case EEP_RF_SILENT:
1572 return pBase->rfSilent;
1573 case EEP_OB_5:
1574 return pModal[0].ob;
1575 case EEP_DB_5:
1576 return pModal[0].db;
1577 case EEP_OB_2:
1578 return pModal[1].ob;
1579 case EEP_DB_2:
1580 return pModal[1].db;
1581 case EEP_MINOR_REV:
1582 return pBase->version & AR5416_EEP_VER_MINOR_MASK;
1583 case EEP_TX_MASK:
1584 return pBase->txMask;
1585 case EEP_RX_MASK:
1586 return pBase->rxMask;
1587 default:
1588 return 0;
1589 }
1590}
1591
1592int ath9k_hw_eeprom_attach(struct ath_hal *ah)
1593{
1594 int status;
1595
1596 if (ath9k_hw_use_flash(ah))
1597 ath9k_hw_flash_map(ah);
1598
1599 if (!ath9k_hw_fill_eeprom(ah))
1600 return -EIO;
1601
1602 status = ath9k_hw_check_eeprom(ah);
1603
1604 return status;
1605}
diff --git a/drivers/net/wireless/ath9k/hw.c b/drivers/net/wireless/ath9k/hw.c
index 1417ba07523d..e05c9ef55e47 100644
--- a/drivers/net/wireless/ath9k/hw.c
+++ b/drivers/net/wireless/ath9k/hw.c
@@ -23,183 +23,68 @@
23#include "phy.h" 23#include "phy.h"
24#include "initvals.h" 24#include "initvals.h"
25 25
26static void ath9k_hw_iqcal_collect(struct ath_hal *ah);
27static void ath9k_hw_iqcalibrate(struct ath_hal *ah, u8 numChains);
28static void ath9k_hw_adc_gaincal_collect(struct ath_hal *ah);
29static void ath9k_hw_adc_gaincal_calibrate(struct ath_hal *ah,
30 u8 numChains);
31static void ath9k_hw_adc_dccal_collect(struct ath_hal *ah);
32static void ath9k_hw_adc_dccal_calibrate(struct ath_hal *ah,
33 u8 numChains);
34
35static const u8 CLOCK_RATE[] = { 40, 80, 22, 44, 88, 40 }; 26static const u8 CLOCK_RATE[] = { 40, 80, 22, 44, 88, 40 };
36static const int16_t NOISE_FLOOR[] = { -96, -93, -98, -96, -93, -96 };
37
38static const struct hal_percal_data iq_cal_multi_sample = {
39 IQ_MISMATCH_CAL,
40 MAX_CAL_SAMPLES,
41 PER_MIN_LOG_COUNT,
42 ath9k_hw_iqcal_collect,
43 ath9k_hw_iqcalibrate
44};
45static const struct hal_percal_data iq_cal_single_sample = {
46 IQ_MISMATCH_CAL,
47 MIN_CAL_SAMPLES,
48 PER_MAX_LOG_COUNT,
49 ath9k_hw_iqcal_collect,
50 ath9k_hw_iqcalibrate
51};
52static const struct hal_percal_data adc_gain_cal_multi_sample = {
53 ADC_GAIN_CAL,
54 MAX_CAL_SAMPLES,
55 PER_MIN_LOG_COUNT,
56 ath9k_hw_adc_gaincal_collect,
57 ath9k_hw_adc_gaincal_calibrate
58};
59static const struct hal_percal_data adc_gain_cal_single_sample = {
60 ADC_GAIN_CAL,
61 MIN_CAL_SAMPLES,
62 PER_MAX_LOG_COUNT,
63 ath9k_hw_adc_gaincal_collect,
64 ath9k_hw_adc_gaincal_calibrate
65};
66static const struct hal_percal_data adc_dc_cal_multi_sample = {
67 ADC_DC_CAL,
68 MAX_CAL_SAMPLES,
69 PER_MIN_LOG_COUNT,
70 ath9k_hw_adc_dccal_collect,
71 ath9k_hw_adc_dccal_calibrate
72};
73static const struct hal_percal_data adc_dc_cal_single_sample = {
74 ADC_DC_CAL,
75 MIN_CAL_SAMPLES,
76 PER_MAX_LOG_COUNT,
77 ath9k_hw_adc_dccal_collect,
78 ath9k_hw_adc_dccal_calibrate
79};
80static const struct hal_percal_data adc_init_dc_cal = {
81 ADC_DC_INIT_CAL,
82 MIN_CAL_SAMPLES,
83 INIT_LOG_COUNT,
84 ath9k_hw_adc_dccal_collect,
85 ath9k_hw_adc_dccal_calibrate
86};
87 27
88static struct ath9k_rate_table ar5416_11a_table = { 28extern struct hal_percal_data iq_cal_multi_sample;
89 8, 29extern struct hal_percal_data iq_cal_single_sample;
90 {0}, 30extern struct hal_percal_data adc_gain_cal_multi_sample;
91 { 31extern struct hal_percal_data adc_gain_cal_single_sample;
92 {true, PHY_OFDM, 6000, 0x0b, 0x00, (0x80 | 12), 0}, 32extern struct hal_percal_data adc_dc_cal_multi_sample;
93 {true, PHY_OFDM, 9000, 0x0f, 0x00, 18, 0}, 33extern struct hal_percal_data adc_dc_cal_single_sample;
94 {true, PHY_OFDM, 12000, 0x0a, 0x00, (0x80 | 24), 2}, 34extern struct hal_percal_data adc_init_dc_cal;
95 {true, PHY_OFDM, 18000, 0x0e, 0x00, 36, 2},
96 {true, PHY_OFDM, 24000, 0x09, 0x00, (0x80 | 48), 4},
97 {true, PHY_OFDM, 36000, 0x0d, 0x00, 72, 4},
98 {true, PHY_OFDM, 48000, 0x08, 0x00, 96, 4},
99 {true, PHY_OFDM, 54000, 0x0c, 0x00, 108, 4}
100 },
101};
102 35
103static struct ath9k_rate_table ar5416_11b_table = { 36static bool ath9k_hw_set_reset_reg(struct ath_hal *ah, u32 type);
104 4, 37static void ath9k_hw_set_regs(struct ath_hal *ah, struct ath9k_channel *chan,
105 {0}, 38 enum ath9k_ht_macmode macmode);
106 { 39static u32 ath9k_hw_ini_fixup(struct ath_hal *ah,
107 {true, PHY_CCK, 1000, 0x1b, 0x00, (0x80 | 2), 0}, 40 struct ar5416_eeprom *pEepData,
108 {true, PHY_CCK, 2000, 0x1a, 0x04, (0x80 | 4), 1}, 41 u32 reg, u32 value);
109 {true, PHY_CCK, 5500, 0x19, 0x04, (0x80 | 11), 1}, 42static void ath9k_hw_9280_spur_mitigate(struct ath_hal *ah, struct ath9k_channel *chan);
110 {true, PHY_CCK, 11000, 0x18, 0x04, (0x80 | 22), 1} 43static void ath9k_hw_spur_mitigate(struct ath_hal *ah, struct ath9k_channel *chan);
111 },
112};
113 44
114static struct ath9k_rate_table ar5416_11g_table = { 45/********************/
115 12, 46/* Helper Functions */
116 {0}, 47/********************/
117 {
118 {true, PHY_CCK, 1000, 0x1b, 0x00, (0x80 | 2), 0},
119 {true, PHY_CCK, 2000, 0x1a, 0x04, (0x80 | 4), 1},
120 {true, PHY_CCK, 5500, 0x19, 0x04, (0x80 | 11), 2},
121 {true, PHY_CCK, 11000, 0x18, 0x04, (0x80 | 22), 3},
122 48
123 {false, PHY_OFDM, 6000, 0x0b, 0x00, 12, 4}, 49static u32 ath9k_hw_mac_usec(struct ath_hal *ah, u32 clks)
124 {false, PHY_OFDM, 9000, 0x0f, 0x00, 18, 4}, 50{
125 {true, PHY_OFDM, 12000, 0x0a, 0x00, 24, 6}, 51 if (ah->ah_curchan != NULL)
126 {true, PHY_OFDM, 18000, 0x0e, 0x00, 36, 6}, 52 return clks / CLOCK_RATE[ath9k_hw_chan2wmode(ah, ah->ah_curchan)];
127 {true, PHY_OFDM, 24000, 0x09, 0x00, 48, 8}, 53 else
128 {true, PHY_OFDM, 36000, 0x0d, 0x00, 72, 8}, 54 return clks / CLOCK_RATE[ATH9K_MODE_11B];
129 {true, PHY_OFDM, 48000, 0x08, 0x00, 96, 8}, 55}
130 {true, PHY_OFDM, 54000, 0x0c, 0x00, 108, 8}
131 },
132};
133 56
134static struct ath9k_rate_table ar5416_11ng_table = { 57static u32 ath9k_hw_mac_to_usec(struct ath_hal *ah, u32 clks)
135 28, 58{
136 {0}, 59 struct ath9k_channel *chan = ah->ah_curchan;
137 {
138 {true, PHY_CCK, 1000, 0x1b, 0x00, (0x80 | 2), 0},
139 {true, PHY_CCK, 2000, 0x1a, 0x04, (0x80 | 4), 1},
140 {true, PHY_CCK, 5500, 0x19, 0x04, (0x80 | 11), 2},
141 {true, PHY_CCK, 11000, 0x18, 0x04, (0x80 | 22), 3},
142 60
143 {false, PHY_OFDM, 6000, 0x0b, 0x00, 12, 4}, 61 if (chan && IS_CHAN_HT40(chan))
144 {false, PHY_OFDM, 9000, 0x0f, 0x00, 18, 4}, 62 return ath9k_hw_mac_usec(ah, clks) / 2;
145 {true, PHY_OFDM, 12000, 0x0a, 0x00, 24, 6}, 63 else
146 {true, PHY_OFDM, 18000, 0x0e, 0x00, 36, 6}, 64 return ath9k_hw_mac_usec(ah, clks);
147 {true, PHY_OFDM, 24000, 0x09, 0x00, 48, 8}, 65}
148 {true, PHY_OFDM, 36000, 0x0d, 0x00, 72, 8},
149 {true, PHY_OFDM, 48000, 0x08, 0x00, 96, 8},
150 {true, PHY_OFDM, 54000, 0x0c, 0x00, 108, 8},
151 {true, PHY_HT, 6500, 0x80, 0x00, 0, 4},
152 {true, PHY_HT, 13000, 0x81, 0x00, 1, 6},
153 {true, PHY_HT, 19500, 0x82, 0x00, 2, 6},
154 {true, PHY_HT, 26000, 0x83, 0x00, 3, 8},
155 {true, PHY_HT, 39000, 0x84, 0x00, 4, 8},
156 {true, PHY_HT, 52000, 0x85, 0x00, 5, 8},
157 {true, PHY_HT, 58500, 0x86, 0x00, 6, 8},
158 {true, PHY_HT, 65000, 0x87, 0x00, 7, 8},
159 {true, PHY_HT, 13000, 0x88, 0x00, 8, 4},
160 {true, PHY_HT, 26000, 0x89, 0x00, 9, 6},
161 {true, PHY_HT, 39000, 0x8a, 0x00, 10, 6},
162 {true, PHY_HT, 52000, 0x8b, 0x00, 11, 8},
163 {true, PHY_HT, 78000, 0x8c, 0x00, 12, 8},
164 {true, PHY_HT, 104000, 0x8d, 0x00, 13, 8},
165 {true, PHY_HT, 117000, 0x8e, 0x00, 14, 8},
166 {true, PHY_HT, 130000, 0x8f, 0x00, 15, 8},
167 },
168};
169 66
170static struct ath9k_rate_table ar5416_11na_table = { 67static u32 ath9k_hw_mac_clks(struct ath_hal *ah, u32 usecs)
171 24, 68{
172 {0}, 69 if (ah->ah_curchan != NULL)
173 { 70 return usecs * CLOCK_RATE[ath9k_hw_chan2wmode(ah,
174 {true, PHY_OFDM, 6000, 0x0b, 0x00, (0x80 | 12), 0}, 71 ah->ah_curchan)];
175 {true, PHY_OFDM, 9000, 0x0f, 0x00, 18, 0}, 72 else
176 {true, PHY_OFDM, 12000, 0x0a, 0x00, (0x80 | 24), 2}, 73 return usecs * CLOCK_RATE[ATH9K_MODE_11B];
177 {true, PHY_OFDM, 18000, 0x0e, 0x00, 36, 2}, 74}
178 {true, PHY_OFDM, 24000, 0x09, 0x00, (0x80 | 48), 4}, 75
179 {true, PHY_OFDM, 36000, 0x0d, 0x00, 72, 4}, 76static u32 ath9k_hw_mac_to_clks(struct ath_hal *ah, u32 usecs)
180 {true, PHY_OFDM, 48000, 0x08, 0x00, 96, 4}, 77{
181 {true, PHY_OFDM, 54000, 0x0c, 0x00, 108, 4}, 78 struct ath9k_channel *chan = ah->ah_curchan;
182 {true, PHY_HT, 6500, 0x80, 0x00, 0, 0}, 79
183 {true, PHY_HT, 13000, 0x81, 0x00, 1, 2}, 80 if (chan && IS_CHAN_HT40(chan))
184 {true, PHY_HT, 19500, 0x82, 0x00, 2, 2}, 81 return ath9k_hw_mac_clks(ah, usecs) * 2;
185 {true, PHY_HT, 26000, 0x83, 0x00, 3, 4}, 82 else
186 {true, PHY_HT, 39000, 0x84, 0x00, 4, 4}, 83 return ath9k_hw_mac_clks(ah, usecs);
187 {true, PHY_HT, 52000, 0x85, 0x00, 5, 4}, 84}
188 {true, PHY_HT, 58500, 0x86, 0x00, 6, 4},
189 {true, PHY_HT, 65000, 0x87, 0x00, 7, 4},
190 {true, PHY_HT, 13000, 0x88, 0x00, 8, 0},
191 {true, PHY_HT, 26000, 0x89, 0x00, 9, 2},
192 {true, PHY_HT, 39000, 0x8a, 0x00, 10, 2},
193 {true, PHY_HT, 52000, 0x8b, 0x00, 11, 4},
194 {true, PHY_HT, 78000, 0x8c, 0x00, 12, 4},
195 {true, PHY_HT, 104000, 0x8d, 0x00, 13, 4},
196 {true, PHY_HT, 117000, 0x8e, 0x00, 14, 4},
197 {true, PHY_HT, 130000, 0x8f, 0x00, 15, 4},
198 },
199};
200 85
201static enum wireless_mode ath9k_hw_chan2wmode(struct ath_hal *ah, 86enum wireless_mode ath9k_hw_chan2wmode(struct ath_hal *ah,
202 const struct ath9k_channel *chan) 87 const struct ath9k_channel *chan)
203{ 88{
204 if (IS_CHAN_CCK(chan)) 89 if (IS_CHAN_CCK(chan))
205 return ATH9K_MODE_11A; 90 return ATH9K_MODE_11A;
@@ -208,10 +93,7 @@ static enum wireless_mode ath9k_hw_chan2wmode(struct ath_hal *ah,
208 return ATH9K_MODE_11A; 93 return ATH9K_MODE_11A;
209} 94}
210 95
211static bool ath9k_hw_wait(struct ath_hal *ah, 96bool ath9k_hw_wait(struct ath_hal *ah, u32 reg, u32 mask, u32 val)
212 u32 reg,
213 u32 mask,
214 u32 val)
215{ 97{
216 int i; 98 int i;
217 99
@@ -222,78 +104,10 @@ static bool ath9k_hw_wait(struct ath_hal *ah,
222 udelay(AH_TIME_QUANTUM); 104 udelay(AH_TIME_QUANTUM);
223 } 105 }
224 DPRINTF(ah->ah_sc, ATH_DBG_PHY_IO, 106 DPRINTF(ah->ah_sc, ATH_DBG_PHY_IO,
225 "%s: timeout on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n", 107 "%s: timeout on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
226 __func__, reg, REG_READ(ah, reg), mask, val); 108 __func__, reg, REG_READ(ah, reg), mask, val);
227 return false;
228}
229
230static bool ath9k_hw_eeprom_read(struct ath_hal *ah, u32 off,
231 u16 *data)
232{
233 (void) REG_READ(ah, AR5416_EEPROM_OFFSET + (off << AR5416_EEPROM_S));
234
235 if (!ath9k_hw_wait(ah,
236 AR_EEPROM_STATUS_DATA,
237 AR_EEPROM_STATUS_DATA_BUSY |
238 AR_EEPROM_STATUS_DATA_PROT_ACCESS, 0)) {
239 return false;
240 }
241
242 *data = MS(REG_READ(ah, AR_EEPROM_STATUS_DATA),
243 AR_EEPROM_STATUS_DATA_VAL);
244
245 return true;
246}
247
248static int ath9k_hw_flash_map(struct ath_hal *ah)
249{
250 struct ath_hal_5416 *ahp = AH5416(ah);
251
252 ahp->ah_cal_mem = ioremap(AR5416_EEPROM_START_ADDR, AR5416_EEPROM_MAX);
253
254 if (!ahp->ah_cal_mem) {
255 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
256 "%s: cannot remap eeprom region \n", __func__);
257 return -EIO;
258 }
259
260 return 0;
261}
262
263static bool ath9k_hw_flash_read(struct ath_hal *ah, u32 off,
264 u16 *data)
265{
266 struct ath_hal_5416 *ahp = AH5416(ah);
267
268 *data = ioread16(ahp->ah_cal_mem + off);
269 return true;
270}
271
272static void ath9k_hw_read_revisions(struct ath_hal *ah)
273{
274 u32 val;
275
276 val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
277
278 if (val == 0xFF) {
279 val = REG_READ(ah, AR_SREV);
280
281 ah->ah_macVersion =
282 (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
283
284 ah->ah_macRev = MS(val, AR_SREV_REVISION2);
285 ah->ah_isPciExpress =
286 (val & AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
287
288 } else {
289 if (!AR_SREV_9100(ah))
290 ah->ah_macVersion = MS(val, AR_SREV_VERSION);
291
292 ah->ah_macRev = val & AR_SREV_REVISION;
293 109
294 if (ah->ah_macVersion == AR_SREV_VERSION_5416_PCIE) 110 return false;
295 ah->ah_isPciExpress = true;
296 }
297} 111}
298 112
299u32 ath9k_hw_reverse_bits(u32 val, u32 n) 113u32 ath9k_hw_reverse_bits(u32 val, u32 n)
@@ -308,596 +122,215 @@ u32 ath9k_hw_reverse_bits(u32 val, u32 n)
308 return retval; 122 return retval;
309} 123}
310 124
311static void ath9k_hw_set_defaults(struct ath_hal *ah) 125bool ath9k_get_channel_edges(struct ath_hal *ah,
126 u16 flags, u16 *low,
127 u16 *high)
312{ 128{
313 int i; 129 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
314
315 ah->ah_config.dma_beacon_response_time = 2;
316 ah->ah_config.sw_beacon_response_time = 10;
317 ah->ah_config.additional_swba_backoff = 0;
318 ah->ah_config.ack_6mb = 0x0;
319 ah->ah_config.cwm_ignore_extcca = 0;
320 ah->ah_config.pcie_powersave_enable = 0;
321 ah->ah_config.pcie_l1skp_enable = 0;
322 ah->ah_config.pcie_clock_req = 0;
323 ah->ah_config.pcie_power_reset = 0x100;
324 ah->ah_config.pcie_restore = 0;
325 ah->ah_config.pcie_waen = 0;
326 ah->ah_config.analog_shiftreg = 1;
327 ah->ah_config.ht_enable = 1;
328 ah->ah_config.ofdm_trig_low = 200;
329 ah->ah_config.ofdm_trig_high = 500;
330 ah->ah_config.cck_trig_high = 200;
331 ah->ah_config.cck_trig_low = 100;
332 ah->ah_config.enable_ani = 1;
333 ah->ah_config.noise_immunity_level = 4;
334 ah->ah_config.ofdm_weaksignal_det = 1;
335 ah->ah_config.cck_weaksignal_thr = 0;
336 ah->ah_config.spur_immunity_level = 2;
337 ah->ah_config.firstep_level = 0;
338 ah->ah_config.rssi_thr_high = 40;
339 ah->ah_config.rssi_thr_low = 7;
340 ah->ah_config.diversity_control = 0;
341 ah->ah_config.antenna_switch_swap = 0;
342 130
343 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) { 131 if (flags & CHANNEL_5GHZ) {
344 ah->ah_config.spurchans[i][0] = AR_NO_SPUR; 132 *low = pCap->low_5ghz_chan;
345 ah->ah_config.spurchans[i][1] = AR_NO_SPUR; 133 *high = pCap->high_5ghz_chan;
134 return true;
346 } 135 }
347 136 if ((flags & CHANNEL_2GHZ)) {
348 ah->ah_config.intr_mitigation = 1; 137 *low = pCap->low_2ghz_chan;
349} 138 *high = pCap->high_2ghz_chan;
350 139 return true;
351static void ath9k_hw_override_ini(struct ath_hal *ah,
352 struct ath9k_channel *chan)
353{
354 if (!AR_SREV_5416_V20_OR_LATER(ah)
355 || AR_SREV_9280_10_OR_LATER(ah))
356 return;
357
358 REG_WRITE(ah, 0x9800 + (651 << 2), 0x11);
359}
360
361static void ath9k_hw_init_bb(struct ath_hal *ah,
362 struct ath9k_channel *chan)
363{
364 u32 synthDelay;
365
366 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
367 if (IS_CHAN_CCK(chan))
368 synthDelay = (4 * synthDelay) / 22;
369 else
370 synthDelay /= 10;
371
372 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
373
374 udelay(synthDelay + BASE_ACTIVATE_DELAY);
375}
376
377static void ath9k_hw_init_interrupt_masks(struct ath_hal *ah,
378 enum ath9k_opmode opmode)
379{
380 struct ath_hal_5416 *ahp = AH5416(ah);
381
382 ahp->ah_maskReg = AR_IMR_TXERR |
383 AR_IMR_TXURN |
384 AR_IMR_RXERR |
385 AR_IMR_RXORN |
386 AR_IMR_BCNMISC;
387
388 if (ahp->ah_intrMitigation)
389 ahp->ah_maskReg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
390 else
391 ahp->ah_maskReg |= AR_IMR_RXOK;
392
393 ahp->ah_maskReg |= AR_IMR_TXOK;
394
395 if (opmode == ATH9K_M_HOSTAP)
396 ahp->ah_maskReg |= AR_IMR_MIB;
397
398 REG_WRITE(ah, AR_IMR, ahp->ah_maskReg);
399 REG_WRITE(ah, AR_IMR_S2, REG_READ(ah, AR_IMR_S2) | AR_IMR_S2_GTT);
400
401 if (!AR_SREV_9100(ah)) {
402 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
403 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT);
404 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
405 } 140 }
141 return false;
406} 142}
407 143
408static void ath9k_hw_init_qos(struct ath_hal *ah) 144u16 ath9k_hw_computetxtime(struct ath_hal *ah,
409{ 145 const struct ath9k_rate_table *rates,
410 REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa); 146 u32 frameLen, u16 rateix,
411 REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210); 147 bool shortPreamble)
412
413 REG_WRITE(ah, AR_QOS_NO_ACK,
414 SM(2, AR_QOS_NO_ACK_TWO_BIT) |
415 SM(5, AR_QOS_NO_ACK_BIT_OFF) |
416 SM(0, AR_QOS_NO_ACK_BYTE_OFF));
417
418 REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
419 REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
420 REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
421 REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
422 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
423}
424
425static void ath9k_hw_analog_shift_rmw(struct ath_hal *ah,
426 u32 reg,
427 u32 mask,
428 u32 shift,
429 u32 val)
430{
431 u32 regVal;
432
433 regVal = REG_READ(ah, reg) & ~mask;
434 regVal |= (val << shift) & mask;
435
436 REG_WRITE(ah, reg, regVal);
437
438 if (ah->ah_config.analog_shiftreg)
439 udelay(100);
440
441 return;
442}
443
444static u8 ath9k_hw_get_num_ant_config(struct ath_hal_5416 *ahp,
445 enum ieee80211_band freq_band)
446{ 148{
447 struct ar5416_eeprom *eep = &ahp->ah_eeprom; 149 u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
448 struct modal_eep_header *pModal = 150 u32 kbps;
449 &(eep->modalHeader[IEEE80211_BAND_5GHZ == freq_band]);
450 struct base_eep_header *pBase = &eep->baseEepHeader;
451 u8 num_ant_config;
452
453 num_ant_config = 1;
454
455 if (pBase->version >= 0x0E0D)
456 if (pModal->useAnt1)
457 num_ant_config += 1;
458
459 return num_ant_config;
460}
461 151
462static int 152 kbps = rates->info[rateix].rateKbps;
463ath9k_hw_get_eeprom_antenna_cfg(struct ath_hal_5416 *ahp,
464 struct ath9k_channel *chan,
465 u8 index,
466 u16 *config)
467{
468 struct ar5416_eeprom *eep = &ahp->ah_eeprom;
469 struct modal_eep_header *pModal =
470 &(eep->modalHeader[IS_CHAN_2GHZ(chan)]);
471 struct base_eep_header *pBase = &eep->baseEepHeader;
472 153
473 switch (index) { 154 if (kbps == 0)
474 case 0:
475 *config = pModal->antCtrlCommon & 0xFFFF;
476 return 0; 155 return 0;
477 case 1: 156
478 if (pBase->version >= 0x0E0D) { 157 switch (rates->info[rateix].phy) {
479 if (pModal->useAnt1) { 158 case PHY_CCK:
480 *config = 159 phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
481 ((pModal->antCtrlCommon & 0xFFFF0000) >> 16); 160 if (shortPreamble && rates->info[rateix].shortPreamble)
482 return 0; 161 phyTime >>= 1;
483 } 162 numBits = frameLen << 3;
163 txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
164 break;
165 case PHY_OFDM:
166 if (ah->ah_curchan && IS_CHAN_QUARTER_RATE(ah->ah_curchan)) {
167 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
168 numBits = OFDM_PLCP_BITS + (frameLen << 3);
169 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
170 txTime = OFDM_SIFS_TIME_QUARTER
171 + OFDM_PREAMBLE_TIME_QUARTER
172 + (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
173 } else if (ah->ah_curchan &&
174 IS_CHAN_HALF_RATE(ah->ah_curchan)) {
175 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
176 numBits = OFDM_PLCP_BITS + (frameLen << 3);
177 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
178 txTime = OFDM_SIFS_TIME_HALF +
179 OFDM_PREAMBLE_TIME_HALF
180 + (numSymbols * OFDM_SYMBOL_TIME_HALF);
181 } else {
182 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
183 numBits = OFDM_PLCP_BITS + (frameLen << 3);
184 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
185 txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME
186 + (numSymbols * OFDM_SYMBOL_TIME);
484 } 187 }
485 break; 188 break;
486 default: 189 default:
190 DPRINTF(ah->ah_sc, ATH_DBG_PHY_IO,
191 "%s: unknown phy %u (rate ix %u)\n", __func__,
192 rates->info[rateix].phy, rateix);
193 txTime = 0;
487 break; 194 break;
488 } 195 }
489 196
490 return -EINVAL; 197 return txTime;
491}
492
493static inline bool ath9k_hw_nvram_read(struct ath_hal *ah,
494 u32 off,
495 u16 *data)
496{
497 if (ath9k_hw_use_flash(ah))
498 return ath9k_hw_flash_read(ah, off, data);
499 else
500 return ath9k_hw_eeprom_read(ah, off, data);
501} 198}
502 199
503static bool ath9k_hw_fill_eeprom(struct ath_hal *ah) 200u32 ath9k_hw_mhz2ieee(struct ath_hal *ah, u32 freq, u32 flags)
504{ 201{
505 struct ath_hal_5416 *ahp = AH5416(ah); 202 if (flags & CHANNEL_2GHZ) {
506 struct ar5416_eeprom *eep = &ahp->ah_eeprom; 203 if (freq == 2484)
507 u16 *eep_data; 204 return 14;
508 int addr, ar5416_eep_start_loc = 0; 205 if (freq < 2484)
509 206 return (freq - 2407) / 5;
510 if (!ath9k_hw_use_flash(ah)) { 207 else
511 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, 208 return 15 + ((freq - 2512) / 20);
512 "%s: Reading from EEPROM, not flash\n", __func__); 209 } else if (flags & CHANNEL_5GHZ) {
513 ar5416_eep_start_loc = 256; 210 if (ath9k_regd_is_public_safety_sku(ah) &&
514 } 211 IS_CHAN_IN_PUBLIC_SAFETY_BAND(freq)) {
515 if (AR_SREV_9100(ah)) 212 return ((freq * 10) +
516 ar5416_eep_start_loc = 256; 213 (((freq % 5) == 2) ? 5 : 0) - 49400) / 5;
517 214 } else if ((flags & CHANNEL_A) && (freq <= 5000)) {
518 eep_data = (u16 *) eep; 215 return (freq - 4000) / 5;
519 for (addr = 0; 216 } else {
520 addr < sizeof(struct ar5416_eeprom) / sizeof(u16); 217 return (freq - 5000) / 5;
521 addr++) {
522 if (!ath9k_hw_nvram_read(ah, addr + ar5416_eep_start_loc,
523 eep_data)) {
524 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
525 "%s: Unable to read eeprom region \n",
526 __func__);
527 return false;
528 } 218 }
529 eep_data++; 219 } else {
220 if (freq == 2484)
221 return 14;
222 if (freq < 2484)
223 return (freq - 2407) / 5;
224 if (freq < 5000) {
225 if (ath9k_regd_is_public_safety_sku(ah)
226 && IS_CHAN_IN_PUBLIC_SAFETY_BAND(freq)) {
227 return ((freq * 10) +
228 (((freq % 5) ==
229 2) ? 5 : 0) - 49400) / 5;
230 } else if (freq > 4900) {
231 return (freq - 4000) / 5;
232 } else {
233 return 15 + ((freq - 2512) / 20);
234 }
235 }
236 return (freq - 5000) / 5;
530 } 237 }
531 return true;
532} 238}
533 239
534/* XXX: Clean me up, make me more legible */ 240void ath9k_hw_get_channel_centers(struct ath_hal *ah,
535static bool 241 struct ath9k_channel *chan,
536ath9k_hw_eeprom_set_board_values(struct ath_hal *ah, 242 struct chan_centers *centers)
537 struct ath9k_channel *chan)
538{ 243{
539 struct modal_eep_header *pModal; 244 int8_t extoff;
540 int i, regChainOffset;
541 struct ath_hal_5416 *ahp = AH5416(ah); 245 struct ath_hal_5416 *ahp = AH5416(ah);
542 struct ar5416_eeprom *eep = &ahp->ah_eeprom;
543 u8 txRxAttenLocal;
544 u16 ant_config;
545 246
546 pModal = &(eep->modalHeader[IS_CHAN_2GHZ(chan)]); 247 if (!IS_CHAN_HT40(chan)) {
248 centers->ctl_center = centers->ext_center =
249 centers->synth_center = chan->channel;
250 return;
251 }
547 252
548 txRxAttenLocal = IS_CHAN_2GHZ(chan) ? 23 : 44; 253 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
254 (chan->chanmode == CHANNEL_G_HT40PLUS)) {
255 centers->synth_center =
256 chan->channel + HT40_CHANNEL_CENTER_SHIFT;
257 extoff = 1;
258 } else {
259 centers->synth_center =
260 chan->channel - HT40_CHANNEL_CENTER_SHIFT;
261 extoff = -1;
262 }
549 263
550 ath9k_hw_get_eeprom_antenna_cfg(ahp, chan, 1, &ant_config); 264 centers->ctl_center =
551 REG_WRITE(ah, AR_PHY_SWITCH_COM, ant_config); 265 centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
266 centers->ext_center =
267 centers->synth_center + (extoff *
268 ((ahp->ah_extprotspacing == ATH9K_HT_EXTPROTSPACING_20) ?
269 HT40_CHANNEL_CENTER_SHIFT : 15));
552 270
553 for (i = 0; i < AR5416_MAX_CHAINS; i++) { 271}
554 if (AR_SREV_9280(ah)) {
555 if (i >= 2)
556 break;
557 }
558 272
559 if (AR_SREV_5416_V20_OR_LATER(ah) && 273/******************/
560 (ahp->ah_rxchainmask == 5 || ahp->ah_txchainmask == 5) 274/* Chip Revisions */
561 && (i != 0)) 275/******************/
562 regChainOffset = (i == 1) ? 0x2000 : 0x1000;
563 else
564 regChainOffset = i * 0x1000;
565
566 REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
567 pModal->antCtrlChain[i]);
568
569 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset,
570 (REG_READ(ah,
571 AR_PHY_TIMING_CTRL4(0) +
572 regChainOffset) &
573 ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF |
574 AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) |
575 SM(pModal->iqCalICh[i],
576 AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) |
577 SM(pModal->iqCalQCh[i],
578 AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF));
579
580 if ((i == 0) || AR_SREV_5416_V20_OR_LATER(ah)) {
581 if ((eep->baseEepHeader.version &
582 AR5416_EEP_VER_MINOR_MASK) >=
583 AR5416_EEP_MINOR_VER_3) {
584 txRxAttenLocal = pModal->txRxAttenCh[i];
585 if (AR_SREV_9280_10_OR_LATER(ah)) {
586 REG_RMW_FIELD(ah,
587 AR_PHY_GAIN_2GHZ +
588 regChainOffset,
589 AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN,
590 pModal->
591 bswMargin[i]);
592 REG_RMW_FIELD(ah,
593 AR_PHY_GAIN_2GHZ +
594 regChainOffset,
595 AR_PHY_GAIN_2GHZ_XATTEN1_DB,
596 pModal->
597 bswAtten[i]);
598 REG_RMW_FIELD(ah,
599 AR_PHY_GAIN_2GHZ +
600 regChainOffset,
601 AR_PHY_GAIN_2GHZ_XATTEN2_MARGIN,
602 pModal->
603 xatten2Margin[i]);
604 REG_RMW_FIELD(ah,
605 AR_PHY_GAIN_2GHZ +
606 regChainOffset,
607 AR_PHY_GAIN_2GHZ_XATTEN2_DB,
608 pModal->
609 xatten2Db[i]);
610 } else {
611 REG_WRITE(ah,
612 AR_PHY_GAIN_2GHZ +
613 regChainOffset,
614 (REG_READ(ah,
615 AR_PHY_GAIN_2GHZ +
616 regChainOffset) &
617 ~AR_PHY_GAIN_2GHZ_BSW_MARGIN)
618 | SM(pModal->
619 bswMargin[i],
620 AR_PHY_GAIN_2GHZ_BSW_MARGIN));
621 REG_WRITE(ah,
622 AR_PHY_GAIN_2GHZ +
623 regChainOffset,
624 (REG_READ(ah,
625 AR_PHY_GAIN_2GHZ +
626 regChainOffset) &
627 ~AR_PHY_GAIN_2GHZ_BSW_ATTEN)
628 | SM(pModal->bswAtten[i],
629 AR_PHY_GAIN_2GHZ_BSW_ATTEN));
630 }
631 }
632 if (AR_SREV_9280_10_OR_LATER(ah)) {
633 REG_RMW_FIELD(ah,
634 AR_PHY_RXGAIN +
635 regChainOffset,
636 AR9280_PHY_RXGAIN_TXRX_ATTEN,
637 txRxAttenLocal);
638 REG_RMW_FIELD(ah,
639 AR_PHY_RXGAIN +
640 regChainOffset,
641 AR9280_PHY_RXGAIN_TXRX_MARGIN,
642 pModal->rxTxMarginCh[i]);
643 } else {
644 REG_WRITE(ah,
645 AR_PHY_RXGAIN + regChainOffset,
646 (REG_READ(ah,
647 AR_PHY_RXGAIN +
648 regChainOffset) &
649 ~AR_PHY_RXGAIN_TXRX_ATTEN) |
650 SM(txRxAttenLocal,
651 AR_PHY_RXGAIN_TXRX_ATTEN));
652 REG_WRITE(ah,
653 AR_PHY_GAIN_2GHZ +
654 regChainOffset,
655 (REG_READ(ah,
656 AR_PHY_GAIN_2GHZ +
657 regChainOffset) &
658 ~AR_PHY_GAIN_2GHZ_RXTX_MARGIN) |
659 SM(pModal->rxTxMarginCh[i],
660 AR_PHY_GAIN_2GHZ_RXTX_MARGIN));
661 }
662 }
663 }
664 276
665 if (AR_SREV_9280_10_OR_LATER(ah)) { 277static void ath9k_hw_read_revisions(struct ath_hal *ah)
666 if (IS_CHAN_2GHZ(chan)) { 278{
667 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH0, 279 u32 val;
668 AR_AN_RF2G1_CH0_OB,
669 AR_AN_RF2G1_CH0_OB_S,
670 pModal->ob);
671 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH0,
672 AR_AN_RF2G1_CH0_DB,
673 AR_AN_RF2G1_CH0_DB_S,
674 pModal->db);
675 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH1,
676 AR_AN_RF2G1_CH1_OB,
677 AR_AN_RF2G1_CH1_OB_S,
678 pModal->ob_ch1);
679 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH1,
680 AR_AN_RF2G1_CH1_DB,
681 AR_AN_RF2G1_CH1_DB_S,
682 pModal->db_ch1);
683 } else {
684 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH0,
685 AR_AN_RF5G1_CH0_OB5,
686 AR_AN_RF5G1_CH0_OB5_S,
687 pModal->ob);
688 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH0,
689 AR_AN_RF5G1_CH0_DB5,
690 AR_AN_RF5G1_CH0_DB5_S,
691 pModal->db);
692 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH1,
693 AR_AN_RF5G1_CH1_OB5,
694 AR_AN_RF5G1_CH1_OB5_S,
695 pModal->ob_ch1);
696 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH1,
697 AR_AN_RF5G1_CH1_DB5,
698 AR_AN_RF5G1_CH1_DB5_S,
699 pModal->db_ch1);
700 }
701 ath9k_hw_analog_shift_rmw(ah, AR_AN_TOP2,
702 AR_AN_TOP2_XPABIAS_LVL,
703 AR_AN_TOP2_XPABIAS_LVL_S,
704 pModal->xpaBiasLvl);
705 ath9k_hw_analog_shift_rmw(ah, AR_AN_TOP2,
706 AR_AN_TOP2_LOCALBIAS,
707 AR_AN_TOP2_LOCALBIAS_S,
708 pModal->local_bias);
709 DPRINTF(ah->ah_sc, ATH_DBG_ANY, "ForceXPAon: %d\n",
710 pModal->force_xpaon);
711 REG_RMW_FIELD(ah, AR_PHY_XPA_CFG, AR_PHY_FORCE_XPA_CFG,
712 pModal->force_xpaon);
713 }
714 280
715 REG_RMW_FIELD(ah, AR_PHY_SETTLING, AR_PHY_SETTLING_SWITCH, 281 val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
716 pModal->switchSettling);
717 REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ, AR_PHY_DESIRED_SZ_ADC,
718 pModal->adcDesiredSize);
719 282
720 if (!AR_SREV_9280_10_OR_LATER(ah)) 283 if (val == 0xFF) {
721 REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ, 284 val = REG_READ(ah, AR_SREV);
722 AR_PHY_DESIRED_SZ_PGA, 285 ah->ah_macVersion = (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
723 pModal->pgaDesiredSize); 286 ah->ah_macRev = MS(val, AR_SREV_REVISION2);
724 287 ah->ah_isPciExpress = (val & AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
725 REG_WRITE(ah, AR_PHY_RF_CTL4,
726 SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF)
727 | SM(pModal->txEndToXpaOff,
728 AR_PHY_RF_CTL4_TX_END_XPAB_OFF)
729 | SM(pModal->txFrameToXpaOn,
730 AR_PHY_RF_CTL4_FRAME_XPAA_ON)
731 | SM(pModal->txFrameToXpaOn,
732 AR_PHY_RF_CTL4_FRAME_XPAB_ON));
733
734 REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_A2_RX_ON,
735 pModal->txEndToRxOn);
736 if (AR_SREV_9280_10_OR_LATER(ah)) {
737 REG_RMW_FIELD(ah, AR_PHY_CCA, AR9280_PHY_CCA_THRESH62,
738 pModal->thresh62);
739 REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0,
740 AR_PHY_EXT_CCA0_THRESH62,
741 pModal->thresh62);
742 } else { 288 } else {
743 REG_RMW_FIELD(ah, AR_PHY_CCA, AR_PHY_CCA_THRESH62, 289 if (!AR_SREV_9100(ah))
744 pModal->thresh62); 290 ah->ah_macVersion = MS(val, AR_SREV_VERSION);
745 REG_RMW_FIELD(ah, AR_PHY_EXT_CCA,
746 AR_PHY_EXT_CCA_THRESH62,
747 pModal->thresh62);
748 }
749 291
750 if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >= 292 ah->ah_macRev = val & AR_SREV_REVISION;
751 AR5416_EEP_MINOR_VER_2) {
752 REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
753 AR_PHY_TX_END_DATA_START,
754 pModal->txFrameToDataStart);
755 REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_PA_ON,
756 pModal->txFrameToPaOn);
757 }
758 293
759 if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >= 294 if (ah->ah_macVersion == AR_SREV_VERSION_5416_PCIE)
760 AR5416_EEP_MINOR_VER_3) { 295 ah->ah_isPciExpress = true;
761 if (IS_CHAN_HT40(chan))
762 REG_RMW_FIELD(ah, AR_PHY_SETTLING,
763 AR_PHY_SETTLING_SWITCH,
764 pModal->swSettleHt40);
765 } 296 }
766
767 return true;
768} 297}
769 298
770static int ath9k_hw_check_eeprom(struct ath_hal *ah) 299static int ath9k_hw_get_radiorev(struct ath_hal *ah)
771{ 300{
772 u32 sum = 0, el; 301 u32 val;
773 u16 *eepdata;
774 int i; 302 int i;
775 struct ath_hal_5416 *ahp = AH5416(ah);
776 bool need_swap = false;
777 struct ar5416_eeprom *eep =
778 (struct ar5416_eeprom *) &ahp->ah_eeprom;
779
780 if (!ath9k_hw_use_flash(ah)) {
781 u16 magic, magic2;
782 int addr;
783
784 if (!ath9k_hw_nvram_read(ah, AR5416_EEPROM_MAGIC_OFFSET,
785 &magic)) {
786 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
787 "%s: Reading Magic # failed\n", __func__);
788 return false;
789 }
790 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, "%s: Read Magic = 0x%04X\n",
791 __func__, magic);
792
793 if (magic != AR5416_EEPROM_MAGIC) {
794 magic2 = swab16(magic);
795
796 if (magic2 == AR5416_EEPROM_MAGIC) {
797 need_swap = true;
798 eepdata = (u16 *) (&ahp->ah_eeprom);
799
800 for (addr = 0;
801 addr <
802 sizeof(struct ar5416_eeprom) /
803 sizeof(u16); addr++) {
804 u16 temp;
805
806 temp = swab16(*eepdata);
807 *eepdata = temp;
808 eepdata++;
809
810 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
811 "0x%04X ", *eepdata);
812 if (((addr + 1) % 6) == 0)
813 DPRINTF(ah->ah_sc,
814 ATH_DBG_EEPROM,
815 "\n");
816 }
817 } else {
818 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
819 "Invalid EEPROM Magic. "
820 "endianness missmatch.\n");
821 return -EINVAL;
822 }
823 }
824 }
825 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, "need_swap = %s.\n",
826 need_swap ? "True" : "False");
827
828 if (need_swap)
829 el = swab16(ahp->ah_eeprom.baseEepHeader.length);
830 else
831 el = ahp->ah_eeprom.baseEepHeader.length;
832
833 if (el > sizeof(struct ar5416_eeprom))
834 el = sizeof(struct ar5416_eeprom) / sizeof(u16);
835 else
836 el = el / sizeof(u16);
837
838 eepdata = (u16 *) (&ahp->ah_eeprom);
839
840 for (i = 0; i < el; i++)
841 sum ^= *eepdata++;
842
843 if (need_swap) {
844 u32 integer, j;
845 u16 word;
846 303
847 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, 304 REG_WRITE(ah, AR_PHY(0x36), 0x00007058);
848 "EEPROM Endianness is not native.. Changing \n");
849
850 word = swab16(eep->baseEepHeader.length);
851 eep->baseEepHeader.length = word;
852
853 word = swab16(eep->baseEepHeader.checksum);
854 eep->baseEepHeader.checksum = word;
855
856 word = swab16(eep->baseEepHeader.version);
857 eep->baseEepHeader.version = word;
858
859 word = swab16(eep->baseEepHeader.regDmn[0]);
860 eep->baseEepHeader.regDmn[0] = word;
861
862 word = swab16(eep->baseEepHeader.regDmn[1]);
863 eep->baseEepHeader.regDmn[1] = word;
864
865 word = swab16(eep->baseEepHeader.rfSilent);
866 eep->baseEepHeader.rfSilent = word;
867
868 word = swab16(eep->baseEepHeader.blueToothOptions);
869 eep->baseEepHeader.blueToothOptions = word;
870 305
871 word = swab16(eep->baseEepHeader.deviceCap); 306 for (i = 0; i < 8; i++)
872 eep->baseEepHeader.deviceCap = word; 307 REG_WRITE(ah, AR_PHY(0x20), 0x00010000);
308 val = (REG_READ(ah, AR_PHY(256)) >> 24) & 0xff;
309 val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4);
873 310
874 for (j = 0; j < ARRAY_SIZE(eep->modalHeader); j++) { 311 return ath9k_hw_reverse_bits(val, 8);
875 struct modal_eep_header *pModal = 312}
876 &eep->modalHeader[j];
877 integer = swab32(pModal->antCtrlCommon);
878 pModal->antCtrlCommon = integer;
879 313
880 for (i = 0; i < AR5416_MAX_CHAINS; i++) { 314/************************************/
881 integer = swab32(pModal->antCtrlChain[i]); 315/* HW Attach, Detach, Init Routines */
882 pModal->antCtrlChain[i] = integer; 316/************************************/
883 }
884 317
885 for (i = 0; i < AR5416_EEPROM_MODAL_SPURS; i++) { 318static void ath9k_hw_disablepcie(struct ath_hal *ah)
886 word = swab16(pModal->spurChans[i].spurChan); 319{
887 pModal->spurChans[i].spurChan = word; 320 if (!AR_SREV_9100(ah))
888 } 321 return;
889 }
890 }
891 322
892 if (sum != 0xffff || ar5416_get_eep_ver(ahp) != AR5416_EEP_VER || 323 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
893 ar5416_get_eep_rev(ahp) < AR5416_EEP_NO_BACK_VER) { 324 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
894 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, 325 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
895 "Bad EEPROM checksum 0x%x or revision 0x%04x\n", 326 REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
896 sum, ar5416_get_eep_ver(ahp)); 327 REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
897 return -EINVAL; 328 REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
898 } 329 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
330 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
331 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
899 332
900 return 0; 333 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
901} 334}
902 335
903static bool ath9k_hw_chip_test(struct ath_hal *ah) 336static bool ath9k_hw_chip_test(struct ath_hal *ah)
@@ -905,9 +338,9 @@ static bool ath9k_hw_chip_test(struct ath_hal *ah)
905 u32 regAddr[2] = { AR_STA_ID0, AR_PHY_BASE + (8 << 2) }; 338 u32 regAddr[2] = { AR_STA_ID0, AR_PHY_BASE + (8 << 2) };
906 u32 regHold[2]; 339 u32 regHold[2];
907 u32 patternData[4] = { 0x55555555, 340 u32 patternData[4] = { 0x55555555,
908 0xaaaaaaaa, 341 0xaaaaaaaa,
909 0x66666666, 342 0x66666666,
910 0x99999999 }; 343 0x99999999 };
911 int i, j; 344 int i, j;
912 345
913 for (i = 0; i < 2; i++) { 346 for (i = 0; i < 2; i++) {
@@ -921,9 +354,9 @@ static bool ath9k_hw_chip_test(struct ath_hal *ah)
921 rdData = REG_READ(ah, addr); 354 rdData = REG_READ(ah, addr);
922 if (rdData != wrData) { 355 if (rdData != wrData) {
923 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO, 356 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
924 "%s: address test failed " 357 "%s: address test failed "
925 "addr: 0x%08x - wr:0x%08x != rd:0x%08x\n", 358 "addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
926 __func__, addr, wrData, rdData); 359 __func__, addr, wrData, rdData);
927 return false; 360 return false;
928 } 361 }
929 } 362 }
@@ -933,9 +366,9 @@ static bool ath9k_hw_chip_test(struct ath_hal *ah)
933 rdData = REG_READ(ah, addr); 366 rdData = REG_READ(ah, addr);
934 if (wrData != rdData) { 367 if (wrData != rdData) {
935 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO, 368 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
936 "%s: address test failed " 369 "%s: address test failed "
937 "addr: 0x%08x - wr:0x%08x != rd:0x%08x\n", 370 "addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
938 __func__, addr, wrData, rdData); 371 __func__, addr, wrData, rdData);
939 return false; 372 return false;
940 } 373 }
941 } 374 }
@@ -945,213 +378,62 @@ static bool ath9k_hw_chip_test(struct ath_hal *ah)
945 return true; 378 return true;
946} 379}
947 380
948u32 ath9k_hw_getrxfilter(struct ath_hal *ah) 381static const char *ath9k_hw_devname(u16 devid)
949{
950 u32 bits = REG_READ(ah, AR_RX_FILTER);
951 u32 phybits = REG_READ(ah, AR_PHY_ERR);
952
953 if (phybits & AR_PHY_ERR_RADAR)
954 bits |= ATH9K_RX_FILTER_PHYRADAR;
955 if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
956 bits |= ATH9K_RX_FILTER_PHYERR;
957 return bits;
958}
959
960void ath9k_hw_setrxfilter(struct ath_hal *ah, u32 bits)
961{
962 u32 phybits;
963
964 REG_WRITE(ah, AR_RX_FILTER, (bits & 0xffff) | AR_RX_COMPR_BAR);
965 phybits = 0;
966 if (bits & ATH9K_RX_FILTER_PHYRADAR)
967 phybits |= AR_PHY_ERR_RADAR;
968 if (bits & ATH9K_RX_FILTER_PHYERR)
969 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
970 REG_WRITE(ah, AR_PHY_ERR, phybits);
971
972 if (phybits)
973 REG_WRITE(ah, AR_RXCFG,
974 REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
975 else
976 REG_WRITE(ah, AR_RXCFG,
977 REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA);
978}
979
980bool ath9k_hw_setcapability(struct ath_hal *ah,
981 enum ath9k_capability_type type,
982 u32 capability,
983 u32 setting,
984 int *status)
985{
986 struct ath_hal_5416 *ahp = AH5416(ah);
987 u32 v;
988
989 switch (type) {
990 case ATH9K_CAP_TKIP_MIC:
991 if (setting)
992 ahp->ah_staId1Defaults |=
993 AR_STA_ID1_CRPT_MIC_ENABLE;
994 else
995 ahp->ah_staId1Defaults &=
996 ~AR_STA_ID1_CRPT_MIC_ENABLE;
997 return true;
998 case ATH9K_CAP_DIVERSITY:
999 v = REG_READ(ah, AR_PHY_CCK_DETECT);
1000 if (setting)
1001 v |= AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
1002 else
1003 v &= ~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
1004 REG_WRITE(ah, AR_PHY_CCK_DETECT, v);
1005 return true;
1006 case ATH9K_CAP_MCAST_KEYSRCH:
1007 if (setting)
1008 ahp->ah_staId1Defaults |= AR_STA_ID1_MCAST_KSRCH;
1009 else
1010 ahp->ah_staId1Defaults &= ~AR_STA_ID1_MCAST_KSRCH;
1011 return true;
1012 case ATH9K_CAP_TSF_ADJUST:
1013 if (setting)
1014 ahp->ah_miscMode |= AR_PCU_TX_ADD_TSF;
1015 else
1016 ahp->ah_miscMode &= ~AR_PCU_TX_ADD_TSF;
1017 return true;
1018 default:
1019 return false;
1020 }
1021}
1022
1023void ath9k_hw_dmaRegDump(struct ath_hal *ah)
1024{ 382{
1025 u32 val[ATH9K_NUM_DMA_DEBUG_REGS]; 383 switch (devid) {
1026 int qcuOffset = 0, dcuOffset = 0; 384 case AR5416_DEVID_PCI:
1027 u32 *qcuBase = &val[0], *dcuBase = &val[4]; 385 case AR5416_DEVID_PCIE:
1028 int i; 386 return "Atheros 5416";
1029 387 case AR9160_DEVID_PCI:
1030 REG_WRITE(ah, AR_MACMISC, 388 return "Atheros 9160";
1031 ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) | 389 case AR9280_DEVID_PCI:
1032 (AR_MACMISC_MISC_OBS_BUS_1 << 390 case AR9280_DEVID_PCIE:
1033 AR_MACMISC_MISC_OBS_BUS_MSB_S))); 391 return "Atheros 9280";
1034
1035 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO, "Raw DMA Debug values:\n");
1036 for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
1037 if (i % 4 == 0)
1038 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO, "\n");
1039
1040 val[i] = REG_READ(ah, AR_DMADBG_0 + (i * sizeof(u32)));
1041 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO, "%d: %08x ", i, val[i]);
1042 }
1043
1044 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO, "\n\n");
1045 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
1046 "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
1047
1048 for (i = 0; i < ATH9K_NUM_QUEUES;
1049 i++, qcuOffset += 4, dcuOffset += 5) {
1050 if (i == 8) {
1051 qcuOffset = 0;
1052 qcuBase++;
1053 }
1054
1055 if (i == 6) {
1056 dcuOffset = 0;
1057 dcuBase++;
1058 }
1059
1060 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
1061 "%2d %2x %1x %2x %2x\n",
1062 i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
1063 (*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset +
1064 3),
1065 val[2] & (0x7 << (i * 3)) >> (i * 3),
1066 (*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
1067 } 392 }
1068 393
1069 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO, "\n"); 394 return NULL;
1070 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
1071 "qcu_stitch state: %2x qcu_fetch state: %2x\n",
1072 (val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);
1073 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
1074 "qcu_complete state: %2x dcu_complete state: %2x\n",
1075 (val[3] & 0x1c000000) >> 26, (val[6] & 0x3));
1076 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
1077 "dcu_arb state: %2x dcu_fp state: %2x\n",
1078 (val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);
1079 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
1080 "chan_idle_dur: %3d chan_idle_dur_valid: %1d\n",
1081 (val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);
1082 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
1083 "txfifo_valid_0: %1d txfifo_valid_1: %1d\n",
1084 (val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);
1085 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
1086 "txfifo_dcu_num_0: %2d txfifo_dcu_num_1: %2d\n",
1087 (val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);
1088
1089 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO, "pcu observe 0x%x \n",
1090 REG_READ(ah, AR_OBS_BUS_1));
1091 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
1092 "AR_CR 0x%x \n", REG_READ(ah, AR_CR));
1093} 395}
1094 396
1095u32 ath9k_hw_GetMibCycleCountsPct(struct ath_hal *ah, 397static void ath9k_hw_set_defaults(struct ath_hal *ah)
1096 u32 *rxc_pcnt,
1097 u32 *rxf_pcnt,
1098 u32 *txf_pcnt)
1099{ 398{
1100 static u32 cycles, rx_clear, rx_frame, tx_frame; 399 int i;
1101 u32 good = 1;
1102 400
1103 u32 rc = REG_READ(ah, AR_RCCNT); 401 ah->ah_config.dma_beacon_response_time = 2;
1104 u32 rf = REG_READ(ah, AR_RFCNT); 402 ah->ah_config.sw_beacon_response_time = 10;
1105 u32 tf = REG_READ(ah, AR_TFCNT); 403 ah->ah_config.additional_swba_backoff = 0;
1106 u32 cc = REG_READ(ah, AR_CCCNT); 404 ah->ah_config.ack_6mb = 0x0;
405 ah->ah_config.cwm_ignore_extcca = 0;
406 ah->ah_config.pcie_powersave_enable = 0;
407 ah->ah_config.pcie_l1skp_enable = 0;
408 ah->ah_config.pcie_clock_req = 0;
409 ah->ah_config.pcie_power_reset = 0x100;
410 ah->ah_config.pcie_restore = 0;
411 ah->ah_config.pcie_waen = 0;
412 ah->ah_config.analog_shiftreg = 1;
413 ah->ah_config.ht_enable = 1;
414 ah->ah_config.ofdm_trig_low = 200;
415 ah->ah_config.ofdm_trig_high = 500;
416 ah->ah_config.cck_trig_high = 200;
417 ah->ah_config.cck_trig_low = 100;
418 ah->ah_config.enable_ani = 1;
419 ah->ah_config.noise_immunity_level = 4;
420 ah->ah_config.ofdm_weaksignal_det = 1;
421 ah->ah_config.cck_weaksignal_thr = 0;
422 ah->ah_config.spur_immunity_level = 2;
423 ah->ah_config.firstep_level = 0;
424 ah->ah_config.rssi_thr_high = 40;
425 ah->ah_config.rssi_thr_low = 7;
426 ah->ah_config.diversity_control = 0;
427 ah->ah_config.antenna_switch_swap = 0;
1107 428
1108 if (cycles == 0 || cycles > cc) { 429 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
1109 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL, 430 ah->ah_config.spurchans[i][0] = AR_NO_SPUR;
1110 "%s: cycle counter wrap. ExtBusy = 0\n", 431 ah->ah_config.spurchans[i][1] = AR_NO_SPUR;
1111 __func__);
1112 good = 0;
1113 } else {
1114 u32 cc_d = cc - cycles;
1115 u32 rc_d = rc - rx_clear;
1116 u32 rf_d = rf - rx_frame;
1117 u32 tf_d = tf - tx_frame;
1118
1119 if (cc_d != 0) {
1120 *rxc_pcnt = rc_d * 100 / cc_d;
1121 *rxf_pcnt = rf_d * 100 / cc_d;
1122 *txf_pcnt = tf_d * 100 / cc_d;
1123 } else {
1124 good = 0;
1125 }
1126 } 432 }
1127 433
1128 cycles = cc; 434 ah->ah_config.intr_mitigation = 1;
1129 rx_frame = rf;
1130 rx_clear = rc;
1131 tx_frame = tf;
1132
1133 return good;
1134}
1135
1136void ath9k_hw_set11nmac2040(struct ath_hal *ah, enum ath9k_ht_macmode mode)
1137{
1138 u32 macmode;
1139
1140 if (mode == ATH9K_HT_MACMODE_2040 &&
1141 !ah->ah_config.cwm_ignore_extcca)
1142 macmode = AR_2040_JOINED_RX_CLEAR;
1143 else
1144 macmode = 0;
1145
1146 REG_WRITE(ah, AR_2040_MODE, macmode);
1147}
1148
1149static void ath9k_hw_mark_phy_inactive(struct ath_hal *ah)
1150{
1151 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
1152} 435}
1153 436
1154
1155static struct ath_hal_5416 *ath9k_hw_newstate(u16 devid, 437static struct ath_hal_5416 *ath9k_hw_newstate(u16 devid,
1156 struct ath_softc *sc, 438 struct ath_softc *sc,
1157 void __iomem *mem, 439 void __iomem *mem,
@@ -1165,20 +447,17 @@ static struct ath_hal_5416 *ath9k_hw_newstate(u16 devid,
1165 ahp = kzalloc(sizeof(struct ath_hal_5416), GFP_KERNEL); 447 ahp = kzalloc(sizeof(struct ath_hal_5416), GFP_KERNEL);
1166 if (ahp == NULL) { 448 if (ahp == NULL) {
1167 DPRINTF(sc, ATH_DBG_FATAL, 449 DPRINTF(sc, ATH_DBG_FATAL,
1168 "%s: cannot allocate memory for state block\n", 450 "%s: cannot allocate memory for state block\n",
1169 __func__); 451 __func__);
1170 *status = -ENOMEM; 452 *status = -ENOMEM;
1171 return NULL; 453 return NULL;
1172 } 454 }
1173 455
1174 ah = &ahp->ah; 456 ah = &ahp->ah;
1175
1176 ah->ah_sc = sc; 457 ah->ah_sc = sc;
1177 ah->ah_sh = mem; 458 ah->ah_sh = mem;
1178
1179 ah->ah_magic = AR5416_MAGIC; 459 ah->ah_magic = AR5416_MAGIC;
1180 ah->ah_countryCode = CTRY_DEFAULT; 460 ah->ah_countryCode = CTRY_DEFAULT;
1181
1182 ah->ah_devid = devid; 461 ah->ah_devid = devid;
1183 ah->ah_subvendorid = 0; 462 ah->ah_subvendorid = 0;
1184 463
@@ -1190,12 +469,10 @@ static struct ath_hal_5416 *ath9k_hw_newstate(u16 devid,
1190 469
1191 ah->ah_powerLimit = MAX_RATE_POWER; 470 ah->ah_powerLimit = MAX_RATE_POWER;
1192 ah->ah_tpScale = ATH9K_TP_SCALE_MAX; 471 ah->ah_tpScale = ATH9K_TP_SCALE_MAX;
1193
1194 ahp->ah_atimWindow = 0; 472 ahp->ah_atimWindow = 0;
1195 ahp->ah_diversityControl = ah->ah_config.diversity_control; 473 ahp->ah_diversityControl = ah->ah_config.diversity_control;
1196 ahp->ah_antennaSwitchSwap = 474 ahp->ah_antennaSwitchSwap =
1197 ah->ah_config.antenna_switch_swap; 475 ah->ah_config.antenna_switch_swap;
1198
1199 ahp->ah_staId1Defaults = AR_STA_ID1_CRPT_MIC_ENABLE; 476 ahp->ah_staId1Defaults = AR_STA_ID1_CRPT_MIC_ENABLE;
1200 ahp->ah_beaconInterval = 100; 477 ahp->ah_beaconInterval = 100;
1201 ahp->ah_enable32kHzClock = DONT_USE_32KHZ; 478 ahp->ah_enable32kHzClock = DONT_USE_32KHZ;
@@ -1210,162 +487,6 @@ static struct ath_hal_5416 *ath9k_hw_newstate(u16 devid,
1210 return ahp; 487 return ahp;
1211} 488}
1212 489
1213static int ath9k_hw_eeprom_attach(struct ath_hal *ah)
1214{
1215 int status;
1216
1217 if (ath9k_hw_use_flash(ah))
1218 ath9k_hw_flash_map(ah);
1219
1220 if (!ath9k_hw_fill_eeprom(ah))
1221 return -EIO;
1222
1223 status = ath9k_hw_check_eeprom(ah);
1224
1225 return status;
1226}
1227
1228u32 ath9k_hw_get_eeprom(struct ath_hal_5416 *ahp,
1229 enum eeprom_param param)
1230{
1231 struct ar5416_eeprom *eep = &ahp->ah_eeprom;
1232 struct modal_eep_header *pModal = eep->modalHeader;
1233 struct base_eep_header *pBase = &eep->baseEepHeader;
1234
1235 switch (param) {
1236 case EEP_NFTHRESH_5:
1237 return -pModal[0].noiseFloorThreshCh[0];
1238 case EEP_NFTHRESH_2:
1239 return -pModal[1].noiseFloorThreshCh[0];
1240 case AR_EEPROM_MAC(0):
1241 return pBase->macAddr[0] << 8 | pBase->macAddr[1];
1242 case AR_EEPROM_MAC(1):
1243 return pBase->macAddr[2] << 8 | pBase->macAddr[3];
1244 case AR_EEPROM_MAC(2):
1245 return pBase->macAddr[4] << 8 | pBase->macAddr[5];
1246 case EEP_REG_0:
1247 return pBase->regDmn[0];
1248 case EEP_REG_1:
1249 return pBase->regDmn[1];
1250 case EEP_OP_CAP:
1251 return pBase->deviceCap;
1252 case EEP_OP_MODE:
1253 return pBase->opCapFlags;
1254 case EEP_RF_SILENT:
1255 return pBase->rfSilent;
1256 case EEP_OB_5:
1257 return pModal[0].ob;
1258 case EEP_DB_5:
1259 return pModal[0].db;
1260 case EEP_OB_2:
1261 return pModal[1].ob;
1262 case EEP_DB_2:
1263 return pModal[1].db;
1264 case EEP_MINOR_REV:
1265 return pBase->version & AR5416_EEP_VER_MINOR_MASK;
1266 case EEP_TX_MASK:
1267 return pBase->txMask;
1268 case EEP_RX_MASK:
1269 return pBase->rxMask;
1270 default:
1271 return 0;
1272 }
1273}
1274
1275static int ath9k_hw_get_radiorev(struct ath_hal *ah)
1276{
1277 u32 val;
1278 int i;
1279
1280 REG_WRITE(ah, AR_PHY(0x36), 0x00007058);
1281 for (i = 0; i < 8; i++)
1282 REG_WRITE(ah, AR_PHY(0x20), 0x00010000);
1283 val = (REG_READ(ah, AR_PHY(256)) >> 24) & 0xff;
1284 val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4);
1285 return ath9k_hw_reverse_bits(val, 8);
1286}
1287
1288static int ath9k_hw_init_macaddr(struct ath_hal *ah)
1289{
1290 u32 sum;
1291 int i;
1292 u16 eeval;
1293 struct ath_hal_5416 *ahp = AH5416(ah);
1294
1295 sum = 0;
1296 for (i = 0; i < 3; i++) {
1297 eeval = ath9k_hw_get_eeprom(ahp, AR_EEPROM_MAC(i));
1298 sum += eeval;
1299 ahp->ah_macaddr[2 * i] = eeval >> 8;
1300 ahp->ah_macaddr[2 * i + 1] = eeval & 0xff;
1301 }
1302 if (sum == 0 || sum == 0xffff * 3) {
1303 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
1304 "%s: mac address read failed: %pM\n", __func__,
1305 ahp->ah_macaddr);
1306 return -EADDRNOTAVAIL;
1307 }
1308
1309 return 0;
1310}
1311
1312static inline int16_t ath9k_hw_interpolate(u16 target,
1313 u16 srcLeft,
1314 u16 srcRight,
1315 int16_t targetLeft,
1316 int16_t targetRight)
1317{
1318 int16_t rv;
1319
1320 if (srcRight == srcLeft) {
1321 rv = targetLeft;
1322 } else {
1323 rv = (int16_t) (((target - srcLeft) * targetRight +
1324 (srcRight - target) * targetLeft) /
1325 (srcRight - srcLeft));
1326 }
1327 return rv;
1328}
1329
1330static inline u16 ath9k_hw_fbin2freq(u8 fbin,
1331 bool is2GHz)
1332{
1333
1334 if (fbin == AR5416_BCHAN_UNUSED)
1335 return fbin;
1336
1337 return (u16) ((is2GHz) ? (2300 + fbin) : (4800 + 5 * fbin));
1338}
1339
1340static u16 ath9k_hw_eeprom_get_spur_chan(struct ath_hal *ah,
1341 u16 i,
1342 bool is2GHz)
1343{
1344 struct ath_hal_5416 *ahp = AH5416(ah);
1345 struct ar5416_eeprom *eep =
1346 (struct ar5416_eeprom *) &ahp->ah_eeprom;
1347 u16 spur_val = AR_NO_SPUR;
1348
1349 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
1350 "Getting spur idx %d is2Ghz. %d val %x\n",
1351 i, is2GHz, ah->ah_config.spurchans[i][is2GHz]);
1352
1353 switch (ah->ah_config.spurmode) {
1354 case SPUR_DISABLE:
1355 break;
1356 case SPUR_ENABLE_IOCTL:
1357 spur_val = ah->ah_config.spurchans[i][is2GHz];
1358 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
1359 "Getting spur val from new loc. %d\n", spur_val);
1360 break;
1361 case SPUR_ENABLE_EEPROM:
1362 spur_val = eep->modalHeader[is2GHz].spurChans[i].spurChan;
1363 break;
1364
1365 }
1366 return spur_val;
1367}
1368
1369static int ath9k_hw_rfattach(struct ath_hal *ah) 490static int ath9k_hw_rfattach(struct ath_hal *ah)
1370{ 491{
1371 bool rfStatus = false; 492 bool rfStatus = false;
@@ -1374,8 +495,8 @@ static int ath9k_hw_rfattach(struct ath_hal *ah)
1374 rfStatus = ath9k_hw_init_rf(ah, &ecode); 495 rfStatus = ath9k_hw_init_rf(ah, &ecode);
1375 if (!rfStatus) { 496 if (!rfStatus) {
1376 DPRINTF(ah->ah_sc, ATH_DBG_RESET, 497 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
1377 "%s: RF setup failed, status %u\n", __func__, 498 "%s: RF setup failed, status %u\n", __func__,
1378 ecode); 499 ecode);
1379 return ecode; 500 return ecode;
1380 } 501 }
1381 502
@@ -1400,9 +521,9 @@ static int ath9k_hw_rf_claim(struct ath_hal *ah)
1400 break; 521 break;
1401 default: 522 default:
1402 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL, 523 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
1403 "%s: 5G Radio Chip Rev 0x%02X is not " 524 "%s: 5G Radio Chip Rev 0x%02X is not "
1404 "supported by this driver\n", 525 "supported by this driver\n",
1405 __func__, ah->ah_analog5GhzRev); 526 __func__, ah->ah_analog5GhzRev);
1406 return -EOPNOTSUPP; 527 return -EOPNOTSUPP;
1407 } 528 }
1408 529
@@ -1411,1482 +532,37 @@ static int ath9k_hw_rf_claim(struct ath_hal *ah)
1411 return 0; 532 return 0;
1412} 533}
1413 534
1414static void ath9k_hw_init_pll(struct ath_hal *ah, 535static int ath9k_hw_init_macaddr(struct ath_hal *ah)
1415 struct ath9k_channel *chan)
1416{
1417 u32 pll;
1418
1419 if (AR_SREV_9100(ah)) {
1420 if (chan && IS_CHAN_5GHZ(chan))
1421 pll = 0x1450;
1422 else
1423 pll = 0x1458;
1424 } else {
1425 if (AR_SREV_9280_10_OR_LATER(ah)) {
1426 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
1427
1428 if (chan && IS_CHAN_HALF_RATE(chan))
1429 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
1430 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1431 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
1432
1433 if (chan && IS_CHAN_5GHZ(chan)) {
1434 pll |= SM(0x28, AR_RTC_9160_PLL_DIV);
1435
1436
1437 if (AR_SREV_9280_20(ah)) {
1438 if (((chan->channel % 20) == 0)
1439 || ((chan->channel % 10) == 0))
1440 pll = 0x2850;
1441 else
1442 pll = 0x142c;
1443 }
1444 } else {
1445 pll |= SM(0x2c, AR_RTC_9160_PLL_DIV);
1446 }
1447
1448 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
1449
1450 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
1451
1452 if (chan && IS_CHAN_HALF_RATE(chan))
1453 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
1454 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1455 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
1456
1457 if (chan && IS_CHAN_5GHZ(chan))
1458 pll |= SM(0x50, AR_RTC_9160_PLL_DIV);
1459 else
1460 pll |= SM(0x58, AR_RTC_9160_PLL_DIV);
1461 } else {
1462 pll = AR_RTC_PLL_REFDIV_5 | AR_RTC_PLL_DIV2;
1463
1464 if (chan && IS_CHAN_HALF_RATE(chan))
1465 pll |= SM(0x1, AR_RTC_PLL_CLKSEL);
1466 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1467 pll |= SM(0x2, AR_RTC_PLL_CLKSEL);
1468
1469 if (chan && IS_CHAN_5GHZ(chan))
1470 pll |= SM(0xa, AR_RTC_PLL_DIV);
1471 else
1472 pll |= SM(0xb, AR_RTC_PLL_DIV);
1473 }
1474 }
1475 REG_WRITE(ah, (u16) (AR_RTC_PLL_CONTROL), pll);
1476
1477 udelay(RTC_PLL_SETTLE_DELAY);
1478
1479 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
1480}
1481
1482static void ath9k_hw_set_regs(struct ath_hal *ah, struct ath9k_channel *chan,
1483 enum ath9k_ht_macmode macmode)
1484{
1485 u32 phymode;
1486 struct ath_hal_5416 *ahp = AH5416(ah);
1487
1488 phymode = AR_PHY_FC_HT_EN | AR_PHY_FC_SHORT_GI_40
1489 | AR_PHY_FC_SINGLE_HT_LTF1 | AR_PHY_FC_WALSH;
1490
1491 if (IS_CHAN_HT40(chan)) {
1492 phymode |= AR_PHY_FC_DYN2040_EN;
1493
1494 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
1495 (chan->chanmode == CHANNEL_G_HT40PLUS))
1496 phymode |= AR_PHY_FC_DYN2040_PRI_CH;
1497
1498 if (ahp->ah_extprotspacing == ATH9K_HT_EXTPROTSPACING_25)
1499 phymode |= AR_PHY_FC_DYN2040_EXT_CH;
1500 }
1501 REG_WRITE(ah, AR_PHY_TURBO, phymode);
1502
1503 ath9k_hw_set11nmac2040(ah, macmode);
1504
1505 REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
1506 REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
1507}
1508
1509static void ath9k_hw_set_operating_mode(struct ath_hal *ah, int opmode)
1510{
1511 u32 val;
1512
1513 val = REG_READ(ah, AR_STA_ID1);
1514 val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC);
1515 switch (opmode) {
1516 case ATH9K_M_HOSTAP:
1517 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP
1518 | AR_STA_ID1_KSRCH_MODE);
1519 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1520 break;
1521 case ATH9K_M_IBSS:
1522 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC
1523 | AR_STA_ID1_KSRCH_MODE);
1524 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1525 break;
1526 case ATH9K_M_STA:
1527 case ATH9K_M_MONITOR:
1528 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
1529 break;
1530 }
1531}
1532
1533static void
1534ath9k_hw_set_rfmode(struct ath_hal *ah, struct ath9k_channel *chan)
1535{
1536 u32 rfMode = 0;
1537
1538 if (chan == NULL)
1539 return;
1540
1541 rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
1542 ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
1543
1544 if (!AR_SREV_9280_10_OR_LATER(ah))
1545 rfMode |= (IS_CHAN_5GHZ(chan)) ? AR_PHY_MODE_RF5GHZ :
1546 AR_PHY_MODE_RF2GHZ;
1547
1548 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan))
1549 rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
1550
1551 REG_WRITE(ah, AR_PHY_MODE, rfMode);
1552}
1553
1554static bool ath9k_hw_set_reset(struct ath_hal *ah, int type)
1555{
1556 u32 rst_flags;
1557 u32 tmpReg;
1558
1559 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1560 AR_RTC_FORCE_WAKE_ON_INT);
1561
1562 if (AR_SREV_9100(ah)) {
1563 rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
1564 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1565 } else {
1566 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1567 if (tmpReg &
1568 (AR_INTR_SYNC_LOCAL_TIMEOUT |
1569 AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
1570 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
1571 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
1572 } else {
1573 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1574 }
1575
1576 rst_flags = AR_RTC_RC_MAC_WARM;
1577 if (type == ATH9K_RESET_COLD)
1578 rst_flags |= AR_RTC_RC_MAC_COLD;
1579 }
1580
1581 REG_WRITE(ah, (u16) (AR_RTC_RC), rst_flags);
1582 udelay(50);
1583
1584 REG_WRITE(ah, (u16) (AR_RTC_RC), 0);
1585 if (!ath9k_hw_wait(ah, (u16) (AR_RTC_RC), AR_RTC_RC_M, 0)) {
1586 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
1587 "%s: RTC stuck in MAC reset\n",
1588 __func__);
1589 return false;
1590 }
1591
1592 if (!AR_SREV_9100(ah))
1593 REG_WRITE(ah, AR_RC, 0);
1594
1595 ath9k_hw_init_pll(ah, NULL);
1596
1597 if (AR_SREV_9100(ah))
1598 udelay(50);
1599
1600 return true;
1601}
1602
1603static bool ath9k_hw_set_reset_power_on(struct ath_hal *ah)
1604{
1605 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1606 AR_RTC_FORCE_WAKE_ON_INT);
1607
1608 REG_WRITE(ah, (u16) (AR_RTC_RESET), 0);
1609 REG_WRITE(ah, (u16) (AR_RTC_RESET), 1);
1610
1611 if (!ath9k_hw_wait(ah,
1612 AR_RTC_STATUS,
1613 AR_RTC_STATUS_M,
1614 AR_RTC_STATUS_ON)) {
1615 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "%s: RTC not waking up\n",
1616 __func__);
1617 return false;
1618 }
1619
1620 ath9k_hw_read_revisions(ah);
1621
1622 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1623}
1624
1625static bool ath9k_hw_set_reset_reg(struct ath_hal *ah,
1626 u32 type)
1627{
1628 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1629 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1630
1631 switch (type) {
1632 case ATH9K_RESET_POWER_ON:
1633 return ath9k_hw_set_reset_power_on(ah);
1634 break;
1635 case ATH9K_RESET_WARM:
1636 case ATH9K_RESET_COLD:
1637 return ath9k_hw_set_reset(ah, type);
1638 break;
1639 default:
1640 return false;
1641 }
1642}
1643
1644static
1645struct ath9k_channel *ath9k_hw_check_chan(struct ath_hal *ah,
1646 struct ath9k_channel *chan)
1647{
1648 if (!(IS_CHAN_2GHZ(chan) ^ IS_CHAN_5GHZ(chan))) {
1649 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
1650 "%s: invalid channel %u/0x%x; not marked as "
1651 "2GHz or 5GHz\n", __func__, chan->channel,
1652 chan->channelFlags);
1653 return NULL;
1654 }
1655
1656 if (!IS_CHAN_OFDM(chan) &&
1657 !IS_CHAN_CCK(chan) &&
1658 !IS_CHAN_HT20(chan) &&
1659 !IS_CHAN_HT40(chan)) {
1660 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
1661 "%s: invalid channel %u/0x%x; not marked as "
1662 "OFDM or CCK or HT20 or HT40PLUS or HT40MINUS\n",
1663 __func__, chan->channel, chan->channelFlags);
1664 return NULL;
1665 }
1666
1667 return ath9k_regd_check_channel(ah, chan);
1668}
1669
1670static inline bool
1671ath9k_hw_get_lower_upper_index(u8 target,
1672 u8 *pList,
1673 u16 listSize,
1674 u16 *indexL,
1675 u16 *indexR)
1676{
1677 u16 i;
1678
1679 if (target <= pList[0]) {
1680 *indexL = *indexR = 0;
1681 return true;
1682 }
1683 if (target >= pList[listSize - 1]) {
1684 *indexL = *indexR = (u16) (listSize - 1);
1685 return true;
1686 }
1687
1688 for (i = 0; i < listSize - 1; i++) {
1689 if (pList[i] == target) {
1690 *indexL = *indexR = i;
1691 return true;
1692 }
1693 if (target < pList[i + 1]) {
1694 *indexL = i;
1695 *indexR = (u16) (i + 1);
1696 return false;
1697 }
1698 }
1699 return false;
1700}
1701
1702static int16_t ath9k_hw_get_nf_hist_mid(int16_t *nfCalBuffer)
1703{
1704 int16_t nfval;
1705 int16_t sort[ATH9K_NF_CAL_HIST_MAX];
1706 int i, j;
1707
1708 for (i = 0; i < ATH9K_NF_CAL_HIST_MAX; i++)
1709 sort[i] = nfCalBuffer[i];
1710
1711 for (i = 0; i < ATH9K_NF_CAL_HIST_MAX - 1; i++) {
1712 for (j = 1; j < ATH9K_NF_CAL_HIST_MAX - i; j++) {
1713 if (sort[j] > sort[j - 1]) {
1714 nfval = sort[j];
1715 sort[j] = sort[j - 1];
1716 sort[j - 1] = nfval;
1717 }
1718 }
1719 }
1720 nfval = sort[(ATH9K_NF_CAL_HIST_MAX - 1) >> 1];
1721
1722 return nfval;
1723}
1724
1725static void ath9k_hw_update_nfcal_hist_buffer(struct ath9k_nfcal_hist *h,
1726 int16_t *nfarray)
1727{ 536{
537 u32 sum;
1728 int i; 538 int i;
1729 539 u16 eeval;
1730 for (i = 0; i < NUM_NF_READINGS; i++) {
1731 h[i].nfCalBuffer[h[i].currIndex] = nfarray[i];
1732
1733 if (++h[i].currIndex >= ATH9K_NF_CAL_HIST_MAX)
1734 h[i].currIndex = 0;
1735
1736 if (h[i].invalidNFcount > 0) {
1737 if (nfarray[i] < AR_PHY_CCA_MIN_BAD_VALUE
1738 || nfarray[i] > AR_PHY_CCA_MAX_HIGH_VALUE) {
1739 h[i].invalidNFcount = ATH9K_NF_CAL_HIST_MAX;
1740 } else {
1741 h[i].invalidNFcount--;
1742 h[i].privNF = nfarray[i];
1743 }
1744 } else {
1745 h[i].privNF =
1746 ath9k_hw_get_nf_hist_mid(h[i].nfCalBuffer);
1747 }
1748 }
1749 return;
1750}
1751
1752static void ar5416GetNoiseFloor(struct ath_hal *ah,
1753 int16_t nfarray[NUM_NF_READINGS])
1754{
1755 int16_t nf;
1756
1757 if (AR_SREV_9280_10_OR_LATER(ah))
1758 nf = MS(REG_READ(ah, AR_PHY_CCA), AR9280_PHY_MINCCA_PWR);
1759 else
1760 nf = MS(REG_READ(ah, AR_PHY_CCA), AR_PHY_MINCCA_PWR);
1761
1762 if (nf & 0x100)
1763 nf = 0 - ((nf ^ 0x1ff) + 1);
1764 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
1765 "NF calibrated [ctl] [chain 0] is %d\n", nf);
1766 nfarray[0] = nf;
1767
1768 if (AR_SREV_9280_10_OR_LATER(ah))
1769 nf = MS(REG_READ(ah, AR_PHY_CH1_CCA),
1770 AR9280_PHY_CH1_MINCCA_PWR);
1771 else
1772 nf = MS(REG_READ(ah, AR_PHY_CH1_CCA),
1773 AR_PHY_CH1_MINCCA_PWR);
1774
1775 if (nf & 0x100)
1776 nf = 0 - ((nf ^ 0x1ff) + 1);
1777 DPRINTF(ah->ah_sc, ATH_DBG_NF_CAL,
1778 "NF calibrated [ctl] [chain 1] is %d\n", nf);
1779 nfarray[1] = nf;
1780
1781 if (!AR_SREV_9280(ah)) {
1782 nf = MS(REG_READ(ah, AR_PHY_CH2_CCA),
1783 AR_PHY_CH2_MINCCA_PWR);
1784 if (nf & 0x100)
1785 nf = 0 - ((nf ^ 0x1ff) + 1);
1786 DPRINTF(ah->ah_sc, ATH_DBG_NF_CAL,
1787 "NF calibrated [ctl] [chain 2] is %d\n", nf);
1788 nfarray[2] = nf;
1789 }
1790
1791 if (AR_SREV_9280_10_OR_LATER(ah))
1792 nf = MS(REG_READ(ah, AR_PHY_EXT_CCA),
1793 AR9280_PHY_EXT_MINCCA_PWR);
1794 else
1795 nf = MS(REG_READ(ah, AR_PHY_EXT_CCA),
1796 AR_PHY_EXT_MINCCA_PWR);
1797
1798 if (nf & 0x100)
1799 nf = 0 - ((nf ^ 0x1ff) + 1);
1800 DPRINTF(ah->ah_sc, ATH_DBG_NF_CAL,
1801 "NF calibrated [ext] [chain 0] is %d\n", nf);
1802 nfarray[3] = nf;
1803
1804 if (AR_SREV_9280_10_OR_LATER(ah))
1805 nf = MS(REG_READ(ah, AR_PHY_CH1_EXT_CCA),
1806 AR9280_PHY_CH1_EXT_MINCCA_PWR);
1807 else
1808 nf = MS(REG_READ(ah, AR_PHY_CH1_EXT_CCA),
1809 AR_PHY_CH1_EXT_MINCCA_PWR);
1810
1811 if (nf & 0x100)
1812 nf = 0 - ((nf ^ 0x1ff) + 1);
1813 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
1814 "NF calibrated [ext] [chain 1] is %d\n", nf);
1815 nfarray[4] = nf;
1816
1817 if (!AR_SREV_9280(ah)) {
1818 nf = MS(REG_READ(ah, AR_PHY_CH2_EXT_CCA),
1819 AR_PHY_CH2_EXT_MINCCA_PWR);
1820 if (nf & 0x100)
1821 nf = 0 - ((nf ^ 0x1ff) + 1);
1822 DPRINTF(ah->ah_sc, ATH_DBG_NF_CAL,
1823 "NF calibrated [ext] [chain 2] is %d\n", nf);
1824 nfarray[5] = nf;
1825 }
1826}
1827
1828static bool
1829getNoiseFloorThresh(struct ath_hal *ah,
1830 const struct ath9k_channel *chan,
1831 int16_t *nft)
1832{
1833 struct ath_hal_5416 *ahp = AH5416(ah); 540 struct ath_hal_5416 *ahp = AH5416(ah);
1834 541
1835 switch (chan->chanmode) { 542 sum = 0;
1836 case CHANNEL_A: 543 for (i = 0; i < 3; i++) {
1837 case CHANNEL_A_HT20: 544 eeval = ath9k_hw_get_eeprom(ah, AR_EEPROM_MAC(i));
1838 case CHANNEL_A_HT40PLUS: 545 sum += eeval;
1839 case CHANNEL_A_HT40MINUS: 546 ahp->ah_macaddr[2 * i] = eeval >> 8;
1840 *nft = (int16_t) ath9k_hw_get_eeprom(ahp, EEP_NFTHRESH_5); 547 ahp->ah_macaddr[2 * i + 1] = eeval & 0xff;
1841 break;
1842 case CHANNEL_B:
1843 case CHANNEL_G:
1844 case CHANNEL_G_HT20:
1845 case CHANNEL_G_HT40PLUS:
1846 case CHANNEL_G_HT40MINUS:
1847 *nft = (int16_t) ath9k_hw_get_eeprom(ahp, EEP_NFTHRESH_2);
1848 break;
1849 default:
1850 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
1851 "%s: invalid channel flags 0x%x\n", __func__,
1852 chan->channelFlags);
1853 return false;
1854 }
1855 return true;
1856}
1857
1858static void ath9k_hw_start_nfcal(struct ath_hal *ah)
1859{
1860 REG_SET_BIT(ah, AR_PHY_AGC_CONTROL,
1861 AR_PHY_AGC_CONTROL_ENABLE_NF);
1862 REG_SET_BIT(ah, AR_PHY_AGC_CONTROL,
1863 AR_PHY_AGC_CONTROL_NO_UPDATE_NF);
1864 REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_NF);
1865}
1866
1867static void
1868ath9k_hw_loadnf(struct ath_hal *ah, struct ath9k_channel *chan)
1869{
1870 struct ath9k_nfcal_hist *h;
1871 int i, j;
1872 int32_t val;
1873 const u32 ar5416_cca_regs[6] = {
1874 AR_PHY_CCA,
1875 AR_PHY_CH1_CCA,
1876 AR_PHY_CH2_CCA,
1877 AR_PHY_EXT_CCA,
1878 AR_PHY_CH1_EXT_CCA,
1879 AR_PHY_CH2_EXT_CCA
1880 };
1881 u8 chainmask;
1882
1883 if (AR_SREV_9280(ah))
1884 chainmask = 0x1B;
1885 else
1886 chainmask = 0x3F;
1887
1888#ifdef ATH_NF_PER_CHAN
1889 h = chan->nfCalHist;
1890#else
1891 h = ah->nfCalHist;
1892#endif
1893
1894 for (i = 0; i < NUM_NF_READINGS; i++) {
1895 if (chainmask & (1 << i)) {
1896 val = REG_READ(ah, ar5416_cca_regs[i]);
1897 val &= 0xFFFFFE00;
1898 val |= (((u32) (h[i].privNF) << 1) & 0x1ff);
1899 REG_WRITE(ah, ar5416_cca_regs[i], val);
1900 }
1901 }
1902
1903 REG_CLR_BIT(ah, AR_PHY_AGC_CONTROL,
1904 AR_PHY_AGC_CONTROL_ENABLE_NF);
1905 REG_CLR_BIT(ah, AR_PHY_AGC_CONTROL,
1906 AR_PHY_AGC_CONTROL_NO_UPDATE_NF);
1907 REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_NF);
1908
1909 for (j = 0; j < 1000; j++) {
1910 if ((REG_READ(ah, AR_PHY_AGC_CONTROL) &
1911 AR_PHY_AGC_CONTROL_NF) == 0)
1912 break;
1913 udelay(10);
1914 }
1915
1916 for (i = 0; i < NUM_NF_READINGS; i++) {
1917 if (chainmask & (1 << i)) {
1918 val = REG_READ(ah, ar5416_cca_regs[i]);
1919 val &= 0xFFFFFE00;
1920 val |= (((u32) (-50) << 1) & 0x1ff);
1921 REG_WRITE(ah, ar5416_cca_regs[i], val);
1922 }
1923 }
1924}
1925
1926static int16_t ath9k_hw_getnf(struct ath_hal *ah,
1927 struct ath9k_channel *chan)
1928{
1929 int16_t nf, nfThresh;
1930 int16_t nfarray[NUM_NF_READINGS] = { 0 };
1931 struct ath9k_nfcal_hist *h;
1932 u8 chainmask;
1933
1934 if (AR_SREV_9280(ah))
1935 chainmask = 0x1B;
1936 else
1937 chainmask = 0x3F;
1938
1939 chan->channelFlags &= (~CHANNEL_CW_INT);
1940 if (REG_READ(ah, AR_PHY_AGC_CONTROL) & AR_PHY_AGC_CONTROL_NF) {
1941 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
1942 "%s: NF did not complete in calibration window\n",
1943 __func__);
1944 nf = 0;
1945 chan->rawNoiseFloor = nf;
1946 return chan->rawNoiseFloor;
1947 } else {
1948 ar5416GetNoiseFloor(ah, nfarray);
1949 nf = nfarray[0];
1950 if (getNoiseFloorThresh(ah, chan, &nfThresh)
1951 && nf > nfThresh) {
1952 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
1953 "%s: noise floor failed detected; "
1954 "detected %d, threshold %d\n", __func__,
1955 nf, nfThresh);
1956 chan->channelFlags |= CHANNEL_CW_INT;
1957 }
1958 } 548 }
1959 549 if (sum == 0 || sum == 0xffff * 3) {
1960#ifdef ATH_NF_PER_CHAN 550 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
1961 h = chan->nfCalHist; 551 "%s: mac address read failed: %pM\n", __func__,
1962#else 552 ahp->ah_macaddr);
1963 h = ah->nfCalHist; 553 return -EADDRNOTAVAIL;
1964#endif
1965
1966 ath9k_hw_update_nfcal_hist_buffer(h, nfarray);
1967 chan->rawNoiseFloor = h[0].privNF;
1968
1969 return chan->rawNoiseFloor;
1970}
1971
1972static void ath9k_hw_update_mibstats(struct ath_hal *ah,
1973 struct ath9k_mib_stats *stats)
1974{
1975 stats->ackrcv_bad += REG_READ(ah, AR_ACK_FAIL);
1976 stats->rts_bad += REG_READ(ah, AR_RTS_FAIL);
1977 stats->fcs_bad += REG_READ(ah, AR_FCS_FAIL);
1978 stats->rts_good += REG_READ(ah, AR_RTS_OK);
1979 stats->beacons += REG_READ(ah, AR_BEACON_CNT);
1980}
1981
1982static void ath9k_enable_mib_counters(struct ath_hal *ah)
1983{
1984 struct ath_hal_5416 *ahp = AH5416(ah);
1985
1986 DPRINTF(ah->ah_sc, ATH_DBG_ANI, "Enable mib counters\n");
1987
1988 ath9k_hw_update_mibstats(ah, &ahp->ah_mibStats);
1989
1990 REG_WRITE(ah, AR_FILT_OFDM, 0);
1991 REG_WRITE(ah, AR_FILT_CCK, 0);
1992 REG_WRITE(ah, AR_MIBC,
1993 ~(AR_MIBC_COW | AR_MIBC_FMC | AR_MIBC_CMC | AR_MIBC_MCS)
1994 & 0x0f);
1995 REG_WRITE(ah, AR_PHY_ERR_MASK_1, AR_PHY_ERR_OFDM_TIMING);
1996 REG_WRITE(ah, AR_PHY_ERR_MASK_2, AR_PHY_ERR_CCK_TIMING);
1997}
1998
1999static void ath9k_hw_disable_mib_counters(struct ath_hal *ah)
2000{
2001 struct ath_hal_5416 *ahp = AH5416(ah);
2002
2003 DPRINTF(ah->ah_sc, ATH_DBG_ANI, "Disabling MIB counters\n");
2004
2005 REG_WRITE(ah, AR_MIBC, AR_MIBC_FMC | AR_MIBC_CMC);
2006
2007 ath9k_hw_update_mibstats(ah, &ahp->ah_mibStats);
2008
2009 REG_WRITE(ah, AR_FILT_OFDM, 0);
2010 REG_WRITE(ah, AR_FILT_CCK, 0);
2011}
2012
2013static int ath9k_hw_get_ani_channel_idx(struct ath_hal *ah,
2014 struct ath9k_channel *chan)
2015{
2016 struct ath_hal_5416 *ahp = AH5416(ah);
2017 int i;
2018
2019 for (i = 0; i < ARRAY_SIZE(ahp->ah_ani); i++) {
2020 if (ahp->ah_ani[i].c.channel == chan->channel)
2021 return i;
2022 if (ahp->ah_ani[i].c.channel == 0) {
2023 ahp->ah_ani[i].c.channel = chan->channel;
2024 ahp->ah_ani[i].c.channelFlags = chan->channelFlags;
2025 return i;
2026 }
2027 } 554 }
2028 555
2029 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
2030 "No more channel states left. Using channel 0\n");
2031 return 0; 556 return 0;
2032} 557}
2033 558
2034static void ath9k_hw_ani_attach(struct ath_hal *ah)
2035{
2036 struct ath_hal_5416 *ahp = AH5416(ah);
2037 int i;
2038
2039 ahp->ah_hasHwPhyCounters = 1;
2040
2041 memset(ahp->ah_ani, 0, sizeof(ahp->ah_ani));
2042 for (i = 0; i < ARRAY_SIZE(ahp->ah_ani); i++) {
2043 ahp->ah_ani[i].ofdmTrigHigh = ATH9K_ANI_OFDM_TRIG_HIGH;
2044 ahp->ah_ani[i].ofdmTrigLow = ATH9K_ANI_OFDM_TRIG_LOW;
2045 ahp->ah_ani[i].cckTrigHigh = ATH9K_ANI_CCK_TRIG_HIGH;
2046 ahp->ah_ani[i].cckTrigLow = ATH9K_ANI_CCK_TRIG_LOW;
2047 ahp->ah_ani[i].rssiThrHigh = ATH9K_ANI_RSSI_THR_HIGH;
2048 ahp->ah_ani[i].rssiThrLow = ATH9K_ANI_RSSI_THR_LOW;
2049 ahp->ah_ani[i].ofdmWeakSigDetectOff =
2050 !ATH9K_ANI_USE_OFDM_WEAK_SIG;
2051 ahp->ah_ani[i].cckWeakSigThreshold =
2052 ATH9K_ANI_CCK_WEAK_SIG_THR;
2053 ahp->ah_ani[i].spurImmunityLevel = ATH9K_ANI_SPUR_IMMUNE_LVL;
2054 ahp->ah_ani[i].firstepLevel = ATH9K_ANI_FIRSTEP_LVL;
2055 if (ahp->ah_hasHwPhyCounters) {
2056 ahp->ah_ani[i].ofdmPhyErrBase =
2057 AR_PHY_COUNTMAX - ATH9K_ANI_OFDM_TRIG_HIGH;
2058 ahp->ah_ani[i].cckPhyErrBase =
2059 AR_PHY_COUNTMAX - ATH9K_ANI_CCK_TRIG_HIGH;
2060 }
2061 }
2062 if (ahp->ah_hasHwPhyCounters) {
2063 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
2064 "Setting OfdmErrBase = 0x%08x\n",
2065 ahp->ah_ani[0].ofdmPhyErrBase);
2066 DPRINTF(ah->ah_sc, ATH_DBG_ANI, "Setting cckErrBase = 0x%08x\n",
2067 ahp->ah_ani[0].cckPhyErrBase);
2068
2069 REG_WRITE(ah, AR_PHY_ERR_1, ahp->ah_ani[0].ofdmPhyErrBase);
2070 REG_WRITE(ah, AR_PHY_ERR_2, ahp->ah_ani[0].cckPhyErrBase);
2071 ath9k_enable_mib_counters(ah);
2072 }
2073 ahp->ah_aniPeriod = ATH9K_ANI_PERIOD;
2074 if (ah->ah_config.enable_ani)
2075 ahp->ah_procPhyErr |= HAL_PROCESS_ANI;
2076}
2077
2078static void ath9k_hw_ani_setup(struct ath_hal *ah)
2079{
2080 struct ath_hal_5416 *ahp = AH5416(ah);
2081 int i;
2082
2083 const int totalSizeDesired[] = { -55, -55, -55, -55, -62 };
2084 const int coarseHigh[] = { -14, -14, -14, -14, -12 };
2085 const int coarseLow[] = { -64, -64, -64, -64, -70 };
2086 const int firpwr[] = { -78, -78, -78, -78, -80 };
2087
2088 for (i = 0; i < 5; i++) {
2089 ahp->ah_totalSizeDesired[i] = totalSizeDesired[i];
2090 ahp->ah_coarseHigh[i] = coarseHigh[i];
2091 ahp->ah_coarseLow[i] = coarseLow[i];
2092 ahp->ah_firpwr[i] = firpwr[i];
2093 }
2094}
2095
2096static void ath9k_hw_ani_detach(struct ath_hal *ah)
2097{
2098 struct ath_hal_5416 *ahp = AH5416(ah);
2099
2100 DPRINTF(ah->ah_sc, ATH_DBG_ANI, "Detaching Ani\n");
2101 if (ahp->ah_hasHwPhyCounters) {
2102 ath9k_hw_disable_mib_counters(ah);
2103 REG_WRITE(ah, AR_PHY_ERR_1, 0);
2104 REG_WRITE(ah, AR_PHY_ERR_2, 0);
2105 }
2106}
2107
2108
2109static bool ath9k_hw_ani_control(struct ath_hal *ah,
2110 enum ath9k_ani_cmd cmd, int param)
2111{
2112 struct ath_hal_5416 *ahp = AH5416(ah);
2113 struct ar5416AniState *aniState = ahp->ah_curani;
2114
2115 switch (cmd & ahp->ah_ani_function) {
2116 case ATH9K_ANI_NOISE_IMMUNITY_LEVEL:{
2117 u32 level = param;
2118
2119 if (level >= ARRAY_SIZE(ahp->ah_totalSizeDesired)) {
2120 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
2121 "%s: level out of range (%u > %u)\n",
2122 __func__, level,
2123 (unsigned) ARRAY_SIZE(ahp->
2124 ah_totalSizeDesired));
2125 return false;
2126 }
2127
2128 REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ,
2129 AR_PHY_DESIRED_SZ_TOT_DES,
2130 ahp->ah_totalSizeDesired[level]);
2131 REG_RMW_FIELD(ah, AR_PHY_AGC_CTL1,
2132 AR_PHY_AGC_CTL1_COARSE_LOW,
2133 ahp->ah_coarseLow[level]);
2134 REG_RMW_FIELD(ah, AR_PHY_AGC_CTL1,
2135 AR_PHY_AGC_CTL1_COARSE_HIGH,
2136 ahp->ah_coarseHigh[level]);
2137 REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
2138 AR_PHY_FIND_SIG_FIRPWR,
2139 ahp->ah_firpwr[level]);
2140
2141 if (level > aniState->noiseImmunityLevel)
2142 ahp->ah_stats.ast_ani_niup++;
2143 else if (level < aniState->noiseImmunityLevel)
2144 ahp->ah_stats.ast_ani_nidown++;
2145 aniState->noiseImmunityLevel = level;
2146 break;
2147 }
2148 case ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION:{
2149 const int m1ThreshLow[] = { 127, 50 };
2150 const int m2ThreshLow[] = { 127, 40 };
2151 const int m1Thresh[] = { 127, 0x4d };
2152 const int m2Thresh[] = { 127, 0x40 };
2153 const int m2CountThr[] = { 31, 16 };
2154 const int m2CountThrLow[] = { 63, 48 };
2155 u32 on = param ? 1 : 0;
2156
2157 REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
2158 AR_PHY_SFCORR_LOW_M1_THRESH_LOW,
2159 m1ThreshLow[on]);
2160 REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
2161 AR_PHY_SFCORR_LOW_M2_THRESH_LOW,
2162 m2ThreshLow[on]);
2163 REG_RMW_FIELD(ah, AR_PHY_SFCORR,
2164 AR_PHY_SFCORR_M1_THRESH,
2165 m1Thresh[on]);
2166 REG_RMW_FIELD(ah, AR_PHY_SFCORR,
2167 AR_PHY_SFCORR_M2_THRESH,
2168 m2Thresh[on]);
2169 REG_RMW_FIELD(ah, AR_PHY_SFCORR,
2170 AR_PHY_SFCORR_M2COUNT_THR,
2171 m2CountThr[on]);
2172 REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
2173 AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW,
2174 m2CountThrLow[on]);
2175
2176 REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
2177 AR_PHY_SFCORR_EXT_M1_THRESH_LOW,
2178 m1ThreshLow[on]);
2179 REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
2180 AR_PHY_SFCORR_EXT_M2_THRESH_LOW,
2181 m2ThreshLow[on]);
2182 REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
2183 AR_PHY_SFCORR_EXT_M1_THRESH,
2184 m1Thresh[on]);
2185 REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
2186 AR_PHY_SFCORR_EXT_M2_THRESH,
2187 m2Thresh[on]);
2188
2189 if (on)
2190 REG_SET_BIT(ah, AR_PHY_SFCORR_LOW,
2191 AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
2192 else
2193 REG_CLR_BIT(ah, AR_PHY_SFCORR_LOW,
2194 AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
2195
2196 if (!on != aniState->ofdmWeakSigDetectOff) {
2197 if (on)
2198 ahp->ah_stats.ast_ani_ofdmon++;
2199 else
2200 ahp->ah_stats.ast_ani_ofdmoff++;
2201 aniState->ofdmWeakSigDetectOff = !on;
2202 }
2203 break;
2204 }
2205 case ATH9K_ANI_CCK_WEAK_SIGNAL_THR:{
2206 const int weakSigThrCck[] = { 8, 6 };
2207 u32 high = param ? 1 : 0;
2208
2209 REG_RMW_FIELD(ah, AR_PHY_CCK_DETECT,
2210 AR_PHY_CCK_DETECT_WEAK_SIG_THR_CCK,
2211 weakSigThrCck[high]);
2212 if (high != aniState->cckWeakSigThreshold) {
2213 if (high)
2214 ahp->ah_stats.ast_ani_cckhigh++;
2215 else
2216 ahp->ah_stats.ast_ani_ccklow++;
2217 aniState->cckWeakSigThreshold = high;
2218 }
2219 break;
2220 }
2221 case ATH9K_ANI_FIRSTEP_LEVEL:{
2222 const int firstep[] = { 0, 4, 8 };
2223 u32 level = param;
2224
2225 if (level >= ARRAY_SIZE(firstep)) {
2226 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
2227 "%s: level out of range (%u > %u)\n",
2228 __func__, level,
2229 (unsigned) ARRAY_SIZE(firstep));
2230 return false;
2231 }
2232 REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
2233 AR_PHY_FIND_SIG_FIRSTEP,
2234 firstep[level]);
2235 if (level > aniState->firstepLevel)
2236 ahp->ah_stats.ast_ani_stepup++;
2237 else if (level < aniState->firstepLevel)
2238 ahp->ah_stats.ast_ani_stepdown++;
2239 aniState->firstepLevel = level;
2240 break;
2241 }
2242 case ATH9K_ANI_SPUR_IMMUNITY_LEVEL:{
2243 const int cycpwrThr1[] =
2244 { 2, 4, 6, 8, 10, 12, 14, 16 };
2245 u32 level = param;
2246
2247 if (level >= ARRAY_SIZE(cycpwrThr1)) {
2248 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
2249 "%s: level out of range (%u > %u)\n",
2250 __func__, level,
2251 (unsigned)
2252 ARRAY_SIZE(cycpwrThr1));
2253 return false;
2254 }
2255 REG_RMW_FIELD(ah, AR_PHY_TIMING5,
2256 AR_PHY_TIMING5_CYCPWR_THR1,
2257 cycpwrThr1[level]);
2258 if (level > aniState->spurImmunityLevel)
2259 ahp->ah_stats.ast_ani_spurup++;
2260 else if (level < aniState->spurImmunityLevel)
2261 ahp->ah_stats.ast_ani_spurdown++;
2262 aniState->spurImmunityLevel = level;
2263 break;
2264 }
2265 case ATH9K_ANI_PRESENT:
2266 break;
2267 default:
2268 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
2269 "%s: invalid cmd %u\n", __func__, cmd);
2270 return false;
2271 }
2272
2273 DPRINTF(ah->ah_sc, ATH_DBG_ANI, "%s: ANI parameters:\n", __func__);
2274 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
2275 "noiseImmunityLevel=%d, spurImmunityLevel=%d, "
2276 "ofdmWeakSigDetectOff=%d\n",
2277 aniState->noiseImmunityLevel, aniState->spurImmunityLevel,
2278 !aniState->ofdmWeakSigDetectOff);
2279 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
2280 "cckWeakSigThreshold=%d, "
2281 "firstepLevel=%d, listenTime=%d\n",
2282 aniState->cckWeakSigThreshold, aniState->firstepLevel,
2283 aniState->listenTime);
2284 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
2285 "cycleCount=%d, ofdmPhyErrCount=%d, cckPhyErrCount=%d\n\n",
2286 aniState->cycleCount, aniState->ofdmPhyErrCount,
2287 aniState->cckPhyErrCount);
2288 return true;
2289}
2290
2291static void ath9k_ani_restart(struct ath_hal *ah)
2292{
2293 struct ath_hal_5416 *ahp = AH5416(ah);
2294 struct ar5416AniState *aniState;
2295
2296 if (!DO_ANI(ah))
2297 return;
2298
2299 aniState = ahp->ah_curani;
2300
2301 aniState->listenTime = 0;
2302 if (ahp->ah_hasHwPhyCounters) {
2303 if (aniState->ofdmTrigHigh > AR_PHY_COUNTMAX) {
2304 aniState->ofdmPhyErrBase = 0;
2305 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
2306 "OFDM Trigger is too high for hw counters\n");
2307 } else {
2308 aniState->ofdmPhyErrBase =
2309 AR_PHY_COUNTMAX - aniState->ofdmTrigHigh;
2310 }
2311 if (aniState->cckTrigHigh > AR_PHY_COUNTMAX) {
2312 aniState->cckPhyErrBase = 0;
2313 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
2314 "CCK Trigger is too high for hw counters\n");
2315 } else {
2316 aniState->cckPhyErrBase =
2317 AR_PHY_COUNTMAX - aniState->cckTrigHigh;
2318 }
2319 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
2320 "%s: Writing ofdmbase=%u cckbase=%u\n",
2321 __func__, aniState->ofdmPhyErrBase,
2322 aniState->cckPhyErrBase);
2323 REG_WRITE(ah, AR_PHY_ERR_1, aniState->ofdmPhyErrBase);
2324 REG_WRITE(ah, AR_PHY_ERR_2, aniState->cckPhyErrBase);
2325 REG_WRITE(ah, AR_PHY_ERR_MASK_1, AR_PHY_ERR_OFDM_TIMING);
2326 REG_WRITE(ah, AR_PHY_ERR_MASK_2, AR_PHY_ERR_CCK_TIMING);
2327
2328 ath9k_hw_update_mibstats(ah, &ahp->ah_mibStats);
2329 }
2330 aniState->ofdmPhyErrCount = 0;
2331 aniState->cckPhyErrCount = 0;
2332}
2333
2334static void ath9k_hw_ani_ofdm_err_trigger(struct ath_hal *ah)
2335{
2336 struct ath_hal_5416 *ahp = AH5416(ah);
2337 struct ath9k_channel *chan = ah->ah_curchan;
2338 struct ar5416AniState *aniState;
2339 enum wireless_mode mode;
2340 int32_t rssi;
2341
2342 if (!DO_ANI(ah))
2343 return;
2344
2345 aniState = ahp->ah_curani;
2346
2347 if (aniState->noiseImmunityLevel < HAL_NOISE_IMMUNE_MAX) {
2348 if (ath9k_hw_ani_control(ah, ATH9K_ANI_NOISE_IMMUNITY_LEVEL,
2349 aniState->noiseImmunityLevel + 1)) {
2350 return;
2351 }
2352 }
2353
2354 if (aniState->spurImmunityLevel < HAL_SPUR_IMMUNE_MAX) {
2355 if (ath9k_hw_ani_control(ah, ATH9K_ANI_SPUR_IMMUNITY_LEVEL,
2356 aniState->spurImmunityLevel + 1)) {
2357 return;
2358 }
2359 }
2360
2361 if (ah->ah_opmode == ATH9K_M_HOSTAP) {
2362 if (aniState->firstepLevel < HAL_FIRST_STEP_MAX) {
2363 ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
2364 aniState->firstepLevel + 1);
2365 }
2366 return;
2367 }
2368 rssi = BEACON_RSSI(ahp);
2369 if (rssi > aniState->rssiThrHigh) {
2370 if (!aniState->ofdmWeakSigDetectOff) {
2371 if (ath9k_hw_ani_control(ah,
2372 ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
2373 false)) {
2374 ath9k_hw_ani_control(ah,
2375 ATH9K_ANI_SPUR_IMMUNITY_LEVEL,
2376 0);
2377 return;
2378 }
2379 }
2380 if (aniState->firstepLevel < HAL_FIRST_STEP_MAX) {
2381 ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
2382 aniState->firstepLevel + 1);
2383 return;
2384 }
2385 } else if (rssi > aniState->rssiThrLow) {
2386 if (aniState->ofdmWeakSigDetectOff)
2387 ath9k_hw_ani_control(ah,
2388 ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
2389 true);
2390 if (aniState->firstepLevel < HAL_FIRST_STEP_MAX)
2391 ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
2392 aniState->firstepLevel + 1);
2393 return;
2394 } else {
2395 mode = ath9k_hw_chan2wmode(ah, chan);
2396 if (mode == ATH9K_MODE_11G || mode == ATH9K_MODE_11B) {
2397 if (!aniState->ofdmWeakSigDetectOff)
2398 ath9k_hw_ani_control(ah,
2399 ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
2400 false);
2401 if (aniState->firstepLevel > 0)
2402 ath9k_hw_ani_control(ah,
2403 ATH9K_ANI_FIRSTEP_LEVEL,
2404 0);
2405 return;
2406 }
2407 }
2408}
2409
2410static void ath9k_hw_ani_cck_err_trigger(struct ath_hal *ah)
2411{
2412 struct ath_hal_5416 *ahp = AH5416(ah);
2413 struct ath9k_channel *chan = ah->ah_curchan;
2414 struct ar5416AniState *aniState;
2415 enum wireless_mode mode;
2416 int32_t rssi;
2417
2418 if (!DO_ANI(ah))
2419 return;
2420
2421 aniState = ahp->ah_curani;
2422 if (aniState->noiseImmunityLevel < HAL_NOISE_IMMUNE_MAX) {
2423 if (ath9k_hw_ani_control(ah, ATH9K_ANI_NOISE_IMMUNITY_LEVEL,
2424 aniState->noiseImmunityLevel + 1)) {
2425 return;
2426 }
2427 }
2428 if (ah->ah_opmode == ATH9K_M_HOSTAP) {
2429 if (aniState->firstepLevel < HAL_FIRST_STEP_MAX) {
2430 ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
2431 aniState->firstepLevel + 1);
2432 }
2433 return;
2434 }
2435 rssi = BEACON_RSSI(ahp);
2436 if (rssi > aniState->rssiThrLow) {
2437 if (aniState->firstepLevel < HAL_FIRST_STEP_MAX)
2438 ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
2439 aniState->firstepLevel + 1);
2440 } else {
2441 mode = ath9k_hw_chan2wmode(ah, chan);
2442 if (mode == ATH9K_MODE_11G || mode == ATH9K_MODE_11B) {
2443 if (aniState->firstepLevel > 0)
2444 ath9k_hw_ani_control(ah,
2445 ATH9K_ANI_FIRSTEP_LEVEL,
2446 0);
2447 }
2448 }
2449}
2450
2451static void ath9k_ani_reset(struct ath_hal *ah)
2452{
2453 struct ath_hal_5416 *ahp = AH5416(ah);
2454 struct ar5416AniState *aniState;
2455 struct ath9k_channel *chan = ah->ah_curchan;
2456 int index;
2457
2458 if (!DO_ANI(ah))
2459 return;
2460
2461 index = ath9k_hw_get_ani_channel_idx(ah, chan);
2462 aniState = &ahp->ah_ani[index];
2463 ahp->ah_curani = aniState;
2464
2465 if (DO_ANI(ah) && ah->ah_opmode != ATH9K_M_STA
2466 && ah->ah_opmode != ATH9K_M_IBSS) {
2467 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
2468 "%s: Reset ANI state opmode %u\n", __func__,
2469 ah->ah_opmode);
2470 ahp->ah_stats.ast_ani_reset++;
2471 ath9k_hw_ani_control(ah, ATH9K_ANI_NOISE_IMMUNITY_LEVEL, 0);
2472 ath9k_hw_ani_control(ah, ATH9K_ANI_SPUR_IMMUNITY_LEVEL, 0);
2473 ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL, 0);
2474 ath9k_hw_ani_control(ah,
2475 ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
2476 !ATH9K_ANI_USE_OFDM_WEAK_SIG);
2477 ath9k_hw_ani_control(ah, ATH9K_ANI_CCK_WEAK_SIGNAL_THR,
2478 ATH9K_ANI_CCK_WEAK_SIG_THR);
2479 ath9k_hw_setrxfilter(ah,
2480 ath9k_hw_getrxfilter(ah) |
2481 ATH9K_RX_FILTER_PHYERR);
2482 if (ah->ah_opmode == ATH9K_M_HOSTAP) {
2483 ahp->ah_curani->ofdmTrigHigh =
2484 ah->ah_config.ofdm_trig_high;
2485 ahp->ah_curani->ofdmTrigLow =
2486 ah->ah_config.ofdm_trig_low;
2487 ahp->ah_curani->cckTrigHigh =
2488 ah->ah_config.cck_trig_high;
2489 ahp->ah_curani->cckTrigLow =
2490 ah->ah_config.cck_trig_low;
2491 }
2492 ath9k_ani_restart(ah);
2493 return;
2494 }
2495
2496 if (aniState->noiseImmunityLevel != 0)
2497 ath9k_hw_ani_control(ah, ATH9K_ANI_NOISE_IMMUNITY_LEVEL,
2498 aniState->noiseImmunityLevel);
2499 if (aniState->spurImmunityLevel != 0)
2500 ath9k_hw_ani_control(ah, ATH9K_ANI_SPUR_IMMUNITY_LEVEL,
2501 aniState->spurImmunityLevel);
2502 if (aniState->ofdmWeakSigDetectOff)
2503 ath9k_hw_ani_control(ah,
2504 ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
2505 !aniState->ofdmWeakSigDetectOff);
2506 if (aniState->cckWeakSigThreshold)
2507 ath9k_hw_ani_control(ah, ATH9K_ANI_CCK_WEAK_SIGNAL_THR,
2508 aniState->cckWeakSigThreshold);
2509 if (aniState->firstepLevel != 0)
2510 ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
2511 aniState->firstepLevel);
2512 if (ahp->ah_hasHwPhyCounters) {
2513 ath9k_hw_setrxfilter(ah,
2514 ath9k_hw_getrxfilter(ah) &
2515 ~ATH9K_RX_FILTER_PHYERR);
2516 ath9k_ani_restart(ah);
2517 REG_WRITE(ah, AR_PHY_ERR_MASK_1, AR_PHY_ERR_OFDM_TIMING);
2518 REG_WRITE(ah, AR_PHY_ERR_MASK_2, AR_PHY_ERR_CCK_TIMING);
2519
2520 } else {
2521 ath9k_ani_restart(ah);
2522 ath9k_hw_setrxfilter(ah,
2523 ath9k_hw_getrxfilter(ah) |
2524 ATH9K_RX_FILTER_PHYERR);
2525 }
2526}
2527
2528/*
2529 * Process a MIB interrupt. We may potentially be invoked because
2530 * any of the MIB counters overflow/trigger so don't assume we're
2531 * here because a PHY error counter triggered.
2532 */
2533void ath9k_hw_procmibevent(struct ath_hal *ah,
2534 const struct ath9k_node_stats *stats)
2535{
2536 struct ath_hal_5416 *ahp = AH5416(ah);
2537 u32 phyCnt1, phyCnt2;
2538
2539 DPRINTF(ah->ah_sc, ATH_DBG_ANI, "Processing Mib Intr\n");
2540 /* Reset these counters regardless */
2541 REG_WRITE(ah, AR_FILT_OFDM, 0);
2542 REG_WRITE(ah, AR_FILT_CCK, 0);
2543 if (!(REG_READ(ah, AR_SLP_MIB_CTRL) & AR_SLP_MIB_PENDING))
2544 REG_WRITE(ah, AR_SLP_MIB_CTRL, AR_SLP_MIB_CLEAR);
2545
2546 /* Clear the mib counters and save them in the stats */
2547 ath9k_hw_update_mibstats(ah, &ahp->ah_mibStats);
2548 ahp->ah_stats.ast_nodestats = *stats;
2549
2550 if (!DO_ANI(ah))
2551 return;
2552
2553 /* NB: these are not reset-on-read */
2554 phyCnt1 = REG_READ(ah, AR_PHY_ERR_1);
2555 phyCnt2 = REG_READ(ah, AR_PHY_ERR_2);
2556 if (((phyCnt1 & AR_MIBCNT_INTRMASK) == AR_MIBCNT_INTRMASK) ||
2557 ((phyCnt2 & AR_MIBCNT_INTRMASK) == AR_MIBCNT_INTRMASK)) {
2558 struct ar5416AniState *aniState = ahp->ah_curani;
2559 u32 ofdmPhyErrCnt, cckPhyErrCnt;
2560
2561 /* NB: only use ast_ani_*errs with AH_PRIVATE_DIAG */
2562 ofdmPhyErrCnt = phyCnt1 - aniState->ofdmPhyErrBase;
2563 ahp->ah_stats.ast_ani_ofdmerrs +=
2564 ofdmPhyErrCnt - aniState->ofdmPhyErrCount;
2565 aniState->ofdmPhyErrCount = ofdmPhyErrCnt;
2566
2567 cckPhyErrCnt = phyCnt2 - aniState->cckPhyErrBase;
2568 ahp->ah_stats.ast_ani_cckerrs +=
2569 cckPhyErrCnt - aniState->cckPhyErrCount;
2570 aniState->cckPhyErrCount = cckPhyErrCnt;
2571
2572 /*
2573 * NB: figure out which counter triggered. If both
2574 * trigger we'll only deal with one as the processing
2575 * clobbers the error counter so the trigger threshold
2576 * check will never be true.
2577 */
2578 if (aniState->ofdmPhyErrCount > aniState->ofdmTrigHigh)
2579 ath9k_hw_ani_ofdm_err_trigger(ah);
2580 if (aniState->cckPhyErrCount > aniState->cckTrigHigh)
2581 ath9k_hw_ani_cck_err_trigger(ah);
2582 /* NB: always restart to insure the h/w counters are reset */
2583 ath9k_ani_restart(ah);
2584 }
2585}
2586
2587static void ath9k_hw_ani_lower_immunity(struct ath_hal *ah)
2588{
2589 struct ath_hal_5416 *ahp = AH5416(ah);
2590 struct ar5416AniState *aniState;
2591 int32_t rssi;
2592
2593 aniState = ahp->ah_curani;
2594
2595 if (ah->ah_opmode == ATH9K_M_HOSTAP) {
2596 if (aniState->firstepLevel > 0) {
2597 if (ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
2598 aniState->firstepLevel - 1)) {
2599 return;
2600 }
2601 }
2602 } else {
2603 rssi = BEACON_RSSI(ahp);
2604 if (rssi > aniState->rssiThrHigh) {
2605 /* XXX: Handle me */
2606 } else if (rssi > aniState->rssiThrLow) {
2607 if (aniState->ofdmWeakSigDetectOff) {
2608 if (ath9k_hw_ani_control(ah,
2609 ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
2610 true) ==
2611 true) {
2612 return;
2613 }
2614 }
2615 if (aniState->firstepLevel > 0) {
2616 if (ath9k_hw_ani_control
2617 (ah, ATH9K_ANI_FIRSTEP_LEVEL,
2618 aniState->firstepLevel - 1) ==
2619 true) {
2620 return;
2621 }
2622 }
2623 } else {
2624 if (aniState->firstepLevel > 0) {
2625 if (ath9k_hw_ani_control
2626 (ah, ATH9K_ANI_FIRSTEP_LEVEL,
2627 aniState->firstepLevel - 1) ==
2628 true) {
2629 return;
2630 }
2631 }
2632 }
2633 }
2634
2635 if (aniState->spurImmunityLevel > 0) {
2636 if (ath9k_hw_ani_control(ah, ATH9K_ANI_SPUR_IMMUNITY_LEVEL,
2637 aniState->spurImmunityLevel - 1)) {
2638 return;
2639 }
2640 }
2641
2642 if (aniState->noiseImmunityLevel > 0) {
2643 ath9k_hw_ani_control(ah, ATH9K_ANI_NOISE_IMMUNITY_LEVEL,
2644 aniState->noiseImmunityLevel - 1);
2645 return;
2646 }
2647}
2648
2649static int32_t ath9k_hw_ani_get_listen_time(struct ath_hal *ah)
2650{
2651 struct ath_hal_5416 *ahp = AH5416(ah);
2652 struct ar5416AniState *aniState;
2653 u32 txFrameCount, rxFrameCount, cycleCount;
2654 int32_t listenTime;
2655
2656 txFrameCount = REG_READ(ah, AR_TFCNT);
2657 rxFrameCount = REG_READ(ah, AR_RFCNT);
2658 cycleCount = REG_READ(ah, AR_CCCNT);
2659
2660 aniState = ahp->ah_curani;
2661 if (aniState->cycleCount == 0 || aniState->cycleCount > cycleCount) {
2662
2663 listenTime = 0;
2664 ahp->ah_stats.ast_ani_lzero++;
2665 } else {
2666 int32_t ccdelta = cycleCount - aniState->cycleCount;
2667 int32_t rfdelta = rxFrameCount - aniState->rxFrameCount;
2668 int32_t tfdelta = txFrameCount - aniState->txFrameCount;
2669 listenTime = (ccdelta - rfdelta - tfdelta) / 44000;
2670 }
2671 aniState->cycleCount = cycleCount;
2672 aniState->txFrameCount = txFrameCount;
2673 aniState->rxFrameCount = rxFrameCount;
2674
2675 return listenTime;
2676}
2677
2678void ath9k_hw_ani_monitor(struct ath_hal *ah,
2679 const struct ath9k_node_stats *stats,
2680 struct ath9k_channel *chan)
2681{
2682 struct ath_hal_5416 *ahp = AH5416(ah);
2683 struct ar5416AniState *aniState;
2684 int32_t listenTime;
2685
2686 aniState = ahp->ah_curani;
2687 ahp->ah_stats.ast_nodestats = *stats;
2688
2689 listenTime = ath9k_hw_ani_get_listen_time(ah);
2690 if (listenTime < 0) {
2691 ahp->ah_stats.ast_ani_lneg++;
2692 ath9k_ani_restart(ah);
2693 return;
2694 }
2695
2696 aniState->listenTime += listenTime;
2697
2698 if (ahp->ah_hasHwPhyCounters) {
2699 u32 phyCnt1, phyCnt2;
2700 u32 ofdmPhyErrCnt, cckPhyErrCnt;
2701
2702 ath9k_hw_update_mibstats(ah, &ahp->ah_mibStats);
2703
2704 phyCnt1 = REG_READ(ah, AR_PHY_ERR_1);
2705 phyCnt2 = REG_READ(ah, AR_PHY_ERR_2);
2706
2707 if (phyCnt1 < aniState->ofdmPhyErrBase ||
2708 phyCnt2 < aniState->cckPhyErrBase) {
2709 if (phyCnt1 < aniState->ofdmPhyErrBase) {
2710 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
2711 "%s: phyCnt1 0x%x, resetting "
2712 "counter value to 0x%x\n",
2713 __func__, phyCnt1,
2714 aniState->ofdmPhyErrBase);
2715 REG_WRITE(ah, AR_PHY_ERR_1,
2716 aniState->ofdmPhyErrBase);
2717 REG_WRITE(ah, AR_PHY_ERR_MASK_1,
2718 AR_PHY_ERR_OFDM_TIMING);
2719 }
2720 if (phyCnt2 < aniState->cckPhyErrBase) {
2721 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
2722 "%s: phyCnt2 0x%x, resetting "
2723 "counter value to 0x%x\n",
2724 __func__, phyCnt2,
2725 aniState->cckPhyErrBase);
2726 REG_WRITE(ah, AR_PHY_ERR_2,
2727 aniState->cckPhyErrBase);
2728 REG_WRITE(ah, AR_PHY_ERR_MASK_2,
2729 AR_PHY_ERR_CCK_TIMING);
2730 }
2731 return;
2732 }
2733
2734 ofdmPhyErrCnt = phyCnt1 - aniState->ofdmPhyErrBase;
2735 ahp->ah_stats.ast_ani_ofdmerrs +=
2736 ofdmPhyErrCnt - aniState->ofdmPhyErrCount;
2737 aniState->ofdmPhyErrCount = ofdmPhyErrCnt;
2738
2739 cckPhyErrCnt = phyCnt2 - aniState->cckPhyErrBase;
2740 ahp->ah_stats.ast_ani_cckerrs +=
2741 cckPhyErrCnt - aniState->cckPhyErrCount;
2742 aniState->cckPhyErrCount = cckPhyErrCnt;
2743 }
2744
2745 if (!DO_ANI(ah))
2746 return;
2747
2748 if (aniState->listenTime > 5 * ahp->ah_aniPeriod) {
2749 if (aniState->ofdmPhyErrCount <= aniState->listenTime *
2750 aniState->ofdmTrigLow / 1000 &&
2751 aniState->cckPhyErrCount <= aniState->listenTime *
2752 aniState->cckTrigLow / 1000)
2753 ath9k_hw_ani_lower_immunity(ah);
2754 ath9k_ani_restart(ah);
2755 } else if (aniState->listenTime > ahp->ah_aniPeriod) {
2756 if (aniState->ofdmPhyErrCount > aniState->listenTime *
2757 aniState->ofdmTrigHigh / 1000) {
2758 ath9k_hw_ani_ofdm_err_trigger(ah);
2759 ath9k_ani_restart(ah);
2760 } else if (aniState->cckPhyErrCount >
2761 aniState->listenTime * aniState->cckTrigHigh /
2762 1000) {
2763 ath9k_hw_ani_cck_err_trigger(ah);
2764 ath9k_ani_restart(ah);
2765 }
2766 }
2767}
2768
2769#ifndef ATH_NF_PER_CHAN
2770static void ath9k_init_nfcal_hist_buffer(struct ath_hal *ah)
2771{
2772 int i, j;
2773
2774 for (i = 0; i < NUM_NF_READINGS; i++) {
2775 ah->nfCalHist[i].currIndex = 0;
2776 ah->nfCalHist[i].privNF = AR_PHY_CCA_MAX_GOOD_VALUE;
2777 ah->nfCalHist[i].invalidNFcount =
2778 AR_PHY_CCA_FILTERWINDOW_LENGTH;
2779 for (j = 0; j < ATH9K_NF_CAL_HIST_MAX; j++) {
2780 ah->nfCalHist[i].nfCalBuffer[j] =
2781 AR_PHY_CCA_MAX_GOOD_VALUE;
2782 }
2783 }
2784 return;
2785}
2786#endif
2787
2788static void ath9k_hw_gpio_cfg_output_mux(struct ath_hal *ah,
2789 u32 gpio, u32 type)
2790{
2791 int addr;
2792 u32 gpio_shift, tmp;
2793
2794 if (gpio > 11)
2795 addr = AR_GPIO_OUTPUT_MUX3;
2796 else if (gpio > 5)
2797 addr = AR_GPIO_OUTPUT_MUX2;
2798 else
2799 addr = AR_GPIO_OUTPUT_MUX1;
2800
2801 gpio_shift = (gpio % 6) * 5;
2802
2803 if (AR_SREV_9280_20_OR_LATER(ah)
2804 || (addr != AR_GPIO_OUTPUT_MUX1)) {
2805 REG_RMW(ah, addr, (type << gpio_shift),
2806 (0x1f << gpio_shift));
2807 } else {
2808 tmp = REG_READ(ah, addr);
2809 tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
2810 tmp &= ~(0x1f << gpio_shift);
2811 tmp |= (type << gpio_shift);
2812 REG_WRITE(ah, addr, tmp);
2813 }
2814}
2815
2816void ath9k_hw_cfg_output(struct ath_hal *ah, u32 gpio,
2817 u32 ah_signal_type)
2818{
2819 u32 gpio_shift;
2820
2821 ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
2822
2823 gpio_shift = 2 * gpio;
2824
2825 REG_RMW(ah,
2826 AR_GPIO_OE_OUT,
2827 (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
2828 (AR_GPIO_OE_OUT_DRV << gpio_shift));
2829}
2830
2831void ath9k_hw_set_gpio(struct ath_hal *ah, u32 gpio, u32 val)
2832{
2833 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
2834 AR_GPIO_BIT(gpio));
2835}
2836
2837/*
2838 * Configure GPIO Input lines
2839 */
2840void ath9k_hw_cfg_gpio_input(struct ath_hal *ah, u32 gpio)
2841{
2842 u32 gpio_shift;
2843
2844 ASSERT(gpio < ah->ah_caps.num_gpio_pins);
2845
2846 gpio_shift = gpio << 1;
2847
2848 REG_RMW(ah,
2849 AR_GPIO_OE_OUT,
2850 (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
2851 (AR_GPIO_OE_OUT_DRV << gpio_shift));
2852}
2853
2854#ifdef CONFIG_RFKILL
2855static void ath9k_enable_rfkill(struct ath_hal *ah)
2856{
2857 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
2858 AR_GPIO_INPUT_EN_VAL_RFSILENT_BB);
2859
2860 REG_CLR_BIT(ah, AR_GPIO_INPUT_MUX2,
2861 AR_GPIO_INPUT_MUX2_RFSILENT);
2862
2863 ath9k_hw_cfg_gpio_input(ah, ah->ah_rfkill_gpio);
2864 REG_SET_BIT(ah, AR_PHY_TEST, RFSILENT_BB);
2865}
2866#endif
2867
2868u32 ath9k_hw_gpio_get(struct ath_hal *ah, u32 gpio)
2869{
2870 if (gpio >= ah->ah_caps.num_gpio_pins)
2871 return 0xffffffff;
2872
2873 if (AR_SREV_9280_10_OR_LATER(ah)) {
2874 return (MS
2875 (REG_READ(ah, AR_GPIO_IN_OUT),
2876 AR928X_GPIO_IN_VAL) & AR_GPIO_BIT(gpio)) != 0;
2877 } else {
2878 return (MS(REG_READ(ah, AR_GPIO_IN_OUT), AR_GPIO_IN_VAL) &
2879 AR_GPIO_BIT(gpio)) != 0;
2880 }
2881}
2882
2883static int ath9k_hw_post_attach(struct ath_hal *ah) 559static int ath9k_hw_post_attach(struct ath_hal *ah)
2884{ 560{
2885 int ecode; 561 int ecode;
2886 562
2887 if (!ath9k_hw_chip_test(ah)) { 563 if (!ath9k_hw_chip_test(ah)) {
2888 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO, 564 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
2889 "%s: hardware self-test failed\n", __func__); 565 "%s: hardware self-test failed\n", __func__);
2890 return -ENODEV; 566 return -ENODEV;
2891 } 567 }
2892 568
@@ -2905,357 +581,12 @@ static int ath9k_hw_post_attach(struct ath_hal *ah)
2905 ath9k_hw_ani_setup(ah); 581 ath9k_hw_ani_setup(ah);
2906 ath9k_hw_ani_attach(ah); 582 ath9k_hw_ani_attach(ah);
2907 } 583 }
2908 return 0;
2909}
2910
2911static u32 ath9k_hw_ini_fixup(struct ath_hal *ah,
2912 struct ar5416_eeprom *pEepData,
2913 u32 reg, u32 value)
2914{
2915 struct base_eep_header *pBase = &(pEepData->baseEepHeader);
2916
2917 switch (ah->ah_devid) {
2918 case AR9280_DEVID_PCI:
2919 if (reg == 0x7894) {
2920 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
2921 "ini VAL: %x EEPROM: %x\n", value,
2922 (pBase->version & 0xff));
2923
2924 if ((pBase->version & 0xff) > 0x0a) {
2925 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
2926 "PWDCLKIND: %d\n",
2927 pBase->pwdclkind);
2928 value &= ~AR_AN_TOP2_PWDCLKIND;
2929 value |= AR_AN_TOP2_PWDCLKIND & (pBase->
2930 pwdclkind << AR_AN_TOP2_PWDCLKIND_S);
2931 } else {
2932 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
2933 "PWDCLKIND Earlier Rev\n");
2934 }
2935
2936 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
2937 "final ini VAL: %x\n", value);
2938 }
2939 break;
2940 }
2941 return value;
2942}
2943
2944static bool ath9k_hw_fill_cap_info(struct ath_hal *ah)
2945{
2946 struct ath_hal_5416 *ahp = AH5416(ah);
2947 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
2948 u16 capField = 0, eeval;
2949
2950 eeval = ath9k_hw_get_eeprom(ahp, EEP_REG_0);
2951
2952 ah->ah_currentRD = eeval;
2953
2954 eeval = ath9k_hw_get_eeprom(ahp, EEP_REG_1);
2955 ah->ah_currentRDExt = eeval;
2956
2957 capField = ath9k_hw_get_eeprom(ahp, EEP_OP_CAP);
2958
2959 if (ah->ah_opmode != ATH9K_M_HOSTAP &&
2960 ah->ah_subvendorid == AR_SUBVENDOR_ID_NEW_A) {
2961 if (ah->ah_currentRD == 0x64 || ah->ah_currentRD == 0x65)
2962 ah->ah_currentRD += 5;
2963 else if (ah->ah_currentRD == 0x41)
2964 ah->ah_currentRD = 0x43;
2965 DPRINTF(ah->ah_sc, ATH_DBG_REGULATORY,
2966 "%s: regdomain mapped to 0x%x\n", __func__,
2967 ah->ah_currentRD);
2968 }
2969
2970 eeval = ath9k_hw_get_eeprom(ahp, EEP_OP_MODE);
2971 bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX);
2972 584
2973 if (eeval & AR5416_OPFLAGS_11A) { 585 return 0;
2974 set_bit(ATH9K_MODE_11A, pCap->wireless_modes);
2975 if (ah->ah_config.ht_enable) {
2976 if (!(eeval & AR5416_OPFLAGS_N_5G_HT20))
2977 set_bit(ATH9K_MODE_11NA_HT20,
2978 pCap->wireless_modes);
2979 if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) {
2980 set_bit(ATH9K_MODE_11NA_HT40PLUS,
2981 pCap->wireless_modes);
2982 set_bit(ATH9K_MODE_11NA_HT40MINUS,
2983 pCap->wireless_modes);
2984 }
2985 }
2986 }
2987
2988 if (eeval & AR5416_OPFLAGS_11G) {
2989 set_bit(ATH9K_MODE_11B, pCap->wireless_modes);
2990 set_bit(ATH9K_MODE_11G, pCap->wireless_modes);
2991 if (ah->ah_config.ht_enable) {
2992 if (!(eeval & AR5416_OPFLAGS_N_2G_HT20))
2993 set_bit(ATH9K_MODE_11NG_HT20,
2994 pCap->wireless_modes);
2995 if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) {
2996 set_bit(ATH9K_MODE_11NG_HT40PLUS,
2997 pCap->wireless_modes);
2998 set_bit(ATH9K_MODE_11NG_HT40MINUS,
2999 pCap->wireless_modes);
3000 }
3001 }
3002 }
3003
3004 pCap->tx_chainmask = ath9k_hw_get_eeprom(ahp, EEP_TX_MASK);
3005 if ((ah->ah_isPciExpress)
3006 || (eeval & AR5416_OPFLAGS_11A)) {
3007 pCap->rx_chainmask =
3008 ath9k_hw_get_eeprom(ahp, EEP_RX_MASK);
3009 } else {
3010 pCap->rx_chainmask =
3011 (ath9k_hw_gpio_get(ah, 0)) ? 0x5 : 0x7;
3012 }
3013
3014 if (!(AR_SREV_9280(ah) && (ah->ah_macRev == 0)))
3015 ahp->ah_miscMode |= AR_PCU_MIC_NEW_LOC_ENA;
3016
3017 pCap->low_2ghz_chan = 2312;
3018 pCap->high_2ghz_chan = 2732;
3019
3020 pCap->low_5ghz_chan = 4920;
3021 pCap->high_5ghz_chan = 6100;
3022
3023 pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP;
3024 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP;
3025 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM;
3026
3027 pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP;
3028 pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP;
3029 pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM;
3030
3031 pCap->hw_caps |= ATH9K_HW_CAP_CHAN_SPREAD;
3032
3033 if (ah->ah_config.ht_enable)
3034 pCap->hw_caps |= ATH9K_HW_CAP_HT;
3035 else
3036 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
3037
3038 pCap->hw_caps |= ATH9K_HW_CAP_GTT;
3039 pCap->hw_caps |= ATH9K_HW_CAP_VEOL;
3040 pCap->hw_caps |= ATH9K_HW_CAP_BSSIDMASK;
3041 pCap->hw_caps &= ~ATH9K_HW_CAP_MCAST_KEYSEARCH;
3042
3043 if (capField & AR_EEPROM_EEPCAP_MAXQCU)
3044 pCap->total_queues =
3045 MS(capField, AR_EEPROM_EEPCAP_MAXQCU);
3046 else
3047 pCap->total_queues = ATH9K_NUM_TX_QUEUES;
3048
3049 if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES)
3050 pCap->keycache_size =
3051 1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES);
3052 else
3053 pCap->keycache_size = AR_KEYTABLE_SIZE;
3054
3055 pCap->hw_caps |= ATH9K_HW_CAP_FASTCC;
3056 pCap->num_mr_retries = 4;
3057 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD;
3058
3059 if (AR_SREV_9280_10_OR_LATER(ah))
3060 pCap->num_gpio_pins = AR928X_NUM_GPIO;
3061 else
3062 pCap->num_gpio_pins = AR_NUM_GPIO;
3063
3064 if (AR_SREV_9280_10_OR_LATER(ah)) {
3065 pCap->hw_caps |= ATH9K_HW_CAP_WOW;
3066 pCap->hw_caps |= ATH9K_HW_CAP_WOW_MATCHPATTERN_EXACT;
3067 } else {
3068 pCap->hw_caps &= ~ATH9K_HW_CAP_WOW;
3069 pCap->hw_caps &= ~ATH9K_HW_CAP_WOW_MATCHPATTERN_EXACT;
3070 }
3071
3072 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) {
3073 pCap->hw_caps |= ATH9K_HW_CAP_CST;
3074 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
3075 } else {
3076 pCap->rts_aggr_limit = (8 * 1024);
3077 }
3078
3079 pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM;
3080
3081#ifdef CONFIG_RFKILL
3082 ah->ah_rfsilent = ath9k_hw_get_eeprom(ahp, EEP_RF_SILENT);
3083 if (ah->ah_rfsilent & EEP_RFSILENT_ENABLED) {
3084 ah->ah_rfkill_gpio =
3085 MS(ah->ah_rfsilent, EEP_RFSILENT_GPIO_SEL);
3086 ah->ah_rfkill_polarity =
3087 MS(ah->ah_rfsilent, EEP_RFSILENT_POLARITY);
3088
3089 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
3090 }
3091#endif
3092
3093 if ((ah->ah_macVersion == AR_SREV_VERSION_5416_PCI) ||
3094 (ah->ah_macVersion == AR_SREV_VERSION_5416_PCIE) ||
3095 (ah->ah_macVersion == AR_SREV_VERSION_9160) ||
3096 (ah->ah_macVersion == AR_SREV_VERSION_9100) ||
3097 (ah->ah_macVersion == AR_SREV_VERSION_9280))
3098 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
3099 else
3100 pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP;
3101
3102 if (AR_SREV_9280(ah))
3103 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
3104 else
3105 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
3106
3107 if (ah->ah_currentRDExt & (1 << REG_EXT_JAPAN_MIDBAND)) {
3108 pCap->reg_cap =
3109 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3110 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN |
3111 AR_EEPROM_EEREGCAP_EN_KK_U2 |
3112 AR_EEPROM_EEREGCAP_EN_KK_MIDBAND;
3113 } else {
3114 pCap->reg_cap =
3115 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3116 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN;
3117 }
3118
3119 pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND;
3120
3121 pCap->num_antcfg_5ghz =
3122 ath9k_hw_get_num_ant_config(ahp, IEEE80211_BAND_5GHZ);
3123 pCap->num_antcfg_2ghz =
3124 ath9k_hw_get_num_ant_config(ahp, IEEE80211_BAND_2GHZ);
3125
3126 return true;
3127}
3128
3129static void ar5416DisablePciePhy(struct ath_hal *ah)
3130{
3131 if (!AR_SREV_9100(ah))
3132 return;
3133
3134 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
3135 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
3136 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
3137 REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
3138 REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
3139 REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
3140 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
3141 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
3142 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
3143
3144 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
3145}
3146
3147static void ath9k_set_power_sleep(struct ath_hal *ah, int setChip)
3148{
3149 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
3150 if (setChip) {
3151 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
3152 AR_RTC_FORCE_WAKE_EN);
3153 if (!AR_SREV_9100(ah))
3154 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
3155
3156 REG_CLR_BIT(ah, (u16) (AR_RTC_RESET),
3157 AR_RTC_RESET_EN);
3158 }
3159}
3160
3161static void ath9k_set_power_network_sleep(struct ath_hal *ah, int setChip)
3162{
3163 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
3164 if (setChip) {
3165 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
3166
3167 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
3168 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
3169 AR_RTC_FORCE_WAKE_ON_INT);
3170 } else {
3171 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
3172 AR_RTC_FORCE_WAKE_EN);
3173 }
3174 }
3175}
3176
3177static bool ath9k_hw_set_power_awake(struct ath_hal *ah,
3178 int setChip)
3179{
3180 u32 val;
3181 int i;
3182
3183 if (setChip) {
3184 if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M) ==
3185 AR_RTC_STATUS_SHUTDOWN) {
3186 if (ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)
3187 != true) {
3188 return false;
3189 }
3190 }
3191 if (AR_SREV_9100(ah))
3192 REG_SET_BIT(ah, AR_RTC_RESET,
3193 AR_RTC_RESET_EN);
3194
3195 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
3196 AR_RTC_FORCE_WAKE_EN);
3197 udelay(50);
3198
3199 for (i = POWER_UP_TIME / 50; i > 0; i--) {
3200 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
3201 if (val == AR_RTC_STATUS_ON)
3202 break;
3203 udelay(50);
3204 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
3205 AR_RTC_FORCE_WAKE_EN);
3206 }
3207 if (i == 0) {
3208 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
3209 "%s: Failed to wakeup in %uus\n",
3210 __func__, POWER_UP_TIME / 20);
3211 return false;
3212 }
3213 }
3214
3215 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
3216 return true;
3217}
3218
3219bool ath9k_hw_setpower(struct ath_hal *ah,
3220 enum ath9k_power_mode mode)
3221{
3222 struct ath_hal_5416 *ahp = AH5416(ah);
3223 static const char *modes[] = {
3224 "AWAKE",
3225 "FULL-SLEEP",
3226 "NETWORK SLEEP",
3227 "UNDEFINED"
3228 };
3229 int status = true, setChip = true;
3230
3231 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT, "%s: %s -> %s (%s)\n", __func__,
3232 modes[ahp->ah_powerMode], modes[mode],
3233 setChip ? "set chip " : "");
3234
3235 switch (mode) {
3236 case ATH9K_PM_AWAKE:
3237 status = ath9k_hw_set_power_awake(ah, setChip);
3238 break;
3239 case ATH9K_PM_FULL_SLEEP:
3240 ath9k_set_power_sleep(ah, setChip);
3241 ahp->ah_chipFullSleep = true;
3242 break;
3243 case ATH9K_PM_NETWORK_SLEEP:
3244 ath9k_set_power_network_sleep(ah, setChip);
3245 break;
3246 default:
3247 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
3248 "%s: unknown power mode %u\n", __func__, mode);
3249 return false;
3250 }
3251 ahp->ah_powerMode = mode;
3252 return status;
3253} 586}
3254 587
3255static struct ath_hal *ath9k_hw_do_attach(u16 devid, 588static struct ath_hal *ath9k_hw_do_attach(u16 devid, struct ath_softc *sc,
3256 struct ath_softc *sc, 589 void __iomem *mem, int *status)
3257 void __iomem *mem,
3258 int *status)
3259{ 590{
3260 struct ath_hal_5416 *ahp; 591 struct ath_hal_5416 *ahp;
3261 struct ath_hal *ah; 592 struct ath_hal *ah;
@@ -3299,6 +630,7 @@ static struct ath_hal *ath9k_hw_do_attach(u16 devid,
3299 SER_REG_MODE_OFF; 630 SER_REG_MODE_OFF;
3300 } 631 }
3301 } 632 }
633
3302 DPRINTF(ah->ah_sc, ATH_DBG_RESET, 634 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
3303 "%s: serialize_regmode is %d\n", 635 "%s: serialize_regmode is %d\n",
3304 __func__, ah->ah_config.serialize_regmode); 636 __func__, ah->ah_config.serialize_regmode);
@@ -3308,9 +640,9 @@ static struct ath_hal *ath9k_hw_do_attach(u16 devid,
3308 (ah->ah_macVersion != AR_SREV_VERSION_9160) && 640 (ah->ah_macVersion != AR_SREV_VERSION_9160) &&
3309 (!AR_SREV_9100(ah)) && (!AR_SREV_9280(ah))) { 641 (!AR_SREV_9100(ah)) && (!AR_SREV_9280(ah))) {
3310 DPRINTF(ah->ah_sc, ATH_DBG_RESET, 642 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
3311 "%s: Mac Chip Rev 0x%02x.%x is not supported by " 643 "%s: Mac Chip Rev 0x%02x.%x is not supported by "
3312 "this driver\n", __func__, 644 "this driver\n", __func__,
3313 ah->ah_macVersion, ah->ah_macRev); 645 ah->ah_macVersion, ah->ah_macRev);
3314 ecode = -EOPNOTSUPP; 646 ecode = -EOPNOTSUPP;
3315 goto bad; 647 goto bad;
3316 } 648 }
@@ -3340,8 +672,7 @@ static struct ath_hal *ath9k_hw_do_attach(u16 devid,
3340 ahp->ah_adcDcCalInitData.calData = 672 ahp->ah_adcDcCalInitData.calData =
3341 &adc_init_dc_cal; 673 &adc_init_dc_cal;
3342 } 674 }
3343 ahp->ah_suppCals = 675 ahp->ah_suppCals = ADC_GAIN_CAL | ADC_DC_CAL | IQ_MISMATCH_CAL;
3344 ADC_GAIN_CAL | ADC_DC_CAL | IQ_MISMATCH_CAL;
3345 } 676 }
3346 677
3347 if (AR_SREV_9160(ah)) { 678 if (AR_SREV_9160(ah)) {
@@ -3351,14 +682,13 @@ static struct ath_hal *ath9k_hw_do_attach(u16 devid,
3351 } else { 682 } else {
3352 ahp->ah_ani_function = ATH9K_ANI_ALL; 683 ahp->ah_ani_function = ATH9K_ANI_ALL;
3353 if (AR_SREV_9280_10_OR_LATER(ah)) { 684 if (AR_SREV_9280_10_OR_LATER(ah)) {
3354 ahp->ah_ani_function &= 685 ahp->ah_ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
3355 ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
3356 } 686 }
3357 } 687 }
3358 688
3359 DPRINTF(ah->ah_sc, ATH_DBG_RESET, 689 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
3360 "%s: This Mac Chip Rev 0x%02x.%x is \n", __func__, 690 "%s: This Mac Chip Rev 0x%02x.%x is \n", __func__,
3361 ah->ah_macVersion, ah->ah_macRev); 691 ah->ah_macVersion, ah->ah_macRev);
3362 692
3363 if (AR_SREV_9280_20_OR_LATER(ah)) { 693 if (AR_SREV_9280_20_OR_LATER(ah)) {
3364 INIT_INI_ARRAY(&ahp->ah_iniModes, ar9280Modes_9280_2, 694 INIT_INI_ARRAY(&ahp->ah_iniModes, ar9280Modes_9280_2,
@@ -3368,21 +698,16 @@ static struct ath_hal *ath9k_hw_do_attach(u16 devid,
3368 698
3369 if (ah->ah_config.pcie_clock_req) { 699 if (ah->ah_config.pcie_clock_req) {
3370 INIT_INI_ARRAY(&ahp->ah_iniPcieSerdes, 700 INIT_INI_ARRAY(&ahp->ah_iniPcieSerdes,
3371 ar9280PciePhy_clkreq_off_L1_9280, 701 ar9280PciePhy_clkreq_off_L1_9280,
3372 ARRAY_SIZE 702 ARRAY_SIZE(ar9280PciePhy_clkreq_off_L1_9280),2);
3373 (ar9280PciePhy_clkreq_off_L1_9280),
3374 2);
3375 } else { 703 } else {
3376 INIT_INI_ARRAY(&ahp->ah_iniPcieSerdes, 704 INIT_INI_ARRAY(&ahp->ah_iniPcieSerdes,
3377 ar9280PciePhy_clkreq_always_on_L1_9280, 705 ar9280PciePhy_clkreq_always_on_L1_9280,
3378 ARRAY_SIZE 706 ARRAY_SIZE(ar9280PciePhy_clkreq_always_on_L1_9280), 2);
3379 (ar9280PciePhy_clkreq_always_on_L1_9280),
3380 2);
3381 } 707 }
3382 INIT_INI_ARRAY(&ahp->ah_iniModesAdditional, 708 INIT_INI_ARRAY(&ahp->ah_iniModesAdditional,
3383 ar9280Modes_fast_clock_9280_2, 709 ar9280Modes_fast_clock_9280_2,
3384 ARRAY_SIZE(ar9280Modes_fast_clock_9280_2), 710 ARRAY_SIZE(ar9280Modes_fast_clock_9280_2), 3);
3385 3);
3386 } else if (AR_SREV_9280_10_OR_LATER(ah)) { 711 } else if (AR_SREV_9280_10_OR_LATER(ah)) {
3387 INIT_INI_ARRAY(&ahp->ah_iniModes, ar9280Modes_9280, 712 INIT_INI_ARRAY(&ahp->ah_iniModes, ar9280Modes_9280,
3388 ARRAY_SIZE(ar9280Modes_9280), 6); 713 ARRAY_SIZE(ar9280Modes_9280), 6);
@@ -3468,7 +793,7 @@ static struct ath_hal *ath9k_hw_do_attach(u16 devid,
3468 if (ah->ah_isPciExpress) 793 if (ah->ah_isPciExpress)
3469 ath9k_hw_configpcipowersave(ah, 0); 794 ath9k_hw_configpcipowersave(ah, 0);
3470 else 795 else
3471 ar5416DisablePciePhy(ah); 796 ath9k_hw_disablepcie(ah);
3472 797
3473 ecode = ath9k_hw_post_attach(ah); 798 ecode = ath9k_hw_post_attach(ah);
3474 if (ecode != 0) 799 if (ecode != 0)
@@ -3489,10 +814,9 @@ static struct ath_hal *ath9k_hw_do_attach(u16 devid,
3489 } 814 }
3490 } 815 }
3491#endif 816#endif
3492
3493 if (!ath9k_hw_fill_cap_info(ah)) { 817 if (!ath9k_hw_fill_cap_info(ah)) {
3494 DPRINTF(ah->ah_sc, ATH_DBG_RESET, 818 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
3495 "%s:failed ath9k_hw_fill_cap_info\n", __func__); 819 "%s:failed ath9k_hw_fill_cap_info\n", __func__);
3496 ecode = -EINVAL; 820 ecode = -EINVAL;
3497 goto bad; 821 goto bad;
3498 } 822 }
@@ -3500,8 +824,8 @@ static struct ath_hal *ath9k_hw_do_attach(u16 devid,
3500 ecode = ath9k_hw_init_macaddr(ah); 824 ecode = ath9k_hw_init_macaddr(ah);
3501 if (ecode != 0) { 825 if (ecode != 0) {
3502 DPRINTF(ah->ah_sc, ATH_DBG_RESET, 826 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
3503 "%s: failed initializing mac address\n", 827 "%s: failed initializing mac address\n",
3504 __func__); 828 __func__);
3505 goto bad; 829 goto bad;
3506 } 830 }
3507 831
@@ -3510,1106 +834,553 @@ static struct ath_hal *ath9k_hw_do_attach(u16 devid,
3510 else 834 else
3511 ah->ah_txTrigLevel = (AR_FTRIG_512B >> AR_FTRIG_S); 835 ah->ah_txTrigLevel = (AR_FTRIG_512B >> AR_FTRIG_S);
3512 836
3513#ifndef ATH_NF_PER_CHAN
3514
3515 ath9k_init_nfcal_hist_buffer(ah); 837 ath9k_init_nfcal_hist_buffer(ah);
3516#endif
3517 838
3518 return ah; 839 return ah;
3519
3520bad: 840bad:
3521 if (ahp) 841 if (ahp)
3522 ath9k_hw_detach((struct ath_hal *) ahp); 842 ath9k_hw_detach((struct ath_hal *) ahp);
3523 if (status) 843 if (status)
3524 *status = ecode; 844 *status = ecode;
845
3525 return NULL; 846 return NULL;
3526} 847}
3527 848
3528void ath9k_hw_detach(struct ath_hal *ah) 849static void ath9k_hw_init_bb(struct ath_hal *ah,
850 struct ath9k_channel *chan)
3529{ 851{
3530 if (!AR_SREV_9100(ah)) 852 u32 synthDelay;
3531 ath9k_hw_ani_detach(ah);
3532 ath9k_hw_rfdetach(ah);
3533 853
3534 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP); 854 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
3535 kfree(ah); 855 if (IS_CHAN_CCK(chan))
856 synthDelay = (4 * synthDelay) / 22;
857 else
858 synthDelay /= 10;
859
860 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
861
862 udelay(synthDelay + BASE_ACTIVATE_DELAY);
3536} 863}
3537 864
3538bool ath9k_get_channel_edges(struct ath_hal *ah, 865static void ath9k_hw_init_qos(struct ath_hal *ah)
3539 u16 flags, u16 *low,
3540 u16 *high)
3541{ 866{
3542 struct ath9k_hw_capabilities *pCap = &ah->ah_caps; 867 REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
868 REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
3543 869
3544 if (flags & CHANNEL_5GHZ) { 870 REG_WRITE(ah, AR_QOS_NO_ACK,
3545 *low = pCap->low_5ghz_chan; 871 SM(2, AR_QOS_NO_ACK_TWO_BIT) |
3546 *high = pCap->high_5ghz_chan; 872 SM(5, AR_QOS_NO_ACK_BIT_OFF) |
3547 return true; 873 SM(0, AR_QOS_NO_ACK_BYTE_OFF));
3548 }
3549 if ((flags & CHANNEL_2GHZ)) {
3550 *low = pCap->low_2ghz_chan;
3551 *high = pCap->high_2ghz_chan;
3552 874
3553 return true; 875 REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
3554 } 876 REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
3555 return false; 877 REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
878 REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
879 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
3556} 880}
3557 881
3558static inline bool ath9k_hw_fill_vpd_table(u8 pwrMin, 882static void ath9k_hw_init_pll(struct ath_hal *ah,
3559 u8 pwrMax, 883 struct ath9k_channel *chan)
3560 u8 *pPwrList,
3561 u8 *pVpdList,
3562 u16
3563 numIntercepts,
3564 u8 *pRetVpdList)
3565{ 884{
3566 u16 i, k; 885 u32 pll;
3567 u8 currPwr = pwrMin;
3568 u16 idxL = 0, idxR = 0;
3569
3570 for (i = 0; i <= (pwrMax - pwrMin) / 2; i++) {
3571 ath9k_hw_get_lower_upper_index(currPwr, pPwrList,
3572 numIntercepts, &(idxL),
3573 &(idxR));
3574 if (idxR < 1)
3575 idxR = 1;
3576 if (idxL == numIntercepts - 1)
3577 idxL = (u16) (numIntercepts - 2);
3578 if (pPwrList[idxL] == pPwrList[idxR])
3579 k = pVpdList[idxL];
3580 else
3581 k = (u16) (((currPwr -
3582 pPwrList[idxL]) *
3583 pVpdList[idxR] +
3584 (pPwrList[idxR] -
3585 currPwr) * pVpdList[idxL]) /
3586 (pPwrList[idxR] -
3587 pPwrList[idxL]));
3588 pRetVpdList[i] = (u8) k;
3589 currPwr += 2;
3590 }
3591 886
3592 return true; 887 if (AR_SREV_9100(ah)) {
3593} 888 if (chan && IS_CHAN_5GHZ(chan))
889 pll = 0x1450;
890 else
891 pll = 0x1458;
892 } else {
893 if (AR_SREV_9280_10_OR_LATER(ah)) {
894 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
3594 895
3595static void 896 if (chan && IS_CHAN_HALF_RATE(chan))
3596ath9k_hw_get_gain_boundaries_pdadcs(struct ath_hal *ah, 897 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
3597 struct ath9k_channel *chan, 898 else if (chan && IS_CHAN_QUARTER_RATE(chan))
3598 struct cal_data_per_freq *pRawDataSet, 899 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
3599 u8 *bChans,
3600 u16 availPiers,
3601 u16 tPdGainOverlap,
3602 int16_t *pMinCalPower,
3603 u16 *pPdGainBoundaries,
3604 u8 *pPDADCValues,
3605 u16 numXpdGains)
3606{
3607 int i, j, k;
3608 int16_t ss;
3609 u16 idxL = 0, idxR = 0, numPiers;
3610 static u8 vpdTableL[AR5416_NUM_PD_GAINS]
3611 [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
3612 static u8 vpdTableR[AR5416_NUM_PD_GAINS]
3613 [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
3614 static u8 vpdTableI[AR5416_NUM_PD_GAINS]
3615 [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
3616
3617 u8 *pVpdL, *pVpdR, *pPwrL, *pPwrR;
3618 u8 minPwrT4[AR5416_NUM_PD_GAINS];
3619 u8 maxPwrT4[AR5416_NUM_PD_GAINS];
3620 int16_t vpdStep;
3621 int16_t tmpVal;
3622 u16 sizeCurrVpdTable, maxIndex, tgtIndex;
3623 bool match;
3624 int16_t minDelta = 0;
3625 struct chan_centers centers;
3626 900
3627 ath9k_hw_get_channel_centers(ah, chan, &centers); 901 if (chan && IS_CHAN_5GHZ(chan)) {
902 pll |= SM(0x28, AR_RTC_9160_PLL_DIV);
3628 903
3629 for (numPiers = 0; numPiers < availPiers; numPiers++) {
3630 if (bChans[numPiers] == AR5416_BCHAN_UNUSED)
3631 break;
3632 }
3633 904
3634 match = ath9k_hw_get_lower_upper_index((u8) 905 if (AR_SREV_9280_20(ah)) {
3635 FREQ2FBIN(centers. 906 if (((chan->channel % 20) == 0)
3636 synth_center, 907 || ((chan->channel % 10) == 0))
3637 IS_CHAN_2GHZ 908 pll = 0x2850;
3638 (chan)), bChans, 909 else
3639 numPiers, &idxL, &idxR); 910 pll = 0x142c;
3640 911 }
3641 if (match) { 912 } else {
3642 for (i = 0; i < numXpdGains; i++) { 913 pll |= SM(0x2c, AR_RTC_9160_PLL_DIV);
3643 minPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][0];
3644 maxPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][4];
3645 ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
3646 pRawDataSet[idxL].
3647 pwrPdg[i],
3648 pRawDataSet[idxL].
3649 vpdPdg[i],
3650 AR5416_PD_GAIN_ICEPTS,
3651 vpdTableI[i]);
3652 }
3653 } else {
3654 for (i = 0; i < numXpdGains; i++) {
3655 pVpdL = pRawDataSet[idxL].vpdPdg[i];
3656 pPwrL = pRawDataSet[idxL].pwrPdg[i];
3657 pVpdR = pRawDataSet[idxR].vpdPdg[i];
3658 pPwrR = pRawDataSet[idxR].pwrPdg[i];
3659
3660 minPwrT4[i] = max(pPwrL[0], pPwrR[0]);
3661
3662 maxPwrT4[i] =
3663 min(pPwrL[AR5416_PD_GAIN_ICEPTS - 1],
3664 pPwrR[AR5416_PD_GAIN_ICEPTS - 1]);
3665
3666
3667 ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
3668 pPwrL, pVpdL,
3669 AR5416_PD_GAIN_ICEPTS,
3670 vpdTableL[i]);
3671 ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
3672 pPwrR, pVpdR,
3673 AR5416_PD_GAIN_ICEPTS,
3674 vpdTableR[i]);
3675
3676 for (j = 0; j <= (maxPwrT4[i] - minPwrT4[i]) / 2; j++) {
3677 vpdTableI[i][j] =
3678 (u8) (ath9k_hw_interpolate
3679 ((u16)
3680 FREQ2FBIN(centers.
3681 synth_center,
3682 IS_CHAN_2GHZ
3683 (chan)),
3684 bChans[idxL],
3685 bChans[idxR], vpdTableL[i]
3686 [j], vpdTableR[i]
3687 [j]));
3688 } 914 }
3689 }
3690 }
3691 915
3692 *pMinCalPower = (int16_t) (minPwrT4[0] / 2); 916 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
3693
3694 k = 0;
3695 for (i = 0; i < numXpdGains; i++) {
3696 if (i == (numXpdGains - 1))
3697 pPdGainBoundaries[i] =
3698 (u16) (maxPwrT4[i] / 2);
3699 else
3700 pPdGainBoundaries[i] =
3701 (u16) ((maxPwrT4[i] +
3702 minPwrT4[i + 1]) / 4);
3703 917
3704 pPdGainBoundaries[i] = 918 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
3705 min((u16) AR5416_MAX_RATE_POWER,
3706 pPdGainBoundaries[i]);
3707 919
3708 if ((i == 0) && !AR_SREV_5416_V20_OR_LATER(ah)) { 920 if (chan && IS_CHAN_HALF_RATE(chan))
3709 minDelta = pPdGainBoundaries[0] - 23; 921 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
3710 pPdGainBoundaries[0] = 23; 922 else if (chan && IS_CHAN_QUARTER_RATE(chan))
3711 } else { 923 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
3712 minDelta = 0;
3713 }
3714 924
3715 if (i == 0) { 925 if (chan && IS_CHAN_5GHZ(chan))
3716 if (AR_SREV_9280_10_OR_LATER(ah)) 926 pll |= SM(0x50, AR_RTC_9160_PLL_DIV);
3717 ss = (int16_t) (0 - (minPwrT4[i] / 2));
3718 else 927 else
3719 ss = 0; 928 pll |= SM(0x58, AR_RTC_9160_PLL_DIV);
3720 } else { 929 } else {
3721 ss = (int16_t) ((pPdGainBoundaries[i - 1] - 930 pll = AR_RTC_PLL_REFDIV_5 | AR_RTC_PLL_DIV2;
3722 (minPwrT4[i] / 2)) -
3723 tPdGainOverlap + 1 + minDelta);
3724 }
3725 vpdStep = (int16_t) (vpdTableI[i][1] - vpdTableI[i][0]);
3726 vpdStep = (int16_t) ((vpdStep < 1) ? 1 : vpdStep);
3727
3728 while ((ss < 0) && (k < (AR5416_NUM_PDADC_VALUES - 1))) {
3729 tmpVal = (int16_t) (vpdTableI[i][0] + ss * vpdStep);
3730 pPDADCValues[k++] =
3731 (u8) ((tmpVal < 0) ? 0 : tmpVal);
3732 ss++;
3733 }
3734
3735 sizeCurrVpdTable =
3736 (u8) ((maxPwrT4[i] - minPwrT4[i]) / 2 + 1);
3737 tgtIndex = (u8) (pPdGainBoundaries[i] + tPdGainOverlap -
3738 (minPwrT4[i] / 2));
3739 maxIndex = (tgtIndex <
3740 sizeCurrVpdTable) ? tgtIndex : sizeCurrVpdTable;
3741 931
3742 while ((ss < maxIndex) 932 if (chan && IS_CHAN_HALF_RATE(chan))
3743 && (k < (AR5416_NUM_PDADC_VALUES - 1))) { 933 pll |= SM(0x1, AR_RTC_PLL_CLKSEL);
3744 pPDADCValues[k++] = vpdTableI[i][ss++]; 934 else if (chan && IS_CHAN_QUARTER_RATE(chan))
3745 } 935 pll |= SM(0x2, AR_RTC_PLL_CLKSEL);
3746 936
3747 vpdStep = (int16_t) (vpdTableI[i][sizeCurrVpdTable - 1] - 937 if (chan && IS_CHAN_5GHZ(chan))
3748 vpdTableI[i][sizeCurrVpdTable - 2]); 938 pll |= SM(0xa, AR_RTC_PLL_DIV);
3749 vpdStep = (int16_t) ((vpdStep < 1) ? 1 : vpdStep); 939 else
3750 940 pll |= SM(0xb, AR_RTC_PLL_DIV);
3751 if (tgtIndex > maxIndex) {
3752 while ((ss <= tgtIndex)
3753 && (k < (AR5416_NUM_PDADC_VALUES - 1))) {
3754 tmpVal = (int16_t) ((vpdTableI[i]
3755 [sizeCurrVpdTable -
3756 1] + (ss - maxIndex +
3757 1) * vpdStep));
3758 pPDADCValues[k++] = (u8) ((tmpVal >
3759 255) ? 255 : tmpVal);
3760 ss++;
3761 }
3762 } 941 }
3763 } 942 }
943 REG_WRITE(ah, (u16) (AR_RTC_PLL_CONTROL), pll);
3764 944
3765 while (i < AR5416_PD_GAINS_IN_MASK) { 945 udelay(RTC_PLL_SETTLE_DELAY);
3766 pPdGainBoundaries[i] = pPdGainBoundaries[i - 1];
3767 i++;
3768 }
3769 946
3770 while (k < AR5416_NUM_PDADC_VALUES) { 947 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
3771 pPDADCValues[k] = pPDADCValues[k - 1];
3772 k++;
3773 }
3774 return;
3775} 948}
3776 949
3777static bool 950static void ath9k_hw_init_chain_masks(struct ath_hal *ah)
3778ath9k_hw_set_power_cal_table(struct ath_hal *ah,
3779 struct ar5416_eeprom *pEepData,
3780 struct ath9k_channel *chan,
3781 int16_t *pTxPowerIndexOffset)
3782{ 951{
3783 struct cal_data_per_freq *pRawDataset;
3784 u8 *pCalBChans = NULL;
3785 u16 pdGainOverlap_t2;
3786 static u8 pdadcValues[AR5416_NUM_PDADC_VALUES];
3787 u16 gainBoundaries[AR5416_PD_GAINS_IN_MASK];
3788 u16 numPiers, i, j;
3789 int16_t tMinCalPower;
3790 u16 numXpdGain, xpdMask;
3791 u16 xpdGainValues[AR5416_NUM_PD_GAINS] = { 0, 0, 0, 0 };
3792 u32 reg32, regOffset, regChainOffset;
3793 int16_t modalIdx;
3794 struct ath_hal_5416 *ahp = AH5416(ah); 952 struct ath_hal_5416 *ahp = AH5416(ah);
953 int rx_chainmask, tx_chainmask;
3795 954
3796 modalIdx = IS_CHAN_2GHZ(chan) ? 1 : 0; 955 rx_chainmask = ahp->ah_rxchainmask;
3797 xpdMask = pEepData->modalHeader[modalIdx].xpdGain; 956 tx_chainmask = ahp->ah_txchainmask;
3798
3799 if ((pEepData->baseEepHeader.
3800 version & AR5416_EEP_VER_MINOR_MASK) >=
3801 AR5416_EEP_MINOR_VER_2) {
3802 pdGainOverlap_t2 =
3803 pEepData->modalHeader[modalIdx].pdGainOverlap;
3804 } else {
3805 pdGainOverlap_t2 =
3806 (u16) (MS
3807 (REG_READ(ah, AR_PHY_TPCRG5),
3808 AR_PHY_TPCRG5_PD_GAIN_OVERLAP));
3809 }
3810
3811 if (IS_CHAN_2GHZ(chan)) {
3812 pCalBChans = pEepData->calFreqPier2G;
3813 numPiers = AR5416_NUM_2G_CAL_PIERS;
3814 } else {
3815 pCalBChans = pEepData->calFreqPier5G;
3816 numPiers = AR5416_NUM_5G_CAL_PIERS;
3817 }
3818
3819 numXpdGain = 0;
3820 957
3821 for (i = 1; i <= AR5416_PD_GAINS_IN_MASK; i++) { 958 switch (rx_chainmask) {
3822 if ((xpdMask >> (AR5416_PD_GAINS_IN_MASK - i)) & 1) { 959 case 0x5:
3823 if (numXpdGain >= AR5416_NUM_PD_GAINS) 960 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
3824 break; 961 AR_PHY_SWAP_ALT_CHAIN);
3825 xpdGainValues[numXpdGain] = 962 case 0x3:
3826 (u16) (AR5416_PD_GAINS_IN_MASK - i); 963 if (((ah)->ah_macVersion <= AR_SREV_VERSION_9160)) {
3827 numXpdGain++; 964 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, 0x7);
965 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, 0x7);
966 break;
3828 } 967 }
968 case 0x1:
969 case 0x2:
970 if (!AR_SREV_9280(ah))
971 break;
972 case 0x7:
973 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
974 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
975 break;
976 default:
977 break;
3829 } 978 }
3830 979
3831 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN, 980 REG_WRITE(ah, AR_SELFGEN_MASK, tx_chainmask);
3832 (numXpdGain - 1) & 0x3); 981 if (tx_chainmask == 0x5) {
3833 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1, 982 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
3834 xpdGainValues[0]); 983 AR_PHY_SWAP_ALT_CHAIN);
3835 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2,
3836 xpdGainValues[1]);
3837 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3,
3838 xpdGainValues[2]);
3839
3840 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
3841 if (AR_SREV_5416_V20_OR_LATER(ah) &&
3842 (ahp->ah_rxchainmask == 5 || ahp->ah_txchainmask == 5)
3843 && (i != 0)) {
3844 regChainOffset = (i == 1) ? 0x2000 : 0x1000;
3845 } else
3846 regChainOffset = i * 0x1000;
3847 if (pEepData->baseEepHeader.txMask & (1 << i)) {
3848 if (IS_CHAN_2GHZ(chan))
3849 pRawDataset = pEepData->calPierData2G[i];
3850 else
3851 pRawDataset = pEepData->calPierData5G[i];
3852
3853 ath9k_hw_get_gain_boundaries_pdadcs(ah, chan,
3854 pRawDataset,
3855 pCalBChans,
3856 numPiers,
3857 pdGainOverlap_t2,
3858 &tMinCalPower,
3859 gainBoundaries,
3860 pdadcValues,
3861 numXpdGain);
3862
3863 if ((i == 0) || AR_SREV_5416_V20_OR_LATER(ah)) {
3864
3865 REG_WRITE(ah,
3866 AR_PHY_TPCRG5 + regChainOffset,
3867 SM(pdGainOverlap_t2,
3868 AR_PHY_TPCRG5_PD_GAIN_OVERLAP)
3869 | SM(gainBoundaries[0],
3870 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_1)
3871 | SM(gainBoundaries[1],
3872 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_2)
3873 | SM(gainBoundaries[2],
3874 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_3)
3875 | SM(gainBoundaries[3],
3876 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_4));
3877 }
3878
3879 regOffset =
3880 AR_PHY_BASE + (672 << 2) + regChainOffset;
3881 for (j = 0; j < 32; j++) {
3882 reg32 =
3883 ((pdadcValues[4 * j + 0] & 0xFF) << 0)
3884 | ((pdadcValues[4 * j + 1] & 0xFF) <<
3885 8) | ((pdadcValues[4 * j + 2] &
3886 0xFF) << 16) |
3887 ((pdadcValues[4 * j + 3] & 0xFF) <<
3888 24);
3889 REG_WRITE(ah, regOffset, reg32);
3890
3891 DPRINTF(ah->ah_sc, ATH_DBG_PHY_IO,
3892 "PDADC (%d,%4x): %4.4x %8.8x\n",
3893 i, regChainOffset, regOffset,
3894 reg32);
3895 DPRINTF(ah->ah_sc, ATH_DBG_PHY_IO,
3896 "PDADC: Chain %d | PDADC %3d Value %3d | "
3897 "PDADC %3d Value %3d | PDADC %3d Value %3d | "
3898 "PDADC %3d Value %3d |\n",
3899 i, 4 * j, pdadcValues[4 * j],
3900 4 * j + 1, pdadcValues[4 * j + 1],
3901 4 * j + 2, pdadcValues[4 * j + 2],
3902 4 * j + 3,
3903 pdadcValues[4 * j + 3]);
3904
3905 regOffset += 4;
3906 }
3907 }
3908 } 984 }
3909 *pTxPowerIndexOffset = 0; 985 if (AR_SREV_9100(ah))
3910 986 REG_WRITE(ah, AR_PHY_ANALOG_SWAP,
3911 return true; 987 REG_READ(ah, AR_PHY_ANALOG_SWAP) | 0x00000001);
3912} 988}
3913 989
3914void ath9k_hw_configpcipowersave(struct ath_hal *ah, int restore) 990static void ath9k_hw_init_interrupt_masks(struct ath_hal *ah, enum ath9k_opmode opmode)
3915{ 991{
3916 struct ath_hal_5416 *ahp = AH5416(ah); 992 struct ath_hal_5416 *ahp = AH5416(ah);
3917 u8 i;
3918 993
3919 if (ah->ah_isPciExpress != true) 994 ahp->ah_maskReg = AR_IMR_TXERR |
3920 return; 995 AR_IMR_TXURN |
3921 996 AR_IMR_RXERR |
3922 if (ah->ah_config.pcie_powersave_enable == 2) 997 AR_IMR_RXORN |
3923 return; 998 AR_IMR_BCNMISC;
3924
3925 if (restore)
3926 return;
3927
3928 if (AR_SREV_9280_20_OR_LATER(ah)) {
3929 for (i = 0; i < ahp->ah_iniPcieSerdes.ia_rows; i++) {
3930 REG_WRITE(ah, INI_RA(&ahp->ah_iniPcieSerdes, i, 0),
3931 INI_RA(&ahp->ah_iniPcieSerdes, i, 1));
3932 }
3933 udelay(1000);
3934 } else if (AR_SREV_9280(ah)
3935 && (ah->ah_macRev == AR_SREV_REVISION_9280_10)) {
3936 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fd00);
3937 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
3938 999
3939 REG_WRITE(ah, AR_PCIE_SERDES, 0xa8000019); 1000 if (ahp->ah_intrMitigation)
3940 REG_WRITE(ah, AR_PCIE_SERDES, 0x13160820); 1001 ahp->ah_maskReg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
3941 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980560); 1002 else
1003 ahp->ah_maskReg |= AR_IMR_RXOK;
3942 1004
3943 if (ah->ah_config.pcie_clock_req) 1005 ahp->ah_maskReg |= AR_IMR_TXOK;
3944 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffc);
3945 else
3946 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffd);
3947 1006
3948 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40); 1007 if (opmode == ATH9K_M_HOSTAP)
3949 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554); 1008 ahp->ah_maskReg |= AR_IMR_MIB;
3950 REG_WRITE(ah, AR_PCIE_SERDES, 0x00043007);
3951 1009
3952 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000); 1010 REG_WRITE(ah, AR_IMR, ahp->ah_maskReg);
1011 REG_WRITE(ah, AR_IMR_S2, REG_READ(ah, AR_IMR_S2) | AR_IMR_S2_GTT);
3953 1012
3954 udelay(1000); 1013 if (!AR_SREV_9100(ah)) {
3955 } else { 1014 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
3956 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00); 1015 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT);
3957 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924); 1016 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
3958 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
3959 REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
3960 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
3961 REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
3962 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
3963 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
3964 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
3965 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
3966 } 1017 }
1018}
3967 1019
3968 REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA); 1020static bool ath9k_hw_set_ack_timeout(struct ath_hal *ah, u32 us)
1021{
1022 struct ath_hal_5416 *ahp = AH5416(ah);
3969 1023
3970 if (ah->ah_config.pcie_waen) { 1024 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_ACK))) {
3971 REG_WRITE(ah, AR_WA, ah->ah_config.pcie_waen); 1025 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "%s: bad ack timeout %u\n",
1026 __func__, us);
1027 ahp->ah_acktimeout = (u32) -1;
1028 return false;
3972 } else { 1029 } else {
3973 if (AR_SREV_9280(ah)) 1030 REG_RMW_FIELD(ah, AR_TIME_OUT,
3974 REG_WRITE(ah, AR_WA, 0x0040073f); 1031 AR_TIME_OUT_ACK, ath9k_hw_mac_to_clks(ah, us));
3975 else 1032 ahp->ah_acktimeout = us;
3976 REG_WRITE(ah, AR_WA, 0x0000073f); 1033 return true;
3977 } 1034 }
3978} 1035}
3979 1036
3980static void 1037static bool ath9k_hw_set_cts_timeout(struct ath_hal *ah, u32 us)
3981ath9k_hw_get_legacy_target_powers(struct ath_hal *ah,
3982 struct ath9k_channel *chan,
3983 struct cal_target_power_leg *powInfo,
3984 u16 numChannels,
3985 struct cal_target_power_leg *pNewPower,
3986 u16 numRates,
3987 bool isExtTarget)
3988{ 1038{
3989 u16 clo, chi; 1039 struct ath_hal_5416 *ahp = AH5416(ah);
3990 int i;
3991 int matchIndex = -1, lowIndex = -1;
3992 u16 freq;
3993 struct chan_centers centers;
3994
3995 ath9k_hw_get_channel_centers(ah, chan, &centers);
3996 freq = (isExtTarget) ? centers.ext_center : centers.ctl_center;
3997 1040
3998 if (freq <= ath9k_hw_fbin2freq(powInfo[0].bChannel, 1041 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_CTS))) {
3999 IS_CHAN_2GHZ(chan))) { 1042 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "%s: bad cts timeout %u\n",
4000 matchIndex = 0; 1043 __func__, us);
1044 ahp->ah_ctstimeout = (u32) -1;
1045 return false;
4001 } else { 1046 } else {
4002 for (i = 0; (i < numChannels) 1047 REG_RMW_FIELD(ah, AR_TIME_OUT,
4003 && (powInfo[i].bChannel != AR5416_BCHAN_UNUSED); i++) { 1048 AR_TIME_OUT_CTS, ath9k_hw_mac_to_clks(ah, us));
4004 if (freq == 1049 ahp->ah_ctstimeout = us;
4005 ath9k_hw_fbin2freq(powInfo[i].bChannel, 1050 return true;
4006 IS_CHAN_2GHZ(chan))) {
4007 matchIndex = i;
4008 break;
4009 } else if ((freq <
4010 ath9k_hw_fbin2freq(powInfo[i].bChannel,
4011 IS_CHAN_2GHZ(chan)))
4012 && (freq >
4013 ath9k_hw_fbin2freq(powInfo[i - 1].
4014 bChannel,
4015 IS_CHAN_2GHZ
4016 (chan)))) {
4017 lowIndex = i - 1;
4018 break;
4019 }
4020 }
4021 if ((matchIndex == -1) && (lowIndex == -1))
4022 matchIndex = i - 1;
4023 } 1051 }
1052}
4024 1053
4025 if (matchIndex != -1) { 1054static bool ath9k_hw_set_global_txtimeout(struct ath_hal *ah, u32 tu)
4026 *pNewPower = powInfo[matchIndex]; 1055{
1056 struct ath_hal_5416 *ahp = AH5416(ah);
1057
1058 if (tu > 0xFFFF) {
1059 DPRINTF(ah->ah_sc, ATH_DBG_XMIT,
1060 "%s: bad global tx timeout %u\n", __func__, tu);
1061 ahp->ah_globaltxtimeout = (u32) -1;
1062 return false;
4027 } else { 1063 } else {
4028 clo = ath9k_hw_fbin2freq(powInfo[lowIndex].bChannel, 1064 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
4029 IS_CHAN_2GHZ(chan)); 1065 ahp->ah_globaltxtimeout = tu;
4030 chi = ath9k_hw_fbin2freq(powInfo[lowIndex + 1].bChannel, 1066 return true;
4031 IS_CHAN_2GHZ(chan));
4032
4033 for (i = 0; i < numRates; i++) {
4034 pNewPower->tPow2x[i] =
4035 (u8) ath9k_hw_interpolate(freq, clo, chi,
4036 powInfo
4037 [lowIndex].
4038 tPow2x[i],
4039 powInfo
4040 [lowIndex +
4041 1].tPow2x[i]);
4042 }
4043 } 1067 }
4044} 1068}
4045 1069
4046static void 1070static void ath9k_hw_init_user_settings(struct ath_hal *ah)
4047ath9k_hw_get_target_powers(struct ath_hal *ah,
4048 struct ath9k_channel *chan,
4049 struct cal_target_power_ht *powInfo,
4050 u16 numChannels,
4051 struct cal_target_power_ht *pNewPower,
4052 u16 numRates,
4053 bool isHt40Target)
4054{ 1071{
4055 u16 clo, chi; 1072 struct ath_hal_5416 *ahp = AH5416(ah);
4056 int i;
4057 int matchIndex = -1, lowIndex = -1;
4058 u16 freq;
4059 struct chan_centers centers;
4060 1073
4061 ath9k_hw_get_channel_centers(ah, chan, &centers); 1074 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "--AP %s ahp->ah_miscMode 0x%x\n",
4062 freq = isHt40Target ? centers.synth_center : centers.ctl_center; 1075 __func__, ahp->ah_miscMode);
4063 1076
4064 if (freq <= 1077 if (ahp->ah_miscMode != 0)
4065 ath9k_hw_fbin2freq(powInfo[0].bChannel, IS_CHAN_2GHZ(chan))) { 1078 REG_WRITE(ah, AR_PCU_MISC,
4066 matchIndex = 0; 1079 REG_READ(ah, AR_PCU_MISC) | ahp->ah_miscMode);
4067 } else { 1080 if (ahp->ah_slottime != (u32) -1)
4068 for (i = 0; (i < numChannels) 1081 ath9k_hw_setslottime(ah, ahp->ah_slottime);
4069 && (powInfo[i].bChannel != AR5416_BCHAN_UNUSED); i++) { 1082 if (ahp->ah_acktimeout != (u32) -1)
4070 if (freq == 1083 ath9k_hw_set_ack_timeout(ah, ahp->ah_acktimeout);
4071 ath9k_hw_fbin2freq(powInfo[i].bChannel, 1084 if (ahp->ah_ctstimeout != (u32) -1)
4072 IS_CHAN_2GHZ(chan))) { 1085 ath9k_hw_set_cts_timeout(ah, ahp->ah_ctstimeout);
4073 matchIndex = i; 1086 if (ahp->ah_globaltxtimeout != (u32) -1)
4074 break; 1087 ath9k_hw_set_global_txtimeout(ah, ahp->ah_globaltxtimeout);
4075 } else 1088}
4076 if ((freq <
4077 ath9k_hw_fbin2freq(powInfo[i].bChannel,
4078 IS_CHAN_2GHZ(chan)))
4079 && (freq >
4080 ath9k_hw_fbin2freq(powInfo[i - 1].
4081 bChannel,
4082 IS_CHAN_2GHZ
4083 (chan)))) {
4084 lowIndex = i - 1;
4085 break;
4086 }
4087 }
4088 if ((matchIndex == -1) && (lowIndex == -1))
4089 matchIndex = i - 1;
4090 }
4091 1089
4092 if (matchIndex != -1) { 1090const char *ath9k_hw_probe(u16 vendorid, u16 devid)
4093 *pNewPower = powInfo[matchIndex]; 1091{
4094 } else { 1092 return vendorid == ATHEROS_VENDOR_ID ?
4095 clo = ath9k_hw_fbin2freq(powInfo[lowIndex].bChannel, 1093 ath9k_hw_devname(devid) : NULL;
4096 IS_CHAN_2GHZ(chan));
4097 chi = ath9k_hw_fbin2freq(powInfo[lowIndex + 1].bChannel,
4098 IS_CHAN_2GHZ(chan));
4099
4100 for (i = 0; i < numRates; i++) {
4101 pNewPower->tPow2x[i] =
4102 (u8) ath9k_hw_interpolate(freq, clo, chi,
4103 powInfo
4104 [lowIndex].
4105 tPow2x[i],
4106 powInfo
4107 [lowIndex +
4108 1].tPow2x[i]);
4109 }
4110 }
4111} 1094}
4112 1095
4113static u16 1096void ath9k_hw_detach(struct ath_hal *ah)
4114ath9k_hw_get_max_edge_power(u16 freq,
4115 struct cal_ctl_edges *pRdEdgesPower,
4116 bool is2GHz)
4117{ 1097{
4118 u16 twiceMaxEdgePower = AR5416_MAX_RATE_POWER; 1098 if (!AR_SREV_9100(ah))
4119 int i; 1099 ath9k_hw_ani_detach(ah);
4120 1100
4121 for (i = 0; (i < AR5416_NUM_BAND_EDGES) 1101 ath9k_hw_rfdetach(ah);
4122 && (pRdEdgesPower[i].bChannel != AR5416_BCHAN_UNUSED); i++) { 1102 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
4123 if (freq == ath9k_hw_fbin2freq(pRdEdgesPower[i].bChannel, 1103 kfree(ah);
4124 is2GHz)) {
4125 twiceMaxEdgePower = pRdEdgesPower[i].tPower;
4126 break;
4127 } else if ((i > 0)
4128 && (freq <
4129 ath9k_hw_fbin2freq(pRdEdgesPower[i].
4130 bChannel, is2GHz))) {
4131 if (ath9k_hw_fbin2freq
4132 (pRdEdgesPower[i - 1].bChannel, is2GHz) < freq
4133 && pRdEdgesPower[i - 1].flag) {
4134 twiceMaxEdgePower =
4135 pRdEdgesPower[i - 1].tPower;
4136 }
4137 break;
4138 }
4139 }
4140 return twiceMaxEdgePower;
4141} 1104}
4142 1105
4143static bool 1106struct ath_hal *ath9k_hw_attach(u16 devid, struct ath_softc *sc,
4144ath9k_hw_set_power_per_rate_table(struct ath_hal *ah, 1107 void __iomem *mem, int *error)
4145 struct ar5416_eeprom *pEepData,
4146 struct ath9k_channel *chan,
4147 int16_t *ratesArray,
4148 u16 cfgCtl,
4149 u8 AntennaReduction,
4150 u8 twiceMaxRegulatoryPower,
4151 u8 powerLimit)
4152{ 1108{
4153 u8 twiceMaxEdgePower = AR5416_MAX_RATE_POWER; 1109 struct ath_hal *ah = NULL;
4154 static const u16 tpScaleReductionTable[5] =
4155 { 0, 3, 6, 9, AR5416_MAX_RATE_POWER };
4156 1110
4157 int i; 1111 switch (devid) {
4158 int8_t twiceLargestAntenna; 1112 case AR5416_DEVID_PCI:
4159 struct cal_ctl_data *rep; 1113 case AR5416_DEVID_PCIE:
4160 struct cal_target_power_leg targetPowerOfdm, targetPowerCck = { 1114 case AR9160_DEVID_PCI:
4161 0, { 0, 0, 0, 0} 1115 case AR9280_DEVID_PCI:
4162 }; 1116 case AR9280_DEVID_PCIE:
4163 struct cal_target_power_leg targetPowerOfdmExt = { 1117 ah = ath9k_hw_do_attach(devid, sc, mem, error);
4164 0, { 0, 0, 0, 0} }, targetPowerCckExt = { 1118 break;
4165 0, { 0, 0, 0, 0 } 1119 default:
4166 }; 1120 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
4167 struct cal_target_power_ht targetPowerHt20, targetPowerHt40 = { 1121 "devid=0x%x not supported.\n", devid);
4168 0, {0, 0, 0, 0} 1122 ah = NULL;
4169 }; 1123 *error = -ENXIO;
4170 u8 scaledPower = 0, minCtlPower, maxRegAllowedPower; 1124 break;
4171 u16 ctlModesFor11a[] = 1125 }
4172 { CTL_11A, CTL_5GHT20, CTL_11A_EXT, CTL_5GHT40 };
4173 u16 ctlModesFor11g[] =
4174 { CTL_11B, CTL_11G, CTL_2GHT20, CTL_11B_EXT, CTL_11G_EXT,
4175 CTL_2GHT40
4176 };
4177 u16 numCtlModes, *pCtlMode, ctlMode, freq;
4178 struct chan_centers centers;
4179 int tx_chainmask;
4180 u8 twiceMinEdgePower;
4181 struct ath_hal_5416 *ahp = AH5416(ah);
4182 1126
4183 tx_chainmask = ahp->ah_txchainmask; 1127 return ah;
1128}
4184 1129
4185 ath9k_hw_get_channel_centers(ah, chan, &centers); 1130/*******/
1131/* INI */
1132/*******/
4186 1133
4187 twiceLargestAntenna = max( 1134static void ath9k_hw_override_ini(struct ath_hal *ah,
4188 pEepData->modalHeader 1135 struct ath9k_channel *chan)
4189 [IS_CHAN_2GHZ(chan)].antennaGainCh[0], 1136{
4190 pEepData->modalHeader 1137 if (!AR_SREV_5416_V20_OR_LATER(ah) ||
4191 [IS_CHAN_2GHZ(chan)].antennaGainCh[1]); 1138 AR_SREV_9280_10_OR_LATER(ah))
1139 return;
4192 1140
4193 twiceLargestAntenna = max((u8) twiceLargestAntenna, 1141 REG_WRITE(ah, 0x9800 + (651 << 2), 0x11);
4194 pEepData->modalHeader 1142}
4195 [IS_CHAN_2GHZ(chan)].antennaGainCh[2]); 1143
1144static u32 ath9k_hw_ini_fixup(struct ath_hal *ah,
1145 struct ar5416_eeprom *pEepData,
1146 u32 reg, u32 value)
1147{
1148 struct base_eep_header *pBase = &(pEepData->baseEepHeader);
4196 1149
4197 twiceLargestAntenna = 1150 switch (ah->ah_devid) {
4198 (int8_t) min(AntennaReduction - twiceLargestAntenna, 0); 1151 case AR9280_DEVID_PCI:
1152 if (reg == 0x7894) {
1153 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
1154 "ini VAL: %x EEPROM: %x\n", value,
1155 (pBase->version & 0xff));
4199 1156
4200 maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna; 1157 if ((pBase->version & 0xff) > 0x0a) {
1158 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
1159 "PWDCLKIND: %d\n",
1160 pBase->pwdclkind);
1161 value &= ~AR_AN_TOP2_PWDCLKIND;
1162 value |= AR_AN_TOP2_PWDCLKIND &
1163 (pBase->pwdclkind << AR_AN_TOP2_PWDCLKIND_S);
1164 } else {
1165 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
1166 "PWDCLKIND Earlier Rev\n");
1167 }
4201 1168
4202 if (ah->ah_tpScale != ATH9K_TP_SCALE_MAX) { 1169 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
4203 maxRegAllowedPower -= 1170 "final ini VAL: %x\n", value);
4204 (tpScaleReductionTable[(ah->ah_tpScale)] * 2); 1171 }
1172 break;
4205 } 1173 }
4206 1174
4207 scaledPower = min(powerLimit, maxRegAllowedPower); 1175 return value;
1176}
4208 1177
4209 switch (ar5416_get_ntxchains(tx_chainmask)) { 1178static int ath9k_hw_process_ini(struct ath_hal *ah,
4210 case 1: 1179 struct ath9k_channel *chan,
1180 enum ath9k_ht_macmode macmode)
1181{
1182 int i, regWrites = 0;
1183 struct ath_hal_5416 *ahp = AH5416(ah);
1184 u32 modesIndex, freqIndex;
1185 int status;
1186
1187 switch (chan->chanmode) {
1188 case CHANNEL_A:
1189 case CHANNEL_A_HT20:
1190 modesIndex = 1;
1191 freqIndex = 1;
4211 break; 1192 break;
4212 case 2: 1193 case CHANNEL_A_HT40PLUS:
4213 scaledPower -= 1194 case CHANNEL_A_HT40MINUS:
4214 pEepData->modalHeader[IS_CHAN_2GHZ(chan)]. 1195 modesIndex = 2;
4215 pwrDecreaseFor2Chain; 1196 freqIndex = 1;
4216 break; 1197 break;
4217 case 3: 1198 case CHANNEL_G:
4218 scaledPower -= 1199 case CHANNEL_G_HT20:
4219 pEepData->modalHeader[IS_CHAN_2GHZ(chan)]. 1200 case CHANNEL_B:
4220 pwrDecreaseFor3Chain; 1201 modesIndex = 4;
1202 freqIndex = 2;
4221 break; 1203 break;
1204 case CHANNEL_G_HT40PLUS:
1205 case CHANNEL_G_HT40MINUS:
1206 modesIndex = 3;
1207 freqIndex = 2;
1208 break;
1209
1210 default:
1211 return -EINVAL;
4222 } 1212 }
4223 1213
4224 scaledPower = max(0, (int32_t) scaledPower); 1214 REG_WRITE(ah, AR_PHY(0), 0x00000007);
4225
4226 if (IS_CHAN_2GHZ(chan)) {
4227 numCtlModes =
4228 ARRAY_SIZE(ctlModesFor11g) -
4229 SUB_NUM_CTL_MODES_AT_2G_40;
4230 pCtlMode = ctlModesFor11g;
4231
4232 ath9k_hw_get_legacy_target_powers(ah, chan,
4233 pEepData->
4234 calTargetPowerCck,
4235 AR5416_NUM_2G_CCK_TARGET_POWERS,
4236 &targetPowerCck, 4,
4237 false);
4238 ath9k_hw_get_legacy_target_powers(ah, chan,
4239 pEepData->
4240 calTargetPower2G,
4241 AR5416_NUM_2G_20_TARGET_POWERS,
4242 &targetPowerOfdm, 4,
4243 false);
4244 ath9k_hw_get_target_powers(ah, chan,
4245 pEepData->calTargetPower2GHT20,
4246 AR5416_NUM_2G_20_TARGET_POWERS,
4247 &targetPowerHt20, 8, false);
4248 1215
4249 if (IS_CHAN_HT40(chan)) { 1216 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_EXTERNAL_RADIO);
4250 numCtlModes = ARRAY_SIZE(ctlModesFor11g); 1217
4251 ath9k_hw_get_target_powers(ah, chan, 1218 ath9k_hw_set_addac(ah, chan);
4252 pEepData-> 1219
4253 calTargetPower2GHT40, 1220 if (AR_SREV_5416_V22_OR_LATER(ah)) {
4254 AR5416_NUM_2G_40_TARGET_POWERS, 1221 REG_WRITE_ARRAY(&ahp->ah_iniAddac, 1, regWrites);
4255 &targetPowerHt40, 8,
4256 true);
4257 ath9k_hw_get_legacy_target_powers(ah, chan,
4258 pEepData->
4259 calTargetPowerCck,
4260 AR5416_NUM_2G_CCK_TARGET_POWERS,
4261 &targetPowerCckExt,
4262 4, true);
4263 ath9k_hw_get_legacy_target_powers(ah, chan,
4264 pEepData->
4265 calTargetPower2G,
4266 AR5416_NUM_2G_20_TARGET_POWERS,
4267 &targetPowerOfdmExt,
4268 4, true);
4269 }
4270 } else { 1222 } else {
1223 struct ar5416IniArray temp;
1224 u32 addacSize =
1225 sizeof(u32) * ahp->ah_iniAddac.ia_rows *
1226 ahp->ah_iniAddac.ia_columns;
4271 1227
4272 numCtlModes = 1228 memcpy(ahp->ah_addac5416_21,
4273 ARRAY_SIZE(ctlModesFor11a) - 1229 ahp->ah_iniAddac.ia_array, addacSize);
4274 SUB_NUM_CTL_MODES_AT_5G_40;
4275 pCtlMode = ctlModesFor11a;
4276
4277 ath9k_hw_get_legacy_target_powers(ah, chan,
4278 pEepData->
4279 calTargetPower5G,
4280 AR5416_NUM_5G_20_TARGET_POWERS,
4281 &targetPowerOfdm, 4,
4282 false);
4283 ath9k_hw_get_target_powers(ah, chan,
4284 pEepData->calTargetPower5GHT20,
4285 AR5416_NUM_5G_20_TARGET_POWERS,
4286 &targetPowerHt20, 8, false);
4287 1230
4288 if (IS_CHAN_HT40(chan)) { 1231 (ahp->ah_addac5416_21)[31 * ahp->ah_iniAddac.ia_columns + 1] = 0;
4289 numCtlModes = ARRAY_SIZE(ctlModesFor11a);
4290 ath9k_hw_get_target_powers(ah, chan,
4291 pEepData->
4292 calTargetPower5GHT40,
4293 AR5416_NUM_5G_40_TARGET_POWERS,
4294 &targetPowerHt40, 8,
4295 true);
4296 ath9k_hw_get_legacy_target_powers(ah, chan,
4297 pEepData->
4298 calTargetPower5G,
4299 AR5416_NUM_5G_20_TARGET_POWERS,
4300 &targetPowerOfdmExt,
4301 4, true);
4302 }
4303 }
4304 1232
4305 for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) { 1233 temp.ia_array = ahp->ah_addac5416_21;
4306 bool isHt40CtlMode = 1234 temp.ia_columns = ahp->ah_iniAddac.ia_columns;
4307 (pCtlMode[ctlMode] == CTL_5GHT40) 1235 temp.ia_rows = ahp->ah_iniAddac.ia_rows;
4308 || (pCtlMode[ctlMode] == CTL_2GHT40); 1236 REG_WRITE_ARRAY(&temp, 1, regWrites);
4309 if (isHt40CtlMode) 1237 }
4310 freq = centers.synth_center;
4311 else if (pCtlMode[ctlMode] & EXT_ADDITIVE)
4312 freq = centers.ext_center;
4313 else
4314 freq = centers.ctl_center;
4315 1238
4316 if (ar5416_get_eep_ver(ahp) == 14 1239 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_INTERNAL_ADDAC);
4317 && ar5416_get_eep_rev(ahp) <= 2)
4318 twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
4319 1240
4320 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT, 1241 for (i = 0; i < ahp->ah_iniModes.ia_rows; i++) {
4321 "LOOP-Mode ctlMode %d < %d, isHt40CtlMode %d, " 1242 u32 reg = INI_RA(&ahp->ah_iniModes, i, 0);
4322 "EXT_ADDITIVE %d\n", 1243 u32 val = INI_RA(&ahp->ah_iniModes, i, modesIndex);
4323 ctlMode, numCtlModes, isHt40CtlMode,
4324 (pCtlMode[ctlMode] & EXT_ADDITIVE));
4325 1244
4326 for (i = 0; (i < AR5416_NUM_CTLS) && pEepData->ctlIndex[i]; 1245#ifdef CONFIG_SLOW_ANT_DIV
4327 i++) { 1246 if (ah->ah_devid == AR9280_DEVID_PCI)
4328 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT, 1247 val = ath9k_hw_ini_fixup(ah, &ahp->ah_eeprom, reg, val);
4329 " LOOP-Ctlidx %d: cfgCtl 0x%2.2x " 1248#endif
4330 "pCtlMode 0x%2.2x ctlIndex 0x%2.2x "
4331 "chan %d\n",
4332 i, cfgCtl, pCtlMode[ctlMode],
4333 pEepData->ctlIndex[i], chan->channel);
4334
4335 if ((((cfgCtl & ~CTL_MODE_M) |
4336 (pCtlMode[ctlMode] & CTL_MODE_M)) ==
4337 pEepData->ctlIndex[i])
4338 ||
4339 (((cfgCtl & ~CTL_MODE_M) |
4340 (pCtlMode[ctlMode] & CTL_MODE_M)) ==
4341 ((pEepData->
4342 ctlIndex[i] & CTL_MODE_M) | SD_NO_CTL))) {
4343 rep = &(pEepData->ctlData[i]);
4344
4345 twiceMinEdgePower =
4346 ath9k_hw_get_max_edge_power(freq,
4347 rep->
4348 ctlEdges
4349 [ar5416_get_ntxchains
4350 (tx_chainmask)
4351 - 1],
4352 IS_CHAN_2GHZ
4353 (chan));
4354
4355 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
4356 " MATCH-EE_IDX %d: ch %d is2 %d "
4357 "2xMinEdge %d chainmask %d chains %d\n",
4358 i, freq, IS_CHAN_2GHZ(chan),
4359 twiceMinEdgePower, tx_chainmask,
4360 ar5416_get_ntxchains
4361 (tx_chainmask));
4362 if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) {
4363 twiceMaxEdgePower =
4364 min(twiceMaxEdgePower,
4365 twiceMinEdgePower);
4366 } else {
4367 twiceMaxEdgePower =
4368 twiceMinEdgePower;
4369 break;
4370 }
4371 }
4372 }
4373 1249
4374 minCtlPower = min(twiceMaxEdgePower, scaledPower); 1250 REG_WRITE(ah, reg, val);
4375 1251
4376 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT, 1252 if (reg >= 0x7800 && reg < 0x78a0
4377 " SEL-Min ctlMode %d pCtlMode %d " 1253 && ah->ah_config.analog_shiftreg) {
4378 "2xMaxEdge %d sP %d minCtlPwr %d\n", 1254 udelay(100);
4379 ctlMode, pCtlMode[ctlMode], twiceMaxEdgePower,
4380 scaledPower, minCtlPower);
4381
4382 switch (pCtlMode[ctlMode]) {
4383 case CTL_11B:
4384 for (i = 0; i < ARRAY_SIZE(targetPowerCck.tPow2x);
4385 i++) {
4386 targetPowerCck.tPow2x[i] =
4387 min(targetPowerCck.tPow2x[i],
4388 minCtlPower);
4389 }
4390 break;
4391 case CTL_11A:
4392 case CTL_11G:
4393 for (i = 0; i < ARRAY_SIZE(targetPowerOfdm.tPow2x);
4394 i++) {
4395 targetPowerOfdm.tPow2x[i] =
4396 min(targetPowerOfdm.tPow2x[i],
4397 minCtlPower);
4398 }
4399 break;
4400 case CTL_5GHT20:
4401 case CTL_2GHT20:
4402 for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x);
4403 i++) {
4404 targetPowerHt20.tPow2x[i] =
4405 min(targetPowerHt20.tPow2x[i],
4406 minCtlPower);
4407 }
4408 break;
4409 case CTL_11B_EXT:
4410 targetPowerCckExt.tPow2x[0] =
4411 min(targetPowerCckExt.tPow2x[0], minCtlPower);
4412 break;
4413 case CTL_11A_EXT:
4414 case CTL_11G_EXT:
4415 targetPowerOfdmExt.tPow2x[0] =
4416 min(targetPowerOfdmExt.tPow2x[0], minCtlPower);
4417 break;
4418 case CTL_5GHT40:
4419 case CTL_2GHT40:
4420 for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x);
4421 i++) {
4422 targetPowerHt40.tPow2x[i] =
4423 min(targetPowerHt40.tPow2x[i],
4424 minCtlPower);
4425 }
4426 break;
4427 default:
4428 break;
4429 } 1255 }
4430 }
4431 1256
4432 ratesArray[rate6mb] = ratesArray[rate9mb] = ratesArray[rate12mb] = 1257 DO_DELAY(regWrites);
4433 ratesArray[rate18mb] = ratesArray[rate24mb] =
4434 targetPowerOfdm.tPow2x[0];
4435 ratesArray[rate36mb] = targetPowerOfdm.tPow2x[1];
4436 ratesArray[rate48mb] = targetPowerOfdm.tPow2x[2];
4437 ratesArray[rate54mb] = targetPowerOfdm.tPow2x[3];
4438 ratesArray[rateXr] = targetPowerOfdm.tPow2x[0];
4439
4440 for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++)
4441 ratesArray[rateHt20_0 + i] = targetPowerHt20.tPow2x[i];
4442
4443 if (IS_CHAN_2GHZ(chan)) {
4444 ratesArray[rate1l] = targetPowerCck.tPow2x[0];
4445 ratesArray[rate2s] = ratesArray[rate2l] =
4446 targetPowerCck.tPow2x[1];
4447 ratesArray[rate5_5s] = ratesArray[rate5_5l] =
4448 targetPowerCck.tPow2x[2];
4449 ;
4450 ratesArray[rate11s] = ratesArray[rate11l] =
4451 targetPowerCck.tPow2x[3];
4452 ;
4453 } 1258 }
4454 if (IS_CHAN_HT40(chan)) { 1259
4455 for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) { 1260 for (i = 0; i < ahp->ah_iniCommon.ia_rows; i++) {
4456 ratesArray[rateHt40_0 + i] = 1261 u32 reg = INI_RA(&ahp->ah_iniCommon, i, 0);
4457 targetPowerHt40.tPow2x[i]; 1262 u32 val = INI_RA(&ahp->ah_iniCommon, i, 1);
4458 } 1263
4459 ratesArray[rateDupOfdm] = targetPowerHt40.tPow2x[0]; 1264 REG_WRITE(ah, reg, val);
4460 ratesArray[rateDupCck] = targetPowerHt40.tPow2x[0]; 1265
4461 ratesArray[rateExtOfdm] = targetPowerOfdmExt.tPow2x[0]; 1266 if (reg >= 0x7800 && reg < 0x78a0
4462 if (IS_CHAN_2GHZ(chan)) { 1267 && ah->ah_config.analog_shiftreg) {
4463 ratesArray[rateExtCck] = 1268 udelay(100);
4464 targetPowerCckExt.tPow2x[0];
4465 } 1269 }
4466 }
4467 return true;
4468}
4469 1270
4470static int 1271 DO_DELAY(regWrites);
4471ath9k_hw_set_txpower(struct ath_hal *ah, 1272 }
4472 struct ar5416_eeprom *pEepData,
4473 struct ath9k_channel *chan,
4474 u16 cfgCtl,
4475 u8 twiceAntennaReduction,
4476 u8 twiceMaxRegulatoryPower,
4477 u8 powerLimit)
4478{
4479 struct modal_eep_header *pModal =
4480 &(pEepData->modalHeader[IS_CHAN_2GHZ(chan)]);
4481 int16_t ratesArray[Ar5416RateSize];
4482 int16_t txPowerIndexOffset = 0;
4483 u8 ht40PowerIncForPdadc = 2;
4484 int i;
4485 1273
4486 memset(ratesArray, 0, sizeof(ratesArray)); 1274 ath9k_hw_write_regs(ah, modesIndex, freqIndex, regWrites);
4487 1275
4488 if ((pEepData->baseEepHeader. 1276 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan)) {
4489 version & AR5416_EEP_VER_MINOR_MASK) >= 1277 REG_WRITE_ARRAY(&ahp->ah_iniModesAdditional, modesIndex,
4490 AR5416_EEP_MINOR_VER_2) { 1278 regWrites);
4491 ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
4492 } 1279 }
4493 1280
4494 if (!ath9k_hw_set_power_per_rate_table(ah, pEepData, chan, 1281 ath9k_hw_override_ini(ah, chan);
4495 &ratesArray[0], cfgCtl, 1282 ath9k_hw_set_regs(ah, chan, macmode);
4496 twiceAntennaReduction, 1283 ath9k_hw_init_chain_masks(ah);
4497 twiceMaxRegulatoryPower, 1284
4498 powerLimit)) { 1285 status = ath9k_hw_set_txpower(ah, chan,
4499 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, 1286 ath9k_regd_get_ctl(ah, chan),
4500 "ath9k_hw_set_txpower: unable to set " 1287 ath9k_regd_get_antenna_allowed(ah,
4501 "tx power per rate table\n"); 1288 chan),
1289 chan->maxRegTxPower * 2,
1290 min((u32) MAX_RATE_POWER,
1291 (u32) ah->ah_powerLimit));
1292 if (status != 0) {
1293 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
1294 "%s: error init'ing transmit power\n", __func__);
4502 return -EIO; 1295 return -EIO;
4503 } 1296 }
4504 1297
4505 if (!ath9k_hw_set_power_cal_table 1298 if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) {
4506 (ah, pEepData, chan, &txPowerIndexOffset)) { 1299 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
4507 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, 1300 "%s: ar5416SetRfRegs failed\n", __func__);
4508 "ath9k_hw_set_txpower: unable to set power table\n");
4509 return -EIO; 1301 return -EIO;
4510 } 1302 }
4511 1303
4512 for (i = 0; i < ARRAY_SIZE(ratesArray); i++) { 1304 return 0;
4513 ratesArray[i] = 1305}
4514 (int16_t) (txPowerIndexOffset + ratesArray[i]);
4515 if (ratesArray[i] > AR5416_MAX_RATE_POWER)
4516 ratesArray[i] = AR5416_MAX_RATE_POWER;
4517 }
4518 1306
4519 if (AR_SREV_9280_10_OR_LATER(ah)) { 1307/****************************************/
4520 for (i = 0; i < Ar5416RateSize; i++) 1308/* Reset and Channel Switching Routines */
4521 ratesArray[i] -= AR5416_PWR_TABLE_OFFSET * 2; 1309/****************************************/
4522 }
4523 1310
4524 REG_WRITE(ah, AR_PHY_POWER_TX_RATE1, 1311static void ath9k_hw_set_rfmode(struct ath_hal *ah, struct ath9k_channel *chan)
4525 ATH9K_POW_SM(ratesArray[rate18mb], 24) 1312{
4526 | ATH9K_POW_SM(ratesArray[rate12mb], 16) 1313 u32 rfMode = 0;
4527 | ATH9K_POW_SM(ratesArray[rate9mb], 8)
4528 | ATH9K_POW_SM(ratesArray[rate6mb], 0)
4529 );
4530 REG_WRITE(ah, AR_PHY_POWER_TX_RATE2,
4531 ATH9K_POW_SM(ratesArray[rate54mb], 24)
4532 | ATH9K_POW_SM(ratesArray[rate48mb], 16)
4533 | ATH9K_POW_SM(ratesArray[rate36mb], 8)
4534 | ATH9K_POW_SM(ratesArray[rate24mb], 0)
4535 );
4536
4537 if (IS_CHAN_2GHZ(chan)) {
4538 REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
4539 ATH9K_POW_SM(ratesArray[rate2s], 24)
4540 | ATH9K_POW_SM(ratesArray[rate2l], 16)
4541 | ATH9K_POW_SM(ratesArray[rateXr], 8)
4542 | ATH9K_POW_SM(ratesArray[rate1l], 0)
4543 );
4544 REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
4545 ATH9K_POW_SM(ratesArray[rate11s], 24)
4546 | ATH9K_POW_SM(ratesArray[rate11l], 16)
4547 | ATH9K_POW_SM(ratesArray[rate5_5s], 8)
4548 | ATH9K_POW_SM(ratesArray[rate5_5l], 0)
4549 );
4550 }
4551 1314
4552 REG_WRITE(ah, AR_PHY_POWER_TX_RATE5, 1315 if (chan == NULL)
4553 ATH9K_POW_SM(ratesArray[rateHt20_3], 24) 1316 return;
4554 | ATH9K_POW_SM(ratesArray[rateHt20_2], 16)
4555 | ATH9K_POW_SM(ratesArray[rateHt20_1], 8)
4556 | ATH9K_POW_SM(ratesArray[rateHt20_0], 0)
4557 );
4558 REG_WRITE(ah, AR_PHY_POWER_TX_RATE6,
4559 ATH9K_POW_SM(ratesArray[rateHt20_7], 24)
4560 | ATH9K_POW_SM(ratesArray[rateHt20_6], 16)
4561 | ATH9K_POW_SM(ratesArray[rateHt20_5], 8)
4562 | ATH9K_POW_SM(ratesArray[rateHt20_4], 0)
4563 );
4564 1317
4565 if (IS_CHAN_HT40(chan)) { 1318 rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
4566 REG_WRITE(ah, AR_PHY_POWER_TX_RATE7, 1319 ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
4567 ATH9K_POW_SM(ratesArray[rateHt40_3] +
4568 ht40PowerIncForPdadc, 24)
4569 | ATH9K_POW_SM(ratesArray[rateHt40_2] +
4570 ht40PowerIncForPdadc, 16)
4571 | ATH9K_POW_SM(ratesArray[rateHt40_1] +
4572 ht40PowerIncForPdadc, 8)
4573 | ATH9K_POW_SM(ratesArray[rateHt40_0] +
4574 ht40PowerIncForPdadc, 0)
4575 );
4576 REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
4577 ATH9K_POW_SM(ratesArray[rateHt40_7] +
4578 ht40PowerIncForPdadc, 24)
4579 | ATH9K_POW_SM(ratesArray[rateHt40_6] +
4580 ht40PowerIncForPdadc, 16)
4581 | ATH9K_POW_SM(ratesArray[rateHt40_5] +
4582 ht40PowerIncForPdadc, 8)
4583 | ATH9K_POW_SM(ratesArray[rateHt40_4] +
4584 ht40PowerIncForPdadc, 0)
4585 );
4586
4587 REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
4588 ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
4589 | ATH9K_POW_SM(ratesArray[rateExtCck], 16)
4590 | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
4591 | ATH9K_POW_SM(ratesArray[rateDupCck], 0)
4592 );
4593 }
4594 1320
4595 REG_WRITE(ah, AR_PHY_POWER_TX_SUB, 1321 if (!AR_SREV_9280_10_OR_LATER(ah))
4596 ATH9K_POW_SM(pModal->pwrDecreaseFor3Chain, 6) 1322 rfMode |= (IS_CHAN_5GHZ(chan)) ?
4597 | ATH9K_POW_SM(pModal->pwrDecreaseFor2Chain, 0) 1323 AR_PHY_MODE_RF5GHZ : AR_PHY_MODE_RF2GHZ;
4598 );
4599 1324
4600 i = rate6mb; 1325 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan))
4601 if (IS_CHAN_HT40(chan)) 1326 rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
4602 i = rateHt40_0;
4603 else if (IS_CHAN_HT20(chan))
4604 i = rateHt20_0;
4605 1327
4606 if (AR_SREV_9280_10_OR_LATER(ah)) 1328 REG_WRITE(ah, AR_PHY_MODE, rfMode);
4607 ah->ah_maxPowerLevel = 1329}
4608 ratesArray[i] + AR5416_PWR_TABLE_OFFSET * 2;
4609 else
4610 ah->ah_maxPowerLevel = ratesArray[i];
4611 1330
4612 return 0; 1331static void ath9k_hw_mark_phy_inactive(struct ath_hal *ah)
1332{
1333 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
1334}
1335
1336static inline void ath9k_hw_set_dma(struct ath_hal *ah)
1337{
1338 u32 regval;
1339
1340 regval = REG_READ(ah, AR_AHB_MODE);
1341 REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN);
1342
1343 regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK;
1344 REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B);
1345
1346 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->ah_txTrigLevel);
1347
1348 regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK;
1349 REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B);
1350
1351 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
1352
1353 if (AR_SREV_9285(ah)) {
1354 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1355 AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
1356 } else {
1357 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1358 AR_PCU_TXBUF_CTRL_USABLE_SIZE);
1359 }
1360}
1361
1362static void ath9k_hw_set_operating_mode(struct ath_hal *ah, int opmode)
1363{
1364 u32 val;
1365
1366 val = REG_READ(ah, AR_STA_ID1);
1367 val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC);
1368 switch (opmode) {
1369 case ATH9K_M_HOSTAP:
1370 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP
1371 | AR_STA_ID1_KSRCH_MODE);
1372 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1373 break;
1374 case ATH9K_M_IBSS:
1375 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC
1376 | AR_STA_ID1_KSRCH_MODE);
1377 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1378 break;
1379 case ATH9K_M_STA:
1380 case ATH9K_M_MONITOR:
1381 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
1382 break;
1383 }
4613} 1384}
4614 1385
4615static inline void ath9k_hw_get_delta_slope_vals(struct ath_hal *ah, 1386static inline void ath9k_hw_get_delta_slope_vals(struct ath_hal *ah,
@@ -4631,9 +1402,8 @@ static inline void ath9k_hw_get_delta_slope_vals(struct ath_hal *ah,
4631 *coef_exponent = coef_exp - 16; 1402 *coef_exponent = coef_exp - 16;
4632} 1403}
4633 1404
4634static void 1405static void ath9k_hw_set_delta_slope(struct ath_hal *ah,
4635ath9k_hw_set_delta_slope(struct ath_hal *ah, 1406 struct ath9k_channel *chan)
4636 struct ath9k_channel *chan)
4637{ 1407{
4638 u32 coef_scaled, ds_coef_exp, ds_coef_man; 1408 u32 coef_scaled, ds_coef_exp, ds_coef_man;
4639 u32 clockMhzScaled = 0x64000000; 1409 u32 clockMhzScaled = 0x64000000;
@@ -4666,8 +1436,242 @@ ath9k_hw_set_delta_slope(struct ath_hal *ah,
4666 AR_PHY_HALFGI_DSC_EXP, ds_coef_exp); 1436 AR_PHY_HALFGI_DSC_EXP, ds_coef_exp);
4667} 1437}
4668 1438
4669static void ath9k_hw_9280_spur_mitigate(struct ath_hal *ah, 1439static bool ath9k_hw_set_reset(struct ath_hal *ah, int type)
4670 struct ath9k_channel *chan) 1440{
1441 u32 rst_flags;
1442 u32 tmpReg;
1443
1444 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1445 AR_RTC_FORCE_WAKE_ON_INT);
1446
1447 if (AR_SREV_9100(ah)) {
1448 rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
1449 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1450 } else {
1451 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1452 if (tmpReg &
1453 (AR_INTR_SYNC_LOCAL_TIMEOUT |
1454 AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
1455 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
1456 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
1457 } else {
1458 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1459 }
1460
1461 rst_flags = AR_RTC_RC_MAC_WARM;
1462 if (type == ATH9K_RESET_COLD)
1463 rst_flags |= AR_RTC_RC_MAC_COLD;
1464 }
1465
1466 REG_WRITE(ah, (u16) (AR_RTC_RC), rst_flags);
1467 udelay(50);
1468
1469 REG_WRITE(ah, (u16) (AR_RTC_RC), 0);
1470 if (!ath9k_hw_wait(ah, (u16) (AR_RTC_RC), AR_RTC_RC_M, 0)) {
1471 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
1472 "%s: RTC stuck in MAC reset\n",
1473 __func__);
1474 return false;
1475 }
1476
1477 if (!AR_SREV_9100(ah))
1478 REG_WRITE(ah, AR_RC, 0);
1479
1480 ath9k_hw_init_pll(ah, NULL);
1481
1482 if (AR_SREV_9100(ah))
1483 udelay(50);
1484
1485 return true;
1486}
1487
1488static bool ath9k_hw_set_reset_power_on(struct ath_hal *ah)
1489{
1490 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1491 AR_RTC_FORCE_WAKE_ON_INT);
1492
1493 REG_WRITE(ah, (u16) (AR_RTC_RESET), 0);
1494 REG_WRITE(ah, (u16) (AR_RTC_RESET), 1);
1495
1496 if (!ath9k_hw_wait(ah,
1497 AR_RTC_STATUS,
1498 AR_RTC_STATUS_M,
1499 AR_RTC_STATUS_ON)) {
1500 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "%s: RTC not waking up\n",
1501 __func__);
1502 return false;
1503 }
1504
1505 ath9k_hw_read_revisions(ah);
1506
1507 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1508}
1509
1510static bool ath9k_hw_set_reset_reg(struct ath_hal *ah, u32 type)
1511{
1512 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1513 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1514
1515 switch (type) {
1516 case ATH9K_RESET_POWER_ON:
1517 return ath9k_hw_set_reset_power_on(ah);
1518 break;
1519 case ATH9K_RESET_WARM:
1520 case ATH9K_RESET_COLD:
1521 return ath9k_hw_set_reset(ah, type);
1522 break;
1523 default:
1524 return false;
1525 }
1526}
1527
1528static void ath9k_hw_set_regs(struct ath_hal *ah, struct ath9k_channel *chan,
1529 enum ath9k_ht_macmode macmode)
1530{
1531 u32 phymode;
1532 struct ath_hal_5416 *ahp = AH5416(ah);
1533
1534 phymode = AR_PHY_FC_HT_EN | AR_PHY_FC_SHORT_GI_40
1535 | AR_PHY_FC_SINGLE_HT_LTF1 | AR_PHY_FC_WALSH;
1536
1537 if (IS_CHAN_HT40(chan)) {
1538 phymode |= AR_PHY_FC_DYN2040_EN;
1539
1540 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
1541 (chan->chanmode == CHANNEL_G_HT40PLUS))
1542 phymode |= AR_PHY_FC_DYN2040_PRI_CH;
1543
1544 if (ahp->ah_extprotspacing == ATH9K_HT_EXTPROTSPACING_25)
1545 phymode |= AR_PHY_FC_DYN2040_EXT_CH;
1546 }
1547 REG_WRITE(ah, AR_PHY_TURBO, phymode);
1548
1549 ath9k_hw_set11nmac2040(ah, macmode);
1550
1551 REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
1552 REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
1553}
1554
1555static bool ath9k_hw_chip_reset(struct ath_hal *ah,
1556 struct ath9k_channel *chan)
1557{
1558 struct ath_hal_5416 *ahp = AH5416(ah);
1559
1560 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
1561 return false;
1562
1563 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
1564 return false;
1565
1566 ahp->ah_chipFullSleep = false;
1567
1568 ath9k_hw_init_pll(ah, chan);
1569
1570 ath9k_hw_set_rfmode(ah, chan);
1571
1572 return true;
1573}
1574
1575static struct ath9k_channel *ath9k_hw_check_chan(struct ath_hal *ah,
1576 struct ath9k_channel *chan)
1577{
1578 if (!(IS_CHAN_2GHZ(chan) ^ IS_CHAN_5GHZ(chan))) {
1579 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
1580 "%s: invalid channel %u/0x%x; not marked as "
1581 "2GHz or 5GHz\n", __func__, chan->channel,
1582 chan->channelFlags);
1583 return NULL;
1584 }
1585
1586 if (!IS_CHAN_OFDM(chan) &&
1587 !IS_CHAN_CCK(chan) &&
1588 !IS_CHAN_HT20(chan) &&
1589 !IS_CHAN_HT40(chan)) {
1590 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
1591 "%s: invalid channel %u/0x%x; not marked as "
1592 "OFDM or CCK or HT20 or HT40PLUS or HT40MINUS\n",
1593 __func__, chan->channel, chan->channelFlags);
1594 return NULL;
1595 }
1596
1597 return ath9k_regd_check_channel(ah, chan);
1598}
1599
1600static bool ath9k_hw_channel_change(struct ath_hal *ah,
1601 struct ath9k_channel *chan,
1602 enum ath9k_ht_macmode macmode)
1603{
1604 u32 synthDelay, qnum;
1605
1606 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1607 if (ath9k_hw_numtxpending(ah, qnum)) {
1608 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
1609 "%s: Transmit frames pending on queue %d\n",
1610 __func__, qnum);
1611 return false;
1612 }
1613 }
1614
1615 REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
1616 if (!ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
1617 AR_PHY_RFBUS_GRANT_EN)) {
1618 DPRINTF(ah->ah_sc, ATH_DBG_PHY_IO,
1619 "%s: Could not kill baseband RX\n", __func__);
1620 return false;
1621 }
1622
1623 ath9k_hw_set_regs(ah, chan, macmode);
1624
1625 if (AR_SREV_9280_10_OR_LATER(ah)) {
1626 if (!(ath9k_hw_ar9280_set_channel(ah, chan))) {
1627 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
1628 "%s: failed to set channel\n", __func__);
1629 return false;
1630 }
1631 } else {
1632 if (!(ath9k_hw_set_channel(ah, chan))) {
1633 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
1634 "%s: failed to set channel\n", __func__);
1635 return false;
1636 }
1637 }
1638
1639 if (ath9k_hw_set_txpower(ah, chan,
1640 ath9k_regd_get_ctl(ah, chan),
1641 ath9k_regd_get_antenna_allowed(ah, chan),
1642 chan->maxRegTxPower * 2,
1643 min((u32) MAX_RATE_POWER,
1644 (u32) ah->ah_powerLimit)) != 0) {
1645 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
1646 "%s: error init'ing transmit power\n", __func__);
1647 return false;
1648 }
1649
1650 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
1651 if (IS_CHAN_CCK(chan))
1652 synthDelay = (4 * synthDelay) / 22;
1653 else
1654 synthDelay /= 10;
1655
1656 udelay(synthDelay + BASE_ACTIVATE_DELAY);
1657
1658 REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
1659
1660 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1661 ath9k_hw_set_delta_slope(ah, chan);
1662
1663 if (AR_SREV_9280_10_OR_LATER(ah))
1664 ath9k_hw_9280_spur_mitigate(ah, chan);
1665 else
1666 ath9k_hw_spur_mitigate(ah, chan);
1667
1668 if (!chan->oneTimeCalsDone)
1669 chan->oneTimeCalsDone = true;
1670
1671 return true;
1672}
1673
1674static void ath9k_hw_9280_spur_mitigate(struct ath_hal *ah, struct ath9k_channel *chan)
4671{ 1675{
4672 int bb_spur = AR_NO_SPUR; 1676 int bb_spur = AR_NO_SPUR;
4673 int freq; 1677 int freq;
@@ -4917,8 +1921,7 @@ static void ath9k_hw_9280_spur_mitigate(struct ath_hal *ah,
4917 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask); 1921 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
4918} 1922}
4919 1923
4920static void ath9k_hw_spur_mitigate(struct ath_hal *ah, 1924static void ath9k_hw_spur_mitigate(struct ath_hal *ah, struct ath9k_channel *chan)
4921 struct ath9k_channel *chan)
4922{ 1925{
4923 int bb_spur = AR_NO_SPUR; 1926 int bb_spur = AR_NO_SPUR;
4924 int bin, cur_bin; 1927 int bin, cur_bin;
@@ -5119,752 +2122,11 @@ static void ath9k_hw_spur_mitigate(struct ath_hal *ah,
5119 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask); 2122 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
5120} 2123}
5121 2124
5122static void ath9k_hw_init_chain_masks(struct ath_hal *ah) 2125bool ath9k_hw_reset(struct ath_hal *ah, struct ath9k_channel *chan,
5123{
5124 struct ath_hal_5416 *ahp = AH5416(ah);
5125 int rx_chainmask, tx_chainmask;
5126
5127 rx_chainmask = ahp->ah_rxchainmask;
5128 tx_chainmask = ahp->ah_txchainmask;
5129
5130 switch (rx_chainmask) {
5131 case 0x5:
5132 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
5133 AR_PHY_SWAP_ALT_CHAIN);
5134 case 0x3:
5135 if (((ah)->ah_macVersion <= AR_SREV_VERSION_9160)) {
5136 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, 0x7);
5137 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, 0x7);
5138 break;
5139 }
5140 case 0x1:
5141 case 0x2:
5142 if (!AR_SREV_9280(ah))
5143 break;
5144 case 0x7:
5145 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
5146 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
5147 break;
5148 default:
5149 break;
5150 }
5151
5152 REG_WRITE(ah, AR_SELFGEN_MASK, tx_chainmask);
5153 if (tx_chainmask == 0x5) {
5154 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
5155 AR_PHY_SWAP_ALT_CHAIN);
5156 }
5157 if (AR_SREV_9100(ah))
5158 REG_WRITE(ah, AR_PHY_ANALOG_SWAP,
5159 REG_READ(ah, AR_PHY_ANALOG_SWAP) | 0x00000001);
5160}
5161
5162static void ath9k_hw_set_addac(struct ath_hal *ah,
5163 struct ath9k_channel *chan)
5164{
5165 struct modal_eep_header *pModal;
5166 struct ath_hal_5416 *ahp = AH5416(ah);
5167 struct ar5416_eeprom *eep = &ahp->ah_eeprom;
5168 u8 biaslevel;
5169
5170 if (ah->ah_macVersion != AR_SREV_VERSION_9160)
5171 return;
5172
5173 if (ar5416_get_eep_rev(ahp) < AR5416_EEP_MINOR_VER_7)
5174 return;
5175
5176 pModal = &(eep->modalHeader[IS_CHAN_2GHZ(chan)]);
5177
5178 if (pModal->xpaBiasLvl != 0xff) {
5179 biaslevel = pModal->xpaBiasLvl;
5180 } else {
5181
5182 u16 resetFreqBin, freqBin, freqCount = 0;
5183 struct chan_centers centers;
5184
5185 ath9k_hw_get_channel_centers(ah, chan, &centers);
5186
5187 resetFreqBin =
5188 FREQ2FBIN(centers.synth_center, IS_CHAN_2GHZ(chan));
5189 freqBin = pModal->xpaBiasLvlFreq[0] & 0xff;
5190 biaslevel = (u8) (pModal->xpaBiasLvlFreq[0] >> 14);
5191
5192 freqCount++;
5193
5194 while (freqCount < 3) {
5195 if (pModal->xpaBiasLvlFreq[freqCount] == 0x0)
5196 break;
5197
5198 freqBin = pModal->xpaBiasLvlFreq[freqCount] & 0xff;
5199 if (resetFreqBin >= freqBin) {
5200 biaslevel =
5201 (u8) (pModal->
5202 xpaBiasLvlFreq[freqCount]
5203 >> 14);
5204 } else {
5205 break;
5206 }
5207 freqCount++;
5208 }
5209 }
5210
5211 if (IS_CHAN_2GHZ(chan)) {
5212 INI_RA(&ahp->ah_iniAddac, 7, 1) =
5213 (INI_RA(&ahp->ah_iniAddac, 7, 1) & (~0x18)) | biaslevel
5214 << 3;
5215 } else {
5216 INI_RA(&ahp->ah_iniAddac, 6, 1) =
5217 (INI_RA(&ahp->ah_iniAddac, 6, 1) & (~0xc0)) | biaslevel
5218 << 6;
5219 }
5220}
5221
5222static u32 ath9k_hw_mac_usec(struct ath_hal *ah, u32 clks)
5223{
5224 if (ah->ah_curchan != NULL)
5225 return clks /
5226 CLOCK_RATE[ath9k_hw_chan2wmode(ah, ah->ah_curchan)];
5227 else
5228 return clks / CLOCK_RATE[ATH9K_MODE_11B];
5229}
5230
5231static u32 ath9k_hw_mac_to_usec(struct ath_hal *ah, u32 clks)
5232{
5233 struct ath9k_channel *chan = ah->ah_curchan;
5234
5235 if (chan && IS_CHAN_HT40(chan))
5236 return ath9k_hw_mac_usec(ah, clks) / 2;
5237 else
5238 return ath9k_hw_mac_usec(ah, clks);
5239}
5240
5241static u32 ath9k_hw_mac_clks(struct ath_hal *ah, u32 usecs)
5242{
5243 if (ah->ah_curchan != NULL)
5244 return usecs * CLOCK_RATE[ath9k_hw_chan2wmode(ah,
5245 ah->ah_curchan)];
5246 else
5247 return usecs * CLOCK_RATE[ATH9K_MODE_11B];
5248}
5249
5250static u32 ath9k_hw_mac_to_clks(struct ath_hal *ah, u32 usecs)
5251{
5252 struct ath9k_channel *chan = ah->ah_curchan;
5253
5254 if (chan && IS_CHAN_HT40(chan))
5255 return ath9k_hw_mac_clks(ah, usecs) * 2;
5256 else
5257 return ath9k_hw_mac_clks(ah, usecs);
5258}
5259
5260static bool ath9k_hw_set_ack_timeout(struct ath_hal *ah, u32 us)
5261{
5262 struct ath_hal_5416 *ahp = AH5416(ah);
5263
5264 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_ACK))) {
5265 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "%s: bad ack timeout %u\n",
5266 __func__, us);
5267 ahp->ah_acktimeout = (u32) -1;
5268 return false;
5269 } else {
5270 REG_RMW_FIELD(ah, AR_TIME_OUT,
5271 AR_TIME_OUT_ACK, ath9k_hw_mac_to_clks(ah, us));
5272 ahp->ah_acktimeout = us;
5273 return true;
5274 }
5275}
5276
5277static bool ath9k_hw_set_cts_timeout(struct ath_hal *ah, u32 us)
5278{
5279 struct ath_hal_5416 *ahp = AH5416(ah);
5280
5281 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_CTS))) {
5282 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "%s: bad cts timeout %u\n",
5283 __func__, us);
5284 ahp->ah_ctstimeout = (u32) -1;
5285 return false;
5286 } else {
5287 REG_RMW_FIELD(ah, AR_TIME_OUT,
5288 AR_TIME_OUT_CTS, ath9k_hw_mac_to_clks(ah, us));
5289 ahp->ah_ctstimeout = us;
5290 return true;
5291 }
5292}
5293static bool ath9k_hw_set_global_txtimeout(struct ath_hal *ah,
5294 u32 tu)
5295{
5296 struct ath_hal_5416 *ahp = AH5416(ah);
5297
5298 if (tu > 0xFFFF) {
5299 DPRINTF(ah->ah_sc, ATH_DBG_XMIT,
5300 "%s: bad global tx timeout %u\n", __func__, tu);
5301 ahp->ah_globaltxtimeout = (u32) -1;
5302 return false;
5303 } else {
5304 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
5305 ahp->ah_globaltxtimeout = tu;
5306 return true;
5307 }
5308}
5309
5310bool ath9k_hw_setslottime(struct ath_hal *ah, u32 us)
5311{
5312 struct ath_hal_5416 *ahp = AH5416(ah);
5313
5314 if (us < ATH9K_SLOT_TIME_9 || us > ath9k_hw_mac_to_usec(ah, 0xffff)) {
5315 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "%s: bad slot time %u\n",
5316 __func__, us);
5317 ahp->ah_slottime = (u32) -1;
5318 return false;
5319 } else {
5320 REG_WRITE(ah, AR_D_GBL_IFS_SLOT, ath9k_hw_mac_to_clks(ah, us));
5321 ahp->ah_slottime = us;
5322 return true;
5323 }
5324}
5325
5326static void ath9k_hw_init_user_settings(struct ath_hal *ah)
5327{
5328 struct ath_hal_5416 *ahp = AH5416(ah);
5329
5330 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "--AP %s ahp->ah_miscMode 0x%x\n",
5331 __func__, ahp->ah_miscMode);
5332 if (ahp->ah_miscMode != 0)
5333 REG_WRITE(ah, AR_PCU_MISC,
5334 REG_READ(ah, AR_PCU_MISC) | ahp->ah_miscMode);
5335 if (ahp->ah_slottime != (u32) -1)
5336 ath9k_hw_setslottime(ah, ahp->ah_slottime);
5337 if (ahp->ah_acktimeout != (u32) -1)
5338 ath9k_hw_set_ack_timeout(ah, ahp->ah_acktimeout);
5339 if (ahp->ah_ctstimeout != (u32) -1)
5340 ath9k_hw_set_cts_timeout(ah, ahp->ah_ctstimeout);
5341 if (ahp->ah_globaltxtimeout != (u32) -1)
5342 ath9k_hw_set_global_txtimeout(ah, ahp->ah_globaltxtimeout);
5343}
5344
5345static int
5346ath9k_hw_process_ini(struct ath_hal *ah,
5347 struct ath9k_channel *chan,
5348 enum ath9k_ht_macmode macmode)
5349{
5350 int i, regWrites = 0;
5351 struct ath_hal_5416 *ahp = AH5416(ah);
5352 u32 modesIndex, freqIndex;
5353 int status;
5354
5355 switch (chan->chanmode) {
5356 case CHANNEL_A:
5357 case CHANNEL_A_HT20:
5358 modesIndex = 1;
5359 freqIndex = 1;
5360 break;
5361 case CHANNEL_A_HT40PLUS:
5362 case CHANNEL_A_HT40MINUS:
5363 modesIndex = 2;
5364 freqIndex = 1;
5365 break;
5366 case CHANNEL_G:
5367 case CHANNEL_G_HT20:
5368 case CHANNEL_B:
5369 modesIndex = 4;
5370 freqIndex = 2;
5371 break;
5372 case CHANNEL_G_HT40PLUS:
5373 case CHANNEL_G_HT40MINUS:
5374 modesIndex = 3;
5375 freqIndex = 2;
5376 break;
5377
5378 default:
5379 return -EINVAL;
5380 }
5381
5382 REG_WRITE(ah, AR_PHY(0), 0x00000007);
5383
5384 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_EXTERNAL_RADIO);
5385
5386 ath9k_hw_set_addac(ah, chan);
5387
5388 if (AR_SREV_5416_V22_OR_LATER(ah)) {
5389 REG_WRITE_ARRAY(&ahp->ah_iniAddac, 1, regWrites);
5390 } else {
5391 struct ar5416IniArray temp;
5392 u32 addacSize =
5393 sizeof(u32) * ahp->ah_iniAddac.ia_rows *
5394 ahp->ah_iniAddac.ia_columns;
5395
5396 memcpy(ahp->ah_addac5416_21,
5397 ahp->ah_iniAddac.ia_array, addacSize);
5398
5399 (ahp->ah_addac5416_21)[31 *
5400 ahp->ah_iniAddac.ia_columns + 1] = 0;
5401
5402 temp.ia_array = ahp->ah_addac5416_21;
5403 temp.ia_columns = ahp->ah_iniAddac.ia_columns;
5404 temp.ia_rows = ahp->ah_iniAddac.ia_rows;
5405 REG_WRITE_ARRAY(&temp, 1, regWrites);
5406 }
5407 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_INTERNAL_ADDAC);
5408
5409 for (i = 0; i < ahp->ah_iniModes.ia_rows; i++) {
5410 u32 reg = INI_RA(&ahp->ah_iniModes, i, 0);
5411 u32 val = INI_RA(&ahp->ah_iniModes, i, modesIndex);
5412
5413#ifdef CONFIG_SLOW_ANT_DIV
5414 if (ah->ah_devid == AR9280_DEVID_PCI)
5415 val = ath9k_hw_ini_fixup(ah, &ahp->ah_eeprom, reg,
5416 val);
5417#endif
5418
5419 REG_WRITE(ah, reg, val);
5420
5421 if (reg >= 0x7800 && reg < 0x78a0
5422 && ah->ah_config.analog_shiftreg) {
5423 udelay(100);
5424 }
5425
5426 DO_DELAY(regWrites);
5427 }
5428
5429 for (i = 0; i < ahp->ah_iniCommon.ia_rows; i++) {
5430 u32 reg = INI_RA(&ahp->ah_iniCommon, i, 0);
5431 u32 val = INI_RA(&ahp->ah_iniCommon, i, 1);
5432
5433 REG_WRITE(ah, reg, val);
5434
5435 if (reg >= 0x7800 && reg < 0x78a0
5436 && ah->ah_config.analog_shiftreg) {
5437 udelay(100);
5438 }
5439
5440 DO_DELAY(regWrites);
5441 }
5442
5443 ath9k_hw_write_regs(ah, modesIndex, freqIndex, regWrites);
5444
5445 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan)) {
5446 REG_WRITE_ARRAY(&ahp->ah_iniModesAdditional, modesIndex,
5447 regWrites);
5448 }
5449
5450 ath9k_hw_override_ini(ah, chan);
5451 ath9k_hw_set_regs(ah, chan, macmode);
5452 ath9k_hw_init_chain_masks(ah);
5453
5454 status = ath9k_hw_set_txpower(ah, &ahp->ah_eeprom, chan,
5455 ath9k_regd_get_ctl(ah, chan),
5456 ath9k_regd_get_antenna_allowed(ah,
5457 chan),
5458 chan->maxRegTxPower * 2,
5459 min((u32) MAX_RATE_POWER,
5460 (u32) ah->ah_powerLimit));
5461 if (status != 0) {
5462 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
5463 "%s: error init'ing transmit power\n", __func__);
5464 return -EIO;
5465 }
5466
5467 if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) {
5468 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
5469 "%s: ar5416SetRfRegs failed\n", __func__);
5470 return -EIO;
5471 }
5472
5473 return 0;
5474}
5475
5476static void ath9k_hw_setup_calibration(struct ath_hal *ah,
5477 struct hal_cal_list *currCal)
5478{
5479 REG_RMW_FIELD(ah, AR_PHY_TIMING_CTRL4(0),
5480 AR_PHY_TIMING_CTRL4_IQCAL_LOG_COUNT_MAX,
5481 currCal->calData->calCountMax);
5482
5483 switch (currCal->calData->calType) {
5484 case IQ_MISMATCH_CAL:
5485 REG_WRITE(ah, AR_PHY_CALMODE, AR_PHY_CALMODE_IQ);
5486 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
5487 "%s: starting IQ Mismatch Calibration\n",
5488 __func__);
5489 break;
5490 case ADC_GAIN_CAL:
5491 REG_WRITE(ah, AR_PHY_CALMODE, AR_PHY_CALMODE_ADC_GAIN);
5492 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
5493 "%s: starting ADC Gain Calibration\n", __func__);
5494 break;
5495 case ADC_DC_CAL:
5496 REG_WRITE(ah, AR_PHY_CALMODE, AR_PHY_CALMODE_ADC_DC_PER);
5497 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
5498 "%s: starting ADC DC Calibration\n", __func__);
5499 break;
5500 case ADC_DC_INIT_CAL:
5501 REG_WRITE(ah, AR_PHY_CALMODE, AR_PHY_CALMODE_ADC_DC_INIT);
5502 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
5503 "%s: starting Init ADC DC Calibration\n",
5504 __func__);
5505 break;
5506 }
5507
5508 REG_SET_BIT(ah, AR_PHY_TIMING_CTRL4(0),
5509 AR_PHY_TIMING_CTRL4_DO_CAL);
5510}
5511
5512static void ath9k_hw_reset_calibration(struct ath_hal *ah,
5513 struct hal_cal_list *currCal)
5514{
5515 struct ath_hal_5416 *ahp = AH5416(ah);
5516 int i;
5517
5518 ath9k_hw_setup_calibration(ah, currCal);
5519
5520 currCal->calState = CAL_RUNNING;
5521
5522 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
5523 ahp->ah_Meas0.sign[i] = 0;
5524 ahp->ah_Meas1.sign[i] = 0;
5525 ahp->ah_Meas2.sign[i] = 0;
5526 ahp->ah_Meas3.sign[i] = 0;
5527 }
5528
5529 ahp->ah_CalSamples = 0;
5530}
5531
5532static void
5533ath9k_hw_per_calibration(struct ath_hal *ah,
5534 struct ath9k_channel *ichan,
5535 u8 rxchainmask,
5536 struct hal_cal_list *currCal,
5537 bool *isCalDone)
5538{
5539 struct ath_hal_5416 *ahp = AH5416(ah);
5540
5541 *isCalDone = false;
5542
5543 if (currCal->calState == CAL_RUNNING) {
5544 if (!(REG_READ(ah,
5545 AR_PHY_TIMING_CTRL4(0)) &
5546 AR_PHY_TIMING_CTRL4_DO_CAL)) {
5547
5548 currCal->calData->calCollect(ah);
5549
5550 ahp->ah_CalSamples++;
5551
5552 if (ahp->ah_CalSamples >=
5553 currCal->calData->calNumSamples) {
5554 int i, numChains = 0;
5555 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
5556 if (rxchainmask & (1 << i))
5557 numChains++;
5558 }
5559
5560 currCal->calData->calPostProc(ah,
5561 numChains);
5562
5563 ichan->CalValid |=
5564 currCal->calData->calType;
5565 currCal->calState = CAL_DONE;
5566 *isCalDone = true;
5567 } else {
5568 ath9k_hw_setup_calibration(ah, currCal);
5569 }
5570 }
5571 } else if (!(ichan->CalValid & currCal->calData->calType)) {
5572 ath9k_hw_reset_calibration(ah, currCal);
5573 }
5574}
5575
5576static inline bool ath9k_hw_run_init_cals(struct ath_hal *ah,
5577 int init_cal_count)
5578{
5579 struct ath_hal_5416 *ahp = AH5416(ah);
5580 struct ath9k_channel ichan;
5581 bool isCalDone;
5582 struct hal_cal_list *currCal = ahp->ah_cal_list_curr;
5583 const struct hal_percal_data *calData = currCal->calData;
5584 int i;
5585
5586 if (currCal == NULL)
5587 return false;
5588
5589 ichan.CalValid = 0;
5590
5591 for (i = 0; i < init_cal_count; i++) {
5592 ath9k_hw_reset_calibration(ah, currCal);
5593
5594 if (!ath9k_hw_wait(ah, AR_PHY_TIMING_CTRL4(0),
5595 AR_PHY_TIMING_CTRL4_DO_CAL, 0)) {
5596 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
5597 "%s: Cal %d failed to complete in 100ms.\n",
5598 __func__, calData->calType);
5599
5600 ahp->ah_cal_list = ahp->ah_cal_list_last =
5601 ahp->ah_cal_list_curr = NULL;
5602 return false;
5603 }
5604
5605 ath9k_hw_per_calibration(ah, &ichan, ahp->ah_rxchainmask,
5606 currCal, &isCalDone);
5607 if (!isCalDone) {
5608 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
5609 "%s: Not able to run Init Cal %d.\n",
5610 __func__, calData->calType);
5611 }
5612 if (currCal->calNext) {
5613 currCal = currCal->calNext;
5614 calData = currCal->calData;
5615 }
5616 }
5617
5618 ahp->ah_cal_list = ahp->ah_cal_list_last = ahp->ah_cal_list_curr = NULL;
5619 return true;
5620}
5621
5622static bool
5623ath9k_hw_channel_change(struct ath_hal *ah,
5624 struct ath9k_channel *chan,
5625 enum ath9k_ht_macmode macmode)
5626{
5627 u32 synthDelay, qnum;
5628 struct ath_hal_5416 *ahp = AH5416(ah);
5629
5630 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
5631 if (ath9k_hw_numtxpending(ah, qnum)) {
5632 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
5633 "%s: Transmit frames pending on queue %d\n",
5634 __func__, qnum);
5635 return false;
5636 }
5637 }
5638
5639 REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
5640 if (!ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
5641 AR_PHY_RFBUS_GRANT_EN)) {
5642 DPRINTF(ah->ah_sc, ATH_DBG_PHY_IO,
5643 "%s: Could not kill baseband RX\n", __func__);
5644 return false;
5645 }
5646
5647 ath9k_hw_set_regs(ah, chan, macmode);
5648
5649 if (AR_SREV_9280_10_OR_LATER(ah)) {
5650 if (!(ath9k_hw_ar9280_set_channel(ah, chan))) {
5651 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
5652 "%s: failed to set channel\n", __func__);
5653 return false;
5654 }
5655 } else {
5656 if (!(ath9k_hw_set_channel(ah, chan))) {
5657 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
5658 "%s: failed to set channel\n", __func__);
5659 return false;
5660 }
5661 }
5662
5663 if (ath9k_hw_set_txpower(ah, &ahp->ah_eeprom, chan,
5664 ath9k_regd_get_ctl(ah, chan),
5665 ath9k_regd_get_antenna_allowed(ah, chan),
5666 chan->maxRegTxPower * 2,
5667 min((u32) MAX_RATE_POWER,
5668 (u32) ah->ah_powerLimit)) != 0) {
5669 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
5670 "%s: error init'ing transmit power\n", __func__);
5671 return false;
5672 }
5673
5674 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
5675 if (IS_CHAN_CCK(chan))
5676 synthDelay = (4 * synthDelay) / 22;
5677 else
5678 synthDelay /= 10;
5679
5680 udelay(synthDelay + BASE_ACTIVATE_DELAY);
5681
5682 REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
5683
5684 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
5685 ath9k_hw_set_delta_slope(ah, chan);
5686
5687 if (AR_SREV_9280_10_OR_LATER(ah))
5688 ath9k_hw_9280_spur_mitigate(ah, chan);
5689 else
5690 ath9k_hw_spur_mitigate(ah, chan);
5691
5692 if (!chan->oneTimeCalsDone)
5693 chan->oneTimeCalsDone = true;
5694
5695 return true;
5696}
5697
5698static bool ath9k_hw_chip_reset(struct ath_hal *ah,
5699 struct ath9k_channel *chan)
5700{
5701 struct ath_hal_5416 *ahp = AH5416(ah);
5702
5703 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
5704 return false;
5705
5706 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
5707 return false;
5708
5709 ahp->ah_chipFullSleep = false;
5710
5711 ath9k_hw_init_pll(ah, chan);
5712
5713 ath9k_hw_set_rfmode(ah, chan);
5714
5715 return true;
5716}
5717
5718static inline void ath9k_hw_set_dma(struct ath_hal *ah)
5719{
5720 u32 regval;
5721
5722 regval = REG_READ(ah, AR_AHB_MODE);
5723 REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN);
5724
5725 regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK;
5726 REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B);
5727
5728 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->ah_txTrigLevel);
5729
5730 regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK;
5731 REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B);
5732
5733 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
5734
5735 if (AR_SREV_9285(ah)) {
5736 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
5737 AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
5738 } else {
5739 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
5740 AR_PCU_TXBUF_CTRL_USABLE_SIZE);
5741 }
5742}
5743
5744bool ath9k_hw_stopdmarecv(struct ath_hal *ah)
5745{
5746 REG_WRITE(ah, AR_CR, AR_CR_RXD);
5747 if (!ath9k_hw_wait(ah, AR_CR, AR_CR_RXE, 0)) {
5748 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
5749 "%s: dma failed to stop in 10ms\n"
5750 "AR_CR=0x%08x\nAR_DIAG_SW=0x%08x\n",
5751 __func__,
5752 REG_READ(ah, AR_CR), REG_READ(ah, AR_DIAG_SW));
5753 return false;
5754 } else {
5755 return true;
5756 }
5757}
5758
5759void ath9k_hw_startpcureceive(struct ath_hal *ah)
5760{
5761 REG_CLR_BIT(ah, AR_DIAG_SW,
5762 (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
5763
5764 ath9k_enable_mib_counters(ah);
5765
5766 ath9k_ani_reset(ah);
5767}
5768
5769void ath9k_hw_stoppcurecv(struct ath_hal *ah)
5770{
5771 REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_DIS);
5772
5773 ath9k_hw_disable_mib_counters(ah);
5774}
5775
5776static bool ath9k_hw_iscal_supported(struct ath_hal *ah,
5777 struct ath9k_channel *chan,
5778 enum hal_cal_types calType)
5779{
5780 struct ath_hal_5416 *ahp = AH5416(ah);
5781 bool retval = false;
5782
5783 switch (calType & ahp->ah_suppCals) {
5784 case IQ_MISMATCH_CAL:
5785 if (!IS_CHAN_B(chan))
5786 retval = true;
5787 break;
5788 case ADC_GAIN_CAL:
5789 case ADC_DC_CAL:
5790 if (!IS_CHAN_B(chan)
5791 && !(IS_CHAN_2GHZ(chan) && IS_CHAN_HT20(chan)))
5792 retval = true;
5793 break;
5794 }
5795
5796 return retval;
5797}
5798
5799static bool ath9k_hw_init_cal(struct ath_hal *ah,
5800 struct ath9k_channel *chan)
5801{
5802 struct ath_hal_5416 *ahp = AH5416(ah);
5803 struct ath9k_channel *ichan =
5804 ath9k_regd_check_channel(ah, chan);
5805
5806 REG_WRITE(ah, AR_PHY_AGC_CONTROL,
5807 REG_READ(ah, AR_PHY_AGC_CONTROL) |
5808 AR_PHY_AGC_CONTROL_CAL);
5809
5810 if (!ath9k_hw_wait
5811 (ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_CAL, 0)) {
5812 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
5813 "%s: offset calibration failed to complete in 1ms; "
5814 "noisy environment?\n", __func__);
5815 return false;
5816 }
5817
5818 REG_WRITE(ah, AR_PHY_AGC_CONTROL,
5819 REG_READ(ah, AR_PHY_AGC_CONTROL) |
5820 AR_PHY_AGC_CONTROL_NF);
5821
5822 ahp->ah_cal_list = ahp->ah_cal_list_last = ahp->ah_cal_list_curr =
5823 NULL;
5824
5825 if (AR_SREV_9100(ah) || AR_SREV_9160_10_OR_LATER(ah)) {
5826 if (ath9k_hw_iscal_supported(ah, chan, ADC_GAIN_CAL)) {
5827 INIT_CAL(&ahp->ah_adcGainCalData);
5828 INSERT_CAL(ahp, &ahp->ah_adcGainCalData);
5829 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
5830 "%s: enabling ADC Gain Calibration.\n",
5831 __func__);
5832 }
5833 if (ath9k_hw_iscal_supported(ah, chan, ADC_DC_CAL)) {
5834 INIT_CAL(&ahp->ah_adcDcCalData);
5835 INSERT_CAL(ahp, &ahp->ah_adcDcCalData);
5836 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
5837 "%s: enabling ADC DC Calibration.\n",
5838 __func__);
5839 }
5840 if (ath9k_hw_iscal_supported(ah, chan, IQ_MISMATCH_CAL)) {
5841 INIT_CAL(&ahp->ah_iqCalData);
5842 INSERT_CAL(ahp, &ahp->ah_iqCalData);
5843 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
5844 "%s: enabling IQ Calibration.\n",
5845 __func__);
5846 }
5847
5848 ahp->ah_cal_list_curr = ahp->ah_cal_list;
5849
5850 if (ahp->ah_cal_list_curr)
5851 ath9k_hw_reset_calibration(ah,
5852 ahp->ah_cal_list_curr);
5853 }
5854
5855 ichan->CalValid = 0;
5856
5857 return true;
5858}
5859
5860
5861bool ath9k_hw_reset(struct ath_hal *ah,
5862 struct ath9k_channel *chan,
5863 enum ath9k_ht_macmode macmode, 2126 enum ath9k_ht_macmode macmode,
5864 u8 txchainmask, u8 rxchainmask, 2127 u8 txchainmask, u8 rxchainmask,
5865 enum ath9k_ht_extprotspacing extprotspacing, 2128 enum ath9k_ht_extprotspacing extprotspacing,
5866 bool bChannelChange, 2129 bool bChannelChange, int *status)
5867 int *status)
5868{ 2130{
5869 u32 saveLedState; 2131 u32 saveLedState;
5870 struct ath_hal_5416 *ahp = AH5416(ah); 2132 struct ath_hal_5416 *ahp = AH5416(ah);
@@ -5885,8 +2147,8 @@ bool ath9k_hw_reset(struct ath_hal *ah,
5885 2147
5886 if (ath9k_hw_check_chan(ah, chan) == NULL) { 2148 if (ath9k_hw_check_chan(ah, chan) == NULL) {
5887 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL, 2149 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
5888 "%s: invalid channel %u/0x%x; no mapping\n", 2150 "%s: invalid channel %u/0x%x; no mapping\n",
5889 __func__, chan->channel, chan->channelFlags); 2151 __func__, chan->channel, chan->channelFlags);
5890 ecode = -EINVAL; 2152 ecode = -EINVAL;
5891 goto bad; 2153 goto bad;
5892 } 2154 }
@@ -5964,7 +2226,7 @@ bool ath9k_hw_reset(struct ath_hal *ah,
5964 2226
5965 if (!ath9k_hw_eeprom_set_board_values(ah, chan)) { 2227 if (!ath9k_hw_eeprom_set_board_values(ah, chan)) {
5966 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, 2228 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
5967 "%s: error setting board options\n", __func__); 2229 "%s: error setting board options\n", __func__);
5968 ecode = -EIO; 2230 ecode = -EIO;
5969 goto bad; 2231 goto bad;
5970 } 2232 }
@@ -6054,15 +2316,15 @@ bool ath9k_hw_reset(struct ath_hal *ah,
6054 mask = REG_READ(ah, AR_CFG); 2316 mask = REG_READ(ah, AR_CFG);
6055 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) { 2317 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
6056 DPRINTF(ah->ah_sc, ATH_DBG_RESET, 2318 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
6057 "%s CFG Byte Swap Set 0x%x\n", __func__, 2319 "%s CFG Byte Swap Set 0x%x\n", __func__,
6058 mask); 2320 mask);
6059 } else { 2321 } else {
6060 mask = 2322 mask =
6061 INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB; 2323 INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
6062 REG_WRITE(ah, AR_CFG, mask); 2324 REG_WRITE(ah, AR_CFG, mask);
6063 DPRINTF(ah->ah_sc, ATH_DBG_RESET, 2325 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
6064 "%s Setting CFG 0x%x\n", __func__, 2326 "%s Setting CFG 0x%x\n", __func__,
6065 REG_READ(ah, AR_CFG)); 2327 REG_READ(ah, AR_CFG));
6066 } 2328 }
6067 } else { 2329 } else {
6068#ifdef __BIG_ENDIAN 2330#ifdef __BIG_ENDIAN
@@ -6077,692 +2339,403 @@ bad:
6077 return false; 2339 return false;
6078} 2340}
6079 2341
6080bool ath9k_hw_phy_disable(struct ath_hal *ah) 2342/************************/
6081{ 2343/* Key Cache Management */
6082 return ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM); 2344/************************/
6083}
6084
6085bool ath9k_hw_disable(struct ath_hal *ah)
6086{
6087 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
6088 return false;
6089
6090 return ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD);
6091}
6092 2345
6093bool 2346bool ath9k_hw_keyreset(struct ath_hal *ah, u16 entry)
6094ath9k_hw_calibrate(struct ath_hal *ah, struct ath9k_channel *chan,
6095 u8 rxchainmask, bool longcal,
6096 bool *isCalDone)
6097{ 2347{
6098 struct ath_hal_5416 *ahp = AH5416(ah); 2348 u32 keyType;
6099 struct hal_cal_list *currCal = ahp->ah_cal_list_curr;
6100 struct ath9k_channel *ichan =
6101 ath9k_regd_check_channel(ah, chan);
6102
6103 *isCalDone = true;
6104 2349
6105 if (ichan == NULL) { 2350 if (entry >= ah->ah_caps.keycache_size) {
6106 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL, 2351 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
6107 "%s: invalid channel %u/0x%x; no mapping\n", 2352 "%s: entry %u out of range\n", __func__, entry);
6108 __func__, chan->channel, chan->channelFlags);
6109 return false; 2353 return false;
6110 } 2354 }
6111 2355
6112 if (currCal && 2356 keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry));
6113 (currCal->calState == CAL_RUNNING ||
6114 currCal->calState == CAL_WAITING)) {
6115 ath9k_hw_per_calibration(ah, ichan, rxchainmask, currCal,
6116 isCalDone);
6117 if (*isCalDone) {
6118 ahp->ah_cal_list_curr = currCal = currCal->calNext;
6119
6120 if (currCal->calState == CAL_WAITING) {
6121 *isCalDone = false;
6122 ath9k_hw_reset_calibration(ah, currCal);
6123 }
6124 }
6125 }
6126 2357
6127 if (longcal) { 2358 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0);
6128 ath9k_hw_getnf(ah, ichan); 2359 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0);
6129 ath9k_hw_loadnf(ah, ah->ah_curchan); 2360 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0);
6130 ath9k_hw_start_nfcal(ah); 2361 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0);
2362 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0);
2363 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR);
2364 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0);
2365 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0);
2366
2367 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2368 u16 micentry = entry + 64;
6131 2369
6132 if ((ichan->channelFlags & CHANNEL_CW_INT) != 0) { 2370 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0);
2371 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
2372 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0);
2373 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
6133 2374
6134 chan->channelFlags |= CHANNEL_CW_INT;
6135 ichan->channelFlags &= ~CHANNEL_CW_INT;
6136 }
6137 } 2375 }
6138 2376
2377 if (ah->ah_curchan == NULL)
2378 return true;
2379
6139 return true; 2380 return true;
6140} 2381}
6141 2382
6142static void ath9k_hw_iqcal_collect(struct ath_hal *ah) 2383bool ath9k_hw_keysetmac(struct ath_hal *ah, u16 entry, const u8 *mac)
6143{ 2384{
6144 struct ath_hal_5416 *ahp = AH5416(ah); 2385 u32 macHi, macLo;
6145 int i;
6146 2386
6147 for (i = 0; i < AR5416_MAX_CHAINS; i++) { 2387 if (entry >= ah->ah_caps.keycache_size) {
6148 ahp->ah_totalPowerMeasI[i] += 2388 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
6149 REG_READ(ah, AR_PHY_CAL_MEAS_0(i)); 2389 "%s: entry %u out of range\n", __func__, entry);
6150 ahp->ah_totalPowerMeasQ[i] += 2390 return false;
6151 REG_READ(ah, AR_PHY_CAL_MEAS_1(i));
6152 ahp->ah_totalIqCorrMeas[i] +=
6153 (int32_t) REG_READ(ah, AR_PHY_CAL_MEAS_2(i));
6154 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
6155 "%d: Chn %d pmi=0x%08x;pmq=0x%08x;iqcm=0x%08x;\n",
6156 ahp->ah_CalSamples, i, ahp->ah_totalPowerMeasI[i],
6157 ahp->ah_totalPowerMeasQ[i],
6158 ahp->ah_totalIqCorrMeas[i]);
6159 } 2391 }
6160}
6161 2392
6162static void ath9k_hw_adc_gaincal_collect(struct ath_hal *ah) 2393 if (mac != NULL) {
6163{ 2394 macHi = (mac[5] << 8) | mac[4];
6164 struct ath_hal_5416 *ahp = AH5416(ah); 2395 macLo = (mac[3] << 24) |
6165 int i; 2396 (mac[2] << 16) |
6166 2397 (mac[1] << 8) |
6167 for (i = 0; i < AR5416_MAX_CHAINS; i++) { 2398 mac[0];
6168 ahp->ah_totalAdcIOddPhase[i] += 2399 macLo >>= 1;
6169 REG_READ(ah, AR_PHY_CAL_MEAS_0(i)); 2400 macLo |= (macHi & 1) << 31;
6170 ahp->ah_totalAdcIEvenPhase[i] += 2401 macHi >>= 1;
6171 REG_READ(ah, AR_PHY_CAL_MEAS_1(i)); 2402 } else {
6172 ahp->ah_totalAdcQOddPhase[i] += 2403 macLo = macHi = 0;
6173 REG_READ(ah, AR_PHY_CAL_MEAS_2(i));
6174 ahp->ah_totalAdcQEvenPhase[i] +=
6175 REG_READ(ah, AR_PHY_CAL_MEAS_3(i));
6176
6177 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
6178 "%d: Chn %d oddi=0x%08x; eveni=0x%08x; "
6179 "oddq=0x%08x; evenq=0x%08x;\n",
6180 ahp->ah_CalSamples, i,
6181 ahp->ah_totalAdcIOddPhase[i],
6182 ahp->ah_totalAdcIEvenPhase[i],
6183 ahp->ah_totalAdcQOddPhase[i],
6184 ahp->ah_totalAdcQEvenPhase[i]);
6185 } 2404 }
2405 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo);
2406 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID);
2407
2408 return true;
6186} 2409}
6187 2410
6188static void ath9k_hw_adc_dccal_collect(struct ath_hal *ah) 2411bool ath9k_hw_set_keycache_entry(struct ath_hal *ah, u16 entry,
2412 const struct ath9k_keyval *k,
2413 const u8 *mac, int xorKey)
6189{ 2414{
2415 const struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
2416 u32 key0, key1, key2, key3, key4;
2417 u32 keyType;
2418 u32 xorMask = xorKey ?
2419 (ATH9K_KEY_XOR << 24 | ATH9K_KEY_XOR << 16 | ATH9K_KEY_XOR << 8
2420 | ATH9K_KEY_XOR) : 0;
6190 struct ath_hal_5416 *ahp = AH5416(ah); 2421 struct ath_hal_5416 *ahp = AH5416(ah);
6191 int i;
6192 2422
6193 for (i = 0; i < AR5416_MAX_CHAINS; i++) { 2423 if (entry >= pCap->keycache_size) {
6194 ahp->ah_totalAdcDcOffsetIOddPhase[i] += 2424 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
6195 (int32_t) REG_READ(ah, AR_PHY_CAL_MEAS_0(i)); 2425 "%s: entry %u out of range\n", __func__, entry);
6196 ahp->ah_totalAdcDcOffsetIEvenPhase[i] += 2426 return false;
6197 (int32_t) REG_READ(ah, AR_PHY_CAL_MEAS_1(i));
6198 ahp->ah_totalAdcDcOffsetQOddPhase[i] +=
6199 (int32_t) REG_READ(ah, AR_PHY_CAL_MEAS_2(i));
6200 ahp->ah_totalAdcDcOffsetQEvenPhase[i] +=
6201 (int32_t) REG_READ(ah, AR_PHY_CAL_MEAS_3(i));
6202
6203 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
6204 "%d: Chn %d oddi=0x%08x; eveni=0x%08x; "
6205 "oddq=0x%08x; evenq=0x%08x;\n",
6206 ahp->ah_CalSamples, i,
6207 ahp->ah_totalAdcDcOffsetIOddPhase[i],
6208 ahp->ah_totalAdcDcOffsetIEvenPhase[i],
6209 ahp->ah_totalAdcDcOffsetQOddPhase[i],
6210 ahp->ah_totalAdcDcOffsetQEvenPhase[i]);
6211 } 2427 }
6212}
6213 2428
6214static void ath9k_hw_iqcalibrate(struct ath_hal *ah, u8 numChains) 2429 switch (k->kv_type) {
6215{ 2430 case ATH9K_CIPHER_AES_OCB:
6216 struct ath_hal_5416 *ahp = AH5416(ah); 2431 keyType = AR_KEYTABLE_TYPE_AES;
6217 u32 powerMeasQ, powerMeasI, iqCorrMeas; 2432 break;
6218 u32 qCoffDenom, iCoffDenom; 2433 case ATH9K_CIPHER_AES_CCM:
6219 int32_t qCoff, iCoff; 2434 if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) {
6220 int iqCorrNeg, i; 2435 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
2436 "%s: AES-CCM not supported by "
2437 "mac rev 0x%x\n", __func__,
2438 ah->ah_macRev);
2439 return false;
2440 }
2441 keyType = AR_KEYTABLE_TYPE_CCM;
2442 break;
2443 case ATH9K_CIPHER_TKIP:
2444 keyType = AR_KEYTABLE_TYPE_TKIP;
2445 if (ATH9K_IS_MIC_ENABLED(ah)
2446 && entry + 64 >= pCap->keycache_size) {
2447 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
2448 "%s: entry %u inappropriate for TKIP\n",
2449 __func__, entry);
2450 return false;
2451 }
2452 break;
2453 case ATH9K_CIPHER_WEP:
2454 if (k->kv_len < LEN_WEP40) {
2455 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
2456 "%s: WEP key length %u too small\n",
2457 __func__, k->kv_len);
2458 return false;
2459 }
2460 if (k->kv_len <= LEN_WEP40)
2461 keyType = AR_KEYTABLE_TYPE_40;
2462 else if (k->kv_len <= LEN_WEP104)
2463 keyType = AR_KEYTABLE_TYPE_104;
2464 else
2465 keyType = AR_KEYTABLE_TYPE_128;
2466 break;
2467 case ATH9K_CIPHER_CLR:
2468 keyType = AR_KEYTABLE_TYPE_CLR;
2469 break;
2470 default:
2471 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
2472 "%s: cipher %u not supported\n", __func__,
2473 k->kv_type);
2474 return false;
2475 }
6221 2476
6222 for (i = 0; i < numChains; i++) { 2477 key0 = get_unaligned_le32(k->kv_val + 0) ^ xorMask;
6223 powerMeasI = ahp->ah_totalPowerMeasI[i]; 2478 key1 = (get_unaligned_le16(k->kv_val + 4) ^ xorMask) & 0xffff;
6224 powerMeasQ = ahp->ah_totalPowerMeasQ[i]; 2479 key2 = get_unaligned_le32(k->kv_val + 6) ^ xorMask;
6225 iqCorrMeas = ahp->ah_totalIqCorrMeas[i]; 2480 key3 = (get_unaligned_le16(k->kv_val + 10) ^ xorMask) & 0xffff;
2481 key4 = get_unaligned_le32(k->kv_val + 12) ^ xorMask;
2482 if (k->kv_len <= LEN_WEP104)
2483 key4 &= 0xff;
6226 2484
6227 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE, 2485 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
6228 "Starting IQ Cal and Correction for Chain %d\n", 2486 u16 micentry = entry + 64;
6229 i);
6230 2487
6231 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE, 2488 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0);
6232 "Orignal: Chn %diq_corr_meas = 0x%08x\n", 2489 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1);
6233 i, ahp->ah_totalIqCorrMeas[i]); 2490 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2491 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
2492 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2493 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
2494 (void) ath9k_hw_keysetmac(ah, entry, mac);
6234 2495
6235 iqCorrNeg = 0; 2496 if (ahp->ah_miscMode & AR_PCU_MIC_NEW_LOC_ENA) {
2497 u32 mic0, mic1, mic2, mic3, mic4;
6236 2498
2499 mic0 = get_unaligned_le32(k->kv_mic + 0);
2500 mic2 = get_unaligned_le32(k->kv_mic + 4);
2501 mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff;
2502 mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff;
2503 mic4 = get_unaligned_le32(k->kv_txmic + 4);
2504 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2505 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1);
2506 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2507 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3);
2508 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4);
2509 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2510 AR_KEYTABLE_TYPE_CLR);
6237 2511
6238 if (iqCorrMeas > 0x80000000) { 2512 } else {
6239 iqCorrMeas = (0xffffffff - iqCorrMeas) + 1; 2513 u32 mic0, mic2;
6240 iqCorrNeg = 1;
6241 }
6242 2514
6243 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE, 2515 mic0 = get_unaligned_le32(k->kv_mic + 0);
6244 "Chn %d pwr_meas_i = 0x%08x\n", i, powerMeasI); 2516 mic2 = get_unaligned_le32(k->kv_mic + 4);
6245 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE, 2517 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
6246 "Chn %d pwr_meas_q = 0x%08x\n", i, powerMeasQ); 2518 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
6247 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE, "iqCorrNeg is 0x%08x\n", 2519 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
6248 iqCorrNeg); 2520 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
6249 2521 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
6250 iCoffDenom = (powerMeasI / 2 + powerMeasQ / 2) / 128; 2522 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
6251 qCoffDenom = powerMeasQ / 64; 2523 AR_KEYTABLE_TYPE_CLR);
6252
6253 if (powerMeasQ != 0) {
6254
6255 iCoff = iqCorrMeas / iCoffDenom;
6256 qCoff = powerMeasI / qCoffDenom - 64;
6257 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
6258 "Chn %d iCoff = 0x%08x\n", i, iCoff);
6259 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
6260 "Chn %d qCoff = 0x%08x\n", i, qCoff);
6261
6262
6263 iCoff = iCoff & 0x3f;
6264 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
6265 "New: Chn %d iCoff = 0x%08x\n", i, iCoff);
6266 if (iqCorrNeg == 0x0)
6267 iCoff = 0x40 - iCoff;
6268
6269 if (qCoff > 15)
6270 qCoff = 15;
6271 else if (qCoff <= -16)
6272 qCoff = 16;
6273
6274 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
6275 "Chn %d : iCoff = 0x%x qCoff = 0x%x\n",
6276 i, iCoff, qCoff);
6277
6278 REG_RMW_FIELD(ah, AR_PHY_TIMING_CTRL4(i),
6279 AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF,
6280 iCoff);
6281 REG_RMW_FIELD(ah, AR_PHY_TIMING_CTRL4(i),
6282 AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF,
6283 qCoff);
6284 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
6285 "IQ Cal and Correction done for Chain %d\n",
6286 i);
6287 } 2524 }
6288 } 2525 REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0);
6289 2526 REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0);
6290 REG_SET_BIT(ah, AR_PHY_TIMING_CTRL4(0), 2527 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
6291 AR_PHY_TIMING_CTRL4_IQCORR_ENABLE); 2528 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
6292} 2529 } else {
2530 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2531 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
2532 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2533 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
2534 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2535 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
6293 2536
6294static void 2537 (void) ath9k_hw_keysetmac(ah, entry, mac);
6295ath9k_hw_adc_gaincal_calibrate(struct ath_hal *ah, u8 numChains)
6296{
6297 struct ath_hal_5416 *ahp = AH5416(ah);
6298 u32 iOddMeasOffset, iEvenMeasOffset, qOddMeasOffset,
6299 qEvenMeasOffset;
6300 u32 qGainMismatch, iGainMismatch, val, i;
6301
6302 for (i = 0; i < numChains; i++) {
6303 iOddMeasOffset = ahp->ah_totalAdcIOddPhase[i];
6304 iEvenMeasOffset = ahp->ah_totalAdcIEvenPhase[i];
6305 qOddMeasOffset = ahp->ah_totalAdcQOddPhase[i];
6306 qEvenMeasOffset = ahp->ah_totalAdcQEvenPhase[i];
6307
6308 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
6309 "Starting ADC Gain Cal for Chain %d\n", i);
6310
6311 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
6312 "Chn %d pwr_meas_odd_i = 0x%08x\n", i,
6313 iOddMeasOffset);
6314 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
6315 "Chn %d pwr_meas_even_i = 0x%08x\n", i,
6316 iEvenMeasOffset);
6317 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
6318 "Chn %d pwr_meas_odd_q = 0x%08x\n", i,
6319 qOddMeasOffset);
6320 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
6321 "Chn %d pwr_meas_even_q = 0x%08x\n", i,
6322 qEvenMeasOffset);
6323
6324 if (iOddMeasOffset != 0 && qEvenMeasOffset != 0) {
6325 iGainMismatch =
6326 ((iEvenMeasOffset * 32) /
6327 iOddMeasOffset) & 0x3f;
6328 qGainMismatch =
6329 ((qOddMeasOffset * 32) /
6330 qEvenMeasOffset) & 0x3f;
6331
6332 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
6333 "Chn %d gain_mismatch_i = 0x%08x\n", i,
6334 iGainMismatch);
6335 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
6336 "Chn %d gain_mismatch_q = 0x%08x\n", i,
6337 qGainMismatch);
6338
6339 val = REG_READ(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(i));
6340 val &= 0xfffff000;
6341 val |= (qGainMismatch) | (iGainMismatch << 6);
6342 REG_WRITE(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(i), val);
6343
6344 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
6345 "ADC Gain Cal done for Chain %d\n", i);
6346 }
6347 } 2538 }
6348 2539
6349 REG_WRITE(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(0), 2540 if (ah->ah_curchan == NULL)
6350 REG_READ(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(0)) | 2541 return true;
6351 AR_PHY_NEW_ADC_GAIN_CORR_ENABLE); 2542
2543 return true;
6352} 2544}
6353 2545
6354static void 2546bool ath9k_hw_keyisvalid(struct ath_hal *ah, u16 entry)
6355ath9k_hw_adc_dccal_calibrate(struct ath_hal *ah, u8 numChains)
6356{ 2547{
6357 struct ath_hal_5416 *ahp = AH5416(ah); 2548 if (entry < ah->ah_caps.keycache_size) {
6358 u32 iOddMeasOffset, iEvenMeasOffset, val, i; 2549 u32 val = REG_READ(ah, AR_KEYTABLE_MAC1(entry));
6359 int32_t qOddMeasOffset, qEvenMeasOffset, qDcMismatch, iDcMismatch; 2550 if (val & AR_KEYTABLE_VALID)
6360 const struct hal_percal_data *calData = 2551 return true;
6361 ahp->ah_cal_list_curr->calData;
6362 u32 numSamples =
6363 (1 << (calData->calCountMax + 5)) * calData->calNumSamples;
6364
6365 for (i = 0; i < numChains; i++) {
6366 iOddMeasOffset = ahp->ah_totalAdcDcOffsetIOddPhase[i];
6367 iEvenMeasOffset = ahp->ah_totalAdcDcOffsetIEvenPhase[i];
6368 qOddMeasOffset = ahp->ah_totalAdcDcOffsetQOddPhase[i];
6369 qEvenMeasOffset = ahp->ah_totalAdcDcOffsetQEvenPhase[i];
6370
6371 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
6372 "Starting ADC DC Offset Cal for Chain %d\n", i);
6373
6374 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
6375 "Chn %d pwr_meas_odd_i = %d\n", i,
6376 iOddMeasOffset);
6377 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
6378 "Chn %d pwr_meas_even_i = %d\n", i,
6379 iEvenMeasOffset);
6380 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
6381 "Chn %d pwr_meas_odd_q = %d\n", i,
6382 qOddMeasOffset);
6383 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
6384 "Chn %d pwr_meas_even_q = %d\n", i,
6385 qEvenMeasOffset);
6386
6387 iDcMismatch = (((iEvenMeasOffset - iOddMeasOffset) * 2) /
6388 numSamples) & 0x1ff;
6389 qDcMismatch = (((qOddMeasOffset - qEvenMeasOffset) * 2) /
6390 numSamples) & 0x1ff;
6391
6392 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
6393 "Chn %d dc_offset_mismatch_i = 0x%08x\n", i,
6394 iDcMismatch);
6395 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
6396 "Chn %d dc_offset_mismatch_q = 0x%08x\n", i,
6397 qDcMismatch);
6398
6399 val = REG_READ(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(i));
6400 val &= 0xc0000fff;
6401 val |= (qDcMismatch << 12) | (iDcMismatch << 21);
6402 REG_WRITE(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(i), val);
6403
6404 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
6405 "ADC DC Offset Cal done for Chain %d\n", i);
6406 } 2552 }
6407 2553 return false;
6408 REG_WRITE(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(0),
6409 REG_READ(ah, AR_PHY_NEW_ADC_DC_GAIN_CORR(0)) |
6410 AR_PHY_NEW_ADC_DC_OFFSET_CORR_ENABLE);
6411} 2554}
6412 2555
6413bool ath9k_hw_set_txpowerlimit(struct ath_hal *ah, u32 limit) 2556/******************************/
6414{ 2557/* Power Management (Chipset) */
6415 struct ath_hal_5416 *ahp = AH5416(ah); 2558/******************************/
6416 struct ath9k_channel *chan = ah->ah_curchan;
6417
6418 ah->ah_powerLimit = min(limit, (u32) MAX_RATE_POWER);
6419
6420 if (ath9k_hw_set_txpower(ah, &ahp->ah_eeprom, chan,
6421 ath9k_regd_get_ctl(ah, chan),
6422 ath9k_regd_get_antenna_allowed(ah,
6423 chan),
6424 chan->maxRegTxPower * 2,
6425 min((u32) MAX_RATE_POWER,
6426 (u32) ah->ah_powerLimit)) != 0)
6427 return false;
6428 2559
6429 return true; 2560static void ath9k_set_power_sleep(struct ath_hal *ah, int setChip)
6430}
6431
6432void
6433ath9k_hw_get_channel_centers(struct ath_hal *ah,
6434 struct ath9k_channel *chan,
6435 struct chan_centers *centers)
6436{ 2561{
6437 int8_t extoff; 2562 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
6438 struct ath_hal_5416 *ahp = AH5416(ah); 2563 if (setChip) {
6439 2564 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
6440 if (!IS_CHAN_HT40(chan)) { 2565 AR_RTC_FORCE_WAKE_EN);
6441 centers->ctl_center = centers->ext_center = 2566 if (!AR_SREV_9100(ah))
6442 centers->synth_center = chan->channel; 2567 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
6443 return;
6444 }
6445 2568
6446 if ((chan->chanmode == CHANNEL_A_HT40PLUS) || 2569 REG_CLR_BIT(ah, (u16) (AR_RTC_RESET),
6447 (chan->chanmode == CHANNEL_G_HT40PLUS)) { 2570 AR_RTC_RESET_EN);
6448 centers->synth_center =
6449 chan->channel + HT40_CHANNEL_CENTER_SHIFT;
6450 extoff = 1;
6451 } else {
6452 centers->synth_center =
6453 chan->channel - HT40_CHANNEL_CENTER_SHIFT;
6454 extoff = -1;
6455 } 2571 }
6456
6457 centers->ctl_center = centers->synth_center - (extoff *
6458 HT40_CHANNEL_CENTER_SHIFT);
6459 centers->ext_center = centers->synth_center + (extoff *
6460 ((ahp->
6461 ah_extprotspacing
6462 ==
6463 ATH9K_HT_EXTPROTSPACING_20)
6464 ?
6465 HT40_CHANNEL_CENTER_SHIFT
6466 : 15));
6467
6468} 2572}
6469 2573
6470void 2574static void ath9k_set_power_network_sleep(struct ath_hal *ah, int setChip)
6471ath9k_hw_reset_calvalid(struct ath_hal *ah, struct ath9k_channel *chan,
6472 bool *isCalDone)
6473{ 2575{
6474 struct ath_hal_5416 *ahp = AH5416(ah); 2576 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
6475 struct ath9k_channel *ichan = 2577 if (setChip) {
6476 ath9k_regd_check_channel(ah, chan); 2578 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
6477 struct hal_cal_list *currCal = ahp->ah_cal_list_curr;
6478
6479 *isCalDone = true;
6480
6481 if (!AR_SREV_9100(ah) && !AR_SREV_9160_10_OR_LATER(ah))
6482 return;
6483
6484 if (currCal == NULL)
6485 return;
6486
6487 if (ichan == NULL) {
6488 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
6489 "%s: invalid channel %u/0x%x; no mapping\n",
6490 __func__, chan->channel, chan->channelFlags);
6491 return;
6492 }
6493
6494 2579
6495 if (currCal->calState != CAL_DONE) { 2580 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
6496 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE, 2581 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
6497 "%s: Calibration state incorrect, %d\n", 2582 AR_RTC_FORCE_WAKE_ON_INT);
6498 __func__, currCal->calState); 2583 } else {
6499 return; 2584 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2585 AR_RTC_FORCE_WAKE_EN);
2586 }
6500 } 2587 }
6501
6502
6503 if (!ath9k_hw_iscal_supported(ah, chan, currCal->calData->calType))
6504 return;
6505
6506 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
6507 "%s: Resetting Cal %d state for channel %u/0x%x\n",
6508 __func__, currCal->calData->calType, chan->channel,
6509 chan->channelFlags);
6510
6511 ichan->CalValid &= ~currCal->calData->calType;
6512 currCal->calState = CAL_WAITING;
6513
6514 *isCalDone = false;
6515} 2588}
6516 2589
6517void ath9k_hw_getmac(struct ath_hal *ah, u8 *mac) 2590static bool ath9k_hw_set_power_awake(struct ath_hal *ah,
2591 int setChip)
6518{ 2592{
6519 struct ath_hal_5416 *ahp = AH5416(ah); 2593 u32 val;
2594 int i;
6520 2595
6521 memcpy(mac, ahp->ah_macaddr, ETH_ALEN); 2596 if (setChip) {
6522} 2597 if ((REG_READ(ah, AR_RTC_STATUS) &
2598 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
2599 if (ath9k_hw_set_reset_reg(ah,
2600 ATH9K_RESET_POWER_ON) != true) {
2601 return false;
2602 }
2603 }
2604 if (AR_SREV_9100(ah))
2605 REG_SET_BIT(ah, AR_RTC_RESET,
2606 AR_RTC_RESET_EN);
6523 2607
6524bool ath9k_hw_setmac(struct ath_hal *ah, const u8 *mac) 2608 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
6525{ 2609 AR_RTC_FORCE_WAKE_EN);
6526 struct ath_hal_5416 *ahp = AH5416(ah); 2610 udelay(50);
6527 2611
6528 memcpy(ahp->ah_macaddr, mac, ETH_ALEN); 2612 for (i = POWER_UP_TIME / 50; i > 0; i--) {
6529 return true; 2613 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
6530} 2614 if (val == AR_RTC_STATUS_ON)
2615 break;
2616 udelay(50);
2617 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2618 AR_RTC_FORCE_WAKE_EN);
2619 }
2620 if (i == 0) {
2621 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
2622 "%s: Failed to wakeup in %uus\n",
2623 __func__, POWER_UP_TIME / 20);
2624 return false;
2625 }
2626 }
6531 2627
6532void ath9k_hw_getbssidmask(struct ath_hal *ah, u8 *mask) 2628 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
6533{
6534 struct ath_hal_5416 *ahp = AH5416(ah);
6535 2629
6536 memcpy(mask, ahp->ah_bssidmask, ETH_ALEN); 2630 return true;
6537} 2631}
6538 2632
6539bool 2633bool ath9k_hw_setpower(struct ath_hal *ah,
6540ath9k_hw_setbssidmask(struct ath_hal *ah, const u8 *mask) 2634 enum ath9k_power_mode mode)
6541{ 2635{
6542 struct ath_hal_5416 *ahp = AH5416(ah); 2636 struct ath_hal_5416 *ahp = AH5416(ah);
2637 static const char *modes[] = {
2638 "AWAKE",
2639 "FULL-SLEEP",
2640 "NETWORK SLEEP",
2641 "UNDEFINED"
2642 };
2643 int status = true, setChip = true;
6543 2644
6544 memcpy(ahp->ah_bssidmask, mask, ETH_ALEN); 2645 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT, "%s: %s -> %s (%s)\n", __func__,
2646 modes[ahp->ah_powerMode], modes[mode],
2647 setChip ? "set chip " : "");
6545 2648
6546 REG_WRITE(ah, AR_BSSMSKL, get_unaligned_le32(ahp->ah_bssidmask)); 2649 switch (mode) {
6547 REG_WRITE(ah, AR_BSSMSKU, get_unaligned_le16(ahp->ah_bssidmask + 4)); 2650 case ATH9K_PM_AWAKE:
2651 status = ath9k_hw_set_power_awake(ah, setChip);
2652 break;
2653 case ATH9K_PM_FULL_SLEEP:
2654 ath9k_set_power_sleep(ah, setChip);
2655 ahp->ah_chipFullSleep = true;
2656 break;
2657 case ATH9K_PM_NETWORK_SLEEP:
2658 ath9k_set_power_network_sleep(ah, setChip);
2659 break;
2660 default:
2661 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
2662 "%s: unknown power mode %u\n", __func__, mode);
2663 return false;
2664 }
2665 ahp->ah_powerMode = mode;
6548 2666
6549 return true; 2667 return status;
6550} 2668}
6551 2669
6552void 2670void ath9k_hw_configpcipowersave(struct ath_hal *ah, int restore)
6553ath9k_hw_write_associd(struct ath_hal *ah, const u8 *bssid,
6554 u16 assocId)
6555{ 2671{
6556 struct ath_hal_5416 *ahp = AH5416(ah); 2672 struct ath_hal_5416 *ahp = AH5416(ah);
2673 u8 i;
6557 2674
6558 memcpy(ahp->ah_bssid, bssid, ETH_ALEN); 2675 if (ah->ah_isPciExpress != true)
6559 ahp->ah_assocId = assocId; 2676 return;
6560
6561 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(ahp->ah_bssid));
6562 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(ahp->ah_bssid + 4) |
6563 ((assocId & 0x3fff) << AR_BSS_ID1_AID_S));
6564}
6565
6566u64 ath9k_hw_gettsf64(struct ath_hal *ah)
6567{
6568 u64 tsf;
6569 2677
6570 tsf = REG_READ(ah, AR_TSF_U32); 2678 if (ah->ah_config.pcie_powersave_enable == 2)
6571 tsf = (tsf << 32) | REG_READ(ah, AR_TSF_L32); 2679 return;
6572 return tsf;
6573}
6574 2680
6575void ath9k_hw_reset_tsf(struct ath_hal *ah) 2681 if (restore)
6576{ 2682 return;
6577 int count;
6578 2683
6579 count = 0; 2684 if (AR_SREV_9280_20_OR_LATER(ah)) {
6580 while (REG_READ(ah, AR_SLP32_MODE) & AR_SLP32_TSF_WRITE_STATUS) { 2685 for (i = 0; i < ahp->ah_iniPcieSerdes.ia_rows; i++) {
6581 count++; 2686 REG_WRITE(ah, INI_RA(&ahp->ah_iniPcieSerdes, i, 0),
6582 if (count > 10) { 2687 INI_RA(&ahp->ah_iniPcieSerdes, i, 1));
6583 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
6584 "%s: AR_SLP32_TSF_WRITE_STATUS limit exceeded\n",
6585 __func__);
6586 break;
6587 } 2688 }
6588 udelay(10); 2689 udelay(1000);
6589 } 2690 } else if (AR_SREV_9280(ah) &&
6590 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE); 2691 (ah->ah_macRev == AR_SREV_REVISION_9280_10)) {
6591} 2692 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fd00);
6592 2693 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
6593u32 ath9k_hw_getdefantenna(struct ath_hal *ah)
6594{
6595 return REG_READ(ah, AR_DEF_ANTENNA) & 0x7;
6596}
6597 2694
6598void ath9k_hw_setantenna(struct ath_hal *ah, u32 antenna) 2695 REG_WRITE(ah, AR_PCIE_SERDES, 0xa8000019);
6599{ 2696 REG_WRITE(ah, AR_PCIE_SERDES, 0x13160820);
6600 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7)); 2697 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980560);
6601}
6602 2698
6603bool 2699 if (ah->ah_config.pcie_clock_req)
6604ath9k_hw_setantennaswitch(struct ath_hal *ah, 2700 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffc);
6605 enum ath9k_ant_setting settings, 2701 else
6606 struct ath9k_channel *chan, 2702 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffd);
6607 u8 *tx_chainmask,
6608 u8 *rx_chainmask,
6609 u8 *antenna_cfgd)
6610{
6611 struct ath_hal_5416 *ahp = AH5416(ah);
6612 static u8 tx_chainmask_cfg, rx_chainmask_cfg;
6613 2703
6614 if (AR_SREV_9280(ah)) { 2704 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
6615 if (!tx_chainmask_cfg) { 2705 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
2706 REG_WRITE(ah, AR_PCIE_SERDES, 0x00043007);
6616 2707
6617 tx_chainmask_cfg = *tx_chainmask; 2708 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
6618 rx_chainmask_cfg = *rx_chainmask;
6619 }
6620 2709
6621 switch (settings) { 2710 udelay(1000);
6622 case ATH9K_ANT_FIXED_A:
6623 *tx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
6624 *rx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
6625 *antenna_cfgd = true;
6626 break;
6627 case ATH9K_ANT_FIXED_B:
6628 if (ah->ah_caps.tx_chainmask >
6629 ATH9K_ANTENNA1_CHAINMASK) {
6630 *tx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
6631 }
6632 *rx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
6633 *antenna_cfgd = true;
6634 break;
6635 case ATH9K_ANT_VARIABLE:
6636 *tx_chainmask = tx_chainmask_cfg;
6637 *rx_chainmask = rx_chainmask_cfg;
6638 *antenna_cfgd = true;
6639 break;
6640 default:
6641 break;
6642 }
6643 } else { 2711 } else {
6644 ahp->ah_diversityControl = settings; 2712 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
2713 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
2714 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
2715 REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
2716 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
2717 REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
2718 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
2719 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
2720 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
2721 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
6645 } 2722 }
6646 2723
6647 return true; 2724 REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
6648}
6649
6650void ath9k_hw_setopmode(struct ath_hal *ah)
6651{
6652 ath9k_hw_set_operating_mode(ah, ah->ah_opmode);
6653}
6654
6655bool
6656ath9k_hw_getcapability(struct ath_hal *ah, enum ath9k_capability_type type,
6657 u32 capability, u32 *result)
6658{
6659 struct ath_hal_5416 *ahp = AH5416(ah);
6660 const struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
6661 2725
6662 switch (type) { 2726 if (ah->ah_config.pcie_waen) {
6663 case ATH9K_CAP_CIPHER: 2727 REG_WRITE(ah, AR_WA, ah->ah_config.pcie_waen);
6664 switch (capability) { 2728 } else {
6665 case ATH9K_CIPHER_AES_CCM: 2729 if (AR_SREV_9280(ah))
6666 case ATH9K_CIPHER_AES_OCB: 2730 REG_WRITE(ah, AR_WA, 0x0040073f);
6667 case ATH9K_CIPHER_TKIP: 2731 else
6668 case ATH9K_CIPHER_WEP: 2732 REG_WRITE(ah, AR_WA, 0x0000073f);
6669 case ATH9K_CIPHER_MIC:
6670 case ATH9K_CIPHER_CLR:
6671 return true;
6672 default:
6673 return false;
6674 }
6675 case ATH9K_CAP_TKIP_MIC:
6676 switch (capability) {
6677 case 0:
6678 return true;
6679 case 1:
6680 return (ahp->ah_staId1Defaults &
6681 AR_STA_ID1_CRPT_MIC_ENABLE) ? true :
6682 false;
6683 }
6684 case ATH9K_CAP_TKIP_SPLIT:
6685 return (ahp->ah_miscMode & AR_PCU_MIC_NEW_LOC_ENA) ?
6686 false : true;
6687 case ATH9K_CAP_WME_TKIPMIC:
6688 return 0;
6689 case ATH9K_CAP_PHYCOUNTERS:
6690 return ahp->ah_hasHwPhyCounters ? 0 : -ENXIO;
6691 case ATH9K_CAP_DIVERSITY:
6692 return (REG_READ(ah, AR_PHY_CCK_DETECT) &
6693 AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV) ?
6694 true : false;
6695 case ATH9K_CAP_PHYDIAG:
6696 return true;
6697 case ATH9K_CAP_MCAST_KEYSRCH:
6698 switch (capability) {
6699 case 0:
6700 return true;
6701 case 1:
6702 if (REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) {
6703 return false;
6704 } else {
6705 return (ahp->ah_staId1Defaults &
6706 AR_STA_ID1_MCAST_KSRCH) ? true :
6707 false;
6708 }
6709 }
6710 return false;
6711 case ATH9K_CAP_TSF_ADJUST:
6712 return (ahp->ah_miscMode & AR_PCU_TX_ADD_TSF) ?
6713 true : false;
6714 case ATH9K_CAP_RFSILENT:
6715 if (capability == 3)
6716 return false;
6717 case ATH9K_CAP_ANT_CFG_2GHZ:
6718 *result = pCap->num_antcfg_2ghz;
6719 return true;
6720 case ATH9K_CAP_ANT_CFG_5GHZ:
6721 *result = pCap->num_antcfg_5ghz;
6722 return true;
6723 case ATH9K_CAP_TXPOW:
6724 switch (capability) {
6725 case 0:
6726 return 0;
6727 case 1:
6728 *result = ah->ah_powerLimit;
6729 return 0;
6730 case 2:
6731 *result = ah->ah_maxPowerLevel;
6732 return 0;
6733 case 3:
6734 *result = ah->ah_tpScale;
6735 return 0;
6736 }
6737 return false;
6738 default:
6739 return false;
6740 } 2733 }
6741} 2734}
6742 2735
6743int 2736/**********************/
6744ath9k_hw_select_antconfig(struct ath_hal *ah, u32 cfg) 2737/* Interrupt Handling */
6745{ 2738/**********************/
6746 struct ath_hal_5416 *ahp = AH5416(ah);
6747 struct ath9k_channel *chan = ah->ah_curchan;
6748 const struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
6749 u16 ant_config;
6750 u32 halNumAntConfig;
6751
6752 halNumAntConfig =
6753 IS_CHAN_2GHZ(chan) ? pCap->num_antcfg_2ghz : pCap->
6754 num_antcfg_5ghz;
6755
6756 if (cfg < halNumAntConfig) {
6757 if (!ath9k_hw_get_eeprom_antenna_cfg(ahp, chan,
6758 cfg, &ant_config)) {
6759 REG_WRITE(ah, AR_PHY_SWITCH_COM, ant_config);
6760 return 0;
6761 }
6762 }
6763
6764 return -EINVAL;
6765}
6766 2739
6767bool ath9k_hw_intrpend(struct ath_hal *ah) 2740bool ath9k_hw_intrpend(struct ath_hal *ah)
6768{ 2741{
@@ -6790,6 +2763,7 @@ bool ath9k_hw_getisr(struct ath_hal *ah, enum ath9k_int *masked)
6790 struct ath9k_hw_capabilities *pCap = &ah->ah_caps; 2763 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
6791 u32 sync_cause = 0; 2764 u32 sync_cause = 0;
6792 bool fatal_int = false; 2765 bool fatal_int = false;
2766 struct ath_hal_5416 *ahp = AH5416(ah);
6793 2767
6794 if (!AR_SREV_9100(ah)) { 2768 if (!AR_SREV_9100(ah)) {
6795 if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) { 2769 if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
@@ -6799,9 +2773,8 @@ bool ath9k_hw_getisr(struct ath_hal *ah, enum ath9k_int *masked)
6799 } 2773 }
6800 } 2774 }
6801 2775
6802 sync_cause = 2776 sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) &
6803 REG_READ(ah, 2777 AR_INTR_SYNC_DEFAULT;
6804 AR_INTR_SYNC_CAUSE) & AR_INTR_SYNC_DEFAULT;
6805 2778
6806 *masked = 0; 2779 *masked = 0;
6807 2780
@@ -6813,8 +2786,6 @@ bool ath9k_hw_getisr(struct ath_hal *ah, enum ath9k_int *masked)
6813 } 2786 }
6814 2787
6815 if (isr) { 2788 if (isr) {
6816 struct ath_hal_5416 *ahp = AH5416(ah);
6817
6818 if (isr & AR_ISR_BCNMISC) { 2789 if (isr & AR_ISR_BCNMISC) {
6819 u32 isr2; 2790 u32 isr2;
6820 isr2 = REG_READ(ah, AR_ISR_S2); 2791 isr2 = REG_READ(ah, AR_ISR_S2);
@@ -6841,7 +2812,6 @@ bool ath9k_hw_getisr(struct ath_hal *ah, enum ath9k_int *masked)
6841 *masked = isr & ATH9K_INT_COMMON; 2812 *masked = isr & ATH9K_INT_COMMON;
6842 2813
6843 if (ahp->ah_intrMitigation) { 2814 if (ahp->ah_intrMitigation) {
6844
6845 if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM)) 2815 if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
6846 *masked |= ATH9K_INT_RX; 2816 *masked |= ATH9K_INT_RX;
6847 } 2817 }
@@ -6866,8 +2836,8 @@ bool ath9k_hw_getisr(struct ath_hal *ah, enum ath9k_int *masked)
6866 2836
6867 if (isr & AR_ISR_RXORN) { 2837 if (isr & AR_ISR_RXORN) {
6868 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, 2838 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT,
6869 "%s: receive FIFO overrun interrupt\n", 2839 "%s: receive FIFO overrun interrupt\n",
6870 __func__); 2840 __func__);
6871 } 2841 }
6872 2842
6873 if (!AR_SREV_9100(ah)) { 2843 if (!AR_SREV_9100(ah)) {
@@ -6880,8 +2850,10 @@ bool ath9k_hw_getisr(struct ath_hal *ah, enum ath9k_int *masked)
6880 2850
6881 *masked |= mask2; 2851 *masked |= mask2;
6882 } 2852 }
2853
6883 if (AR_SREV_9100(ah)) 2854 if (AR_SREV_9100(ah))
6884 return true; 2855 return true;
2856
6885 if (sync_cause) { 2857 if (sync_cause) {
6886 fatal_int = 2858 fatal_int =
6887 (sync_cause & 2859 (sync_cause &
@@ -6891,32 +2863,33 @@ bool ath9k_hw_getisr(struct ath_hal *ah, enum ath9k_int *masked)
6891 if (fatal_int) { 2863 if (fatal_int) {
6892 if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) { 2864 if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
6893 DPRINTF(ah->ah_sc, ATH_DBG_ANY, 2865 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
6894 "%s: received PCI FATAL interrupt\n", 2866 "%s: received PCI FATAL interrupt\n",
6895 __func__); 2867 __func__);
6896 } 2868 }
6897 if (sync_cause & AR_INTR_SYNC_HOST1_PERR) { 2869 if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
6898 DPRINTF(ah->ah_sc, ATH_DBG_ANY, 2870 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
6899 "%s: received PCI PERR interrupt\n", 2871 "%s: received PCI PERR interrupt\n",
6900 __func__); 2872 __func__);
6901 } 2873 }
6902 } 2874 }
6903 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) { 2875 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
6904 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, 2876 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT,
6905 "%s: AR_INTR_SYNC_RADM_CPL_TIMEOUT\n", 2877 "%s: AR_INTR_SYNC_RADM_CPL_TIMEOUT\n",
6906 __func__); 2878 __func__);
6907 REG_WRITE(ah, AR_RC, AR_RC_HOSTIF); 2879 REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
6908 REG_WRITE(ah, AR_RC, 0); 2880 REG_WRITE(ah, AR_RC, 0);
6909 *masked |= ATH9K_INT_FATAL; 2881 *masked |= ATH9K_INT_FATAL;
6910 } 2882 }
6911 if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) { 2883 if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) {
6912 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, 2884 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT,
6913 "%s: AR_INTR_SYNC_LOCAL_TIMEOUT\n", 2885 "%s: AR_INTR_SYNC_LOCAL_TIMEOUT\n",
6914 __func__); 2886 __func__);
6915 } 2887 }
6916 2888
6917 REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause); 2889 REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
6918 (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR); 2890 (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
6919 } 2891 }
2892
6920 return true; 2893 return true;
6921} 2894}
6922 2895
@@ -7034,9 +3007,11 @@ enum ath9k_int ath9k_hw_set_interrupts(struct ath_hal *ah, enum ath9k_int ints)
7034 return omask; 3007 return omask;
7035} 3008}
7036 3009
7037void 3010/*******************/
7038ath9k_hw_beaconinit(struct ath_hal *ah, 3011/* Beacon Handling */
7039 u32 next_beacon, u32 beacon_period) 3012/*******************/
3013
3014void ath9k_hw_beaconinit(struct ath_hal *ah, u32 next_beacon, u32 beacon_period)
7040{ 3015{
7041 struct ath_hal_5416 *ahp = AH5416(ah); 3016 struct ath_hal_5416 *ahp = AH5416(ah);
7042 int flags = 0; 3017 int flags = 0;
@@ -7088,9 +3063,8 @@ ath9k_hw_beaconinit(struct ath_hal *ah,
7088 REG_SET_BIT(ah, AR_TIMER_MODE, flags); 3063 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
7089} 3064}
7090 3065
7091void 3066void ath9k_hw_set_sta_beacon_timers(struct ath_hal *ah,
7092ath9k_hw_set_sta_beacon_timers(struct ath_hal *ah, 3067 const struct ath9k_beacon_state *bs)
7093 const struct ath9k_beacon_state *bs)
7094{ 3068{
7095 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout; 3069 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
7096 struct ath9k_hw_capabilities *pCap = &ah->ah_caps; 3070 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
@@ -7153,1421 +3127,869 @@ ath9k_hw_set_sta_beacon_timers(struct ath_hal *ah,
7153 3127
7154} 3128}
7155 3129
7156bool ath9k_hw_keyisvalid(struct ath_hal *ah, u16 entry) 3130/***************/
7157{ 3131/* Rate tables */
7158 if (entry < ah->ah_caps.keycache_size) { 3132/***************/
7159 u32 val = REG_READ(ah, AR_KEYTABLE_MAC1(entry));
7160 if (val & AR_KEYTABLE_VALID)
7161 return true;
7162 }
7163 return false;
7164}
7165 3133
7166bool ath9k_hw_keyreset(struct ath_hal *ah, u16 entry) 3134static struct ath9k_rate_table ar5416_11a_table = {
7167{ 3135 8,
7168 u32 keyType; 3136 {0},
3137 {
3138 {true, PHY_OFDM, 6000, 0x0b, 0x00, (0x80 | 12), 0},
3139 {true, PHY_OFDM, 9000, 0x0f, 0x00, 18, 0},
3140 {true, PHY_OFDM, 12000, 0x0a, 0x00, (0x80 | 24), 2},
3141 {true, PHY_OFDM, 18000, 0x0e, 0x00, 36, 2},
3142 {true, PHY_OFDM, 24000, 0x09, 0x00, (0x80 | 48), 4},
3143 {true, PHY_OFDM, 36000, 0x0d, 0x00, 72, 4},
3144 {true, PHY_OFDM, 48000, 0x08, 0x00, 96, 4},
3145 {true, PHY_OFDM, 54000, 0x0c, 0x00, 108, 4}
3146 },
3147};
7169 3148
7170 if (entry >= ah->ah_caps.keycache_size) { 3149static struct ath9k_rate_table ar5416_11b_table = {
7171 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE, 3150 4,
7172 "%s: entry %u out of range\n", __func__, entry); 3151 {0},
7173 return false; 3152 {
7174 } 3153 {true, PHY_CCK, 1000, 0x1b, 0x00, (0x80 | 2), 0},
7175 keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry)); 3154 {true, PHY_CCK, 2000, 0x1a, 0x04, (0x80 | 4), 1},
3155 {true, PHY_CCK, 5500, 0x19, 0x04, (0x80 | 11), 1},
3156 {true, PHY_CCK, 11000, 0x18, 0x04, (0x80 | 22), 1}
3157 },
3158};
7176 3159
7177 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0); 3160static struct ath9k_rate_table ar5416_11g_table = {
7178 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0); 3161 12,
7179 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0); 3162 {0},
7180 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0); 3163 {
7181 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0); 3164 {true, PHY_CCK, 1000, 0x1b, 0x00, (0x80 | 2), 0},
7182 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR); 3165 {true, PHY_CCK, 2000, 0x1a, 0x04, (0x80 | 4), 1},
7183 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0); 3166 {true, PHY_CCK, 5500, 0x19, 0x04, (0x80 | 11), 2},
7184 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0); 3167 {true, PHY_CCK, 11000, 0x18, 0x04, (0x80 | 22), 3},
7185 3168
7186 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) { 3169 {false, PHY_OFDM, 6000, 0x0b, 0x00, 12, 4},
7187 u16 micentry = entry + 64; 3170 {false, PHY_OFDM, 9000, 0x0f, 0x00, 18, 4},
3171 {true, PHY_OFDM, 12000, 0x0a, 0x00, 24, 6},
3172 {true, PHY_OFDM, 18000, 0x0e, 0x00, 36, 6},
3173 {true, PHY_OFDM, 24000, 0x09, 0x00, 48, 8},
3174 {true, PHY_OFDM, 36000, 0x0d, 0x00, 72, 8},
3175 {true, PHY_OFDM, 48000, 0x08, 0x00, 96, 8},
3176 {true, PHY_OFDM, 54000, 0x0c, 0x00, 108, 8}
3177 },
3178};
7188 3179
7189 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0); 3180static struct ath9k_rate_table ar5416_11ng_table = {
7190 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0); 3181 28,
7191 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0); 3182 {0},
7192 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0); 3183 {
3184 {true, PHY_CCK, 1000, 0x1b, 0x00, (0x80 | 2), 0},
3185 {true, PHY_CCK, 2000, 0x1a, 0x04, (0x80 | 4), 1},
3186 {true, PHY_CCK, 5500, 0x19, 0x04, (0x80 | 11), 2},
3187 {true, PHY_CCK, 11000, 0x18, 0x04, (0x80 | 22), 3},
7193 3188
7194 } 3189 {false, PHY_OFDM, 6000, 0x0b, 0x00, 12, 4},
3190 {false, PHY_OFDM, 9000, 0x0f, 0x00, 18, 4},
3191 {true, PHY_OFDM, 12000, 0x0a, 0x00, 24, 6},
3192 {true, PHY_OFDM, 18000, 0x0e, 0x00, 36, 6},
3193 {true, PHY_OFDM, 24000, 0x09, 0x00, 48, 8},
3194 {true, PHY_OFDM, 36000, 0x0d, 0x00, 72, 8},
3195 {true, PHY_OFDM, 48000, 0x08, 0x00, 96, 8},
3196 {true, PHY_OFDM, 54000, 0x0c, 0x00, 108, 8},
3197 {true, PHY_HT, 6500, 0x80, 0x00, 0, 4},
3198 {true, PHY_HT, 13000, 0x81, 0x00, 1, 6},
3199 {true, PHY_HT, 19500, 0x82, 0x00, 2, 6},
3200 {true, PHY_HT, 26000, 0x83, 0x00, 3, 8},
3201 {true, PHY_HT, 39000, 0x84, 0x00, 4, 8},
3202 {true, PHY_HT, 52000, 0x85, 0x00, 5, 8},
3203 {true, PHY_HT, 58500, 0x86, 0x00, 6, 8},
3204 {true, PHY_HT, 65000, 0x87, 0x00, 7, 8},
3205 {true, PHY_HT, 13000, 0x88, 0x00, 8, 4},
3206 {true, PHY_HT, 26000, 0x89, 0x00, 9, 6},
3207 {true, PHY_HT, 39000, 0x8a, 0x00, 10, 6},
3208 {true, PHY_HT, 52000, 0x8b, 0x00, 11, 8},
3209 {true, PHY_HT, 78000, 0x8c, 0x00, 12, 8},
3210 {true, PHY_HT, 104000, 0x8d, 0x00, 13, 8},
3211 {true, PHY_HT, 117000, 0x8e, 0x00, 14, 8},
3212 {true, PHY_HT, 130000, 0x8f, 0x00, 15, 8},
3213 },
3214};
7195 3215
7196 return true; 3216static struct ath9k_rate_table ar5416_11na_table = {
7197} 3217 24,
3218 {0},
3219 {
3220 {true, PHY_OFDM, 6000, 0x0b, 0x00, (0x80 | 12), 0},
3221 {true, PHY_OFDM, 9000, 0x0f, 0x00, 18, 0},
3222 {true, PHY_OFDM, 12000, 0x0a, 0x00, (0x80 | 24), 2},
3223 {true, PHY_OFDM, 18000, 0x0e, 0x00, 36, 2},
3224 {true, PHY_OFDM, 24000, 0x09, 0x00, (0x80 | 48), 4},
3225 {true, PHY_OFDM, 36000, 0x0d, 0x00, 72, 4},
3226 {true, PHY_OFDM, 48000, 0x08, 0x00, 96, 4},
3227 {true, PHY_OFDM, 54000, 0x0c, 0x00, 108, 4},
3228 {true, PHY_HT, 6500, 0x80, 0x00, 0, 0},
3229 {true, PHY_HT, 13000, 0x81, 0x00, 1, 2},
3230 {true, PHY_HT, 19500, 0x82, 0x00, 2, 2},
3231 {true, PHY_HT, 26000, 0x83, 0x00, 3, 4},
3232 {true, PHY_HT, 39000, 0x84, 0x00, 4, 4},
3233 {true, PHY_HT, 52000, 0x85, 0x00, 5, 4},
3234 {true, PHY_HT, 58500, 0x86, 0x00, 6, 4},
3235 {true, PHY_HT, 65000, 0x87, 0x00, 7, 4},
3236 {true, PHY_HT, 13000, 0x88, 0x00, 8, 0},
3237 {true, PHY_HT, 26000, 0x89, 0x00, 9, 2},
3238 {true, PHY_HT, 39000, 0x8a, 0x00, 10, 2},
3239 {true, PHY_HT, 52000, 0x8b, 0x00, 11, 4},
3240 {true, PHY_HT, 78000, 0x8c, 0x00, 12, 4},
3241 {true, PHY_HT, 104000, 0x8d, 0x00, 13, 4},
3242 {true, PHY_HT, 117000, 0x8e, 0x00, 14, 4},
3243 {true, PHY_HT, 130000, 0x8f, 0x00, 15, 4},
3244 },
3245};
7198 3246
7199bool 3247static void ath9k_hw_setup_rate_table(struct ath_hal *ah,
7200ath9k_hw_keysetmac(struct ath_hal *ah, u16 entry, 3248 struct ath9k_rate_table *rt)
7201 const u8 *mac)
7202{ 3249{
7203 u32 macHi, macLo; 3250 int i;
7204 3251
7205 if (entry >= ah->ah_caps.keycache_size) { 3252 if (rt->rateCodeToIndex[0] != 0)
7206 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE, 3253 return;
7207 "%s: entry %u out of range\n", __func__, entry);
7208 return false;
7209 }
7210 3254
7211 if (mac != NULL) { 3255 for (i = 0; i < 256; i++)
7212 macHi = (mac[5] << 8) | mac[4]; 3256 rt->rateCodeToIndex[i] = (u8) -1;
7213 macLo = (mac[3] << 24) | (mac[2] << 16)
7214 | (mac[1] << 8) | mac[0];
7215 macLo >>= 1;
7216 macLo |= (macHi & 1) << 31;
7217 macHi >>= 1;
7218 } else {
7219 macLo = macHi = 0;
7220 }
7221 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo);
7222 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID);
7223 3257
7224 return true; 3258 for (i = 0; i < rt->rateCount; i++) {
3259 u8 code = rt->info[i].rateCode;
3260 u8 cix = rt->info[i].controlRate;
3261
3262 rt->rateCodeToIndex[code] = i;
3263 rt->rateCodeToIndex[code | rt->info[i].shortPreamble] = i;
3264
3265 rt->info[i].lpAckDuration =
3266 ath9k_hw_computetxtime(ah, rt,
3267 WLAN_CTRL_FRAME_SIZE,
3268 cix,
3269 false);
3270 rt->info[i].spAckDuration =
3271 ath9k_hw_computetxtime(ah, rt,
3272 WLAN_CTRL_FRAME_SIZE,
3273 cix,
3274 true);
3275 }
7225} 3276}
7226 3277
7227bool 3278const struct ath9k_rate_table *ath9k_hw_getratetable(struct ath_hal *ah,
7228ath9k_hw_set_keycache_entry(struct ath_hal *ah, u16 entry, 3279 u32 mode)
7229 const struct ath9k_keyval *k,
7230 const u8 *mac, int xorKey)
7231{ 3280{
7232 const struct ath9k_hw_capabilities *pCap = &ah->ah_caps; 3281 struct ath9k_rate_table *rt;
7233 u32 key0, key1, key2, key3, key4;
7234 u32 keyType;
7235 u32 xorMask = xorKey ?
7236 (ATH9K_KEY_XOR << 24 | ATH9K_KEY_XOR << 16 | ATH9K_KEY_XOR << 8
7237 | ATH9K_KEY_XOR) : 0;
7238 struct ath_hal_5416 *ahp = AH5416(ah);
7239 3282
7240 if (entry >= pCap->keycache_size) { 3283 switch (mode) {
7241 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE, 3284 case ATH9K_MODE_11A:
7242 "%s: entry %u out of range\n", __func__, entry); 3285 rt = &ar5416_11a_table;
7243 return false;
7244 }
7245 switch (k->kv_type) {
7246 case ATH9K_CIPHER_AES_OCB:
7247 keyType = AR_KEYTABLE_TYPE_AES;
7248 break; 3286 break;
7249 case ATH9K_CIPHER_AES_CCM: 3287 case ATH9K_MODE_11B:
7250 if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) { 3288 rt = &ar5416_11b_table;
7251 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
7252 "%s: AES-CCM not supported by "
7253 "mac rev 0x%x\n", __func__,
7254 ah->ah_macRev);
7255 return false;
7256 }
7257 keyType = AR_KEYTABLE_TYPE_CCM;
7258 break; 3289 break;
7259 case ATH9K_CIPHER_TKIP: 3290 case ATH9K_MODE_11G:
7260 keyType = AR_KEYTABLE_TYPE_TKIP; 3291 rt = &ar5416_11g_table;
7261 if (ATH9K_IS_MIC_ENABLED(ah)
7262 && entry + 64 >= pCap->keycache_size) {
7263 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
7264 "%s: entry %u inappropriate for TKIP\n",
7265 __func__, entry);
7266 return false;
7267 }
7268 break; 3292 break;
7269 case ATH9K_CIPHER_WEP: 3293 case ATH9K_MODE_11NG_HT20:
7270 if (k->kv_len < LEN_WEP40) { 3294 case ATH9K_MODE_11NG_HT40PLUS:
7271 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE, 3295 case ATH9K_MODE_11NG_HT40MINUS:
7272 "%s: WEP key length %u too small\n", 3296 rt = &ar5416_11ng_table;
7273 __func__, k->kv_len);
7274 return false;
7275 }
7276 if (k->kv_len <= LEN_WEP40)
7277 keyType = AR_KEYTABLE_TYPE_40;
7278 else if (k->kv_len <= LEN_WEP104)
7279 keyType = AR_KEYTABLE_TYPE_104;
7280 else
7281 keyType = AR_KEYTABLE_TYPE_128;
7282 break; 3297 break;
7283 case ATH9K_CIPHER_CLR: 3298 case ATH9K_MODE_11NA_HT20:
7284 keyType = AR_KEYTABLE_TYPE_CLR; 3299 case ATH9K_MODE_11NA_HT40PLUS:
3300 case ATH9K_MODE_11NA_HT40MINUS:
3301 rt = &ar5416_11na_table;
7285 break; 3302 break;
7286 default: 3303 default:
7287 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE, 3304 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL, "%s: invalid mode 0x%x\n",
7288 "%s: cipher %u not supported\n", __func__, 3305 __func__, mode);
7289 k->kv_type); 3306 return NULL;
7290 return false;
7291 } 3307 }
7292 3308
7293 key0 = get_unaligned_le32(k->kv_val + 0) ^ xorMask; 3309 ath9k_hw_setup_rate_table(ah, rt);
7294 key1 = (get_unaligned_le16(k->kv_val + 4) ^ xorMask) & 0xffff;
7295 key2 = get_unaligned_le32(k->kv_val + 6) ^ xorMask;
7296 key3 = (get_unaligned_le16(k->kv_val + 10) ^ xorMask) & 0xffff;
7297 key4 = get_unaligned_le32(k->kv_val + 12) ^ xorMask;
7298 if (k->kv_len <= LEN_WEP104)
7299 key4 &= 0xff;
7300 3310
7301 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) { 3311 return rt;
7302 u16 micentry = entry + 64; 3312}
7303 3313
7304 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0); 3314/*******************/
7305 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1); 3315/* HW Capabilities */
7306 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2); 3316/*******************/
7307 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
7308 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
7309 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
7310 (void) ath9k_hw_keysetmac(ah, entry, mac);
7311 3317
7312 if (ahp->ah_miscMode & AR_PCU_MIC_NEW_LOC_ENA) { 3318bool ath9k_hw_fill_cap_info(struct ath_hal *ah)
7313 u32 mic0, mic1, mic2, mic3, mic4; 3319{
3320 struct ath_hal_5416 *ahp = AH5416(ah);
3321 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
3322 u16 capField = 0, eeval;
7314 3323
7315 mic0 = get_unaligned_le32(k->kv_mic + 0); 3324 eeval = ath9k_hw_get_eeprom(ah, EEP_REG_0);
7316 mic2 = get_unaligned_le32(k->kv_mic + 4);
7317 mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff;
7318 mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff;
7319 mic4 = get_unaligned_le32(k->kv_txmic + 4);
7320 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
7321 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1);
7322 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
7323 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3);
7324 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4);
7325 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
7326 AR_KEYTABLE_TYPE_CLR);
7327 3325
7328 } else { 3326 ah->ah_currentRD = eeval;
7329 u32 mic0, mic2;
7330 3327
7331 mic0 = get_unaligned_le32(k->kv_mic + 0); 3328 eeval = ath9k_hw_get_eeprom(ah, EEP_REG_1);
7332 mic2 = get_unaligned_le32(k->kv_mic + 4); 3329 ah->ah_currentRDExt = eeval;
7333 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
7334 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
7335 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
7336 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
7337 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
7338 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
7339 AR_KEYTABLE_TYPE_CLR);
7340 }
7341 REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0);
7342 REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0);
7343 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
7344 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
7345 } else {
7346 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
7347 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
7348 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
7349 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
7350 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
7351 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
7352 3330
7353 (void) ath9k_hw_keysetmac(ah, entry, mac); 3331 capField = ath9k_hw_get_eeprom(ah, EEP_OP_CAP);
7354 }
7355 3332
7356 if (ah->ah_curchan == NULL) 3333 if (ah->ah_opmode != ATH9K_M_HOSTAP &&
7357 return true; 3334 ah->ah_subvendorid == AR_SUBVENDOR_ID_NEW_A) {
3335 if (ah->ah_currentRD == 0x64 || ah->ah_currentRD == 0x65)
3336 ah->ah_currentRD += 5;
3337 else if (ah->ah_currentRD == 0x41)
3338 ah->ah_currentRD = 0x43;
3339 DPRINTF(ah->ah_sc, ATH_DBG_REGULATORY,
3340 "%s: regdomain mapped to 0x%x\n", __func__,
3341 ah->ah_currentRD);
3342 }
7358 3343
7359 return true; 3344 eeval = ath9k_hw_get_eeprom(ah, EEP_OP_MODE);
7360} 3345 bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX);
7361 3346
7362bool 3347 if (eeval & AR5416_OPFLAGS_11A) {
7363ath9k_hw_updatetxtriglevel(struct ath_hal *ah, bool bIncTrigLevel) 3348 set_bit(ATH9K_MODE_11A, pCap->wireless_modes);
7364{ 3349 if (ah->ah_config.ht_enable) {
7365 struct ath_hal_5416 *ahp = AH5416(ah); 3350 if (!(eeval & AR5416_OPFLAGS_N_5G_HT20))
7366 u32 txcfg, curLevel, newLevel; 3351 set_bit(ATH9K_MODE_11NA_HT20,
7367 enum ath9k_int omask; 3352 pCap->wireless_modes);
3353 if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) {
3354 set_bit(ATH9K_MODE_11NA_HT40PLUS,
3355 pCap->wireless_modes);
3356 set_bit(ATH9K_MODE_11NA_HT40MINUS,
3357 pCap->wireless_modes);
3358 }
3359 }
3360 }
7368 3361
7369 if (ah->ah_txTrigLevel >= MAX_TX_FIFO_THRESHOLD) 3362 if (eeval & AR5416_OPFLAGS_11G) {
7370 return false; 3363 set_bit(ATH9K_MODE_11B, pCap->wireless_modes);
3364 set_bit(ATH9K_MODE_11G, pCap->wireless_modes);
3365 if (ah->ah_config.ht_enable) {
3366 if (!(eeval & AR5416_OPFLAGS_N_2G_HT20))
3367 set_bit(ATH9K_MODE_11NG_HT20,
3368 pCap->wireless_modes);
3369 if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) {
3370 set_bit(ATH9K_MODE_11NG_HT40PLUS,
3371 pCap->wireless_modes);
3372 set_bit(ATH9K_MODE_11NG_HT40MINUS,
3373 pCap->wireless_modes);
3374 }
3375 }
3376 }
7371 3377
7372 omask = ath9k_hw_set_interrupts(ah, 3378 pCap->tx_chainmask = ath9k_hw_get_eeprom(ah, EEP_TX_MASK);
7373 ahp->ah_maskReg & ~ATH9K_INT_GLOBAL); 3379 if ((ah->ah_isPciExpress)
3380 || (eeval & AR5416_OPFLAGS_11A)) {
3381 pCap->rx_chainmask =
3382 ath9k_hw_get_eeprom(ah, EEP_RX_MASK);
3383 } else {
3384 pCap->rx_chainmask =
3385 (ath9k_hw_gpio_get(ah, 0)) ? 0x5 : 0x7;
3386 }
7374 3387
7375 txcfg = REG_READ(ah, AR_TXCFG); 3388 if (!(AR_SREV_9280(ah) && (ah->ah_macRev == 0)))
7376 curLevel = MS(txcfg, AR_FTRIG); 3389 ahp->ah_miscMode |= AR_PCU_MIC_NEW_LOC_ENA;
7377 newLevel = curLevel;
7378 if (bIncTrigLevel) {
7379 if (curLevel < MAX_TX_FIFO_THRESHOLD)
7380 newLevel++;
7381 } else if (curLevel > MIN_TX_FIFO_THRESHOLD)
7382 newLevel--;
7383 if (newLevel != curLevel)
7384 REG_WRITE(ah, AR_TXCFG,
7385 (txcfg & ~AR_FTRIG) | SM(newLevel, AR_FTRIG));
7386 3390
7387 ath9k_hw_set_interrupts(ah, omask); 3391 pCap->low_2ghz_chan = 2312;
3392 pCap->high_2ghz_chan = 2732;
7388 3393
7389 ah->ah_txTrigLevel = newLevel; 3394 pCap->low_5ghz_chan = 4920;
3395 pCap->high_5ghz_chan = 6100;
7390 3396
7391 return newLevel != curLevel; 3397 pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP;
7392} 3398 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP;
3399 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM;
7393 3400
7394bool ath9k_hw_set_txq_props(struct ath_hal *ah, int q, 3401 pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP;
7395 const struct ath9k_tx_queue_info *qinfo) 3402 pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP;
7396{ 3403 pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM;
7397 u32 cw;
7398 struct ath_hal_5416 *ahp = AH5416(ah);
7399 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
7400 struct ath9k_tx_queue_info *qi;
7401 3404
7402 if (q >= pCap->total_queues) { 3405 pCap->hw_caps |= ATH9K_HW_CAP_CHAN_SPREAD;
7403 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "%s: invalid queue num %u\n",
7404 __func__, q);
7405 return false;
7406 }
7407 3406
7408 qi = &ahp->ah_txq[q]; 3407 if (ah->ah_config.ht_enable)
7409 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) { 3408 pCap->hw_caps |= ATH9K_HW_CAP_HT;
7410 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "%s: inactive queue\n", 3409 else
7411 __func__); 3410 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
7412 return false;
7413 }
7414 3411
7415 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "%s: queue %p\n", __func__, qi); 3412 pCap->hw_caps |= ATH9K_HW_CAP_GTT;
3413 pCap->hw_caps |= ATH9K_HW_CAP_VEOL;
3414 pCap->hw_caps |= ATH9K_HW_CAP_BSSIDMASK;
3415 pCap->hw_caps &= ~ATH9K_HW_CAP_MCAST_KEYSEARCH;
7416 3416
7417 qi->tqi_ver = qinfo->tqi_ver; 3417 if (capField & AR_EEPROM_EEPCAP_MAXQCU)
7418 qi->tqi_subtype = qinfo->tqi_subtype; 3418 pCap->total_queues =
7419 qi->tqi_qflags = qinfo->tqi_qflags; 3419 MS(capField, AR_EEPROM_EEPCAP_MAXQCU);
7420 qi->tqi_priority = qinfo->tqi_priority;
7421 if (qinfo->tqi_aifs != ATH9K_TXQ_USEDEFAULT)
7422 qi->tqi_aifs = min(qinfo->tqi_aifs, 255U);
7423 else
7424 qi->tqi_aifs = INIT_AIFS;
7425 if (qinfo->tqi_cwmin != ATH9K_TXQ_USEDEFAULT) {
7426 cw = min(qinfo->tqi_cwmin, 1024U);
7427 qi->tqi_cwmin = 1;
7428 while (qi->tqi_cwmin < cw)
7429 qi->tqi_cwmin = (qi->tqi_cwmin << 1) | 1;
7430 } else
7431 qi->tqi_cwmin = qinfo->tqi_cwmin;
7432 if (qinfo->tqi_cwmax != ATH9K_TXQ_USEDEFAULT) {
7433 cw = min(qinfo->tqi_cwmax, 1024U);
7434 qi->tqi_cwmax = 1;
7435 while (qi->tqi_cwmax < cw)
7436 qi->tqi_cwmax = (qi->tqi_cwmax << 1) | 1;
7437 } else
7438 qi->tqi_cwmax = INIT_CWMAX;
7439
7440 if (qinfo->tqi_shretry != 0)
7441 qi->tqi_shretry = min((u32) qinfo->tqi_shretry, 15U);
7442 else 3420 else
7443 qi->tqi_shretry = INIT_SH_RETRY; 3421 pCap->total_queues = ATH9K_NUM_TX_QUEUES;
7444 if (qinfo->tqi_lgretry != 0) 3422
7445 qi->tqi_lgretry = min((u32) qinfo->tqi_lgretry, 15U); 3423 if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES)
3424 pCap->keycache_size =
3425 1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES);
7446 else 3426 else
7447 qi->tqi_lgretry = INIT_LG_RETRY; 3427 pCap->keycache_size = AR_KEYTABLE_SIZE;
7448 qi->tqi_cbrPeriod = qinfo->tqi_cbrPeriod;
7449 qi->tqi_cbrOverflowLimit = qinfo->tqi_cbrOverflowLimit;
7450 qi->tqi_burstTime = qinfo->tqi_burstTime;
7451 qi->tqi_readyTime = qinfo->tqi_readyTime;
7452
7453 switch (qinfo->tqi_subtype) {
7454 case ATH9K_WME_UPSD:
7455 if (qi->tqi_type == ATH9K_TX_QUEUE_DATA)
7456 qi->tqi_intFlags = ATH9K_TXQ_USE_LOCKOUT_BKOFF_DIS;
7457 break;
7458 default:
7459 break;
7460 }
7461 return true;
7462}
7463 3428
7464bool ath9k_hw_get_txq_props(struct ath_hal *ah, int q, 3429 pCap->hw_caps |= ATH9K_HW_CAP_FASTCC;
7465 struct ath9k_tx_queue_info *qinfo) 3430 pCap->num_mr_retries = 4;
7466{ 3431 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD;
7467 struct ath_hal_5416 *ahp = AH5416(ah);
7468 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
7469 struct ath9k_tx_queue_info *qi;
7470 3432
7471 if (q >= pCap->total_queues) { 3433 if (AR_SREV_9280_10_OR_LATER(ah))
7472 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "%s: invalid queue num %u\n", 3434 pCap->num_gpio_pins = AR928X_NUM_GPIO;
7473 __func__, q); 3435 else
7474 return false; 3436 pCap->num_gpio_pins = AR_NUM_GPIO;
7475 }
7476 3437
7477 qi = &ahp->ah_txq[q]; 3438 if (AR_SREV_9280_10_OR_LATER(ah)) {
7478 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) { 3439 pCap->hw_caps |= ATH9K_HW_CAP_WOW;
7479 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "%s: inactive queue\n", 3440 pCap->hw_caps |= ATH9K_HW_CAP_WOW_MATCHPATTERN_EXACT;
7480 __func__); 3441 } else {
7481 return false; 3442 pCap->hw_caps &= ~ATH9K_HW_CAP_WOW;
3443 pCap->hw_caps &= ~ATH9K_HW_CAP_WOW_MATCHPATTERN_EXACT;
7482 } 3444 }
7483 3445
7484 qinfo->tqi_qflags = qi->tqi_qflags; 3446 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) {
7485 qinfo->tqi_ver = qi->tqi_ver; 3447 pCap->hw_caps |= ATH9K_HW_CAP_CST;
7486 qinfo->tqi_subtype = qi->tqi_subtype; 3448 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
7487 qinfo->tqi_qflags = qi->tqi_qflags; 3449 } else {
7488 qinfo->tqi_priority = qi->tqi_priority; 3450 pCap->rts_aggr_limit = (8 * 1024);
7489 qinfo->tqi_aifs = qi->tqi_aifs; 3451 }
7490 qinfo->tqi_cwmin = qi->tqi_cwmin;
7491 qinfo->tqi_cwmax = qi->tqi_cwmax;
7492 qinfo->tqi_shretry = qi->tqi_shretry;
7493 qinfo->tqi_lgretry = qi->tqi_lgretry;
7494 qinfo->tqi_cbrPeriod = qi->tqi_cbrPeriod;
7495 qinfo->tqi_cbrOverflowLimit = qi->tqi_cbrOverflowLimit;
7496 qinfo->tqi_burstTime = qi->tqi_burstTime;
7497 qinfo->tqi_readyTime = qi->tqi_readyTime;
7498 3452
7499 return true; 3453 pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM;
7500}
7501 3454
7502int 3455#ifdef CONFIG_RFKILL
7503ath9k_hw_setuptxqueue(struct ath_hal *ah, enum ath9k_tx_queue type, 3456 ah->ah_rfsilent = ath9k_hw_get_eeprom(ah, EEP_RF_SILENT);
7504 const struct ath9k_tx_queue_info *qinfo) 3457 if (ah->ah_rfsilent & EEP_RFSILENT_ENABLED) {
7505{ 3458 ah->ah_rfkill_gpio =
7506 struct ath_hal_5416 *ahp = AH5416(ah); 3459 MS(ah->ah_rfsilent, EEP_RFSILENT_GPIO_SEL);
7507 struct ath9k_tx_queue_info *qi; 3460 ah->ah_rfkill_polarity =
7508 struct ath9k_hw_capabilities *pCap = &ah->ah_caps; 3461 MS(ah->ah_rfsilent, EEP_RFSILENT_POLARITY);
7509 int q;
7510 3462
7511 switch (type) { 3463 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
7512 case ATH9K_TX_QUEUE_BEACON:
7513 q = pCap->total_queues - 1;
7514 break;
7515 case ATH9K_TX_QUEUE_CAB:
7516 q = pCap->total_queues - 2;
7517 break;
7518 case ATH9K_TX_QUEUE_PSPOLL:
7519 q = 1;
7520 break;
7521 case ATH9K_TX_QUEUE_UAPSD:
7522 q = pCap->total_queues - 3;
7523 break;
7524 case ATH9K_TX_QUEUE_DATA:
7525 for (q = 0; q < pCap->total_queues; q++)
7526 if (ahp->ah_txq[q].tqi_type ==
7527 ATH9K_TX_QUEUE_INACTIVE)
7528 break;
7529 if (q == pCap->total_queues) {
7530 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
7531 "%s: no available tx queue\n", __func__);
7532 return -1;
7533 }
7534 break;
7535 default:
7536 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "%s: bad tx queue type %u\n",
7537 __func__, type);
7538 return -1;
7539 } 3464 }
3465#endif
7540 3466
7541 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "%s: queue %u\n", __func__, q); 3467 if ((ah->ah_macVersion == AR_SREV_VERSION_5416_PCI) ||
3468 (ah->ah_macVersion == AR_SREV_VERSION_5416_PCIE) ||
3469 (ah->ah_macVersion == AR_SREV_VERSION_9160) ||
3470 (ah->ah_macVersion == AR_SREV_VERSION_9100) ||
3471 (ah->ah_macVersion == AR_SREV_VERSION_9280))
3472 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
3473 else
3474 pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP;
7542 3475
7543 qi = &ahp->ah_txq[q]; 3476 if (AR_SREV_9280(ah))
7544 if (qi->tqi_type != ATH9K_TX_QUEUE_INACTIVE) { 3477 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
7545 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, 3478 else
7546 "%s: tx queue %u already active\n", __func__, q); 3479 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
7547 return -1; 3480
7548 } 3481 if (ah->ah_currentRDExt & (1 << REG_EXT_JAPAN_MIDBAND)) {
7549 memset(qi, 0, sizeof(struct ath9k_tx_queue_info)); 3482 pCap->reg_cap =
7550 qi->tqi_type = type; 3483 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
7551 if (qinfo == NULL) { 3484 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN |
7552 qi->tqi_qflags = 3485 AR_EEPROM_EEREGCAP_EN_KK_U2 |
7553 TXQ_FLAG_TXOKINT_ENABLE 3486 AR_EEPROM_EEREGCAP_EN_KK_MIDBAND;
7554 | TXQ_FLAG_TXERRINT_ENABLE
7555 | TXQ_FLAG_TXDESCINT_ENABLE | TXQ_FLAG_TXURNINT_ENABLE;
7556 qi->tqi_aifs = INIT_AIFS;
7557 qi->tqi_cwmin = ATH9K_TXQ_USEDEFAULT;
7558 qi->tqi_cwmax = INIT_CWMAX;
7559 qi->tqi_shretry = INIT_SH_RETRY;
7560 qi->tqi_lgretry = INIT_LG_RETRY;
7561 qi->tqi_physCompBuf = 0;
7562 } else { 3487 } else {
7563 qi->tqi_physCompBuf = qinfo->tqi_physCompBuf; 3488 pCap->reg_cap =
7564 (void) ath9k_hw_set_txq_props(ah, q, qinfo); 3489 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3490 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN;
7565 } 3491 }
7566 3492
7567 return q; 3493 pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND;
7568}
7569 3494
7570static void 3495 pCap->num_antcfg_5ghz =
7571ath9k_hw_set_txq_interrupts(struct ath_hal *ah, 3496 ath9k_hw_get_num_ant_config(ah, IEEE80211_BAND_5GHZ);
7572 struct ath9k_tx_queue_info *qi) 3497 pCap->num_antcfg_2ghz =
7573{ 3498 ath9k_hw_get_num_ant_config(ah, IEEE80211_BAND_2GHZ);
7574 struct ath_hal_5416 *ahp = AH5416(ah);
7575 3499
7576 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, 3500 return true;
7577 "%s: tx ok 0x%x err 0x%x desc 0x%x eol 0x%x urn 0x%x\n",
7578 __func__, ahp->ah_txOkInterruptMask,
7579 ahp->ah_txErrInterruptMask, ahp->ah_txDescInterruptMask,
7580 ahp->ah_txEolInterruptMask, ahp->ah_txUrnInterruptMask);
7581
7582 REG_WRITE(ah, AR_IMR_S0,
7583 SM(ahp->ah_txOkInterruptMask, AR_IMR_S0_QCU_TXOK)
7584 | SM(ahp->ah_txDescInterruptMask, AR_IMR_S0_QCU_TXDESC));
7585 REG_WRITE(ah, AR_IMR_S1,
7586 SM(ahp->ah_txErrInterruptMask, AR_IMR_S1_QCU_TXERR)
7587 | SM(ahp->ah_txEolInterruptMask, AR_IMR_S1_QCU_TXEOL));
7588 REG_RMW_FIELD(ah, AR_IMR_S2,
7589 AR_IMR_S2_QCU_TXURN, ahp->ah_txUrnInterruptMask);
7590} 3501}
7591 3502
7592bool ath9k_hw_releasetxqueue(struct ath_hal *ah, u32 q) 3503bool ath9k_hw_getcapability(struct ath_hal *ah, enum ath9k_capability_type type,
3504 u32 capability, u32 *result)
7593{ 3505{
7594 struct ath_hal_5416 *ahp = AH5416(ah); 3506 struct ath_hal_5416 *ahp = AH5416(ah);
7595 struct ath9k_hw_capabilities *pCap = &ah->ah_caps; 3507 const struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
7596 struct ath9k_tx_queue_info *qi;
7597 3508
7598 if (q >= pCap->total_queues) { 3509 switch (type) {
7599 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "%s: invalid queue num %u\n", 3510 case ATH9K_CAP_CIPHER:
7600 __func__, q); 3511 switch (capability) {
3512 case ATH9K_CIPHER_AES_CCM:
3513 case ATH9K_CIPHER_AES_OCB:
3514 case ATH9K_CIPHER_TKIP:
3515 case ATH9K_CIPHER_WEP:
3516 case ATH9K_CIPHER_MIC:
3517 case ATH9K_CIPHER_CLR:
3518 return true;
3519 default:
3520 return false;
3521 }
3522 case ATH9K_CAP_TKIP_MIC:
3523 switch (capability) {
3524 case 0:
3525 return true;
3526 case 1:
3527 return (ahp->ah_staId1Defaults &
3528 AR_STA_ID1_CRPT_MIC_ENABLE) ? true :
3529 false;
3530 }
3531 case ATH9K_CAP_TKIP_SPLIT:
3532 return (ahp->ah_miscMode & AR_PCU_MIC_NEW_LOC_ENA) ?
3533 false : true;
3534 case ATH9K_CAP_WME_TKIPMIC:
3535 return 0;
3536 case ATH9K_CAP_PHYCOUNTERS:
3537 return ahp->ah_hasHwPhyCounters ? 0 : -ENXIO;
3538 case ATH9K_CAP_DIVERSITY:
3539 return (REG_READ(ah, AR_PHY_CCK_DETECT) &
3540 AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV) ?
3541 true : false;
3542 case ATH9K_CAP_PHYDIAG:
3543 return true;
3544 case ATH9K_CAP_MCAST_KEYSRCH:
3545 switch (capability) {
3546 case 0:
3547 return true;
3548 case 1:
3549 if (REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) {
3550 return false;
3551 } else {
3552 return (ahp->ah_staId1Defaults &
3553 AR_STA_ID1_MCAST_KSRCH) ? true :
3554 false;
3555 }
3556 }
7601 return false; 3557 return false;
7602 } 3558 case ATH9K_CAP_TSF_ADJUST:
7603 qi = &ahp->ah_txq[q]; 3559 return (ahp->ah_miscMode & AR_PCU_TX_ADD_TSF) ?
7604 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) { 3560 true : false;
7605 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "%s: inactive queue %u\n", 3561 case ATH9K_CAP_RFSILENT:
7606 __func__, q); 3562 if (capability == 3)
3563 return false;
3564 case ATH9K_CAP_ANT_CFG_2GHZ:
3565 *result = pCap->num_antcfg_2ghz;
3566 return true;
3567 case ATH9K_CAP_ANT_CFG_5GHZ:
3568 *result = pCap->num_antcfg_5ghz;
3569 return true;
3570 case ATH9K_CAP_TXPOW:
3571 switch (capability) {
3572 case 0:
3573 return 0;
3574 case 1:
3575 *result = ah->ah_powerLimit;
3576 return 0;
3577 case 2:
3578 *result = ah->ah_maxPowerLevel;
3579 return 0;
3580 case 3:
3581 *result = ah->ah_tpScale;
3582 return 0;
3583 }
3584 return false;
3585 default:
7607 return false; 3586 return false;
7608 } 3587 }
7609
7610 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "%s: release queue %u\n",
7611 __func__, q);
7612
7613 qi->tqi_type = ATH9K_TX_QUEUE_INACTIVE;
7614 ahp->ah_txOkInterruptMask &= ~(1 << q);
7615 ahp->ah_txErrInterruptMask &= ~(1 << q);
7616 ahp->ah_txDescInterruptMask &= ~(1 << q);
7617 ahp->ah_txEolInterruptMask &= ~(1 << q);
7618 ahp->ah_txUrnInterruptMask &= ~(1 << q);
7619 ath9k_hw_set_txq_interrupts(ah, qi);
7620
7621 return true;
7622} 3588}
7623 3589
7624bool ath9k_hw_resettxqueue(struct ath_hal *ah, u32 q) 3590bool ath9k_hw_setcapability(struct ath_hal *ah, enum ath9k_capability_type type,
3591 u32 capability, u32 setting, int *status)
7625{ 3592{
7626 struct ath_hal_5416 *ahp = AH5416(ah); 3593 struct ath_hal_5416 *ahp = AH5416(ah);
7627 struct ath9k_hw_capabilities *pCap = &ah->ah_caps; 3594 u32 v;
7628 struct ath9k_channel *chan = ah->ah_curchan;
7629 struct ath9k_tx_queue_info *qi;
7630 u32 cwMin, chanCwMin, value;
7631 3595
7632 if (q >= pCap->total_queues) { 3596 switch (type) {
7633 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "%s: invalid queue num %u\n", 3597 case ATH9K_CAP_TKIP_MIC:
7634 __func__, q); 3598 if (setting)
7635 return false; 3599 ahp->ah_staId1Defaults |=
7636 } 3600 AR_STA_ID1_CRPT_MIC_ENABLE;
7637 qi = &ahp->ah_txq[q]; 3601 else
7638 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) { 3602 ahp->ah_staId1Defaults &=
7639 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "%s: inactive queue %u\n", 3603 ~AR_STA_ID1_CRPT_MIC_ENABLE;
7640 __func__, q);
7641 return true; 3604 return true;
7642 } 3605 case ATH9K_CAP_DIVERSITY:
7643 3606 v = REG_READ(ah, AR_PHY_CCK_DETECT);
7644 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "%s: reset queue %u\n", __func__, q); 3607 if (setting)
7645 3608 v |= AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
7646 if (qi->tqi_cwmin == ATH9K_TXQ_USEDEFAULT) {
7647 if (chan && IS_CHAN_B(chan))
7648 chanCwMin = INIT_CWMIN_11B;
7649 else 3609 else
7650 chanCwMin = INIT_CWMIN; 3610 v &= ~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
7651 3611 REG_WRITE(ah, AR_PHY_CCK_DETECT, v);
7652 for (cwMin = 1; cwMin < chanCwMin; cwMin = (cwMin << 1) | 1); 3612 return true;
7653 } else 3613 case ATH9K_CAP_MCAST_KEYSRCH:
7654 cwMin = qi->tqi_cwmin; 3614 if (setting)
7655 3615 ahp->ah_staId1Defaults |= AR_STA_ID1_MCAST_KSRCH;
7656 REG_WRITE(ah, AR_DLCL_IFS(q), SM(cwMin, AR_D_LCL_IFS_CWMIN) 3616 else
7657 | SM(qi->tqi_cwmax, AR_D_LCL_IFS_CWMAX) 3617 ahp->ah_staId1Defaults &= ~AR_STA_ID1_MCAST_KSRCH;
7658 | SM(qi->tqi_aifs, AR_D_LCL_IFS_AIFS)); 3618 return true;
7659 3619 case ATH9K_CAP_TSF_ADJUST:
7660 REG_WRITE(ah, AR_DRETRY_LIMIT(q), 3620 if (setting)
7661 SM(INIT_SSH_RETRY, AR_D_RETRY_LIMIT_STA_SH) 3621 ahp->ah_miscMode |= AR_PCU_TX_ADD_TSF;
7662 | SM(INIT_SLG_RETRY, AR_D_RETRY_LIMIT_STA_LG) 3622 else
7663 | SM(qi->tqi_shretry, AR_D_RETRY_LIMIT_FR_SH)); 3623 ahp->ah_miscMode &= ~AR_PCU_TX_ADD_TSF;
7664 3624 return true;
7665 REG_WRITE(ah, AR_QMISC(q), AR_Q_MISC_DCU_EARLY_TERM_REQ);
7666 REG_WRITE(ah, AR_DMISC(q),
7667 AR_D_MISC_CW_BKOFF_EN | AR_D_MISC_FRAG_WAIT_EN | 0x2);
7668
7669 if (qi->tqi_cbrPeriod) {
7670 REG_WRITE(ah, AR_QCBRCFG(q),
7671 SM(qi->tqi_cbrPeriod, AR_Q_CBRCFG_INTERVAL)
7672 | SM(qi->tqi_cbrOverflowLimit,
7673 AR_Q_CBRCFG_OVF_THRESH));
7674 REG_WRITE(ah, AR_QMISC(q),
7675 REG_READ(ah,
7676 AR_QMISC(q)) | AR_Q_MISC_FSP_CBR | (qi->
7677 tqi_cbrOverflowLimit
7678 ?
7679 AR_Q_MISC_CBR_EXP_CNTR_LIMIT_EN
7680 :
7681 0));
7682 }
7683 if (qi->tqi_readyTime && (qi->tqi_type != ATH9K_TX_QUEUE_CAB)) {
7684 REG_WRITE(ah, AR_QRDYTIMECFG(q),
7685 SM(qi->tqi_readyTime, AR_Q_RDYTIMECFG_DURATION) |
7686 AR_Q_RDYTIMECFG_EN);
7687 }
7688
7689 REG_WRITE(ah, AR_DCHNTIME(q),
7690 SM(qi->tqi_burstTime, AR_D_CHNTIME_DUR) |
7691 (qi->tqi_burstTime ? AR_D_CHNTIME_EN : 0));
7692
7693 if (qi->tqi_burstTime
7694 && (qi->tqi_qflags & TXQ_FLAG_RDYTIME_EXP_POLICY_ENABLE)) {
7695 REG_WRITE(ah, AR_QMISC(q),
7696 REG_READ(ah,
7697 AR_QMISC(q)) |
7698 AR_Q_MISC_RDYTIME_EXP_POLICY);
7699
7700 }
7701
7702 if (qi->tqi_qflags & TXQ_FLAG_BACKOFF_DISABLE) {
7703 REG_WRITE(ah, AR_DMISC(q),
7704 REG_READ(ah, AR_DMISC(q)) |
7705 AR_D_MISC_POST_FR_BKOFF_DIS);
7706 }
7707 if (qi->tqi_qflags & TXQ_FLAG_FRAG_BURST_BACKOFF_ENABLE) {
7708 REG_WRITE(ah, AR_DMISC(q),
7709 REG_READ(ah, AR_DMISC(q)) |
7710 AR_D_MISC_FRAG_BKOFF_EN);
7711 }
7712 switch (qi->tqi_type) {
7713 case ATH9K_TX_QUEUE_BEACON:
7714 REG_WRITE(ah, AR_QMISC(q), REG_READ(ah, AR_QMISC(q))
7715 | AR_Q_MISC_FSP_DBA_GATED
7716 | AR_Q_MISC_BEACON_USE
7717 | AR_Q_MISC_CBR_INCR_DIS1);
7718
7719 REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q))
7720 | (AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL <<
7721 AR_D_MISC_ARB_LOCKOUT_CNTRL_S)
7722 | AR_D_MISC_BEACON_USE
7723 | AR_D_MISC_POST_FR_BKOFF_DIS);
7724 break;
7725 case ATH9K_TX_QUEUE_CAB:
7726 REG_WRITE(ah, AR_QMISC(q), REG_READ(ah, AR_QMISC(q))
7727 | AR_Q_MISC_FSP_DBA_GATED
7728 | AR_Q_MISC_CBR_INCR_DIS1
7729 | AR_Q_MISC_CBR_INCR_DIS0);
7730 value = (qi->tqi_readyTime
7731 - (ah->ah_config.sw_beacon_response_time -
7732 ah->ah_config.dma_beacon_response_time)
7733 -
7734 ah->ah_config.additional_swba_backoff) *
7735 1024;
7736 REG_WRITE(ah, AR_QRDYTIMECFG(q),
7737 value | AR_Q_RDYTIMECFG_EN);
7738 REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q))
7739 | (AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL <<
7740 AR_D_MISC_ARB_LOCKOUT_CNTRL_S));
7741 break;
7742 case ATH9K_TX_QUEUE_PSPOLL:
7743 REG_WRITE(ah, AR_QMISC(q),
7744 REG_READ(ah,
7745 AR_QMISC(q)) | AR_Q_MISC_CBR_INCR_DIS1);
7746 break;
7747 case ATH9K_TX_QUEUE_UAPSD:
7748 REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q))
7749 | AR_D_MISC_POST_FR_BKOFF_DIS);
7750 break;
7751 default: 3625 default:
7752 break; 3626 return false;
7753 }
7754
7755 if (qi->tqi_intFlags & ATH9K_TXQ_USE_LOCKOUT_BKOFF_DIS) {
7756 REG_WRITE(ah, AR_DMISC(q),
7757 REG_READ(ah, AR_DMISC(q)) |
7758 SM(AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL,
7759 AR_D_MISC_ARB_LOCKOUT_CNTRL) |
7760 AR_D_MISC_POST_FR_BKOFF_DIS);
7761 } 3627 }
7762
7763 if (qi->tqi_qflags & TXQ_FLAG_TXOKINT_ENABLE)
7764 ahp->ah_txOkInterruptMask |= 1 << q;
7765 else
7766 ahp->ah_txOkInterruptMask &= ~(1 << q);
7767 if (qi->tqi_qflags & TXQ_FLAG_TXERRINT_ENABLE)
7768 ahp->ah_txErrInterruptMask |= 1 << q;
7769 else
7770 ahp->ah_txErrInterruptMask &= ~(1 << q);
7771 if (qi->tqi_qflags & TXQ_FLAG_TXDESCINT_ENABLE)
7772 ahp->ah_txDescInterruptMask |= 1 << q;
7773 else
7774 ahp->ah_txDescInterruptMask &= ~(1 << q);
7775 if (qi->tqi_qflags & TXQ_FLAG_TXEOLINT_ENABLE)
7776 ahp->ah_txEolInterruptMask |= 1 << q;
7777 else
7778 ahp->ah_txEolInterruptMask &= ~(1 << q);
7779 if (qi->tqi_qflags & TXQ_FLAG_TXURNINT_ENABLE)
7780 ahp->ah_txUrnInterruptMask |= 1 << q;
7781 else
7782 ahp->ah_txUrnInterruptMask &= ~(1 << q);
7783 ath9k_hw_set_txq_interrupts(ah, qi);
7784
7785 return true;
7786} 3628}
7787 3629
7788void ath9k_hw_gettxintrtxqs(struct ath_hal *ah, u32 *txqs) 3630/****************************/
7789{ 3631/* GPIO / RFKILL / Antennae */
7790 struct ath_hal_5416 *ahp = AH5416(ah); 3632/****************************/
7791 *txqs &= ahp->ah_intrTxqs;
7792 ahp->ah_intrTxqs &= ~(*txqs);
7793}
7794
7795bool
7796ath9k_hw_filltxdesc(struct ath_hal *ah, struct ath_desc *ds,
7797 u32 segLen, bool firstSeg,
7798 bool lastSeg, const struct ath_desc *ds0)
7799{
7800 struct ar5416_desc *ads = AR5416DESC(ds);
7801
7802 if (firstSeg) {
7803 ads->ds_ctl1 |= segLen | (lastSeg ? 0 : AR_TxMore);
7804 } else if (lastSeg) {
7805 ads->ds_ctl0 = 0;
7806 ads->ds_ctl1 = segLen;
7807 ads->ds_ctl2 = AR5416DESC_CONST(ds0)->ds_ctl2;
7808 ads->ds_ctl3 = AR5416DESC_CONST(ds0)->ds_ctl3;
7809 } else {
7810 ads->ds_ctl0 = 0;
7811 ads->ds_ctl1 = segLen | AR_TxMore;
7812 ads->ds_ctl2 = 0;
7813 ads->ds_ctl3 = 0;
7814 }
7815 ads->ds_txstatus0 = ads->ds_txstatus1 = 0;
7816 ads->ds_txstatus2 = ads->ds_txstatus3 = 0;
7817 ads->ds_txstatus4 = ads->ds_txstatus5 = 0;
7818 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
7819 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
7820 return true;
7821}
7822 3633
7823void ath9k_hw_cleartxdesc(struct ath_hal *ah, struct ath_desc *ds) 3634static void ath9k_hw_gpio_cfg_output_mux(struct ath_hal *ah,
3635 u32 gpio, u32 type)
7824{ 3636{
7825 struct ar5416_desc *ads = AR5416DESC(ds); 3637 int addr;
3638 u32 gpio_shift, tmp;
7826 3639
7827 ads->ds_txstatus0 = ads->ds_txstatus1 = 0; 3640 if (gpio > 11)
7828 ads->ds_txstatus2 = ads->ds_txstatus3 = 0; 3641 addr = AR_GPIO_OUTPUT_MUX3;
7829 ads->ds_txstatus4 = ads->ds_txstatus5 = 0; 3642 else if (gpio > 5)
7830 ads->ds_txstatus6 = ads->ds_txstatus7 = 0; 3643 addr = AR_GPIO_OUTPUT_MUX2;
7831 ads->ds_txstatus8 = ads->ds_txstatus9 = 0; 3644 else
7832} 3645 addr = AR_GPIO_OUTPUT_MUX1;
7833 3646
7834int 3647 gpio_shift = (gpio % 6) * 5;
7835ath9k_hw_txprocdesc(struct ath_hal *ah, struct ath_desc *ds)
7836{
7837 struct ar5416_desc *ads = AR5416DESC(ds);
7838
7839 if ((ads->ds_txstatus9 & AR_TxDone) == 0)
7840 return -EINPROGRESS;
7841
7842 ds->ds_txstat.ts_seqnum = MS(ads->ds_txstatus9, AR_SeqNum);
7843 ds->ds_txstat.ts_tstamp = ads->AR_SendTimestamp;
7844 ds->ds_txstat.ts_status = 0;
7845 ds->ds_txstat.ts_flags = 0;
7846
7847 if (ads->ds_txstatus1 & AR_ExcessiveRetries)
7848 ds->ds_txstat.ts_status |= ATH9K_TXERR_XRETRY;
7849 if (ads->ds_txstatus1 & AR_Filtered)
7850 ds->ds_txstat.ts_status |= ATH9K_TXERR_FILT;
7851 if (ads->ds_txstatus1 & AR_FIFOUnderrun)
7852 ds->ds_txstat.ts_status |= ATH9K_TXERR_FIFO;
7853 if (ads->ds_txstatus9 & AR_TxOpExceeded)
7854 ds->ds_txstat.ts_status |= ATH9K_TXERR_XTXOP;
7855 if (ads->ds_txstatus1 & AR_TxTimerExpired)
7856 ds->ds_txstat.ts_status |= ATH9K_TXERR_TIMER_EXPIRED;
7857
7858 if (ads->ds_txstatus1 & AR_DescCfgErr)
7859 ds->ds_txstat.ts_flags |= ATH9K_TX_DESC_CFG_ERR;
7860 if (ads->ds_txstatus1 & AR_TxDataUnderrun) {
7861 ds->ds_txstat.ts_flags |= ATH9K_TX_DATA_UNDERRUN;
7862 ath9k_hw_updatetxtriglevel(ah, true);
7863 }
7864 if (ads->ds_txstatus1 & AR_TxDelimUnderrun) {
7865 ds->ds_txstat.ts_flags |= ATH9K_TX_DELIM_UNDERRUN;
7866 ath9k_hw_updatetxtriglevel(ah, true);
7867 }
7868 if (ads->ds_txstatus0 & AR_TxBaStatus) {
7869 ds->ds_txstat.ts_flags |= ATH9K_TX_BA;
7870 ds->ds_txstat.ba_low = ads->AR_BaBitmapLow;
7871 ds->ds_txstat.ba_high = ads->AR_BaBitmapHigh;
7872 }
7873 3648
7874 ds->ds_txstat.ts_rateindex = MS(ads->ds_txstatus9, AR_FinalTxIdx); 3649 if (AR_SREV_9280_20_OR_LATER(ah)
7875 switch (ds->ds_txstat.ts_rateindex) { 3650 || (addr != AR_GPIO_OUTPUT_MUX1)) {
7876 case 0: 3651 REG_RMW(ah, addr, (type << gpio_shift),
7877 ds->ds_txstat.ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate0); 3652 (0x1f << gpio_shift));
7878 break; 3653 } else {
7879 case 1: 3654 tmp = REG_READ(ah, addr);
7880 ds->ds_txstat.ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate1); 3655 tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
7881 break; 3656 tmp &= ~(0x1f << gpio_shift);
7882 case 2: 3657 tmp |= (type << gpio_shift);
7883 ds->ds_txstat.ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate2); 3658 REG_WRITE(ah, addr, tmp);
7884 break;
7885 case 3:
7886 ds->ds_txstat.ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate3);
7887 break;
7888 } 3659 }
7889
7890 ds->ds_txstat.ts_rssi = MS(ads->ds_txstatus5, AR_TxRSSICombined);
7891 ds->ds_txstat.ts_rssi_ctl0 = MS(ads->ds_txstatus0, AR_TxRSSIAnt00);
7892 ds->ds_txstat.ts_rssi_ctl1 = MS(ads->ds_txstatus0, AR_TxRSSIAnt01);
7893 ds->ds_txstat.ts_rssi_ctl2 = MS(ads->ds_txstatus0, AR_TxRSSIAnt02);
7894 ds->ds_txstat.ts_rssi_ext0 = MS(ads->ds_txstatus5, AR_TxRSSIAnt10);
7895 ds->ds_txstat.ts_rssi_ext1 = MS(ads->ds_txstatus5, AR_TxRSSIAnt11);
7896 ds->ds_txstat.ts_rssi_ext2 = MS(ads->ds_txstatus5, AR_TxRSSIAnt12);
7897 ds->ds_txstat.evm0 = ads->AR_TxEVM0;
7898 ds->ds_txstat.evm1 = ads->AR_TxEVM1;
7899 ds->ds_txstat.evm2 = ads->AR_TxEVM2;
7900 ds->ds_txstat.ts_shortretry = MS(ads->ds_txstatus1, AR_RTSFailCnt);
7901 ds->ds_txstat.ts_longretry = MS(ads->ds_txstatus1, AR_DataFailCnt);
7902 ds->ds_txstat.ts_virtcol = MS(ads->ds_txstatus1, AR_VirtRetryCnt);
7903 ds->ds_txstat.ts_antenna = 1;
7904
7905 return 0;
7906} 3660}
7907 3661
7908void 3662void ath9k_hw_cfg_gpio_input(struct ath_hal *ah, u32 gpio)
7909ath9k_hw_set11n_txdesc(struct ath_hal *ah, struct ath_desc *ds,
7910 u32 pktLen, enum ath9k_pkt_type type, u32 txPower,
7911 u32 keyIx, enum ath9k_key_type keyType, u32 flags)
7912{ 3663{
7913 struct ar5416_desc *ads = AR5416DESC(ds); 3664 u32 gpio_shift;
7914 struct ath_hal_5416 *ahp = AH5416(ah);
7915
7916 txPower += ahp->ah_txPowerIndexOffset;
7917 if (txPower > 63)
7918 txPower = 63;
7919
7920 ads->ds_ctl0 = (pktLen & AR_FrameLen)
7921 | (flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
7922 | SM(txPower, AR_XmitPower)
7923 | (flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
7924 | (flags & ATH9K_TXDESC_CLRDMASK ? AR_ClrDestMask : 0)
7925 | (flags & ATH9K_TXDESC_INTREQ ? AR_TxIntrReq : 0)
7926 | (keyIx != ATH9K_TXKEYIX_INVALID ? AR_DestIdxValid : 0);
7927
7928 ads->ds_ctl1 =
7929 (keyIx != ATH9K_TXKEYIX_INVALID ? SM(keyIx, AR_DestIdx) : 0)
7930 | SM(type, AR_FrameType)
7931 | (flags & ATH9K_TXDESC_NOACK ? AR_NoAck : 0)
7932 | (flags & ATH9K_TXDESC_EXT_ONLY ? AR_ExtOnly : 0)
7933 | (flags & ATH9K_TXDESC_EXT_AND_CTL ? AR_ExtAndCtl : 0);
7934 3665
7935 ads->ds_ctl6 = SM(keyType, AR_EncrType); 3666 ASSERT(gpio < ah->ah_caps.num_gpio_pins);
7936 3667
7937 if (AR_SREV_9285(ah)) { 3668 gpio_shift = gpio << 1;
7938 3669
7939 ads->ds_ctl8 = 0; 3670 REG_RMW(ah,
7940 ads->ds_ctl9 = 0; 3671 AR_GPIO_OE_OUT,
7941 ads->ds_ctl10 = 0; 3672 (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
7942 ads->ds_ctl11 = 0; 3673 (AR_GPIO_OE_OUT_DRV << gpio_shift));
7943 }
7944} 3674}
7945 3675
7946void 3676u32 ath9k_hw_gpio_get(struct ath_hal *ah, u32 gpio)
7947ath9k_hw_set11n_ratescenario(struct ath_hal *ah, struct ath_desc *ds,
7948 struct ath_desc *lastds,
7949 u32 durUpdateEn, u32 rtsctsRate,
7950 u32 rtsctsDuration,
7951 struct ath9k_11n_rate_series series[],
7952 u32 nseries, u32 flags)
7953{ 3677{
7954 struct ar5416_desc *ads = AR5416DESC(ds); 3678 if (gpio >= ah->ah_caps.num_gpio_pins)
7955 struct ar5416_desc *last_ads = AR5416DESC(lastds); 3679 return 0xffffffff;
7956 u32 ds_ctl0;
7957
7958 (void) nseries;
7959 (void) rtsctsDuration;
7960
7961 if (flags & (ATH9K_TXDESC_RTSENA | ATH9K_TXDESC_CTSENA)) {
7962 ds_ctl0 = ads->ds_ctl0;
7963
7964 if (flags & ATH9K_TXDESC_RTSENA) {
7965 ds_ctl0 &= ~AR_CTSEnable;
7966 ds_ctl0 |= AR_RTSEnable;
7967 } else {
7968 ds_ctl0 &= ~AR_RTSEnable;
7969 ds_ctl0 |= AR_CTSEnable;
7970 }
7971 3680
7972 ads->ds_ctl0 = ds_ctl0; 3681 if (AR_SREV_9280_10_OR_LATER(ah)) {
3682 return (MS
3683 (REG_READ(ah, AR_GPIO_IN_OUT),
3684 AR928X_GPIO_IN_VAL) & AR_GPIO_BIT(gpio)) != 0;
7973 } else { 3685 } else {
7974 ads->ds_ctl0 = 3686 return (MS(REG_READ(ah, AR_GPIO_IN_OUT), AR_GPIO_IN_VAL) &
7975 (ads->ds_ctl0 & ~(AR_RTSEnable | AR_CTSEnable)); 3687 AR_GPIO_BIT(gpio)) != 0;
7976 } 3688 }
7977
7978 ads->ds_ctl2 = set11nTries(series, 0)
7979 | set11nTries(series, 1)
7980 | set11nTries(series, 2)
7981 | set11nTries(series, 3)
7982 | (durUpdateEn ? AR_DurUpdateEna : 0)
7983 | SM(0, AR_BurstDur);
7984
7985 ads->ds_ctl3 = set11nRate(series, 0)
7986 | set11nRate(series, 1)
7987 | set11nRate(series, 2)
7988 | set11nRate(series, 3);
7989
7990 ads->ds_ctl4 = set11nPktDurRTSCTS(series, 0)
7991 | set11nPktDurRTSCTS(series, 1);
7992
7993 ads->ds_ctl5 = set11nPktDurRTSCTS(series, 2)
7994 | set11nPktDurRTSCTS(series, 3);
7995
7996 ads->ds_ctl7 = set11nRateFlags(series, 0)
7997 | set11nRateFlags(series, 1)
7998 | set11nRateFlags(series, 2)
7999 | set11nRateFlags(series, 3)
8000 | SM(rtsctsRate, AR_RTSCTSRate);
8001 last_ads->ds_ctl2 = ads->ds_ctl2;
8002 last_ads->ds_ctl3 = ads->ds_ctl3;
8003} 3689}
8004 3690
8005void 3691void ath9k_hw_cfg_output(struct ath_hal *ah, u32 gpio,
8006ath9k_hw_set11n_aggr_first(struct ath_hal *ah, struct ath_desc *ds, 3692 u32 ah_signal_type)
8007 u32 aggrLen)
8008{ 3693{
8009 struct ar5416_desc *ads = AR5416DESC(ds); 3694 u32 gpio_shift;
8010
8011 ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
8012
8013 ads->ds_ctl6 &= ~AR_AggrLen;
8014 ads->ds_ctl6 |= SM(aggrLen, AR_AggrLen);
8015}
8016 3695
8017void 3696 ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
8018ath9k_hw_set11n_aggr_middle(struct ath_hal *ah, struct ath_desc *ds,
8019 u32 numDelims)
8020{
8021 struct ar5416_desc *ads = AR5416DESC(ds);
8022 unsigned int ctl6;
8023 3697
8024 ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr); 3698 gpio_shift = 2 * gpio;
8025 3699
8026 ctl6 = ads->ds_ctl6; 3700 REG_RMW(ah,
8027 ctl6 &= ~AR_PadDelim; 3701 AR_GPIO_OE_OUT,
8028 ctl6 |= SM(numDelims, AR_PadDelim); 3702 (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
8029 ads->ds_ctl6 = ctl6; 3703 (AR_GPIO_OE_OUT_DRV << gpio_shift));
8030} 3704}
8031 3705
8032void ath9k_hw_set11n_aggr_last(struct ath_hal *ah, struct ath_desc *ds) 3706void ath9k_hw_set_gpio(struct ath_hal *ah, u32 gpio, u32 val)
8033{ 3707{
8034 struct ar5416_desc *ads = AR5416DESC(ds); 3708 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
8035 3709 AR_GPIO_BIT(gpio));
8036 ads->ds_ctl1 |= AR_IsAggr;
8037 ads->ds_ctl1 &= ~AR_MoreAggr;
8038 ads->ds_ctl6 &= ~AR_PadDelim;
8039} 3710}
8040 3711
8041void ath9k_hw_clr11n_aggr(struct ath_hal *ah, struct ath_desc *ds) 3712#ifdef CONFIG_RFKILL
3713void ath9k_enable_rfkill(struct ath_hal *ah)
8042{ 3714{
8043 struct ar5416_desc *ads = AR5416DESC(ds); 3715 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
3716 AR_GPIO_INPUT_EN_VAL_RFSILENT_BB);
8044 3717
8045 ads->ds_ctl1 &= (~AR_IsAggr & ~AR_MoreAggr); 3718 REG_CLR_BIT(ah, AR_GPIO_INPUT_MUX2,
3719 AR_GPIO_INPUT_MUX2_RFSILENT);
3720
3721 ath9k_hw_cfg_gpio_input(ah, ah->ah_rfkill_gpio);
3722 REG_SET_BIT(ah, AR_PHY_TEST, RFSILENT_BB);
8046} 3723}
3724#endif
8047 3725
8048void 3726int ath9k_hw_select_antconfig(struct ath_hal *ah, u32 cfg)
8049ath9k_hw_set11n_burstduration(struct ath_hal *ah, struct ath_desc *ds,
8050 u32 burstDuration)
8051{ 3727{
8052 struct ar5416_desc *ads = AR5416DESC(ds); 3728 struct ath9k_channel *chan = ah->ah_curchan;
3729 const struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
3730 u16 ant_config;
3731 u32 halNumAntConfig;
8053 3732
8054 ads->ds_ctl2 &= ~AR_BurstDur; 3733 halNumAntConfig = IS_CHAN_2GHZ(chan) ?
8055 ads->ds_ctl2 |= SM(burstDuration, AR_BurstDur); 3734 pCap->num_antcfg_2ghz : pCap->num_antcfg_5ghz;
8056}
8057 3735
8058void 3736 if (cfg < halNumAntConfig) {
8059ath9k_hw_set11n_virtualmorefrag(struct ath_hal *ah, struct ath_desc *ds, 3737 if (!ath9k_hw_get_eeprom_antenna_cfg(ah, chan,
8060 u32 vmf) 3738 cfg, &ant_config)) {
8061{ 3739 REG_WRITE(ah, AR_PHY_SWITCH_COM, ant_config);
8062 struct ar5416_desc *ads = AR5416DESC(ds); 3740 return 0;
3741 }
3742 }
8063 3743
8064 if (vmf) 3744 return -EINVAL;
8065 ads->ds_ctl0 |= AR_VirtMoreFrag;
8066 else
8067 ads->ds_ctl0 &= ~AR_VirtMoreFrag;
8068} 3745}
8069 3746
8070void ath9k_hw_putrxbuf(struct ath_hal *ah, u32 rxdp) 3747u32 ath9k_hw_getdefantenna(struct ath_hal *ah)
8071{ 3748{
8072 REG_WRITE(ah, AR_RXDP, rxdp); 3749 return REG_READ(ah, AR_DEF_ANTENNA) & 0x7;
8073} 3750}
8074 3751
8075void ath9k_hw_rxena(struct ath_hal *ah) 3752void ath9k_hw_setantenna(struct ath_hal *ah, u32 antenna)
8076{ 3753{
8077 REG_WRITE(ah, AR_CR, AR_CR_RXE); 3754 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
8078} 3755}
8079 3756
8080bool ath9k_hw_setrxabort(struct ath_hal *ah, bool set) 3757bool ath9k_hw_setantennaswitch(struct ath_hal *ah,
3758 enum ath9k_ant_setting settings,
3759 struct ath9k_channel *chan,
3760 u8 *tx_chainmask,
3761 u8 *rx_chainmask,
3762 u8 *antenna_cfgd)
8081{ 3763{
8082 if (set) { 3764 struct ath_hal_5416 *ahp = AH5416(ah);
8083 3765 static u8 tx_chainmask_cfg, rx_chainmask_cfg;
8084 REG_SET_BIT(ah, AR_DIAG_SW,
8085 (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
8086
8087 if (!ath9k_hw_wait
8088 (ah, AR_OBS_BUS_1, AR_OBS_BUS_1_RX_STATE, 0)) {
8089 u32 reg;
8090 3766
8091 REG_CLR_BIT(ah, AR_DIAG_SW, 3767 if (AR_SREV_9280(ah)) {
8092 (AR_DIAG_RX_DIS | 3768 if (!tx_chainmask_cfg) {
8093 AR_DIAG_RX_ABORT));
8094 3769
8095 reg = REG_READ(ah, AR_OBS_BUS_1); 3770 tx_chainmask_cfg = *tx_chainmask;
8096 DPRINTF(ah->ah_sc, ATH_DBG_FATAL, 3771 rx_chainmask_cfg = *rx_chainmask;
8097 "%s: rx failed to go idle in 10 ms RXSM=0x%x\n", 3772 }
8098 __func__, reg);
8099 3773
8100 return false; 3774 switch (settings) {
3775 case ATH9K_ANT_FIXED_A:
3776 *tx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
3777 *rx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
3778 *antenna_cfgd = true;
3779 break;
3780 case ATH9K_ANT_FIXED_B:
3781 if (ah->ah_caps.tx_chainmask >
3782 ATH9K_ANTENNA1_CHAINMASK) {
3783 *tx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
3784 }
3785 *rx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
3786 *antenna_cfgd = true;
3787 break;
3788 case ATH9K_ANT_VARIABLE:
3789 *tx_chainmask = tx_chainmask_cfg;
3790 *rx_chainmask = rx_chainmask_cfg;
3791 *antenna_cfgd = true;
3792 break;
3793 default:
3794 break;
8101 } 3795 }
8102 } else { 3796 } else {
8103 REG_CLR_BIT(ah, AR_DIAG_SW, 3797 ahp->ah_diversityControl = settings;
8104 (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
8105 } 3798 }
8106 3799
8107 return true; 3800 return true;
8108} 3801}
8109 3802
8110void 3803/*********************/
8111ath9k_hw_setmcastfilter(struct ath_hal *ah, u32 filter0, 3804/* General Operation */
8112 u32 filter1) 3805/*********************/
8113{
8114 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
8115 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
8116}
8117 3806
8118bool 3807u32 ath9k_hw_getrxfilter(struct ath_hal *ah)
8119ath9k_hw_setuprxdesc(struct ath_hal *ah, struct ath_desc *ds,
8120 u32 size, u32 flags)
8121{ 3808{
8122 struct ar5416_desc *ads = AR5416DESC(ds); 3809 u32 bits = REG_READ(ah, AR_RX_FILTER);
8123 struct ath9k_hw_capabilities *pCap = &ah->ah_caps; 3810 u32 phybits = REG_READ(ah, AR_PHY_ERR);
8124 3811
8125 ads->ds_ctl1 = size & AR_BufLen; 3812 if (phybits & AR_PHY_ERR_RADAR)
8126 if (flags & ATH9K_RXDESC_INTREQ) 3813 bits |= ATH9K_RX_FILTER_PHYRADAR;
8127 ads->ds_ctl1 |= AR_RxIntrReq; 3814 if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
3815 bits |= ATH9K_RX_FILTER_PHYERR;
8128 3816
8129 ads->ds_rxstatus8 &= ~AR_RxDone; 3817 return bits;
8130 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
8131 memset(&(ads->u), 0, sizeof(ads->u));
8132 return true;
8133} 3818}
8134 3819
8135int 3820void ath9k_hw_setrxfilter(struct ath_hal *ah, u32 bits)
8136ath9k_hw_rxprocdesc(struct ath_hal *ah, struct ath_desc *ds,
8137 u32 pa, struct ath_desc *nds, u64 tsf)
8138{ 3821{
8139 struct ar5416_desc ads; 3822 u32 phybits;
8140 struct ar5416_desc *adsp = AR5416DESC(ds);
8141
8142 if ((adsp->ds_rxstatus8 & AR_RxDone) == 0)
8143 return -EINPROGRESS;
8144
8145 ads.u.rx = adsp->u.rx;
8146
8147 ds->ds_rxstat.rs_status = 0;
8148 ds->ds_rxstat.rs_flags = 0;
8149 3823
8150 ds->ds_rxstat.rs_datalen = ads.ds_rxstatus1 & AR_DataLen; 3824 REG_WRITE(ah, AR_RX_FILTER, (bits & 0xffff) | AR_RX_COMPR_BAR);
8151 ds->ds_rxstat.rs_tstamp = ads.AR_RcvTimestamp; 3825 phybits = 0;
3826 if (bits & ATH9K_RX_FILTER_PHYRADAR)
3827 phybits |= AR_PHY_ERR_RADAR;
3828 if (bits & ATH9K_RX_FILTER_PHYERR)
3829 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
3830 REG_WRITE(ah, AR_PHY_ERR, phybits);
8152 3831
8153 ds->ds_rxstat.rs_rssi = MS(ads.ds_rxstatus4, AR_RxRSSICombined); 3832 if (phybits)
8154 ds->ds_rxstat.rs_rssi_ctl0 = MS(ads.ds_rxstatus0, AR_RxRSSIAnt00); 3833 REG_WRITE(ah, AR_RXCFG,
8155 ds->ds_rxstat.rs_rssi_ctl1 = MS(ads.ds_rxstatus0, AR_RxRSSIAnt01); 3834 REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
8156 ds->ds_rxstat.rs_rssi_ctl2 = MS(ads.ds_rxstatus0, AR_RxRSSIAnt02);
8157 ds->ds_rxstat.rs_rssi_ext0 = MS(ads.ds_rxstatus4, AR_RxRSSIAnt10);
8158 ds->ds_rxstat.rs_rssi_ext1 = MS(ads.ds_rxstatus4, AR_RxRSSIAnt11);
8159 ds->ds_rxstat.rs_rssi_ext2 = MS(ads.ds_rxstatus4, AR_RxRSSIAnt12);
8160 if (ads.ds_rxstatus8 & AR_RxKeyIdxValid)
8161 ds->ds_rxstat.rs_keyix = MS(ads.ds_rxstatus8, AR_KeyIdx);
8162 else 3835 else
8163 ds->ds_rxstat.rs_keyix = ATH9K_RXKEYIX_INVALID; 3836 REG_WRITE(ah, AR_RXCFG,
8164 3837 REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA);
8165 ds->ds_rxstat.rs_rate = RXSTATUS_RATE(ah, (&ads));
8166 ds->ds_rxstat.rs_more = (ads.ds_rxstatus1 & AR_RxMore) ? 1 : 0;
8167
8168 ds->ds_rxstat.rs_isaggr = (ads.ds_rxstatus8 & AR_RxAggr) ? 1 : 0;
8169 ds->ds_rxstat.rs_moreaggr =
8170 (ads.ds_rxstatus8 & AR_RxMoreAggr) ? 1 : 0;
8171 ds->ds_rxstat.rs_antenna = MS(ads.ds_rxstatus3, AR_RxAntenna);
8172 ds->ds_rxstat.rs_flags =
8173 (ads.ds_rxstatus3 & AR_GI) ? ATH9K_RX_GI : 0;
8174 ds->ds_rxstat.rs_flags |=
8175 (ads.ds_rxstatus3 & AR_2040) ? ATH9K_RX_2040 : 0;
8176
8177 if (ads.ds_rxstatus8 & AR_PreDelimCRCErr)
8178 ds->ds_rxstat.rs_flags |= ATH9K_RX_DELIM_CRC_PRE;
8179 if (ads.ds_rxstatus8 & AR_PostDelimCRCErr)
8180 ds->ds_rxstat.rs_flags |= ATH9K_RX_DELIM_CRC_POST;
8181 if (ads.ds_rxstatus8 & AR_DecryptBusyErr)
8182 ds->ds_rxstat.rs_flags |= ATH9K_RX_DECRYPT_BUSY;
8183
8184 if ((ads.ds_rxstatus8 & AR_RxFrameOK) == 0) {
8185
8186 if (ads.ds_rxstatus8 & AR_CRCErr)
8187 ds->ds_rxstat.rs_status |= ATH9K_RXERR_CRC;
8188 else if (ads.ds_rxstatus8 & AR_PHYErr) {
8189 u32 phyerr;
8190
8191 ds->ds_rxstat.rs_status |= ATH9K_RXERR_PHY;
8192 phyerr = MS(ads.ds_rxstatus8, AR_PHYErrCode);
8193 ds->ds_rxstat.rs_phyerr = phyerr;
8194 } else if (ads.ds_rxstatus8 & AR_DecryptCRCErr)
8195 ds->ds_rxstat.rs_status |= ATH9K_RXERR_DECRYPT;
8196 else if (ads.ds_rxstatus8 & AR_MichaelErr)
8197 ds->ds_rxstat.rs_status |= ATH9K_RXERR_MIC;
8198 }
8199
8200 return 0;
8201} 3838}
8202 3839
8203static void ath9k_hw_setup_rate_table(struct ath_hal *ah, 3840bool ath9k_hw_phy_disable(struct ath_hal *ah)
8204 struct ath9k_rate_table *rt)
8205{ 3841{
8206 int i; 3842 return ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM);
8207
8208 if (rt->rateCodeToIndex[0] != 0)
8209 return;
8210 for (i = 0; i < 256; i++)
8211 rt->rateCodeToIndex[i] = (u8) -1;
8212 for (i = 0; i < rt->rateCount; i++) {
8213 u8 code = rt->info[i].rateCode;
8214 u8 cix = rt->info[i].controlRate;
8215
8216 rt->rateCodeToIndex[code] = i;
8217 rt->rateCodeToIndex[code | rt->info[i].shortPreamble] = i;
8218
8219 rt->info[i].lpAckDuration =
8220 ath9k_hw_computetxtime(ah, rt,
8221 WLAN_CTRL_FRAME_SIZE,
8222 cix,
8223 false);
8224 rt->info[i].spAckDuration =
8225 ath9k_hw_computetxtime(ah, rt,
8226 WLAN_CTRL_FRAME_SIZE,
8227 cix,
8228 true);
8229 }
8230} 3843}
8231 3844
8232const struct ath9k_rate_table *ath9k_hw_getratetable(struct ath_hal *ah, 3845bool ath9k_hw_disable(struct ath_hal *ah)
8233 u32 mode)
8234{ 3846{
8235 struct ath9k_rate_table *rt; 3847 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
8236 switch (mode) { 3848 return false;
8237 case ATH9K_MODE_11A:
8238 rt = &ar5416_11a_table;
8239 break;
8240 case ATH9K_MODE_11B:
8241 rt = &ar5416_11b_table;
8242 break;
8243 case ATH9K_MODE_11G:
8244 rt = &ar5416_11g_table;
8245 break;
8246 case ATH9K_MODE_11NG_HT20:
8247 case ATH9K_MODE_11NG_HT40PLUS:
8248 case ATH9K_MODE_11NG_HT40MINUS:
8249 rt = &ar5416_11ng_table;
8250 break;
8251 case ATH9K_MODE_11NA_HT20:
8252 case ATH9K_MODE_11NA_HT40PLUS:
8253 case ATH9K_MODE_11NA_HT40MINUS:
8254 rt = &ar5416_11na_table;
8255 break;
8256 default:
8257 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL, "%s: invalid mode 0x%x\n",
8258 __func__, mode);
8259 return NULL;
8260 }
8261 ath9k_hw_setup_rate_table(ah, rt);
8262 return rt;
8263}
8264 3849
8265static const char *ath9k_hw_devname(u16 devid) 3850 return ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD);
8266{
8267 switch (devid) {
8268 case AR5416_DEVID_PCI:
8269 case AR5416_DEVID_PCIE:
8270 return "Atheros 5416";
8271 case AR9160_DEVID_PCI:
8272 return "Atheros 9160";
8273 case AR9280_DEVID_PCI:
8274 case AR9280_DEVID_PCIE:
8275 return "Atheros 9280";
8276 }
8277 return NULL;
8278} 3851}
8279 3852
8280const char *ath9k_hw_probe(u16 vendorid, u16 devid) 3853bool ath9k_hw_set_txpowerlimit(struct ath_hal *ah, u32 limit)
8281{ 3854{
8282 return vendorid == ATHEROS_VENDOR_ID ? 3855 struct ath9k_channel *chan = ah->ah_curchan;
8283 ath9k_hw_devname(devid) : NULL;
8284}
8285 3856
8286struct ath_hal *ath9k_hw_attach(u16 devid, 3857 ah->ah_powerLimit = min(limit, (u32) MAX_RATE_POWER);
8287 struct ath_softc *sc,
8288 void __iomem *mem,
8289 int *error)
8290{
8291 struct ath_hal *ah = NULL;
8292 3858
8293 switch (devid) { 3859 if (ath9k_hw_set_txpower(ah, chan,
8294 case AR5416_DEVID_PCI: 3860 ath9k_regd_get_ctl(ah, chan),
8295 case AR5416_DEVID_PCIE: 3861 ath9k_regd_get_antenna_allowed(ah, chan),
8296 case AR9160_DEVID_PCI: 3862 chan->maxRegTxPower * 2,
8297 case AR9280_DEVID_PCI: 3863 min((u32) MAX_RATE_POWER,
8298 case AR9280_DEVID_PCIE: 3864 (u32) ah->ah_powerLimit)) != 0)
8299 ah = ath9k_hw_do_attach(devid, sc, mem, error); 3865 return false;
8300 break;
8301 default:
8302 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
8303 "devid=0x%x not supported.\n", devid);
8304 ah = NULL;
8305 *error = -ENXIO;
8306 break;
8307 }
8308 3866
8309 return ah; 3867 return true;
8310} 3868}
8311 3869
8312u16 3870void ath9k_hw_getmac(struct ath_hal *ah, u8 *mac)
8313ath9k_hw_computetxtime(struct ath_hal *ah,
8314 const struct ath9k_rate_table *rates,
8315 u32 frameLen, u16 rateix,
8316 bool shortPreamble)
8317{ 3871{
8318 u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime; 3872 struct ath_hal_5416 *ahp = AH5416(ah);
8319 u32 kbps;
8320
8321 kbps = rates->info[rateix].rateKbps;
8322
8323 if (kbps == 0)
8324 return 0;
8325 switch (rates->info[rateix].phy) {
8326
8327 case PHY_CCK:
8328 phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
8329 if (shortPreamble && rates->info[rateix].shortPreamble)
8330 phyTime >>= 1;
8331 numBits = frameLen << 3;
8332 txTime = CCK_SIFS_TIME + phyTime
8333 + ((numBits * 1000) / kbps);
8334 break;
8335 case PHY_OFDM:
8336 if (ah->ah_curchan && IS_CHAN_QUARTER_RATE(ah->ah_curchan)) {
8337 bitsPerSymbol =
8338 (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
8339
8340 numBits = OFDM_PLCP_BITS + (frameLen << 3);
8341 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
8342 txTime = OFDM_SIFS_TIME_QUARTER
8343 + OFDM_PREAMBLE_TIME_QUARTER
8344 + (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
8345 } else if (ah->ah_curchan &&
8346 IS_CHAN_HALF_RATE(ah->ah_curchan)) {
8347 bitsPerSymbol =
8348 (kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
8349
8350 numBits = OFDM_PLCP_BITS + (frameLen << 3);
8351 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
8352 txTime = OFDM_SIFS_TIME_HALF +
8353 OFDM_PREAMBLE_TIME_HALF
8354 + (numSymbols * OFDM_SYMBOL_TIME_HALF);
8355 } else {
8356 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
8357
8358 numBits = OFDM_PLCP_BITS + (frameLen << 3);
8359 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
8360 txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME
8361 + (numSymbols * OFDM_SYMBOL_TIME);
8362 }
8363 break;
8364 3873
8365 default: 3874 memcpy(mac, ahp->ah_macaddr, ETH_ALEN);
8366 DPRINTF(ah->ah_sc, ATH_DBG_PHY_IO,
8367 "%s: unknown phy %u (rate ix %u)\n", __func__,
8368 rates->info[rateix].phy, rateix);
8369 txTime = 0;
8370 break;
8371 }
8372 return txTime;
8373} 3875}
8374 3876
8375u32 ath9k_hw_mhz2ieee(struct ath_hal *ah, u32 freq, u32 flags) 3877bool ath9k_hw_setmac(struct ath_hal *ah, const u8 *mac)
8376{ 3878{
8377 if (flags & CHANNEL_2GHZ) { 3879 struct ath_hal_5416 *ahp = AH5416(ah);
8378 if (freq == 2484)
8379 return 14;
8380 if (freq < 2484)
8381 return (freq - 2407) / 5;
8382 else
8383 return 15 + ((freq - 2512) / 20);
8384 } else if (flags & CHANNEL_5GHZ) {
8385 if (ath9k_regd_is_public_safety_sku(ah) &&
8386 IS_CHAN_IN_PUBLIC_SAFETY_BAND(freq)) {
8387 return ((freq * 10) +
8388 (((freq % 5) == 2) ? 5 : 0) - 49400) / 5;
8389 } else if ((flags & CHANNEL_A) && (freq <= 5000)) {
8390 return (freq - 4000) / 5;
8391 } else {
8392 return (freq - 5000) / 5;
8393 }
8394 } else {
8395 if (freq == 2484)
8396 return 14;
8397 if (freq < 2484)
8398 return (freq - 2407) / 5;
8399 if (freq < 5000) {
8400 if (ath9k_regd_is_public_safety_sku(ah)
8401 && IS_CHAN_IN_PUBLIC_SAFETY_BAND(freq)) {
8402 return ((freq * 10) +
8403 (((freq % 5) ==
8404 2) ? 5 : 0) - 49400) / 5;
8405 } else if (freq > 4900) {
8406 return (freq - 4000) / 5;
8407 } else {
8408 return 15 + ((freq - 2512) / 20);
8409 }
8410 }
8411 return (freq - 5000) / 5;
8412 }
8413}
8414 3880
8415/* We can tune this as we go by monitoring really low values */ 3881 memcpy(ahp->ah_macaddr, mac, ETH_ALEN);
8416#define ATH9K_NF_TOO_LOW -60
8417 3882
8418/* AR5416 may return very high value (like -31 dBm), in those cases the nf
8419 * is incorrect and we should use the static NF value. Later we can try to
8420 * find out why they are reporting these values */
8421static bool ath9k_hw_nf_in_range(struct ath_hal *ah, s16 nf)
8422{
8423 if (nf > ATH9K_NF_TOO_LOW) {
8424 DPRINTF(ah->ah_sc, ATH_DBG_NF_CAL,
8425 "%s: noise floor value detected (%d) is "
8426 "lower than what we think is a "
8427 "reasonable value (%d)\n",
8428 __func__, nf, ATH9K_NF_TOO_LOW);
8429 return false;
8430 }
8431 return true; 3883 return true;
8432} 3884}
8433 3885
8434s16 3886void ath9k_hw_setopmode(struct ath_hal *ah)
8435ath9k_hw_getchan_noise(struct ath_hal *ah, struct ath9k_channel *chan)
8436{ 3887{
8437 struct ath9k_channel *ichan; 3888 ath9k_hw_set_operating_mode(ah, ah->ah_opmode);
8438 s16 nf;
8439
8440 ichan = ath9k_regd_check_channel(ah, chan);
8441 if (ichan == NULL) {
8442 DPRINTF(ah->ah_sc, ATH_DBG_NF_CAL,
8443 "%s: invalid channel %u/0x%x; no mapping\n",
8444 __func__, chan->channel, chan->channelFlags);
8445 return ATH_DEFAULT_NOISE_FLOOR;
8446 }
8447 if (ichan->rawNoiseFloor == 0) {
8448 enum wireless_mode mode = ath9k_hw_chan2wmode(ah, chan);
8449 nf = NOISE_FLOOR[mode];
8450 } else
8451 nf = ichan->rawNoiseFloor;
8452
8453 if (!ath9k_hw_nf_in_range(ah, nf))
8454 nf = ATH_DEFAULT_NOISE_FLOOR;
8455
8456 return nf;
8457} 3889}
8458 3890
8459bool ath9k_hw_set_tsfadjust(struct ath_hal *ah, u32 setting) 3891void ath9k_hw_setmcastfilter(struct ath_hal *ah, u32 filter0, u32 filter1)
8460{ 3892{
8461 struct ath_hal_5416 *ahp = AH5416(ah); 3893 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
8462 3894 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
8463 if (setting)
8464 ahp->ah_miscMode |= AR_PCU_TX_ADD_TSF;
8465 else
8466 ahp->ah_miscMode &= ~AR_PCU_TX_ADD_TSF;
8467 return true;
8468} 3895}
8469 3896
8470bool ath9k_hw_phycounters(struct ath_hal *ah) 3897void ath9k_hw_getbssidmask(struct ath_hal *ah, u8 *mask)
8471{ 3898{
8472 struct ath_hal_5416 *ahp = AH5416(ah); 3899 struct ath_hal_5416 *ahp = AH5416(ah);
8473 3900
8474 return ahp->ah_hasHwPhyCounters ? true : false; 3901 memcpy(mask, ahp->ah_bssidmask, ETH_ALEN);
8475} 3902}
8476 3903
8477u32 ath9k_hw_gettxbuf(struct ath_hal *ah, u32 q) 3904bool ath9k_hw_setbssidmask(struct ath_hal *ah, const u8 *mask)
8478{ 3905{
8479 return REG_READ(ah, AR_QTXDP(q)); 3906 struct ath_hal_5416 *ahp = AH5416(ah);
8480}
8481 3907
8482bool ath9k_hw_puttxbuf(struct ath_hal *ah, u32 q, 3908 memcpy(ahp->ah_bssidmask, mask, ETH_ALEN);
8483 u32 txdp) 3909
8484{ 3910 REG_WRITE(ah, AR_BSSMSKL, get_unaligned_le32(ahp->ah_bssidmask));
8485 REG_WRITE(ah, AR_QTXDP(q), txdp); 3911 REG_WRITE(ah, AR_BSSMSKU, get_unaligned_le16(ahp->ah_bssidmask + 4));
8486 3912
8487 return true; 3913 return true;
8488} 3914}
8489 3915
8490bool ath9k_hw_txstart(struct ath_hal *ah, u32 q) 3916void ath9k_hw_write_associd(struct ath_hal *ah, const u8 *bssid, u16 assocId)
8491{ 3917{
8492 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "%s: queue %u\n", __func__, q); 3918 struct ath_hal_5416 *ahp = AH5416(ah);
8493 3919
8494 REG_WRITE(ah, AR_Q_TXE, 1 << q); 3920 memcpy(ahp->ah_bssid, bssid, ETH_ALEN);
3921 ahp->ah_assocId = assocId;
8495 3922
8496 return true; 3923 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(ahp->ah_bssid));
3924 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(ahp->ah_bssid + 4) |
3925 ((assocId & 0x3fff) << AR_BSS_ID1_AID_S));
8497} 3926}
8498 3927
8499u32 ath9k_hw_numtxpending(struct ath_hal *ah, u32 q) 3928u64 ath9k_hw_gettsf64(struct ath_hal *ah)
8500{ 3929{
8501 u32 npend; 3930 u64 tsf;
8502 3931
8503 npend = REG_READ(ah, AR_QSTS(q)) & AR_Q_STS_PEND_FR_CNT; 3932 tsf = REG_READ(ah, AR_TSF_U32);
8504 if (npend == 0) { 3933 tsf = (tsf << 32) | REG_READ(ah, AR_TSF_L32);
8505 3934
8506 if (REG_READ(ah, AR_Q_TXE) & (1 << q)) 3935 return tsf;
8507 npend = 1;
8508 }
8509 return npend;
8510} 3936}
8511 3937
8512bool ath9k_hw_stoptxdma(struct ath_hal *ah, u32 q) 3938void ath9k_hw_reset_tsf(struct ath_hal *ah)
8513{ 3939{
8514 u32 wait; 3940 int count;
8515
8516 REG_WRITE(ah, AR_Q_TXD, 1 << q);
8517 3941
8518 for (wait = 1000; wait != 0; wait--) { 3942 count = 0;
8519 if (ath9k_hw_numtxpending(ah, q) == 0) 3943 while (REG_READ(ah, AR_SLP32_MODE) & AR_SLP32_TSF_WRITE_STATUS) {
3944 count++;
3945 if (count > 10) {
3946 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
3947 "%s: AR_SLP32_TSF_WRITE_STATUS limit exceeded\n",
3948 __func__);
8520 break; 3949 break;
8521 udelay(100); 3950 }
3951 udelay(10);
8522 } 3952 }
3953 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
3954}
8523 3955
8524 if (ath9k_hw_numtxpending(ah, q)) { 3956bool ath9k_hw_set_tsfadjust(struct ath_hal *ah, u32 setting)
8525 u32 tsfLow, j; 3957{
8526 3958 struct ath_hal_5416 *ahp = AH5416(ah);
8527 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
8528 "%s: Num of pending TX Frames %d on Q %d\n",
8529 __func__, ath9k_hw_numtxpending(ah, q), q);
8530
8531 for (j = 0; j < 2; j++) {
8532 tsfLow = REG_READ(ah, AR_TSF_L32);
8533 REG_WRITE(ah, AR_QUIET2,
8534 SM(10, AR_QUIET2_QUIET_DUR));
8535 REG_WRITE(ah, AR_QUIET_PERIOD, 100);
8536 REG_WRITE(ah, AR_NEXT_QUIET_TIMER, tsfLow >> 10);
8537 REG_SET_BIT(ah, AR_TIMER_MODE,
8538 AR_QUIET_TIMER_EN);
8539 3959
8540 if ((REG_READ(ah, AR_TSF_L32) >> 10) == 3960 if (setting)
8541 (tsfLow >> 10)) { 3961 ahp->ah_miscMode |= AR_PCU_TX_ADD_TSF;
8542 break; 3962 else
8543 } 3963 ahp->ah_miscMode &= ~AR_PCU_TX_ADD_TSF;
8544 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
8545 "%s: TSF have moved while trying to set "
8546 "quiet time TSF: 0x%08x\n",
8547 __func__, tsfLow);
8548 }
8549 3964
8550 REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_FORCE_CH_IDLE_HIGH); 3965 return true;
3966}
8551 3967
8552 udelay(200); 3968bool ath9k_hw_setslottime(struct ath_hal *ah, u32 us)
8553 REG_CLR_BIT(ah, AR_TIMER_MODE, AR_QUIET_TIMER_EN); 3969{
3970 struct ath_hal_5416 *ahp = AH5416(ah);
8554 3971
8555 wait = 1000; 3972 if (us < ATH9K_SLOT_TIME_9 || us > ath9k_hw_mac_to_usec(ah, 0xffff)) {
3973 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "%s: bad slot time %u\n",
3974 __func__, us);
3975 ahp->ah_slottime = (u32) -1;
3976 return false;
3977 } else {
3978 REG_WRITE(ah, AR_D_GBL_IFS_SLOT, ath9k_hw_mac_to_clks(ah, us));
3979 ahp->ah_slottime = us;
3980 return true;
3981 }
3982}
8556 3983
8557 while (ath9k_hw_numtxpending(ah, q)) { 3984void ath9k_hw_set11nmac2040(struct ath_hal *ah, enum ath9k_ht_macmode mode)
8558 if ((--wait) == 0) { 3985{
8559 DPRINTF(ah->ah_sc, ATH_DBG_XMIT, 3986 u32 macmode;
8560 "%s: Failed to stop Tx DMA in 100 "
8561 "msec after killing last frame\n",
8562 __func__);
8563 break;
8564 }
8565 udelay(100);
8566 }
8567 3987
8568 REG_CLR_BIT(ah, AR_DIAG_SW, AR_DIAG_FORCE_CH_IDLE_HIGH); 3988 if (mode == ATH9K_HT_MACMODE_2040 &&
8569 } 3989 !ah->ah_config.cwm_ignore_extcca)
3990 macmode = AR_2040_JOINED_RX_CLEAR;
3991 else
3992 macmode = 0;
8570 3993
8571 REG_WRITE(ah, AR_Q_TXD, 0); 3994 REG_WRITE(ah, AR_2040_MODE, macmode);
8572 return wait != 0;
8573} 3995}
diff --git a/drivers/net/wireless/ath9k/hw.h b/drivers/net/wireless/ath9k/hw.h
index 2113818ee934..6a29f2d43c21 100644
--- a/drivers/net/wireless/ath9k/hw.h
+++ b/drivers/net/wireless/ath9k/hw.h
@@ -923,7 +923,7 @@ struct ath_hal_5416 {
923#define OFDM_PLCP_BITS_QUARTER 22 923#define OFDM_PLCP_BITS_QUARTER 22
924#define OFDM_SYMBOL_TIME_QUARTER 16 924#define OFDM_SYMBOL_TIME_QUARTER 16
925 925
926u32 ath9k_hw_get_eeprom(struct ath_hal_5416 *ahp, 926u32 ath9k_hw_get_eeprom(struct ath_hal *ah,
927 enum eeprom_param param); 927 enum eeprom_param param);
928 928
929#endif 929#endif
diff --git a/drivers/net/wireless/ath9k/mac.c b/drivers/net/wireless/ath9k/mac.c
new file mode 100644
index 000000000000..c344a81e738a
--- /dev/null
+++ b/drivers/net/wireless/ath9k/mac.c
@@ -0,0 +1,1031 @@
1/*
2 * Copyright (c) 2008 Atheros Communications Inc.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#include "core.h"
18#include "hw.h"
19#include "reg.h"
20#include "phy.h"
21
22static void ath9k_hw_set_txq_interrupts(struct ath_hal *ah,
23 struct ath9k_tx_queue_info *qi)
24{
25 struct ath_hal_5416 *ahp = AH5416(ah);
26
27 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT,
28 "%s: tx ok 0x%x err 0x%x desc 0x%x eol 0x%x urn 0x%x\n",
29 __func__, ahp->ah_txOkInterruptMask,
30 ahp->ah_txErrInterruptMask, ahp->ah_txDescInterruptMask,
31 ahp->ah_txEolInterruptMask, ahp->ah_txUrnInterruptMask);
32
33 REG_WRITE(ah, AR_IMR_S0,
34 SM(ahp->ah_txOkInterruptMask, AR_IMR_S0_QCU_TXOK)
35 | SM(ahp->ah_txDescInterruptMask, AR_IMR_S0_QCU_TXDESC));
36 REG_WRITE(ah, AR_IMR_S1,
37 SM(ahp->ah_txErrInterruptMask, AR_IMR_S1_QCU_TXERR)
38 | SM(ahp->ah_txEolInterruptMask, AR_IMR_S1_QCU_TXEOL));
39 REG_RMW_FIELD(ah, AR_IMR_S2,
40 AR_IMR_S2_QCU_TXURN, ahp->ah_txUrnInterruptMask);
41}
42
43void ath9k_hw_dmaRegDump(struct ath_hal *ah)
44{
45 u32 val[ATH9K_NUM_DMA_DEBUG_REGS];
46 int qcuOffset = 0, dcuOffset = 0;
47 u32 *qcuBase = &val[0], *dcuBase = &val[4];
48 int i;
49
50 REG_WRITE(ah, AR_MACMISC,
51 ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
52 (AR_MACMISC_MISC_OBS_BUS_1 <<
53 AR_MACMISC_MISC_OBS_BUS_MSB_S)));
54
55 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO, "Raw DMA Debug values:\n");
56
57 for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
58 if (i % 4 == 0)
59 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO, "\n");
60
61 val[i] = REG_READ(ah, AR_DMADBG_0 + (i * sizeof(u32)));
62 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO, "%d: %08x ", i, val[i]);
63 }
64
65 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO, "\n\n");
66 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
67 "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
68
69 for (i = 0; i < ATH9K_NUM_QUEUES;
70 i++, qcuOffset += 4, dcuOffset += 5) {
71 if (i == 8) {
72 qcuOffset = 0;
73 qcuBase++;
74 }
75
76 if (i == 6) {
77 dcuOffset = 0;
78 dcuBase++;
79 }
80
81 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
82 "%2d %2x %1x %2x %2x\n",
83 i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
84 (*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3),
85 val[2] & (0x7 << (i * 3)) >> (i * 3),
86 (*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
87 }
88
89 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO, "\n");
90 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
91 "qcu_stitch state: %2x qcu_fetch state: %2x\n",
92 (val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);
93 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
94 "qcu_complete state: %2x dcu_complete state: %2x\n",
95 (val[3] & 0x1c000000) >> 26, (val[6] & 0x3));
96 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
97 "dcu_arb state: %2x dcu_fp state: %2x\n",
98 (val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);
99 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
100 "chan_idle_dur: %3d chan_idle_dur_valid: %1d\n",
101 (val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);
102 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
103 "txfifo_valid_0: %1d txfifo_valid_1: %1d\n",
104 (val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);
105 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
106 "txfifo_dcu_num_0: %2d txfifo_dcu_num_1: %2d\n",
107 (val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);
108
109 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO, "pcu observe 0x%x \n",
110 REG_READ(ah, AR_OBS_BUS_1));
111 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
112 "AR_CR 0x%x \n", REG_READ(ah, AR_CR));
113}
114
115u32 ath9k_hw_gettxbuf(struct ath_hal *ah, u32 q)
116{
117 return REG_READ(ah, AR_QTXDP(q));
118}
119
120bool ath9k_hw_puttxbuf(struct ath_hal *ah, u32 q, u32 txdp)
121{
122 REG_WRITE(ah, AR_QTXDP(q), txdp);
123
124 return true;
125}
126
127bool ath9k_hw_txstart(struct ath_hal *ah, u32 q)
128{
129 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "%s: queue %u\n", __func__, q);
130
131 REG_WRITE(ah, AR_Q_TXE, 1 << q);
132
133 return true;
134}
135
136u32 ath9k_hw_numtxpending(struct ath_hal *ah, u32 q)
137{
138 u32 npend;
139
140 npend = REG_READ(ah, AR_QSTS(q)) & AR_Q_STS_PEND_FR_CNT;
141 if (npend == 0) {
142
143 if (REG_READ(ah, AR_Q_TXE) & (1 << q))
144 npend = 1;
145 }
146
147 return npend;
148}
149
150bool ath9k_hw_updatetxtriglevel(struct ath_hal *ah, bool bIncTrigLevel)
151{
152 struct ath_hal_5416 *ahp = AH5416(ah);
153 u32 txcfg, curLevel, newLevel;
154 enum ath9k_int omask;
155
156 if (ah->ah_txTrigLevel >= MAX_TX_FIFO_THRESHOLD)
157 return false;
158
159 omask = ath9k_hw_set_interrupts(ah, ahp->ah_maskReg & ~ATH9K_INT_GLOBAL);
160
161 txcfg = REG_READ(ah, AR_TXCFG);
162 curLevel = MS(txcfg, AR_FTRIG);
163 newLevel = curLevel;
164 if (bIncTrigLevel) {
165 if (curLevel < MAX_TX_FIFO_THRESHOLD)
166 newLevel++;
167 } else if (curLevel > MIN_TX_FIFO_THRESHOLD)
168 newLevel--;
169 if (newLevel != curLevel)
170 REG_WRITE(ah, AR_TXCFG,
171 (txcfg & ~AR_FTRIG) | SM(newLevel, AR_FTRIG));
172
173 ath9k_hw_set_interrupts(ah, omask);
174
175 ah->ah_txTrigLevel = newLevel;
176
177 return newLevel != curLevel;
178}
179
180bool ath9k_hw_stoptxdma(struct ath_hal *ah, u32 q)
181{
182 u32 tsfLow, j, wait;
183
184 REG_WRITE(ah, AR_Q_TXD, 1 << q);
185
186 for (wait = 1000; wait != 0; wait--) {
187 if (ath9k_hw_numtxpending(ah, q) == 0)
188 break;
189 udelay(100);
190 }
191
192 if (ath9k_hw_numtxpending(ah, q)) {
193 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
194 "%s: Num of pending TX Frames %d on Q %d\n",
195 __func__, ath9k_hw_numtxpending(ah, q), q);
196
197 for (j = 0; j < 2; j++) {
198 tsfLow = REG_READ(ah, AR_TSF_L32);
199 REG_WRITE(ah, AR_QUIET2,
200 SM(10, AR_QUIET2_QUIET_DUR));
201 REG_WRITE(ah, AR_QUIET_PERIOD, 100);
202 REG_WRITE(ah, AR_NEXT_QUIET_TIMER, tsfLow >> 10);
203 REG_SET_BIT(ah, AR_TIMER_MODE,
204 AR_QUIET_TIMER_EN);
205
206 if ((REG_READ(ah, AR_TSF_L32) >> 10) == (tsfLow >> 10))
207 break;
208
209 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
210 "%s: TSF have moved while trying to set "
211 "quiet time TSF: 0x%08x\n",
212 __func__, tsfLow);
213 }
214
215 REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_FORCE_CH_IDLE_HIGH);
216
217 udelay(200);
218 REG_CLR_BIT(ah, AR_TIMER_MODE, AR_QUIET_TIMER_EN);
219
220 wait = 1000;
221
222 while (ath9k_hw_numtxpending(ah, q)) {
223 if ((--wait) == 0) {
224 DPRINTF(ah->ah_sc, ATH_DBG_XMIT,
225 "%s: Failed to stop Tx DMA in 100 "
226 "msec after killing last frame\n",
227 __func__);
228 break;
229 }
230 udelay(100);
231 }
232
233 REG_CLR_BIT(ah, AR_DIAG_SW, AR_DIAG_FORCE_CH_IDLE_HIGH);
234 }
235
236 REG_WRITE(ah, AR_Q_TXD, 0);
237
238 return wait != 0;
239}
240
241bool ath9k_hw_filltxdesc(struct ath_hal *ah, struct ath_desc *ds,
242 u32 segLen, bool firstSeg,
243 bool lastSeg, const struct ath_desc *ds0)
244{
245 struct ar5416_desc *ads = AR5416DESC(ds);
246
247 if (firstSeg) {
248 ads->ds_ctl1 |= segLen | (lastSeg ? 0 : AR_TxMore);
249 } else if (lastSeg) {
250 ads->ds_ctl0 = 0;
251 ads->ds_ctl1 = segLen;
252 ads->ds_ctl2 = AR5416DESC_CONST(ds0)->ds_ctl2;
253 ads->ds_ctl3 = AR5416DESC_CONST(ds0)->ds_ctl3;
254 } else {
255 ads->ds_ctl0 = 0;
256 ads->ds_ctl1 = segLen | AR_TxMore;
257 ads->ds_ctl2 = 0;
258 ads->ds_ctl3 = 0;
259 }
260 ads->ds_txstatus0 = ads->ds_txstatus1 = 0;
261 ads->ds_txstatus2 = ads->ds_txstatus3 = 0;
262 ads->ds_txstatus4 = ads->ds_txstatus5 = 0;
263 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
264 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
265
266 return true;
267}
268
269void ath9k_hw_cleartxdesc(struct ath_hal *ah, struct ath_desc *ds)
270{
271 struct ar5416_desc *ads = AR5416DESC(ds);
272
273 ads->ds_txstatus0 = ads->ds_txstatus1 = 0;
274 ads->ds_txstatus2 = ads->ds_txstatus3 = 0;
275 ads->ds_txstatus4 = ads->ds_txstatus5 = 0;
276 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
277 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
278}
279
280int ath9k_hw_txprocdesc(struct ath_hal *ah, struct ath_desc *ds)
281{
282 struct ar5416_desc *ads = AR5416DESC(ds);
283
284 if ((ads->ds_txstatus9 & AR_TxDone) == 0)
285 return -EINPROGRESS;
286
287 ds->ds_txstat.ts_seqnum = MS(ads->ds_txstatus9, AR_SeqNum);
288 ds->ds_txstat.ts_tstamp = ads->AR_SendTimestamp;
289 ds->ds_txstat.ts_status = 0;
290 ds->ds_txstat.ts_flags = 0;
291
292 if (ads->ds_txstatus1 & AR_ExcessiveRetries)
293 ds->ds_txstat.ts_status |= ATH9K_TXERR_XRETRY;
294 if (ads->ds_txstatus1 & AR_Filtered)
295 ds->ds_txstat.ts_status |= ATH9K_TXERR_FILT;
296 if (ads->ds_txstatus1 & AR_FIFOUnderrun)
297 ds->ds_txstat.ts_status |= ATH9K_TXERR_FIFO;
298 if (ads->ds_txstatus9 & AR_TxOpExceeded)
299 ds->ds_txstat.ts_status |= ATH9K_TXERR_XTXOP;
300 if (ads->ds_txstatus1 & AR_TxTimerExpired)
301 ds->ds_txstat.ts_status |= ATH9K_TXERR_TIMER_EXPIRED;
302
303 if (ads->ds_txstatus1 & AR_DescCfgErr)
304 ds->ds_txstat.ts_flags |= ATH9K_TX_DESC_CFG_ERR;
305 if (ads->ds_txstatus1 & AR_TxDataUnderrun) {
306 ds->ds_txstat.ts_flags |= ATH9K_TX_DATA_UNDERRUN;
307 ath9k_hw_updatetxtriglevel(ah, true);
308 }
309 if (ads->ds_txstatus1 & AR_TxDelimUnderrun) {
310 ds->ds_txstat.ts_flags |= ATH9K_TX_DELIM_UNDERRUN;
311 ath9k_hw_updatetxtriglevel(ah, true);
312 }
313 if (ads->ds_txstatus0 & AR_TxBaStatus) {
314 ds->ds_txstat.ts_flags |= ATH9K_TX_BA;
315 ds->ds_txstat.ba_low = ads->AR_BaBitmapLow;
316 ds->ds_txstat.ba_high = ads->AR_BaBitmapHigh;
317 }
318
319 ds->ds_txstat.ts_rateindex = MS(ads->ds_txstatus9, AR_FinalTxIdx);
320 switch (ds->ds_txstat.ts_rateindex) {
321 case 0:
322 ds->ds_txstat.ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate0);
323 break;
324 case 1:
325 ds->ds_txstat.ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate1);
326 break;
327 case 2:
328 ds->ds_txstat.ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate2);
329 break;
330 case 3:
331 ds->ds_txstat.ts_ratecode = MS(ads->ds_ctl3, AR_XmitRate3);
332 break;
333 }
334
335 ds->ds_txstat.ts_rssi = MS(ads->ds_txstatus5, AR_TxRSSICombined);
336 ds->ds_txstat.ts_rssi_ctl0 = MS(ads->ds_txstatus0, AR_TxRSSIAnt00);
337 ds->ds_txstat.ts_rssi_ctl1 = MS(ads->ds_txstatus0, AR_TxRSSIAnt01);
338 ds->ds_txstat.ts_rssi_ctl2 = MS(ads->ds_txstatus0, AR_TxRSSIAnt02);
339 ds->ds_txstat.ts_rssi_ext0 = MS(ads->ds_txstatus5, AR_TxRSSIAnt10);
340 ds->ds_txstat.ts_rssi_ext1 = MS(ads->ds_txstatus5, AR_TxRSSIAnt11);
341 ds->ds_txstat.ts_rssi_ext2 = MS(ads->ds_txstatus5, AR_TxRSSIAnt12);
342 ds->ds_txstat.evm0 = ads->AR_TxEVM0;
343 ds->ds_txstat.evm1 = ads->AR_TxEVM1;
344 ds->ds_txstat.evm2 = ads->AR_TxEVM2;
345 ds->ds_txstat.ts_shortretry = MS(ads->ds_txstatus1, AR_RTSFailCnt);
346 ds->ds_txstat.ts_longretry = MS(ads->ds_txstatus1, AR_DataFailCnt);
347 ds->ds_txstat.ts_virtcol = MS(ads->ds_txstatus1, AR_VirtRetryCnt);
348 ds->ds_txstat.ts_antenna = 1;
349
350 return 0;
351}
352
353void ath9k_hw_set11n_txdesc(struct ath_hal *ah, struct ath_desc *ds,
354 u32 pktLen, enum ath9k_pkt_type type, u32 txPower,
355 u32 keyIx, enum ath9k_key_type keyType, u32 flags)
356{
357 struct ar5416_desc *ads = AR5416DESC(ds);
358 struct ath_hal_5416 *ahp = AH5416(ah);
359
360 txPower += ahp->ah_txPowerIndexOffset;
361 if (txPower > 63)
362 txPower = 63;
363
364 ads->ds_ctl0 = (pktLen & AR_FrameLen)
365 | (flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
366 | SM(txPower, AR_XmitPower)
367 | (flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
368 | (flags & ATH9K_TXDESC_CLRDMASK ? AR_ClrDestMask : 0)
369 | (flags & ATH9K_TXDESC_INTREQ ? AR_TxIntrReq : 0)
370 | (keyIx != ATH9K_TXKEYIX_INVALID ? AR_DestIdxValid : 0);
371
372 ads->ds_ctl1 =
373 (keyIx != ATH9K_TXKEYIX_INVALID ? SM(keyIx, AR_DestIdx) : 0)
374 | SM(type, AR_FrameType)
375 | (flags & ATH9K_TXDESC_NOACK ? AR_NoAck : 0)
376 | (flags & ATH9K_TXDESC_EXT_ONLY ? AR_ExtOnly : 0)
377 | (flags & ATH9K_TXDESC_EXT_AND_CTL ? AR_ExtAndCtl : 0);
378
379 ads->ds_ctl6 = SM(keyType, AR_EncrType);
380
381 if (AR_SREV_9285(ah)) {
382 ads->ds_ctl8 = 0;
383 ads->ds_ctl9 = 0;
384 ads->ds_ctl10 = 0;
385 ads->ds_ctl11 = 0;
386 }
387}
388
389void ath9k_hw_set11n_ratescenario(struct ath_hal *ah, struct ath_desc *ds,
390 struct ath_desc *lastds,
391 u32 durUpdateEn, u32 rtsctsRate,
392 u32 rtsctsDuration,
393 struct ath9k_11n_rate_series series[],
394 u32 nseries, u32 flags)
395{
396 struct ar5416_desc *ads = AR5416DESC(ds);
397 struct ar5416_desc *last_ads = AR5416DESC(lastds);
398 u32 ds_ctl0;
399
400 (void) nseries;
401 (void) rtsctsDuration;
402
403 if (flags & (ATH9K_TXDESC_RTSENA | ATH9K_TXDESC_CTSENA)) {
404 ds_ctl0 = ads->ds_ctl0;
405
406 if (flags & ATH9K_TXDESC_RTSENA) {
407 ds_ctl0 &= ~AR_CTSEnable;
408 ds_ctl0 |= AR_RTSEnable;
409 } else {
410 ds_ctl0 &= ~AR_RTSEnable;
411 ds_ctl0 |= AR_CTSEnable;
412 }
413
414 ads->ds_ctl0 = ds_ctl0;
415 } else {
416 ads->ds_ctl0 =
417 (ads->ds_ctl0 & ~(AR_RTSEnable | AR_CTSEnable));
418 }
419
420 ads->ds_ctl2 = set11nTries(series, 0)
421 | set11nTries(series, 1)
422 | set11nTries(series, 2)
423 | set11nTries(series, 3)
424 | (durUpdateEn ? AR_DurUpdateEna : 0)
425 | SM(0, AR_BurstDur);
426
427 ads->ds_ctl3 = set11nRate(series, 0)
428 | set11nRate(series, 1)
429 | set11nRate(series, 2)
430 | set11nRate(series, 3);
431
432 ads->ds_ctl4 = set11nPktDurRTSCTS(series, 0)
433 | set11nPktDurRTSCTS(series, 1);
434
435 ads->ds_ctl5 = set11nPktDurRTSCTS(series, 2)
436 | set11nPktDurRTSCTS(series, 3);
437
438 ads->ds_ctl7 = set11nRateFlags(series, 0)
439 | set11nRateFlags(series, 1)
440 | set11nRateFlags(series, 2)
441 | set11nRateFlags(series, 3)
442 | SM(rtsctsRate, AR_RTSCTSRate);
443 last_ads->ds_ctl2 = ads->ds_ctl2;
444 last_ads->ds_ctl3 = ads->ds_ctl3;
445}
446
447void ath9k_hw_set11n_aggr_first(struct ath_hal *ah, struct ath_desc *ds,
448 u32 aggrLen)
449{
450 struct ar5416_desc *ads = AR5416DESC(ds);
451
452 ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
453 ads->ds_ctl6 &= ~AR_AggrLen;
454 ads->ds_ctl6 |= SM(aggrLen, AR_AggrLen);
455}
456
457void ath9k_hw_set11n_aggr_middle(struct ath_hal *ah, struct ath_desc *ds,
458 u32 numDelims)
459{
460 struct ar5416_desc *ads = AR5416DESC(ds);
461 unsigned int ctl6;
462
463 ads->ds_ctl1 |= (AR_IsAggr | AR_MoreAggr);
464
465 ctl6 = ads->ds_ctl6;
466 ctl6 &= ~AR_PadDelim;
467 ctl6 |= SM(numDelims, AR_PadDelim);
468 ads->ds_ctl6 = ctl6;
469}
470
471void ath9k_hw_set11n_aggr_last(struct ath_hal *ah, struct ath_desc *ds)
472{
473 struct ar5416_desc *ads = AR5416DESC(ds);
474
475 ads->ds_ctl1 |= AR_IsAggr;
476 ads->ds_ctl1 &= ~AR_MoreAggr;
477 ads->ds_ctl6 &= ~AR_PadDelim;
478}
479
480void ath9k_hw_clr11n_aggr(struct ath_hal *ah, struct ath_desc *ds)
481{
482 struct ar5416_desc *ads = AR5416DESC(ds);
483
484 ads->ds_ctl1 &= (~AR_IsAggr & ~AR_MoreAggr);
485}
486
487void ath9k_hw_set11n_burstduration(struct ath_hal *ah, struct ath_desc *ds,
488 u32 burstDuration)
489{
490 struct ar5416_desc *ads = AR5416DESC(ds);
491
492 ads->ds_ctl2 &= ~AR_BurstDur;
493 ads->ds_ctl2 |= SM(burstDuration, AR_BurstDur);
494}
495
496void ath9k_hw_set11n_virtualmorefrag(struct ath_hal *ah, struct ath_desc *ds,
497 u32 vmf)
498{
499 struct ar5416_desc *ads = AR5416DESC(ds);
500
501 if (vmf)
502 ads->ds_ctl0 |= AR_VirtMoreFrag;
503 else
504 ads->ds_ctl0 &= ~AR_VirtMoreFrag;
505}
506
507void ath9k_hw_gettxintrtxqs(struct ath_hal *ah, u32 *txqs)
508{
509 struct ath_hal_5416 *ahp = AH5416(ah);
510
511 *txqs &= ahp->ah_intrTxqs;
512 ahp->ah_intrTxqs &= ~(*txqs);
513}
514
515bool ath9k_hw_set_txq_props(struct ath_hal *ah, int q,
516 const struct ath9k_tx_queue_info *qinfo)
517{
518 u32 cw;
519 struct ath_hal_5416 *ahp = AH5416(ah);
520 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
521 struct ath9k_tx_queue_info *qi;
522
523 if (q >= pCap->total_queues) {
524 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "%s: invalid queue num %u\n",
525 __func__, q);
526 return false;
527 }
528
529 qi = &ahp->ah_txq[q];
530 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
531 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "%s: inactive queue\n",
532 __func__);
533 return false;
534 }
535
536 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "%s: queue %p\n", __func__, qi);
537
538 qi->tqi_ver = qinfo->tqi_ver;
539 qi->tqi_subtype = qinfo->tqi_subtype;
540 qi->tqi_qflags = qinfo->tqi_qflags;
541 qi->tqi_priority = qinfo->tqi_priority;
542 if (qinfo->tqi_aifs != ATH9K_TXQ_USEDEFAULT)
543 qi->tqi_aifs = min(qinfo->tqi_aifs, 255U);
544 else
545 qi->tqi_aifs = INIT_AIFS;
546 if (qinfo->tqi_cwmin != ATH9K_TXQ_USEDEFAULT) {
547 cw = min(qinfo->tqi_cwmin, 1024U);
548 qi->tqi_cwmin = 1;
549 while (qi->tqi_cwmin < cw)
550 qi->tqi_cwmin = (qi->tqi_cwmin << 1) | 1;
551 } else
552 qi->tqi_cwmin = qinfo->tqi_cwmin;
553 if (qinfo->tqi_cwmax != ATH9K_TXQ_USEDEFAULT) {
554 cw = min(qinfo->tqi_cwmax, 1024U);
555 qi->tqi_cwmax = 1;
556 while (qi->tqi_cwmax < cw)
557 qi->tqi_cwmax = (qi->tqi_cwmax << 1) | 1;
558 } else
559 qi->tqi_cwmax = INIT_CWMAX;
560
561 if (qinfo->tqi_shretry != 0)
562 qi->tqi_shretry = min((u32) qinfo->tqi_shretry, 15U);
563 else
564 qi->tqi_shretry = INIT_SH_RETRY;
565 if (qinfo->tqi_lgretry != 0)
566 qi->tqi_lgretry = min((u32) qinfo->tqi_lgretry, 15U);
567 else
568 qi->tqi_lgretry = INIT_LG_RETRY;
569 qi->tqi_cbrPeriod = qinfo->tqi_cbrPeriod;
570 qi->tqi_cbrOverflowLimit = qinfo->tqi_cbrOverflowLimit;
571 qi->tqi_burstTime = qinfo->tqi_burstTime;
572 qi->tqi_readyTime = qinfo->tqi_readyTime;
573
574 switch (qinfo->tqi_subtype) {
575 case ATH9K_WME_UPSD:
576 if (qi->tqi_type == ATH9K_TX_QUEUE_DATA)
577 qi->tqi_intFlags = ATH9K_TXQ_USE_LOCKOUT_BKOFF_DIS;
578 break;
579 default:
580 break;
581 }
582
583 return true;
584}
585
586bool ath9k_hw_get_txq_props(struct ath_hal *ah, int q,
587 struct ath9k_tx_queue_info *qinfo)
588{
589 struct ath_hal_5416 *ahp = AH5416(ah);
590 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
591 struct ath9k_tx_queue_info *qi;
592
593 if (q >= pCap->total_queues) {
594 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "%s: invalid queue num %u\n",
595 __func__, q);
596 return false;
597 }
598
599 qi = &ahp->ah_txq[q];
600 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
601 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "%s: inactive queue\n",
602 __func__);
603 return false;
604 }
605
606 qinfo->tqi_qflags = qi->tqi_qflags;
607 qinfo->tqi_ver = qi->tqi_ver;
608 qinfo->tqi_subtype = qi->tqi_subtype;
609 qinfo->tqi_qflags = qi->tqi_qflags;
610 qinfo->tqi_priority = qi->tqi_priority;
611 qinfo->tqi_aifs = qi->tqi_aifs;
612 qinfo->tqi_cwmin = qi->tqi_cwmin;
613 qinfo->tqi_cwmax = qi->tqi_cwmax;
614 qinfo->tqi_shretry = qi->tqi_shretry;
615 qinfo->tqi_lgretry = qi->tqi_lgretry;
616 qinfo->tqi_cbrPeriod = qi->tqi_cbrPeriod;
617 qinfo->tqi_cbrOverflowLimit = qi->tqi_cbrOverflowLimit;
618 qinfo->tqi_burstTime = qi->tqi_burstTime;
619 qinfo->tqi_readyTime = qi->tqi_readyTime;
620
621 return true;
622}
623
624int ath9k_hw_setuptxqueue(struct ath_hal *ah, enum ath9k_tx_queue type,
625 const struct ath9k_tx_queue_info *qinfo)
626{
627 struct ath_hal_5416 *ahp = AH5416(ah);
628 struct ath9k_tx_queue_info *qi;
629 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
630 int q;
631
632 switch (type) {
633 case ATH9K_TX_QUEUE_BEACON:
634 q = pCap->total_queues - 1;
635 break;
636 case ATH9K_TX_QUEUE_CAB:
637 q = pCap->total_queues - 2;
638 break;
639 case ATH9K_TX_QUEUE_PSPOLL:
640 q = 1;
641 break;
642 case ATH9K_TX_QUEUE_UAPSD:
643 q = pCap->total_queues - 3;
644 break;
645 case ATH9K_TX_QUEUE_DATA:
646 for (q = 0; q < pCap->total_queues; q++)
647 if (ahp->ah_txq[q].tqi_type ==
648 ATH9K_TX_QUEUE_INACTIVE)
649 break;
650 if (q == pCap->total_queues) {
651 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
652 "%s: no available tx queue\n", __func__);
653 return -1;
654 }
655 break;
656 default:
657 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "%s: bad tx queue type %u\n",
658 __func__, type);
659 return -1;
660 }
661
662 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "%s: queue %u\n", __func__, q);
663
664 qi = &ahp->ah_txq[q];
665 if (qi->tqi_type != ATH9K_TX_QUEUE_INACTIVE) {
666 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
667 "%s: tx queue %u already active\n", __func__, q);
668 return -1;
669 }
670 memset(qi, 0, sizeof(struct ath9k_tx_queue_info));
671 qi->tqi_type = type;
672 if (qinfo == NULL) {
673 qi->tqi_qflags =
674 TXQ_FLAG_TXOKINT_ENABLE
675 | TXQ_FLAG_TXERRINT_ENABLE
676 | TXQ_FLAG_TXDESCINT_ENABLE | TXQ_FLAG_TXURNINT_ENABLE;
677 qi->tqi_aifs = INIT_AIFS;
678 qi->tqi_cwmin = ATH9K_TXQ_USEDEFAULT;
679 qi->tqi_cwmax = INIT_CWMAX;
680 qi->tqi_shretry = INIT_SH_RETRY;
681 qi->tqi_lgretry = INIT_LG_RETRY;
682 qi->tqi_physCompBuf = 0;
683 } else {
684 qi->tqi_physCompBuf = qinfo->tqi_physCompBuf;
685 (void) ath9k_hw_set_txq_props(ah, q, qinfo);
686 }
687
688 return q;
689}
690
691bool ath9k_hw_releasetxqueue(struct ath_hal *ah, u32 q)
692{
693 struct ath_hal_5416 *ahp = AH5416(ah);
694 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
695 struct ath9k_tx_queue_info *qi;
696
697 if (q >= pCap->total_queues) {
698 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "%s: invalid queue num %u\n",
699 __func__, q);
700 return false;
701 }
702 qi = &ahp->ah_txq[q];
703 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
704 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "%s: inactive queue %u\n",
705 __func__, q);
706 return false;
707 }
708
709 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "%s: release queue %u\n",
710 __func__, q);
711
712 qi->tqi_type = ATH9K_TX_QUEUE_INACTIVE;
713 ahp->ah_txOkInterruptMask &= ~(1 << q);
714 ahp->ah_txErrInterruptMask &= ~(1 << q);
715 ahp->ah_txDescInterruptMask &= ~(1 << q);
716 ahp->ah_txEolInterruptMask &= ~(1 << q);
717 ahp->ah_txUrnInterruptMask &= ~(1 << q);
718 ath9k_hw_set_txq_interrupts(ah, qi);
719
720 return true;
721}
722
723bool ath9k_hw_resettxqueue(struct ath_hal *ah, u32 q)
724{
725 struct ath_hal_5416 *ahp = AH5416(ah);
726 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
727 struct ath9k_channel *chan = ah->ah_curchan;
728 struct ath9k_tx_queue_info *qi;
729 u32 cwMin, chanCwMin, value;
730
731 if (q >= pCap->total_queues) {
732 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "%s: invalid queue num %u\n",
733 __func__, q);
734 return false;
735 }
736
737 qi = &ahp->ah_txq[q];
738 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
739 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "%s: inactive queue %u\n",
740 __func__, q);
741 return true;
742 }
743
744 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "%s: reset queue %u\n", __func__, q);
745
746 if (qi->tqi_cwmin == ATH9K_TXQ_USEDEFAULT) {
747 if (chan && IS_CHAN_B(chan))
748 chanCwMin = INIT_CWMIN_11B;
749 else
750 chanCwMin = INIT_CWMIN;
751
752 for (cwMin = 1; cwMin < chanCwMin; cwMin = (cwMin << 1) | 1);
753 } else
754 cwMin = qi->tqi_cwmin;
755
756 REG_WRITE(ah, AR_DLCL_IFS(q),
757 SM(cwMin, AR_D_LCL_IFS_CWMIN) |
758 SM(qi->tqi_cwmax, AR_D_LCL_IFS_CWMAX) |
759 SM(qi->tqi_aifs, AR_D_LCL_IFS_AIFS));
760
761 REG_WRITE(ah, AR_DRETRY_LIMIT(q),
762 SM(INIT_SSH_RETRY, AR_D_RETRY_LIMIT_STA_SH) |
763 SM(INIT_SLG_RETRY, AR_D_RETRY_LIMIT_STA_LG) |
764 SM(qi->tqi_shretry, AR_D_RETRY_LIMIT_FR_SH));
765
766 REG_WRITE(ah, AR_QMISC(q), AR_Q_MISC_DCU_EARLY_TERM_REQ);
767 REG_WRITE(ah, AR_DMISC(q),
768 AR_D_MISC_CW_BKOFF_EN | AR_D_MISC_FRAG_WAIT_EN | 0x2);
769
770 if (qi->tqi_cbrPeriod) {
771 REG_WRITE(ah, AR_QCBRCFG(q),
772 SM(qi->tqi_cbrPeriod, AR_Q_CBRCFG_INTERVAL) |
773 SM(qi->tqi_cbrOverflowLimit, AR_Q_CBRCFG_OVF_THRESH));
774 REG_WRITE(ah, AR_QMISC(q),
775 REG_READ(ah, AR_QMISC(q)) | AR_Q_MISC_FSP_CBR |
776 (qi->tqi_cbrOverflowLimit ?
777 AR_Q_MISC_CBR_EXP_CNTR_LIMIT_EN : 0));
778 }
779 if (qi->tqi_readyTime && (qi->tqi_type != ATH9K_TX_QUEUE_CAB)) {
780 REG_WRITE(ah, AR_QRDYTIMECFG(q),
781 SM(qi->tqi_readyTime, AR_Q_RDYTIMECFG_DURATION) |
782 AR_Q_RDYTIMECFG_EN);
783 }
784
785 REG_WRITE(ah, AR_DCHNTIME(q),
786 SM(qi->tqi_burstTime, AR_D_CHNTIME_DUR) |
787 (qi->tqi_burstTime ? AR_D_CHNTIME_EN : 0));
788
789 if (qi->tqi_burstTime
790 && (qi->tqi_qflags & TXQ_FLAG_RDYTIME_EXP_POLICY_ENABLE)) {
791 REG_WRITE(ah, AR_QMISC(q),
792 REG_READ(ah, AR_QMISC(q)) |
793 AR_Q_MISC_RDYTIME_EXP_POLICY);
794
795 }
796
797 if (qi->tqi_qflags & TXQ_FLAG_BACKOFF_DISABLE) {
798 REG_WRITE(ah, AR_DMISC(q),
799 REG_READ(ah, AR_DMISC(q)) |
800 AR_D_MISC_POST_FR_BKOFF_DIS);
801 }
802 if (qi->tqi_qflags & TXQ_FLAG_FRAG_BURST_BACKOFF_ENABLE) {
803 REG_WRITE(ah, AR_DMISC(q),
804 REG_READ(ah, AR_DMISC(q)) |
805 AR_D_MISC_FRAG_BKOFF_EN);
806 }
807 switch (qi->tqi_type) {
808 case ATH9K_TX_QUEUE_BEACON:
809 REG_WRITE(ah, AR_QMISC(q), REG_READ(ah, AR_QMISC(q))
810 | AR_Q_MISC_FSP_DBA_GATED
811 | AR_Q_MISC_BEACON_USE
812 | AR_Q_MISC_CBR_INCR_DIS1);
813
814 REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q))
815 | (AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL <<
816 AR_D_MISC_ARB_LOCKOUT_CNTRL_S)
817 | AR_D_MISC_BEACON_USE
818 | AR_D_MISC_POST_FR_BKOFF_DIS);
819 break;
820 case ATH9K_TX_QUEUE_CAB:
821 REG_WRITE(ah, AR_QMISC(q), REG_READ(ah, AR_QMISC(q))
822 | AR_Q_MISC_FSP_DBA_GATED
823 | AR_Q_MISC_CBR_INCR_DIS1
824 | AR_Q_MISC_CBR_INCR_DIS0);
825 value = (qi->tqi_readyTime -
826 (ah->ah_config.sw_beacon_response_time -
827 ah->ah_config.dma_beacon_response_time) -
828 ah->ah_config.additional_swba_backoff) * 1024;
829 REG_WRITE(ah, AR_QRDYTIMECFG(q),
830 value | AR_Q_RDYTIMECFG_EN);
831 REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q))
832 | (AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL <<
833 AR_D_MISC_ARB_LOCKOUT_CNTRL_S));
834 break;
835 case ATH9K_TX_QUEUE_PSPOLL:
836 REG_WRITE(ah, AR_QMISC(q),
837 REG_READ(ah, AR_QMISC(q)) | AR_Q_MISC_CBR_INCR_DIS1);
838 break;
839 case ATH9K_TX_QUEUE_UAPSD:
840 REG_WRITE(ah, AR_DMISC(q), REG_READ(ah, AR_DMISC(q)) |
841 AR_D_MISC_POST_FR_BKOFF_DIS);
842 break;
843 default:
844 break;
845 }
846
847 if (qi->tqi_intFlags & ATH9K_TXQ_USE_LOCKOUT_BKOFF_DIS) {
848 REG_WRITE(ah, AR_DMISC(q),
849 REG_READ(ah, AR_DMISC(q)) |
850 SM(AR_D_MISC_ARB_LOCKOUT_CNTRL_GLOBAL,
851 AR_D_MISC_ARB_LOCKOUT_CNTRL) |
852 AR_D_MISC_POST_FR_BKOFF_DIS);
853 }
854
855 if (qi->tqi_qflags & TXQ_FLAG_TXOKINT_ENABLE)
856 ahp->ah_txOkInterruptMask |= 1 << q;
857 else
858 ahp->ah_txOkInterruptMask &= ~(1 << q);
859 if (qi->tqi_qflags & TXQ_FLAG_TXERRINT_ENABLE)
860 ahp->ah_txErrInterruptMask |= 1 << q;
861 else
862 ahp->ah_txErrInterruptMask &= ~(1 << q);
863 if (qi->tqi_qflags & TXQ_FLAG_TXDESCINT_ENABLE)
864 ahp->ah_txDescInterruptMask |= 1 << q;
865 else
866 ahp->ah_txDescInterruptMask &= ~(1 << q);
867 if (qi->tqi_qflags & TXQ_FLAG_TXEOLINT_ENABLE)
868 ahp->ah_txEolInterruptMask |= 1 << q;
869 else
870 ahp->ah_txEolInterruptMask &= ~(1 << q);
871 if (qi->tqi_qflags & TXQ_FLAG_TXURNINT_ENABLE)
872 ahp->ah_txUrnInterruptMask |= 1 << q;
873 else
874 ahp->ah_txUrnInterruptMask &= ~(1 << q);
875 ath9k_hw_set_txq_interrupts(ah, qi);
876
877 return true;
878}
879
880int ath9k_hw_rxprocdesc(struct ath_hal *ah, struct ath_desc *ds,
881 u32 pa, struct ath_desc *nds, u64 tsf)
882{
883 struct ar5416_desc ads;
884 struct ar5416_desc *adsp = AR5416DESC(ds);
885 u32 phyerr;
886
887 if ((adsp->ds_rxstatus8 & AR_RxDone) == 0)
888 return -EINPROGRESS;
889
890 ads.u.rx = adsp->u.rx;
891
892 ds->ds_rxstat.rs_status = 0;
893 ds->ds_rxstat.rs_flags = 0;
894
895 ds->ds_rxstat.rs_datalen = ads.ds_rxstatus1 & AR_DataLen;
896 ds->ds_rxstat.rs_tstamp = ads.AR_RcvTimestamp;
897
898 ds->ds_rxstat.rs_rssi = MS(ads.ds_rxstatus4, AR_RxRSSICombined);
899 ds->ds_rxstat.rs_rssi_ctl0 = MS(ads.ds_rxstatus0, AR_RxRSSIAnt00);
900 ds->ds_rxstat.rs_rssi_ctl1 = MS(ads.ds_rxstatus0, AR_RxRSSIAnt01);
901 ds->ds_rxstat.rs_rssi_ctl2 = MS(ads.ds_rxstatus0, AR_RxRSSIAnt02);
902 ds->ds_rxstat.rs_rssi_ext0 = MS(ads.ds_rxstatus4, AR_RxRSSIAnt10);
903 ds->ds_rxstat.rs_rssi_ext1 = MS(ads.ds_rxstatus4, AR_RxRSSIAnt11);
904 ds->ds_rxstat.rs_rssi_ext2 = MS(ads.ds_rxstatus4, AR_RxRSSIAnt12);
905 if (ads.ds_rxstatus8 & AR_RxKeyIdxValid)
906 ds->ds_rxstat.rs_keyix = MS(ads.ds_rxstatus8, AR_KeyIdx);
907 else
908 ds->ds_rxstat.rs_keyix = ATH9K_RXKEYIX_INVALID;
909
910 ds->ds_rxstat.rs_rate = RXSTATUS_RATE(ah, (&ads));
911 ds->ds_rxstat.rs_more = (ads.ds_rxstatus1 & AR_RxMore) ? 1 : 0;
912
913 ds->ds_rxstat.rs_isaggr = (ads.ds_rxstatus8 & AR_RxAggr) ? 1 : 0;
914 ds->ds_rxstat.rs_moreaggr =
915 (ads.ds_rxstatus8 & AR_RxMoreAggr) ? 1 : 0;
916 ds->ds_rxstat.rs_antenna = MS(ads.ds_rxstatus3, AR_RxAntenna);
917 ds->ds_rxstat.rs_flags =
918 (ads.ds_rxstatus3 & AR_GI) ? ATH9K_RX_GI : 0;
919 ds->ds_rxstat.rs_flags |=
920 (ads.ds_rxstatus3 & AR_2040) ? ATH9K_RX_2040 : 0;
921
922 if (ads.ds_rxstatus8 & AR_PreDelimCRCErr)
923 ds->ds_rxstat.rs_flags |= ATH9K_RX_DELIM_CRC_PRE;
924 if (ads.ds_rxstatus8 & AR_PostDelimCRCErr)
925 ds->ds_rxstat.rs_flags |= ATH9K_RX_DELIM_CRC_POST;
926 if (ads.ds_rxstatus8 & AR_DecryptBusyErr)
927 ds->ds_rxstat.rs_flags |= ATH9K_RX_DECRYPT_BUSY;
928
929 if ((ads.ds_rxstatus8 & AR_RxFrameOK) == 0) {
930 if (ads.ds_rxstatus8 & AR_CRCErr)
931 ds->ds_rxstat.rs_status |= ATH9K_RXERR_CRC;
932 else if (ads.ds_rxstatus8 & AR_PHYErr) {
933 ds->ds_rxstat.rs_status |= ATH9K_RXERR_PHY;
934 phyerr = MS(ads.ds_rxstatus8, AR_PHYErrCode);
935 ds->ds_rxstat.rs_phyerr = phyerr;
936 } else if (ads.ds_rxstatus8 & AR_DecryptCRCErr)
937 ds->ds_rxstat.rs_status |= ATH9K_RXERR_DECRYPT;
938 else if (ads.ds_rxstatus8 & AR_MichaelErr)
939 ds->ds_rxstat.rs_status |= ATH9K_RXERR_MIC;
940 }
941
942 return 0;
943}
944
945bool ath9k_hw_setuprxdesc(struct ath_hal *ah, struct ath_desc *ds,
946 u32 size, u32 flags)
947{
948 struct ar5416_desc *ads = AR5416DESC(ds);
949 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
950
951 ads->ds_ctl1 = size & AR_BufLen;
952 if (flags & ATH9K_RXDESC_INTREQ)
953 ads->ds_ctl1 |= AR_RxIntrReq;
954
955 ads->ds_rxstatus8 &= ~AR_RxDone;
956 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
957 memset(&(ads->u), 0, sizeof(ads->u));
958
959 return true;
960}
961
962bool ath9k_hw_setrxabort(struct ath_hal *ah, bool set)
963{
964 u32 reg;
965
966 if (set) {
967 REG_SET_BIT(ah, AR_DIAG_SW,
968 (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
969
970 if (!ath9k_hw_wait(ah, AR_OBS_BUS_1, AR_OBS_BUS_1_RX_STATE, 0)) {
971 REG_CLR_BIT(ah, AR_DIAG_SW,
972 (AR_DIAG_RX_DIS |
973 AR_DIAG_RX_ABORT));
974
975 reg = REG_READ(ah, AR_OBS_BUS_1);
976 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
977 "%s: rx failed to go idle in 10 ms RXSM=0x%x\n",
978 __func__, reg);
979
980 return false;
981 }
982 } else {
983 REG_CLR_BIT(ah, AR_DIAG_SW,
984 (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
985 }
986
987 return true;
988}
989
990void ath9k_hw_putrxbuf(struct ath_hal *ah, u32 rxdp)
991{
992 REG_WRITE(ah, AR_RXDP, rxdp);
993}
994
995void ath9k_hw_rxena(struct ath_hal *ah)
996{
997 REG_WRITE(ah, AR_CR, AR_CR_RXE);
998}
999
1000void ath9k_hw_startpcureceive(struct ath_hal *ah)
1001{
1002 REG_CLR_BIT(ah, AR_DIAG_SW,
1003 (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
1004
1005 ath9k_enable_mib_counters(ah);
1006
1007 ath9k_ani_reset(ah);
1008}
1009
1010void ath9k_hw_stoppcurecv(struct ath_hal *ah)
1011{
1012 REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_DIS);
1013
1014 ath9k_hw_disable_mib_counters(ah);
1015}
1016
1017bool ath9k_hw_stopdmarecv(struct ath_hal *ah)
1018{
1019 REG_WRITE(ah, AR_CR, AR_CR_RXD);
1020
1021 if (!ath9k_hw_wait(ah, AR_CR, AR_CR_RXE, 0)) {
1022 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
1023 "%s: dma failed to stop in 10ms\n"
1024 "AR_CR=0x%08x\nAR_DIAG_SW=0x%08x\n",
1025 __func__,
1026 REG_READ(ah, AR_CR), REG_READ(ah, AR_DIAG_SW));
1027 return false;
1028 } else {
1029 return true;
1030 }
1031}
diff --git a/drivers/net/wireless/ath9k/main.c b/drivers/net/wireless/ath9k/main.c
index f6dc4c826044..fb50aa0fc996 100644
--- a/drivers/net/wireless/ath9k/main.c
+++ b/drivers/net/wireless/ath9k/main.c
@@ -21,8 +21,6 @@
21 21
22#define ATH_PCI_VERSION "0.1" 22#define ATH_PCI_VERSION "0.1"
23 23
24#define IEEE80211_HTCAP_MAXRXAMPDU_FACTOR 13
25
26static char *dev_info = "ath9k"; 24static char *dev_info = "ath9k";
27 25
28MODULE_AUTHOR("Atheros Communications"); 26MODULE_AUTHOR("Atheros Communications");
@@ -164,7 +162,7 @@ static int ath_key_config(struct ath_softc *sc,
164 if (!sc->sc_vaps[0]) 162 if (!sc->sc_vaps[0])
165 return -EIO; 163 return -EIO;
166 164
167 vif = sc->sc_vaps[0]->av_if_data; 165 vif = sc->sc_vaps[0];
168 opmode = vif->type; 166 opmode = vif->type;
169 167
170 /* 168 /*
@@ -297,41 +295,6 @@ static void ath9k_rx_prepare(struct ath_softc *sc,
297 rx_status->flag |= RX_FLAG_TSFT; 295 rx_status->flag |= RX_FLAG_TSFT;
298} 296}
299 297
300static u8 parse_mpdudensity(u8 mpdudensity)
301{
302 /*
303 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
304 * 0 for no restriction
305 * 1 for 1/4 us
306 * 2 for 1/2 us
307 * 3 for 1 us
308 * 4 for 2 us
309 * 5 for 4 us
310 * 6 for 8 us
311 * 7 for 16 us
312 */
313 switch (mpdudensity) {
314 case 0:
315 return 0;
316 case 1:
317 case 2:
318 case 3:
319 /* Our lower layer calculations limit our precision to
320 1 microsecond */
321 return 1;
322 case 4:
323 return 2;
324 case 5:
325 return 4;
326 case 6:
327 return 8;
328 case 7:
329 return 16;
330 default:
331 return 0;
332 }
333}
334
335static void ath9k_ht_conf(struct ath_softc *sc, 298static void ath9k_ht_conf(struct ath_softc *sc,
336 struct ieee80211_bss_conf *bss_conf) 299 struct ieee80211_bss_conf *bss_conf)
337{ 300{
@@ -350,11 +313,12 @@ static void ath9k_ht_conf(struct ath_softc *sc,
350} 313}
351 314
352static void ath9k_bss_assoc_info(struct ath_softc *sc, 315static void ath9k_bss_assoc_info(struct ath_softc *sc,
316 struct ieee80211_vif *vif,
353 struct ieee80211_bss_conf *bss_conf) 317 struct ieee80211_bss_conf *bss_conf)
354{ 318{
355 struct ieee80211_hw *hw = sc->hw; 319 struct ieee80211_hw *hw = sc->hw;
356 struct ieee80211_channel *curchan = hw->conf.channel; 320 struct ieee80211_channel *curchan = hw->conf.channel;
357 struct ath_vap *avp; 321 struct ath_vap *avp = (void *)vif->drv_priv;
358 int pos; 322 int pos;
359 323
360 if (bss_conf->assoc) { 324 if (bss_conf->assoc) {
@@ -362,13 +326,6 @@ static void ath9k_bss_assoc_info(struct ath_softc *sc,
362 __func__, 326 __func__,
363 bss_conf->aid); 327 bss_conf->aid);
364 328
365 avp = sc->sc_vaps[0];
366 if (avp == NULL) {
367 DPRINTF(sc, ATH_DBG_FATAL, "%s: Invalid interface\n",
368 __func__);
369 return;
370 }
371
372 /* New association, store aid */ 329 /* New association, store aid */
373 if (avp->av_opmode == ATH9K_M_STA) { 330 if (avp->av_opmode == ATH9K_M_STA) {
374 sc->sc_curaid = bss_conf->aid; 331 sc->sc_curaid = bss_conf->aid;
@@ -449,7 +406,7 @@ void ath_get_beaconconfig(struct ath_softc *sc,
449} 406}
450 407
451void ath_tx_complete(struct ath_softc *sc, struct sk_buff *skb, 408void ath_tx_complete(struct ath_softc *sc, struct sk_buff *skb,
452 struct ath_xmit_status *tx_status, struct ath_node *an) 409 struct ath_xmit_status *tx_status)
453{ 410{
454 struct ieee80211_hw *hw = sc->hw; 411 struct ieee80211_hw *hw = sc->hw;
455 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); 412 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
@@ -479,8 +436,6 @@ void ath_tx_complete(struct ath_softc *sc, struct sk_buff *skb,
479 tx_info->status.rates[0].count = tx_status->retries + 1; 436 tx_info->status.rates[0].count = tx_status->retries + 1;
480 437
481 ieee80211_tx_status(hw, skb); 438 ieee80211_tx_status(hw, skb);
482 if (an)
483 ath_node_put(sc, an, ATH9K_BH_STATUS_CHANGE);
484} 439}
485 440
486int _ath_rx_indicate(struct ath_softc *sc, 441int _ath_rx_indicate(struct ath_softc *sc,
@@ -489,12 +444,10 @@ int _ath_rx_indicate(struct ath_softc *sc,
489 u16 keyix) 444 u16 keyix)
490{ 445{
491 struct ieee80211_hw *hw = sc->hw; 446 struct ieee80211_hw *hw = sc->hw;
492 struct ath_node *an = NULL;
493 struct ieee80211_rx_status rx_status; 447 struct ieee80211_rx_status rx_status;
494 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; 448 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
495 int hdrlen = ieee80211_get_hdrlen_from_skb(skb); 449 int hdrlen = ieee80211_get_hdrlen_from_skb(skb);
496 int padsize; 450 int padsize;
497 enum ATH_RX_TYPE st;
498 451
499 /* see if any padding is done by the hw and remove it */ 452 /* see if any padding is done by the hw and remove it */
500 if (hdrlen & 3) { 453 if (hdrlen & 3) {
@@ -518,33 +471,6 @@ int _ath_rx_indicate(struct ath_softc *sc,
518 rx_status.flag |= RX_FLAG_DECRYPTED; 471 rx_status.flag |= RX_FLAG_DECRYPTED;
519 } 472 }
520 473
521 spin_lock_bh(&sc->node_lock);
522 an = ath_node_find(sc, hdr->addr2);
523 spin_unlock_bh(&sc->node_lock);
524
525 if (an) {
526 ath_rx_input(sc, an,
527 skb, status, &st);
528 }
529 if (!an || (st != ATH_RX_CONSUMED))
530 __ieee80211_rx(hw, skb, &rx_status);
531
532 return 0;
533}
534
535int ath_rx_subframe(struct ath_node *an,
536 struct sk_buff *skb,
537 struct ath_recv_status *status)
538{
539 struct ath_softc *sc = an->an_sc;
540 struct ieee80211_hw *hw = sc->hw;
541 struct ieee80211_rx_status rx_status;
542
543 /* Prepare rx status */
544 ath9k_rx_prepare(sc, skb, status, &rx_status);
545 if (!(status->flags & ATH_RX_DECRYPT_ERROR))
546 rx_status.flag |= RX_FLAG_DECRYPTED;
547
548 __ieee80211_rx(hw, skb, &rx_status); 474 __ieee80211_rx(hw, skb, &rx_status);
549 475
550 return 0; 476 return 0;
@@ -666,6 +592,7 @@ fail:
666} 592}
667 593
668#ifdef CONFIG_RFKILL 594#ifdef CONFIG_RFKILL
595
669/*******************/ 596/*******************/
670/* Rfkill */ 597/* Rfkill */
671/*******************/ 598/*******************/
@@ -866,43 +793,72 @@ static void ath_deinit_rfkill(struct ath_softc *sc)
866 sc->rf_kill.rfkill = NULL; 793 sc->rf_kill.rfkill = NULL;
867 } 794 }
868} 795}
796
797static int ath_start_rfkill_poll(struct ath_softc *sc)
798{
799 if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
800 queue_delayed_work(sc->hw->workqueue,
801 &sc->rf_kill.rfkill_poll, 0);
802
803 if (!(sc->sc_flags & SC_OP_RFKILL_REGISTERED)) {
804 if (rfkill_register(sc->rf_kill.rfkill)) {
805 DPRINTF(sc, ATH_DBG_FATAL,
806 "Unable to register rfkill\n");
807 rfkill_free(sc->rf_kill.rfkill);
808
809 /* Deinitialize the device */
810 if (sc->pdev->irq)
811 free_irq(sc->pdev->irq, sc);
812 ath_detach(sc);
813 pci_iounmap(sc->pdev, sc->mem);
814 pci_release_region(sc->pdev, 0);
815 pci_disable_device(sc->pdev);
816 ieee80211_free_hw(hw);
817 return -EIO;
818 } else {
819 sc->sc_flags |= SC_OP_RFKILL_REGISTERED;
820 }
821 }
822
823 return 0;
824}
869#endif /* CONFIG_RFKILL */ 825#endif /* CONFIG_RFKILL */
870 826
871static int ath_detach(struct ath_softc *sc) 827static void ath_detach(struct ath_softc *sc)
872{ 828{
873 struct ieee80211_hw *hw = sc->hw; 829 struct ieee80211_hw *hw = sc->hw;
830 int i = 0;
874 831
875 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Detach ATH hw\n", __func__); 832 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Detach ATH hw\n", __func__);
876 833
877 /* Deinit LED control */ 834 ieee80211_unregister_hw(hw);
835
878 ath_deinit_leds(sc); 836 ath_deinit_leds(sc);
879 837
880#ifdef CONFIG_RFKILL 838#ifdef CONFIG_RFKILL
881 /* deinit rfkill */
882 ath_deinit_rfkill(sc); 839 ath_deinit_rfkill(sc);
883#endif 840#endif
884
885 /* Unregister hw */
886
887 ieee80211_unregister_hw(hw);
888
889 /* unregister Rate control */
890 ath_rate_control_unregister(); 841 ath_rate_control_unregister();
891 842 ath_rate_detach(sc->sc_rc);
892 /* tx/rx cleanup */
893 843
894 ath_rx_cleanup(sc); 844 ath_rx_cleanup(sc);
895 ath_tx_cleanup(sc); 845 ath_tx_cleanup(sc);
896 846
897 /* Deinit */ 847 tasklet_kill(&sc->intr_tq);
848 tasklet_kill(&sc->bcon_tasklet);
898 849
899 ath_deinit(sc); 850 if (!(sc->sc_flags & SC_OP_INVALID))
851 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE);
900 852
901 return 0; 853 /* cleanup tx queues */
854 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
855 if (ATH_TXQ_SETUP(sc, i))
856 ath_tx_cleanupq(sc, &sc->sc_txq[i]);
857
858 ath9k_hw_detach(sc->sc_ah);
902} 859}
903 860
904static int ath_attach(u16 devid, 861static int ath_attach(u16 devid, struct ath_softc *sc)
905 struct ath_softc *sc)
906{ 862{
907 struct ieee80211_hw *hw = sc->hw; 863 struct ieee80211_hw *hw = sc->hw;
908 int error = 0; 864 int error = 0;
@@ -913,47 +869,23 @@ static int ath_attach(u16 devid,
913 if (error != 0) 869 if (error != 0)
914 return error; 870 return error;
915 871
916 /* Init nodes */
917
918 INIT_LIST_HEAD(&sc->node_list);
919 spin_lock_init(&sc->node_lock);
920
921 /* get mac address from hardware and set in mac80211 */ 872 /* get mac address from hardware and set in mac80211 */
922 873
923 SET_IEEE80211_PERM_ADDR(hw, sc->sc_myaddr); 874 SET_IEEE80211_PERM_ADDR(hw, sc->sc_myaddr);
924 875
925 /* setup channels and rates */ 876 hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
926 877 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
927 sc->sbands[IEEE80211_BAND_2GHZ].channels = 878 IEEE80211_HW_SIGNAL_DBM |
928 sc->channels[IEEE80211_BAND_2GHZ]; 879 IEEE80211_HW_AMPDU_AGGREGATION;
929 sc->sbands[IEEE80211_BAND_2GHZ].bitrates =
930 sc->rates[IEEE80211_BAND_2GHZ];
931 sc->sbands[IEEE80211_BAND_2GHZ].band = IEEE80211_BAND_2GHZ;
932
933 if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_HT)
934 /* Setup HT capabilities for 2.4Ghz*/
935 setup_ht_cap(&sc->sbands[IEEE80211_BAND_2GHZ].ht_cap);
936
937 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
938 &sc->sbands[IEEE80211_BAND_2GHZ];
939
940 if (test_bit(ATH9K_MODE_11A, sc->sc_ah->ah_caps.wireless_modes)) {
941 sc->sbands[IEEE80211_BAND_5GHZ].channels =
942 sc->channels[IEEE80211_BAND_5GHZ];
943 sc->sbands[IEEE80211_BAND_5GHZ].bitrates =
944 sc->rates[IEEE80211_BAND_5GHZ];
945 sc->sbands[IEEE80211_BAND_5GHZ].band =
946 IEEE80211_BAND_5GHZ;
947
948 if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_HT)
949 /* Setup HT capabilities for 5Ghz*/
950 setup_ht_cap(&sc->sbands[IEEE80211_BAND_5GHZ].ht_cap);
951 880
952 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = 881 hw->wiphy->interface_modes =
953 &sc->sbands[IEEE80211_BAND_5GHZ]; 882 BIT(NL80211_IFTYPE_AP) |
954 } 883 BIT(NL80211_IFTYPE_STATION) |
884 BIT(NL80211_IFTYPE_ADHOC);
955 885
956 hw->queues = 4; 886 hw->queues = 4;
887 hw->sta_data_size = sizeof(struct ath_node);
888 hw->vif_data_size = sizeof(struct ath_vap);
957 889
958 /* Register rate control */ 890 /* Register rate control */
959 hw->rate_control_algorithm = "ath9k_rate_control"; 891 hw->rate_control_algorithm = "ath9k_rate_control";
@@ -966,6 +898,17 @@ static int ath_attach(u16 devid,
966 goto bad; 898 goto bad;
967 } 899 }
968 900
901 if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_HT) {
902 setup_ht_cap(&sc->sbands[IEEE80211_BAND_2GHZ].ht_cap);
903 if (test_bit(ATH9K_MODE_11A, sc->sc_ah->ah_caps.wireless_modes))
904 setup_ht_cap(&sc->sbands[IEEE80211_BAND_5GHZ].ht_cap);
905 }
906
907 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &sc->sbands[IEEE80211_BAND_2GHZ];
908 if (test_bit(ATH9K_MODE_11A, sc->sc_ah->ah_caps.wireless_modes))
909 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
910 &sc->sbands[IEEE80211_BAND_5GHZ];
911
969 error = ieee80211_register_hw(hw); 912 error = ieee80211_register_hw(hw);
970 if (error != 0) { 913 if (error != 0) {
971 ath_rate_control_unregister(); 914 ath_rate_control_unregister();
@@ -1011,62 +954,44 @@ static int ath9k_start(struct ieee80211_hw *hw)
1011 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Starting driver with " 954 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Starting driver with "
1012 "initial channel: %d MHz\n", __func__, curchan->center_freq); 955 "initial channel: %d MHz\n", __func__, curchan->center_freq);
1013 956
957 memset(&sc->sc_ht_info, 0, sizeof(struct ath_ht_info));
958
1014 /* setup initial channel */ 959 /* setup initial channel */
1015 960
1016 pos = ath_get_channel(sc, curchan); 961 pos = ath_get_channel(sc, curchan);
1017 if (pos == -1) { 962 if (pos == -1) {
1018 DPRINTF(sc, ATH_DBG_FATAL, "%s: Invalid channel\n", __func__); 963 DPRINTF(sc, ATH_DBG_FATAL, "%s: Invalid channel\n", __func__);
1019 return -EINVAL; 964 error = -EINVAL;
965 goto exit;
1020 } 966 }
1021 967
1022 sc->sc_ah->ah_channels[pos].chanmode = 968 sc->sc_ah->ah_channels[pos].chanmode =
1023 (curchan->band == IEEE80211_BAND_2GHZ) ? CHANNEL_G : CHANNEL_A; 969 (curchan->band == IEEE80211_BAND_2GHZ) ? CHANNEL_G : CHANNEL_A;
1024 970
1025 /* open ath_dev */
1026 error = ath_open(sc, &sc->sc_ah->ah_channels[pos]); 971 error = ath_open(sc, &sc->sc_ah->ah_channels[pos]);
1027 if (error) { 972 if (error) {
1028 DPRINTF(sc, ATH_DBG_FATAL, 973 DPRINTF(sc, ATH_DBG_FATAL,
1029 "%s: Unable to complete ath_open\n", __func__); 974 "%s: Unable to complete ath_open\n", __func__);
1030 return error; 975 goto exit;
1031 } 976 }
1032 977
1033#ifdef CONFIG_RFKILL 978#ifdef CONFIG_RFKILL
1034 /* Start rfkill polling */ 979 error = ath_start_rfkill_poll(sc);
1035 if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
1036 queue_delayed_work(sc->hw->workqueue,
1037 &sc->rf_kill.rfkill_poll, 0);
1038
1039 if (!(sc->sc_flags & SC_OP_RFKILL_REGISTERED)) {
1040 if (rfkill_register(sc->rf_kill.rfkill)) {
1041 DPRINTF(sc, ATH_DBG_FATAL,
1042 "Unable to register rfkill\n");
1043 rfkill_free(sc->rf_kill.rfkill);
1044
1045 /* Deinitialize the device */
1046 if (sc->pdev->irq)
1047 free_irq(sc->pdev->irq, sc);
1048 ath_detach(sc);
1049 pci_iounmap(sc->pdev, sc->mem);
1050 pci_release_region(sc->pdev, 0);
1051 pci_disable_device(sc->pdev);
1052 ieee80211_free_hw(hw);
1053 return -EIO;
1054 } else {
1055 sc->sc_flags |= SC_OP_RFKILL_REGISTERED;
1056 }
1057 }
1058#endif 980#endif
1059 981
1060 ieee80211_wake_queues(hw); 982exit:
1061 return 0; 983 return error;
1062} 984}
1063 985
1064static int ath9k_tx(struct ieee80211_hw *hw, 986static int ath9k_tx(struct ieee80211_hw *hw,
1065 struct sk_buff *skb) 987 struct sk_buff *skb)
1066{ 988{
989 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1067 struct ath_softc *sc = hw->priv; 990 struct ath_softc *sc = hw->priv;
991 struct ath_tx_control txctl;
1068 int hdrlen, padsize; 992 int hdrlen, padsize;
1069 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 993
994 memset(&txctl, 0, sizeof(struct ath_tx_control));
1070 995
1071 /* 996 /*
1072 * As a temporary workaround, assign seq# here; this will likely need 997 * As a temporary workaround, assign seq# here; this will likely need
@@ -1091,45 +1016,47 @@ static int ath9k_tx(struct ieee80211_hw *hw,
1091 memmove(skb->data, skb->data + padsize, hdrlen); 1016 memmove(skb->data, skb->data + padsize, hdrlen);
1092 } 1017 }
1093 1018
1019 /* Check if a tx queue is available */
1020
1021 txctl.txq = ath_test_get_txq(sc, skb);
1022 if (!txctl.txq)
1023 goto exit;
1024
1094 DPRINTF(sc, ATH_DBG_XMIT, "%s: transmitting packet, skb: %p\n", 1025 DPRINTF(sc, ATH_DBG_XMIT, "%s: transmitting packet, skb: %p\n",
1095 __func__, 1026 __func__,
1096 skb); 1027 skb);
1097 1028
1098 if (ath_tx_start(sc, skb) != 0) { 1029 if (ath_tx_start(sc, skb, &txctl) != 0) {
1099 DPRINTF(sc, ATH_DBG_XMIT, "%s: TX failed\n", __func__); 1030 DPRINTF(sc, ATH_DBG_XMIT, "%s: TX failed\n", __func__);
1100 dev_kfree_skb_any(skb); 1031 goto exit;
1101 /* FIXME: Check for proper return value from ATH_DEV */
1102 return 0;
1103 } 1032 }
1104 1033
1105 return 0; 1034 return 0;
1035exit:
1036 dev_kfree_skb_any(skb);
1037 return 0;
1106} 1038}
1107 1039
1108static void ath9k_stop(struct ieee80211_hw *hw) 1040static void ath9k_stop(struct ieee80211_hw *hw)
1109{ 1041{
1110 struct ath_softc *sc = hw->priv; 1042 struct ath_softc *sc = hw->priv;
1111 int error;
1112 1043
1113 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Driver halt\n", __func__); 1044 if (sc->sc_flags & SC_OP_INVALID) {
1114 1045 DPRINTF(sc, ATH_DBG_ANY, "%s: Device not present\n", __func__);
1115 error = ath_suspend(sc); 1046 return;
1116 if (error) 1047 }
1117 DPRINTF(sc, ATH_DBG_CONFIG,
1118 "%s: Device is no longer present\n", __func__);
1119 1048
1120 ieee80211_stop_queues(hw); 1049 ath_stop(sc);
1121 1050
1122#ifdef CONFIG_RFKILL 1051 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Driver halt\n", __func__);
1123 if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
1124 cancel_delayed_work_sync(&sc->rf_kill.rfkill_poll);
1125#endif
1126} 1052}
1127 1053
1128static int ath9k_add_interface(struct ieee80211_hw *hw, 1054static int ath9k_add_interface(struct ieee80211_hw *hw,
1129 struct ieee80211_if_init_conf *conf) 1055 struct ieee80211_if_init_conf *conf)
1130{ 1056{
1131 struct ath_softc *sc = hw->priv; 1057 struct ath_softc *sc = hw->priv;
1132 int error, ic_opmode = 0; 1058 struct ath_vap *avp = (void *)conf->vif->drv_priv;
1059 int ic_opmode = 0;
1133 1060
1134 /* Support only vap for now */ 1061 /* Support only vap for now */
1135 1062
@@ -1157,13 +1084,22 @@ static int ath9k_add_interface(struct ieee80211_hw *hw,
1157 __func__, 1084 __func__,
1158 ic_opmode); 1085 ic_opmode);
1159 1086
1160 error = ath_vap_attach(sc, 0, conf->vif, ic_opmode); 1087 /* Set the VAP opmode */
1161 if (error) { 1088 avp->av_opmode = ic_opmode;
1162 DPRINTF(sc, ATH_DBG_FATAL, 1089 avp->av_bslot = -1;
1163 "%s: Unable to attach vap, error: %d\n", 1090
1164 __func__, error); 1091 if (ic_opmode == ATH9K_M_HOSTAP)
1165 return error; 1092 ath9k_hw_set_tsfadjust(sc->sc_ah, 1);
1166 } 1093
1094 sc->sc_vaps[0] = conf->vif;
1095 sc->sc_nvaps++;
1096
1097 /* Set the device opmode */
1098 sc->sc_ah->ah_opmode = ic_opmode;
1099
1100 /* default VAP configuration */
1101 avp->av_config.av_fixed_rateset = IEEE80211_FIXED_RATE_NONE;
1102 avp->av_config.av_fixed_retryset = 0x03030303;
1167 1103
1168 if (conf->type == NL80211_IFTYPE_AP) { 1104 if (conf->type == NL80211_IFTYPE_AP) {
1169 /* TODO: is this a suitable place to start ANI for AP mode? */ 1105 /* TODO: is this a suitable place to start ANI for AP mode? */
@@ -1179,27 +1115,16 @@ static void ath9k_remove_interface(struct ieee80211_hw *hw,
1179 struct ieee80211_if_init_conf *conf) 1115 struct ieee80211_if_init_conf *conf)
1180{ 1116{
1181 struct ath_softc *sc = hw->priv; 1117 struct ath_softc *sc = hw->priv;
1182 struct ath_vap *avp; 1118 struct ath_vap *avp = (void *)conf->vif->drv_priv;
1183 int error;
1184 1119
1185 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Detach VAP\n", __func__); 1120 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Detach VAP\n", __func__);
1186 1121
1187 avp = sc->sc_vaps[0];
1188 if (avp == NULL) {
1189 DPRINTF(sc, ATH_DBG_FATAL, "%s: Invalid interface\n",
1190 __func__);
1191 return;
1192 }
1193
1194#ifdef CONFIG_SLOW_ANT_DIV 1122#ifdef CONFIG_SLOW_ANT_DIV
1195 ath_slow_ant_div_stop(&sc->sc_antdiv); 1123 ath_slow_ant_div_stop(&sc->sc_antdiv);
1196#endif 1124#endif
1197 /* Stop ANI */ 1125 /* Stop ANI */
1198 del_timer_sync(&sc->sc_ani.timer); 1126 del_timer_sync(&sc->sc_ani.timer);
1199 1127
1200 /* Update ratectrl */
1201 ath_rate_newstate(sc, avp);
1202
1203 /* Reclaim beacon resources */ 1128 /* Reclaim beacon resources */
1204 if (sc->sc_ah->ah_opmode == ATH9K_M_HOSTAP || 1129 if (sc->sc_ah->ah_opmode == ATH9K_M_HOSTAP ||
1205 sc->sc_ah->ah_opmode == ATH9K_M_IBSS) { 1130 sc->sc_ah->ah_opmode == ATH9K_M_IBSS) {
@@ -1207,16 +1132,10 @@ static void ath9k_remove_interface(struct ieee80211_hw *hw,
1207 ath_beacon_return(sc, avp); 1132 ath_beacon_return(sc, avp);
1208 } 1133 }
1209 1134
1210 /* Set interrupt mask */
1211 sc->sc_imask &= ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS);
1212 ath9k_hw_set_interrupts(sc->sc_ah, sc->sc_imask & ~ATH9K_INT_GLOBAL);
1213 sc->sc_flags &= ~SC_OP_BEACONS; 1135 sc->sc_flags &= ~SC_OP_BEACONS;
1214 1136
1215 error = ath_vap_detach(sc, 0); 1137 sc->sc_vaps[0] = NULL;
1216 if (error) 1138 sc->sc_nvaps--;
1217 DPRINTF(sc, ATH_DBG_FATAL,
1218 "%s: Unable to detach vap, error: %d\n",
1219 __func__, error);
1220} 1139}
1221 1140
1222static int ath9k_config(struct ieee80211_hw *hw, u32 changed) 1141static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
@@ -1264,17 +1183,10 @@ static int ath9k_config_interface(struct ieee80211_hw *hw,
1264{ 1183{
1265 struct ath_softc *sc = hw->priv; 1184 struct ath_softc *sc = hw->priv;
1266 struct ath_hal *ah = sc->sc_ah; 1185 struct ath_hal *ah = sc->sc_ah;
1267 struct ath_vap *avp; 1186 struct ath_vap *avp = (void *)vif->drv_priv;
1268 u32 rfilt = 0; 1187 u32 rfilt = 0;
1269 int error, i; 1188 int error, i;
1270 1189
1271 avp = sc->sc_vaps[0];
1272 if (avp == NULL) {
1273 DPRINTF(sc, ATH_DBG_FATAL, "%s: Invalid interface\n",
1274 __func__);
1275 return -EINVAL;
1276 }
1277
1278 /* TODO: Need to decide which hw opmode to use for multi-interface 1190 /* TODO: Need to decide which hw opmode to use for multi-interface
1279 * cases */ 1191 * cases */
1280 if (vif->type == NL80211_IFTYPE_AP && 1192 if (vif->type == NL80211_IFTYPE_AP &&
@@ -1303,23 +1215,6 @@ static int ath9k_config_interface(struct ieee80211_hw *hw,
1303 /* Set aggregation protection mode parameters */ 1215 /* Set aggregation protection mode parameters */
1304 sc->sc_config.ath_aggr_prot = 0; 1216 sc->sc_config.ath_aggr_prot = 0;
1305 1217
1306 /*
1307 * Reset our TSF so that its value is lower than the
1308 * beacon that we are trying to catch.
1309 * Only then hw will update its TSF register with the
1310 * new beacon. Reset the TSF before setting the BSSID
1311 * to avoid allowing in any frames that would update
1312 * our TSF only to have us clear it
1313 * immediately thereafter.
1314 */
1315 ath9k_hw_reset_tsf(sc->sc_ah);
1316
1317 /* Disable BMISS interrupt when we're not associated */
1318 ath9k_hw_set_interrupts(sc->sc_ah,
1319 sc->sc_imask &
1320 ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS));
1321 sc->sc_imask &= ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS);
1322
1323 DPRINTF(sc, ATH_DBG_CONFIG, 1218 DPRINTF(sc, ATH_DBG_CONFIG,
1324 "%s: RX filter 0x%x bssid %pM aid 0x%x\n", 1219 "%s: RX filter 0x%x bssid %pM aid 0x%x\n",
1325 __func__, rfilt, 1220 __func__, rfilt,
@@ -1355,7 +1250,7 @@ static int ath9k_config_interface(struct ieee80211_hw *hw,
1355 } 1250 }
1356 1251
1357 /* Check for WLAN_CAPABILITY_PRIVACY ? */ 1252 /* Check for WLAN_CAPABILITY_PRIVACY ? */
1358 if ((avp->av_opmode != NL80211_IFTYPE_STATION)) { 1253 if ((avp->av_opmode != ATH9K_M_STA)) {
1359 for (i = 0; i < IEEE80211_WEP_NKID; i++) 1254 for (i = 0; i < IEEE80211_WEP_NKID; i++)
1360 if (ath9k_hw_keyisvalid(sc->sc_ah, (u16)i)) 1255 if (ath9k_hw_keyisvalid(sc->sc_ah, (u16)i))
1361 ath9k_hw_keysetmac(sc->sc_ah, 1256 ath9k_hw_keysetmac(sc->sc_ah,
@@ -1410,44 +1305,13 @@ static void ath9k_sta_notify(struct ieee80211_hw *hw,
1410 struct ieee80211_sta *sta) 1305 struct ieee80211_sta *sta)
1411{ 1306{
1412 struct ath_softc *sc = hw->priv; 1307 struct ath_softc *sc = hw->priv;
1413 struct ath_node *an;
1414 unsigned long flags;
1415
1416 spin_lock_irqsave(&sc->node_lock, flags);
1417 an = ath_node_find(sc, sta->addr);
1418 spin_unlock_irqrestore(&sc->node_lock, flags);
1419 1308
1420 switch (cmd) { 1309 switch (cmd) {
1421 case STA_NOTIFY_ADD: 1310 case STA_NOTIFY_ADD:
1422 spin_lock_irqsave(&sc->node_lock, flags); 1311 ath_node_attach(sc, sta);
1423 if (!an) {
1424 ath_node_attach(sc, sta->addr, 0);
1425 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Attach a node: %pM\n",
1426 __func__, sta->addr);
1427 } else {
1428 ath_node_get(sc, sta->addr);
1429 }
1430
1431 /* XXX: Is this right? Can the capabilities change? */
1432 an = ath_node_find(sc, sta->addr);
1433 an->maxampdu = 1 << (IEEE80211_HTCAP_MAXRXAMPDU_FACTOR +
1434 sta->ht_cap.ampdu_factor);
1435 an->mpdudensity =
1436 parse_mpdudensity(sta->ht_cap.ampdu_density);
1437
1438 spin_unlock_irqrestore(&sc->node_lock, flags);
1439 break; 1312 break;
1440 case STA_NOTIFY_REMOVE: 1313 case STA_NOTIFY_REMOVE:
1441 if (!an) 1314 ath_node_detach(sc, sta);
1442 DPRINTF(sc, ATH_DBG_FATAL,
1443 "%s: Removal of a non-existent node\n",
1444 __func__);
1445 else {
1446 ath_node_put(sc, an, ATH9K_BH_STATUS_INTACT);
1447 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Put a node: %pM\n",
1448 __func__,
1449 sta->addr);
1450 }
1451 break; 1315 break;
1452 default: 1316 default:
1453 break; 1317 break;
@@ -1562,7 +1426,7 @@ static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
1562 DPRINTF(sc, ATH_DBG_CONFIG, "%s: BSS Changed ASSOC %d\n", 1426 DPRINTF(sc, ATH_DBG_CONFIG, "%s: BSS Changed ASSOC %d\n",
1563 __func__, 1427 __func__,
1564 bss_conf->assoc); 1428 bss_conf->assoc);
1565 ath9k_bss_assoc_info(sc, bss_conf); 1429 ath9k_bss_assoc_info(sc, vif, bss_conf);
1566 } 1430 }
1567} 1431}
1568 1432
@@ -1595,21 +1459,13 @@ static int ath9k_ampdu_action(struct ieee80211_hw *hw,
1595 1459
1596 switch (action) { 1460 switch (action) {
1597 case IEEE80211_AMPDU_RX_START: 1461 case IEEE80211_AMPDU_RX_START:
1598 ret = ath_rx_aggr_start(sc, sta->addr, tid, ssn); 1462 if (!(sc->sc_flags & SC_OP_RXAGGR))
1599 if (ret < 0) 1463 ret = -ENOTSUPP;
1600 DPRINTF(sc, ATH_DBG_FATAL,
1601 "%s: Unable to start RX aggregation\n",
1602 __func__);
1603 break; 1464 break;
1604 case IEEE80211_AMPDU_RX_STOP: 1465 case IEEE80211_AMPDU_RX_STOP:
1605 ret = ath_rx_aggr_stop(sc, sta->addr, tid);
1606 if (ret < 0)
1607 DPRINTF(sc, ATH_DBG_FATAL,
1608 "%s: Unable to stop RX aggregation\n",
1609 __func__);
1610 break; 1466 break;
1611 case IEEE80211_AMPDU_TX_START: 1467 case IEEE80211_AMPDU_TX_START:
1612 ret = ath_tx_aggr_start(sc, sta->addr, tid, ssn); 1468 ret = ath_tx_aggr_start(sc, sta, tid, ssn);
1613 if (ret < 0) 1469 if (ret < 0)
1614 DPRINTF(sc, ATH_DBG_FATAL, 1470 DPRINTF(sc, ATH_DBG_FATAL,
1615 "%s: Unable to start TX aggregation\n", 1471 "%s: Unable to start TX aggregation\n",
@@ -1618,7 +1474,7 @@ static int ath9k_ampdu_action(struct ieee80211_hw *hw,
1618 ieee80211_start_tx_ba_cb_irqsafe(hw, sta->addr, tid); 1474 ieee80211_start_tx_ba_cb_irqsafe(hw, sta->addr, tid);
1619 break; 1475 break;
1620 case IEEE80211_AMPDU_TX_STOP: 1476 case IEEE80211_AMPDU_TX_STOP:
1621 ret = ath_tx_aggr_stop(sc, sta->addr, tid); 1477 ret = ath_tx_aggr_stop(sc, sta, tid);
1622 if (ret < 0) 1478 if (ret < 0)
1623 DPRINTF(sc, ATH_DBG_FATAL, 1479 DPRINTF(sc, ATH_DBG_FATAL,
1624 "%s: Unable to stop TX aggregation\n", 1480 "%s: Unable to stop TX aggregation\n",
@@ -1626,6 +1482,9 @@ static int ath9k_ampdu_action(struct ieee80211_hw *hw,
1626 1482
1627 ieee80211_stop_tx_ba_cb_irqsafe(hw, sta->addr, tid); 1483 ieee80211_stop_tx_ba_cb_irqsafe(hw, sta->addr, tid);
1628 break; 1484 break;
1485 case IEEE80211_AMPDU_TX_RESUME:
1486 ath_tx_aggr_resume(sc, sta, tid);
1487 break;
1629 default: 1488 default:
1630 DPRINTF(sc, ATH_DBG_FATAL, 1489 DPRINTF(sc, ATH_DBG_FATAL,
1631 "%s: Unknown AMPDU action\n", __func__); 1490 "%s: Unknown AMPDU action\n", __func__);
@@ -1648,20 +1507,12 @@ static struct ieee80211_ops ath9k_ops = {
1648 .config = ath9k_config, 1507 .config = ath9k_config,
1649 .config_interface = ath9k_config_interface, 1508 .config_interface = ath9k_config_interface,
1650 .configure_filter = ath9k_configure_filter, 1509 .configure_filter = ath9k_configure_filter,
1651 .get_stats = NULL,
1652 .sta_notify = ath9k_sta_notify, 1510 .sta_notify = ath9k_sta_notify,
1653 .conf_tx = ath9k_conf_tx, 1511 .conf_tx = ath9k_conf_tx,
1654 .get_tx_stats = NULL,
1655 .bss_info_changed = ath9k_bss_info_changed, 1512 .bss_info_changed = ath9k_bss_info_changed,
1656 .set_tim = NULL,
1657 .set_key = ath9k_set_key, 1513 .set_key = ath9k_set_key,
1658 .hw_scan = NULL,
1659 .get_tkip_seq = NULL,
1660 .set_rts_threshold = NULL,
1661 .set_frag_threshold = NULL,
1662 .get_tsf = ath9k_get_tsf, 1514 .get_tsf = ath9k_get_tsf,
1663 .reset_tsf = ath9k_reset_tsf, 1515 .reset_tsf = ath9k_reset_tsf,
1664 .tx_last_beacon = NULL,
1665 .ampdu_action = ath9k_ampdu_action, 1516 .ampdu_action = ath9k_ampdu_action,
1666 .set_frag_threshold = ath9k_no_fragmentation, 1517 .set_frag_threshold = ath9k_no_fragmentation,
1667}; 1518};
@@ -1739,17 +1590,6 @@ static int ath_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1739 goto bad2; 1590 goto bad2;
1740 } 1591 }
1741 1592
1742 hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
1743 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
1744 IEEE80211_HW_SIGNAL_DBM |
1745 IEEE80211_HW_NOISE_DBM |
1746 IEEE80211_HW_AMPDU_AGGREGATION;
1747
1748 hw->wiphy->interface_modes =
1749 BIT(NL80211_IFTYPE_AP) |
1750 BIT(NL80211_IFTYPE_STATION) |
1751 BIT(NL80211_IFTYPE_ADHOC);
1752
1753 SET_IEEE80211_DEV(hw, &pdev->dev); 1593 SET_IEEE80211_DEV(hw, &pdev->dev);
1754 pci_set_drvdata(pdev, hw); 1594 pci_set_drvdata(pdev, hw);
1755 1595
@@ -1797,17 +1637,10 @@ static void ath_pci_remove(struct pci_dev *pdev)
1797{ 1637{
1798 struct ieee80211_hw *hw = pci_get_drvdata(pdev); 1638 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
1799 struct ath_softc *sc = hw->priv; 1639 struct ath_softc *sc = hw->priv;
1800 enum ath9k_int status;
1801 1640
1802 if (pdev->irq) {
1803 ath9k_hw_set_interrupts(sc->sc_ah, 0);
1804 /* clear the ISR */
1805 ath9k_hw_getisr(sc->sc_ah, &status);
1806 sc->sc_flags |= SC_OP_INVALID;
1807 free_irq(pdev->irq, sc);
1808 }
1809 ath_detach(sc); 1641 ath_detach(sc);
1810 1642 if (pdev->irq)
1643 free_irq(pdev->irq, sc);
1811 pci_iounmap(pdev, sc->mem); 1644 pci_iounmap(pdev, sc->mem);
1812 pci_release_region(pdev, 0); 1645 pci_release_region(pdev, 0);
1813 pci_disable_device(pdev); 1646 pci_disable_device(pdev);
diff --git a/drivers/net/wireless/ath9k/phy.c b/drivers/net/wireless/ath9k/phy.c
index eb9121fdfd38..4f1c8bf8342b 100644
--- a/drivers/net/wireless/ath9k/phy.c
+++ b/drivers/net/wireless/ath9k/phy.c
@@ -215,7 +215,7 @@ ath9k_hw_set_rf_regs(struct ath_hal *ah, struct ath9k_channel *chan,
215 if (AR_SREV_9280_10_OR_LATER(ah)) 215 if (AR_SREV_9280_10_OR_LATER(ah))
216 return true; 216 return true;
217 217
218 eepMinorRev = ath9k_hw_get_eeprom(ahp, EEP_MINOR_REV); 218 eepMinorRev = ath9k_hw_get_eeprom(ah, EEP_MINOR_REV);
219 219
220 RF_BANK_SETUP(ahp->ah_analogBank0Data, &ahp->ah_iniBank0, 1); 220 RF_BANK_SETUP(ahp->ah_analogBank0Data, &ahp->ah_iniBank0, 1);
221 221
@@ -235,15 +235,15 @@ ath9k_hw_set_rf_regs(struct ath_hal *ah, struct ath9k_channel *chan,
235 235
236 if (eepMinorRev >= 2) { 236 if (eepMinorRev >= 2) {
237 if (IS_CHAN_2GHZ(chan)) { 237 if (IS_CHAN_2GHZ(chan)) {
238 ob2GHz = ath9k_hw_get_eeprom(ahp, EEP_OB_2); 238 ob2GHz = ath9k_hw_get_eeprom(ah, EEP_OB_2);
239 db2GHz = ath9k_hw_get_eeprom(ahp, EEP_DB_2); 239 db2GHz = ath9k_hw_get_eeprom(ah, EEP_DB_2);
240 ath9k_phy_modify_rx_buffer(ahp->ah_analogBank6Data, 240 ath9k_phy_modify_rx_buffer(ahp->ah_analogBank6Data,
241 ob2GHz, 3, 197, 0); 241 ob2GHz, 3, 197, 0);
242 ath9k_phy_modify_rx_buffer(ahp->ah_analogBank6Data, 242 ath9k_phy_modify_rx_buffer(ahp->ah_analogBank6Data,
243 db2GHz, 3, 194, 0); 243 db2GHz, 3, 194, 0);
244 } else { 244 } else {
245 ob5GHz = ath9k_hw_get_eeprom(ahp, EEP_OB_5); 245 ob5GHz = ath9k_hw_get_eeprom(ah, EEP_OB_5);
246 db5GHz = ath9k_hw_get_eeprom(ahp, EEP_DB_5); 246 db5GHz = ath9k_hw_get_eeprom(ah, EEP_DB_5);
247 ath9k_phy_modify_rx_buffer(ahp->ah_analogBank6Data, 247 ath9k_phy_modify_rx_buffer(ahp->ah_analogBank6Data,
248 ob5GHz, 3, 203, 0); 248 ob5GHz, 3, 203, 0);
249 ath9k_phy_modify_rx_buffer(ahp->ah_analogBank6Data, 249 ath9k_phy_modify_rx_buffer(ahp->ah_analogBank6Data,
diff --git a/drivers/net/wireless/ath9k/rc.c b/drivers/net/wireless/ath9k/rc.c
index ecffd6f45fd0..aa6bfd717c20 100644
--- a/drivers/net/wireless/ath9k/rc.c
+++ b/drivers/net/wireless/ath9k/rc.c
@@ -816,7 +816,7 @@ void ath_rate_detach(struct ath_rate_softc *asc)
816} 816}
817 817
818u8 ath_rate_findrateix(struct ath_softc *sc, 818u8 ath_rate_findrateix(struct ath_softc *sc,
819 u8 dot11rate) 819 u8 dot11rate)
820{ 820{
821 const struct ath_rate_table *ratetable; 821 const struct ath_rate_table *ratetable;
822 struct ath_rate_softc *rsc = sc->sc_rc; 822 struct ath_rate_softc *rsc = sc->sc_rc;
@@ -1867,9 +1867,7 @@ static void ath_tx_status(void *priv, struct ieee80211_supported_band *sband,
1867 /* XXX: UGLY HACK!! */ 1867 /* XXX: UGLY HACK!! */
1868 tx_info_priv = (struct ath_tx_info_priv *)tx_info->control.vif; 1868 tx_info_priv = (struct ath_tx_info_priv *)tx_info->control.vif;
1869 1869
1870 spin_lock_bh(&sc->node_lock); 1870 an = (struct ath_node *)sta->drv_priv;
1871 an = ath_node_find(sc, hdr->addr1);
1872 spin_unlock_bh(&sc->node_lock);
1873 1871
1874 if (tx_info_priv == NULL) 1872 if (tx_info_priv == NULL)
1875 return; 1873 return;
@@ -1881,49 +1879,6 @@ static void ath_tx_status(void *priv, struct ieee80211_supported_band *sband,
1881 tx_info->control.vif = NULL; 1879 tx_info->control.vif = NULL;
1882} 1880}
1883 1881
1884static void ath_tx_aggr_resp(struct ath_softc *sc,
1885 struct ieee80211_supported_band *sband,
1886 struct ieee80211_sta *sta,
1887 struct ath_node *an,
1888 u8 tidno)
1889{
1890 struct ath_atx_tid *txtid;
1891 u16 buffersize = 0;
1892 int state;
1893 struct sta_info *si;
1894
1895 if (!(sc->sc_flags & SC_OP_TXAGGR))
1896 return;
1897
1898 txtid = ATH_AN_2_TID(an, tidno);
1899 if (!txtid->paused)
1900 return;
1901
1902 /*
1903 * XXX: This is entirely busted, we aren't supposed to
1904 * access the sta from here because it's internal
1905 * to mac80211, and looking at the state without
1906 * locking is wrong too.
1907 */
1908 si = container_of(sta, struct sta_info, sta);
1909 buffersize = IEEE80211_MIN_AMPDU_BUF <<
1910 sband->ht_cap.ampdu_factor; /* FIXME */
1911 state = si->ampdu_mlme.tid_state_tx[tidno];
1912
1913 if (state & HT_ADDBA_RECEIVED_MSK) {
1914 txtid->addba_exchangecomplete = 1;
1915 txtid->addba_exchangeinprogress = 0;
1916 txtid->baw_size = buffersize;
1917
1918 DPRINTF(sc, ATH_DBG_AGGR,
1919 "%s: Resuming tid, buffersize: %d\n",
1920 __func__,
1921 buffersize);
1922
1923 ath_tx_resume_tid(sc, txtid);
1924 }
1925}
1926
1927static void ath_get_rate(void *priv, struct ieee80211_sta *sta, void *priv_sta, 1882static void ath_get_rate(void *priv, struct ieee80211_sta *sta, void *priv_sta,
1928 struct ieee80211_tx_rate_control *txrc) 1883 struct ieee80211_tx_rate_control *txrc)
1929{ 1884{
@@ -1936,7 +1891,7 @@ static void ath_get_rate(void *priv, struct ieee80211_sta *sta, void *priv_sta,
1936 struct ath_rate_node *ath_rc_priv = priv_sta; 1891 struct ath_rate_node *ath_rc_priv = priv_sta;
1937 struct ath_node *an; 1892 struct ath_node *an;
1938 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); 1893 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
1939 int is_probe = FALSE, chk, ret; 1894 int is_probe = FALSE;
1940 s8 lowest_idx; 1895 s8 lowest_idx;
1941 __le16 fc = hdr->frame_control; 1896 __le16 fc = hdr->frame_control;
1942 u8 *qc, tid; 1897 u8 *qc, tid;
@@ -1983,35 +1938,10 @@ static void ath_get_rate(void *priv, struct ieee80211_sta *sta, void *priv_sta,
1983 if (ieee80211_is_data_qos(fc)) { 1938 if (ieee80211_is_data_qos(fc)) {
1984 qc = ieee80211_get_qos_ctl(hdr); 1939 qc = ieee80211_get_qos_ctl(hdr);
1985 tid = qc[0] & 0xf; 1940 tid = qc[0] & 0xf;
1941 an = (struct ath_node *)sta->drv_priv;
1986 1942
1987 spin_lock_bh(&sc->node_lock); 1943 if(ath_tx_aggr_check(sc, an, tid))
1988 an = ath_node_find(sc, hdr->addr1); 1944 ieee80211_start_tx_ba_session(hw, hdr->addr1, tid);
1989 spin_unlock_bh(&sc->node_lock);
1990
1991 if (!an) {
1992 DPRINTF(sc, ATH_DBG_AGGR,
1993 "%s: Node not found to "
1994 "init/chk TX aggr\n", __func__);
1995 return;
1996 }
1997
1998 chk = ath_tx_aggr_check(sc, an, tid);
1999 if (chk == AGGR_REQUIRED) {
2000 ret = ieee80211_start_tx_ba_session(hw,
2001 hdr->addr1, tid);
2002 if (ret)
2003 DPRINTF(sc, ATH_DBG_AGGR,
2004 "%s: Unable to start tx "
2005 "aggr for: %pM\n",
2006 __func__,
2007 hdr->addr1);
2008 else
2009 DPRINTF(sc, ATH_DBG_AGGR,
2010 "%s: Started tx aggr for: %pM\n",
2011 __func__,
2012 hdr->addr1);
2013 } else if (chk == AGGR_EXCHANGE_PROGRESS)
2014 ath_tx_aggr_resp(sc, sband, sta, an, tid);
2015 } 1945 }
2016 } 1946 }
2017} 1947}
@@ -2053,12 +1983,18 @@ static void ath_rate_free(void *priv)
2053 1983
2054static void *ath_rate_alloc_sta(void *priv, struct ieee80211_sta *sta, gfp_t gfp) 1984static void *ath_rate_alloc_sta(void *priv, struct ieee80211_sta *sta, gfp_t gfp)
2055{ 1985{
1986 struct ieee80211_vif *vif;
2056 struct ath_softc *sc = priv; 1987 struct ath_softc *sc = priv;
2057 struct ath_vap *avp = sc->sc_vaps[0]; 1988 struct ath_vap *avp;
2058 struct ath_rate_node *rate_priv; 1989 struct ath_rate_node *rate_priv;
2059 1990
2060 DPRINTF(sc, ATH_DBG_RATE, "%s\n", __func__); 1991 DPRINTF(sc, ATH_DBG_RATE, "%s\n", __func__);
2061 1992
1993 vif = sc->sc_vaps[0];
1994 ASSERT(vif);
1995
1996 avp = (void *)vif->drv_priv;
1997
2062 rate_priv = ath_rate_node_alloc(avp, sc->sc_rc, gfp); 1998 rate_priv = ath_rate_node_alloc(avp, sc->sc_rc, gfp);
2063 if (!rate_priv) { 1999 if (!rate_priv) {
2064 DPRINTF(sc, ATH_DBG_FATAL, 2000 DPRINTF(sc, ATH_DBG_FATAL,
diff --git a/drivers/net/wireless/ath9k/recv.c b/drivers/net/wireless/ath9k/recv.c
index 828322840a86..2ecb0a010ce2 100644
--- a/drivers/net/wireless/ath9k/recv.c
+++ b/drivers/net/wireless/ath9k/recv.c
@@ -64,328 +64,6 @@ static void ath_rx_buf_link(struct ath_softc *sc, struct ath_buf *bf)
64 ath9k_hw_rxena(ah); 64 ath9k_hw_rxena(ah);
65} 65}
66 66
67/* Process received BAR frame */
68
69static int ath_bar_rx(struct ath_softc *sc,
70 struct ath_node *an,
71 struct sk_buff *skb)
72{
73 struct ieee80211_bar *bar;
74 struct ath_arx_tid *rxtid;
75 struct sk_buff *tskb;
76 struct ath_recv_status *rx_status;
77 int tidno, index, cindex;
78 u16 seqno;
79
80 /* look at BAR contents */
81
82 bar = (struct ieee80211_bar *)skb->data;
83 tidno = (le16_to_cpu(bar->control) & IEEE80211_BAR_CTL_TID_M)
84 >> IEEE80211_BAR_CTL_TID_S;
85 seqno = le16_to_cpu(bar->start_seq_num) >> IEEE80211_SEQ_SEQ_SHIFT;
86
87 /* process BAR - indicate all pending RX frames till the BAR seqno */
88
89 rxtid = &an->an_aggr.rx.tid[tidno];
90
91 spin_lock_bh(&rxtid->tidlock);
92
93 /* get relative index */
94
95 index = ATH_BA_INDEX(rxtid->seq_next, seqno);
96
97 /* drop BAR if old sequence (index is too large) */
98
99 if ((index > rxtid->baw_size) &&
100 (index > (IEEE80211_SEQ_MAX - (rxtid->baw_size << 2))))
101 /* discard frame, ieee layer may not treat frame as a dup */
102 goto unlock_and_free;
103
104 /* complete receive processing for all pending frames upto BAR seqno */
105
106 cindex = (rxtid->baw_head + index) & (ATH_TID_MAX_BUFS - 1);
107 while ((rxtid->baw_head != rxtid->baw_tail) &&
108 (rxtid->baw_head != cindex)) {
109 tskb = rxtid->rxbuf[rxtid->baw_head].rx_wbuf;
110 rx_status = &rxtid->rxbuf[rxtid->baw_head].rx_status;
111 rxtid->rxbuf[rxtid->baw_head].rx_wbuf = NULL;
112
113 if (tskb != NULL)
114 ath_rx_subframe(an, tskb, rx_status);
115
116 INCR(rxtid->baw_head, ATH_TID_MAX_BUFS);
117 INCR(rxtid->seq_next, IEEE80211_SEQ_MAX);
118 }
119
120 /* ... and indicate rest of the frames in-order */
121
122 while (rxtid->baw_head != rxtid->baw_tail &&
123 rxtid->rxbuf[rxtid->baw_head].rx_wbuf != NULL) {
124 tskb = rxtid->rxbuf[rxtid->baw_head].rx_wbuf;
125 rx_status = &rxtid->rxbuf[rxtid->baw_head].rx_status;
126 rxtid->rxbuf[rxtid->baw_head].rx_wbuf = NULL;
127
128 ath_rx_subframe(an, tskb, rx_status);
129
130 INCR(rxtid->baw_head, ATH_TID_MAX_BUFS);
131 INCR(rxtid->seq_next, IEEE80211_SEQ_MAX);
132 }
133
134unlock_and_free:
135 spin_unlock_bh(&rxtid->tidlock);
136 /* free bar itself */
137 dev_kfree_skb(skb);
138 return IEEE80211_FTYPE_CTL;
139}
140
141/* Function to handle a subframe of aggregation when HT is enabled */
142
143static int ath_ampdu_input(struct ath_softc *sc,
144 struct ath_node *an,
145 struct sk_buff *skb,
146 struct ath_recv_status *rx_status)
147{
148 struct ieee80211_hdr *hdr;
149 struct ath_arx_tid *rxtid;
150 struct ath_rxbuf *rxbuf;
151 u8 type, subtype;
152 u16 rxseq;
153 int tid = 0, index, cindex, rxdiff;
154 __le16 fc;
155 u8 *qc;
156
157 hdr = (struct ieee80211_hdr *)skb->data;
158 fc = hdr->frame_control;
159
160 /* collect stats of frames with non-zero version */
161
162 if ((le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_VERS) != 0) {
163 dev_kfree_skb(skb);
164 return -1;
165 }
166
167 type = le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_FTYPE;
168 subtype = le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_STYPE;
169
170 if (ieee80211_is_back_req(fc))
171 return ath_bar_rx(sc, an, skb);
172
173 /* special aggregate processing only for qos unicast data frames */
174
175 if (!ieee80211_is_data(fc) ||
176 !ieee80211_is_data_qos(fc) ||
177 is_multicast_ether_addr(hdr->addr1))
178 return ath_rx_subframe(an, skb, rx_status);
179
180 /* lookup rx tid state */
181
182 if (ieee80211_is_data_qos(fc)) {
183 qc = ieee80211_get_qos_ctl(hdr);
184 tid = qc[0] & 0xf;
185 }
186
187 if (sc->sc_ah->ah_opmode == ATH9K_M_STA) {
188 /* Drop the frame not belonging to me. */
189 if (memcmp(hdr->addr1, sc->sc_myaddr, ETH_ALEN)) {
190 dev_kfree_skb(skb);
191 return -1;
192 }
193 }
194
195 rxtid = &an->an_aggr.rx.tid[tid];
196
197 spin_lock(&rxtid->tidlock);
198
199 rxdiff = (rxtid->baw_tail - rxtid->baw_head) &
200 (ATH_TID_MAX_BUFS - 1);
201
202 /*
203 * If the ADDBA exchange has not been completed by the source,
204 * process via legacy path (i.e. no reordering buffer is needed)
205 */
206 if (!rxtid->addba_exchangecomplete) {
207 spin_unlock(&rxtid->tidlock);
208 return ath_rx_subframe(an, skb, rx_status);
209 }
210
211 /* extract sequence number from recvd frame */
212
213 rxseq = le16_to_cpu(hdr->seq_ctrl) >> IEEE80211_SEQ_SEQ_SHIFT;
214
215 if (rxtid->seq_reset) {
216 rxtid->seq_reset = 0;
217 rxtid->seq_next = rxseq;
218 }
219
220 index = ATH_BA_INDEX(rxtid->seq_next, rxseq);
221
222 /* drop frame if old sequence (index is too large) */
223
224 if (index > (IEEE80211_SEQ_MAX - (rxtid->baw_size << 2))) {
225 /* discard frame, ieee layer may not treat frame as a dup */
226 spin_unlock(&rxtid->tidlock);
227 dev_kfree_skb(skb);
228 return IEEE80211_FTYPE_DATA;
229 }
230
231 /* sequence number is beyond block-ack window */
232
233 if (index >= rxtid->baw_size) {
234
235 /* complete receive processing for all pending frames */
236
237 while (index >= rxtid->baw_size) {
238
239 rxbuf = rxtid->rxbuf + rxtid->baw_head;
240
241 if (rxbuf->rx_wbuf != NULL) {
242 ath_rx_subframe(an, rxbuf->rx_wbuf,
243 &rxbuf->rx_status);
244 rxbuf->rx_wbuf = NULL;
245 }
246
247 INCR(rxtid->baw_head, ATH_TID_MAX_BUFS);
248 INCR(rxtid->seq_next, IEEE80211_SEQ_MAX);
249
250 index--;
251 }
252 }
253
254 /* add buffer to the recv ba window */
255
256 cindex = (rxtid->baw_head + index) & (ATH_TID_MAX_BUFS - 1);
257 rxbuf = rxtid->rxbuf + cindex;
258
259 if (rxbuf->rx_wbuf != NULL) {
260 spin_unlock(&rxtid->tidlock);
261 /* duplicate frame */
262 dev_kfree_skb(skb);
263 return IEEE80211_FTYPE_DATA;
264 }
265
266 rxbuf->rx_wbuf = skb;
267 rxbuf->rx_time = get_timestamp();
268 rxbuf->rx_status = *rx_status;
269
270 /* advance tail if sequence received is newer
271 * than any received so far */
272
273 if (index >= rxdiff) {
274 rxtid->baw_tail = cindex;
275 INCR(rxtid->baw_tail, ATH_TID_MAX_BUFS);
276 }
277
278 /* indicate all in-order received frames */
279
280 while (rxtid->baw_head != rxtid->baw_tail) {
281 rxbuf = rxtid->rxbuf + rxtid->baw_head;
282 if (!rxbuf->rx_wbuf)
283 break;
284
285 ath_rx_subframe(an, rxbuf->rx_wbuf, &rxbuf->rx_status);
286 rxbuf->rx_wbuf = NULL;
287
288 INCR(rxtid->baw_head, ATH_TID_MAX_BUFS);
289 INCR(rxtid->seq_next, IEEE80211_SEQ_MAX);
290 }
291
292 /*
293 * start a timer to flush all received frames if there are pending
294 * receive frames
295 */
296 if (rxtid->baw_head != rxtid->baw_tail)
297 mod_timer(&rxtid->timer, ATH_RX_TIMEOUT);
298 else
299 del_timer_sync(&rxtid->timer);
300
301 spin_unlock(&rxtid->tidlock);
302 return IEEE80211_FTYPE_DATA;
303}
304
305/* Timer to flush all received sub-frames */
306
307static void ath_rx_timer(unsigned long data)
308{
309 struct ath_arx_tid *rxtid = (struct ath_arx_tid *)data;
310 struct ath_node *an = rxtid->an;
311 struct ath_rxbuf *rxbuf;
312 int nosched;
313
314 spin_lock_bh(&rxtid->tidlock);
315 while (rxtid->baw_head != rxtid->baw_tail) {
316 rxbuf = rxtid->rxbuf + rxtid->baw_head;
317 if (!rxbuf->rx_wbuf) {
318 INCR(rxtid->baw_head, ATH_TID_MAX_BUFS);
319 INCR(rxtid->seq_next, IEEE80211_SEQ_MAX);
320 continue;
321 }
322
323 /*
324 * Stop if the next one is a very recent frame.
325 *
326 * Call get_timestamp in every iteration to protect against the
327 * case in which a new frame is received while we are executing
328 * this function. Using a timestamp obtained before entering
329 * the loop could lead to a very large time interval
330 * (a negative value typecast to unsigned), breaking the
331 * function's logic.
332 */
333 if ((get_timestamp() - rxbuf->rx_time) <
334 (ATH_RX_TIMEOUT * HZ / 1000))
335 break;
336
337 ath_rx_subframe(an, rxbuf->rx_wbuf,
338 &rxbuf->rx_status);
339 rxbuf->rx_wbuf = NULL;
340
341 INCR(rxtid->baw_head, ATH_TID_MAX_BUFS);
342 INCR(rxtid->seq_next, IEEE80211_SEQ_MAX);
343 }
344
345 /*
346 * start a timer to flush all received frames if there are pending
347 * receive frames
348 */
349 if (rxtid->baw_head != rxtid->baw_tail)
350 nosched = 0;
351 else
352 nosched = 1; /* no need to re-arm the timer again */
353
354 spin_unlock_bh(&rxtid->tidlock);
355}
356
357/* Free all pending sub-frames in the re-ordering buffer */
358
359static void ath_rx_flush_tid(struct ath_softc *sc,
360 struct ath_arx_tid *rxtid, int drop)
361{
362 struct ath_rxbuf *rxbuf;
363 unsigned long flag;
364
365 spin_lock_irqsave(&rxtid->tidlock, flag);
366 while (rxtid->baw_head != rxtid->baw_tail) {
367 rxbuf = rxtid->rxbuf + rxtid->baw_head;
368 if (!rxbuf->rx_wbuf) {
369 INCR(rxtid->baw_head, ATH_TID_MAX_BUFS);
370 INCR(rxtid->seq_next, IEEE80211_SEQ_MAX);
371 continue;
372 }
373
374 if (drop)
375 dev_kfree_skb(rxbuf->rx_wbuf);
376 else
377 ath_rx_subframe(rxtid->an,
378 rxbuf->rx_wbuf,
379 &rxbuf->rx_status);
380
381 rxbuf->rx_wbuf = NULL;
382
383 INCR(rxtid->baw_head, ATH_TID_MAX_BUFS);
384 INCR(rxtid->seq_next, IEEE80211_SEQ_MAX);
385 }
386 spin_unlock_irqrestore(&rxtid->tidlock, flag);
387}
388
389static struct sk_buff *ath_rxbuf_alloc(struct ath_softc *sc, 67static struct sk_buff *ath_rxbuf_alloc(struct ath_softc *sc,
390 u32 len) 68 u32 len)
391{ 69{
@@ -716,23 +394,6 @@ void ath_flushrecv(struct ath_softc *sc)
716 spin_unlock_bh(&sc->sc_rxflushlock); 394 spin_unlock_bh(&sc->sc_rxflushlock);
717} 395}
718 396
719/* Process an individual frame */
720
721int ath_rx_input(struct ath_softc *sc,
722 struct ath_node *an,
723 struct sk_buff *skb,
724 struct ath_recv_status *rx_status,
725 enum ATH_RX_TYPE *status)
726{
727 if (sc->sc_flags & SC_OP_RXAGGR) {
728 *status = ATH_RX_CONSUMED;
729 return ath_ampdu_input(sc, an, skb, rx_status);
730 } else {
731 *status = ATH_RX_NON_CONSUMED;
732 return -1;
733 }
734}
735
736/* Process receive queue, as well as LED, etc. */ 397/* Process receive queue, as well as LED, etc. */
737 398
738int ath_rx_tasklet(struct ath_softc *sc, int flush) 399int ath_rx_tasklet(struct ath_softc *sc, int flush)
@@ -1091,200 +752,3 @@ rx_next:
1091 return 0; 752 return 0;
1092#undef PA2DESC 753#undef PA2DESC
1093} 754}
1094
1095/* Process ADDBA request in per-TID data structure */
1096
1097int ath_rx_aggr_start(struct ath_softc *sc,
1098 const u8 *addr,
1099 u16 tid,
1100 u16 *ssn)
1101{
1102 struct ath_arx_tid *rxtid;
1103 struct ath_node *an;
1104 struct ieee80211_hw *hw = sc->hw;
1105 struct ieee80211_supported_band *sband;
1106 u16 buffersize = 0;
1107
1108 spin_lock_bh(&sc->node_lock);
1109 an = ath_node_find(sc, (u8 *) addr);
1110 spin_unlock_bh(&sc->node_lock);
1111
1112 if (!an) {
1113 DPRINTF(sc, ATH_DBG_AGGR,
1114 "%s: Node not found to initialize RX aggregation\n",
1115 __func__);
1116 return -1;
1117 }
1118
1119 sband = hw->wiphy->bands[hw->conf.channel->band];
1120 buffersize = IEEE80211_MIN_AMPDU_BUF <<
1121 sband->ht_cap.ampdu_factor; /* FIXME */
1122
1123 rxtid = &an->an_aggr.rx.tid[tid];
1124
1125 spin_lock_bh(&rxtid->tidlock);
1126 if (sc->sc_flags & SC_OP_RXAGGR) {
1127 /* Allow aggregation reception
1128 * Adjust rx BA window size. Peer might indicate a
1129 * zero buffer size for a _dont_care_ condition.
1130 */
1131 if (buffersize)
1132 rxtid->baw_size = min(buffersize, rxtid->baw_size);
1133
1134 /* set rx sequence number */
1135 rxtid->seq_next = *ssn;
1136
1137 /* Allocate the receive buffers for this TID */
1138 DPRINTF(sc, ATH_DBG_AGGR,
1139 "%s: Allcating rxbuffer for TID %d\n", __func__, tid);
1140
1141 if (rxtid->rxbuf == NULL) {
1142 /*
1143 * If the rxbuff is not NULL at this point, we *probably*
1144 * already allocated the buffer on a previous ADDBA,
1145 * and this is a subsequent ADDBA that got through.
1146 * Don't allocate, but use the value in the pointer,
1147 * we zero it out when we de-allocate.
1148 */
1149 rxtid->rxbuf = kmalloc(ATH_TID_MAX_BUFS *
1150 sizeof(struct ath_rxbuf), GFP_ATOMIC);
1151 }
1152 if (rxtid->rxbuf == NULL) {
1153 DPRINTF(sc, ATH_DBG_AGGR,
1154 "%s: Unable to allocate RX buffer, "
1155 "refusing ADDBA\n", __func__);
1156 } else {
1157 /* Ensure the memory is zeroed out (all internal
1158 * pointers are null) */
1159 memset(rxtid->rxbuf, 0, ATH_TID_MAX_BUFS *
1160 sizeof(struct ath_rxbuf));
1161 DPRINTF(sc, ATH_DBG_AGGR,
1162 "%s: Allocated @%p\n", __func__, rxtid->rxbuf);
1163
1164 /* Allow aggregation reception */
1165 rxtid->addba_exchangecomplete = 1;
1166 }
1167 }
1168 spin_unlock_bh(&rxtid->tidlock);
1169
1170 return 0;
1171}
1172
1173/* Process DELBA */
1174
1175int ath_rx_aggr_stop(struct ath_softc *sc,
1176 const u8 *addr,
1177 u16 tid)
1178{
1179 struct ath_node *an;
1180
1181 spin_lock_bh(&sc->node_lock);
1182 an = ath_node_find(sc, (u8 *) addr);
1183 spin_unlock_bh(&sc->node_lock);
1184
1185 if (!an) {
1186 DPRINTF(sc, ATH_DBG_AGGR,
1187 "%s: RX aggr stop for non-existent node\n", __func__);
1188 return -1;
1189 }
1190
1191 ath_rx_aggr_teardown(sc, an, tid);
1192 return 0;
1193}
1194
1195/* Rx aggregation tear down */
1196
1197void ath_rx_aggr_teardown(struct ath_softc *sc,
1198 struct ath_node *an, u8 tid)
1199{
1200 struct ath_arx_tid *rxtid = &an->an_aggr.rx.tid[tid];
1201
1202 if (!rxtid->addba_exchangecomplete)
1203 return;
1204
1205 del_timer_sync(&rxtid->timer);
1206 ath_rx_flush_tid(sc, rxtid, 0);
1207 rxtid->addba_exchangecomplete = 0;
1208
1209 /* De-allocate the receive buffer array allocated when addba started */
1210
1211 if (rxtid->rxbuf) {
1212 DPRINTF(sc, ATH_DBG_AGGR,
1213 "%s: Deallocating TID %d rxbuff @%p\n",
1214 __func__, tid, rxtid->rxbuf);
1215 kfree(rxtid->rxbuf);
1216
1217 /* Set pointer to null to avoid reuse*/
1218 rxtid->rxbuf = NULL;
1219 }
1220}
1221
1222/* Initialize per-node receive state */
1223
1224void ath_rx_node_init(struct ath_softc *sc, struct ath_node *an)
1225{
1226 if (sc->sc_flags & SC_OP_RXAGGR) {
1227 struct ath_arx_tid *rxtid;
1228 int tidno;
1229
1230 /* Init per tid rx state */
1231 for (tidno = 0, rxtid = &an->an_aggr.rx.tid[tidno];
1232 tidno < WME_NUM_TID;
1233 tidno++, rxtid++) {
1234 rxtid->an = an;
1235 rxtid->seq_reset = 1;
1236 rxtid->seq_next = 0;
1237 rxtid->baw_size = WME_MAX_BA;
1238 rxtid->baw_head = rxtid->baw_tail = 0;
1239
1240 /*
1241 * Ensure the buffer pointer is null at this point
1242 * (needs to be allocated when addba is received)
1243 */
1244
1245 rxtid->rxbuf = NULL;
1246 setup_timer(&rxtid->timer, ath_rx_timer,
1247 (unsigned long)rxtid);
1248 spin_lock_init(&rxtid->tidlock);
1249
1250 /* ADDBA state */
1251 rxtid->addba_exchangecomplete = 0;
1252 }
1253 }
1254}
1255
1256void ath_rx_node_cleanup(struct ath_softc *sc, struct ath_node *an)
1257{
1258 if (sc->sc_flags & SC_OP_RXAGGR) {
1259 struct ath_arx_tid *rxtid;
1260 int tidno, i;
1261
1262 /* Init per tid rx state */
1263 for (tidno = 0, rxtid = &an->an_aggr.rx.tid[tidno];
1264 tidno < WME_NUM_TID;
1265 tidno++, rxtid++) {
1266
1267 if (!rxtid->addba_exchangecomplete)
1268 continue;
1269
1270 /* must cancel timer first */
1271 del_timer_sync(&rxtid->timer);
1272
1273 /* drop any pending sub-frames */
1274 ath_rx_flush_tid(sc, rxtid, 1);
1275
1276 for (i = 0; i < ATH_TID_MAX_BUFS; i++)
1277 ASSERT(rxtid->rxbuf[i].rx_wbuf == NULL);
1278
1279 rxtid->addba_exchangecomplete = 0;
1280 }
1281 }
1282
1283}
1284
1285/* Cleanup per-node receive state */
1286
1287void ath_rx_node_free(struct ath_softc *sc, struct ath_node *an)
1288{
1289 ath_rx_node_cleanup(sc, an);
1290}
diff --git a/drivers/net/wireless/ath9k/xmit.c b/drivers/net/wireless/ath9k/xmit.c
index 7cfab5a542f0..8937728b0301 100644
--- a/drivers/net/wireless/ath9k/xmit.c
+++ b/drivers/net/wireless/ath9k/xmit.c
@@ -65,11 +65,12 @@ static u32 bits_per_symbol[][2] = {
65 * NB: must be called with txq lock held 65 * NB: must be called with txq lock held
66 */ 66 */
67 67
68static void ath_tx_txqaddbuf(struct ath_softc *sc, 68static void ath_tx_txqaddbuf(struct ath_softc *sc, struct ath_txq *txq,
69 struct ath_txq *txq, struct list_head *head) 69 struct list_head *head)
70{ 70{
71 struct ath_hal *ah = sc->sc_ah; 71 struct ath_hal *ah = sc->sc_ah;
72 struct ath_buf *bf; 72 struct ath_buf *bf;
73
73 /* 74 /*
74 * Insert the frame on the outbound list and 75 * Insert the frame on the outbound list and
75 * pass it on to the hardware. 76 * pass it on to the hardware.
@@ -124,27 +125,29 @@ static int ath_tx_findindex(const struct ath9k_rate_table *rt, int rate)
124 125
125/* Check if it's okay to send out aggregates */ 126/* Check if it's okay to send out aggregates */
126 127
127static int ath_aggr_query(struct ath_softc *sc, 128static int ath_aggr_query(struct ath_softc *sc, struct ath_node *an, u8 tidno)
128 struct ath_node *an, u8 tidno)
129{ 129{
130 struct ath_atx_tid *tid; 130 struct ath_atx_tid *tid;
131 tid = ATH_AN_2_TID(an, tidno); 131 tid = ATH_AN_2_TID(an, tidno);
132 132
133 if (tid->addba_exchangecomplete || tid->addba_exchangeinprogress) 133 if (tid->state & AGGR_ADDBA_COMPLETE ||
134 tid->state & AGGR_ADDBA_PROGRESS)
134 return 1; 135 return 1;
135 else 136 else
136 return 0; 137 return 0;
137} 138}
138 139
139static enum ath9k_pkt_type get_hal_packet_type(struct ieee80211_hdr *hdr) 140/* Calculate Atheros packet type from IEEE80211 packet header */
141
142static enum ath9k_pkt_type get_hw_packet_type(struct sk_buff *skb)
140{ 143{
144 struct ieee80211_hdr *hdr;
141 enum ath9k_pkt_type htype; 145 enum ath9k_pkt_type htype;
142 __le16 fc; 146 __le16 fc;
143 147
148 hdr = (struct ieee80211_hdr *)skb->data;
144 fc = hdr->frame_control; 149 fc = hdr->frame_control;
145 150
146 /* Calculate Atheros packet type from IEEE80211 packet header */
147
148 if (ieee80211_is_beacon(fc)) 151 if (ieee80211_is_beacon(fc))
149 htype = ATH9K_PKT_TYPE_BEACON; 152 htype = ATH9K_PKT_TYPE_BEACON;
150 else if (ieee80211_is_probe_resp(fc)) 153 else if (ieee80211_is_probe_resp(fc))
@@ -159,223 +162,176 @@ static enum ath9k_pkt_type get_hal_packet_type(struct ieee80211_hdr *hdr)
159 return htype; 162 return htype;
160} 163}
161 164
162static void fill_min_rates(struct sk_buff *skb, struct ath_tx_control *txctl) 165static bool check_min_rate(struct sk_buff *skb)
163{ 166{
164 struct ieee80211_hdr *hdr; 167 struct ieee80211_hdr *hdr;
165 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); 168 bool use_minrate = false;
166 struct ath_tx_info_priv *tx_info_priv;
167 __le16 fc; 169 __le16 fc;
168 170
169 hdr = (struct ieee80211_hdr *)skb->data; 171 hdr = (struct ieee80211_hdr *)skb->data;
170 fc = hdr->frame_control; 172 fc = hdr->frame_control;
171 173
172 /* XXX: HACK! */
173 tx_info_priv = (struct ath_tx_info_priv *)tx_info->control.vif;
174
175 if (ieee80211_is_mgmt(fc) || ieee80211_is_ctl(fc)) { 174 if (ieee80211_is_mgmt(fc) || ieee80211_is_ctl(fc)) {
176 txctl->use_minrate = 1; 175 use_minrate = true;
177 txctl->min_rate = tx_info_priv->min_rate;
178 } else if (ieee80211_is_data(fc)) { 176 } else if (ieee80211_is_data(fc)) {
179 if (ieee80211_is_nullfunc(fc) || 177 if (ieee80211_is_nullfunc(fc) ||
180 /* Port Access Entity (IEEE 802.1X) */ 178 /* Port Access Entity (IEEE 802.1X) */
181 (skb->protocol == cpu_to_be16(ETH_P_PAE))) { 179 (skb->protocol == cpu_to_be16(ETH_P_PAE))) {
182 txctl->use_minrate = 1; 180 use_minrate = true;
183 txctl->min_rate = tx_info_priv->min_rate;
184 } 181 }
185 if (is_multicast_ether_addr(hdr->addr1))
186 txctl->mcast_rate = tx_info_priv->min_rate;
187 } 182 }
188 183
184 return use_minrate;
189} 185}
190 186
191/* This function will setup additional txctl information, mostly rate stuff */ 187static int get_hw_crypto_keytype(struct sk_buff *skb)
192/* FIXME: seqno, ps */
193static int ath_tx_prepare(struct ath_softc *sc,
194 struct sk_buff *skb,
195 struct ath_tx_control *txctl)
196{ 188{
197 struct ieee80211_hw *hw = sc->hw;
198 struct ieee80211_hdr *hdr;
199 struct ath_rc_series *rcs;
200 struct ath_txq *txq = NULL;
201 const struct ath9k_rate_table *rt;
202 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); 189 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
203 struct ath_tx_info_priv *tx_info_priv;
204 int hdrlen;
205 u8 rix, antenna;
206 __le16 fc;
207 u8 *qc;
208
209 txctl->dev = sc;
210 hdr = (struct ieee80211_hdr *)skb->data;
211 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
212 fc = hdr->frame_control;
213
214 rt = sc->sc_currates;
215 BUG_ON(!rt);
216
217 /* Fill misc fields */
218
219 spin_lock_bh(&sc->node_lock);
220 txctl->an = ath_node_get(sc, hdr->addr1);
221 /* create a temp node, if the node is not there already */
222 if (!txctl->an)
223 txctl->an = ath_node_attach(sc, hdr->addr1, 0);
224 spin_unlock_bh(&sc->node_lock);
225
226 if (ieee80211_is_data_qos(fc)) {
227 qc = ieee80211_get_qos_ctl(hdr);
228 txctl->tidno = qc[0] & 0xf;
229 }
230
231 txctl->if_id = 0;
232 txctl->frmlen = skb->len + FCS_LEN - (hdrlen & 3);
233
234 /* Always try at highest power possible unless the the device
235 * was configured by the user to use another power. */
236 if (likely(sc->sc_config.txpowlimit == ATH_TXPOWER_MAX))
237 txctl->txpower = ATH_TXPOWER_MAX;
238 else
239 txctl->txpower = sc->sc_config.txpowlimit;
240
241 /* Fill Key related fields */
242
243 txctl->keytype = ATH9K_KEY_TYPE_CLEAR;
244 txctl->keyix = ATH9K_TXKEYIX_INVALID;
245 190
246 if (tx_info->control.hw_key) { 191 if (tx_info->control.hw_key) {
247 txctl->keyix = tx_info->control.hw_key->hw_key_idx;
248 txctl->frmlen += tx_info->control.hw_key->icv_len;
249
250 if (tx_info->control.hw_key->alg == ALG_WEP) 192 if (tx_info->control.hw_key->alg == ALG_WEP)
251 txctl->keytype = ATH9K_KEY_TYPE_WEP; 193 return ATH9K_KEY_TYPE_WEP;
252 else if (tx_info->control.hw_key->alg == ALG_TKIP) 194 else if (tx_info->control.hw_key->alg == ALG_TKIP)
253 txctl->keytype = ATH9K_KEY_TYPE_TKIP; 195 return ATH9K_KEY_TYPE_TKIP;
254 else if (tx_info->control.hw_key->alg == ALG_CCMP) 196 else if (tx_info->control.hw_key->alg == ALG_CCMP)
255 txctl->keytype = ATH9K_KEY_TYPE_AES; 197 return ATH9K_KEY_TYPE_AES;
256 } 198 }
257 199
258 /* Fill packet type */ 200 return ATH9K_KEY_TYPE_CLEAR;
259 201}
260 txctl->atype = get_hal_packet_type(hdr);
261
262 /* Fill qnum */
263 202
264 if (unlikely(txctl->flags & ATH9K_TXDESC_CAB)) { 203static void setup_rate_retries(struct ath_softc *sc, struct sk_buff *skb)
265 txctl->qnum = 0; 204{
266 txq = sc->sc_cabq; 205 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
267 } else { 206 struct ath_tx_info_priv *tx_info_priv;
268 txctl->qnum = ath_get_hal_qnum(skb_get_queue_mapping(skb), sc); 207 struct ath_rc_series *rcs;
269 txq = &sc->sc_txq[txctl->qnum]; 208 struct ieee80211_hdr *hdr;
270 } 209 const struct ath9k_rate_table *rt;
271 spin_lock_bh(&txq->axq_lock); 210 bool use_minrate;
211 __le16 fc;
212 u8 rix;
272 213
273 /* Try to avoid running out of descriptors */ 214 rt = sc->sc_currates;
274 if (txq->axq_depth >= (ATH_TXBUF - 20) && 215 BUG_ON(!rt);
275 !(txctl->flags & ATH9K_TXDESC_CAB)) {
276 DPRINTF(sc, ATH_DBG_FATAL,
277 "%s: TX queue: %d is full, depth: %d\n",
278 __func__,
279 txctl->qnum,
280 txq->axq_depth);
281 ieee80211_stop_queue(hw, skb_get_queue_mapping(skb));
282 txq->stopped = 1;
283 spin_unlock_bh(&txq->axq_lock);
284 return -1;
285 }
286 216
287 spin_unlock_bh(&txq->axq_lock); 217 hdr = (struct ieee80211_hdr *)skb->data;
218 fc = hdr->frame_control;
219 tx_info_priv = (struct ath_tx_info_priv *)tx_info->control.vif; /* HACK */
220 rcs = tx_info_priv->rcs;
288 221
289 /* Fill rate */ 222 /* Check if min rates have to be used */
223 use_minrate = check_min_rate(skb);
290 224
291 fill_min_rates(skb, txctl); 225 if (ieee80211_is_data(fc) && !use_minrate) {
226 if (is_multicast_ether_addr(hdr->addr1)) {
227 rcs[0].rix =
228 ath_tx_findindex(rt, tx_info_priv->min_rate);
229 /* mcast packets are not re-tried */
230 rcs[0].tries = 1;
231 }
232 } else {
233 /* for management and control frames,
234 or for NULL and EAPOL frames */
235 if (use_minrate)
236 rcs[0].rix = ath_rate_findrateix(sc, tx_info_priv->min_rate);
237 else
238 rcs[0].rix = 0;
239 rcs[0].tries = ATH_MGT_TXMAXTRY;
240 }
292 241
293 /* Fill flags */ 242 rix = rcs[0].rix;
294 243
295 txctl->flags |= ATH9K_TXDESC_CLRDMASK /* needed for crypto errors */ 244 if (ieee80211_has_morefrags(fc) ||
296 | ATH9K_TXDESC_INTREQ; /* Generate an interrupt */ 245 (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG)) {
246 rcs[1].tries = rcs[2].tries = rcs[3].tries = 0;
247 rcs[1].rix = rcs[2].rix = rcs[3].rix = 0;
248 /* reset tries but keep rate index */
249 rcs[0].tries = ATH_TXMAXTRY;
250 }
251}
297 252
298 if (tx_info->flags & IEEE80211_TX_CTL_NO_ACK) 253/* Called only when tx aggregation is enabled and HT is supported */
299 txctl->flags |= ATH9K_TXDESC_NOACK;
300 254
301 if (tx_info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) 255static void assign_aggr_tid_seqno(struct sk_buff *skb,
302 txctl->flags |= ATH9K_TXDESC_RTSENA; 256 struct ath_buf *bf)
257{
258 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
259 struct ieee80211_hdr *hdr;
260 struct ath_node *an;
261 struct ath_atx_tid *tid;
262 __le16 fc;
263 u8 *qc;
303 264
304 /* 265 if (!tx_info->control.sta)
305 * Setup for rate calculations. 266 return;
306 */
307 267
308 /* XXX: HACK! */ 268 an = (struct ath_node *)tx_info->control.sta->drv_priv;
309 tx_info_priv = (struct ath_tx_info_priv *)tx_info->control.vif; 269 hdr = (struct ieee80211_hdr *)skb->data;
310 rcs = tx_info_priv->rcs; 270 fc = hdr->frame_control;
311 271
312 if (ieee80211_is_data(fc) && !txctl->use_minrate) { 272 /* Get tidno */
313 273
314 /* Enable HT only for DATA frames and not for EAPOL */ 274 if (ieee80211_is_data_qos(fc)) {
315 /* XXX why AMPDU only?? */ 275 qc = ieee80211_get_qos_ctl(hdr);
316 txctl->ht = (hw->conf.ht.enabled && 276 bf->bf_tidno = qc[0] & 0xf;
317 (tx_info->flags & IEEE80211_TX_CTL_AMPDU)); 277 }
318 278
319 if (is_multicast_ether_addr(hdr->addr1)) { 279 /* Get seqno */
320 rcs[0].rix = (u8)
321 ath_tx_findindex(rt, txctl->mcast_rate);
322 280
323 /* 281 if (ieee80211_is_data(fc) && !check_min_rate(skb)) {
324 * mcast packets are not re-tried.
325 */
326 rcs[0].tries = 1;
327 }
328 /* For HT capable stations, we save tidno for later use. 282 /* For HT capable stations, we save tidno for later use.
329 * We also override seqno set by upper layer with the one 283 * We also override seqno set by upper layer with the one
330 * in tx aggregation state. 284 * in tx aggregation state.
331 * 285 *
332 * First, the fragmentation stat is determined.
333 * If fragmentation is on, the sequence number is 286 * If fragmentation is on, the sequence number is
334 * not overridden, since it has been 287 * not overridden, since it has been
335 * incremented by the fragmentation routine. 288 * incremented by the fragmentation routine.
289 *
290 * FIXME: check if the fragmentation threshold exceeds
291 * IEEE80211 max.
336 */ 292 */
337 if (likely(!(txctl->flags & ATH9K_TXDESC_FRAG_IS_ON)) && 293 tid = ATH_AN_2_TID(an, bf->bf_tidno);
338 txctl->ht && (sc->sc_flags & SC_OP_TXAGGR)) { 294 hdr->seq_ctrl = cpu_to_le16(tid->seq_next <<
339 struct ath_atx_tid *tid; 295 IEEE80211_SEQ_SEQ_SHIFT);
296 bf->bf_seqno = tid->seq_next;
297 INCR(tid->seq_next, IEEE80211_SEQ_MAX);
298 }
299}
340 300
341 tid = ATH_AN_2_TID(txctl->an, txctl->tidno); 301static int setup_tx_flags(struct ath_softc *sc, struct sk_buff *skb,
302 struct ath_txq *txq)
303{
304 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
305 int flags = 0;
342 306
343 hdr->seq_ctrl = cpu_to_le16(tid->seq_next << 307 flags |= ATH9K_TXDESC_CLRDMASK; /* needed for crypto errors */
344 IEEE80211_SEQ_SEQ_SHIFT); 308 flags |= ATH9K_TXDESC_INTREQ;
345 txctl->seqno = tid->seq_next;
346 INCR(tid->seq_next, IEEE80211_SEQ_MAX);
347 }
348 } else {
349 /* for management and control frames,
350 * or for NULL and EAPOL frames */
351 if (txctl->min_rate)
352 rcs[0].rix = ath_rate_findrateix(sc, txctl->min_rate);
353 else
354 rcs[0].rix = 0;
355 rcs[0].tries = ATH_MGT_TXMAXTRY;
356 }
357 rix = rcs[0].rix;
358 309
359 if (ieee80211_has_morefrags(fc) || 310 if (tx_info->flags & IEEE80211_TX_CTL_NO_ACK)
360 (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG)) { 311 flags |= ATH9K_TXDESC_NOACK;
361 /* 312 if (tx_info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS)
362 ** Force hardware to use computed duration for next 313 flags |= ATH9K_TXDESC_RTSENA;
363 ** fragment by disabling multi-rate retry, which 314
364 ** updates duration based on the multi-rate 315 return flags;
365 ** duration table. 316}
366 */
367 rcs[1].tries = rcs[2].tries = rcs[3].tries = 0;
368 rcs[1].rix = rcs[2].rix = rcs[3].rix = 0;
369 /* reset tries but keep rate index */
370 rcs[0].tries = ATH_TXMAXTRY;
371 }
372 317
373 if (is_multicast_ether_addr(hdr->addr1)) { 318static struct ath_buf *ath_tx_get_buffer(struct ath_softc *sc)
374 antenna = sc->sc_mcastantenna + 1; 319{
375 sc->sc_mcastantenna = (sc->sc_mcastantenna + 1) & 0x1; 320 struct ath_buf *bf = NULL;
321
322 spin_lock_bh(&sc->sc_txbuflock);
323
324 if (unlikely(list_empty(&sc->sc_txbuf))) {
325 spin_unlock_bh(&sc->sc_txbuflock);
326 return NULL;
376 } 327 }
377 328
378 return 0; 329 bf = list_first_entry(&sc->sc_txbuf, struct ath_buf, list);
330 list_del(&bf->list);
331
332 spin_unlock_bh(&sc->sc_txbuflock);
333
334 return bf;
379} 335}
380 336
381/* To complete a chain of buffers associated a frame */ 337/* To complete a chain of buffers associated a frame */
@@ -405,13 +361,14 @@ static void ath_tx_complete_buf(struct ath_softc *sc,
405 if (bf_isxretried(bf)) 361 if (bf_isxretried(bf))
406 tx_status.flags |= ATH_TX_XRETRY; 362 tx_status.flags |= ATH_TX_XRETRY;
407 } 363 }
364
408 /* Unmap this frame */ 365 /* Unmap this frame */
409 pci_unmap_single(sc->pdev, 366 pci_unmap_single(sc->pdev,
410 bf->bf_dmacontext, 367 bf->bf_dmacontext,
411 skb->len, 368 skb->len,
412 PCI_DMA_TODEVICE); 369 PCI_DMA_TODEVICE);
413 /* complete this frame */ 370 /* complete this frame */
414 ath_tx_complete(sc, skb, &tx_status, bf->bf_node); 371 ath_tx_complete(sc, skb, &tx_status);
415 372
416 /* 373 /*
417 * Return the list of ath_buf of this mpdu to free queue 374 * Return the list of ath_buf of this mpdu to free queue
@@ -496,11 +453,9 @@ unlock:
496 453
497/* Compute the number of bad frames */ 454/* Compute the number of bad frames */
498 455
499static int ath_tx_num_badfrms(struct ath_softc *sc, 456static int ath_tx_num_badfrms(struct ath_softc *sc, struct ath_buf *bf,
500 struct ath_buf *bf, int txok) 457 int txok)
501{ 458{
502 struct ath_node *an = bf->bf_node;
503 int isnodegone = (an->an_flags & ATH_NODE_CLEAN);
504 struct ath_buf *bf_last = bf->bf_lastbf; 459 struct ath_buf *bf_last = bf->bf_lastbf;
505 struct ath_desc *ds = bf_last->bf_desc; 460 struct ath_desc *ds = bf_last->bf_desc;
506 u16 seq_st = 0; 461 u16 seq_st = 0;
@@ -509,7 +464,7 @@ static int ath_tx_num_badfrms(struct ath_softc *sc,
509 int nbad = 0; 464 int nbad = 0;
510 int isaggr = 0; 465 int isaggr = 0;
511 466
512 if (isnodegone || ds->ds_txstat.ts_flags == ATH9K_TX_SW_ABORTED) 467 if (ds->ds_txstat.ts_flags == ATH9K_TX_SW_ABORTED)
513 return 0; 468 return 0;
514 469
515 isaggr = bf_isaggr(bf); 470 isaggr = bf_isaggr(bf);
@@ -544,8 +499,8 @@ static void ath_tx_set_retry(struct ath_softc *sc, struct ath_buf *bf)
544 499
545/* Update block ack window */ 500/* Update block ack window */
546 501
547static void ath_tx_update_baw(struct ath_softc *sc, 502static void ath_tx_update_baw(struct ath_softc *sc, struct ath_atx_tid *tid,
548 struct ath_atx_tid *tid, int seqno) 503 int seqno)
549{ 504{
550 int index, cindex; 505 int index, cindex;
551 506
@@ -569,12 +524,8 @@ static void ath_tx_update_baw(struct ath_softc *sc,
569 * half_gi - to use 4us v/s 3.6 us for symbol time 524 * half_gi - to use 4us v/s 3.6 us for symbol time
570 */ 525 */
571 526
572static u32 ath_pkt_duration(struct ath_softc *sc, 527static u32 ath_pkt_duration(struct ath_softc *sc, u8 rix, struct ath_buf *bf,
573 u8 rix, 528 int width, int half_gi, bool shortPreamble)
574 struct ath_buf *bf,
575 int width,
576 int half_gi,
577 bool shortPreamble)
578{ 529{
579 const struct ath9k_rate_table *rt = sc->sc_currates; 530 const struct ath9k_rate_table *rt = sc->sc_currates;
580 u32 nbits, nsymbits, duration, nsymbols; 531 u32 nbits, nsymbits, duration, nsymbols;
@@ -588,11 +539,8 @@ static u32 ath_pkt_duration(struct ath_softc *sc,
588 * for legacy rates, use old function to compute packet duration 539 * for legacy rates, use old function to compute packet duration
589 */ 540 */
590 if (!IS_HT_RATE(rc)) 541 if (!IS_HT_RATE(rc))
591 return ath9k_hw_computetxtime(sc->sc_ah, 542 return ath9k_hw_computetxtime(sc->sc_ah, rt, pktlen, rix,
592 rt, 543 shortPreamble);
593 pktlen,
594 rix,
595 shortPreamble);
596 /* 544 /*
597 * find number of symbols: PLCP + data 545 * find number of symbols: PLCP + data
598 */ 546 */
@@ -610,6 +558,7 @@ static u32 ath_pkt_duration(struct ath_softc *sc,
610 */ 558 */
611 streams = HT_RC_2_STREAMS(rc); 559 streams = HT_RC_2_STREAMS(rc);
612 duration += L_STF + L_LTF + L_SIG + HT_SIG + HT_STF + HT_LTF(streams); 560 duration += L_STF + L_LTF + L_SIG + HT_SIG + HT_STF + HT_LTF(streams);
561
613 return duration; 562 return duration;
614} 563}
615 564
@@ -622,11 +571,18 @@ static void ath_buf_set_rate(struct ath_softc *sc, struct ath_buf *bf)
622 struct ath_desc *ds = bf->bf_desc; 571 struct ath_desc *ds = bf->bf_desc;
623 struct ath_desc *lastds = bf->bf_lastbf->bf_desc; 572 struct ath_desc *lastds = bf->bf_lastbf->bf_desc;
624 struct ath9k_11n_rate_series series[4]; 573 struct ath9k_11n_rate_series series[4];
625 int i, flags, rtsctsena = 0, dynamic_mimops = 0; 574 int i, flags, rtsctsena = 0;
626 u32 ctsduration = 0; 575 u32 ctsduration = 0;
627 u8 rix = 0, cix, ctsrate = 0; 576 u8 rix = 0, cix, ctsrate = 0;
628 u32 aggr_limit_with_rts = ah->ah_caps.rts_aggr_limit; 577 struct ath_node *an = NULL;
629 struct ath_node *an = (struct ath_node *) bf->bf_node; 578 struct sk_buff *skb;
579 struct ieee80211_tx_info *tx_info;
580
581 skb = (struct sk_buff *)bf->bf_mpdu;
582 tx_info = IEEE80211_SKB_CB(skb);
583
584 if (tx_info->control.sta)
585 an = (struct ath_node *)tx_info->control.sta->drv_priv;
630 586
631 /* 587 /*
632 * get the cix for the lowest valid rix. 588 * get the cix for the lowest valid rix.
@@ -665,24 +621,11 @@ static void ath_buf_set_rate(struct ath_softc *sc, struct ath_buf *bf)
665 * use RTS. 621 * use RTS.
666 */ 622 */
667 if ((ah->ah_caps.hw_caps & ATH9K_HW_CAP_HT) && bf_isdata(bf)) { 623 if ((ah->ah_caps.hw_caps & ATH9K_HW_CAP_HT) && bf_isdata(bf)) {
668 BUG_ON(!an);
669 /* 624 /*
670 * 802.11g protection not needed, use our default behavior 625 * 802.11g protection not needed, use our default behavior
671 */ 626 */
672 if (!rtsctsena) 627 if (!rtsctsena)
673 flags = ATH9K_TXDESC_RTSENA; 628 flags = ATH9K_TXDESC_RTSENA;
674 /*
675 * For dynamic MIMO PS, RTS needs to precede the first aggregate
676 * and the second aggregate should have any protection at all.
677 */
678 if (an->an_smmode == ATH_SM_PWRSAV_DYNAMIC) {
679 if (!bf_isaggrburst(bf)) {
680 flags = ATH9K_TXDESC_RTSENA;
681 dynamic_mimops = 1;
682 } else {
683 flags = 0;
684 }
685 }
686 } 629 }
687 630
688 /* 631 /*
@@ -698,7 +641,7 @@ static void ath_buf_set_rate(struct ath_softc *sc, struct ath_buf *bf)
698 /* 641 /*
699 * For AR5416 - RTS cannot be followed by a frame larger than 8K. 642 * For AR5416 - RTS cannot be followed by a frame larger than 8K.
700 */ 643 */
701 if (bf_isaggr(bf) && (bf->bf_al > aggr_limit_with_rts)) { 644 if (bf_isaggr(bf) && (bf->bf_al > ah->ah_caps.rts_aggr_limit)) {
702 /* 645 /*
703 * Ensure that in the case of SM Dynamic power save 646 * Ensure that in the case of SM Dynamic power save
704 * while we are bursting the second aggregate the 647 * while we are bursting the second aggregate the
@@ -711,8 +654,8 @@ static void ath_buf_set_rate(struct ath_softc *sc, struct ath_buf *bf)
711 * CTS transmit rate is derived from the transmit rate 654 * CTS transmit rate is derived from the transmit rate
712 * by looking in the h/w rate table. We must also factor 655 * by looking in the h/w rate table. We must also factor
713 * in whether or not a short preamble is to be used. 656 * in whether or not a short preamble is to be used.
657 * NB: cix is set above where RTS/CTS is enabled
714 */ 658 */
715 /* NB: cix is set above where RTS/CTS is enabled */
716 BUG_ON(cix == 0xff); 659 BUG_ON(cix == 0xff);
717 ctsrate = rt->info[cix].rateCode | 660 ctsrate = rt->info[cix].rateCode |
718 (bf_isshpreamble(bf) ? rt->info[cix].shortPreamble : 0); 661 (bf_isshpreamble(bf) ? rt->info[cix].shortPreamble : 0);
@@ -741,39 +684,18 @@ static void ath_buf_set_rate(struct ath_softc *sc, struct ath_buf *bf)
741 ((bf->bf_rcs[i].flags & ATH_RC_SGI_FLAG) ? 684 ((bf->bf_rcs[i].flags & ATH_RC_SGI_FLAG) ?
742 ATH9K_RATESERIES_HALFGI : 0); 685 ATH9K_RATESERIES_HALFGI : 0);
743 686
744 series[i].PktDuration = ath_pkt_duration( 687 series[i].PktDuration = ath_pkt_duration(sc, rix, bf,
745 sc, rix, bf, 688 (bf->bf_rcs[i].flags & ATH_RC_CW40_FLAG) != 0,
746 (bf->bf_rcs[i].flags & ATH_RC_CW40_FLAG) != 0, 689 (bf->bf_rcs[i].flags & ATH_RC_SGI_FLAG),
747 (bf->bf_rcs[i].flags & ATH_RC_SGI_FLAG), 690 bf_isshpreamble(bf));
748 bf_isshpreamble(bf));
749 691
750 if ((an->an_smmode == ATH_SM_PWRSAV_STATIC) && 692 if (bf_isht(bf) && an)
751 (bf->bf_rcs[i].flags & ATH_RC_DS_FLAG) == 0) { 693 series[i].ChSel = ath_chainmask_sel_logic(sc, an);
752 /* 694 else
753 * When sending to an HT node that has enabled static
754 * SM/MIMO power save, send at single stream rates but
755 * use maximum allowed transmit chains per user,
756 * hardware, regulatory, or country limits for
757 * better range.
758 */
759 series[i].ChSel = sc->sc_tx_chainmask; 695 series[i].ChSel = sc->sc_tx_chainmask;
760 } else {
761 if (bf_isht(bf))
762 series[i].ChSel =
763 ath_chainmask_sel_logic(sc, an);
764 else
765 series[i].ChSel = sc->sc_tx_chainmask;
766 }
767 696
768 if (rtsctsena) 697 if (rtsctsena)
769 series[i].RateFlags |= ATH9K_RATESERIES_RTS_CTS; 698 series[i].RateFlags |= ATH9K_RATESERIES_RTS_CTS;
770
771 /*
772 * Set RTS for all rates if node is in dynamic powersave
773 * mode and we are using dual stream rates.
774 */
775 if (dynamic_mimops && (bf->bf_rcs[i].flags & ATH_RC_DS_FLAG))
776 series[i].RateFlags |= ATH9K_RATESERIES_RTS_CTS;
777 } 699 }
778 700
779 /* 701 /*
@@ -819,6 +741,7 @@ static void ath_buf_set_rate(struct ath_softc *sc, struct ath_buf *bf)
819 ctsrate, 741 ctsrate,
820 ctsduration, 742 ctsduration,
821 series, 4, flags); 743 series, 4, flags);
744
822 if (sc->sc_config.ath_aggr_prot && flags) 745 if (sc->sc_config.ath_aggr_prot && flags)
823 ath9k_hw_set11n_burstduration(ah, ds, 8192); 746 ath9k_hw_set11n_burstduration(ah, ds, 8192);
824} 747}
@@ -899,8 +822,10 @@ static void ath_tx_complete_aggr_rifs(struct ath_softc *sc,
899 struct list_head *bf_q, 822 struct list_head *bf_q,
900 int txok) 823 int txok)
901{ 824{
902 struct ath_node *an = bf->bf_node; 825 struct ath_node *an = NULL;
903 struct ath_atx_tid *tid = ATH_AN_2_TID(an, bf->bf_tidno); 826 struct sk_buff *skb;
827 struct ieee80211_tx_info *tx_info;
828 struct ath_atx_tid *tid = NULL;
904 struct ath_buf *bf_last = bf->bf_lastbf; 829 struct ath_buf *bf_last = bf->bf_lastbf;
905 struct ath_desc *ds = bf_last->bf_desc; 830 struct ath_desc *ds = bf_last->bf_desc;
906 struct ath_buf *bf_next, *bf_lastq = NULL; 831 struct ath_buf *bf_next, *bf_lastq = NULL;
@@ -908,7 +833,14 @@ static void ath_tx_complete_aggr_rifs(struct ath_softc *sc,
908 u16 seq_st = 0; 833 u16 seq_st = 0;
909 u32 ba[WME_BA_BMP_SIZE >> 5]; 834 u32 ba[WME_BA_BMP_SIZE >> 5];
910 int isaggr, txfail, txpending, sendbar = 0, needreset = 0; 835 int isaggr, txfail, txpending, sendbar = 0, needreset = 0;
911 int isnodegone = (an->an_flags & ATH_NODE_CLEAN); 836
837 skb = (struct sk_buff *)bf->bf_mpdu;
838 tx_info = IEEE80211_SKB_CB(skb);
839
840 if (tx_info->control.sta) {
841 an = (struct ath_node *)tx_info->control.sta->drv_priv;
842 tid = ATH_AN_2_TID(an, bf->bf_tidno);
843 }
912 844
913 isaggr = bf_isaggr(bf); 845 isaggr = bf_isaggr(bf);
914 if (isaggr) { 846 if (isaggr) {
@@ -954,7 +886,7 @@ static void ath_tx_complete_aggr_rifs(struct ath_softc *sc,
954 /* transmit completion */ 886 /* transmit completion */
955 } else { 887 } else {
956 888
957 if (!tid->cleanup_inprogress && !isnodegone && 889 if (!(tid->state & AGGR_CLEANUP) &&
958 ds->ds_txstat.ts_flags != ATH9K_TX_SW_ABORTED) { 890 ds->ds_txstat.ts_flags != ATH9K_TX_SW_ABORTED) {
959 if (bf->bf_retries < ATH_MAX_SW_RETRIES) { 891 if (bf->bf_retries < ATH_MAX_SW_RETRIES) {
960 ath_tx_set_retry(sc, bf); 892 ath_tx_set_retry(sc, bf);
@@ -1042,7 +974,6 @@ static void ath_tx_complete_aggr_rifs(struct ath_softc *sc,
1042 974
1043 /* copy descriptor content */ 975 /* copy descriptor content */
1044 tbf->bf_mpdu = bf_last->bf_mpdu; 976 tbf->bf_mpdu = bf_last->bf_mpdu;
1045 tbf->bf_node = bf_last->bf_node;
1046 tbf->bf_buf_addr = bf_last->bf_buf_addr; 977 tbf->bf_buf_addr = bf_last->bf_buf_addr;
1047 *(tbf->bf_desc) = *(bf_last->bf_desc); 978 *(tbf->bf_desc) = *(bf_last->bf_desc);
1048 979
@@ -1083,25 +1014,16 @@ static void ath_tx_complete_aggr_rifs(struct ath_softc *sc,
1083 bf = bf_next; 1014 bf = bf_next;
1084 } 1015 }
1085 1016
1086 /* 1017 if (tid->state & AGGR_CLEANUP) {
1087 * node is already gone. no more assocication
1088 * with the node. the node might have been freed
1089 * any node acces can result in panic.note tid
1090 * is part of the node.
1091 */
1092 if (isnodegone)
1093 return;
1094
1095 if (tid->cleanup_inprogress) {
1096 /* check to see if we're done with cleaning the h/w queue */ 1018 /* check to see if we're done with cleaning the h/w queue */
1097 spin_lock_bh(&txq->axq_lock); 1019 spin_lock_bh(&txq->axq_lock);
1098 1020
1099 if (tid->baw_head == tid->baw_tail) { 1021 if (tid->baw_head == tid->baw_tail) {
1100 tid->addba_exchangecomplete = 0; 1022 tid->state &= ~AGGR_ADDBA_COMPLETE;
1101 tid->addba_exchangeattempts = 0; 1023 tid->addba_exchangeattempts = 0;
1102 spin_unlock_bh(&txq->axq_lock); 1024 spin_unlock_bh(&txq->axq_lock);
1103 1025
1104 tid->cleanup_inprogress = false; 1026 tid->state &= ~AGGR_CLEANUP;
1105 1027
1106 /* send buffered frames as singles */ 1028 /* send buffered frames as singles */
1107 ath_tx_flush_tid(sc, tid); 1029 ath_tx_flush_tid(sc, tid);
@@ -1310,26 +1232,21 @@ static void ath_tx_stopdma(struct ath_softc *sc, struct ath_txq *txq)
1310static void ath_drain_txdataq(struct ath_softc *sc, bool retry_tx) 1232static void ath_drain_txdataq(struct ath_softc *sc, bool retry_tx)
1311{ 1233{
1312 struct ath_hal *ah = sc->sc_ah; 1234 struct ath_hal *ah = sc->sc_ah;
1313 int i; 1235 int i, status, npend = 0;
1314 int npend = 0;
1315 1236
1316 /* XXX return value */
1317 if (!(sc->sc_flags & SC_OP_INVALID)) { 1237 if (!(sc->sc_flags & SC_OP_INVALID)) {
1318 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) { 1238 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
1319 if (ATH_TXQ_SETUP(sc, i)) { 1239 if (ATH_TXQ_SETUP(sc, i)) {
1320 ath_tx_stopdma(sc, &sc->sc_txq[i]); 1240 ath_tx_stopdma(sc, &sc->sc_txq[i]);
1321
1322 /* The TxDMA may not really be stopped. 1241 /* The TxDMA may not really be stopped.
1323 * Double check the hal tx pending count */ 1242 * Double check the hal tx pending count */
1324 npend += ath9k_hw_numtxpending(ah, 1243 npend += ath9k_hw_numtxpending(ah,
1325 sc->sc_txq[i].axq_qnum); 1244 sc->sc_txq[i].axq_qnum);
1326 } 1245 }
1327 } 1246 }
1328 } 1247 }
1329 1248
1330 if (npend) { 1249 if (npend) {
1331 int status;
1332
1333 /* TxDMA not stopped, reset the hal */ 1250 /* TxDMA not stopped, reset the hal */
1334 DPRINTF(sc, ATH_DBG_XMIT, 1251 DPRINTF(sc, ATH_DBG_XMIT,
1335 "%s: Unable to stop TxDMA. Reset HAL!\n", __func__); 1252 "%s: Unable to stop TxDMA. Reset HAL!\n", __func__);
@@ -1385,7 +1302,6 @@ static void ath_tx_addto_baw(struct ath_softc *sc,
1385 */ 1302 */
1386 1303
1387static int ath_tx_send_ampdu(struct ath_softc *sc, 1304static int ath_tx_send_ampdu(struct ath_softc *sc,
1388 struct ath_txq *txq,
1389 struct ath_atx_tid *tid, 1305 struct ath_atx_tid *tid,
1390 struct list_head *bf_head, 1306 struct list_head *bf_head,
1391 struct ath_tx_control *txctl) 1307 struct ath_tx_control *txctl)
@@ -1399,8 +1315,6 @@ static int ath_tx_send_ampdu(struct ath_softc *sc,
1399 1315
1400 bf = list_first_entry(bf_head, struct ath_buf, list); 1316 bf = list_first_entry(bf_head, struct ath_buf, list);
1401 bf->bf_state.bf_type |= BUF_AMPDU; 1317 bf->bf_state.bf_type |= BUF_AMPDU;
1402 bf->bf_seqno = txctl->seqno; /* save seqno and tidno in buffer */
1403 bf->bf_tidno = txctl->tidno;
1404 1318
1405 /* 1319 /*
1406 * Do not queue to h/w when any of the following conditions is true: 1320 * Do not queue to h/w when any of the following conditions is true:
@@ -1411,13 +1325,13 @@ static int ath_tx_send_ampdu(struct ath_softc *sc,
1411 */ 1325 */
1412 if (!list_empty(&tid->buf_q) || tid->paused || 1326 if (!list_empty(&tid->buf_q) || tid->paused ||
1413 !BAW_WITHIN(tid->seq_start, tid->baw_size, bf->bf_seqno) || 1327 !BAW_WITHIN(tid->seq_start, tid->baw_size, bf->bf_seqno) ||
1414 txq->axq_depth >= ATH_AGGR_MIN_QDEPTH) { 1328 txctl->txq->axq_depth >= ATH_AGGR_MIN_QDEPTH) {
1415 /* 1329 /*
1416 * Add this frame to software queue for scheduling later 1330 * Add this frame to software queue for scheduling later
1417 * for aggregation. 1331 * for aggregation.
1418 */ 1332 */
1419 list_splice_tail_init(bf_head, &tid->buf_q); 1333 list_splice_tail_init(bf_head, &tid->buf_q);
1420 ath_tx_queue_tid(txq, tid); 1334 ath_tx_queue_tid(txctl->txq, tid);
1421 return 0; 1335 return 0;
1422 } 1336 }
1423 1337
@@ -1434,7 +1348,8 @@ static int ath_tx_send_ampdu(struct ath_softc *sc,
1434 bf->bf_nframes = 1; 1348 bf->bf_nframes = 1;
1435 bf->bf_lastbf = bf->bf_lastfrm; /* one single frame */ 1349 bf->bf_lastbf = bf->bf_lastfrm; /* one single frame */
1436 ath_buf_set_rate(sc, bf); 1350 ath_buf_set_rate(sc, bf);
1437 ath_tx_txqaddbuf(sc, txq, bf_head); 1351 ath_tx_txqaddbuf(sc, txctl->txq, bf_head);
1352
1438 return 0; 1353 return 0;
1439} 1354}
1440 1355
@@ -1455,7 +1370,6 @@ static u32 ath_lookup_rate(struct ath_softc *sc,
1455 u16 aggr_limit, legacy = 0, maxampdu; 1370 u16 aggr_limit, legacy = 0, maxampdu;
1456 int i; 1371 int i;
1457 1372
1458
1459 skb = (struct sk_buff *)bf->bf_mpdu; 1373 skb = (struct sk_buff *)bf->bf_mpdu;
1460 tx_info = IEEE80211_SKB_CB(skb); 1374 tx_info = IEEE80211_SKB_CB(skb);
1461 tx_info_priv = (struct ath_tx_info_priv *) 1375 tx_info_priv = (struct ath_tx_info_priv *)
@@ -1795,8 +1709,8 @@ static void ath_tx_sched_aggr(struct ath_softc *sc,
1795 1709
1796static void ath_tid_drain(struct ath_softc *sc, 1710static void ath_tid_drain(struct ath_softc *sc,
1797 struct ath_txq *txq, 1711 struct ath_txq *txq,
1798 struct ath_atx_tid *tid, 1712 struct ath_atx_tid *tid)
1799 bool bh_flag) 1713
1800{ 1714{
1801 struct ath_buf *bf; 1715 struct ath_buf *bf;
1802 struct list_head bf_head; 1716 struct list_head bf_head;
@@ -1817,18 +1731,12 @@ static void ath_tid_drain(struct ath_softc *sc,
1817 * do not indicate packets while holding txq spinlock. 1731 * do not indicate packets while holding txq spinlock.
1818 * unlock is intentional here 1732 * unlock is intentional here
1819 */ 1733 */
1820 if (likely(bh_flag)) 1734 spin_unlock(&txq->axq_lock);
1821 spin_unlock_bh(&txq->axq_lock);
1822 else
1823 spin_unlock(&txq->axq_lock);
1824 1735
1825 /* complete this sub-frame */ 1736 /* complete this sub-frame */
1826 ath_tx_complete_buf(sc, bf, &bf_head, 0, 0); 1737 ath_tx_complete_buf(sc, bf, &bf_head, 0, 0);
1827 1738
1828 if (likely(bh_flag)) 1739 spin_lock(&txq->axq_lock);
1829 spin_lock_bh(&txq->axq_lock);
1830 else
1831 spin_lock(&txq->axq_lock);
1832 } 1740 }
1833 1741
1834 /* 1742 /*
@@ -1847,8 +1755,7 @@ static void ath_tid_drain(struct ath_softc *sc,
1847 */ 1755 */
1848 1756
1849static void ath_txq_drain_pending_buffers(struct ath_softc *sc, 1757static void ath_txq_drain_pending_buffers(struct ath_softc *sc,
1850 struct ath_txq *txq, 1758 struct ath_txq *txq)
1851 bool bh_flag)
1852{ 1759{
1853 struct ath_atx_ac *ac, *ac_tmp; 1760 struct ath_atx_ac *ac, *ac_tmp;
1854 struct ath_atx_tid *tid, *tid_tmp; 1761 struct ath_atx_tid *tid, *tid_tmp;
@@ -1859,51 +1766,32 @@ static void ath_txq_drain_pending_buffers(struct ath_softc *sc,
1859 list_for_each_entry_safe(tid, tid_tmp, &ac->tid_q, list) { 1766 list_for_each_entry_safe(tid, tid_tmp, &ac->tid_q, list) {
1860 list_del(&tid->list); 1767 list_del(&tid->list);
1861 tid->sched = false; 1768 tid->sched = false;
1862 ath_tid_drain(sc, txq, tid, bh_flag); 1769 ath_tid_drain(sc, txq, tid);
1863 } 1770 }
1864 } 1771 }
1865} 1772}
1866 1773
1867static int ath_tx_start_dma(struct ath_softc *sc, 1774static void ath_tx_setup_buffer(struct ath_softc *sc, struct ath_buf *bf,
1868 struct sk_buff *skb, 1775 struct sk_buff *skb, struct scatterlist *sg,
1869 struct scatterlist *sg, 1776 struct ath_tx_control *txctl)
1870 u32 n_sg,
1871 struct ath_tx_control *txctl)
1872{ 1777{
1873 struct ath_node *an = txctl->an; 1778 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
1874 struct ath_buf *bf = NULL; 1779 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1875 struct list_head bf_head;
1876 struct ath_desc *ds;
1877 struct ath_hal *ah = sc->sc_ah;
1878 struct ath_txq *txq;
1879 struct ath_tx_info_priv *tx_info_priv; 1780 struct ath_tx_info_priv *tx_info_priv;
1880 struct ath_rc_series *rcs; 1781 struct ath_rc_series *rcs;
1881 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 1782 int hdrlen;
1882 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); 1783 __le16 fc;
1883 __le16 fc = hdr->frame_control;
1884
1885 if (unlikely(txctl->flags & ATH9K_TXDESC_CAB))
1886 txq = sc->sc_cabq;
1887 else
1888 txq = &sc->sc_txq[txctl->qnum];
1889 1784
1890 /* For each sglist entry, allocate an ath_buf for DMA */ 1785 tx_info_priv = (struct ath_tx_info_priv *)tx_info->control.vif;
1891 INIT_LIST_HEAD(&bf_head); 1786 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
1892 spin_lock_bh(&sc->sc_txbuflock); 1787 fc = hdr->frame_control;
1893 if (unlikely(list_empty(&sc->sc_txbuf))) { 1788 rcs = tx_info_priv->rcs;
1894 spin_unlock_bh(&sc->sc_txbuflock);
1895 return -ENOMEM;
1896 }
1897 1789
1898 bf = list_first_entry(&sc->sc_txbuf, struct ath_buf, list); 1790 ATH_TXBUF_RESET(bf);
1899 list_del(&bf->list);
1900 spin_unlock_bh(&sc->sc_txbuflock);
1901 1791
1902 list_add_tail(&bf->list, &bf_head); 1792 /* Frame type */
1903 1793
1904 /* set up this buffer */ 1794 bf->bf_frmlen = skb->len + FCS_LEN - (hdrlen & 3);
1905 ATH_TXBUF_RESET(bf);
1906 bf->bf_frmlen = txctl->frmlen;
1907 1795
1908 ieee80211_is_data(fc) ? 1796 ieee80211_is_data(fc) ?
1909 (bf->bf_state.bf_type |= BUF_DATA) : 1797 (bf->bf_state.bf_type |= BUF_DATA) :
@@ -1917,121 +1805,142 @@ static int ath_tx_start_dma(struct ath_softc *sc,
1917 (sc->sc_flags & SC_OP_PREAMBLE_SHORT) ? 1805 (sc->sc_flags & SC_OP_PREAMBLE_SHORT) ?
1918 (bf->bf_state.bf_type |= BUF_SHORT_PREAMBLE) : 1806 (bf->bf_state.bf_type |= BUF_SHORT_PREAMBLE) :
1919 (bf->bf_state.bf_type &= ~BUF_SHORT_PREAMBLE); 1807 (bf->bf_state.bf_type &= ~BUF_SHORT_PREAMBLE);
1808 (sc->hw->conf.ht.enabled &&
1809 (tx_info->flags & IEEE80211_TX_CTL_AMPDU)) ?
1810 (bf->bf_state.bf_type |= BUF_HT) :
1811 (bf->bf_state.bf_type &= ~BUF_HT);
1812
1813 bf->bf_flags = setup_tx_flags(sc, skb, txctl->txq);
1814
1815 /* Crypto */
1816
1817 bf->bf_keytype = get_hw_crypto_keytype(skb);
1818
1819 if (bf->bf_keytype != ATH9K_KEY_TYPE_CLEAR) {
1820 bf->bf_frmlen += tx_info->control.hw_key->icv_len;
1821 bf->bf_keyix = tx_info->control.hw_key->hw_key_idx;
1822 } else {
1823 bf->bf_keyix = ATH9K_TXKEYIX_INVALID;
1824 }
1825
1826 /* Rate series */
1827
1828 setup_rate_retries(sc, skb);
1920 1829
1921 bf->bf_flags = txctl->flags;
1922 bf->bf_keytype = txctl->keytype;
1923 /* XXX: HACK! */
1924 tx_info_priv = (struct ath_tx_info_priv *)tx_info->control.vif;
1925 rcs = tx_info_priv->rcs;
1926 bf->bf_rcs[0] = rcs[0]; 1830 bf->bf_rcs[0] = rcs[0];
1927 bf->bf_rcs[1] = rcs[1]; 1831 bf->bf_rcs[1] = rcs[1];
1928 bf->bf_rcs[2] = rcs[2]; 1832 bf->bf_rcs[2] = rcs[2];
1929 bf->bf_rcs[3] = rcs[3]; 1833 bf->bf_rcs[3] = rcs[3];
1930 bf->bf_node = an; 1834
1835 /* Assign seqno, tidno */
1836
1837 if (bf_isht(bf) && (sc->sc_flags & SC_OP_TXAGGR))
1838 assign_aggr_tid_seqno(skb, bf);
1839
1840 /* DMA setup */
1841
1931 bf->bf_mpdu = skb; 1842 bf->bf_mpdu = skb;
1932 bf->bf_buf_addr = sg_dma_address(sg); 1843 bf->bf_dmacontext = pci_map_single(sc->pdev, skb->data,
1844 skb->len, PCI_DMA_TODEVICE);
1845 bf->bf_buf_addr = bf->bf_dmacontext;
1846}
1847
1848/* FIXME: tx power */
1849static void ath_tx_start_dma(struct ath_softc *sc, struct ath_buf *bf,
1850 struct scatterlist *sg, u32 n_sg,
1851 struct ath_tx_control *txctl)
1852{
1853 struct sk_buff *skb = (struct sk_buff *)bf->bf_mpdu;
1854 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
1855 struct ath_node *an = NULL;
1856 struct list_head bf_head;
1857 struct ath_desc *ds;
1858 struct ath_atx_tid *tid;
1859 struct ath_hal *ah = sc->sc_ah;
1860 int frm_type;
1861
1862 frm_type = get_hw_packet_type(skb);
1863
1864 INIT_LIST_HEAD(&bf_head);
1865 list_add_tail(&bf->list, &bf_head);
1933 1866
1934 /* setup descriptor */ 1867 /* setup descriptor */
1868
1935 ds = bf->bf_desc; 1869 ds = bf->bf_desc;
1936 ds->ds_link = 0; 1870 ds->ds_link = 0;
1937 ds->ds_data = bf->bf_buf_addr; 1871 ds->ds_data = bf->bf_buf_addr;
1938 1872
1939 /* 1873 /* Formulate first tx descriptor with tx controls */
1940 * Save the DMA context in the first ath_buf
1941 */
1942 bf->bf_dmacontext = txctl->dmacontext;
1943 1874
1944 /* 1875 ath9k_hw_set11n_txdesc(ah, ds, bf->bf_frmlen, frm_type, MAX_RATE_POWER,
1945 * Formulate first tx descriptor with tx controls. 1876 bf->bf_keyix, bf->bf_keytype, bf->bf_flags);
1946 */ 1877
1947 ath9k_hw_set11n_txdesc(ah, 1878 ath9k_hw_filltxdesc(ah, ds,
1948 ds, 1879 sg_dma_len(sg), /* segment length */
1949 bf->bf_frmlen, /* frame length */ 1880 true, /* first segment */
1950 txctl->atype, /* Atheros packet type */ 1881 (n_sg == 1) ? true : false, /* last segment */
1951 min(txctl->txpower, (u16)60), /* txpower */ 1882 ds); /* first descriptor */
1952 txctl->keyix, /* key cache index */
1953 txctl->keytype, /* key type */
1954 txctl->flags); /* flags */
1955 ath9k_hw_filltxdesc(ah,
1956 ds,
1957 sg_dma_len(sg), /* segment length */
1958 true, /* first segment */
1959 (n_sg == 1) ? true : false, /* last segment */
1960 ds); /* first descriptor */
1961 1883
1962 bf->bf_lastfrm = bf; 1884 bf->bf_lastfrm = bf;
1963 (txctl->ht) ?
1964 (bf->bf_state.bf_type |= BUF_HT) :
1965 (bf->bf_state.bf_type &= ~BUF_HT);
1966 1885
1967 spin_lock_bh(&txq->axq_lock); 1886 spin_lock_bh(&txctl->txq->axq_lock);
1887
1888 if (bf_isht(bf) && (sc->sc_flags & SC_OP_TXAGGR) &&
1889 tx_info->control.sta) {
1890 an = (struct ath_node *)tx_info->control.sta->drv_priv;
1891 tid = ATH_AN_2_TID(an, bf->bf_tidno);
1968 1892
1969 if (txctl->ht && (sc->sc_flags & SC_OP_TXAGGR)) { 1893 if (ath_aggr_query(sc, an, bf->bf_tidno)) {
1970 struct ath_atx_tid *tid = ATH_AN_2_TID(an, txctl->tidno);
1971 if (ath_aggr_query(sc, an, txctl->tidno)) {
1972 /* 1894 /*
1973 * Try aggregation if it's a unicast data frame 1895 * Try aggregation if it's a unicast data frame
1974 * and the destination is HT capable. 1896 * and the destination is HT capable.
1975 */ 1897 */
1976 ath_tx_send_ampdu(sc, txq, tid, &bf_head, txctl); 1898 ath_tx_send_ampdu(sc, tid, &bf_head, txctl);
1977 } else { 1899 } else {
1978 /* 1900 /*
1979 * Send this frame as regular when ADDBA exchange 1901 * Send this frame as regular when ADDBA
1980 * is neither complete nor pending. 1902 * exchange is neither complete nor pending.
1981 */ 1903 */
1982 ath_tx_send_normal(sc, txq, tid, &bf_head); 1904 ath_tx_send_normal(sc, txctl->txq,
1905 tid, &bf_head);
1983 } 1906 }
1984 } else { 1907 } else {
1985 bf->bf_lastbf = bf; 1908 bf->bf_lastbf = bf;
1986 bf->bf_nframes = 1; 1909 bf->bf_nframes = 1;
1987 ath_buf_set_rate(sc, bf);
1988
1989 if (ieee80211_is_back_req(fc)) {
1990 /* This is required for resuming tid
1991 * during BAR completion */
1992 bf->bf_tidno = txctl->tidno;
1993 }
1994 1910
1995 ath_tx_txqaddbuf(sc, txq, &bf_head); 1911 ath_buf_set_rate(sc, bf);
1912 ath_tx_txqaddbuf(sc, txctl->txq, &bf_head);
1996 } 1913 }
1997 spin_unlock_bh(&txq->axq_lock); 1914
1998 return 0; 1915 spin_unlock_bh(&txctl->txq->axq_lock);
1999} 1916}
2000 1917
2001static void xmit_map_sg(struct ath_softc *sc, 1918int ath_tx_start(struct ath_softc *sc, struct sk_buff *skb,
2002 struct sk_buff *skb, 1919 struct ath_tx_control *txctl)
2003 struct ath_tx_control *txctl)
2004{ 1920{
2005 struct ath_xmit_status tx_status; 1921 struct ath_buf *bf;
2006 struct ath_atx_tid *tid;
2007 struct scatterlist sg; 1922 struct scatterlist sg;
2008 1923
2009 txctl->dmacontext = pci_map_single(sc->pdev, skb->data, 1924 /* Check if a tx buffer is available */
2010 skb->len, PCI_DMA_TODEVICE); 1925
1926 bf = ath_tx_get_buffer(sc);
1927 if (!bf) {
1928 DPRINTF(sc, ATH_DBG_XMIT, "%s: TX buffers are full\n",
1929 __func__);
1930 return -1;
1931 }
1932
1933 ath_tx_setup_buffer(sc, bf, skb, &sg, txctl);
1934
1935 /* Setup S/G */
2011 1936
2012 /* setup S/G list */
2013 memset(&sg, 0, sizeof(struct scatterlist)); 1937 memset(&sg, 0, sizeof(struct scatterlist));
2014 sg_dma_address(&sg) = txctl->dmacontext; 1938 sg_dma_address(&sg) = bf->bf_dmacontext;
2015 sg_dma_len(&sg) = skb->len; 1939 sg_dma_len(&sg) = skb->len;
2016 1940
2017 if (ath_tx_start_dma(sc, skb, &sg, 1, txctl) != 0) { 1941 ath_tx_start_dma(sc, bf, &sg, 1, txctl);
2018 /*
2019 * We have to do drop frame here.
2020 */
2021 pci_unmap_single(sc->pdev, txctl->dmacontext,
2022 skb->len, PCI_DMA_TODEVICE);
2023
2024 tx_status.retries = 0;
2025 tx_status.flags = ATH_TX_ERROR;
2026 1942
2027 if (txctl->ht && (sc->sc_flags & SC_OP_TXAGGR)) { 1943 return 0;
2028 /* Reclaim the seqno. */
2029 tid = ATH_AN_2_TID((struct ath_node *)
2030 txctl->an, txctl->tidno);
2031 DECR(tid->seq_next, IEEE80211_SEQ_MAX);
2032 }
2033 ath_tx_complete(sc, skb, &tx_status, txctl->an);
2034 }
2035} 1944}
2036 1945
2037/* Initialize TX queue and h/w */ 1946/* Initialize TX queue and h/w */
@@ -2217,6 +2126,34 @@ int ath_tx_get_qnum(struct ath_softc *sc, int qtype, int haltype)
2217 return qnum; 2126 return qnum;
2218} 2127}
2219 2128
2129/* Get a transmit queue, if available */
2130
2131struct ath_txq *ath_test_get_txq(struct ath_softc *sc, struct sk_buff *skb)
2132{
2133 struct ath_txq *txq = NULL;
2134 int qnum;
2135
2136 qnum = ath_get_hal_qnum(skb_get_queue_mapping(skb), sc);
2137 txq = &sc->sc_txq[qnum];
2138
2139 spin_lock_bh(&txq->axq_lock);
2140
2141 /* Try to avoid running out of descriptors */
2142 if (txq->axq_depth >= (ATH_TXBUF - 20)) {
2143 DPRINTF(sc, ATH_DBG_FATAL,
2144 "%s: TX queue: %d is full, depth: %d\n",
2145 __func__, qnum, txq->axq_depth);
2146 ieee80211_stop_queue(sc->hw, skb_get_queue_mapping(skb));
2147 txq->stopped = 1;
2148 spin_unlock_bh(&txq->axq_lock);
2149 return NULL;
2150 }
2151
2152 spin_unlock_bh(&txq->axq_lock);
2153
2154 return txq;
2155}
2156
2220/* Update parameters for a transmit queue */ 2157/* Update parameters for a transmit queue */
2221 2158
2222int ath_txq_update(struct ath_softc *sc, int qnum, 2159int ath_txq_update(struct ath_softc *sc, int qnum,
@@ -2280,27 +2217,6 @@ int ath_cabq_update(struct ath_softc *sc)
2280 return 0; 2217 return 0;
2281} 2218}
2282 2219
2283int ath_tx_start(struct ath_softc *sc, struct sk_buff *skb)
2284{
2285 struct ath_tx_control txctl;
2286 int error = 0;
2287
2288 memset(&txctl, 0, sizeof(struct ath_tx_control));
2289 error = ath_tx_prepare(sc, skb, &txctl);
2290 if (error == 0)
2291 /*
2292 * Start DMA mapping.
2293 * ath_tx_start_dma() will be called either synchronously
2294 * or asynchrounsly once DMA is complete.
2295 */
2296 xmit_map_sg(sc, skb, &txctl);
2297 else
2298 ath_node_put(sc, txctl.an, ATH9K_BH_STATUS_CHANGE);
2299
2300 /* failed packets will be dropped by the caller */
2301 return error;
2302}
2303
2304/* Deferred processing of transmit interrupt */ 2220/* Deferred processing of transmit interrupt */
2305 2221
2306void ath_tx_tasklet(struct ath_softc *sc) 2222void ath_tx_tasklet(struct ath_softc *sc)
@@ -2374,8 +2290,7 @@ void ath_tx_draintxq(struct ath_softc *sc,
2374 if (sc->sc_flags & SC_OP_TXAGGR) { 2290 if (sc->sc_flags & SC_OP_TXAGGR) {
2375 if (!retry_tx) { 2291 if (!retry_tx) {
2376 spin_lock_bh(&txq->axq_lock); 2292 spin_lock_bh(&txq->axq_lock);
2377 ath_txq_drain_pending_buffers(sc, txq, 2293 ath_txq_drain_pending_buffers(sc, txq);
2378 ATH9K_BH_STATUS_CHANGE);
2379 spin_unlock_bh(&txq->axq_lock); 2294 spin_unlock_bh(&txq->axq_lock);
2380 } 2295 }
2381 } 2296 }
@@ -2406,63 +2321,39 @@ u32 ath_txq_aggr_depth(struct ath_softc *sc, int qnum)
2406 return sc->sc_txq[qnum].axq_aggr_depth; 2321 return sc->sc_txq[qnum].axq_aggr_depth;
2407} 2322}
2408 2323
2409/* Check if an ADDBA is required. A valid node must be passed. */ 2324bool ath_tx_aggr_check(struct ath_softc *sc, struct ath_node *an, u8 tidno)
2410enum ATH_AGGR_CHECK ath_tx_aggr_check(struct ath_softc *sc,
2411 struct ath_node *an,
2412 u8 tidno)
2413{ 2325{
2414 struct ath_atx_tid *txtid; 2326 struct ath_atx_tid *txtid;
2415 2327
2416 if (!(sc->sc_flags & SC_OP_TXAGGR)) 2328 if (!(sc->sc_flags & SC_OP_TXAGGR))
2417 return AGGR_NOT_REQUIRED; 2329 return false;
2418 2330
2419 /* ADDBA exchange must be completed before sending aggregates */
2420 txtid = ATH_AN_2_TID(an, tidno); 2331 txtid = ATH_AN_2_TID(an, tidno);
2421 2332
2422 if (txtid->addba_exchangecomplete) 2333 if (!(txtid->state & AGGR_ADDBA_COMPLETE)) {
2423 return AGGR_EXCHANGE_DONE; 2334 if (!(txtid->state & AGGR_ADDBA_PROGRESS) &&
2424
2425 if (txtid->cleanup_inprogress)
2426 return AGGR_CLEANUP_PROGRESS;
2427
2428 if (txtid->addba_exchangeinprogress)
2429 return AGGR_EXCHANGE_PROGRESS;
2430
2431 if (!txtid->addba_exchangecomplete) {
2432 if (!txtid->addba_exchangeinprogress &&
2433 (txtid->addba_exchangeattempts < ADDBA_EXCHANGE_ATTEMPTS)) { 2335 (txtid->addba_exchangeattempts < ADDBA_EXCHANGE_ATTEMPTS)) {
2434 txtid->addba_exchangeattempts++; 2336 txtid->addba_exchangeattempts++;
2435 return AGGR_REQUIRED; 2337 return true;
2436 } 2338 }
2437 } 2339 }
2438 2340
2439 return AGGR_NOT_REQUIRED; 2341 return false;
2440} 2342}
2441 2343
2442/* Start TX aggregation */ 2344/* Start TX aggregation */
2443 2345
2444int ath_tx_aggr_start(struct ath_softc *sc, 2346int ath_tx_aggr_start(struct ath_softc *sc, struct ieee80211_sta *sta,
2445 const u8 *addr, 2347 u16 tid, u16 *ssn)
2446 u16 tid,
2447 u16 *ssn)
2448{ 2348{
2449 struct ath_atx_tid *txtid; 2349 struct ath_atx_tid *txtid;
2450 struct ath_node *an; 2350 struct ath_node *an;
2451 2351
2452 spin_lock_bh(&sc->node_lock); 2352 an = (struct ath_node *)sta->drv_priv;
2453 an = ath_node_find(sc, (u8 *) addr);
2454 spin_unlock_bh(&sc->node_lock);
2455
2456 if (!an) {
2457 DPRINTF(sc, ATH_DBG_AGGR,
2458 "%s: Node not found to initialize "
2459 "TX aggregation\n", __func__);
2460 return -1;
2461 }
2462 2353
2463 if (sc->sc_flags & SC_OP_TXAGGR) { 2354 if (sc->sc_flags & SC_OP_TXAGGR) {
2464 txtid = ATH_AN_2_TID(an, tid); 2355 txtid = ATH_AN_2_TID(an, tid);
2465 txtid->addba_exchangeinprogress = 1; 2356 txtid->state |= AGGR_ADDBA_PROGRESS;
2466 ath_tx_pause_tid(sc, txtid); 2357 ath_tx_pause_tid(sc, txtid);
2467 } 2358 }
2468 2359
@@ -2471,24 +2362,31 @@ int ath_tx_aggr_start(struct ath_softc *sc,
2471 2362
2472/* Stop tx aggregation */ 2363/* Stop tx aggregation */
2473 2364
2474int ath_tx_aggr_stop(struct ath_softc *sc, 2365int ath_tx_aggr_stop(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid)
2475 const u8 *addr,
2476 u16 tid)
2477{ 2366{
2367 struct ath_node *an = (struct ath_node *)sta->drv_priv;
2368
2369 ath_tx_aggr_teardown(sc, an, tid);
2370 return 0;
2371}
2372
2373/* Resume tx aggregation */
2374
2375void ath_tx_aggr_resume(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid)
2376{
2377 struct ath_atx_tid *txtid;
2478 struct ath_node *an; 2378 struct ath_node *an;
2479 2379
2480 spin_lock_bh(&sc->node_lock); 2380 an = (struct ath_node *)sta->drv_priv;
2481 an = ath_node_find(sc, (u8 *) addr);
2482 spin_unlock_bh(&sc->node_lock);
2483 2381
2484 if (!an) { 2382 if (sc->sc_flags & SC_OP_TXAGGR) {
2485 DPRINTF(sc, ATH_DBG_AGGR, 2383 txtid = ATH_AN_2_TID(an, tid);
2486 "%s: TX aggr stop for non-existent node\n", __func__); 2384 txtid->baw_size =
2487 return -1; 2385 IEEE80211_MIN_AMPDU_BUF << sta->ht_cap.ampdu_factor;
2386 txtid->state |= AGGR_ADDBA_COMPLETE;
2387 txtid->state &= ~AGGR_ADDBA_PROGRESS;
2388 ath_tx_resume_tid(sc, txtid);
2488 } 2389 }
2489
2490 ath_tx_aggr_teardown(sc, an, tid);
2491 return 0;
2492} 2390}
2493 2391
2494/* 2392/*
@@ -2498,8 +2396,7 @@ int ath_tx_aggr_stop(struct ath_softc *sc,
2498 * - Discard all retry frames from the s/w queue. 2396 * - Discard all retry frames from the s/w queue.
2499 */ 2397 */
2500 2398
2501void ath_tx_aggr_teardown(struct ath_softc *sc, 2399void ath_tx_aggr_teardown(struct ath_softc *sc, struct ath_node *an, u8 tid)
2502 struct ath_node *an, u8 tid)
2503{ 2400{
2504 struct ath_atx_tid *txtid = ATH_AN_2_TID(an, tid); 2401 struct ath_atx_tid *txtid = ATH_AN_2_TID(an, tid);
2505 struct ath_txq *txq = &sc->sc_txq[txtid->ac->qnum]; 2402 struct ath_txq *txq = &sc->sc_txq[txtid->ac->qnum];
@@ -2509,10 +2406,10 @@ void ath_tx_aggr_teardown(struct ath_softc *sc,
2509 2406
2510 DPRINTF(sc, ATH_DBG_AGGR, "%s: teardown TX aggregation\n", __func__); 2407 DPRINTF(sc, ATH_DBG_AGGR, "%s: teardown TX aggregation\n", __func__);
2511 2408
2512 if (txtid->cleanup_inprogress) /* cleanup is in progress */ 2409 if (txtid->state & AGGR_CLEANUP) /* cleanup is in progress */
2513 return; 2410 return;
2514 2411
2515 if (!txtid->addba_exchangecomplete) { 2412 if (!(txtid->state & AGGR_ADDBA_COMPLETE)) {
2516 txtid->addba_exchangeattempts = 0; 2413 txtid->addba_exchangeattempts = 0;
2517 return; 2414 return;
2518 } 2415 }
@@ -2542,9 +2439,9 @@ void ath_tx_aggr_teardown(struct ath_softc *sc,
2542 2439
2543 if (txtid->baw_head != txtid->baw_tail) { 2440 if (txtid->baw_head != txtid->baw_tail) {
2544 spin_unlock_bh(&txq->axq_lock); 2441 spin_unlock_bh(&txq->axq_lock);
2545 txtid->cleanup_inprogress = true; 2442 txtid->state |= AGGR_CLEANUP;
2546 } else { 2443 } else {
2547 txtid->addba_exchangecomplete = 0; 2444 txtid->state &= ~AGGR_ADDBA_COMPLETE;
2548 txtid->addba_exchangeattempts = 0; 2445 txtid->addba_exchangeattempts = 0;
2549 spin_unlock_bh(&txq->axq_lock); 2446 spin_unlock_bh(&txq->axq_lock);
2550 ath_tx_flush_tid(sc, txtid); 2447 ath_tx_flush_tid(sc, txtid);
@@ -2586,10 +2483,8 @@ void ath_txq_schedule(struct ath_softc *sc, struct ath_txq *txq)
2586 if (tid->paused) /* check next tid to keep h/w busy */ 2483 if (tid->paused) /* check next tid to keep h/w busy */
2587 continue; 2484 continue;
2588 2485
2589 if (!(tid->an->an_smmode == ATH_SM_PWRSAV_DYNAMIC) || 2486 if ((txq->axq_depth % 2) == 0)
2590 ((txq->axq_depth % 2) == 0)) {
2591 ath_tx_sched_aggr(sc, txq, tid); 2487 ath_tx_sched_aggr(sc, txq, tid);
2592 }
2593 2488
2594 /* 2489 /*
2595 * add tid to round-robin queue if more frames 2490 * add tid to round-robin queue if more frames
@@ -2620,72 +2515,67 @@ void ath_txq_schedule(struct ath_softc *sc, struct ath_txq *txq)
2620 2515
2621void ath_tx_node_init(struct ath_softc *sc, struct ath_node *an) 2516void ath_tx_node_init(struct ath_softc *sc, struct ath_node *an)
2622{ 2517{
2623 if (sc->sc_flags & SC_OP_TXAGGR) { 2518 struct ath_atx_tid *tid;
2624 struct ath_atx_tid *tid; 2519 struct ath_atx_ac *ac;
2625 struct ath_atx_ac *ac; 2520 int tidno, acno;
2626 int tidno, acno;
2627
2628 an->maxampdu = ATH_AMPDU_LIMIT_DEFAULT;
2629 2521
2630 /* 2522 /*
2631 * Init per tid tx state 2523 * Init per tid tx state
2632 */ 2524 */
2633 for (tidno = 0, tid = &an->an_aggr.tx.tid[tidno]; 2525 for (tidno = 0, tid = &an->an_aggr.tx.tid[tidno];
2634 tidno < WME_NUM_TID; 2526 tidno < WME_NUM_TID;
2635 tidno++, tid++) { 2527 tidno++, tid++) {
2636 tid->an = an; 2528 tid->an = an;
2637 tid->tidno = tidno; 2529 tid->tidno = tidno;
2638 tid->seq_start = tid->seq_next = 0; 2530 tid->seq_start = tid->seq_next = 0;
2639 tid->baw_size = WME_MAX_BA; 2531 tid->baw_size = WME_MAX_BA;
2640 tid->baw_head = tid->baw_tail = 0; 2532 tid->baw_head = tid->baw_tail = 0;
2641 tid->sched = false; 2533 tid->sched = false;
2642 tid->paused = false; 2534 tid->paused = false;
2643 tid->cleanup_inprogress = false; 2535 tid->state &= ~AGGR_CLEANUP;
2644 INIT_LIST_HEAD(&tid->buf_q); 2536 INIT_LIST_HEAD(&tid->buf_q);
2645 2537
2646 acno = TID_TO_WME_AC(tidno); 2538 acno = TID_TO_WME_AC(tidno);
2647 tid->ac = &an->an_aggr.tx.ac[acno]; 2539 tid->ac = &an->an_aggr.tx.ac[acno];
2648 2540
2649 /* ADDBA state */ 2541 /* ADDBA state */
2650 tid->addba_exchangecomplete = 0; 2542 tid->state &= ~AGGR_ADDBA_COMPLETE;
2651 tid->addba_exchangeinprogress = 0; 2543 tid->state &= ~AGGR_ADDBA_PROGRESS;
2652 tid->addba_exchangeattempts = 0; 2544 tid->addba_exchangeattempts = 0;
2653 } 2545 }
2654 2546
2655 /* 2547 /*
2656 * Init per ac tx state 2548 * Init per ac tx state
2657 */ 2549 */
2658 for (acno = 0, ac = &an->an_aggr.tx.ac[acno]; 2550 for (acno = 0, ac = &an->an_aggr.tx.ac[acno];
2659 acno < WME_NUM_AC; acno++, ac++) { 2551 acno < WME_NUM_AC; acno++, ac++) {
2660 ac->sched = false; 2552 ac->sched = false;
2661 INIT_LIST_HEAD(&ac->tid_q); 2553 INIT_LIST_HEAD(&ac->tid_q);
2662 2554
2663 switch (acno) { 2555 switch (acno) {
2664 case WME_AC_BE: 2556 case WME_AC_BE:
2665 ac->qnum = ath_tx_get_qnum(sc, 2557 ac->qnum = ath_tx_get_qnum(sc,
2666 ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_BE); 2558 ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_BE);
2667 break; 2559 break;
2668 case WME_AC_BK: 2560 case WME_AC_BK:
2669 ac->qnum = ath_tx_get_qnum(sc, 2561 ac->qnum = ath_tx_get_qnum(sc,
2670 ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_BK); 2562 ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_BK);
2671 break; 2563 break;
2672 case WME_AC_VI: 2564 case WME_AC_VI:
2673 ac->qnum = ath_tx_get_qnum(sc, 2565 ac->qnum = ath_tx_get_qnum(sc,
2674 ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_VI); 2566 ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_VI);
2675 break; 2567 break;
2676 case WME_AC_VO: 2568 case WME_AC_VO:
2677 ac->qnum = ath_tx_get_qnum(sc, 2569 ac->qnum = ath_tx_get_qnum(sc,
2678 ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_VO); 2570 ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_VO);
2679 break; 2571 break;
2680 }
2681 } 2572 }
2682 } 2573 }
2683} 2574}
2684 2575
2685/* Cleanupthe pending buffers for the node. */ 2576/* Cleanupthe pending buffers for the node. */
2686 2577
2687void ath_tx_node_cleanup(struct ath_softc *sc, 2578void ath_tx_node_cleanup(struct ath_softc *sc, struct ath_node *an)
2688 struct ath_node *an, bool bh_flag)
2689{ 2579{
2690 int i; 2580 int i;
2691 struct ath_atx_ac *ac, *ac_tmp; 2581 struct ath_atx_ac *ac, *ac_tmp;
@@ -2695,10 +2585,7 @@ void ath_tx_node_cleanup(struct ath_softc *sc,
2695 if (ATH_TXQ_SETUP(sc, i)) { 2585 if (ATH_TXQ_SETUP(sc, i)) {
2696 txq = &sc->sc_txq[i]; 2586 txq = &sc->sc_txq[i];
2697 2587
2698 if (likely(bh_flag)) 2588 spin_lock(&txq->axq_lock);
2699 spin_lock_bh(&txq->axq_lock);
2700 else
2701 spin_lock(&txq->axq_lock);
2702 2589
2703 list_for_each_entry_safe(ac, 2590 list_for_each_entry_safe(ac,
2704 ac_tmp, &txq->axq_acq, list) { 2591 ac_tmp, &txq->axq_acq, list) {
@@ -2713,36 +2600,14 @@ void ath_tx_node_cleanup(struct ath_softc *sc,
2713 tid_tmp, &ac->tid_q, list) { 2600 tid_tmp, &ac->tid_q, list) {
2714 list_del(&tid->list); 2601 list_del(&tid->list);
2715 tid->sched = false; 2602 tid->sched = false;
2716 ath_tid_drain(sc, txq, tid, bh_flag); 2603 ath_tid_drain(sc, txq, tid);
2717 tid->addba_exchangecomplete = 0; 2604 tid->state &= ~AGGR_ADDBA_COMPLETE;
2718 tid->addba_exchangeattempts = 0; 2605 tid->addba_exchangeattempts = 0;
2719 tid->cleanup_inprogress = false; 2606 tid->state &= ~AGGR_CLEANUP;
2720 } 2607 }
2721 } 2608 }
2722 2609
2723 if (likely(bh_flag)) 2610 spin_unlock(&txq->axq_lock);
2724 spin_unlock_bh(&txq->axq_lock);
2725 else
2726 spin_unlock(&txq->axq_lock);
2727 }
2728 }
2729}
2730
2731/* Cleanup per node transmit state */
2732
2733void ath_tx_node_free(struct ath_softc *sc, struct ath_node *an)
2734{
2735 if (sc->sc_flags & SC_OP_TXAGGR) {
2736 struct ath_atx_tid *tid;
2737 int tidno, i;
2738
2739 /* Init per tid rx state */
2740 for (tidno = 0, tid = &an->an_aggr.tx.tid[tidno];
2741 tidno < WME_NUM_TID;
2742 tidno++, tid++) {
2743
2744 for (i = 0; i < ATH_TID_MAX_BUFS; i++)
2745 ASSERT(tid->tx_buf[i] == NULL);
2746 } 2611 }
2747 } 2612 }
2748} 2613}
@@ -2753,6 +2618,8 @@ void ath_tx_cabq(struct ath_softc *sc, struct sk_buff *skb)
2753 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 2618 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2754 struct ath_tx_control txctl; 2619 struct ath_tx_control txctl;
2755 2620
2621 memset(&txctl, 0, sizeof(struct ath_tx_control));
2622
2756 /* 2623 /*
2757 * As a temporary workaround, assign seq# here; this will likely need 2624 * As a temporary workaround, assign seq# here; this will likely need
2758 * to be cleaned up to work better with Beacon transmission and virtual 2625 * to be cleaned up to work better with Beacon transmission and virtual
@@ -2780,23 +2647,18 @@ void ath_tx_cabq(struct ath_softc *sc, struct sk_buff *skb)
2780 memmove(skb->data, skb->data + padsize, hdrlen); 2647 memmove(skb->data, skb->data + padsize, hdrlen);
2781 } 2648 }
2782 2649
2650 txctl.txq = sc->sc_cabq;
2651
2783 DPRINTF(sc, ATH_DBG_XMIT, "%s: transmitting CABQ packet, skb: %p\n", 2652 DPRINTF(sc, ATH_DBG_XMIT, "%s: transmitting CABQ packet, skb: %p\n",
2784 __func__, 2653 __func__,
2785 skb); 2654 skb);
2786 2655
2787 memset(&txctl, 0, sizeof(struct ath_tx_control)); 2656 if (ath_tx_start(sc, skb, &txctl) != 0) {
2788 txctl.flags = ATH9K_TXDESC_CAB; 2657 DPRINTF(sc, ATH_DBG_XMIT, "%s: TX failed\n", __func__);
2789 if (ath_tx_prepare(sc, skb, &txctl) == 0) { 2658 goto exit;
2790 /*
2791 * Start DMA mapping.
2792 * ath_tx_start_dma() will be called either synchronously
2793 * or asynchrounsly once DMA is complete.
2794 */
2795 xmit_map_sg(sc, skb, &txctl);
2796 } else {
2797 ath_node_put(sc, txctl.an, ATH9K_BH_STATUS_CHANGE);
2798 DPRINTF(sc, ATH_DBG_XMIT, "%s: TX CABQ failed\n", __func__);
2799 dev_kfree_skb_any(skb);
2800 } 2659 }
2801}
2802 2660
2661 return;
2662exit:
2663 dev_kfree_skb_any(skb);
2664}
diff --git a/drivers/net/wireless/atmel.c b/drivers/net/wireless/atmel.c
index d16931589f81..3962b553fbf1 100644
--- a/drivers/net/wireless/atmel.c
+++ b/drivers/net/wireless/atmel.c
@@ -67,7 +67,7 @@
67#include <linux/moduleparam.h> 67#include <linux/moduleparam.h>
68#include <linux/firmware.h> 68#include <linux/firmware.h>
69#include <linux/jiffies.h> 69#include <linux/jiffies.h>
70#include <net/ieee80211.h> 70#include <linux/ieee80211.h>
71#include "atmel.h" 71#include "atmel.h"
72 72
73#define DRIVER_MAJOR 0 73#define DRIVER_MAJOR 0
@@ -569,7 +569,7 @@ static void atmel_wmem32(struct atmel_private *priv, u16 pos, u32 data);
569static void atmel_command_irq(struct atmel_private *priv); 569static void atmel_command_irq(struct atmel_private *priv);
570static int atmel_validate_channel(struct atmel_private *priv, int channel); 570static int atmel_validate_channel(struct atmel_private *priv, int channel);
571static void atmel_management_frame(struct atmel_private *priv, 571static void atmel_management_frame(struct atmel_private *priv,
572 struct ieee80211_hdr_4addr *header, 572 struct ieee80211_hdr *header,
573 u16 frame_len, u8 rssi); 573 u16 frame_len, u8 rssi);
574static void atmel_management_timer(u_long a); 574static void atmel_management_timer(u_long a);
575static void atmel_send_command(struct atmel_private *priv, int command, 575static void atmel_send_command(struct atmel_private *priv, int command,
@@ -577,7 +577,7 @@ static void atmel_send_command(struct atmel_private *priv, int command,
577static int atmel_send_command_wait(struct atmel_private *priv, int command, 577static int atmel_send_command_wait(struct atmel_private *priv, int command,
578 void *cmd, int cmd_size); 578 void *cmd, int cmd_size);
579static void atmel_transmit_management_frame(struct atmel_private *priv, 579static void atmel_transmit_management_frame(struct atmel_private *priv,
580 struct ieee80211_hdr_4addr *header, 580 struct ieee80211_hdr *header,
581 u8 *body, int body_len); 581 u8 *body, int body_len);
582 582
583static u8 atmel_get_mib8(struct atmel_private *priv, u8 type, u8 index); 583static u8 atmel_get_mib8(struct atmel_private *priv, u8 type, u8 index);
@@ -785,7 +785,7 @@ static int start_tx(struct sk_buff *skb, struct net_device *dev)
785{ 785{
786 static const u8 SNAP_RFC1024[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; 786 static const u8 SNAP_RFC1024[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
787 struct atmel_private *priv = netdev_priv(dev); 787 struct atmel_private *priv = netdev_priv(dev);
788 struct ieee80211_hdr_4addr header; 788 struct ieee80211_hdr header;
789 unsigned long flags; 789 unsigned long flags;
790 u16 buff, frame_ctl, len = (ETH_ZLEN < skb->len) ? skb->len : ETH_ZLEN; 790 u16 buff, frame_ctl, len = (ETH_ZLEN < skb->len) ? skb->len : ETH_ZLEN;
791 791
@@ -823,7 +823,7 @@ static int start_tx(struct sk_buff *skb, struct net_device *dev)
823 823
824 frame_ctl = IEEE80211_FTYPE_DATA; 824 frame_ctl = IEEE80211_FTYPE_DATA;
825 header.duration_id = 0; 825 header.duration_id = 0;
826 header.seq_ctl = 0; 826 header.seq_ctrl = 0;
827 if (priv->wep_is_on) 827 if (priv->wep_is_on)
828 frame_ctl |= IEEE80211_FCTL_PROTECTED; 828 frame_ctl |= IEEE80211_FCTL_PROTECTED;
829 if (priv->operating_mode == IW_MODE_ADHOC) { 829 if (priv->operating_mode == IW_MODE_ADHOC) {
@@ -840,7 +840,7 @@ static int start_tx(struct sk_buff *skb, struct net_device *dev)
840 if (priv->use_wpa) 840 if (priv->use_wpa)
841 memcpy(&header.addr4, SNAP_RFC1024, 6); 841 memcpy(&header.addr4, SNAP_RFC1024, 6);
842 842
843 header.frame_ctl = cpu_to_le16(frame_ctl); 843 header.frame_control = cpu_to_le16(frame_ctl);
844 /* Copy the wireless header into the card */ 844 /* Copy the wireless header into the card */
845 atmel_copy_to_card(dev, buff, (unsigned char *)&header, DATA_FRAME_WS_HEADER_SIZE); 845 atmel_copy_to_card(dev, buff, (unsigned char *)&header, DATA_FRAME_WS_HEADER_SIZE);
846 /* Copy the packet sans its 802.3 header addresses which have been replaced */ 846 /* Copy the packet sans its 802.3 header addresses which have been replaced */
@@ -860,7 +860,7 @@ static int start_tx(struct sk_buff *skb, struct net_device *dev)
860} 860}
861 861
862static void atmel_transmit_management_frame(struct atmel_private *priv, 862static void atmel_transmit_management_frame(struct atmel_private *priv,
863 struct ieee80211_hdr_4addr *header, 863 struct ieee80211_hdr *header,
864 u8 *body, int body_len) 864 u8 *body, int body_len)
865{ 865{
866 u16 buff; 866 u16 buff;
@@ -876,7 +876,7 @@ static void atmel_transmit_management_frame(struct atmel_private *priv,
876} 876}
877 877
878static void fast_rx_path(struct atmel_private *priv, 878static void fast_rx_path(struct atmel_private *priv,
879 struct ieee80211_hdr_4addr *header, 879 struct ieee80211_hdr *header,
880 u16 msdu_size, u16 rx_packet_loc, u32 crc) 880 u16 msdu_size, u16 rx_packet_loc, u32 crc)
881{ 881{
882 /* fast path: unfragmented packet copy directly into skbuf */ 882 /* fast path: unfragmented packet copy directly into skbuf */
@@ -914,7 +914,7 @@ static void fast_rx_path(struct atmel_private *priv,
914 } 914 }
915 915
916 memcpy(skbp, header->addr1, 6); /* destination address */ 916 memcpy(skbp, header->addr1, 6); /* destination address */
917 if (le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_FROMDS) 917 if (le16_to_cpu(header->frame_control) & IEEE80211_FCTL_FROMDS)
918 memcpy(&skbp[6], header->addr3, 6); 918 memcpy(&skbp[6], header->addr3, 6);
919 else 919 else
920 memcpy(&skbp[6], header->addr2, 6); /* source address */ 920 memcpy(&skbp[6], header->addr2, 6); /* source address */
@@ -949,7 +949,7 @@ static int probe_crc(struct atmel_private *priv, u16 packet_loc, u16 msdu_size)
949} 949}
950 950
951static void frag_rx_path(struct atmel_private *priv, 951static void frag_rx_path(struct atmel_private *priv,
952 struct ieee80211_hdr_4addr *header, 952 struct ieee80211_hdr *header,
953 u16 msdu_size, u16 rx_packet_loc, u32 crc, u16 seq_no, 953 u16 msdu_size, u16 rx_packet_loc, u32 crc, u16 seq_no,
954 u8 frag_no, int more_frags) 954 u8 frag_no, int more_frags)
955{ 955{
@@ -957,7 +957,7 @@ static void frag_rx_path(struct atmel_private *priv,
957 u8 source[6]; 957 u8 source[6];
958 struct sk_buff *skb; 958 struct sk_buff *skb;
959 959
960 if (le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_FROMDS) 960 if (le16_to_cpu(header->frame_control) & IEEE80211_FCTL_FROMDS)
961 memcpy(source, header->addr3, 6); 961 memcpy(source, header->addr3, 6);
962 else 962 else
963 memcpy(source, header->addr2, 6); 963 memcpy(source, header->addr2, 6);
@@ -1039,7 +1039,7 @@ static void frag_rx_path(struct atmel_private *priv,
1039static void rx_done_irq(struct atmel_private *priv) 1039static void rx_done_irq(struct atmel_private *priv)
1040{ 1040{
1041 int i; 1041 int i;
1042 struct ieee80211_hdr_4addr header; 1042 struct ieee80211_hdr header;
1043 1043
1044 for (i = 0; 1044 for (i = 0;
1045 atmel_rmem8(priv, atmel_rx(priv, RX_DESC_FLAGS_OFFSET, priv->rx_desc_head)) == RX_DESC_FLAG_VALID && 1045 atmel_rmem8(priv, atmel_rx(priv, RX_DESC_FLAGS_OFFSET, priv->rx_desc_head)) == RX_DESC_FLAG_VALID &&
@@ -1066,10 +1066,10 @@ static void rx_done_irq(struct atmel_private *priv)
1066 goto next; 1066 goto next;
1067 } 1067 }
1068 1068
1069 /* Get header as far as end of seq_ctl */ 1069 /* Get header as far as end of seq_ctrl */
1070 atmel_copy_to_host(priv->dev, (char *)&header, rx_packet_loc, 24); 1070 atmel_copy_to_host(priv->dev, (char *)&header, rx_packet_loc, 24);
1071 frame_ctl = le16_to_cpu(header.frame_ctl); 1071 frame_ctl = le16_to_cpu(header.frame_control);
1072 seq_control = le16_to_cpu(header.seq_ctl); 1072 seq_control = le16_to_cpu(header.seq_ctrl);
1073 1073
1074 /* probe for CRC use here if needed once five packets have 1074 /* probe for CRC use here if needed once five packets have
1075 arrived with the same crc status, we assume we know what's 1075 arrived with the same crc status, we assume we know what's
@@ -1819,7 +1819,7 @@ static int atmel_set_encodeext(struct net_device *dev,
1819 /* Determine and validate the key index */ 1819 /* Determine and validate the key index */
1820 idx = encoding->flags & IW_ENCODE_INDEX; 1820 idx = encoding->flags & IW_ENCODE_INDEX;
1821 if (idx) { 1821 if (idx) {
1822 if (idx < 1 || idx > WEP_KEYS) 1822 if (idx < 1 || idx > 4)
1823 return -EINVAL; 1823 return -EINVAL;
1824 idx--; 1824 idx--;
1825 } else 1825 } else
@@ -1882,7 +1882,7 @@ static int atmel_get_encodeext(struct net_device *dev,
1882 1882
1883 idx = encoding->flags & IW_ENCODE_INDEX; 1883 idx = encoding->flags & IW_ENCODE_INDEX;
1884 if (idx) { 1884 if (idx) {
1885 if (idx < 1 || idx > WEP_KEYS) 1885 if (idx < 1 || idx > 4)
1886 return -EINVAL; 1886 return -EINVAL;
1887 idx--; 1887 idx--;
1888 } else 1888 } else
@@ -2797,7 +2797,7 @@ static void handle_beacon_probe(struct atmel_private *priv, u16 capability,
2797 u8 channel) 2797 u8 channel)
2798{ 2798{
2799 int rejoin = 0; 2799 int rejoin = 0;
2800 int new = capability & MFIE_TYPE_POWER_CONSTRAINT ? 2800 int new = capability & WLAN_CAPABILITY_SHORT_PREAMBLE ?
2801 SHORT_PREAMBLE : LONG_PREAMBLE; 2801 SHORT_PREAMBLE : LONG_PREAMBLE;
2802 2802
2803 if (priv->preamble != new) { 2803 if (priv->preamble != new) {
@@ -2826,19 +2826,19 @@ static void handle_beacon_probe(struct atmel_private *priv, u16 capability,
2826static void send_authentication_request(struct atmel_private *priv, u16 system, 2826static void send_authentication_request(struct atmel_private *priv, u16 system,
2827 u8 *challenge, int challenge_len) 2827 u8 *challenge, int challenge_len)
2828{ 2828{
2829 struct ieee80211_hdr_4addr header; 2829 struct ieee80211_hdr header;
2830 struct auth_body auth; 2830 struct auth_body auth;
2831 2831
2832 header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_AUTH); 2832 header.frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_AUTH);
2833 header.duration_id = cpu_to_le16(0x8000); 2833 header.duration_id = cpu_to_le16(0x8000);
2834 header.seq_ctl = 0; 2834 header.seq_ctrl = 0;
2835 memcpy(header.addr1, priv->CurrentBSSID, 6); 2835 memcpy(header.addr1, priv->CurrentBSSID, 6);
2836 memcpy(header.addr2, priv->dev->dev_addr, 6); 2836 memcpy(header.addr2, priv->dev->dev_addr, 6);
2837 memcpy(header.addr3, priv->CurrentBSSID, 6); 2837 memcpy(header.addr3, priv->CurrentBSSID, 6);
2838 2838
2839 if (priv->wep_is_on && priv->CurrentAuthentTransactionSeqNum != 1) 2839 if (priv->wep_is_on && priv->CurrentAuthentTransactionSeqNum != 1)
2840 /* no WEP for authentication frames with TrSeqNo 1 */ 2840 /* no WEP for authentication frames with TrSeqNo 1 */
2841 header.frame_ctl |= cpu_to_le16(IEEE80211_FCTL_PROTECTED); 2841 header.frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
2842 2842
2843 auth.alg = cpu_to_le16(system); 2843 auth.alg = cpu_to_le16(system);
2844 2844
@@ -2861,7 +2861,7 @@ static void send_association_request(struct atmel_private *priv, int is_reassoc)
2861{ 2861{
2862 u8 *ssid_el_p; 2862 u8 *ssid_el_p;
2863 int bodysize; 2863 int bodysize;
2864 struct ieee80211_hdr_4addr header; 2864 struct ieee80211_hdr header;
2865 struct ass_req_format { 2865 struct ass_req_format {
2866 __le16 capability; 2866 __le16 capability;
2867 __le16 listen_interval; 2867 __le16 listen_interval;
@@ -2874,10 +2874,10 @@ static void send_association_request(struct atmel_private *priv, int is_reassoc)
2874 u8 rates[4]; 2874 u8 rates[4];
2875 } body; 2875 } body;
2876 2876
2877 header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_MGMT | 2877 header.frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2878 (is_reassoc ? IEEE80211_STYPE_REASSOC_REQ : IEEE80211_STYPE_ASSOC_REQ)); 2878 (is_reassoc ? IEEE80211_STYPE_REASSOC_REQ : IEEE80211_STYPE_ASSOC_REQ));
2879 header.duration_id = cpu_to_le16(0x8000); 2879 header.duration_id = cpu_to_le16(0x8000);
2880 header.seq_ctl = 0; 2880 header.seq_ctrl = 0;
2881 2881
2882 memcpy(header.addr1, priv->CurrentBSSID, 6); 2882 memcpy(header.addr1, priv->CurrentBSSID, 6);
2883 memcpy(header.addr2, priv->dev->dev_addr, 6); 2883 memcpy(header.addr2, priv->dev->dev_addr, 6);
@@ -2887,7 +2887,7 @@ static void send_association_request(struct atmel_private *priv, int is_reassoc)
2887 if (priv->wep_is_on) 2887 if (priv->wep_is_on)
2888 body.capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY); 2888 body.capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
2889 if (priv->preamble == SHORT_PREAMBLE) 2889 if (priv->preamble == SHORT_PREAMBLE)
2890 body.capability |= cpu_to_le16(MFIE_TYPE_POWER_CONSTRAINT); 2890 body.capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE);
2891 2891
2892 body.listen_interval = cpu_to_le16(priv->listen_interval * priv->beacon_period); 2892 body.listen_interval = cpu_to_le16(priv->listen_interval * priv->beacon_period);
2893 2893
@@ -2901,10 +2901,10 @@ static void send_association_request(struct atmel_private *priv, int is_reassoc)
2901 bodysize = 12 + priv->SSID_size; 2901 bodysize = 12 + priv->SSID_size;
2902 } 2902 }
2903 2903
2904 ssid_el_p[0] = MFIE_TYPE_SSID; 2904 ssid_el_p[0] = WLAN_EID_SSID;
2905 ssid_el_p[1] = priv->SSID_size; 2905 ssid_el_p[1] = priv->SSID_size;
2906 memcpy(ssid_el_p + 2, priv->SSID, priv->SSID_size); 2906 memcpy(ssid_el_p + 2, priv->SSID, priv->SSID_size);
2907 ssid_el_p[2 + priv->SSID_size] = MFIE_TYPE_RATES; 2907 ssid_el_p[2 + priv->SSID_size] = WLAN_EID_SUPP_RATES;
2908 ssid_el_p[3 + priv->SSID_size] = 4; /* len of suported rates */ 2908 ssid_el_p[3 + priv->SSID_size] = 4; /* len of suported rates */
2909 memcpy(ssid_el_p + 4 + priv->SSID_size, atmel_basic_rates, 4); 2909 memcpy(ssid_el_p + 4 + priv->SSID_size, atmel_basic_rates, 4);
2910 2910
@@ -2912,9 +2912,9 @@ static void send_association_request(struct atmel_private *priv, int is_reassoc)
2912} 2912}
2913 2913
2914static int is_frame_from_current_bss(struct atmel_private *priv, 2914static int is_frame_from_current_bss(struct atmel_private *priv,
2915 struct ieee80211_hdr_4addr *header) 2915 struct ieee80211_hdr *header)
2916{ 2916{
2917 if (le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_FROMDS) 2917 if (le16_to_cpu(header->frame_control) & IEEE80211_FCTL_FROMDS)
2918 return memcmp(header->addr3, priv->CurrentBSSID, 6) == 0; 2918 return memcmp(header->addr3, priv->CurrentBSSID, 6) == 0;
2919 else 2919 else
2920 return memcmp(header->addr2, priv->CurrentBSSID, 6) == 0; 2920 return memcmp(header->addr2, priv->CurrentBSSID, 6) == 0;
@@ -2962,7 +2962,7 @@ static int retrieve_bss(struct atmel_private *priv)
2962} 2962}
2963 2963
2964static void store_bss_info(struct atmel_private *priv, 2964static void store_bss_info(struct atmel_private *priv,
2965 struct ieee80211_hdr_4addr *header, u16 capability, 2965 struct ieee80211_hdr *header, u16 capability,
2966 u16 beacon_period, u8 channel, u8 rssi, u8 ssid_len, 2966 u16 beacon_period, u8 channel, u8 rssi, u8 ssid_len,
2967 u8 *ssid, int is_beacon) 2967 u8 *ssid, int is_beacon)
2968{ 2968{
@@ -3001,7 +3001,7 @@ static void store_bss_info(struct atmel_private *priv,
3001 else if (capability & WLAN_CAPABILITY_ESS) 3001 else if (capability & WLAN_CAPABILITY_ESS)
3002 priv->BSSinfo[index].BSStype =IW_MODE_INFRA; 3002 priv->BSSinfo[index].BSStype =IW_MODE_INFRA;
3003 3003
3004 priv->BSSinfo[index].preamble = capability & MFIE_TYPE_POWER_CONSTRAINT ? 3004 priv->BSSinfo[index].preamble = capability & WLAN_CAPABILITY_SHORT_PREAMBLE ?
3005 SHORT_PREAMBLE : LONG_PREAMBLE; 3005 SHORT_PREAMBLE : LONG_PREAMBLE;
3006} 3006}
3007 3007
@@ -3037,7 +3037,7 @@ static void authenticate(struct atmel_private *priv, u16 frame_len)
3037 } 3037 }
3038 } else if (system == WLAN_AUTH_SHARED_KEY) { 3038 } else if (system == WLAN_AUTH_SHARED_KEY) {
3039 if (trans_seq_no == 0x0002 && 3039 if (trans_seq_no == 0x0002 &&
3040 auth->el_id == MFIE_TYPE_CHALLENGE) { 3040 auth->el_id == WLAN_EID_CHALLENGE) {
3041 send_authentication_request(priv, system, auth->chall_text, auth->chall_text_len); 3041 send_authentication_request(priv, system, auth->chall_text, auth->chall_text_len);
3042 return; 3042 return;
3043 } else if (trans_seq_no == 0x0004) { 3043 } else if (trans_seq_no == 0x0004) {
@@ -3288,12 +3288,12 @@ static void atmel_smooth_qual(struct atmel_private *priv)
3288 3288
3289/* deals with incoming managment frames. */ 3289/* deals with incoming managment frames. */
3290static void atmel_management_frame(struct atmel_private *priv, 3290static void atmel_management_frame(struct atmel_private *priv,
3291 struct ieee80211_hdr_4addr *header, 3291 struct ieee80211_hdr *header,
3292 u16 frame_len, u8 rssi) 3292 u16 frame_len, u8 rssi)
3293{ 3293{
3294 u16 subtype; 3294 u16 subtype;
3295 3295
3296 subtype = le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_STYPE; 3296 subtype = le16_to_cpu(header->frame_control) & IEEE80211_FCTL_STYPE;
3297 switch (subtype) { 3297 switch (subtype) {
3298 case IEEE80211_STYPE_BEACON: 3298 case IEEE80211_STYPE_BEACON:
3299 case IEEE80211_STYPE_PROBE_RESP: 3299 case IEEE80211_STYPE_PROBE_RESP:
diff --git a/drivers/net/wireless/b43/b43.h b/drivers/net/wireless/b43/b43.h
index 427b8203e3f9..a53c378e7484 100644
--- a/drivers/net/wireless/b43/b43.h
+++ b/drivers/net/wireless/b43/b43.h
@@ -718,7 +718,6 @@ struct b43_wldev {
718 718
719 bool bad_frames_preempt; /* Use "Bad Frames Preemption" (default off) */ 719 bool bad_frames_preempt; /* Use "Bad Frames Preemption" (default off) */
720 bool dfq_valid; /* Directed frame queue valid (IBSS PS mode, ATIM) */ 720 bool dfq_valid; /* Directed frame queue valid (IBSS PS mode, ATIM) */
721 bool short_slot; /* TRUE, if short slot timing is enabled. */
722 bool radio_hw_enable; /* saved state of radio hardware enabled state */ 721 bool radio_hw_enable; /* saved state of radio hardware enabled state */
723 bool suspend_in_progress; /* TRUE, if we are in a suspend/resume cycle */ 722 bool suspend_in_progress; /* TRUE, if we are in a suspend/resume cycle */
724 723
diff --git a/drivers/net/wireless/b43/main.c b/drivers/net/wireless/b43/main.c
index 2a599fb772d9..ba7a5ab7fe1d 100644
--- a/drivers/net/wireless/b43/main.c
+++ b/drivers/net/wireless/b43/main.c
@@ -703,13 +703,11 @@ static void b43_set_slot_time(struct b43_wldev *dev, u16 slot_time)
703static void b43_short_slot_timing_enable(struct b43_wldev *dev) 703static void b43_short_slot_timing_enable(struct b43_wldev *dev)
704{ 704{
705 b43_set_slot_time(dev, 9); 705 b43_set_slot_time(dev, 9);
706 dev->short_slot = 1;
707} 706}
708 707
709static void b43_short_slot_timing_disable(struct b43_wldev *dev) 708static void b43_short_slot_timing_disable(struct b43_wldev *dev)
710{ 709{
711 b43_set_slot_time(dev, 20); 710 b43_set_slot_time(dev, 20);
712 dev->short_slot = 0;
713} 711}
714 712
715/* Enable a Generic IRQ. "mask" is the mask of which IRQs to enable. 713/* Enable a Generic IRQ. "mask" is the mask of which IRQs to enable.
@@ -1674,25 +1672,6 @@ static void b43_update_templates(struct b43_wl *wl)
1674 queue_work(wl->hw->workqueue, &wl->beacon_update_trigger); 1672 queue_work(wl->hw->workqueue, &wl->beacon_update_trigger);
1675} 1673}
1676 1674
1677static void b43_set_ssid(struct b43_wldev *dev, const u8 * ssid, u8 ssid_len)
1678{
1679 u32 tmp;
1680 u16 i, len;
1681
1682 len = min((u16) ssid_len, (u16) 0x100);
1683 for (i = 0; i < len; i += sizeof(u32)) {
1684 tmp = (u32) (ssid[i + 0]);
1685 if (i + 1 < len)
1686 tmp |= (u32) (ssid[i + 1]) << 8;
1687 if (i + 2 < len)
1688 tmp |= (u32) (ssid[i + 2]) << 16;
1689 if (i + 3 < len)
1690 tmp |= (u32) (ssid[i + 3]) << 24;
1691 b43_shm_write32(dev, B43_SHM_SHARED, 0x380 + i, tmp);
1692 }
1693 b43_shm_write16(dev, B43_SHM_SHARED, 0x48, len);
1694}
1695
1696static void b43_set_beacon_int(struct b43_wldev *dev, u16 beacon_int) 1675static void b43_set_beacon_int(struct b43_wldev *dev, u16 beacon_int)
1697{ 1676{
1698 b43_time_lock(dev); 1677 b43_time_lock(dev);
@@ -3380,16 +3359,6 @@ static int b43_op_config(struct ieee80211_hw *hw, u32 changed)
3380 if (conf->channel->hw_value != phy->channel) 3359 if (conf->channel->hw_value != phy->channel)
3381 b43_switch_channel(dev, conf->channel->hw_value); 3360 b43_switch_channel(dev, conf->channel->hw_value);
3382 3361
3383 /* Enable/Disable ShortSlot timing. */
3384 if ((!!(conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME)) !=
3385 dev->short_slot) {
3386 B43_WARN_ON(phy->type != B43_PHYTYPE_G);
3387 if (conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME)
3388 b43_short_slot_timing_enable(dev);
3389 else
3390 b43_short_slot_timing_disable(dev);
3391 }
3392
3393 dev->wl->radiotap_enabled = !!(conf->flags & IEEE80211_CONF_RADIOTAP); 3362 dev->wl->radiotap_enabled = !!(conf->flags & IEEE80211_CONF_RADIOTAP);
3394 3363
3395 /* Adjust the desired TX power level. */ 3364 /* Adjust the desired TX power level. */
@@ -3440,6 +3409,104 @@ static int b43_op_config(struct ieee80211_hw *hw, u32 changed)
3440 return err; 3409 return err;
3441} 3410}
3442 3411
3412static void b43_update_basic_rates(struct b43_wldev *dev, u64 brates)
3413{
3414 struct ieee80211_supported_band *sband =
3415 dev->wl->hw->wiphy->bands[b43_current_band(dev->wl)];
3416 struct ieee80211_rate *rate;
3417 int i;
3418 u16 basic, direct, offset, basic_offset, rateptr;
3419
3420 for (i = 0; i < sband->n_bitrates; i++) {
3421 rate = &sband->bitrates[i];
3422
3423 if (b43_is_cck_rate(rate->hw_value)) {
3424 direct = B43_SHM_SH_CCKDIRECT;
3425 basic = B43_SHM_SH_CCKBASIC;
3426 offset = b43_plcp_get_ratecode_cck(rate->hw_value);
3427 offset &= 0xF;
3428 } else {
3429 direct = B43_SHM_SH_OFDMDIRECT;
3430 basic = B43_SHM_SH_OFDMBASIC;
3431 offset = b43_plcp_get_ratecode_ofdm(rate->hw_value);
3432 offset &= 0xF;
3433 }
3434
3435 rate = ieee80211_get_response_rate(sband, brates, rate->bitrate);
3436
3437 if (b43_is_cck_rate(rate->hw_value)) {
3438 basic_offset = b43_plcp_get_ratecode_cck(rate->hw_value);
3439 basic_offset &= 0xF;
3440 } else {
3441 basic_offset = b43_plcp_get_ratecode_ofdm(rate->hw_value);
3442 basic_offset &= 0xF;
3443 }
3444
3445 /*
3446 * Get the pointer that we need to point to
3447 * from the direct map
3448 */
3449 rateptr = b43_shm_read16(dev, B43_SHM_SHARED,
3450 direct + 2 * basic_offset);
3451 /* and write it to the basic map */
3452 b43_shm_write16(dev, B43_SHM_SHARED, basic + 2 * offset,
3453 rateptr);
3454 }
3455}
3456
3457static void b43_op_bss_info_changed(struct ieee80211_hw *hw,
3458 struct ieee80211_vif *vif,
3459 struct ieee80211_bss_conf *conf,
3460 u32 changed)
3461{
3462 struct b43_wl *wl = hw_to_b43_wl(hw);
3463 struct b43_wldev *dev;
3464 struct b43_phy *phy;
3465 unsigned long flags;
3466 u32 savedirqs;
3467
3468 mutex_lock(&wl->mutex);
3469
3470 dev = wl->current_dev;
3471 phy = &dev->phy;
3472
3473 /* Disable IRQs while reconfiguring the device.
3474 * This makes it possible to drop the spinlock throughout
3475 * the reconfiguration process. */
3476 spin_lock_irqsave(&wl->irq_lock, flags);
3477 if (b43_status(dev) < B43_STAT_STARTED) {
3478 spin_unlock_irqrestore(&wl->irq_lock, flags);
3479 goto out_unlock_mutex;
3480 }
3481 savedirqs = b43_interrupt_disable(dev, B43_IRQ_ALL);
3482 spin_unlock_irqrestore(&wl->irq_lock, flags);
3483 b43_synchronize_irq(dev);
3484
3485 b43_mac_suspend(dev);
3486
3487 if (changed & BSS_CHANGED_BASIC_RATES)
3488 b43_update_basic_rates(dev, conf->basic_rates);
3489
3490 if (changed & BSS_CHANGED_ERP_SLOT) {
3491 if (conf->use_short_slot)
3492 b43_short_slot_timing_enable(dev);
3493 else
3494 b43_short_slot_timing_disable(dev);
3495 }
3496
3497 b43_mac_enable(dev);
3498
3499 spin_lock_irqsave(&wl->irq_lock, flags);
3500 b43_interrupt_enable(dev, savedirqs);
3501 /* XXX: why? */
3502 mmiowb();
3503 spin_unlock_irqrestore(&wl->irq_lock, flags);
3504 out_unlock_mutex:
3505 mutex_unlock(&wl->mutex);
3506
3507 return;
3508}
3509
3443static int b43_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, 3510static int b43_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3444 const u8 *local_addr, const u8 *addr, 3511 const u8 *local_addr, const u8 *addr,
3445 struct ieee80211_key_conf *key) 3512 struct ieee80211_key_conf *key)
@@ -3602,8 +3669,6 @@ static int b43_op_config_interface(struct ieee80211_hw *hw,
3602 if (b43_is_mode(wl, NL80211_IFTYPE_AP) || 3669 if (b43_is_mode(wl, NL80211_IFTYPE_AP) ||
3603 b43_is_mode(wl, NL80211_IFTYPE_MESH_POINT)) { 3670 b43_is_mode(wl, NL80211_IFTYPE_MESH_POINT)) {
3604 B43_WARN_ON(vif->type != wl->if_type); 3671 B43_WARN_ON(vif->type != wl->if_type);
3605 if (conf->changed & IEEE80211_IFCC_SSID)
3606 b43_set_ssid(dev, conf->ssid, conf->ssid_len);
3607 if (conf->changed & IEEE80211_IFCC_BEACON) 3672 if (conf->changed & IEEE80211_IFCC_BEACON)
3608 b43_update_templates(wl); 3673 b43_update_templates(wl);
3609 } else if (b43_is_mode(wl, NL80211_IFTYPE_ADHOC)) { 3674 } else if (b43_is_mode(wl, NL80211_IFTYPE_ADHOC)) {
@@ -4231,6 +4296,7 @@ static const struct ieee80211_ops b43_hw_ops = {
4231 .add_interface = b43_op_add_interface, 4296 .add_interface = b43_op_add_interface,
4232 .remove_interface = b43_op_remove_interface, 4297 .remove_interface = b43_op_remove_interface,
4233 .config = b43_op_config, 4298 .config = b43_op_config,
4299 .bss_info_changed = b43_op_bss_info_changed,
4234 .config_interface = b43_op_config_interface, 4300 .config_interface = b43_op_config_interface,
4235 .configure_filter = b43_op_configure_filter, 4301 .configure_filter = b43_op_configure_filter,
4236 .set_key = b43_op_set_key, 4302 .set_key = b43_op_set_key,
diff --git a/drivers/net/wireless/b43legacy/dma.c b/drivers/net/wireless/b43legacy/dma.c
index 308c2647f002..3649fc367098 100644
--- a/drivers/net/wireless/b43legacy/dma.c
+++ b/drivers/net/wireless/b43legacy/dma.c
@@ -919,7 +919,7 @@ struct b43legacy_dmaring *b43legacy_setup_dmaring(struct b43legacy_wldev *dev,
919 if (!ring->txhdr_cache) 919 if (!ring->txhdr_cache)
920 goto err_kfree_meta; 920 goto err_kfree_meta;
921 921
922 dma_test = ssb_dma_map_single(dev->dev, 922 dma_test = ssb_dma_map_single(dev->dev,
923 ring->txhdr_cache, 923 ring->txhdr_cache,
924 sizeof(struct b43legacy_txhdr_fw3), 924 sizeof(struct b43legacy_txhdr_fw3),
925 DMA_TO_DEVICE); 925 DMA_TO_DEVICE);
diff --git a/drivers/net/wireless/b43legacy/main.c b/drivers/net/wireless/b43legacy/main.c
index 9edbdf9cb50f..6c8eb4d2519a 100644
--- a/drivers/net/wireless/b43legacy/main.c
+++ b/drivers/net/wireless/b43legacy/main.c
@@ -1160,29 +1160,6 @@ static void b43legacy_update_templates(struct b43legacy_wl *wl)
1160 wl->beacon1_uploaded = 0; 1160 wl->beacon1_uploaded = 0;
1161} 1161}
1162 1162
1163static void b43legacy_set_ssid(struct b43legacy_wldev *dev,
1164 const u8 *ssid, u8 ssid_len)
1165{
1166 u32 tmp;
1167 u16 i;
1168 u16 len;
1169
1170 len = min((u16)ssid_len, (u16)0x100);
1171 for (i = 0; i < len; i += sizeof(u32)) {
1172 tmp = (u32)(ssid[i + 0]);
1173 if (i + 1 < len)
1174 tmp |= (u32)(ssid[i + 1]) << 8;
1175 if (i + 2 < len)
1176 tmp |= (u32)(ssid[i + 2]) << 16;
1177 if (i + 3 < len)
1178 tmp |= (u32)(ssid[i + 3]) << 24;
1179 b43legacy_shm_write32(dev, B43legacy_SHM_SHARED,
1180 0x380 + i, tmp);
1181 }
1182 b43legacy_shm_write16(dev, B43legacy_SHM_SHARED,
1183 0x48, len);
1184}
1185
1186static void b43legacy_set_beacon_int(struct b43legacy_wldev *dev, 1163static void b43legacy_set_beacon_int(struct b43legacy_wldev *dev,
1187 u16 beacon_int) 1164 u16 beacon_int)
1188{ 1165{
@@ -2744,7 +2721,6 @@ static int b43legacy_op_config_interface(struct ieee80211_hw *hw,
2744 if (b43legacy_status(dev) >= B43legacy_STAT_INITIALIZED) { 2721 if (b43legacy_status(dev) >= B43legacy_STAT_INITIALIZED) {
2745 if (b43legacy_is_mode(wl, NL80211_IFTYPE_AP)) { 2722 if (b43legacy_is_mode(wl, NL80211_IFTYPE_AP)) {
2746 B43legacy_WARN_ON(vif->type != NL80211_IFTYPE_AP); 2723 B43legacy_WARN_ON(vif->type != NL80211_IFTYPE_AP);
2747 b43legacy_set_ssid(dev, conf->ssid, conf->ssid_len);
2748 if (conf->changed & IEEE80211_IFCC_BEACON) 2724 if (conf->changed & IEEE80211_IFCC_BEACON)
2749 b43legacy_update_templates(wl); 2725 b43legacy_update_templates(wl);
2750 } else if (b43legacy_is_mode(wl, NL80211_IFTYPE_ADHOC)) { 2726 } else if (b43legacy_is_mode(wl, NL80211_IFTYPE_ADHOC)) {
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945.h b/drivers/net/wireless/iwlwifi/iwl-3945.h
index 592c5958723b..7187925bd0d5 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945.h
+++ b/drivers/net/wireless/iwlwifi/iwl-3945.h
@@ -828,8 +828,6 @@ struct iwl3945_priv {
828 unsigned long last_statistics_time; 828 unsigned long last_statistics_time;
829 829
830 /* context information */ 830 /* context information */
831 u8 essid[IW_ESSID_MAX_SIZE];
832 u8 essid_len;
833 u16 rates_mask; 831 u16 rates_mask;
834 832
835 u32 power_mode; 833 u32 power_mode;
diff --git a/drivers/net/wireless/iwlwifi/iwl-4965.c b/drivers/net/wireless/iwlwifi/iwl-4965.c
index 0953a9c56807..157cad4e9da0 100644
--- a/drivers/net/wireless/iwlwifi/iwl-4965.c
+++ b/drivers/net/wireless/iwlwifi/iwl-4965.c
@@ -2323,7 +2323,7 @@ static struct iwl_lib_ops iwl4965_lib = {
2323 .reset = iwl4965_apm_reset, 2323 .reset = iwl4965_apm_reset,
2324 .stop = iwl4965_apm_stop, 2324 .stop = iwl4965_apm_stop,
2325 .config = iwl4965_nic_config, 2325 .config = iwl4965_nic_config,
2326 .set_pwr_src = iwl4965_set_pwr_src, 2326 .set_pwr_src = iwl_set_pwr_src,
2327 }, 2327 },
2328 .eeprom_ops = { 2328 .eeprom_ops = {
2329 .regulatory_bands = { 2329 .regulatory_bands = {
@@ -2342,7 +2342,7 @@ static struct iwl_lib_ops iwl4965_lib = {
2342 .query_addr = iwlcore_eeprom_query_addr, 2342 .query_addr = iwlcore_eeprom_query_addr,
2343 }, 2343 },
2344 .send_tx_power = iwl4965_send_tx_power, 2344 .send_tx_power = iwl4965_send_tx_power,
2345 .update_chain_flags = iwl4965_update_chain_flags, 2345 .update_chain_flags = iwl_update_chain_flags,
2346 .temperature = iwl4965_temperature_calib, 2346 .temperature = iwl4965_temperature_calib,
2347}; 2347};
2348 2348
diff --git a/drivers/net/wireless/iwlwifi/iwl-5000.c b/drivers/net/wireless/iwlwifi/iwl-5000.c
index 4348c7db3d1f..31e62a838ad4 100644
--- a/drivers/net/wireless/iwlwifi/iwl-5000.c
+++ b/drivers/net/wireless/iwlwifi/iwl-5000.c
@@ -535,7 +535,7 @@ static int iwl5000_load_section(struct iwl_priv *priv,
535 iwl_write_direct32(priv, 535 iwl_write_direct32(priv,
536 FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL), 536 FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL),
537 FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE | 537 FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
538 FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_DISABLE_VAL | 538 FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_DISABLE |
539 FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_ENDTFD); 539 FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_ENDTFD);
540 540
541 iwl_release_nic_access(priv); 541 iwl_release_nic_access(priv);
@@ -549,14 +549,13 @@ static int iwl5000_load_given_ucode(struct iwl_priv *priv,
549{ 549{
550 int ret = 0; 550 int ret = 0;
551 551
552 ret = iwl5000_load_section( 552 ret = iwl5000_load_section(priv, inst_image, RTC_INST_LOWER_BOUND);
553 priv, inst_image, RTC_INST_LOWER_BOUND);
554 if (ret) 553 if (ret)
555 return ret; 554 return ret;
556 555
557 IWL_DEBUG_INFO("INST uCode section being loaded...\n"); 556 IWL_DEBUG_INFO("INST uCode section being loaded...\n");
558 ret = wait_event_interruptible_timeout(priv->wait_command_queue, 557 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
559 priv->ucode_write_complete, 5 * HZ); 558 priv->ucode_write_complete, 5 * HZ);
560 if (ret == -ERESTARTSYS) { 559 if (ret == -ERESTARTSYS) {
561 IWL_ERROR("Could not load the INST uCode section due " 560 IWL_ERROR("Could not load the INST uCode section due "
562 "to interrupt\n"); 561 "to interrupt\n");
@@ -753,6 +752,7 @@ static int iwl5000_alive_notify(struct iwl_priv *priv)
753 priv->cfg->ops->lib->txq_set_sched(priv, IWL_MASK(0, 7)); 752 priv->cfg->ops->lib->txq_set_sched(priv, IWL_MASK(0, 7));
754 753
755 iwl5000_set_wr_ptrs(priv, IWL_CMD_QUEUE_NUM, 0); 754 iwl5000_set_wr_ptrs(priv, IWL_CMD_QUEUE_NUM, 0);
755
756 /* map qos queues to fifos one-to-one */ 756 /* map qos queues to fifos one-to-one */
757 for (i = 0; i < ARRAY_SIZE(iwl5000_default_queue_to_tx_fifo); i++) { 757 for (i = 0; i < ARRAY_SIZE(iwl5000_default_queue_to_tx_fifo); i++) {
758 int ac = iwl5000_default_queue_to_tx_fifo[i]; 758 int ac = iwl5000_default_queue_to_tx_fifo[i];
@@ -1474,13 +1474,13 @@ static struct iwl_lib_ops iwl5000_lib = {
1474 .alive_notify = iwl5000_alive_notify, 1474 .alive_notify = iwl5000_alive_notify,
1475 .send_tx_power = iwl5000_send_tx_power, 1475 .send_tx_power = iwl5000_send_tx_power,
1476 .temperature = iwl5000_temperature, 1476 .temperature = iwl5000_temperature,
1477 .update_chain_flags = iwl4965_update_chain_flags, 1477 .update_chain_flags = iwl_update_chain_flags,
1478 .apm_ops = { 1478 .apm_ops = {
1479 .init = iwl5000_apm_init, 1479 .init = iwl5000_apm_init,
1480 .reset = iwl5000_apm_reset, 1480 .reset = iwl5000_apm_reset,
1481 .stop = iwl5000_apm_stop, 1481 .stop = iwl5000_apm_stop,
1482 .config = iwl5000_nic_config, 1482 .config = iwl5000_nic_config,
1483 .set_pwr_src = iwl4965_set_pwr_src, 1483 .set_pwr_src = iwl_set_pwr_src,
1484 }, 1484 },
1485 .eeprom_ops = { 1485 .eeprom_ops = {
1486 .regulatory_bands = { 1486 .regulatory_bands = {
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
index f5e94b65a7f6..0332805cc630 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
@@ -2071,15 +2071,13 @@ static void rs_initialize_lq(struct iwl_priv *priv,
2071 if ((i < 0) || (i >= IWL_RATE_COUNT)) 2071 if ((i < 0) || (i >= IWL_RATE_COUNT))
2072 i = 0; 2072 i = 0;
2073 2073
2074 /* FIXME:RS: This is also wrong in 4965 */
2075 rate = iwl_rates[i].plcp; 2074 rate = iwl_rates[i].plcp;
2076 rate |= RATE_MCS_ANT_B_MSK; 2075 tbl->ant_type = first_antenna(valid_tx_ant);
2077 rate &= ~RATE_MCS_ANT_A_MSK; 2076 rate |= tbl->ant_type << RATE_MCS_ANT_POS;
2078 2077
2079 if (i >= IWL_FIRST_CCK_RATE && i <= IWL_LAST_CCK_RATE) 2078 if (i >= IWL_FIRST_CCK_RATE && i <= IWL_LAST_CCK_RATE)
2080 rate |= RATE_MCS_CCK_MSK; 2079 rate |= RATE_MCS_CCK_MSK;
2081 2080
2082 tbl->ant_type = ANT_B;
2083 rs_get_tbl_info_from_mcs(rate, priv->band, tbl, &rate_idx); 2081 rs_get_tbl_info_from_mcs(rate, priv->band, tbl, &rate_idx);
2084 if (!rs_is_valid_ant(valid_tx_ant, tbl->ant_type)) 2082 if (!rs_is_valid_ant(valid_tx_ant, tbl->ant_type))
2085 rs_toggle_antenna(valid_tx_ant, &rate, tbl); 2083 rs_toggle_antenna(valid_tx_ant, &rate, tbl);
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-rs.h b/drivers/net/wireless/iwlwifi/iwl-agn-rs.h
index ccfafcfa4767..adcbf538ed54 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-rs.h
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-rs.h
@@ -294,7 +294,7 @@ static inline u8 first_antenna(u8 mask)
294} 294}
295 295
296 296
297static inline u8 iwl4965_get_prev_ieee_rate(u8 rate_index) 297static inline u8 iwl_get_prev_ieee_rate(u8 rate_index)
298{ 298{
299 u8 rate = iwl_rates[rate_index].prev_ieee; 299 u8 rate = iwl_rates[rate_index].prev_ieee;
300 300
@@ -304,11 +304,11 @@ static inline u8 iwl4965_get_prev_ieee_rate(u8 rate_index)
304} 304}
305 305
306/** 306/**
307 * iwl4965_rate_control_register - Register the rate control algorithm callbacks 307 * iwl_rate_control_register - Register the rate control algorithm callbacks
308 * 308 *
309 * Since the rate control algorithm is hardware specific, there is no need 309 * Since the rate control algorithm is hardware specific, there is no need
310 * or reason to place it as a stand alone module. The driver can call 310 * or reason to place it as a stand alone module. The driver can call
311 * iwl4965_rate_control_register in order to register the rate control callbacks 311 * iwl_rate_control_register in order to register the rate control callbacks
312 * with the mac80211 subsystem. This should be performed prior to calling 312 * with the mac80211 subsystem. This should be performed prior to calling
313 * ieee80211_register_hw 313 * ieee80211_register_hw
314 * 314 *
@@ -316,7 +316,7 @@ static inline u8 iwl4965_get_prev_ieee_rate(u8 rate_index)
316extern int iwlagn_rate_control_register(void); 316extern int iwlagn_rate_control_register(void);
317 317
318/** 318/**
319 * iwl4965_rate_control_unregister - Unregister the rate control callbacks 319 * iwl_rate_control_unregister - Unregister the rate control callbacks
320 * 320 *
321 * This should be called after calling ieee80211_unregister_hw, but before 321 * This should be called after calling ieee80211_unregister_hw, but before
322 * the driver is unloaded. 322 * the driver is unloaded.
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.c b/drivers/net/wireless/iwlwifi/iwl-agn.c
index 2c35a017e5f6..8264d3742d08 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn.c
@@ -96,7 +96,7 @@ MODULE_ALIAS("iwl4965");
96 96
97 97
98 98
99static void iwl4965_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt) 99static void iwl_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt)
100{ 100{
101 struct iwl_rxon_cmd *rxon = &priv->staging_rxon; 101 struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
102 102
@@ -108,13 +108,13 @@ static void iwl4965_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt)
108} 108}
109 109
110/** 110/**
111 * iwl4965_check_rxon_cmd - validate RXON structure is valid 111 * iwl_check_rxon_cmd - validate RXON structure is valid
112 * 112 *
113 * NOTE: This is really only useful during development and can eventually 113 * NOTE: This is really only useful during development and can eventually
114 * be #ifdef'd out once the driver is stable and folks aren't actively 114 * be #ifdef'd out once the driver is stable and folks aren't actively
115 * making changes 115 * making changes
116 */ 116 */
117static int iwl4965_check_rxon_cmd(struct iwl_rxon_cmd *rxon) 117static int iwl_check_rxon_cmd(struct iwl_rxon_cmd *rxon)
118{ 118{
119 int error = 0; 119 int error = 0;
120 int counter = 1; 120 int counter = 1;
@@ -174,7 +174,7 @@ static int iwl4965_check_rxon_cmd(struct iwl_rxon_cmd *rxon)
174 le16_to_cpu(rxon->channel)); 174 le16_to_cpu(rxon->channel));
175 175
176 if (error) { 176 if (error) {
177 IWL_ERROR("Not a valid iwl4965_rxon_assoc_cmd field values\n"); 177 IWL_ERROR("Not a valid iwl_rxon_assoc_cmd field values\n");
178 return -1; 178 return -1;
179 } 179 }
180 return 0; 180 return 0;
@@ -228,14 +228,14 @@ static int iwl_full_rxon_required(struct iwl_priv *priv)
228} 228}
229 229
230/** 230/**
231 * iwl4965_commit_rxon - commit staging_rxon to hardware 231 * iwl_commit_rxon - commit staging_rxon to hardware
232 * 232 *
233 * The RXON command in staging_rxon is committed to the hardware and 233 * The RXON command in staging_rxon is committed to the hardware and
234 * the active_rxon structure is updated with the new data. This 234 * the active_rxon structure is updated with the new data. This
235 * function correctly transitions out of the RXON_ASSOC_MSK state if 235 * function correctly transitions out of the RXON_ASSOC_MSK state if
236 * a HW tune is required based on the RXON structure changes. 236 * a HW tune is required based on the RXON structure changes.
237 */ 237 */
238static int iwl4965_commit_rxon(struct iwl_priv *priv) 238static int iwl_commit_rxon(struct iwl_priv *priv)
239{ 239{
240 /* cast away the const for active_rxon in this function */ 240 /* cast away the const for active_rxon in this function */
241 struct iwl_rxon_cmd *active_rxon = (void *)&priv->active_rxon; 241 struct iwl_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
@@ -252,14 +252,14 @@ static int iwl4965_commit_rxon(struct iwl_priv *priv)
252 * 5000, but will not damage 4965 */ 252 * 5000, but will not damage 4965 */
253 priv->staging_rxon.flags |= RXON_FLG_SELF_CTS_EN; 253 priv->staging_rxon.flags |= RXON_FLG_SELF_CTS_EN;
254 254
255 ret = iwl4965_check_rxon_cmd(&priv->staging_rxon); 255 ret = iwl_check_rxon_cmd(&priv->staging_rxon);
256 if (ret) { 256 if (ret) {
257 IWL_ERROR("Invalid RXON configuration. Not committing.\n"); 257 IWL_ERROR("Invalid RXON configuration. Not committing.\n");
258 return -EINVAL; 258 return -EINVAL;
259 } 259 }
260 260
261 /* If we don't need to send a full RXON, we can use 261 /* If we don't need to send a full RXON, we can use
262 * iwl4965_rxon_assoc_cmd which is used to reconfigure filter 262 * iwl_rxon_assoc_cmd which is used to reconfigure filter
263 * and other flags for the current radio configuration. */ 263 * and other flags for the current radio configuration. */
264 if (!iwl_full_rxon_required(priv)) { 264 if (!iwl_full_rxon_required(priv)) {
265 ret = iwl_send_rxon_assoc(priv); 265 ret = iwl_send_rxon_assoc(priv);
@@ -304,7 +304,7 @@ static int iwl4965_commit_rxon(struct iwl_priv *priv)
304 le16_to_cpu(priv->staging_rxon.channel), 304 le16_to_cpu(priv->staging_rxon.channel),
305 priv->staging_rxon.bssid_addr); 305 priv->staging_rxon.bssid_addr);
306 306
307 iwl4965_set_rxon_hwcrypto(priv, !priv->hw_params.sw_crypto); 307 iwl_set_rxon_hwcrypto(priv, !priv->hw_params.sw_crypto);
308 308
309 /* Apply the new configuration 309 /* Apply the new configuration
310 * RXON unassoc clears the station table in uCode, send it before 310 * RXON unassoc clears the station table in uCode, send it before
@@ -374,14 +374,14 @@ static int iwl4965_commit_rxon(struct iwl_priv *priv)
374 return 0; 374 return 0;
375} 375}
376 376
377void iwl4965_update_chain_flags(struct iwl_priv *priv) 377void iwl_update_chain_flags(struct iwl_priv *priv)
378{ 378{
379 379
380 iwl_set_rxon_chain(priv); 380 iwl_set_rxon_chain(priv);
381 iwl4965_commit_rxon(priv); 381 iwl_commit_rxon(priv);
382} 382}
383 383
384static int iwl4965_send_bt_config(struct iwl_priv *priv) 384static int iwl_send_bt_config(struct iwl_priv *priv)
385{ 385{
386 struct iwl4965_bt_cmd bt_cmd = { 386 struct iwl4965_bt_cmd bt_cmd = {
387 .flags = 3, 387 .flags = 3,
@@ -459,7 +459,7 @@ static unsigned int iwl_fill_beacon_frame(struct iwl_priv *priv,
459 return priv->ibss_beacon->len; 459 return priv->ibss_beacon->len;
460} 460}
461 461
462static u8 iwl4965_rate_get_lowest_plcp(struct iwl_priv *priv) 462static u8 iwl_rate_get_lowest_plcp(struct iwl_priv *priv)
463{ 463{
464 int i; 464 int i;
465 int rate_mask; 465 int rate_mask;
@@ -484,7 +484,7 @@ static u8 iwl4965_rate_get_lowest_plcp(struct iwl_priv *priv)
484 return IWL_RATE_6M_PLCP; 484 return IWL_RATE_6M_PLCP;
485} 485}
486 486
487static unsigned int iwl4965_hw_get_beacon_cmd(struct iwl_priv *priv, 487static unsigned int iwl_hw_get_beacon_cmd(struct iwl_priv *priv,
488 struct iwl_frame *frame, u8 rate) 488 struct iwl_frame *frame, u8 rate)
489{ 489{
490 struct iwl_tx_beacon_cmd *tx_beacon_cmd; 490 struct iwl_tx_beacon_cmd *tx_beacon_cmd;
@@ -516,7 +516,7 @@ static unsigned int iwl4965_hw_get_beacon_cmd(struct iwl_priv *priv,
516 516
517 return sizeof(*tx_beacon_cmd) + frame_size; 517 return sizeof(*tx_beacon_cmd) + frame_size;
518} 518}
519static int iwl4965_send_beacon_cmd(struct iwl_priv *priv) 519static int iwl_send_beacon_cmd(struct iwl_priv *priv)
520{ 520{
521 struct iwl_frame *frame; 521 struct iwl_frame *frame;
522 unsigned int frame_size; 522 unsigned int frame_size;
@@ -531,9 +531,9 @@ static int iwl4965_send_beacon_cmd(struct iwl_priv *priv)
531 return -ENOMEM; 531 return -ENOMEM;
532 } 532 }
533 533
534 rate = iwl4965_rate_get_lowest_plcp(priv); 534 rate = iwl_rate_get_lowest_plcp(priv);
535 535
536 frame_size = iwl4965_hw_get_beacon_cmd(priv, frame, rate); 536 frame_size = iwl_hw_get_beacon_cmd(priv, frame, rate);
537 537
538 rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size, 538 rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
539 &frame->u.cmd[0]); 539 &frame->u.cmd[0]);
@@ -549,7 +549,7 @@ static int iwl4965_send_beacon_cmd(struct iwl_priv *priv)
549 * 549 *
550 ******************************************************************************/ 550 ******************************************************************************/
551 551
552static void iwl4965_ht_conf(struct iwl_priv *priv, 552static void iwl_ht_conf(struct iwl_priv *priv,
553 struct ieee80211_bss_conf *bss_conf) 553 struct ieee80211_bss_conf *bss_conf)
554{ 554{
555 struct ieee80211_sta_ht_cap *ht_conf; 555 struct ieee80211_sta_ht_cap *ht_conf;
@@ -708,7 +708,7 @@ static void iwl_set_flags_for_band(struct iwl_priv *priv,
708 | RXON_FLG_CCK_MSK); 708 | RXON_FLG_CCK_MSK);
709 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; 709 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
710 } else { 710 } else {
711 /* Copied from iwl4965_post_associate() */ 711 /* Copied from iwl_post_associate() */
712 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) 712 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
713 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; 713 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
714 else 714 else
@@ -726,13 +726,13 @@ static void iwl_set_flags_for_band(struct iwl_priv *priv,
726/* 726/*
727 * initialize rxon structure with default values from eeprom 727 * initialize rxon structure with default values from eeprom
728 */ 728 */
729static void iwl4965_connection_init_rx_config(struct iwl_priv *priv) 729static void iwl_connection_init_rx_config(struct iwl_priv *priv, int mode)
730{ 730{
731 const struct iwl_channel_info *ch_info; 731 const struct iwl_channel_info *ch_info;
732 732
733 memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon)); 733 memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
734 734
735 switch (priv->iw_mode) { 735 switch (mode) {
736 case NL80211_IFTYPE_AP: 736 case NL80211_IFTYPE_AP:
737 priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP; 737 priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP;
738 break; 738 break;
@@ -755,7 +755,7 @@ static void iwl4965_connection_init_rx_config(struct iwl_priv *priv)
755 RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK; 755 RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK;
756 break; 756 break;
757 default: 757 default:
758 IWL_ERROR("Unsupported interface type %d\n", priv->iw_mode); 758 IWL_ERROR("Unsupported interface type %d\n", mode);
759 break; 759 break;
760 } 760 }
761 761
@@ -801,11 +801,9 @@ static void iwl4965_connection_init_rx_config(struct iwl_priv *priv)
801 iwl_set_rxon_chain(priv); 801 iwl_set_rxon_chain(priv);
802} 802}
803 803
804static int iwl4965_set_mode(struct iwl_priv *priv, int mode) 804static int iwl_set_mode(struct iwl_priv *priv, int mode)
805{ 805{
806 priv->iw_mode = mode; 806 iwl_connection_init_rx_config(priv, mode);
807
808 iwl4965_connection_init_rx_config(priv);
809 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); 807 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
810 808
811 iwl_clear_stations_table(priv); 809 iwl_clear_stations_table(priv);
@@ -821,12 +819,12 @@ static int iwl4965_set_mode(struct iwl_priv *priv, int mode)
821 return -EAGAIN; 819 return -EAGAIN;
822 } 820 }
823 821
824 iwl4965_commit_rxon(priv); 822 iwl_commit_rxon(priv);
825 823
826 return 0; 824 return 0;
827} 825}
828 826
829static void iwl4965_set_rate(struct iwl_priv *priv) 827static void iwl_set_rate(struct iwl_priv *priv)
830{ 828{
831 const struct ieee80211_supported_band *hw = NULL; 829 const struct ieee80211_supported_band *hw = NULL;
832 struct ieee80211_rate *rate; 830 struct ieee80211_rate *rate;
@@ -888,7 +886,7 @@ static void iwl4965_set_rate(struct iwl_priv *priv)
888 * the lower 3 bytes is the time in usec within one beacon interval 886 * the lower 3 bytes is the time in usec within one beacon interval
889 */ 887 */
890 888
891static u32 iwl4965_usecs_to_beacons(u32 usec, u32 beacon_interval) 889static u32 iwl_usecs_to_beacons(u32 usec, u32 beacon_interval)
892{ 890{
893 u32 quot; 891 u32 quot;
894 u32 rem; 892 u32 rem;
@@ -907,7 +905,7 @@ static u32 iwl4965_usecs_to_beacons(u32 usec, u32 beacon_interval)
907 * the same as HW timer counter counting down 905 * the same as HW timer counter counting down
908 */ 906 */
909 907
910static __le32 iwl4965_add_beacon_time(u32 base, u32 addon, u32 beacon_interval) 908static __le32 iwl_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
911{ 909{
912 u32 base_low = base & BEACON_TIME_MASK_LOW; 910 u32 base_low = base & BEACON_TIME_MASK_LOW;
913 u32 addon_low = addon & BEACON_TIME_MASK_LOW; 911 u32 addon_low = addon & BEACON_TIME_MASK_LOW;
@@ -926,7 +924,7 @@ static __le32 iwl4965_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
926 return cpu_to_le32(res); 924 return cpu_to_le32(res);
927} 925}
928 926
929static int iwl4965_get_measurement(struct iwl_priv *priv, 927static int iwl_get_measurement(struct iwl_priv *priv,
930 struct ieee80211_measurement_params *params, 928 struct ieee80211_measurement_params *params,
931 u8 type) 929 u8 type)
932{ 930{
@@ -944,7 +942,7 @@ static int iwl4965_get_measurement(struct iwl_priv *priv,
944 942
945 if (iwl_is_associated(priv)) 943 if (iwl_is_associated(priv))
946 add_time = 944 add_time =
947 iwl4965_usecs_to_beacons( 945 iwl_usecs_to_beacons(
948 le64_to_cpu(params->start_time) - priv->last_tsf, 946 le64_to_cpu(params->start_time) - priv->last_tsf,
949 le16_to_cpu(priv->rxon_timing.beacon_interval)); 947 le16_to_cpu(priv->rxon_timing.beacon_interval));
950 948
@@ -959,7 +957,7 @@ static int iwl4965_get_measurement(struct iwl_priv *priv,
959 957
960 if (iwl_is_associated(priv)) 958 if (iwl_is_associated(priv))
961 spectrum.start_time = 959 spectrum.start_time =
962 iwl4965_add_beacon_time(priv->last_beacon_time, 960 iwl_add_beacon_time(priv->last_beacon_time,
963 add_time, 961 add_time,
964 le16_to_cpu(priv->rxon_timing.beacon_interval)); 962 le16_to_cpu(priv->rxon_timing.beacon_interval));
965 else 963 else
@@ -1047,7 +1045,7 @@ static void iwl_rx_reply_alive(struct iwl_priv *priv,
1047 IWL_WARNING("uCode did not respond OK.\n"); 1045 IWL_WARNING("uCode did not respond OK.\n");
1048} 1046}
1049 1047
1050static void iwl4965_rx_reply_error(struct iwl_priv *priv, 1048static void iwl_rx_reply_error(struct iwl_priv *priv,
1051 struct iwl_rx_mem_buffer *rxb) 1049 struct iwl_rx_mem_buffer *rxb)
1052{ 1050{
1053 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; 1051 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
@@ -1063,7 +1061,7 @@ static void iwl4965_rx_reply_error(struct iwl_priv *priv,
1063 1061
1064#define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x 1062#define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
1065 1063
1066static void iwl4965_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb) 1064static void iwl_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
1067{ 1065{
1068 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; 1066 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
1069 struct iwl_rxon_cmd *rxon = (void *)&priv->active_rxon; 1067 struct iwl_rxon_cmd *rxon = (void *)&priv->active_rxon;
@@ -1074,7 +1072,7 @@ static void iwl4965_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
1074 priv->staging_rxon.channel = csa->channel; 1072 priv->staging_rxon.channel = csa->channel;
1075} 1073}
1076 1074
1077static void iwl4965_rx_spectrum_measure_notif(struct iwl_priv *priv, 1075static void iwl_rx_spectrum_measure_notif(struct iwl_priv *priv,
1078 struct iwl_rx_mem_buffer *rxb) 1076 struct iwl_rx_mem_buffer *rxb)
1079{ 1077{
1080#ifdef CONFIG_IWLAGN_SPECTRUM_MEASUREMENT 1078#ifdef CONFIG_IWLAGN_SPECTRUM_MEASUREMENT
@@ -1092,7 +1090,7 @@ static void iwl4965_rx_spectrum_measure_notif(struct iwl_priv *priv,
1092#endif 1090#endif
1093} 1091}
1094 1092
1095static void iwl4965_rx_pm_sleep_notif(struct iwl_priv *priv, 1093static void iwl_rx_pm_sleep_notif(struct iwl_priv *priv,
1096 struct iwl_rx_mem_buffer *rxb) 1094 struct iwl_rx_mem_buffer *rxb)
1097{ 1095{
1098#ifdef CONFIG_IWLWIFI_DEBUG 1096#ifdef CONFIG_IWLWIFI_DEBUG
@@ -1103,7 +1101,7 @@ static void iwl4965_rx_pm_sleep_notif(struct iwl_priv *priv,
1103#endif 1101#endif
1104} 1102}
1105 1103
1106static void iwl4965_rx_pm_debug_statistics_notif(struct iwl_priv *priv, 1104static void iwl_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
1107 struct iwl_rx_mem_buffer *rxb) 1105 struct iwl_rx_mem_buffer *rxb)
1108{ 1106{
1109 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; 1107 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
@@ -1113,7 +1111,7 @@ static void iwl4965_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
1113 iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len)); 1111 iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len));
1114} 1112}
1115 1113
1116static void iwl4965_bg_beacon_update(struct work_struct *work) 1114static void iwl_bg_beacon_update(struct work_struct *work)
1117{ 1115{
1118 struct iwl_priv *priv = 1116 struct iwl_priv *priv =
1119 container_of(work, struct iwl_priv, beacon_update); 1117 container_of(work, struct iwl_priv, beacon_update);
@@ -1135,11 +1133,11 @@ static void iwl4965_bg_beacon_update(struct work_struct *work)
1135 priv->ibss_beacon = beacon; 1133 priv->ibss_beacon = beacon;
1136 mutex_unlock(&priv->mutex); 1134 mutex_unlock(&priv->mutex);
1137 1135
1138 iwl4965_send_beacon_cmd(priv); 1136 iwl_send_beacon_cmd(priv);
1139} 1137}
1140 1138
1141/** 1139/**
1142 * iwl4965_bg_statistics_periodic - Timer callback to queue statistics 1140 * iwl_bg_statistics_periodic - Timer callback to queue statistics
1143 * 1141 *
1144 * This callback is provided in order to send a statistics request. 1142 * This callback is provided in order to send a statistics request.
1145 * 1143 *
@@ -1148,17 +1146,21 @@ static void iwl4965_bg_beacon_update(struct work_struct *work)
1148 * was received. We need to ensure we receive the statistics in order 1146 * was received. We need to ensure we receive the statistics in order
1149 * to update the temperature used for calibrating the TXPOWER. 1147 * to update the temperature used for calibrating the TXPOWER.
1150 */ 1148 */
1151static void iwl4965_bg_statistics_periodic(unsigned long data) 1149static void iwl_bg_statistics_periodic(unsigned long data)
1152{ 1150{
1153 struct iwl_priv *priv = (struct iwl_priv *)data; 1151 struct iwl_priv *priv = (struct iwl_priv *)data;
1154 1152
1155 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) 1153 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
1156 return; 1154 return;
1157 1155
1156 /* dont send host command if rf-kill is on */
1157 if (!iwl_is_ready_rf(priv))
1158 return;
1159
1158 iwl_send_statistics_request(priv, CMD_ASYNC); 1160 iwl_send_statistics_request(priv, CMD_ASYNC);
1159} 1161}
1160 1162
1161static void iwl4965_rx_beacon_notif(struct iwl_priv *priv, 1163static void iwl_rx_beacon_notif(struct iwl_priv *priv,
1162 struct iwl_rx_mem_buffer *rxb) 1164 struct iwl_rx_mem_buffer *rxb)
1163{ 1165{
1164#ifdef CONFIG_IWLWIFI_DEBUG 1166#ifdef CONFIG_IWLWIFI_DEBUG
@@ -1182,7 +1184,7 @@ static void iwl4965_rx_beacon_notif(struct iwl_priv *priv,
1182 1184
1183/* Handle notification from uCode that card's power state is changing 1185/* Handle notification from uCode that card's power state is changing
1184 * due to software, hardware, or critical temperature RFKILL */ 1186 * due to software, hardware, or critical temperature RFKILL */
1185static void iwl4965_rx_card_state_notif(struct iwl_priv *priv, 1187static void iwl_rx_card_state_notif(struct iwl_priv *priv,
1186 struct iwl_rx_mem_buffer *rxb) 1188 struct iwl_rx_mem_buffer *rxb)
1187{ 1189{
1188 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; 1190 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
@@ -1251,7 +1253,7 @@ static void iwl4965_rx_card_state_notif(struct iwl_priv *priv,
1251 wake_up_interruptible(&priv->wait_command_queue); 1253 wake_up_interruptible(&priv->wait_command_queue);
1252} 1254}
1253 1255
1254int iwl4965_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src) 1256int iwl_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src)
1255{ 1257{
1256 int ret; 1258 int ret;
1257 unsigned long flags; 1259 unsigned long flags;
@@ -1283,7 +1285,7 @@ err:
1283} 1285}
1284 1286
1285/** 1287/**
1286 * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks 1288 * iwl_setup_rx_handlers - Initialize Rx handler callbacks
1287 * 1289 *
1288 * Setup the RX handlers for each of the reply types sent from the uCode 1290 * Setup the RX handlers for each of the reply types sent from the uCode
1289 * to the host. 1291 * to the host.
@@ -1294,14 +1296,14 @@ err:
1294static void iwl_setup_rx_handlers(struct iwl_priv *priv) 1296static void iwl_setup_rx_handlers(struct iwl_priv *priv)
1295{ 1297{
1296 priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive; 1298 priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive;
1297 priv->rx_handlers[REPLY_ERROR] = iwl4965_rx_reply_error; 1299 priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error;
1298 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl4965_rx_csa; 1300 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
1299 priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] = 1301 priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
1300 iwl4965_rx_spectrum_measure_notif; 1302 iwl_rx_spectrum_measure_notif;
1301 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl4965_rx_pm_sleep_notif; 1303 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif;
1302 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] = 1304 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
1303 iwl4965_rx_pm_debug_statistics_notif; 1305 iwl_rx_pm_debug_statistics_notif;
1304 priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif; 1306 priv->rx_handlers[BEACON_NOTIFICATION] = iwl_rx_beacon_notif;
1305 1307
1306 /* 1308 /*
1307 * The same handler is used for both the REPLY to a discrete 1309 * The same handler is used for both the REPLY to a discrete
@@ -1314,7 +1316,7 @@ static void iwl_setup_rx_handlers(struct iwl_priv *priv)
1314 iwl_setup_rx_scan_handlers(priv); 1316 iwl_setup_rx_scan_handlers(priv);
1315 1317
1316 /* status change handler */ 1318 /* status change handler */
1317 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl4965_rx_card_state_notif; 1319 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl_rx_card_state_notif;
1318 1320
1319 priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] = 1321 priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] =
1320 iwl_rx_missed_beacon_notif; 1322 iwl_rx_missed_beacon_notif;
@@ -1398,7 +1400,7 @@ void iwl_rx_handle(struct iwl_priv *priv)
1398 1400
1399 /* Based on type of command response or notification, 1401 /* Based on type of command response or notification,
1400 * handle those that need handling via function in 1402 * handle those that need handling via function in
1401 * rx_handlers table. See iwl4965_setup_rx_handlers() */ 1403 * rx_handlers table. See iwl_setup_rx_handlers() */
1402 if (priv->rx_handlers[pkt->hdr.cmd]) { 1404 if (priv->rx_handlers[pkt->hdr.cmd]) {
1403 IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d, %s, 0x%02x\n", r, 1405 IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d, %s, 0x%02x\n", r,
1404 i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd); 1406 i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
@@ -1455,7 +1457,7 @@ void iwl_rx_handle(struct iwl_priv *priv)
1455} 1457}
1456 1458
1457#ifdef CONFIG_IWLWIFI_DEBUG 1459#ifdef CONFIG_IWLWIFI_DEBUG
1458static void iwl4965_print_rx_config_cmd(struct iwl_priv *priv) 1460static void iwl_print_rx_config_cmd(struct iwl_priv *priv)
1459{ 1461{
1460 struct iwl_rxon_cmd *rxon = &priv->staging_rxon; 1462 struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
1461 1463
@@ -1475,7 +1477,7 @@ static void iwl4965_print_rx_config_cmd(struct iwl_priv *priv)
1475} 1477}
1476#endif 1478#endif
1477 1479
1478static void iwl4965_enable_interrupts(struct iwl_priv *priv) 1480static void iwl_enable_interrupts(struct iwl_priv *priv)
1479{ 1481{
1480 IWL_DEBUG_ISR("Enabling interrupts\n"); 1482 IWL_DEBUG_ISR("Enabling interrupts\n");
1481 set_bit(STATUS_INT_ENABLED, &priv->status); 1483 set_bit(STATUS_INT_ENABLED, &priv->status);
@@ -1490,7 +1492,7 @@ static inline void iwl_synchronize_irq(struct iwl_priv *priv)
1490 tasklet_kill(&priv->irq_tasklet); 1492 tasklet_kill(&priv->irq_tasklet);
1491} 1493}
1492 1494
1493static inline void iwl4965_disable_interrupts(struct iwl_priv *priv) 1495static inline void iwl_disable_interrupts(struct iwl_priv *priv)
1494{ 1496{
1495 clear_bit(STATUS_INT_ENABLED, &priv->status); 1497 clear_bit(STATUS_INT_ENABLED, &priv->status);
1496 1498
@@ -1506,11 +1508,11 @@ static inline void iwl4965_disable_interrupts(struct iwl_priv *priv)
1506 1508
1507 1509
1508/** 1510/**
1509 * iwl4965_irq_handle_error - called for HW or SW error interrupt from card 1511 * iwl_irq_handle_error - called for HW or SW error interrupt from card
1510 */ 1512 */
1511static void iwl4965_irq_handle_error(struct iwl_priv *priv) 1513static void iwl_irq_handle_error(struct iwl_priv *priv)
1512{ 1514{
1513 /* Set the FW error flag -- cleared on iwl4965_down */ 1515 /* Set the FW error flag -- cleared on iwl_down */
1514 set_bit(STATUS_FW_ERROR, &priv->status); 1516 set_bit(STATUS_FW_ERROR, &priv->status);
1515 1517
1516 /* Cancel currently queued command. */ 1518 /* Cancel currently queued command. */
@@ -1520,7 +1522,7 @@ static void iwl4965_irq_handle_error(struct iwl_priv *priv)
1520 if (priv->debug_level & IWL_DL_FW_ERRORS) { 1522 if (priv->debug_level & IWL_DL_FW_ERRORS) {
1521 iwl_dump_nic_error_log(priv); 1523 iwl_dump_nic_error_log(priv);
1522 iwl_dump_nic_event_log(priv); 1524 iwl_dump_nic_event_log(priv);
1523 iwl4965_print_rx_config_cmd(priv); 1525 iwl_print_rx_config_cmd(priv);
1524 } 1526 }
1525#endif 1527#endif
1526 1528
@@ -1544,14 +1546,14 @@ static void iwl4965_irq_handle_error(struct iwl_priv *priv)
1544 } 1546 }
1545} 1547}
1546 1548
1547static void iwl4965_error_recovery(struct iwl_priv *priv) 1549static void iwl_error_recovery(struct iwl_priv *priv)
1548{ 1550{
1549 unsigned long flags; 1551 unsigned long flags;
1550 1552
1551 memcpy(&priv->staging_rxon, &priv->recovery_rxon, 1553 memcpy(&priv->staging_rxon, &priv->recovery_rxon,
1552 sizeof(priv->staging_rxon)); 1554 sizeof(priv->staging_rxon));
1553 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; 1555 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
1554 iwl4965_commit_rxon(priv); 1556 iwl_commit_rxon(priv);
1555 1557
1556 iwl_rxon_add_station(priv, priv->bssid, 1); 1558 iwl_rxon_add_station(priv, priv->bssid, 1);
1557 1559
@@ -1561,7 +1563,7 @@ static void iwl4965_error_recovery(struct iwl_priv *priv)
1561 spin_unlock_irqrestore(&priv->lock, flags); 1563 spin_unlock_irqrestore(&priv->lock, flags);
1562} 1564}
1563 1565
1564static void iwl4965_irq_tasklet(struct iwl_priv *priv) 1566static void iwl_irq_tasklet(struct iwl_priv *priv)
1565{ 1567{
1566 u32 inta, handled = 0; 1568 u32 inta, handled = 0;
1567 u32 inta_fh; 1569 u32 inta_fh;
@@ -1607,9 +1609,9 @@ static void iwl4965_irq_tasklet(struct iwl_priv *priv)
1607 IWL_ERROR("Microcode HW error detected. Restarting.\n"); 1609 IWL_ERROR("Microcode HW error detected. Restarting.\n");
1608 1610
1609 /* Tell the device to stop sending interrupts */ 1611 /* Tell the device to stop sending interrupts */
1610 iwl4965_disable_interrupts(priv); 1612 iwl_disable_interrupts(priv);
1611 1613
1612 iwl4965_irq_handle_error(priv); 1614 iwl_irq_handle_error(priv);
1613 1615
1614 handled |= CSR_INT_BIT_HW_ERR; 1616 handled |= CSR_INT_BIT_HW_ERR;
1615 1617
@@ -1663,7 +1665,7 @@ static void iwl4965_irq_tasklet(struct iwl_priv *priv)
1663 if (inta & CSR_INT_BIT_SW_ERR) { 1665 if (inta & CSR_INT_BIT_SW_ERR) {
1664 IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n", 1666 IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n",
1665 inta); 1667 inta);
1666 iwl4965_irq_handle_error(priv); 1668 iwl_irq_handle_error(priv);
1667 handled |= CSR_INT_BIT_SW_ERR; 1669 handled |= CSR_INT_BIT_SW_ERR;
1668 } 1670 }
1669 1671
@@ -1709,7 +1711,7 @@ static void iwl4965_irq_tasklet(struct iwl_priv *priv)
1709 /* Re-enable all interrupts */ 1711 /* Re-enable all interrupts */
1710 /* only Re-enable if diabled by irq */ 1712 /* only Re-enable if diabled by irq */
1711 if (test_bit(STATUS_INT_ENABLED, &priv->status)) 1713 if (test_bit(STATUS_INT_ENABLED, &priv->status))
1712 iwl4965_enable_interrupts(priv); 1714 iwl_enable_interrupts(priv);
1713 1715
1714#ifdef CONFIG_IWLWIFI_DEBUG 1716#ifdef CONFIG_IWLWIFI_DEBUG
1715 if (priv->debug_level & (IWL_DL_ISR)) { 1717 if (priv->debug_level & (IWL_DL_ISR)) {
@@ -1723,7 +1725,7 @@ static void iwl4965_irq_tasklet(struct iwl_priv *priv)
1723 spin_unlock_irqrestore(&priv->lock, flags); 1725 spin_unlock_irqrestore(&priv->lock, flags);
1724} 1726}
1725 1727
1726static irqreturn_t iwl4965_isr(int irq, void *data) 1728static irqreturn_t iwl_isr(int irq, void *data)
1727{ 1729{
1728 struct iwl_priv *priv = data; 1730 struct iwl_priv *priv = data;
1729 u32 inta, inta_mask; 1731 u32 inta, inta_mask;
@@ -1764,7 +1766,7 @@ static irqreturn_t iwl4965_isr(int irq, void *data)
1764 1766
1765 inta &= ~CSR_INT_BIT_SCD; 1767 inta &= ~CSR_INT_BIT_SCD;
1766 1768
1767 /* iwl4965_irq_tasklet() will service interrupts and re-enable them */ 1769 /* iwl_irq_tasklet() will service interrupts and re-enable them */
1768 if (likely(inta || inta_fh)) 1770 if (likely(inta || inta_fh))
1769 tasklet_schedule(&priv->irq_tasklet); 1771 tasklet_schedule(&priv->irq_tasklet);
1770 1772
@@ -1776,7 +1778,7 @@ static irqreturn_t iwl4965_isr(int irq, void *data)
1776 /* re-enable interrupts here since we don't have anything to service. */ 1778 /* re-enable interrupts here since we don't have anything to service. */
1777 /* only Re-enable if diabled by irq */ 1779 /* only Re-enable if diabled by irq */
1778 if (test_bit(STATUS_INT_ENABLED, &priv->status)) 1780 if (test_bit(STATUS_INT_ENABLED, &priv->status))
1779 iwl4965_enable_interrupts(priv); 1781 iwl_enable_interrupts(priv);
1780 spin_unlock(&priv->lock); 1782 spin_unlock(&priv->lock);
1781 return IRQ_NONE; 1783 return IRQ_NONE;
1782} 1784}
@@ -1787,7 +1789,7 @@ static irqreturn_t iwl4965_isr(int irq, void *data)
1787 * 1789 *
1788 ******************************************************************************/ 1790 ******************************************************************************/
1789 1791
1790static void iwl4965_dealloc_ucode_pci(struct iwl_priv *priv) 1792static void iwl_dealloc_ucode_pci(struct iwl_priv *priv)
1791{ 1793{
1792 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code); 1794 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
1793 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data); 1795 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
@@ -1797,7 +1799,7 @@ static void iwl4965_dealloc_ucode_pci(struct iwl_priv *priv)
1797 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot); 1799 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
1798} 1800}
1799 1801
1800static void iwl4965_nic_start(struct iwl_priv *priv) 1802static void iwl_nic_start(struct iwl_priv *priv)
1801{ 1803{
1802 /* Remove all resets to allow NIC to operate */ 1804 /* Remove all resets to allow NIC to operate */
1803 iwl_write32(priv, CSR_RESET, 0); 1805 iwl_write32(priv, CSR_RESET, 0);
@@ -1805,11 +1807,11 @@ static void iwl4965_nic_start(struct iwl_priv *priv)
1805 1807
1806 1808
1807/** 1809/**
1808 * iwl4965_read_ucode - Read uCode images from disk file. 1810 * iwl_read_ucode - Read uCode images from disk file.
1809 * 1811 *
1810 * Copy into buffers for card to fetch via bus-mastering 1812 * Copy into buffers for card to fetch via bus-mastering
1811 */ 1813 */
1812static int iwl4965_read_ucode(struct iwl_priv *priv) 1814static int iwl_read_ucode(struct iwl_priv *priv)
1813{ 1815{
1814 struct iwl_ucode *ucode; 1816 struct iwl_ucode *ucode;
1815 int ret; 1817 int ret;
@@ -1953,7 +1955,7 @@ static int iwl4965_read_ucode(struct iwl_priv *priv)
1953 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr); 1955 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
1954 1956
1955 /* Runtime data (2nd block) 1957 /* Runtime data (2nd block)
1956 * NOTE: Copy into backup buffer will be done in iwl4965_up() */ 1958 * NOTE: Copy into backup buffer will be done in iwl_up() */
1957 src = &ucode->data[inst_size]; 1959 src = &ucode->data[inst_size];
1958 len = priv->ucode_data.len; 1960 len = priv->ucode_data.len;
1959 IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len); 1961 IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len);
@@ -1991,7 +1993,7 @@ static int iwl4965_read_ucode(struct iwl_priv *priv)
1991 err_pci_alloc: 1993 err_pci_alloc:
1992 IWL_ERROR("failed to allocate pci memory\n"); 1994 IWL_ERROR("failed to allocate pci memory\n");
1993 ret = -ENOMEM; 1995 ret = -ENOMEM;
1994 iwl4965_dealloc_ucode_pci(priv); 1996 iwl_dealloc_ucode_pci(priv);
1995 1997
1996 err_release: 1998 err_release:
1997 release_firmware(ucode_raw); 1999 release_firmware(ucode_raw);
@@ -2036,7 +2038,7 @@ static void iwl_alive_start(struct iwl_priv *priv)
2036 goto restart; 2038 goto restart;
2037 } 2039 }
2038 2040
2039 /* After the ALIVE response, we can send host commands to 4965 uCode */ 2041 /* After the ALIVE response, we can send host commands to the uCode */
2040 set_bit(STATUS_ALIVE, &priv->status); 2042 set_bit(STATUS_ALIVE, &priv->status);
2041 2043
2042 if (iwl_is_rfkill(priv)) 2044 if (iwl_is_rfkill(priv))
@@ -2056,17 +2058,17 @@ static void iwl_alive_start(struct iwl_priv *priv)
2056 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; 2058 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2057 } else { 2059 } else {
2058 /* Initialize our rx_config data */ 2060 /* Initialize our rx_config data */
2059 iwl4965_connection_init_rx_config(priv); 2061 iwl_connection_init_rx_config(priv, priv->iw_mode);
2060 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); 2062 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
2061 } 2063 }
2062 2064
2063 /* Configure Bluetooth device coexistence support */ 2065 /* Configure Bluetooth device coexistence support */
2064 iwl4965_send_bt_config(priv); 2066 iwl_send_bt_config(priv);
2065 2067
2066 iwl_reset_run_time_calib(priv); 2068 iwl_reset_run_time_calib(priv);
2067 2069
2068 /* Configure the adapter for unassociated operation */ 2070 /* Configure the adapter for unassociated operation */
2069 iwl4965_commit_rxon(priv); 2071 iwl_commit_rxon(priv);
2070 2072
2071 /* At this point, the NIC is initialized and operational */ 2073 /* At this point, the NIC is initialized and operational */
2072 iwl_rf_kill_ct_config(priv); 2074 iwl_rf_kill_ct_config(priv);
@@ -2078,12 +2080,12 @@ static void iwl_alive_start(struct iwl_priv *priv)
2078 wake_up_interruptible(&priv->wait_command_queue); 2080 wake_up_interruptible(&priv->wait_command_queue);
2079 2081
2080 if (priv->error_recovering) 2082 if (priv->error_recovering)
2081 iwl4965_error_recovery(priv); 2083 iwl_error_recovery(priv);
2082 2084
2083 iwl_power_update_mode(priv, 1); 2085 iwl_power_update_mode(priv, 1);
2084 2086
2085 if (test_and_clear_bit(STATUS_MODE_PENDING, &priv->status)) 2087 if (test_and_clear_bit(STATUS_MODE_PENDING, &priv->status))
2086 iwl4965_set_mode(priv, priv->iw_mode); 2088 iwl_set_mode(priv, priv->iw_mode);
2087 2089
2088 return; 2090 return;
2089 2091
@@ -2093,7 +2095,7 @@ static void iwl_alive_start(struct iwl_priv *priv)
2093 2095
2094static void iwl_cancel_deferred_work(struct iwl_priv *priv); 2096static void iwl_cancel_deferred_work(struct iwl_priv *priv);
2095 2097
2096static void __iwl4965_down(struct iwl_priv *priv) 2098static void __iwl_down(struct iwl_priv *priv)
2097{ 2099{
2098 unsigned long flags; 2100 unsigned long flags;
2099 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status); 2101 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
@@ -2120,14 +2122,14 @@ static void __iwl4965_down(struct iwl_priv *priv)
2120 2122
2121 /* tell the device to stop sending interrupts */ 2123 /* tell the device to stop sending interrupts */
2122 spin_lock_irqsave(&priv->lock, flags); 2124 spin_lock_irqsave(&priv->lock, flags);
2123 iwl4965_disable_interrupts(priv); 2125 iwl_disable_interrupts(priv);
2124 spin_unlock_irqrestore(&priv->lock, flags); 2126 spin_unlock_irqrestore(&priv->lock, flags);
2125 iwl_synchronize_irq(priv); 2127 iwl_synchronize_irq(priv);
2126 2128
2127 if (priv->mac80211_registered) 2129 if (priv->mac80211_registered)
2128 ieee80211_stop_queues(priv->hw); 2130 ieee80211_stop_queues(priv->hw);
2129 2131
2130 /* If we have not previously called iwl4965_init() then 2132 /* If we have not previously called iwl_init() then
2131 * clear all bits but the RF Kill and SUSPEND bits and return */ 2133 * clear all bits but the RF Kill and SUSPEND bits and return */
2132 if (!iwl_is_init(priv)) { 2134 if (!iwl_is_init(priv)) {
2133 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) << 2135 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
@@ -2194,10 +2196,10 @@ static void __iwl4965_down(struct iwl_priv *priv)
2194 iwl_clear_free_frames(priv); 2196 iwl_clear_free_frames(priv);
2195} 2197}
2196 2198
2197static void iwl4965_down(struct iwl_priv *priv) 2199static void iwl_down(struct iwl_priv *priv)
2198{ 2200{
2199 mutex_lock(&priv->mutex); 2201 mutex_lock(&priv->mutex);
2200 __iwl4965_down(priv); 2202 __iwl_down(priv);
2201 mutex_unlock(&priv->mutex); 2203 mutex_unlock(&priv->mutex);
2202 2204
2203 iwl_cancel_deferred_work(priv); 2205 iwl_cancel_deferred_work(priv);
@@ -2205,7 +2207,7 @@ static void iwl4965_down(struct iwl_priv *priv)
2205 2207
2206#define MAX_HW_RESTARTS 5 2208#define MAX_HW_RESTARTS 5
2207 2209
2208static int __iwl4965_up(struct iwl_priv *priv) 2210static int __iwl_up(struct iwl_priv *priv)
2209{ 2211{
2210 int i; 2212 int i;
2211 int ret; 2213 int ret;
@@ -2227,7 +2229,7 @@ static int __iwl4965_up(struct iwl_priv *priv)
2227 set_bit(STATUS_RF_KILL_HW, &priv->status); 2229 set_bit(STATUS_RF_KILL_HW, &priv->status);
2228 2230
2229 if (iwl_is_rfkill(priv)) { 2231 if (iwl_is_rfkill(priv)) {
2230 iwl4965_enable_interrupts(priv); 2232 iwl_enable_interrupts(priv);
2231 IWL_WARNING("Radio disabled by %s RF Kill switch\n", 2233 IWL_WARNING("Radio disabled by %s RF Kill switch\n",
2232 test_bit(STATUS_RF_KILL_HW, &priv->status) ? "HW" : "SW"); 2234 test_bit(STATUS_RF_KILL_HW, &priv->status) ? "HW" : "SW");
2233 return 0; 2235 return 0;
@@ -2254,7 +2256,7 @@ static int __iwl4965_up(struct iwl_priv *priv)
2254 2256
2255 /* clear (again), then enable host interrupts */ 2257 /* clear (again), then enable host interrupts */
2256 iwl_write32(priv, CSR_INT, 0xFFFFFFFF); 2258 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
2257 iwl4965_enable_interrupts(priv); 2259 iwl_enable_interrupts(priv);
2258 2260
2259 /* really make sure rfkill handshake bits are cleared */ 2261 /* really make sure rfkill handshake bits are cleared */
2260 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); 2262 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
@@ -2284,7 +2286,7 @@ static int __iwl4965_up(struct iwl_priv *priv)
2284 clear_bit(STATUS_FW_ERROR, &priv->status); 2286 clear_bit(STATUS_FW_ERROR, &priv->status);
2285 2287
2286 /* start card; "initialize" will load runtime ucode */ 2288 /* start card; "initialize" will load runtime ucode */
2287 iwl4965_nic_start(priv); 2289 iwl_nic_start(priv);
2288 2290
2289 IWL_DEBUG_INFO(DRV_NAME " is coming up\n"); 2291 IWL_DEBUG_INFO(DRV_NAME " is coming up\n");
2290 2292
@@ -2292,7 +2294,7 @@ static int __iwl4965_up(struct iwl_priv *priv)
2292 } 2294 }
2293 2295
2294 set_bit(STATUS_EXIT_PENDING, &priv->status); 2296 set_bit(STATUS_EXIT_PENDING, &priv->status);
2295 __iwl4965_down(priv); 2297 __iwl_down(priv);
2296 clear_bit(STATUS_EXIT_PENDING, &priv->status); 2298 clear_bit(STATUS_EXIT_PENDING, &priv->status);
2297 2299
2298 /* tried to restart and config the device for as long as our 2300 /* tried to restart and config the device for as long as our
@@ -2335,7 +2337,7 @@ static void iwl_bg_alive_start(struct work_struct *data)
2335 ieee80211_notify_mac(priv->hw, IEEE80211_NOTIFY_RE_ASSOC); 2337 ieee80211_notify_mac(priv->hw, IEEE80211_NOTIFY_RE_ASSOC);
2336} 2338}
2337 2339
2338static void iwl4965_bg_rf_kill(struct work_struct *work) 2340static void iwl_bg_rf_kill(struct work_struct *work)
2339{ 2341{
2340 struct iwl_priv *priv = container_of(work, struct iwl_priv, rf_kill); 2342 struct iwl_priv *priv = container_of(work, struct iwl_priv, rf_kill);
2341 2343
@@ -2369,7 +2371,7 @@ static void iwl4965_bg_rf_kill(struct work_struct *work)
2369 iwl_rfkill_set_hw_state(priv); 2371 iwl_rfkill_set_hw_state(priv);
2370} 2372}
2371 2373
2372static void iwl4965_bg_set_monitor(struct work_struct *work) 2374static void iwl_bg_set_monitor(struct work_struct *work)
2373{ 2375{
2374 struct iwl_priv *priv = container_of(work, 2376 struct iwl_priv *priv = container_of(work,
2375 struct iwl_priv, set_monitor); 2377 struct iwl_priv, set_monitor);
@@ -2379,16 +2381,16 @@ static void iwl4965_bg_set_monitor(struct work_struct *work)
2379 2381
2380 mutex_lock(&priv->mutex); 2382 mutex_lock(&priv->mutex);
2381 2383
2382 ret = iwl4965_set_mode(priv, NL80211_IFTYPE_MONITOR); 2384 ret = iwl_set_mode(priv, NL80211_IFTYPE_MONITOR);
2383
2384 if (ret) { 2385 if (ret) {
2385 if (ret == -EAGAIN) 2386 if (ret == -EAGAIN)
2386 IWL_DEBUG(IWL_DL_STATE, "leave - not ready\n"); 2387 IWL_DEBUG(IWL_DL_STATE, "leave - not ready\n");
2387 else 2388 else
2388 IWL_ERROR("iwl4965_set_mode() failed ret = %d\n", ret); 2389 IWL_ERROR("iwl_set_mode() failed ret = %d\n", ret);
2389 } 2390 }
2390 2391
2391 mutex_unlock(&priv->mutex); 2392 mutex_unlock(&priv->mutex);
2393 ieee80211_notify_mac(priv->hw, IEEE80211_NOTIFY_RE_ASSOC);
2392} 2394}
2393 2395
2394static void iwl_bg_run_time_calib_work(struct work_struct *work) 2396static void iwl_bg_run_time_calib_work(struct work_struct *work)
@@ -2414,7 +2416,7 @@ static void iwl_bg_run_time_calib_work(struct work_struct *work)
2414 return; 2416 return;
2415} 2417}
2416 2418
2417static void iwl4965_bg_up(struct work_struct *data) 2419static void iwl_bg_up(struct work_struct *data)
2418{ 2420{
2419 struct iwl_priv *priv = container_of(data, struct iwl_priv, up); 2421 struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
2420 2422
@@ -2422,23 +2424,23 @@ static void iwl4965_bg_up(struct work_struct *data)
2422 return; 2424 return;
2423 2425
2424 mutex_lock(&priv->mutex); 2426 mutex_lock(&priv->mutex);
2425 __iwl4965_up(priv); 2427 __iwl_up(priv);
2426 mutex_unlock(&priv->mutex); 2428 mutex_unlock(&priv->mutex);
2427 iwl_rfkill_set_hw_state(priv); 2429 iwl_rfkill_set_hw_state(priv);
2428} 2430}
2429 2431
2430static void iwl4965_bg_restart(struct work_struct *data) 2432static void iwl_bg_restart(struct work_struct *data)
2431{ 2433{
2432 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart); 2434 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
2433 2435
2434 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) 2436 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2435 return; 2437 return;
2436 2438
2437 iwl4965_down(priv); 2439 iwl_down(priv);
2438 queue_work(priv->workqueue, &priv->up); 2440 queue_work(priv->workqueue, &priv->up);
2439} 2441}
2440 2442
2441static void iwl4965_bg_rx_replenish(struct work_struct *data) 2443static void iwl_bg_rx_replenish(struct work_struct *data)
2442{ 2444{
2443 struct iwl_priv *priv = 2445 struct iwl_priv *priv =
2444 container_of(data, struct iwl_priv, rx_replenish); 2446 container_of(data, struct iwl_priv, rx_replenish);
@@ -2453,7 +2455,7 @@ static void iwl4965_bg_rx_replenish(struct work_struct *data)
2453 2455
2454#define IWL_DELAY_NEXT_SCAN (HZ*2) 2456#define IWL_DELAY_NEXT_SCAN (HZ*2)
2455 2457
2456static void iwl4965_post_associate(struct iwl_priv *priv) 2458static void iwl_post_associate(struct iwl_priv *priv)
2457{ 2459{
2458 struct ieee80211_conf *conf = NULL; 2460 struct ieee80211_conf *conf = NULL;
2459 int ret = 0; 2461 int ret = 0;
@@ -2481,7 +2483,7 @@ static void iwl4965_post_associate(struct iwl_priv *priv)
2481 conf = ieee80211_get_hw_conf(priv->hw); 2483 conf = ieee80211_get_hw_conf(priv->hw);
2482 2484
2483 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; 2485 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2484 iwl4965_commit_rxon(priv); 2486 iwl_commit_rxon(priv);
2485 2487
2486 iwl_setup_rxon_timing(priv); 2488 iwl_setup_rxon_timing(priv);
2487 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING, 2489 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
@@ -2516,7 +2518,7 @@ static void iwl4965_post_associate(struct iwl_priv *priv)
2516 2518
2517 } 2519 }
2518 2520
2519 iwl4965_commit_rxon(priv); 2521 iwl_commit_rxon(priv);
2520 2522
2521 switch (priv->iw_mode) { 2523 switch (priv->iw_mode) {
2522 case NL80211_IFTYPE_STATION: 2524 case NL80211_IFTYPE_STATION:
@@ -2528,7 +2530,7 @@ static void iwl4965_post_associate(struct iwl_priv *priv)
2528 priv->assoc_id = 1; 2530 priv->assoc_id = 1;
2529 2531
2530 iwl_rxon_add_station(priv, priv->bssid, 0); 2532 iwl_rxon_add_station(priv, priv->bssid, 0);
2531 iwl4965_send_beacon_cmd(priv); 2533 iwl_send_beacon_cmd(priv);
2532 2534
2533 break; 2535 break;
2534 2536
@@ -2565,7 +2567,7 @@ static void iwl4965_post_associate(struct iwl_priv *priv)
2565 2567
2566#define UCODE_READY_TIMEOUT (4 * HZ) 2568#define UCODE_READY_TIMEOUT (4 * HZ)
2567 2569
2568static int iwl4965_mac_start(struct ieee80211_hw *hw) 2570static int iwl_mac_start(struct ieee80211_hw *hw)
2569{ 2571{
2570 struct iwl_priv *priv = hw->priv; 2572 struct iwl_priv *priv = hw->priv;
2571 int ret; 2573 int ret;
@@ -2587,7 +2589,7 @@ static int iwl4965_mac_start(struct ieee80211_hw *hw)
2587 pci_write_config_word(priv->pci_dev, PCI_COMMAND, pci_cmd); 2589 pci_write_config_word(priv->pci_dev, PCI_COMMAND, pci_cmd);
2588 } 2590 }
2589 2591
2590 ret = request_irq(priv->pci_dev->irq, iwl4965_isr, IRQF_SHARED, 2592 ret = request_irq(priv->pci_dev->irq, iwl_isr, IRQF_SHARED,
2591 DRV_NAME, priv); 2593 DRV_NAME, priv);
2592 if (ret) { 2594 if (ret) {
2593 IWL_ERROR("Error allocating IRQ %d\n", priv->pci_dev->irq); 2595 IWL_ERROR("Error allocating IRQ %d\n", priv->pci_dev->irq);
@@ -2602,7 +2604,7 @@ static int iwl4965_mac_start(struct ieee80211_hw *hw)
2602 * ucode filename and max sizes are card-specific. */ 2604 * ucode filename and max sizes are card-specific. */
2603 2605
2604 if (!priv->ucode_code.len) { 2606 if (!priv->ucode_code.len) {
2605 ret = iwl4965_read_ucode(priv); 2607 ret = iwl_read_ucode(priv);
2606 if (ret) { 2608 if (ret) {
2607 IWL_ERROR("Could not read microcode: %d\n", ret); 2609 IWL_ERROR("Could not read microcode: %d\n", ret);
2608 mutex_unlock(&priv->mutex); 2610 mutex_unlock(&priv->mutex);
@@ -2610,7 +2612,7 @@ static int iwl4965_mac_start(struct ieee80211_hw *hw)
2610 } 2612 }
2611 } 2613 }
2612 2614
2613 ret = __iwl4965_up(priv); 2615 ret = __iwl_up(priv);
2614 2616
2615 mutex_unlock(&priv->mutex); 2617 mutex_unlock(&priv->mutex);
2616 2618
@@ -2656,7 +2658,7 @@ out_disable_msi:
2656 return ret; 2658 return ret;
2657} 2659}
2658 2660
2659static void iwl4965_mac_stop(struct ieee80211_hw *hw) 2661static void iwl_mac_stop(struct ieee80211_hw *hw)
2660{ 2662{
2661 struct iwl_priv *priv = hw->priv; 2663 struct iwl_priv *priv = hw->priv;
2662 2664
@@ -2678,7 +2680,7 @@ static void iwl4965_mac_stop(struct ieee80211_hw *hw)
2678 mutex_unlock(&priv->mutex); 2680 mutex_unlock(&priv->mutex);
2679 } 2681 }
2680 2682
2681 iwl4965_down(priv); 2683 iwl_down(priv);
2682 2684
2683 flush_workqueue(priv->workqueue); 2685 flush_workqueue(priv->workqueue);
2684 free_irq(priv->pci_dev->irq, priv); 2686 free_irq(priv->pci_dev->irq, priv);
@@ -2689,7 +2691,7 @@ static void iwl4965_mac_stop(struct ieee80211_hw *hw)
2689 IWL_DEBUG_MAC80211("leave\n"); 2691 IWL_DEBUG_MAC80211("leave\n");
2690} 2692}
2691 2693
2692static int iwl4965_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb) 2694static int iwl_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
2693{ 2695{
2694 struct iwl_priv *priv = hw->priv; 2696 struct iwl_priv *priv = hw->priv;
2695 2697
@@ -2705,7 +2707,7 @@ static int iwl4965_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
2705 return 0; 2707 return 0;
2706} 2708}
2707 2709
2708static int iwl4965_mac_add_interface(struct ieee80211_hw *hw, 2710static int iwl_mac_add_interface(struct ieee80211_hw *hw,
2709 struct ieee80211_if_init_conf *conf) 2711 struct ieee80211_if_init_conf *conf)
2710{ 2712{
2711 struct iwl_priv *priv = hw->priv; 2713 struct iwl_priv *priv = hw->priv;
@@ -2720,6 +2722,7 @@ static int iwl4965_mac_add_interface(struct ieee80211_hw *hw,
2720 2722
2721 spin_lock_irqsave(&priv->lock, flags); 2723 spin_lock_irqsave(&priv->lock, flags);
2722 priv->vif = conf->vif; 2724 priv->vif = conf->vif;
2725 priv->iw_mode = conf->type;
2723 2726
2724 spin_unlock_irqrestore(&priv->lock, flags); 2727 spin_unlock_irqrestore(&priv->lock, flags);
2725 2728
@@ -2730,7 +2733,7 @@ static int iwl4965_mac_add_interface(struct ieee80211_hw *hw,
2730 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN); 2733 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
2731 } 2734 }
2732 2735
2733 if (iwl4965_set_mode(priv, conf->type) == -EAGAIN) 2736 if (iwl_set_mode(priv, conf->type) == -EAGAIN)
2734 /* we are not ready, will run again when ready */ 2737 /* we are not ready, will run again when ready */
2735 set_bit(STATUS_MODE_PENDING, &priv->status); 2738 set_bit(STATUS_MODE_PENDING, &priv->status);
2736 2739
@@ -2741,13 +2744,13 @@ static int iwl4965_mac_add_interface(struct ieee80211_hw *hw,
2741} 2744}
2742 2745
2743/** 2746/**
2744 * iwl4965_mac_config - mac80211 config callback 2747 * iwl_mac_config - mac80211 config callback
2745 * 2748 *
2746 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to 2749 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
2747 * be set inappropriately and the driver currently sets the hardware up to 2750 * be set inappropriately and the driver currently sets the hardware up to
2748 * use it whenever needed. 2751 * use it whenever needed.
2749 */ 2752 */
2750static int iwl4965_mac_config(struct ieee80211_hw *hw, u32 changed) 2753static int iwl_mac_config(struct ieee80211_hw *hw, u32 changed)
2751{ 2754{
2752 struct iwl_priv *priv = hw->priv; 2755 struct iwl_priv *priv = hw->priv;
2753 const struct iwl_channel_info *ch_info; 2756 const struct iwl_channel_info *ch_info;
@@ -2818,13 +2821,13 @@ static int iwl4965_mac_config(struct ieee80211_hw *hw, u32 changed)
2818 /* The list of supported rates and rate mask can be different 2821 /* The list of supported rates and rate mask can be different
2819 * for each band; since the band may have changed, reset 2822 * for each band; since the band may have changed, reset
2820 * the rate mask to what mac80211 lists */ 2823 * the rate mask to what mac80211 lists */
2821 iwl4965_set_rate(priv); 2824 iwl_set_rate(priv);
2822 2825
2823 spin_unlock_irqrestore(&priv->lock, flags); 2826 spin_unlock_irqrestore(&priv->lock, flags);
2824 2827
2825#ifdef IEEE80211_CONF_CHANNEL_SWITCH 2828#ifdef IEEE80211_CONF_CHANNEL_SWITCH
2826 if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) { 2829 if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
2827 iwl4965_hw_channel_switch(priv, conf->channel); 2830 iwl_hw_channel_switch(priv, conf->channel);
2828 goto out; 2831 goto out;
2829 } 2832 }
2830#endif 2833#endif
@@ -2852,11 +2855,11 @@ static int iwl4965_mac_config(struct ieee80211_hw *hw, u32 changed)
2852 2855
2853 iwl_set_tx_power(priv, conf->power_level, false); 2856 iwl_set_tx_power(priv, conf->power_level, false);
2854 2857
2855 iwl4965_set_rate(priv); 2858 iwl_set_rate(priv);
2856 2859
2857 if (memcmp(&priv->active_rxon, 2860 if (memcmp(&priv->active_rxon,
2858 &priv->staging_rxon, sizeof(priv->staging_rxon))) 2861 &priv->staging_rxon, sizeof(priv->staging_rxon)))
2859 iwl4965_commit_rxon(priv); 2862 iwl_commit_rxon(priv);
2860 else 2863 else
2861 IWL_DEBUG_INFO("No re-sending same RXON configuration.\n"); 2864 IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
2862 2865
@@ -2867,7 +2870,7 @@ out:
2867 return ret; 2870 return ret;
2868} 2871}
2869 2872
2870static void iwl4965_config_ap(struct iwl_priv *priv) 2873static void iwl_config_ap(struct iwl_priv *priv)
2871{ 2874{
2872 int ret = 0; 2875 int ret = 0;
2873 unsigned long flags; 2876 unsigned long flags;
@@ -2880,7 +2883,7 @@ static void iwl4965_config_ap(struct iwl_priv *priv)
2880 2883
2881 /* RXON - unassoc (to set timing command) */ 2884 /* RXON - unassoc (to set timing command) */
2882 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; 2885 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2883 iwl4965_commit_rxon(priv); 2886 iwl_commit_rxon(priv);
2884 2887
2885 /* RXON Timing */ 2888 /* RXON Timing */
2886 iwl_setup_rxon_timing(priv); 2889 iwl_setup_rxon_timing(priv);
@@ -2916,13 +2919,13 @@ static void iwl4965_config_ap(struct iwl_priv *priv)
2916 } 2919 }
2917 /* restore RXON assoc */ 2920 /* restore RXON assoc */
2918 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; 2921 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
2919 iwl4965_commit_rxon(priv); 2922 iwl_commit_rxon(priv);
2920 spin_lock_irqsave(&priv->lock, flags); 2923 spin_lock_irqsave(&priv->lock, flags);
2921 iwl_activate_qos(priv, 1); 2924 iwl_activate_qos(priv, 1);
2922 spin_unlock_irqrestore(&priv->lock, flags); 2925 spin_unlock_irqrestore(&priv->lock, flags);
2923 iwl_rxon_add_station(priv, iwl_bcast_addr, 0); 2926 iwl_rxon_add_station(priv, iwl_bcast_addr, 0);
2924 } 2927 }
2925 iwl4965_send_beacon_cmd(priv); 2928 iwl_send_beacon_cmd(priv);
2926 2929
2927 /* FIXME - we need to add code here to detect a totally new 2930 /* FIXME - we need to add code here to detect a totally new
2928 * configuration, reset the AP, unassoc, rxon timing, assoc, 2931 * configuration, reset the AP, unassoc, rxon timing, assoc,
@@ -2930,14 +2933,13 @@ static void iwl4965_config_ap(struct iwl_priv *priv)
2930} 2933}
2931 2934
2932/* temporary */ 2935/* temporary */
2933static int iwl4965_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb); 2936static int iwl_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb);
2934 2937
2935static int iwl4965_mac_config_interface(struct ieee80211_hw *hw, 2938static int iwl_mac_config_interface(struct ieee80211_hw *hw,
2936 struct ieee80211_vif *vif, 2939 struct ieee80211_vif *vif,
2937 struct ieee80211_if_conf *conf) 2940 struct ieee80211_if_conf *conf)
2938{ 2941{
2939 struct iwl_priv *priv = hw->priv; 2942 struct iwl_priv *priv = hw->priv;
2940 unsigned long flags;
2941 int rc; 2943 int rc;
2942 2944
2943 if (conf == NULL) 2945 if (conf == NULL)
@@ -2953,18 +2955,11 @@ static int iwl4965_mac_config_interface(struct ieee80211_hw *hw,
2953 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif); 2955 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
2954 if (!beacon) 2956 if (!beacon)
2955 return -ENOMEM; 2957 return -ENOMEM;
2956 rc = iwl4965_mac_beacon_update(hw, beacon); 2958 rc = iwl_mac_beacon_update(hw, beacon);
2957 if (rc) 2959 if (rc)
2958 return rc; 2960 return rc;
2959 } 2961 }
2960 2962
2961 if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
2962 (!conf->ssid_len)) {
2963 IWL_DEBUG_MAC80211
2964 ("Leaving in AP mode because HostAPD is not ready.\n");
2965 return 0;
2966 }
2967
2968 if (!iwl_is_alive(priv)) 2963 if (!iwl_is_alive(priv))
2969 return -EAGAIN; 2964 return -EAGAIN;
2970 2965
@@ -3016,9 +3011,9 @@ static int iwl4965_mac_config_interface(struct ieee80211_hw *hw,
3016 memcpy(priv->bssid, conf->bssid, ETH_ALEN); 3011 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
3017 3012
3018 if (priv->iw_mode == NL80211_IFTYPE_AP) 3013 if (priv->iw_mode == NL80211_IFTYPE_AP)
3019 iwl4965_config_ap(priv); 3014 iwl_config_ap(priv);
3020 else { 3015 else {
3021 rc = iwl4965_commit_rxon(priv); 3016 rc = iwl_commit_rxon(priv);
3022 if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc) 3017 if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc)
3023 iwl_rxon_add_station( 3018 iwl_rxon_add_station(
3024 priv, priv->active_rxon.bssid_addr, 1); 3019 priv, priv->active_rxon.bssid_addr, 1);
@@ -3027,26 +3022,17 @@ static int iwl4965_mac_config_interface(struct ieee80211_hw *hw,
3027 } else { 3022 } else {
3028 iwl_scan_cancel_timeout(priv, 100); 3023 iwl_scan_cancel_timeout(priv, 100);
3029 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; 3024 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3030 iwl4965_commit_rxon(priv); 3025 iwl_commit_rxon(priv);
3031 } 3026 }
3032 3027
3033 done: 3028 done:
3034 spin_lock_irqsave(&priv->lock, flags);
3035 if (!conf->ssid_len)
3036 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
3037 else
3038 memcpy(priv->essid, conf->ssid, conf->ssid_len);
3039
3040 priv->essid_len = conf->ssid_len;
3041 spin_unlock_irqrestore(&priv->lock, flags);
3042
3043 IWL_DEBUG_MAC80211("leave\n"); 3029 IWL_DEBUG_MAC80211("leave\n");
3044 mutex_unlock(&priv->mutex); 3030 mutex_unlock(&priv->mutex);
3045 3031
3046 return 0; 3032 return 0;
3047} 3033}
3048 3034
3049static void iwl4965_configure_filter(struct ieee80211_hw *hw, 3035static void iwl_configure_filter(struct ieee80211_hw *hw,
3050 unsigned int changed_flags, 3036 unsigned int changed_flags,
3051 unsigned int *total_flags, 3037 unsigned int *total_flags,
3052 int mc_count, struct dev_addr_list *mc_list) 3038 int mc_count, struct dev_addr_list *mc_list)
@@ -3065,7 +3051,7 @@ static void iwl4965_configure_filter(struct ieee80211_hw *hw,
3065 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL; 3051 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
3066} 3052}
3067 3053
3068static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw, 3054static void iwl_mac_remove_interface(struct ieee80211_hw *hw,
3069 struct ieee80211_if_init_conf *conf) 3055 struct ieee80211_if_init_conf *conf)
3070{ 3056{
3071 struct iwl_priv *priv = hw->priv; 3057 struct iwl_priv *priv = hw->priv;
@@ -3077,13 +3063,11 @@ static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw,
3077 if (iwl_is_ready_rf(priv)) { 3063 if (iwl_is_ready_rf(priv)) {
3078 iwl_scan_cancel_timeout(priv, 100); 3064 iwl_scan_cancel_timeout(priv, 100);
3079 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; 3065 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3080 iwl4965_commit_rxon(priv); 3066 iwl_commit_rxon(priv);
3081 } 3067 }
3082 if (priv->vif == conf->vif) { 3068 if (priv->vif == conf->vif) {
3083 priv->vif = NULL; 3069 priv->vif = NULL;
3084 memset(priv->bssid, 0, ETH_ALEN); 3070 memset(priv->bssid, 0, ETH_ALEN);
3085 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
3086 priv->essid_len = 0;
3087 } 3071 }
3088 mutex_unlock(&priv->mutex); 3072 mutex_unlock(&priv->mutex);
3089 3073
@@ -3092,7 +3076,7 @@ static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw,
3092} 3076}
3093 3077
3094#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6) 3078#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
3095static void iwl4965_bss_info_changed(struct ieee80211_hw *hw, 3079static void iwl_bss_info_changed(struct ieee80211_hw *hw,
3096 struct ieee80211_vif *vif, 3080 struct ieee80211_vif *vif,
3097 struct ieee80211_bss_conf *bss_conf, 3081 struct ieee80211_bss_conf *bss_conf,
3098 u32 changes) 3082 u32 changes)
@@ -3119,7 +3103,7 @@ static void iwl4965_bss_info_changed(struct ieee80211_hw *hw,
3119 } 3103 }
3120 3104
3121 if (changes & BSS_CHANGED_HT) { 3105 if (changes & BSS_CHANGED_HT) {
3122 iwl4965_ht_conf(priv, bss_conf); 3106 iwl_ht_conf(priv, bss_conf);
3123 iwl_set_rxon_chain(priv); 3107 iwl_set_rxon_chain(priv);
3124 } 3108 }
3125 3109
@@ -3142,7 +3126,7 @@ static void iwl4965_bss_info_changed(struct ieee80211_hw *hw,
3142 priv->next_scan_jiffies = jiffies + 3126 priv->next_scan_jiffies = jiffies +
3143 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC; 3127 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
3144 mutex_lock(&priv->mutex); 3128 mutex_lock(&priv->mutex);
3145 iwl4965_post_associate(priv); 3129 iwl_post_associate(priv);
3146 mutex_unlock(&priv->mutex); 3130 mutex_unlock(&priv->mutex);
3147 } else { 3131 } else {
3148 priv->assoc_id = 0; 3132 priv->assoc_id = 0;
@@ -3218,7 +3202,7 @@ out_unlock:
3218 return ret; 3202 return ret;
3219} 3203}
3220 3204
3221static void iwl4965_mac_update_tkip_key(struct ieee80211_hw *hw, 3205static void iwl_mac_update_tkip_key(struct ieee80211_hw *hw,
3222 struct ieee80211_key_conf *keyconf, const u8 *addr, 3206 struct ieee80211_key_conf *keyconf, const u8 *addr,
3223 u32 iv32, u16 *phase1key) 3207 u32 iv32, u16 *phase1key)
3224{ 3208{
@@ -3269,7 +3253,7 @@ static void iwl4965_mac_update_tkip_key(struct ieee80211_hw *hw,
3269 IWL_DEBUG_MAC80211("leave\n"); 3253 IWL_DEBUG_MAC80211("leave\n");
3270} 3254}
3271 3255
3272static int iwl4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, 3256static int iwl_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3273 const u8 *local_addr, const u8 *addr, 3257 const u8 *local_addr, const u8 *addr,
3274 struct ieee80211_key_conf *key) 3258 struct ieee80211_key_conf *key)
3275{ 3259{
@@ -3340,7 +3324,7 @@ static int iwl4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3340 return ret; 3324 return ret;
3341} 3325}
3342 3326
3343static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, u16 queue, 3327static int iwl_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
3344 const struct ieee80211_tx_queue_params *params) 3328 const struct ieee80211_tx_queue_params *params)
3345{ 3329{
3346 struct iwl_priv *priv = hw->priv; 3330 struct iwl_priv *priv = hw->priv;
@@ -3388,7 +3372,7 @@ static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
3388 return 0; 3372 return 0;
3389} 3373}
3390 3374
3391static int iwl4965_mac_ampdu_action(struct ieee80211_hw *hw, 3375static int iwl_mac_ampdu_action(struct ieee80211_hw *hw,
3392 enum ieee80211_ampdu_mlme_action action, 3376 enum ieee80211_ampdu_mlme_action action,
3393 struct ieee80211_sta *sta, u16 tid, u16 *ssn) 3377 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
3394{ 3378{
@@ -3420,7 +3404,7 @@ static int iwl4965_mac_ampdu_action(struct ieee80211_hw *hw,
3420 } 3404 }
3421 return 0; 3405 return 0;
3422} 3406}
3423static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw, 3407static int iwl_mac_get_tx_stats(struct ieee80211_hw *hw,
3424 struct ieee80211_tx_queue_stats *stats) 3408 struct ieee80211_tx_queue_stats *stats)
3425{ 3409{
3426 struct iwl_priv *priv = hw->priv; 3410 struct iwl_priv *priv = hw->priv;
@@ -3455,7 +3439,7 @@ static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw,
3455 return 0; 3439 return 0;
3456} 3440}
3457 3441
3458static int iwl4965_mac_get_stats(struct ieee80211_hw *hw, 3442static int iwl_mac_get_stats(struct ieee80211_hw *hw,
3459 struct ieee80211_low_level_stats *stats) 3443 struct ieee80211_low_level_stats *stats)
3460{ 3444{
3461 struct iwl_priv *priv = hw->priv; 3445 struct iwl_priv *priv = hw->priv;
@@ -3467,7 +3451,7 @@ static int iwl4965_mac_get_stats(struct ieee80211_hw *hw,
3467 return 0; 3451 return 0;
3468} 3452}
3469 3453
3470static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw) 3454static void iwl_mac_reset_tsf(struct ieee80211_hw *hw)
3471{ 3455{
3472 struct iwl_priv *priv = hw->priv; 3456 struct iwl_priv *priv = hw->priv;
3473 unsigned long flags; 3457 unsigned long flags;
@@ -3511,7 +3495,7 @@ static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw)
3511 if (priv->iw_mode != NL80211_IFTYPE_AP) { 3495 if (priv->iw_mode != NL80211_IFTYPE_AP) {
3512 iwl_scan_cancel_timeout(priv, 100); 3496 iwl_scan_cancel_timeout(priv, 100);
3513 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; 3497 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3514 iwl4965_commit_rxon(priv); 3498 iwl_commit_rxon(priv);
3515 } 3499 }
3516 3500
3517 iwl_power_update_mode(priv, 0); 3501 iwl_power_update_mode(priv, 0);
@@ -3534,14 +3518,14 @@ static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw)
3534 return; 3518 return;
3535 } 3519 }
3536 3520
3537 iwl4965_set_rate(priv); 3521 iwl_set_rate(priv);
3538 3522
3539 mutex_unlock(&priv->mutex); 3523 mutex_unlock(&priv->mutex);
3540 3524
3541 IWL_DEBUG_MAC80211("leave\n"); 3525 IWL_DEBUG_MAC80211("leave\n");
3542} 3526}
3543 3527
3544static int iwl4965_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb) 3528static int iwl_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
3545{ 3529{
3546 struct iwl_priv *priv = hw->priv; 3530 struct iwl_priv *priv = hw->priv;
3547 unsigned long flags; 3531 unsigned long flags;
@@ -3578,7 +3562,7 @@ static int iwl4965_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *sk
3578 3562
3579 iwl_reset_qos(priv); 3563 iwl_reset_qos(priv);
3580 3564
3581 iwl4965_post_associate(priv); 3565 iwl_post_associate(priv);
3582 3566
3583 mutex_unlock(&priv->mutex); 3567 mutex_unlock(&priv->mutex);
3584 3568
@@ -3732,7 +3716,7 @@ static ssize_t store_flags(struct device *d,
3732 else { 3716 else {
3733 IWL_DEBUG_INFO("Commit rxon.flags = 0x%04X\n", flags); 3717 IWL_DEBUG_INFO("Commit rxon.flags = 0x%04X\n", flags);
3734 priv->staging_rxon.flags = cpu_to_le32(flags); 3718 priv->staging_rxon.flags = cpu_to_le32(flags);
3735 iwl4965_commit_rxon(priv); 3719 iwl_commit_rxon(priv);
3736 } 3720 }
3737 } 3721 }
3738 mutex_unlock(&priv->mutex); 3722 mutex_unlock(&priv->mutex);
@@ -3773,7 +3757,7 @@ static ssize_t store_filter_flags(struct device *d,
3773 "0x%04X\n", filter_flags); 3757 "0x%04X\n", filter_flags);
3774 priv->staging_rxon.filter_flags = 3758 priv->staging_rxon.filter_flags =
3775 cpu_to_le32(filter_flags); 3759 cpu_to_le32(filter_flags);
3776 iwl4965_commit_rxon(priv); 3760 iwl_commit_rxon(priv);
3777 } 3761 }
3778 } 3762 }
3779 mutex_unlock(&priv->mutex); 3763 mutex_unlock(&priv->mutex);
@@ -3848,7 +3832,7 @@ static ssize_t store_measurement(struct device *d,
3848 3832
3849 IWL_DEBUG_INFO("Invoking measurement of type %d on " 3833 IWL_DEBUG_INFO("Invoking measurement of type %d on "
3850 "channel %d (for '%s')\n", type, params.channel, buf); 3834 "channel %d (for '%s')\n", type, params.channel, buf);
3851 iwl4965_get_measurement(priv, &params, type); 3835 iwl_get_measurement(priv, &params, type);
3852 3836
3853 return count; 3837 return count;
3854} 3838}
@@ -4068,12 +4052,12 @@ static void iwl_setup_deferred_work(struct iwl_priv *priv)
4068 4052
4069 init_waitqueue_head(&priv->wait_command_queue); 4053 init_waitqueue_head(&priv->wait_command_queue);
4070 4054
4071 INIT_WORK(&priv->up, iwl4965_bg_up); 4055 INIT_WORK(&priv->up, iwl_bg_up);
4072 INIT_WORK(&priv->restart, iwl4965_bg_restart); 4056 INIT_WORK(&priv->restart, iwl_bg_restart);
4073 INIT_WORK(&priv->rx_replenish, iwl4965_bg_rx_replenish); 4057 INIT_WORK(&priv->rx_replenish, iwl_bg_rx_replenish);
4074 INIT_WORK(&priv->rf_kill, iwl4965_bg_rf_kill); 4058 INIT_WORK(&priv->rf_kill, iwl_bg_rf_kill);
4075 INIT_WORK(&priv->beacon_update, iwl4965_bg_beacon_update); 4059 INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update);
4076 INIT_WORK(&priv->set_monitor, iwl4965_bg_set_monitor); 4060 INIT_WORK(&priv->set_monitor, iwl_bg_set_monitor);
4077 INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work); 4061 INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
4078 INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start); 4062 INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start);
4079 INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start); 4063 INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start);
@@ -4086,10 +4070,10 @@ static void iwl_setup_deferred_work(struct iwl_priv *priv)
4086 4070
4087 init_timer(&priv->statistics_periodic); 4071 init_timer(&priv->statistics_periodic);
4088 priv->statistics_periodic.data = (unsigned long)priv; 4072 priv->statistics_periodic.data = (unsigned long)priv;
4089 priv->statistics_periodic.function = iwl4965_bg_statistics_periodic; 4073 priv->statistics_periodic.function = iwl_bg_statistics_periodic;
4090 4074
4091 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) 4075 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
4092 iwl4965_irq_tasklet, (unsigned long)priv); 4076 iwl_irq_tasklet, (unsigned long)priv);
4093} 4077}
4094 4078
4095static void iwl_cancel_deferred_work(struct iwl_priv *priv) 4079static void iwl_cancel_deferred_work(struct iwl_priv *priv)
@@ -4105,7 +4089,7 @@ static void iwl_cancel_deferred_work(struct iwl_priv *priv)
4105 del_timer_sync(&priv->statistics_periodic); 4089 del_timer_sync(&priv->statistics_periodic);
4106} 4090}
4107 4091
4108static struct attribute *iwl4965_sysfs_entries[] = { 4092static struct attribute *iwl_sysfs_entries[] = {
4109 &dev_attr_channels.attr, 4093 &dev_attr_channels.attr,
4110 &dev_attr_flags.attr, 4094 &dev_attr_flags.attr,
4111 &dev_attr_filter_flags.attr, 4095 &dev_attr_filter_flags.attr,
@@ -4126,32 +4110,32 @@ static struct attribute *iwl4965_sysfs_entries[] = {
4126 NULL 4110 NULL
4127}; 4111};
4128 4112
4129static struct attribute_group iwl4965_attribute_group = { 4113static struct attribute_group iwl_attribute_group = {
4130 .name = NULL, /* put in device directory */ 4114 .name = NULL, /* put in device directory */
4131 .attrs = iwl4965_sysfs_entries, 4115 .attrs = iwl_sysfs_entries,
4132}; 4116};
4133 4117
4134static struct ieee80211_ops iwl4965_hw_ops = { 4118static struct ieee80211_ops iwl_hw_ops = {
4135 .tx = iwl4965_mac_tx, 4119 .tx = iwl_mac_tx,
4136 .start = iwl4965_mac_start, 4120 .start = iwl_mac_start,
4137 .stop = iwl4965_mac_stop, 4121 .stop = iwl_mac_stop,
4138 .add_interface = iwl4965_mac_add_interface, 4122 .add_interface = iwl_mac_add_interface,
4139 .remove_interface = iwl4965_mac_remove_interface, 4123 .remove_interface = iwl_mac_remove_interface,
4140 .config = iwl4965_mac_config, 4124 .config = iwl_mac_config,
4141 .config_interface = iwl4965_mac_config_interface, 4125 .config_interface = iwl_mac_config_interface,
4142 .configure_filter = iwl4965_configure_filter, 4126 .configure_filter = iwl_configure_filter,
4143 .set_key = iwl4965_mac_set_key, 4127 .set_key = iwl_mac_set_key,
4144 .update_tkip_key = iwl4965_mac_update_tkip_key, 4128 .update_tkip_key = iwl_mac_update_tkip_key,
4145 .get_stats = iwl4965_mac_get_stats, 4129 .get_stats = iwl_mac_get_stats,
4146 .get_tx_stats = iwl4965_mac_get_tx_stats, 4130 .get_tx_stats = iwl_mac_get_tx_stats,
4147 .conf_tx = iwl4965_mac_conf_tx, 4131 .conf_tx = iwl_mac_conf_tx,
4148 .reset_tsf = iwl4965_mac_reset_tsf, 4132 .reset_tsf = iwl_mac_reset_tsf,
4149 .bss_info_changed = iwl4965_bss_info_changed, 4133 .bss_info_changed = iwl_bss_info_changed,
4150 .ampdu_action = iwl4965_mac_ampdu_action, 4134 .ampdu_action = iwl_mac_ampdu_action,
4151 .hw_scan = iwl_mac_hw_scan 4135 .hw_scan = iwl_mac_hw_scan
4152}; 4136};
4153 4137
4154static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 4138static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
4155{ 4139{
4156 int err = 0; 4140 int err = 0;
4157 struct iwl_priv *priv; 4141 struct iwl_priv *priv;
@@ -4169,10 +4153,10 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
4169 if (cfg->mod_params->debug & IWL_DL_INFO) 4153 if (cfg->mod_params->debug & IWL_DL_INFO)
4170 dev_printk(KERN_DEBUG, &(pdev->dev), 4154 dev_printk(KERN_DEBUG, &(pdev->dev),
4171 "Disabling hw_scan\n"); 4155 "Disabling hw_scan\n");
4172 iwl4965_hw_ops.hw_scan = NULL; 4156 iwl_hw_ops.hw_scan = NULL;
4173 } 4157 }
4174 4158
4175 hw = iwl_alloc_all(cfg, &iwl4965_hw_ops); 4159 hw = iwl_alloc_all(cfg, &iwl_hw_ops);
4176 if (!hw) { 4160 if (!hw) {
4177 err = -ENOMEM; 4161 err = -ENOMEM;
4178 goto out; 4162 goto out;
@@ -4300,10 +4284,10 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
4300 * 8. Setup services 4284 * 8. Setup services
4301 ********************/ 4285 ********************/
4302 spin_lock_irqsave(&priv->lock, flags); 4286 spin_lock_irqsave(&priv->lock, flags);
4303 iwl4965_disable_interrupts(priv); 4287 iwl_disable_interrupts(priv);
4304 spin_unlock_irqrestore(&priv->lock, flags); 4288 spin_unlock_irqrestore(&priv->lock, flags);
4305 4289
4306 err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group); 4290 err = sysfs_create_group(&pdev->dev.kobj, &iwl_attribute_group);
4307 if (err) { 4291 if (err) {
4308 IWL_ERROR("failed to create sysfs device attributes\n"); 4292 IWL_ERROR("failed to create sysfs device attributes\n");
4309 goto out_uninit_drv; 4293 goto out_uninit_drv;
@@ -4339,7 +4323,7 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
4339 return 0; 4323 return 0;
4340 4324
4341 out_remove_sysfs: 4325 out_remove_sysfs:
4342 sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group); 4326 sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group);
4343 out_uninit_drv: 4327 out_uninit_drv:
4344 iwl_uninit_drv(priv); 4328 iwl_uninit_drv(priv);
4345 out_free_eeprom: 4329 out_free_eeprom:
@@ -4357,7 +4341,7 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
4357 return err; 4341 return err;
4358} 4342}
4359 4343
4360static void __devexit iwl4965_pci_remove(struct pci_dev *pdev) 4344static void __devexit iwl_pci_remove(struct pci_dev *pdev)
4361{ 4345{
4362 struct iwl_priv *priv = pci_get_drvdata(pdev); 4346 struct iwl_priv *priv = pci_get_drvdata(pdev);
4363 unsigned long flags; 4347 unsigned long flags;
@@ -4368,10 +4352,10 @@ static void __devexit iwl4965_pci_remove(struct pci_dev *pdev)
4368 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n"); 4352 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
4369 4353
4370 iwl_dbgfs_unregister(priv); 4354 iwl_dbgfs_unregister(priv);
4371 sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group); 4355 sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group);
4372 4356
4373 /* ieee80211_unregister_hw call wil cause iwl4965_mac_stop to 4357 /* ieee80211_unregister_hw call wil cause iwl_mac_stop to
4374 * to be called and iwl4965_down since we are removing the device 4358 * to be called and iwl_down since we are removing the device
4375 * we need to set STATUS_EXIT_PENDING bit. 4359 * we need to set STATUS_EXIT_PENDING bit.
4376 */ 4360 */
4377 set_bit(STATUS_EXIT_PENDING, &priv->status); 4361 set_bit(STATUS_EXIT_PENDING, &priv->status);
@@ -4379,20 +4363,20 @@ static void __devexit iwl4965_pci_remove(struct pci_dev *pdev)
4379 ieee80211_unregister_hw(priv->hw); 4363 ieee80211_unregister_hw(priv->hw);
4380 priv->mac80211_registered = 0; 4364 priv->mac80211_registered = 0;
4381 } else { 4365 } else {
4382 iwl4965_down(priv); 4366 iwl_down(priv);
4383 } 4367 }
4384 4368
4385 /* make sure we flush any pending irq or 4369 /* make sure we flush any pending irq or
4386 * tasklet for the driver 4370 * tasklet for the driver
4387 */ 4371 */
4388 spin_lock_irqsave(&priv->lock, flags); 4372 spin_lock_irqsave(&priv->lock, flags);
4389 iwl4965_disable_interrupts(priv); 4373 iwl_disable_interrupts(priv);
4390 spin_unlock_irqrestore(&priv->lock, flags); 4374 spin_unlock_irqrestore(&priv->lock, flags);
4391 4375
4392 iwl_synchronize_irq(priv); 4376 iwl_synchronize_irq(priv);
4393 4377
4394 iwl_rfkill_unregister(priv); 4378 iwl_rfkill_unregister(priv);
4395 iwl4965_dealloc_ucode_pci(priv); 4379 iwl_dealloc_ucode_pci(priv);
4396 4380
4397 if (priv->rxq.bd) 4381 if (priv->rxq.bd)
4398 iwl_rx_queue_free(priv, &priv->rxq); 4382 iwl_rx_queue_free(priv, &priv->rxq);
@@ -4405,7 +4389,7 @@ static void __devexit iwl4965_pci_remove(struct pci_dev *pdev)
4405 /*netif_stop_queue(dev); */ 4389 /*netif_stop_queue(dev); */
4406 flush_workqueue(priv->workqueue); 4390 flush_workqueue(priv->workqueue);
4407 4391
4408 /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes 4392 /* ieee80211_unregister_hw calls iwl_mac_stop, which flushes
4409 * priv->workqueue... so we can't take down the workqueue 4393 * priv->workqueue... so we can't take down the workqueue
4410 * until now... */ 4394 * until now... */
4411 destroy_workqueue(priv->workqueue); 4395 destroy_workqueue(priv->workqueue);
@@ -4426,13 +4410,13 @@ static void __devexit iwl4965_pci_remove(struct pci_dev *pdev)
4426 4410
4427#ifdef CONFIG_PM 4411#ifdef CONFIG_PM
4428 4412
4429static int iwl4965_pci_suspend(struct pci_dev *pdev, pm_message_t state) 4413static int iwl_pci_suspend(struct pci_dev *pdev, pm_message_t state)
4430{ 4414{
4431 struct iwl_priv *priv = pci_get_drvdata(pdev); 4415 struct iwl_priv *priv = pci_get_drvdata(pdev);
4432 4416
4433 if (priv->is_open) { 4417 if (priv->is_open) {
4434 set_bit(STATUS_IN_SUSPEND, &priv->status); 4418 set_bit(STATUS_IN_SUSPEND, &priv->status);
4435 iwl4965_mac_stop(priv->hw); 4419 iwl_mac_stop(priv->hw);
4436 priv->is_open = 1; 4420 priv->is_open = 1;
4437 } 4421 }
4438 4422
@@ -4441,14 +4425,14 @@ static int iwl4965_pci_suspend(struct pci_dev *pdev, pm_message_t state)
4441 return 0; 4425 return 0;
4442} 4426}
4443 4427
4444static int iwl4965_pci_resume(struct pci_dev *pdev) 4428static int iwl_pci_resume(struct pci_dev *pdev)
4445{ 4429{
4446 struct iwl_priv *priv = pci_get_drvdata(pdev); 4430 struct iwl_priv *priv = pci_get_drvdata(pdev);
4447 4431
4448 pci_set_power_state(pdev, PCI_D0); 4432 pci_set_power_state(pdev, PCI_D0);
4449 4433
4450 if (priv->is_open) 4434 if (priv->is_open)
4451 iwl4965_mac_start(priv->hw); 4435 iwl_mac_start(priv->hw);
4452 4436
4453 clear_bit(STATUS_IN_SUSPEND, &priv->status); 4437 clear_bit(STATUS_IN_SUSPEND, &priv->status);
4454 return 0; 4438 return 0;
@@ -4491,15 +4475,15 @@ MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids);
4491static struct pci_driver iwl_driver = { 4475static struct pci_driver iwl_driver = {
4492 .name = DRV_NAME, 4476 .name = DRV_NAME,
4493 .id_table = iwl_hw_card_ids, 4477 .id_table = iwl_hw_card_ids,
4494 .probe = iwl4965_pci_probe, 4478 .probe = iwl_pci_probe,
4495 .remove = __devexit_p(iwl4965_pci_remove), 4479 .remove = __devexit_p(iwl_pci_remove),
4496#ifdef CONFIG_PM 4480#ifdef CONFIG_PM
4497 .suspend = iwl4965_pci_suspend, 4481 .suspend = iwl_pci_suspend,
4498 .resume = iwl4965_pci_resume, 4482 .resume = iwl_pci_resume,
4499#endif 4483#endif
4500}; 4484};
4501 4485
4502static int __init iwl4965_init(void) 4486static int __init iwl_init(void)
4503{ 4487{
4504 4488
4505 int ret; 4489 int ret;
@@ -4525,11 +4509,11 @@ error_register:
4525 return ret; 4509 return ret;
4526} 4510}
4527 4511
4528static void __exit iwl4965_exit(void) 4512static void __exit iwl_exit(void)
4529{ 4513{
4530 pci_unregister_driver(&iwl_driver); 4514 pci_unregister_driver(&iwl_driver);
4531 iwlagn_rate_control_unregister(); 4515 iwlagn_rate_control_unregister();
4532} 4516}
4533 4517
4534module_exit(iwl4965_exit); 4518module_exit(iwl_exit);
4535module_init(iwl4965_init); 4519module_init(iwl_init);
diff --git a/drivers/net/wireless/iwlwifi/iwl-commands.h b/drivers/net/wireless/iwlwifi/iwl-commands.h
index 5ab74fc0fd10..8aade00e165a 100644
--- a/drivers/net/wireless/iwlwifi/iwl-commands.h
+++ b/drivers/net/wireless/iwlwifi/iwl-commands.h
@@ -66,8 +66,8 @@
66 * Please use iwl-dev.h for driver implementation definitions. 66 * Please use iwl-dev.h for driver implementation definitions.
67 */ 67 */
68 68
69#ifndef __iwl4965_commands_h__ 69#ifndef __iwl_commands_h__
70#define __iwl4965_commands_h__ 70#define __iwl_commands_h__
71 71
72enum { 72enum {
73 REPLY_ALIVE = 0x1, 73 REPLY_ALIVE = 0x1,
@@ -3064,4 +3064,4 @@ struct iwl_rx_packet {
3064 3064
3065#define IWL_RX_FRAME_SIZE (4 + sizeof(struct iwl4965_rx_frame)) 3065#define IWL_RX_FRAME_SIZE (4 + sizeof(struct iwl4965_rx_frame))
3066 3066
3067#endif /* __iwl4965_commands_h__ */ 3067#endif /* __iwl_commands_h__ */
diff --git a/drivers/net/wireless/iwlwifi/iwl-dev.h b/drivers/net/wireless/iwlwifi/iwl-dev.h
index b58fcdef5432..eb396f26730c 100644
--- a/drivers/net/wireless/iwlwifi/iwl-dev.h
+++ b/drivers/net/wireless/iwlwifi/iwl-dev.h
@@ -576,8 +576,8 @@ extern int iwl_send_add_sta(struct iwl_priv *priv,
576 struct iwl_addsta_cmd *sta, u8 flags); 576 struct iwl_addsta_cmd *sta, u8 flags);
577extern u8 iwl_add_station_flags(struct iwl_priv *priv, const u8 *addr, 577extern u8 iwl_add_station_flags(struct iwl_priv *priv, const u8 *addr,
578 int is_ap, u8 flags, struct ieee80211_sta_ht_cap *ht_info); 578 int is_ap, u8 flags, struct ieee80211_sta_ht_cap *ht_info);
579extern void iwl4965_update_chain_flags(struct iwl_priv *priv); 579extern void iwl_update_chain_flags(struct iwl_priv *priv);
580extern int iwl4965_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src); 580extern int iwl_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src);
581extern const u8 iwl_bcast_addr[ETH_ALEN]; 581extern const u8 iwl_bcast_addr[ETH_ALEN];
582extern int iwl_rxq_stop(struct iwl_priv *priv); 582extern int iwl_rxq_stop(struct iwl_priv *priv);
583extern void iwl_txq_ctx_stop(struct iwl_priv *priv); 583extern void iwl_txq_ctx_stop(struct iwl_priv *priv);
@@ -926,8 +926,6 @@ struct iwl_priv {
926 unsigned long last_statistics_time; 926 unsigned long last_statistics_time;
927 927
928 /* context information */ 928 /* context information */
929 u8 essid[IW_ESSID_MAX_SIZE];
930 u8 essid_len;
931 u16 rates_mask; 929 u16 rates_mask;
932 930
933 u32 power_mode; 931 u32 power_mode;
diff --git a/drivers/net/wireless/iwlwifi/iwl-fh.h b/drivers/net/wireless/iwlwifi/iwl-fh.h
index f2688d551830..97e2cf41258d 100644
--- a/drivers/net/wireless/iwlwifi/iwl-fh.h
+++ b/drivers/net/wireless/iwlwifi/iwl-fh.h
@@ -318,34 +318,40 @@
318#define FH_TCSR_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xE60) 318#define FH_TCSR_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xE60)
319 319
320/* Find Control/Status reg for given Tx DMA/FIFO channel */ 320/* Find Control/Status reg for given Tx DMA/FIFO channel */
321#define FH_TCSR_CHNL_TX_CONFIG_REG(_chnl) \ 321#define FH49_TCSR_CHNL_NUM (7)
322 (FH_TCSR_LOWER_BOUND + 0x20 * _chnl) 322#define FH50_TCSR_CHNL_NUM (8)
323 323
324#define FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_DISABLE_VAL (0x00000000) 324#define FH_TCSR_CHNL_TX_CONFIG_REG(_chnl) \
325#define FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE_VAL (0x00000008) 325 (FH_TCSR_LOWER_BOUND + 0x20 * (_chnl))
326#define FH_TCSR_CHNL_TX_CREDIT_REG(_chnl) \
327 (FH_TCSR_LOWER_BOUND + 0x20 * (_chnl) + 0x4)
328#define FH_TCSR_CHNL_TX_BUF_STS_REG(_chnl) \
329 (FH_TCSR_LOWER_BOUND + 0x20 * (_chnl) + 0x8)
326 330
327#define FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE (0x00000000) 331#define FH_TCSR_TX_CONFIG_REG_VAL_MSG_MODE_TXF (0x00000000)
328#define FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE_EOF (0x40000000) 332#define FH_TCSR_TX_CONFIG_REG_VAL_MSG_MODE_DRV (0x00000001)
329#define FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE (0x80000000)
330 333
331#define FH_TCSR_CHNL_NUM (7) 334#define FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_DISABLE (0x00000000)
335#define FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE (0x00000008)
332 336
333#define FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_EMPTY (0x00000000) 337#define FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_NOINT (0x00000000)
334#define FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_WAIT (0x00002000) 338#define FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_ENDTFD (0x00100000)
335#define FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_VALID (0x00000003) 339#define FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_IFTFD (0x00200000)
336 340
337#define FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_NOINT (0x00000000) 341#define FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_RTC_NOINT (0x00000000)
338#define FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_ENDTFD (0x00100000) 342#define FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_RTC_ENDTFD (0x00400000)
339#define FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_IFTFD (0x00200000) 343#define FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_RTC_IFTFD (0x00800000)
340 344
341#define FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_NUM (20) 345#define FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE (0x00000000)
342#define FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_IDX (12) 346#define FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE_EOF (0x40000000)
343#define FH_TCSR_CHNL_TX_CONFIG_REG(_chnl) \ 347#define FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE (0x80000000)
344 (FH_TCSR_LOWER_BOUND + 0x20 * _chnl) 348
345#define FH_TCSR_CHNL_TX_CREDIT_REG(_chnl) \ 349#define FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_EMPTY (0x00000000)
346 (FH_TCSR_LOWER_BOUND + 0x20 * _chnl + 0x4) 350#define FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_WAIT (0x00002000)
347#define FH_TCSR_CHNL_TX_BUF_STS_REG(_chnl) \ 351#define FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_VALID (0x00000003)
348 (FH_TCSR_LOWER_BOUND + 0x20 * _chnl + 0x8) 352
353#define FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_NUM (20)
354#define FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_IDX (12)
349 355
350/** 356/**
351 * Tx Shared Status Registers (TSSR) 357 * Tx Shared Status Registers (TSSR)
@@ -362,7 +368,7 @@
362#define FH_TSSR_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xEA0) 368#define FH_TSSR_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xEA0)
363#define FH_TSSR_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xEC0) 369#define FH_TSSR_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xEC0)
364 370
365#define FH_TSSR_TX_STATUS_REG (FH_TSSR_LOWER_BOUND + 0x010) 371#define FH_TSSR_TX_STATUS_REG (FH_TSSR_LOWER_BOUND + 0x010)
366 372
367#define FH_TSSR_TX_STATUS_REG_BIT_BUFS_EMPTY(_chnl) ((1 << (_chnl)) << 24) 373#define FH_TSSR_TX_STATUS_REG_BIT_BUFS_EMPTY(_chnl) ((1 << (_chnl)) << 24)
368#define FH_TSSR_TX_STATUS_REG_BIT_NO_PEND_REQ(_chnl) ((1 << (_chnl)) << 16) 374#define FH_TSSR_TX_STATUS_REG_BIT_NO_PEND_REQ(_chnl) ((1 << (_chnl)) << 16)
diff --git a/drivers/net/wireless/iwlwifi/iwl-scan.c b/drivers/net/wireless/iwlwifi/iwl-scan.c
index 6c5654f70a06..c4b90301e9a1 100644
--- a/drivers/net/wireless/iwlwifi/iwl-scan.c
+++ b/drivers/net/wireless/iwlwifi/iwl-scan.c
@@ -743,13 +743,6 @@ static void iwl_bg_request_scan(struct work_struct *data)
743 memcpy(scan->direct_scan[0].ssid, 743 memcpy(scan->direct_scan[0].ssid,
744 priv->direct_ssid, priv->direct_ssid_len); 744 priv->direct_ssid, priv->direct_ssid_len);
745 n_probes++; 745 n_probes++;
746 } else if (!iwl_is_associated(priv) && priv->essid_len) {
747 IWL_DEBUG_SCAN("Start direct scan for '%s' (not associated)\n",
748 print_ssid(ssid, priv->essid, priv->essid_len));
749 scan->direct_scan[0].id = WLAN_EID_SSID;
750 scan->direct_scan[0].len = priv->essid_len;
751 memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len);
752 n_probes++;
753 } else { 746 } else {
754 IWL_DEBUG_SCAN("Start indirect scan.\n"); 747 IWL_DEBUG_SCAN("Start indirect scan.\n");
755 } 748 }
diff --git a/drivers/net/wireless/iwlwifi/iwl-sta.c b/drivers/net/wireless/iwlwifi/iwl-sta.c
index bfc009ce8a94..0c5f1221b8f3 100644
--- a/drivers/net/wireless/iwlwifi/iwl-sta.c
+++ b/drivers/net/wireless/iwlwifi/iwl-sta.c
@@ -870,7 +870,7 @@ static void iwl_sta_init_lq(struct iwl_priv *priv, const u8 *addr, int is_ap)
870 870
871 link_cmd.rs_table[i].rate_n_flags = 871 link_cmd.rs_table[i].rate_n_flags =
872 iwl_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags); 872 iwl_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags);
873 r = iwl4965_get_prev_ieee_rate(r); 873 r = iwl_get_prev_ieee_rate(r);
874 } 874 }
875 875
876 link_cmd.general_params.single_stream_ant_msk = 876 link_cmd.general_params.single_stream_ant_msk =
diff --git a/drivers/net/wireless/iwlwifi/iwl-tx.c b/drivers/net/wireless/iwlwifi/iwl-tx.c
index 6008c0cce214..7d8b4e2d5094 100644
--- a/drivers/net/wireless/iwlwifi/iwl-tx.c
+++ b/drivers/net/wireless/iwlwifi/iwl-tx.c
@@ -431,8 +431,8 @@ static int iwl_hw_tx_queue_init(struct iwl_priv *priv,
431 431
432 /* Enable DMA channel, using same id as for TFD queue */ 432 /* Enable DMA channel, using same id as for TFD queue */
433 iwl_write_direct32(priv, FH_TCSR_CHNL_TX_CONFIG_REG(txq_id), 433 iwl_write_direct32(priv, FH_TCSR_CHNL_TX_CONFIG_REG(txq_id),
434 FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE | 434 FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
435 FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE_VAL); 435 FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE);
436 436
437 iwl_release_nic_access(priv); 437 iwl_release_nic_access(priv);
438 spin_unlock_irqrestore(&priv->lock, flags); 438 spin_unlock_irqrestore(&priv->lock, flags);
diff --git a/drivers/net/wireless/iwlwifi/iwl3945-base.c b/drivers/net/wireless/iwlwifi/iwl3945-base.c
index f675b2993a3d..119185fb1e26 100644
--- a/drivers/net/wireless/iwlwifi/iwl3945-base.c
+++ b/drivers/net/wireless/iwlwifi/iwl3945-base.c
@@ -1593,7 +1593,7 @@ static u16 iwl3945_supported_rate_to_ie(u8 *ie, u16 supported_rate,
1593 */ 1593 */
1594static u16 iwl3945_fill_probe_req(struct iwl3945_priv *priv, 1594static u16 iwl3945_fill_probe_req(struct iwl3945_priv *priv,
1595 struct ieee80211_mgmt *frame, 1595 struct ieee80211_mgmt *frame,
1596 int left, int is_direct) 1596 int left)
1597{ 1597{
1598 int len = 0; 1598 int len = 0;
1599 u8 *pos = NULL; 1599 u8 *pos = NULL;
@@ -1623,20 +1623,6 @@ static u16 iwl3945_fill_probe_req(struct iwl3945_priv *priv,
1623 *pos++ = WLAN_EID_SSID; 1623 *pos++ = WLAN_EID_SSID;
1624 *pos++ = 0; 1624 *pos++ = 0;
1625 1625
1626 /* fill in our direct SSID IE... */
1627 if (is_direct) {
1628 /* ...next IE... */
1629 left -= 2 + priv->essid_len;
1630 if (left < 0)
1631 return 0;
1632 /* ... fill it in... */
1633 *pos++ = WLAN_EID_SSID;
1634 *pos++ = priv->essid_len;
1635 memcpy(pos, priv->essid, priv->essid_len);
1636 pos += priv->essid_len;
1637 len += 2 + priv->essid_len;
1638 }
1639
1640 /* fill in supported rate */ 1626 /* fill in supported rate */
1641 /* ...next IE... */ 1627 /* ...next IE... */
1642 left -= 2; 1628 left -= 2;
@@ -2189,13 +2175,14 @@ static void iwl3945_set_flags_for_phymode(struct iwl3945_priv *priv,
2189/* 2175/*
2190 * initialize rxon structure with default values from eeprom 2176 * initialize rxon structure with default values from eeprom
2191 */ 2177 */
2192static void iwl3945_connection_init_rx_config(struct iwl3945_priv *priv) 2178static void iwl3945_connection_init_rx_config(struct iwl3945_priv *priv,
2179 int mode)
2193{ 2180{
2194 const struct iwl3945_channel_info *ch_info; 2181 const struct iwl3945_channel_info *ch_info;
2195 2182
2196 memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon)); 2183 memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
2197 2184
2198 switch (priv->iw_mode) { 2185 switch (mode) {
2199 case NL80211_IFTYPE_AP: 2186 case NL80211_IFTYPE_AP:
2200 priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP; 2187 priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP;
2201 break; 2188 break;
@@ -2218,7 +2205,7 @@ static void iwl3945_connection_init_rx_config(struct iwl3945_priv *priv)
2218 RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK; 2205 RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK;
2219 break; 2206 break;
2220 default: 2207 default:
2221 IWL_ERROR("Unsupported interface type %d\n", priv->iw_mode); 2208 IWL_ERROR("Unsupported interface type %d\n", mode);
2222 break; 2209 break;
2223 } 2210 }
2224 2211
@@ -2241,8 +2228,7 @@ static void iwl3945_connection_init_rx_config(struct iwl3945_priv *priv)
2241 * in some case A channels are all non IBSS 2228 * in some case A channels are all non IBSS
2242 * in this case force B/G channel 2229 * in this case force B/G channel
2243 */ 2230 */
2244 if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) && 2231 if ((mode == NL80211_IFTYPE_ADHOC) && !(is_channel_ibss(ch_info)))
2245 !(is_channel_ibss(ch_info)))
2246 ch_info = &priv->channel_info[0]; 2232 ch_info = &priv->channel_info[0];
2247 2233
2248 priv->staging_rxon.channel = cpu_to_le16(ch_info->channel); 2234 priv->staging_rxon.channel = cpu_to_le16(ch_info->channel);
@@ -2275,9 +2261,7 @@ static int iwl3945_set_mode(struct iwl3945_priv *priv, int mode)
2275 } 2261 }
2276 } 2262 }
2277 2263
2278 priv->iw_mode = mode; 2264 iwl3945_connection_init_rx_config(priv, mode);
2279
2280 iwl3945_connection_init_rx_config(priv);
2281 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); 2265 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
2282 2266
2283 iwl3945_clear_stations_table(priv); 2267 iwl3945_clear_stations_table(priv);
@@ -5699,7 +5683,7 @@ static void iwl3945_alive_start(struct iwl3945_priv *priv)
5699 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; 5683 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
5700 } else { 5684 } else {
5701 /* Initialize our rx_config data */ 5685 /* Initialize our rx_config data */
5702 iwl3945_connection_init_rx_config(priv); 5686 iwl3945_connection_init_rx_config(priv, priv->iw_mode);
5703 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); 5687 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
5704 } 5688 }
5705 5689
@@ -6015,6 +5999,7 @@ static void iwl3945_bg_set_monitor(struct work_struct *work)
6015 IWL_ERROR("iwl3945_set_mode() failed\n"); 5999 IWL_ERROR("iwl3945_set_mode() failed\n");
6016 6000
6017 mutex_unlock(&priv->mutex); 6001 mutex_unlock(&priv->mutex);
6002 ieee80211_notify_mac(priv->hw, IEEE80211_NOTIFY_RE_ASSOC);
6018} 6003}
6019 6004
6020#define IWL_SCAN_CHECK_WATCHDOG (7 * HZ) 6005#define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
@@ -6162,14 +6147,6 @@ static void iwl3945_bg_request_scan(struct work_struct *data)
6162 memcpy(scan->direct_scan[0].ssid, 6147 memcpy(scan->direct_scan[0].ssid,
6163 priv->direct_ssid, priv->direct_ssid_len); 6148 priv->direct_ssid, priv->direct_ssid_len);
6164 n_probes++; 6149 n_probes++;
6165 } else if (!iwl3945_is_associated(priv) && priv->essid_len) {
6166 IWL_DEBUG_SCAN
6167 ("Kicking off one direct scan for '%s' when not associated\n",
6168 print_ssid(ssid, priv->essid, priv->essid_len));
6169 scan->direct_scan[0].id = WLAN_EID_SSID;
6170 scan->direct_scan[0].len = priv->essid_len;
6171 memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len);
6172 n_probes++;
6173 } else 6150 } else
6174 IWL_DEBUG_SCAN("Kicking off one indirect scan.\n"); 6151 IWL_DEBUG_SCAN("Kicking off one indirect scan.\n");
6175 6152
@@ -6177,7 +6154,7 @@ static void iwl3945_bg_request_scan(struct work_struct *data)
6177 * that based on the direct_mask added to each channel entry */ 6154 * that based on the direct_mask added to each channel entry */
6178 scan->tx_cmd.len = cpu_to_le16( 6155 scan->tx_cmd.len = cpu_to_le16(
6179 iwl3945_fill_probe_req(priv, (struct ieee80211_mgmt *)scan->data, 6156 iwl3945_fill_probe_req(priv, (struct ieee80211_mgmt *)scan->data,
6180 IWL_MAX_SCAN_SIZE - sizeof(*scan), 0)); 6157 IWL_MAX_SCAN_SIZE - sizeof(*scan)));
6181 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK; 6158 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
6182 scan->tx_cmd.sta_id = priv->hw_setting.bcast_sta_id; 6159 scan->tx_cmd.sta_id = priv->hw_setting.bcast_sta_id;
6183 scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; 6160 scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
@@ -6566,6 +6543,7 @@ static int iwl3945_mac_add_interface(struct ieee80211_hw *hw,
6566 6543
6567 spin_lock_irqsave(&priv->lock, flags); 6544 spin_lock_irqsave(&priv->lock, flags);
6568 priv->vif = conf->vif; 6545 priv->vif = conf->vif;
6546 priv->iw_mode = conf->type;
6569 6547
6570 spin_unlock_irqrestore(&priv->lock, flags); 6548 spin_unlock_irqrestore(&priv->lock, flags);
6571 6549
@@ -6742,7 +6720,6 @@ static int iwl3945_mac_config_interface(struct ieee80211_hw *hw,
6742 struct ieee80211_if_conf *conf) 6720 struct ieee80211_if_conf *conf)
6743{ 6721{
6744 struct iwl3945_priv *priv = hw->priv; 6722 struct iwl3945_priv *priv = hw->priv;
6745 unsigned long flags;
6746 int rc; 6723 int rc;
6747 6724
6748 if (conf == NULL) 6725 if (conf == NULL)
@@ -6764,15 +6741,6 @@ static int iwl3945_mac_config_interface(struct ieee80211_hw *hw,
6764 return rc; 6741 return rc;
6765 } 6742 }
6766 6743
6767 /* XXX: this MUST use conf->mac_addr */
6768
6769 if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
6770 (!conf->ssid_len)) {
6771 IWL_DEBUG_MAC80211
6772 ("Leaving in AP mode because HostAPD is not ready.\n");
6773 return 0;
6774 }
6775
6776 if (!iwl3945_is_alive(priv)) 6744 if (!iwl3945_is_alive(priv))
6777 return -EAGAIN; 6745 return -EAGAIN;
6778 6746
@@ -6839,15 +6807,6 @@ static int iwl3945_mac_config_interface(struct ieee80211_hw *hw,
6839 } 6807 }
6840 6808
6841 done: 6809 done:
6842 spin_lock_irqsave(&priv->lock, flags);
6843 if (!conf->ssid_len)
6844 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
6845 else
6846 memcpy(priv->essid, conf->ssid, conf->ssid_len);
6847
6848 priv->essid_len = conf->ssid_len;
6849 spin_unlock_irqrestore(&priv->lock, flags);
6850
6851 IWL_DEBUG_MAC80211("leave\n"); 6810 IWL_DEBUG_MAC80211("leave\n");
6852 mutex_unlock(&priv->mutex); 6811 mutex_unlock(&priv->mutex);
6853 6812
@@ -6890,8 +6849,6 @@ static void iwl3945_mac_remove_interface(struct ieee80211_hw *hw,
6890 if (priv->vif == conf->vif) { 6849 if (priv->vif == conf->vif) {
6891 priv->vif = NULL; 6850 priv->vif = NULL;
6892 memset(priv->bssid, 0, ETH_ALEN); 6851 memset(priv->bssid, 0, ETH_ALEN);
6893 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
6894 priv->essid_len = 0;
6895 } 6852 }
6896 mutex_unlock(&priv->mutex); 6853 mutex_unlock(&priv->mutex);
6897 6854
diff --git a/drivers/net/wireless/libertas/assoc.c b/drivers/net/wireless/libertas/assoc.c
index 92863780286f..a0e440cd8967 100644
--- a/drivers/net/wireless/libertas/assoc.c
+++ b/drivers/net/wireless/libertas/assoc.c
@@ -2,6 +2,8 @@
2 2
3#include <linux/types.h> 3#include <linux/types.h>
4#include <linux/etherdevice.h> 4#include <linux/etherdevice.h>
5#include <linux/ieee80211.h>
6#include <linux/if_arp.h>
5#include <net/lib80211.h> 7#include <net/lib80211.h>
6 8
7#include "assoc.h" 9#include "assoc.h"
@@ -341,12 +343,12 @@ static int lbs_adhoc_start(struct lbs_private *priv,
341 WARN_ON(!assoc_req->channel); 343 WARN_ON(!assoc_req->channel);
342 344
343 /* set Physical parameter set */ 345 /* set Physical parameter set */
344 cmd.phyparamset.dsparamset.elementid = MFIE_TYPE_DS_SET; 346 cmd.phyparamset.dsparamset.elementid = WLAN_EID_DS_PARAMS;
345 cmd.phyparamset.dsparamset.len = 1; 347 cmd.phyparamset.dsparamset.len = 1;
346 cmd.phyparamset.dsparamset.currentchan = assoc_req->channel; 348 cmd.phyparamset.dsparamset.currentchan = assoc_req->channel;
347 349
348 /* set IBSS parameter set */ 350 /* set IBSS parameter set */
349 cmd.ssparamset.ibssparamset.elementid = MFIE_TYPE_IBSS_SET; 351 cmd.ssparamset.ibssparamset.elementid = WLAN_EID_IBSS_PARAMS;
350 cmd.ssparamset.ibssparamset.len = 2; 352 cmd.ssparamset.ibssparamset.len = 2;
351 cmd.ssparamset.ibssparamset.atimwindow = 0; 353 cmd.ssparamset.ibssparamset.atimwindow = 0;
352 354
@@ -430,8 +432,8 @@ static inline int match_bss_no_security(struct lbs_802_11_security *secinfo,
430{ 432{
431 if (!secinfo->wep_enabled && !secinfo->WPAenabled 433 if (!secinfo->wep_enabled && !secinfo->WPAenabled
432 && !secinfo->WPA2enabled 434 && !secinfo->WPA2enabled
433 && match_bss->wpa_ie[0] != MFIE_TYPE_GENERIC 435 && match_bss->wpa_ie[0] != WLAN_EID_GENERIC
434 && match_bss->rsn_ie[0] != MFIE_TYPE_RSN 436 && match_bss->rsn_ie[0] != WLAN_EID_RSN
435 && !(match_bss->capability & WLAN_CAPABILITY_PRIVACY)) 437 && !(match_bss->capability & WLAN_CAPABILITY_PRIVACY))
436 return 1; 438 return 1;
437 else 439 else
@@ -453,7 +455,7 @@ static inline int match_bss_wpa(struct lbs_802_11_security *secinfo,
453 struct bss_descriptor *match_bss) 455 struct bss_descriptor *match_bss)
454{ 456{
455 if (!secinfo->wep_enabled && secinfo->WPAenabled 457 if (!secinfo->wep_enabled && secinfo->WPAenabled
456 && (match_bss->wpa_ie[0] == MFIE_TYPE_GENERIC) 458 && (match_bss->wpa_ie[0] == WLAN_EID_GENERIC)
457 /* privacy bit may NOT be set in some APs like LinkSys WRT54G 459 /* privacy bit may NOT be set in some APs like LinkSys WRT54G
458 && (match_bss->capability & WLAN_CAPABILITY_PRIVACY) */ 460 && (match_bss->capability & WLAN_CAPABILITY_PRIVACY) */
459 ) 461 )
@@ -466,7 +468,7 @@ static inline int match_bss_wpa2(struct lbs_802_11_security *secinfo,
466 struct bss_descriptor *match_bss) 468 struct bss_descriptor *match_bss)
467{ 469{
468 if (!secinfo->wep_enabled && secinfo->WPA2enabled && 470 if (!secinfo->wep_enabled && secinfo->WPA2enabled &&
469 (match_bss->rsn_ie[0] == MFIE_TYPE_RSN) 471 (match_bss->rsn_ie[0] == WLAN_EID_RSN)
470 /* privacy bit may NOT be set in some APs like LinkSys WRT54G 472 /* privacy bit may NOT be set in some APs like LinkSys WRT54G
471 (match_bss->capability & WLAN_CAPABILITY_PRIVACY) */ 473 (match_bss->capability & WLAN_CAPABILITY_PRIVACY) */
472 ) 474 )
@@ -480,8 +482,8 @@ static inline int match_bss_dynamic_wep(struct lbs_802_11_security *secinfo,
480{ 482{
481 if (!secinfo->wep_enabled && !secinfo->WPAenabled 483 if (!secinfo->wep_enabled && !secinfo->WPAenabled
482 && !secinfo->WPA2enabled 484 && !secinfo->WPA2enabled
483 && (match_bss->wpa_ie[0] != MFIE_TYPE_GENERIC) 485 && (match_bss->wpa_ie[0] != WLAN_EID_GENERIC)
484 && (match_bss->rsn_ie[0] != MFIE_TYPE_RSN) 486 && (match_bss->rsn_ie[0] != WLAN_EID_RSN)
485 && (match_bss->capability & WLAN_CAPABILITY_PRIVACY)) 487 && (match_bss->capability & WLAN_CAPABILITY_PRIVACY))
486 return 1; 488 return 1;
487 else 489 else
diff --git a/drivers/net/wireless/libertas/cmd.c b/drivers/net/wireless/libertas/cmd.c
index 38843c8b919c..957fd5a10a8d 100644
--- a/drivers/net/wireless/libertas/cmd.c
+++ b/drivers/net/wireless/libertas/cmd.c
@@ -5,7 +5,6 @@
5 5
6#include <net/iw_handler.h> 6#include <net/iw_handler.h>
7#include <net/lib80211.h> 7#include <net/lib80211.h>
8#include <net/ieee80211.h>
9#include <linux/kfifo.h> 8#include <linux/kfifo.h>
10#include "host.h" 9#include "host.h"
11#include "hostcmd.h" 10#include "hostcmd.h"
@@ -1071,7 +1070,7 @@ int lbs_mesh_config(struct lbs_private *priv, uint16_t action, uint16_t chan)
1071 1070
1072 switch (action) { 1071 switch (action) {
1073 case CMD_ACT_MESH_CONFIG_START: 1072 case CMD_ACT_MESH_CONFIG_START:
1074 ie->hdr.id = MFIE_TYPE_GENERIC; 1073 ie->id = WLAN_EID_GENERIC;
1075 ie->val.oui[0] = 0x00; 1074 ie->val.oui[0] = 0x00;
1076 ie->val.oui[1] = 0x50; 1075 ie->val.oui[1] = 0x50;
1077 ie->val.oui[2] = 0x43; 1076 ie->val.oui[2] = 0x43;
@@ -1083,7 +1082,7 @@ int lbs_mesh_config(struct lbs_private *priv, uint16_t action, uint16_t chan)
1083 ie->val.mesh_capability = MARVELL_MESH_CAPABILITY; 1082 ie->val.mesh_capability = MARVELL_MESH_CAPABILITY;
1084 ie->val.mesh_id_len = priv->mesh_ssid_len; 1083 ie->val.mesh_id_len = priv->mesh_ssid_len;
1085 memcpy(ie->val.mesh_id, priv->mesh_ssid, priv->mesh_ssid_len); 1084 memcpy(ie->val.mesh_id, priv->mesh_ssid, priv->mesh_ssid_len);
1086 ie->hdr.len = sizeof(struct mrvl_meshie_val) - 1085 ie->len = sizeof(struct mrvl_meshie_val) -
1087 IW_ESSID_MAX_SIZE + priv->mesh_ssid_len; 1086 IW_ESSID_MAX_SIZE + priv->mesh_ssid_len;
1088 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie_val)); 1087 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie_val));
1089 break; 1088 break;
diff --git a/drivers/net/wireless/libertas/dev.h b/drivers/net/wireless/libertas/dev.h
index f6f3753da303..dd682c4cfde8 100644
--- a/drivers/net/wireless/libertas/dev.h
+++ b/drivers/net/wireless/libertas/dev.h
@@ -10,7 +10,6 @@
10#include <linux/wireless.h> 10#include <linux/wireless.h>
11#include <linux/ethtool.h> 11#include <linux/ethtool.h>
12#include <linux/debugfs.h> 12#include <linux/debugfs.h>
13#include <net/ieee80211.h>
14 13
15#include "defs.h" 14#include "defs.h"
16#include "hostcmd.h" 15#include "hostcmd.h"
@@ -278,6 +277,12 @@ struct lbs_private {
278 struct enc_key wpa_mcast_key; 277 struct enc_key wpa_mcast_key;
279 struct enc_key wpa_unicast_key; 278 struct enc_key wpa_unicast_key;
280 279
280/*
281 * In theory, the IE is limited to the IE length, 255,
282 * but in practice 64 bytes are enough.
283 */
284#define MAX_WPA_IE_LEN 64
285
281 /** WPA Information Elements*/ 286 /** WPA Information Elements*/
282 u8 wpa_ie[MAX_WPA_IE_LEN]; 287 u8 wpa_ie[MAX_WPA_IE_LEN];
283 u8 wpa_ie_len; 288 u8 wpa_ie_len;
diff --git a/drivers/net/wireless/libertas/main.c b/drivers/net/wireless/libertas/main.c
index e9d23f68174f..241af7fe44bb 100644
--- a/drivers/net/wireless/libertas/main.c
+++ b/drivers/net/wireless/libertas/main.c
@@ -12,9 +12,8 @@
12#include <linux/kthread.h> 12#include <linux/kthread.h>
13#include <linux/kfifo.h> 13#include <linux/kfifo.h>
14#include <linux/stddef.h> 14#include <linux/stddef.h>
15 15#include <linux/ieee80211.h>
16#include <net/iw_handler.h> 16#include <net/iw_handler.h>
17#include <net/ieee80211.h>
18 17
19#include "host.h" 18#include "host.h"
20#include "decl.h" 19#include "decl.h"
@@ -223,7 +222,7 @@ u8 lbs_data_rate_to_fw_index(u32 rate)
223static ssize_t lbs_anycast_get(struct device *dev, 222static ssize_t lbs_anycast_get(struct device *dev,
224 struct device_attribute *attr, char * buf) 223 struct device_attribute *attr, char * buf)
225{ 224{
226 struct lbs_private *priv = to_net_dev(dev)->priv; 225 struct lbs_private *priv = netdev_priv(to_net_dev(dev));
227 struct cmd_ds_mesh_access mesh_access; 226 struct cmd_ds_mesh_access mesh_access;
228 int ret; 227 int ret;
229 228
@@ -242,7 +241,7 @@ static ssize_t lbs_anycast_get(struct device *dev,
242static ssize_t lbs_anycast_set(struct device *dev, 241static ssize_t lbs_anycast_set(struct device *dev,
243 struct device_attribute *attr, const char * buf, size_t count) 242 struct device_attribute *attr, const char * buf, size_t count)
244{ 243{
245 struct lbs_private *priv = to_net_dev(dev)->priv; 244 struct lbs_private *priv = netdev_priv(to_net_dev(dev));
246 struct cmd_ds_mesh_access mesh_access; 245 struct cmd_ds_mesh_access mesh_access;
247 uint32_t datum; 246 uint32_t datum;
248 int ret; 247 int ret;
@@ -270,7 +269,7 @@ static void lbs_remove_mesh(struct lbs_private *priv);
270static ssize_t lbs_rtap_get(struct device *dev, 269static ssize_t lbs_rtap_get(struct device *dev,
271 struct device_attribute *attr, char * buf) 270 struct device_attribute *attr, char * buf)
272{ 271{
273 struct lbs_private *priv = to_net_dev(dev)->priv; 272 struct lbs_private *priv = netdev_priv(to_net_dev(dev));
274 return snprintf(buf, 5, "0x%X\n", priv->monitormode); 273 return snprintf(buf, 5, "0x%X\n", priv->monitormode);
275} 274}
276 275
@@ -281,7 +280,7 @@ static ssize_t lbs_rtap_set(struct device *dev,
281 struct device_attribute *attr, const char * buf, size_t count) 280 struct device_attribute *attr, const char * buf, size_t count)
282{ 281{
283 int monitor_mode; 282 int monitor_mode;
284 struct lbs_private *priv = to_net_dev(dev)->priv; 283 struct lbs_private *priv = netdev_priv(to_net_dev(dev));
285 284
286 sscanf(buf, "%x", &monitor_mode); 285 sscanf(buf, "%x", &monitor_mode);
287 if (monitor_mode) { 286 if (monitor_mode) {
@@ -332,7 +331,7 @@ static DEVICE_ATTR(lbs_rtap, 0644, lbs_rtap_get, lbs_rtap_set );
332static ssize_t lbs_mesh_get(struct device *dev, 331static ssize_t lbs_mesh_get(struct device *dev,
333 struct device_attribute *attr, char * buf) 332 struct device_attribute *attr, char * buf)
334{ 333{
335 struct lbs_private *priv = to_net_dev(dev)->priv; 334 struct lbs_private *priv = netdev_priv(to_net_dev(dev));
336 return snprintf(buf, 5, "0x%X\n", !!priv->mesh_dev); 335 return snprintf(buf, 5, "0x%X\n", !!priv->mesh_dev);
337} 336}
338 337
@@ -342,7 +341,7 @@ static ssize_t lbs_mesh_get(struct device *dev,
342static ssize_t lbs_mesh_set(struct device *dev, 341static ssize_t lbs_mesh_set(struct device *dev,
343 struct device_attribute *attr, const char * buf, size_t count) 342 struct device_attribute *attr, const char * buf, size_t count)
344{ 343{
345 struct lbs_private *priv = to_net_dev(dev)->priv; 344 struct lbs_private *priv = netdev_priv(to_net_dev(dev));
346 int enable; 345 int enable;
347 int ret, action = CMD_ACT_MESH_CONFIG_STOP; 346 int ret, action = CMD_ACT_MESH_CONFIG_STOP;
348 347
@@ -393,7 +392,7 @@ static struct attribute_group lbs_mesh_attr_group = {
393 */ 392 */
394static int lbs_dev_open(struct net_device *dev) 393static int lbs_dev_open(struct net_device *dev)
395{ 394{
396 struct lbs_private *priv = (struct lbs_private *) dev->priv ; 395 struct lbs_private *priv = netdev_priv(dev) ;
397 int ret = 0; 396 int ret = 0;
398 397
399 lbs_deb_enter(LBS_DEB_NET); 398 lbs_deb_enter(LBS_DEB_NET);
@@ -435,7 +434,7 @@ static int lbs_dev_open(struct net_device *dev)
435 */ 434 */
436static int lbs_mesh_stop(struct net_device *dev) 435static int lbs_mesh_stop(struct net_device *dev)
437{ 436{
438 struct lbs_private *priv = (struct lbs_private *) (dev->priv); 437 struct lbs_private *priv = dev->ml_priv;
439 438
440 lbs_deb_enter(LBS_DEB_MESH); 439 lbs_deb_enter(LBS_DEB_MESH);
441 spin_lock_irq(&priv->driver_lock); 440 spin_lock_irq(&priv->driver_lock);
@@ -462,7 +461,7 @@ static int lbs_mesh_stop(struct net_device *dev)
462 */ 461 */
463static int lbs_eth_stop(struct net_device *dev) 462static int lbs_eth_stop(struct net_device *dev)
464{ 463{
465 struct lbs_private *priv = (struct lbs_private *) dev->priv; 464 struct lbs_private *priv = netdev_priv(dev);
466 465
467 lbs_deb_enter(LBS_DEB_NET); 466 lbs_deb_enter(LBS_DEB_NET);
468 467
@@ -479,7 +478,7 @@ static int lbs_eth_stop(struct net_device *dev)
479 478
480static void lbs_tx_timeout(struct net_device *dev) 479static void lbs_tx_timeout(struct net_device *dev)
481{ 480{
482 struct lbs_private *priv = (struct lbs_private *) dev->priv; 481 struct lbs_private *priv = netdev_priv(dev);
483 482
484 lbs_deb_enter(LBS_DEB_TX); 483 lbs_deb_enter(LBS_DEB_TX);
485 484
@@ -531,7 +530,7 @@ EXPORT_SYMBOL_GPL(lbs_host_to_card_done);
531 */ 530 */
532static struct net_device_stats *lbs_get_stats(struct net_device *dev) 531static struct net_device_stats *lbs_get_stats(struct net_device *dev)
533{ 532{
534 struct lbs_private *priv = (struct lbs_private *) dev->priv; 533 struct lbs_private *priv = netdev_priv(dev);
535 534
536 lbs_deb_enter(LBS_DEB_NET); 535 lbs_deb_enter(LBS_DEB_NET);
537 return &priv->stats; 536 return &priv->stats;
@@ -540,7 +539,7 @@ static struct net_device_stats *lbs_get_stats(struct net_device *dev)
540static int lbs_set_mac_address(struct net_device *dev, void *addr) 539static int lbs_set_mac_address(struct net_device *dev, void *addr)
541{ 540{
542 int ret = 0; 541 int ret = 0;
543 struct lbs_private *priv = (struct lbs_private *) dev->priv; 542 struct lbs_private *priv = netdev_priv(dev);
544 struct sockaddr *phwaddr = addr; 543 struct sockaddr *phwaddr = addr;
545 struct cmd_ds_802_11_mac_address cmd; 544 struct cmd_ds_802_11_mac_address cmd;
546 545
@@ -673,7 +672,7 @@ static void lbs_set_mcast_worker(struct work_struct *work)
673 672
674static void lbs_set_multicast_list(struct net_device *dev) 673static void lbs_set_multicast_list(struct net_device *dev)
675{ 674{
676 struct lbs_private *priv = dev->priv; 675 struct lbs_private *priv = netdev_priv(dev);
677 676
678 schedule_work(&priv->mcast_work); 677 schedule_work(&priv->mcast_work);
679} 678}
@@ -689,7 +688,7 @@ static void lbs_set_multicast_list(struct net_device *dev)
689static int lbs_thread(void *data) 688static int lbs_thread(void *data)
690{ 689{
691 struct net_device *dev = data; 690 struct net_device *dev = data;
692 struct lbs_private *priv = dev->priv; 691 struct lbs_private *priv = netdev_priv(dev);
693 wait_queue_t wait; 692 wait_queue_t wait;
694 693
695 lbs_deb_enter(LBS_DEB_THREAD); 694 lbs_deb_enter(LBS_DEB_THREAD);
@@ -1124,7 +1123,7 @@ struct lbs_private *lbs_add_card(void *card, struct device *dmdev)
1124 lbs_pr_err("init ethX device failed\n"); 1123 lbs_pr_err("init ethX device failed\n");
1125 goto done; 1124 goto done;
1126 } 1125 }
1127 priv = dev->priv; 1126 priv = netdev_priv(dev);
1128 1127
1129 if (lbs_init_adapter(priv)) { 1128 if (lbs_init_adapter(priv)) {
1130 lbs_pr_err("failed to initialize adapter structure.\n"); 1129 lbs_pr_err("failed to initialize adapter structure.\n");
@@ -1377,7 +1376,7 @@ static int lbs_add_mesh(struct lbs_private *priv)
1377 ret = -ENOMEM; 1376 ret = -ENOMEM;
1378 goto done; 1377 goto done;
1379 } 1378 }
1380 mesh_dev->priv = priv; 1379 mesh_dev->ml_priv = priv;
1381 priv->mesh_dev = mesh_dev; 1380 priv->mesh_dev = mesh_dev;
1382 1381
1383 mesh_dev->open = lbs_dev_open; 1382 mesh_dev->open = lbs_dev_open;
@@ -1590,7 +1589,7 @@ static int lbs_rtap_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
1590 1589
1591static struct net_device_stats *lbs_rtap_get_stats(struct net_device *dev) 1590static struct net_device_stats *lbs_rtap_get_stats(struct net_device *dev)
1592{ 1591{
1593 struct lbs_private *priv = dev->priv; 1592 struct lbs_private *priv = dev->ml_priv;
1594 lbs_deb_enter(LBS_DEB_NET); 1593 lbs_deb_enter(LBS_DEB_NET);
1595 return &priv->stats; 1594 return &priv->stats;
1596} 1595}
@@ -1631,7 +1630,7 @@ static int lbs_add_rtap(struct lbs_private *priv)
1631 rtap_dev->stop = lbs_rtap_stop; 1630 rtap_dev->stop = lbs_rtap_stop;
1632 rtap_dev->get_stats = lbs_rtap_get_stats; 1631 rtap_dev->get_stats = lbs_rtap_get_stats;
1633 rtap_dev->hard_start_xmit = lbs_rtap_hard_start_xmit; 1632 rtap_dev->hard_start_xmit = lbs_rtap_hard_start_xmit;
1634 rtap_dev->priv = priv; 1633 rtap_dev->ml_priv = priv;
1635 SET_NETDEV_DEV(rtap_dev, priv->dev->dev.parent); 1634 SET_NETDEV_DEV(rtap_dev, priv->dev->dev.parent);
1636 1635
1637 ret = register_netdev(rtap_dev); 1636 ret = register_netdev(rtap_dev);
diff --git a/drivers/net/wireless/libertas/persistcfg.c b/drivers/net/wireless/libertas/persistcfg.c
index 3309a9c3cfef..56e2401cc768 100644
--- a/drivers/net/wireless/libertas/persistcfg.c
+++ b/drivers/net/wireless/libertas/persistcfg.c
@@ -233,7 +233,7 @@ static ssize_t mesh_id_set(struct device *dev, struct device_attribute *attr,
233 /* SSID len */ 233 /* SSID len */
234 ie->val.mesh_id_len = len; 234 ie->val.mesh_id_len = len;
235 /* IE len */ 235 /* IE len */
236 ie->hdr.len = sizeof(struct mrvl_meshie_val) - IW_ESSID_MAX_SIZE + len; 236 ie->len = sizeof(struct mrvl_meshie_val) - IW_ESSID_MAX_SIZE + len;
237 237
238 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET, 238 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
239 CMD_TYPE_MESH_SET_MESH_IE); 239 CMD_TYPE_MESH_SET_MESH_IE);
diff --git a/drivers/net/wireless/libertas/scan.c b/drivers/net/wireless/libertas/scan.c
index 5c34ac588189..93f74763a010 100644
--- a/drivers/net/wireless/libertas/scan.c
+++ b/drivers/net/wireless/libertas/scan.c
@@ -6,8 +6,8 @@
6 */ 6 */
7#include <linux/types.h> 7#include <linux/types.h>
8#include <linux/etherdevice.h> 8#include <linux/etherdevice.h>
9#include <linux/if_arp.h>
9#include <asm/unaligned.h> 10#include <asm/unaligned.h>
10
11#include <net/lib80211.h> 11#include <net/lib80211.h>
12 12
13#include "host.h" 13#include "host.h"
@@ -55,6 +55,8 @@
55//! Scan time specified in the channel TLV for each channel for active scans 55//! Scan time specified in the channel TLV for each channel for active scans
56#define MRVDRV_ACTIVE_SCAN_CHAN_TIME 100 56#define MRVDRV_ACTIVE_SCAN_CHAN_TIME 100
57 57
58#define DEFAULT_MAX_SCAN_AGE (15 * HZ)
59
58static int lbs_ret_80211_scan(struct lbs_private *priv, unsigned long dummy, 60static int lbs_ret_80211_scan(struct lbs_private *priv, unsigned long dummy,
59 struct cmd_header *resp); 61 struct cmd_header *resp);
60 62
@@ -591,38 +593,36 @@ static int lbs_process_bss(struct bss_descriptor *bss,
591 593
592 /* process variable IE */ 594 /* process variable IE */
593 while (pos <= end - 2) { 595 while (pos <= end - 2) {
594 struct ieee80211_info_element * elem = (void *)pos; 596 if (pos + pos[1] > end) {
595
596 if (pos + elem->len > end) {
597 lbs_deb_scan("process_bss: error in processing IE, " 597 lbs_deb_scan("process_bss: error in processing IE, "
598 "bytes left < IE length\n"); 598 "bytes left < IE length\n");
599 break; 599 break;
600 } 600 }
601 601
602 switch (elem->id) { 602 switch (pos[0]) {
603 case MFIE_TYPE_SSID: 603 case WLAN_EID_SSID:
604 bss->ssid_len = min_t(int, 32, elem->len); 604 bss->ssid_len = min_t(int, IEEE80211_MAX_SSID_LEN, pos[1]);
605 memcpy(bss->ssid, elem->data, bss->ssid_len); 605 memcpy(bss->ssid, pos + 2, bss->ssid_len);
606 lbs_deb_scan("got SSID IE: '%s', len %u\n", 606 lbs_deb_scan("got SSID IE: '%s', len %u\n",
607 print_ssid(ssid, bss->ssid, bss->ssid_len), 607 print_ssid(ssid, bss->ssid, bss->ssid_len),
608 bss->ssid_len); 608 bss->ssid_len);
609 break; 609 break;
610 610
611 case MFIE_TYPE_RATES: 611 case WLAN_EID_SUPP_RATES:
612 n_basic_rates = min_t(uint8_t, MAX_RATES, elem->len); 612 n_basic_rates = min_t(uint8_t, MAX_RATES, pos[1]);
613 memcpy(bss->rates, elem->data, n_basic_rates); 613 memcpy(bss->rates, pos + 2, n_basic_rates);
614 got_basic_rates = 1; 614 got_basic_rates = 1;
615 lbs_deb_scan("got RATES IE\n"); 615 lbs_deb_scan("got RATES IE\n");
616 break; 616 break;
617 617
618 case MFIE_TYPE_FH_SET: 618 case WLAN_EID_FH_PARAMS:
619 pFH = (struct ieeetypes_fhparamset *) pos; 619 pFH = (struct ieeetypes_fhparamset *) pos;
620 memmove(&bss->phyparamset.fhparamset, pFH, 620 memmove(&bss->phyparamset.fhparamset, pFH,
621 sizeof(struct ieeetypes_fhparamset)); 621 sizeof(struct ieeetypes_fhparamset));
622 lbs_deb_scan("got FH IE\n"); 622 lbs_deb_scan("got FH IE\n");
623 break; 623 break;
624 624
625 case MFIE_TYPE_DS_SET: 625 case WLAN_EID_DS_PARAMS:
626 pDS = (struct ieeetypes_dsparamset *) pos; 626 pDS = (struct ieeetypes_dsparamset *) pos;
627 bss->channel = pDS->currentchan; 627 bss->channel = pDS->currentchan;
628 memcpy(&bss->phyparamset.dsparamset, pDS, 628 memcpy(&bss->phyparamset.dsparamset, pDS,
@@ -630,14 +630,14 @@ static int lbs_process_bss(struct bss_descriptor *bss,
630 lbs_deb_scan("got DS IE, channel %d\n", bss->channel); 630 lbs_deb_scan("got DS IE, channel %d\n", bss->channel);
631 break; 631 break;
632 632
633 case MFIE_TYPE_CF_SET: 633 case WLAN_EID_CF_PARAMS:
634 pCF = (struct ieeetypes_cfparamset *) pos; 634 pCF = (struct ieeetypes_cfparamset *) pos;
635 memcpy(&bss->ssparamset.cfparamset, pCF, 635 memcpy(&bss->ssparamset.cfparamset, pCF,
636 sizeof(struct ieeetypes_cfparamset)); 636 sizeof(struct ieeetypes_cfparamset));
637 lbs_deb_scan("got CF IE\n"); 637 lbs_deb_scan("got CF IE\n");
638 break; 638 break;
639 639
640 case MFIE_TYPE_IBSS_SET: 640 case WLAN_EID_IBSS_PARAMS:
641 pibss = (struct ieeetypes_ibssparamset *) pos; 641 pibss = (struct ieeetypes_ibssparamset *) pos;
642 bss->atimwindow = le16_to_cpu(pibss->atimwindow); 642 bss->atimwindow = le16_to_cpu(pibss->atimwindow);
643 memmove(&bss->ssparamset.ibssparamset, pibss, 643 memmove(&bss->ssparamset.ibssparamset, pibss,
@@ -645,7 +645,7 @@ static int lbs_process_bss(struct bss_descriptor *bss,
645 lbs_deb_scan("got IBSS IE\n"); 645 lbs_deb_scan("got IBSS IE\n");
646 break; 646 break;
647 647
648 case MFIE_TYPE_COUNTRY: 648 case WLAN_EID_COUNTRY:
649 pcountryinfo = (struct ieeetypes_countryinfoset *) pos; 649 pcountryinfo = (struct ieeetypes_countryinfoset *) pos;
650 lbs_deb_scan("got COUNTRY IE\n"); 650 lbs_deb_scan("got COUNTRY IE\n");
651 if (pcountryinfo->len < sizeof(pcountryinfo->countrycode) 651 if (pcountryinfo->len < sizeof(pcountryinfo->countrycode)
@@ -662,7 +662,7 @@ static int lbs_process_bss(struct bss_descriptor *bss,
662 (int) (pcountryinfo->len + 2)); 662 (int) (pcountryinfo->len + 2));
663 break; 663 break;
664 664
665 case MFIE_TYPE_RATES_EX: 665 case WLAN_EID_EXT_SUPP_RATES:
666 /* only process extended supported rate if data rate is 666 /* only process extended supported rate if data rate is
667 * already found. Data rate IE should come before 667 * already found. Data rate IE should come before
668 * extended supported rate IE 668 * extended supported rate IE
@@ -673,50 +673,51 @@ static int lbs_process_bss(struct bss_descriptor *bss,
673 break; 673 break;
674 } 674 }
675 675
676 n_ex_rates = elem->len; 676 n_ex_rates = pos[1];
677 if (n_basic_rates + n_ex_rates > MAX_RATES) 677 if (n_basic_rates + n_ex_rates > MAX_RATES)
678 n_ex_rates = MAX_RATES - n_basic_rates; 678 n_ex_rates = MAX_RATES - n_basic_rates;
679 679
680 p = bss->rates + n_basic_rates; 680 p = bss->rates + n_basic_rates;
681 memcpy(p, elem->data, n_ex_rates); 681 memcpy(p, pos + 2, n_ex_rates);
682 break; 682 break;
683 683
684 case MFIE_TYPE_GENERIC: 684 case WLAN_EID_GENERIC:
685 if (elem->len >= 4 && 685 if (pos[1] >= 4 &&
686 elem->data[0] == 0x00 && elem->data[1] == 0x50 && 686 pos[2] == 0x00 && pos[3] == 0x50 &&
687 elem->data[2] == 0xf2 && elem->data[3] == 0x01) { 687 pos[4] == 0xf2 && pos[5] == 0x01) {
688 bss->wpa_ie_len = min(elem->len + 2, MAX_WPA_IE_LEN); 688 bss->wpa_ie_len = min(pos[1] + 2, MAX_WPA_IE_LEN);
689 memcpy(bss->wpa_ie, elem, bss->wpa_ie_len); 689 memcpy(bss->wpa_ie, pos, bss->wpa_ie_len);
690 lbs_deb_scan("got WPA IE\n"); 690 lbs_deb_scan("got WPA IE\n");
691 lbs_deb_hex(LBS_DEB_SCAN, "WPA IE", bss->wpa_ie, elem->len); 691 lbs_deb_hex(LBS_DEB_SCAN, "WPA IE", bss->wpa_ie,
692 } else if (elem->len >= MARVELL_MESH_IE_LENGTH && 692 bss->wpa_ie_len);
693 elem->data[0] == 0x00 && elem->data[1] == 0x50 && 693 } else if (pos[1] >= MARVELL_MESH_IE_LENGTH &&
694 elem->data[2] == 0x43 && elem->data[3] == 0x04) { 694 pos[2] == 0x00 && pos[3] == 0x50 &&
695 pos[4] == 0x43 && pos[4] == 0x04) {
695 lbs_deb_scan("got mesh IE\n"); 696 lbs_deb_scan("got mesh IE\n");
696 bss->mesh = 1; 697 bss->mesh = 1;
697 } else { 698 } else {
698 lbs_deb_scan("got generic IE: %02x:%02x:%02x:%02x, len %d\n", 699 lbs_deb_scan("got generic IE: %02x:%02x:%02x:%02x, len %d\n",
699 elem->data[0], elem->data[1], 700 pos[2], pos[3],
700 elem->data[2], elem->data[3], 701 pos[4], pos[5],
701 elem->len); 702 pos[1]);
702 } 703 }
703 break; 704 break;
704 705
705 case MFIE_TYPE_RSN: 706 case WLAN_EID_RSN:
706 lbs_deb_scan("got RSN IE\n"); 707 lbs_deb_scan("got RSN IE\n");
707 bss->rsn_ie_len = min(elem->len + 2, MAX_WPA_IE_LEN); 708 bss->rsn_ie_len = min(pos[1] + 2, MAX_WPA_IE_LEN);
708 memcpy(bss->rsn_ie, elem, bss->rsn_ie_len); 709 memcpy(bss->rsn_ie, pos, bss->rsn_ie_len);
709 lbs_deb_hex(LBS_DEB_SCAN, "process_bss: RSN_IE", 710 lbs_deb_hex(LBS_DEB_SCAN, "process_bss: RSN_IE",
710 bss->rsn_ie, elem->len); 711 bss->rsn_ie, bss->rsn_ie_len);
711 break; 712 break;
712 713
713 default: 714 default:
714 lbs_deb_scan("got IE 0x%04x, len %d\n", 715 lbs_deb_scan("got IE 0x%04x, len %d\n",
715 elem->id, elem->len); 716 pos[0], pos[1]);
716 break; 717 break;
717 } 718 }
718 719
719 pos += elem->len + 2; 720 pos += pos[1] + 2;
720 } 721 }
721 722
722 /* Timestamp */ 723 /* Timestamp */
diff --git a/drivers/net/wireless/libertas/scan.h b/drivers/net/wireless/libertas/scan.h
index 9e07b0464a8e..fab7d5d097fc 100644
--- a/drivers/net/wireless/libertas/scan.h
+++ b/drivers/net/wireless/libertas/scan.h
@@ -7,6 +7,10 @@
7#ifndef _LBS_SCAN_H 7#ifndef _LBS_SCAN_H
8#define _LBS_SCAN_H 8#define _LBS_SCAN_H
9 9
10#include <net/iw_handler.h>
11
12#define MAX_NETWORK_COUNT 128
13
10/** 14/**
11 * @brief Maximum number of channels that can be sent in a setuserscan ioctl 15 * @brief Maximum number of channels that can be sent in a setuserscan ioctl
12 */ 16 */
diff --git a/drivers/net/wireless/libertas/types.h b/drivers/net/wireless/libertas/types.h
index e0c2599da92f..fb7a2d1a2525 100644
--- a/drivers/net/wireless/libertas/types.h
+++ b/drivers/net/wireless/libertas/types.h
@@ -7,7 +7,6 @@
7#include <linux/if_ether.h> 7#include <linux/if_ether.h>
8#include <asm/byteorder.h> 8#include <asm/byteorder.h>
9#include <linux/wireless.h> 9#include <linux/wireless.h>
10#include <net/ieee80211.h>
11 10
12struct ieeetypes_cfparamset { 11struct ieeetypes_cfparamset {
13 u8 elementid; 12 u8 elementid;
@@ -258,7 +257,7 @@ struct mrvlietypes_ledbhv {
258 * Note that the len member of the ieee80211_info_element varies depending on 257 * Note that the len member of the ieee80211_info_element varies depending on
259 * the mesh_id_len */ 258 * the mesh_id_len */
260struct mrvl_meshie_val { 259struct mrvl_meshie_val {
261 uint8_t oui[P80211_OUI_LEN]; 260 uint8_t oui[3];
262 uint8_t type; 261 uint8_t type;
263 uint8_t subtype; 262 uint8_t subtype;
264 uint8_t version; 263 uint8_t version;
@@ -270,7 +269,7 @@ struct mrvl_meshie_val {
270} __attribute__ ((packed)); 269} __attribute__ ((packed));
271 270
272struct mrvl_meshie { 271struct mrvl_meshie {
273 struct ieee80211_info_element hdr; 272 u8 id, len;
274 struct mrvl_meshie_val val; 273 struct mrvl_meshie_val val;
275} __attribute__ ((packed)); 274} __attribute__ ((packed));
276 275
diff --git a/drivers/net/wireless/libertas/wext.c b/drivers/net/wireless/libertas/wext.c
index d4c6a659b562..fe7498f12147 100644
--- a/drivers/net/wireless/libertas/wext.c
+++ b/drivers/net/wireless/libertas/wext.c
@@ -9,7 +9,6 @@
9#include <linux/bitops.h> 9#include <linux/bitops.h>
10 10
11#include <net/lib80211.h> 11#include <net/lib80211.h>
12#include <net/ieee80211.h>
13#include <net/iw_handler.h> 12#include <net/iw_handler.h>
14 13
15#include "host.h" 14#include "host.h"
diff --git a/drivers/net/wireless/libertas_tf/if_usb.c b/drivers/net/wireless/libertas_tf/if_usb.c
index 1cc03a8dd67a..59634c33b1f9 100644
--- a/drivers/net/wireless/libertas_tf/if_usb.c
+++ b/drivers/net/wireless/libertas_tf/if_usb.c
@@ -331,7 +331,7 @@ static int __if_usb_submit_rx_urb(struct if_usb_card *cardp,
331 /* Fill the receive configuration URB and initialise the Rx call back */ 331 /* Fill the receive configuration URB and initialise the Rx call back */
332 usb_fill_bulk_urb(cardp->rx_urb, cardp->udev, 332 usb_fill_bulk_urb(cardp->rx_urb, cardp->udev,
333 usb_rcvbulkpipe(cardp->udev, cardp->ep_in), 333 usb_rcvbulkpipe(cardp->udev, cardp->ep_in),
334 (void *) (skb->tail), 334 skb_tail_pointer(skb),
335 MRVDRV_ETH_RX_PACKET_BUFFER_SIZE, callbackfn, cardp); 335 MRVDRV_ETH_RX_PACKET_BUFFER_SIZE, callbackfn, cardp);
336 336
337 cardp->rx_urb->transfer_flags |= URB_ZERO_PACKET; 337 cardp->rx_urb->transfer_flags |= URB_ZERO_PACKET;
diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
index c57652325286..b9230da925ee 100644
--- a/drivers/net/wireless/mac80211_hwsim.c
+++ b/drivers/net/wireless/mac80211_hwsim.c
@@ -21,6 +21,7 @@
21#include <linux/if_arp.h> 21#include <linux/if_arp.h>
22#include <linux/rtnetlink.h> 22#include <linux/rtnetlink.h>
23#include <linux/etherdevice.h> 23#include <linux/etherdevice.h>
24#include <linux/debugfs.h>
24 25
25MODULE_AUTHOR("Jouni Malinen"); 26MODULE_AUTHOR("Jouni Malinen");
26MODULE_DESCRIPTION("Software simulator of 802.11 radio(s) for mac80211"); 27MODULE_DESCRIPTION("Software simulator of 802.11 radio(s) for mac80211");
@@ -32,6 +33,9 @@ MODULE_PARM_DESC(radios, "Number of simulated radios");
32 33
33struct hwsim_vif_priv { 34struct hwsim_vif_priv {
34 u32 magic; 35 u32 magic;
36 u8 bssid[ETH_ALEN];
37 bool assoc;
38 u16 aid;
35}; 39};
36 40
37#define HWSIM_VIF_MAGIC 0x69537748 41#define HWSIM_VIF_MAGIC 0x69537748
@@ -132,6 +136,12 @@ struct mac80211_hwsim_data {
132 unsigned int rx_filter; 136 unsigned int rx_filter;
133 int started; 137 int started;
134 struct timer_list beacon_timer; 138 struct timer_list beacon_timer;
139 enum ps_mode {
140 PS_DISABLED, PS_ENABLED, PS_AUTO_POLL, PS_MANUAL_POLL
141 } ps;
142 bool ps_poll_pending;
143 struct dentry *debugfs;
144 struct dentry *debugfs_ps;
135}; 145};
136 146
137 147
@@ -196,6 +206,34 @@ static void mac80211_hwsim_monitor_rx(struct ieee80211_hw *hw,
196} 206}
197 207
198 208
209static bool hwsim_ps_rx_ok(struct mac80211_hwsim_data *data,
210 struct sk_buff *skb)
211{
212 switch (data->ps) {
213 case PS_DISABLED:
214 return true;
215 case PS_ENABLED:
216 return false;
217 case PS_AUTO_POLL:
218 /* TODO: accept (some) Beacons by default and other frames only
219 * if pending PS-Poll has been sent */
220 return true;
221 case PS_MANUAL_POLL:
222 /* Allow unicast frames to own address if there is a pending
223 * PS-Poll */
224 if (data->ps_poll_pending &&
225 memcmp(data->hw->wiphy->perm_addr, skb->data + 4,
226 ETH_ALEN) == 0) {
227 data->ps_poll_pending = false;
228 return true;
229 }
230 return false;
231 }
232
233 return true;
234}
235
236
199static bool mac80211_hwsim_tx_frame(struct ieee80211_hw *hw, 237static bool mac80211_hwsim_tx_frame(struct ieee80211_hw *hw,
200 struct sk_buff *skb) 238 struct sk_buff *skb)
201{ 239{
@@ -212,6 +250,9 @@ static bool mac80211_hwsim_tx_frame(struct ieee80211_hw *hw,
212 rx_status.rate_idx = info->control.rates[0].idx; 250 rx_status.rate_idx = info->control.rates[0].idx;
213 /* TODO: simulate signal strength (and optional packet drop) */ 251 /* TODO: simulate signal strength (and optional packet drop) */
214 252
253 if (data->ps != PS_DISABLED)
254 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
255
215 /* Copy skb to all enabled radios that are on the current frequency */ 256 /* Copy skb to all enabled radios that are on the current frequency */
216 spin_lock(&hwsim_radio_lock); 257 spin_lock(&hwsim_radio_lock);
217 list_for_each_entry(data2, &hwsim_radios, list) { 258 list_for_each_entry(data2, &hwsim_radios, list) {
@@ -221,6 +262,7 @@ static bool mac80211_hwsim_tx_frame(struct ieee80211_hw *hw,
221 continue; 262 continue;
222 263
223 if (!data2->started || !data2->radio_enabled || 264 if (!data2->started || !data2->radio_enabled ||
265 !hwsim_ps_rx_ok(data2, skb) ||
224 data->channel->center_freq != data2->channel->center_freq) 266 data->channel->center_freq != data2->channel->center_freq)
225 continue; 267 continue;
226 268
@@ -290,6 +332,7 @@ static void mac80211_hwsim_stop(struct ieee80211_hw *hw)
290{ 332{
291 struct mac80211_hwsim_data *data = hw->priv; 333 struct mac80211_hwsim_data *data = hw->priv;
292 data->started = 0; 334 data->started = 0;
335 del_timer(&data->beacon_timer);
293 printk(KERN_DEBUG "%s:%s\n", wiphy_name(hw->wiphy), __func__); 336 printk(KERN_DEBUG "%s:%s\n", wiphy_name(hw->wiphy), __func__);
294} 337}
295 338
@@ -403,7 +446,16 @@ static int mac80211_hwsim_config_interface(struct ieee80211_hw *hw,
403 struct ieee80211_vif *vif, 446 struct ieee80211_vif *vif,
404 struct ieee80211_if_conf *conf) 447 struct ieee80211_if_conf *conf)
405{ 448{
449 struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
450
406 hwsim_check_magic(vif); 451 hwsim_check_magic(vif);
452 if (conf->changed & IEEE80211_IFCC_BSSID) {
453 DECLARE_MAC_BUF(mac);
454 printk(KERN_DEBUG "%s:%s: BSSID changed: %s\n",
455 wiphy_name(hw->wiphy), __func__,
456 print_mac(mac, conf->bssid));
457 memcpy(vp->bssid, conf->bssid, ETH_ALEN);
458 }
407 return 0; 459 return 0;
408} 460}
409 461
@@ -412,7 +464,48 @@ static void mac80211_hwsim_bss_info_changed(struct ieee80211_hw *hw,
412 struct ieee80211_bss_conf *info, 464 struct ieee80211_bss_conf *info,
413 u32 changed) 465 u32 changed)
414{ 466{
467 struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
468
415 hwsim_check_magic(vif); 469 hwsim_check_magic(vif);
470
471 printk(KERN_DEBUG "%s:%s(changed=0x%x)\n",
472 wiphy_name(hw->wiphy), __func__, changed);
473
474 if (changed & BSS_CHANGED_ASSOC) {
475 printk(KERN_DEBUG " %s: ASSOC: assoc=%d aid=%d\n",
476 wiphy_name(hw->wiphy), info->assoc, info->aid);
477 vp->assoc = info->assoc;
478 vp->aid = info->aid;
479 }
480
481 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
482 printk(KERN_DEBUG " %s: ERP_CTS_PROT: %d\n",
483 wiphy_name(hw->wiphy), info->use_cts_prot);
484 }
485
486 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
487 printk(KERN_DEBUG " %s: ERP_PREAMBLE: %d\n",
488 wiphy_name(hw->wiphy), info->use_short_preamble);
489 }
490
491 if (changed & BSS_CHANGED_ERP_SLOT) {
492 printk(KERN_DEBUG " %s: ERP_SLOT: %d\n",
493 wiphy_name(hw->wiphy), info->use_short_slot);
494 }
495
496 if (changed & BSS_CHANGED_HT) {
497 printk(KERN_DEBUG " %s: HT: sec_ch_offs=%d width_40_ok=%d "
498 "op_mode=%d\n",
499 wiphy_name(hw->wiphy),
500 info->ht.secondary_channel_offset,
501 info->ht.width_40_ok, info->ht.operation_mode);
502 }
503
504 if (changed & BSS_CHANGED_BASIC_RATES) {
505 printk(KERN_DEBUG " %s: BASIC_RATES: 0x%llx\n",
506 wiphy_name(hw->wiphy),
507 (unsigned long long) info->basic_rates);
508 }
416} 509}
417 510
418static void mac80211_hwsim_sta_notify(struct ieee80211_hw *hw, 511static void mac80211_hwsim_sta_notify(struct ieee80211_hw *hw,
@@ -439,6 +532,17 @@ static int mac80211_hwsim_set_tim(struct ieee80211_hw *hw,
439 return 0; 532 return 0;
440} 533}
441 534
535static int mac80211_hwsim_conf_tx(
536 struct ieee80211_hw *hw, u16 queue,
537 const struct ieee80211_tx_queue_params *params)
538{
539 printk(KERN_DEBUG "%s:%s (queue=%d txop=%d cw_min=%d cw_max=%d "
540 "aifs=%d)\n",
541 wiphy_name(hw->wiphy), __func__, queue,
542 params->txop, params->cw_min, params->cw_max, params->aifs);
543 return 0;
544}
545
442static const struct ieee80211_ops mac80211_hwsim_ops = 546static const struct ieee80211_ops mac80211_hwsim_ops =
443{ 547{
444 .tx = mac80211_hwsim_tx, 548 .tx = mac80211_hwsim_tx,
@@ -452,6 +556,7 @@ static const struct ieee80211_ops mac80211_hwsim_ops =
452 .bss_info_changed = mac80211_hwsim_bss_info_changed, 556 .bss_info_changed = mac80211_hwsim_bss_info_changed,
453 .sta_notify = mac80211_hwsim_sta_notify, 557 .sta_notify = mac80211_hwsim_sta_notify,
454 .set_tim = mac80211_hwsim_set_tim, 558 .set_tim = mac80211_hwsim_set_tim,
559 .conf_tx = mac80211_hwsim_conf_tx,
455}; 560};
456 561
457 562
@@ -468,6 +573,8 @@ static void mac80211_hwsim_free(void)
468 spin_unlock_bh(&hwsim_radio_lock); 573 spin_unlock_bh(&hwsim_radio_lock);
469 574
470 list_for_each_entry(data, &tmplist, list) { 575 list_for_each_entry(data, &tmplist, list) {
576 debugfs_remove(data->debugfs_ps);
577 debugfs_remove(data->debugfs);
471 ieee80211_unregister_hw(data->hw); 578 ieee80211_unregister_hw(data->hw);
472 device_unregister(data->dev); 579 device_unregister(data->dev);
473 ieee80211_free_hw(data->hw); 580 ieee80211_free_hw(data->hw);
@@ -493,6 +600,127 @@ static void hwsim_mon_setup(struct net_device *dev)
493} 600}
494 601
495 602
603static void hwsim_send_ps_poll(void *dat, u8 *mac, struct ieee80211_vif *vif)
604{
605 struct mac80211_hwsim_data *data = dat;
606 struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
607 DECLARE_MAC_BUF(buf);
608 struct sk_buff *skb;
609 struct ieee80211_pspoll *pspoll;
610
611 if (!vp->assoc)
612 return;
613
614 printk(KERN_DEBUG "%s:%s: send PS-Poll to %s for aid %d\n",
615 wiphy_name(data->hw->wiphy), __func__,
616 print_mac(buf, vp->bssid), vp->aid);
617
618 skb = dev_alloc_skb(sizeof(*pspoll));
619 if (!skb)
620 return;
621 pspoll = (void *) skb_put(skb, sizeof(*pspoll));
622 pspoll->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL |
623 IEEE80211_STYPE_PSPOLL |
624 IEEE80211_FCTL_PM);
625 pspoll->aid = cpu_to_le16(0xc000 | vp->aid);
626 memcpy(pspoll->bssid, vp->bssid, ETH_ALEN);
627 memcpy(pspoll->ta, mac, ETH_ALEN);
628 if (data->radio_enabled &&
629 !mac80211_hwsim_tx_frame(data->hw, skb))
630 printk(KERN_DEBUG "%s: PS-Poll frame not ack'ed\n", __func__);
631 dev_kfree_skb(skb);
632}
633
634
635static void hwsim_send_nullfunc(struct mac80211_hwsim_data *data, u8 *mac,
636 struct ieee80211_vif *vif, int ps)
637{
638 struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
639 DECLARE_MAC_BUF(buf);
640 struct sk_buff *skb;
641 struct ieee80211_hdr *hdr;
642
643 if (!vp->assoc)
644 return;
645
646 printk(KERN_DEBUG "%s:%s: send data::nullfunc to %s ps=%d\n",
647 wiphy_name(data->hw->wiphy), __func__,
648 print_mac(buf, vp->bssid), ps);
649
650 skb = dev_alloc_skb(sizeof(*hdr));
651 if (!skb)
652 return;
653 hdr = (void *) skb_put(skb, sizeof(*hdr) - ETH_ALEN);
654 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
655 IEEE80211_STYPE_NULLFUNC |
656 (ps ? IEEE80211_FCTL_PM : 0));
657 hdr->duration_id = cpu_to_le16(0);
658 memcpy(hdr->addr1, vp->bssid, ETH_ALEN);
659 memcpy(hdr->addr2, mac, ETH_ALEN);
660 memcpy(hdr->addr3, vp->bssid, ETH_ALEN);
661 if (data->radio_enabled &&
662 !mac80211_hwsim_tx_frame(data->hw, skb))
663 printk(KERN_DEBUG "%s: nullfunc frame not ack'ed\n", __func__);
664 dev_kfree_skb(skb);
665}
666
667
668static void hwsim_send_nullfunc_ps(void *dat, u8 *mac,
669 struct ieee80211_vif *vif)
670{
671 struct mac80211_hwsim_data *data = dat;
672 hwsim_send_nullfunc(data, mac, vif, 1);
673}
674
675
676static void hwsim_send_nullfunc_no_ps(void *dat, u8 *mac,
677 struct ieee80211_vif *vif)
678{
679 struct mac80211_hwsim_data *data = dat;
680 hwsim_send_nullfunc(data, mac, vif, 0);
681}
682
683
684static int hwsim_fops_ps_read(void *dat, u64 *val)
685{
686 struct mac80211_hwsim_data *data = dat;
687 *val = data->ps;
688 return 0;
689}
690
691static int hwsim_fops_ps_write(void *dat, u64 val)
692{
693 struct mac80211_hwsim_data *data = dat;
694 enum ps_mode old_ps;
695
696 if (val != PS_DISABLED && val != PS_ENABLED && val != PS_AUTO_POLL &&
697 val != PS_MANUAL_POLL)
698 return -EINVAL;
699
700 old_ps = data->ps;
701 data->ps = val;
702
703 if (val == PS_MANUAL_POLL) {
704 ieee80211_iterate_active_interfaces(data->hw,
705 hwsim_send_ps_poll, data);
706 data->ps_poll_pending = true;
707 } else if (old_ps == PS_DISABLED && val != PS_DISABLED) {
708 ieee80211_iterate_active_interfaces(data->hw,
709 hwsim_send_nullfunc_ps,
710 data);
711 } else if (old_ps != PS_DISABLED && val == PS_DISABLED) {
712 ieee80211_iterate_active_interfaces(data->hw,
713 hwsim_send_nullfunc_no_ps,
714 data);
715 }
716
717 return 0;
718}
719
720DEFINE_SIMPLE_ATTRIBUTE(hwsim_fops_ps, hwsim_fops_ps_read, hwsim_fops_ps_write,
721 "%llu\n");
722
723
496static int __init init_mac80211_hwsim(void) 724static int __init init_mac80211_hwsim(void)
497{ 725{
498 int i, err = 0; 726 int i, err = 0;
@@ -584,6 +812,12 @@ static int __init init_mac80211_hwsim(void)
584 wiphy_name(hw->wiphy), 812 wiphy_name(hw->wiphy),
585 hw->wiphy->perm_addr); 813 hw->wiphy->perm_addr);
586 814
815 data->debugfs = debugfs_create_dir("hwsim",
816 hw->wiphy->debugfsdir);
817 data->debugfs_ps = debugfs_create_file("ps", 0666,
818 data->debugfs, data,
819 &hwsim_fops_ps);
820
587 setup_timer(&data->beacon_timer, mac80211_hwsim_beacon, 821 setup_timer(&data->beacon_timer, mac80211_hwsim_beacon,
588 (unsigned long) hw); 822 (unsigned long) hw);
589 823
diff --git a/drivers/net/wireless/orinoco/Makefile b/drivers/net/wireless/orinoco/Makefile
new file mode 100644
index 000000000000..791366e08c50
--- /dev/null
+++ b/drivers/net/wireless/orinoco/Makefile
@@ -0,0 +1,12 @@
1#
2# Makefile for the orinoco wireless device drivers.
3#
4
5obj-$(CONFIG_HERMES) += orinoco.o hermes.o hermes_dld.o
6obj-$(CONFIG_PCMCIA_HERMES) += orinoco_cs.o
7obj-$(CONFIG_APPLE_AIRPORT) += airport.o
8obj-$(CONFIG_PLX_HERMES) += orinoco_plx.o
9obj-$(CONFIG_PCI_HERMES) += orinoco_pci.o
10obj-$(CONFIG_TMD_HERMES) += orinoco_tmd.o
11obj-$(CONFIG_NORTEL_HERMES) += orinoco_nortel.o
12obj-$(CONFIG_PCMCIA_SPECTRUM) += spectrum_cs.o
diff --git a/drivers/net/wireless/airport.c b/drivers/net/wireless/orinoco/airport.c
index ce03a2e865fa..ce03a2e865fa 100644
--- a/drivers/net/wireless/airport.c
+++ b/drivers/net/wireless/orinoco/airport.c
diff --git a/drivers/net/wireless/hermes.c b/drivers/net/wireless/orinoco/hermes.c
index bfa375369df3..bfa375369df3 100644
--- a/drivers/net/wireless/hermes.c
+++ b/drivers/net/wireless/orinoco/hermes.c
diff --git a/drivers/net/wireless/hermes.h b/drivers/net/wireless/orinoco/hermes.h
index 8b13c8fef3dc..8b13c8fef3dc 100644
--- a/drivers/net/wireless/hermes.h
+++ b/drivers/net/wireless/orinoco/hermes.h
diff --git a/drivers/net/wireless/hermes_dld.c b/drivers/net/wireless/orinoco/hermes_dld.c
index d8c626e61a3a..d8c626e61a3a 100644
--- a/drivers/net/wireless/hermes_dld.c
+++ b/drivers/net/wireless/orinoco/hermes_dld.c
diff --git a/drivers/net/wireless/hermes_dld.h b/drivers/net/wireless/orinoco/hermes_dld.h
index 6fcb26277999..6fcb26277999 100644
--- a/drivers/net/wireless/hermes_dld.h
+++ b/drivers/net/wireless/orinoco/hermes_dld.h
diff --git a/drivers/net/wireless/hermes_rid.h b/drivers/net/wireless/orinoco/hermes_rid.h
index 42eb67dea1df..42eb67dea1df 100644
--- a/drivers/net/wireless/hermes_rid.h
+++ b/drivers/net/wireless/orinoco/hermes_rid.h
diff --git a/drivers/net/wireless/orinoco.c b/drivers/net/wireless/orinoco/orinoco.c
index b657a916b1d7..f4ea08f96970 100644
--- a/drivers/net/wireless/orinoco.c
+++ b/drivers/net/wireless/orinoco/orinoco.c
@@ -86,8 +86,8 @@
86#include <linux/firmware.h> 86#include <linux/firmware.h>
87#include <linux/if_arp.h> 87#include <linux/if_arp.h>
88#include <linux/wireless.h> 88#include <linux/wireless.h>
89#include <linux/ieee80211.h>
89#include <net/iw_handler.h> 90#include <net/iw_handler.h>
90#include <net/ieee80211.h>
91 91
92#include <linux/scatterlist.h> 92#include <linux/scatterlist.h>
93#include <linux/crypto.h> 93#include <linux/crypto.h>
@@ -143,7 +143,7 @@ static const u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
143#define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2) 143#define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2)
144 144
145#define ORINOCO_MIN_MTU 256 145#define ORINOCO_MIN_MTU 256
146#define ORINOCO_MAX_MTU (IEEE80211_DATA_LEN - ENCAPS_OVERHEAD) 146#define ORINOCO_MAX_MTU (IEEE80211_MAX_DATA_LEN - ENCAPS_OVERHEAD)
147 147
148#define SYMBOL_MAX_VER_LEN (14) 148#define SYMBOL_MAX_VER_LEN (14)
149#define USER_BAP 0 149#define USER_BAP 0
@@ -392,7 +392,7 @@ static void orinoco_bss_data_init(struct orinoco_private *priv)
392} 392}
393 393
394static inline u8 *orinoco_get_ie(u8 *data, size_t len, 394static inline u8 *orinoco_get_ie(u8 *data, size_t len,
395 enum ieee80211_mfie eid) 395 enum ieee80211_eid eid)
396{ 396{
397 u8 *p = data; 397 u8 *p = data;
398 while ((p + 2) < (data + len)) { 398 while ((p + 2) < (data + len)) {
@@ -409,7 +409,7 @@ static inline u8 *orinoco_get_wpa_ie(u8 *data, size_t len)
409{ 409{
410 u8 *p = data; 410 u8 *p = data;
411 while ((p + 2 + WPA_SELECTOR_LEN) < (data + len)) { 411 while ((p + 2 + WPA_SELECTOR_LEN) < (data + len)) {
412 if ((p[0] == MFIE_TYPE_GENERIC) && 412 if ((p[0] == WLAN_EID_GENERIC) &&
413 (memcmp(&p[2], WPA_OUI_TYPE, WPA_SELECTOR_LEN) == 0)) 413 (memcmp(&p[2], WPA_OUI_TYPE, WPA_SELECTOR_LEN) == 0))
414 return p; 414 return p;
415 p += p[1] + 2; 415 p += p[1] + 2;
@@ -839,7 +839,8 @@ static int orinoco_change_mtu(struct net_device *dev, int new_mtu)
839 if ( (new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU) ) 839 if ( (new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU) )
840 return -EINVAL; 840 return -EINVAL;
841 841
842 if ( (new_mtu + ENCAPS_OVERHEAD + IEEE80211_HLEN) > 842 /* MTU + encapsulation + header length */
843 if ( (new_mtu + ENCAPS_OVERHEAD + sizeof(struct ieee80211_hdr)) >
843 (priv->nicbuf_size - ETH_HLEN) ) 844 (priv->nicbuf_size - ETH_HLEN) )
844 return -EINVAL; 845 return -EINVAL;
845 846
@@ -1254,7 +1255,7 @@ static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
1254 } 1255 }
1255 1256
1256 /* sanity check the length */ 1257 /* sanity check the length */
1257 if (datalen > IEEE80211_DATA_LEN + 12) { 1258 if (datalen > IEEE80211_MAX_DATA_LEN + 12) {
1258 printk(KERN_DEBUG "%s: oversized monitor frame, " 1259 printk(KERN_DEBUG "%s: oversized monitor frame, "
1259 "data length = %d\n", dev->name, datalen); 1260 "data length = %d\n", dev->name, datalen);
1260 stats->rx_length_errors++; 1261 stats->rx_length_errors++;
@@ -1382,7 +1383,7 @@ static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
1382 data. */ 1383 data. */
1383 goto out; 1384 goto out;
1384 } 1385 }
1385 if (length > IEEE80211_DATA_LEN) { 1386 if (length > IEEE80211_MAX_DATA_LEN) {
1386 printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n", 1387 printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
1387 dev->name, length); 1388 dev->name, length);
1388 stats->rx_length_errors++; 1389 stats->rx_length_errors++;
@@ -3285,7 +3286,7 @@ static int orinoco_init(struct net_device *dev)
3285 3286
3286 /* No need to lock, the hw_unavailable flag is already set in 3287 /* No need to lock, the hw_unavailable flag is already set in
3287 * alloc_orinocodev() */ 3288 * alloc_orinocodev() */
3288 priv->nicbuf_size = IEEE80211_FRAME_LEN + ETH_HLEN; 3289 priv->nicbuf_size = IEEE80211_MAX_FRAME_LEN + ETH_HLEN;
3289 3290
3290 /* Initialize the firmware */ 3291 /* Initialize the firmware */
3291 err = hermes_init(hw); 3292 err = hermes_init(hw);
@@ -4681,7 +4682,7 @@ static int orinoco_ioctl_set_encodeext(struct net_device *dev,
4681 /* Determine and validate the key index */ 4682 /* Determine and validate the key index */
4682 idx = encoding->flags & IW_ENCODE_INDEX; 4683 idx = encoding->flags & IW_ENCODE_INDEX;
4683 if (idx) { 4684 if (idx) {
4684 if ((idx < 1) || (idx > WEP_KEYS)) 4685 if ((idx < 1) || (idx > 4))
4685 goto out; 4686 goto out;
4686 idx--; 4687 idx--;
4687 } else 4688 } else
@@ -4786,7 +4787,7 @@ static int orinoco_ioctl_get_encodeext(struct net_device *dev,
4786 4787
4787 idx = encoding->flags & IW_ENCODE_INDEX; 4788 idx = encoding->flags & IW_ENCODE_INDEX;
4788 if (idx) { 4789 if (idx) {
4789 if ((idx < 1) || (idx > WEP_KEYS)) 4790 if ((idx < 1) || (idx > 4))
4790 goto out; 4791 goto out;
4791 idx--; 4792 idx--;
4792 } else 4793 } else
@@ -4949,7 +4950,8 @@ static int orinoco_ioctl_set_genie(struct net_device *dev,
4949 unsigned long flags; 4950 unsigned long flags;
4950 int err = 0; 4951 int err = 0;
4951 4952
4952 if ((wrqu->data.length > MAX_WPA_IE_LEN) || 4953 /* cut off at IEEE80211_MAX_DATA_LEN */
4954 if ((wrqu->data.length > IEEE80211_MAX_DATA_LEN) ||
4953 (wrqu->data.length && (extra == NULL))) 4955 (wrqu->data.length && (extra == NULL)))
4954 return -EINVAL; 4956 return -EINVAL;
4955 4957
@@ -5632,7 +5634,7 @@ static inline char *orinoco_translate_ext_scan(struct net_device *dev,
5632 &iwe, IW_EV_UINT_LEN); 5634 &iwe, IW_EV_UINT_LEN);
5633 } 5635 }
5634 5636
5635 ie = orinoco_get_ie(bss->data, sizeof(bss->data), MFIE_TYPE_DS_SET); 5637 ie = orinoco_get_ie(bss->data, sizeof(bss->data), WLAN_EID_DS_PARAMS);
5636 channel = ie ? ie[2] : 0; 5638 channel = ie ? ie[2] : 0;
5637 if ((channel >= 1) && (channel <= NUM_CHANNELS)) { 5639 if ((channel >= 1) && (channel <= NUM_CHANNELS)) {
5638 /* Add channel and frequency */ 5640 /* Add channel and frequency */
@@ -5682,7 +5684,7 @@ static inline char *orinoco_translate_ext_scan(struct net_device *dev,
5682 } 5684 }
5683 5685
5684 /* RSN IE */ 5686 /* RSN IE */
5685 ie = orinoco_get_ie(bss->data, sizeof(bss->data), MFIE_TYPE_RSN); 5687 ie = orinoco_get_ie(bss->data, sizeof(bss->data), WLAN_EID_RSN);
5686 if (ie) { 5688 if (ie) {
5687 iwe.cmd = IWEVGENIE; 5689 iwe.cmd = IWEVGENIE;
5688 iwe.u.data.length = ie[1] + 2; 5690 iwe.u.data.length = ie[1] + 2;
@@ -5690,7 +5692,7 @@ static inline char *orinoco_translate_ext_scan(struct net_device *dev,
5690 &iwe, ie); 5692 &iwe, ie);
5691 } 5693 }
5692 5694
5693 ie = orinoco_get_ie(bss->data, sizeof(bss->data), MFIE_TYPE_RATES); 5695 ie = orinoco_get_ie(bss->data, sizeof(bss->data), WLAN_EID_SUPP_RATES);
5694 if (ie) { 5696 if (ie) {
5695 char *p = current_ev + iwe_stream_lcp_len(info); 5697 char *p = current_ev + iwe_stream_lcp_len(info);
5696 int i; 5698 int i;
diff --git a/drivers/net/wireless/orinoco.h b/drivers/net/wireless/orinoco/orinoco.h
index 8c2953834923..8c2953834923 100644
--- a/drivers/net/wireless/orinoco.h
+++ b/drivers/net/wireless/orinoco/orinoco.h
diff --git a/drivers/net/wireless/orinoco_cs.c b/drivers/net/wireless/orinoco/orinoco_cs.c
index 6fcf2bda7cdf..6fcf2bda7cdf 100644
--- a/drivers/net/wireless/orinoco_cs.c
+++ b/drivers/net/wireless/orinoco/orinoco_cs.c
diff --git a/drivers/net/wireless/orinoco_nortel.c b/drivers/net/wireless/orinoco/orinoco_nortel.c
index 2fc86596302e..2fc86596302e 100644
--- a/drivers/net/wireless/orinoco_nortel.c
+++ b/drivers/net/wireless/orinoco/orinoco_nortel.c
diff --git a/drivers/net/wireless/orinoco_pci.c b/drivers/net/wireless/orinoco/orinoco_pci.c
index 4ebd638a073e..4ebd638a073e 100644
--- a/drivers/net/wireless/orinoco_pci.c
+++ b/drivers/net/wireless/orinoco/orinoco_pci.c
diff --git a/drivers/net/wireless/orinoco_pci.h b/drivers/net/wireless/orinoco/orinoco_pci.h
index f4e5e06760c1..f4e5e06760c1 100644
--- a/drivers/net/wireless/orinoco_pci.h
+++ b/drivers/net/wireless/orinoco/orinoco_pci.h
diff --git a/drivers/net/wireless/orinoco_plx.c b/drivers/net/wireless/orinoco/orinoco_plx.c
index ef761857bb38..ef761857bb38 100644
--- a/drivers/net/wireless/orinoco_plx.c
+++ b/drivers/net/wireless/orinoco/orinoco_plx.c
diff --git a/drivers/net/wireless/orinoco_tmd.c b/drivers/net/wireless/orinoco/orinoco_tmd.c
index ede24ec309c0..ede24ec309c0 100644
--- a/drivers/net/wireless/orinoco_tmd.c
+++ b/drivers/net/wireless/orinoco/orinoco_tmd.c
diff --git a/drivers/net/wireless/spectrum_cs.c b/drivers/net/wireless/orinoco/spectrum_cs.c
index 852789ad34b3..852789ad34b3 100644
--- a/drivers/net/wireless/spectrum_cs.c
+++ b/drivers/net/wireless/orinoco/spectrum_cs.c
diff --git a/drivers/net/wireless/p54/p54.h b/drivers/net/wireless/p54/p54.h
index eb69b904f651..b585ff65e0e4 100644
--- a/drivers/net/wireless/p54/p54.h
+++ b/drivers/net/wireless/p54/p54.h
@@ -108,6 +108,7 @@ struct p54_common {
108 struct timer_list stats_timer; 108 struct timer_list stats_timer;
109 struct completion stats_comp; 109 struct completion stats_comp;
110 struct sk_buff *cached_stats; 110 struct sk_buff *cached_stats;
111 struct sk_buff *cached_beacon;
111 int noise; 112 int noise;
112 void *eeprom; 113 void *eeprom;
113 struct completion eeprom_comp; 114 struct completion eeprom_comp;
diff --git a/drivers/net/wireless/p54/p54common.c b/drivers/net/wireless/p54/p54common.c
index cf04c721a012..1796b8c6c5b8 100644
--- a/drivers/net/wireless/p54/p54common.c
+++ b/drivers/net/wireless/p54/p54common.c
@@ -9,7 +9,7 @@
9 * - the islsm (softmac prism54) driver, which is: 9 * - the islsm (softmac prism54) driver, which is:
10 * Copyright 2004-2006 Jean-Baptiste Note <jbnote@gmail.com>, et al. 10 * Copyright 2004-2006 Jean-Baptiste Note <jbnote@gmail.com>, et al.
11 * - stlc45xx driver 11 * - stlc45xx driver
12 * C Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). 12 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
13 * 13 *
14 * This program is free software; you can redistribute it and/or modify 14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2 as 15 * it under the terms of the GNU General Public License version 2 as
@@ -214,12 +214,17 @@ int p54_parse_firmware(struct ieee80211_hw *dev, const struct firmware *fw)
214 printk(KERN_INFO "p54: FW rev %s - Softmac protocol %x.%x\n", 214 printk(KERN_INFO "p54: FW rev %s - Softmac protocol %x.%x\n",
215 fw_version, priv->fw_var >> 8, priv->fw_var & 0xff); 215 fw_version, priv->fw_var >> 8, priv->fw_var & 0xff);
216 216
217 if (priv->fw_var < 0x500)
218 printk(KERN_INFO "p54: you are using an obsolete firmware. "
219 "visit http://wireless.kernel.org/en/users/Drivers/p54 "
220 "and grab one for \"kernel >= 2.6.28\"!\n");
221
217 if (priv->fw_var >= 0x300) { 222 if (priv->fw_var >= 0x300) {
218 /* Firmware supports QoS, use it! */ 223 /* Firmware supports QoS, use it! */
219 priv->tx_stats[4].limit = 3; 224 priv->tx_stats[4].limit = 3; /* AC_VO */
220 priv->tx_stats[5].limit = 4; 225 priv->tx_stats[5].limit = 4; /* AC_VI */
221 priv->tx_stats[6].limit = 3; 226 priv->tx_stats[6].limit = 3; /* AC_BE */
222 priv->tx_stats[7].limit = 1; 227 priv->tx_stats[7].limit = 2; /* AC_BK */
223 dev->queues = 4; 228 dev->queues = 4;
224 } 229 }
225 230
@@ -415,6 +420,30 @@ static int p54_parse_eeprom(struct ieee80211_hw *dev, void *eeprom, int len)
415 /* make it overrun */ 420 /* make it overrun */
416 entry_len = len; 421 entry_len = len;
417 break; 422 break;
423 case PDR_MANUFACTURING_PART_NUMBER:
424 case PDR_PDA_VERSION:
425 case PDR_NIC_SERIAL_NUMBER:
426 case PDR_REGULATORY_DOMAIN_LIST:
427 case PDR_TEMPERATURE_TYPE:
428 case PDR_PRISM_PCI_IDENTIFIER:
429 case PDR_COUNTRY_INFORMATION:
430 case PDR_OEM_NAME:
431 case PDR_PRODUCT_NAME:
432 case PDR_UTF8_OEM_NAME:
433 case PDR_UTF8_PRODUCT_NAME:
434 case PDR_COUNTRY_LIST:
435 case PDR_DEFAULT_COUNTRY:
436 case PDR_ANTENNA_GAIN:
437 case PDR_PRISM_INDIGO_PA_CALIBRATION_DATA:
438 case PDR_RSSI_LINEAR_APPROXIMATION:
439 case PDR_RSSI_LINEAR_APPROXIMATION_DUAL_BAND:
440 case PDR_REGULATORY_POWER_LIMITS:
441 case PDR_RSSI_LINEAR_APPROXIMATION_EXTENDED:
442 case PDR_RADIATED_TRANSMISSION_CORRECTION:
443 case PDR_PRISM_TX_IQ_CALIBRATION:
444 case PDR_BASEBAND_REGISTERS:
445 case PDR_PER_CHANNEL_BASEBAND_REGISTERS:
446 break;
418 default: 447 default:
419 printk(KERN_INFO "p54: unknown eeprom code : 0x%x\n", 448 printk(KERN_INFO "p54: unknown eeprom code : 0x%x\n",
420 le16_to_cpu(entry->code)); 449 le16_to_cpu(entry->code));
@@ -431,12 +460,12 @@ static int p54_parse_eeprom(struct ieee80211_hw *dev, void *eeprom, int len)
431 goto err; 460 goto err;
432 } 461 }
433 462
434 priv->rxhw = synth & 0x07; 463 priv->rxhw = synth & PDR_SYNTH_FRONTEND_MASK;
435 if (priv->rxhw == 4) 464 if (priv->rxhw == 4)
436 p54_init_xbow_synth(dev); 465 p54_init_xbow_synth(dev);
437 if (!(synth & 0x40)) 466 if (!(synth & PDR_SYNTH_24_GHZ_DISABLED))
438 dev->wiphy->bands[IEEE80211_BAND_2GHZ] = &band_2GHz; 467 dev->wiphy->bands[IEEE80211_BAND_2GHZ] = &band_2GHz;
439 if (!(synth & 0x80)) 468 if (!(synth & PDR_SYNTH_5_GHZ_DISABLED))
440 dev->wiphy->bands[IEEE80211_BAND_5GHZ] = &band_5GHz; 469 dev->wiphy->bands[IEEE80211_BAND_5GHZ] = &band_5GHz;
441 470
442 if (!is_valid_ether_addr(dev->wiphy->perm_addr)) { 471 if (!is_valid_ether_addr(dev->wiphy->perm_addr)) {
@@ -621,6 +650,12 @@ static void p54_rx_frame_sent(struct ieee80211_hw *dev, struct sk_buff *skb)
621 __skb_unlink(entry, &priv->tx_queue); 650 __skb_unlink(entry, &priv->tx_queue);
622 spin_unlock_irqrestore(&priv->tx_queue.lock, flags); 651 spin_unlock_irqrestore(&priv->tx_queue.lock, flags);
623 652
653 if (unlikely(entry == priv->cached_beacon)) {
654 kfree_skb(entry);
655 priv->cached_beacon = NULL;
656 goto out;
657 }
658
624 /* 659 /*
625 * Clear manually, ieee80211_tx_info_clear_status would 660 * Clear manually, ieee80211_tx_info_clear_status would
626 * clear the counts too and we need them. 661 * clear the counts too and we need them.
@@ -654,7 +689,7 @@ static void p54_rx_frame_sent(struct ieee80211_hw *dev, struct sk_buff *skb)
654 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK) && 689 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK) &&
655 (!payload->status)) 690 (!payload->status))
656 info->flags |= IEEE80211_TX_STAT_ACK; 691 info->flags |= IEEE80211_TX_STAT_ACK;
657 if (payload->status & 0x02) 692 if (payload->status & P54_TX_PSM_CANCELLED)
658 info->flags |= IEEE80211_TX_STAT_TX_FILTERED; 693 info->flags |= IEEE80211_TX_STAT_TX_FILTERED;
659 info->status.ack_signal = p54_rssi_to_dbm(dev, 694 info->status.ack_signal = p54_rssi_to_dbm(dev,
660 (int)payload->ack_rssi); 695 (int)payload->ack_rssi);
@@ -706,6 +741,35 @@ static void p54_rx_stats(struct ieee80211_hw *dev, struct sk_buff *skb)
706 mod_timer(&priv->stats_timer, jiffies + 5 * HZ); 741 mod_timer(&priv->stats_timer, jiffies + 5 * HZ);
707} 742}
708 743
744static void p54_rx_trap(struct ieee80211_hw *dev, struct sk_buff *skb)
745{
746 struct p54_hdr *hdr = (struct p54_hdr *) skb->data;
747 struct p54_trap *trap = (struct p54_trap *) hdr->data;
748 u16 event = le16_to_cpu(trap->event);
749 u16 freq = le16_to_cpu(trap->frequency);
750
751 switch (event) {
752 case P54_TRAP_BEACON_TX:
753 break;
754 case P54_TRAP_RADAR:
755 printk(KERN_INFO "%s: radar (freq:%d MHz)\n",
756 wiphy_name(dev->wiphy), freq);
757 break;
758 case P54_TRAP_NO_BEACON:
759 break;
760 case P54_TRAP_SCAN:
761 break;
762 case P54_TRAP_TBTT:
763 break;
764 case P54_TRAP_TIMER:
765 break;
766 default:
767 printk(KERN_INFO "%s: received event:%x freq:%d\n",
768 wiphy_name(dev->wiphy), event, freq);
769 break;
770 }
771}
772
709static int p54_rx_control(struct ieee80211_hw *dev, struct sk_buff *skb) 773static int p54_rx_control(struct ieee80211_hw *dev, struct sk_buff *skb)
710{ 774{
711 struct p54_hdr *hdr = (struct p54_hdr *) skb->data; 775 struct p54_hdr *hdr = (struct p54_hdr *) skb->data;
@@ -714,6 +778,9 @@ static int p54_rx_control(struct ieee80211_hw *dev, struct sk_buff *skb)
714 case P54_CONTROL_TYPE_TXDONE: 778 case P54_CONTROL_TYPE_TXDONE:
715 p54_rx_frame_sent(dev, skb); 779 p54_rx_frame_sent(dev, skb);
716 break; 780 break;
781 case P54_CONTROL_TYPE_TRAP:
782 p54_rx_trap(dev, skb);
783 break;
717 case P54_CONTROL_TYPE_BBP: 784 case P54_CONTROL_TYPE_BBP:
718 break; 785 break;
719 case P54_CONTROL_TYPE_STAT_READBACK: 786 case P54_CONTROL_TYPE_STAT_READBACK:
@@ -734,9 +801,9 @@ static int p54_rx_control(struct ieee80211_hw *dev, struct sk_buff *skb)
734/* returns zero if skb can be reused */ 801/* returns zero if skb can be reused */
735int p54_rx(struct ieee80211_hw *dev, struct sk_buff *skb) 802int p54_rx(struct ieee80211_hw *dev, struct sk_buff *skb)
736{ 803{
737 u8 type = le16_to_cpu(*((__le16 *)skb->data)) >> 8; 804 u16 type = le16_to_cpu(*((__le16 *)skb->data));
738 805
739 if (type == 0x80) 806 if (type & P54_HDR_FLAG_CONTROL)
740 return p54_rx_control(dev, skb); 807 return p54_rx_control(dev, skb);
741 else 808 else
742 return p54_rx_data(dev, skb); 809 return p54_rx_data(dev, skb);
@@ -897,41 +964,162 @@ free:
897} 964}
898EXPORT_SYMBOL_GPL(p54_read_eeprom); 965EXPORT_SYMBOL_GPL(p54_read_eeprom);
899 966
967static int p54_set_tim(struct ieee80211_hw *dev, struct ieee80211_sta *sta,
968 bool set)
969{
970 struct p54_common *priv = dev->priv;
971 struct sk_buff *skb;
972 struct p54_tim *tim;
973
974 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET,
975 sizeof(struct p54_hdr) + sizeof(*tim),
976 P54_CONTROL_TYPE_TIM, GFP_KERNEL);
977 if (!skb)
978 return -ENOMEM;
979
980 tim = (struct p54_tim *) skb_put(skb, sizeof(*tim));
981 tim->count = 1;
982 tim->entry[0] = cpu_to_le16(set ? (sta->aid | 0x8000) : sta->aid);
983 priv->tx(dev, skb, 1);
984 return 0;
985}
986
987static int p54_sta_unlock(struct ieee80211_hw *dev, u8 *addr)
988{
989 struct p54_common *priv = dev->priv;
990 struct sk_buff *skb;
991 struct p54_sta_unlock *sta;
992
993 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET,
994 sizeof(struct p54_hdr) + sizeof(*sta),
995 P54_CONTROL_TYPE_PSM_STA_UNLOCK, GFP_ATOMIC);
996 if (!skb)
997 return -ENOMEM;
998
999 sta = (struct p54_sta_unlock *)skb_put(skb, sizeof(*sta));
1000 memcpy(sta->addr, addr, ETH_ALEN);
1001 priv->tx(dev, skb, 1);
1002 return 0;
1003}
1004
1005static int p54_tx_cancel(struct ieee80211_hw *dev, struct sk_buff *entry)
1006{
1007 struct p54_common *priv = dev->priv;
1008 struct sk_buff *skb;
1009 struct p54_hdr *hdr;
1010 struct p54_txcancel *cancel;
1011
1012 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET,
1013 sizeof(struct p54_hdr) + sizeof(*cancel),
1014 P54_CONTROL_TYPE_TXCANCEL, GFP_ATOMIC);
1015 if (!skb)
1016 return -ENOMEM;
1017
1018 hdr = (void *)entry->data;
1019 cancel = (struct p54_txcancel *)skb_put(skb, sizeof(*cancel));
1020 cancel->req_id = hdr->req_id;
1021 priv->tx(dev, skb, 1);
1022 return 0;
1023}
1024
1025static int p54_tx_fill(struct ieee80211_hw *dev, struct sk_buff *skb,
1026 struct ieee80211_tx_info *info, u8 *queue, size_t *extra_len,
1027 u16 *flags, u16 *aid)
1028{
1029 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1030 struct p54_common *priv = dev->priv;
1031 int ret = 0;
1032
1033 if (unlikely(ieee80211_is_mgmt(hdr->frame_control))) {
1034 if (ieee80211_is_beacon(hdr->frame_control)) {
1035 *aid = 0;
1036 *queue = 0;
1037 *extra_len = IEEE80211_MAX_TIM_LEN;
1038 *flags = P54_HDR_FLAG_DATA_OUT_TIMESTAMP;
1039 return 0;
1040 } else if (ieee80211_is_probe_resp(hdr->frame_control)) {
1041 *aid = 0;
1042 *queue = 2;
1043 *flags = P54_HDR_FLAG_DATA_OUT_TIMESTAMP |
1044 P54_HDR_FLAG_DATA_OUT_NOCANCEL;
1045 return 0;
1046 } else {
1047 *queue = 2;
1048 ret = 0;
1049 }
1050 } else {
1051 *queue += 4;
1052 ret = 1;
1053 }
1054
1055 switch (priv->mode) {
1056 case NL80211_IFTYPE_STATION:
1057 *aid = 1;
1058 break;
1059 case NL80211_IFTYPE_AP:
1060 case NL80211_IFTYPE_ADHOC:
1061 if (info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) {
1062 *aid = 0;
1063 *queue = 3;
1064 return 0;
1065 }
1066 if (info->control.sta)
1067 *aid = info->control.sta->aid;
1068 else
1069 *flags = P54_HDR_FLAG_DATA_OUT_NOCANCEL;
1070 }
1071 return ret;
1072}
1073
900static int p54_tx(struct ieee80211_hw *dev, struct sk_buff *skb) 1074static int p54_tx(struct ieee80211_hw *dev, struct sk_buff *skb)
901{ 1075{
902 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 1076 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
903 struct ieee80211_tx_queue_stats *current_queue; 1077 struct ieee80211_tx_queue_stats *current_queue = NULL;
904 struct p54_common *priv = dev->priv; 1078 struct p54_common *priv = dev->priv;
905 struct p54_hdr *hdr; 1079 struct p54_hdr *hdr;
906 struct p54_tx_data *txhdr; 1080 struct p54_tx_data *txhdr;
907 size_t padding, len; 1081 size_t padding, len, tim_len = 0;
908 int i, j, ridx; 1082 int i, j, ridx;
909 u8 rate; 1083 u16 hdr_flags = 0, aid = 0;
1084 u8 rate, queue;
910 u8 cts_rate = 0x20; 1085 u8 cts_rate = 0x20;
911 u8 rc_flags; 1086 u8 rc_flags;
912 u8 calculated_tries[4]; 1087 u8 calculated_tries[4];
913 u8 nrates = 0, nremaining = 8; 1088 u8 nrates = 0, nremaining = 8;
914 1089
915 current_queue = &priv->tx_stats[skb_get_queue_mapping(skb) + 4]; 1090 queue = skb_get_queue_mapping(skb);
916 if (unlikely(current_queue->len > current_queue->limit)) 1091
917 return NETDEV_TX_BUSY; 1092 if (p54_tx_fill(dev, skb, info, &queue, &tim_len, &hdr_flags, &aid)) {
918 current_queue->len++; 1093 current_queue = &priv->tx_stats[queue];
919 current_queue->count++; 1094 if (unlikely(current_queue->len > current_queue->limit))
920 if (current_queue->len == current_queue->limit) 1095 return NETDEV_TX_BUSY;
921 ieee80211_stop_queue(dev, skb_get_queue_mapping(skb)); 1096 current_queue->len++;
1097 current_queue->count++;
1098 if (current_queue->len == current_queue->limit)
1099 ieee80211_stop_queue(dev, skb_get_queue_mapping(skb));
1100 }
922 1101
923 padding = (unsigned long)(skb->data - (sizeof(*hdr) + sizeof(*txhdr))) & 3; 1102 padding = (unsigned long)(skb->data - (sizeof(*hdr) + sizeof(*txhdr))) & 3;
924 len = skb->len; 1103 len = skb->len;
925 1104
1105 if (info->flags & IEEE80211_TX_CTL_CLEAR_PS_FILT) {
1106 if (info->control.sta)
1107 if (p54_sta_unlock(dev, info->control.sta->addr)) {
1108 if (current_queue) {
1109 current_queue->len--;
1110 current_queue->count--;
1111 }
1112 return NETDEV_TX_BUSY;
1113 }
1114 }
1115
926 txhdr = (struct p54_tx_data *) skb_push(skb, sizeof(*txhdr) + padding); 1116 txhdr = (struct p54_tx_data *) skb_push(skb, sizeof(*txhdr) + padding);
927 hdr = (struct p54_hdr *) skb_push(skb, sizeof(*hdr)); 1117 hdr = (struct p54_hdr *) skb_push(skb, sizeof(*hdr));
928 1118
929 if (padding) 1119 if (padding)
930 hdr->flags = cpu_to_le16(P54_HDR_FLAG_DATA_ALIGN); 1120 hdr_flags |= P54_HDR_FLAG_DATA_ALIGN;
931 else
932 hdr->flags = cpu_to_le16(0);
933 hdr->len = cpu_to_le16(len); 1121 hdr->len = cpu_to_le16(len);
934 hdr->type = (info->flags & IEEE80211_TX_CTL_NO_ACK) ? 0 : cpu_to_le16(1); 1122 hdr->type = cpu_to_le16(aid);
935 hdr->rts_tries = info->control.rates[0].count; 1123 hdr->rts_tries = info->control.rates[0].count;
936 1124
937 /* 1125 /*
@@ -998,12 +1186,18 @@ static int p54_tx(struct ieee80211_hw *dev, struct sk_buff *skb)
998 ridx++; 1186 ridx++;
999 } 1187 }
1000 } 1188 }
1189
1190 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ)
1191 hdr_flags |= P54_HDR_FLAG_DATA_OUT_SEQNR;
1192
1193 /* TODO: enable bursting */
1194 hdr->flags = cpu_to_le16(hdr_flags);
1001 hdr->tries = ridx; 1195 hdr->tries = ridx;
1002 txhdr->crypt_offset = 0; 1196 txhdr->crypt_offset = 0;
1003 txhdr->rts_rate_idx = 0; 1197 txhdr->rts_rate_idx = 0;
1004 txhdr->key_type = 0; 1198 txhdr->key_type = 0;
1005 txhdr->key_len = 0; 1199 txhdr->key_len = 0;
1006 txhdr->hw_queue = skb_get_queue_mapping(skb) + 4; 1200 txhdr->hw_queue = queue;
1007 txhdr->backlog = 32; 1201 txhdr->backlog = 32;
1008 memset(txhdr->durations, 0, sizeof(txhdr->durations)); 1202 memset(txhdr->durations, 0, sizeof(txhdr->durations));
1009 txhdr->tx_antenna = (info->antenna_sel_tx == 0) ? 1203 txhdr->tx_antenna = (info->antenna_sel_tx == 0) ?
@@ -1014,8 +1208,12 @@ static int p54_tx(struct ieee80211_hw *dev, struct sk_buff *skb)
1014 txhdr->align[0] = padding; 1208 txhdr->align[0] = padding;
1015 1209
1016 /* modifies skb->cb and with it info, so must be last! */ 1210 /* modifies skb->cb and with it info, so must be last! */
1017 if (unlikely(p54_assign_address(dev, skb, hdr, skb->len))) { 1211 if (unlikely(p54_assign_address(dev, skb, hdr, skb->len + tim_len))) {
1018 skb_pull(skb, sizeof(*hdr) + sizeof(*txhdr) + padding); 1212 skb_pull(skb, sizeof(*hdr) + sizeof(*txhdr) + padding);
1213 if (current_queue) {
1214 current_queue->len--;
1215 current_queue->count--;
1216 }
1019 return NETDEV_TX_BUSY; 1217 return NETDEV_TX_BUSY;
1020 } 1218 }
1021 priv->tx(dev, skb, 0); 1219 priv->tx(dev, skb, 0);
@@ -1043,8 +1241,10 @@ static int p54_setup_mac(struct ieee80211_hw *dev, u16 mode, const u8 *bssid)
1043 else 1241 else
1044 memcpy(setup->bssid, bssid, ETH_ALEN); 1242 memcpy(setup->bssid, bssid, ETH_ALEN);
1045 setup->rx_antenna = priv->rx_antenna; 1243 setup->rx_antenna = priv->rx_antenna;
1244 setup->rx_align = 0;
1046 if (priv->fw_var < 0x500) { 1245 if (priv->fw_var < 0x500) {
1047 setup->v1.basic_rate_mask = cpu_to_le32(0x15f); 1246 setup->v1.basic_rate_mask = cpu_to_le32(0x15f);
1247 memset(setup->v1.rts_rates, 0, 8);
1048 setup->v1.rx_addr = cpu_to_le32(priv->rx_end); 1248 setup->v1.rx_addr = cpu_to_le32(priv->rx_end);
1049 setup->v1.max_rx = cpu_to_le16(priv->rx_mtu); 1249 setup->v1.max_rx = cpu_to_le16(priv->rx_mtu);
1050 setup->v1.rxhw = cpu_to_le16(priv->rxhw); 1250 setup->v1.rxhw = cpu_to_le16(priv->rxhw);
@@ -1069,13 +1269,14 @@ static int p54_setup_mac(struct ieee80211_hw *dev, u16 mode, const u8 *bssid)
1069 return 0; 1269 return 0;
1070} 1270}
1071 1271
1072static int p54_set_freq(struct ieee80211_hw *dev, __le16 freq) 1272static int p54_set_freq(struct ieee80211_hw *dev, u16 frequency)
1073{ 1273{
1074 struct p54_common *priv = dev->priv; 1274 struct p54_common *priv = dev->priv;
1075 struct sk_buff *skb; 1275 struct sk_buff *skb;
1076 struct p54_scan *chan; 1276 struct p54_scan *chan;
1077 unsigned int i; 1277 unsigned int i;
1078 void *entry; 1278 void *entry;
1279 __le16 freq = cpu_to_le16(frequency);
1079 1280
1080 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*chan) + 1281 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*chan) +
1081 sizeof(struct p54_hdr), P54_CONTROL_TYPE_SCAN, 1282 sizeof(struct p54_hdr), P54_CONTROL_TYPE_SCAN,
@@ -1127,11 +1328,11 @@ static int p54_set_freq(struct ieee80211_hw *dev, __le16 freq)
1127 } 1328 }
1128 1329
1129 entry += sizeof(__le16); 1330 entry += sizeof(__le16);
1130 chan->pa_points_per_curve = 1331 chan->pa_points_per_curve = 8;
1131 min(priv->curve_data->points_per_channel, (u8) 8); 1332 memset(chan->curve_data, 0, sizeof(*chan->curve_data));
1132 1333 memcpy(chan->curve_data, entry,
1133 memcpy(chan->curve_data, entry, sizeof(*chan->curve_data) * 1334 sizeof(struct p54_pa_curve_data_sample) *
1134 chan->pa_points_per_curve); 1335 min((u8)8, priv->curve_data->points_per_channel));
1135 break; 1336 break;
1136 } 1337 }
1137 1338
@@ -1207,6 +1408,7 @@ static int p54_set_edcf(struct ieee80211_hw *dev)
1207 /* (see prism54/isl_oid.h for further details) */ 1408 /* (see prism54/isl_oid.h for further details) */
1208 edcf->frameburst = cpu_to_le16(0); 1409 edcf->frameburst = cpu_to_le16(0);
1209 edcf->round_trip_delay = cpu_to_le16(0); 1410 edcf->round_trip_delay = cpu_to_le16(0);
1411 edcf->flags = 0;
1210 memset(edcf->mapping, 0, sizeof(edcf->mapping)); 1412 memset(edcf->mapping, 0, sizeof(edcf->mapping));
1211 memcpy(edcf->queue, priv->qos_params, sizeof(edcf->queue)); 1413 memcpy(edcf->queue, priv->qos_params, sizeof(edcf->queue));
1212 priv->tx(dev, skb, 1); 1414 priv->tx(dev, skb, 1);
@@ -1227,11 +1429,94 @@ static int p54_init_stats(struct ieee80211_hw *dev)
1227 return 0; 1429 return 0;
1228} 1430}
1229 1431
1432static int p54_beacon_tim(struct sk_buff *skb)
1433{
1434 /*
1435 * the good excuse for this mess is ... the firmware.
1436 * The dummy TIM MUST be at the end of the beacon frame,
1437 * because it'll be overwritten!
1438 */
1439
1440 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1441 u8 *pos, *end;
1442
1443 if (skb->len <= sizeof(mgmt)) {
1444 printk(KERN_ERR "p54: beacon is too short!\n");
1445 return -EINVAL;
1446 }
1447
1448 pos = (u8 *)mgmt->u.beacon.variable;
1449 end = skb->data + skb->len;
1450 while (pos < end) {
1451 if (pos + 2 + pos[1] > end) {
1452 printk(KERN_ERR "p54: parsing beacon failed\n");
1453 return -EINVAL;
1454 }
1455
1456 if (pos[0] == WLAN_EID_TIM) {
1457 u8 dtim_len = pos[1];
1458 u8 dtim_period = pos[3];
1459 u8 *next = pos + 2 + dtim_len;
1460
1461 if (dtim_len < 3) {
1462 printk(KERN_ERR "p54: invalid dtim len!\n");
1463 return -EINVAL;
1464 }
1465 memmove(pos, next, end - next);
1466
1467 if (dtim_len > 3)
1468 skb_trim(skb, skb->len - (dtim_len - 3));
1469
1470 pos = end - (dtim_len + 2);
1471
1472 /* add the dummy at the end */
1473 pos[0] = WLAN_EID_TIM;
1474 pos[1] = 3;
1475 pos[2] = 0;
1476 pos[3] = dtim_period;
1477 pos[4] = 0;
1478 return 0;
1479 }
1480 pos += 2 + pos[1];
1481 }
1482 return 0;
1483}
1484
1485static int p54_beacon_update(struct ieee80211_hw *dev,
1486 struct ieee80211_vif *vif)
1487{
1488 struct p54_common *priv = dev->priv;
1489 struct sk_buff *beacon;
1490 int ret;
1491
1492 if (priv->cached_beacon) {
1493 p54_tx_cancel(dev, priv->cached_beacon);
1494 /* wait for the last beacon the be freed */
1495 msleep(10);
1496 }
1497
1498 beacon = ieee80211_beacon_get(dev, vif);
1499 if (!beacon)
1500 return -ENOMEM;
1501 ret = p54_beacon_tim(beacon);
1502 if (ret)
1503 return ret;
1504 ret = p54_tx(dev, beacon);
1505 if (ret)
1506 return ret;
1507 priv->cached_beacon = beacon;
1508 priv->tsf_high32 = 0;
1509 priv->tsf_low32 = 0;
1510
1511 return 0;
1512}
1513
1230static int p54_start(struct ieee80211_hw *dev) 1514static int p54_start(struct ieee80211_hw *dev)
1231{ 1515{
1232 struct p54_common *priv = dev->priv; 1516 struct p54_common *priv = dev->priv;
1233 int err; 1517 int err;
1234 1518
1519 mutex_lock(&priv->conf_mutex);
1235 err = priv->open(dev); 1520 err = priv->open(dev);
1236 if (!err) 1521 if (!err)
1237 priv->mode = NL80211_IFTYPE_MONITOR; 1522 priv->mode = NL80211_IFTYPE_MONITOR;
@@ -1243,6 +1528,7 @@ static int p54_start(struct ieee80211_hw *dev)
1243 if (!err) 1528 if (!err)
1244 err = p54_init_stats(dev); 1529 err = p54_init_stats(dev);
1245 1530
1531 mutex_unlock(&priv->conf_mutex);
1246 return err; 1532 return err;
1247} 1533}
1248 1534
@@ -1251,15 +1537,22 @@ static void p54_stop(struct ieee80211_hw *dev)
1251 struct p54_common *priv = dev->priv; 1537 struct p54_common *priv = dev->priv;
1252 struct sk_buff *skb; 1538 struct sk_buff *skb;
1253 1539
1540 mutex_lock(&priv->conf_mutex);
1254 del_timer(&priv->stats_timer); 1541 del_timer(&priv->stats_timer);
1255 p54_free_skb(dev, priv->cached_stats); 1542 p54_free_skb(dev, priv->cached_stats);
1256 priv->cached_stats = NULL; 1543 priv->cached_stats = NULL;
1544 if (priv->cached_beacon)
1545 p54_tx_cancel(dev, priv->cached_beacon);
1546
1257 while ((skb = skb_dequeue(&priv->tx_queue))) 1547 while ((skb = skb_dequeue(&priv->tx_queue)))
1258 kfree_skb(skb); 1548 kfree_skb(skb);
1259 1549
1550 kfree(priv->cached_beacon);
1551 priv->cached_beacon = NULL;
1260 priv->stop(dev); 1552 priv->stop(dev);
1261 priv->tsf_high32 = priv->tsf_low32 = 0; 1553 priv->tsf_high32 = priv->tsf_low32 = 0;
1262 priv->mode = NL80211_IFTYPE_UNSPECIFIED; 1554 priv->mode = NL80211_IFTYPE_UNSPECIFIED;
1555 mutex_unlock(&priv->conf_mutex);
1263} 1556}
1264 1557
1265static int p54_add_interface(struct ieee80211_hw *dev, 1558static int p54_add_interface(struct ieee80211_hw *dev,
@@ -1267,14 +1560,20 @@ static int p54_add_interface(struct ieee80211_hw *dev,
1267{ 1560{
1268 struct p54_common *priv = dev->priv; 1561 struct p54_common *priv = dev->priv;
1269 1562
1270 if (priv->mode != NL80211_IFTYPE_MONITOR) 1563 mutex_lock(&priv->conf_mutex);
1564 if (priv->mode != NL80211_IFTYPE_MONITOR) {
1565 mutex_unlock(&priv->conf_mutex);
1271 return -EOPNOTSUPP; 1566 return -EOPNOTSUPP;
1567 }
1272 1568
1273 switch (conf->type) { 1569 switch (conf->type) {
1274 case NL80211_IFTYPE_STATION: 1570 case NL80211_IFTYPE_STATION:
1571 case NL80211_IFTYPE_ADHOC:
1572 case NL80211_IFTYPE_AP:
1275 priv->mode = conf->type; 1573 priv->mode = conf->type;
1276 break; 1574 break;
1277 default: 1575 default:
1576 mutex_unlock(&priv->conf_mutex);
1278 return -EOPNOTSUPP; 1577 return -EOPNOTSUPP;
1279 } 1578 }
1280 1579
@@ -1286,6 +1585,12 @@ static int p54_add_interface(struct ieee80211_hw *dev,
1286 case NL80211_IFTYPE_STATION: 1585 case NL80211_IFTYPE_STATION:
1287 p54_setup_mac(dev, P54_FILTER_TYPE_STATION, NULL); 1586 p54_setup_mac(dev, P54_FILTER_TYPE_STATION, NULL);
1288 break; 1587 break;
1588 case NL80211_IFTYPE_AP:
1589 p54_setup_mac(dev, P54_FILTER_TYPE_AP, priv->mac_addr);
1590 break;
1591 case NL80211_IFTYPE_ADHOC:
1592 p54_setup_mac(dev, P54_FILTER_TYPE_IBSS, NULL);
1593 break;
1289 default: 1594 default:
1290 BUG(); /* impossible */ 1595 BUG(); /* impossible */
1291 break; 1596 break;
@@ -1293,6 +1598,7 @@ static int p54_add_interface(struct ieee80211_hw *dev,
1293 1598
1294 p54_set_leds(dev, 1, 0, 0); 1599 p54_set_leds(dev, 1, 0, 0);
1295 1600
1601 mutex_unlock(&priv->conf_mutex);
1296 return 0; 1602 return 0;
1297} 1603}
1298 1604
@@ -1300,9 +1606,14 @@ static void p54_remove_interface(struct ieee80211_hw *dev,
1300 struct ieee80211_if_init_conf *conf) 1606 struct ieee80211_if_init_conf *conf)
1301{ 1607{
1302 struct p54_common *priv = dev->priv; 1608 struct p54_common *priv = dev->priv;
1609
1610 mutex_lock(&priv->conf_mutex);
1611 if (priv->cached_beacon)
1612 p54_tx_cancel(dev, priv->cached_beacon);
1613 p54_setup_mac(dev, P54_FILTER_TYPE_NONE, NULL);
1303 priv->mode = NL80211_IFTYPE_MONITOR; 1614 priv->mode = NL80211_IFTYPE_MONITOR;
1304 memset(priv->mac_addr, 0, ETH_ALEN); 1615 memset(priv->mac_addr, 0, ETH_ALEN);
1305 p54_setup_mac(dev, P54_FILTER_TYPE_NONE, NULL); 1616 mutex_unlock(&priv->conf_mutex);
1306} 1617}
1307 1618
1308static int p54_config(struct ieee80211_hw *dev, u32 changed) 1619static int p54_config(struct ieee80211_hw *dev, u32 changed)
@@ -1314,7 +1625,7 @@ static int p54_config(struct ieee80211_hw *dev, u32 changed)
1314 mutex_lock(&priv->conf_mutex); 1625 mutex_lock(&priv->conf_mutex);
1315 priv->rx_antenna = 2; /* automatic */ 1626 priv->rx_antenna = 2; /* automatic */
1316 priv->output_power = conf->power_level << 2; 1627 priv->output_power = conf->power_level << 2;
1317 ret = p54_set_freq(dev, cpu_to_le16(conf->channel->center_freq)); 1628 ret = p54_set_freq(dev, conf->channel->center_freq);
1318 if (!ret) 1629 if (!ret)
1319 ret = p54_set_edcf(dev); 1630 ret = p54_set_edcf(dev);
1320 mutex_unlock(&priv->conf_mutex); 1631 mutex_unlock(&priv->conf_mutex);
@@ -1326,13 +1637,41 @@ static int p54_config_interface(struct ieee80211_hw *dev,
1326 struct ieee80211_if_conf *conf) 1637 struct ieee80211_if_conf *conf)
1327{ 1638{
1328 struct p54_common *priv = dev->priv; 1639 struct p54_common *priv = dev->priv;
1640 int ret = 0;
1329 1641
1330 mutex_lock(&priv->conf_mutex); 1642 mutex_lock(&priv->conf_mutex);
1331 p54_setup_mac(dev, P54_FILTER_TYPE_STATION, conf->bssid); 1643 switch (priv->mode) {
1332 p54_set_leds(dev, 1, !is_multicast_ether_addr(conf->bssid), 0); 1644 case NL80211_IFTYPE_STATION:
1333 memcpy(priv->bssid, conf->bssid, ETH_ALEN); 1645 ret = p54_setup_mac(dev, P54_FILTER_TYPE_STATION, conf->bssid);
1646 if (ret)
1647 goto out;
1648 ret = p54_set_leds(dev, 1,
1649 !is_multicast_ether_addr(conf->bssid), 0);
1650 if (ret)
1651 goto out;
1652 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
1653 break;
1654 case NL80211_IFTYPE_AP:
1655 case NL80211_IFTYPE_ADHOC:
1656 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
1657 ret = p54_set_freq(dev, dev->conf.channel->center_freq);
1658 if (ret)
1659 goto out;
1660 ret = p54_setup_mac(dev, priv->mac_mode, priv->bssid);
1661 if (ret)
1662 goto out;
1663 if (conf->changed & IEEE80211_IFCC_BEACON) {
1664 ret = p54_beacon_update(dev, vif);
1665 if (ret)
1666 goto out;
1667 ret = p54_set_edcf(dev);
1668 if (ret)
1669 goto out;
1670 }
1671 }
1672out:
1334 mutex_unlock(&priv->conf_mutex); 1673 mutex_unlock(&priv->conf_mutex);
1335 return 0; 1674 return ret;
1336} 1675}
1337 1676
1338static void p54_configure_filter(struct ieee80211_hw *dev, 1677static void p54_configure_filter(struct ieee80211_hw *dev,
@@ -1367,14 +1706,18 @@ static int p54_conf_tx(struct ieee80211_hw *dev, u16 queue,
1367 const struct ieee80211_tx_queue_params *params) 1706 const struct ieee80211_tx_queue_params *params)
1368{ 1707{
1369 struct p54_common *priv = dev->priv; 1708 struct p54_common *priv = dev->priv;
1709 int ret;
1370 1710
1711 mutex_lock(&priv->conf_mutex);
1371 if ((params) && !(queue > 4)) { 1712 if ((params) && !(queue > 4)) {
1372 P54_SET_QUEUE(priv->qos_params[queue], params->aifs, 1713 P54_SET_QUEUE(priv->qos_params[queue], params->aifs,
1373 params->cw_min, params->cw_max, params->txop); 1714 params->cw_min, params->cw_max, params->txop);
1374 } else 1715 } else
1375 return -EINVAL; 1716 ret = -EINVAL;
1376 1717 if (!ret)
1377 return p54_set_edcf(dev); 1718 ret = p54_set_edcf(dev);
1719 mutex_unlock(&priv->conf_mutex);
1720 return ret;
1378} 1721}
1379 1722
1380static int p54_init_xbow_synth(struct ieee80211_hw *dev) 1723static int p54_init_xbow_synth(struct ieee80211_hw *dev)
@@ -1457,6 +1800,7 @@ static const struct ieee80211_ops p54_ops = {
1457 .stop = p54_stop, 1800 .stop = p54_stop,
1458 .add_interface = p54_add_interface, 1801 .add_interface = p54_add_interface,
1459 .remove_interface = p54_remove_interface, 1802 .remove_interface = p54_remove_interface,
1803 .set_tim = p54_set_tim,
1460 .config = p54_config, 1804 .config = p54_config,
1461 .config_interface = p54_config_interface, 1805 .config_interface = p54_config_interface,
1462 .bss_info_changed = p54_bss_info_changed, 1806 .bss_info_changed = p54_bss_info_changed,
@@ -1478,24 +1822,20 @@ struct ieee80211_hw *p54_init_common(size_t priv_data_len)
1478 priv = dev->priv; 1822 priv = dev->priv;
1479 priv->mode = NL80211_IFTYPE_UNSPECIFIED; 1823 priv->mode = NL80211_IFTYPE_UNSPECIFIED;
1480 skb_queue_head_init(&priv->tx_queue); 1824 skb_queue_head_init(&priv->tx_queue);
1481 dev->flags = IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING | /* not sure */ 1825 dev->flags = IEEE80211_HW_RX_INCLUDES_FCS |
1482 IEEE80211_HW_RX_INCLUDES_FCS |
1483 IEEE80211_HW_SIGNAL_DBM | 1826 IEEE80211_HW_SIGNAL_DBM |
1484 IEEE80211_HW_NOISE_DBM; 1827 IEEE80211_HW_NOISE_DBM;
1485 1828
1486 /* 1829 dev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION |
1487 * XXX: when this driver gets support for any mode that 1830 NL80211_IFTYPE_ADHOC |
1488 * requires beacons (AP, MESH, IBSS) then it must 1831 NL80211_IFTYPE_AP);
1489 * implement IEEE80211_TX_CTL_ASSIGN_SEQ.
1490 */
1491 dev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
1492 1832
1493 dev->channel_change_time = 1000; /* TODO: find actual value */ 1833 dev->channel_change_time = 1000; /* TODO: find actual value */
1494 priv->tx_stats[0].limit = 1; 1834 priv->tx_stats[0].limit = 1; /* Beacon queue */
1495 priv->tx_stats[1].limit = 1; 1835 priv->tx_stats[1].limit = 1; /* Probe queue for HW scan */
1496 priv->tx_stats[2].limit = 1; 1836 priv->tx_stats[2].limit = 3; /* queue for MLMEs */
1497 priv->tx_stats[3].limit = 1; 1837 priv->tx_stats[3].limit = 3; /* Broadcast / MC queue */
1498 priv->tx_stats[4].limit = 5; 1838 priv->tx_stats[4].limit = 5; /* Data */
1499 dev->queues = 1; 1839 dev->queues = 1;
1500 priv->noise = -94; 1840 priv->noise = -94;
1501 /* 1841 /*
diff --git a/drivers/net/wireless/p54/p54common.h b/drivers/net/wireless/p54/p54common.h
index b1101feace69..8c8793cb2d79 100644
--- a/drivers/net/wireless/p54/p54common.h
+++ b/drivers/net/wireless/p54/p54common.h
@@ -25,6 +25,22 @@ struct bootrec {
25 u32 data[10]; 25 u32 data[10];
26} __attribute__((packed)); 26} __attribute__((packed));
27 27
28#define PDR_SYNTH_FRONTEND_MASK 0x0007
29#define PDR_SYNTH_IQ_CAL_MASK 0x0018
30#define PDR_SYNTH_IQ_CAL_PA_DETECTOR 0x0000
31#define PDR_SYNTH_IQ_CAL_DISABLED 0x0008
32#define PDR_SYNTH_IQ_CAL_ZIF 0x0010
33#define PDR_SYNTH_FAA_SWITCH_MASK 0x0020
34#define PDR_SYNTH_FAA_SWITCH_ENABLED 0x0001
35#define PDR_SYNTH_24_GHZ_MASK 0x0040
36#define PDR_SYNTH_24_GHZ_DISABLED 0x0040
37#define PDR_SYNTH_5_GHZ_MASK 0x0080
38#define PDR_SYNTH_5_GHZ_DISABLED 0x0080
39#define PDR_SYNTH_RX_DIV_MASK 0x0100
40#define PDR_SYNTH_RX_DIV_SUPPORTED 0x0100
41#define PDR_SYNTH_TX_DIV_MASK 0x0200
42#define PDR_SYNTH_TX_DIV_SUPPORTED 0x0200
43
28struct bootrec_exp_if { 44struct bootrec_exp_if {
29 __le16 role; 45 __le16 role;
30 __le16 if_id; 46 __le16 if_id;
@@ -210,6 +226,19 @@ struct pda_pa_curve_data {
210#define PDR_BASEBAND_REGISTERS 0x8000 226#define PDR_BASEBAND_REGISTERS 0x8000
211#define PDR_PER_CHANNEL_BASEBAND_REGISTERS 0x8001 227#define PDR_PER_CHANNEL_BASEBAND_REGISTERS 0x8001
212 228
229/* PDR definitions for default country & country list */
230#define PDR_COUNTRY_CERT_CODE 0x80
231#define PDR_COUNTRY_CERT_CODE_REAL 0x00
232#define PDR_COUNTRY_CERT_CODE_PSEUDO 0x80
233#define PDR_COUNTRY_CERT_BAND 0x40
234#define PDR_COUNTRY_CERT_BAND_2GHZ 0x00
235#define PDR_COUNTRY_CERT_BAND_5GHZ 0x40
236#define PDR_COUNTRY_CERT_IODOOR 0x30
237#define PDR_COUNTRY_CERT_IODOOR_BOTH 0x00
238#define PDR_COUNTRY_CERT_IODOOR_INDOOR 0x20
239#define PDR_COUNTRY_CERT_IODOOR_OUTDOOR 0x30
240#define PDR_COUNTRY_CERT_INDEX 0x0F
241
213/* stored in skb->cb */ 242/* stored in skb->cb */
214struct memrecord { 243struct memrecord {
215 u32 start_addr; 244 u32 start_addr;
@@ -507,7 +536,7 @@ struct p54_sta_unlock {
507} __attribute__ ((packed)); 536} __attribute__ ((packed));
508 537
509#define P54_TIM_CLEAR BIT(15) 538#define P54_TIM_CLEAR BIT(15)
510struct p54_tx_control_tim { 539struct p54_tim {
511 u8 count; 540 u8 count;
512 u8 padding[3]; 541 u8 padding[3];
513 __le16 entry[8]; 542 __le16 entry[8];
diff --git a/drivers/net/wireless/p54/p54pci.c b/drivers/net/wireless/p54/p54pci.c
index 3c9d030ccb8d..c4a868ae6d6b 100644
--- a/drivers/net/wireless/p54/p54pci.c
+++ b/drivers/net/wireless/p54/p54pci.c
@@ -28,6 +28,7 @@ MODULE_AUTHOR("Michael Wu <flamingice@sourmilk.net>");
28MODULE_DESCRIPTION("Prism54 PCI wireless driver"); 28MODULE_DESCRIPTION("Prism54 PCI wireless driver");
29MODULE_LICENSE("GPL"); 29MODULE_LICENSE("GPL");
30MODULE_ALIAS("prism54pci"); 30MODULE_ALIAS("prism54pci");
31MODULE_FIRMWARE("isl3886pci");
31 32
32static struct pci_device_id p54p_table[] __devinitdata = { 33static struct pci_device_id p54p_table[] __devinitdata = {
33 /* Intersil PRISM Duette/Prism GT Wireless LAN adapter */ 34 /* Intersil PRISM Duette/Prism GT Wireless LAN adapter */
@@ -72,11 +73,13 @@ static int p54p_upload_firmware(struct ieee80211_hw *dev)
72 P54P_WRITE(ctrl_stat, reg); 73 P54P_WRITE(ctrl_stat, reg);
73 wmb(); 74 wmb();
74 75
75 err = request_firmware(&fw_entry, "isl3886", &priv->pdev->dev); 76 err = request_firmware(&fw_entry, "isl3886pci", &priv->pdev->dev);
76 if (err) { 77 if (err) {
77 printk(KERN_ERR "%s (p54pci): cannot find firmware " 78 printk(KERN_ERR "%s (p54pci): cannot find firmware "
78 "(isl3886)\n", pci_name(priv->pdev)); 79 "(isl3886pci)\n", pci_name(priv->pdev));
79 return err; 80 err = request_firmware(&fw_entry, "isl3886", &priv->pdev->dev);
81 if (err)
82 return err;
80 } 83 }
81 84
82 err = p54_parse_firmware(dev, fw_entry); 85 err = p54_parse_firmware(dev, fw_entry);
diff --git a/drivers/net/wireless/p54/p54usb.c b/drivers/net/wireless/p54/p54usb.c
index 49739c36a449..21ba526a45bf 100644
--- a/drivers/net/wireless/p54/p54usb.c
+++ b/drivers/net/wireless/p54/p54usb.c
@@ -28,6 +28,8 @@ MODULE_AUTHOR("Michael Wu <flamingice@sourmilk.net>");
28MODULE_DESCRIPTION("Prism54 USB wireless driver"); 28MODULE_DESCRIPTION("Prism54 USB wireless driver");
29MODULE_LICENSE("GPL"); 29MODULE_LICENSE("GPL");
30MODULE_ALIAS("prism54usb"); 30MODULE_ALIAS("prism54usb");
31MODULE_FIRMWARE("isl3886usb");
32MODULE_FIRMWARE("isl3887usb");
31 33
32static struct usb_device_id p54u_table[] __devinitdata = { 34static struct usb_device_id p54u_table[] __devinitdata = {
33 /* Version 1 devices (pci chip + net2280) */ 35 /* Version 1 devices (pci chip + net2280) */
@@ -415,10 +417,13 @@ static int p54u_upload_firmware_3887(struct ieee80211_hw *dev)
415 goto err_reset; 417 goto err_reset;
416 } 418 }
417 419
418 err = request_firmware(&fw_entry, "isl3887usb_bare", &priv->udev->dev); 420 err = request_firmware(&fw_entry, "isl3887usb", &priv->udev->dev);
419 if (err) { 421 if (err) {
420 printk(KERN_ERR "p54usb: cannot find firmware (isl3887usb_bare)!\n"); 422 printk(KERN_ERR "p54usb: cannot find firmware (isl3887usb)\n");
421 goto err_req_fw_failed; 423 err = request_firmware(&fw_entry, "isl3887usb_bare",
424 &priv->udev->dev);
425 if (err)
426 goto err_req_fw_failed;
422 } 427 }
423 428
424 err = p54_parse_firmware(dev, fw_entry); 429 err = p54_parse_firmware(dev, fw_entry);
@@ -553,11 +558,15 @@ static int p54u_upload_firmware_net2280(struct ieee80211_hw *dev)
553 return -ENOMEM; 558 return -ENOMEM;
554 } 559 }
555 560
556 err = request_firmware(&fw_entry, "isl3890usb", &priv->udev->dev); 561 err = request_firmware(&fw_entry, "isl3886usb", &priv->udev->dev);
557 if (err) { 562 if (err) {
558 printk(KERN_ERR "p54usb: cannot find firmware (isl3890usb)!\n"); 563 printk(KERN_ERR "p54usb: cannot find firmware (isl3886usb)\n");
559 kfree(buf); 564 err = request_firmware(&fw_entry, "isl3890usb",
560 return err; 565 &priv->udev->dev);
566 if (err) {
567 kfree(buf);
568 return err;
569 }
561 } 570 }
562 571
563 err = p54_parse_firmware(dev, fw_entry); 572 err = p54_parse_firmware(dev, fw_entry);
diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
index bd059e3c7e2b..a1eeb48f9466 100644
--- a/drivers/net/wireless/rndis_wlan.c
+++ b/drivers/net/wireless/rndis_wlan.c
@@ -37,11 +37,11 @@
37#include <linux/usb.h> 37#include <linux/usb.h>
38#include <linux/usb/cdc.h> 38#include <linux/usb/cdc.h>
39#include <linux/wireless.h> 39#include <linux/wireless.h>
40#include <linux/ieee80211.h>
40#include <linux/if_arp.h> 41#include <linux/if_arp.h>
41#include <linux/ctype.h> 42#include <linux/ctype.h>
42#include <linux/spinlock.h> 43#include <linux/spinlock.h>
43#include <net/iw_handler.h> 44#include <net/iw_handler.h>
44#include <net/ieee80211.h>
45#include <linux/usb/usbnet.h> 45#include <linux/usb/usbnet.h>
46#include <linux/usb/rndis_host.h> 46#include <linux/usb/rndis_host.h>
47 47
@@ -1652,7 +1652,7 @@ static char *rndis_translate_scan(struct net_device *dev,
1652#ifdef DEBUG 1652#ifdef DEBUG
1653 struct usbnet *usbdev = dev->priv; 1653 struct usbnet *usbdev = dev->priv;
1654#endif 1654#endif
1655 struct ieee80211_info_element *ie; 1655 u8 *ie;
1656 char *current_val; 1656 char *current_val;
1657 int bssid_len, ie_len, i; 1657 int bssid_len, ie_len, i;
1658 u32 beacon, atim; 1658 u32 beacon, atim;
@@ -1750,20 +1750,20 @@ static char *rndis_translate_scan(struct net_device *dev,
1750 ie_len = min(bssid_len - (int)sizeof(*bssid), 1750 ie_len = min(bssid_len - (int)sizeof(*bssid),
1751 (int)le32_to_cpu(bssid->ie_length)); 1751 (int)le32_to_cpu(bssid->ie_length));
1752 ie_len -= sizeof(struct ndis_80211_fixed_ies); 1752 ie_len -= sizeof(struct ndis_80211_fixed_ies);
1753 while (ie_len >= sizeof(*ie) && sizeof(*ie) + ie->len <= ie_len) { 1753 while (ie_len >= 2 && 2 + ie[1] <= ie_len) {
1754 if ((ie->id == MFIE_TYPE_GENERIC && ie->len >= 4 && 1754 if ((ie[0] == WLAN_EID_GENERIC && ie[1] >= 4 &&
1755 memcmp(ie->data, "\x00\x50\xf2\x01", 4) == 0) || 1755 memcmp(ie + 2, "\x00\x50\xf2\x01", 4) == 0) ||
1756 ie->id == MFIE_TYPE_RSN) { 1756 ie[0] == WLAN_EID_RSN) {
1757 devdbg(usbdev, "IE: WPA%d", 1757 devdbg(usbdev, "IE: WPA%d",
1758 (ie->id == MFIE_TYPE_RSN) ? 2 : 1); 1758 (ie[0] == WLAN_EID_RSN) ? 2 : 1);
1759 iwe.cmd = IWEVGENIE; 1759 iwe.cmd = IWEVGENIE;
1760 iwe.u.data.length = min(ie->len + 2, MAX_WPA_IE_LEN); 1760 /* arbitrary cut-off at 64 */
1761 cev = iwe_stream_add_point(info, cev, end_buf, &iwe, 1761 iwe.u.data.length = min(ie[1] + 2, 64);
1762 (u8 *)ie); 1762 cev = iwe_stream_add_point(info, cev, end_buf, &iwe, ie);
1763 } 1763 }
1764 1764
1765 ie_len -= sizeof(*ie) + ie->len; 1765 ie_len -= 2 + ie[1];
1766 ie = (struct ieee80211_info_element *)&ie->data[ie->len]; 1766 ie += 2 + ie[1];
1767 } 1767 }
1768 1768
1769 return cev; 1769 return cev;
diff --git a/drivers/net/wireless/rt2x00/rt2400pci.c b/drivers/net/wireless/rt2x00/rt2400pci.c
index 1adca7a1b9dc..42bd38ac7a1d 100644
--- a/drivers/net/wireless/rt2x00/rt2400pci.c
+++ b/drivers/net/wireless/rt2x00/rt2400pci.c
@@ -188,43 +188,34 @@ static void rt2400pci_eepromregister_write(struct eeprom_93cx6 *eeprom)
188} 188}
189 189
190#ifdef CONFIG_RT2X00_LIB_DEBUGFS 190#ifdef CONFIG_RT2X00_LIB_DEBUGFS
191#define CSR_OFFSET(__word) ( CSR_REG_BASE + ((__word) * sizeof(u32)) )
192
193static void rt2400pci_read_csr(struct rt2x00_dev *rt2x00dev,
194 const unsigned int word, u32 *data)
195{
196 rt2x00pci_register_read(rt2x00dev, CSR_OFFSET(word), data);
197}
198
199static void rt2400pci_write_csr(struct rt2x00_dev *rt2x00dev,
200 const unsigned int word, u32 data)
201{
202 rt2x00pci_register_write(rt2x00dev, CSR_OFFSET(word), data);
203}
204
205static const struct rt2x00debug rt2400pci_rt2x00debug = { 191static const struct rt2x00debug rt2400pci_rt2x00debug = {
206 .owner = THIS_MODULE, 192 .owner = THIS_MODULE,
207 .csr = { 193 .csr = {
208 .read = rt2400pci_read_csr, 194 .read = rt2x00pci_register_read,
209 .write = rt2400pci_write_csr, 195 .write = rt2x00pci_register_write,
196 .flags = RT2X00DEBUGFS_OFFSET,
197 .word_base = CSR_REG_BASE,
210 .word_size = sizeof(u32), 198 .word_size = sizeof(u32),
211 .word_count = CSR_REG_SIZE / sizeof(u32), 199 .word_count = CSR_REG_SIZE / sizeof(u32),
212 }, 200 },
213 .eeprom = { 201 .eeprom = {
214 .read = rt2x00_eeprom_read, 202 .read = rt2x00_eeprom_read,
215 .write = rt2x00_eeprom_write, 203 .write = rt2x00_eeprom_write,
204 .word_base = EEPROM_BASE,
216 .word_size = sizeof(u16), 205 .word_size = sizeof(u16),
217 .word_count = EEPROM_SIZE / sizeof(u16), 206 .word_count = EEPROM_SIZE / sizeof(u16),
218 }, 207 },
219 .bbp = { 208 .bbp = {
220 .read = rt2400pci_bbp_read, 209 .read = rt2400pci_bbp_read,
221 .write = rt2400pci_bbp_write, 210 .write = rt2400pci_bbp_write,
211 .word_base = BBP_BASE,
222 .word_size = sizeof(u8), 212 .word_size = sizeof(u8),
223 .word_count = BBP_SIZE / sizeof(u8), 213 .word_count = BBP_SIZE / sizeof(u8),
224 }, 214 },
225 .rf = { 215 .rf = {
226 .read = rt2x00_rf_read, 216 .read = rt2x00_rf_read,
227 .write = rt2400pci_rf_write, 217 .write = rt2400pci_rf_write,
218 .word_base = RF_BASE,
228 .word_size = sizeof(u32), 219 .word_size = sizeof(u32),
229 .word_count = RF_SIZE / sizeof(u32), 220 .word_count = RF_SIZE / sizeof(u32),
230 }, 221 },
@@ -396,12 +387,74 @@ static void rt2400pci_config_erp(struct rt2x00_dev *rt2x00dev,
396 rt2x00_set_field32(&reg, ARCSR5_SERVICE, 0x84); 387 rt2x00_set_field32(&reg, ARCSR5_SERVICE, 0x84);
397 rt2x00_set_field32(&reg, ARCSR2_LENGTH, get_duration(ACK_SIZE, 110)); 388 rt2x00_set_field32(&reg, ARCSR2_LENGTH, get_duration(ACK_SIZE, 110));
398 rt2x00pci_register_write(rt2x00dev, ARCSR5, reg); 389 rt2x00pci_register_write(rt2x00dev, ARCSR5, reg);
390
391 rt2x00pci_register_write(rt2x00dev, ARCSR1, erp->basic_rates);
392
393 rt2x00pci_register_read(rt2x00dev, CSR11, &reg);
394 rt2x00_set_field32(&reg, CSR11_SLOT_TIME, erp->slot_time);
395 rt2x00pci_register_write(rt2x00dev, CSR11, reg);
396
397 rt2x00pci_register_read(rt2x00dev, CSR18, &reg);
398 rt2x00_set_field32(&reg, CSR18_SIFS, erp->sifs);
399 rt2x00_set_field32(&reg, CSR18_PIFS, erp->pifs);
400 rt2x00pci_register_write(rt2x00dev, CSR18, reg);
401
402 rt2x00pci_register_read(rt2x00dev, CSR19, &reg);
403 rt2x00_set_field32(&reg, CSR19_DIFS, erp->difs);
404 rt2x00_set_field32(&reg, CSR19_EIFS, erp->eifs);
405 rt2x00pci_register_write(rt2x00dev, CSR19, reg);
399} 406}
400 407
401static void rt2400pci_config_phymode(struct rt2x00_dev *rt2x00dev, 408static void rt2400pci_config_ant(struct rt2x00_dev *rt2x00dev,
402 const int basic_rate_mask) 409 struct antenna_setup *ant)
403{ 410{
404 rt2x00pci_register_write(rt2x00dev, ARCSR1, basic_rate_mask); 411 u8 r1;
412 u8 r4;
413
414 /*
415 * We should never come here because rt2x00lib is supposed
416 * to catch this and send us the correct antenna explicitely.
417 */
418 BUG_ON(ant->rx == ANTENNA_SW_DIVERSITY ||
419 ant->tx == ANTENNA_SW_DIVERSITY);
420
421 rt2400pci_bbp_read(rt2x00dev, 4, &r4);
422 rt2400pci_bbp_read(rt2x00dev, 1, &r1);
423
424 /*
425 * Configure the TX antenna.
426 */
427 switch (ant->tx) {
428 case ANTENNA_HW_DIVERSITY:
429 rt2x00_set_field8(&r1, BBP_R1_TX_ANTENNA, 1);
430 break;
431 case ANTENNA_A:
432 rt2x00_set_field8(&r1, BBP_R1_TX_ANTENNA, 0);
433 break;
434 case ANTENNA_B:
435 default:
436 rt2x00_set_field8(&r1, BBP_R1_TX_ANTENNA, 2);
437 break;
438 }
439
440 /*
441 * Configure the RX antenna.
442 */
443 switch (ant->rx) {
444 case ANTENNA_HW_DIVERSITY:
445 rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA, 1);
446 break;
447 case ANTENNA_A:
448 rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA, 0);
449 break;
450 case ANTENNA_B:
451 default:
452 rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA, 2);
453 break;
454 }
455
456 rt2400pci_bbp_write(rt2x00dev, 4, r4);
457 rt2400pci_bbp_write(rt2x00dev, 1, r1);
405} 458}
406 459
407static void rt2400pci_config_channel(struct rt2x00_dev *rt2x00dev, 460static void rt2400pci_config_channel(struct rt2x00_dev *rt2x00dev,
@@ -460,56 +513,17 @@ static void rt2400pci_config_txpower(struct rt2x00_dev *rt2x00dev, int txpower)
460 rt2400pci_bbp_write(rt2x00dev, 3, TXPOWER_TO_DEV(txpower)); 513 rt2400pci_bbp_write(rt2x00dev, 3, TXPOWER_TO_DEV(txpower));
461} 514}
462 515
463static void rt2400pci_config_antenna(struct rt2x00_dev *rt2x00dev, 516static void rt2400pci_config_retry_limit(struct rt2x00_dev *rt2x00dev,
464 struct antenna_setup *ant) 517 struct rt2x00lib_conf *libconf)
465{ 518{
466 u8 r1; 519 u32 reg;
467 u8 r4;
468
469 /*
470 * We should never come here because rt2x00lib is supposed
471 * to catch this and send us the correct antenna explicitely.
472 */
473 BUG_ON(ant->rx == ANTENNA_SW_DIVERSITY ||
474 ant->tx == ANTENNA_SW_DIVERSITY);
475
476 rt2400pci_bbp_read(rt2x00dev, 4, &r4);
477 rt2400pci_bbp_read(rt2x00dev, 1, &r1);
478
479 /*
480 * Configure the TX antenna.
481 */
482 switch (ant->tx) {
483 case ANTENNA_HW_DIVERSITY:
484 rt2x00_set_field8(&r1, BBP_R1_TX_ANTENNA, 1);
485 break;
486 case ANTENNA_A:
487 rt2x00_set_field8(&r1, BBP_R1_TX_ANTENNA, 0);
488 break;
489 case ANTENNA_B:
490 default:
491 rt2x00_set_field8(&r1, BBP_R1_TX_ANTENNA, 2);
492 break;
493 }
494
495 /*
496 * Configure the RX antenna.
497 */
498 switch (ant->rx) {
499 case ANTENNA_HW_DIVERSITY:
500 rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA, 1);
501 break;
502 case ANTENNA_A:
503 rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA, 0);
504 break;
505 case ANTENNA_B:
506 default:
507 rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA, 2);
508 break;
509 }
510 520
511 rt2400pci_bbp_write(rt2x00dev, 4, r4); 521 rt2x00pci_register_read(rt2x00dev, CSR11, &reg);
512 rt2400pci_bbp_write(rt2x00dev, 1, r1); 522 rt2x00_set_field32(&reg, CSR11_LONG_RETRY,
523 libconf->conf->long_frame_max_tx_count);
524 rt2x00_set_field32(&reg, CSR11_SHORT_RETRY,
525 libconf->conf->short_frame_max_tx_count);
526 rt2x00pci_register_write(rt2x00dev, CSR11, reg);
513} 527}
514 528
515static void rt2400pci_config_duration(struct rt2x00_dev *rt2x00dev, 529static void rt2400pci_config_duration(struct rt2x00_dev *rt2x00dev,
@@ -517,20 +531,6 @@ static void rt2400pci_config_duration(struct rt2x00_dev *rt2x00dev,
517{ 531{
518 u32 reg; 532 u32 reg;
519 533
520 rt2x00pci_register_read(rt2x00dev, CSR11, &reg);
521 rt2x00_set_field32(&reg, CSR11_SLOT_TIME, libconf->slot_time);
522 rt2x00pci_register_write(rt2x00dev, CSR11, reg);
523
524 rt2x00pci_register_read(rt2x00dev, CSR18, &reg);
525 rt2x00_set_field32(&reg, CSR18_SIFS, libconf->sifs);
526 rt2x00_set_field32(&reg, CSR18_PIFS, libconf->pifs);
527 rt2x00pci_register_write(rt2x00dev, CSR18, reg);
528
529 rt2x00pci_register_read(rt2x00dev, CSR19, &reg);
530 rt2x00_set_field32(&reg, CSR19_DIFS, libconf->difs);
531 rt2x00_set_field32(&reg, CSR19_EIFS, libconf->eifs);
532 rt2x00pci_register_write(rt2x00dev, CSR19, reg);
533
534 rt2x00pci_register_read(rt2x00dev, TXCSR1, &reg); 534 rt2x00pci_register_read(rt2x00dev, TXCSR1, &reg);
535 rt2x00_set_field32(&reg, TXCSR1_TSF_OFFSET, IEEE80211_HEADER); 535 rt2x00_set_field32(&reg, TXCSR1_TSF_OFFSET, IEEE80211_HEADER);
536 rt2x00_set_field32(&reg, TXCSR1_AUTORESPONDER, 1); 536 rt2x00_set_field32(&reg, TXCSR1_AUTORESPONDER, 1);
@@ -548,16 +548,14 @@ static void rt2400pci_config(struct rt2x00_dev *rt2x00dev,
548 struct rt2x00lib_conf *libconf, 548 struct rt2x00lib_conf *libconf,
549 const unsigned int flags) 549 const unsigned int flags)
550{ 550{
551 if (flags & CONFIG_UPDATE_PHYMODE) 551 if (flags & IEEE80211_CONF_CHANGE_CHANNEL)
552 rt2400pci_config_phymode(rt2x00dev, libconf->basic_rates);
553 if (flags & CONFIG_UPDATE_CHANNEL)
554 rt2400pci_config_channel(rt2x00dev, &libconf->rf); 552 rt2400pci_config_channel(rt2x00dev, &libconf->rf);
555 if (flags & CONFIG_UPDATE_TXPOWER) 553 if (flags & IEEE80211_CONF_CHANGE_POWER)
556 rt2400pci_config_txpower(rt2x00dev, 554 rt2400pci_config_txpower(rt2x00dev,
557 libconf->conf->power_level); 555 libconf->conf->power_level);
558 if (flags & CONFIG_UPDATE_ANTENNA) 556 if (flags & IEEE80211_CONF_CHANGE_RETRY_LIMITS)
559 rt2400pci_config_antenna(rt2x00dev, &libconf->ant); 557 rt2400pci_config_retry_limit(rt2x00dev, libconf);
560 if (flags & (CONFIG_UPDATE_SLOT_TIME | CONFIG_UPDATE_BEACON_INT)) 558 if (flags & IEEE80211_CONF_CHANGE_BEACON_INTERVAL)
561 rt2400pci_config_duration(rt2x00dev, libconf); 559 rt2400pci_config_duration(rt2x00dev, libconf);
562} 560}
563 561
@@ -1502,20 +1500,6 @@ static int rt2400pci_probe_hw(struct rt2x00_dev *rt2x00dev)
1502/* 1500/*
1503 * IEEE80211 stack callback functions. 1501 * IEEE80211 stack callback functions.
1504 */ 1502 */
1505static int rt2400pci_set_retry_limit(struct ieee80211_hw *hw,
1506 u32 short_retry, u32 long_retry)
1507{
1508 struct rt2x00_dev *rt2x00dev = hw->priv;
1509 u32 reg;
1510
1511 rt2x00pci_register_read(rt2x00dev, CSR11, &reg);
1512 rt2x00_set_field32(&reg, CSR11_LONG_RETRY, long_retry);
1513 rt2x00_set_field32(&reg, CSR11_SHORT_RETRY, short_retry);
1514 rt2x00pci_register_write(rt2x00dev, CSR11, reg);
1515
1516 return 0;
1517}
1518
1519static int rt2400pci_conf_tx(struct ieee80211_hw *hw, u16 queue, 1503static int rt2400pci_conf_tx(struct ieee80211_hw *hw, u16 queue,
1520 const struct ieee80211_tx_queue_params *params) 1504 const struct ieee80211_tx_queue_params *params)
1521{ 1505{
@@ -1601,8 +1585,8 @@ static const struct rt2x00lib_ops rt2400pci_rt2x00_ops = {
1601 .config_filter = rt2400pci_config_filter, 1585 .config_filter = rt2400pci_config_filter,
1602 .config_intf = rt2400pci_config_intf, 1586 .config_intf = rt2400pci_config_intf,
1603 .config_erp = rt2400pci_config_erp, 1587 .config_erp = rt2400pci_config_erp,
1588 .config_ant = rt2400pci_config_ant,
1604 .config = rt2400pci_config, 1589 .config = rt2400pci_config,
1605 .set_retry_limit = rt2400pci_set_retry_limit,
1606}; 1590};
1607 1591
1608static const struct data_queue_desc rt2400pci_queue_rx = { 1592static const struct data_queue_desc rt2400pci_queue_rx = {
diff --git a/drivers/net/wireless/rt2x00/rt2400pci.h b/drivers/net/wireless/rt2x00/rt2400pci.h
index bbff381ce396..9aefda4ab3c2 100644
--- a/drivers/net/wireless/rt2x00/rt2400pci.h
+++ b/drivers/net/wireless/rt2x00/rt2400pci.h
@@ -46,7 +46,9 @@
46#define CSR_REG_SIZE 0x014c 46#define CSR_REG_SIZE 0x014c
47#define EEPROM_BASE 0x0000 47#define EEPROM_BASE 0x0000
48#define EEPROM_SIZE 0x0100 48#define EEPROM_SIZE 0x0100
49#define BBP_BASE 0x0000
49#define BBP_SIZE 0x0020 50#define BBP_SIZE 0x0020
51#define RF_BASE 0x0000
50#define RF_SIZE 0x0010 52#define RF_SIZE 0x0010
51 53
52/* 54/*
diff --git a/drivers/net/wireless/rt2x00/rt2500pci.c b/drivers/net/wireless/rt2x00/rt2500pci.c
index 85b0387f46eb..928452f30c25 100644
--- a/drivers/net/wireless/rt2x00/rt2500pci.c
+++ b/drivers/net/wireless/rt2x00/rt2500pci.c
@@ -188,43 +188,34 @@ static void rt2500pci_eepromregister_write(struct eeprom_93cx6 *eeprom)
188} 188}
189 189
190#ifdef CONFIG_RT2X00_LIB_DEBUGFS 190#ifdef CONFIG_RT2X00_LIB_DEBUGFS
191#define CSR_OFFSET(__word) ( CSR_REG_BASE + ((__word) * sizeof(u32)) )
192
193static void rt2500pci_read_csr(struct rt2x00_dev *rt2x00dev,
194 const unsigned int word, u32 *data)
195{
196 rt2x00pci_register_read(rt2x00dev, CSR_OFFSET(word), data);
197}
198
199static void rt2500pci_write_csr(struct rt2x00_dev *rt2x00dev,
200 const unsigned int word, u32 data)
201{
202 rt2x00pci_register_write(rt2x00dev, CSR_OFFSET(word), data);
203}
204
205static const struct rt2x00debug rt2500pci_rt2x00debug = { 191static const struct rt2x00debug rt2500pci_rt2x00debug = {
206 .owner = THIS_MODULE, 192 .owner = THIS_MODULE,
207 .csr = { 193 .csr = {
208 .read = rt2500pci_read_csr, 194 .read = rt2x00pci_register_read,
209 .write = rt2500pci_write_csr, 195 .write = rt2x00pci_register_write,
196 .flags = RT2X00DEBUGFS_OFFSET,
197 .word_base = CSR_REG_BASE,
210 .word_size = sizeof(u32), 198 .word_size = sizeof(u32),
211 .word_count = CSR_REG_SIZE / sizeof(u32), 199 .word_count = CSR_REG_SIZE / sizeof(u32),
212 }, 200 },
213 .eeprom = { 201 .eeprom = {
214 .read = rt2x00_eeprom_read, 202 .read = rt2x00_eeprom_read,
215 .write = rt2x00_eeprom_write, 203 .write = rt2x00_eeprom_write,
204 .word_base = EEPROM_BASE,
216 .word_size = sizeof(u16), 205 .word_size = sizeof(u16),
217 .word_count = EEPROM_SIZE / sizeof(u16), 206 .word_count = EEPROM_SIZE / sizeof(u16),
218 }, 207 },
219 .bbp = { 208 .bbp = {
220 .read = rt2500pci_bbp_read, 209 .read = rt2500pci_bbp_read,
221 .write = rt2500pci_bbp_write, 210 .write = rt2500pci_bbp_write,
211 .word_base = BBP_BASE,
222 .word_size = sizeof(u8), 212 .word_size = sizeof(u8),
223 .word_count = BBP_SIZE / sizeof(u8), 213 .word_count = BBP_SIZE / sizeof(u8),
224 }, 214 },
225 .rf = { 215 .rf = {
226 .read = rt2x00_rf_read, 216 .read = rt2x00_rf_read,
227 .write = rt2500pci_rf_write, 217 .write = rt2500pci_rf_write,
218 .word_base = RF_BASE,
228 .word_size = sizeof(u32), 219 .word_size = sizeof(u32),
229 .word_count = RF_SIZE / sizeof(u32), 220 .word_count = RF_SIZE / sizeof(u32),
230 }, 221 },
@@ -402,12 +393,94 @@ static void rt2500pci_config_erp(struct rt2x00_dev *rt2x00dev,
402 rt2x00_set_field32(&reg, ARCSR5_SERVICE, 0x84); 393 rt2x00_set_field32(&reg, ARCSR5_SERVICE, 0x84);
403 rt2x00_set_field32(&reg, ARCSR2_LENGTH, get_duration(ACK_SIZE, 110)); 394 rt2x00_set_field32(&reg, ARCSR2_LENGTH, get_duration(ACK_SIZE, 110));
404 rt2x00pci_register_write(rt2x00dev, ARCSR5, reg); 395 rt2x00pci_register_write(rt2x00dev, ARCSR5, reg);
396
397 rt2x00pci_register_write(rt2x00dev, ARCSR1, erp->basic_rates);
398
399 rt2x00pci_register_read(rt2x00dev, CSR11, &reg);
400 rt2x00_set_field32(&reg, CSR11_SLOT_TIME, erp->slot_time);
401 rt2x00pci_register_write(rt2x00dev, CSR11, reg);
402
403 rt2x00pci_register_read(rt2x00dev, CSR18, &reg);
404 rt2x00_set_field32(&reg, CSR18_SIFS, erp->sifs);
405 rt2x00_set_field32(&reg, CSR18_PIFS, erp->pifs);
406 rt2x00pci_register_write(rt2x00dev, CSR18, reg);
407
408 rt2x00pci_register_read(rt2x00dev, CSR19, &reg);
409 rt2x00_set_field32(&reg, CSR19_DIFS, erp->difs);
410 rt2x00_set_field32(&reg, CSR19_EIFS, erp->eifs);
411 rt2x00pci_register_write(rt2x00dev, CSR19, reg);
405} 412}
406 413
407static void rt2500pci_config_phymode(struct rt2x00_dev *rt2x00dev, 414static void rt2500pci_config_ant(struct rt2x00_dev *rt2x00dev,
408 const int basic_rate_mask) 415 struct antenna_setup *ant)
409{ 416{
410 rt2x00pci_register_write(rt2x00dev, ARCSR1, basic_rate_mask); 417 u32 reg;
418 u8 r14;
419 u8 r2;
420
421 /*
422 * We should never come here because rt2x00lib is supposed
423 * to catch this and send us the correct antenna explicitely.
424 */
425 BUG_ON(ant->rx == ANTENNA_SW_DIVERSITY ||
426 ant->tx == ANTENNA_SW_DIVERSITY);
427
428 rt2x00pci_register_read(rt2x00dev, BBPCSR1, &reg);
429 rt2500pci_bbp_read(rt2x00dev, 14, &r14);
430 rt2500pci_bbp_read(rt2x00dev, 2, &r2);
431
432 /*
433 * Configure the TX antenna.
434 */
435 switch (ant->tx) {
436 case ANTENNA_A:
437 rt2x00_set_field8(&r2, BBP_R2_TX_ANTENNA, 0);
438 rt2x00_set_field32(&reg, BBPCSR1_CCK, 0);
439 rt2x00_set_field32(&reg, BBPCSR1_OFDM, 0);
440 break;
441 case ANTENNA_B:
442 default:
443 rt2x00_set_field8(&r2, BBP_R2_TX_ANTENNA, 2);
444 rt2x00_set_field32(&reg, BBPCSR1_CCK, 2);
445 rt2x00_set_field32(&reg, BBPCSR1_OFDM, 2);
446 break;
447 }
448
449 /*
450 * Configure the RX antenna.
451 */
452 switch (ant->rx) {
453 case ANTENNA_A:
454 rt2x00_set_field8(&r14, BBP_R14_RX_ANTENNA, 0);
455 break;
456 case ANTENNA_B:
457 default:
458 rt2x00_set_field8(&r14, BBP_R14_RX_ANTENNA, 2);
459 break;
460 }
461
462 /*
463 * RT2525E and RT5222 need to flip TX I/Q
464 */
465 if (rt2x00_rf(&rt2x00dev->chip, RF2525E) ||
466 rt2x00_rf(&rt2x00dev->chip, RF5222)) {
467 rt2x00_set_field8(&r2, BBP_R2_TX_IQ_FLIP, 1);
468 rt2x00_set_field32(&reg, BBPCSR1_CCK_FLIP, 1);
469 rt2x00_set_field32(&reg, BBPCSR1_OFDM_FLIP, 1);
470
471 /*
472 * RT2525E does not need RX I/Q Flip.
473 */
474 if (rt2x00_rf(&rt2x00dev->chip, RF2525E))
475 rt2x00_set_field8(&r14, BBP_R14_RX_IQ_FLIP, 0);
476 } else {
477 rt2x00_set_field32(&reg, BBPCSR1_CCK_FLIP, 0);
478 rt2x00_set_field32(&reg, BBPCSR1_OFDM_FLIP, 0);
479 }
480
481 rt2x00pci_register_write(rt2x00dev, BBPCSR1, reg);
482 rt2500pci_bbp_write(rt2x00dev, 14, r14);
483 rt2500pci_bbp_write(rt2x00dev, 2, r2);
411} 484}
412 485
413static void rt2500pci_config_channel(struct rt2x00_dev *rt2x00dev, 486static void rt2500pci_config_channel(struct rt2x00_dev *rt2x00dev,
@@ -489,76 +562,17 @@ static void rt2500pci_config_txpower(struct rt2x00_dev *rt2x00dev,
489 rt2500pci_rf_write(rt2x00dev, 3, rf3); 562 rt2500pci_rf_write(rt2x00dev, 3, rf3);
490} 563}
491 564
492static void rt2500pci_config_antenna(struct rt2x00_dev *rt2x00dev, 565static void rt2500pci_config_retry_limit(struct rt2x00_dev *rt2x00dev,
493 struct antenna_setup *ant) 566 struct rt2x00lib_conf *libconf)
494{ 567{
495 u32 reg; 568 u32 reg;
496 u8 r14;
497 u8 r2;
498
499 /*
500 * We should never come here because rt2x00lib is supposed
501 * to catch this and send us the correct antenna explicitely.
502 */
503 BUG_ON(ant->rx == ANTENNA_SW_DIVERSITY ||
504 ant->tx == ANTENNA_SW_DIVERSITY);
505
506 rt2x00pci_register_read(rt2x00dev, BBPCSR1, &reg);
507 rt2500pci_bbp_read(rt2x00dev, 14, &r14);
508 rt2500pci_bbp_read(rt2x00dev, 2, &r2);
509 569
510 /* 570 rt2x00pci_register_read(rt2x00dev, CSR11, &reg);
511 * Configure the TX antenna. 571 rt2x00_set_field32(&reg, CSR11_LONG_RETRY,
512 */ 572 libconf->conf->long_frame_max_tx_count);
513 switch (ant->tx) { 573 rt2x00_set_field32(&reg, CSR11_SHORT_RETRY,
514 case ANTENNA_A: 574 libconf->conf->short_frame_max_tx_count);
515 rt2x00_set_field8(&r2, BBP_R2_TX_ANTENNA, 0); 575 rt2x00pci_register_write(rt2x00dev, CSR11, reg);
516 rt2x00_set_field32(&reg, BBPCSR1_CCK, 0);
517 rt2x00_set_field32(&reg, BBPCSR1_OFDM, 0);
518 break;
519 case ANTENNA_B:
520 default:
521 rt2x00_set_field8(&r2, BBP_R2_TX_ANTENNA, 2);
522 rt2x00_set_field32(&reg, BBPCSR1_CCK, 2);
523 rt2x00_set_field32(&reg, BBPCSR1_OFDM, 2);
524 break;
525 }
526
527 /*
528 * Configure the RX antenna.
529 */
530 switch (ant->rx) {
531 case ANTENNA_A:
532 rt2x00_set_field8(&r14, BBP_R14_RX_ANTENNA, 0);
533 break;
534 case ANTENNA_B:
535 default:
536 rt2x00_set_field8(&r14, BBP_R14_RX_ANTENNA, 2);
537 break;
538 }
539
540 /*
541 * RT2525E and RT5222 need to flip TX I/Q
542 */
543 if (rt2x00_rf(&rt2x00dev->chip, RF2525E) ||
544 rt2x00_rf(&rt2x00dev->chip, RF5222)) {
545 rt2x00_set_field8(&r2, BBP_R2_TX_IQ_FLIP, 1);
546 rt2x00_set_field32(&reg, BBPCSR1_CCK_FLIP, 1);
547 rt2x00_set_field32(&reg, BBPCSR1_OFDM_FLIP, 1);
548
549 /*
550 * RT2525E does not need RX I/Q Flip.
551 */
552 if (rt2x00_rf(&rt2x00dev->chip, RF2525E))
553 rt2x00_set_field8(&r14, BBP_R14_RX_IQ_FLIP, 0);
554 } else {
555 rt2x00_set_field32(&reg, BBPCSR1_CCK_FLIP, 0);
556 rt2x00_set_field32(&reg, BBPCSR1_OFDM_FLIP, 0);
557 }
558
559 rt2x00pci_register_write(rt2x00dev, BBPCSR1, reg);
560 rt2500pci_bbp_write(rt2x00dev, 14, r14);
561 rt2500pci_bbp_write(rt2x00dev, 2, r2);
562} 576}
563 577
564static void rt2500pci_config_duration(struct rt2x00_dev *rt2x00dev, 578static void rt2500pci_config_duration(struct rt2x00_dev *rt2x00dev,
@@ -566,20 +580,6 @@ static void rt2500pci_config_duration(struct rt2x00_dev *rt2x00dev,
566{ 580{
567 u32 reg; 581 u32 reg;
568 582
569 rt2x00pci_register_read(rt2x00dev, CSR11, &reg);
570 rt2x00_set_field32(&reg, CSR11_SLOT_TIME, libconf->slot_time);
571 rt2x00pci_register_write(rt2x00dev, CSR11, reg);
572
573 rt2x00pci_register_read(rt2x00dev, CSR18, &reg);
574 rt2x00_set_field32(&reg, CSR18_SIFS, libconf->sifs);
575 rt2x00_set_field32(&reg, CSR18_PIFS, libconf->pifs);
576 rt2x00pci_register_write(rt2x00dev, CSR18, reg);
577
578 rt2x00pci_register_read(rt2x00dev, CSR19, &reg);
579 rt2x00_set_field32(&reg, CSR19_DIFS, libconf->difs);
580 rt2x00_set_field32(&reg, CSR19_EIFS, libconf->eifs);
581 rt2x00pci_register_write(rt2x00dev, CSR19, reg);
582
583 rt2x00pci_register_read(rt2x00dev, TXCSR1, &reg); 583 rt2x00pci_register_read(rt2x00dev, TXCSR1, &reg);
584 rt2x00_set_field32(&reg, TXCSR1_TSF_OFFSET, IEEE80211_HEADER); 584 rt2x00_set_field32(&reg, TXCSR1_TSF_OFFSET, IEEE80211_HEADER);
585 rt2x00_set_field32(&reg, TXCSR1_AUTORESPONDER, 1); 585 rt2x00_set_field32(&reg, TXCSR1_AUTORESPONDER, 1);
@@ -597,17 +597,16 @@ static void rt2500pci_config(struct rt2x00_dev *rt2x00dev,
597 struct rt2x00lib_conf *libconf, 597 struct rt2x00lib_conf *libconf,
598 const unsigned int flags) 598 const unsigned int flags)
599{ 599{
600 if (flags & CONFIG_UPDATE_PHYMODE) 600 if (flags & IEEE80211_CONF_CHANGE_CHANNEL)
601 rt2500pci_config_phymode(rt2x00dev, libconf->basic_rates);
602 if (flags & CONFIG_UPDATE_CHANNEL)
603 rt2500pci_config_channel(rt2x00dev, &libconf->rf, 601 rt2500pci_config_channel(rt2x00dev, &libconf->rf,
604 libconf->conf->power_level); 602 libconf->conf->power_level);
605 if ((flags & CONFIG_UPDATE_TXPOWER) && !(flags & CONFIG_UPDATE_CHANNEL)) 603 if ((flags & IEEE80211_CONF_CHANGE_POWER) &&
604 !(flags & IEEE80211_CONF_CHANGE_CHANNEL))
606 rt2500pci_config_txpower(rt2x00dev, 605 rt2500pci_config_txpower(rt2x00dev,
607 libconf->conf->power_level); 606 libconf->conf->power_level);
608 if (flags & CONFIG_UPDATE_ANTENNA) 607 if (flags & IEEE80211_CONF_CHANGE_RETRY_LIMITS)
609 rt2500pci_config_antenna(rt2x00dev, &libconf->ant); 608 rt2500pci_config_retry_limit(rt2x00dev, libconf);
610 if (flags & (CONFIG_UPDATE_SLOT_TIME | CONFIG_UPDATE_BEACON_INT)) 609 if (flags & IEEE80211_CONF_CHANGE_BEACON_INTERVAL)
611 rt2500pci_config_duration(rt2x00dev, libconf); 610 rt2500pci_config_duration(rt2x00dev, libconf);
612} 611}
613 612
@@ -1827,20 +1826,6 @@ static int rt2500pci_probe_hw(struct rt2x00_dev *rt2x00dev)
1827/* 1826/*
1828 * IEEE80211 stack callback functions. 1827 * IEEE80211 stack callback functions.
1829 */ 1828 */
1830static int rt2500pci_set_retry_limit(struct ieee80211_hw *hw,
1831 u32 short_retry, u32 long_retry)
1832{
1833 struct rt2x00_dev *rt2x00dev = hw->priv;
1834 u32 reg;
1835
1836 rt2x00pci_register_read(rt2x00dev, CSR11, &reg);
1837 rt2x00_set_field32(&reg, CSR11_LONG_RETRY, long_retry);
1838 rt2x00_set_field32(&reg, CSR11_SHORT_RETRY, short_retry);
1839 rt2x00pci_register_write(rt2x00dev, CSR11, reg);
1840
1841 return 0;
1842}
1843
1844static u64 rt2500pci_get_tsf(struct ieee80211_hw *hw) 1829static u64 rt2500pci_get_tsf(struct ieee80211_hw *hw)
1845{ 1830{
1846 struct rt2x00_dev *rt2x00dev = hw->priv; 1831 struct rt2x00_dev *rt2x00dev = hw->priv;
@@ -1901,8 +1886,8 @@ static const struct rt2x00lib_ops rt2500pci_rt2x00_ops = {
1901 .config_filter = rt2500pci_config_filter, 1886 .config_filter = rt2500pci_config_filter,
1902 .config_intf = rt2500pci_config_intf, 1887 .config_intf = rt2500pci_config_intf,
1903 .config_erp = rt2500pci_config_erp, 1888 .config_erp = rt2500pci_config_erp,
1889 .config_ant = rt2500pci_config_ant,
1904 .config = rt2500pci_config, 1890 .config = rt2500pci_config,
1905 .set_retry_limit = rt2500pci_set_retry_limit,
1906}; 1891};
1907 1892
1908static const struct data_queue_desc rt2500pci_queue_rx = { 1893static const struct data_queue_desc rt2500pci_queue_rx = {
diff --git a/drivers/net/wireless/rt2x00/rt2500pci.h b/drivers/net/wireless/rt2x00/rt2500pci.h
index 8c26bef6cf49..e135247f7f89 100644
--- a/drivers/net/wireless/rt2x00/rt2500pci.h
+++ b/drivers/net/wireless/rt2x00/rt2500pci.h
@@ -57,7 +57,9 @@
57#define CSR_REG_SIZE 0x0174 57#define CSR_REG_SIZE 0x0174
58#define EEPROM_BASE 0x0000 58#define EEPROM_BASE 0x0000
59#define EEPROM_SIZE 0x0200 59#define EEPROM_SIZE 0x0200
60#define BBP_BASE 0x0000
60#define BBP_SIZE 0x0040 61#define BBP_SIZE 0x0040
62#define RF_BASE 0x0000
61#define RF_SIZE 0x0014 63#define RF_SIZE 0x0014
62 64
63/* 65/*
diff --git a/drivers/net/wireless/rt2x00/rt2500usb.c b/drivers/net/wireless/rt2x00/rt2500usb.c
index d19bee43861d..639d5a2f84e2 100644
--- a/drivers/net/wireless/rt2x00/rt2500usb.c
+++ b/drivers/net/wireless/rt2x00/rt2500usb.c
@@ -245,43 +245,48 @@ rf_write:
245} 245}
246 246
247#ifdef CONFIG_RT2X00_LIB_DEBUGFS 247#ifdef CONFIG_RT2X00_LIB_DEBUGFS
248#define CSR_OFFSET(__word) ( CSR_REG_BASE + ((__word) * sizeof(u16)) ) 248static void _rt2500usb_register_read(struct rt2x00_dev *rt2x00dev,
249 249 const unsigned int offset,
250static void rt2500usb_read_csr(struct rt2x00_dev *rt2x00dev, 250 u32 *value)
251 const unsigned int word, u32 *data)
252{ 251{
253 rt2500usb_register_read(rt2x00dev, CSR_OFFSET(word), (u16 *) data); 252 rt2500usb_register_read(rt2x00dev, offset, (u16 *)value);
254} 253}
255 254
256static void rt2500usb_write_csr(struct rt2x00_dev *rt2x00dev, 255static void _rt2500usb_register_write(struct rt2x00_dev *rt2x00dev,
257 const unsigned int word, u32 data) 256 const unsigned int offset,
257 u32 value)
258{ 258{
259 rt2500usb_register_write(rt2x00dev, CSR_OFFSET(word), data); 259 rt2500usb_register_write(rt2x00dev, offset, value);
260} 260}
261 261
262static const struct rt2x00debug rt2500usb_rt2x00debug = { 262static const struct rt2x00debug rt2500usb_rt2x00debug = {
263 .owner = THIS_MODULE, 263 .owner = THIS_MODULE,
264 .csr = { 264 .csr = {
265 .read = rt2500usb_read_csr, 265 .read = _rt2500usb_register_read,
266 .write = rt2500usb_write_csr, 266 .write = _rt2500usb_register_write,
267 .flags = RT2X00DEBUGFS_OFFSET,
268 .word_base = CSR_REG_BASE,
267 .word_size = sizeof(u16), 269 .word_size = sizeof(u16),
268 .word_count = CSR_REG_SIZE / sizeof(u16), 270 .word_count = CSR_REG_SIZE / sizeof(u16),
269 }, 271 },
270 .eeprom = { 272 .eeprom = {
271 .read = rt2x00_eeprom_read, 273 .read = rt2x00_eeprom_read,
272 .write = rt2x00_eeprom_write, 274 .write = rt2x00_eeprom_write,
275 .word_base = EEPROM_BASE,
273 .word_size = sizeof(u16), 276 .word_size = sizeof(u16),
274 .word_count = EEPROM_SIZE / sizeof(u16), 277 .word_count = EEPROM_SIZE / sizeof(u16),
275 }, 278 },
276 .bbp = { 279 .bbp = {
277 .read = rt2500usb_bbp_read, 280 .read = rt2500usb_bbp_read,
278 .write = rt2500usb_bbp_write, 281 .write = rt2500usb_bbp_write,
282 .word_base = BBP_BASE,
279 .word_size = sizeof(u8), 283 .word_size = sizeof(u8),
280 .word_count = BBP_SIZE / sizeof(u8), 284 .word_count = BBP_SIZE / sizeof(u8),
281 }, 285 },
282 .rf = { 286 .rf = {
283 .read = rt2x00_rf_read, 287 .read = rt2x00_rf_read,
284 .write = rt2500usb_rf_write, 288 .write = rt2500usb_rf_write,
289 .word_base = RF_BASE,
285 .word_size = sizeof(u32), 290 .word_size = sizeof(u32),
286 .word_count = RF_SIZE / sizeof(u32), 291 .word_count = RF_SIZE / sizeof(u32),
287 }, 292 },
@@ -423,57 +428,16 @@ static void rt2500usb_config_erp(struct rt2x00_dev *rt2x00dev,
423 rt2x00_set_field16(&reg, TXRX_CSR10_AUTORESPOND_PREAMBLE, 428 rt2x00_set_field16(&reg, TXRX_CSR10_AUTORESPOND_PREAMBLE,
424 !!erp->short_preamble); 429 !!erp->short_preamble);
425 rt2500usb_register_write(rt2x00dev, TXRX_CSR10, reg); 430 rt2500usb_register_write(rt2x00dev, TXRX_CSR10, reg);
426}
427
428static void rt2500usb_config_phymode(struct rt2x00_dev *rt2x00dev,
429 const int basic_rate_mask)
430{
431 rt2500usb_register_write(rt2x00dev, TXRX_CSR11, basic_rate_mask);
432}
433 431
434static void rt2500usb_config_channel(struct rt2x00_dev *rt2x00dev, 432 rt2500usb_register_write(rt2x00dev, TXRX_CSR11, erp->basic_rates);
435 struct rf_channel *rf, const int txpower)
436{
437 /*
438 * Set TXpower.
439 */
440 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower));
441 433
442 /* 434 rt2500usb_register_write(rt2x00dev, MAC_CSR10, erp->slot_time);
443 * For RT2525E we should first set the channel to half band higher. 435 rt2500usb_register_write(rt2x00dev, MAC_CSR11, erp->sifs);
444 */ 436 rt2500usb_register_write(rt2x00dev, MAC_CSR12, erp->eifs);
445 if (rt2x00_rf(&rt2x00dev->chip, RF2525E)) {
446 static const u32 vals[] = {
447 0x000008aa, 0x000008ae, 0x000008ae, 0x000008b2,
448 0x000008b2, 0x000008b6, 0x000008b6, 0x000008ba,
449 0x000008ba, 0x000008be, 0x000008b7, 0x00000902,
450 0x00000902, 0x00000906
451 };
452
453 rt2500usb_rf_write(rt2x00dev, 2, vals[rf->channel - 1]);
454 if (rf->rf4)
455 rt2500usb_rf_write(rt2x00dev, 4, rf->rf4);
456 }
457
458 rt2500usb_rf_write(rt2x00dev, 1, rf->rf1);
459 rt2500usb_rf_write(rt2x00dev, 2, rf->rf2);
460 rt2500usb_rf_write(rt2x00dev, 3, rf->rf3);
461 if (rf->rf4)
462 rt2500usb_rf_write(rt2x00dev, 4, rf->rf4);
463}
464
465static void rt2500usb_config_txpower(struct rt2x00_dev *rt2x00dev,
466 const int txpower)
467{
468 u32 rf3;
469
470 rt2x00_rf_read(rt2x00dev, 3, &rf3);
471 rt2x00_set_field32(&rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower));
472 rt2500usb_rf_write(rt2x00dev, 3, rf3);
473} 437}
474 438
475static void rt2500usb_config_antenna(struct rt2x00_dev *rt2x00dev, 439static void rt2500usb_config_ant(struct rt2x00_dev *rt2x00dev,
476 struct antenna_setup *ant) 440 struct antenna_setup *ant)
477{ 441{
478 u8 r2; 442 u8 r2;
479 u8 r14; 443 u8 r14;
@@ -555,15 +519,52 @@ static void rt2500usb_config_antenna(struct rt2x00_dev *rt2x00dev,
555 rt2500usb_register_write(rt2x00dev, PHY_CSR6, csr6); 519 rt2500usb_register_write(rt2x00dev, PHY_CSR6, csr6);
556} 520}
557 521
522static void rt2500usb_config_channel(struct rt2x00_dev *rt2x00dev,
523 struct rf_channel *rf, const int txpower)
524{
525 /*
526 * Set TXpower.
527 */
528 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower));
529
530 /*
531 * For RT2525E we should first set the channel to half band higher.
532 */
533 if (rt2x00_rf(&rt2x00dev->chip, RF2525E)) {
534 static const u32 vals[] = {
535 0x000008aa, 0x000008ae, 0x000008ae, 0x000008b2,
536 0x000008b2, 0x000008b6, 0x000008b6, 0x000008ba,
537 0x000008ba, 0x000008be, 0x000008b7, 0x00000902,
538 0x00000902, 0x00000906
539 };
540
541 rt2500usb_rf_write(rt2x00dev, 2, vals[rf->channel - 1]);
542 if (rf->rf4)
543 rt2500usb_rf_write(rt2x00dev, 4, rf->rf4);
544 }
545
546 rt2500usb_rf_write(rt2x00dev, 1, rf->rf1);
547 rt2500usb_rf_write(rt2x00dev, 2, rf->rf2);
548 rt2500usb_rf_write(rt2x00dev, 3, rf->rf3);
549 if (rf->rf4)
550 rt2500usb_rf_write(rt2x00dev, 4, rf->rf4);
551}
552
553static void rt2500usb_config_txpower(struct rt2x00_dev *rt2x00dev,
554 const int txpower)
555{
556 u32 rf3;
557
558 rt2x00_rf_read(rt2x00dev, 3, &rf3);
559 rt2x00_set_field32(&rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower));
560 rt2500usb_rf_write(rt2x00dev, 3, rf3);
561}
562
558static void rt2500usb_config_duration(struct rt2x00_dev *rt2x00dev, 563static void rt2500usb_config_duration(struct rt2x00_dev *rt2x00dev,
559 struct rt2x00lib_conf *libconf) 564 struct rt2x00lib_conf *libconf)
560{ 565{
561 u16 reg; 566 u16 reg;
562 567
563 rt2500usb_register_write(rt2x00dev, MAC_CSR10, libconf->slot_time);
564 rt2500usb_register_write(rt2x00dev, MAC_CSR11, libconf->sifs);
565 rt2500usb_register_write(rt2x00dev, MAC_CSR12, libconf->eifs);
566
567 rt2500usb_register_read(rt2x00dev, TXRX_CSR18, &reg); 568 rt2500usb_register_read(rt2x00dev, TXRX_CSR18, &reg);
568 rt2x00_set_field16(&reg, TXRX_CSR18_INTERVAL, 569 rt2x00_set_field16(&reg, TXRX_CSR18_INTERVAL,
569 libconf->conf->beacon_int * 4); 570 libconf->conf->beacon_int * 4);
@@ -574,17 +575,14 @@ static void rt2500usb_config(struct rt2x00_dev *rt2x00dev,
574 struct rt2x00lib_conf *libconf, 575 struct rt2x00lib_conf *libconf,
575 const unsigned int flags) 576 const unsigned int flags)
576{ 577{
577 if (flags & CONFIG_UPDATE_PHYMODE) 578 if (flags & IEEE80211_CONF_CHANGE_CHANNEL)
578 rt2500usb_config_phymode(rt2x00dev, libconf->basic_rates);
579 if (flags & CONFIG_UPDATE_CHANNEL)
580 rt2500usb_config_channel(rt2x00dev, &libconf->rf, 579 rt2500usb_config_channel(rt2x00dev, &libconf->rf,
581 libconf->conf->power_level); 580 libconf->conf->power_level);
582 if ((flags & CONFIG_UPDATE_TXPOWER) && !(flags & CONFIG_UPDATE_CHANNEL)) 581 if ((flags & IEEE80211_CONF_CHANGE_POWER) &&
582 !(flags & IEEE80211_CONF_CHANGE_CHANNEL))
583 rt2500usb_config_txpower(rt2x00dev, 583 rt2500usb_config_txpower(rt2x00dev,
584 libconf->conf->power_level); 584 libconf->conf->power_level);
585 if (flags & CONFIG_UPDATE_ANTENNA) 585 if (flags & IEEE80211_CONF_CHANGE_BEACON_INTERVAL)
586 rt2500usb_config_antenna(rt2x00dev, &libconf->ant);
587 if (flags & (CONFIG_UPDATE_SLOT_TIME | CONFIG_UPDATE_BEACON_INT))
588 rt2500usb_config_duration(rt2x00dev, libconf); 586 rt2500usb_config_duration(rt2x00dev, libconf);
589} 587}
590 588
@@ -1794,6 +1792,7 @@ static const struct rt2x00lib_ops rt2500usb_rt2x00_ops = {
1794 .config_filter = rt2500usb_config_filter, 1792 .config_filter = rt2500usb_config_filter,
1795 .config_intf = rt2500usb_config_intf, 1793 .config_intf = rt2500usb_config_intf,
1796 .config_erp = rt2500usb_config_erp, 1794 .config_erp = rt2500usb_config_erp,
1795 .config_ant = rt2500usb_config_ant,
1797 .config = rt2500usb_config, 1796 .config = rt2500usb_config,
1798}; 1797};
1799 1798
diff --git a/drivers/net/wireless/rt2x00/rt2500usb.h b/drivers/net/wireless/rt2x00/rt2500usb.h
index 89e5ed24e4f7..dbb5d689e23d 100644
--- a/drivers/net/wireless/rt2x00/rt2500usb.h
+++ b/drivers/net/wireless/rt2x00/rt2500usb.h
@@ -57,7 +57,9 @@
57#define CSR_REG_SIZE 0x0100 57#define CSR_REG_SIZE 0x0100
58#define EEPROM_BASE 0x0000 58#define EEPROM_BASE 0x0000
59#define EEPROM_SIZE 0x006a 59#define EEPROM_SIZE 0x006a
60#define BBP_BASE 0x0000
60#define BBP_SIZE 0x0060 61#define BBP_SIZE 0x0060
62#define RF_BASE 0x0000
61#define RF_SIZE 0x0014 63#define RF_SIZE 0x0014
62 64
63/* 65/*
diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
index 0887e895d5c1..f85eedbbad68 100644
--- a/drivers/net/wireless/rt2x00/rt2x00.h
+++ b/drivers/net/wireless/rt2x00/rt2x00.h
@@ -44,7 +44,7 @@
44/* 44/*
45 * Module information. 45 * Module information.
46 */ 46 */
47#define DRV_VERSION "2.2.1" 47#define DRV_VERSION "2.2.2"
48#define DRV_PROJECT "http://rt2x00.serialmonkey.com" 48#define DRV_PROJECT "http://rt2x00.serialmonkey.com"
49 49
50/* 50/*
@@ -348,13 +348,6 @@ struct rt2x00_intf {
348 spinlock_t lock; 348 spinlock_t lock;
349 349
350 /* 350 /*
351 * BSS configuration. Copied from the structure
352 * passed to us through the bss_info_changed()
353 * callback funtion.
354 */
355 struct ieee80211_bss_conf conf;
356
357 /*
358 * MAC of the device. 351 * MAC of the device.
359 */ 352 */
360 u8 mac[ETH_ALEN]; 353 u8 mac[ETH_ALEN];
@@ -433,18 +426,6 @@ struct rt2x00lib_conf {
433 426
434 struct rf_channel rf; 427 struct rf_channel rf;
435 struct channel_info channel; 428 struct channel_info channel;
436
437 struct antenna_setup ant;
438
439 enum ieee80211_band band;
440
441 u32 basic_rates;
442 u32 slot_time;
443
444 short sifs;
445 short pifs;
446 short difs;
447 short eifs;
448}; 429};
449 430
450/* 431/*
@@ -456,6 +437,15 @@ struct rt2x00lib_erp {
456 437
457 int ack_timeout; 438 int ack_timeout;
458 int ack_consume_time; 439 int ack_consume_time;
440
441 u64 basic_rates;
442
443 int slot_time;
444
445 short sifs;
446 short pifs;
447 short difs;
448 short eifs;
459}; 449};
460 450
461/* 451/*
@@ -589,19 +579,11 @@ struct rt2x00lib_ops {
589 579
590 void (*config_erp) (struct rt2x00_dev *rt2x00dev, 580 void (*config_erp) (struct rt2x00_dev *rt2x00dev,
591 struct rt2x00lib_erp *erp); 581 struct rt2x00lib_erp *erp);
582 void (*config_ant) (struct rt2x00_dev *rt2x00dev,
583 struct antenna_setup *ant);
592 void (*config) (struct rt2x00_dev *rt2x00dev, 584 void (*config) (struct rt2x00_dev *rt2x00dev,
593 struct rt2x00lib_conf *libconf, 585 struct rt2x00lib_conf *libconf,
594 const unsigned int flags); 586 const unsigned int changed_flags);
595#define CONFIG_UPDATE_PHYMODE ( 1 << 1 )
596#define CONFIG_UPDATE_CHANNEL ( 1 << 2 )
597#define CONFIG_UPDATE_TXPOWER ( 1 << 3 )
598#define CONFIG_UPDATE_ANTENNA ( 1 << 4 )
599#define CONFIG_UPDATE_SLOT_TIME ( 1 << 5 )
600#define CONFIG_UPDATE_BEACON_INT ( 1 << 6 )
601#define CONFIG_UPDATE_ALL 0xffff
602
603 int (*set_retry_limit) (struct ieee80211_hw *hw,
604 u32 short_limit, u32 long_limit);
605}; 587};
606 588
607/* 589/*
diff --git a/drivers/net/wireless/rt2x00/rt2x00config.c b/drivers/net/wireless/rt2x00/rt2x00config.c
index 7910147157b5..3e4eee3ab7d2 100644
--- a/drivers/net/wireless/rt2x00/rt2x00config.c
+++ b/drivers/net/wireless/rt2x00/rt2x00config.c
@@ -86,13 +86,14 @@ void rt2x00lib_config_erp(struct rt2x00_dev *rt2x00dev,
86 erp.short_preamble = bss_conf->use_short_preamble; 86 erp.short_preamble = bss_conf->use_short_preamble;
87 erp.cts_protection = bss_conf->use_cts_prot; 87 erp.cts_protection = bss_conf->use_cts_prot;
88 88
89 erp.ack_timeout = PLCP + get_duration(ACK_SIZE, 10); 89 erp.slot_time = bss_conf->use_short_slot ? SHORT_SLOT_TIME : SLOT_TIME;
90 erp.ack_consume_time = SIFS + PLCP + get_duration(ACK_SIZE, 10); 90 erp.sifs = SIFS;
91 erp.pifs = bss_conf->use_short_slot ? SHORT_PIFS : PIFS;
92 erp.difs = bss_conf->use_short_slot ? SHORT_DIFS : DIFS;
93 erp.eifs = bss_conf->use_short_slot ? SHORT_EIFS : EIFS;
91 94
92 if (rt2x00dev->hw->conf.flags & IEEE80211_CONF_SHORT_SLOT_TIME) 95 erp.ack_timeout = PLCP + erp.difs + get_duration(ACK_SIZE, 10);
93 erp.ack_timeout += SHORT_DIFS; 96 erp.ack_consume_time = SIFS + PLCP + get_duration(ACK_SIZE, 10);
94 else
95 erp.ack_timeout += DIFS;
96 97
97 if (bss_conf->use_short_preamble) { 98 if (bss_conf->use_short_preamble) {
98 erp.ack_timeout += SHORT_PREAMBLE; 99 erp.ack_timeout += SHORT_PREAMBLE;
@@ -102,16 +103,18 @@ void rt2x00lib_config_erp(struct rt2x00_dev *rt2x00dev,
102 erp.ack_consume_time += PREAMBLE; 103 erp.ack_consume_time += PREAMBLE;
103 } 104 }
104 105
106 erp.basic_rates = bss_conf->basic_rates;
107
105 rt2x00dev->ops->lib->config_erp(rt2x00dev, &erp); 108 rt2x00dev->ops->lib->config_erp(rt2x00dev, &erp);
106} 109}
107 110
108void rt2x00lib_config_antenna(struct rt2x00_dev *rt2x00dev, 111void rt2x00lib_config_antenna(struct rt2x00_dev *rt2x00dev,
109 enum antenna rx, enum antenna tx) 112 enum antenna rx, enum antenna tx)
110{ 113{
111 struct rt2x00lib_conf libconf; 114 struct antenna_setup ant;
112 115
113 libconf.ant.rx = rx; 116 ant.rx = rx;
114 libconf.ant.tx = tx; 117 ant.tx = tx;
115 118
116 if (rx == rt2x00dev->link.ant.active.rx && 119 if (rx == rt2x00dev->link.ant.active.rx &&
117 tx == rt2x00dev->link.ant.active.tx) 120 tx == rt2x00dev->link.ant.active.tx)
@@ -129,111 +132,28 @@ void rt2x00lib_config_antenna(struct rt2x00_dev *rt2x00dev,
129 * The latter is required since we need to recalibrate the 132 * The latter is required since we need to recalibrate the
130 * noise-sensitivity ratio for the new setup. 133 * noise-sensitivity ratio for the new setup.
131 */ 134 */
132 rt2x00dev->ops->lib->config(rt2x00dev, &libconf, CONFIG_UPDATE_ANTENNA); 135 rt2x00dev->ops->lib->config_ant(rt2x00dev, &ant);
136
133 rt2x00lib_reset_link_tuner(rt2x00dev); 137 rt2x00lib_reset_link_tuner(rt2x00dev);
134 rt2x00_reset_link_ant_rssi(&rt2x00dev->link); 138 rt2x00_reset_link_ant_rssi(&rt2x00dev->link);
135 139
136 rt2x00dev->link.ant.active.rx = libconf.ant.rx; 140 memcpy(&rt2x00dev->link.ant.active, &ant, sizeof(ant));
137 rt2x00dev->link.ant.active.tx = libconf.ant.tx;
138 141
139 if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags)) 142 if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
140 rt2x00lib_toggle_rx(rt2x00dev, STATE_RADIO_RX_ON_LINK); 143 rt2x00lib_toggle_rx(rt2x00dev, STATE_RADIO_RX_ON_LINK);
141} 144}
142 145
143static u32 rt2x00lib_get_basic_rates(struct ieee80211_supported_band *band)
144{
145 const struct rt2x00_rate *rate;
146 unsigned int i;
147 u32 mask = 0;
148
149 for (i = 0; i < band->n_bitrates; i++) {
150 rate = rt2x00_get_rate(band->bitrates[i].hw_value);
151 if (rate->flags & DEV_RATE_BASIC)
152 mask |= rate->ratemask;
153 }
154
155 return mask;
156}
157
158void rt2x00lib_config(struct rt2x00_dev *rt2x00dev, 146void rt2x00lib_config(struct rt2x00_dev *rt2x00dev,
159 struct ieee80211_conf *conf, const int force_config) 147 struct ieee80211_conf *conf,
148 unsigned int ieee80211_flags)
160{ 149{
161 struct rt2x00lib_conf libconf; 150 struct rt2x00lib_conf libconf;
162 struct ieee80211_supported_band *band;
163 struct antenna_setup *default_ant = &rt2x00dev->default_ant;
164 struct antenna_setup *active_ant = &rt2x00dev->link.ant.active;
165 int flags = 0;
166 int short_slot_time;
167
168 /*
169 * In some situations we want to force all configurations
170 * to be reloaded (When resuming for instance).
171 */
172 if (force_config) {
173 flags = CONFIG_UPDATE_ALL;
174 goto config;
175 }
176
177 /*
178 * Check which configuration options have been
179 * updated and should be send to the device.
180 */
181 if (rt2x00dev->rx_status.band != conf->channel->band)
182 flags |= CONFIG_UPDATE_PHYMODE;
183 if (rt2x00dev->rx_status.freq != conf->channel->center_freq)
184 flags |= CONFIG_UPDATE_CHANNEL;
185 if (rt2x00dev->tx_power != conf->power_level)
186 flags |= CONFIG_UPDATE_TXPOWER;
187
188 /*
189 * Determining changes in the antenna setups request several checks:
190 * antenna_sel_{r,t}x = 0
191 * -> Does active_{r,t}x match default_{r,t}x
192 * -> Is default_{r,t}x SW_DIVERSITY
193 * antenna_sel_{r,t}x = 1/2
194 * -> Does active_{r,t}x match antenna_sel_{r,t}x
195 * The reason for not updating the antenna while SW diversity
196 * should be used is simple: Software diversity means that
197 * we should switch between the antenna's based on the
198 * quality. This means that the current antenna is good enough
199 * to work with untill the link tuner decides that an antenna
200 * switch should be performed.
201 */
202 if (default_ant->rx != ANTENNA_SW_DIVERSITY &&
203 default_ant->rx != active_ant->rx)
204 flags |= CONFIG_UPDATE_ANTENNA;
205 else if (active_ant->rx == ANTENNA_SW_DIVERSITY)
206 flags |= CONFIG_UPDATE_ANTENNA;
207
208 if (default_ant->tx != ANTENNA_SW_DIVERSITY &&
209 default_ant->tx != active_ant->tx)
210 flags |= CONFIG_UPDATE_ANTENNA;
211 else if (active_ant->tx == ANTENNA_SW_DIVERSITY)
212 flags |= CONFIG_UPDATE_ANTENNA;
213 151
214 /*
215 * The following configuration options are never
216 * stored anywhere and will always be updated.
217 */
218 flags |= CONFIG_UPDATE_SLOT_TIME;
219 flags |= CONFIG_UPDATE_BEACON_INT;
220
221 /*
222 * We have determined what options should be updated,
223 * now precalculate device configuration values depending
224 * on what configuration options need to be updated.
225 */
226config:
227 memset(&libconf, 0, sizeof(libconf)); 152 memset(&libconf, 0, sizeof(libconf));
228 153
229 if (flags & CONFIG_UPDATE_PHYMODE) { 154 libconf.conf = conf;
230 band = &rt2x00dev->bands[conf->channel->band];
231
232 libconf.band = conf->channel->band;
233 libconf.basic_rates = rt2x00lib_get_basic_rates(band);
234 }
235 155
236 if (flags & CONFIG_UPDATE_CHANNEL) { 156 if (ieee80211_flags & IEEE80211_CONF_CHANGE_CHANNEL) {
237 memcpy(&libconf.rf, 157 memcpy(&libconf.rf,
238 &rt2x00dev->spec.channels[conf->channel->hw_value], 158 &rt2x00dev->spec.channels[conf->channel->hw_value],
239 sizeof(libconf.rf)); 159 sizeof(libconf.rf));
@@ -243,57 +163,21 @@ config:
243 sizeof(libconf.channel)); 163 sizeof(libconf.channel));
244 } 164 }
245 165
246 if (flags & CONFIG_UPDATE_ANTENNA) {
247 if (default_ant->rx != ANTENNA_SW_DIVERSITY)
248 libconf.ant.rx = default_ant->rx;
249 else if (active_ant->rx == ANTENNA_SW_DIVERSITY)
250 libconf.ant.rx = ANTENNA_B;
251 else
252 libconf.ant.rx = active_ant->rx;
253
254 if (default_ant->tx != ANTENNA_SW_DIVERSITY)
255 libconf.ant.tx = default_ant->tx;
256 else if (active_ant->tx == ANTENNA_SW_DIVERSITY)
257 libconf.ant.tx = ANTENNA_B;
258 else
259 libconf.ant.tx = active_ant->tx;
260 }
261
262 if (flags & CONFIG_UPDATE_SLOT_TIME) {
263 short_slot_time = conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME;
264
265 libconf.slot_time =
266 short_slot_time ? SHORT_SLOT_TIME : SLOT_TIME;
267 libconf.sifs = SIFS;
268 libconf.pifs = short_slot_time ? SHORT_PIFS : PIFS;
269 libconf.difs = short_slot_time ? SHORT_DIFS : DIFS;
270 libconf.eifs = short_slot_time ? SHORT_EIFS : EIFS;
271 }
272
273 libconf.conf = conf;
274
275 /* 166 /*
276 * Start configuration. 167 * Start configuration.
277 */ 168 */
278 rt2x00dev->ops->lib->config(rt2x00dev, &libconf, flags); 169 rt2x00dev->ops->lib->config(rt2x00dev, &libconf, ieee80211_flags);
279 170
280 /* 171 /*
281 * Some configuration changes affect the link quality 172 * Some configuration changes affect the link quality
282 * which means we need to reset the link tuner. 173 * which means we need to reset the link tuner.
283 */ 174 */
284 if (flags & (CONFIG_UPDATE_CHANNEL | CONFIG_UPDATE_ANTENNA)) 175 if (ieee80211_flags & IEEE80211_CONF_CHANGE_CHANNEL)
285 rt2x00lib_reset_link_tuner(rt2x00dev); 176 rt2x00lib_reset_link_tuner(rt2x00dev);
286 177
287 if (flags & CONFIG_UPDATE_PHYMODE) { 178 rt2x00dev->curr_band = conf->channel->band;
288 rt2x00dev->curr_band = conf->channel->band;
289 rt2x00dev->rx_status.band = conf->channel->band;
290 }
291
292 rt2x00dev->rx_status.freq = conf->channel->center_freq;
293 rt2x00dev->tx_power = conf->power_level; 179 rt2x00dev->tx_power = conf->power_level;
294 180
295 if (flags & CONFIG_UPDATE_ANTENNA) { 181 rt2x00dev->rx_status.band = conf->channel->band;
296 rt2x00dev->link.ant.active.rx = libconf.ant.rx; 182 rt2x00dev->rx_status.freq = conf->channel->center_freq;
297 rt2x00dev->link.ant.active.tx = libconf.ant.tx;
298 }
299} 183}
diff --git a/drivers/net/wireless/rt2x00/rt2x00debug.c b/drivers/net/wireless/rt2x00/rt2x00debug.c
index a31418a700c1..54dd10060bf1 100644
--- a/drivers/net/wireless/rt2x00/rt2x00debug.c
+++ b/drivers/net/wireless/rt2x00/rt2x00debug.c
@@ -424,16 +424,21 @@ static ssize_t rt2x00debug_read_##__name(struct file *file, \
424 const struct rt2x00debug *debug = intf->debug; \ 424 const struct rt2x00debug *debug = intf->debug; \
425 char line[16]; \ 425 char line[16]; \
426 size_t size; \ 426 size_t size; \
427 unsigned int index = intf->offset_##__name; \
427 __type value; \ 428 __type value; \
428 \ 429 \
429 if (*offset) \ 430 if (*offset) \
430 return 0; \ 431 return 0; \
431 \ 432 \
432 if (intf->offset_##__name >= debug->__name.word_count) \ 433 if (index >= debug->__name.word_count) \
433 return -EINVAL; \ 434 return -EINVAL; \
434 \ 435 \
435 debug->__name.read(intf->rt2x00dev, \ 436 if (debug->__name.flags & RT2X00DEBUGFS_OFFSET) \
436 intf->offset_##__name, &value); \ 437 index *= debug->__name.word_size; \
438 \
439 index += debug->__name.word_base; \
440 \
441 debug->__name.read(intf->rt2x00dev, index, &value); \
437 \ 442 \
438 size = sprintf(line, __format, value); \ 443 size = sprintf(line, __format, value); \
439 \ 444 \
@@ -454,12 +459,13 @@ static ssize_t rt2x00debug_write_##__name(struct file *file, \
454 const struct rt2x00debug *debug = intf->debug; \ 459 const struct rt2x00debug *debug = intf->debug; \
455 char line[16]; \ 460 char line[16]; \
456 size_t size; \ 461 size_t size; \
462 unsigned int index = intf->offset_##__name; \
457 __type value; \ 463 __type value; \
458 \ 464 \
459 if (*offset) \ 465 if (*offset) \
460 return 0; \ 466 return 0; \
461 \ 467 \
462 if (intf->offset_##__name >= debug->__name.word_count) \ 468 if (index >= debug->__name.word_count) \
463 return -EINVAL; \ 469 return -EINVAL; \
464 \ 470 \
465 if (copy_from_user(line, buf, length)) \ 471 if (copy_from_user(line, buf, length)) \
@@ -468,8 +474,12 @@ static ssize_t rt2x00debug_write_##__name(struct file *file, \
468 size = strlen(line); \ 474 size = strlen(line); \
469 value = simple_strtoul(line, NULL, 0); \ 475 value = simple_strtoul(line, NULL, 0); \
470 \ 476 \
471 debug->__name.write(intf->rt2x00dev, \ 477 if (debug->__name.flags & RT2X00DEBUGFS_OFFSET) \
472 intf->offset_##__name, value); \ 478 index *= debug->__name.word_size; \
479 \
480 index += debug->__name.word_base; \
481 \
482 debug->__name.write(intf->rt2x00dev, index, value); \
473 \ 483 \
474 *offset += size; \ 484 *offset += size; \
475 return size; \ 485 return size; \
diff --git a/drivers/net/wireless/rt2x00/rt2x00debug.h b/drivers/net/wireless/rt2x00/rt2x00debug.h
index c4ce895aa1c7..a92104dfee9a 100644
--- a/drivers/net/wireless/rt2x00/rt2x00debug.h
+++ b/drivers/net/wireless/rt2x00/rt2x00debug.h
@@ -28,6 +28,16 @@
28 28
29struct rt2x00_dev; 29struct rt2x00_dev;
30 30
31/**
32 * enum rt2x00debugfs_entry_flags: Flags for debugfs registry entry
33 *
34 * @RT2X00DEBUGFS_OFFSET: rt2x00lib should pass the register offset
35 * as argument when using the callback function read()/write()
36 */
37enum rt2x00debugfs_entry_flags {
38 RT2X00DEBUGFS_OFFSET = (1 << 0),
39};
40
31#define RT2X00DEBUGFS_REGISTER_ENTRY(__name, __type) \ 41#define RT2X00DEBUGFS_REGISTER_ENTRY(__name, __type) \
32struct reg##__name { \ 42struct reg##__name { \
33 void (*read)(struct rt2x00_dev *rt2x00dev, \ 43 void (*read)(struct rt2x00_dev *rt2x00dev, \
@@ -35,6 +45,9 @@ struct reg##__name { \
35 void (*write)(struct rt2x00_dev *rt2x00dev, \ 45 void (*write)(struct rt2x00_dev *rt2x00dev, \
36 const unsigned int word, __type data); \ 46 const unsigned int word, __type data); \
37 \ 47 \
48 unsigned int flags; \
49 \
50 unsigned int word_base; \
38 unsigned int word_size; \ 51 unsigned int word_size; \
39 unsigned int word_count; \ 52 unsigned int word_count; \
40} __name 53} __name
diff --git a/drivers/net/wireless/rt2x00/rt2x00dev.c b/drivers/net/wireless/rt2x00/rt2x00dev.c
index e1feab8b6b02..477a944167c4 100644
--- a/drivers/net/wireless/rt2x00/rt2x00dev.c
+++ b/drivers/net/wireless/rt2x00/rt2x00dev.c
@@ -417,7 +417,7 @@ static void rt2x00lib_intf_scheduled_iter(void *data, u8 *mac,
417 */ 417 */
418 spin_lock(&intf->lock); 418 spin_lock(&intf->lock);
419 419
420 memcpy(&conf, &intf->conf, sizeof(conf)); 420 memcpy(&conf, &vif->bss_conf, sizeof(conf));
421 delayed_flags = intf->delayed_flags; 421 delayed_flags = intf->delayed_flags;
422 intf->delayed_flags = 0; 422 intf->delayed_flags = 0;
423 423
@@ -1056,10 +1056,16 @@ int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev)
1056 */ 1056 */
1057 rt2x00dev->hw->vif_data_size = sizeof(struct rt2x00_intf); 1057 rt2x00dev->hw->vif_data_size = sizeof(struct rt2x00_intf);
1058 1058
1059 rt2x00dev->hw->wiphy->interface_modes = 1059 /*
1060 BIT(NL80211_IFTYPE_AP) | 1060 * Determine which operating modes are supported, all modes
1061 BIT(NL80211_IFTYPE_STATION) | 1061 * which require beaconing, depend on the availability of
1062 BIT(NL80211_IFTYPE_ADHOC); 1062 * beacon entries.
1063 */
1064 rt2x00dev->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
1065 if (rt2x00dev->ops->bcn->entry_num > 0)
1066 rt2x00dev->hw->wiphy->interface_modes |=
1067 BIT(NL80211_IFTYPE_ADHOC) |
1068 BIT(NL80211_IFTYPE_AP);
1063 1069
1064 /* 1070 /*
1065 * Let the driver probe the device to detect the capabilities. 1071 * Let the driver probe the device to detect the capabilities.
diff --git a/drivers/net/wireless/rt2x00/rt2x00lib.h b/drivers/net/wireless/rt2x00/rt2x00lib.h
index 797eb619aa0a..9f214f89ba6d 100644
--- a/drivers/net/wireless/rt2x00/rt2x00lib.h
+++ b/drivers/net/wireless/rt2x00/rt2x00lib.h
@@ -96,7 +96,8 @@ void rt2x00lib_config_erp(struct rt2x00_dev *rt2x00dev,
96void rt2x00lib_config_antenna(struct rt2x00_dev *rt2x00dev, 96void rt2x00lib_config_antenna(struct rt2x00_dev *rt2x00dev,
97 enum antenna rx, enum antenna tx); 97 enum antenna rx, enum antenna tx);
98void rt2x00lib_config(struct rt2x00_dev *rt2x00dev, 98void rt2x00lib_config(struct rt2x00_dev *rt2x00dev,
99 struct ieee80211_conf *conf, const int force_config); 99 struct ieee80211_conf *conf,
100 const unsigned int changed_flags);
100 101
101/** 102/**
102 * DOC: Queue handlers 103 * DOC: Queue handlers
diff --git a/drivers/net/wireless/rt2x00/rt2x00mac.c b/drivers/net/wireless/rt2x00/rt2x00mac.c
index b32d59eafaa3..8fc2315c5963 100644
--- a/drivers/net/wireless/rt2x00/rt2x00mac.c
+++ b/drivers/net/wireless/rt2x00/rt2x00mac.c
@@ -349,15 +349,6 @@ int rt2x00mac_config(struct ieee80211_hw *hw, u32 changed)
349 if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags)) 349 if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags))
350 return 0; 350 return 0;
351 351
352 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
353 rt2x00dev->ops->lib->set_retry_limit(hw,
354 conf->short_frame_max_tx_count,
355 conf->long_frame_max_tx_count);
356 }
357 changed &= ~IEEE80211_CONF_CHANGE_RETRY_LIMITS;
358 if (!changed)
359 return 0;
360
361 /* 352 /*
362 * Only change device state when the radio is enabled. It does not 353 * Only change device state when the radio is enabled. It does not
363 * matter what parameters we have configured when the radio is disabled 354 * matter what parameters we have configured when the radio is disabled
@@ -379,7 +370,7 @@ int rt2x00mac_config(struct ieee80211_hw *hw, u32 changed)
379 * When we've just turned on the radio, we want to reprogram 370 * When we've just turned on the radio, we want to reprogram
380 * everything to ensure a consistent state 371 * everything to ensure a consistent state
381 */ 372 */
382 rt2x00lib_config(rt2x00dev, conf, !radio_on); 373 rt2x00lib_config(rt2x00dev, conf, changed);
383 374
384 /* Turn RX back on */ 375 /* Turn RX back on */
385 rt2x00lib_toggle_rx(rt2x00dev, STATE_RADIO_RX_ON); 376 rt2x00lib_toggle_rx(rt2x00dev, STATE_RADIO_RX_ON);
@@ -643,7 +634,6 @@ void rt2x00mac_bss_info_changed(struct ieee80211_hw *hw,
643 } 634 }
644 635
645 spin_lock(&intf->lock); 636 spin_lock(&intf->lock);
646 memcpy(&intf->conf, bss_conf, sizeof(*bss_conf));
647 if (delayed) { 637 if (delayed) {
648 intf->delayed_flags |= delayed; 638 intf->delayed_flags |= delayed;
649 schedule_work(&rt2x00dev->intf_work); 639 schedule_work(&rt2x00dev->intf_work);
diff --git a/drivers/net/wireless/rt2x00/rt2x00pci.h b/drivers/net/wireless/rt2x00/rt2x00pci.h
index 80bf97c03e2d..a83f45f784f2 100644
--- a/drivers/net/wireless/rt2x00/rt2x00pci.h
+++ b/drivers/net/wireless/rt2x00/rt2x00pci.h
@@ -58,7 +58,7 @@
58 * Register access. 58 * Register access.
59 */ 59 */
60static inline void rt2x00pci_register_read(struct rt2x00_dev *rt2x00dev, 60static inline void rt2x00pci_register_read(struct rt2x00_dev *rt2x00dev,
61 const unsigned long offset, 61 const unsigned int offset,
62 u32 *value) 62 u32 *value)
63{ 63{
64 *value = readl(rt2x00dev->csr.base + offset); 64 *value = readl(rt2x00dev->csr.base + offset);
@@ -66,14 +66,14 @@ static inline void rt2x00pci_register_read(struct rt2x00_dev *rt2x00dev,
66 66
67static inline void 67static inline void
68rt2x00pci_register_multiread(struct rt2x00_dev *rt2x00dev, 68rt2x00pci_register_multiread(struct rt2x00_dev *rt2x00dev,
69 const unsigned long offset, 69 const unsigned int offset,
70 void *value, const u16 length) 70 void *value, const u16 length)
71{ 71{
72 memcpy_fromio(value, rt2x00dev->csr.base + offset, length); 72 memcpy_fromio(value, rt2x00dev->csr.base + offset, length);
73} 73}
74 74
75static inline void rt2x00pci_register_write(struct rt2x00_dev *rt2x00dev, 75static inline void rt2x00pci_register_write(struct rt2x00_dev *rt2x00dev,
76 const unsigned long offset, 76 const unsigned int offset,
77 u32 value) 77 u32 value)
78{ 78{
79 writel(value, rt2x00dev->csr.base + offset); 79 writel(value, rt2x00dev->csr.base + offset);
@@ -81,7 +81,7 @@ static inline void rt2x00pci_register_write(struct rt2x00_dev *rt2x00dev,
81 81
82static inline void 82static inline void
83rt2x00pci_register_multiwrite(struct rt2x00_dev *rt2x00dev, 83rt2x00pci_register_multiwrite(struct rt2x00_dev *rt2x00dev,
84 const unsigned long offset, 84 const unsigned int offset,
85 const void *value, const u16 length) 85 const void *value, const u16 length)
86{ 86{
87 memcpy_toio(rt2x00dev->csr.base + offset, value, length); 87 memcpy_toio(rt2x00dev->csr.base + offset, value, length);
diff --git a/drivers/net/wireless/rt2x00/rt61pci.c b/drivers/net/wireless/rt2x00/rt61pci.c
index 921dcd5064de..3f272793412a 100644
--- a/drivers/net/wireless/rt2x00/rt61pci.c
+++ b/drivers/net/wireless/rt2x00/rt61pci.c
@@ -228,43 +228,34 @@ static void rt61pci_eepromregister_write(struct eeprom_93cx6 *eeprom)
228} 228}
229 229
230#ifdef CONFIG_RT2X00_LIB_DEBUGFS 230#ifdef CONFIG_RT2X00_LIB_DEBUGFS
231#define CSR_OFFSET(__word) ( CSR_REG_BASE + ((__word) * sizeof(u32)) )
232
233static void rt61pci_read_csr(struct rt2x00_dev *rt2x00dev,
234 const unsigned int word, u32 *data)
235{
236 rt2x00pci_register_read(rt2x00dev, CSR_OFFSET(word), data);
237}
238
239static void rt61pci_write_csr(struct rt2x00_dev *rt2x00dev,
240 const unsigned int word, u32 data)
241{
242 rt2x00pci_register_write(rt2x00dev, CSR_OFFSET(word), data);
243}
244
245static const struct rt2x00debug rt61pci_rt2x00debug = { 231static const struct rt2x00debug rt61pci_rt2x00debug = {
246 .owner = THIS_MODULE, 232 .owner = THIS_MODULE,
247 .csr = { 233 .csr = {
248 .read = rt61pci_read_csr, 234 .read = rt2x00pci_register_read,
249 .write = rt61pci_write_csr, 235 .write = rt2x00pci_register_write,
236 .flags = RT2X00DEBUGFS_OFFSET,
237 .word_base = CSR_REG_BASE,
250 .word_size = sizeof(u32), 238 .word_size = sizeof(u32),
251 .word_count = CSR_REG_SIZE / sizeof(u32), 239 .word_count = CSR_REG_SIZE / sizeof(u32),
252 }, 240 },
253 .eeprom = { 241 .eeprom = {
254 .read = rt2x00_eeprom_read, 242 .read = rt2x00_eeprom_read,
255 .write = rt2x00_eeprom_write, 243 .write = rt2x00_eeprom_write,
244 .word_base = EEPROM_BASE,
256 .word_size = sizeof(u16), 245 .word_size = sizeof(u16),
257 .word_count = EEPROM_SIZE / sizeof(u16), 246 .word_count = EEPROM_SIZE / sizeof(u16),
258 }, 247 },
259 .bbp = { 248 .bbp = {
260 .read = rt61pci_bbp_read, 249 .read = rt61pci_bbp_read,
261 .write = rt61pci_bbp_write, 250 .write = rt61pci_bbp_write,
251 .word_base = BBP_BASE,
262 .word_size = sizeof(u8), 252 .word_size = sizeof(u8),
263 .word_count = BBP_SIZE / sizeof(u8), 253 .word_count = BBP_SIZE / sizeof(u8),
264 }, 254 },
265 .rf = { 255 .rf = {
266 .read = rt2x00_rf_read, 256 .read = rt2x00_rf_read,
267 .write = rt61pci_rf_write, 257 .write = rt61pci_rf_write,
258 .word_base = RF_BASE,
268 .word_size = sizeof(u32), 259 .word_size = sizeof(u32),
269 .word_count = RF_SIZE / sizeof(u32), 260 .word_count = RF_SIZE / sizeof(u32),
270 }, 261 },
@@ -643,95 +634,18 @@ static void rt61pci_config_erp(struct rt2x00_dev *rt2x00dev,
643 rt2x00_set_field32(&reg, TXRX_CSR4_AUTORESPOND_PREAMBLE, 634 rt2x00_set_field32(&reg, TXRX_CSR4_AUTORESPOND_PREAMBLE,
644 !!erp->short_preamble); 635 !!erp->short_preamble);
645 rt2x00pci_register_write(rt2x00dev, TXRX_CSR4, reg); 636 rt2x00pci_register_write(rt2x00dev, TXRX_CSR4, reg);
646}
647
648
649static void rt61pci_config_lna_gain(struct rt2x00_dev *rt2x00dev,
650 struct rt2x00lib_conf *libconf)
651{
652 u16 eeprom;
653 short lna_gain = 0;
654
655 if (libconf->band == IEEE80211_BAND_2GHZ) {
656 if (test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags))
657 lna_gain += 14;
658
659 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_BG, &eeprom);
660 lna_gain -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_BG_1);
661 } else {
662 if (test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags))
663 lna_gain += 14;
664
665 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_A, &eeprom);
666 lna_gain -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_A_1);
667 }
668 637
669 rt2x00dev->lna_gain = lna_gain; 638 rt2x00pci_register_write(rt2x00dev, TXRX_CSR5, erp->basic_rates);
670}
671
672static void rt61pci_config_phymode(struct rt2x00_dev *rt2x00dev,
673 const int basic_rate_mask)
674{
675 rt2x00pci_register_write(rt2x00dev, TXRX_CSR5, basic_rate_mask);
676}
677
678static void rt61pci_config_channel(struct rt2x00_dev *rt2x00dev,
679 struct rf_channel *rf, const int txpower)
680{
681 u8 r3;
682 u8 r94;
683 u8 smart;
684
685 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower));
686 rt2x00_set_field32(&rf->rf4, RF4_FREQ_OFFSET, rt2x00dev->freq_offset);
687
688 smart = !(rt2x00_rf(&rt2x00dev->chip, RF5225) ||
689 rt2x00_rf(&rt2x00dev->chip, RF2527));
690
691 rt61pci_bbp_read(rt2x00dev, 3, &r3);
692 rt2x00_set_field8(&r3, BBP_R3_SMART_MODE, smart);
693 rt61pci_bbp_write(rt2x00dev, 3, r3);
694 639
695 r94 = 6; 640 rt2x00pci_register_read(rt2x00dev, MAC_CSR9, &reg);
696 if (txpower > MAX_TXPOWER && txpower <= (MAX_TXPOWER + r94)) 641 rt2x00_set_field32(&reg, MAC_CSR9_SLOT_TIME, erp->slot_time);
697 r94 += txpower - MAX_TXPOWER; 642 rt2x00pci_register_write(rt2x00dev, MAC_CSR9, reg);
698 else if (txpower < MIN_TXPOWER && txpower >= (MIN_TXPOWER - r94))
699 r94 += txpower;
700 rt61pci_bbp_write(rt2x00dev, 94, r94);
701
702 rt61pci_rf_write(rt2x00dev, 1, rf->rf1);
703 rt61pci_rf_write(rt2x00dev, 2, rf->rf2);
704 rt61pci_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
705 rt61pci_rf_write(rt2x00dev, 4, rf->rf4);
706
707 udelay(200);
708
709 rt61pci_rf_write(rt2x00dev, 1, rf->rf1);
710 rt61pci_rf_write(rt2x00dev, 2, rf->rf2);
711 rt61pci_rf_write(rt2x00dev, 3, rf->rf3 | 0x00000004);
712 rt61pci_rf_write(rt2x00dev, 4, rf->rf4);
713
714 udelay(200);
715
716 rt61pci_rf_write(rt2x00dev, 1, rf->rf1);
717 rt61pci_rf_write(rt2x00dev, 2, rf->rf2);
718 rt61pci_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
719 rt61pci_rf_write(rt2x00dev, 4, rf->rf4);
720
721 msleep(1);
722}
723
724static void rt61pci_config_txpower(struct rt2x00_dev *rt2x00dev,
725 const int txpower)
726{
727 struct rf_channel rf;
728
729 rt2x00_rf_read(rt2x00dev, 1, &rf.rf1);
730 rt2x00_rf_read(rt2x00dev, 2, &rf.rf2);
731 rt2x00_rf_read(rt2x00dev, 3, &rf.rf3);
732 rt2x00_rf_read(rt2x00dev, 4, &rf.rf4);
733 643
734 rt61pci_config_channel(rt2x00dev, &rf, txpower); 644 rt2x00pci_register_read(rt2x00dev, MAC_CSR8, &reg);
645 rt2x00_set_field32(&reg, MAC_CSR8_SIFS, erp->sifs);
646 rt2x00_set_field32(&reg, MAC_CSR8_SIFS_AFTER_RX_OFDM, 3);
647 rt2x00_set_field32(&reg, MAC_CSR8_EIFS, erp->eifs);
648 rt2x00pci_register_write(rt2x00dev, MAC_CSR8, reg);
735} 649}
736 650
737static void rt61pci_config_antenna_5x(struct rt2x00_dev *rt2x00dev, 651static void rt61pci_config_antenna_5x(struct rt2x00_dev *rt2x00dev,
@@ -906,8 +820,8 @@ static const struct antenna_sel antenna_sel_bg[] = {
906 { 98, { 0x48, 0x48 } }, 820 { 98, { 0x48, 0x48 } },
907}; 821};
908 822
909static void rt61pci_config_antenna(struct rt2x00_dev *rt2x00dev, 823static void rt61pci_config_ant(struct rt2x00_dev *rt2x00dev,
910 struct antenna_setup *ant) 824 struct antenna_setup *ant)
911{ 825{
912 const struct antenna_sel *sel; 826 const struct antenna_sel *sel;
913 unsigned int lna; 827 unsigned int lna;
@@ -954,20 +868,105 @@ static void rt61pci_config_antenna(struct rt2x00_dev *rt2x00dev,
954 } 868 }
955} 869}
956 870
957static void rt61pci_config_duration(struct rt2x00_dev *rt2x00dev, 871static void rt61pci_config_lna_gain(struct rt2x00_dev *rt2x00dev,
872 struct rt2x00lib_conf *libconf)
873{
874 u16 eeprom;
875 short lna_gain = 0;
876
877 if (libconf->conf->channel->band == IEEE80211_BAND_2GHZ) {
878 if (test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags))
879 lna_gain += 14;
880
881 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_BG, &eeprom);
882 lna_gain -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_BG_1);
883 } else {
884 if (test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags))
885 lna_gain += 14;
886
887 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_A, &eeprom);
888 lna_gain -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_A_1);
889 }
890
891 rt2x00dev->lna_gain = lna_gain;
892}
893
894static void rt61pci_config_channel(struct rt2x00_dev *rt2x00dev,
895 struct rf_channel *rf, const int txpower)
896{
897 u8 r3;
898 u8 r94;
899 u8 smart;
900
901 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower));
902 rt2x00_set_field32(&rf->rf4, RF4_FREQ_OFFSET, rt2x00dev->freq_offset);
903
904 smart = !(rt2x00_rf(&rt2x00dev->chip, RF5225) ||
905 rt2x00_rf(&rt2x00dev->chip, RF2527));
906
907 rt61pci_bbp_read(rt2x00dev, 3, &r3);
908 rt2x00_set_field8(&r3, BBP_R3_SMART_MODE, smart);
909 rt61pci_bbp_write(rt2x00dev, 3, r3);
910
911 r94 = 6;
912 if (txpower > MAX_TXPOWER && txpower <= (MAX_TXPOWER + r94))
913 r94 += txpower - MAX_TXPOWER;
914 else if (txpower < MIN_TXPOWER && txpower >= (MIN_TXPOWER - r94))
915 r94 += txpower;
916 rt61pci_bbp_write(rt2x00dev, 94, r94);
917
918 rt61pci_rf_write(rt2x00dev, 1, rf->rf1);
919 rt61pci_rf_write(rt2x00dev, 2, rf->rf2);
920 rt61pci_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
921 rt61pci_rf_write(rt2x00dev, 4, rf->rf4);
922
923 udelay(200);
924
925 rt61pci_rf_write(rt2x00dev, 1, rf->rf1);
926 rt61pci_rf_write(rt2x00dev, 2, rf->rf2);
927 rt61pci_rf_write(rt2x00dev, 3, rf->rf3 | 0x00000004);
928 rt61pci_rf_write(rt2x00dev, 4, rf->rf4);
929
930 udelay(200);
931
932 rt61pci_rf_write(rt2x00dev, 1, rf->rf1);
933 rt61pci_rf_write(rt2x00dev, 2, rf->rf2);
934 rt61pci_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
935 rt61pci_rf_write(rt2x00dev, 4, rf->rf4);
936
937 msleep(1);
938}
939
940static void rt61pci_config_txpower(struct rt2x00_dev *rt2x00dev,
941 const int txpower)
942{
943 struct rf_channel rf;
944
945 rt2x00_rf_read(rt2x00dev, 1, &rf.rf1);
946 rt2x00_rf_read(rt2x00dev, 2, &rf.rf2);
947 rt2x00_rf_read(rt2x00dev, 3, &rf.rf3);
948 rt2x00_rf_read(rt2x00dev, 4, &rf.rf4);
949
950 rt61pci_config_channel(rt2x00dev, &rf, txpower);
951}
952
953static void rt61pci_config_retry_limit(struct rt2x00_dev *rt2x00dev,
958 struct rt2x00lib_conf *libconf) 954 struct rt2x00lib_conf *libconf)
959{ 955{
960 u32 reg; 956 u32 reg;
961 957
962 rt2x00pci_register_read(rt2x00dev, MAC_CSR9, &reg); 958 rt2x00pci_register_read(rt2x00dev, TXRX_CSR4, &reg);
963 rt2x00_set_field32(&reg, MAC_CSR9_SLOT_TIME, libconf->slot_time); 959 rt2x00_set_field32(&reg, TXRX_CSR4_LONG_RETRY_LIMIT,
964 rt2x00pci_register_write(rt2x00dev, MAC_CSR9, reg); 960 libconf->conf->long_frame_max_tx_count);
961 rt2x00_set_field32(&reg, TXRX_CSR4_SHORT_RETRY_LIMIT,
962 libconf->conf->short_frame_max_tx_count);
963 rt2x00pci_register_write(rt2x00dev, TXRX_CSR4, reg);
964}
965 965
966 rt2x00pci_register_read(rt2x00dev, MAC_CSR8, &reg); 966static void rt61pci_config_duration(struct rt2x00_dev *rt2x00dev,
967 rt2x00_set_field32(&reg, MAC_CSR8_SIFS, libconf->sifs); 967 struct rt2x00lib_conf *libconf)
968 rt2x00_set_field32(&reg, MAC_CSR8_SIFS_AFTER_RX_OFDM, 3); 968{
969 rt2x00_set_field32(&reg, MAC_CSR8_EIFS, libconf->eifs); 969 u32 reg;
970 rt2x00pci_register_write(rt2x00dev, MAC_CSR8, reg);
971 970
972 rt2x00pci_register_read(rt2x00dev, TXRX_CSR0, &reg); 971 rt2x00pci_register_read(rt2x00dev, TXRX_CSR0, &reg);
973 rt2x00_set_field32(&reg, TXRX_CSR0_TSF_OFFSET, IEEE80211_HEADER); 972 rt2x00_set_field32(&reg, TXRX_CSR0_TSF_OFFSET, IEEE80211_HEADER);
@@ -990,16 +989,15 @@ static void rt61pci_config(struct rt2x00_dev *rt2x00dev,
990 /* Always recalculate LNA gain before changing configuration */ 989 /* Always recalculate LNA gain before changing configuration */
991 rt61pci_config_lna_gain(rt2x00dev, libconf); 990 rt61pci_config_lna_gain(rt2x00dev, libconf);
992 991
993 if (flags & CONFIG_UPDATE_PHYMODE) 992 if (flags & IEEE80211_CONF_CHANGE_CHANNEL)
994 rt61pci_config_phymode(rt2x00dev, libconf->basic_rates);
995 if (flags & CONFIG_UPDATE_CHANNEL)
996 rt61pci_config_channel(rt2x00dev, &libconf->rf, 993 rt61pci_config_channel(rt2x00dev, &libconf->rf,
997 libconf->conf->power_level); 994 libconf->conf->power_level);
998 if ((flags & CONFIG_UPDATE_TXPOWER) && !(flags & CONFIG_UPDATE_CHANNEL)) 995 if ((flags & IEEE80211_CONF_CHANGE_POWER) &&
996 !(flags & IEEE80211_CONF_CHANGE_CHANNEL))
999 rt61pci_config_txpower(rt2x00dev, libconf->conf->power_level); 997 rt61pci_config_txpower(rt2x00dev, libconf->conf->power_level);
1000 if (flags & CONFIG_UPDATE_ANTENNA) 998 if (flags & IEEE80211_CONF_CHANGE_RETRY_LIMITS)
1001 rt61pci_config_antenna(rt2x00dev, &libconf->ant); 999 rt61pci_config_retry_limit(rt2x00dev, libconf);
1002 if (flags & (CONFIG_UPDATE_SLOT_TIME | CONFIG_UPDATE_BEACON_INT)) 1000 if (flags & IEEE80211_CONF_CHANGE_BEACON_INTERVAL)
1003 rt61pci_config_duration(rt2x00dev, libconf); 1001 rt61pci_config_duration(rt2x00dev, libconf);
1004} 1002}
1005 1003
@@ -2628,20 +2626,6 @@ static int rt61pci_probe_hw(struct rt2x00_dev *rt2x00dev)
2628/* 2626/*
2629 * IEEE80211 stack callback functions. 2627 * IEEE80211 stack callback functions.
2630 */ 2628 */
2631static int rt61pci_set_retry_limit(struct ieee80211_hw *hw,
2632 u32 short_retry, u32 long_retry)
2633{
2634 struct rt2x00_dev *rt2x00dev = hw->priv;
2635 u32 reg;
2636
2637 rt2x00pci_register_read(rt2x00dev, TXRX_CSR4, &reg);
2638 rt2x00_set_field32(&reg, TXRX_CSR4_LONG_RETRY_LIMIT, long_retry);
2639 rt2x00_set_field32(&reg, TXRX_CSR4_SHORT_RETRY_LIMIT, short_retry);
2640 rt2x00pci_register_write(rt2x00dev, TXRX_CSR4, reg);
2641
2642 return 0;
2643}
2644
2645static int rt61pci_conf_tx(struct ieee80211_hw *hw, u16 queue_idx, 2629static int rt61pci_conf_tx(struct ieee80211_hw *hw, u16 queue_idx,
2646 const struct ieee80211_tx_queue_params *params) 2630 const struct ieee80211_tx_queue_params *params)
2647{ 2631{
@@ -2755,8 +2739,8 @@ static const struct rt2x00lib_ops rt61pci_rt2x00_ops = {
2755 .config_filter = rt61pci_config_filter, 2739 .config_filter = rt61pci_config_filter,
2756 .config_intf = rt61pci_config_intf, 2740 .config_intf = rt61pci_config_intf,
2757 .config_erp = rt61pci_config_erp, 2741 .config_erp = rt61pci_config_erp,
2742 .config_ant = rt61pci_config_ant,
2758 .config = rt61pci_config, 2743 .config = rt61pci_config,
2759 .set_retry_limit = rt61pci_set_retry_limit,
2760}; 2744};
2761 2745
2762static const struct data_queue_desc rt61pci_queue_rx = { 2746static const struct data_queue_desc rt61pci_queue_rx = {
diff --git a/drivers/net/wireless/rt2x00/rt61pci.h b/drivers/net/wireless/rt2x00/rt61pci.h
index 8ec1451308cc..65fe3332364a 100644
--- a/drivers/net/wireless/rt2x00/rt61pci.h
+++ b/drivers/net/wireless/rt2x00/rt61pci.h
@@ -48,7 +48,9 @@
48#define CSR_REG_SIZE 0x04b0 48#define CSR_REG_SIZE 0x04b0
49#define EEPROM_BASE 0x0000 49#define EEPROM_BASE 0x0000
50#define EEPROM_SIZE 0x0100 50#define EEPROM_SIZE 0x0100
51#define BBP_BASE 0x0000
51#define BBP_SIZE 0x0080 52#define BBP_SIZE 0x0080
53#define RF_BASE 0x0000
52#define RF_SIZE 0x0014 54#define RF_SIZE 0x0014
53 55
54/* 56/*
diff --git a/drivers/net/wireless/rt2x00/rt73usb.c b/drivers/net/wireless/rt2x00/rt73usb.c
index 69a4931a2fd3..767e3c98184c 100644
--- a/drivers/net/wireless/rt2x00/rt73usb.c
+++ b/drivers/net/wireless/rt2x00/rt73usb.c
@@ -249,43 +249,34 @@ rf_write:
249} 249}
250 250
251#ifdef CONFIG_RT2X00_LIB_DEBUGFS 251#ifdef CONFIG_RT2X00_LIB_DEBUGFS
252#define CSR_OFFSET(__word) ( CSR_REG_BASE + ((__word) * sizeof(u32)) )
253
254static void rt73usb_read_csr(struct rt2x00_dev *rt2x00dev,
255 const unsigned int word, u32 *data)
256{
257 rt73usb_register_read(rt2x00dev, CSR_OFFSET(word), data);
258}
259
260static void rt73usb_write_csr(struct rt2x00_dev *rt2x00dev,
261 const unsigned int word, u32 data)
262{
263 rt73usb_register_write(rt2x00dev, CSR_OFFSET(word), data);
264}
265
266static const struct rt2x00debug rt73usb_rt2x00debug = { 252static const struct rt2x00debug rt73usb_rt2x00debug = {
267 .owner = THIS_MODULE, 253 .owner = THIS_MODULE,
268 .csr = { 254 .csr = {
269 .read = rt73usb_read_csr, 255 .read = rt73usb_register_read,
270 .write = rt73usb_write_csr, 256 .write = rt73usb_register_write,
257 .flags = RT2X00DEBUGFS_OFFSET,
258 .word_base = CSR_REG_BASE,
271 .word_size = sizeof(u32), 259 .word_size = sizeof(u32),
272 .word_count = CSR_REG_SIZE / sizeof(u32), 260 .word_count = CSR_REG_SIZE / sizeof(u32),
273 }, 261 },
274 .eeprom = { 262 .eeprom = {
275 .read = rt2x00_eeprom_read, 263 .read = rt2x00_eeprom_read,
276 .write = rt2x00_eeprom_write, 264 .write = rt2x00_eeprom_write,
265 .word_base = EEPROM_BASE,
277 .word_size = sizeof(u16), 266 .word_size = sizeof(u16),
278 .word_count = EEPROM_SIZE / sizeof(u16), 267 .word_count = EEPROM_SIZE / sizeof(u16),
279 }, 268 },
280 .bbp = { 269 .bbp = {
281 .read = rt73usb_bbp_read, 270 .read = rt73usb_bbp_read,
282 .write = rt73usb_bbp_write, 271 .write = rt73usb_bbp_write,
272 .word_base = BBP_BASE,
283 .word_size = sizeof(u8), 273 .word_size = sizeof(u8),
284 .word_count = BBP_SIZE / sizeof(u8), 274 .word_count = BBP_SIZE / sizeof(u8),
285 }, 275 },
286 .rf = { 276 .rf = {
287 .read = rt2x00_rf_read, 277 .read = rt2x00_rf_read,
288 .write = rt73usb_rf_write, 278 .write = rt73usb_rf_write,
279 .word_base = RF_BASE,
289 .word_size = sizeof(u32), 280 .word_size = sizeof(u32),
290 .word_count = RF_SIZE / sizeof(u32), 281 .word_count = RF_SIZE / sizeof(u32),
291 }, 282 },
@@ -669,87 +660,18 @@ static void rt73usb_config_erp(struct rt2x00_dev *rt2x00dev,
669 rt2x00_set_field32(&reg, TXRX_CSR4_AUTORESPOND_PREAMBLE, 660 rt2x00_set_field32(&reg, TXRX_CSR4_AUTORESPOND_PREAMBLE,
670 !!erp->short_preamble); 661 !!erp->short_preamble);
671 rt73usb_register_write(rt2x00dev, TXRX_CSR4, reg); 662 rt73usb_register_write(rt2x00dev, TXRX_CSR4, reg);
672}
673
674static void rt73usb_config_lna_gain(struct rt2x00_dev *rt2x00dev,
675 struct rt2x00lib_conf *libconf)
676{
677 u16 eeprom;
678 short lna_gain = 0;
679
680 if (libconf->band == IEEE80211_BAND_2GHZ) {
681 if (test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags))
682 lna_gain += 14;
683
684 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_BG, &eeprom);
685 lna_gain -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_BG_1);
686 } else {
687 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_A, &eeprom);
688 lna_gain -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_A_1);
689 }
690
691 rt2x00dev->lna_gain = lna_gain;
692}
693
694static void rt73usb_config_phymode(struct rt2x00_dev *rt2x00dev,
695 const int basic_rate_mask)
696{
697 rt73usb_register_write(rt2x00dev, TXRX_CSR5, basic_rate_mask);
698}
699 663
700static void rt73usb_config_channel(struct rt2x00_dev *rt2x00dev, 664 rt73usb_register_write(rt2x00dev, TXRX_CSR5, erp->basic_rates);
701 struct rf_channel *rf, const int txpower)
702{
703 u8 r3;
704 u8 r94;
705 u8 smart;
706
707 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower));
708 rt2x00_set_field32(&rf->rf4, RF4_FREQ_OFFSET, rt2x00dev->freq_offset);
709
710 smart = !(rt2x00_rf(&rt2x00dev->chip, RF5225) ||
711 rt2x00_rf(&rt2x00dev->chip, RF2527));
712
713 rt73usb_bbp_read(rt2x00dev, 3, &r3);
714 rt2x00_set_field8(&r3, BBP_R3_SMART_MODE, smart);
715 rt73usb_bbp_write(rt2x00dev, 3, r3);
716 665
717 r94 = 6; 666 rt73usb_register_read(rt2x00dev, MAC_CSR9, &reg);
718 if (txpower > MAX_TXPOWER && txpower <= (MAX_TXPOWER + r94)) 667 rt2x00_set_field32(&reg, MAC_CSR9_SLOT_TIME, erp->slot_time);
719 r94 += txpower - MAX_TXPOWER; 668 rt73usb_register_write(rt2x00dev, MAC_CSR9, reg);
720 else if (txpower < MIN_TXPOWER && txpower >= (MIN_TXPOWER - r94))
721 r94 += txpower;
722 rt73usb_bbp_write(rt2x00dev, 94, r94);
723
724 rt73usb_rf_write(rt2x00dev, 1, rf->rf1);
725 rt73usb_rf_write(rt2x00dev, 2, rf->rf2);
726 rt73usb_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
727 rt73usb_rf_write(rt2x00dev, 4, rf->rf4);
728
729 rt73usb_rf_write(rt2x00dev, 1, rf->rf1);
730 rt73usb_rf_write(rt2x00dev, 2, rf->rf2);
731 rt73usb_rf_write(rt2x00dev, 3, rf->rf3 | 0x00000004);
732 rt73usb_rf_write(rt2x00dev, 4, rf->rf4);
733
734 rt73usb_rf_write(rt2x00dev, 1, rf->rf1);
735 rt73usb_rf_write(rt2x00dev, 2, rf->rf2);
736 rt73usb_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
737 rt73usb_rf_write(rt2x00dev, 4, rf->rf4);
738
739 udelay(10);
740}
741
742static void rt73usb_config_txpower(struct rt2x00_dev *rt2x00dev,
743 const int txpower)
744{
745 struct rf_channel rf;
746
747 rt2x00_rf_read(rt2x00dev, 1, &rf.rf1);
748 rt2x00_rf_read(rt2x00dev, 2, &rf.rf2);
749 rt2x00_rf_read(rt2x00dev, 3, &rf.rf3);
750 rt2x00_rf_read(rt2x00dev, 4, &rf.rf4);
751 669
752 rt73usb_config_channel(rt2x00dev, &rf, txpower); 670 rt73usb_register_read(rt2x00dev, MAC_CSR8, &reg);
671 rt2x00_set_field32(&reg, MAC_CSR8_SIFS, erp->sifs);
672 rt2x00_set_field32(&reg, MAC_CSR8_SIFS_AFTER_RX_OFDM, 3);
673 rt2x00_set_field32(&reg, MAC_CSR8_EIFS, erp->eifs);
674 rt73usb_register_write(rt2x00dev, MAC_CSR8, reg);
753} 675}
754 676
755static void rt73usb_config_antenna_5x(struct rt2x00_dev *rt2x00dev, 677static void rt73usb_config_antenna_5x(struct rt2x00_dev *rt2x00dev,
@@ -869,8 +791,8 @@ static const struct antenna_sel antenna_sel_bg[] = {
869 { 98, { 0x48, 0x48 } }, 791 { 98, { 0x48, 0x48 } },
870}; 792};
871 793
872static void rt73usb_config_antenna(struct rt2x00_dev *rt2x00dev, 794static void rt73usb_config_ant(struct rt2x00_dev *rt2x00dev,
873 struct antenna_setup *ant) 795 struct antenna_setup *ant)
874{ 796{
875 const struct antenna_sel *sel; 797 const struct antenna_sel *sel;
876 unsigned int lna; 798 unsigned int lna;
@@ -912,20 +834,98 @@ static void rt73usb_config_antenna(struct rt2x00_dev *rt2x00dev,
912 rt73usb_config_antenna_2x(rt2x00dev, ant); 834 rt73usb_config_antenna_2x(rt2x00dev, ant);
913} 835}
914 836
915static void rt73usb_config_duration(struct rt2x00_dev *rt2x00dev, 837static void rt73usb_config_lna_gain(struct rt2x00_dev *rt2x00dev,
916 struct rt2x00lib_conf *libconf) 838 struct rt2x00lib_conf *libconf)
917{ 839{
840 u16 eeprom;
841 short lna_gain = 0;
842
843 if (libconf->conf->channel->band == IEEE80211_BAND_2GHZ) {
844 if (test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags))
845 lna_gain += 14;
846
847 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_BG, &eeprom);
848 lna_gain -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_BG_1);
849 } else {
850 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_A, &eeprom);
851 lna_gain -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_A_1);
852 }
853
854 rt2x00dev->lna_gain = lna_gain;
855}
856
857static void rt73usb_config_channel(struct rt2x00_dev *rt2x00dev,
858 struct rf_channel *rf, const int txpower)
859{
860 u8 r3;
861 u8 r94;
862 u8 smart;
863
864 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower));
865 rt2x00_set_field32(&rf->rf4, RF4_FREQ_OFFSET, rt2x00dev->freq_offset);
866
867 smart = !(rt2x00_rf(&rt2x00dev->chip, RF5225) ||
868 rt2x00_rf(&rt2x00dev->chip, RF2527));
869
870 rt73usb_bbp_read(rt2x00dev, 3, &r3);
871 rt2x00_set_field8(&r3, BBP_R3_SMART_MODE, smart);
872 rt73usb_bbp_write(rt2x00dev, 3, r3);
873
874 r94 = 6;
875 if (txpower > MAX_TXPOWER && txpower <= (MAX_TXPOWER + r94))
876 r94 += txpower - MAX_TXPOWER;
877 else if (txpower < MIN_TXPOWER && txpower >= (MIN_TXPOWER - r94))
878 r94 += txpower;
879 rt73usb_bbp_write(rt2x00dev, 94, r94);
880
881 rt73usb_rf_write(rt2x00dev, 1, rf->rf1);
882 rt73usb_rf_write(rt2x00dev, 2, rf->rf2);
883 rt73usb_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
884 rt73usb_rf_write(rt2x00dev, 4, rf->rf4);
885
886 rt73usb_rf_write(rt2x00dev, 1, rf->rf1);
887 rt73usb_rf_write(rt2x00dev, 2, rf->rf2);
888 rt73usb_rf_write(rt2x00dev, 3, rf->rf3 | 0x00000004);
889 rt73usb_rf_write(rt2x00dev, 4, rf->rf4);
890
891 rt73usb_rf_write(rt2x00dev, 1, rf->rf1);
892 rt73usb_rf_write(rt2x00dev, 2, rf->rf2);
893 rt73usb_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
894 rt73usb_rf_write(rt2x00dev, 4, rf->rf4);
895
896 udelay(10);
897}
898
899static void rt73usb_config_txpower(struct rt2x00_dev *rt2x00dev,
900 const int txpower)
901{
902 struct rf_channel rf;
903
904 rt2x00_rf_read(rt2x00dev, 1, &rf.rf1);
905 rt2x00_rf_read(rt2x00dev, 2, &rf.rf2);
906 rt2x00_rf_read(rt2x00dev, 3, &rf.rf3);
907 rt2x00_rf_read(rt2x00dev, 4, &rf.rf4);
908
909 rt73usb_config_channel(rt2x00dev, &rf, txpower);
910}
911
912static void rt73usb_config_retry_limit(struct rt2x00_dev *rt2x00dev,
913 struct rt2x00lib_conf *libconf)
914{
918 u32 reg; 915 u32 reg;
919 916
920 rt73usb_register_read(rt2x00dev, MAC_CSR9, &reg); 917 rt73usb_register_read(rt2x00dev, TXRX_CSR4, &reg);
921 rt2x00_set_field32(&reg, MAC_CSR9_SLOT_TIME, libconf->slot_time); 918 rt2x00_set_field32(&reg, TXRX_CSR4_LONG_RETRY_LIMIT,
922 rt73usb_register_write(rt2x00dev, MAC_CSR9, reg); 919 libconf->conf->long_frame_max_tx_count);
920 rt2x00_set_field32(&reg, TXRX_CSR4_SHORT_RETRY_LIMIT,
921 libconf->conf->short_frame_max_tx_count);
922 rt73usb_register_write(rt2x00dev, TXRX_CSR4, reg);
923}
923 924
924 rt73usb_register_read(rt2x00dev, MAC_CSR8, &reg); 925static void rt73usb_config_duration(struct rt2x00_dev *rt2x00dev,
925 rt2x00_set_field32(&reg, MAC_CSR8_SIFS, libconf->sifs); 926 struct rt2x00lib_conf *libconf)
926 rt2x00_set_field32(&reg, MAC_CSR8_SIFS_AFTER_RX_OFDM, 3); 927{
927 rt2x00_set_field32(&reg, MAC_CSR8_EIFS, libconf->eifs); 928 u32 reg;
928 rt73usb_register_write(rt2x00dev, MAC_CSR8, reg);
929 929
930 rt73usb_register_read(rt2x00dev, TXRX_CSR0, &reg); 930 rt73usb_register_read(rt2x00dev, TXRX_CSR0, &reg);
931 rt2x00_set_field32(&reg, TXRX_CSR0_TSF_OFFSET, IEEE80211_HEADER); 931 rt2x00_set_field32(&reg, TXRX_CSR0_TSF_OFFSET, IEEE80211_HEADER);
@@ -948,16 +948,15 @@ static void rt73usb_config(struct rt2x00_dev *rt2x00dev,
948 /* Always recalculate LNA gain before changing configuration */ 948 /* Always recalculate LNA gain before changing configuration */
949 rt73usb_config_lna_gain(rt2x00dev, libconf); 949 rt73usb_config_lna_gain(rt2x00dev, libconf);
950 950
951 if (flags & CONFIG_UPDATE_PHYMODE) 951 if (flags & IEEE80211_CONF_CHANGE_CHANNEL)
952 rt73usb_config_phymode(rt2x00dev, libconf->basic_rates);
953 if (flags & CONFIG_UPDATE_CHANNEL)
954 rt73usb_config_channel(rt2x00dev, &libconf->rf, 952 rt73usb_config_channel(rt2x00dev, &libconf->rf,
955 libconf->conf->power_level); 953 libconf->conf->power_level);
956 if ((flags & CONFIG_UPDATE_TXPOWER) && !(flags & CONFIG_UPDATE_CHANNEL)) 954 if ((flags & IEEE80211_CONF_CHANGE_POWER) &&
955 !(flags & IEEE80211_CONF_CHANGE_CHANNEL))
957 rt73usb_config_txpower(rt2x00dev, libconf->conf->power_level); 956 rt73usb_config_txpower(rt2x00dev, libconf->conf->power_level);
958 if (flags & CONFIG_UPDATE_ANTENNA) 957 if (flags & IEEE80211_CONF_CHANGE_RETRY_LIMITS)
959 rt73usb_config_antenna(rt2x00dev, &libconf->ant); 958 rt73usb_config_retry_limit(rt2x00dev, libconf);
960 if (flags & (CONFIG_UPDATE_SLOT_TIME | CONFIG_UPDATE_BEACON_INT)) 959 if (flags & IEEE80211_CONF_CHANGE_BEACON_INTERVAL)
961 rt73usb_config_duration(rt2x00dev, libconf); 960 rt73usb_config_duration(rt2x00dev, libconf);
962} 961}
963 962
@@ -2209,20 +2208,6 @@ static int rt73usb_probe_hw(struct rt2x00_dev *rt2x00dev)
2209/* 2208/*
2210 * IEEE80211 stack callback functions. 2209 * IEEE80211 stack callback functions.
2211 */ 2210 */
2212static int rt73usb_set_retry_limit(struct ieee80211_hw *hw,
2213 u32 short_retry, u32 long_retry)
2214{
2215 struct rt2x00_dev *rt2x00dev = hw->priv;
2216 u32 reg;
2217
2218 rt73usb_register_read(rt2x00dev, TXRX_CSR4, &reg);
2219 rt2x00_set_field32(&reg, TXRX_CSR4_LONG_RETRY_LIMIT, long_retry);
2220 rt2x00_set_field32(&reg, TXRX_CSR4_SHORT_RETRY_LIMIT, short_retry);
2221 rt73usb_register_write(rt2x00dev, TXRX_CSR4, reg);
2222
2223 return 0;
2224}
2225
2226static int rt73usb_conf_tx(struct ieee80211_hw *hw, u16 queue_idx, 2211static int rt73usb_conf_tx(struct ieee80211_hw *hw, u16 queue_idx,
2227 const struct ieee80211_tx_queue_params *params) 2212 const struct ieee80211_tx_queue_params *params)
2228{ 2213{
@@ -2345,8 +2330,8 @@ static const struct rt2x00lib_ops rt73usb_rt2x00_ops = {
2345 .config_filter = rt73usb_config_filter, 2330 .config_filter = rt73usb_config_filter,
2346 .config_intf = rt73usb_config_intf, 2331 .config_intf = rt73usb_config_intf,
2347 .config_erp = rt73usb_config_erp, 2332 .config_erp = rt73usb_config_erp,
2333 .config_ant = rt73usb_config_ant,
2348 .config = rt73usb_config, 2334 .config = rt73usb_config,
2349 .set_retry_limit = rt73usb_set_retry_limit,
2350}; 2335};
2351 2336
2352static const struct data_queue_desc rt73usb_queue_rx = { 2337static const struct data_queue_desc rt73usb_queue_rx = {
diff --git a/drivers/net/wireless/rt2x00/rt73usb.h b/drivers/net/wireless/rt2x00/rt73usb.h
index 868386c457f6..46e1405eb0e2 100644
--- a/drivers/net/wireless/rt2x00/rt73usb.h
+++ b/drivers/net/wireless/rt2x00/rt73usb.h
@@ -48,7 +48,9 @@
48#define CSR_REG_SIZE 0x04b0 48#define CSR_REG_SIZE 0x04b0
49#define EEPROM_BASE 0x0000 49#define EEPROM_BASE 0x0000
50#define EEPROM_SIZE 0x0100 50#define EEPROM_SIZE 0x0100
51#define BBP_BASE 0x0000
51#define BBP_SIZE 0x0080 52#define BBP_SIZE 0x0080
53#define RF_BASE 0x0000
52#define RF_SIZE 0x0014 54#define RF_SIZE 0x0014
53 55
54/* 56/*
diff --git a/drivers/net/wireless/rtl8187_dev.c b/drivers/net/wireless/rtl8187_dev.c
index 6260ed8ce12b..66add5e77e00 100644
--- a/drivers/net/wireless/rtl8187_dev.c
+++ b/drivers/net/wireless/rtl8187_dev.c
@@ -152,8 +152,6 @@ void rtl8187_write_phy(struct ieee80211_hw *dev, u8 addr, u32 data)
152 rtl818x_iowrite8(priv, &priv->map->PHY[2], (data >> 16) & 0xFF); 152 rtl818x_iowrite8(priv, &priv->map->PHY[2], (data >> 16) & 0xFF);
153 rtl818x_iowrite8(priv, &priv->map->PHY[1], (data >> 8) & 0xFF); 153 rtl818x_iowrite8(priv, &priv->map->PHY[1], (data >> 8) & 0xFF);
154 rtl818x_iowrite8(priv, &priv->map->PHY[0], data & 0xFF); 154 rtl818x_iowrite8(priv, &priv->map->PHY[0], data & 0xFF);
155
156 msleep(1);
157} 155}
158 156
159static void rtl8187_tx_cb(struct urb *urb) 157static void rtl8187_tx_cb(struct urb *urb)
@@ -669,7 +667,7 @@ static int rtl8187b_init_hw(struct ieee80211_hw *dev)
669 rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, 0x0480); 667 rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, 0x0480);
670 rtl818x_iowrite16(priv, &priv->map->RFPinsSelect, 0x2488); 668 rtl818x_iowrite16(priv, &priv->map->RFPinsSelect, 0x2488);
671 rtl818x_iowrite16(priv, &priv->map->RFPinsEnable, 0x1FFF); 669 rtl818x_iowrite16(priv, &priv->map->RFPinsEnable, 0x1FFF);
672 msleep(1100); 670 msleep(100);
673 671
674 priv->rf->init(dev); 672 priv->rf->init(dev);
675 673
@@ -872,7 +870,6 @@ static int rtl8187_config(struct ieee80211_hw *dev, u32 changed)
872 */ 870 */
873 rtl818x_iowrite32(priv, &priv->map->TX_CONF, 871 rtl818x_iowrite32(priv, &priv->map->TX_CONF,
874 reg | RTL818X_TX_CONF_LOOPBACK_MAC); 872 reg | RTL818X_TX_CONF_LOOPBACK_MAC);
875 msleep(10);
876 priv->rf->set_chan(dev, conf); 873 priv->rf->set_chan(dev, conf);
877 msleep(10); 874 msleep(10);
878 rtl818x_iowrite32(priv, &priv->map->TX_CONF, reg); 875 rtl818x_iowrite32(priv, &priv->map->TX_CONF, reg);
diff --git a/drivers/net/wireless/rtl8187_rtl8225.c b/drivers/net/wireless/rtl8187_rtl8225.c
index b999f87ed150..69030be62b36 100644
--- a/drivers/net/wireless/rtl8187_rtl8225.c
+++ b/drivers/net/wireless/rtl8187_rtl8225.c
@@ -64,7 +64,6 @@ static void rtl8225_write_bitbang(struct ieee80211_hw *dev, u8 addr, u16 data)
64 64
65 rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, reg80 | (1 << 2)); 65 rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, reg80 | (1 << 2));
66 rtl818x_iowrite16(priv, &priv->map->RFPinsSelect, reg84); 66 rtl818x_iowrite16(priv, &priv->map->RFPinsSelect, reg84);
67 msleep(2);
68} 67}
69 68
70static void rtl8225_write_8051(struct ieee80211_hw *dev, u8 addr, __le16 data) 69static void rtl8225_write_8051(struct ieee80211_hw *dev, u8 addr, __le16 data)
@@ -98,7 +97,6 @@ static void rtl8225_write_8051(struct ieee80211_hw *dev, u8 addr, __le16 data)
98 97
99 rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, reg80 | (1 << 2)); 98 rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, reg80 | (1 << 2));
100 rtl818x_iowrite16(priv, &priv->map->RFPinsSelect, reg84); 99 rtl818x_iowrite16(priv, &priv->map->RFPinsSelect, reg84);
101 msleep(2);
102} 100}
103 101
104static void rtl8225_write(struct ieee80211_hw *dev, u8 addr, u16 data) 102static void rtl8225_write(struct ieee80211_hw *dev, u8 addr, u16 data)
@@ -333,21 +331,21 @@ static void rtl8225_rf_init(struct ieee80211_hw *dev)
333 struct rtl8187_priv *priv = dev->priv; 331 struct rtl8187_priv *priv = dev->priv;
334 int i; 332 int i;
335 333
336 rtl8225_write(dev, 0x0, 0x067); msleep(1); 334 rtl8225_write(dev, 0x0, 0x067);
337 rtl8225_write(dev, 0x1, 0xFE0); msleep(1); 335 rtl8225_write(dev, 0x1, 0xFE0);
338 rtl8225_write(dev, 0x2, 0x44D); msleep(1); 336 rtl8225_write(dev, 0x2, 0x44D);
339 rtl8225_write(dev, 0x3, 0x441); msleep(1); 337 rtl8225_write(dev, 0x3, 0x441);
340 rtl8225_write(dev, 0x4, 0x486); msleep(1); 338 rtl8225_write(dev, 0x4, 0x486);
341 rtl8225_write(dev, 0x5, 0xBC0); msleep(1); 339 rtl8225_write(dev, 0x5, 0xBC0);
342 rtl8225_write(dev, 0x6, 0xAE6); msleep(1); 340 rtl8225_write(dev, 0x6, 0xAE6);
343 rtl8225_write(dev, 0x7, 0x82A); msleep(1); 341 rtl8225_write(dev, 0x7, 0x82A);
344 rtl8225_write(dev, 0x8, 0x01F); msleep(1); 342 rtl8225_write(dev, 0x8, 0x01F);
345 rtl8225_write(dev, 0x9, 0x334); msleep(1); 343 rtl8225_write(dev, 0x9, 0x334);
346 rtl8225_write(dev, 0xA, 0xFD4); msleep(1); 344 rtl8225_write(dev, 0xA, 0xFD4);
347 rtl8225_write(dev, 0xB, 0x391); msleep(1); 345 rtl8225_write(dev, 0xB, 0x391);
348 rtl8225_write(dev, 0xC, 0x050); msleep(1); 346 rtl8225_write(dev, 0xC, 0x050);
349 rtl8225_write(dev, 0xD, 0x6DB); msleep(1); 347 rtl8225_write(dev, 0xD, 0x6DB);
350 rtl8225_write(dev, 0xE, 0x029); msleep(1); 348 rtl8225_write(dev, 0xE, 0x029);
351 rtl8225_write(dev, 0xF, 0x914); msleep(100); 349 rtl8225_write(dev, 0xF, 0x914); msleep(100);
352 350
353 rtl8225_write(dev, 0x2, 0xC4D); msleep(200); 351 rtl8225_write(dev, 0x2, 0xC4D); msleep(200);
@@ -375,91 +373,89 @@ static void rtl8225_rf_init(struct ieee80211_hw *dev)
375 373
376 for (i = 0; i < ARRAY_SIZE(rtl8225_agc); i++) { 374 for (i = 0; i < ARRAY_SIZE(rtl8225_agc); i++) {
377 rtl8225_write_phy_ofdm(dev, 0xB, rtl8225_agc[i]); 375 rtl8225_write_phy_ofdm(dev, 0xB, rtl8225_agc[i]);
378 msleep(1);
379 rtl8225_write_phy_ofdm(dev, 0xA, 0x80 + i); 376 rtl8225_write_phy_ofdm(dev, 0xA, 0x80 + i);
380 msleep(1);
381 } 377 }
382 378
383 msleep(1); 379 msleep(1);
384 380
385 rtl8225_write_phy_ofdm(dev, 0x00, 0x01); msleep(1); 381 rtl8225_write_phy_ofdm(dev, 0x00, 0x01);
386 rtl8225_write_phy_ofdm(dev, 0x01, 0x02); msleep(1); 382 rtl8225_write_phy_ofdm(dev, 0x01, 0x02);
387 rtl8225_write_phy_ofdm(dev, 0x02, 0x42); msleep(1); 383 rtl8225_write_phy_ofdm(dev, 0x02, 0x42);
388 rtl8225_write_phy_ofdm(dev, 0x03, 0x00); msleep(1); 384 rtl8225_write_phy_ofdm(dev, 0x03, 0x00);
389 rtl8225_write_phy_ofdm(dev, 0x04, 0x00); msleep(1); 385 rtl8225_write_phy_ofdm(dev, 0x04, 0x00);
390 rtl8225_write_phy_ofdm(dev, 0x05, 0x00); msleep(1); 386 rtl8225_write_phy_ofdm(dev, 0x05, 0x00);
391 rtl8225_write_phy_ofdm(dev, 0x06, 0x40); msleep(1); 387 rtl8225_write_phy_ofdm(dev, 0x06, 0x40);
392 rtl8225_write_phy_ofdm(dev, 0x07, 0x00); msleep(1); 388 rtl8225_write_phy_ofdm(dev, 0x07, 0x00);
393 rtl8225_write_phy_ofdm(dev, 0x08, 0x40); msleep(1); 389 rtl8225_write_phy_ofdm(dev, 0x08, 0x40);
394 rtl8225_write_phy_ofdm(dev, 0x09, 0xfe); msleep(1); 390 rtl8225_write_phy_ofdm(dev, 0x09, 0xfe);
395 rtl8225_write_phy_ofdm(dev, 0x0a, 0x09); msleep(1); 391 rtl8225_write_phy_ofdm(dev, 0x0a, 0x09);
396 rtl8225_write_phy_ofdm(dev, 0x0b, 0x80); msleep(1); 392 rtl8225_write_phy_ofdm(dev, 0x0b, 0x80);
397 rtl8225_write_phy_ofdm(dev, 0x0c, 0x01); msleep(1); 393 rtl8225_write_phy_ofdm(dev, 0x0c, 0x01);
398 rtl8225_write_phy_ofdm(dev, 0x0e, 0xd3); msleep(1); 394 rtl8225_write_phy_ofdm(dev, 0x0e, 0xd3);
399 rtl8225_write_phy_ofdm(dev, 0x0f, 0x38); msleep(1); 395 rtl8225_write_phy_ofdm(dev, 0x0f, 0x38);
400 rtl8225_write_phy_ofdm(dev, 0x10, 0x84); msleep(1); 396 rtl8225_write_phy_ofdm(dev, 0x10, 0x84);
401 rtl8225_write_phy_ofdm(dev, 0x11, 0x06); msleep(1); 397 rtl8225_write_phy_ofdm(dev, 0x11, 0x06);
402 rtl8225_write_phy_ofdm(dev, 0x12, 0x20); msleep(1); 398 rtl8225_write_phy_ofdm(dev, 0x12, 0x20);
403 rtl8225_write_phy_ofdm(dev, 0x13, 0x20); msleep(1); 399 rtl8225_write_phy_ofdm(dev, 0x13, 0x20);
404 rtl8225_write_phy_ofdm(dev, 0x14, 0x00); msleep(1); 400 rtl8225_write_phy_ofdm(dev, 0x14, 0x00);
405 rtl8225_write_phy_ofdm(dev, 0x15, 0x40); msleep(1); 401 rtl8225_write_phy_ofdm(dev, 0x15, 0x40);
406 rtl8225_write_phy_ofdm(dev, 0x16, 0x00); msleep(1); 402 rtl8225_write_phy_ofdm(dev, 0x16, 0x00);
407 rtl8225_write_phy_ofdm(dev, 0x17, 0x40); msleep(1); 403 rtl8225_write_phy_ofdm(dev, 0x17, 0x40);
408 rtl8225_write_phy_ofdm(dev, 0x18, 0xef); msleep(1); 404 rtl8225_write_phy_ofdm(dev, 0x18, 0xef);
409 rtl8225_write_phy_ofdm(dev, 0x19, 0x19); msleep(1); 405 rtl8225_write_phy_ofdm(dev, 0x19, 0x19);
410 rtl8225_write_phy_ofdm(dev, 0x1a, 0x20); msleep(1); 406 rtl8225_write_phy_ofdm(dev, 0x1a, 0x20);
411 rtl8225_write_phy_ofdm(dev, 0x1b, 0x76); msleep(1); 407 rtl8225_write_phy_ofdm(dev, 0x1b, 0x76);
412 rtl8225_write_phy_ofdm(dev, 0x1c, 0x04); msleep(1); 408 rtl8225_write_phy_ofdm(dev, 0x1c, 0x04);
413 rtl8225_write_phy_ofdm(dev, 0x1e, 0x95); msleep(1); 409 rtl8225_write_phy_ofdm(dev, 0x1e, 0x95);
414 rtl8225_write_phy_ofdm(dev, 0x1f, 0x75); msleep(1); 410 rtl8225_write_phy_ofdm(dev, 0x1f, 0x75);
415 rtl8225_write_phy_ofdm(dev, 0x20, 0x1f); msleep(1); 411 rtl8225_write_phy_ofdm(dev, 0x20, 0x1f);
416 rtl8225_write_phy_ofdm(dev, 0x21, 0x27); msleep(1); 412 rtl8225_write_phy_ofdm(dev, 0x21, 0x27);
417 rtl8225_write_phy_ofdm(dev, 0x22, 0x16); msleep(1); 413 rtl8225_write_phy_ofdm(dev, 0x22, 0x16);
418 rtl8225_write_phy_ofdm(dev, 0x24, 0x46); msleep(1); 414 rtl8225_write_phy_ofdm(dev, 0x24, 0x46);
419 rtl8225_write_phy_ofdm(dev, 0x25, 0x20); msleep(1); 415 rtl8225_write_phy_ofdm(dev, 0x25, 0x20);
420 rtl8225_write_phy_ofdm(dev, 0x26, 0x90); msleep(1); 416 rtl8225_write_phy_ofdm(dev, 0x26, 0x90);
421 rtl8225_write_phy_ofdm(dev, 0x27, 0x88); msleep(1); 417 rtl8225_write_phy_ofdm(dev, 0x27, 0x88);
422 418
423 rtl8225_write_phy_ofdm(dev, 0x0d, rtl8225_gain[2 * 4]); 419 rtl8225_write_phy_ofdm(dev, 0x0d, rtl8225_gain[2 * 4]);
424 rtl8225_write_phy_ofdm(dev, 0x1b, rtl8225_gain[2 * 4 + 2]); 420 rtl8225_write_phy_ofdm(dev, 0x1b, rtl8225_gain[2 * 4 + 2]);
425 rtl8225_write_phy_ofdm(dev, 0x1d, rtl8225_gain[2 * 4 + 3]); 421 rtl8225_write_phy_ofdm(dev, 0x1d, rtl8225_gain[2 * 4 + 3]);
426 rtl8225_write_phy_ofdm(dev, 0x23, rtl8225_gain[2 * 4 + 1]); 422 rtl8225_write_phy_ofdm(dev, 0x23, rtl8225_gain[2 * 4 + 1]);
427 423
428 rtl8225_write_phy_cck(dev, 0x00, 0x98); msleep(1); 424 rtl8225_write_phy_cck(dev, 0x00, 0x98);
429 rtl8225_write_phy_cck(dev, 0x03, 0x20); msleep(1); 425 rtl8225_write_phy_cck(dev, 0x03, 0x20);
430 rtl8225_write_phy_cck(dev, 0x04, 0x7e); msleep(1); 426 rtl8225_write_phy_cck(dev, 0x04, 0x7e);
431 rtl8225_write_phy_cck(dev, 0x05, 0x12); msleep(1); 427 rtl8225_write_phy_cck(dev, 0x05, 0x12);
432 rtl8225_write_phy_cck(dev, 0x06, 0xfc); msleep(1); 428 rtl8225_write_phy_cck(dev, 0x06, 0xfc);
433 rtl8225_write_phy_cck(dev, 0x07, 0x78); msleep(1); 429 rtl8225_write_phy_cck(dev, 0x07, 0x78);
434 rtl8225_write_phy_cck(dev, 0x08, 0x2e); msleep(1); 430 rtl8225_write_phy_cck(dev, 0x08, 0x2e);
435 rtl8225_write_phy_cck(dev, 0x10, 0x9b); msleep(1); 431 rtl8225_write_phy_cck(dev, 0x10, 0x9b);
436 rtl8225_write_phy_cck(dev, 0x11, 0x88); msleep(1); 432 rtl8225_write_phy_cck(dev, 0x11, 0x88);
437 rtl8225_write_phy_cck(dev, 0x12, 0x47); msleep(1); 433 rtl8225_write_phy_cck(dev, 0x12, 0x47);
438 rtl8225_write_phy_cck(dev, 0x13, 0xd0); 434 rtl8225_write_phy_cck(dev, 0x13, 0xd0);
439 rtl8225_write_phy_cck(dev, 0x19, 0x00); 435 rtl8225_write_phy_cck(dev, 0x19, 0x00);
440 rtl8225_write_phy_cck(dev, 0x1a, 0xa0); 436 rtl8225_write_phy_cck(dev, 0x1a, 0xa0);
441 rtl8225_write_phy_cck(dev, 0x1b, 0x08); 437 rtl8225_write_phy_cck(dev, 0x1b, 0x08);
442 rtl8225_write_phy_cck(dev, 0x40, 0x86); 438 rtl8225_write_phy_cck(dev, 0x40, 0x86);
443 rtl8225_write_phy_cck(dev, 0x41, 0x8d); msleep(1); 439 rtl8225_write_phy_cck(dev, 0x41, 0x8d);
444 rtl8225_write_phy_cck(dev, 0x42, 0x15); msleep(1); 440 rtl8225_write_phy_cck(dev, 0x42, 0x15);
445 rtl8225_write_phy_cck(dev, 0x43, 0x18); msleep(1); 441 rtl8225_write_phy_cck(dev, 0x43, 0x18);
446 rtl8225_write_phy_cck(dev, 0x44, 0x1f); msleep(1); 442 rtl8225_write_phy_cck(dev, 0x44, 0x1f);
447 rtl8225_write_phy_cck(dev, 0x45, 0x1e); msleep(1); 443 rtl8225_write_phy_cck(dev, 0x45, 0x1e);
448 rtl8225_write_phy_cck(dev, 0x46, 0x1a); msleep(1); 444 rtl8225_write_phy_cck(dev, 0x46, 0x1a);
449 rtl8225_write_phy_cck(dev, 0x47, 0x15); msleep(1); 445 rtl8225_write_phy_cck(dev, 0x47, 0x15);
450 rtl8225_write_phy_cck(dev, 0x48, 0x10); msleep(1); 446 rtl8225_write_phy_cck(dev, 0x48, 0x10);
451 rtl8225_write_phy_cck(dev, 0x49, 0x0a); msleep(1); 447 rtl8225_write_phy_cck(dev, 0x49, 0x0a);
452 rtl8225_write_phy_cck(dev, 0x4a, 0x05); msleep(1); 448 rtl8225_write_phy_cck(dev, 0x4a, 0x05);
453 rtl8225_write_phy_cck(dev, 0x4b, 0x02); msleep(1); 449 rtl8225_write_phy_cck(dev, 0x4b, 0x02);
454 rtl8225_write_phy_cck(dev, 0x4c, 0x05); msleep(1); 450 rtl8225_write_phy_cck(dev, 0x4c, 0x05);
455 451
456 rtl818x_iowrite8(priv, &priv->map->TESTR, 0x0D); 452 rtl818x_iowrite8(priv, &priv->map->TESTR, 0x0D);
457 453
458 rtl8225_rf_set_tx_power(dev, 1); 454 rtl8225_rf_set_tx_power(dev, 1);
459 455
460 /* RX antenna default to A */ 456 /* RX antenna default to A */
461 rtl8225_write_phy_cck(dev, 0x10, 0x9b); msleep(1); /* B: 0xDB */ 457 rtl8225_write_phy_cck(dev, 0x10, 0x9b); /* B: 0xDB */
462 rtl8225_write_phy_ofdm(dev, 0x26, 0x90); msleep(1); /* B: 0x10 */ 458 rtl8225_write_phy_ofdm(dev, 0x26, 0x90); /* B: 0x10 */
463 459
464 rtl818x_iowrite8(priv, &priv->map->TX_ANTENNA, 0x03); /* B: 0x00 */ 460 rtl818x_iowrite8(priv, &priv->map->TX_ANTENNA, 0x03); /* B: 0x00 */
465 msleep(1); 461 msleep(1);
@@ -629,7 +625,7 @@ static void rtl8225z2_b_rf_set_tx_power(struct ieee80211_hw *dev, int channel)
629 rtl8225_write_phy_cck(dev, 0x44 + i, *tmp++); 625 rtl8225_write_phy_cck(dev, 0x44 + i, *tmp++);
630 626
631 rtl818x_iowrite8(priv, &priv->map->TX_GAIN_CCK, 627 rtl818x_iowrite8(priv, &priv->map->TX_GAIN_CCK,
632 rtl8225z2_tx_gain_cck_ofdm[cck_power]); 628 rtl8225z2_tx_gain_cck_ofdm[cck_power] << 1);
633 msleep(1); 629 msleep(1);
634 630
635 rtl818x_iowrite8(priv, &priv->map->TX_GAIN_OFDM, 631 rtl818x_iowrite8(priv, &priv->map->TX_GAIN_OFDM,
@@ -687,22 +683,23 @@ static void rtl8225z2_rf_init(struct ieee80211_hw *dev)
687 struct rtl8187_priv *priv = dev->priv; 683 struct rtl8187_priv *priv = dev->priv;
688 int i; 684 int i;
689 685
690 rtl8225_write(dev, 0x0, 0x2BF); msleep(1); 686 rtl8225_write(dev, 0x0, 0x2BF);
691 rtl8225_write(dev, 0x1, 0xEE0); msleep(1); 687 rtl8225_write(dev, 0x1, 0xEE0);
692 rtl8225_write(dev, 0x2, 0x44D); msleep(1); 688 rtl8225_write(dev, 0x2, 0x44D);
693 rtl8225_write(dev, 0x3, 0x441); msleep(1); 689 rtl8225_write(dev, 0x3, 0x441);
694 rtl8225_write(dev, 0x4, 0x8C3); msleep(1); 690 rtl8225_write(dev, 0x4, 0x8C3);
695 rtl8225_write(dev, 0x5, 0xC72); msleep(1); 691 rtl8225_write(dev, 0x5, 0xC72);
696 rtl8225_write(dev, 0x6, 0x0E6); msleep(1); 692 rtl8225_write(dev, 0x6, 0x0E6);
697 rtl8225_write(dev, 0x7, 0x82A); msleep(1); 693 rtl8225_write(dev, 0x7, 0x82A);
698 rtl8225_write(dev, 0x8, 0x03F); msleep(1); 694 rtl8225_write(dev, 0x8, 0x03F);
699 rtl8225_write(dev, 0x9, 0x335); msleep(1); 695 rtl8225_write(dev, 0x9, 0x335);
700 rtl8225_write(dev, 0xa, 0x9D4); msleep(1); 696 rtl8225_write(dev, 0xa, 0x9D4);
701 rtl8225_write(dev, 0xb, 0x7BB); msleep(1); 697 rtl8225_write(dev, 0xb, 0x7BB);
702 rtl8225_write(dev, 0xc, 0x850); msleep(1); 698 rtl8225_write(dev, 0xc, 0x850);
703 rtl8225_write(dev, 0xd, 0xCDF); msleep(1); 699 rtl8225_write(dev, 0xd, 0xCDF);
704 rtl8225_write(dev, 0xe, 0x02B); msleep(1); 700 rtl8225_write(dev, 0xe, 0x02B);
705 rtl8225_write(dev, 0xf, 0x114); msleep(100); 701 rtl8225_write(dev, 0xf, 0x114);
702 msleep(100);
706 703
707 rtl8225_write(dev, 0x0, 0x1B7); 704 rtl8225_write(dev, 0x0, 0x1B7);
708 705
@@ -736,94 +733,92 @@ static void rtl8225z2_rf_init(struct ieee80211_hw *dev)
736 733
737 for (i = 0; i < ARRAY_SIZE(rtl8225_agc); i++) { 734 for (i = 0; i < ARRAY_SIZE(rtl8225_agc); i++) {
738 rtl8225_write_phy_ofdm(dev, 0xB, rtl8225_agc[i]); 735 rtl8225_write_phy_ofdm(dev, 0xB, rtl8225_agc[i]);
739 msleep(1);
740 rtl8225_write_phy_ofdm(dev, 0xA, 0x80 + i); 736 rtl8225_write_phy_ofdm(dev, 0xA, 0x80 + i);
741 msleep(1);
742 } 737 }
743 738
744 msleep(1); 739 msleep(1);
745 740
746 rtl8225_write_phy_ofdm(dev, 0x00, 0x01); msleep(1); 741 rtl8225_write_phy_ofdm(dev, 0x00, 0x01);
747 rtl8225_write_phy_ofdm(dev, 0x01, 0x02); msleep(1); 742 rtl8225_write_phy_ofdm(dev, 0x01, 0x02);
748 rtl8225_write_phy_ofdm(dev, 0x02, 0x42); msleep(1); 743 rtl8225_write_phy_ofdm(dev, 0x02, 0x42);
749 rtl8225_write_phy_ofdm(dev, 0x03, 0x00); msleep(1); 744 rtl8225_write_phy_ofdm(dev, 0x03, 0x00);
750 rtl8225_write_phy_ofdm(dev, 0x04, 0x00); msleep(1); 745 rtl8225_write_phy_ofdm(dev, 0x04, 0x00);
751 rtl8225_write_phy_ofdm(dev, 0x05, 0x00); msleep(1); 746 rtl8225_write_phy_ofdm(dev, 0x05, 0x00);
752 rtl8225_write_phy_ofdm(dev, 0x06, 0x40); msleep(1); 747 rtl8225_write_phy_ofdm(dev, 0x06, 0x40);
753 rtl8225_write_phy_ofdm(dev, 0x07, 0x00); msleep(1); 748 rtl8225_write_phy_ofdm(dev, 0x07, 0x00);
754 rtl8225_write_phy_ofdm(dev, 0x08, 0x40); msleep(1); 749 rtl8225_write_phy_ofdm(dev, 0x08, 0x40);
755 rtl8225_write_phy_ofdm(dev, 0x09, 0xfe); msleep(1); 750 rtl8225_write_phy_ofdm(dev, 0x09, 0xfe);
756 rtl8225_write_phy_ofdm(dev, 0x0a, 0x08); msleep(1); 751 rtl8225_write_phy_ofdm(dev, 0x0a, 0x08);
757 rtl8225_write_phy_ofdm(dev, 0x0b, 0x80); msleep(1); 752 rtl8225_write_phy_ofdm(dev, 0x0b, 0x80);
758 rtl8225_write_phy_ofdm(dev, 0x0c, 0x01); msleep(1); 753 rtl8225_write_phy_ofdm(dev, 0x0c, 0x01);
759 rtl8225_write_phy_ofdm(dev, 0x0d, 0x43); 754 rtl8225_write_phy_ofdm(dev, 0x0d, 0x43);
760 rtl8225_write_phy_ofdm(dev, 0x0e, 0xd3); msleep(1); 755 rtl8225_write_phy_ofdm(dev, 0x0e, 0xd3);
761 rtl8225_write_phy_ofdm(dev, 0x0f, 0x38); msleep(1); 756 rtl8225_write_phy_ofdm(dev, 0x0f, 0x38);
762 rtl8225_write_phy_ofdm(dev, 0x10, 0x84); msleep(1); 757 rtl8225_write_phy_ofdm(dev, 0x10, 0x84);
763 rtl8225_write_phy_ofdm(dev, 0x11, 0x07); msleep(1); 758 rtl8225_write_phy_ofdm(dev, 0x11, 0x07);
764 rtl8225_write_phy_ofdm(dev, 0x12, 0x20); msleep(1); 759 rtl8225_write_phy_ofdm(dev, 0x12, 0x20);
765 rtl8225_write_phy_ofdm(dev, 0x13, 0x20); msleep(1); 760 rtl8225_write_phy_ofdm(dev, 0x13, 0x20);
766 rtl8225_write_phy_ofdm(dev, 0x14, 0x00); msleep(1); 761 rtl8225_write_phy_ofdm(dev, 0x14, 0x00);
767 rtl8225_write_phy_ofdm(dev, 0x15, 0x40); msleep(1); 762 rtl8225_write_phy_ofdm(dev, 0x15, 0x40);
768 rtl8225_write_phy_ofdm(dev, 0x16, 0x00); msleep(1); 763 rtl8225_write_phy_ofdm(dev, 0x16, 0x00);
769 rtl8225_write_phy_ofdm(dev, 0x17, 0x40); msleep(1); 764 rtl8225_write_phy_ofdm(dev, 0x17, 0x40);
770 rtl8225_write_phy_ofdm(dev, 0x18, 0xef); msleep(1); 765 rtl8225_write_phy_ofdm(dev, 0x18, 0xef);
771 rtl8225_write_phy_ofdm(dev, 0x19, 0x19); msleep(1); 766 rtl8225_write_phy_ofdm(dev, 0x19, 0x19);
772 rtl8225_write_phy_ofdm(dev, 0x1a, 0x20); msleep(1); 767 rtl8225_write_phy_ofdm(dev, 0x1a, 0x20);
773 rtl8225_write_phy_ofdm(dev, 0x1b, 0x15); msleep(1); 768 rtl8225_write_phy_ofdm(dev, 0x1b, 0x15);
774 rtl8225_write_phy_ofdm(dev, 0x1c, 0x04); msleep(1); 769 rtl8225_write_phy_ofdm(dev, 0x1c, 0x04);
775 rtl8225_write_phy_ofdm(dev, 0x1d, 0xc5); msleep(1); 770 rtl8225_write_phy_ofdm(dev, 0x1d, 0xc5);
776 rtl8225_write_phy_ofdm(dev, 0x1e, 0x95); msleep(1); 771 rtl8225_write_phy_ofdm(dev, 0x1e, 0x95);
777 rtl8225_write_phy_ofdm(dev, 0x1f, 0x75); msleep(1); 772 rtl8225_write_phy_ofdm(dev, 0x1f, 0x75);
778 rtl8225_write_phy_ofdm(dev, 0x20, 0x1f); msleep(1); 773 rtl8225_write_phy_ofdm(dev, 0x20, 0x1f);
779 rtl8225_write_phy_ofdm(dev, 0x21, 0x17); msleep(1); 774 rtl8225_write_phy_ofdm(dev, 0x21, 0x17);
780 rtl8225_write_phy_ofdm(dev, 0x22, 0x16); msleep(1); 775 rtl8225_write_phy_ofdm(dev, 0x22, 0x16);
781 rtl8225_write_phy_ofdm(dev, 0x23, 0x80); msleep(1); //FIXME: not needed? 776 rtl8225_write_phy_ofdm(dev, 0x23, 0x80);
782 rtl8225_write_phy_ofdm(dev, 0x24, 0x46); msleep(1); 777 rtl8225_write_phy_ofdm(dev, 0x24, 0x46);
783 rtl8225_write_phy_ofdm(dev, 0x25, 0x00); msleep(1); 778 rtl8225_write_phy_ofdm(dev, 0x25, 0x00);
784 rtl8225_write_phy_ofdm(dev, 0x26, 0x90); msleep(1); 779 rtl8225_write_phy_ofdm(dev, 0x26, 0x90);
785 rtl8225_write_phy_ofdm(dev, 0x27, 0x88); msleep(1); 780 rtl8225_write_phy_ofdm(dev, 0x27, 0x88);
786 781
787 rtl8225_write_phy_ofdm(dev, 0x0b, rtl8225z2_gain_bg[4 * 3]); 782 rtl8225_write_phy_ofdm(dev, 0x0b, rtl8225z2_gain_bg[4 * 3]);
788 rtl8225_write_phy_ofdm(dev, 0x1b, rtl8225z2_gain_bg[4 * 3 + 1]); 783 rtl8225_write_phy_ofdm(dev, 0x1b, rtl8225z2_gain_bg[4 * 3 + 1]);
789 rtl8225_write_phy_ofdm(dev, 0x1d, rtl8225z2_gain_bg[4 * 3 + 2]); 784 rtl8225_write_phy_ofdm(dev, 0x1d, rtl8225z2_gain_bg[4 * 3 + 2]);
790 rtl8225_write_phy_ofdm(dev, 0x21, 0x37); 785 rtl8225_write_phy_ofdm(dev, 0x21, 0x37);
791 786
792 rtl8225_write_phy_cck(dev, 0x00, 0x98); msleep(1); 787 rtl8225_write_phy_cck(dev, 0x00, 0x98);
793 rtl8225_write_phy_cck(dev, 0x03, 0x20); msleep(1); 788 rtl8225_write_phy_cck(dev, 0x03, 0x20);
794 rtl8225_write_phy_cck(dev, 0x04, 0x7e); msleep(1); 789 rtl8225_write_phy_cck(dev, 0x04, 0x7e);
795 rtl8225_write_phy_cck(dev, 0x05, 0x12); msleep(1); 790 rtl8225_write_phy_cck(dev, 0x05, 0x12);
796 rtl8225_write_phy_cck(dev, 0x06, 0xfc); msleep(1); 791 rtl8225_write_phy_cck(dev, 0x06, 0xfc);
797 rtl8225_write_phy_cck(dev, 0x07, 0x78); msleep(1); 792 rtl8225_write_phy_cck(dev, 0x07, 0x78);
798 rtl8225_write_phy_cck(dev, 0x08, 0x2e); msleep(1); 793 rtl8225_write_phy_cck(dev, 0x08, 0x2e);
799 rtl8225_write_phy_cck(dev, 0x10, 0x9b); msleep(1); 794 rtl8225_write_phy_cck(dev, 0x10, 0x9b);
800 rtl8225_write_phy_cck(dev, 0x11, 0x88); msleep(1); 795 rtl8225_write_phy_cck(dev, 0x11, 0x88);
801 rtl8225_write_phy_cck(dev, 0x12, 0x47); msleep(1); 796 rtl8225_write_phy_cck(dev, 0x12, 0x47);
802 rtl8225_write_phy_cck(dev, 0x13, 0xd0); 797 rtl8225_write_phy_cck(dev, 0x13, 0xd0);
803 rtl8225_write_phy_cck(dev, 0x19, 0x00); 798 rtl8225_write_phy_cck(dev, 0x19, 0x00);
804 rtl8225_write_phy_cck(dev, 0x1a, 0xa0); 799 rtl8225_write_phy_cck(dev, 0x1a, 0xa0);
805 rtl8225_write_phy_cck(dev, 0x1b, 0x08); 800 rtl8225_write_phy_cck(dev, 0x1b, 0x08);
806 rtl8225_write_phy_cck(dev, 0x40, 0x86); 801 rtl8225_write_phy_cck(dev, 0x40, 0x86);
807 rtl8225_write_phy_cck(dev, 0x41, 0x8d); msleep(1); 802 rtl8225_write_phy_cck(dev, 0x41, 0x8d);
808 rtl8225_write_phy_cck(dev, 0x42, 0x15); msleep(1); 803 rtl8225_write_phy_cck(dev, 0x42, 0x15);
809 rtl8225_write_phy_cck(dev, 0x43, 0x18); msleep(1); 804 rtl8225_write_phy_cck(dev, 0x43, 0x18);
810 rtl8225_write_phy_cck(dev, 0x44, 0x36); msleep(1); 805 rtl8225_write_phy_cck(dev, 0x44, 0x36);
811 rtl8225_write_phy_cck(dev, 0x45, 0x35); msleep(1); 806 rtl8225_write_phy_cck(dev, 0x45, 0x35);
812 rtl8225_write_phy_cck(dev, 0x46, 0x2e); msleep(1); 807 rtl8225_write_phy_cck(dev, 0x46, 0x2e);
813 rtl8225_write_phy_cck(dev, 0x47, 0x25); msleep(1); 808 rtl8225_write_phy_cck(dev, 0x47, 0x25);
814 rtl8225_write_phy_cck(dev, 0x48, 0x1c); msleep(1); 809 rtl8225_write_phy_cck(dev, 0x48, 0x1c);
815 rtl8225_write_phy_cck(dev, 0x49, 0x12); msleep(1); 810 rtl8225_write_phy_cck(dev, 0x49, 0x12);
816 rtl8225_write_phy_cck(dev, 0x4a, 0x09); msleep(1); 811 rtl8225_write_phy_cck(dev, 0x4a, 0x09);
817 rtl8225_write_phy_cck(dev, 0x4b, 0x04); msleep(1); 812 rtl8225_write_phy_cck(dev, 0x4b, 0x04);
818 rtl8225_write_phy_cck(dev, 0x4c, 0x05); msleep(1); 813 rtl8225_write_phy_cck(dev, 0x4c, 0x05);
819 814
820 rtl818x_iowrite8(priv, (u8 *)0xFF5B, 0x0D); msleep(1); 815 rtl818x_iowrite8(priv, (u8 *)0xFF5B, 0x0D); msleep(1);
821 816
822 rtl8225z2_rf_set_tx_power(dev, 1); 817 rtl8225z2_rf_set_tx_power(dev, 1);
823 818
824 /* RX antenna default to A */ 819 /* RX antenna default to A */
825 rtl8225_write_phy_cck(dev, 0x10, 0x9b); msleep(1); /* B: 0xDB */ 820 rtl8225_write_phy_cck(dev, 0x10, 0x9b); /* B: 0xDB */
826 rtl8225_write_phy_ofdm(dev, 0x26, 0x90); msleep(1); /* B: 0x10 */ 821 rtl8225_write_phy_ofdm(dev, 0x26, 0x90); /* B: 0x10 */
827 822
828 rtl818x_iowrite8(priv, &priv->map->TX_ANTENNA, 0x03); /* B: 0x00 */ 823 rtl818x_iowrite8(priv, &priv->map->TX_ANTENNA, 0x03); /* B: 0x00 */
829 msleep(1); 824 msleep(1);
@@ -835,40 +830,38 @@ static void rtl8225z2_b_rf_init(struct ieee80211_hw *dev)
835 struct rtl8187_priv *priv = dev->priv; 830 struct rtl8187_priv *priv = dev->priv;
836 int i; 831 int i;
837 832
838 rtl8225_write(dev, 0x0, 0x0B7); msleep(1); 833 rtl8225_write(dev, 0x0, 0x0B7);
839 rtl8225_write(dev, 0x1, 0xEE0); msleep(1); 834 rtl8225_write(dev, 0x1, 0xEE0);
840 rtl8225_write(dev, 0x2, 0x44D); msleep(1); 835 rtl8225_write(dev, 0x2, 0x44D);
841 rtl8225_write(dev, 0x3, 0x441); msleep(1); 836 rtl8225_write(dev, 0x3, 0x441);
842 rtl8225_write(dev, 0x4, 0x8C3); msleep(1); 837 rtl8225_write(dev, 0x4, 0x8C3);
843 rtl8225_write(dev, 0x5, 0xC72); msleep(1); 838 rtl8225_write(dev, 0x5, 0xC72);
844 rtl8225_write(dev, 0x6, 0x0E6); msleep(1); 839 rtl8225_write(dev, 0x6, 0x0E6);
845 rtl8225_write(dev, 0x7, 0x82A); msleep(1); 840 rtl8225_write(dev, 0x7, 0x82A);
846 rtl8225_write(dev, 0x8, 0x03F); msleep(1); 841 rtl8225_write(dev, 0x8, 0x03F);
847 rtl8225_write(dev, 0x9, 0x335); msleep(1); 842 rtl8225_write(dev, 0x9, 0x335);
848 rtl8225_write(dev, 0xa, 0x9D4); msleep(1); 843 rtl8225_write(dev, 0xa, 0x9D4);
849 rtl8225_write(dev, 0xb, 0x7BB); msleep(1); 844 rtl8225_write(dev, 0xb, 0x7BB);
850 rtl8225_write(dev, 0xc, 0x850); msleep(1); 845 rtl8225_write(dev, 0xc, 0x850);
851 rtl8225_write(dev, 0xd, 0xCDF); msleep(1); 846 rtl8225_write(dev, 0xd, 0xCDF);
852 rtl8225_write(dev, 0xe, 0x02B); msleep(1); 847 rtl8225_write(dev, 0xe, 0x02B);
853 rtl8225_write(dev, 0xf, 0x114); msleep(1); 848 rtl8225_write(dev, 0xf, 0x114);
854 849
855 rtl8225_write(dev, 0x0, 0x1B7); msleep(1); 850 rtl8225_write(dev, 0x0, 0x1B7);
856 851
857 for (i = 0; i < ARRAY_SIZE(rtl8225z2_rxgain); i++) { 852 for (i = 0; i < ARRAY_SIZE(rtl8225z2_rxgain); i++) {
858 rtl8225_write(dev, 0x1, i + 1); msleep(1); 853 rtl8225_write(dev, 0x1, i + 1);
859 rtl8225_write(dev, 0x2, rtl8225z2_rxgain[i]); msleep(1); 854 rtl8225_write(dev, 0x2, rtl8225z2_rxgain[i]);
860 } 855 }
861 856
862 rtl8225_write(dev, 0x3, 0x080); msleep(1); 857 rtl8225_write(dev, 0x3, 0x080);
863 rtl8225_write(dev, 0x5, 0x004); msleep(1); 858 rtl8225_write(dev, 0x5, 0x004);
864 rtl8225_write(dev, 0x0, 0x0B7); msleep(1); 859 rtl8225_write(dev, 0x0, 0x0B7);
865 msleep(3000);
866 860
867 rtl8225_write(dev, 0x2, 0xC4D); msleep(1); 861 rtl8225_write(dev, 0x2, 0xC4D);
868 msleep(2000);
869 862
870 rtl8225_write(dev, 0x2, 0x44D); msleep(1); 863 rtl8225_write(dev, 0x2, 0x44D);
871 rtl8225_write(dev, 0x0, 0x2BF); msleep(1); 864 rtl8225_write(dev, 0x0, 0x2BF);
872 865
873 rtl818x_iowrite8(priv, &priv->map->TX_GAIN_CCK, 0x03); 866 rtl818x_iowrite8(priv, &priv->map->TX_GAIN_CCK, 0x03);
874 rtl818x_iowrite8(priv, &priv->map->TX_GAIN_OFDM, 0x07); 867 rtl818x_iowrite8(priv, &priv->map->TX_GAIN_OFDM, 0x07);
@@ -891,10 +884,10 @@ static void rtl8225z2_b_rf_init(struct ieee80211_hw *dev)
891 rtl818x_iowrite32(priv, (__le32 *)0xFFFC, (7 << 12) | (3 << 8) | 28); 884 rtl818x_iowrite32(priv, (__le32 *)0xFFFC, (7 << 12) | (3 << 8) | 28);
892 rtl818x_iowrite8(priv, &priv->map->ACM_CONTROL, 0); 885 rtl818x_iowrite8(priv, &priv->map->ACM_CONTROL, 0);
893 886
894 rtl8225_write_phy_ofdm(dev, 0x97, 0x46); msleep(1); 887 rtl8225_write_phy_ofdm(dev, 0x97, 0x46);
895 rtl8225_write_phy_ofdm(dev, 0xa4, 0xb6); msleep(1); 888 rtl8225_write_phy_ofdm(dev, 0xa4, 0xb6);
896 rtl8225_write_phy_ofdm(dev, 0x85, 0xfc); msleep(1); 889 rtl8225_write_phy_ofdm(dev, 0x85, 0xfc);
897 rtl8225_write_phy_cck(dev, 0xc1, 0x88); msleep(1); 890 rtl8225_write_phy_cck(dev, 0xc1, 0x88);
898} 891}
899 892
900static void rtl8225_rf_stop(struct ieee80211_hw *dev) 893static void rtl8225_rf_stop(struct ieee80211_hw *dev)
@@ -902,7 +895,7 @@ static void rtl8225_rf_stop(struct ieee80211_hw *dev)
902 u8 reg; 895 u8 reg;
903 struct rtl8187_priv *priv = dev->priv; 896 struct rtl8187_priv *priv = dev->priv;
904 897
905 rtl8225_write(dev, 0x4, 0x1f); msleep(1); 898 rtl8225_write(dev, 0x4, 0x1f);
906 899
907 rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_CONFIG); 900 rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_CONFIG);
908 reg = rtl818x_ioread8(priv, &priv->map->CONFIG3); 901 reg = rtl818x_ioread8(priv, &priv->map->CONFIG3);
diff --git a/drivers/net/wireless/wl3501.h b/drivers/net/wireless/wl3501.h
index 65ceb088f700..59bb3a55ab48 100644
--- a/drivers/net/wireless/wl3501.h
+++ b/drivers/net/wireless/wl3501.h
@@ -2,7 +2,7 @@
2#define __WL3501_H__ 2#define __WL3501_H__
3 3
4#include <linux/spinlock.h> 4#include <linux/spinlock.h>
5#include <net/ieee80211.h> 5#include <linux/ieee80211.h>
6 6
7/* define for WLA 2.0 */ 7/* define for WLA 2.0 */
8#define WL3501_BLKSZ 256 8#define WL3501_BLKSZ 256
@@ -548,7 +548,7 @@ struct wl3501_80211_tx_plcp_hdr {
548 548
549struct wl3501_80211_tx_hdr { 549struct wl3501_80211_tx_hdr {
550 struct wl3501_80211_tx_plcp_hdr pclp_hdr; 550 struct wl3501_80211_tx_plcp_hdr pclp_hdr;
551 struct ieee80211_hdr_4addr mac_hdr; 551 struct ieee80211_hdr mac_hdr;
552} __attribute__ ((packed)); 552} __attribute__ ((packed));
553 553
554/* 554/*
diff --git a/drivers/net/wireless/zd1201.c b/drivers/net/wireless/zd1201.c
index bf744c1f5b23..1134e2fb1890 100644
--- a/drivers/net/wireless/zd1201.c
+++ b/drivers/net/wireless/zd1201.c
@@ -17,11 +17,11 @@
17#include <linux/netdevice.h> 17#include <linux/netdevice.h>
18#include <linux/etherdevice.h> 18#include <linux/etherdevice.h>
19#include <linux/wireless.h> 19#include <linux/wireless.h>
20#include <linux/ieee80211.h>
20#include <net/iw_handler.h> 21#include <net/iw_handler.h>
21#include <linux/string.h> 22#include <linux/string.h>
22#include <linux/if_arp.h> 23#include <linux/if_arp.h>
23#include <linux/firmware.h> 24#include <linux/firmware.h>
24#include <net/ieee80211.h>
25#include "zd1201.h" 25#include "zd1201.h"
26 26
27static struct usb_device_id zd1201_table[] = { 27static struct usb_device_id zd1201_table[] = {
@@ -345,7 +345,7 @@ static void zd1201_usbrx(struct urb *urb)
345 frag = kmalloc(sizeof(*frag), GFP_ATOMIC); 345 frag = kmalloc(sizeof(*frag), GFP_ATOMIC);
346 if (!frag) 346 if (!frag)
347 goto resubmit; 347 goto resubmit;
348 skb = dev_alloc_skb(IEEE80211_DATA_LEN +14+2); 348 skb = dev_alloc_skb(IEEE80211_MAX_DATA_LEN +14+2);
349 if (!skb) { 349 if (!skb) {
350 kfree(frag); 350 kfree(frag);
351 goto resubmit; 351 goto resubmit;
diff --git a/include/linux/ieee80211.h b/include/linux/ieee80211.h
index aad99195a4cc..56b0eb25d927 100644
--- a/include/linux/ieee80211.h
+++ b/include/linux/ieee80211.h
@@ -97,7 +97,10 @@
97#define IEEE80211_MAX_FRAME_LEN 2352 97#define IEEE80211_MAX_FRAME_LEN 2352
98 98
99#define IEEE80211_MAX_SSID_LEN 32 99#define IEEE80211_MAX_SSID_LEN 32
100
100#define IEEE80211_MAX_MESH_ID_LEN 32 101#define IEEE80211_MAX_MESH_ID_LEN 32
102#define IEEE80211_MESH_CONFIG_LEN 19
103
101#define IEEE80211_QOS_CTL_LEN 2 104#define IEEE80211_QOS_CTL_LEN 2
102#define IEEE80211_QOS_CTL_TID_MASK 0x000F 105#define IEEE80211_QOS_CTL_TID_MASK 0x000F
103#define IEEE80211_QOS_CTL_TAG1D_MASK 0x0007 106#define IEEE80211_QOS_CTL_TAG1D_MASK 0x0007
@@ -666,6 +669,13 @@ struct ieee80211_cts {
666 u8 ra[6]; 669 u8 ra[6];
667} __attribute__ ((packed)); 670} __attribute__ ((packed));
668 671
672struct ieee80211_pspoll {
673 __le16 frame_control;
674 __le16 aid;
675 u8 bssid[6];
676 u8 ta[6];
677} __attribute__ ((packed));
678
669/** 679/**
670 * struct ieee80211_bar - HT Block Ack Request 680 * struct ieee80211_bar - HT Block Ack Request
671 * 681 *
diff --git a/include/linux/nl80211.h b/include/linux/nl80211.h
index e4cc7869b22f..79827345351d 100644
--- a/include/linux/nl80211.h
+++ b/include/linux/nl80211.h
@@ -25,8 +25,9 @@
25 * 25 *
26 * @NL80211_CMD_GET_WIPHY: request information about a wiphy or dump request 26 * @NL80211_CMD_GET_WIPHY: request information about a wiphy or dump request
27 * to get a list of all present wiphys. 27 * to get a list of all present wiphys.
28 * @NL80211_CMD_SET_WIPHY: set wiphy name, needs %NL80211_ATTR_WIPHY and 28 * @NL80211_CMD_SET_WIPHY: set wiphy parameters, needs %NL80211_ATTR_WIPHY or
29 * %NL80211_ATTR_WIPHY_NAME. 29 * %NL80211_ATTR_IFINDEX; can be used to set %NL80211_ATTR_WIPHY_NAME
30 * and/or %NL80211_ATTR_WIPHY_TXQ_PARAMS.
30 * @NL80211_CMD_NEW_WIPHY: Newly created wiphy, response to get request 31 * @NL80211_CMD_NEW_WIPHY: Newly created wiphy, response to get request
31 * or rename notification. Has attributes %NL80211_ATTR_WIPHY and 32 * or rename notification. Has attributes %NL80211_ATTR_WIPHY and
32 * %NL80211_ATTR_WIPHY_NAME. 33 * %NL80211_ATTR_WIPHY_NAME.
@@ -178,6 +179,7 @@ enum nl80211_commands {
178 * @NL80211_ATTR_WIPHY: index of wiphy to operate on, cf. 179 * @NL80211_ATTR_WIPHY: index of wiphy to operate on, cf.
179 * /sys/class/ieee80211/<phyname>/index 180 * /sys/class/ieee80211/<phyname>/index
180 * @NL80211_ATTR_WIPHY_NAME: wiphy name (used for renaming) 181 * @NL80211_ATTR_WIPHY_NAME: wiphy name (used for renaming)
182 * @NL80211_ATTR_WIPHY_TXQ_PARAMS: a nested array of TX queue parameters
181 * 183 *
182 * @NL80211_ATTR_IFINDEX: network interface index of the device to operate on 184 * @NL80211_ATTR_IFINDEX: network interface index of the device to operate on
183 * @NL80211_ATTR_IFNAME: network interface name 185 * @NL80211_ATTR_IFNAME: network interface name
@@ -243,6 +245,9 @@ enum nl80211_commands {
243 * (u8, 0 or 1) 245 * (u8, 0 or 1)
244 * @NL80211_ATTR_BSS_SHORT_SLOT_TIME: whether short slot time enabled 246 * @NL80211_ATTR_BSS_SHORT_SLOT_TIME: whether short slot time enabled
245 * (u8, 0 or 1) 247 * (u8, 0 or 1)
248 * @NL80211_ATTR_BSS_BASIC_RATES: basic rates, array of basic
249 * rates in format defined by IEEE 802.11 7.3.2.2 but without the length
250 * restriction (at most %NL80211_MAX_SUPP_RATES).
246 * 251 *
247 * @NL80211_ATTR_HT_CAPABILITY: HT Capability information element (from 252 * @NL80211_ATTR_HT_CAPABILITY: HT Capability information element (from
248 * association request when used with NL80211_CMD_NEW_STATION) 253 * association request when used with NL80211_CMD_NEW_STATION)
@@ -307,6 +312,10 @@ enum nl80211_attrs {
307 312
308 NL80211_ATTR_MESH_PARAMS, 313 NL80211_ATTR_MESH_PARAMS,
309 314
315 NL80211_ATTR_BSS_BASIC_RATES,
316
317 NL80211_ATTR_WIPHY_TXQ_PARAMS,
318
310 /* add attributes here, update the policy in nl80211.c */ 319 /* add attributes here, update the policy in nl80211.c */
311 320
312 __NL80211_ATTR_AFTER_LAST, 321 __NL80211_ATTR_AFTER_LAST,
@@ -318,6 +327,8 @@ enum nl80211_attrs {
318 * here 327 * here
319 */ 328 */
320#define NL80211_ATTR_HT_CAPABILITY NL80211_ATTR_HT_CAPABILITY 329#define NL80211_ATTR_HT_CAPABILITY NL80211_ATTR_HT_CAPABILITY
330#define NL80211_ATTR_BSS_BASIC_RATES NL80211_ATTR_BSS_BASIC_RATES
331#define NL80211_ATTR_WIPHY_TXQ_PARAMS NL80211_ATTR_WIPHY_TXQ_PARAMS
321 332
322#define NL80211_MAX_SUPP_RATES 32 333#define NL80211_MAX_SUPP_RATES 32
323#define NL80211_MAX_SUPP_REG_RULES 32 334#define NL80211_MAX_SUPP_REG_RULES 32
@@ -692,4 +703,38 @@ enum nl80211_meshconf_params {
692 NL80211_MESHCONF_ATTR_MAX = __NL80211_MESHCONF_ATTR_AFTER_LAST - 1 703 NL80211_MESHCONF_ATTR_MAX = __NL80211_MESHCONF_ATTR_AFTER_LAST - 1
693}; 704};
694 705
706/**
707 * enum nl80211_txq_attr - TX queue parameter attributes
708 * @__NL80211_TXQ_ATTR_INVALID: Attribute number 0 is reserved
709 * @NL80211_TXQ_ATTR_QUEUE: TX queue identifier (NL80211_TXQ_Q_*)
710 * @NL80211_TXQ_ATTR_TXOP: Maximum burst time in units of 32 usecs, 0 meaning
711 * disabled
712 * @NL80211_TXQ_ATTR_CWMIN: Minimum contention window [a value of the form
713 * 2^n-1 in the range 1..32767]
714 * @NL80211_TXQ_ATTR_CWMAX: Maximum contention window [a value of the form
715 * 2^n-1 in the range 1..32767]
716 * @NL80211_TXQ_ATTR_AIFS: Arbitration interframe space [0..255]
717 * @__NL80211_TXQ_ATTR_AFTER_LAST: Internal
718 * @NL80211_TXQ_ATTR_MAX: Maximum TXQ attribute number
719 */
720enum nl80211_txq_attr {
721 __NL80211_TXQ_ATTR_INVALID,
722 NL80211_TXQ_ATTR_QUEUE,
723 NL80211_TXQ_ATTR_TXOP,
724 NL80211_TXQ_ATTR_CWMIN,
725 NL80211_TXQ_ATTR_CWMAX,
726 NL80211_TXQ_ATTR_AIFS,
727
728 /* keep last */
729 __NL80211_TXQ_ATTR_AFTER_LAST,
730 NL80211_TXQ_ATTR_MAX = __NL80211_TXQ_ATTR_AFTER_LAST - 1
731};
732
733enum nl80211_txq_q {
734 NL80211_TXQ_Q_VO,
735 NL80211_TXQ_Q_VI,
736 NL80211_TXQ_Q_BE,
737 NL80211_TXQ_Q_BK
738};
739
695#endif /* __LINUX_NL80211_H */ 740#endif /* __LINUX_NL80211_H */
diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index 03e1e88c6a09..1d57835d73f2 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -280,11 +280,16 @@ struct mpath_info {
280 * (0 = no, 1 = yes, -1 = do not change) 280 * (0 = no, 1 = yes, -1 = do not change)
281 * @use_short_slot_time: Whether the use of short slot time is allowed 281 * @use_short_slot_time: Whether the use of short slot time is allowed
282 * (0 = no, 1 = yes, -1 = do not change) 282 * (0 = no, 1 = yes, -1 = do not change)
283 * @basic_rates: basic rates in IEEE 802.11 format
284 * (or NULL for no change)
285 * @basic_rates_len: number of basic rates
283 */ 286 */
284struct bss_parameters { 287struct bss_parameters {
285 int use_cts_prot; 288 int use_cts_prot;
286 int use_short_preamble; 289 int use_short_preamble;
287 int use_short_slot_time; 290 int use_short_slot_time;
291 u8 *basic_rates;
292 u8 basic_rates_len;
288}; 293};
289 294
290/** 295/**
@@ -331,19 +336,19 @@ struct ieee80211_regdomain {
331 struct ieee80211_reg_rule reg_rules[]; 336 struct ieee80211_reg_rule reg_rules[];
332}; 337};
333 338
334#define MHZ_TO_KHZ(freq) (freq * 1000) 339#define MHZ_TO_KHZ(freq) ((freq) * 1000)
335#define KHZ_TO_MHZ(freq) (freq / 1000) 340#define KHZ_TO_MHZ(freq) ((freq) / 1000)
336#define DBI_TO_MBI(gain) (gain * 100) 341#define DBI_TO_MBI(gain) ((gain) * 100)
337#define MBI_TO_DBI(gain) (gain / 100) 342#define MBI_TO_DBI(gain) ((gain) / 100)
338#define DBM_TO_MBM(gain) (gain * 100) 343#define DBM_TO_MBM(gain) ((gain) * 100)
339#define MBM_TO_DBM(gain) (gain / 100) 344#define MBM_TO_DBM(gain) ((gain) / 100)
340 345
341#define REG_RULE(start, end, bw, gain, eirp, reg_flags) { \ 346#define REG_RULE(start, end, bw, gain, eirp, reg_flags) { \
342 .freq_range.start_freq_khz = (start) * 1000, \ 347 .freq_range.start_freq_khz = MHZ_TO_KHZ(start), \
343 .freq_range.end_freq_khz = (end) * 1000, \ 348 .freq_range.end_freq_khz = MHZ_TO_KHZ(end), \
344 .freq_range.max_bandwidth_khz = (bw) * 1000, \ 349 .freq_range.max_bandwidth_khz = MHZ_TO_KHZ(bw), \
345 .power_rule.max_antenna_gain = (gain) * 100, \ 350 .power_rule.max_antenna_gain = DBI_TO_MBI(gain), \
346 .power_rule.max_eirp = (eirp) * 100, \ 351 .power_rule.max_eirp = DBM_TO_MBM(eirp), \
347 .flags = reg_flags, \ 352 .flags = reg_flags, \
348 } 353 }
349 354
@@ -366,6 +371,24 @@ struct mesh_config {
366 u16 dot11MeshHWMPnetDiameterTraversalTime; 371 u16 dot11MeshHWMPnetDiameterTraversalTime;
367}; 372};
368 373
374/**
375 * struct ieee80211_txq_params - TX queue parameters
376 * @queue: TX queue identifier (NL80211_TXQ_Q_*)
377 * @txop: Maximum burst time in units of 32 usecs, 0 meaning disabled
378 * @cwmin: Minimum contention window [a value of the form 2^n-1 in the range
379 * 1..32767]
380 * @cwmax: Maximum contention window [a value of the form 2^n-1 in the range
381 * 1..32767]
382 * @aifs: Arbitration interframe space [0..255]
383 */
384struct ieee80211_txq_params {
385 enum nl80211_txq_q queue;
386 u16 txop;
387 u16 cwmin;
388 u16 cwmax;
389 u8 aifs;
390};
391
369/* from net/wireless.h */ 392/* from net/wireless.h */
370struct wiphy; 393struct wiphy;
371 394
@@ -425,6 +448,8 @@ struct wiphy;
425 * @set_mesh_cfg: set mesh parameters (by now, just mesh id) 448 * @set_mesh_cfg: set mesh parameters (by now, just mesh id)
426 * 449 *
427 * @change_bss: Modify parameters for a given BSS. 450 * @change_bss: Modify parameters for a given BSS.
451 *
452 * @set_txq_params: Set TX queue parameters
428 */ 453 */
429struct cfg80211_ops { 454struct cfg80211_ops {
430 int (*add_virtual_intf)(struct wiphy *wiphy, char *name, 455 int (*add_virtual_intf)(struct wiphy *wiphy, char *name,
@@ -485,6 +510,9 @@ struct cfg80211_ops {
485 const struct mesh_config *nconf, u32 mask); 510 const struct mesh_config *nconf, u32 mask);
486 int (*change_bss)(struct wiphy *wiphy, struct net_device *dev, 511 int (*change_bss)(struct wiphy *wiphy, struct net_device *dev,
487 struct bss_parameters *params); 512 struct bss_parameters *params);
513
514 int (*set_txq_params)(struct wiphy *wiphy,
515 struct ieee80211_txq_params *params);
488}; 516};
489 517
490#endif /* __NET_CFG80211_H */ 518#endif /* __NET_CFG80211_H */
diff --git a/include/net/mac80211.h b/include/net/mac80211.h
index 0b983bed3829..53856003aa18 100644
--- a/include/net/mac80211.h
+++ b/include/net/mac80211.h
@@ -616,14 +616,12 @@ struct ieee80211_if_init_conf {
616 * enum ieee80211_if_conf_change - interface config change flags 616 * enum ieee80211_if_conf_change - interface config change flags
617 * 617 *
618 * @IEEE80211_IFCC_BSSID: The BSSID changed. 618 * @IEEE80211_IFCC_BSSID: The BSSID changed.
619 * @IEEE80211_IFCC_SSID: The SSID changed.
620 * @IEEE80211_IFCC_BEACON: The beacon for this interface changed 619 * @IEEE80211_IFCC_BEACON: The beacon for this interface changed
621 * (currently AP and MESH only), use ieee80211_beacon_get(). 620 * (currently AP and MESH only), use ieee80211_beacon_get().
622 */ 621 */
623enum ieee80211_if_conf_change { 622enum ieee80211_if_conf_change {
624 IEEE80211_IFCC_BSSID = BIT(0), 623 IEEE80211_IFCC_BSSID = BIT(0),
625 IEEE80211_IFCC_SSID = BIT(1), 624 IEEE80211_IFCC_BEACON = BIT(1),
626 IEEE80211_IFCC_BEACON = BIT(2),
627}; 625};
628 626
629/** 627/**
@@ -631,11 +629,6 @@ enum ieee80211_if_conf_change {
631 * 629 *
632 * @changed: parameters that have changed, see &enum ieee80211_if_conf_change. 630 * @changed: parameters that have changed, see &enum ieee80211_if_conf_change.
633 * @bssid: BSSID of the network we are associated to/creating. 631 * @bssid: BSSID of the network we are associated to/creating.
634 * @ssid: used (together with @ssid_len) by drivers for hardware that
635 * generate beacons independently. The pointer is valid only during the
636 * config_interface() call, so copy the value somewhere if you need
637 * it.
638 * @ssid_len: length of the @ssid field.
639 * 632 *
640 * This structure is passed to the config_interface() callback of 633 * This structure is passed to the config_interface() callback of
641 * &struct ieee80211_hw. 634 * &struct ieee80211_hw.
@@ -643,8 +636,6 @@ enum ieee80211_if_conf_change {
643struct ieee80211_if_conf { 636struct ieee80211_if_conf {
644 u32 changed; 637 u32 changed;
645 u8 *bssid; 638 u8 *bssid;
646 u8 *ssid;
647 size_t ssid_len;
648}; 639};
649 640
650/** 641/**
@@ -1136,12 +1127,14 @@ enum ieee80211_filter_flags {
1136 * @IEEE80211_AMPDU_RX_STOP: stop Rx aggregation 1127 * @IEEE80211_AMPDU_RX_STOP: stop Rx aggregation
1137 * @IEEE80211_AMPDU_TX_START: start Tx aggregation 1128 * @IEEE80211_AMPDU_TX_START: start Tx aggregation
1138 * @IEEE80211_AMPDU_TX_STOP: stop Tx aggregation 1129 * @IEEE80211_AMPDU_TX_STOP: stop Tx aggregation
1130 * @IEEE80211_AMPDU_TX_RESUME: resume TX aggregation
1139 */ 1131 */
1140enum ieee80211_ampdu_mlme_action { 1132enum ieee80211_ampdu_mlme_action {
1141 IEEE80211_AMPDU_RX_START, 1133 IEEE80211_AMPDU_RX_START,
1142 IEEE80211_AMPDU_RX_STOP, 1134 IEEE80211_AMPDU_RX_STOP,
1143 IEEE80211_AMPDU_TX_START, 1135 IEEE80211_AMPDU_TX_START,
1144 IEEE80211_AMPDU_TX_STOP, 1136 IEEE80211_AMPDU_TX_STOP,
1137 IEEE80211_AMPDU_TX_RESUME,
1145}; 1138};
1146 1139
1147/** 1140/**
diff --git a/include/net/wireless.h b/include/net/wireless.h
index 41294c5f6f8f..17d4b582cf34 100644
--- a/include/net/wireless.h
+++ b/include/net/wireless.h
@@ -341,6 +341,22 @@ ieee80211_get_channel(struct wiphy *wiphy, int freq)
341} 341}
342 342
343/** 343/**
344 * ieee80211_get_response_rate - get basic rate for a given rate
345 *
346 * @sband: the band to look for rates in
347 * @basic_rates: bitmap of basic rates
348 * @bitrate: the bitrate for which to find the basic rate
349 *
350 * This function returns the basic rate corresponding to a given
351 * bitrate, that is the next lower bitrate contained in the basic
352 * rate map, which is, for this function, given as a bitmap of
353 * indices of rates in the band's bitrate table.
354 */
355struct ieee80211_rate *
356ieee80211_get_response_rate(struct ieee80211_supported_band *sband,
357 u64 basic_rates, int bitrate);
358
359/**
344 * regulatory_hint - driver hint to the wireless core a regulatory domain 360 * regulatory_hint - driver hint to the wireless core a regulatory domain
345 * @wiphy: the wireless device giving the hint (used only for reporting 361 * @wiphy: the wireless device giving the hint (used only for reporting
346 * conflicts) 362 * conflicts)
diff --git a/net/ieee80211/ieee80211_wx.c b/net/ieee80211/ieee80211_wx.c
index 29eb41695a82..7cc4e5ee3660 100644
--- a/net/ieee80211/ieee80211_wx.c
+++ b/net/ieee80211/ieee80211_wx.c
@@ -399,6 +399,10 @@ int ieee80211_wx_set_encode(struct ieee80211_device *ieee,
399 399
400 /* If a new key was provided, set it up */ 400 /* If a new key was provided, set it up */
401 if (erq->length > 0) { 401 if (erq->length > 0) {
402#ifdef CONFIG_IEEE80211_DEBUG
403 DECLARE_SSID_BUF(ssid);
404#endif
405
402 len = erq->length <= 5 ? 5 : 13; 406 len = erq->length <= 5 ? 5 : 13;
403 memcpy(sec.keys[key], keybuf, erq->length); 407 memcpy(sec.keys[key], keybuf, erq->length);
404 if (len > erq->length) 408 if (len > erq->length)
diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index 91f56a48e2b4..16423f94801b 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -26,6 +26,8 @@ static bool nl80211_type_check(enum nl80211_iftype type)
26#ifdef CONFIG_MAC80211_MESH 26#ifdef CONFIG_MAC80211_MESH
27 case NL80211_IFTYPE_MESH_POINT: 27 case NL80211_IFTYPE_MESH_POINT:
28#endif 28#endif
29 case NL80211_IFTYPE_AP:
30 case NL80211_IFTYPE_AP_VLAN:
29 case NL80211_IFTYPE_WDS: 31 case NL80211_IFTYPE_WDS:
30 return true; 32 return true;
31 default: 33 default:
@@ -1046,11 +1048,53 @@ static int ieee80211_change_bss(struct wiphy *wiphy,
1046 changed |= BSS_CHANGED_ERP_SLOT; 1048 changed |= BSS_CHANGED_ERP_SLOT;
1047 } 1049 }
1048 1050
1051 if (params->basic_rates) {
1052 int i, j;
1053 u32 rates = 0;
1054 struct ieee80211_local *local = wiphy_priv(wiphy);
1055 struct ieee80211_supported_band *sband =
1056 wiphy->bands[local->oper_channel->band];
1057
1058 for (i = 0; i < params->basic_rates_len; i++) {
1059 int rate = (params->basic_rates[i] & 0x7f) * 5;
1060 for (j = 0; j < sband->n_bitrates; j++) {
1061 if (sband->bitrates[j].bitrate == rate)
1062 rates |= BIT(j);
1063 }
1064 }
1065 sdata->vif.bss_conf.basic_rates = rates;
1066 changed |= BSS_CHANGED_BASIC_RATES;
1067 }
1068
1049 ieee80211_bss_info_change_notify(sdata, changed); 1069 ieee80211_bss_info_change_notify(sdata, changed);
1050 1070
1051 return 0; 1071 return 0;
1052} 1072}
1053 1073
1074static int ieee80211_set_txq_params(struct wiphy *wiphy,
1075 struct ieee80211_txq_params *params)
1076{
1077 struct ieee80211_local *local = wiphy_priv(wiphy);
1078 struct ieee80211_tx_queue_params p;
1079
1080 if (!local->ops->conf_tx)
1081 return -EOPNOTSUPP;
1082
1083 memset(&p, 0, sizeof(p));
1084 p.aifs = params->aifs;
1085 p.cw_max = params->cwmax;
1086 p.cw_min = params->cwmin;
1087 p.txop = params->txop;
1088 if (local->ops->conf_tx(local_to_hw(local), params->queue, &p)) {
1089 printk(KERN_DEBUG "%s: failed to set TX queue "
1090 "parameters for queue %d\n", local->mdev->name,
1091 params->queue);
1092 return -EINVAL;
1093 }
1094
1095 return 0;
1096}
1097
1054struct cfg80211_ops mac80211_config_ops = { 1098struct cfg80211_ops mac80211_config_ops = {
1055 .add_virtual_intf = ieee80211_add_iface, 1099 .add_virtual_intf = ieee80211_add_iface,
1056 .del_virtual_intf = ieee80211_del_iface, 1100 .del_virtual_intf = ieee80211_del_iface,
@@ -1077,4 +1121,5 @@ struct cfg80211_ops mac80211_config_ops = {
1077 .get_mesh_params = ieee80211_get_mesh_params, 1121 .get_mesh_params = ieee80211_get_mesh_params,
1078#endif 1122#endif
1079 .change_bss = ieee80211_change_bss, 1123 .change_bss = ieee80211_change_bss,
1124 .set_txq_params = ieee80211_set_txq_params,
1080}; 1125};
diff --git a/net/mac80211/ht.c b/net/mac80211/ht.c
index 08009d4b7d6e..3e231d756776 100644
--- a/net/mac80211/ht.c
+++ b/net/mac80211/ht.c
@@ -987,7 +987,7 @@ void ieee80211_process_addba_resp(struct ieee80211_local *local,
987{ 987{
988 struct ieee80211_hw *hw = &local->hw; 988 struct ieee80211_hw *hw = &local->hw;
989 u16 capab; 989 u16 capab;
990 u16 tid; 990 u16 tid, start_seq_num;
991 u8 *state; 991 u8 *state;
992 992
993 capab = le16_to_cpu(mgmt->u.action.u.addba_resp.capab); 993 capab = le16_to_cpu(mgmt->u.action.u.addba_resp.capab);
@@ -1024,6 +1024,14 @@ void ieee80211_process_addba_resp(struct ieee80211_local *local,
1024 local->hw.ampdu_queues) 1024 local->hw.ampdu_queues)
1025 ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]); 1025 ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
1026 1026
1027 if (local->ops->ampdu_action) {
1028 (void)local->ops->ampdu_action(hw,
1029 IEEE80211_AMPDU_TX_RESUME,
1030 &sta->sta, tid, &start_seq_num);
1031 }
1032#ifdef CONFIG_MAC80211_HT_DEBUG
1033 printk(KERN_DEBUG "Resuming TX aggregation for tid %d\n", tid);
1034#endif /* CONFIG_MAC80211_HT_DEBUG */
1027 spin_unlock_bh(&sta->lock); 1035 spin_unlock_bh(&sta->lock);
1028 } else { 1036 } else {
1029 sta->ampdu_mlme.addba_req_num[tid]++; 1037 sta->ampdu_mlme.addba_req_num[tid]++;
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
index 2c91108e3901..155a20410017 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -212,9 +212,6 @@ struct ieee80211_if_ap {
212 212
213 struct list_head vlans; 213 struct list_head vlans;
214 214
215 u8 ssid[IEEE80211_MAX_SSID_LEN];
216 size_t ssid_len;
217
218 /* yes, this looks ugly, but guarantees that we can later use 215 /* yes, this looks ugly, but guarantees that we can later use
219 * bitmap_empty :) 216 * bitmap_empty :)
220 * NB: don't touch this bitmap, use sta_info_{set,clear}_tim_bit */ 217 * NB: don't touch this bitmap, use sta_info_{set,clear}_tim_bit */
diff --git a/net/mac80211/main.c b/net/mac80211/main.c
index fa0cc7a1e6b4..d631dc96c323 100644
--- a/net/mac80211/main.c
+++ b/net/mac80211/main.c
@@ -171,19 +171,13 @@ int ieee80211_if_config(struct ieee80211_sub_if_data *sdata, u32 changed)
171 conf.changed = changed; 171 conf.changed = changed;
172 172
173 if (sdata->vif.type == NL80211_IFTYPE_STATION || 173 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
174 sdata->vif.type == NL80211_IFTYPE_ADHOC) { 174 sdata->vif.type == NL80211_IFTYPE_ADHOC)
175 conf.bssid = sdata->u.sta.bssid; 175 conf.bssid = sdata->u.sta.bssid;
176 conf.ssid = sdata->u.sta.ssid; 176 else if (sdata->vif.type == NL80211_IFTYPE_AP)
177 conf.ssid_len = sdata->u.sta.ssid_len;
178 } else if (sdata->vif.type == NL80211_IFTYPE_AP) {
179 conf.bssid = sdata->dev->dev_addr; 177 conf.bssid = sdata->dev->dev_addr;
180 conf.ssid = sdata->u.ap.ssid; 178 else if (ieee80211_vif_is_mesh(&sdata->vif)) {
181 conf.ssid_len = sdata->u.ap.ssid_len;
182 } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
183 u8 zero[ETH_ALEN] = { 0 }; 179 u8 zero[ETH_ALEN] = { 0 };
184 conf.bssid = zero; 180 conf.bssid = zero;
185 conf.ssid = zero;
186 conf.ssid_len = 0;
187 } else { 181 } else {
188 WARN_ON(1); 182 WARN_ON(1);
189 return -EINVAL; 183 return -EINVAL;
@@ -192,9 +186,6 @@ int ieee80211_if_config(struct ieee80211_sub_if_data *sdata, u32 changed)
192 if (WARN_ON(!conf.bssid && (changed & IEEE80211_IFCC_BSSID))) 186 if (WARN_ON(!conf.bssid && (changed & IEEE80211_IFCC_BSSID)))
193 return -EINVAL; 187 return -EINVAL;
194 188
195 if (WARN_ON(!conf.ssid && (changed & IEEE80211_IFCC_SSID)))
196 return -EINVAL;
197
198 return local->ops->config_interface(local_to_hw(local), 189 return local->ops->config_interface(local_to_hw(local),
199 &sdata->vif, &conf); 190 &sdata->vif, &conf);
200} 191}
diff --git a/net/mac80211/mesh.c b/net/mac80211/mesh.c
index d3b6e1a648bd..82f568e94365 100644
--- a/net/mac80211/mesh.c
+++ b/net/mac80211/mesh.c
@@ -238,7 +238,7 @@ void mesh_mgmt_ies_add(struct sk_buff *skb, struct ieee80211_sub_if_data *sdata)
238 238
239 pos = skb_put(skb, 21); 239 pos = skb_put(skb, 21);
240 *pos++ = WLAN_EID_MESH_CONFIG; 240 *pos++ = WLAN_EID_MESH_CONFIG;
241 *pos++ = MESH_CFG_LEN; 241 *pos++ = IEEE80211_MESH_CONFIG_LEN;
242 /* Version */ 242 /* Version */
243 *pos++ = 1; 243 *pos++ = 1;
244 244
diff --git a/net/mac80211/mesh.h b/net/mac80211/mesh.h
index e10471c6ba42..c197ab545e54 100644
--- a/net/mac80211/mesh.h
+++ b/net/mac80211/mesh.h
@@ -145,9 +145,6 @@ struct mesh_rmc {
145}; 145};
146 146
147 147
148/* Mesh IEs constants */
149#define MESH_CFG_LEN 19
150
151/* 148/*
152 * MESH_CFG_COMP_LEN Includes: 149 * MESH_CFG_COMP_LEN Includes:
153 * - Active path selection protocol ID. 150 * - Active path selection protocol ID.
@@ -157,7 +154,7 @@ struct mesh_rmc {
157 * Does not include mesh capabilities, which may vary across nodes in the same 154 * Does not include mesh capabilities, which may vary across nodes in the same
158 * mesh 155 * mesh
159 */ 156 */
160#define MESH_CFG_CMP_LEN 17 157#define MESH_CFG_CMP_LEN (IEEE80211_MESH_CONFIG_LEN - 2)
161 158
162/* Default values, timeouts in ms */ 159/* Default values, timeouts in ms */
163#define MESH_TTL 5 160#define MESH_TTL 5
diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
index 29fafbe440b7..dee6448c4eb0 100644
--- a/net/mac80211/mlme.c
+++ b/net/mac80211/mlme.c
@@ -1123,7 +1123,8 @@ static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
1123 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code); 1123 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
1124 1124
1125 if (ifsta->flags & IEEE80211_STA_AUTHENTICATED) 1125 if (ifsta->flags & IEEE80211_STA_AUTHENTICATED)
1126 printk(KERN_DEBUG "%s: deauthenticated\n", sdata->dev->name); 1126 printk(KERN_DEBUG "%s: deauthenticated (Reason: %u)\n",
1127 sdata->dev->name, reason_code);
1127 1128
1128 if (ifsta->state == IEEE80211_STA_MLME_AUTHENTICATE || 1129 if (ifsta->state == IEEE80211_STA_MLME_AUTHENTICATE ||
1129 ifsta->state == IEEE80211_STA_MLME_ASSOCIATE || 1130 ifsta->state == IEEE80211_STA_MLME_ASSOCIATE ||
@@ -1154,7 +1155,8 @@ static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
1154 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code); 1155 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
1155 1156
1156 if (ifsta->flags & IEEE80211_STA_ASSOCIATED) 1157 if (ifsta->flags & IEEE80211_STA_ASSOCIATED)
1157 printk(KERN_DEBUG "%s: disassociated\n", sdata->dev->name); 1158 printk(KERN_DEBUG "%s: disassociated (Reason: %u)\n",
1159 sdata->dev->name, reason_code);
1158 1160
1159 if (ifsta->state == IEEE80211_STA_MLME_ASSOCIATED) { 1161 if (ifsta->state == IEEE80211_STA_MLME_ASSOCIATED) {
1160 ifsta->state = IEEE80211_STA_MLME_ASSOCIATE; 1162 ifsta->state = IEEE80211_STA_MLME_ASSOCIATE;
@@ -1289,29 +1291,35 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1289 1291
1290 for (i = 0; i < elems.supp_rates_len; i++) { 1292 for (i = 0; i < elems.supp_rates_len; i++) {
1291 int rate = (elems.supp_rates[i] & 0x7f) * 5; 1293 int rate = (elems.supp_rates[i] & 0x7f) * 5;
1294 bool is_basic = !!(elems.supp_rates[i] & 0x80);
1292 1295
1293 if (rate > 110) 1296 if (rate > 110)
1294 have_higher_than_11mbit = true; 1297 have_higher_than_11mbit = true;
1295 1298
1296 for (j = 0; j < sband->n_bitrates; j++) { 1299 for (j = 0; j < sband->n_bitrates; j++) {
1297 if (sband->bitrates[j].bitrate == rate) 1300 if (sband->bitrates[j].bitrate == rate) {
1298 rates |= BIT(j); 1301 rates |= BIT(j);
1299 if (elems.supp_rates[i] & 0x80) 1302 if (is_basic)
1300 basic_rates |= BIT(j); 1303 basic_rates |= BIT(j);
1304 break;
1305 }
1301 } 1306 }
1302 } 1307 }
1303 1308
1304 for (i = 0; i < elems.ext_supp_rates_len; i++) { 1309 for (i = 0; i < elems.ext_supp_rates_len; i++) {
1305 int rate = (elems.ext_supp_rates[i] & 0x7f) * 5; 1310 int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
1311 bool is_basic = !!(elems.supp_rates[i] & 0x80);
1306 1312
1307 if (rate > 110) 1313 if (rate > 110)
1308 have_higher_than_11mbit = true; 1314 have_higher_than_11mbit = true;
1309 1315
1310 for (j = 0; j < sband->n_bitrates; j++) { 1316 for (j = 0; j < sband->n_bitrates; j++) {
1311 if (sband->bitrates[j].bitrate == rate) 1317 if (sband->bitrates[j].bitrate == rate) {
1312 rates |= BIT(j); 1318 rates |= BIT(j);
1313 if (elems.ext_supp_rates[i] & 0x80) 1319 if (is_basic)
1314 basic_rates |= BIT(j); 1320 basic_rates |= BIT(j);
1321 break;
1322 }
1315 } 1323 }
1316 } 1324 }
1317 1325
@@ -2414,7 +2422,6 @@ void ieee80211_sta_req_auth(struct ieee80211_sub_if_data *sdata,
2414int ieee80211_sta_set_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t len) 2422int ieee80211_sta_set_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t len)
2415{ 2423{
2416 struct ieee80211_if_sta *ifsta; 2424 struct ieee80211_if_sta *ifsta;
2417 int res;
2418 2425
2419 if (len > IEEE80211_MAX_SSID_LEN) 2426 if (len > IEEE80211_MAX_SSID_LEN)
2420 return -EINVAL; 2427 return -EINVAL;
@@ -2426,19 +2433,6 @@ int ieee80211_sta_set_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size
2426 memcpy(ifsta->ssid, ssid, len); 2433 memcpy(ifsta->ssid, ssid, len);
2427 ifsta->ssid_len = len; 2434 ifsta->ssid_len = len;
2428 ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET; 2435 ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
2429
2430 res = 0;
2431 /*
2432 * Hack! MLME code needs to be cleaned up to have different
2433 * entry points for configuration and internal selection change
2434 */
2435 if (netif_running(sdata->dev))
2436 res = ieee80211_if_config(sdata, IEEE80211_IFCC_SSID);
2437 if (res) {
2438 printk(KERN_DEBUG "%s: Failed to config new SSID to "
2439 "the low-level driver\n", sdata->dev->name);
2440 return res;
2441 }
2442 } 2436 }
2443 2437
2444 if (len) 2438 if (len)
diff --git a/net/mac80211/rc80211_minstrel.c b/net/mac80211/rc80211_minstrel.c
index c643e373fc50..2b3b490a6073 100644
--- a/net/mac80211/rc80211_minstrel.c
+++ b/net/mac80211/rc80211_minstrel.c
@@ -225,7 +225,7 @@ minstrel_get_next_sample(struct minstrel_sta_info *mi)
225 return sample_ndx; 225 return sample_ndx;
226} 226}
227 227
228void 228static void
229minstrel_get_rate(void *priv, struct ieee80211_sta *sta, 229minstrel_get_rate(void *priv, struct ieee80211_sta *sta,
230 void *priv_sta, struct ieee80211_tx_rate_control *txrc) 230 void *priv_sta, struct ieee80211_tx_rate_control *txrc)
231{ 231{
diff --git a/net/mac80211/scan.c b/net/mac80211/scan.c
index 7372d7abb8c0..f5c7c3371929 100644
--- a/net/mac80211/scan.c
+++ b/net/mac80211/scan.c
@@ -159,7 +159,7 @@ ieee80211_rx_mesh_bss_add(struct ieee80211_local *local, u8 *mesh_id, int mesh_i
159{ 159{
160 struct ieee80211_bss *bss; 160 struct ieee80211_bss *bss;
161 161
162 if (mesh_config_len != MESH_CFG_LEN) 162 if (mesh_config_len != IEEE80211_MESH_CONFIG_LEN)
163 return NULL; 163 return NULL;
164 164
165 bss = kzalloc(sizeof(*bss), GFP_ATOMIC); 165 bss = kzalloc(sizeof(*bss), GFP_ATOMIC);
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
index d6392af9cd20..0d81b2cfd1a6 100644
--- a/net/mac80211/tx.c
+++ b/net/mac80211/tx.c
@@ -698,7 +698,6 @@ ieee80211_tx_h_fragment(struct ieee80211_tx_data *tx)
698 left = payload_len - per_fragm; 698 left = payload_len - per_fragm;
699 for (i = 0; i < num_fragm - 1; i++) { 699 for (i = 0; i < num_fragm - 1; i++) {
700 struct ieee80211_hdr *fhdr; 700 struct ieee80211_hdr *fhdr;
701 struct ieee80211_tx_info *info;
702 size_t copylen; 701 size_t copylen;
703 702
704 if (left <= 0) 703 if (left <= 0)
diff --git a/net/mac80211/wext.c b/net/mac80211/wext.c
index 231cab57351f..63f36e9d1af8 100644
--- a/net/mac80211/wext.c
+++ b/net/mac80211/wext.c
@@ -407,13 +407,6 @@ static int ieee80211_ioctl_siwessid(struct net_device *dev,
407 return 0; 407 return 0;
408 } 408 }
409 409
410 if (sdata->vif.type == NL80211_IFTYPE_AP) {
411 memcpy(sdata->u.ap.ssid, ssid, len);
412 memset(sdata->u.ap.ssid + len, 0,
413 IEEE80211_MAX_SSID_LEN - len);
414 sdata->u.ap.ssid_len = len;
415 return ieee80211_if_config(sdata, IEEE80211_IFCC_SSID);
416 }
417 return -EOPNOTSUPP; 410 return -EOPNOTSUPP;
418} 411}
419 412
@@ -437,15 +430,6 @@ static int ieee80211_ioctl_giwessid(struct net_device *dev,
437 return res; 430 return res;
438 } 431 }
439 432
440 if (sdata->vif.type == NL80211_IFTYPE_AP) {
441 len = sdata->u.ap.ssid_len;
442 if (len > IW_ESSID_MAX_SIZE)
443 len = IW_ESSID_MAX_SIZE;
444 memcpy(ssid, sdata->u.ap.ssid, len);
445 data->length = len;
446 data->flags = 1;
447 return 0;
448 }
449 return -EOPNOTSUPP; 433 return -EOPNOTSUPP;
450} 434}
451 435
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 5e1d658a8b5a..e3e1494e769a 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -58,6 +58,7 @@ static struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] __read_mostly = {
58 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, 58 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
59 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, 59 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
60 .len = BUS_ID_SIZE-1 }, 60 .len = BUS_ID_SIZE-1 },
61 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
61 62
62 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, 63 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
63 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, 64 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
@@ -95,6 +96,8 @@ static struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] __read_mostly = {
95 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, 96 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
96 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, 97 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
97 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, 98 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
99 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
100 .len = NL80211_MAX_SUPP_RATES },
98 101
99 [NL80211_ATTR_MESH_PARAMS] = { .type = NLA_NESTED }, 102 [NL80211_ATTR_MESH_PARAMS] = { .type = NLA_NESTED },
100 103
@@ -284,20 +287,76 @@ static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
284 return -ENOBUFS; 287 return -ENOBUFS;
285} 288}
286 289
290static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
291 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
292 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
293 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
294 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
295 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
296};
297
298static int parse_txq_params(struct nlattr *tb[],
299 struct ieee80211_txq_params *txq_params)
300{
301 if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] ||
302 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
303 !tb[NL80211_TXQ_ATTR_AIFS])
304 return -EINVAL;
305
306 txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]);
307 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
308 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
309 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
310 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
311
312 return 0;
313}
314
287static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) 315static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
288{ 316{
289 struct cfg80211_registered_device *rdev; 317 struct cfg80211_registered_device *rdev;
290 int result; 318 int result = 0, rem_txq_params = 0;
291 319 struct nlattr *nl_txq_params;
292 if (!info->attrs[NL80211_ATTR_WIPHY_NAME])
293 return -EINVAL;
294 320
295 rdev = cfg80211_get_dev_from_info(info); 321 rdev = cfg80211_get_dev_from_info(info);
296 if (IS_ERR(rdev)) 322 if (IS_ERR(rdev))
297 return PTR_ERR(rdev); 323 return PTR_ERR(rdev);
298 324
299 result = cfg80211_dev_rename(rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); 325 if (info->attrs[NL80211_ATTR_WIPHY_NAME]) {
326 result = cfg80211_dev_rename(
327 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
328 if (result)
329 goto bad_res;
330 }
331
332 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
333 struct ieee80211_txq_params txq_params;
334 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
335
336 if (!rdev->ops->set_txq_params) {
337 result = -EOPNOTSUPP;
338 goto bad_res;
339 }
300 340
341 nla_for_each_nested(nl_txq_params,
342 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
343 rem_txq_params) {
344 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
345 nla_data(nl_txq_params),
346 nla_len(nl_txq_params),
347 txq_params_policy);
348 result = parse_txq_params(tb, &txq_params);
349 if (result)
350 goto bad_res;
351
352 result = rdev->ops->set_txq_params(&rdev->wiphy,
353 &txq_params);
354 if (result)
355 goto bad_res;
356 }
357 }
358
359bad_res:
301 cfg80211_put_dev(rdev); 360 cfg80211_put_dev(rdev);
302 return result; 361 return result;
303} 362}
@@ -1613,6 +1672,12 @@ static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
1613 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) 1672 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
1614 params.use_short_slot_time = 1673 params.use_short_slot_time =
1615 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); 1674 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
1675 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
1676 params.basic_rates =
1677 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
1678 params.basic_rates_len =
1679 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
1680 }
1616 1681
1617 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 1682 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
1618 if (err) 1683 if (err)
diff --git a/net/wireless/reg.c b/net/wireless/reg.c
index 9dff716d1b02..4c7e39d466c4 100644
--- a/net/wireless/reg.c
+++ b/net/wireless/reg.c
@@ -42,16 +42,33 @@
42#include "core.h" 42#include "core.h"
43#include "reg.h" 43#include "reg.h"
44 44
45/* 45/**
46 * wiphy is set if this request's initiator is 46 * struct regulatory_request - receipt of last regulatory request
47 * REGDOM_SET_BY_COUNTRY_IE or _DRIVER 47 *
48 * @wiphy: this is set if this request's initiator is
49 * %REGDOM_SET_BY_COUNTRY_IE or %REGDOM_SET_BY_DRIVER. This
50 * can be used by the wireless core to deal with conflicts
51 * and potentially inform users of which devices specifically
52 * cased the conflicts.
53 * @initiator: indicates who sent this request, could be any of
54 * of those set in reg_set_by, %REGDOM_SET_BY_*
55 * @alpha2: the ISO / IEC 3166 alpha2 country code of the requested
56 * regulatory domain. We have a few special codes:
57 * 00 - World regulatory domain
58 * 99 - built by driver but a specific alpha2 cannot be determined
59 * 98 - result of an intersection between two regulatory domains
60 * @intersect: indicates whether the wireless core should intersect
61 * the requested regulatory domain with the presently set regulatory
62 * domain.
48 */ 63 */
49struct regulatory_request { 64struct regulatory_request {
50 struct wiphy *wiphy; 65 struct wiphy *wiphy;
51 enum reg_set_by initiator; 66 enum reg_set_by initiator;
52 char alpha2[2]; 67 char alpha2[2];
68 bool intersect;
53}; 69};
54 70
71/* Receipt of information from last regulatory request */
55static struct regulatory_request *last_request; 72static struct regulatory_request *last_request;
56 73
57/* To trigger userspace events */ 74/* To trigger userspace events */
@@ -321,7 +338,7 @@ static bool is_valid_reg_rule(const struct ieee80211_reg_rule *rule)
321 338
322 freq_diff = freq_range->end_freq_khz - freq_range->start_freq_khz; 339 freq_diff = freq_range->end_freq_khz - freq_range->start_freq_khz;
323 340
324 if (freq_range->max_bandwidth_khz > freq_diff) 341 if (freq_diff <= 0 || freq_range->max_bandwidth_khz > freq_diff)
325 return false; 342 return false;
326 343
327 return true; 344 return true;
@@ -359,6 +376,143 @@ static u32 freq_max_bandwidth(const struct ieee80211_freq_range *freq_range,
359 return 0; 376 return 0;
360} 377}
361 378
379/* Helper for regdom_intersect(), this does the real
380 * mathematical intersection fun */
381static int reg_rules_intersect(
382 const struct ieee80211_reg_rule *rule1,
383 const struct ieee80211_reg_rule *rule2,
384 struct ieee80211_reg_rule *intersected_rule)
385{
386 const struct ieee80211_freq_range *freq_range1, *freq_range2;
387 struct ieee80211_freq_range *freq_range;
388 const struct ieee80211_power_rule *power_rule1, *power_rule2;
389 struct ieee80211_power_rule *power_rule;
390 u32 freq_diff;
391
392 freq_range1 = &rule1->freq_range;
393 freq_range2 = &rule2->freq_range;
394 freq_range = &intersected_rule->freq_range;
395
396 power_rule1 = &rule1->power_rule;
397 power_rule2 = &rule2->power_rule;
398 power_rule = &intersected_rule->power_rule;
399
400 freq_range->start_freq_khz = max(freq_range1->start_freq_khz,
401 freq_range2->start_freq_khz);
402 freq_range->end_freq_khz = min(freq_range1->end_freq_khz,
403 freq_range2->end_freq_khz);
404 freq_range->max_bandwidth_khz = min(freq_range1->max_bandwidth_khz,
405 freq_range2->max_bandwidth_khz);
406
407 freq_diff = freq_range->end_freq_khz - freq_range->start_freq_khz;
408 if (freq_range->max_bandwidth_khz > freq_diff)
409 freq_range->max_bandwidth_khz = freq_diff;
410
411 power_rule->max_eirp = min(power_rule1->max_eirp,
412 power_rule2->max_eirp);
413 power_rule->max_antenna_gain = min(power_rule1->max_antenna_gain,
414 power_rule2->max_antenna_gain);
415
416 intersected_rule->flags = (rule1->flags | rule2->flags);
417
418 if (!is_valid_reg_rule(intersected_rule))
419 return -EINVAL;
420
421 return 0;
422}
423
424/**
425 * regdom_intersect - do the intersection between two regulatory domains
426 * @rd1: first regulatory domain
427 * @rd2: second regulatory domain
428 *
429 * Use this function to get the intersection between two regulatory domains.
430 * Once completed we will mark the alpha2 for the rd as intersected, "98",
431 * as no one single alpha2 can represent this regulatory domain.
432 *
433 * Returns a pointer to the regulatory domain structure which will hold the
434 * resulting intersection of rules between rd1 and rd2. We will
435 * kzalloc() this structure for you.
436 */
437static struct ieee80211_regdomain *regdom_intersect(
438 const struct ieee80211_regdomain *rd1,
439 const struct ieee80211_regdomain *rd2)
440{
441 int r, size_of_regd;
442 unsigned int x, y;
443 unsigned int num_rules = 0, rule_idx = 0;
444 const struct ieee80211_reg_rule *rule1, *rule2;
445 struct ieee80211_reg_rule *intersected_rule;
446 struct ieee80211_regdomain *rd;
447 /* This is just a dummy holder to help us count */
448 struct ieee80211_reg_rule irule;
449
450 /* Uses the stack temporarily for counter arithmetic */
451 intersected_rule = &irule;
452
453 memset(intersected_rule, 0, sizeof(struct ieee80211_reg_rule));
454
455 if (!rd1 || !rd2)
456 return NULL;
457
458 /* First we get a count of the rules we'll need, then we actually
459 * build them. This is to so we can malloc() and free() a
460 * regdomain once. The reason we use reg_rules_intersect() here
461 * is it will return -EINVAL if the rule computed makes no sense.
462 * All rules that do check out OK are valid. */
463
464 for (x = 0; x < rd1->n_reg_rules; x++) {
465 rule1 = &rd1->reg_rules[x];
466 for (y = 0; y < rd2->n_reg_rules; y++) {
467 rule2 = &rd2->reg_rules[y];
468 if (!reg_rules_intersect(rule1, rule2,
469 intersected_rule))
470 num_rules++;
471 memset(intersected_rule, 0,
472 sizeof(struct ieee80211_reg_rule));
473 }
474 }
475
476 if (!num_rules)
477 return NULL;
478
479 size_of_regd = sizeof(struct ieee80211_regdomain) +
480 ((num_rules + 1) * sizeof(struct ieee80211_reg_rule));
481
482 rd = kzalloc(size_of_regd, GFP_KERNEL);
483 if (!rd)
484 return NULL;
485
486 for (x = 0; x < rd1->n_reg_rules; x++) {
487 rule1 = &rd1->reg_rules[x];
488 for (y = 0; y < rd2->n_reg_rules; y++) {
489 rule2 = &rd2->reg_rules[y];
490 /* This time around instead of using the stack lets
491 * write to the target rule directly saving ourselves
492 * a memcpy() */
493 intersected_rule = &rd->reg_rules[rule_idx];
494 r = reg_rules_intersect(rule1, rule2,
495 intersected_rule);
496 /* No need to memset here the intersected rule here as
497 * we're not using the stack anymore */
498 if (r)
499 continue;
500 rule_idx++;
501 }
502 }
503
504 if (rule_idx != num_rules) {
505 kfree(rd);
506 return NULL;
507 }
508
509 rd->n_reg_rules = num_rules;
510 rd->alpha2[0] = '9';
511 rd->alpha2[1] = '8';
512
513 return rd;
514}
515
362/* XXX: add support for the rest of enum nl80211_reg_rule_flags, we may 516/* XXX: add support for the rest of enum nl80211_reg_rule_flags, we may
363 * want to just have the channel structure use these */ 517 * want to just have the channel structure use these */
364static u32 map_regdom_flags(u32 rd_flags) 518static u32 map_regdom_flags(u32 rd_flags)
@@ -468,6 +622,10 @@ void wiphy_update_regulatory(struct wiphy *wiphy, enum reg_set_by setby)
468 } 622 }
469} 623}
470 624
625/* Return value which can be used by ignore_request() to indicate
626 * it has been determined we should intersect two regulatory domains */
627#define REG_INTERSECT 1
628
471/* This has the logic which determines when a new request 629/* This has the logic which determines when a new request
472 * should be ignored. */ 630 * should be ignored. */
473static int ignore_request(struct wiphy *wiphy, enum reg_set_by set_by, 631static int ignore_request(struct wiphy *wiphy, enum reg_set_by set_by,
@@ -517,14 +675,8 @@ static int ignore_request(struct wiphy *wiphy, enum reg_set_by set_by,
517 return -EALREADY; 675 return -EALREADY;
518 return 0; 676 return 0;
519 case REGDOM_SET_BY_USER: 677 case REGDOM_SET_BY_USER:
520 /*
521 * If the user wants to override the AP's hint, we may
522 * need to follow both and use the intersection. For now,
523 * reject any such attempt (but we don't support country
524 * IEs right now anyway.)
525 */
526 if (last_request->initiator == REGDOM_SET_BY_COUNTRY_IE) 678 if (last_request->initiator == REGDOM_SET_BY_COUNTRY_IE)
527 return -EOPNOTSUPP; 679 return REG_INTERSECT;
528 return 0; 680 return 0;
529 } 681 }
530 682
@@ -536,10 +688,14 @@ int __regulatory_hint(struct wiphy *wiphy, enum reg_set_by set_by,
536 const char *alpha2) 688 const char *alpha2)
537{ 689{
538 struct regulatory_request *request; 690 struct regulatory_request *request;
691 bool intersect = false;
539 int r = 0; 692 int r = 0;
540 693
541 r = ignore_request(wiphy, set_by, alpha2); 694 r = ignore_request(wiphy, set_by, alpha2);
542 if (r) 695
696 if (r == REG_INTERSECT)
697 intersect = true;
698 else if (r)
543 return r; 699 return r;
544 700
545 switch (set_by) { 701 switch (set_by) {
@@ -556,6 +712,7 @@ int __regulatory_hint(struct wiphy *wiphy, enum reg_set_by set_by,
556 request->alpha2[1] = alpha2[1]; 712 request->alpha2[1] = alpha2[1];
557 request->initiator = set_by; 713 request->initiator = set_by;
558 request->wiphy = wiphy; 714 request->wiphy = wiphy;
715 request->intersect = intersect;
559 716
560 kfree(last_request); 717 kfree(last_request);
561 last_request = request; 718 last_request = request;
@@ -638,7 +795,7 @@ static void print_regdomain(const struct ieee80211_regdomain *rd)
638 print_rd_rules(rd); 795 print_rd_rules(rd);
639} 796}
640 797
641void print_regdomain_info(const struct ieee80211_regdomain *rd) 798static void print_regdomain_info(const struct ieee80211_regdomain *rd)
642{ 799{
643 printk(KERN_INFO "cfg80211: Regulatory domain: %c%c\n", 800 printk(KERN_INFO "cfg80211: Regulatory domain: %c%c\n",
644 rd->alpha2[0], rd->alpha2[1]); 801 rd->alpha2[0], rd->alpha2[1]);
@@ -648,6 +805,7 @@ void print_regdomain_info(const struct ieee80211_regdomain *rd)
648/* Takes ownership of rd only if it doesn't fail */ 805/* Takes ownership of rd only if it doesn't fail */
649static int __set_regdom(const struct ieee80211_regdomain *rd) 806static int __set_regdom(const struct ieee80211_regdomain *rd)
650{ 807{
808 const struct ieee80211_regdomain *intersected_rd = NULL;
651 /* Some basic sanity checks first */ 809 /* Some basic sanity checks first */
652 810
653 if (is_world_regdom(rd->alpha2)) { 811 if (is_world_regdom(rd->alpha2)) {
@@ -697,6 +855,14 @@ static int __set_regdom(const struct ieee80211_regdomain *rd)
697 return -EOPNOTSUPP; 855 return -EOPNOTSUPP;
698 } 856 }
699 857
858 if (unlikely(last_request->intersect)) {
859 intersected_rd = regdom_intersect(rd, cfg80211_regdomain);
860 if (!intersected_rd)
861 return -EINVAL;
862 kfree(rd);
863 rd = intersected_rd;
864 }
865
700 /* Tada! */ 866 /* Tada! */
701 cfg80211_regdomain = rd; 867 cfg80211_regdomain = rd;
702 868
diff --git a/net/wireless/util.c b/net/wireless/util.c
index f54424693a38..e76cc28b0345 100644
--- a/net/wireless/util.c
+++ b/net/wireless/util.c
@@ -7,6 +7,25 @@
7#include <asm/bitops.h> 7#include <asm/bitops.h>
8#include "core.h" 8#include "core.h"
9 9
10struct ieee80211_rate *
11ieee80211_get_response_rate(struct ieee80211_supported_band *sband,
12 u64 basic_rates, int bitrate)
13{
14 struct ieee80211_rate *result = &sband->bitrates[0];
15 int i;
16
17 for (i = 0; i < sband->n_bitrates; i++) {
18 if (!(basic_rates & BIT(i)))
19 continue;
20 if (sband->bitrates[i].bitrate > bitrate)
21 continue;
22 result = &sband->bitrates[i];
23 }
24
25 return result;
26}
27EXPORT_SYMBOL(ieee80211_get_response_rate);
28
10int ieee80211_channel_to_frequency(int chan) 29int ieee80211_channel_to_frequency(int chan)
11{ 30{
12 if (chan < 14) 31 if (chan < 14)