aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/rt2x00
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless/rt2x00')
-rw-r--r--drivers/net/wireless/rt2x00/Kconfig128
-rw-r--r--drivers/net/wireless/rt2x00/Makefile1
-rw-r--r--drivers/net/wireless/rt2x00/rt2400pci.c58
-rw-r--r--drivers/net/wireless/rt2x00/rt2400pci.h22
-rw-r--r--drivers/net/wireless/rt2x00/rt2500pci.c59
-rw-r--r--drivers/net/wireless/rt2x00/rt2500pci.h17
-rw-r--r--drivers/net/wireless/rt2x00/rt2500usb.c68
-rw-r--r--drivers/net/wireless/rt2x00/rt2500usb.h17
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00.h90
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00config.c16
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00crypto.c215
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00debug.c97
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00dev.c129
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00lib.h49
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00mac.c245
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00queue.c136
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00queue.h82
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00reg.h19
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00rfkill.c63
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00usb.c21
-rw-r--r--drivers/net/wireless/rt2x00/rt61pci.c447
-rw-r--r--drivers/net/wireless/rt2x00/rt61pci.h38
-rw-r--r--drivers/net/wireless/rt2x00/rt73usb.c457
-rw-r--r--drivers/net/wireless/rt2x00/rt73usb.h38
24 files changed, 1909 insertions, 603 deletions
diff --git a/drivers/net/wireless/rt2x00/Kconfig b/drivers/net/wireless/rt2x00/Kconfig
index d485a86bba75..f839ce044afd 100644
--- a/drivers/net/wireless/rt2x00/Kconfig
+++ b/drivers/net/wireless/rt2x00/Kconfig
@@ -1,5 +1,5 @@
1config RT2X00 1menuconfig RT2X00
2 tristate "Ralink driver support" 2 bool "Ralink driver support"
3 depends on MAC80211 && WLAN_80211 && EXPERIMENTAL 3 depends on MAC80211 && WLAN_80211 && EXPERIMENTAL
4 ---help--- 4 ---help---
5 This will enable the experimental support for the Ralink drivers, 5 This will enable the experimental support for the Ralink drivers,
@@ -17,31 +17,6 @@ config RT2X00
17 17
18if RT2X00 18if RT2X00
19 19
20config RT2X00_LIB
21 tristate
22
23config RT2X00_LIB_PCI
24 tristate
25 select RT2X00_LIB
26
27config RT2X00_LIB_USB
28 tristate
29 select RT2X00_LIB
30
31config RT2X00_LIB_FIRMWARE
32 boolean
33 depends on RT2X00_LIB
34 select FW_LOADER
35
36config RT2X00_LIB_RFKILL
37 boolean
38 depends on RT2X00_LIB
39 select RFKILL
40
41config RT2X00_LIB_LEDS
42 boolean
43 depends on RT2X00_LIB && NEW_LEDS
44
45config RT2400PCI 20config RT2400PCI
46 tristate "Ralink rt2400 (PCI/PCMCIA) support" 21 tristate "Ralink rt2400 (PCI/PCMCIA) support"
47 depends on PCI 22 depends on PCI
@@ -53,23 +28,6 @@ config RT2400PCI
53 28
54 When compiled as a module, this driver will be called "rt2400pci.ko". 29 When compiled as a module, this driver will be called "rt2400pci.ko".
55 30
56config RT2400PCI_RFKILL
57 bool "Ralink rt2400 rfkill support"
58 depends on RT2400PCI
59 select RT2X00_LIB_RFKILL
60 ---help---
61 This adds support for integrated rt2400 hardware that features a
62 hardware button to control the radio state.
63 This feature depends on the RF switch subsystem rfkill.
64
65config RT2400PCI_LEDS
66 bool "Ralink rt2400 leds support"
67 depends on RT2400PCI && NEW_LEDS
68 select LEDS_CLASS
69 select RT2X00_LIB_LEDS
70 ---help---
71 This adds support for led triggers provided my mac80211.
72
73config RT2500PCI 31config RT2500PCI
74 tristate "Ralink rt2500 (PCI/PCMCIA) support" 32 tristate "Ralink rt2500 (PCI/PCMCIA) support"
75 depends on PCI 33 depends on PCI
@@ -81,28 +39,12 @@ config RT2500PCI
81 39
82 When compiled as a module, this driver will be called "rt2500pci.ko". 40 When compiled as a module, this driver will be called "rt2500pci.ko".
83 41
84config RT2500PCI_RFKILL
85 bool "Ralink rt2500 rfkill support"
86 depends on RT2500PCI
87 select RT2X00_LIB_RFKILL
88 ---help---
89 This adds support for integrated rt2500 hardware that features a
90 hardware button to control the radio state.
91 This feature depends on the RF switch subsystem rfkill.
92
93config RT2500PCI_LEDS
94 bool "Ralink rt2500 leds support"
95 depends on RT2500PCI && NEW_LEDS
96 select LEDS_CLASS
97 select RT2X00_LIB_LEDS
98 ---help---
99 This adds support for led triggers provided my mac80211.
100
101config RT61PCI 42config RT61PCI
102 tristate "Ralink rt2501/rt61 (PCI/PCMCIA) support" 43 tristate "Ralink rt2501/rt61 (PCI/PCMCIA) support"
103 depends on PCI 44 depends on PCI
104 select RT2X00_LIB_PCI 45 select RT2X00_LIB_PCI
105 select RT2X00_LIB_FIRMWARE 46 select RT2X00_LIB_FIRMWARE
47 select RT2X00_LIB_CRYPTO
106 select CRC_ITU_T 48 select CRC_ITU_T
107 select EEPROM_93CX6 49 select EEPROM_93CX6
108 ---help--- 50 ---help---
@@ -111,23 +53,6 @@ config RT61PCI
111 53
112 When compiled as a module, this driver will be called "rt61pci.ko". 54 When compiled as a module, this driver will be called "rt61pci.ko".
113 55
114config RT61PCI_RFKILL
115 bool "Ralink rt2501/rt61 rfkill support"
116 depends on RT61PCI
117 select RT2X00_LIB_RFKILL
118 ---help---
119 This adds support for integrated rt61 hardware that features a
120 hardware button to control the radio state.
121 This feature depends on the RF switch subsystem rfkill.
122
123config RT61PCI_LEDS
124 bool "Ralink rt2501/rt61 leds support"
125 depends on RT61PCI && NEW_LEDS
126 select LEDS_CLASS
127 select RT2X00_LIB_LEDS
128 ---help---
129 This adds support for led triggers provided my mac80211.
130
131config RT2500USB 56config RT2500USB
132 tristate "Ralink rt2500 (USB) support" 57 tristate "Ralink rt2500 (USB) support"
133 depends on USB 58 depends on USB
@@ -138,19 +63,12 @@ config RT2500USB
138 63
139 When compiled as a module, this driver will be called "rt2500usb.ko". 64 When compiled as a module, this driver will be called "rt2500usb.ko".
140 65
141config RT2500USB_LEDS
142 bool "Ralink rt2500 leds support"
143 depends on RT2500USB && NEW_LEDS
144 select LEDS_CLASS
145 select RT2X00_LIB_LEDS
146 ---help---
147 This adds support for led triggers provided my mac80211.
148
149config RT73USB 66config RT73USB
150 tristate "Ralink rt2501/rt73 (USB) support" 67 tristate "Ralink rt2501/rt73 (USB) support"
151 depends on USB 68 depends on USB
152 select RT2X00_LIB_USB 69 select RT2X00_LIB_USB
153 select RT2X00_LIB_FIRMWARE 70 select RT2X00_LIB_FIRMWARE
71 select RT2X00_LIB_CRYPTO
154 select CRC_ITU_T 72 select CRC_ITU_T
155 ---help--- 73 ---help---
156 This adds support for rt2501 wireless chipset family. 74 This adds support for rt2501 wireless chipset family.
@@ -158,13 +76,37 @@ config RT73USB
158 76
159 When compiled as a module, this driver will be called "rt73usb.ko". 77 When compiled as a module, this driver will be called "rt73usb.ko".
160 78
161config RT73USB_LEDS 79config RT2X00_LIB_PCI
162 bool "Ralink rt2501/rt73 leds support" 80 tristate
163 depends on RT73USB && NEW_LEDS 81 select RT2X00_LIB
164 select LEDS_CLASS 82
165 select RT2X00_LIB_LEDS 83config RT2X00_LIB_USB
166 ---help--- 84 tristate
167 This adds support for led triggers provided my mac80211. 85 select RT2X00_LIB
86
87config RT2X00_LIB
88 tristate
89
90config RT2X00_LIB_FIRMWARE
91 boolean
92 select FW_LOADER
93
94config RT2X00_LIB_CRYPTO
95 boolean
96
97config RT2X00_LIB_RFKILL
98 boolean
99 default y if (RT2X00_LIB=y && RFKILL=y) || (RT2X00_LIB=m && RFKILL!=n)
100
101comment "rt2x00 rfkill support disabled due to modularized RFKILL and built-in rt2x00"
102 depends on RT2X00_LIB=y && RFKILL=m
103
104config RT2X00_LIB_LEDS
105 boolean
106 default y if (RT2X00_LIB=y && LEDS_CLASS=y) || (RT2X00_LIB=m && LEDS_CLASS!=n)
107
108comment "rt2x00 leds support disabled due to modularized LEDS_CLASS and built-in rt2x00"
109 depends on RT2X00_LIB=y && LEDS_CLASS=m
168 110
169config RT2X00_LIB_DEBUGFS 111config RT2X00_LIB_DEBUGFS
170 bool "Ralink debugfs support" 112 bool "Ralink debugfs support"
diff --git a/drivers/net/wireless/rt2x00/Makefile b/drivers/net/wireless/rt2x00/Makefile
index 1087dbcf1a04..917cb4f3b038 100644
--- a/drivers/net/wireless/rt2x00/Makefile
+++ b/drivers/net/wireless/rt2x00/Makefile
@@ -3,6 +3,7 @@ rt2x00lib-y += rt2x00mac.o
3rt2x00lib-y += rt2x00config.o 3rt2x00lib-y += rt2x00config.o
4rt2x00lib-y += rt2x00queue.o 4rt2x00lib-y += rt2x00queue.o
5rt2x00lib-$(CONFIG_RT2X00_LIB_DEBUGFS) += rt2x00debug.o 5rt2x00lib-$(CONFIG_RT2X00_LIB_DEBUGFS) += rt2x00debug.o
6rt2x00lib-$(CONFIG_RT2X00_LIB_CRYPTO) += rt2x00crypto.o
6rt2x00lib-$(CONFIG_RT2X00_LIB_RFKILL) += rt2x00rfkill.o 7rt2x00lib-$(CONFIG_RT2X00_LIB_RFKILL) += rt2x00rfkill.o
7rt2x00lib-$(CONFIG_RT2X00_LIB_FIRMWARE) += rt2x00firmware.o 8rt2x00lib-$(CONFIG_RT2X00_LIB_FIRMWARE) += rt2x00firmware.o
8rt2x00lib-$(CONFIG_RT2X00_LIB_LEDS) += rt2x00leds.o 9rt2x00lib-$(CONFIG_RT2X00_LIB_LEDS) += rt2x00leds.o
diff --git a/drivers/net/wireless/rt2x00/rt2400pci.c b/drivers/net/wireless/rt2x00/rt2400pci.c
index 4c0538d6099b..08cb9eec16a6 100644
--- a/drivers/net/wireless/rt2x00/rt2400pci.c
+++ b/drivers/net/wireless/rt2x00/rt2400pci.c
@@ -231,7 +231,7 @@ static const struct rt2x00debug rt2400pci_rt2x00debug = {
231}; 231};
232#endif /* CONFIG_RT2X00_LIB_DEBUGFS */ 232#endif /* CONFIG_RT2X00_LIB_DEBUGFS */
233 233
234#ifdef CONFIG_RT2400PCI_RFKILL 234#ifdef CONFIG_RT2X00_LIB_RFKILL
235static int rt2400pci_rfkill_poll(struct rt2x00_dev *rt2x00dev) 235static int rt2400pci_rfkill_poll(struct rt2x00_dev *rt2x00dev)
236{ 236{
237 u32 reg; 237 u32 reg;
@@ -241,9 +241,9 @@ static int rt2400pci_rfkill_poll(struct rt2x00_dev *rt2x00dev)
241} 241}
242#else 242#else
243#define rt2400pci_rfkill_poll NULL 243#define rt2400pci_rfkill_poll NULL
244#endif /* CONFIG_RT2400PCI_RFKILL */ 244#endif /* CONFIG_RT2X00_LIB_RFKILL */
245 245
246#ifdef CONFIG_RT2400PCI_LEDS 246#ifdef CONFIG_RT2X00_LIB_LEDS
247static void rt2400pci_brightness_set(struct led_classdev *led_cdev, 247static void rt2400pci_brightness_set(struct led_classdev *led_cdev,
248 enum led_brightness brightness) 248 enum led_brightness brightness)
249{ 249{
@@ -288,7 +288,7 @@ static void rt2400pci_init_led(struct rt2x00_dev *rt2x00dev,
288 led->led_dev.blink_set = rt2400pci_blink_set; 288 led->led_dev.blink_set = rt2400pci_blink_set;
289 led->flags = LED_INITIALIZED; 289 led->flags = LED_INITIALIZED;
290} 290}
291#endif /* CONFIG_RT2400PCI_LEDS */ 291#endif /* CONFIG_RT2X00_LIB_LEDS */
292 292
293/* 293/*
294 * Configuration handlers. 294 * Configuration handlers.
@@ -1241,7 +1241,7 @@ static irqreturn_t rt2400pci_interrupt(int irq, void *dev_instance)
1241 if (!reg) 1241 if (!reg)
1242 return IRQ_NONE; 1242 return IRQ_NONE;
1243 1243
1244 if (!test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags)) 1244 if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
1245 return IRQ_HANDLED; 1245 return IRQ_HANDLED;
1246 1246
1247 /* 1247 /*
@@ -1374,22 +1374,22 @@ static int rt2400pci_init_eeprom(struct rt2x00_dev *rt2x00dev)
1374 /* 1374 /*
1375 * Store led mode, for correct led behaviour. 1375 * Store led mode, for correct led behaviour.
1376 */ 1376 */
1377#ifdef CONFIG_RT2400PCI_LEDS 1377#ifdef CONFIG_RT2X00_LIB_LEDS
1378 value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_LED_MODE); 1378 value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_LED_MODE);
1379 1379
1380 rt2400pci_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO); 1380 rt2400pci_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO);
1381 if (value == LED_MODE_TXRX_ACTIVITY) 1381 if (value == LED_MODE_TXRX_ACTIVITY)
1382 rt2400pci_init_led(rt2x00dev, &rt2x00dev->led_qual, 1382 rt2400pci_init_led(rt2x00dev, &rt2x00dev->led_qual,
1383 LED_TYPE_ACTIVITY); 1383 LED_TYPE_ACTIVITY);
1384#endif /* CONFIG_RT2400PCI_LEDS */ 1384#endif /* CONFIG_RT2X00_LIB_LEDS */
1385 1385
1386 /* 1386 /*
1387 * Detect if this device has an hardware controlled radio. 1387 * Detect if this device has an hardware controlled radio.
1388 */ 1388 */
1389#ifdef CONFIG_RT2400PCI_RFKILL 1389#ifdef CONFIG_RT2X00_LIB_RFKILL
1390 if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_HARDWARE_RADIO)) 1390 if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_HARDWARE_RADIO))
1391 __set_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags); 1391 __set_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags);
1392#endif /* CONFIG_RT2400PCI_RFKILL */ 1392#endif /* CONFIG_RT2X00_LIB_RFKILL */
1393 1393
1394 /* 1394 /*
1395 * Check if the BBP tuning should be enabled. 1395 * Check if the BBP tuning should be enabled.
@@ -1404,7 +1404,7 @@ static int rt2400pci_init_eeprom(struct rt2x00_dev *rt2x00dev)
1404 * RF value list for RF2420 & RF2421 1404 * RF value list for RF2420 & RF2421
1405 * Supports: 2.4 GHz 1405 * Supports: 2.4 GHz
1406 */ 1406 */
1407static const struct rf_channel rf_vals_bg[] = { 1407static const struct rf_channel rf_vals_b[] = {
1408 { 1, 0x00022058, 0x000c1fda, 0x00000101, 0 }, 1408 { 1, 0x00022058, 0x000c1fda, 0x00000101, 0 },
1409 { 2, 0x00022058, 0x000c1fee, 0x00000101, 0 }, 1409 { 2, 0x00022058, 0x000c1fee, 0x00000101, 0 },
1410 { 3, 0x00022058, 0x000c2002, 0x00000101, 0 }, 1410 { 3, 0x00022058, 0x000c2002, 0x00000101, 0 },
@@ -1421,10 +1421,11 @@ static const struct rf_channel rf_vals_bg[] = {
1421 { 14, 0x00022058, 0x000c20fa, 0x00000101, 0 }, 1421 { 14, 0x00022058, 0x000c20fa, 0x00000101, 0 },
1422}; 1422};
1423 1423
1424static void rt2400pci_probe_hw_mode(struct rt2x00_dev *rt2x00dev) 1424static int rt2400pci_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
1425{ 1425{
1426 struct hw_mode_spec *spec = &rt2x00dev->spec; 1426 struct hw_mode_spec *spec = &rt2x00dev->spec;
1427 u8 *txpower; 1427 struct channel_info *info;
1428 char *tx_power;
1428 unsigned int i; 1429 unsigned int i;
1429 1430
1430 /* 1431 /*
@@ -1440,23 +1441,28 @@ static void rt2400pci_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
1440 EEPROM_MAC_ADDR_0)); 1441 EEPROM_MAC_ADDR_0));
1441 1442
1442 /* 1443 /*
1443 * Convert tx_power array in eeprom.
1444 */
1445 txpower = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_START);
1446 for (i = 0; i < 14; i++)
1447 txpower[i] = TXPOWER_FROM_DEV(txpower[i]);
1448
1449 /*
1450 * Initialize hw_mode information. 1444 * Initialize hw_mode information.
1451 */ 1445 */
1452 spec->supported_bands = SUPPORT_BAND_2GHZ; 1446 spec->supported_bands = SUPPORT_BAND_2GHZ;
1453 spec->supported_rates = SUPPORT_RATE_CCK; 1447 spec->supported_rates = SUPPORT_RATE_CCK;
1454 spec->tx_power_a = NULL;
1455 spec->tx_power_bg = txpower;
1456 spec->tx_power_default = DEFAULT_TXPOWER;
1457 1448
1458 spec->num_channels = ARRAY_SIZE(rf_vals_bg); 1449 spec->num_channels = ARRAY_SIZE(rf_vals_b);
1459 spec->channels = rf_vals_bg; 1450 spec->channels = rf_vals_b;
1451
1452 /*
1453 * Create channel information array
1454 */
1455 info = kzalloc(spec->num_channels * sizeof(*info), GFP_KERNEL);
1456 if (!info)
1457 return -ENOMEM;
1458
1459 spec->channels_info = info;
1460
1461 tx_power = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_START);
1462 for (i = 0; i < 14; i++)
1463 info[i].tx_power1 = TXPOWER_FROM_DEV(tx_power[i]);
1464
1465 return 0;
1460} 1466}
1461 1467
1462static int rt2400pci_probe_hw(struct rt2x00_dev *rt2x00dev) 1468static int rt2400pci_probe_hw(struct rt2x00_dev *rt2x00dev)
@@ -1477,7 +1483,9 @@ static int rt2400pci_probe_hw(struct rt2x00_dev *rt2x00dev)
1477 /* 1483 /*
1478 * Initialize hw specifications. 1484 * Initialize hw specifications.
1479 */ 1485 */
1480 rt2400pci_probe_hw_mode(rt2x00dev); 1486 retval = rt2400pci_probe_hw_mode(rt2x00dev);
1487 if (retval)
1488 return retval;
1481 1489
1482 /* 1490 /*
1483 * This device requires the atim queue and DMA-mapped skbs. 1491 * This device requires the atim queue and DMA-mapped skbs.
diff --git a/drivers/net/wireless/rt2x00/rt2400pci.h b/drivers/net/wireless/rt2x00/rt2400pci.h
index bc5564258228..bbff381ce396 100644
--- a/drivers/net/wireless/rt2x00/rt2400pci.h
+++ b/drivers/net/wireless/rt2x00/rt2400pci.h
@@ -938,19 +938,13 @@
938#define MAX_TXPOWER 62 938#define MAX_TXPOWER 62
939#define DEFAULT_TXPOWER 39 939#define DEFAULT_TXPOWER 39
940 940
941#define TXPOWER_FROM_DEV(__txpower) \ 941#define __CLAMP_TX(__txpower) \
942({ \ 942 clamp_t(char, (__txpower), MIN_TXPOWER, MAX_TXPOWER)
943 ((__txpower) > MAX_TXPOWER) ? DEFAULT_TXPOWER - MIN_TXPOWER : \ 943
944 ((__txpower) < MIN_TXPOWER) ? DEFAULT_TXPOWER - MIN_TXPOWER : \ 944#define TXPOWER_FROM_DEV(__txpower) \
945 (((__txpower) - MAX_TXPOWER) + MIN_TXPOWER); \ 945 ((__CLAMP_TX(__txpower) - MAX_TXPOWER) + MIN_TXPOWER)
946}) 946
947 947#define TXPOWER_TO_DEV(__txpower) \
948#define TXPOWER_TO_DEV(__txpower) \ 948 MAX_TXPOWER - (__CLAMP_TX(__txpower) - MIN_TXPOWER)
949({ \
950 (__txpower) += MIN_TXPOWER; \
951 ((__txpower) <= MIN_TXPOWER) ? MAX_TXPOWER : \
952 (((__txpower) >= MAX_TXPOWER) ? MIN_TXPOWER : \
953 (MAX_TXPOWER - ((__txpower) - MIN_TXPOWER))); \
954})
955 949
956#endif /* RT2400PCI_H */ 950#endif /* RT2400PCI_H */
diff --git a/drivers/net/wireless/rt2x00/rt2500pci.c b/drivers/net/wireless/rt2x00/rt2500pci.c
index 181a146b4768..ef42cc04a2d7 100644
--- a/drivers/net/wireless/rt2x00/rt2500pci.c
+++ b/drivers/net/wireless/rt2x00/rt2500pci.c
@@ -231,7 +231,7 @@ static const struct rt2x00debug rt2500pci_rt2x00debug = {
231}; 231};
232#endif /* CONFIG_RT2X00_LIB_DEBUGFS */ 232#endif /* CONFIG_RT2X00_LIB_DEBUGFS */
233 233
234#ifdef CONFIG_RT2500PCI_RFKILL 234#ifdef CONFIG_RT2X00_LIB_RFKILL
235static int rt2500pci_rfkill_poll(struct rt2x00_dev *rt2x00dev) 235static int rt2500pci_rfkill_poll(struct rt2x00_dev *rt2x00dev)
236{ 236{
237 u32 reg; 237 u32 reg;
@@ -241,9 +241,9 @@ static int rt2500pci_rfkill_poll(struct rt2x00_dev *rt2x00dev)
241} 241}
242#else 242#else
243#define rt2500pci_rfkill_poll NULL 243#define rt2500pci_rfkill_poll NULL
244#endif /* CONFIG_RT2500PCI_RFKILL */ 244#endif /* CONFIG_RT2X00_LIB_RFKILL */
245 245
246#ifdef CONFIG_RT2500PCI_LEDS 246#ifdef CONFIG_RT2X00_LIB_LEDS
247static void rt2500pci_brightness_set(struct led_classdev *led_cdev, 247static void rt2500pci_brightness_set(struct led_classdev *led_cdev,
248 enum led_brightness brightness) 248 enum led_brightness brightness)
249{ 249{
@@ -288,7 +288,7 @@ static void rt2500pci_init_led(struct rt2x00_dev *rt2x00dev,
288 led->led_dev.blink_set = rt2500pci_blink_set; 288 led->led_dev.blink_set = rt2500pci_blink_set;
289 led->flags = LED_INITIALIZED; 289 led->flags = LED_INITIALIZED;
290} 290}
291#endif /* CONFIG_RT2500PCI_LEDS */ 291#endif /* CONFIG_RT2X00_LIB_LEDS */
292 292
293/* 293/*
294 * Configuration handlers. 294 * Configuration handlers.
@@ -1316,6 +1316,8 @@ static void rt2500pci_fill_rxdone(struct queue_entry *entry,
1316 1316
1317 if (rt2x00_get_field32(word0, RXD_W0_OFDM)) 1317 if (rt2x00_get_field32(word0, RXD_W0_OFDM))
1318 rxdesc->dev_flags |= RXDONE_SIGNAL_PLCP; 1318 rxdesc->dev_flags |= RXDONE_SIGNAL_PLCP;
1319 else
1320 rxdesc->dev_flags |= RXDONE_SIGNAL_BITRATE;
1319 if (rt2x00_get_field32(word0, RXD_W0_MY_BSS)) 1321 if (rt2x00_get_field32(word0, RXD_W0_MY_BSS))
1320 rxdesc->dev_flags |= RXDONE_MY_BSS; 1322 rxdesc->dev_flags |= RXDONE_MY_BSS;
1321} 1323}
@@ -1377,7 +1379,7 @@ static irqreturn_t rt2500pci_interrupt(int irq, void *dev_instance)
1377 if (!reg) 1379 if (!reg)
1378 return IRQ_NONE; 1380 return IRQ_NONE;
1379 1381
1380 if (!test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags)) 1382 if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
1381 return IRQ_HANDLED; 1383 return IRQ_HANDLED;
1382 1384
1383 /* 1385 /*
@@ -1531,22 +1533,22 @@ static int rt2500pci_init_eeprom(struct rt2x00_dev *rt2x00dev)
1531 /* 1533 /*
1532 * Store led mode, for correct led behaviour. 1534 * Store led mode, for correct led behaviour.
1533 */ 1535 */
1534#ifdef CONFIG_RT2500PCI_LEDS 1536#ifdef CONFIG_RT2X00_LIB_LEDS
1535 value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_LED_MODE); 1537 value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_LED_MODE);
1536 1538
1537 rt2500pci_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO); 1539 rt2500pci_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO);
1538 if (value == LED_MODE_TXRX_ACTIVITY) 1540 if (value == LED_MODE_TXRX_ACTIVITY)
1539 rt2500pci_init_led(rt2x00dev, &rt2x00dev->led_qual, 1541 rt2500pci_init_led(rt2x00dev, &rt2x00dev->led_qual,
1540 LED_TYPE_ACTIVITY); 1542 LED_TYPE_ACTIVITY);
1541#endif /* CONFIG_RT2500PCI_LEDS */ 1543#endif /* CONFIG_RT2X00_LIB_LEDS */
1542 1544
1543 /* 1545 /*
1544 * Detect if this device has an hardware controlled radio. 1546 * Detect if this device has an hardware controlled radio.
1545 */ 1547 */
1546#ifdef CONFIG_RT2500PCI_RFKILL 1548#ifdef CONFIG_RT2X00_LIB_RFKILL
1547 if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_HARDWARE_RADIO)) 1549 if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_HARDWARE_RADIO))
1548 __set_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags); 1550 __set_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags);
1549#endif /* CONFIG_RT2500PCI_RFKILL */ 1551#endif /* CONFIG_RT2X00_LIB_RFKILL */
1550 1552
1551 /* 1553 /*
1552 * Check if the BBP tuning should be enabled. 1554 * Check if the BBP tuning should be enabled.
@@ -1721,10 +1723,11 @@ static const struct rf_channel rf_vals_5222[] = {
1721 { 161, 0x00022020, 0x000090be, 0x00000101, 0x00000a07 }, 1723 { 161, 0x00022020, 0x000090be, 0x00000101, 0x00000a07 },
1722}; 1724};
1723 1725
1724static void rt2500pci_probe_hw_mode(struct rt2x00_dev *rt2x00dev) 1726static int rt2500pci_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
1725{ 1727{
1726 struct hw_mode_spec *spec = &rt2x00dev->spec; 1728 struct hw_mode_spec *spec = &rt2x00dev->spec;
1727 u8 *txpower; 1729 struct channel_info *info;
1730 char *tx_power;
1728 unsigned int i; 1731 unsigned int i;
1729 1732
1730 /* 1733 /*
@@ -1741,20 +1744,10 @@ static void rt2500pci_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
1741 EEPROM_MAC_ADDR_0)); 1744 EEPROM_MAC_ADDR_0));
1742 1745
1743 /* 1746 /*
1744 * Convert tx_power array in eeprom.
1745 */
1746 txpower = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_START);
1747 for (i = 0; i < 14; i++)
1748 txpower[i] = TXPOWER_FROM_DEV(txpower[i]);
1749
1750 /*
1751 * Initialize hw_mode information. 1747 * Initialize hw_mode information.
1752 */ 1748 */
1753 spec->supported_bands = SUPPORT_BAND_2GHZ; 1749 spec->supported_bands = SUPPORT_BAND_2GHZ;
1754 spec->supported_rates = SUPPORT_RATE_CCK | SUPPORT_RATE_OFDM; 1750 spec->supported_rates = SUPPORT_RATE_CCK | SUPPORT_RATE_OFDM;
1755 spec->tx_power_a = NULL;
1756 spec->tx_power_bg = txpower;
1757 spec->tx_power_default = DEFAULT_TXPOWER;
1758 1751
1759 if (rt2x00_rf(&rt2x00dev->chip, RF2522)) { 1752 if (rt2x00_rf(&rt2x00dev->chip, RF2522)) {
1760 spec->num_channels = ARRAY_SIZE(rf_vals_bg_2522); 1753 spec->num_channels = ARRAY_SIZE(rf_vals_bg_2522);
@@ -1776,6 +1769,26 @@ static void rt2500pci_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
1776 spec->num_channels = ARRAY_SIZE(rf_vals_5222); 1769 spec->num_channels = ARRAY_SIZE(rf_vals_5222);
1777 spec->channels = rf_vals_5222; 1770 spec->channels = rf_vals_5222;
1778 } 1771 }
1772
1773 /*
1774 * Create channel information array
1775 */
1776 info = kzalloc(spec->num_channels * sizeof(*info), GFP_KERNEL);
1777 if (!info)
1778 return -ENOMEM;
1779
1780 spec->channels_info = info;
1781
1782 tx_power = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_START);
1783 for (i = 0; i < 14; i++)
1784 info[i].tx_power1 = TXPOWER_FROM_DEV(tx_power[i]);
1785
1786 if (spec->num_channels > 14) {
1787 for (i = 14; i < spec->num_channels; i++)
1788 info[i].tx_power1 = DEFAULT_TXPOWER;
1789 }
1790
1791 return 0;
1779} 1792}
1780 1793
1781static int rt2500pci_probe_hw(struct rt2x00_dev *rt2x00dev) 1794static int rt2500pci_probe_hw(struct rt2x00_dev *rt2x00dev)
@@ -1796,7 +1809,9 @@ static int rt2500pci_probe_hw(struct rt2x00_dev *rt2x00dev)
1796 /* 1809 /*
1797 * Initialize hw specifications. 1810 * Initialize hw specifications.
1798 */ 1811 */
1799 rt2500pci_probe_hw_mode(rt2x00dev); 1812 retval = rt2500pci_probe_hw_mode(rt2x00dev);
1813 if (retval)
1814 return retval;
1800 1815
1801 /* 1816 /*
1802 * This device requires the atim queue and DMA-mapped skbs. 1817 * This device requires the atim queue and DMA-mapped skbs.
diff --git a/drivers/net/wireless/rt2x00/rt2500pci.h b/drivers/net/wireless/rt2x00/rt2500pci.h
index 42f376929ea9..8c26bef6cf49 100644
--- a/drivers/net/wireless/rt2x00/rt2500pci.h
+++ b/drivers/net/wireless/rt2x00/rt2500pci.h
@@ -1223,17 +1223,10 @@
1223#define MAX_TXPOWER 31 1223#define MAX_TXPOWER 31
1224#define DEFAULT_TXPOWER 24 1224#define DEFAULT_TXPOWER 24
1225 1225
1226#define TXPOWER_FROM_DEV(__txpower) \ 1226#define TXPOWER_FROM_DEV(__txpower) \
1227({ \ 1227 (((u8)(__txpower)) > MAX_TXPOWER) ? DEFAULT_TXPOWER : (__txpower)
1228 ((__txpower) > MAX_TXPOWER) ? \ 1228
1229 DEFAULT_TXPOWER : (__txpower); \ 1229#define TXPOWER_TO_DEV(__txpower) \
1230}) 1230 clamp_t(char, __txpower, MIN_TXPOWER, MAX_TXPOWER)
1231
1232#define TXPOWER_TO_DEV(__txpower) \
1233({ \
1234 ((__txpower) <= MIN_TXPOWER) ? MIN_TXPOWER : \
1235 (((__txpower) >= MAX_TXPOWER) ? MAX_TXPOWER : \
1236 (__txpower)); \
1237})
1238 1231
1239#endif /* RT2500PCI_H */ 1232#endif /* RT2500PCI_H */
diff --git a/drivers/net/wireless/rt2x00/rt2500usb.c b/drivers/net/wireless/rt2x00/rt2500usb.c
index cd5af656932d..d3bf7bba611a 100644
--- a/drivers/net/wireless/rt2x00/rt2500usb.c
+++ b/drivers/net/wireless/rt2x00/rt2500usb.c
@@ -288,7 +288,7 @@ static const struct rt2x00debug rt2500usb_rt2x00debug = {
288}; 288};
289#endif /* CONFIG_RT2X00_LIB_DEBUGFS */ 289#endif /* CONFIG_RT2X00_LIB_DEBUGFS */
290 290
291#ifdef CONFIG_RT2500USB_LEDS 291#ifdef CONFIG_RT2X00_LIB_LEDS
292static void rt2500usb_brightness_set(struct led_classdev *led_cdev, 292static void rt2500usb_brightness_set(struct led_classdev *led_cdev,
293 enum led_brightness brightness) 293 enum led_brightness brightness)
294{ 294{
@@ -333,7 +333,7 @@ static void rt2500usb_init_led(struct rt2x00_dev *rt2x00dev,
333 led->led_dev.blink_set = rt2500usb_blink_set; 333 led->led_dev.blink_set = rt2500usb_blink_set;
334 led->flags = LED_INITIALIZED; 334 led->flags = LED_INITIALIZED;
335} 335}
336#endif /* CONFIG_RT2500USB_LEDS */ 336#endif /* CONFIG_RT2X00_LIB_LEDS */
337 337
338/* 338/*
339 * Configuration handlers. 339 * Configuration handlers.
@@ -384,7 +384,7 @@ static void rt2500usb_config_intf(struct rt2x00_dev *rt2x00dev,
384 rt2500usb_register_read(rt2x00dev, TXRX_CSR20, &reg); 384 rt2500usb_register_read(rt2x00dev, TXRX_CSR20, &reg);
385 rt2x00_set_field16(&reg, TXRX_CSR20_OFFSET, bcn_preload >> 6); 385 rt2x00_set_field16(&reg, TXRX_CSR20_OFFSET, bcn_preload >> 6);
386 rt2x00_set_field16(&reg, TXRX_CSR20_BCN_EXPECT_WINDOW, 386 rt2x00_set_field16(&reg, TXRX_CSR20_BCN_EXPECT_WINDOW,
387 2 * (conf->type != IEEE80211_IF_TYPE_STA)); 387 2 * (conf->type != NL80211_IFTYPE_STATION));
388 rt2500usb_register_write(rt2x00dev, TXRX_CSR20, reg); 388 rt2500usb_register_write(rt2x00dev, TXRX_CSR20, reg);
389 389
390 /* 390 /*
@@ -1114,8 +1114,7 @@ static void rt2500usb_write_tx_desc(struct rt2x00_dev *rt2x00dev,
1114 rt2x00_set_field32(&word, TXD_W0_NEW_SEQ, 1114 rt2x00_set_field32(&word, TXD_W0_NEW_SEQ,
1115 test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags)); 1115 test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags));
1116 rt2x00_set_field32(&word, TXD_W0_IFS, txdesc->ifs); 1116 rt2x00_set_field32(&word, TXD_W0_IFS, txdesc->ifs);
1117 rt2x00_set_field32(&word, TXD_W0_DATABYTE_COUNT, 1117 rt2x00_set_field32(&word, TXD_W0_DATABYTE_COUNT, skb->len);
1118 skb->len - skbdesc->desc_len);
1119 rt2x00_set_field32(&word, TXD_W0_CIPHER, CIPHER_NONE); 1118 rt2x00_set_field32(&word, TXD_W0_CIPHER, CIPHER_NONE);
1120 rt2x00_desc_write(txd, 0, word); 1119 rt2x00_desc_write(txd, 0, word);
1121} 1120}
@@ -1134,7 +1133,6 @@ static void rt2500usb_write_beacon(struct queue_entry *entry)
1134 int pipe = usb_sndbulkpipe(usb_dev, 1); 1133 int pipe = usb_sndbulkpipe(usb_dev, 1);
1135 int length; 1134 int length;
1136 u16 reg; 1135 u16 reg;
1137 u32 word, len;
1138 1136
1139 /* 1137 /*
1140 * Add the descriptor in front of the skb. 1138 * Add the descriptor in front of the skb.
@@ -1144,17 +1142,6 @@ static void rt2500usb_write_beacon(struct queue_entry *entry)
1144 skbdesc->desc = entry->skb->data; 1142 skbdesc->desc = entry->skb->data;
1145 1143
1146 /* 1144 /*
1147 * Adjust the beacon databyte count. The current number is
1148 * calculated before this function gets called, but falsely
1149 * assumes that the descriptor was already present in the SKB.
1150 */
1151 rt2x00_desc_read(skbdesc->desc, 0, &word);
1152 len = rt2x00_get_field32(word, TXD_W0_DATABYTE_COUNT);
1153 len += skbdesc->desc_len;
1154 rt2x00_set_field32(&word, TXD_W0_DATABYTE_COUNT, len);
1155 rt2x00_desc_write(skbdesc->desc, 0, word);
1156
1157 /*
1158 * Disable beaconing while we are reloading the beacon data, 1145 * Disable beaconing while we are reloading the beacon data,
1159 * otherwise we might be sending out invalid data. 1146 * otherwise we might be sending out invalid data.
1160 */ 1147 */
@@ -1280,6 +1267,8 @@ static void rt2500usb_fill_rxdone(struct queue_entry *entry,
1280 1267
1281 if (rt2x00_get_field32(word0, RXD_W0_OFDM)) 1268 if (rt2x00_get_field32(word0, RXD_W0_OFDM))
1282 rxdesc->dev_flags |= RXDONE_SIGNAL_PLCP; 1269 rxdesc->dev_flags |= RXDONE_SIGNAL_PLCP;
1270 else
1271 rxdesc->dev_flags |= RXDONE_SIGNAL_BITRATE;
1283 if (rt2x00_get_field32(word0, RXD_W0_MY_BSS)) 1272 if (rt2x00_get_field32(word0, RXD_W0_MY_BSS))
1284 rxdesc->dev_flags |= RXDONE_MY_BSS; 1273 rxdesc->dev_flags |= RXDONE_MY_BSS;
1285 1274
@@ -1297,7 +1286,7 @@ static void rt2500usb_beacondone(struct urb *urb)
1297 struct queue_entry *entry = (struct queue_entry *)urb->context; 1286 struct queue_entry *entry = (struct queue_entry *)urb->context;
1298 struct queue_entry_priv_usb_bcn *bcn_priv = entry->priv_data; 1287 struct queue_entry_priv_usb_bcn *bcn_priv = entry->priv_data;
1299 1288
1300 if (!test_bit(DEVICE_ENABLED_RADIO, &entry->queue->rt2x00dev->flags)) 1289 if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &entry->queue->rt2x00dev->flags))
1301 return; 1290 return;
1302 1291
1303 /* 1292 /*
@@ -1484,14 +1473,14 @@ static int rt2500usb_init_eeprom(struct rt2x00_dev *rt2x00dev)
1484 /* 1473 /*
1485 * Store led mode, for correct led behaviour. 1474 * Store led mode, for correct led behaviour.
1486 */ 1475 */
1487#ifdef CONFIG_RT2500USB_LEDS 1476#ifdef CONFIG_RT2X00_LIB_LEDS
1488 value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_LED_MODE); 1477 value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_LED_MODE);
1489 1478
1490 rt2500usb_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO); 1479 rt2500usb_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO);
1491 if (value == LED_MODE_TXRX_ACTIVITY) 1480 if (value == LED_MODE_TXRX_ACTIVITY)
1492 rt2500usb_init_led(rt2x00dev, &rt2x00dev->led_qual, 1481 rt2500usb_init_led(rt2x00dev, &rt2x00dev->led_qual,
1493 LED_TYPE_ACTIVITY); 1482 LED_TYPE_ACTIVITY);
1494#endif /* CONFIG_RT2500USB_LEDS */ 1483#endif /* CONFIG_RT2X00_LIB_LEDS */
1495 1484
1496 /* 1485 /*
1497 * Check if the BBP tuning should be disabled. 1486 * Check if the BBP tuning should be disabled.
@@ -1665,10 +1654,11 @@ static const struct rf_channel rf_vals_5222[] = {
1665 { 161, 0x00022020, 0x000090be, 0x00000101, 0x00000a07 }, 1654 { 161, 0x00022020, 0x000090be, 0x00000101, 0x00000a07 },
1666}; 1655};
1667 1656
1668static void rt2500usb_probe_hw_mode(struct rt2x00_dev *rt2x00dev) 1657static int rt2500usb_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
1669{ 1658{
1670 struct hw_mode_spec *spec = &rt2x00dev->spec; 1659 struct hw_mode_spec *spec = &rt2x00dev->spec;
1671 u8 *txpower; 1660 struct channel_info *info;
1661 char *tx_power;
1672 unsigned int i; 1662 unsigned int i;
1673 1663
1674 /* 1664 /*
@@ -1687,20 +1677,10 @@ static void rt2500usb_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
1687 EEPROM_MAC_ADDR_0)); 1677 EEPROM_MAC_ADDR_0));
1688 1678
1689 /* 1679 /*
1690 * Convert tx_power array in eeprom.
1691 */
1692 txpower = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_START);
1693 for (i = 0; i < 14; i++)
1694 txpower[i] = TXPOWER_FROM_DEV(txpower[i]);
1695
1696 /*
1697 * Initialize hw_mode information. 1680 * Initialize hw_mode information.
1698 */ 1681 */
1699 spec->supported_bands = SUPPORT_BAND_2GHZ; 1682 spec->supported_bands = SUPPORT_BAND_2GHZ;
1700 spec->supported_rates = SUPPORT_RATE_CCK | SUPPORT_RATE_OFDM; 1683 spec->supported_rates = SUPPORT_RATE_CCK | SUPPORT_RATE_OFDM;
1701 spec->tx_power_a = NULL;
1702 spec->tx_power_bg = txpower;
1703 spec->tx_power_default = DEFAULT_TXPOWER;
1704 1684
1705 if (rt2x00_rf(&rt2x00dev->chip, RF2522)) { 1685 if (rt2x00_rf(&rt2x00dev->chip, RF2522)) {
1706 spec->num_channels = ARRAY_SIZE(rf_vals_bg_2522); 1686 spec->num_channels = ARRAY_SIZE(rf_vals_bg_2522);
@@ -1722,6 +1702,26 @@ static void rt2500usb_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
1722 spec->num_channels = ARRAY_SIZE(rf_vals_5222); 1702 spec->num_channels = ARRAY_SIZE(rf_vals_5222);
1723 spec->channels = rf_vals_5222; 1703 spec->channels = rf_vals_5222;
1724 } 1704 }
1705
1706 /*
1707 * Create channel information array
1708 */
1709 info = kzalloc(spec->num_channels * sizeof(*info), GFP_KERNEL);
1710 if (!info)
1711 return -ENOMEM;
1712
1713 spec->channels_info = info;
1714
1715 tx_power = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_START);
1716 for (i = 0; i < 14; i++)
1717 info[i].tx_power1 = TXPOWER_FROM_DEV(tx_power[i]);
1718
1719 if (spec->num_channels > 14) {
1720 for (i = 14; i < spec->num_channels; i++)
1721 info[i].tx_power1 = DEFAULT_TXPOWER;
1722 }
1723
1724 return 0;
1725} 1725}
1726 1726
1727static int rt2500usb_probe_hw(struct rt2x00_dev *rt2x00dev) 1727static int rt2500usb_probe_hw(struct rt2x00_dev *rt2x00dev)
@@ -1742,7 +1742,9 @@ static int rt2500usb_probe_hw(struct rt2x00_dev *rt2x00dev)
1742 /* 1742 /*
1743 * Initialize hw specifications. 1743 * Initialize hw specifications.
1744 */ 1744 */
1745 rt2500usb_probe_hw_mode(rt2x00dev); 1745 retval = rt2500usb_probe_hw_mode(rt2x00dev);
1746 if (retval)
1747 return retval;
1746 1748
1747 /* 1749 /*
1748 * This device requires the atim queue 1750 * This device requires the atim queue
diff --git a/drivers/net/wireless/rt2x00/rt2500usb.h b/drivers/net/wireless/rt2x00/rt2500usb.h
index 4769ffeb4cc6..89e5ed24e4f7 100644
--- a/drivers/net/wireless/rt2x00/rt2500usb.h
+++ b/drivers/net/wireless/rt2x00/rt2500usb.h
@@ -825,17 +825,10 @@
825#define MAX_TXPOWER 31 825#define MAX_TXPOWER 31
826#define DEFAULT_TXPOWER 24 826#define DEFAULT_TXPOWER 24
827 827
828#define TXPOWER_FROM_DEV(__txpower) \ 828#define TXPOWER_FROM_DEV(__txpower) \
829({ \ 829 (((u8)(__txpower)) > MAX_TXPOWER) ? DEFAULT_TXPOWER : (__txpower)
830 ((__txpower) > MAX_TXPOWER) ? \ 830
831 DEFAULT_TXPOWER : (__txpower); \ 831#define TXPOWER_TO_DEV(__txpower) \
832}) 832 clamp_t(char, __txpower, MIN_TXPOWER, MAX_TXPOWER)
833
834#define TXPOWER_TO_DEV(__txpower) \
835({ \
836 ((__txpower) <= MIN_TXPOWER) ? MIN_TXPOWER : \
837 (((__txpower) >= MAX_TXPOWER) ? MAX_TXPOWER : \
838 (__txpower)); \
839})
840 833
841#endif /* RT2500USB_H */ 834#endif /* RT2500USB_H */
diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
index 8b10ea41b204..1359a3768404 100644
--- a/drivers/net/wireless/rt2x00/rt2x00.h
+++ b/drivers/net/wireless/rt2x00/rt2x00.h
@@ -44,7 +44,7 @@
44/* 44/*
45 * Module information. 45 * Module information.
46 */ 46 */
47#define DRV_VERSION "2.1.8" 47#define DRV_VERSION "2.2.1"
48#define DRV_PROJECT "http://rt2x00.serialmonkey.com" 48#define DRV_PROJECT "http://rt2x00.serialmonkey.com"
49 49
50/* 50/*
@@ -53,11 +53,11 @@
53 */ 53 */
54#define DEBUG_PRINTK_MSG(__dev, __kernlvl, __lvl, __msg, __args...) \ 54#define DEBUG_PRINTK_MSG(__dev, __kernlvl, __lvl, __msg, __args...) \
55 printk(__kernlvl "%s -> %s: %s - " __msg, \ 55 printk(__kernlvl "%s -> %s: %s - " __msg, \
56 wiphy_name((__dev)->hw->wiphy), __FUNCTION__, __lvl, ##__args) 56 wiphy_name((__dev)->hw->wiphy), __func__, __lvl, ##__args)
57 57
58#define DEBUG_PRINTK_PROBE(__kernlvl, __lvl, __msg, __args...) \ 58#define DEBUG_PRINTK_PROBE(__kernlvl, __lvl, __msg, __args...) \
59 printk(__kernlvl "%s -> %s: %s - " __msg, \ 59 printk(__kernlvl "%s -> %s: %s - " __msg, \
60 KBUILD_MODNAME, __FUNCTION__, __lvl, ##__args) 60 KBUILD_MODNAME, __func__, __lvl, ##__args)
61 61
62#ifdef CONFIG_RT2X00_DEBUG 62#ifdef CONFIG_RT2X00_DEBUG
63#define DEBUG_PRINTK(__dev, __kernlvl, __lvl, __msg, __args...) \ 63#define DEBUG_PRINTK(__dev, __kernlvl, __lvl, __msg, __args...) \
@@ -144,6 +144,17 @@ struct rf_channel {
144}; 144};
145 145
146/* 146/*
147 * Channel information structure
148 */
149struct channel_info {
150 unsigned int flags;
151#define GEOGRAPHY_ALLOWED 0x00000001
152
153 short tx_power1;
154 short tx_power2;
155};
156
157/*
147 * Antenna setup values. 158 * Antenna setup values.
148 */ 159 */
149struct antenna_setup { 160struct antenna_setup {
@@ -394,10 +405,7 @@ static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
394 * @num_channels: Number of supported channels. This is used as array size 405 * @num_channels: Number of supported channels. This is used as array size
395 * for @tx_power_a, @tx_power_bg and @channels. 406 * for @tx_power_a, @tx_power_bg and @channels.
396 * @channels: Device/chipset specific channel values (See &struct rf_channel). 407 * @channels: Device/chipset specific channel values (See &struct rf_channel).
397 * @tx_power_a: TX power values for all 5.2GHz channels (may be NULL). 408 * @channels_info: Additional information for channels (See &struct channel_info).
398 * @tx_power_bg: TX power values for all 2.4GHz channels (may be NULL).
399 * @tx_power_default: Default TX power value to use when either
400 * @tx_power_a or @tx_power_bg is missing.
401 */ 409 */
402struct hw_mode_spec { 410struct hw_mode_spec {
403 unsigned int supported_bands; 411 unsigned int supported_bands;
@@ -410,10 +418,7 @@ struct hw_mode_spec {
410 418
411 unsigned int num_channels; 419 unsigned int num_channels;
412 const struct rf_channel *channels; 420 const struct rf_channel *channels;
413 421 const struct channel_info *channels_info;
414 const u8 *tx_power_a;
415 const u8 *tx_power_bg;
416 u8 tx_power_default;
417}; 422};
418 423
419/* 424/*
@@ -425,7 +430,9 @@ struct hw_mode_spec {
425 */ 430 */
426struct rt2x00lib_conf { 431struct rt2x00lib_conf {
427 struct ieee80211_conf *conf; 432 struct ieee80211_conf *conf;
433
428 struct rf_channel rf; 434 struct rf_channel rf;
435 struct channel_info channel;
429 436
430 struct antenna_setup ant; 437 struct antenna_setup ant;
431 438
@@ -452,6 +459,23 @@ struct rt2x00lib_erp {
452}; 459};
453 460
454/* 461/*
462 * Configuration structure for hardware encryption.
463 */
464struct rt2x00lib_crypto {
465 enum cipher cipher;
466
467 enum set_key_cmd cmd;
468 const u8 *address;
469
470 u32 bssidx;
471 u32 aid;
472
473 u8 key[16];
474 u8 tx_mic[8];
475 u8 rx_mic[8];
476};
477
478/*
455 * Configuration structure wrapper around the 479 * Configuration structure wrapper around the
456 * rt2x00 interface configuration handler. 480 * rt2x00 interface configuration handler.
457 */ 481 */
@@ -459,7 +483,7 @@ struct rt2x00intf_conf {
459 /* 483 /*
460 * Interface type 484 * Interface type
461 */ 485 */
462 enum ieee80211_if_types type; 486 enum nl80211_iftype type;
463 487
464 /* 488 /*
465 * TSF sync value, this is dependant on the operation type. 489 * TSF sync value, this is dependant on the operation type.
@@ -547,6 +571,12 @@ struct rt2x00lib_ops {
547 /* 571 /*
548 * Configuration handlers. 572 * Configuration handlers.
549 */ 573 */
574 int (*config_shared_key) (struct rt2x00_dev *rt2x00dev,
575 struct rt2x00lib_crypto *crypto,
576 struct ieee80211_key_conf *key);
577 int (*config_pairwise_key) (struct rt2x00_dev *rt2x00dev,
578 struct rt2x00lib_crypto *crypto,
579 struct ieee80211_key_conf *key);
550 void (*config_filter) (struct rt2x00_dev *rt2x00dev, 580 void (*config_filter) (struct rt2x00_dev *rt2x00dev,
551 const unsigned int filter_flags); 581 const unsigned int filter_flags);
552 void (*config_intf) (struct rt2x00_dev *rt2x00dev, 582 void (*config_intf) (struct rt2x00_dev *rt2x00dev,
@@ -599,17 +629,16 @@ enum rt2x00_flags {
599 /* 629 /*
600 * Device state flags 630 * Device state flags
601 */ 631 */
602 DEVICE_PRESENT, 632 DEVICE_STATE_PRESENT,
603 DEVICE_REGISTERED_HW, 633 DEVICE_STATE_REGISTERED_HW,
604 DEVICE_INITIALIZED, 634 DEVICE_STATE_INITIALIZED,
605 DEVICE_STARTED, 635 DEVICE_STATE_STARTED,
606 DEVICE_STARTED_SUSPEND, 636 DEVICE_STATE_STARTED_SUSPEND,
607 DEVICE_ENABLED_RADIO, 637 DEVICE_STATE_ENABLED_RADIO,
608 DEVICE_DISABLED_RADIO_HW, 638 DEVICE_STATE_DISABLED_RADIO_HW,
609 DEVICE_DIRTY_CONFIG,
610 639
611 /* 640 /*
612 * Driver features 641 * Driver requirements
613 */ 642 */
614 DRIVER_REQUIRE_FIRMWARE, 643 DRIVER_REQUIRE_FIRMWARE,
615 DRIVER_REQUIRE_BEACON_GUARD, 644 DRIVER_REQUIRE_BEACON_GUARD,
@@ -618,9 +647,14 @@ enum rt2x00_flags {
618 DRIVER_REQUIRE_DMA, 647 DRIVER_REQUIRE_DMA,
619 648
620 /* 649 /*
621 * Driver configuration 650 * Driver features
622 */ 651 */
623 CONFIG_SUPPORT_HW_BUTTON, 652 CONFIG_SUPPORT_HW_BUTTON,
653 CONFIG_SUPPORT_HW_CRYPTO,
654
655 /*
656 * Driver configuration
657 */
624 CONFIG_FRAME_TYPE, 658 CONFIG_FRAME_TYPE,
625 CONFIG_RF_SEQUENCE, 659 CONFIG_RF_SEQUENCE,
626 CONFIG_EXTERNAL_LNA_A, 660 CONFIG_EXTERNAL_LNA_A,
@@ -769,6 +803,11 @@ struct rt2x00_dev {
769 u32 *rf; 803 u32 *rf;
770 804
771 /* 805 /*
806 * LNA gain
807 */
808 short lna_gain;
809
810 /*
772 * USB Max frame size (for rt2500usb & rt73usb). 811 * USB Max frame size (for rt2500usb & rt73usb).
773 */ 812 */
774 u16 usb_maxpacket; 813 u16 usb_maxpacket;
@@ -966,6 +1005,13 @@ void rt2x00mac_configure_filter(struct ieee80211_hw *hw,
966 unsigned int changed_flags, 1005 unsigned int changed_flags,
967 unsigned int *total_flags, 1006 unsigned int *total_flags,
968 int mc_count, struct dev_addr_list *mc_list); 1007 int mc_count, struct dev_addr_list *mc_list);
1008#ifdef CONFIG_RT2X00_LIB_CRYPTO
1009int rt2x00mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
1010 const u8 *local_address, const u8 *address,
1011 struct ieee80211_key_conf *key);
1012#else
1013#define rt2x00mac_set_key NULL
1014#endif /* CONFIG_RT2X00_LIB_CRYPTO */
969int rt2x00mac_get_stats(struct ieee80211_hw *hw, 1015int rt2x00mac_get_stats(struct ieee80211_hw *hw,
970 struct ieee80211_low_level_stats *stats); 1016 struct ieee80211_low_level_stats *stats);
971int rt2x00mac_get_tx_stats(struct ieee80211_hw *hw, 1017int rt2x00mac_get_tx_stats(struct ieee80211_hw *hw,
diff --git a/drivers/net/wireless/rt2x00/rt2x00config.c b/drivers/net/wireless/rt2x00/rt2x00config.c
index d134c3be539a..4d5e87b015a0 100644
--- a/drivers/net/wireless/rt2x00/rt2x00config.c
+++ b/drivers/net/wireless/rt2x00/rt2x00config.c
@@ -31,7 +31,7 @@
31 31
32void rt2x00lib_config_intf(struct rt2x00_dev *rt2x00dev, 32void rt2x00lib_config_intf(struct rt2x00_dev *rt2x00dev,
33 struct rt2x00_intf *intf, 33 struct rt2x00_intf *intf,
34 enum ieee80211_if_types type, 34 enum nl80211_iftype type,
35 u8 *mac, u8 *bssid) 35 u8 *mac, u8 *bssid)
36{ 36{
37 struct rt2x00intf_conf conf; 37 struct rt2x00intf_conf conf;
@@ -40,11 +40,11 @@ void rt2x00lib_config_intf(struct rt2x00_dev *rt2x00dev,
40 conf.type = type; 40 conf.type = type;
41 41
42 switch (type) { 42 switch (type) {
43 case IEEE80211_IF_TYPE_IBSS: 43 case NL80211_IFTYPE_ADHOC:
44 case IEEE80211_IF_TYPE_AP: 44 case NL80211_IFTYPE_AP:
45 conf.sync = TSF_SYNC_BEACON; 45 conf.sync = TSF_SYNC_BEACON;
46 break; 46 break;
47 case IEEE80211_IF_TYPE_STA: 47 case NL80211_IFTYPE_STATION:
48 conf.sync = TSF_SYNC_INFRA; 48 conf.sync = TSF_SYNC_INFRA;
49 break; 49 break;
50 default: 50 default:
@@ -121,7 +121,7 @@ void rt2x00lib_config_antenna(struct rt2x00_dev *rt2x00dev,
121 * Antenna setup changes require the RX to be disabled, 121 * Antenna setup changes require the RX to be disabled,
122 * else the changes will be ignored by the device. 122 * else the changes will be ignored by the device.
123 */ 123 */
124 if (test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags)) 124 if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
125 rt2x00lib_toggle_rx(rt2x00dev, STATE_RADIO_RX_OFF_LINK); 125 rt2x00lib_toggle_rx(rt2x00dev, STATE_RADIO_RX_OFF_LINK);
126 126
127 /* 127 /*
@@ -136,7 +136,7 @@ void rt2x00lib_config_antenna(struct rt2x00_dev *rt2x00dev,
136 rt2x00dev->link.ant.active.rx = libconf.ant.rx; 136 rt2x00dev->link.ant.active.rx = libconf.ant.rx;
137 rt2x00dev->link.ant.active.tx = libconf.ant.tx; 137 rt2x00dev->link.ant.active.tx = libconf.ant.tx;
138 138
139 if (test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags)) 139 if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
140 rt2x00lib_toggle_rx(rt2x00dev, STATE_RADIO_RX_ON_LINK); 140 rt2x00lib_toggle_rx(rt2x00dev, STATE_RADIO_RX_ON_LINK);
141} 141}
142 142
@@ -245,6 +245,10 @@ config:
245 memcpy(&libconf.rf, 245 memcpy(&libconf.rf,
246 &rt2x00dev->spec.channels[conf->channel->hw_value], 246 &rt2x00dev->spec.channels[conf->channel->hw_value],
247 sizeof(libconf.rf)); 247 sizeof(libconf.rf));
248
249 memcpy(&libconf.channel,
250 &rt2x00dev->spec.channels_info[conf->channel->hw_value],
251 sizeof(libconf.channel));
248 } 252 }
249 253
250 if (flags & CONFIG_UPDATE_ANTENNA) { 254 if (flags & CONFIG_UPDATE_ANTENNA) {
diff --git a/drivers/net/wireless/rt2x00/rt2x00crypto.c b/drivers/net/wireless/rt2x00/rt2x00crypto.c
new file mode 100644
index 000000000000..5a858e5106c4
--- /dev/null
+++ b/drivers/net/wireless/rt2x00/rt2x00crypto.c
@@ -0,0 +1,215 @@
1/*
2 Copyright (C) 2004 - 2008 rt2x00 SourceForge Project
3 <http://rt2x00.serialmonkey.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the
17 Free Software Foundation, Inc.,
18 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21/*
22 Module: rt2x00lib
23 Abstract: rt2x00 crypto specific routines.
24 */
25
26#include <linux/kernel.h>
27#include <linux/module.h>
28
29#include "rt2x00.h"
30#include "rt2x00lib.h"
31
32enum cipher rt2x00crypto_key_to_cipher(struct ieee80211_key_conf *key)
33{
34 switch (key->alg) {
35 case ALG_WEP:
36 if (key->keylen == LEN_WEP40)
37 return CIPHER_WEP64;
38 else
39 return CIPHER_WEP128;
40 case ALG_TKIP:
41 return CIPHER_TKIP;
42 case ALG_CCMP:
43 return CIPHER_AES;
44 default:
45 return CIPHER_NONE;
46 }
47}
48
49unsigned int rt2x00crypto_tx_overhead(struct ieee80211_tx_info *tx_info)
50{
51 struct ieee80211_key_conf *key = tx_info->control.hw_key;
52 unsigned int overhead = 0;
53
54 /*
55 * Extend frame length to include IV/EIV/ICV/MMIC,
56 * note that these lengths should only be added when
57 * mac80211 does not generate it.
58 */
59 overhead += key->icv_len;
60
61 if (!(key->flags & IEEE80211_KEY_FLAG_GENERATE_IV))
62 overhead += key->iv_len;
63
64 if (!(key->flags & IEEE80211_KEY_FLAG_GENERATE_MMIC)) {
65 if (key->alg == ALG_TKIP)
66 overhead += 8;
67 }
68
69 return overhead;
70}
71
72void rt2x00crypto_tx_remove_iv(struct sk_buff *skb, unsigned int iv_len)
73{
74 struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb);
75 unsigned int header_length = ieee80211_get_hdrlen_from_skb(skb);
76
77 if (unlikely(!iv_len))
78 return;
79
80 /* Copy IV/EIV data */
81 if (iv_len >= 4)
82 memcpy(&skbdesc->iv, skb->data + header_length, 4);
83 if (iv_len >= 8)
84 memcpy(&skbdesc->eiv, skb->data + header_length + 4, 4);
85
86 /* Move ieee80211 header */
87 memmove(skb->data + iv_len, skb->data, header_length);
88
89 /* Pull buffer to correct size */
90 skb_pull(skb, iv_len);
91
92 /* IV/EIV data has officially be stripped */
93 skbdesc->flags |= FRAME_DESC_IV_STRIPPED;
94}
95
96void rt2x00crypto_tx_insert_iv(struct sk_buff *skb)
97{
98 struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb);
99 unsigned int header_length = ieee80211_get_hdrlen_from_skb(skb);
100 const unsigned int iv_len =
101 ((!!(skbdesc->iv)) * 4) + ((!!(skbdesc->eiv)) * 4);
102
103 if (!(skbdesc->flags & FRAME_DESC_IV_STRIPPED))
104 return;
105
106 skb_push(skb, iv_len);
107
108 /* Move ieee80211 header */
109 memmove(skb->data, skb->data + iv_len, header_length);
110
111 /* Copy IV/EIV data */
112 if (iv_len >= 4)
113 memcpy(skb->data + header_length, &skbdesc->iv, 4);
114 if (iv_len >= 8)
115 memcpy(skb->data + header_length + 4, &skbdesc->eiv, 4);
116
117 /* IV/EIV data has returned into the frame */
118 skbdesc->flags &= ~FRAME_DESC_IV_STRIPPED;
119}
120
121void rt2x00crypto_rx_insert_iv(struct sk_buff *skb, unsigned int align,
122 unsigned int header_length,
123 struct rxdone_entry_desc *rxdesc)
124{
125 unsigned int payload_len = rxdesc->size - header_length;
126 unsigned int iv_len;
127 unsigned int icv_len;
128 unsigned int transfer = 0;
129
130 /*
131 * WEP64/WEP128: Provides IV & ICV
132 * TKIP: Provides IV/EIV & ICV
133 * AES: Provies IV/EIV & ICV
134 */
135 switch (rxdesc->cipher) {
136 case CIPHER_WEP64:
137 case CIPHER_WEP128:
138 iv_len = 4;
139 icv_len = 4;
140 break;
141 case CIPHER_TKIP:
142 iv_len = 8;
143 icv_len = 4;
144 break;
145 case CIPHER_AES:
146 iv_len = 8;
147 icv_len = 8;
148 break;
149 default:
150 /* Unsupport type */
151 return;
152 }
153
154 /*
155 * Make room for new data, note that we increase both
156 * headsize and tailsize when required. The tailsize is
157 * only needed when ICV data needs to be inserted and
158 * the padding is smaller then the ICV data.
159 * When alignment requirements is greater then the
160 * ICV data we must trim the skb to the correct size
161 * because we need to remove the extra bytes.
162 */
163 skb_push(skb, iv_len + align);
164 if (align < icv_len)
165 skb_put(skb, icv_len - align);
166 else if (align > icv_len)
167 skb_trim(skb, rxdesc->size + iv_len + icv_len);
168
169 /* Move ieee80211 header */
170 memmove(skb->data + transfer,
171 skb->data + transfer + iv_len + align,
172 header_length);
173 transfer += header_length;
174
175 /* Copy IV data */
176 if (iv_len >= 4) {
177 memcpy(skb->data + transfer, &rxdesc->iv, 4);
178 transfer += 4;
179 }
180
181 /* Copy EIV data */
182 if (iv_len >= 8) {
183 memcpy(skb->data + transfer, &rxdesc->eiv, 4);
184 transfer += 4;
185 }
186
187 /* Move payload */
188 if (align) {
189 memmove(skb->data + transfer,
190 skb->data + transfer + align,
191 payload_len);
192 }
193
194 /*
195 * NOTE: Always count the payload as transfered,
196 * even when alignment was set to zero. This is required
197 * for determining the correct offset for the ICV data.
198 */
199 transfer += payload_len;
200
201 /* Copy ICV data */
202 if (icv_len >= 4) {
203 memcpy(skb->data + transfer, &rxdesc->icv, 4);
204 /*
205 * AES appends 8 bytes, we can't fill the upper
206 * 4 bytes, but mac80211 doesn't care about what
207 * we provide here anyway and strips it immediately.
208 */
209 transfer += icv_len;
210 }
211
212 /* IV/EIV/ICV has been inserted into frame */
213 rxdesc->size = transfer;
214 rxdesc->flags &= ~RX_FLAG_IV_STRIPPED;
215}
diff --git a/drivers/net/wireless/rt2x00/rt2x00debug.c b/drivers/net/wireless/rt2x00/rt2x00debug.c
index 6bee1d611bbf..5cf4c859e39d 100644
--- a/drivers/net/wireless/rt2x00/rt2x00debug.c
+++ b/drivers/net/wireless/rt2x00/rt2x00debug.c
@@ -35,6 +35,13 @@
35 35
36#define MAX_LINE_LENGTH 64 36#define MAX_LINE_LENGTH 64
37 37
38struct rt2x00debug_crypto {
39 unsigned long success;
40 unsigned long icv_error;
41 unsigned long mic_error;
42 unsigned long key_error;
43};
44
38struct rt2x00debug_intf { 45struct rt2x00debug_intf {
39 /* 46 /*
40 * Pointer to driver structure where 47 * Pointer to driver structure where
@@ -63,6 +70,7 @@ struct rt2x00debug_intf {
63 * - queue folder 70 * - queue folder
64 * - frame dump file 71 * - frame dump file
65 * - queue stats file 72 * - queue stats file
73 * - crypto stats file
66 */ 74 */
67 struct dentry *driver_folder; 75 struct dentry *driver_folder;
68 struct dentry *driver_entry; 76 struct dentry *driver_entry;
@@ -80,6 +88,7 @@ struct rt2x00debug_intf {
80 struct dentry *queue_folder; 88 struct dentry *queue_folder;
81 struct dentry *queue_frame_dump_entry; 89 struct dentry *queue_frame_dump_entry;
82 struct dentry *queue_stats_entry; 90 struct dentry *queue_stats_entry;
91 struct dentry *crypto_stats_entry;
83 92
84 /* 93 /*
85 * The frame dump file only allows a single reader, 94 * The frame dump file only allows a single reader,
@@ -98,6 +107,12 @@ struct rt2x00debug_intf {
98 wait_queue_head_t frame_dump_waitqueue; 107 wait_queue_head_t frame_dump_waitqueue;
99 108
100 /* 109 /*
110 * HW crypto statistics.
111 * All statistics are stored seperately per cipher type.
112 */
113 struct rt2x00debug_crypto crypto_stats[CIPHER_MAX];
114
115 /*
101 * Driver and chipset files will use a data buffer 116 * Driver and chipset files will use a data buffer
102 * that has been created in advance. This will simplify 117 * that has been created in advance. This will simplify
103 * the code since we can use the debugfs functions. 118 * the code since we can use the debugfs functions.
@@ -114,6 +129,25 @@ struct rt2x00debug_intf {
114 unsigned int offset_rf; 129 unsigned int offset_rf;
115}; 130};
116 131
132void rt2x00debug_update_crypto(struct rt2x00_dev *rt2x00dev,
133 enum cipher cipher, enum rx_crypto status)
134{
135 struct rt2x00debug_intf *intf = rt2x00dev->debugfs_intf;
136
137 if (cipher == CIPHER_TKIP_NO_MIC)
138 cipher = CIPHER_TKIP;
139 if (cipher == CIPHER_NONE || cipher > CIPHER_MAX)
140 return;
141
142 /* Remove CIPHER_NONE index */
143 cipher--;
144
145 intf->crypto_stats[cipher].success += (status == RX_CRYPTO_SUCCESS);
146 intf->crypto_stats[cipher].icv_error += (status == RX_CRYPTO_FAIL_ICV);
147 intf->crypto_stats[cipher].mic_error += (status == RX_CRYPTO_FAIL_MIC);
148 intf->crypto_stats[cipher].key_error += (status == RX_CRYPTO_FAIL_KEY);
149}
150
117void rt2x00debug_dump_frame(struct rt2x00_dev *rt2x00dev, 151void rt2x00debug_dump_frame(struct rt2x00_dev *rt2x00dev,
118 enum rt2x00_dump_type type, struct sk_buff *skb) 152 enum rt2x00_dump_type type, struct sk_buff *skb)
119{ 153{
@@ -327,6 +361,59 @@ static const struct file_operations rt2x00debug_fop_queue_stats = {
327 .release = rt2x00debug_file_release, 361 .release = rt2x00debug_file_release,
328}; 362};
329 363
364#ifdef CONFIG_RT2X00_LIB_CRYPTO
365static ssize_t rt2x00debug_read_crypto_stats(struct file *file,
366 char __user *buf,
367 size_t length,
368 loff_t *offset)
369{
370 struct rt2x00debug_intf *intf = file->private_data;
371 char *name[] = { "WEP64", "WEP128", "TKIP", "AES" };
372 char *data;
373 char *temp;
374 size_t size;
375 unsigned int i;
376
377 if (*offset)
378 return 0;
379
380 data = kzalloc((1 + CIPHER_MAX)* MAX_LINE_LENGTH, GFP_KERNEL);
381 if (!data)
382 return -ENOMEM;
383
384 temp = data;
385 temp += sprintf(data, "cipher\tsuccess\ticv err\tmic err\tkey err\n");
386
387 for (i = 0; i < CIPHER_MAX; i++) {
388 temp += sprintf(temp, "%s\t%lu\t%lu\t%lu\t%lu\n", name[i],
389 intf->crypto_stats[i].success,
390 intf->crypto_stats[i].icv_error,
391 intf->crypto_stats[i].mic_error,
392 intf->crypto_stats[i].key_error);
393 }
394
395 size = strlen(data);
396 size = min(size, length);
397
398 if (copy_to_user(buf, data, size)) {
399 kfree(data);
400 return -EFAULT;
401 }
402
403 kfree(data);
404
405 *offset += size;
406 return size;
407}
408
409static const struct file_operations rt2x00debug_fop_crypto_stats = {
410 .owner = THIS_MODULE,
411 .read = rt2x00debug_read_crypto_stats,
412 .open = rt2x00debug_file_open,
413 .release = rt2x00debug_file_release,
414};
415#endif
416
330#define RT2X00DEBUGFS_OPS_READ(__name, __format, __type) \ 417#define RT2X00DEBUGFS_OPS_READ(__name, __format, __type) \
331static ssize_t rt2x00debug_read_##__name(struct file *file, \ 418static ssize_t rt2x00debug_read_##__name(struct file *file, \
332 char __user *buf, \ 419 char __user *buf, \
@@ -569,6 +656,13 @@ void rt2x00debug_register(struct rt2x00_dev *rt2x00dev)
569 debugfs_create_file("queue", S_IRUSR, intf->queue_folder, 656 debugfs_create_file("queue", S_IRUSR, intf->queue_folder,
570 intf, &rt2x00debug_fop_queue_stats); 657 intf, &rt2x00debug_fop_queue_stats);
571 658
659#ifdef CONFIG_RT2X00_LIB_CRYPTO
660 if (test_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags))
661 intf->crypto_stats_entry =
662 debugfs_create_file("crypto", S_IRUGO, intf->queue_folder,
663 intf, &rt2x00debug_fop_crypto_stats);
664#endif
665
572 return; 666 return;
573 667
574exit: 668exit:
@@ -587,6 +681,9 @@ void rt2x00debug_deregister(struct rt2x00_dev *rt2x00dev)
587 681
588 skb_queue_purge(&intf->frame_dump_skbqueue); 682 skb_queue_purge(&intf->frame_dump_skbqueue);
589 683
684#ifdef CONFIG_RT2X00_LIB_CRYPTO
685 debugfs_remove(intf->crypto_stats_entry);
686#endif
590 debugfs_remove(intf->queue_stats_entry); 687 debugfs_remove(intf->queue_stats_entry);
591 debugfs_remove(intf->queue_frame_dump_entry); 688 debugfs_remove(intf->queue_frame_dump_entry);
592 debugfs_remove(intf->queue_folder); 689 debugfs_remove(intf->queue_folder);
diff --git a/drivers/net/wireless/rt2x00/rt2x00dev.c b/drivers/net/wireless/rt2x00/rt2x00dev.c
index f42283ad7b02..86840e3585e8 100644
--- a/drivers/net/wireless/rt2x00/rt2x00dev.c
+++ b/drivers/net/wireless/rt2x00/rt2x00dev.c
@@ -34,7 +34,7 @@
34 */ 34 */
35void rt2x00lib_reset_link_tuner(struct rt2x00_dev *rt2x00dev) 35void rt2x00lib_reset_link_tuner(struct rt2x00_dev *rt2x00dev)
36{ 36{
37 if (!test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags)) 37 if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
38 return; 38 return;
39 39
40 /* 40 /*
@@ -94,8 +94,8 @@ int rt2x00lib_enable_radio(struct rt2x00_dev *rt2x00dev)
94 * Don't enable the radio twice. 94 * Don't enable the radio twice.
95 * And check if the hardware button has been disabled. 95 * And check if the hardware button has been disabled.
96 */ 96 */
97 if (test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags) || 97 if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags) ||
98 test_bit(DEVICE_DISABLED_RADIO_HW, &rt2x00dev->flags)) 98 test_bit(DEVICE_STATE_DISABLED_RADIO_HW, &rt2x00dev->flags))
99 return 0; 99 return 0;
100 100
101 /* 101 /*
@@ -117,7 +117,7 @@ int rt2x00lib_enable_radio(struct rt2x00_dev *rt2x00dev)
117 rt2x00leds_led_radio(rt2x00dev, true); 117 rt2x00leds_led_radio(rt2x00dev, true);
118 rt2x00led_led_activity(rt2x00dev, true); 118 rt2x00led_led_activity(rt2x00dev, true);
119 119
120 __set_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags); 120 set_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags);
121 121
122 /* 122 /*
123 * Enable RX. 123 * Enable RX.
@@ -134,7 +134,7 @@ int rt2x00lib_enable_radio(struct rt2x00_dev *rt2x00dev)
134 134
135void rt2x00lib_disable_radio(struct rt2x00_dev *rt2x00dev) 135void rt2x00lib_disable_radio(struct rt2x00_dev *rt2x00dev)
136{ 136{
137 if (!__test_and_clear_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags)) 137 if (!test_and_clear_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
138 return; 138 return;
139 139
140 /* 140 /*
@@ -354,7 +354,7 @@ static void rt2x00lib_link_tuner(struct work_struct *work)
354 * When the radio is shutting down we should 354 * When the radio is shutting down we should
355 * immediately cease all link tuning. 355 * immediately cease all link tuning.
356 */ 356 */
357 if (!test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags)) 357 if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
358 return; 358 return;
359 359
360 /* 360 /*
@@ -431,7 +431,7 @@ static void rt2x00lib_intf_scheduled_iter(void *data, u8 *mac,
431 * note that in the spinlock protected area above the delayed_flags 431 * note that in the spinlock protected area above the delayed_flags
432 * have been cleared correctly. 432 * have been cleared correctly.
433 */ 433 */
434 if (!test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags)) 434 if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
435 return; 435 return;
436 436
437 if (delayed_flags & DELAYED_UPDATE_BEACON) 437 if (delayed_flags & DELAYED_UPDATE_BEACON)
@@ -467,8 +467,8 @@ static void rt2x00lib_beacondone_iter(void *data, u8 *mac,
467 struct rt2x00_dev *rt2x00dev = data; 467 struct rt2x00_dev *rt2x00dev = data;
468 struct rt2x00_intf *intf = vif_to_intf(vif); 468 struct rt2x00_intf *intf = vif_to_intf(vif);
469 469
470 if (vif->type != IEEE80211_IF_TYPE_AP && 470 if (vif->type != NL80211_IFTYPE_AP &&
471 vif->type != IEEE80211_IF_TYPE_IBSS) 471 vif->type != NL80211_IFTYPE_ADHOC)
472 return; 472 return;
473 473
474 /* 474 /*
@@ -484,7 +484,7 @@ static void rt2x00lib_beacondone_iter(void *data, u8 *mac,
484 484
485void rt2x00lib_beacondone(struct rt2x00_dev *rt2x00dev) 485void rt2x00lib_beacondone(struct rt2x00_dev *rt2x00dev)
486{ 486{
487 if (!test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags)) 487 if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
488 return; 488 return;
489 489
490 ieee80211_iterate_active_interfaces_atomic(rt2x00dev->hw, 490 ieee80211_iterate_active_interfaces_atomic(rt2x00dev->hw,
@@ -508,6 +508,15 @@ void rt2x00lib_txdone(struct queue_entry *entry,
508 rt2x00queue_unmap_skb(rt2x00dev, entry->skb); 508 rt2x00queue_unmap_skb(rt2x00dev, entry->skb);
509 509
510 /* 510 /*
511 * If the IV/EIV data was stripped from the frame before it was
512 * passed to the hardware, we should now reinsert it again because
513 * mac80211 will expect the the same data to be present it the
514 * frame as it was passed to us.
515 */
516 if (test_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags))
517 rt2x00crypto_tx_insert_iv(entry->skb);
518
519 /*
511 * Send frame to debugfs immediately, after this call is completed 520 * Send frame to debugfs immediately, after this call is completed
512 * we are going to overwrite the skb->cb array. 521 * we are going to overwrite the skb->cb array.
513 */ 522 */
@@ -563,7 +572,7 @@ void rt2x00lib_txdone(struct queue_entry *entry,
563 572
564 rt2x00dev->ops->lib->init_txentry(rt2x00dev, entry); 573 rt2x00dev->ops->lib->init_txentry(rt2x00dev, entry);
565 574
566 __clear_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags); 575 clear_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags);
567 rt2x00queue_index_inc(entry->queue, Q_INDEX_DONE); 576 rt2x00queue_index_inc(entry->queue, Q_INDEX_DONE);
568 577
569 /* 578 /*
@@ -585,7 +594,7 @@ void rt2x00lib_rxdone(struct rt2x00_dev *rt2x00dev,
585 struct ieee80211_supported_band *sband; 594 struct ieee80211_supported_band *sband;
586 struct ieee80211_hdr *hdr; 595 struct ieee80211_hdr *hdr;
587 const struct rt2x00_rate *rate; 596 const struct rt2x00_rate *rate;
588 unsigned int header_size; 597 unsigned int header_length;
589 unsigned int align; 598 unsigned int align;
590 unsigned int i; 599 unsigned int i;
591 int idx = -1; 600 int idx = -1;
@@ -613,10 +622,19 @@ void rt2x00lib_rxdone(struct rt2x00_dev *rt2x00dev,
613 * The data behind the ieee80211 header must be 622 * The data behind the ieee80211 header must be
614 * aligned on a 4 byte boundary. 623 * aligned on a 4 byte boundary.
615 */ 624 */
616 header_size = ieee80211_get_hdrlen_from_skb(entry->skb); 625 header_length = ieee80211_get_hdrlen_from_skb(entry->skb);
617 align = ((unsigned long)(entry->skb->data + header_size)) & 3; 626 align = ((unsigned long)(entry->skb->data + header_length)) & 3;
618 627
619 if (align) { 628 /*
629 * Hardware might have stripped the IV/EIV/ICV data,
630 * in that case it is possible that the data was
631 * provided seperately (through hardware descriptor)
632 * in which case we should reinsert the data into the frame.
633 */
634 if ((rxdesc.flags & RX_FLAG_IV_STRIPPED)) {
635 rt2x00crypto_rx_insert_iv(entry->skb, align,
636 header_length, &rxdesc);
637 } else if (align) {
620 skb_push(entry->skb, align); 638 skb_push(entry->skb, align);
621 /* Move entire frame in 1 command */ 639 /* Move entire frame in 1 command */
622 memmove(entry->skb->data, entry->skb->data + align, 640 memmove(entry->skb->data, entry->skb->data + align,
@@ -635,7 +653,7 @@ void rt2x00lib_rxdone(struct rt2x00_dev *rt2x00dev,
635 653
636 if (((rxdesc.dev_flags & RXDONE_SIGNAL_PLCP) && 654 if (((rxdesc.dev_flags & RXDONE_SIGNAL_PLCP) &&
637 (rate->plcp == rxdesc.signal)) || 655 (rate->plcp == rxdesc.signal)) ||
638 (!(rxdesc.dev_flags & RXDONE_SIGNAL_PLCP) && 656 ((rxdesc.dev_flags & RXDONE_SIGNAL_BITRATE) &&
639 (rate->bitrate == rxdesc.signal))) { 657 (rate->bitrate == rxdesc.signal))) {
640 idx = i; 658 idx = i;
641 break; 659 break;
@@ -657,6 +675,10 @@ void rt2x00lib_rxdone(struct rt2x00_dev *rt2x00dev,
657 (rxdesc.dev_flags & RXDONE_MY_BSS)) 675 (rxdesc.dev_flags & RXDONE_MY_BSS))
658 rt2x00lib_update_link_stats(&rt2x00dev->link, rxdesc.rssi); 676 rt2x00lib_update_link_stats(&rt2x00dev->link, rxdesc.rssi);
659 677
678 rt2x00debug_update_crypto(rt2x00dev,
679 rxdesc.cipher,
680 rxdesc.cipher_status);
681
660 rt2x00dev->link.qual.rx_success++; 682 rt2x00dev->link.qual.rx_success++;
661 683
662 rx_status->mactime = rxdesc.timestamp; 684 rx_status->mactime = rxdesc.timestamp;
@@ -796,7 +818,6 @@ static int rt2x00lib_probe_hw_modes(struct rt2x00_dev *rt2x00dev,
796 struct ieee80211_rate *rates; 818 struct ieee80211_rate *rates;
797 unsigned int num_rates; 819 unsigned int num_rates;
798 unsigned int i; 820 unsigned int i;
799 unsigned char tx_power;
800 821
801 num_rates = 0; 822 num_rates = 0;
802 if (spec->supported_rates & SUPPORT_RATE_CCK) 823 if (spec->supported_rates & SUPPORT_RATE_CCK)
@@ -822,20 +843,9 @@ static int rt2x00lib_probe_hw_modes(struct rt2x00_dev *rt2x00dev,
822 * Initialize Channel list. 843 * Initialize Channel list.
823 */ 844 */
824 for (i = 0; i < spec->num_channels; i++) { 845 for (i = 0; i < spec->num_channels; i++) {
825 if (spec->channels[i].channel <= 14) {
826 if (spec->tx_power_bg)
827 tx_power = spec->tx_power_bg[i];
828 else
829 tx_power = spec->tx_power_default;
830 } else {
831 if (spec->tx_power_a)
832 tx_power = spec->tx_power_a[i];
833 else
834 tx_power = spec->tx_power_default;
835 }
836
837 rt2x00lib_channel(&channels[i], 846 rt2x00lib_channel(&channels[i],
838 spec->channels[i].channel, tx_power, i); 847 spec->channels[i].channel,
848 spec->channels_info[i].tx_power1, i);
839 } 849 }
840 850
841 /* 851 /*
@@ -878,7 +888,7 @@ static int rt2x00lib_probe_hw_modes(struct rt2x00_dev *rt2x00dev,
878 888
879static void rt2x00lib_remove_hw(struct rt2x00_dev *rt2x00dev) 889static void rt2x00lib_remove_hw(struct rt2x00_dev *rt2x00dev)
880{ 890{
881 if (test_bit(DEVICE_REGISTERED_HW, &rt2x00dev->flags)) 891 if (test_bit(DEVICE_STATE_REGISTERED_HW, &rt2x00dev->flags))
882 ieee80211_unregister_hw(rt2x00dev->hw); 892 ieee80211_unregister_hw(rt2x00dev->hw);
883 893
884 if (likely(rt2x00dev->hw->wiphy->bands[IEEE80211_BAND_2GHZ])) { 894 if (likely(rt2x00dev->hw->wiphy->bands[IEEE80211_BAND_2GHZ])) {
@@ -887,6 +897,8 @@ static void rt2x00lib_remove_hw(struct rt2x00_dev *rt2x00dev)
887 rt2x00dev->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = NULL; 897 rt2x00dev->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = NULL;
888 rt2x00dev->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL; 898 rt2x00dev->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
889 } 899 }
900
901 kfree(rt2x00dev->spec.channels_info);
890} 902}
891 903
892static int rt2x00lib_probe_hw(struct rt2x00_dev *rt2x00dev) 904static int rt2x00lib_probe_hw(struct rt2x00_dev *rt2x00dev)
@@ -894,6 +906,9 @@ static int rt2x00lib_probe_hw(struct rt2x00_dev *rt2x00dev)
894 struct hw_mode_spec *spec = &rt2x00dev->spec; 906 struct hw_mode_spec *spec = &rt2x00dev->spec;
895 int status; 907 int status;
896 908
909 if (test_bit(DEVICE_STATE_REGISTERED_HW, &rt2x00dev->flags))
910 return 0;
911
897 /* 912 /*
898 * Initialize HW modes. 913 * Initialize HW modes.
899 */ 914 */
@@ -915,7 +930,7 @@ static int rt2x00lib_probe_hw(struct rt2x00_dev *rt2x00dev)
915 return status; 930 return status;
916 } 931 }
917 932
918 __set_bit(DEVICE_REGISTERED_HW, &rt2x00dev->flags); 933 set_bit(DEVICE_STATE_REGISTERED_HW, &rt2x00dev->flags);
919 934
920 return 0; 935 return 0;
921} 936}
@@ -925,7 +940,7 @@ static int rt2x00lib_probe_hw(struct rt2x00_dev *rt2x00dev)
925 */ 940 */
926static void rt2x00lib_uninitialize(struct rt2x00_dev *rt2x00dev) 941static void rt2x00lib_uninitialize(struct rt2x00_dev *rt2x00dev)
927{ 942{
928 if (!__test_and_clear_bit(DEVICE_INITIALIZED, &rt2x00dev->flags)) 943 if (!test_and_clear_bit(DEVICE_STATE_INITIALIZED, &rt2x00dev->flags))
929 return; 944 return;
930 945
931 /* 946 /*
@@ -948,7 +963,7 @@ static int rt2x00lib_initialize(struct rt2x00_dev *rt2x00dev)
948{ 963{
949 int status; 964 int status;
950 965
951 if (test_bit(DEVICE_INITIALIZED, &rt2x00dev->flags)) 966 if (test_bit(DEVICE_STATE_INITIALIZED, &rt2x00dev->flags))
952 return 0; 967 return 0;
953 968
954 /* 969 /*
@@ -967,7 +982,7 @@ static int rt2x00lib_initialize(struct rt2x00_dev *rt2x00dev)
967 return status; 982 return status;
968 } 983 }
969 984
970 __set_bit(DEVICE_INITIALIZED, &rt2x00dev->flags); 985 set_bit(DEVICE_STATE_INITIALIZED, &rt2x00dev->flags);
971 986
972 /* 987 /*
973 * Register the extra components. 988 * Register the extra components.
@@ -981,7 +996,7 @@ int rt2x00lib_start(struct rt2x00_dev *rt2x00dev)
981{ 996{
982 int retval; 997 int retval;
983 998
984 if (test_bit(DEVICE_STARTED, &rt2x00dev->flags)) 999 if (test_bit(DEVICE_STATE_STARTED, &rt2x00dev->flags))
985 return 0; 1000 return 0;
986 1001
987 /* 1002 /*
@@ -999,28 +1014,18 @@ int rt2x00lib_start(struct rt2x00_dev *rt2x00dev)
999 if (retval) 1014 if (retval)
1000 return retval; 1015 return retval;
1001 1016
1002 /*
1003 * Enable radio.
1004 */
1005 retval = rt2x00lib_enable_radio(rt2x00dev);
1006 if (retval) {
1007 rt2x00lib_uninitialize(rt2x00dev);
1008 return retval;
1009 }
1010
1011 rt2x00dev->intf_ap_count = 0; 1017 rt2x00dev->intf_ap_count = 0;
1012 rt2x00dev->intf_sta_count = 0; 1018 rt2x00dev->intf_sta_count = 0;
1013 rt2x00dev->intf_associated = 0; 1019 rt2x00dev->intf_associated = 0;
1014 1020
1015 __set_bit(DEVICE_STARTED, &rt2x00dev->flags); 1021 set_bit(DEVICE_STATE_STARTED, &rt2x00dev->flags);
1016 __set_bit(DEVICE_DIRTY_CONFIG, &rt2x00dev->flags);
1017 1022
1018 return 0; 1023 return 0;
1019} 1024}
1020 1025
1021void rt2x00lib_stop(struct rt2x00_dev *rt2x00dev) 1026void rt2x00lib_stop(struct rt2x00_dev *rt2x00dev)
1022{ 1027{
1023 if (!test_bit(DEVICE_STARTED, &rt2x00dev->flags)) 1028 if (!test_and_clear_bit(DEVICE_STATE_STARTED, &rt2x00dev->flags))
1024 return; 1029 return;
1025 1030
1026 /* 1031 /*
@@ -1032,8 +1037,6 @@ void rt2x00lib_stop(struct rt2x00_dev *rt2x00dev)
1032 rt2x00dev->intf_ap_count = 0; 1037 rt2x00dev->intf_ap_count = 0;
1033 rt2x00dev->intf_sta_count = 0; 1038 rt2x00dev->intf_sta_count = 0;
1034 rt2x00dev->intf_associated = 0; 1039 rt2x00dev->intf_associated = 0;
1035
1036 __clear_bit(DEVICE_STARTED, &rt2x00dev->flags);
1037} 1040}
1038 1041
1039/* 1042/*
@@ -1049,6 +1052,11 @@ int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev)
1049 */ 1052 */
1050 rt2x00dev->hw->vif_data_size = sizeof(struct rt2x00_intf); 1053 rt2x00dev->hw->vif_data_size = sizeof(struct rt2x00_intf);
1051 1054
1055 rt2x00dev->hw->wiphy->interface_modes =
1056 BIT(NL80211_IFTYPE_AP) |
1057 BIT(NL80211_IFTYPE_STATION) |
1058 BIT(NL80211_IFTYPE_ADHOC);
1059
1052 /* 1060 /*
1053 * Let the driver probe the device to detect the capabilities. 1061 * Let the driver probe the device to detect the capabilities.
1054 */ 1062 */
@@ -1088,7 +1096,7 @@ int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev)
1088 rt2x00rfkill_allocate(rt2x00dev); 1096 rt2x00rfkill_allocate(rt2x00dev);
1089 rt2x00debug_register(rt2x00dev); 1097 rt2x00debug_register(rt2x00dev);
1090 1098
1091 __set_bit(DEVICE_PRESENT, &rt2x00dev->flags); 1099 set_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags);
1092 1100
1093 return 0; 1101 return 0;
1094 1102
@@ -1101,7 +1109,7 @@ EXPORT_SYMBOL_GPL(rt2x00lib_probe_dev);
1101 1109
1102void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev) 1110void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev)
1103{ 1111{
1104 __clear_bit(DEVICE_PRESENT, &rt2x00dev->flags); 1112 clear_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags);
1105 1113
1106 /* 1114 /*
1107 * Disable radio. 1115 * Disable radio.
@@ -1146,14 +1154,15 @@ int rt2x00lib_suspend(struct rt2x00_dev *rt2x00dev, pm_message_t state)
1146 int retval; 1154 int retval;
1147 1155
1148 NOTICE(rt2x00dev, "Going to sleep.\n"); 1156 NOTICE(rt2x00dev, "Going to sleep.\n");
1149 __clear_bit(DEVICE_PRESENT, &rt2x00dev->flags);
1150 1157
1151 /* 1158 /*
1152 * Only continue if mac80211 has open interfaces. 1159 * Only continue if mac80211 has open interfaces.
1153 */ 1160 */
1154 if (!test_bit(DEVICE_STARTED, &rt2x00dev->flags)) 1161 if (!test_and_clear_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags) ||
1162 !test_bit(DEVICE_STATE_STARTED, &rt2x00dev->flags))
1155 goto exit; 1163 goto exit;
1156 __set_bit(DEVICE_STARTED_SUSPEND, &rt2x00dev->flags); 1164
1165 set_bit(DEVICE_STATE_STARTED_SUSPEND, &rt2x00dev->flags);
1157 1166
1158 /* 1167 /*
1159 * Disable radio. 1168 * Disable radio.
@@ -1203,8 +1212,8 @@ static void rt2x00lib_resume_intf(void *data, u8 *mac,
1203 /* 1212 /*
1204 * Master or Ad-hoc mode require a new beacon update. 1213 * Master or Ad-hoc mode require a new beacon update.
1205 */ 1214 */
1206 if (vif->type == IEEE80211_IF_TYPE_AP || 1215 if (vif->type == NL80211_IFTYPE_AP ||
1207 vif->type == IEEE80211_IF_TYPE_IBSS) 1216 vif->type == NL80211_IFTYPE_ADHOC)
1208 intf->delayed_flags |= DELAYED_UPDATE_BEACON; 1217 intf->delayed_flags |= DELAYED_UPDATE_BEACON;
1209 1218
1210 spin_unlock(&intf->lock); 1219 spin_unlock(&intf->lock);
@@ -1225,7 +1234,7 @@ int rt2x00lib_resume(struct rt2x00_dev *rt2x00dev)
1225 /* 1234 /*
1226 * Only continue if mac80211 had open interfaces. 1235 * Only continue if mac80211 had open interfaces.
1227 */ 1236 */
1228 if (!__test_and_clear_bit(DEVICE_STARTED_SUSPEND, &rt2x00dev->flags)) 1237 if (!test_and_clear_bit(DEVICE_STATE_STARTED_SUSPEND, &rt2x00dev->flags))
1229 return 0; 1238 return 0;
1230 1239
1231 /* 1240 /*
@@ -1252,7 +1261,7 @@ int rt2x00lib_resume(struct rt2x00_dev *rt2x00dev)
1252 /* 1261 /*
1253 * We are ready again to receive requests from mac80211. 1262 * We are ready again to receive requests from mac80211.
1254 */ 1263 */
1255 __set_bit(DEVICE_PRESENT, &rt2x00dev->flags); 1264 set_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags);
1256 1265
1257 /* 1266 /*
1258 * It is possible that during that mac80211 has attempted 1267 * It is possible that during that mac80211 has attempted
@@ -1272,7 +1281,7 @@ int rt2x00lib_resume(struct rt2x00_dev *rt2x00dev)
1272 return 0; 1281 return 0;
1273 1282
1274exit: 1283exit:
1275 rt2x00lib_disable_radio(rt2x00dev); 1284 rt2x00lib_stop(rt2x00dev);
1276 rt2x00lib_uninitialize(rt2x00dev); 1285 rt2x00lib_uninitialize(rt2x00dev);
1277 rt2x00debug_deregister(rt2x00dev); 1286 rt2x00debug_deregister(rt2x00dev);
1278 1287
diff --git a/drivers/net/wireless/rt2x00/rt2x00lib.h b/drivers/net/wireless/rt2x00/rt2x00lib.h
index c5fb3a72cf37..797eb619aa0a 100644
--- a/drivers/net/wireless/rt2x00/rt2x00lib.h
+++ b/drivers/net/wireless/rt2x00/rt2x00lib.h
@@ -88,7 +88,7 @@ void rt2x00lib_stop(struct rt2x00_dev *rt2x00dev);
88 */ 88 */
89void rt2x00lib_config_intf(struct rt2x00_dev *rt2x00dev, 89void rt2x00lib_config_intf(struct rt2x00_dev *rt2x00dev,
90 struct rt2x00_intf *intf, 90 struct rt2x00_intf *intf,
91 enum ieee80211_if_types type, 91 enum nl80211_iftype type,
92 u8 *mac, u8 *bssid); 92 u8 *mac, u8 *bssid);
93void rt2x00lib_config_erp(struct rt2x00_dev *rt2x00dev, 93void rt2x00lib_config_erp(struct rt2x00_dev *rt2x00dev,
94 struct rt2x00_intf *intf, 94 struct rt2x00_intf *intf,
@@ -181,6 +181,8 @@ void rt2x00debug_register(struct rt2x00_dev *rt2x00dev);
181void rt2x00debug_deregister(struct rt2x00_dev *rt2x00dev); 181void rt2x00debug_deregister(struct rt2x00_dev *rt2x00dev);
182void rt2x00debug_dump_frame(struct rt2x00_dev *rt2x00dev, 182void rt2x00debug_dump_frame(struct rt2x00_dev *rt2x00dev,
183 enum rt2x00_dump_type type, struct sk_buff *skb); 183 enum rt2x00_dump_type type, struct sk_buff *skb);
184void rt2x00debug_update_crypto(struct rt2x00_dev *rt2x00dev,
185 enum cipher cipher, enum rx_crypto status);
184#else 186#else
185static inline void rt2x00debug_register(struct rt2x00_dev *rt2x00dev) 187static inline void rt2x00debug_register(struct rt2x00_dev *rt2x00dev)
186{ 188{
@@ -195,9 +197,54 @@ static inline void rt2x00debug_dump_frame(struct rt2x00_dev *rt2x00dev,
195 struct sk_buff *skb) 197 struct sk_buff *skb)
196{ 198{
197} 199}
200
201static inline void rt2x00debug_update_crypto(struct rt2x00_dev *rt2x00dev,
202 enum cipher cipher,
203 enum rx_crypto status)
204{
205}
198#endif /* CONFIG_RT2X00_LIB_DEBUGFS */ 206#endif /* CONFIG_RT2X00_LIB_DEBUGFS */
199 207
200/* 208/*
209 * Crypto handlers.
210 */
211#ifdef CONFIG_RT2X00_LIB_CRYPTO
212enum cipher rt2x00crypto_key_to_cipher(struct ieee80211_key_conf *key);
213unsigned int rt2x00crypto_tx_overhead(struct ieee80211_tx_info *tx_info);
214void rt2x00crypto_tx_remove_iv(struct sk_buff *skb, unsigned int iv_len);
215void rt2x00crypto_tx_insert_iv(struct sk_buff *skb);
216void rt2x00crypto_rx_insert_iv(struct sk_buff *skb, unsigned int align,
217 unsigned int header_length,
218 struct rxdone_entry_desc *rxdesc);
219#else
220static inline enum cipher rt2x00crypto_key_to_cipher(struct ieee80211_key_conf *key)
221{
222 return CIPHER_NONE;
223}
224
225static inline unsigned int rt2x00crypto_tx_overhead(struct ieee80211_tx_info *tx_info)
226{
227 return 0;
228}
229
230static inline void rt2x00crypto_tx_remove_iv(struct sk_buff *skb,
231 unsigned int iv_len)
232{
233}
234
235static inline void rt2x00crypto_tx_insert_iv(struct sk_buff *skb)
236{
237}
238
239static inline void rt2x00crypto_rx_insert_iv(struct sk_buff *skb,
240 unsigned int align,
241 unsigned int header_length,
242 struct rxdone_entry_desc *rxdesc)
243{
244}
245#endif
246
247/*
201 * RFkill handlers. 248 * RFkill handlers.
202 */ 249 */
203#ifdef CONFIG_RT2X00_LIB_RFKILL 250#ifdef CONFIG_RT2X00_LIB_RFKILL
diff --git a/drivers/net/wireless/rt2x00/rt2x00mac.c b/drivers/net/wireless/rt2x00/rt2x00mac.c
index d06507388635..2c6cc5c374ff 100644
--- a/drivers/net/wireless/rt2x00/rt2x00mac.c
+++ b/drivers/net/wireless/rt2x00/rt2x00mac.c
@@ -36,21 +36,22 @@ static int rt2x00mac_tx_rts_cts(struct rt2x00_dev *rt2x00dev,
36 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(frag_skb); 36 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(frag_skb);
37 struct ieee80211_tx_info *rts_info; 37 struct ieee80211_tx_info *rts_info;
38 struct sk_buff *skb; 38 struct sk_buff *skb;
39 int size; 39 unsigned int data_length;
40 int retval = 0;
40 41
41 if (tx_info->flags & IEEE80211_TX_CTL_USE_CTS_PROTECT) 42 if (tx_info->flags & IEEE80211_TX_CTL_USE_CTS_PROTECT)
42 size = sizeof(struct ieee80211_cts); 43 data_length = sizeof(struct ieee80211_cts);
43 else 44 else
44 size = sizeof(struct ieee80211_rts); 45 data_length = sizeof(struct ieee80211_rts);
45 46
46 skb = dev_alloc_skb(size + rt2x00dev->hw->extra_tx_headroom); 47 skb = dev_alloc_skb(data_length + rt2x00dev->hw->extra_tx_headroom);
47 if (!skb) { 48 if (unlikely(!skb)) {
48 WARNING(rt2x00dev, "Failed to create RTS/CTS frame.\n"); 49 WARNING(rt2x00dev, "Failed to create RTS/CTS frame.\n");
49 return NETDEV_TX_BUSY; 50 return -ENOMEM;
50 } 51 }
51 52
52 skb_reserve(skb, rt2x00dev->hw->extra_tx_headroom); 53 skb_reserve(skb, rt2x00dev->hw->extra_tx_headroom);
53 skb_put(skb, size); 54 skb_put(skb, data_length);
54 55
55 /* 56 /*
56 * Copy TX information over from original frame to 57 * Copy TX information over from original frame to
@@ -63,7 +64,6 @@ static int rt2x00mac_tx_rts_cts(struct rt2x00_dev *rt2x00dev,
63 */ 64 */
64 memcpy(skb->cb, frag_skb->cb, sizeof(skb->cb)); 65 memcpy(skb->cb, frag_skb->cb, sizeof(skb->cb));
65 rts_info = IEEE80211_SKB_CB(skb); 66 rts_info = IEEE80211_SKB_CB(skb);
66 rts_info->control.hw_key = NULL;
67 rts_info->flags &= ~IEEE80211_TX_CTL_USE_RTS_CTS; 67 rts_info->flags &= ~IEEE80211_TX_CTL_USE_RTS_CTS;
68 rts_info->flags &= ~IEEE80211_TX_CTL_USE_CTS_PROTECT; 68 rts_info->flags &= ~IEEE80211_TX_CTL_USE_CTS_PROTECT;
69 rts_info->flags &= ~IEEE80211_TX_CTL_REQ_TX_STATUS; 69 rts_info->flags &= ~IEEE80211_TX_CTL_REQ_TX_STATUS;
@@ -73,22 +73,33 @@ static int rt2x00mac_tx_rts_cts(struct rt2x00_dev *rt2x00dev,
73 else 73 else
74 rts_info->flags &= ~IEEE80211_TX_CTL_NO_ACK; 74 rts_info->flags &= ~IEEE80211_TX_CTL_NO_ACK;
75 75
76 skb->do_not_encrypt = 1;
77
78 /*
79 * RTS/CTS frame should use the length of the frame plus any
80 * encryption overhead that will be added by the hardware.
81 */
82#ifdef CONFIG_RT2X00_LIB_CRYPTO
83 if (!frag_skb->do_not_encrypt)
84 data_length += rt2x00crypto_tx_overhead(tx_info);
85#endif /* CONFIG_RT2X00_LIB_CRYPTO */
86
76 if (tx_info->flags & IEEE80211_TX_CTL_USE_CTS_PROTECT) 87 if (tx_info->flags & IEEE80211_TX_CTL_USE_CTS_PROTECT)
77 ieee80211_ctstoself_get(rt2x00dev->hw, tx_info->control.vif, 88 ieee80211_ctstoself_get(rt2x00dev->hw, tx_info->control.vif,
78 frag_skb->data, size, tx_info, 89 frag_skb->data, data_length, tx_info,
79 (struct ieee80211_cts *)(skb->data)); 90 (struct ieee80211_cts *)(skb->data));
80 else 91 else
81 ieee80211_rts_get(rt2x00dev->hw, tx_info->control.vif, 92 ieee80211_rts_get(rt2x00dev->hw, tx_info->control.vif,
82 frag_skb->data, size, tx_info, 93 frag_skb->data, data_length, tx_info,
83 (struct ieee80211_rts *)(skb->data)); 94 (struct ieee80211_rts *)(skb->data));
84 95
85 if (rt2x00queue_write_tx_frame(queue, skb)) { 96 retval = rt2x00queue_write_tx_frame(queue, skb);
97 if (retval) {
86 dev_kfree_skb_any(skb); 98 dev_kfree_skb_any(skb);
87 WARNING(rt2x00dev, "Failed to send RTS/CTS frame.\n"); 99 WARNING(rt2x00dev, "Failed to send RTS/CTS frame.\n");
88 return NETDEV_TX_BUSY;
89 } 100 }
90 101
91 return NETDEV_TX_OK; 102 return retval;
92} 103}
93 104
94int rt2x00mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb) 105int rt2x00mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
@@ -106,11 +117,8 @@ int rt2x00mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
106 * Note that we can only stop the TX queues inside the TX path 117 * Note that we can only stop the TX queues inside the TX path
107 * due to possible race conditions in mac80211. 118 * due to possible race conditions in mac80211.
108 */ 119 */
109 if (!test_bit(DEVICE_PRESENT, &rt2x00dev->flags)) { 120 if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags))
110 ieee80211_stop_queues(hw); 121 goto exit_fail;
111 dev_kfree_skb_any(skb);
112 return NETDEV_TX_OK;
113 }
114 122
115 /* 123 /*
116 * Determine which queue to put packet on. 124 * Determine which queue to put packet on.
@@ -141,26 +149,25 @@ int rt2x00mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
141 if ((tx_info->flags & (IEEE80211_TX_CTL_USE_RTS_CTS | 149 if ((tx_info->flags & (IEEE80211_TX_CTL_USE_RTS_CTS |
142 IEEE80211_TX_CTL_USE_CTS_PROTECT)) && 150 IEEE80211_TX_CTL_USE_CTS_PROTECT)) &&
143 !rt2x00dev->ops->hw->set_rts_threshold) { 151 !rt2x00dev->ops->hw->set_rts_threshold) {
144 if (rt2x00queue_available(queue) <= 1) { 152 if (rt2x00queue_available(queue) <= 1)
145 ieee80211_stop_queue(rt2x00dev->hw, qid); 153 goto exit_fail;
146 return NETDEV_TX_BUSY;
147 }
148
149 if (rt2x00mac_tx_rts_cts(rt2x00dev, queue, skb)) {
150 ieee80211_stop_queue(rt2x00dev->hw, qid);
151 return NETDEV_TX_BUSY;
152 }
153 }
154 154
155 if (rt2x00queue_write_tx_frame(queue, skb)) { 155 if (rt2x00mac_tx_rts_cts(rt2x00dev, queue, skb))
156 ieee80211_stop_queue(rt2x00dev->hw, qid); 156 goto exit_fail;
157 return NETDEV_TX_BUSY;
158 } 157 }
159 158
159 if (rt2x00queue_write_tx_frame(queue, skb))
160 goto exit_fail;
161
160 if (rt2x00queue_threshold(queue)) 162 if (rt2x00queue_threshold(queue))
161 ieee80211_stop_queue(rt2x00dev->hw, qid); 163 ieee80211_stop_queue(rt2x00dev->hw, qid);
162 164
163 return NETDEV_TX_OK; 165 return NETDEV_TX_OK;
166
167 exit_fail:
168 ieee80211_stop_queue(rt2x00dev->hw, qid);
169 dev_kfree_skb_any(skb);
170 return NETDEV_TX_OK;
164} 171}
165EXPORT_SYMBOL_GPL(rt2x00mac_tx); 172EXPORT_SYMBOL_GPL(rt2x00mac_tx);
166 173
@@ -168,7 +175,7 @@ int rt2x00mac_start(struct ieee80211_hw *hw)
168{ 175{
169 struct rt2x00_dev *rt2x00dev = hw->priv; 176 struct rt2x00_dev *rt2x00dev = hw->priv;
170 177
171 if (!test_bit(DEVICE_PRESENT, &rt2x00dev->flags)) 178 if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags))
172 return 0; 179 return 0;
173 180
174 return rt2x00lib_start(rt2x00dev); 181 return rt2x00lib_start(rt2x00dev);
@@ -179,7 +186,7 @@ void rt2x00mac_stop(struct ieee80211_hw *hw)
179{ 186{
180 struct rt2x00_dev *rt2x00dev = hw->priv; 187 struct rt2x00_dev *rt2x00dev = hw->priv;
181 188
182 if (!test_bit(DEVICE_PRESENT, &rt2x00dev->flags)) 189 if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags))
183 return; 190 return;
184 191
185 rt2x00lib_stop(rt2x00dev); 192 rt2x00lib_stop(rt2x00dev);
@@ -199,12 +206,12 @@ int rt2x00mac_add_interface(struct ieee80211_hw *hw,
199 * Don't allow interfaces to be added 206 * Don't allow interfaces to be added
200 * the device has disappeared. 207 * the device has disappeared.
201 */ 208 */
202 if (!test_bit(DEVICE_PRESENT, &rt2x00dev->flags) || 209 if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags) ||
203 !test_bit(DEVICE_STARTED, &rt2x00dev->flags)) 210 !test_bit(DEVICE_STATE_STARTED, &rt2x00dev->flags))
204 return -ENODEV; 211 return -ENODEV;
205 212
206 switch (conf->type) { 213 switch (conf->type) {
207 case IEEE80211_IF_TYPE_AP: 214 case NL80211_IFTYPE_AP:
208 /* 215 /*
209 * We don't support mixed combinations of 216 * We don't support mixed combinations of
210 * sta and ap interfaces. 217 * sta and ap interfaces.
@@ -220,8 +227,8 @@ int rt2x00mac_add_interface(struct ieee80211_hw *hw,
220 return -ENOBUFS; 227 return -ENOBUFS;
221 228
222 break; 229 break;
223 case IEEE80211_IF_TYPE_STA: 230 case NL80211_IFTYPE_STATION:
224 case IEEE80211_IF_TYPE_IBSS: 231 case NL80211_IFTYPE_ADHOC:
225 /* 232 /*
226 * We don't support mixed combinations of 233 * We don't support mixed combinations of
227 * sta and ap interfaces. 234 * sta and ap interfaces.
@@ -249,7 +256,7 @@ int rt2x00mac_add_interface(struct ieee80211_hw *hw,
249 */ 256 */
250 for (i = 0; i < queue->limit; i++) { 257 for (i = 0; i < queue->limit; i++) {
251 entry = &queue->entries[i]; 258 entry = &queue->entries[i];
252 if (!__test_and_set_bit(ENTRY_BCN_ASSIGNED, &entry->flags)) 259 if (!test_and_set_bit(ENTRY_BCN_ASSIGNED, &entry->flags))
253 break; 260 break;
254 } 261 }
255 262
@@ -261,7 +268,7 @@ int rt2x00mac_add_interface(struct ieee80211_hw *hw,
261 * increase interface count and start initialization. 268 * increase interface count and start initialization.
262 */ 269 */
263 270
264 if (conf->type == IEEE80211_IF_TYPE_AP) 271 if (conf->type == NL80211_IFTYPE_AP)
265 rt2x00dev->intf_ap_count++; 272 rt2x00dev->intf_ap_count++;
266 else 273 else
267 rt2x00dev->intf_sta_count++; 274 rt2x00dev->intf_sta_count++;
@@ -270,7 +277,7 @@ int rt2x00mac_add_interface(struct ieee80211_hw *hw,
270 spin_lock_init(&intf->seqlock); 277 spin_lock_init(&intf->seqlock);
271 intf->beacon = entry; 278 intf->beacon = entry;
272 279
273 if (conf->type == IEEE80211_IF_TYPE_AP) 280 if (conf->type == NL80211_IFTYPE_AP)
274 memcpy(&intf->bssid, conf->mac_addr, ETH_ALEN); 281 memcpy(&intf->bssid, conf->mac_addr, ETH_ALEN);
275 memcpy(&intf->mac, conf->mac_addr, ETH_ALEN); 282 memcpy(&intf->mac, conf->mac_addr, ETH_ALEN);
276 283
@@ -303,12 +310,12 @@ void rt2x00mac_remove_interface(struct ieee80211_hw *hw,
303 * either the device has disappeared or when 310 * either the device has disappeared or when
304 * no interface is present. 311 * no interface is present.
305 */ 312 */
306 if (!test_bit(DEVICE_PRESENT, &rt2x00dev->flags) || 313 if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags) ||
307 (conf->type == IEEE80211_IF_TYPE_AP && !rt2x00dev->intf_ap_count) || 314 (conf->type == NL80211_IFTYPE_AP && !rt2x00dev->intf_ap_count) ||
308 (conf->type != IEEE80211_IF_TYPE_AP && !rt2x00dev->intf_sta_count)) 315 (conf->type != NL80211_IFTYPE_AP && !rt2x00dev->intf_sta_count))
309 return; 316 return;
310 317
311 if (conf->type == IEEE80211_IF_TYPE_AP) 318 if (conf->type == NL80211_IFTYPE_AP)
312 rt2x00dev->intf_ap_count--; 319 rt2x00dev->intf_ap_count--;
313 else 320 else
314 rt2x00dev->intf_sta_count--; 321 rt2x00dev->intf_sta_count--;
@@ -317,59 +324,59 @@ void rt2x00mac_remove_interface(struct ieee80211_hw *hw,
317 * Release beacon entry so it is available for 324 * Release beacon entry so it is available for
318 * new interfaces again. 325 * new interfaces again.
319 */ 326 */
320 __clear_bit(ENTRY_BCN_ASSIGNED, &intf->beacon->flags); 327 clear_bit(ENTRY_BCN_ASSIGNED, &intf->beacon->flags);
321 328
322 /* 329 /*
323 * Make sure the bssid and mac address registers 330 * Make sure the bssid and mac address registers
324 * are cleared to prevent false ACKing of frames. 331 * are cleared to prevent false ACKing of frames.
325 */ 332 */
326 rt2x00lib_config_intf(rt2x00dev, intf, 333 rt2x00lib_config_intf(rt2x00dev, intf,
327 IEEE80211_IF_TYPE_INVALID, NULL, NULL); 334 NL80211_IFTYPE_UNSPECIFIED, NULL, NULL);
328} 335}
329EXPORT_SYMBOL_GPL(rt2x00mac_remove_interface); 336EXPORT_SYMBOL_GPL(rt2x00mac_remove_interface);
330 337
331int rt2x00mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf) 338int rt2x00mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf)
332{ 339{
333 struct rt2x00_dev *rt2x00dev = hw->priv; 340 struct rt2x00_dev *rt2x00dev = hw->priv;
334 int force_reconfig; 341 int radio_on;
342 int status;
335 343
336 /* 344 /*
337 * Mac80211 might be calling this function while we are trying 345 * Mac80211 might be calling this function while we are trying
338 * to remove the device or perhaps suspending it. 346 * to remove the device or perhaps suspending it.
339 */ 347 */
340 if (!test_bit(DEVICE_PRESENT, &rt2x00dev->flags)) 348 if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags))
341 return 0; 349 return 0;
342 350
343 /* 351 /*
344 * Check if we need to disable the radio, 352 * Only change device state when the radio is enabled. It does not
345 * if this is not the case, at least the RX must be disabled. 353 * matter what parameters we have configured when the radio is disabled
354 * because we won't be able to send or receive anyway. Also note that
355 * some configuration parameters (e.g. channel and antenna values) can
356 * only be set when the radio is enabled.
346 */ 357 */
347 if (test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags)) { 358 radio_on = test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags);
348 if (!conf->radio_enabled) 359 if (conf->radio_enabled) {
349 rt2x00lib_disable_radio(rt2x00dev); 360 /* For programming the values, we have to turn RX off */
350 else 361 rt2x00lib_toggle_rx(rt2x00dev, STATE_RADIO_RX_OFF);
351 rt2x00lib_toggle_rx(rt2x00dev, STATE_RADIO_RX_OFF);
352 }
353 362
354 /* 363 /* Enable the radio */
355 * When the DEVICE_DIRTY_CONFIG flag is set, the device has recently 364 status = rt2x00lib_enable_radio(rt2x00dev);
356 * been started and the configuration must be forced upon the hardware. 365 if (unlikely(status))
357 * Otherwise registers will not be intialized correctly and could 366 return status;
358 * result in non-working hardware because essential registers aren't
359 * initialized.
360 */
361 force_reconfig =
362 __test_and_clear_bit(DEVICE_DIRTY_CONFIG, &rt2x00dev->flags);
363 367
364 rt2x00lib_config(rt2x00dev, conf, force_reconfig); 368 /*
369 * When we've just turned on the radio, we want to reprogram
370 * everything to ensure a consistent state
371 */
372 rt2x00lib_config(rt2x00dev, conf, !radio_on);
365 373
366 /* 374 /* Turn RX back on */
367 * Reenable RX only if the radio should be on.
368 */
369 if (test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags))
370 rt2x00lib_toggle_rx(rt2x00dev, STATE_RADIO_RX_ON); 375 rt2x00lib_toggle_rx(rt2x00dev, STATE_RADIO_RX_ON);
371 else if (conf->radio_enabled) 376 } else {
372 return rt2x00lib_enable_radio(rt2x00dev); 377 /* Disable the radio */
378 rt2x00lib_disable_radio(rt2x00dev);
379 }
373 380
374 return 0; 381 return 0;
375} 382}
@@ -388,7 +395,7 @@ int rt2x00mac_config_interface(struct ieee80211_hw *hw,
388 * Mac80211 might be calling this function while we are trying 395 * Mac80211 might be calling this function while we are trying
389 * to remove the device or perhaps suspending it. 396 * to remove the device or perhaps suspending it.
390 */ 397 */
391 if (!test_bit(DEVICE_PRESENT, &rt2x00dev->flags)) 398 if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags))
392 return 0; 399 return 0;
393 400
394 spin_lock(&intf->lock); 401 spin_lock(&intf->lock);
@@ -467,6 +474,91 @@ void rt2x00mac_configure_filter(struct ieee80211_hw *hw,
467} 474}
468EXPORT_SYMBOL_GPL(rt2x00mac_configure_filter); 475EXPORT_SYMBOL_GPL(rt2x00mac_configure_filter);
469 476
477#ifdef CONFIG_RT2X00_LIB_CRYPTO
478int rt2x00mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
479 const u8 *local_address, const u8 *address,
480 struct ieee80211_key_conf *key)
481{
482 struct rt2x00_dev *rt2x00dev = hw->priv;
483 int (*set_key) (struct rt2x00_dev *rt2x00dev,
484 struct rt2x00lib_crypto *crypto,
485 struct ieee80211_key_conf *key);
486 struct rt2x00lib_crypto crypto;
487
488 if (!test_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags))
489 return -EOPNOTSUPP;
490 else if (key->keylen > 32)
491 return -ENOSPC;
492
493 memset(&crypto, 0, sizeof(crypto));
494
495 /*
496 * When in STA mode, bssidx is always 0 otherwise local_address[5]
497 * contains the bss number, see BSS_ID_MASK comments for details.
498 */
499 if (rt2x00dev->intf_sta_count)
500 crypto.bssidx = 0;
501 else
502 crypto.bssidx =
503 local_address[5] & (rt2x00dev->ops->max_ap_intf - 1);
504
505 crypto.cipher = rt2x00crypto_key_to_cipher(key);
506 if (crypto.cipher == CIPHER_NONE)
507 return -EOPNOTSUPP;
508
509 crypto.cmd = cmd;
510 crypto.address = address;
511
512 if (crypto.cipher == CIPHER_TKIP) {
513 if (key->keylen > NL80211_TKIP_DATA_OFFSET_ENCR_KEY)
514 memcpy(&crypto.key,
515 &key->key[NL80211_TKIP_DATA_OFFSET_ENCR_KEY],
516 sizeof(crypto.key));
517
518 if (key->keylen > NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY)
519 memcpy(&crypto.tx_mic,
520 &key->key[NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY],
521 sizeof(crypto.tx_mic));
522
523 if (key->keylen > NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY)
524 memcpy(&crypto.rx_mic,
525 &key->key[NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY],
526 sizeof(crypto.rx_mic));
527 } else
528 memcpy(&crypto.key, &key->key[0], key->keylen);
529
530 /*
531 * Each BSS has a maximum of 4 shared keys.
532 * Shared key index values:
533 * 0) BSS0 key0
534 * 1) BSS0 key1
535 * ...
536 * 4) BSS1 key0
537 * ...
538 * 8) BSS2 key0
539 * ...
540 * Both pairwise as shared key indeces are determined by
541 * driver. This is required because the hardware requires
542 * keys to be assigned in correct order (When key 1 is
543 * provided but key 0 is not, then the key is not found
544 * by the hardware during RX).
545 */
546 if (cmd == SET_KEY)
547 key->hw_key_idx = 0;
548
549 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
550 set_key = rt2x00dev->ops->lib->config_pairwise_key;
551 else
552 set_key = rt2x00dev->ops->lib->config_shared_key;
553
554 if (!set_key)
555 return -EOPNOTSUPP;
556
557 return set_key(rt2x00dev, &crypto, key);
558}
559EXPORT_SYMBOL_GPL(rt2x00mac_set_key);
560#endif /* CONFIG_RT2X00_LIB_CRYPTO */
561
470int rt2x00mac_get_stats(struct ieee80211_hw *hw, 562int rt2x00mac_get_stats(struct ieee80211_hw *hw,
471 struct ieee80211_low_level_stats *stats) 563 struct ieee80211_low_level_stats *stats)
472{ 564{
@@ -575,10 +667,11 @@ int rt2x00mac_conf_tx(struct ieee80211_hw *hw, u16 queue_idx,
575 queue->cw_max = 10; /* cw_min: 2^10 = 1024. */ 667 queue->cw_max = 10; /* cw_min: 2^10 = 1024. */
576 668
577 queue->aifs = params->aifs; 669 queue->aifs = params->aifs;
670 queue->txop = params->txop;
578 671
579 INFO(rt2x00dev, 672 INFO(rt2x00dev,
580 "Configured TX queue %d - CWmin: %d, CWmax: %d, Aifs: %d.\n", 673 "Configured TX queue %d - CWmin: %d, CWmax: %d, Aifs: %d, TXop: %d.\n",
581 queue_idx, queue->cw_min, queue->cw_max, queue->aifs); 674 queue_idx, queue->cw_min, queue->cw_max, queue->aifs, queue->txop);
582 675
583 return 0; 676 return 0;
584} 677}
diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
index 898cdd7f57d9..1676ac484790 100644
--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
@@ -33,10 +33,11 @@
33struct sk_buff *rt2x00queue_alloc_rxskb(struct rt2x00_dev *rt2x00dev, 33struct sk_buff *rt2x00queue_alloc_rxskb(struct rt2x00_dev *rt2x00dev,
34 struct queue_entry *entry) 34 struct queue_entry *entry)
35{ 35{
36 unsigned int frame_size;
37 unsigned int reserved_size;
38 struct sk_buff *skb; 36 struct sk_buff *skb;
39 struct skb_frame_desc *skbdesc; 37 struct skb_frame_desc *skbdesc;
38 unsigned int frame_size;
39 unsigned int head_size = 0;
40 unsigned int tail_size = 0;
40 41
41 /* 42 /*
42 * The frame size includes descriptor size, because the 43 * The frame size includes descriptor size, because the
@@ -49,16 +50,32 @@ struct sk_buff *rt2x00queue_alloc_rxskb(struct rt2x00_dev *rt2x00dev,
49 * this means we need at least 3 bytes for moving the frame 50 * this means we need at least 3 bytes for moving the frame
50 * into the correct offset. 51 * into the correct offset.
51 */ 52 */
52 reserved_size = 4; 53 head_size = 4;
54
55 /*
56 * For IV/EIV/ICV assembly we must make sure there is
57 * at least 8 bytes bytes available in headroom for IV/EIV
58 * and 4 bytes for ICV data as tailroon.
59 */
60#ifdef CONFIG_RT2X00_LIB_CRYPTO
61 if (test_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags)) {
62 head_size += 8;
63 tail_size += 4;
64 }
65#endif /* CONFIG_RT2X00_LIB_CRYPTO */
53 66
54 /* 67 /*
55 * Allocate skbuffer. 68 * Allocate skbuffer.
56 */ 69 */
57 skb = dev_alloc_skb(frame_size + reserved_size); 70 skb = dev_alloc_skb(frame_size + head_size + tail_size);
58 if (!skb) 71 if (!skb)
59 return NULL; 72 return NULL;
60 73
61 skb_reserve(skb, reserved_size); 74 /*
75 * Make sure we not have a frame with the requested bytes
76 * available in the head and tail.
77 */
78 skb_reserve(skb, head_size);
62 skb_put(skb, frame_size); 79 skb_put(skb, frame_size);
63 80
64 /* 81 /*
@@ -83,8 +100,21 @@ void rt2x00queue_map_txskb(struct rt2x00_dev *rt2x00dev, struct sk_buff *skb)
83{ 100{
84 struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb); 101 struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb);
85 102
86 skbdesc->skb_dma = dma_map_single(rt2x00dev->dev, skb->data, skb->len, 103 /*
87 DMA_TO_DEVICE); 104 * If device has requested headroom, we should make sure that
105 * is also mapped to the DMA so it can be used for transfering
106 * additional descriptor information to the hardware.
107 */
108 skb_push(skb, rt2x00dev->hw->extra_tx_headroom);
109
110 skbdesc->skb_dma =
111 dma_map_single(rt2x00dev->dev, skb->data, skb->len, DMA_TO_DEVICE);
112
113 /*
114 * Restore data pointer to original location again.
115 */
116 skb_pull(skb, rt2x00dev->hw->extra_tx_headroom);
117
88 skbdesc->flags |= SKBDESC_DMA_MAPPED_TX; 118 skbdesc->flags |= SKBDESC_DMA_MAPPED_TX;
89} 119}
90EXPORT_SYMBOL_GPL(rt2x00queue_map_txskb); 120EXPORT_SYMBOL_GPL(rt2x00queue_map_txskb);
@@ -100,7 +130,12 @@ void rt2x00queue_unmap_skb(struct rt2x00_dev *rt2x00dev, struct sk_buff *skb)
100 } 130 }
101 131
102 if (skbdesc->flags & SKBDESC_DMA_MAPPED_TX) { 132 if (skbdesc->flags & SKBDESC_DMA_MAPPED_TX) {
103 dma_unmap_single(rt2x00dev->dev, skbdesc->skb_dma, skb->len, 133 /*
134 * Add headroom to the skb length, it has been removed
135 * by the driver, but it was actually mapped to DMA.
136 */
137 dma_unmap_single(rt2x00dev->dev, skbdesc->skb_dma,
138 skb->len + rt2x00dev->hw->extra_tx_headroom,
104 DMA_TO_DEVICE); 139 DMA_TO_DEVICE);
105 skbdesc->flags &= ~SKBDESC_DMA_MAPPED_TX; 140 skbdesc->flags &= ~SKBDESC_DMA_MAPPED_TX;
106 } 141 }
@@ -120,7 +155,6 @@ static void rt2x00queue_create_tx_descriptor(struct queue_entry *entry,
120{ 155{
121 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev; 156 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
122 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(entry->skb); 157 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(entry->skb);
123 struct rt2x00_intf *intf = vif_to_intf(tx_info->control.vif);
124 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)entry->skb->data; 158 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)entry->skb->data;
125 struct ieee80211_rate *rate = 159 struct ieee80211_rate *rate =
126 ieee80211_get_tx_rate(rt2x00dev->hw, tx_info); 160 ieee80211_get_tx_rate(rt2x00dev->hw, tx_info);
@@ -140,7 +174,7 @@ static void rt2x00queue_create_tx_descriptor(struct queue_entry *entry,
140 txdesc->cw_max = entry->queue->cw_max; 174 txdesc->cw_max = entry->queue->cw_max;
141 txdesc->aifs = entry->queue->aifs; 175 txdesc->aifs = entry->queue->aifs;
142 176
143 /* Data length should be extended with 4 bytes for CRC */ 177 /* Data length + CRC + IV/EIV/ICV/MMIC (when using encryption) */
144 data_length = entry->skb->len + 4; 178 data_length = entry->skb->len + 4;
145 179
146 /* 180 /*
@@ -149,6 +183,35 @@ static void rt2x00queue_create_tx_descriptor(struct queue_entry *entry,
149 if (!(tx_info->flags & IEEE80211_TX_CTL_NO_ACK)) 183 if (!(tx_info->flags & IEEE80211_TX_CTL_NO_ACK))
150 __set_bit(ENTRY_TXD_ACK, &txdesc->flags); 184 __set_bit(ENTRY_TXD_ACK, &txdesc->flags);
151 185
186#ifdef CONFIG_RT2X00_LIB_CRYPTO
187 if (test_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags) &&
188 !entry->skb->do_not_encrypt) {
189 struct ieee80211_key_conf *hw_key = tx_info->control.hw_key;
190
191 __set_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags);
192
193 txdesc->cipher = rt2x00crypto_key_to_cipher(hw_key);
194
195 if (hw_key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
196 __set_bit(ENTRY_TXD_ENCRYPT_PAIRWISE, &txdesc->flags);
197
198 txdesc->key_idx = hw_key->hw_key_idx;
199 txdesc->iv_offset = ieee80211_get_hdrlen_from_skb(entry->skb);
200
201 /*
202 * Extend frame length to include all encryption overhead
203 * that will be added by the hardware.
204 */
205 data_length += rt2x00crypto_tx_overhead(tx_info);
206
207 if (!(hw_key->flags & IEEE80211_KEY_FLAG_GENERATE_IV))
208 __set_bit(ENTRY_TXD_ENCRYPT_IV, &txdesc->flags);
209
210 if (!(hw_key->flags & IEEE80211_KEY_FLAG_GENERATE_MMIC))
211 __set_bit(ENTRY_TXD_ENCRYPT_MMIC, &txdesc->flags);
212 }
213#endif /* CONFIG_RT2X00_LIB_CRYPTO */
214
152 /* 215 /*
153 * Check if this is a RTS/CTS frame 216 * Check if this is a RTS/CTS frame
154 */ 217 */
@@ -214,16 +277,22 @@ static void rt2x00queue_create_tx_descriptor(struct queue_entry *entry,
214 * sequence counter given by mac80211. 277 * sequence counter given by mac80211.
215 */ 278 */
216 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) { 279 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
217 spin_lock_irqsave(&intf->seqlock, irqflags); 280 if (likely(tx_info->control.vif)) {
281 struct rt2x00_intf *intf;
218 282
219 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags)) 283 intf = vif_to_intf(tx_info->control.vif);
220 intf->seqno += 0x10;
221 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
222 hdr->seq_ctrl |= cpu_to_le16(intf->seqno);
223 284
224 spin_unlock_irqrestore(&intf->seqlock, irqflags); 285 spin_lock_irqsave(&intf->seqlock, irqflags);
225 286
226 __set_bit(ENTRY_TXD_GENERATE_SEQ, &txdesc->flags); 287 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
288 intf->seqno += 0x10;
289 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
290 hdr->seq_ctrl |= cpu_to_le16(intf->seqno);
291
292 spin_unlock_irqrestore(&intf->seqlock, irqflags);
293
294 __set_bit(ENTRY_TXD_GENERATE_SEQ, &txdesc->flags);
295 }
227 } 296 }
228 297
229 /* 298 /*
@@ -305,11 +374,12 @@ int rt2x00queue_write_tx_frame(struct data_queue *queue, struct sk_buff *skb)
305 struct queue_entry *entry = rt2x00queue_get_entry(queue, Q_INDEX); 374 struct queue_entry *entry = rt2x00queue_get_entry(queue, Q_INDEX);
306 struct txentry_desc txdesc; 375 struct txentry_desc txdesc;
307 struct skb_frame_desc *skbdesc; 376 struct skb_frame_desc *skbdesc;
377 unsigned int iv_len;
308 378
309 if (unlikely(rt2x00queue_full(queue))) 379 if (unlikely(rt2x00queue_full(queue)))
310 return -EINVAL; 380 return -EINVAL;
311 381
312 if (__test_and_set_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags)) { 382 if (test_and_set_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags)) {
313 ERROR(queue->rt2x00dev, 383 ERROR(queue->rt2x00dev,
314 "Arrived at non-free entry in the non-full queue %d.\n" 384 "Arrived at non-free entry in the non-full queue %d.\n"
315 "Please file bug report to %s.\n", 385 "Please file bug report to %s.\n",
@@ -326,21 +396,42 @@ int rt2x00queue_write_tx_frame(struct data_queue *queue, struct sk_buff *skb)
326 rt2x00queue_create_tx_descriptor(entry, &txdesc); 396 rt2x00queue_create_tx_descriptor(entry, &txdesc);
327 397
328 /* 398 /*
329 * skb->cb array is now ours and we are free to use it. 399 * All information is retreived from the skb->cb array,
400 * now we should claim ownership of the driver part of that
401 * array.
330 */ 402 */
331 skbdesc = get_skb_frame_desc(entry->skb); 403 skbdesc = get_skb_frame_desc(entry->skb);
332 memset(skbdesc, 0, sizeof(*skbdesc)); 404 memset(skbdesc, 0, sizeof(*skbdesc));
333 skbdesc->entry = entry; 405 skbdesc->entry = entry;
334 406
407 /*
408 * When hardware encryption is supported, and this frame
409 * is to be encrypted, we should strip the IV/EIV data from
410 * the frame so we can provide it to the driver seperately.
411 */
412 if (test_bit(ENTRY_TXD_ENCRYPT, &txdesc.flags) &&
413 !test_bit(ENTRY_TXD_ENCRYPT_IV, &txdesc.flags) &&
414 (IEEE80211_SKB_CB(skb)->control.hw_key != NULL)) {
415 iv_len = IEEE80211_SKB_CB(skb)->control.hw_key->iv_len;
416 rt2x00crypto_tx_remove_iv(skb, iv_len);
417 }
418
419 /*
420 * It could be possible that the queue was corrupted and this
421 * call failed. Just drop the frame, we cannot rollback and pass
422 * the frame to mac80211 because the skb->cb has now been tainted.
423 */
335 if (unlikely(queue->rt2x00dev->ops->lib->write_tx_data(entry))) { 424 if (unlikely(queue->rt2x00dev->ops->lib->write_tx_data(entry))) {
336 __clear_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags); 425 clear_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags);
337 return -EIO; 426 dev_kfree_skb_any(entry->skb);
427 entry->skb = NULL;
428 return 0;
338 } 429 }
339 430
340 if (test_bit(DRIVER_REQUIRE_DMA, &queue->rt2x00dev->flags)) 431 if (test_bit(DRIVER_REQUIRE_DMA, &queue->rt2x00dev->flags))
341 rt2x00queue_map_txskb(queue->rt2x00dev, skb); 432 rt2x00queue_map_txskb(queue->rt2x00dev, skb);
342 433
343 __set_bit(ENTRY_DATA_PENDING, &entry->flags); 434 set_bit(ENTRY_DATA_PENDING, &entry->flags);
344 435
345 rt2x00queue_index_inc(queue, Q_INDEX); 436 rt2x00queue_index_inc(queue, Q_INDEX);
346 rt2x00queue_write_tx_descriptor(entry, &txdesc); 437 rt2x00queue_write_tx_descriptor(entry, &txdesc);
@@ -653,6 +744,7 @@ static void rt2x00queue_init(struct rt2x00_dev *rt2x00dev,
653 744
654 queue->rt2x00dev = rt2x00dev; 745 queue->rt2x00dev = rt2x00dev;
655 queue->qid = qid; 746 queue->qid = qid;
747 queue->txop = 0;
656 queue->aifs = 2; 748 queue->aifs = 2;
657 queue->cw_min = 5; 749 queue->cw_min = 5;
658 queue->cw_max = 10; 750 queue->cw_max = 10;
diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.h b/drivers/net/wireless/rt2x00/rt2x00queue.h
index ff78e52ce43c..9dbf04f0f04c 100644
--- a/drivers/net/wireless/rt2x00/rt2x00queue.h
+++ b/drivers/net/wireless/rt2x00/rt2x00queue.h
@@ -87,10 +87,13 @@ enum data_queue_qid {
87 * 87 *
88 * @SKBDESC_DMA_MAPPED_RX: &skb_dma field has been mapped for RX 88 * @SKBDESC_DMA_MAPPED_RX: &skb_dma field has been mapped for RX
89 * @SKBDESC_DMA_MAPPED_TX: &skb_dma field has been mapped for TX 89 * @SKBDESC_DMA_MAPPED_TX: &skb_dma field has been mapped for TX
90 * @FRAME_DESC_IV_STRIPPED: Frame contained a IV/EIV provided by
91 * mac80211 but was stripped for processing by the driver.
90 */ 92 */
91enum skb_frame_desc_flags { 93enum skb_frame_desc_flags {
92 SKBDESC_DMA_MAPPED_RX = (1 << 0), 94 SKBDESC_DMA_MAPPED_RX = 1 << 0,
93 SKBDESC_DMA_MAPPED_TX = (1 << 1), 95 SKBDESC_DMA_MAPPED_TX = 1 << 1,
96 FRAME_DESC_IV_STRIPPED = 1 << 2,
94}; 97};
95 98
96/** 99/**
@@ -104,6 +107,8 @@ enum skb_frame_desc_flags {
104 * @desc: Pointer to descriptor part of the frame. 107 * @desc: Pointer to descriptor part of the frame.
105 * Note that this pointer could point to something outside 108 * Note that this pointer could point to something outside
106 * of the scope of the skb->data pointer. 109 * of the scope of the skb->data pointer.
110 * @iv: IV data used during encryption/decryption.
111 * @eiv: EIV data used during encryption/decryption.
107 * @skb_dma: (PCI-only) the DMA address associated with the sk buffer. 112 * @skb_dma: (PCI-only) the DMA address associated with the sk buffer.
108 * @entry: The entry to which this sk buffer belongs. 113 * @entry: The entry to which this sk buffer belongs.
109 */ 114 */
@@ -113,6 +118,9 @@ struct skb_frame_desc {
113 unsigned int desc_len; 118 unsigned int desc_len;
114 void *desc; 119 void *desc;
115 120
121 __le32 iv;
122 __le32 eiv;
123
116 dma_addr_t skb_dma; 124 dma_addr_t skb_dma;
117 125
118 struct queue_entry *entry; 126 struct queue_entry *entry;
@@ -132,13 +140,14 @@ static inline struct skb_frame_desc* get_skb_frame_desc(struct sk_buff *skb)
132/** 140/**
133 * enum rxdone_entry_desc_flags: Flags for &struct rxdone_entry_desc 141 * enum rxdone_entry_desc_flags: Flags for &struct rxdone_entry_desc
134 * 142 *
135 * @RXDONE_SIGNAL_PLCP: Does the signal field contain the plcp value, 143 * @RXDONE_SIGNAL_PLCP: Signal field contains the plcp value.
136 * or does it contain the bitrate itself. 144 * @RXDONE_SIGNAL_BITRATE: Signal field contains the bitrate value.
137 * @RXDONE_MY_BSS: Does this frame originate from device's BSS. 145 * @RXDONE_MY_BSS: Does this frame originate from device's BSS.
138 */ 146 */
139enum rxdone_entry_desc_flags { 147enum rxdone_entry_desc_flags {
140 RXDONE_SIGNAL_PLCP = 1 << 0, 148 RXDONE_SIGNAL_PLCP = 1 << 0,
141 RXDONE_MY_BSS = 1 << 1, 149 RXDONE_SIGNAL_BITRATE = 1 << 1,
150 RXDONE_MY_BSS = 1 << 2,
142}; 151};
143 152
144/** 153/**
@@ -152,7 +161,11 @@ enum rxdone_entry_desc_flags {
152 * @size: Data size of the received frame. 161 * @size: Data size of the received frame.
153 * @flags: MAC80211 receive flags (See &enum mac80211_rx_flags). 162 * @flags: MAC80211 receive flags (See &enum mac80211_rx_flags).
154 * @dev_flags: Ralink receive flags (See &enum rxdone_entry_desc_flags). 163 * @dev_flags: Ralink receive flags (See &enum rxdone_entry_desc_flags).
155 164 * @cipher: Cipher type used during decryption.
165 * @cipher_status: Decryption status.
166 * @iv: IV data used during decryption.
167 * @eiv: EIV data used during decryption.
168 * @icv: ICV data used during decryption.
156 */ 169 */
157struct rxdone_entry_desc { 170struct rxdone_entry_desc {
158 u64 timestamp; 171 u64 timestamp;
@@ -161,6 +174,12 @@ struct rxdone_entry_desc {
161 int size; 174 int size;
162 int flags; 175 int flags;
163 int dev_flags; 176 int dev_flags;
177 u8 cipher;
178 u8 cipher_status;
179
180 __le32 iv;
181 __le32 eiv;
182 __le32 icv;
164}; 183};
165 184
166/** 185/**
@@ -206,6 +225,10 @@ struct txdone_entry_desc {
206 * @ENTRY_TXD_BURST: This frame belongs to the same burst event. 225 * @ENTRY_TXD_BURST: This frame belongs to the same burst event.
207 * @ENTRY_TXD_ACK: An ACK is required for this frame. 226 * @ENTRY_TXD_ACK: An ACK is required for this frame.
208 * @ENTRY_TXD_RETRY_MODE: When set, the long retry count is used. 227 * @ENTRY_TXD_RETRY_MODE: When set, the long retry count is used.
228 * @ENTRY_TXD_ENCRYPT: This frame should be encrypted.
229 * @ENTRY_TXD_ENCRYPT_PAIRWISE: Use pairwise key table (instead of shared).
230 * @ENTRY_TXD_ENCRYPT_IV: Generate IV/EIV in hardware.
231 * @ENTRY_TXD_ENCRYPT_MMIC: Generate MIC in hardware.
209 */ 232 */
210enum txentry_desc_flags { 233enum txentry_desc_flags {
211 ENTRY_TXD_RTS_FRAME, 234 ENTRY_TXD_RTS_FRAME,
@@ -218,6 +241,10 @@ enum txentry_desc_flags {
218 ENTRY_TXD_BURST, 241 ENTRY_TXD_BURST,
219 ENTRY_TXD_ACK, 242 ENTRY_TXD_ACK,
220 ENTRY_TXD_RETRY_MODE, 243 ENTRY_TXD_RETRY_MODE,
244 ENTRY_TXD_ENCRYPT,
245 ENTRY_TXD_ENCRYPT_PAIRWISE,
246 ENTRY_TXD_ENCRYPT_IV,
247 ENTRY_TXD_ENCRYPT_MMIC,
221}; 248};
222 249
223/** 250/**
@@ -236,6 +263,9 @@ enum txentry_desc_flags {
236 * @ifs: IFS value. 263 * @ifs: IFS value.
237 * @cw_min: cwmin value. 264 * @cw_min: cwmin value.
238 * @cw_max: cwmax value. 265 * @cw_max: cwmax value.
266 * @cipher: Cipher type used for encryption.
267 * @key_idx: Key index used for encryption.
268 * @iv_offset: Position where IV should be inserted by hardware.
239 */ 269 */
240struct txentry_desc { 270struct txentry_desc {
241 unsigned long flags; 271 unsigned long flags;
@@ -252,6 +282,10 @@ struct txentry_desc {
252 short ifs; 282 short ifs;
253 short cw_min; 283 short cw_min;
254 short cw_max; 284 short cw_max;
285
286 enum cipher cipher;
287 u16 key_idx;
288 u16 iv_offset;
255}; 289};
256 290
257/** 291/**
@@ -335,6 +369,7 @@ enum queue_index {
335 * @length: Number of frames in queue. 369 * @length: Number of frames in queue.
336 * @index: Index pointers to entry positions in the queue, 370 * @index: Index pointers to entry positions in the queue,
337 * use &enum queue_index to get a specific index field. 371 * use &enum queue_index to get a specific index field.
372 * @txop: maximum burst time.
338 * @aifs: The aifs value for outgoing frames (field ignored in RX queue). 373 * @aifs: The aifs value for outgoing frames (field ignored in RX queue).
339 * @cw_min: The cw min value for outgoing frames (field ignored in RX queue). 374 * @cw_min: The cw min value for outgoing frames (field ignored in RX queue).
340 * @cw_max: The cw max value for outgoing frames (field ignored in RX queue). 375 * @cw_max: The cw max value for outgoing frames (field ignored in RX queue).
@@ -354,6 +389,7 @@ struct data_queue {
354 unsigned short length; 389 unsigned short length;
355 unsigned short index[Q_INDEX_MAX]; 390 unsigned short index[Q_INDEX_MAX];
356 391
392 unsigned short txop;
357 unsigned short aifs; 393 unsigned short aifs;
358 unsigned short cw_min; 394 unsigned short cw_min;
359 unsigned short cw_max; 395 unsigned short cw_max;
@@ -484,25 +520,51 @@ static inline int rt2x00queue_threshold(struct data_queue *queue)
484} 520}
485 521
486/** 522/**
487 * rt2x00_desc_read - Read a word from the hardware descriptor. 523 * _rt2x00_desc_read - Read a word from the hardware descriptor.
524 * @desc: Base descriptor address
525 * @word: Word index from where the descriptor should be read.
526 * @value: Address where the descriptor value should be written into.
527 */
528static inline void _rt2x00_desc_read(__le32 *desc, const u8 word, __le32 *value)
529{
530 *value = desc[word];
531}
532
533/**
534 * rt2x00_desc_read - Read a word from the hardware descriptor, this
535 * function will take care of the byte ordering.
488 * @desc: Base descriptor address 536 * @desc: Base descriptor address
489 * @word: Word index from where the descriptor should be read. 537 * @word: Word index from where the descriptor should be read.
490 * @value: Address where the descriptor value should be written into. 538 * @value: Address where the descriptor value should be written into.
491 */ 539 */
492static inline void rt2x00_desc_read(__le32 *desc, const u8 word, u32 *value) 540static inline void rt2x00_desc_read(__le32 *desc, const u8 word, u32 *value)
493{ 541{
494 *value = le32_to_cpu(desc[word]); 542 __le32 tmp;
543 _rt2x00_desc_read(desc, word, &tmp);
544 *value = le32_to_cpu(tmp);
545}
546
547/**
548 * rt2x00_desc_write - write a word to the hardware descriptor, this
549 * function will take care of the byte ordering.
550 * @desc: Base descriptor address
551 * @word: Word index from where the descriptor should be written.
552 * @value: Value that should be written into the descriptor.
553 */
554static inline void _rt2x00_desc_write(__le32 *desc, const u8 word, __le32 value)
555{
556 desc[word] = value;
495} 557}
496 558
497/** 559/**
498 * rt2x00_desc_write - wrote a word to the hardware descriptor. 560 * rt2x00_desc_write - write a word to the hardware descriptor.
499 * @desc: Base descriptor address 561 * @desc: Base descriptor address
500 * @word: Word index from where the descriptor should be written. 562 * @word: Word index from where the descriptor should be written.
501 * @value: Value that should be written into the descriptor. 563 * @value: Value that should be written into the descriptor.
502 */ 564 */
503static inline void rt2x00_desc_write(__le32 *desc, const u8 word, u32 value) 565static inline void rt2x00_desc_write(__le32 *desc, const u8 word, u32 value)
504{ 566{
505 desc[word] = cpu_to_le32(value); 567 _rt2x00_desc_write(desc, word, cpu_to_le32(value));
506} 568}
507 569
508#endif /* RT2X00QUEUE_H */ 570#endif /* RT2X00QUEUE_H */
diff --git a/drivers/net/wireless/rt2x00/rt2x00reg.h b/drivers/net/wireless/rt2x00/rt2x00reg.h
index 2ea7866abd5d..c2fba7c9f05c 100644
--- a/drivers/net/wireless/rt2x00/rt2x00reg.h
+++ b/drivers/net/wireless/rt2x00/rt2x00reg.h
@@ -27,6 +27,16 @@
27#define RT2X00REG_H 27#define RT2X00REG_H
28 28
29/* 29/*
30 * RX crypto status
31 */
32enum rx_crypto {
33 RX_CRYPTO_SUCCESS = 0,
34 RX_CRYPTO_FAIL_ICV = 1,
35 RX_CRYPTO_FAIL_MIC = 2,
36 RX_CRYPTO_FAIL_KEY = 3,
37};
38
39/*
30 * Antenna values 40 * Antenna values
31 */ 41 */
32enum antenna { 42enum antenna {
@@ -104,7 +114,14 @@ enum cipher {
104 */ 114 */
105 CIPHER_CKIP64 = 5, 115 CIPHER_CKIP64 = 5,
106 CIPHER_CKIP128 = 6, 116 CIPHER_CKIP128 = 6,
107 CIPHER_TKIP_NO_MIC = 7, 117 CIPHER_TKIP_NO_MIC = 7, /* Don't send to device */
118
119/*
120 * Max cipher type.
121 * Note that CIPHER_NONE isn't counted, and CKIP64 and CKIP128
122 * are excluded due to limitations in mac80211.
123 */
124 CIPHER_MAX = 4,
108}; 125};
109 126
110/* 127/*
diff --git a/drivers/net/wireless/rt2x00/rt2x00rfkill.c b/drivers/net/wireless/rt2x00/rt2x00rfkill.c
index 04b29716d356..c3f53a92180a 100644
--- a/drivers/net/wireless/rt2x00/rt2x00rfkill.c
+++ b/drivers/net/wireless/rt2x00/rt2x00rfkill.c
@@ -41,20 +41,19 @@ static int rt2x00rfkill_toggle_radio(void *data, enum rfkill_state state)
41 /* 41 /*
42 * Only continue if there are enabled interfaces. 42 * Only continue if there are enabled interfaces.
43 */ 43 */
44 if (!test_bit(DEVICE_STARTED, &rt2x00dev->flags)) 44 if (!test_bit(DEVICE_STATE_STARTED, &rt2x00dev->flags))
45 return 0; 45 return 0;
46 46
47 if (state == RFKILL_STATE_UNBLOCKED) { 47 if (state == RFKILL_STATE_UNBLOCKED) {
48 INFO(rt2x00dev, "Hardware button pressed, enabling radio.\n"); 48 INFO(rt2x00dev, "RFKILL event: enabling radio.\n");
49 __clear_bit(DEVICE_DISABLED_RADIO_HW, &rt2x00dev->flags); 49 clear_bit(DEVICE_STATE_DISABLED_RADIO_HW, &rt2x00dev->flags);
50 retval = rt2x00lib_enable_radio(rt2x00dev); 50 retval = rt2x00lib_enable_radio(rt2x00dev);
51 } else if (state == RFKILL_STATE_SOFT_BLOCKED) { 51 } else if (state == RFKILL_STATE_SOFT_BLOCKED) {
52 INFO(rt2x00dev, "Hardware button pressed, disabling radio.\n"); 52 INFO(rt2x00dev, "RFKILL event: disabling radio.\n");
53 __set_bit(DEVICE_DISABLED_RADIO_HW, &rt2x00dev->flags); 53 set_bit(DEVICE_STATE_DISABLED_RADIO_HW, &rt2x00dev->flags);
54 rt2x00lib_disable_radio(rt2x00dev); 54 rt2x00lib_disable_radio(rt2x00dev);
55 } else { 55 } else {
56 WARNING(rt2x00dev, "Received unexpected rfkill state %d.\n", 56 WARNING(rt2x00dev, "RFKILL event: unknown state %d.\n", state);
57 state);
58 } 57 }
59 58
60 return retval; 59 return retval;
@@ -64,7 +63,12 @@ static int rt2x00rfkill_get_state(void *data, enum rfkill_state *state)
64{ 63{
65 struct rt2x00_dev *rt2x00dev = data; 64 struct rt2x00_dev *rt2x00dev = data;
66 65
67 *state = rt2x00dev->rfkill->state; 66 /*
67 * rfkill_poll reports 1 when the key has been pressed and the
68 * radio should be blocked.
69 */
70 *state = rt2x00dev->ops->lib->rfkill_poll(rt2x00dev) ?
71 RFKILL_STATE_SOFT_BLOCKED : RFKILL_STATE_UNBLOCKED;
68 72
69 return 0; 73 return 0;
70} 74}
@@ -73,19 +77,18 @@ static void rt2x00rfkill_poll(struct work_struct *work)
73{ 77{
74 struct rt2x00_dev *rt2x00dev = 78 struct rt2x00_dev *rt2x00dev =
75 container_of(work, struct rt2x00_dev, rfkill_work.work); 79 container_of(work, struct rt2x00_dev, rfkill_work.work);
76 int state; 80 enum rfkill_state state;
77 81
78 if (!test_bit(RFKILL_STATE_REGISTERED, &rt2x00dev->rfkill_state)) 82 if (!test_bit(RFKILL_STATE_REGISTERED, &rt2x00dev->rfkill_state) ||
83 !test_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags))
79 return; 84 return;
80 85
81 /* 86 /*
82 * rfkill_poll reports 1 when the key has been pressed and the 87 * Poll latest state and report it to rfkill who should sort
83 * radio should be blocked. 88 * out if the state should be toggled or not.
84 */ 89 */
85 state = !rt2x00dev->ops->lib->rfkill_poll(rt2x00dev) ? 90 if (!rt2x00rfkill_get_state(rt2x00dev, &state))
86 RFKILL_STATE_UNBLOCKED : RFKILL_STATE_SOFT_BLOCKED; 91 rfkill_force_state(rt2x00dev->rfkill, state);
87
88 rfkill_force_state(rt2x00dev->rfkill, state);
89 92
90 queue_delayed_work(rt2x00dev->hw->workqueue, 93 queue_delayed_work(rt2x00dev->hw->workqueue,
91 &rt2x00dev->rfkill_work, RFKILL_POLL_INTERVAL); 94 &rt2x00dev->rfkill_work, RFKILL_POLL_INTERVAL);
@@ -93,8 +96,8 @@ static void rt2x00rfkill_poll(struct work_struct *work)
93 96
94void rt2x00rfkill_register(struct rt2x00_dev *rt2x00dev) 97void rt2x00rfkill_register(struct rt2x00_dev *rt2x00dev)
95{ 98{
96 if (!test_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags) || 99 if (!test_bit(RFKILL_STATE_ALLOCATED, &rt2x00dev->rfkill_state) ||
97 !test_bit(RFKILL_STATE_ALLOCATED, &rt2x00dev->rfkill_state)) 100 test_bit(RFKILL_STATE_REGISTERED, &rt2x00dev->rfkill_state))
98 return; 101 return;
99 102
100 if (rfkill_register(rt2x00dev->rfkill)) { 103 if (rfkill_register(rt2x00dev->rfkill)) {
@@ -114,7 +117,7 @@ void rt2x00rfkill_register(struct rt2x00_dev *rt2x00dev)
114 117
115void rt2x00rfkill_unregister(struct rt2x00_dev *rt2x00dev) 118void rt2x00rfkill_unregister(struct rt2x00_dev *rt2x00dev)
116{ 119{
117 if (!test_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags) || 120 if (!test_bit(RFKILL_STATE_ALLOCATED, &rt2x00dev->rfkill_state) ||
118 !test_bit(RFKILL_STATE_REGISTERED, &rt2x00dev->rfkill_state)) 121 !test_bit(RFKILL_STATE_REGISTERED, &rt2x00dev->rfkill_state))
119 return; 122 return;
120 123
@@ -127,21 +130,30 @@ void rt2x00rfkill_unregister(struct rt2x00_dev *rt2x00dev)
127 130
128void rt2x00rfkill_allocate(struct rt2x00_dev *rt2x00dev) 131void rt2x00rfkill_allocate(struct rt2x00_dev *rt2x00dev)
129{ 132{
130 if (!test_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags)) 133 struct device *dev = wiphy_dev(rt2x00dev->hw->wiphy);
134
135 if (test_bit(RFKILL_STATE_ALLOCATED, &rt2x00dev->rfkill_state))
131 return; 136 return;
132 137
133 rt2x00dev->rfkill = 138 rt2x00dev->rfkill = rfkill_allocate(dev, RFKILL_TYPE_WLAN);
134 rfkill_allocate(wiphy_dev(rt2x00dev->hw->wiphy), RFKILL_TYPE_WLAN);
135 if (!rt2x00dev->rfkill) { 139 if (!rt2x00dev->rfkill) {
136 ERROR(rt2x00dev, "Failed to allocate rfkill handler.\n"); 140 ERROR(rt2x00dev, "Failed to allocate rfkill handler.\n");
137 return; 141 return;
138 } 142 }
139 143
144 __set_bit(RFKILL_STATE_ALLOCATED, &rt2x00dev->rfkill_state);
145
140 rt2x00dev->rfkill->name = rt2x00dev->ops->name; 146 rt2x00dev->rfkill->name = rt2x00dev->ops->name;
141 rt2x00dev->rfkill->data = rt2x00dev; 147 rt2x00dev->rfkill->data = rt2x00dev;
142 rt2x00dev->rfkill->state = -1;
143 rt2x00dev->rfkill->toggle_radio = rt2x00rfkill_toggle_radio; 148 rt2x00dev->rfkill->toggle_radio = rt2x00rfkill_toggle_radio;
144 rt2x00dev->rfkill->get_state = rt2x00rfkill_get_state; 149 if (test_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags)) {
150 rt2x00dev->rfkill->get_state = rt2x00rfkill_get_state;
151 rt2x00dev->rfkill->state =
152 rt2x00dev->ops->lib->rfkill_poll(rt2x00dev) ?
153 RFKILL_STATE_SOFT_BLOCKED : RFKILL_STATE_UNBLOCKED;
154 } else {
155 rt2x00dev->rfkill->state = RFKILL_STATE_UNBLOCKED;
156 }
145 157
146 INIT_DELAYED_WORK(&rt2x00dev->rfkill_work, rt2x00rfkill_poll); 158 INIT_DELAYED_WORK(&rt2x00dev->rfkill_work, rt2x00rfkill_poll);
147 159
@@ -150,8 +162,7 @@ void rt2x00rfkill_allocate(struct rt2x00_dev *rt2x00dev)
150 162
151void rt2x00rfkill_free(struct rt2x00_dev *rt2x00dev) 163void rt2x00rfkill_free(struct rt2x00_dev *rt2x00dev)
152{ 164{
153 if (!test_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags) || 165 if (!test_bit(RFKILL_STATE_ALLOCATED, &rt2x00dev->flags))
154 !test_bit(RFKILL_STATE_ALLOCATED, &rt2x00dev->rfkill_state))
155 return; 166 return;
156 167
157 cancel_delayed_work_sync(&rt2x00dev->rfkill_work); 168 cancel_delayed_work_sync(&rt2x00dev->rfkill_work);
diff --git a/drivers/net/wireless/rt2x00/rt2x00usb.c b/drivers/net/wireless/rt2x00/rt2x00usb.c
index 2050227ea530..b73a7e0aeed4 100644
--- a/drivers/net/wireless/rt2x00/rt2x00usb.c
+++ b/drivers/net/wireless/rt2x00/rt2x00usb.c
@@ -163,16 +163,11 @@ static void rt2x00usb_interrupt_txdone(struct urb *urb)
163 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev; 163 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
164 struct txdone_entry_desc txdesc; 164 struct txdone_entry_desc txdesc;
165 165
166 if (!test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags) || 166 if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags) ||
167 !test_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags)) 167 !test_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags))
168 return; 168 return;
169 169
170 /* 170 /*
171 * Remove the descriptor data from the buffer.
172 */
173 skb_pull(entry->skb, entry->queue->desc_size);
174
175 /*
176 * Obtain the status about this packet. 171 * Obtain the status about this packet.
177 * Note that when the status is 0 it does not mean the 172 * Note that when the status is 0 it does not mean the
178 * frame was send out correctly. It only means the frame 173 * frame was send out correctly. It only means the frame
@@ -224,6 +219,12 @@ int rt2x00usb_write_tx_data(struct queue_entry *entry)
224 entry->skb->data, length, 219 entry->skb->data, length,
225 rt2x00usb_interrupt_txdone, entry); 220 rt2x00usb_interrupt_txdone, entry);
226 221
222 /*
223 * Make sure the skb->data pointer points to the frame, not the
224 * descriptor.
225 */
226 skb_pull(entry->skb, entry->queue->desc_size);
227
227 return 0; 228 return 0;
228} 229}
229EXPORT_SYMBOL_GPL(rt2x00usb_write_tx_data); 230EXPORT_SYMBOL_GPL(rt2x00usb_write_tx_data);
@@ -232,7 +233,7 @@ static inline void rt2x00usb_kick_tx_entry(struct queue_entry *entry)
232{ 233{
233 struct queue_entry_priv_usb *entry_priv = entry->priv_data; 234 struct queue_entry_priv_usb *entry_priv = entry->priv_data;
234 235
235 if (__test_and_clear_bit(ENTRY_DATA_PENDING, &entry->flags)) 236 if (test_and_clear_bit(ENTRY_DATA_PENDING, &entry->flags))
236 usb_submit_urb(entry_priv->urb, GFP_ATOMIC); 237 usb_submit_urb(entry_priv->urb, GFP_ATOMIC);
237} 238}
238 239
@@ -283,7 +284,7 @@ static void rt2x00usb_interrupt_rxdone(struct urb *urb)
283 struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb); 284 struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
284 u8 rxd[32]; 285 u8 rxd[32];
285 286
286 if (!test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags) || 287 if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags) ||
287 !test_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags)) 288 !test_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags))
288 return; 289 return;
289 290
@@ -293,7 +294,7 @@ static void rt2x00usb_interrupt_rxdone(struct urb *urb)
293 * a problem. 294 * a problem.
294 */ 295 */
295 if (urb->actual_length < entry->queue->desc_size || urb->status) { 296 if (urb->actual_length < entry->queue->desc_size || urb->status) {
296 __set_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags); 297 set_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags);
297 usb_submit_urb(urb, GFP_ATOMIC); 298 usb_submit_urb(urb, GFP_ATOMIC);
298 return; 299 return;
299 } 300 }
@@ -361,7 +362,7 @@ void rt2x00usb_init_rxentry(struct rt2x00_dev *rt2x00dev,
361 entry->skb->data, entry->skb->len, 362 entry->skb->data, entry->skb->len,
362 rt2x00usb_interrupt_rxdone, entry); 363 rt2x00usb_interrupt_rxdone, entry);
363 364
364 __set_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags); 365 set_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags);
365 usb_submit_urb(entry_priv->urb, GFP_ATOMIC); 366 usb_submit_urb(entry_priv->urb, GFP_ATOMIC);
366} 367}
367EXPORT_SYMBOL_GPL(rt2x00usb_init_rxentry); 368EXPORT_SYMBOL_GPL(rt2x00usb_init_rxentry);
diff --git a/drivers/net/wireless/rt2x00/rt61pci.c b/drivers/net/wireless/rt2x00/rt61pci.c
index 087e90b328cd..a461620b489f 100644
--- a/drivers/net/wireless/rt2x00/rt61pci.c
+++ b/drivers/net/wireless/rt2x00/rt61pci.c
@@ -38,6 +38,13 @@
38#include "rt61pci.h" 38#include "rt61pci.h"
39 39
40/* 40/*
41 * Allow hardware encryption to be disabled.
42 */
43static int modparam_nohwcrypt = 0;
44module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO);
45MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
46
47/*
41 * Register access. 48 * Register access.
42 * BBP and RF register require indirect register access, 49 * BBP and RF register require indirect register access,
43 * and use the CSR registers PHY_CSR3 and PHY_CSR4 to achieve this. 50 * and use the CSR registers PHY_CSR3 and PHY_CSR4 to achieve this.
@@ -156,7 +163,7 @@ rf_write:
156 rt2x00_rf_write(rt2x00dev, word, value); 163 rt2x00_rf_write(rt2x00dev, word, value);
157} 164}
158 165
159#ifdef CONFIG_RT61PCI_LEDS 166#ifdef CONFIG_RT2X00_LIB_LEDS
160/* 167/*
161 * This function is only called from rt61pci_led_brightness() 168 * This function is only called from rt61pci_led_brightness()
162 * make gcc happy by placing this function inside the 169 * make gcc happy by placing this function inside the
@@ -188,7 +195,7 @@ static void rt61pci_mcu_request(struct rt2x00_dev *rt2x00dev,
188 rt2x00_set_field32(&reg, HOST_CMD_CSR_INTERRUPT_MCU, 1); 195 rt2x00_set_field32(&reg, HOST_CMD_CSR_INTERRUPT_MCU, 1);
189 rt2x00pci_register_write(rt2x00dev, HOST_CMD_CSR, reg); 196 rt2x00pci_register_write(rt2x00dev, HOST_CMD_CSR, reg);
190} 197}
191#endif /* CONFIG_RT61PCI_LEDS */ 198#endif /* CONFIG_RT2X00_LIB_LEDS */
192 199
193static void rt61pci_eepromregister_read(struct eeprom_93cx6 *eeprom) 200static void rt61pci_eepromregister_read(struct eeprom_93cx6 *eeprom)
194{ 201{
@@ -264,7 +271,7 @@ static const struct rt2x00debug rt61pci_rt2x00debug = {
264}; 271};
265#endif /* CONFIG_RT2X00_LIB_DEBUGFS */ 272#endif /* CONFIG_RT2X00_LIB_DEBUGFS */
266 273
267#ifdef CONFIG_RT61PCI_RFKILL 274#ifdef CONFIG_RT2X00_LIB_RFKILL
268static int rt61pci_rfkill_poll(struct rt2x00_dev *rt2x00dev) 275static int rt61pci_rfkill_poll(struct rt2x00_dev *rt2x00dev)
269{ 276{
270 u32 reg; 277 u32 reg;
@@ -274,9 +281,9 @@ static int rt61pci_rfkill_poll(struct rt2x00_dev *rt2x00dev)
274} 281}
275#else 282#else
276#define rt61pci_rfkill_poll NULL 283#define rt61pci_rfkill_poll NULL
277#endif /* CONFIG_RT61PCI_RFKILL */ 284#endif /* CONFIG_RT2X00_LIB_RFKILL */
278 285
279#ifdef CONFIG_RT61PCI_LEDS 286#ifdef CONFIG_RT2X00_LIB_LEDS
280static void rt61pci_brightness_set(struct led_classdev *led_cdev, 287static void rt61pci_brightness_set(struct led_classdev *led_cdev,
281 enum led_brightness brightness) 288 enum led_brightness brightness)
282{ 289{
@@ -341,11 +348,209 @@ static void rt61pci_init_led(struct rt2x00_dev *rt2x00dev,
341 led->led_dev.blink_set = rt61pci_blink_set; 348 led->led_dev.blink_set = rt61pci_blink_set;
342 led->flags = LED_INITIALIZED; 349 led->flags = LED_INITIALIZED;
343} 350}
344#endif /* CONFIG_RT61PCI_LEDS */ 351#endif /* CONFIG_RT2X00_LIB_LEDS */
345 352
346/* 353/*
347 * Configuration handlers. 354 * Configuration handlers.
348 */ 355 */
356static int rt61pci_config_shared_key(struct rt2x00_dev *rt2x00dev,
357 struct rt2x00lib_crypto *crypto,
358 struct ieee80211_key_conf *key)
359{
360 struct hw_key_entry key_entry;
361 struct rt2x00_field32 field;
362 u32 mask;
363 u32 reg;
364
365 if (crypto->cmd == SET_KEY) {
366 /*
367 * rt2x00lib can't determine the correct free
368 * key_idx for shared keys. We have 1 register
369 * with key valid bits. The goal is simple, read
370 * the register, if that is full we have no slots
371 * left.
372 * Note that each BSS is allowed to have up to 4
373 * shared keys, so put a mask over the allowed
374 * entries.
375 */
376 mask = (0xf << crypto->bssidx);
377
378 rt2x00pci_register_read(rt2x00dev, SEC_CSR0, &reg);
379 reg &= mask;
380
381 if (reg && reg == mask)
382 return -ENOSPC;
383
384 key->hw_key_idx += reg ? ffz(reg) : 0;
385
386 /*
387 * Upload key to hardware
388 */
389 memcpy(key_entry.key, crypto->key,
390 sizeof(key_entry.key));
391 memcpy(key_entry.tx_mic, crypto->tx_mic,
392 sizeof(key_entry.tx_mic));
393 memcpy(key_entry.rx_mic, crypto->rx_mic,
394 sizeof(key_entry.rx_mic));
395
396 reg = SHARED_KEY_ENTRY(key->hw_key_idx);
397 rt2x00pci_register_multiwrite(rt2x00dev, reg,
398 &key_entry, sizeof(key_entry));
399
400 /*
401 * The cipher types are stored over 2 registers.
402 * bssidx 0 and 1 keys are stored in SEC_CSR1 and
403 * bssidx 1 and 2 keys are stored in SEC_CSR5.
404 * Using the correct defines correctly will cause overhead,
405 * so just calculate the correct offset.
406 */
407 if (key->hw_key_idx < 8) {
408 field.bit_offset = (3 * key->hw_key_idx);
409 field.bit_mask = 0x7 << field.bit_offset;
410
411 rt2x00pci_register_read(rt2x00dev, SEC_CSR1, &reg);
412 rt2x00_set_field32(&reg, field, crypto->cipher);
413 rt2x00pci_register_write(rt2x00dev, SEC_CSR1, reg);
414 } else {
415 field.bit_offset = (3 * (key->hw_key_idx - 8));
416 field.bit_mask = 0x7 << field.bit_offset;
417
418 rt2x00pci_register_read(rt2x00dev, SEC_CSR5, &reg);
419 rt2x00_set_field32(&reg, field, crypto->cipher);
420 rt2x00pci_register_write(rt2x00dev, SEC_CSR5, reg);
421 }
422
423 /*
424 * The driver does not support the IV/EIV generation
425 * in hardware. However it doesn't support the IV/EIV
426 * inside the ieee80211 frame either, but requires it
427 * to be provided seperately for the descriptor.
428 * rt2x00lib will cut the IV/EIV data out of all frames
429 * given to us by mac80211, but we must tell mac80211
430 * to generate the IV/EIV data.
431 */
432 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
433 }
434
435 /*
436 * SEC_CSR0 contains only single-bit fields to indicate
437 * a particular key is valid. Because using the FIELD32()
438 * defines directly will cause a lot of overhead we use
439 * a calculation to determine the correct bit directly.
440 */
441 mask = 1 << key->hw_key_idx;
442
443 rt2x00pci_register_read(rt2x00dev, SEC_CSR0, &reg);
444 if (crypto->cmd == SET_KEY)
445 reg |= mask;
446 else if (crypto->cmd == DISABLE_KEY)
447 reg &= ~mask;
448 rt2x00pci_register_write(rt2x00dev, SEC_CSR0, reg);
449
450 return 0;
451}
452
453static int rt61pci_config_pairwise_key(struct rt2x00_dev *rt2x00dev,
454 struct rt2x00lib_crypto *crypto,
455 struct ieee80211_key_conf *key)
456{
457 struct hw_pairwise_ta_entry addr_entry;
458 struct hw_key_entry key_entry;
459 u32 mask;
460 u32 reg;
461
462 if (crypto->cmd == SET_KEY) {
463 /*
464 * rt2x00lib can't determine the correct free
465 * key_idx for pairwise keys. We have 2 registers
466 * with key valid bits. The goal is simple, read
467 * the first register, if that is full move to
468 * the next register.
469 * When both registers are full, we drop the key,
470 * otherwise we use the first invalid entry.
471 */
472 rt2x00pci_register_read(rt2x00dev, SEC_CSR2, &reg);
473 if (reg && reg == ~0) {
474 key->hw_key_idx = 32;
475 rt2x00pci_register_read(rt2x00dev, SEC_CSR3, &reg);
476 if (reg && reg == ~0)
477 return -ENOSPC;
478 }
479
480 key->hw_key_idx += reg ? ffz(reg) : 0;
481
482 /*
483 * Upload key to hardware
484 */
485 memcpy(key_entry.key, crypto->key,
486 sizeof(key_entry.key));
487 memcpy(key_entry.tx_mic, crypto->tx_mic,
488 sizeof(key_entry.tx_mic));
489 memcpy(key_entry.rx_mic, crypto->rx_mic,
490 sizeof(key_entry.rx_mic));
491
492 memset(&addr_entry, 0, sizeof(addr_entry));
493 memcpy(&addr_entry, crypto->address, ETH_ALEN);
494 addr_entry.cipher = crypto->cipher;
495
496 reg = PAIRWISE_KEY_ENTRY(key->hw_key_idx);
497 rt2x00pci_register_multiwrite(rt2x00dev, reg,
498 &key_entry, sizeof(key_entry));
499
500 reg = PAIRWISE_TA_ENTRY(key->hw_key_idx);
501 rt2x00pci_register_multiwrite(rt2x00dev, reg,
502 &addr_entry, sizeof(addr_entry));
503
504 /*
505 * Enable pairwise lookup table for given BSS idx,
506 * without this received frames will not be decrypted
507 * by the hardware.
508 */
509 rt2x00pci_register_read(rt2x00dev, SEC_CSR4, &reg);
510 reg |= (1 << crypto->bssidx);
511 rt2x00pci_register_write(rt2x00dev, SEC_CSR4, reg);
512
513 /*
514 * The driver does not support the IV/EIV generation
515 * in hardware. However it doesn't support the IV/EIV
516 * inside the ieee80211 frame either, but requires it
517 * to be provided seperately for the descriptor.
518 * rt2x00lib will cut the IV/EIV data out of all frames
519 * given to us by mac80211, but we must tell mac80211
520 * to generate the IV/EIV data.
521 */
522 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
523 }
524
525 /*
526 * SEC_CSR2 and SEC_CSR3 contain only single-bit fields to indicate
527 * a particular key is valid. Because using the FIELD32()
528 * defines directly will cause a lot of overhead we use
529 * a calculation to determine the correct bit directly.
530 */
531 if (key->hw_key_idx < 32) {
532 mask = 1 << key->hw_key_idx;
533
534 rt2x00pci_register_read(rt2x00dev, SEC_CSR2, &reg);
535 if (crypto->cmd == SET_KEY)
536 reg |= mask;
537 else if (crypto->cmd == DISABLE_KEY)
538 reg &= ~mask;
539 rt2x00pci_register_write(rt2x00dev, SEC_CSR2, reg);
540 } else {
541 mask = 1 << (key->hw_key_idx - 32);
542
543 rt2x00pci_register_read(rt2x00dev, SEC_CSR3, &reg);
544 if (crypto->cmd == SET_KEY)
545 reg |= mask;
546 else if (crypto->cmd == DISABLE_KEY)
547 reg &= ~mask;
548 rt2x00pci_register_write(rt2x00dev, SEC_CSR3, reg);
549 }
550
551 return 0;
552}
553
349static void rt61pci_config_filter(struct rt2x00_dev *rt2x00dev, 554static void rt61pci_config_filter(struct rt2x00_dev *rt2x00dev,
350 const unsigned int filter_flags) 555 const unsigned int filter_flags)
351{ 556{
@@ -440,6 +645,30 @@ static void rt61pci_config_erp(struct rt2x00_dev *rt2x00dev,
440 rt2x00pci_register_write(rt2x00dev, TXRX_CSR4, reg); 645 rt2x00pci_register_write(rt2x00dev, TXRX_CSR4, reg);
441} 646}
442 647
648
649static void rt61pci_config_lna_gain(struct rt2x00_dev *rt2x00dev,
650 struct rt2x00lib_conf *libconf)
651{
652 u16 eeprom;
653 short lna_gain = 0;
654
655 if (libconf->band == IEEE80211_BAND_2GHZ) {
656 if (test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags))
657 lna_gain += 14;
658
659 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_BG, &eeprom);
660 lna_gain -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_BG_1);
661 } else {
662 if (test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags))
663 lna_gain += 14;
664
665 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_A, &eeprom);
666 lna_gain -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_A_1);
667 }
668
669 rt2x00dev->lna_gain = lna_gain;
670}
671
443static void rt61pci_config_phymode(struct rt2x00_dev *rt2x00dev, 672static void rt61pci_config_phymode(struct rt2x00_dev *rt2x00dev,
444 const int basic_rate_mask) 673 const int basic_rate_mask)
445{ 674{
@@ -758,6 +987,9 @@ static void rt61pci_config(struct rt2x00_dev *rt2x00dev,
758 struct rt2x00lib_conf *libconf, 987 struct rt2x00lib_conf *libconf,
759 const unsigned int flags) 988 const unsigned int flags)
760{ 989{
990 /* Always recalculate LNA gain before changing configuration */
991 rt61pci_config_lna_gain(rt2x00dev, libconf);
992
761 if (flags & CONFIG_UPDATE_PHYMODE) 993 if (flags & CONFIG_UPDATE_PHYMODE)
762 rt61pci_config_phymode(rt2x00dev, libconf->basic_rates); 994 rt61pci_config_phymode(rt2x00dev, libconf->basic_rates);
763 if (flags & CONFIG_UPDATE_CHANNEL) 995 if (flags & CONFIG_UPDATE_CHANNEL)
@@ -1246,16 +1478,6 @@ static int rt61pci_init_registers(struct rt2x00_dev *rt2x00dev)
1246 1478
1247 rt2x00pci_register_write(rt2x00dev, M2H_CMD_DONE_CSR, 0xffffffff); 1479 rt2x00pci_register_write(rt2x00dev, M2H_CMD_DONE_CSR, 0xffffffff);
1248 1480
1249 rt2x00pci_register_read(rt2x00dev, AC_TXOP_CSR0, &reg);
1250 rt2x00_set_field32(&reg, AC_TXOP_CSR0_AC0_TX_OP, 0);
1251 rt2x00_set_field32(&reg, AC_TXOP_CSR0_AC1_TX_OP, 0);
1252 rt2x00pci_register_write(rt2x00dev, AC_TXOP_CSR0, reg);
1253
1254 rt2x00pci_register_read(rt2x00dev, AC_TXOP_CSR1, &reg);
1255 rt2x00_set_field32(&reg, AC_TXOP_CSR1_AC2_TX_OP, 192);
1256 rt2x00_set_field32(&reg, AC_TXOP_CSR1_AC3_TX_OP, 48);
1257 rt2x00pci_register_write(rt2x00dev, AC_TXOP_CSR1, reg);
1258
1259 /* 1481 /*
1260 * Clear all beacons 1482 * Clear all beacons
1261 * For the Beacon base registers we only need to clear 1483 * For the Beacon base registers we only need to clear
@@ -1533,8 +1755,8 @@ static int rt61pci_set_device_state(struct rt2x00_dev *rt2x00dev,
1533 * TX descriptor initialization 1755 * TX descriptor initialization
1534 */ 1756 */
1535static void rt61pci_write_tx_desc(struct rt2x00_dev *rt2x00dev, 1757static void rt61pci_write_tx_desc(struct rt2x00_dev *rt2x00dev,
1536 struct sk_buff *skb, 1758 struct sk_buff *skb,
1537 struct txentry_desc *txdesc) 1759 struct txentry_desc *txdesc)
1538{ 1760{
1539 struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb); 1761 struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb);
1540 __le32 *txd = skbdesc->desc; 1762 __le32 *txd = skbdesc->desc;
@@ -1548,7 +1770,7 @@ static void rt61pci_write_tx_desc(struct rt2x00_dev *rt2x00dev,
1548 rt2x00_set_field32(&word, TXD_W1_AIFSN, txdesc->aifs); 1770 rt2x00_set_field32(&word, TXD_W1_AIFSN, txdesc->aifs);
1549 rt2x00_set_field32(&word, TXD_W1_CWMIN, txdesc->cw_min); 1771 rt2x00_set_field32(&word, TXD_W1_CWMIN, txdesc->cw_min);
1550 rt2x00_set_field32(&word, TXD_W1_CWMAX, txdesc->cw_max); 1772 rt2x00_set_field32(&word, TXD_W1_CWMAX, txdesc->cw_max);
1551 rt2x00_set_field32(&word, TXD_W1_IV_OFFSET, IEEE80211_HEADER); 1773 rt2x00_set_field32(&word, TXD_W1_IV_OFFSET, txdesc->iv_offset);
1552 rt2x00_set_field32(&word, TXD_W1_HW_SEQUENCE, 1774 rt2x00_set_field32(&word, TXD_W1_HW_SEQUENCE,
1553 test_bit(ENTRY_TXD_GENERATE_SEQ, &txdesc->flags)); 1775 test_bit(ENTRY_TXD_GENERATE_SEQ, &txdesc->flags));
1554 rt2x00_set_field32(&word, TXD_W1_BUFFER_COUNT, 1); 1776 rt2x00_set_field32(&word, TXD_W1_BUFFER_COUNT, 1);
@@ -1561,6 +1783,11 @@ static void rt61pci_write_tx_desc(struct rt2x00_dev *rt2x00dev,
1561 rt2x00_set_field32(&word, TXD_W2_PLCP_LENGTH_HIGH, txdesc->length_high); 1783 rt2x00_set_field32(&word, TXD_W2_PLCP_LENGTH_HIGH, txdesc->length_high);
1562 rt2x00_desc_write(txd, 2, word); 1784 rt2x00_desc_write(txd, 2, word);
1563 1785
1786 if (test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags)) {
1787 _rt2x00_desc_write(txd, 3, skbdesc->iv);
1788 _rt2x00_desc_write(txd, 4, skbdesc->eiv);
1789 }
1790
1564 rt2x00_desc_read(txd, 5, &word); 1791 rt2x00_desc_read(txd, 5, &word);
1565 rt2x00_set_field32(&word, TXD_W5_PID_TYPE, skbdesc->entry->queue->qid); 1792 rt2x00_set_field32(&word, TXD_W5_PID_TYPE, skbdesc->entry->queue->qid);
1566 rt2x00_set_field32(&word, TXD_W5_PID_SUBTYPE, 1793 rt2x00_set_field32(&word, TXD_W5_PID_SUBTYPE,
@@ -1595,11 +1822,15 @@ static void rt61pci_write_tx_desc(struct rt2x00_dev *rt2x00dev,
1595 rt2x00_set_field32(&word, TXD_W0_IFS, txdesc->ifs); 1822 rt2x00_set_field32(&word, TXD_W0_IFS, txdesc->ifs);
1596 rt2x00_set_field32(&word, TXD_W0_RETRY_MODE, 1823 rt2x00_set_field32(&word, TXD_W0_RETRY_MODE,
1597 test_bit(ENTRY_TXD_RETRY_MODE, &txdesc->flags)); 1824 test_bit(ENTRY_TXD_RETRY_MODE, &txdesc->flags));
1598 rt2x00_set_field32(&word, TXD_W0_TKIP_MIC, 0); 1825 rt2x00_set_field32(&word, TXD_W0_TKIP_MIC,
1826 test_bit(ENTRY_TXD_ENCRYPT_MMIC, &txdesc->flags));
1827 rt2x00_set_field32(&word, TXD_W0_KEY_TABLE,
1828 test_bit(ENTRY_TXD_ENCRYPT_PAIRWISE, &txdesc->flags));
1829 rt2x00_set_field32(&word, TXD_W0_KEY_INDEX, txdesc->key_idx);
1599 rt2x00_set_field32(&word, TXD_W0_DATABYTE_COUNT, skb->len); 1830 rt2x00_set_field32(&word, TXD_W0_DATABYTE_COUNT, skb->len);
1600 rt2x00_set_field32(&word, TXD_W0_BURST, 1831 rt2x00_set_field32(&word, TXD_W0_BURST,
1601 test_bit(ENTRY_TXD_BURST, &txdesc->flags)); 1832 test_bit(ENTRY_TXD_BURST, &txdesc->flags));
1602 rt2x00_set_field32(&word, TXD_W0_CIPHER_ALG, CIPHER_NONE); 1833 rt2x00_set_field32(&word, TXD_W0_CIPHER_ALG, txdesc->cipher);
1603 rt2x00_desc_write(txd, 0, word); 1834 rt2x00_desc_write(txd, 0, word);
1604} 1835}
1605 1836
@@ -1676,40 +1907,27 @@ static void rt61pci_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
1676 */ 1907 */
1677static int rt61pci_agc_to_rssi(struct rt2x00_dev *rt2x00dev, int rxd_w1) 1908static int rt61pci_agc_to_rssi(struct rt2x00_dev *rt2x00dev, int rxd_w1)
1678{ 1909{
1679 u16 eeprom; 1910 u8 offset = rt2x00dev->lna_gain;
1680 u8 offset;
1681 u8 lna; 1911 u8 lna;
1682 1912
1683 lna = rt2x00_get_field32(rxd_w1, RXD_W1_RSSI_LNA); 1913 lna = rt2x00_get_field32(rxd_w1, RXD_W1_RSSI_LNA);
1684 switch (lna) { 1914 switch (lna) {
1685 case 3: 1915 case 3:
1686 offset = 90; 1916 offset += 90;
1687 break; 1917 break;
1688 case 2: 1918 case 2:
1689 offset = 74; 1919 offset += 74;
1690 break; 1920 break;
1691 case 1: 1921 case 1:
1692 offset = 64; 1922 offset += 64;
1693 break; 1923 break;
1694 default: 1924 default:
1695 return 0; 1925 return 0;
1696 } 1926 }
1697 1927
1698 if (rt2x00dev->rx_status.band == IEEE80211_BAND_5GHZ) { 1928 if (rt2x00dev->rx_status.band == IEEE80211_BAND_5GHZ) {
1699 if (test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags))
1700 offset += 14;
1701
1702 if (lna == 3 || lna == 2) 1929 if (lna == 3 || lna == 2)
1703 offset += 10; 1930 offset += 10;
1704
1705 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_A, &eeprom);
1706 offset -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_A_1);
1707 } else {
1708 if (test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags))
1709 offset += 14;
1710
1711 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_BG, &eeprom);
1712 offset -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_BG_1);
1713 } 1931 }
1714 1932
1715 return rt2x00_get_field32(rxd_w1, RXD_W1_RSSI_AGC) * 2 - offset; 1933 return rt2x00_get_field32(rxd_w1, RXD_W1_RSSI_AGC) * 2 - offset;
@@ -1718,6 +1936,7 @@ static int rt61pci_agc_to_rssi(struct rt2x00_dev *rt2x00dev, int rxd_w1)
1718static void rt61pci_fill_rxdone(struct queue_entry *entry, 1936static void rt61pci_fill_rxdone(struct queue_entry *entry,
1719 struct rxdone_entry_desc *rxdesc) 1937 struct rxdone_entry_desc *rxdesc)
1720{ 1938{
1939 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
1721 struct queue_entry_priv_pci *entry_priv = entry->priv_data; 1940 struct queue_entry_priv_pci *entry_priv = entry->priv_data;
1722 u32 word0; 1941 u32 word0;
1723 u32 word1; 1942 u32 word1;
@@ -1728,6 +1947,38 @@ static void rt61pci_fill_rxdone(struct queue_entry *entry,
1728 if (rt2x00_get_field32(word0, RXD_W0_CRC_ERROR)) 1947 if (rt2x00_get_field32(word0, RXD_W0_CRC_ERROR))
1729 rxdesc->flags |= RX_FLAG_FAILED_FCS_CRC; 1948 rxdesc->flags |= RX_FLAG_FAILED_FCS_CRC;
1730 1949
1950 if (test_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags)) {
1951 rxdesc->cipher =
1952 rt2x00_get_field32(word0, RXD_W0_CIPHER_ALG);
1953 rxdesc->cipher_status =
1954 rt2x00_get_field32(word0, RXD_W0_CIPHER_ERROR);
1955 }
1956
1957 if (rxdesc->cipher != CIPHER_NONE) {
1958 _rt2x00_desc_read(entry_priv->desc, 2, &rxdesc->iv);
1959 _rt2x00_desc_read(entry_priv->desc, 3, &rxdesc->eiv);
1960 _rt2x00_desc_read(entry_priv->desc, 4, &rxdesc->icv);
1961
1962 /*
1963 * Hardware has stripped IV/EIV data from 802.11 frame during
1964 * decryption. It has provided the data seperately but rt2x00lib
1965 * should decide if it should be reinserted.
1966 */
1967 rxdesc->flags |= RX_FLAG_IV_STRIPPED;
1968
1969 /*
1970 * FIXME: Legacy driver indicates that the frame does
1971 * contain the Michael Mic. Unfortunately, in rt2x00
1972 * the MIC seems to be missing completely...
1973 */
1974 rxdesc->flags |= RX_FLAG_MMIC_STRIPPED;
1975
1976 if (rxdesc->cipher_status == RX_CRYPTO_SUCCESS)
1977 rxdesc->flags |= RX_FLAG_DECRYPTED;
1978 else if (rxdesc->cipher_status == RX_CRYPTO_FAIL_MIC)
1979 rxdesc->flags |= RX_FLAG_MMIC_ERROR;
1980 }
1981
1731 /* 1982 /*
1732 * Obtain the status about this packet. 1983 * Obtain the status about this packet.
1733 * When frame was received with an OFDM bitrate, 1984 * When frame was received with an OFDM bitrate,
@@ -1735,11 +1986,13 @@ static void rt61pci_fill_rxdone(struct queue_entry *entry,
1735 * a CCK bitrate the signal is the rate in 100kbit/s. 1986 * a CCK bitrate the signal is the rate in 100kbit/s.
1736 */ 1987 */
1737 rxdesc->signal = rt2x00_get_field32(word1, RXD_W1_SIGNAL); 1988 rxdesc->signal = rt2x00_get_field32(word1, RXD_W1_SIGNAL);
1738 rxdesc->rssi = rt61pci_agc_to_rssi(entry->queue->rt2x00dev, word1); 1989 rxdesc->rssi = rt61pci_agc_to_rssi(rt2x00dev, word1);
1739 rxdesc->size = rt2x00_get_field32(word0, RXD_W0_DATABYTE_COUNT); 1990 rxdesc->size = rt2x00_get_field32(word0, RXD_W0_DATABYTE_COUNT);
1740 1991
1741 if (rt2x00_get_field32(word0, RXD_W0_OFDM)) 1992 if (rt2x00_get_field32(word0, RXD_W0_OFDM))
1742 rxdesc->dev_flags |= RXDONE_SIGNAL_PLCP; 1993 rxdesc->dev_flags |= RXDONE_SIGNAL_PLCP;
1994 else
1995 rxdesc->dev_flags |= RXDONE_SIGNAL_BITRATE;
1743 if (rt2x00_get_field32(word0, RXD_W0_MY_BSS)) 1996 if (rt2x00_get_field32(word0, RXD_W0_MY_BSS))
1744 rxdesc->dev_flags |= RXDONE_MY_BSS; 1997 rxdesc->dev_flags |= RXDONE_MY_BSS;
1745} 1998}
@@ -1860,7 +2113,7 @@ static irqreturn_t rt61pci_interrupt(int irq, void *dev_instance)
1860 if (!reg && !reg_mcu) 2113 if (!reg && !reg_mcu)
1861 return IRQ_NONE; 2114 return IRQ_NONE;
1862 2115
1863 if (!test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags)) 2116 if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
1864 return IRQ_HANDLED; 2117 return IRQ_HANDLED;
1865 2118
1866 /* 2119 /*
@@ -2060,10 +2313,10 @@ static int rt61pci_init_eeprom(struct rt2x00_dev *rt2x00dev)
2060 /* 2313 /*
2061 * Detect if this device has an hardware controlled radio. 2314 * Detect if this device has an hardware controlled radio.
2062 */ 2315 */
2063#ifdef CONFIG_RT61PCI_RFKILL 2316#ifdef CONFIG_RT2X00_LIB_RFKILL
2064 if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_HARDWARE_RADIO)) 2317 if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_HARDWARE_RADIO))
2065 __set_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags); 2318 __set_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags);
2066#endif /* CONFIG_RT61PCI_RFKILL */ 2319#endif /* CONFIG_RT2X00_LIB_RFKILL */
2067 2320
2068 /* 2321 /*
2069 * Read frequency offset and RF programming sequence. 2322 * Read frequency offset and RF programming sequence.
@@ -2121,7 +2374,7 @@ static int rt61pci_init_eeprom(struct rt2x00_dev *rt2x00dev)
2121 * If the eeprom value is invalid, 2374 * If the eeprom value is invalid,
2122 * switch to default led mode. 2375 * switch to default led mode.
2123 */ 2376 */
2124#ifdef CONFIG_RT61PCI_LEDS 2377#ifdef CONFIG_RT2X00_LIB_LEDS
2125 rt2x00_eeprom_read(rt2x00dev, EEPROM_LED, &eeprom); 2378 rt2x00_eeprom_read(rt2x00dev, EEPROM_LED, &eeprom);
2126 value = rt2x00_get_field16(eeprom, EEPROM_LED_LED_MODE); 2379 value = rt2x00_get_field16(eeprom, EEPROM_LED_LED_MODE);
2127 2380
@@ -2155,7 +2408,7 @@ static int rt61pci_init_eeprom(struct rt2x00_dev *rt2x00dev)
2155 rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_READY_A, 2408 rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_READY_A,
2156 rt2x00_get_field16(eeprom, 2409 rt2x00_get_field16(eeprom,
2157 EEPROM_LED_POLARITY_RDY_A)); 2410 EEPROM_LED_POLARITY_RDY_A));
2158#endif /* CONFIG_RT61PCI_LEDS */ 2411#endif /* CONFIG_RT2X00_LIB_LEDS */
2159 2412
2160 return 0; 2413 return 0;
2161} 2414}
@@ -2274,10 +2527,11 @@ static const struct rf_channel rf_vals_seq[] = {
2274 { 46, 0x00002ccc, 0x000049a6, 0x0009be55, 0x000c0a23 }, 2527 { 46, 0x00002ccc, 0x000049a6, 0x0009be55, 0x000c0a23 },
2275}; 2528};
2276 2529
2277static void rt61pci_probe_hw_mode(struct rt2x00_dev *rt2x00dev) 2530static int rt61pci_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
2278{ 2531{
2279 struct hw_mode_spec *spec = &rt2x00dev->spec; 2532 struct hw_mode_spec *spec = &rt2x00dev->spec;
2280 u8 *txpower; 2533 struct channel_info *info;
2534 char *tx_power;
2281 unsigned int i; 2535 unsigned int i;
2282 2536
2283 /* 2537 /*
@@ -2294,20 +2548,10 @@ static void rt61pci_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
2294 EEPROM_MAC_ADDR_0)); 2548 EEPROM_MAC_ADDR_0));
2295 2549
2296 /* 2550 /*
2297 * Convert tx_power array in eeprom.
2298 */
2299 txpower = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_G_START);
2300 for (i = 0; i < 14; i++)
2301 txpower[i] = TXPOWER_FROM_DEV(txpower[i]);
2302
2303 /*
2304 * Initialize hw_mode information. 2551 * Initialize hw_mode information.
2305 */ 2552 */
2306 spec->supported_bands = SUPPORT_BAND_2GHZ; 2553 spec->supported_bands = SUPPORT_BAND_2GHZ;
2307 spec->supported_rates = SUPPORT_RATE_CCK | SUPPORT_RATE_OFDM; 2554 spec->supported_rates = SUPPORT_RATE_CCK | SUPPORT_RATE_OFDM;
2308 spec->tx_power_a = NULL;
2309 spec->tx_power_bg = txpower;
2310 spec->tx_power_default = DEFAULT_TXPOWER;
2311 2555
2312 if (!test_bit(CONFIG_RF_SEQUENCE, &rt2x00dev->flags)) { 2556 if (!test_bit(CONFIG_RF_SEQUENCE, &rt2x00dev->flags)) {
2313 spec->num_channels = 14; 2557 spec->num_channels = 14;
@@ -2321,13 +2565,28 @@ static void rt61pci_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
2321 rt2x00_rf(&rt2x00dev->chip, RF5325)) { 2565 rt2x00_rf(&rt2x00dev->chip, RF5325)) {
2322 spec->supported_bands |= SUPPORT_BAND_5GHZ; 2566 spec->supported_bands |= SUPPORT_BAND_5GHZ;
2323 spec->num_channels = ARRAY_SIZE(rf_vals_seq); 2567 spec->num_channels = ARRAY_SIZE(rf_vals_seq);
2568 }
2324 2569
2325 txpower = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_A_START); 2570 /*
2326 for (i = 0; i < 14; i++) 2571 * Create channel information array
2327 txpower[i] = TXPOWER_FROM_DEV(txpower[i]); 2572 */
2573 info = kzalloc(spec->num_channels * sizeof(*info), GFP_KERNEL);
2574 if (!info)
2575 return -ENOMEM;
2328 2576
2329 spec->tx_power_a = txpower; 2577 spec->channels_info = info;
2578
2579 tx_power = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_G_START);
2580 for (i = 0; i < 14; i++)
2581 info[i].tx_power1 = TXPOWER_FROM_DEV(tx_power[i]);
2582
2583 if (spec->num_channels > 14) {
2584 tx_power = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_A_START);
2585 for (i = 14; i < spec->num_channels; i++)
2586 info[i].tx_power1 = TXPOWER_FROM_DEV(tx_power[i]);
2330 } 2587 }
2588
2589 return 0;
2331} 2590}
2332 2591
2333static int rt61pci_probe_hw(struct rt2x00_dev *rt2x00dev) 2592static int rt61pci_probe_hw(struct rt2x00_dev *rt2x00dev)
@@ -2348,13 +2607,17 @@ static int rt61pci_probe_hw(struct rt2x00_dev *rt2x00dev)
2348 /* 2607 /*
2349 * Initialize hw specifications. 2608 * Initialize hw specifications.
2350 */ 2609 */
2351 rt61pci_probe_hw_mode(rt2x00dev); 2610 retval = rt61pci_probe_hw_mode(rt2x00dev);
2611 if (retval)
2612 return retval;
2352 2613
2353 /* 2614 /*
2354 * This device requires firmware and DMA mapped skbs. 2615 * This device requires firmware and DMA mapped skbs.
2355 */ 2616 */
2356 __set_bit(DRIVER_REQUIRE_FIRMWARE, &rt2x00dev->flags); 2617 __set_bit(DRIVER_REQUIRE_FIRMWARE, &rt2x00dev->flags);
2357 __set_bit(DRIVER_REQUIRE_DMA, &rt2x00dev->flags); 2618 __set_bit(DRIVER_REQUIRE_DMA, &rt2x00dev->flags);
2619 if (!modparam_nohwcrypt)
2620 __set_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags);
2358 2621
2359 /* 2622 /*
2360 * Set the rssi offset. 2623 * Set the rssi offset.
@@ -2381,6 +2644,63 @@ static int rt61pci_set_retry_limit(struct ieee80211_hw *hw,
2381 return 0; 2644 return 0;
2382} 2645}
2383 2646
2647static int rt61pci_conf_tx(struct ieee80211_hw *hw, u16 queue_idx,
2648 const struct ieee80211_tx_queue_params *params)
2649{
2650 struct rt2x00_dev *rt2x00dev = hw->priv;
2651 struct data_queue *queue;
2652 struct rt2x00_field32 field;
2653 int retval;
2654 u32 reg;
2655
2656 /*
2657 * First pass the configuration through rt2x00lib, that will
2658 * update the queue settings and validate the input. After that
2659 * we are free to update the registers based on the value
2660 * in the queue parameter.
2661 */
2662 retval = rt2x00mac_conf_tx(hw, queue_idx, params);
2663 if (retval)
2664 return retval;
2665
2666 queue = rt2x00queue_get_queue(rt2x00dev, queue_idx);
2667
2668 /* Update WMM TXOP register */
2669 if (queue_idx < 2) {
2670 field.bit_offset = queue_idx * 16;
2671 field.bit_mask = 0xffff << field.bit_offset;
2672
2673 rt2x00pci_register_read(rt2x00dev, AC_TXOP_CSR0, &reg);
2674 rt2x00_set_field32(&reg, field, queue->txop);
2675 rt2x00pci_register_write(rt2x00dev, AC_TXOP_CSR0, reg);
2676 } else if (queue_idx < 4) {
2677 field.bit_offset = (queue_idx - 2) * 16;
2678 field.bit_mask = 0xffff << field.bit_offset;
2679
2680 rt2x00pci_register_read(rt2x00dev, AC_TXOP_CSR1, &reg);
2681 rt2x00_set_field32(&reg, field, queue->txop);
2682 rt2x00pci_register_write(rt2x00dev, AC_TXOP_CSR1, reg);
2683 }
2684
2685 /* Update WMM registers */
2686 field.bit_offset = queue_idx * 4;
2687 field.bit_mask = 0xf << field.bit_offset;
2688
2689 rt2x00pci_register_read(rt2x00dev, AIFSN_CSR, &reg);
2690 rt2x00_set_field32(&reg, field, queue->aifs);
2691 rt2x00pci_register_write(rt2x00dev, AIFSN_CSR, reg);
2692
2693 rt2x00pci_register_read(rt2x00dev, CWMIN_CSR, &reg);
2694 rt2x00_set_field32(&reg, field, queue->cw_min);
2695 rt2x00pci_register_write(rt2x00dev, CWMIN_CSR, reg);
2696
2697 rt2x00pci_register_read(rt2x00dev, CWMAX_CSR, &reg);
2698 rt2x00_set_field32(&reg, field, queue->cw_max);
2699 rt2x00pci_register_write(rt2x00dev, CWMAX_CSR, reg);
2700
2701 return 0;
2702}
2703
2384static u64 rt61pci_get_tsf(struct ieee80211_hw *hw) 2704static u64 rt61pci_get_tsf(struct ieee80211_hw *hw)
2385{ 2705{
2386 struct rt2x00_dev *rt2x00dev = hw->priv; 2706 struct rt2x00_dev *rt2x00dev = hw->priv;
@@ -2404,10 +2724,11 @@ static const struct ieee80211_ops rt61pci_mac80211_ops = {
2404 .config = rt2x00mac_config, 2724 .config = rt2x00mac_config,
2405 .config_interface = rt2x00mac_config_interface, 2725 .config_interface = rt2x00mac_config_interface,
2406 .configure_filter = rt2x00mac_configure_filter, 2726 .configure_filter = rt2x00mac_configure_filter,
2727 .set_key = rt2x00mac_set_key,
2407 .get_stats = rt2x00mac_get_stats, 2728 .get_stats = rt2x00mac_get_stats,
2408 .set_retry_limit = rt61pci_set_retry_limit, 2729 .set_retry_limit = rt61pci_set_retry_limit,
2409 .bss_info_changed = rt2x00mac_bss_info_changed, 2730 .bss_info_changed = rt2x00mac_bss_info_changed,
2410 .conf_tx = rt2x00mac_conf_tx, 2731 .conf_tx = rt61pci_conf_tx,
2411 .get_tx_stats = rt2x00mac_get_tx_stats, 2732 .get_tx_stats = rt2x00mac_get_tx_stats,
2412 .get_tsf = rt61pci_get_tsf, 2733 .get_tsf = rt61pci_get_tsf,
2413}; 2734};
@@ -2432,6 +2753,8 @@ static const struct rt2x00lib_ops rt61pci_rt2x00_ops = {
2432 .write_beacon = rt61pci_write_beacon, 2753 .write_beacon = rt61pci_write_beacon,
2433 .kick_tx_queue = rt61pci_kick_tx_queue, 2754 .kick_tx_queue = rt61pci_kick_tx_queue,
2434 .fill_rxdone = rt61pci_fill_rxdone, 2755 .fill_rxdone = rt61pci_fill_rxdone,
2756 .config_shared_key = rt61pci_config_shared_key,
2757 .config_pairwise_key = rt61pci_config_pairwise_key,
2435 .config_filter = rt61pci_config_filter, 2758 .config_filter = rt61pci_config_filter,
2436 .config_intf = rt61pci_config_intf, 2759 .config_intf = rt61pci_config_intf,
2437 .config_erp = rt61pci_config_erp, 2760 .config_erp = rt61pci_config_erp,
diff --git a/drivers/net/wireless/rt2x00/rt61pci.h b/drivers/net/wireless/rt2x00/rt61pci.h
index 1004d5b899e6..8ec1451308cc 100644
--- a/drivers/net/wireless/rt2x00/rt61pci.h
+++ b/drivers/net/wireless/rt2x00/rt61pci.h
@@ -134,6 +134,16 @@
134#define PAIRWISE_KEY_TABLE_BASE 0x1200 134#define PAIRWISE_KEY_TABLE_BASE 0x1200
135#define PAIRWISE_TA_TABLE_BASE 0x1a00 135#define PAIRWISE_TA_TABLE_BASE 0x1a00
136 136
137#define SHARED_KEY_ENTRY(__idx) \
138 ( SHARED_KEY_TABLE_BASE + \
139 ((__idx) * sizeof(struct hw_key_entry)) )
140#define PAIRWISE_KEY_ENTRY(__idx) \
141 ( PAIRWISE_KEY_TABLE_BASE + \
142 ((__idx) * sizeof(struct hw_key_entry)) )
143#define PAIRWISE_TA_ENTRY(__idx) \
144 ( PAIRWISE_TA_TABLE_BASE + \
145 ((__idx) * sizeof(struct hw_pairwise_ta_entry)) )
146
137struct hw_key_entry { 147struct hw_key_entry {
138 u8 key[16]; 148 u8 key[16];
139 u8 tx_mic[8]; 149 u8 tx_mic[8];
@@ -142,7 +152,8 @@ struct hw_key_entry {
142 152
143struct hw_pairwise_ta_entry { 153struct hw_pairwise_ta_entry {
144 u8 address[6]; 154 u8 address[6];
145 u8 reserved[2]; 155 u8 cipher;
156 u8 reserved;
146} __attribute__ ((packed)); 157} __attribute__ ((packed));
147 158
148/* 159/*
@@ -662,6 +673,10 @@ struct hw_pairwise_ta_entry {
662 * SEC_CSR4: Pairwise key table lookup control. 673 * SEC_CSR4: Pairwise key table lookup control.
663 */ 674 */
664#define SEC_CSR4 0x30b0 675#define SEC_CSR4 0x30b0
676#define SEC_CSR4_ENABLE_BSS0 FIELD32(0x00000001)
677#define SEC_CSR4_ENABLE_BSS1 FIELD32(0x00000002)
678#define SEC_CSR4_ENABLE_BSS2 FIELD32(0x00000004)
679#define SEC_CSR4_ENABLE_BSS3 FIELD32(0x00000008)
665 680
666/* 681/*
667 * SEC_CSR5: shared key table security mode register. 682 * SEC_CSR5: shared key table security mode register.
@@ -1428,8 +1443,10 @@ struct hw_pairwise_ta_entry {
1428 1443
1429/* 1444/*
1430 * Word4 1445 * Word4
1446 * ICV: Received ICV of originally encrypted.
1447 * NOTE: This is a guess, the official definition is "reserved"
1431 */ 1448 */
1432#define RXD_W4_RESERVED FIELD32(0xffffffff) 1449#define RXD_W4_ICV FIELD32(0xffffffff)
1433 1450
1434/* 1451/*
1435 * the above 20-byte is called RXINFO and will be DMAed to MAC RX block 1452 * the above 20-byte is called RXINFO and will be DMAed to MAC RX block
@@ -1465,17 +1482,10 @@ struct hw_pairwise_ta_entry {
1465#define MAX_TXPOWER 31 1482#define MAX_TXPOWER 31
1466#define DEFAULT_TXPOWER 24 1483#define DEFAULT_TXPOWER 24
1467 1484
1468#define TXPOWER_FROM_DEV(__txpower) \ 1485#define TXPOWER_FROM_DEV(__txpower) \
1469({ \ 1486 (((u8)(__txpower)) > MAX_TXPOWER) ? DEFAULT_TXPOWER : (__txpower)
1470 ((__txpower) > MAX_TXPOWER) ? \ 1487
1471 DEFAULT_TXPOWER : (__txpower); \ 1488#define TXPOWER_TO_DEV(__txpower) \
1472}) 1489 clamp_t(char, __txpower, MIN_TXPOWER, MAX_TXPOWER)
1473
1474#define TXPOWER_TO_DEV(__txpower) \
1475({ \
1476 ((__txpower) <= MIN_TXPOWER) ? MIN_TXPOWER : \
1477 (((__txpower) >= MAX_TXPOWER) ? MAX_TXPOWER : \
1478 (__txpower)); \
1479})
1480 1490
1481#endif /* RT61PCI_H */ 1491#endif /* RT61PCI_H */
diff --git a/drivers/net/wireless/rt2x00/rt73usb.c b/drivers/net/wireless/rt2x00/rt73usb.c
index 9761eaaa08be..934f8e03c5aa 100644
--- a/drivers/net/wireless/rt2x00/rt73usb.c
+++ b/drivers/net/wireless/rt2x00/rt73usb.c
@@ -37,6 +37,13 @@
37#include "rt73usb.h" 37#include "rt73usb.h"
38 38
39/* 39/*
40 * Allow hardware encryption to be disabled.
41 */
42static int modparam_nohwcrypt = 0;
43module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO);
44MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
45
46/*
40 * Register access. 47 * Register access.
41 * All access to the CSR registers will go through the methods 48 * All access to the CSR registers will go through the methods
42 * rt73usb_register_read and rt73usb_register_write. 49 * rt73usb_register_read and rt73usb_register_write.
@@ -285,7 +292,7 @@ static const struct rt2x00debug rt73usb_rt2x00debug = {
285}; 292};
286#endif /* CONFIG_RT2X00_LIB_DEBUGFS */ 293#endif /* CONFIG_RT2X00_LIB_DEBUGFS */
287 294
288#ifdef CONFIG_RT73USB_LEDS 295#ifdef CONFIG_RT2X00_LIB_LEDS
289static void rt73usb_brightness_set(struct led_classdev *led_cdev, 296static void rt73usb_brightness_set(struct led_classdev *led_cdev,
290 enum led_brightness brightness) 297 enum led_brightness brightness)
291{ 298{
@@ -352,11 +359,224 @@ static void rt73usb_init_led(struct rt2x00_dev *rt2x00dev,
352 led->led_dev.blink_set = rt73usb_blink_set; 359 led->led_dev.blink_set = rt73usb_blink_set;
353 led->flags = LED_INITIALIZED; 360 led->flags = LED_INITIALIZED;
354} 361}
355#endif /* CONFIG_RT73USB_LEDS */ 362#endif /* CONFIG_RT2X00_LIB_LEDS */
356 363
357/* 364/*
358 * Configuration handlers. 365 * Configuration handlers.
359 */ 366 */
367static int rt73usb_config_shared_key(struct rt2x00_dev *rt2x00dev,
368 struct rt2x00lib_crypto *crypto,
369 struct ieee80211_key_conf *key)
370{
371 struct hw_key_entry key_entry;
372 struct rt2x00_field32 field;
373 int timeout;
374 u32 mask;
375 u32 reg;
376
377 if (crypto->cmd == SET_KEY) {
378 /*
379 * rt2x00lib can't determine the correct free
380 * key_idx for shared keys. We have 1 register
381 * with key valid bits. The goal is simple, read
382 * the register, if that is full we have no slots
383 * left.
384 * Note that each BSS is allowed to have up to 4
385 * shared keys, so put a mask over the allowed
386 * entries.
387 */
388 mask = (0xf << crypto->bssidx);
389
390 rt73usb_register_read(rt2x00dev, SEC_CSR0, &reg);
391 reg &= mask;
392
393 if (reg && reg == mask)
394 return -ENOSPC;
395
396 key->hw_key_idx += reg ? ffz(reg) : 0;
397
398 /*
399 * Upload key to hardware
400 */
401 memcpy(key_entry.key, crypto->key,
402 sizeof(key_entry.key));
403 memcpy(key_entry.tx_mic, crypto->tx_mic,
404 sizeof(key_entry.tx_mic));
405 memcpy(key_entry.rx_mic, crypto->rx_mic,
406 sizeof(key_entry.rx_mic));
407
408 reg = SHARED_KEY_ENTRY(key->hw_key_idx);
409 timeout = REGISTER_TIMEOUT32(sizeof(key_entry));
410 rt2x00usb_vendor_request_large_buff(rt2x00dev, USB_MULTI_WRITE,
411 USB_VENDOR_REQUEST_OUT, reg,
412 &key_entry,
413 sizeof(key_entry),
414 timeout);
415
416 /*
417 * The cipher types are stored over 2 registers.
418 * bssidx 0 and 1 keys are stored in SEC_CSR1 and
419 * bssidx 1 and 2 keys are stored in SEC_CSR5.
420 * Using the correct defines correctly will cause overhead,
421 * so just calculate the correct offset.
422 */
423 if (key->hw_key_idx < 8) {
424 field.bit_offset = (3 * key->hw_key_idx);
425 field.bit_mask = 0x7 << field.bit_offset;
426
427 rt73usb_register_read(rt2x00dev, SEC_CSR1, &reg);
428 rt2x00_set_field32(&reg, field, crypto->cipher);
429 rt73usb_register_write(rt2x00dev, SEC_CSR1, reg);
430 } else {
431 field.bit_offset = (3 * (key->hw_key_idx - 8));
432 field.bit_mask = 0x7 << field.bit_offset;
433
434 rt73usb_register_read(rt2x00dev, SEC_CSR5, &reg);
435 rt2x00_set_field32(&reg, field, crypto->cipher);
436 rt73usb_register_write(rt2x00dev, SEC_CSR5, reg);
437 }
438
439 /*
440 * The driver does not support the IV/EIV generation
441 * in hardware. However it doesn't support the IV/EIV
442 * inside the ieee80211 frame either, but requires it
443 * to be provided seperately for the descriptor.
444 * rt2x00lib will cut the IV/EIV data out of all frames
445 * given to us by mac80211, but we must tell mac80211
446 * to generate the IV/EIV data.
447 */
448 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
449 }
450
451 /*
452 * SEC_CSR0 contains only single-bit fields to indicate
453 * a particular key is valid. Because using the FIELD32()
454 * defines directly will cause a lot of overhead we use
455 * a calculation to determine the correct bit directly.
456 */
457 mask = 1 << key->hw_key_idx;
458
459 rt73usb_register_read(rt2x00dev, SEC_CSR0, &reg);
460 if (crypto->cmd == SET_KEY)
461 reg |= mask;
462 else if (crypto->cmd == DISABLE_KEY)
463 reg &= ~mask;
464 rt73usb_register_write(rt2x00dev, SEC_CSR0, reg);
465
466 return 0;
467}
468
469static int rt73usb_config_pairwise_key(struct rt2x00_dev *rt2x00dev,
470 struct rt2x00lib_crypto *crypto,
471 struct ieee80211_key_conf *key)
472{
473 struct hw_pairwise_ta_entry addr_entry;
474 struct hw_key_entry key_entry;
475 int timeout;
476 u32 mask;
477 u32 reg;
478
479 if (crypto->cmd == SET_KEY) {
480 /*
481 * rt2x00lib can't determine the correct free
482 * key_idx for pairwise keys. We have 2 registers
483 * with key valid bits. The goal is simple, read
484 * the first register, if that is full move to
485 * the next register.
486 * When both registers are full, we drop the key,
487 * otherwise we use the first invalid entry.
488 */
489 rt73usb_register_read(rt2x00dev, SEC_CSR2, &reg);
490 if (reg && reg == ~0) {
491 key->hw_key_idx = 32;
492 rt73usb_register_read(rt2x00dev, SEC_CSR3, &reg);
493 if (reg && reg == ~0)
494 return -ENOSPC;
495 }
496
497 key->hw_key_idx += reg ? ffz(reg) : 0;
498
499 /*
500 * Upload key to hardware
501 */
502 memcpy(key_entry.key, crypto->key,
503 sizeof(key_entry.key));
504 memcpy(key_entry.tx_mic, crypto->tx_mic,
505 sizeof(key_entry.tx_mic));
506 memcpy(key_entry.rx_mic, crypto->rx_mic,
507 sizeof(key_entry.rx_mic));
508
509 reg = PAIRWISE_KEY_ENTRY(key->hw_key_idx);
510 timeout = REGISTER_TIMEOUT32(sizeof(key_entry));
511 rt2x00usb_vendor_request_large_buff(rt2x00dev, USB_MULTI_WRITE,
512 USB_VENDOR_REQUEST_OUT, reg,
513 &key_entry,
514 sizeof(key_entry),
515 timeout);
516
517 /*
518 * Send the address and cipher type to the hardware register.
519 * This data fits within the CSR cache size, so we can use
520 * rt73usb_register_multiwrite() directly.
521 */
522 memset(&addr_entry, 0, sizeof(addr_entry));
523 memcpy(&addr_entry, crypto->address, ETH_ALEN);
524 addr_entry.cipher = crypto->cipher;
525
526 reg = PAIRWISE_TA_ENTRY(key->hw_key_idx);
527 rt73usb_register_multiwrite(rt2x00dev, reg,
528 &addr_entry, sizeof(addr_entry));
529
530 /*
531 * Enable pairwise lookup table for given BSS idx,
532 * without this received frames will not be decrypted
533 * by the hardware.
534 */
535 rt73usb_register_read(rt2x00dev, SEC_CSR4, &reg);
536 reg |= (1 << crypto->bssidx);
537 rt73usb_register_write(rt2x00dev, SEC_CSR4, reg);
538
539 /*
540 * The driver does not support the IV/EIV generation
541 * in hardware. However it doesn't support the IV/EIV
542 * inside the ieee80211 frame either, but requires it
543 * to be provided seperately for the descriptor.
544 * rt2x00lib will cut the IV/EIV data out of all frames
545 * given to us by mac80211, but we must tell mac80211
546 * to generate the IV/EIV data.
547 */
548 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
549 }
550
551 /*
552 * SEC_CSR2 and SEC_CSR3 contain only single-bit fields to indicate
553 * a particular key is valid. Because using the FIELD32()
554 * defines directly will cause a lot of overhead we use
555 * a calculation to determine the correct bit directly.
556 */
557 if (key->hw_key_idx < 32) {
558 mask = 1 << key->hw_key_idx;
559
560 rt73usb_register_read(rt2x00dev, SEC_CSR2, &reg);
561 if (crypto->cmd == SET_KEY)
562 reg |= mask;
563 else if (crypto->cmd == DISABLE_KEY)
564 reg &= ~mask;
565 rt73usb_register_write(rt2x00dev, SEC_CSR2, reg);
566 } else {
567 mask = 1 << (key->hw_key_idx - 32);
568
569 rt73usb_register_read(rt2x00dev, SEC_CSR3, &reg);
570 if (crypto->cmd == SET_KEY)
571 reg |= mask;
572 else if (crypto->cmd == DISABLE_KEY)
573 reg &= ~mask;
574 rt73usb_register_write(rt2x00dev, SEC_CSR3, reg);
575 }
576
577 return 0;
578}
579
360static void rt73usb_config_filter(struct rt2x00_dev *rt2x00dev, 580static void rt73usb_config_filter(struct rt2x00_dev *rt2x00dev,
361 const unsigned int filter_flags) 581 const unsigned int filter_flags)
362{ 582{
@@ -451,6 +671,26 @@ static void rt73usb_config_erp(struct rt2x00_dev *rt2x00dev,
451 rt73usb_register_write(rt2x00dev, TXRX_CSR4, reg); 671 rt73usb_register_write(rt2x00dev, TXRX_CSR4, reg);
452} 672}
453 673
674static void rt73usb_config_lna_gain(struct rt2x00_dev *rt2x00dev,
675 struct rt2x00lib_conf *libconf)
676{
677 u16 eeprom;
678 short lna_gain = 0;
679
680 if (libconf->band == IEEE80211_BAND_2GHZ) {
681 if (test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags))
682 lna_gain += 14;
683
684 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_BG, &eeprom);
685 lna_gain -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_BG_1);
686 } else {
687 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_A, &eeprom);
688 lna_gain -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_A_1);
689 }
690
691 rt2x00dev->lna_gain = lna_gain;
692}
693
454static void rt73usb_config_phymode(struct rt2x00_dev *rt2x00dev, 694static void rt73usb_config_phymode(struct rt2x00_dev *rt2x00dev,
455 const int basic_rate_mask) 695 const int basic_rate_mask)
456{ 696{
@@ -705,6 +945,9 @@ static void rt73usb_config(struct rt2x00_dev *rt2x00dev,
705 struct rt2x00lib_conf *libconf, 945 struct rt2x00lib_conf *libconf,
706 const unsigned int flags) 946 const unsigned int flags)
707{ 947{
948 /* Always recalculate LNA gain before changing configuration */
949 rt73usb_config_lna_gain(rt2x00dev, libconf);
950
708 if (flags & CONFIG_UPDATE_PHYMODE) 951 if (flags & CONFIG_UPDATE_PHYMODE)
709 rt73usb_config_phymode(rt2x00dev, libconf->basic_rates); 952 rt73usb_config_phymode(rt2x00dev, libconf->basic_rates);
710 if (flags & CONFIG_UPDATE_CHANNEL) 953 if (flags & CONFIG_UPDATE_CHANNEL)
@@ -1034,16 +1277,6 @@ static int rt73usb_init_registers(struct rt2x00_dev *rt2x00dev)
1034 rt73usb_register_write(rt2x00dev, PHY_CSR6, 0x00080606); 1277 rt73usb_register_write(rt2x00dev, PHY_CSR6, 0x00080606);
1035 rt73usb_register_write(rt2x00dev, PHY_CSR7, 0x00000408); 1278 rt73usb_register_write(rt2x00dev, PHY_CSR7, 0x00000408);
1036 1279
1037 rt73usb_register_read(rt2x00dev, AC_TXOP_CSR0, &reg);
1038 rt2x00_set_field32(&reg, AC_TXOP_CSR0_AC0_TX_OP, 0);
1039 rt2x00_set_field32(&reg, AC_TXOP_CSR0_AC1_TX_OP, 0);
1040 rt73usb_register_write(rt2x00dev, AC_TXOP_CSR0, reg);
1041
1042 rt73usb_register_read(rt2x00dev, AC_TXOP_CSR1, &reg);
1043 rt2x00_set_field32(&reg, AC_TXOP_CSR1_AC2_TX_OP, 192);
1044 rt2x00_set_field32(&reg, AC_TXOP_CSR1_AC3_TX_OP, 48);
1045 rt73usb_register_write(rt2x00dev, AC_TXOP_CSR1, reg);
1046
1047 rt73usb_register_read(rt2x00dev, MAC_CSR9, &reg); 1280 rt73usb_register_read(rt2x00dev, MAC_CSR9, &reg);
1048 rt2x00_set_field32(&reg, MAC_CSR9_CW_SELECT, 0); 1281 rt2x00_set_field32(&reg, MAC_CSR9_CW_SELECT, 0);
1049 rt73usb_register_write(rt2x00dev, MAC_CSR9, reg); 1282 rt73usb_register_write(rt2x00dev, MAC_CSR9, reg);
@@ -1265,8 +1498,8 @@ static int rt73usb_set_device_state(struct rt2x00_dev *rt2x00dev,
1265 * TX descriptor initialization 1498 * TX descriptor initialization
1266 */ 1499 */
1267static void rt73usb_write_tx_desc(struct rt2x00_dev *rt2x00dev, 1500static void rt73usb_write_tx_desc(struct rt2x00_dev *rt2x00dev,
1268 struct sk_buff *skb, 1501 struct sk_buff *skb,
1269 struct txentry_desc *txdesc) 1502 struct txentry_desc *txdesc)
1270{ 1503{
1271 struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb); 1504 struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb);
1272 __le32 *txd = skbdesc->desc; 1505 __le32 *txd = skbdesc->desc;
@@ -1280,7 +1513,7 @@ static void rt73usb_write_tx_desc(struct rt2x00_dev *rt2x00dev,
1280 rt2x00_set_field32(&word, TXD_W1_AIFSN, txdesc->aifs); 1513 rt2x00_set_field32(&word, TXD_W1_AIFSN, txdesc->aifs);
1281 rt2x00_set_field32(&word, TXD_W1_CWMIN, txdesc->cw_min); 1514 rt2x00_set_field32(&word, TXD_W1_CWMIN, txdesc->cw_min);
1282 rt2x00_set_field32(&word, TXD_W1_CWMAX, txdesc->cw_max); 1515 rt2x00_set_field32(&word, TXD_W1_CWMAX, txdesc->cw_max);
1283 rt2x00_set_field32(&word, TXD_W1_IV_OFFSET, IEEE80211_HEADER); 1516 rt2x00_set_field32(&word, TXD_W1_IV_OFFSET, txdesc->iv_offset);
1284 rt2x00_set_field32(&word, TXD_W1_HW_SEQUENCE, 1517 rt2x00_set_field32(&word, TXD_W1_HW_SEQUENCE,
1285 test_bit(ENTRY_TXD_GENERATE_SEQ, &txdesc->flags)); 1518 test_bit(ENTRY_TXD_GENERATE_SEQ, &txdesc->flags));
1286 rt2x00_desc_write(txd, 1, word); 1519 rt2x00_desc_write(txd, 1, word);
@@ -1292,6 +1525,11 @@ static void rt73usb_write_tx_desc(struct rt2x00_dev *rt2x00dev,
1292 rt2x00_set_field32(&word, TXD_W2_PLCP_LENGTH_HIGH, txdesc->length_high); 1525 rt2x00_set_field32(&word, TXD_W2_PLCP_LENGTH_HIGH, txdesc->length_high);
1293 rt2x00_desc_write(txd, 2, word); 1526 rt2x00_desc_write(txd, 2, word);
1294 1527
1528 if (test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags)) {
1529 _rt2x00_desc_write(txd, 3, skbdesc->iv);
1530 _rt2x00_desc_write(txd, 4, skbdesc->eiv);
1531 }
1532
1295 rt2x00_desc_read(txd, 5, &word); 1533 rt2x00_desc_read(txd, 5, &word);
1296 rt2x00_set_field32(&word, TXD_W5_TX_POWER, 1534 rt2x00_set_field32(&word, TXD_W5_TX_POWER,
1297 TXPOWER_TO_DEV(rt2x00dev->tx_power)); 1535 TXPOWER_TO_DEV(rt2x00dev->tx_power));
@@ -1313,12 +1551,15 @@ static void rt73usb_write_tx_desc(struct rt2x00_dev *rt2x00dev,
1313 rt2x00_set_field32(&word, TXD_W0_IFS, txdesc->ifs); 1551 rt2x00_set_field32(&word, TXD_W0_IFS, txdesc->ifs);
1314 rt2x00_set_field32(&word, TXD_W0_RETRY_MODE, 1552 rt2x00_set_field32(&word, TXD_W0_RETRY_MODE,
1315 test_bit(ENTRY_TXD_RETRY_MODE, &txdesc->flags)); 1553 test_bit(ENTRY_TXD_RETRY_MODE, &txdesc->flags));
1316 rt2x00_set_field32(&word, TXD_W0_TKIP_MIC, 0); 1554 rt2x00_set_field32(&word, TXD_W0_TKIP_MIC,
1317 rt2x00_set_field32(&word, TXD_W0_DATABYTE_COUNT, 1555 test_bit(ENTRY_TXD_ENCRYPT_MMIC, &txdesc->flags));
1318 skb->len - skbdesc->desc_len); 1556 rt2x00_set_field32(&word, TXD_W0_KEY_TABLE,
1557 test_bit(ENTRY_TXD_ENCRYPT_PAIRWISE, &txdesc->flags));
1558 rt2x00_set_field32(&word, TXD_W0_KEY_INDEX, txdesc->key_idx);
1559 rt2x00_set_field32(&word, TXD_W0_DATABYTE_COUNT, skb->len);
1319 rt2x00_set_field32(&word, TXD_W0_BURST2, 1560 rt2x00_set_field32(&word, TXD_W0_BURST2,
1320 test_bit(ENTRY_TXD_BURST, &txdesc->flags)); 1561 test_bit(ENTRY_TXD_BURST, &txdesc->flags));
1321 rt2x00_set_field32(&word, TXD_W0_CIPHER_ALG, CIPHER_NONE); 1562 rt2x00_set_field32(&word, TXD_W0_CIPHER_ALG, txdesc->cipher);
1322 rt2x00_desc_write(txd, 0, word); 1563 rt2x00_desc_write(txd, 0, word);
1323} 1564}
1324 1565
@@ -1331,7 +1572,6 @@ static void rt73usb_write_beacon(struct queue_entry *entry)
1331 struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb); 1572 struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
1332 unsigned int beacon_base; 1573 unsigned int beacon_base;
1333 u32 reg; 1574 u32 reg;
1334 u32 word, len;
1335 1575
1336 /* 1576 /*
1337 * Add the descriptor in front of the skb. 1577 * Add the descriptor in front of the skb.
@@ -1341,17 +1581,6 @@ static void rt73usb_write_beacon(struct queue_entry *entry)
1341 skbdesc->desc = entry->skb->data; 1581 skbdesc->desc = entry->skb->data;
1342 1582
1343 /* 1583 /*
1344 * Adjust the beacon databyte count. The current number is
1345 * calculated before this function gets called, but falsely
1346 * assumes that the descriptor was already present in the SKB.
1347 */
1348 rt2x00_desc_read(skbdesc->desc, 0, &word);
1349 len = rt2x00_get_field32(word, TXD_W0_DATABYTE_COUNT);
1350 len += skbdesc->desc_len;
1351 rt2x00_set_field32(&word, TXD_W0_DATABYTE_COUNT, len);
1352 rt2x00_desc_write(skbdesc->desc, 0, word);
1353
1354 /*
1355 * Disable beaconing while we are reloading the beacon data, 1584 * Disable beaconing while we are reloading the beacon data,
1356 * otherwise we might be sending out invalid data. 1585 * otherwise we might be sending out invalid data.
1357 */ 1586 */
@@ -1422,20 +1651,19 @@ static void rt73usb_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
1422 */ 1651 */
1423static int rt73usb_agc_to_rssi(struct rt2x00_dev *rt2x00dev, int rxd_w1) 1652static int rt73usb_agc_to_rssi(struct rt2x00_dev *rt2x00dev, int rxd_w1)
1424{ 1653{
1425 u16 eeprom; 1654 u8 offset = rt2x00dev->lna_gain;
1426 u8 offset;
1427 u8 lna; 1655 u8 lna;
1428 1656
1429 lna = rt2x00_get_field32(rxd_w1, RXD_W1_RSSI_LNA); 1657 lna = rt2x00_get_field32(rxd_w1, RXD_W1_RSSI_LNA);
1430 switch (lna) { 1658 switch (lna) {
1431 case 3: 1659 case 3:
1432 offset = 90; 1660 offset += 90;
1433 break; 1661 break;
1434 case 2: 1662 case 2:
1435 offset = 74; 1663 offset += 74;
1436 break; 1664 break;
1437 case 1: 1665 case 1:
1438 offset = 64; 1666 offset += 64;
1439 break; 1667 break;
1440 default: 1668 default:
1441 return 0; 1669 return 0;
@@ -1451,15 +1679,6 @@ static int rt73usb_agc_to_rssi(struct rt2x00_dev *rt2x00dev, int rxd_w1)
1451 else if (lna == 2) 1679 else if (lna == 2)
1452 offset += 8; 1680 offset += 8;
1453 } 1681 }
1454
1455 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_A, &eeprom);
1456 offset -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_A_1);
1457 } else {
1458 if (test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags))
1459 offset += 14;
1460
1461 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_BG, &eeprom);
1462 offset -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_BG_1);
1463 } 1682 }
1464 1683
1465 return rt2x00_get_field32(rxd_w1, RXD_W1_RSSI_AGC) * 2 - offset; 1684 return rt2x00_get_field32(rxd_w1, RXD_W1_RSSI_AGC) * 2 - offset;
@@ -1468,6 +1687,7 @@ static int rt73usb_agc_to_rssi(struct rt2x00_dev *rt2x00dev, int rxd_w1)
1468static void rt73usb_fill_rxdone(struct queue_entry *entry, 1687static void rt73usb_fill_rxdone(struct queue_entry *entry,
1469 struct rxdone_entry_desc *rxdesc) 1688 struct rxdone_entry_desc *rxdesc)
1470{ 1689{
1690 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
1471 struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb); 1691 struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
1472 __le32 *rxd = (__le32 *)entry->skb->data; 1692 __le32 *rxd = (__le32 *)entry->skb->data;
1473 u32 word0; 1693 u32 word0;
@@ -1489,6 +1709,38 @@ static void rt73usb_fill_rxdone(struct queue_entry *entry,
1489 if (rt2x00_get_field32(word0, RXD_W0_CRC_ERROR)) 1709 if (rt2x00_get_field32(word0, RXD_W0_CRC_ERROR))
1490 rxdesc->flags |= RX_FLAG_FAILED_FCS_CRC; 1710 rxdesc->flags |= RX_FLAG_FAILED_FCS_CRC;
1491 1711
1712 if (test_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags)) {
1713 rxdesc->cipher =
1714 rt2x00_get_field32(word0, RXD_W0_CIPHER_ALG);
1715 rxdesc->cipher_status =
1716 rt2x00_get_field32(word0, RXD_W0_CIPHER_ERROR);
1717 }
1718
1719 if (rxdesc->cipher != CIPHER_NONE) {
1720 _rt2x00_desc_read(rxd, 2, &rxdesc->iv);
1721 _rt2x00_desc_read(rxd, 3, &rxdesc->eiv);
1722 _rt2x00_desc_read(rxd, 4, &rxdesc->icv);
1723
1724 /*
1725 * Hardware has stripped IV/EIV data from 802.11 frame during
1726 * decryption. It has provided the data seperately but rt2x00lib
1727 * should decide if it should be reinserted.
1728 */
1729 rxdesc->flags |= RX_FLAG_IV_STRIPPED;
1730
1731 /*
1732 * FIXME: Legacy driver indicates that the frame does
1733 * contain the Michael Mic. Unfortunately, in rt2x00
1734 * the MIC seems to be missing completely...
1735 */
1736 rxdesc->flags |= RX_FLAG_MMIC_STRIPPED;
1737
1738 if (rxdesc->cipher_status == RX_CRYPTO_SUCCESS)
1739 rxdesc->flags |= RX_FLAG_DECRYPTED;
1740 else if (rxdesc->cipher_status == RX_CRYPTO_FAIL_MIC)
1741 rxdesc->flags |= RX_FLAG_MMIC_ERROR;
1742 }
1743
1492 /* 1744 /*
1493 * Obtain the status about this packet. 1745 * Obtain the status about this packet.
1494 * When frame was received with an OFDM bitrate, 1746 * When frame was received with an OFDM bitrate,
@@ -1496,11 +1748,13 @@ static void rt73usb_fill_rxdone(struct queue_entry *entry,
1496 * a CCK bitrate the signal is the rate in 100kbit/s. 1748 * a CCK bitrate the signal is the rate in 100kbit/s.
1497 */ 1749 */
1498 rxdesc->signal = rt2x00_get_field32(word1, RXD_W1_SIGNAL); 1750 rxdesc->signal = rt2x00_get_field32(word1, RXD_W1_SIGNAL);
1499 rxdesc->rssi = rt73usb_agc_to_rssi(entry->queue->rt2x00dev, word1); 1751 rxdesc->rssi = rt73usb_agc_to_rssi(rt2x00dev, word1);
1500 rxdesc->size = rt2x00_get_field32(word0, RXD_W0_DATABYTE_COUNT); 1752 rxdesc->size = rt2x00_get_field32(word0, RXD_W0_DATABYTE_COUNT);
1501 1753
1502 if (rt2x00_get_field32(word0, RXD_W0_OFDM)) 1754 if (rt2x00_get_field32(word0, RXD_W0_OFDM))
1503 rxdesc->dev_flags |= RXDONE_SIGNAL_PLCP; 1755 rxdesc->dev_flags |= RXDONE_SIGNAL_PLCP;
1756 else
1757 rxdesc->dev_flags |= RXDONE_SIGNAL_BITRATE;
1504 if (rt2x00_get_field32(word0, RXD_W0_MY_BSS)) 1758 if (rt2x00_get_field32(word0, RXD_W0_MY_BSS))
1505 rxdesc->dev_flags |= RXDONE_MY_BSS; 1759 rxdesc->dev_flags |= RXDONE_MY_BSS;
1506 1760
@@ -1678,7 +1932,7 @@ static int rt73usb_init_eeprom(struct rt2x00_dev *rt2x00dev)
1678 /* 1932 /*
1679 * Store led settings, for correct led behaviour. 1933 * Store led settings, for correct led behaviour.
1680 */ 1934 */
1681#ifdef CONFIG_RT73USB_LEDS 1935#ifdef CONFIG_RT2X00_LIB_LEDS
1682 rt2x00_eeprom_read(rt2x00dev, EEPROM_LED, &eeprom); 1936 rt2x00_eeprom_read(rt2x00dev, EEPROM_LED, &eeprom);
1683 1937
1684 rt73usb_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO); 1938 rt73usb_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO);
@@ -1711,7 +1965,7 @@ static int rt73usb_init_eeprom(struct rt2x00_dev *rt2x00dev)
1711 rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_READY_A, 1965 rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_READY_A,
1712 rt2x00_get_field16(eeprom, 1966 rt2x00_get_field16(eeprom,
1713 EEPROM_LED_POLARITY_RDY_A)); 1967 EEPROM_LED_POLARITY_RDY_A));
1714#endif /* CONFIG_RT73USB_LEDS */ 1968#endif /* CONFIG_RT2X00_LIB_LEDS */
1715 1969
1716 return 0; 1970 return 0;
1717} 1971}
@@ -1852,10 +2106,11 @@ static const struct rf_channel rf_vals_5225_2527[] = {
1852}; 2106};
1853 2107
1854 2108
1855static void rt73usb_probe_hw_mode(struct rt2x00_dev *rt2x00dev) 2109static int rt73usb_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
1856{ 2110{
1857 struct hw_mode_spec *spec = &rt2x00dev->spec; 2111 struct hw_mode_spec *spec = &rt2x00dev->spec;
1858 u8 *txpower; 2112 struct channel_info *info;
2113 char *tx_power;
1859 unsigned int i; 2114 unsigned int i;
1860 2115
1861 /* 2116 /*
@@ -1872,20 +2127,10 @@ static void rt73usb_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
1872 EEPROM_MAC_ADDR_0)); 2127 EEPROM_MAC_ADDR_0));
1873 2128
1874 /* 2129 /*
1875 * Convert tx_power array in eeprom.
1876 */
1877 txpower = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_G_START);
1878 for (i = 0; i < 14; i++)
1879 txpower[i] = TXPOWER_FROM_DEV(txpower[i]);
1880
1881 /*
1882 * Initialize hw_mode information. 2130 * Initialize hw_mode information.
1883 */ 2131 */
1884 spec->supported_bands = SUPPORT_BAND_2GHZ; 2132 spec->supported_bands = SUPPORT_BAND_2GHZ;
1885 spec->supported_rates = SUPPORT_RATE_CCK | SUPPORT_RATE_OFDM; 2133 spec->supported_rates = SUPPORT_RATE_CCK | SUPPORT_RATE_OFDM;
1886 spec->tx_power_a = NULL;
1887 spec->tx_power_bg = txpower;
1888 spec->tx_power_default = DEFAULT_TXPOWER;
1889 2134
1890 if (rt2x00_rf(&rt2x00dev->chip, RF2528)) { 2135 if (rt2x00_rf(&rt2x00dev->chip, RF2528)) {
1891 spec->num_channels = ARRAY_SIZE(rf_vals_bg_2528); 2136 spec->num_channels = ARRAY_SIZE(rf_vals_bg_2528);
@@ -1903,14 +2148,26 @@ static void rt73usb_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
1903 spec->channels = rf_vals_5225_2527; 2148 spec->channels = rf_vals_5225_2527;
1904 } 2149 }
1905 2150
1906 if (rt2x00_rf(&rt2x00dev->chip, RF5225) || 2151 /*
1907 rt2x00_rf(&rt2x00dev->chip, RF5226)) { 2152 * Create channel information array
1908 txpower = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_A_START); 2153 */
1909 for (i = 0; i < 14; i++) 2154 info = kzalloc(spec->num_channels * sizeof(*info), GFP_KERNEL);
1910 txpower[i] = TXPOWER_FROM_DEV(txpower[i]); 2155 if (!info)
2156 return -ENOMEM;
1911 2157
1912 spec->tx_power_a = txpower; 2158 spec->channels_info = info;
2159
2160 tx_power = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_G_START);
2161 for (i = 0; i < 14; i++)
2162 info[i].tx_power1 = TXPOWER_FROM_DEV(tx_power[i]);
2163
2164 if (spec->num_channels > 14) {
2165 tx_power = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_A_START);
2166 for (i = 14; i < spec->num_channels; i++)
2167 info[i].tx_power1 = TXPOWER_FROM_DEV(tx_power[i]);
1913 } 2168 }
2169
2170 return 0;
1914} 2171}
1915 2172
1916static int rt73usb_probe_hw(struct rt2x00_dev *rt2x00dev) 2173static int rt73usb_probe_hw(struct rt2x00_dev *rt2x00dev)
@@ -1931,13 +2188,17 @@ static int rt73usb_probe_hw(struct rt2x00_dev *rt2x00dev)
1931 /* 2188 /*
1932 * Initialize hw specifications. 2189 * Initialize hw specifications.
1933 */ 2190 */
1934 rt73usb_probe_hw_mode(rt2x00dev); 2191 retval = rt73usb_probe_hw_mode(rt2x00dev);
2192 if (retval)
2193 return retval;
1935 2194
1936 /* 2195 /*
1937 * This device requires firmware. 2196 * This device requires firmware.
1938 */ 2197 */
1939 __set_bit(DRIVER_REQUIRE_FIRMWARE, &rt2x00dev->flags); 2198 __set_bit(DRIVER_REQUIRE_FIRMWARE, &rt2x00dev->flags);
1940 __set_bit(DRIVER_REQUIRE_SCHEDULED, &rt2x00dev->flags); 2199 __set_bit(DRIVER_REQUIRE_SCHEDULED, &rt2x00dev->flags);
2200 if (!modparam_nohwcrypt)
2201 __set_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags);
1941 2202
1942 /* 2203 /*
1943 * Set the rssi offset. 2204 * Set the rssi offset.
@@ -1964,6 +2225,63 @@ static int rt73usb_set_retry_limit(struct ieee80211_hw *hw,
1964 return 0; 2225 return 0;
1965} 2226}
1966 2227
2228static int rt73usb_conf_tx(struct ieee80211_hw *hw, u16 queue_idx,
2229 const struct ieee80211_tx_queue_params *params)
2230{
2231 struct rt2x00_dev *rt2x00dev = hw->priv;
2232 struct data_queue *queue;
2233 struct rt2x00_field32 field;
2234 int retval;
2235 u32 reg;
2236
2237 /*
2238 * First pass the configuration through rt2x00lib, that will
2239 * update the queue settings and validate the input. After that
2240 * we are free to update the registers based on the value
2241 * in the queue parameter.
2242 */
2243 retval = rt2x00mac_conf_tx(hw, queue_idx, params);
2244 if (retval)
2245 return retval;
2246
2247 queue = rt2x00queue_get_queue(rt2x00dev, queue_idx);
2248
2249 /* Update WMM TXOP register */
2250 if (queue_idx < 2) {
2251 field.bit_offset = queue_idx * 16;
2252 field.bit_mask = 0xffff << field.bit_offset;
2253
2254 rt73usb_register_read(rt2x00dev, AC_TXOP_CSR0, &reg);
2255 rt2x00_set_field32(&reg, field, queue->txop);
2256 rt73usb_register_write(rt2x00dev, AC_TXOP_CSR0, reg);
2257 } else if (queue_idx < 4) {
2258 field.bit_offset = (queue_idx - 2) * 16;
2259 field.bit_mask = 0xffff << field.bit_offset;
2260
2261 rt73usb_register_read(rt2x00dev, AC_TXOP_CSR1, &reg);
2262 rt2x00_set_field32(&reg, field, queue->txop);
2263 rt73usb_register_write(rt2x00dev, AC_TXOP_CSR1, reg);
2264 }
2265
2266 /* Update WMM registers */
2267 field.bit_offset = queue_idx * 4;
2268 field.bit_mask = 0xf << field.bit_offset;
2269
2270 rt73usb_register_read(rt2x00dev, AIFSN_CSR, &reg);
2271 rt2x00_set_field32(&reg, field, queue->aifs);
2272 rt73usb_register_write(rt2x00dev, AIFSN_CSR, reg);
2273
2274 rt73usb_register_read(rt2x00dev, CWMIN_CSR, &reg);
2275 rt2x00_set_field32(&reg, field, queue->cw_min);
2276 rt73usb_register_write(rt2x00dev, CWMIN_CSR, reg);
2277
2278 rt73usb_register_read(rt2x00dev, CWMAX_CSR, &reg);
2279 rt2x00_set_field32(&reg, field, queue->cw_max);
2280 rt73usb_register_write(rt2x00dev, CWMAX_CSR, reg);
2281
2282 return 0;
2283}
2284
1967#if 0 2285#if 0
1968/* 2286/*
1969 * Mac80211 demands get_tsf must be atomic. 2287 * Mac80211 demands get_tsf must be atomic.
@@ -1997,10 +2315,11 @@ static const struct ieee80211_ops rt73usb_mac80211_ops = {
1997 .config = rt2x00mac_config, 2315 .config = rt2x00mac_config,
1998 .config_interface = rt2x00mac_config_interface, 2316 .config_interface = rt2x00mac_config_interface,
1999 .configure_filter = rt2x00mac_configure_filter, 2317 .configure_filter = rt2x00mac_configure_filter,
2318 .set_key = rt2x00mac_set_key,
2000 .get_stats = rt2x00mac_get_stats, 2319 .get_stats = rt2x00mac_get_stats,
2001 .set_retry_limit = rt73usb_set_retry_limit, 2320 .set_retry_limit = rt73usb_set_retry_limit,
2002 .bss_info_changed = rt2x00mac_bss_info_changed, 2321 .bss_info_changed = rt2x00mac_bss_info_changed,
2003 .conf_tx = rt2x00mac_conf_tx, 2322 .conf_tx = rt73usb_conf_tx,
2004 .get_tx_stats = rt2x00mac_get_tx_stats, 2323 .get_tx_stats = rt2x00mac_get_tx_stats,
2005 .get_tsf = rt73usb_get_tsf, 2324 .get_tsf = rt73usb_get_tsf,
2006}; 2325};
@@ -2024,6 +2343,8 @@ static const struct rt2x00lib_ops rt73usb_rt2x00_ops = {
2024 .get_tx_data_len = rt73usb_get_tx_data_len, 2343 .get_tx_data_len = rt73usb_get_tx_data_len,
2025 .kick_tx_queue = rt73usb_kick_tx_queue, 2344 .kick_tx_queue = rt73usb_kick_tx_queue,
2026 .fill_rxdone = rt73usb_fill_rxdone, 2345 .fill_rxdone = rt73usb_fill_rxdone,
2346 .config_shared_key = rt73usb_config_shared_key,
2347 .config_pairwise_key = rt73usb_config_pairwise_key,
2027 .config_filter = rt73usb_config_filter, 2348 .config_filter = rt73usb_config_filter,
2028 .config_intf = rt73usb_config_intf, 2349 .config_intf = rt73usb_config_intf,
2029 .config_erp = rt73usb_config_erp, 2350 .config_erp = rt73usb_config_erp,
diff --git a/drivers/net/wireless/rt2x00/rt73usb.h b/drivers/net/wireless/rt2x00/rt73usb.h
index 148493501011..868386c457f6 100644
--- a/drivers/net/wireless/rt2x00/rt73usb.h
+++ b/drivers/net/wireless/rt2x00/rt73usb.h
@@ -92,6 +92,16 @@
92#define PAIRWISE_KEY_TABLE_BASE 0x1200 92#define PAIRWISE_KEY_TABLE_BASE 0x1200
93#define PAIRWISE_TA_TABLE_BASE 0x1a00 93#define PAIRWISE_TA_TABLE_BASE 0x1a00
94 94
95#define SHARED_KEY_ENTRY(__idx) \
96 ( SHARED_KEY_TABLE_BASE + \
97 ((__idx) * sizeof(struct hw_key_entry)) )
98#define PAIRWISE_KEY_ENTRY(__idx) \
99 ( PAIRWISE_KEY_TABLE_BASE + \
100 ((__idx) * sizeof(struct hw_key_entry)) )
101#define PAIRWISE_TA_ENTRY(__idx) \
102 ( PAIRWISE_TA_TABLE_BASE + \
103 ((__idx) * sizeof(struct hw_pairwise_ta_entry)) )
104
95struct hw_key_entry { 105struct hw_key_entry {
96 u8 key[16]; 106 u8 key[16];
97 u8 tx_mic[8]; 107 u8 tx_mic[8];
@@ -100,7 +110,8 @@ struct hw_key_entry {
100 110
101struct hw_pairwise_ta_entry { 111struct hw_pairwise_ta_entry {
102 u8 address[6]; 112 u8 address[6];
103 u8 reserved[2]; 113 u8 cipher;
114 u8 reserved;
104} __attribute__ ((packed)); 115} __attribute__ ((packed));
105 116
106/* 117/*
@@ -563,6 +574,10 @@ struct hw_pairwise_ta_entry {
563 * SEC_CSR4: Pairwise key table lookup control. 574 * SEC_CSR4: Pairwise key table lookup control.
564 */ 575 */
565#define SEC_CSR4 0x30b0 576#define SEC_CSR4 0x30b0
577#define SEC_CSR4_ENABLE_BSS0 FIELD32(0x00000001)
578#define SEC_CSR4_ENABLE_BSS1 FIELD32(0x00000002)
579#define SEC_CSR4_ENABLE_BSS2 FIELD32(0x00000004)
580#define SEC_CSR4_ENABLE_BSS3 FIELD32(0x00000008)
566 581
567/* 582/*
568 * SEC_CSR5: shared key table security mode register. 583 * SEC_CSR5: shared key table security mode register.
@@ -1010,8 +1025,10 @@ struct hw_pairwise_ta_entry {
1010 1025
1011/* 1026/*
1012 * Word4 1027 * Word4
1028 * ICV: Received ICV of originally encrypted.
1029 * NOTE: This is a guess, the official definition is "reserved"
1013 */ 1030 */
1014#define RXD_W4_RESERVED FIELD32(0xffffffff) 1031#define RXD_W4_ICV FIELD32(0xffffffff)
1015 1032
1016/* 1033/*
1017 * the above 20-byte is called RXINFO and will be DMAed to MAC RX block 1034 * the above 20-byte is called RXINFO and will be DMAed to MAC RX block
@@ -1033,17 +1050,10 @@ struct hw_pairwise_ta_entry {
1033#define MAX_TXPOWER 31 1050#define MAX_TXPOWER 31
1034#define DEFAULT_TXPOWER 24 1051#define DEFAULT_TXPOWER 24
1035 1052
1036#define TXPOWER_FROM_DEV(__txpower) \ 1053#define TXPOWER_FROM_DEV(__txpower) \
1037({ \ 1054 (((u8)(__txpower)) > MAX_TXPOWER) ? DEFAULT_TXPOWER : (__txpower)
1038 ((__txpower) > MAX_TXPOWER) ? \ 1055
1039 DEFAULT_TXPOWER : (__txpower); \ 1056#define TXPOWER_TO_DEV(__txpower) \
1040}) 1057 clamp_t(char, __txpower, MIN_TXPOWER, MAX_TXPOWER)
1041
1042#define TXPOWER_TO_DEV(__txpower) \
1043({ \
1044 ((__txpower) <= MIN_TXPOWER) ? MIN_TXPOWER : \
1045 (((__txpower) >= MAX_TXPOWER) ? MAX_TXPOWER : \
1046 (__txpower)); \
1047})
1048 1058
1049#endif /* RT73USB_H */ 1059#endif /* RT73USB_H */