aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2009-11-09 14:17:24 -0500
committerDavid S. Miller <davem@davemloft.net>2009-11-09 14:17:24 -0500
commitf6d773cd4f3c18c40ab25a5cb92453756237840e (patch)
tree5631a6ea4495ae2eb5058fb63b25dea3b197d61b /drivers
parentd0e1e88d6e7dbd8e1661cb6a058ca30f54ee39e4 (diff)
parentbcb628d579a61d0ab0cac4c6cc8a403de5254920 (diff)
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-next-2.6
Diffstat (limited to 'drivers')
-rw-r--r--drivers/net/wireless/Kconfig140
-rw-r--r--drivers/net/wireless/Makefile10
-rw-r--r--drivers/net/wireless/ath/Kconfig1
-rw-r--r--drivers/net/wireless/ath/ar9170/Kconfig2
-rw-r--r--drivers/net/wireless/ath/ath5k/Kconfig2
-rw-r--r--drivers/net/wireless/ath/ath5k/led.c2
-rw-r--r--drivers/net/wireless/ath/ath9k/Kconfig2
-rw-r--r--drivers/net/wireless/ath/ath9k/ahb.c10
-rw-r--r--drivers/net/wireless/ath/ath9k/calib.c2
-rw-r--r--drivers/net/wireless/ath/ath9k/eeprom_4k.c4
-rw-r--r--drivers/net/wireless/ath/ath9k/hw.c669
-rw-r--r--drivers/net/wireless/ath/ath9k/hw.h22
-rw-r--r--drivers/net/wireless/ath/ath9k/initvals.h29
-rw-r--r--drivers/net/wireless/ath/ath9k/main.c58
-rw-r--r--drivers/net/wireless/ath/ath9k/pci.c10
-rw-r--r--drivers/net/wireless/ath/ath9k/phy.c1100
-rw-r--r--drivers/net/wireless/ath/ath9k/phy.h40
-rw-r--r--drivers/net/wireless/ath/ath9k/recv.c3
-rw-r--r--drivers/net/wireless/ath/ath9k/reg.h3
-rw-r--r--drivers/net/wireless/ath/ath9k/xmit.c3
-rw-r--r--drivers/net/wireless/b43/Kconfig2
-rw-r--r--drivers/net/wireless/b43/b43.h2
-rw-r--r--drivers/net/wireless/b43/main.c2
-rw-r--r--drivers/net/wireless/b43/phy_lp.c783
-rw-r--r--drivers/net/wireless/b43/phy_lp.h11
-rw-r--r--drivers/net/wireless/b43/xmit.c1
-rw-r--r--drivers/net/wireless/b43legacy/Kconfig2
-rw-r--r--drivers/net/wireless/b43legacy/b43legacy.h2
-rw-r--r--drivers/net/wireless/b43legacy/dma.c17
-rw-r--r--drivers/net/wireless/b43legacy/main.c2
-rw-r--r--drivers/net/wireless/b43legacy/xmit.c1
-rw-r--r--drivers/net/wireless/hostap/Kconfig1
-rw-r--r--drivers/net/wireless/ipw2x00/Kconfig6
-rw-r--r--drivers/net/wireless/iwlwifi/Kconfig2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-1000.c4
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945-rs.c102
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945.h35
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-5000.c12
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-6000.c25
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-rs.c13
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn.c143
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-calib.c1
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-commands.h161
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-core.c236
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-core.h7
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-dev.h1
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-eeprom.c11
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-hcmd.c2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-scan.c1
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-sta.c69
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-sta.h1
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-tx.c13
-rw-r--r--drivers/net/wireless/iwlwifi/iwl3945-base.c15
-rw-r--r--drivers/net/wireless/iwmc3200wifi/Kconfig2
-rw-r--r--drivers/net/wireless/libertas/Kconfig2
-rw-r--r--drivers/net/wireless/libertas/if_spi.c136
-rw-r--r--drivers/net/wireless/mac80211_hwsim.c67
-rw-r--r--drivers/net/wireless/mwl8k.c1258
-rw-r--r--drivers/net/wireless/orinoco/Kconfig2
-rw-r--r--drivers/net/wireless/p54/Kconfig2
-rw-r--r--drivers/net/wireless/p54/eeprom.c31
-rw-r--r--drivers/net/wireless/rt2x00/Kconfig18
-rw-r--r--drivers/net/wireless/rt2x00/Makefile1
-rw-r--r--drivers/net/wireless/rt2x00/rt2800.h1816
-rw-r--r--drivers/net/wireless/rt2x00/rt2800lib.c1817
-rw-r--r--drivers/net/wireless/rt2x00/rt2800lib.h134
-rw-r--r--drivers/net/wireless/rt2x00/rt2800pci.c1908
-rw-r--r--drivers/net/wireless/rt2x00/rt2800pci.h1780
-rw-r--r--drivers/net/wireless/rt2x00/rt2800usb.c1828
-rw-r--r--drivers/net/wireless/rt2x00/rt2800usb.h1818
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00.h43
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00leds.h4
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00pci.h24
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00usb.c2
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00usb.h17
-rw-r--r--drivers/net/wireless/rtl818x/rtl8187.h1
-rw-r--r--drivers/net/wireless/rtl818x/rtl8187_dev.c13
-rw-r--r--drivers/net/wireless/wl12xx/Kconfig3
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_main.c3
-rw-r--r--drivers/net/wireless/wl12xx/wl1271.h3
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_acx.c2
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_boot.c5
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_cmd.c99
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_cmd.h3
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_conf.h8
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_event.c53
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_event.h7
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_init.c7
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_main.c19
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_rx.c2
-rw-r--r--drivers/net/wireless/zd1211rw/Kconfig2
-rw-r--r--drivers/staging/Kconfig8
-rw-r--r--drivers/staging/Makefile5
-rw-r--r--drivers/staging/arlan/Kconfig15
-rw-r--r--drivers/staging/arlan/Makefile3
-rw-r--r--drivers/staging/arlan/TODO7
-rw-r--r--drivers/staging/arlan/arlan-main.c (renamed from drivers/net/wireless/arlan-main.c)0
-rw-r--r--drivers/staging/arlan/arlan-proc.c (renamed from drivers/net/wireless/arlan-proc.c)0
-rw-r--r--drivers/staging/arlan/arlan.h (renamed from drivers/net/wireless/arlan.h)0
-rw-r--r--drivers/staging/netwave/Kconfig11
-rw-r--r--drivers/staging/netwave/Makefile1
-rw-r--r--drivers/staging/netwave/TODO7
-rw-r--r--drivers/staging/netwave/netwave_cs.c (renamed from drivers/net/wireless/netwave_cs.c)0
-rw-r--r--drivers/staging/strip/Kconfig22
-rw-r--r--drivers/staging/strip/Makefile1
-rw-r--r--drivers/staging/strip/TODO7
-rw-r--r--drivers/staging/strip/strip.c (renamed from drivers/net/wireless/strip.c)0
-rw-r--r--drivers/staging/wavelan/Kconfig38
-rw-r--r--drivers/staging/wavelan/Makefile2
-rw-r--r--drivers/staging/wavelan/TODO7
-rw-r--r--drivers/staging/wavelan/i82586.h (renamed from drivers/net/wireless/i82586.h)0
-rw-r--r--drivers/staging/wavelan/i82593.h (renamed from drivers/net/wireless/i82593.h)0
-rw-r--r--drivers/staging/wavelan/wavelan.c (renamed from drivers/net/wireless/wavelan.c)0
-rw-r--r--drivers/staging/wavelan/wavelan.h (renamed from drivers/net/wireless/wavelan.h)0
-rw-r--r--drivers/staging/wavelan/wavelan.p.h (renamed from drivers/net/wireless/wavelan.p.h)0
-rw-r--r--drivers/staging/wavelan/wavelan_cs.c (renamed from drivers/net/wireless/wavelan_cs.c)0
-rw-r--r--drivers/staging/wavelan/wavelan_cs.h (renamed from drivers/net/wireless/wavelan_cs.h)0
-rw-r--r--drivers/staging/wavelan/wavelan_cs.p.h (renamed from drivers/net/wireless/wavelan_cs.p.h)0
118 files changed, 7730 insertions, 9142 deletions
diff --git a/drivers/net/wireless/Kconfig b/drivers/net/wireless/Kconfig
index 85f8bf4112c1..56dd6650c97a 100644
--- a/drivers/net/wireless/Kconfig
+++ b/drivers/net/wireless/Kconfig
@@ -16,118 +16,9 @@ menuconfig WLAN
16 16
17if WLAN 17if WLAN
18 18
19menuconfig WLAN_PRE80211
20 bool "Wireless LAN (pre-802.11)"
21 depends on NETDEVICES
22 ---help---
23 Say Y if you have any pre-802.11 wireless LAN hardware.
24
25 This option does not affect the kernel build, it only
26 lets you choose drivers.
27
28config STRIP
29 tristate "STRIP (Metricom starmode radio IP)"
30 depends on INET && WLAN_PRE80211
31 select WIRELESS_EXT
32 ---help---
33 Say Y if you have a Metricom radio and intend to use Starmode Radio
34 IP. STRIP is a radio protocol developed for the MosquitoNet project
35 to send Internet traffic using Metricom radios. Metricom radios are
36 small, battery powered, 100kbit/sec packet radio transceivers, about
37 the size and weight of a cellular telephone. (You may also have heard
38 them called "Metricom modems" but we avoid the term "modem" because
39 it misleads many people into thinking that you can plug a Metricom
40 modem into a phone line and use it as a modem.)
41
42 You can use STRIP on any Linux machine with a serial port, although
43 it is obviously most useful for people with laptop computers. If you
44 think you might get a Metricom radio in the future, there is no harm
45 in saying Y to STRIP now, except that it makes the kernel a bit
46 bigger.
47
48 To compile this as a module, choose M here: the module will be
49 called strip.
50
51config ARLAN
52 tristate "Aironet Arlan 655 & IC2200 DS support"
53 depends on ISA && !64BIT && WLAN_PRE80211
54 select WIRELESS_EXT
55 ---help---
56 Aironet makes Arlan, a class of wireless LAN adapters. These use the
57 www.Telxon.com chip, which is also used on several similar cards.
58 This driver is tested on the 655 and IC2200 series cards. Look at
59 <http://www.ylenurme.ee/~elmer/655/> for the latest information.
60
61 The driver is built as two modules, arlan and arlan-proc. The latter
62 is the /proc interface and is not needed most of time.
63
64 On some computers the card ends up in non-valid state after some
65 time. Use a ping-reset script to clear it.
66
67config WAVELAN
68 tristate "AT&T/Lucent old WaveLAN & DEC RoamAbout DS ISA support"
69 depends on ISA && WLAN_PRE80211
70 select WIRELESS_EXT
71 select WEXT_SPY
72 select WEXT_PRIV
73 ---help---
74 The Lucent WaveLAN (formerly NCR and AT&T; or DEC RoamAbout DS) is
75 a Radio LAN (wireless Ethernet-like Local Area Network) using the
76 radio frequencies 900 MHz and 2.4 GHz.
77
78 If you want to use an ISA WaveLAN card under Linux, say Y and read
79 the Ethernet-HOWTO, available from
80 <http://www.tldp.org/docs.html#howto>. Some more specific
81 information is contained in
82 <file:Documentation/networking/wavelan.txt> and in the source code
83 <file:drivers/net/wireless/wavelan.p.h>.
84
85 You will also need the wireless tools package available from
86 <http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/Tools.html>.
87 Please read the man pages contained therein.
88
89 To compile this driver as a module, choose M here: the module will be
90 called wavelan.
91
92config PCMCIA_WAVELAN
93 tristate "AT&T/Lucent old WaveLAN Pcmcia wireless support"
94 depends on PCMCIA && WLAN_PRE80211
95 select WIRELESS_EXT
96 select WEXT_SPY
97 select WEXT_PRIV
98 help
99 Say Y here if you intend to attach an AT&T/Lucent Wavelan PCMCIA
100 (PC-card) wireless Ethernet networking card to your computer. This
101 driver is for the non-IEEE-802.11 Wavelan cards.
102
103 To compile this driver as a module, choose M here: the module will be
104 called wavelan_cs. If unsure, say N.
105
106config PCMCIA_NETWAVE
107 tristate "Xircom Netwave AirSurfer Pcmcia wireless support"
108 depends on PCMCIA && WLAN_PRE80211
109 select WIRELESS_EXT
110 select WEXT_PRIV
111 help
112 Say Y here if you intend to attach this type of PCMCIA (PC-card)
113 wireless Ethernet networking card to your computer.
114
115 To compile this driver as a module, choose M here: the module will be
116 called netwave_cs. If unsure, say N.
117
118
119menuconfig WLAN_80211
120 bool "Wireless LAN (IEEE 802.11)"
121 depends on NETDEVICES
122 ---help---
123 Say Y if you have any 802.11 wireless LAN hardware.
124
125 This option does not affect the kernel build, it only
126 lets you choose drivers.
127
128config PCMCIA_RAYCS 19config PCMCIA_RAYCS
129 tristate "Aviator/Raytheon 2.4GHz wireless support" 20 tristate "Aviator/Raytheon 2.4GHz wireless support"
130 depends on PCMCIA && WLAN_80211 21 depends on PCMCIA
131 select WIRELESS_EXT 22 select WIRELESS_EXT
132 select WEXT_SPY 23 select WEXT_SPY
133 select WEXT_PRIV 24 select WEXT_PRIV
@@ -142,7 +33,7 @@ config PCMCIA_RAYCS
142 33
143config LIBERTAS_THINFIRM 34config LIBERTAS_THINFIRM
144 tristate "Marvell 8xxx Libertas WLAN driver support with thin firmware" 35 tristate "Marvell 8xxx Libertas WLAN driver support with thin firmware"
145 depends on WLAN_80211 && MAC80211 36 depends on MAC80211
146 select FW_LOADER 37 select FW_LOADER
147 ---help--- 38 ---help---
148 A library for Marvell Libertas 8xxx devices using thinfirm. 39 A library for Marvell Libertas 8xxx devices using thinfirm.
@@ -155,7 +46,7 @@ config LIBERTAS_THINFIRM_USB
155 46
156config AIRO 47config AIRO
157 tristate "Cisco/Aironet 34X/35X/4500/4800 ISA and PCI cards" 48 tristate "Cisco/Aironet 34X/35X/4500/4800 ISA and PCI cards"
158 depends on ISA_DMA_API && WLAN_80211 && (PCI || BROKEN) 49 depends on ISA_DMA_API && (PCI || BROKEN)
159 select WIRELESS_EXT 50 select WIRELESS_EXT
160 select CRYPTO 51 select CRYPTO
161 select WEXT_SPY 52 select WEXT_SPY
@@ -175,7 +66,7 @@ config AIRO
175 66
176config ATMEL 67config ATMEL
177 tristate "Atmel at76c50x chipset 802.11b support" 68 tristate "Atmel at76c50x chipset 802.11b support"
178 depends on (PCI || PCMCIA) && WLAN_80211 69 depends on (PCI || PCMCIA)
179 select WIRELESS_EXT 70 select WIRELESS_EXT
180 select WEXT_PRIV 71 select WEXT_PRIV
181 select FW_LOADER 72 select FW_LOADER
@@ -210,7 +101,7 @@ config PCMCIA_ATMEL
210 101
211config AT76C50X_USB 102config AT76C50X_USB
212 tristate "Atmel at76c503/at76c505/at76c505a USB cards" 103 tristate "Atmel at76c503/at76c505/at76c505a USB cards"
213 depends on MAC80211 && WLAN_80211 && USB 104 depends on MAC80211 && USB
214 select FW_LOADER 105 select FW_LOADER
215 ---help--- 106 ---help---
216 Enable support for USB Wireless devices using Atmel at76c503, 107 Enable support for USB Wireless devices using Atmel at76c503,
@@ -218,8 +109,9 @@ config AT76C50X_USB
218 109
219config AIRO_CS 110config AIRO_CS
220 tristate "Cisco/Aironet 34X/35X/4500/4800 PCMCIA cards" 111 tristate "Cisco/Aironet 34X/35X/4500/4800 PCMCIA cards"
221 depends on PCMCIA && (BROKEN || !M32R) && WLAN_80211 112 depends on PCMCIA && (BROKEN || !M32R)
222 select WIRELESS_EXT 113 select WIRELESS_EXT
114 select WEXT_SPY
223 select CRYPTO 115 select CRYPTO
224 select CRYPTO_AES 116 select CRYPTO_AES
225 ---help--- 117 ---help---
@@ -238,7 +130,7 @@ config AIRO_CS
238 130
239config PCMCIA_WL3501 131config PCMCIA_WL3501
240 tristate "Planet WL3501 PCMCIA cards" 132 tristate "Planet WL3501 PCMCIA cards"
241 depends on EXPERIMENTAL && PCMCIA && WLAN_80211 133 depends on EXPERIMENTAL && PCMCIA
242 select WIRELESS_EXT 134 select WIRELESS_EXT
243 select WEXT_SPY 135 select WEXT_SPY
244 help 136 help
@@ -248,7 +140,7 @@ config PCMCIA_WL3501
248 140
249config PRISM54 141config PRISM54
250 tristate 'Intersil Prism GT/Duette/Indigo PCI/Cardbus (DEPRECATED)' 142 tristate 'Intersil Prism GT/Duette/Indigo PCI/Cardbus (DEPRECATED)'
251 depends on PCI && EXPERIMENTAL && WLAN_80211 143 depends on PCI && EXPERIMENTAL
252 select WIRELESS_EXT 144 select WIRELESS_EXT
253 select WEXT_SPY 145 select WEXT_SPY
254 select WEXT_PRIV 146 select WEXT_PRIV
@@ -272,7 +164,7 @@ config PRISM54
272 164
273config USB_ZD1201 165config USB_ZD1201
274 tristate "USB ZD1201 based Wireless device support" 166 tristate "USB ZD1201 based Wireless device support"
275 depends on USB && WLAN_80211 167 depends on USB
276 select WIRELESS_EXT 168 select WIRELESS_EXT
277 select WEXT_PRIV 169 select WEXT_PRIV
278 select FW_LOADER 170 select FW_LOADER
@@ -291,7 +183,7 @@ config USB_ZD1201
291 183
292config USB_NET_RNDIS_WLAN 184config USB_NET_RNDIS_WLAN
293 tristate "Wireless RNDIS USB support" 185 tristate "Wireless RNDIS USB support"
294 depends on USB && WLAN_80211 && EXPERIMENTAL 186 depends on USB && EXPERIMENTAL
295 depends on CFG80211 187 depends on CFG80211
296 select USB_USBNET 188 select USB_USBNET
297 select USB_NET_CDCETHER 189 select USB_NET_CDCETHER
@@ -319,7 +211,7 @@ config USB_NET_RNDIS_WLAN
319 211
320config RTL8180 212config RTL8180
321 tristate "Realtek 8180/8185 PCI support" 213 tristate "Realtek 8180/8185 PCI support"
322 depends on MAC80211 && PCI && WLAN_80211 && EXPERIMENTAL 214 depends on MAC80211 && PCI && EXPERIMENTAL
323 select EEPROM_93CX6 215 select EEPROM_93CX6
324 ---help--- 216 ---help---
325 This is a driver for RTL8180 and RTL8185 based cards. 217 This is a driver for RTL8180 and RTL8185 based cards.
@@ -375,7 +267,7 @@ config RTL8180
375 267
376config RTL8187 268config RTL8187
377 tristate "Realtek 8187 and 8187B USB support" 269 tristate "Realtek 8187 and 8187B USB support"
378 depends on MAC80211 && USB && WLAN_80211 270 depends on MAC80211 && USB
379 select EEPROM_93CX6 271 select EEPROM_93CX6
380 ---help--- 272 ---help---
381 This is a driver for RTL8187 and RTL8187B based cards. 273 This is a driver for RTL8187 and RTL8187B based cards.
@@ -404,7 +296,7 @@ config RTL8187_LEDS
404 296
405config ADM8211 297config ADM8211
406 tristate "ADMtek ADM8211 support" 298 tristate "ADMtek ADM8211 support"
407 depends on MAC80211 && PCI && WLAN_80211 && EXPERIMENTAL 299 depends on MAC80211 && PCI && EXPERIMENTAL
408 select CRC32 300 select CRC32
409 select EEPROM_93CX6 301 select EEPROM_93CX6
410 ---help--- 302 ---help---
@@ -431,7 +323,7 @@ config ADM8211
431 323
432config MAC80211_HWSIM 324config MAC80211_HWSIM
433 tristate "Simulated radio testing tool for mac80211" 325 tristate "Simulated radio testing tool for mac80211"
434 depends on MAC80211 && WLAN_80211 326 depends on MAC80211
435 ---help--- 327 ---help---
436 This driver is a developer testing tool that can be used to test 328 This driver is a developer testing tool that can be used to test
437 IEEE 802.11 networking stack (mac80211) functionality. This is not 329 IEEE 802.11 networking stack (mac80211) functionality. This is not
@@ -444,7 +336,7 @@ config MAC80211_HWSIM
444 336
445config MWL8K 337config MWL8K
446 tristate "Marvell 88W8xxx PCI/PCIe Wireless support" 338 tristate "Marvell 88W8xxx PCI/PCIe Wireless support"
447 depends on MAC80211 && PCI && WLAN_80211 && EXPERIMENTAL 339 depends on MAC80211 && PCI && EXPERIMENTAL
448 ---help--- 340 ---help---
449 This driver supports Marvell TOPDOG 802.11 wireless cards. 341 This driver supports Marvell TOPDOG 802.11 wireless cards.
450 342
diff --git a/drivers/net/wireless/Makefile b/drivers/net/wireless/Makefile
index 7a4647e78fd3..5d4ce4d2b32b 100644
--- a/drivers/net/wireless/Makefile
+++ b/drivers/net/wireless/Makefile
@@ -5,16 +5,6 @@
5obj-$(CONFIG_IPW2100) += ipw2x00/ 5obj-$(CONFIG_IPW2100) += ipw2x00/
6obj-$(CONFIG_IPW2200) += ipw2x00/ 6obj-$(CONFIG_IPW2200) += ipw2x00/
7 7
8obj-$(CONFIG_STRIP) += strip.o
9obj-$(CONFIG_ARLAN) += arlan.o
10
11arlan-objs := arlan-main.o arlan-proc.o
12
13# Obsolete cards
14obj-$(CONFIG_WAVELAN) += wavelan.o
15obj-$(CONFIG_PCMCIA_NETWAVE) += netwave_cs.o
16obj-$(CONFIG_PCMCIA_WAVELAN) += wavelan_cs.o
17
18obj-$(CONFIG_HERMES) += orinoco/ 8obj-$(CONFIG_HERMES) += orinoco/
19 9
20obj-$(CONFIG_AIRO) += airo.o 10obj-$(CONFIG_AIRO) += airo.o
diff --git a/drivers/net/wireless/ath/Kconfig b/drivers/net/wireless/ath/Kconfig
index 6ce86cb37654..4e7a7fd695c8 100644
--- a/drivers/net/wireless/ath/Kconfig
+++ b/drivers/net/wireless/ath/Kconfig
@@ -1,6 +1,5 @@
1menuconfig ATH_COMMON 1menuconfig ATH_COMMON
2 tristate "Atheros Wireless Cards" 2 tristate "Atheros Wireless Cards"
3 depends on WLAN_80211
4 depends on CFG80211 3 depends on CFG80211
5 ---help--- 4 ---help---
6 This will enable the support for the Atheros wireless drivers. 5 This will enable the support for the Atheros wireless drivers.
diff --git a/drivers/net/wireless/ath/ar9170/Kconfig b/drivers/net/wireless/ath/ar9170/Kconfig
index 05918f1e685a..d7a4799d20fb 100644
--- a/drivers/net/wireless/ath/ar9170/Kconfig
+++ b/drivers/net/wireless/ath/ar9170/Kconfig
@@ -1,6 +1,6 @@
1config AR9170_USB 1config AR9170_USB
2 tristate "Atheros AR9170 802.11n USB support" 2 tristate "Atheros AR9170 802.11n USB support"
3 depends on USB && MAC80211 && WLAN_80211 3 depends on USB && MAC80211
4 select FW_LOADER 4 select FW_LOADER
5 help 5 help
6 This is a driver for the Atheros "otus" 802.11n USB devices. 6 This is a driver for the Atheros "otus" 802.11n USB devices.
diff --git a/drivers/net/wireless/ath/ath5k/Kconfig b/drivers/net/wireless/ath/ath5k/Kconfig
index 06d006675d7d..eb83b7b4d0e3 100644
--- a/drivers/net/wireless/ath/ath5k/Kconfig
+++ b/drivers/net/wireless/ath/ath5k/Kconfig
@@ -1,6 +1,6 @@
1config ATH5K 1config ATH5K
2 tristate "Atheros 5xxx wireless cards support" 2 tristate "Atheros 5xxx wireless cards support"
3 depends on PCI && MAC80211 && WLAN_80211 3 depends on PCI && MAC80211
4 select MAC80211_LEDS 4 select MAC80211_LEDS
5 select LEDS_CLASS 5 select LEDS_CLASS
6 select NEW_LEDS 6 select NEW_LEDS
diff --git a/drivers/net/wireless/ath/ath5k/led.c b/drivers/net/wireless/ath/ath5k/led.c
index b767c3b67b24..7ce98bd7c749 100644
--- a/drivers/net/wireless/ath/ath5k/led.c
+++ b/drivers/net/wireless/ath/ath5k/led.c
@@ -59,6 +59,8 @@ static const struct pci_device_id ath5k_led_devices[] = {
59 { ATH_SDEVICE(PCI_VENDOR_ID_COMPAQ, PCI_ANY_ID), ATH_LED(1, 1) }, 59 { ATH_SDEVICE(PCI_VENDOR_ID_COMPAQ, PCI_ANY_ID), ATH_LED(1, 1) },
60 /* Acer Aspire One A150 (maximlevitsky@gmail.com) */ 60 /* Acer Aspire One A150 (maximlevitsky@gmail.com) */
61 { ATH_SDEVICE(PCI_VENDOR_ID_FOXCONN, 0xe008), ATH_LED(3, 0) }, 61 { ATH_SDEVICE(PCI_VENDOR_ID_FOXCONN, 0xe008), ATH_LED(3, 0) },
62 /* Acer Aspire One AO531h AO751h (keng-yu.lin@canonical.com) */
63 { ATH_SDEVICE(PCI_VENDOR_ID_FOXCONN, 0xe00d), ATH_LED(3, 0) },
62 /* Acer Ferrari 5000 (russ.dill@gmail.com) */ 64 /* Acer Ferrari 5000 (russ.dill@gmail.com) */
63 { ATH_SDEVICE(PCI_VENDOR_ID_AMBIT, 0x0422), ATH_LED(1, 1) }, 65 { ATH_SDEVICE(PCI_VENDOR_ID_AMBIT, 0x0422), ATH_LED(1, 1) },
64 /* E-machines E510 (tuliom@gmail.com) */ 66 /* E-machines E510 (tuliom@gmail.com) */
diff --git a/drivers/net/wireless/ath/ath9k/Kconfig b/drivers/net/wireless/ath/ath9k/Kconfig
index 99ce066392a7..b735fb399fb1 100644
--- a/drivers/net/wireless/ath/ath9k/Kconfig
+++ b/drivers/net/wireless/ath/ath9k/Kconfig
@@ -3,7 +3,7 @@ config ATH9K_HW
3 3
4config ATH9K 4config ATH9K
5 tristate "Atheros 802.11n wireless cards support" 5 tristate "Atheros 802.11n wireless cards support"
6 depends on PCI && MAC80211 && WLAN_80211 6 depends on PCI && MAC80211
7 select ATH9K_HW 7 select ATH9K_HW
8 select MAC80211_LEDS 8 select MAC80211_LEDS
9 select LEDS_CLASS 9 select LEDS_CLASS
diff --git a/drivers/net/wireless/ath/ath9k/ahb.c b/drivers/net/wireless/ath/ath9k/ahb.c
index 25531f231b67..329e6bc137ab 100644
--- a/drivers/net/wireless/ath/ath9k/ahb.c
+++ b/drivers/net/wireless/ath/ath9k/ahb.c
@@ -69,6 +69,7 @@ static int ath_ahb_probe(struct platform_device *pdev)
69 int irq; 69 int irq;
70 int ret = 0; 70 int ret = 0;
71 struct ath_hw *ah; 71 struct ath_hw *ah;
72 char hw_name[64];
72 73
73 if (!pdev->dev.platform_data) { 74 if (!pdev->dev.platform_data) {
74 dev_err(&pdev->dev, "no platform data specified\n"); 75 dev_err(&pdev->dev, "no platform data specified\n");
@@ -133,14 +134,11 @@ static int ath_ahb_probe(struct platform_device *pdev)
133 } 134 }
134 135
135 ah = sc->sc_ah; 136 ah = sc->sc_ah;
137 ath9k_hw_name(ah, hw_name, sizeof(hw_name));
136 printk(KERN_INFO 138 printk(KERN_INFO
137 "%s: Atheros AR%s MAC/BB Rev:%x, " 139 "%s: %s mem=0x%lx, irq=%d\n",
138 "AR%s RF Rev:%x, mem=0x%lx, irq=%d\n",
139 wiphy_name(hw->wiphy), 140 wiphy_name(hw->wiphy),
140 ath_mac_bb_name(ah->hw_version.macVersion), 141 hw_name,
141 ah->hw_version.macRev,
142 ath_rf_name((ah->hw_version.analog5GhzRev & AR_RADIO_SREV_MAJOR)),
143 ah->hw_version.phyRev,
144 (unsigned long)mem, irq); 142 (unsigned long)mem, irq);
145 143
146 return 0; 144 return 0;
diff --git a/drivers/net/wireless/ath/ath9k/calib.c b/drivers/net/wireless/ath/ath9k/calib.c
index 551f8801459f..238a5744d8e9 100644
--- a/drivers/net/wireless/ath/ath9k/calib.c
+++ b/drivers/net/wireless/ath/ath9k/calib.c
@@ -877,7 +877,7 @@ static void ath9k_hw_9271_pa_cal(struct ath_hw *ah, bool is_reset)
877 REG_RMW_FIELD(ah, AR9285_AN_RF2G6, AR9271_AN_RF2G6_OFFS, 0); 877 REG_RMW_FIELD(ah, AR9285_AN_RF2G6, AR9271_AN_RF2G6_OFFS, 0);
878 878
879 /* find off_6_1; */ 879 /* find off_6_1; */
880 for (i = 6; i >= 0; i--) { 880 for (i = 6; i > 0; i--) {
881 regVal = REG_READ(ah, 0x7834); 881 regVal = REG_READ(ah, 0x7834);
882 regVal |= (1 << (20 + i)); 882 regVal |= (1 << (20 + i));
883 REG_WRITE(ah, 0x7834, regVal); 883 REG_WRITE(ah, 0x7834, regVal);
diff --git a/drivers/net/wireless/ath/ath9k/eeprom_4k.c b/drivers/net/wireless/ath/ath9k/eeprom_4k.c
index 58167d861dc6..68db16690abf 100644
--- a/drivers/net/wireless/ath/ath9k/eeprom_4k.c
+++ b/drivers/net/wireless/ath/ath9k/eeprom_4k.c
@@ -1112,6 +1112,10 @@ static void ath9k_hw_4k_set_board_values(struct ath_hw *ah,
1112 1112
1113 REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_A2_RX_ON, 1113 REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_A2_RX_ON,
1114 pModal->txEndToRxOn); 1114 pModal->txEndToRxOn);
1115
1116 if (AR_SREV_9271_10(ah))
1117 REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_A2_RX_ON,
1118 pModal->txEndToRxOn);
1115 REG_RMW_FIELD(ah, AR_PHY_CCA, AR9280_PHY_CCA_THRESH62, 1119 REG_RMW_FIELD(ah, AR_PHY_CCA, AR9280_PHY_CCA_THRESH62,
1116 pModal->thresh62); 1120 pModal->thresh62);
1117 REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0, AR_PHY_EXT_CCA0_THRESH62, 1121 REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0, AR_PHY_EXT_CCA0_THRESH62,
diff --git a/drivers/net/wireless/ath/ath9k/hw.c b/drivers/net/wireless/ath/ath9k/hw.c
index cab17c6c8a37..111ff049f75d 100644
--- a/drivers/net/wireless/ath/ath9k/hw.c
+++ b/drivers/net/wireless/ath/ath9k/hw.c
@@ -30,8 +30,6 @@ static void ath9k_hw_set_regs(struct ath_hw *ah, struct ath9k_channel *chan);
30static u32 ath9k_hw_ini_fixup(struct ath_hw *ah, 30static u32 ath9k_hw_ini_fixup(struct ath_hw *ah,
31 struct ar5416_eeprom_def *pEepData, 31 struct ar5416_eeprom_def *pEepData,
32 u32 reg, u32 value); 32 u32 reg, u32 value);
33static void ath9k_hw_9280_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan);
34static void ath9k_hw_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan);
35 33
36MODULE_AUTHOR("Atheros Communications"); 34MODULE_AUTHOR("Atheros Communications");
37MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards."); 35MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
@@ -454,21 +452,6 @@ static void ath9k_hw_init_defaults(struct ath_hw *ah)
454 ah->power_mode = ATH9K_PM_UNDEFINED; 452 ah->power_mode = ATH9K_PM_UNDEFINED;
455} 453}
456 454
457static int ath9k_hw_rfattach(struct ath_hw *ah)
458{
459 bool rfStatus = false;
460 int ecode = 0;
461
462 rfStatus = ath9k_hw_init_rf(ah, &ecode);
463 if (!rfStatus) {
464 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
465 "RF setup failed, status: %u\n", ecode);
466 return ecode;
467 }
468
469 return 0;
470}
471
472static int ath9k_hw_rf_claim(struct ath_hw *ah) 455static int ath9k_hw_rf_claim(struct ath_hw *ah)
473{ 456{
474 u32 val; 457 u32 val;
@@ -585,9 +568,15 @@ static int ath9k_hw_post_init(struct ath_hw *ah)
585 ah->eep_ops->get_eeprom_ver(ah), 568 ah->eep_ops->get_eeprom_ver(ah),
586 ah->eep_ops->get_eeprom_rev(ah)); 569 ah->eep_ops->get_eeprom_rev(ah));
587 570
588 ecode = ath9k_hw_rfattach(ah); 571 if (!AR_SREV_9280_10_OR_LATER(ah)) {
589 if (ecode != 0) 572 ecode = ath9k_hw_rf_alloc_ext_banks(ah);
590 return ecode; 573 if (ecode) {
574 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
575 "Failed allocating banks for "
576 "external radio\n");
577 return ecode;
578 }
579 }
591 580
592 if (!AR_SREV_9100(ah)) { 581 if (!AR_SREV_9100(ah)) {
593 ath9k_hw_ani_setup(ah); 582 ath9k_hw_ani_setup(ah);
@@ -662,10 +651,13 @@ static void ath9k_hw_init_cal_settings(struct ath_hw *ah)
662static void ath9k_hw_init_mode_regs(struct ath_hw *ah) 651static void ath9k_hw_init_mode_regs(struct ath_hw *ah)
663{ 652{
664 if (AR_SREV_9271(ah)) { 653 if (AR_SREV_9271(ah)) {
665 INIT_INI_ARRAY(&ah->iniModes, ar9271Modes_9271_1_0, 654 INIT_INI_ARRAY(&ah->iniModes, ar9271Modes_9271,
666 ARRAY_SIZE(ar9271Modes_9271_1_0), 6); 655 ARRAY_SIZE(ar9271Modes_9271), 6);
667 INIT_INI_ARRAY(&ah->iniCommon, ar9271Common_9271_1_0, 656 INIT_INI_ARRAY(&ah->iniCommon, ar9271Common_9271,
668 ARRAY_SIZE(ar9271Common_9271_1_0), 2); 657 ARRAY_SIZE(ar9271Common_9271), 2);
658 INIT_INI_ARRAY(&ah->iniModes_9271_1_0_only,
659 ar9271Modes_9271_1_0_only,
660 ARRAY_SIZE(ar9271Modes_9271_1_0_only), 6);
669 return; 661 return;
670 } 662 }
671 663
@@ -957,8 +949,14 @@ int ath9k_hw_init(struct ath_hw *ah)
957 ath9k_hw_init_cal_settings(ah); 949 ath9k_hw_init_cal_settings(ah);
958 950
959 ah->ani_function = ATH9K_ANI_ALL; 951 ah->ani_function = ATH9K_ANI_ALL;
960 if (AR_SREV_9280_10_OR_LATER(ah)) 952 if (AR_SREV_9280_10_OR_LATER(ah)) {
961 ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL; 953 ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
954 ah->ath9k_hw_rf_set_freq = &ath9k_hw_ar9280_set_channel;
955 ah->ath9k_hw_spur_mitigate_freq = &ath9k_hw_9280_spur_mitigate;
956 } else {
957 ah->ath9k_hw_rf_set_freq = &ath9k_hw_set_channel;
958 ah->ath9k_hw_spur_mitigate_freq = &ath9k_hw_spur_mitigate;
959 }
962 960
963 ath9k_hw_init_mode_regs(ah); 961 ath9k_hw_init_mode_regs(ah);
964 962
@@ -1037,6 +1035,22 @@ static void ath9k_hw_init_qos(struct ath_hw *ah)
1037 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF); 1035 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
1038} 1036}
1039 1037
1038static void ath9k_hw_change_target_baud(struct ath_hw *ah, u32 freq, u32 baud)
1039{
1040 u32 lcr;
1041 u32 baud_divider = freq * 1000 * 1000 / 16 / baud;
1042
1043 lcr = REG_READ(ah , 0x5100c);
1044 lcr |= 0x80;
1045
1046 REG_WRITE(ah, 0x5100c, lcr);
1047 REG_WRITE(ah, 0x51004, (baud_divider >> 8));
1048 REG_WRITE(ah, 0x51000, (baud_divider & 0xff));
1049
1050 lcr &= ~0x80;
1051 REG_WRITE(ah, 0x5100c, lcr);
1052}
1053
1040static void ath9k_hw_init_pll(struct ath_hw *ah, 1054static void ath9k_hw_init_pll(struct ath_hw *ah,
1041 struct ath9k_channel *chan) 1055 struct ath9k_channel *chan)
1042{ 1056{
@@ -1100,6 +1114,26 @@ static void ath9k_hw_init_pll(struct ath_hw *ah,
1100 } 1114 }
1101 REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll); 1115 REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
1102 1116
1117 /* Switch the core clock for ar9271 to 117Mhz */
1118 if (AR_SREV_9271(ah)) {
1119 if ((pll == 0x142c) || (pll == 0x2850) ) {
1120 udelay(500);
1121 /* set CLKOBS to output AHB clock */
1122 REG_WRITE(ah, 0x7020, 0xe);
1123 /*
1124 * 0x304: 117Mhz, ahb_ratio: 1x1
1125 * 0x306: 40Mhz, ahb_ratio: 1x1
1126 */
1127 REG_WRITE(ah, 0x50040, 0x304);
1128 /*
1129 * makes adjustments for the baud dividor to keep the
1130 * targetted baud rate based on the used core clock.
1131 */
1132 ath9k_hw_change_target_baud(ah, AR9271_CORE_CLOCK,
1133 AR9271_TARGET_BAUD_RATE);
1134 }
1135 }
1136
1103 udelay(RTC_PLL_SETTLE_DELAY); 1137 udelay(RTC_PLL_SETTLE_DELAY);
1104 1138
1105 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK); 1139 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
@@ -1252,7 +1286,8 @@ void ath9k_hw_detach(struct ath_hw *ah)
1252 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP); 1286 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
1253 1287
1254free_hw: 1288free_hw:
1255 ath9k_hw_rf_free(ah); 1289 if (!AR_SREV_9280_10_OR_LATER(ah))
1290 ath9k_hw_rf_free_ext_banks(ah);
1256 kfree(ah); 1291 kfree(ah);
1257 ah = NULL; 1292 ah = NULL;
1258} 1293}
@@ -1274,7 +1309,8 @@ static void ath9k_hw_override_ini(struct ath_hw *ah,
1274 * AR9271 1.1 1309 * AR9271 1.1
1275 */ 1310 */
1276 if (AR_SREV_9271_10(ah)) { 1311 if (AR_SREV_9271_10(ah)) {
1277 val = REG_READ(ah, AR_PHY_SPECTRAL_SCAN) | AR_PHY_SPECTRAL_SCAN_ENABLE; 1312 val = REG_READ(ah, AR_PHY_SPECTRAL_SCAN) |
1313 AR_PHY_SPECTRAL_SCAN_ENABLE;
1278 REG_WRITE(ah, AR_PHY_SPECTRAL_SCAN, val); 1314 REG_WRITE(ah, AR_PHY_SPECTRAL_SCAN, val);
1279 } 1315 }
1280 else if (AR_SREV_9271_11(ah)) 1316 else if (AR_SREV_9271_11(ah))
@@ -1489,7 +1525,11 @@ static int ath9k_hw_process_ini(struct ath_hw *ah,
1489 DO_DELAY(regWrites); 1525 DO_DELAY(regWrites);
1490 } 1526 }
1491 1527
1492 ath9k_hw_write_regs(ah, modesIndex, freqIndex, regWrites); 1528 ath9k_hw_write_regs(ah, freqIndex, regWrites);
1529
1530 if (AR_SREV_9271_10(ah))
1531 REG_WRITE_ARRAY(&ah->iniModes_9271_1_0_only,
1532 modesIndex, regWrites);
1493 1533
1494 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan)) { 1534 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan)) {
1495 REG_WRITE_ARRAY(&ah->iniModesAdditional, modesIndex, 1535 REG_WRITE_ARRAY(&ah->iniModesAdditional, modesIndex,
@@ -1832,6 +1872,7 @@ static bool ath9k_hw_channel_change(struct ath_hw *ah,
1832 struct ath_common *common = ath9k_hw_common(ah); 1872 struct ath_common *common = ath9k_hw_common(ah);
1833 struct ieee80211_channel *channel = chan->chan; 1873 struct ieee80211_channel *channel = chan->chan;
1834 u32 synthDelay, qnum; 1874 u32 synthDelay, qnum;
1875 int r;
1835 1876
1836 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) { 1877 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1837 if (ath9k_hw_numtxpending(ah, qnum)) { 1878 if (ath9k_hw_numtxpending(ah, qnum)) {
@@ -1852,14 +1893,11 @@ static bool ath9k_hw_channel_change(struct ath_hw *ah,
1852 1893
1853 ath9k_hw_set_regs(ah, chan); 1894 ath9k_hw_set_regs(ah, chan);
1854 1895
1855 if (AR_SREV_9280_10_OR_LATER(ah)) { 1896 r = ah->ath9k_hw_rf_set_freq(ah, chan);
1856 ath9k_hw_ar9280_set_channel(ah, chan); 1897 if (r) {
1857 } else { 1898 ath_print(common, ATH_DBG_FATAL,
1858 if (!(ath9k_hw_set_channel(ah, chan))) { 1899 "Failed to set channel\n");
1859 ath_print(common, ATH_DBG_FATAL, 1900 return false;
1860 "Failed to set channel\n");
1861 return false;
1862 }
1863 } 1901 }
1864 1902
1865 ah->eep_ops->set_txpower(ah, chan, 1903 ah->eep_ops->set_txpower(ah, chan,
@@ -1882,10 +1920,7 @@ static bool ath9k_hw_channel_change(struct ath_hw *ah,
1882 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan)) 1920 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1883 ath9k_hw_set_delta_slope(ah, chan); 1921 ath9k_hw_set_delta_slope(ah, chan);
1884 1922
1885 if (AR_SREV_9280_10_OR_LATER(ah)) 1923 ah->ath9k_hw_spur_mitigate_freq(ah, chan);
1886 ath9k_hw_9280_spur_mitigate(ah, chan);
1887 else
1888 ath9k_hw_spur_mitigate(ah, chan);
1889 1924
1890 if (!chan->oneTimeCalsDone) 1925 if (!chan->oneTimeCalsDone)
1891 chan->oneTimeCalsDone = true; 1926 chan->oneTimeCalsDone = true;
@@ -1893,457 +1928,6 @@ static bool ath9k_hw_channel_change(struct ath_hw *ah,
1893 return true; 1928 return true;
1894} 1929}
1895 1930
1896static void ath9k_hw_9280_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan)
1897{
1898 int bb_spur = AR_NO_SPUR;
1899 int freq;
1900 int bin, cur_bin;
1901 int bb_spur_off, spur_subchannel_sd;
1902 int spur_freq_sd;
1903 int spur_delta_phase;
1904 int denominator;
1905 int upper, lower, cur_vit_mask;
1906 int tmp, newVal;
1907 int i;
1908 int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
1909 AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
1910 };
1911 int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
1912 AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
1913 };
1914 int inc[4] = { 0, 100, 0, 0 };
1915 struct chan_centers centers;
1916
1917 int8_t mask_m[123];
1918 int8_t mask_p[123];
1919 int8_t mask_amt;
1920 int tmp_mask;
1921 int cur_bb_spur;
1922 bool is2GHz = IS_CHAN_2GHZ(chan);
1923
1924 memset(&mask_m, 0, sizeof(int8_t) * 123);
1925 memset(&mask_p, 0, sizeof(int8_t) * 123);
1926
1927 ath9k_hw_get_channel_centers(ah, chan, &centers);
1928 freq = centers.synth_center;
1929
1930 ah->config.spurmode = SPUR_ENABLE_EEPROM;
1931 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
1932 cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
1933
1934 if (is2GHz)
1935 cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_2GHZ;
1936 else
1937 cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_5GHZ;
1938
1939 if (AR_NO_SPUR == cur_bb_spur)
1940 break;
1941 cur_bb_spur = cur_bb_spur - freq;
1942
1943 if (IS_CHAN_HT40(chan)) {
1944 if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT40) &&
1945 (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT40)) {
1946 bb_spur = cur_bb_spur;
1947 break;
1948 }
1949 } else if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT20) &&
1950 (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT20)) {
1951 bb_spur = cur_bb_spur;
1952 break;
1953 }
1954 }
1955
1956 if (AR_NO_SPUR == bb_spur) {
1957 REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
1958 AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
1959 return;
1960 } else {
1961 REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
1962 AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
1963 }
1964
1965 bin = bb_spur * 320;
1966
1967 tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
1968
1969 newVal = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
1970 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
1971 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
1972 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
1973 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), newVal);
1974
1975 newVal = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
1976 AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
1977 AR_PHY_SPUR_REG_MASK_RATE_SELECT |
1978 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
1979 SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
1980 REG_WRITE(ah, AR_PHY_SPUR_REG, newVal);
1981
1982 if (IS_CHAN_HT40(chan)) {
1983 if (bb_spur < 0) {
1984 spur_subchannel_sd = 1;
1985 bb_spur_off = bb_spur + 10;
1986 } else {
1987 spur_subchannel_sd = 0;
1988 bb_spur_off = bb_spur - 10;
1989 }
1990 } else {
1991 spur_subchannel_sd = 0;
1992 bb_spur_off = bb_spur;
1993 }
1994
1995 if (IS_CHAN_HT40(chan))
1996 spur_delta_phase =
1997 ((bb_spur * 262144) /
1998 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
1999 else
2000 spur_delta_phase =
2001 ((bb_spur * 524288) /
2002 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
2003
2004 denominator = IS_CHAN_2GHZ(chan) ? 44 : 40;
2005 spur_freq_sd = ((bb_spur_off * 2048) / denominator) & 0x3ff;
2006
2007 newVal = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
2008 SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
2009 SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
2010 REG_WRITE(ah, AR_PHY_TIMING11, newVal);
2011
2012 newVal = spur_subchannel_sd << AR_PHY_SFCORR_SPUR_SUBCHNL_SD_S;
2013 REG_WRITE(ah, AR_PHY_SFCORR_EXT, newVal);
2014
2015 cur_bin = -6000;
2016 upper = bin + 100;
2017 lower = bin - 100;
2018
2019 for (i = 0; i < 4; i++) {
2020 int pilot_mask = 0;
2021 int chan_mask = 0;
2022 int bp = 0;
2023 for (bp = 0; bp < 30; bp++) {
2024 if ((cur_bin > lower) && (cur_bin < upper)) {
2025 pilot_mask = pilot_mask | 0x1 << bp;
2026 chan_mask = chan_mask | 0x1 << bp;
2027 }
2028 cur_bin += 100;
2029 }
2030 cur_bin += inc[i];
2031 REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
2032 REG_WRITE(ah, chan_mask_reg[i], chan_mask);
2033 }
2034
2035 cur_vit_mask = 6100;
2036 upper = bin + 120;
2037 lower = bin - 120;
2038
2039 for (i = 0; i < 123; i++) {
2040 if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
2041
2042 /* workaround for gcc bug #37014 */
2043 volatile int tmp_v = abs(cur_vit_mask - bin);
2044
2045 if (tmp_v < 75)
2046 mask_amt = 1;
2047 else
2048 mask_amt = 0;
2049 if (cur_vit_mask < 0)
2050 mask_m[abs(cur_vit_mask / 100)] = mask_amt;
2051 else
2052 mask_p[cur_vit_mask / 100] = mask_amt;
2053 }
2054 cur_vit_mask -= 100;
2055 }
2056
2057 tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
2058 | (mask_m[48] << 26) | (mask_m[49] << 24)
2059 | (mask_m[50] << 22) | (mask_m[51] << 20)
2060 | (mask_m[52] << 18) | (mask_m[53] << 16)
2061 | (mask_m[54] << 14) | (mask_m[55] << 12)
2062 | (mask_m[56] << 10) | (mask_m[57] << 8)
2063 | (mask_m[58] << 6) | (mask_m[59] << 4)
2064 | (mask_m[60] << 2) | (mask_m[61] << 0);
2065 REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
2066 REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
2067
2068 tmp_mask = (mask_m[31] << 28)
2069 | (mask_m[32] << 26) | (mask_m[33] << 24)
2070 | (mask_m[34] << 22) | (mask_m[35] << 20)
2071 | (mask_m[36] << 18) | (mask_m[37] << 16)
2072 | (mask_m[48] << 14) | (mask_m[39] << 12)
2073 | (mask_m[40] << 10) | (mask_m[41] << 8)
2074 | (mask_m[42] << 6) | (mask_m[43] << 4)
2075 | (mask_m[44] << 2) | (mask_m[45] << 0);
2076 REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
2077 REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
2078
2079 tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
2080 | (mask_m[18] << 26) | (mask_m[18] << 24)
2081 | (mask_m[20] << 22) | (mask_m[20] << 20)
2082 | (mask_m[22] << 18) | (mask_m[22] << 16)
2083 | (mask_m[24] << 14) | (mask_m[24] << 12)
2084 | (mask_m[25] << 10) | (mask_m[26] << 8)
2085 | (mask_m[27] << 6) | (mask_m[28] << 4)
2086 | (mask_m[29] << 2) | (mask_m[30] << 0);
2087 REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
2088 REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
2089
2090 tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
2091 | (mask_m[2] << 26) | (mask_m[3] << 24)
2092 | (mask_m[4] << 22) | (mask_m[5] << 20)
2093 | (mask_m[6] << 18) | (mask_m[7] << 16)
2094 | (mask_m[8] << 14) | (mask_m[9] << 12)
2095 | (mask_m[10] << 10) | (mask_m[11] << 8)
2096 | (mask_m[12] << 6) | (mask_m[13] << 4)
2097 | (mask_m[14] << 2) | (mask_m[15] << 0);
2098 REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
2099 REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
2100
2101 tmp_mask = (mask_p[15] << 28)
2102 | (mask_p[14] << 26) | (mask_p[13] << 24)
2103 | (mask_p[12] << 22) | (mask_p[11] << 20)
2104 | (mask_p[10] << 18) | (mask_p[9] << 16)
2105 | (mask_p[8] << 14) | (mask_p[7] << 12)
2106 | (mask_p[6] << 10) | (mask_p[5] << 8)
2107 | (mask_p[4] << 6) | (mask_p[3] << 4)
2108 | (mask_p[2] << 2) | (mask_p[1] << 0);
2109 REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
2110 REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
2111
2112 tmp_mask = (mask_p[30] << 28)
2113 | (mask_p[29] << 26) | (mask_p[28] << 24)
2114 | (mask_p[27] << 22) | (mask_p[26] << 20)
2115 | (mask_p[25] << 18) | (mask_p[24] << 16)
2116 | (mask_p[23] << 14) | (mask_p[22] << 12)
2117 | (mask_p[21] << 10) | (mask_p[20] << 8)
2118 | (mask_p[19] << 6) | (mask_p[18] << 4)
2119 | (mask_p[17] << 2) | (mask_p[16] << 0);
2120 REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
2121 REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
2122
2123 tmp_mask = (mask_p[45] << 28)
2124 | (mask_p[44] << 26) | (mask_p[43] << 24)
2125 | (mask_p[42] << 22) | (mask_p[41] << 20)
2126 | (mask_p[40] << 18) | (mask_p[39] << 16)
2127 | (mask_p[38] << 14) | (mask_p[37] << 12)
2128 | (mask_p[36] << 10) | (mask_p[35] << 8)
2129 | (mask_p[34] << 6) | (mask_p[33] << 4)
2130 | (mask_p[32] << 2) | (mask_p[31] << 0);
2131 REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
2132 REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
2133
2134 tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
2135 | (mask_p[59] << 26) | (mask_p[58] << 24)
2136 | (mask_p[57] << 22) | (mask_p[56] << 20)
2137 | (mask_p[55] << 18) | (mask_p[54] << 16)
2138 | (mask_p[53] << 14) | (mask_p[52] << 12)
2139 | (mask_p[51] << 10) | (mask_p[50] << 8)
2140 | (mask_p[49] << 6) | (mask_p[48] << 4)
2141 | (mask_p[47] << 2) | (mask_p[46] << 0);
2142 REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
2143 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
2144}
2145
2146static void ath9k_hw_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan)
2147{
2148 int bb_spur = AR_NO_SPUR;
2149 int bin, cur_bin;
2150 int spur_freq_sd;
2151 int spur_delta_phase;
2152 int denominator;
2153 int upper, lower, cur_vit_mask;
2154 int tmp, new;
2155 int i;
2156 int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
2157 AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
2158 };
2159 int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
2160 AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
2161 };
2162 int inc[4] = { 0, 100, 0, 0 };
2163
2164 int8_t mask_m[123];
2165 int8_t mask_p[123];
2166 int8_t mask_amt;
2167 int tmp_mask;
2168 int cur_bb_spur;
2169 bool is2GHz = IS_CHAN_2GHZ(chan);
2170
2171 memset(&mask_m, 0, sizeof(int8_t) * 123);
2172 memset(&mask_p, 0, sizeof(int8_t) * 123);
2173
2174 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
2175 cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
2176 if (AR_NO_SPUR == cur_bb_spur)
2177 break;
2178 cur_bb_spur = cur_bb_spur - (chan->channel * 10);
2179 if ((cur_bb_spur > -95) && (cur_bb_spur < 95)) {
2180 bb_spur = cur_bb_spur;
2181 break;
2182 }
2183 }
2184
2185 if (AR_NO_SPUR == bb_spur)
2186 return;
2187
2188 bin = bb_spur * 32;
2189
2190 tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
2191 new = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
2192 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
2193 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
2194 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
2195
2196 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), new);
2197
2198 new = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
2199 AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
2200 AR_PHY_SPUR_REG_MASK_RATE_SELECT |
2201 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
2202 SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
2203 REG_WRITE(ah, AR_PHY_SPUR_REG, new);
2204
2205 spur_delta_phase = ((bb_spur * 524288) / 100) &
2206 AR_PHY_TIMING11_SPUR_DELTA_PHASE;
2207
2208 denominator = IS_CHAN_2GHZ(chan) ? 440 : 400;
2209 spur_freq_sd = ((bb_spur * 2048) / denominator) & 0x3ff;
2210
2211 new = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
2212 SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
2213 SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
2214 REG_WRITE(ah, AR_PHY_TIMING11, new);
2215
2216 cur_bin = -6000;
2217 upper = bin + 100;
2218 lower = bin - 100;
2219
2220 for (i = 0; i < 4; i++) {
2221 int pilot_mask = 0;
2222 int chan_mask = 0;
2223 int bp = 0;
2224 for (bp = 0; bp < 30; bp++) {
2225 if ((cur_bin > lower) && (cur_bin < upper)) {
2226 pilot_mask = pilot_mask | 0x1 << bp;
2227 chan_mask = chan_mask | 0x1 << bp;
2228 }
2229 cur_bin += 100;
2230 }
2231 cur_bin += inc[i];
2232 REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
2233 REG_WRITE(ah, chan_mask_reg[i], chan_mask);
2234 }
2235
2236 cur_vit_mask = 6100;
2237 upper = bin + 120;
2238 lower = bin - 120;
2239
2240 for (i = 0; i < 123; i++) {
2241 if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
2242
2243 /* workaround for gcc bug #37014 */
2244 volatile int tmp_v = abs(cur_vit_mask - bin);
2245
2246 if (tmp_v < 75)
2247 mask_amt = 1;
2248 else
2249 mask_amt = 0;
2250 if (cur_vit_mask < 0)
2251 mask_m[abs(cur_vit_mask / 100)] = mask_amt;
2252 else
2253 mask_p[cur_vit_mask / 100] = mask_amt;
2254 }
2255 cur_vit_mask -= 100;
2256 }
2257
2258 tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
2259 | (mask_m[48] << 26) | (mask_m[49] << 24)
2260 | (mask_m[50] << 22) | (mask_m[51] << 20)
2261 | (mask_m[52] << 18) | (mask_m[53] << 16)
2262 | (mask_m[54] << 14) | (mask_m[55] << 12)
2263 | (mask_m[56] << 10) | (mask_m[57] << 8)
2264 | (mask_m[58] << 6) | (mask_m[59] << 4)
2265 | (mask_m[60] << 2) | (mask_m[61] << 0);
2266 REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
2267 REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
2268
2269 tmp_mask = (mask_m[31] << 28)
2270 | (mask_m[32] << 26) | (mask_m[33] << 24)
2271 | (mask_m[34] << 22) | (mask_m[35] << 20)
2272 | (mask_m[36] << 18) | (mask_m[37] << 16)
2273 | (mask_m[48] << 14) | (mask_m[39] << 12)
2274 | (mask_m[40] << 10) | (mask_m[41] << 8)
2275 | (mask_m[42] << 6) | (mask_m[43] << 4)
2276 | (mask_m[44] << 2) | (mask_m[45] << 0);
2277 REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
2278 REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
2279
2280 tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
2281 | (mask_m[18] << 26) | (mask_m[18] << 24)
2282 | (mask_m[20] << 22) | (mask_m[20] << 20)
2283 | (mask_m[22] << 18) | (mask_m[22] << 16)
2284 | (mask_m[24] << 14) | (mask_m[24] << 12)
2285 | (mask_m[25] << 10) | (mask_m[26] << 8)
2286 | (mask_m[27] << 6) | (mask_m[28] << 4)
2287 | (mask_m[29] << 2) | (mask_m[30] << 0);
2288 REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
2289 REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
2290
2291 tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
2292 | (mask_m[2] << 26) | (mask_m[3] << 24)
2293 | (mask_m[4] << 22) | (mask_m[5] << 20)
2294 | (mask_m[6] << 18) | (mask_m[7] << 16)
2295 | (mask_m[8] << 14) | (mask_m[9] << 12)
2296 | (mask_m[10] << 10) | (mask_m[11] << 8)
2297 | (mask_m[12] << 6) | (mask_m[13] << 4)
2298 | (mask_m[14] << 2) | (mask_m[15] << 0);
2299 REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
2300 REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
2301
2302 tmp_mask = (mask_p[15] << 28)
2303 | (mask_p[14] << 26) | (mask_p[13] << 24)
2304 | (mask_p[12] << 22) | (mask_p[11] << 20)
2305 | (mask_p[10] << 18) | (mask_p[9] << 16)
2306 | (mask_p[8] << 14) | (mask_p[7] << 12)
2307 | (mask_p[6] << 10) | (mask_p[5] << 8)
2308 | (mask_p[4] << 6) | (mask_p[3] << 4)
2309 | (mask_p[2] << 2) | (mask_p[1] << 0);
2310 REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
2311 REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
2312
2313 tmp_mask = (mask_p[30] << 28)
2314 | (mask_p[29] << 26) | (mask_p[28] << 24)
2315 | (mask_p[27] << 22) | (mask_p[26] << 20)
2316 | (mask_p[25] << 18) | (mask_p[24] << 16)
2317 | (mask_p[23] << 14) | (mask_p[22] << 12)
2318 | (mask_p[21] << 10) | (mask_p[20] << 8)
2319 | (mask_p[19] << 6) | (mask_p[18] << 4)
2320 | (mask_p[17] << 2) | (mask_p[16] << 0);
2321 REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
2322 REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
2323
2324 tmp_mask = (mask_p[45] << 28)
2325 | (mask_p[44] << 26) | (mask_p[43] << 24)
2326 | (mask_p[42] << 22) | (mask_p[41] << 20)
2327 | (mask_p[40] << 18) | (mask_p[39] << 16)
2328 | (mask_p[38] << 14) | (mask_p[37] << 12)
2329 | (mask_p[36] << 10) | (mask_p[35] << 8)
2330 | (mask_p[34] << 6) | (mask_p[33] << 4)
2331 | (mask_p[32] << 2) | (mask_p[31] << 0);
2332 REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
2333 REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
2334
2335 tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
2336 | (mask_p[59] << 26) | (mask_p[58] << 24)
2337 | (mask_p[57] << 22) | (mask_p[56] << 20)
2338 | (mask_p[55] << 18) | (mask_p[54] << 16)
2339 | (mask_p[53] << 14) | (mask_p[52] << 12)
2340 | (mask_p[51] << 10) | (mask_p[50] << 8)
2341 | (mask_p[49] << 6) | (mask_p[48] << 4)
2342 | (mask_p[47] << 2) | (mask_p[46] << 0);
2343 REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
2344 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
2345}
2346
2347static void ath9k_enable_rfkill(struct ath_hw *ah) 1931static void ath9k_enable_rfkill(struct ath_hw *ah)
2348{ 1932{
2349 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, 1933 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
@@ -2469,14 +2053,11 @@ int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
2469 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan)) 2053 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
2470 ath9k_hw_set_delta_slope(ah, chan); 2054 ath9k_hw_set_delta_slope(ah, chan);
2471 2055
2472 if (AR_SREV_9280_10_OR_LATER(ah)) 2056 ah->ath9k_hw_spur_mitigate_freq(ah, chan);
2473 ath9k_hw_9280_spur_mitigate(ah, chan);
2474 else
2475 ath9k_hw_spur_mitigate(ah, chan);
2476
2477 ah->eep_ops->set_board_values(ah, chan); 2057 ah->eep_ops->set_board_values(ah, chan);
2478 2058
2479 ath9k_hw_decrease_chain_power(ah, chan); 2059 if (AR_SREV_5416(ah))
2060 ath9k_hw_decrease_chain_power(ah, chan);
2480 2061
2481 REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr)); 2062 REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr));
2482 REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4) 2063 REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4)
@@ -2497,11 +2078,9 @@ int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
2497 2078
2498 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR); 2079 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
2499 2080
2500 if (AR_SREV_9280_10_OR_LATER(ah)) 2081 r = ah->ath9k_hw_rf_set_freq(ah, chan);
2501 ath9k_hw_ar9280_set_channel(ah, chan); 2082 if (r)
2502 else 2083 return r;
2503 if (!(ath9k_hw_set_channel(ah, chan)))
2504 return -EIO;
2505 2084
2506 for (i = 0; i < AR_NUM_DCU; i++) 2085 for (i = 0; i < AR_NUM_DCU; i++)
2507 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i); 2086 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
@@ -4350,3 +3929,89 @@ void ath_gen_timer_isr(struct ath_hw *ah)
4350 } 3929 }
4351} 3930}
4352EXPORT_SYMBOL(ath_gen_timer_isr); 3931EXPORT_SYMBOL(ath_gen_timer_isr);
3932
3933static struct {
3934 u32 version;
3935 const char * name;
3936} ath_mac_bb_names[] = {
3937 /* Devices with external radios */
3938 { AR_SREV_VERSION_5416_PCI, "5416" },
3939 { AR_SREV_VERSION_5416_PCIE, "5418" },
3940 { AR_SREV_VERSION_9100, "9100" },
3941 { AR_SREV_VERSION_9160, "9160" },
3942 /* Single-chip solutions */
3943 { AR_SREV_VERSION_9280, "9280" },
3944 { AR_SREV_VERSION_9285, "9285" },
3945 { AR_SREV_VERSION_9287, "9287" },
3946 { AR_SREV_VERSION_9271, "9271" },
3947};
3948
3949/* For devices with external radios */
3950static struct {
3951 u16 version;
3952 const char * name;
3953} ath_rf_names[] = {
3954 { 0, "5133" },
3955 { AR_RAD5133_SREV_MAJOR, "5133" },
3956 { AR_RAD5122_SREV_MAJOR, "5122" },
3957 { AR_RAD2133_SREV_MAJOR, "2133" },
3958 { AR_RAD2122_SREV_MAJOR, "2122" }
3959};
3960
3961/*
3962 * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
3963 */
3964static const char *ath9k_hw_mac_bb_name(u32 mac_bb_version)
3965{
3966 int i;
3967
3968 for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
3969 if (ath_mac_bb_names[i].version == mac_bb_version) {
3970 return ath_mac_bb_names[i].name;
3971 }
3972 }
3973
3974 return "????";
3975}
3976
3977/*
3978 * Return the RF name. "????" is returned if the RF is unknown.
3979 * Used for devices with external radios.
3980 */
3981static const char *ath9k_hw_rf_name(u16 rf_version)
3982{
3983 int i;
3984
3985 for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
3986 if (ath_rf_names[i].version == rf_version) {
3987 return ath_rf_names[i].name;
3988 }
3989 }
3990
3991 return "????";
3992}
3993
3994void ath9k_hw_name(struct ath_hw *ah, char *hw_name, size_t len)
3995{
3996 int used;
3997
3998 /* chipsets >= AR9280 are single-chip */
3999 if (AR_SREV_9280_10_OR_LATER(ah)) {
4000 used = snprintf(hw_name, len,
4001 "Atheros AR%s Rev:%x",
4002 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
4003 ah->hw_version.macRev);
4004 }
4005 else {
4006 used = snprintf(hw_name, len,
4007 "Atheros AR%s MAC/BB Rev:%x AR%s RF Rev:%x",
4008 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
4009 ah->hw_version.macRev,
4010 ath9k_hw_rf_name((ah->hw_version.analog5GhzRev &
4011 AR_RADIO_SREV_MAJOR)),
4012 ah->hw_version.phyRev);
4013 }
4014
4015 hw_name[used] = '\0';
4016}
4017EXPORT_SYMBOL(ath9k_hw_name);
diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
index cdaec526db35..c7b0c4d5f75a 100644
--- a/drivers/net/wireless/ath/ath9k/hw.h
+++ b/drivers/net/wireless/ath/ath9k/hw.h
@@ -148,6 +148,15 @@ enum wireless_mode {
148 ATH9K_MODE_MAX, 148 ATH9K_MODE_MAX,
149}; 149};
150 150
151/**
152 * ath9k_ant_setting - transmit antenna settings
153 *
154 * Configures the antenna setting to use for transmit.
155 *
156 * @ATH9K_ANT_VARIABLE: this means transmit on all active antennas
157 * @ATH9K_ANT_FIXED_A: this means transmit on the first antenna only
158 * @ATH9K_ANT_FIXED_B: this means transmit on the second antenna only
159 */
151enum ath9k_ant_setting { 160enum ath9k_ant_setting {
152 ATH9K_ANT_VARIABLE = 0, 161 ATH9K_ANT_VARIABLE = 0,
153 ATH9K_ANT_FIXED_A, 162 ATH9K_ANT_FIXED_A,
@@ -539,7 +548,14 @@ struct ath_hw {
539 DONT_USE_32KHZ, 548 DONT_USE_32KHZ,
540 } enable_32kHz_clock; 549 } enable_32kHz_clock;
541 550
542 /* RF */ 551 /* Callback for radio frequency change */
552 int (*ath9k_hw_rf_set_freq)(struct ath_hw *ah, struct ath9k_channel *chan);
553
554 /* Callback for baseband spur frequency */
555 void (*ath9k_hw_spur_mitigate_freq)(struct ath_hw *ah,
556 struct ath9k_channel *chan);
557
558 /* Used to program the radio on non single-chip devices */
543 u32 *analogBank0Data; 559 u32 *analogBank0Data;
544 u32 *analogBank1Data; 560 u32 *analogBank1Data;
545 u32 *analogBank2Data; 561 u32 *analogBank2Data;
@@ -596,6 +612,7 @@ struct ath_hw {
596 struct ar5416IniArray iniModesAdditional; 612 struct ar5416IniArray iniModesAdditional;
597 struct ar5416IniArray iniModesRxGain; 613 struct ar5416IniArray iniModesRxGain;
598 struct ar5416IniArray iniModesTxGain; 614 struct ar5416IniArray iniModesTxGain;
615 struct ar5416IniArray iniModes_9271_1_0_only;
599 struct ar5416IniArray iniCckfirNormal; 616 struct ar5416IniArray iniCckfirNormal;
600 struct ar5416IniArray iniCckfirJapan2484; 617 struct ar5416IniArray iniCckfirJapan2484;
601 618
@@ -618,7 +635,6 @@ static inline struct ath_regulatory *ath9k_hw_regulatory(struct ath_hw *ah)
618const char *ath9k_hw_probe(u16 vendorid, u16 devid); 635const char *ath9k_hw_probe(u16 vendorid, u16 devid);
619void ath9k_hw_detach(struct ath_hw *ah); 636void ath9k_hw_detach(struct ath_hw *ah);
620int ath9k_hw_init(struct ath_hw *ah); 637int ath9k_hw_init(struct ath_hw *ah);
621void ath9k_hw_rf_free(struct ath_hw *ah);
622int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan, 638int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
623 bool bChannelChange); 639 bool bChannelChange);
624void ath9k_hw_fill_cap_info(struct ath_hw *ah); 640void ath9k_hw_fill_cap_info(struct ath_hw *ah);
@@ -704,6 +720,8 @@ void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer);
704void ath_gen_timer_isr(struct ath_hw *hw); 720void ath_gen_timer_isr(struct ath_hw *hw);
705u32 ath9k_hw_gettsf32(struct ath_hw *ah); 721u32 ath9k_hw_gettsf32(struct ath_hw *ah);
706 722
723void ath9k_hw_name(struct ath_hw *ah, char *hw_name, size_t len);
724
707#define ATH_PCIE_CAP_LINK_CTRL 0x70 725#define ATH_PCIE_CAP_LINK_CTRL 0x70
708#define ATH_PCIE_CAP_LINK_L0S 1 726#define ATH_PCIE_CAP_LINK_L0S 1
709#define ATH_PCIE_CAP_LINK_L1 2 727#define ATH_PCIE_CAP_LINK_L1 2
diff --git a/drivers/net/wireless/ath/ath9k/initvals.h b/drivers/net/wireless/ath/ath9k/initvals.h
index 3ee6658d809b..8a3bf3ab998d 100644
--- a/drivers/net/wireless/ath/ath9k/initvals.h
+++ b/drivers/net/wireless/ath/ath9k/initvals.h
@@ -6379,8 +6379,8 @@ static const u_int32_t ar9287PciePhy_clkreq_off_L1_9287_1_1[][2] = {
6379}; 6379};
6380 6380
6381 6381
6382/* AR9271 initialization values automaticaly created: 03/23/09 */ 6382/* AR9271 initialization values automaticaly created: 06/04/09 */
6383static const u_int32_t ar9271Modes_9271_1_0[][6] = { 6383static const u_int32_t ar9271Modes_9271[][6] = {
6384 { 0x00001030, 0x00000230, 0x00000460, 0x000002c0, 0x00000160, 0x000001e0 }, 6384 { 0x00001030, 0x00000230, 0x00000460, 0x000002c0, 0x00000160, 0x000001e0 },
6385 { 0x00001070, 0x00000168, 0x000002d0, 0x00000318, 0x0000018c, 0x000001e0 }, 6385 { 0x00001070, 0x00000168, 0x000002d0, 0x00000318, 0x0000018c, 0x000001e0 },
6386 { 0x000010b0, 0x00000e60, 0x00001cc0, 0x00007c70, 0x00003e38, 0x00001180 }, 6386 { 0x000010b0, 0x00000e60, 0x00001cc0, 0x00007c70, 0x00003e38, 0x00001180 },
@@ -6390,8 +6390,8 @@ static const u_int32_t ar9271Modes_9271_1_0[][6] = {
6390 { 0x00008318, 0x00003e80, 0x00007d00, 0x00006880, 0x00003440, 0x00006880 }, 6390 { 0x00008318, 0x00003e80, 0x00007d00, 0x00006880, 0x00003440, 0x00006880 },
6391 { 0x00009804, 0x00000300, 0x000003c4, 0x000003c4, 0x00000300, 0x00000303 }, 6391 { 0x00009804, 0x00000300, 0x000003c4, 0x000003c4, 0x00000300, 0x00000303 },
6392 { 0x00009820, 0x02020200, 0x02020200, 0x02020200, 0x02020200, 0x02020200 }, 6392 { 0x00009820, 0x02020200, 0x02020200, 0x02020200, 0x02020200, 0x02020200 },
6393 { 0x00009824, 0x00000e0e, 0x00000e0e, 0x00000e0e, 0x00000e0e, 0x00000e0e }, 6393 { 0x00009824, 0x01000e0e, 0x01000e0e, 0x01000e0e, 0x01000e0e, 0x01000e0e },
6394 { 0x00009828, 0x0a020001, 0x0a020001, 0x0a020001, 0x0a020001, 0x0a020001 }, 6394 { 0x00009828, 0x3a020001, 0x3a020001, 0x3a020001, 0x3a020001, 0x3a020001 },
6395 { 0x00009834, 0x00000e0e, 0x00000e0e, 0x00000e0e, 0x00000e0e, 0x00000e0e }, 6395 { 0x00009834, 0x00000e0e, 0x00000e0e, 0x00000e0e, 0x00000e0e, 0x00000e0e },
6396 { 0x00009838, 0x00000007, 0x00000007, 0x00000007, 0x00000007, 0x00000007 }, 6396 { 0x00009838, 0x00000007, 0x00000007, 0x00000007, 0x00000007, 0x00000007 },
6397 { 0x00009840, 0x206a012e, 0x206a012e, 0x206a012e, 0x206a012e, 0x206a012e }, 6397 { 0x00009840, 0x206a012e, 0x206a012e, 0x206a012e, 0x206a012e, 0x206a012e },
@@ -6405,6 +6405,7 @@ static const u_int32_t ar9271Modes_9271_1_0[][6] = {
6405 { 0x00009864, 0x0000fe00, 0x0000fe00, 0x0001ce00, 0x0001ce00, 0x0001ce00 }, 6405 { 0x00009864, 0x0000fe00, 0x0000fe00, 0x0001ce00, 0x0001ce00, 0x0001ce00 },
6406 { 0x00009868, 0x5ac640d0, 0x5ac640d0, 0x5ac640d0, 0x5ac640d0, 0x5ac640d0 }, 6406 { 0x00009868, 0x5ac640d0, 0x5ac640d0, 0x5ac640d0, 0x5ac640d0, 0x5ac640d0 },
6407 { 0x0000986c, 0x06903081, 0x06903081, 0x06903881, 0x06903881, 0x06903881 }, 6407 { 0x0000986c, 0x06903081, 0x06903081, 0x06903881, 0x06903881, 0x06903881 },
6408 { 0x00009910, 0x30002310, 0x30002310, 0x30002310, 0x30002310, 0x30002310 },
6408 { 0x00009914, 0x000007d0, 0x00000fa0, 0x00001130, 0x00000898, 0x000007d0 }, 6409 { 0x00009914, 0x000007d0, 0x00000fa0, 0x00001130, 0x00000898, 0x000007d0 },
6409 { 0x00009918, 0x0000000a, 0x00000014, 0x00000016, 0x0000000b, 0x00000016 }, 6410 { 0x00009918, 0x0000000a, 0x00000014, 0x00000016, 0x0000000b, 0x00000016 },
6410 { 0x00009924, 0xd00a8007, 0xd00a8007, 0xd00a800d, 0xd00a800d, 0xd00a800d }, 6411 { 0x00009924, 0xd00a8007, 0xd00a8007, 0xd00a800d, 0xd00a800d, 0xd00a800d },
@@ -6415,7 +6416,7 @@ static const u_int32_t ar9271Modes_9271_1_0[][6] = {
6415 { 0x000099bc, 0x00000600, 0x00000600, 0x00000c00, 0x00000c00, 0x00000c00 }, 6416 { 0x000099bc, 0x00000600, 0x00000600, 0x00000c00, 0x00000c00, 0x00000c00 },
6416 { 0x000099c0, 0x05eea6d4, 0x05eea6d4, 0x05eea6d4, 0x05eea6d4, 0x05eea6d4 }, 6417 { 0x000099c0, 0x05eea6d4, 0x05eea6d4, 0x05eea6d4, 0x05eea6d4, 0x05eea6d4 },
6417 { 0x000099c4, 0x06336f77, 0x06336f77, 0x06336f77, 0x06336f77, 0x06336f77 }, 6418 { 0x000099c4, 0x06336f77, 0x06336f77, 0x06336f77, 0x06336f77, 0x06336f77 },
6418 { 0x000099c8, 0x6af65329, 0x6af65329, 0x6af65329, 0x6af65329, 0x6af65329 }, 6419 { 0x000099c8, 0x6af6532f, 0x6af6532f, 0x6af6532f, 0x6af6532f, 0x6af6532f },
6419 { 0x000099cc, 0x08f186c8, 0x08f186c8, 0x08f186c8, 0x08f186c8, 0x08f186c8 }, 6420 { 0x000099cc, 0x08f186c8, 0x08f186c8, 0x08f186c8, 0x08f186c8, 0x08f186c8 },
6420 { 0x000099d0, 0x00046384, 0x00046384, 0x00046384, 0x00046384, 0x00046384 }, 6421 { 0x000099d0, 0x00046384, 0x00046384, 0x00046384, 0x00046384, 0x00046384 },
6421 { 0x000099d4, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, 6422 { 0x000099d4, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
@@ -6704,7 +6705,7 @@ static const u_int32_t ar9271Modes_9271_1_0[][6] = {
6704 { 0x0000a358, 0x7999aa02, 0x7999aa02, 0x7999aa0e, 0x7999aa0e, 0x7999aa0e }, 6705 { 0x0000a358, 0x7999aa02, 0x7999aa02, 0x7999aa0e, 0x7999aa0e, 0x7999aa0e },
6705}; 6706};
6706 6707
6707static const u_int32_t ar9271Common_9271_1_0[][2] = { 6708static const u_int32_t ar9271Common_9271[][2] = {
6708 { 0x0000000c, 0x00000000 }, 6709 { 0x0000000c, 0x00000000 },
6709 { 0x00000030, 0x00020045 }, 6710 { 0x00000030, 0x00020045 },
6710 { 0x00000034, 0x00000005 }, 6711 { 0x00000034, 0x00000005 },
@@ -6800,7 +6801,7 @@ static const u_int32_t ar9271Common_9271_1_0[][2] = {
6800 { 0x0000803c, 0x00000000 }, 6801 { 0x0000803c, 0x00000000 },
6801 { 0x00008048, 0x00000000 }, 6802 { 0x00008048, 0x00000000 },
6802 { 0x00008054, 0x00000000 }, 6803 { 0x00008054, 0x00000000 },
6803 { 0x00008058, 0x02000000 }, 6804 { 0x00008058, 0x00000000 },
6804 { 0x0000805c, 0x000fc78f }, 6805 { 0x0000805c, 0x000fc78f },
6805 { 0x00008060, 0x0000000f }, 6806 { 0x00008060, 0x0000000f },
6806 { 0x00008064, 0x00000000 }, 6807 { 0x00008064, 0x00000000 },
@@ -6831,7 +6832,7 @@ static const u_int32_t ar9271Common_9271_1_0[][2] = {
6831 { 0x00008110, 0x00000168 }, 6832 { 0x00008110, 0x00000168 },
6832 { 0x00008118, 0x000100aa }, 6833 { 0x00008118, 0x000100aa },
6833 { 0x0000811c, 0x00003210 }, 6834 { 0x0000811c, 0x00003210 },
6834 { 0x00008120, 0x08f04814 }, 6835 { 0x00008120, 0x08f04810 },
6835 { 0x00008124, 0x00000000 }, 6836 { 0x00008124, 0x00000000 },
6836 { 0x00008128, 0x00000000 }, 6837 { 0x00008128, 0x00000000 },
6837 { 0x0000812c, 0x00000000 }, 6838 { 0x0000812c, 0x00000000 },
@@ -6878,7 +6879,7 @@ static const u_int32_t ar9271Common_9271_1_0[][2] = {
6878 { 0x00008258, 0x00000000 }, 6879 { 0x00008258, 0x00000000 },
6879 { 0x0000825c, 0x400000ff }, 6880 { 0x0000825c, 0x400000ff },
6880 { 0x00008260, 0x00080922 }, 6881 { 0x00008260, 0x00080922 },
6881 { 0x00008264, 0xa8a00010 }, 6882 { 0x00008264, 0x88a00010 },
6882 { 0x00008270, 0x00000000 }, 6883 { 0x00008270, 0x00000000 },
6883 { 0x00008274, 0x40000000 }, 6884 { 0x00008274, 0x40000000 },
6884 { 0x00008278, 0x003e4180 }, 6885 { 0x00008278, 0x003e4180 },
@@ -6910,7 +6911,7 @@ static const u_int32_t ar9271Common_9271_1_0[][2] = {
6910 { 0x00007814, 0x924934a8 }, 6911 { 0x00007814, 0x924934a8 },
6911 { 0x0000781c, 0x00000000 }, 6912 { 0x0000781c, 0x00000000 },
6912 { 0x00007820, 0x00000c04 }, 6913 { 0x00007820, 0x00000c04 },
6913 { 0x00007824, 0x00d86bff }, 6914 { 0x00007824, 0x00d8abff },
6914 { 0x00007828, 0x66964300 }, 6915 { 0x00007828, 0x66964300 },
6915 { 0x0000782c, 0x8db6d961 }, 6916 { 0x0000782c, 0x8db6d961 },
6916 { 0x00007830, 0x8db6d96c }, 6917 { 0x00007830, 0x8db6d96c },
@@ -6944,7 +6945,6 @@ static const u_int32_t ar9271Common_9271_1_0[][2] = {
6944 { 0x00009904, 0x00000000 }, 6945 { 0x00009904, 0x00000000 },
6945 { 0x00009908, 0x00000000 }, 6946 { 0x00009908, 0x00000000 },
6946 { 0x0000990c, 0x00000000 }, 6947 { 0x0000990c, 0x00000000 },
6947 { 0x00009910, 0x30002310 },
6948 { 0x0000991c, 0x10000fff }, 6948 { 0x0000991c, 0x10000fff },
6949 { 0x00009920, 0x04900000 }, 6949 { 0x00009920, 0x04900000 },
6950 { 0x00009928, 0x00000001 }, 6950 { 0x00009928, 0x00000001 },
@@ -6958,7 +6958,7 @@ static const u_int32_t ar9271Common_9271_1_0[][2] = {
6958 { 0x00009954, 0x5f3ca3de }, 6958 { 0x00009954, 0x5f3ca3de },
6959 { 0x00009958, 0x0108ecff }, 6959 { 0x00009958, 0x0108ecff },
6960 { 0x00009968, 0x000003ce }, 6960 { 0x00009968, 0x000003ce },
6961 { 0x00009970, 0x192bb515 }, 6961 { 0x00009970, 0x192bb514 },
6962 { 0x00009974, 0x00000000 }, 6962 { 0x00009974, 0x00000000 },
6963 { 0x00009978, 0x00000001 }, 6963 { 0x00009978, 0x00000001 },
6964 { 0x0000997c, 0x00000000 }, 6964 { 0x0000997c, 0x00000000 },
@@ -7045,3 +7045,8 @@ static const u_int32_t ar9271Common_9271_1_0[][2] = {
7045 { 0x0000d380, 0x7f3c7bba }, 7045 { 0x0000d380, 0x7f3c7bba },
7046 { 0x0000d384, 0xf3307ff0 }, 7046 { 0x0000d384, 0xf3307ff0 },
7047}; 7047};
7048
7049static const u_int32_t ar9271Modes_9271_1_0_only[][6] = {
7050 { 0x00009910, 0x30002311, 0x30002311, 0x30002311, 0x30002311, 0x30002311 },
7051 { 0x00009828, 0x0a020001, 0x0a020001, 0x0a020001, 0x0a020001, 0x0a020001 },
7052};
diff --git a/drivers/net/wireless/ath/ath9k/main.c b/drivers/net/wireless/ath/ath9k/main.c
index 69cf702b18c2..9fefc51aec17 100644
--- a/drivers/net/wireless/ath/ath9k/main.c
+++ b/drivers/net/wireless/ath/ath9k/main.c
@@ -3191,64 +3191,6 @@ struct ieee80211_ops ath9k_ops = {
3191 .rfkill_poll = ath9k_rfkill_poll_state, 3191 .rfkill_poll = ath9k_rfkill_poll_state,
3192}; 3192};
3193 3193
3194static struct {
3195 u32 version;
3196 const char * name;
3197} ath_mac_bb_names[] = {
3198 { AR_SREV_VERSION_5416_PCI, "5416" },
3199 { AR_SREV_VERSION_5416_PCIE, "5418" },
3200 { AR_SREV_VERSION_9100, "9100" },
3201 { AR_SREV_VERSION_9160, "9160" },
3202 { AR_SREV_VERSION_9280, "9280" },
3203 { AR_SREV_VERSION_9285, "9285" },
3204 { AR_SREV_VERSION_9287, "9287" }
3205};
3206
3207static struct {
3208 u16 version;
3209 const char * name;
3210} ath_rf_names[] = {
3211 { 0, "5133" },
3212 { AR_RAD5133_SREV_MAJOR, "5133" },
3213 { AR_RAD5122_SREV_MAJOR, "5122" },
3214 { AR_RAD2133_SREV_MAJOR, "2133" },
3215 { AR_RAD2122_SREV_MAJOR, "2122" }
3216};
3217
3218/*
3219 * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
3220 */
3221const char *
3222ath_mac_bb_name(u32 mac_bb_version)
3223{
3224 int i;
3225
3226 for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
3227 if (ath_mac_bb_names[i].version == mac_bb_version) {
3228 return ath_mac_bb_names[i].name;
3229 }
3230 }
3231
3232 return "????";
3233}
3234
3235/*
3236 * Return the RF name. "????" is returned if the RF is unknown.
3237 */
3238const char *
3239ath_rf_name(u16 rf_version)
3240{
3241 int i;
3242
3243 for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
3244 if (ath_rf_names[i].version == rf_version) {
3245 return ath_rf_names[i].name;
3246 }
3247 }
3248
3249 return "????";
3250}
3251
3252static int __init ath9k_init(void) 3194static int __init ath9k_init(void)
3253{ 3195{
3254 int error; 3196 int error;
diff --git a/drivers/net/wireless/ath/ath9k/pci.c b/drivers/net/wireless/ath/ath9k/pci.c
index 63059b6a90da..5321f735e5a0 100644
--- a/drivers/net/wireless/ath/ath9k/pci.c
+++ b/drivers/net/wireless/ath/ath9k/pci.c
@@ -114,6 +114,7 @@ static int ath_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
114 u32 val; 114 u32 val;
115 int ret = 0; 115 int ret = 0;
116 struct ath_hw *ah; 116 struct ath_hw *ah;
117 char hw_name[64];
117 118
118 if (pci_enable_device(pdev)) 119 if (pci_enable_device(pdev))
119 return -EIO; 120 return -EIO;
@@ -218,14 +219,11 @@ static int ath_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
218 sc->irq = pdev->irq; 219 sc->irq = pdev->irq;
219 220
220 ah = sc->sc_ah; 221 ah = sc->sc_ah;
222 ath9k_hw_name(ah, hw_name, sizeof(hw_name));
221 printk(KERN_INFO 223 printk(KERN_INFO
222 "%s: Atheros AR%s MAC/BB Rev:%x " 224 "%s: %s mem=0x%lx, irq=%d\n",
223 "AR%s RF Rev:%x: mem=0x%lx, irq=%d\n",
224 wiphy_name(hw->wiphy), 225 wiphy_name(hw->wiphy),
225 ath_mac_bb_name(ah->hw_version.macVersion), 226 hw_name,
226 ah->hw_version.macRev,
227 ath_rf_name((ah->hw_version.analog5GhzRev & AR_RADIO_SREV_MAJOR)),
228 ah->hw_version.phyRev,
229 (unsigned long)mem, pdev->irq); 227 (unsigned long)mem, pdev->irq);
230 228
231 return 0; 229 return 0;
diff --git a/drivers/net/wireless/ath/ath9k/phy.c b/drivers/net/wireless/ath/ath9k/phy.c
index 72a17c43a5a0..13ab4d7eb7aa 100644
--- a/drivers/net/wireless/ath/ath9k/phy.c
+++ b/drivers/net/wireless/ath/ath9k/phy.c
@@ -14,91 +14,70 @@
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/**
18 * DOC: Programming Atheros 802.11n analog front end radios
19 *
20 * AR5416 MAC based PCI devices and AR518 MAC based PCI-Express
21 * devices have either an external AR2133 analog front end radio for single
22 * band 2.4 GHz communication or an AR5133 analog front end radio for dual
23 * band 2.4 GHz / 5 GHz communication.
24 *
25 * All devices after the AR5416 and AR5418 family starting with the AR9280
26 * have their analog front radios, MAC/BB and host PCIe/USB interface embedded
27 * into a single-chip and require less programming.
28 *
29 * The following single-chips exist with a respective embedded radio:
30 *
31 * AR9280 - 11n dual-band 2x2 MIMO for PCIe
32 * AR9281 - 11n single-band 1x2 MIMO for PCIe
33 * AR9285 - 11n single-band 1x1 for PCIe
34 * AR9287 - 11n single-band 2x2 MIMO for PCIe
35 *
36 * AR9220 - 11n dual-band 2x2 MIMO for PCI
37 * AR9223 - 11n single-band 2x2 MIMO for PCI
38 *
39 * AR9287 - 11n single-band 1x1 MIMO for USB
40 */
41
17#include "hw.h" 42#include "hw.h"
18 43
19void 44/**
20ath9k_hw_write_regs(struct ath_hw *ah, u32 modesIndex, u32 freqIndex, 45 * ath9k_hw_write_regs - ??
21 int regWrites) 46 *
47 * @ah: atheros hardware structure
48 * @freqIndex:
49 * @regWrites:
50 *
51 * Used for both the chipsets with an external AR2133/AR5133 radios and
52 * single-chip devices.
53 */
54void ath9k_hw_write_regs(struct ath_hw *ah, u32 freqIndex, int regWrites)
22{ 55{
23 REG_WRITE_ARRAY(&ah->iniBB_RfGain, freqIndex, regWrites); 56 REG_WRITE_ARRAY(&ah->iniBB_RfGain, freqIndex, regWrites);
24} 57}
25 58
26bool 59/**
27ath9k_hw_set_channel(struct ath_hw *ah, struct ath9k_channel *chan) 60 * ath9k_hw_ar9280_set_channel - set channel on single-chip device
28{ 61 * @ah: atheros hardware structure
29 struct ath_common *common = ath9k_hw_common(ah); 62 * @chan:
30 u32 channelSel = 0; 63 *
31 u32 bModeSynth = 0; 64 * This is the function to change channel on single-chip devices, that is
32 u32 aModeRefSel = 0; 65 * all devices after ar9280.
33 u32 reg32 = 0; 66 *
34 u16 freq; 67 * This function takes the channel value in MHz and sets
35 struct chan_centers centers; 68 * hardware channel value. Assumes writes have been enabled to analog bus.
36 69 *
37 ath9k_hw_get_channel_centers(ah, chan, &centers); 70 * Actual Expression,
38 freq = centers.synth_center; 71 *
39 72 * For 2GHz channel,
40 if (freq < 4800) { 73 * Channel Frequency = (3/4) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^17)
41 u32 txctl; 74 * (freq_ref = 40MHz)
42 75 *
43 if (((freq - 2192) % 5) == 0) { 76 * For 5GHz channel,
44 channelSel = ((freq - 672) * 2 - 3040) / 10; 77 * Channel Frequency = (3/2) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^10)
45 bModeSynth = 0; 78 * (freq_ref = 40MHz/(24>>amodeRefSel))
46 } else if (((freq - 2224) % 5) == 0) { 79 */
47 channelSel = ((freq - 704) * 2 - 3040) / 10; 80int ath9k_hw_ar9280_set_channel(struct ath_hw *ah, struct ath9k_channel *chan)
48 bModeSynth = 1;
49 } else {
50 ath_print(common, ATH_DBG_FATAL,
51 "Invalid channel %u MHz\n", freq);
52 return false;
53 }
54
55 channelSel = (channelSel << 2) & 0xff;
56 channelSel = ath9k_hw_reverse_bits(channelSel, 8);
57
58 txctl = REG_READ(ah, AR_PHY_CCK_TX_CTRL);
59 if (freq == 2484) {
60
61 REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
62 txctl | AR_PHY_CCK_TX_CTRL_JAPAN);
63 } else {
64 REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
65 txctl & ~AR_PHY_CCK_TX_CTRL_JAPAN);
66 }
67
68 } else if ((freq % 20) == 0 && freq >= 5120) {
69 channelSel =
70 ath9k_hw_reverse_bits(((freq - 4800) / 20 << 2), 8);
71 aModeRefSel = ath9k_hw_reverse_bits(1, 2);
72 } else if ((freq % 10) == 0) {
73 channelSel =
74 ath9k_hw_reverse_bits(((freq - 4800) / 10 << 1), 8);
75 if (AR_SREV_9100(ah) || AR_SREV_9160_10_OR_LATER(ah))
76 aModeRefSel = ath9k_hw_reverse_bits(2, 2);
77 else
78 aModeRefSel = ath9k_hw_reverse_bits(1, 2);
79 } else if ((freq % 5) == 0) {
80 channelSel = ath9k_hw_reverse_bits((freq - 4800) / 5, 8);
81 aModeRefSel = ath9k_hw_reverse_bits(1, 2);
82 } else {
83 ath_print(common, ATH_DBG_FATAL,
84 "Invalid channel %u MHz\n", freq);
85 return false;
86 }
87
88 reg32 =
89 (channelSel << 8) | (aModeRefSel << 2) | (bModeSynth << 1) |
90 (1 << 5) | 0x1;
91
92 REG_WRITE(ah, AR_PHY(0x37), reg32);
93
94 ah->curchan = chan;
95 ah->curchan_rad_index = -1;
96
97 return true;
98}
99
100void ath9k_hw_ar9280_set_channel(struct ath_hw *ah,
101 struct ath9k_channel *chan)
102{ 81{
103 u16 bMode, fracMode, aModeRefSel = 0; 82 u16 bMode, fracMode, aModeRefSel = 0;
104 u32 freq, ndiv, channelSel = 0, channelFrac = 0, reg32 = 0; 83 u32 freq, ndiv, channelSel = 0, channelFrac = 0, reg32 = 0;
@@ -111,7 +90,7 @@ void ath9k_hw_ar9280_set_channel(struct ath_hw *ah,
111 reg32 = REG_READ(ah, AR_PHY_SYNTH_CONTROL); 90 reg32 = REG_READ(ah, AR_PHY_SYNTH_CONTROL);
112 reg32 &= 0xc0000000; 91 reg32 &= 0xc0000000;
113 92
114 if (freq < 4800) { 93 if (freq < 4800) { /* 2 GHz, fractional mode */
115 u32 txctl; 94 u32 txctl;
116 int regWrites = 0; 95 int regWrites = 0;
117 96
@@ -122,6 +101,7 @@ void ath9k_hw_ar9280_set_channel(struct ath_hw *ah,
122 101
123 if (AR_SREV_9287_11_OR_LATER(ah)) { 102 if (AR_SREV_9287_11_OR_LATER(ah)) {
124 if (freq == 2484) { 103 if (freq == 2484) {
104 /* Enable channel spreading for channel 14 */
125 REG_WRITE_ARRAY(&ah->iniCckfirJapan2484, 105 REG_WRITE_ARRAY(&ah->iniCckfirJapan2484,
126 1, regWrites); 106 1, regWrites);
127 } else { 107 } else {
@@ -155,10 +135,15 @@ void ath9k_hw_ar9280_set_channel(struct ath_hw *ah,
155 case 1: 135 case 1:
156 default: 136 default:
157 aModeRefSel = 0; 137 aModeRefSel = 0;
138 /*
139 * Enable 2G (fractional) mode for channels
140 * which are 5MHz spaced.
141 */
158 fracMode = 1; 142 fracMode = 1;
159 refDivA = 1; 143 refDivA = 1;
160 channelSel = (freq * 0x8000) / 15; 144 channelSel = (freq * 0x8000) / 15;
161 145
146 /* RefDivA setting */
162 REG_RMW_FIELD(ah, AR_AN_SYNTH9, 147 REG_RMW_FIELD(ah, AR_AN_SYNTH9,
163 AR_AN_SYNTH9_REFDIVA, refDivA); 148 AR_AN_SYNTH9_REFDIVA, refDivA);
164 149
@@ -180,12 +165,284 @@ void ath9k_hw_ar9280_set_channel(struct ath_hw *ah,
180 165
181 ah->curchan = chan; 166 ah->curchan = chan;
182 ah->curchan_rad_index = -1; 167 ah->curchan_rad_index = -1;
168
169 return 0;
170}
171
172/**
173 * ath9k_hw_9280_spur_mitigate - convert baseband spur frequency
174 * @ah: atheros hardware structure
175 * @chan:
176 *
177 * For single-chip solutions. Converts to baseband spur frequency given the
178 * input channel frequency and compute register settings below.
179 */
180void ath9k_hw_9280_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan)
181{
182 int bb_spur = AR_NO_SPUR;
183 int freq;
184 int bin, cur_bin;
185 int bb_spur_off, spur_subchannel_sd;
186 int spur_freq_sd;
187 int spur_delta_phase;
188 int denominator;
189 int upper, lower, cur_vit_mask;
190 int tmp, newVal;
191 int i;
192 int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
193 AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
194 };
195 int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
196 AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
197 };
198 int inc[4] = { 0, 100, 0, 0 };
199 struct chan_centers centers;
200
201 int8_t mask_m[123];
202 int8_t mask_p[123];
203 int8_t mask_amt;
204 int tmp_mask;
205 int cur_bb_spur;
206 bool is2GHz = IS_CHAN_2GHZ(chan);
207
208 memset(&mask_m, 0, sizeof(int8_t) * 123);
209 memset(&mask_p, 0, sizeof(int8_t) * 123);
210
211 ath9k_hw_get_channel_centers(ah, chan, &centers);
212 freq = centers.synth_center;
213
214 ah->config.spurmode = SPUR_ENABLE_EEPROM;
215 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
216 cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
217
218 if (is2GHz)
219 cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_2GHZ;
220 else
221 cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_5GHZ;
222
223 if (AR_NO_SPUR == cur_bb_spur)
224 break;
225 cur_bb_spur = cur_bb_spur - freq;
226
227 if (IS_CHAN_HT40(chan)) {
228 if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT40) &&
229 (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT40)) {
230 bb_spur = cur_bb_spur;
231 break;
232 }
233 } else if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT20) &&
234 (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT20)) {
235 bb_spur = cur_bb_spur;
236 break;
237 }
238 }
239
240 if (AR_NO_SPUR == bb_spur) {
241 REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
242 AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
243 return;
244 } else {
245 REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
246 AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
247 }
248
249 bin = bb_spur * 320;
250
251 tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
252
253 newVal = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
254 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
255 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
256 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
257 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), newVal);
258
259 newVal = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
260 AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
261 AR_PHY_SPUR_REG_MASK_RATE_SELECT |
262 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
263 SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
264 REG_WRITE(ah, AR_PHY_SPUR_REG, newVal);
265
266 if (IS_CHAN_HT40(chan)) {
267 if (bb_spur < 0) {
268 spur_subchannel_sd = 1;
269 bb_spur_off = bb_spur + 10;
270 } else {
271 spur_subchannel_sd = 0;
272 bb_spur_off = bb_spur - 10;
273 }
274 } else {
275 spur_subchannel_sd = 0;
276 bb_spur_off = bb_spur;
277 }
278
279 if (IS_CHAN_HT40(chan))
280 spur_delta_phase =
281 ((bb_spur * 262144) /
282 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
283 else
284 spur_delta_phase =
285 ((bb_spur * 524288) /
286 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
287
288 denominator = IS_CHAN_2GHZ(chan) ? 44 : 40;
289 spur_freq_sd = ((bb_spur_off * 2048) / denominator) & 0x3ff;
290
291 newVal = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
292 SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
293 SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
294 REG_WRITE(ah, AR_PHY_TIMING11, newVal);
295
296 newVal = spur_subchannel_sd << AR_PHY_SFCORR_SPUR_SUBCHNL_SD_S;
297 REG_WRITE(ah, AR_PHY_SFCORR_EXT, newVal);
298
299 cur_bin = -6000;
300 upper = bin + 100;
301 lower = bin - 100;
302
303 for (i = 0; i < 4; i++) {
304 int pilot_mask = 0;
305 int chan_mask = 0;
306 int bp = 0;
307 for (bp = 0; bp < 30; bp++) {
308 if ((cur_bin > lower) && (cur_bin < upper)) {
309 pilot_mask = pilot_mask | 0x1 << bp;
310 chan_mask = chan_mask | 0x1 << bp;
311 }
312 cur_bin += 100;
313 }
314 cur_bin += inc[i];
315 REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
316 REG_WRITE(ah, chan_mask_reg[i], chan_mask);
317 }
318
319 cur_vit_mask = 6100;
320 upper = bin + 120;
321 lower = bin - 120;
322
323 for (i = 0; i < 123; i++) {
324 if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
325
326 /* workaround for gcc bug #37014 */
327 volatile int tmp_v = abs(cur_vit_mask - bin);
328
329 if (tmp_v < 75)
330 mask_amt = 1;
331 else
332 mask_amt = 0;
333 if (cur_vit_mask < 0)
334 mask_m[abs(cur_vit_mask / 100)] = mask_amt;
335 else
336 mask_p[cur_vit_mask / 100] = mask_amt;
337 }
338 cur_vit_mask -= 100;
339 }
340
341 tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
342 | (mask_m[48] << 26) | (mask_m[49] << 24)
343 | (mask_m[50] << 22) | (mask_m[51] << 20)
344 | (mask_m[52] << 18) | (mask_m[53] << 16)
345 | (mask_m[54] << 14) | (mask_m[55] << 12)
346 | (mask_m[56] << 10) | (mask_m[57] << 8)
347 | (mask_m[58] << 6) | (mask_m[59] << 4)
348 | (mask_m[60] << 2) | (mask_m[61] << 0);
349 REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
350 REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
351
352 tmp_mask = (mask_m[31] << 28)
353 | (mask_m[32] << 26) | (mask_m[33] << 24)
354 | (mask_m[34] << 22) | (mask_m[35] << 20)
355 | (mask_m[36] << 18) | (mask_m[37] << 16)
356 | (mask_m[48] << 14) | (mask_m[39] << 12)
357 | (mask_m[40] << 10) | (mask_m[41] << 8)
358 | (mask_m[42] << 6) | (mask_m[43] << 4)
359 | (mask_m[44] << 2) | (mask_m[45] << 0);
360 REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
361 REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
362
363 tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
364 | (mask_m[18] << 26) | (mask_m[18] << 24)
365 | (mask_m[20] << 22) | (mask_m[20] << 20)
366 | (mask_m[22] << 18) | (mask_m[22] << 16)
367 | (mask_m[24] << 14) | (mask_m[24] << 12)
368 | (mask_m[25] << 10) | (mask_m[26] << 8)
369 | (mask_m[27] << 6) | (mask_m[28] << 4)
370 | (mask_m[29] << 2) | (mask_m[30] << 0);
371 REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
372 REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
373
374 tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
375 | (mask_m[2] << 26) | (mask_m[3] << 24)
376 | (mask_m[4] << 22) | (mask_m[5] << 20)
377 | (mask_m[6] << 18) | (mask_m[7] << 16)
378 | (mask_m[8] << 14) | (mask_m[9] << 12)
379 | (mask_m[10] << 10) | (mask_m[11] << 8)
380 | (mask_m[12] << 6) | (mask_m[13] << 4)
381 | (mask_m[14] << 2) | (mask_m[15] << 0);
382 REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
383 REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
384
385 tmp_mask = (mask_p[15] << 28)
386 | (mask_p[14] << 26) | (mask_p[13] << 24)
387 | (mask_p[12] << 22) | (mask_p[11] << 20)
388 | (mask_p[10] << 18) | (mask_p[9] << 16)
389 | (mask_p[8] << 14) | (mask_p[7] << 12)
390 | (mask_p[6] << 10) | (mask_p[5] << 8)
391 | (mask_p[4] << 6) | (mask_p[3] << 4)
392 | (mask_p[2] << 2) | (mask_p[1] << 0);
393 REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
394 REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
395
396 tmp_mask = (mask_p[30] << 28)
397 | (mask_p[29] << 26) | (mask_p[28] << 24)
398 | (mask_p[27] << 22) | (mask_p[26] << 20)
399 | (mask_p[25] << 18) | (mask_p[24] << 16)
400 | (mask_p[23] << 14) | (mask_p[22] << 12)
401 | (mask_p[21] << 10) | (mask_p[20] << 8)
402 | (mask_p[19] << 6) | (mask_p[18] << 4)
403 | (mask_p[17] << 2) | (mask_p[16] << 0);
404 REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
405 REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
406
407 tmp_mask = (mask_p[45] << 28)
408 | (mask_p[44] << 26) | (mask_p[43] << 24)
409 | (mask_p[42] << 22) | (mask_p[41] << 20)
410 | (mask_p[40] << 18) | (mask_p[39] << 16)
411 | (mask_p[38] << 14) | (mask_p[37] << 12)
412 | (mask_p[36] << 10) | (mask_p[35] << 8)
413 | (mask_p[34] << 6) | (mask_p[33] << 4)
414 | (mask_p[32] << 2) | (mask_p[31] << 0);
415 REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
416 REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
417
418 tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
419 | (mask_p[59] << 26) | (mask_p[58] << 24)
420 | (mask_p[57] << 22) | (mask_p[56] << 20)
421 | (mask_p[55] << 18) | (mask_p[54] << 16)
422 | (mask_p[53] << 14) | (mask_p[52] << 12)
423 | (mask_p[51] << 10) | (mask_p[50] << 8)
424 | (mask_p[49] << 6) | (mask_p[48] << 4)
425 | (mask_p[47] << 2) | (mask_p[46] << 0);
426 REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
427 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
183} 428}
184 429
185static void 430/* All code below is for non single-chip solutions */
186ath9k_phy_modify_rx_buffer(u32 *rfBuf, u32 reg32, 431
187 u32 numBits, u32 firstBit, 432/**
188 u32 column) 433 * ath9k_phy_modify_rx_buffer() - perform analog swizzling of parameters
434 * @rfbuf:
435 * @reg32:
436 * @numBits:
437 * @firstBit:
438 * @column:
439 *
440 * Performs analog "swizzling" of parameters into their location.
441 * Used on external AR2133/AR5133 radios.
442 */
443static void ath9k_phy_modify_rx_buffer(u32 *rfBuf, u32 reg32,
444 u32 numBits, u32 firstBit,
445 u32 column)
189{ 446{
190 u32 tmp32, mask, arrayEntry, lastBit; 447 u32 tmp32, mask, arrayEntry, lastBit;
191 int32_t bitPosition, bitsLeft; 448 int32_t bitPosition, bitsLeft;
@@ -209,26 +466,556 @@ ath9k_phy_modify_rx_buffer(u32 *rfBuf, u32 reg32,
209 } 466 }
210} 467}
211 468
212bool 469/*
213ath9k_hw_set_rf_regs(struct ath_hw *ah, struct ath9k_channel *chan, 470 * Fix on 2.4 GHz band for orientation sensitivity issue by increasing
214 u16 modesIndex) 471 * rf_pwd_icsyndiv.
472 *
473 * Theoretical Rules:
474 * if 2 GHz band
475 * if forceBiasAuto
476 * if synth_freq < 2412
477 * bias = 0
478 * else if 2412 <= synth_freq <= 2422
479 * bias = 1
480 * else // synth_freq > 2422
481 * bias = 2
482 * else if forceBias > 0
483 * bias = forceBias & 7
484 * else
485 * no change, use value from ini file
486 * else
487 * no change, invalid band
488 *
489 * 1st Mod:
490 * 2422 also uses value of 2
491 * <approved>
492 *
493 * 2nd Mod:
494 * Less than 2412 uses value of 0, 2412 and above uses value of 2
495 */
496static void ath9k_hw_force_bias(struct ath_hw *ah, u16 synth_freq)
497{
498 struct ath_common *common = ath9k_hw_common(ah);
499 u32 tmp_reg;
500 int reg_writes = 0;
501 u32 new_bias = 0;
502
503 if (!AR_SREV_5416(ah) || synth_freq >= 3000) {
504 return;
505 }
506
507 BUG_ON(AR_SREV_9280_10_OR_LATER(ah));
508
509 if (synth_freq < 2412)
510 new_bias = 0;
511 else if (synth_freq < 2422)
512 new_bias = 1;
513 else
514 new_bias = 2;
515
516 /* pre-reverse this field */
517 tmp_reg = ath9k_hw_reverse_bits(new_bias, 3);
518
519 ath_print(common, ATH_DBG_CONFIG,
520 "Force rf_pwd_icsyndiv to %1d on %4d\n",
521 new_bias, synth_freq);
522
523 /* swizzle rf_pwd_icsyndiv */
524 ath9k_phy_modify_rx_buffer(ah->analogBank6Data, tmp_reg, 3, 181, 3);
525
526 /* write Bank 6 with new params */
527 REG_WRITE_RF_ARRAY(&ah->iniBank6, ah->analogBank6Data, reg_writes);
528}
529
530/**
531 * ath9k_hw_decrease_chain_power()
532 *
533 * @ah: atheros hardware structure
534 * @chan:
535 *
536 * Only used on the AR5416 and AR5418 with the external AR2133/AR5133 radios.
537 *
538 * Sets a chain internal RF path to the lowest output power. Any
539 * further writes to bank6 after this setting will override these
540 * changes. Thus this function must be the last function in the
541 * sequence to modify bank 6.
542 *
543 * This function must be called after ar5416SetRfRegs() which is
544 * called from ath9k_hw_process_ini() due to swizzling of bank 6.
545 * Depends on ah->analogBank6Data being initialized by
546 * ath9k_hw_set_rf_regs()
547 *
548 * Additional additive reduction in power -
549 * change chain's switch table so chain's tx state is actually the rx
550 * state value. May produce different results in 2GHz/5GHz as well as
551 * board to board but in general should be a reduction.
552 *
553 * Activated by #ifdef ALTER_SWITCH. Not tried yet. If so, must be
554 * called after ah->eep_ops->set_board_values() due to RMW of
555 * PHY_SWITCH_CHAIN_0.
556 */
557void ath9k_hw_decrease_chain_power(struct ath_hw *ah,
558 struct ath9k_channel *chan)
559{
560 int i, regWrites = 0;
561 u32 bank6SelMask;
562 u32 *bank6Temp = ah->bank6Temp;
563
564 BUG_ON(AR_SREV_9280_10_OR_LATER(ah));
565
566 switch (ah->config.diversity_control) {
567 case ATH9K_ANT_FIXED_A:
568 bank6SelMask =
569 (ah->config.antenna_switch_swap & ANTSWAP_AB) ?
570 REDUCE_CHAIN_0 : /* swapped, reduce chain 0 */
571 REDUCE_CHAIN_1; /* normal, select chain 1/2 to reduce */
572 break;
573 case ATH9K_ANT_FIXED_B:
574 bank6SelMask =
575 (ah->config.antenna_switch_swap & ANTSWAP_AB) ?
576 REDUCE_CHAIN_1 : /* swapped, reduce chain 1/2 */
577 REDUCE_CHAIN_0; /* normal, select chain 0 to reduce */
578 break;
579 case ATH9K_ANT_VARIABLE:
580 return; /* do not change anything */
581 break;
582 default:
583 return; /* do not change anything */
584 break;
585 }
586
587 for (i = 0; i < ah->iniBank6.ia_rows; i++)
588 bank6Temp[i] = ah->analogBank6Data[i];
589
590 /* Write Bank 5 to switch Bank 6 write to selected chain only */
591 REG_WRITE(ah, AR_PHY_BASE + 0xD8, bank6SelMask);
592
593 /*
594 * Modify Bank6 selected chain to use lowest amplification.
595 * Modifies the parameters to a value of 1.
596 * Depends on existing bank 6 values to be cached in
597 * ah->analogBank6Data
598 */
599 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 189, 0);
600 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 190, 0);
601 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 191, 0);
602 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 192, 0);
603 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 193, 0);
604 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 222, 0);
605 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 245, 0);
606 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 246, 0);
607 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 247, 0);
608
609 REG_WRITE_RF_ARRAY(&ah->iniBank6, bank6Temp, regWrites);
610
611 REG_WRITE(ah, AR_PHY_BASE + 0xD8, 0x00000053);
612#ifdef ALTER_SWITCH
613 REG_WRITE(ah, PHY_SWITCH_CHAIN_0,
614 (REG_READ(ah, PHY_SWITCH_CHAIN_0) & ~0x38)
615 | ((REG_READ(ah, PHY_SWITCH_CHAIN_0) >> 3) & 0x38));
616#endif
617}
618
619/**
620 * ath9k_hw_set_channel - tune to a channel on the external AR2133/AR5133 radios
621 * @ah: atheros hardware stucture
622 * @chan:
623 *
624 * For the external AR2133/AR5133 radios, takes the MHz channel value and set
625 * the channel value. Assumes writes enabled to analog bus and bank6 register
626 * cache in ah->analogBank6Data.
627 */
628int ath9k_hw_set_channel(struct ath_hw *ah, struct ath9k_channel *chan)
629{
630 struct ath_common *common = ath9k_hw_common(ah);
631 u32 channelSel = 0;
632 u32 bModeSynth = 0;
633 u32 aModeRefSel = 0;
634 u32 reg32 = 0;
635 u16 freq;
636 struct chan_centers centers;
637
638 ath9k_hw_get_channel_centers(ah, chan, &centers);
639 freq = centers.synth_center;
640
641 if (freq < 4800) {
642 u32 txctl;
643
644 if (((freq - 2192) % 5) == 0) {
645 channelSel = ((freq - 672) * 2 - 3040) / 10;
646 bModeSynth = 0;
647 } else if (((freq - 2224) % 5) == 0) {
648 channelSel = ((freq - 704) * 2 - 3040) / 10;
649 bModeSynth = 1;
650 } else {
651 ath_print(common, ATH_DBG_FATAL,
652 "Invalid channel %u MHz\n", freq);
653 return -EINVAL;
654 }
655
656 channelSel = (channelSel << 2) & 0xff;
657 channelSel = ath9k_hw_reverse_bits(channelSel, 8);
658
659 txctl = REG_READ(ah, AR_PHY_CCK_TX_CTRL);
660 if (freq == 2484) {
661
662 REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
663 txctl | AR_PHY_CCK_TX_CTRL_JAPAN);
664 } else {
665 REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
666 txctl & ~AR_PHY_CCK_TX_CTRL_JAPAN);
667 }
668
669 } else if ((freq % 20) == 0 && freq >= 5120) {
670 channelSel =
671 ath9k_hw_reverse_bits(((freq - 4800) / 20 << 2), 8);
672 aModeRefSel = ath9k_hw_reverse_bits(1, 2);
673 } else if ((freq % 10) == 0) {
674 channelSel =
675 ath9k_hw_reverse_bits(((freq - 4800) / 10 << 1), 8);
676 if (AR_SREV_9100(ah) || AR_SREV_9160_10_OR_LATER(ah))
677 aModeRefSel = ath9k_hw_reverse_bits(2, 2);
678 else
679 aModeRefSel = ath9k_hw_reverse_bits(1, 2);
680 } else if ((freq % 5) == 0) {
681 channelSel = ath9k_hw_reverse_bits((freq - 4800) / 5, 8);
682 aModeRefSel = ath9k_hw_reverse_bits(1, 2);
683 } else {
684 ath_print(common, ATH_DBG_FATAL,
685 "Invalid channel %u MHz\n", freq);
686 return -EINVAL;
687 }
688
689 ath9k_hw_force_bias(ah, freq);
690 ath9k_hw_decrease_chain_power(ah, chan);
691
692 reg32 =
693 (channelSel << 8) | (aModeRefSel << 2) | (bModeSynth << 1) |
694 (1 << 5) | 0x1;
695
696 REG_WRITE(ah, AR_PHY(0x37), reg32);
697
698 ah->curchan = chan;
699 ah->curchan_rad_index = -1;
700
701 return 0;
702}
703
704/**
705 * ath9k_hw_spur_mitigate - convert baseband spur frequency for external radios
706 * @ah: atheros hardware structure
707 * @chan:
708 *
709 * For non single-chip solutions. Converts to baseband spur frequency given the
710 * input channel frequency and compute register settings below.
711 */
712void ath9k_hw_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan)
713{
714 int bb_spur = AR_NO_SPUR;
715 int bin, cur_bin;
716 int spur_freq_sd;
717 int spur_delta_phase;
718 int denominator;
719 int upper, lower, cur_vit_mask;
720 int tmp, new;
721 int i;
722 int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
723 AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
724 };
725 int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
726 AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
727 };
728 int inc[4] = { 0, 100, 0, 0 };
729
730 int8_t mask_m[123];
731 int8_t mask_p[123];
732 int8_t mask_amt;
733 int tmp_mask;
734 int cur_bb_spur;
735 bool is2GHz = IS_CHAN_2GHZ(chan);
736
737 memset(&mask_m, 0, sizeof(int8_t) * 123);
738 memset(&mask_p, 0, sizeof(int8_t) * 123);
739
740 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
741 cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
742 if (AR_NO_SPUR == cur_bb_spur)
743 break;
744 cur_bb_spur = cur_bb_spur - (chan->channel * 10);
745 if ((cur_bb_spur > -95) && (cur_bb_spur < 95)) {
746 bb_spur = cur_bb_spur;
747 break;
748 }
749 }
750
751 if (AR_NO_SPUR == bb_spur)
752 return;
753
754 bin = bb_spur * 32;
755
756 tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
757 new = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
758 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
759 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
760 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
761
762 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), new);
763
764 new = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
765 AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
766 AR_PHY_SPUR_REG_MASK_RATE_SELECT |
767 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
768 SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
769 REG_WRITE(ah, AR_PHY_SPUR_REG, new);
770
771 spur_delta_phase = ((bb_spur * 524288) / 100) &
772 AR_PHY_TIMING11_SPUR_DELTA_PHASE;
773
774 denominator = IS_CHAN_2GHZ(chan) ? 440 : 400;
775 spur_freq_sd = ((bb_spur * 2048) / denominator) & 0x3ff;
776
777 new = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
778 SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
779 SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
780 REG_WRITE(ah, AR_PHY_TIMING11, new);
781
782 cur_bin = -6000;
783 upper = bin + 100;
784 lower = bin - 100;
785
786 for (i = 0; i < 4; i++) {
787 int pilot_mask = 0;
788 int chan_mask = 0;
789 int bp = 0;
790 for (bp = 0; bp < 30; bp++) {
791 if ((cur_bin > lower) && (cur_bin < upper)) {
792 pilot_mask = pilot_mask | 0x1 << bp;
793 chan_mask = chan_mask | 0x1 << bp;
794 }
795 cur_bin += 100;
796 }
797 cur_bin += inc[i];
798 REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
799 REG_WRITE(ah, chan_mask_reg[i], chan_mask);
800 }
801
802 cur_vit_mask = 6100;
803 upper = bin + 120;
804 lower = bin - 120;
805
806 for (i = 0; i < 123; i++) {
807 if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
808
809 /* workaround for gcc bug #37014 */
810 volatile int tmp_v = abs(cur_vit_mask - bin);
811
812 if (tmp_v < 75)
813 mask_amt = 1;
814 else
815 mask_amt = 0;
816 if (cur_vit_mask < 0)
817 mask_m[abs(cur_vit_mask / 100)] = mask_amt;
818 else
819 mask_p[cur_vit_mask / 100] = mask_amt;
820 }
821 cur_vit_mask -= 100;
822 }
823
824 tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
825 | (mask_m[48] << 26) | (mask_m[49] << 24)
826 | (mask_m[50] << 22) | (mask_m[51] << 20)
827 | (mask_m[52] << 18) | (mask_m[53] << 16)
828 | (mask_m[54] << 14) | (mask_m[55] << 12)
829 | (mask_m[56] << 10) | (mask_m[57] << 8)
830 | (mask_m[58] << 6) | (mask_m[59] << 4)
831 | (mask_m[60] << 2) | (mask_m[61] << 0);
832 REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
833 REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
834
835 tmp_mask = (mask_m[31] << 28)
836 | (mask_m[32] << 26) | (mask_m[33] << 24)
837 | (mask_m[34] << 22) | (mask_m[35] << 20)
838 | (mask_m[36] << 18) | (mask_m[37] << 16)
839 | (mask_m[48] << 14) | (mask_m[39] << 12)
840 | (mask_m[40] << 10) | (mask_m[41] << 8)
841 | (mask_m[42] << 6) | (mask_m[43] << 4)
842 | (mask_m[44] << 2) | (mask_m[45] << 0);
843 REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
844 REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
845
846 tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
847 | (mask_m[18] << 26) | (mask_m[18] << 24)
848 | (mask_m[20] << 22) | (mask_m[20] << 20)
849 | (mask_m[22] << 18) | (mask_m[22] << 16)
850 | (mask_m[24] << 14) | (mask_m[24] << 12)
851 | (mask_m[25] << 10) | (mask_m[26] << 8)
852 | (mask_m[27] << 6) | (mask_m[28] << 4)
853 | (mask_m[29] << 2) | (mask_m[30] << 0);
854 REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
855 REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
856
857 tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
858 | (mask_m[2] << 26) | (mask_m[3] << 24)
859 | (mask_m[4] << 22) | (mask_m[5] << 20)
860 | (mask_m[6] << 18) | (mask_m[7] << 16)
861 | (mask_m[8] << 14) | (mask_m[9] << 12)
862 | (mask_m[10] << 10) | (mask_m[11] << 8)
863 | (mask_m[12] << 6) | (mask_m[13] << 4)
864 | (mask_m[14] << 2) | (mask_m[15] << 0);
865 REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
866 REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
867
868 tmp_mask = (mask_p[15] << 28)
869 | (mask_p[14] << 26) | (mask_p[13] << 24)
870 | (mask_p[12] << 22) | (mask_p[11] << 20)
871 | (mask_p[10] << 18) | (mask_p[9] << 16)
872 | (mask_p[8] << 14) | (mask_p[7] << 12)
873 | (mask_p[6] << 10) | (mask_p[5] << 8)
874 | (mask_p[4] << 6) | (mask_p[3] << 4)
875 | (mask_p[2] << 2) | (mask_p[1] << 0);
876 REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
877 REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
878
879 tmp_mask = (mask_p[30] << 28)
880 | (mask_p[29] << 26) | (mask_p[28] << 24)
881 | (mask_p[27] << 22) | (mask_p[26] << 20)
882 | (mask_p[25] << 18) | (mask_p[24] << 16)
883 | (mask_p[23] << 14) | (mask_p[22] << 12)
884 | (mask_p[21] << 10) | (mask_p[20] << 8)
885 | (mask_p[19] << 6) | (mask_p[18] << 4)
886 | (mask_p[17] << 2) | (mask_p[16] << 0);
887 REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
888 REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
889
890 tmp_mask = (mask_p[45] << 28)
891 | (mask_p[44] << 26) | (mask_p[43] << 24)
892 | (mask_p[42] << 22) | (mask_p[41] << 20)
893 | (mask_p[40] << 18) | (mask_p[39] << 16)
894 | (mask_p[38] << 14) | (mask_p[37] << 12)
895 | (mask_p[36] << 10) | (mask_p[35] << 8)
896 | (mask_p[34] << 6) | (mask_p[33] << 4)
897 | (mask_p[32] << 2) | (mask_p[31] << 0);
898 REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
899 REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
900
901 tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
902 | (mask_p[59] << 26) | (mask_p[58] << 24)
903 | (mask_p[57] << 22) | (mask_p[56] << 20)
904 | (mask_p[55] << 18) | (mask_p[54] << 16)
905 | (mask_p[53] << 14) | (mask_p[52] << 12)
906 | (mask_p[51] << 10) | (mask_p[50] << 8)
907 | (mask_p[49] << 6) | (mask_p[48] << 4)
908 | (mask_p[47] << 2) | (mask_p[46] << 0);
909 REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
910 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
911}
912
913/**
914 * ath9k_hw_rf_alloc_ext_banks - allocates banks for external radio programming
915 * @ah: atheros hardware structure
916 *
917 * Only required for older devices with external AR2133/AR5133 radios.
918 */
919int ath9k_hw_rf_alloc_ext_banks(struct ath_hw *ah)
920{
921#define ATH_ALLOC_BANK(bank, size) do { \
922 bank = kzalloc((sizeof(u32) * size), GFP_KERNEL); \
923 if (!bank) { \
924 ath_print(common, ATH_DBG_FATAL, \
925 "Cannot allocate RF banks\n"); \
926 return -ENOMEM; \
927 } \
928 } while (0);
929
930 struct ath_common *common = ath9k_hw_common(ah);
931
932 BUG_ON(AR_SREV_9280_10_OR_LATER(ah));
933
934 ATH_ALLOC_BANK(ah->analogBank0Data, ah->iniBank0.ia_rows);
935 ATH_ALLOC_BANK(ah->analogBank1Data, ah->iniBank1.ia_rows);
936 ATH_ALLOC_BANK(ah->analogBank2Data, ah->iniBank2.ia_rows);
937 ATH_ALLOC_BANK(ah->analogBank3Data, ah->iniBank3.ia_rows);
938 ATH_ALLOC_BANK(ah->analogBank6Data, ah->iniBank6.ia_rows);
939 ATH_ALLOC_BANK(ah->analogBank6TPCData, ah->iniBank6TPC.ia_rows);
940 ATH_ALLOC_BANK(ah->analogBank7Data, ah->iniBank7.ia_rows);
941 ATH_ALLOC_BANK(ah->addac5416_21,
942 ah->iniAddac.ia_rows * ah->iniAddac.ia_columns);
943 ATH_ALLOC_BANK(ah->bank6Temp, ah->iniBank6.ia_rows);
944
945 return 0;
946#undef ATH_ALLOC_BANK
947}
948
949
950/**
951 * ath9k_hw_rf_free_ext_banks - Free memory for analog bank scratch buffers
952 * @ah: atheros hardware struture
953 * For the external AR2133/AR5133 radios banks.
954 */
955void
956ath9k_hw_rf_free_ext_banks(struct ath_hw *ah)
957{
958#define ATH_FREE_BANK(bank) do { \
959 kfree(bank); \
960 bank = NULL; \
961 } while (0);
962
963 BUG_ON(AR_SREV_9280_10_OR_LATER(ah));
964
965 ATH_FREE_BANK(ah->analogBank0Data);
966 ATH_FREE_BANK(ah->analogBank1Data);
967 ATH_FREE_BANK(ah->analogBank2Data);
968 ATH_FREE_BANK(ah->analogBank3Data);
969 ATH_FREE_BANK(ah->analogBank6Data);
970 ATH_FREE_BANK(ah->analogBank6TPCData);
971 ATH_FREE_BANK(ah->analogBank7Data);
972 ATH_FREE_BANK(ah->addac5416_21);
973 ATH_FREE_BANK(ah->bank6Temp);
974
975#undef ATH_FREE_BANK
976}
977
978/* *
979 * ath9k_hw_set_rf_regs - programs rf registers based on EEPROM
980 * @ah: atheros hardware structure
981 * @chan:
982 * @modesIndex:
983 *
984 * Used for the external AR2133/AR5133 radios.
985 *
986 * Reads the EEPROM header info from the device structure and programs
987 * all rf registers. This routine requires access to the analog
988 * rf device. This is not required for single-chip devices.
989 */
990bool ath9k_hw_set_rf_regs(struct ath_hw *ah, struct ath9k_channel *chan,
991 u16 modesIndex)
215{ 992{
216 u32 eepMinorRev; 993 u32 eepMinorRev;
217 u32 ob5GHz = 0, db5GHz = 0; 994 u32 ob5GHz = 0, db5GHz = 0;
218 u32 ob2GHz = 0, db2GHz = 0; 995 u32 ob2GHz = 0, db2GHz = 0;
219 int regWrites = 0; 996 int regWrites = 0;
220 997
998 /*
999 * Software does not need to program bank data
1000 * for single chip devices, that is AR9280 or anything
1001 * after that.
1002 */
221 if (AR_SREV_9280_10_OR_LATER(ah)) 1003 if (AR_SREV_9280_10_OR_LATER(ah))
222 return true; 1004 return true;
223 1005
1006 /* Setup rf parameters */
224 eepMinorRev = ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV); 1007 eepMinorRev = ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV);
225 1008
1009 /* Setup Bank 0 Write */
226 RF_BANK_SETUP(ah->analogBank0Data, &ah->iniBank0, 1); 1010 RF_BANK_SETUP(ah->analogBank0Data, &ah->iniBank0, 1);
227 1011
1012 /* Setup Bank 1 Write */
228 RF_BANK_SETUP(ah->analogBank1Data, &ah->iniBank1, 1); 1013 RF_BANK_SETUP(ah->analogBank1Data, &ah->iniBank1, 1);
229 1014
1015 /* Setup Bank 2 Write */
230 RF_BANK_SETUP(ah->analogBank2Data, &ah->iniBank2, 1); 1016 RF_BANK_SETUP(ah->analogBank2Data, &ah->iniBank2, 1);
231 1017
1018 /* Setup Bank 6 Write */
232 RF_BANK_SETUP(ah->analogBank3Data, &ah->iniBank3, 1019 RF_BANK_SETUP(ah->analogBank3Data, &ah->iniBank3,
233 modesIndex); 1020 modesIndex);
234 { 1021 {
@@ -239,6 +1026,7 @@ ath9k_hw_set_rf_regs(struct ath_hw *ah, struct ath9k_channel *chan,
239 } 1026 }
240 } 1027 }
241 1028
1029 /* Only the 5 or 2 GHz OB/DB need to be set for a mode */
242 if (eepMinorRev >= 2) { 1030 if (eepMinorRev >= 2) {
243 if (IS_CHAN_2GHZ(chan)) { 1031 if (IS_CHAN_2GHZ(chan)) {
244 ob2GHz = ah->eep_ops->get_eeprom(ah, EEP_OB_2); 1032 ob2GHz = ah->eep_ops->get_eeprom(ah, EEP_OB_2);
@@ -257,8 +1045,10 @@ ath9k_hw_set_rf_regs(struct ath_hw *ah, struct ath9k_channel *chan,
257 } 1045 }
258 } 1046 }
259 1047
1048 /* Setup Bank 7 Setup */
260 RF_BANK_SETUP(ah->analogBank7Data, &ah->iniBank7, 1); 1049 RF_BANK_SETUP(ah->analogBank7Data, &ah->iniBank7, 1);
261 1050
1051 /* Write Analog registers */
262 REG_WRITE_RF_ARRAY(&ah->iniBank0, ah->analogBank0Data, 1052 REG_WRITE_RF_ARRAY(&ah->iniBank0, ah->analogBank0Data,
263 regWrites); 1053 regWrites);
264 REG_WRITE_RF_ARRAY(&ah->iniBank1, ah->analogBank1Data, 1054 REG_WRITE_RF_ARRAY(&ah->iniBank1, ah->analogBank1Data,
@@ -274,139 +1064,3 @@ ath9k_hw_set_rf_regs(struct ath_hw *ah, struct ath9k_channel *chan,
274 1064
275 return true; 1065 return true;
276} 1066}
277
278void
279ath9k_hw_rf_free(struct ath_hw *ah)
280{
281#define ATH_FREE_BANK(bank) do { \
282 kfree(bank); \
283 bank = NULL; \
284 } while (0);
285
286 ATH_FREE_BANK(ah->analogBank0Data);
287 ATH_FREE_BANK(ah->analogBank1Data);
288 ATH_FREE_BANK(ah->analogBank2Data);
289 ATH_FREE_BANK(ah->analogBank3Data);
290 ATH_FREE_BANK(ah->analogBank6Data);
291 ATH_FREE_BANK(ah->analogBank6TPCData);
292 ATH_FREE_BANK(ah->analogBank7Data);
293 ATH_FREE_BANK(ah->addac5416_21);
294 ATH_FREE_BANK(ah->bank6Temp);
295#undef ATH_FREE_BANK
296}
297
298bool ath9k_hw_init_rf(struct ath_hw *ah, int *status)
299{
300 struct ath_common *common = ath9k_hw_common(ah);
301
302 if (!AR_SREV_9280_10_OR_LATER(ah)) {
303 ah->analogBank0Data =
304 kzalloc((sizeof(u32) *
305 ah->iniBank0.ia_rows), GFP_KERNEL);
306 ah->analogBank1Data =
307 kzalloc((sizeof(u32) *
308 ah->iniBank1.ia_rows), GFP_KERNEL);
309 ah->analogBank2Data =
310 kzalloc((sizeof(u32) *
311 ah->iniBank2.ia_rows), GFP_KERNEL);
312 ah->analogBank3Data =
313 kzalloc((sizeof(u32) *
314 ah->iniBank3.ia_rows), GFP_KERNEL);
315 ah->analogBank6Data =
316 kzalloc((sizeof(u32) *
317 ah->iniBank6.ia_rows), GFP_KERNEL);
318 ah->analogBank6TPCData =
319 kzalloc((sizeof(u32) *
320 ah->iniBank6TPC.ia_rows), GFP_KERNEL);
321 ah->analogBank7Data =
322 kzalloc((sizeof(u32) *
323 ah->iniBank7.ia_rows), GFP_KERNEL);
324
325 if (ah->analogBank0Data == NULL
326 || ah->analogBank1Data == NULL
327 || ah->analogBank2Data == NULL
328 || ah->analogBank3Data == NULL
329 || ah->analogBank6Data == NULL
330 || ah->analogBank6TPCData == NULL
331 || ah->analogBank7Data == NULL) {
332 ath_print(common, ATH_DBG_FATAL,
333 "Cannot allocate RF banks\n");
334 *status = -ENOMEM;
335 return false;
336 }
337
338 ah->addac5416_21 =
339 kzalloc((sizeof(u32) *
340 ah->iniAddac.ia_rows *
341 ah->iniAddac.ia_columns), GFP_KERNEL);
342 if (ah->addac5416_21 == NULL) {
343 ath_print(common, ATH_DBG_FATAL,
344 "Cannot allocate addac5416_21\n");
345 *status = -ENOMEM;
346 return false;
347 }
348
349 ah->bank6Temp =
350 kzalloc((sizeof(u32) *
351 ah->iniBank6.ia_rows), GFP_KERNEL);
352 if (ah->bank6Temp == NULL) {
353 ath_print(common, ATH_DBG_FATAL,
354 "Cannot allocate bank6Temp\n");
355 *status = -ENOMEM;
356 return false;
357 }
358 }
359
360 return true;
361}
362
363void
364ath9k_hw_decrease_chain_power(struct ath_hw *ah, struct ath9k_channel *chan)
365{
366 int i, regWrites = 0;
367 u32 bank6SelMask;
368 u32 *bank6Temp = ah->bank6Temp;
369
370 switch (ah->config.diversity_control) {
371 case ATH9K_ANT_FIXED_A:
372 bank6SelMask =
373 (ah->config.antenna_switch_swap & ANTSWAP_AB) ?
374 REDUCE_CHAIN_0 : REDUCE_CHAIN_1;
375 break;
376 case ATH9K_ANT_FIXED_B:
377 bank6SelMask =
378 (ah->config.antenna_switch_swap & ANTSWAP_AB) ?
379 REDUCE_CHAIN_1 : REDUCE_CHAIN_0;
380 break;
381 case ATH9K_ANT_VARIABLE:
382 return;
383 break;
384 default:
385 return;
386 break;
387 }
388
389 for (i = 0; i < ah->iniBank6.ia_rows; i++)
390 bank6Temp[i] = ah->analogBank6Data[i];
391
392 REG_WRITE(ah, AR_PHY_BASE + 0xD8, bank6SelMask);
393
394 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 189, 0);
395 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 190, 0);
396 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 191, 0);
397 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 192, 0);
398 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 193, 0);
399 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 222, 0);
400 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 245, 0);
401 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 246, 0);
402 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 247, 0);
403
404 REG_WRITE_RF_ARRAY(&ah->iniBank6, bank6Temp, regWrites);
405
406 REG_WRITE(ah, AR_PHY_BASE + 0xD8, 0x00000053);
407#ifdef ALTER_SWITCH
408 REG_WRITE(ah, PHY_SWITCH_CHAIN_0,
409 (REG_READ(ah, PHY_SWITCH_CHAIN_0) & ~0x38)
410 | ((REG_READ(ah, PHY_SWITCH_CHAIN_0) >> 3) & 0x38));
411#endif
412}
diff --git a/drivers/net/wireless/ath/ath9k/phy.h b/drivers/net/wireless/ath/ath9k/phy.h
index 140fef74c666..dc145a135dc7 100644
--- a/drivers/net/wireless/ath/ath9k/phy.h
+++ b/drivers/net/wireless/ath/ath9k/phy.h
@@ -17,20 +17,26 @@
17#ifndef PHY_H 17#ifndef PHY_H
18#define PHY_H 18#define PHY_H
19 19
20void ath9k_hw_ar9280_set_channel(struct ath_hw *ah, 20/* Common between single chip and non single-chip solutions */
21 struct ath9k_channel 21void ath9k_hw_write_regs(struct ath_hw *ah, u32 freqIndex, int regWrites);
22 *chan); 22
23bool ath9k_hw_set_channel(struct ath_hw *ah, 23/* Single chip radio settings */
24 struct ath9k_channel *chan); 24int ath9k_hw_ar9280_set_channel(struct ath_hw *ah, struct ath9k_channel *chan);
25void ath9k_hw_write_regs(struct ath_hw *ah, u32 modesIndex, 25void ath9k_hw_9280_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan);
26 u32 freqIndex, int regWrites); 26
27/* Routines below are for non single-chip solutions */
28int ath9k_hw_set_channel(struct ath_hw *ah, struct ath9k_channel *chan);
29void ath9k_hw_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan);
30
31int ath9k_hw_rf_alloc_ext_banks(struct ath_hw *ah);
32void ath9k_hw_rf_free_ext_banks(struct ath_hw *ah);
33
27bool ath9k_hw_set_rf_regs(struct ath_hw *ah, 34bool ath9k_hw_set_rf_regs(struct ath_hw *ah,
28 struct ath9k_channel *chan, 35 struct ath9k_channel *chan,
29 u16 modesIndex); 36 u16 modesIndex);
37
30void ath9k_hw_decrease_chain_power(struct ath_hw *ah, 38void ath9k_hw_decrease_chain_power(struct ath_hw *ah,
31 struct ath9k_channel *chan); 39 struct ath9k_channel *chan);
32bool ath9k_hw_init_rf(struct ath_hw *ah,
33 int *status);
34 40
35#define AR_PHY_BASE 0x9800 41#define AR_PHY_BASE 0x9800
36#define AR_PHY(_n) (AR_PHY_BASE + ((_n)<<2)) 42#define AR_PHY(_n) (AR_PHY_BASE + ((_n)<<2))
@@ -186,8 +192,20 @@ bool ath9k_hw_init_rf(struct ath_hw *ah,
186#define AR_PHY_PLL_CTL_44_2133 0xeb 192#define AR_PHY_PLL_CTL_44_2133 0xeb
187#define AR_PHY_PLL_CTL_40_2133 0xea 193#define AR_PHY_PLL_CTL_40_2133 0xea
188 194
189#define AR_PHY_SPECTRAL_SCAN 0x9912 195#define AR_PHY_SPECTRAL_SCAN 0x9910 /* AR9280 spectral scan configuration register */
190#define AR_PHY_SPECTRAL_SCAN_ENABLE 0x1 196#define AR_PHY_SPECTRAL_SCAN_ENABLE 0x1
197#define AR_PHY_SPECTRAL_SCAN_ENA 0x00000001 /* Enable spectral scan, reg 68, bit 0 */
198#define AR_PHY_SPECTRAL_SCAN_ENA_S 0 /* Enable spectral scan, reg 68, bit 0 */
199#define AR_PHY_SPECTRAL_SCAN_ACTIVE 0x00000002 /* Activate spectral scan reg 68, bit 1*/
200#define AR_PHY_SPECTRAL_SCAN_ACTIVE_S 1 /* Activate spectral scan reg 68, bit 1*/
201#define AR_PHY_SPECTRAL_SCAN_FFT_PERIOD 0x000000F0 /* Interval for FFT reports, reg 68, bits 4-7*/
202#define AR_PHY_SPECTRAL_SCAN_FFT_PERIOD_S 4
203#define AR_PHY_SPECTRAL_SCAN_PERIOD 0x0000FF00 /* Interval for FFT reports, reg 68, bits 8-15*/
204#define AR_PHY_SPECTRAL_SCAN_PERIOD_S 8
205#define AR_PHY_SPECTRAL_SCAN_COUNT 0x00FF0000 /* Number of reports, reg 68, bits 16-23*/
206#define AR_PHY_SPECTRAL_SCAN_COUNT_S 16
207#define AR_PHY_SPECTRAL_SCAN_SHORT_REPEAT 0x01000000 /* Short repeat, reg 68, bit 24*/
208#define AR_PHY_SPECTRAL_SCAN_SHORT_REPEAT_S 24 /* Short repeat, reg 68, bit 24*/
191 209
192#define AR_PHY_RX_DELAY 0x9914 210#define AR_PHY_RX_DELAY 0x9914
193#define AR_PHY_SEARCH_START_DELAY 0x9918 211#define AR_PHY_SEARCH_START_DELAY 0x9918
diff --git a/drivers/net/wireless/ath/ath9k/recv.c b/drivers/net/wireless/ath/ath9k/recv.c
index c880a55939bf..355dd1834e1d 100644
--- a/drivers/net/wireless/ath/ath9k/recv.c
+++ b/drivers/net/wireless/ath/ath9k/recv.c
@@ -202,7 +202,8 @@ static int ath_rx_prepare(struct sk_buff *skb, struct ath_desc *ds,
202 } 202 }
203 203
204 rcu_read_lock(); 204 rcu_read_lock();
205 sta = ieee80211_find_sta(sc->hw, hdr->addr2); 205 /* XXX: use ieee80211_find_sta! */
206 sta = ieee80211_find_sta_by_hw(sc->hw, hdr->addr2);
206 if (sta) { 207 if (sta) {
207 an = (struct ath_node *) sta->drv_priv; 208 an = (struct ath_node *) sta->drv_priv;
208 if (ds->ds_rxstat.rs_rssi != ATH9K_RSSI_BAD && 209 if (ds->ds_rxstat.rs_rssi != ATH9K_RSSI_BAD &&
diff --git a/drivers/net/wireless/ath/ath9k/reg.h b/drivers/net/wireless/ath/ath9k/reg.h
index ceed0095efac..061e12ce0b24 100644
--- a/drivers/net/wireless/ath/ath9k/reg.h
+++ b/drivers/net/wireless/ath/ath9k/reg.h
@@ -1704,4 +1704,7 @@ enum {
1704#define AR_KEYTABLE_MAC0(_n) (AR_KEYTABLE(_n) + 24) 1704#define AR_KEYTABLE_MAC0(_n) (AR_KEYTABLE(_n) + 24)
1705#define AR_KEYTABLE_MAC1(_n) (AR_KEYTABLE(_n) + 28) 1705#define AR_KEYTABLE_MAC1(_n) (AR_KEYTABLE(_n) + 28)
1706 1706
1707#define AR9271_CORE_CLOCK 117 /* clock to 117Mhz */
1708#define AR9271_TARGET_BAUD_RATE 19200 /* 115200 */
1709
1707#endif 1710#endif
diff --git a/drivers/net/wireless/ath/ath9k/xmit.c b/drivers/net/wireless/ath/ath9k/xmit.c
index 2a4efcbced60..8e052f406c35 100644
--- a/drivers/net/wireless/ath/ath9k/xmit.c
+++ b/drivers/net/wireless/ath/ath9k/xmit.c
@@ -282,7 +282,8 @@ static void ath_tx_complete_aggr(struct ath_softc *sc, struct ath_txq *txq,
282 282
283 rcu_read_lock(); 283 rcu_read_lock();
284 284
285 sta = ieee80211_find_sta(sc->hw, hdr->addr1); 285 /* XXX: use ieee80211_find_sta! */
286 sta = ieee80211_find_sta_by_hw(sc->hw, hdr->addr1);
286 if (!sta) { 287 if (!sta) {
287 rcu_read_unlock(); 288 rcu_read_unlock();
288 return; 289 return;
diff --git a/drivers/net/wireless/b43/Kconfig b/drivers/net/wireless/b43/Kconfig
index 54ea61c15d8b..64c12e1bced3 100644
--- a/drivers/net/wireless/b43/Kconfig
+++ b/drivers/net/wireless/b43/Kconfig
@@ -1,6 +1,6 @@
1config B43 1config B43
2 tristate "Broadcom 43xx wireless support (mac80211 stack)" 2 tristate "Broadcom 43xx wireless support (mac80211 stack)"
3 depends on SSB_POSSIBLE && MAC80211 && WLAN_80211 && HAS_DMA 3 depends on SSB_POSSIBLE && MAC80211 && HAS_DMA
4 select SSB 4 select SSB
5 select FW_LOADER 5 select FW_LOADER
6 ---help--- 6 ---help---
diff --git a/drivers/net/wireless/b43/b43.h b/drivers/net/wireless/b43/b43.h
index 65b23f725a04..fe3bf9491997 100644
--- a/drivers/net/wireless/b43/b43.h
+++ b/drivers/net/wireless/b43/b43.h
@@ -26,8 +26,6 @@
26# define B43_DEBUG 0 26# define B43_DEBUG 0
27#endif 27#endif
28 28
29#define B43_RX_MAX_SSI 60
30
31/* MMIO offsets */ 29/* MMIO offsets */
32#define B43_MMIO_DMA0_REASON 0x20 30#define B43_MMIO_DMA0_REASON 0x20
33#define B43_MMIO_DMA0_IRQ_MASK 0x24 31#define B43_MMIO_DMA0_IRQ_MASK 0x24
diff --git a/drivers/net/wireless/b43/main.c b/drivers/net/wireless/b43/main.c
index ed6e96a34743..c806924c7b5c 100644
--- a/drivers/net/wireless/b43/main.c
+++ b/drivers/net/wireless/b43/main.c
@@ -3573,7 +3573,7 @@ static int b43_op_config(struct ieee80211_hw *hw, u32 changed)
3573 if (conf->channel->hw_value != phy->channel) 3573 if (conf->channel->hw_value != phy->channel)
3574 b43_switch_channel(dev, conf->channel->hw_value); 3574 b43_switch_channel(dev, conf->channel->hw_value);
3575 3575
3576 dev->wl->radiotap_enabled = !!(conf->flags & IEEE80211_CONF_RADIOTAP); 3576 dev->wl->radiotap_enabled = !!(conf->flags & IEEE80211_CONF_MONITOR);
3577 3577
3578 /* Adjust the desired TX power level. */ 3578 /* Adjust the desired TX power level. */
3579 if (conf->power_level != 0) { 3579 if (conf->power_level != 0) {
diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
index c6987b147af4..3e046ec1ff86 100644
--- a/drivers/net/wireless/b43/phy_lp.c
+++ b/drivers/net/wireless/b43/phy_lp.c
@@ -67,6 +67,7 @@ static void b43_lpphy_op_prepare_structs(struct b43_wldev *dev)
67 struct b43_phy_lp *lpphy = phy->lp; 67 struct b43_phy_lp *lpphy = phy->lp;
68 68
69 memset(lpphy, 0, sizeof(*lpphy)); 69 memset(lpphy, 0, sizeof(*lpphy));
70 lpphy->antenna = B43_ANTENNA_DEFAULT;
70 71
71 //TODO 72 //TODO
72} 73}
@@ -379,8 +380,6 @@ static void lpphy_save_dig_flt_state(struct b43_wldev *dev)
379 } 380 }
380} 381}
381 382
382/* lpphy_restore_dig_flt_state is unused but kept as a reference */
383#if 0
384static void lpphy_restore_dig_flt_state(struct b43_wldev *dev) 383static void lpphy_restore_dig_flt_state(struct b43_wldev *dev)
385{ 384{
386 static const u16 addr[] = { 385 static const u16 addr[] = {
@@ -401,7 +400,6 @@ static void lpphy_restore_dig_flt_state(struct b43_wldev *dev)
401 for (i = 0; i < ARRAY_SIZE(addr); i++) 400 for (i = 0; i < ARRAY_SIZE(addr); i++)
402 b43_phy_write(dev, addr[i], lpphy->dig_flt_state[i]); 401 b43_phy_write(dev, addr[i], lpphy->dig_flt_state[i]);
403} 402}
404#endif
405 403
406static void lpphy_baseband_rev2plus_init(struct b43_wldev *dev) 404static void lpphy_baseband_rev2plus_init(struct b43_wldev *dev)
407{ 405{
@@ -754,11 +752,17 @@ static void lpphy_clear_deaf(struct b43_wldev *dev, bool user)
754 } 752 }
755} 753}
756 754
755static void lpphy_set_trsw_over(struct b43_wldev *dev, bool tx, bool rx)
756{
757 u16 trsw = (tx << 1) | rx;
758 b43_phy_maskset(dev, B43_LPPHY_RF_OVERRIDE_VAL_0, 0xFFFC, trsw);
759 b43_phy_set(dev, B43_LPPHY_RF_OVERRIDE_0, 0x3);
760}
761
757static void lpphy_disable_crs(struct b43_wldev *dev, bool user) 762static void lpphy_disable_crs(struct b43_wldev *dev, bool user)
758{ 763{
759 lpphy_set_deaf(dev, user); 764 lpphy_set_deaf(dev, user);
760 b43_phy_maskset(dev, B43_LPPHY_RF_OVERRIDE_VAL_0, 0xFFFC, 0x1); 765 lpphy_set_trsw_over(dev, false, true);
761 b43_phy_set(dev, B43_LPPHY_RF_OVERRIDE_0, 0x3);
762 b43_phy_mask(dev, B43_LPPHY_RF_OVERRIDE_VAL_0, 0xFFFB); 766 b43_phy_mask(dev, B43_LPPHY_RF_OVERRIDE_VAL_0, 0xFFFB);
763 b43_phy_set(dev, B43_LPPHY_RF_OVERRIDE_0, 0x4); 767 b43_phy_set(dev, B43_LPPHY_RF_OVERRIDE_0, 0x4);
764 b43_phy_mask(dev, B43_LPPHY_RF_OVERRIDE_VAL_0, 0xFFF7); 768 b43_phy_mask(dev, B43_LPPHY_RF_OVERRIDE_VAL_0, 0xFFF7);
@@ -793,6 +797,60 @@ static void lpphy_restore_crs(struct b43_wldev *dev, bool user)
793 797
794struct lpphy_tx_gains { u16 gm, pga, pad, dac; }; 798struct lpphy_tx_gains { u16 gm, pga, pad, dac; };
795 799
800static void lpphy_disable_rx_gain_override(struct b43_wldev *dev)
801{
802 b43_phy_mask(dev, B43_LPPHY_RF_OVERRIDE_0, 0xFFFE);
803 b43_phy_mask(dev, B43_LPPHY_RF_OVERRIDE_0, 0xFFEF);
804 b43_phy_mask(dev, B43_LPPHY_RF_OVERRIDE_0, 0xFFBF);
805 if (dev->phy.rev >= 2) {
806 b43_phy_mask(dev, B43_LPPHY_RF_OVERRIDE_2, 0xFEFF);
807 if (b43_current_band(dev->wl) == IEEE80211_BAND_2GHZ) {
808 b43_phy_mask(dev, B43_LPPHY_RF_OVERRIDE_2, 0xFBFF);
809 b43_phy_mask(dev, B43_PHY_OFDM(0xE5), 0xFFF7);
810 }
811 } else {
812 b43_phy_mask(dev, B43_LPPHY_RF_OVERRIDE_2, 0xFDFF);
813 }
814}
815
816static void lpphy_enable_rx_gain_override(struct b43_wldev *dev)
817{
818 b43_phy_set(dev, B43_LPPHY_RF_OVERRIDE_0, 0x1);
819 b43_phy_set(dev, B43_LPPHY_RF_OVERRIDE_0, 0x10);
820 b43_phy_set(dev, B43_LPPHY_RF_OVERRIDE_0, 0x40);
821 if (dev->phy.rev >= 2) {
822 b43_phy_set(dev, B43_LPPHY_RF_OVERRIDE_2, 0x100);
823 if (b43_current_band(dev->wl) == IEEE80211_BAND_2GHZ) {
824 b43_phy_set(dev, B43_LPPHY_RF_OVERRIDE_2, 0x400);
825 b43_phy_set(dev, B43_PHY_OFDM(0xE5), 0x8);
826 }
827 } else {
828 b43_phy_set(dev, B43_LPPHY_RF_OVERRIDE_2, 0x200);
829 }
830}
831
832static void lpphy_disable_tx_gain_override(struct b43_wldev *dev)
833{
834 if (dev->phy.rev < 2)
835 b43_phy_mask(dev, B43_LPPHY_RF_OVERRIDE_2, 0xFEFF);
836 else {
837 b43_phy_mask(dev, B43_LPPHY_RF_OVERRIDE_2, 0xFF7F);
838 b43_phy_mask(dev, B43_LPPHY_RF_OVERRIDE_2, 0xBFFF);
839 }
840 b43_phy_mask(dev, B43_LPPHY_AFE_CTL_OVR, 0xFFBF);
841}
842
843static void lpphy_enable_tx_gain_override(struct b43_wldev *dev)
844{
845 if (dev->phy.rev < 2)
846 b43_phy_set(dev, B43_LPPHY_RF_OVERRIDE_2, 0x100);
847 else {
848 b43_phy_set(dev, B43_LPPHY_RF_OVERRIDE_2, 0x80);
849 b43_phy_set(dev, B43_LPPHY_RF_OVERRIDE_2, 0x4000);
850 }
851 b43_phy_set(dev, B43_LPPHY_AFE_CTL_OVR, 0x40);
852}
853
796static struct lpphy_tx_gains lpphy_get_tx_gains(struct b43_wldev *dev) 854static struct lpphy_tx_gains lpphy_get_tx_gains(struct b43_wldev *dev)
797{ 855{
798 struct lpphy_tx_gains gains; 856 struct lpphy_tx_gains gains;
@@ -822,6 +880,17 @@ static void lpphy_set_dac_gain(struct b43_wldev *dev, u16 dac)
822 b43_phy_maskset(dev, B43_LPPHY_AFE_DAC_CTL, 0xF000, ctl); 880 b43_phy_maskset(dev, B43_LPPHY_AFE_DAC_CTL, 0xF000, ctl);
823} 881}
824 882
883static u16 lpphy_get_pa_gain(struct b43_wldev *dev)
884{
885 return b43_phy_read(dev, B43_PHY_OFDM(0xFB)) & 0x7F;
886}
887
888static void lpphy_set_pa_gain(struct b43_wldev *dev, u16 gain)
889{
890 b43_phy_maskset(dev, B43_PHY_OFDM(0xFB), 0xE03F, gain << 6);
891 b43_phy_maskset(dev, B43_PHY_OFDM(0xFD), 0x80FF, gain << 8);
892}
893
825static void lpphy_set_tx_gains(struct b43_wldev *dev, 894static void lpphy_set_tx_gains(struct b43_wldev *dev,
826 struct lpphy_tx_gains gains) 895 struct lpphy_tx_gains gains)
827{ 896{
@@ -832,25 +901,22 @@ static void lpphy_set_tx_gains(struct b43_wldev *dev,
832 b43_phy_maskset(dev, B43_LPPHY_TX_GAIN_CTL_OVERRIDE_VAL, 901 b43_phy_maskset(dev, B43_LPPHY_TX_GAIN_CTL_OVERRIDE_VAL,
833 0xF800, rf_gain); 902 0xF800, rf_gain);
834 } else { 903 } else {
835 pa_gain = b43_phy_read(dev, B43_PHY_OFDM(0xFB)) & 0x1FC0; 904 pa_gain = lpphy_get_pa_gain(dev);
836 pa_gain <<= 2;
837 b43_phy_write(dev, B43_LPPHY_TX_GAIN_CTL_OVERRIDE_VAL, 905 b43_phy_write(dev, B43_LPPHY_TX_GAIN_CTL_OVERRIDE_VAL,
838 (gains.pga << 8) | gains.gm); 906 (gains.pga << 8) | gains.gm);
907 /*
908 * SPEC FIXME The spec calls for (pa_gain << 8) here, but that
909 * conflicts with the spec for set_pa_gain! Vendor driver bug?
910 */
839 b43_phy_maskset(dev, B43_PHY_OFDM(0xFB), 911 b43_phy_maskset(dev, B43_PHY_OFDM(0xFB),
840 0x8000, gains.pad | pa_gain); 912 0x8000, gains.pad | (pa_gain << 6));
841 b43_phy_write(dev, B43_PHY_OFDM(0xFC), 913 b43_phy_write(dev, B43_PHY_OFDM(0xFC),
842 (gains.pga << 8) | gains.gm); 914 (gains.pga << 8) | gains.gm);
843 b43_phy_maskset(dev, B43_PHY_OFDM(0xFD), 915 b43_phy_maskset(dev, B43_PHY_OFDM(0xFD),
844 0x8000, gains.pad | pa_gain); 916 0x8000, gains.pad | (pa_gain << 8));
845 } 917 }
846 lpphy_set_dac_gain(dev, gains.dac); 918 lpphy_set_dac_gain(dev, gains.dac);
847 if (dev->phy.rev < 2) { 919 lpphy_enable_tx_gain_override(dev);
848 b43_phy_maskset(dev, B43_LPPHY_RF_OVERRIDE_2, 0xFEFF, 1 << 8);
849 } else {
850 b43_phy_maskset(dev, B43_LPPHY_RF_OVERRIDE_2, 0xFF7F, 1 << 7);
851 b43_phy_maskset(dev, B43_LPPHY_RF_OVERRIDE_2, 0xBFFF, 1 << 14);
852 }
853 b43_phy_maskset(dev, B43_LPPHY_AFE_CTL_OVR, 0xFFBF, 1 << 6);
854} 920}
855 921
856static void lpphy_rev0_1_set_rx_gain(struct b43_wldev *dev, u32 gain) 922static void lpphy_rev0_1_set_rx_gain(struct b43_wldev *dev, u32 gain)
@@ -890,41 +956,6 @@ static void lpphy_rev2plus_set_rx_gain(struct b43_wldev *dev, u32 gain)
890 } 956 }
891} 957}
892 958
893/* lpphy_disable_rx_gain_override is unused but kept as a reference */
894#if 0
895static void lpphy_disable_rx_gain_override(struct b43_wldev *dev)
896{
897 b43_phy_mask(dev, B43_LPPHY_RF_OVERRIDE_0, 0xFFFE);
898 b43_phy_mask(dev, B43_LPPHY_RF_OVERRIDE_0, 0xFFEF);
899 b43_phy_mask(dev, B43_LPPHY_RF_OVERRIDE_0, 0xFFBF);
900 if (dev->phy.rev >= 2) {
901 b43_phy_mask(dev, B43_LPPHY_RF_OVERRIDE_2, 0xFEFF);
902 if (b43_current_band(dev->wl) == IEEE80211_BAND_2GHZ) {
903 b43_phy_mask(dev, B43_LPPHY_RF_OVERRIDE_2, 0xFBFF);
904 b43_phy_mask(dev, B43_PHY_OFDM(0xE5), 0xFFF7);
905 }
906 } else {
907 b43_phy_mask(dev, B43_LPPHY_RF_OVERRIDE_2, 0xFDFF);
908 }
909}
910#endif
911
912static void lpphy_enable_rx_gain_override(struct b43_wldev *dev)
913{
914 b43_phy_set(dev, B43_LPPHY_RF_OVERRIDE_0, 0x1);
915 b43_phy_set(dev, B43_LPPHY_RF_OVERRIDE_0, 0x10);
916 b43_phy_set(dev, B43_LPPHY_RF_OVERRIDE_0, 0x40);
917 if (dev->phy.rev >= 2) {
918 b43_phy_set(dev, B43_LPPHY_RF_OVERRIDE_2, 0x100);
919 if (b43_current_band(dev->wl) == IEEE80211_BAND_2GHZ) {
920 b43_phy_set(dev, B43_LPPHY_RF_OVERRIDE_2, 0x400);
921 b43_phy_set(dev, B43_PHY_OFDM(0xE5), 0x8);
922 }
923 } else {
924 b43_phy_set(dev, B43_LPPHY_RF_OVERRIDE_2, 0x200);
925 }
926}
927
928static void lpphy_set_rx_gain(struct b43_wldev *dev, u32 gain) 959static void lpphy_set_rx_gain(struct b43_wldev *dev, u32 gain)
929{ 960{
930 if (dev->phy.rev < 2) 961 if (dev->phy.rev < 2)
@@ -1009,8 +1040,7 @@ static int lpphy_loopback(struct b43_wldev *dev)
1009 1040
1010 memset(&iq_est, 0, sizeof(iq_est)); 1041 memset(&iq_est, 0, sizeof(iq_est));
1011 1042
1012 b43_phy_maskset(dev, B43_LPPHY_RF_OVERRIDE_VAL_0, 0xFFFC, 0x3); 1043 lpphy_set_trsw_over(dev, true, true);
1013 b43_phy_set(dev, B43_LPPHY_RF_OVERRIDE_0, 0x3);
1014 b43_phy_set(dev, B43_LPPHY_AFE_CTL_OVR, 1); 1044 b43_phy_set(dev, B43_LPPHY_AFE_CTL_OVR, 1);
1015 b43_phy_mask(dev, B43_LPPHY_AFE_CTL_OVRVAL, 0xFFFE); 1045 b43_phy_mask(dev, B43_LPPHY_AFE_CTL_OVRVAL, 0xFFFE);
1016 b43_phy_set(dev, B43_LPPHY_RF_OVERRIDE_0, 0x800); 1046 b43_phy_set(dev, B43_LPPHY_RF_OVERRIDE_0, 0x800);
@@ -1132,7 +1162,7 @@ static void lpphy_set_tx_power_control(struct b43_wldev *dev,
1132 b43_phy_maskset(dev, B43_LPPHY_TX_PWR_CTL_NNUM, 1162 b43_phy_maskset(dev, B43_LPPHY_TX_PWR_CTL_NNUM,
1133 0x8FFF, ((u16)lpphy->tssi_npt << 16)); 1163 0x8FFF, ((u16)lpphy->tssi_npt << 16));
1134 //TODO Set "TSSI Transmit Count" variable to total transmitted frame count 1164 //TODO Set "TSSI Transmit Count" variable to total transmitted frame count
1135 //TODO Disable TX gain override 1165 lpphy_disable_tx_gain_override(dev);
1136 lpphy->tx_pwr_idx_over = -1; 1166 lpphy->tx_pwr_idx_over = -1;
1137 } 1167 }
1138 } 1168 }
@@ -1318,15 +1348,73 @@ static void lpphy_calibrate_rc(struct b43_wldev *dev)
1318 } 1348 }
1319} 1349}
1320 1350
1351static void b43_lpphy_op_set_rx_antenna(struct b43_wldev *dev, int antenna)
1352{
1353 if (dev->phy.rev >= 2)
1354 return; // rev2+ doesn't support antenna diversity
1355
1356 if (B43_WARN_ON(antenna > B43_ANTENNA_AUTO1))
1357 return;
1358
1359 b43_hf_write(dev, b43_hf_read(dev) & ~B43_HF_ANTDIVHELP);
1360
1361 b43_phy_maskset(dev, B43_LPPHY_CRSGAIN_CTL, 0xFFFD, antenna & 0x2);
1362 b43_phy_maskset(dev, B43_LPPHY_CRSGAIN_CTL, 0xFFFE, antenna & 0x1);
1363
1364 b43_hf_write(dev, b43_hf_read(dev) | B43_HF_ANTDIVHELP);
1365
1366 dev->phy.lp->antenna = antenna;
1367}
1368
1369static void lpphy_set_tx_iqcc(struct b43_wldev *dev, u16 a, u16 b)
1370{
1371 u16 tmp[2];
1372
1373 tmp[0] = a;
1374 tmp[1] = b;
1375 b43_lptab_write_bulk(dev, B43_LPTAB16(0, 80), 2, tmp);
1376}
1377
1321static void lpphy_set_tx_power_by_index(struct b43_wldev *dev, u8 index) 1378static void lpphy_set_tx_power_by_index(struct b43_wldev *dev, u8 index)
1322{ 1379{
1323 struct b43_phy_lp *lpphy = dev->phy.lp; 1380 struct b43_phy_lp *lpphy = dev->phy.lp;
1381 struct lpphy_tx_gains gains;
1382 u32 iq_comp, tx_gain, coeff, rf_power;
1324 1383
1325 lpphy->tx_pwr_idx_over = index; 1384 lpphy->tx_pwr_idx_over = index;
1385 lpphy_read_tx_pctl_mode_from_hardware(dev);
1326 if (lpphy->txpctl_mode != B43_LPPHY_TXPCTL_OFF) 1386 if (lpphy->txpctl_mode != B43_LPPHY_TXPCTL_OFF)
1327 lpphy_set_tx_power_control(dev, B43_LPPHY_TXPCTL_SW); 1387 lpphy_set_tx_power_control(dev, B43_LPPHY_TXPCTL_SW);
1328 1388 if (dev->phy.rev >= 2) {
1329 //TODO 1389 iq_comp = b43_lptab_read(dev, B43_LPTAB32(7, index + 320));
1390 tx_gain = b43_lptab_read(dev, B43_LPTAB32(7, index + 192));
1391 gains.pad = (tx_gain >> 16) & 0xFF;
1392 gains.gm = tx_gain & 0xFF;
1393 gains.pga = (tx_gain >> 8) & 0xFF;
1394 gains.dac = (iq_comp >> 28) & 0xFF;
1395 lpphy_set_tx_gains(dev, gains);
1396 } else {
1397 iq_comp = b43_lptab_read(dev, B43_LPTAB32(10, index + 320));
1398 tx_gain = b43_lptab_read(dev, B43_LPTAB32(10, index + 192));
1399 b43_phy_maskset(dev, B43_LPPHY_TX_GAIN_CTL_OVERRIDE_VAL,
1400 0xF800, (tx_gain >> 4) & 0x7FFF);
1401 lpphy_set_dac_gain(dev, tx_gain & 0x7);
1402 lpphy_set_pa_gain(dev, (tx_gain >> 24) & 0x7F);
1403 }
1404 lpphy_set_bb_mult(dev, (iq_comp >> 20) & 0xFF);
1405 lpphy_set_tx_iqcc(dev, (iq_comp >> 10) & 0x3FF, iq_comp & 0x3FF);
1406 if (dev->phy.rev >= 2) {
1407 coeff = b43_lptab_read(dev, B43_LPTAB32(7, index + 448));
1408 } else {
1409 coeff = b43_lptab_read(dev, B43_LPTAB32(10, index + 448));
1410 }
1411 b43_lptab_write(dev, B43_LPTAB16(0, 85), coeff & 0xFFFF);
1412 if (dev->phy.rev >= 2) {
1413 rf_power = b43_lptab_read(dev, B43_LPTAB32(7, index + 576));
1414 b43_phy_maskset(dev, B43_LPPHY_RF_PWR_OVERRIDE, 0xFF00,
1415 rf_power & 0xFFFF);//SPEC FIXME mask & set != 0
1416 }
1417 lpphy_enable_tx_gain_override(dev);
1330} 1418}
1331 1419
1332static void lpphy_btcoex_override(struct b43_wldev *dev) 1420static void lpphy_btcoex_override(struct b43_wldev *dev)
@@ -1335,58 +1423,45 @@ static void lpphy_btcoex_override(struct b43_wldev *dev)
1335 b43_write16(dev, B43_MMIO_BTCOEX_TXCTL, 0xFF); 1423 b43_write16(dev, B43_MMIO_BTCOEX_TXCTL, 0xFF);
1336} 1424}
1337 1425
1338static void lpphy_pr41573_workaround(struct b43_wldev *dev) 1426static void b43_lpphy_op_software_rfkill(struct b43_wldev *dev,
1427 bool blocked)
1339{ 1428{
1340 struct b43_phy_lp *lpphy = dev->phy.lp; 1429 //TODO check MAC control register
1341 u32 *saved_tab; 1430 if (blocked) {
1342 const unsigned int saved_tab_size = 256; 1431 if (dev->phy.rev >= 2) {
1343 enum b43_lpphy_txpctl_mode txpctl_mode; 1432 b43_phy_mask(dev, B43_LPPHY_RF_OVERRIDE_VAL_0, 0x83FF);
1344 s8 tx_pwr_idx_over; 1433 b43_phy_set(dev, B43_LPPHY_RF_OVERRIDE_0, 0x1F00);
1345 u16 tssi_npt, tssi_idx; 1434 b43_phy_mask(dev, B43_LPPHY_AFE_DDFS, 0x80FF);
1346 1435 b43_phy_mask(dev, B43_LPPHY_RF_OVERRIDE_2_VAL, 0xDFFF);
1347 saved_tab = kcalloc(saved_tab_size, sizeof(saved_tab[0]), GFP_KERNEL); 1436 b43_phy_set(dev, B43_LPPHY_RF_OVERRIDE_2, 0x0808);
1348 if (!saved_tab) { 1437 } else {
1349 b43err(dev->wl, "PR41573 failed. Out of memory!\n"); 1438 b43_phy_mask(dev, B43_LPPHY_RF_OVERRIDE_VAL_0, 0xE0FF);
1350 return; 1439 b43_phy_set(dev, B43_LPPHY_RF_OVERRIDE_0, 0x1F00);
1351 } 1440 b43_phy_mask(dev, B43_LPPHY_RF_OVERRIDE_2_VAL, 0xFCFF);
1352 1441 b43_phy_set(dev, B43_LPPHY_RF_OVERRIDE_2, 0x0018);
1353 lpphy_read_tx_pctl_mode_from_hardware(dev); 1442 }
1354 txpctl_mode = lpphy->txpctl_mode;
1355 tx_pwr_idx_over = lpphy->tx_pwr_idx_over;
1356 tssi_npt = lpphy->tssi_npt;
1357 tssi_idx = lpphy->tssi_idx;
1358
1359 if (dev->phy.rev < 2) {
1360 b43_lptab_read_bulk(dev, B43_LPTAB32(10, 0x140),
1361 saved_tab_size, saved_tab);
1362 } else { 1443 } else {
1363 b43_lptab_read_bulk(dev, B43_LPTAB32(7, 0x140), 1444 b43_phy_mask(dev, B43_LPPHY_RF_OVERRIDE_0, 0xE0FF);
1364 saved_tab_size, saved_tab); 1445 if (dev->phy.rev >= 2)
1446 b43_phy_mask(dev, B43_LPPHY_RF_OVERRIDE_2, 0xF7F7);
1447 else
1448 b43_phy_mask(dev, B43_LPPHY_RF_OVERRIDE_2, 0xFFE7);
1365 } 1449 }
1366 //TODO
1367
1368 kfree(saved_tab);
1369} 1450}
1370 1451
1371static void lpphy_calibration(struct b43_wldev *dev) 1452/* This was previously called lpphy_japan_filter */
1453static void lpphy_set_analog_filter(struct b43_wldev *dev, int channel)
1372{ 1454{
1373 struct b43_phy_lp *lpphy = dev->phy.lp; 1455 struct b43_phy_lp *lpphy = dev->phy.lp;
1374 enum b43_lpphy_txpctl_mode saved_pctl_mode; 1456 u16 tmp = (channel == 14); //SPEC FIXME check japanwidefilter!
1375
1376 b43_mac_suspend(dev);
1377
1378 lpphy_btcoex_override(dev);
1379 lpphy_read_tx_pctl_mode_from_hardware(dev);
1380 saved_pctl_mode = lpphy->txpctl_mode;
1381 lpphy_set_tx_power_control(dev, B43_LPPHY_TXPCTL_OFF);
1382 //TODO Perform transmit power table I/Q LO calibration
1383 if ((dev->phy.rev == 0) && (saved_pctl_mode != B43_LPPHY_TXPCTL_OFF))
1384 lpphy_pr41573_workaround(dev);
1385 //TODO If a full calibration has not been performed on this channel yet, perform PAPD TX-power calibration
1386 lpphy_set_tx_power_control(dev, saved_pctl_mode);
1387 //TODO Perform I/Q calibration with a single control value set
1388 1457
1389 b43_mac_enable(dev); 1458 if (dev->phy.rev < 2) { //SPEC FIXME Isn't this rev0/1-specific?
1459 b43_phy_maskset(dev, B43_LPPHY_LP_PHY_CTL, 0xFCFF, tmp << 9);
1460 if ((dev->phy.rev == 1) && (lpphy->rc_cap))
1461 lpphy_set_rc_cap(dev);
1462 } else {
1463 b43_radio_write(dev, B2063_TX_BB_SP3, 0x3F);
1464 }
1390} 1465}
1391 1466
1392static void lpphy_set_tssi_mux(struct b43_wldev *dev, enum tssi_mux_mode mode) 1467static void lpphy_set_tssi_mux(struct b43_wldev *dev, enum tssi_mux_mode mode)
@@ -1495,6 +1570,473 @@ static void lpphy_tx_pctl_init(struct b43_wldev *dev)
1495 } 1570 }
1496} 1571}
1497 1572
1573static void lpphy_pr41573_workaround(struct b43_wldev *dev)
1574{
1575 struct b43_phy_lp *lpphy = dev->phy.lp;
1576 u32 *saved_tab;
1577 const unsigned int saved_tab_size = 256;
1578 enum b43_lpphy_txpctl_mode txpctl_mode;
1579 s8 tx_pwr_idx_over;
1580 u16 tssi_npt, tssi_idx;
1581
1582 saved_tab = kcalloc(saved_tab_size, sizeof(saved_tab[0]), GFP_KERNEL);
1583 if (!saved_tab) {
1584 b43err(dev->wl, "PR41573 failed. Out of memory!\n");
1585 return;
1586 }
1587
1588 lpphy_read_tx_pctl_mode_from_hardware(dev);
1589 txpctl_mode = lpphy->txpctl_mode;
1590 tx_pwr_idx_over = lpphy->tx_pwr_idx_over;
1591 tssi_npt = lpphy->tssi_npt;
1592 tssi_idx = lpphy->tssi_idx;
1593
1594 if (dev->phy.rev < 2) {
1595 b43_lptab_read_bulk(dev, B43_LPTAB32(10, 0x140),
1596 saved_tab_size, saved_tab);
1597 } else {
1598 b43_lptab_read_bulk(dev, B43_LPTAB32(7, 0x140),
1599 saved_tab_size, saved_tab);
1600 }
1601 //FIXME PHY reset
1602 lpphy_table_init(dev); //FIXME is table init needed?
1603 lpphy_baseband_init(dev);
1604 lpphy_tx_pctl_init(dev);
1605 b43_lpphy_op_software_rfkill(dev, false);
1606 lpphy_set_tx_power_control(dev, B43_LPPHY_TXPCTL_OFF);
1607 if (dev->phy.rev < 2) {
1608 b43_lptab_write_bulk(dev, B43_LPTAB32(10, 0x140),
1609 saved_tab_size, saved_tab);
1610 } else {
1611 b43_lptab_write_bulk(dev, B43_LPTAB32(7, 0x140),
1612 saved_tab_size, saved_tab);
1613 }
1614 b43_write16(dev, B43_MMIO_CHANNEL, lpphy->channel);
1615 lpphy->tssi_npt = tssi_npt;
1616 lpphy->tssi_idx = tssi_idx;
1617 lpphy_set_analog_filter(dev, lpphy->channel);
1618 if (tx_pwr_idx_over != -1)
1619 lpphy_set_tx_power_by_index(dev, tx_pwr_idx_over);
1620 if (lpphy->rc_cap)
1621 lpphy_set_rc_cap(dev);
1622 b43_lpphy_op_set_rx_antenna(dev, lpphy->antenna);
1623 lpphy_set_tx_power_control(dev, txpctl_mode);
1624 kfree(saved_tab);
1625}
1626
1627struct lpphy_rx_iq_comp { u8 chan; s8 c1, c0; };
1628
1629static const struct lpphy_rx_iq_comp lpphy_5354_iq_table[] = {
1630 { .chan = 1, .c1 = -66, .c0 = 15, },
1631 { .chan = 2, .c1 = -66, .c0 = 15, },
1632 { .chan = 3, .c1 = -66, .c0 = 15, },
1633 { .chan = 4, .c1 = -66, .c0 = 15, },
1634 { .chan = 5, .c1 = -66, .c0 = 15, },
1635 { .chan = 6, .c1 = -66, .c0 = 15, },
1636 { .chan = 7, .c1 = -66, .c0 = 14, },
1637 { .chan = 8, .c1 = -66, .c0 = 14, },
1638 { .chan = 9, .c1 = -66, .c0 = 14, },
1639 { .chan = 10, .c1 = -66, .c0 = 14, },
1640 { .chan = 11, .c1 = -66, .c0 = 14, },
1641 { .chan = 12, .c1 = -66, .c0 = 13, },
1642 { .chan = 13, .c1 = -66, .c0 = 13, },
1643 { .chan = 14, .c1 = -66, .c0 = 13, },
1644};
1645
1646static const struct lpphy_rx_iq_comp lpphy_rev0_1_iq_table[] = {
1647 { .chan = 1, .c1 = -64, .c0 = 13, },
1648 { .chan = 2, .c1 = -64, .c0 = 13, },
1649 { .chan = 3, .c1 = -64, .c0 = 13, },
1650 { .chan = 4, .c1 = -64, .c0 = 13, },
1651 { .chan = 5, .c1 = -64, .c0 = 12, },
1652 { .chan = 6, .c1 = -64, .c0 = 12, },
1653 { .chan = 7, .c1 = -64, .c0 = 12, },
1654 { .chan = 8, .c1 = -64, .c0 = 12, },
1655 { .chan = 9, .c1 = -64, .c0 = 12, },
1656 { .chan = 10, .c1 = -64, .c0 = 11, },
1657 { .chan = 11, .c1 = -64, .c0 = 11, },
1658 { .chan = 12, .c1 = -64, .c0 = 11, },
1659 { .chan = 13, .c1 = -64, .c0 = 11, },
1660 { .chan = 14, .c1 = -64, .c0 = 10, },
1661 { .chan = 34, .c1 = -62, .c0 = 24, },
1662 { .chan = 38, .c1 = -62, .c0 = 24, },
1663 { .chan = 42, .c1 = -62, .c0 = 24, },
1664 { .chan = 46, .c1 = -62, .c0 = 23, },
1665 { .chan = 36, .c1 = -62, .c0 = 24, },
1666 { .chan = 40, .c1 = -62, .c0 = 24, },
1667 { .chan = 44, .c1 = -62, .c0 = 23, },
1668 { .chan = 48, .c1 = -62, .c0 = 23, },
1669 { .chan = 52, .c1 = -62, .c0 = 23, },
1670 { .chan = 56, .c1 = -62, .c0 = 22, },
1671 { .chan = 60, .c1 = -62, .c0 = 22, },
1672 { .chan = 64, .c1 = -62, .c0 = 22, },
1673 { .chan = 100, .c1 = -62, .c0 = 16, },
1674 { .chan = 104, .c1 = -62, .c0 = 16, },
1675 { .chan = 108, .c1 = -62, .c0 = 15, },
1676 { .chan = 112, .c1 = -62, .c0 = 14, },
1677 { .chan = 116, .c1 = -62, .c0 = 14, },
1678 { .chan = 120, .c1 = -62, .c0 = 13, },
1679 { .chan = 124, .c1 = -62, .c0 = 12, },
1680 { .chan = 128, .c1 = -62, .c0 = 12, },
1681 { .chan = 132, .c1 = -62, .c0 = 12, },
1682 { .chan = 136, .c1 = -62, .c0 = 11, },
1683 { .chan = 140, .c1 = -62, .c0 = 10, },
1684 { .chan = 149, .c1 = -61, .c0 = 9, },
1685 { .chan = 153, .c1 = -61, .c0 = 9, },
1686 { .chan = 157, .c1 = -61, .c0 = 9, },
1687 { .chan = 161, .c1 = -61, .c0 = 8, },
1688 { .chan = 165, .c1 = -61, .c0 = 8, },
1689 { .chan = 184, .c1 = -62, .c0 = 25, },
1690 { .chan = 188, .c1 = -62, .c0 = 25, },
1691 { .chan = 192, .c1 = -62, .c0 = 25, },
1692 { .chan = 196, .c1 = -62, .c0 = 25, },
1693 { .chan = 200, .c1 = -62, .c0 = 25, },
1694 { .chan = 204, .c1 = -62, .c0 = 25, },
1695 { .chan = 208, .c1 = -62, .c0 = 25, },
1696 { .chan = 212, .c1 = -62, .c0 = 25, },
1697 { .chan = 216, .c1 = -62, .c0 = 26, },
1698};
1699
1700static const struct lpphy_rx_iq_comp lpphy_rev2plus_iq_comp = {
1701 .chan = 0,
1702 .c1 = -64,
1703 .c0 = 0,
1704};
1705
1706static u8 lpphy_nbits(s32 val)
1707{
1708 u32 tmp = abs(val);
1709 u8 nbits = 0;
1710
1711 while (tmp != 0) {
1712 nbits++;
1713 tmp >>= 1;
1714 }
1715
1716 return nbits;
1717}
1718
1719static int lpphy_calc_rx_iq_comp(struct b43_wldev *dev, u16 samples)
1720{
1721 struct lpphy_iq_est iq_est;
1722 u16 c0, c1;
1723 int prod, ipwr, qpwr, prod_msb, q_msb, tmp1, tmp2, tmp3, tmp4, ret;
1724
1725 c1 = b43_phy_read(dev, B43_LPPHY_RX_COMP_COEFF_S);
1726 c0 = c1 >> 8;
1727 c1 |= 0xFF;
1728
1729 b43_phy_maskset(dev, B43_LPPHY_RX_COMP_COEFF_S, 0xFF00, 0x00C0);
1730 b43_phy_mask(dev, B43_LPPHY_RX_COMP_COEFF_S, 0x00FF);
1731
1732 ret = lpphy_rx_iq_est(dev, samples, 32, &iq_est);
1733 if (!ret)
1734 goto out;
1735
1736 prod = iq_est.iq_prod;
1737 ipwr = iq_est.i_pwr;
1738 qpwr = iq_est.q_pwr;
1739
1740 if (ipwr + qpwr < 2) {
1741 ret = 0;
1742 goto out;
1743 }
1744
1745 prod_msb = lpphy_nbits(prod);
1746 q_msb = lpphy_nbits(qpwr);
1747 tmp1 = prod_msb - 20;
1748
1749 if (tmp1 >= 0) {
1750 tmp3 = ((prod << (30 - prod_msb)) + (ipwr >> (1 + tmp1))) /
1751 (ipwr >> tmp1);
1752 } else {
1753 tmp3 = ((prod << (30 - prod_msb)) + (ipwr << (-1 - tmp1))) /
1754 (ipwr << -tmp1);
1755 }
1756
1757 tmp2 = q_msb - 11;
1758
1759 if (tmp2 >= 0)
1760 tmp4 = (qpwr << (31 - q_msb)) / (ipwr >> tmp2);
1761 else
1762 tmp4 = (qpwr << (31 - q_msb)) / (ipwr << -tmp2);
1763
1764 tmp4 -= tmp3 * tmp3;
1765 tmp4 = -int_sqrt(tmp4);
1766
1767 c0 = tmp3 >> 3;
1768 c1 = tmp4 >> 4;
1769
1770out:
1771 b43_phy_maskset(dev, B43_LPPHY_RX_COMP_COEFF_S, 0xFF00, c1);
1772 b43_phy_maskset(dev, B43_LPPHY_RX_COMP_COEFF_S, 0x00FF, c0 << 8);
1773 return ret;
1774}
1775
1776/* Complex number using 2 32-bit signed integers */
1777typedef struct {s32 i, q;} lpphy_c32;
1778
1779static lpphy_c32 lpphy_cordic(int theta)
1780{
1781 u32 arctg[] = { 2949120, 1740967, 919879, 466945, 234379, 117304,
1782 58666, 29335, 14668, 7334, 3667, 1833, 917, 458,
1783 229, 115, 57, 29, };
1784 int i, tmp, signx = 1, angle = 0;
1785 lpphy_c32 ret = { .i = 39797, .q = 0, };
1786
1787 theta = clamp_t(int, theta, -180, 180);
1788
1789 if (theta > 90) {
1790 theta -= 180;
1791 signx = -1;
1792 } else if (theta < -90) {
1793 theta += 180;
1794 signx = -1;
1795 }
1796
1797 for (i = 0; i <= 17; i++) {
1798 if (theta > angle) {
1799 tmp = ret.i - (ret.q >> i);
1800 ret.q += ret.i >> i;
1801 ret.i = tmp;
1802 angle += arctg[i];
1803 } else {
1804 tmp = ret.i + (ret.q >> i);
1805 ret.q -= ret.i >> i;
1806 ret.i = tmp;
1807 angle -= arctg[i];
1808 }
1809 }
1810
1811 ret.i *= signx;
1812 ret.q *= signx;
1813
1814 return ret;
1815}
1816
1817static void lpphy_run_samples(struct b43_wldev *dev, u16 samples, u16 loops,
1818 u16 wait)
1819{
1820 b43_phy_maskset(dev, B43_LPPHY_SMPL_PLAY_BUFFER_CTL,
1821 0xFFC0, samples - 1);
1822 if (loops != 0xFFFF)
1823 loops--;
1824 b43_phy_maskset(dev, B43_LPPHY_SMPL_PLAY_COUNT, 0xF000, loops);
1825 b43_phy_maskset(dev, B43_LPPHY_SMPL_PLAY_BUFFER_CTL, 0x3F, wait << 6);
1826 b43_phy_set(dev, B43_LPPHY_A_PHY_CTL_ADDR, 0x1);
1827}
1828
1829//SPEC FIXME what does a negative freq mean?
1830static void lpphy_start_tx_tone(struct b43_wldev *dev, s32 freq, u16 max)
1831{
1832 struct b43_phy_lp *lpphy = dev->phy.lp;
1833 u16 buf[64];
1834 int i, samples = 0, angle = 0, rotation = (9 * freq) / 500;
1835 lpphy_c32 sample;
1836
1837 lpphy->tx_tone_freq = freq;
1838
1839 if (freq) {
1840 /* Find i for which abs(freq) integrally divides 20000 * i */
1841 for (i = 1; samples * abs(freq) != 20000 * i; i++) {
1842 samples = (20000 * i) / abs(freq);
1843 if(B43_WARN_ON(samples > 63))
1844 return;
1845 }
1846 } else {
1847 samples = 2;
1848 }
1849
1850 for (i = 0; i < samples; i++) {
1851 sample = lpphy_cordic(angle);
1852 angle += rotation;
1853 buf[i] = ((sample.i * max) & 0xFF) << 8;
1854 buf[i] |= (sample.q * max) & 0xFF;
1855 }
1856
1857 b43_lptab_write_bulk(dev, B43_LPTAB16(5, 0), samples, buf);
1858
1859 lpphy_run_samples(dev, samples, 0xFFFF, 0);
1860}
1861
1862static void lpphy_stop_tx_tone(struct b43_wldev *dev)
1863{
1864 struct b43_phy_lp *lpphy = dev->phy.lp;
1865 int i;
1866
1867 lpphy->tx_tone_freq = 0;
1868
1869 b43_phy_mask(dev, B43_LPPHY_SMPL_PLAY_COUNT, 0xF000);
1870 for (i = 0; i < 31; i++) {
1871 if (!(b43_phy_read(dev, B43_LPPHY_A_PHY_CTL_ADDR) & 0x1))
1872 break;
1873 udelay(100);
1874 }
1875}
1876
1877
1878static void lpphy_papd_cal(struct b43_wldev *dev, struct lpphy_tx_gains gains,
1879 int mode, bool useindex, u8 index)
1880{
1881 //TODO
1882}
1883
1884static void lpphy_papd_cal_txpwr(struct b43_wldev *dev)
1885{
1886 struct b43_phy_lp *lpphy = dev->phy.lp;
1887 struct ssb_bus *bus = dev->dev->bus;
1888 struct lpphy_tx_gains gains, oldgains;
1889 int old_txpctl, old_afe_ovr, old_rf, old_bbmult;
1890
1891 lpphy_read_tx_pctl_mode_from_hardware(dev);
1892 old_txpctl = lpphy->txpctl_mode;
1893 old_afe_ovr = b43_phy_read(dev, B43_LPPHY_AFE_CTL_OVR) & 0x40;
1894 if (old_afe_ovr)
1895 oldgains = lpphy_get_tx_gains(dev);
1896 old_rf = b43_phy_read(dev, B43_LPPHY_RF_PWR_OVERRIDE) & 0xFF;
1897 old_bbmult = lpphy_get_bb_mult(dev);
1898
1899 lpphy_set_tx_power_control(dev, B43_LPPHY_TXPCTL_OFF);
1900
1901 if (bus->chip_id == 0x4325 && bus->chip_rev == 0)
1902 lpphy_papd_cal(dev, gains, 0, 1, 30);
1903 else
1904 lpphy_papd_cal(dev, gains, 0, 1, 65);
1905
1906 if (old_afe_ovr)
1907 lpphy_set_tx_gains(dev, oldgains);
1908 lpphy_set_bb_mult(dev, old_bbmult);
1909 lpphy_set_tx_power_control(dev, old_txpctl);
1910 b43_phy_maskset(dev, B43_LPPHY_RF_PWR_OVERRIDE, 0xFF00, old_rf);
1911}
1912
1913static int lpphy_rx_iq_cal(struct b43_wldev *dev, bool noise, bool tx,
1914 bool rx, bool pa, struct lpphy_tx_gains *gains)
1915{
1916 struct b43_phy_lp *lpphy = dev->phy.lp;
1917 struct ssb_bus *bus = dev->dev->bus;
1918 const struct lpphy_rx_iq_comp *iqcomp = NULL;
1919 struct lpphy_tx_gains nogains, oldgains;
1920 u16 tmp;
1921 int i, ret;
1922
1923 memset(&nogains, 0, sizeof(nogains));
1924 memset(&oldgains, 0, sizeof(oldgains));
1925
1926 if (bus->chip_id == 0x5354) {
1927 for (i = 0; i < ARRAY_SIZE(lpphy_5354_iq_table); i++) {
1928 if (lpphy_5354_iq_table[i].chan == lpphy->channel) {
1929 iqcomp = &lpphy_5354_iq_table[i];
1930 }
1931 }
1932 } else if (dev->phy.rev >= 2) {
1933 iqcomp = &lpphy_rev2plus_iq_comp;
1934 } else {
1935 for (i = 0; i < ARRAY_SIZE(lpphy_rev0_1_iq_table); i++) {
1936 if (lpphy_rev0_1_iq_table[i].chan == lpphy->channel) {
1937 iqcomp = &lpphy_rev0_1_iq_table[i];
1938 }
1939 }
1940 }
1941
1942 if (B43_WARN_ON(!iqcomp))
1943 return 0;
1944
1945 b43_phy_maskset(dev, B43_LPPHY_RX_COMP_COEFF_S, 0xFF00, iqcomp->c1);
1946 b43_phy_maskset(dev, B43_LPPHY_RX_COMP_COEFF_S,
1947 0x00FF, iqcomp->c0 << 8);
1948
1949 if (noise) {
1950 tx = true;
1951 rx = false;
1952 pa = false;
1953 }
1954
1955 lpphy_set_trsw_over(dev, tx, rx);
1956
1957 if (b43_current_band(dev->wl) == IEEE80211_BAND_2GHZ) {
1958 b43_phy_set(dev, B43_LPPHY_RF_OVERRIDE_0, 0x8);
1959 b43_phy_maskset(dev, B43_LPPHY_RF_OVERRIDE_VAL_0,
1960 0xFFF7, pa << 3);
1961 } else {
1962 b43_phy_set(dev, B43_LPPHY_RF_OVERRIDE_0, 0x20);
1963 b43_phy_maskset(dev, B43_LPPHY_RF_OVERRIDE_VAL_0,
1964 0xFFDF, pa << 5);
1965 }
1966
1967 tmp = b43_phy_read(dev, B43_LPPHY_AFE_CTL_OVR) & 0x40;
1968
1969 if (noise)
1970 lpphy_set_rx_gain(dev, 0x2D5D);
1971 else {
1972 if (tmp)
1973 oldgains = lpphy_get_tx_gains(dev);
1974 if (!gains)
1975 gains = &nogains;
1976 lpphy_set_tx_gains(dev, *gains);
1977 }
1978
1979 b43_phy_mask(dev, B43_LPPHY_AFE_CTL_OVR, 0xFFFE);
1980 b43_phy_mask(dev, B43_LPPHY_AFE_CTL_OVRVAL, 0xFFFE);
1981 b43_phy_set(dev, B43_LPPHY_RF_OVERRIDE_0, 0x800);
1982 b43_phy_set(dev, B43_LPPHY_RF_OVERRIDE_VAL_0, 0x800);
1983 lpphy_set_deaf(dev, false);
1984 if (noise)
1985 ret = lpphy_calc_rx_iq_comp(dev, 0xFFF0);
1986 else {
1987 lpphy_start_tx_tone(dev, 4000, 100);
1988 ret = lpphy_calc_rx_iq_comp(dev, 0x4000);
1989 lpphy_stop_tx_tone(dev);
1990 }
1991 lpphy_clear_deaf(dev, false);
1992 b43_phy_mask(dev, B43_LPPHY_RF_OVERRIDE_0, 0xFFFC);
1993 b43_phy_mask(dev, B43_LPPHY_RF_OVERRIDE_0, 0xFFF7);
1994 b43_phy_mask(dev, B43_LPPHY_RF_OVERRIDE_0, 0xFFDF);
1995 if (!noise) {
1996 if (tmp)
1997 lpphy_set_tx_gains(dev, oldgains);
1998 else
1999 lpphy_disable_tx_gain_override(dev);
2000 }
2001 lpphy_disable_rx_gain_override(dev);
2002 b43_phy_mask(dev, B43_LPPHY_AFE_CTL_OVR, 0xFFFE);
2003 b43_phy_mask(dev, B43_LPPHY_AFE_CTL_OVRVAL, 0xF7FF);
2004 return ret;
2005}
2006
2007static void lpphy_calibration(struct b43_wldev *dev)
2008{
2009 struct b43_phy_lp *lpphy = dev->phy.lp;
2010 enum b43_lpphy_txpctl_mode saved_pctl_mode;
2011 bool full_cal = false;
2012
2013 if (lpphy->full_calib_chan != lpphy->channel) {
2014 full_cal = true;
2015 lpphy->full_calib_chan = lpphy->channel;
2016 }
2017
2018 b43_mac_suspend(dev);
2019
2020 lpphy_btcoex_override(dev);
2021 if (dev->phy.rev >= 2)
2022 lpphy_save_dig_flt_state(dev);
2023 lpphy_read_tx_pctl_mode_from_hardware(dev);
2024 saved_pctl_mode = lpphy->txpctl_mode;
2025 lpphy_set_tx_power_control(dev, B43_LPPHY_TXPCTL_OFF);
2026 //TODO Perform transmit power table I/Q LO calibration
2027 if ((dev->phy.rev == 0) && (saved_pctl_mode != B43_LPPHY_TXPCTL_OFF))
2028 lpphy_pr41573_workaround(dev);
2029 if ((dev->phy.rev >= 2) && full_cal) {
2030 lpphy_papd_cal_txpwr(dev);
2031 }
2032 lpphy_set_tx_power_control(dev, saved_pctl_mode);
2033 if (dev->phy.rev >= 2)
2034 lpphy_restore_dig_flt_state(dev);
2035 lpphy_rx_iq_cal(dev, true, true, false, false, NULL);
2036
2037 b43_mac_enable(dev);
2038}
2039
1498static u16 b43_lpphy_op_read(struct b43_wldev *dev, u16 reg) 2040static u16 b43_lpphy_op_read(struct b43_wldev *dev, u16 reg)
1499{ 2041{
1500 b43_write16(dev, B43_MMIO_PHY_CONTROL, reg); 2042 b43_write16(dev, B43_MMIO_PHY_CONTROL, reg);
@@ -1539,12 +2081,6 @@ static void b43_lpphy_op_radio_write(struct b43_wldev *dev, u16 reg, u16 value)
1539 b43_write16(dev, B43_MMIO_RADIO_DATA_LOW, value); 2081 b43_write16(dev, B43_MMIO_RADIO_DATA_LOW, value);
1540} 2082}
1541 2083
1542static void b43_lpphy_op_software_rfkill(struct b43_wldev *dev,
1543 bool blocked)
1544{
1545 //TODO
1546}
1547
1548struct b206x_channel { 2084struct b206x_channel {
1549 u8 channel; 2085 u8 channel;
1550 u16 freq; 2086 u16 freq;
@@ -2010,22 +2546,6 @@ static int lpphy_b2062_tune(struct b43_wldev *dev,
2010 return err; 2546 return err;
2011} 2547}
2012 2548
2013
2014/* This was previously called lpphy_japan_filter */
2015static void lpphy_set_analog_filter(struct b43_wldev *dev, int channel)
2016{
2017 struct b43_phy_lp *lpphy = dev->phy.lp;
2018 u16 tmp = (channel == 14); //SPEC FIXME check japanwidefilter!
2019
2020 if (dev->phy.rev < 2) { //SPEC FIXME Isn't this rev0/1-specific?
2021 b43_phy_maskset(dev, B43_LPPHY_LP_PHY_CTL, 0xFCFF, tmp << 9);
2022 if ((dev->phy.rev == 1) && (lpphy->rc_cap))
2023 lpphy_set_rc_cap(dev);
2024 } else {
2025 b43_radio_write(dev, B2063_TX_BB_SP3, 0x3F);
2026 }
2027}
2028
2029static void lpphy_b2063_vco_calib(struct b43_wldev *dev) 2549static void lpphy_b2063_vco_calib(struct b43_wldev *dev)
2030{ 2550{
2031 u16 tmp; 2551 u16 tmp;
@@ -2210,18 +2730,6 @@ static int b43_lpphy_op_init(struct b43_wldev *dev)
2210 return 0; 2730 return 0;
2211} 2731}
2212 2732
2213static void b43_lpphy_op_set_rx_antenna(struct b43_wldev *dev, int antenna)
2214{
2215 if (dev->phy.rev >= 2)
2216 return; // rev2+ doesn't support antenna diversity
2217
2218 if (B43_WARN_ON(antenna > B43_ANTENNA_AUTO1))
2219 return;
2220
2221 b43_phy_maskset(dev, B43_LPPHY_CRSGAIN_CTL, 0xFFFD, antenna & 0x2);
2222 b43_phy_maskset(dev, B43_LPPHY_CRSGAIN_CTL, 0xFFFE, antenna & 0x1);
2223}
2224
2225static void b43_lpphy_op_adjust_txpower(struct b43_wldev *dev) 2733static void b43_lpphy_op_adjust_txpower(struct b43_wldev *dev)
2226{ 2734{
2227 //TODO 2735 //TODO
@@ -2244,6 +2752,11 @@ void b43_lpphy_op_switch_analog(struct b43_wldev *dev, bool on)
2244 } 2752 }
2245} 2753}
2246 2754
2755static void b43_lpphy_op_pwork_15sec(struct b43_wldev *dev)
2756{
2757 //TODO
2758}
2759
2247const struct b43_phy_operations b43_phyops_lp = { 2760const struct b43_phy_operations b43_phyops_lp = {
2248 .allocate = b43_lpphy_op_allocate, 2761 .allocate = b43_lpphy_op_allocate,
2249 .free = b43_lpphy_op_free, 2762 .free = b43_lpphy_op_free,
@@ -2261,4 +2774,6 @@ const struct b43_phy_operations b43_phyops_lp = {
2261 .set_rx_antenna = b43_lpphy_op_set_rx_antenna, 2774 .set_rx_antenna = b43_lpphy_op_set_rx_antenna,
2262 .recalc_txpower = b43_lpphy_op_recalc_txpower, 2775 .recalc_txpower = b43_lpphy_op_recalc_txpower,
2263 .adjust_txpower = b43_lpphy_op_adjust_txpower, 2776 .adjust_txpower = b43_lpphy_op_adjust_txpower,
2777 .pwork_15sec = b43_lpphy_op_pwork_15sec,
2778 .pwork_60sec = lpphy_calibration,
2264}; 2779};
diff --git a/drivers/net/wireless/b43/phy_lp.h b/drivers/net/wireless/b43/phy_lp.h
index c3232c17b60a..62737f700cbc 100644
--- a/drivers/net/wireless/b43/phy_lp.h
+++ b/drivers/net/wireless/b43/phy_lp.h
@@ -286,6 +286,7 @@
286#define B43_LPPHY_TR_LOOKUP_6 B43_PHY_OFDM(0xC8) /* TR Lookup 6 */ 286#define B43_LPPHY_TR_LOOKUP_6 B43_PHY_OFDM(0xC8) /* TR Lookup 6 */
287#define B43_LPPHY_TR_LOOKUP_7 B43_PHY_OFDM(0xC9) /* TR Lookup 7 */ 287#define B43_LPPHY_TR_LOOKUP_7 B43_PHY_OFDM(0xC9) /* TR Lookup 7 */
288#define B43_LPPHY_TR_LOOKUP_8 B43_PHY_OFDM(0xCA) /* TR Lookup 8 */ 288#define B43_LPPHY_TR_LOOKUP_8 B43_PHY_OFDM(0xCA) /* TR Lookup 8 */
289#define B43_LPPHY_RF_PWR_OVERRIDE B43_PHY_OFDM(0xD3) /* RF power override */
289 290
290 291
291 292
@@ -871,12 +872,12 @@ struct b43_phy_lp {
871 u8 rssi_gs; 872 u8 rssi_gs;
872 873
873 /* RC cap */ 874 /* RC cap */
874 u8 rc_cap; /* FIXME initial value? */ 875 u8 rc_cap;
875 /* BX arch */ 876 /* BX arch */
876 u8 bx_arch; 877 u8 bx_arch;
877 878
878 /* Full calibration channel */ 879 /* Full calibration channel */
879 u8 full_calib_chan; /* FIXME initial value? */ 880 u8 full_calib_chan;
880 881
881 /* Transmit iqlocal best coeffs */ 882 /* Transmit iqlocal best coeffs */
882 bool tx_iqloc_best_coeffs_valid; 883 bool tx_iqloc_best_coeffs_valid;
@@ -891,6 +892,12 @@ struct b43_phy_lp {
891 892
892 /* The channel we are tuned to */ 893 /* The channel we are tuned to */
893 u8 channel; 894 u8 channel;
895
896 /* The active antenna diversity mode */
897 int antenna;
898
899 /* Frequency of the active TX tone */
900 int tx_tone_freq;
894}; 901};
895 902
896enum tssi_mux_mode { 903enum tssi_mux_mode {
diff --git a/drivers/net/wireless/b43/xmit.c b/drivers/net/wireless/b43/xmit.c
index 7a5e294be2bc..eda06529ef5f 100644
--- a/drivers/net/wireless/b43/xmit.c
+++ b/drivers/net/wireless/b43/xmit.c
@@ -621,7 +621,6 @@ void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr)
621 (phystat0 & B43_RX_PHYST0_OFDM), 621 (phystat0 & B43_RX_PHYST0_OFDM),
622 (phystat0 & B43_RX_PHYST0_GAINCTL), 622 (phystat0 & B43_RX_PHYST0_GAINCTL),
623 (phystat3 & B43_RX_PHYST3_TRSTATE)); 623 (phystat3 & B43_RX_PHYST3_TRSTATE));
624 status.qual = (rxhdr->jssi * 100) / B43_RX_MAX_SSI;
625 } 624 }
626 625
627 if (phystat0 & B43_RX_PHYST0_OFDM) 626 if (phystat0 & B43_RX_PHYST0_OFDM)
diff --git a/drivers/net/wireless/b43legacy/Kconfig b/drivers/net/wireless/b43legacy/Kconfig
index 94a463478053..1ffa28835c58 100644
--- a/drivers/net/wireless/b43legacy/Kconfig
+++ b/drivers/net/wireless/b43legacy/Kconfig
@@ -1,6 +1,6 @@
1config B43LEGACY 1config B43LEGACY
2 tristate "Broadcom 43xx-legacy wireless support (mac80211 stack)" 2 tristate "Broadcom 43xx-legacy wireless support (mac80211 stack)"
3 depends on SSB_POSSIBLE && MAC80211 && WLAN_80211 && HAS_DMA 3 depends on SSB_POSSIBLE && MAC80211 && HAS_DMA
4 select SSB 4 select SSB
5 select FW_LOADER 5 select FW_LOADER
6 ---help--- 6 ---help---
diff --git a/drivers/net/wireless/b43legacy/b43legacy.h b/drivers/net/wireless/b43legacy/b43legacy.h
index 038baa8869e2..89fe2f972c72 100644
--- a/drivers/net/wireless/b43legacy/b43legacy.h
+++ b/drivers/net/wireless/b43legacy/b43legacy.h
@@ -29,8 +29,6 @@
29 29
30#define B43legacy_IRQWAIT_MAX_RETRIES 20 30#define B43legacy_IRQWAIT_MAX_RETRIES 20
31 31
32#define B43legacy_RX_MAX_SSI 60 /* best guess at max ssi */
33
34/* MMIO offsets */ 32/* MMIO offsets */
35#define B43legacy_MMIO_DMA0_REASON 0x20 33#define B43legacy_MMIO_DMA0_REASON 0x20
36#define B43legacy_MMIO_DMA0_IRQ_MASK 0x24 34#define B43legacy_MMIO_DMA0_IRQ_MASK 0x24
diff --git a/drivers/net/wireless/b43legacy/dma.c b/drivers/net/wireless/b43legacy/dma.c
index 866403415811..0a86bdf53154 100644
--- a/drivers/net/wireless/b43legacy/dma.c
+++ b/drivers/net/wireless/b43legacy/dma.c
@@ -1240,8 +1240,9 @@ struct b43legacy_dmaring *parse_cookie(struct b43legacy_wldev *dev,
1240} 1240}
1241 1241
1242static int dma_tx_fragment(struct b43legacy_dmaring *ring, 1242static int dma_tx_fragment(struct b43legacy_dmaring *ring,
1243 struct sk_buff *skb) 1243 struct sk_buff **in_skb)
1244{ 1244{
1245 struct sk_buff *skb = *in_skb;
1245 const struct b43legacy_dma_ops *ops = ring->ops; 1246 const struct b43legacy_dma_ops *ops = ring->ops;
1246 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 1247 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1247 u8 *header; 1248 u8 *header;
@@ -1305,8 +1306,14 @@ static int dma_tx_fragment(struct b43legacy_dmaring *ring,
1305 } 1306 }
1306 1307
1307 memcpy(skb_put(bounce_skb, skb->len), skb->data, skb->len); 1308 memcpy(skb_put(bounce_skb, skb->len), skb->data, skb->len);
1309 memcpy(bounce_skb->cb, skb->cb, sizeof(skb->cb));
1310 bounce_skb->dev = skb->dev;
1311 skb_set_queue_mapping(bounce_skb, skb_get_queue_mapping(skb));
1312 info = IEEE80211_SKB_CB(bounce_skb);
1313
1308 dev_kfree_skb_any(skb); 1314 dev_kfree_skb_any(skb);
1309 skb = bounce_skb; 1315 skb = bounce_skb;
1316 *in_skb = bounce_skb;
1310 meta->skb = skb; 1317 meta->skb = skb;
1311 meta->dmaaddr = map_descbuffer(ring, skb->data, skb->len, 1); 1318 meta->dmaaddr = map_descbuffer(ring, skb->data, skb->len, 1);
1312 if (b43legacy_dma_mapping_error(ring, meta->dmaaddr, skb->len, 1)) { 1319 if (b43legacy_dma_mapping_error(ring, meta->dmaaddr, skb->len, 1)) {
@@ -1360,8 +1367,10 @@ int b43legacy_dma_tx(struct b43legacy_wldev *dev,
1360 struct sk_buff *skb) 1367 struct sk_buff *skb)
1361{ 1368{
1362 struct b43legacy_dmaring *ring; 1369 struct b43legacy_dmaring *ring;
1370 struct ieee80211_hdr *hdr;
1363 int err = 0; 1371 int err = 0;
1364 unsigned long flags; 1372 unsigned long flags;
1373 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1365 1374
1366 ring = priority_to_txring(dev, skb_get_queue_mapping(skb)); 1375 ring = priority_to_txring(dev, skb_get_queue_mapping(skb));
1367 spin_lock_irqsave(&ring->lock, flags); 1376 spin_lock_irqsave(&ring->lock, flags);
@@ -1386,7 +1395,11 @@ int b43legacy_dma_tx(struct b43legacy_wldev *dev,
1386 goto out_unlock; 1395 goto out_unlock;
1387 } 1396 }
1388 1397
1389 err = dma_tx_fragment(ring, skb); 1398 /* dma_tx_fragment might reallocate the skb, so invalidate pointers pointing
1399 * into the skb data or cb now. */
1400 hdr = NULL;
1401 info = NULL;
1402 err = dma_tx_fragment(ring, &skb);
1390 if (unlikely(err == -ENOKEY)) { 1403 if (unlikely(err == -ENOKEY)) {
1391 /* Drop this packet, as we don't have the encryption key 1404 /* Drop this packet, as we don't have the encryption key
1392 * anymore and must not transmit it unencrypted. */ 1405 * anymore and must not transmit it unencrypted. */
diff --git a/drivers/net/wireless/b43legacy/main.c b/drivers/net/wireless/b43legacy/main.c
index 0983406f4630..d579bb9035c4 100644
--- a/drivers/net/wireless/b43legacy/main.c
+++ b/drivers/net/wireless/b43legacy/main.c
@@ -2676,7 +2676,7 @@ static int b43legacy_op_dev_config(struct ieee80211_hw *hw,
2676 if (conf->channel->hw_value != phy->channel) 2676 if (conf->channel->hw_value != phy->channel)
2677 b43legacy_radio_selectchannel(dev, conf->channel->hw_value, 0); 2677 b43legacy_radio_selectchannel(dev, conf->channel->hw_value, 0);
2678 2678
2679 dev->wl->radiotap_enabled = !!(conf->flags & IEEE80211_CONF_RADIOTAP); 2679 dev->wl->radiotap_enabled = !!(conf->flags & IEEE80211_CONF_MONITOR);
2680 2680
2681 /* Adjust the desired TX power level. */ 2681 /* Adjust the desired TX power level. */
2682 if (conf->power_level != 0) { 2682 if (conf->power_level != 0) {
diff --git a/drivers/net/wireless/b43legacy/xmit.c b/drivers/net/wireless/b43legacy/xmit.c
index 103f3c9e7f58..9c8882d9275e 100644
--- a/drivers/net/wireless/b43legacy/xmit.c
+++ b/drivers/net/wireless/b43legacy/xmit.c
@@ -549,7 +549,6 @@ void b43legacy_rx(struct b43legacy_wldev *dev,
549 (phystat0 & B43legacy_RX_PHYST0_GAINCTL), 549 (phystat0 & B43legacy_RX_PHYST0_GAINCTL),
550 (phystat3 & B43legacy_RX_PHYST3_TRSTATE)); 550 (phystat3 & B43legacy_RX_PHYST3_TRSTATE));
551 status.noise = dev->stats.link_noise; 551 status.noise = dev->stats.link_noise;
552 status.qual = (jssi * 100) / B43legacy_RX_MAX_SSI;
553 /* change to support A PHY */ 552 /* change to support A PHY */
554 if (phystat0 & B43legacy_RX_PHYST0_OFDM) 553 if (phystat0 & B43legacy_RX_PHYST0_OFDM)
555 status.rate_idx = b43legacy_plcp_get_bitrate_idx_ofdm(plcp, false); 554 status.rate_idx = b43legacy_plcp_get_bitrate_idx_ofdm(plcp, false);
diff --git a/drivers/net/wireless/hostap/Kconfig b/drivers/net/wireless/hostap/Kconfig
index 08f1e989653d..287d82728bc3 100644
--- a/drivers/net/wireless/hostap/Kconfig
+++ b/drivers/net/wireless/hostap/Kconfig
@@ -1,6 +1,5 @@
1config HOSTAP 1config HOSTAP
2 tristate "IEEE 802.11 for Host AP (Prism2/2.5/3 and WEP/TKIP/CCMP)" 2 tristate "IEEE 802.11 for Host AP (Prism2/2.5/3 and WEP/TKIP/CCMP)"
3 depends on WLAN_80211
4 select WIRELESS_EXT 3 select WIRELESS_EXT
5 select WEXT_SPY 4 select WEXT_SPY
6 select WEXT_PRIV 5 select WEXT_PRIV
diff --git a/drivers/net/wireless/ipw2x00/Kconfig b/drivers/net/wireless/ipw2x00/Kconfig
index 59ec9eec5024..2715b101aded 100644
--- a/drivers/net/wireless/ipw2x00/Kconfig
+++ b/drivers/net/wireless/ipw2x00/Kconfig
@@ -4,7 +4,7 @@
4 4
5config IPW2100 5config IPW2100
6 tristate "Intel PRO/Wireless 2100 Network Connection" 6 tristate "Intel PRO/Wireless 2100 Network Connection"
7 depends on PCI && WLAN_80211 && CFG80211 7 depends on PCI && CFG80211
8 select WIRELESS_EXT 8 select WIRELESS_EXT
9 select WEXT_SPY 9 select WEXT_SPY
10 select WEXT_PRIV 10 select WEXT_PRIV
@@ -65,7 +65,7 @@ config IPW2100_DEBUG
65 65
66config IPW2200 66config IPW2200
67 tristate "Intel PRO/Wireless 2200BG and 2915ABG Network Connection" 67 tristate "Intel PRO/Wireless 2200BG and 2915ABG Network Connection"
68 depends on PCI && WLAN_80211 && CFG80211 && CFG80211_WEXT 68 depends on PCI && CFG80211 && CFG80211_WEXT
69 select WIRELESS_EXT 69 select WIRELESS_EXT
70 select WEXT_SPY 70 select WEXT_SPY
71 select WEXT_PRIV 71 select WEXT_PRIV
@@ -154,7 +154,7 @@ config IPW2200_DEBUG
154 154
155config LIBIPW 155config LIBIPW
156 tristate 156 tristate
157 depends on PCI && WLAN_80211 && CFG80211 157 depends on PCI && CFG80211
158 select WIRELESS_EXT 158 select WIRELESS_EXT
159 select WEXT_SPY 159 select WEXT_SPY
160 select CRYPTO 160 select CRYPTO
diff --git a/drivers/net/wireless/iwlwifi/Kconfig b/drivers/net/wireless/iwlwifi/Kconfig
index c82c97be7bfa..b16b06c2031f 100644
--- a/drivers/net/wireless/iwlwifi/Kconfig
+++ b/drivers/net/wireless/iwlwifi/Kconfig
@@ -1,6 +1,6 @@
1config IWLWIFI 1config IWLWIFI
2 tristate "Intel Wireless Wifi" 2 tristate "Intel Wireless Wifi"
3 depends on PCI && MAC80211 && WLAN_80211 && EXPERIMENTAL 3 depends on PCI && MAC80211 && EXPERIMENTAL
4 select FW_LOADER 4 select FW_LOADER
5 5
6config IWLWIFI_SPECTRUM_MEASUREMENT 6config IWLWIFI_SPECTRUM_MEASUREMENT
diff --git a/drivers/net/wireless/iwlwifi/iwl-1000.c b/drivers/net/wireless/iwlwifi/iwl-1000.c
index 3a645e485dda..1e387b9dce1e 100644
--- a/drivers/net/wireless/iwlwifi/iwl-1000.c
+++ b/drivers/net/wireless/iwlwifi/iwl-1000.c
@@ -164,7 +164,7 @@ struct iwl_cfg iwl1000_bgn_cfg = {
164 .valid_tx_ant = ANT_A, 164 .valid_tx_ant = ANT_A,
165 .valid_rx_ant = ANT_AB, 165 .valid_rx_ant = ANT_AB,
166 .pll_cfg_val = CSR50_ANA_PLL_CFG_VAL, 166 .pll_cfg_val = CSR50_ANA_PLL_CFG_VAL,
167 .set_l0s = false, 167 .set_l0s = true,
168 .use_bsm = false, 168 .use_bsm = false,
169 .max_ll_items = OTP_MAX_LL_ITEMS_1000, 169 .max_ll_items = OTP_MAX_LL_ITEMS_1000,
170 .shadow_ram_support = false, 170 .shadow_ram_support = false,
@@ -190,7 +190,7 @@ struct iwl_cfg iwl1000_bg_cfg = {
190 .valid_tx_ant = ANT_A, 190 .valid_tx_ant = ANT_A,
191 .valid_rx_ant = ANT_AB, 191 .valid_rx_ant = ANT_AB,
192 .pll_cfg_val = CSR50_ANA_PLL_CFG_VAL, 192 .pll_cfg_val = CSR50_ANA_PLL_CFG_VAL,
193 .set_l0s = false, 193 .set_l0s = true,
194 .use_bsm = false, 194 .use_bsm = false,
195 .max_ll_items = OTP_MAX_LL_ITEMS_1000, 195 .max_ll_items = OTP_MAX_LL_ITEMS_1000,
196 .shadow_ram_support = false, 196 .shadow_ram_support = false,
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945-rs.c b/drivers/net/wireless/iwlwifi/iwl-3945-rs.c
index cbb0585083a9..dc81e19674f7 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945-rs.c
+++ b/drivers/net/wireless/iwlwifi/iwl-3945-rs.c
@@ -42,38 +42,6 @@
42 42
43#define RS_NAME "iwl-3945-rs" 43#define RS_NAME "iwl-3945-rs"
44 44
45struct iwl3945_rate_scale_data {
46 u64 data;
47 s32 success_counter;
48 s32 success_ratio;
49 s32 counter;
50 s32 average_tpt;
51 unsigned long stamp;
52};
53
54struct iwl3945_rs_sta {
55 spinlock_t lock;
56 struct iwl_priv *priv;
57 s32 *expected_tpt;
58 unsigned long last_partial_flush;
59 unsigned long last_flush;
60 u32 flush_time;
61 u32 last_tx_packets;
62 u32 tx_packets;
63 u8 tgg;
64 u8 flush_pending;
65 u8 start_rate;
66 u8 ibss_sta_added;
67 struct timer_list rate_scale_flush;
68 struct iwl3945_rate_scale_data win[IWL_RATE_COUNT_3945];
69#ifdef CONFIG_MAC80211_DEBUGFS
70 struct dentry *rs_sta_dbgfs_stats_table_file;
71#endif
72
73 /* used to be in sta_info */
74 int last_txrate_idx;
75};
76
77static s32 iwl3945_expected_tpt_g[IWL_RATE_COUNT_3945] = { 45static s32 iwl3945_expected_tpt_g[IWL_RATE_COUNT_3945] = {
78 7, 13, 35, 58, 0, 0, 76, 104, 130, 168, 191, 202 46 7, 13, 35, 58, 0, 0, 76, 104, 130, 168, 191, 202
79}; 47};
@@ -370,6 +338,28 @@ static void rs_rate_init(void *priv_r, struct ieee80211_supported_band *sband,
370 338
371 IWL_DEBUG_RATE(priv, "enter\n"); 339 IWL_DEBUG_RATE(priv, "enter\n");
372 340
341 spin_lock_init(&rs_sta->lock);
342
343 rs_sta->priv = priv;
344
345 rs_sta->start_rate = IWL_RATE_INVALID;
346
347 /* default to just 802.11b */
348 rs_sta->expected_tpt = iwl3945_expected_tpt_b;
349
350 rs_sta->last_partial_flush = jiffies;
351 rs_sta->last_flush = jiffies;
352 rs_sta->flush_time = IWL_RATE_FLUSH;
353 rs_sta->last_tx_packets = 0;
354 rs_sta->ibss_sta_added = 0;
355
356 init_timer(&rs_sta->rate_scale_flush);
357 rs_sta->rate_scale_flush.data = (unsigned long)rs_sta;
358 rs_sta->rate_scale_flush.function = &iwl3945_bg_rate_scale_flush;
359
360 for (i = 0; i < IWL_RATE_COUNT_3945; i++)
361 iwl3945_clear_window(&rs_sta->win[i]);
362
373 /* TODO: what is a good starting rate for STA? About middle? Maybe not 363 /* TODO: what is a good starting rate for STA? About middle? Maybe not
374 * the lowest or the highest rate.. Could consider using RSSI from 364 * the lowest or the highest rate.. Could consider using RSSI from
375 * previous packets? Need to have IEEE 802.1X auth succeed immediately 365 * previous packets? Need to have IEEE 802.1X auth succeed immediately
@@ -409,45 +399,11 @@ static void *rs_alloc_sta(void *iwl_priv, struct ieee80211_sta *sta, gfp_t gfp)
409{ 399{
410 struct iwl3945_rs_sta *rs_sta; 400 struct iwl3945_rs_sta *rs_sta;
411 struct iwl3945_sta_priv *psta = (void *) sta->drv_priv; 401 struct iwl3945_sta_priv *psta = (void *) sta->drv_priv;
412 struct iwl_priv *priv = iwl_priv; 402 struct iwl_priv *priv __maybe_unused = iwl_priv;
413 int i;
414
415 /*
416 * XXX: If it's using sta->drv_priv anyway, it might
417 * as well just put all the information there.
418 */
419 403
420 IWL_DEBUG_RATE(priv, "enter\n"); 404 IWL_DEBUG_RATE(priv, "enter\n");
421 405
422 rs_sta = kzalloc(sizeof(struct iwl3945_rs_sta), gfp); 406 rs_sta = &psta->rs_sta;
423 if (!rs_sta) {
424 IWL_DEBUG_RATE(priv, "leave: ENOMEM\n");
425 return NULL;
426 }
427
428 psta->rs_sta = rs_sta;
429
430 spin_lock_init(&rs_sta->lock);
431
432 rs_sta->priv = priv;
433
434 rs_sta->start_rate = IWL_RATE_INVALID;
435
436 /* default to just 802.11b */
437 rs_sta->expected_tpt = iwl3945_expected_tpt_b;
438
439 rs_sta->last_partial_flush = jiffies;
440 rs_sta->last_flush = jiffies;
441 rs_sta->flush_time = IWL_RATE_FLUSH;
442 rs_sta->last_tx_packets = 0;
443 rs_sta->ibss_sta_added = 0;
444
445 init_timer(&rs_sta->rate_scale_flush);
446 rs_sta->rate_scale_flush.data = (unsigned long)rs_sta;
447 rs_sta->rate_scale_flush.function = &iwl3945_bg_rate_scale_flush;
448
449 for (i = 0; i < IWL_RATE_COUNT_3945; i++)
450 iwl3945_clear_window(&rs_sta->win[i]);
451 407
452 IWL_DEBUG_RATE(priv, "leave\n"); 408 IWL_DEBUG_RATE(priv, "leave\n");
453 409
@@ -458,14 +414,11 @@ static void rs_free_sta(void *iwl_priv, struct ieee80211_sta *sta,
458 void *priv_sta) 414 void *priv_sta)
459{ 415{
460 struct iwl3945_sta_priv *psta = (void *) sta->drv_priv; 416 struct iwl3945_sta_priv *psta = (void *) sta->drv_priv;
461 struct iwl3945_rs_sta *rs_sta = priv_sta; 417 struct iwl3945_rs_sta *rs_sta = &psta->rs_sta;
462 struct iwl_priv *priv __maybe_unused = rs_sta->priv; 418 struct iwl_priv *priv __maybe_unused = rs_sta->priv;
463 419
464 psta->rs_sta = NULL;
465
466 IWL_DEBUG_RATE(priv, "enter\n"); 420 IWL_DEBUG_RATE(priv, "enter\n");
467 del_timer_sync(&rs_sta->rate_scale_flush); 421 del_timer_sync(&rs_sta->rate_scale_flush);
468 kfree(rs_sta);
469 IWL_DEBUG_RATE(priv, "leave\n"); 422 IWL_DEBUG_RATE(priv, "leave\n");
470} 423}
471 424
@@ -960,14 +913,15 @@ void iwl3945_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id)
960 913
961 rcu_read_lock(); 914 rcu_read_lock();
962 915
963 sta = ieee80211_find_sta(hw, priv->stations[sta_id].sta.sta.addr); 916 sta = ieee80211_find_sta(priv->vif,
917 priv->stations[sta_id].sta.sta.addr);
964 if (!sta) { 918 if (!sta) {
965 rcu_read_unlock(); 919 rcu_read_unlock();
966 return; 920 return;
967 } 921 }
968 922
969 psta = (void *) sta->drv_priv; 923 psta = (void *) sta->drv_priv;
970 rs_sta = psta->rs_sta; 924 rs_sta = &psta->rs_sta;
971 925
972 spin_lock_irqsave(&rs_sta->lock, flags); 926 spin_lock_irqsave(&rs_sta->lock, flags);
973 927
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945.h b/drivers/net/wireless/iwlwifi/iwl-3945.h
index ebb999a51b58..2b0d65c5780a 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945.h
+++ b/drivers/net/wireless/iwlwifi/iwl-3945.h
@@ -74,8 +74,41 @@ extern struct pci_device_id iwl3945_hw_card_ids[];
74/* Module parameters accessible from iwl-*.c */ 74/* Module parameters accessible from iwl-*.c */
75extern struct iwl_mod_params iwl3945_mod_params; 75extern struct iwl_mod_params iwl3945_mod_params;
76 76
77struct iwl3945_rate_scale_data {
78 u64 data;
79 s32 success_counter;
80 s32 success_ratio;
81 s32 counter;
82 s32 average_tpt;
83 unsigned long stamp;
84};
85
86struct iwl3945_rs_sta {
87 spinlock_t lock;
88 struct iwl_priv *priv;
89 s32 *expected_tpt;
90 unsigned long last_partial_flush;
91 unsigned long last_flush;
92 u32 flush_time;
93 u32 last_tx_packets;
94 u32 tx_packets;
95 u8 tgg;
96 u8 flush_pending;
97 u8 start_rate;
98 u8 ibss_sta_added;
99 struct timer_list rate_scale_flush;
100 struct iwl3945_rate_scale_data win[IWL_RATE_COUNT_3945];
101#ifdef CONFIG_MAC80211_DEBUGFS
102 struct dentry *rs_sta_dbgfs_stats_table_file;
103#endif
104
105 /* used to be in sta_info */
106 int last_txrate_idx;
107};
108
109
77struct iwl3945_sta_priv { 110struct iwl3945_sta_priv {
78 struct iwl3945_rs_sta *rs_sta; 111 struct iwl3945_rs_sta rs_sta;
79}; 112};
80 113
81enum iwl3945_antenna { 114enum iwl3945_antenna {
diff --git a/drivers/net/wireless/iwlwifi/iwl-5000.c b/drivers/net/wireless/iwlwifi/iwl-5000.c
index d256fecc6cda..910217f0ad8a 100644
--- a/drivers/net/wireless/iwlwifi/iwl-5000.c
+++ b/drivers/net/wireless/iwlwifi/iwl-5000.c
@@ -591,16 +591,6 @@ static void iwl5000_tx_queue_set_status(struct iwl_priv *priv,
591 scd_retry ? "BA" : "AC", txq_id, tx_fifo_id); 591 scd_retry ? "BA" : "AC", txq_id, tx_fifo_id);
592} 592}
593 593
594static int iwl5000_send_wimax_coex(struct iwl_priv *priv)
595{
596 struct iwl_wimax_coex_cmd coex_cmd;
597
598 memset(&coex_cmd, 0, sizeof(coex_cmd));
599
600 return iwl_send_cmd_pdu(priv, COEX_PRIORITY_TABLE_CMD,
601 sizeof(coex_cmd), &coex_cmd);
602}
603
604int iwl5000_alive_notify(struct iwl_priv *priv) 594int iwl5000_alive_notify(struct iwl_priv *priv)
605{ 595{
606 u32 a; 596 u32 a;
@@ -681,7 +671,7 @@ int iwl5000_alive_notify(struct iwl_priv *priv)
681 spin_unlock_irqrestore(&priv->lock, flags); 671 spin_unlock_irqrestore(&priv->lock, flags);
682 672
683 673
684 iwl5000_send_wimax_coex(priv); 674 iwl_send_wimax_coex(priv);
685 675
686 iwl5000_set_Xtal_calib(priv); 676 iwl5000_set_Xtal_calib(priv);
687 iwl_send_calib_results(priv); 677 iwl_send_calib_results(priv);
diff --git a/drivers/net/wireless/iwlwifi/iwl-6000.c b/drivers/net/wireless/iwlwifi/iwl-6000.c
index 32466d38d1ae..70e117f8d0c4 100644
--- a/drivers/net/wireless/iwlwifi/iwl-6000.c
+++ b/drivers/net/wireless/iwlwifi/iwl-6000.c
@@ -299,7 +299,7 @@ struct iwl_cfg iwl6000h_2agn_cfg = {
299 .valid_tx_ant = ANT_AB, 299 .valid_tx_ant = ANT_AB,
300 .valid_rx_ant = ANT_AB, 300 .valid_rx_ant = ANT_AB,
301 .pll_cfg_val = 0, 301 .pll_cfg_val = 0,
302 .set_l0s = false, 302 .set_l0s = true,
303 .use_bsm = false, 303 .use_bsm = false,
304 .pa_type = IWL_PA_HYBRID, 304 .pa_type = IWL_PA_HYBRID,
305 .max_ll_items = OTP_MAX_LL_ITEMS_6x00, 305 .max_ll_items = OTP_MAX_LL_ITEMS_6x00,
@@ -329,7 +329,7 @@ struct iwl_cfg iwl6000h_2abg_cfg = {
329 .valid_tx_ant = ANT_AB, 329 .valid_tx_ant = ANT_AB,
330 .valid_rx_ant = ANT_AB, 330 .valid_rx_ant = ANT_AB,
331 .pll_cfg_val = 0, 331 .pll_cfg_val = 0,
332 .set_l0s = false, 332 .set_l0s = true,
333 .use_bsm = false, 333 .use_bsm = false,
334 .pa_type = IWL_PA_HYBRID, 334 .pa_type = IWL_PA_HYBRID,
335 .max_ll_items = OTP_MAX_LL_ITEMS_6x00, 335 .max_ll_items = OTP_MAX_LL_ITEMS_6x00,
@@ -358,7 +358,7 @@ struct iwl_cfg iwl6000h_2bg_cfg = {
358 .valid_tx_ant = ANT_AB, 358 .valid_tx_ant = ANT_AB,
359 .valid_rx_ant = ANT_AB, 359 .valid_rx_ant = ANT_AB,
360 .pll_cfg_val = 0, 360 .pll_cfg_val = 0,
361 .set_l0s = false, 361 .set_l0s = true,
362 .use_bsm = false, 362 .use_bsm = false,
363 .pa_type = IWL_PA_HYBRID, 363 .pa_type = IWL_PA_HYBRID,
364 .max_ll_items = OTP_MAX_LL_ITEMS_6x00, 364 .max_ll_items = OTP_MAX_LL_ITEMS_6x00,
@@ -390,7 +390,7 @@ struct iwl_cfg iwl6000i_2agn_cfg = {
390 .valid_tx_ant = ANT_BC, 390 .valid_tx_ant = ANT_BC,
391 .valid_rx_ant = ANT_BC, 391 .valid_rx_ant = ANT_BC,
392 .pll_cfg_val = 0, 392 .pll_cfg_val = 0,
393 .set_l0s = false, 393 .set_l0s = true,
394 .use_bsm = false, 394 .use_bsm = false,
395 .pa_type = IWL_PA_INTERNAL, 395 .pa_type = IWL_PA_INTERNAL,
396 .max_ll_items = OTP_MAX_LL_ITEMS_6x00, 396 .max_ll_items = OTP_MAX_LL_ITEMS_6x00,
@@ -420,7 +420,7 @@ struct iwl_cfg iwl6000i_2abg_cfg = {
420 .valid_tx_ant = ANT_BC, 420 .valid_tx_ant = ANT_BC,
421 .valid_rx_ant = ANT_BC, 421 .valid_rx_ant = ANT_BC,
422 .pll_cfg_val = 0, 422 .pll_cfg_val = 0,
423 .set_l0s = false, 423 .set_l0s = true,
424 .use_bsm = false, 424 .use_bsm = false,
425 .pa_type = IWL_PA_INTERNAL, 425 .pa_type = IWL_PA_INTERNAL,
426 .max_ll_items = OTP_MAX_LL_ITEMS_6x00, 426 .max_ll_items = OTP_MAX_LL_ITEMS_6x00,
@@ -449,7 +449,7 @@ struct iwl_cfg iwl6000i_2bg_cfg = {
449 .valid_tx_ant = ANT_BC, 449 .valid_tx_ant = ANT_BC,
450 .valid_rx_ant = ANT_BC, 450 .valid_rx_ant = ANT_BC,
451 .pll_cfg_val = 0, 451 .pll_cfg_val = 0,
452 .set_l0s = false, 452 .set_l0s = true,
453 .use_bsm = false, 453 .use_bsm = false,
454 .pa_type = IWL_PA_INTERNAL, 454 .pa_type = IWL_PA_INTERNAL,
455 .max_ll_items = OTP_MAX_LL_ITEMS_6x00, 455 .max_ll_items = OTP_MAX_LL_ITEMS_6x00,
@@ -478,7 +478,7 @@ struct iwl_cfg iwl6050_2agn_cfg = {
478 .valid_tx_ant = ANT_AB, 478 .valid_tx_ant = ANT_AB,
479 .valid_rx_ant = ANT_AB, 479 .valid_rx_ant = ANT_AB,
480 .pll_cfg_val = 0, 480 .pll_cfg_val = 0,
481 .set_l0s = false, 481 .set_l0s = true,
482 .use_bsm = false, 482 .use_bsm = false,
483 .pa_type = IWL_PA_SYSTEM, 483 .pa_type = IWL_PA_SYSTEM,
484 .max_ll_items = OTP_MAX_LL_ITEMS_6x50, 484 .max_ll_items = OTP_MAX_LL_ITEMS_6x50,
@@ -490,6 +490,8 @@ struct iwl_cfg iwl6050_2agn_cfg = {
490 .supports_idle = true, 490 .supports_idle = true,
491 .adv_thermal_throttle = true, 491 .adv_thermal_throttle = true,
492 .support_ct_kill_exit = true, 492 .support_ct_kill_exit = true,
493 .support_sm_ps = true,
494 .support_wimax_coexist = true,
493}; 495};
494 496
495struct iwl_cfg iwl6050_2abg_cfg = { 497struct iwl_cfg iwl6050_2abg_cfg = {
@@ -508,7 +510,7 @@ struct iwl_cfg iwl6050_2abg_cfg = {
508 .valid_tx_ant = ANT_AB, 510 .valid_tx_ant = ANT_AB,
509 .valid_rx_ant = ANT_AB, 511 .valid_rx_ant = ANT_AB,
510 .pll_cfg_val = 0, 512 .pll_cfg_val = 0,
511 .set_l0s = false, 513 .set_l0s = true,
512 .use_bsm = false, 514 .use_bsm = false,
513 .pa_type = IWL_PA_SYSTEM, 515 .pa_type = IWL_PA_SYSTEM,
514 .max_ll_items = OTP_MAX_LL_ITEMS_6x50, 516 .max_ll_items = OTP_MAX_LL_ITEMS_6x50,
@@ -519,6 +521,7 @@ struct iwl_cfg iwl6050_2abg_cfg = {
519 .supports_idle = true, 521 .supports_idle = true,
520 .adv_thermal_throttle = true, 522 .adv_thermal_throttle = true,
521 .support_ct_kill_exit = true, 523 .support_ct_kill_exit = true,
524 .support_wimax_coexist = true,
522}; 525};
523 526
524struct iwl_cfg iwl6000_3agn_cfg = { 527struct iwl_cfg iwl6000_3agn_cfg = {
@@ -537,7 +540,7 @@ struct iwl_cfg iwl6000_3agn_cfg = {
537 .valid_tx_ant = ANT_ABC, 540 .valid_tx_ant = ANT_ABC,
538 .valid_rx_ant = ANT_ABC, 541 .valid_rx_ant = ANT_ABC,
539 .pll_cfg_val = 0, 542 .pll_cfg_val = 0,
540 .set_l0s = false, 543 .set_l0s = true,
541 .use_bsm = false, 544 .use_bsm = false,
542 .pa_type = IWL_PA_SYSTEM, 545 .pa_type = IWL_PA_SYSTEM,
543 .max_ll_items = OTP_MAX_LL_ITEMS_6x00, 546 .max_ll_items = OTP_MAX_LL_ITEMS_6x00,
@@ -567,7 +570,7 @@ struct iwl_cfg iwl6050_3agn_cfg = {
567 .valid_tx_ant = ANT_ABC, 570 .valid_tx_ant = ANT_ABC,
568 .valid_rx_ant = ANT_ABC, 571 .valid_rx_ant = ANT_ABC,
569 .pll_cfg_val = 0, 572 .pll_cfg_val = 0,
570 .set_l0s = false, 573 .set_l0s = true,
571 .use_bsm = false, 574 .use_bsm = false,
572 .pa_type = IWL_PA_SYSTEM, 575 .pa_type = IWL_PA_SYSTEM,
573 .max_ll_items = OTP_MAX_LL_ITEMS_6x50, 576 .max_ll_items = OTP_MAX_LL_ITEMS_6x50,
@@ -579,6 +582,8 @@ struct iwl_cfg iwl6050_3agn_cfg = {
579 .supports_idle = true, 582 .supports_idle = true,
580 .adv_thermal_throttle = true, 583 .adv_thermal_throttle = true,
581 .support_ct_kill_exit = true, 584 .support_ct_kill_exit = true,
585 .support_sm_ps = true,
586 .support_wimax_coexist = true,
582}; 587};
583 588
584MODULE_FIRMWARE(IWL6000_MODULE_FIRMWARE(IWL6000_UCODE_API_MAX)); 589MODULE_FIRMWARE(IWL6000_MODULE_FIRMWARE(IWL6000_UCODE_API_MAX));
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
index 27d4ece4d467..43edd8fd4405 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
@@ -2477,19 +2477,12 @@ static void *rs_alloc_sta(void *priv_rate, struct ieee80211_sta *sta,
2477 struct iwl_lq_sta *lq_sta; 2477 struct iwl_lq_sta *lq_sta;
2478 struct iwl_station_priv *sta_priv = (struct iwl_station_priv *) sta->drv_priv; 2478 struct iwl_station_priv *sta_priv = (struct iwl_station_priv *) sta->drv_priv;
2479 struct iwl_priv *priv; 2479 struct iwl_priv *priv;
2480 int i, j;
2481 2480
2482 priv = (struct iwl_priv *)priv_rate; 2481 priv = (struct iwl_priv *)priv_rate;
2483 IWL_DEBUG_RATE(priv, "create station rate scale window\n"); 2482 IWL_DEBUG_RATE(priv, "create station rate scale window\n");
2484 2483
2485 lq_sta = &sta_priv->lq_sta; 2484 lq_sta = &sta_priv->lq_sta;
2486 2485
2487 lq_sta->lq.sta_id = 0xff;
2488
2489 for (j = 0; j < LQ_SIZE; j++)
2490 for (i = 0; i < IWL_RATE_COUNT; i++)
2491 rs_rate_scale_clear_window(&lq_sta->lq_info[j].win[i]);
2492
2493 return lq_sta; 2486 return lq_sta;
2494} 2487}
2495 2488
@@ -2502,6 +2495,12 @@ static void rs_rate_init(void *priv_r, struct ieee80211_supported_band *sband,
2502 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap; 2495 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
2503 struct iwl_lq_sta *lq_sta = priv_sta; 2496 struct iwl_lq_sta *lq_sta = priv_sta;
2504 2497
2498 lq_sta->lq.sta_id = 0xff;
2499
2500 for (j = 0; j < LQ_SIZE; j++)
2501 for (i = 0; i < IWL_RATE_COUNT; i++)
2502 rs_rate_scale_clear_window(&lq_sta->lq_info[j].win[i]);
2503
2505 lq_sta->flush_timer = 0; 2504 lq_sta->flush_timer = 0;
2506 lq_sta->supp_rates = sta->supp_rates[sband->band]; 2505 lq_sta->supp_rates = sta->supp_rates[sband->band];
2507 for (j = 0; j < LQ_SIZE; j++) 2506 for (j = 0; j < LQ_SIZE; j++)
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.c b/drivers/net/wireless/iwlwifi/iwl-agn.c
index fa1672e99e4b..b5fe8f87aa7e 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn.c
@@ -190,11 +190,7 @@ int iwl_commit_rxon(struct iwl_priv *priv)
190 priv->start_calib = 0; 190 priv->start_calib = 0;
191 191
192 /* Add the broadcast address so we can send broadcast frames */ 192 /* Add the broadcast address so we can send broadcast frames */
193 if (iwl_rxon_add_station(priv, iwl_bcast_addr, 0) == 193 iwl_add_bcast_station(priv);
194 IWL_INVALID_STATION) {
195 IWL_ERR(priv, "Error adding BROADCAST address for transmit.\n");
196 return -EIO;
197 }
198 194
199 /* If we have set the ASSOC_MSK and we are in BSS mode then 195 /* If we have set the ASSOC_MSK and we are in BSS mode then
200 * add the IWL_AP_ID to the station rate table */ 196 * add the IWL_AP_ID to the station rate table */
@@ -890,6 +886,7 @@ static void iwl_irq_tasklet_legacy(struct iwl_priv *priv)
890 u32 inta, handled = 0; 886 u32 inta, handled = 0;
891 u32 inta_fh; 887 u32 inta_fh;
892 unsigned long flags; 888 unsigned long flags;
889 u32 i;
893#ifdef CONFIG_IWLWIFI_DEBUG 890#ifdef CONFIG_IWLWIFI_DEBUG
894 u32 inta_mask; 891 u32 inta_mask;
895#endif 892#endif
@@ -1007,19 +1004,17 @@ static void iwl_irq_tasklet_legacy(struct iwl_priv *priv)
1007 handled |= CSR_INT_BIT_SW_ERR; 1004 handled |= CSR_INT_BIT_SW_ERR;
1008 } 1005 }
1009 1006
1010 /* uCode wakes up after power-down sleep */ 1007 /*
1008 * uCode wakes up after power-down sleep.
1009 * Tell device about any new tx or host commands enqueued,
1010 * and about any Rx buffers made available while asleep.
1011 */
1011 if (inta & CSR_INT_BIT_WAKEUP) { 1012 if (inta & CSR_INT_BIT_WAKEUP) {
1012 IWL_DEBUG_ISR(priv, "Wakeup interrupt\n"); 1013 IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
1013 iwl_rx_queue_update_write_ptr(priv, &priv->rxq); 1014 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
1014 iwl_txq_update_write_ptr(priv, &priv->txq[0]); 1015 for (i = 0; i < priv->hw_params.max_txq_num; i++)
1015 iwl_txq_update_write_ptr(priv, &priv->txq[1]); 1016 iwl_txq_update_write_ptr(priv, &priv->txq[i]);
1016 iwl_txq_update_write_ptr(priv, &priv->txq[2]);
1017 iwl_txq_update_write_ptr(priv, &priv->txq[3]);
1018 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
1019 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
1020
1021 priv->isr_stats.wakeup++; 1017 priv->isr_stats.wakeup++;
1022
1023 handled |= CSR_INT_BIT_WAKEUP; 1018 handled |= CSR_INT_BIT_WAKEUP;
1024 } 1019 }
1025 1020
@@ -1033,11 +1028,12 @@ static void iwl_irq_tasklet_legacy(struct iwl_priv *priv)
1033 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX); 1028 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
1034 } 1029 }
1035 1030
1031 /* This "Tx" DMA channel is used only for loading uCode */
1036 if (inta & CSR_INT_BIT_FH_TX) { 1032 if (inta & CSR_INT_BIT_FH_TX) {
1037 IWL_DEBUG_ISR(priv, "Tx interrupt\n"); 1033 IWL_DEBUG_ISR(priv, "uCode load interrupt\n");
1038 priv->isr_stats.tx++; 1034 priv->isr_stats.tx++;
1039 handled |= CSR_INT_BIT_FH_TX; 1035 handled |= CSR_INT_BIT_FH_TX;
1040 /* FH finished to write, send event */ 1036 /* Wake up uCode load routine, now that load is complete */
1041 priv->ucode_write_complete = 1; 1037 priv->ucode_write_complete = 1;
1042 wake_up_interruptible(&priv->wait_command_queue); 1038 wake_up_interruptible(&priv->wait_command_queue);
1043 } 1039 }
@@ -1234,12 +1230,13 @@ static void iwl_irq_tasklet(struct iwl_priv *priv)
1234 iwl_leds_background(priv); 1230 iwl_leds_background(priv);
1235 } 1231 }
1236 1232
1233 /* This "Tx" DMA channel is used only for loading uCode */
1237 if (inta & CSR_INT_BIT_FH_TX) { 1234 if (inta & CSR_INT_BIT_FH_TX) {
1238 iwl_write32(priv, CSR_FH_INT_STATUS, CSR49_FH_INT_TX_MASK); 1235 iwl_write32(priv, CSR_FH_INT_STATUS, CSR49_FH_INT_TX_MASK);
1239 IWL_DEBUG_ISR(priv, "Tx interrupt\n"); 1236 IWL_DEBUG_ISR(priv, "uCode load interrupt\n");
1240 priv->isr_stats.tx++; 1237 priv->isr_stats.tx++;
1241 handled |= CSR_INT_BIT_FH_TX; 1238 handled |= CSR_INT_BIT_FH_TX;
1242 /* FH finished to write, send event */ 1239 /* Wake up uCode load routine, now that load is complete */
1243 priv->ucode_write_complete = 1; 1240 priv->ucode_write_complete = 1;
1244 wake_up_interruptible(&priv->wait_command_queue); 1241 wake_up_interruptible(&priv->wait_command_queue);
1245 } 1242 }
@@ -1377,6 +1374,14 @@ static int iwl_read_ucode(struct iwl_priv *priv)
1377 IWL_UCODE_API(priv->ucode_ver), 1374 IWL_UCODE_API(priv->ucode_ver),
1378 IWL_UCODE_SERIAL(priv->ucode_ver)); 1375 IWL_UCODE_SERIAL(priv->ucode_ver));
1379 1376
1377 snprintf(priv->hw->wiphy->fw_version,
1378 sizeof(priv->hw->wiphy->fw_version),
1379 "%u.%u.%u.%u",
1380 IWL_UCODE_MAJOR(priv->ucode_ver),
1381 IWL_UCODE_MINOR(priv->ucode_ver),
1382 IWL_UCODE_API(priv->ucode_ver),
1383 IWL_UCODE_SERIAL(priv->ucode_ver));
1384
1380 if (build) 1385 if (build)
1381 IWL_DEBUG_INFO(priv, "Build %u\n", build); 1386 IWL_DEBUG_INFO(priv, "Build %u\n", build);
1382 1387
@@ -2515,7 +2520,7 @@ void iwl_config_ap(struct iwl_priv *priv)
2515 spin_lock_irqsave(&priv->lock, flags); 2520 spin_lock_irqsave(&priv->lock, flags);
2516 iwl_activate_qos(priv, 1); 2521 iwl_activate_qos(priv, 1);
2517 spin_unlock_irqrestore(&priv->lock, flags); 2522 spin_unlock_irqrestore(&priv->lock, flags);
2518 iwl_rxon_add_station(priv, iwl_bcast_addr, 0); 2523 iwl_add_bcast_station(priv);
2519 } 2524 }
2520 iwl_send_beacon_cmd(priv); 2525 iwl_send_beacon_cmd(priv);
2521 2526
@@ -2963,6 +2968,100 @@ static void iwl_cancel_deferred_work(struct iwl_priv *priv)
2963 del_timer_sync(&priv->statistics_periodic); 2968 del_timer_sync(&priv->statistics_periodic);
2964} 2969}
2965 2970
2971static void iwl_init_hw_rates(struct iwl_priv *priv,
2972 struct ieee80211_rate *rates)
2973{
2974 int i;
2975
2976 for (i = 0; i < IWL_RATE_COUNT_LEGACY; i++) {
2977 rates[i].bitrate = iwl_rates[i].ieee * 5;
2978 rates[i].hw_value = i; /* Rate scaling will work on indexes */
2979 rates[i].hw_value_short = i;
2980 rates[i].flags = 0;
2981 if ((i >= IWL_FIRST_CCK_RATE) && (i <= IWL_LAST_CCK_RATE)) {
2982 /*
2983 * If CCK != 1M then set short preamble rate flag.
2984 */
2985 rates[i].flags |=
2986 (iwl_rates[i].plcp == IWL_RATE_1M_PLCP) ?
2987 0 : IEEE80211_RATE_SHORT_PREAMBLE;
2988 }
2989 }
2990}
2991
2992static int iwl_init_drv(struct iwl_priv *priv)
2993{
2994 int ret;
2995
2996 priv->ibss_beacon = NULL;
2997
2998 spin_lock_init(&priv->lock);
2999 spin_lock_init(&priv->sta_lock);
3000 spin_lock_init(&priv->hcmd_lock);
3001
3002 INIT_LIST_HEAD(&priv->free_frames);
3003
3004 mutex_init(&priv->mutex);
3005
3006 /* Clear the driver's (not device's) station table */
3007 iwl_clear_stations_table(priv);
3008
3009 priv->ieee_channels = NULL;
3010 priv->ieee_rates = NULL;
3011 priv->band = IEEE80211_BAND_2GHZ;
3012
3013 priv->iw_mode = NL80211_IFTYPE_STATION;
3014 if (priv->cfg->support_sm_ps)
3015 priv->current_ht_config.sm_ps = WLAN_HT_CAP_SM_PS_DYNAMIC;
3016 else
3017 priv->current_ht_config.sm_ps = WLAN_HT_CAP_SM_PS_DISABLED;
3018
3019 /* Choose which receivers/antennas to use */
3020 if (priv->cfg->ops->hcmd->set_rxon_chain)
3021 priv->cfg->ops->hcmd->set_rxon_chain(priv);
3022
3023 iwl_init_scan_params(priv);
3024
3025 iwl_reset_qos(priv);
3026
3027 priv->qos_data.qos_active = 0;
3028 priv->qos_data.qos_cap.val = 0;
3029
3030 priv->rates_mask = IWL_RATES_MASK;
3031 /* Set the tx_power_user_lmt to the lowest power level
3032 * this value will get overwritten by channel max power avg
3033 * from eeprom */
3034 priv->tx_power_user_lmt = IWL_TX_POWER_TARGET_POWER_MIN;
3035
3036 ret = iwl_init_channel_map(priv);
3037 if (ret) {
3038 IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
3039 goto err;
3040 }
3041
3042 ret = iwlcore_init_geos(priv);
3043 if (ret) {
3044 IWL_ERR(priv, "initializing geos failed: %d\n", ret);
3045 goto err_free_channel_map;
3046 }
3047 iwl_init_hw_rates(priv, priv->ieee_rates);
3048
3049 return 0;
3050
3051err_free_channel_map:
3052 iwl_free_channel_map(priv);
3053err:
3054 return ret;
3055}
3056
3057static void iwl_uninit_drv(struct iwl_priv *priv)
3058{
3059 iwl_calib_free_results(priv);
3060 iwlcore_free_geos(priv);
3061 iwl_free_channel_map(priv);
3062 kfree(priv->scan);
3063}
3064
2966static struct attribute *iwl_sysfs_entries[] = { 3065static struct attribute *iwl_sysfs_entries[] = {
2967 &dev_attr_flags.attr, 3066 &dev_attr_flags.attr,
2968 &dev_attr_filter_flags.attr, 3067 &dev_attr_filter_flags.attr,
@@ -3105,12 +3204,6 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
3105 goto out_iounmap; 3204 goto out_iounmap;
3106 } 3205 }
3107 3206
3108 /* amp init */
3109 err = priv->cfg->ops->lib->apm_ops.init(priv);
3110 if (err < 0) {
3111 IWL_ERR(priv, "Failed to init APMG\n");
3112 goto out_iounmap;
3113 }
3114 /***************** 3207 /*****************
3115 * 4. Read EEPROM 3208 * 4. Read EEPROM
3116 *****************/ 3209 *****************/
diff --git a/drivers/net/wireless/iwlwifi/iwl-calib.c b/drivers/net/wireless/iwlwifi/iwl-calib.c
index 1f801eb9fbff..d994de7438d8 100644
--- a/drivers/net/wireless/iwlwifi/iwl-calib.c
+++ b/drivers/net/wireless/iwlwifi/iwl-calib.c
@@ -132,6 +132,7 @@ void iwl_calib_free_results(struct iwl_priv *priv)
132 priv->calib_results[i].buf_len = 0; 132 priv->calib_results[i].buf_len = 0;
133 } 133 }
134} 134}
135EXPORT_SYMBOL(iwl_calib_free_results);
135 136
136/***************************************************************************** 137/*****************************************************************************
137 * RUNTIME calibrations framework 138 * RUNTIME calibrations framework
diff --git a/drivers/net/wireless/iwlwifi/iwl-commands.h b/drivers/net/wireless/iwlwifi/iwl-commands.h
index 954bad60355d..b62c90ec9e1e 100644
--- a/drivers/net/wireless/iwlwifi/iwl-commands.h
+++ b/drivers/net/wireless/iwlwifi/iwl-commands.h
@@ -3503,30 +3503,134 @@ struct iwl_led_cmd {
3503} __attribute__ ((packed)); 3503} __attribute__ ((packed));
3504 3504
3505/* 3505/*
3506 * Coexistence WIFI/WIMAX Command 3506 * station priority table entries
3507 * COEX_PRIORITY_TABLE_CMD = 0x5a 3507 * also used as potential "events" value for both
3508 * 3508 * COEX_MEDIUM_NOTIFICATION and COEX_EVENT_CMD
3509 */ 3509 */
3510
3511/*
3512 * COEX events entry flag masks
3513 * RP - Requested Priority
3514 * WP - Win Medium Priority: priority assigned when the contention has been won
3515 */
3516#define COEX_EVT_FLAG_MEDIUM_FREE_NTFY_FLG (0x1)
3517#define COEX_EVT_FLAG_MEDIUM_ACTV_NTFY_FLG (0x2)
3518#define COEX_EVT_FLAG_DELAY_MEDIUM_FREE_NTFY_FLG (0x4)
3519
3520#define COEX_CU_UNASSOC_IDLE_RP 4
3521#define COEX_CU_UNASSOC_MANUAL_SCAN_RP 4
3522#define COEX_CU_UNASSOC_AUTO_SCAN_RP 4
3523#define COEX_CU_CALIBRATION_RP 4
3524#define COEX_CU_PERIODIC_CALIBRATION_RP 4
3525#define COEX_CU_CONNECTION_ESTAB_RP 4
3526#define COEX_CU_ASSOCIATED_IDLE_RP 4
3527#define COEX_CU_ASSOC_MANUAL_SCAN_RP 4
3528#define COEX_CU_ASSOC_AUTO_SCAN_RP 4
3529#define COEX_CU_ASSOC_ACTIVE_LEVEL_RP 4
3530#define COEX_CU_RF_ON_RP 6
3531#define COEX_CU_RF_OFF_RP 4
3532#define COEX_CU_STAND_ALONE_DEBUG_RP 6
3533#define COEX_CU_IPAN_ASSOC_LEVEL_RP 4
3534#define COEX_CU_RSRVD1_RP 4
3535#define COEX_CU_RSRVD2_RP 4
3536
3537#define COEX_CU_UNASSOC_IDLE_WP 3
3538#define COEX_CU_UNASSOC_MANUAL_SCAN_WP 3
3539#define COEX_CU_UNASSOC_AUTO_SCAN_WP 3
3540#define COEX_CU_CALIBRATION_WP 3
3541#define COEX_CU_PERIODIC_CALIBRATION_WP 3
3542#define COEX_CU_CONNECTION_ESTAB_WP 3
3543#define COEX_CU_ASSOCIATED_IDLE_WP 3
3544#define COEX_CU_ASSOC_MANUAL_SCAN_WP 3
3545#define COEX_CU_ASSOC_AUTO_SCAN_WP 3
3546#define COEX_CU_ASSOC_ACTIVE_LEVEL_WP 3
3547#define COEX_CU_RF_ON_WP 3
3548#define COEX_CU_RF_OFF_WP 3
3549#define COEX_CU_STAND_ALONE_DEBUG_WP 6
3550#define COEX_CU_IPAN_ASSOC_LEVEL_WP 3
3551#define COEX_CU_RSRVD1_WP 3
3552#define COEX_CU_RSRVD2_WP 3
3553
3554#define COEX_UNASSOC_IDLE_FLAGS 0
3555#define COEX_UNASSOC_MANUAL_SCAN_FLAGS \
3556 (COEX_EVT_FLAG_MEDIUM_FREE_NTFY_FLG | \
3557 COEX_EVT_FLAG_MEDIUM_ACTV_NTFY_FLG)
3558#define COEX_UNASSOC_AUTO_SCAN_FLAGS \
3559 (COEX_EVT_FLAG_MEDIUM_FREE_NTFY_FLG | \
3560 COEX_EVT_FLAG_MEDIUM_ACTV_NTFY_FLG)
3561#define COEX_CALIBRATION_FLAGS \
3562 (COEX_EVT_FLAG_MEDIUM_FREE_NTFY_FLG | \
3563 COEX_EVT_FLAG_MEDIUM_ACTV_NTFY_FLG)
3564#define COEX_PERIODIC_CALIBRATION_FLAGS 0
3565/*
3566 * COEX_CONNECTION_ESTAB:
3567 * we need DELAY_MEDIUM_FREE_NTFY to let WiMAX disconnect from network.
3568 */
3569#define COEX_CONNECTION_ESTAB_FLAGS \
3570 (COEX_EVT_FLAG_MEDIUM_FREE_NTFY_FLG | \
3571 COEX_EVT_FLAG_MEDIUM_ACTV_NTFY_FLG | \
3572 COEX_EVT_FLAG_DELAY_MEDIUM_FREE_NTFY_FLG)
3573#define COEX_ASSOCIATED_IDLE_FLAGS 0
3574#define COEX_ASSOC_MANUAL_SCAN_FLAGS \
3575 (COEX_EVT_FLAG_MEDIUM_FREE_NTFY_FLG | \
3576 COEX_EVT_FLAG_MEDIUM_ACTV_NTFY_FLG)
3577#define COEX_ASSOC_AUTO_SCAN_FLAGS \
3578 (COEX_EVT_FLAG_MEDIUM_FREE_NTFY_FLG | \
3579 COEX_EVT_FLAG_MEDIUM_ACTV_NTFY_FLG)
3580#define COEX_ASSOC_ACTIVE_LEVEL_FLAGS 0
3581#define COEX_RF_ON_FLAGS 0
3582#define COEX_RF_OFF_FLAGS 0
3583#define COEX_STAND_ALONE_DEBUG_FLAGS \
3584 (COEX_EVT_FLAG_MEDIUM_FREE_NTFY_FLG | \
3585 COEX_EVT_FLAG_MEDIUM_ACTV_NTFY_FLG)
3586#define COEX_IPAN_ASSOC_LEVEL_FLAGS \
3587 (COEX_EVT_FLAG_MEDIUM_FREE_NTFY_FLG | \
3588 COEX_EVT_FLAG_MEDIUM_ACTV_NTFY_FLG | \
3589 COEX_EVT_FLAG_DELAY_MEDIUM_FREE_NTFY_FLG)
3590#define COEX_RSRVD1_FLAGS 0
3591#define COEX_RSRVD2_FLAGS 0
3592/*
3593 * COEX_CU_RF_ON is the event wrapping all radio ownership.
3594 * We need DELAY_MEDIUM_FREE_NTFY to let WiMAX disconnect from network.
3595 */
3596#define COEX_CU_RF_ON_FLAGS \
3597 (COEX_EVT_FLAG_MEDIUM_FREE_NTFY_FLG | \
3598 COEX_EVT_FLAG_MEDIUM_ACTV_NTFY_FLG | \
3599 COEX_EVT_FLAG_DELAY_MEDIUM_FREE_NTFY_FLG)
3600
3601
3510enum { 3602enum {
3603 /* un-association part */
3511 COEX_UNASSOC_IDLE = 0, 3604 COEX_UNASSOC_IDLE = 0,
3512 COEX_UNASSOC_MANUAL_SCAN = 1, 3605 COEX_UNASSOC_MANUAL_SCAN = 1,
3513 COEX_UNASSOC_AUTO_SCAN = 2, 3606 COEX_UNASSOC_AUTO_SCAN = 2,
3607 /* calibration */
3514 COEX_CALIBRATION = 3, 3608 COEX_CALIBRATION = 3,
3515 COEX_PERIODIC_CALIBRATION = 4, 3609 COEX_PERIODIC_CALIBRATION = 4,
3610 /* connection */
3516 COEX_CONNECTION_ESTAB = 5, 3611 COEX_CONNECTION_ESTAB = 5,
3612 /* association part */
3517 COEX_ASSOCIATED_IDLE = 6, 3613 COEX_ASSOCIATED_IDLE = 6,
3518 COEX_ASSOC_MANUAL_SCAN = 7, 3614 COEX_ASSOC_MANUAL_SCAN = 7,
3519 COEX_ASSOC_AUTO_SCAN = 8, 3615 COEX_ASSOC_AUTO_SCAN = 8,
3520 COEX_ASSOC_ACTIVE_LEVEL = 9, 3616 COEX_ASSOC_ACTIVE_LEVEL = 9,
3617 /* RF ON/OFF */
3521 COEX_RF_ON = 10, 3618 COEX_RF_ON = 10,
3522 COEX_RF_OFF = 11, 3619 COEX_RF_OFF = 11,
3523 COEX_STAND_ALONE_DEBUG = 12, 3620 COEX_STAND_ALONE_DEBUG = 12,
3621 /* IPAN */
3524 COEX_IPAN_ASSOC_LEVEL = 13, 3622 COEX_IPAN_ASSOC_LEVEL = 13,
3623 /* reserved */
3525 COEX_RSRVD1 = 14, 3624 COEX_RSRVD1 = 14,
3526 COEX_RSRVD2 = 15, 3625 COEX_RSRVD2 = 15,
3527 COEX_NUM_OF_EVENTS = 16 3626 COEX_NUM_OF_EVENTS = 16
3528}; 3627};
3529 3628
3629/*
3630 * Coexistence WIFI/WIMAX Command
3631 * COEX_PRIORITY_TABLE_CMD = 0x5a
3632 *
3633 */
3530struct iwl_wimax_coex_event_entry { 3634struct iwl_wimax_coex_event_entry {
3531 u8 request_prio; 3635 u8 request_prio;
3532 u8 win_medium_prio; 3636 u8 win_medium_prio;
@@ -3551,6 +3655,55 @@ struct iwl_wimax_coex_cmd {
3551 struct iwl_wimax_coex_event_entry sta_prio[COEX_NUM_OF_EVENTS]; 3655 struct iwl_wimax_coex_event_entry sta_prio[COEX_NUM_OF_EVENTS];
3552} __attribute__ ((packed)); 3656} __attribute__ ((packed));
3553 3657
3658/*
3659 * Coexistence MEDIUM NOTIFICATION
3660 * COEX_MEDIUM_NOTIFICATION = 0x5b
3661 *
3662 * notification from uCode to host to indicate medium changes
3663 *
3664 */
3665/*
3666 * status field
3667 * bit 0 - 2: medium status
3668 * bit 3: medium change indication
3669 * bit 4 - 31: reserved
3670 */
3671/* status option values, (0 - 2 bits) */
3672#define COEX_MEDIUM_BUSY (0x0) /* radio belongs to WiMAX */
3673#define COEX_MEDIUM_ACTIVE (0x1) /* radio belongs to WiFi */
3674#define COEX_MEDIUM_PRE_RELEASE (0x2) /* received radio release */
3675#define COEX_MEDIUM_MSK (0x7)
3676
3677/* send notification status (1 bit) */
3678#define COEX_MEDIUM_CHANGED (0x8)
3679#define COEX_MEDIUM_CHANGED_MSK (0x8)
3680#define COEX_MEDIUM_SHIFT (3)
3681
3682struct iwl_coex_medium_notification {
3683 __le32 status;
3684 __le32 events;
3685} __attribute__ ((packed));
3686
3687/*
3688 * Coexistence EVENT Command
3689 * COEX_EVENT_CMD = 0x5c
3690 *
3691 * send from host to uCode for coex event request.
3692 */
3693/* flags options */
3694#define COEX_EVENT_REQUEST_MSK (0x1)
3695
3696struct iwl_coex_event_cmd {
3697 u8 flags;
3698 u8 event;
3699 __le16 reserved;
3700} __attribute__ ((packed));
3701
3702struct iwl_coex_event_resp {
3703 __le32 status;
3704} __attribute__ ((packed));
3705
3706
3554/****************************************************************************** 3707/******************************************************************************
3555 * (13) 3708 * (13)
3556 * Union of all expected notifications/responses: 3709 * Union of all expected notifications/responses:
@@ -3587,6 +3740,8 @@ struct iwl_rx_packet {
3587 struct iwl_notif_statistics stats; 3740 struct iwl_notif_statistics stats;
3588 struct iwl_compressed_ba_resp compressed_ba; 3741 struct iwl_compressed_ba_resp compressed_ba;
3589 struct iwl_missed_beacon_notif missed_beacon; 3742 struct iwl_missed_beacon_notif missed_beacon;
3743 struct iwl_coex_medium_notification coex_medium_notif;
3744 struct iwl_coex_event_resp coex_event;
3590 __le32 status; 3745 __le32 status;
3591 u8 raw[0]; 3746 u8 raw[0];
3592 } u; 3747 } u;
diff --git a/drivers/net/wireless/iwlwifi/iwl-core.c b/drivers/net/wireless/iwlwifi/iwl-core.c
index d2b56baf98fb..e0b5b4aef41d 100644
--- a/drivers/net/wireless/iwlwifi/iwl-core.c
+++ b/drivers/net/wireless/iwlwifi/iwl-core.c
@@ -46,6 +46,37 @@ MODULE_VERSION(IWLWIFI_VERSION);
46MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR); 46MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
47MODULE_LICENSE("GPL"); 47MODULE_LICENSE("GPL");
48 48
49static struct iwl_wimax_coex_event_entry cu_priorities[COEX_NUM_OF_EVENTS] = {
50 {COEX_CU_UNASSOC_IDLE_RP, COEX_CU_UNASSOC_IDLE_WP,
51 0, COEX_UNASSOC_IDLE_FLAGS},
52 {COEX_CU_UNASSOC_MANUAL_SCAN_RP, COEX_CU_UNASSOC_MANUAL_SCAN_WP,
53 0, COEX_UNASSOC_MANUAL_SCAN_FLAGS},
54 {COEX_CU_UNASSOC_AUTO_SCAN_RP, COEX_CU_UNASSOC_AUTO_SCAN_WP,
55 0, COEX_UNASSOC_AUTO_SCAN_FLAGS},
56 {COEX_CU_CALIBRATION_RP, COEX_CU_CALIBRATION_WP,
57 0, COEX_CALIBRATION_FLAGS},
58 {COEX_CU_PERIODIC_CALIBRATION_RP, COEX_CU_PERIODIC_CALIBRATION_WP,
59 0, COEX_PERIODIC_CALIBRATION_FLAGS},
60 {COEX_CU_CONNECTION_ESTAB_RP, COEX_CU_CONNECTION_ESTAB_WP,
61 0, COEX_CONNECTION_ESTAB_FLAGS},
62 {COEX_CU_ASSOCIATED_IDLE_RP, COEX_CU_ASSOCIATED_IDLE_WP,
63 0, COEX_ASSOCIATED_IDLE_FLAGS},
64 {COEX_CU_ASSOC_MANUAL_SCAN_RP, COEX_CU_ASSOC_MANUAL_SCAN_WP,
65 0, COEX_ASSOC_MANUAL_SCAN_FLAGS},
66 {COEX_CU_ASSOC_AUTO_SCAN_RP, COEX_CU_ASSOC_AUTO_SCAN_WP,
67 0, COEX_ASSOC_AUTO_SCAN_FLAGS},
68 {COEX_CU_ASSOC_ACTIVE_LEVEL_RP, COEX_CU_ASSOC_ACTIVE_LEVEL_WP,
69 0, COEX_ASSOC_ACTIVE_LEVEL_FLAGS},
70 {COEX_CU_RF_ON_RP, COEX_CU_RF_ON_WP, 0, COEX_CU_RF_ON_FLAGS},
71 {COEX_CU_RF_OFF_RP, COEX_CU_RF_OFF_WP, 0, COEX_RF_OFF_FLAGS},
72 {COEX_CU_STAND_ALONE_DEBUG_RP, COEX_CU_STAND_ALONE_DEBUG_WP,
73 0, COEX_STAND_ALONE_DEBUG_FLAGS},
74 {COEX_CU_IPAN_ASSOC_LEVEL_RP, COEX_CU_IPAN_ASSOC_LEVEL_WP,
75 0, COEX_IPAN_ASSOC_LEVEL_FLAGS},
76 {COEX_CU_RSRVD1_RP, COEX_CU_RSRVD1_WP, 0, COEX_RSRVD1_FLAGS},
77 {COEX_CU_RSRVD2_RP, COEX_CU_RSRVD2_WP, 0, COEX_RSRVD2_FLAGS}
78};
79
49#define IWL_DECLARE_RATE_INFO(r, s, ip, in, rp, rn, pp, np) \ 80#define IWL_DECLARE_RATE_INFO(r, s, ip, in, rp, rn, pp, np) \
50 [IWL_RATE_##r##M_INDEX] = { IWL_RATE_##r##M_PLCP, \ 81 [IWL_RATE_##r##M_INDEX] = { IWL_RATE_##r##M_PLCP, \
51 IWL_RATE_SISO_##s##M_PLCP, \ 82 IWL_RATE_SISO_##s##M_PLCP, \
@@ -414,8 +445,12 @@ static void iwlcore_init_ht_hw_capab(const struct iwl_priv *priv,
414 if (priv->cfg->ht_greenfield_support) 445 if (priv->cfg->ht_greenfield_support)
415 ht_info->cap |= IEEE80211_HT_CAP_GRN_FLD; 446 ht_info->cap |= IEEE80211_HT_CAP_GRN_FLD;
416 ht_info->cap |= IEEE80211_HT_CAP_SGI_20; 447 ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
417 ht_info->cap |= (IEEE80211_HT_CAP_SM_PS & 448 if (priv->cfg->support_sm_ps)
418 (WLAN_HT_CAP_SM_PS_DISABLED << 2)); 449 ht_info->cap |= (IEEE80211_HT_CAP_SM_PS &
450 (WLAN_HT_CAP_SM_PS_DYNAMIC << 2));
451 else
452 ht_info->cap |= (IEEE80211_HT_CAP_SM_PS &
453 (WLAN_HT_CAP_SM_PS_DISABLED << 2));
419 454
420 max_bit_rate = MAX_BIT_RATE_20_MHZ; 455 max_bit_rate = MAX_BIT_RATE_20_MHZ;
421 if (priv->hw_params.ht40_channel & BIT(band)) { 456 if (priv->hw_params.ht40_channel & BIT(band)) {
@@ -451,28 +486,6 @@ static void iwlcore_init_ht_hw_capab(const struct iwl_priv *priv,
451 } 486 }
452} 487}
453 488
454static void iwlcore_init_hw_rates(struct iwl_priv *priv,
455 struct ieee80211_rate *rates)
456{
457 int i;
458
459 for (i = 0; i < IWL_RATE_COUNT_LEGACY; i++) {
460 rates[i].bitrate = iwl_rates[i].ieee * 5;
461 rates[i].hw_value = i; /* Rate scaling will work on indexes */
462 rates[i].hw_value_short = i;
463 rates[i].flags = 0;
464 if ((i >= IWL_FIRST_CCK_RATE) && (i <= IWL_LAST_CCK_RATE)) {
465 /*
466 * If CCK != 1M then set short preamble rate flag.
467 */
468 rates[i].flags |=
469 (iwl_rates[i].plcp == IWL_RATE_1M_PLCP) ?
470 0 : IEEE80211_RATE_SHORT_PREAMBLE;
471 }
472 }
473}
474
475
476/** 489/**
477 * iwlcore_init_geos - Initialize mac80211's geo/channel info based from eeprom 490 * iwlcore_init_geos - Initialize mac80211's geo/channel info based from eeprom
478 */ 491 */
@@ -985,17 +998,35 @@ static int iwl_get_active_rx_chain_count(struct iwl_priv *priv)
985} 998}
986 999
987/* 1000/*
988 * When we are in power saving, there's no difference between 1001 * When we are in power saving mode, unless device support spatial
989 * using multiple chains or just a single chain, but due to the 1002 * multiplexing power save, use the active count for rx chain count.
990 * lack of SM PS we lose a lot of throughput if we use just a
991 * single chain.
992 *
993 * Therefore, use the active count here (which will use multiple
994 * chains unless connected to a legacy AP).
995 */ 1003 */
996static int iwl_get_idle_rx_chain_count(struct iwl_priv *priv, int active_cnt) 1004static int iwl_get_idle_rx_chain_count(struct iwl_priv *priv, int active_cnt)
997{ 1005{
998 return active_cnt; 1006 int idle_cnt = active_cnt;
1007 bool is_cam = !test_bit(STATUS_POWER_PMI, &priv->status);
1008
1009 if (priv->cfg->support_sm_ps) {
1010 /* # Rx chains when idling and maybe trying to save power */
1011 switch (priv->current_ht_config.sm_ps) {
1012 case WLAN_HT_CAP_SM_PS_STATIC:
1013 case WLAN_HT_CAP_SM_PS_DYNAMIC:
1014 idle_cnt = (is_cam) ? IWL_NUM_IDLE_CHAINS_DUAL :
1015 IWL_NUM_IDLE_CHAINS_SINGLE;
1016 break;
1017 case WLAN_HT_CAP_SM_PS_DISABLED:
1018 idle_cnt = (is_cam) ? active_cnt :
1019 IWL_NUM_IDLE_CHAINS_SINGLE;
1020 break;
1021 case WLAN_HT_CAP_SM_PS_INVALID:
1022 default:
1023 IWL_ERR(priv, "invalid sm_ps mode %d\n",
1024 priv->current_ht_config.sm_ps);
1025 WARN_ON(1);
1026 break;
1027 }
1028 }
1029 return idle_cnt;
999} 1030}
1000 1031
1001/* up to 4 chains */ 1032/* up to 4 chains */
@@ -1353,39 +1384,39 @@ EXPORT_SYMBOL(iwl_irq_handle_error);
1353 1384
1354int iwl_apm_stop_master(struct iwl_priv *priv) 1385int iwl_apm_stop_master(struct iwl_priv *priv)
1355{ 1386{
1356 unsigned long flags; 1387 int ret = 0;
1357
1358 spin_lock_irqsave(&priv->lock, flags);
1359 1388
1360 /* set stop master bit */ 1389 /* stop device's busmaster DMA activity */
1361 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER); 1390 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER);
1362 1391
1363 iwl_poll_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_MASTER_DISABLED, 1392 ret = iwl_poll_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_MASTER_DISABLED,
1364 CSR_RESET_REG_FLAG_MASTER_DISABLED, 100); 1393 CSR_RESET_REG_FLAG_MASTER_DISABLED, 100);
1394 if (ret)
1395 IWL_WARN(priv, "Master Disable Timed Out, 100 usec\n");
1365 1396
1366 spin_unlock_irqrestore(&priv->lock, flags);
1367 IWL_DEBUG_INFO(priv, "stop master\n"); 1397 IWL_DEBUG_INFO(priv, "stop master\n");
1368 1398
1369 return 0; 1399 return ret;
1370} 1400}
1371EXPORT_SYMBOL(iwl_apm_stop_master); 1401EXPORT_SYMBOL(iwl_apm_stop_master);
1372 1402
1373void iwl_apm_stop(struct iwl_priv *priv) 1403void iwl_apm_stop(struct iwl_priv *priv)
1374{ 1404{
1375 unsigned long flags;
1376
1377 IWL_DEBUG_INFO(priv, "Stop card, put in low power state\n"); 1405 IWL_DEBUG_INFO(priv, "Stop card, put in low power state\n");
1378 1406
1407 /* Stop device's DMA activity */
1379 iwl_apm_stop_master(priv); 1408 iwl_apm_stop_master(priv);
1380 1409
1381 spin_lock_irqsave(&priv->lock, flags); 1410 /* Reset the entire device */
1382
1383 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET); 1411 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
1384 1412
1385 udelay(10); 1413 udelay(10);
1386 /* clear "init complete" move adapter D0A* --> D0U state */ 1414
1415 /*
1416 * Clear "initialization complete" bit to move adapter from
1417 * D0A* (powered-up Active) --> D0U* (Uninitialized) state.
1418 */
1387 iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE); 1419 iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
1388 spin_unlock_irqrestore(&priv->lock, flags);
1389} 1420}
1390EXPORT_SYMBOL(iwl_apm_stop); 1421EXPORT_SYMBOL(iwl_apm_stop);
1391 1422
@@ -1430,8 +1461,12 @@ int iwl_apm_init(struct iwl_priv *priv)
1430 CSR_HW_IF_CONFIG_REG_BIT_HAP_WAKE_L1A); 1461 CSR_HW_IF_CONFIG_REG_BIT_HAP_WAKE_L1A);
1431 1462
1432 /* 1463 /*
1433 * HW bug W/A - costs negligible power consumption ... 1464 * HW bug W/A for instability in PCIe bus L0->L0S->L1 transition.
1434 * Check if BIOS (or OS) enabled L1-ASPM on this device 1465 * Check if BIOS (or OS) enabled L1-ASPM on this device.
1466 * If so (likely), disable L0S, so device moves directly L0->L1;
1467 * costs negligible amount of power savings.
1468 * If not (unlikely), enable L0S, so there is at least some
1469 * power savings, even without L1.
1435 */ 1470 */
1436 if (priv->cfg->set_l0s) { 1471 if (priv->cfg->set_l0s) {
1437 lctl = iwl_pcie_link_ctl(priv); 1472 lctl = iwl_pcie_link_ctl(priv);
@@ -1567,68 +1602,6 @@ int iwl_set_hw_params(struct iwl_priv *priv)
1567} 1602}
1568EXPORT_SYMBOL(iwl_set_hw_params); 1603EXPORT_SYMBOL(iwl_set_hw_params);
1569 1604
1570int iwl_init_drv(struct iwl_priv *priv)
1571{
1572 int ret;
1573
1574 priv->ibss_beacon = NULL;
1575
1576 spin_lock_init(&priv->lock);
1577 spin_lock_init(&priv->sta_lock);
1578 spin_lock_init(&priv->hcmd_lock);
1579
1580 INIT_LIST_HEAD(&priv->free_frames);
1581
1582 mutex_init(&priv->mutex);
1583
1584 /* Clear the driver's (not device's) station table */
1585 iwl_clear_stations_table(priv);
1586
1587 priv->ieee_channels = NULL;
1588 priv->ieee_rates = NULL;
1589 priv->band = IEEE80211_BAND_2GHZ;
1590
1591 priv->iw_mode = NL80211_IFTYPE_STATION;
1592
1593 /* Choose which receivers/antennas to use */
1594 if (priv->cfg->ops->hcmd->set_rxon_chain)
1595 priv->cfg->ops->hcmd->set_rxon_chain(priv);
1596
1597 iwl_init_scan_params(priv);
1598
1599 iwl_reset_qos(priv);
1600
1601 priv->qos_data.qos_active = 0;
1602 priv->qos_data.qos_cap.val = 0;
1603
1604 priv->rates_mask = IWL_RATES_MASK;
1605 /* Set the tx_power_user_lmt to the lowest power level
1606 * this value will get overwritten by channel max power avg
1607 * from eeprom */
1608 priv->tx_power_user_lmt = IWL_TX_POWER_TARGET_POWER_MIN;
1609
1610 ret = iwl_init_channel_map(priv);
1611 if (ret) {
1612 IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
1613 goto err;
1614 }
1615
1616 ret = iwlcore_init_geos(priv);
1617 if (ret) {
1618 IWL_ERR(priv, "initializing geos failed: %d\n", ret);
1619 goto err_free_channel_map;
1620 }
1621 iwlcore_init_hw_rates(priv, priv->ieee_rates);
1622
1623 return 0;
1624
1625err_free_channel_map:
1626 iwl_free_channel_map(priv);
1627err:
1628 return ret;
1629}
1630EXPORT_SYMBOL(iwl_init_drv);
1631
1632int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force) 1605int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force)
1633{ 1606{
1634 int ret = 0; 1607 int ret = 0;
@@ -1676,15 +1649,6 @@ int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force)
1676} 1649}
1677EXPORT_SYMBOL(iwl_set_tx_power); 1650EXPORT_SYMBOL(iwl_set_tx_power);
1678 1651
1679void iwl_uninit_drv(struct iwl_priv *priv)
1680{
1681 iwl_calib_free_results(priv);
1682 iwlcore_free_geos(priv);
1683 iwl_free_channel_map(priv);
1684 kfree(priv->scan);
1685}
1686EXPORT_SYMBOL(iwl_uninit_drv);
1687
1688#define ICT_COUNT (PAGE_SIZE/sizeof(u32)) 1652#define ICT_COUNT (PAGE_SIZE/sizeof(u32))
1689 1653
1690/* Free dram table */ 1654/* Free dram table */
@@ -2336,7 +2300,7 @@ static void iwl_ht_conf(struct iwl_priv *priv,
2336 switch (priv->iw_mode) { 2300 switch (priv->iw_mode) {
2337 case NL80211_IFTYPE_STATION: 2301 case NL80211_IFTYPE_STATION:
2338 rcu_read_lock(); 2302 rcu_read_lock();
2339 sta = ieee80211_find_sta(priv->hw, priv->bssid); 2303 sta = ieee80211_find_sta(priv->vif, priv->bssid);
2340 if (sta) { 2304 if (sta) {
2341 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap; 2305 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
2342 int maxstreams; 2306 int maxstreams;
@@ -2346,6 +2310,12 @@ static void iwl_ht_conf(struct iwl_priv *priv,
2346 >> IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT; 2310 >> IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
2347 maxstreams += 1; 2311 maxstreams += 1;
2348 2312
2313 ht_conf->sm_ps =
2314 (u8)((ht_cap->cap & IEEE80211_HT_CAP_SM_PS)
2315 >> 2);
2316 IWL_DEBUG_MAC80211(priv, "sm_ps: 0x%x\n",
2317 ht_conf->sm_ps);
2318
2349 if ((ht_cap->mcs.rx_mask[1] == 0) && 2319 if ((ht_cap->mcs.rx_mask[1] == 0) &&
2350 (ht_cap->mcs.rx_mask[2] == 0)) 2320 (ht_cap->mcs.rx_mask[2] == 0))
2351 ht_conf->single_chain_sufficient = true; 2321 ht_conf->single_chain_sufficient = true;
@@ -2926,6 +2896,34 @@ void iwl_free_txq_mem(struct iwl_priv *priv)
2926} 2896}
2927EXPORT_SYMBOL(iwl_free_txq_mem); 2897EXPORT_SYMBOL(iwl_free_txq_mem);
2928 2898
2899int iwl_send_wimax_coex(struct iwl_priv *priv)
2900{
2901 struct iwl_wimax_coex_cmd uninitialized_var(coex_cmd);
2902
2903 if (priv->cfg->support_wimax_coexist) {
2904 /* UnMask wake up src at associated sleep */
2905 coex_cmd.flags |= COEX_FLAGS_ASSOC_WA_UNMASK_MSK;
2906
2907 /* UnMask wake up src at unassociated sleep */
2908 coex_cmd.flags |= COEX_FLAGS_UNASSOC_WA_UNMASK_MSK;
2909 memcpy(coex_cmd.sta_prio, cu_priorities,
2910 sizeof(struct iwl_wimax_coex_event_entry) *
2911 COEX_NUM_OF_EVENTS);
2912
2913 /* enabling the coexistence feature */
2914 coex_cmd.flags |= COEX_FLAGS_COEX_ENABLE_MSK;
2915
2916 /* enabling the priorities tables */
2917 coex_cmd.flags |= COEX_FLAGS_STA_TABLE_VALID_MSK;
2918 } else {
2919 /* coexistence is disabled */
2920 memset(&coex_cmd, 0, sizeof(coex_cmd));
2921 }
2922 return iwl_send_cmd_pdu(priv, COEX_PRIORITY_TABLE_CMD,
2923 sizeof(coex_cmd), &coex_cmd);
2924}
2925EXPORT_SYMBOL(iwl_send_wimax_coex);
2926
2929#ifdef CONFIG_IWLWIFI_DEBUGFS 2927#ifdef CONFIG_IWLWIFI_DEBUGFS
2930 2928
2931#define IWL_TRAFFIC_DUMP_SIZE (IWL_TRAFFIC_ENTRY_SIZE * IWL_TRAFFIC_ENTRIES) 2929#define IWL_TRAFFIC_DUMP_SIZE (IWL_TRAFFIC_ENTRY_SIZE * IWL_TRAFFIC_ENTRIES)
diff --git a/drivers/net/wireless/iwlwifi/iwl-core.h b/drivers/net/wireless/iwlwifi/iwl-core.h
index b875dcfca2d6..9574d8f33537 100644
--- a/drivers/net/wireless/iwlwifi/iwl-core.h
+++ b/drivers/net/wireless/iwlwifi/iwl-core.h
@@ -228,6 +228,8 @@ struct iwl_mod_params {
228 * @chain_noise_num_beacons: number of beacons used to compute chain noise 228 * @chain_noise_num_beacons: number of beacons used to compute chain noise
229 * @adv_thermal_throttle: support advance thermal throttle 229 * @adv_thermal_throttle: support advance thermal throttle
230 * @support_ct_kill_exit: support ct kill exit condition 230 * @support_ct_kill_exit: support ct kill exit condition
231 * @support_sm_ps: support spatial multiplexing power save
232 * @support_wimax_coexist: support wimax/wifi co-exist
231 * 233 *
232 * We enable the driver to be backward compatible wrt API version. The 234 * We enable the driver to be backward compatible wrt API version. The
233 * driver specifies which APIs it supports (with @ucode_api_max being the 235 * driver specifies which APIs it supports (with @ucode_api_max being the
@@ -283,6 +285,8 @@ struct iwl_cfg {
283 const bool supports_idle; 285 const bool supports_idle;
284 bool adv_thermal_throttle; 286 bool adv_thermal_throttle;
285 bool support_ct_kill_exit; 287 bool support_ct_kill_exit;
288 bool support_sm_ps;
289 const bool support_wimax_coexist;
286}; 290};
287 291
288/*************************** 292/***************************
@@ -316,8 +320,6 @@ void iwl_configure_filter(struct ieee80211_hw *hw,
316 unsigned int *total_flags, u64 multicast); 320 unsigned int *total_flags, u64 multicast);
317int iwl_hw_nic_init(struct iwl_priv *priv); 321int iwl_hw_nic_init(struct iwl_priv *priv);
318int iwl_set_hw_params(struct iwl_priv *priv); 322int iwl_set_hw_params(struct iwl_priv *priv);
319int iwl_init_drv(struct iwl_priv *priv);
320void iwl_uninit_drv(struct iwl_priv *priv);
321bool iwl_is_monitor_mode(struct iwl_priv *priv); 323bool iwl_is_monitor_mode(struct iwl_priv *priv);
322void iwl_post_associate(struct iwl_priv *priv); 324void iwl_post_associate(struct iwl_priv *priv);
323void iwl_bss_info_changed(struct ieee80211_hw *hw, 325void iwl_bss_info_changed(struct ieee80211_hw *hw,
@@ -340,6 +342,7 @@ int iwl_alloc_txq_mem(struct iwl_priv *priv);
340void iwl_free_txq_mem(struct iwl_priv *priv); 342void iwl_free_txq_mem(struct iwl_priv *priv);
341void iwlcore_rts_tx_cmd_flag(struct ieee80211_tx_info *info, 343void iwlcore_rts_tx_cmd_flag(struct ieee80211_tx_info *info,
342 __le32 *tx_flags); 344 __le32 *tx_flags);
345int iwl_send_wimax_coex(struct iwl_priv *priv);
343#ifdef CONFIG_IWLWIFI_DEBUGFS 346#ifdef CONFIG_IWLWIFI_DEBUGFS
344int iwl_alloc_traffic_mem(struct iwl_priv *priv); 347int iwl_alloc_traffic_mem(struct iwl_priv *priv);
345void iwl_free_traffic_mem(struct iwl_priv *priv); 348void iwl_free_traffic_mem(struct iwl_priv *priv);
diff --git a/drivers/net/wireless/iwlwifi/iwl-dev.h b/drivers/net/wireless/iwlwifi/iwl-dev.h
index e7ce67387662..cb2642c18da4 100644
--- a/drivers/net/wireless/iwlwifi/iwl-dev.h
+++ b/drivers/net/wireless/iwlwifi/iwl-dev.h
@@ -517,6 +517,7 @@ struct iwl_ht_config {
517 bool is_ht; 517 bool is_ht;
518 bool is_40mhz; 518 bool is_40mhz;
519 bool single_chain_sufficient; 519 bool single_chain_sufficient;
520 u8 sm_ps;
520 /* BSS related data */ 521 /* BSS related data */
521 u8 extension_chan_offset; 522 u8 extension_chan_offset;
522 u8 ht_protection; 523 u8 ht_protection;
diff --git a/drivers/net/wireless/iwlwifi/iwl-eeprom.c b/drivers/net/wireless/iwlwifi/iwl-eeprom.c
index 9429cb1c69bd..8a0709e81a9f 100644
--- a/drivers/net/wireless/iwlwifi/iwl-eeprom.c
+++ b/drivers/net/wireless/iwlwifi/iwl-eeprom.c
@@ -533,6 +533,10 @@ int iwl_eeprom_init(struct iwl_priv *priv)
533 goto err; 533 goto err;
534 } 534 }
535 if (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP) { 535 if (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP) {
536
537 /* OTP reads require powered-up chip */
538 priv->cfg->ops->lib->apm_ops.init(priv);
539
536 ret = iwl_init_otp_access(priv); 540 ret = iwl_init_otp_access(priv);
537 if (ret) { 541 if (ret) {
538 IWL_ERR(priv, "Failed to initialize OTP access.\n"); 542 IWL_ERR(priv, "Failed to initialize OTP access.\n");
@@ -563,6 +567,13 @@ int iwl_eeprom_init(struct iwl_priv *priv)
563 e[cache_addr / 2] = eeprom_data; 567 e[cache_addr / 2] = eeprom_data;
564 cache_addr += sizeof(u16); 568 cache_addr += sizeof(u16);
565 } 569 }
570
571 /*
572 * Now that OTP reads are complete, reset chip to save
573 * power until we load uCode during "up".
574 */
575 priv->cfg->ops->lib->apm_ops.stop(priv);
576
566 } else { 577 } else {
567 /* eeprom is an array of 16bit values */ 578 /* eeprom is an array of 16bit values */
568 for (addr = 0; addr < sz; addr += sizeof(u16)) { 579 for (addr = 0; addr < sz; addr += sizeof(u16)) {
diff --git a/drivers/net/wireless/iwlwifi/iwl-hcmd.c b/drivers/net/wireless/iwlwifi/iwl-hcmd.c
index f2a60dc4109f..905645d15a9b 100644
--- a/drivers/net/wireless/iwlwifi/iwl-hcmd.c
+++ b/drivers/net/wireless/iwlwifi/iwl-hcmd.c
@@ -55,6 +55,8 @@ const char *get_cmd_string(u8 cmd)
55 IWL_CMD(REPLY_LEDS_CMD); 55 IWL_CMD(REPLY_LEDS_CMD);
56 IWL_CMD(REPLY_TX_LINK_QUALITY_CMD); 56 IWL_CMD(REPLY_TX_LINK_QUALITY_CMD);
57 IWL_CMD(COEX_PRIORITY_TABLE_CMD); 57 IWL_CMD(COEX_PRIORITY_TABLE_CMD);
58 IWL_CMD(COEX_MEDIUM_NOTIFICATION);
59 IWL_CMD(COEX_EVENT_CMD);
58 IWL_CMD(RADAR_NOTIFICATION); 60 IWL_CMD(RADAR_NOTIFICATION);
59 IWL_CMD(REPLY_QUIET_CMD); 61 IWL_CMD(REPLY_QUIET_CMD);
60 IWL_CMD(REPLY_CHANNEL_SWITCH); 62 IWL_CMD(REPLY_CHANNEL_SWITCH);
diff --git a/drivers/net/wireless/iwlwifi/iwl-scan.c b/drivers/net/wireless/iwlwifi/iwl-scan.c
index 4fca65a2fe9c..1eb0d0bf1fe4 100644
--- a/drivers/net/wireless/iwlwifi/iwl-scan.c
+++ b/drivers/net/wireless/iwlwifi/iwl-scan.c
@@ -401,6 +401,7 @@ void iwl_init_scan_params(struct iwl_priv *priv)
401 if (!priv->scan_tx_ant[IEEE80211_BAND_2GHZ]) 401 if (!priv->scan_tx_ant[IEEE80211_BAND_2GHZ])
402 priv->scan_tx_ant[IEEE80211_BAND_2GHZ] = ant_idx; 402 priv->scan_tx_ant[IEEE80211_BAND_2GHZ] = ant_idx;
403} 403}
404EXPORT_SYMBOL(iwl_init_scan_params);
404 405
405static int iwl_scan_initiate(struct iwl_priv *priv) 406static int iwl_scan_initiate(struct iwl_priv *priv)
406{ 407{
diff --git a/drivers/net/wireless/iwlwifi/iwl-sta.c b/drivers/net/wireless/iwlwifi/iwl-sta.c
index dc74c16d36a8..eba36f737388 100644
--- a/drivers/net/wireless/iwlwifi/iwl-sta.c
+++ b/drivers/net/wireless/iwlwifi/iwl-sta.c
@@ -182,6 +182,11 @@ static void iwl_set_ht_add_station(struct iwl_priv *priv, u8 index,
182 goto done; 182 goto done;
183 183
184 mimo_ps_mode = (sta_ht_inf->cap & IEEE80211_HT_CAP_SM_PS) >> 2; 184 mimo_ps_mode = (sta_ht_inf->cap & IEEE80211_HT_CAP_SM_PS) >> 2;
185 IWL_DEBUG_ASSOC(priv, "spatial multiplexing power save mode: %s\n",
186 (mimo_ps_mode == WLAN_HT_CAP_SM_PS_STATIC) ?
187 "static" :
188 (mimo_ps_mode == WLAN_HT_CAP_SM_PS_DYNAMIC) ?
189 "dynamic" : "disabled");
185 190
186 sta_flags = priv->stations[index].sta.station_flags; 191 sta_flags = priv->stations[index].sta.station_flags;
187 192
@@ -1012,7 +1017,7 @@ int iwl_rxon_add_station(struct iwl_priv *priv, const u8 *addr, bool is_ap)
1012 */ 1017 */
1013 if (priv->current_ht_config.is_ht) { 1018 if (priv->current_ht_config.is_ht) {
1014 rcu_read_lock(); 1019 rcu_read_lock();
1015 sta = ieee80211_find_sta(priv->hw, addr); 1020 sta = ieee80211_find_sta(priv->vif, addr);
1016 if (sta) { 1021 if (sta) {
1017 memcpy(&ht_config, &sta->ht_cap, sizeof(ht_config)); 1022 memcpy(&ht_config, &sta->ht_cap, sizeof(ht_config));
1018 cur_ht_config = &ht_config; 1023 cur_ht_config = &ht_config;
@@ -1030,6 +1035,68 @@ int iwl_rxon_add_station(struct iwl_priv *priv, const u8 *addr, bool is_ap)
1030EXPORT_SYMBOL(iwl_rxon_add_station); 1035EXPORT_SYMBOL(iwl_rxon_add_station);
1031 1036
1032/** 1037/**
1038 * iwl_sta_init_bcast_lq - Initialize a bcast station's hardware rate table
1039 *
1040 * NOTE: Run REPLY_ADD_STA command to set up station table entry, before
1041 * calling this function (which runs REPLY_TX_LINK_QUALITY_CMD,
1042 * which requires station table entry to exist).
1043 */
1044static void iwl_sta_init_bcast_lq(struct iwl_priv *priv)
1045{
1046 int i, r;
1047 struct iwl_link_quality_cmd link_cmd = {
1048 .reserved1 = 0,
1049 };
1050 u32 rate_flags;
1051
1052 /* Set up the rate scaling to start at selected rate, fall back
1053 * all the way down to 1M in IEEE order, and then spin on 1M */
1054 if (priv->band == IEEE80211_BAND_5GHZ)
1055 r = IWL_RATE_6M_INDEX;
1056 else
1057 r = IWL_RATE_1M_INDEX;
1058
1059 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
1060 rate_flags = 0;
1061 if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE)
1062 rate_flags |= RATE_MCS_CCK_MSK;
1063
1064 rate_flags |= first_antenna(priv->hw_params.valid_tx_ant) <<
1065 RATE_MCS_ANT_POS;
1066
1067 link_cmd.rs_table[i].rate_n_flags =
1068 iwl_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags);
1069 r = iwl_get_prev_ieee_rate(r);
1070 }
1071
1072 link_cmd.general_params.single_stream_ant_msk =
1073 first_antenna(priv->hw_params.valid_tx_ant);
1074 link_cmd.general_params.dual_stream_ant_msk = 3;
1075 link_cmd.agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF;
1076 link_cmd.agg_params.agg_time_limit =
1077 cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF);
1078
1079 /* Update the rate scaling for control frame Tx to AP */
1080 link_cmd.sta_id = priv->hw_params.bcast_sta_id;
1081
1082 iwl_send_cmd_pdu_async(priv, REPLY_TX_LINK_QUALITY_CMD,
1083 sizeof(link_cmd), &link_cmd, NULL);
1084}
1085
1086
1087/**
1088 * iwl_add_bcast_station - add broadcast station into station table.
1089 */
1090void iwl_add_bcast_station(struct iwl_priv *priv)
1091{
1092 iwl_add_station(priv, iwl_bcast_addr, false, CMD_SYNC, NULL);
1093
1094 /* Set up default rate scaling table in device's station table */
1095 iwl_sta_init_bcast_lq(priv);
1096}
1097EXPORT_SYMBOL(iwl_add_bcast_station);
1098
1099/**
1033 * iwl_get_sta_id - Find station's index within station table 1100 * iwl_get_sta_id - Find station's index within station table
1034 * 1101 *
1035 * If new IBSS station, create new entry in station table 1102 * If new IBSS station, create new entry in station table
diff --git a/drivers/net/wireless/iwlwifi/iwl-sta.h b/drivers/net/wireless/iwlwifi/iwl-sta.h
index 6deebade6361..1c382de80d49 100644
--- a/drivers/net/wireless/iwlwifi/iwl-sta.h
+++ b/drivers/net/wireless/iwlwifi/iwl-sta.h
@@ -52,6 +52,7 @@ void iwl_update_tkip_key(struct iwl_priv *priv,
52 const u8 *addr, u32 iv32, u16 *phase1key); 52 const u8 *addr, u32 iv32, u16 *phase1key);
53 53
54int iwl_rxon_add_station(struct iwl_priv *priv, const u8 *addr, bool is_ap); 54int iwl_rxon_add_station(struct iwl_priv *priv, const u8 *addr, bool is_ap);
55void iwl_add_bcast_station(struct iwl_priv *priv);
55int iwl_remove_station(struct iwl_priv *priv, const u8 *addr, bool is_ap); 56int iwl_remove_station(struct iwl_priv *priv, const u8 *addr, bool is_ap);
56void iwl_clear_stations_table(struct iwl_priv *priv); 57void iwl_clear_stations_table(struct iwl_priv *priv);
57int iwl_get_free_ucode_key_index(struct iwl_priv *priv); 58int iwl_get_free_ucode_key_index(struct iwl_priv *priv);
diff --git a/drivers/net/wireless/iwlwifi/iwl-tx.c b/drivers/net/wireless/iwlwifi/iwl-tx.c
index 8ae4c9b614e7..05e75109d842 100644
--- a/drivers/net/wireless/iwlwifi/iwl-tx.c
+++ b/drivers/net/wireless/iwlwifi/iwl-tx.c
@@ -979,7 +979,8 @@ int iwl_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd)
979 !(cmd->flags & CMD_SIZE_HUGE)); 979 !(cmd->flags & CMD_SIZE_HUGE));
980 980
981 if (iwl_is_rfkill(priv) || iwl_is_ctkill(priv)) { 981 if (iwl_is_rfkill(priv) || iwl_is_ctkill(priv)) {
982 IWL_DEBUG_INFO(priv, "Not sending command - RF/CT KILL\n"); 982 IWL_WARN(priv, "Not sending command - %s KILL\n",
983 iwl_is_rfkill(priv) ? "RF" : "CT");
983 return -EIO; 984 return -EIO;
984 } 985 }
985 986
@@ -1121,11 +1122,6 @@ static void iwl_hcmd_queue_reclaim(struct iwl_priv *priv, int txq_id,
1121 return; 1122 return;
1122 } 1123 }
1123 1124
1124 pci_unmap_single(priv->pci_dev,
1125 pci_unmap_addr(&txq->meta[cmd_idx], mapping),
1126 pci_unmap_len(&txq->meta[cmd_idx], len),
1127 PCI_DMA_BIDIRECTIONAL);
1128
1129 for (idx = iwl_queue_inc_wrap(idx, q->n_bd); q->read_ptr != idx; 1125 for (idx = iwl_queue_inc_wrap(idx, q->n_bd); q->read_ptr != idx;
1130 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) { 1126 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
1131 1127
@@ -1173,6 +1169,11 @@ void iwl_tx_cmd_complete(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
1173 cmd = priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index]; 1169 cmd = priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index];
1174 meta = &priv->txq[IWL_CMD_QUEUE_NUM].meta[cmd_index]; 1170 meta = &priv->txq[IWL_CMD_QUEUE_NUM].meta[cmd_index];
1175 1171
1172 pci_unmap_single(priv->pci_dev,
1173 pci_unmap_addr(meta, mapping),
1174 pci_unmap_len(meta, len),
1175 PCI_DMA_BIDIRECTIONAL);
1176
1176 /* Input error checking is done when commands are added to queue. */ 1177 /* Input error checking is done when commands are added to queue. */
1177 if (meta->flags & CMD_WANT_SKB) { 1178 if (meta->flags & CMD_WANT_SKB) {
1178 meta->source->reply_page = (unsigned long)rxb_addr(rxb); 1179 meta->source->reply_page = (unsigned long)rxb_addr(rxb);
diff --git a/drivers/net/wireless/iwlwifi/iwl3945-base.c b/drivers/net/wireless/iwlwifi/iwl3945-base.c
index bfd7f497157f..23b31e6dcacd 100644
--- a/drivers/net/wireless/iwlwifi/iwl3945-base.c
+++ b/drivers/net/wireless/iwlwifi/iwl3945-base.c
@@ -2160,6 +2160,14 @@ static int iwl3945_read_ucode(struct iwl_priv *priv)
2160 IWL_UCODE_API(priv->ucode_ver), 2160 IWL_UCODE_API(priv->ucode_ver),
2161 IWL_UCODE_SERIAL(priv->ucode_ver)); 2161 IWL_UCODE_SERIAL(priv->ucode_ver));
2162 2162
2163 snprintf(priv->hw->wiphy->fw_version,
2164 sizeof(priv->hw->wiphy->fw_version),
2165 "%u.%u.%u.%u",
2166 IWL_UCODE_MAJOR(priv->ucode_ver),
2167 IWL_UCODE_MINOR(priv->ucode_ver),
2168 IWL_UCODE_API(priv->ucode_ver),
2169 IWL_UCODE_SERIAL(priv->ucode_ver));
2170
2163 IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n", 2171 IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
2164 priv->ucode_ver); 2172 priv->ucode_ver);
2165 IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %u\n", 2173 IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %u\n",
@@ -3992,13 +4000,6 @@ static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
3992 */ 4000 */
3993 spin_lock_init(&priv->reg_lock); 4001 spin_lock_init(&priv->reg_lock);
3994 4002
3995 /* amp init */
3996 err = priv->cfg->ops->lib->apm_ops.init(priv);
3997 if (err < 0) {
3998 IWL_DEBUG_INFO(priv, "Failed to init the card\n");
3999 goto out_iounmap;
4000 }
4001
4002 /*********************** 4003 /***********************
4003 * 4. Read EEPROM 4004 * 4. Read EEPROM
4004 * ********************/ 4005 * ********************/
diff --git a/drivers/net/wireless/iwmc3200wifi/Kconfig b/drivers/net/wireless/iwmc3200wifi/Kconfig
index 9606b3100fde..b9d34a766964 100644
--- a/drivers/net/wireless/iwmc3200wifi/Kconfig
+++ b/drivers/net/wireless/iwmc3200wifi/Kconfig
@@ -1,6 +1,6 @@
1config IWM 1config IWM
2 tristate "Intel Wireless Multicomm 3200 WiFi driver" 2 tristate "Intel Wireless Multicomm 3200 WiFi driver"
3 depends on MMC && WLAN_80211 && EXPERIMENTAL 3 depends on MMC && EXPERIMENTAL
4 depends on CFG80211 4 depends on CFG80211
5 select FW_LOADER 5 select FW_LOADER
6 select IWMC3200TOP 6 select IWMC3200TOP
diff --git a/drivers/net/wireless/libertas/Kconfig b/drivers/net/wireless/libertas/Kconfig
index 8f8d75b61ea9..30aa9d48d67e 100644
--- a/drivers/net/wireless/libertas/Kconfig
+++ b/drivers/net/wireless/libertas/Kconfig
@@ -1,6 +1,6 @@
1config LIBERTAS 1config LIBERTAS
2 tristate "Marvell 8xxx Libertas WLAN driver support" 2 tristate "Marvell 8xxx Libertas WLAN driver support"
3 depends on WLAN_80211 && CFG80211 3 depends on CFG80211
4 select WIRELESS_EXT 4 select WIRELESS_EXT
5 select WEXT_SPY 5 select WEXT_SPY
6 select LIB80211 6 select LIB80211
diff --git a/drivers/net/wireless/libertas/if_spi.c b/drivers/net/wireless/libertas/if_spi.c
index 30d9d0ea28eb..d6a48dd3652c 100644
--- a/drivers/net/wireless/libertas/if_spi.c
+++ b/drivers/net/wireless/libertas/if_spi.c
@@ -32,12 +32,6 @@
32#include "dev.h" 32#include "dev.h"
33#include "if_spi.h" 33#include "if_spi.h"
34 34
35struct if_spi_packet {
36 struct list_head list;
37 u16 blen;
38 u8 buffer[0] __attribute__((aligned(4)));
39};
40
41struct if_spi_card { 35struct if_spi_card {
42 struct spi_device *spi; 36 struct spi_device *spi;
43 struct lbs_private *priv; 37 struct lbs_private *priv;
@@ -66,33 +60,10 @@ struct if_spi_card {
66 struct semaphore spi_thread_terminated; 60 struct semaphore spi_thread_terminated;
67 61
68 u8 cmd_buffer[IF_SPI_CMD_BUF_SIZE]; 62 u8 cmd_buffer[IF_SPI_CMD_BUF_SIZE];
69
70 /* A buffer of incoming packets from libertas core.
71 * Since we can't sleep in hw_host_to_card, we have to buffer
72 * them. */
73 struct list_head cmd_packet_list;
74 struct list_head data_packet_list;
75
76 /* Protects cmd_packet_list and data_packet_list */
77 spinlock_t buffer_lock;
78}; 63};
79 64
80static void free_if_spi_card(struct if_spi_card *card) 65static void free_if_spi_card(struct if_spi_card *card)
81{ 66{
82 struct list_head *cursor, *next;
83 struct if_spi_packet *packet;
84
85 BUG_ON(card->run_thread);
86 list_for_each_safe(cursor, next, &card->cmd_packet_list) {
87 packet = container_of(cursor, struct if_spi_packet, list);
88 list_del(&packet->list);
89 kfree(packet);
90 }
91 list_for_each_safe(cursor, next, &card->data_packet_list) {
92 packet = container_of(cursor, struct if_spi_packet, list);
93 list_del(&packet->list);
94 kfree(packet);
95 }
96 spi_set_drvdata(card->spi, NULL); 67 spi_set_drvdata(card->spi, NULL);
97 kfree(card); 68 kfree(card);
98} 69}
@@ -774,40 +745,6 @@ out:
774 return err; 745 return err;
775} 746}
776 747
777/* Move data or a command from the host to the card. */
778static void if_spi_h2c(struct if_spi_card *card,
779 struct if_spi_packet *packet, int type)
780{
781 int err = 0;
782 u16 int_type, port_reg;
783
784 switch (type) {
785 case MVMS_DAT:
786 int_type = IF_SPI_CIC_TX_DOWNLOAD_OVER;
787 port_reg = IF_SPI_DATA_RDWRPORT_REG;
788 break;
789 case MVMS_CMD:
790 int_type = IF_SPI_CIC_CMD_DOWNLOAD_OVER;
791 port_reg = IF_SPI_CMD_RDWRPORT_REG;
792 break;
793 default:
794 lbs_pr_err("can't transfer buffer of type %d\n", type);
795 err = -EINVAL;
796 goto out;
797 }
798
799 /* Write the data to the card */
800 err = spu_write(card, port_reg, packet->buffer, packet->blen);
801 if (err)
802 goto out;
803
804out:
805 kfree(packet);
806
807 if (err)
808 lbs_pr_err("%s: error %d\n", __func__, err);
809}
810
811/* Inform the host about a card event */ 748/* Inform the host about a card event */
812static void if_spi_e2h(struct if_spi_card *card) 749static void if_spi_e2h(struct if_spi_card *card)
813{ 750{
@@ -837,8 +774,6 @@ static int lbs_spi_thread(void *data)
837 int err; 774 int err;
838 struct if_spi_card *card = data; 775 struct if_spi_card *card = data;
839 u16 hiStatus; 776 u16 hiStatus;
840 unsigned long flags;
841 struct if_spi_packet *packet;
842 777
843 while (1) { 778 while (1) {
844 /* Wait to be woken up by one of two things. First, our ISR 779 /* Wait to be woken up by one of two things. First, our ISR
@@ -877,43 +812,9 @@ static int lbs_spi_thread(void *data)
877 if (hiStatus & IF_SPI_HIST_CMD_DOWNLOAD_RDY || 812 if (hiStatus & IF_SPI_HIST_CMD_DOWNLOAD_RDY ||
878 (card->priv->psstate != PS_STATE_FULL_POWER && 813 (card->priv->psstate != PS_STATE_FULL_POWER &&
879 (hiStatus & IF_SPI_HIST_TX_DOWNLOAD_RDY))) { 814 (hiStatus & IF_SPI_HIST_TX_DOWNLOAD_RDY))) {
880 /* This means two things. First of all,
881 * if there was a previous command sent, the card has
882 * successfully received it.
883 * Secondly, it is now ready to download another
884 * command.
885 */
886 lbs_host_to_card_done(card->priv); 815 lbs_host_to_card_done(card->priv);
887
888 /* Do we have any command packets from the host to
889 * send? */
890 packet = NULL;
891 spin_lock_irqsave(&card->buffer_lock, flags);
892 if (!list_empty(&card->cmd_packet_list)) {
893 packet = (struct if_spi_packet *)(card->
894 cmd_packet_list.next);
895 list_del(&packet->list);
896 }
897 spin_unlock_irqrestore(&card->buffer_lock, flags);
898
899 if (packet)
900 if_spi_h2c(card, packet, MVMS_CMD);
901 } 816 }
902 if (hiStatus & IF_SPI_HIST_TX_DOWNLOAD_RDY) {
903 /* Do we have any data packets from the host to
904 * send? */
905 packet = NULL;
906 spin_lock_irqsave(&card->buffer_lock, flags);
907 if (!list_empty(&card->data_packet_list)) {
908 packet = (struct if_spi_packet *)(card->
909 data_packet_list.next);
910 list_del(&packet->list);
911 }
912 spin_unlock_irqrestore(&card->buffer_lock, flags);
913 817
914 if (packet)
915 if_spi_h2c(card, packet, MVMS_DAT);
916 }
917 if (hiStatus & IF_SPI_HIST_CARD_EVENT) 818 if (hiStatus & IF_SPI_HIST_CARD_EVENT)
918 if_spi_e2h(card); 819 if_spi_e2h(card);
919 820
@@ -942,40 +843,18 @@ static int if_spi_host_to_card(struct lbs_private *priv,
942 u8 type, u8 *buf, u16 nb) 843 u8 type, u8 *buf, u16 nb)
943{ 844{
944 int err = 0; 845 int err = 0;
945 unsigned long flags;
946 struct if_spi_card *card = priv->card; 846 struct if_spi_card *card = priv->card;
947 struct if_spi_packet *packet;
948 u16 blen;
949 847
950 lbs_deb_enter_args(LBS_DEB_SPI, "type %d, bytes %d", type, nb); 848 lbs_deb_enter_args(LBS_DEB_SPI, "type %d, bytes %d", type, nb);
951 849
952 if (nb == 0) { 850 nb = ALIGN(nb, 4);
953 lbs_pr_err("%s: invalid size requested: %d\n", __func__, nb);
954 err = -EINVAL;
955 goto out;
956 }
957 blen = ALIGN(nb, 4);
958 packet = kzalloc(sizeof(struct if_spi_packet) + blen, GFP_ATOMIC);
959 if (!packet) {
960 err = -ENOMEM;
961 goto out;
962 }
963 packet->blen = blen;
964 memcpy(packet->buffer, buf, nb);
965 memset(packet->buffer + nb, 0, blen - nb);
966 851
967 switch (type) { 852 switch (type) {
968 case MVMS_CMD: 853 case MVMS_CMD:
969 priv->dnld_sent = DNLD_CMD_SENT; 854 err = spu_write(card, IF_SPI_CMD_RDWRPORT_REG, buf, nb);
970 spin_lock_irqsave(&card->buffer_lock, flags);
971 list_add_tail(&packet->list, &card->cmd_packet_list);
972 spin_unlock_irqrestore(&card->buffer_lock, flags);
973 break; 855 break;
974 case MVMS_DAT: 856 case MVMS_DAT:
975 priv->dnld_sent = DNLD_DATA_SENT; 857 err = spu_write(card, IF_SPI_DATA_RDWRPORT_REG, buf, nb);
976 spin_lock_irqsave(&card->buffer_lock, flags);
977 list_add_tail(&packet->list, &card->data_packet_list);
978 spin_unlock_irqrestore(&card->buffer_lock, flags);
979 break; 858 break;
980 default: 859 default:
981 lbs_pr_err("can't transfer buffer of type %d", type); 860 lbs_pr_err("can't transfer buffer of type %d", type);
@@ -983,9 +862,6 @@ static int if_spi_host_to_card(struct lbs_private *priv,
983 break; 862 break;
984 } 863 }
985 864
986 /* Wake up the spi thread */
987 up(&card->spi_ready);
988out:
989 lbs_deb_leave_args(LBS_DEB_SPI, "err=%d", err); 865 lbs_deb_leave_args(LBS_DEB_SPI, "err=%d", err);
990 return err; 866 return err;
991} 867}
@@ -1062,9 +938,6 @@ static int __devinit if_spi_probe(struct spi_device *spi)
1062 938
1063 sema_init(&card->spi_ready, 0); 939 sema_init(&card->spi_ready, 0);
1064 sema_init(&card->spi_thread_terminated, 0); 940 sema_init(&card->spi_thread_terminated, 0);
1065 INIT_LIST_HEAD(&card->cmd_packet_list);
1066 INIT_LIST_HEAD(&card->data_packet_list);
1067 spin_lock_init(&card->buffer_lock);
1068 941
1069 /* Initialize the SPI Interface Unit */ 942 /* Initialize the SPI Interface Unit */
1070 err = spu_init(card, pdata->use_dummy_writes); 943 err = spu_init(card, pdata->use_dummy_writes);
@@ -1141,6 +1014,9 @@ static int __devinit if_spi_probe(struct spi_device *spi)
1141 goto terminate_thread; 1014 goto terminate_thread;
1142 } 1015 }
1143 1016
1017 /* poke the IRQ handler so that we don't miss the first interrupt */
1018 up(&card->spi_ready);
1019
1144 /* Start the card. 1020 /* Start the card.
1145 * This will call register_netdev, and we'll start 1021 * This will call register_netdev, and we'll start
1146 * getting interrupts... */ 1022 * getting interrupts... */
diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
index 38cfd79e0590..fc4ec48eda12 100644
--- a/drivers/net/wireless/mac80211_hwsim.c
+++ b/drivers/net/wireless/mac80211_hwsim.c
@@ -284,7 +284,7 @@ struct mac80211_hwsim_data {
284 struct ieee80211_channel *channel; 284 struct ieee80211_channel *channel;
285 unsigned long beacon_int; /* in jiffies unit */ 285 unsigned long beacon_int; /* in jiffies unit */
286 unsigned int rx_filter; 286 unsigned int rx_filter;
287 int started; 287 bool started, idle;
288 struct timer_list beacon_timer; 288 struct timer_list beacon_timer;
289 enum ps_mode { 289 enum ps_mode {
290 PS_DISABLED, PS_ENABLED, PS_AUTO_POLL, PS_MANUAL_POLL 290 PS_DISABLED, PS_ENABLED, PS_AUTO_POLL, PS_MANUAL_POLL
@@ -365,6 +365,49 @@ static void mac80211_hwsim_monitor_rx(struct ieee80211_hw *hw,
365} 365}
366 366
367 367
368static void mac80211_hwsim_monitor_ack(struct ieee80211_hw *hw, const u8 *addr)
369{
370 struct mac80211_hwsim_data *data = hw->priv;
371 struct sk_buff *skb;
372 struct hwsim_radiotap_hdr *hdr;
373 u16 flags;
374 struct ieee80211_hdr *hdr11;
375
376 if (!netif_running(hwsim_mon))
377 return;
378
379 skb = dev_alloc_skb(100);
380 if (skb == NULL)
381 return;
382
383 hdr = (struct hwsim_radiotap_hdr *) skb_put(skb, sizeof(*hdr));
384 hdr->hdr.it_version = PKTHDR_RADIOTAP_VERSION;
385 hdr->hdr.it_pad = 0;
386 hdr->hdr.it_len = cpu_to_le16(sizeof(*hdr));
387 hdr->hdr.it_present = cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
388 (1 << IEEE80211_RADIOTAP_CHANNEL));
389 hdr->rt_flags = 0;
390 hdr->rt_rate = 0;
391 hdr->rt_channel = cpu_to_le16(data->channel->center_freq);
392 flags = IEEE80211_CHAN_2GHZ;
393 hdr->rt_chbitmask = cpu_to_le16(flags);
394
395 hdr11 = (struct ieee80211_hdr *) skb_put(skb, 10);
396 hdr11->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL |
397 IEEE80211_STYPE_ACK);
398 hdr11->duration_id = cpu_to_le16(0);
399 memcpy(hdr11->addr1, addr, ETH_ALEN);
400
401 skb->dev = hwsim_mon;
402 skb_set_mac_header(skb, 0);
403 skb->ip_summed = CHECKSUM_UNNECESSARY;
404 skb->pkt_type = PACKET_OTHERHOST;
405 skb->protocol = htons(ETH_P_802_2);
406 memset(skb->cb, 0, sizeof(skb->cb));
407 netif_rx(skb);
408}
409
410
368static bool hwsim_ps_rx_ok(struct mac80211_hwsim_data *data, 411static bool hwsim_ps_rx_ok(struct mac80211_hwsim_data *data,
369 struct sk_buff *skb) 412 struct sk_buff *skb)
370{ 413{
@@ -402,6 +445,12 @@ static bool mac80211_hwsim_tx_frame(struct ieee80211_hw *hw,
402 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 445 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
403 struct ieee80211_rx_status rx_status; 446 struct ieee80211_rx_status rx_status;
404 447
448 if (data->idle) {
449 printk(KERN_DEBUG "%s: Trying to TX when idle - reject\n",
450 wiphy_name(hw->wiphy));
451 return false;
452 }
453
405 memset(&rx_status, 0, sizeof(rx_status)); 454 memset(&rx_status, 0, sizeof(rx_status));
406 /* TODO: set mactime */ 455 /* TODO: set mactime */
407 rx_status.freq = data->channel->center_freq; 456 rx_status.freq = data->channel->center_freq;
@@ -428,7 +477,8 @@ static bool mac80211_hwsim_tx_frame(struct ieee80211_hw *hw,
428 if (data == data2) 477 if (data == data2)
429 continue; 478 continue;
430 479
431 if (!data2->started || !hwsim_ps_rx_ok(data2, skb) || 480 if (data2->idle || !data2->started ||
481 !hwsim_ps_rx_ok(data2, skb) ||
432 !data->channel || !data2->channel || 482 !data->channel || !data2->channel ||
433 data->channel->center_freq != data2->channel->center_freq || 483 data->channel->center_freq != data2->channel->center_freq ||
434 !(data->group & data2->group)) 484 !(data->group & data2->group))
@@ -464,6 +514,10 @@ static int mac80211_hwsim_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
464 } 514 }
465 515
466 ack = mac80211_hwsim_tx_frame(hw, skb); 516 ack = mac80211_hwsim_tx_frame(hw, skb);
517 if (ack && skb->len >= 16) {
518 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
519 mac80211_hwsim_monitor_ack(hw, hdr->addr2);
520 }
467 521
468 txi = IEEE80211_SKB_CB(skb); 522 txi = IEEE80211_SKB_CB(skb);
469 523
@@ -571,6 +625,8 @@ static int mac80211_hwsim_config(struct ieee80211_hw *hw, u32 changed)
571 !!(conf->flags & IEEE80211_CONF_IDLE), 625 !!(conf->flags & IEEE80211_CONF_IDLE),
572 !!(conf->flags & IEEE80211_CONF_PS)); 626 !!(conf->flags & IEEE80211_CONF_PS));
573 627
628 data->idle = !!(conf->flags & IEEE80211_CONF_IDLE);
629
574 data->channel = conf->channel; 630 data->channel = conf->channel;
575 if (!data->started || !data->beacon_int) 631 if (!data->started || !data->beacon_int)
576 del_timer(&data->beacon_timer); 632 del_timer(&data->beacon_timer);
@@ -1045,19 +1101,20 @@ static int __init init_mac80211_hwsim(void)
1045 sband->channels = data->channels_2ghz; 1101 sband->channels = data->channels_2ghz;
1046 sband->n_channels = 1102 sband->n_channels =
1047 ARRAY_SIZE(hwsim_channels_2ghz); 1103 ARRAY_SIZE(hwsim_channels_2ghz);
1104 sband->bitrates = data->rates;
1105 sband->n_bitrates = ARRAY_SIZE(hwsim_rates);
1048 break; 1106 break;
1049 case IEEE80211_BAND_5GHZ: 1107 case IEEE80211_BAND_5GHZ:
1050 sband->channels = data->channels_5ghz; 1108 sband->channels = data->channels_5ghz;
1051 sband->n_channels = 1109 sband->n_channels =
1052 ARRAY_SIZE(hwsim_channels_5ghz); 1110 ARRAY_SIZE(hwsim_channels_5ghz);
1111 sband->bitrates = data->rates + 4;
1112 sband->n_bitrates = ARRAY_SIZE(hwsim_rates) - 4;
1053 break; 1113 break;
1054 default: 1114 default:
1055 break; 1115 break;
1056 } 1116 }
1057 1117
1058 sband->bitrates = data->rates;
1059 sband->n_bitrates = ARRAY_SIZE(hwsim_rates);
1060
1061 sband->ht_cap.ht_supported = true; 1118 sband->ht_cap.ht_supported = true;
1062 sband->ht_cap.cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 | 1119 sband->ht_cap.cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
1063 IEEE80211_HT_CAP_GRN_FLD | 1120 IEEE80211_HT_CAP_GRN_FLD |
diff --git a/drivers/net/wireless/mwl8k.c b/drivers/net/wireless/mwl8k.c
index 746532ebe5a8..2ebfee4da3fa 100644
--- a/drivers/net/wireless/mwl8k.c
+++ b/drivers/net/wireless/mwl8k.c
@@ -12,6 +12,7 @@
12#include <linux/init.h> 12#include <linux/init.h>
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/sched.h>
15#include <linux/spinlock.h> 16#include <linux/spinlock.h>
16#include <linux/list.h> 17#include <linux/list.h>
17#include <linux/pci.h> 18#include <linux/pci.h>
@@ -27,18 +28,6 @@
27#define MWL8K_NAME KBUILD_MODNAME 28#define MWL8K_NAME KBUILD_MODNAME
28#define MWL8K_VERSION "0.10" 29#define MWL8K_VERSION "0.10"
29 30
30MODULE_DESCRIPTION(MWL8K_DESC);
31MODULE_VERSION(MWL8K_VERSION);
32MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
33MODULE_LICENSE("GPL");
34
35static DEFINE_PCI_DEVICE_TABLE(mwl8k_table) = {
36 { PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = 8687, },
37 { PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = 8687, },
38 { }
39};
40MODULE_DEVICE_TABLE(pci, mwl8k_table);
41
42/* Register definitions */ 31/* Register definitions */
43#define MWL8K_HIU_GEN_PTR 0x00000c10 32#define MWL8K_HIU_GEN_PTR 0x00000c10
44#define MWL8K_MODE_STA 0x0000005a 33#define MWL8K_MODE_STA 0x0000005a
@@ -88,72 +77,89 @@ MODULE_DEVICE_TABLE(pci, mwl8k_table);
88 MWL8K_A2H_INT_RX_READY | \ 77 MWL8K_A2H_INT_RX_READY | \
89 MWL8K_A2H_INT_TX_DONE) 78 MWL8K_A2H_INT_TX_DONE)
90 79
91/* WME stream classes */
92#define WME_AC_BE 0 /* best effort */
93#define WME_AC_BK 1 /* background */
94#define WME_AC_VI 2 /* video */
95#define WME_AC_VO 3 /* voice */
96
97#define MWL8K_RX_QUEUES 1 80#define MWL8K_RX_QUEUES 1
98#define MWL8K_TX_QUEUES 4 81#define MWL8K_TX_QUEUES 4
99 82
83struct rxd_ops {
84 int rxd_size;
85 void (*rxd_init)(void *rxd, dma_addr_t next_dma_addr);
86 void (*rxd_refill)(void *rxd, dma_addr_t addr, int len);
87 int (*rxd_process)(void *rxd, struct ieee80211_rx_status *status);
88};
89
90struct mwl8k_device_info {
91 char *part_name;
92 char *helper_image;
93 char *fw_image;
94 struct rxd_ops *rxd_ops;
95 u16 modes;
96};
97
100struct mwl8k_rx_queue { 98struct mwl8k_rx_queue {
101 int rx_desc_count; 99 int rxd_count;
102 100
103 /* hw receives here */ 101 /* hw receives here */
104 int rx_head; 102 int head;
105 103
106 /* refill descs here */ 104 /* refill descs here */
107 int rx_tail; 105 int tail;
108 106
109 struct mwl8k_rx_desc *rx_desc_area; 107 void *rxd;
110 dma_addr_t rx_desc_dma; 108 dma_addr_t rxd_dma;
111 struct sk_buff **rx_skb; 109 struct {
110 struct sk_buff *skb;
111 DECLARE_PCI_UNMAP_ADDR(dma)
112 } *buf;
112}; 113};
113 114
114struct mwl8k_tx_queue { 115struct mwl8k_tx_queue {
115 /* hw transmits here */ 116 /* hw transmits here */
116 int tx_head; 117 int head;
117 118
118 /* sw appends here */ 119 /* sw appends here */
119 int tx_tail; 120 int tail;
120 121
121 struct ieee80211_tx_queue_stats tx_stats; 122 struct ieee80211_tx_queue_stats stats;
122 struct mwl8k_tx_desc *tx_desc_area; 123 struct mwl8k_tx_desc *txd;
123 dma_addr_t tx_desc_dma; 124 dma_addr_t txd_dma;
124 struct sk_buff **tx_skb; 125 struct sk_buff **skb;
125}; 126};
126 127
127/* Pointers to the firmware data and meta information about it. */ 128/* Pointers to the firmware data and meta information about it. */
128struct mwl8k_firmware { 129struct mwl8k_firmware {
129 /* Microcode */
130 struct firmware *ucode;
131
132 /* Boot helper code */ 130 /* Boot helper code */
133 struct firmware *helper; 131 struct firmware *helper;
132
133 /* Microcode */
134 struct firmware *ucode;
134}; 135};
135 136
136struct mwl8k_priv { 137struct mwl8k_priv {
138 void __iomem *sram;
137 void __iomem *regs; 139 void __iomem *regs;
138 struct ieee80211_hw *hw; 140 struct ieee80211_hw *hw;
139 141
140 struct pci_dev *pdev; 142 struct pci_dev *pdev;
141 u8 name[16]; 143
144 struct mwl8k_device_info *device_info;
145 bool ap_fw;
146 struct rxd_ops *rxd_ops;
142 147
143 /* firmware files and meta data */ 148 /* firmware files and meta data */
144 struct mwl8k_firmware fw; 149 struct mwl8k_firmware fw;
145 u32 part_num;
146 150
147 /* firmware access */ 151 /* firmware access */
148 struct mutex fw_mutex; 152 struct mutex fw_mutex;
149 struct task_struct *fw_mutex_owner; 153 struct task_struct *fw_mutex_owner;
150 int fw_mutex_depth; 154 int fw_mutex_depth;
151 struct completion *tx_wait;
152 struct completion *hostcmd_wait; 155 struct completion *hostcmd_wait;
153 156
154 /* lock held over TX and TX reap */ 157 /* lock held over TX and TX reap */
155 spinlock_t tx_lock; 158 spinlock_t tx_lock;
156 159
160 /* TX quiesce completion, protected by fw_mutex and tx_lock */
161 struct completion *tx_wait;
162
157 struct ieee80211_vif *vif; 163 struct ieee80211_vif *vif;
158 164
159 struct ieee80211_channel *current_channel; 165 struct ieee80211_channel *current_channel;
@@ -178,10 +184,11 @@ struct mwl8k_priv {
178 /* PHY parameters */ 184 /* PHY parameters */
179 struct ieee80211_supported_band band; 185 struct ieee80211_supported_band band;
180 struct ieee80211_channel channels[14]; 186 struct ieee80211_channel channels[14];
181 struct ieee80211_rate rates[12]; 187 struct ieee80211_rate rates[13];
182 188
183 bool radio_on; 189 bool radio_on;
184 bool radio_short_preamble; 190 bool radio_short_preamble;
191 bool sniffer_enabled;
185 bool wmm_enabled; 192 bool wmm_enabled;
186 193
187 /* XXX need to convert this to handle multiple interfaces */ 194 /* XXX need to convert this to handle multiple interfaces */
@@ -199,9 +206,6 @@ struct mwl8k_priv {
199 206
200 /* Tasklet to reclaim TX descriptors and buffers after tx */ 207 /* Tasklet to reclaim TX descriptors and buffers after tx */
201 struct tasklet_struct tx_reclaim_task; 208 struct tasklet_struct tx_reclaim_task;
202
203 /* Work thread to serialize configuration requests */
204 struct workqueue_struct *config_wq;
205}; 209};
206 210
207/* Per interface specific private data */ 211/* Per interface specific private data */
@@ -220,7 +224,7 @@ struct mwl8k_vif {
220 * Subset of supported legacy rates. 224 * Subset of supported legacy rates.
221 * Intersection of AP and STA supported rates. 225 * Intersection of AP and STA supported rates.
222 */ 226 */
223 struct ieee80211_rate legacy_rates[12]; 227 struct ieee80211_rate legacy_rates[13];
224 228
225 /* number of supported legacy rates */ 229 /* number of supported legacy rates */
226 u8 legacy_nrates; 230 u8 legacy_nrates;
@@ -252,9 +256,10 @@ static const struct ieee80211_rate mwl8k_rates[] = {
252 { .bitrate = 10, .hw_value = 2, }, 256 { .bitrate = 10, .hw_value = 2, },
253 { .bitrate = 20, .hw_value = 4, }, 257 { .bitrate = 20, .hw_value = 4, },
254 { .bitrate = 55, .hw_value = 11, }, 258 { .bitrate = 55, .hw_value = 11, },
259 { .bitrate = 110, .hw_value = 22, },
260 { .bitrate = 220, .hw_value = 44, },
255 { .bitrate = 60, .hw_value = 12, }, 261 { .bitrate = 60, .hw_value = 12, },
256 { .bitrate = 90, .hw_value = 18, }, 262 { .bitrate = 90, .hw_value = 18, },
257 { .bitrate = 110, .hw_value = 22, },
258 { .bitrate = 120, .hw_value = 24, }, 263 { .bitrate = 120, .hw_value = 24, },
259 { .bitrate = 180, .hw_value = 36, }, 264 { .bitrate = 180, .hw_value = 36, },
260 { .bitrate = 240, .hw_value = 48, }, 265 { .bitrate = 240, .hw_value = 48, },
@@ -270,10 +275,12 @@ static const struct ieee80211_rate mwl8k_rates[] = {
270/* Firmware command codes */ 275/* Firmware command codes */
271#define MWL8K_CMD_CODE_DNLD 0x0001 276#define MWL8K_CMD_CODE_DNLD 0x0001
272#define MWL8K_CMD_GET_HW_SPEC 0x0003 277#define MWL8K_CMD_GET_HW_SPEC 0x0003
278#define MWL8K_CMD_SET_HW_SPEC 0x0004
273#define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010 279#define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
274#define MWL8K_CMD_GET_STAT 0x0014 280#define MWL8K_CMD_GET_STAT 0x0014
275#define MWL8K_CMD_RADIO_CONTROL 0x001c 281#define MWL8K_CMD_RADIO_CONTROL 0x001c
276#define MWL8K_CMD_RF_TX_POWER 0x001e 282#define MWL8K_CMD_RF_TX_POWER 0x001e
283#define MWL8K_CMD_RF_ANTENNA 0x0020
277#define MWL8K_CMD_SET_PRE_SCAN 0x0107 284#define MWL8K_CMD_SET_PRE_SCAN 0x0107
278#define MWL8K_CMD_SET_POST_SCAN 0x0108 285#define MWL8K_CMD_SET_POST_SCAN 0x0108
279#define MWL8K_CMD_SET_RF_CHANNEL 0x010a 286#define MWL8K_CMD_SET_RF_CHANNEL 0x010a
@@ -287,6 +294,7 @@ static const struct ieee80211_rate mwl8k_rates[] = {
287#define MWL8K_CMD_MIMO_CONFIG 0x0125 294#define MWL8K_CMD_MIMO_CONFIG 0x0125
288#define MWL8K_CMD_USE_FIXED_RATE 0x0126 295#define MWL8K_CMD_USE_FIXED_RATE 0x0126
289#define MWL8K_CMD_ENABLE_SNIFFER 0x0150 296#define MWL8K_CMD_ENABLE_SNIFFER 0x0150
297#define MWL8K_CMD_SET_MAC_ADDR 0x0202
290#define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203 298#define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
291#define MWL8K_CMD_UPDATE_STADB 0x1123 299#define MWL8K_CMD_UPDATE_STADB 0x1123
292 300
@@ -299,10 +307,12 @@ static const char *mwl8k_cmd_name(u16 cmd, char *buf, int bufsize)
299 switch (cmd & ~0x8000) { 307 switch (cmd & ~0x8000) {
300 MWL8K_CMDNAME(CODE_DNLD); 308 MWL8K_CMDNAME(CODE_DNLD);
301 MWL8K_CMDNAME(GET_HW_SPEC); 309 MWL8K_CMDNAME(GET_HW_SPEC);
310 MWL8K_CMDNAME(SET_HW_SPEC);
302 MWL8K_CMDNAME(MAC_MULTICAST_ADR); 311 MWL8K_CMDNAME(MAC_MULTICAST_ADR);
303 MWL8K_CMDNAME(GET_STAT); 312 MWL8K_CMDNAME(GET_STAT);
304 MWL8K_CMDNAME(RADIO_CONTROL); 313 MWL8K_CMDNAME(RADIO_CONTROL);
305 MWL8K_CMDNAME(RF_TX_POWER); 314 MWL8K_CMDNAME(RF_TX_POWER);
315 MWL8K_CMDNAME(RF_ANTENNA);
306 MWL8K_CMDNAME(SET_PRE_SCAN); 316 MWL8K_CMDNAME(SET_PRE_SCAN);
307 MWL8K_CMDNAME(SET_POST_SCAN); 317 MWL8K_CMDNAME(SET_POST_SCAN);
308 MWL8K_CMDNAME(SET_RF_CHANNEL); 318 MWL8K_CMDNAME(SET_RF_CHANNEL);
@@ -316,6 +326,7 @@ static const char *mwl8k_cmd_name(u16 cmd, char *buf, int bufsize)
316 MWL8K_CMDNAME(MIMO_CONFIG); 326 MWL8K_CMDNAME(MIMO_CONFIG);
317 MWL8K_CMDNAME(USE_FIXED_RATE); 327 MWL8K_CMDNAME(USE_FIXED_RATE);
318 MWL8K_CMDNAME(ENABLE_SNIFFER); 328 MWL8K_CMDNAME(ENABLE_SNIFFER);
329 MWL8K_CMDNAME(SET_MAC_ADDR);
319 MWL8K_CMDNAME(SET_RATEADAPT_MODE); 330 MWL8K_CMDNAME(SET_RATEADAPT_MODE);
320 MWL8K_CMDNAME(UPDATE_STADB); 331 MWL8K_CMDNAME(UPDATE_STADB);
321 default: 332 default:
@@ -353,41 +364,35 @@ static void mwl8k_release_firmware(struct mwl8k_priv *priv)
353 364
354/* Request fw image */ 365/* Request fw image */
355static int mwl8k_request_fw(struct mwl8k_priv *priv, 366static int mwl8k_request_fw(struct mwl8k_priv *priv,
356 const char *fname, struct firmware **fw) 367 const char *fname, struct firmware **fw)
357{ 368{
358 /* release current image */ 369 /* release current image */
359 if (*fw != NULL) 370 if (*fw != NULL)
360 mwl8k_release_fw(fw); 371 mwl8k_release_fw(fw);
361 372
362 return request_firmware((const struct firmware **)fw, 373 return request_firmware((const struct firmware **)fw,
363 fname, &priv->pdev->dev); 374 fname, &priv->pdev->dev);
364} 375}
365 376
366static int mwl8k_request_firmware(struct mwl8k_priv *priv, u32 part_num) 377static int mwl8k_request_firmware(struct mwl8k_priv *priv)
367{ 378{
368 u8 filename[64]; 379 struct mwl8k_device_info *di = priv->device_info;
369 int rc; 380 int rc;
370 381
371 priv->part_num = part_num; 382 if (di->helper_image != NULL) {
372 383 rc = mwl8k_request_fw(priv, di->helper_image, &priv->fw.helper);
373 snprintf(filename, sizeof(filename), 384 if (rc) {
374 "mwl8k/helper_%u.fw", priv->part_num); 385 printk(KERN_ERR "%s: Error requesting helper "
375 386 "firmware file %s\n", pci_name(priv->pdev),
376 rc = mwl8k_request_fw(priv, filename, &priv->fw.helper); 387 di->helper_image);
377 if (rc) { 388 return rc;
378 printk(KERN_ERR 389 }
379 "%s Error requesting helper firmware file %s\n",
380 pci_name(priv->pdev), filename);
381 return rc;
382 } 390 }
383 391
384 snprintf(filename, sizeof(filename), 392 rc = mwl8k_request_fw(priv, di->fw_image, &priv->fw.ucode);
385 "mwl8k/fmimage_%u.fw", priv->part_num);
386
387 rc = mwl8k_request_fw(priv, filename, &priv->fw.ucode);
388 if (rc) { 393 if (rc) {
389 printk(KERN_ERR "%s Error requesting firmware file %s\n", 394 printk(KERN_ERR "%s: Error requesting firmware file %s\n",
390 pci_name(priv->pdev), filename); 395 pci_name(priv->pdev), di->fw_image);
391 mwl8k_release_fw(&priv->fw.helper); 396 mwl8k_release_fw(&priv->fw.helper);
392 return rc; 397 return rc;
393 } 398 }
@@ -434,6 +439,7 @@ mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length)
434 break; 439 break;
435 } 440 }
436 441
442 cond_resched();
437 udelay(1); 443 udelay(1);
438 } while (--loops); 444 } while (--loops);
439 445
@@ -542,43 +548,62 @@ static int mwl8k_feed_fw_image(struct mwl8k_priv *priv,
542 return rc; 548 return rc;
543} 549}
544 550
545static int mwl8k_load_firmware(struct mwl8k_priv *priv) 551static int mwl8k_load_firmware(struct ieee80211_hw *hw)
546{ 552{
547 int loops, rc; 553 struct mwl8k_priv *priv = hw->priv;
554 struct firmware *fw = priv->fw.ucode;
555 struct mwl8k_device_info *di = priv->device_info;
556 int rc;
557 int loops;
558
559 if (!memcmp(fw->data, "\x01\x00\x00\x00", 4)) {
560 struct firmware *helper = priv->fw.helper;
548 561
549 const u8 *ucode = priv->fw.ucode->data; 562 if (helper == NULL) {
550 size_t ucode_len = priv->fw.ucode->size; 563 printk(KERN_ERR "%s: helper image needed but none "
551 const u8 *helper = priv->fw.helper->data; 564 "given\n", pci_name(priv->pdev));
552 size_t helper_len = priv->fw.helper->size; 565 return -EINVAL;
566 }
553 567
554 if (!memcmp(ucode, "\x01\x00\x00\x00", 4)) { 568 rc = mwl8k_load_fw_image(priv, helper->data, helper->size);
555 rc = mwl8k_load_fw_image(priv, helper, helper_len);
556 if (rc) { 569 if (rc) {
557 printk(KERN_ERR "%s: unable to load firmware " 570 printk(KERN_ERR "%s: unable to load firmware "
558 "helper image\n", pci_name(priv->pdev)); 571 "helper image\n", pci_name(priv->pdev));
559 return rc; 572 return rc;
560 } 573 }
561 msleep(1); 574 msleep(1);
562 575
563 rc = mwl8k_feed_fw_image(priv, ucode, ucode_len); 576 rc = mwl8k_feed_fw_image(priv, fw->data, fw->size);
564 } else { 577 } else {
565 rc = mwl8k_load_fw_image(priv, ucode, ucode_len); 578 rc = mwl8k_load_fw_image(priv, fw->data, fw->size);
566 } 579 }
567 580
568 if (rc) { 581 if (rc) {
569 printk(KERN_ERR "%s: unable to load firmware data\n", 582 printk(KERN_ERR "%s: unable to load firmware image\n",
570 pci_name(priv->pdev)); 583 pci_name(priv->pdev));
571 return rc; 584 return rc;
572 } 585 }
573 586
574 iowrite32(MWL8K_MODE_STA, priv->regs + MWL8K_HIU_GEN_PTR); 587 if (di->modes & BIT(NL80211_IFTYPE_AP))
588 iowrite32(MWL8K_MODE_AP, priv->regs + MWL8K_HIU_GEN_PTR);
589 else
590 iowrite32(MWL8K_MODE_STA, priv->regs + MWL8K_HIU_GEN_PTR);
575 msleep(1); 591 msleep(1);
576 592
577 loops = 200000; 593 loops = 200000;
578 do { 594 do {
579 if (ioread32(priv->regs + MWL8K_HIU_INT_CODE) 595 u32 ready_code;
580 == MWL8K_FWSTA_READY) 596
597 ready_code = ioread32(priv->regs + MWL8K_HIU_INT_CODE);
598 if (ready_code == MWL8K_FWAP_READY) {
599 priv->ap_fw = 1;
581 break; 600 break;
601 } else if (ready_code == MWL8K_FWSTA_READY) {
602 priv->ap_fw = 0;
603 break;
604 }
605
606 cond_resched();
582 udelay(1); 607 udelay(1);
583 } while (--loops); 608 } while (--loops);
584 609
@@ -605,7 +630,7 @@ struct ewc_ht_info {
605/* Peer Entry flags - used to define the type of the peer node */ 630/* Peer Entry flags - used to define the type of the peer node */
606#define MWL8K_PEER_TYPE_ACCESSPOINT 2 631#define MWL8K_PEER_TYPE_ACCESSPOINT 2
607 632
608#define MWL8K_IEEE_LEGACY_DATA_RATES 12 633#define MWL8K_IEEE_LEGACY_DATA_RATES 13
609#define MWL8K_MCS_BITMAP_SIZE 16 634#define MWL8K_MCS_BITMAP_SIZE 16
610 635
611struct peer_capability_info { 636struct peer_capability_info {
@@ -731,16 +756,96 @@ static inline void mwl8k_add_dma_header(struct sk_buff *skb)
731 756
732 757
733/* 758/*
734 * Packet reception. 759 * Packet reception for 88w8366.
735 */ 760 */
736#define MWL8K_RX_CTRL_OWNED_BY_HOST 0x02 761struct mwl8k_rxd_8366 {
762 __le16 pkt_len;
763 __u8 sq2;
764 __u8 rate;
765 __le32 pkt_phys_addr;
766 __le32 next_rxd_phys_addr;
767 __le16 qos_control;
768 __le16 htsig2;
769 __le32 hw_rssi_info;
770 __le32 hw_noise_floor_info;
771 __u8 noise_floor;
772 __u8 pad0[3];
773 __u8 rssi;
774 __u8 rx_status;
775 __u8 channel;
776 __u8 rx_ctrl;
777} __attribute__((packed));
737 778
738struct mwl8k_rx_desc { 779#define MWL8K_8366_RX_CTRL_OWNED_BY_HOST 0x80
780
781static void mwl8k_rxd_8366_init(void *_rxd, dma_addr_t next_dma_addr)
782{
783 struct mwl8k_rxd_8366 *rxd = _rxd;
784
785 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
786 rxd->rx_ctrl = MWL8K_8366_RX_CTRL_OWNED_BY_HOST;
787}
788
789static void mwl8k_rxd_8366_refill(void *_rxd, dma_addr_t addr, int len)
790{
791 struct mwl8k_rxd_8366 *rxd = _rxd;
792
793 rxd->pkt_len = cpu_to_le16(len);
794 rxd->pkt_phys_addr = cpu_to_le32(addr);
795 wmb();
796 rxd->rx_ctrl = 0;
797}
798
799static int
800mwl8k_rxd_8366_process(void *_rxd, struct ieee80211_rx_status *status)
801{
802 struct mwl8k_rxd_8366 *rxd = _rxd;
803
804 if (!(rxd->rx_ctrl & MWL8K_8366_RX_CTRL_OWNED_BY_HOST))
805 return -1;
806 rmb();
807
808 memset(status, 0, sizeof(*status));
809
810 status->signal = -rxd->rssi;
811 status->noise = -rxd->noise_floor;
812
813 if (rxd->rate & 0x80) {
814 status->flag |= RX_FLAG_HT;
815 status->rate_idx = rxd->rate & 0x7f;
816 } else {
817 int i;
818
819 for (i = 0; i < ARRAY_SIZE(mwl8k_rates); i++) {
820 if (mwl8k_rates[i].hw_value == rxd->rate) {
821 status->rate_idx = i;
822 break;
823 }
824 }
825 }
826
827 status->band = IEEE80211_BAND_2GHZ;
828 status->freq = ieee80211_channel_to_frequency(rxd->channel);
829
830 return le16_to_cpu(rxd->pkt_len);
831}
832
833static struct rxd_ops rxd_8366_ops = {
834 .rxd_size = sizeof(struct mwl8k_rxd_8366),
835 .rxd_init = mwl8k_rxd_8366_init,
836 .rxd_refill = mwl8k_rxd_8366_refill,
837 .rxd_process = mwl8k_rxd_8366_process,
838};
839
840/*
841 * Packet reception for 88w8687.
842 */
843struct mwl8k_rxd_8687 {
739 __le16 pkt_len; 844 __le16 pkt_len;
740 __u8 link_quality; 845 __u8 link_quality;
741 __u8 noise_level; 846 __u8 noise_level;
742 __le32 pkt_phys_addr; 847 __le32 pkt_phys_addr;
743 __le32 next_rx_desc_phys_addr; 848 __le32 next_rxd_phys_addr;
744 __le16 qos_control; 849 __le16 qos_control;
745 __le16 rate_info; 850 __le16 rate_info;
746 __le32 pad0[4]; 851 __le32 pad0[4];
@@ -752,6 +857,76 @@ struct mwl8k_rx_desc {
752 __u8 pad2[2]; 857 __u8 pad2[2];
753} __attribute__((packed)); 858} __attribute__((packed));
754 859
860#define MWL8K_8687_RATE_INFO_SHORTPRE 0x8000
861#define MWL8K_8687_RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3)
862#define MWL8K_8687_RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f)
863#define MWL8K_8687_RATE_INFO_40MHZ 0x0004
864#define MWL8K_8687_RATE_INFO_SHORTGI 0x0002
865#define MWL8K_8687_RATE_INFO_MCS_FORMAT 0x0001
866
867#define MWL8K_8687_RX_CTRL_OWNED_BY_HOST 0x02
868
869static void mwl8k_rxd_8687_init(void *_rxd, dma_addr_t next_dma_addr)
870{
871 struct mwl8k_rxd_8687 *rxd = _rxd;
872
873 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
874 rxd->rx_ctrl = MWL8K_8687_RX_CTRL_OWNED_BY_HOST;
875}
876
877static void mwl8k_rxd_8687_refill(void *_rxd, dma_addr_t addr, int len)
878{
879 struct mwl8k_rxd_8687 *rxd = _rxd;
880
881 rxd->pkt_len = cpu_to_le16(len);
882 rxd->pkt_phys_addr = cpu_to_le32(addr);
883 wmb();
884 rxd->rx_ctrl = 0;
885}
886
887static int
888mwl8k_rxd_8687_process(void *_rxd, struct ieee80211_rx_status *status)
889{
890 struct mwl8k_rxd_8687 *rxd = _rxd;
891 u16 rate_info;
892
893 if (!(rxd->rx_ctrl & MWL8K_8687_RX_CTRL_OWNED_BY_HOST))
894 return -1;
895 rmb();
896
897 rate_info = le16_to_cpu(rxd->rate_info);
898
899 memset(status, 0, sizeof(*status));
900
901 status->signal = -rxd->rssi;
902 status->noise = -rxd->noise_level;
903 status->qual = rxd->link_quality;
904 status->antenna = MWL8K_8687_RATE_INFO_ANTSELECT(rate_info);
905 status->rate_idx = MWL8K_8687_RATE_INFO_RATEID(rate_info);
906
907 if (rate_info & MWL8K_8687_RATE_INFO_SHORTPRE)
908 status->flag |= RX_FLAG_SHORTPRE;
909 if (rate_info & MWL8K_8687_RATE_INFO_40MHZ)
910 status->flag |= RX_FLAG_40MHZ;
911 if (rate_info & MWL8K_8687_RATE_INFO_SHORTGI)
912 status->flag |= RX_FLAG_SHORT_GI;
913 if (rate_info & MWL8K_8687_RATE_INFO_MCS_FORMAT)
914 status->flag |= RX_FLAG_HT;
915
916 status->band = IEEE80211_BAND_2GHZ;
917 status->freq = ieee80211_channel_to_frequency(rxd->channel);
918
919 return le16_to_cpu(rxd->pkt_len);
920}
921
922static struct rxd_ops rxd_8687_ops = {
923 .rxd_size = sizeof(struct mwl8k_rxd_8687),
924 .rxd_init = mwl8k_rxd_8687_init,
925 .rxd_refill = mwl8k_rxd_8687_refill,
926 .rxd_process = mwl8k_rxd_8687_process,
927};
928
929
755#define MWL8K_RX_DESCS 256 930#define MWL8K_RX_DESCS 256
756#define MWL8K_RX_MAXSZ 3800 931#define MWL8K_RX_MAXSZ 3800
757 932
@@ -762,43 +937,44 @@ static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index)
762 int size; 937 int size;
763 int i; 938 int i;
764 939
765 rxq->rx_desc_count = 0; 940 rxq->rxd_count = 0;
766 rxq->rx_head = 0; 941 rxq->head = 0;
767 rxq->rx_tail = 0; 942 rxq->tail = 0;
768 943
769 size = MWL8K_RX_DESCS * sizeof(struct mwl8k_rx_desc); 944 size = MWL8K_RX_DESCS * priv->rxd_ops->rxd_size;
770 945
771 rxq->rx_desc_area = 946 rxq->rxd = pci_alloc_consistent(priv->pdev, size, &rxq->rxd_dma);
772 pci_alloc_consistent(priv->pdev, size, &rxq->rx_desc_dma); 947 if (rxq->rxd == NULL) {
773 if (rxq->rx_desc_area == NULL) {
774 printk(KERN_ERR "%s: failed to alloc RX descriptors\n", 948 printk(KERN_ERR "%s: failed to alloc RX descriptors\n",
775 priv->name); 949 wiphy_name(hw->wiphy));
776 return -ENOMEM; 950 return -ENOMEM;
777 } 951 }
778 memset(rxq->rx_desc_area, 0, size); 952 memset(rxq->rxd, 0, size);
779 953
780 rxq->rx_skb = kmalloc(MWL8K_RX_DESCS * 954 rxq->buf = kmalloc(MWL8K_RX_DESCS * sizeof(*rxq->buf), GFP_KERNEL);
781 sizeof(*rxq->rx_skb), GFP_KERNEL); 955 if (rxq->buf == NULL) {
782 if (rxq->rx_skb == NULL) {
783 printk(KERN_ERR "%s: failed to alloc RX skbuff list\n", 956 printk(KERN_ERR "%s: failed to alloc RX skbuff list\n",
784 priv->name); 957 wiphy_name(hw->wiphy));
785 pci_free_consistent(priv->pdev, size, 958 pci_free_consistent(priv->pdev, size, rxq->rxd, rxq->rxd_dma);
786 rxq->rx_desc_area, rxq->rx_desc_dma);
787 return -ENOMEM; 959 return -ENOMEM;
788 } 960 }
789 memset(rxq->rx_skb, 0, MWL8K_RX_DESCS * sizeof(*rxq->rx_skb)); 961 memset(rxq->buf, 0, MWL8K_RX_DESCS * sizeof(*rxq->buf));
790 962
791 for (i = 0; i < MWL8K_RX_DESCS; i++) { 963 for (i = 0; i < MWL8K_RX_DESCS; i++) {
792 struct mwl8k_rx_desc *rx_desc; 964 int desc_size;
965 void *rxd;
793 int nexti; 966 int nexti;
967 dma_addr_t next_dma_addr;
794 968
795 rx_desc = rxq->rx_desc_area + i; 969 desc_size = priv->rxd_ops->rxd_size;
796 nexti = (i + 1) % MWL8K_RX_DESCS; 970 rxd = rxq->rxd + (i * priv->rxd_ops->rxd_size);
797 971
798 rx_desc->next_rx_desc_phys_addr = 972 nexti = i + 1;
799 cpu_to_le32(rxq->rx_desc_dma 973 if (nexti == MWL8K_RX_DESCS)
800 + nexti * sizeof(*rx_desc)); 974 nexti = 0;
801 rx_desc->rx_ctrl = MWL8K_RX_CTRL_OWNED_BY_HOST; 975 next_dma_addr = rxq->rxd_dma + (nexti * desc_size);
976
977 priv->rxd_ops->rxd_init(rxd, next_dma_addr);
802 } 978 }
803 979
804 return 0; 980 return 0;
@@ -811,27 +987,28 @@ static int rxq_refill(struct ieee80211_hw *hw, int index, int limit)
811 int refilled; 987 int refilled;
812 988
813 refilled = 0; 989 refilled = 0;
814 while (rxq->rx_desc_count < MWL8K_RX_DESCS && limit--) { 990 while (rxq->rxd_count < MWL8K_RX_DESCS && limit--) {
815 struct sk_buff *skb; 991 struct sk_buff *skb;
992 dma_addr_t addr;
816 int rx; 993 int rx;
994 void *rxd;
817 995
818 skb = dev_alloc_skb(MWL8K_RX_MAXSZ); 996 skb = dev_alloc_skb(MWL8K_RX_MAXSZ);
819 if (skb == NULL) 997 if (skb == NULL)
820 break; 998 break;
821 999
822 rxq->rx_desc_count++; 1000 addr = pci_map_single(priv->pdev, skb->data,
823 1001 MWL8K_RX_MAXSZ, DMA_FROM_DEVICE);
824 rx = rxq->rx_tail;
825 rxq->rx_tail = (rx + 1) % MWL8K_RX_DESCS;
826 1002
827 rxq->rx_desc_area[rx].pkt_phys_addr = 1003 rxq->rxd_count++;
828 cpu_to_le32(pci_map_single(priv->pdev, skb->data, 1004 rx = rxq->tail++;
829 MWL8K_RX_MAXSZ, DMA_FROM_DEVICE)); 1005 if (rxq->tail == MWL8K_RX_DESCS)
1006 rxq->tail = 0;
1007 rxq->buf[rx].skb = skb;
1008 pci_unmap_addr_set(&rxq->buf[rx], dma, addr);
830 1009
831 rxq->rx_desc_area[rx].pkt_len = cpu_to_le16(MWL8K_RX_MAXSZ); 1010 rxd = rxq->rxd + (rx * priv->rxd_ops->rxd_size);
832 rxq->rx_skb[rx] = skb; 1011 priv->rxd_ops->rxd_refill(rxd, addr, MWL8K_RX_MAXSZ);
833 wmb();
834 rxq->rx_desc_area[rx].rx_ctrl = 0;
835 1012
836 refilled++; 1013 refilled++;
837 } 1014 }
@@ -847,24 +1024,24 @@ static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index)
847 int i; 1024 int i;
848 1025
849 for (i = 0; i < MWL8K_RX_DESCS; i++) { 1026 for (i = 0; i < MWL8K_RX_DESCS; i++) {
850 if (rxq->rx_skb[i] != NULL) { 1027 if (rxq->buf[i].skb != NULL) {
851 unsigned long addr; 1028 pci_unmap_single(priv->pdev,
852 1029 pci_unmap_addr(&rxq->buf[i], dma),
853 addr = le32_to_cpu(rxq->rx_desc_area[i].pkt_phys_addr); 1030 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
854 pci_unmap_single(priv->pdev, addr, MWL8K_RX_MAXSZ, 1031 pci_unmap_addr_set(&rxq->buf[i], dma, 0);
855 PCI_DMA_FROMDEVICE); 1032
856 kfree_skb(rxq->rx_skb[i]); 1033 kfree_skb(rxq->buf[i].skb);
857 rxq->rx_skb[i] = NULL; 1034 rxq->buf[i].skb = NULL;
858 } 1035 }
859 } 1036 }
860 1037
861 kfree(rxq->rx_skb); 1038 kfree(rxq->buf);
862 rxq->rx_skb = NULL; 1039 rxq->buf = NULL;
863 1040
864 pci_free_consistent(priv->pdev, 1041 pci_free_consistent(priv->pdev,
865 MWL8K_RX_DESCS * sizeof(struct mwl8k_rx_desc), 1042 MWL8K_RX_DESCS * priv->rxd_ops->rxd_size,
866 rxq->rx_desc_area, rxq->rx_desc_dma); 1043 rxq->rxd, rxq->rxd_dma);
867 rxq->rx_desc_area = NULL; 1044 rxq->rxd = NULL;
868} 1045}
869 1046
870 1047
@@ -880,9 +1057,11 @@ mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh)
880 !compare_ether_addr(wh->addr3, priv->capture_bssid); 1057 !compare_ether_addr(wh->addr3, priv->capture_bssid);
881} 1058}
882 1059
883static inline void mwl8k_save_beacon(struct mwl8k_priv *priv, 1060static inline void mwl8k_save_beacon(struct ieee80211_hw *hw,
884 struct sk_buff *skb) 1061 struct sk_buff *skb)
885{ 1062{
1063 struct mwl8k_priv *priv = hw->priv;
1064
886 priv->capture_beacon = false; 1065 priv->capture_beacon = false;
887 memset(priv->capture_bssid, 0, ETH_ALEN); 1066 memset(priv->capture_bssid, 0, ETH_ALEN);
888 1067
@@ -893,8 +1072,7 @@ static inline void mwl8k_save_beacon(struct mwl8k_priv *priv,
893 */ 1072 */
894 priv->beacon_skb = skb_copy(skb, GFP_ATOMIC); 1073 priv->beacon_skb = skb_copy(skb, GFP_ATOMIC);
895 if (priv->beacon_skb != NULL) 1074 if (priv->beacon_skb != NULL)
896 queue_work(priv->config_wq, 1075 ieee80211_queue_work(hw, &priv->finalize_join_worker);
897 &priv->finalize_join_worker);
898} 1076}
899 1077
900static int rxq_process(struct ieee80211_hw *hw, int index, int limit) 1078static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
@@ -904,53 +1082,46 @@ static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
904 int processed; 1082 int processed;
905 1083
906 processed = 0; 1084 processed = 0;
907 while (rxq->rx_desc_count && limit--) { 1085 while (rxq->rxd_count && limit--) {
908 struct mwl8k_rx_desc *rx_desc;
909 struct sk_buff *skb; 1086 struct sk_buff *skb;
1087 void *rxd;
1088 int pkt_len;
910 struct ieee80211_rx_status status; 1089 struct ieee80211_rx_status status;
911 unsigned long addr;
912 struct ieee80211_hdr *wh;
913 1090
914 rx_desc = rxq->rx_desc_area + rxq->rx_head; 1091 skb = rxq->buf[rxq->head].skb;
915 if (!(rx_desc->rx_ctrl & MWL8K_RX_CTRL_OWNED_BY_HOST)) 1092 if (skb == NULL)
916 break; 1093 break;
917 rmb();
918 1094
919 skb = rxq->rx_skb[rxq->rx_head]; 1095 rxd = rxq->rxd + (rxq->head * priv->rxd_ops->rxd_size);
920 if (skb == NULL) 1096
1097 pkt_len = priv->rxd_ops->rxd_process(rxd, &status);
1098 if (pkt_len < 0)
921 break; 1099 break;
922 rxq->rx_skb[rxq->rx_head] = NULL;
923 1100
924 rxq->rx_head = (rxq->rx_head + 1) % MWL8K_RX_DESCS; 1101 rxq->buf[rxq->head].skb = NULL;
925 rxq->rx_desc_count--;
926 1102
927 addr = le32_to_cpu(rx_desc->pkt_phys_addr); 1103 pci_unmap_single(priv->pdev,
928 pci_unmap_single(priv->pdev, addr, 1104 pci_unmap_addr(&rxq->buf[rxq->head], dma),
929 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE); 1105 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
1106 pci_unmap_addr_set(&rxq->buf[rxq->head], dma, 0);
930 1107
931 skb_put(skb, le16_to_cpu(rx_desc->pkt_len)); 1108 rxq->head++;
932 mwl8k_remove_dma_header(skb); 1109 if (rxq->head == MWL8K_RX_DESCS)
1110 rxq->head = 0;
1111
1112 rxq->rxd_count--;
933 1113
934 wh = (struct ieee80211_hdr *)skb->data; 1114 skb_put(skb, pkt_len);
1115 mwl8k_remove_dma_header(skb);
935 1116
936 /* 1117 /*
937 * Check for pending join operation. save a copy of 1118 * Check for a pending join operation. Save a
938 * the beacon and schedule a tasklet to send finalize 1119 * copy of the beacon and schedule a tasklet to
939 * join command to the firmware. 1120 * send a FINALIZE_JOIN command to the firmware.
940 */ 1121 */
941 if (mwl8k_capture_bssid(priv, wh)) 1122 if (mwl8k_capture_bssid(priv, (void *)skb->data))
942 mwl8k_save_beacon(priv, skb); 1123 mwl8k_save_beacon(hw, skb);
943 1124
944 memset(&status, 0, sizeof(status));
945 status.mactime = 0;
946 status.signal = -rx_desc->rssi;
947 status.noise = -rx_desc->noise_level;
948 status.qual = rx_desc->link_quality;
949 status.antenna = 1;
950 status.rate_idx = 1;
951 status.flag = 0;
952 status.band = IEEE80211_BAND_2GHZ;
953 status.freq = ieee80211_channel_to_frequency(rx_desc->channel);
954 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status)); 1125 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
955 ieee80211_rx_irqsafe(hw, skb); 1126 ieee80211_rx_irqsafe(hw, skb);
956 1127
@@ -965,24 +1136,10 @@ static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
965 * Packet transmission. 1136 * Packet transmission.
966 */ 1137 */
967 1138
968/* Transmit queue assignment. */
969enum {
970 MWL8K_WME_AC_BK = 0, /* background access */
971 MWL8K_WME_AC_BE = 1, /* best effort access */
972 MWL8K_WME_AC_VI = 2, /* video access */
973 MWL8K_WME_AC_VO = 3, /* voice access */
974};
975
976/* Transmit packet ACK policy */ 1139/* Transmit packet ACK policy */
977#define MWL8K_TXD_ACK_POLICY_NORMAL 0 1140#define MWL8K_TXD_ACK_POLICY_NORMAL 0
978#define MWL8K_TXD_ACK_POLICY_BLOCKACK 3 1141#define MWL8K_TXD_ACK_POLICY_BLOCKACK 3
979 1142
980#define GET_TXQ(_ac) (\
981 ((_ac) == WME_AC_VO) ? MWL8K_WME_AC_VO : \
982 ((_ac) == WME_AC_VI) ? MWL8K_WME_AC_VI : \
983 ((_ac) == WME_AC_BK) ? MWL8K_WME_AC_BK : \
984 MWL8K_WME_AC_BE)
985
986#define MWL8K_TXD_STATUS_OK 0x00000001 1143#define MWL8K_TXD_STATUS_OK 0x00000001
987#define MWL8K_TXD_STATUS_OK_RETRY 0x00000002 1144#define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
988#define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004 1145#define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
@@ -997,7 +1154,7 @@ struct mwl8k_tx_desc {
997 __le32 pkt_phys_addr; 1154 __le32 pkt_phys_addr;
998 __le16 pkt_len; 1155 __le16 pkt_len;
999 __u8 dest_MAC_addr[ETH_ALEN]; 1156 __u8 dest_MAC_addr[ETH_ALEN];
1000 __le32 next_tx_desc_phys_addr; 1157 __le32 next_txd_phys_addr;
1001 __le32 reserved; 1158 __le32 reserved;
1002 __le16 rate_info; 1159 __le16 rate_info;
1003 __u8 peer_id; 1160 __u8 peer_id;
@@ -1013,44 +1170,40 @@ static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
1013 int size; 1170 int size;
1014 int i; 1171 int i;
1015 1172
1016 memset(&txq->tx_stats, 0, sizeof(struct ieee80211_tx_queue_stats)); 1173 memset(&txq->stats, 0, sizeof(struct ieee80211_tx_queue_stats));
1017 txq->tx_stats.limit = MWL8K_TX_DESCS; 1174 txq->stats.limit = MWL8K_TX_DESCS;
1018 txq->tx_head = 0; 1175 txq->head = 0;
1019 txq->tx_tail = 0; 1176 txq->tail = 0;
1020 1177
1021 size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc); 1178 size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc);
1022 1179
1023 txq->tx_desc_area = 1180 txq->txd = pci_alloc_consistent(priv->pdev, size, &txq->txd_dma);
1024 pci_alloc_consistent(priv->pdev, size, &txq->tx_desc_dma); 1181 if (txq->txd == NULL) {
1025 if (txq->tx_desc_area == NULL) {
1026 printk(KERN_ERR "%s: failed to alloc TX descriptors\n", 1182 printk(KERN_ERR "%s: failed to alloc TX descriptors\n",
1027 priv->name); 1183 wiphy_name(hw->wiphy));
1028 return -ENOMEM; 1184 return -ENOMEM;
1029 } 1185 }
1030 memset(txq->tx_desc_area, 0, size); 1186 memset(txq->txd, 0, size);
1031 1187
1032 txq->tx_skb = kmalloc(MWL8K_TX_DESCS * sizeof(*txq->tx_skb), 1188 txq->skb = kmalloc(MWL8K_TX_DESCS * sizeof(*txq->skb), GFP_KERNEL);
1033 GFP_KERNEL); 1189 if (txq->skb == NULL) {
1034 if (txq->tx_skb == NULL) {
1035 printk(KERN_ERR "%s: failed to alloc TX skbuff list\n", 1190 printk(KERN_ERR "%s: failed to alloc TX skbuff list\n",
1036 priv->name); 1191 wiphy_name(hw->wiphy));
1037 pci_free_consistent(priv->pdev, size, 1192 pci_free_consistent(priv->pdev, size, txq->txd, txq->txd_dma);
1038 txq->tx_desc_area, txq->tx_desc_dma);
1039 return -ENOMEM; 1193 return -ENOMEM;
1040 } 1194 }
1041 memset(txq->tx_skb, 0, MWL8K_TX_DESCS * sizeof(*txq->tx_skb)); 1195 memset(txq->skb, 0, MWL8K_TX_DESCS * sizeof(*txq->skb));
1042 1196
1043 for (i = 0; i < MWL8K_TX_DESCS; i++) { 1197 for (i = 0; i < MWL8K_TX_DESCS; i++) {
1044 struct mwl8k_tx_desc *tx_desc; 1198 struct mwl8k_tx_desc *tx_desc;
1045 int nexti; 1199 int nexti;
1046 1200
1047 tx_desc = txq->tx_desc_area + i; 1201 tx_desc = txq->txd + i;
1048 nexti = (i + 1) % MWL8K_TX_DESCS; 1202 nexti = (i + 1) % MWL8K_TX_DESCS;
1049 1203
1050 tx_desc->status = 0; 1204 tx_desc->status = 0;
1051 tx_desc->next_tx_desc_phys_addr = 1205 tx_desc->next_txd_phys_addr =
1052 cpu_to_le32(txq->tx_desc_dma + 1206 cpu_to_le32(txq->txd_dma + nexti * sizeof(*tx_desc));
1053 nexti * sizeof(*tx_desc));
1054 } 1207 }
1055 1208
1056 return 0; 1209 return 0;
@@ -1065,11 +1218,6 @@ static inline void mwl8k_tx_start(struct mwl8k_priv *priv)
1065 ioread32(priv->regs + MWL8K_HIU_INT_CODE); 1218 ioread32(priv->regs + MWL8K_HIU_INT_CODE);
1066} 1219}
1067 1220
1068static inline int mwl8k_txq_busy(struct mwl8k_priv *priv)
1069{
1070 return priv->pending_tx_pkts;
1071}
1072
1073struct mwl8k_txq_info { 1221struct mwl8k_txq_info {
1074 u32 fw_owned; 1222 u32 fw_owned;
1075 u32 drv_owned; 1223 u32 drv_owned;
@@ -1089,14 +1237,13 @@ static int mwl8k_scan_tx_ring(struct mwl8k_priv *priv,
1089 1237
1090 memset(txinfo, 0, MWL8K_TX_QUEUES * sizeof(struct mwl8k_txq_info)); 1238 memset(txinfo, 0, MWL8K_TX_QUEUES * sizeof(struct mwl8k_txq_info));
1091 1239
1092 spin_lock_bh(&priv->tx_lock);
1093 for (count = 0; count < MWL8K_TX_QUEUES; count++) { 1240 for (count = 0; count < MWL8K_TX_QUEUES; count++) {
1094 txq = priv->txq + count; 1241 txq = priv->txq + count;
1095 txinfo[count].len = txq->tx_stats.len; 1242 txinfo[count].len = txq->stats.len;
1096 txinfo[count].head = txq->tx_head; 1243 txinfo[count].head = txq->head;
1097 txinfo[count].tail = txq->tx_tail; 1244 txinfo[count].tail = txq->tail;
1098 for (desc = 0; desc < MWL8K_TX_DESCS; desc++) { 1245 for (desc = 0; desc < MWL8K_TX_DESCS; desc++) {
1099 tx_desc = txq->tx_desc_area + desc; 1246 tx_desc = txq->txd + desc;
1100 status = le32_to_cpu(tx_desc->status); 1247 status = le32_to_cpu(tx_desc->status);
1101 1248
1102 if (status & MWL8K_TXD_STATUS_FW_OWNED) 1249 if (status & MWL8K_TXD_STATUS_FW_OWNED)
@@ -1108,30 +1255,26 @@ static int mwl8k_scan_tx_ring(struct mwl8k_priv *priv,
1108 txinfo[count].unused++; 1255 txinfo[count].unused++;
1109 } 1256 }
1110 } 1257 }
1111 spin_unlock_bh(&priv->tx_lock);
1112 1258
1113 return ndescs; 1259 return ndescs;
1114} 1260}
1115 1261
1116/* 1262/*
1117 * Must be called with hw->fw_mutex held and tx queues stopped. 1263 * Must be called with priv->fw_mutex held and tx queues stopped.
1118 */ 1264 */
1119static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw) 1265static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw)
1120{ 1266{
1121 struct mwl8k_priv *priv = hw->priv; 1267 struct mwl8k_priv *priv = hw->priv;
1122 DECLARE_COMPLETION_ONSTACK(cmd_wait); 1268 DECLARE_COMPLETION_ONSTACK(tx_wait);
1123 u32 count; 1269 u32 count;
1124 unsigned long timeout; 1270 unsigned long timeout;
1125 1271
1126 might_sleep(); 1272 might_sleep();
1127 1273
1128 spin_lock_bh(&priv->tx_lock); 1274 spin_lock_bh(&priv->tx_lock);
1129 count = mwl8k_txq_busy(priv); 1275 count = priv->pending_tx_pkts;
1130 if (count) { 1276 if (count)
1131 priv->tx_wait = &cmd_wait; 1277 priv->tx_wait = &tx_wait;
1132 if (priv->radio_on)
1133 mwl8k_tx_start(priv);
1134 }
1135 spin_unlock_bh(&priv->tx_lock); 1278 spin_unlock_bh(&priv->tx_lock);
1136 1279
1137 if (count) { 1280 if (count) {
@@ -1139,23 +1282,23 @@ static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw)
1139 int index; 1282 int index;
1140 int newcount; 1283 int newcount;
1141 1284
1142 timeout = wait_for_completion_timeout(&cmd_wait, 1285 timeout = wait_for_completion_timeout(&tx_wait,
1143 msecs_to_jiffies(5000)); 1286 msecs_to_jiffies(5000));
1144 if (timeout) 1287 if (timeout)
1145 return 0; 1288 return 0;
1146 1289
1147 spin_lock_bh(&priv->tx_lock); 1290 spin_lock_bh(&priv->tx_lock);
1148 priv->tx_wait = NULL; 1291 priv->tx_wait = NULL;
1149 newcount = mwl8k_txq_busy(priv); 1292 newcount = priv->pending_tx_pkts;
1293 mwl8k_scan_tx_ring(priv, txinfo);
1150 spin_unlock_bh(&priv->tx_lock); 1294 spin_unlock_bh(&priv->tx_lock);
1151 1295
1152 printk(KERN_ERR "%s(%u) TIMEDOUT:5000ms Pend:%u-->%u\n", 1296 printk(KERN_ERR "%s(%u) TIMEDOUT:5000ms Pend:%u-->%u\n",
1153 __func__, __LINE__, count, newcount); 1297 __func__, __LINE__, count, newcount);
1154 1298
1155 mwl8k_scan_tx_ring(priv, txinfo);
1156 for (index = 0; index < MWL8K_TX_QUEUES; index++) 1299 for (index = 0; index < MWL8K_TX_QUEUES; index++)
1157 printk(KERN_ERR 1300 printk(KERN_ERR "TXQ:%u L:%u H:%u T:%u FW:%u "
1158 "TXQ:%u L:%u H:%u T:%u FW:%u DRV:%u U:%u\n", 1301 "DRV:%u U:%u\n",
1159 index, 1302 index,
1160 txinfo[index].len, 1303 txinfo[index].len,
1161 txinfo[index].head, 1304 txinfo[index].head,
@@ -1181,7 +1324,7 @@ static void mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int force)
1181 struct mwl8k_tx_queue *txq = priv->txq + index; 1324 struct mwl8k_tx_queue *txq = priv->txq + index;
1182 int wake = 0; 1325 int wake = 0;
1183 1326
1184 while (txq->tx_stats.len > 0) { 1327 while (txq->stats.len > 0) {
1185 int tx; 1328 int tx;
1186 struct mwl8k_tx_desc *tx_desc; 1329 struct mwl8k_tx_desc *tx_desc;
1187 unsigned long addr; 1330 unsigned long addr;
@@ -1190,8 +1333,8 @@ static void mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int force)
1190 struct ieee80211_tx_info *info; 1333 struct ieee80211_tx_info *info;
1191 u32 status; 1334 u32 status;
1192 1335
1193 tx = txq->tx_head; 1336 tx = txq->head;
1194 tx_desc = txq->tx_desc_area + tx; 1337 tx_desc = txq->txd + tx;
1195 1338
1196 status = le32_to_cpu(tx_desc->status); 1339 status = le32_to_cpu(tx_desc->status);
1197 1340
@@ -1202,15 +1345,15 @@ static void mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int force)
1202 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED); 1345 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED);
1203 } 1346 }
1204 1347
1205 txq->tx_head = (tx + 1) % MWL8K_TX_DESCS; 1348 txq->head = (tx + 1) % MWL8K_TX_DESCS;
1206 BUG_ON(txq->tx_stats.len == 0); 1349 BUG_ON(txq->stats.len == 0);
1207 txq->tx_stats.len--; 1350 txq->stats.len--;
1208 priv->pending_tx_pkts--; 1351 priv->pending_tx_pkts--;
1209 1352
1210 addr = le32_to_cpu(tx_desc->pkt_phys_addr); 1353 addr = le32_to_cpu(tx_desc->pkt_phys_addr);
1211 size = le16_to_cpu(tx_desc->pkt_len); 1354 size = le16_to_cpu(tx_desc->pkt_len);
1212 skb = txq->tx_skb[tx]; 1355 skb = txq->skb[tx];
1213 txq->tx_skb[tx] = NULL; 1356 txq->skb[tx] = NULL;
1214 1357
1215 BUG_ON(skb == NULL); 1358 BUG_ON(skb == NULL);
1216 pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE); 1359 pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE);
@@ -1243,13 +1386,13 @@ static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
1243 1386
1244 mwl8k_txq_reclaim(hw, index, 1); 1387 mwl8k_txq_reclaim(hw, index, 1);
1245 1388
1246 kfree(txq->tx_skb); 1389 kfree(txq->skb);
1247 txq->tx_skb = NULL; 1390 txq->skb = NULL;
1248 1391
1249 pci_free_consistent(priv->pdev, 1392 pci_free_consistent(priv->pdev,
1250 MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc), 1393 MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc),
1251 txq->tx_desc_area, txq->tx_desc_dma); 1394 txq->txd, txq->txd_dma);
1252 txq->tx_desc_area = NULL; 1395 txq->txd = NULL;
1253} 1396}
1254 1397
1255static int 1398static int
@@ -1317,7 +1460,7 @@ mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
1317 1460
1318 if (pci_dma_mapping_error(priv->pdev, dma)) { 1461 if (pci_dma_mapping_error(priv->pdev, dma)) {
1319 printk(KERN_DEBUG "%s: failed to dma map skb, " 1462 printk(KERN_DEBUG "%s: failed to dma map skb, "
1320 "dropping TX frame.\n", priv->name); 1463 "dropping TX frame.\n", wiphy_name(hw->wiphy));
1321 dev_kfree_skb(skb); 1464 dev_kfree_skb(skb);
1322 return NETDEV_TX_OK; 1465 return NETDEV_TX_OK;
1323 } 1466 }
@@ -1326,10 +1469,10 @@ mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
1326 1469
1327 txq = priv->txq + index; 1470 txq = priv->txq + index;
1328 1471
1329 BUG_ON(txq->tx_skb[txq->tx_tail] != NULL); 1472 BUG_ON(txq->skb[txq->tail] != NULL);
1330 txq->tx_skb[txq->tx_tail] = skb; 1473 txq->skb[txq->tail] = skb;
1331 1474
1332 tx = txq->tx_desc_area + txq->tx_tail; 1475 tx = txq->txd + txq->tail;
1333 tx->data_rate = txdatarate; 1476 tx->data_rate = txdatarate;
1334 tx->tx_priority = index; 1477 tx->tx_priority = index;
1335 tx->qos_control = cpu_to_le16(qos); 1478 tx->qos_control = cpu_to_le16(qos);
@@ -1340,15 +1483,15 @@ mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
1340 wmb(); 1483 wmb();
1341 tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus); 1484 tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus);
1342 1485
1343 txq->tx_stats.count++; 1486 txq->stats.count++;
1344 txq->tx_stats.len++; 1487 txq->stats.len++;
1345 priv->pending_tx_pkts++; 1488 priv->pending_tx_pkts++;
1346 1489
1347 txq->tx_tail++; 1490 txq->tail++;
1348 if (txq->tx_tail == MWL8K_TX_DESCS) 1491 if (txq->tail == MWL8K_TX_DESCS)
1349 txq->tx_tail = 0; 1492 txq->tail = 0;
1350 1493
1351 if (txq->tx_head == txq->tx_tail) 1494 if (txq->head == txq->tail)
1352 ieee80211_stop_queue(hw, index); 1495 ieee80211_stop_queue(hw, index);
1353 1496
1354 mwl8k_tx_start(priv); 1497 mwl8k_tx_start(priv);
@@ -1431,7 +1574,7 @@ static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
1431 unsigned long timeout = 0; 1574 unsigned long timeout = 0;
1432 u8 buf[32]; 1575 u8 buf[32];
1433 1576
1434 cmd->result = 0xFFFF; 1577 cmd->result = 0xffff;
1435 dma_size = le16_to_cpu(cmd->length); 1578 dma_size = le16_to_cpu(cmd->length);
1436 dma_addr = pci_map_single(priv->pdev, cmd, dma_size, 1579 dma_addr = pci_map_single(priv->pdev, cmd, dma_size,
1437 PCI_DMA_BIDIRECTIONAL); 1580 PCI_DMA_BIDIRECTIONAL);
@@ -1464,7 +1607,7 @@ static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
1464 1607
1465 if (!timeout) { 1608 if (!timeout) {
1466 printk(KERN_ERR "%s: Command %s timeout after %u ms\n", 1609 printk(KERN_ERR "%s: Command %s timeout after %u ms\n",
1467 priv->name, 1610 wiphy_name(hw->wiphy),
1468 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)), 1611 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1469 MWL8K_CMD_TIMEOUT_MS); 1612 MWL8K_CMD_TIMEOUT_MS);
1470 rc = -ETIMEDOUT; 1613 rc = -ETIMEDOUT;
@@ -1472,7 +1615,7 @@ static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
1472 rc = cmd->result ? -EINVAL : 0; 1615 rc = cmd->result ? -EINVAL : 0;
1473 if (rc) 1616 if (rc)
1474 printk(KERN_ERR "%s: Command %s error 0x%x\n", 1617 printk(KERN_ERR "%s: Command %s error 0x%x\n",
1475 priv->name, 1618 wiphy_name(hw->wiphy),
1476 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)), 1619 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1477 le16_to_cpu(cmd->result)); 1620 le16_to_cpu(cmd->result));
1478 } 1621 }
@@ -1481,9 +1624,9 @@ static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
1481} 1624}
1482 1625
1483/* 1626/*
1484 * GET_HW_SPEC. 1627 * CMD_GET_HW_SPEC (STA version).
1485 */ 1628 */
1486struct mwl8k_cmd_get_hw_spec { 1629struct mwl8k_cmd_get_hw_spec_sta {
1487 struct mwl8k_cmd_pkt header; 1630 struct mwl8k_cmd_pkt header;
1488 __u8 hw_rev; 1631 __u8 hw_rev;
1489 __u8 host_interface; 1632 __u8 host_interface;
@@ -1499,13 +1642,13 @@ struct mwl8k_cmd_get_hw_spec {
1499 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES]; 1642 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1500 __le32 caps2; 1643 __le32 caps2;
1501 __le32 num_tx_desc_per_queue; 1644 __le32 num_tx_desc_per_queue;
1502 __le32 total_rx_desc; 1645 __le32 total_rxd;
1503} __attribute__((packed)); 1646} __attribute__((packed));
1504 1647
1505static int mwl8k_cmd_get_hw_spec(struct ieee80211_hw *hw) 1648static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw *hw)
1506{ 1649{
1507 struct mwl8k_priv *priv = hw->priv; 1650 struct mwl8k_priv *priv = hw->priv;
1508 struct mwl8k_cmd_get_hw_spec *cmd; 1651 struct mwl8k_cmd_get_hw_spec_sta *cmd;
1509 int rc; 1652 int rc;
1510 int i; 1653 int i;
1511 1654
@@ -1518,12 +1661,12 @@ static int mwl8k_cmd_get_hw_spec(struct ieee80211_hw *hw)
1518 1661
1519 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr)); 1662 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1520 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma); 1663 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1521 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rx_desc_dma); 1664 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
1522 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES); 1665 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
1523 for (i = 0; i < MWL8K_TX_QUEUES; i++) 1666 for (i = 0; i < MWL8K_TX_QUEUES; i++)
1524 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].tx_desc_dma); 1667 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
1525 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS); 1668 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
1526 cmd->total_rx_desc = cpu_to_le32(MWL8K_RX_DESCS); 1669 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
1527 1670
1528 rc = mwl8k_post_cmd(hw, &cmd->header); 1671 rc = mwl8k_post_cmd(hw, &cmd->header);
1529 1672
@@ -1539,6 +1682,129 @@ static int mwl8k_cmd_get_hw_spec(struct ieee80211_hw *hw)
1539} 1682}
1540 1683
1541/* 1684/*
1685 * CMD_GET_HW_SPEC (AP version).
1686 */
1687struct mwl8k_cmd_get_hw_spec_ap {
1688 struct mwl8k_cmd_pkt header;
1689 __u8 hw_rev;
1690 __u8 host_interface;
1691 __le16 num_wcb;
1692 __le16 num_mcaddrs;
1693 __u8 perm_addr[ETH_ALEN];
1694 __le16 region_code;
1695 __le16 num_antenna;
1696 __le32 fw_rev;
1697 __le32 wcbbase0;
1698 __le32 rxwrptr;
1699 __le32 rxrdptr;
1700 __le32 ps_cookie;
1701 __le32 wcbbase1;
1702 __le32 wcbbase2;
1703 __le32 wcbbase3;
1704} __attribute__((packed));
1705
1706static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw *hw)
1707{
1708 struct mwl8k_priv *priv = hw->priv;
1709 struct mwl8k_cmd_get_hw_spec_ap *cmd;
1710 int rc;
1711
1712 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1713 if (cmd == NULL)
1714 return -ENOMEM;
1715
1716 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1717 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1718
1719 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1720 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1721
1722 rc = mwl8k_post_cmd(hw, &cmd->header);
1723
1724 if (!rc) {
1725 int off;
1726
1727 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1728 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
1729 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
1730 priv->hw_rev = cmd->hw_rev;
1731
1732 off = le32_to_cpu(cmd->wcbbase0) & 0xffff;
1733 iowrite32(cpu_to_le32(priv->txq[0].txd_dma), priv->sram + off);
1734
1735 off = le32_to_cpu(cmd->rxwrptr) & 0xffff;
1736 iowrite32(cpu_to_le32(priv->rxq[0].rxd_dma), priv->sram + off);
1737
1738 off = le32_to_cpu(cmd->rxrdptr) & 0xffff;
1739 iowrite32(cpu_to_le32(priv->rxq[0].rxd_dma), priv->sram + off);
1740
1741 off = le32_to_cpu(cmd->wcbbase1) & 0xffff;
1742 iowrite32(cpu_to_le32(priv->txq[1].txd_dma), priv->sram + off);
1743
1744 off = le32_to_cpu(cmd->wcbbase2) & 0xffff;
1745 iowrite32(cpu_to_le32(priv->txq[2].txd_dma), priv->sram + off);
1746
1747 off = le32_to_cpu(cmd->wcbbase3) & 0xffff;
1748 iowrite32(cpu_to_le32(priv->txq[3].txd_dma), priv->sram + off);
1749 }
1750
1751 kfree(cmd);
1752 return rc;
1753}
1754
1755/*
1756 * CMD_SET_HW_SPEC.
1757 */
1758struct mwl8k_cmd_set_hw_spec {
1759 struct mwl8k_cmd_pkt header;
1760 __u8 hw_rev;
1761 __u8 host_interface;
1762 __le16 num_mcaddrs;
1763 __u8 perm_addr[ETH_ALEN];
1764 __le16 region_code;
1765 __le32 fw_rev;
1766 __le32 ps_cookie;
1767 __le32 caps;
1768 __le32 rx_queue_ptr;
1769 __le32 num_tx_queues;
1770 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1771 __le32 flags;
1772 __le32 num_tx_desc_per_queue;
1773 __le32 total_rxd;
1774} __attribute__((packed));
1775
1776#define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080
1777
1778static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw *hw)
1779{
1780 struct mwl8k_priv *priv = hw->priv;
1781 struct mwl8k_cmd_set_hw_spec *cmd;
1782 int rc;
1783 int i;
1784
1785 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1786 if (cmd == NULL)
1787 return -ENOMEM;
1788
1789 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_HW_SPEC);
1790 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1791
1792 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1793 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
1794 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
1795 for (i = 0; i < MWL8K_TX_QUEUES; i++)
1796 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
1797 cmd->flags = cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT);
1798 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
1799 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
1800
1801 rc = mwl8k_post_cmd(hw, &cmd->header);
1802 kfree(cmd);
1803
1804 return rc;
1805}
1806
1807/*
1542 * CMD_MAC_MULTICAST_ADR. 1808 * CMD_MAC_MULTICAST_ADR.
1543 */ 1809 */
1544struct mwl8k_cmd_mac_multicast_adr { 1810struct mwl8k_cmd_mac_multicast_adr {
@@ -1548,19 +1814,23 @@ struct mwl8k_cmd_mac_multicast_adr {
1548 __u8 addr[0][ETH_ALEN]; 1814 __u8 addr[0][ETH_ALEN];
1549}; 1815};
1550 1816
1551#define MWL8K_ENABLE_RX_MULTICAST 0x000F 1817#define MWL8K_ENABLE_RX_DIRECTED 0x0001
1818#define MWL8K_ENABLE_RX_MULTICAST 0x0002
1819#define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004
1820#define MWL8K_ENABLE_RX_BROADCAST 0x0008
1552 1821
1553static struct mwl8k_cmd_pkt * 1822static struct mwl8k_cmd_pkt *
1554__mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw, 1823__mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw, int allmulti,
1555 int mc_count, struct dev_addr_list *mclist) 1824 int mc_count, struct dev_addr_list *mclist)
1556{ 1825{
1557 struct mwl8k_priv *priv = hw->priv; 1826 struct mwl8k_priv *priv = hw->priv;
1558 struct mwl8k_cmd_mac_multicast_adr *cmd; 1827 struct mwl8k_cmd_mac_multicast_adr *cmd;
1559 int size; 1828 int size;
1560 int i;
1561 1829
1562 if (mc_count > priv->num_mcaddrs) 1830 if (allmulti || mc_count > priv->num_mcaddrs) {
1563 mc_count = priv->num_mcaddrs; 1831 allmulti = 1;
1832 mc_count = 0;
1833 }
1564 1834
1565 size = sizeof(*cmd) + mc_count * ETH_ALEN; 1835 size = sizeof(*cmd) + mc_count * ETH_ALEN;
1566 1836
@@ -1570,16 +1840,24 @@ __mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw,
1570 1840
1571 cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR); 1841 cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR);
1572 cmd->header.length = cpu_to_le16(size); 1842 cmd->header.length = cpu_to_le16(size);
1573 cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST); 1843 cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED |
1574 cmd->numaddr = cpu_to_le16(mc_count); 1844 MWL8K_ENABLE_RX_BROADCAST);
1575 1845
1576 for (i = 0; i < mc_count && mclist; i++) { 1846 if (allmulti) {
1577 if (mclist->da_addrlen != ETH_ALEN) { 1847 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST);
1578 kfree(cmd); 1848 } else if (mc_count) {
1579 return NULL; 1849 int i;
1850
1851 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST);
1852 cmd->numaddr = cpu_to_le16(mc_count);
1853 for (i = 0; i < mc_count && mclist; i++) {
1854 if (mclist->da_addrlen != ETH_ALEN) {
1855 kfree(cmd);
1856 return NULL;
1857 }
1858 memcpy(cmd->addr[i], mclist->da_addr, ETH_ALEN);
1859 mclist = mclist->next;
1580 } 1860 }
1581 memcpy(cmd->addr[i], mclist->da_addr, ETH_ALEN);
1582 mclist = mclist->next;
1583 } 1861 }
1584 1862
1585 return &cmd->header; 1863 return &cmd->header;
@@ -1590,7 +1868,6 @@ __mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw,
1590 */ 1868 */
1591struct mwl8k_cmd_802_11_get_stat { 1869struct mwl8k_cmd_802_11_get_stat {
1592 struct mwl8k_cmd_pkt header; 1870 struct mwl8k_cmd_pkt header;
1593 __le16 action;
1594 __le32 stats[64]; 1871 __le32 stats[64];
1595} __attribute__((packed)); 1872} __attribute__((packed));
1596 1873
@@ -1611,7 +1888,6 @@ static int mwl8k_cmd_802_11_get_stat(struct ieee80211_hw *hw,
1611 1888
1612 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT); 1889 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT);
1613 cmd->header.length = cpu_to_le16(sizeof(*cmd)); 1890 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1614 cmd->action = cpu_to_le16(MWL8K_CMD_GET);
1615 1891
1616 rc = mwl8k_post_cmd(hw, &cmd->header); 1892 rc = mwl8k_post_cmd(hw, &cmd->header);
1617 if (!rc) { 1893 if (!rc) {
@@ -1727,6 +2003,39 @@ static int mwl8k_cmd_802_11_rf_tx_power(struct ieee80211_hw *hw, int dBm)
1727} 2003}
1728 2004
1729/* 2005/*
2006 * CMD_RF_ANTENNA.
2007 */
2008struct mwl8k_cmd_rf_antenna {
2009 struct mwl8k_cmd_pkt header;
2010 __le16 antenna;
2011 __le16 mode;
2012} __attribute__((packed));
2013
2014#define MWL8K_RF_ANTENNA_RX 1
2015#define MWL8K_RF_ANTENNA_TX 2
2016
2017static int
2018mwl8k_cmd_rf_antenna(struct ieee80211_hw *hw, int antenna, int mask)
2019{
2020 struct mwl8k_cmd_rf_antenna *cmd;
2021 int rc;
2022
2023 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2024 if (cmd == NULL)
2025 return -ENOMEM;
2026
2027 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_ANTENNA);
2028 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2029 cmd->antenna = cpu_to_le16(antenna);
2030 cmd->mode = cpu_to_le16(mask);
2031
2032 rc = mwl8k_post_cmd(hw, &cmd->header);
2033 kfree(cmd);
2034
2035 return rc;
2036}
2037
2038/*
1730 * CMD_SET_PRE_SCAN. 2039 * CMD_SET_PRE_SCAN.
1731 */ 2040 */
1732struct mwl8k_cmd_set_pre_scan { 2041struct mwl8k_cmd_set_pre_scan {
@@ -1904,6 +2213,46 @@ static int mwl8k_enable_sniffer(struct ieee80211_hw *hw, bool enable)
1904} 2213}
1905 2214
1906/* 2215/*
2216 * CMD_SET_MAC_ADDR.
2217 */
2218struct mwl8k_cmd_set_mac_addr {
2219 struct mwl8k_cmd_pkt header;
2220 union {
2221 struct {
2222 __le16 mac_type;
2223 __u8 mac_addr[ETH_ALEN];
2224 } mbss;
2225 __u8 mac_addr[ETH_ALEN];
2226 };
2227} __attribute__((packed));
2228
2229static int mwl8k_set_mac_addr(struct ieee80211_hw *hw, u8 *mac)
2230{
2231 struct mwl8k_priv *priv = hw->priv;
2232 struct mwl8k_cmd_set_mac_addr *cmd;
2233 int rc;
2234
2235 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2236 if (cmd == NULL)
2237 return -ENOMEM;
2238
2239 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR);
2240 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2241 if (priv->ap_fw) {
2242 cmd->mbss.mac_type = 0;
2243 memcpy(cmd->mbss.mac_addr, mac, ETH_ALEN);
2244 } else {
2245 memcpy(cmd->mac_addr, mac, ETH_ALEN);
2246 }
2247
2248 rc = mwl8k_post_cmd(hw, &cmd->header);
2249 kfree(cmd);
2250
2251 return rc;
2252}
2253
2254
2255/*
1907 * CMD_SET_RATEADAPT_MODE. 2256 * CMD_SET_RATEADAPT_MODE.
1908 */ 2257 */
1909struct mwl8k_cmd_set_rate_adapt_mode { 2258struct mwl8k_cmd_set_rate_adapt_mode {
@@ -2005,17 +2354,34 @@ struct mwl8k_cmd_set_edca_params {
2005 /* TX opportunity in units of 32 us */ 2354 /* TX opportunity in units of 32 us */
2006 __le16 txop; 2355 __le16 txop;
2007 2356
2008 /* Log exponent of max contention period: 0...15*/ 2357 union {
2009 __u8 log_cw_max; 2358 struct {
2359 /* Log exponent of max contention period: 0...15 */
2360 __le32 log_cw_max;
2361
2362 /* Log exponent of min contention period: 0...15 */
2363 __le32 log_cw_min;
2364
2365 /* Adaptive interframe spacing in units of 32us */
2366 __u8 aifs;
2367
2368 /* TX queue to configure */
2369 __u8 txq;
2370 } ap;
2371 struct {
2372 /* Log exponent of max contention period: 0...15 */
2373 __u8 log_cw_max;
2010 2374
2011 /* Log exponent of min contention period: 0...15 */ 2375 /* Log exponent of min contention period: 0...15 */
2012 __u8 log_cw_min; 2376 __u8 log_cw_min;
2013 2377
2014 /* Adaptive interframe spacing in units of 32us */ 2378 /* Adaptive interframe spacing in units of 32us */
2015 __u8 aifs; 2379 __u8 aifs;
2016 2380
2017 /* TX queue to configure */ 2381 /* TX queue to configure */
2018 __u8 txq; 2382 __u8 txq;
2383 } sta;
2384 };
2019} __attribute__((packed)); 2385} __attribute__((packed));
2020 2386
2021#define MWL8K_SET_EDCA_CW 0x01 2387#define MWL8K_SET_EDCA_CW 0x01
@@ -2031,6 +2397,7 @@ mwl8k_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
2031 __u16 cw_min, __u16 cw_max, 2397 __u16 cw_min, __u16 cw_max,
2032 __u8 aifs, __u16 txop) 2398 __u8 aifs, __u16 txop)
2033{ 2399{
2400 struct mwl8k_priv *priv = hw->priv;
2034 struct mwl8k_cmd_set_edca_params *cmd; 2401 struct mwl8k_cmd_set_edca_params *cmd;
2035 int rc; 2402 int rc;
2036 2403
@@ -2038,14 +2405,27 @@ mwl8k_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
2038 if (cmd == NULL) 2405 if (cmd == NULL)
2039 return -ENOMEM; 2406 return -ENOMEM;
2040 2407
2408 /*
2409 * Queues 0 (BE) and 1 (BK) are swapped in hardware for
2410 * this call.
2411 */
2412 qnum ^= !(qnum >> 1);
2413
2041 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS); 2414 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
2042 cmd->header.length = cpu_to_le16(sizeof(*cmd)); 2415 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2043 cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL); 2416 cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
2044 cmd->txop = cpu_to_le16(txop); 2417 cmd->txop = cpu_to_le16(txop);
2045 cmd->log_cw_max = (u8)ilog2(cw_max + 1); 2418 if (priv->ap_fw) {
2046 cmd->log_cw_min = (u8)ilog2(cw_min + 1); 2419 cmd->ap.log_cw_max = cpu_to_le32(ilog2(cw_max + 1));
2047 cmd->aifs = aifs; 2420 cmd->ap.log_cw_min = cpu_to_le32(ilog2(cw_min + 1));
2048 cmd->txq = qnum; 2421 cmd->ap.aifs = aifs;
2422 cmd->ap.txq = qnum;
2423 } else {
2424 cmd->sta.log_cw_max = (u8)ilog2(cw_max + 1);
2425 cmd->sta.log_cw_min = (u8)ilog2(cw_min + 1);
2426 cmd->sta.aifs = aifs;
2427 cmd->sta.txq = qnum;
2428 }
2049 2429
2050 rc = mwl8k_post_cmd(hw, &cmd->header); 2430 rc = mwl8k_post_cmd(hw, &cmd->header);
2051 kfree(cmd); 2431 kfree(cmd);
@@ -2093,8 +2473,8 @@ static int mwl8k_finalize_join(struct ieee80211_hw *hw, void *frame,
2093 /* XXX TBD Might just have to abort and return an error */ 2473 /* XXX TBD Might just have to abort and return an error */
2094 if (payload_len > MWL8K_FJ_BEACON_MAXLEN) 2474 if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
2095 printk(KERN_ERR "%s(): WARNING: Incomplete beacon " 2475 printk(KERN_ERR "%s(): WARNING: Incomplete beacon "
2096 "sent to firmware. Sz=%u MAX=%u\n", __func__, 2476 "sent to firmware. Sz=%u MAX=%u\n", __func__,
2097 payload_len, MWL8K_FJ_BEACON_MAXLEN); 2477 payload_len, MWL8K_FJ_BEACON_MAXLEN);
2098 2478
2099 if (payload_len > MWL8K_FJ_BEACON_MAXLEN) 2479 if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
2100 payload_len = MWL8K_FJ_BEACON_MAXLEN; 2480 payload_len = MWL8K_FJ_BEACON_MAXLEN;
@@ -2341,9 +2721,10 @@ static int mwl8k_cmd_use_fixed_rate(struct ieee80211_hw *hw,
2341 cmd->rate_type = cpu_to_le32(rate_type); 2721 cmd->rate_type = cpu_to_le32(rate_type);
2342 2722
2343 if (rate_table != NULL) { 2723 if (rate_table != NULL) {
2344 /* Copy over each field manually so 2724 /*
2345 * that bitflipping can be done 2725 * Copy over each field manually so that endian
2346 */ 2726 * conversion can be done.
2727 */
2347 cmd->rate_table.allow_rate_drop = 2728 cmd->rate_table.allow_rate_drop =
2348 cpu_to_le32(rate_table->allow_rate_drop); 2729 cpu_to_le32(rate_table->allow_rate_drop);
2349 cmd->rate_table.num_rates = 2730 cmd->rate_table.num_rates =
@@ -2399,7 +2780,7 @@ static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
2399 2780
2400 if (status & MWL8K_A2H_INT_QUEUE_EMPTY) { 2781 if (status & MWL8K_A2H_INT_QUEUE_EMPTY) {
2401 if (!mutex_is_locked(&priv->fw_mutex) && 2782 if (!mutex_is_locked(&priv->fw_mutex) &&
2402 priv->radio_on && mwl8k_txq_busy(priv)) 2783 priv->radio_on && priv->pending_tx_pkts)
2403 mwl8k_tx_start(priv); 2784 mwl8k_tx_start(priv);
2404 } 2785 }
2405 2786
@@ -2418,7 +2799,7 @@ static int mwl8k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
2418 2799
2419 if (priv->current_channel == NULL) { 2800 if (priv->current_channel == NULL) {
2420 printk(KERN_DEBUG "%s: dropped TX frame since radio " 2801 printk(KERN_DEBUG "%s: dropped TX frame since radio "
2421 "disabled\n", priv->name); 2802 "disabled\n", wiphy_name(hw->wiphy));
2422 dev_kfree_skb(skb); 2803 dev_kfree_skb(skb);
2423 return NETDEV_TX_OK; 2804 return NETDEV_TX_OK;
2424 } 2805 }
@@ -2437,7 +2818,7 @@ static int mwl8k_start(struct ieee80211_hw *hw)
2437 IRQF_SHARED, MWL8K_NAME, hw); 2818 IRQF_SHARED, MWL8K_NAME, hw);
2438 if (rc) { 2819 if (rc) {
2439 printk(KERN_ERR "%s: failed to register IRQ handler\n", 2820 printk(KERN_ERR "%s: failed to register IRQ handler\n",
2440 priv->name); 2821 wiphy_name(hw->wiphy));
2441 return -EIO; 2822 return -EIO;
2442 } 2823 }
2443 2824
@@ -2451,12 +2832,17 @@ static int mwl8k_start(struct ieee80211_hw *hw)
2451 if (!rc) { 2832 if (!rc) {
2452 rc = mwl8k_cmd_802_11_radio_enable(hw); 2833 rc = mwl8k_cmd_802_11_radio_enable(hw);
2453 2834
2454 if (!rc) 2835 if (!priv->ap_fw) {
2455 rc = mwl8k_cmd_set_pre_scan(hw); 2836 if (!rc)
2837 rc = mwl8k_enable_sniffer(hw, 0);
2456 2838
2457 if (!rc) 2839 if (!rc)
2458 rc = mwl8k_cmd_set_post_scan(hw, 2840 rc = mwl8k_cmd_set_pre_scan(hw);
2459 "\x00\x00\x00\x00\x00\x00"); 2841
2842 if (!rc)
2843 rc = mwl8k_cmd_set_post_scan(hw,
2844 "\x00\x00\x00\x00\x00\x00");
2845 }
2460 2846
2461 if (!rc) 2847 if (!rc)
2462 rc = mwl8k_cmd_setrateadaptmode(hw, 0); 2848 rc = mwl8k_cmd_setrateadaptmode(hw, 0);
@@ -2464,9 +2850,6 @@ static int mwl8k_start(struct ieee80211_hw *hw)
2464 if (!rc) 2850 if (!rc)
2465 rc = mwl8k_set_wmm(hw, 0); 2851 rc = mwl8k_set_wmm(hw, 0);
2466 2852
2467 if (!rc)
2468 rc = mwl8k_enable_sniffer(hw, 0);
2469
2470 mwl8k_fw_unlock(hw); 2853 mwl8k_fw_unlock(hw);
2471 } 2854 }
2472 2855
@@ -2500,9 +2883,6 @@ static void mwl8k_stop(struct ieee80211_hw *hw)
2500 /* Stop tx reclaim tasklet */ 2883 /* Stop tx reclaim tasklet */
2501 tasklet_disable(&priv->tx_reclaim_task); 2884 tasklet_disable(&priv->tx_reclaim_task);
2502 2885
2503 /* Stop config thread */
2504 flush_workqueue(priv->config_wq);
2505
2506 /* Return all skbs to mac80211 */ 2886 /* Return all skbs to mac80211 */
2507 for (i = 0; i < MWL8K_TX_QUEUES; i++) 2887 for (i = 0; i < MWL8K_TX_QUEUES; i++)
2508 mwl8k_txq_reclaim(hw, i, 1); 2888 mwl8k_txq_reclaim(hw, i, 1);
@@ -2526,11 +2906,24 @@ static int mwl8k_add_interface(struct ieee80211_hw *hw,
2526 if (conf->type != NL80211_IFTYPE_STATION) 2906 if (conf->type != NL80211_IFTYPE_STATION)
2527 return -EINVAL; 2907 return -EINVAL;
2528 2908
2909 /*
2910 * Reject interface creation if sniffer mode is active, as
2911 * STA operation is mutually exclusive with hardware sniffer
2912 * mode.
2913 */
2914 if (priv->sniffer_enabled) {
2915 printk(KERN_INFO "%s: unable to create STA "
2916 "interface due to sniffer mode being enabled\n",
2917 wiphy_name(hw->wiphy));
2918 return -EINVAL;
2919 }
2920
2529 /* Clean out driver private area */ 2921 /* Clean out driver private area */
2530 mwl8k_vif = MWL8K_VIF(conf->vif); 2922 mwl8k_vif = MWL8K_VIF(conf->vif);
2531 memset(mwl8k_vif, 0, sizeof(*mwl8k_vif)); 2923 memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
2532 2924
2533 /* Save the mac address */ 2925 /* Set and save the mac address */
2926 mwl8k_set_mac_addr(hw, conf->mac_addr);
2534 memcpy(mwl8k_vif->mac_addr, conf->mac_addr, ETH_ALEN); 2927 memcpy(mwl8k_vif->mac_addr, conf->mac_addr, ETH_ALEN);
2535 2928
2536 /* Back pointer to parent config block */ 2929 /* Back pointer to parent config block */
@@ -2558,6 +2951,8 @@ static void mwl8k_remove_interface(struct ieee80211_hw *hw,
2558 if (priv->vif == NULL) 2951 if (priv->vif == NULL)
2559 return; 2952 return;
2560 2953
2954 mwl8k_set_mac_addr(hw, "\x00\x00\x00\x00\x00\x00");
2955
2561 priv->vif = NULL; 2956 priv->vif = NULL;
2562} 2957}
2563 2958
@@ -2593,8 +2988,13 @@ static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
2593 if (rc) 2988 if (rc)
2594 goto out; 2989 goto out;
2595 2990
2596 if (mwl8k_cmd_mimo_config(hw, 0x7, 0x7)) 2991 if (priv->ap_fw) {
2597 rc = -EINVAL; 2992 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_RX, 0x7);
2993 if (!rc)
2994 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_TX, 0x7);
2995 } else {
2996 rc = mwl8k_cmd_mimo_config(hw, 0x7, 0x7);
2997 }
2598 2998
2599out: 2999out:
2600 mwl8k_fw_unlock(hw); 3000 mwl8k_fw_unlock(hw);
@@ -2681,32 +3081,108 @@ static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
2681{ 3081{
2682 struct mwl8k_cmd_pkt *cmd; 3082 struct mwl8k_cmd_pkt *cmd;
2683 3083
2684 cmd = __mwl8k_cmd_mac_multicast_adr(hw, mc_count, mclist); 3084 /*
3085 * Synthesize and return a command packet that programs the
3086 * hardware multicast address filter. At this point we don't
3087 * know whether FIF_ALLMULTI is being requested, but if it is,
3088 * we'll end up throwing this packet away and creating a new
3089 * one in mwl8k_configure_filter().
3090 */
3091 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 0, mc_count, mclist);
2685 3092
2686 return (unsigned long)cmd; 3093 return (unsigned long)cmd;
2687} 3094}
2688 3095
3096static int
3097mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw,
3098 unsigned int changed_flags,
3099 unsigned int *total_flags)
3100{
3101 struct mwl8k_priv *priv = hw->priv;
3102
3103 /*
3104 * Hardware sniffer mode is mutually exclusive with STA
3105 * operation, so refuse to enable sniffer mode if a STA
3106 * interface is active.
3107 */
3108 if (priv->vif != NULL) {
3109 if (net_ratelimit())
3110 printk(KERN_INFO "%s: not enabling sniffer "
3111 "mode because STA interface is active\n",
3112 wiphy_name(hw->wiphy));
3113 return 0;
3114 }
3115
3116 if (!priv->sniffer_enabled) {
3117 if (mwl8k_enable_sniffer(hw, 1))
3118 return 0;
3119 priv->sniffer_enabled = true;
3120 }
3121
3122 *total_flags &= FIF_PROMISC_IN_BSS | FIF_ALLMULTI |
3123 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL |
3124 FIF_OTHER_BSS;
3125
3126 return 1;
3127}
3128
2689static void mwl8k_configure_filter(struct ieee80211_hw *hw, 3129static void mwl8k_configure_filter(struct ieee80211_hw *hw,
2690 unsigned int changed_flags, 3130 unsigned int changed_flags,
2691 unsigned int *total_flags, 3131 unsigned int *total_flags,
2692 u64 multicast) 3132 u64 multicast)
2693{ 3133{
2694 struct mwl8k_priv *priv = hw->priv; 3134 struct mwl8k_priv *priv = hw->priv;
2695 struct mwl8k_cmd_pkt *multicast_adr_cmd; 3135 struct mwl8k_cmd_pkt *cmd = (void *)(unsigned long)multicast;
3136
3137 /*
3138 * AP firmware doesn't allow fine-grained control over
3139 * the receive filter.
3140 */
3141 if (priv->ap_fw) {
3142 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
3143 kfree(cmd);
3144 return;
3145 }
3146
3147 /*
3148 * Enable hardware sniffer mode if FIF_CONTROL or
3149 * FIF_OTHER_BSS is requested.
3150 */
3151 if (*total_flags & (FIF_CONTROL | FIF_OTHER_BSS) &&
3152 mwl8k_configure_filter_sniffer(hw, changed_flags, total_flags)) {
3153 kfree(cmd);
3154 return;
3155 }
2696 3156
2697 /* Clear unsupported feature flags */ 3157 /* Clear unsupported feature flags */
2698 *total_flags &= FIF_BCN_PRBRESP_PROMISC; 3158 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
2699 3159
2700 if (mwl8k_fw_lock(hw)) 3160 if (mwl8k_fw_lock(hw))
2701 return; 3161 return;
2702 3162
3163 if (priv->sniffer_enabled) {
3164 mwl8k_enable_sniffer(hw, 0);
3165 priv->sniffer_enabled = false;
3166 }
3167
2703 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) { 3168 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
2704 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) 3169 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
3170 /*
3171 * Disable the BSS filter.
3172 */
2705 mwl8k_cmd_set_pre_scan(hw); 3173 mwl8k_cmd_set_pre_scan(hw);
2706 else { 3174 } else {
2707 u8 *bssid; 3175 u8 *bssid;
2708 3176
2709 bssid = "\x00\x00\x00\x00\x00\x00"; 3177 /*
3178 * Enable the BSS filter.
3179 *
3180 * If there is an active STA interface, use that
3181 * interface's BSSID, otherwise use a dummy one
3182 * (where the OUI part needs to be nonzero for
3183 * the BSSID to be accepted by POST_SCAN).
3184 */
3185 bssid = "\x01\x00\x00\x00\x00\x00";
2710 if (priv->vif != NULL) 3186 if (priv->vif != NULL)
2711 bssid = MWL8K_VIF(priv->vif)->bssid; 3187 bssid = MWL8K_VIF(priv->vif)->bssid;
2712 3188
@@ -2714,10 +3190,20 @@ static void mwl8k_configure_filter(struct ieee80211_hw *hw,
2714 } 3190 }
2715 } 3191 }
2716 3192
2717 multicast_adr_cmd = (void *)(unsigned long)multicast; 3193 /*
2718 if (multicast_adr_cmd != NULL) { 3194 * If FIF_ALLMULTI is being requested, throw away the command
2719 mwl8k_post_cmd(hw, multicast_adr_cmd); 3195 * packet that ->prepare_multicast() built and replace it with
2720 kfree(multicast_adr_cmd); 3196 * a command packet that enables reception of all multicast
3197 * packets.
3198 */
3199 if (*total_flags & FIF_ALLMULTI) {
3200 kfree(cmd);
3201 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 1, 0, NULL);
3202 }
3203
3204 if (cmd != NULL) {
3205 mwl8k_post_cmd(hw, cmd);
3206 kfree(cmd);
2721 } 3207 }
2722 3208
2723 mwl8k_fw_unlock(hw); 3209 mwl8k_fw_unlock(hw);
@@ -2762,7 +3248,7 @@ static int mwl8k_get_tx_stats(struct ieee80211_hw *hw,
2762 spin_lock_bh(&priv->tx_lock); 3248 spin_lock_bh(&priv->tx_lock);
2763 for (index = 0; index < MWL8K_TX_QUEUES; index++) { 3249 for (index = 0; index < MWL8K_TX_QUEUES; index++) {
2764 txq = priv->txq + index; 3250 txq = priv->txq + index;
2765 memcpy(&stats[index], &txq->tx_stats, 3251 memcpy(&stats[index], &txq->stats,
2766 sizeof(struct ieee80211_tx_queue_stats)); 3252 sizeof(struct ieee80211_tx_queue_stats));
2767 } 3253 }
2768 spin_unlock_bh(&priv->tx_lock); 3254 spin_unlock_bh(&priv->tx_lock);
@@ -2802,7 +3288,7 @@ static void mwl8k_tx_reclaim_handler(unsigned long data)
2802 for (i = 0; i < MWL8K_TX_QUEUES; i++) 3288 for (i = 0; i < MWL8K_TX_QUEUES; i++)
2803 mwl8k_txq_reclaim(hw, i, 0); 3289 mwl8k_txq_reclaim(hw, i, 0);
2804 3290
2805 if (priv->tx_wait != NULL && mwl8k_txq_busy(priv) == 0) { 3291 if (priv->tx_wait != NULL && !priv->pending_tx_pkts) {
2806 complete(priv->tx_wait); 3292 complete(priv->tx_wait);
2807 priv->tx_wait = NULL; 3293 priv->tx_wait = NULL;
2808 } 3294 }
@@ -2822,6 +3308,36 @@ static void mwl8k_finalize_join_worker(struct work_struct *work)
2822 priv->beacon_skb = NULL; 3308 priv->beacon_skb = NULL;
2823} 3309}
2824 3310
3311enum {
3312 MWL8687 = 0,
3313 MWL8366,
3314};
3315
3316static struct mwl8k_device_info mwl8k_info_tbl[] __devinitdata = {
3317 {
3318 .part_name = "88w8687",
3319 .helper_image = "mwl8k/helper_8687.fw",
3320 .fw_image = "mwl8k/fmimage_8687.fw",
3321 .rxd_ops = &rxd_8687_ops,
3322 .modes = BIT(NL80211_IFTYPE_STATION),
3323 },
3324 {
3325 .part_name = "88w8366",
3326 .helper_image = "mwl8k/helper_8366.fw",
3327 .fw_image = "mwl8k/fmimage_8366.fw",
3328 .rxd_ops = &rxd_8366_ops,
3329 .modes = 0,
3330 },
3331};
3332
3333static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
3334 { PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = MWL8687, },
3335 { PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = MWL8687, },
3336 { PCI_VDEVICE(MARVELL, 0x2a40), .driver_data = MWL8366, },
3337 { },
3338};
3339MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
3340
2825static int __devinit mwl8k_probe(struct pci_dev *pdev, 3341static int __devinit mwl8k_probe(struct pci_dev *pdev,
2826 const struct pci_device_id *id) 3342 const struct pci_device_id *id)
2827{ 3343{
@@ -2862,17 +3378,34 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
2862 priv = hw->priv; 3378 priv = hw->priv;
2863 priv->hw = hw; 3379 priv->hw = hw;
2864 priv->pdev = pdev; 3380 priv->pdev = pdev;
3381 priv->device_info = &mwl8k_info_tbl[id->driver_data];
3382 priv->rxd_ops = priv->device_info->rxd_ops;
3383 priv->sniffer_enabled = false;
2865 priv->wmm_enabled = false; 3384 priv->wmm_enabled = false;
2866 priv->pending_tx_pkts = 0; 3385 priv->pending_tx_pkts = 0;
2867 strncpy(priv->name, MWL8K_NAME, sizeof(priv->name));
2868 3386
2869 SET_IEEE80211_DEV(hw, &pdev->dev); 3387 SET_IEEE80211_DEV(hw, &pdev->dev);
2870 pci_set_drvdata(pdev, hw); 3388 pci_set_drvdata(pdev, hw);
2871 3389
3390 priv->sram = pci_iomap(pdev, 0, 0x10000);
3391 if (priv->sram == NULL) {
3392 printk(KERN_ERR "%s: Cannot map device SRAM\n",
3393 wiphy_name(hw->wiphy));
3394 goto err_iounmap;
3395 }
3396
3397 /*
3398 * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
3399 * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
3400 */
2872 priv->regs = pci_iomap(pdev, 1, 0x10000); 3401 priv->regs = pci_iomap(pdev, 1, 0x10000);
2873 if (priv->regs == NULL) { 3402 if (priv->regs == NULL) {
2874 printk(KERN_ERR "%s: Cannot map device memory\n", priv->name); 3403 priv->regs = pci_iomap(pdev, 2, 0x10000);
2875 goto err_iounmap; 3404 if (priv->regs == NULL) {
3405 printk(KERN_ERR "%s: Cannot map device registers\n",
3406 wiphy_name(hw->wiphy));
3407 goto err_iounmap;
3408 }
2876 } 3409 }
2877 3410
2878 memcpy(priv->channels, mwl8k_channels, sizeof(mwl8k_channels)); 3411 memcpy(priv->channels, mwl8k_channels, sizeof(mwl8k_channels));
@@ -2897,7 +3430,7 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
2897 3430
2898 hw->queues = MWL8K_TX_QUEUES; 3431 hw->queues = MWL8K_TX_QUEUES;
2899 3432
2900 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION); 3433 hw->wiphy->interface_modes = priv->device_info->modes;
2901 3434
2902 /* Set rssi and noise values to dBm */ 3435 /* Set rssi and noise values to dBm */
2903 hw->flags |= IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_NOISE_DBM; 3436 hw->flags |= IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_NOISE_DBM;
@@ -2916,11 +3449,6 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
2916 mwl8k_tx_reclaim_handler, (unsigned long)hw); 3449 mwl8k_tx_reclaim_handler, (unsigned long)hw);
2917 tasklet_disable(&priv->tx_reclaim_task); 3450 tasklet_disable(&priv->tx_reclaim_task);
2918 3451
2919 /* Config workthread */
2920 priv->config_wq = create_singlethread_workqueue("mwl8k_config");
2921 if (priv->config_wq == NULL)
2922 goto err_iounmap;
2923
2924 /* Power management cookie */ 3452 /* Power management cookie */
2925 priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma); 3453 priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
2926 if (priv->cookie == NULL) 3454 if (priv->cookie == NULL)
@@ -2934,11 +3462,12 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
2934 mutex_init(&priv->fw_mutex); 3462 mutex_init(&priv->fw_mutex);
2935 priv->fw_mutex_owner = NULL; 3463 priv->fw_mutex_owner = NULL;
2936 priv->fw_mutex_depth = 0; 3464 priv->fw_mutex_depth = 0;
2937 priv->tx_wait = NULL;
2938 priv->hostcmd_wait = NULL; 3465 priv->hostcmd_wait = NULL;
2939 3466
2940 spin_lock_init(&priv->tx_lock); 3467 spin_lock_init(&priv->tx_lock);
2941 3468
3469 priv->tx_wait = NULL;
3470
2942 for (i = 0; i < MWL8K_TX_QUEUES; i++) { 3471 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
2943 rc = mwl8k_txq_init(hw, i); 3472 rc = mwl8k_txq_init(hw, i);
2944 if (rc) 3473 if (rc)
@@ -2954,7 +3483,7 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
2954 IRQF_SHARED, MWL8K_NAME, hw); 3483 IRQF_SHARED, MWL8K_NAME, hw);
2955 if (rc) { 3484 if (rc) {
2956 printk(KERN_ERR "%s: failed to register IRQ handler\n", 3485 printk(KERN_ERR "%s: failed to register IRQ handler\n",
2957 priv->name); 3486 wiphy_name(hw->wiphy));
2958 goto err_free_queues; 3487 goto err_free_queues;
2959 } 3488 }
2960 3489
@@ -2962,16 +3491,18 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
2962 mwl8k_hw_reset(priv); 3491 mwl8k_hw_reset(priv);
2963 3492
2964 /* Ask userland hotplug daemon for the device firmware */ 3493 /* Ask userland hotplug daemon for the device firmware */
2965 rc = mwl8k_request_firmware(priv, (u32)id->driver_data); 3494 rc = mwl8k_request_firmware(priv);
2966 if (rc) { 3495 if (rc) {
2967 printk(KERN_ERR "%s: Firmware files not found\n", priv->name); 3496 printk(KERN_ERR "%s: Firmware files not found\n",
3497 wiphy_name(hw->wiphy));
2968 goto err_free_irq; 3498 goto err_free_irq;
2969 } 3499 }
2970 3500
2971 /* Load firmware into hardware */ 3501 /* Load firmware into hardware */
2972 rc = mwl8k_load_firmware(priv); 3502 rc = mwl8k_load_firmware(hw);
2973 if (rc) { 3503 if (rc) {
2974 printk(KERN_ERR "%s: Cannot start firmware\n", priv->name); 3504 printk(KERN_ERR "%s: Cannot start firmware\n",
3505 wiphy_name(hw->wiphy));
2975 goto err_stop_firmware; 3506 goto err_stop_firmware;
2976 } 3507 }
2977 3508
@@ -2986,16 +3517,31 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
2986 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK); 3517 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
2987 3518
2988 /* Get config data, mac addrs etc */ 3519 /* Get config data, mac addrs etc */
2989 rc = mwl8k_cmd_get_hw_spec(hw); 3520 if (priv->ap_fw) {
3521 rc = mwl8k_cmd_get_hw_spec_ap(hw);
3522 if (!rc)
3523 rc = mwl8k_cmd_set_hw_spec(hw);
3524 } else {
3525 rc = mwl8k_cmd_get_hw_spec_sta(hw);
3526 }
2990 if (rc) { 3527 if (rc) {
2991 printk(KERN_ERR "%s: Cannot initialise firmware\n", priv->name); 3528 printk(KERN_ERR "%s: Cannot initialise firmware\n",
3529 wiphy_name(hw->wiphy));
2992 goto err_stop_firmware; 3530 goto err_stop_firmware;
2993 } 3531 }
2994 3532
2995 /* Turn radio off */ 3533 /* Turn radio off */
2996 rc = mwl8k_cmd_802_11_radio_disable(hw); 3534 rc = mwl8k_cmd_802_11_radio_disable(hw);
2997 if (rc) { 3535 if (rc) {
2998 printk(KERN_ERR "%s: Cannot disable\n", priv->name); 3536 printk(KERN_ERR "%s: Cannot disable\n", wiphy_name(hw->wiphy));
3537 goto err_stop_firmware;
3538 }
3539
3540 /* Clear MAC address */
3541 rc = mwl8k_set_mac_addr(hw, "\x00\x00\x00\x00\x00\x00");
3542 if (rc) {
3543 printk(KERN_ERR "%s: Cannot clear MAC address\n",
3544 wiphy_name(hw->wiphy));
2999 goto err_stop_firmware; 3545 goto err_stop_firmware;
3000 } 3546 }
3001 3547
@@ -3005,13 +3551,15 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
3005 3551
3006 rc = ieee80211_register_hw(hw); 3552 rc = ieee80211_register_hw(hw);
3007 if (rc) { 3553 if (rc) {
3008 printk(KERN_ERR "%s: Cannot register device\n", priv->name); 3554 printk(KERN_ERR "%s: Cannot register device\n",
3555 wiphy_name(hw->wiphy));
3009 goto err_stop_firmware; 3556 goto err_stop_firmware;
3010 } 3557 }
3011 3558
3012 printk(KERN_INFO "%s: 88w%u v%d, %pM, firmware version %u.%u.%u.%u\n", 3559 printk(KERN_INFO "%s: %s v%d, %pM, %s firmware %u.%u.%u.%u\n",
3013 wiphy_name(hw->wiphy), priv->part_num, priv->hw_rev, 3560 wiphy_name(hw->wiphy), priv->device_info->part_name,
3014 hw->wiphy->perm_addr, 3561 priv->hw_rev, hw->wiphy->perm_addr,
3562 priv->ap_fw ? "AP" : "STA",
3015 (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff, 3563 (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff,
3016 (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff); 3564 (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff);
3017 3565
@@ -3038,8 +3586,8 @@ err_iounmap:
3038 if (priv->regs != NULL) 3586 if (priv->regs != NULL)
3039 pci_iounmap(pdev, priv->regs); 3587 pci_iounmap(pdev, priv->regs);
3040 3588
3041 if (priv->config_wq != NULL) 3589 if (priv->sram != NULL)
3042 destroy_workqueue(priv->config_wq); 3590 pci_iounmap(pdev, priv->sram);
3043 3591
3044 pci_set_drvdata(pdev, NULL); 3592 pci_set_drvdata(pdev, NULL);
3045 ieee80211_free_hw(hw); 3593 ieee80211_free_hw(hw);
@@ -3073,9 +3621,6 @@ static void __devexit mwl8k_remove(struct pci_dev *pdev)
3073 /* Remove tx reclaim tasklet */ 3621 /* Remove tx reclaim tasklet */
3074 tasklet_kill(&priv->tx_reclaim_task); 3622 tasklet_kill(&priv->tx_reclaim_task);
3075 3623
3076 /* Stop config thread */
3077 destroy_workqueue(priv->config_wq);
3078
3079 /* Stop hardware */ 3624 /* Stop hardware */
3080 mwl8k_hw_reset(priv); 3625 mwl8k_hw_reset(priv);
3081 3626
@@ -3088,10 +3633,10 @@ static void __devexit mwl8k_remove(struct pci_dev *pdev)
3088 3633
3089 mwl8k_rxq_deinit(hw, 0); 3634 mwl8k_rxq_deinit(hw, 0);
3090 3635
3091 pci_free_consistent(priv->pdev, 4, 3636 pci_free_consistent(priv->pdev, 4, priv->cookie, priv->cookie_dma);
3092 priv->cookie, priv->cookie_dma);
3093 3637
3094 pci_iounmap(pdev, priv->regs); 3638 pci_iounmap(pdev, priv->regs);
3639 pci_iounmap(pdev, priv->sram);
3095 pci_set_drvdata(pdev, NULL); 3640 pci_set_drvdata(pdev, NULL);
3096 ieee80211_free_hw(hw); 3641 ieee80211_free_hw(hw);
3097 pci_release_regions(pdev); 3642 pci_release_regions(pdev);
@@ -3100,7 +3645,7 @@ static void __devexit mwl8k_remove(struct pci_dev *pdev)
3100 3645
3101static struct pci_driver mwl8k_driver = { 3646static struct pci_driver mwl8k_driver = {
3102 .name = MWL8K_NAME, 3647 .name = MWL8K_NAME,
3103 .id_table = mwl8k_table, 3648 .id_table = mwl8k_pci_id_table,
3104 .probe = mwl8k_probe, 3649 .probe = mwl8k_probe,
3105 .remove = __devexit_p(mwl8k_remove), 3650 .remove = __devexit_p(mwl8k_remove),
3106 .shutdown = __devexit_p(mwl8k_shutdown), 3651 .shutdown = __devexit_p(mwl8k_shutdown),
@@ -3118,3 +3663,8 @@ static void __exit mwl8k_exit(void)
3118 3663
3119module_init(mwl8k_init); 3664module_init(mwl8k_init);
3120module_exit(mwl8k_exit); 3665module_exit(mwl8k_exit);
3666
3667MODULE_DESCRIPTION(MWL8K_DESC);
3668MODULE_VERSION(MWL8K_VERSION);
3669MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
3670MODULE_LICENSE("GPL");
diff --git a/drivers/net/wireless/orinoco/Kconfig b/drivers/net/wireless/orinoco/Kconfig
index dce652054afd..e2a2c18920aa 100644
--- a/drivers/net/wireless/orinoco/Kconfig
+++ b/drivers/net/wireless/orinoco/Kconfig
@@ -1,6 +1,6 @@
1config HERMES 1config HERMES
2 tristate "Hermes chipset 802.11b support (Orinoco/Prism2/Symbol)" 2 tristate "Hermes chipset 802.11b support (Orinoco/Prism2/Symbol)"
3 depends on (PPC_PMAC || PCI || PCMCIA) && WLAN_80211 3 depends on (PPC_PMAC || PCI || PCMCIA)
4 depends on CFG80211 && CFG80211_WEXT 4 depends on CFG80211 && CFG80211_WEXT
5 select WIRELESS_EXT 5 select WIRELESS_EXT
6 select WEXT_SPY 6 select WEXT_SPY
diff --git a/drivers/net/wireless/p54/Kconfig b/drivers/net/wireless/p54/Kconfig
index b45d6a4ed1e8..b0342a520bf1 100644
--- a/drivers/net/wireless/p54/Kconfig
+++ b/drivers/net/wireless/p54/Kconfig
@@ -1,6 +1,6 @@
1config P54_COMMON 1config P54_COMMON
2 tristate "Softmac Prism54 support" 2 tristate "Softmac Prism54 support"
3 depends on MAC80211 && WLAN_80211 && EXPERIMENTAL 3 depends on MAC80211 && EXPERIMENTAL
4 select FW_LOADER 4 select FW_LOADER
5 ---help--- 5 ---help---
6 This is common code for isl38xx/stlc45xx based modules. 6 This is common code for isl38xx/stlc45xx based modules.
diff --git a/drivers/net/wireless/p54/eeprom.c b/drivers/net/wireless/p54/eeprom.c
index 0efe67deedee..8e3818f6832e 100644
--- a/drivers/net/wireless/p54/eeprom.c
+++ b/drivers/net/wireless/p54/eeprom.c
@@ -126,7 +126,7 @@ static int p54_generate_band(struct ieee80211_hw *dev,
126 int ret = -ENOMEM; 126 int ret = -ENOMEM;
127 127
128 if ((!list->entries) || (!list->band_channel_num[band])) 128 if ((!list->entries) || (!list->band_channel_num[band]))
129 return 0; 129 return -EINVAL;
130 130
131 tmp = kzalloc(sizeof(*tmp), GFP_KERNEL); 131 tmp = kzalloc(sizeof(*tmp), GFP_KERNEL);
132 if (!tmp) 132 if (!tmp)
@@ -158,6 +158,7 @@ static int p54_generate_band(struct ieee80211_hw *dev,
158 (list->channels[i].data & CHAN_HAS_CURVE ? "" : 158 (list->channels[i].data & CHAN_HAS_CURVE ? "" :
159 " [curve data]"), 159 " [curve data]"),
160 list->channels[i].index, list->channels[i].freq); 160 list->channels[i].index, list->channels[i].freq);
161 continue;
161 } 162 }
162 163
163 tmp->channels[j].band = list->channels[i].band; 164 tmp->channels[j].band = list->channels[i].band;
@@ -165,7 +166,16 @@ static int p54_generate_band(struct ieee80211_hw *dev,
165 j++; 166 j++;
166 } 167 }
167 168
168 tmp->n_channels = list->band_channel_num[band]; 169 if (j == 0) {
170 printk(KERN_ERR "%s: Disabling totally damaged %s band.\n",
171 wiphy_name(dev->wiphy), (band == IEEE80211_BAND_2GHZ) ?
172 "2 GHz" : "5 GHz");
173
174 ret = -ENODATA;
175 goto err_out;
176 }
177
178 tmp->n_channels = j;
169 old = priv->band_table[band]; 179 old = priv->band_table[band];
170 priv->band_table[band] = tmp; 180 priv->band_table[band] = tmp;
171 if (old) { 181 if (old) {
@@ -228,13 +238,13 @@ static int p54_generate_channel_lists(struct ieee80211_hw *dev)
228 struct p54_common *priv = dev->priv; 238 struct p54_common *priv = dev->priv;
229 struct p54_channel_list *list; 239 struct p54_channel_list *list;
230 unsigned int i, j, max_channel_num; 240 unsigned int i, j, max_channel_num;
231 int ret = -ENOMEM; 241 int ret = 0;
232 u16 freq; 242 u16 freq;
233 243
234 if ((priv->iq_autocal_len != priv->curve_data->entries) || 244 if ((priv->iq_autocal_len != priv->curve_data->entries) ||
235 (priv->iq_autocal_len != priv->output_limit->entries)) 245 (priv->iq_autocal_len != priv->output_limit->entries))
236 printk(KERN_ERR "%s: EEPROM is damaged... you may not be able" 246 printk(KERN_ERR "%s: Unsupported or damaged EEPROM detected. "
237 "to use all channels with this device.\n", 247 "You may not be able to use all channels.\n",
238 wiphy_name(dev->wiphy)); 248 wiphy_name(dev->wiphy));
239 249
240 max_channel_num = max_t(unsigned int, priv->output_limit->entries, 250 max_channel_num = max_t(unsigned int, priv->output_limit->entries,
@@ -243,8 +253,10 @@ static int p54_generate_channel_lists(struct ieee80211_hw *dev)
243 priv->curve_data->entries); 253 priv->curve_data->entries);
244 254
245 list = kzalloc(sizeof(*list), GFP_KERNEL); 255 list = kzalloc(sizeof(*list), GFP_KERNEL);
246 if (!list) 256 if (!list) {
257 ret = -ENOMEM;
247 goto free; 258 goto free;
259 }
248 260
249 list->max_entries = max_channel_num; 261 list->max_entries = max_channel_num;
250 list->channels = kzalloc(sizeof(struct p54_channel_entry) * 262 list->channels = kzalloc(sizeof(struct p54_channel_entry) *
@@ -282,13 +294,8 @@ static int p54_generate_channel_lists(struct ieee80211_hw *dev)
282 p54_compare_channels, NULL); 294 p54_compare_channels, NULL);
283 295
284 for (i = 0, j = 0; i < IEEE80211_NUM_BANDS; i++) { 296 for (i = 0, j = 0; i < IEEE80211_NUM_BANDS; i++) {
285 if (list->band_channel_num[i]) { 297 if (p54_generate_band(dev, list, i) == 0)
286 ret = p54_generate_band(dev, list, i);
287 if (ret)
288 goto free;
289
290 j++; 298 j++;
291 }
292 } 299 }
293 if (j == 0) { 300 if (j == 0) {
294 /* no useable band available. */ 301 /* no useable band available. */
diff --git a/drivers/net/wireless/rt2x00/Kconfig b/drivers/net/wireless/rt2x00/Kconfig
index 390c0c7b3ac2..bf60689aaabb 100644
--- a/drivers/net/wireless/rt2x00/Kconfig
+++ b/drivers/net/wireless/rt2x00/Kconfig
@@ -1,6 +1,6 @@
1menuconfig RT2X00 1menuconfig RT2X00
2 tristate "Ralink driver support" 2 tristate "Ralink driver support"
3 depends on MAC80211 && WLAN_80211 3 depends on MAC80211
4 ---help--- 4 ---help---
5 This will enable the support for the Ralink drivers, 5 This will enable the support for the Ralink drivers,
6 developed in the rt2x00 project <http://rt2x00.serialmonkey.com>. 6 developed in the rt2x00 project <http://rt2x00.serialmonkey.com>.
@@ -64,8 +64,9 @@ config RT2800PCI_SOC
64 default y 64 default y
65 65
66config RT2800PCI 66config RT2800PCI
67 tristate "Ralink rt2800 (PCI/PCMCIA) support" 67 tristate "Ralink rt2800 (PCI/PCMCIA) support (VERY EXPERIMENTAL)"
68 depends on (RT2800PCI_PCI || RT2800PCI_SOC) && EXPERIMENTAL 68 depends on (RT2800PCI_PCI || RT2800PCI_SOC) && EXPERIMENTAL
69 select RT2800_LIB
69 select RT2X00_LIB_PCI if RT2800PCI_PCI 70 select RT2X00_LIB_PCI if RT2800PCI_PCI
70 select RT2X00_LIB_SOC if RT2800PCI_SOC 71 select RT2X00_LIB_SOC if RT2800PCI_SOC
71 select RT2X00_LIB_HT 72 select RT2X00_LIB_HT
@@ -77,6 +78,9 @@ config RT2800PCI
77 This adds support for rt2800 wireless chipset family. 78 This adds support for rt2800 wireless chipset family.
78 Supported chips: RT2760, RT2790, RT2860, RT2880, RT2890 & RT3052 79 Supported chips: RT2760, RT2790, RT2860, RT2880, RT2890 & RT3052
79 80
81 This driver is non-functional at the moment and is intended for
82 developers.
83
80 When compiled as a module, this driver will be called "rt2800pci.ko". 84 When compiled as a module, this driver will be called "rt2800pci.ko".
81 85
82config RT2500USB 86config RT2500USB
@@ -104,8 +108,9 @@ config RT73USB
104 When compiled as a module, this driver will be called rt73usb. 108 When compiled as a module, this driver will be called rt73usb.
105 109
106config RT2800USB 110config RT2800USB
107 tristate "Ralink rt2800 (USB) support" 111 tristate "Ralink rt2800 (USB) support (EXPERIMENTAL)"
108 depends on USB && EXPERIMENTAL 112 depends on USB && EXPERIMENTAL
113 select RT2800_LIB
109 select RT2X00_LIB_USB 114 select RT2X00_LIB_USB
110 select RT2X00_LIB_HT 115 select RT2X00_LIB_HT
111 select RT2X00_LIB_FIRMWARE 116 select RT2X00_LIB_FIRMWARE
@@ -115,8 +120,15 @@ config RT2800USB
115 This adds experimental support for rt2800 wireless chipset family. 120 This adds experimental support for rt2800 wireless chipset family.
116 Supported chips: RT2770, RT2870 & RT3070. 121 Supported chips: RT2770, RT2870 & RT3070.
117 122
123 Known issues:
124 - support for RT2870 chips doesn't work with 802.11n APs yet
125 - support for RT3070 chips is non-functional at the moment
126
118 When compiled as a module, this driver will be called "rt2800usb.ko". 127 When compiled as a module, this driver will be called "rt2800usb.ko".
119 128
129config RT2800_LIB
130 tristate
131
120config RT2X00_LIB_PCI 132config RT2X00_LIB_PCI
121 tristate 133 tristate
122 select RT2X00_LIB 134 select RT2X00_LIB
diff --git a/drivers/net/wireless/rt2x00/Makefile b/drivers/net/wireless/rt2x00/Makefile
index 912f5f67e159..971339858297 100644
--- a/drivers/net/wireless/rt2x00/Makefile
+++ b/drivers/net/wireless/rt2x00/Makefile
@@ -13,6 +13,7 @@ obj-$(CONFIG_RT2X00_LIB) += rt2x00lib.o
13obj-$(CONFIG_RT2X00_LIB_PCI) += rt2x00pci.o 13obj-$(CONFIG_RT2X00_LIB_PCI) += rt2x00pci.o
14obj-$(CONFIG_RT2X00_LIB_SOC) += rt2x00soc.o 14obj-$(CONFIG_RT2X00_LIB_SOC) += rt2x00soc.o
15obj-$(CONFIG_RT2X00_LIB_USB) += rt2x00usb.o 15obj-$(CONFIG_RT2X00_LIB_USB) += rt2x00usb.o
16obj-$(CONFIG_RT2800_LIB) += rt2800lib.o
16obj-$(CONFIG_RT2400PCI) += rt2400pci.o 17obj-$(CONFIG_RT2400PCI) += rt2400pci.o
17obj-$(CONFIG_RT2500PCI) += rt2500pci.o 18obj-$(CONFIG_RT2500PCI) += rt2500pci.o
18obj-$(CONFIG_RT61PCI) += rt61pci.o 19obj-$(CONFIG_RT61PCI) += rt61pci.o
diff --git a/drivers/net/wireless/rt2x00/rt2800.h b/drivers/net/wireless/rt2x00/rt2800.h
new file mode 100644
index 000000000000..d9b6a72e6d27
--- /dev/null
+++ b/drivers/net/wireless/rt2x00/rt2800.h
@@ -0,0 +1,1816 @@
1/*
2 Copyright (C) 2004 - 2009 rt2x00 SourceForge Project
3 <http://rt2x00.serialmonkey.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the
17 Free Software Foundation, Inc.,
18 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21/*
22 Module: rt2800
23 Abstract: Data structures and registers for the rt2800 modules.
24 Supported chipsets: RT2800E, RT2800ED & RT2800U.
25 */
26
27#ifndef RT2800_H
28#define RT2800_H
29
30/*
31 * RF chip defines.
32 *
33 * RF2820 2.4G 2T3R
34 * RF2850 2.4G/5G 2T3R
35 * RF2720 2.4G 1T2R
36 * RF2750 2.4G/5G 1T2R
37 * RF3020 2.4G 1T1R
38 * RF2020 2.4G B/G
39 * RF3021 2.4G 1T2R
40 * RF3022 2.4G 2T2R
41 * RF3052 2.4G 2T2R
42 */
43#define RF2820 0x0001
44#define RF2850 0x0002
45#define RF2720 0x0003
46#define RF2750 0x0004
47#define RF3020 0x0005
48#define RF2020 0x0006
49#define RF3021 0x0007
50#define RF3022 0x0008
51#define RF3052 0x0009
52
53/*
54 * Chipset version.
55 */
56#define RT2860C_VERSION 0x28600100
57#define RT2860D_VERSION 0x28600101
58#define RT2880E_VERSION 0x28720200
59#define RT2883_VERSION 0x28830300
60#define RT3070_VERSION 0x30700200
61
62/*
63 * Signal information.
64 * Default offset is required for RSSI <-> dBm conversion.
65 */
66#define DEFAULT_RSSI_OFFSET 120 /* FIXME */
67
68/*
69 * Register layout information.
70 */
71#define CSR_REG_BASE 0x1000
72#define CSR_REG_SIZE 0x0800
73#define EEPROM_BASE 0x0000
74#define EEPROM_SIZE 0x0110
75#define BBP_BASE 0x0000
76#define BBP_SIZE 0x0080
77#define RF_BASE 0x0004
78#define RF_SIZE 0x0010
79
80/*
81 * Number of TX queues.
82 */
83#define NUM_TX_QUEUES 4
84
85/*
86 * USB registers.
87 */
88
89/*
90 * INT_SOURCE_CSR: Interrupt source register.
91 * Write one to clear corresponding bit.
92 * TX_FIFO_STATUS: FIFO Statistics is full, sw should read 0x171c
93 */
94#define INT_SOURCE_CSR 0x0200
95#define INT_SOURCE_CSR_RXDELAYINT FIELD32(0x00000001)
96#define INT_SOURCE_CSR_TXDELAYINT FIELD32(0x00000002)
97#define INT_SOURCE_CSR_RX_DONE FIELD32(0x00000004)
98#define INT_SOURCE_CSR_AC0_DMA_DONE FIELD32(0x00000008)
99#define INT_SOURCE_CSR_AC1_DMA_DONE FIELD32(0x00000010)
100#define INT_SOURCE_CSR_AC2_DMA_DONE FIELD32(0x00000020)
101#define INT_SOURCE_CSR_AC3_DMA_DONE FIELD32(0x00000040)
102#define INT_SOURCE_CSR_HCCA_DMA_DONE FIELD32(0x00000080)
103#define INT_SOURCE_CSR_MGMT_DMA_DONE FIELD32(0x00000100)
104#define INT_SOURCE_CSR_MCU_COMMAND FIELD32(0x00000200)
105#define INT_SOURCE_CSR_RXTX_COHERENT FIELD32(0x00000400)
106#define INT_SOURCE_CSR_TBTT FIELD32(0x00000800)
107#define INT_SOURCE_CSR_PRE_TBTT FIELD32(0x00001000)
108#define INT_SOURCE_CSR_TX_FIFO_STATUS FIELD32(0x00002000)
109#define INT_SOURCE_CSR_AUTO_WAKEUP FIELD32(0x00004000)
110#define INT_SOURCE_CSR_GPTIMER FIELD32(0x00008000)
111#define INT_SOURCE_CSR_RX_COHERENT FIELD32(0x00010000)
112#define INT_SOURCE_CSR_TX_COHERENT FIELD32(0x00020000)
113
114/*
115 * INT_MASK_CSR: Interrupt MASK register. 1: the interrupt is mask OFF.
116 */
117#define INT_MASK_CSR 0x0204
118#define INT_MASK_CSR_RXDELAYINT FIELD32(0x00000001)
119#define INT_MASK_CSR_TXDELAYINT FIELD32(0x00000002)
120#define INT_MASK_CSR_RX_DONE FIELD32(0x00000004)
121#define INT_MASK_CSR_AC0_DMA_DONE FIELD32(0x00000008)
122#define INT_MASK_CSR_AC1_DMA_DONE FIELD32(0x00000010)
123#define INT_MASK_CSR_AC2_DMA_DONE FIELD32(0x00000020)
124#define INT_MASK_CSR_AC3_DMA_DONE FIELD32(0x00000040)
125#define INT_MASK_CSR_HCCA_DMA_DONE FIELD32(0x00000080)
126#define INT_MASK_CSR_MGMT_DMA_DONE FIELD32(0x00000100)
127#define INT_MASK_CSR_MCU_COMMAND FIELD32(0x00000200)
128#define INT_MASK_CSR_RXTX_COHERENT FIELD32(0x00000400)
129#define INT_MASK_CSR_TBTT FIELD32(0x00000800)
130#define INT_MASK_CSR_PRE_TBTT FIELD32(0x00001000)
131#define INT_MASK_CSR_TX_FIFO_STATUS FIELD32(0x00002000)
132#define INT_MASK_CSR_AUTO_WAKEUP FIELD32(0x00004000)
133#define INT_MASK_CSR_GPTIMER FIELD32(0x00008000)
134#define INT_MASK_CSR_RX_COHERENT FIELD32(0x00010000)
135#define INT_MASK_CSR_TX_COHERENT FIELD32(0x00020000)
136
137/*
138 * WPDMA_GLO_CFG
139 */
140#define WPDMA_GLO_CFG 0x0208
141#define WPDMA_GLO_CFG_ENABLE_TX_DMA FIELD32(0x00000001)
142#define WPDMA_GLO_CFG_TX_DMA_BUSY FIELD32(0x00000002)
143#define WPDMA_GLO_CFG_ENABLE_RX_DMA FIELD32(0x00000004)
144#define WPDMA_GLO_CFG_RX_DMA_BUSY FIELD32(0x00000008)
145#define WPDMA_GLO_CFG_WP_DMA_BURST_SIZE FIELD32(0x00000030)
146#define WPDMA_GLO_CFG_TX_WRITEBACK_DONE FIELD32(0x00000040)
147#define WPDMA_GLO_CFG_BIG_ENDIAN FIELD32(0x00000080)
148#define WPDMA_GLO_CFG_RX_HDR_SCATTER FIELD32(0x0000ff00)
149#define WPDMA_GLO_CFG_HDR_SEG_LEN FIELD32(0xffff0000)
150
151/*
152 * WPDMA_RST_IDX
153 */
154#define WPDMA_RST_IDX 0x020c
155#define WPDMA_RST_IDX_DTX_IDX0 FIELD32(0x00000001)
156#define WPDMA_RST_IDX_DTX_IDX1 FIELD32(0x00000002)
157#define WPDMA_RST_IDX_DTX_IDX2 FIELD32(0x00000004)
158#define WPDMA_RST_IDX_DTX_IDX3 FIELD32(0x00000008)
159#define WPDMA_RST_IDX_DTX_IDX4 FIELD32(0x00000010)
160#define WPDMA_RST_IDX_DTX_IDX5 FIELD32(0x00000020)
161#define WPDMA_RST_IDX_DRX_IDX0 FIELD32(0x00010000)
162
163/*
164 * DELAY_INT_CFG
165 */
166#define DELAY_INT_CFG 0x0210
167#define DELAY_INT_CFG_RXMAX_PTIME FIELD32(0x000000ff)
168#define DELAY_INT_CFG_RXMAX_PINT FIELD32(0x00007f00)
169#define DELAY_INT_CFG_RXDLY_INT_EN FIELD32(0x00008000)
170#define DELAY_INT_CFG_TXMAX_PTIME FIELD32(0x00ff0000)
171#define DELAY_INT_CFG_TXMAX_PINT FIELD32(0x7f000000)
172#define DELAY_INT_CFG_TXDLY_INT_EN FIELD32(0x80000000)
173
174/*
175 * WMM_AIFSN_CFG: Aifsn for each EDCA AC
176 * AIFSN0: AC_BE
177 * AIFSN1: AC_BK
178 * AIFSN2: AC_VI
179 * AIFSN3: AC_VO
180 */
181#define WMM_AIFSN_CFG 0x0214
182#define WMM_AIFSN_CFG_AIFSN0 FIELD32(0x0000000f)
183#define WMM_AIFSN_CFG_AIFSN1 FIELD32(0x000000f0)
184#define WMM_AIFSN_CFG_AIFSN2 FIELD32(0x00000f00)
185#define WMM_AIFSN_CFG_AIFSN3 FIELD32(0x0000f000)
186
187/*
188 * WMM_CWMIN_CSR: CWmin for each EDCA AC
189 * CWMIN0: AC_BE
190 * CWMIN1: AC_BK
191 * CWMIN2: AC_VI
192 * CWMIN3: AC_VO
193 */
194#define WMM_CWMIN_CFG 0x0218
195#define WMM_CWMIN_CFG_CWMIN0 FIELD32(0x0000000f)
196#define WMM_CWMIN_CFG_CWMIN1 FIELD32(0x000000f0)
197#define WMM_CWMIN_CFG_CWMIN2 FIELD32(0x00000f00)
198#define WMM_CWMIN_CFG_CWMIN3 FIELD32(0x0000f000)
199
200/*
201 * WMM_CWMAX_CSR: CWmax for each EDCA AC
202 * CWMAX0: AC_BE
203 * CWMAX1: AC_BK
204 * CWMAX2: AC_VI
205 * CWMAX3: AC_VO
206 */
207#define WMM_CWMAX_CFG 0x021c
208#define WMM_CWMAX_CFG_CWMAX0 FIELD32(0x0000000f)
209#define WMM_CWMAX_CFG_CWMAX1 FIELD32(0x000000f0)
210#define WMM_CWMAX_CFG_CWMAX2 FIELD32(0x00000f00)
211#define WMM_CWMAX_CFG_CWMAX3 FIELD32(0x0000f000)
212
213/*
214 * AC_TXOP0: AC_BK/AC_BE TXOP register
215 * AC0TXOP: AC_BK in unit of 32us
216 * AC1TXOP: AC_BE in unit of 32us
217 */
218#define WMM_TXOP0_CFG 0x0220
219#define WMM_TXOP0_CFG_AC0TXOP FIELD32(0x0000ffff)
220#define WMM_TXOP0_CFG_AC1TXOP FIELD32(0xffff0000)
221
222/*
223 * AC_TXOP1: AC_VO/AC_VI TXOP register
224 * AC2TXOP: AC_VI in unit of 32us
225 * AC3TXOP: AC_VO in unit of 32us
226 */
227#define WMM_TXOP1_CFG 0x0224
228#define WMM_TXOP1_CFG_AC2TXOP FIELD32(0x0000ffff)
229#define WMM_TXOP1_CFG_AC3TXOP FIELD32(0xffff0000)
230
231/*
232 * GPIO_CTRL_CFG:
233 */
234#define GPIO_CTRL_CFG 0x0228
235#define GPIO_CTRL_CFG_BIT0 FIELD32(0x00000001)
236#define GPIO_CTRL_CFG_BIT1 FIELD32(0x00000002)
237#define GPIO_CTRL_CFG_BIT2 FIELD32(0x00000004)
238#define GPIO_CTRL_CFG_BIT3 FIELD32(0x00000008)
239#define GPIO_CTRL_CFG_BIT4 FIELD32(0x00000010)
240#define GPIO_CTRL_CFG_BIT5 FIELD32(0x00000020)
241#define GPIO_CTRL_CFG_BIT6 FIELD32(0x00000040)
242#define GPIO_CTRL_CFG_BIT7 FIELD32(0x00000080)
243#define GPIO_CTRL_CFG_BIT8 FIELD32(0x00000100)
244
245/*
246 * MCU_CMD_CFG
247 */
248#define MCU_CMD_CFG 0x022c
249
250/*
251 * AC_BK register offsets
252 */
253#define TX_BASE_PTR0 0x0230
254#define TX_MAX_CNT0 0x0234
255#define TX_CTX_IDX0 0x0238
256#define TX_DTX_IDX0 0x023c
257
258/*
259 * AC_BE register offsets
260 */
261#define TX_BASE_PTR1 0x0240
262#define TX_MAX_CNT1 0x0244
263#define TX_CTX_IDX1 0x0248
264#define TX_DTX_IDX1 0x024c
265
266/*
267 * AC_VI register offsets
268 */
269#define TX_BASE_PTR2 0x0250
270#define TX_MAX_CNT2 0x0254
271#define TX_CTX_IDX2 0x0258
272#define TX_DTX_IDX2 0x025c
273
274/*
275 * AC_VO register offsets
276 */
277#define TX_BASE_PTR3 0x0260
278#define TX_MAX_CNT3 0x0264
279#define TX_CTX_IDX3 0x0268
280#define TX_DTX_IDX3 0x026c
281
282/*
283 * HCCA register offsets
284 */
285#define TX_BASE_PTR4 0x0270
286#define TX_MAX_CNT4 0x0274
287#define TX_CTX_IDX4 0x0278
288#define TX_DTX_IDX4 0x027c
289
290/*
291 * MGMT register offsets
292 */
293#define TX_BASE_PTR5 0x0280
294#define TX_MAX_CNT5 0x0284
295#define TX_CTX_IDX5 0x0288
296#define TX_DTX_IDX5 0x028c
297
298/*
299 * RX register offsets
300 */
301#define RX_BASE_PTR 0x0290
302#define RX_MAX_CNT 0x0294
303#define RX_CRX_IDX 0x0298
304#define RX_DRX_IDX 0x029c
305
306/*
307 * PBF_SYS_CTRL
308 * HOST_RAM_WRITE: enable Host program ram write selection
309 */
310#define PBF_SYS_CTRL 0x0400
311#define PBF_SYS_CTRL_READY FIELD32(0x00000080)
312#define PBF_SYS_CTRL_HOST_RAM_WRITE FIELD32(0x00010000)
313
314/*
315 * HOST-MCU shared memory
316 */
317#define HOST_CMD_CSR 0x0404
318#define HOST_CMD_CSR_HOST_COMMAND FIELD32(0x000000ff)
319
320/*
321 * PBF registers
322 * Most are for debug. Driver doesn't touch PBF register.
323 */
324#define PBF_CFG 0x0408
325#define PBF_MAX_PCNT 0x040c
326#define PBF_CTRL 0x0410
327#define PBF_INT_STA 0x0414
328#define PBF_INT_ENA 0x0418
329
330/*
331 * BCN_OFFSET0:
332 */
333#define BCN_OFFSET0 0x042c
334#define BCN_OFFSET0_BCN0 FIELD32(0x000000ff)
335#define BCN_OFFSET0_BCN1 FIELD32(0x0000ff00)
336#define BCN_OFFSET0_BCN2 FIELD32(0x00ff0000)
337#define BCN_OFFSET0_BCN3 FIELD32(0xff000000)
338
339/*
340 * BCN_OFFSET1:
341 */
342#define BCN_OFFSET1 0x0430
343#define BCN_OFFSET1_BCN4 FIELD32(0x000000ff)
344#define BCN_OFFSET1_BCN5 FIELD32(0x0000ff00)
345#define BCN_OFFSET1_BCN6 FIELD32(0x00ff0000)
346#define BCN_OFFSET1_BCN7 FIELD32(0xff000000)
347
348/*
349 * PBF registers
350 * Most are for debug. Driver doesn't touch PBF register.
351 */
352#define TXRXQ_PCNT 0x0438
353#define PBF_DBG 0x043c
354
355/*
356 * RF registers
357 */
358#define RF_CSR_CFG 0x0500
359#define RF_CSR_CFG_DATA FIELD32(0x000000ff)
360#define RF_CSR_CFG_REGNUM FIELD32(0x00001f00)
361#define RF_CSR_CFG_WRITE FIELD32(0x00010000)
362#define RF_CSR_CFG_BUSY FIELD32(0x00020000)
363
364/*
365 * MAC Control/Status Registers(CSR).
366 * Some values are set in TU, whereas 1 TU == 1024 us.
367 */
368
369/*
370 * MAC_CSR0: ASIC revision number.
371 * ASIC_REV: 0
372 * ASIC_VER: 2860 or 2870
373 */
374#define MAC_CSR0 0x1000
375#define MAC_CSR0_ASIC_REV FIELD32(0x0000ffff)
376#define MAC_CSR0_ASIC_VER FIELD32(0xffff0000)
377
378/*
379 * MAC_SYS_CTRL:
380 */
381#define MAC_SYS_CTRL 0x1004
382#define MAC_SYS_CTRL_RESET_CSR FIELD32(0x00000001)
383#define MAC_SYS_CTRL_RESET_BBP FIELD32(0x00000002)
384#define MAC_SYS_CTRL_ENABLE_TX FIELD32(0x00000004)
385#define MAC_SYS_CTRL_ENABLE_RX FIELD32(0x00000008)
386#define MAC_SYS_CTRL_CONTINUOUS_TX FIELD32(0x00000010)
387#define MAC_SYS_CTRL_LOOPBACK FIELD32(0x00000020)
388#define MAC_SYS_CTRL_WLAN_HALT FIELD32(0x00000040)
389#define MAC_SYS_CTRL_RX_TIMESTAMP FIELD32(0x00000080)
390
391/*
392 * MAC_ADDR_DW0: STA MAC register 0
393 */
394#define MAC_ADDR_DW0 0x1008
395#define MAC_ADDR_DW0_BYTE0 FIELD32(0x000000ff)
396#define MAC_ADDR_DW0_BYTE1 FIELD32(0x0000ff00)
397#define MAC_ADDR_DW0_BYTE2 FIELD32(0x00ff0000)
398#define MAC_ADDR_DW0_BYTE3 FIELD32(0xff000000)
399
400/*
401 * MAC_ADDR_DW1: STA MAC register 1
402 * UNICAST_TO_ME_MASK:
403 * Used to mask off bits from byte 5 of the MAC address
404 * to determine the UNICAST_TO_ME bit for RX frames.
405 * The full mask is complemented by BSS_ID_MASK:
406 * MASK = BSS_ID_MASK & UNICAST_TO_ME_MASK
407 */
408#define MAC_ADDR_DW1 0x100c
409#define MAC_ADDR_DW1_BYTE4 FIELD32(0x000000ff)
410#define MAC_ADDR_DW1_BYTE5 FIELD32(0x0000ff00)
411#define MAC_ADDR_DW1_UNICAST_TO_ME_MASK FIELD32(0x00ff0000)
412
413/*
414 * MAC_BSSID_DW0: BSSID register 0
415 */
416#define MAC_BSSID_DW0 0x1010
417#define MAC_BSSID_DW0_BYTE0 FIELD32(0x000000ff)
418#define MAC_BSSID_DW0_BYTE1 FIELD32(0x0000ff00)
419#define MAC_BSSID_DW0_BYTE2 FIELD32(0x00ff0000)
420#define MAC_BSSID_DW0_BYTE3 FIELD32(0xff000000)
421
422/*
423 * MAC_BSSID_DW1: BSSID register 1
424 * BSS_ID_MASK:
425 * 0: 1-BSSID mode (BSS index = 0)
426 * 1: 2-BSSID mode (BSS index: Byte5, bit 0)
427 * 2: 4-BSSID mode (BSS index: byte5, bit 0 - 1)
428 * 3: 8-BSSID mode (BSS index: byte5, bit 0 - 2)
429 * This mask is used to mask off bits 0, 1 and 2 of byte 5 of the
430 * BSSID. This will make sure that those bits will be ignored
431 * when determining the MY_BSS of RX frames.
432 */
433#define MAC_BSSID_DW1 0x1014
434#define MAC_BSSID_DW1_BYTE4 FIELD32(0x000000ff)
435#define MAC_BSSID_DW1_BYTE5 FIELD32(0x0000ff00)
436#define MAC_BSSID_DW1_BSS_ID_MASK FIELD32(0x00030000)
437#define MAC_BSSID_DW1_BSS_BCN_NUM FIELD32(0x001c0000)
438
439/*
440 * MAX_LEN_CFG: Maximum frame length register.
441 * MAX_MPDU: rt2860b max 16k bytes
442 * MAX_PSDU: Maximum PSDU length
443 * (power factor) 0:2^13, 1:2^14, 2:2^15, 3:2^16
444 */
445#define MAX_LEN_CFG 0x1018
446#define MAX_LEN_CFG_MAX_MPDU FIELD32(0x00000fff)
447#define MAX_LEN_CFG_MAX_PSDU FIELD32(0x00003000)
448#define MAX_LEN_CFG_MIN_PSDU FIELD32(0x0000c000)
449#define MAX_LEN_CFG_MIN_MPDU FIELD32(0x000f0000)
450
451/*
452 * BBP_CSR_CFG: BBP serial control register
453 * VALUE: Register value to program into BBP
454 * REG_NUM: Selected BBP register
455 * READ_CONTROL: 0 write BBP, 1 read BBP
456 * BUSY: ASIC is busy executing BBP commands
457 * BBP_PAR_DUR: 0 4 MAC clocks, 1 8 MAC clocks
458 * BBP_RW_MODE: 0 serial, 1 paralell
459 */
460#define BBP_CSR_CFG 0x101c
461#define BBP_CSR_CFG_VALUE FIELD32(0x000000ff)
462#define BBP_CSR_CFG_REGNUM FIELD32(0x0000ff00)
463#define BBP_CSR_CFG_READ_CONTROL FIELD32(0x00010000)
464#define BBP_CSR_CFG_BUSY FIELD32(0x00020000)
465#define BBP_CSR_CFG_BBP_PAR_DUR FIELD32(0x00040000)
466#define BBP_CSR_CFG_BBP_RW_MODE FIELD32(0x00080000)
467
468/*
469 * RF_CSR_CFG0: RF control register
470 * REGID_AND_VALUE: Register value to program into RF
471 * BITWIDTH: Selected RF register
472 * STANDBYMODE: 0 high when standby, 1 low when standby
473 * SEL: 0 RF_LE0 activate, 1 RF_LE1 activate
474 * BUSY: ASIC is busy executing RF commands
475 */
476#define RF_CSR_CFG0 0x1020
477#define RF_CSR_CFG0_REGID_AND_VALUE FIELD32(0x00ffffff)
478#define RF_CSR_CFG0_BITWIDTH FIELD32(0x1f000000)
479#define RF_CSR_CFG0_REG_VALUE_BW FIELD32(0x1fffffff)
480#define RF_CSR_CFG0_STANDBYMODE FIELD32(0x20000000)
481#define RF_CSR_CFG0_SEL FIELD32(0x40000000)
482#define RF_CSR_CFG0_BUSY FIELD32(0x80000000)
483
484/*
485 * RF_CSR_CFG1: RF control register
486 * REGID_AND_VALUE: Register value to program into RF
487 * RFGAP: Gap between BB_CONTROL_RF and RF_LE
488 * 0: 3 system clock cycle (37.5usec)
489 * 1: 5 system clock cycle (62.5usec)
490 */
491#define RF_CSR_CFG1 0x1024
492#define RF_CSR_CFG1_REGID_AND_VALUE FIELD32(0x00ffffff)
493#define RF_CSR_CFG1_RFGAP FIELD32(0x1f000000)
494
495/*
496 * RF_CSR_CFG2: RF control register
497 * VALUE: Register value to program into RF
498 */
499#define RF_CSR_CFG2 0x1028
500#define RF_CSR_CFG2_VALUE FIELD32(0x00ffffff)
501
502/*
503 * LED_CFG: LED control
504 * color LED's:
505 * 0: off
506 * 1: blinking upon TX2
507 * 2: periodic slow blinking
508 * 3: always on
509 * LED polarity:
510 * 0: active low
511 * 1: active high
512 */
513#define LED_CFG 0x102c
514#define LED_CFG_ON_PERIOD FIELD32(0x000000ff)
515#define LED_CFG_OFF_PERIOD FIELD32(0x0000ff00)
516#define LED_CFG_SLOW_BLINK_PERIOD FIELD32(0x003f0000)
517#define LED_CFG_R_LED_MODE FIELD32(0x03000000)
518#define LED_CFG_G_LED_MODE FIELD32(0x0c000000)
519#define LED_CFG_Y_LED_MODE FIELD32(0x30000000)
520#define LED_CFG_LED_POLAR FIELD32(0x40000000)
521
522/*
523 * XIFS_TIME_CFG: MAC timing
524 * CCKM_SIFS_TIME: unit 1us. Applied after CCK RX/TX
525 * OFDM_SIFS_TIME: unit 1us. Applied after OFDM RX/TX
526 * OFDM_XIFS_TIME: unit 1us. Applied after OFDM RX
527 * when MAC doesn't reference BBP signal BBRXEND
528 * EIFS: unit 1us
529 * BB_RXEND_ENABLE: reference RXEND signal to begin XIFS defer
530 *
531 */
532#define XIFS_TIME_CFG 0x1100
533#define XIFS_TIME_CFG_CCKM_SIFS_TIME FIELD32(0x000000ff)
534#define XIFS_TIME_CFG_OFDM_SIFS_TIME FIELD32(0x0000ff00)
535#define XIFS_TIME_CFG_OFDM_XIFS_TIME FIELD32(0x000f0000)
536#define XIFS_TIME_CFG_EIFS FIELD32(0x1ff00000)
537#define XIFS_TIME_CFG_BB_RXEND_ENABLE FIELD32(0x20000000)
538
539/*
540 * BKOFF_SLOT_CFG:
541 */
542#define BKOFF_SLOT_CFG 0x1104
543#define BKOFF_SLOT_CFG_SLOT_TIME FIELD32(0x000000ff)
544#define BKOFF_SLOT_CFG_CC_DELAY_TIME FIELD32(0x0000ff00)
545
546/*
547 * NAV_TIME_CFG:
548 */
549#define NAV_TIME_CFG 0x1108
550#define NAV_TIME_CFG_SIFS FIELD32(0x000000ff)
551#define NAV_TIME_CFG_SLOT_TIME FIELD32(0x0000ff00)
552#define NAV_TIME_CFG_EIFS FIELD32(0x01ff0000)
553#define NAV_TIME_ZERO_SIFS FIELD32(0x02000000)
554
555/*
556 * CH_TIME_CFG: count as channel busy
557 */
558#define CH_TIME_CFG 0x110c
559
560/*
561 * PBF_LIFE_TIMER: TX/RX MPDU timestamp timer (free run) Unit: 1us
562 */
563#define PBF_LIFE_TIMER 0x1110
564
565/*
566 * BCN_TIME_CFG:
567 * BEACON_INTERVAL: in unit of 1/16 TU
568 * TSF_TICKING: Enable TSF auto counting
569 * TSF_SYNC: Enable TSF sync, 00: disable, 01: infra mode, 10: ad-hoc mode
570 * BEACON_GEN: Enable beacon generator
571 */
572#define BCN_TIME_CFG 0x1114
573#define BCN_TIME_CFG_BEACON_INTERVAL FIELD32(0x0000ffff)
574#define BCN_TIME_CFG_TSF_TICKING FIELD32(0x00010000)
575#define BCN_TIME_CFG_TSF_SYNC FIELD32(0x00060000)
576#define BCN_TIME_CFG_TBTT_ENABLE FIELD32(0x00080000)
577#define BCN_TIME_CFG_BEACON_GEN FIELD32(0x00100000)
578#define BCN_TIME_CFG_TX_TIME_COMPENSATE FIELD32(0xf0000000)
579
580/*
581 * TBTT_SYNC_CFG:
582 */
583#define TBTT_SYNC_CFG 0x1118
584
585/*
586 * TSF_TIMER_DW0: Local lsb TSF timer, read-only
587 */
588#define TSF_TIMER_DW0 0x111c
589#define TSF_TIMER_DW0_LOW_WORD FIELD32(0xffffffff)
590
591/*
592 * TSF_TIMER_DW1: Local msb TSF timer, read-only
593 */
594#define TSF_TIMER_DW1 0x1120
595#define TSF_TIMER_DW1_HIGH_WORD FIELD32(0xffffffff)
596
597/*
598 * TBTT_TIMER: TImer remains till next TBTT, read-only
599 */
600#define TBTT_TIMER 0x1124
601
602/*
603 * INT_TIMER_CFG:
604 */
605#define INT_TIMER_CFG 0x1128
606
607/*
608 * INT_TIMER_EN: GP-timer and pre-tbtt Int enable
609 */
610#define INT_TIMER_EN 0x112c
611
612/*
613 * CH_IDLE_STA: channel idle time
614 */
615#define CH_IDLE_STA 0x1130
616
617/*
618 * CH_BUSY_STA: channel busy time
619 */
620#define CH_BUSY_STA 0x1134
621
622/*
623 * MAC_STATUS_CFG:
624 * BBP_RF_BUSY: When set to 0, BBP and RF are stable.
625 * if 1 or higher one of the 2 registers is busy.
626 */
627#define MAC_STATUS_CFG 0x1200
628#define MAC_STATUS_CFG_BBP_RF_BUSY FIELD32(0x00000003)
629
630/*
631 * PWR_PIN_CFG:
632 */
633#define PWR_PIN_CFG 0x1204
634
635/*
636 * AUTOWAKEUP_CFG: Manual power control / status register
637 * TBCN_BEFORE_WAKE: ForceWake has high privilege than PutToSleep when both set
638 * AUTOWAKE: 0:sleep, 1:awake
639 */
640#define AUTOWAKEUP_CFG 0x1208
641#define AUTOWAKEUP_CFG_AUTO_LEAD_TIME FIELD32(0x000000ff)
642#define AUTOWAKEUP_CFG_TBCN_BEFORE_WAKE FIELD32(0x00007f00)
643#define AUTOWAKEUP_CFG_AUTOWAKE FIELD32(0x00008000)
644
645/*
646 * EDCA_AC0_CFG:
647 */
648#define EDCA_AC0_CFG 0x1300
649#define EDCA_AC0_CFG_TX_OP FIELD32(0x000000ff)
650#define EDCA_AC0_CFG_AIFSN FIELD32(0x00000f00)
651#define EDCA_AC0_CFG_CWMIN FIELD32(0x0000f000)
652#define EDCA_AC0_CFG_CWMAX FIELD32(0x000f0000)
653
654/*
655 * EDCA_AC1_CFG:
656 */
657#define EDCA_AC1_CFG 0x1304
658#define EDCA_AC1_CFG_TX_OP FIELD32(0x000000ff)
659#define EDCA_AC1_CFG_AIFSN FIELD32(0x00000f00)
660#define EDCA_AC1_CFG_CWMIN FIELD32(0x0000f000)
661#define EDCA_AC1_CFG_CWMAX FIELD32(0x000f0000)
662
663/*
664 * EDCA_AC2_CFG:
665 */
666#define EDCA_AC2_CFG 0x1308
667#define EDCA_AC2_CFG_TX_OP FIELD32(0x000000ff)
668#define EDCA_AC2_CFG_AIFSN FIELD32(0x00000f00)
669#define EDCA_AC2_CFG_CWMIN FIELD32(0x0000f000)
670#define EDCA_AC2_CFG_CWMAX FIELD32(0x000f0000)
671
672/*
673 * EDCA_AC3_CFG:
674 */
675#define EDCA_AC3_CFG 0x130c
676#define EDCA_AC3_CFG_TX_OP FIELD32(0x000000ff)
677#define EDCA_AC3_CFG_AIFSN FIELD32(0x00000f00)
678#define EDCA_AC3_CFG_CWMIN FIELD32(0x0000f000)
679#define EDCA_AC3_CFG_CWMAX FIELD32(0x000f0000)
680
681/*
682 * EDCA_TID_AC_MAP:
683 */
684#define EDCA_TID_AC_MAP 0x1310
685
686/*
687 * TX_PWR_CFG_0:
688 */
689#define TX_PWR_CFG_0 0x1314
690#define TX_PWR_CFG_0_1MBS FIELD32(0x0000000f)
691#define TX_PWR_CFG_0_2MBS FIELD32(0x000000f0)
692#define TX_PWR_CFG_0_55MBS FIELD32(0x00000f00)
693#define TX_PWR_CFG_0_11MBS FIELD32(0x0000f000)
694#define TX_PWR_CFG_0_6MBS FIELD32(0x000f0000)
695#define TX_PWR_CFG_0_9MBS FIELD32(0x00f00000)
696#define TX_PWR_CFG_0_12MBS FIELD32(0x0f000000)
697#define TX_PWR_CFG_0_18MBS FIELD32(0xf0000000)
698
699/*
700 * TX_PWR_CFG_1:
701 */
702#define TX_PWR_CFG_1 0x1318
703#define TX_PWR_CFG_1_24MBS FIELD32(0x0000000f)
704#define TX_PWR_CFG_1_36MBS FIELD32(0x000000f0)
705#define TX_PWR_CFG_1_48MBS FIELD32(0x00000f00)
706#define TX_PWR_CFG_1_54MBS FIELD32(0x0000f000)
707#define TX_PWR_CFG_1_MCS0 FIELD32(0x000f0000)
708#define TX_PWR_CFG_1_MCS1 FIELD32(0x00f00000)
709#define TX_PWR_CFG_1_MCS2 FIELD32(0x0f000000)
710#define TX_PWR_CFG_1_MCS3 FIELD32(0xf0000000)
711
712/*
713 * TX_PWR_CFG_2:
714 */
715#define TX_PWR_CFG_2 0x131c
716#define TX_PWR_CFG_2_MCS4 FIELD32(0x0000000f)
717#define TX_PWR_CFG_2_MCS5 FIELD32(0x000000f0)
718#define TX_PWR_CFG_2_MCS6 FIELD32(0x00000f00)
719#define TX_PWR_CFG_2_MCS7 FIELD32(0x0000f000)
720#define TX_PWR_CFG_2_MCS8 FIELD32(0x000f0000)
721#define TX_PWR_CFG_2_MCS9 FIELD32(0x00f00000)
722#define TX_PWR_CFG_2_MCS10 FIELD32(0x0f000000)
723#define TX_PWR_CFG_2_MCS11 FIELD32(0xf0000000)
724
725/*
726 * TX_PWR_CFG_3:
727 */
728#define TX_PWR_CFG_3 0x1320
729#define TX_PWR_CFG_3_MCS12 FIELD32(0x0000000f)
730#define TX_PWR_CFG_3_MCS13 FIELD32(0x000000f0)
731#define TX_PWR_CFG_3_MCS14 FIELD32(0x00000f00)
732#define TX_PWR_CFG_3_MCS15 FIELD32(0x0000f000)
733#define TX_PWR_CFG_3_UKNOWN1 FIELD32(0x000f0000)
734#define TX_PWR_CFG_3_UKNOWN2 FIELD32(0x00f00000)
735#define TX_PWR_CFG_3_UKNOWN3 FIELD32(0x0f000000)
736#define TX_PWR_CFG_3_UKNOWN4 FIELD32(0xf0000000)
737
738/*
739 * TX_PWR_CFG_4:
740 */
741#define TX_PWR_CFG_4 0x1324
742#define TX_PWR_CFG_4_UKNOWN5 FIELD32(0x0000000f)
743#define TX_PWR_CFG_4_UKNOWN6 FIELD32(0x000000f0)
744#define TX_PWR_CFG_4_UKNOWN7 FIELD32(0x00000f00)
745#define TX_PWR_CFG_4_UKNOWN8 FIELD32(0x0000f000)
746
747/*
748 * TX_PIN_CFG:
749 */
750#define TX_PIN_CFG 0x1328
751#define TX_PIN_CFG_PA_PE_A0_EN FIELD32(0x00000001)
752#define TX_PIN_CFG_PA_PE_G0_EN FIELD32(0x00000002)
753#define TX_PIN_CFG_PA_PE_A1_EN FIELD32(0x00000004)
754#define TX_PIN_CFG_PA_PE_G1_EN FIELD32(0x00000008)
755#define TX_PIN_CFG_PA_PE_A0_POL FIELD32(0x00000010)
756#define TX_PIN_CFG_PA_PE_G0_POL FIELD32(0x00000020)
757#define TX_PIN_CFG_PA_PE_A1_POL FIELD32(0x00000040)
758#define TX_PIN_CFG_PA_PE_G1_POL FIELD32(0x00000080)
759#define TX_PIN_CFG_LNA_PE_A0_EN FIELD32(0x00000100)
760#define TX_PIN_CFG_LNA_PE_G0_EN FIELD32(0x00000200)
761#define TX_PIN_CFG_LNA_PE_A1_EN FIELD32(0x00000400)
762#define TX_PIN_CFG_LNA_PE_G1_EN FIELD32(0x00000800)
763#define TX_PIN_CFG_LNA_PE_A0_POL FIELD32(0x00001000)
764#define TX_PIN_CFG_LNA_PE_G0_POL FIELD32(0x00002000)
765#define TX_PIN_CFG_LNA_PE_A1_POL FIELD32(0x00004000)
766#define TX_PIN_CFG_LNA_PE_G1_POL FIELD32(0x00008000)
767#define TX_PIN_CFG_RFTR_EN FIELD32(0x00010000)
768#define TX_PIN_CFG_RFTR_POL FIELD32(0x00020000)
769#define TX_PIN_CFG_TRSW_EN FIELD32(0x00040000)
770#define TX_PIN_CFG_TRSW_POL FIELD32(0x00080000)
771
772/*
773 * TX_BAND_CFG: 0x1 use upper 20MHz, 0x0 use lower 20MHz
774 */
775#define TX_BAND_CFG 0x132c
776#define TX_BAND_CFG_HT40_PLUS FIELD32(0x00000001)
777#define TX_BAND_CFG_A FIELD32(0x00000002)
778#define TX_BAND_CFG_BG FIELD32(0x00000004)
779
780/*
781 * TX_SW_CFG0:
782 */
783#define TX_SW_CFG0 0x1330
784
785/*
786 * TX_SW_CFG1:
787 */
788#define TX_SW_CFG1 0x1334
789
790/*
791 * TX_SW_CFG2:
792 */
793#define TX_SW_CFG2 0x1338
794
795/*
796 * TXOP_THRES_CFG:
797 */
798#define TXOP_THRES_CFG 0x133c
799
800/*
801 * TXOP_CTRL_CFG:
802 */
803#define TXOP_CTRL_CFG 0x1340
804
805/*
806 * TX_RTS_CFG:
807 * RTS_THRES: unit:byte
808 * RTS_FBK_EN: enable rts rate fallback
809 */
810#define TX_RTS_CFG 0x1344
811#define TX_RTS_CFG_AUTO_RTS_RETRY_LIMIT FIELD32(0x000000ff)
812#define TX_RTS_CFG_RTS_THRES FIELD32(0x00ffff00)
813#define TX_RTS_CFG_RTS_FBK_EN FIELD32(0x01000000)
814
815/*
816 * TX_TIMEOUT_CFG:
817 * MPDU_LIFETIME: expiration time = 2^(9+MPDU LIFE TIME) us
818 * RX_ACK_TIMEOUT: unit:slot. Used for TX procedure
819 * TX_OP_TIMEOUT: TXOP timeout value for TXOP truncation.
820 * it is recommended that:
821 * (SLOT_TIME) > (TX_OP_TIMEOUT) > (RX_ACK_TIMEOUT)
822 */
823#define TX_TIMEOUT_CFG 0x1348
824#define TX_TIMEOUT_CFG_MPDU_LIFETIME FIELD32(0x000000f0)
825#define TX_TIMEOUT_CFG_RX_ACK_TIMEOUT FIELD32(0x0000ff00)
826#define TX_TIMEOUT_CFG_TX_OP_TIMEOUT FIELD32(0x00ff0000)
827
828/*
829 * TX_RTY_CFG:
830 * SHORT_RTY_LIMIT: short retry limit
831 * LONG_RTY_LIMIT: long retry limit
832 * LONG_RTY_THRE: Long retry threshoold
833 * NON_AGG_RTY_MODE: Non-Aggregate MPDU retry mode
834 * 0:expired by retry limit, 1: expired by mpdu life timer
835 * AGG_RTY_MODE: Aggregate MPDU retry mode
836 * 0:expired by retry limit, 1: expired by mpdu life timer
837 * TX_AUTO_FB_ENABLE: Tx retry PHY rate auto fallback enable
838 */
839#define TX_RTY_CFG 0x134c
840#define TX_RTY_CFG_SHORT_RTY_LIMIT FIELD32(0x000000ff)
841#define TX_RTY_CFG_LONG_RTY_LIMIT FIELD32(0x0000ff00)
842#define TX_RTY_CFG_LONG_RTY_THRE FIELD32(0x0fff0000)
843#define TX_RTY_CFG_NON_AGG_RTY_MODE FIELD32(0x10000000)
844#define TX_RTY_CFG_AGG_RTY_MODE FIELD32(0x20000000)
845#define TX_RTY_CFG_TX_AUTO_FB_ENABLE FIELD32(0x40000000)
846
847/*
848 * TX_LINK_CFG:
849 * REMOTE_MFB_LIFETIME: remote MFB life time. unit: 32us
850 * MFB_ENABLE: TX apply remote MFB 1:enable
851 * REMOTE_UMFS_ENABLE: remote unsolicit MFB enable
852 * 0: not apply remote remote unsolicit (MFS=7)
853 * TX_MRQ_EN: MCS request TX enable
854 * TX_RDG_EN: RDG TX enable
855 * TX_CF_ACK_EN: Piggyback CF-ACK enable
856 * REMOTE_MFB: remote MCS feedback
857 * REMOTE_MFS: remote MCS feedback sequence number
858 */
859#define TX_LINK_CFG 0x1350
860#define TX_LINK_CFG_REMOTE_MFB_LIFETIME FIELD32(0x000000ff)
861#define TX_LINK_CFG_MFB_ENABLE FIELD32(0x00000100)
862#define TX_LINK_CFG_REMOTE_UMFS_ENABLE FIELD32(0x00000200)
863#define TX_LINK_CFG_TX_MRQ_EN FIELD32(0x00000400)
864#define TX_LINK_CFG_TX_RDG_EN FIELD32(0x00000800)
865#define TX_LINK_CFG_TX_CF_ACK_EN FIELD32(0x00001000)
866#define TX_LINK_CFG_REMOTE_MFB FIELD32(0x00ff0000)
867#define TX_LINK_CFG_REMOTE_MFS FIELD32(0xff000000)
868
869/*
870 * HT_FBK_CFG0:
871 */
872#define HT_FBK_CFG0 0x1354
873#define HT_FBK_CFG0_HTMCS0FBK FIELD32(0x0000000f)
874#define HT_FBK_CFG0_HTMCS1FBK FIELD32(0x000000f0)
875#define HT_FBK_CFG0_HTMCS2FBK FIELD32(0x00000f00)
876#define HT_FBK_CFG0_HTMCS3FBK FIELD32(0x0000f000)
877#define HT_FBK_CFG0_HTMCS4FBK FIELD32(0x000f0000)
878#define HT_FBK_CFG0_HTMCS5FBK FIELD32(0x00f00000)
879#define HT_FBK_CFG0_HTMCS6FBK FIELD32(0x0f000000)
880#define HT_FBK_CFG0_HTMCS7FBK FIELD32(0xf0000000)
881
882/*
883 * HT_FBK_CFG1:
884 */
885#define HT_FBK_CFG1 0x1358
886#define HT_FBK_CFG1_HTMCS8FBK FIELD32(0x0000000f)
887#define HT_FBK_CFG1_HTMCS9FBK FIELD32(0x000000f0)
888#define HT_FBK_CFG1_HTMCS10FBK FIELD32(0x00000f00)
889#define HT_FBK_CFG1_HTMCS11FBK FIELD32(0x0000f000)
890#define HT_FBK_CFG1_HTMCS12FBK FIELD32(0x000f0000)
891#define HT_FBK_CFG1_HTMCS13FBK FIELD32(0x00f00000)
892#define HT_FBK_CFG1_HTMCS14FBK FIELD32(0x0f000000)
893#define HT_FBK_CFG1_HTMCS15FBK FIELD32(0xf0000000)
894
895/*
896 * LG_FBK_CFG0:
897 */
898#define LG_FBK_CFG0 0x135c
899#define LG_FBK_CFG0_OFDMMCS0FBK FIELD32(0x0000000f)
900#define LG_FBK_CFG0_OFDMMCS1FBK FIELD32(0x000000f0)
901#define LG_FBK_CFG0_OFDMMCS2FBK FIELD32(0x00000f00)
902#define LG_FBK_CFG0_OFDMMCS3FBK FIELD32(0x0000f000)
903#define LG_FBK_CFG0_OFDMMCS4FBK FIELD32(0x000f0000)
904#define LG_FBK_CFG0_OFDMMCS5FBK FIELD32(0x00f00000)
905#define LG_FBK_CFG0_OFDMMCS6FBK FIELD32(0x0f000000)
906#define LG_FBK_CFG0_OFDMMCS7FBK FIELD32(0xf0000000)
907
908/*
909 * LG_FBK_CFG1:
910 */
911#define LG_FBK_CFG1 0x1360
912#define LG_FBK_CFG0_CCKMCS0FBK FIELD32(0x0000000f)
913#define LG_FBK_CFG0_CCKMCS1FBK FIELD32(0x000000f0)
914#define LG_FBK_CFG0_CCKMCS2FBK FIELD32(0x00000f00)
915#define LG_FBK_CFG0_CCKMCS3FBK FIELD32(0x0000f000)
916
917/*
918 * CCK_PROT_CFG: CCK Protection
919 * PROTECT_RATE: Protection control frame rate for CCK TX(RTS/CTS/CFEnd)
920 * PROTECT_CTRL: Protection control frame type for CCK TX
921 * 0:none, 1:RTS/CTS, 2:CTS-to-self
922 * PROTECT_NAV: TXOP protection type for CCK TX
923 * 0:none, 1:ShortNAVprotect, 2:LongNAVProtect
924 * TX_OP_ALLOW_CCK: CCK TXOP allowance, 0:disallow
925 * TX_OP_ALLOW_OFDM: CCK TXOP allowance, 0:disallow
926 * TX_OP_ALLOW_MM20: CCK TXOP allowance, 0:disallow
927 * TX_OP_ALLOW_MM40: CCK TXOP allowance, 0:disallow
928 * TX_OP_ALLOW_GF20: CCK TXOP allowance, 0:disallow
929 * TX_OP_ALLOW_GF40: CCK TXOP allowance, 0:disallow
930 * RTS_TH_EN: RTS threshold enable on CCK TX
931 */
932#define CCK_PROT_CFG 0x1364
933#define CCK_PROT_CFG_PROTECT_RATE FIELD32(0x0000ffff)
934#define CCK_PROT_CFG_PROTECT_CTRL FIELD32(0x00030000)
935#define CCK_PROT_CFG_PROTECT_NAV FIELD32(0x000c0000)
936#define CCK_PROT_CFG_TX_OP_ALLOW_CCK FIELD32(0x00100000)
937#define CCK_PROT_CFG_TX_OP_ALLOW_OFDM FIELD32(0x00200000)
938#define CCK_PROT_CFG_TX_OP_ALLOW_MM20 FIELD32(0x00400000)
939#define CCK_PROT_CFG_TX_OP_ALLOW_MM40 FIELD32(0x00800000)
940#define CCK_PROT_CFG_TX_OP_ALLOW_GF20 FIELD32(0x01000000)
941#define CCK_PROT_CFG_TX_OP_ALLOW_GF40 FIELD32(0x02000000)
942#define CCK_PROT_CFG_RTS_TH_EN FIELD32(0x04000000)
943
944/*
945 * OFDM_PROT_CFG: OFDM Protection
946 */
947#define OFDM_PROT_CFG 0x1368
948#define OFDM_PROT_CFG_PROTECT_RATE FIELD32(0x0000ffff)
949#define OFDM_PROT_CFG_PROTECT_CTRL FIELD32(0x00030000)
950#define OFDM_PROT_CFG_PROTECT_NAV FIELD32(0x000c0000)
951#define OFDM_PROT_CFG_TX_OP_ALLOW_CCK FIELD32(0x00100000)
952#define OFDM_PROT_CFG_TX_OP_ALLOW_OFDM FIELD32(0x00200000)
953#define OFDM_PROT_CFG_TX_OP_ALLOW_MM20 FIELD32(0x00400000)
954#define OFDM_PROT_CFG_TX_OP_ALLOW_MM40 FIELD32(0x00800000)
955#define OFDM_PROT_CFG_TX_OP_ALLOW_GF20 FIELD32(0x01000000)
956#define OFDM_PROT_CFG_TX_OP_ALLOW_GF40 FIELD32(0x02000000)
957#define OFDM_PROT_CFG_RTS_TH_EN FIELD32(0x04000000)
958
959/*
960 * MM20_PROT_CFG: MM20 Protection
961 */
962#define MM20_PROT_CFG 0x136c
963#define MM20_PROT_CFG_PROTECT_RATE FIELD32(0x0000ffff)
964#define MM20_PROT_CFG_PROTECT_CTRL FIELD32(0x00030000)
965#define MM20_PROT_CFG_PROTECT_NAV FIELD32(0x000c0000)
966#define MM20_PROT_CFG_TX_OP_ALLOW_CCK FIELD32(0x00100000)
967#define MM20_PROT_CFG_TX_OP_ALLOW_OFDM FIELD32(0x00200000)
968#define MM20_PROT_CFG_TX_OP_ALLOW_MM20 FIELD32(0x00400000)
969#define MM20_PROT_CFG_TX_OP_ALLOW_MM40 FIELD32(0x00800000)
970#define MM20_PROT_CFG_TX_OP_ALLOW_GF20 FIELD32(0x01000000)
971#define MM20_PROT_CFG_TX_OP_ALLOW_GF40 FIELD32(0x02000000)
972#define MM20_PROT_CFG_RTS_TH_EN FIELD32(0x04000000)
973
974/*
975 * MM40_PROT_CFG: MM40 Protection
976 */
977#define MM40_PROT_CFG 0x1370
978#define MM40_PROT_CFG_PROTECT_RATE FIELD32(0x0000ffff)
979#define MM40_PROT_CFG_PROTECT_CTRL FIELD32(0x00030000)
980#define MM40_PROT_CFG_PROTECT_NAV FIELD32(0x000c0000)
981#define MM40_PROT_CFG_TX_OP_ALLOW_CCK FIELD32(0x00100000)
982#define MM40_PROT_CFG_TX_OP_ALLOW_OFDM FIELD32(0x00200000)
983#define MM40_PROT_CFG_TX_OP_ALLOW_MM20 FIELD32(0x00400000)
984#define MM40_PROT_CFG_TX_OP_ALLOW_MM40 FIELD32(0x00800000)
985#define MM40_PROT_CFG_TX_OP_ALLOW_GF20 FIELD32(0x01000000)
986#define MM40_PROT_CFG_TX_OP_ALLOW_GF40 FIELD32(0x02000000)
987#define MM40_PROT_CFG_RTS_TH_EN FIELD32(0x04000000)
988
989/*
990 * GF20_PROT_CFG: GF20 Protection
991 */
992#define GF20_PROT_CFG 0x1374
993#define GF20_PROT_CFG_PROTECT_RATE FIELD32(0x0000ffff)
994#define GF20_PROT_CFG_PROTECT_CTRL FIELD32(0x00030000)
995#define GF20_PROT_CFG_PROTECT_NAV FIELD32(0x000c0000)
996#define GF20_PROT_CFG_TX_OP_ALLOW_CCK FIELD32(0x00100000)
997#define GF20_PROT_CFG_TX_OP_ALLOW_OFDM FIELD32(0x00200000)
998#define GF20_PROT_CFG_TX_OP_ALLOW_MM20 FIELD32(0x00400000)
999#define GF20_PROT_CFG_TX_OP_ALLOW_MM40 FIELD32(0x00800000)
1000#define GF20_PROT_CFG_TX_OP_ALLOW_GF20 FIELD32(0x01000000)
1001#define GF20_PROT_CFG_TX_OP_ALLOW_GF40 FIELD32(0x02000000)
1002#define GF20_PROT_CFG_RTS_TH_EN FIELD32(0x04000000)
1003
1004/*
1005 * GF40_PROT_CFG: GF40 Protection
1006 */
1007#define GF40_PROT_CFG 0x1378
1008#define GF40_PROT_CFG_PROTECT_RATE FIELD32(0x0000ffff)
1009#define GF40_PROT_CFG_PROTECT_CTRL FIELD32(0x00030000)
1010#define GF40_PROT_CFG_PROTECT_NAV FIELD32(0x000c0000)
1011#define GF40_PROT_CFG_TX_OP_ALLOW_CCK FIELD32(0x00100000)
1012#define GF40_PROT_CFG_TX_OP_ALLOW_OFDM FIELD32(0x00200000)
1013#define GF40_PROT_CFG_TX_OP_ALLOW_MM20 FIELD32(0x00400000)
1014#define GF40_PROT_CFG_TX_OP_ALLOW_MM40 FIELD32(0x00800000)
1015#define GF40_PROT_CFG_TX_OP_ALLOW_GF20 FIELD32(0x01000000)
1016#define GF40_PROT_CFG_TX_OP_ALLOW_GF40 FIELD32(0x02000000)
1017#define GF40_PROT_CFG_RTS_TH_EN FIELD32(0x04000000)
1018
1019/*
1020 * EXP_CTS_TIME:
1021 */
1022#define EXP_CTS_TIME 0x137c
1023
1024/*
1025 * EXP_ACK_TIME:
1026 */
1027#define EXP_ACK_TIME 0x1380
1028
1029/*
1030 * RX_FILTER_CFG: RX configuration register.
1031 */
1032#define RX_FILTER_CFG 0x1400
1033#define RX_FILTER_CFG_DROP_CRC_ERROR FIELD32(0x00000001)
1034#define RX_FILTER_CFG_DROP_PHY_ERROR FIELD32(0x00000002)
1035#define RX_FILTER_CFG_DROP_NOT_TO_ME FIELD32(0x00000004)
1036#define RX_FILTER_CFG_DROP_NOT_MY_BSSD FIELD32(0x00000008)
1037#define RX_FILTER_CFG_DROP_VER_ERROR FIELD32(0x00000010)
1038#define RX_FILTER_CFG_DROP_MULTICAST FIELD32(0x00000020)
1039#define RX_FILTER_CFG_DROP_BROADCAST FIELD32(0x00000040)
1040#define RX_FILTER_CFG_DROP_DUPLICATE FIELD32(0x00000080)
1041#define RX_FILTER_CFG_DROP_CF_END_ACK FIELD32(0x00000100)
1042#define RX_FILTER_CFG_DROP_CF_END FIELD32(0x00000200)
1043#define RX_FILTER_CFG_DROP_ACK FIELD32(0x00000400)
1044#define RX_FILTER_CFG_DROP_CTS FIELD32(0x00000800)
1045#define RX_FILTER_CFG_DROP_RTS FIELD32(0x00001000)
1046#define RX_FILTER_CFG_DROP_PSPOLL FIELD32(0x00002000)
1047#define RX_FILTER_CFG_DROP_BA FIELD32(0x00004000)
1048#define RX_FILTER_CFG_DROP_BAR FIELD32(0x00008000)
1049#define RX_FILTER_CFG_DROP_CNTL FIELD32(0x00010000)
1050
1051/*
1052 * AUTO_RSP_CFG:
1053 * AUTORESPONDER: 0: disable, 1: enable
1054 * BAC_ACK_POLICY: 0:long, 1:short preamble
1055 * CTS_40_MMODE: Response CTS 40MHz duplicate mode
1056 * CTS_40_MREF: Response CTS 40MHz duplicate mode
1057 * AR_PREAMBLE: Auto responder preamble 0:long, 1:short preamble
1058 * DUAL_CTS_EN: Power bit value in control frame
1059 * ACK_CTS_PSM_BIT:Power bit value in control frame
1060 */
1061#define AUTO_RSP_CFG 0x1404
1062#define AUTO_RSP_CFG_AUTORESPONDER FIELD32(0x00000001)
1063#define AUTO_RSP_CFG_BAC_ACK_POLICY FIELD32(0x00000002)
1064#define AUTO_RSP_CFG_CTS_40_MMODE FIELD32(0x00000004)
1065#define AUTO_RSP_CFG_CTS_40_MREF FIELD32(0x00000008)
1066#define AUTO_RSP_CFG_AR_PREAMBLE FIELD32(0x00000010)
1067#define AUTO_RSP_CFG_DUAL_CTS_EN FIELD32(0x00000040)
1068#define AUTO_RSP_CFG_ACK_CTS_PSM_BIT FIELD32(0x00000080)
1069
1070/*
1071 * LEGACY_BASIC_RATE:
1072 */
1073#define LEGACY_BASIC_RATE 0x1408
1074
1075/*
1076 * HT_BASIC_RATE:
1077 */
1078#define HT_BASIC_RATE 0x140c
1079
1080/*
1081 * HT_CTRL_CFG:
1082 */
1083#define HT_CTRL_CFG 0x1410
1084
1085/*
1086 * SIFS_COST_CFG:
1087 */
1088#define SIFS_COST_CFG 0x1414
1089
1090/*
1091 * RX_PARSER_CFG:
1092 * Set NAV for all received frames
1093 */
1094#define RX_PARSER_CFG 0x1418
1095
1096/*
1097 * TX_SEC_CNT0:
1098 */
1099#define TX_SEC_CNT0 0x1500
1100
1101/*
1102 * RX_SEC_CNT0:
1103 */
1104#define RX_SEC_CNT0 0x1504
1105
1106/*
1107 * CCMP_FC_MUTE:
1108 */
1109#define CCMP_FC_MUTE 0x1508
1110
1111/*
1112 * TXOP_HLDR_ADDR0:
1113 */
1114#define TXOP_HLDR_ADDR0 0x1600
1115
1116/*
1117 * TXOP_HLDR_ADDR1:
1118 */
1119#define TXOP_HLDR_ADDR1 0x1604
1120
1121/*
1122 * TXOP_HLDR_ET:
1123 */
1124#define TXOP_HLDR_ET 0x1608
1125
1126/*
1127 * QOS_CFPOLL_RA_DW0:
1128 */
1129#define QOS_CFPOLL_RA_DW0 0x160c
1130
1131/*
1132 * QOS_CFPOLL_RA_DW1:
1133 */
1134#define QOS_CFPOLL_RA_DW1 0x1610
1135
1136/*
1137 * QOS_CFPOLL_QC:
1138 */
1139#define QOS_CFPOLL_QC 0x1614
1140
1141/*
1142 * RX_STA_CNT0: RX PLCP error count & RX CRC error count
1143 */
1144#define RX_STA_CNT0 0x1700
1145#define RX_STA_CNT0_CRC_ERR FIELD32(0x0000ffff)
1146#define RX_STA_CNT0_PHY_ERR FIELD32(0xffff0000)
1147
1148/*
1149 * RX_STA_CNT1: RX False CCA count & RX LONG frame count
1150 */
1151#define RX_STA_CNT1 0x1704
1152#define RX_STA_CNT1_FALSE_CCA FIELD32(0x0000ffff)
1153#define RX_STA_CNT1_PLCP_ERR FIELD32(0xffff0000)
1154
1155/*
1156 * RX_STA_CNT2:
1157 */
1158#define RX_STA_CNT2 0x1708
1159#define RX_STA_CNT2_RX_DUPLI_COUNT FIELD32(0x0000ffff)
1160#define RX_STA_CNT2_RX_FIFO_OVERFLOW FIELD32(0xffff0000)
1161
1162/*
1163 * TX_STA_CNT0: TX Beacon count
1164 */
1165#define TX_STA_CNT0 0x170c
1166#define TX_STA_CNT0_TX_FAIL_COUNT FIELD32(0x0000ffff)
1167#define TX_STA_CNT0_TX_BEACON_COUNT FIELD32(0xffff0000)
1168
1169/*
1170 * TX_STA_CNT1: TX tx count
1171 */
1172#define TX_STA_CNT1 0x1710
1173#define TX_STA_CNT1_TX_SUCCESS FIELD32(0x0000ffff)
1174#define TX_STA_CNT1_TX_RETRANSMIT FIELD32(0xffff0000)
1175
1176/*
1177 * TX_STA_CNT2: TX tx count
1178 */
1179#define TX_STA_CNT2 0x1714
1180#define TX_STA_CNT2_TX_ZERO_LEN_COUNT FIELD32(0x0000ffff)
1181#define TX_STA_CNT2_TX_UNDER_FLOW_COUNT FIELD32(0xffff0000)
1182
1183/*
1184 * TX_STA_FIFO: TX Result for specific PID status fifo register
1185 */
1186#define TX_STA_FIFO 0x1718
1187#define TX_STA_FIFO_VALID FIELD32(0x00000001)
1188#define TX_STA_FIFO_PID_TYPE FIELD32(0x0000001e)
1189#define TX_STA_FIFO_TX_SUCCESS FIELD32(0x00000020)
1190#define TX_STA_FIFO_TX_AGGRE FIELD32(0x00000040)
1191#define TX_STA_FIFO_TX_ACK_REQUIRED FIELD32(0x00000080)
1192#define TX_STA_FIFO_WCID FIELD32(0x0000ff00)
1193#define TX_STA_FIFO_SUCCESS_RATE FIELD32(0xffff0000)
1194#define TX_STA_FIFO_MCS FIELD32(0x007f0000)
1195#define TX_STA_FIFO_PHYMODE FIELD32(0xc0000000)
1196
1197/*
1198 * TX_AGG_CNT: Debug counter
1199 */
1200#define TX_AGG_CNT 0x171c
1201#define TX_AGG_CNT_NON_AGG_TX_COUNT FIELD32(0x0000ffff)
1202#define TX_AGG_CNT_AGG_TX_COUNT FIELD32(0xffff0000)
1203
1204/*
1205 * TX_AGG_CNT0:
1206 */
1207#define TX_AGG_CNT0 0x1720
1208#define TX_AGG_CNT0_AGG_SIZE_1_COUNT FIELD32(0x0000ffff)
1209#define TX_AGG_CNT0_AGG_SIZE_2_COUNT FIELD32(0xffff0000)
1210
1211/*
1212 * TX_AGG_CNT1:
1213 */
1214#define TX_AGG_CNT1 0x1724
1215#define TX_AGG_CNT1_AGG_SIZE_3_COUNT FIELD32(0x0000ffff)
1216#define TX_AGG_CNT1_AGG_SIZE_4_COUNT FIELD32(0xffff0000)
1217
1218/*
1219 * TX_AGG_CNT2:
1220 */
1221#define TX_AGG_CNT2 0x1728
1222#define TX_AGG_CNT2_AGG_SIZE_5_COUNT FIELD32(0x0000ffff)
1223#define TX_AGG_CNT2_AGG_SIZE_6_COUNT FIELD32(0xffff0000)
1224
1225/*
1226 * TX_AGG_CNT3:
1227 */
1228#define TX_AGG_CNT3 0x172c
1229#define TX_AGG_CNT3_AGG_SIZE_7_COUNT FIELD32(0x0000ffff)
1230#define TX_AGG_CNT3_AGG_SIZE_8_COUNT FIELD32(0xffff0000)
1231
1232/*
1233 * TX_AGG_CNT4:
1234 */
1235#define TX_AGG_CNT4 0x1730
1236#define TX_AGG_CNT4_AGG_SIZE_9_COUNT FIELD32(0x0000ffff)
1237#define TX_AGG_CNT4_AGG_SIZE_10_COUNT FIELD32(0xffff0000)
1238
1239/*
1240 * TX_AGG_CNT5:
1241 */
1242#define TX_AGG_CNT5 0x1734
1243#define TX_AGG_CNT5_AGG_SIZE_11_COUNT FIELD32(0x0000ffff)
1244#define TX_AGG_CNT5_AGG_SIZE_12_COUNT FIELD32(0xffff0000)
1245
1246/*
1247 * TX_AGG_CNT6:
1248 */
1249#define TX_AGG_CNT6 0x1738
1250#define TX_AGG_CNT6_AGG_SIZE_13_COUNT FIELD32(0x0000ffff)
1251#define TX_AGG_CNT6_AGG_SIZE_14_COUNT FIELD32(0xffff0000)
1252
1253/*
1254 * TX_AGG_CNT7:
1255 */
1256#define TX_AGG_CNT7 0x173c
1257#define TX_AGG_CNT7_AGG_SIZE_15_COUNT FIELD32(0x0000ffff)
1258#define TX_AGG_CNT7_AGG_SIZE_16_COUNT FIELD32(0xffff0000)
1259
1260/*
1261 * MPDU_DENSITY_CNT:
1262 * TX_ZERO_DEL: TX zero length delimiter count
1263 * RX_ZERO_DEL: RX zero length delimiter count
1264 */
1265#define MPDU_DENSITY_CNT 0x1740
1266#define MPDU_DENSITY_CNT_TX_ZERO_DEL FIELD32(0x0000ffff)
1267#define MPDU_DENSITY_CNT_RX_ZERO_DEL FIELD32(0xffff0000)
1268
1269/*
1270 * Security key table memory.
1271 * MAC_WCID_BASE: 8-bytes (use only 6 bytes) * 256 entry
1272 * PAIRWISE_KEY_TABLE_BASE: 32-byte * 256 entry
1273 * MAC_IVEIV_TABLE_BASE: 8-byte * 256-entry
1274 * MAC_WCID_ATTRIBUTE_BASE: 4-byte * 256-entry
1275 * SHARED_KEY_TABLE_BASE: 32-byte * 16-entry
1276 * SHARED_KEY_MODE_BASE: 4-byte * 16-entry
1277 */
1278#define MAC_WCID_BASE 0x1800
1279#define PAIRWISE_KEY_TABLE_BASE 0x4000
1280#define MAC_IVEIV_TABLE_BASE 0x6000
1281#define MAC_WCID_ATTRIBUTE_BASE 0x6800
1282#define SHARED_KEY_TABLE_BASE 0x6c00
1283#define SHARED_KEY_MODE_BASE 0x7000
1284
1285#define MAC_WCID_ENTRY(__idx) \
1286 ( MAC_WCID_BASE + ((__idx) * sizeof(struct mac_wcid_entry)) )
1287#define PAIRWISE_KEY_ENTRY(__idx) \
1288 ( PAIRWISE_KEY_TABLE_BASE + ((__idx) * sizeof(struct hw_key_entry)) )
1289#define MAC_IVEIV_ENTRY(__idx) \
1290 ( MAC_IVEIV_TABLE_BASE + ((__idx) & sizeof(struct mac_iveiv_entry)) )
1291#define MAC_WCID_ATTR_ENTRY(__idx) \
1292 ( MAC_WCID_ATTRIBUTE_BASE + ((__idx) * sizeof(u32)) )
1293#define SHARED_KEY_ENTRY(__idx) \
1294 ( SHARED_KEY_TABLE_BASE + ((__idx) * sizeof(struct hw_key_entry)) )
1295#define SHARED_KEY_MODE_ENTRY(__idx) \
1296 ( SHARED_KEY_MODE_BASE + ((__idx) * sizeof(u32)) )
1297
1298struct mac_wcid_entry {
1299 u8 mac[6];
1300 u8 reserved[2];
1301} __attribute__ ((packed));
1302
1303struct hw_key_entry {
1304 u8 key[16];
1305 u8 tx_mic[8];
1306 u8 rx_mic[8];
1307} __attribute__ ((packed));
1308
1309struct mac_iveiv_entry {
1310 u8 iv[8];
1311} __attribute__ ((packed));
1312
1313/*
1314 * MAC_WCID_ATTRIBUTE:
1315 */
1316#define MAC_WCID_ATTRIBUTE_KEYTAB FIELD32(0x00000001)
1317#define MAC_WCID_ATTRIBUTE_CIPHER FIELD32(0x0000000e)
1318#define MAC_WCID_ATTRIBUTE_BSS_IDX FIELD32(0x00000070)
1319#define MAC_WCID_ATTRIBUTE_RX_WIUDF FIELD32(0x00000380)
1320
1321/*
1322 * SHARED_KEY_MODE:
1323 */
1324#define SHARED_KEY_MODE_BSS0_KEY0 FIELD32(0x00000007)
1325#define SHARED_KEY_MODE_BSS0_KEY1 FIELD32(0x00000070)
1326#define SHARED_KEY_MODE_BSS0_KEY2 FIELD32(0x00000700)
1327#define SHARED_KEY_MODE_BSS0_KEY3 FIELD32(0x00007000)
1328#define SHARED_KEY_MODE_BSS1_KEY0 FIELD32(0x00070000)
1329#define SHARED_KEY_MODE_BSS1_KEY1 FIELD32(0x00700000)
1330#define SHARED_KEY_MODE_BSS1_KEY2 FIELD32(0x07000000)
1331#define SHARED_KEY_MODE_BSS1_KEY3 FIELD32(0x70000000)
1332
1333/*
1334 * HOST-MCU communication
1335 */
1336
1337/*
1338 * H2M_MAILBOX_CSR: Host-to-MCU Mailbox.
1339 */
1340#define H2M_MAILBOX_CSR 0x7010
1341#define H2M_MAILBOX_CSR_ARG0 FIELD32(0x000000ff)
1342#define H2M_MAILBOX_CSR_ARG1 FIELD32(0x0000ff00)
1343#define H2M_MAILBOX_CSR_CMD_TOKEN FIELD32(0x00ff0000)
1344#define H2M_MAILBOX_CSR_OWNER FIELD32(0xff000000)
1345
1346/*
1347 * H2M_MAILBOX_CID:
1348 */
1349#define H2M_MAILBOX_CID 0x7014
1350#define H2M_MAILBOX_CID_CMD0 FIELD32(0x000000ff)
1351#define H2M_MAILBOX_CID_CMD1 FIELD32(0x0000ff00)
1352#define H2M_MAILBOX_CID_CMD2 FIELD32(0x00ff0000)
1353#define H2M_MAILBOX_CID_CMD3 FIELD32(0xff000000)
1354
1355/*
1356 * H2M_MAILBOX_STATUS:
1357 */
1358#define H2M_MAILBOX_STATUS 0x701c
1359
1360/*
1361 * H2M_INT_SRC:
1362 */
1363#define H2M_INT_SRC 0x7024
1364
1365/*
1366 * H2M_BBP_AGENT:
1367 */
1368#define H2M_BBP_AGENT 0x7028
1369
1370/*
1371 * MCU_LEDCS: LED control for MCU Mailbox.
1372 */
1373#define MCU_LEDCS_LED_MODE FIELD8(0x1f)
1374#define MCU_LEDCS_POLARITY FIELD8(0x01)
1375
1376/*
1377 * HW_CS_CTS_BASE:
1378 * Carrier-sense CTS frame base address.
1379 * It's where mac stores carrier-sense frame for carrier-sense function.
1380 */
1381#define HW_CS_CTS_BASE 0x7700
1382
1383/*
1384 * HW_DFS_CTS_BASE:
1385 * DFS CTS frame base address. It's where mac stores CTS frame for DFS.
1386 */
1387#define HW_DFS_CTS_BASE 0x7780
1388
1389/*
1390 * TXRX control registers - base address 0x3000
1391 */
1392
1393/*
1394 * TXRX_CSR1:
1395 * rt2860b UNKNOWN reg use R/O Reg Addr 0x77d0 first..
1396 */
1397#define TXRX_CSR1 0x77d0
1398
1399/*
1400 * HW_DEBUG_SETTING_BASE:
1401 * since NULL frame won't be that long (256 byte)
1402 * We steal 16 tail bytes to save debugging settings
1403 */
1404#define HW_DEBUG_SETTING_BASE 0x77f0
1405#define HW_DEBUG_SETTING_BASE2 0x7770
1406
1407/*
1408 * HW_BEACON_BASE
1409 * In order to support maximum 8 MBSS and its maximum length
1410 * is 512 bytes for each beacon
1411 * Three section discontinue memory segments will be used.
1412 * 1. The original region for BCN 0~3
1413 * 2. Extract memory from FCE table for BCN 4~5
1414 * 3. Extract memory from Pair-wise key table for BCN 6~7
1415 * It occupied those memory of wcid 238~253 for BCN 6
1416 * and wcid 222~237 for BCN 7
1417 *
1418 * IMPORTANT NOTE: Not sure why legacy driver does this,
1419 * but HW_BEACON_BASE7 is 0x0200 bytes below HW_BEACON_BASE6.
1420 */
1421#define HW_BEACON_BASE0 0x7800
1422#define HW_BEACON_BASE1 0x7a00
1423#define HW_BEACON_BASE2 0x7c00
1424#define HW_BEACON_BASE3 0x7e00
1425#define HW_BEACON_BASE4 0x7200
1426#define HW_BEACON_BASE5 0x7400
1427#define HW_BEACON_BASE6 0x5dc0
1428#define HW_BEACON_BASE7 0x5bc0
1429
1430#define HW_BEACON_OFFSET(__index) \
1431 ( ((__index) < 4) ? ( HW_BEACON_BASE0 + (__index * 0x0200) ) : \
1432 (((__index) < 6) ? ( HW_BEACON_BASE4 + ((__index - 4) * 0x0200) ) : \
1433 (HW_BEACON_BASE6 - ((__index - 6) * 0x0200))) )
1434
1435/*
1436 * BBP registers.
1437 * The wordsize of the BBP is 8 bits.
1438 */
1439
1440/*
1441 * BBP 1: TX Antenna
1442 */
1443#define BBP1_TX_POWER FIELD8(0x07)
1444#define BBP1_TX_ANTENNA FIELD8(0x18)
1445
1446/*
1447 * BBP 3: RX Antenna
1448 */
1449#define BBP3_RX_ANTENNA FIELD8(0x18)
1450#define BBP3_HT40_PLUS FIELD8(0x20)
1451
1452/*
1453 * BBP 4: Bandwidth
1454 */
1455#define BBP4_TX_BF FIELD8(0x01)
1456#define BBP4_BANDWIDTH FIELD8(0x18)
1457
1458/*
1459 * RFCSR registers
1460 * The wordsize of the RFCSR is 8 bits.
1461 */
1462
1463/*
1464 * RFCSR 6:
1465 */
1466#define RFCSR6_R FIELD8(0x03)
1467
1468/*
1469 * RFCSR 7:
1470 */
1471#define RFCSR7_RF_TUNING FIELD8(0x01)
1472
1473/*
1474 * RFCSR 12:
1475 */
1476#define RFCSR12_TX_POWER FIELD8(0x1f)
1477
1478/*
1479 * RFCSR 22:
1480 */
1481#define RFCSR22_BASEBAND_LOOPBACK FIELD8(0x01)
1482
1483/*
1484 * RFCSR 23:
1485 */
1486#define RFCSR23_FREQ_OFFSET FIELD8(0x7f)
1487
1488/*
1489 * RFCSR 30:
1490 */
1491#define RFCSR30_RF_CALIBRATION FIELD8(0x80)
1492
1493/*
1494 * RF registers
1495 */
1496
1497/*
1498 * RF 2
1499 */
1500#define RF2_ANTENNA_RX2 FIELD32(0x00000040)
1501#define RF2_ANTENNA_TX1 FIELD32(0x00004000)
1502#define RF2_ANTENNA_RX1 FIELD32(0x00020000)
1503
1504/*
1505 * RF 3
1506 */
1507#define RF3_TXPOWER_G FIELD32(0x00003e00)
1508#define RF3_TXPOWER_A_7DBM_BOOST FIELD32(0x00000200)
1509#define RF3_TXPOWER_A FIELD32(0x00003c00)
1510
1511/*
1512 * RF 4
1513 */
1514#define RF4_TXPOWER_G FIELD32(0x000007c0)
1515#define RF4_TXPOWER_A_7DBM_BOOST FIELD32(0x00000040)
1516#define RF4_TXPOWER_A FIELD32(0x00000780)
1517#define RF4_FREQ_OFFSET FIELD32(0x001f8000)
1518#define RF4_HT40 FIELD32(0x00200000)
1519
1520/*
1521 * EEPROM content.
1522 * The wordsize of the EEPROM is 16 bits.
1523 */
1524
1525/*
1526 * EEPROM Version
1527 */
1528#define EEPROM_VERSION 0x0001
1529#define EEPROM_VERSION_FAE FIELD16(0x00ff)
1530#define EEPROM_VERSION_VERSION FIELD16(0xff00)
1531
1532/*
1533 * HW MAC address.
1534 */
1535#define EEPROM_MAC_ADDR_0 0x0002
1536#define EEPROM_MAC_ADDR_BYTE0 FIELD16(0x00ff)
1537#define EEPROM_MAC_ADDR_BYTE1 FIELD16(0xff00)
1538#define EEPROM_MAC_ADDR_1 0x0003
1539#define EEPROM_MAC_ADDR_BYTE2 FIELD16(0x00ff)
1540#define EEPROM_MAC_ADDR_BYTE3 FIELD16(0xff00)
1541#define EEPROM_MAC_ADDR_2 0x0004
1542#define EEPROM_MAC_ADDR_BYTE4 FIELD16(0x00ff)
1543#define EEPROM_MAC_ADDR_BYTE5 FIELD16(0xff00)
1544
1545/*
1546 * EEPROM ANTENNA config
1547 * RXPATH: 1: 1R, 2: 2R, 3: 3R
1548 * TXPATH: 1: 1T, 2: 2T
1549 */
1550#define EEPROM_ANTENNA 0x001a
1551#define EEPROM_ANTENNA_RXPATH FIELD16(0x000f)
1552#define EEPROM_ANTENNA_TXPATH FIELD16(0x00f0)
1553#define EEPROM_ANTENNA_RF_TYPE FIELD16(0x0f00)
1554
1555/*
1556 * EEPROM NIC config
1557 * CARDBUS_ACCEL: 0 - enable, 1 - disable
1558 */
1559#define EEPROM_NIC 0x001b
1560#define EEPROM_NIC_HW_RADIO FIELD16(0x0001)
1561#define EEPROM_NIC_DYNAMIC_TX_AGC FIELD16(0x0002)
1562#define EEPROM_NIC_EXTERNAL_LNA_BG FIELD16(0x0004)
1563#define EEPROM_NIC_EXTERNAL_LNA_A FIELD16(0x0008)
1564#define EEPROM_NIC_CARDBUS_ACCEL FIELD16(0x0010)
1565#define EEPROM_NIC_BW40M_SB_BG FIELD16(0x0020)
1566#define EEPROM_NIC_BW40M_SB_A FIELD16(0x0040)
1567#define EEPROM_NIC_WPS_PBC FIELD16(0x0080)
1568#define EEPROM_NIC_BW40M_BG FIELD16(0x0100)
1569#define EEPROM_NIC_BW40M_A FIELD16(0x0200)
1570
1571/*
1572 * EEPROM frequency
1573 */
1574#define EEPROM_FREQ 0x001d
1575#define EEPROM_FREQ_OFFSET FIELD16(0x00ff)
1576#define EEPROM_FREQ_LED_MODE FIELD16(0x7f00)
1577#define EEPROM_FREQ_LED_POLARITY FIELD16(0x1000)
1578
1579/*
1580 * EEPROM LED
1581 * POLARITY_RDY_G: Polarity RDY_G setting.
1582 * POLARITY_RDY_A: Polarity RDY_A setting.
1583 * POLARITY_ACT: Polarity ACT setting.
1584 * POLARITY_GPIO_0: Polarity GPIO0 setting.
1585 * POLARITY_GPIO_1: Polarity GPIO1 setting.
1586 * POLARITY_GPIO_2: Polarity GPIO2 setting.
1587 * POLARITY_GPIO_3: Polarity GPIO3 setting.
1588 * POLARITY_GPIO_4: Polarity GPIO4 setting.
1589 * LED_MODE: Led mode.
1590 */
1591#define EEPROM_LED1 0x001e
1592#define EEPROM_LED2 0x001f
1593#define EEPROM_LED3 0x0020
1594#define EEPROM_LED_POLARITY_RDY_BG FIELD16(0x0001)
1595#define EEPROM_LED_POLARITY_RDY_A FIELD16(0x0002)
1596#define EEPROM_LED_POLARITY_ACT FIELD16(0x0004)
1597#define EEPROM_LED_POLARITY_GPIO_0 FIELD16(0x0008)
1598#define EEPROM_LED_POLARITY_GPIO_1 FIELD16(0x0010)
1599#define EEPROM_LED_POLARITY_GPIO_2 FIELD16(0x0020)
1600#define EEPROM_LED_POLARITY_GPIO_3 FIELD16(0x0040)
1601#define EEPROM_LED_POLARITY_GPIO_4 FIELD16(0x0080)
1602#define EEPROM_LED_LED_MODE FIELD16(0x1f00)
1603
1604/*
1605 * EEPROM LNA
1606 */
1607#define EEPROM_LNA 0x0022
1608#define EEPROM_LNA_BG FIELD16(0x00ff)
1609#define EEPROM_LNA_A0 FIELD16(0xff00)
1610
1611/*
1612 * EEPROM RSSI BG offset
1613 */
1614#define EEPROM_RSSI_BG 0x0023
1615#define EEPROM_RSSI_BG_OFFSET0 FIELD16(0x00ff)
1616#define EEPROM_RSSI_BG_OFFSET1 FIELD16(0xff00)
1617
1618/*
1619 * EEPROM RSSI BG2 offset
1620 */
1621#define EEPROM_RSSI_BG2 0x0024
1622#define EEPROM_RSSI_BG2_OFFSET2 FIELD16(0x00ff)
1623#define EEPROM_RSSI_BG2_LNA_A1 FIELD16(0xff00)
1624
1625/*
1626 * EEPROM RSSI A offset
1627 */
1628#define EEPROM_RSSI_A 0x0025
1629#define EEPROM_RSSI_A_OFFSET0 FIELD16(0x00ff)
1630#define EEPROM_RSSI_A_OFFSET1 FIELD16(0xff00)
1631
1632/*
1633 * EEPROM RSSI A2 offset
1634 */
1635#define EEPROM_RSSI_A2 0x0026
1636#define EEPROM_RSSI_A2_OFFSET2 FIELD16(0x00ff)
1637#define EEPROM_RSSI_A2_LNA_A2 FIELD16(0xff00)
1638
1639/*
1640 * EEPROM TXpower delta: 20MHZ AND 40 MHZ use different power.
1641 * This is delta in 40MHZ.
1642 * VALUE: Tx Power dalta value (MAX=4)
1643 * TYPE: 1: Plus the delta value, 0: minus the delta value
1644 * TXPOWER: Enable:
1645 */
1646#define EEPROM_TXPOWER_DELTA 0x0028
1647#define EEPROM_TXPOWER_DELTA_VALUE FIELD16(0x003f)
1648#define EEPROM_TXPOWER_DELTA_TYPE FIELD16(0x0040)
1649#define EEPROM_TXPOWER_DELTA_TXPOWER FIELD16(0x0080)
1650
1651/*
1652 * EEPROM TXPOWER 802.11BG
1653 */
1654#define EEPROM_TXPOWER_BG1 0x0029
1655#define EEPROM_TXPOWER_BG2 0x0030
1656#define EEPROM_TXPOWER_BG_SIZE 7
1657#define EEPROM_TXPOWER_BG_1 FIELD16(0x00ff)
1658#define EEPROM_TXPOWER_BG_2 FIELD16(0xff00)
1659
1660/*
1661 * EEPROM TXPOWER 802.11A
1662 */
1663#define EEPROM_TXPOWER_A1 0x003c
1664#define EEPROM_TXPOWER_A2 0x0053
1665#define EEPROM_TXPOWER_A_SIZE 6
1666#define EEPROM_TXPOWER_A_1 FIELD16(0x00ff)
1667#define EEPROM_TXPOWER_A_2 FIELD16(0xff00)
1668
1669/*
1670 * EEPROM TXpower byrate: 20MHZ power
1671 */
1672#define EEPROM_TXPOWER_BYRATE 0x006f
1673
1674/*
1675 * EEPROM BBP.
1676 */
1677#define EEPROM_BBP_START 0x0078
1678#define EEPROM_BBP_SIZE 16
1679#define EEPROM_BBP_VALUE FIELD16(0x00ff)
1680#define EEPROM_BBP_REG_ID FIELD16(0xff00)
1681
1682/*
1683 * MCU mailbox commands.
1684 */
1685#define MCU_SLEEP 0x30
1686#define MCU_WAKEUP 0x31
1687#define MCU_RADIO_OFF 0x35
1688#define MCU_CURRENT 0x36
1689#define MCU_LED 0x50
1690#define MCU_LED_STRENGTH 0x51
1691#define MCU_LED_1 0x52
1692#define MCU_LED_2 0x53
1693#define MCU_LED_3 0x54
1694#define MCU_RADAR 0x60
1695#define MCU_BOOT_SIGNAL 0x72
1696#define MCU_BBP_SIGNAL 0x80
1697#define MCU_POWER_SAVE 0x83
1698
1699/*
1700 * MCU mailbox tokens
1701 */
1702#define TOKEN_WAKUP 3
1703
1704/*
1705 * DMA descriptor defines.
1706 */
1707#define TXWI_DESC_SIZE ( 4 * sizeof(__le32) )
1708#define RXWI_DESC_SIZE ( 4 * sizeof(__le32) )
1709
1710/*
1711 * TX WI structure
1712 */
1713
1714/*
1715 * Word0
1716 * FRAG: 1 To inform TKIP engine this is a fragment.
1717 * MIMO_PS: The remote peer is in dynamic MIMO-PS mode
1718 * TX_OP: 0:HT TXOP rule , 1:PIFS TX ,2:Backoff, 3:sifs
1719 * BW: Channel bandwidth 20MHz or 40 MHz
1720 * STBC: 1: STBC support MCS =0-7, 2,3 : RESERVED
1721 */
1722#define TXWI_W0_FRAG FIELD32(0x00000001)
1723#define TXWI_W0_MIMO_PS FIELD32(0x00000002)
1724#define TXWI_W0_CF_ACK FIELD32(0x00000004)
1725#define TXWI_W0_TS FIELD32(0x00000008)
1726#define TXWI_W0_AMPDU FIELD32(0x00000010)
1727#define TXWI_W0_MPDU_DENSITY FIELD32(0x000000e0)
1728#define TXWI_W0_TX_OP FIELD32(0x00000300)
1729#define TXWI_W0_MCS FIELD32(0x007f0000)
1730#define TXWI_W0_BW FIELD32(0x00800000)
1731#define TXWI_W0_SHORT_GI FIELD32(0x01000000)
1732#define TXWI_W0_STBC FIELD32(0x06000000)
1733#define TXWI_W0_IFS FIELD32(0x08000000)
1734#define TXWI_W0_PHYMODE FIELD32(0xc0000000)
1735
1736/*
1737 * Word1
1738 */
1739#define TXWI_W1_ACK FIELD32(0x00000001)
1740#define TXWI_W1_NSEQ FIELD32(0x00000002)
1741#define TXWI_W1_BW_WIN_SIZE FIELD32(0x000000fc)
1742#define TXWI_W1_WIRELESS_CLI_ID FIELD32(0x0000ff00)
1743#define TXWI_W1_MPDU_TOTAL_BYTE_COUNT FIELD32(0x0fff0000)
1744#define TXWI_W1_PACKETID FIELD32(0xf0000000)
1745
1746/*
1747 * Word2
1748 */
1749#define TXWI_W2_IV FIELD32(0xffffffff)
1750
1751/*
1752 * Word3
1753 */
1754#define TXWI_W3_EIV FIELD32(0xffffffff)
1755
1756/*
1757 * RX WI structure
1758 */
1759
1760/*
1761 * Word0
1762 */
1763#define RXWI_W0_WIRELESS_CLI_ID FIELD32(0x000000ff)
1764#define RXWI_W0_KEY_INDEX FIELD32(0x00000300)
1765#define RXWI_W0_BSSID FIELD32(0x00001c00)
1766#define RXWI_W0_UDF FIELD32(0x0000e000)
1767#define RXWI_W0_MPDU_TOTAL_BYTE_COUNT FIELD32(0x0fff0000)
1768#define RXWI_W0_TID FIELD32(0xf0000000)
1769
1770/*
1771 * Word1
1772 */
1773#define RXWI_W1_FRAG FIELD32(0x0000000f)
1774#define RXWI_W1_SEQUENCE FIELD32(0x0000fff0)
1775#define RXWI_W1_MCS FIELD32(0x007f0000)
1776#define RXWI_W1_BW FIELD32(0x00800000)
1777#define RXWI_W1_SHORT_GI FIELD32(0x01000000)
1778#define RXWI_W1_STBC FIELD32(0x06000000)
1779#define RXWI_W1_PHYMODE FIELD32(0xc0000000)
1780
1781/*
1782 * Word2
1783 */
1784#define RXWI_W2_RSSI0 FIELD32(0x000000ff)
1785#define RXWI_W2_RSSI1 FIELD32(0x0000ff00)
1786#define RXWI_W2_RSSI2 FIELD32(0x00ff0000)
1787
1788/*
1789 * Word3
1790 */
1791#define RXWI_W3_SNR0 FIELD32(0x000000ff)
1792#define RXWI_W3_SNR1 FIELD32(0x0000ff00)
1793
1794/*
1795 * Macros for converting txpower from EEPROM to mac80211 value
1796 * and from mac80211 value to register value.
1797 */
1798#define MIN_G_TXPOWER 0
1799#define MIN_A_TXPOWER -7
1800#define MAX_G_TXPOWER 31
1801#define MAX_A_TXPOWER 15
1802#define DEFAULT_TXPOWER 5
1803
1804#define TXPOWER_G_FROM_DEV(__txpower) \
1805 ((__txpower) > MAX_G_TXPOWER) ? DEFAULT_TXPOWER : (__txpower)
1806
1807#define TXPOWER_G_TO_DEV(__txpower) \
1808 clamp_t(char, __txpower, MIN_G_TXPOWER, MAX_G_TXPOWER)
1809
1810#define TXPOWER_A_FROM_DEV(__txpower) \
1811 ((__txpower) > MAX_A_TXPOWER) ? DEFAULT_TXPOWER : (__txpower)
1812
1813#define TXPOWER_A_TO_DEV(__txpower) \
1814 clamp_t(char, __txpower, MIN_A_TXPOWER, MAX_A_TXPOWER)
1815
1816#endif /* RT2800_H */
diff --git a/drivers/net/wireless/rt2x00/rt2800lib.c b/drivers/net/wireless/rt2x00/rt2800lib.c
new file mode 100644
index 000000000000..5c7d74a6f16e
--- /dev/null
+++ b/drivers/net/wireless/rt2x00/rt2800lib.c
@@ -0,0 +1,1817 @@
1/*
2 Copyright (C) 2009 Bartlomiej Zolnierkiewicz
3
4 Based on the original rt2800pci.c and rt2800usb.c:
5
6 Copyright (C) 2004 - 2009 rt2x00 SourceForge Project
7 <http://rt2x00.serialmonkey.com>
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the
21 Free Software Foundation, Inc.,
22 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 */
24
25/*
26 Module: rt2800lib
27 Abstract: rt2800 generic device routines.
28 */
29
30#include <linux/kernel.h>
31#include <linux/module.h>
32
33#include "rt2x00.h"
34#ifdef CONFIG_RT2800USB
35#include "rt2x00usb.h"
36#endif
37#include "rt2800lib.h"
38#include "rt2800.h"
39#include "rt2800usb.h"
40
41MODULE_AUTHOR("Bartlomiej Zolnierkiewicz");
42MODULE_DESCRIPTION("rt2800 library");
43MODULE_LICENSE("GPL");
44
45/*
46 * Register access.
47 * All access to the CSR registers will go through the methods
48 * rt2800_register_read and rt2800_register_write.
49 * BBP and RF register require indirect register access,
50 * and use the CSR registers BBPCSR and RFCSR to achieve this.
51 * These indirect registers work with busy bits,
52 * and we will try maximal REGISTER_BUSY_COUNT times to access
53 * the register while taking a REGISTER_BUSY_DELAY us delay
54 * between each attampt. When the busy bit is still set at that time,
55 * the access attempt is considered to have failed,
56 * and we will print an error.
57 * The _lock versions must be used if you already hold the csr_mutex
58 */
59#define WAIT_FOR_BBP(__dev, __reg) \
60 rt2800_regbusy_read((__dev), BBP_CSR_CFG, BBP_CSR_CFG_BUSY, (__reg))
61#define WAIT_FOR_RFCSR(__dev, __reg) \
62 rt2800_regbusy_read((__dev), RF_CSR_CFG, RF_CSR_CFG_BUSY, (__reg))
63#define WAIT_FOR_RF(__dev, __reg) \
64 rt2800_regbusy_read((__dev), RF_CSR_CFG0, RF_CSR_CFG0_BUSY, (__reg))
65#define WAIT_FOR_MCU(__dev, __reg) \
66 rt2800_regbusy_read((__dev), H2M_MAILBOX_CSR, \
67 H2M_MAILBOX_CSR_OWNER, (__reg))
68
69static void rt2800_bbp_write(struct rt2x00_dev *rt2x00dev,
70 const unsigned int word, const u8 value)
71{
72 u32 reg;
73
74 mutex_lock(&rt2x00dev->csr_mutex);
75
76 /*
77 * Wait until the BBP becomes available, afterwards we
78 * can safely write the new data into the register.
79 */
80 if (WAIT_FOR_BBP(rt2x00dev, &reg)) {
81 reg = 0;
82 rt2x00_set_field32(&reg, BBP_CSR_CFG_VALUE, value);
83 rt2x00_set_field32(&reg, BBP_CSR_CFG_REGNUM, word);
84 rt2x00_set_field32(&reg, BBP_CSR_CFG_BUSY, 1);
85 rt2x00_set_field32(&reg, BBP_CSR_CFG_READ_CONTROL, 0);
86 if (rt2x00_intf_is_pci(rt2x00dev))
87 rt2x00_set_field32(&reg, BBP_CSR_CFG_BBP_RW_MODE, 1);
88
89 rt2800_register_write_lock(rt2x00dev, BBP_CSR_CFG, reg);
90 }
91
92 mutex_unlock(&rt2x00dev->csr_mutex);
93}
94
95static void rt2800_bbp_read(struct rt2x00_dev *rt2x00dev,
96 const unsigned int word, u8 *value)
97{
98 u32 reg;
99
100 mutex_lock(&rt2x00dev->csr_mutex);
101
102 /*
103 * Wait until the BBP becomes available, afterwards we
104 * can safely write the read request into the register.
105 * After the data has been written, we wait until hardware
106 * returns the correct value, if at any time the register
107 * doesn't become available in time, reg will be 0xffffffff
108 * which means we return 0xff to the caller.
109 */
110 if (WAIT_FOR_BBP(rt2x00dev, &reg)) {
111 reg = 0;
112 rt2x00_set_field32(&reg, BBP_CSR_CFG_REGNUM, word);
113 rt2x00_set_field32(&reg, BBP_CSR_CFG_BUSY, 1);
114 rt2x00_set_field32(&reg, BBP_CSR_CFG_READ_CONTROL, 1);
115 if (rt2x00_intf_is_pci(rt2x00dev))
116 rt2x00_set_field32(&reg, BBP_CSR_CFG_BBP_RW_MODE, 1);
117
118 rt2800_register_write_lock(rt2x00dev, BBP_CSR_CFG, reg);
119
120 WAIT_FOR_BBP(rt2x00dev, &reg);
121 }
122
123 *value = rt2x00_get_field32(reg, BBP_CSR_CFG_VALUE);
124
125 mutex_unlock(&rt2x00dev->csr_mutex);
126}
127
128static void rt2800_rfcsr_write(struct rt2x00_dev *rt2x00dev,
129 const unsigned int word, const u8 value)
130{
131 u32 reg;
132
133 mutex_lock(&rt2x00dev->csr_mutex);
134
135 /*
136 * Wait until the RFCSR becomes available, afterwards we
137 * can safely write the new data into the register.
138 */
139 if (WAIT_FOR_RFCSR(rt2x00dev, &reg)) {
140 reg = 0;
141 rt2x00_set_field32(&reg, RF_CSR_CFG_DATA, value);
142 rt2x00_set_field32(&reg, RF_CSR_CFG_REGNUM, word);
143 rt2x00_set_field32(&reg, RF_CSR_CFG_WRITE, 1);
144 rt2x00_set_field32(&reg, RF_CSR_CFG_BUSY, 1);
145
146 rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG, reg);
147 }
148
149 mutex_unlock(&rt2x00dev->csr_mutex);
150}
151
152static void rt2800_rfcsr_read(struct rt2x00_dev *rt2x00dev,
153 const unsigned int word, u8 *value)
154{
155 u32 reg;
156
157 mutex_lock(&rt2x00dev->csr_mutex);
158
159 /*
160 * Wait until the RFCSR becomes available, afterwards we
161 * can safely write the read request into the register.
162 * After the data has been written, we wait until hardware
163 * returns the correct value, if at any time the register
164 * doesn't become available in time, reg will be 0xffffffff
165 * which means we return 0xff to the caller.
166 */
167 if (WAIT_FOR_RFCSR(rt2x00dev, &reg)) {
168 reg = 0;
169 rt2x00_set_field32(&reg, RF_CSR_CFG_REGNUM, word);
170 rt2x00_set_field32(&reg, RF_CSR_CFG_WRITE, 0);
171 rt2x00_set_field32(&reg, RF_CSR_CFG_BUSY, 1);
172
173 rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG, reg);
174
175 WAIT_FOR_RFCSR(rt2x00dev, &reg);
176 }
177
178 *value = rt2x00_get_field32(reg, RF_CSR_CFG_DATA);
179
180 mutex_unlock(&rt2x00dev->csr_mutex);
181}
182
183static void rt2800_rf_write(struct rt2x00_dev *rt2x00dev,
184 const unsigned int word, const u32 value)
185{
186 u32 reg;
187
188 mutex_lock(&rt2x00dev->csr_mutex);
189
190 /*
191 * Wait until the RF becomes available, afterwards we
192 * can safely write the new data into the register.
193 */
194 if (WAIT_FOR_RF(rt2x00dev, &reg)) {
195 reg = 0;
196 rt2x00_set_field32(&reg, RF_CSR_CFG0_REG_VALUE_BW, value);
197 rt2x00_set_field32(&reg, RF_CSR_CFG0_STANDBYMODE, 0);
198 rt2x00_set_field32(&reg, RF_CSR_CFG0_SEL, 0);
199 rt2x00_set_field32(&reg, RF_CSR_CFG0_BUSY, 1);
200
201 rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG0, reg);
202 rt2x00_rf_write(rt2x00dev, word, value);
203 }
204
205 mutex_unlock(&rt2x00dev->csr_mutex);
206}
207
208void rt2800_mcu_request(struct rt2x00_dev *rt2x00dev,
209 const u8 command, const u8 token,
210 const u8 arg0, const u8 arg1)
211{
212 u32 reg;
213
214 if (rt2x00_intf_is_pci(rt2x00dev)) {
215 /*
216 * RT2880 and RT3052 don't support MCU requests.
217 */
218 if (rt2x00_rt(&rt2x00dev->chip, RT2880) ||
219 rt2x00_rt(&rt2x00dev->chip, RT3052))
220 return;
221 }
222
223 mutex_lock(&rt2x00dev->csr_mutex);
224
225 /*
226 * Wait until the MCU becomes available, afterwards we
227 * can safely write the new data into the register.
228 */
229 if (WAIT_FOR_MCU(rt2x00dev, &reg)) {
230 rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_OWNER, 1);
231 rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_CMD_TOKEN, token);
232 rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_ARG0, arg0);
233 rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_ARG1, arg1);
234 rt2800_register_write_lock(rt2x00dev, H2M_MAILBOX_CSR, reg);
235
236 reg = 0;
237 rt2x00_set_field32(&reg, HOST_CMD_CSR_HOST_COMMAND, command);
238 rt2800_register_write_lock(rt2x00dev, HOST_CMD_CSR, reg);
239 }
240
241 mutex_unlock(&rt2x00dev->csr_mutex);
242}
243EXPORT_SYMBOL_GPL(rt2800_mcu_request);
244
245#ifdef CONFIG_RT2X00_LIB_DEBUGFS
246const struct rt2x00debug rt2800_rt2x00debug = {
247 .owner = THIS_MODULE,
248 .csr = {
249 .read = rt2800_register_read,
250 .write = rt2800_register_write,
251 .flags = RT2X00DEBUGFS_OFFSET,
252 .word_base = CSR_REG_BASE,
253 .word_size = sizeof(u32),
254 .word_count = CSR_REG_SIZE / sizeof(u32),
255 },
256 .eeprom = {
257 .read = rt2x00_eeprom_read,
258 .write = rt2x00_eeprom_write,
259 .word_base = EEPROM_BASE,
260 .word_size = sizeof(u16),
261 .word_count = EEPROM_SIZE / sizeof(u16),
262 },
263 .bbp = {
264 .read = rt2800_bbp_read,
265 .write = rt2800_bbp_write,
266 .word_base = BBP_BASE,
267 .word_size = sizeof(u8),
268 .word_count = BBP_SIZE / sizeof(u8),
269 },
270 .rf = {
271 .read = rt2x00_rf_read,
272 .write = rt2800_rf_write,
273 .word_base = RF_BASE,
274 .word_size = sizeof(u32),
275 .word_count = RF_SIZE / sizeof(u32),
276 },
277};
278EXPORT_SYMBOL_GPL(rt2800_rt2x00debug);
279#endif /* CONFIG_RT2X00_LIB_DEBUGFS */
280
281int rt2800_rfkill_poll(struct rt2x00_dev *rt2x00dev)
282{
283 u32 reg;
284
285 rt2800_register_read(rt2x00dev, GPIO_CTRL_CFG, &reg);
286 return rt2x00_get_field32(reg, GPIO_CTRL_CFG_BIT2);
287}
288EXPORT_SYMBOL_GPL(rt2800_rfkill_poll);
289
290#ifdef CONFIG_RT2X00_LIB_LEDS
291static void rt2800_brightness_set(struct led_classdev *led_cdev,
292 enum led_brightness brightness)
293{
294 struct rt2x00_led *led =
295 container_of(led_cdev, struct rt2x00_led, led_dev);
296 unsigned int enabled = brightness != LED_OFF;
297 unsigned int bg_mode =
298 (enabled && led->rt2x00dev->curr_band == IEEE80211_BAND_2GHZ);
299 unsigned int polarity =
300 rt2x00_get_field16(led->rt2x00dev->led_mcu_reg,
301 EEPROM_FREQ_LED_POLARITY);
302 unsigned int ledmode =
303 rt2x00_get_field16(led->rt2x00dev->led_mcu_reg,
304 EEPROM_FREQ_LED_MODE);
305
306 if (led->type == LED_TYPE_RADIO) {
307 rt2800_mcu_request(led->rt2x00dev, MCU_LED, 0xff, ledmode,
308 enabled ? 0x20 : 0);
309 } else if (led->type == LED_TYPE_ASSOC) {
310 rt2800_mcu_request(led->rt2x00dev, MCU_LED, 0xff, ledmode,
311 enabled ? (bg_mode ? 0x60 : 0xa0) : 0x20);
312 } else if (led->type == LED_TYPE_QUALITY) {
313 /*
314 * The brightness is divided into 6 levels (0 - 5),
315 * The specs tell us the following levels:
316 * 0, 1 ,3, 7, 15, 31
317 * to determine the level in a simple way we can simply
318 * work with bitshifting:
319 * (1 << level) - 1
320 */
321 rt2800_mcu_request(led->rt2x00dev, MCU_LED_STRENGTH, 0xff,
322 (1 << brightness / (LED_FULL / 6)) - 1,
323 polarity);
324 }
325}
326
327static int rt2800_blink_set(struct led_classdev *led_cdev,
328 unsigned long *delay_on, unsigned long *delay_off)
329{
330 struct rt2x00_led *led =
331 container_of(led_cdev, struct rt2x00_led, led_dev);
332 u32 reg;
333
334 rt2800_register_read(led->rt2x00dev, LED_CFG, &reg);
335 rt2x00_set_field32(&reg, LED_CFG_ON_PERIOD, *delay_on);
336 rt2x00_set_field32(&reg, LED_CFG_OFF_PERIOD, *delay_off);
337 rt2x00_set_field32(&reg, LED_CFG_SLOW_BLINK_PERIOD, 3);
338 rt2x00_set_field32(&reg, LED_CFG_R_LED_MODE, 3);
339 rt2x00_set_field32(&reg, LED_CFG_G_LED_MODE, 12);
340 rt2x00_set_field32(&reg, LED_CFG_Y_LED_MODE, 3);
341 rt2x00_set_field32(&reg, LED_CFG_LED_POLAR, 1);
342 rt2800_register_write(led->rt2x00dev, LED_CFG, reg);
343
344 return 0;
345}
346
347void rt2800_init_led(struct rt2x00_dev *rt2x00dev,
348 struct rt2x00_led *led, enum led_type type)
349{
350 led->rt2x00dev = rt2x00dev;
351 led->type = type;
352 led->led_dev.brightness_set = rt2800_brightness_set;
353 led->led_dev.blink_set = rt2800_blink_set;
354 led->flags = LED_INITIALIZED;
355}
356EXPORT_SYMBOL_GPL(rt2800_init_led);
357#endif /* CONFIG_RT2X00_LIB_LEDS */
358
359/*
360 * Configuration handlers.
361 */
362static void rt2800_config_wcid_attr(struct rt2x00_dev *rt2x00dev,
363 struct rt2x00lib_crypto *crypto,
364 struct ieee80211_key_conf *key)
365{
366 struct mac_wcid_entry wcid_entry;
367 struct mac_iveiv_entry iveiv_entry;
368 u32 offset;
369 u32 reg;
370
371 offset = MAC_WCID_ATTR_ENTRY(key->hw_key_idx);
372
373 rt2800_register_read(rt2x00dev, offset, &reg);
374 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_KEYTAB,
375 !!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE));
376 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_CIPHER,
377 (crypto->cmd == SET_KEY) * crypto->cipher);
378 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_BSS_IDX,
379 (crypto->cmd == SET_KEY) * crypto->bssidx);
380 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_RX_WIUDF, crypto->cipher);
381 rt2800_register_write(rt2x00dev, offset, reg);
382
383 offset = MAC_IVEIV_ENTRY(key->hw_key_idx);
384
385 memset(&iveiv_entry, 0, sizeof(iveiv_entry));
386 if ((crypto->cipher == CIPHER_TKIP) ||
387 (crypto->cipher == CIPHER_TKIP_NO_MIC) ||
388 (crypto->cipher == CIPHER_AES))
389 iveiv_entry.iv[3] |= 0x20;
390 iveiv_entry.iv[3] |= key->keyidx << 6;
391 rt2800_register_multiwrite(rt2x00dev, offset,
392 &iveiv_entry, sizeof(iveiv_entry));
393
394 offset = MAC_WCID_ENTRY(key->hw_key_idx);
395
396 memset(&wcid_entry, 0, sizeof(wcid_entry));
397 if (crypto->cmd == SET_KEY)
398 memcpy(&wcid_entry, crypto->address, ETH_ALEN);
399 rt2800_register_multiwrite(rt2x00dev, offset,
400 &wcid_entry, sizeof(wcid_entry));
401}
402
403int rt2800_config_shared_key(struct rt2x00_dev *rt2x00dev,
404 struct rt2x00lib_crypto *crypto,
405 struct ieee80211_key_conf *key)
406{
407 struct hw_key_entry key_entry;
408 struct rt2x00_field32 field;
409 u32 offset;
410 u32 reg;
411
412 if (crypto->cmd == SET_KEY) {
413 key->hw_key_idx = (4 * crypto->bssidx) + key->keyidx;
414
415 memcpy(key_entry.key, crypto->key,
416 sizeof(key_entry.key));
417 memcpy(key_entry.tx_mic, crypto->tx_mic,
418 sizeof(key_entry.tx_mic));
419 memcpy(key_entry.rx_mic, crypto->rx_mic,
420 sizeof(key_entry.rx_mic));
421
422 offset = SHARED_KEY_ENTRY(key->hw_key_idx);
423 rt2800_register_multiwrite(rt2x00dev, offset,
424 &key_entry, sizeof(key_entry));
425 }
426
427 /*
428 * The cipher types are stored over multiple registers
429 * starting with SHARED_KEY_MODE_BASE each word will have
430 * 32 bits and contains the cipher types for 2 bssidx each.
431 * Using the correct defines correctly will cause overhead,
432 * so just calculate the correct offset.
433 */
434 field.bit_offset = 4 * (key->hw_key_idx % 8);
435 field.bit_mask = 0x7 << field.bit_offset;
436
437 offset = SHARED_KEY_MODE_ENTRY(key->hw_key_idx / 8);
438
439 rt2800_register_read(rt2x00dev, offset, &reg);
440 rt2x00_set_field32(&reg, field,
441 (crypto->cmd == SET_KEY) * crypto->cipher);
442 rt2800_register_write(rt2x00dev, offset, reg);
443
444 /*
445 * Update WCID information
446 */
447 rt2800_config_wcid_attr(rt2x00dev, crypto, key);
448
449 return 0;
450}
451EXPORT_SYMBOL_GPL(rt2800_config_shared_key);
452
453int rt2800_config_pairwise_key(struct rt2x00_dev *rt2x00dev,
454 struct rt2x00lib_crypto *crypto,
455 struct ieee80211_key_conf *key)
456{
457 struct hw_key_entry key_entry;
458 u32 offset;
459
460 if (crypto->cmd == SET_KEY) {
461 /*
462 * 1 pairwise key is possible per AID, this means that the AID
463 * equals our hw_key_idx. Make sure the WCID starts _after_ the
464 * last possible shared key entry.
465 */
466 if (crypto->aid > (256 - 32))
467 return -ENOSPC;
468
469 key->hw_key_idx = 32 + crypto->aid;
470
471 memcpy(key_entry.key, crypto->key,
472 sizeof(key_entry.key));
473 memcpy(key_entry.tx_mic, crypto->tx_mic,
474 sizeof(key_entry.tx_mic));
475 memcpy(key_entry.rx_mic, crypto->rx_mic,
476 sizeof(key_entry.rx_mic));
477
478 offset = PAIRWISE_KEY_ENTRY(key->hw_key_idx);
479 rt2800_register_multiwrite(rt2x00dev, offset,
480 &key_entry, sizeof(key_entry));
481 }
482
483 /*
484 * Update WCID information
485 */
486 rt2800_config_wcid_attr(rt2x00dev, crypto, key);
487
488 return 0;
489}
490EXPORT_SYMBOL_GPL(rt2800_config_pairwise_key);
491
492void rt2800_config_filter(struct rt2x00_dev *rt2x00dev,
493 const unsigned int filter_flags)
494{
495 u32 reg;
496
497 /*
498 * Start configuration steps.
499 * Note that the version error will always be dropped
500 * and broadcast frames will always be accepted since
501 * there is no filter for it at this time.
502 */
503 rt2800_register_read(rt2x00dev, RX_FILTER_CFG, &reg);
504 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CRC_ERROR,
505 !(filter_flags & FIF_FCSFAIL));
506 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_PHY_ERROR,
507 !(filter_flags & FIF_PLCPFAIL));
508 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_NOT_TO_ME,
509 !(filter_flags & FIF_PROMISC_IN_BSS));
510 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_NOT_MY_BSSD, 0);
511 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_VER_ERROR, 1);
512 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_MULTICAST,
513 !(filter_flags & FIF_ALLMULTI));
514 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_BROADCAST, 0);
515 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_DUPLICATE, 1);
516 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CF_END_ACK,
517 !(filter_flags & FIF_CONTROL));
518 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CF_END,
519 !(filter_flags & FIF_CONTROL));
520 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_ACK,
521 !(filter_flags & FIF_CONTROL));
522 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CTS,
523 !(filter_flags & FIF_CONTROL));
524 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_RTS,
525 !(filter_flags & FIF_CONTROL));
526 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_PSPOLL,
527 !(filter_flags & FIF_PSPOLL));
528 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_BA, 1);
529 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_BAR, 0);
530 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CNTL,
531 !(filter_flags & FIF_CONTROL));
532 rt2800_register_write(rt2x00dev, RX_FILTER_CFG, reg);
533}
534EXPORT_SYMBOL_GPL(rt2800_config_filter);
535
536void rt2800_config_intf(struct rt2x00_dev *rt2x00dev, struct rt2x00_intf *intf,
537 struct rt2x00intf_conf *conf, const unsigned int flags)
538{
539 unsigned int beacon_base;
540 u32 reg;
541
542 if (flags & CONFIG_UPDATE_TYPE) {
543 /*
544 * Clear current synchronisation setup.
545 * For the Beacon base registers we only need to clear
546 * the first byte since that byte contains the VALID and OWNER
547 * bits which (when set to 0) will invalidate the entire beacon.
548 */
549 beacon_base = HW_BEACON_OFFSET(intf->beacon->entry_idx);
550 rt2800_register_write(rt2x00dev, beacon_base, 0);
551
552 /*
553 * Enable synchronisation.
554 */
555 rt2800_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
556 rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 1);
557 rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_SYNC, conf->sync);
558 rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 1);
559 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
560 }
561
562 if (flags & CONFIG_UPDATE_MAC) {
563 reg = le32_to_cpu(conf->mac[1]);
564 rt2x00_set_field32(&reg, MAC_ADDR_DW1_UNICAST_TO_ME_MASK, 0xff);
565 conf->mac[1] = cpu_to_le32(reg);
566
567 rt2800_register_multiwrite(rt2x00dev, MAC_ADDR_DW0,
568 conf->mac, sizeof(conf->mac));
569 }
570
571 if (flags & CONFIG_UPDATE_BSSID) {
572 reg = le32_to_cpu(conf->bssid[1]);
573 rt2x00_set_field32(&reg, MAC_BSSID_DW1_BSS_ID_MASK, 0);
574 rt2x00_set_field32(&reg, MAC_BSSID_DW1_BSS_BCN_NUM, 0);
575 conf->bssid[1] = cpu_to_le32(reg);
576
577 rt2800_register_multiwrite(rt2x00dev, MAC_BSSID_DW0,
578 conf->bssid, sizeof(conf->bssid));
579 }
580}
581EXPORT_SYMBOL_GPL(rt2800_config_intf);
582
583void rt2800_config_erp(struct rt2x00_dev *rt2x00dev, struct rt2x00lib_erp *erp)
584{
585 u32 reg;
586
587 rt2800_register_read(rt2x00dev, TX_TIMEOUT_CFG, &reg);
588 rt2x00_set_field32(&reg, TX_TIMEOUT_CFG_RX_ACK_TIMEOUT, 0x20);
589 rt2800_register_write(rt2x00dev, TX_TIMEOUT_CFG, reg);
590
591 rt2800_register_read(rt2x00dev, AUTO_RSP_CFG, &reg);
592 rt2x00_set_field32(&reg, AUTO_RSP_CFG_BAC_ACK_POLICY,
593 !!erp->short_preamble);
594 rt2x00_set_field32(&reg, AUTO_RSP_CFG_AR_PREAMBLE,
595 !!erp->short_preamble);
596 rt2800_register_write(rt2x00dev, AUTO_RSP_CFG, reg);
597
598 rt2800_register_read(rt2x00dev, OFDM_PROT_CFG, &reg);
599 rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_CTRL,
600 erp->cts_protection ? 2 : 0);
601 rt2800_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
602
603 rt2800_register_write(rt2x00dev, LEGACY_BASIC_RATE,
604 erp->basic_rates);
605 rt2800_register_write(rt2x00dev, HT_BASIC_RATE, 0x00008003);
606
607 rt2800_register_read(rt2x00dev, BKOFF_SLOT_CFG, &reg);
608 rt2x00_set_field32(&reg, BKOFF_SLOT_CFG_SLOT_TIME, erp->slot_time);
609 rt2x00_set_field32(&reg, BKOFF_SLOT_CFG_CC_DELAY_TIME, 2);
610 rt2800_register_write(rt2x00dev, BKOFF_SLOT_CFG, reg);
611
612 rt2800_register_read(rt2x00dev, XIFS_TIME_CFG, &reg);
613 rt2x00_set_field32(&reg, XIFS_TIME_CFG_CCKM_SIFS_TIME, erp->sifs);
614 rt2x00_set_field32(&reg, XIFS_TIME_CFG_OFDM_SIFS_TIME, erp->sifs);
615 rt2x00_set_field32(&reg, XIFS_TIME_CFG_OFDM_XIFS_TIME, 4);
616 rt2x00_set_field32(&reg, XIFS_TIME_CFG_EIFS, erp->eifs);
617 rt2x00_set_field32(&reg, XIFS_TIME_CFG_BB_RXEND_ENABLE, 1);
618 rt2800_register_write(rt2x00dev, XIFS_TIME_CFG, reg);
619
620 rt2800_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
621 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_INTERVAL,
622 erp->beacon_int * 16);
623 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
624}
625EXPORT_SYMBOL_GPL(rt2800_config_erp);
626
627void rt2800_config_ant(struct rt2x00_dev *rt2x00dev, struct antenna_setup *ant)
628{
629 u8 r1;
630 u8 r3;
631
632 rt2800_bbp_read(rt2x00dev, 1, &r1);
633 rt2800_bbp_read(rt2x00dev, 3, &r3);
634
635 /*
636 * Configure the TX antenna.
637 */
638 switch ((int)ant->tx) {
639 case 1:
640 rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 0);
641 if (rt2x00_intf_is_pci(rt2x00dev))
642 rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 0);
643 break;
644 case 2:
645 rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 2);
646 break;
647 case 3:
648 /* Do nothing */
649 break;
650 }
651
652 /*
653 * Configure the RX antenna.
654 */
655 switch ((int)ant->rx) {
656 case 1:
657 rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 0);
658 break;
659 case 2:
660 rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 1);
661 break;
662 case 3:
663 rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 2);
664 break;
665 }
666
667 rt2800_bbp_write(rt2x00dev, 3, r3);
668 rt2800_bbp_write(rt2x00dev, 1, r1);
669}
670EXPORT_SYMBOL_GPL(rt2800_config_ant);
671
672static void rt2800_config_lna_gain(struct rt2x00_dev *rt2x00dev,
673 struct rt2x00lib_conf *libconf)
674{
675 u16 eeprom;
676 short lna_gain;
677
678 if (libconf->rf.channel <= 14) {
679 rt2x00_eeprom_read(rt2x00dev, EEPROM_LNA, &eeprom);
680 lna_gain = rt2x00_get_field16(eeprom, EEPROM_LNA_BG);
681 } else if (libconf->rf.channel <= 64) {
682 rt2x00_eeprom_read(rt2x00dev, EEPROM_LNA, &eeprom);
683 lna_gain = rt2x00_get_field16(eeprom, EEPROM_LNA_A0);
684 } else if (libconf->rf.channel <= 128) {
685 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &eeprom);
686 lna_gain = rt2x00_get_field16(eeprom, EEPROM_RSSI_BG2_LNA_A1);
687 } else {
688 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &eeprom);
689 lna_gain = rt2x00_get_field16(eeprom, EEPROM_RSSI_A2_LNA_A2);
690 }
691
692 rt2x00dev->lna_gain = lna_gain;
693}
694
695static void rt2800_config_channel_rt2x(struct rt2x00_dev *rt2x00dev,
696 struct ieee80211_conf *conf,
697 struct rf_channel *rf,
698 struct channel_info *info)
699{
700 rt2x00_set_field32(&rf->rf4, RF4_FREQ_OFFSET, rt2x00dev->freq_offset);
701
702 if (rt2x00dev->default_ant.tx == 1)
703 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_TX1, 1);
704
705 if (rt2x00dev->default_ant.rx == 1) {
706 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX1, 1);
707 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1);
708 } else if (rt2x00dev->default_ant.rx == 2)
709 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1);
710
711 if (rf->channel > 14) {
712 /*
713 * When TX power is below 0, we should increase it by 7 to
714 * make it a positive value (Minumum value is -7).
715 * However this means that values between 0 and 7 have
716 * double meaning, and we should set a 7DBm boost flag.
717 */
718 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_A_7DBM_BOOST,
719 (info->tx_power1 >= 0));
720
721 if (info->tx_power1 < 0)
722 info->tx_power1 += 7;
723
724 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_A,
725 TXPOWER_A_TO_DEV(info->tx_power1));
726
727 rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_A_7DBM_BOOST,
728 (info->tx_power2 >= 0));
729
730 if (info->tx_power2 < 0)
731 info->tx_power2 += 7;
732
733 rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_A,
734 TXPOWER_A_TO_DEV(info->tx_power2));
735 } else {
736 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_G,
737 TXPOWER_G_TO_DEV(info->tx_power1));
738 rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_G,
739 TXPOWER_G_TO_DEV(info->tx_power2));
740 }
741
742 rt2x00_set_field32(&rf->rf4, RF4_HT40, conf_is_ht40(conf));
743
744 rt2800_rf_write(rt2x00dev, 1, rf->rf1);
745 rt2800_rf_write(rt2x00dev, 2, rf->rf2);
746 rt2800_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
747 rt2800_rf_write(rt2x00dev, 4, rf->rf4);
748
749 udelay(200);
750
751 rt2800_rf_write(rt2x00dev, 1, rf->rf1);
752 rt2800_rf_write(rt2x00dev, 2, rf->rf2);
753 rt2800_rf_write(rt2x00dev, 3, rf->rf3 | 0x00000004);
754 rt2800_rf_write(rt2x00dev, 4, rf->rf4);
755
756 udelay(200);
757
758 rt2800_rf_write(rt2x00dev, 1, rf->rf1);
759 rt2800_rf_write(rt2x00dev, 2, rf->rf2);
760 rt2800_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
761 rt2800_rf_write(rt2x00dev, 4, rf->rf4);
762}
763
764static void rt2800_config_channel_rt3x(struct rt2x00_dev *rt2x00dev,
765 struct ieee80211_conf *conf,
766 struct rf_channel *rf,
767 struct channel_info *info)
768{
769 u8 rfcsr;
770
771 rt2800_rfcsr_write(rt2x00dev, 2, rf->rf1);
772 rt2800_rfcsr_write(rt2x00dev, 2, rf->rf3);
773
774 rt2800_rfcsr_read(rt2x00dev, 6, &rfcsr);
775 rt2x00_set_field8(&rfcsr, RFCSR6_R, rf->rf2);
776 rt2800_rfcsr_write(rt2x00dev, 6, rfcsr);
777
778 rt2800_rfcsr_read(rt2x00dev, 12, &rfcsr);
779 rt2x00_set_field8(&rfcsr, RFCSR12_TX_POWER,
780 TXPOWER_G_TO_DEV(info->tx_power1));
781 rt2800_rfcsr_write(rt2x00dev, 12, rfcsr);
782
783 rt2800_rfcsr_read(rt2x00dev, 23, &rfcsr);
784 rt2x00_set_field8(&rfcsr, RFCSR23_FREQ_OFFSET, rt2x00dev->freq_offset);
785 rt2800_rfcsr_write(rt2x00dev, 23, rfcsr);
786
787 rt2800_rfcsr_write(rt2x00dev, 24,
788 rt2x00dev->calibration[conf_is_ht40(conf)]);
789
790 rt2800_rfcsr_read(rt2x00dev, 23, &rfcsr);
791 rt2x00_set_field8(&rfcsr, RFCSR7_RF_TUNING, 1);
792 rt2800_rfcsr_write(rt2x00dev, 23, rfcsr);
793}
794
795static void rt2800_config_channel(struct rt2x00_dev *rt2x00dev,
796 struct ieee80211_conf *conf,
797 struct rf_channel *rf,
798 struct channel_info *info)
799{
800 u32 reg;
801 unsigned int tx_pin;
802 u8 bbp;
803
804 if (rt2x00_rev(&rt2x00dev->chip) != RT3070_VERSION)
805 rt2800_config_channel_rt2x(rt2x00dev, conf, rf, info);
806 else
807 rt2800_config_channel_rt3x(rt2x00dev, conf, rf, info);
808
809 /*
810 * Change BBP settings
811 */
812 rt2800_bbp_write(rt2x00dev, 62, 0x37 - rt2x00dev->lna_gain);
813 rt2800_bbp_write(rt2x00dev, 63, 0x37 - rt2x00dev->lna_gain);
814 rt2800_bbp_write(rt2x00dev, 64, 0x37 - rt2x00dev->lna_gain);
815 rt2800_bbp_write(rt2x00dev, 86, 0);
816
817 if (rf->channel <= 14) {
818 if (test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags)) {
819 rt2800_bbp_write(rt2x00dev, 82, 0x62);
820 rt2800_bbp_write(rt2x00dev, 75, 0x46);
821 } else {
822 rt2800_bbp_write(rt2x00dev, 82, 0x84);
823 rt2800_bbp_write(rt2x00dev, 75, 0x50);
824 }
825 } else {
826 rt2800_bbp_write(rt2x00dev, 82, 0xf2);
827
828 if (test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags))
829 rt2800_bbp_write(rt2x00dev, 75, 0x46);
830 else
831 rt2800_bbp_write(rt2x00dev, 75, 0x50);
832 }
833
834 rt2800_register_read(rt2x00dev, TX_BAND_CFG, &reg);
835 rt2x00_set_field32(&reg, TX_BAND_CFG_HT40_PLUS, conf_is_ht40_plus(conf));
836 rt2x00_set_field32(&reg, TX_BAND_CFG_A, rf->channel > 14);
837 rt2x00_set_field32(&reg, TX_BAND_CFG_BG, rf->channel <= 14);
838 rt2800_register_write(rt2x00dev, TX_BAND_CFG, reg);
839
840 tx_pin = 0;
841
842 /* Turn on unused PA or LNA when not using 1T or 1R */
843 if (rt2x00dev->default_ant.tx != 1) {
844 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A1_EN, 1);
845 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G1_EN, 1);
846 }
847
848 /* Turn on unused PA or LNA when not using 1T or 1R */
849 if (rt2x00dev->default_ant.rx != 1) {
850 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A1_EN, 1);
851 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G1_EN, 1);
852 }
853
854 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A0_EN, 1);
855 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G0_EN, 1);
856 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_RFTR_EN, 1);
857 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_TRSW_EN, 1);
858 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G0_EN, rf->channel <= 14);
859 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A0_EN, rf->channel > 14);
860
861 rt2800_register_write(rt2x00dev, TX_PIN_CFG, tx_pin);
862
863 rt2800_bbp_read(rt2x00dev, 4, &bbp);
864 rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 2 * conf_is_ht40(conf));
865 rt2800_bbp_write(rt2x00dev, 4, bbp);
866
867 rt2800_bbp_read(rt2x00dev, 3, &bbp);
868 rt2x00_set_field8(&bbp, BBP3_HT40_PLUS, conf_is_ht40_plus(conf));
869 rt2800_bbp_write(rt2x00dev, 3, bbp);
870
871 if (rt2x00_rev(&rt2x00dev->chip) == RT2860C_VERSION) {
872 if (conf_is_ht40(conf)) {
873 rt2800_bbp_write(rt2x00dev, 69, 0x1a);
874 rt2800_bbp_write(rt2x00dev, 70, 0x0a);
875 rt2800_bbp_write(rt2x00dev, 73, 0x16);
876 } else {
877 rt2800_bbp_write(rt2x00dev, 69, 0x16);
878 rt2800_bbp_write(rt2x00dev, 70, 0x08);
879 rt2800_bbp_write(rt2x00dev, 73, 0x11);
880 }
881 }
882
883 msleep(1);
884}
885
886static void rt2800_config_txpower(struct rt2x00_dev *rt2x00dev,
887 const int txpower)
888{
889 u32 reg;
890 u32 value = TXPOWER_G_TO_DEV(txpower);
891 u8 r1;
892
893 rt2800_bbp_read(rt2x00dev, 1, &r1);
894 rt2x00_set_field8(&reg, BBP1_TX_POWER, 0);
895 rt2800_bbp_write(rt2x00dev, 1, r1);
896
897 rt2800_register_read(rt2x00dev, TX_PWR_CFG_0, &reg);
898 rt2x00_set_field32(&reg, TX_PWR_CFG_0_1MBS, value);
899 rt2x00_set_field32(&reg, TX_PWR_CFG_0_2MBS, value);
900 rt2x00_set_field32(&reg, TX_PWR_CFG_0_55MBS, value);
901 rt2x00_set_field32(&reg, TX_PWR_CFG_0_11MBS, value);
902 rt2x00_set_field32(&reg, TX_PWR_CFG_0_6MBS, value);
903 rt2x00_set_field32(&reg, TX_PWR_CFG_0_9MBS, value);
904 rt2x00_set_field32(&reg, TX_PWR_CFG_0_12MBS, value);
905 rt2x00_set_field32(&reg, TX_PWR_CFG_0_18MBS, value);
906 rt2800_register_write(rt2x00dev, TX_PWR_CFG_0, reg);
907
908 rt2800_register_read(rt2x00dev, TX_PWR_CFG_1, &reg);
909 rt2x00_set_field32(&reg, TX_PWR_CFG_1_24MBS, value);
910 rt2x00_set_field32(&reg, TX_PWR_CFG_1_36MBS, value);
911 rt2x00_set_field32(&reg, TX_PWR_CFG_1_48MBS, value);
912 rt2x00_set_field32(&reg, TX_PWR_CFG_1_54MBS, value);
913 rt2x00_set_field32(&reg, TX_PWR_CFG_1_MCS0, value);
914 rt2x00_set_field32(&reg, TX_PWR_CFG_1_MCS1, value);
915 rt2x00_set_field32(&reg, TX_PWR_CFG_1_MCS2, value);
916 rt2x00_set_field32(&reg, TX_PWR_CFG_1_MCS3, value);
917 rt2800_register_write(rt2x00dev, TX_PWR_CFG_1, reg);
918
919 rt2800_register_read(rt2x00dev, TX_PWR_CFG_2, &reg);
920 rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS4, value);
921 rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS5, value);
922 rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS6, value);
923 rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS7, value);
924 rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS8, value);
925 rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS9, value);
926 rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS10, value);
927 rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS11, value);
928 rt2800_register_write(rt2x00dev, TX_PWR_CFG_2, reg);
929
930 rt2800_register_read(rt2x00dev, TX_PWR_CFG_3, &reg);
931 rt2x00_set_field32(&reg, TX_PWR_CFG_3_MCS12, value);
932 rt2x00_set_field32(&reg, TX_PWR_CFG_3_MCS13, value);
933 rt2x00_set_field32(&reg, TX_PWR_CFG_3_MCS14, value);
934 rt2x00_set_field32(&reg, TX_PWR_CFG_3_MCS15, value);
935 rt2x00_set_field32(&reg, TX_PWR_CFG_3_UKNOWN1, value);
936 rt2x00_set_field32(&reg, TX_PWR_CFG_3_UKNOWN2, value);
937 rt2x00_set_field32(&reg, TX_PWR_CFG_3_UKNOWN3, value);
938 rt2x00_set_field32(&reg, TX_PWR_CFG_3_UKNOWN4, value);
939 rt2800_register_write(rt2x00dev, TX_PWR_CFG_3, reg);
940
941 rt2800_register_read(rt2x00dev, TX_PWR_CFG_4, &reg);
942 rt2x00_set_field32(&reg, TX_PWR_CFG_4_UKNOWN5, value);
943 rt2x00_set_field32(&reg, TX_PWR_CFG_4_UKNOWN6, value);
944 rt2x00_set_field32(&reg, TX_PWR_CFG_4_UKNOWN7, value);
945 rt2x00_set_field32(&reg, TX_PWR_CFG_4_UKNOWN8, value);
946 rt2800_register_write(rt2x00dev, TX_PWR_CFG_4, reg);
947}
948
949static void rt2800_config_retry_limit(struct rt2x00_dev *rt2x00dev,
950 struct rt2x00lib_conf *libconf)
951{
952 u32 reg;
953
954 rt2800_register_read(rt2x00dev, TX_RTY_CFG, &reg);
955 rt2x00_set_field32(&reg, TX_RTY_CFG_SHORT_RTY_LIMIT,
956 libconf->conf->short_frame_max_tx_count);
957 rt2x00_set_field32(&reg, TX_RTY_CFG_LONG_RTY_LIMIT,
958 libconf->conf->long_frame_max_tx_count);
959 rt2x00_set_field32(&reg, TX_RTY_CFG_LONG_RTY_THRE, 2000);
960 rt2x00_set_field32(&reg, TX_RTY_CFG_NON_AGG_RTY_MODE, 0);
961 rt2x00_set_field32(&reg, TX_RTY_CFG_AGG_RTY_MODE, 0);
962 rt2x00_set_field32(&reg, TX_RTY_CFG_TX_AUTO_FB_ENABLE, 1);
963 rt2800_register_write(rt2x00dev, TX_RTY_CFG, reg);
964}
965
966static void rt2800_config_ps(struct rt2x00_dev *rt2x00dev,
967 struct rt2x00lib_conf *libconf)
968{
969 enum dev_state state =
970 (libconf->conf->flags & IEEE80211_CONF_PS) ?
971 STATE_SLEEP : STATE_AWAKE;
972 u32 reg;
973
974 if (state == STATE_SLEEP) {
975 rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, 0);
976
977 rt2800_register_read(rt2x00dev, AUTOWAKEUP_CFG, &reg);
978 rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTO_LEAD_TIME, 5);
979 rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_TBCN_BEFORE_WAKE,
980 libconf->conf->listen_interval - 1);
981 rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTOWAKE, 1);
982 rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, reg);
983
984 rt2x00dev->ops->lib->set_device_state(rt2x00dev, state);
985 } else {
986 rt2x00dev->ops->lib->set_device_state(rt2x00dev, state);
987
988 rt2800_register_read(rt2x00dev, AUTOWAKEUP_CFG, &reg);
989 rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTO_LEAD_TIME, 0);
990 rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_TBCN_BEFORE_WAKE, 0);
991 rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTOWAKE, 0);
992 rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, reg);
993 }
994}
995
996void rt2800_config(struct rt2x00_dev *rt2x00dev,
997 struct rt2x00lib_conf *libconf,
998 const unsigned int flags)
999{
1000 /* Always recalculate LNA gain before changing configuration */
1001 rt2800_config_lna_gain(rt2x00dev, libconf);
1002
1003 if (flags & IEEE80211_CONF_CHANGE_CHANNEL)
1004 rt2800_config_channel(rt2x00dev, libconf->conf,
1005 &libconf->rf, &libconf->channel);
1006 if (flags & IEEE80211_CONF_CHANGE_POWER)
1007 rt2800_config_txpower(rt2x00dev, libconf->conf->power_level);
1008 if (flags & IEEE80211_CONF_CHANGE_RETRY_LIMITS)
1009 rt2800_config_retry_limit(rt2x00dev, libconf);
1010 if (flags & IEEE80211_CONF_CHANGE_PS)
1011 rt2800_config_ps(rt2x00dev, libconf);
1012}
1013EXPORT_SYMBOL_GPL(rt2800_config);
1014
1015/*
1016 * Link tuning
1017 */
1018void rt2800_link_stats(struct rt2x00_dev *rt2x00dev, struct link_qual *qual)
1019{
1020 u32 reg;
1021
1022 /*
1023 * Update FCS error count from register.
1024 */
1025 rt2800_register_read(rt2x00dev, RX_STA_CNT0, &reg);
1026 qual->rx_failed = rt2x00_get_field32(reg, RX_STA_CNT0_CRC_ERR);
1027}
1028EXPORT_SYMBOL_GPL(rt2800_link_stats);
1029
1030static u8 rt2800_get_default_vgc(struct rt2x00_dev *rt2x00dev)
1031{
1032 if (rt2x00dev->curr_band == IEEE80211_BAND_2GHZ) {
1033 if (rt2x00_intf_is_usb(rt2x00dev) &&
1034 rt2x00_rev(&rt2x00dev->chip) == RT3070_VERSION)
1035 return 0x1c + (2 * rt2x00dev->lna_gain);
1036 else
1037 return 0x2e + rt2x00dev->lna_gain;
1038 }
1039
1040 if (!test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags))
1041 return 0x32 + (rt2x00dev->lna_gain * 5) / 3;
1042 else
1043 return 0x3a + (rt2x00dev->lna_gain * 5) / 3;
1044}
1045
1046static inline void rt2800_set_vgc(struct rt2x00_dev *rt2x00dev,
1047 struct link_qual *qual, u8 vgc_level)
1048{
1049 if (qual->vgc_level != vgc_level) {
1050 rt2800_bbp_write(rt2x00dev, 66, vgc_level);
1051 qual->vgc_level = vgc_level;
1052 qual->vgc_level_reg = vgc_level;
1053 }
1054}
1055
1056void rt2800_reset_tuner(struct rt2x00_dev *rt2x00dev, struct link_qual *qual)
1057{
1058 rt2800_set_vgc(rt2x00dev, qual, rt2800_get_default_vgc(rt2x00dev));
1059}
1060EXPORT_SYMBOL_GPL(rt2800_reset_tuner);
1061
1062void rt2800_link_tuner(struct rt2x00_dev *rt2x00dev, struct link_qual *qual,
1063 const u32 count)
1064{
1065 if (rt2x00_rev(&rt2x00dev->chip) == RT2860C_VERSION)
1066 return;
1067
1068 /*
1069 * When RSSI is better then -80 increase VGC level with 0x10
1070 */
1071 rt2800_set_vgc(rt2x00dev, qual,
1072 rt2800_get_default_vgc(rt2x00dev) +
1073 ((qual->rssi > -80) * 0x10));
1074}
1075EXPORT_SYMBOL_GPL(rt2800_link_tuner);
1076
1077/*
1078 * Initialization functions.
1079 */
1080int rt2800_init_registers(struct rt2x00_dev *rt2x00dev)
1081{
1082 u32 reg;
1083 unsigned int i;
1084
1085 if (rt2x00_intf_is_usb(rt2x00dev)) {
1086 /*
1087 * Wait untill BBP and RF are ready.
1088 */
1089 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
1090 rt2800_register_read(rt2x00dev, MAC_CSR0, &reg);
1091 if (reg && reg != ~0)
1092 break;
1093 msleep(1);
1094 }
1095
1096 if (i == REGISTER_BUSY_COUNT) {
1097 ERROR(rt2x00dev, "Unstable hardware.\n");
1098 return -EBUSY;
1099 }
1100
1101 rt2800_register_read(rt2x00dev, PBF_SYS_CTRL, &reg);
1102 rt2800_register_write(rt2x00dev, PBF_SYS_CTRL,
1103 reg & ~0x00002000);
1104 } else if (rt2x00_intf_is_pci(rt2x00dev))
1105 rt2800_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000003);
1106
1107 rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
1108 rt2x00_set_field32(&reg, MAC_SYS_CTRL_RESET_CSR, 1);
1109 rt2x00_set_field32(&reg, MAC_SYS_CTRL_RESET_BBP, 1);
1110 rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
1111
1112 if (rt2x00_intf_is_usb(rt2x00dev)) {
1113 rt2800_register_write(rt2x00dev, USB_DMA_CFG, 0x00000000);
1114#ifdef CONFIG_RT2800USB
1115 rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE, 0,
1116 USB_MODE_RESET, REGISTER_TIMEOUT);
1117#endif
1118 }
1119
1120 rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, 0x00000000);
1121
1122 rt2800_register_read(rt2x00dev, BCN_OFFSET0, &reg);
1123 rt2x00_set_field32(&reg, BCN_OFFSET0_BCN0, 0xe0); /* 0x3800 */
1124 rt2x00_set_field32(&reg, BCN_OFFSET0_BCN1, 0xe8); /* 0x3a00 */
1125 rt2x00_set_field32(&reg, BCN_OFFSET0_BCN2, 0xf0); /* 0x3c00 */
1126 rt2x00_set_field32(&reg, BCN_OFFSET0_BCN3, 0xf8); /* 0x3e00 */
1127 rt2800_register_write(rt2x00dev, BCN_OFFSET0, reg);
1128
1129 rt2800_register_read(rt2x00dev, BCN_OFFSET1, &reg);
1130 rt2x00_set_field32(&reg, BCN_OFFSET1_BCN4, 0xc8); /* 0x3200 */
1131 rt2x00_set_field32(&reg, BCN_OFFSET1_BCN5, 0xd0); /* 0x3400 */
1132 rt2x00_set_field32(&reg, BCN_OFFSET1_BCN6, 0x77); /* 0x1dc0 */
1133 rt2x00_set_field32(&reg, BCN_OFFSET1_BCN7, 0x6f); /* 0x1bc0 */
1134 rt2800_register_write(rt2x00dev, BCN_OFFSET1, reg);
1135
1136 rt2800_register_write(rt2x00dev, LEGACY_BASIC_RATE, 0x0000013f);
1137 rt2800_register_write(rt2x00dev, HT_BASIC_RATE, 0x00008003);
1138
1139 rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, 0x00000000);
1140
1141 rt2800_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
1142 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_INTERVAL, 0);
1143 rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 0);
1144 rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_SYNC, 0);
1145 rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 0);
1146 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 0);
1147 rt2x00_set_field32(&reg, BCN_TIME_CFG_TX_TIME_COMPENSATE, 0);
1148 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
1149
1150 if (rt2x00_intf_is_usb(rt2x00dev) &&
1151 rt2x00_rev(&rt2x00dev->chip) == RT3070_VERSION) {
1152 rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000400);
1153 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000);
1154 rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000);
1155 } else {
1156 rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000000);
1157 rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606);
1158 }
1159
1160 rt2800_register_read(rt2x00dev, TX_LINK_CFG, &reg);
1161 rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_MFB_LIFETIME, 32);
1162 rt2x00_set_field32(&reg, TX_LINK_CFG_MFB_ENABLE, 0);
1163 rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_UMFS_ENABLE, 0);
1164 rt2x00_set_field32(&reg, TX_LINK_CFG_TX_MRQ_EN, 0);
1165 rt2x00_set_field32(&reg, TX_LINK_CFG_TX_RDG_EN, 0);
1166 rt2x00_set_field32(&reg, TX_LINK_CFG_TX_CF_ACK_EN, 1);
1167 rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_MFB, 0);
1168 rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_MFS, 0);
1169 rt2800_register_write(rt2x00dev, TX_LINK_CFG, reg);
1170
1171 rt2800_register_read(rt2x00dev, TX_TIMEOUT_CFG, &reg);
1172 rt2x00_set_field32(&reg, TX_TIMEOUT_CFG_MPDU_LIFETIME, 9);
1173 rt2x00_set_field32(&reg, TX_TIMEOUT_CFG_TX_OP_TIMEOUT, 10);
1174 rt2800_register_write(rt2x00dev, TX_TIMEOUT_CFG, reg);
1175
1176 rt2800_register_read(rt2x00dev, MAX_LEN_CFG, &reg);
1177 rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_MPDU, AGGREGATION_SIZE);
1178 if (rt2x00_rev(&rt2x00dev->chip) >= RT2880E_VERSION &&
1179 rt2x00_rev(&rt2x00dev->chip) < RT3070_VERSION)
1180 rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_PSDU, 2);
1181 else
1182 rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_PSDU, 1);
1183 rt2x00_set_field32(&reg, MAX_LEN_CFG_MIN_PSDU, 0);
1184 rt2x00_set_field32(&reg, MAX_LEN_CFG_MIN_MPDU, 0);
1185 rt2800_register_write(rt2x00dev, MAX_LEN_CFG, reg);
1186
1187 rt2800_register_write(rt2x00dev, PBF_MAX_PCNT, 0x1f3fbf9f);
1188
1189 rt2800_register_read(rt2x00dev, AUTO_RSP_CFG, &reg);
1190 rt2x00_set_field32(&reg, AUTO_RSP_CFG_AUTORESPONDER, 1);
1191 rt2x00_set_field32(&reg, AUTO_RSP_CFG_CTS_40_MMODE, 0);
1192 rt2x00_set_field32(&reg, AUTO_RSP_CFG_CTS_40_MREF, 0);
1193 rt2x00_set_field32(&reg, AUTO_RSP_CFG_DUAL_CTS_EN, 0);
1194 rt2x00_set_field32(&reg, AUTO_RSP_CFG_ACK_CTS_PSM_BIT, 0);
1195 rt2800_register_write(rt2x00dev, AUTO_RSP_CFG, reg);
1196
1197 rt2800_register_read(rt2x00dev, CCK_PROT_CFG, &reg);
1198 rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_RATE, 8);
1199 rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_CTRL, 0);
1200 rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_NAV, 1);
1201 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_CCK, 1);
1202 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
1203 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_MM20, 1);
1204 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_MM40, 1);
1205 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_GF20, 1);
1206 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_GF40, 1);
1207 rt2800_register_write(rt2x00dev, CCK_PROT_CFG, reg);
1208
1209 rt2800_register_read(rt2x00dev, OFDM_PROT_CFG, &reg);
1210 rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_RATE, 8);
1211 rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_CTRL, 0);
1212 rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_NAV, 1);
1213 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_CCK, 1);
1214 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
1215 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_MM20, 1);
1216 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_MM40, 1);
1217 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_GF20, 1);
1218 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_GF40, 1);
1219 rt2800_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
1220
1221 rt2800_register_read(rt2x00dev, MM20_PROT_CFG, &reg);
1222 rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_RATE, 0x4004);
1223 rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_CTRL, 0);
1224 rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_NAV, 1);
1225 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_CCK, 1);
1226 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
1227 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_MM20, 1);
1228 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_MM40, 0);
1229 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_GF20, 1);
1230 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_GF40, 0);
1231 rt2800_register_write(rt2x00dev, MM20_PROT_CFG, reg);
1232
1233 rt2800_register_read(rt2x00dev, MM40_PROT_CFG, &reg);
1234 rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_RATE, 0x4084);
1235 rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_CTRL, 0);
1236 rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_NAV, 1);
1237 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_CCK, 1);
1238 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
1239 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_MM20, 1);
1240 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_MM40, 1);
1241 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_GF20, 1);
1242 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_GF40, 1);
1243 rt2800_register_write(rt2x00dev, MM40_PROT_CFG, reg);
1244
1245 rt2800_register_read(rt2x00dev, GF20_PROT_CFG, &reg);
1246 rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_RATE, 0x4004);
1247 rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_CTRL, 0);
1248 rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_NAV, 1);
1249 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_CCK, 1);
1250 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
1251 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_MM20, 1);
1252 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_MM40, 0);
1253 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_GF20, 1);
1254 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_GF40, 0);
1255 rt2800_register_write(rt2x00dev, GF20_PROT_CFG, reg);
1256
1257 rt2800_register_read(rt2x00dev, GF40_PROT_CFG, &reg);
1258 rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_RATE, 0x4084);
1259 rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_CTRL, 0);
1260 rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_NAV, 1);
1261 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_CCK, 1);
1262 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
1263 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_MM20, 1);
1264 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_MM40, 1);
1265 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_GF20, 1);
1266 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_GF40, 1);
1267 rt2800_register_write(rt2x00dev, GF40_PROT_CFG, reg);
1268
1269 if (rt2x00_intf_is_usb(rt2x00dev)) {
1270 rt2800_register_write(rt2x00dev, PBF_CFG, 0xf40006);
1271
1272 rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
1273 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
1274 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_DMA_BUSY, 0);
1275 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
1276 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_RX_DMA_BUSY, 0);
1277 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_WP_DMA_BURST_SIZE, 3);
1278 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 0);
1279 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_BIG_ENDIAN, 0);
1280 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_RX_HDR_SCATTER, 0);
1281 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_HDR_SEG_LEN, 0);
1282 rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
1283 }
1284
1285 rt2800_register_write(rt2x00dev, TXOP_CTRL_CFG, 0x0000583f);
1286 rt2800_register_write(rt2x00dev, TXOP_HLDR_ET, 0x00000002);
1287
1288 rt2800_register_read(rt2x00dev, TX_RTS_CFG, &reg);
1289 rt2x00_set_field32(&reg, TX_RTS_CFG_AUTO_RTS_RETRY_LIMIT, 32);
1290 rt2x00_set_field32(&reg, TX_RTS_CFG_RTS_THRES,
1291 IEEE80211_MAX_RTS_THRESHOLD);
1292 rt2x00_set_field32(&reg, TX_RTS_CFG_RTS_FBK_EN, 0);
1293 rt2800_register_write(rt2x00dev, TX_RTS_CFG, reg);
1294
1295 rt2800_register_write(rt2x00dev, EXP_ACK_TIME, 0x002400ca);
1296 rt2800_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000003);
1297
1298 /*
1299 * ASIC will keep garbage value after boot, clear encryption keys.
1300 */
1301 for (i = 0; i < 4; i++)
1302 rt2800_register_write(rt2x00dev,
1303 SHARED_KEY_MODE_ENTRY(i), 0);
1304
1305 for (i = 0; i < 256; i++) {
1306 u32 wcid[2] = { 0xffffffff, 0x00ffffff };
1307 rt2800_register_multiwrite(rt2x00dev, MAC_WCID_ENTRY(i),
1308 wcid, sizeof(wcid));
1309
1310 rt2800_register_write(rt2x00dev, MAC_WCID_ATTR_ENTRY(i), 1);
1311 rt2800_register_write(rt2x00dev, MAC_IVEIV_ENTRY(i), 0);
1312 }
1313
1314 /*
1315 * Clear all beacons
1316 * For the Beacon base registers we only need to clear
1317 * the first byte since that byte contains the VALID and OWNER
1318 * bits which (when set to 0) will invalidate the entire beacon.
1319 */
1320 rt2800_register_write(rt2x00dev, HW_BEACON_BASE0, 0);
1321 rt2800_register_write(rt2x00dev, HW_BEACON_BASE1, 0);
1322 rt2800_register_write(rt2x00dev, HW_BEACON_BASE2, 0);
1323 rt2800_register_write(rt2x00dev, HW_BEACON_BASE3, 0);
1324 rt2800_register_write(rt2x00dev, HW_BEACON_BASE4, 0);
1325 rt2800_register_write(rt2x00dev, HW_BEACON_BASE5, 0);
1326 rt2800_register_write(rt2x00dev, HW_BEACON_BASE6, 0);
1327 rt2800_register_write(rt2x00dev, HW_BEACON_BASE7, 0);
1328
1329 if (rt2x00_intf_is_usb(rt2x00dev)) {
1330 rt2800_register_read(rt2x00dev, USB_CYC_CFG, &reg);
1331 rt2x00_set_field32(&reg, USB_CYC_CFG_CLOCK_CYCLE, 30);
1332 rt2800_register_write(rt2x00dev, USB_CYC_CFG, reg);
1333 }
1334
1335 rt2800_register_read(rt2x00dev, HT_FBK_CFG0, &reg);
1336 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS0FBK, 0);
1337 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS1FBK, 0);
1338 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS2FBK, 1);
1339 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS3FBK, 2);
1340 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS4FBK, 3);
1341 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS5FBK, 4);
1342 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS6FBK, 5);
1343 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS7FBK, 6);
1344 rt2800_register_write(rt2x00dev, HT_FBK_CFG0, reg);
1345
1346 rt2800_register_read(rt2x00dev, HT_FBK_CFG1, &reg);
1347 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS8FBK, 8);
1348 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS9FBK, 8);
1349 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS10FBK, 9);
1350 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS11FBK, 10);
1351 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS12FBK, 11);
1352 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS13FBK, 12);
1353 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS14FBK, 13);
1354 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS15FBK, 14);
1355 rt2800_register_write(rt2x00dev, HT_FBK_CFG1, reg);
1356
1357 rt2800_register_read(rt2x00dev, LG_FBK_CFG0, &reg);
1358 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS0FBK, 8);
1359 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS1FBK, 8);
1360 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS2FBK, 9);
1361 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS3FBK, 10);
1362 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS4FBK, 11);
1363 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS5FBK, 12);
1364 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS6FBK, 13);
1365 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS7FBK, 14);
1366 rt2800_register_write(rt2x00dev, LG_FBK_CFG0, reg);
1367
1368 rt2800_register_read(rt2x00dev, LG_FBK_CFG1, &reg);
1369 rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS0FBK, 0);
1370 rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS1FBK, 0);
1371 rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS2FBK, 1);
1372 rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS3FBK, 2);
1373 rt2800_register_write(rt2x00dev, LG_FBK_CFG1, reg);
1374
1375 /*
1376 * We must clear the error counters.
1377 * These registers are cleared on read,
1378 * so we may pass a useless variable to store the value.
1379 */
1380 rt2800_register_read(rt2x00dev, RX_STA_CNT0, &reg);
1381 rt2800_register_read(rt2x00dev, RX_STA_CNT1, &reg);
1382 rt2800_register_read(rt2x00dev, RX_STA_CNT2, &reg);
1383 rt2800_register_read(rt2x00dev, TX_STA_CNT0, &reg);
1384 rt2800_register_read(rt2x00dev, TX_STA_CNT1, &reg);
1385 rt2800_register_read(rt2x00dev, TX_STA_CNT2, &reg);
1386
1387 return 0;
1388}
1389EXPORT_SYMBOL_GPL(rt2800_init_registers);
1390
1391static int rt2800_wait_bbp_rf_ready(struct rt2x00_dev *rt2x00dev)
1392{
1393 unsigned int i;
1394 u32 reg;
1395
1396 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
1397 rt2800_register_read(rt2x00dev, MAC_STATUS_CFG, &reg);
1398 if (!rt2x00_get_field32(reg, MAC_STATUS_CFG_BBP_RF_BUSY))
1399 return 0;
1400
1401 udelay(REGISTER_BUSY_DELAY);
1402 }
1403
1404 ERROR(rt2x00dev, "BBP/RF register access failed, aborting.\n");
1405 return -EACCES;
1406}
1407
1408static int rt2800_wait_bbp_ready(struct rt2x00_dev *rt2x00dev)
1409{
1410 unsigned int i;
1411 u8 value;
1412
1413 /*
1414 * BBP was enabled after firmware was loaded,
1415 * but we need to reactivate it now.
1416 */
1417 rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
1418 rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
1419 msleep(1);
1420
1421 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
1422 rt2800_bbp_read(rt2x00dev, 0, &value);
1423 if ((value != 0xff) && (value != 0x00))
1424 return 0;
1425 udelay(REGISTER_BUSY_DELAY);
1426 }
1427
1428 ERROR(rt2x00dev, "BBP register access failed, aborting.\n");
1429 return -EACCES;
1430}
1431
1432int rt2800_init_bbp(struct rt2x00_dev *rt2x00dev)
1433{
1434 unsigned int i;
1435 u16 eeprom;
1436 u8 reg_id;
1437 u8 value;
1438
1439 if (unlikely(rt2800_wait_bbp_rf_ready(rt2x00dev) ||
1440 rt2800_wait_bbp_ready(rt2x00dev)))
1441 return -EACCES;
1442
1443 rt2800_bbp_write(rt2x00dev, 65, 0x2c);
1444 rt2800_bbp_write(rt2x00dev, 66, 0x38);
1445 rt2800_bbp_write(rt2x00dev, 69, 0x12);
1446 rt2800_bbp_write(rt2x00dev, 70, 0x0a);
1447 rt2800_bbp_write(rt2x00dev, 73, 0x10);
1448 rt2800_bbp_write(rt2x00dev, 81, 0x37);
1449 rt2800_bbp_write(rt2x00dev, 82, 0x62);
1450 rt2800_bbp_write(rt2x00dev, 83, 0x6a);
1451 rt2800_bbp_write(rt2x00dev, 84, 0x99);
1452 rt2800_bbp_write(rt2x00dev, 86, 0x00);
1453 rt2800_bbp_write(rt2x00dev, 91, 0x04);
1454 rt2800_bbp_write(rt2x00dev, 92, 0x00);
1455 rt2800_bbp_write(rt2x00dev, 103, 0x00);
1456 rt2800_bbp_write(rt2x00dev, 105, 0x05);
1457
1458 if (rt2x00_rev(&rt2x00dev->chip) == RT2860C_VERSION) {
1459 rt2800_bbp_write(rt2x00dev, 69, 0x16);
1460 rt2800_bbp_write(rt2x00dev, 73, 0x12);
1461 }
1462
1463 if (rt2x00_rev(&rt2x00dev->chip) > RT2860D_VERSION)
1464 rt2800_bbp_write(rt2x00dev, 84, 0x19);
1465
1466 if (rt2x00_intf_is_usb(rt2x00dev) &&
1467 rt2x00_rev(&rt2x00dev->chip) == RT3070_VERSION) {
1468 rt2800_bbp_write(rt2x00dev, 70, 0x0a);
1469 rt2800_bbp_write(rt2x00dev, 84, 0x99);
1470 rt2800_bbp_write(rt2x00dev, 105, 0x05);
1471 }
1472
1473 if (rt2x00_intf_is_pci(rt2x00dev) &&
1474 rt2x00_rt(&rt2x00dev->chip, RT3052)) {
1475 rt2800_bbp_write(rt2x00dev, 31, 0x08);
1476 rt2800_bbp_write(rt2x00dev, 78, 0x0e);
1477 rt2800_bbp_write(rt2x00dev, 80, 0x08);
1478 }
1479
1480 for (i = 0; i < EEPROM_BBP_SIZE; i++) {
1481 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBP_START + i, &eeprom);
1482
1483 if (eeprom != 0xffff && eeprom != 0x0000) {
1484 reg_id = rt2x00_get_field16(eeprom, EEPROM_BBP_REG_ID);
1485 value = rt2x00_get_field16(eeprom, EEPROM_BBP_VALUE);
1486 rt2800_bbp_write(rt2x00dev, reg_id, value);
1487 }
1488 }
1489
1490 return 0;
1491}
1492EXPORT_SYMBOL_GPL(rt2800_init_bbp);
1493
1494static u8 rt2800_init_rx_filter(struct rt2x00_dev *rt2x00dev,
1495 bool bw40, u8 rfcsr24, u8 filter_target)
1496{
1497 unsigned int i;
1498 u8 bbp;
1499 u8 rfcsr;
1500 u8 passband;
1501 u8 stopband;
1502 u8 overtuned = 0;
1503
1504 rt2800_rfcsr_write(rt2x00dev, 24, rfcsr24);
1505
1506 rt2800_bbp_read(rt2x00dev, 4, &bbp);
1507 rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 2 * bw40);
1508 rt2800_bbp_write(rt2x00dev, 4, bbp);
1509
1510 rt2800_rfcsr_read(rt2x00dev, 22, &rfcsr);
1511 rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 1);
1512 rt2800_rfcsr_write(rt2x00dev, 22, rfcsr);
1513
1514 /*
1515 * Set power & frequency of passband test tone
1516 */
1517 rt2800_bbp_write(rt2x00dev, 24, 0);
1518
1519 for (i = 0; i < 100; i++) {
1520 rt2800_bbp_write(rt2x00dev, 25, 0x90);
1521 msleep(1);
1522
1523 rt2800_bbp_read(rt2x00dev, 55, &passband);
1524 if (passband)
1525 break;
1526 }
1527
1528 /*
1529 * Set power & frequency of stopband test tone
1530 */
1531 rt2800_bbp_write(rt2x00dev, 24, 0x06);
1532
1533 for (i = 0; i < 100; i++) {
1534 rt2800_bbp_write(rt2x00dev, 25, 0x90);
1535 msleep(1);
1536
1537 rt2800_bbp_read(rt2x00dev, 55, &stopband);
1538
1539 if ((passband - stopband) <= filter_target) {
1540 rfcsr24++;
1541 overtuned += ((passband - stopband) == filter_target);
1542 } else
1543 break;
1544
1545 rt2800_rfcsr_write(rt2x00dev, 24, rfcsr24);
1546 }
1547
1548 rfcsr24 -= !!overtuned;
1549
1550 rt2800_rfcsr_write(rt2x00dev, 24, rfcsr24);
1551 return rfcsr24;
1552}
1553
1554int rt2800_init_rfcsr(struct rt2x00_dev *rt2x00dev)
1555{
1556 u8 rfcsr;
1557 u8 bbp;
1558
1559 if (rt2x00_intf_is_usb(rt2x00dev) &&
1560 rt2x00_rev(&rt2x00dev->chip) != RT3070_VERSION)
1561 return 0;
1562
1563 if (rt2x00_intf_is_pci(rt2x00dev)) {
1564 if (!rt2x00_rf(&rt2x00dev->chip, RF3020) &&
1565 !rt2x00_rf(&rt2x00dev->chip, RF3021) &&
1566 !rt2x00_rf(&rt2x00dev->chip, RF3022))
1567 return 0;
1568 }
1569
1570 /*
1571 * Init RF calibration.
1572 */
1573 rt2800_rfcsr_read(rt2x00dev, 30, &rfcsr);
1574 rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 1);
1575 rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
1576 msleep(1);
1577 rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 0);
1578 rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
1579
1580 if (rt2x00_intf_is_usb(rt2x00dev)) {
1581 rt2800_rfcsr_write(rt2x00dev, 4, 0x40);
1582 rt2800_rfcsr_write(rt2x00dev, 5, 0x03);
1583 rt2800_rfcsr_write(rt2x00dev, 6, 0x02);
1584 rt2800_rfcsr_write(rt2x00dev, 7, 0x70);
1585 rt2800_rfcsr_write(rt2x00dev, 9, 0x0f);
1586 rt2800_rfcsr_write(rt2x00dev, 10, 0x71);
1587 rt2800_rfcsr_write(rt2x00dev, 11, 0x21);
1588 rt2800_rfcsr_write(rt2x00dev, 12, 0x7b);
1589 rt2800_rfcsr_write(rt2x00dev, 14, 0x90);
1590 rt2800_rfcsr_write(rt2x00dev, 15, 0x58);
1591 rt2800_rfcsr_write(rt2x00dev, 16, 0xb3);
1592 rt2800_rfcsr_write(rt2x00dev, 17, 0x92);
1593 rt2800_rfcsr_write(rt2x00dev, 18, 0x2c);
1594 rt2800_rfcsr_write(rt2x00dev, 19, 0x02);
1595 rt2800_rfcsr_write(rt2x00dev, 20, 0xba);
1596 rt2800_rfcsr_write(rt2x00dev, 21, 0xdb);
1597 rt2800_rfcsr_write(rt2x00dev, 24, 0x16);
1598 rt2800_rfcsr_write(rt2x00dev, 25, 0x01);
1599 rt2800_rfcsr_write(rt2x00dev, 27, 0x03);
1600 rt2800_rfcsr_write(rt2x00dev, 29, 0x1f);
1601 } else if (rt2x00_intf_is_pci(rt2x00dev)) {
1602 rt2800_rfcsr_write(rt2x00dev, 0, 0x50);
1603 rt2800_rfcsr_write(rt2x00dev, 1, 0x01);
1604 rt2800_rfcsr_write(rt2x00dev, 2, 0xf7);
1605 rt2800_rfcsr_write(rt2x00dev, 3, 0x75);
1606 rt2800_rfcsr_write(rt2x00dev, 4, 0x40);
1607 rt2800_rfcsr_write(rt2x00dev, 5, 0x03);
1608 rt2800_rfcsr_write(rt2x00dev, 6, 0x02);
1609 rt2800_rfcsr_write(rt2x00dev, 7, 0x50);
1610 rt2800_rfcsr_write(rt2x00dev, 8, 0x39);
1611 rt2800_rfcsr_write(rt2x00dev, 9, 0x0f);
1612 rt2800_rfcsr_write(rt2x00dev, 10, 0x60);
1613 rt2800_rfcsr_write(rt2x00dev, 11, 0x21);
1614 rt2800_rfcsr_write(rt2x00dev, 12, 0x75);
1615 rt2800_rfcsr_write(rt2x00dev, 13, 0x75);
1616 rt2800_rfcsr_write(rt2x00dev, 14, 0x90);
1617 rt2800_rfcsr_write(rt2x00dev, 15, 0x58);
1618 rt2800_rfcsr_write(rt2x00dev, 16, 0xb3);
1619 rt2800_rfcsr_write(rt2x00dev, 17, 0x92);
1620 rt2800_rfcsr_write(rt2x00dev, 18, 0x2c);
1621 rt2800_rfcsr_write(rt2x00dev, 19, 0x02);
1622 rt2800_rfcsr_write(rt2x00dev, 20, 0xba);
1623 rt2800_rfcsr_write(rt2x00dev, 21, 0xdb);
1624 rt2800_rfcsr_write(rt2x00dev, 22, 0x00);
1625 rt2800_rfcsr_write(rt2x00dev, 23, 0x31);
1626 rt2800_rfcsr_write(rt2x00dev, 24, 0x08);
1627 rt2800_rfcsr_write(rt2x00dev, 25, 0x01);
1628 rt2800_rfcsr_write(rt2x00dev, 26, 0x25);
1629 rt2800_rfcsr_write(rt2x00dev, 27, 0x23);
1630 rt2800_rfcsr_write(rt2x00dev, 28, 0x13);
1631 rt2800_rfcsr_write(rt2x00dev, 29, 0x83);
1632 }
1633
1634 /*
1635 * Set RX Filter calibration for 20MHz and 40MHz
1636 */
1637 rt2x00dev->calibration[0] =
1638 rt2800_init_rx_filter(rt2x00dev, false, 0x07, 0x16);
1639 rt2x00dev->calibration[1] =
1640 rt2800_init_rx_filter(rt2x00dev, true, 0x27, 0x19);
1641
1642 /*
1643 * Set back to initial state
1644 */
1645 rt2800_bbp_write(rt2x00dev, 24, 0);
1646
1647 rt2800_rfcsr_read(rt2x00dev, 22, &rfcsr);
1648 rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 0);
1649 rt2800_rfcsr_write(rt2x00dev, 22, rfcsr);
1650
1651 /*
1652 * set BBP back to BW20
1653 */
1654 rt2800_bbp_read(rt2x00dev, 4, &bbp);
1655 rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 0);
1656 rt2800_bbp_write(rt2x00dev, 4, bbp);
1657
1658 return 0;
1659}
1660EXPORT_SYMBOL_GPL(rt2800_init_rfcsr);
1661
1662/*
1663 * IEEE80211 stack callback functions.
1664 */
1665static void rt2800_get_tkip_seq(struct ieee80211_hw *hw, u8 hw_key_idx,
1666 u32 *iv32, u16 *iv16)
1667{
1668 struct rt2x00_dev *rt2x00dev = hw->priv;
1669 struct mac_iveiv_entry iveiv_entry;
1670 u32 offset;
1671
1672 offset = MAC_IVEIV_ENTRY(hw_key_idx);
1673 rt2800_register_multiread(rt2x00dev, offset,
1674 &iveiv_entry, sizeof(iveiv_entry));
1675
1676 memcpy(&iveiv_entry.iv[0], iv16, sizeof(iv16));
1677 memcpy(&iveiv_entry.iv[4], iv32, sizeof(iv32));
1678}
1679
1680static int rt2800_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1681{
1682 struct rt2x00_dev *rt2x00dev = hw->priv;
1683 u32 reg;
1684 bool enabled = (value < IEEE80211_MAX_RTS_THRESHOLD);
1685
1686 rt2800_register_read(rt2x00dev, TX_RTS_CFG, &reg);
1687 rt2x00_set_field32(&reg, TX_RTS_CFG_RTS_THRES, value);
1688 rt2800_register_write(rt2x00dev, TX_RTS_CFG, reg);
1689
1690 rt2800_register_read(rt2x00dev, CCK_PROT_CFG, &reg);
1691 rt2x00_set_field32(&reg, CCK_PROT_CFG_RTS_TH_EN, enabled);
1692 rt2800_register_write(rt2x00dev, CCK_PROT_CFG, reg);
1693
1694 rt2800_register_read(rt2x00dev, OFDM_PROT_CFG, &reg);
1695 rt2x00_set_field32(&reg, OFDM_PROT_CFG_RTS_TH_EN, enabled);
1696 rt2800_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
1697
1698 rt2800_register_read(rt2x00dev, MM20_PROT_CFG, &reg);
1699 rt2x00_set_field32(&reg, MM20_PROT_CFG_RTS_TH_EN, enabled);
1700 rt2800_register_write(rt2x00dev, MM20_PROT_CFG, reg);
1701
1702 rt2800_register_read(rt2x00dev, MM40_PROT_CFG, &reg);
1703 rt2x00_set_field32(&reg, MM40_PROT_CFG_RTS_TH_EN, enabled);
1704 rt2800_register_write(rt2x00dev, MM40_PROT_CFG, reg);
1705
1706 rt2800_register_read(rt2x00dev, GF20_PROT_CFG, &reg);
1707 rt2x00_set_field32(&reg, GF20_PROT_CFG_RTS_TH_EN, enabled);
1708 rt2800_register_write(rt2x00dev, GF20_PROT_CFG, reg);
1709
1710 rt2800_register_read(rt2x00dev, GF40_PROT_CFG, &reg);
1711 rt2x00_set_field32(&reg, GF40_PROT_CFG_RTS_TH_EN, enabled);
1712 rt2800_register_write(rt2x00dev, GF40_PROT_CFG, reg);
1713
1714 return 0;
1715}
1716
1717static int rt2800_conf_tx(struct ieee80211_hw *hw, u16 queue_idx,
1718 const struct ieee80211_tx_queue_params *params)
1719{
1720 struct rt2x00_dev *rt2x00dev = hw->priv;
1721 struct data_queue *queue;
1722 struct rt2x00_field32 field;
1723 int retval;
1724 u32 reg;
1725 u32 offset;
1726
1727 /*
1728 * First pass the configuration through rt2x00lib, that will
1729 * update the queue settings and validate the input. After that
1730 * we are free to update the registers based on the value
1731 * in the queue parameter.
1732 */
1733 retval = rt2x00mac_conf_tx(hw, queue_idx, params);
1734 if (retval)
1735 return retval;
1736
1737 /*
1738 * We only need to perform additional register initialization
1739 * for WMM queues/
1740 */
1741 if (queue_idx >= 4)
1742 return 0;
1743
1744 queue = rt2x00queue_get_queue(rt2x00dev, queue_idx);
1745
1746 /* Update WMM TXOP register */
1747 offset = WMM_TXOP0_CFG + (sizeof(u32) * (!!(queue_idx & 2)));
1748 field.bit_offset = (queue_idx & 1) * 16;
1749 field.bit_mask = 0xffff << field.bit_offset;
1750
1751 rt2800_register_read(rt2x00dev, offset, &reg);
1752 rt2x00_set_field32(&reg, field, queue->txop);
1753 rt2800_register_write(rt2x00dev, offset, reg);
1754
1755 /* Update WMM registers */
1756 field.bit_offset = queue_idx * 4;
1757 field.bit_mask = 0xf << field.bit_offset;
1758
1759 rt2800_register_read(rt2x00dev, WMM_AIFSN_CFG, &reg);
1760 rt2x00_set_field32(&reg, field, queue->aifs);
1761 rt2800_register_write(rt2x00dev, WMM_AIFSN_CFG, reg);
1762
1763 rt2800_register_read(rt2x00dev, WMM_CWMIN_CFG, &reg);
1764 rt2x00_set_field32(&reg, field, queue->cw_min);
1765 rt2800_register_write(rt2x00dev, WMM_CWMIN_CFG, reg);
1766
1767 rt2800_register_read(rt2x00dev, WMM_CWMAX_CFG, &reg);
1768 rt2x00_set_field32(&reg, field, queue->cw_max);
1769 rt2800_register_write(rt2x00dev, WMM_CWMAX_CFG, reg);
1770
1771 /* Update EDCA registers */
1772 offset = EDCA_AC0_CFG + (sizeof(u32) * queue_idx);
1773
1774 rt2800_register_read(rt2x00dev, offset, &reg);
1775 rt2x00_set_field32(&reg, EDCA_AC0_CFG_TX_OP, queue->txop);
1776 rt2x00_set_field32(&reg, EDCA_AC0_CFG_AIFSN, queue->aifs);
1777 rt2x00_set_field32(&reg, EDCA_AC0_CFG_CWMIN, queue->cw_min);
1778 rt2x00_set_field32(&reg, EDCA_AC0_CFG_CWMAX, queue->cw_max);
1779 rt2800_register_write(rt2x00dev, offset, reg);
1780
1781 return 0;
1782}
1783
1784static u64 rt2800_get_tsf(struct ieee80211_hw *hw)
1785{
1786 struct rt2x00_dev *rt2x00dev = hw->priv;
1787 u64 tsf;
1788 u32 reg;
1789
1790 rt2800_register_read(rt2x00dev, TSF_TIMER_DW1, &reg);
1791 tsf = (u64) rt2x00_get_field32(reg, TSF_TIMER_DW1_HIGH_WORD) << 32;
1792 rt2800_register_read(rt2x00dev, TSF_TIMER_DW0, &reg);
1793 tsf |= rt2x00_get_field32(reg, TSF_TIMER_DW0_LOW_WORD);
1794
1795 return tsf;
1796}
1797
1798const struct ieee80211_ops rt2800_mac80211_ops = {
1799 .tx = rt2x00mac_tx,
1800 .start = rt2x00mac_start,
1801 .stop = rt2x00mac_stop,
1802 .add_interface = rt2x00mac_add_interface,
1803 .remove_interface = rt2x00mac_remove_interface,
1804 .config = rt2x00mac_config,
1805 .configure_filter = rt2x00mac_configure_filter,
1806 .set_tim = rt2x00mac_set_tim,
1807 .set_key = rt2x00mac_set_key,
1808 .get_stats = rt2x00mac_get_stats,
1809 .get_tkip_seq = rt2800_get_tkip_seq,
1810 .set_rts_threshold = rt2800_set_rts_threshold,
1811 .bss_info_changed = rt2x00mac_bss_info_changed,
1812 .conf_tx = rt2800_conf_tx,
1813 .get_tx_stats = rt2x00mac_get_tx_stats,
1814 .get_tsf = rt2800_get_tsf,
1815 .rfkill_poll = rt2x00mac_rfkill_poll,
1816};
1817EXPORT_SYMBOL_GPL(rt2800_mac80211_ops);
diff --git a/drivers/net/wireless/rt2x00/rt2800lib.h b/drivers/net/wireless/rt2x00/rt2800lib.h
new file mode 100644
index 000000000000..5eea8fcba6cc
--- /dev/null
+++ b/drivers/net/wireless/rt2x00/rt2800lib.h
@@ -0,0 +1,134 @@
1/*
2 Copyright (C) 2009 Bartlomiej Zolnierkiewicz
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the
16 Free Software Foundation, Inc.,
17 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20#ifndef RT2800LIB_H
21#define RT2800LIB_H
22
23struct rt2800_ops {
24 void (*register_read)(struct rt2x00_dev *rt2x00dev,
25 const unsigned int offset, u32 *value);
26 void (*register_write)(struct rt2x00_dev *rt2x00dev,
27 const unsigned int offset, u32 value);
28 void (*register_write_lock)(struct rt2x00_dev *rt2x00dev,
29 const unsigned int offset, u32 value);
30
31 void (*register_multiread)(struct rt2x00_dev *rt2x00dev,
32 const unsigned int offset,
33 void *value, const u32 length);
34 void (*register_multiwrite)(struct rt2x00_dev *rt2x00dev,
35 const unsigned int offset,
36 const void *value, const u32 length);
37
38 int (*regbusy_read)(struct rt2x00_dev *rt2x00dev,
39 const unsigned int offset,
40 const struct rt2x00_field32 field, u32 *reg);
41};
42
43static inline void rt2800_register_read(struct rt2x00_dev *rt2x00dev,
44 const unsigned int offset,
45 u32 *value)
46{
47 const struct rt2800_ops *rt2800ops = rt2x00dev->priv;
48
49 rt2800ops->register_read(rt2x00dev, offset, value);
50}
51
52static inline void rt2800_register_write(struct rt2x00_dev *rt2x00dev,
53 const unsigned int offset,
54 u32 value)
55{
56 const struct rt2800_ops *rt2800ops = rt2x00dev->priv;
57
58 rt2800ops->register_write(rt2x00dev, offset, value);
59}
60
61static inline void rt2800_register_write_lock(struct rt2x00_dev *rt2x00dev,
62 const unsigned int offset,
63 u32 value)
64{
65 const struct rt2800_ops *rt2800ops = rt2x00dev->priv;
66
67 rt2800ops->register_write_lock(rt2x00dev, offset, value);
68}
69
70static inline void rt2800_register_multiread(struct rt2x00_dev *rt2x00dev,
71 const unsigned int offset,
72 void *value, const u32 length)
73{
74 const struct rt2800_ops *rt2800ops = rt2x00dev->priv;
75
76 rt2800ops->register_multiread(rt2x00dev, offset, value, length);
77}
78
79static inline void rt2800_register_multiwrite(struct rt2x00_dev *rt2x00dev,
80 const unsigned int offset,
81 const void *value,
82 const u32 length)
83{
84 const struct rt2800_ops *rt2800ops = rt2x00dev->priv;
85
86 rt2800ops->register_multiwrite(rt2x00dev, offset, value, length);
87}
88
89static inline int rt2800_regbusy_read(struct rt2x00_dev *rt2x00dev,
90 const unsigned int offset,
91 const struct rt2x00_field32 field,
92 u32 *reg)
93{
94 const struct rt2800_ops *rt2800ops = rt2x00dev->priv;
95
96 return rt2800ops->regbusy_read(rt2x00dev, offset, field, reg);
97}
98
99void rt2800_mcu_request(struct rt2x00_dev *rt2x00dev,
100 const u8 command, const u8 token,
101 const u8 arg0, const u8 arg1);
102
103extern const struct rt2x00debug rt2800_rt2x00debug;
104
105int rt2800_rfkill_poll(struct rt2x00_dev *rt2x00dev);
106void rt2800_init_led(struct rt2x00_dev *rt2x00dev,
107 struct rt2x00_led *led, enum led_type type);
108int rt2800_config_shared_key(struct rt2x00_dev *rt2x00dev,
109 struct rt2x00lib_crypto *crypto,
110 struct ieee80211_key_conf *key);
111int rt2800_config_pairwise_key(struct rt2x00_dev *rt2x00dev,
112 struct rt2x00lib_crypto *crypto,
113 struct ieee80211_key_conf *key);
114void rt2800_config_filter(struct rt2x00_dev *rt2x00dev,
115 const unsigned int filter_flags);
116void rt2800_config_intf(struct rt2x00_dev *rt2x00dev, struct rt2x00_intf *intf,
117 struct rt2x00intf_conf *conf, const unsigned int flags);
118void rt2800_config_erp(struct rt2x00_dev *rt2x00dev, struct rt2x00lib_erp *erp);
119void rt2800_config_ant(struct rt2x00_dev *rt2x00dev, struct antenna_setup *ant);
120void rt2800_config(struct rt2x00_dev *rt2x00dev,
121 struct rt2x00lib_conf *libconf,
122 const unsigned int flags);
123void rt2800_link_stats(struct rt2x00_dev *rt2x00dev, struct link_qual *qual);
124void rt2800_reset_tuner(struct rt2x00_dev *rt2x00dev, struct link_qual *qual);
125void rt2800_link_tuner(struct rt2x00_dev *rt2x00dev, struct link_qual *qual,
126 const u32 count);
127
128int rt2800_init_registers(struct rt2x00_dev *rt2x00dev);
129int rt2800_init_bbp(struct rt2x00_dev *rt2x00dev);
130int rt2800_init_rfcsr(struct rt2x00_dev *rt2x00dev);
131
132extern const struct ieee80211_ops rt2800_mac80211_ops;
133
134#endif /* RT2800LIB_H */
diff --git a/drivers/net/wireless/rt2x00/rt2800pci.c b/drivers/net/wireless/rt2x00/rt2800pci.c
index be81788b80c7..3c5b875cdee8 100644
--- a/drivers/net/wireless/rt2x00/rt2800pci.c
+++ b/drivers/net/wireless/rt2x00/rt2800pci.c
@@ -37,6 +37,8 @@
37#include "rt2x00.h" 37#include "rt2x00.h"
38#include "rt2x00pci.h" 38#include "rt2x00pci.h"
39#include "rt2x00soc.h" 39#include "rt2x00soc.h"
40#include "rt2800lib.h"
41#include "rt2800.h"
40#include "rt2800pci.h" 42#include "rt2800pci.h"
41 43
42#ifdef CONFIG_RT2800PCI_PCI_MODULE 44#ifdef CONFIG_RT2800PCI_PCI_MODULE
@@ -54,205 +56,13 @@ static int modparam_nohwcrypt = 1;
54module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO); 56module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO);
55MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption."); 57MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
56 58
57/*
58 * Register access.
59 * BBP and RF register require indirect register access,
60 * and use the CSR registers PHY_CSR3 and PHY_CSR4 to achieve this.
61 * These indirect registers work with busy bits,
62 * and we will try maximal REGISTER_BUSY_COUNT times to access
63 * the register while taking a REGISTER_BUSY_DELAY us delay
64 * between each attampt. When the busy bit is still set at that time,
65 * the access attempt is considered to have failed,
66 * and we will print an error.
67 */
68#define WAIT_FOR_BBP(__dev, __reg) \
69 rt2x00pci_regbusy_read((__dev), BBP_CSR_CFG, BBP_CSR_CFG_BUSY, (__reg))
70#define WAIT_FOR_RFCSR(__dev, __reg) \
71 rt2x00pci_regbusy_read((__dev), RF_CSR_CFG, RF_CSR_CFG_BUSY, (__reg))
72#define WAIT_FOR_RF(__dev, __reg) \
73 rt2x00pci_regbusy_read((__dev), RF_CSR_CFG0, RF_CSR_CFG0_BUSY, (__reg))
74#define WAIT_FOR_MCU(__dev, __reg) \
75 rt2x00pci_regbusy_read((__dev), H2M_MAILBOX_CSR, \
76 H2M_MAILBOX_CSR_OWNER, (__reg))
77
78static void rt2800pci_bbp_write(struct rt2x00_dev *rt2x00dev,
79 const unsigned int word, const u8 value)
80{
81 u32 reg;
82
83 mutex_lock(&rt2x00dev->csr_mutex);
84
85 /*
86 * Wait until the BBP becomes available, afterwards we
87 * can safely write the new data into the register.
88 */
89 if (WAIT_FOR_BBP(rt2x00dev, &reg)) {
90 reg = 0;
91 rt2x00_set_field32(&reg, BBP_CSR_CFG_VALUE, value);
92 rt2x00_set_field32(&reg, BBP_CSR_CFG_REGNUM, word);
93 rt2x00_set_field32(&reg, BBP_CSR_CFG_BUSY, 1);
94 rt2x00_set_field32(&reg, BBP_CSR_CFG_READ_CONTROL, 0);
95 rt2x00_set_field32(&reg, BBP_CSR_CFG_BBP_RW_MODE, 1);
96
97 rt2x00pci_register_write(rt2x00dev, BBP_CSR_CFG, reg);
98 }
99
100 mutex_unlock(&rt2x00dev->csr_mutex);
101}
102
103static void rt2800pci_bbp_read(struct rt2x00_dev *rt2x00dev,
104 const unsigned int word, u8 *value)
105{
106 u32 reg;
107
108 mutex_lock(&rt2x00dev->csr_mutex);
109
110 /*
111 * Wait until the BBP becomes available, afterwards we
112 * can safely write the read request into the register.
113 * After the data has been written, we wait until hardware
114 * returns the correct value, if at any time the register
115 * doesn't become available in time, reg will be 0xffffffff
116 * which means we return 0xff to the caller.
117 */
118 if (WAIT_FOR_BBP(rt2x00dev, &reg)) {
119 reg = 0;
120 rt2x00_set_field32(&reg, BBP_CSR_CFG_REGNUM, word);
121 rt2x00_set_field32(&reg, BBP_CSR_CFG_BUSY, 1);
122 rt2x00_set_field32(&reg, BBP_CSR_CFG_READ_CONTROL, 1);
123 rt2x00_set_field32(&reg, BBP_CSR_CFG_BBP_RW_MODE, 1);
124
125 rt2x00pci_register_write(rt2x00dev, BBP_CSR_CFG, reg);
126
127 WAIT_FOR_BBP(rt2x00dev, &reg);
128 }
129
130 *value = rt2x00_get_field32(reg, BBP_CSR_CFG_VALUE);
131
132 mutex_unlock(&rt2x00dev->csr_mutex);
133}
134
135static void rt2800pci_rfcsr_write(struct rt2x00_dev *rt2x00dev,
136 const unsigned int word, const u8 value)
137{
138 u32 reg;
139
140 mutex_lock(&rt2x00dev->csr_mutex);
141
142 /*
143 * Wait until the RFCSR becomes available, afterwards we
144 * can safely write the new data into the register.
145 */
146 if (WAIT_FOR_RFCSR(rt2x00dev, &reg)) {
147 reg = 0;
148 rt2x00_set_field32(&reg, RF_CSR_CFG_DATA, value);
149 rt2x00_set_field32(&reg, RF_CSR_CFG_REGNUM, word);
150 rt2x00_set_field32(&reg, RF_CSR_CFG_WRITE, 1);
151 rt2x00_set_field32(&reg, RF_CSR_CFG_BUSY, 1);
152
153 rt2x00pci_register_write(rt2x00dev, RF_CSR_CFG, reg);
154 }
155
156 mutex_unlock(&rt2x00dev->csr_mutex);
157}
158
159static void rt2800pci_rfcsr_read(struct rt2x00_dev *rt2x00dev,
160 const unsigned int word, u8 *value)
161{
162 u32 reg;
163
164 mutex_lock(&rt2x00dev->csr_mutex);
165
166 /*
167 * Wait until the RFCSR becomes available, afterwards we
168 * can safely write the read request into the register.
169 * After the data has been written, we wait until hardware
170 * returns the correct value, if at any time the register
171 * doesn't become available in time, reg will be 0xffffffff
172 * which means we return 0xff to the caller.
173 */
174 if (WAIT_FOR_RFCSR(rt2x00dev, &reg)) {
175 reg = 0;
176 rt2x00_set_field32(&reg, RF_CSR_CFG_REGNUM, word);
177 rt2x00_set_field32(&reg, RF_CSR_CFG_WRITE, 0);
178 rt2x00_set_field32(&reg, RF_CSR_CFG_BUSY, 1);
179
180 rt2x00pci_register_write(rt2x00dev, RF_CSR_CFG, reg);
181
182 WAIT_FOR_RFCSR(rt2x00dev, &reg);
183 }
184
185 *value = rt2x00_get_field32(reg, RF_CSR_CFG_DATA);
186
187 mutex_unlock(&rt2x00dev->csr_mutex);
188}
189
190static void rt2800pci_rf_write(struct rt2x00_dev *rt2x00dev,
191 const unsigned int word, const u32 value)
192{
193 u32 reg;
194
195 mutex_lock(&rt2x00dev->csr_mutex);
196
197 /*
198 * Wait until the RF becomes available, afterwards we
199 * can safely write the new data into the register.
200 */
201 if (WAIT_FOR_RF(rt2x00dev, &reg)) {
202 reg = 0;
203 rt2x00_set_field32(&reg, RF_CSR_CFG0_REG_VALUE_BW, value);
204 rt2x00_set_field32(&reg, RF_CSR_CFG0_STANDBYMODE, 0);
205 rt2x00_set_field32(&reg, RF_CSR_CFG0_SEL, 0);
206 rt2x00_set_field32(&reg, RF_CSR_CFG0_BUSY, 1);
207
208 rt2x00pci_register_write(rt2x00dev, RF_CSR_CFG0, reg);
209 rt2x00_rf_write(rt2x00dev, word, value);
210 }
211
212 mutex_unlock(&rt2x00dev->csr_mutex);
213}
214
215static void rt2800pci_mcu_request(struct rt2x00_dev *rt2x00dev,
216 const u8 command, const u8 token,
217 const u8 arg0, const u8 arg1)
218{
219 u32 reg;
220
221 /*
222 * RT2880 and RT3052 don't support MCU requests.
223 */
224 if (rt2x00_rt(&rt2x00dev->chip, RT2880) ||
225 rt2x00_rt(&rt2x00dev->chip, RT3052))
226 return;
227
228 mutex_lock(&rt2x00dev->csr_mutex);
229
230 /*
231 * Wait until the MCU becomes available, afterwards we
232 * can safely write the new data into the register.
233 */
234 if (WAIT_FOR_MCU(rt2x00dev, &reg)) {
235 rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_OWNER, 1);
236 rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_CMD_TOKEN, token);
237 rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_ARG0, arg0);
238 rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_ARG1, arg1);
239 rt2x00pci_register_write(rt2x00dev, H2M_MAILBOX_CSR, reg);
240
241 reg = 0;
242 rt2x00_set_field32(&reg, HOST_CMD_CSR_HOST_COMMAND, command);
243 rt2x00pci_register_write(rt2x00dev, HOST_CMD_CSR, reg);
244 }
245
246 mutex_unlock(&rt2x00dev->csr_mutex);
247}
248
249static void rt2800pci_mcu_status(struct rt2x00_dev *rt2x00dev, const u8 token) 59static void rt2800pci_mcu_status(struct rt2x00_dev *rt2x00dev, const u8 token)
250{ 60{
251 unsigned int i; 61 unsigned int i;
252 u32 reg; 62 u32 reg;
253 63
254 for (i = 0; i < 200; i++) { 64 for (i = 0; i < 200; i++) {
255 rt2x00pci_register_read(rt2x00dev, H2M_MAILBOX_CID, &reg); 65 rt2800_register_read(rt2x00dev, H2M_MAILBOX_CID, &reg);
256 66
257 if ((rt2x00_get_field32(reg, H2M_MAILBOX_CID_CMD0) == token) || 67 if ((rt2x00_get_field32(reg, H2M_MAILBOX_CID_CMD0) == token) ||
258 (rt2x00_get_field32(reg, H2M_MAILBOX_CID_CMD1) == token) || 68 (rt2x00_get_field32(reg, H2M_MAILBOX_CID_CMD1) == token) ||
@@ -266,8 +76,8 @@ static void rt2800pci_mcu_status(struct rt2x00_dev *rt2x00dev, const u8 token)
266 if (i == 200) 76 if (i == 200)
267 ERROR(rt2x00dev, "MCU request failed, no response from hardware\n"); 77 ERROR(rt2x00dev, "MCU request failed, no response from hardware\n");
268 78
269 rt2x00pci_register_write(rt2x00dev, H2M_MAILBOX_STATUS, ~0); 79 rt2800_register_write(rt2x00dev, H2M_MAILBOX_STATUS, ~0);
270 rt2x00pci_register_write(rt2x00dev, H2M_MAILBOX_CID, ~0); 80 rt2800_register_write(rt2x00dev, H2M_MAILBOX_CID, ~0);
271} 81}
272 82
273#ifdef CONFIG_RT2800PCI_WISOC 83#ifdef CONFIG_RT2800PCI_WISOC
@@ -289,7 +99,7 @@ static void rt2800pci_eepromregister_read(struct eeprom_93cx6 *eeprom)
289 struct rt2x00_dev *rt2x00dev = eeprom->data; 99 struct rt2x00_dev *rt2x00dev = eeprom->data;
290 u32 reg; 100 u32 reg;
291 101
292 rt2x00pci_register_read(rt2x00dev, E2PROM_CSR, &reg); 102 rt2800_register_read(rt2x00dev, E2PROM_CSR, &reg);
293 103
294 eeprom->reg_data_in = !!rt2x00_get_field32(reg, E2PROM_CSR_DATA_IN); 104 eeprom->reg_data_in = !!rt2x00_get_field32(reg, E2PROM_CSR_DATA_IN);
295 eeprom->reg_data_out = !!rt2x00_get_field32(reg, E2PROM_CSR_DATA_OUT); 105 eeprom->reg_data_out = !!rt2x00_get_field32(reg, E2PROM_CSR_DATA_OUT);
@@ -311,7 +121,7 @@ static void rt2800pci_eepromregister_write(struct eeprom_93cx6 *eeprom)
311 rt2x00_set_field32(&reg, E2PROM_CSR_CHIP_SELECT, 121 rt2x00_set_field32(&reg, E2PROM_CSR_CHIP_SELECT,
312 !!eeprom->reg_chip_select); 122 !!eeprom->reg_chip_select);
313 123
314 rt2x00pci_register_write(rt2x00dev, E2PROM_CSR, reg); 124 rt2800_register_write(rt2x00dev, E2PROM_CSR, reg);
315} 125}
316 126
317static void rt2800pci_read_eeprom_pci(struct rt2x00_dev *rt2x00dev) 127static void rt2800pci_read_eeprom_pci(struct rt2x00_dev *rt2x00dev)
@@ -319,7 +129,7 @@ static void rt2800pci_read_eeprom_pci(struct rt2x00_dev *rt2x00dev)
319 struct eeprom_93cx6 eeprom; 129 struct eeprom_93cx6 eeprom;
320 u32 reg; 130 u32 reg;
321 131
322 rt2x00pci_register_read(rt2x00dev, E2PROM_CSR, &reg); 132 rt2800_register_read(rt2x00dev, E2PROM_CSR, &reg);
323 133
324 eeprom.data = rt2x00dev; 134 eeprom.data = rt2x00dev;
325 eeprom.register_read = rt2800pci_eepromregister_read; 135 eeprom.register_read = rt2800pci_eepromregister_read;
@@ -340,23 +150,23 @@ static void rt2800pci_efuse_read(struct rt2x00_dev *rt2x00dev,
340{ 150{
341 u32 reg; 151 u32 reg;
342 152
343 rt2x00pci_register_read(rt2x00dev, EFUSE_CTRL, &reg); 153 rt2800_register_read(rt2x00dev, EFUSE_CTRL, &reg);
344 rt2x00_set_field32(&reg, EFUSE_CTRL_ADDRESS_IN, i); 154 rt2x00_set_field32(&reg, EFUSE_CTRL_ADDRESS_IN, i);
345 rt2x00_set_field32(&reg, EFUSE_CTRL_MODE, 0); 155 rt2x00_set_field32(&reg, EFUSE_CTRL_MODE, 0);
346 rt2x00_set_field32(&reg, EFUSE_CTRL_KICK, 1); 156 rt2x00_set_field32(&reg, EFUSE_CTRL_KICK, 1);
347 rt2x00pci_register_write(rt2x00dev, EFUSE_CTRL, reg); 157 rt2800_register_write(rt2x00dev, EFUSE_CTRL, reg);
348 158
349 /* Wait until the EEPROM has been loaded */ 159 /* Wait until the EEPROM has been loaded */
350 rt2x00pci_regbusy_read(rt2x00dev, EFUSE_CTRL, EFUSE_CTRL_KICK, &reg); 160 rt2800_regbusy_read(rt2x00dev, EFUSE_CTRL, EFUSE_CTRL_KICK, &reg);
351 161
352 /* Apparently the data is read from end to start */ 162 /* Apparently the data is read from end to start */
353 rt2x00pci_register_read(rt2x00dev, EFUSE_DATA3, 163 rt2800_register_read(rt2x00dev, EFUSE_DATA3,
354 (u32 *)&rt2x00dev->eeprom[i]); 164 (u32 *)&rt2x00dev->eeprom[i]);
355 rt2x00pci_register_read(rt2x00dev, EFUSE_DATA2, 165 rt2800_register_read(rt2x00dev, EFUSE_DATA2,
356 (u32 *)&rt2x00dev->eeprom[i + 2]); 166 (u32 *)&rt2x00dev->eeprom[i + 2]);
357 rt2x00pci_register_read(rt2x00dev, EFUSE_DATA1, 167 rt2800_register_read(rt2x00dev, EFUSE_DATA1,
358 (u32 *)&rt2x00dev->eeprom[i + 4]); 168 (u32 *)&rt2x00dev->eeprom[i + 4]);
359 rt2x00pci_register_read(rt2x00dev, EFUSE_DATA0, 169 rt2800_register_read(rt2x00dev, EFUSE_DATA0,
360 (u32 *)&rt2x00dev->eeprom[i + 6]); 170 (u32 *)&rt2x00dev->eeprom[i + 6]);
361} 171}
362 172
@@ -377,829 +187,6 @@ static inline void rt2800pci_read_eeprom_efuse(struct rt2x00_dev *rt2x00dev)
377} 187}
378#endif /* CONFIG_RT2800PCI_PCI */ 188#endif /* CONFIG_RT2800PCI_PCI */
379 189
380#ifdef CONFIG_RT2X00_LIB_DEBUGFS
381static const struct rt2x00debug rt2800pci_rt2x00debug = {
382 .owner = THIS_MODULE,
383 .csr = {
384 .read = rt2x00pci_register_read,
385 .write = rt2x00pci_register_write,
386 .flags = RT2X00DEBUGFS_OFFSET,
387 .word_base = CSR_REG_BASE,
388 .word_size = sizeof(u32),
389 .word_count = CSR_REG_SIZE / sizeof(u32),
390 },
391 .eeprom = {
392 .read = rt2x00_eeprom_read,
393 .write = rt2x00_eeprom_write,
394 .word_base = EEPROM_BASE,
395 .word_size = sizeof(u16),
396 .word_count = EEPROM_SIZE / sizeof(u16),
397 },
398 .bbp = {
399 .read = rt2800pci_bbp_read,
400 .write = rt2800pci_bbp_write,
401 .word_base = BBP_BASE,
402 .word_size = sizeof(u8),
403 .word_count = BBP_SIZE / sizeof(u8),
404 },
405 .rf = {
406 .read = rt2x00_rf_read,
407 .write = rt2800pci_rf_write,
408 .word_base = RF_BASE,
409 .word_size = sizeof(u32),
410 .word_count = RF_SIZE / sizeof(u32),
411 },
412};
413#endif /* CONFIG_RT2X00_LIB_DEBUGFS */
414
415static int rt2800pci_rfkill_poll(struct rt2x00_dev *rt2x00dev)
416{
417 u32 reg;
418
419 rt2x00pci_register_read(rt2x00dev, GPIO_CTRL_CFG, &reg);
420 return rt2x00_get_field32(reg, GPIO_CTRL_CFG_BIT2);
421}
422
423#ifdef CONFIG_RT2X00_LIB_LEDS
424static void rt2800pci_brightness_set(struct led_classdev *led_cdev,
425 enum led_brightness brightness)
426{
427 struct rt2x00_led *led =
428 container_of(led_cdev, struct rt2x00_led, led_dev);
429 unsigned int enabled = brightness != LED_OFF;
430 unsigned int bg_mode =
431 (enabled && led->rt2x00dev->curr_band == IEEE80211_BAND_2GHZ);
432 unsigned int polarity =
433 rt2x00_get_field16(led->rt2x00dev->led_mcu_reg,
434 EEPROM_FREQ_LED_POLARITY);
435 unsigned int ledmode =
436 rt2x00_get_field16(led->rt2x00dev->led_mcu_reg,
437 EEPROM_FREQ_LED_MODE);
438
439 if (led->type == LED_TYPE_RADIO) {
440 rt2800pci_mcu_request(led->rt2x00dev, MCU_LED, 0xff, ledmode,
441 enabled ? 0x20 : 0);
442 } else if (led->type == LED_TYPE_ASSOC) {
443 rt2800pci_mcu_request(led->rt2x00dev, MCU_LED, 0xff, ledmode,
444 enabled ? (bg_mode ? 0x60 : 0xa0) : 0x20);
445 } else if (led->type == LED_TYPE_QUALITY) {
446 /*
447 * The brightness is divided into 6 levels (0 - 5),
448 * The specs tell us the following levels:
449 * 0, 1 ,3, 7, 15, 31
450 * to determine the level in a simple way we can simply
451 * work with bitshifting:
452 * (1 << level) - 1
453 */
454 rt2800pci_mcu_request(led->rt2x00dev, MCU_LED_STRENGTH, 0xff,
455 (1 << brightness / (LED_FULL / 6)) - 1,
456 polarity);
457 }
458}
459
460static int rt2800pci_blink_set(struct led_classdev *led_cdev,
461 unsigned long *delay_on,
462 unsigned long *delay_off)
463{
464 struct rt2x00_led *led =
465 container_of(led_cdev, struct rt2x00_led, led_dev);
466 u32 reg;
467
468 rt2x00pci_register_read(led->rt2x00dev, LED_CFG, &reg);
469 rt2x00_set_field32(&reg, LED_CFG_ON_PERIOD, *delay_on);
470 rt2x00_set_field32(&reg, LED_CFG_OFF_PERIOD, *delay_off);
471 rt2x00_set_field32(&reg, LED_CFG_SLOW_BLINK_PERIOD, 3);
472 rt2x00_set_field32(&reg, LED_CFG_R_LED_MODE, 3);
473 rt2x00_set_field32(&reg, LED_CFG_G_LED_MODE, 12);
474 rt2x00_set_field32(&reg, LED_CFG_Y_LED_MODE, 3);
475 rt2x00_set_field32(&reg, LED_CFG_LED_POLAR, 1);
476 rt2x00pci_register_write(led->rt2x00dev, LED_CFG, reg);
477
478 return 0;
479}
480
481static void rt2800pci_init_led(struct rt2x00_dev *rt2x00dev,
482 struct rt2x00_led *led,
483 enum led_type type)
484{
485 led->rt2x00dev = rt2x00dev;
486 led->type = type;
487 led->led_dev.brightness_set = rt2800pci_brightness_set;
488 led->led_dev.blink_set = rt2800pci_blink_set;
489 led->flags = LED_INITIALIZED;
490}
491#endif /* CONFIG_RT2X00_LIB_LEDS */
492
493/*
494 * Configuration handlers.
495 */
496static void rt2800pci_config_wcid_attr(struct rt2x00_dev *rt2x00dev,
497 struct rt2x00lib_crypto *crypto,
498 struct ieee80211_key_conf *key)
499{
500 struct mac_wcid_entry wcid_entry;
501 struct mac_iveiv_entry iveiv_entry;
502 u32 offset;
503 u32 reg;
504
505 offset = MAC_WCID_ATTR_ENTRY(key->hw_key_idx);
506
507 rt2x00pci_register_read(rt2x00dev, offset, &reg);
508 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_KEYTAB,
509 !!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE));
510 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_CIPHER,
511 (crypto->cmd == SET_KEY) * crypto->cipher);
512 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_BSS_IDX,
513 (crypto->cmd == SET_KEY) * crypto->bssidx);
514 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_RX_WIUDF, crypto->cipher);
515 rt2x00pci_register_write(rt2x00dev, offset, reg);
516
517 offset = MAC_IVEIV_ENTRY(key->hw_key_idx);
518
519 memset(&iveiv_entry, 0, sizeof(iveiv_entry));
520 if ((crypto->cipher == CIPHER_TKIP) ||
521 (crypto->cipher == CIPHER_TKIP_NO_MIC) ||
522 (crypto->cipher == CIPHER_AES))
523 iveiv_entry.iv[3] |= 0x20;
524 iveiv_entry.iv[3] |= key->keyidx << 6;
525 rt2x00pci_register_multiwrite(rt2x00dev, offset,
526 &iveiv_entry, sizeof(iveiv_entry));
527
528 offset = MAC_WCID_ENTRY(key->hw_key_idx);
529
530 memset(&wcid_entry, 0, sizeof(wcid_entry));
531 if (crypto->cmd == SET_KEY)
532 memcpy(&wcid_entry, crypto->address, ETH_ALEN);
533 rt2x00pci_register_multiwrite(rt2x00dev, offset,
534 &wcid_entry, sizeof(wcid_entry));
535}
536
537static int rt2800pci_config_shared_key(struct rt2x00_dev *rt2x00dev,
538 struct rt2x00lib_crypto *crypto,
539 struct ieee80211_key_conf *key)
540{
541 struct hw_key_entry key_entry;
542 struct rt2x00_field32 field;
543 u32 offset;
544 u32 reg;
545
546 if (crypto->cmd == SET_KEY) {
547 key->hw_key_idx = (4 * crypto->bssidx) + key->keyidx;
548
549 memcpy(key_entry.key, crypto->key,
550 sizeof(key_entry.key));
551 memcpy(key_entry.tx_mic, crypto->tx_mic,
552 sizeof(key_entry.tx_mic));
553 memcpy(key_entry.rx_mic, crypto->rx_mic,
554 sizeof(key_entry.rx_mic));
555
556 offset = SHARED_KEY_ENTRY(key->hw_key_idx);
557 rt2x00pci_register_multiwrite(rt2x00dev, offset,
558 &key_entry, sizeof(key_entry));
559 }
560
561 /*
562 * The cipher types are stored over multiple registers
563 * starting with SHARED_KEY_MODE_BASE each word will have
564 * 32 bits and contains the cipher types for 2 bssidx each.
565 * Using the correct defines correctly will cause overhead,
566 * so just calculate the correct offset.
567 */
568 field.bit_offset = 4 * (key->hw_key_idx % 8);
569 field.bit_mask = 0x7 << field.bit_offset;
570
571 offset = SHARED_KEY_MODE_ENTRY(key->hw_key_idx / 8);
572
573 rt2x00pci_register_read(rt2x00dev, offset, &reg);
574 rt2x00_set_field32(&reg, field,
575 (crypto->cmd == SET_KEY) * crypto->cipher);
576 rt2x00pci_register_write(rt2x00dev, offset, reg);
577
578 /*
579 * Update WCID information
580 */
581 rt2800pci_config_wcid_attr(rt2x00dev, crypto, key);
582
583 return 0;
584}
585
586static int rt2800pci_config_pairwise_key(struct rt2x00_dev *rt2x00dev,
587 struct rt2x00lib_crypto *crypto,
588 struct ieee80211_key_conf *key)
589{
590 struct hw_key_entry key_entry;
591 u32 offset;
592
593 if (crypto->cmd == SET_KEY) {
594 /*
595 * 1 pairwise key is possible per AID, this means that the AID
596 * equals our hw_key_idx. Make sure the WCID starts _after_ the
597 * last possible shared key entry.
598 */
599 if (crypto->aid > (256 - 32))
600 return -ENOSPC;
601
602 key->hw_key_idx = 32 + crypto->aid;
603
604
605 memcpy(key_entry.key, crypto->key,
606 sizeof(key_entry.key));
607 memcpy(key_entry.tx_mic, crypto->tx_mic,
608 sizeof(key_entry.tx_mic));
609 memcpy(key_entry.rx_mic, crypto->rx_mic,
610 sizeof(key_entry.rx_mic));
611
612 offset = PAIRWISE_KEY_ENTRY(key->hw_key_idx);
613 rt2x00pci_register_multiwrite(rt2x00dev, offset,
614 &key_entry, sizeof(key_entry));
615 }
616
617 /*
618 * Update WCID information
619 */
620 rt2800pci_config_wcid_attr(rt2x00dev, crypto, key);
621
622 return 0;
623}
624
625static void rt2800pci_config_filter(struct rt2x00_dev *rt2x00dev,
626 const unsigned int filter_flags)
627{
628 u32 reg;
629
630 /*
631 * Start configuration steps.
632 * Note that the version error will always be dropped
633 * and broadcast frames will always be accepted since
634 * there is no filter for it at this time.
635 */
636 rt2x00pci_register_read(rt2x00dev, RX_FILTER_CFG, &reg);
637 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CRC_ERROR,
638 !(filter_flags & FIF_FCSFAIL));
639 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_PHY_ERROR,
640 !(filter_flags & FIF_PLCPFAIL));
641 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_NOT_TO_ME,
642 !(filter_flags & FIF_PROMISC_IN_BSS));
643 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_NOT_MY_BSSD, 0);
644 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_VER_ERROR, 1);
645 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_MULTICAST,
646 !(filter_flags & FIF_ALLMULTI));
647 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_BROADCAST, 0);
648 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_DUPLICATE, 1);
649 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CF_END_ACK,
650 !(filter_flags & FIF_CONTROL));
651 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CF_END,
652 !(filter_flags & FIF_CONTROL));
653 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_ACK,
654 !(filter_flags & FIF_CONTROL));
655 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CTS,
656 !(filter_flags & FIF_CONTROL));
657 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_RTS,
658 !(filter_flags & FIF_CONTROL));
659 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_PSPOLL,
660 !(filter_flags & FIF_PSPOLL));
661 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_BA, 1);
662 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_BAR, 0);
663 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CNTL,
664 !(filter_flags & FIF_CONTROL));
665 rt2x00pci_register_write(rt2x00dev, RX_FILTER_CFG, reg);
666}
667
668static void rt2800pci_config_intf(struct rt2x00_dev *rt2x00dev,
669 struct rt2x00_intf *intf,
670 struct rt2x00intf_conf *conf,
671 const unsigned int flags)
672{
673 unsigned int beacon_base;
674 u32 reg;
675
676 if (flags & CONFIG_UPDATE_TYPE) {
677 /*
678 * Clear current synchronisation setup.
679 * For the Beacon base registers we only need to clear
680 * the first byte since that byte contains the VALID and OWNER
681 * bits which (when set to 0) will invalidate the entire beacon.
682 */
683 beacon_base = HW_BEACON_OFFSET(intf->beacon->entry_idx);
684 rt2x00pci_register_write(rt2x00dev, beacon_base, 0);
685
686 /*
687 * Enable synchronisation.
688 */
689 rt2x00pci_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
690 rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 1);
691 rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_SYNC, conf->sync);
692 rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 1);
693 rt2x00pci_register_write(rt2x00dev, BCN_TIME_CFG, reg);
694 }
695
696 if (flags & CONFIG_UPDATE_MAC) {
697 reg = le32_to_cpu(conf->mac[1]);
698 rt2x00_set_field32(&reg, MAC_ADDR_DW1_UNICAST_TO_ME_MASK, 0xff);
699 conf->mac[1] = cpu_to_le32(reg);
700
701 rt2x00pci_register_multiwrite(rt2x00dev, MAC_ADDR_DW0,
702 conf->mac, sizeof(conf->mac));
703 }
704
705 if (flags & CONFIG_UPDATE_BSSID) {
706 reg = le32_to_cpu(conf->bssid[1]);
707 rt2x00_set_field32(&reg, MAC_BSSID_DW1_BSS_ID_MASK, 0);
708 rt2x00_set_field32(&reg, MAC_BSSID_DW1_BSS_BCN_NUM, 0);
709 conf->bssid[1] = cpu_to_le32(reg);
710
711 rt2x00pci_register_multiwrite(rt2x00dev, MAC_BSSID_DW0,
712 conf->bssid, sizeof(conf->bssid));
713 }
714}
715
716static void rt2800pci_config_erp(struct rt2x00_dev *rt2x00dev,
717 struct rt2x00lib_erp *erp)
718{
719 u32 reg;
720
721 rt2x00pci_register_read(rt2x00dev, TX_TIMEOUT_CFG, &reg);
722 rt2x00_set_field32(&reg, TX_TIMEOUT_CFG_RX_ACK_TIMEOUT, 0x20);
723 rt2x00pci_register_write(rt2x00dev, TX_TIMEOUT_CFG, reg);
724
725 rt2x00pci_register_read(rt2x00dev, AUTO_RSP_CFG, &reg);
726 rt2x00_set_field32(&reg, AUTO_RSP_CFG_BAC_ACK_POLICY,
727 !!erp->short_preamble);
728 rt2x00_set_field32(&reg, AUTO_RSP_CFG_AR_PREAMBLE,
729 !!erp->short_preamble);
730 rt2x00pci_register_write(rt2x00dev, AUTO_RSP_CFG, reg);
731
732 rt2x00pci_register_read(rt2x00dev, OFDM_PROT_CFG, &reg);
733 rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_CTRL,
734 erp->cts_protection ? 2 : 0);
735 rt2x00pci_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
736
737 rt2x00pci_register_write(rt2x00dev, LEGACY_BASIC_RATE,
738 erp->basic_rates);
739 rt2x00pci_register_write(rt2x00dev, HT_BASIC_RATE, 0x00008003);
740
741 rt2x00pci_register_read(rt2x00dev, BKOFF_SLOT_CFG, &reg);
742 rt2x00_set_field32(&reg, BKOFF_SLOT_CFG_SLOT_TIME, erp->slot_time);
743 rt2x00_set_field32(&reg, BKOFF_SLOT_CFG_CC_DELAY_TIME, 2);
744 rt2x00pci_register_write(rt2x00dev, BKOFF_SLOT_CFG, reg);
745
746 rt2x00pci_register_read(rt2x00dev, XIFS_TIME_CFG, &reg);
747 rt2x00_set_field32(&reg, XIFS_TIME_CFG_CCKM_SIFS_TIME, erp->sifs);
748 rt2x00_set_field32(&reg, XIFS_TIME_CFG_OFDM_SIFS_TIME, erp->sifs);
749 rt2x00_set_field32(&reg, XIFS_TIME_CFG_OFDM_XIFS_TIME, 4);
750 rt2x00_set_field32(&reg, XIFS_TIME_CFG_EIFS, erp->eifs);
751 rt2x00_set_field32(&reg, XIFS_TIME_CFG_BB_RXEND_ENABLE, 1);
752 rt2x00pci_register_write(rt2x00dev, XIFS_TIME_CFG, reg);
753
754 rt2x00pci_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
755 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_INTERVAL,
756 erp->beacon_int * 16);
757 rt2x00pci_register_write(rt2x00dev, BCN_TIME_CFG, reg);
758}
759
760static void rt2800pci_config_ant(struct rt2x00_dev *rt2x00dev,
761 struct antenna_setup *ant)
762{
763 u8 r1;
764 u8 r3;
765
766 rt2800pci_bbp_read(rt2x00dev, 1, &r1);
767 rt2800pci_bbp_read(rt2x00dev, 3, &r3);
768
769 /*
770 * Configure the TX antenna.
771 */
772 switch ((int)ant->tx) {
773 case 1:
774 rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 0);
775 rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 0);
776 break;
777 case 2:
778 rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 2);
779 break;
780 case 3:
781 /* Do nothing */
782 break;
783 }
784
785 /*
786 * Configure the RX antenna.
787 */
788 switch ((int)ant->rx) {
789 case 1:
790 rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 0);
791 break;
792 case 2:
793 rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 1);
794 break;
795 case 3:
796 rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 2);
797 break;
798 }
799
800 rt2800pci_bbp_write(rt2x00dev, 3, r3);
801 rt2800pci_bbp_write(rt2x00dev, 1, r1);
802}
803
804static void rt2800pci_config_lna_gain(struct rt2x00_dev *rt2x00dev,
805 struct rt2x00lib_conf *libconf)
806{
807 u16 eeprom;
808 short lna_gain;
809
810 if (libconf->rf.channel <= 14) {
811 rt2x00_eeprom_read(rt2x00dev, EEPROM_LNA, &eeprom);
812 lna_gain = rt2x00_get_field16(eeprom, EEPROM_LNA_BG);
813 } else if (libconf->rf.channel <= 64) {
814 rt2x00_eeprom_read(rt2x00dev, EEPROM_LNA, &eeprom);
815 lna_gain = rt2x00_get_field16(eeprom, EEPROM_LNA_A0);
816 } else if (libconf->rf.channel <= 128) {
817 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &eeprom);
818 lna_gain = rt2x00_get_field16(eeprom, EEPROM_RSSI_BG2_LNA_A1);
819 } else {
820 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &eeprom);
821 lna_gain = rt2x00_get_field16(eeprom, EEPROM_RSSI_A2_LNA_A2);
822 }
823
824 rt2x00dev->lna_gain = lna_gain;
825}
826
827static void rt2800pci_config_channel_rt2x(struct rt2x00_dev *rt2x00dev,
828 struct ieee80211_conf *conf,
829 struct rf_channel *rf,
830 struct channel_info *info)
831{
832 rt2x00_set_field32(&rf->rf4, RF4_FREQ_OFFSET, rt2x00dev->freq_offset);
833
834 if (rt2x00dev->default_ant.tx == 1)
835 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_TX1, 1);
836
837 if (rt2x00dev->default_ant.rx == 1) {
838 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX1, 1);
839 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1);
840 } else if (rt2x00dev->default_ant.rx == 2)
841 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1);
842
843 if (rf->channel > 14) {
844 /*
845 * When TX power is below 0, we should increase it by 7 to
846 * make it a positive value (Minumum value is -7).
847 * However this means that values between 0 and 7 have
848 * double meaning, and we should set a 7DBm boost flag.
849 */
850 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_A_7DBM_BOOST,
851 (info->tx_power1 >= 0));
852
853 if (info->tx_power1 < 0)
854 info->tx_power1 += 7;
855
856 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_A,
857 TXPOWER_A_TO_DEV(info->tx_power1));
858
859 rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_A_7DBM_BOOST,
860 (info->tx_power2 >= 0));
861
862 if (info->tx_power2 < 0)
863 info->tx_power2 += 7;
864
865 rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_A,
866 TXPOWER_A_TO_DEV(info->tx_power2));
867 } else {
868 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_G,
869 TXPOWER_G_TO_DEV(info->tx_power1));
870 rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_G,
871 TXPOWER_G_TO_DEV(info->tx_power2));
872 }
873
874 rt2x00_set_field32(&rf->rf4, RF4_HT40, conf_is_ht40(conf));
875
876 rt2800pci_rf_write(rt2x00dev, 1, rf->rf1);
877 rt2800pci_rf_write(rt2x00dev, 2, rf->rf2);
878 rt2800pci_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
879 rt2800pci_rf_write(rt2x00dev, 4, rf->rf4);
880
881 udelay(200);
882
883 rt2800pci_rf_write(rt2x00dev, 1, rf->rf1);
884 rt2800pci_rf_write(rt2x00dev, 2, rf->rf2);
885 rt2800pci_rf_write(rt2x00dev, 3, rf->rf3 | 0x00000004);
886 rt2800pci_rf_write(rt2x00dev, 4, rf->rf4);
887
888 udelay(200);
889
890 rt2800pci_rf_write(rt2x00dev, 1, rf->rf1);
891 rt2800pci_rf_write(rt2x00dev, 2, rf->rf2);
892 rt2800pci_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
893 rt2800pci_rf_write(rt2x00dev, 4, rf->rf4);
894}
895
896static void rt2800pci_config_channel_rt3x(struct rt2x00_dev *rt2x00dev,
897 struct ieee80211_conf *conf,
898 struct rf_channel *rf,
899 struct channel_info *info)
900{
901 u8 rfcsr;
902
903 rt2800pci_rfcsr_write(rt2x00dev, 2, rf->rf1);
904 rt2800pci_rfcsr_write(rt2x00dev, 2, rf->rf3);
905
906 rt2800pci_rfcsr_read(rt2x00dev, 6, &rfcsr);
907 rt2x00_set_field8(&rfcsr, RFCSR6_R, rf->rf2);
908 rt2800pci_rfcsr_write(rt2x00dev, 6, rfcsr);
909
910 rt2800pci_rfcsr_read(rt2x00dev, 12, &rfcsr);
911 rt2x00_set_field8(&rfcsr, RFCSR12_TX_POWER,
912 TXPOWER_G_TO_DEV(info->tx_power1));
913 rt2800pci_rfcsr_write(rt2x00dev, 12, rfcsr);
914
915 rt2800pci_rfcsr_read(rt2x00dev, 23, &rfcsr);
916 rt2x00_set_field8(&rfcsr, RFCSR23_FREQ_OFFSET, rt2x00dev->freq_offset);
917 rt2800pci_rfcsr_write(rt2x00dev, 23, rfcsr);
918
919 rt2800pci_rfcsr_write(rt2x00dev, 24,
920 rt2x00dev->calibration[conf_is_ht40(conf)]);
921
922 rt2800pci_rfcsr_read(rt2x00dev, 23, &rfcsr);
923 rt2x00_set_field8(&rfcsr, RFCSR7_RF_TUNING, 1);
924 rt2800pci_rfcsr_write(rt2x00dev, 23, rfcsr);
925}
926
927static void rt2800pci_config_channel(struct rt2x00_dev *rt2x00dev,
928 struct ieee80211_conf *conf,
929 struct rf_channel *rf,
930 struct channel_info *info)
931{
932 u32 reg;
933 unsigned int tx_pin;
934 u8 bbp;
935
936 if (rt2x00_rev(&rt2x00dev->chip) != RT3070_VERSION)
937 rt2800pci_config_channel_rt2x(rt2x00dev, conf, rf, info);
938 else
939 rt2800pci_config_channel_rt3x(rt2x00dev, conf, rf, info);
940
941 /*
942 * Change BBP settings
943 */
944 rt2800pci_bbp_write(rt2x00dev, 62, 0x37 - rt2x00dev->lna_gain);
945 rt2800pci_bbp_write(rt2x00dev, 63, 0x37 - rt2x00dev->lna_gain);
946 rt2800pci_bbp_write(rt2x00dev, 64, 0x37 - rt2x00dev->lna_gain);
947 rt2800pci_bbp_write(rt2x00dev, 86, 0);
948
949 if (rf->channel <= 14) {
950 if (test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags)) {
951 rt2800pci_bbp_write(rt2x00dev, 82, 0x62);
952 rt2800pci_bbp_write(rt2x00dev, 75, 0x46);
953 } else {
954 rt2800pci_bbp_write(rt2x00dev, 82, 0x84);
955 rt2800pci_bbp_write(rt2x00dev, 75, 0x50);
956 }
957 } else {
958 rt2800pci_bbp_write(rt2x00dev, 82, 0xf2);
959
960 if (test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags))
961 rt2800pci_bbp_write(rt2x00dev, 75, 0x46);
962 else
963 rt2800pci_bbp_write(rt2x00dev, 75, 0x50);
964 }
965
966 rt2x00pci_register_read(rt2x00dev, TX_BAND_CFG, &reg);
967 rt2x00_set_field32(&reg, TX_BAND_CFG_HT40_PLUS, conf_is_ht40_plus(conf));
968 rt2x00_set_field32(&reg, TX_BAND_CFG_A, rf->channel > 14);
969 rt2x00_set_field32(&reg, TX_BAND_CFG_BG, rf->channel <= 14);
970 rt2x00pci_register_write(rt2x00dev, TX_BAND_CFG, reg);
971
972 tx_pin = 0;
973
974 /* Turn on unused PA or LNA when not using 1T or 1R */
975 if (rt2x00dev->default_ant.tx != 1) {
976 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A1_EN, 1);
977 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G1_EN, 1);
978 }
979
980 /* Turn on unused PA or LNA when not using 1T or 1R */
981 if (rt2x00dev->default_ant.rx != 1) {
982 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A1_EN, 1);
983 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G1_EN, 1);
984 }
985
986 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A0_EN, 1);
987 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G0_EN, 1);
988 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_RFTR_EN, 1);
989 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_TRSW_EN, 1);
990 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G0_EN, rf->channel <= 14);
991 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A0_EN, rf->channel > 14);
992
993 rt2x00pci_register_write(rt2x00dev, TX_PIN_CFG, tx_pin);
994
995 rt2800pci_bbp_read(rt2x00dev, 4, &bbp);
996 rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 2 * conf_is_ht40(conf));
997 rt2800pci_bbp_write(rt2x00dev, 4, bbp);
998
999 rt2800pci_bbp_read(rt2x00dev, 3, &bbp);
1000 rt2x00_set_field8(&bbp, BBP3_HT40_PLUS, conf_is_ht40_plus(conf));
1001 rt2800pci_bbp_write(rt2x00dev, 3, bbp);
1002
1003 if (rt2x00_rev(&rt2x00dev->chip) == RT2860C_VERSION) {
1004 if (conf_is_ht40(conf)) {
1005 rt2800pci_bbp_write(rt2x00dev, 69, 0x1a);
1006 rt2800pci_bbp_write(rt2x00dev, 70, 0x0a);
1007 rt2800pci_bbp_write(rt2x00dev, 73, 0x16);
1008 } else {
1009 rt2800pci_bbp_write(rt2x00dev, 69, 0x16);
1010 rt2800pci_bbp_write(rt2x00dev, 70, 0x08);
1011 rt2800pci_bbp_write(rt2x00dev, 73, 0x11);
1012 }
1013 }
1014
1015 msleep(1);
1016}
1017
1018static void rt2800pci_config_txpower(struct rt2x00_dev *rt2x00dev,
1019 const int txpower)
1020{
1021 u32 reg;
1022 u32 value = TXPOWER_G_TO_DEV(txpower);
1023 u8 r1;
1024
1025 rt2800pci_bbp_read(rt2x00dev, 1, &r1);
1026 rt2x00_set_field8(&reg, BBP1_TX_POWER, 0);
1027 rt2800pci_bbp_write(rt2x00dev, 1, r1);
1028
1029 rt2x00pci_register_read(rt2x00dev, TX_PWR_CFG_0, &reg);
1030 rt2x00_set_field32(&reg, TX_PWR_CFG_0_1MBS, value);
1031 rt2x00_set_field32(&reg, TX_PWR_CFG_0_2MBS, value);
1032 rt2x00_set_field32(&reg, TX_PWR_CFG_0_55MBS, value);
1033 rt2x00_set_field32(&reg, TX_PWR_CFG_0_11MBS, value);
1034 rt2x00_set_field32(&reg, TX_PWR_CFG_0_6MBS, value);
1035 rt2x00_set_field32(&reg, TX_PWR_CFG_0_9MBS, value);
1036 rt2x00_set_field32(&reg, TX_PWR_CFG_0_12MBS, value);
1037 rt2x00_set_field32(&reg, TX_PWR_CFG_0_18MBS, value);
1038 rt2x00pci_register_write(rt2x00dev, TX_PWR_CFG_0, reg);
1039
1040 rt2x00pci_register_read(rt2x00dev, TX_PWR_CFG_1, &reg);
1041 rt2x00_set_field32(&reg, TX_PWR_CFG_1_24MBS, value);
1042 rt2x00_set_field32(&reg, TX_PWR_CFG_1_36MBS, value);
1043 rt2x00_set_field32(&reg, TX_PWR_CFG_1_48MBS, value);
1044 rt2x00_set_field32(&reg, TX_PWR_CFG_1_54MBS, value);
1045 rt2x00_set_field32(&reg, TX_PWR_CFG_1_MCS0, value);
1046 rt2x00_set_field32(&reg, TX_PWR_CFG_1_MCS1, value);
1047 rt2x00_set_field32(&reg, TX_PWR_CFG_1_MCS2, value);
1048 rt2x00_set_field32(&reg, TX_PWR_CFG_1_MCS3, value);
1049 rt2x00pci_register_write(rt2x00dev, TX_PWR_CFG_1, reg);
1050
1051 rt2x00pci_register_read(rt2x00dev, TX_PWR_CFG_2, &reg);
1052 rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS4, value);
1053 rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS5, value);
1054 rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS6, value);
1055 rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS7, value);
1056 rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS8, value);
1057 rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS9, value);
1058 rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS10, value);
1059 rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS11, value);
1060 rt2x00pci_register_write(rt2x00dev, TX_PWR_CFG_2, reg);
1061
1062 rt2x00pci_register_read(rt2x00dev, TX_PWR_CFG_3, &reg);
1063 rt2x00_set_field32(&reg, TX_PWR_CFG_3_MCS12, value);
1064 rt2x00_set_field32(&reg, TX_PWR_CFG_3_MCS13, value);
1065 rt2x00_set_field32(&reg, TX_PWR_CFG_3_MCS14, value);
1066 rt2x00_set_field32(&reg, TX_PWR_CFG_3_MCS15, value);
1067 rt2x00_set_field32(&reg, TX_PWR_CFG_3_UKNOWN1, value);
1068 rt2x00_set_field32(&reg, TX_PWR_CFG_3_UKNOWN2, value);
1069 rt2x00_set_field32(&reg, TX_PWR_CFG_3_UKNOWN3, value);
1070 rt2x00_set_field32(&reg, TX_PWR_CFG_3_UKNOWN4, value);
1071 rt2x00pci_register_write(rt2x00dev, TX_PWR_CFG_3, reg);
1072
1073 rt2x00pci_register_read(rt2x00dev, TX_PWR_CFG_4, &reg);
1074 rt2x00_set_field32(&reg, TX_PWR_CFG_4_UKNOWN5, value);
1075 rt2x00_set_field32(&reg, TX_PWR_CFG_4_UKNOWN6, value);
1076 rt2x00_set_field32(&reg, TX_PWR_CFG_4_UKNOWN7, value);
1077 rt2x00_set_field32(&reg, TX_PWR_CFG_4_UKNOWN8, value);
1078 rt2x00pci_register_write(rt2x00dev, TX_PWR_CFG_4, reg);
1079}
1080
1081static void rt2800pci_config_retry_limit(struct rt2x00_dev *rt2x00dev,
1082 struct rt2x00lib_conf *libconf)
1083{
1084 u32 reg;
1085
1086 rt2x00pci_register_read(rt2x00dev, TX_RTY_CFG, &reg);
1087 rt2x00_set_field32(&reg, TX_RTY_CFG_SHORT_RTY_LIMIT,
1088 libconf->conf->short_frame_max_tx_count);
1089 rt2x00_set_field32(&reg, TX_RTY_CFG_LONG_RTY_LIMIT,
1090 libconf->conf->long_frame_max_tx_count);
1091 rt2x00_set_field32(&reg, TX_RTY_CFG_LONG_RTY_THRE, 2000);
1092 rt2x00_set_field32(&reg, TX_RTY_CFG_NON_AGG_RTY_MODE, 0);
1093 rt2x00_set_field32(&reg, TX_RTY_CFG_AGG_RTY_MODE, 0);
1094 rt2x00_set_field32(&reg, TX_RTY_CFG_TX_AUTO_FB_ENABLE, 1);
1095 rt2x00pci_register_write(rt2x00dev, TX_RTY_CFG, reg);
1096}
1097
1098static void rt2800pci_config_ps(struct rt2x00_dev *rt2x00dev,
1099 struct rt2x00lib_conf *libconf)
1100{
1101 enum dev_state state =
1102 (libconf->conf->flags & IEEE80211_CONF_PS) ?
1103 STATE_SLEEP : STATE_AWAKE;
1104 u32 reg;
1105
1106 if (state == STATE_SLEEP) {
1107 rt2x00pci_register_write(rt2x00dev, AUTOWAKEUP_CFG, 0);
1108
1109 rt2x00pci_register_read(rt2x00dev, AUTOWAKEUP_CFG, &reg);
1110 rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTO_LEAD_TIME, 5);
1111 rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_TBCN_BEFORE_WAKE,
1112 libconf->conf->listen_interval - 1);
1113 rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTOWAKE, 1);
1114 rt2x00pci_register_write(rt2x00dev, AUTOWAKEUP_CFG, reg);
1115
1116 rt2x00dev->ops->lib->set_device_state(rt2x00dev, state);
1117 } else {
1118 rt2x00dev->ops->lib->set_device_state(rt2x00dev, state);
1119
1120 rt2x00pci_register_read(rt2x00dev, AUTOWAKEUP_CFG, &reg);
1121 rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTO_LEAD_TIME, 0);
1122 rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_TBCN_BEFORE_WAKE, 0);
1123 rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTOWAKE, 0);
1124 rt2x00pci_register_write(rt2x00dev, AUTOWAKEUP_CFG, reg);
1125 }
1126}
1127
1128static void rt2800pci_config(struct rt2x00_dev *rt2x00dev,
1129 struct rt2x00lib_conf *libconf,
1130 const unsigned int flags)
1131{
1132 /* Always recalculate LNA gain before changing configuration */
1133 rt2800pci_config_lna_gain(rt2x00dev, libconf);
1134
1135 if (flags & IEEE80211_CONF_CHANGE_CHANNEL)
1136 rt2800pci_config_channel(rt2x00dev, libconf->conf,
1137 &libconf->rf, &libconf->channel);
1138 if (flags & IEEE80211_CONF_CHANGE_POWER)
1139 rt2800pci_config_txpower(rt2x00dev, libconf->conf->power_level);
1140 if (flags & IEEE80211_CONF_CHANGE_RETRY_LIMITS)
1141 rt2800pci_config_retry_limit(rt2x00dev, libconf);
1142 if (flags & IEEE80211_CONF_CHANGE_PS)
1143 rt2800pci_config_ps(rt2x00dev, libconf);
1144}
1145
1146/*
1147 * Link tuning
1148 */
1149static void rt2800pci_link_stats(struct rt2x00_dev *rt2x00dev,
1150 struct link_qual *qual)
1151{
1152 u32 reg;
1153
1154 /*
1155 * Update FCS error count from register.
1156 */
1157 rt2x00pci_register_read(rt2x00dev, RX_STA_CNT0, &reg);
1158 qual->rx_failed = rt2x00_get_field32(reg, RX_STA_CNT0_CRC_ERR);
1159}
1160
1161static u8 rt2800pci_get_default_vgc(struct rt2x00_dev *rt2x00dev)
1162{
1163 if (rt2x00dev->curr_band == IEEE80211_BAND_2GHZ)
1164 return 0x2e + rt2x00dev->lna_gain;
1165
1166 if (!test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags))
1167 return 0x32 + (rt2x00dev->lna_gain * 5) / 3;
1168 else
1169 return 0x3a + (rt2x00dev->lna_gain * 5) / 3;
1170}
1171
1172static inline void rt2800pci_set_vgc(struct rt2x00_dev *rt2x00dev,
1173 struct link_qual *qual, u8 vgc_level)
1174{
1175 if (qual->vgc_level != vgc_level) {
1176 rt2800pci_bbp_write(rt2x00dev, 66, vgc_level);
1177 qual->vgc_level = vgc_level;
1178 qual->vgc_level_reg = vgc_level;
1179 }
1180}
1181
1182static void rt2800pci_reset_tuner(struct rt2x00_dev *rt2x00dev,
1183 struct link_qual *qual)
1184{
1185 rt2800pci_set_vgc(rt2x00dev, qual,
1186 rt2800pci_get_default_vgc(rt2x00dev));
1187}
1188
1189static void rt2800pci_link_tuner(struct rt2x00_dev *rt2x00dev,
1190 struct link_qual *qual, const u32 count)
1191{
1192 if (rt2x00_rev(&rt2x00dev->chip) == RT2860C_VERSION)
1193 return;
1194
1195 /*
1196 * When RSSI is better then -80 increase VGC level with 0x10
1197 */
1198 rt2800pci_set_vgc(rt2x00dev, qual,
1199 rt2800pci_get_default_vgc(rt2x00dev) +
1200 ((qual->rssi > -80) * 0x10));
1201}
1202
1203/* 190/*
1204 * Firmware functions 191 * Firmware functions
1205 */ 192 */
@@ -1257,7 +244,7 @@ static int rt2800pci_load_firmware(struct rt2x00_dev *rt2x00dev,
1257 * Wait for stable hardware. 244 * Wait for stable hardware.
1258 */ 245 */
1259 for (i = 0; i < REGISTER_BUSY_COUNT; i++) { 246 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
1260 rt2x00pci_register_read(rt2x00dev, MAC_CSR0, &reg); 247 rt2800_register_read(rt2x00dev, MAC_CSR0, &reg);
1261 if (reg && reg != ~0) 248 if (reg && reg != ~0)
1262 break; 249 break;
1263 msleep(1); 250 msleep(1);
@@ -1268,42 +255,42 @@ static int rt2800pci_load_firmware(struct rt2x00_dev *rt2x00dev,
1268 return -EBUSY; 255 return -EBUSY;
1269 } 256 }
1270 257
1271 rt2x00pci_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000002); 258 rt2800_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000002);
1272 rt2x00pci_register_write(rt2x00dev, AUTOWAKEUP_CFG, 0x00000000); 259 rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, 0x00000000);
1273 260
1274 /* 261 /*
1275 * Disable DMA, will be reenabled later when enabling 262 * Disable DMA, will be reenabled later when enabling
1276 * the radio. 263 * the radio.
1277 */ 264 */
1278 rt2x00pci_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg); 265 rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
1279 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0); 266 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
1280 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_DMA_BUSY, 0); 267 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_DMA_BUSY, 0);
1281 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0); 268 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
1282 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_RX_DMA_BUSY, 0); 269 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_RX_DMA_BUSY, 0);
1283 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1); 270 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1);
1284 rt2x00pci_register_write(rt2x00dev, WPDMA_GLO_CFG, reg); 271 rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
1285 272
1286 /* 273 /*
1287 * enable Host program ram write selection 274 * enable Host program ram write selection
1288 */ 275 */
1289 reg = 0; 276 reg = 0;
1290 rt2x00_set_field32(&reg, PBF_SYS_CTRL_HOST_RAM_WRITE, 1); 277 rt2x00_set_field32(&reg, PBF_SYS_CTRL_HOST_RAM_WRITE, 1);
1291 rt2x00pci_register_write(rt2x00dev, PBF_SYS_CTRL, reg); 278 rt2800_register_write(rt2x00dev, PBF_SYS_CTRL, reg);
1292 279
1293 /* 280 /*
1294 * Write firmware to device. 281 * Write firmware to device.
1295 */ 282 */
1296 rt2x00pci_register_multiwrite(rt2x00dev, FIRMWARE_IMAGE_BASE, 283 rt2800_register_multiwrite(rt2x00dev, FIRMWARE_IMAGE_BASE,
1297 data, len); 284 data, len);
1298 285
1299 rt2x00pci_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00000); 286 rt2800_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00000);
1300 rt2x00pci_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00001); 287 rt2800_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00001);
1301 288
1302 /* 289 /*
1303 * Wait for device to stabilize. 290 * Wait for device to stabilize.
1304 */ 291 */
1305 for (i = 0; i < REGISTER_BUSY_COUNT; i++) { 292 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
1306 rt2x00pci_register_read(rt2x00dev, PBF_SYS_CTRL, &reg); 293 rt2800_register_read(rt2x00dev, PBF_SYS_CTRL, &reg);
1307 if (rt2x00_get_field32(reg, PBF_SYS_CTRL_READY)) 294 if (rt2x00_get_field32(reg, PBF_SYS_CTRL_READY))
1308 break; 295 break;
1309 msleep(1); 296 msleep(1);
@@ -1322,8 +309,8 @@ static int rt2800pci_load_firmware(struct rt2x00_dev *rt2x00dev,
1322 /* 309 /*
1323 * Initialize BBP R/W access agent 310 * Initialize BBP R/W access agent
1324 */ 311 */
1325 rt2x00pci_register_write(rt2x00dev, H2M_BBP_AGENT, 0); 312 rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
1326 rt2x00pci_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0); 313 rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
1327 314
1328 return 0; 315 return 0;
1329} 316}
@@ -1373,7 +360,7 @@ static int rt2800pci_init_queues(struct rt2x00_dev *rt2x00dev)
1373 struct queue_entry_priv_pci *entry_priv; 360 struct queue_entry_priv_pci *entry_priv;
1374 u32 reg; 361 u32 reg;
1375 362
1376 rt2x00pci_register_read(rt2x00dev, WPDMA_RST_IDX, &reg); 363 rt2800_register_read(rt2x00dev, WPDMA_RST_IDX, &reg);
1377 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX0, 1); 364 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX0, 1);
1378 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX1, 1); 365 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX1, 1);
1379 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX2, 1); 366 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX2, 1);
@@ -1381,539 +368,54 @@ static int rt2800pci_init_queues(struct rt2x00_dev *rt2x00dev)
1381 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX4, 1); 368 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX4, 1);
1382 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX5, 1); 369 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX5, 1);
1383 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DRX_IDX0, 1); 370 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DRX_IDX0, 1);
1384 rt2x00pci_register_write(rt2x00dev, WPDMA_RST_IDX, reg); 371 rt2800_register_write(rt2x00dev, WPDMA_RST_IDX, reg);
1385 372
1386 rt2x00pci_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00000e1f); 373 rt2800_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00000e1f);
1387 rt2x00pci_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00000e00); 374 rt2800_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00000e00);
1388 375
1389 /* 376 /*
1390 * Initialize registers. 377 * Initialize registers.
1391 */ 378 */
1392 entry_priv = rt2x00dev->tx[0].entries[0].priv_data; 379 entry_priv = rt2x00dev->tx[0].entries[0].priv_data;
1393 rt2x00pci_register_write(rt2x00dev, TX_BASE_PTR0, entry_priv->desc_dma); 380 rt2800_register_write(rt2x00dev, TX_BASE_PTR0, entry_priv->desc_dma);
1394 rt2x00pci_register_write(rt2x00dev, TX_MAX_CNT0, rt2x00dev->tx[0].limit); 381 rt2800_register_write(rt2x00dev, TX_MAX_CNT0, rt2x00dev->tx[0].limit);
1395 rt2x00pci_register_write(rt2x00dev, TX_CTX_IDX0, 0); 382 rt2800_register_write(rt2x00dev, TX_CTX_IDX0, 0);
1396 rt2x00pci_register_write(rt2x00dev, TX_DTX_IDX0, 0); 383 rt2800_register_write(rt2x00dev, TX_DTX_IDX0, 0);
1397 384
1398 entry_priv = rt2x00dev->tx[1].entries[0].priv_data; 385 entry_priv = rt2x00dev->tx[1].entries[0].priv_data;
1399 rt2x00pci_register_write(rt2x00dev, TX_BASE_PTR1, entry_priv->desc_dma); 386 rt2800_register_write(rt2x00dev, TX_BASE_PTR1, entry_priv->desc_dma);
1400 rt2x00pci_register_write(rt2x00dev, TX_MAX_CNT1, rt2x00dev->tx[1].limit); 387 rt2800_register_write(rt2x00dev, TX_MAX_CNT1, rt2x00dev->tx[1].limit);
1401 rt2x00pci_register_write(rt2x00dev, TX_CTX_IDX1, 0); 388 rt2800_register_write(rt2x00dev, TX_CTX_IDX1, 0);
1402 rt2x00pci_register_write(rt2x00dev, TX_DTX_IDX1, 0); 389 rt2800_register_write(rt2x00dev, TX_DTX_IDX1, 0);
1403 390
1404 entry_priv = rt2x00dev->tx[2].entries[0].priv_data; 391 entry_priv = rt2x00dev->tx[2].entries[0].priv_data;
1405 rt2x00pci_register_write(rt2x00dev, TX_BASE_PTR2, entry_priv->desc_dma); 392 rt2800_register_write(rt2x00dev, TX_BASE_PTR2, entry_priv->desc_dma);
1406 rt2x00pci_register_write(rt2x00dev, TX_MAX_CNT2, rt2x00dev->tx[2].limit); 393 rt2800_register_write(rt2x00dev, TX_MAX_CNT2, rt2x00dev->tx[2].limit);
1407 rt2x00pci_register_write(rt2x00dev, TX_CTX_IDX2, 0); 394 rt2800_register_write(rt2x00dev, TX_CTX_IDX2, 0);
1408 rt2x00pci_register_write(rt2x00dev, TX_DTX_IDX2, 0); 395 rt2800_register_write(rt2x00dev, TX_DTX_IDX2, 0);
1409 396
1410 entry_priv = rt2x00dev->tx[3].entries[0].priv_data; 397 entry_priv = rt2x00dev->tx[3].entries[0].priv_data;
1411 rt2x00pci_register_write(rt2x00dev, TX_BASE_PTR3, entry_priv->desc_dma); 398 rt2800_register_write(rt2x00dev, TX_BASE_PTR3, entry_priv->desc_dma);
1412 rt2x00pci_register_write(rt2x00dev, TX_MAX_CNT3, rt2x00dev->tx[3].limit); 399 rt2800_register_write(rt2x00dev, TX_MAX_CNT3, rt2x00dev->tx[3].limit);
1413 rt2x00pci_register_write(rt2x00dev, TX_CTX_IDX3, 0); 400 rt2800_register_write(rt2x00dev, TX_CTX_IDX3, 0);
1414 rt2x00pci_register_write(rt2x00dev, TX_DTX_IDX3, 0); 401 rt2800_register_write(rt2x00dev, TX_DTX_IDX3, 0);
1415 402
1416 entry_priv = rt2x00dev->rx->entries[0].priv_data; 403 entry_priv = rt2x00dev->rx->entries[0].priv_data;
1417 rt2x00pci_register_write(rt2x00dev, RX_BASE_PTR, entry_priv->desc_dma); 404 rt2800_register_write(rt2x00dev, RX_BASE_PTR, entry_priv->desc_dma);
1418 rt2x00pci_register_write(rt2x00dev, RX_MAX_CNT, rt2x00dev->rx[0].limit); 405 rt2800_register_write(rt2x00dev, RX_MAX_CNT, rt2x00dev->rx[0].limit);
1419 rt2x00pci_register_write(rt2x00dev, RX_CRX_IDX, rt2x00dev->rx[0].limit - 1); 406 rt2800_register_write(rt2x00dev, RX_CRX_IDX, rt2x00dev->rx[0].limit - 1);
1420 rt2x00pci_register_write(rt2x00dev, RX_DRX_IDX, 0); 407 rt2800_register_write(rt2x00dev, RX_DRX_IDX, 0);
1421 408
1422 /* 409 /*
1423 * Enable global DMA configuration 410 * Enable global DMA configuration
1424 */ 411 */
1425 rt2x00pci_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg); 412 rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
1426 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0); 413 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
1427 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0); 414 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
1428 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1); 415 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1);
1429 rt2x00pci_register_write(rt2x00dev, WPDMA_GLO_CFG, reg); 416 rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
1430
1431 rt2x00pci_register_write(rt2x00dev, DELAY_INT_CFG, 0);
1432
1433 return 0;
1434}
1435
1436static int rt2800pci_init_registers(struct rt2x00_dev *rt2x00dev)
1437{
1438 u32 reg;
1439 unsigned int i;
1440
1441 rt2x00pci_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000003);
1442
1443 rt2x00pci_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
1444 rt2x00_set_field32(&reg, MAC_SYS_CTRL_RESET_CSR, 1);
1445 rt2x00_set_field32(&reg, MAC_SYS_CTRL_RESET_BBP, 1);
1446 rt2x00pci_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
1447
1448 rt2x00pci_register_write(rt2x00dev, MAC_SYS_CTRL, 0x00000000);
1449
1450 rt2x00pci_register_read(rt2x00dev, BCN_OFFSET0, &reg);
1451 rt2x00_set_field32(&reg, BCN_OFFSET0_BCN0, 0xe0); /* 0x3800 */
1452 rt2x00_set_field32(&reg, BCN_OFFSET0_BCN1, 0xe8); /* 0x3a00 */
1453 rt2x00_set_field32(&reg, BCN_OFFSET0_BCN2, 0xf0); /* 0x3c00 */
1454 rt2x00_set_field32(&reg, BCN_OFFSET0_BCN3, 0xf8); /* 0x3e00 */
1455 rt2x00pci_register_write(rt2x00dev, BCN_OFFSET0, reg);
1456
1457 rt2x00pci_register_read(rt2x00dev, BCN_OFFSET1, &reg);
1458 rt2x00_set_field32(&reg, BCN_OFFSET1_BCN4, 0xc8); /* 0x3200 */
1459 rt2x00_set_field32(&reg, BCN_OFFSET1_BCN5, 0xd0); /* 0x3400 */
1460 rt2x00_set_field32(&reg, BCN_OFFSET1_BCN6, 0x77); /* 0x1dc0 */
1461 rt2x00_set_field32(&reg, BCN_OFFSET1_BCN7, 0x6f); /* 0x1bc0 */
1462 rt2x00pci_register_write(rt2x00dev, BCN_OFFSET1, reg);
1463
1464 rt2x00pci_register_write(rt2x00dev, LEGACY_BASIC_RATE, 0x0000013f);
1465 rt2x00pci_register_write(rt2x00dev, HT_BASIC_RATE, 0x00008003);
1466
1467 rt2x00pci_register_write(rt2x00dev, MAC_SYS_CTRL, 0x00000000);
1468
1469 rt2x00pci_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
1470 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_INTERVAL, 0);
1471 rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 0);
1472 rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_SYNC, 0);
1473 rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 0);
1474 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 0);
1475 rt2x00_set_field32(&reg, BCN_TIME_CFG_TX_TIME_COMPENSATE, 0);
1476 rt2x00pci_register_write(rt2x00dev, BCN_TIME_CFG, reg);
1477
1478 rt2x00pci_register_write(rt2x00dev, TX_SW_CFG0, 0x00000000);
1479 rt2x00pci_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606);
1480
1481 rt2x00pci_register_read(rt2x00dev, TX_LINK_CFG, &reg);
1482 rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_MFB_LIFETIME, 32);
1483 rt2x00_set_field32(&reg, TX_LINK_CFG_MFB_ENABLE, 0);
1484 rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_UMFS_ENABLE, 0);
1485 rt2x00_set_field32(&reg, TX_LINK_CFG_TX_MRQ_EN, 0);
1486 rt2x00_set_field32(&reg, TX_LINK_CFG_TX_RDG_EN, 0);
1487 rt2x00_set_field32(&reg, TX_LINK_CFG_TX_CF_ACK_EN, 1);
1488 rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_MFB, 0);
1489 rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_MFS, 0);
1490 rt2x00pci_register_write(rt2x00dev, TX_LINK_CFG, reg);
1491
1492 rt2x00pci_register_read(rt2x00dev, TX_TIMEOUT_CFG, &reg);
1493 rt2x00_set_field32(&reg, TX_TIMEOUT_CFG_MPDU_LIFETIME, 9);
1494 rt2x00_set_field32(&reg, TX_TIMEOUT_CFG_TX_OP_TIMEOUT, 10);
1495 rt2x00pci_register_write(rt2x00dev, TX_TIMEOUT_CFG, reg);
1496
1497 rt2x00pci_register_read(rt2x00dev, MAX_LEN_CFG, &reg);
1498 rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_MPDU, AGGREGATION_SIZE);
1499 if (rt2x00_rev(&rt2x00dev->chip) >= RT2880E_VERSION &&
1500 rt2x00_rev(&rt2x00dev->chip) < RT3070_VERSION)
1501 rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_PSDU, 2);
1502 else
1503 rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_PSDU, 1);
1504 rt2x00_set_field32(&reg, MAX_LEN_CFG_MIN_PSDU, 0);
1505 rt2x00_set_field32(&reg, MAX_LEN_CFG_MIN_MPDU, 0);
1506 rt2x00pci_register_write(rt2x00dev, MAX_LEN_CFG, reg);
1507
1508 rt2x00pci_register_write(rt2x00dev, PBF_MAX_PCNT, 0x1f3fbf9f);
1509
1510 rt2x00pci_register_read(rt2x00dev, AUTO_RSP_CFG, &reg);
1511 rt2x00_set_field32(&reg, AUTO_RSP_CFG_AUTORESPONDER, 1);
1512 rt2x00_set_field32(&reg, AUTO_RSP_CFG_CTS_40_MMODE, 0);
1513 rt2x00_set_field32(&reg, AUTO_RSP_CFG_CTS_40_MREF, 0);
1514 rt2x00_set_field32(&reg, AUTO_RSP_CFG_DUAL_CTS_EN, 0);
1515 rt2x00_set_field32(&reg, AUTO_RSP_CFG_ACK_CTS_PSM_BIT, 0);
1516 rt2x00pci_register_write(rt2x00dev, AUTO_RSP_CFG, reg);
1517
1518 rt2x00pci_register_read(rt2x00dev, CCK_PROT_CFG, &reg);
1519 rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_RATE, 8);
1520 rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_CTRL, 0);
1521 rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_NAV, 1);
1522 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_CCK, 1);
1523 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
1524 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_MM20, 1);
1525 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_MM40, 1);
1526 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_GF20, 1);
1527 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_GF40, 1);
1528 rt2x00pci_register_write(rt2x00dev, CCK_PROT_CFG, reg);
1529
1530 rt2x00pci_register_read(rt2x00dev, OFDM_PROT_CFG, &reg);
1531 rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_RATE, 8);
1532 rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_CTRL, 0);
1533 rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_NAV, 1);
1534 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_CCK, 1);
1535 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
1536 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_MM20, 1);
1537 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_MM40, 1);
1538 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_GF20, 1);
1539 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_GF40, 1);
1540 rt2x00pci_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
1541
1542 rt2x00pci_register_read(rt2x00dev, MM20_PROT_CFG, &reg);
1543 rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_RATE, 0x4004);
1544 rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_CTRL, 0);
1545 rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_NAV, 1);
1546 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_CCK, 1);
1547 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
1548 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_MM20, 1);
1549 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_MM40, 0);
1550 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_GF20, 1);
1551 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_GF40, 0);
1552 rt2x00pci_register_write(rt2x00dev, MM20_PROT_CFG, reg);
1553
1554 rt2x00pci_register_read(rt2x00dev, MM40_PROT_CFG, &reg);
1555 rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_RATE, 0x4084);
1556 rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_CTRL, 0);
1557 rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_NAV, 1);
1558 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_CCK, 1);
1559 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
1560 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_MM20, 1);
1561 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_MM40, 1);
1562 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_GF20, 1);
1563 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_GF40, 1);
1564 rt2x00pci_register_write(rt2x00dev, MM40_PROT_CFG, reg);
1565
1566 rt2x00pci_register_read(rt2x00dev, GF20_PROT_CFG, &reg);
1567 rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_RATE, 0x4004);
1568 rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_CTRL, 0);
1569 rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_NAV, 1);
1570 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_CCK, 1);
1571 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
1572 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_MM20, 1);
1573 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_MM40, 0);
1574 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_GF20, 1);
1575 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_GF40, 0);
1576 rt2x00pci_register_write(rt2x00dev, GF20_PROT_CFG, reg);
1577
1578 rt2x00pci_register_read(rt2x00dev, GF40_PROT_CFG, &reg);
1579 rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_RATE, 0x4084);
1580 rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_CTRL, 0);
1581 rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_NAV, 1);
1582 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_CCK, 1);
1583 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
1584 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_MM20, 1);
1585 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_MM40, 1);
1586 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_GF20, 1);
1587 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_GF40, 1);
1588 rt2x00pci_register_write(rt2x00dev, GF40_PROT_CFG, reg);
1589
1590 rt2x00pci_register_write(rt2x00dev, TXOP_CTRL_CFG, 0x0000583f);
1591 rt2x00pci_register_write(rt2x00dev, TXOP_HLDR_ET, 0x00000002);
1592
1593 rt2x00pci_register_read(rt2x00dev, TX_RTS_CFG, &reg);
1594 rt2x00_set_field32(&reg, TX_RTS_CFG_AUTO_RTS_RETRY_LIMIT, 32);
1595 rt2x00_set_field32(&reg, TX_RTS_CFG_RTS_THRES,
1596 IEEE80211_MAX_RTS_THRESHOLD);
1597 rt2x00_set_field32(&reg, TX_RTS_CFG_RTS_FBK_EN, 0);
1598 rt2x00pci_register_write(rt2x00dev, TX_RTS_CFG, reg);
1599
1600 rt2x00pci_register_write(rt2x00dev, EXP_ACK_TIME, 0x002400ca);
1601 rt2x00pci_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000003);
1602
1603 /*
1604 * ASIC will keep garbage value after boot, clear encryption keys.
1605 */
1606 for (i = 0; i < 4; i++)
1607 rt2x00pci_register_write(rt2x00dev,
1608 SHARED_KEY_MODE_ENTRY(i), 0);
1609
1610 for (i = 0; i < 256; i++) {
1611 u32 wcid[2] = { 0xffffffff, 0x00ffffff };
1612 rt2x00pci_register_multiwrite(rt2x00dev, MAC_WCID_ENTRY(i),
1613 wcid, sizeof(wcid));
1614
1615 rt2x00pci_register_write(rt2x00dev, MAC_WCID_ATTR_ENTRY(i), 1);
1616 rt2x00pci_register_write(rt2x00dev, MAC_IVEIV_ENTRY(i), 0);
1617 }
1618
1619 /*
1620 * Clear all beacons
1621 * For the Beacon base registers we only need to clear
1622 * the first byte since that byte contains the VALID and OWNER
1623 * bits which (when set to 0) will invalidate the entire beacon.
1624 */
1625 rt2x00pci_register_write(rt2x00dev, HW_BEACON_BASE0, 0);
1626 rt2x00pci_register_write(rt2x00dev, HW_BEACON_BASE1, 0);
1627 rt2x00pci_register_write(rt2x00dev, HW_BEACON_BASE2, 0);
1628 rt2x00pci_register_write(rt2x00dev, HW_BEACON_BASE3, 0);
1629 rt2x00pci_register_write(rt2x00dev, HW_BEACON_BASE4, 0);
1630 rt2x00pci_register_write(rt2x00dev, HW_BEACON_BASE5, 0);
1631 rt2x00pci_register_write(rt2x00dev, HW_BEACON_BASE6, 0);
1632 rt2x00pci_register_write(rt2x00dev, HW_BEACON_BASE7, 0);
1633
1634 rt2x00pci_register_read(rt2x00dev, HT_FBK_CFG0, &reg);
1635 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS0FBK, 0);
1636 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS1FBK, 0);
1637 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS2FBK, 1);
1638 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS3FBK, 2);
1639 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS4FBK, 3);
1640 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS5FBK, 4);
1641 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS6FBK, 5);
1642 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS7FBK, 6);
1643 rt2x00pci_register_write(rt2x00dev, HT_FBK_CFG0, reg);
1644
1645 rt2x00pci_register_read(rt2x00dev, HT_FBK_CFG1, &reg);
1646 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS8FBK, 8);
1647 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS9FBK, 8);
1648 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS10FBK, 9);
1649 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS11FBK, 10);
1650 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS12FBK, 11);
1651 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS13FBK, 12);
1652 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS14FBK, 13);
1653 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS15FBK, 14);
1654 rt2x00pci_register_write(rt2x00dev, HT_FBK_CFG1, reg);
1655
1656 rt2x00pci_register_read(rt2x00dev, LG_FBK_CFG0, &reg);
1657 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS0FBK, 8);
1658 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS1FBK, 8);
1659 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS2FBK, 9);
1660 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS3FBK, 10);
1661 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS4FBK, 11);
1662 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS5FBK, 12);
1663 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS6FBK, 13);
1664 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS7FBK, 14);
1665 rt2x00pci_register_write(rt2x00dev, LG_FBK_CFG0, reg);
1666
1667 rt2x00pci_register_read(rt2x00dev, LG_FBK_CFG1, &reg);
1668 rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS0FBK, 0);
1669 rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS1FBK, 0);
1670 rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS2FBK, 1);
1671 rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS3FBK, 2);
1672 rt2x00pci_register_write(rt2x00dev, LG_FBK_CFG1, reg);
1673
1674 /*
1675 * We must clear the error counters.
1676 * These registers are cleared on read,
1677 * so we may pass a useless variable to store the value.
1678 */
1679 rt2x00pci_register_read(rt2x00dev, RX_STA_CNT0, &reg);
1680 rt2x00pci_register_read(rt2x00dev, RX_STA_CNT1, &reg);
1681 rt2x00pci_register_read(rt2x00dev, RX_STA_CNT2, &reg);
1682 rt2x00pci_register_read(rt2x00dev, TX_STA_CNT0, &reg);
1683 rt2x00pci_register_read(rt2x00dev, TX_STA_CNT1, &reg);
1684 rt2x00pci_register_read(rt2x00dev, TX_STA_CNT2, &reg);
1685
1686 return 0;
1687}
1688
1689static int rt2800pci_wait_bbp_rf_ready(struct rt2x00_dev *rt2x00dev)
1690{
1691 unsigned int i;
1692 u32 reg;
1693
1694 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
1695 rt2x00pci_register_read(rt2x00dev, MAC_STATUS_CFG, &reg);
1696 if (!rt2x00_get_field32(reg, MAC_STATUS_CFG_BBP_RF_BUSY))
1697 return 0;
1698
1699 udelay(REGISTER_BUSY_DELAY);
1700 }
1701
1702 ERROR(rt2x00dev, "BBP/RF register access failed, aborting.\n");
1703 return -EACCES;
1704}
1705
1706static int rt2800pci_wait_bbp_ready(struct rt2x00_dev *rt2x00dev)
1707{
1708 unsigned int i;
1709 u8 value;
1710
1711 /*
1712 * BBP was enabled after firmware was loaded,
1713 * but we need to reactivate it now.
1714 */
1715 rt2x00pci_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
1716 rt2x00pci_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
1717 msleep(1);
1718
1719 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
1720 rt2800pci_bbp_read(rt2x00dev, 0, &value);
1721 if ((value != 0xff) && (value != 0x00))
1722 return 0;
1723 udelay(REGISTER_BUSY_DELAY);
1724 }
1725
1726 ERROR(rt2x00dev, "BBP register access failed, aborting.\n");
1727 return -EACCES;
1728}
1729
1730static int rt2800pci_init_bbp(struct rt2x00_dev *rt2x00dev)
1731{
1732 unsigned int i;
1733 u16 eeprom;
1734 u8 reg_id;
1735 u8 value;
1736
1737 if (unlikely(rt2800pci_wait_bbp_rf_ready(rt2x00dev) ||
1738 rt2800pci_wait_bbp_ready(rt2x00dev)))
1739 return -EACCES;
1740
1741 rt2800pci_bbp_write(rt2x00dev, 65, 0x2c);
1742 rt2800pci_bbp_write(rt2x00dev, 66, 0x38);
1743 rt2800pci_bbp_write(rt2x00dev, 69, 0x12);
1744 rt2800pci_bbp_write(rt2x00dev, 70, 0x0a);
1745 rt2800pci_bbp_write(rt2x00dev, 73, 0x10);
1746 rt2800pci_bbp_write(rt2x00dev, 81, 0x37);
1747 rt2800pci_bbp_write(rt2x00dev, 82, 0x62);
1748 rt2800pci_bbp_write(rt2x00dev, 83, 0x6a);
1749 rt2800pci_bbp_write(rt2x00dev, 84, 0x99);
1750 rt2800pci_bbp_write(rt2x00dev, 86, 0x00);
1751 rt2800pci_bbp_write(rt2x00dev, 91, 0x04);
1752 rt2800pci_bbp_write(rt2x00dev, 92, 0x00);
1753 rt2800pci_bbp_write(rt2x00dev, 103, 0x00);
1754 rt2800pci_bbp_write(rt2x00dev, 105, 0x05);
1755
1756 if (rt2x00_rev(&rt2x00dev->chip) == RT2860C_VERSION) {
1757 rt2800pci_bbp_write(rt2x00dev, 69, 0x16);
1758 rt2800pci_bbp_write(rt2x00dev, 73, 0x12);
1759 }
1760
1761 if (rt2x00_rev(&rt2x00dev->chip) > RT2860D_VERSION)
1762 rt2800pci_bbp_write(rt2x00dev, 84, 0x19);
1763
1764 if (rt2x00_rt(&rt2x00dev->chip, RT3052)) {
1765 rt2800pci_bbp_write(rt2x00dev, 31, 0x08);
1766 rt2800pci_bbp_write(rt2x00dev, 78, 0x0e);
1767 rt2800pci_bbp_write(rt2x00dev, 80, 0x08);
1768 }
1769
1770 for (i = 0; i < EEPROM_BBP_SIZE; i++) {
1771 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBP_START + i, &eeprom);
1772
1773 if (eeprom != 0xffff && eeprom != 0x0000) {
1774 reg_id = rt2x00_get_field16(eeprom, EEPROM_BBP_REG_ID);
1775 value = rt2x00_get_field16(eeprom, EEPROM_BBP_VALUE);
1776 rt2800pci_bbp_write(rt2x00dev, reg_id, value);
1777 }
1778 }
1779 417
1780 return 0; 418 rt2800_register_write(rt2x00dev, DELAY_INT_CFG, 0);
1781}
1782
1783static u8 rt2800pci_init_rx_filter(struct rt2x00_dev *rt2x00dev,
1784 bool bw40, u8 rfcsr24, u8 filter_target)
1785{
1786 unsigned int i;
1787 u8 bbp;
1788 u8 rfcsr;
1789 u8 passband;
1790 u8 stopband;
1791 u8 overtuned = 0;
1792
1793 rt2800pci_rfcsr_write(rt2x00dev, 24, rfcsr24);
1794
1795 rt2800pci_bbp_read(rt2x00dev, 4, &bbp);
1796 rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 2 * bw40);
1797 rt2800pci_bbp_write(rt2x00dev, 4, bbp);
1798
1799 rt2800pci_rfcsr_read(rt2x00dev, 22, &rfcsr);
1800 rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 1);
1801 rt2800pci_rfcsr_write(rt2x00dev, 22, rfcsr);
1802
1803 /*
1804 * Set power & frequency of passband test tone
1805 */
1806 rt2800pci_bbp_write(rt2x00dev, 24, 0);
1807
1808 for (i = 0; i < 100; i++) {
1809 rt2800pci_bbp_write(rt2x00dev, 25, 0x90);
1810 msleep(1);
1811
1812 rt2800pci_bbp_read(rt2x00dev, 55, &passband);
1813 if (passband)
1814 break;
1815 }
1816
1817 /*
1818 * Set power & frequency of stopband test tone
1819 */
1820 rt2800pci_bbp_write(rt2x00dev, 24, 0x06);
1821
1822 for (i = 0; i < 100; i++) {
1823 rt2800pci_bbp_write(rt2x00dev, 25, 0x90);
1824 msleep(1);
1825
1826 rt2800pci_bbp_read(rt2x00dev, 55, &stopband);
1827
1828 if ((passband - stopband) <= filter_target) {
1829 rfcsr24++;
1830 overtuned += ((passband - stopband) == filter_target);
1831 } else
1832 break;
1833
1834 rt2800pci_rfcsr_write(rt2x00dev, 24, rfcsr24);
1835 }
1836
1837 rfcsr24 -= !!overtuned;
1838
1839 rt2800pci_rfcsr_write(rt2x00dev, 24, rfcsr24);
1840 return rfcsr24;
1841}
1842
1843static int rt2800pci_init_rfcsr(struct rt2x00_dev *rt2x00dev)
1844{
1845 u8 rfcsr;
1846 u8 bbp;
1847
1848 if (!rt2x00_rf(&rt2x00dev->chip, RF3020) &&
1849 !rt2x00_rf(&rt2x00dev->chip, RF3021) &&
1850 !rt2x00_rf(&rt2x00dev->chip, RF3022))
1851 return 0;
1852
1853 /*
1854 * Init RF calibration.
1855 */
1856 rt2800pci_rfcsr_read(rt2x00dev, 30, &rfcsr);
1857 rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 1);
1858 rt2800pci_rfcsr_write(rt2x00dev, 30, rfcsr);
1859 msleep(1);
1860 rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 0);
1861 rt2800pci_rfcsr_write(rt2x00dev, 30, rfcsr);
1862
1863 rt2800pci_rfcsr_write(rt2x00dev, 0, 0x50);
1864 rt2800pci_rfcsr_write(rt2x00dev, 1, 0x01);
1865 rt2800pci_rfcsr_write(rt2x00dev, 2, 0xf7);
1866 rt2800pci_rfcsr_write(rt2x00dev, 3, 0x75);
1867 rt2800pci_rfcsr_write(rt2x00dev, 4, 0x40);
1868 rt2800pci_rfcsr_write(rt2x00dev, 5, 0x03);
1869 rt2800pci_rfcsr_write(rt2x00dev, 6, 0x02);
1870 rt2800pci_rfcsr_write(rt2x00dev, 7, 0x50);
1871 rt2800pci_rfcsr_write(rt2x00dev, 8, 0x39);
1872 rt2800pci_rfcsr_write(rt2x00dev, 9, 0x0f);
1873 rt2800pci_rfcsr_write(rt2x00dev, 10, 0x60);
1874 rt2800pci_rfcsr_write(rt2x00dev, 11, 0x21);
1875 rt2800pci_rfcsr_write(rt2x00dev, 12, 0x75);
1876 rt2800pci_rfcsr_write(rt2x00dev, 13, 0x75);
1877 rt2800pci_rfcsr_write(rt2x00dev, 14, 0x90);
1878 rt2800pci_rfcsr_write(rt2x00dev, 15, 0x58);
1879 rt2800pci_rfcsr_write(rt2x00dev, 16, 0xb3);
1880 rt2800pci_rfcsr_write(rt2x00dev, 17, 0x92);
1881 rt2800pci_rfcsr_write(rt2x00dev, 18, 0x2c);
1882 rt2800pci_rfcsr_write(rt2x00dev, 19, 0x02);
1883 rt2800pci_rfcsr_write(rt2x00dev, 20, 0xba);
1884 rt2800pci_rfcsr_write(rt2x00dev, 21, 0xdb);
1885 rt2800pci_rfcsr_write(rt2x00dev, 22, 0x00);
1886 rt2800pci_rfcsr_write(rt2x00dev, 23, 0x31);
1887 rt2800pci_rfcsr_write(rt2x00dev, 24, 0x08);
1888 rt2800pci_rfcsr_write(rt2x00dev, 25, 0x01);
1889 rt2800pci_rfcsr_write(rt2x00dev, 26, 0x25);
1890 rt2800pci_rfcsr_write(rt2x00dev, 27, 0x23);
1891 rt2800pci_rfcsr_write(rt2x00dev, 28, 0x13);
1892 rt2800pci_rfcsr_write(rt2x00dev, 29, 0x83);
1893
1894 /*
1895 * Set RX Filter calibration for 20MHz and 40MHz
1896 */
1897 rt2x00dev->calibration[0] =
1898 rt2800pci_init_rx_filter(rt2x00dev, false, 0x07, 0x16);
1899 rt2x00dev->calibration[1] =
1900 rt2800pci_init_rx_filter(rt2x00dev, true, 0x27, 0x19);
1901
1902 /*
1903 * Set back to initial state
1904 */
1905 rt2800pci_bbp_write(rt2x00dev, 24, 0);
1906
1907 rt2800pci_rfcsr_read(rt2x00dev, 22, &rfcsr);
1908 rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 0);
1909 rt2800pci_rfcsr_write(rt2x00dev, 22, rfcsr);
1910
1911 /*
1912 * set BBP back to BW20
1913 */
1914 rt2800pci_bbp_read(rt2x00dev, 4, &bbp);
1915 rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 0);
1916 rt2800pci_bbp_write(rt2x00dev, 4, bbp);
1917 419
1918 return 0; 420 return 0;
1919} 421}
@@ -1926,11 +428,11 @@ static void rt2800pci_toggle_rx(struct rt2x00_dev *rt2x00dev,
1926{ 428{
1927 u32 reg; 429 u32 reg;
1928 430
1929 rt2x00pci_register_read(rt2x00dev, MAC_SYS_CTRL, &reg); 431 rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
1930 rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX, 432 rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX,
1931 (state == STATE_RADIO_RX_ON) || 433 (state == STATE_RADIO_RX_ON) ||
1932 (state == STATE_RADIO_RX_ON_LINK)); 434 (state == STATE_RADIO_RX_ON_LINK));
1933 rt2x00pci_register_write(rt2x00dev, MAC_SYS_CTRL, reg); 435 rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
1934} 436}
1935 437
1936static void rt2800pci_toggle_irq(struct rt2x00_dev *rt2x00dev, 438static void rt2800pci_toggle_irq(struct rt2x00_dev *rt2x00dev,
@@ -1944,11 +446,11 @@ static void rt2800pci_toggle_irq(struct rt2x00_dev *rt2x00dev,
1944 * should clear the register to assure a clean state. 446 * should clear the register to assure a clean state.
1945 */ 447 */
1946 if (state == STATE_RADIO_IRQ_ON) { 448 if (state == STATE_RADIO_IRQ_ON) {
1947 rt2x00pci_register_read(rt2x00dev, INT_SOURCE_CSR, &reg); 449 rt2800_register_read(rt2x00dev, INT_SOURCE_CSR, &reg);
1948 rt2x00pci_register_write(rt2x00dev, INT_SOURCE_CSR, reg); 450 rt2800_register_write(rt2x00dev, INT_SOURCE_CSR, reg);
1949 } 451 }
1950 452
1951 rt2x00pci_register_read(rt2x00dev, INT_MASK_CSR, &reg); 453 rt2800_register_read(rt2x00dev, INT_MASK_CSR, &reg);
1952 rt2x00_set_field32(&reg, INT_MASK_CSR_RXDELAYINT, mask); 454 rt2x00_set_field32(&reg, INT_MASK_CSR_RXDELAYINT, mask);
1953 rt2x00_set_field32(&reg, INT_MASK_CSR_TXDELAYINT, mask); 455 rt2x00_set_field32(&reg, INT_MASK_CSR_TXDELAYINT, mask);
1954 rt2x00_set_field32(&reg, INT_MASK_CSR_RX_DONE, mask); 456 rt2x00_set_field32(&reg, INT_MASK_CSR_RX_DONE, mask);
@@ -1967,7 +469,7 @@ static void rt2800pci_toggle_irq(struct rt2x00_dev *rt2x00dev,
1967 rt2x00_set_field32(&reg, INT_MASK_CSR_GPTIMER, mask); 469 rt2x00_set_field32(&reg, INT_MASK_CSR_GPTIMER, mask);
1968 rt2x00_set_field32(&reg, INT_MASK_CSR_RX_COHERENT, mask); 470 rt2x00_set_field32(&reg, INT_MASK_CSR_RX_COHERENT, mask);
1969 rt2x00_set_field32(&reg, INT_MASK_CSR_TX_COHERENT, mask); 471 rt2x00_set_field32(&reg, INT_MASK_CSR_TX_COHERENT, mask);
1970 rt2x00pci_register_write(rt2x00dev, INT_MASK_CSR, reg); 472 rt2800_register_write(rt2x00dev, INT_MASK_CSR, reg);
1971} 473}
1972 474
1973static int rt2800pci_wait_wpdma_ready(struct rt2x00_dev *rt2x00dev) 475static int rt2800pci_wait_wpdma_ready(struct rt2x00_dev *rt2x00dev)
@@ -1976,7 +478,7 @@ static int rt2800pci_wait_wpdma_ready(struct rt2x00_dev *rt2x00dev)
1976 u32 reg; 478 u32 reg;
1977 479
1978 for (i = 0; i < REGISTER_BUSY_COUNT; i++) { 480 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
1979 rt2x00pci_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg); 481 rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
1980 if (!rt2x00_get_field32(reg, WPDMA_GLO_CFG_TX_DMA_BUSY) && 482 if (!rt2x00_get_field32(reg, WPDMA_GLO_CFG_TX_DMA_BUSY) &&
1981 !rt2x00_get_field32(reg, WPDMA_GLO_CFG_RX_DMA_BUSY)) 483 !rt2x00_get_field32(reg, WPDMA_GLO_CFG_RX_DMA_BUSY))
1982 return 0; 484 return 0;
@@ -1998,50 +500,50 @@ static int rt2800pci_enable_radio(struct rt2x00_dev *rt2x00dev)
1998 */ 500 */
1999 if (unlikely(rt2800pci_wait_wpdma_ready(rt2x00dev) || 501 if (unlikely(rt2800pci_wait_wpdma_ready(rt2x00dev) ||
2000 rt2800pci_init_queues(rt2x00dev) || 502 rt2800pci_init_queues(rt2x00dev) ||
2001 rt2800pci_init_registers(rt2x00dev) || 503 rt2800_init_registers(rt2x00dev) ||
2002 rt2800pci_wait_wpdma_ready(rt2x00dev) || 504 rt2800pci_wait_wpdma_ready(rt2x00dev) ||
2003 rt2800pci_init_bbp(rt2x00dev) || 505 rt2800_init_bbp(rt2x00dev) ||
2004 rt2800pci_init_rfcsr(rt2x00dev))) 506 rt2800_init_rfcsr(rt2x00dev)))
2005 return -EIO; 507 return -EIO;
2006 508
2007 /* 509 /*
2008 * Send signal to firmware during boot time. 510 * Send signal to firmware during boot time.
2009 */ 511 */
2010 rt2800pci_mcu_request(rt2x00dev, MCU_BOOT_SIGNAL, 0xff, 0, 0); 512 rt2800_mcu_request(rt2x00dev, MCU_BOOT_SIGNAL, 0xff, 0, 0);
2011 513
2012 /* 514 /*
2013 * Enable RX. 515 * Enable RX.
2014 */ 516 */
2015 rt2x00pci_register_read(rt2x00dev, MAC_SYS_CTRL, &reg); 517 rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
2016 rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_TX, 1); 518 rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_TX, 1);
2017 rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX, 0); 519 rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX, 0);
2018 rt2x00pci_register_write(rt2x00dev, MAC_SYS_CTRL, reg); 520 rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
2019 521
2020 rt2x00pci_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg); 522 rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
2021 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 1); 523 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 1);
2022 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 1); 524 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 1);
2023 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_WP_DMA_BURST_SIZE, 2); 525 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_WP_DMA_BURST_SIZE, 2);
2024 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1); 526 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1);
2025 rt2x00pci_register_write(rt2x00dev, WPDMA_GLO_CFG, reg); 527 rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
2026 528
2027 rt2x00pci_register_read(rt2x00dev, MAC_SYS_CTRL, &reg); 529 rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
2028 rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_TX, 1); 530 rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_TX, 1);
2029 rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX, 1); 531 rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX, 1);
2030 rt2x00pci_register_write(rt2x00dev, MAC_SYS_CTRL, reg); 532 rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
2031 533
2032 /* 534 /*
2033 * Initialize LED control 535 * Initialize LED control
2034 */ 536 */
2035 rt2x00_eeprom_read(rt2x00dev, EEPROM_LED1, &word); 537 rt2x00_eeprom_read(rt2x00dev, EEPROM_LED1, &word);
2036 rt2800pci_mcu_request(rt2x00dev, MCU_LED_1, 0xff, 538 rt2800_mcu_request(rt2x00dev, MCU_LED_1, 0xff,
2037 word & 0xff, (word >> 8) & 0xff); 539 word & 0xff, (word >> 8) & 0xff);
2038 540
2039 rt2x00_eeprom_read(rt2x00dev, EEPROM_LED2, &word); 541 rt2x00_eeprom_read(rt2x00dev, EEPROM_LED2, &word);
2040 rt2800pci_mcu_request(rt2x00dev, MCU_LED_2, 0xff, 542 rt2800_mcu_request(rt2x00dev, MCU_LED_2, 0xff,
2041 word & 0xff, (word >> 8) & 0xff); 543 word & 0xff, (word >> 8) & 0xff);
2042 544
2043 rt2x00_eeprom_read(rt2x00dev, EEPROM_LED3, &word); 545 rt2x00_eeprom_read(rt2x00dev, EEPROM_LED3, &word);
2044 rt2800pci_mcu_request(rt2x00dev, MCU_LED_3, 0xff, 546 rt2800_mcu_request(rt2x00dev, MCU_LED_3, 0xff,
2045 word & 0xff, (word >> 8) & 0xff); 547 word & 0xff, (word >> 8) & 0xff);
2046 548
2047 return 0; 549 return 0;
@@ -2051,21 +553,21 @@ static void rt2800pci_disable_radio(struct rt2x00_dev *rt2x00dev)
2051{ 553{
2052 u32 reg; 554 u32 reg;
2053 555
2054 rt2x00pci_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg); 556 rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
2055 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0); 557 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
2056 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_DMA_BUSY, 0); 558 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_DMA_BUSY, 0);
2057 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0); 559 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
2058 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_RX_DMA_BUSY, 0); 560 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_RX_DMA_BUSY, 0);
2059 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1); 561 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1);
2060 rt2x00pci_register_write(rt2x00dev, WPDMA_GLO_CFG, reg); 562 rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
2061 563
2062 rt2x00pci_register_write(rt2x00dev, MAC_SYS_CTRL, 0); 564 rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, 0);
2063 rt2x00pci_register_write(rt2x00dev, PWR_PIN_CFG, 0); 565 rt2800_register_write(rt2x00dev, PWR_PIN_CFG, 0);
2064 rt2x00pci_register_write(rt2x00dev, TX_PIN_CFG, 0); 566 rt2800_register_write(rt2x00dev, TX_PIN_CFG, 0);
2065 567
2066 rt2x00pci_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00001280); 568 rt2800_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00001280);
2067 569
2068 rt2x00pci_register_read(rt2x00dev, WPDMA_RST_IDX, &reg); 570 rt2800_register_read(rt2x00dev, WPDMA_RST_IDX, &reg);
2069 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX0, 1); 571 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX0, 1);
2070 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX1, 1); 572 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX1, 1);
2071 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX2, 1); 573 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX2, 1);
@@ -2073,10 +575,10 @@ static void rt2800pci_disable_radio(struct rt2x00_dev *rt2x00dev)
2073 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX4, 1); 575 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX4, 1);
2074 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX5, 1); 576 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX5, 1);
2075 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DRX_IDX0, 1); 577 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DRX_IDX0, 1);
2076 rt2x00pci_register_write(rt2x00dev, WPDMA_RST_IDX, reg); 578 rt2800_register_write(rt2x00dev, WPDMA_RST_IDX, reg);
2077 579
2078 rt2x00pci_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00000e1f); 580 rt2800_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00000e1f);
2079 rt2x00pci_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00000e00); 581 rt2800_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00000e00);
2080 582
2081 /* Wait for DMA, ignore error */ 583 /* Wait for DMA, ignore error */
2082 rt2800pci_wait_wpdma_ready(rt2x00dev); 584 rt2800pci_wait_wpdma_ready(rt2x00dev);
@@ -2090,10 +592,10 @@ static int rt2800pci_set_state(struct rt2x00_dev *rt2x00dev,
2090 * if the device is booting and wasn't asleep it will return 592 * if the device is booting and wasn't asleep it will return
2091 * failure when attempting to wakeup. 593 * failure when attempting to wakeup.
2092 */ 594 */
2093 rt2800pci_mcu_request(rt2x00dev, MCU_SLEEP, 0xff, 0, 2); 595 rt2800_mcu_request(rt2x00dev, MCU_SLEEP, 0xff, 0, 2);
2094 596
2095 if (state == STATE_AWAKE) { 597 if (state == STATE_AWAKE) {
2096 rt2800pci_mcu_request(rt2x00dev, MCU_WAKEUP, TOKEN_WAKUP, 0, 0); 598 rt2800_mcu_request(rt2x00dev, MCU_WAKEUP, TOKEN_WAKUP, 0, 0);
2097 rt2800pci_mcu_status(rt2x00dev, TOKEN_WAKUP); 599 rt2800pci_mcu_status(rt2x00dev, TOKEN_WAKUP);
2098 } 600 }
2099 601
@@ -2195,7 +697,7 @@ static void rt2800pci_write_tx_desc(struct rt2x00_dev *rt2x00dev,
2195 rt2x00_set_field32(&word, TXWI_W1_BW_WIN_SIZE, txdesc->ba_size); 697 rt2x00_set_field32(&word, TXWI_W1_BW_WIN_SIZE, txdesc->ba_size);
2196 rt2x00_set_field32(&word, TXWI_W1_WIRELESS_CLI_ID, 698 rt2x00_set_field32(&word, TXWI_W1_WIRELESS_CLI_ID,
2197 test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags) ? 699 test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags) ?
2198 (skbdesc->entry->entry_idx + 1) : 0xff); 700 txdesc->key_idx : 0xff);
2199 rt2x00_set_field32(&word, TXWI_W1_MPDU_TOTAL_BYTE_COUNT, 701 rt2x00_set_field32(&word, TXWI_W1_MPDU_TOTAL_BYTE_COUNT,
2200 skb->len - txdesc->l2pad); 702 skb->len - txdesc->l2pad);
2201 rt2x00_set_field32(&word, TXWI_W1_PACKETID, 703 rt2x00_set_field32(&word, TXWI_W1_PACKETID,
@@ -2204,8 +706,8 @@ static void rt2800pci_write_tx_desc(struct rt2x00_dev *rt2x00dev,
2204 706
2205 /* 707 /*
2206 * Always write 0 to IV/EIV fields, hardware will insert the IV 708 * Always write 0 to IV/EIV fields, hardware will insert the IV
2207 * from the IVEIV register when ENTRY_TXD_ENCRYPT_IV is set to 0. 709 * from the IVEIV register when TXD_W3_WIV is set to 0.
2208 * When ENTRY_TXD_ENCRYPT_IV is set to 1 it will use the IV data 710 * When TXD_W3_WIV is set to 1 it will use the IV data
2209 * from the descriptor. The TXWI_W1_WIRELESS_CLI_ID indicates which 711 * from the descriptor. The TXWI_W1_WIRELESS_CLI_ID indicates which
2210 * crypto entry in the registers should be used to encrypt the frame. 712 * crypto entry in the registers should be used to encrypt the frame.
2211 */ 713 */
@@ -2265,18 +767,18 @@ static void rt2800pci_write_beacon(struct queue_entry *entry)
2265 * Disable beaconing while we are reloading the beacon data, 767 * Disable beaconing while we are reloading the beacon data,
2266 * otherwise we might be sending out invalid data. 768 * otherwise we might be sending out invalid data.
2267 */ 769 */
2268 rt2x00pci_register_read(rt2x00dev, BCN_TIME_CFG, &reg); 770 rt2800_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
2269 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 0); 771 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 0);
2270 rt2x00pci_register_write(rt2x00dev, BCN_TIME_CFG, reg); 772 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
2271 773
2272 /* 774 /*
2273 * Write entire beacon with descriptor to register. 775 * Write entire beacon with descriptor to register.
2274 */ 776 */
2275 beacon_base = HW_BEACON_OFFSET(entry->entry_idx); 777 beacon_base = HW_BEACON_OFFSET(entry->entry_idx);
2276 rt2x00pci_register_multiwrite(rt2x00dev, 778 rt2800_register_multiwrite(rt2x00dev,
2277 beacon_base, 779 beacon_base,
2278 skbdesc->desc, skbdesc->desc_len); 780 skbdesc->desc, skbdesc->desc_len);
2279 rt2x00pci_register_multiwrite(rt2x00dev, 781 rt2800_register_multiwrite(rt2x00dev,
2280 beacon_base + skbdesc->desc_len, 782 beacon_base + skbdesc->desc_len,
2281 entry->skb->data, entry->skb->len); 783 entry->skb->data, entry->skb->len);
2282 784
@@ -2295,12 +797,12 @@ static void rt2800pci_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
2295 u32 reg; 797 u32 reg;
2296 798
2297 if (queue_idx == QID_BEACON) { 799 if (queue_idx == QID_BEACON) {
2298 rt2x00pci_register_read(rt2x00dev, BCN_TIME_CFG, &reg); 800 rt2800_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
2299 if (!rt2x00_get_field32(reg, BCN_TIME_CFG_BEACON_GEN)) { 801 if (!rt2x00_get_field32(reg, BCN_TIME_CFG_BEACON_GEN)) {
2300 rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 1); 802 rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 1);
2301 rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 1); 803 rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 1);
2302 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 1); 804 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 1);
2303 rt2x00pci_register_write(rt2x00dev, BCN_TIME_CFG, reg); 805 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
2304 } 806 }
2305 return; 807 return;
2306 } 808 }
@@ -2316,7 +818,7 @@ static void rt2800pci_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
2316 else 818 else
2317 qidx = queue_idx; 819 qidx = queue_idx;
2318 820
2319 rt2x00pci_register_write(rt2x00dev, TX_CTX_IDX(qidx), idx); 821 rt2800_register_write(rt2x00dev, TX_CTX_IDX(qidx), idx);
2320} 822}
2321 823
2322static void rt2800pci_kill_tx_queue(struct rt2x00_dev *rt2x00dev, 824static void rt2800pci_kill_tx_queue(struct rt2x00_dev *rt2x00dev,
@@ -2325,16 +827,16 @@ static void rt2800pci_kill_tx_queue(struct rt2x00_dev *rt2x00dev,
2325 u32 reg; 827 u32 reg;
2326 828
2327 if (qid == QID_BEACON) { 829 if (qid == QID_BEACON) {
2328 rt2x00pci_register_write(rt2x00dev, BCN_TIME_CFG, 0); 830 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, 0);
2329 return; 831 return;
2330 } 832 }
2331 833
2332 rt2x00pci_register_read(rt2x00dev, WPDMA_RST_IDX, &reg); 834 rt2800_register_read(rt2x00dev, WPDMA_RST_IDX, &reg);
2333 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX0, (qid == QID_AC_BE)); 835 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX0, (qid == QID_AC_BE));
2334 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX1, (qid == QID_AC_BK)); 836 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX1, (qid == QID_AC_BK));
2335 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX2, (qid == QID_AC_VI)); 837 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX2, (qid == QID_AC_VI));
2336 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX3, (qid == QID_AC_VO)); 838 rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX3, (qid == QID_AC_VO));
2337 rt2x00pci_register_write(rt2x00dev, WPDMA_RST_IDX, reg); 839 rt2800_register_write(rt2x00dev, WPDMA_RST_IDX, reg);
2338} 840}
2339 841
2340/* 842/*
@@ -2430,7 +932,7 @@ static void rt2800pci_fill_rxdone(struct queue_entry *entry,
2430 * Set RX IDX in register to inform hardware that we have handled 932 * Set RX IDX in register to inform hardware that we have handled
2431 * this entry and it is available for reuse again. 933 * this entry and it is available for reuse again.
2432 */ 934 */
2433 rt2x00pci_register_write(rt2x00dev, RX_CRX_IDX, entry->entry_idx); 935 rt2800_register_write(rt2x00dev, RX_CRX_IDX, entry->entry_idx);
2434 936
2435 /* 937 /*
2436 * Remove TXWI descriptor from start of buffer. 938 * Remove TXWI descriptor from start of buffer.
@@ -2467,7 +969,7 @@ static void rt2800pci_txdone(struct rt2x00_dev *rt2x00dev)
2467 old_reg = 0; 969 old_reg = 0;
2468 970
2469 while (1) { 971 while (1) {
2470 rt2x00pci_register_read(rt2x00dev, TX_STA_FIFO, &reg); 972 rt2800_register_read(rt2x00dev, TX_STA_FIFO, &reg);
2471 if (!rt2x00_get_field32(reg, TX_STA_FIFO_VALID)) 973 if (!rt2x00_get_field32(reg, TX_STA_FIFO_VALID))
2472 break; 974 break;
2473 975
@@ -2551,8 +1053,8 @@ static irqreturn_t rt2800pci_interrupt(int irq, void *dev_instance)
2551 u32 reg; 1053 u32 reg;
2552 1054
2553 /* Read status and ACK all interrupts */ 1055 /* Read status and ACK all interrupts */
2554 rt2x00pci_register_read(rt2x00dev, INT_SOURCE_CSR, &reg); 1056 rt2800_register_read(rt2x00dev, INT_SOURCE_CSR, &reg);
2555 rt2x00pci_register_write(rt2x00dev, INT_SOURCE_CSR, reg); 1057 rt2800_register_write(rt2x00dev, INT_SOURCE_CSR, reg);
2556 1058
2557 if (!reg) 1059 if (!reg)
2558 return IRQ_NONE; 1060 return IRQ_NONE;
@@ -2709,7 +1211,7 @@ static int rt2800pci_init_eeprom(struct rt2x00_dev *rt2x00dev)
2709 * Identify RF chipset. 1211 * Identify RF chipset.
2710 */ 1212 */
2711 value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE); 1213 value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE);
2712 rt2x00pci_register_read(rt2x00dev, MAC_CSR0, &reg); 1214 rt2800_register_read(rt2x00dev, MAC_CSR0, &reg);
2713 rt2x00_set_chip_rf(rt2x00dev, value, reg); 1215 rt2x00_set_chip_rf(rt2x00dev, value, reg);
2714 1216
2715 if (!rt2x00_rf(&rt2x00dev->chip, RF2820) && 1217 if (!rt2x00_rf(&rt2x00dev->chip, RF2820) &&
@@ -2758,9 +1260,9 @@ static int rt2800pci_init_eeprom(struct rt2x00_dev *rt2x00dev)
2758 * Store led settings, for correct led behaviour. 1260 * Store led settings, for correct led behaviour.
2759 */ 1261 */
2760#ifdef CONFIG_RT2X00_LIB_LEDS 1262#ifdef CONFIG_RT2X00_LIB_LEDS
2761 rt2800pci_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO); 1263 rt2800_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO);
2762 rt2800pci_init_led(rt2x00dev, &rt2x00dev->led_assoc, LED_TYPE_ASSOC); 1264 rt2800_init_led(rt2x00dev, &rt2x00dev->led_assoc, LED_TYPE_ASSOC);
2763 rt2800pci_init_led(rt2x00dev, &rt2x00dev->led_qual, LED_TYPE_QUALITY); 1265 rt2800_init_led(rt2x00dev, &rt2x00dev->led_qual, LED_TYPE_QUALITY);
2764 1266
2765 rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &rt2x00dev->led_mcu_reg); 1267 rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &rt2x00dev->led_mcu_reg);
2766#endif /* CONFIG_RT2X00_LIB_LEDS */ 1268#endif /* CONFIG_RT2X00_LIB_LEDS */
@@ -2948,10 +1450,25 @@ static int rt2800pci_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
2948 return 0; 1450 return 0;
2949} 1451}
2950 1452
1453static const struct rt2800_ops rt2800pci_rt2800_ops = {
1454 .register_read = rt2x00pci_register_read,
1455 .register_write = rt2x00pci_register_write,
1456 .register_write_lock = rt2x00pci_register_write, /* same for PCI */
1457
1458 .register_multiread = rt2x00pci_register_multiread,
1459 .register_multiwrite = rt2x00pci_register_multiwrite,
1460
1461 .regbusy_read = rt2x00pci_regbusy_read,
1462};
1463
2951static int rt2800pci_probe_hw(struct rt2x00_dev *rt2x00dev) 1464static int rt2800pci_probe_hw(struct rt2x00_dev *rt2x00dev)
2952{ 1465{
2953 int retval; 1466 int retval;
2954 1467
1468 rt2x00_set_chip_intf(rt2x00dev, RT2X00_CHIP_INTF_PCI);
1469
1470 rt2x00dev->priv = (void *)&rt2800pci_rt2800_ops;
1471
2955 /* 1472 /*
2956 * Allocate eeprom data. 1473 * Allocate eeprom data.
2957 */ 1474 */
@@ -2996,161 +1513,6 @@ static int rt2800pci_probe_hw(struct rt2x00_dev *rt2x00dev)
2996 return 0; 1513 return 0;
2997} 1514}
2998 1515
2999/*
3000 * IEEE80211 stack callback functions.
3001 */
3002static void rt2800pci_get_tkip_seq(struct ieee80211_hw *hw, u8 hw_key_idx,
3003 u32 *iv32, u16 *iv16)
3004{
3005 struct rt2x00_dev *rt2x00dev = hw->priv;
3006 struct mac_iveiv_entry iveiv_entry;
3007 u32 offset;
3008
3009 offset = MAC_IVEIV_ENTRY(hw_key_idx);
3010 rt2x00pci_register_multiread(rt2x00dev, offset,
3011 &iveiv_entry, sizeof(iveiv_entry));
3012
3013 memcpy(&iveiv_entry.iv[0], iv16, sizeof(iv16));
3014 memcpy(&iveiv_entry.iv[4], iv32, sizeof(iv32));
3015}
3016
3017static int rt2800pci_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3018{
3019 struct rt2x00_dev *rt2x00dev = hw->priv;
3020 u32 reg;
3021 bool enabled = (value < IEEE80211_MAX_RTS_THRESHOLD);
3022
3023 rt2x00pci_register_read(rt2x00dev, TX_RTS_CFG, &reg);
3024 rt2x00_set_field32(&reg, TX_RTS_CFG_RTS_THRES, value);
3025 rt2x00pci_register_write(rt2x00dev, TX_RTS_CFG, reg);
3026
3027 rt2x00pci_register_read(rt2x00dev, CCK_PROT_CFG, &reg);
3028 rt2x00_set_field32(&reg, CCK_PROT_CFG_RTS_TH_EN, enabled);
3029 rt2x00pci_register_write(rt2x00dev, CCK_PROT_CFG, reg);
3030
3031 rt2x00pci_register_read(rt2x00dev, OFDM_PROT_CFG, &reg);
3032 rt2x00_set_field32(&reg, OFDM_PROT_CFG_RTS_TH_EN, enabled);
3033 rt2x00pci_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
3034
3035 rt2x00pci_register_read(rt2x00dev, MM20_PROT_CFG, &reg);
3036 rt2x00_set_field32(&reg, MM20_PROT_CFG_RTS_TH_EN, enabled);
3037 rt2x00pci_register_write(rt2x00dev, MM20_PROT_CFG, reg);
3038
3039 rt2x00pci_register_read(rt2x00dev, MM40_PROT_CFG, &reg);
3040 rt2x00_set_field32(&reg, MM40_PROT_CFG_RTS_TH_EN, enabled);
3041 rt2x00pci_register_write(rt2x00dev, MM40_PROT_CFG, reg);
3042
3043 rt2x00pci_register_read(rt2x00dev, GF20_PROT_CFG, &reg);
3044 rt2x00_set_field32(&reg, GF20_PROT_CFG_RTS_TH_EN, enabled);
3045 rt2x00pci_register_write(rt2x00dev, GF20_PROT_CFG, reg);
3046
3047 rt2x00pci_register_read(rt2x00dev, GF40_PROT_CFG, &reg);
3048 rt2x00_set_field32(&reg, GF40_PROT_CFG_RTS_TH_EN, enabled);
3049 rt2x00pci_register_write(rt2x00dev, GF40_PROT_CFG, reg);
3050
3051 return 0;
3052}
3053
3054static int rt2800pci_conf_tx(struct ieee80211_hw *hw, u16 queue_idx,
3055 const struct ieee80211_tx_queue_params *params)
3056{
3057 struct rt2x00_dev *rt2x00dev = hw->priv;
3058 struct data_queue *queue;
3059 struct rt2x00_field32 field;
3060 int retval;
3061 u32 reg;
3062 u32 offset;
3063
3064 /*
3065 * First pass the configuration through rt2x00lib, that will
3066 * update the queue settings and validate the input. After that
3067 * we are free to update the registers based on the value
3068 * in the queue parameter.
3069 */
3070 retval = rt2x00mac_conf_tx(hw, queue_idx, params);
3071 if (retval)
3072 return retval;
3073
3074 /*
3075 * We only need to perform additional register initialization
3076 * for WMM queues/
3077 */
3078 if (queue_idx >= 4)
3079 return 0;
3080
3081 queue = rt2x00queue_get_queue(rt2x00dev, queue_idx);
3082
3083 /* Update WMM TXOP register */
3084 offset = WMM_TXOP0_CFG + (sizeof(u32) * (!!(queue_idx & 2)));
3085 field.bit_offset = (queue_idx & 1) * 16;
3086 field.bit_mask = 0xffff << field.bit_offset;
3087
3088 rt2x00pci_register_read(rt2x00dev, offset, &reg);
3089 rt2x00_set_field32(&reg, field, queue->txop);
3090 rt2x00pci_register_write(rt2x00dev, offset, reg);
3091
3092 /* Update WMM registers */
3093 field.bit_offset = queue_idx * 4;
3094 field.bit_mask = 0xf << field.bit_offset;
3095
3096 rt2x00pci_register_read(rt2x00dev, WMM_AIFSN_CFG, &reg);
3097 rt2x00_set_field32(&reg, field, queue->aifs);
3098 rt2x00pci_register_write(rt2x00dev, WMM_AIFSN_CFG, reg);
3099
3100 rt2x00pci_register_read(rt2x00dev, WMM_CWMIN_CFG, &reg);
3101 rt2x00_set_field32(&reg, field, queue->cw_min);
3102 rt2x00pci_register_write(rt2x00dev, WMM_CWMIN_CFG, reg);
3103
3104 rt2x00pci_register_read(rt2x00dev, WMM_CWMAX_CFG, &reg);
3105 rt2x00_set_field32(&reg, field, queue->cw_max);
3106 rt2x00pci_register_write(rt2x00dev, WMM_CWMAX_CFG, reg);
3107
3108 /* Update EDCA registers */
3109 offset = EDCA_AC0_CFG + (sizeof(u32) * queue_idx);
3110
3111 rt2x00pci_register_read(rt2x00dev, offset, &reg);
3112 rt2x00_set_field32(&reg, EDCA_AC0_CFG_TX_OP, queue->txop);
3113 rt2x00_set_field32(&reg, EDCA_AC0_CFG_AIFSN, queue->aifs);
3114 rt2x00_set_field32(&reg, EDCA_AC0_CFG_CWMIN, queue->cw_min);
3115 rt2x00_set_field32(&reg, EDCA_AC0_CFG_CWMAX, queue->cw_max);
3116 rt2x00pci_register_write(rt2x00dev, offset, reg);
3117
3118 return 0;
3119}
3120
3121static u64 rt2800pci_get_tsf(struct ieee80211_hw *hw)
3122{
3123 struct rt2x00_dev *rt2x00dev = hw->priv;
3124 u64 tsf;
3125 u32 reg;
3126
3127 rt2x00pci_register_read(rt2x00dev, TSF_TIMER_DW1, &reg);
3128 tsf = (u64) rt2x00_get_field32(reg, TSF_TIMER_DW1_HIGH_WORD) << 32;
3129 rt2x00pci_register_read(rt2x00dev, TSF_TIMER_DW0, &reg);
3130 tsf |= rt2x00_get_field32(reg, TSF_TIMER_DW0_LOW_WORD);
3131
3132 return tsf;
3133}
3134
3135static const struct ieee80211_ops rt2800pci_mac80211_ops = {
3136 .tx = rt2x00mac_tx,
3137 .start = rt2x00mac_start,
3138 .stop = rt2x00mac_stop,
3139 .add_interface = rt2x00mac_add_interface,
3140 .remove_interface = rt2x00mac_remove_interface,
3141 .config = rt2x00mac_config,
3142 .configure_filter = rt2x00mac_configure_filter,
3143 .set_key = rt2x00mac_set_key,
3144 .get_stats = rt2x00mac_get_stats,
3145 .get_tkip_seq = rt2800pci_get_tkip_seq,
3146 .set_rts_threshold = rt2800pci_set_rts_threshold,
3147 .bss_info_changed = rt2x00mac_bss_info_changed,
3148 .conf_tx = rt2800pci_conf_tx,
3149 .get_tx_stats = rt2x00mac_get_tx_stats,
3150 .get_tsf = rt2800pci_get_tsf,
3151 .rfkill_poll = rt2x00mac_rfkill_poll,
3152};
3153
3154static const struct rt2x00lib_ops rt2800pci_rt2x00_ops = { 1516static const struct rt2x00lib_ops rt2800pci_rt2x00_ops = {
3155 .irq_handler = rt2800pci_interrupt, 1517 .irq_handler = rt2800pci_interrupt,
3156 .probe_hw = rt2800pci_probe_hw, 1518 .probe_hw = rt2800pci_probe_hw,
@@ -3162,23 +1524,23 @@ static const struct rt2x00lib_ops rt2800pci_rt2x00_ops = {
3162 .get_entry_state = rt2800pci_get_entry_state, 1524 .get_entry_state = rt2800pci_get_entry_state,
3163 .clear_entry = rt2800pci_clear_entry, 1525 .clear_entry = rt2800pci_clear_entry,
3164 .set_device_state = rt2800pci_set_device_state, 1526 .set_device_state = rt2800pci_set_device_state,
3165 .rfkill_poll = rt2800pci_rfkill_poll, 1527 .rfkill_poll = rt2800_rfkill_poll,
3166 .link_stats = rt2800pci_link_stats, 1528 .link_stats = rt2800_link_stats,
3167 .reset_tuner = rt2800pci_reset_tuner, 1529 .reset_tuner = rt2800_reset_tuner,
3168 .link_tuner = rt2800pci_link_tuner, 1530 .link_tuner = rt2800_link_tuner,
3169 .write_tx_desc = rt2800pci_write_tx_desc, 1531 .write_tx_desc = rt2800pci_write_tx_desc,
3170 .write_tx_data = rt2x00pci_write_tx_data, 1532 .write_tx_data = rt2x00pci_write_tx_data,
3171 .write_beacon = rt2800pci_write_beacon, 1533 .write_beacon = rt2800pci_write_beacon,
3172 .kick_tx_queue = rt2800pci_kick_tx_queue, 1534 .kick_tx_queue = rt2800pci_kick_tx_queue,
3173 .kill_tx_queue = rt2800pci_kill_tx_queue, 1535 .kill_tx_queue = rt2800pci_kill_tx_queue,
3174 .fill_rxdone = rt2800pci_fill_rxdone, 1536 .fill_rxdone = rt2800pci_fill_rxdone,
3175 .config_shared_key = rt2800pci_config_shared_key, 1537 .config_shared_key = rt2800_config_shared_key,
3176 .config_pairwise_key = rt2800pci_config_pairwise_key, 1538 .config_pairwise_key = rt2800_config_pairwise_key,
3177 .config_filter = rt2800pci_config_filter, 1539 .config_filter = rt2800_config_filter,
3178 .config_intf = rt2800pci_config_intf, 1540 .config_intf = rt2800_config_intf,
3179 .config_erp = rt2800pci_config_erp, 1541 .config_erp = rt2800_config_erp,
3180 .config_ant = rt2800pci_config_ant, 1542 .config_ant = rt2800_config_ant,
3181 .config = rt2800pci_config, 1543 .config = rt2800_config,
3182}; 1544};
3183 1545
3184static const struct data_queue_desc rt2800pci_queue_rx = { 1546static const struct data_queue_desc rt2800pci_queue_rx = {
@@ -3213,9 +1575,9 @@ static const struct rt2x00_ops rt2800pci_ops = {
3213 .tx = &rt2800pci_queue_tx, 1575 .tx = &rt2800pci_queue_tx,
3214 .bcn = &rt2800pci_queue_bcn, 1576 .bcn = &rt2800pci_queue_bcn,
3215 .lib = &rt2800pci_rt2x00_ops, 1577 .lib = &rt2800pci_rt2x00_ops,
3216 .hw = &rt2800pci_mac80211_ops, 1578 .hw = &rt2800_mac80211_ops,
3217#ifdef CONFIG_RT2X00_LIB_DEBUGFS 1579#ifdef CONFIG_RT2X00_LIB_DEBUGFS
3218 .debugfs = &rt2800pci_rt2x00debug, 1580 .debugfs = &rt2800_rt2x00debug,
3219#endif /* CONFIG_RT2X00_LIB_DEBUGFS */ 1581#endif /* CONFIG_RT2X00_LIB_DEBUGFS */
3220}; 1582};
3221 1583
diff --git a/drivers/net/wireless/rt2x00/rt2800pci.h b/drivers/net/wireless/rt2x00/rt2800pci.h
index 856908815221..1dbf13270cda 100644
--- a/drivers/net/wireless/rt2x00/rt2800pci.h
+++ b/drivers/net/wireless/rt2x00/rt2800pci.h
@@ -28,61 +28,6 @@
28#define RT2800PCI_H 28#define RT2800PCI_H
29 29
30/* 30/*
31 * RF chip defines.
32 *
33 * RF2820 2.4G 2T3R
34 * RF2850 2.4G/5G 2T3R
35 * RF2720 2.4G 1T2R
36 * RF2750 2.4G/5G 1T2R
37 * RF3020 2.4G 1T1R
38 * RF2020 2.4G B/G
39 * RF3021 2.4G 1T2R
40 * RF3022 2.4G 2T2R
41 * RF3052 2.4G 2T2R
42 */
43#define RF2820 0x0001
44#define RF2850 0x0002
45#define RF2720 0x0003
46#define RF2750 0x0004
47#define RF3020 0x0005
48#define RF2020 0x0006
49#define RF3021 0x0007
50#define RF3022 0x0008
51#define RF3052 0x0009
52
53/*
54 * RT2860 version
55 */
56#define RT2860C_VERSION 0x28600100
57#define RT2860D_VERSION 0x28600101
58#define RT2880E_VERSION 0x28720200
59#define RT2883_VERSION 0x28830300
60#define RT3070_VERSION 0x30700200
61
62/*
63 * Signal information.
64 * Default offset is required for RSSI <-> dBm conversion.
65 */
66#define DEFAULT_RSSI_OFFSET 120 /* FIXME */
67
68/*
69 * Register layout information.
70 */
71#define CSR_REG_BASE 0x1000
72#define CSR_REG_SIZE 0x0800
73#define EEPROM_BASE 0x0000
74#define EEPROM_SIZE 0x0110
75#define BBP_BASE 0x0000
76#define BBP_SIZE 0x0080
77#define RF_BASE 0x0004
78#define RF_SIZE 0x0010
79
80/*
81 * Number of TX queues.
82 */
83#define NUM_TX_QUEUES 4
84
85/*
86 * PCI registers. 31 * PCI registers.
87 */ 32 */
88 33
@@ -102,215 +47,6 @@
102#define E2PROM_CSR_RELOAD FIELD32(0x00000080) 47#define E2PROM_CSR_RELOAD FIELD32(0x00000080)
103 48
104/* 49/*
105 * INT_SOURCE_CSR: Interrupt source register.
106 * Write one to clear corresponding bit.
107 * TX_FIFO_STATUS: FIFO Statistics is full, sw should read 0x171c
108 */
109#define INT_SOURCE_CSR 0x0200
110#define INT_SOURCE_CSR_RXDELAYINT FIELD32(0x00000001)
111#define INT_SOURCE_CSR_TXDELAYINT FIELD32(0x00000002)
112#define INT_SOURCE_CSR_RX_DONE FIELD32(0x00000004)
113#define INT_SOURCE_CSR_AC0_DMA_DONE FIELD32(0x00000008)
114#define INT_SOURCE_CSR_AC1_DMA_DONE FIELD32(0x00000010)
115#define INT_SOURCE_CSR_AC2_DMA_DONE FIELD32(0x00000020)
116#define INT_SOURCE_CSR_AC3_DMA_DONE FIELD32(0x00000040)
117#define INT_SOURCE_CSR_HCCA_DMA_DONE FIELD32(0x00000080)
118#define INT_SOURCE_CSR_MGMT_DMA_DONE FIELD32(0x00000100)
119#define INT_SOURCE_CSR_MCU_COMMAND FIELD32(0x00000200)
120#define INT_SOURCE_CSR_RXTX_COHERENT FIELD32(0x00000400)
121#define INT_SOURCE_CSR_TBTT FIELD32(0x00000800)
122#define INT_SOURCE_CSR_PRE_TBTT FIELD32(0x00001000)
123#define INT_SOURCE_CSR_TX_FIFO_STATUS FIELD32(0x00002000)
124#define INT_SOURCE_CSR_AUTO_WAKEUP FIELD32(0x00004000)
125#define INT_SOURCE_CSR_GPTIMER FIELD32(0x00008000)
126#define INT_SOURCE_CSR_RX_COHERENT FIELD32(0x00010000)
127#define INT_SOURCE_CSR_TX_COHERENT FIELD32(0x00020000)
128
129/*
130 * INT_MASK_CSR: Interrupt MASK register. 1: the interrupt is mask OFF.
131 */
132#define INT_MASK_CSR 0x0204
133#define INT_MASK_CSR_RXDELAYINT FIELD32(0x00000001)
134#define INT_MASK_CSR_TXDELAYINT FIELD32(0x00000002)
135#define INT_MASK_CSR_RX_DONE FIELD32(0x00000004)
136#define INT_MASK_CSR_AC0_DMA_DONE FIELD32(0x00000008)
137#define INT_MASK_CSR_AC1_DMA_DONE FIELD32(0x00000010)
138#define INT_MASK_CSR_AC2_DMA_DONE FIELD32(0x00000020)
139#define INT_MASK_CSR_AC3_DMA_DONE FIELD32(0x00000040)
140#define INT_MASK_CSR_HCCA_DMA_DONE FIELD32(0x00000080)
141#define INT_MASK_CSR_MGMT_DMA_DONE FIELD32(0x00000100)
142#define INT_MASK_CSR_MCU_COMMAND FIELD32(0x00000200)
143#define INT_MASK_CSR_RXTX_COHERENT FIELD32(0x00000400)
144#define INT_MASK_CSR_TBTT FIELD32(0x00000800)
145#define INT_MASK_CSR_PRE_TBTT FIELD32(0x00001000)
146#define INT_MASK_CSR_TX_FIFO_STATUS FIELD32(0x00002000)
147#define INT_MASK_CSR_AUTO_WAKEUP FIELD32(0x00004000)
148#define INT_MASK_CSR_GPTIMER FIELD32(0x00008000)
149#define INT_MASK_CSR_RX_COHERENT FIELD32(0x00010000)
150#define INT_MASK_CSR_TX_COHERENT FIELD32(0x00020000)
151
152/*
153 * WPDMA_GLO_CFG
154 */
155#define WPDMA_GLO_CFG 0x0208
156#define WPDMA_GLO_CFG_ENABLE_TX_DMA FIELD32(0x00000001)
157#define WPDMA_GLO_CFG_TX_DMA_BUSY FIELD32(0x00000002)
158#define WPDMA_GLO_CFG_ENABLE_RX_DMA FIELD32(0x00000004)
159#define WPDMA_GLO_CFG_RX_DMA_BUSY FIELD32(0x00000008)
160#define WPDMA_GLO_CFG_WP_DMA_BURST_SIZE FIELD32(0x00000030)
161#define WPDMA_GLO_CFG_TX_WRITEBACK_DONE FIELD32(0x00000040)
162#define WPDMA_GLO_CFG_BIG_ENDIAN FIELD32(0x00000080)
163#define WPDMA_GLO_CFG_RX_HDR_SCATTER FIELD32(0x0000ff00)
164#define WPDMA_GLO_CFG_HDR_SEG_LEN FIELD32(0xffff0000)
165
166/*
167 * WPDMA_RST_IDX
168 */
169#define WPDMA_RST_IDX 0x020c
170#define WPDMA_RST_IDX_DTX_IDX0 FIELD32(0x00000001)
171#define WPDMA_RST_IDX_DTX_IDX1 FIELD32(0x00000002)
172#define WPDMA_RST_IDX_DTX_IDX2 FIELD32(0x00000004)
173#define WPDMA_RST_IDX_DTX_IDX3 FIELD32(0x00000008)
174#define WPDMA_RST_IDX_DTX_IDX4 FIELD32(0x00000010)
175#define WPDMA_RST_IDX_DTX_IDX5 FIELD32(0x00000020)
176#define WPDMA_RST_IDX_DRX_IDX0 FIELD32(0x00010000)
177
178/*
179 * DELAY_INT_CFG
180 */
181#define DELAY_INT_CFG 0x0210
182#define DELAY_INT_CFG_RXMAX_PTIME FIELD32(0x000000ff)
183#define DELAY_INT_CFG_RXMAX_PINT FIELD32(0x00007f00)
184#define DELAY_INT_CFG_RXDLY_INT_EN FIELD32(0x00008000)
185#define DELAY_INT_CFG_TXMAX_PTIME FIELD32(0x00ff0000)
186#define DELAY_INT_CFG_TXMAX_PINT FIELD32(0x7f000000)
187#define DELAY_INT_CFG_TXDLY_INT_EN FIELD32(0x80000000)
188
189/*
190 * WMM_AIFSN_CFG: Aifsn for each EDCA AC
191 * AIFSN0: AC_BE
192 * AIFSN1: AC_BK
193 * AIFSN1: AC_VI
194 * AIFSN1: AC_VO
195 */
196#define WMM_AIFSN_CFG 0x0214
197#define WMM_AIFSN_CFG_AIFSN0 FIELD32(0x0000000f)
198#define WMM_AIFSN_CFG_AIFSN1 FIELD32(0x000000f0)
199#define WMM_AIFSN_CFG_AIFSN2 FIELD32(0x00000f00)
200#define WMM_AIFSN_CFG_AIFSN3 FIELD32(0x0000f000)
201
202/*
203 * WMM_CWMIN_CSR: CWmin for each EDCA AC
204 * CWMIN0: AC_BE
205 * CWMIN1: AC_BK
206 * CWMIN1: AC_VI
207 * CWMIN1: AC_VO
208 */
209#define WMM_CWMIN_CFG 0x0218
210#define WMM_CWMIN_CFG_CWMIN0 FIELD32(0x0000000f)
211#define WMM_CWMIN_CFG_CWMIN1 FIELD32(0x000000f0)
212#define WMM_CWMIN_CFG_CWMIN2 FIELD32(0x00000f00)
213#define WMM_CWMIN_CFG_CWMIN3 FIELD32(0x0000f000)
214
215/*
216 * WMM_CWMAX_CSR: CWmax for each EDCA AC
217 * CWMAX0: AC_BE
218 * CWMAX1: AC_BK
219 * CWMAX1: AC_VI
220 * CWMAX1: AC_VO
221 */
222#define WMM_CWMAX_CFG 0x021c
223#define WMM_CWMAX_CFG_CWMAX0 FIELD32(0x0000000f)
224#define WMM_CWMAX_CFG_CWMAX1 FIELD32(0x000000f0)
225#define WMM_CWMAX_CFG_CWMAX2 FIELD32(0x00000f00)
226#define WMM_CWMAX_CFG_CWMAX3 FIELD32(0x0000f000)
227
228/*
229 * AC_TXOP0: AC_BK/AC_BE TXOP register
230 * AC0TXOP: AC_BK in unit of 32us
231 * AC1TXOP: AC_BE in unit of 32us
232 */
233#define WMM_TXOP0_CFG 0x0220
234#define WMM_TXOP0_CFG_AC0TXOP FIELD32(0x0000ffff)
235#define WMM_TXOP0_CFG_AC1TXOP FIELD32(0xffff0000)
236
237/*
238 * AC_TXOP1: AC_VO/AC_VI TXOP register
239 * AC2TXOP: AC_VI in unit of 32us
240 * AC3TXOP: AC_VO in unit of 32us
241 */
242#define WMM_TXOP1_CFG 0x0224
243#define WMM_TXOP1_CFG_AC2TXOP FIELD32(0x0000ffff)
244#define WMM_TXOP1_CFG_AC3TXOP FIELD32(0xffff0000)
245
246/*
247 * GPIO_CTRL_CFG:
248 */
249#define GPIO_CTRL_CFG 0x0228
250#define GPIO_CTRL_CFG_BIT0 FIELD32(0x00000001)
251#define GPIO_CTRL_CFG_BIT1 FIELD32(0x00000002)
252#define GPIO_CTRL_CFG_BIT2 FIELD32(0x00000004)
253#define GPIO_CTRL_CFG_BIT3 FIELD32(0x00000008)
254#define GPIO_CTRL_CFG_BIT4 FIELD32(0x00000010)
255#define GPIO_CTRL_CFG_BIT5 FIELD32(0x00000020)
256#define GPIO_CTRL_CFG_BIT6 FIELD32(0x00000040)
257#define GPIO_CTRL_CFG_BIT7 FIELD32(0x00000080)
258#define GPIO_CTRL_CFG_BIT8 FIELD32(0x00000100)
259
260/*
261 * MCU_CMD_CFG
262 */
263#define MCU_CMD_CFG 0x022c
264
265/*
266 * AC_BK register offsets
267 */
268#define TX_BASE_PTR0 0x0230
269#define TX_MAX_CNT0 0x0234
270#define TX_CTX_IDX0 0x0238
271#define TX_DTX_IDX0 0x023c
272
273/*
274 * AC_BE register offsets
275 */
276#define TX_BASE_PTR1 0x0240
277#define TX_MAX_CNT1 0x0244
278#define TX_CTX_IDX1 0x0248
279#define TX_DTX_IDX1 0x024c
280
281/*
282 * AC_VI register offsets
283 */
284#define TX_BASE_PTR2 0x0250
285#define TX_MAX_CNT2 0x0254
286#define TX_CTX_IDX2 0x0258
287#define TX_DTX_IDX2 0x025c
288
289/*
290 * AC_VO register offsets
291 */
292#define TX_BASE_PTR3 0x0260
293#define TX_MAX_CNT3 0x0264
294#define TX_CTX_IDX3 0x0268
295#define TX_DTX_IDX3 0x026c
296
297/*
298 * HCCA register offsets
299 */
300#define TX_BASE_PTR4 0x0270
301#define TX_MAX_CNT4 0x0274
302#define TX_CTX_IDX4 0x0278
303#define TX_DTX_IDX4 0x027c
304
305/*
306 * MGMT register offsets
307 */
308#define TX_BASE_PTR5 0x0280
309#define TX_MAX_CNT5 0x0284
310#define TX_CTX_IDX5 0x0288
311#define TX_DTX_IDX5 0x028c
312
313/*
314 * Queue register offset macros 50 * Queue register offset macros
315 */ 51 */
316#define TX_QUEUE_REG_OFFSET 0x10 52#define TX_QUEUE_REG_OFFSET 0x10
@@ -320,72 +56,6 @@
320#define TX_DTX_IDX(__x) TX_DTX_IDX0 + ((__x) * TX_QUEUE_REG_OFFSET) 56#define TX_DTX_IDX(__x) TX_DTX_IDX0 + ((__x) * TX_QUEUE_REG_OFFSET)
321 57
322/* 58/*
323 * RX register offsets
324 */
325#define RX_BASE_PTR 0x0290
326#define RX_MAX_CNT 0x0294
327#define RX_CRX_IDX 0x0298
328#define RX_DRX_IDX 0x029c
329
330/*
331 * PBF_SYS_CTRL
332 * HOST_RAM_WRITE: enable Host program ram write selection
333 */
334#define PBF_SYS_CTRL 0x0400
335#define PBF_SYS_CTRL_READY FIELD32(0x00000080)
336#define PBF_SYS_CTRL_HOST_RAM_WRITE FIELD32(0x00010000)
337
338/*
339 * HOST-MCU shared memory
340 */
341#define HOST_CMD_CSR 0x0404
342#define HOST_CMD_CSR_HOST_COMMAND FIELD32(0x000000ff)
343
344/*
345 * PBF registers
346 * Most are for debug. Driver doesn't touch PBF register.
347 */
348#define PBF_CFG 0x0408
349#define PBF_MAX_PCNT 0x040c
350#define PBF_CTRL 0x0410
351#define PBF_INT_STA 0x0414
352#define PBF_INT_ENA 0x0418
353
354/*
355 * BCN_OFFSET0:
356 */
357#define BCN_OFFSET0 0x042c
358#define BCN_OFFSET0_BCN0 FIELD32(0x000000ff)
359#define BCN_OFFSET0_BCN1 FIELD32(0x0000ff00)
360#define BCN_OFFSET0_BCN2 FIELD32(0x00ff0000)
361#define BCN_OFFSET0_BCN3 FIELD32(0xff000000)
362
363/*
364 * BCN_OFFSET1:
365 */
366#define BCN_OFFSET1 0x0430
367#define BCN_OFFSET1_BCN4 FIELD32(0x000000ff)
368#define BCN_OFFSET1_BCN5 FIELD32(0x0000ff00)
369#define BCN_OFFSET1_BCN6 FIELD32(0x00ff0000)
370#define BCN_OFFSET1_BCN7 FIELD32(0xff000000)
371
372/*
373 * PBF registers
374 * Most are for debug. Driver doesn't touch PBF register.
375 */
376#define TXRXQ_PCNT 0x0438
377#define PBF_DBG 0x043c
378
379/*
380 * RF registers
381 */
382#define RF_CSR_CFG 0x0500
383#define RF_CSR_CFG_DATA FIELD32(0x000000ff)
384#define RF_CSR_CFG_REGNUM FIELD32(0x00001f00)
385#define RF_CSR_CFG_WRITE FIELD32(0x00010000)
386#define RF_CSR_CFG_BUSY FIELD32(0x00020000)
387
388/*
389 * EFUSE_CSR: RT3090 EEPROM 59 * EFUSE_CSR: RT3090 EEPROM
390 */ 60 */
391#define EFUSE_CTRL 0x0580 61#define EFUSE_CTRL 0x0580
@@ -414,1360 +84,16 @@
414#define EFUSE_DATA3 0x059c 84#define EFUSE_DATA3 0x059c
415 85
416/* 86/*
417 * MAC Control/Status Registers(CSR).
418 * Some values are set in TU, whereas 1 TU == 1024 us.
419 */
420
421/*
422 * MAC_CSR0: ASIC revision number.
423 * ASIC_REV: 0
424 * ASIC_VER: 2860
425 */
426#define MAC_CSR0 0x1000
427#define MAC_CSR0_ASIC_REV FIELD32(0x0000ffff)
428#define MAC_CSR0_ASIC_VER FIELD32(0xffff0000)
429
430/*
431 * MAC_SYS_CTRL:
432 */
433#define MAC_SYS_CTRL 0x1004
434#define MAC_SYS_CTRL_RESET_CSR FIELD32(0x00000001)
435#define MAC_SYS_CTRL_RESET_BBP FIELD32(0x00000002)
436#define MAC_SYS_CTRL_ENABLE_TX FIELD32(0x00000004)
437#define MAC_SYS_CTRL_ENABLE_RX FIELD32(0x00000008)
438#define MAC_SYS_CTRL_CONTINUOUS_TX FIELD32(0x00000010)
439#define MAC_SYS_CTRL_LOOPBACK FIELD32(0x00000020)
440#define MAC_SYS_CTRL_WLAN_HALT FIELD32(0x00000040)
441#define MAC_SYS_CTRL_RX_TIMESTAMP FIELD32(0x00000080)
442
443/*
444 * MAC_ADDR_DW0: STA MAC register 0
445 */
446#define MAC_ADDR_DW0 0x1008
447#define MAC_ADDR_DW0_BYTE0 FIELD32(0x000000ff)
448#define MAC_ADDR_DW0_BYTE1 FIELD32(0x0000ff00)
449#define MAC_ADDR_DW0_BYTE2 FIELD32(0x00ff0000)
450#define MAC_ADDR_DW0_BYTE3 FIELD32(0xff000000)
451
452/*
453 * MAC_ADDR_DW1: STA MAC register 1
454 * UNICAST_TO_ME_MASK:
455 * Used to mask off bits from byte 5 of the MAC address
456 * to determine the UNICAST_TO_ME bit for RX frames.
457 * The full mask is complemented by BSS_ID_MASK:
458 * MASK = BSS_ID_MASK & UNICAST_TO_ME_MASK
459 */
460#define MAC_ADDR_DW1 0x100c
461#define MAC_ADDR_DW1_BYTE4 FIELD32(0x000000ff)
462#define MAC_ADDR_DW1_BYTE5 FIELD32(0x0000ff00)
463#define MAC_ADDR_DW1_UNICAST_TO_ME_MASK FIELD32(0x00ff0000)
464
465/*
466 * MAC_BSSID_DW0: BSSID register 0
467 */
468#define MAC_BSSID_DW0 0x1010
469#define MAC_BSSID_DW0_BYTE0 FIELD32(0x000000ff)
470#define MAC_BSSID_DW0_BYTE1 FIELD32(0x0000ff00)
471#define MAC_BSSID_DW0_BYTE2 FIELD32(0x00ff0000)
472#define MAC_BSSID_DW0_BYTE3 FIELD32(0xff000000)
473
474/*
475 * MAC_BSSID_DW1: BSSID register 1
476 * BSS_ID_MASK:
477 * 0: 1-BSSID mode (BSS index = 0)
478 * 1: 2-BSSID mode (BSS index: Byte5, bit 0)
479 * 2: 4-BSSID mode (BSS index: byte5, bit 0 - 1)
480 * 3: 8-BSSID mode (BSS index: byte5, bit 0 - 2)
481 * This mask is used to mask off bits 0, 1 and 2 of byte 5 of the
482 * BSSID. This will make sure that those bits will be ignored
483 * when determining the MY_BSS of RX frames.
484 */
485#define MAC_BSSID_DW1 0x1014
486#define MAC_BSSID_DW1_BYTE4 FIELD32(0x000000ff)
487#define MAC_BSSID_DW1_BYTE5 FIELD32(0x0000ff00)
488#define MAC_BSSID_DW1_BSS_ID_MASK FIELD32(0x00030000)
489#define MAC_BSSID_DW1_BSS_BCN_NUM FIELD32(0x001c0000)
490
491/*
492 * MAX_LEN_CFG: Maximum frame length register.
493 * MAX_MPDU: rt2860b max 16k bytes
494 * MAX_PSDU: Maximum PSDU length
495 * (power factor) 0:2^13, 1:2^14, 2:2^15, 3:2^16
496 */
497#define MAX_LEN_CFG 0x1018
498#define MAX_LEN_CFG_MAX_MPDU FIELD32(0x00000fff)
499#define MAX_LEN_CFG_MAX_PSDU FIELD32(0x00003000)
500#define MAX_LEN_CFG_MIN_PSDU FIELD32(0x0000c000)
501#define MAX_LEN_CFG_MIN_MPDU FIELD32(0x000f0000)
502
503/*
504 * BBP_CSR_CFG: BBP serial control register
505 * VALUE: Register value to program into BBP
506 * REG_NUM: Selected BBP register
507 * READ_CONTROL: 0 write BBP, 1 read BBP
508 * BUSY: ASIC is busy executing BBP commands
509 * BBP_PAR_DUR: 0 4 MAC clocks, 1 8 MAC clocks
510 * BBP_RW_MODE: 0 serial, 1 paralell
511 */
512#define BBP_CSR_CFG 0x101c
513#define BBP_CSR_CFG_VALUE FIELD32(0x000000ff)
514#define BBP_CSR_CFG_REGNUM FIELD32(0x0000ff00)
515#define BBP_CSR_CFG_READ_CONTROL FIELD32(0x00010000)
516#define BBP_CSR_CFG_BUSY FIELD32(0x00020000)
517#define BBP_CSR_CFG_BBP_PAR_DUR FIELD32(0x00040000)
518#define BBP_CSR_CFG_BBP_RW_MODE FIELD32(0x00080000)
519
520/*
521 * RF_CSR_CFG0: RF control register
522 * REGID_AND_VALUE: Register value to program into RF
523 * BITWIDTH: Selected RF register
524 * STANDBYMODE: 0 high when standby, 1 low when standby
525 * SEL: 0 RF_LE0 activate, 1 RF_LE1 activate
526 * BUSY: ASIC is busy executing RF commands
527 */
528#define RF_CSR_CFG0 0x1020
529#define RF_CSR_CFG0_REGID_AND_VALUE FIELD32(0x00ffffff)
530#define RF_CSR_CFG0_BITWIDTH FIELD32(0x1f000000)
531#define RF_CSR_CFG0_REG_VALUE_BW FIELD32(0x1fffffff)
532#define RF_CSR_CFG0_STANDBYMODE FIELD32(0x20000000)
533#define RF_CSR_CFG0_SEL FIELD32(0x40000000)
534#define RF_CSR_CFG0_BUSY FIELD32(0x80000000)
535
536/*
537 * RF_CSR_CFG1: RF control register
538 * REGID_AND_VALUE: Register value to program into RF
539 * RFGAP: Gap between BB_CONTROL_RF and RF_LE
540 * 0: 3 system clock cycle (37.5usec)
541 * 1: 5 system clock cycle (62.5usec)
542 */
543#define RF_CSR_CFG1 0x1024
544#define RF_CSR_CFG1_REGID_AND_VALUE FIELD32(0x00ffffff)
545#define RF_CSR_CFG1_RFGAP FIELD32(0x1f000000)
546
547/*
548 * RF_CSR_CFG2: RF control register
549 * VALUE: Register value to program into RF
550 * RFGAP: Gap between BB_CONTROL_RF and RF_LE
551 * 0: 3 system clock cycle (37.5usec)
552 * 1: 5 system clock cycle (62.5usec)
553 */
554#define RF_CSR_CFG2 0x1028
555#define RF_CSR_CFG2_VALUE FIELD32(0x00ffffff)
556
557/*
558 * LED_CFG: LED control
559 * color LED's:
560 * 0: off
561 * 1: blinking upon TX2
562 * 2: periodic slow blinking
563 * 3: always on
564 * LED polarity:
565 * 0: active low
566 * 1: active high
567 */
568#define LED_CFG 0x102c
569#define LED_CFG_ON_PERIOD FIELD32(0x000000ff)
570#define LED_CFG_OFF_PERIOD FIELD32(0x0000ff00)
571#define LED_CFG_SLOW_BLINK_PERIOD FIELD32(0x003f0000)
572#define LED_CFG_R_LED_MODE FIELD32(0x03000000)
573#define LED_CFG_G_LED_MODE FIELD32(0x0c000000)
574#define LED_CFG_Y_LED_MODE FIELD32(0x30000000)
575#define LED_CFG_LED_POLAR FIELD32(0x40000000)
576
577/*
578 * XIFS_TIME_CFG: MAC timing
579 * CCKM_SIFS_TIME: unit 1us. Applied after CCK RX/TX
580 * OFDM_SIFS_TIME: unit 1us. Applied after OFDM RX/TX
581 * OFDM_XIFS_TIME: unit 1us. Applied after OFDM RX
582 * when MAC doesn't reference BBP signal BBRXEND
583 * EIFS: unit 1us
584 * BB_RXEND_ENABLE: reference RXEND signal to begin XIFS defer
585 *
586 */
587#define XIFS_TIME_CFG 0x1100
588#define XIFS_TIME_CFG_CCKM_SIFS_TIME FIELD32(0x000000ff)
589#define XIFS_TIME_CFG_OFDM_SIFS_TIME FIELD32(0x0000ff00)
590#define XIFS_TIME_CFG_OFDM_XIFS_TIME FIELD32(0x000f0000)
591#define XIFS_TIME_CFG_EIFS FIELD32(0x1ff00000)
592#define XIFS_TIME_CFG_BB_RXEND_ENABLE FIELD32(0x20000000)
593
594/*
595 * BKOFF_SLOT_CFG:
596 */
597#define BKOFF_SLOT_CFG 0x1104
598#define BKOFF_SLOT_CFG_SLOT_TIME FIELD32(0x000000ff)
599#define BKOFF_SLOT_CFG_CC_DELAY_TIME FIELD32(0x0000ff00)
600
601/*
602 * NAV_TIME_CFG:
603 */
604#define NAV_TIME_CFG 0x1108
605#define NAV_TIME_CFG_SIFS FIELD32(0x000000ff)
606#define NAV_TIME_CFG_SLOT_TIME FIELD32(0x0000ff00)
607#define NAV_TIME_CFG_EIFS FIELD32(0x01ff0000)
608#define NAV_TIME_ZERO_SIFS FIELD32(0x02000000)
609
610/*
611 * CH_TIME_CFG: count as channel busy
612 */
613#define CH_TIME_CFG 0x110c
614
615/*
616 * PBF_LIFE_TIMER: TX/RX MPDU timestamp timer (free run) Unit: 1us
617 */
618#define PBF_LIFE_TIMER 0x1110
619
620/*
621 * BCN_TIME_CFG:
622 * BEACON_INTERVAL: in unit of 1/16 TU
623 * TSF_TICKING: Enable TSF auto counting
624 * TSF_SYNC: Enable TSF sync, 00: disable, 01: infra mode, 10: ad-hoc mode
625 * BEACON_GEN: Enable beacon generator
626 */
627#define BCN_TIME_CFG 0x1114
628#define BCN_TIME_CFG_BEACON_INTERVAL FIELD32(0x0000ffff)
629#define BCN_TIME_CFG_TSF_TICKING FIELD32(0x00010000)
630#define BCN_TIME_CFG_TSF_SYNC FIELD32(0x00060000)
631#define BCN_TIME_CFG_TBTT_ENABLE FIELD32(0x00080000)
632#define BCN_TIME_CFG_BEACON_GEN FIELD32(0x00100000)
633#define BCN_TIME_CFG_TX_TIME_COMPENSATE FIELD32(0xf0000000)
634
635/*
636 * TBTT_SYNC_CFG:
637 */
638#define TBTT_SYNC_CFG 0x1118
639
640/*
641 * TSF_TIMER_DW0: Local lsb TSF timer, read-only
642 */
643#define TSF_TIMER_DW0 0x111c
644#define TSF_TIMER_DW0_LOW_WORD FIELD32(0xffffffff)
645
646/*
647 * TSF_TIMER_DW1: Local msb TSF timer, read-only
648 */
649#define TSF_TIMER_DW1 0x1120
650#define TSF_TIMER_DW1_HIGH_WORD FIELD32(0xffffffff)
651
652/*
653 * TBTT_TIMER: TImer remains till next TBTT, read-only
654 */
655#define TBTT_TIMER 0x1124
656
657/*
658 * INT_TIMER_CFG:
659 */
660#define INT_TIMER_CFG 0x1128
661
662/*
663 * INT_TIMER_EN: GP-timer and pre-tbtt Int enable
664 */
665#define INT_TIMER_EN 0x112c
666
667/*
668 * CH_IDLE_STA: channel idle time
669 */
670#define CH_IDLE_STA 0x1130
671
672/*
673 * CH_BUSY_STA: channel busy time
674 */
675#define CH_BUSY_STA 0x1134
676
677/*
678 * MAC_STATUS_CFG:
679 * BBP_RF_BUSY: When set to 0, BBP and RF are stable.
680 * if 1 or higher one of the 2 registers is busy.
681 */
682#define MAC_STATUS_CFG 0x1200
683#define MAC_STATUS_CFG_BBP_RF_BUSY FIELD32(0x00000003)
684
685/*
686 * PWR_PIN_CFG:
687 */
688#define PWR_PIN_CFG 0x1204
689
690/*
691 * AUTOWAKEUP_CFG: Manual power control / status register
692 * TBCN_BEFORE_WAKE: ForceWake has high privilege than PutToSleep when both set
693 * AUTOWAKE: 0:sleep, 1:awake
694 */
695#define AUTOWAKEUP_CFG 0x1208
696#define AUTOWAKEUP_CFG_AUTO_LEAD_TIME FIELD32(0x000000ff)
697#define AUTOWAKEUP_CFG_TBCN_BEFORE_WAKE FIELD32(0x00007f00)
698#define AUTOWAKEUP_CFG_AUTOWAKE FIELD32(0x00008000)
699
700/*
701 * EDCA_AC0_CFG:
702 */
703#define EDCA_AC0_CFG 0x1300
704#define EDCA_AC0_CFG_TX_OP FIELD32(0x000000ff)
705#define EDCA_AC0_CFG_AIFSN FIELD32(0x00000f00)
706#define EDCA_AC0_CFG_CWMIN FIELD32(0x0000f000)
707#define EDCA_AC0_CFG_CWMAX FIELD32(0x000f0000)
708
709/*
710 * EDCA_AC1_CFG:
711 */
712#define EDCA_AC1_CFG 0x1304
713#define EDCA_AC1_CFG_TX_OP FIELD32(0x000000ff)
714#define EDCA_AC1_CFG_AIFSN FIELD32(0x00000f00)
715#define EDCA_AC1_CFG_CWMIN FIELD32(0x0000f000)
716#define EDCA_AC1_CFG_CWMAX FIELD32(0x000f0000)
717
718/*
719 * EDCA_AC2_CFG:
720 */
721#define EDCA_AC2_CFG 0x1308
722#define EDCA_AC2_CFG_TX_OP FIELD32(0x000000ff)
723#define EDCA_AC2_CFG_AIFSN FIELD32(0x00000f00)
724#define EDCA_AC2_CFG_CWMIN FIELD32(0x0000f000)
725#define EDCA_AC2_CFG_CWMAX FIELD32(0x000f0000)
726
727/*
728 * EDCA_AC3_CFG:
729 */
730#define EDCA_AC3_CFG 0x130c
731#define EDCA_AC3_CFG_TX_OP FIELD32(0x000000ff)
732#define EDCA_AC3_CFG_AIFSN FIELD32(0x00000f00)
733#define EDCA_AC3_CFG_CWMIN FIELD32(0x0000f000)
734#define EDCA_AC3_CFG_CWMAX FIELD32(0x000f0000)
735
736/*
737 * EDCA_TID_AC_MAP:
738 */
739#define EDCA_TID_AC_MAP 0x1310
740
741/*
742 * TX_PWR_CFG_0:
743 */
744#define TX_PWR_CFG_0 0x1314
745#define TX_PWR_CFG_0_1MBS FIELD32(0x0000000f)
746#define TX_PWR_CFG_0_2MBS FIELD32(0x000000f0)
747#define TX_PWR_CFG_0_55MBS FIELD32(0x00000f00)
748#define TX_PWR_CFG_0_11MBS FIELD32(0x0000f000)
749#define TX_PWR_CFG_0_6MBS FIELD32(0x000f0000)
750#define TX_PWR_CFG_0_9MBS FIELD32(0x00f00000)
751#define TX_PWR_CFG_0_12MBS FIELD32(0x0f000000)
752#define TX_PWR_CFG_0_18MBS FIELD32(0xf0000000)
753
754/*
755 * TX_PWR_CFG_1:
756 */
757#define TX_PWR_CFG_1 0x1318
758#define TX_PWR_CFG_1_24MBS FIELD32(0x0000000f)
759#define TX_PWR_CFG_1_36MBS FIELD32(0x000000f0)
760#define TX_PWR_CFG_1_48MBS FIELD32(0x00000f00)
761#define TX_PWR_CFG_1_54MBS FIELD32(0x0000f000)
762#define TX_PWR_CFG_1_MCS0 FIELD32(0x000f0000)
763#define TX_PWR_CFG_1_MCS1 FIELD32(0x00f00000)
764#define TX_PWR_CFG_1_MCS2 FIELD32(0x0f000000)
765#define TX_PWR_CFG_1_MCS3 FIELD32(0xf0000000)
766
767/*
768 * TX_PWR_CFG_2:
769 */
770#define TX_PWR_CFG_2 0x131c
771#define TX_PWR_CFG_2_MCS4 FIELD32(0x0000000f)
772#define TX_PWR_CFG_2_MCS5 FIELD32(0x000000f0)
773#define TX_PWR_CFG_2_MCS6 FIELD32(0x00000f00)
774#define TX_PWR_CFG_2_MCS7 FIELD32(0x0000f000)
775#define TX_PWR_CFG_2_MCS8 FIELD32(0x000f0000)
776#define TX_PWR_CFG_2_MCS9 FIELD32(0x00f00000)
777#define TX_PWR_CFG_2_MCS10 FIELD32(0x0f000000)
778#define TX_PWR_CFG_2_MCS11 FIELD32(0xf0000000)
779
780/*
781 * TX_PWR_CFG_3:
782 */
783#define TX_PWR_CFG_3 0x1320
784#define TX_PWR_CFG_3_MCS12 FIELD32(0x0000000f)
785#define TX_PWR_CFG_3_MCS13 FIELD32(0x000000f0)
786#define TX_PWR_CFG_3_MCS14 FIELD32(0x00000f00)
787#define TX_PWR_CFG_3_MCS15 FIELD32(0x0000f000)
788#define TX_PWR_CFG_3_UKNOWN1 FIELD32(0x000f0000)
789#define TX_PWR_CFG_3_UKNOWN2 FIELD32(0x00f00000)
790#define TX_PWR_CFG_3_UKNOWN3 FIELD32(0x0f000000)
791#define TX_PWR_CFG_3_UKNOWN4 FIELD32(0xf0000000)
792
793/*
794 * TX_PWR_CFG_4:
795 */
796#define TX_PWR_CFG_4 0x1324
797#define TX_PWR_CFG_4_UKNOWN5 FIELD32(0x0000000f)
798#define TX_PWR_CFG_4_UKNOWN6 FIELD32(0x000000f0)
799#define TX_PWR_CFG_4_UKNOWN7 FIELD32(0x00000f00)
800#define TX_PWR_CFG_4_UKNOWN8 FIELD32(0x0000f000)
801
802/*
803 * TX_PIN_CFG:
804 */
805#define TX_PIN_CFG 0x1328
806#define TX_PIN_CFG_PA_PE_A0_EN FIELD32(0x00000001)
807#define TX_PIN_CFG_PA_PE_G0_EN FIELD32(0x00000002)
808#define TX_PIN_CFG_PA_PE_A1_EN FIELD32(0x00000004)
809#define TX_PIN_CFG_PA_PE_G1_EN FIELD32(0x00000008)
810#define TX_PIN_CFG_PA_PE_A0_POL FIELD32(0x00000010)
811#define TX_PIN_CFG_PA_PE_G0_POL FIELD32(0x00000020)
812#define TX_PIN_CFG_PA_PE_A1_POL FIELD32(0x00000040)
813#define TX_PIN_CFG_PA_PE_G1_POL FIELD32(0x00000080)
814#define TX_PIN_CFG_LNA_PE_A0_EN FIELD32(0x00000100)
815#define TX_PIN_CFG_LNA_PE_G0_EN FIELD32(0x00000200)
816#define TX_PIN_CFG_LNA_PE_A1_EN FIELD32(0x00000400)
817#define TX_PIN_CFG_LNA_PE_G1_EN FIELD32(0x00000800)
818#define TX_PIN_CFG_LNA_PE_A0_POL FIELD32(0x00001000)
819#define TX_PIN_CFG_LNA_PE_G0_POL FIELD32(0x00002000)
820#define TX_PIN_CFG_LNA_PE_A1_POL FIELD32(0x00004000)
821#define TX_PIN_CFG_LNA_PE_G1_POL FIELD32(0x00008000)
822#define TX_PIN_CFG_RFTR_EN FIELD32(0x00010000)
823#define TX_PIN_CFG_RFTR_POL FIELD32(0x00020000)
824#define TX_PIN_CFG_TRSW_EN FIELD32(0x00040000)
825#define TX_PIN_CFG_TRSW_POL FIELD32(0x00080000)
826
827/*
828 * TX_BAND_CFG: 0x1 use upper 20MHz, 0x0 use lower 20MHz
829 */
830#define TX_BAND_CFG 0x132c
831#define TX_BAND_CFG_HT40_PLUS FIELD32(0x00000001)
832#define TX_BAND_CFG_A FIELD32(0x00000002)
833#define TX_BAND_CFG_BG FIELD32(0x00000004)
834
835/*
836 * TX_SW_CFG0:
837 */
838#define TX_SW_CFG0 0x1330
839
840/*
841 * TX_SW_CFG1:
842 */
843#define TX_SW_CFG1 0x1334
844
845/*
846 * TX_SW_CFG2:
847 */
848#define TX_SW_CFG2 0x1338
849
850/*
851 * TXOP_THRES_CFG:
852 */
853#define TXOP_THRES_CFG 0x133c
854
855/*
856 * TXOP_CTRL_CFG:
857 */
858#define TXOP_CTRL_CFG 0x1340
859
860/*
861 * TX_RTS_CFG:
862 * RTS_THRES: unit:byte
863 * RTS_FBK_EN: enable rts rate fallback
864 */
865#define TX_RTS_CFG 0x1344
866#define TX_RTS_CFG_AUTO_RTS_RETRY_LIMIT FIELD32(0x000000ff)
867#define TX_RTS_CFG_RTS_THRES FIELD32(0x00ffff00)
868#define TX_RTS_CFG_RTS_FBK_EN FIELD32(0x01000000)
869
870/*
871 * TX_TIMEOUT_CFG:
872 * MPDU_LIFETIME: expiration time = 2^(9+MPDU LIFE TIME) us
873 * RX_ACK_TIMEOUT: unit:slot. Used for TX procedure
874 * TX_OP_TIMEOUT: TXOP timeout value for TXOP truncation.
875 * it is recommended that:
876 * (SLOT_TIME) > (TX_OP_TIMEOUT) > (RX_ACK_TIMEOUT)
877 */
878#define TX_TIMEOUT_CFG 0x1348
879#define TX_TIMEOUT_CFG_MPDU_LIFETIME FIELD32(0x000000f0)
880#define TX_TIMEOUT_CFG_RX_ACK_TIMEOUT FIELD32(0x0000ff00)
881#define TX_TIMEOUT_CFG_TX_OP_TIMEOUT FIELD32(0x00ff0000)
882
883/*
884 * TX_RTY_CFG:
885 * SHORT_RTY_LIMIT: short retry limit
886 * LONG_RTY_LIMIT: long retry limit
887 * LONG_RTY_THRE: Long retry threshoold
888 * NON_AGG_RTY_MODE: Non-Aggregate MPDU retry mode
889 * 0:expired by retry limit, 1: expired by mpdu life timer
890 * AGG_RTY_MODE: Aggregate MPDU retry mode
891 * 0:expired by retry limit, 1: expired by mpdu life timer
892 * TX_AUTO_FB_ENABLE: Tx retry PHY rate auto fallback enable
893 */
894#define TX_RTY_CFG 0x134c
895#define TX_RTY_CFG_SHORT_RTY_LIMIT FIELD32(0x000000ff)
896#define TX_RTY_CFG_LONG_RTY_LIMIT FIELD32(0x0000ff00)
897#define TX_RTY_CFG_LONG_RTY_THRE FIELD32(0x0fff0000)
898#define TX_RTY_CFG_NON_AGG_RTY_MODE FIELD32(0x10000000)
899#define TX_RTY_CFG_AGG_RTY_MODE FIELD32(0x20000000)
900#define TX_RTY_CFG_TX_AUTO_FB_ENABLE FIELD32(0x40000000)
901
902/*
903 * TX_LINK_CFG:
904 * REMOTE_MFB_LIFETIME: remote MFB life time. unit: 32us
905 * MFB_ENABLE: TX apply remote MFB 1:enable
906 * REMOTE_UMFS_ENABLE: remote unsolicit MFB enable
907 * 0: not apply remote remote unsolicit (MFS=7)
908 * TX_MRQ_EN: MCS request TX enable
909 * TX_RDG_EN: RDG TX enable
910 * TX_CF_ACK_EN: Piggyback CF-ACK enable
911 * REMOTE_MFB: remote MCS feedback
912 * REMOTE_MFS: remote MCS feedback sequence number
913 */
914#define TX_LINK_CFG 0x1350
915#define TX_LINK_CFG_REMOTE_MFB_LIFETIME FIELD32(0x000000ff)
916#define TX_LINK_CFG_MFB_ENABLE FIELD32(0x00000100)
917#define TX_LINK_CFG_REMOTE_UMFS_ENABLE FIELD32(0x00000200)
918#define TX_LINK_CFG_TX_MRQ_EN FIELD32(0x00000400)
919#define TX_LINK_CFG_TX_RDG_EN FIELD32(0x00000800)
920#define TX_LINK_CFG_TX_CF_ACK_EN FIELD32(0x00001000)
921#define TX_LINK_CFG_REMOTE_MFB FIELD32(0x00ff0000)
922#define TX_LINK_CFG_REMOTE_MFS FIELD32(0xff000000)
923
924/*
925 * HT_FBK_CFG0:
926 */
927#define HT_FBK_CFG0 0x1354
928#define HT_FBK_CFG0_HTMCS0FBK FIELD32(0x0000000f)
929#define HT_FBK_CFG0_HTMCS1FBK FIELD32(0x000000f0)
930#define HT_FBK_CFG0_HTMCS2FBK FIELD32(0x00000f00)
931#define HT_FBK_CFG0_HTMCS3FBK FIELD32(0x0000f000)
932#define HT_FBK_CFG0_HTMCS4FBK FIELD32(0x000f0000)
933#define HT_FBK_CFG0_HTMCS5FBK FIELD32(0x00f00000)
934#define HT_FBK_CFG0_HTMCS6FBK FIELD32(0x0f000000)
935#define HT_FBK_CFG0_HTMCS7FBK FIELD32(0xf0000000)
936
937/*
938 * HT_FBK_CFG1:
939 */
940#define HT_FBK_CFG1 0x1358
941#define HT_FBK_CFG1_HTMCS8FBK FIELD32(0x0000000f)
942#define HT_FBK_CFG1_HTMCS9FBK FIELD32(0x000000f0)
943#define HT_FBK_CFG1_HTMCS10FBK FIELD32(0x00000f00)
944#define HT_FBK_CFG1_HTMCS11FBK FIELD32(0x0000f000)
945#define HT_FBK_CFG1_HTMCS12FBK FIELD32(0x000f0000)
946#define HT_FBK_CFG1_HTMCS13FBK FIELD32(0x00f00000)
947#define HT_FBK_CFG1_HTMCS14FBK FIELD32(0x0f000000)
948#define HT_FBK_CFG1_HTMCS15FBK FIELD32(0xf0000000)
949
950/*
951 * LG_FBK_CFG0:
952 */
953#define LG_FBK_CFG0 0x135c
954#define LG_FBK_CFG0_OFDMMCS0FBK FIELD32(0x0000000f)
955#define LG_FBK_CFG0_OFDMMCS1FBK FIELD32(0x000000f0)
956#define LG_FBK_CFG0_OFDMMCS2FBK FIELD32(0x00000f00)
957#define LG_FBK_CFG0_OFDMMCS3FBK FIELD32(0x0000f000)
958#define LG_FBK_CFG0_OFDMMCS4FBK FIELD32(0x000f0000)
959#define LG_FBK_CFG0_OFDMMCS5FBK FIELD32(0x00f00000)
960#define LG_FBK_CFG0_OFDMMCS6FBK FIELD32(0x0f000000)
961#define LG_FBK_CFG0_OFDMMCS7FBK FIELD32(0xf0000000)
962
963/*
964 * LG_FBK_CFG1:
965 */
966#define LG_FBK_CFG1 0x1360
967#define LG_FBK_CFG0_CCKMCS0FBK FIELD32(0x0000000f)
968#define LG_FBK_CFG0_CCKMCS1FBK FIELD32(0x000000f0)
969#define LG_FBK_CFG0_CCKMCS2FBK FIELD32(0x00000f00)
970#define LG_FBK_CFG0_CCKMCS3FBK FIELD32(0x0000f000)
971
972/*
973 * CCK_PROT_CFG: CCK Protection
974 * PROTECT_RATE: Protection control frame rate for CCK TX(RTS/CTS/CFEnd)
975 * PROTECT_CTRL: Protection control frame type for CCK TX
976 * 0:none, 1:RTS/CTS, 2:CTS-to-self
977 * PROTECT_NAV: TXOP protection type for CCK TX
978 * 0:none, 1:ShortNAVprotect, 2:LongNAVProtect
979 * TX_OP_ALLOW_CCK: CCK TXOP allowance, 0:disallow
980 * TX_OP_ALLOW_OFDM: CCK TXOP allowance, 0:disallow
981 * TX_OP_ALLOW_MM20: CCK TXOP allowance, 0:disallow
982 * TX_OP_ALLOW_MM40: CCK TXOP allowance, 0:disallow
983 * TX_OP_ALLOW_GF20: CCK TXOP allowance, 0:disallow
984 * TX_OP_ALLOW_GF40: CCK TXOP allowance, 0:disallow
985 * RTS_TH_EN: RTS threshold enable on CCK TX
986 */
987#define CCK_PROT_CFG 0x1364
988#define CCK_PROT_CFG_PROTECT_RATE FIELD32(0x0000ffff)
989#define CCK_PROT_CFG_PROTECT_CTRL FIELD32(0x00030000)
990#define CCK_PROT_CFG_PROTECT_NAV FIELD32(0x000c0000)
991#define CCK_PROT_CFG_TX_OP_ALLOW_CCK FIELD32(0x00100000)
992#define CCK_PROT_CFG_TX_OP_ALLOW_OFDM FIELD32(0x00200000)
993#define CCK_PROT_CFG_TX_OP_ALLOW_MM20 FIELD32(0x00400000)
994#define CCK_PROT_CFG_TX_OP_ALLOW_MM40 FIELD32(0x00800000)
995#define CCK_PROT_CFG_TX_OP_ALLOW_GF20 FIELD32(0x01000000)
996#define CCK_PROT_CFG_TX_OP_ALLOW_GF40 FIELD32(0x02000000)
997#define CCK_PROT_CFG_RTS_TH_EN FIELD32(0x04000000)
998
999/*
1000 * OFDM_PROT_CFG: OFDM Protection
1001 */
1002#define OFDM_PROT_CFG 0x1368
1003#define OFDM_PROT_CFG_PROTECT_RATE FIELD32(0x0000ffff)
1004#define OFDM_PROT_CFG_PROTECT_CTRL FIELD32(0x00030000)
1005#define OFDM_PROT_CFG_PROTECT_NAV FIELD32(0x000c0000)
1006#define OFDM_PROT_CFG_TX_OP_ALLOW_CCK FIELD32(0x00100000)
1007#define OFDM_PROT_CFG_TX_OP_ALLOW_OFDM FIELD32(0x00200000)
1008#define OFDM_PROT_CFG_TX_OP_ALLOW_MM20 FIELD32(0x00400000)
1009#define OFDM_PROT_CFG_TX_OP_ALLOW_MM40 FIELD32(0x00800000)
1010#define OFDM_PROT_CFG_TX_OP_ALLOW_GF20 FIELD32(0x01000000)
1011#define OFDM_PROT_CFG_TX_OP_ALLOW_GF40 FIELD32(0x02000000)
1012#define OFDM_PROT_CFG_RTS_TH_EN FIELD32(0x04000000)
1013
1014/*
1015 * MM20_PROT_CFG: MM20 Protection
1016 */
1017#define MM20_PROT_CFG 0x136c
1018#define MM20_PROT_CFG_PROTECT_RATE FIELD32(0x0000ffff)
1019#define MM20_PROT_CFG_PROTECT_CTRL FIELD32(0x00030000)
1020#define MM20_PROT_CFG_PROTECT_NAV FIELD32(0x000c0000)
1021#define MM20_PROT_CFG_TX_OP_ALLOW_CCK FIELD32(0x00100000)
1022#define MM20_PROT_CFG_TX_OP_ALLOW_OFDM FIELD32(0x00200000)
1023#define MM20_PROT_CFG_TX_OP_ALLOW_MM20 FIELD32(0x00400000)
1024#define MM20_PROT_CFG_TX_OP_ALLOW_MM40 FIELD32(0x00800000)
1025#define MM20_PROT_CFG_TX_OP_ALLOW_GF20 FIELD32(0x01000000)
1026#define MM20_PROT_CFG_TX_OP_ALLOW_GF40 FIELD32(0x02000000)
1027#define MM20_PROT_CFG_RTS_TH_EN FIELD32(0x04000000)
1028
1029/*
1030 * MM40_PROT_CFG: MM40 Protection
1031 */
1032#define MM40_PROT_CFG 0x1370
1033#define MM40_PROT_CFG_PROTECT_RATE FIELD32(0x0000ffff)
1034#define MM40_PROT_CFG_PROTECT_CTRL FIELD32(0x00030000)
1035#define MM40_PROT_CFG_PROTECT_NAV FIELD32(0x000c0000)
1036#define MM40_PROT_CFG_TX_OP_ALLOW_CCK FIELD32(0x00100000)
1037#define MM40_PROT_CFG_TX_OP_ALLOW_OFDM FIELD32(0x00200000)
1038#define MM40_PROT_CFG_TX_OP_ALLOW_MM20 FIELD32(0x00400000)
1039#define MM40_PROT_CFG_TX_OP_ALLOW_MM40 FIELD32(0x00800000)
1040#define MM40_PROT_CFG_TX_OP_ALLOW_GF20 FIELD32(0x01000000)
1041#define MM40_PROT_CFG_TX_OP_ALLOW_GF40 FIELD32(0x02000000)
1042#define MM40_PROT_CFG_RTS_TH_EN FIELD32(0x04000000)
1043
1044/*
1045 * GF20_PROT_CFG: GF20 Protection
1046 */
1047#define GF20_PROT_CFG 0x1374
1048#define GF20_PROT_CFG_PROTECT_RATE FIELD32(0x0000ffff)
1049#define GF20_PROT_CFG_PROTECT_CTRL FIELD32(0x00030000)
1050#define GF20_PROT_CFG_PROTECT_NAV FIELD32(0x000c0000)
1051#define GF20_PROT_CFG_TX_OP_ALLOW_CCK FIELD32(0x00100000)
1052#define GF20_PROT_CFG_TX_OP_ALLOW_OFDM FIELD32(0x00200000)
1053#define GF20_PROT_CFG_TX_OP_ALLOW_MM20 FIELD32(0x00400000)
1054#define GF20_PROT_CFG_TX_OP_ALLOW_MM40 FIELD32(0x00800000)
1055#define GF20_PROT_CFG_TX_OP_ALLOW_GF20 FIELD32(0x01000000)
1056#define GF20_PROT_CFG_TX_OP_ALLOW_GF40 FIELD32(0x02000000)
1057#define GF20_PROT_CFG_RTS_TH_EN FIELD32(0x04000000)
1058
1059/*
1060 * GF40_PROT_CFG: GF40 Protection
1061 */
1062#define GF40_PROT_CFG 0x1378
1063#define GF40_PROT_CFG_PROTECT_RATE FIELD32(0x0000ffff)
1064#define GF40_PROT_CFG_PROTECT_CTRL FIELD32(0x00030000)
1065#define GF40_PROT_CFG_PROTECT_NAV FIELD32(0x000c0000)
1066#define GF40_PROT_CFG_TX_OP_ALLOW_CCK FIELD32(0x00100000)
1067#define GF40_PROT_CFG_TX_OP_ALLOW_OFDM FIELD32(0x00200000)
1068#define GF40_PROT_CFG_TX_OP_ALLOW_MM20 FIELD32(0x00400000)
1069#define GF40_PROT_CFG_TX_OP_ALLOW_MM40 FIELD32(0x00800000)
1070#define GF40_PROT_CFG_TX_OP_ALLOW_GF20 FIELD32(0x01000000)
1071#define GF40_PROT_CFG_TX_OP_ALLOW_GF40 FIELD32(0x02000000)
1072#define GF40_PROT_CFG_RTS_TH_EN FIELD32(0x04000000)
1073
1074/*
1075 * EXP_CTS_TIME:
1076 */
1077#define EXP_CTS_TIME 0x137c
1078
1079/*
1080 * EXP_ACK_TIME:
1081 */
1082#define EXP_ACK_TIME 0x1380
1083
1084/*
1085 * RX_FILTER_CFG: RX configuration register.
1086 */
1087#define RX_FILTER_CFG 0x1400
1088#define RX_FILTER_CFG_DROP_CRC_ERROR FIELD32(0x00000001)
1089#define RX_FILTER_CFG_DROP_PHY_ERROR FIELD32(0x00000002)
1090#define RX_FILTER_CFG_DROP_NOT_TO_ME FIELD32(0x00000004)
1091#define RX_FILTER_CFG_DROP_NOT_MY_BSSD FIELD32(0x00000008)
1092#define RX_FILTER_CFG_DROP_VER_ERROR FIELD32(0x00000010)
1093#define RX_FILTER_CFG_DROP_MULTICAST FIELD32(0x00000020)
1094#define RX_FILTER_CFG_DROP_BROADCAST FIELD32(0x00000040)
1095#define RX_FILTER_CFG_DROP_DUPLICATE FIELD32(0x00000080)
1096#define RX_FILTER_CFG_DROP_CF_END_ACK FIELD32(0x00000100)
1097#define RX_FILTER_CFG_DROP_CF_END FIELD32(0x00000200)
1098#define RX_FILTER_CFG_DROP_ACK FIELD32(0x00000400)
1099#define RX_FILTER_CFG_DROP_CTS FIELD32(0x00000800)
1100#define RX_FILTER_CFG_DROP_RTS FIELD32(0x00001000)
1101#define RX_FILTER_CFG_DROP_PSPOLL FIELD32(0x00002000)
1102#define RX_FILTER_CFG_DROP_BA FIELD32(0x00004000)
1103#define RX_FILTER_CFG_DROP_BAR FIELD32(0x00008000)
1104#define RX_FILTER_CFG_DROP_CNTL FIELD32(0x00010000)
1105
1106/*
1107 * AUTO_RSP_CFG:
1108 * AUTORESPONDER: 0: disable, 1: enable
1109 * BAC_ACK_POLICY: 0:long, 1:short preamble
1110 * CTS_40_MMODE: Response CTS 40MHz duplicate mode
1111 * CTS_40_MREF: Response CTS 40MHz duplicate mode
1112 * AR_PREAMBLE: Auto responder preamble 0:long, 1:short preamble
1113 * DUAL_CTS_EN: Power bit value in control frame
1114 * ACK_CTS_PSM_BIT:Power bit value in control frame
1115 */
1116#define AUTO_RSP_CFG 0x1404
1117#define AUTO_RSP_CFG_AUTORESPONDER FIELD32(0x00000001)
1118#define AUTO_RSP_CFG_BAC_ACK_POLICY FIELD32(0x00000002)
1119#define AUTO_RSP_CFG_CTS_40_MMODE FIELD32(0x00000004)
1120#define AUTO_RSP_CFG_CTS_40_MREF FIELD32(0x00000008)
1121#define AUTO_RSP_CFG_AR_PREAMBLE FIELD32(0x00000010)
1122#define AUTO_RSP_CFG_DUAL_CTS_EN FIELD32(0x00000040)
1123#define AUTO_RSP_CFG_ACK_CTS_PSM_BIT FIELD32(0x00000080)
1124
1125/*
1126 * LEGACY_BASIC_RATE:
1127 */
1128#define LEGACY_BASIC_RATE 0x1408
1129
1130/*
1131 * HT_BASIC_RATE:
1132 */
1133#define HT_BASIC_RATE 0x140c
1134
1135/*
1136 * HT_CTRL_CFG:
1137 */
1138#define HT_CTRL_CFG 0x1410
1139
1140/*
1141 * SIFS_COST_CFG:
1142 */
1143#define SIFS_COST_CFG 0x1414
1144
1145/*
1146 * RX_PARSER_CFG:
1147 * Set NAV for all received frames
1148 */
1149#define RX_PARSER_CFG 0x1418
1150
1151/*
1152 * TX_SEC_CNT0:
1153 */
1154#define TX_SEC_CNT0 0x1500
1155
1156/*
1157 * RX_SEC_CNT0:
1158 */
1159#define RX_SEC_CNT0 0x1504
1160
1161/*
1162 * CCMP_FC_MUTE:
1163 */
1164#define CCMP_FC_MUTE 0x1508
1165
1166/*
1167 * TXOP_HLDR_ADDR0:
1168 */
1169#define TXOP_HLDR_ADDR0 0x1600
1170
1171/*
1172 * TXOP_HLDR_ADDR1:
1173 */
1174#define TXOP_HLDR_ADDR1 0x1604
1175
1176/*
1177 * TXOP_HLDR_ET:
1178 */
1179#define TXOP_HLDR_ET 0x1608
1180
1181/*
1182 * QOS_CFPOLL_RA_DW0:
1183 */
1184#define QOS_CFPOLL_RA_DW0 0x160c
1185
1186/*
1187 * QOS_CFPOLL_RA_DW1:
1188 */
1189#define QOS_CFPOLL_RA_DW1 0x1610
1190
1191/*
1192 * QOS_CFPOLL_QC:
1193 */
1194#define QOS_CFPOLL_QC 0x1614
1195
1196/*
1197 * RX_STA_CNT0: RX PLCP error count & RX CRC error count
1198 */
1199#define RX_STA_CNT0 0x1700
1200#define RX_STA_CNT0_CRC_ERR FIELD32(0x0000ffff)
1201#define RX_STA_CNT0_PHY_ERR FIELD32(0xffff0000)
1202
1203/*
1204 * RX_STA_CNT1: RX False CCA count & RX LONG frame count
1205 */
1206#define RX_STA_CNT1 0x1704
1207#define RX_STA_CNT1_FALSE_CCA FIELD32(0x0000ffff)
1208#define RX_STA_CNT1_PLCP_ERR FIELD32(0xffff0000)
1209
1210/*
1211 * RX_STA_CNT2:
1212 */
1213#define RX_STA_CNT2 0x1708
1214#define RX_STA_CNT2_RX_DUPLI_COUNT FIELD32(0x0000ffff)
1215#define RX_STA_CNT2_RX_FIFO_OVERFLOW FIELD32(0xffff0000)
1216
1217/*
1218 * TX_STA_CNT0: TX Beacon count
1219 */
1220#define TX_STA_CNT0 0x170c
1221#define TX_STA_CNT0_TX_FAIL_COUNT FIELD32(0x0000ffff)
1222#define TX_STA_CNT0_TX_BEACON_COUNT FIELD32(0xffff0000)
1223
1224/*
1225 * TX_STA_CNT1: TX tx count
1226 */
1227#define TX_STA_CNT1 0x1710
1228#define TX_STA_CNT1_TX_SUCCESS FIELD32(0x0000ffff)
1229#define TX_STA_CNT1_TX_RETRANSMIT FIELD32(0xffff0000)
1230
1231/*
1232 * TX_STA_CNT2: TX tx count
1233 */
1234#define TX_STA_CNT2 0x1714
1235#define TX_STA_CNT2_TX_ZERO_LEN_COUNT FIELD32(0x0000ffff)
1236#define TX_STA_CNT2_TX_UNDER_FLOW_COUNT FIELD32(0xffff0000)
1237
1238/*
1239 * TX_STA_FIFO: TX Result for specific PID status fifo register
1240 */
1241#define TX_STA_FIFO 0x1718
1242#define TX_STA_FIFO_VALID FIELD32(0x00000001)
1243#define TX_STA_FIFO_PID_TYPE FIELD32(0x0000001e)
1244#define TX_STA_FIFO_TX_SUCCESS FIELD32(0x00000020)
1245#define TX_STA_FIFO_TX_AGGRE FIELD32(0x00000040)
1246#define TX_STA_FIFO_TX_ACK_REQUIRED FIELD32(0x00000080)
1247#define TX_STA_FIFO_WCID FIELD32(0x0000ff00)
1248#define TX_STA_FIFO_MCS FIELD32(0x007f0000)
1249#define TX_STA_FIFO_PHYMODE FIELD32(0xc0000000)
1250
1251/*
1252 * TX_AGG_CNT: Debug counter
1253 */
1254#define TX_AGG_CNT 0x171c
1255#define TX_AGG_CNT_NON_AGG_TX_COUNT FIELD32(0x0000ffff)
1256#define TX_AGG_CNT_AGG_TX_COUNT FIELD32(0xffff0000)
1257
1258/*
1259 * TX_AGG_CNT0:
1260 */
1261#define TX_AGG_CNT0 0x1720
1262#define TX_AGG_CNT0_AGG_SIZE_1_COUNT FIELD32(0x0000ffff)
1263#define TX_AGG_CNT0_AGG_SIZE_2_COUNT FIELD32(0xffff0000)
1264
1265/*
1266 * TX_AGG_CNT1:
1267 */
1268#define TX_AGG_CNT1 0x1724
1269#define TX_AGG_CNT1_AGG_SIZE_3_COUNT FIELD32(0x0000ffff)
1270#define TX_AGG_CNT1_AGG_SIZE_4_COUNT FIELD32(0xffff0000)
1271
1272/*
1273 * TX_AGG_CNT2:
1274 */
1275#define TX_AGG_CNT2 0x1728
1276#define TX_AGG_CNT2_AGG_SIZE_5_COUNT FIELD32(0x0000ffff)
1277#define TX_AGG_CNT2_AGG_SIZE_6_COUNT FIELD32(0xffff0000)
1278
1279/*
1280 * TX_AGG_CNT3:
1281 */
1282#define TX_AGG_CNT3 0x172c
1283#define TX_AGG_CNT3_AGG_SIZE_7_COUNT FIELD32(0x0000ffff)
1284#define TX_AGG_CNT3_AGG_SIZE_8_COUNT FIELD32(0xffff0000)
1285
1286/*
1287 * TX_AGG_CNT4:
1288 */
1289#define TX_AGG_CNT4 0x1730
1290#define TX_AGG_CNT4_AGG_SIZE_9_COUNT FIELD32(0x0000ffff)
1291#define TX_AGG_CNT4_AGG_SIZE_10_COUNT FIELD32(0xffff0000)
1292
1293/*
1294 * TX_AGG_CNT5:
1295 */
1296#define TX_AGG_CNT5 0x1734
1297#define TX_AGG_CNT5_AGG_SIZE_11_COUNT FIELD32(0x0000ffff)
1298#define TX_AGG_CNT5_AGG_SIZE_12_COUNT FIELD32(0xffff0000)
1299
1300/*
1301 * TX_AGG_CNT6:
1302 */
1303#define TX_AGG_CNT6 0x1738
1304#define TX_AGG_CNT6_AGG_SIZE_13_COUNT FIELD32(0x0000ffff)
1305#define TX_AGG_CNT6_AGG_SIZE_14_COUNT FIELD32(0xffff0000)
1306
1307/*
1308 * TX_AGG_CNT7:
1309 */
1310#define TX_AGG_CNT7 0x173c
1311#define TX_AGG_CNT7_AGG_SIZE_15_COUNT FIELD32(0x0000ffff)
1312#define TX_AGG_CNT7_AGG_SIZE_16_COUNT FIELD32(0xffff0000)
1313
1314/*
1315 * MPDU_DENSITY_CNT:
1316 * TX_ZERO_DEL: TX zero length delimiter count
1317 * RX_ZERO_DEL: RX zero length delimiter count
1318 */
1319#define MPDU_DENSITY_CNT 0x1740
1320#define MPDU_DENSITY_CNT_TX_ZERO_DEL FIELD32(0x0000ffff)
1321#define MPDU_DENSITY_CNT_RX_ZERO_DEL FIELD32(0xffff0000)
1322
1323/*
1324 * Security key table memory.
1325 * MAC_WCID_BASE: 8-bytes (use only 6 bytes) * 256 entry
1326 * PAIRWISE_KEY_TABLE_BASE: 32-byte * 256 entry
1327 * MAC_IVEIV_TABLE_BASE: 8-byte * 256-entry
1328 * MAC_WCID_ATTRIBUTE_BASE: 4-byte * 256-entry
1329 * SHARED_KEY_TABLE_BASE: 32 bytes * 32-entry
1330 * SHARED_KEY_MODE_BASE: 4 bits * 32-entry
1331 */
1332#define MAC_WCID_BASE 0x1800
1333#define PAIRWISE_KEY_TABLE_BASE 0x4000
1334#define MAC_IVEIV_TABLE_BASE 0x6000
1335#define MAC_WCID_ATTRIBUTE_BASE 0x6800
1336#define SHARED_KEY_TABLE_BASE 0x6c00
1337#define SHARED_KEY_MODE_BASE 0x7000
1338
1339#define MAC_WCID_ENTRY(__idx) \
1340 ( MAC_WCID_BASE + ((__idx) * sizeof(struct mac_wcid_entry)) )
1341#define PAIRWISE_KEY_ENTRY(__idx) \
1342 ( PAIRWISE_KEY_TABLE_BASE + ((__idx) * sizeof(struct hw_key_entry)) )
1343#define MAC_IVEIV_ENTRY(__idx) \
1344 ( MAC_IVEIV_TABLE_BASE + ((__idx) & sizeof(struct mac_iveiv_entry)) )
1345#define MAC_WCID_ATTR_ENTRY(__idx) \
1346 ( MAC_WCID_ATTRIBUTE_BASE + ((__idx) * sizeof(u32)) )
1347#define SHARED_KEY_ENTRY(__idx) \
1348 ( SHARED_KEY_TABLE_BASE + ((__idx) * sizeof(struct hw_key_entry)) )
1349#define SHARED_KEY_MODE_ENTRY(__idx) \
1350 ( SHARED_KEY_MODE_BASE + ((__idx) * sizeof(u32)) )
1351
1352struct mac_wcid_entry {
1353 u8 mac[6];
1354 u8 reserved[2];
1355} __attribute__ ((packed));
1356
1357struct hw_key_entry {
1358 u8 key[16];
1359 u8 tx_mic[8];
1360 u8 rx_mic[8];
1361} __attribute__ ((packed));
1362
1363struct mac_iveiv_entry {
1364 u8 iv[8];
1365} __attribute__ ((packed));
1366
1367/*
1368 * MAC_WCID_ATTRIBUTE:
1369 */
1370#define MAC_WCID_ATTRIBUTE_KEYTAB FIELD32(0x00000001)
1371#define MAC_WCID_ATTRIBUTE_CIPHER FIELD32(0x0000000e)
1372#define MAC_WCID_ATTRIBUTE_BSS_IDX FIELD32(0x00000070)
1373#define MAC_WCID_ATTRIBUTE_RX_WIUDF FIELD32(0x00000380)
1374
1375/*
1376 * SHARED_KEY_MODE:
1377 */
1378#define SHARED_KEY_MODE_BSS0_KEY0 FIELD32(0x00000007)
1379#define SHARED_KEY_MODE_BSS0_KEY1 FIELD32(0x00000070)
1380#define SHARED_KEY_MODE_BSS0_KEY2 FIELD32(0x00000700)
1381#define SHARED_KEY_MODE_BSS0_KEY3 FIELD32(0x00007000)
1382#define SHARED_KEY_MODE_BSS1_KEY0 FIELD32(0x00070000)
1383#define SHARED_KEY_MODE_BSS1_KEY1 FIELD32(0x00700000)
1384#define SHARED_KEY_MODE_BSS1_KEY2 FIELD32(0x07000000)
1385#define SHARED_KEY_MODE_BSS1_KEY3 FIELD32(0x70000000)
1386
1387/*
1388 * HOST-MCU communication
1389 */
1390
1391/*
1392 * H2M_MAILBOX_CSR: Host-to-MCU Mailbox.
1393 */
1394#define H2M_MAILBOX_CSR 0x7010
1395#define H2M_MAILBOX_CSR_ARG0 FIELD32(0x000000ff)
1396#define H2M_MAILBOX_CSR_ARG1 FIELD32(0x0000ff00)
1397#define H2M_MAILBOX_CSR_CMD_TOKEN FIELD32(0x00ff0000)
1398#define H2M_MAILBOX_CSR_OWNER FIELD32(0xff000000)
1399
1400/*
1401 * H2M_MAILBOX_CID:
1402 */
1403#define H2M_MAILBOX_CID 0x7014
1404#define H2M_MAILBOX_CID_CMD0 FIELD32(0x000000ff)
1405#define H2M_MAILBOX_CID_CMD1 FIELD32(0x0000ff00)
1406#define H2M_MAILBOX_CID_CMD2 FIELD32(0x00ff0000)
1407#define H2M_MAILBOX_CID_CMD3 FIELD32(0xff000000)
1408
1409/*
1410 * H2M_MAILBOX_STATUS:
1411 */
1412#define H2M_MAILBOX_STATUS 0x701c
1413
1414/*
1415 * H2M_INT_SRC:
1416 */
1417#define H2M_INT_SRC 0x7024
1418
1419/*
1420 * H2M_BBP_AGENT:
1421 */
1422#define H2M_BBP_AGENT 0x7028
1423
1424/*
1425 * MCU_LEDCS: LED control for MCU Mailbox.
1426 */
1427#define MCU_LEDCS_LED_MODE FIELD8(0x1f)
1428#define MCU_LEDCS_POLARITY FIELD8(0x01)
1429
1430/*
1431 * HW_CS_CTS_BASE:
1432 * Carrier-sense CTS frame base address.
1433 * It's where mac stores carrier-sense frame for carrier-sense function.
1434 */
1435#define HW_CS_CTS_BASE 0x7700
1436
1437/*
1438 * HW_DFS_CTS_BASE:
1439 * FS CTS frame base address. It's where mac stores CTS frame for DFS.
1440 */
1441#define HW_DFS_CTS_BASE 0x7780
1442
1443/*
1444 * TXRX control registers - base address 0x3000
1445 */
1446
1447/*
1448 * TXRX_CSR1:
1449 * rt2860b UNKNOWN reg use R/O Reg Addr 0x77d0 first..
1450 */
1451#define TXRX_CSR1 0x77d0
1452
1453/*
1454 * HW_DEBUG_SETTING_BASE:
1455 * since NULL frame won't be that long (256 byte)
1456 * We steal 16 tail bytes to save debugging settings
1457 */
1458#define HW_DEBUG_SETTING_BASE 0x77f0
1459#define HW_DEBUG_SETTING_BASE2 0x7770
1460
1461/*
1462 * HW_BEACON_BASE
1463 * In order to support maximum 8 MBSS and its maximum length
1464 * is 512 bytes for each beacon
1465 * Three section discontinue memory segments will be used.
1466 * 1. The original region for BCN 0~3
1467 * 2. Extract memory from FCE table for BCN 4~5
1468 * 3. Extract memory from Pair-wise key table for BCN 6~7
1469 * It occupied those memory of wcid 238~253 for BCN 6
1470 * and wcid 222~237 for BCN 7
1471 *
1472 * IMPORTANT NOTE: Not sure why legacy driver does this,
1473 * but HW_BEACON_BASE7 is 0x0200 bytes below HW_BEACON_BASE6.
1474 */
1475#define HW_BEACON_BASE0 0x7800
1476#define HW_BEACON_BASE1 0x7a00
1477#define HW_BEACON_BASE2 0x7c00
1478#define HW_BEACON_BASE3 0x7e00
1479#define HW_BEACON_BASE4 0x7200
1480#define HW_BEACON_BASE5 0x7400
1481#define HW_BEACON_BASE6 0x5dc0
1482#define HW_BEACON_BASE7 0x5bc0
1483
1484#define HW_BEACON_OFFSET(__index) \
1485 ( ((__index) < 4) ? ( HW_BEACON_BASE0 + (__index * 0x0200) ) : \
1486 (((__index) < 6) ? ( HW_BEACON_BASE4 + ((__index - 4) * 0x0200) ) : \
1487 (HW_BEACON_BASE6 - ((__index - 6) * 0x0200))) )
1488
1489/*
1490 * 8051 firmware image. 87 * 8051 firmware image.
1491 */ 88 */
1492#define FIRMWARE_RT2860 "rt2860.bin" 89#define FIRMWARE_RT2860 "rt2860.bin"
1493#define FIRMWARE_IMAGE_BASE 0x2000 90#define FIRMWARE_IMAGE_BASE 0x2000
1494 91
1495/* 92/*
1496 * BBP registers.
1497 * The wordsize of the BBP is 8 bits.
1498 */
1499
1500/*
1501 * BBP 1: TX Antenna
1502 */
1503#define BBP1_TX_POWER FIELD8(0x07)
1504#define BBP1_TX_ANTENNA FIELD8(0x18)
1505
1506/*
1507 * BBP 3: RX Antenna
1508 */
1509#define BBP3_RX_ANTENNA FIELD8(0x18)
1510#define BBP3_HT40_PLUS FIELD8(0x20)
1511
1512/*
1513 * BBP 4: Bandwidth
1514 */
1515#define BBP4_TX_BF FIELD8(0x01)
1516#define BBP4_BANDWIDTH FIELD8(0x18)
1517
1518/*
1519 * RFCSR registers
1520 * The wordsize of the RFCSR is 8 bits.
1521 */
1522
1523/*
1524 * RFCSR 6:
1525 */
1526#define RFCSR6_R FIELD8(0x03)
1527
1528/*
1529 * RFCSR 7:
1530 */
1531#define RFCSR7_RF_TUNING FIELD8(0x01)
1532
1533/*
1534 * RFCSR 12:
1535 */
1536#define RFCSR12_TX_POWER FIELD8(0x1f)
1537
1538/*
1539 * RFCSR 22:
1540 */
1541#define RFCSR22_BASEBAND_LOOPBACK FIELD8(0x01)
1542
1543/*
1544 * RFCSR 23:
1545 */
1546#define RFCSR23_FREQ_OFFSET FIELD8(0x7f)
1547
1548/*
1549 * RFCSR 30:
1550 */
1551#define RFCSR30_RF_CALIBRATION FIELD8(0x80)
1552
1553/*
1554 * RF registers
1555 */
1556
1557/*
1558 * RF 2
1559 */
1560#define RF2_ANTENNA_RX2 FIELD32(0x00000040)
1561#define RF2_ANTENNA_TX1 FIELD32(0x00004000)
1562#define RF2_ANTENNA_RX1 FIELD32(0x00020000)
1563
1564/*
1565 * RF 3
1566 */
1567#define RF3_TXPOWER_G FIELD32(0x00003e00)
1568#define RF3_TXPOWER_A_7DBM_BOOST FIELD32(0x00000200)
1569#define RF3_TXPOWER_A FIELD32(0x00003c00)
1570
1571/*
1572 * RF 4
1573 */
1574#define RF4_TXPOWER_G FIELD32(0x000007c0)
1575#define RF4_TXPOWER_A_7DBM_BOOST FIELD32(0x00000040)
1576#define RF4_TXPOWER_A FIELD32(0x00000780)
1577#define RF4_FREQ_OFFSET FIELD32(0x001f8000)
1578#define RF4_HT40 FIELD32(0x00200000)
1579
1580/*
1581 * EEPROM content.
1582 * The wordsize of the EEPROM is 16 bits.
1583 */
1584
1585/*
1586 * EEPROM Version
1587 */
1588#define EEPROM_VERSION 0x0001
1589#define EEPROM_VERSION_FAE FIELD16(0x00ff)
1590#define EEPROM_VERSION_VERSION FIELD16(0xff00)
1591
1592/*
1593 * HW MAC address.
1594 */
1595#define EEPROM_MAC_ADDR_0 0x0002
1596#define EEPROM_MAC_ADDR_BYTE0 FIELD16(0x00ff)
1597#define EEPROM_MAC_ADDR_BYTE1 FIELD16(0xff00)
1598#define EEPROM_MAC_ADDR_1 0x0003
1599#define EEPROM_MAC_ADDR_BYTE2 FIELD16(0x00ff)
1600#define EEPROM_MAC_ADDR_BYTE3 FIELD16(0xff00)
1601#define EEPROM_MAC_ADDR_2 0x0004
1602#define EEPROM_MAC_ADDR_BYTE4 FIELD16(0x00ff)
1603#define EEPROM_MAC_ADDR_BYTE5 FIELD16(0xff00)
1604
1605/*
1606 * EEPROM ANTENNA config
1607 * RXPATH: 1: 1R, 2: 2R, 3: 3R
1608 * TXPATH: 1: 1T, 2: 2T
1609 */
1610#define EEPROM_ANTENNA 0x001a
1611#define EEPROM_ANTENNA_RXPATH FIELD16(0x000f)
1612#define EEPROM_ANTENNA_TXPATH FIELD16(0x00f0)
1613#define EEPROM_ANTENNA_RF_TYPE FIELD16(0x0f00)
1614
1615/*
1616 * EEPROM NIC config
1617 * CARDBUS_ACCEL: 0 - enable, 1 - disable
1618 */
1619#define EEPROM_NIC 0x001b
1620#define EEPROM_NIC_HW_RADIO FIELD16(0x0001)
1621#define EEPROM_NIC_DYNAMIC_TX_AGC FIELD16(0x0002)
1622#define EEPROM_NIC_EXTERNAL_LNA_BG FIELD16(0x0004)
1623#define EEPROM_NIC_EXTERNAL_LNA_A FIELD16(0x0008)
1624#define EEPROM_NIC_CARDBUS_ACCEL FIELD16(0x0010)
1625#define EEPROM_NIC_BW40M_SB_BG FIELD16(0x0020)
1626#define EEPROM_NIC_BW40M_SB_A FIELD16(0x0040)
1627#define EEPROM_NIC_WPS_PBC FIELD16(0x0080)
1628#define EEPROM_NIC_BW40M_BG FIELD16(0x0100)
1629#define EEPROM_NIC_BW40M_A FIELD16(0x0200)
1630
1631/*
1632 * EEPROM frequency
1633 */
1634#define EEPROM_FREQ 0x001d
1635#define EEPROM_FREQ_OFFSET FIELD16(0x00ff)
1636#define EEPROM_FREQ_LED_MODE FIELD16(0x7f00)
1637#define EEPROM_FREQ_LED_POLARITY FIELD16(0x1000)
1638
1639/*
1640 * EEPROM LED
1641 * POLARITY_RDY_G: Polarity RDY_G setting.
1642 * POLARITY_RDY_A: Polarity RDY_A setting.
1643 * POLARITY_ACT: Polarity ACT setting.
1644 * POLARITY_GPIO_0: Polarity GPIO0 setting.
1645 * POLARITY_GPIO_1: Polarity GPIO1 setting.
1646 * POLARITY_GPIO_2: Polarity GPIO2 setting.
1647 * POLARITY_GPIO_3: Polarity GPIO3 setting.
1648 * POLARITY_GPIO_4: Polarity GPIO4 setting.
1649 * LED_MODE: Led mode.
1650 */
1651#define EEPROM_LED1 0x001e
1652#define EEPROM_LED2 0x001f
1653#define EEPROM_LED3 0x0020
1654#define EEPROM_LED_POLARITY_RDY_BG FIELD16(0x0001)
1655#define EEPROM_LED_POLARITY_RDY_A FIELD16(0x0002)
1656#define EEPROM_LED_POLARITY_ACT FIELD16(0x0004)
1657#define EEPROM_LED_POLARITY_GPIO_0 FIELD16(0x0008)
1658#define EEPROM_LED_POLARITY_GPIO_1 FIELD16(0x0010)
1659#define EEPROM_LED_POLARITY_GPIO_2 FIELD16(0x0020)
1660#define EEPROM_LED_POLARITY_GPIO_3 FIELD16(0x0040)
1661#define EEPROM_LED_POLARITY_GPIO_4 FIELD16(0x0080)
1662#define EEPROM_LED_LED_MODE FIELD16(0x1f00)
1663
1664/*
1665 * EEPROM LNA
1666 */
1667#define EEPROM_LNA 0x0022
1668#define EEPROM_LNA_BG FIELD16(0x00ff)
1669#define EEPROM_LNA_A0 FIELD16(0xff00)
1670
1671/*
1672 * EEPROM RSSI BG offset
1673 */
1674#define EEPROM_RSSI_BG 0x0023
1675#define EEPROM_RSSI_BG_OFFSET0 FIELD16(0x00ff)
1676#define EEPROM_RSSI_BG_OFFSET1 FIELD16(0xff00)
1677
1678/*
1679 * EEPROM RSSI BG2 offset
1680 */
1681#define EEPROM_RSSI_BG2 0x0024
1682#define EEPROM_RSSI_BG2_OFFSET2 FIELD16(0x00ff)
1683#define EEPROM_RSSI_BG2_LNA_A1 FIELD16(0xff00)
1684
1685/*
1686 * EEPROM RSSI A offset
1687 */
1688#define EEPROM_RSSI_A 0x0025
1689#define EEPROM_RSSI_A_OFFSET0 FIELD16(0x00ff)
1690#define EEPROM_RSSI_A_OFFSET1 FIELD16(0xff00)
1691
1692/*
1693 * EEPROM RSSI A2 offset
1694 */
1695#define EEPROM_RSSI_A2 0x0026
1696#define EEPROM_RSSI_A2_OFFSET2 FIELD16(0x00ff)
1697#define EEPROM_RSSI_A2_LNA_A2 FIELD16(0xff00)
1698
1699/*
1700 * EEPROM TXpower delta: 20MHZ AND 40 MHZ use different power.
1701 * This is delta in 40MHZ.
1702 * VALUE: Tx Power dalta value (MAX=4)
1703 * TYPE: 1: Plus the delta value, 0: minus the delta value
1704 * TXPOWER: Enable:
1705 */
1706#define EEPROM_TXPOWER_DELTA 0x0028
1707#define EEPROM_TXPOWER_DELTA_VALUE FIELD16(0x003f)
1708#define EEPROM_TXPOWER_DELTA_TYPE FIELD16(0x0040)
1709#define EEPROM_TXPOWER_DELTA_TXPOWER FIELD16(0x0080)
1710
1711/*
1712 * EEPROM TXPOWER 802.11BG
1713 */
1714#define EEPROM_TXPOWER_BG1 0x0029
1715#define EEPROM_TXPOWER_BG2 0x0030
1716#define EEPROM_TXPOWER_BG_SIZE 7
1717#define EEPROM_TXPOWER_BG_1 FIELD16(0x00ff)
1718#define EEPROM_TXPOWER_BG_2 FIELD16(0xff00)
1719
1720/*
1721 * EEPROM TXPOWER 802.11A
1722 */
1723#define EEPROM_TXPOWER_A1 0x003c
1724#define EEPROM_TXPOWER_A2 0x0053
1725#define EEPROM_TXPOWER_A_SIZE 6
1726#define EEPROM_TXPOWER_A_1 FIELD16(0x00ff)
1727#define EEPROM_TXPOWER_A_2 FIELD16(0xff00)
1728
1729/*
1730 * EEPROM TXpower byrate: 20MHZ power
1731 */
1732#define EEPROM_TXPOWER_BYRATE 0x006f
1733
1734/*
1735 * EEPROM BBP.
1736 */
1737#define EEPROM_BBP_START 0x0078
1738#define EEPROM_BBP_SIZE 16
1739#define EEPROM_BBP_VALUE FIELD16(0x00ff)
1740#define EEPROM_BBP_REG_ID FIELD16(0xff00)
1741
1742/*
1743 * MCU mailbox commands.
1744 */
1745#define MCU_SLEEP 0x30
1746#define MCU_WAKEUP 0x31
1747#define MCU_RADIO_OFF 0x35
1748#define MCU_CURRENT 0x36
1749#define MCU_LED 0x50
1750#define MCU_LED_STRENGTH 0x51
1751#define MCU_LED_1 0x52
1752#define MCU_LED_2 0x53
1753#define MCU_LED_3 0x54
1754#define MCU_RADAR 0x60
1755#define MCU_BOOT_SIGNAL 0x72
1756#define MCU_BBP_SIGNAL 0x80
1757#define MCU_POWER_SAVE 0x83
1758
1759/*
1760 * MCU mailbox tokens
1761 */
1762#define TOKEN_WAKUP 3
1763
1764/*
1765 * DMA descriptor defines. 93 * DMA descriptor defines.
1766 */ 94 */
1767#define TXD_DESC_SIZE ( 4 * sizeof(__le32) ) 95#define TXD_DESC_SIZE ( 4 * sizeof(__le32) )
1768#define TXWI_DESC_SIZE ( 4 * sizeof(__le32) )
1769#define RXD_DESC_SIZE ( 4 * sizeof(__le32) ) 96#define RXD_DESC_SIZE ( 4 * sizeof(__le32) )
1770#define RXWI_DESC_SIZE ( 4 * sizeof(__le32) )
1771 97
1772/* 98/*
1773 * TX descriptor format for TX, PRIO and Beacon Ring. 99 * TX descriptor format for TX, PRIO and Beacon Ring.
@@ -1806,52 +132,6 @@ struct mac_iveiv_entry {
1806#define TXD_W3_ICO FIELD32(0x80000000) 132#define TXD_W3_ICO FIELD32(0x80000000)
1807 133
1808/* 134/*
1809 * TX WI structure
1810 */
1811
1812/*
1813 * Word0
1814 * FRAG: 1 To inform TKIP engine this is a fragment.
1815 * MIMO_PS: The remote peer is in dynamic MIMO-PS mode
1816 * TX_OP: 0:HT TXOP rule , 1:PIFS TX ,2:Backoff, 3:sifs
1817 * BW: Channel bandwidth 20MHz or 40 MHz
1818 * STBC: 1: STBC support MCS =0-7, 2,3 : RESERVED
1819 */
1820#define TXWI_W0_FRAG FIELD32(0x00000001)
1821#define TXWI_W0_MIMO_PS FIELD32(0x00000002)
1822#define TXWI_W0_CF_ACK FIELD32(0x00000004)
1823#define TXWI_W0_TS FIELD32(0x00000008)
1824#define TXWI_W0_AMPDU FIELD32(0x00000010)
1825#define TXWI_W0_MPDU_DENSITY FIELD32(0x000000e0)
1826#define TXWI_W0_TX_OP FIELD32(0x00000300)
1827#define TXWI_W0_MCS FIELD32(0x007f0000)
1828#define TXWI_W0_BW FIELD32(0x00800000)
1829#define TXWI_W0_SHORT_GI FIELD32(0x01000000)
1830#define TXWI_W0_STBC FIELD32(0x06000000)
1831#define TXWI_W0_IFS FIELD32(0x08000000)
1832#define TXWI_W0_PHYMODE FIELD32(0xc0000000)
1833
1834/*
1835 * Word1
1836 */
1837#define TXWI_W1_ACK FIELD32(0x00000001)
1838#define TXWI_W1_NSEQ FIELD32(0x00000002)
1839#define TXWI_W1_BW_WIN_SIZE FIELD32(0x000000fc)
1840#define TXWI_W1_WIRELESS_CLI_ID FIELD32(0x0000ff00)
1841#define TXWI_W1_MPDU_TOTAL_BYTE_COUNT FIELD32(0x0fff0000)
1842#define TXWI_W1_PACKETID FIELD32(0xf0000000)
1843
1844/*
1845 * Word2
1846 */
1847#define TXWI_W2_IV FIELD32(0xffffffff)
1848
1849/*
1850 * Word3
1851 */
1852#define TXWI_W3_EIV FIELD32(0xffffffff)
1853
1854/*
1855 * RX descriptor format for RX Ring. 135 * RX descriptor format for RX Ring.
1856 */ 136 */
1857 137
@@ -1897,64 +177,4 @@ struct mac_iveiv_entry {
1897#define RXD_W3_PLCP_SIGNAL FIELD32(0x00020000) 177#define RXD_W3_PLCP_SIGNAL FIELD32(0x00020000)
1898#define RXD_W3_PLCP_RSSI FIELD32(0x00040000) 178#define RXD_W3_PLCP_RSSI FIELD32(0x00040000)
1899 179
1900/*
1901 * RX WI structure
1902 */
1903
1904/*
1905 * Word0
1906 */
1907#define RXWI_W0_WIRELESS_CLI_ID FIELD32(0x000000ff)
1908#define RXWI_W0_KEY_INDEX FIELD32(0x00000300)
1909#define RXWI_W0_BSSID FIELD32(0x00001c00)
1910#define RXWI_W0_UDF FIELD32(0x0000e000)
1911#define RXWI_W0_MPDU_TOTAL_BYTE_COUNT FIELD32(0x0fff0000)
1912#define RXWI_W0_TID FIELD32(0xf0000000)
1913
1914/*
1915 * Word1
1916 */
1917#define RXWI_W1_FRAG FIELD32(0x0000000f)
1918#define RXWI_W1_SEQUENCE FIELD32(0x0000fff0)
1919#define RXWI_W1_MCS FIELD32(0x007f0000)
1920#define RXWI_W1_BW FIELD32(0x00800000)
1921#define RXWI_W1_SHORT_GI FIELD32(0x01000000)
1922#define RXWI_W1_STBC FIELD32(0x06000000)
1923#define RXWI_W1_PHYMODE FIELD32(0xc0000000)
1924
1925/*
1926 * Word2
1927 */
1928#define RXWI_W2_RSSI0 FIELD32(0x000000ff)
1929#define RXWI_W2_RSSI1 FIELD32(0x0000ff00)
1930#define RXWI_W2_RSSI2 FIELD32(0x00ff0000)
1931
1932/*
1933 * Word3
1934 */
1935#define RXWI_W3_SNR0 FIELD32(0x000000ff)
1936#define RXWI_W3_SNR1 FIELD32(0x0000ff00)
1937
1938/*
1939 * Macros for converting txpower from EEPROM to mac80211 value
1940 * and from mac80211 value to register value.
1941 */
1942#define MIN_G_TXPOWER 0
1943#define MIN_A_TXPOWER -7
1944#define MAX_G_TXPOWER 31
1945#define MAX_A_TXPOWER 15
1946#define DEFAULT_TXPOWER 5
1947
1948#define TXPOWER_G_FROM_DEV(__txpower) \
1949 ((__txpower) > MAX_G_TXPOWER) ? DEFAULT_TXPOWER : (__txpower)
1950
1951#define TXPOWER_G_TO_DEV(__txpower) \
1952 clamp_t(char, __txpower, MIN_G_TXPOWER, MAX_G_TXPOWER)
1953
1954#define TXPOWER_A_FROM_DEV(__txpower) \
1955 ((__txpower) > MAX_A_TXPOWER) ? DEFAULT_TXPOWER : (__txpower)
1956
1957#define TXPOWER_A_TO_DEV(__txpower) \
1958 clamp_t(char, __txpower, MIN_A_TXPOWER, MAX_A_TXPOWER)
1959
1960#endif /* RT2800PCI_H */ 180#endif /* RT2800PCI_H */
diff --git a/drivers/net/wireless/rt2x00/rt2800usb.c b/drivers/net/wireless/rt2x00/rt2800usb.c
index 9fe770f7d7bb..ce2e893856c1 100644
--- a/drivers/net/wireless/rt2x00/rt2800usb.c
+++ b/drivers/net/wireless/rt2x00/rt2800usb.c
@@ -34,6 +34,8 @@
34 34
35#include "rt2x00.h" 35#include "rt2x00.h"
36#include "rt2x00usb.h" 36#include "rt2x00usb.h"
37#include "rt2800lib.h"
38#include "rt2800.h"
37#include "rt2800usb.h" 39#include "rt2800usb.h"
38 40
39/* 41/*
@@ -44,1027 +46,6 @@ module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO);
44MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption."); 46MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
45 47
46/* 48/*
47 * Register access.
48 * All access to the CSR registers will go through the methods
49 * rt2x00usb_register_read and rt2x00usb_register_write.
50 * BBP and RF register require indirect register access,
51 * and use the CSR registers BBPCSR and RFCSR to achieve this.
52 * These indirect registers work with busy bits,
53 * and we will try maximal REGISTER_BUSY_COUNT times to access
54 * the register while taking a REGISTER_BUSY_DELAY us delay
55 * between each attampt. When the busy bit is still set at that time,
56 * the access attempt is considered to have failed,
57 * and we will print an error.
58 * The _lock versions must be used if you already hold the csr_mutex
59 */
60#define WAIT_FOR_BBP(__dev, __reg) \
61 rt2x00usb_regbusy_read((__dev), BBP_CSR_CFG, BBP_CSR_CFG_BUSY, (__reg))
62#define WAIT_FOR_RFCSR(__dev, __reg) \
63 rt2x00usb_regbusy_read((__dev), RF_CSR_CFG, RF_CSR_CFG_BUSY, (__reg))
64#define WAIT_FOR_RF(__dev, __reg) \
65 rt2x00usb_regbusy_read((__dev), RF_CSR_CFG0, RF_CSR_CFG0_BUSY, (__reg))
66#define WAIT_FOR_MCU(__dev, __reg) \
67 rt2x00usb_regbusy_read((__dev), H2M_MAILBOX_CSR, \
68 H2M_MAILBOX_CSR_OWNER, (__reg))
69
70static void rt2800usb_bbp_write(struct rt2x00_dev *rt2x00dev,
71 const unsigned int word, const u8 value)
72{
73 u32 reg;
74
75 mutex_lock(&rt2x00dev->csr_mutex);
76
77 /*
78 * Wait until the BBP becomes available, afterwards we
79 * can safely write the new data into the register.
80 */
81 if (WAIT_FOR_BBP(rt2x00dev, &reg)) {
82 reg = 0;
83 rt2x00_set_field32(&reg, BBP_CSR_CFG_VALUE, value);
84 rt2x00_set_field32(&reg, BBP_CSR_CFG_REGNUM, word);
85 rt2x00_set_field32(&reg, BBP_CSR_CFG_BUSY, 1);
86 rt2x00_set_field32(&reg, BBP_CSR_CFG_READ_CONTROL, 0);
87
88 rt2x00usb_register_write_lock(rt2x00dev, BBP_CSR_CFG, reg);
89 }
90
91 mutex_unlock(&rt2x00dev->csr_mutex);
92}
93
94static void rt2800usb_bbp_read(struct rt2x00_dev *rt2x00dev,
95 const unsigned int word, u8 *value)
96{
97 u32 reg;
98
99 mutex_lock(&rt2x00dev->csr_mutex);
100
101 /*
102 * Wait until the BBP becomes available, afterwards we
103 * can safely write the read request into the register.
104 * After the data has been written, we wait until hardware
105 * returns the correct value, if at any time the register
106 * doesn't become available in time, reg will be 0xffffffff
107 * which means we return 0xff to the caller.
108 */
109 if (WAIT_FOR_BBP(rt2x00dev, &reg)) {
110 reg = 0;
111 rt2x00_set_field32(&reg, BBP_CSR_CFG_REGNUM, word);
112 rt2x00_set_field32(&reg, BBP_CSR_CFG_BUSY, 1);
113 rt2x00_set_field32(&reg, BBP_CSR_CFG_READ_CONTROL, 1);
114
115 rt2x00usb_register_write_lock(rt2x00dev, BBP_CSR_CFG, reg);
116
117 WAIT_FOR_BBP(rt2x00dev, &reg);
118 }
119
120 *value = rt2x00_get_field32(reg, BBP_CSR_CFG_VALUE);
121
122 mutex_unlock(&rt2x00dev->csr_mutex);
123}
124
125static void rt2800usb_rfcsr_write(struct rt2x00_dev *rt2x00dev,
126 const unsigned int word, const u8 value)
127{
128 u32 reg;
129
130 mutex_lock(&rt2x00dev->csr_mutex);
131
132 /*
133 * Wait until the RFCSR becomes available, afterwards we
134 * can safely write the new data into the register.
135 */
136 if (WAIT_FOR_RFCSR(rt2x00dev, &reg)) {
137 reg = 0;
138 rt2x00_set_field32(&reg, RF_CSR_CFG_DATA, value);
139 rt2x00_set_field32(&reg, RF_CSR_CFG_REGNUM, word);
140 rt2x00_set_field32(&reg, RF_CSR_CFG_WRITE, 1);
141 rt2x00_set_field32(&reg, RF_CSR_CFG_BUSY, 1);
142
143 rt2x00usb_register_write_lock(rt2x00dev, RF_CSR_CFG, reg);
144 }
145
146 mutex_unlock(&rt2x00dev->csr_mutex);
147}
148
149static void rt2800usb_rfcsr_read(struct rt2x00_dev *rt2x00dev,
150 const unsigned int word, u8 *value)
151{
152 u32 reg;
153
154 mutex_lock(&rt2x00dev->csr_mutex);
155
156 /*
157 * Wait until the RFCSR becomes available, afterwards we
158 * can safely write the read request into the register.
159 * After the data has been written, we wait until hardware
160 * returns the correct value, if at any time the register
161 * doesn't become available in time, reg will be 0xffffffff
162 * which means we return 0xff to the caller.
163 */
164 if (WAIT_FOR_RFCSR(rt2x00dev, &reg)) {
165 reg = 0;
166 rt2x00_set_field32(&reg, RF_CSR_CFG_REGNUM, word);
167 rt2x00_set_field32(&reg, RF_CSR_CFG_WRITE, 0);
168 rt2x00_set_field32(&reg, RF_CSR_CFG_BUSY, 1);
169
170 rt2x00usb_register_write_lock(rt2x00dev, BBP_CSR_CFG, reg);
171
172 WAIT_FOR_RFCSR(rt2x00dev, &reg);
173 }
174
175 *value = rt2x00_get_field32(reg, RF_CSR_CFG_DATA);
176
177 mutex_unlock(&rt2x00dev->csr_mutex);
178}
179
180static void rt2800usb_rf_write(struct rt2x00_dev *rt2x00dev,
181 const unsigned int word, const u32 value)
182{
183 u32 reg;
184
185 mutex_lock(&rt2x00dev->csr_mutex);
186
187 /*
188 * Wait until the RF becomes available, afterwards we
189 * can safely write the new data into the register.
190 */
191 if (WAIT_FOR_RF(rt2x00dev, &reg)) {
192 reg = 0;
193 rt2x00_set_field32(&reg, RF_CSR_CFG0_REG_VALUE_BW, value);
194 rt2x00_set_field32(&reg, RF_CSR_CFG0_STANDBYMODE, 0);
195 rt2x00_set_field32(&reg, RF_CSR_CFG0_SEL, 0);
196 rt2x00_set_field32(&reg, RF_CSR_CFG0_BUSY, 1);
197
198 rt2x00usb_register_write_lock(rt2x00dev, RF_CSR_CFG0, reg);
199 rt2x00_rf_write(rt2x00dev, word, value);
200 }
201
202 mutex_unlock(&rt2x00dev->csr_mutex);
203}
204
205static void rt2800usb_mcu_request(struct rt2x00_dev *rt2x00dev,
206 const u8 command, const u8 token,
207 const u8 arg0, const u8 arg1)
208{
209 u32 reg;
210
211 mutex_lock(&rt2x00dev->csr_mutex);
212
213 /*
214 * Wait until the MCU becomes available, afterwards we
215 * can safely write the new data into the register.
216 */
217 if (WAIT_FOR_MCU(rt2x00dev, &reg)) {
218 rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_OWNER, 1);
219 rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_CMD_TOKEN, token);
220 rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_ARG0, arg0);
221 rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_ARG1, arg1);
222 rt2x00usb_register_write_lock(rt2x00dev, H2M_MAILBOX_CSR, reg);
223
224 reg = 0;
225 rt2x00_set_field32(&reg, HOST_CMD_CSR_HOST_COMMAND, command);
226 rt2x00usb_register_write_lock(rt2x00dev, HOST_CMD_CSR, reg);
227 }
228
229 mutex_unlock(&rt2x00dev->csr_mutex);
230}
231
232#ifdef CONFIG_RT2X00_LIB_DEBUGFS
233static const struct rt2x00debug rt2800usb_rt2x00debug = {
234 .owner = THIS_MODULE,
235 .csr = {
236 .read = rt2x00usb_register_read,
237 .write = rt2x00usb_register_write,
238 .flags = RT2X00DEBUGFS_OFFSET,
239 .word_base = CSR_REG_BASE,
240 .word_size = sizeof(u32),
241 .word_count = CSR_REG_SIZE / sizeof(u32),
242 },
243 .eeprom = {
244 .read = rt2x00_eeprom_read,
245 .write = rt2x00_eeprom_write,
246 .word_base = EEPROM_BASE,
247 .word_size = sizeof(u16),
248 .word_count = EEPROM_SIZE / sizeof(u16),
249 },
250 .bbp = {
251 .read = rt2800usb_bbp_read,
252 .write = rt2800usb_bbp_write,
253 .word_base = BBP_BASE,
254 .word_size = sizeof(u8),
255 .word_count = BBP_SIZE / sizeof(u8),
256 },
257 .rf = {
258 .read = rt2x00_rf_read,
259 .write = rt2800usb_rf_write,
260 .word_base = RF_BASE,
261 .word_size = sizeof(u32),
262 .word_count = RF_SIZE / sizeof(u32),
263 },
264};
265#endif /* CONFIG_RT2X00_LIB_DEBUGFS */
266
267static int rt2800usb_rfkill_poll(struct rt2x00_dev *rt2x00dev)
268{
269 u32 reg;
270
271 rt2x00usb_register_read(rt2x00dev, GPIO_CTRL_CFG, &reg);
272 return rt2x00_get_field32(reg, GPIO_CTRL_CFG_BIT2);
273}
274
275#ifdef CONFIG_RT2X00_LIB_LEDS
276static void rt2800usb_brightness_set(struct led_classdev *led_cdev,
277 enum led_brightness brightness)
278{
279 struct rt2x00_led *led =
280 container_of(led_cdev, struct rt2x00_led, led_dev);
281 unsigned int enabled = brightness != LED_OFF;
282 unsigned int bg_mode =
283 (enabled && led->rt2x00dev->curr_band == IEEE80211_BAND_2GHZ);
284 unsigned int polarity =
285 rt2x00_get_field16(led->rt2x00dev->led_mcu_reg,
286 EEPROM_FREQ_LED_POLARITY);
287 unsigned int ledmode =
288 rt2x00_get_field16(led->rt2x00dev->led_mcu_reg,
289 EEPROM_FREQ_LED_MODE);
290
291 if (led->type == LED_TYPE_RADIO) {
292 rt2800usb_mcu_request(led->rt2x00dev, MCU_LED, 0xff, ledmode,
293 enabled ? 0x20 : 0);
294 } else if (led->type == LED_TYPE_ASSOC) {
295 rt2800usb_mcu_request(led->rt2x00dev, MCU_LED, 0xff, ledmode,
296 enabled ? (bg_mode ? 0x60 : 0xa0) : 0x20);
297 } else if (led->type == LED_TYPE_QUALITY) {
298 /*
299 * The brightness is divided into 6 levels (0 - 5),
300 * The specs tell us the following levels:
301 * 0, 1 ,3, 7, 15, 31
302 * to determine the level in a simple way we can simply
303 * work with bitshifting:
304 * (1 << level) - 1
305 */
306 rt2800usb_mcu_request(led->rt2x00dev, MCU_LED_STRENGTH, 0xff,
307 (1 << brightness / (LED_FULL / 6)) - 1,
308 polarity);
309 }
310}
311
312static int rt2800usb_blink_set(struct led_classdev *led_cdev,
313 unsigned long *delay_on,
314 unsigned long *delay_off)
315{
316 struct rt2x00_led *led =
317 container_of(led_cdev, struct rt2x00_led, led_dev);
318 u32 reg;
319
320 rt2x00usb_register_read(led->rt2x00dev, LED_CFG, &reg);
321 rt2x00_set_field32(&reg, LED_CFG_ON_PERIOD, *delay_on);
322 rt2x00_set_field32(&reg, LED_CFG_OFF_PERIOD, *delay_off);
323 rt2x00_set_field32(&reg, LED_CFG_SLOW_BLINK_PERIOD, 3);
324 rt2x00_set_field32(&reg, LED_CFG_R_LED_MODE, 3);
325 rt2x00_set_field32(&reg, LED_CFG_G_LED_MODE, 12);
326 rt2x00_set_field32(&reg, LED_CFG_Y_LED_MODE, 3);
327 rt2x00_set_field32(&reg, LED_CFG_LED_POLAR, 1);
328 rt2x00usb_register_write(led->rt2x00dev, LED_CFG, reg);
329
330 return 0;
331}
332
333static void rt2800usb_init_led(struct rt2x00_dev *rt2x00dev,
334 struct rt2x00_led *led,
335 enum led_type type)
336{
337 led->rt2x00dev = rt2x00dev;
338 led->type = type;
339 led->led_dev.brightness_set = rt2800usb_brightness_set;
340 led->led_dev.blink_set = rt2800usb_blink_set;
341 led->flags = LED_INITIALIZED;
342}
343#endif /* CONFIG_RT2X00_LIB_LEDS */
344
345/*
346 * Configuration handlers.
347 */
348static void rt2800usb_config_wcid_attr(struct rt2x00_dev *rt2x00dev,
349 struct rt2x00lib_crypto *crypto,
350 struct ieee80211_key_conf *key)
351{
352 struct mac_wcid_entry wcid_entry;
353 struct mac_iveiv_entry iveiv_entry;
354 u32 offset;
355 u32 reg;
356
357 offset = MAC_WCID_ATTR_ENTRY(key->hw_key_idx);
358
359 rt2x00usb_register_read(rt2x00dev, offset, &reg);
360 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_KEYTAB,
361 !!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE));
362 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_CIPHER,
363 (crypto->cmd == SET_KEY) * crypto->cipher);
364 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_BSS_IDX,
365 (crypto->cmd == SET_KEY) * crypto->bssidx);
366 rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_RX_WIUDF, crypto->cipher);
367 rt2x00usb_register_write(rt2x00dev, offset, reg);
368
369 offset = MAC_IVEIV_ENTRY(key->hw_key_idx);
370
371 memset(&iveiv_entry, 0, sizeof(iveiv_entry));
372 if ((crypto->cipher == CIPHER_TKIP) ||
373 (crypto->cipher == CIPHER_TKIP_NO_MIC) ||
374 (crypto->cipher == CIPHER_AES))
375 iveiv_entry.iv[3] |= 0x20;
376 iveiv_entry.iv[3] |= key->keyidx << 6;
377 rt2x00usb_register_multiwrite(rt2x00dev, offset,
378 &iveiv_entry, sizeof(iveiv_entry));
379
380 offset = MAC_WCID_ENTRY(key->hw_key_idx);
381
382 memset(&wcid_entry, 0, sizeof(wcid_entry));
383 if (crypto->cmd == SET_KEY)
384 memcpy(&wcid_entry, crypto->address, ETH_ALEN);
385 rt2x00usb_register_multiwrite(rt2x00dev, offset,
386 &wcid_entry, sizeof(wcid_entry));
387}
388
389static int rt2800usb_config_shared_key(struct rt2x00_dev *rt2x00dev,
390 struct rt2x00lib_crypto *crypto,
391 struct ieee80211_key_conf *key)
392{
393 struct hw_key_entry key_entry;
394 struct rt2x00_field32 field;
395 int timeout;
396 u32 offset;
397 u32 reg;
398
399 if (crypto->cmd == SET_KEY) {
400 key->hw_key_idx = (4 * crypto->bssidx) + key->keyidx;
401
402 memcpy(key_entry.key, crypto->key,
403 sizeof(key_entry.key));
404 memcpy(key_entry.tx_mic, crypto->tx_mic,
405 sizeof(key_entry.tx_mic));
406 memcpy(key_entry.rx_mic, crypto->rx_mic,
407 sizeof(key_entry.rx_mic));
408
409 offset = SHARED_KEY_ENTRY(key->hw_key_idx);
410 timeout = REGISTER_TIMEOUT32(sizeof(key_entry));
411 rt2x00usb_vendor_request_large_buff(rt2x00dev, USB_MULTI_WRITE,
412 USB_VENDOR_REQUEST_OUT,
413 offset, &key_entry,
414 sizeof(key_entry),
415 timeout);
416 }
417
418 /*
419 * The cipher types are stored over multiple registers
420 * starting with SHARED_KEY_MODE_BASE each word will have
421 * 32 bits and contains the cipher types for 2 bssidx each.
422 * Using the correct defines correctly will cause overhead,
423 * so just calculate the correct offset.
424 */
425 field.bit_offset = 4 * (key->hw_key_idx % 8);
426 field.bit_mask = 0x7 << field.bit_offset;
427
428 offset = SHARED_KEY_MODE_ENTRY(key->hw_key_idx / 8);
429
430 rt2x00usb_register_read(rt2x00dev, offset, &reg);
431 rt2x00_set_field32(&reg, field,
432 (crypto->cmd == SET_KEY) * crypto->cipher);
433 rt2x00usb_register_write(rt2x00dev, offset, reg);
434
435 /*
436 * Update WCID information
437 */
438 rt2800usb_config_wcid_attr(rt2x00dev, crypto, key);
439
440 return 0;
441}
442
443static int rt2800usb_config_pairwise_key(struct rt2x00_dev *rt2x00dev,
444 struct rt2x00lib_crypto *crypto,
445 struct ieee80211_key_conf *key)
446{
447 struct hw_key_entry key_entry;
448 int timeout;
449 u32 offset;
450
451 if (crypto->cmd == SET_KEY) {
452 /*
453 * 1 pairwise key is possible per AID, this means that the AID
454 * equals our hw_key_idx. Make sure the WCID starts _after_ the
455 * last possible shared key entry.
456 */
457 if (crypto->aid > (256 - 32))
458 return -ENOSPC;
459
460 key->hw_key_idx = 32 + crypto->aid;
461
462 memcpy(key_entry.key, crypto->key,
463 sizeof(key_entry.key));
464 memcpy(key_entry.tx_mic, crypto->tx_mic,
465 sizeof(key_entry.tx_mic));
466 memcpy(key_entry.rx_mic, crypto->rx_mic,
467 sizeof(key_entry.rx_mic));
468
469 offset = PAIRWISE_KEY_ENTRY(key->hw_key_idx);
470 timeout = REGISTER_TIMEOUT32(sizeof(key_entry));
471 rt2x00usb_vendor_request_large_buff(rt2x00dev, USB_MULTI_WRITE,
472 USB_VENDOR_REQUEST_OUT,
473 offset, &key_entry,
474 sizeof(key_entry),
475 timeout);
476 }
477
478 /*
479 * Update WCID information
480 */
481 rt2800usb_config_wcid_attr(rt2x00dev, crypto, key);
482
483 return 0;
484}
485
486static void rt2800usb_config_filter(struct rt2x00_dev *rt2x00dev,
487 const unsigned int filter_flags)
488{
489 u32 reg;
490
491 /*
492 * Start configuration steps.
493 * Note that the version error will always be dropped
494 * and broadcast frames will always be accepted since
495 * there is no filter for it at this time.
496 */
497 rt2x00usb_register_read(rt2x00dev, RX_FILTER_CFG, &reg);
498 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CRC_ERROR,
499 !(filter_flags & FIF_FCSFAIL));
500 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_PHY_ERROR,
501 !(filter_flags & FIF_PLCPFAIL));
502 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_NOT_TO_ME,
503 !(filter_flags & FIF_PROMISC_IN_BSS));
504 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_NOT_MY_BSSD, 0);
505 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_VER_ERROR, 1);
506 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_MULTICAST,
507 !(filter_flags & FIF_ALLMULTI));
508 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_BROADCAST, 0);
509 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_DUPLICATE, 1);
510 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CF_END_ACK,
511 !(filter_flags & FIF_CONTROL));
512 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CF_END,
513 !(filter_flags & FIF_CONTROL));
514 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_ACK,
515 !(filter_flags & FIF_CONTROL));
516 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CTS,
517 !(filter_flags & FIF_CONTROL));
518 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_RTS,
519 !(filter_flags & FIF_CONTROL));
520 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_PSPOLL,
521 !(filter_flags & FIF_PSPOLL));
522 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_BA, 1);
523 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_BAR, 0);
524 rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CNTL,
525 !(filter_flags & FIF_CONTROL));
526 rt2x00usb_register_write(rt2x00dev, RX_FILTER_CFG, reg);
527}
528
529static void rt2800usb_config_intf(struct rt2x00_dev *rt2x00dev,
530 struct rt2x00_intf *intf,
531 struct rt2x00intf_conf *conf,
532 const unsigned int flags)
533{
534 unsigned int beacon_base;
535 u32 reg;
536
537 if (flags & CONFIG_UPDATE_TYPE) {
538 /*
539 * Clear current synchronisation setup.
540 * For the Beacon base registers we only need to clear
541 * the first byte since that byte contains the VALID and OWNER
542 * bits which (when set to 0) will invalidate the entire beacon.
543 */
544 beacon_base = HW_BEACON_OFFSET(intf->beacon->entry_idx);
545 rt2x00usb_register_write(rt2x00dev, beacon_base, 0);
546
547 /*
548 * Enable synchronisation.
549 */
550 rt2x00usb_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
551 rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 1);
552 rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_SYNC, conf->sync);
553 rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 1);
554 rt2x00usb_register_write(rt2x00dev, BCN_TIME_CFG, reg);
555 }
556
557 if (flags & CONFIG_UPDATE_MAC) {
558 reg = le32_to_cpu(conf->mac[1]);
559 rt2x00_set_field32(&reg, MAC_ADDR_DW1_UNICAST_TO_ME_MASK, 0xff);
560 conf->mac[1] = cpu_to_le32(reg);
561
562 rt2x00usb_register_multiwrite(rt2x00dev, MAC_ADDR_DW0,
563 conf->mac, sizeof(conf->mac));
564 }
565
566 if (flags & CONFIG_UPDATE_BSSID) {
567 reg = le32_to_cpu(conf->bssid[1]);
568 rt2x00_set_field32(&reg, MAC_BSSID_DW1_BSS_ID_MASK, 0);
569 rt2x00_set_field32(&reg, MAC_BSSID_DW1_BSS_BCN_NUM, 0);
570 conf->bssid[1] = cpu_to_le32(reg);
571
572 rt2x00usb_register_multiwrite(rt2x00dev, MAC_BSSID_DW0,
573 conf->bssid, sizeof(conf->bssid));
574 }
575}
576
577static void rt2800usb_config_erp(struct rt2x00_dev *rt2x00dev,
578 struct rt2x00lib_erp *erp)
579{
580 u32 reg;
581
582 rt2x00usb_register_read(rt2x00dev, TX_TIMEOUT_CFG, &reg);
583 rt2x00_set_field32(&reg, TX_TIMEOUT_CFG_RX_ACK_TIMEOUT, 0x20);
584 rt2x00usb_register_write(rt2x00dev, TX_TIMEOUT_CFG, reg);
585
586 rt2x00usb_register_read(rt2x00dev, AUTO_RSP_CFG, &reg);
587 rt2x00_set_field32(&reg, AUTO_RSP_CFG_BAC_ACK_POLICY,
588 !!erp->short_preamble);
589 rt2x00_set_field32(&reg, AUTO_RSP_CFG_AR_PREAMBLE,
590 !!erp->short_preamble);
591 rt2x00usb_register_write(rt2x00dev, AUTO_RSP_CFG, reg);
592
593 rt2x00usb_register_read(rt2x00dev, OFDM_PROT_CFG, &reg);
594 rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_CTRL,
595 erp->cts_protection ? 2 : 0);
596 rt2x00usb_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
597
598 rt2x00usb_register_write(rt2x00dev, LEGACY_BASIC_RATE,
599 erp->basic_rates);
600 rt2x00usb_register_write(rt2x00dev, HT_BASIC_RATE, 0x00008003);
601
602 rt2x00usb_register_read(rt2x00dev, BKOFF_SLOT_CFG, &reg);
603 rt2x00_set_field32(&reg, BKOFF_SLOT_CFG_SLOT_TIME, erp->slot_time);
604 rt2x00_set_field32(&reg, BKOFF_SLOT_CFG_CC_DELAY_TIME, 2);
605 rt2x00usb_register_write(rt2x00dev, BKOFF_SLOT_CFG, reg);
606
607 rt2x00usb_register_read(rt2x00dev, XIFS_TIME_CFG, &reg);
608 rt2x00_set_field32(&reg, XIFS_TIME_CFG_CCKM_SIFS_TIME, erp->sifs);
609 rt2x00_set_field32(&reg, XIFS_TIME_CFG_OFDM_SIFS_TIME, erp->sifs);
610 rt2x00_set_field32(&reg, XIFS_TIME_CFG_OFDM_XIFS_TIME, 4);
611 rt2x00_set_field32(&reg, XIFS_TIME_CFG_EIFS, erp->eifs);
612 rt2x00_set_field32(&reg, XIFS_TIME_CFG_BB_RXEND_ENABLE, 1);
613 rt2x00usb_register_write(rt2x00dev, XIFS_TIME_CFG, reg);
614
615 rt2x00usb_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
616 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_INTERVAL,
617 erp->beacon_int * 16);
618 rt2x00usb_register_write(rt2x00dev, BCN_TIME_CFG, reg);
619}
620
621static void rt2800usb_config_ant(struct rt2x00_dev *rt2x00dev,
622 struct antenna_setup *ant)
623{
624 u8 r1;
625 u8 r3;
626
627 rt2800usb_bbp_read(rt2x00dev, 1, &r1);
628 rt2800usb_bbp_read(rt2x00dev, 3, &r3);
629
630 /*
631 * Configure the TX antenna.
632 */
633 switch ((int)ant->tx) {
634 case 1:
635 rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 0);
636 break;
637 case 2:
638 rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 2);
639 break;
640 case 3:
641 /* Do nothing */
642 break;
643 }
644
645 /*
646 * Configure the RX antenna.
647 */
648 switch ((int)ant->rx) {
649 case 1:
650 rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 0);
651 break;
652 case 2:
653 rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 1);
654 break;
655 case 3:
656 rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 2);
657 break;
658 }
659
660 rt2800usb_bbp_write(rt2x00dev, 3, r3);
661 rt2800usb_bbp_write(rt2x00dev, 1, r1);
662}
663
664static void rt2800usb_config_lna_gain(struct rt2x00_dev *rt2x00dev,
665 struct rt2x00lib_conf *libconf)
666{
667 u16 eeprom;
668 short lna_gain;
669
670 if (libconf->rf.channel <= 14) {
671 rt2x00_eeprom_read(rt2x00dev, EEPROM_LNA, &eeprom);
672 lna_gain = rt2x00_get_field16(eeprom, EEPROM_LNA_BG);
673 } else if (libconf->rf.channel <= 64) {
674 rt2x00_eeprom_read(rt2x00dev, EEPROM_LNA, &eeprom);
675 lna_gain = rt2x00_get_field16(eeprom, EEPROM_LNA_A0);
676 } else if (libconf->rf.channel <= 128) {
677 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &eeprom);
678 lna_gain = rt2x00_get_field16(eeprom, EEPROM_RSSI_BG2_LNA_A1);
679 } else {
680 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &eeprom);
681 lna_gain = rt2x00_get_field16(eeprom, EEPROM_RSSI_A2_LNA_A2);
682 }
683
684 rt2x00dev->lna_gain = lna_gain;
685}
686
687static void rt2800usb_config_channel_rt2x(struct rt2x00_dev *rt2x00dev,
688 struct ieee80211_conf *conf,
689 struct rf_channel *rf,
690 struct channel_info *info)
691{
692 rt2x00_set_field32(&rf->rf4, RF4_FREQ_OFFSET, rt2x00dev->freq_offset);
693
694 if (rt2x00dev->default_ant.tx == 1)
695 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_TX1, 1);
696
697 if (rt2x00dev->default_ant.rx == 1) {
698 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX1, 1);
699 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1);
700 } else if (rt2x00dev->default_ant.rx == 2)
701 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1);
702
703 if (rf->channel > 14) {
704 /*
705 * When TX power is below 0, we should increase it by 7 to
706 * make it a positive value (Minumum value is -7).
707 * However this means that values between 0 and 7 have
708 * double meaning, and we should set a 7DBm boost flag.
709 */
710 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_A_7DBM_BOOST,
711 (info->tx_power1 >= 0));
712
713 if (info->tx_power1 < 0)
714 info->tx_power1 += 7;
715
716 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_A,
717 TXPOWER_A_TO_DEV(info->tx_power1));
718
719 rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_A_7DBM_BOOST,
720 (info->tx_power2 >= 0));
721
722 if (info->tx_power2 < 0)
723 info->tx_power2 += 7;
724
725 rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_A,
726 TXPOWER_A_TO_DEV(info->tx_power2));
727 } else {
728 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_G,
729 TXPOWER_G_TO_DEV(info->tx_power1));
730 rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_G,
731 TXPOWER_G_TO_DEV(info->tx_power2));
732 }
733
734 rt2x00_set_field32(&rf->rf4, RF4_HT40, conf_is_ht40(conf));
735
736 rt2800usb_rf_write(rt2x00dev, 1, rf->rf1);
737 rt2800usb_rf_write(rt2x00dev, 2, rf->rf2);
738 rt2800usb_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
739 rt2800usb_rf_write(rt2x00dev, 4, rf->rf4);
740
741 udelay(200);
742
743 rt2800usb_rf_write(rt2x00dev, 1, rf->rf1);
744 rt2800usb_rf_write(rt2x00dev, 2, rf->rf2);
745 rt2800usb_rf_write(rt2x00dev, 3, rf->rf3 | 0x00000004);
746 rt2800usb_rf_write(rt2x00dev, 4, rf->rf4);
747
748 udelay(200);
749
750 rt2800usb_rf_write(rt2x00dev, 1, rf->rf1);
751 rt2800usb_rf_write(rt2x00dev, 2, rf->rf2);
752 rt2800usb_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
753 rt2800usb_rf_write(rt2x00dev, 4, rf->rf4);
754}
755
756static void rt2800usb_config_channel_rt3x(struct rt2x00_dev *rt2x00dev,
757 struct ieee80211_conf *conf,
758 struct rf_channel *rf,
759 struct channel_info *info)
760{
761 u8 rfcsr;
762
763 rt2800usb_rfcsr_write(rt2x00dev, 2, rf->rf1);
764 rt2800usb_rfcsr_write(rt2x00dev, 2, rf->rf3);
765
766 rt2800usb_rfcsr_read(rt2x00dev, 6, &rfcsr);
767 rt2x00_set_field8(&rfcsr, RFCSR6_R, rf->rf2);
768 rt2800usb_rfcsr_write(rt2x00dev, 6, rfcsr);
769
770 rt2800usb_rfcsr_read(rt2x00dev, 12, &rfcsr);
771 rt2x00_set_field8(&rfcsr, RFCSR12_TX_POWER,
772 TXPOWER_G_TO_DEV(info->tx_power1));
773 rt2800usb_rfcsr_write(rt2x00dev, 12, rfcsr);
774
775 rt2800usb_rfcsr_read(rt2x00dev, 23, &rfcsr);
776 rt2x00_set_field8(&rfcsr, RFCSR23_FREQ_OFFSET, rt2x00dev->freq_offset);
777 rt2800usb_rfcsr_write(rt2x00dev, 23, rfcsr);
778
779 rt2800usb_rfcsr_write(rt2x00dev, 24,
780 rt2x00dev->calibration[conf_is_ht40(conf)]);
781
782 rt2800usb_rfcsr_read(rt2x00dev, 23, &rfcsr);
783 rt2x00_set_field8(&rfcsr, RFCSR7_RF_TUNING, 1);
784 rt2800usb_rfcsr_write(rt2x00dev, 23, rfcsr);
785}
786
787static void rt2800usb_config_channel(struct rt2x00_dev *rt2x00dev,
788 struct ieee80211_conf *conf,
789 struct rf_channel *rf,
790 struct channel_info *info)
791{
792 u32 reg;
793 unsigned int tx_pin;
794 u8 bbp;
795
796 if (rt2x00_rev(&rt2x00dev->chip) != RT3070_VERSION)
797 rt2800usb_config_channel_rt2x(rt2x00dev, conf, rf, info);
798 else
799 rt2800usb_config_channel_rt3x(rt2x00dev, conf, rf, info);
800
801 /*
802 * Change BBP settings
803 */
804 rt2800usb_bbp_write(rt2x00dev, 62, 0x37 - rt2x00dev->lna_gain);
805 rt2800usb_bbp_write(rt2x00dev, 63, 0x37 - rt2x00dev->lna_gain);
806 rt2800usb_bbp_write(rt2x00dev, 64, 0x37 - rt2x00dev->lna_gain);
807 rt2800usb_bbp_write(rt2x00dev, 86, 0);
808
809 if (rf->channel <= 14) {
810 if (test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags)) {
811 rt2800usb_bbp_write(rt2x00dev, 82, 0x62);
812 rt2800usb_bbp_write(rt2x00dev, 75, 0x46);
813 } else {
814 rt2800usb_bbp_write(rt2x00dev, 82, 0x84);
815 rt2800usb_bbp_write(rt2x00dev, 75, 0x50);
816 }
817 } else {
818 rt2800usb_bbp_write(rt2x00dev, 82, 0xf2);
819
820 if (test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags))
821 rt2800usb_bbp_write(rt2x00dev, 75, 0x46);
822 else
823 rt2800usb_bbp_write(rt2x00dev, 75, 0x50);
824 }
825
826 rt2x00usb_register_read(rt2x00dev, TX_BAND_CFG, &reg);
827 rt2x00_set_field32(&reg, TX_BAND_CFG_HT40_PLUS, conf_is_ht40_plus(conf));
828 rt2x00_set_field32(&reg, TX_BAND_CFG_A, rf->channel > 14);
829 rt2x00_set_field32(&reg, TX_BAND_CFG_BG, rf->channel <= 14);
830 rt2x00usb_register_write(rt2x00dev, TX_BAND_CFG, reg);
831
832 tx_pin = 0;
833
834 /* Turn on unused PA or LNA when not using 1T or 1R */
835 if (rt2x00dev->default_ant.tx != 1) {
836 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A1_EN, 1);
837 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G1_EN, 1);
838 }
839
840 /* Turn on unused PA or LNA when not using 1T or 1R */
841 if (rt2x00dev->default_ant.rx != 1) {
842 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A1_EN, 1);
843 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G1_EN, 1);
844 }
845
846 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A0_EN, 1);
847 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G0_EN, 1);
848 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_RFTR_EN, 1);
849 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_TRSW_EN, 1);
850 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G0_EN, rf->channel <= 14);
851 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A0_EN, rf->channel > 14);
852
853 rt2x00usb_register_write(rt2x00dev, TX_PIN_CFG, tx_pin);
854
855 rt2800usb_bbp_read(rt2x00dev, 4, &bbp);
856 rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 2 * conf_is_ht40(conf));
857 rt2800usb_bbp_write(rt2x00dev, 4, bbp);
858
859 rt2800usb_bbp_read(rt2x00dev, 3, &bbp);
860 rt2x00_set_field8(&bbp, BBP3_HT40_PLUS, conf_is_ht40_plus(conf));
861 rt2800usb_bbp_write(rt2x00dev, 3, bbp);
862
863 if (rt2x00_rev(&rt2x00dev->chip) == RT2860C_VERSION) {
864 if (conf_is_ht40(conf)) {
865 rt2800usb_bbp_write(rt2x00dev, 69, 0x1a);
866 rt2800usb_bbp_write(rt2x00dev, 70, 0x0a);
867 rt2800usb_bbp_write(rt2x00dev, 73, 0x16);
868 } else {
869 rt2800usb_bbp_write(rt2x00dev, 69, 0x16);
870 rt2800usb_bbp_write(rt2x00dev, 70, 0x08);
871 rt2800usb_bbp_write(rt2x00dev, 73, 0x11);
872 }
873 }
874
875 msleep(1);
876}
877
878static void rt2800usb_config_txpower(struct rt2x00_dev *rt2x00dev,
879 const int txpower)
880{
881 u32 reg;
882 u32 value = TXPOWER_G_TO_DEV(txpower);
883 u8 r1;
884
885 rt2800usb_bbp_read(rt2x00dev, 1, &r1);
886 rt2x00_set_field8(&reg, BBP1_TX_POWER, 0);
887 rt2800usb_bbp_write(rt2x00dev, 1, r1);
888
889 rt2x00usb_register_read(rt2x00dev, TX_PWR_CFG_0, &reg);
890 rt2x00_set_field32(&reg, TX_PWR_CFG_0_1MBS, value);
891 rt2x00_set_field32(&reg, TX_PWR_CFG_0_2MBS, value);
892 rt2x00_set_field32(&reg, TX_PWR_CFG_0_55MBS, value);
893 rt2x00_set_field32(&reg, TX_PWR_CFG_0_11MBS, value);
894 rt2x00_set_field32(&reg, TX_PWR_CFG_0_6MBS, value);
895 rt2x00_set_field32(&reg, TX_PWR_CFG_0_9MBS, value);
896 rt2x00_set_field32(&reg, TX_PWR_CFG_0_12MBS, value);
897 rt2x00_set_field32(&reg, TX_PWR_CFG_0_18MBS, value);
898 rt2x00usb_register_write(rt2x00dev, TX_PWR_CFG_0, reg);
899
900 rt2x00usb_register_read(rt2x00dev, TX_PWR_CFG_1, &reg);
901 rt2x00_set_field32(&reg, TX_PWR_CFG_1_24MBS, value);
902 rt2x00_set_field32(&reg, TX_PWR_CFG_1_36MBS, value);
903 rt2x00_set_field32(&reg, TX_PWR_CFG_1_48MBS, value);
904 rt2x00_set_field32(&reg, TX_PWR_CFG_1_54MBS, value);
905 rt2x00_set_field32(&reg, TX_PWR_CFG_1_MCS0, value);
906 rt2x00_set_field32(&reg, TX_PWR_CFG_1_MCS1, value);
907 rt2x00_set_field32(&reg, TX_PWR_CFG_1_MCS2, value);
908 rt2x00_set_field32(&reg, TX_PWR_CFG_1_MCS3, value);
909 rt2x00usb_register_write(rt2x00dev, TX_PWR_CFG_1, reg);
910
911 rt2x00usb_register_read(rt2x00dev, TX_PWR_CFG_2, &reg);
912 rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS4, value);
913 rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS5, value);
914 rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS6, value);
915 rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS7, value);
916 rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS8, value);
917 rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS9, value);
918 rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS10, value);
919 rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS11, value);
920 rt2x00usb_register_write(rt2x00dev, TX_PWR_CFG_2, reg);
921
922 rt2x00usb_register_read(rt2x00dev, TX_PWR_CFG_3, &reg);
923 rt2x00_set_field32(&reg, TX_PWR_CFG_3_MCS12, value);
924 rt2x00_set_field32(&reg, TX_PWR_CFG_3_MCS13, value);
925 rt2x00_set_field32(&reg, TX_PWR_CFG_3_MCS14, value);
926 rt2x00_set_field32(&reg, TX_PWR_CFG_3_MCS15, value);
927 rt2x00_set_field32(&reg, TX_PWR_CFG_3_UKNOWN1, value);
928 rt2x00_set_field32(&reg, TX_PWR_CFG_3_UKNOWN2, value);
929 rt2x00_set_field32(&reg, TX_PWR_CFG_3_UKNOWN3, value);
930 rt2x00_set_field32(&reg, TX_PWR_CFG_3_UKNOWN4, value);
931 rt2x00usb_register_write(rt2x00dev, TX_PWR_CFG_3, reg);
932
933 rt2x00usb_register_read(rt2x00dev, TX_PWR_CFG_4, &reg);
934 rt2x00_set_field32(&reg, TX_PWR_CFG_4_UKNOWN5, value);
935 rt2x00_set_field32(&reg, TX_PWR_CFG_4_UKNOWN6, value);
936 rt2x00_set_field32(&reg, TX_PWR_CFG_4_UKNOWN7, value);
937 rt2x00_set_field32(&reg, TX_PWR_CFG_4_UKNOWN8, value);
938 rt2x00usb_register_write(rt2x00dev, TX_PWR_CFG_4, reg);
939}
940
941static void rt2800usb_config_retry_limit(struct rt2x00_dev *rt2x00dev,
942 struct rt2x00lib_conf *libconf)
943{
944 u32 reg;
945
946 rt2x00usb_register_read(rt2x00dev, TX_RTY_CFG, &reg);
947 rt2x00_set_field32(&reg, TX_RTY_CFG_SHORT_RTY_LIMIT,
948 libconf->conf->short_frame_max_tx_count);
949 rt2x00_set_field32(&reg, TX_RTY_CFG_LONG_RTY_LIMIT,
950 libconf->conf->long_frame_max_tx_count);
951 rt2x00_set_field32(&reg, TX_RTY_CFG_LONG_RTY_THRE, 2000);
952 rt2x00_set_field32(&reg, TX_RTY_CFG_NON_AGG_RTY_MODE, 0);
953 rt2x00_set_field32(&reg, TX_RTY_CFG_AGG_RTY_MODE, 0);
954 rt2x00_set_field32(&reg, TX_RTY_CFG_TX_AUTO_FB_ENABLE, 1);
955 rt2x00usb_register_write(rt2x00dev, TX_RTY_CFG, reg);
956}
957
958static void rt2800usb_config_ps(struct rt2x00_dev *rt2x00dev,
959 struct rt2x00lib_conf *libconf)
960{
961 enum dev_state state =
962 (libconf->conf->flags & IEEE80211_CONF_PS) ?
963 STATE_SLEEP : STATE_AWAKE;
964 u32 reg;
965
966 if (state == STATE_SLEEP) {
967 rt2x00usb_register_write(rt2x00dev, AUTOWAKEUP_CFG, 0);
968
969 rt2x00usb_register_read(rt2x00dev, AUTOWAKEUP_CFG, &reg);
970 rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTO_LEAD_TIME, 5);
971 rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_TBCN_BEFORE_WAKE,
972 libconf->conf->listen_interval - 1);
973 rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTOWAKE, 1);
974 rt2x00usb_register_write(rt2x00dev, AUTOWAKEUP_CFG, reg);
975
976 rt2x00dev->ops->lib->set_device_state(rt2x00dev, state);
977 } else {
978 rt2x00dev->ops->lib->set_device_state(rt2x00dev, state);
979
980 rt2x00usb_register_read(rt2x00dev, AUTOWAKEUP_CFG, &reg);
981 rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTO_LEAD_TIME, 0);
982 rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_TBCN_BEFORE_WAKE, 0);
983 rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTOWAKE, 0);
984 rt2x00usb_register_write(rt2x00dev, AUTOWAKEUP_CFG, reg);
985 }
986}
987
988static void rt2800usb_config(struct rt2x00_dev *rt2x00dev,
989 struct rt2x00lib_conf *libconf,
990 const unsigned int flags)
991{
992 /* Always recalculate LNA gain before changing configuration */
993 rt2800usb_config_lna_gain(rt2x00dev, libconf);
994
995 if (flags & IEEE80211_CONF_CHANGE_CHANNEL)
996 rt2800usb_config_channel(rt2x00dev, libconf->conf,
997 &libconf->rf, &libconf->channel);
998 if (flags & IEEE80211_CONF_CHANGE_POWER)
999 rt2800usb_config_txpower(rt2x00dev, libconf->conf->power_level);
1000 if (flags & IEEE80211_CONF_CHANGE_RETRY_LIMITS)
1001 rt2800usb_config_retry_limit(rt2x00dev, libconf);
1002 if (flags & IEEE80211_CONF_CHANGE_PS)
1003 rt2800usb_config_ps(rt2x00dev, libconf);
1004}
1005
1006/*
1007 * Link tuning
1008 */
1009static void rt2800usb_link_stats(struct rt2x00_dev *rt2x00dev,
1010 struct link_qual *qual)
1011{
1012 u32 reg;
1013
1014 /*
1015 * Update FCS error count from register.
1016 */
1017 rt2x00usb_register_read(rt2x00dev, RX_STA_CNT0, &reg);
1018 qual->rx_failed = rt2x00_get_field32(reg, RX_STA_CNT0_CRC_ERR);
1019}
1020
1021static u8 rt2800usb_get_default_vgc(struct rt2x00_dev *rt2x00dev)
1022{
1023 if (rt2x00dev->curr_band == IEEE80211_BAND_2GHZ) {
1024 if (rt2x00_rev(&rt2x00dev->chip) == RT3070_VERSION)
1025 return 0x1c + (2 * rt2x00dev->lna_gain);
1026 else
1027 return 0x2e + rt2x00dev->lna_gain;
1028 }
1029
1030 if (!test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags))
1031 return 0x32 + (rt2x00dev->lna_gain * 5) / 3;
1032 else
1033 return 0x3a + (rt2x00dev->lna_gain * 5) / 3;
1034}
1035
1036static inline void rt2800usb_set_vgc(struct rt2x00_dev *rt2x00dev,
1037 struct link_qual *qual, u8 vgc_level)
1038{
1039 if (qual->vgc_level != vgc_level) {
1040 rt2800usb_bbp_write(rt2x00dev, 66, vgc_level);
1041 qual->vgc_level = vgc_level;
1042 qual->vgc_level_reg = vgc_level;
1043 }
1044}
1045
1046static void rt2800usb_reset_tuner(struct rt2x00_dev *rt2x00dev,
1047 struct link_qual *qual)
1048{
1049 rt2800usb_set_vgc(rt2x00dev, qual,
1050 rt2800usb_get_default_vgc(rt2x00dev));
1051}
1052
1053static void rt2800usb_link_tuner(struct rt2x00_dev *rt2x00dev,
1054 struct link_qual *qual, const u32 count)
1055{
1056 if (rt2x00_rev(&rt2x00dev->chip) == RT2860C_VERSION)
1057 return;
1058
1059 /*
1060 * When RSSI is better then -80 increase VGC level with 0x10
1061 */
1062 rt2800usb_set_vgc(rt2x00dev, qual,
1063 rt2800usb_get_default_vgc(rt2x00dev) +
1064 ((qual->rssi > -80) * 0x10));
1065}
1066
1067/*
1068 * Firmware functions 49 * Firmware functions
1069 */ 50 */
1070static char *rt2800usb_get_firmware_name(struct rt2x00_dev *rt2x00dev) 51static char *rt2800usb_get_firmware_name(struct rt2x00_dev *rt2x00dev)
@@ -1172,7 +153,7 @@ static int rt2800usb_load_firmware(struct rt2x00_dev *rt2x00dev,
1172 * Wait for stable hardware. 153 * Wait for stable hardware.
1173 */ 154 */
1174 for (i = 0; i < REGISTER_BUSY_COUNT; i++) { 155 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
1175 rt2x00usb_register_read(rt2x00dev, MAC_CSR0, &reg); 156 rt2800_register_read(rt2x00dev, MAC_CSR0, &reg);
1176 if (reg && reg != ~0) 157 if (reg && reg != ~0)
1177 break; 158 break;
1178 msleep(1); 159 msleep(1);
@@ -1192,8 +173,8 @@ static int rt2800usb_load_firmware(struct rt2x00_dev *rt2x00dev,
1192 data + offset, length, 173 data + offset, length,
1193 REGISTER_TIMEOUT32(length)); 174 REGISTER_TIMEOUT32(length));
1194 175
1195 rt2x00usb_register_write(rt2x00dev, H2M_MAILBOX_CID, ~0); 176 rt2800_register_write(rt2x00dev, H2M_MAILBOX_CID, ~0);
1196 rt2x00usb_register_write(rt2x00dev, H2M_MAILBOX_STATUS, ~0); 177 rt2800_register_write(rt2x00dev, H2M_MAILBOX_STATUS, ~0);
1197 178
1198 /* 179 /*
1199 * Send firmware request to device to load firmware, 180 * Send firmware request to device to load firmware,
@@ -1208,18 +189,18 @@ static int rt2800usb_load_firmware(struct rt2x00_dev *rt2x00dev,
1208 } 189 }
1209 190
1210 msleep(10); 191 msleep(10);
1211 rt2x00usb_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0); 192 rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
1212 193
1213 /* 194 /*
1214 * Send signal to firmware during boot time. 195 * Send signal to firmware during boot time.
1215 */ 196 */
1216 rt2800usb_mcu_request(rt2x00dev, MCU_BOOT_SIGNAL, 0xff, 0, 0); 197 rt2800_mcu_request(rt2x00dev, MCU_BOOT_SIGNAL, 0xff, 0, 0);
1217 198
1218 if ((chipset == 0x3070) || 199 if ((chipset == 0x3070) ||
1219 (chipset == 0x3071) || 200 (chipset == 0x3071) ||
1220 (chipset == 0x3572)) { 201 (chipset == 0x3572)) {
1221 udelay(200); 202 udelay(200);
1222 rt2800usb_mcu_request(rt2x00dev, MCU_CURRENT, 0, 0, 0); 203 rt2800_mcu_request(rt2x00dev, MCU_CURRENT, 0, 0, 0);
1223 udelay(10); 204 udelay(10);
1224 } 205 }
1225 206
@@ -1227,7 +208,7 @@ static int rt2800usb_load_firmware(struct rt2x00_dev *rt2x00dev,
1227 * Wait for device to stabilize. 208 * Wait for device to stabilize.
1228 */ 209 */
1229 for (i = 0; i < REGISTER_BUSY_COUNT; i++) { 210 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
1230 rt2x00usb_register_read(rt2x00dev, PBF_SYS_CTRL, &reg); 211 rt2800_register_read(rt2x00dev, PBF_SYS_CTRL, &reg);
1231 if (rt2x00_get_field32(reg, PBF_SYS_CTRL_READY)) 212 if (rt2x00_get_field32(reg, PBF_SYS_CTRL_READY))
1232 break; 213 break;
1233 msleep(1); 214 msleep(1);
@@ -1241,536 +222,14 @@ static int rt2800usb_load_firmware(struct rt2x00_dev *rt2x00dev,
1241 /* 222 /*
1242 * Initialize firmware. 223 * Initialize firmware.
1243 */ 224 */
1244 rt2x00usb_register_write(rt2x00dev, H2M_BBP_AGENT, 0); 225 rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
1245 rt2x00usb_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0); 226 rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
1246 msleep(1); 227 msleep(1);
1247 228
1248 return 0; 229 return 0;
1249} 230}
1250 231
1251/* 232/*
1252 * Initialization functions.
1253 */
1254static int rt2800usb_init_registers(struct rt2x00_dev *rt2x00dev)
1255{
1256 u32 reg;
1257 unsigned int i;
1258
1259 /*
1260 * Wait untill BBP and RF are ready.
1261 */
1262 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
1263 rt2x00usb_register_read(rt2x00dev, MAC_CSR0, &reg);
1264 if (reg && reg != ~0)
1265 break;
1266 msleep(1);
1267 }
1268
1269 if (i == REGISTER_BUSY_COUNT) {
1270 ERROR(rt2x00dev, "Unstable hardware.\n");
1271 return -EBUSY;
1272 }
1273
1274 rt2x00usb_register_read(rt2x00dev, PBF_SYS_CTRL, &reg);
1275 rt2x00usb_register_write(rt2x00dev, PBF_SYS_CTRL, reg & ~0x00002000);
1276
1277 rt2x00usb_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
1278 rt2x00_set_field32(&reg, MAC_SYS_CTRL_RESET_CSR, 1);
1279 rt2x00_set_field32(&reg, MAC_SYS_CTRL_RESET_BBP, 1);
1280 rt2x00usb_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
1281
1282 rt2x00usb_register_write(rt2x00dev, USB_DMA_CFG, 0x00000000);
1283
1284 rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE, 0,
1285 USB_MODE_RESET, REGISTER_TIMEOUT);
1286
1287 rt2x00usb_register_write(rt2x00dev, MAC_SYS_CTRL, 0x00000000);
1288
1289 rt2x00usb_register_read(rt2x00dev, BCN_OFFSET0, &reg);
1290 rt2x00_set_field32(&reg, BCN_OFFSET0_BCN0, 0xe0); /* 0x3800 */
1291 rt2x00_set_field32(&reg, BCN_OFFSET0_BCN1, 0xe8); /* 0x3a00 */
1292 rt2x00_set_field32(&reg, BCN_OFFSET0_BCN2, 0xf0); /* 0x3c00 */
1293 rt2x00_set_field32(&reg, BCN_OFFSET0_BCN3, 0xf8); /* 0x3e00 */
1294 rt2x00usb_register_write(rt2x00dev, BCN_OFFSET0, reg);
1295
1296 rt2x00usb_register_read(rt2x00dev, BCN_OFFSET1, &reg);
1297 rt2x00_set_field32(&reg, BCN_OFFSET1_BCN4, 0xc8); /* 0x3200 */
1298 rt2x00_set_field32(&reg, BCN_OFFSET1_BCN5, 0xd0); /* 0x3400 */
1299 rt2x00_set_field32(&reg, BCN_OFFSET1_BCN6, 0x77); /* 0x1dc0 */
1300 rt2x00_set_field32(&reg, BCN_OFFSET1_BCN7, 0x6f); /* 0x1bc0 */
1301 rt2x00usb_register_write(rt2x00dev, BCN_OFFSET1, reg);
1302
1303 rt2x00usb_register_write(rt2x00dev, LEGACY_BASIC_RATE, 0x0000013f);
1304 rt2x00usb_register_write(rt2x00dev, HT_BASIC_RATE, 0x00008003);
1305
1306 rt2x00usb_register_write(rt2x00dev, MAC_SYS_CTRL, 0x00000000);
1307
1308 rt2x00usb_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
1309 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_INTERVAL, 0);
1310 rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 0);
1311 rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_SYNC, 0);
1312 rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 0);
1313 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 0);
1314 rt2x00_set_field32(&reg, BCN_TIME_CFG_TX_TIME_COMPENSATE, 0);
1315 rt2x00usb_register_write(rt2x00dev, BCN_TIME_CFG, reg);
1316
1317 if (rt2x00_rev(&rt2x00dev->chip) == RT3070_VERSION) {
1318 rt2x00usb_register_write(rt2x00dev, TX_SW_CFG0, 0x00000400);
1319 rt2x00usb_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000);
1320 rt2x00usb_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000);
1321 } else {
1322 rt2x00usb_register_write(rt2x00dev, TX_SW_CFG0, 0x00000000);
1323 rt2x00usb_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606);
1324 }
1325
1326 rt2x00usb_register_read(rt2x00dev, TX_LINK_CFG, &reg);
1327 rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_MFB_LIFETIME, 32);
1328 rt2x00_set_field32(&reg, TX_LINK_CFG_MFB_ENABLE, 0);
1329 rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_UMFS_ENABLE, 0);
1330 rt2x00_set_field32(&reg, TX_LINK_CFG_TX_MRQ_EN, 0);
1331 rt2x00_set_field32(&reg, TX_LINK_CFG_TX_RDG_EN, 0);
1332 rt2x00_set_field32(&reg, TX_LINK_CFG_TX_CF_ACK_EN, 1);
1333 rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_MFB, 0);
1334 rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_MFS, 0);
1335 rt2x00usb_register_write(rt2x00dev, TX_LINK_CFG, reg);
1336
1337 rt2x00usb_register_read(rt2x00dev, TX_TIMEOUT_CFG, &reg);
1338 rt2x00_set_field32(&reg, TX_TIMEOUT_CFG_MPDU_LIFETIME, 9);
1339 rt2x00_set_field32(&reg, TX_TIMEOUT_CFG_TX_OP_TIMEOUT, 10);
1340 rt2x00usb_register_write(rt2x00dev, TX_TIMEOUT_CFG, reg);
1341
1342 rt2x00usb_register_read(rt2x00dev, MAX_LEN_CFG, &reg);
1343 rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_MPDU, AGGREGATION_SIZE);
1344 if (rt2x00_rev(&rt2x00dev->chip) >= RT2880E_VERSION &&
1345 rt2x00_rev(&rt2x00dev->chip) < RT3070_VERSION)
1346 rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_PSDU, 2);
1347 else
1348 rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_PSDU, 1);
1349 rt2x00_set_field32(&reg, MAX_LEN_CFG_MIN_PSDU, 0);
1350 rt2x00_set_field32(&reg, MAX_LEN_CFG_MIN_MPDU, 0);
1351 rt2x00usb_register_write(rt2x00dev, MAX_LEN_CFG, reg);
1352
1353 rt2x00usb_register_write(rt2x00dev, PBF_MAX_PCNT, 0x1f3fbf9f);
1354
1355 rt2x00usb_register_read(rt2x00dev, AUTO_RSP_CFG, &reg);
1356 rt2x00_set_field32(&reg, AUTO_RSP_CFG_AUTORESPONDER, 1);
1357 rt2x00_set_field32(&reg, AUTO_RSP_CFG_CTS_40_MMODE, 0);
1358 rt2x00_set_field32(&reg, AUTO_RSP_CFG_CTS_40_MREF, 0);
1359 rt2x00_set_field32(&reg, AUTO_RSP_CFG_DUAL_CTS_EN, 0);
1360 rt2x00_set_field32(&reg, AUTO_RSP_CFG_ACK_CTS_PSM_BIT, 0);
1361 rt2x00usb_register_write(rt2x00dev, AUTO_RSP_CFG, reg);
1362
1363 rt2x00usb_register_read(rt2x00dev, CCK_PROT_CFG, &reg);
1364 rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_RATE, 8);
1365 rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_CTRL, 0);
1366 rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_NAV, 1);
1367 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_CCK, 1);
1368 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
1369 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_MM20, 1);
1370 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_MM40, 1);
1371 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_GF20, 1);
1372 rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_GF40, 1);
1373 rt2x00usb_register_write(rt2x00dev, CCK_PROT_CFG, reg);
1374
1375 rt2x00usb_register_read(rt2x00dev, OFDM_PROT_CFG, &reg);
1376 rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_RATE, 8);
1377 rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_CTRL, 0);
1378 rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_NAV, 1);
1379 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_CCK, 1);
1380 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
1381 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_MM20, 1);
1382 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_MM40, 1);
1383 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_GF20, 1);
1384 rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_GF40, 1);
1385 rt2x00usb_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
1386
1387 rt2x00usb_register_read(rt2x00dev, MM20_PROT_CFG, &reg);
1388 rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_RATE, 0x4004);
1389 rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_CTRL, 0);
1390 rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_NAV, 1);
1391 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_CCK, 1);
1392 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
1393 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_MM20, 1);
1394 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_MM40, 0);
1395 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_GF20, 1);
1396 rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_GF40, 0);
1397 rt2x00usb_register_write(rt2x00dev, MM20_PROT_CFG, reg);
1398
1399 rt2x00usb_register_read(rt2x00dev, MM40_PROT_CFG, &reg);
1400 rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_RATE, 0x4084);
1401 rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_CTRL, 0);
1402 rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_NAV, 1);
1403 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_CCK, 1);
1404 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
1405 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_MM20, 1);
1406 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_MM40, 1);
1407 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_GF20, 1);
1408 rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_GF40, 1);
1409 rt2x00usb_register_write(rt2x00dev, MM40_PROT_CFG, reg);
1410
1411 rt2x00usb_register_read(rt2x00dev, GF20_PROT_CFG, &reg);
1412 rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_RATE, 0x4004);
1413 rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_CTRL, 0);
1414 rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_NAV, 1);
1415 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_CCK, 1);
1416 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
1417 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_MM20, 1);
1418 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_MM40, 0);
1419 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_GF20, 1);
1420 rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_GF40, 0);
1421 rt2x00usb_register_write(rt2x00dev, GF20_PROT_CFG, reg);
1422
1423 rt2x00usb_register_read(rt2x00dev, GF40_PROT_CFG, &reg);
1424 rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_RATE, 0x4084);
1425 rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_CTRL, 0);
1426 rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_NAV, 1);
1427 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_CCK, 1);
1428 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
1429 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_MM20, 1);
1430 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_MM40, 1);
1431 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_GF20, 1);
1432 rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_GF40, 1);
1433 rt2x00usb_register_write(rt2x00dev, GF40_PROT_CFG, reg);
1434
1435 rt2x00usb_register_write(rt2x00dev, PBF_CFG, 0xf40006);
1436
1437 rt2x00usb_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
1438 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
1439 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_DMA_BUSY, 0);
1440 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
1441 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_RX_DMA_BUSY, 0);
1442 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_WP_DMA_BURST_SIZE, 3);
1443 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 0);
1444 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_BIG_ENDIAN, 0);
1445 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_RX_HDR_SCATTER, 0);
1446 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_HDR_SEG_LEN, 0);
1447 rt2x00usb_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
1448
1449 rt2x00usb_register_write(rt2x00dev, TXOP_CTRL_CFG, 0x0000583f);
1450 rt2x00usb_register_write(rt2x00dev, TXOP_HLDR_ET, 0x00000002);
1451
1452 rt2x00usb_register_read(rt2x00dev, TX_RTS_CFG, &reg);
1453 rt2x00_set_field32(&reg, TX_RTS_CFG_AUTO_RTS_RETRY_LIMIT, 32);
1454 rt2x00_set_field32(&reg, TX_RTS_CFG_RTS_THRES,
1455 IEEE80211_MAX_RTS_THRESHOLD);
1456 rt2x00_set_field32(&reg, TX_RTS_CFG_RTS_FBK_EN, 0);
1457 rt2x00usb_register_write(rt2x00dev, TX_RTS_CFG, reg);
1458
1459 rt2x00usb_register_write(rt2x00dev, EXP_ACK_TIME, 0x002400ca);
1460 rt2x00usb_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000003);
1461
1462 /*
1463 * ASIC will keep garbage value after boot, clear encryption keys.
1464 */
1465 for (i = 0; i < 4; i++)
1466 rt2x00usb_register_write(rt2x00dev,
1467 SHARED_KEY_MODE_ENTRY(i), 0);
1468
1469 for (i = 0; i < 256; i++) {
1470 u32 wcid[2] = { 0xffffffff, 0x00ffffff };
1471 rt2x00usb_register_multiwrite(rt2x00dev, MAC_WCID_ENTRY(i),
1472 wcid, sizeof(wcid));
1473
1474 rt2x00usb_register_write(rt2x00dev, MAC_WCID_ATTR_ENTRY(i), 1);
1475 rt2x00usb_register_write(rt2x00dev, MAC_IVEIV_ENTRY(i), 0);
1476 }
1477
1478 /*
1479 * Clear all beacons
1480 * For the Beacon base registers we only need to clear
1481 * the first byte since that byte contains the VALID and OWNER
1482 * bits which (when set to 0) will invalidate the entire beacon.
1483 */
1484 rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE0, 0);
1485 rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE1, 0);
1486 rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE2, 0);
1487 rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE3, 0);
1488 rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE4, 0);
1489 rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE5, 0);
1490 rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE6, 0);
1491 rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE7, 0);
1492
1493 rt2x00usb_register_read(rt2x00dev, USB_CYC_CFG, &reg);
1494 rt2x00_set_field32(&reg, USB_CYC_CFG_CLOCK_CYCLE, 30);
1495 rt2x00usb_register_write(rt2x00dev, USB_CYC_CFG, reg);
1496
1497 rt2x00usb_register_read(rt2x00dev, HT_FBK_CFG0, &reg);
1498 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS0FBK, 0);
1499 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS1FBK, 0);
1500 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS2FBK, 1);
1501 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS3FBK, 2);
1502 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS4FBK, 3);
1503 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS5FBK, 4);
1504 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS6FBK, 5);
1505 rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS7FBK, 6);
1506 rt2x00usb_register_write(rt2x00dev, HT_FBK_CFG0, reg);
1507
1508 rt2x00usb_register_read(rt2x00dev, HT_FBK_CFG1, &reg);
1509 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS8FBK, 8);
1510 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS9FBK, 8);
1511 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS10FBK, 9);
1512 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS11FBK, 10);
1513 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS12FBK, 11);
1514 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS13FBK, 12);
1515 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS14FBK, 13);
1516 rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS15FBK, 14);
1517 rt2x00usb_register_write(rt2x00dev, HT_FBK_CFG1, reg);
1518
1519 rt2x00usb_register_read(rt2x00dev, LG_FBK_CFG0, &reg);
1520 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS0FBK, 8);
1521 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS1FBK, 8);
1522 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS2FBK, 9);
1523 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS3FBK, 10);
1524 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS4FBK, 11);
1525 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS5FBK, 12);
1526 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS6FBK, 13);
1527 rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS7FBK, 14);
1528 rt2x00usb_register_write(rt2x00dev, LG_FBK_CFG0, reg);
1529
1530 rt2x00usb_register_read(rt2x00dev, LG_FBK_CFG1, &reg);
1531 rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS0FBK, 0);
1532 rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS1FBK, 0);
1533 rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS2FBK, 1);
1534 rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS3FBK, 2);
1535 rt2x00usb_register_write(rt2x00dev, LG_FBK_CFG1, reg);
1536
1537 /*
1538 * We must clear the error counters.
1539 * These registers are cleared on read,
1540 * so we may pass a useless variable to store the value.
1541 */
1542 rt2x00usb_register_read(rt2x00dev, RX_STA_CNT0, &reg);
1543 rt2x00usb_register_read(rt2x00dev, RX_STA_CNT1, &reg);
1544 rt2x00usb_register_read(rt2x00dev, RX_STA_CNT2, &reg);
1545 rt2x00usb_register_read(rt2x00dev, TX_STA_CNT0, &reg);
1546 rt2x00usb_register_read(rt2x00dev, TX_STA_CNT1, &reg);
1547 rt2x00usb_register_read(rt2x00dev, TX_STA_CNT2, &reg);
1548
1549 return 0;
1550}
1551
1552static int rt2800usb_wait_bbp_rf_ready(struct rt2x00_dev *rt2x00dev)
1553{
1554 unsigned int i;
1555 u32 reg;
1556
1557 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
1558 rt2x00usb_register_read(rt2x00dev, MAC_STATUS_CFG, &reg);
1559 if (!rt2x00_get_field32(reg, MAC_STATUS_CFG_BBP_RF_BUSY))
1560 return 0;
1561
1562 udelay(REGISTER_BUSY_DELAY);
1563 }
1564
1565 ERROR(rt2x00dev, "BBP/RF register access failed, aborting.\n");
1566 return -EACCES;
1567}
1568
1569static int rt2800usb_wait_bbp_ready(struct rt2x00_dev *rt2x00dev)
1570{
1571 unsigned int i;
1572 u8 value;
1573
1574 /*
1575 * BBP was enabled after firmware was loaded,
1576 * but we need to reactivate it now.
1577 */
1578 rt2x00usb_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
1579 rt2x00usb_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
1580 msleep(1);
1581
1582 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
1583 rt2800usb_bbp_read(rt2x00dev, 0, &value);
1584 if ((value != 0xff) && (value != 0x00))
1585 return 0;
1586 udelay(REGISTER_BUSY_DELAY);
1587 }
1588
1589 ERROR(rt2x00dev, "BBP register access failed, aborting.\n");
1590 return -EACCES;
1591}
1592
1593static int rt2800usb_init_bbp(struct rt2x00_dev *rt2x00dev)
1594{
1595 unsigned int i;
1596 u16 eeprom;
1597 u8 reg_id;
1598 u8 value;
1599
1600 if (unlikely(rt2800usb_wait_bbp_rf_ready(rt2x00dev) ||
1601 rt2800usb_wait_bbp_ready(rt2x00dev)))
1602 return -EACCES;
1603
1604 rt2800usb_bbp_write(rt2x00dev, 65, 0x2c);
1605 rt2800usb_bbp_write(rt2x00dev, 66, 0x38);
1606 rt2800usb_bbp_write(rt2x00dev, 69, 0x12);
1607 rt2800usb_bbp_write(rt2x00dev, 70, 0x0a);
1608 rt2800usb_bbp_write(rt2x00dev, 73, 0x10);
1609 rt2800usb_bbp_write(rt2x00dev, 81, 0x37);
1610 rt2800usb_bbp_write(rt2x00dev, 82, 0x62);
1611 rt2800usb_bbp_write(rt2x00dev, 83, 0x6a);
1612 rt2800usb_bbp_write(rt2x00dev, 84, 0x99);
1613 rt2800usb_bbp_write(rt2x00dev, 86, 0x00);
1614 rt2800usb_bbp_write(rt2x00dev, 91, 0x04);
1615 rt2800usb_bbp_write(rt2x00dev, 92, 0x00);
1616 rt2800usb_bbp_write(rt2x00dev, 103, 0x00);
1617 rt2800usb_bbp_write(rt2x00dev, 105, 0x05);
1618
1619 if (rt2x00_rev(&rt2x00dev->chip) == RT2860C_VERSION) {
1620 rt2800usb_bbp_write(rt2x00dev, 69, 0x16);
1621 rt2800usb_bbp_write(rt2x00dev, 73, 0x12);
1622 }
1623
1624 if (rt2x00_rev(&rt2x00dev->chip) > RT2860D_VERSION) {
1625 rt2800usb_bbp_write(rt2x00dev, 84, 0x19);
1626 }
1627
1628 if (rt2x00_rev(&rt2x00dev->chip) == RT3070_VERSION) {
1629 rt2800usb_bbp_write(rt2x00dev, 70, 0x0a);
1630 rt2800usb_bbp_write(rt2x00dev, 84, 0x99);
1631 rt2800usb_bbp_write(rt2x00dev, 105, 0x05);
1632 }
1633
1634 for (i = 0; i < EEPROM_BBP_SIZE; i++) {
1635 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBP_START + i, &eeprom);
1636
1637 if (eeprom != 0xffff && eeprom != 0x0000) {
1638 reg_id = rt2x00_get_field16(eeprom, EEPROM_BBP_REG_ID);
1639 value = rt2x00_get_field16(eeprom, EEPROM_BBP_VALUE);
1640 rt2800usb_bbp_write(rt2x00dev, reg_id, value);
1641 }
1642 }
1643
1644 return 0;
1645}
1646
1647static u8 rt2800usb_init_rx_filter(struct rt2x00_dev *rt2x00dev,
1648 bool bw40, u8 rfcsr24, u8 filter_target)
1649{
1650 unsigned int i;
1651 u8 bbp;
1652 u8 rfcsr;
1653 u8 passband;
1654 u8 stopband;
1655 u8 overtuned = 0;
1656
1657 rt2800usb_rfcsr_write(rt2x00dev, 24, rfcsr24);
1658
1659 rt2800usb_bbp_read(rt2x00dev, 4, &bbp);
1660 rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 2 * bw40);
1661 rt2800usb_bbp_write(rt2x00dev, 4, bbp);
1662
1663 rt2800usb_rfcsr_read(rt2x00dev, 22, &rfcsr);
1664 rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 1);
1665 rt2800usb_rfcsr_write(rt2x00dev, 22, rfcsr);
1666
1667 /*
1668 * Set power & frequency of passband test tone
1669 */
1670 rt2800usb_bbp_write(rt2x00dev, 24, 0);
1671
1672 for (i = 0; i < 100; i++) {
1673 rt2800usb_bbp_write(rt2x00dev, 25, 0x90);
1674 msleep(1);
1675
1676 rt2800usb_bbp_read(rt2x00dev, 55, &passband);
1677 if (passband)
1678 break;
1679 }
1680
1681 /*
1682 * Set power & frequency of stopband test tone
1683 */
1684 rt2800usb_bbp_write(rt2x00dev, 24, 0x06);
1685
1686 for (i = 0; i < 100; i++) {
1687 rt2800usb_bbp_write(rt2x00dev, 25, 0x90);
1688 msleep(1);
1689
1690 rt2800usb_bbp_read(rt2x00dev, 55, &stopband);
1691
1692 if ((passband - stopband) <= filter_target) {
1693 rfcsr24++;
1694 overtuned += ((passband - stopband) == filter_target);
1695 } else
1696 break;
1697
1698 rt2800usb_rfcsr_write(rt2x00dev, 24, rfcsr24);
1699 }
1700
1701 rfcsr24 -= !!overtuned;
1702
1703 rt2800usb_rfcsr_write(rt2x00dev, 24, rfcsr24);
1704 return rfcsr24;
1705}
1706
1707static int rt2800usb_init_rfcsr(struct rt2x00_dev *rt2x00dev)
1708{
1709 u8 rfcsr;
1710 u8 bbp;
1711
1712 if (rt2x00_rev(&rt2x00dev->chip) != RT3070_VERSION)
1713 return 0;
1714
1715 /*
1716 * Init RF calibration.
1717 */
1718 rt2800usb_rfcsr_read(rt2x00dev, 30, &rfcsr);
1719 rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 1);
1720 rt2800usb_rfcsr_write(rt2x00dev, 30, rfcsr);
1721 msleep(1);
1722 rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 0);
1723 rt2800usb_rfcsr_write(rt2x00dev, 30, rfcsr);
1724
1725 rt2800usb_rfcsr_write(rt2x00dev, 4, 0x40);
1726 rt2800usb_rfcsr_write(rt2x00dev, 5, 0x03);
1727 rt2800usb_rfcsr_write(rt2x00dev, 6, 0x02);
1728 rt2800usb_rfcsr_write(rt2x00dev, 7, 0x70);
1729 rt2800usb_rfcsr_write(rt2x00dev, 9, 0x0f);
1730 rt2800usb_rfcsr_write(rt2x00dev, 10, 0x71);
1731 rt2800usb_rfcsr_write(rt2x00dev, 11, 0x21);
1732 rt2800usb_rfcsr_write(rt2x00dev, 12, 0x7b);
1733 rt2800usb_rfcsr_write(rt2x00dev, 14, 0x90);
1734 rt2800usb_rfcsr_write(rt2x00dev, 15, 0x58);
1735 rt2800usb_rfcsr_write(rt2x00dev, 16, 0xb3);
1736 rt2800usb_rfcsr_write(rt2x00dev, 17, 0x92);
1737 rt2800usb_rfcsr_write(rt2x00dev, 18, 0x2c);
1738 rt2800usb_rfcsr_write(rt2x00dev, 19, 0x02);
1739 rt2800usb_rfcsr_write(rt2x00dev, 20, 0xba);
1740 rt2800usb_rfcsr_write(rt2x00dev, 21, 0xdb);
1741 rt2800usb_rfcsr_write(rt2x00dev, 24, 0x16);
1742 rt2800usb_rfcsr_write(rt2x00dev, 25, 0x01);
1743 rt2800usb_rfcsr_write(rt2x00dev, 27, 0x03);
1744 rt2800usb_rfcsr_write(rt2x00dev, 29, 0x1f);
1745
1746 /*
1747 * Set RX Filter calibration for 20MHz and 40MHz
1748 */
1749 rt2x00dev->calibration[0] =
1750 rt2800usb_init_rx_filter(rt2x00dev, false, 0x07, 0x16);
1751 rt2x00dev->calibration[1] =
1752 rt2800usb_init_rx_filter(rt2x00dev, true, 0x27, 0x19);
1753
1754 /*
1755 * Set back to initial state
1756 */
1757 rt2800usb_bbp_write(rt2x00dev, 24, 0);
1758
1759 rt2800usb_rfcsr_read(rt2x00dev, 22, &rfcsr);
1760 rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 0);
1761 rt2800usb_rfcsr_write(rt2x00dev, 22, rfcsr);
1762
1763 /*
1764 * set BBP back to BW20
1765 */
1766 rt2800usb_bbp_read(rt2x00dev, 4, &bbp);
1767 rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 0);
1768 rt2800usb_bbp_write(rt2x00dev, 4, bbp);
1769
1770 return 0;
1771}
1772
1773/*
1774 * Device state switch handlers. 233 * Device state switch handlers.
1775 */ 234 */
1776static void rt2800usb_toggle_rx(struct rt2x00_dev *rt2x00dev, 235static void rt2800usb_toggle_rx(struct rt2x00_dev *rt2x00dev,
@@ -1778,11 +237,11 @@ static void rt2800usb_toggle_rx(struct rt2x00_dev *rt2x00dev,
1778{ 237{
1779 u32 reg; 238 u32 reg;
1780 239
1781 rt2x00usb_register_read(rt2x00dev, MAC_SYS_CTRL, &reg); 240 rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
1782 rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX, 241 rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX,
1783 (state == STATE_RADIO_RX_ON) || 242 (state == STATE_RADIO_RX_ON) ||
1784 (state == STATE_RADIO_RX_ON_LINK)); 243 (state == STATE_RADIO_RX_ON_LINK));
1785 rt2x00usb_register_write(rt2x00dev, MAC_SYS_CTRL, reg); 244 rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
1786} 245}
1787 246
1788static int rt2800usb_wait_wpdma_ready(struct rt2x00_dev *rt2x00dev) 247static int rt2800usb_wait_wpdma_ready(struct rt2x00_dev *rt2x00dev)
@@ -1791,7 +250,7 @@ static int rt2800usb_wait_wpdma_ready(struct rt2x00_dev *rt2x00dev)
1791 u32 reg; 250 u32 reg;
1792 251
1793 for (i = 0; i < REGISTER_BUSY_COUNT; i++) { 252 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
1794 rt2x00usb_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg); 253 rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
1795 if (!rt2x00_get_field32(reg, WPDMA_GLO_CFG_TX_DMA_BUSY) && 254 if (!rt2x00_get_field32(reg, WPDMA_GLO_CFG_TX_DMA_BUSY) &&
1796 !rt2x00_get_field32(reg, WPDMA_GLO_CFG_RX_DMA_BUSY)) 255 !rt2x00_get_field32(reg, WPDMA_GLO_CFG_RX_DMA_BUSY))
1797 return 0; 256 return 0;
@@ -1812,25 +271,25 @@ static int rt2800usb_enable_radio(struct rt2x00_dev *rt2x00dev)
1812 * Initialize all registers. 271 * Initialize all registers.
1813 */ 272 */
1814 if (unlikely(rt2800usb_wait_wpdma_ready(rt2x00dev) || 273 if (unlikely(rt2800usb_wait_wpdma_ready(rt2x00dev) ||
1815 rt2800usb_init_registers(rt2x00dev) || 274 rt2800_init_registers(rt2x00dev) ||
1816 rt2800usb_init_bbp(rt2x00dev) || 275 rt2800_init_bbp(rt2x00dev) ||
1817 rt2800usb_init_rfcsr(rt2x00dev))) 276 rt2800_init_rfcsr(rt2x00dev)))
1818 return -EIO; 277 return -EIO;
1819 278
1820 rt2x00usb_register_read(rt2x00dev, MAC_SYS_CTRL, &reg); 279 rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
1821 rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_TX, 1); 280 rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_TX, 1);
1822 rt2x00usb_register_write(rt2x00dev, MAC_SYS_CTRL, reg); 281 rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
1823 282
1824 udelay(50); 283 udelay(50);
1825 284
1826 rt2x00usb_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg); 285 rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
1827 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1); 286 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1);
1828 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 1); 287 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 1);
1829 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 1); 288 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 1);
1830 rt2x00usb_register_write(rt2x00dev, WPDMA_GLO_CFG, reg); 289 rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
1831 290
1832 291
1833 rt2x00usb_register_read(rt2x00dev, USB_DMA_CFG, &reg); 292 rt2800_register_read(rt2x00dev, USB_DMA_CFG, &reg);
1834 rt2x00_set_field32(&reg, USB_DMA_CFG_PHY_CLEAR, 0); 293 rt2x00_set_field32(&reg, USB_DMA_CFG_PHY_CLEAR, 0);
1835 /* Don't use bulk in aggregation when working with USB 1.1 */ 294 /* Don't use bulk in aggregation when working with USB 1.1 */
1836 rt2x00_set_field32(&reg, USB_DMA_CFG_RX_BULK_AGG_EN, 295 rt2x00_set_field32(&reg, USB_DMA_CFG_RX_BULK_AGG_EN,
@@ -1844,26 +303,26 @@ static int rt2800usb_enable_radio(struct rt2x00_dev *rt2x00dev)
1844 ((RX_ENTRIES * DATA_FRAME_SIZE) / 1024) - 3); 303 ((RX_ENTRIES * DATA_FRAME_SIZE) / 1024) - 3);
1845 rt2x00_set_field32(&reg, USB_DMA_CFG_RX_BULK_EN, 1); 304 rt2x00_set_field32(&reg, USB_DMA_CFG_RX_BULK_EN, 1);
1846 rt2x00_set_field32(&reg, USB_DMA_CFG_TX_BULK_EN, 1); 305 rt2x00_set_field32(&reg, USB_DMA_CFG_TX_BULK_EN, 1);
1847 rt2x00usb_register_write(rt2x00dev, USB_DMA_CFG, reg); 306 rt2800_register_write(rt2x00dev, USB_DMA_CFG, reg);
1848 307
1849 rt2x00usb_register_read(rt2x00dev, MAC_SYS_CTRL, &reg); 308 rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
1850 rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_TX, 1); 309 rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_TX, 1);
1851 rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX, 1); 310 rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX, 1);
1852 rt2x00usb_register_write(rt2x00dev, MAC_SYS_CTRL, reg); 311 rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
1853 312
1854 /* 313 /*
1855 * Initialize LED control 314 * Initialize LED control
1856 */ 315 */
1857 rt2x00_eeprom_read(rt2x00dev, EEPROM_LED1, &word); 316 rt2x00_eeprom_read(rt2x00dev, EEPROM_LED1, &word);
1858 rt2800usb_mcu_request(rt2x00dev, MCU_LED_1, 0xff, 317 rt2800_mcu_request(rt2x00dev, MCU_LED_1, 0xff,
1859 word & 0xff, (word >> 8) & 0xff); 318 word & 0xff, (word >> 8) & 0xff);
1860 319
1861 rt2x00_eeprom_read(rt2x00dev, EEPROM_LED2, &word); 320 rt2x00_eeprom_read(rt2x00dev, EEPROM_LED2, &word);
1862 rt2800usb_mcu_request(rt2x00dev, MCU_LED_2, 0xff, 321 rt2800_mcu_request(rt2x00dev, MCU_LED_2, 0xff,
1863 word & 0xff, (word >> 8) & 0xff); 322 word & 0xff, (word >> 8) & 0xff);
1864 323
1865 rt2x00_eeprom_read(rt2x00dev, EEPROM_LED3, &word); 324 rt2x00_eeprom_read(rt2x00dev, EEPROM_LED3, &word);
1866 rt2800usb_mcu_request(rt2x00dev, MCU_LED_3, 0xff, 325 rt2800_mcu_request(rt2x00dev, MCU_LED_3, 0xff,
1867 word & 0xff, (word >> 8) & 0xff); 326 word & 0xff, (word >> 8) & 0xff);
1868 327
1869 return 0; 328 return 0;
@@ -1873,14 +332,14 @@ static void rt2800usb_disable_radio(struct rt2x00_dev *rt2x00dev)
1873{ 332{
1874 u32 reg; 333 u32 reg;
1875 334
1876 rt2x00usb_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg); 335 rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
1877 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0); 336 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
1878 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0); 337 rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
1879 rt2x00usb_register_write(rt2x00dev, WPDMA_GLO_CFG, reg); 338 rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
1880 339
1881 rt2x00usb_register_write(rt2x00dev, MAC_SYS_CTRL, 0); 340 rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, 0);
1882 rt2x00usb_register_write(rt2x00dev, PWR_PIN_CFG, 0); 341 rt2800_register_write(rt2x00dev, PWR_PIN_CFG, 0);
1883 rt2x00usb_register_write(rt2x00dev, TX_PIN_CFG, 0); 342 rt2800_register_write(rt2x00dev, TX_PIN_CFG, 0);
1884 343
1885 /* Wait for DMA, ignore error */ 344 /* Wait for DMA, ignore error */
1886 rt2800usb_wait_wpdma_ready(rt2x00dev); 345 rt2800usb_wait_wpdma_ready(rt2x00dev);
@@ -1892,9 +351,9 @@ static int rt2800usb_set_state(struct rt2x00_dev *rt2x00dev,
1892 enum dev_state state) 351 enum dev_state state)
1893{ 352{
1894 if (state == STATE_AWAKE) 353 if (state == STATE_AWAKE)
1895 rt2800usb_mcu_request(rt2x00dev, MCU_WAKEUP, 0xff, 0, 0); 354 rt2800_mcu_request(rt2x00dev, MCU_WAKEUP, 0xff, 0, 0);
1896 else 355 else
1897 rt2800usb_mcu_request(rt2x00dev, MCU_SLEEP, 0xff, 0, 2); 356 rt2800_mcu_request(rt2x00dev, MCU_SLEEP, 0xff, 0, 2);
1898 357
1899 return 0; 358 return 0;
1900} 359}
@@ -2048,9 +507,9 @@ static void rt2800usb_write_beacon(struct queue_entry *entry)
2048 * Disable beaconing while we are reloading the beacon data, 507 * Disable beaconing while we are reloading the beacon data,
2049 * otherwise we might be sending out invalid data. 508 * otherwise we might be sending out invalid data.
2050 */ 509 */
2051 rt2x00usb_register_read(rt2x00dev, BCN_TIME_CFG, &reg); 510 rt2800_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
2052 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 0); 511 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 0);
2053 rt2x00usb_register_write(rt2x00dev, BCN_TIME_CFG, reg); 512 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
2054 513
2055 /* 514 /*
2056 * Write entire beacon with descriptor to register. 515 * Write entire beacon with descriptor to register.
@@ -2093,12 +552,12 @@ static void rt2800usb_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
2093 return; 552 return;
2094 } 553 }
2095 554
2096 rt2x00usb_register_read(rt2x00dev, BCN_TIME_CFG, &reg); 555 rt2800_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
2097 if (!rt2x00_get_field32(reg, BCN_TIME_CFG_BEACON_GEN)) { 556 if (!rt2x00_get_field32(reg, BCN_TIME_CFG_BEACON_GEN)) {
2098 rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 1); 557 rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 1);
2099 rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 1); 558 rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 1);
2100 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 1); 559 rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 1);
2101 rt2x00usb_register_write(rt2x00dev, BCN_TIME_CFG, reg); 560 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
2102 } 561 }
2103} 562}
2104 563
@@ -2124,7 +583,7 @@ static void rt2800usb_fill_rxdone(struct queue_entry *entry,
2124 */ 583 */
2125 memcpy(skbdesc->desc, rxd, skbdesc->desc_len); 584 memcpy(skbdesc->desc, rxd, skbdesc->desc_len);
2126 rxd = (__le32 *)skbdesc->desc; 585 rxd = (__le32 *)skbdesc->desc;
2127 rxwi = &rxd[RXD_DESC_SIZE / sizeof(__le32)]; 586 rxwi = &rxd[RXINFO_DESC_SIZE / sizeof(__le32)];
2128 587
2129 /* 588 /*
2130 * It is now safe to read the descriptor on all architectures. 589 * It is now safe to read the descriptor on all architectures.
@@ -2326,7 +785,7 @@ static int rt2800usb_init_eeprom(struct rt2x00_dev *rt2x00dev)
2326 * Identify RF chipset. 785 * Identify RF chipset.
2327 */ 786 */
2328 value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE); 787 value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE);
2329 rt2x00usb_register_read(rt2x00dev, MAC_CSR0, &reg); 788 rt2800_register_read(rt2x00dev, MAC_CSR0, &reg);
2330 rt2x00_set_chip(rt2x00dev, RT2870, value, reg); 789 rt2x00_set_chip(rt2x00dev, RT2870, value, reg);
2331 790
2332 /* 791 /*
@@ -2385,9 +844,9 @@ static int rt2800usb_init_eeprom(struct rt2x00_dev *rt2x00dev)
2385 * Store led settings, for correct led behaviour. 844 * Store led settings, for correct led behaviour.
2386 */ 845 */
2387#ifdef CONFIG_RT2X00_LIB_LEDS 846#ifdef CONFIG_RT2X00_LIB_LEDS
2388 rt2800usb_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO); 847 rt2800_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO);
2389 rt2800usb_init_led(rt2x00dev, &rt2x00dev->led_assoc, LED_TYPE_ASSOC); 848 rt2800_init_led(rt2x00dev, &rt2x00dev->led_assoc, LED_TYPE_ASSOC);
2390 rt2800usb_init_led(rt2x00dev, &rt2x00dev->led_qual, LED_TYPE_QUALITY); 849 rt2800_init_led(rt2x00dev, &rt2x00dev->led_qual, LED_TYPE_QUALITY);
2391 850
2392 rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, 851 rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ,
2393 &rt2x00dev->led_mcu_reg); 852 &rt2x00dev->led_mcu_reg);
@@ -2600,10 +1059,25 @@ static int rt2800usb_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
2600 return 0; 1059 return 0;
2601} 1060}
2602 1061
1062static const struct rt2800_ops rt2800usb_rt2800_ops = {
1063 .register_read = rt2x00usb_register_read,
1064 .register_write = rt2x00usb_register_write,
1065 .register_write_lock = rt2x00usb_register_write_lock,
1066
1067 .register_multiread = rt2x00usb_register_multiread,
1068 .register_multiwrite = rt2x00usb_register_multiwrite,
1069
1070 .regbusy_read = rt2x00usb_regbusy_read,
1071};
1072
2603static int rt2800usb_probe_hw(struct rt2x00_dev *rt2x00dev) 1073static int rt2800usb_probe_hw(struct rt2x00_dev *rt2x00dev)
2604{ 1074{
2605 int retval; 1075 int retval;
2606 1076
1077 rt2x00_set_chip_intf(rt2x00dev, RT2X00_CHIP_INTF_USB);
1078
1079 rt2x00dev->priv = (void *)&rt2800usb_rt2800_ops;
1080
2607 /* 1081 /*
2608 * Allocate eeprom data. 1082 * Allocate eeprom data.
2609 */ 1083 */
@@ -2645,162 +1119,6 @@ static int rt2800usb_probe_hw(struct rt2x00_dev *rt2x00dev)
2645 return 0; 1119 return 0;
2646} 1120}
2647 1121
2648/*
2649 * IEEE80211 stack callback functions.
2650 */
2651static void rt2800usb_get_tkip_seq(struct ieee80211_hw *hw, u8 hw_key_idx,
2652 u32 *iv32, u16 *iv16)
2653{
2654 struct rt2x00_dev *rt2x00dev = hw->priv;
2655 struct mac_iveiv_entry iveiv_entry;
2656 u32 offset;
2657
2658 offset = MAC_IVEIV_ENTRY(hw_key_idx);
2659 rt2x00usb_register_multiread(rt2x00dev, offset,
2660 &iveiv_entry, sizeof(iveiv_entry));
2661
2662 memcpy(&iveiv_entry.iv[0], iv16, sizeof(iv16));
2663 memcpy(&iveiv_entry.iv[4], iv32, sizeof(iv32));
2664}
2665
2666static int rt2800usb_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
2667{
2668 struct rt2x00_dev *rt2x00dev = hw->priv;
2669 u32 reg;
2670 bool enabled = (value < IEEE80211_MAX_RTS_THRESHOLD);
2671
2672 rt2x00usb_register_read(rt2x00dev, TX_RTS_CFG, &reg);
2673 rt2x00_set_field32(&reg, TX_RTS_CFG_RTS_THRES, value);
2674 rt2x00usb_register_write(rt2x00dev, TX_RTS_CFG, reg);
2675
2676 rt2x00usb_register_read(rt2x00dev, CCK_PROT_CFG, &reg);
2677 rt2x00_set_field32(&reg, CCK_PROT_CFG_RTS_TH_EN, enabled);
2678 rt2x00usb_register_write(rt2x00dev, CCK_PROT_CFG, reg);
2679
2680 rt2x00usb_register_read(rt2x00dev, OFDM_PROT_CFG, &reg);
2681 rt2x00_set_field32(&reg, OFDM_PROT_CFG_RTS_TH_EN, enabled);
2682 rt2x00usb_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
2683
2684 rt2x00usb_register_read(rt2x00dev, MM20_PROT_CFG, &reg);
2685 rt2x00_set_field32(&reg, MM20_PROT_CFG_RTS_TH_EN, enabled);
2686 rt2x00usb_register_write(rt2x00dev, MM20_PROT_CFG, reg);
2687
2688 rt2x00usb_register_read(rt2x00dev, MM40_PROT_CFG, &reg);
2689 rt2x00_set_field32(&reg, MM40_PROT_CFG_RTS_TH_EN, enabled);
2690 rt2x00usb_register_write(rt2x00dev, MM40_PROT_CFG, reg);
2691
2692 rt2x00usb_register_read(rt2x00dev, GF20_PROT_CFG, &reg);
2693 rt2x00_set_field32(&reg, GF20_PROT_CFG_RTS_TH_EN, enabled);
2694 rt2x00usb_register_write(rt2x00dev, GF20_PROT_CFG, reg);
2695
2696 rt2x00usb_register_read(rt2x00dev, GF40_PROT_CFG, &reg);
2697 rt2x00_set_field32(&reg, GF40_PROT_CFG_RTS_TH_EN, enabled);
2698 rt2x00usb_register_write(rt2x00dev, GF40_PROT_CFG, reg);
2699
2700 return 0;
2701}
2702
2703static int rt2800usb_conf_tx(struct ieee80211_hw *hw, u16 queue_idx,
2704 const struct ieee80211_tx_queue_params *params)
2705{
2706 struct rt2x00_dev *rt2x00dev = hw->priv;
2707 struct data_queue *queue;
2708 struct rt2x00_field32 field;
2709 int retval;
2710 u32 reg;
2711 u32 offset;
2712
2713 /*
2714 * First pass the configuration through rt2x00lib, that will
2715 * update the queue settings and validate the input. After that
2716 * we are free to update the registers based on the value
2717 * in the queue parameter.
2718 */
2719 retval = rt2x00mac_conf_tx(hw, queue_idx, params);
2720 if (retval)
2721 return retval;
2722
2723 /*
2724 * We only need to perform additional register initialization
2725 * for WMM queues/
2726 */
2727 if (queue_idx >= 4)
2728 return 0;
2729
2730 queue = rt2x00queue_get_queue(rt2x00dev, queue_idx);
2731
2732 /* Update WMM TXOP register */
2733 offset = WMM_TXOP0_CFG + (sizeof(u32) * (!!(queue_idx & 2)));
2734 field.bit_offset = (queue_idx & 1) * 16;
2735 field.bit_mask = 0xffff << field.bit_offset;
2736
2737 rt2x00usb_register_read(rt2x00dev, offset, &reg);
2738 rt2x00_set_field32(&reg, field, queue->txop);
2739 rt2x00usb_register_write(rt2x00dev, offset, reg);
2740
2741 /* Update WMM registers */
2742 field.bit_offset = queue_idx * 4;
2743 field.bit_mask = 0xf << field.bit_offset;
2744
2745 rt2x00usb_register_read(rt2x00dev, WMM_AIFSN_CFG, &reg);
2746 rt2x00_set_field32(&reg, field, queue->aifs);
2747 rt2x00usb_register_write(rt2x00dev, WMM_AIFSN_CFG, reg);
2748
2749 rt2x00usb_register_read(rt2x00dev, WMM_CWMIN_CFG, &reg);
2750 rt2x00_set_field32(&reg, field, queue->cw_min);
2751 rt2x00usb_register_write(rt2x00dev, WMM_CWMIN_CFG, reg);
2752
2753 rt2x00usb_register_read(rt2x00dev, WMM_CWMAX_CFG, &reg);
2754 rt2x00_set_field32(&reg, field, queue->cw_max);
2755 rt2x00usb_register_write(rt2x00dev, WMM_CWMAX_CFG, reg);
2756
2757 /* Update EDCA registers */
2758 offset = EDCA_AC0_CFG + (sizeof(u32) * queue_idx);
2759
2760 rt2x00usb_register_read(rt2x00dev, offset, &reg);
2761 rt2x00_set_field32(&reg, EDCA_AC0_CFG_TX_OP, queue->txop);
2762 rt2x00_set_field32(&reg, EDCA_AC0_CFG_AIFSN, queue->aifs);
2763 rt2x00_set_field32(&reg, EDCA_AC0_CFG_CWMIN, queue->cw_min);
2764 rt2x00_set_field32(&reg, EDCA_AC0_CFG_CWMAX, queue->cw_max);
2765 rt2x00usb_register_write(rt2x00dev, offset, reg);
2766
2767 return 0;
2768}
2769
2770static u64 rt2800usb_get_tsf(struct ieee80211_hw *hw)
2771{
2772 struct rt2x00_dev *rt2x00dev = hw->priv;
2773 u64 tsf;
2774 u32 reg;
2775
2776 rt2x00usb_register_read(rt2x00dev, TSF_TIMER_DW1, &reg);
2777 tsf = (u64) rt2x00_get_field32(reg, TSF_TIMER_DW1_HIGH_WORD) << 32;
2778 rt2x00usb_register_read(rt2x00dev, TSF_TIMER_DW0, &reg);
2779 tsf |= rt2x00_get_field32(reg, TSF_TIMER_DW0_LOW_WORD);
2780
2781 return tsf;
2782}
2783
2784static const struct ieee80211_ops rt2800usb_mac80211_ops = {
2785 .tx = rt2x00mac_tx,
2786 .start = rt2x00mac_start,
2787 .stop = rt2x00mac_stop,
2788 .add_interface = rt2x00mac_add_interface,
2789 .remove_interface = rt2x00mac_remove_interface,
2790 .config = rt2x00mac_config,
2791 .configure_filter = rt2x00mac_configure_filter,
2792 .set_tim = rt2x00mac_set_tim,
2793 .set_key = rt2x00mac_set_key,
2794 .get_stats = rt2x00mac_get_stats,
2795 .get_tkip_seq = rt2800usb_get_tkip_seq,
2796 .set_rts_threshold = rt2800usb_set_rts_threshold,
2797 .bss_info_changed = rt2x00mac_bss_info_changed,
2798 .conf_tx = rt2800usb_conf_tx,
2799 .get_tx_stats = rt2x00mac_get_tx_stats,
2800 .get_tsf = rt2800usb_get_tsf,
2801 .rfkill_poll = rt2x00mac_rfkill_poll,
2802};
2803
2804static const struct rt2x00lib_ops rt2800usb_rt2x00_ops = { 1122static const struct rt2x00lib_ops rt2800usb_rt2x00_ops = {
2805 .probe_hw = rt2800usb_probe_hw, 1123 .probe_hw = rt2800usb_probe_hw,
2806 .get_firmware_name = rt2800usb_get_firmware_name, 1124 .get_firmware_name = rt2800usb_get_firmware_name,
@@ -2810,10 +1128,10 @@ static const struct rt2x00lib_ops rt2800usb_rt2x00_ops = {
2810 .uninitialize = rt2x00usb_uninitialize, 1128 .uninitialize = rt2x00usb_uninitialize,
2811 .clear_entry = rt2x00usb_clear_entry, 1129 .clear_entry = rt2x00usb_clear_entry,
2812 .set_device_state = rt2800usb_set_device_state, 1130 .set_device_state = rt2800usb_set_device_state,
2813 .rfkill_poll = rt2800usb_rfkill_poll, 1131 .rfkill_poll = rt2800_rfkill_poll,
2814 .link_stats = rt2800usb_link_stats, 1132 .link_stats = rt2800_link_stats,
2815 .reset_tuner = rt2800usb_reset_tuner, 1133 .reset_tuner = rt2800_reset_tuner,
2816 .link_tuner = rt2800usb_link_tuner, 1134 .link_tuner = rt2800_link_tuner,
2817 .write_tx_desc = rt2800usb_write_tx_desc, 1135 .write_tx_desc = rt2800usb_write_tx_desc,
2818 .write_tx_data = rt2x00usb_write_tx_data, 1136 .write_tx_data = rt2x00usb_write_tx_data,
2819 .write_beacon = rt2800usb_write_beacon, 1137 .write_beacon = rt2800usb_write_beacon,
@@ -2821,19 +1139,19 @@ static const struct rt2x00lib_ops rt2800usb_rt2x00_ops = {
2821 .kick_tx_queue = rt2800usb_kick_tx_queue, 1139 .kick_tx_queue = rt2800usb_kick_tx_queue,
2822 .kill_tx_queue = rt2x00usb_kill_tx_queue, 1140 .kill_tx_queue = rt2x00usb_kill_tx_queue,
2823 .fill_rxdone = rt2800usb_fill_rxdone, 1141 .fill_rxdone = rt2800usb_fill_rxdone,
2824 .config_shared_key = rt2800usb_config_shared_key, 1142 .config_shared_key = rt2800_config_shared_key,
2825 .config_pairwise_key = rt2800usb_config_pairwise_key, 1143 .config_pairwise_key = rt2800_config_pairwise_key,
2826 .config_filter = rt2800usb_config_filter, 1144 .config_filter = rt2800_config_filter,
2827 .config_intf = rt2800usb_config_intf, 1145 .config_intf = rt2800_config_intf,
2828 .config_erp = rt2800usb_config_erp, 1146 .config_erp = rt2800_config_erp,
2829 .config_ant = rt2800usb_config_ant, 1147 .config_ant = rt2800_config_ant,
2830 .config = rt2800usb_config, 1148 .config = rt2800_config,
2831}; 1149};
2832 1150
2833static const struct data_queue_desc rt2800usb_queue_rx = { 1151static const struct data_queue_desc rt2800usb_queue_rx = {
2834 .entry_num = RX_ENTRIES, 1152 .entry_num = RX_ENTRIES,
2835 .data_size = AGGREGATION_SIZE, 1153 .data_size = AGGREGATION_SIZE,
2836 .desc_size = RXD_DESC_SIZE + RXWI_DESC_SIZE, 1154 .desc_size = RXINFO_DESC_SIZE + RXWI_DESC_SIZE,
2837 .priv_size = sizeof(struct queue_entry_priv_usb), 1155 .priv_size = sizeof(struct queue_entry_priv_usb),
2838}; 1156};
2839 1157
@@ -2862,9 +1180,9 @@ static const struct rt2x00_ops rt2800usb_ops = {
2862 .tx = &rt2800usb_queue_tx, 1180 .tx = &rt2800usb_queue_tx,
2863 .bcn = &rt2800usb_queue_bcn, 1181 .bcn = &rt2800usb_queue_bcn,
2864 .lib = &rt2800usb_rt2x00_ops, 1182 .lib = &rt2800usb_rt2x00_ops,
2865 .hw = &rt2800usb_mac80211_ops, 1183 .hw = &rt2800_mac80211_ops,
2866#ifdef CONFIG_RT2X00_LIB_DEBUGFS 1184#ifdef CONFIG_RT2X00_LIB_DEBUGFS
2867 .debugfs = &rt2800usb_rt2x00debug, 1185 .debugfs = &rt2800_rt2x00debug,
2868#endif /* CONFIG_RT2X00_LIB_DEBUGFS */ 1186#endif /* CONFIG_RT2X00_LIB_DEBUGFS */
2869}; 1187};
2870 1188
diff --git a/drivers/net/wireless/rt2x00/rt2800usb.h b/drivers/net/wireless/rt2x00/rt2800usb.h
index 4d9991c9a51c..c9d7d40ee5fb 100644
--- a/drivers/net/wireless/rt2x00/rt2800usb.h
+++ b/drivers/net/wireless/rt2x00/rt2800usb.h
@@ -28,288 +28,10 @@
28#define RT2800USB_H 28#define RT2800USB_H
29 29
30/* 30/*
31 * RF chip defines.
32 *
33 * RF2820 2.4G 2T3R
34 * RF2850 2.4G/5G 2T3R
35 * RF2720 2.4G 1T2R
36 * RF2750 2.4G/5G 1T2R
37 * RF3020 2.4G 1T1R
38 * RF2020 2.4G B/G
39 * RF3021 2.4G 1T2R
40 * RF3022 2.4G 2T2R
41 * RF3052 2.4G 2T2R
42 */
43#define RF2820 0x0001
44#define RF2850 0x0002
45#define RF2720 0x0003
46#define RF2750 0x0004
47#define RF3020 0x0005
48#define RF2020 0x0006
49#define RF3021 0x0007
50#define RF3022 0x0008
51#define RF3052 0x0009
52
53/*
54 * RT2870 version
55 */
56#define RT2860C_VERSION 0x28600100
57#define RT2860D_VERSION 0x28600101
58#define RT2880E_VERSION 0x28720200
59#define RT2883_VERSION 0x28830300
60#define RT3070_VERSION 0x30700200
61
62/*
63 * Signal information.
64 * Defaul offset is required for RSSI <-> dBm conversion.
65 */
66#define DEFAULT_RSSI_OFFSET 120 /* FIXME */
67
68/*
69 * Register layout information.
70 */
71#define CSR_REG_BASE 0x1000
72#define CSR_REG_SIZE 0x0800
73#define EEPROM_BASE 0x0000
74#define EEPROM_SIZE 0x0110
75#define BBP_BASE 0x0000
76#define BBP_SIZE 0x0080
77#define RF_BASE 0x0004
78#define RF_SIZE 0x0010
79
80/*
81 * Number of TX queues.
82 */
83#define NUM_TX_QUEUES 4
84
85/*
86 * USB registers. 31 * USB registers.
87 */ 32 */
88 33
89/* 34/*
90 * HOST-MCU shared memory
91 */
92#define HOST_CMD_CSR 0x0404
93#define HOST_CMD_CSR_HOST_COMMAND FIELD32(0x000000ff)
94
95/*
96 * INT_SOURCE_CSR: Interrupt source register.
97 * Write one to clear corresponding bit.
98 * TX_FIFO_STATUS: FIFO Statistics is full, sw should read 0x171c
99 */
100#define INT_SOURCE_CSR 0x0200
101#define INT_SOURCE_CSR_RXDELAYINT FIELD32(0x00000001)
102#define INT_SOURCE_CSR_TXDELAYINT FIELD32(0x00000002)
103#define INT_SOURCE_CSR_RX_DONE FIELD32(0x00000004)
104#define INT_SOURCE_CSR_AC0_DMA_DONE FIELD32(0x00000008)
105#define INT_SOURCE_CSR_AC1_DMA_DONE FIELD32(0x00000010)
106#define INT_SOURCE_CSR_AC2_DMA_DONE FIELD32(0x00000020)
107#define INT_SOURCE_CSR_AC3_DMA_DONE FIELD32(0x00000040)
108#define INT_SOURCE_CSR_HCCA_DMA_DONE FIELD32(0x00000080)
109#define INT_SOURCE_CSR_MGMT_DMA_DONE FIELD32(0x00000100)
110#define INT_SOURCE_CSR_MCU_COMMAND FIELD32(0x00000200)
111#define INT_SOURCE_CSR_RXTX_COHERENT FIELD32(0x00000400)
112#define INT_SOURCE_CSR_TBTT FIELD32(0x00000800)
113#define INT_SOURCE_CSR_PRE_TBTT FIELD32(0x00001000)
114#define INT_SOURCE_CSR_TX_FIFO_STATUS FIELD32(0x00002000)
115#define INT_SOURCE_CSR_AUTO_WAKEUP FIELD32(0x00004000)
116#define INT_SOURCE_CSR_GPTIMER FIELD32(0x00008000)
117#define INT_SOURCE_CSR_RX_COHERENT FIELD32(0x00010000)
118#define INT_SOURCE_CSR_TX_COHERENT FIELD32(0x00020000)
119
120/*
121 * INT_MASK_CSR: Interrupt MASK register. 1: the interrupt is mask OFF.
122 */
123#define INT_MASK_CSR 0x0204
124#define INT_MASK_CSR_RXDELAYINT FIELD32(0x00000001)
125#define INT_MASK_CSR_TXDELAYINT FIELD32(0x00000002)
126#define INT_MASK_CSR_RX_DONE FIELD32(0x00000004)
127#define INT_MASK_CSR_AC0_DMA_DONE FIELD32(0x00000008)
128#define INT_MASK_CSR_AC1_DMA_DONE FIELD32(0x00000010)
129#define INT_MASK_CSR_AC2_DMA_DONE FIELD32(0x00000020)
130#define INT_MASK_CSR_AC3_DMA_DONE FIELD32(0x00000040)
131#define INT_MASK_CSR_HCCA_DMA_DONE FIELD32(0x00000080)
132#define INT_MASK_CSR_MGMT_DMA_DONE FIELD32(0x00000100)
133#define INT_MASK_CSR_MCU_COMMAND FIELD32(0x00000200)
134#define INT_MASK_CSR_RXTX_COHERENT FIELD32(0x00000400)
135#define INT_MASK_CSR_TBTT FIELD32(0x00000800)
136#define INT_MASK_CSR_PRE_TBTT FIELD32(0x00001000)
137#define INT_MASK_CSR_TX_FIFO_STATUS FIELD32(0x00002000)
138#define INT_MASK_CSR_AUTO_WAKEUP FIELD32(0x00004000)
139#define INT_MASK_CSR_GPTIMER FIELD32(0x00008000)
140#define INT_MASK_CSR_RX_COHERENT FIELD32(0x00010000)
141#define INT_MASK_CSR_TX_COHERENT FIELD32(0x00020000)
142
143/*
144 * WPDMA_GLO_CFG
145 */
146#define WPDMA_GLO_CFG 0x0208
147#define WPDMA_GLO_CFG_ENABLE_TX_DMA FIELD32(0x00000001)
148#define WPDMA_GLO_CFG_TX_DMA_BUSY FIELD32(0x00000002)
149#define WPDMA_GLO_CFG_ENABLE_RX_DMA FIELD32(0x00000004)
150#define WPDMA_GLO_CFG_RX_DMA_BUSY FIELD32(0x00000008)
151#define WPDMA_GLO_CFG_WP_DMA_BURST_SIZE FIELD32(0x00000030)
152#define WPDMA_GLO_CFG_TX_WRITEBACK_DONE FIELD32(0x00000040)
153#define WPDMA_GLO_CFG_BIG_ENDIAN FIELD32(0x00000080)
154#define WPDMA_GLO_CFG_RX_HDR_SCATTER FIELD32(0x0000ff00)
155#define WPDMA_GLO_CFG_HDR_SEG_LEN FIELD32(0xffff0000)
156
157/*
158 * WPDMA_RST_IDX
159 */
160#define WPDMA_RST_IDX 0x020c
161#define WPDMA_RST_IDX_DTX_IDX0 FIELD32(0x00000001)
162#define WPDMA_RST_IDX_DTX_IDX1 FIELD32(0x00000002)
163#define WPDMA_RST_IDX_DTX_IDX2 FIELD32(0x00000004)
164#define WPDMA_RST_IDX_DTX_IDX3 FIELD32(0x00000008)
165#define WPDMA_RST_IDX_DTX_IDX4 FIELD32(0x00000010)
166#define WPDMA_RST_IDX_DTX_IDX5 FIELD32(0x00000020)
167#define WPDMA_RST_IDX_DRX_IDX0 FIELD32(0x00010000)
168
169/*
170 * DELAY_INT_CFG
171 */
172#define DELAY_INT_CFG 0x0210
173#define DELAY_INT_CFG_RXMAX_PTIME FIELD32(0x000000ff)
174#define DELAY_INT_CFG_RXMAX_PINT FIELD32(0x00007f00)
175#define DELAY_INT_CFG_RXDLY_INT_EN FIELD32(0x00008000)
176#define DELAY_INT_CFG_TXMAX_PTIME FIELD32(0x00ff0000)
177#define DELAY_INT_CFG_TXMAX_PINT FIELD32(0x7f000000)
178#define DELAY_INT_CFG_TXDLY_INT_EN FIELD32(0x80000000)
179
180/*
181 * WMM_AIFSN_CFG: Aifsn for each EDCA AC
182 * AIFSN0: AC_BE
183 * AIFSN1: AC_BK
184 * AIFSN1: AC_VI
185 * AIFSN1: AC_VO
186 */
187#define WMM_AIFSN_CFG 0x0214
188#define WMM_AIFSN_CFG_AIFSN0 FIELD32(0x0000000f)
189#define WMM_AIFSN_CFG_AIFSN1 FIELD32(0x000000f0)
190#define WMM_AIFSN_CFG_AIFSN2 FIELD32(0x00000f00)
191#define WMM_AIFSN_CFG_AIFSN3 FIELD32(0x0000f000)
192
193/*
194 * WMM_CWMIN_CSR: CWmin for each EDCA AC
195 * CWMIN0: AC_BE
196 * CWMIN1: AC_BK
197 * CWMIN1: AC_VI
198 * CWMIN1: AC_VO
199 */
200#define WMM_CWMIN_CFG 0x0218
201#define WMM_CWMIN_CFG_CWMIN0 FIELD32(0x0000000f)
202#define WMM_CWMIN_CFG_CWMIN1 FIELD32(0x000000f0)
203#define WMM_CWMIN_CFG_CWMIN2 FIELD32(0x00000f00)
204#define WMM_CWMIN_CFG_CWMIN3 FIELD32(0x0000f000)
205
206/*
207 * WMM_CWMAX_CSR: CWmax for each EDCA AC
208 * CWMAX0: AC_BE
209 * CWMAX1: AC_BK
210 * CWMAX1: AC_VI
211 * CWMAX1: AC_VO
212 */
213#define WMM_CWMAX_CFG 0x021c
214#define WMM_CWMAX_CFG_CWMAX0 FIELD32(0x0000000f)
215#define WMM_CWMAX_CFG_CWMAX1 FIELD32(0x000000f0)
216#define WMM_CWMAX_CFG_CWMAX2 FIELD32(0x00000f00)
217#define WMM_CWMAX_CFG_CWMAX3 FIELD32(0x0000f000)
218
219/*
220 * AC_TXOP0: AC_BK/AC_BE TXOP register
221 * AC0TXOP: AC_BK in unit of 32us
222 * AC1TXOP: AC_BE in unit of 32us
223 */
224#define WMM_TXOP0_CFG 0x0220
225#define WMM_TXOP0_CFG_AC0TXOP FIELD32(0x0000ffff)
226#define WMM_TXOP0_CFG_AC1TXOP FIELD32(0xffff0000)
227
228/*
229 * AC_TXOP1: AC_VO/AC_VI TXOP register
230 * AC2TXOP: AC_VI in unit of 32us
231 * AC3TXOP: AC_VO in unit of 32us
232 */
233#define WMM_TXOP1_CFG 0x0224
234#define WMM_TXOP1_CFG_AC2TXOP FIELD32(0x0000ffff)
235#define WMM_TXOP1_CFG_AC3TXOP FIELD32(0xffff0000)
236
237/*
238 * GPIO_CTRL_CFG:
239 */
240#define GPIO_CTRL_CFG 0x0228
241#define GPIO_CTRL_CFG_BIT0 FIELD32(0x00000001)
242#define GPIO_CTRL_CFG_BIT1 FIELD32(0x00000002)
243#define GPIO_CTRL_CFG_BIT2 FIELD32(0x00000004)
244#define GPIO_CTRL_CFG_BIT3 FIELD32(0x00000008)
245#define GPIO_CTRL_CFG_BIT4 FIELD32(0x00000010)
246#define GPIO_CTRL_CFG_BIT5 FIELD32(0x00000020)
247#define GPIO_CTRL_CFG_BIT6 FIELD32(0x00000040)
248#define GPIO_CTRL_CFG_BIT7 FIELD32(0x00000080)
249#define GPIO_CTRL_CFG_BIT8 FIELD32(0x00000100)
250
251/*
252 * MCU_CMD_CFG
253 */
254#define MCU_CMD_CFG 0x022c
255
256/*
257 * AC_BK register offsets
258 */
259#define TX_BASE_PTR0 0x0230
260#define TX_MAX_CNT0 0x0234
261#define TX_CTX_IDX0 0x0238
262#define TX_DTX_IDX0 0x023c
263
264/*
265 * AC_BE register offsets
266 */
267#define TX_BASE_PTR1 0x0240
268#define TX_MAX_CNT1 0x0244
269#define TX_CTX_IDX1 0x0248
270#define TX_DTX_IDX1 0x024c
271
272/*
273 * AC_VI register offsets
274 */
275#define TX_BASE_PTR2 0x0250
276#define TX_MAX_CNT2 0x0254
277#define TX_CTX_IDX2 0x0258
278#define TX_DTX_IDX2 0x025c
279
280/*
281 * AC_VO register offsets
282 */
283#define TX_BASE_PTR3 0x0260
284#define TX_MAX_CNT3 0x0264
285#define TX_CTX_IDX3 0x0268
286#define TX_DTX_IDX3 0x026c
287
288/*
289 * HCCA register offsets
290 */
291#define TX_BASE_PTR4 0x0270
292#define TX_MAX_CNT4 0x0274
293#define TX_CTX_IDX4 0x0278
294#define TX_DTX_IDX4 0x027c
295
296/*
297 * MGMT register offsets
298 */
299#define TX_BASE_PTR5 0x0280
300#define TX_MAX_CNT5 0x0284
301#define TX_CTX_IDX5 0x0288
302#define TX_DTX_IDX5 0x028c
303
304/*
305 * RX register offsets
306 */
307#define RX_BASE_PTR 0x0290
308#define RX_MAX_CNT 0x0294
309#define RX_CRX_IDX 0x0298
310#define RX_DRX_IDX 0x029c
311
312/*
313 * USB_DMA_CFG 35 * USB_DMA_CFG
314 * RX_BULK_AGG_TIMEOUT: Rx Bulk Aggregation TimeOut in unit of 33ns. 36 * RX_BULK_AGG_TIMEOUT: Rx Bulk Aggregation TimeOut in unit of 33ns.
315 * RX_BULK_AGG_LIMIT: Rx Bulk Aggregation Limit in unit of 256 bytes. 37 * RX_BULK_AGG_LIMIT: Rx Bulk Aggregation Limit in unit of 256 bytes.
@@ -343,1448 +65,16 @@
343#define USB_CYC_CFG_CLOCK_CYCLE FIELD32(0x000000ff) 65#define USB_CYC_CFG_CLOCK_CYCLE FIELD32(0x000000ff)
344 66
345/* 67/*
346 * PBF_SYS_CTRL
347 * HOST_RAM_WRITE: enable Host program ram write selection
348 */
349#define PBF_SYS_CTRL 0x0400
350#define PBF_SYS_CTRL_READY FIELD32(0x00000080)
351#define PBF_SYS_CTRL_HOST_RAM_WRITE FIELD32(0x00010000)
352
353/*
354 * PBF registers
355 * Most are for debug. Driver doesn't touch PBF register.
356 */
357#define PBF_CFG 0x0408
358#define PBF_MAX_PCNT 0x040c
359#define PBF_CTRL 0x0410
360#define PBF_INT_STA 0x0414
361#define PBF_INT_ENA 0x0418
362
363/*
364 * BCN_OFFSET0:
365 */
366#define BCN_OFFSET0 0x042c
367#define BCN_OFFSET0_BCN0 FIELD32(0x000000ff)
368#define BCN_OFFSET0_BCN1 FIELD32(0x0000ff00)
369#define BCN_OFFSET0_BCN2 FIELD32(0x00ff0000)
370#define BCN_OFFSET0_BCN3 FIELD32(0xff000000)
371
372/*
373 * BCN_OFFSET1:
374 */
375#define BCN_OFFSET1 0x0430
376#define BCN_OFFSET1_BCN4 FIELD32(0x000000ff)
377#define BCN_OFFSET1_BCN5 FIELD32(0x0000ff00)
378#define BCN_OFFSET1_BCN6 FIELD32(0x00ff0000)
379#define BCN_OFFSET1_BCN7 FIELD32(0xff000000)
380
381/*
382 * PBF registers
383 * Most are for debug. Driver doesn't touch PBF register.
384 */
385#define TXRXQ_PCNT 0x0438
386#define PBF_DBG 0x043c
387
388/*
389 * RF registers
390 */
391#define RF_CSR_CFG 0x0500
392#define RF_CSR_CFG_DATA FIELD32(0x000000ff)
393#define RF_CSR_CFG_REGNUM FIELD32(0x00001f00)
394#define RF_CSR_CFG_WRITE FIELD32(0x00010000)
395#define RF_CSR_CFG_BUSY FIELD32(0x00020000)
396
397/*
398 * MAC Control/Status Registers(CSR).
399 * Some values are set in TU, whereas 1 TU == 1024 us.
400 */
401
402/*
403 * MAC_CSR0: ASIC revision number.
404 * ASIC_REV: 0
405 * ASIC_VER: 2870
406 */
407#define MAC_CSR0 0x1000
408#define MAC_CSR0_ASIC_REV FIELD32(0x0000ffff)
409#define MAC_CSR0_ASIC_VER FIELD32(0xffff0000)
410
411/*
412 * MAC_SYS_CTRL:
413 */
414#define MAC_SYS_CTRL 0x1004
415#define MAC_SYS_CTRL_RESET_CSR FIELD32(0x00000001)
416#define MAC_SYS_CTRL_RESET_BBP FIELD32(0x00000002)
417#define MAC_SYS_CTRL_ENABLE_TX FIELD32(0x00000004)
418#define MAC_SYS_CTRL_ENABLE_RX FIELD32(0x00000008)
419#define MAC_SYS_CTRL_CONTINUOUS_TX FIELD32(0x00000010)
420#define MAC_SYS_CTRL_LOOPBACK FIELD32(0x00000020)
421#define MAC_SYS_CTRL_WLAN_HALT FIELD32(0x00000040)
422#define MAC_SYS_CTRL_RX_TIMESTAMP FIELD32(0x00000080)
423
424/*
425 * MAC_ADDR_DW0: STA MAC register 0
426 */
427#define MAC_ADDR_DW0 0x1008
428#define MAC_ADDR_DW0_BYTE0 FIELD32(0x000000ff)
429#define MAC_ADDR_DW0_BYTE1 FIELD32(0x0000ff00)
430#define MAC_ADDR_DW0_BYTE2 FIELD32(0x00ff0000)
431#define MAC_ADDR_DW0_BYTE3 FIELD32(0xff000000)
432
433/*
434 * MAC_ADDR_DW1: STA MAC register 1
435 * UNICAST_TO_ME_MASK:
436 * Used to mask off bits from byte 5 of the MAC address
437 * to determine the UNICAST_TO_ME bit for RX frames.
438 * The full mask is complemented by BSS_ID_MASK:
439 * MASK = BSS_ID_MASK & UNICAST_TO_ME_MASK
440 */
441#define MAC_ADDR_DW1 0x100c
442#define MAC_ADDR_DW1_BYTE4 FIELD32(0x000000ff)
443#define MAC_ADDR_DW1_BYTE5 FIELD32(0x0000ff00)
444#define MAC_ADDR_DW1_UNICAST_TO_ME_MASK FIELD32(0x00ff0000)
445
446/*
447 * MAC_BSSID_DW0: BSSID register 0
448 */
449#define MAC_BSSID_DW0 0x1010
450#define MAC_BSSID_DW0_BYTE0 FIELD32(0x000000ff)
451#define MAC_BSSID_DW0_BYTE1 FIELD32(0x0000ff00)
452#define MAC_BSSID_DW0_BYTE2 FIELD32(0x00ff0000)
453#define MAC_BSSID_DW0_BYTE3 FIELD32(0xff000000)
454
455/*
456 * MAC_BSSID_DW1: BSSID register 1
457 * BSS_ID_MASK:
458 * 0: 1-BSSID mode (BSS index = 0)
459 * 1: 2-BSSID mode (BSS index: Byte5, bit 0)
460 * 2: 4-BSSID mode (BSS index: byte5, bit 0 - 1)
461 * 3: 8-BSSID mode (BSS index: byte5, bit 0 - 2)
462 * This mask is used to mask off bits 0, 1 and 2 of byte 5 of the
463 * BSSID. This will make sure that those bits will be ignored
464 * when determining the MY_BSS of RX frames.
465 */
466#define MAC_BSSID_DW1 0x1014
467#define MAC_BSSID_DW1_BYTE4 FIELD32(0x000000ff)
468#define MAC_BSSID_DW1_BYTE5 FIELD32(0x0000ff00)
469#define MAC_BSSID_DW1_BSS_ID_MASK FIELD32(0x00030000)
470#define MAC_BSSID_DW1_BSS_BCN_NUM FIELD32(0x001c0000)
471
472/*
473 * MAX_LEN_CFG: Maximum frame length register.
474 * MAX_MPDU: rt2860b max 16k bytes
475 * MAX_PSDU: Maximum PSDU length
476 * (power factor) 0:2^13, 1:2^14, 2:2^15, 3:2^16
477 */
478#define MAX_LEN_CFG 0x1018
479#define MAX_LEN_CFG_MAX_MPDU FIELD32(0x00000fff)
480#define MAX_LEN_CFG_MAX_PSDU FIELD32(0x00003000)
481#define MAX_LEN_CFG_MIN_PSDU FIELD32(0x0000c000)
482#define MAX_LEN_CFG_MIN_MPDU FIELD32(0x000f0000)
483
484/*
485 * BBP_CSR_CFG: BBP serial control register
486 * VALUE: Register value to program into BBP
487 * REG_NUM: Selected BBP register
488 * READ_CONTROL: 0 write BBP, 1 read BBP
489 * BUSY: ASIC is busy executing BBP commands
490 * BBP_PAR_DUR: 0 4 MAC clocks, 1 8 MAC clocks
491 * BBP_RW_MODE: 0 serial, 1 paralell
492 */
493#define BBP_CSR_CFG 0x101c
494#define BBP_CSR_CFG_VALUE FIELD32(0x000000ff)
495#define BBP_CSR_CFG_REGNUM FIELD32(0x0000ff00)
496#define BBP_CSR_CFG_READ_CONTROL FIELD32(0x00010000)
497#define BBP_CSR_CFG_BUSY FIELD32(0x00020000)
498#define BBP_CSR_CFG_BBP_PAR_DUR FIELD32(0x00040000)
499#define BBP_CSR_CFG_BBP_RW_MODE FIELD32(0x00080000)
500
501/*
502 * RF_CSR_CFG0: RF control register
503 * REGID_AND_VALUE: Register value to program into RF
504 * BITWIDTH: Selected RF register
505 * STANDBYMODE: 0 high when standby, 1 low when standby
506 * SEL: 0 RF_LE0 activate, 1 RF_LE1 activate
507 * BUSY: ASIC is busy executing RF commands
508 */
509#define RF_CSR_CFG0 0x1020
510#define RF_CSR_CFG0_REGID_AND_VALUE FIELD32(0x00ffffff)
511#define RF_CSR_CFG0_BITWIDTH FIELD32(0x1f000000)
512#define RF_CSR_CFG0_REG_VALUE_BW FIELD32(0x1fffffff)
513#define RF_CSR_CFG0_STANDBYMODE FIELD32(0x20000000)
514#define RF_CSR_CFG0_SEL FIELD32(0x40000000)
515#define RF_CSR_CFG0_BUSY FIELD32(0x80000000)
516
517/*
518 * RF_CSR_CFG1: RF control register
519 * REGID_AND_VALUE: Register value to program into RF
520 * RFGAP: Gap between BB_CONTROL_RF and RF_LE
521 * 0: 3 system clock cycle (37.5usec)
522 * 1: 5 system clock cycle (62.5usec)
523 */
524#define RF_CSR_CFG1 0x1024
525#define RF_CSR_CFG1_REGID_AND_VALUE FIELD32(0x00ffffff)
526#define RF_CSR_CFG1_RFGAP FIELD32(0x1f000000)
527
528/*
529 * RF_CSR_CFG2: RF control register
530 * VALUE: Register value to program into RF
531 * RFGAP: Gap between BB_CONTROL_RF and RF_LE
532 * 0: 3 system clock cycle (37.5usec)
533 * 1: 5 system clock cycle (62.5usec)
534 */
535#define RF_CSR_CFG2 0x1028
536#define RF_CSR_CFG2_VALUE FIELD32(0x00ffffff)
537
538/*
539 * LED_CFG: LED control
540 * color LED's:
541 * 0: off
542 * 1: blinking upon TX2
543 * 2: periodic slow blinking
544 * 3: always on
545 * LED polarity:
546 * 0: active low
547 * 1: active high
548 */
549#define LED_CFG 0x102c
550#define LED_CFG_ON_PERIOD FIELD32(0x000000ff)
551#define LED_CFG_OFF_PERIOD FIELD32(0x0000ff00)
552#define LED_CFG_SLOW_BLINK_PERIOD FIELD32(0x003f0000)
553#define LED_CFG_R_LED_MODE FIELD32(0x03000000)
554#define LED_CFG_G_LED_MODE FIELD32(0x0c000000)
555#define LED_CFG_Y_LED_MODE FIELD32(0x30000000)
556#define LED_CFG_LED_POLAR FIELD32(0x40000000)
557
558/*
559 * XIFS_TIME_CFG: MAC timing
560 * CCKM_SIFS_TIME: unit 1us. Applied after CCK RX/TX
561 * OFDM_SIFS_TIME: unit 1us. Applied after OFDM RX/TX
562 * OFDM_XIFS_TIME: unit 1us. Applied after OFDM RX
563 * when MAC doesn't reference BBP signal BBRXEND
564 * EIFS: unit 1us
565 * BB_RXEND_ENABLE: reference RXEND signal to begin XIFS defer
566 *
567 */
568#define XIFS_TIME_CFG 0x1100
569#define XIFS_TIME_CFG_CCKM_SIFS_TIME FIELD32(0x000000ff)
570#define XIFS_TIME_CFG_OFDM_SIFS_TIME FIELD32(0x0000ff00)
571#define XIFS_TIME_CFG_OFDM_XIFS_TIME FIELD32(0x000f0000)
572#define XIFS_TIME_CFG_EIFS FIELD32(0x1ff00000)
573#define XIFS_TIME_CFG_BB_RXEND_ENABLE FIELD32(0x20000000)
574
575/*
576 * BKOFF_SLOT_CFG:
577 */
578#define BKOFF_SLOT_CFG 0x1104
579#define BKOFF_SLOT_CFG_SLOT_TIME FIELD32(0x000000ff)
580#define BKOFF_SLOT_CFG_CC_DELAY_TIME FIELD32(0x0000ff00)
581
582/*
583 * NAV_TIME_CFG:
584 */
585#define NAV_TIME_CFG 0x1108
586#define NAV_TIME_CFG_SIFS FIELD32(0x000000ff)
587#define NAV_TIME_CFG_SLOT_TIME FIELD32(0x0000ff00)
588#define NAV_TIME_CFG_EIFS FIELD32(0x01ff0000)
589#define NAV_TIME_ZERO_SIFS FIELD32(0x02000000)
590
591/*
592 * CH_TIME_CFG: count as channel busy
593 */
594#define CH_TIME_CFG 0x110c
595
596/*
597 * PBF_LIFE_TIMER: TX/RX MPDU timestamp timer (free run) Unit: 1us
598 */
599#define PBF_LIFE_TIMER 0x1110
600
601/*
602 * BCN_TIME_CFG:
603 * BEACON_INTERVAL: in unit of 1/16 TU
604 * TSF_TICKING: Enable TSF auto counting
605 * TSF_SYNC: Enable TSF sync, 00: disable, 01: infra mode, 10: ad-hoc mode
606 * BEACON_GEN: Enable beacon generator
607 */
608#define BCN_TIME_CFG 0x1114
609#define BCN_TIME_CFG_BEACON_INTERVAL FIELD32(0x0000ffff)
610#define BCN_TIME_CFG_TSF_TICKING FIELD32(0x00010000)
611#define BCN_TIME_CFG_TSF_SYNC FIELD32(0x00060000)
612#define BCN_TIME_CFG_TBTT_ENABLE FIELD32(0x00080000)
613#define BCN_TIME_CFG_BEACON_GEN FIELD32(0x00100000)
614#define BCN_TIME_CFG_TX_TIME_COMPENSATE FIELD32(0xf0000000)
615
616/*
617 * TBTT_SYNC_CFG:
618 */
619#define TBTT_SYNC_CFG 0x1118
620
621/*
622 * TSF_TIMER_DW0: Local lsb TSF timer, read-only
623 */
624#define TSF_TIMER_DW0 0x111c
625#define TSF_TIMER_DW0_LOW_WORD FIELD32(0xffffffff)
626
627/*
628 * TSF_TIMER_DW1: Local msb TSF timer, read-only
629 */
630#define TSF_TIMER_DW1 0x1120
631#define TSF_TIMER_DW1_HIGH_WORD FIELD32(0xffffffff)
632
633/*
634 * TBTT_TIMER: TImer remains till next TBTT, read-only
635 */
636#define TBTT_TIMER 0x1124
637
638/*
639 * INT_TIMER_CFG:
640 */
641#define INT_TIMER_CFG 0x1128
642
643/*
644 * INT_TIMER_EN: GP-timer and pre-tbtt Int enable
645 */
646#define INT_TIMER_EN 0x112c
647
648/*
649 * CH_IDLE_STA: channel idle time
650 */
651#define CH_IDLE_STA 0x1130
652
653/*
654 * CH_BUSY_STA: channel busy time
655 */
656#define CH_BUSY_STA 0x1134
657
658/*
659 * MAC_STATUS_CFG:
660 * BBP_RF_BUSY: When set to 0, BBP and RF are stable.
661 * if 1 or higher one of the 2 registers is busy.
662 */
663#define MAC_STATUS_CFG 0x1200
664#define MAC_STATUS_CFG_BBP_RF_BUSY FIELD32(0x00000003)
665
666/*
667 * PWR_PIN_CFG:
668 */
669#define PWR_PIN_CFG 0x1204
670
671/*
672 * AUTOWAKEUP_CFG: Manual power control / status register
673 * TBCN_BEFORE_WAKE: ForceWake has high privilege than PutToSleep when both set
674 * AUTOWAKE: 0:sleep, 1:awake
675 */
676#define AUTOWAKEUP_CFG 0x1208
677#define AUTOWAKEUP_CFG_AUTO_LEAD_TIME FIELD32(0x000000ff)
678#define AUTOWAKEUP_CFG_TBCN_BEFORE_WAKE FIELD32(0x00007f00)
679#define AUTOWAKEUP_CFG_AUTOWAKE FIELD32(0x00008000)
680
681/*
682 * EDCA_AC0_CFG:
683 */
684#define EDCA_AC0_CFG 0x1300
685#define EDCA_AC0_CFG_TX_OP FIELD32(0x000000ff)
686#define EDCA_AC0_CFG_AIFSN FIELD32(0x00000f00)
687#define EDCA_AC0_CFG_CWMIN FIELD32(0x0000f000)
688#define EDCA_AC0_CFG_CWMAX FIELD32(0x000f0000)
689
690/*
691 * EDCA_AC1_CFG:
692 */
693#define EDCA_AC1_CFG 0x1304
694#define EDCA_AC1_CFG_TX_OP FIELD32(0x000000ff)
695#define EDCA_AC1_CFG_AIFSN FIELD32(0x00000f00)
696#define EDCA_AC1_CFG_CWMIN FIELD32(0x0000f000)
697#define EDCA_AC1_CFG_CWMAX FIELD32(0x000f0000)
698
699/*
700 * EDCA_AC2_CFG:
701 */
702#define EDCA_AC2_CFG 0x1308
703#define EDCA_AC2_CFG_TX_OP FIELD32(0x000000ff)
704#define EDCA_AC2_CFG_AIFSN FIELD32(0x00000f00)
705#define EDCA_AC2_CFG_CWMIN FIELD32(0x0000f000)
706#define EDCA_AC2_CFG_CWMAX FIELD32(0x000f0000)
707
708/*
709 * EDCA_AC3_CFG:
710 */
711#define EDCA_AC3_CFG 0x130c
712#define EDCA_AC3_CFG_TX_OP FIELD32(0x000000ff)
713#define EDCA_AC3_CFG_AIFSN FIELD32(0x00000f00)
714#define EDCA_AC3_CFG_CWMIN FIELD32(0x0000f000)
715#define EDCA_AC3_CFG_CWMAX FIELD32(0x000f0000)
716
717/*
718 * EDCA_TID_AC_MAP:
719 */
720#define EDCA_TID_AC_MAP 0x1310
721
722/*
723 * TX_PWR_CFG_0:
724 */
725#define TX_PWR_CFG_0 0x1314
726#define TX_PWR_CFG_0_1MBS FIELD32(0x0000000f)
727#define TX_PWR_CFG_0_2MBS FIELD32(0x000000f0)
728#define TX_PWR_CFG_0_55MBS FIELD32(0x00000f00)
729#define TX_PWR_CFG_0_11MBS FIELD32(0x0000f000)
730#define TX_PWR_CFG_0_6MBS FIELD32(0x000f0000)
731#define TX_PWR_CFG_0_9MBS FIELD32(0x00f00000)
732#define TX_PWR_CFG_0_12MBS FIELD32(0x0f000000)
733#define TX_PWR_CFG_0_18MBS FIELD32(0xf0000000)
734
735/*
736 * TX_PWR_CFG_1:
737 */
738#define TX_PWR_CFG_1 0x1318
739#define TX_PWR_CFG_1_24MBS FIELD32(0x0000000f)
740#define TX_PWR_CFG_1_36MBS FIELD32(0x000000f0)
741#define TX_PWR_CFG_1_48MBS FIELD32(0x00000f00)
742#define TX_PWR_CFG_1_54MBS FIELD32(0x0000f000)
743#define TX_PWR_CFG_1_MCS0 FIELD32(0x000f0000)
744#define TX_PWR_CFG_1_MCS1 FIELD32(0x00f00000)
745#define TX_PWR_CFG_1_MCS2 FIELD32(0x0f000000)
746#define TX_PWR_CFG_1_MCS3 FIELD32(0xf0000000)
747
748/*
749 * TX_PWR_CFG_2:
750 */
751#define TX_PWR_CFG_2 0x131c
752#define TX_PWR_CFG_2_MCS4 FIELD32(0x0000000f)
753#define TX_PWR_CFG_2_MCS5 FIELD32(0x000000f0)
754#define TX_PWR_CFG_2_MCS6 FIELD32(0x00000f00)
755#define TX_PWR_CFG_2_MCS7 FIELD32(0x0000f000)
756#define TX_PWR_CFG_2_MCS8 FIELD32(0x000f0000)
757#define TX_PWR_CFG_2_MCS9 FIELD32(0x00f00000)
758#define TX_PWR_CFG_2_MCS10 FIELD32(0x0f000000)
759#define TX_PWR_CFG_2_MCS11 FIELD32(0xf0000000)
760
761/*
762 * TX_PWR_CFG_3:
763 */
764#define TX_PWR_CFG_3 0x1320
765#define TX_PWR_CFG_3_MCS12 FIELD32(0x0000000f)
766#define TX_PWR_CFG_3_MCS13 FIELD32(0x000000f0)
767#define TX_PWR_CFG_3_MCS14 FIELD32(0x00000f00)
768#define TX_PWR_CFG_3_MCS15 FIELD32(0x0000f000)
769#define TX_PWR_CFG_3_UKNOWN1 FIELD32(0x000f0000)
770#define TX_PWR_CFG_3_UKNOWN2 FIELD32(0x00f00000)
771#define TX_PWR_CFG_3_UKNOWN3 FIELD32(0x0f000000)
772#define TX_PWR_CFG_3_UKNOWN4 FIELD32(0xf0000000)
773
774/*
775 * TX_PWR_CFG_4:
776 */
777#define TX_PWR_CFG_4 0x1324
778#define TX_PWR_CFG_4_UKNOWN5 FIELD32(0x0000000f)
779#define TX_PWR_CFG_4_UKNOWN6 FIELD32(0x000000f0)
780#define TX_PWR_CFG_4_UKNOWN7 FIELD32(0x00000f00)
781#define TX_PWR_CFG_4_UKNOWN8 FIELD32(0x0000f000)
782
783/*
784 * TX_PIN_CFG:
785 */
786#define TX_PIN_CFG 0x1328
787#define TX_PIN_CFG_PA_PE_A0_EN FIELD32(0x00000001)
788#define TX_PIN_CFG_PA_PE_G0_EN FIELD32(0x00000002)
789#define TX_PIN_CFG_PA_PE_A1_EN FIELD32(0x00000004)
790#define TX_PIN_CFG_PA_PE_G1_EN FIELD32(0x00000008)
791#define TX_PIN_CFG_PA_PE_A0_POL FIELD32(0x00000010)
792#define TX_PIN_CFG_PA_PE_G0_POL FIELD32(0x00000020)
793#define TX_PIN_CFG_PA_PE_A1_POL FIELD32(0x00000040)
794#define TX_PIN_CFG_PA_PE_G1_POL FIELD32(0x00000080)
795#define TX_PIN_CFG_LNA_PE_A0_EN FIELD32(0x00000100)
796#define TX_PIN_CFG_LNA_PE_G0_EN FIELD32(0x00000200)
797#define TX_PIN_CFG_LNA_PE_A1_EN FIELD32(0x00000400)
798#define TX_PIN_CFG_LNA_PE_G1_EN FIELD32(0x00000800)
799#define TX_PIN_CFG_LNA_PE_A0_POL FIELD32(0x00001000)
800#define TX_PIN_CFG_LNA_PE_G0_POL FIELD32(0x00002000)
801#define TX_PIN_CFG_LNA_PE_A1_POL FIELD32(0x00004000)
802#define TX_PIN_CFG_LNA_PE_G1_POL FIELD32(0x00008000)
803#define TX_PIN_CFG_RFTR_EN FIELD32(0x00010000)
804#define TX_PIN_CFG_RFTR_POL FIELD32(0x00020000)
805#define TX_PIN_CFG_TRSW_EN FIELD32(0x00040000)
806#define TX_PIN_CFG_TRSW_POL FIELD32(0x00080000)
807
808/*
809 * TX_BAND_CFG: 0x1 use upper 20MHz, 0x0 use lower 20MHz
810 */
811#define TX_BAND_CFG 0x132c
812#define TX_BAND_CFG_HT40_PLUS FIELD32(0x00000001)
813#define TX_BAND_CFG_A FIELD32(0x00000002)
814#define TX_BAND_CFG_BG FIELD32(0x00000004)
815
816/*
817 * TX_SW_CFG0:
818 */
819#define TX_SW_CFG0 0x1330
820
821/*
822 * TX_SW_CFG1:
823 */
824#define TX_SW_CFG1 0x1334
825
826/*
827 * TX_SW_CFG2:
828 */
829#define TX_SW_CFG2 0x1338
830
831/*
832 * TXOP_THRES_CFG:
833 */
834#define TXOP_THRES_CFG 0x133c
835
836/*
837 * TXOP_CTRL_CFG:
838 */
839#define TXOP_CTRL_CFG 0x1340
840
841/*
842 * TX_RTS_CFG:
843 * RTS_THRES: unit:byte
844 * RTS_FBK_EN: enable rts rate fallback
845 */
846#define TX_RTS_CFG 0x1344
847#define TX_RTS_CFG_AUTO_RTS_RETRY_LIMIT FIELD32(0x000000ff)
848#define TX_RTS_CFG_RTS_THRES FIELD32(0x00ffff00)
849#define TX_RTS_CFG_RTS_FBK_EN FIELD32(0x01000000)
850
851/*
852 * TX_TIMEOUT_CFG:
853 * MPDU_LIFETIME: expiration time = 2^(9+MPDU LIFE TIME) us
854 * RX_ACK_TIMEOUT: unit:slot. Used for TX procedure
855 * TX_OP_TIMEOUT: TXOP timeout value for TXOP truncation.
856 * it is recommended that:
857 * (SLOT_TIME) > (TX_OP_TIMEOUT) > (RX_ACK_TIMEOUT)
858 */
859#define TX_TIMEOUT_CFG 0x1348
860#define TX_TIMEOUT_CFG_MPDU_LIFETIME FIELD32(0x000000f0)
861#define TX_TIMEOUT_CFG_RX_ACK_TIMEOUT FIELD32(0x0000ff00)
862#define TX_TIMEOUT_CFG_TX_OP_TIMEOUT FIELD32(0x00ff0000)
863
864/*
865 * TX_RTY_CFG:
866 * SHORT_RTY_LIMIT: short retry limit
867 * LONG_RTY_LIMIT: long retry limit
868 * LONG_RTY_THRE: Long retry threshoold
869 * NON_AGG_RTY_MODE: Non-Aggregate MPDU retry mode
870 * 0:expired by retry limit, 1: expired by mpdu life timer
871 * AGG_RTY_MODE: Aggregate MPDU retry mode
872 * 0:expired by retry limit, 1: expired by mpdu life timer
873 * TX_AUTO_FB_ENABLE: Tx retry PHY rate auto fallback enable
874 */
875#define TX_RTY_CFG 0x134c
876#define TX_RTY_CFG_SHORT_RTY_LIMIT FIELD32(0x000000ff)
877#define TX_RTY_CFG_LONG_RTY_LIMIT FIELD32(0x0000ff00)
878#define TX_RTY_CFG_LONG_RTY_THRE FIELD32(0x0fff0000)
879#define TX_RTY_CFG_NON_AGG_RTY_MODE FIELD32(0x10000000)
880#define TX_RTY_CFG_AGG_RTY_MODE FIELD32(0x20000000)
881#define TX_RTY_CFG_TX_AUTO_FB_ENABLE FIELD32(0x40000000)
882
883/*
884 * TX_LINK_CFG:
885 * REMOTE_MFB_LIFETIME: remote MFB life time. unit: 32us
886 * MFB_ENABLE: TX apply remote MFB 1:enable
887 * REMOTE_UMFS_ENABLE: remote unsolicit MFB enable
888 * 0: not apply remote remote unsolicit (MFS=7)
889 * TX_MRQ_EN: MCS request TX enable
890 * TX_RDG_EN: RDG TX enable
891 * TX_CF_ACK_EN: Piggyback CF-ACK enable
892 * REMOTE_MFB: remote MCS feedback
893 * REMOTE_MFS: remote MCS feedback sequence number
894 */
895#define TX_LINK_CFG 0x1350
896#define TX_LINK_CFG_REMOTE_MFB_LIFETIME FIELD32(0x000000ff)
897#define TX_LINK_CFG_MFB_ENABLE FIELD32(0x00000100)
898#define TX_LINK_CFG_REMOTE_UMFS_ENABLE FIELD32(0x00000200)
899#define TX_LINK_CFG_TX_MRQ_EN FIELD32(0x00000400)
900#define TX_LINK_CFG_TX_RDG_EN FIELD32(0x00000800)
901#define TX_LINK_CFG_TX_CF_ACK_EN FIELD32(0x00001000)
902#define TX_LINK_CFG_REMOTE_MFB FIELD32(0x00ff0000)
903#define TX_LINK_CFG_REMOTE_MFS FIELD32(0xff000000)
904
905/*
906 * HT_FBK_CFG0:
907 */
908#define HT_FBK_CFG0 0x1354
909#define HT_FBK_CFG0_HTMCS0FBK FIELD32(0x0000000f)
910#define HT_FBK_CFG0_HTMCS1FBK FIELD32(0x000000f0)
911#define HT_FBK_CFG0_HTMCS2FBK FIELD32(0x00000f00)
912#define HT_FBK_CFG0_HTMCS3FBK FIELD32(0x0000f000)
913#define HT_FBK_CFG0_HTMCS4FBK FIELD32(0x000f0000)
914#define HT_FBK_CFG0_HTMCS5FBK FIELD32(0x00f00000)
915#define HT_FBK_CFG0_HTMCS6FBK FIELD32(0x0f000000)
916#define HT_FBK_CFG0_HTMCS7FBK FIELD32(0xf0000000)
917
918/*
919 * HT_FBK_CFG1:
920 */
921#define HT_FBK_CFG1 0x1358
922#define HT_FBK_CFG1_HTMCS8FBK FIELD32(0x0000000f)
923#define HT_FBK_CFG1_HTMCS9FBK FIELD32(0x000000f0)
924#define HT_FBK_CFG1_HTMCS10FBK FIELD32(0x00000f00)
925#define HT_FBK_CFG1_HTMCS11FBK FIELD32(0x0000f000)
926#define HT_FBK_CFG1_HTMCS12FBK FIELD32(0x000f0000)
927#define HT_FBK_CFG1_HTMCS13FBK FIELD32(0x00f00000)
928#define HT_FBK_CFG1_HTMCS14FBK FIELD32(0x0f000000)
929#define HT_FBK_CFG1_HTMCS15FBK FIELD32(0xf0000000)
930
931/*
932 * LG_FBK_CFG0:
933 */
934#define LG_FBK_CFG0 0x135c
935#define LG_FBK_CFG0_OFDMMCS0FBK FIELD32(0x0000000f)
936#define LG_FBK_CFG0_OFDMMCS1FBK FIELD32(0x000000f0)
937#define LG_FBK_CFG0_OFDMMCS2FBK FIELD32(0x00000f00)
938#define LG_FBK_CFG0_OFDMMCS3FBK FIELD32(0x0000f000)
939#define LG_FBK_CFG0_OFDMMCS4FBK FIELD32(0x000f0000)
940#define LG_FBK_CFG0_OFDMMCS5FBK FIELD32(0x00f00000)
941#define LG_FBK_CFG0_OFDMMCS6FBK FIELD32(0x0f000000)
942#define LG_FBK_CFG0_OFDMMCS7FBK FIELD32(0xf0000000)
943
944/*
945 * LG_FBK_CFG1:
946 */
947#define LG_FBK_CFG1 0x1360
948#define LG_FBK_CFG0_CCKMCS0FBK FIELD32(0x0000000f)
949#define LG_FBK_CFG0_CCKMCS1FBK FIELD32(0x000000f0)
950#define LG_FBK_CFG0_CCKMCS2FBK FIELD32(0x00000f00)
951#define LG_FBK_CFG0_CCKMCS3FBK FIELD32(0x0000f000)
952
953/*
954 * CCK_PROT_CFG: CCK Protection
955 * PROTECT_RATE: Protection control frame rate for CCK TX(RTS/CTS/CFEnd)
956 * PROTECT_CTRL: Protection control frame type for CCK TX
957 * 0:none, 1:RTS/CTS, 2:CTS-to-self
958 * PROTECT_NAV: TXOP protection type for CCK TX
959 * 0:none, 1:ShortNAVprotect, 2:LongNAVProtect
960 * TX_OP_ALLOW_CCK: CCK TXOP allowance, 0:disallow
961 * TX_OP_ALLOW_OFDM: CCK TXOP allowance, 0:disallow
962 * TX_OP_ALLOW_MM20: CCK TXOP allowance, 0:disallow
963 * TX_OP_ALLOW_MM40: CCK TXOP allowance, 0:disallow
964 * TX_OP_ALLOW_GF20: CCK TXOP allowance, 0:disallow
965 * TX_OP_ALLOW_GF40: CCK TXOP allowance, 0:disallow
966 * RTS_TH_EN: RTS threshold enable on CCK TX
967 */
968#define CCK_PROT_CFG 0x1364
969#define CCK_PROT_CFG_PROTECT_RATE FIELD32(0x0000ffff)
970#define CCK_PROT_CFG_PROTECT_CTRL FIELD32(0x00030000)
971#define CCK_PROT_CFG_PROTECT_NAV FIELD32(0x000c0000)
972#define CCK_PROT_CFG_TX_OP_ALLOW_CCK FIELD32(0x00100000)
973#define CCK_PROT_CFG_TX_OP_ALLOW_OFDM FIELD32(0x00200000)
974#define CCK_PROT_CFG_TX_OP_ALLOW_MM20 FIELD32(0x00400000)
975#define CCK_PROT_CFG_TX_OP_ALLOW_MM40 FIELD32(0x00800000)
976#define CCK_PROT_CFG_TX_OP_ALLOW_GF20 FIELD32(0x01000000)
977#define CCK_PROT_CFG_TX_OP_ALLOW_GF40 FIELD32(0x02000000)
978#define CCK_PROT_CFG_RTS_TH_EN FIELD32(0x04000000)
979
980/*
981 * OFDM_PROT_CFG: OFDM Protection
982 */
983#define OFDM_PROT_CFG 0x1368
984#define OFDM_PROT_CFG_PROTECT_RATE FIELD32(0x0000ffff)
985#define OFDM_PROT_CFG_PROTECT_CTRL FIELD32(0x00030000)
986#define OFDM_PROT_CFG_PROTECT_NAV FIELD32(0x000c0000)
987#define OFDM_PROT_CFG_TX_OP_ALLOW_CCK FIELD32(0x00100000)
988#define OFDM_PROT_CFG_TX_OP_ALLOW_OFDM FIELD32(0x00200000)
989#define OFDM_PROT_CFG_TX_OP_ALLOW_MM20 FIELD32(0x00400000)
990#define OFDM_PROT_CFG_TX_OP_ALLOW_MM40 FIELD32(0x00800000)
991#define OFDM_PROT_CFG_TX_OP_ALLOW_GF20 FIELD32(0x01000000)
992#define OFDM_PROT_CFG_TX_OP_ALLOW_GF40 FIELD32(0x02000000)
993#define OFDM_PROT_CFG_RTS_TH_EN FIELD32(0x04000000)
994
995/*
996 * MM20_PROT_CFG: MM20 Protection
997 */
998#define MM20_PROT_CFG 0x136c
999#define MM20_PROT_CFG_PROTECT_RATE FIELD32(0x0000ffff)
1000#define MM20_PROT_CFG_PROTECT_CTRL FIELD32(0x00030000)
1001#define MM20_PROT_CFG_PROTECT_NAV FIELD32(0x000c0000)
1002#define MM20_PROT_CFG_TX_OP_ALLOW_CCK FIELD32(0x00100000)
1003#define MM20_PROT_CFG_TX_OP_ALLOW_OFDM FIELD32(0x00200000)
1004#define MM20_PROT_CFG_TX_OP_ALLOW_MM20 FIELD32(0x00400000)
1005#define MM20_PROT_CFG_TX_OP_ALLOW_MM40 FIELD32(0x00800000)
1006#define MM20_PROT_CFG_TX_OP_ALLOW_GF20 FIELD32(0x01000000)
1007#define MM20_PROT_CFG_TX_OP_ALLOW_GF40 FIELD32(0x02000000)
1008#define MM20_PROT_CFG_RTS_TH_EN FIELD32(0x04000000)
1009
1010/*
1011 * MM40_PROT_CFG: MM40 Protection
1012 */
1013#define MM40_PROT_CFG 0x1370
1014#define MM40_PROT_CFG_PROTECT_RATE FIELD32(0x0000ffff)
1015#define MM40_PROT_CFG_PROTECT_CTRL FIELD32(0x00030000)
1016#define MM40_PROT_CFG_PROTECT_NAV FIELD32(0x000c0000)
1017#define MM40_PROT_CFG_TX_OP_ALLOW_CCK FIELD32(0x00100000)
1018#define MM40_PROT_CFG_TX_OP_ALLOW_OFDM FIELD32(0x00200000)
1019#define MM40_PROT_CFG_TX_OP_ALLOW_MM20 FIELD32(0x00400000)
1020#define MM40_PROT_CFG_TX_OP_ALLOW_MM40 FIELD32(0x00800000)
1021#define MM40_PROT_CFG_TX_OP_ALLOW_GF20 FIELD32(0x01000000)
1022#define MM40_PROT_CFG_TX_OP_ALLOW_GF40 FIELD32(0x02000000)
1023#define MM40_PROT_CFG_RTS_TH_EN FIELD32(0x04000000)
1024
1025/*
1026 * GF20_PROT_CFG: GF20 Protection
1027 */
1028#define GF20_PROT_CFG 0x1374
1029#define GF20_PROT_CFG_PROTECT_RATE FIELD32(0x0000ffff)
1030#define GF20_PROT_CFG_PROTECT_CTRL FIELD32(0x00030000)
1031#define GF20_PROT_CFG_PROTECT_NAV FIELD32(0x000c0000)
1032#define GF20_PROT_CFG_TX_OP_ALLOW_CCK FIELD32(0x00100000)
1033#define GF20_PROT_CFG_TX_OP_ALLOW_OFDM FIELD32(0x00200000)
1034#define GF20_PROT_CFG_TX_OP_ALLOW_MM20 FIELD32(0x00400000)
1035#define GF20_PROT_CFG_TX_OP_ALLOW_MM40 FIELD32(0x00800000)
1036#define GF20_PROT_CFG_TX_OP_ALLOW_GF20 FIELD32(0x01000000)
1037#define GF20_PROT_CFG_TX_OP_ALLOW_GF40 FIELD32(0x02000000)
1038#define GF20_PROT_CFG_RTS_TH_EN FIELD32(0x04000000)
1039
1040/*
1041 * GF40_PROT_CFG: GF40 Protection
1042 */
1043#define GF40_PROT_CFG 0x1378
1044#define GF40_PROT_CFG_PROTECT_RATE FIELD32(0x0000ffff)
1045#define GF40_PROT_CFG_PROTECT_CTRL FIELD32(0x00030000)
1046#define GF40_PROT_CFG_PROTECT_NAV FIELD32(0x000c0000)
1047#define GF40_PROT_CFG_TX_OP_ALLOW_CCK FIELD32(0x00100000)
1048#define GF40_PROT_CFG_TX_OP_ALLOW_OFDM FIELD32(0x00200000)
1049#define GF40_PROT_CFG_TX_OP_ALLOW_MM20 FIELD32(0x00400000)
1050#define GF40_PROT_CFG_TX_OP_ALLOW_MM40 FIELD32(0x00800000)
1051#define GF40_PROT_CFG_TX_OP_ALLOW_GF20 FIELD32(0x01000000)
1052#define GF40_PROT_CFG_TX_OP_ALLOW_GF40 FIELD32(0x02000000)
1053#define GF40_PROT_CFG_RTS_TH_EN FIELD32(0x04000000)
1054
1055/*
1056 * EXP_CTS_TIME:
1057 */
1058#define EXP_CTS_TIME 0x137c
1059
1060/*
1061 * EXP_ACK_TIME:
1062 */
1063#define EXP_ACK_TIME 0x1380
1064
1065/*
1066 * RX_FILTER_CFG: RX configuration register.
1067 */
1068#define RX_FILTER_CFG 0x1400
1069#define RX_FILTER_CFG_DROP_CRC_ERROR FIELD32(0x00000001)
1070#define RX_FILTER_CFG_DROP_PHY_ERROR FIELD32(0x00000002)
1071#define RX_FILTER_CFG_DROP_NOT_TO_ME FIELD32(0x00000004)
1072#define RX_FILTER_CFG_DROP_NOT_MY_BSSD FIELD32(0x00000008)
1073#define RX_FILTER_CFG_DROP_VER_ERROR FIELD32(0x00000010)
1074#define RX_FILTER_CFG_DROP_MULTICAST FIELD32(0x00000020)
1075#define RX_FILTER_CFG_DROP_BROADCAST FIELD32(0x00000040)
1076#define RX_FILTER_CFG_DROP_DUPLICATE FIELD32(0x00000080)
1077#define RX_FILTER_CFG_DROP_CF_END_ACK FIELD32(0x00000100)
1078#define RX_FILTER_CFG_DROP_CF_END FIELD32(0x00000200)
1079#define RX_FILTER_CFG_DROP_ACK FIELD32(0x00000400)
1080#define RX_FILTER_CFG_DROP_CTS FIELD32(0x00000800)
1081#define RX_FILTER_CFG_DROP_RTS FIELD32(0x00001000)
1082#define RX_FILTER_CFG_DROP_PSPOLL FIELD32(0x00002000)
1083#define RX_FILTER_CFG_DROP_BA FIELD32(0x00004000)
1084#define RX_FILTER_CFG_DROP_BAR FIELD32(0x00008000)
1085#define RX_FILTER_CFG_DROP_CNTL FIELD32(0x00010000)
1086
1087/*
1088 * AUTO_RSP_CFG:
1089 * AUTORESPONDER: 0: disable, 1: enable
1090 * BAC_ACK_POLICY: 0:long, 1:short preamble
1091 * CTS_40_MMODE: Response CTS 40MHz duplicate mode
1092 * CTS_40_MREF: Response CTS 40MHz duplicate mode
1093 * AR_PREAMBLE: Auto responder preamble 0:long, 1:short preamble
1094 * DUAL_CTS_EN: Power bit value in control frame
1095 * ACK_CTS_PSM_BIT:Power bit value in control frame
1096 */
1097#define AUTO_RSP_CFG 0x1404
1098#define AUTO_RSP_CFG_AUTORESPONDER FIELD32(0x00000001)
1099#define AUTO_RSP_CFG_BAC_ACK_POLICY FIELD32(0x00000002)
1100#define AUTO_RSP_CFG_CTS_40_MMODE FIELD32(0x00000004)
1101#define AUTO_RSP_CFG_CTS_40_MREF FIELD32(0x00000008)
1102#define AUTO_RSP_CFG_AR_PREAMBLE FIELD32(0x00000010)
1103#define AUTO_RSP_CFG_DUAL_CTS_EN FIELD32(0x00000040)
1104#define AUTO_RSP_CFG_ACK_CTS_PSM_BIT FIELD32(0x00000080)
1105
1106/*
1107 * LEGACY_BASIC_RATE:
1108 */
1109#define LEGACY_BASIC_RATE 0x1408
1110
1111/*
1112 * HT_BASIC_RATE:
1113 */
1114#define HT_BASIC_RATE 0x140c
1115
1116/*
1117 * HT_CTRL_CFG:
1118 */
1119#define HT_CTRL_CFG 0x1410
1120
1121/*
1122 * SIFS_COST_CFG:
1123 */
1124#define SIFS_COST_CFG 0x1414
1125
1126/*
1127 * RX_PARSER_CFG:
1128 * Set NAV for all received frames
1129 */
1130#define RX_PARSER_CFG 0x1418
1131
1132/*
1133 * TX_SEC_CNT0:
1134 */
1135#define TX_SEC_CNT0 0x1500
1136
1137/*
1138 * RX_SEC_CNT0:
1139 */
1140#define RX_SEC_CNT0 0x1504
1141
1142/*
1143 * CCMP_FC_MUTE:
1144 */
1145#define CCMP_FC_MUTE 0x1508
1146
1147/*
1148 * TXOP_HLDR_ADDR0:
1149 */
1150#define TXOP_HLDR_ADDR0 0x1600
1151
1152/*
1153 * TXOP_HLDR_ADDR1:
1154 */
1155#define TXOP_HLDR_ADDR1 0x1604
1156
1157/*
1158 * TXOP_HLDR_ET:
1159 */
1160#define TXOP_HLDR_ET 0x1608
1161
1162/*
1163 * QOS_CFPOLL_RA_DW0:
1164 */
1165#define QOS_CFPOLL_RA_DW0 0x160c
1166
1167/*
1168 * QOS_CFPOLL_RA_DW1:
1169 */
1170#define QOS_CFPOLL_RA_DW1 0x1610
1171
1172/*
1173 * QOS_CFPOLL_QC:
1174 */
1175#define QOS_CFPOLL_QC 0x1614
1176
1177/*
1178 * RX_STA_CNT0: RX PLCP error count & RX CRC error count
1179 */
1180#define RX_STA_CNT0 0x1700
1181#define RX_STA_CNT0_CRC_ERR FIELD32(0x0000ffff)
1182#define RX_STA_CNT0_PHY_ERR FIELD32(0xffff0000)
1183
1184/*
1185 * RX_STA_CNT1: RX False CCA count & RX LONG frame count
1186 */
1187#define RX_STA_CNT1 0x1704
1188#define RX_STA_CNT1_FALSE_CCA FIELD32(0x0000ffff)
1189#define RX_STA_CNT1_PLCP_ERR FIELD32(0xffff0000)
1190
1191/*
1192 * RX_STA_CNT2:
1193 */
1194#define RX_STA_CNT2 0x1708
1195#define RX_STA_CNT2_RX_DUPLI_COUNT FIELD32(0x0000ffff)
1196#define RX_STA_CNT2_RX_FIFO_OVERFLOW FIELD32(0xffff0000)
1197
1198/*
1199 * TX_STA_CNT0: TX Beacon count
1200 */
1201#define TX_STA_CNT0 0x170c
1202#define TX_STA_CNT0_TX_FAIL_COUNT FIELD32(0x0000ffff)
1203#define TX_STA_CNT0_TX_BEACON_COUNT FIELD32(0xffff0000)
1204
1205/*
1206 * TX_STA_CNT1: TX tx count
1207 */
1208#define TX_STA_CNT1 0x1710
1209#define TX_STA_CNT1_TX_SUCCESS FIELD32(0x0000ffff)
1210#define TX_STA_CNT1_TX_RETRANSMIT FIELD32(0xffff0000)
1211
1212/*
1213 * TX_STA_CNT2: TX tx count
1214 */
1215#define TX_STA_CNT2 0x1714
1216#define TX_STA_CNT2_TX_ZERO_LEN_COUNT FIELD32(0x0000ffff)
1217#define TX_STA_CNT2_TX_UNDER_FLOW_COUNT FIELD32(0xffff0000)
1218
1219/*
1220 * TX_STA_FIFO: TX Result for specific PID status fifo register
1221 */
1222#define TX_STA_FIFO 0x1718
1223#define TX_STA_FIFO_VALID FIELD32(0x00000001)
1224#define TX_STA_FIFO_PID_TYPE FIELD32(0x0000001e)
1225#define TX_STA_FIFO_TX_SUCCESS FIELD32(0x00000020)
1226#define TX_STA_FIFO_TX_AGGRE FIELD32(0x00000040)
1227#define TX_STA_FIFO_TX_ACK_REQUIRED FIELD32(0x00000080)
1228#define TX_STA_FIFO_WCID FIELD32(0x0000ff00)
1229#define TX_STA_FIFO_SUCCESS_RATE FIELD32(0xffff0000)
1230
1231/*
1232 * TX_AGG_CNT: Debug counter
1233 */
1234#define TX_AGG_CNT 0x171c
1235#define TX_AGG_CNT_NON_AGG_TX_COUNT FIELD32(0x0000ffff)
1236#define TX_AGG_CNT_AGG_TX_COUNT FIELD32(0xffff0000)
1237
1238/*
1239 * TX_AGG_CNT0:
1240 */
1241#define TX_AGG_CNT0 0x1720
1242#define TX_AGG_CNT0_AGG_SIZE_1_COUNT FIELD32(0x0000ffff)
1243#define TX_AGG_CNT0_AGG_SIZE_2_COUNT FIELD32(0xffff0000)
1244
1245/*
1246 * TX_AGG_CNT1:
1247 */
1248#define TX_AGG_CNT1 0x1724
1249#define TX_AGG_CNT1_AGG_SIZE_3_COUNT FIELD32(0x0000ffff)
1250#define TX_AGG_CNT1_AGG_SIZE_4_COUNT FIELD32(0xffff0000)
1251
1252/*
1253 * TX_AGG_CNT2:
1254 */
1255#define TX_AGG_CNT2 0x1728
1256#define TX_AGG_CNT2_AGG_SIZE_5_COUNT FIELD32(0x0000ffff)
1257#define TX_AGG_CNT2_AGG_SIZE_6_COUNT FIELD32(0xffff0000)
1258
1259/*
1260 * TX_AGG_CNT3:
1261 */
1262#define TX_AGG_CNT3 0x172c
1263#define TX_AGG_CNT3_AGG_SIZE_7_COUNT FIELD32(0x0000ffff)
1264#define TX_AGG_CNT3_AGG_SIZE_8_COUNT FIELD32(0xffff0000)
1265
1266/*
1267 * TX_AGG_CNT4:
1268 */
1269#define TX_AGG_CNT4 0x1730
1270#define TX_AGG_CNT4_AGG_SIZE_9_COUNT FIELD32(0x0000ffff)
1271#define TX_AGG_CNT4_AGG_SIZE_10_COUNT FIELD32(0xffff0000)
1272
1273/*
1274 * TX_AGG_CNT5:
1275 */
1276#define TX_AGG_CNT5 0x1734
1277#define TX_AGG_CNT5_AGG_SIZE_11_COUNT FIELD32(0x0000ffff)
1278#define TX_AGG_CNT5_AGG_SIZE_12_COUNT FIELD32(0xffff0000)
1279
1280/*
1281 * TX_AGG_CNT6:
1282 */
1283#define TX_AGG_CNT6 0x1738
1284#define TX_AGG_CNT6_AGG_SIZE_13_COUNT FIELD32(0x0000ffff)
1285#define TX_AGG_CNT6_AGG_SIZE_14_COUNT FIELD32(0xffff0000)
1286
1287/*
1288 * TX_AGG_CNT7:
1289 */
1290#define TX_AGG_CNT7 0x173c
1291#define TX_AGG_CNT7_AGG_SIZE_15_COUNT FIELD32(0x0000ffff)
1292#define TX_AGG_CNT7_AGG_SIZE_16_COUNT FIELD32(0xffff0000)
1293
1294/*
1295 * MPDU_DENSITY_CNT:
1296 * TX_ZERO_DEL: TX zero length delimiter count
1297 * RX_ZERO_DEL: RX zero length delimiter count
1298 */
1299#define MPDU_DENSITY_CNT 0x1740
1300#define MPDU_DENSITY_CNT_TX_ZERO_DEL FIELD32(0x0000ffff)
1301#define MPDU_DENSITY_CNT_RX_ZERO_DEL FIELD32(0xffff0000)
1302
1303/*
1304 * Security key table memory.
1305 * MAC_WCID_BASE: 8-bytes (use only 6 bytes) * 256 entry
1306 * PAIRWISE_KEY_TABLE_BASE: 32-byte * 256 entry
1307 * MAC_IVEIV_TABLE_BASE: 8-byte * 256-entry
1308 * MAC_WCID_ATTRIBUTE_BASE: 4-byte * 256-entry
1309 * SHARED_KEY_TABLE_BASE: 32 bytes * 32-entry
1310 * SHARED_KEY_MODE_BASE: 4 bits * 32-entry
1311 */
1312#define MAC_WCID_BASE 0x1800
1313#define PAIRWISE_KEY_TABLE_BASE 0x4000
1314#define MAC_IVEIV_TABLE_BASE 0x6000
1315#define MAC_WCID_ATTRIBUTE_BASE 0x6800
1316#define SHARED_KEY_TABLE_BASE 0x6c00
1317#define SHARED_KEY_MODE_BASE 0x7000
1318
1319#define MAC_WCID_ENTRY(__idx) \
1320 ( MAC_WCID_BASE + ((__idx) * sizeof(struct mac_wcid_entry)) )
1321#define PAIRWISE_KEY_ENTRY(__idx) \
1322 ( PAIRWISE_KEY_TABLE_BASE + ((__idx) * sizeof(struct hw_key_entry)) )
1323#define MAC_IVEIV_ENTRY(__idx) \
1324 ( MAC_IVEIV_TABLE_BASE + ((__idx) & sizeof(struct mac_iveiv_entry)) )
1325#define MAC_WCID_ATTR_ENTRY(__idx) \
1326 ( MAC_WCID_ATTRIBUTE_BASE + ((__idx) * sizeof(u32)) )
1327#define SHARED_KEY_ENTRY(__idx) \
1328 ( SHARED_KEY_TABLE_BASE + ((__idx) * sizeof(struct hw_key_entry)) )
1329#define SHARED_KEY_MODE_ENTRY(__idx) \
1330 ( SHARED_KEY_MODE_BASE + ((__idx) * sizeof(u32)) )
1331
1332struct mac_wcid_entry {
1333 u8 mac[6];
1334 u8 reserved[2];
1335} __attribute__ ((packed));
1336
1337struct hw_key_entry {
1338 u8 key[16];
1339 u8 tx_mic[8];
1340 u8 rx_mic[8];
1341} __attribute__ ((packed));
1342
1343struct mac_iveiv_entry {
1344 u8 iv[8];
1345} __attribute__ ((packed));
1346
1347/*
1348 * MAC_WCID_ATTRIBUTE:
1349 */
1350#define MAC_WCID_ATTRIBUTE_KEYTAB FIELD32(0x00000001)
1351#define MAC_WCID_ATTRIBUTE_CIPHER FIELD32(0x0000000e)
1352#define MAC_WCID_ATTRIBUTE_BSS_IDX FIELD32(0x00000070)
1353#define MAC_WCID_ATTRIBUTE_RX_WIUDF FIELD32(0x00000380)
1354
1355/*
1356 * SHARED_KEY_MODE:
1357 */
1358#define SHARED_KEY_MODE_BSS0_KEY0 FIELD32(0x00000007)
1359#define SHARED_KEY_MODE_BSS0_KEY1 FIELD32(0x00000070)
1360#define SHARED_KEY_MODE_BSS0_KEY2 FIELD32(0x00000700)
1361#define SHARED_KEY_MODE_BSS0_KEY3 FIELD32(0x00007000)
1362#define SHARED_KEY_MODE_BSS1_KEY0 FIELD32(0x00070000)
1363#define SHARED_KEY_MODE_BSS1_KEY1 FIELD32(0x00700000)
1364#define SHARED_KEY_MODE_BSS1_KEY2 FIELD32(0x07000000)
1365#define SHARED_KEY_MODE_BSS1_KEY3 FIELD32(0x70000000)
1366
1367/*
1368 * HOST-MCU communication
1369 */
1370
1371/*
1372 * H2M_MAILBOX_CSR: Host-to-MCU Mailbox.
1373 */
1374#define H2M_MAILBOX_CSR 0x7010
1375#define H2M_MAILBOX_CSR_ARG0 FIELD32(0x000000ff)
1376#define H2M_MAILBOX_CSR_ARG1 FIELD32(0x0000ff00)
1377#define H2M_MAILBOX_CSR_CMD_TOKEN FIELD32(0x00ff0000)
1378#define H2M_MAILBOX_CSR_OWNER FIELD32(0xff000000)
1379
1380/*
1381 * H2M_MAILBOX_CID:
1382 */
1383#define H2M_MAILBOX_CID 0x7014
1384#define H2M_MAILBOX_CID_CMD0 FIELD32(0x000000ff)
1385#define H2M_MAILBOX_CID_CMD1 FIELD32(0x0000ff00)
1386#define H2M_MAILBOX_CID_CMD2 FIELD32(0x00ff0000)
1387#define H2M_MAILBOX_CID_CMD3 FIELD32(0xff000000)
1388
1389/*
1390 * H2M_MAILBOX_STATUS:
1391 */
1392#define H2M_MAILBOX_STATUS 0x701c
1393
1394/*
1395 * H2M_INT_SRC:
1396 */
1397#define H2M_INT_SRC 0x7024
1398
1399/*
1400 * H2M_BBP_AGENT:
1401 */
1402#define H2M_BBP_AGENT 0x7028
1403
1404/*
1405 * MCU_LEDCS: LED control for MCU Mailbox.
1406 */
1407#define MCU_LEDCS_LED_MODE FIELD8(0x1f)
1408#define MCU_LEDCS_POLARITY FIELD8(0x01)
1409
1410/*
1411 * HW_CS_CTS_BASE:
1412 * Carrier-sense CTS frame base address.
1413 * It's where mac stores carrier-sense frame for carrier-sense function.
1414 */
1415#define HW_CS_CTS_BASE 0x7700
1416
1417/*
1418 * HW_DFS_CTS_BASE:
1419 * FS CTS frame base address. It's where mac stores CTS frame for DFS.
1420 */
1421#define HW_DFS_CTS_BASE 0x7780
1422
1423/*
1424 * TXRX control registers - base address 0x3000
1425 */
1426
1427/*
1428 * TXRX_CSR1:
1429 * rt2860b UNKNOWN reg use R/O Reg Addr 0x77d0 first..
1430 */
1431#define TXRX_CSR1 0x77d0
1432
1433/*
1434 * HW_DEBUG_SETTING_BASE:
1435 * since NULL frame won't be that long (256 byte)
1436 * We steal 16 tail bytes to save debugging settings
1437 */
1438#define HW_DEBUG_SETTING_BASE 0x77f0
1439#define HW_DEBUG_SETTING_BASE2 0x7770
1440
1441/*
1442 * HW_BEACON_BASE
1443 * In order to support maximum 8 MBSS and its maximum length
1444 * is 512 bytes for each beacon
1445 * Three section discontinue memory segments will be used.
1446 * 1. The original region for BCN 0~3
1447 * 2. Extract memory from FCE table for BCN 4~5
1448 * 3. Extract memory from Pair-wise key table for BCN 6~7
1449 * It occupied those memory of wcid 238~253 for BCN 6
1450 * and wcid 222~237 for BCN 7
1451 *
1452 * IMPORTANT NOTE: Not sure why legacy driver does this,
1453 * but HW_BEACON_BASE7 is 0x0200 bytes below HW_BEACON_BASE6.
1454 */
1455#define HW_BEACON_BASE0 0x7800
1456#define HW_BEACON_BASE1 0x7a00
1457#define HW_BEACON_BASE2 0x7c00
1458#define HW_BEACON_BASE3 0x7e00
1459#define HW_BEACON_BASE4 0x7200
1460#define HW_BEACON_BASE5 0x7400
1461#define HW_BEACON_BASE6 0x5dc0
1462#define HW_BEACON_BASE7 0x5bc0
1463
1464#define HW_BEACON_OFFSET(__index) \
1465 ( ((__index) < 4) ? ( HW_BEACON_BASE0 + (__index * 0x0200) ) : \
1466 (((__index) < 6) ? ( HW_BEACON_BASE4 + ((__index - 4) * 0x0200) ) : \
1467 (HW_BEACON_BASE6 - ((__index - 6) * 0x0200))) )
1468
1469/*
1470 * 8051 firmware image. 68 * 8051 firmware image.
1471 */ 69 */
1472#define FIRMWARE_RT2870 "rt2870.bin" 70#define FIRMWARE_RT2870 "rt2870.bin"
1473#define FIRMWARE_IMAGE_BASE 0x3000 71#define FIRMWARE_IMAGE_BASE 0x3000
1474 72
1475/* 73/*
1476 * BBP registers.
1477 * The wordsize of the BBP is 8 bits.
1478 */
1479
1480/*
1481 * BBP 1: TX Antenna
1482 */
1483#define BBP1_TX_POWER FIELD8(0x07)
1484#define BBP1_TX_ANTENNA FIELD8(0x18)
1485
1486/*
1487 * BBP 3: RX Antenna
1488 */
1489#define BBP3_RX_ANTENNA FIELD8(0x18)
1490#define BBP3_HT40_PLUS FIELD8(0x20)
1491
1492/*
1493 * BBP 4: Bandwidth
1494 */
1495#define BBP4_TX_BF FIELD8(0x01)
1496#define BBP4_BANDWIDTH FIELD8(0x18)
1497
1498/*
1499 * RFCSR registers
1500 * The wordsize of the RFCSR is 8 bits.
1501 */
1502
1503/*
1504 * RFCSR 6:
1505 */
1506#define RFCSR6_R FIELD8(0x03)
1507
1508/*
1509 * RFCSR 7:
1510 */
1511#define RFCSR7_RF_TUNING FIELD8(0x01)
1512
1513/*
1514 * RFCSR 12:
1515 */
1516#define RFCSR12_TX_POWER FIELD8(0x1f)
1517
1518/*
1519 * RFCSR 22:
1520 */
1521#define RFCSR22_BASEBAND_LOOPBACK FIELD8(0x01)
1522
1523/*
1524 * RFCSR 23:
1525 */
1526#define RFCSR23_FREQ_OFFSET FIELD8(0x7f)
1527
1528/*
1529 * RFCSR 30:
1530 */
1531#define RFCSR30_RF_CALIBRATION FIELD8(0x80)
1532
1533/*
1534 * RF registers
1535 */
1536
1537/*
1538 * RF 2
1539 */
1540#define RF2_ANTENNA_RX2 FIELD32(0x00000040)
1541#define RF2_ANTENNA_TX1 FIELD32(0x00004000)
1542#define RF2_ANTENNA_RX1 FIELD32(0x00020000)
1543
1544/*
1545 * RF 3
1546 */
1547#define RF3_TXPOWER_G FIELD32(0x00003e00)
1548#define RF3_TXPOWER_A_7DBM_BOOST FIELD32(0x00000200)
1549#define RF3_TXPOWER_A FIELD32(0x00003c00)
1550
1551/*
1552 * RF 4
1553 */
1554#define RF4_TXPOWER_G FIELD32(0x000007c0)
1555#define RF4_TXPOWER_A_7DBM_BOOST FIELD32(0x00000040)
1556#define RF4_TXPOWER_A FIELD32(0x00000780)
1557#define RF4_FREQ_OFFSET FIELD32(0x001f8000)
1558#define RF4_HT40 FIELD32(0x00200000)
1559
1560/*
1561 * EEPROM content.
1562 * The wordsize of the EEPROM is 16 bits.
1563 */
1564
1565/*
1566 * EEPROM Version
1567 */
1568#define EEPROM_VERSION 0x0001
1569#define EEPROM_VERSION_FAE FIELD16(0x00ff)
1570#define EEPROM_VERSION_VERSION FIELD16(0xff00)
1571
1572/*
1573 * HW MAC address.
1574 */
1575#define EEPROM_MAC_ADDR_0 0x0002
1576#define EEPROM_MAC_ADDR_BYTE0 FIELD16(0x00ff)
1577#define EEPROM_MAC_ADDR_BYTE1 FIELD16(0xff00)
1578#define EEPROM_MAC_ADDR_1 0x0003
1579#define EEPROM_MAC_ADDR_BYTE2 FIELD16(0x00ff)
1580#define EEPROM_MAC_ADDR_BYTE3 FIELD16(0xff00)
1581#define EEPROM_MAC_ADDR_2 0x0004
1582#define EEPROM_MAC_ADDR_BYTE4 FIELD16(0x00ff)
1583#define EEPROM_MAC_ADDR_BYTE5 FIELD16(0xff00)
1584
1585/*
1586 * EEPROM ANTENNA config
1587 * RXPATH: 1: 1R, 2: 2R, 3: 3R
1588 * TXPATH: 1: 1T, 2: 2T
1589 */
1590#define EEPROM_ANTENNA 0x001a
1591#define EEPROM_ANTENNA_RXPATH FIELD16(0x000f)
1592#define EEPROM_ANTENNA_TXPATH FIELD16(0x00f0)
1593#define EEPROM_ANTENNA_RF_TYPE FIELD16(0x0f00)
1594
1595/*
1596 * EEPROM NIC config
1597 * CARDBUS_ACCEL: 0 - enable, 1 - disable
1598 */
1599#define EEPROM_NIC 0x001b
1600#define EEPROM_NIC_HW_RADIO FIELD16(0x0001)
1601#define EEPROM_NIC_DYNAMIC_TX_AGC FIELD16(0x0002)
1602#define EEPROM_NIC_EXTERNAL_LNA_BG FIELD16(0x0004)
1603#define EEPROM_NIC_EXTERNAL_LNA_A FIELD16(0x0008)
1604#define EEPROM_NIC_CARDBUS_ACCEL FIELD16(0x0010)
1605#define EEPROM_NIC_BW40M_SB_BG FIELD16(0x0020)
1606#define EEPROM_NIC_BW40M_SB_A FIELD16(0x0040)
1607#define EEPROM_NIC_WPS_PBC FIELD16(0x0080)
1608#define EEPROM_NIC_BW40M_BG FIELD16(0x0100)
1609#define EEPROM_NIC_BW40M_A FIELD16(0x0200)
1610
1611/*
1612 * EEPROM frequency
1613 */
1614#define EEPROM_FREQ 0x001d
1615#define EEPROM_FREQ_OFFSET FIELD16(0x00ff)
1616#define EEPROM_FREQ_LED_MODE FIELD16(0x7f00)
1617#define EEPROM_FREQ_LED_POLARITY FIELD16(0x1000)
1618
1619/*
1620 * EEPROM LED
1621 * POLARITY_RDY_G: Polarity RDY_G setting.
1622 * POLARITY_RDY_A: Polarity RDY_A setting.
1623 * POLARITY_ACT: Polarity ACT setting.
1624 * POLARITY_GPIO_0: Polarity GPIO0 setting.
1625 * POLARITY_GPIO_1: Polarity GPIO1 setting.
1626 * POLARITY_GPIO_2: Polarity GPIO2 setting.
1627 * POLARITY_GPIO_3: Polarity GPIO3 setting.
1628 * POLARITY_GPIO_4: Polarity GPIO4 setting.
1629 * LED_MODE: Led mode.
1630 */
1631#define EEPROM_LED1 0x001e
1632#define EEPROM_LED2 0x001f
1633#define EEPROM_LED3 0x0020
1634#define EEPROM_LED_POLARITY_RDY_BG FIELD16(0x0001)
1635#define EEPROM_LED_POLARITY_RDY_A FIELD16(0x0002)
1636#define EEPROM_LED_POLARITY_ACT FIELD16(0x0004)
1637#define EEPROM_LED_POLARITY_GPIO_0 FIELD16(0x0008)
1638#define EEPROM_LED_POLARITY_GPIO_1 FIELD16(0x0010)
1639#define EEPROM_LED_POLARITY_GPIO_2 FIELD16(0x0020)
1640#define EEPROM_LED_POLARITY_GPIO_3 FIELD16(0x0040)
1641#define EEPROM_LED_POLARITY_GPIO_4 FIELD16(0x0080)
1642#define EEPROM_LED_LED_MODE FIELD16(0x1f00)
1643
1644/*
1645 * EEPROM LNA
1646 */
1647#define EEPROM_LNA 0x0022
1648#define EEPROM_LNA_BG FIELD16(0x00ff)
1649#define EEPROM_LNA_A0 FIELD16(0xff00)
1650
1651/*
1652 * EEPROM RSSI BG offset
1653 */
1654#define EEPROM_RSSI_BG 0x0023
1655#define EEPROM_RSSI_BG_OFFSET0 FIELD16(0x00ff)
1656#define EEPROM_RSSI_BG_OFFSET1 FIELD16(0xff00)
1657
1658/*
1659 * EEPROM RSSI BG2 offset
1660 */
1661#define EEPROM_RSSI_BG2 0x0024
1662#define EEPROM_RSSI_BG2_OFFSET2 FIELD16(0x00ff)
1663#define EEPROM_RSSI_BG2_LNA_A1 FIELD16(0xff00)
1664
1665/*
1666 * EEPROM RSSI A offset
1667 */
1668#define EEPROM_RSSI_A 0x0025
1669#define EEPROM_RSSI_A_OFFSET0 FIELD16(0x00ff)
1670#define EEPROM_RSSI_A_OFFSET1 FIELD16(0xff00)
1671
1672/*
1673 * EEPROM RSSI A2 offset
1674 */
1675#define EEPROM_RSSI_A2 0x0026
1676#define EEPROM_RSSI_A2_OFFSET2 FIELD16(0x00ff)
1677#define EEPROM_RSSI_A2_LNA_A2 FIELD16(0xff00)
1678
1679/*
1680 * EEPROM TXpower delta: 20MHZ AND 40 MHZ use different power.
1681 * This is delta in 40MHZ.
1682 * VALUE: Tx Power dalta value (MAX=4)
1683 * TYPE: 1: Plus the delta value, 0: minus the delta value
1684 * TXPOWER: Enable:
1685 */
1686#define EEPROM_TXPOWER_DELTA 0x0028
1687#define EEPROM_TXPOWER_DELTA_VALUE FIELD16(0x003f)
1688#define EEPROM_TXPOWER_DELTA_TYPE FIELD16(0x0040)
1689#define EEPROM_TXPOWER_DELTA_TXPOWER FIELD16(0x0080)
1690
1691/*
1692 * EEPROM TXPOWER 802.11BG
1693 */
1694#define EEPROM_TXPOWER_BG1 0x0029
1695#define EEPROM_TXPOWER_BG2 0x0030
1696#define EEPROM_TXPOWER_BG_SIZE 7
1697#define EEPROM_TXPOWER_BG_1 FIELD16(0x00ff)
1698#define EEPROM_TXPOWER_BG_2 FIELD16(0xff00)
1699
1700/*
1701 * EEPROM TXPOWER 802.11A
1702 */
1703#define EEPROM_TXPOWER_A1 0x003c
1704#define EEPROM_TXPOWER_A2 0x0053
1705#define EEPROM_TXPOWER_A_SIZE 6
1706#define EEPROM_TXPOWER_A_1 FIELD16(0x00ff)
1707#define EEPROM_TXPOWER_A_2 FIELD16(0xff00)
1708
1709/*
1710 * EEPROM TXpower byrate: 20MHZ power
1711 */
1712#define EEPROM_TXPOWER_BYRATE 0x006f
1713
1714/*
1715 * EEPROM BBP.
1716 */
1717#define EEPROM_BBP_START 0x0078
1718#define EEPROM_BBP_SIZE 16
1719#define EEPROM_BBP_VALUE FIELD16(0x00ff)
1720#define EEPROM_BBP_REG_ID FIELD16(0xff00)
1721
1722/*
1723 * MCU mailbox commands.
1724 */
1725#define MCU_SLEEP 0x30
1726#define MCU_WAKEUP 0x31
1727#define MCU_RADIO_OFF 0x35
1728#define MCU_CURRENT 0x36
1729#define MCU_LED 0x50
1730#define MCU_LED_STRENGTH 0x51
1731#define MCU_LED_1 0x52
1732#define MCU_LED_2 0x53
1733#define MCU_LED_3 0x54
1734#define MCU_RADAR 0x60
1735#define MCU_BOOT_SIGNAL 0x72
1736#define MCU_BBP_SIGNAL 0x80
1737#define MCU_POWER_SAVE 0x83
1738
1739/*
1740 * MCU mailbox tokens
1741 */
1742#define TOKEN_WAKUP 3
1743
1744/*
1745 * DMA descriptor defines. 74 * DMA descriptor defines.
1746 */ 75 */
1747#define TXD_DESC_SIZE ( 4 * sizeof(__le32) )
1748#define TXINFO_DESC_SIZE ( 1 * sizeof(__le32) ) 76#define TXINFO_DESC_SIZE ( 1 * sizeof(__le32) )
1749#define TXWI_DESC_SIZE ( 4 * sizeof(__le32) ) 77#define RXINFO_DESC_SIZE ( 1 * sizeof(__le32) )
1750#define RXD_DESC_SIZE ( 1 * sizeof(__le32) )
1751#define RXWI_DESC_SIZE ( 4 * sizeof(__le32) )
1752
1753/*
1754 * TX descriptor format for TX, PRIO and Beacon Ring.
1755 */
1756
1757/*
1758 * Word0
1759 */
1760#define TXD_W0_SD_PTR0 FIELD32(0xffffffff)
1761
1762/*
1763 * Word1
1764 */
1765#define TXD_W1_SD_LEN1 FIELD32(0x00003fff)
1766#define TXD_W1_LAST_SEC1 FIELD32(0x00004000)
1767#define TXD_W1_BURST FIELD32(0x00008000)
1768#define TXD_W1_SD_LEN0 FIELD32(0x3fff0000)
1769#define TXD_W1_LAST_SEC0 FIELD32(0x40000000)
1770#define TXD_W1_DMA_DONE FIELD32(0x80000000)
1771
1772/*
1773 * Word2
1774 */
1775#define TXD_W2_SD_PTR1 FIELD32(0xffffffff)
1776
1777/*
1778 * Word3
1779 * WIV: Wireless Info Valid. 1: Driver filled WI, 0: DMA needs to copy WI
1780 * QSEL: Select on-chip FIFO ID for 2nd-stage output scheduler.
1781 * 0:MGMT, 1:HCCA 2:EDCA
1782 */
1783#define TXD_W3_WIV FIELD32(0x01000000)
1784#define TXD_W3_QSEL FIELD32(0x06000000)
1785#define TXD_W3_TCO FIELD32(0x20000000)
1786#define TXD_W3_UCO FIELD32(0x40000000)
1787#define TXD_W3_ICO FIELD32(0x80000000)
1788 78
1789/* 79/*
1790 * TX Info structure 80 * TX Info structure
@@ -1807,52 +97,6 @@ struct mac_iveiv_entry {
1807#define TXINFO_W0_USB_DMA_TX_BURST FIELD32(0x80000000) 97#define TXINFO_W0_USB_DMA_TX_BURST FIELD32(0x80000000)
1808 98
1809/* 99/*
1810 * TX WI structure
1811 */
1812
1813/*
1814 * Word0
1815 * FRAG: 1 To inform TKIP engine this is a fragment.
1816 * MIMO_PS: The remote peer is in dynamic MIMO-PS mode
1817 * TX_OP: 0:HT TXOP rule , 1:PIFS TX ,2:Backoff, 3:sifs
1818 * BW: Channel bandwidth 20MHz or 40 MHz
1819 * STBC: 1: STBC support MCS =0-7, 2,3 : RESERVED
1820 */
1821#define TXWI_W0_FRAG FIELD32(0x00000001)
1822#define TXWI_W0_MIMO_PS FIELD32(0x00000002)
1823#define TXWI_W0_CF_ACK FIELD32(0x00000004)
1824#define TXWI_W0_TS FIELD32(0x00000008)
1825#define TXWI_W0_AMPDU FIELD32(0x00000010)
1826#define TXWI_W0_MPDU_DENSITY FIELD32(0x000000e0)
1827#define TXWI_W0_TX_OP FIELD32(0x00000300)
1828#define TXWI_W0_MCS FIELD32(0x007f0000)
1829#define TXWI_W0_BW FIELD32(0x00800000)
1830#define TXWI_W0_SHORT_GI FIELD32(0x01000000)
1831#define TXWI_W0_STBC FIELD32(0x06000000)
1832#define TXWI_W0_IFS FIELD32(0x08000000)
1833#define TXWI_W0_PHYMODE FIELD32(0xc0000000)
1834
1835/*
1836 * Word1
1837 */
1838#define TXWI_W1_ACK FIELD32(0x00000001)
1839#define TXWI_W1_NSEQ FIELD32(0x00000002)
1840#define TXWI_W1_BW_WIN_SIZE FIELD32(0x000000fc)
1841#define TXWI_W1_WIRELESS_CLI_ID FIELD32(0x0000ff00)
1842#define TXWI_W1_MPDU_TOTAL_BYTE_COUNT FIELD32(0x0fff0000)
1843#define TXWI_W1_PACKETID FIELD32(0xf0000000)
1844
1845/*
1846 * Word2
1847 */
1848#define TXWI_W2_IV FIELD32(0xffffffff)
1849
1850/*
1851 * Word3
1852 */
1853#define TXWI_W3_EIV FIELD32(0xffffffff)
1854
1855/*
1856 * RX descriptor format for RX Ring. 100 * RX descriptor format for RX Ring.
1857 */ 101 */
1858 102
@@ -1888,64 +132,4 @@ struct mac_iveiv_entry {
1888#define RXD_W0_LAST_AMSDU FIELD32(0x00080000) 132#define RXD_W0_LAST_AMSDU FIELD32(0x00080000)
1889#define RXD_W0_PLCP_SIGNAL FIELD32(0xfff00000) 133#define RXD_W0_PLCP_SIGNAL FIELD32(0xfff00000)
1890 134
1891/*
1892 * RX WI structure
1893 */
1894
1895/*
1896 * Word0
1897 */
1898#define RXWI_W0_WIRELESS_CLI_ID FIELD32(0x000000ff)
1899#define RXWI_W0_KEY_INDEX FIELD32(0x00000300)
1900#define RXWI_W0_BSSID FIELD32(0x00001c00)
1901#define RXWI_W0_UDF FIELD32(0x0000e000)
1902#define RXWI_W0_MPDU_TOTAL_BYTE_COUNT FIELD32(0x0fff0000)
1903#define RXWI_W0_TID FIELD32(0xf0000000)
1904
1905/*
1906 * Word1
1907 */
1908#define RXWI_W1_FRAG FIELD32(0x0000000f)
1909#define RXWI_W1_SEQUENCE FIELD32(0x0000fff0)
1910#define RXWI_W1_MCS FIELD32(0x007f0000)
1911#define RXWI_W1_BW FIELD32(0x00800000)
1912#define RXWI_W1_SHORT_GI FIELD32(0x01000000)
1913#define RXWI_W1_STBC FIELD32(0x06000000)
1914#define RXWI_W1_PHYMODE FIELD32(0xc0000000)
1915
1916/*
1917 * Word2
1918 */
1919#define RXWI_W2_RSSI0 FIELD32(0x000000ff)
1920#define RXWI_W2_RSSI1 FIELD32(0x0000ff00)
1921#define RXWI_W2_RSSI2 FIELD32(0x00ff0000)
1922
1923/*
1924 * Word3
1925 */
1926#define RXWI_W3_SNR0 FIELD32(0x000000ff)
1927#define RXWI_W3_SNR1 FIELD32(0x0000ff00)
1928
1929/*
1930 * Macros for converting txpower from EEPROM to mac80211 value
1931 * and from mac80211 value to register value.
1932 */
1933#define MIN_G_TXPOWER 0
1934#define MIN_A_TXPOWER -7
1935#define MAX_G_TXPOWER 31
1936#define MAX_A_TXPOWER 15
1937#define DEFAULT_TXPOWER 5
1938
1939#define TXPOWER_G_FROM_DEV(__txpower) \
1940 ((__txpower) > MAX_G_TXPOWER) ? DEFAULT_TXPOWER : (__txpower)
1941
1942#define TXPOWER_G_TO_DEV(__txpower) \
1943 clamp_t(char, __txpower, MIN_G_TXPOWER, MAX_G_TXPOWER)
1944
1945#define TXPOWER_A_FROM_DEV(__txpower) \
1946 ((__txpower) > MAX_A_TXPOWER) ? DEFAULT_TXPOWER : (__txpower)
1947
1948#define TXPOWER_A_TO_DEV(__txpower) \
1949 clamp_t(char, __txpower, MIN_A_TXPOWER, MAX_A_TXPOWER)
1950
1951#endif /* RT2800USB_H */ 135#endif /* RT2800USB_H */
diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
index 196de8ab8153..c83dbaefd57a 100644
--- a/drivers/net/wireless/rt2x00/rt2x00.h
+++ b/drivers/net/wireless/rt2x00/rt2x00.h
@@ -144,6 +144,11 @@ struct avg_val {
144 int avg_weight; 144 int avg_weight;
145}; 145};
146 146
147enum rt2x00_chip_intf {
148 RT2X00_CHIP_INTF_PCI,
149 RT2X00_CHIP_INTF_USB,
150};
151
147/* 152/*
148 * Chipset identification 153 * Chipset identification
149 * The chipset on the device is composed of a RT and RF chip. 154 * The chipset on the device is composed of a RT and RF chip.
@@ -169,6 +174,8 @@ struct rt2x00_chip {
169 174
170 u16 rf; 175 u16 rf;
171 u32 rev; 176 u32 rev;
177
178 enum rt2x00_chip_intf intf;
172}; 179};
173 180
174/* 181/*
@@ -842,9 +849,23 @@ struct rt2x00_dev {
842 * Firmware image. 849 * Firmware image.
843 */ 850 */
844 const struct firmware *fw; 851 const struct firmware *fw;
852
853 /*
854 * Driver specific data.
855 */
856 void *priv;
845}; 857};
846 858
847/* 859/*
860 * Register defines.
861 * Some registers require multiple attempts before success,
862 * in those cases REGISTER_BUSY_COUNT attempts should be
863 * taken with a REGISTER_BUSY_DELAY interval.
864 */
865#define REGISTER_BUSY_COUNT 5
866#define REGISTER_BUSY_DELAY 100
867
868/*
848 * Generic RF access. 869 * Generic RF access.
849 * The RF is being accessed by word index. 870 * The RF is being accessed by word index.
850 */ 871 */
@@ -932,6 +953,28 @@ static inline bool rt2x00_check_rev(const struct rt2x00_chip *chipset,
932 return ((chipset->rev & mask) == rev); 953 return ((chipset->rev & mask) == rev);
933} 954}
934 955
956static inline void rt2x00_set_chip_intf(struct rt2x00_dev *rt2x00dev,
957 enum rt2x00_chip_intf intf)
958{
959 rt2x00dev->chip.intf = intf;
960}
961
962static inline bool rt2x00_intf(const struct rt2x00_chip *chipset,
963 enum rt2x00_chip_intf intf)
964{
965 return (chipset->intf == intf);
966}
967
968static inline bool rt2x00_intf_is_pci(struct rt2x00_dev *rt2x00dev)
969{
970 return rt2x00_intf(&rt2x00dev->chip, RT2X00_CHIP_INTF_PCI);
971}
972
973static inline bool rt2x00_intf_is_usb(struct rt2x00_dev *rt2x00dev)
974{
975 return rt2x00_intf(&rt2x00dev->chip, RT2X00_CHIP_INTF_USB);
976}
977
935/** 978/**
936 * rt2x00queue_map_txskb - Map a skb into DMA for TX purposes. 979 * rt2x00queue_map_txskb - Map a skb into DMA for TX purposes.
937 * @rt2x00dev: Pointer to &struct rt2x00_dev. 980 * @rt2x00dev: Pointer to &struct rt2x00_dev.
diff --git a/drivers/net/wireless/rt2x00/rt2x00leds.h b/drivers/net/wireless/rt2x00/rt2x00leds.h
index 1046977e6a12..8e03c045e037 100644
--- a/drivers/net/wireless/rt2x00/rt2x00leds.h
+++ b/drivers/net/wireless/rt2x00/rt2x00leds.h
@@ -33,8 +33,6 @@ enum led_type {
33 LED_TYPE_QUALITY, 33 LED_TYPE_QUALITY,
34}; 34};
35 35
36#ifdef CONFIG_RT2X00_LIB_LEDS
37
38struct rt2x00_led { 36struct rt2x00_led {
39 struct rt2x00_dev *rt2x00dev; 37 struct rt2x00_dev *rt2x00dev;
40 struct led_classdev led_dev; 38 struct led_classdev led_dev;
@@ -45,6 +43,4 @@ struct rt2x00_led {
45#define LED_REGISTERED ( 1 << 1 ) 43#define LED_REGISTERED ( 1 << 1 )
46}; 44};
47 45
48#endif /* CONFIG_RT2X00_LIB_LEDS */
49
50#endif /* RT2X00LEDS_H */ 46#endif /* RT2X00LEDS_H */
diff --git a/drivers/net/wireless/rt2x00/rt2x00pci.h b/drivers/net/wireless/rt2x00/rt2x00pci.h
index 15a12487e04b..ae33eebe9a6f 100644
--- a/drivers/net/wireless/rt2x00/rt2x00pci.h
+++ b/drivers/net/wireless/rt2x00/rt2x00pci.h
@@ -35,15 +35,6 @@
35#define PCI_DEVICE_DATA(__ops) .driver_data = (kernel_ulong_t)(__ops) 35#define PCI_DEVICE_DATA(__ops) .driver_data = (kernel_ulong_t)(__ops)
36 36
37/* 37/*
38 * Register defines.
39 * Some registers require multiple attempts before success,
40 * in those cases REGISTER_BUSY_COUNT attempts should be
41 * taken with a REGISTER_BUSY_DELAY interval.
42 */
43#define REGISTER_BUSY_COUNT 5
44#define REGISTER_BUSY_DELAY 100
45
46/*
47 * Register access. 38 * Register access.
48 */ 39 */
49static inline void rt2x00pci_register_read(struct rt2x00_dev *rt2x00dev, 40static inline void rt2x00pci_register_read(struct rt2x00_dev *rt2x00dev,
@@ -53,10 +44,9 @@ static inline void rt2x00pci_register_read(struct rt2x00_dev *rt2x00dev,
53 *value = readl(rt2x00dev->csr.base + offset); 44 *value = readl(rt2x00dev->csr.base + offset);
54} 45}
55 46
56static inline void 47static inline void rt2x00pci_register_multiread(struct rt2x00_dev *rt2x00dev,
57rt2x00pci_register_multiread(struct rt2x00_dev *rt2x00dev, 48 const unsigned int offset,
58 const unsigned int offset, 49 void *value, const u32 length)
59 void *value, const u16 length)
60{ 50{
61 memcpy_fromio(value, rt2x00dev->csr.base + offset, length); 51 memcpy_fromio(value, rt2x00dev->csr.base + offset, length);
62} 52}
@@ -68,10 +58,10 @@ static inline void rt2x00pci_register_write(struct rt2x00_dev *rt2x00dev,
68 writel(value, rt2x00dev->csr.base + offset); 58 writel(value, rt2x00dev->csr.base + offset);
69} 59}
70 60
71static inline void 61static inline void rt2x00pci_register_multiwrite(struct rt2x00_dev *rt2x00dev,
72rt2x00pci_register_multiwrite(struct rt2x00_dev *rt2x00dev, 62 const unsigned int offset,
73 const unsigned int offset, 63 const void *value,
74 const void *value, const u16 length) 64 const u32 length)
75{ 65{
76 memcpy_toio(rt2x00dev->csr.base + offset, value, length); 66 memcpy_toio(rt2x00dev->csr.base + offset, value, length);
77} 67}
diff --git a/drivers/net/wireless/rt2x00/rt2x00usb.c b/drivers/net/wireless/rt2x00/rt2x00usb.c
index f02b48a90593..c9cbdaa1073f 100644
--- a/drivers/net/wireless/rt2x00/rt2x00usb.c
+++ b/drivers/net/wireless/rt2x00/rt2x00usb.c
@@ -160,7 +160,7 @@ EXPORT_SYMBOL_GPL(rt2x00usb_vendor_request_large_buff);
160 160
161int rt2x00usb_regbusy_read(struct rt2x00_dev *rt2x00dev, 161int rt2x00usb_regbusy_read(struct rt2x00_dev *rt2x00dev,
162 const unsigned int offset, 162 const unsigned int offset,
163 struct rt2x00_field32 field, 163 const struct rt2x00_field32 field,
164 u32 *reg) 164 u32 *reg)
165{ 165{
166 unsigned int i; 166 unsigned int i;
diff --git a/drivers/net/wireless/rt2x00/rt2x00usb.h b/drivers/net/wireless/rt2x00/rt2x00usb.h
index bd2d59c85f1b..9943e428bc21 100644
--- a/drivers/net/wireless/rt2x00/rt2x00usb.h
+++ b/drivers/net/wireless/rt2x00/rt2x00usb.h
@@ -39,17 +39,11 @@
39#define USB_DEVICE_DATA(__ops) .driver_info = (kernel_ulong_t)(__ops) 39#define USB_DEVICE_DATA(__ops) .driver_info = (kernel_ulong_t)(__ops)
40 40
41/* 41/*
42 * Register defines.
43 * Some registers require multiple attempts before success,
44 * in those cases REGISTER_BUSY_COUNT attempts should be
45 * taken with a REGISTER_BUSY_DELAY interval.
46 * For USB vendor requests we need to pass a timeout 42 * For USB vendor requests we need to pass a timeout
47 * time in ms, for this we use the REGISTER_TIMEOUT, 43 * time in ms, for this we use the REGISTER_TIMEOUT,
48 * however when loading firmware a higher value is 44 * however when loading firmware a higher value is
49 * required. In that case we use the REGISTER_TIMEOUT_FIRMWARE. 45 * required. In that case we use the REGISTER_TIMEOUT_FIRMWARE.
50 */ 46 */
51#define REGISTER_BUSY_COUNT 5
52#define REGISTER_BUSY_DELAY 100
53#define REGISTER_TIMEOUT 500 47#define REGISTER_TIMEOUT 500
54#define REGISTER_TIMEOUT_FIRMWARE 1000 48#define REGISTER_TIMEOUT_FIRMWARE 1000
55 49
@@ -232,7 +226,7 @@ static inline int rt2x00usb_eeprom_read(struct rt2x00_dev *rt2x00dev,
232} 226}
233 227
234/** 228/**
235 * rt2x00usb_regbusy_read - Read 32bit register word 229 * rt2x00usb_register_read - Read 32bit register word
236 * @rt2x00dev: Device pointer, see &struct rt2x00_dev. 230 * @rt2x00dev: Device pointer, see &struct rt2x00_dev.
237 * @offset: Register offset 231 * @offset: Register offset
238 * @value: Pointer to where register contents should be stored 232 * @value: Pointer to where register contents should be stored
@@ -340,12 +334,13 @@ static inline void rt2x00usb_register_write_lock(struct rt2x00_dev *rt2x00dev,
340 * through rt2x00usb_vendor_request_buff(). 334 * through rt2x00usb_vendor_request_buff().
341 */ 335 */
342static inline void rt2x00usb_register_multiwrite(struct rt2x00_dev *rt2x00dev, 336static inline void rt2x00usb_register_multiwrite(struct rt2x00_dev *rt2x00dev,
343 const unsigned int offset, 337 const unsigned int offset,
344 void *value, const u32 length) 338 const void *value,
339 const u32 length)
345{ 340{
346 rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_WRITE, 341 rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_WRITE,
347 USB_VENDOR_REQUEST_OUT, offset, 342 USB_VENDOR_REQUEST_OUT, offset,
348 value, length, 343 (void *)value, length,
349 REGISTER_TIMEOUT32(length)); 344 REGISTER_TIMEOUT32(length));
350} 345}
351 346
@@ -364,7 +359,7 @@ static inline void rt2x00usb_register_multiwrite(struct rt2x00_dev *rt2x00dev,
364 */ 359 */
365int rt2x00usb_regbusy_read(struct rt2x00_dev *rt2x00dev, 360int rt2x00usb_regbusy_read(struct rt2x00_dev *rt2x00dev,
366 const unsigned int offset, 361 const unsigned int offset,
367 struct rt2x00_field32 field, 362 const struct rt2x00_field32 field,
368 u32 *reg); 363 u32 *reg);
369 364
370/* 365/*
diff --git a/drivers/net/wireless/rtl818x/rtl8187.h b/drivers/net/wireless/rtl818x/rtl8187.h
index bf9175a8c1f4..abb4907cf296 100644
--- a/drivers/net/wireless/rtl818x/rtl8187.h
+++ b/drivers/net/wireless/rtl818x/rtl8187.h
@@ -119,7 +119,6 @@ struct rtl8187_priv {
119 } hw_rev; 119 } hw_rev;
120 struct sk_buff_head rx_queue; 120 struct sk_buff_head rx_queue;
121 u8 signal; 121 u8 signal;
122 u8 quality;
123 u8 noise; 122 u8 noise;
124 u8 slot_time; 123 u8 slot_time;
125 u8 aifsn[4]; 124 u8 aifsn[4];
diff --git a/drivers/net/wireless/rtl818x/rtl8187_dev.c b/drivers/net/wireless/rtl818x/rtl8187_dev.c
index 2017ccc00145..76973b8c7099 100644
--- a/drivers/net/wireless/rtl818x/rtl8187_dev.c
+++ b/drivers/net/wireless/rtl818x/rtl8187_dev.c
@@ -320,7 +320,6 @@ static void rtl8187_rx_cb(struct urb *urb)
320 struct ieee80211_rx_status rx_status = { 0 }; 320 struct ieee80211_rx_status rx_status = { 0 };
321 int rate, signal; 321 int rate, signal;
322 u32 flags; 322 u32 flags;
323 u32 quality;
324 unsigned long f; 323 unsigned long f;
325 324
326 spin_lock_irqsave(&priv->rx_queue.lock, f); 325 spin_lock_irqsave(&priv->rx_queue.lock, f);
@@ -338,10 +337,9 @@ static void rtl8187_rx_cb(struct urb *urb)
338 (typeof(hdr))(skb_tail_pointer(skb) - sizeof(*hdr)); 337 (typeof(hdr))(skb_tail_pointer(skb) - sizeof(*hdr));
339 flags = le32_to_cpu(hdr->flags); 338 flags = le32_to_cpu(hdr->flags);
340 /* As with the RTL8187B below, the AGC is used to calculate 339 /* As with the RTL8187B below, the AGC is used to calculate
341 * signal strength and quality. In this case, the scaling 340 * signal strength. In this case, the scaling
342 * constants are derived from the output of p54usb. 341 * constants are derived from the output of p54usb.
343 */ 342 */
344 quality = 130 - ((41 * hdr->agc) >> 6);
345 signal = -4 - ((27 * hdr->agc) >> 6); 343 signal = -4 - ((27 * hdr->agc) >> 6);
346 rx_status.antenna = (hdr->signal >> 7) & 1; 344 rx_status.antenna = (hdr->signal >> 7) & 1;
347 rx_status.mactime = le64_to_cpu(hdr->mac_time); 345 rx_status.mactime = le64_to_cpu(hdr->mac_time);
@@ -354,23 +352,18 @@ static void rtl8187_rx_cb(struct urb *urb)
354 * In testing, none of these quantities show qualitative 352 * In testing, none of these quantities show qualitative
355 * agreement with AP signal strength, except for the AGC, 353 * agreement with AP signal strength, except for the AGC,
356 * which is inversely proportional to the strength of the 354 * which is inversely proportional to the strength of the
357 * signal. In the following, the quality and signal strength 355 * signal. In the following, the signal strength
358 * are derived from the AGC. The arbitrary scaling constants 356 * is derived from the AGC. The arbitrary scaling constants
359 * are chosen to make the results close to the values obtained 357 * are chosen to make the results close to the values obtained
360 * for a BCM4312 using b43 as the driver. The noise is ignored 358 * for a BCM4312 using b43 as the driver. The noise is ignored
361 * for now. 359 * for now.
362 */ 360 */
363 flags = le32_to_cpu(hdr->flags); 361 flags = le32_to_cpu(hdr->flags);
364 quality = 170 - hdr->agc;
365 signal = 14 - hdr->agc / 2; 362 signal = 14 - hdr->agc / 2;
366 rx_status.antenna = (hdr->rssi >> 7) & 1; 363 rx_status.antenna = (hdr->rssi >> 7) & 1;
367 rx_status.mactime = le64_to_cpu(hdr->mac_time); 364 rx_status.mactime = le64_to_cpu(hdr->mac_time);
368 } 365 }
369 366
370 if (quality > 100)
371 quality = 100;
372 rx_status.qual = quality;
373 priv->quality = quality;
374 rx_status.signal = signal; 367 rx_status.signal = signal;
375 priv->signal = signal; 368 priv->signal = signal;
376 rate = (flags >> 20) & 0xF; 369 rate = (flags >> 20) & 0xF;
diff --git a/drivers/net/wireless/wl12xx/Kconfig b/drivers/net/wireless/wl12xx/Kconfig
index 88060e117541..785e0244e305 100644
--- a/drivers/net/wireless/wl12xx/Kconfig
+++ b/drivers/net/wireless/wl12xx/Kconfig
@@ -1,6 +1,6 @@
1menuconfig WL12XX 1menuconfig WL12XX
2 tristate "TI wl12xx driver support" 2 tristate "TI wl12xx driver support"
3 depends on MAC80211 && WLAN_80211 && EXPERIMENTAL 3 depends on MAC80211 && EXPERIMENTAL
4 ---help--- 4 ---help---
5 This will enable TI wl12xx driver support. The drivers make 5 This will enable TI wl12xx driver support. The drivers make
6 use of the mac80211 stack. 6 use of the mac80211 stack.
@@ -42,6 +42,7 @@ config WL1251_SDIO
42config WL1271 42config WL1271
43 tristate "TI wl1271 support" 43 tristate "TI wl1271 support"
44 depends on WL12XX && SPI_MASTER && GENERIC_HARDIRQS 44 depends on WL12XX && SPI_MASTER && GENERIC_HARDIRQS
45 depends on INET
45 select FW_LOADER 46 select FW_LOADER
46 select CRC7 47 select CRC7
47 ---help--- 48 ---help---
diff --git a/drivers/net/wireless/wl12xx/wl1251_main.c b/drivers/net/wireless/wl12xx/wl1251_main.c
index 48b0bfd6c55a..da3bf1cebc08 100644
--- a/drivers/net/wireless/wl12xx/wl1251_main.c
+++ b/drivers/net/wireless/wl12xx/wl1251_main.c
@@ -1311,7 +1311,8 @@ int wl1251_init_ieee80211(struct wl1251 *wl)
1311 wl->hw->channel_change_time = 10000; 1311 wl->hw->channel_change_time = 10000;
1312 1312
1313 wl->hw->flags = IEEE80211_HW_SIGNAL_DBM | 1313 wl->hw->flags = IEEE80211_HW_SIGNAL_DBM |
1314 IEEE80211_HW_NOISE_DBM; 1314 IEEE80211_HW_NOISE_DBM |
1315 IEEE80211_HW_SUPPORTS_PS;
1315 1316
1316 wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION); 1317 wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
1317 wl->hw->wiphy->max_scan_ssids = 1; 1318 wl->hw->wiphy->max_scan_ssids = 1;
diff --git a/drivers/net/wireless/wl12xx/wl1271.h b/drivers/net/wireless/wl12xx/wl1271.h
index 566f1521ec22..94359b1a861f 100644
--- a/drivers/net/wireless/wl12xx/wl1271.h
+++ b/drivers/net/wireless/wl12xx/wl1271.h
@@ -417,6 +417,9 @@ struct wl1271 {
417 /* PSM mode requested */ 417 /* PSM mode requested */
418 bool psm_requested; 418 bool psm_requested;
419 419
420 /* retry counter for PSM entries */
421 u8 psm_entry_retry;
422
420 /* in dBm */ 423 /* in dBm */
421 int power_level; 424 int power_level;
422 425
diff --git a/drivers/net/wireless/wl12xx/wl1271_acx.c b/drivers/net/wireless/wl12xx/wl1271_acx.c
index bf5a8680a462..5cc89bbdac7a 100644
--- a/drivers/net/wireless/wl12xx/wl1271_acx.c
+++ b/drivers/net/wireless/wl12xx/wl1271_acx.c
@@ -141,7 +141,7 @@ int wl1271_acx_tx_power(struct wl1271 *wl, int power)
141 * calibration, to avoid distortions 141 * calibration, to avoid distortions
142 */ 142 */
143 /* acx->current_tx_power = power * 10; */ 143 /* acx->current_tx_power = power * 10; */
144 acx->current_tx_power = 70; 144 acx->current_tx_power = 120;
145 145
146 ret = wl1271_cmd_configure(wl, DOT11_CUR_TX_PWR, acx, sizeof(*acx)); 146 ret = wl1271_cmd_configure(wl, DOT11_CUR_TX_PWR, acx, sizeof(*acx));
147 if (ret < 0) { 147 if (ret < 0) {
diff --git a/drivers/net/wireless/wl12xx/wl1271_boot.c b/drivers/net/wireless/wl12xx/wl1271_boot.c
index ba4a2b4f0f56..b7c96454cca3 100644
--- a/drivers/net/wireless/wl12xx/wl1271_boot.c
+++ b/drivers/net/wireless/wl12xx/wl1271_boot.c
@@ -380,7 +380,7 @@ static int wl1271_boot_run_firmware(struct wl1271 *wl)
380 } 380 }
381 } 381 }
382 382
383 if (loop >= INIT_LOOP) { 383 if (loop > INIT_LOOP) {
384 wl1271_error("timeout waiting for the hardware to " 384 wl1271_error("timeout waiting for the hardware to "
385 "complete initialization"); 385 "complete initialization");
386 return -EIO; 386 return -EIO;
@@ -407,7 +407,8 @@ static int wl1271_boot_run_firmware(struct wl1271 *wl)
407 407
408 /* unmask required mbox events */ 408 /* unmask required mbox events */
409 wl->event_mask = BSS_LOSE_EVENT_ID | 409 wl->event_mask = BSS_LOSE_EVENT_ID |
410 SCAN_COMPLETE_EVENT_ID; 410 SCAN_COMPLETE_EVENT_ID |
411 PS_REPORT_EVENT_ID;
411 412
412 ret = wl1271_event_unmask(wl); 413 ret = wl1271_event_unmask(wl);
413 if (ret < 0) { 414 if (ret < 0) {
diff --git a/drivers/net/wireless/wl12xx/wl1271_cmd.c b/drivers/net/wireless/wl12xx/wl1271_cmd.c
index 0666328ce9ab..990eb01b4c71 100644
--- a/drivers/net/wireless/wl12xx/wl1271_cmd.c
+++ b/drivers/net/wireless/wl12xx/wl1271_cmd.c
@@ -42,12 +42,14 @@
42 * @buf: buffer containing the command, must work with dma 42 * @buf: buffer containing the command, must work with dma
43 * @len: length of the buffer 43 * @len: length of the buffer
44 */ 44 */
45int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len) 45int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len,
46 size_t res_len)
46{ 47{
47 struct wl1271_cmd_header *cmd; 48 struct wl1271_cmd_header *cmd;
48 unsigned long timeout; 49 unsigned long timeout;
49 u32 intr; 50 u32 intr;
50 int ret = 0; 51 int ret = 0;
52 u16 status;
51 53
52 cmd = buf; 54 cmd = buf;
53 cmd->id = cpu_to_le16(id); 55 cmd->id = cpu_to_le16(id);
@@ -74,6 +76,17 @@ int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len)
74 intr = wl1271_spi_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR); 76 intr = wl1271_spi_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
75 } 77 }
76 78
79 /* read back the status code of the command */
80 if (res_len == 0)
81 res_len = sizeof(struct wl1271_cmd_header);
82 wl1271_spi_read(wl, wl->cmd_box_addr, cmd, res_len, false);
83
84 status = le16_to_cpu(cmd->status);
85 if (status != CMD_STATUS_SUCCESS) {
86 wl1271_error("command execute failure %d", status);
87 ret = -EIO;
88 }
89
77 wl1271_spi_write32(wl, ACX_REG_INTERRUPT_ACK, 90 wl1271_spi_write32(wl, ACX_REG_INTERRUPT_ACK,
78 WL1271_ACX_INTR_CMD_COMPLETE); 91 WL1271_ACX_INTR_CMD_COMPLETE);
79 92
@@ -262,7 +275,7 @@ int wl1271_cmd_join(struct wl1271 *wl)
262 wl->tx_security_seq_16 = 0; 275 wl->tx_security_seq_16 = 0;
263 wl->tx_security_seq_32 = 0; 276 wl->tx_security_seq_32 = 0;
264 277
265 ret = wl1271_cmd_send(wl, CMD_START_JOIN, join, sizeof(*join)); 278 ret = wl1271_cmd_send(wl, CMD_START_JOIN, join, sizeof(*join), 0);
266 if (ret < 0) { 279 if (ret < 0) {
267 wl1271_error("failed to initiate cmd join"); 280 wl1271_error("failed to initiate cmd join");
268 goto out_free; 281 goto out_free;
@@ -294,35 +307,21 @@ out:
294int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer) 307int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer)
295{ 308{
296 int ret; 309 int ret;
310 size_t res_len = 0;
297 311
298 wl1271_debug(DEBUG_CMD, "cmd test"); 312 wl1271_debug(DEBUG_CMD, "cmd test");
299 313
300 ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len); 314 if (answer)
315 res_len = buf_len;
316
317 ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len, res_len);
301 318
302 if (ret < 0) { 319 if (ret < 0) {
303 wl1271_warning("TEST command failed"); 320 wl1271_warning("TEST command failed");
304 return ret; 321 return ret;
305 } 322 }
306 323
307 if (answer) { 324 return ret;
308 struct wl1271_command *cmd_answer;
309 u16 status;
310
311 /*
312 * The test command got in, we can read the answer.
313 * The answer would be a wl1271_command, where the
314 * parameter array contains the actual answer.
315 */
316 wl1271_spi_read(wl, wl->cmd_box_addr, buf, buf_len, false);
317
318 cmd_answer = buf;
319 status = le16_to_cpu(cmd_answer->header.status);
320
321 if (status != CMD_STATUS_SUCCESS)
322 wl1271_error("TEST command answer error: %d", status);
323 }
324
325 return 0;
326} 325}
327 326
328/** 327/**
@@ -345,21 +344,10 @@ int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len)
345 /* payload length, does not include any headers */ 344 /* payload length, does not include any headers */
346 acx->len = cpu_to_le16(len - sizeof(*acx)); 345 acx->len = cpu_to_le16(len - sizeof(*acx));
347 346
348 ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx)); 347 ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx), len);
349 if (ret < 0) { 348 if (ret < 0)
350 wl1271_error("INTERROGATE command failed"); 349 wl1271_error("INTERROGATE command failed");
351 goto out;
352 }
353 350
354 /* the interrogate command got in, we can read the answer */
355 wl1271_spi_read(wl, wl->cmd_box_addr, buf, len, false);
356
357 acx = buf;
358 if (le16_to_cpu(acx->cmd.status) != CMD_STATUS_SUCCESS)
359 wl1271_error("INTERROGATE command error: %d",
360 le16_to_cpu(acx->cmd.status));
361
362out:
363 return ret; 351 return ret;
364} 352}
365 353
@@ -383,7 +371,7 @@ int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len)
383 /* payload length, does not include any headers */ 371 /* payload length, does not include any headers */
384 acx->len = cpu_to_le16(len - sizeof(*acx)); 372 acx->len = cpu_to_le16(len - sizeof(*acx));
385 373
386 ret = wl1271_cmd_send(wl, CMD_CONFIGURE, acx, len); 374 ret = wl1271_cmd_send(wl, CMD_CONFIGURE, acx, len, 0);
387 if (ret < 0) { 375 if (ret < 0) {
388 wl1271_warning("CONFIGURE command NOK"); 376 wl1271_warning("CONFIGURE command NOK");
389 return ret; 377 return ret;
@@ -416,7 +404,7 @@ int wl1271_cmd_data_path(struct wl1271 *wl, u8 channel, bool enable)
416 cmd_tx = CMD_DISABLE_TX; 404 cmd_tx = CMD_DISABLE_TX;
417 } 405 }
418 406
419 ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd)); 407 ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd), 0);
420 if (ret < 0) { 408 if (ret < 0) {
421 wl1271_error("rx %s cmd for channel %d failed", 409 wl1271_error("rx %s cmd for channel %d failed",
422 enable ? "start" : "stop", channel); 410 enable ? "start" : "stop", channel);
@@ -426,7 +414,7 @@ int wl1271_cmd_data_path(struct wl1271 *wl, u8 channel, bool enable)
426 wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d", 414 wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d",
427 enable ? "start" : "stop", channel); 415 enable ? "start" : "stop", channel);
428 416
429 ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd)); 417 ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd), 0);
430 if (ret < 0) { 418 if (ret < 0) {
431 wl1271_error("tx %s cmd for channel %d failed", 419 wl1271_error("tx %s cmd for channel %d failed",
432 enable ? "start" : "stop", channel); 420 enable ? "start" : "stop", channel);
@@ -468,7 +456,7 @@ int wl1271_cmd_ps_mode(struct wl1271 *wl, u8 ps_mode)
468 ps_params->null_data_rate = cpu_to_le32(1); /* 1 Mbps */ 456 ps_params->null_data_rate = cpu_to_le32(1); /* 1 Mbps */
469 457
470 ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params, 458 ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params,
471 sizeof(*ps_params)); 459 sizeof(*ps_params), 0);
472 if (ret < 0) { 460 if (ret < 0) {
473 wl1271_error("cmd set_ps_mode failed"); 461 wl1271_error("cmd set_ps_mode failed");
474 goto out; 462 goto out;
@@ -499,19 +487,14 @@ int wl1271_cmd_read_memory(struct wl1271 *wl, u32 addr, void *answer,
499 cmd->addr = cpu_to_le32(addr); 487 cmd->addr = cpu_to_le32(addr);
500 cmd->size = cpu_to_le32(len); 488 cmd->size = cpu_to_le32(len);
501 489
502 ret = wl1271_cmd_send(wl, CMD_READ_MEMORY, cmd, sizeof(*cmd)); 490 ret = wl1271_cmd_send(wl, CMD_READ_MEMORY, cmd, sizeof(*cmd),
491 sizeof(*cmd));
503 if (ret < 0) { 492 if (ret < 0) {
504 wl1271_error("read memory command failed: %d", ret); 493 wl1271_error("read memory command failed: %d", ret);
505 goto out; 494 goto out;
506 } 495 }
507 496
508 /* the read command got in, we can now read the answer */ 497 /* the read command got in */
509 wl1271_spi_read(wl, wl->cmd_box_addr, cmd, sizeof(*cmd), false);
510
511 if (le16_to_cpu(cmd->header.status) != CMD_STATUS_SUCCESS)
512 wl1271_error("error in read command result: %d",
513 le16_to_cpu(cmd->header.status));
514
515 memcpy(answer, cmd->value, len); 498 memcpy(answer, cmd->value, len);
516 499
517out: 500out:
@@ -613,7 +596,7 @@ int wl1271_cmd_scan(struct wl1271 *wl, u8 *ssid, size_t len,
613 trigger->timeout = 0; 596 trigger->timeout = 0;
614 597
615 ret = wl1271_cmd_send(wl, CMD_TRIGGER_SCAN_TO, trigger, 598 ret = wl1271_cmd_send(wl, CMD_TRIGGER_SCAN_TO, trigger,
616 sizeof(*trigger)); 599 sizeof(*trigger), 0);
617 if (ret < 0) { 600 if (ret < 0) {
618 wl1271_error("trigger scan to failed for hw scan"); 601 wl1271_error("trigger scan to failed for hw scan");
619 goto out; 602 goto out;
@@ -636,20 +619,10 @@ int wl1271_cmd_scan(struct wl1271 *wl, u8 *ssid, size_t len,
636 } 619 }
637 } 620 }
638 621
639 ret = wl1271_cmd_send(wl, CMD_SCAN, params, sizeof(*params)); 622 ret = wl1271_cmd_send(wl, CMD_SCAN, params, sizeof(*params), 0);
640 if (ret < 0) { 623 if (ret < 0) {
641 wl1271_error("SCAN failed"); 624 wl1271_error("SCAN failed");
642 goto out;
643 }
644
645 wl1271_spi_read(wl, wl->cmd_box_addr, params, sizeof(*params),
646 false);
647
648 if (le16_to_cpu(params->header.status) != CMD_STATUS_SUCCESS) {
649 wl1271_error("Scan command error: %d",
650 le16_to_cpu(params->header.status));
651 wl->scanning = false; 625 wl->scanning = false;
652 ret = -EIO;
653 goto out; 626 goto out;
654 } 627 }
655 628
@@ -684,7 +657,7 @@ int wl1271_cmd_template_set(struct wl1271 *wl, u16 template_id,
684 if (buf) 657 if (buf)
685 memcpy(cmd->template_data, buf, buf_len); 658 memcpy(cmd->template_data, buf, buf_len);
686 659
687 ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd)); 660 ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd), 0);
688 if (ret < 0) { 661 if (ret < 0) {
689 wl1271_warning("cmd set_template failed: %d", ret); 662 wl1271_warning("cmd set_template failed: %d", ret);
690 goto out_free; 663 goto out_free;
@@ -863,7 +836,7 @@ int wl1271_cmd_set_default_wep_key(struct wl1271 *wl, u8 id)
863 cmd->key_action = cpu_to_le16(KEY_SET_ID); 836 cmd->key_action = cpu_to_le16(KEY_SET_ID);
864 cmd->key_type = KEY_WEP; 837 cmd->key_type = KEY_WEP;
865 838
866 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd)); 839 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
867 if (ret < 0) { 840 if (ret < 0) {
868 wl1271_warning("cmd set_default_wep_key failed: %d", ret); 841 wl1271_warning("cmd set_default_wep_key failed: %d", ret);
869 goto out; 842 goto out;
@@ -920,7 +893,7 @@ int wl1271_cmd_set_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
920 893
921 wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd)); 894 wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd));
922 895
923 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd)); 896 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
924 if (ret < 0) { 897 if (ret < 0) {
925 wl1271_warning("could not set keys"); 898 wl1271_warning("could not set keys");
926 goto out; 899 goto out;
@@ -950,7 +923,7 @@ int wl1271_cmd_disconnect(struct wl1271 *wl)
950 /* disconnect reason is not used in immediate disconnections */ 923 /* disconnect reason is not used in immediate disconnections */
951 cmd->type = DISCONNECT_IMMEDIATE; 924 cmd->type = DISCONNECT_IMMEDIATE;
952 925
953 ret = wl1271_cmd_send(wl, CMD_DISCONNECT, cmd, sizeof(*cmd)); 926 ret = wl1271_cmd_send(wl, CMD_DISCONNECT, cmd, sizeof(*cmd), 0);
954 if (ret < 0) { 927 if (ret < 0) {
955 wl1271_error("failed to send disconnect command"); 928 wl1271_error("failed to send disconnect command");
956 goto out_free; 929 goto out_free;
diff --git a/drivers/net/wireless/wl12xx/wl1271_cmd.h b/drivers/net/wireless/wl12xx/wl1271_cmd.h
index 174b8209dbf3..9d7061b3c8a0 100644
--- a/drivers/net/wireless/wl12xx/wl1271_cmd.h
+++ b/drivers/net/wireless/wl12xx/wl1271_cmd.h
@@ -29,7 +29,8 @@
29 29
30struct acx_header; 30struct acx_header;
31 31
32int wl1271_cmd_send(struct wl1271 *wl, u16 type, void *buf, size_t buf_len); 32int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len,
33 size_t res_len);
33int wl1271_cmd_join(struct wl1271 *wl); 34int wl1271_cmd_join(struct wl1271 *wl);
34int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer); 35int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer);
35int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len); 36int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len);
diff --git a/drivers/net/wireless/wl12xx/wl1271_conf.h b/drivers/net/wireless/wl12xx/wl1271_conf.h
index 061d47520a32..565373ede265 100644
--- a/drivers/net/wireless/wl12xx/wl1271_conf.h
+++ b/drivers/net/wireless/wl12xx/wl1271_conf.h
@@ -712,6 +712,14 @@ struct conf_conn_settings {
712 * Range 0 - 255 712 * Range 0 - 255
713 */ 713 */
714 u8 bet_max_consecutive; 714 u8 bet_max_consecutive;
715
716 /*
717 * Specifies the maximum number of times to try PSM entry if it fails
718 * (if sending the appropriate null-func message fails.)
719 *
720 * Range 0 - 255
721 */
722 u8 psm_entry_retries;
715}; 723};
716 724
717#define CONF_SR_ERR_TBL_MAX_VALUES 14 725#define CONF_SR_ERR_TBL_MAX_VALUES 14
diff --git a/drivers/net/wireless/wl12xx/wl1271_event.c b/drivers/net/wireless/wl12xx/wl1271_event.c
index 31d396ba9188..e135d894b42a 100644
--- a/drivers/net/wireless/wl12xx/wl1271_event.c
+++ b/drivers/net/wireless/wl12xx/wl1271_event.c
@@ -68,6 +68,40 @@ static int wl1271_event_scan_complete(struct wl1271 *wl,
68 return 0; 68 return 0;
69} 69}
70 70
71static int wl1271_event_ps_report(struct wl1271 *wl,
72 struct event_mailbox *mbox,
73 bool *beacon_loss)
74{
75 int ret = 0;
76
77 wl1271_debug(DEBUG_EVENT, "ps_status: 0x%x", mbox->ps_status);
78
79 switch (mbox->ps_status) {
80 case EVENT_ENTER_POWER_SAVE_FAIL:
81 if (wl->psm_entry_retry < wl->conf.conn.psm_entry_retries) {
82 wl->psm_entry_retry++;
83 wl1271_error("PSM entry failed, retrying %d\n",
84 wl->psm_entry_retry);
85 ret = wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE);
86 } else {
87 wl->psm_entry_retry = 0;
88 *beacon_loss = true;
89 }
90 break;
91 case EVENT_ENTER_POWER_SAVE_SUCCESS:
92 wl->psm_entry_retry = 0;
93 break;
94 case EVENT_EXIT_POWER_SAVE_FAIL:
95 wl1271_info("PSM exit failed");
96 break;
97 case EVENT_EXIT_POWER_SAVE_SUCCESS:
98 default:
99 break;
100 }
101
102 return ret;
103}
104
71static void wl1271_event_mbox_dump(struct event_mailbox *mbox) 105static void wl1271_event_mbox_dump(struct event_mailbox *mbox)
72{ 106{
73 wl1271_debug(DEBUG_EVENT, "MBOX DUMP:"); 107 wl1271_debug(DEBUG_EVENT, "MBOX DUMP:");
@@ -79,6 +113,7 @@ static int wl1271_event_process(struct wl1271 *wl, struct event_mailbox *mbox)
79{ 113{
80 int ret; 114 int ret;
81 u32 vector; 115 u32 vector;
116 bool beacon_loss = false;
82 117
83 wl1271_event_mbox_dump(mbox); 118 wl1271_event_mbox_dump(mbox);
84 119
@@ -101,7 +136,25 @@ static int wl1271_event_process(struct wl1271 *wl, struct event_mailbox *mbox)
101 wl1271_debug(DEBUG_EVENT, "BSS_LOSE_EVENT"); 136 wl1271_debug(DEBUG_EVENT, "BSS_LOSE_EVENT");
102 137
103 /* indicate to the stack, that beacons have been lost */ 138 /* indicate to the stack, that beacons have been lost */
139 beacon_loss = true;
140 }
141
142 if (vector & PS_REPORT_EVENT_ID) {
143 wl1271_debug(DEBUG_EVENT, "PS_REPORT_EVENT");
144 ret = wl1271_event_ps_report(wl, mbox, &beacon_loss);
145 if (ret < 0)
146 return ret;
147 }
148
149 if (beacon_loss) {
150 /* Obviously, it's dangerous to release the mutex while
151 we are holding many of the variables in the wl struct.
152 That's why it's done last in the function, and care must
153 be taken that nothing more is done after this function
154 returns. */
155 mutex_unlock(&wl->mutex);
104 ieee80211_beacon_loss(wl->vif); 156 ieee80211_beacon_loss(wl->vif);
157 mutex_lock(&wl->mutex);
105 } 158 }
106 159
107 return 0; 160 return 0;
diff --git a/drivers/net/wireless/wl12xx/wl1271_event.h b/drivers/net/wireless/wl12xx/wl1271_event.h
index 3ab53d331f15..4e3f55ebb1a8 100644
--- a/drivers/net/wireless/wl12xx/wl1271_event.h
+++ b/drivers/net/wireless/wl12xx/wl1271_event.h
@@ -63,6 +63,13 @@ enum {
63 EVENT_MBOX_ALL_EVENT_ID = 0x7fffffff, 63 EVENT_MBOX_ALL_EVENT_ID = 0x7fffffff,
64}; 64};
65 65
66enum {
67 EVENT_ENTER_POWER_SAVE_FAIL = 0,
68 EVENT_ENTER_POWER_SAVE_SUCCESS,
69 EVENT_EXIT_POWER_SAVE_FAIL,
70 EVENT_EXIT_POWER_SAVE_SUCCESS,
71};
72
66struct event_debug_report { 73struct event_debug_report {
67 u8 debug_event_id; 74 u8 debug_event_id;
68 u8 num_params; 75 u8 num_params;
diff --git a/drivers/net/wireless/wl12xx/wl1271_init.c b/drivers/net/wireless/wl12xx/wl1271_init.c
index 417b4152feb1..7c2017f480ea 100644
--- a/drivers/net/wireless/wl12xx/wl1271_init.c
+++ b/drivers/net/wireless/wl12xx/wl1271_init.c
@@ -303,12 +303,15 @@ int wl1271_hw_init(struct wl1271 *wl)
303{ 303{
304 int ret; 304 int ret;
305 305
306 /* FIXME: the following parameter setting functions return error
307 * codes - the reason is so far unknown. The -EIO is therefore
308 * ignored for the time being. */
306 ret = wl1271_init_general_parms(wl); 309 ret = wl1271_init_general_parms(wl);
307 if (ret < 0) 310 if (ret < 0 && ret != -EIO)
308 return ret; 311 return ret;
309 312
310 ret = wl1271_init_radio_parms(wl); 313 ret = wl1271_init_radio_parms(wl);
311 if (ret < 0) 314 if (ret < 0 && ret != -EIO)
312 return ret; 315 return ret;
313 316
314 /* Template settings */ 317 /* Template settings */
diff --git a/drivers/net/wireless/wl12xx/wl1271_main.c b/drivers/net/wireless/wl12xx/wl1271_main.c
index 86132bb00787..d2149fcd3cf1 100644
--- a/drivers/net/wireless/wl12xx/wl1271_main.c
+++ b/drivers/net/wireless/wl12xx/wl1271_main.c
@@ -222,7 +222,8 @@ static struct conf_drv_settings default_conf = {
222 .snr_pkt_avg_weight = 10 222 .snr_pkt_avg_weight = 10
223 }, 223 },
224 .bet_enable = CONF_BET_MODE_ENABLE, 224 .bet_enable = CONF_BET_MODE_ENABLE,
225 .bet_max_consecutive = 100 225 .bet_max_consecutive = 100,
226 .psm_entry_retries = 3
226 }, 227 },
227 .init = { 228 .init = {
228 .sr_err_tbl = { 229 .sr_err_tbl = {
@@ -973,6 +974,7 @@ static void wl1271_op_stop(struct ieee80211_hw *hw)
973 wl->rx_counter = 0; 974 wl->rx_counter = 0;
974 wl->elp = false; 975 wl->elp = false;
975 wl->psm = 0; 976 wl->psm = 0;
977 wl->psm_entry_retry = 0;
976 wl->tx_queue_stopped = false; 978 wl->tx_queue_stopped = false;
977 wl->power_level = WL1271_DEFAULT_POWER_LEVEL; 979 wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
978 wl->tx_blocks_available = 0; 980 wl->tx_blocks_available = 0;
@@ -1067,11 +1069,11 @@ static int wl1271_op_config_interface(struct ieee80211_hw *hw,
1067 ret = wl1271_cmd_join(wl); 1069 ret = wl1271_cmd_join(wl);
1068 if (ret < 0) 1070 if (ret < 0)
1069 goto out_sleep; 1071 goto out_sleep;
1070 }
1071 1072
1072 ret = wl1271_cmd_build_null_data(wl); 1073 ret = wl1271_cmd_build_null_data(wl);
1073 if (ret < 0) 1074 if (ret < 0)
1074 goto out_sleep; 1075 goto out_sleep;
1076 }
1075 1077
1076 wl->ssid_len = conf->ssid_len; 1078 wl->ssid_len = conf->ssid_len;
1077 if (wl->ssid_len) 1079 if (wl->ssid_len)
@@ -1137,10 +1139,6 @@ static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed)
1137 wl->channel = channel; 1139 wl->channel = channel;
1138 } 1140 }
1139 1141
1140 ret = wl1271_cmd_build_null_data(wl);
1141 if (ret < 0)
1142 goto out_sleep;
1143
1144 if (conf->flags & IEEE80211_CONF_PS && !wl->psm_requested) { 1142 if (conf->flags & IEEE80211_CONF_PS && !wl->psm_requested) {
1145 wl1271_info("psm enabled"); 1143 wl1271_info("psm enabled");
1146 1144
@@ -1165,7 +1163,7 @@ static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed)
1165 if (conf->power_level != wl->power_level) { 1163 if (conf->power_level != wl->power_level) {
1166 ret = wl1271_acx_tx_power(wl, conf->power_level); 1164 ret = wl1271_acx_tx_power(wl, conf->power_level);
1167 if (ret < 0) 1165 if (ret < 0)
1168 goto out; 1166 goto out_sleep;
1169 1167
1170 wl->power_level = conf->power_level; 1168 wl->power_level = conf->power_level;
1171 } 1169 }
@@ -1826,6 +1824,7 @@ static int __devinit wl1271_probe(struct spi_device *spi)
1826 wl->elp = false; 1824 wl->elp = false;
1827 wl->psm = 0; 1825 wl->psm = 0;
1828 wl->psm_requested = false; 1826 wl->psm_requested = false;
1827 wl->psm_entry_retry = 0;
1829 wl->tx_queue_stopped = false; 1828 wl->tx_queue_stopped = false;
1830 wl->power_level = WL1271_DEFAULT_POWER_LEVEL; 1829 wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
1831 wl->basic_rate_set = WL1271_DEFAULT_BASIC_RATE_SET; 1830 wl->basic_rate_set = WL1271_DEFAULT_BASIC_RATE_SET;
diff --git a/drivers/net/wireless/wl12xx/wl1271_rx.c b/drivers/net/wireless/wl12xx/wl1271_rx.c
index 37d81ab6acc0..ca645f38109b 100644
--- a/drivers/net/wireless/wl12xx/wl1271_rx.c
+++ b/drivers/net/wireless/wl12xx/wl1271_rx.c
@@ -159,7 +159,7 @@ static void wl1271_rx_handle_data(struct wl1271 *wl, u32 length)
159 u8 *buf; 159 u8 *buf;
160 u8 beacon = 0; 160 u8 beacon = 0;
161 161
162 skb = dev_alloc_skb(length); 162 skb = __dev_alloc_skb(length, GFP_KERNEL);
163 if (!skb) { 163 if (!skb) {
164 wl1271_error("Couldn't allocate RX frame"); 164 wl1271_error("Couldn't allocate RX frame");
165 return; 165 return;
diff --git a/drivers/net/wireless/zd1211rw/Kconfig b/drivers/net/wireless/zd1211rw/Kconfig
index 74b31eafe72d..5f809695f71a 100644
--- a/drivers/net/wireless/zd1211rw/Kconfig
+++ b/drivers/net/wireless/zd1211rw/Kconfig
@@ -1,6 +1,6 @@
1config ZD1211RW 1config ZD1211RW
2 tristate "ZyDAS ZD1211/ZD1211B USB-wireless support" 2 tristate "ZyDAS ZD1211/ZD1211B USB-wireless support"
3 depends on USB && MAC80211 && WLAN_80211 && EXPERIMENTAL 3 depends on USB && MAC80211 && EXPERIMENTAL
4 select FW_LOADER 4 select FW_LOADER
5 ---help--- 5 ---help---
6 This is an experimental driver for the ZyDAS ZD1211/ZD1211B wireless 6 This is an experimental driver for the ZyDAS ZD1211/ZD1211B wireless
diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig
index 9a4dd5992f65..4e3873bfd010 100644
--- a/drivers/staging/Kconfig
+++ b/drivers/staging/Kconfig
@@ -131,5 +131,13 @@ source "drivers/staging/iio/Kconfig"
131 131
132source "drivers/staging/cowloop/Kconfig" 132source "drivers/staging/cowloop/Kconfig"
133 133
134source "drivers/staging/strip/Kconfig"
135
136source "drivers/staging/arlan/Kconfig"
137
138source "drivers/staging/wavelan/Kconfig"
139
140source "drivers/staging/netwave/Kconfig"
141
134endif # !STAGING_EXCLUDE_BUILD 142endif # !STAGING_EXCLUDE_BUILD
135endif # STAGING 143endif # STAGING
diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile
index 104f2f8897ec..fb1d7851b563 100644
--- a/drivers/staging/Makefile
+++ b/drivers/staging/Makefile
@@ -47,3 +47,8 @@ obj-$(CONFIG_RAR_REGISTER) += rar/
47obj-$(CONFIG_DX_SEP) += sep/ 47obj-$(CONFIG_DX_SEP) += sep/
48obj-$(CONFIG_IIO) += iio/ 48obj-$(CONFIG_IIO) += iio/
49obj-$(CONFIG_COWLOOP) += cowloop/ 49obj-$(CONFIG_COWLOOP) += cowloop/
50obj-$(CONFIG_STRIP) += strip/
51obj-$(CONFIG_ARLAN) += arlan/
52obj-$(CONFIG_WAVELAN) += wavelan/
53obj-$(CONFIG_PCMCIA_WAVELAN) += wavelan/
54obj-$(CONFIG_PCMCIA_NETWAVE) += netwave/
diff --git a/drivers/staging/arlan/Kconfig b/drivers/staging/arlan/Kconfig
new file mode 100644
index 000000000000..0585ed8b4d3e
--- /dev/null
+++ b/drivers/staging/arlan/Kconfig
@@ -0,0 +1,15 @@
1config ARLAN
2 tristate "Aironet Arlan 655 & IC2200 DS support"
3 depends on ISA && !64BIT
4 select WIRELESS_EXT
5 ---help---
6 Aironet makes Arlan, a class of wireless LAN adapters. These use the
7 www.Telxon.com chip, which is also used on several similar cards.
8 This driver is tested on the 655 and IC2200 series cards. Look at
9 <http://www.ylenurme.ee/~elmer/655/> for the latest information.
10
11 The driver is built as two modules, arlan and arlan-proc. The latter
12 is the /proc interface and is not needed most of time.
13
14 On some computers the card ends up in non-valid state after some
15 time. Use a ping-reset script to clear it.
diff --git a/drivers/staging/arlan/Makefile b/drivers/staging/arlan/Makefile
new file mode 100644
index 000000000000..9e58e5fae7b9
--- /dev/null
+++ b/drivers/staging/arlan/Makefile
@@ -0,0 +1,3 @@
1obj-$(CONFIG_ARLAN) += arlan.o
2
3arlan-objs := arlan-main.o arlan-proc.o
diff --git a/drivers/staging/arlan/TODO b/drivers/staging/arlan/TODO
new file mode 100644
index 000000000000..9bd15a2f6d9e
--- /dev/null
+++ b/drivers/staging/arlan/TODO
@@ -0,0 +1,7 @@
1TODO:
2 - step up and maintain this driver to ensure that it continues
3 to work. Having the hardware for this is pretty much a
4 requirement. If this does not happen, the will be removed in
5 the 2.6.35 kernel release.
6
7Please send patches to Greg Kroah-Hartman <greg@kroah.com>.
diff --git a/drivers/net/wireless/arlan-main.c b/drivers/staging/arlan/arlan-main.c
index 921a082487a1..921a082487a1 100644
--- a/drivers/net/wireless/arlan-main.c
+++ b/drivers/staging/arlan/arlan-main.c
diff --git a/drivers/net/wireless/arlan-proc.c b/drivers/staging/arlan/arlan-proc.c
index a8b689635a3b..a8b689635a3b 100644
--- a/drivers/net/wireless/arlan-proc.c
+++ b/drivers/staging/arlan/arlan-proc.c
diff --git a/drivers/net/wireless/arlan.h b/drivers/staging/arlan/arlan.h
index fb3ad51a1caf..fb3ad51a1caf 100644
--- a/drivers/net/wireless/arlan.h
+++ b/drivers/staging/arlan/arlan.h
diff --git a/drivers/staging/netwave/Kconfig b/drivers/staging/netwave/Kconfig
new file mode 100644
index 000000000000..c0c996c0550a
--- /dev/null
+++ b/drivers/staging/netwave/Kconfig
@@ -0,0 +1,11 @@
1config PCMCIA_NETWAVE
2 tristate "Xircom Netwave AirSurfer Pcmcia wireless support"
3 depends on PCMCIA
4 select WIRELESS_EXT
5 select WEXT_PRIV
6 help
7 Say Y here if you intend to attach this type of PCMCIA (PC-card)
8 wireless Ethernet networking card to your computer.
9
10 To compile this driver as a module, choose M here: the module will be
11 called netwave_cs. If unsure, say N.
diff --git a/drivers/staging/netwave/Makefile b/drivers/staging/netwave/Makefile
new file mode 100644
index 000000000000..2ab89de59b9b
--- /dev/null
+++ b/drivers/staging/netwave/Makefile
@@ -0,0 +1 @@
obj-$(CONFIG_PCMCIA_NETWAVE) += netwave_cs.o
diff --git a/drivers/staging/netwave/TODO b/drivers/staging/netwave/TODO
new file mode 100644
index 000000000000..9bd15a2f6d9e
--- /dev/null
+++ b/drivers/staging/netwave/TODO
@@ -0,0 +1,7 @@
1TODO:
2 - step up and maintain this driver to ensure that it continues
3 to work. Having the hardware for this is pretty much a
4 requirement. If this does not happen, the will be removed in
5 the 2.6.35 kernel release.
6
7Please send patches to Greg Kroah-Hartman <greg@kroah.com>.
diff --git a/drivers/net/wireless/netwave_cs.c b/drivers/staging/netwave/netwave_cs.c
index 9498b46c99a4..9498b46c99a4 100644
--- a/drivers/net/wireless/netwave_cs.c
+++ b/drivers/staging/netwave/netwave_cs.c
diff --git a/drivers/staging/strip/Kconfig b/drivers/staging/strip/Kconfig
new file mode 100644
index 000000000000..36257b5cd6e1
--- /dev/null
+++ b/drivers/staging/strip/Kconfig
@@ -0,0 +1,22 @@
1config STRIP
2 tristate "STRIP (Metricom starmode radio IP)"
3 depends on INET
4 select WIRELESS_EXT
5 ---help---
6 Say Y if you have a Metricom radio and intend to use Starmode Radio
7 IP. STRIP is a radio protocol developed for the MosquitoNet project
8 to send Internet traffic using Metricom radios. Metricom radios are
9 small, battery powered, 100kbit/sec packet radio transceivers, about
10 the size and weight of a cellular telephone. (You may also have heard
11 them called "Metricom modems" but we avoid the term "modem" because
12 it misleads many people into thinking that you can plug a Metricom
13 modem into a phone line and use it as a modem.)
14
15 You can use STRIP on any Linux machine with a serial port, although
16 it is obviously most useful for people with laptop computers. If you
17 think you might get a Metricom radio in the future, there is no harm
18 in saying Y to STRIP now, except that it makes the kernel a bit
19 bigger.
20
21 To compile this as a module, choose M here: the module will be
22 called strip.
diff --git a/drivers/staging/strip/Makefile b/drivers/staging/strip/Makefile
new file mode 100644
index 000000000000..6417bdcac2fb
--- /dev/null
+++ b/drivers/staging/strip/Makefile
@@ -0,0 +1 @@
obj-$(CONFIG_STRIP) += strip.o
diff --git a/drivers/staging/strip/TODO b/drivers/staging/strip/TODO
new file mode 100644
index 000000000000..9bd15a2f6d9e
--- /dev/null
+++ b/drivers/staging/strip/TODO
@@ -0,0 +1,7 @@
1TODO:
2 - step up and maintain this driver to ensure that it continues
3 to work. Having the hardware for this is pretty much a
4 requirement. If this does not happen, the will be removed in
5 the 2.6.35 kernel release.
6
7Please send patches to Greg Kroah-Hartman <greg@kroah.com>.
diff --git a/drivers/net/wireless/strip.c b/drivers/staging/strip/strip.c
index 698aade79d40..698aade79d40 100644
--- a/drivers/net/wireless/strip.c
+++ b/drivers/staging/strip/strip.c
diff --git a/drivers/staging/wavelan/Kconfig b/drivers/staging/wavelan/Kconfig
new file mode 100644
index 000000000000..786060e025c0
--- /dev/null
+++ b/drivers/staging/wavelan/Kconfig
@@ -0,0 +1,38 @@
1config WAVELAN
2 tristate "AT&T/Lucent old WaveLAN & DEC RoamAbout DS ISA support"
3 depends on ISA
4 select WIRELESS_EXT
5 select WEXT_SPY
6 select WEXT_PRIV
7 ---help---
8 The Lucent WaveLAN (formerly NCR and AT&T; or DEC RoamAbout DS) is
9 a Radio LAN (wireless Ethernet-like Local Area Network) using the
10 radio frequencies 900 MHz and 2.4 GHz.
11
12 If you want to use an ISA WaveLAN card under Linux, say Y and read
13 the Ethernet-HOWTO, available from
14 <http://www.tldp.org/docs.html#howto>. Some more specific
15 information is contained in
16 <file:Documentation/networking/wavelan.txt> and in the source code
17 <file:drivers/net/wireless/wavelan.p.h>.
18
19 You will also need the wireless tools package available from
20 <http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/Tools.html>.
21 Please read the man pages contained therein.
22
23 To compile this driver as a module, choose M here: the module will be
24 called wavelan.
25
26config PCMCIA_WAVELAN
27 tristate "AT&T/Lucent old WaveLAN Pcmcia wireless support"
28 depends on PCMCIA
29 select WIRELESS_EXT
30 select WEXT_SPY
31 select WEXT_PRIV
32 help
33 Say Y here if you intend to attach an AT&T/Lucent Wavelan PCMCIA
34 (PC-card) wireless Ethernet networking card to your computer. This
35 driver is for the non-IEEE-802.11 Wavelan cards.
36
37 To compile this driver as a module, choose M here: the module will be
38 called wavelan_cs. If unsure, say N.
diff --git a/drivers/staging/wavelan/Makefile b/drivers/staging/wavelan/Makefile
new file mode 100644
index 000000000000..1cde17c69a43
--- /dev/null
+++ b/drivers/staging/wavelan/Makefile
@@ -0,0 +1,2 @@
1obj-$(CONFIG_WAVELAN) += wavelan.o
2obj-$(CONFIG_PCMCIA_WAVELAN) += wavelan_cs.o
diff --git a/drivers/staging/wavelan/TODO b/drivers/staging/wavelan/TODO
new file mode 100644
index 000000000000..9bd15a2f6d9e
--- /dev/null
+++ b/drivers/staging/wavelan/TODO
@@ -0,0 +1,7 @@
1TODO:
2 - step up and maintain this driver to ensure that it continues
3 to work. Having the hardware for this is pretty much a
4 requirement. If this does not happen, the will be removed in
5 the 2.6.35 kernel release.
6
7Please send patches to Greg Kroah-Hartman <greg@kroah.com>.
diff --git a/drivers/net/wireless/i82586.h b/drivers/staging/wavelan/i82586.h
index 5f65b250646f..5f65b250646f 100644
--- a/drivers/net/wireless/i82586.h
+++ b/drivers/staging/wavelan/i82586.h
diff --git a/drivers/net/wireless/i82593.h b/drivers/staging/wavelan/i82593.h
index afac5c7a323d..afac5c7a323d 100644
--- a/drivers/net/wireless/i82593.h
+++ b/drivers/staging/wavelan/i82593.h
diff --git a/drivers/net/wireless/wavelan.c b/drivers/staging/wavelan/wavelan.c
index d634b2da3b84..d634b2da3b84 100644
--- a/drivers/net/wireless/wavelan.c
+++ b/drivers/staging/wavelan/wavelan.c
diff --git a/drivers/net/wireless/wavelan.h b/drivers/staging/wavelan/wavelan.h
index 9ab360558ffd..9ab360558ffd 100644
--- a/drivers/net/wireless/wavelan.h
+++ b/drivers/staging/wavelan/wavelan.h
diff --git a/drivers/net/wireless/wavelan.p.h b/drivers/staging/wavelan/wavelan.p.h
index dbe8de6e5f52..dbe8de6e5f52 100644
--- a/drivers/net/wireless/wavelan.p.h
+++ b/drivers/staging/wavelan/wavelan.p.h
diff --git a/drivers/net/wireless/wavelan_cs.c b/drivers/staging/wavelan/wavelan_cs.c
index 431a20ec6db6..431a20ec6db6 100644
--- a/drivers/net/wireless/wavelan_cs.c
+++ b/drivers/staging/wavelan/wavelan_cs.c
diff --git a/drivers/net/wireless/wavelan_cs.h b/drivers/staging/wavelan/wavelan_cs.h
index 2e4bfe4147c6..2e4bfe4147c6 100644
--- a/drivers/net/wireless/wavelan_cs.h
+++ b/drivers/staging/wavelan/wavelan_cs.h
diff --git a/drivers/net/wireless/wavelan_cs.p.h b/drivers/staging/wavelan/wavelan_cs.p.h
index 81d91531c4f9..81d91531c4f9 100644
--- a/drivers/net/wireless/wavelan_cs.p.h
+++ b/drivers/staging/wavelan/wavelan_cs.p.h