aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/iwlwifi
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless/iwlwifi')
-rw-r--r--drivers/net/wireless/iwlwifi/Kconfig114
-rw-r--r--drivers/net/wireless/iwlwifi/Makefile12
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945-debug.h4
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945-hw.h13
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945-io.h24
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945-led.c180
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945-led.h3
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945-rs.c213
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945-rs.h9
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945.c322
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945.h59
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-4965-hw.h639
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-4965.c4050
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-5000-hw.h141
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-5000.c1591
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-rs.c (renamed from drivers/net/wireless/iwlwifi/iwl-4965-rs.c)1740
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-rs.h (renamed from drivers/net/wireless/iwlwifi/iwl-4965-rs.h)149
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn.c4549
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-calib.c869
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-calib.h84
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-commands.h (renamed from drivers/net/wireless/iwlwifi/iwl-4965-commands.h)526
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-core.c1303
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-core.h221
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-csr.h50
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-debug.h58
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-debugfs.c114
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-dev.h (renamed from drivers/net/wireless/iwlwifi/iwl-4965.h)655
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-eeprom.c177
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-eeprom.h206
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-fh.h393
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-hcmd.c32
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-helpers.h92
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-io.h22
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-led.c257
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-led.h6
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-power.c465
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-power.h91
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-prph.h345
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-rfkill.c107
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-rfkill.h6
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-rx.c1220
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-scan.c947
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-sta.c721
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-sta.h28
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-tx.c1561
-rw-r--r--drivers/net/wireless/iwlwifi/iwl3945-base.c829
-rw-r--r--drivers/net/wireless/iwlwifi/iwl4965-base.c8038
47 files changed, 17983 insertions, 15252 deletions
diff --git a/drivers/net/wireless/iwlwifi/Kconfig b/drivers/net/wireless/iwlwifi/Kconfig
index 62fb89d82318..b0ac0ce3fb9f 100644
--- a/drivers/net/wireless/iwlwifi/Kconfig
+++ b/drivers/net/wireless/iwlwifi/Kconfig
@@ -8,25 +8,55 @@ config IWLCORE
8 select MAC80211_LEDS if IWLWIFI_LEDS 8 select MAC80211_LEDS if IWLWIFI_LEDS
9 select LEDS_CLASS if IWLWIFI_LEDS 9 select LEDS_CLASS if IWLWIFI_LEDS
10 select RFKILL if IWLWIFI_RFKILL 10 select RFKILL if IWLWIFI_RFKILL
11 select RFKILL_INPUT if IWLWIFI_RFKILL
12 11
13config IWLWIFI_LEDS 12config IWLWIFI_LEDS
14 bool 13 bool
15 default n 14 default n
16 15
17config IWLWIFI_RFKILL 16config IWLWIFI_RFKILL
18 boolean "IWLWIFI RF kill support" 17 boolean "Iwlwifi RF kill support"
19 depends on IWLCORE 18 depends on IWLCORE
20 19
21config IWL4965 20config IWLWIFI_DEBUG
22 tristate "Intel Wireless WiFi 4965AGN" 21 bool "Enable full debugging output in iwlagn driver"
22 depends on IWLCORE
23 ---help---
24 This option will enable debug tracing output for the iwlwifi drivers
25
26 This will result in the kernel module being ~100k larger. You can
27 control which debug output is sent to the kernel log by setting the
28 value in
29
30 /sys/class/net/wlan0/device/debug_level
31
32 This entry will only exist if this option is enabled.
33
34 To set a value, simply echo an 8-byte hex value to the same file:
35
36 % echo 0x43fff > /sys/class/net/wlan0/device/debug_level
37
38 You can find the list of debug mask values in:
39 drivers/net/wireless/iwlwifi/iwl-debug.h
40
41 If this is your first time using this driver, you should say Y here
42 as the debug information can assist others in helping you resolve
43 any problems you may encounter.
44
45config IWLWIFI_DEBUGFS
46 bool "Iwlwifi debugfs support"
47 depends on IWLCORE && IWLWIFI_DEBUG && MAC80211_DEBUGFS
48 ---help---
49 Enable creation of debugfs files for the iwlwifi drivers.
50
51config IWLAGN
52 tristate "Intel Wireless WiFi Next Gen AGN"
23 depends on PCI && MAC80211 && WLAN_80211 && EXPERIMENTAL 53 depends on PCI && MAC80211 && WLAN_80211 && EXPERIMENTAL
24 select FW_LOADER 54 select FW_LOADER
25 select IWLCORE 55 select IWLCORE
26 ---help--- 56 ---help---
27 Select to build the driver supporting the: 57 Select to build the driver supporting the:
28 58
29 Intel Wireless WiFi Link 4965AGN 59 Intel Wireless WiFi Link Next-Gen AGN
30 60
31 This driver uses the kernel's mac80211 subsystem. 61 This driver uses the kernel's mac80211 subsystem.
32 62
@@ -43,68 +73,33 @@ config IWL4965
43 If you want to compile the driver as a module ( = code which can be 73 If you want to compile the driver as a module ( = code which can be
44 inserted in and removed from the running kernel whenever you want), 74 inserted in and removed from the running kernel whenever you want),
45 say M here and read <file:Documentation/kbuild/modules.txt>. The 75 say M here and read <file:Documentation/kbuild/modules.txt>. The
46 module will be called iwl4965.ko. 76 module will be called iwlagn.ko.
47 77
48config IWL4965_HT 78config IWLAGN_SPECTRUM_MEASUREMENT
49 bool "Enable 802.11n HT features in iwl4965 driver" 79 bool "Enable Spectrum Measurement in iwlagn driver"
50 depends on EXPERIMENTAL 80 depends on IWLAGN
51 depends on IWL4965
52 ---help--- 81 ---help---
53 This option enables IEEE 802.11n High Throughput features 82 This option will enable spectrum measurement for the iwlagn driver.
54 for the iwl4965 driver.
55 83
56config IWL4965_LEDS 84config IWLAGN_LEDS
57 bool "Enable LEDS features in iwl4965 driver" 85 bool "Enable LEDS features in iwlagn driver"
58 depends on IWL4965 86 depends on IWLAGN
59 select IWLWIFI_LEDS 87 select IWLWIFI_LEDS
60 ---help--- 88 ---help---
61 This option enables LEDS for the iwlwifi drivers 89 This option enables LEDS for the iwlagn drivers
62 90
63 91
64config IWL4965_SPECTRUM_MEASUREMENT 92config IWL4965
65 bool "Enable Spectrum Measurement in iwl4965 driver" 93 bool "Intel Wireless WiFi 4965AGN"
66 depends on IWL4965 94 depends on IWLAGN
67 ---help--- 95 ---help---
68 This option will enable spectrum measurement for the iwl4965 driver. 96 This option enables support for Intel Wireless WiFi Link 4965AGN
69 97
70config IWL4965_SENSITIVITY 98config IWL5000
71 bool "Enable Sensitivity Calibration in iwl4965 driver" 99 bool "Intel Wireless WiFi 5000AGN"
72 depends on IWL4965 100 depends on IWLAGN
73 ---help--- 101 ---help---
74 This option will enable sensitivity calibration for the iwl4965 102 This option enables support for Intel Wireless WiFi Link 5000AGN Family
75 driver.
76
77config IWLWIFI_DEBUG
78 bool "Enable full debugging output in iwl4965 driver"
79 depends on IWL4965
80 ---help---
81 This option will enable debug tracing output for the iwl4965
82 driver.
83
84 This will result in the kernel module being ~100k larger. You can
85 control which debug output is sent to the kernel log by setting the
86 value in
87
88 /sys/bus/pci/drivers/${DRIVER}/debug_level
89
90 This entry will only exist if this option is enabled.
91
92 To set a value, simply echo an 8-byte hex value to the same file:
93
94 % echo 0x43fff > /sys/bus/pci/drivers/${DRIVER}/debug_level
95
96 You can find the list of debug mask values in:
97 drivers/net/wireless/iwlwifi/iwl-4965-debug.h
98
99 If this is your first time using this driver, you should say Y here
100 as the debug information can assist others in helping you resolve
101 any problems you may encounter.
102
103config IWLWIFI_DEBUGFS
104 bool "Iwlwifi debugfs support"
105 depends on IWLCORE && IWLWIFI_DEBUG && MAC80211_DEBUGFS
106 ---help---
107 Enable creation of debugfs files for the iwlwifi drivers.
108 103
109config IWL3945 104config IWL3945
110 tristate "Intel PRO/Wireless 3945ABG/BG Network Connection" 105 tristate "Intel PRO/Wireless 3945ABG/BG Network Connection"
@@ -113,6 +108,7 @@ config IWL3945
113 select IWLWIFI 108 select IWLWIFI
114 select MAC80211_LEDS if IWL3945_LEDS 109 select MAC80211_LEDS if IWL3945_LEDS
115 select LEDS_CLASS if IWL3945_LEDS 110 select LEDS_CLASS if IWL3945_LEDS
111 select RFKILL if IWL3945_RFKILL
116 ---help--- 112 ---help---
117 Select to build the driver supporting the: 113 Select to build the driver supporting the:
118 114
@@ -135,6 +131,10 @@ config IWL3945
135 say M here and read <file:Documentation/kbuild/modules.txt>. The 131 say M here and read <file:Documentation/kbuild/modules.txt>. The
136 module will be called iwl3945.ko. 132 module will be called iwl3945.ko.
137 133
134config IWL3945_RFKILL
135 bool "Enable RF kill support in iwl3945 drivers"
136 depends on IWL3945
137
138config IWL3945_SPECTRUM_MEASUREMENT 138config IWL3945_SPECTRUM_MEASUREMENT
139 bool "Enable Spectrum Measurement in iwl3945 drivers" 139 bool "Enable Spectrum Measurement in iwl3945 drivers"
140 depends on IWL3945 140 depends on IWL3945
diff --git a/drivers/net/wireless/iwlwifi/Makefile b/drivers/net/wireless/iwlwifi/Makefile
index ec6187b75c3b..47aa28f6a513 100644
--- a/drivers/net/wireless/iwlwifi/Makefile
+++ b/drivers/net/wireless/iwlwifi/Makefile
@@ -1,13 +1,19 @@
1obj-$(CONFIG_IWLCORE) += iwlcore.o 1obj-$(CONFIG_IWLCORE) += iwlcore.o
2iwlcore-objs := iwl-core.o iwl-eeprom.o iwl-hcmd.o 2iwlcore-objs := iwl-core.o iwl-eeprom.o iwl-hcmd.o iwl-power.o
3iwlcore-objs += iwl-rx.o iwl-tx.o iwl-sta.o iwl-calib.o
4iwlcore-objs += iwl-scan.o
3iwlcore-$(CONFIG_IWLWIFI_DEBUGFS) += iwl-debugfs.o 5iwlcore-$(CONFIG_IWLWIFI_DEBUGFS) += iwl-debugfs.o
4iwlcore-$(CONFIG_IWLWIFI_LEDS) += iwl-led.o 6iwlcore-$(CONFIG_IWLWIFI_LEDS) += iwl-led.o
5iwlcore-$(CONFIG_IWLWIFI_RFKILL) += iwl-rfkill.o 7iwlcore-$(CONFIG_IWLWIFI_RFKILL) += iwl-rfkill.o
6 8
9obj-$(CONFIG_IWLAGN) += iwlagn.o
10iwlagn-objs := iwl-agn.o iwl-agn-rs.o
11
12iwlagn-$(CONFIG_IWL4965) += iwl-4965.o
13iwlagn-$(CONFIG_IWL5000) += iwl-5000.o
14
7obj-$(CONFIG_IWL3945) += iwl3945.o 15obj-$(CONFIG_IWL3945) += iwl3945.o
8iwl3945-objs := iwl3945-base.o iwl-3945.o iwl-3945-rs.o 16iwl3945-objs := iwl3945-base.o iwl-3945.o iwl-3945-rs.o
9iwl3945-$(CONFIG_IWL3945_LEDS) += iwl-3945-led.o 17iwl3945-$(CONFIG_IWL3945_LEDS) += iwl-3945-led.o
10 18
11obj-$(CONFIG_IWL4965) += iwl4965.o
12iwl4965-objs := iwl4965-base.o iwl-4965.o iwl-4965-rs.o iwl-sta.o
13 19
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945-debug.h b/drivers/net/wireless/iwlwifi/iwl-3945-debug.h
index f1d002f7b790..33016fb5e9b3 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945-debug.h
+++ b/drivers/net/wireless/iwlwifi/iwl-3945-debug.h
@@ -34,12 +34,12 @@ extern u32 iwl3945_debug_level;
34#define IWL_DEBUG(level, fmt, args...) \ 34#define IWL_DEBUG(level, fmt, args...) \
35do { if (iwl3945_debug_level & (level)) \ 35do { if (iwl3945_debug_level & (level)) \
36 printk(KERN_ERR DRV_NAME": %c %s " fmt, \ 36 printk(KERN_ERR DRV_NAME": %c %s " fmt, \
37 in_interrupt() ? 'I' : 'U', __FUNCTION__ , ## args); } while (0) 37 in_interrupt() ? 'I' : 'U', __func__ , ## args); } while (0)
38 38
39#define IWL_DEBUG_LIMIT(level, fmt, args...) \ 39#define IWL_DEBUG_LIMIT(level, fmt, args...) \
40do { if ((iwl3945_debug_level & (level)) && net_ratelimit()) \ 40do { if ((iwl3945_debug_level & (level)) && net_ratelimit()) \
41 printk(KERN_ERR DRV_NAME": %c %s " fmt, \ 41 printk(KERN_ERR DRV_NAME": %c %s " fmt, \
42 in_interrupt() ? 'I' : 'U', __FUNCTION__ , ## args); } while (0) 42 in_interrupt() ? 'I' : 'U', __func__ , ## args); } while (0)
43 43
44static inline void iwl3945_print_hex_dump(int level, void *p, u32 len) 44static inline void iwl3945_print_hex_dump(int level, void *p, u32 len)
45{ 45{
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945-hw.h b/drivers/net/wireless/iwlwifi/iwl-3945-hw.h
index ad612a8719f4..644bd9e08052 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945-hw.h
+++ b/drivers/net/wireless/iwlwifi/iwl-3945-hw.h
@@ -126,7 +126,7 @@ enum {
126 EEPROM_CHANNEL_ACTIVE = (1 << 3), /* active scanning allowed */ 126 EEPROM_CHANNEL_ACTIVE = (1 << 3), /* active scanning allowed */
127 EEPROM_CHANNEL_RADAR = (1 << 4), /* radar detection required */ 127 EEPROM_CHANNEL_RADAR = (1 << 4), /* radar detection required */
128 EEPROM_CHANNEL_WIDE = (1 << 5), /* 20 MHz channel okay */ 128 EEPROM_CHANNEL_WIDE = (1 << 5), /* 20 MHz channel okay */
129 EEPROM_CHANNEL_NARROW = (1 << 6), /* 10 MHz channel (not used) */ 129 /* Bit 6 Reserved (was Narrow Channel) */
130 EEPROM_CHANNEL_DFS = (1 << 7), /* dynamic freq selection candidate */ 130 EEPROM_CHANNEL_DFS = (1 << 7), /* dynamic freq selection candidate */
131}; 131};
132 132
@@ -289,17 +289,6 @@ struct iwl3945_eeprom {
289#define PCI_REG_WUM8 0x0E8 289#define PCI_REG_WUM8 0x0E8
290#define PCI_CFG_PMC_PME_FROM_D3COLD_SUPPORT (0x80000000) 290#define PCI_CFG_PMC_PME_FROM_D3COLD_SUPPORT (0x80000000)
291 291
292/* SCD (3945 Tx Frame Scheduler) */
293#define SCD_BASE (CSR_BASE + 0x2E00)
294
295#define SCD_MODE_REG (SCD_BASE + 0x000)
296#define SCD_ARASTAT_REG (SCD_BASE + 0x004)
297#define SCD_TXFACT_REG (SCD_BASE + 0x010)
298#define SCD_TXF4MF_REG (SCD_BASE + 0x014)
299#define SCD_TXF5MF_REG (SCD_BASE + 0x020)
300#define SCD_SBYP_MODE_1_REG (SCD_BASE + 0x02C)
301#define SCD_SBYP_MODE_2_REG (SCD_BASE + 0x030)
302
303/*=== FH (data Flow Handler) ===*/ 292/*=== FH (data Flow Handler) ===*/
304#define FH_BASE (0x800) 293#define FH_BASE (0x800)
305 294
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945-io.h b/drivers/net/wireless/iwlwifi/iwl-3945-io.h
index 0b9475114618..b3fe48de3ae7 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945-io.h
+++ b/drivers/net/wireless/iwlwifi/iwl-3945-io.h
@@ -59,7 +59,7 @@
59 * 59 *
60 */ 60 */
61 61
62#define _iwl3945_write32(priv, ofs, val) writel((val), (priv)->hw_base + (ofs)) 62#define _iwl3945_write32(priv, ofs, val) iowrite32((val), (priv)->hw_base + (ofs))
63#ifdef CONFIG_IWL3945_DEBUG 63#ifdef CONFIG_IWL3945_DEBUG
64static inline void __iwl3945_write32(const char *f, u32 l, struct iwl3945_priv *priv, 64static inline void __iwl3945_write32(const char *f, u32 l, struct iwl3945_priv *priv,
65 u32 ofs, u32 val) 65 u32 ofs, u32 val)
@@ -73,14 +73,14 @@ static inline void __iwl3945_write32(const char *f, u32 l, struct iwl3945_priv *
73#define iwl3945_write32(priv, ofs, val) _iwl3945_write32(priv, ofs, val) 73#define iwl3945_write32(priv, ofs, val) _iwl3945_write32(priv, ofs, val)
74#endif 74#endif
75 75
76#define _iwl3945_read32(priv, ofs) readl((priv)->hw_base + (ofs)) 76#define _iwl3945_read32(priv, ofs) ioread32((priv)->hw_base + (ofs))
77#ifdef CONFIG_IWL3945_DEBUG 77#ifdef CONFIG_IWL3945_DEBUG
78static inline u32 __iwl3945_read32(char *f, u32 l, struct iwl3945_priv *priv, u32 ofs) 78static inline u32 __iwl3945_read32(char *f, u32 l, struct iwl3945_priv *priv, u32 ofs)
79{ 79{
80 IWL_DEBUG_IO("read_direct32(0x%08X) - %s %d\n", ofs, f, l); 80 IWL_DEBUG_IO("read_direct32(0x%08X) - %s %d\n", ofs, f, l);
81 return _iwl3945_read32(priv, ofs); 81 return _iwl3945_read32(priv, ofs);
82} 82}
83#define iwl3945_read32(priv, ofs) __iwl3945_read32(__FILE__, __LINE__, priv, ofs) 83#define iwl3945_read32(priv, ofs)__iwl3945_read32(__FILE__, __LINE__, priv, ofs)
84#else 84#else
85#define iwl3945_read32(p, o) _iwl3945_read32(p, o) 85#define iwl3945_read32(p, o) _iwl3945_read32(p, o)
86#endif 86#endif
@@ -153,28 +153,10 @@ static inline void __iwl3945_clear_bit(const char *f, u32 l,
153static inline int _iwl3945_grab_nic_access(struct iwl3945_priv *priv) 153static inline int _iwl3945_grab_nic_access(struct iwl3945_priv *priv)
154{ 154{
155 int ret; 155 int ret;
156 u32 gp_ctl;
157
158#ifdef CONFIG_IWL3945_DEBUG 156#ifdef CONFIG_IWL3945_DEBUG
159 if (atomic_read(&priv->restrict_refcnt)) 157 if (atomic_read(&priv->restrict_refcnt))
160 return 0; 158 return 0;
161#endif 159#endif
162 if (test_bit(STATUS_RF_KILL_HW, &priv->status) ||
163 test_bit(STATUS_RF_KILL_SW, &priv->status)) {
164 IWL_WARNING("WARNING: Requesting MAC access during RFKILL "
165 "wakes up NIC\n");
166
167 /* 10 msec allows time for NIC to complete its data save */
168 gp_ctl = _iwl3945_read32(priv, CSR_GP_CNTRL);
169 if (gp_ctl & CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY) {
170 IWL_DEBUG_RF_KILL("Wait for complete power-down, "
171 "gpctl = 0x%08x\n", gp_ctl);
172 mdelay(10);
173 } else
174 IWL_DEBUG_RF_KILL("power-down complete, "
175 "gpctl = 0x%08x\n", gp_ctl);
176 }
177
178 /* this bit wakes up the NIC */ 160 /* this bit wakes up the NIC */
179 _iwl3945_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); 161 _iwl3945_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
180 ret = _iwl3945_poll_bit(priv, CSR_GP_CNTRL, 162 ret = _iwl3945_poll_bit(priv, CSR_GP_CNTRL,
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945-led.c b/drivers/net/wireless/iwlwifi/iwl-3945-led.c
index 8b1528e52d43..705c65bed9fd 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945-led.c
+++ b/drivers/net/wireless/iwlwifi/iwl-3945-led.c
@@ -27,7 +27,6 @@
27 27
28#include <linux/kernel.h> 28#include <linux/kernel.h>
29#include <linux/module.h> 29#include <linux/module.h>
30#include <linux/version.h>
31#include <linux/init.h> 30#include <linux/init.h>
32#include <linux/pci.h> 31#include <linux/pci.h>
33#include <linux/dma-mapping.h> 32#include <linux/dma-mapping.h>
@@ -42,14 +41,11 @@
42#include "iwl-3945.h" 41#include "iwl-3945.h"
43#include "iwl-helpers.h" 42#include "iwl-helpers.h"
44 43
45#define IWL_1MB_RATE (128 * 1024)
46#define IWL_LED_THRESHOLD (16)
47#define IWL_MAX_BLINK_TBL (10)
48 44
49static const struct { 45static const struct {
50 u16 brightness; 46 u16 brightness;
51 u8 on_time; 47 u8 on_time;
52 u8 of_time; 48 u8 off_time;
53} blink_tbl[] = 49} blink_tbl[] =
54{ 50{
55 {300, 25, 25}, 51 {300, 25, 25},
@@ -61,9 +57,16 @@ static const struct {
61 {15, 95, 95 }, 57 {15, 95, 95 },
62 {10, 110, 110}, 58 {10, 110, 110},
63 {5, 130, 130}, 59 {5, 130, 130},
64 {0, 167, 167} 60 {0, 167, 167},
61 /*SOLID_ON*/
62 {-1, IWL_LED_SOLID, 0}
65}; 63};
66 64
65#define IWL_1MB_RATE (128 * 1024)
66#define IWL_LED_THRESHOLD (16)
67#define IWL_MAX_BLINK_TBL (ARRAY_SIZE(blink_tbl) - 1) /*Exclude Solid on*/
68#define IWL_SOLID_BLINK_IDX (ARRAY_SIZE(blink_tbl) - 1)
69
67static int iwl3945_led_cmd_callback(struct iwl3945_priv *priv, 70static int iwl3945_led_cmd_callback(struct iwl3945_priv *priv,
68 struct iwl3945_cmd *cmd, 71 struct iwl3945_cmd *cmd,
69 struct sk_buff *skb) 72 struct sk_buff *skb)
@@ -71,6 +74,10 @@ static int iwl3945_led_cmd_callback(struct iwl3945_priv *priv,
71 return 1; 74 return 1;
72} 75}
73 76
77static inline int iwl3945_brightness_to_idx(enum led_brightness brightness)
78{
79 return fls(0x000000FF & (u32)brightness);
80}
74 81
75/* Send led command */ 82/* Send led command */
76static int iwl_send_led_cmd(struct iwl3945_priv *priv, 83static int iwl_send_led_cmd(struct iwl3945_priv *priv,
@@ -81,49 +88,45 @@ static int iwl_send_led_cmd(struct iwl3945_priv *priv,
81 .len = sizeof(struct iwl3945_led_cmd), 88 .len = sizeof(struct iwl3945_led_cmd),
82 .data = led_cmd, 89 .data = led_cmd,
83 .meta.flags = CMD_ASYNC, 90 .meta.flags = CMD_ASYNC,
84 .meta.u.callback = iwl3945_led_cmd_callback 91 .meta.u.callback = iwl3945_led_cmd_callback,
85 }; 92 };
86 93
87 return iwl3945_send_cmd(priv, &cmd); 94 return iwl3945_send_cmd(priv, &cmd);
88} 95}
89 96
90 97
98
91/* Set led on command */ 99/* Set led on command */
92static int iwl3945_led_on(struct iwl3945_priv *priv, int led_id) 100static int iwl3945_led_pattern(struct iwl3945_priv *priv, int led_id,
101 unsigned int idx)
93{ 102{
94 struct iwl3945_led_cmd led_cmd = { 103 struct iwl3945_led_cmd led_cmd = {
95 .id = led_id, 104 .id = led_id,
96 .on = IWL_LED_SOLID,
97 .off = 0,
98 .interval = IWL_DEF_LED_INTRVL 105 .interval = IWL_DEF_LED_INTRVL
99 }; 106 };
107
108 BUG_ON(idx > IWL_MAX_BLINK_TBL);
109
110 led_cmd.on = blink_tbl[idx].on_time;
111 led_cmd.off = blink_tbl[idx].off_time;
112
100 return iwl_send_led_cmd(priv, &led_cmd); 113 return iwl_send_led_cmd(priv, &led_cmd);
101} 114}
102 115
116
117#if 1
103/* Set led on command */ 118/* Set led on command */
104static int iwl3945_led_pattern(struct iwl3945_priv *priv, int led_id, 119static int iwl3945_led_on(struct iwl3945_priv *priv, int led_id)
105 enum led_brightness brightness)
106{ 120{
107 struct iwl3945_led_cmd led_cmd = { 121 struct iwl3945_led_cmd led_cmd = {
108 .id = led_id, 122 .id = led_id,
109 .on = brightness, 123 .on = IWL_LED_SOLID,
110 .off = brightness, 124 .off = 0,
111 .interval = IWL_DEF_LED_INTRVL 125 .interval = IWL_DEF_LED_INTRVL
112 }; 126 };
113 if (brightness == LED_FULL) {
114 led_cmd.on = IWL_LED_SOLID;
115 led_cmd.off = 0;
116 }
117 return iwl_send_led_cmd(priv, &led_cmd); 127 return iwl_send_led_cmd(priv, &led_cmd);
118} 128}
119 129
120/* Set led register off */
121static int iwl3945_led_on_reg(struct iwl3945_priv *priv, int led_id)
122{
123 IWL_DEBUG_LED("led on %d\n", led_id);
124 return iwl3945_led_on(priv, led_id);
125}
126
127/* Set led off command */ 130/* Set led off command */
128static int iwl3945_led_off(struct iwl3945_priv *priv, int led_id) 131static int iwl3945_led_off(struct iwl3945_priv *priv, int led_id)
129{ 132{
@@ -136,27 +139,7 @@ static int iwl3945_led_off(struct iwl3945_priv *priv, int led_id)
136 IWL_DEBUG_LED("led off %d\n", led_id); 139 IWL_DEBUG_LED("led off %d\n", led_id);
137 return iwl_send_led_cmd(priv, &led_cmd); 140 return iwl_send_led_cmd(priv, &led_cmd);
138} 141}
139 142#endif
140/* Set led register off */
141static int iwl3945_led_off_reg(struct iwl3945_priv *priv, int led_id)
142{
143 iwl3945_led_off(priv, led_id);
144 return 0;
145}
146
147/* Set led blink command */
148static int iwl3945_led_not_solid(struct iwl3945_priv *priv, int led_id,
149 u8 brightness)
150{
151 struct iwl3945_led_cmd led_cmd = {
152 .id = led_id,
153 .on = brightness,
154 .off = brightness,
155 .interval = IWL_DEF_LED_INTRVL
156 };
157
158 return iwl_send_led_cmd(priv, &led_cmd);
159}
160 143
161 144
162/* 145/*
@@ -206,8 +189,10 @@ static void iwl3945_led_brightness_set(struct led_classdev *led_cdev,
206 led->led_off(priv, IWL_LED_LINK); 189 led->led_off(priv, IWL_LED_LINK);
207 break; 190 break;
208 default: 191 default:
209 if (led->led_pattern) 192 if (led->led_pattern) {
210 led->led_pattern(priv, IWL_LED_LINK, brightness); 193 int idx = iwl3945_brightness_to_idx(brightness);
194 led->led_pattern(priv, IWL_LED_LINK, idx);
195 }
211 break; 196 break;
212 } 197 }
213} 198}
@@ -220,12 +205,12 @@ static void iwl3945_led_brightness_set(struct led_classdev *led_cdev,
220static int iwl3945_led_register_led(struct iwl3945_priv *priv, 205static int iwl3945_led_register_led(struct iwl3945_priv *priv,
221 struct iwl3945_led *led, 206 struct iwl3945_led *led,
222 enum led_type type, u8 set_led, 207 enum led_type type, u8 set_led,
223 const char *name, char *trigger) 208 char *trigger)
224{ 209{
225 struct device *device = wiphy_dev(priv->hw->wiphy); 210 struct device *device = wiphy_dev(priv->hw->wiphy);
226 int ret; 211 int ret;
227 212
228 led->led_dev.name = name; 213 led->led_dev.name = led->name;
229 led->led_dev.brightness_set = iwl3945_led_brightness_set; 214 led->led_dev.brightness_set = iwl3945_led_brightness_set;
230 led->led_dev.default_trigger = trigger; 215 led->led_dev.default_trigger = trigger;
231 216
@@ -252,24 +237,20 @@ static int iwl3945_led_register_led(struct iwl3945_priv *priv,
252static inline u8 get_blink_rate(struct iwl3945_priv *priv) 237static inline u8 get_blink_rate(struct iwl3945_priv *priv)
253{ 238{
254 int index; 239 int index;
255 u8 blink_rate; 240 u64 current_tpt = priv->rxtxpackets;
256 241 s64 tpt = current_tpt - priv->led_tpt;
257 if (priv->rxtxpackets < IWL_LED_THRESHOLD) 242
258 index = 10; 243 if (tpt < 0)
259 else { 244 tpt = -tpt;
260 for (index = 0; index < IWL_MAX_BLINK_TBL; index++) { 245 priv->led_tpt = current_tpt;
261 if (priv->rxtxpackets > (blink_tbl[index].brightness *
262 IWL_1MB_RATE))
263 break;
264 }
265 }
266 /* if 0 frame is transfered */
267 if ((index == IWL_MAX_BLINK_TBL) || !priv->allow_blinking)
268 blink_rate = IWL_LED_SOLID;
269 else
270 blink_rate = blink_tbl[index].on_time;
271 246
272 return blink_rate; 247 if (!priv->allow_blinking)
248 index = IWL_MAX_BLINK_TBL;
249 else
250 for (index = 0; index < IWL_MAX_BLINK_TBL; index++)
251 if (tpt > (blink_tbl[index].brightness * IWL_1MB_RATE))
252 break;
253 return index;
273} 254}
274 255
275static inline int is_rf_kill(struct iwl3945_priv *priv) 256static inline int is_rf_kill(struct iwl3945_priv *priv)
@@ -285,7 +266,7 @@ static inline int is_rf_kill(struct iwl3945_priv *priv)
285 */ 266 */
286void iwl3945_led_background(struct iwl3945_priv *priv) 267void iwl3945_led_background(struct iwl3945_priv *priv)
287{ 268{
288 u8 blink_rate; 269 u8 blink_idx;
289 270
290 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { 271 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
291 priv->last_blink_time = 0; 272 priv->last_blink_time = 0;
@@ -298,9 +279,10 @@ void iwl3945_led_background(struct iwl3945_priv *priv)
298 279
299 if (!priv->allow_blinking) { 280 if (!priv->allow_blinking) {
300 priv->last_blink_time = 0; 281 priv->last_blink_time = 0;
301 if (priv->last_blink_rate != IWL_LED_SOLID) { 282 if (priv->last_blink_rate != IWL_SOLID_BLINK_IDX) {
302 priv->last_blink_rate = IWL_LED_SOLID; 283 priv->last_blink_rate = IWL_SOLID_BLINK_IDX;
303 iwl3945_led_on(priv, IWL_LED_LINK); 284 iwl3945_led_pattern(priv, IWL_LED_LINK,
285 IWL_SOLID_BLINK_IDX);
304 } 286 }
305 return; 287 return;
306 } 288 }
@@ -309,21 +291,14 @@ void iwl3945_led_background(struct iwl3945_priv *priv)
309 msecs_to_jiffies(1000))) 291 msecs_to_jiffies(1000)))
310 return; 292 return;
311 293
312 blink_rate = get_blink_rate(priv); 294 blink_idx = get_blink_rate(priv);
313 295
314 /* call only if blink rate change */ 296 /* call only if blink rate change */
315 if (blink_rate != priv->last_blink_rate) { 297 if (blink_idx != priv->last_blink_rate)
316 if (blink_rate != IWL_LED_SOLID) { 298 iwl3945_led_pattern(priv, IWL_LED_LINK, blink_idx);
317 priv->last_blink_time = jiffies +
318 msecs_to_jiffies(1000);
319 iwl3945_led_not_solid(priv, IWL_LED_LINK, blink_rate);
320 } else {
321 priv->last_blink_time = 0;
322 iwl3945_led_on(priv, IWL_LED_LINK);
323 }
324 }
325 299
326 priv->last_blink_rate = blink_rate; 300 priv->last_blink_time = jiffies;
301 priv->last_blink_rate = blink_idx;
327 priv->rxtxpackets = 0; 302 priv->rxtxpackets = 0;
328} 303}
329 304
@@ -332,54 +307,55 @@ void iwl3945_led_background(struct iwl3945_priv *priv)
332int iwl3945_led_register(struct iwl3945_priv *priv) 307int iwl3945_led_register(struct iwl3945_priv *priv)
333{ 308{
334 char *trigger; 309 char *trigger;
335 char name[32];
336 int ret; 310 int ret;
337 311
338 priv->last_blink_rate = 0; 312 priv->last_blink_rate = 0;
339 priv->rxtxpackets = 0; 313 priv->rxtxpackets = 0;
314 priv->led_tpt = 0;
340 priv->last_blink_time = 0; 315 priv->last_blink_time = 0;
341 priv->allow_blinking = 0; 316 priv->allow_blinking = 0;
342 317
343 trigger = ieee80211_get_radio_led_name(priv->hw); 318 trigger = ieee80211_get_radio_led_name(priv->hw);
344 snprintf(name, sizeof(name), "iwl-%s:radio", 319 snprintf(priv->led[IWL_LED_TRG_RADIO].name,
320 sizeof(priv->led[IWL_LED_TRG_RADIO].name), "iwl-%s:radio",
345 wiphy_name(priv->hw->wiphy)); 321 wiphy_name(priv->hw->wiphy));
346 322
347 priv->led[IWL_LED_TRG_RADIO].led_on = iwl3945_led_on_reg; 323 priv->led[IWL_LED_TRG_RADIO].led_on = iwl3945_led_on;
348 priv->led[IWL_LED_TRG_RADIO].led_off = iwl3945_led_off_reg; 324 priv->led[IWL_LED_TRG_RADIO].led_off = iwl3945_led_off;
349 priv->led[IWL_LED_TRG_RADIO].led_pattern = NULL; 325 priv->led[IWL_LED_TRG_RADIO].led_pattern = NULL;
350 326
351 ret = iwl3945_led_register_led(priv, 327 ret = iwl3945_led_register_led(priv,
352 &priv->led[IWL_LED_TRG_RADIO], 328 &priv->led[IWL_LED_TRG_RADIO],
353 IWL_LED_TRG_RADIO, 1, 329 IWL_LED_TRG_RADIO, 1, trigger);
354 name, trigger); 330
355 if (ret) 331 if (ret)
356 goto exit_fail; 332 goto exit_fail;
357 333
358 trigger = ieee80211_get_assoc_led_name(priv->hw); 334 trigger = ieee80211_get_assoc_led_name(priv->hw);
359 snprintf(name, sizeof(name), "iwl-%s:assoc", 335 snprintf(priv->led[IWL_LED_TRG_ASSOC].name,
336 sizeof(priv->led[IWL_LED_TRG_ASSOC].name), "iwl-%s:assoc",
360 wiphy_name(priv->hw->wiphy)); 337 wiphy_name(priv->hw->wiphy));
361 338
362 ret = iwl3945_led_register_led(priv, 339 ret = iwl3945_led_register_led(priv,
363 &priv->led[IWL_LED_TRG_ASSOC], 340 &priv->led[IWL_LED_TRG_ASSOC],
364 IWL_LED_TRG_ASSOC, 0, 341 IWL_LED_TRG_ASSOC, 0, trigger);
365 name, trigger); 342
366 /* for assoc always turn led on */ 343 /* for assoc always turn led on */
367 priv->led[IWL_LED_TRG_ASSOC].led_on = iwl3945_led_on_reg; 344 priv->led[IWL_LED_TRG_ASSOC].led_on = iwl3945_led_on;
368 priv->led[IWL_LED_TRG_ASSOC].led_off = iwl3945_led_on_reg; 345 priv->led[IWL_LED_TRG_ASSOC].led_off = iwl3945_led_on;
369 priv->led[IWL_LED_TRG_ASSOC].led_pattern = NULL; 346 priv->led[IWL_LED_TRG_ASSOC].led_pattern = NULL;
370 347
371 if (ret) 348 if (ret)
372 goto exit_fail; 349 goto exit_fail;
373 350
374 trigger = ieee80211_get_rx_led_name(priv->hw); 351 trigger = ieee80211_get_rx_led_name(priv->hw);
375 snprintf(name, sizeof(name), "iwl-%s:RX", 352 snprintf(priv->led[IWL_LED_TRG_RX].name,
353 sizeof(priv->led[IWL_LED_TRG_RX].name), "iwl-%s:RX",
376 wiphy_name(priv->hw->wiphy)); 354 wiphy_name(priv->hw->wiphy));
377 355
378
379 ret = iwl3945_led_register_led(priv, 356 ret = iwl3945_led_register_led(priv,
380 &priv->led[IWL_LED_TRG_RX], 357 &priv->led[IWL_LED_TRG_RX],
381 IWL_LED_TRG_RX, 0, 358 IWL_LED_TRG_RX, 0, trigger);
382 name, trigger);
383 359
384 priv->led[IWL_LED_TRG_RX].led_on = iwl3945_led_associated; 360 priv->led[IWL_LED_TRG_RX].led_on = iwl3945_led_associated;
385 priv->led[IWL_LED_TRG_RX].led_off = iwl3945_led_associated; 361 priv->led[IWL_LED_TRG_RX].led_off = iwl3945_led_associated;
@@ -389,12 +365,14 @@ int iwl3945_led_register(struct iwl3945_priv *priv)
389 goto exit_fail; 365 goto exit_fail;
390 366
391 trigger = ieee80211_get_tx_led_name(priv->hw); 367 trigger = ieee80211_get_tx_led_name(priv->hw);
392 snprintf(name, sizeof(name), "iwl-%s:TX", 368 snprintf(priv->led[IWL_LED_TRG_TX].name,
369 sizeof(priv->led[IWL_LED_TRG_TX].name), "iwl-%s:TX",
393 wiphy_name(priv->hw->wiphy)); 370 wiphy_name(priv->hw->wiphy));
371
394 ret = iwl3945_led_register_led(priv, 372 ret = iwl3945_led_register_led(priv,
395 &priv->led[IWL_LED_TRG_TX], 373 &priv->led[IWL_LED_TRG_TX],
396 IWL_LED_TRG_TX, 0, 374 IWL_LED_TRG_TX, 0, trigger);
397 name, trigger); 375
398 priv->led[IWL_LED_TRG_TX].led_on = iwl3945_led_associated; 376 priv->led[IWL_LED_TRG_TX].led_on = iwl3945_led_associated;
399 priv->led[IWL_LED_TRG_TX].led_off = iwl3945_led_associated; 377 priv->led[IWL_LED_TRG_TX].led_off = iwl3945_led_associated;
400 priv->led[IWL_LED_TRG_TX].led_pattern = iwl3945_led_pattern; 378 priv->led[IWL_LED_TRG_TX].led_pattern = iwl3945_led_pattern;
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945-led.h b/drivers/net/wireless/iwlwifi/iwl-3945-led.h
index b1d2f6b8b259..2fbd126c1347 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945-led.h
+++ b/drivers/net/wireless/iwlwifi/iwl-3945-led.h
@@ -50,11 +50,12 @@ enum led_type {
50struct iwl3945_led { 50struct iwl3945_led {
51 struct iwl3945_priv *priv; 51 struct iwl3945_priv *priv;
52 struct led_classdev led_dev; 52 struct led_classdev led_dev;
53 char name[32];
53 54
54 int (*led_on) (struct iwl3945_priv *priv, int led_id); 55 int (*led_on) (struct iwl3945_priv *priv, int led_id);
55 int (*led_off) (struct iwl3945_priv *priv, int led_id); 56 int (*led_off) (struct iwl3945_priv *priv, int led_id);
56 int (*led_pattern) (struct iwl3945_priv *priv, int led_id, 57 int (*led_pattern) (struct iwl3945_priv *priv, int led_id,
57 enum led_brightness brightness); 58 unsigned int idx);
58 59
59 enum led_type type; 60 enum led_type type;
60 unsigned int registered; 61 unsigned int registered;
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945-rs.c b/drivers/net/wireless/iwlwifi/iwl-3945-rs.c
index 85c22641542d..6fc5e7361f26 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945-rs.c
+++ b/drivers/net/wireless/iwlwifi/iwl-3945-rs.c
@@ -29,7 +29,6 @@
29#include <linux/skbuff.h> 29#include <linux/skbuff.h>
30#include <linux/wireless.h> 30#include <linux/wireless.h>
31#include <net/mac80211.h> 31#include <net/mac80211.h>
32#include <net/ieee80211.h>
33 32
34#include <linux/netdevice.h> 33#include <linux/netdevice.h>
35#include <linux/etherdevice.h> 34#include <linux/etherdevice.h>
@@ -37,8 +36,6 @@
37 36
38#include <linux/workqueue.h> 37#include <linux/workqueue.h>
39 38
40#include "../net/mac80211/rate.h"
41
42#include "iwl-3945.h" 39#include "iwl-3945.h"
43 40
44#define RS_NAME "iwl-3945-rs" 41#define RS_NAME "iwl-3945-rs"
@@ -66,6 +63,9 @@ struct iwl3945_rs_sta {
66 u8 ibss_sta_added; 63 u8 ibss_sta_added;
67 struct timer_list rate_scale_flush; 64 struct timer_list rate_scale_flush;
68 struct iwl3945_rate_scale_data win[IWL_RATE_COUNT]; 65 struct iwl3945_rate_scale_data win[IWL_RATE_COUNT];
66
67 /* used to be in sta_info */
68 int last_txrate_idx;
69}; 69};
70 70
71static s32 iwl3945_expected_tpt_g[IWL_RATE_COUNT] = { 71static s32 iwl3945_expected_tpt_g[IWL_RATE_COUNT] = {
@@ -317,9 +317,10 @@ static void iwl3945_collect_tx_data(struct iwl3945_rs_sta *rs_sta,
317 } 317 }
318} 318}
319 319
320static void rs_rate_init(void *priv_rate, void *priv_sta, 320static void rs_rate_init(void *priv, struct ieee80211_supported_band *sband,
321 struct ieee80211_local *local, struct sta_info *sta) 321 struct ieee80211_sta *sta, void *priv_sta)
322{ 322{
323 struct iwl3945_rs_sta *rs_sta = priv_sta;
323 int i; 324 int i;
324 325
325 IWL_DEBUG_RATE("enter\n"); 326 IWL_DEBUG_RATE("enter\n");
@@ -330,24 +331,22 @@ static void rs_rate_init(void *priv_rate, void *priv_sta,
330 * after assoc.. */ 331 * after assoc.. */
331 332
332 for (i = IWL_RATE_COUNT - 1; i >= 0; i--) { 333 for (i = IWL_RATE_COUNT - 1; i >= 0; i--) {
333 if (sta->supp_rates[local->hw.conf.channel->band] & (1 << i)) { 334 if (sta->supp_rates[sband->band] & (1 << i)) {
334 sta->txrate_idx = i; 335 rs_sta->last_txrate_idx = i;
335 break; 336 break;
336 } 337 }
337 } 338 }
338 339
339 sta->last_txrate_idx = sta->txrate_idx;
340
341 /* For 5 GHz band it start at IWL_FIRST_OFDM_RATE */ 340 /* For 5 GHz band it start at IWL_FIRST_OFDM_RATE */
342 if (local->hw.conf.channel->band == IEEE80211_BAND_5GHZ) 341 if (sband->band == IEEE80211_BAND_5GHZ)
343 sta->last_txrate_idx += IWL_FIRST_OFDM_RATE; 342 rs_sta->last_txrate_idx += IWL_FIRST_OFDM_RATE;
344 343
345 IWL_DEBUG_RATE("leave\n"); 344 IWL_DEBUG_RATE("leave\n");
346} 345}
347 346
348static void *rs_alloc(struct ieee80211_local *local) 347static void *rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
349{ 348{
350 return local->hw.priv; 349 return hw->priv;
351} 350}
352 351
353/* rate scale requires free function to be implemented */ 352/* rate scale requires free function to be implemented */
@@ -355,17 +354,24 @@ static void rs_free(void *priv)
355{ 354{
356 return; 355 return;
357} 356}
357
358static void rs_clear(void *priv) 358static void rs_clear(void *priv)
359{ 359{
360 return; 360 return;
361} 361}
362 362
363 363
364static void *rs_alloc_sta(void *priv, gfp_t gfp) 364static void *rs_alloc_sta(void *priv, struct ieee80211_sta *sta, gfp_t gfp)
365{ 365{
366 struct iwl3945_rs_sta *rs_sta; 366 struct iwl3945_rs_sta *rs_sta;
367 struct iwl3945_sta_priv *psta = (void *) sta->drv_priv;
367 int i; 368 int i;
368 369
370 /*
371 * XXX: If it's using sta->drv_priv anyway, it might
372 * as well just put all the information there.
373 */
374
369 IWL_DEBUG_RATE("enter\n"); 375 IWL_DEBUG_RATE("enter\n");
370 376
371 rs_sta = kzalloc(sizeof(struct iwl3945_rs_sta), gfp); 377 rs_sta = kzalloc(sizeof(struct iwl3945_rs_sta), gfp);
@@ -374,6 +380,8 @@ static void *rs_alloc_sta(void *priv, gfp_t gfp)
374 return NULL; 380 return NULL;
375 } 381 }
376 382
383 psta->rs_sta = rs_sta;
384
377 spin_lock_init(&rs_sta->lock); 385 spin_lock_init(&rs_sta->lock);
378 386
379 rs_sta->start_rate = IWL_RATE_INVALID; 387 rs_sta->start_rate = IWL_RATE_INVALID;
@@ -399,10 +407,14 @@ static void *rs_alloc_sta(void *priv, gfp_t gfp)
399 return rs_sta; 407 return rs_sta;
400} 408}
401 409
402static void rs_free_sta(void *priv, void *priv_sta) 410static void rs_free_sta(void *priv, struct ieee80211_sta *sta,
411 void *priv_sta)
403{ 412{
413 struct iwl3945_sta_priv *psta = (void *) sta->drv_priv;
404 struct iwl3945_rs_sta *rs_sta = priv_sta; 414 struct iwl3945_rs_sta *rs_sta = priv_sta;
405 415
416 psta->rs_sta = NULL;
417
406 IWL_DEBUG_RATE("enter\n"); 418 IWL_DEBUG_RATE("enter\n");
407 del_timer_sync(&rs_sta->rate_scale_flush); 419 del_timer_sync(&rs_sta->rate_scale_flush);
408 kfree(rs_sta); 420 kfree(rs_sta);
@@ -444,44 +456,31 @@ static int rs_adjust_next_rate(struct iwl3945_priv *priv, int rate)
444 * NOTE: Uses iwl3945_priv->retry_rate for the # of retries attempted by 456 * NOTE: Uses iwl3945_priv->retry_rate for the # of retries attempted by
445 * the hardware for each rate. 457 * the hardware for each rate.
446 */ 458 */
447static void rs_tx_status(void *priv_rate, 459static void rs_tx_status(void *priv_rate, struct ieee80211_supported_band *sband,
448 struct net_device *dev, 460 struct ieee80211_sta *sta, void *priv_sta,
449 struct sk_buff *skb, 461 struct sk_buff *skb)
450 struct ieee80211_tx_status *tx_resp)
451{ 462{
452 u8 retries, current_count; 463 u8 retries, current_count;
453 int scale_rate_index, first_index, last_index; 464 int scale_rate_index, first_index, last_index;
454 unsigned long flags; 465 unsigned long flags;
455 struct sta_info *sta;
456 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
457 struct iwl3945_priv *priv = (struct iwl3945_priv *)priv_rate; 466 struct iwl3945_priv *priv = (struct iwl3945_priv *)priv_rate;
458 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 467 struct iwl3945_rs_sta *rs_sta = priv_sta;
459 struct iwl3945_rs_sta *rs_sta; 468 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
460 struct ieee80211_supported_band *sband;
461 469
462 IWL_DEBUG_RATE("enter\n"); 470 IWL_DEBUG_RATE("enter\n");
463 471
464 sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; 472 retries = info->status.retry_count;
465 473 first_index = sband->bitrates[info->tx_rate_idx].hw_value;
466
467 retries = tx_resp->retry_count;
468 first_index = tx_resp->control.tx_rate->hw_value;
469 if ((first_index < 0) || (first_index >= IWL_RATE_COUNT)) { 474 if ((first_index < 0) || (first_index >= IWL_RATE_COUNT)) {
470 IWL_DEBUG_RATE("leave: Rate out of bounds: %d\n", first_index); 475 IWL_DEBUG_RATE("leave: Rate out of bounds: %d\n", first_index);
471 return; 476 return;
472 } 477 }
473 478
474 rcu_read_lock(); 479 if (!priv_sta) {
475
476 sta = sta_info_get(local, hdr->addr1);
477 if (!sta || !sta->rate_ctrl_priv) {
478 rcu_read_unlock();
479 IWL_DEBUG_RATE("leave: No STA priv data to update!\n"); 480 IWL_DEBUG_RATE("leave: No STA priv data to update!\n");
480 return; 481 return;
481 } 482 }
482 483
483 rs_sta = (void *)sta->rate_ctrl_priv;
484
485 rs_sta->tx_packets++; 484 rs_sta->tx_packets++;
486 485
487 scale_rate_index = first_index; 486 scale_rate_index = first_index;
@@ -526,11 +525,11 @@ static void rs_tx_status(void *priv_rate,
526 /* Update the last index window with success/failure based on ACK */ 525 /* Update the last index window with success/failure based on ACK */
527 IWL_DEBUG_RATE("Update rate %d with %s.\n", 526 IWL_DEBUG_RATE("Update rate %d with %s.\n",
528 last_index, 527 last_index,
529 (tx_resp->flags & IEEE80211_TX_STATUS_ACK) ? 528 (info->flags & IEEE80211_TX_STAT_ACK) ?
530 "success" : "failure"); 529 "success" : "failure");
531 iwl3945_collect_tx_data(rs_sta, 530 iwl3945_collect_tx_data(rs_sta,
532 &rs_sta->win[last_index], 531 &rs_sta->win[last_index],
533 tx_resp->flags & IEEE80211_TX_STATUS_ACK, 1); 532 info->flags & IEEE80211_TX_STAT_ACK, 1);
534 533
535 /* We updated the rate scale window -- if its been more than 534 /* We updated the rate scale window -- if its been more than
536 * flush_time since the last run, schedule the flush 535 * flush_time since the last run, schedule the flush
@@ -548,8 +547,6 @@ static void rs_tx_status(void *priv_rate,
548 547
549 spin_unlock_irqrestore(&rs_sta->lock, flags); 548 spin_unlock_irqrestore(&rs_sta->lock, flags);
550 549
551 rcu_read_unlock();
552
553 IWL_DEBUG_RATE("leave\n"); 550 IWL_DEBUG_RATE("leave\n");
554 551
555 return; 552 return;
@@ -633,16 +630,15 @@ static u16 iwl3945_get_adjacent_rate(struct iwl3945_rs_sta *rs_sta,
633 * rate table and must reference the driver allocated rate table 630 * rate table and must reference the driver allocated rate table
634 * 631 *
635 */ 632 */
636static void rs_get_rate(void *priv_rate, struct net_device *dev, 633static void rs_get_rate(void *priv_r, struct ieee80211_supported_band *sband,
637 struct ieee80211_supported_band *sband, 634 struct ieee80211_sta *sta, void *priv_sta,
638 struct sk_buff *skb, 635 struct sk_buff *skb, struct rate_selection *sel)
639 struct rate_selection *sel)
640{ 636{
641 u8 low = IWL_RATE_INVALID; 637 u8 low = IWL_RATE_INVALID;
642 u8 high = IWL_RATE_INVALID; 638 u8 high = IWL_RATE_INVALID;
643 u16 high_low; 639 u16 high_low;
644 int index; 640 int index;
645 struct iwl3945_rs_sta *rs_sta; 641 struct iwl3945_rs_sta *rs_sta = priv_sta;
646 struct iwl3945_rate_scale_data *window = NULL; 642 struct iwl3945_rate_scale_data *window = NULL;
647 int current_tpt = IWL_INV_TPT; 643 int current_tpt = IWL_INV_TPT;
648 int low_tpt = IWL_INV_TPT; 644 int low_tpt = IWL_INV_TPT;
@@ -650,40 +646,31 @@ static void rs_get_rate(void *priv_rate, struct net_device *dev,
650 u32 fail_count; 646 u32 fail_count;
651 s8 scale_action = 0; 647 s8 scale_action = 0;
652 unsigned long flags; 648 unsigned long flags;
653 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
654 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 649 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
655 struct sta_info *sta;
656 u16 fc, rate_mask; 650 u16 fc, rate_mask;
657 struct iwl3945_priv *priv = (struct iwl3945_priv *)priv_rate; 651 struct iwl3945_priv *priv = (struct iwl3945_priv *)priv_r;
658 DECLARE_MAC_BUF(mac); 652 DECLARE_MAC_BUF(mac);
659 653
660 IWL_DEBUG_RATE("enter\n"); 654 IWL_DEBUG_RATE("enter\n");
661 655
662 rcu_read_lock();
663
664 sta = sta_info_get(local, hdr->addr1);
665
666 /* Send management frames and broadcast/multicast data using lowest 656 /* Send management frames and broadcast/multicast data using lowest
667 * rate. */ 657 * rate. */
668 fc = le16_to_cpu(hdr->frame_control); 658 fc = le16_to_cpu(hdr->frame_control);
669 if ((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA || 659 if ((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA ||
670 is_multicast_ether_addr(hdr->addr1) || 660 is_multicast_ether_addr(hdr->addr1) ||
671 !sta || !sta->rate_ctrl_priv) { 661 !sta || !priv_sta) {
672 IWL_DEBUG_RATE("leave: No STA priv data to update!\n"); 662 IWL_DEBUG_RATE("leave: No STA priv data to update!\n");
673 sel->rate = rate_lowest(local, sband, sta); 663 sel->rate_idx = rate_lowest_index(sband, sta);
674 rcu_read_unlock();
675 return; 664 return;
676 } 665 }
677 666
678 rate_mask = sta->supp_rates[sband->band]; 667 rate_mask = sta->supp_rates[sband->band];
679 index = min(sta->last_txrate_idx & 0xffff, IWL_RATE_COUNT - 1); 668 index = min(rs_sta->last_txrate_idx & 0xffff, IWL_RATE_COUNT - 1);
680 669
681 if (sband->band == IEEE80211_BAND_5GHZ) 670 if (sband->band == IEEE80211_BAND_5GHZ)
682 rate_mask = rate_mask << IWL_FIRST_OFDM_RATE; 671 rate_mask = rate_mask << IWL_FIRST_OFDM_RATE;
683 672
684 rs_sta = (void *)sta->rate_ctrl_priv; 673 if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) &&
685
686 if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) &&
687 !rs_sta->ibss_sta_added) { 674 !rs_sta->ibss_sta_added) {
688 u8 sta_id = iwl3945_hw_find_station(priv, hdr->addr1); 675 u8 sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
689 676
@@ -804,17 +791,13 @@ static void rs_get_rate(void *priv_rate, struct net_device *dev,
804 791
805 out: 792 out:
806 793
807 sta->last_txrate_idx = index; 794 rs_sta->last_txrate_idx = index;
808 if (sband->band == IEEE80211_BAND_5GHZ) 795 if (sband->band == IEEE80211_BAND_5GHZ)
809 sta->txrate_idx = sta->last_txrate_idx - IWL_FIRST_OFDM_RATE; 796 sel->rate_idx = rs_sta->last_txrate_idx - IWL_FIRST_OFDM_RATE;
810 else 797 else
811 sta->txrate_idx = sta->last_txrate_idx; 798 sel->rate_idx = rs_sta->last_txrate_idx;
812
813 rcu_read_unlock();
814 799
815 IWL_DEBUG_RATE("leave: %d\n", index); 800 IWL_DEBUG_RATE("leave: %d\n", index);
816
817 sel->rate = &sband->bitrates[sta->txrate_idx];
818} 801}
819 802
820static struct rate_control_ops rs_ops = { 803static struct rate_control_ops rs_ops = {
@@ -830,114 +813,28 @@ static struct rate_control_ops rs_ops = {
830 .free_sta = rs_free_sta, 813 .free_sta = rs_free_sta,
831}; 814};
832 815
833int iwl3945_fill_rs_info(struct ieee80211_hw *hw, char *buf, u8 sta_id)
834{
835 struct ieee80211_local *local = hw_to_local(hw);
836 struct iwl3945_priv *priv = hw->priv;
837 struct iwl3945_rs_sta *rs_sta;
838 struct sta_info *sta;
839 unsigned long flags;
840 int count = 0, i;
841 u32 samples = 0, success = 0, good = 0;
842 unsigned long now = jiffies;
843 u32 max_time = 0;
844
845 rcu_read_lock();
846
847 sta = sta_info_get(local, priv->stations[sta_id].sta.sta.addr);
848 if (!sta || !sta->rate_ctrl_priv) {
849 if (sta)
850 IWL_DEBUG_RATE("leave - no private rate data!\n");
851 else
852 IWL_DEBUG_RATE("leave - no station!\n");
853 rcu_read_unlock();
854 return sprintf(buf, "station %d not found\n", sta_id);
855 }
856
857 rs_sta = (void *)sta->rate_ctrl_priv;
858 spin_lock_irqsave(&rs_sta->lock, flags);
859 i = IWL_RATE_54M_INDEX;
860 while (1) {
861 u64 mask;
862 int j;
863
864 count +=
865 sprintf(&buf[count], " %2dMbs: ", iwl3945_rates[i].ieee / 2);
866
867 mask = (1ULL << (IWL_RATE_MAX_WINDOW - 1));
868 for (j = 0; j < IWL_RATE_MAX_WINDOW; j++, mask >>= 1)
869 buf[count++] =
870 (rs_sta->win[i].data & mask) ? '1' : '0';
871
872 samples += rs_sta->win[i].counter;
873 good += rs_sta->win[i].success_counter;
874 success += rs_sta->win[i].success_counter *
875 iwl3945_rates[i].ieee;
876
877 if (rs_sta->win[i].stamp) {
878 int delta =
879 jiffies_to_msecs(now - rs_sta->win[i].stamp);
880
881 if (delta > max_time)
882 max_time = delta;
883
884 count += sprintf(&buf[count], "%5dms\n", delta);
885 } else
886 buf[count++] = '\n';
887
888 j = iwl3945_get_prev_ieee_rate(i);
889 if (j == i)
890 break;
891 i = j;
892 }
893 spin_unlock_irqrestore(&rs_sta->lock, flags);
894 rcu_read_unlock();
895
896 /* Display the average rate of all samples taken.
897 *
898 * NOTE: We multiple # of samples by 2 since the IEEE measurement
899 * added from iwl3945_rates is actually 2X the rate */
900 if (samples)
901 count += sprintf(
902 &buf[count],
903 "\nAverage rate is %3d.%02dMbs over last %4dms\n"
904 "%3d%% success (%d good packets over %d tries)\n",
905 success / (2 * samples), (success * 5 / samples) % 10,
906 max_time, good * 100 / samples, good, samples);
907 else
908 count += sprintf(&buf[count], "\nAverage rate: 0Mbs\n");
909
910 return count;
911}
912
913void iwl3945_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id) 816void iwl3945_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id)
914{ 817{
915 struct iwl3945_priv *priv = hw->priv; 818 struct iwl3945_priv *priv = hw->priv;
916 s32 rssi = 0; 819 s32 rssi = 0;
917 unsigned long flags; 820 unsigned long flags;
918 struct ieee80211_local *local = hw_to_local(hw);
919 struct iwl3945_rs_sta *rs_sta; 821 struct iwl3945_rs_sta *rs_sta;
920 struct sta_info *sta; 822 struct ieee80211_sta *sta;
823 struct iwl3945_sta_priv *psta;
921 824
922 IWL_DEBUG_RATE("enter\n"); 825 IWL_DEBUG_RATE("enter\n");
923 826
924 if (!local->rate_ctrl->ops->name ||
925 strcmp(local->rate_ctrl->ops->name, RS_NAME)) {
926 IWL_WARNING("iwl-3945-rs not selected as rate control algo!\n");
927 IWL_DEBUG_RATE("leave - mac80211 picked the wrong RC algo.\n");
928 return;
929 }
930
931 rcu_read_lock(); 827 rcu_read_lock();
932 828
933 sta = sta_info_get(local, priv->stations[sta_id].sta.sta.addr); 829 sta = ieee80211_find_sta(hw, priv->stations[sta_id].sta.sta.addr);
934 if (!sta || !sta->rate_ctrl_priv) { 830 psta = (void *) sta->drv_priv;
831 if (!sta || !psta) {
935 IWL_DEBUG_RATE("leave - no private rate data!\n"); 832 IWL_DEBUG_RATE("leave - no private rate data!\n");
936 rcu_read_unlock(); 833 rcu_read_unlock();
937 return; 834 return;
938 } 835 }
939 836
940 rs_sta = (void *)sta->rate_ctrl_priv; 837 rs_sta = psta->rs_sta;
941 838
942 spin_lock_irqsave(&rs_sta->lock, flags); 839 spin_lock_irqsave(&rs_sta->lock, flags);
943 840
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945-rs.h b/drivers/net/wireless/iwlwifi/iwl-3945-rs.h
index f085d330bdcf..98b17ae6ef24 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945-rs.h
+++ b/drivers/net/wireless/iwlwifi/iwl-3945-rs.h
@@ -176,15 +176,6 @@ static inline u8 iwl3945_get_prev_ieee_rate(u8 rate_index)
176} 176}
177 177
178/** 178/**
179 * iwl3945_fill_rs_info - Fill an output text buffer with the rate representation
180 *
181 * NOTE: This is provided as a quick mechanism for a user to visualize
182 * the performance of the rate control algorithm and is not meant to be
183 * parsed software.
184 */
185extern int iwl3945_fill_rs_info(struct ieee80211_hw *, char *buf, u8 sta_id);
186
187/**
188 * iwl3945_rate_scale_init - Initialize the rate scale table based on assoc info 179 * iwl3945_rate_scale_init - Initialize the rate scale table based on assoc info
189 * 180 *
190 * The specific throughput table used is based on the type of network 181 * The specific throughput table used is based on the type of network
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945.c b/drivers/net/wireless/iwlwifi/iwl-3945.c
index 55ac850744b3..7ca5627cc078 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945.c
+++ b/drivers/net/wireless/iwlwifi/iwl-3945.c
@@ -26,7 +26,6 @@
26 26
27#include <linux/kernel.h> 27#include <linux/kernel.h>
28#include <linux/module.h> 28#include <linux/module.h>
29#include <linux/version.h>
30#include <linux/init.h> 29#include <linux/init.h>
31#include <linux/pci.h> 30#include <linux/pci.h>
32#include <linux/dma-mapping.h> 31#include <linux/dma-mapping.h>
@@ -283,8 +282,7 @@ static void iwl3945_tx_queue_reclaim(struct iwl3945_priv *priv,
283 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) { 282 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
284 283
285 tx_info = &txq->txb[txq->q.read_ptr]; 284 tx_info = &txq->txb[txq->q.read_ptr];
286 ieee80211_tx_status_irqsafe(priv->hw, tx_info->skb[0], 285 ieee80211_tx_status_irqsafe(priv->hw, tx_info->skb[0]);
287 &tx_info->status);
288 tx_info->skb[0] = NULL; 286 tx_info->skb[0] = NULL;
289 iwl3945_hw_txq_free_tfd(priv, txq); 287 iwl3945_hw_txq_free_tfd(priv, txq);
290 } 288 }
@@ -306,7 +304,7 @@ static void iwl3945_rx_reply_tx(struct iwl3945_priv *priv,
306 int txq_id = SEQ_TO_QUEUE(sequence); 304 int txq_id = SEQ_TO_QUEUE(sequence);
307 int index = SEQ_TO_INDEX(sequence); 305 int index = SEQ_TO_INDEX(sequence);
308 struct iwl3945_tx_queue *txq = &priv->txq[txq_id]; 306 struct iwl3945_tx_queue *txq = &priv->txq[txq_id];
309 struct ieee80211_tx_status *tx_status; 307 struct ieee80211_tx_info *info;
310 struct iwl3945_tx_resp *tx_resp = (void *)&pkt->u.raw[0]; 308 struct iwl3945_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
311 u32 status = le32_to_cpu(tx_resp->status); 309 u32 status = le32_to_cpu(tx_resp->status);
312 int rate_idx; 310 int rate_idx;
@@ -319,19 +317,22 @@ static void iwl3945_rx_reply_tx(struct iwl3945_priv *priv,
319 return; 317 return;
320 } 318 }
321 319
322 tx_status = &(txq->txb[txq->q.read_ptr].status); 320 info = IEEE80211_SKB_CB(txq->txb[txq->q.read_ptr].skb[0]);
321 memset(&info->status, 0, sizeof(info->status));
323 322
324 tx_status->retry_count = tx_resp->failure_frame; 323 info->status.retry_count = tx_resp->failure_frame;
325 /* tx_status->rts_retry_count = tx_resp->failure_rts; */ 324 /* tx_status->rts_retry_count = tx_resp->failure_rts; */
326 tx_status->flags = ((status & TX_STATUS_MSK) == TX_STATUS_SUCCESS) ? 325 info->flags |= ((status & TX_STATUS_MSK) == TX_STATUS_SUCCESS) ?
327 IEEE80211_TX_STATUS_ACK : 0; 326 IEEE80211_TX_STAT_ACK : 0;
328 327
329 IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) plcp rate %d retries %d\n", 328 IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) plcp rate %d retries %d\n",
330 txq_id, iwl3945_get_tx_fail_reason(status), status, 329 txq_id, iwl3945_get_tx_fail_reason(status), status,
331 tx_resp->rate, tx_resp->failure_frame); 330 tx_resp->rate, tx_resp->failure_frame);
332 331
333 rate_idx = iwl3945_hwrate_to_plcp_idx(tx_resp->rate); 332 rate_idx = iwl3945_hwrate_to_plcp_idx(tx_resp->rate);
334 tx_status->control.tx_rate = &priv->ieee_rates[rate_idx]; 333 if (info->band == IEEE80211_BAND_5GHZ)
334 rate_idx -= IWL_FIRST_OFDM_RATE;
335 info->tx_rate_idx = rate_idx;
335 IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index); 336 IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index);
336 iwl3945_tx_queue_reclaim(priv, txq_id, index); 337 iwl3945_tx_queue_reclaim(priv, txq_id, index);
337 338
@@ -386,7 +387,7 @@ static void iwl3945_dbg_report_frame(struct iwl3945_priv *priv,
386 u32 print_dump = 0; /* set to 1 to dump all frames' contents */ 387 u32 print_dump = 0; /* set to 1 to dump all frames' contents */
387 u32 hundred = 0; 388 u32 hundred = 0;
388 u32 dataframe = 0; 389 u32 dataframe = 0;
389 u16 fc; 390 __le16 fc;
390 u16 seq_ctl; 391 u16 seq_ctl;
391 u16 channel; 392 u16 channel;
392 u16 phy_flags; 393 u16 phy_flags;
@@ -405,7 +406,7 @@ static void iwl3945_dbg_report_frame(struct iwl3945_priv *priv,
405 u8 *data = IWL_RX_DATA(pkt); 406 u8 *data = IWL_RX_DATA(pkt);
406 407
407 /* MAC header */ 408 /* MAC header */
408 fc = le16_to_cpu(header->frame_control); 409 fc = header->frame_control;
409 seq_ctl = le16_to_cpu(header->seq_ctrl); 410 seq_ctl = le16_to_cpu(header->seq_ctrl);
410 411
411 /* metadata */ 412 /* metadata */
@@ -429,8 +430,8 @@ static void iwl3945_dbg_report_frame(struct iwl3945_priv *priv,
429 430
430 /* if data frame is to us and all is good, 431 /* if data frame is to us and all is good,
431 * (optionally) print summary for only 1 out of every 100 */ 432 * (optionally) print summary for only 1 out of every 100 */
432 if (to_us && (fc & ~IEEE80211_FCTL_PROTECTED) == 433 if (to_us && (fc & ~cpu_to_le16(IEEE80211_FCTL_PROTECTED)) ==
433 (IEEE80211_FCTL_FROMDS | IEEE80211_FTYPE_DATA)) { 434 cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FTYPE_DATA)) {
434 dataframe = 1; 435 dataframe = 1;
435 if (!group100) 436 if (!group100)
436 print_summary = 1; /* print each frame */ 437 print_summary = 1; /* print each frame */
@@ -453,13 +454,13 @@ static void iwl3945_dbg_report_frame(struct iwl3945_priv *priv,
453 454
454 if (hundred) 455 if (hundred)
455 title = "100Frames"; 456 title = "100Frames";
456 else if (fc & IEEE80211_FCTL_RETRY) 457 else if (ieee80211_has_retry(fc))
457 title = "Retry"; 458 title = "Retry";
458 else if (ieee80211_is_assoc_response(fc)) 459 else if (ieee80211_is_assoc_resp(fc))
459 title = "AscRsp"; 460 title = "AscRsp";
460 else if (ieee80211_is_reassoc_response(fc)) 461 else if (ieee80211_is_reassoc_resp(fc))
461 title = "RasRsp"; 462 title = "RasRsp";
462 else if (ieee80211_is_probe_response(fc)) { 463 else if (ieee80211_is_probe_resp(fc)) {
463 title = "PrbRsp"; 464 title = "PrbRsp";
464 print_dump = 1; /* dump frame contents */ 465 print_dump = 1; /* dump frame contents */
465 } else if (ieee80211_is_beacon(fc)) { 466 } else if (ieee80211_is_beacon(fc)) {
@@ -488,14 +489,14 @@ static void iwl3945_dbg_report_frame(struct iwl3945_priv *priv,
488 if (dataframe) 489 if (dataframe)
489 IWL_DEBUG_RX("%s: mhd=0x%04x, dst=0x%02x, " 490 IWL_DEBUG_RX("%s: mhd=0x%04x, dst=0x%02x, "
490 "len=%u, rssi=%d, chnl=%d, rate=%d, \n", 491 "len=%u, rssi=%d, chnl=%d, rate=%d, \n",
491 title, fc, header->addr1[5], 492 title, le16_to_cpu(fc), header->addr1[5],
492 length, rssi, channel, rate); 493 length, rssi, channel, rate);
493 else { 494 else {
494 /* src/dst addresses assume managed mode */ 495 /* src/dst addresses assume managed mode */
495 IWL_DEBUG_RX("%s: 0x%04x, dst=0x%02x, " 496 IWL_DEBUG_RX("%s: 0x%04x, dst=0x%02x, "
496 "src=0x%02x, rssi=%u, tim=%lu usec, " 497 "src=0x%02x, rssi=%u, tim=%lu usec, "
497 "phy=0x%02x, chnl=%d\n", 498 "phy=0x%02x, chnl=%d\n",
498 title, fc, header->addr1[5], 499 title, le16_to_cpu(fc), header->addr1[5],
499 header->addr3[5], rssi, 500 header->addr3[5], rssi,
500 tsf_low - priv->scan_start_tsf, 501 tsf_low - priv->scan_start_tsf,
501 phy_flags, channel); 502 phy_flags, channel);
@@ -512,106 +513,32 @@ static inline void iwl3945_dbg_report_frame(struct iwl3945_priv *priv,
512} 513}
513#endif 514#endif
514 515
515 516/* This is necessary only for a number of statistics, see the caller. */
516static void iwl3945_add_radiotap(struct iwl3945_priv *priv, 517static int iwl3945_is_network_packet(struct iwl3945_priv *priv,
517 struct sk_buff *skb, 518 struct ieee80211_hdr *header)
518 struct iwl3945_rx_frame_hdr *rx_hdr,
519 struct ieee80211_rx_status *stats)
520{ 519{
521 /* First cache any information we need before we overwrite 520 /* Filter incoming packets to determine if they are targeted toward
522 * the information provided in the skb from the hardware */ 521 * this network, discarding packets coming from ourselves */
523 s8 signal = stats->ssi; 522 switch (priv->iw_mode) {
524 s8 noise = 0; 523 case NL80211_IFTYPE_ADHOC: /* Header: Dest. | Source | BSSID */
525 int rate = stats->rate_idx; 524 /* packets to our IBSS update information */
526 u64 tsf = stats->mactime; 525 return !compare_ether_addr(header->addr3, priv->bssid);
527 __le16 phy_flags_hw = rx_hdr->phy_flags, antenna; 526 case NL80211_IFTYPE_STATION: /* Header: Dest. | AP{BSSID} | Source */
528 527 /* packets to our IBSS update information */
529 struct iwl3945_rt_rx_hdr { 528 return !compare_ether_addr(header->addr2, priv->bssid);
530 struct ieee80211_radiotap_header rt_hdr; 529 default:
531 __le64 rt_tsf; /* TSF */ 530 return 1;
532 u8 rt_flags; /* radiotap packet flags */
533 u8 rt_rate; /* rate in 500kb/s */
534 __le16 rt_channelMHz; /* channel in MHz */
535 __le16 rt_chbitmask; /* channel bitfield */
536 s8 rt_dbmsignal; /* signal in dBm, kluged to signed */
537 s8 rt_dbmnoise;
538 u8 rt_antenna; /* antenna number */
539 } __attribute__ ((packed)) *iwl3945_rt;
540
541 if (skb_headroom(skb) < sizeof(*iwl3945_rt)) {
542 if (net_ratelimit())
543 printk(KERN_ERR "not enough headroom [%d] for "
544 "radiotap head [%zd]\n",
545 skb_headroom(skb), sizeof(*iwl3945_rt));
546 return;
547 }
548
549 /* put radiotap header in front of 802.11 header and data */
550 iwl3945_rt = (void *)skb_push(skb, sizeof(*iwl3945_rt));
551
552 /* initialise radiotap header */
553 iwl3945_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
554 iwl3945_rt->rt_hdr.it_pad = 0;
555
556 /* total header + data */
557 put_unaligned_le16(sizeof(*iwl3945_rt), &iwl3945_rt->rt_hdr.it_len);
558
559 /* Indicate all the fields we add to the radiotap header */
560 put_unaligned_le32((1 << IEEE80211_RADIOTAP_TSFT) |
561 (1 << IEEE80211_RADIOTAP_FLAGS) |
562 (1 << IEEE80211_RADIOTAP_RATE) |
563 (1 << IEEE80211_RADIOTAP_CHANNEL) |
564 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
565 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
566 (1 << IEEE80211_RADIOTAP_ANTENNA),
567 &iwl3945_rt->rt_hdr.it_present);
568
569 /* Zero the flags, we'll add to them as we go */
570 iwl3945_rt->rt_flags = 0;
571
572 put_unaligned_le64(tsf, &iwl3945_rt->rt_tsf);
573
574 iwl3945_rt->rt_dbmsignal = signal;
575 iwl3945_rt->rt_dbmnoise = noise;
576
577 /* Convert the channel frequency and set the flags */
578 put_unaligned_le16(stats->freq, &iwl3945_rt->rt_channelMHz);
579 if (!(phy_flags_hw & RX_RES_PHY_FLAGS_BAND_24_MSK))
580 put_unaligned_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ,
581 &iwl3945_rt->rt_chbitmask);
582 else if (phy_flags_hw & RX_RES_PHY_FLAGS_MOD_CCK_MSK)
583 put_unaligned_le16(IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ,
584 &iwl3945_rt->rt_chbitmask);
585 else /* 802.11g */
586 put_unaligned_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ,
587 &iwl3945_rt->rt_chbitmask);
588
589 if (rate == -1)
590 iwl3945_rt->rt_rate = 0;
591 else {
592 if (stats->band == IEEE80211_BAND_5GHZ)
593 rate += IWL_FIRST_OFDM_RATE;
594
595 iwl3945_rt->rt_rate = iwl3945_rates[rate].ieee;
596 } 531 }
597
598 /* antenna number */
599 antenna = phy_flags_hw & RX_RES_PHY_FLAGS_ANTENNA_MSK;
600 iwl3945_rt->rt_antenna = le16_to_cpu(antenna) >> 4;
601
602 /* set the preamble flag if we have it */
603 if (phy_flags_hw & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK)
604 iwl3945_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
605
606 stats->flag |= RX_FLAG_RADIOTAP;
607} 532}
608 533
609static void iwl3945_handle_data_packet(struct iwl3945_priv *priv, int is_data, 534static void iwl3945_pass_packet_to_mac80211(struct iwl3945_priv *priv,
610 struct iwl3945_rx_mem_buffer *rxb, 535 struct iwl3945_rx_mem_buffer *rxb,
611 struct ieee80211_rx_status *stats) 536 struct ieee80211_rx_status *stats)
612{ 537{
613 struct ieee80211_hdr *hdr;
614 struct iwl3945_rx_packet *pkt = (struct iwl3945_rx_packet *)rxb->skb->data; 538 struct iwl3945_rx_packet *pkt = (struct iwl3945_rx_packet *)rxb->skb->data;
539#ifdef CONFIG_IWL3945_LEDS
540 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)IWL_RX_DATA(pkt);
541#endif
615 struct iwl3945_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt); 542 struct iwl3945_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt);
616 struct iwl3945_rx_frame_end *rx_end = IWL_RX_END(pkt); 543 struct iwl3945_rx_frame_end *rx_end = IWL_RX_END(pkt);
617 short len = le16_to_cpu(rx_hdr->len); 544 short len = le16_to_cpu(rx_hdr->len);
@@ -633,17 +560,12 @@ static void iwl3945_handle_data_packet(struct iwl3945_priv *priv, int is_data,
633 /* Set the size of the skb to the size of the frame */ 560 /* Set the size of the skb to the size of the frame */
634 skb_put(rxb->skb, le16_to_cpu(rx_hdr->len)); 561 skb_put(rxb->skb, le16_to_cpu(rx_hdr->len));
635 562
636 hdr = (void *)rxb->skb->data;
637
638 if (iwl3945_param_hwcrypto) 563 if (iwl3945_param_hwcrypto)
639 iwl3945_set_decrypted_flag(priv, rxb->skb, 564 iwl3945_set_decrypted_flag(priv, rxb->skb,
640 le32_to_cpu(rx_end->status), stats); 565 le32_to_cpu(rx_end->status), stats);
641 566
642 if (priv->add_radiotap)
643 iwl3945_add_radiotap(priv, rxb->skb, rx_hdr, stats);
644
645#ifdef CONFIG_IWL3945_LEDS 567#ifdef CONFIG_IWL3945_LEDS
646 if (is_data) 568 if (ieee80211_is_data(hdr->frame_control))
647 priv->rxtxpackets += len; 569 priv->rxtxpackets += len;
648#endif 570#endif
649 ieee80211_rx_irqsafe(priv->hw, rxb->skb, stats); 571 ieee80211_rx_irqsafe(priv->hw, rxb->skb, stats);
@@ -666,7 +588,6 @@ static void iwl3945_rx_reply_rx(struct iwl3945_priv *priv,
666 u16 rx_stats_noise_diff = le16_to_cpu(rx_stats->noise_diff); 588 u16 rx_stats_noise_diff = le16_to_cpu(rx_stats->noise_diff);
667 u8 network_packet; 589 u8 network_packet;
668 590
669 rx_status.antenna = 0;
670 rx_status.flag = 0; 591 rx_status.flag = 0;
671 rx_status.mactime = le64_to_cpu(rx_end->timestamp); 592 rx_status.mactime = le64_to_cpu(rx_end->timestamp);
672 rx_status.freq = 593 rx_status.freq =
@@ -678,6 +599,13 @@ static void iwl3945_rx_reply_rx(struct iwl3945_priv *priv,
678 if (rx_status.band == IEEE80211_BAND_5GHZ) 599 if (rx_status.band == IEEE80211_BAND_5GHZ)
679 rx_status.rate_idx -= IWL_FIRST_OFDM_RATE; 600 rx_status.rate_idx -= IWL_FIRST_OFDM_RATE;
680 601
602 rx_status.antenna = le16_to_cpu(rx_hdr->phy_flags &
603 RX_RES_PHY_FLAGS_ANTENNA_MSK) >> 4;
604
605 /* set the preamble flag if appropriate */
606 if (rx_hdr->phy_flags & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK)
607 rx_status.flag |= RX_FLAG_SHORTPRE;
608
681 if ((unlikely(rx_stats->phy_count > 20))) { 609 if ((unlikely(rx_stats->phy_count > 20))) {
682 IWL_DEBUG_DROP 610 IWL_DEBUG_DROP
683 ("dsp size out of range [0,20]: " 611 ("dsp size out of range [0,20]: "
@@ -691,13 +619,10 @@ static void iwl3945_rx_reply_rx(struct iwl3945_priv *priv,
691 return; 619 return;
692 } 620 }
693 621
694 if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) { 622
695 iwl3945_handle_data_packet(priv, 1, rxb, &rx_status);
696 return;
697 }
698 623
699 /* Convert 3945's rssi indicator to dBm */ 624 /* Convert 3945's rssi indicator to dBm */
700 rx_status.ssi = rx_stats->rssi - IWL_RSSI_OFFSET; 625 rx_status.signal = rx_stats->rssi - IWL_RSSI_OFFSET;
701 626
702 /* Set default noise value to -127 */ 627 /* Set default noise value to -127 */
703 if (priv->last_rx_noise == 0) 628 if (priv->last_rx_noise == 0)
@@ -716,21 +641,21 @@ static void iwl3945_rx_reply_rx(struct iwl3945_priv *priv,
716 * Calculate rx_status.signal (quality indicator in %) based on SNR. */ 641 * Calculate rx_status.signal (quality indicator in %) based on SNR. */
717 if (rx_stats_noise_diff) { 642 if (rx_stats_noise_diff) {
718 snr = rx_stats_sig_avg / rx_stats_noise_diff; 643 snr = rx_stats_sig_avg / rx_stats_noise_diff;
719 rx_status.noise = rx_status.ssi - 644 rx_status.noise = rx_status.signal -
720 iwl3945_calc_db_from_ratio(snr); 645 iwl3945_calc_db_from_ratio(snr);
721 rx_status.signal = iwl3945_calc_sig_qual(rx_status.ssi, 646 rx_status.qual = iwl3945_calc_sig_qual(rx_status.signal,
722 rx_status.noise); 647 rx_status.noise);
723 648
724 /* If noise info not available, calculate signal quality indicator (%) 649 /* If noise info not available, calculate signal quality indicator (%)
725 * using just the dBm signal level. */ 650 * using just the dBm signal level. */
726 } else { 651 } else {
727 rx_status.noise = priv->last_rx_noise; 652 rx_status.noise = priv->last_rx_noise;
728 rx_status.signal = iwl3945_calc_sig_qual(rx_status.ssi, 0); 653 rx_status.qual = iwl3945_calc_sig_qual(rx_status.signal, 0);
729 } 654 }
730 655
731 656
732 IWL_DEBUG_STATS("Rssi %d noise %d qual %d sig_avg %d noise_diff %d\n", 657 IWL_DEBUG_STATS("Rssi %d noise %d qual %d sig_avg %d noise_diff %d\n",
733 rx_status.ssi, rx_status.noise, rx_status.signal, 658 rx_status.signal, rx_status.noise, rx_status.qual,
734 rx_stats_sig_avg, rx_stats_noise_diff); 659 rx_stats_sig_avg, rx_stats_noise_diff);
735 660
736 header = (struct ieee80211_hdr *)IWL_RX_DATA(pkt); 661 header = (struct ieee80211_hdr *)IWL_RX_DATA(pkt);
@@ -740,8 +665,8 @@ static void iwl3945_rx_reply_rx(struct iwl3945_priv *priv,
740 IWL_DEBUG_STATS_LIMIT("[%c] %d RSSI:%d Signal:%u, Noise:%u, Rate:%u\n", 665 IWL_DEBUG_STATS_LIMIT("[%c] %d RSSI:%d Signal:%u, Noise:%u, Rate:%u\n",
741 network_packet ? '*' : ' ', 666 network_packet ? '*' : ' ',
742 le16_to_cpu(rx_hdr->channel), 667 le16_to_cpu(rx_hdr->channel),
743 rx_status.ssi, rx_status.ssi, 668 rx_status.signal, rx_status.signal,
744 rx_status.ssi, rx_status.rate_idx); 669 rx_status.noise, rx_status.rate_idx);
745 670
746#ifdef CONFIG_IWL3945_DEBUG 671#ifdef CONFIG_IWL3945_DEBUG
747 if (iwl3945_debug_level & (IWL_DL_RX)) 672 if (iwl3945_debug_level & (IWL_DL_RX))
@@ -752,115 +677,11 @@ static void iwl3945_rx_reply_rx(struct iwl3945_priv *priv,
752 if (network_packet) { 677 if (network_packet) {
753 priv->last_beacon_time = le32_to_cpu(rx_end->beacon_timestamp); 678 priv->last_beacon_time = le32_to_cpu(rx_end->beacon_timestamp);
754 priv->last_tsf = le64_to_cpu(rx_end->timestamp); 679 priv->last_tsf = le64_to_cpu(rx_end->timestamp);
755 priv->last_rx_rssi = rx_status.ssi; 680 priv->last_rx_rssi = rx_status.signal;
756 priv->last_rx_noise = rx_status.noise; 681 priv->last_rx_noise = rx_status.noise;
757 } 682 }
758 683
759 switch (le16_to_cpu(header->frame_control) & IEEE80211_FCTL_FTYPE) { 684 iwl3945_pass_packet_to_mac80211(priv, rxb, &rx_status);
760 case IEEE80211_FTYPE_MGMT:
761 switch (le16_to_cpu(header->frame_control) &
762 IEEE80211_FCTL_STYPE) {
763 case IEEE80211_STYPE_PROBE_RESP:
764 case IEEE80211_STYPE_BEACON:{
765 /* If this is a beacon or probe response for
766 * our network then cache the beacon
767 * timestamp */
768 if ((((priv->iw_mode == IEEE80211_IF_TYPE_STA)
769 && !compare_ether_addr(header->addr2,
770 priv->bssid)) ||
771 ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
772 && !compare_ether_addr(header->addr3,
773 priv->bssid)))) {
774 struct ieee80211_mgmt *mgmt =
775 (struct ieee80211_mgmt *)header;
776 __le32 *pos;
777 pos =
778 (__le32 *) & mgmt->u.beacon.
779 timestamp;
780 priv->timestamp0 = le32_to_cpu(pos[0]);
781 priv->timestamp1 = le32_to_cpu(pos[1]);
782 priv->beacon_int = le16_to_cpu(
783 mgmt->u.beacon.beacon_int);
784 if (priv->call_post_assoc_from_beacon &&
785 (priv->iw_mode ==
786 IEEE80211_IF_TYPE_STA))
787 queue_work(priv->workqueue,
788 &priv->post_associate.work);
789
790 priv->call_post_assoc_from_beacon = 0;
791 }
792
793 break;
794 }
795
796 case IEEE80211_STYPE_ACTION:
797 /* TODO: Parse 802.11h frames for CSA... */
798 break;
799
800 /*
801 * TODO: Use the new callback function from
802 * mac80211 instead of sniffing these packets.
803 */
804 case IEEE80211_STYPE_ASSOC_RESP:
805 case IEEE80211_STYPE_REASSOC_RESP:{
806 struct ieee80211_mgmt *mgnt =
807 (struct ieee80211_mgmt *)header;
808
809 /* We have just associated, give some
810 * time for the 4-way handshake if
811 * any. Don't start scan too early. */
812 priv->next_scan_jiffies = jiffies +
813 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
814
815 priv->assoc_id = (~((1 << 15) | (1 << 14)) &
816 le16_to_cpu(mgnt->u.
817 assoc_resp.aid));
818 priv->assoc_capability =
819 le16_to_cpu(mgnt->u.assoc_resp.capab_info);
820 if (priv->beacon_int)
821 queue_work(priv->workqueue,
822 &priv->post_associate.work);
823 else
824 priv->call_post_assoc_from_beacon = 1;
825 break;
826 }
827
828 case IEEE80211_STYPE_PROBE_REQ:{
829 DECLARE_MAC_BUF(mac1);
830 DECLARE_MAC_BUF(mac2);
831 DECLARE_MAC_BUF(mac3);
832 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
833 IWL_DEBUG_DROP
834 ("Dropping (non network): %s"
835 ", %s, %s\n",
836 print_mac(mac1, header->addr1),
837 print_mac(mac2, header->addr2),
838 print_mac(mac3, header->addr3));
839 return;
840 }
841 }
842
843 iwl3945_handle_data_packet(priv, 0, rxb, &rx_status);
844 break;
845
846 case IEEE80211_FTYPE_CTL:
847 break;
848
849 case IEEE80211_FTYPE_DATA: {
850 DECLARE_MAC_BUF(mac1);
851 DECLARE_MAC_BUF(mac2);
852 DECLARE_MAC_BUF(mac3);
853
854 if (unlikely(iwl3945_is_duplicate_packet(priv, header)))
855 IWL_DEBUG_DROP("Dropping (dup): %s, %s, %s\n",
856 print_mac(mac1, header->addr1),
857 print_mac(mac2, header->addr2),
858 print_mac(mac3, header->addr3));
859 else
860 iwl3945_handle_data_packet(priv, 1, rxb, &rx_status);
861 break;
862 }
863 }
864} 685}
865 686
866int iwl3945_hw_txq_attach_buf_to_tfd(struct iwl3945_priv *priv, void *ptr, 687int iwl3945_hw_txq_attach_buf_to_tfd(struct iwl3945_priv *priv, void *ptr,
@@ -962,30 +783,31 @@ u8 iwl3945_hw_find_station(struct iwl3945_priv *priv, const u8 *addr)
962*/ 783*/
963void iwl3945_hw_build_tx_cmd_rate(struct iwl3945_priv *priv, 784void iwl3945_hw_build_tx_cmd_rate(struct iwl3945_priv *priv,
964 struct iwl3945_cmd *cmd, 785 struct iwl3945_cmd *cmd,
965 struct ieee80211_tx_control *ctrl, 786 struct ieee80211_tx_info *info,
966 struct ieee80211_hdr *hdr, int sta_id, int tx_id) 787 struct ieee80211_hdr *hdr, int sta_id, int tx_id)
967{ 788{
968 unsigned long flags; 789 unsigned long flags;
969 u16 rate_index = min(ctrl->tx_rate->hw_value & 0xffff, IWL_RATE_COUNT - 1); 790 u16 hw_value = ieee80211_get_tx_rate(priv->hw, info)->hw_value;
791 u16 rate_index = min(hw_value & 0xffff, IWL_RATE_COUNT - 1);
970 u16 rate_mask; 792 u16 rate_mask;
971 int rate; 793 int rate;
972 u8 rts_retry_limit; 794 u8 rts_retry_limit;
973 u8 data_retry_limit; 795 u8 data_retry_limit;
974 __le32 tx_flags; 796 __le32 tx_flags;
975 u16 fc = le16_to_cpu(hdr->frame_control); 797 __le16 fc = hdr->frame_control;
976 798
977 rate = iwl3945_rates[rate_index].plcp; 799 rate = iwl3945_rates[rate_index].plcp;
978 tx_flags = cmd->cmd.tx.tx_flags; 800 tx_flags = cmd->cmd.tx.tx_flags;
979 801
980 /* We need to figure out how to get the sta->supp_rates while 802 /* We need to figure out how to get the sta->supp_rates while
981 * in this running context; perhaps encoding into ctrl->tx_rate? */ 803 * in this running context */
982 rate_mask = IWL_RATES_MASK; 804 rate_mask = IWL_RATES_MASK;
983 805
984 spin_lock_irqsave(&priv->sta_lock, flags); 806 spin_lock_irqsave(&priv->sta_lock, flags);
985 807
986 priv->stations[sta_id].current_rate.rate_n_flags = rate; 808 priv->stations[sta_id].current_rate.rate_n_flags = rate;
987 809
988 if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) && 810 if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) &&
989 (sta_id != priv->hw_setting.bcast_sta_id) && 811 (sta_id != priv->hw_setting.bcast_sta_id) &&
990 (sta_id != IWL_MULTICAST_ID)) 812 (sta_id != IWL_MULTICAST_ID))
991 priv->stations[IWL_STA_ID].current_rate.rate_n_flags = rate; 813 priv->stations[IWL_STA_ID].current_rate.rate_n_flags = rate;
@@ -997,7 +819,7 @@ void iwl3945_hw_build_tx_cmd_rate(struct iwl3945_priv *priv,
997 else 819 else
998 rts_retry_limit = 7; 820 rts_retry_limit = 7;
999 821
1000 if (ieee80211_is_probe_response(fc)) { 822 if (ieee80211_is_probe_resp(fc)) {
1001 data_retry_limit = 3; 823 data_retry_limit = 3;
1002 if (data_retry_limit < rts_retry_limit) 824 if (data_retry_limit < rts_retry_limit)
1003 rts_retry_limit = data_retry_limit; 825 rts_retry_limit = data_retry_limit;
@@ -1007,12 +829,12 @@ void iwl3945_hw_build_tx_cmd_rate(struct iwl3945_priv *priv,
1007 if (priv->data_retry_limit != -1) 829 if (priv->data_retry_limit != -1)
1008 data_retry_limit = priv->data_retry_limit; 830 data_retry_limit = priv->data_retry_limit;
1009 831
1010 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) { 832 if (ieee80211_is_mgmt(fc)) {
1011 switch (fc & IEEE80211_FCTL_STYPE) { 833 switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
1012 case IEEE80211_STYPE_AUTH: 834 case cpu_to_le16(IEEE80211_STYPE_AUTH):
1013 case IEEE80211_STYPE_DEAUTH: 835 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
1014 case IEEE80211_STYPE_ASSOC_REQ: 836 case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ):
1015 case IEEE80211_STYPE_REASSOC_REQ: 837 case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ):
1016 if (tx_flags & TX_CMD_FLG_RTS_MSK) { 838 if (tx_flags & TX_CMD_FLG_RTS_MSK) {
1017 tx_flags &= ~TX_CMD_FLG_RTS_MSK; 839 tx_flags &= ~TX_CMD_FLG_RTS_MSK;
1018 tx_flags |= TX_CMD_FLG_CTS_MSK; 840 tx_flags |= TX_CMD_FLG_CTS_MSK;
@@ -1233,7 +1055,7 @@ int iwl3945_hw_nic_init(struct iwl3945_priv *priv)
1233 iwl3945_power_init_handle(priv); 1055 iwl3945_power_init_handle(priv);
1234 1056
1235 spin_lock_irqsave(&priv->lock, flags); 1057 spin_lock_irqsave(&priv->lock, flags);
1236 iwl3945_set_bit(priv, CSR_ANA_PLL_CFG, (1 << 24)); 1058 iwl3945_set_bit(priv, CSR_ANA_PLL_CFG, CSR39_ANA_PLL_CFG_VAL);
1237 iwl3945_set_bit(priv, CSR_GIO_CHICKEN_BITS, 1059 iwl3945_set_bit(priv, CSR_GIO_CHICKEN_BITS,
1238 CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX); 1060 CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX);
1239 1061
@@ -1502,7 +1324,7 @@ static int iwl3945_hw_reg_adjust_power_by_temp(int new_reading, int old_reading)
1502 */ 1324 */
1503static inline int iwl3945_hw_reg_temp_out_of_range(int temperature) 1325static inline int iwl3945_hw_reg_temp_out_of_range(int temperature)
1504{ 1326{
1505 return (((temperature < -260) || (temperature > 25)) ? 1 : 0); 1327 return ((temperature < -260) || (temperature > 25)) ? 1 : 0;
1506} 1328}
1507 1329
1508int iwl3945_hw_get_temperature(struct iwl3945_priv *priv) 1330int iwl3945_hw_get_temperature(struct iwl3945_priv *priv)
@@ -2623,7 +2445,7 @@ unsigned int iwl3945_hw_get_beacon_cmd(struct iwl3945_priv *priv,
2623 tx_beacon_cmd->tx.supp_rates[1] = 2445 tx_beacon_cmd->tx.supp_rates[1] =
2624 (IWL_CCK_BASIC_RATES_MASK & 0xF); 2446 (IWL_CCK_BASIC_RATES_MASK & 0xF);
2625 2447
2626 return (sizeof(struct iwl3945_tx_beacon_cmd) + frame_size); 2448 return sizeof(struct iwl3945_tx_beacon_cmd) + frame_size;
2627} 2449}
2628 2450
2629void iwl3945_hw_rx_handler_setup(struct iwl3945_priv *priv) 2451void iwl3945_hw_rx_handler_setup(struct iwl3945_priv *priv)
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945.h b/drivers/net/wireless/iwlwifi/iwl-3945.h
index c7695a215a39..bdd32475b99c 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945.h
+++ b/drivers/net/wireless/iwlwifi/iwl-3945.h
@@ -36,6 +36,10 @@
36#include <linux/kernel.h> 36#include <linux/kernel.h>
37#include <net/ieee80211_radiotap.h> 37#include <net/ieee80211_radiotap.h>
38 38
39/*used for rfkill*/
40#include <linux/rfkill.h>
41#include <linux/input.h>
42
39/* Hardware specific file defines the PCI IDs table for that hardware module */ 43/* Hardware specific file defines the PCI IDs table for that hardware module */
40extern struct pci_device_id iwl3945_hw_card_ids[]; 44extern struct pci_device_id iwl3945_hw_card_ids[];
41 45
@@ -69,6 +73,10 @@ extern struct pci_device_id iwl3945_hw_card_ids[];
69extern int iwl3945_param_hwcrypto; 73extern int iwl3945_param_hwcrypto;
70extern int iwl3945_param_queues_num; 74extern int iwl3945_param_queues_num;
71 75
76struct iwl3945_sta_priv {
77 struct iwl3945_rs_sta *rs_sta;
78};
79
72enum iwl3945_antenna { 80enum iwl3945_antenna {
73 IWL_ANTENNA_DIVERSITY, 81 IWL_ANTENNA_DIVERSITY,
74 IWL_ANTENNA_MAIN, 82 IWL_ANTENNA_MAIN,
@@ -124,7 +132,6 @@ int iwl3945_x2_queue_used(const struct iwl3945_queue *q, int i);
124 132
125/* One for each TFD */ 133/* One for each TFD */
126struct iwl3945_tx_info { 134struct iwl3945_tx_info {
127 struct ieee80211_tx_status status;
128 struct sk_buff *skb[MAX_NUM_OF_TBS]; 135 struct sk_buff *skb[MAX_NUM_OF_TBS];
129}; 136};
130 137
@@ -507,8 +514,6 @@ struct iwl3945_ucode {
507 u8 data[0]; /* data in same order as "size" elements */ 514 u8 data[0]; /* data in same order as "size" elements */
508}; 515};
509 516
510#define IWL_IBSS_MAC_HASH_SIZE 32
511
512struct iwl3945_ibss_seq { 517struct iwl3945_ibss_seq {
513 u8 mac[ETH_ALEN]; 518 u8 mac[ETH_ALEN];
514 u16 seq_num; 519 u16 seq_num;
@@ -566,17 +571,8 @@ extern int iwl3945_send_add_station(struct iwl3945_priv *priv,
566 struct iwl3945_addsta_cmd *sta, u8 flags); 571 struct iwl3945_addsta_cmd *sta, u8 flags);
567extern u8 iwl3945_add_station(struct iwl3945_priv *priv, const u8 *bssid, 572extern u8 iwl3945_add_station(struct iwl3945_priv *priv, const u8 *bssid,
568 int is_ap, u8 flags); 573 int is_ap, u8 flags);
569extern int iwl3945_is_network_packet(struct iwl3945_priv *priv,
570 struct ieee80211_hdr *header);
571extern int iwl3945_power_init_handle(struct iwl3945_priv *priv); 574extern int iwl3945_power_init_handle(struct iwl3945_priv *priv);
572extern int iwl3945_eeprom_init(struct iwl3945_priv *priv); 575extern int iwl3945_eeprom_init(struct iwl3945_priv *priv);
573extern void iwl3945_handle_data_packet_monitor(struct iwl3945_priv *priv,
574 struct iwl3945_rx_mem_buffer *rxb,
575 void *data, short len,
576 struct ieee80211_rx_status *stats,
577 u16 phy_flags);
578extern int iwl3945_is_duplicate_packet(struct iwl3945_priv *priv,
579 struct ieee80211_hdr *header);
580extern int iwl3945_rx_queue_alloc(struct iwl3945_priv *priv); 576extern int iwl3945_rx_queue_alloc(struct iwl3945_priv *priv);
581extern void iwl3945_rx_queue_reset(struct iwl3945_priv *priv, 577extern void iwl3945_rx_queue_reset(struct iwl3945_priv *priv,
582 struct iwl3945_rx_queue *rxq); 578 struct iwl3945_rx_queue *rxq);
@@ -645,7 +641,7 @@ extern unsigned int iwl3945_hw_get_beacon_cmd(struct iwl3945_priv *priv,
645extern int iwl3945_hw_get_rx_read(struct iwl3945_priv *priv); 641extern int iwl3945_hw_get_rx_read(struct iwl3945_priv *priv);
646extern void iwl3945_hw_build_tx_cmd_rate(struct iwl3945_priv *priv, 642extern void iwl3945_hw_build_tx_cmd_rate(struct iwl3945_priv *priv,
647 struct iwl3945_cmd *cmd, 643 struct iwl3945_cmd *cmd,
648 struct ieee80211_tx_control *ctrl, 644 struct ieee80211_tx_info *info,
649 struct ieee80211_hdr *hdr, 645 struct ieee80211_hdr *hdr,
650 int sta_id, int tx_id); 646 int sta_id, int tx_id);
651extern int iwl3945_hw_reg_send_txpower(struct iwl3945_priv *priv); 647extern int iwl3945_hw_reg_send_txpower(struct iwl3945_priv *priv);
@@ -687,6 +683,18 @@ enum {
687 683
688#endif 684#endif
689 685
686#ifdef CONFIG_IWL3945_RFKILL
687struct iwl3945_priv;
688
689void iwl3945_rfkill_set_hw_state(struct iwl3945_priv *priv);
690void iwl3945_rfkill_unregister(struct iwl3945_priv *priv);
691int iwl3945_rfkill_init(struct iwl3945_priv *priv);
692#else
693static inline void iwl3945_rfkill_set_hw_state(struct iwl3945_priv *priv) {}
694static inline void iwl3945_rfkill_unregister(struct iwl3945_priv *priv) {}
695static inline int iwl3945_rfkill_init(struct iwl3945_priv *priv) { return 0; }
696#endif
697
690#define IWL_MAX_NUM_QUEUES IWL39_MAX_NUM_QUEUES 698#define IWL_MAX_NUM_QUEUES IWL39_MAX_NUM_QUEUES
691 699
692struct iwl3945_priv { 700struct iwl3945_priv {
@@ -703,7 +711,6 @@ struct iwl3945_priv {
703 711
704 enum ieee80211_band band; 712 enum ieee80211_band band;
705 int alloc_rxb_skb; 713 int alloc_rxb_skb;
706 bool add_radiotap;
707 714
708 void (*rx_handlers[REPLY_MAX])(struct iwl3945_priv *priv, 715 void (*rx_handlers[REPLY_MAX])(struct iwl3945_priv *priv,
709 struct iwl3945_rx_mem_buffer *rxb); 716 struct iwl3945_rx_mem_buffer *rxb);
@@ -780,12 +787,17 @@ struct iwl3945_priv {
780 struct iwl3945_init_alive_resp card_alive_init; 787 struct iwl3945_init_alive_resp card_alive_init;
781 struct iwl3945_alive_resp card_alive; 788 struct iwl3945_alive_resp card_alive;
782 789
790#ifdef CONFIG_IWL3945_RFKILL
791 struct rfkill *rfkill;
792#endif
793
783#ifdef CONFIG_IWL3945_LEDS 794#ifdef CONFIG_IWL3945_LEDS
784 struct iwl3945_led led[IWL_LED_TRG_MAX]; 795 struct iwl3945_led led[IWL_LED_TRG_MAX];
785 unsigned long last_blink_time; 796 unsigned long last_blink_time;
786 u8 last_blink_rate; 797 u8 last_blink_rate;
787 u8 allow_blinking; 798 u8 allow_blinking;
788 unsigned int rxtxpackets; 799 unsigned int rxtxpackets;
800 u64 led_tpt;
789#endif 801#endif
790 802
791 803
@@ -836,24 +848,14 @@ struct iwl3945_priv {
836 848
837 u8 mac80211_registered; 849 u8 mac80211_registered;
838 850
839 u32 notif_missed_beacons;
840
841 /* Rx'd packet timing information */ 851 /* Rx'd packet timing information */
842 u32 last_beacon_time; 852 u32 last_beacon_time;
843 u64 last_tsf; 853 u64 last_tsf;
844 854
845 /* Duplicate packet detection */
846 u16 last_seq_num;
847 u16 last_frag_num;
848 unsigned long last_packet_time;
849
850 /* Hash table for finding stations in IBSS network */
851 struct list_head ibss_mac_hash[IWL_IBSS_MAC_HASH_SIZE];
852
853 /* eeprom */ 855 /* eeprom */
854 struct iwl3945_eeprom eeprom; 856 struct iwl3945_eeprom eeprom;
855 857
856 enum ieee80211_if_types iw_mode; 858 enum nl80211_iftype iw_mode;
857 859
858 struct sk_buff *ibss_beacon; 860 struct sk_buff *ibss_beacon;
859 861
@@ -886,6 +888,7 @@ struct iwl3945_priv {
886 struct work_struct report_work; 888 struct work_struct report_work;
887 struct work_struct request_scan; 889 struct work_struct request_scan;
888 struct work_struct beacon_update; 890 struct work_struct beacon_update;
891 struct work_struct set_monitor;
889 892
890 struct tasklet_struct irq_tasklet; 893 struct tasklet_struct irq_tasklet;
891 894
@@ -895,7 +898,6 @@ struct iwl3945_priv {
895 struct delayed_work thermal_periodic; 898 struct delayed_work thermal_periodic;
896 struct delayed_work gather_stats; 899 struct delayed_work gather_stats;
897 struct delayed_work scan_check; 900 struct delayed_work scan_check;
898 struct delayed_work post_associate;
899 901
900#define IWL_DEFAULT_TX_POWER 0x0F 902#define IWL_DEFAULT_TX_POWER 0x0F
901 s8 user_txpower_limit; 903 s8 user_txpower_limit;
@@ -924,11 +926,6 @@ static inline int is_channel_valid(const struct iwl3945_channel_info *ch_info)
924 return (ch_info->flags & EEPROM_CHANNEL_VALID) ? 1 : 0; 926 return (ch_info->flags & EEPROM_CHANNEL_VALID) ? 1 : 0;
925} 927}
926 928
927static inline int is_channel_narrow(const struct iwl3945_channel_info *ch_info)
928{
929 return (ch_info->flags & EEPROM_CHANNEL_NARROW) ? 1 : 0;
930}
931
932static inline int is_channel_radar(const struct iwl3945_channel_info *ch_info) 929static inline int is_channel_radar(const struct iwl3945_channel_info *ch_info)
933{ 930{
934 return (ch_info->flags & EEPROM_CHANNEL_RADAR) ? 1 : 0; 931 return (ch_info->flags & EEPROM_CHANNEL_RADAR) ? 1 : 0;
diff --git a/drivers/net/wireless/iwlwifi/iwl-4965-hw.h b/drivers/net/wireless/iwlwifi/iwl-4965-hw.h
index 1a66b508a8ea..f4793a609443 100644
--- a/drivers/net/wireless/iwlwifi/iwl-4965-hw.h
+++ b/drivers/net/wireless/iwlwifi/iwl-4965-hw.h
@@ -62,13 +62,18 @@
62 *****************************************************************************/ 62 *****************************************************************************/
63/* 63/*
64 * Please use this file (iwl-4965-hw.h) only for hardware-related definitions. 64 * Please use this file (iwl-4965-hw.h) only for hardware-related definitions.
65 * Use iwl-4965-commands.h for uCode API definitions. 65 * Use iwl-commands.h for uCode API definitions.
66 * Use iwl-4965.h for driver implementation definitions. 66 * Use iwl-dev.h for driver implementation definitions.
67 */ 67 */
68 68
69#ifndef __iwl_4965_hw_h__ 69#ifndef __iwl_4965_hw_h__
70#define __iwl_4965_hw_h__ 70#define __iwl_4965_hw_h__
71 71
72#include "iwl-fh.h"
73
74/* EERPROM */
75#define IWL4965_EEPROM_IMG_SIZE 1024
76
72/* 77/*
73 * uCode queue management definitions ... 78 * uCode queue management definitions ...
74 * Queue #4 is the command queue for 3945 and 4965; map it to Tx FIFO chnl 4. 79 * Queue #4 is the command queue for 3945 and 4965; map it to Tx FIFO chnl 4.
@@ -77,7 +82,7 @@
77 */ 82 */
78#define IWL_CMD_QUEUE_NUM 4 83#define IWL_CMD_QUEUE_NUM 4
79#define IWL_CMD_FIFO_NUM 4 84#define IWL_CMD_FIFO_NUM 4
80#define IWL_BACK_QUEUE_FIRST_ID 7 85#define IWL49_FIRST_AMPDU_QUEUE 7
81 86
82/* Tx rates */ 87/* Tx rates */
83#define IWL_CCK_RATES 4 88#define IWL_CCK_RATES 4
@@ -93,11 +98,17 @@
93#define IWL_RSSI_OFFSET 44 98#define IWL_RSSI_OFFSET 44
94 99
95 100
96#include "iwl-4965-commands.h"
97 101
98#define PCI_LINK_CTRL 0x0F0 102/* PCI registers */
99#define PCI_POWER_SOURCE 0x0C8 103#define PCI_CFG_RETRY_TIMEOUT 0x041
100#define PCI_REG_WUM8 0x0E8 104#define PCI_CFG_POWER_SOURCE 0x0C8
105#define PCI_REG_WUM8 0x0E8
106#define PCI_CFG_LINK_CTRL 0x0F0
107
108/* PCI register values */
109#define PCI_CFG_LINK_CTRL_VAL_L0S_EN 0x01
110#define PCI_CFG_LINK_CTRL_VAL_L1_EN 0x02
111#define PCI_CFG_CMD_REG_INT_DIS_MSK 0x04
101#define PCI_CFG_PMC_PME_FROM_D3COLD_SUPPORT (0x80000000) 112#define PCI_CFG_PMC_PME_FROM_D3COLD_SUPPORT (0x80000000)
102 113
103#define TFD_QUEUE_SIZE_MAX (256) 114#define TFD_QUEUE_SIZE_MAX (256)
@@ -131,10 +142,8 @@
131#define RTC_DATA_LOWER_BOUND (0x800000) 142#define RTC_DATA_LOWER_BOUND (0x800000)
132#define IWL49_RTC_DATA_UPPER_BOUND (0x80A000) 143#define IWL49_RTC_DATA_UPPER_BOUND (0x80A000)
133 144
134#define IWL49_RTC_INST_SIZE \ 145#define IWL49_RTC_INST_SIZE (IWL49_RTC_INST_UPPER_BOUND - RTC_INST_LOWER_BOUND)
135 (IWL49_RTC_INST_UPPER_BOUND - RTC_INST_LOWER_BOUND) 146#define IWL49_RTC_DATA_SIZE (IWL49_RTC_DATA_UPPER_BOUND - RTC_DATA_LOWER_BOUND)
136#define IWL49_RTC_DATA_SIZE \
137 (IWL49_RTC_DATA_UPPER_BOUND - RTC_DATA_LOWER_BOUND)
138 147
139#define IWL_MAX_INST_SIZE IWL49_RTC_INST_SIZE 148#define IWL_MAX_INST_SIZE IWL49_RTC_INST_SIZE
140#define IWL_MAX_DATA_SIZE IWL49_RTC_DATA_SIZE 149#define IWL_MAX_DATA_SIZE IWL49_RTC_DATA_SIZE
@@ -785,585 +794,6 @@ enum {
785 794
786/********************* END TXPOWER *****************************************/ 795/********************* END TXPOWER *****************************************/
787 796
788/****************************/
789/* Flow Handler Definitions */
790/****************************/
791
792/**
793 * This I/O area is directly read/writable by driver (e.g. Linux uses writel())
794 * Addresses are offsets from device's PCI hardware base address.
795 */
796#define FH_MEM_LOWER_BOUND (0x1000)
797#define FH_MEM_UPPER_BOUND (0x1EF0)
798
799/**
800 * Keep-Warm (KW) buffer base address.
801 *
802 * Driver must allocate a 4KByte buffer that is used by 4965 for keeping the
803 * host DRAM powered on (via dummy accesses to DRAM) to maintain low-latency
804 * DRAM access when 4965 is Txing or Rxing. The dummy accesses prevent host
805 * from going into a power-savings mode that would cause higher DRAM latency,
806 * and possible data over/under-runs, before all Tx/Rx is complete.
807 *
808 * Driver loads IWL_FH_KW_MEM_ADDR_REG with the physical address (bits 35:4)
809 * of the buffer, which must be 4K aligned. Once this is set up, the 4965
810 * automatically invokes keep-warm accesses when normal accesses might not
811 * be sufficient to maintain fast DRAM response.
812 *
813 * Bit fields:
814 * 31-0: Keep-warm buffer physical base address [35:4], must be 4K aligned
815 */
816#define IWL_FH_KW_MEM_ADDR_REG (FH_MEM_LOWER_BOUND + 0x97C)
817
818
819/**
820 * TFD Circular Buffers Base (CBBC) addresses
821 *
822 * 4965 has 16 base pointer registers, one for each of 16 host-DRAM-resident
823 * circular buffers (CBs/queues) containing Transmit Frame Descriptors (TFDs)
824 * (see struct iwl_tfd_frame). These 16 pointer registers are offset by 0x04
825 * bytes from one another. Each TFD circular buffer in DRAM must be 256-byte
826 * aligned (address bits 0-7 must be 0).
827 *
828 * Bit fields in each pointer register:
829 * 27-0: TFD CB physical base address [35:8], must be 256-byte aligned
830 */
831#define FH_MEM_CBBC_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0x9D0)
832#define FH_MEM_CBBC_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xA10)
833
834/* Find TFD CB base pointer for given queue (range 0-15). */
835#define FH_MEM_CBBC_QUEUE(x) (FH_MEM_CBBC_LOWER_BOUND + (x) * 0x4)
836
837
838/**
839 * Rx SRAM Control and Status Registers (RSCSR)
840 *
841 * These registers provide handshake between driver and 4965 for the Rx queue
842 * (this queue handles *all* command responses, notifications, Rx data, etc.
843 * sent from 4965 uCode to host driver). Unlike Tx, there is only one Rx
844 * queue, and only one Rx DMA/FIFO channel. Also unlike Tx, which can
845 * concatenate up to 20 DRAM buffers to form a Tx frame, each Receive Buffer
846 * Descriptor (RBD) points to only one Rx Buffer (RB); there is a 1:1
847 * mapping between RBDs and RBs.
848 *
849 * Driver must allocate host DRAM memory for the following, and set the
850 * physical address of each into 4965 registers:
851 *
852 * 1) Receive Buffer Descriptor (RBD) circular buffer (CB), typically with 256
853 * entries (although any power of 2, up to 4096, is selectable by driver).
854 * Each entry (1 dword) points to a receive buffer (RB) of consistent size
855 * (typically 4K, although 8K or 16K are also selectable by driver).
856 * Driver sets up RB size and number of RBDs in the CB via Rx config
857 * register FH_MEM_RCSR_CHNL0_CONFIG_REG.
858 *
859 * Bit fields within one RBD:
860 * 27-0: Receive Buffer physical address bits [35:8], 256-byte aligned
861 *
862 * Driver sets physical address [35:8] of base of RBD circular buffer
863 * into FH_RSCSR_CHNL0_RBDCB_BASE_REG [27:0].
864 *
865 * 2) Rx status buffer, 8 bytes, in which 4965 indicates which Rx Buffers
866 * (RBs) have been filled, via a "write pointer", actually the index of
867 * the RB's corresponding RBD within the circular buffer. Driver sets
868 * physical address [35:4] into FH_RSCSR_CHNL0_STTS_WPTR_REG [31:0].
869 *
870 * Bit fields in lower dword of Rx status buffer (upper dword not used
871 * by driver; see struct iwl4965_shared, val0):
872 * 31-12: Not used by driver
873 * 11- 0: Index of last filled Rx buffer descriptor
874 * (4965 writes, driver reads this value)
875 *
876 * As the driver prepares Receive Buffers (RBs) for 4965 to fill, driver must
877 * enter pointers to these RBs into contiguous RBD circular buffer entries,
878 * and update the 4965's "write" index register, FH_RSCSR_CHNL0_RBDCB_WPTR_REG.
879 *
880 * This "write" index corresponds to the *next* RBD that the driver will make
881 * available, i.e. one RBD past the tail of the ready-to-fill RBDs within
882 * the circular buffer. This value should initially be 0 (before preparing any
883 * RBs), should be 8 after preparing the first 8 RBs (for example), and must
884 * wrap back to 0 at the end of the circular buffer (but don't wrap before
885 * "read" index has advanced past 1! See below).
886 * NOTE: 4965 EXPECTS THE WRITE INDEX TO BE INCREMENTED IN MULTIPLES OF 8.
887 *
888 * As the 4965 fills RBs (referenced from contiguous RBDs within the circular
889 * buffer), it updates the Rx status buffer in host DRAM, 2) described above,
890 * to tell the driver the index of the latest filled RBD. The driver must
891 * read this "read" index from DRAM after receiving an Rx interrupt from 4965.
892 *
893 * The driver must also internally keep track of a third index, which is the
894 * next RBD to process. When receiving an Rx interrupt, driver should process
895 * all filled but unprocessed RBs up to, but not including, the RB
896 * corresponding to the "read" index. For example, if "read" index becomes "1",
897 * driver may process the RB pointed to by RBD 0. Depending on volume of
898 * traffic, there may be many RBs to process.
899 *
900 * If read index == write index, 4965 thinks there is no room to put new data.
901 * Due to this, the maximum number of filled RBs is 255, instead of 256. To
902 * be safe, make sure that there is a gap of at least 2 RBDs between "write"
903 * and "read" indexes; that is, make sure that there are no more than 254
904 * buffers waiting to be filled.
905 */
906#define FH_MEM_RSCSR_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xBC0)
907#define FH_MEM_RSCSR_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xC00)
908#define FH_MEM_RSCSR_CHNL0 (FH_MEM_RSCSR_LOWER_BOUND)
909
910/**
911 * Physical base address of 8-byte Rx Status buffer.
912 * Bit fields:
913 * 31-0: Rx status buffer physical base address [35:4], must 16-byte aligned.
914 */
915#define FH_RSCSR_CHNL0_STTS_WPTR_REG (FH_MEM_RSCSR_CHNL0)
916
917/**
918 * Physical base address of Rx Buffer Descriptor Circular Buffer.
919 * Bit fields:
920 * 27-0: RBD CD physical base address [35:8], must be 256-byte aligned.
921 */
922#define FH_RSCSR_CHNL0_RBDCB_BASE_REG (FH_MEM_RSCSR_CHNL0 + 0x004)
923
924/**
925 * Rx write pointer (index, really!).
926 * Bit fields:
927 * 11-0: Index of driver's most recent prepared-to-be-filled RBD, + 1.
928 * NOTE: For 256-entry circular buffer, use only bits [7:0].
929 */
930#define FH_RSCSR_CHNL0_RBDCB_WPTR_REG (FH_MEM_RSCSR_CHNL0 + 0x008)
931#define FH_RSCSR_CHNL0_WPTR (FH_RSCSR_CHNL0_RBDCB_WPTR_REG)
932
933
934/**
935 * Rx Config/Status Registers (RCSR)
936 * Rx Config Reg for channel 0 (only channel used)
937 *
938 * Driver must initialize FH_MEM_RCSR_CHNL0_CONFIG_REG as follows for
939 * normal operation (see bit fields).
940 *
941 * Clearing FH_MEM_RCSR_CHNL0_CONFIG_REG to 0 turns off Rx DMA.
942 * Driver should poll FH_MEM_RSSR_RX_STATUS_REG for
943 * FH_RSSR_CHNL0_RX_STATUS_CHNL_IDLE (bit 24) before continuing.
944 *
945 * Bit fields:
946 * 31-30: Rx DMA channel enable: '00' off/pause, '01' pause at end of frame,
947 * '10' operate normally
948 * 29-24: reserved
949 * 23-20: # RBDs in circular buffer = 2^value; use "8" for 256 RBDs (normal),
950 * min "5" for 32 RBDs, max "12" for 4096 RBDs.
951 * 19-18: reserved
952 * 17-16: size of each receive buffer; '00' 4K (normal), '01' 8K,
953 * '10' 12K, '11' 16K.
954 * 15-14: reserved
955 * 13-12: IRQ destination; '00' none, '01' host driver (normal operation)
956 * 11- 4: timeout for closing Rx buffer and interrupting host (units 32 usec)
957 * typical value 0x10 (about 1/2 msec)
958 * 3- 0: reserved
959 */
960#define FH_MEM_RCSR_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xC00)
961#define FH_MEM_RCSR_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xCC0)
962#define FH_MEM_RCSR_CHNL0 (FH_MEM_RCSR_LOWER_BOUND)
963
964#define FH_MEM_RCSR_CHNL0_CONFIG_REG (FH_MEM_RCSR_CHNL0)
965
966#define FH_RCSR_CHNL0_RX_CONFIG_RB_TIMEOUT_MASK (0x00000FF0) /* bit 4-11 */
967#define FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_MASK (0x00001000) /* bit 12 */
968#define FH_RCSR_CHNL0_RX_CONFIG_SINGLE_FRAME_MASK (0x00008000) /* bit 15 */
969#define FH_RCSR_CHNL0_RX_CONFIG_RB_SIZE_MASK (0x00030000) /* bits 16-17 */
970#define FH_RCSR_CHNL0_RX_CONFIG_RBDBC_SIZE_MASK (0x00F00000) /* bits 20-23 */
971#define FH_RCSR_CHNL0_RX_CONFIG_DMA_CHNL_EN_MASK (0xC0000000) /* bits 30-31 */
972
973#define FH_RCSR_RX_CONFIG_RBDCB_SIZE_BITSHIFT (20)
974#define FH_RCSR_RX_CONFIG_REG_IRQ_RBTH_BITSHIFT (4)
975#define RX_RB_TIMEOUT (0x10)
976
977#define FH_RCSR_RX_CONFIG_CHNL_EN_PAUSE_VAL (0x00000000)
978#define FH_RCSR_RX_CONFIG_CHNL_EN_PAUSE_EOF_VAL (0x40000000)
979#define FH_RCSR_RX_CONFIG_CHNL_EN_ENABLE_VAL (0x80000000)
980
981#define FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_4K (0x00000000)
982#define FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_8K (0x00010000)
983#define FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_12K (0x00020000)
984#define FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_16K (0x00030000)
985
986#define FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_NO_INT_VAL (0x00000000)
987#define FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_INT_HOST_VAL (0x00001000)
988
989
990/**
991 * Rx Shared Status Registers (RSSR)
992 *
993 * After stopping Rx DMA channel (writing 0 to FH_MEM_RCSR_CHNL0_CONFIG_REG),
994 * driver must poll FH_MEM_RSSR_RX_STATUS_REG until Rx channel is idle.
995 *
996 * Bit fields:
997 * 24: 1 = Channel 0 is idle
998 *
999 * FH_MEM_RSSR_SHARED_CTRL_REG and FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV contain
1000 * default values that should not be altered by the driver.
1001 */
1002#define FH_MEM_RSSR_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xC40)
1003#define FH_MEM_RSSR_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xD00)
1004
1005#define FH_MEM_RSSR_SHARED_CTRL_REG (FH_MEM_RSSR_LOWER_BOUND)
1006#define FH_MEM_RSSR_RX_STATUS_REG (FH_MEM_RSSR_LOWER_BOUND + 0x004)
1007#define FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV (FH_MEM_RSSR_LOWER_BOUND + 0x008)
1008
1009#define FH_RSSR_CHNL0_RX_STATUS_CHNL_IDLE (0x01000000)
1010
1011
1012/**
1013 * Transmit DMA Channel Control/Status Registers (TCSR)
1014 *
1015 * 4965 has one configuration register for each of 8 Tx DMA/FIFO channels
1016 * supported in hardware (don't confuse these with the 16 Tx queues in DRAM,
1017 * which feed the DMA/FIFO channels); config regs are separated by 0x20 bytes.
1018 *
1019 * To use a Tx DMA channel, driver must initialize its
1020 * IWL_FH_TCSR_CHNL_TX_CONFIG_REG(chnl) with:
1021 *
1022 * IWL_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
1023 * IWL_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE_VAL
1024 *
1025 * All other bits should be 0.
1026 *
1027 * Bit fields:
1028 * 31-30: Tx DMA channel enable: '00' off/pause, '01' pause at end of frame,
1029 * '10' operate normally
1030 * 29- 4: Reserved, set to "0"
1031 * 3: Enable internal DMA requests (1, normal operation), disable (0)
1032 * 2- 0: Reserved, set to "0"
1033 */
1034#define IWL_FH_TCSR_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xD00)
1035#define IWL_FH_TCSR_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xE60)
1036
1037/* Find Control/Status reg for given Tx DMA/FIFO channel */
1038#define IWL_FH_TCSR_CHNL_TX_CONFIG_REG(_chnl) \
1039 (IWL_FH_TCSR_LOWER_BOUND + 0x20 * _chnl)
1040
1041#define IWL_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_DISABLE_VAL (0x00000000)
1042#define IWL_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE_VAL (0x00000008)
1043
1044#define IWL_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE (0x00000000)
1045#define IWL_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE_EOF (0x40000000)
1046#define IWL_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE (0x80000000)
1047
1048/**
1049 * Tx Shared Status Registers (TSSR)
1050 *
1051 * After stopping Tx DMA channel (writing 0 to
1052 * IWL_FH_TCSR_CHNL_TX_CONFIG_REG(chnl)), driver must poll
1053 * IWL_FH_TSSR_TX_STATUS_REG until selected Tx channel is idle
1054 * (channel's buffers empty | no pending requests).
1055 *
1056 * Bit fields:
1057 * 31-24: 1 = Channel buffers empty (channel 7:0)
1058 * 23-16: 1 = No pending requests (channel 7:0)
1059 */
1060#define IWL_FH_TSSR_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xEA0)
1061#define IWL_FH_TSSR_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xEC0)
1062
1063#define IWL_FH_TSSR_TX_STATUS_REG (IWL_FH_TSSR_LOWER_BOUND + 0x010)
1064
1065#define IWL_FH_TSSR_TX_STATUS_REG_BIT_BUFS_EMPTY(_chnl) \
1066 ((1 << (_chnl)) << 24)
1067#define IWL_FH_TSSR_TX_STATUS_REG_BIT_NO_PEND_REQ(_chnl) \
1068 ((1 << (_chnl)) << 16)
1069
1070#define IWL_FH_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE(_chnl) \
1071 (IWL_FH_TSSR_TX_STATUS_REG_BIT_BUFS_EMPTY(_chnl) | \
1072 IWL_FH_TSSR_TX_STATUS_REG_BIT_NO_PEND_REQ(_chnl))
1073
1074
1075/********************* START TX SCHEDULER *************************************/
1076
1077/**
1078 * 4965 Tx Scheduler
1079 *
1080 * The Tx Scheduler selects the next frame to be transmitted, chosing TFDs
1081 * (Transmit Frame Descriptors) from up to 16 circular Tx queues resident in
1082 * host DRAM. It steers each frame's Tx command (which contains the frame
1083 * data) into one of up to 7 prioritized Tx DMA FIFO channels within the
1084 * device. A queue maps to only one (selectable by driver) Tx DMA channel,
1085 * but one DMA channel may take input from several queues.
1086 *
1087 * Tx DMA channels have dedicated purposes. For 4965, they are used as follows:
1088 *
1089 * 0 -- EDCA BK (background) frames, lowest priority
1090 * 1 -- EDCA BE (best effort) frames, normal priority
1091 * 2 -- EDCA VI (video) frames, higher priority
1092 * 3 -- EDCA VO (voice) and management frames, highest priority
1093 * 4 -- Commands (e.g. RXON, etc.)
1094 * 5 -- HCCA short frames
1095 * 6 -- HCCA long frames
1096 * 7 -- not used by driver (device-internal only)
1097 *
1098 * Driver should normally map queues 0-6 to Tx DMA/FIFO channels 0-6.
1099 * In addition, driver can map queues 7-15 to Tx DMA/FIFO channels 0-3 to
1100 * support 11n aggregation via EDCA DMA channels.
1101 *
1102 * The driver sets up each queue to work in one of two modes:
1103 *
1104 * 1) Scheduler-Ack, in which the scheduler automatically supports a
1105 * block-ack (BA) window of up to 64 TFDs. In this mode, each queue
1106 * contains TFDs for a unique combination of Recipient Address (RA)
1107 * and Traffic Identifier (TID), that is, traffic of a given
1108 * Quality-Of-Service (QOS) priority, destined for a single station.
1109 *
1110 * In scheduler-ack mode, the scheduler keeps track of the Tx status of
1111 * each frame within the BA window, including whether it's been transmitted,
1112 * and whether it's been acknowledged by the receiving station. The device
1113 * automatically processes block-acks received from the receiving STA,
1114 * and reschedules un-acked frames to be retransmitted (successful
1115 * Tx completion may end up being out-of-order).
1116 *
1117 * The driver must maintain the queue's Byte Count table in host DRAM
1118 * (struct iwl4965_sched_queue_byte_cnt_tbl) for this mode.
1119 * This mode does not support fragmentation.
1120 *
1121 * 2) FIFO (a.k.a. non-Scheduler-ACK), in which each TFD is processed in order.
1122 * The device may automatically retry Tx, but will retry only one frame
1123 * at a time, until receiving ACK from receiving station, or reaching
1124 * retry limit and giving up.
1125 *
1126 * The command queue (#4) must use this mode!
1127 * This mode does not require use of the Byte Count table in host DRAM.
1128 *
1129 * Driver controls scheduler operation via 3 means:
1130 * 1) Scheduler registers
1131 * 2) Shared scheduler data base in internal 4956 SRAM
1132 * 3) Shared data in host DRAM
1133 *
1134 * Initialization:
1135 *
1136 * When loading, driver should allocate memory for:
1137 * 1) 16 TFD circular buffers, each with space for (typically) 256 TFDs.
1138 * 2) 16 Byte Count circular buffers in 16 KBytes contiguous memory
1139 * (1024 bytes for each queue).
1140 *
1141 * After receiving "Alive" response from uCode, driver must initialize
1142 * the scheduler (especially for queue #4, the command queue, otherwise
1143 * the driver can't issue commands!):
1144 */
1145
1146/**
1147 * Max Tx window size is the max number of contiguous TFDs that the scheduler
1148 * can keep track of at one time when creating block-ack chains of frames.
1149 * Note that "64" matches the number of ack bits in a block-ack packet.
1150 * Driver should use SCD_WIN_SIZE and SCD_FRAME_LIMIT values to initialize
1151 * SCD_CONTEXT_QUEUE_OFFSET(x) values.
1152 */
1153#define SCD_WIN_SIZE 64
1154#define SCD_FRAME_LIMIT 64
1155
1156/* SCD registers are internal, must be accessed via HBUS_TARG_PRPH regs */
1157#define SCD_START_OFFSET 0xa02c00
1158
1159/*
1160 * 4965 tells driver SRAM address for internal scheduler structs via this reg.
1161 * Value is valid only after "Alive" response from uCode.
1162 */
1163#define SCD_SRAM_BASE_ADDR (SCD_START_OFFSET + 0x0)
1164
1165/*
1166 * Driver may need to update queue-empty bits after changing queue's
1167 * write and read pointers (indexes) during (re-)initialization (i.e. when
1168 * scheduler is not tracking what's happening).
1169 * Bit fields:
1170 * 31-16: Write mask -- 1: update empty bit, 0: don't change empty bit
1171 * 15-00: Empty state, one for each queue -- 1: empty, 0: non-empty
1172 * NOTE: This register is not used by Linux driver.
1173 */
1174#define SCD_EMPTY_BITS (SCD_START_OFFSET + 0x4)
1175
1176/*
1177 * Physical base address of array of byte count (BC) circular buffers (CBs).
1178 * Each Tx queue has a BC CB in host DRAM to support Scheduler-ACK mode.
1179 * This register points to BC CB for queue 0, must be on 1024-byte boundary.
1180 * Others are spaced by 1024 bytes.
1181 * Each BC CB is 2 bytes * (256 + 64) = 740 bytes, followed by 384 bytes pad.
1182 * (Index into a queue's BC CB) = (index into queue's TFD CB) = (SSN & 0xff).
1183 * Bit fields:
1184 * 25-00: Byte Count CB physical address [35:10], must be 1024-byte aligned.
1185 */
1186#define SCD_DRAM_BASE_ADDR (SCD_START_OFFSET + 0x10)
1187
1188/*
1189 * Enables any/all Tx DMA/FIFO channels.
1190 * Scheduler generates requests for only the active channels.
1191 * Set this to 0xff to enable all 8 channels (normal usage).
1192 * Bit fields:
1193 * 7- 0: Enable (1), disable (0), one bit for each channel 0-7
1194 */
1195#define SCD_TXFACT (SCD_START_OFFSET + 0x1c)
1196
1197/* Mask to enable contiguous Tx DMA/FIFO channels between "lo" and "hi". */
1198#define SCD_TXFACT_REG_TXFIFO_MASK(lo, hi) \
1199 ((1 << (hi)) | ((1 << (hi)) - (1 << (lo))))
1200
1201/*
1202 * Queue (x) Write Pointers (indexes, really!), one for each Tx queue.
1203 * Initialized and updated by driver as new TFDs are added to queue.
1204 * NOTE: If using Block Ack, index must correspond to frame's
1205 * Start Sequence Number; index = (SSN & 0xff)
1206 * NOTE: Alternative to HBUS_TARG_WRPTR, which is what Linux driver uses?
1207 */
1208#define SCD_QUEUE_WRPTR(x) (SCD_START_OFFSET + 0x24 + (x) * 4)
1209
1210/*
1211 * Queue (x) Read Pointers (indexes, really!), one for each Tx queue.
1212 * For FIFO mode, index indicates next frame to transmit.
1213 * For Scheduler-ACK mode, index indicates first frame in Tx window.
1214 * Initialized by driver, updated by scheduler.
1215 */
1216#define SCD_QUEUE_RDPTR(x) (SCD_START_OFFSET + 0x64 + (x) * 4)
1217
1218/*
1219 * Select which queues work in chain mode (1) vs. not (0).
1220 * Use chain mode to build chains of aggregated frames.
1221 * Bit fields:
1222 * 31-16: Reserved
1223 * 15-00: Mode, one bit for each queue -- 1: Chain mode, 0: one-at-a-time
1224 * NOTE: If driver sets up queue for chain mode, it should be also set up
1225 * Scheduler-ACK mode as well, via SCD_QUEUE_STATUS_BITS(x).
1226 */
1227#define SCD_QUEUECHAIN_SEL (SCD_START_OFFSET + 0xd0)
1228
1229/*
1230 * Select which queues interrupt driver when scheduler increments
1231 * a queue's read pointer (index).
1232 * Bit fields:
1233 * 31-16: Reserved
1234 * 15-00: Interrupt enable, one bit for each queue -- 1: enabled, 0: disabled
1235 * NOTE: This functionality is apparently a no-op; driver relies on interrupts
1236 * from Rx queue to read Tx command responses and update Tx queues.
1237 */
1238#define SCD_INTERRUPT_MASK (SCD_START_OFFSET + 0xe4)
1239
1240/*
1241 * Queue search status registers. One for each queue.
1242 * Sets up queue mode and assigns queue to Tx DMA channel.
1243 * Bit fields:
1244 * 19-10: Write mask/enable bits for bits 0-9
1245 * 9: Driver should init to "0"
1246 * 8: Scheduler-ACK mode (1), non-Scheduler-ACK (i.e. FIFO) mode (0).
1247 * Driver should init to "1" for aggregation mode, or "0" otherwise.
1248 * 7-6: Driver should init to "0"
1249 * 5: Window Size Left; indicates whether scheduler can request
1250 * another TFD, based on window size, etc. Driver should init
1251 * this bit to "1" for aggregation mode, or "0" for non-agg.
1252 * 4-1: Tx FIFO to use (range 0-7).
1253 * 0: Queue is active (1), not active (0).
1254 * Other bits should be written as "0"
1255 *
1256 * NOTE: If enabling Scheduler-ACK mode, chain mode should also be enabled
1257 * via SCD_QUEUECHAIN_SEL.
1258 */
1259#define SCD_QUEUE_STATUS_BITS(x) (SCD_START_OFFSET + 0x104 + (x) * 4)
1260
1261/* Bit field positions */
1262#define SCD_QUEUE_STTS_REG_POS_ACTIVE (0)
1263#define SCD_QUEUE_STTS_REG_POS_TXF (1)
1264#define SCD_QUEUE_STTS_REG_POS_WSL (5)
1265#define SCD_QUEUE_STTS_REG_POS_SCD_ACK (8)
1266
1267/* Write masks */
1268#define SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN (10)
1269#define SCD_QUEUE_STTS_REG_MSK (0x0007FC00)
1270
1271/**
1272 * 4965 internal SRAM structures for scheduler, shared with driver ...
1273 *
1274 * Driver should clear and initialize the following areas after receiving
1275 * "Alive" response from 4965 uCode, i.e. after initial
1276 * uCode load, or after a uCode load done for error recovery:
1277 *
1278 * SCD_CONTEXT_DATA_OFFSET (size 128 bytes)
1279 * SCD_TX_STTS_BITMAP_OFFSET (size 256 bytes)
1280 * SCD_TRANSLATE_TBL_OFFSET (size 32 bytes)
1281 *
1282 * Driver accesses SRAM via HBUS_TARG_MEM_* registers.
1283 * Driver reads base address of this scheduler area from SCD_SRAM_BASE_ADDR.
1284 * All OFFSET values must be added to this base address.
1285 */
1286
1287/*
1288 * Queue context. One 8-byte entry for each of 16 queues.
1289 *
1290 * Driver should clear this entire area (size 0x80) to 0 after receiving
1291 * "Alive" notification from uCode. Additionally, driver should init
1292 * each queue's entry as follows:
1293 *
1294 * LS Dword bit fields:
1295 * 0-06: Max Tx window size for Scheduler-ACK. Driver should init to 64.
1296 *
1297 * MS Dword bit fields:
1298 * 16-22: Frame limit. Driver should init to 10 (0xa).
1299 *
1300 * Driver should init all other bits to 0.
1301 *
1302 * Init must be done after driver receives "Alive" response from 4965 uCode,
1303 * and when setting up queue for aggregation.
1304 */
1305#define SCD_CONTEXT_DATA_OFFSET 0x380
1306#define SCD_CONTEXT_QUEUE_OFFSET(x) (SCD_CONTEXT_DATA_OFFSET + ((x) * 8))
1307
1308#define SCD_QUEUE_CTX_REG1_WIN_SIZE_POS (0)
1309#define SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK (0x0000007F)
1310#define SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS (16)
1311#define SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK (0x007F0000)
1312
1313/*
1314 * Tx Status Bitmap
1315 *
1316 * Driver should clear this entire area (size 0x100) to 0 after receiving
1317 * "Alive" notification from uCode. Area is used only by device itself;
1318 * no other support (besides clearing) is required from driver.
1319 */
1320#define SCD_TX_STTS_BITMAP_OFFSET 0x400
1321
1322/*
1323 * RAxTID to queue translation mapping.
1324 *
1325 * When queue is in Scheduler-ACK mode, frames placed in a that queue must be
1326 * for only one combination of receiver address (RA) and traffic ID (TID), i.e.
1327 * one QOS priority level destined for one station (for this wireless link,
1328 * not final destination). The SCD_TRANSLATE_TABLE area provides 16 16-bit
1329 * mappings, one for each of the 16 queues. If queue is not in Scheduler-ACK
1330 * mode, the device ignores the mapping value.
1331 *
1332 * Bit fields, for each 16-bit map:
1333 * 15-9: Reserved, set to 0
1334 * 8-4: Index into device's station table for recipient station
1335 * 3-0: Traffic ID (tid), range 0-15
1336 *
1337 * Driver should clear this entire area (size 32 bytes) to 0 after receiving
1338 * "Alive" notification from uCode. To update a 16-bit map value, driver
1339 * must read a dword-aligned value from device SRAM, replace the 16-bit map
1340 * value of interest, and write the dword value back into device SRAM.
1341 */
1342#define SCD_TRANSLATE_TBL_OFFSET 0x500
1343
1344/* Find translation table dword to read/write for given queue */
1345#define SCD_TRANSLATE_TBL_OFFSET_QUEUE(x) \
1346 ((SCD_TRANSLATE_TBL_OFFSET + ((x) * 2)) & 0xfffffffc)
1347
1348#define SCD_TXFIFO_POS_TID (0)
1349#define SCD_TXFIFO_POS_RA (4)
1350#define SCD_QUEUE_RA_TID_MAP_RATID_MSK (0x01FF)
1351
1352/*********************** END TX SCHEDULER *************************************/
1353
1354static inline u8 iwl4965_hw_get_rate(__le32 rate_n_flags)
1355{
1356 return le32_to_cpu(rate_n_flags) & 0xFF;
1357}
1358static inline u16 iwl4965_hw_get_rate_n_flags(__le32 rate_n_flags)
1359{
1360 return le32_to_cpu(rate_n_flags) & 0xFFFF;
1361}
1362static inline __le32 iwl4965_hw_set_rate_n_flags(u8 rate, u16 flags)
1363{
1364 return cpu_to_le32(flags|(u16)rate);
1365}
1366
1367 797
1368/** 798/**
1369 * Tx/Rx Queues 799 * Tx/Rx Queues
@@ -1385,14 +815,15 @@ static inline __le32 iwl4965_hw_set_rate_n_flags(u8 rate, u16 flags)
1385 * up to 7 DMA channels (FIFOs). Each Tx queue is supported by a circular array 815 * up to 7 DMA channels (FIFOs). Each Tx queue is supported by a circular array
1386 * in DRAM containing 256 Transmit Frame Descriptors (TFDs). 816 * in DRAM containing 256 Transmit Frame Descriptors (TFDs).
1387 */ 817 */
1388#define IWL4965_MAX_WIN_SIZE 64 818#define IWL49_MAX_WIN_SIZE 64
1389#define IWL4965_QUEUE_SIZE 256 819#define IWL49_QUEUE_SIZE 256
1390#define IWL4965_NUM_FIFOS 7 820#define IWL49_NUM_FIFOS 7
1391#define IWL4965_MAX_NUM_QUEUES 16 821#define IWL49_CMD_FIFO_NUM 4
1392 822#define IWL49_NUM_QUEUES 16
823#define IWL49_NUM_AMPDU_QUEUES 8
1393 824
1394/** 825/**
1395 * struct iwl4965_tfd_frame_data 826 * struct iwl_tfd_frame_data
1396 * 827 *
1397 * Describes up to 2 buffers containing (contiguous) portions of a Tx frame. 828 * Describes up to 2 buffers containing (contiguous) portions of a Tx frame.
1398 * Each buffer must be on dword boundary. 829 * Each buffer must be on dword boundary.
@@ -1411,7 +842,7 @@ static inline __le32 iwl4965_hw_set_rate_n_flags(u8 rate, u16 flags)
1411 * 31-20: Tx buffer 2 length (bytes) 842 * 31-20: Tx buffer 2 length (bytes)
1412 * 19- 0: Tx buffer 2 address bits [35:16] 843 * 19- 0: Tx buffer 2 address bits [35:16]
1413 */ 844 */
1414struct iwl4965_tfd_frame_data { 845struct iwl_tfd_frame_data {
1415 __le32 tb1_addr; 846 __le32 tb1_addr;
1416 847
1417 __le32 val1; 848 __le32 val1;
@@ -1441,7 +872,7 @@ struct iwl4965_tfd_frame_data {
1441 872
1442 873
1443/** 874/**
1444 * struct iwl4965_tfd_frame 875 * struct iwl_tfd_frame
1445 * 876 *
1446 * Transmit Frame Descriptor (TFD) 877 * Transmit Frame Descriptor (TFD)
1447 * 878 *
@@ -1468,7 +899,7 @@ struct iwl4965_tfd_frame_data {
1468 * 899 *
1469 * A maximum of 255 (not 256!) TFDs may be on a queue waiting for Tx. 900 * A maximum of 255 (not 256!) TFDs may be on a queue waiting for Tx.
1470 */ 901 */
1471struct iwl4965_tfd_frame { 902struct iwl_tfd_frame {
1472 __le32 val0; 903 __le32 val0;
1473 /* __le32 rsvd1:24; */ 904 /* __le32 rsvd1:24; */
1474 /* __le32 num_tbs:5; */ 905 /* __le32 num_tbs:5; */
@@ -1477,7 +908,7 @@ struct iwl4965_tfd_frame {
1477#define IWL_num_tbs_SYM val0 908#define IWL_num_tbs_SYM val0
1478 /* __le32 rsvd2:1; */ 909 /* __le32 rsvd2:1; */
1479 /* __le32 padding:2; */ 910 /* __le32 padding:2; */
1480 struct iwl4965_tfd_frame_data pa[10]; 911 struct iwl_tfd_frame_data pa[10];
1481 __le32 reserved; 912 __le32 reserved;
1482} __attribute__ ((packed)); 913} __attribute__ ((packed));
1483 914
@@ -1520,10 +951,10 @@ struct iwl4965_queue_byte_cnt_entry {
1520 * 4965 assumes tables are separated by 1024 bytes. 951 * 4965 assumes tables are separated by 1024 bytes.
1521 */ 952 */
1522struct iwl4965_sched_queue_byte_cnt_tbl { 953struct iwl4965_sched_queue_byte_cnt_tbl {
1523 struct iwl4965_queue_byte_cnt_entry tfd_offset[IWL4965_QUEUE_SIZE + 954 struct iwl4965_queue_byte_cnt_entry tfd_offset[IWL49_QUEUE_SIZE +
1524 IWL4965_MAX_WIN_SIZE]; 955 IWL49_MAX_WIN_SIZE];
1525 u8 dont_care[1024 - 956 u8 dont_care[1024 -
1526 (IWL4965_QUEUE_SIZE + IWL4965_MAX_WIN_SIZE) * 957 (IWL49_QUEUE_SIZE + IWL49_MAX_WIN_SIZE) *
1527 sizeof(__le16)]; 958 sizeof(__le16)];
1528} __attribute__ ((packed)); 959} __attribute__ ((packed));
1529 960
@@ -1553,7 +984,7 @@ struct iwl4965_sched_queue_byte_cnt_tbl {
1553 */ 984 */
1554struct iwl4965_shared { 985struct iwl4965_shared {
1555 struct iwl4965_sched_queue_byte_cnt_tbl 986 struct iwl4965_sched_queue_byte_cnt_tbl
1556 queues_byte_cnt_tbls[IWL4965_MAX_NUM_QUEUES]; 987 queues_byte_cnt_tbls[IWL49_NUM_QUEUES];
1557 __le32 rb_closed; 988 __le32 rb_closed;
1558 989
1559 /* __le32 rb_closed_stts_rb_num:12; */ 990 /* __le32 rb_closed_stts_rb_num:12; */
diff --git a/drivers/net/wireless/iwlwifi/iwl-4965.c b/drivers/net/wireless/iwlwifi/iwl-4965.c
index de330ae0ca95..9838de5f4369 100644
--- a/drivers/net/wireless/iwlwifi/iwl-4965.c
+++ b/drivers/net/wireless/iwlwifi/iwl-4965.c
@@ -26,7 +26,6 @@
26 26
27#include <linux/kernel.h> 27#include <linux/kernel.h>
28#include <linux/module.h> 28#include <linux/module.h>
29#include <linux/version.h>
30#include <linux/init.h> 29#include <linux/init.h>
31#include <linux/pci.h> 30#include <linux/pci.h>
32#include <linux/dma-mapping.h> 31#include <linux/dma-mapping.h>
@@ -39,81 +38,33 @@
39#include <asm/unaligned.h> 38#include <asm/unaligned.h>
40 39
41#include "iwl-eeprom.h" 40#include "iwl-eeprom.h"
42#include "iwl-4965.h" 41#include "iwl-dev.h"
43#include "iwl-core.h" 42#include "iwl-core.h"
44#include "iwl-io.h" 43#include "iwl-io.h"
45#include "iwl-helpers.h" 44#include "iwl-helpers.h"
45#include "iwl-calib.h"
46#include "iwl-sta.h"
47
48static int iwl4965_send_tx_power(struct iwl_priv *priv);
49static int iwl4965_hw_get_temperature(const struct iwl_priv *priv);
50
51/* Change firmware file name, using "-" and incrementing number,
52 * *only* when uCode interface or architecture changes so that it
53 * is not compatible with earlier drivers.
54 * This number will also appear in << 8 position of 1st dword of uCode file */
55#define IWL4965_UCODE_API "-2"
56
46 57
47/* module parameters */ 58/* module parameters */
48static struct iwl_mod_params iwl4965_mod_params = { 59static struct iwl_mod_params iwl4965_mod_params = {
49 .num_of_queues = IWL4965_MAX_NUM_QUEUES, 60 .num_of_queues = IWL49_NUM_QUEUES,
61 .num_of_ampdu_queues = IWL49_NUM_AMPDU_QUEUES,
50 .enable_qos = 1, 62 .enable_qos = 1,
51 .amsdu_size_8K = 1, 63 .amsdu_size_8K = 1,
64 .restart_fw = 1,
52 /* the rest are 0 by default */ 65 /* the rest are 0 by default */
53}; 66};
54 67
55static void iwl4965_hw_card_show_info(struct iwl_priv *priv);
56
57#define IWL_DECLARE_RATE_INFO(r, s, ip, in, rp, rn, pp, np) \
58 [IWL_RATE_##r##M_INDEX] = { IWL_RATE_##r##M_PLCP, \
59 IWL_RATE_SISO_##s##M_PLCP, \
60 IWL_RATE_MIMO_##s##M_PLCP, \
61 IWL_RATE_##r##M_IEEE, \
62 IWL_RATE_##ip##M_INDEX, \
63 IWL_RATE_##in##M_INDEX, \
64 IWL_RATE_##rp##M_INDEX, \
65 IWL_RATE_##rn##M_INDEX, \
66 IWL_RATE_##pp##M_INDEX, \
67 IWL_RATE_##np##M_INDEX }
68
69/*
70 * Parameter order:
71 * rate, ht rate, prev rate, next rate, prev tgg rate, next tgg rate
72 *
73 * If there isn't a valid next or previous rate then INV is used which
74 * maps to IWL_RATE_INVALID
75 *
76 */
77const struct iwl4965_rate_info iwl4965_rates[IWL_RATE_COUNT] = {
78 IWL_DECLARE_RATE_INFO(1, INV, INV, 2, INV, 2, INV, 2), /* 1mbps */
79 IWL_DECLARE_RATE_INFO(2, INV, 1, 5, 1, 5, 1, 5), /* 2mbps */
80 IWL_DECLARE_RATE_INFO(5, INV, 2, 6, 2, 11, 2, 11), /*5.5mbps */
81 IWL_DECLARE_RATE_INFO(11, INV, 9, 12, 9, 12, 5, 18), /* 11mbps */
82 IWL_DECLARE_RATE_INFO(6, 6, 5, 9, 5, 11, 5, 11), /* 6mbps */
83 IWL_DECLARE_RATE_INFO(9, 6, 6, 11, 6, 11, 5, 11), /* 9mbps */
84 IWL_DECLARE_RATE_INFO(12, 12, 11, 18, 11, 18, 11, 18), /* 12mbps */
85 IWL_DECLARE_RATE_INFO(18, 18, 12, 24, 12, 24, 11, 24), /* 18mbps */
86 IWL_DECLARE_RATE_INFO(24, 24, 18, 36, 18, 36, 18, 36), /* 24mbps */
87 IWL_DECLARE_RATE_INFO(36, 36, 24, 48, 24, 48, 24, 48), /* 36mbps */
88 IWL_DECLARE_RATE_INFO(48, 48, 36, 54, 36, 54, 36, 54), /* 48mbps */
89 IWL_DECLARE_RATE_INFO(54, 54, 48, INV, 48, INV, 48, INV),/* 54mbps */
90 IWL_DECLARE_RATE_INFO(60, 60, 48, INV, 48, INV, 48, INV),/* 60mbps */
91};
92
93#ifdef CONFIG_IWL4965_HT
94
95static const u16 default_tid_to_tx_fifo[] = {
96 IWL_TX_FIFO_AC1,
97 IWL_TX_FIFO_AC0,
98 IWL_TX_FIFO_AC0,
99 IWL_TX_FIFO_AC1,
100 IWL_TX_FIFO_AC2,
101 IWL_TX_FIFO_AC2,
102 IWL_TX_FIFO_AC3,
103 IWL_TX_FIFO_AC3,
104 IWL_TX_FIFO_NONE,
105 IWL_TX_FIFO_NONE,
106 IWL_TX_FIFO_NONE,
107 IWL_TX_FIFO_NONE,
108 IWL_TX_FIFO_NONE,
109 IWL_TX_FIFO_NONE,
110 IWL_TX_FIFO_NONE,
111 IWL_TX_FIFO_NONE,
112 IWL_TX_FIFO_AC3
113};
114
115#endif /*CONFIG_IWL4965_HT */
116
117/* check contents of special bootstrap uCode SRAM */ 68/* check contents of special bootstrap uCode SRAM */
118static int iwl4965_verify_bsm(struct iwl_priv *priv) 69static int iwl4965_verify_bsm(struct iwl_priv *priv)
119{ 70{
@@ -192,15 +143,18 @@ static int iwl4965_load_bsm(struct iwl_priv *priv)
192 143
193 IWL_DEBUG_INFO("Begin load bsm\n"); 144 IWL_DEBUG_INFO("Begin load bsm\n");
194 145
146 priv->ucode_type = UCODE_RT;
147
195 /* make sure bootstrap program is no larger than BSM's SRAM size */ 148 /* make sure bootstrap program is no larger than BSM's SRAM size */
196 if (len > IWL_MAX_BSM_SIZE) 149 if (len > IWL_MAX_BSM_SIZE)
197 return -EINVAL; 150 return -EINVAL;
198 151
199 /* Tell bootstrap uCode where to find the "Initialize" uCode 152 /* Tell bootstrap uCode where to find the "Initialize" uCode
200 * in host DRAM ... host DRAM physical address bits 35:4 for 4965. 153 * in host DRAM ... host DRAM physical address bits 35:4 for 4965.
201 * NOTE: iwl4965_initialize_alive_start() will replace these values, 154 * NOTE: iwl_init_alive_start() will replace these values,
202 * after the "initialize" uCode has run, to point to 155 * after the "initialize" uCode has run, to point to
203 * runtime/protocol instructions and backup data cache. */ 156 * runtime/protocol instructions and backup data cache.
157 */
204 pinst = priv->ucode_init.p_addr >> 4; 158 pinst = priv->ucode_init.p_addr >> 4;
205 pdata = priv->ucode_init_data.p_addr >> 4; 159 pdata = priv->ucode_init_data.p_addr >> 4;
206 inst_len = priv->ucode_init.len; 160 inst_len = priv->ucode_init.len;
@@ -259,274 +213,25 @@ static int iwl4965_load_bsm(struct iwl_priv *priv)
259 return 0; 213 return 0;
260} 214}
261 215
262static int iwl4965_init_drv(struct iwl_priv *priv)
263{
264 int ret;
265 int i;
266
267 priv->antenna = (enum iwl4965_antenna)priv->cfg->mod_params->antenna;
268 priv->retry_rate = 1;
269 priv->ibss_beacon = NULL;
270
271 spin_lock_init(&priv->lock);
272 spin_lock_init(&priv->power_data.lock);
273 spin_lock_init(&priv->sta_lock);
274 spin_lock_init(&priv->hcmd_lock);
275 spin_lock_init(&priv->lq_mngr.lock);
276
277 priv->shared_virt = pci_alloc_consistent(priv->pci_dev,
278 sizeof(struct iwl4965_shared),
279 &priv->shared_phys);
280
281 if (!priv->shared_virt) {
282 ret = -ENOMEM;
283 goto err;
284 }
285
286 memset(priv->shared_virt, 0, sizeof(struct iwl4965_shared));
287
288
289 for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++)
290 INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
291
292 INIT_LIST_HEAD(&priv->free_frames);
293
294 mutex_init(&priv->mutex);
295
296 /* Clear the driver's (not device's) station table */
297 iwlcore_clear_stations_table(priv);
298
299 priv->data_retry_limit = -1;
300 priv->ieee_channels = NULL;
301 priv->ieee_rates = NULL;
302 priv->band = IEEE80211_BAND_2GHZ;
303
304 priv->iw_mode = IEEE80211_IF_TYPE_STA;
305
306 priv->use_ant_b_for_management_frame = 1; /* start with ant B */
307 priv->valid_antenna = 0x7; /* assume all 3 connected */
308 priv->ps_mode = IWL_MIMO_PS_NONE;
309
310 /* Choose which receivers/antennas to use */
311 iwl4965_set_rxon_chain(priv);
312
313 iwlcore_reset_qos(priv);
314
315 priv->qos_data.qos_active = 0;
316 priv->qos_data.qos_cap.val = 0;
317
318 iwlcore_set_rxon_channel(priv, IEEE80211_BAND_2GHZ, 6);
319
320 priv->rates_mask = IWL_RATES_MASK;
321 /* If power management is turned on, default to AC mode */
322 priv->power_mode = IWL_POWER_AC;
323 priv->user_txpower_limit = IWL_DEFAULT_TX_POWER;
324
325 ret = iwl_init_channel_map(priv);
326 if (ret) {
327 IWL_ERROR("initializing regulatory failed: %d\n", ret);
328 goto err;
329 }
330
331 ret = iwl4965_init_geos(priv);
332 if (ret) {
333 IWL_ERROR("initializing geos failed: %d\n", ret);
334 goto err_free_channel_map;
335 }
336
337 ret = ieee80211_register_hw(priv->hw);
338 if (ret) {
339 IWL_ERROR("Failed to register network device (error %d)\n",
340 ret);
341 goto err_free_geos;
342 }
343
344 priv->hw->conf.beacon_int = 100;
345 priv->mac80211_registered = 1;
346
347 return 0;
348
349err_free_geos:
350 iwl4965_free_geos(priv);
351err_free_channel_map:
352 iwl_free_channel_map(priv);
353err:
354 return ret;
355}
356
357static int is_fat_channel(__le32 rxon_flags)
358{
359 return (rxon_flags & RXON_FLG_CHANNEL_MODE_PURE_40_MSK) ||
360 (rxon_flags & RXON_FLG_CHANNEL_MODE_MIXED_MSK);
361}
362
363static u8 is_single_stream(struct iwl_priv *priv)
364{
365#ifdef CONFIG_IWL4965_HT
366 if (!priv->current_ht_config.is_ht ||
367 (priv->current_ht_config.supp_mcs_set[1] == 0) ||
368 (priv->ps_mode == IWL_MIMO_PS_STATIC))
369 return 1;
370#else
371 return 1;
372#endif /*CONFIG_IWL4965_HT */
373 return 0;
374}
375
376int iwl4965_hwrate_to_plcp_idx(u32 rate_n_flags)
377{
378 int idx = 0;
379
380 /* 4965 HT rate format */
381 if (rate_n_flags & RATE_MCS_HT_MSK) {
382 idx = (rate_n_flags & 0xff);
383
384 if (idx >= IWL_RATE_MIMO_6M_PLCP)
385 idx = idx - IWL_RATE_MIMO_6M_PLCP;
386
387 idx += IWL_FIRST_OFDM_RATE;
388 /* skip 9M not supported in ht*/
389 if (idx >= IWL_RATE_9M_INDEX)
390 idx += 1;
391 if ((idx >= IWL_FIRST_OFDM_RATE) && (idx <= IWL_LAST_OFDM_RATE))
392 return idx;
393
394 /* 4965 legacy rate format, search for match in table */
395 } else {
396 for (idx = 0; idx < ARRAY_SIZE(iwl4965_rates); idx++)
397 if (iwl4965_rates[idx].plcp == (rate_n_flags & 0xFF))
398 return idx;
399 }
400
401 return -1;
402}
403
404/** 216/**
405 * translate ucode response to mac80211 tx status control values 217 * iwl4965_set_ucode_ptrs - Set uCode address location
406 */ 218 *
407void iwl4965_hwrate_to_tx_control(struct iwl_priv *priv, u32 rate_n_flags, 219 * Tell initialization uCode where to find runtime uCode.
408 struct ieee80211_tx_control *control) 220 *
409{ 221 * BSM registers initially contain pointers to initialization uCode.
410 int rate_index; 222 * We need to replace them to load runtime uCode inst and data,
411 223 * and to save runtime data when powering down.
412 control->antenna_sel_tx =
413 ((rate_n_flags & RATE_MCS_ANT_AB_MSK) >> RATE_MCS_ANT_POS);
414 if (rate_n_flags & RATE_MCS_HT_MSK)
415 control->flags |= IEEE80211_TXCTL_OFDM_HT;
416 if (rate_n_flags & RATE_MCS_GF_MSK)
417 control->flags |= IEEE80211_TXCTL_GREEN_FIELD;
418 if (rate_n_flags & RATE_MCS_FAT_MSK)
419 control->flags |= IEEE80211_TXCTL_40_MHZ_WIDTH;
420 if (rate_n_flags & RATE_MCS_DUP_MSK)
421 control->flags |= IEEE80211_TXCTL_DUP_DATA;
422 if (rate_n_flags & RATE_MCS_SGI_MSK)
423 control->flags |= IEEE80211_TXCTL_SHORT_GI;
424 /* since iwl4965_hwrate_to_plcp_idx is band indifferent, we always use
425 * IEEE80211_BAND_2GHZ band as it contains all the rates */
426 rate_index = iwl4965_hwrate_to_plcp_idx(rate_n_flags);
427 if (rate_index == -1)
428 control->tx_rate = NULL;
429 else
430 control->tx_rate =
431 &priv->bands[IEEE80211_BAND_2GHZ].bitrates[rate_index];
432}
433
434/*
435 * Determine how many receiver/antenna chains to use.
436 * More provides better reception via diversity. Fewer saves power.
437 * MIMO (dual stream) requires at least 2, but works better with 3.
438 * This does not determine *which* chains to use, just how many.
439 */ 224 */
440static int iwl4965_get_rx_chain_counter(struct iwl_priv *priv, 225static int iwl4965_set_ucode_ptrs(struct iwl_priv *priv)
441 u8 *idle_state, u8 *rx_state)
442{
443 u8 is_single = is_single_stream(priv);
444 u8 is_cam = test_bit(STATUS_POWER_PMI, &priv->status) ? 0 : 1;
445
446 /* # of Rx chains to use when expecting MIMO. */
447 if (is_single || (!is_cam && (priv->ps_mode == IWL_MIMO_PS_STATIC)))
448 *rx_state = 2;
449 else
450 *rx_state = 3;
451
452 /* # Rx chains when idling and maybe trying to save power */
453 switch (priv->ps_mode) {
454 case IWL_MIMO_PS_STATIC:
455 case IWL_MIMO_PS_DYNAMIC:
456 *idle_state = (is_cam) ? 2 : 1;
457 break;
458 case IWL_MIMO_PS_NONE:
459 *idle_state = (is_cam) ? *rx_state : 1;
460 break;
461 default:
462 *idle_state = 1;
463 break;
464 }
465
466 return 0;
467}
468
469int iwl4965_hw_rxq_stop(struct iwl_priv *priv)
470{
471 int rc;
472 unsigned long flags;
473
474 spin_lock_irqsave(&priv->lock, flags);
475 rc = iwl_grab_nic_access(priv);
476 if (rc) {
477 spin_unlock_irqrestore(&priv->lock, flags);
478 return rc;
479 }
480
481 /* stop Rx DMA */
482 iwl_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0);
483 rc = iwl_poll_direct_bit(priv, FH_MEM_RSSR_RX_STATUS_REG,
484 (1 << 24), 1000);
485 if (rc < 0)
486 IWL_ERROR("Can't stop Rx DMA.\n");
487
488 iwl_release_nic_access(priv);
489 spin_unlock_irqrestore(&priv->lock, flags);
490
491 return 0;
492}
493
494u8 iwl4965_hw_find_station(struct iwl_priv *priv, const u8 *addr)
495{ 226{
496 int i; 227 dma_addr_t pinst;
497 int start = 0; 228 dma_addr_t pdata;
498 int ret = IWL_INVALID_STATION;
499 unsigned long flags; 229 unsigned long flags;
500 DECLARE_MAC_BUF(mac); 230 int ret = 0;
501
502 if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) ||
503 (priv->iw_mode == IEEE80211_IF_TYPE_AP))
504 start = IWL_STA_ID;
505
506 if (is_broadcast_ether_addr(addr))
507 return priv->hw_params.bcast_sta_id;
508
509 spin_lock_irqsave(&priv->sta_lock, flags);
510 for (i = start; i < priv->hw_params.max_stations; i++)
511 if ((priv->stations[i].used) &&
512 (!compare_ether_addr
513 (priv->stations[i].sta.sta.addr, addr))) {
514 ret = i;
515 goto out;
516 }
517
518 IWL_DEBUG_ASSOC_LIMIT("can not find STA %s total %d\n",
519 print_mac(mac, addr), priv->num_stations);
520 231
521 out: 232 /* bits 35:4 for 4965 */
522 spin_unlock_irqrestore(&priv->sta_lock, flags); 233 pinst = priv->ucode_code.p_addr >> 4;
523 return ret; 234 pdata = priv->ucode_data_backup.p_addr >> 4;
524}
525
526static int iwl4965_nic_set_pwr_src(struct iwl_priv *priv, int pwr_max)
527{
528 int ret;
529 unsigned long flags;
530 235
531 spin_lock_irqsave(&priv->lock, flags); 236 spin_lock_irqsave(&priv->lock, flags);
532 ret = iwl_grab_nic_access(priv); 237 ret = iwl_grab_nic_access(priv);
@@ -535,340 +240,209 @@ static int iwl4965_nic_set_pwr_src(struct iwl_priv *priv, int pwr_max)
535 return ret; 240 return ret;
536 } 241 }
537 242
538 if (!pwr_max) { 243 /* Tell bootstrap uCode where to find image to load */
539 u32 val; 244 iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
540 245 iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
541 ret = pci_read_config_dword(priv->pci_dev, PCI_POWER_SOURCE, 246 iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
542 &val); 247 priv->ucode_data.len);
543
544 if (val & PCI_CFG_PMC_PME_FROM_D3COLD_SUPPORT)
545 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
546 APMG_PS_CTRL_VAL_PWR_SRC_VAUX,
547 ~APMG_PS_CTRL_MSK_PWR_SRC);
548 } else
549 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
550 APMG_PS_CTRL_VAL_PWR_SRC_VMAIN,
551 ~APMG_PS_CTRL_MSK_PWR_SRC);
552 248
249 /* Inst bytecount must be last to set up, bit 31 signals uCode
250 * that all new ptr/size info is in place */
251 iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
252 priv->ucode_code.len | BSM_DRAM_INST_LOAD);
553 iwl_release_nic_access(priv); 253 iwl_release_nic_access(priv);
254
554 spin_unlock_irqrestore(&priv->lock, flags); 255 spin_unlock_irqrestore(&priv->lock, flags);
555 256
257 IWL_DEBUG_INFO("Runtime uCode pointers are set.\n");
258
556 return ret; 259 return ret;
557} 260}
558 261
559static int iwl4965_rx_init(struct iwl_priv *priv, struct iwl4965_rx_queue *rxq) 262/**
560{ 263 * iwl4965_init_alive_start - Called after REPLY_ALIVE notification received
561 int ret; 264 *
562 unsigned long flags; 265 * Called after REPLY_ALIVE notification received from "initialize" uCode.
563 unsigned int rb_size; 266 *
564 267 * The 4965 "initialize" ALIVE reply contains calibration data for:
565 spin_lock_irqsave(&priv->lock, flags); 268 * Voltage, temperature, and MIMO tx gain correction, now stored in priv
566 ret = iwl_grab_nic_access(priv); 269 * (3945 does not contain this data).
567 if (ret) { 270 *
568 spin_unlock_irqrestore(&priv->lock, flags); 271 * Tell "initialize" uCode to go ahead and load the runtime uCode.
569 return ret; 272*/
273static void iwl4965_init_alive_start(struct iwl_priv *priv)
274{
275 /* Check alive response for "valid" sign from uCode */
276 if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
277 /* We had an error bringing up the hardware, so take it
278 * all the way back down so we can try again */
279 IWL_DEBUG_INFO("Initialize Alive failed.\n");
280 goto restart;
281 }
282
283 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
284 * This is a paranoid check, because we would not have gotten the
285 * "initialize" alive if code weren't properly loaded. */
286 if (iwl_verify_ucode(priv)) {
287 /* Runtime instruction load was bad;
288 * take it all the way back down so we can try again */
289 IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n");
290 goto restart;
291 }
292
293 /* Calculate temperature */
294 priv->temperature = iwl4965_hw_get_temperature(priv);
295
296 /* Send pointers to protocol/runtime uCode image ... init code will
297 * load and launch runtime uCode, which will send us another "Alive"
298 * notification. */
299 IWL_DEBUG_INFO("Initialization Alive received.\n");
300 if (iwl4965_set_ucode_ptrs(priv)) {
301 /* Runtime instruction load won't happen;
302 * take it all the way back down so we can try again */
303 IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n");
304 goto restart;
570 } 305 }
306 return;
571 307
572 if (priv->cfg->mod_params->amsdu_size_8K) 308restart:
573 rb_size = FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_8K; 309 queue_work(priv->workqueue, &priv->restart);
574 else
575 rb_size = FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_4K;
576
577 /* Stop Rx DMA */
578 iwl_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0);
579
580 /* Reset driver's Rx queue write index */
581 iwl_write_direct32(priv, FH_RSCSR_CHNL0_RBDCB_WPTR_REG, 0);
582
583 /* Tell device where to find RBD circular buffer in DRAM */
584 iwl_write_direct32(priv, FH_RSCSR_CHNL0_RBDCB_BASE_REG,
585 rxq->dma_addr >> 8);
586
587 /* Tell device where in DRAM to update its Rx status */
588 iwl_write_direct32(priv, FH_RSCSR_CHNL0_STTS_WPTR_REG,
589 (priv->shared_phys +
590 offsetof(struct iwl4965_shared, rb_closed)) >> 4);
591
592 /* Enable Rx DMA, enable host interrupt, Rx buffer size 4k, 256 RBDs */
593 iwl_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG,
594 FH_RCSR_RX_CONFIG_CHNL_EN_ENABLE_VAL |
595 FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_INT_HOST_VAL |
596 rb_size |
597 /* 0x10 << 4 | */
598 (RX_QUEUE_SIZE_LOG <<
599 FH_RCSR_RX_CONFIG_RBDCB_SIZE_BITSHIFT));
600
601 /*
602 * iwl_write32(priv,CSR_INT_COAL_REG,0);
603 */
604
605 iwl_release_nic_access(priv);
606 spin_unlock_irqrestore(&priv->lock, flags);
607
608 return 0;
609}
610
611/* Tell 4965 where to find the "keep warm" buffer */
612static int iwl4965_kw_init(struct iwl_priv *priv)
613{
614 unsigned long flags;
615 int rc;
616
617 spin_lock_irqsave(&priv->lock, flags);
618 rc = iwl_grab_nic_access(priv);
619 if (rc)
620 goto out;
621
622 iwl_write_direct32(priv, IWL_FH_KW_MEM_ADDR_REG,
623 priv->kw.dma_addr >> 4);
624 iwl_release_nic_access(priv);
625out:
626 spin_unlock_irqrestore(&priv->lock, flags);
627 return rc;
628} 310}
629 311
630static int iwl4965_kw_alloc(struct iwl_priv *priv) 312static int is_fat_channel(__le32 rxon_flags)
631{ 313{
632 struct pci_dev *dev = priv->pci_dev; 314 return (rxon_flags & RXON_FLG_CHANNEL_MODE_PURE_40_MSK) ||
633 struct iwl4965_kw *kw = &priv->kw; 315 (rxon_flags & RXON_FLG_CHANNEL_MODE_MIXED_MSK);
634
635 kw->size = IWL4965_KW_SIZE; /* TBW need set somewhere else */
636 kw->v_addr = pci_alloc_consistent(dev, kw->size, &kw->dma_addr);
637 if (!kw->v_addr)
638 return -ENOMEM;
639
640 return 0;
641} 316}
642 317
643/** 318/*
644 * iwl4965_kw_free - Free the "keep warm" buffer 319 * EEPROM handlers
645 */ 320 */
646static void iwl4965_kw_free(struct iwl_priv *priv)
647{
648 struct pci_dev *dev = priv->pci_dev;
649 struct iwl4965_kw *kw = &priv->kw;
650 321
651 if (kw->v_addr) { 322static int iwl4965_eeprom_check_version(struct iwl_priv *priv)
652 pci_free_consistent(dev, kw->size, kw->v_addr, kw->dma_addr);
653 memset(kw, 0, sizeof(*kw));
654 }
655}
656
657/**
658 * iwl4965_txq_ctx_reset - Reset TX queue context
659 * Destroys all DMA structures and initialise them again
660 *
661 * @param priv
662 * @return error code
663 */
664static int iwl4965_txq_ctx_reset(struct iwl_priv *priv)
665{ 323{
666 int rc = 0; 324 u16 eeprom_ver;
667 int txq_id, slots_num; 325 u16 calib_ver;
668 unsigned long flags;
669 326
670 iwl4965_kw_free(priv); 327 eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
671 328
672 /* Free all tx/cmd queues and keep-warm buffer */ 329 calib_ver = iwl_eeprom_query16(priv, EEPROM_4965_CALIB_VERSION_OFFSET);
673 iwl4965_hw_txq_ctx_free(priv);
674 330
675 /* Alloc keep-warm buffer */ 331 if (eeprom_ver < EEPROM_4965_EEPROM_VERSION ||
676 rc = iwl4965_kw_alloc(priv); 332 calib_ver < EEPROM_4965_TX_POWER_VERSION)
677 if (rc) { 333 goto err;
678 IWL_ERROR("Keep Warm allocation failed");
679 goto error_kw;
680 }
681
682 spin_lock_irqsave(&priv->lock, flags);
683
684 rc = iwl_grab_nic_access(priv);
685 if (unlikely(rc)) {
686 IWL_ERROR("TX reset failed");
687 spin_unlock_irqrestore(&priv->lock, flags);
688 goto error_reset;
689 }
690
691 /* Turn off all Tx DMA channels */
692 iwl_write_prph(priv, IWL49_SCD_TXFACT, 0);
693 iwl_release_nic_access(priv);
694 spin_unlock_irqrestore(&priv->lock, flags);
695
696 /* Tell 4965 where to find the keep-warm buffer */
697 rc = iwl4965_kw_init(priv);
698 if (rc) {
699 IWL_ERROR("kw_init failed\n");
700 goto error_reset;
701 }
702
703 /* Alloc and init all (default 16) Tx queues,
704 * including the command queue (#4) */
705 for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++) {
706 slots_num = (txq_id == IWL_CMD_QUEUE_NUM) ?
707 TFD_CMD_SLOTS : TFD_TX_CMD_SLOTS;
708 rc = iwl4965_tx_queue_init(priv, &priv->txq[txq_id], slots_num,
709 txq_id);
710 if (rc) {
711 IWL_ERROR("Tx %d queue init failed\n", txq_id);
712 goto error;
713 }
714 }
715 334
716 return rc; 335 return 0;
336err:
337 IWL_ERROR("Unsuported EEPROM VER=0x%x < 0x%x CALIB=0x%x < 0x%x\n",
338 eeprom_ver, EEPROM_4965_EEPROM_VERSION,
339 calib_ver, EEPROM_4965_TX_POWER_VERSION);
340 return -EINVAL;
717 341
718 error:
719 iwl4965_hw_txq_ctx_free(priv);
720 error_reset:
721 iwl4965_kw_free(priv);
722 error_kw:
723 return rc;
724} 342}
725 343
726int iwl4965_hw_nic_init(struct iwl_priv *priv) 344/*
345 * Activate/Deactivat Tx DMA/FIFO channels according tx fifos mask
346 * must be called under priv->lock and mac access
347 */
348static void iwl4965_txq_set_sched(struct iwl_priv *priv, u32 mask)
727{ 349{
728 int rc; 350 iwl_write_prph(priv, IWL49_SCD_TXFACT, mask);
729 unsigned long flags; 351}
730 struct iwl4965_rx_queue *rxq = &priv->rxq;
731 u8 rev_id;
732 u32 val;
733 u8 val_link;
734 352
735 iwl4965_power_init_handle(priv); 353static int iwl4965_apm_init(struct iwl_priv *priv)
354{
355 int ret = 0;
736 356
737 /* nic_init */ 357 iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
738 spin_lock_irqsave(&priv->lock, flags); 358 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
739 359
360 /* disable L0s without affecting L1 :don't wait for ICH L0s bug W/A) */
740 iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS, 361 iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
741 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER); 362 CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX);
742 363
364 /* set "initialization complete" bit to move adapter
365 * D0U* --> D0A* state */
743 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE); 366 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
744 rc = iwl_poll_bit(priv, CSR_GP_CNTRL,
745 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
746 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
747 if (rc < 0) {
748 spin_unlock_irqrestore(&priv->lock, flags);
749 IWL_DEBUG_INFO("Failed to init the card\n");
750 return rc;
751 }
752 367
753 rc = iwl_grab_nic_access(priv); 368 /* wait for clock stabilization */
754 if (rc) { 369 ret = iwl_poll_bit(priv, CSR_GP_CNTRL,
755 spin_unlock_irqrestore(&priv->lock, flags); 370 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
756 return rc; 371 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
372 if (ret < 0) {
373 IWL_DEBUG_INFO("Failed to init the card\n");
374 goto out;
757 } 375 }
758 376
759 iwl_read_prph(priv, APMG_CLK_CTRL_REG); 377 ret = iwl_grab_nic_access(priv);
378 if (ret)
379 goto out;
760 380
761 iwl_write_prph(priv, APMG_CLK_CTRL_REG, 381 /* enable DMA */
762 APMG_CLK_VAL_DMA_CLK_RQT | APMG_CLK_VAL_BSM_CLK_RQT); 382 iwl_write_prph(priv, APMG_CLK_CTRL_REG, APMG_CLK_VAL_DMA_CLK_RQT |
763 iwl_read_prph(priv, APMG_CLK_CTRL_REG); 383 APMG_CLK_VAL_BSM_CLK_RQT);
764 384
765 udelay(20); 385 udelay(20);
766 386
387 /* disable L1-Active */
767 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG, 388 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
768 APMG_PCIDEV_STT_VAL_L1_ACT_DIS); 389 APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
769 390
770 iwl_release_nic_access(priv); 391 iwl_release_nic_access(priv);
771 iwl_write32(priv, CSR_INT_COALESCING, 512 / 32); 392out:
772 spin_unlock_irqrestore(&priv->lock, flags); 393 return ret;
394}
773 395
774 /* Determine HW type */
775 rc = pci_read_config_byte(priv->pci_dev, PCI_REVISION_ID, &rev_id);
776 if (rc)
777 return rc;
778 396
779 IWL_DEBUG_INFO("HW Revision ID = 0x%X\n", rev_id); 397static void iwl4965_nic_config(struct iwl_priv *priv)
398{
399 unsigned long flags;
400 u32 val;
401 u16 radio_cfg;
402 u16 link;
780 403
781 iwl4965_nic_set_pwr_src(priv, 1);
782 spin_lock_irqsave(&priv->lock, flags); 404 spin_lock_irqsave(&priv->lock, flags);
783 405
784 if ((rev_id & 0x80) == 0x80 && (rev_id & 0x7f) < 8) { 406 if ((priv->rev_id & 0x80) == 0x80 && (priv->rev_id & 0x7f) < 8) {
785 pci_read_config_dword(priv->pci_dev, PCI_REG_WUM8, &val); 407 pci_read_config_dword(priv->pci_dev, PCI_REG_WUM8, &val);
786 /* Enable No Snoop field */ 408 /* Enable No Snoop field */
787 pci_write_config_dword(priv->pci_dev, PCI_REG_WUM8, 409 pci_write_config_dword(priv->pci_dev, PCI_REG_WUM8,
788 val & ~(1 << 11)); 410 val & ~(1 << 11));
789 } 411 }
790 412
791 spin_unlock_irqrestore(&priv->lock, flags); 413 pci_read_config_word(priv->pci_dev, PCI_CFG_LINK_CTRL, &link);
792
793 if (priv->eeprom.calib_version < EEPROM_TX_POWER_VERSION_NEW) {
794 IWL_ERROR("Older EEPROM detected! Aborting.\n");
795 return -EINVAL;
796 }
797 414
798 pci_read_config_byte(priv->pci_dev, PCI_LINK_CTRL, &val_link); 415 /* L1 is enabled by BIOS */
416 if ((link & PCI_CFG_LINK_CTRL_VAL_L1_EN) == PCI_CFG_LINK_CTRL_VAL_L1_EN)
417 /* diable L0S disabled L1A enabled */
418 iwl_set_bit(priv, CSR_GIO_REG, CSR_GIO_REG_VAL_L0S_ENABLED);
419 else
420 /* L0S enabled L1A disabled */
421 iwl_clear_bit(priv, CSR_GIO_REG, CSR_GIO_REG_VAL_L0S_ENABLED);
799 422
800 /* disable L1 entry -- workaround for pre-B1 */ 423 radio_cfg = iwl_eeprom_query16(priv, EEPROM_RADIO_CONFIG);
801 pci_write_config_byte(priv->pci_dev, PCI_LINK_CTRL, val_link & ~0x02);
802 424
803 spin_lock_irqsave(&priv->lock, flags); 425 /* write radio config values to register */
426 if (EEPROM_RF_CFG_TYPE_MSK(radio_cfg) == EEPROM_4965_RF_CFG_TYPE_MAX)
427 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
428 EEPROM_RF_CFG_TYPE_MSK(radio_cfg) |
429 EEPROM_RF_CFG_STEP_MSK(radio_cfg) |
430 EEPROM_RF_CFG_DASH_MSK(radio_cfg));
804 431
805 /* set CSR_HW_CONFIG_REG for uCode use */ 432 /* set CSR_HW_CONFIG_REG for uCode use */
806
807 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG, 433 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
808 CSR49_HW_IF_CONFIG_REG_BIT_4965_R | 434 CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |
809 CSR49_HW_IF_CONFIG_REG_BIT_RADIO_SI | 435 CSR_HW_IF_CONFIG_REG_BIT_MAC_SI);
810 CSR49_HW_IF_CONFIG_REG_BIT_MAC_SI);
811
812 rc = iwl_grab_nic_access(priv);
813 if (rc < 0) {
814 spin_unlock_irqrestore(&priv->lock, flags);
815 IWL_DEBUG_INFO("Failed to init the card\n");
816 return rc;
817 }
818 436
819 iwl_read_prph(priv, APMG_PS_CTRL_REG); 437 priv->calib_info = (struct iwl_eeprom_calib_info *)
820 iwl_set_bits_prph(priv, APMG_PS_CTRL_REG, APMG_PS_CTRL_VAL_RESET_REQ); 438 iwl_eeprom_query_addr(priv, EEPROM_4965_CALIB_TXPOWER_OFFSET);
821 udelay(5);
822 iwl_clear_bits_prph(priv, APMG_PS_CTRL_REG, APMG_PS_CTRL_VAL_RESET_REQ);
823 439
824 iwl_release_nic_access(priv);
825 spin_unlock_irqrestore(&priv->lock, flags); 440 spin_unlock_irqrestore(&priv->lock, flags);
826
827 iwl4965_hw_card_show_info(priv);
828
829 /* end nic_init */
830
831 /* Allocate the RX queue, or reset if it is already allocated */
832 if (!rxq->bd) {
833 rc = iwl4965_rx_queue_alloc(priv);
834 if (rc) {
835 IWL_ERROR("Unable to initialize Rx queue\n");
836 return -ENOMEM;
837 }
838 } else
839 iwl4965_rx_queue_reset(priv, rxq);
840
841 iwl4965_rx_replenish(priv);
842
843 iwl4965_rx_init(priv, rxq);
844
845 spin_lock_irqsave(&priv->lock, flags);
846
847 rxq->need_update = 1;
848 iwl4965_rx_queue_update_write_ptr(priv, rxq);
849
850 spin_unlock_irqrestore(&priv->lock, flags);
851
852 /* Allocate and init all Tx and Command queues */
853 rc = iwl4965_txq_ctx_reset(priv);
854 if (rc)
855 return rc;
856
857 if (priv->eeprom.sku_cap & EEPROM_SKU_CAP_SW_RF_KILL_ENABLE)
858 IWL_DEBUG_RF_KILL("SW RF KILL supported in EEPROM.\n");
859
860 if (priv->eeprom.sku_cap & EEPROM_SKU_CAP_HW_RF_KILL_ENABLE)
861 IWL_DEBUG_RF_KILL("HW RF KILL supported in EEPROM.\n");
862
863 set_bit(STATUS_INIT, &priv->status);
864
865 return 0;
866} 441}
867 442
868int iwl4965_hw_nic_stop_master(struct iwl_priv *priv) 443static int iwl4965_apm_stop_master(struct iwl_priv *priv)
869{ 444{
870 int rc = 0; 445 int ret = 0;
871 u32 reg_val;
872 unsigned long flags; 446 unsigned long flags;
873 447
874 spin_lock_irqsave(&priv->lock, flags); 448 spin_lock_irqsave(&priv->lock, flags);
@@ -876,64 +450,41 @@ int iwl4965_hw_nic_stop_master(struct iwl_priv *priv)
876 /* set stop master bit */ 450 /* set stop master bit */
877 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER); 451 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER);
878 452
879 reg_val = iwl_read32(priv, CSR_GP_CNTRL); 453 ret = iwl_poll_bit(priv, CSR_RESET,
880
881 if (CSR_GP_CNTRL_REG_FLAG_MAC_POWER_SAVE ==
882 (reg_val & CSR_GP_CNTRL_REG_MSK_POWER_SAVE_TYPE))
883 IWL_DEBUG_INFO("Card in power save, master is already "
884 "stopped\n");
885 else {
886 rc = iwl_poll_bit(priv, CSR_RESET,
887 CSR_RESET_REG_FLAG_MASTER_DISABLED, 454 CSR_RESET_REG_FLAG_MASTER_DISABLED,
888 CSR_RESET_REG_FLAG_MASTER_DISABLED, 100); 455 CSR_RESET_REG_FLAG_MASTER_DISABLED, 100);
889 if (rc < 0) { 456 if (ret < 0)
890 spin_unlock_irqrestore(&priv->lock, flags); 457 goto out;
891 return rc;
892 }
893 }
894 458
459out:
895 spin_unlock_irqrestore(&priv->lock, flags); 460 spin_unlock_irqrestore(&priv->lock, flags);
896 IWL_DEBUG_INFO("stop master\n"); 461 IWL_DEBUG_INFO("stop master\n");
897 462
898 return rc; 463 return ret;
899} 464}
900 465
901/** 466static void iwl4965_apm_stop(struct iwl_priv *priv)
902 * iwl4965_hw_txq_ctx_stop - Stop all Tx DMA channels, free Tx queue memory
903 */
904void iwl4965_hw_txq_ctx_stop(struct iwl_priv *priv)
905{ 467{
906
907 int txq_id;
908 unsigned long flags; 468 unsigned long flags;
909 469
910 /* Stop each Tx DMA channel, and wait for it to be idle */ 470 iwl4965_apm_stop_master(priv);
911 for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++) {
912 spin_lock_irqsave(&priv->lock, flags);
913 if (iwl_grab_nic_access(priv)) {
914 spin_unlock_irqrestore(&priv->lock, flags);
915 continue;
916 }
917 471
918 iwl_write_direct32(priv, 472 spin_lock_irqsave(&priv->lock, flags);
919 IWL_FH_TCSR_CHNL_TX_CONFIG_REG(txq_id), 0x0); 473
920 iwl_poll_direct_bit(priv, IWL_FH_TSSR_TX_STATUS_REG, 474 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
921 IWL_FH_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE
922 (txq_id), 200);
923 iwl_release_nic_access(priv);
924 spin_unlock_irqrestore(&priv->lock, flags);
925 }
926 475
927 /* Deallocate memory for all Tx queues */ 476 udelay(10);
928 iwl4965_hw_txq_ctx_free(priv); 477 /* clear "init complete" move adapter D0A* --> D0U state */
478 iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
479 spin_unlock_irqrestore(&priv->lock, flags);
929} 480}
930 481
931int iwl4965_hw_nic_reset(struct iwl_priv *priv) 482static int iwl4965_apm_reset(struct iwl_priv *priv)
932{ 483{
933 int rc = 0; 484 int ret = 0;
934 unsigned long flags; 485 unsigned long flags;
935 486
936 iwl4965_hw_nic_stop_master(priv); 487 iwl4965_apm_stop_master(priv);
937 488
938 spin_lock_irqsave(&priv->lock, flags); 489 spin_lock_irqsave(&priv->lock, flags);
939 490
@@ -941,509 +492,50 @@ int iwl4965_hw_nic_reset(struct iwl_priv *priv)
941 492
942 udelay(10); 493 udelay(10);
943 494
495 /* FIXME: put here L1A -L0S w/a */
496
944 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE); 497 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
945 rc = iwl_poll_bit(priv, CSR_RESET, 498
499 ret = iwl_poll_bit(priv, CSR_RESET,
946 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 500 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
947 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25); 501 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25);
948 502
503 if (ret)
504 goto out;
505
949 udelay(10); 506 udelay(10);
950 507
951 rc = iwl_grab_nic_access(priv); 508 ret = iwl_grab_nic_access(priv);
952 if (!rc) { 509 if (ret)
953 iwl_write_prph(priv, APMG_CLK_EN_REG, 510 goto out;
954 APMG_CLK_VAL_DMA_CLK_RQT | 511 /* Enable DMA and BSM Clock */
955 APMG_CLK_VAL_BSM_CLK_RQT); 512 iwl_write_prph(priv, APMG_CLK_EN_REG, APMG_CLK_VAL_DMA_CLK_RQT |
513 APMG_CLK_VAL_BSM_CLK_RQT);
956 514
957 udelay(10); 515 udelay(10);
958 516
959 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG, 517 /* disable L1A */
960 APMG_PCIDEV_STT_VAL_L1_ACT_DIS); 518 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
519 APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
961 520
962 iwl_release_nic_access(priv); 521 iwl_release_nic_access(priv);
963 }
964 522
965 clear_bit(STATUS_HCMD_ACTIVE, &priv->status); 523 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
966 wake_up_interruptible(&priv->wait_command_queue); 524 wake_up_interruptible(&priv->wait_command_queue);
967 525
526out:
968 spin_unlock_irqrestore(&priv->lock, flags); 527 spin_unlock_irqrestore(&priv->lock, flags);
969 528
970 return rc;
971
972}
973
974#define REG_RECALIB_PERIOD (60)
975
976/**
977 * iwl4965_bg_statistics_periodic - Timer callback to queue statistics
978 *
979 * This callback is provided in order to send a statistics request.
980 *
981 * This timer function is continually reset to execute within
982 * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
983 * was received. We need to ensure we receive the statistics in order
984 * to update the temperature used for calibrating the TXPOWER.
985 */
986static void iwl4965_bg_statistics_periodic(unsigned long data)
987{
988 struct iwl_priv *priv = (struct iwl_priv *)data;
989
990 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
991 return;
992
993 iwl_send_statistics_request(priv, CMD_ASYNC);
994}
995
996#define CT_LIMIT_CONST 259
997#define TM_CT_KILL_THRESHOLD 110
998
999void iwl4965_rf_kill_ct_config(struct iwl_priv *priv)
1000{
1001 struct iwl4965_ct_kill_config cmd;
1002 u32 R1, R2, R3;
1003 u32 temp_th;
1004 u32 crit_temperature;
1005 unsigned long flags;
1006 int ret = 0;
1007
1008 spin_lock_irqsave(&priv->lock, flags);
1009 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
1010 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
1011 spin_unlock_irqrestore(&priv->lock, flags);
1012
1013 if (priv->statistics.flag & STATISTICS_REPLY_FLG_FAT_MODE_MSK) {
1014 R1 = (s32)le32_to_cpu(priv->card_alive_init.therm_r1[1]);
1015 R2 = (s32)le32_to_cpu(priv->card_alive_init.therm_r2[1]);
1016 R3 = (s32)le32_to_cpu(priv->card_alive_init.therm_r3[1]);
1017 } else {
1018 R1 = (s32)le32_to_cpu(priv->card_alive_init.therm_r1[0]);
1019 R2 = (s32)le32_to_cpu(priv->card_alive_init.therm_r2[0]);
1020 R3 = (s32)le32_to_cpu(priv->card_alive_init.therm_r3[0]);
1021 }
1022
1023 temp_th = CELSIUS_TO_KELVIN(TM_CT_KILL_THRESHOLD);
1024
1025 crit_temperature = ((temp_th * (R3-R1))/CT_LIMIT_CONST) + R2;
1026 cmd.critical_temperature_R = cpu_to_le32(crit_temperature);
1027 ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
1028 sizeof(cmd), &cmd);
1029 if (ret)
1030 IWL_ERROR("REPLY_CT_KILL_CONFIG_CMD failed\n");
1031 else
1032 IWL_DEBUG_INFO("REPLY_CT_KILL_CONFIG_CMD succeeded\n");
1033}
1034
1035#ifdef CONFIG_IWL4965_SENSITIVITY
1036
1037/* "false alarms" are signals that our DSP tries to lock onto,
1038 * but then determines that they are either noise, or transmissions
1039 * from a distant wireless network (also "noise", really) that get
1040 * "stepped on" by stronger transmissions within our own network.
1041 * This algorithm attempts to set a sensitivity level that is high
1042 * enough to receive all of our own network traffic, but not so
1043 * high that our DSP gets too busy trying to lock onto non-network
1044 * activity/noise. */
1045static int iwl4965_sens_energy_cck(struct iwl_priv *priv,
1046 u32 norm_fa,
1047 u32 rx_enable_time,
1048 struct statistics_general_data *rx_info)
1049{
1050 u32 max_nrg_cck = 0;
1051 int i = 0;
1052 u8 max_silence_rssi = 0;
1053 u32 silence_ref = 0;
1054 u8 silence_rssi_a = 0;
1055 u8 silence_rssi_b = 0;
1056 u8 silence_rssi_c = 0;
1057 u32 val;
1058
1059 /* "false_alarms" values below are cross-multiplications to assess the
1060 * numbers of false alarms within the measured period of actual Rx
1061 * (Rx is off when we're txing), vs the min/max expected false alarms
1062 * (some should be expected if rx is sensitive enough) in a
1063 * hypothetical listening period of 200 time units (TU), 204.8 msec:
1064 *
1065 * MIN_FA/fixed-time < false_alarms/actual-rx-time < MAX_FA/beacon-time
1066 *
1067 * */
1068 u32 false_alarms = norm_fa * 200 * 1024;
1069 u32 max_false_alarms = MAX_FA_CCK * rx_enable_time;
1070 u32 min_false_alarms = MIN_FA_CCK * rx_enable_time;
1071 struct iwl4965_sensitivity_data *data = NULL;
1072
1073 data = &(priv->sensitivity_data);
1074
1075 data->nrg_auto_corr_silence_diff = 0;
1076
1077 /* Find max silence rssi among all 3 receivers.
1078 * This is background noise, which may include transmissions from other
1079 * networks, measured during silence before our network's beacon */
1080 silence_rssi_a = (u8)((rx_info->beacon_silence_rssi_a &
1081 ALL_BAND_FILTER) >> 8);
1082 silence_rssi_b = (u8)((rx_info->beacon_silence_rssi_b &
1083 ALL_BAND_FILTER) >> 8);
1084 silence_rssi_c = (u8)((rx_info->beacon_silence_rssi_c &
1085 ALL_BAND_FILTER) >> 8);
1086
1087 val = max(silence_rssi_b, silence_rssi_c);
1088 max_silence_rssi = max(silence_rssi_a, (u8) val);
1089
1090 /* Store silence rssi in 20-beacon history table */
1091 data->nrg_silence_rssi[data->nrg_silence_idx] = max_silence_rssi;
1092 data->nrg_silence_idx++;
1093 if (data->nrg_silence_idx >= NRG_NUM_PREV_STAT_L)
1094 data->nrg_silence_idx = 0;
1095
1096 /* Find max silence rssi across 20 beacon history */
1097 for (i = 0; i < NRG_NUM_PREV_STAT_L; i++) {
1098 val = data->nrg_silence_rssi[i];
1099 silence_ref = max(silence_ref, val);
1100 }
1101 IWL_DEBUG_CALIB("silence a %u, b %u, c %u, 20-bcn max %u\n",
1102 silence_rssi_a, silence_rssi_b, silence_rssi_c,
1103 silence_ref);
1104
1105 /* Find max rx energy (min value!) among all 3 receivers,
1106 * measured during beacon frame.
1107 * Save it in 10-beacon history table. */
1108 i = data->nrg_energy_idx;
1109 val = min(rx_info->beacon_energy_b, rx_info->beacon_energy_c);
1110 data->nrg_value[i] = min(rx_info->beacon_energy_a, val);
1111
1112 data->nrg_energy_idx++;
1113 if (data->nrg_energy_idx >= 10)
1114 data->nrg_energy_idx = 0;
1115
1116 /* Find min rx energy (max value) across 10 beacon history.
1117 * This is the minimum signal level that we want to receive well.
1118 * Add backoff (margin so we don't miss slightly lower energy frames).
1119 * This establishes an upper bound (min value) for energy threshold. */
1120 max_nrg_cck = data->nrg_value[0];
1121 for (i = 1; i < 10; i++)
1122 max_nrg_cck = (u32) max(max_nrg_cck, (data->nrg_value[i]));
1123 max_nrg_cck += 6;
1124
1125 IWL_DEBUG_CALIB("rx energy a %u, b %u, c %u, 10-bcn max/min %u\n",
1126 rx_info->beacon_energy_a, rx_info->beacon_energy_b,
1127 rx_info->beacon_energy_c, max_nrg_cck - 6);
1128
1129 /* Count number of consecutive beacons with fewer-than-desired
1130 * false alarms. */
1131 if (false_alarms < min_false_alarms)
1132 data->num_in_cck_no_fa++;
1133 else
1134 data->num_in_cck_no_fa = 0;
1135 IWL_DEBUG_CALIB("consecutive bcns with few false alarms = %u\n",
1136 data->num_in_cck_no_fa);
1137
1138 /* If we got too many false alarms this time, reduce sensitivity */
1139 if (false_alarms > max_false_alarms) {
1140 IWL_DEBUG_CALIB("norm FA %u > max FA %u\n",
1141 false_alarms, max_false_alarms);
1142 IWL_DEBUG_CALIB("... reducing sensitivity\n");
1143 data->nrg_curr_state = IWL_FA_TOO_MANY;
1144
1145 if (data->auto_corr_cck > AUTO_CORR_MAX_TH_CCK) {
1146 /* Store for "fewer than desired" on later beacon */
1147 data->nrg_silence_ref = silence_ref;
1148
1149 /* increase energy threshold (reduce nrg value)
1150 * to decrease sensitivity */
1151 if (data->nrg_th_cck > (NRG_MAX_CCK + NRG_STEP_CCK))
1152 data->nrg_th_cck = data->nrg_th_cck
1153 - NRG_STEP_CCK;
1154 }
1155
1156 /* increase auto_corr values to decrease sensitivity */
1157 if (data->auto_corr_cck < AUTO_CORR_MAX_TH_CCK)
1158 data->auto_corr_cck = AUTO_CORR_MAX_TH_CCK + 1;
1159 else {
1160 val = data->auto_corr_cck + AUTO_CORR_STEP_CCK;
1161 data->auto_corr_cck = min((u32)AUTO_CORR_MAX_CCK, val);
1162 }
1163 val = data->auto_corr_cck_mrc + AUTO_CORR_STEP_CCK;
1164 data->auto_corr_cck_mrc = min((u32)AUTO_CORR_MAX_CCK_MRC, val);
1165
1166 /* Else if we got fewer than desired, increase sensitivity */
1167 } else if (false_alarms < min_false_alarms) {
1168 data->nrg_curr_state = IWL_FA_TOO_FEW;
1169
1170 /* Compare silence level with silence level for most recent
1171 * healthy number or too many false alarms */
1172 data->nrg_auto_corr_silence_diff = (s32)data->nrg_silence_ref -
1173 (s32)silence_ref;
1174
1175 IWL_DEBUG_CALIB("norm FA %u < min FA %u, silence diff %d\n",
1176 false_alarms, min_false_alarms,
1177 data->nrg_auto_corr_silence_diff);
1178
1179 /* Increase value to increase sensitivity, but only if:
1180 * 1a) previous beacon did *not* have *too many* false alarms
1181 * 1b) AND there's a significant difference in Rx levels
1182 * from a previous beacon with too many, or healthy # FAs
1183 * OR 2) We've seen a lot of beacons (100) with too few
1184 * false alarms */
1185 if ((data->nrg_prev_state != IWL_FA_TOO_MANY) &&
1186 ((data->nrg_auto_corr_silence_diff > NRG_DIFF) ||
1187 (data->num_in_cck_no_fa > MAX_NUMBER_CCK_NO_FA))) {
1188
1189 IWL_DEBUG_CALIB("... increasing sensitivity\n");
1190 /* Increase nrg value to increase sensitivity */
1191 val = data->nrg_th_cck + NRG_STEP_CCK;
1192 data->nrg_th_cck = min((u32)NRG_MIN_CCK, val);
1193
1194 /* Decrease auto_corr values to increase sensitivity */
1195 val = data->auto_corr_cck - AUTO_CORR_STEP_CCK;
1196 data->auto_corr_cck = max((u32)AUTO_CORR_MIN_CCK, val);
1197
1198 val = data->auto_corr_cck_mrc - AUTO_CORR_STEP_CCK;
1199 data->auto_corr_cck_mrc =
1200 max((u32)AUTO_CORR_MIN_CCK_MRC, val);
1201
1202 } else
1203 IWL_DEBUG_CALIB("... but not changing sensitivity\n");
1204
1205 /* Else we got a healthy number of false alarms, keep status quo */
1206 } else {
1207 IWL_DEBUG_CALIB(" FA in safe zone\n");
1208 data->nrg_curr_state = IWL_FA_GOOD_RANGE;
1209
1210 /* Store for use in "fewer than desired" with later beacon */
1211 data->nrg_silence_ref = silence_ref;
1212
1213 /* If previous beacon had too many false alarms,
1214 * give it some extra margin by reducing sensitivity again
1215 * (but don't go below measured energy of desired Rx) */
1216 if (IWL_FA_TOO_MANY == data->nrg_prev_state) {
1217 IWL_DEBUG_CALIB("... increasing margin\n");
1218 data->nrg_th_cck -= NRG_MARGIN;
1219 }
1220 }
1221
1222 /* Make sure the energy threshold does not go above the measured
1223 * energy of the desired Rx signals (reduced by backoff margin),
1224 * or else we might start missing Rx frames.
1225 * Lower value is higher energy, so we use max()!
1226 */
1227 data->nrg_th_cck = max(max_nrg_cck, data->nrg_th_cck);
1228 IWL_DEBUG_CALIB("new nrg_th_cck %u\n", data->nrg_th_cck);
1229
1230 data->nrg_prev_state = data->nrg_curr_state;
1231
1232 return 0;
1233}
1234
1235
1236static int iwl4965_sens_auto_corr_ofdm(struct iwl_priv *priv,
1237 u32 norm_fa,
1238 u32 rx_enable_time)
1239{
1240 u32 val;
1241 u32 false_alarms = norm_fa * 200 * 1024;
1242 u32 max_false_alarms = MAX_FA_OFDM * rx_enable_time;
1243 u32 min_false_alarms = MIN_FA_OFDM * rx_enable_time;
1244 struct iwl4965_sensitivity_data *data = NULL;
1245
1246 data = &(priv->sensitivity_data);
1247
1248 /* If we got too many false alarms this time, reduce sensitivity */
1249 if (false_alarms > max_false_alarms) {
1250
1251 IWL_DEBUG_CALIB("norm FA %u > max FA %u)\n",
1252 false_alarms, max_false_alarms);
1253
1254 val = data->auto_corr_ofdm + AUTO_CORR_STEP_OFDM;
1255 data->auto_corr_ofdm =
1256 min((u32)AUTO_CORR_MAX_OFDM, val);
1257
1258 val = data->auto_corr_ofdm_mrc + AUTO_CORR_STEP_OFDM;
1259 data->auto_corr_ofdm_mrc =
1260 min((u32)AUTO_CORR_MAX_OFDM_MRC, val);
1261
1262 val = data->auto_corr_ofdm_x1 + AUTO_CORR_STEP_OFDM;
1263 data->auto_corr_ofdm_x1 =
1264 min((u32)AUTO_CORR_MAX_OFDM_X1, val);
1265
1266 val = data->auto_corr_ofdm_mrc_x1 + AUTO_CORR_STEP_OFDM;
1267 data->auto_corr_ofdm_mrc_x1 =
1268 min((u32)AUTO_CORR_MAX_OFDM_MRC_X1, val);
1269 }
1270
1271 /* Else if we got fewer than desired, increase sensitivity */
1272 else if (false_alarms < min_false_alarms) {
1273
1274 IWL_DEBUG_CALIB("norm FA %u < min FA %u\n",
1275 false_alarms, min_false_alarms);
1276
1277 val = data->auto_corr_ofdm - AUTO_CORR_STEP_OFDM;
1278 data->auto_corr_ofdm =
1279 max((u32)AUTO_CORR_MIN_OFDM, val);
1280
1281 val = data->auto_corr_ofdm_mrc - AUTO_CORR_STEP_OFDM;
1282 data->auto_corr_ofdm_mrc =
1283 max((u32)AUTO_CORR_MIN_OFDM_MRC, val);
1284
1285 val = data->auto_corr_ofdm_x1 - AUTO_CORR_STEP_OFDM;
1286 data->auto_corr_ofdm_x1 =
1287 max((u32)AUTO_CORR_MIN_OFDM_X1, val);
1288
1289 val = data->auto_corr_ofdm_mrc_x1 - AUTO_CORR_STEP_OFDM;
1290 data->auto_corr_ofdm_mrc_x1 =
1291 max((u32)AUTO_CORR_MIN_OFDM_MRC_X1, val);
1292 }
1293
1294 else
1295 IWL_DEBUG_CALIB("min FA %u < norm FA %u < max FA %u OK\n",
1296 min_false_alarms, false_alarms, max_false_alarms);
1297
1298 return 0;
1299}
1300
1301static int iwl4965_sensitivity_callback(struct iwl_priv *priv,
1302 struct iwl_cmd *cmd, struct sk_buff *skb)
1303{
1304 /* We didn't cache the SKB; let the caller free it */
1305 return 1;
1306}
1307
1308/* Prepare a SENSITIVITY_CMD, send to uCode if values have changed */
1309static int iwl4965_sensitivity_write(struct iwl_priv *priv, u8 flags)
1310{
1311 struct iwl4965_sensitivity_cmd cmd ;
1312 struct iwl4965_sensitivity_data *data = NULL;
1313 struct iwl_host_cmd cmd_out = {
1314 .id = SENSITIVITY_CMD,
1315 .len = sizeof(struct iwl4965_sensitivity_cmd),
1316 .meta.flags = flags,
1317 .data = &cmd,
1318 };
1319 int ret;
1320
1321 data = &(priv->sensitivity_data);
1322
1323 memset(&cmd, 0, sizeof(cmd));
1324
1325 cmd.table[HD_AUTO_CORR32_X4_TH_ADD_MIN_INDEX] =
1326 cpu_to_le16((u16)data->auto_corr_ofdm);
1327 cmd.table[HD_AUTO_CORR32_X4_TH_ADD_MIN_MRC_INDEX] =
1328 cpu_to_le16((u16)data->auto_corr_ofdm_mrc);
1329 cmd.table[HD_AUTO_CORR32_X1_TH_ADD_MIN_INDEX] =
1330 cpu_to_le16((u16)data->auto_corr_ofdm_x1);
1331 cmd.table[HD_AUTO_CORR32_X1_TH_ADD_MIN_MRC_INDEX] =
1332 cpu_to_le16((u16)data->auto_corr_ofdm_mrc_x1);
1333
1334 cmd.table[HD_AUTO_CORR40_X4_TH_ADD_MIN_INDEX] =
1335 cpu_to_le16((u16)data->auto_corr_cck);
1336 cmd.table[HD_AUTO_CORR40_X4_TH_ADD_MIN_MRC_INDEX] =
1337 cpu_to_le16((u16)data->auto_corr_cck_mrc);
1338
1339 cmd.table[HD_MIN_ENERGY_CCK_DET_INDEX] =
1340 cpu_to_le16((u16)data->nrg_th_cck);
1341 cmd.table[HD_MIN_ENERGY_OFDM_DET_INDEX] =
1342 cpu_to_le16((u16)data->nrg_th_ofdm);
1343
1344 cmd.table[HD_BARKER_CORR_TH_ADD_MIN_INDEX] =
1345 __constant_cpu_to_le16(190);
1346 cmd.table[HD_BARKER_CORR_TH_ADD_MIN_MRC_INDEX] =
1347 __constant_cpu_to_le16(390);
1348 cmd.table[HD_OFDM_ENERGY_TH_IN_INDEX] =
1349 __constant_cpu_to_le16(62);
1350
1351 IWL_DEBUG_CALIB("ofdm: ac %u mrc %u x1 %u mrc_x1 %u thresh %u\n",
1352 data->auto_corr_ofdm, data->auto_corr_ofdm_mrc,
1353 data->auto_corr_ofdm_x1, data->auto_corr_ofdm_mrc_x1,
1354 data->nrg_th_ofdm);
1355
1356 IWL_DEBUG_CALIB("cck: ac %u mrc %u thresh %u\n",
1357 data->auto_corr_cck, data->auto_corr_cck_mrc,
1358 data->nrg_th_cck);
1359
1360 /* Update uCode's "work" table, and copy it to DSP */
1361 cmd.control = SENSITIVITY_CMD_CONTROL_WORK_TABLE;
1362
1363 if (flags & CMD_ASYNC)
1364 cmd_out.meta.u.callback = iwl4965_sensitivity_callback;
1365
1366 /* Don't send command to uCode if nothing has changed */
1367 if (!memcmp(&cmd.table[0], &(priv->sensitivity_tbl[0]),
1368 sizeof(u16)*HD_TABLE_SIZE)) {
1369 IWL_DEBUG_CALIB("No change in SENSITIVITY_CMD\n");
1370 return 0;
1371 }
1372
1373 /* Copy table for comparison next time */
1374 memcpy(&(priv->sensitivity_tbl[0]), &(cmd.table[0]),
1375 sizeof(u16)*HD_TABLE_SIZE);
1376
1377 ret = iwl_send_cmd(priv, &cmd_out);
1378 if (ret)
1379 IWL_ERROR("SENSITIVITY_CMD failed\n");
1380
1381 return ret; 529 return ret;
1382} 530}
1383 531
1384void iwl4965_init_sensitivity(struct iwl_priv *priv, u8 flags, u8 force)
1385{
1386 struct iwl4965_sensitivity_data *data = NULL;
1387 int i;
1388 int ret = 0;
1389
1390 IWL_DEBUG_CALIB("Start iwl4965_init_sensitivity\n");
1391
1392 if (force)
1393 memset(&(priv->sensitivity_tbl[0]), 0,
1394 sizeof(u16)*HD_TABLE_SIZE);
1395
1396 /* Clear driver's sensitivity algo data */
1397 data = &(priv->sensitivity_data);
1398 memset(data, 0, sizeof(struct iwl4965_sensitivity_data));
1399
1400 data->num_in_cck_no_fa = 0;
1401 data->nrg_curr_state = IWL_FA_TOO_MANY;
1402 data->nrg_prev_state = IWL_FA_TOO_MANY;
1403 data->nrg_silence_ref = 0;
1404 data->nrg_silence_idx = 0;
1405 data->nrg_energy_idx = 0;
1406
1407 for (i = 0; i < 10; i++)
1408 data->nrg_value[i] = 0;
1409
1410 for (i = 0; i < NRG_NUM_PREV_STAT_L; i++)
1411 data->nrg_silence_rssi[i] = 0;
1412
1413 data->auto_corr_ofdm = 90;
1414 data->auto_corr_ofdm_mrc = 170;
1415 data->auto_corr_ofdm_x1 = 105;
1416 data->auto_corr_ofdm_mrc_x1 = 220;
1417 data->auto_corr_cck = AUTO_CORR_CCK_MIN_VAL_DEF;
1418 data->auto_corr_cck_mrc = 200;
1419 data->nrg_th_cck = 100;
1420 data->nrg_th_ofdm = 100;
1421
1422 data->last_bad_plcp_cnt_ofdm = 0;
1423 data->last_fa_cnt_ofdm = 0;
1424 data->last_bad_plcp_cnt_cck = 0;
1425 data->last_fa_cnt_cck = 0;
1426
1427 /* Clear prior Sensitivity command data to force send to uCode */
1428 if (force)
1429 memset(&(priv->sensitivity_tbl[0]), 0,
1430 sizeof(u16)*HD_TABLE_SIZE);
1431
1432 ret |= iwl4965_sensitivity_write(priv, flags);
1433 IWL_DEBUG_CALIB("<<return 0x%X\n", ret);
1434
1435 return;
1436}
1437
1438
1439/* Reset differential Rx gains in NIC to prepare for chain noise calibration. 532/* Reset differential Rx gains in NIC to prepare for chain noise calibration.
1440 * Called after every association, but this runs only once! 533 * Called after every association, but this runs only once!
1441 * ... once chain noise is calibrated the first time, it's good forever. */ 534 * ... once chain noise is calibrated the first time, it's good forever. */
1442void iwl4965_chain_noise_reset(struct iwl_priv *priv) 535static void iwl4965_chain_noise_reset(struct iwl_priv *priv)
1443{ 536{
1444 struct iwl4965_chain_noise_data *data = NULL; 537 struct iwl_chain_noise_data *data = &(priv->chain_noise_data);
1445 538
1446 data = &(priv->chain_noise_data);
1447 if ((data->state == IWL_CHAIN_NOISE_ALIVE) && iwl_is_associated(priv)) { 539 if ((data->state == IWL_CHAIN_NOISE_ALIVE) && iwl_is_associated(priv)) {
1448 struct iwl4965_calibration_cmd cmd; 540 struct iwl4965_calibration_cmd cmd;
1449 541
@@ -1452,388 +544,89 @@ void iwl4965_chain_noise_reset(struct iwl_priv *priv)
1452 cmd.diff_gain_a = 0; 544 cmd.diff_gain_a = 0;
1453 cmd.diff_gain_b = 0; 545 cmd.diff_gain_b = 0;
1454 cmd.diff_gain_c = 0; 546 cmd.diff_gain_c = 0;
1455 iwl_send_cmd_pdu_async(priv, REPLY_PHY_CALIBRATION_CMD, 547 if (iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
1456 sizeof(cmd), &cmd, NULL); 548 sizeof(cmd), &cmd))
1457 msleep(4); 549 IWL_ERROR("Could not send REPLY_PHY_CALIBRATION_CMD\n");
1458 data->state = IWL_CHAIN_NOISE_ACCUMULATE; 550 data->state = IWL_CHAIN_NOISE_ACCUMULATE;
1459 IWL_DEBUG_CALIB("Run chain_noise_calibrate\n"); 551 IWL_DEBUG_CALIB("Run chain_noise_calibrate\n");
1460 } 552 }
1461 return;
1462} 553}
1463 554
1464/* 555static void iwl4965_gain_computation(struct iwl_priv *priv,
1465 * Accumulate 20 beacons of signal and noise statistics for each of 556 u32 *average_noise,
1466 * 3 receivers/antennas/rx-chains, then figure out: 557 u16 min_average_noise_antenna_i,
1467 * 1) Which antennas are connected. 558 u32 min_average_noise)
1468 * 2) Differential rx gain settings to balance the 3 receivers.
1469 */
1470static void iwl4965_noise_calibration(struct iwl_priv *priv,
1471 struct iwl4965_notif_statistics *stat_resp)
1472{ 559{
1473 struct iwl4965_chain_noise_data *data = NULL; 560 int i, ret;
1474 int ret = 0; 561 struct iwl_chain_noise_data *data = &priv->chain_noise_data;
1475 562
1476 u32 chain_noise_a; 563 data->delta_gain_code[min_average_noise_antenna_i] = 0;
1477 u32 chain_noise_b;
1478 u32 chain_noise_c;
1479 u32 chain_sig_a;
1480 u32 chain_sig_b;
1481 u32 chain_sig_c;
1482 u32 average_sig[NUM_RX_CHAINS] = {INITIALIZATION_VALUE};
1483 u32 average_noise[NUM_RX_CHAINS] = {INITIALIZATION_VALUE};
1484 u32 max_average_sig;
1485 u16 max_average_sig_antenna_i;
1486 u32 min_average_noise = MIN_AVERAGE_NOISE_MAX_VALUE;
1487 u16 min_average_noise_antenna_i = INITIALIZATION_VALUE;
1488 u16 i = 0;
1489 u16 chan_num = INITIALIZATION_VALUE;
1490 u32 band = INITIALIZATION_VALUE;
1491 u32 active_chains = 0;
1492 unsigned long flags;
1493 struct statistics_rx_non_phy *rx_info = &(stat_resp->rx.general);
1494
1495 data = &(priv->chain_noise_data);
1496
1497 /* Accumulate just the first 20 beacons after the first association,
1498 * then we're done forever. */
1499 if (data->state != IWL_CHAIN_NOISE_ACCUMULATE) {
1500 if (data->state == IWL_CHAIN_NOISE_ALIVE)
1501 IWL_DEBUG_CALIB("Wait for noise calib reset\n");
1502 return;
1503 }
1504
1505 spin_lock_irqsave(&priv->lock, flags);
1506 if (rx_info->interference_data_flag != INTERFERENCE_DATA_AVAILABLE) {
1507 IWL_DEBUG_CALIB(" << Interference data unavailable\n");
1508 spin_unlock_irqrestore(&priv->lock, flags);
1509 return;
1510 }
1511
1512 band = (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) ? 0 : 1;
1513 chan_num = le16_to_cpu(priv->staging_rxon.channel);
1514
1515 /* Make sure we accumulate data for just the associated channel
1516 * (even if scanning). */
1517 if ((chan_num != (le32_to_cpu(stat_resp->flag) >> 16)) ||
1518 ((STATISTICS_REPLY_FLG_BAND_24G_MSK ==
1519 (stat_resp->flag & STATISTICS_REPLY_FLG_BAND_24G_MSK)) && band)) {
1520 IWL_DEBUG_CALIB("Stats not from chan=%d, band=%d\n",
1521 chan_num, band);
1522 spin_unlock_irqrestore(&priv->lock, flags);
1523 return;
1524 }
1525
1526 /* Accumulate beacon statistics values across 20 beacons */
1527 chain_noise_a = le32_to_cpu(rx_info->beacon_silence_rssi_a) &
1528 IN_BAND_FILTER;
1529 chain_noise_b = le32_to_cpu(rx_info->beacon_silence_rssi_b) &
1530 IN_BAND_FILTER;
1531 chain_noise_c = le32_to_cpu(rx_info->beacon_silence_rssi_c) &
1532 IN_BAND_FILTER;
1533
1534 chain_sig_a = le32_to_cpu(rx_info->beacon_rssi_a) & IN_BAND_FILTER;
1535 chain_sig_b = le32_to_cpu(rx_info->beacon_rssi_b) & IN_BAND_FILTER;
1536 chain_sig_c = le32_to_cpu(rx_info->beacon_rssi_c) & IN_BAND_FILTER;
1537 564
1538 spin_unlock_irqrestore(&priv->lock, flags); 565 for (i = 0; i < NUM_RX_CHAINS; i++) {
566 s32 delta_g = 0;
1539 567
1540 data->beacon_count++; 568 if (!(data->disconn_array[i]) &&
1541 569 (data->delta_gain_code[i] ==
1542 data->chain_noise_a = (chain_noise_a + data->chain_noise_a);
1543 data->chain_noise_b = (chain_noise_b + data->chain_noise_b);
1544 data->chain_noise_c = (chain_noise_c + data->chain_noise_c);
1545
1546 data->chain_signal_a = (chain_sig_a + data->chain_signal_a);
1547 data->chain_signal_b = (chain_sig_b + data->chain_signal_b);
1548 data->chain_signal_c = (chain_sig_c + data->chain_signal_c);
1549
1550 IWL_DEBUG_CALIB("chan=%d, band=%d, beacon=%d\n", chan_num, band,
1551 data->beacon_count);
1552 IWL_DEBUG_CALIB("chain_sig: a %d b %d c %d\n",
1553 chain_sig_a, chain_sig_b, chain_sig_c);
1554 IWL_DEBUG_CALIB("chain_noise: a %d b %d c %d\n",
1555 chain_noise_a, chain_noise_b, chain_noise_c);
1556
1557 /* If this is the 20th beacon, determine:
1558 * 1) Disconnected antennas (using signal strengths)
1559 * 2) Differential gain (using silence noise) to balance receivers */
1560 if (data->beacon_count == CAL_NUM_OF_BEACONS) {
1561
1562 /* Analyze signal for disconnected antenna */
1563 average_sig[0] = (data->chain_signal_a) / CAL_NUM_OF_BEACONS;
1564 average_sig[1] = (data->chain_signal_b) / CAL_NUM_OF_BEACONS;
1565 average_sig[2] = (data->chain_signal_c) / CAL_NUM_OF_BEACONS;
1566
1567 if (average_sig[0] >= average_sig[1]) {
1568 max_average_sig = average_sig[0];
1569 max_average_sig_antenna_i = 0;
1570 active_chains = (1 << max_average_sig_antenna_i);
1571 } else {
1572 max_average_sig = average_sig[1];
1573 max_average_sig_antenna_i = 1;
1574 active_chains = (1 << max_average_sig_antenna_i);
1575 }
1576
1577 if (average_sig[2] >= max_average_sig) {
1578 max_average_sig = average_sig[2];
1579 max_average_sig_antenna_i = 2;
1580 active_chains = (1 << max_average_sig_antenna_i);
1581 }
1582
1583 IWL_DEBUG_CALIB("average_sig: a %d b %d c %d\n",
1584 average_sig[0], average_sig[1], average_sig[2]);
1585 IWL_DEBUG_CALIB("max_average_sig = %d, antenna %d\n",
1586 max_average_sig, max_average_sig_antenna_i);
1587
1588 /* Compare signal strengths for all 3 receivers. */
1589 for (i = 0; i < NUM_RX_CHAINS; i++) {
1590 if (i != max_average_sig_antenna_i) {
1591 s32 rssi_delta = (max_average_sig -
1592 average_sig[i]);
1593
1594 /* If signal is very weak, compared with
1595 * strongest, mark it as disconnected. */
1596 if (rssi_delta > MAXIMUM_ALLOWED_PATHLOSS)
1597 data->disconn_array[i] = 1;
1598 else
1599 active_chains |= (1 << i);
1600 IWL_DEBUG_CALIB("i = %d rssiDelta = %d "
1601 "disconn_array[i] = %d\n",
1602 i, rssi_delta, data->disconn_array[i]);
1603 }
1604 }
1605
1606 /*If both chains A & B are disconnected -
1607 * connect B and leave A as is */
1608 if (data->disconn_array[CHAIN_A] &&
1609 data->disconn_array[CHAIN_B]) {
1610 data->disconn_array[CHAIN_B] = 0;
1611 active_chains |= (1 << CHAIN_B);
1612 IWL_DEBUG_CALIB("both A & B chains are disconnected! "
1613 "W/A - declare B as connected\n");
1614 }
1615
1616 IWL_DEBUG_CALIB("active_chains (bitwise) = 0x%x\n",
1617 active_chains);
1618
1619 /* Save for use within RXON, TX, SCAN commands, etc. */
1620 priv->valid_antenna = active_chains;
1621
1622 /* Analyze noise for rx balance */
1623 average_noise[0] = ((data->chain_noise_a)/CAL_NUM_OF_BEACONS);
1624 average_noise[1] = ((data->chain_noise_b)/CAL_NUM_OF_BEACONS);
1625 average_noise[2] = ((data->chain_noise_c)/CAL_NUM_OF_BEACONS);
1626
1627 for (i = 0; i < NUM_RX_CHAINS; i++) {
1628 if (!(data->disconn_array[i]) &&
1629 (average_noise[i] <= min_average_noise)) {
1630 /* This means that chain i is active and has
1631 * lower noise values so far: */
1632 min_average_noise = average_noise[i];
1633 min_average_noise_antenna_i = i;
1634 }
1635 }
1636
1637 data->delta_gain_code[min_average_noise_antenna_i] = 0;
1638
1639 IWL_DEBUG_CALIB("average_noise: a %d b %d c %d\n",
1640 average_noise[0], average_noise[1],
1641 average_noise[2]);
1642
1643 IWL_DEBUG_CALIB("min_average_noise = %d, antenna %d\n",
1644 min_average_noise, min_average_noise_antenna_i);
1645
1646 for (i = 0; i < NUM_RX_CHAINS; i++) {
1647 s32 delta_g = 0;
1648
1649 if (!(data->disconn_array[i]) &&
1650 (data->delta_gain_code[i] ==
1651 CHAIN_NOISE_DELTA_GAIN_INIT_VAL)) { 570 CHAIN_NOISE_DELTA_GAIN_INIT_VAL)) {
1652 delta_g = average_noise[i] - min_average_noise; 571 delta_g = average_noise[i] - min_average_noise;
1653 data->delta_gain_code[i] = (u8)((delta_g * 572 data->delta_gain_code[i] = (u8)((delta_g * 10) / 15);
1654 10) / 15); 573 data->delta_gain_code[i] =
1655 if (CHAIN_NOISE_MAX_DELTA_GAIN_CODE < 574 min(data->delta_gain_code[i],
1656 data->delta_gain_code[i]) 575 (u8) CHAIN_NOISE_MAX_DELTA_GAIN_CODE);
1657 data->delta_gain_code[i] = 576
1658 CHAIN_NOISE_MAX_DELTA_GAIN_CODE; 577 data->delta_gain_code[i] =
1659 578 (data->delta_gain_code[i] | (1 << 2));
1660 data->delta_gain_code[i] = 579 } else {
1661 (data->delta_gain_code[i] | (1 << 2)); 580 data->delta_gain_code[i] = 0;
1662 } else
1663 data->delta_gain_code[i] = 0;
1664 }
1665 IWL_DEBUG_CALIB("delta_gain_codes: a %d b %d c %d\n",
1666 data->delta_gain_code[0],
1667 data->delta_gain_code[1],
1668 data->delta_gain_code[2]);
1669
1670 /* Differential gain gets sent to uCode only once */
1671 if (!data->radio_write) {
1672 struct iwl4965_calibration_cmd cmd;
1673 data->radio_write = 1;
1674
1675 memset(&cmd, 0, sizeof(cmd));
1676 cmd.opCode = PHY_CALIBRATE_DIFF_GAIN_CMD;
1677 cmd.diff_gain_a = data->delta_gain_code[0];
1678 cmd.diff_gain_b = data->delta_gain_code[1];
1679 cmd.diff_gain_c = data->delta_gain_code[2];
1680 ret = iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
1681 sizeof(cmd), &cmd);
1682 if (ret)
1683 IWL_DEBUG_CALIB("fail sending cmd "
1684 "REPLY_PHY_CALIBRATION_CMD \n");
1685
1686 /* TODO we might want recalculate
1687 * rx_chain in rxon cmd */
1688
1689 /* Mark so we run this algo only once! */
1690 data->state = IWL_CHAIN_NOISE_CALIBRATED;
1691 } 581 }
1692 data->chain_noise_a = 0;
1693 data->chain_noise_b = 0;
1694 data->chain_noise_c = 0;
1695 data->chain_signal_a = 0;
1696 data->chain_signal_b = 0;
1697 data->chain_signal_c = 0;
1698 data->beacon_count = 0;
1699 }
1700 return;
1701}
1702
1703static void iwl4965_sensitivity_calibration(struct iwl_priv *priv,
1704 struct iwl4965_notif_statistics *resp)
1705{
1706 u32 rx_enable_time;
1707 u32 fa_cck;
1708 u32 fa_ofdm;
1709 u32 bad_plcp_cck;
1710 u32 bad_plcp_ofdm;
1711 u32 norm_fa_ofdm;
1712 u32 norm_fa_cck;
1713 struct iwl4965_sensitivity_data *data = NULL;
1714 struct statistics_rx_non_phy *rx_info = &(resp->rx.general);
1715 struct statistics_rx *statistics = &(resp->rx);
1716 unsigned long flags;
1717 struct statistics_general_data statis;
1718 int ret;
1719
1720 data = &(priv->sensitivity_data);
1721
1722 if (!iwl_is_associated(priv)) {
1723 IWL_DEBUG_CALIB("<< - not associated\n");
1724 return;
1725 } 582 }
583 IWL_DEBUG_CALIB("delta_gain_codes: a %d b %d c %d\n",
584 data->delta_gain_code[0],
585 data->delta_gain_code[1],
586 data->delta_gain_code[2]);
1726 587
1727 spin_lock_irqsave(&priv->lock, flags); 588 /* Differential gain gets sent to uCode only once */
1728 if (rx_info->interference_data_flag != INTERFERENCE_DATA_AVAILABLE) { 589 if (!data->radio_write) {
1729 IWL_DEBUG_CALIB("<< invalid data.\n"); 590 struct iwl4965_calibration_cmd cmd;
1730 spin_unlock_irqrestore(&priv->lock, flags); 591 data->radio_write = 1;
1731 return;
1732 }
1733
1734 /* Extract Statistics: */
1735 rx_enable_time = le32_to_cpu(rx_info->channel_load);
1736 fa_cck = le32_to_cpu(statistics->cck.false_alarm_cnt);
1737 fa_ofdm = le32_to_cpu(statistics->ofdm.false_alarm_cnt);
1738 bad_plcp_cck = le32_to_cpu(statistics->cck.plcp_err);
1739 bad_plcp_ofdm = le32_to_cpu(statistics->ofdm.plcp_err);
1740
1741 statis.beacon_silence_rssi_a =
1742 le32_to_cpu(statistics->general.beacon_silence_rssi_a);
1743 statis.beacon_silence_rssi_b =
1744 le32_to_cpu(statistics->general.beacon_silence_rssi_b);
1745 statis.beacon_silence_rssi_c =
1746 le32_to_cpu(statistics->general.beacon_silence_rssi_c);
1747 statis.beacon_energy_a =
1748 le32_to_cpu(statistics->general.beacon_energy_a);
1749 statis.beacon_energy_b =
1750 le32_to_cpu(statistics->general.beacon_energy_b);
1751 statis.beacon_energy_c =
1752 le32_to_cpu(statistics->general.beacon_energy_c);
1753
1754 spin_unlock_irqrestore(&priv->lock, flags);
1755
1756 IWL_DEBUG_CALIB("rx_enable_time = %u usecs\n", rx_enable_time);
1757
1758 if (!rx_enable_time) {
1759 IWL_DEBUG_CALIB("<< RX Enable Time == 0! \n");
1760 return;
1761 }
1762
1763 /* These statistics increase monotonically, and do not reset
1764 * at each beacon. Calculate difference from last value, or just
1765 * use the new statistics value if it has reset or wrapped around. */
1766 if (data->last_bad_plcp_cnt_cck > bad_plcp_cck)
1767 data->last_bad_plcp_cnt_cck = bad_plcp_cck;
1768 else {
1769 bad_plcp_cck -= data->last_bad_plcp_cnt_cck;
1770 data->last_bad_plcp_cnt_cck += bad_plcp_cck;
1771 }
1772 592
1773 if (data->last_bad_plcp_cnt_ofdm > bad_plcp_ofdm) 593 memset(&cmd, 0, sizeof(cmd));
1774 data->last_bad_plcp_cnt_ofdm = bad_plcp_ofdm; 594 cmd.opCode = PHY_CALIBRATE_DIFF_GAIN_CMD;
1775 else { 595 cmd.diff_gain_a = data->delta_gain_code[0];
1776 bad_plcp_ofdm -= data->last_bad_plcp_cnt_ofdm; 596 cmd.diff_gain_b = data->delta_gain_code[1];
1777 data->last_bad_plcp_cnt_ofdm += bad_plcp_ofdm; 597 cmd.diff_gain_c = data->delta_gain_code[2];
1778 } 598 ret = iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
599 sizeof(cmd), &cmd);
600 if (ret)
601 IWL_DEBUG_CALIB("fail sending cmd "
602 "REPLY_PHY_CALIBRATION_CMD \n");
1779 603
1780 if (data->last_fa_cnt_ofdm > fa_ofdm) 604 /* TODO we might want recalculate
1781 data->last_fa_cnt_ofdm = fa_ofdm; 605 * rx_chain in rxon cmd */
1782 else {
1783 fa_ofdm -= data->last_fa_cnt_ofdm;
1784 data->last_fa_cnt_ofdm += fa_ofdm;
1785 }
1786 606
1787 if (data->last_fa_cnt_cck > fa_cck) 607 /* Mark so we run this algo only once! */
1788 data->last_fa_cnt_cck = fa_cck; 608 data->state = IWL_CHAIN_NOISE_CALIBRATED;
1789 else {
1790 fa_cck -= data->last_fa_cnt_cck;
1791 data->last_fa_cnt_cck += fa_cck;
1792 } 609 }
1793 610 data->chain_noise_a = 0;
1794 /* Total aborted signal locks */ 611 data->chain_noise_b = 0;
1795 norm_fa_ofdm = fa_ofdm + bad_plcp_ofdm; 612 data->chain_noise_c = 0;
1796 norm_fa_cck = fa_cck + bad_plcp_cck; 613 data->chain_signal_a = 0;
1797 614 data->chain_signal_b = 0;
1798 IWL_DEBUG_CALIB("cck: fa %u badp %u ofdm: fa %u badp %u\n", fa_cck, 615 data->chain_signal_c = 0;
1799 bad_plcp_cck, fa_ofdm, bad_plcp_ofdm); 616 data->beacon_count = 0;
1800
1801 iwl4965_sens_auto_corr_ofdm(priv, norm_fa_ofdm, rx_enable_time);
1802 iwl4965_sens_energy_cck(priv, norm_fa_cck, rx_enable_time, &statis);
1803 ret = iwl4965_sensitivity_write(priv, CMD_ASYNC);
1804
1805 return;
1806} 617}
1807 618
1808static void iwl4965_bg_sensitivity_work(struct work_struct *work) 619static void iwl4965_rts_tx_cmd_flag(struct ieee80211_tx_info *info,
620 __le32 *tx_flags)
1809{ 621{
1810 struct iwl_priv *priv = container_of(work, struct iwl_priv, 622 if (info->flags & IEEE80211_TX_CTL_USE_RTS_CTS) {
1811 sensitivity_work); 623 *tx_flags |= TX_CMD_FLG_RTS_MSK;
1812 624 *tx_flags &= ~TX_CMD_FLG_CTS_MSK;
1813 mutex_lock(&priv->mutex); 625 } else if (info->flags & IEEE80211_TX_CTL_USE_CTS_PROTECT) {
1814 626 *tx_flags &= ~TX_CMD_FLG_RTS_MSK;
1815 if (test_bit(STATUS_EXIT_PENDING, &priv->status) || 627 *tx_flags |= TX_CMD_FLG_CTS_MSK;
1816 test_bit(STATUS_SCANNING, &priv->status)) {
1817 mutex_unlock(&priv->mutex);
1818 return;
1819 } 628 }
1820
1821 if (priv->start_calib) {
1822 iwl4965_noise_calibration(priv, &priv->statistics);
1823
1824 if (priv->sensitivity_data.state ==
1825 IWL_SENS_CALIB_NEED_REINIT) {
1826 iwl4965_init_sensitivity(priv, CMD_ASYNC, 0);
1827 priv->sensitivity_data.state = IWL_SENS_CALIB_ALLOWED;
1828 } else
1829 iwl4965_sensitivity_calibration(priv,
1830 &priv->statistics);
1831 }
1832
1833 mutex_unlock(&priv->mutex);
1834 return;
1835} 629}
1836#endif /*CONFIG_IWL4965_SENSITIVITY*/
1837 630
1838static void iwl4965_bg_txpower_work(struct work_struct *work) 631static void iwl4965_bg_txpower_work(struct work_struct *work)
1839{ 632{
@@ -1853,7 +646,7 @@ static void iwl4965_bg_txpower_work(struct work_struct *work)
1853 /* Regardless of if we are assocaited, we must reconfigure the 646 /* Regardless of if we are assocaited, we must reconfigure the
1854 * TX power since frames can be sent on non-radar channels while 647 * TX power since frames can be sent on non-radar channels while
1855 * not associated */ 648 * not associated */
1856 iwl4965_hw_reg_send_txpower(priv); 649 iwl4965_send_tx_power(priv);
1857 650
1858 /* Update last_temperature to keep is_calib_needed from running 651 /* Update last_temperature to keep is_calib_needed from running
1859 * when it isn't needed... */ 652 * when it isn't needed... */
@@ -1880,7 +673,7 @@ static void iwl4965_set_wr_ptrs(struct iwl_priv *priv, int txq_id, u32 index)
1880 * NOTE: Acquire priv->lock before calling this function ! 673 * NOTE: Acquire priv->lock before calling this function !
1881 */ 674 */
1882static void iwl4965_tx_queue_set_status(struct iwl_priv *priv, 675static void iwl4965_tx_queue_set_status(struct iwl_priv *priv,
1883 struct iwl4965_tx_queue *txq, 676 struct iwl_tx_queue *txq,
1884 int tx_fifo_id, int scd_retry) 677 int tx_fifo_id, int scd_retry)
1885{ 678{
1886 int txq_id = txq->q.id; 679 int txq_id = txq->q.id;
@@ -1890,11 +683,11 @@ static void iwl4965_tx_queue_set_status(struct iwl_priv *priv,
1890 683
1891 /* Set up and activate */ 684 /* Set up and activate */
1892 iwl_write_prph(priv, IWL49_SCD_QUEUE_STATUS_BITS(txq_id), 685 iwl_write_prph(priv, IWL49_SCD_QUEUE_STATUS_BITS(txq_id),
1893 (active << SCD_QUEUE_STTS_REG_POS_ACTIVE) | 686 (active << IWL49_SCD_QUEUE_STTS_REG_POS_ACTIVE) |
1894 (tx_fifo_id << SCD_QUEUE_STTS_REG_POS_TXF) | 687 (tx_fifo_id << IWL49_SCD_QUEUE_STTS_REG_POS_TXF) |
1895 (scd_retry << SCD_QUEUE_STTS_REG_POS_WSL) | 688 (scd_retry << IWL49_SCD_QUEUE_STTS_REG_POS_WSL) |
1896 (scd_retry << SCD_QUEUE_STTS_REG_POS_SCD_ACK) | 689 (scd_retry << IWL49_SCD_QUEUE_STTS_REG_POS_SCD_ACK) |
1897 SCD_QUEUE_STTS_REG_MSK); 690 IWL49_SCD_QUEUE_STTS_REG_MSK);
1898 691
1899 txq->sched_retry = scd_retry; 692 txq->sched_retry = scd_retry;
1900 693
@@ -1908,22 +701,12 @@ static const u16 default_queue_to_tx_fifo[] = {
1908 IWL_TX_FIFO_AC2, 701 IWL_TX_FIFO_AC2,
1909 IWL_TX_FIFO_AC1, 702 IWL_TX_FIFO_AC1,
1910 IWL_TX_FIFO_AC0, 703 IWL_TX_FIFO_AC0,
1911 IWL_CMD_FIFO_NUM, 704 IWL49_CMD_FIFO_NUM,
1912 IWL_TX_FIFO_HCCA_1, 705 IWL_TX_FIFO_HCCA_1,
1913 IWL_TX_FIFO_HCCA_2 706 IWL_TX_FIFO_HCCA_2
1914}; 707};
1915 708
1916static inline void iwl4965_txq_ctx_activate(struct iwl_priv *priv, int txq_id) 709static int iwl4965_alive_notify(struct iwl_priv *priv)
1917{
1918 set_bit(txq_id, &priv->txq_ctx_active_msk);
1919}
1920
1921static inline void iwl4965_txq_ctx_deactivate(struct iwl_priv *priv, int txq_id)
1922{
1923 clear_bit(txq_id, &priv->txq_ctx_active_msk);
1924}
1925
1926int iwl4965_alive_notify(struct iwl_priv *priv)
1927{ 710{
1928 u32 a; 711 u32 a;
1929 int i = 0; 712 int i = 0;
@@ -1932,15 +715,6 @@ int iwl4965_alive_notify(struct iwl_priv *priv)
1932 715
1933 spin_lock_irqsave(&priv->lock, flags); 716 spin_lock_irqsave(&priv->lock, flags);
1934 717
1935#ifdef CONFIG_IWL4965_SENSITIVITY
1936 memset(&(priv->sensitivity_data), 0,
1937 sizeof(struct iwl4965_sensitivity_data));
1938 memset(&(priv->chain_noise_data), 0,
1939 sizeof(struct iwl4965_chain_noise_data));
1940 for (i = 0; i < NUM_RX_CHAINS; i++)
1941 priv->chain_noise_data.delta_gain_code[i] =
1942 CHAIN_NOISE_DELTA_GAIN_INIT_VAL;
1943#endif /* CONFIG_IWL4965_SENSITIVITY*/
1944 ret = iwl_grab_nic_access(priv); 718 ret = iwl_grab_nic_access(priv);
1945 if (ret) { 719 if (ret) {
1946 spin_unlock_irqrestore(&priv->lock, flags); 720 spin_unlock_irqrestore(&priv->lock, flags);
@@ -1949,10 +723,10 @@ int iwl4965_alive_notify(struct iwl_priv *priv)
1949 723
1950 /* Clear 4965's internal Tx Scheduler data base */ 724 /* Clear 4965's internal Tx Scheduler data base */
1951 priv->scd_base_addr = iwl_read_prph(priv, IWL49_SCD_SRAM_BASE_ADDR); 725 priv->scd_base_addr = iwl_read_prph(priv, IWL49_SCD_SRAM_BASE_ADDR);
1952 a = priv->scd_base_addr + SCD_CONTEXT_DATA_OFFSET; 726 a = priv->scd_base_addr + IWL49_SCD_CONTEXT_DATA_OFFSET;
1953 for (; a < priv->scd_base_addr + SCD_TX_STTS_BITMAP_OFFSET; a += 4) 727 for (; a < priv->scd_base_addr + IWL49_SCD_TX_STTS_BITMAP_OFFSET; a += 4)
1954 iwl_write_targ_mem(priv, a, 0); 728 iwl_write_targ_mem(priv, a, 0);
1955 for (; a < priv->scd_base_addr + SCD_TRANSLATE_TBL_OFFSET; a += 4) 729 for (; a < priv->scd_base_addr + IWL49_SCD_TRANSLATE_TBL_OFFSET; a += 4)
1956 iwl_write_targ_mem(priv, a, 0); 730 iwl_write_targ_mem(priv, a, 0);
1957 for (; a < sizeof(u16) * priv->hw_params.max_txq_num; a += 4) 731 for (; a < sizeof(u16) * priv->hw_params.max_txq_num; a += 4)
1958 iwl_write_targ_mem(priv, a, 0); 732 iwl_write_targ_mem(priv, a, 0);
@@ -1974,162 +748,99 @@ int iwl4965_alive_notify(struct iwl_priv *priv)
1974 748
1975 /* Max Tx Window size for Scheduler-ACK mode */ 749 /* Max Tx Window size for Scheduler-ACK mode */
1976 iwl_write_targ_mem(priv, priv->scd_base_addr + 750 iwl_write_targ_mem(priv, priv->scd_base_addr +
1977 SCD_CONTEXT_QUEUE_OFFSET(i), 751 IWL49_SCD_CONTEXT_QUEUE_OFFSET(i),
1978 (SCD_WIN_SIZE << 752 (SCD_WIN_SIZE <<
1979 SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) & 753 IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) &
1980 SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK); 754 IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK);
1981 755
1982 /* Frame limit */ 756 /* Frame limit */
1983 iwl_write_targ_mem(priv, priv->scd_base_addr + 757 iwl_write_targ_mem(priv, priv->scd_base_addr +
1984 SCD_CONTEXT_QUEUE_OFFSET(i) + 758 IWL49_SCD_CONTEXT_QUEUE_OFFSET(i) +
1985 sizeof(u32), 759 sizeof(u32),
1986 (SCD_FRAME_LIMIT << 760 (SCD_FRAME_LIMIT <<
1987 SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) & 761 IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
1988 SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK); 762 IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK);
1989 763
1990 } 764 }
1991 iwl_write_prph(priv, IWL49_SCD_INTERRUPT_MASK, 765 iwl_write_prph(priv, IWL49_SCD_INTERRUPT_MASK,
1992 (1 << priv->hw_params.max_txq_num) - 1); 766 (1 << priv->hw_params.max_txq_num) - 1);
1993 767
1994 /* Activate all Tx DMA/FIFO channels */ 768 /* Activate all Tx DMA/FIFO channels */
1995 iwl_write_prph(priv, IWL49_SCD_TXFACT, 769 priv->cfg->ops->lib->txq_set_sched(priv, IWL_MASK(0, 7));
1996 SCD_TXFACT_REG_TXFIFO_MASK(0, 7));
1997 770
1998 iwl4965_set_wr_ptrs(priv, IWL_CMD_QUEUE_NUM, 0); 771 iwl4965_set_wr_ptrs(priv, IWL_CMD_QUEUE_NUM, 0);
1999 772
2000 /* Map each Tx/cmd queue to its corresponding fifo */ 773 /* Map each Tx/cmd queue to its corresponding fifo */
2001 for (i = 0; i < ARRAY_SIZE(default_queue_to_tx_fifo); i++) { 774 for (i = 0; i < ARRAY_SIZE(default_queue_to_tx_fifo); i++) {
2002 int ac = default_queue_to_tx_fifo[i]; 775 int ac = default_queue_to_tx_fifo[i];
2003 iwl4965_txq_ctx_activate(priv, i); 776 iwl_txq_ctx_activate(priv, i);
2004 iwl4965_tx_queue_set_status(priv, &priv->txq[i], ac, 0); 777 iwl4965_tx_queue_set_status(priv, &priv->txq[i], ac, 0);
2005 } 778 }
2006 779
2007 iwl_release_nic_access(priv); 780 iwl_release_nic_access(priv);
2008 spin_unlock_irqrestore(&priv->lock, flags); 781 spin_unlock_irqrestore(&priv->lock, flags);
2009 782
2010 /* Ask for statistics now, the uCode will send statistics notification
2011 * periodically after association */
2012 iwl_send_statistics_request(priv, CMD_ASYNC);
2013 return ret; 783 return ret;
2014} 784}
2015 785
786static struct iwl_sensitivity_ranges iwl4965_sensitivity = {
787 .min_nrg_cck = 97,
788 .max_nrg_cck = 0,
789
790 .auto_corr_min_ofdm = 85,
791 .auto_corr_min_ofdm_mrc = 170,
792 .auto_corr_min_ofdm_x1 = 105,
793 .auto_corr_min_ofdm_mrc_x1 = 220,
794
795 .auto_corr_max_ofdm = 120,
796 .auto_corr_max_ofdm_mrc = 210,
797 .auto_corr_max_ofdm_x1 = 140,
798 .auto_corr_max_ofdm_mrc_x1 = 270,
799
800 .auto_corr_min_cck = 125,
801 .auto_corr_max_cck = 200,
802 .auto_corr_min_cck_mrc = 200,
803 .auto_corr_max_cck_mrc = 400,
804
805 .nrg_th_cck = 100,
806 .nrg_th_ofdm = 100,
807};
808
2016/** 809/**
2017 * iwl4965_hw_set_hw_params 810 * iwl4965_hw_set_hw_params
2018 * 811 *
2019 * Called when initializing driver 812 * Called when initializing driver
2020 */ 813 */
2021int iwl4965_hw_set_hw_params(struct iwl_priv *priv) 814static int iwl4965_hw_set_hw_params(struct iwl_priv *priv)
2022{ 815{
2023 816
2024 if ((priv->cfg->mod_params->num_of_queues > IWL4965_MAX_NUM_QUEUES) || 817 if ((priv->cfg->mod_params->num_of_queues > IWL49_NUM_QUEUES) ||
2025 (priv->cfg->mod_params->num_of_queues < IWL_MIN_NUM_QUEUES)) { 818 (priv->cfg->mod_params->num_of_queues < IWL_MIN_NUM_QUEUES)) {
2026 IWL_ERROR("invalid queues_num, should be between %d and %d\n", 819 IWL_ERROR("invalid queues_num, should be between %d and %d\n",
2027 IWL_MIN_NUM_QUEUES, IWL4965_MAX_NUM_QUEUES); 820 IWL_MIN_NUM_QUEUES, IWL49_NUM_QUEUES);
2028 return -EINVAL; 821 return -EINVAL;
2029 } 822 }
2030 823
2031 priv->hw_params.max_txq_num = priv->cfg->mod_params->num_of_queues; 824 priv->hw_params.max_txq_num = priv->cfg->mod_params->num_of_queues;
2032 priv->hw_params.tx_cmd_len = sizeof(struct iwl4965_tx_cmd); 825 priv->hw_params.first_ampdu_q = IWL49_FIRST_AMPDU_QUEUE;
2033 priv->hw_params.max_rxq_size = RX_QUEUE_SIZE;
2034 priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
2035 if (priv->cfg->mod_params->amsdu_size_8K)
2036 priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_8K;
2037 else
2038 priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_4K;
2039 priv->hw_params.max_pkt_size = priv->hw_params.rx_buf_size - 256;
2040 priv->hw_params.max_stations = IWL4965_STATION_COUNT; 826 priv->hw_params.max_stations = IWL4965_STATION_COUNT;
2041 priv->hw_params.bcast_sta_id = IWL4965_BROADCAST_ID; 827 priv->hw_params.bcast_sta_id = IWL4965_BROADCAST_ID;
828 priv->hw_params.max_data_size = IWL49_RTC_DATA_SIZE;
829 priv->hw_params.max_inst_size = IWL49_RTC_INST_SIZE;
830 priv->hw_params.max_bsm_size = BSM_SRAM_SIZE;
831 priv->hw_params.fat_channel = BIT(IEEE80211_BAND_5GHZ);
2042 832
2043 priv->hw_params.tx_chains_num = 2; 833 priv->hw_params.tx_chains_num = 2;
2044 priv->hw_params.rx_chains_num = 2; 834 priv->hw_params.rx_chains_num = 2;
2045 priv->hw_params.valid_tx_ant = (IWL_ANTENNA_MAIN | IWL_ANTENNA_AUX); 835 priv->hw_params.valid_tx_ant = ANT_A | ANT_B;
2046 priv->hw_params.valid_rx_ant = (IWL_ANTENNA_MAIN | IWL_ANTENNA_AUX); 836 priv->hw_params.valid_rx_ant = ANT_A | ANT_B;
2047 837 priv->hw_params.ct_kill_threshold = CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD);
2048 return 0;
2049}
2050
2051/**
2052 * iwl4965_hw_txq_ctx_free - Free TXQ Context
2053 *
2054 * Destroy all TX DMA queues and structures
2055 */
2056void iwl4965_hw_txq_ctx_free(struct iwl_priv *priv)
2057{
2058 int txq_id;
2059
2060 /* Tx queues */
2061 for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++)
2062 iwl4965_tx_queue_free(priv, &priv->txq[txq_id]);
2063
2064 /* Keep-warm buffer */
2065 iwl4965_kw_free(priv);
2066}
2067
2068/**
2069 * iwl4965_hw_txq_free_tfd - Free all chunks referenced by TFD [txq->q.read_ptr]
2070 *
2071 * Does NOT advance any TFD circular buffer read/write indexes
2072 * Does NOT free the TFD itself (which is within circular buffer)
2073 */
2074int iwl4965_hw_txq_free_tfd(struct iwl_priv *priv, struct iwl4965_tx_queue *txq)
2075{
2076 struct iwl4965_tfd_frame *bd_tmp = (struct iwl4965_tfd_frame *)&txq->bd[0];
2077 struct iwl4965_tfd_frame *bd = &bd_tmp[txq->q.read_ptr];
2078 struct pci_dev *dev = priv->pci_dev;
2079 int i;
2080 int counter = 0;
2081 int index, is_odd;
2082 838
2083 /* Host command buffers stay mapped in memory, nothing to clean */ 839 priv->hw_params.sens = &iwl4965_sensitivity;
2084 if (txq->q.id == IWL_CMD_QUEUE_NUM)
2085 return 0;
2086 840
2087 /* Sanity check on number of chunks */
2088 counter = IWL_GET_BITS(*bd, num_tbs);
2089 if (counter > MAX_NUM_OF_TBS) {
2090 IWL_ERROR("Too many chunks: %i\n", counter);
2091 /* @todo issue fatal error, it is quite serious situation */
2092 return 0;
2093 }
2094
2095 /* Unmap chunks, if any.
2096 * TFD info for odd chunks is different format than for even chunks. */
2097 for (i = 0; i < counter; i++) {
2098 index = i / 2;
2099 is_odd = i & 0x1;
2100
2101 if (is_odd)
2102 pci_unmap_single(
2103 dev,
2104 IWL_GET_BITS(bd->pa[index], tb2_addr_lo16) |
2105 (IWL_GET_BITS(bd->pa[index],
2106 tb2_addr_hi20) << 16),
2107 IWL_GET_BITS(bd->pa[index], tb2_len),
2108 PCI_DMA_TODEVICE);
2109
2110 else if (i > 0)
2111 pci_unmap_single(dev,
2112 le32_to_cpu(bd->pa[index].tb1_addr),
2113 IWL_GET_BITS(bd->pa[index], tb1_len),
2114 PCI_DMA_TODEVICE);
2115
2116 /* Free SKB, if any, for this chunk */
2117 if (txq->txb[txq->q.read_ptr].skb[i]) {
2118 struct sk_buff *skb = txq->txb[txq->q.read_ptr].skb[i];
2119
2120 dev_kfree_skb(skb);
2121 txq->txb[txq->q.read_ptr].skb[i] = NULL;
2122 }
2123 }
2124 return 0; 841 return 0;
2125} 842}
2126 843
2127int iwl4965_hw_reg_set_txpower(struct iwl_priv *priv, s8 power)
2128{
2129 IWL_ERROR("TODO: Implement iwl4965_hw_reg_set_txpower!\n");
2130 return -EINVAL;
2131}
2132
2133static s32 iwl4965_math_div_round(s32 num, s32 denom, s32 *res) 844static s32 iwl4965_math_div_round(s32 num, s32 denom, s32 *res)
2134{ 845{
2135 s32 sign = 1; 846 s32 sign = 1;
@@ -2179,20 +890,6 @@ static s32 iwl4965_get_voltage_compensation(s32 eeprom_voltage,
2179 return comp; 890 return comp;
2180} 891}
2181 892
2182static const struct iwl_channel_info *
2183iwl4965_get_channel_txpower_info(struct iwl_priv *priv,
2184 enum ieee80211_band band, u16 channel)
2185{
2186 const struct iwl_channel_info *ch_info;
2187
2188 ch_info = iwl_get_channel_info(priv, band, channel);
2189
2190 if (!is_channel_valid(ch_info))
2191 return NULL;
2192
2193 return ch_info;
2194}
2195
2196static s32 iwl4965_get_tx_atten_grp(u16 channel) 893static s32 iwl4965_get_tx_atten_grp(u16 channel)
2197{ 894{
2198 if (channel >= CALIB_IWL_TX_ATTEN_GR5_FCH && 895 if (channel >= CALIB_IWL_TX_ATTEN_GR5_FCH &&
@@ -2224,11 +921,11 @@ static u32 iwl4965_get_sub_band(const struct iwl_priv *priv, u32 channel)
2224 s32 b = -1; 921 s32 b = -1;
2225 922
2226 for (b = 0; b < EEPROM_TX_POWER_BANDS; b++) { 923 for (b = 0; b < EEPROM_TX_POWER_BANDS; b++) {
2227 if (priv->eeprom.calib_info.band_info[b].ch_from == 0) 924 if (priv->calib_info->band_info[b].ch_from == 0)
2228 continue; 925 continue;
2229 926
2230 if ((channel >= priv->eeprom.calib_info.band_info[b].ch_from) 927 if ((channel >= priv->calib_info->band_info[b].ch_from)
2231 && (channel <= priv->eeprom.calib_info.band_info[b].ch_to)) 928 && (channel <= priv->calib_info->band_info[b].ch_to))
2232 break; 929 break;
2233 } 930 }
2234 931
@@ -2256,25 +953,25 @@ static s32 iwl4965_interpolate_value(s32 x, s32 x1, s32 y1, s32 x2, s32 y2)
2256 * in channel number. 953 * in channel number.
2257 */ 954 */
2258static int iwl4965_interpolate_chan(struct iwl_priv *priv, u32 channel, 955static int iwl4965_interpolate_chan(struct iwl_priv *priv, u32 channel,
2259 struct iwl4965_eeprom_calib_ch_info *chan_info) 956 struct iwl_eeprom_calib_ch_info *chan_info)
2260{ 957{
2261 s32 s = -1; 958 s32 s = -1;
2262 u32 c; 959 u32 c;
2263 u32 m; 960 u32 m;
2264 const struct iwl4965_eeprom_calib_measure *m1; 961 const struct iwl_eeprom_calib_measure *m1;
2265 const struct iwl4965_eeprom_calib_measure *m2; 962 const struct iwl_eeprom_calib_measure *m2;
2266 struct iwl4965_eeprom_calib_measure *omeas; 963 struct iwl_eeprom_calib_measure *omeas;
2267 u32 ch_i1; 964 u32 ch_i1;
2268 u32 ch_i2; 965 u32 ch_i2;
2269 966
2270 s = iwl4965_get_sub_band(priv, channel); 967 s = iwl4965_get_sub_band(priv, channel);
2271 if (s >= EEPROM_TX_POWER_BANDS) { 968 if (s >= EEPROM_TX_POWER_BANDS) {
2272 IWL_ERROR("Tx Power can not find channel %d ", channel); 969 IWL_ERROR("Tx Power can not find channel %d\n", channel);
2273 return -1; 970 return -1;
2274 } 971 }
2275 972
2276 ch_i1 = priv->eeprom.calib_info.band_info[s].ch1.ch_num; 973 ch_i1 = priv->calib_info->band_info[s].ch1.ch_num;
2277 ch_i2 = priv->eeprom.calib_info.band_info[s].ch2.ch_num; 974 ch_i2 = priv->calib_info->band_info[s].ch2.ch_num;
2278 chan_info->ch_num = (u8) channel; 975 chan_info->ch_num = (u8) channel;
2279 976
2280 IWL_DEBUG_TXPOWER("channel %d subband %d factory cal ch %d & %d\n", 977 IWL_DEBUG_TXPOWER("channel %d subband %d factory cal ch %d & %d\n",
@@ -2282,9 +979,9 @@ static int iwl4965_interpolate_chan(struct iwl_priv *priv, u32 channel,
2282 979
2283 for (c = 0; c < EEPROM_TX_POWER_TX_CHAINS; c++) { 980 for (c = 0; c < EEPROM_TX_POWER_TX_CHAINS; c++) {
2284 for (m = 0; m < EEPROM_TX_POWER_MEASUREMENTS; m++) { 981 for (m = 0; m < EEPROM_TX_POWER_MEASUREMENTS; m++) {
2285 m1 = &(priv->eeprom.calib_info.band_info[s].ch1. 982 m1 = &(priv->calib_info->band_info[s].ch1.
2286 measurements[c][m]); 983 measurements[c][m]);
2287 m2 = &(priv->eeprom.calib_info.band_info[s].ch2. 984 m2 = &(priv->calib_info->band_info[s].ch2.
2288 measurements[c][m]); 985 measurements[c][m]);
2289 omeas = &(chan_info->measurements[c][m]); 986 omeas = &(chan_info->measurements[c][m]);
2290 987
@@ -2603,8 +1300,8 @@ static int iwl4965_fill_txpower_tbl(struct iwl_priv *priv, u8 band, u16 channel,
2603 int i; 1300 int i;
2604 int c; 1301 int c;
2605 const struct iwl_channel_info *ch_info = NULL; 1302 const struct iwl_channel_info *ch_info = NULL;
2606 struct iwl4965_eeprom_calib_ch_info ch_eeprom_info; 1303 struct iwl_eeprom_calib_ch_info ch_eeprom_info;
2607 const struct iwl4965_eeprom_calib_measure *measurement; 1304 const struct iwl_eeprom_calib_measure *measurement;
2608 s16 voltage; 1305 s16 voltage;
2609 s32 init_voltage; 1306 s32 init_voltage;
2610 s32 voltage_compensation; 1307 s32 voltage_compensation;
@@ -2616,30 +1313,17 @@ static int iwl4965_fill_txpower_tbl(struct iwl_priv *priv, u8 band, u16 channel,
2616 s32 factory_actual_pwr[2]; 1313 s32 factory_actual_pwr[2];
2617 s32 power_index; 1314 s32 power_index;
2618 1315
2619 /* Sanity check requested level (dBm) */
2620 if (priv->user_txpower_limit < IWL_TX_POWER_TARGET_POWER_MIN) {
2621 IWL_WARNING("Requested user TXPOWER %d below limit.\n",
2622 priv->user_txpower_limit);
2623 return -EINVAL;
2624 }
2625 if (priv->user_txpower_limit > IWL_TX_POWER_TARGET_POWER_MAX) {
2626 IWL_WARNING("Requested user TXPOWER %d above limit.\n",
2627 priv->user_txpower_limit);
2628 return -EINVAL;
2629 }
2630
2631 /* user_txpower_limit is in dBm, convert to half-dBm (half-dB units 1316 /* user_txpower_limit is in dBm, convert to half-dBm (half-dB units
2632 * are used for indexing into txpower table) */ 1317 * are used for indexing into txpower table) */
2633 user_target_power = 2 * priv->user_txpower_limit; 1318 user_target_power = 2 * priv->tx_power_user_lmt;
2634 1319
2635 /* Get current (RXON) channel, band, width */ 1320 /* Get current (RXON) channel, band, width */
2636 ch_info =
2637 iwl4965_get_channel_txpower_info(priv, priv->band, channel);
2638
2639 IWL_DEBUG_TXPOWER("chan %d band %d is_fat %d\n", channel, band, 1321 IWL_DEBUG_TXPOWER("chan %d band %d is_fat %d\n", channel, band,
2640 is_fat); 1322 is_fat);
2641 1323
2642 if (!ch_info) 1324 ch_info = iwl_get_channel_info(priv, priv->band, channel);
1325
1326 if (!is_channel_valid(ch_info))
2643 return -EINVAL; 1327 return -EINVAL;
2644 1328
2645 /* get txatten group, used to select 1) thermal txpower adjustment 1329 /* get txatten group, used to select 1) thermal txpower adjustment
@@ -2661,9 +1345,9 @@ static int iwl4965_fill_txpower_tbl(struct iwl_priv *priv, u8 band, u16 channel,
2661 /* hardware txpower limits ... 1345 /* hardware txpower limits ...
2662 * saturation (clipping distortion) txpowers are in half-dBm */ 1346 * saturation (clipping distortion) txpowers are in half-dBm */
2663 if (band) 1347 if (band)
2664 saturation_power = priv->eeprom.calib_info.saturation_power24; 1348 saturation_power = priv->calib_info->saturation_power24;
2665 else 1349 else
2666 saturation_power = priv->eeprom.calib_info.saturation_power52; 1350 saturation_power = priv->calib_info->saturation_power52;
2667 1351
2668 if (saturation_power < IWL_TX_POWER_SATURATION_MIN || 1352 if (saturation_power < IWL_TX_POWER_SATURATION_MIN ||
2669 saturation_power > IWL_TX_POWER_SATURATION_MAX) { 1353 saturation_power > IWL_TX_POWER_SATURATION_MAX) {
@@ -2693,7 +1377,7 @@ static int iwl4965_fill_txpower_tbl(struct iwl_priv *priv, u8 band, u16 channel,
2693 iwl4965_interpolate_chan(priv, channel, &ch_eeprom_info); 1377 iwl4965_interpolate_chan(priv, channel, &ch_eeprom_info);
2694 1378
2695 /* calculate tx gain adjustment based on power supply voltage */ 1379 /* calculate tx gain adjustment based on power supply voltage */
2696 voltage = priv->eeprom.calib_info.voltage; 1380 voltage = priv->calib_info->voltage;
2697 init_voltage = (s32)le32_to_cpu(priv->card_alive_init.voltage); 1381 init_voltage = (s32)le32_to_cpu(priv->card_alive_init.voltage);
2698 voltage_compensation = 1382 voltage_compensation =
2699 iwl4965_get_voltage_compensation(voltage, init_voltage); 1383 iwl4965_get_voltage_compensation(voltage, init_voltage);
@@ -2830,22 +1514,22 @@ static int iwl4965_fill_txpower_tbl(struct iwl_priv *priv, u8 band, u16 channel,
2830 c, atten_value, power_index, 1514 c, atten_value, power_index,
2831 tx_power.s.radio_tx_gain[c], 1515 tx_power.s.radio_tx_gain[c],
2832 tx_power.s.dsp_predis_atten[c]); 1516 tx_power.s.dsp_predis_atten[c]);
2833 }/* for each chain */ 1517 } /* for each chain */
2834 1518
2835 tx_power_tbl->power_tbl[i].dw = cpu_to_le32(tx_power.dw); 1519 tx_power_tbl->power_tbl[i].dw = cpu_to_le32(tx_power.dw);
2836 1520
2837 }/* for each rate */ 1521 } /* for each rate */
2838 1522
2839 return 0; 1523 return 0;
2840} 1524}
2841 1525
2842/** 1526/**
2843 * iwl4965_hw_reg_send_txpower - Configure the TXPOWER level user limit 1527 * iwl4965_send_tx_power - Configure the TXPOWER level user limit
2844 * 1528 *
2845 * Uses the active RXON for channel, band, and characteristics (fat, high) 1529 * Uses the active RXON for channel, band, and characteristics (fat, high)
2846 * The power limit is taken from priv->user_txpower_limit. 1530 * The power limit is taken from priv->tx_power_user_lmt.
2847 */ 1531 */
2848int iwl4965_hw_reg_send_txpower(struct iwl_priv *priv) 1532static int iwl4965_send_tx_power(struct iwl_priv *priv)
2849{ 1533{
2850 struct iwl4965_txpowertable_cmd cmd = { 0 }; 1534 struct iwl4965_txpowertable_cmd cmd = { 0 };
2851 int ret; 1535 int ret;
@@ -2888,8 +1572,8 @@ static int iwl4965_send_rxon_assoc(struct iwl_priv *priv)
2888{ 1572{
2889 int ret = 0; 1573 int ret = 0;
2890 struct iwl4965_rxon_assoc_cmd rxon_assoc; 1574 struct iwl4965_rxon_assoc_cmd rxon_assoc;
2891 const struct iwl4965_rxon_cmd *rxon1 = &priv->staging_rxon; 1575 const struct iwl_rxon_cmd *rxon1 = &priv->staging_rxon;
2892 const struct iwl4965_rxon_cmd *rxon2 = &priv->active_rxon; 1576 const struct iwl_rxon_cmd *rxon2 = &priv->active_rxon;
2893 1577
2894 if ((rxon1->flags == rxon2->flags) && 1578 if ((rxon1->flags == rxon2->flags) &&
2895 (rxon1->filter_flags == rxon2->filter_flags) && 1579 (rxon1->filter_flags == rxon2->filter_flags) &&
@@ -2923,8 +1607,8 @@ static int iwl4965_send_rxon_assoc(struct iwl_priv *priv)
2923 return ret; 1607 return ret;
2924} 1608}
2925 1609
2926 1610#ifdef IEEE80211_CONF_CHANNEL_SWITCH
2927int iwl4965_hw_channel_switch(struct iwl_priv *priv, u16 channel) 1611static int iwl4965_hw_channel_switch(struct iwl_priv *priv, u16 channel)
2928{ 1612{
2929 int rc; 1613 int rc;
2930 u8 band = 0; 1614 u8 band = 0;
@@ -2964,209 +1648,43 @@ int iwl4965_hw_channel_switch(struct iwl_priv *priv, u16 channel)
2964 rc = iwl_send_cmd_pdu(priv, REPLY_CHANNEL_SWITCH, sizeof(cmd), &cmd); 1648 rc = iwl_send_cmd_pdu(priv, REPLY_CHANNEL_SWITCH, sizeof(cmd), &cmd);
2965 return rc; 1649 return rc;
2966} 1650}
1651#endif
2967 1652
2968#define RTS_HCCA_RETRY_LIMIT 3 1653static int iwl4965_shared_mem_rx_idx(struct iwl_priv *priv)
2969#define RTS_DFAULT_RETRY_LIMIT 60
2970
2971void iwl4965_hw_build_tx_cmd_rate(struct iwl_priv *priv,
2972 struct iwl_cmd *cmd,
2973 struct ieee80211_tx_control *ctrl,
2974 struct ieee80211_hdr *hdr, int sta_id,
2975 int is_hcca)
2976{
2977 struct iwl4965_tx_cmd *tx = &cmd->cmd.tx;
2978 u8 rts_retry_limit = 0;
2979 u8 data_retry_limit = 0;
2980 u16 fc = le16_to_cpu(hdr->frame_control);
2981 u8 rate_plcp;
2982 u16 rate_flags = 0;
2983 int rate_idx = min(ctrl->tx_rate->hw_value & 0xffff, IWL_RATE_COUNT - 1);
2984
2985 rate_plcp = iwl4965_rates[rate_idx].plcp;
2986
2987 rts_retry_limit = (is_hcca) ?
2988 RTS_HCCA_RETRY_LIMIT : RTS_DFAULT_RETRY_LIMIT;
2989
2990 if ((rate_idx >= IWL_FIRST_CCK_RATE) && (rate_idx <= IWL_LAST_CCK_RATE))
2991 rate_flags |= RATE_MCS_CCK_MSK;
2992
2993
2994 if (ieee80211_is_probe_response(fc)) {
2995 data_retry_limit = 3;
2996 if (data_retry_limit < rts_retry_limit)
2997 rts_retry_limit = data_retry_limit;
2998 } else
2999 data_retry_limit = IWL_DEFAULT_TX_RETRY;
3000
3001 if (priv->data_retry_limit != -1)
3002 data_retry_limit = priv->data_retry_limit;
3003
3004
3005 if (ieee80211_is_data(fc)) {
3006 tx->initial_rate_index = 0;
3007 tx->tx_flags |= TX_CMD_FLG_STA_RATE_MSK;
3008 } else {
3009 switch (fc & IEEE80211_FCTL_STYPE) {
3010 case IEEE80211_STYPE_AUTH:
3011 case IEEE80211_STYPE_DEAUTH:
3012 case IEEE80211_STYPE_ASSOC_REQ:
3013 case IEEE80211_STYPE_REASSOC_REQ:
3014 if (tx->tx_flags & TX_CMD_FLG_RTS_MSK) {
3015 tx->tx_flags &= ~TX_CMD_FLG_RTS_MSK;
3016 tx->tx_flags |= TX_CMD_FLG_CTS_MSK;
3017 }
3018 break;
3019 default:
3020 break;
3021 }
3022
3023 /* Alternate between antenna A and B for successive frames */
3024 if (priv->use_ant_b_for_management_frame) {
3025 priv->use_ant_b_for_management_frame = 0;
3026 rate_flags |= RATE_MCS_ANT_B_MSK;
3027 } else {
3028 priv->use_ant_b_for_management_frame = 1;
3029 rate_flags |= RATE_MCS_ANT_A_MSK;
3030 }
3031 }
3032
3033 tx->rts_retry_limit = rts_retry_limit;
3034 tx->data_retry_limit = data_retry_limit;
3035 tx->rate_n_flags = iwl4965_hw_set_rate_n_flags(rate_plcp, rate_flags);
3036}
3037
3038int iwl4965_hw_get_rx_read(struct iwl_priv *priv)
3039{ 1654{
3040 struct iwl4965_shared *s = priv->shared_virt; 1655 struct iwl4965_shared *s = priv->shared_virt;
3041 return le32_to_cpu(s->rb_closed) & 0xFFF; 1656 return le32_to_cpu(s->rb_closed) & 0xFFF;
3042} 1657}
3043 1658
3044int iwl4965_hw_get_temperature(struct iwl_priv *priv) 1659static int iwl4965_alloc_shared_mem(struct iwl_priv *priv)
3045{
3046 return priv->temperature;
3047}
3048
3049unsigned int iwl4965_hw_get_beacon_cmd(struct iwl_priv *priv,
3050 struct iwl4965_frame *frame, u8 rate)
3051{
3052 struct iwl4965_tx_beacon_cmd *tx_beacon_cmd;
3053 unsigned int frame_size;
3054
3055 tx_beacon_cmd = &frame->u.beacon;
3056 memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd));
3057
3058 tx_beacon_cmd->tx.sta_id = priv->hw_params.bcast_sta_id;
3059 tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
3060
3061 frame_size = iwl4965_fill_beacon_frame(priv,
3062 tx_beacon_cmd->frame,
3063 iwl4965_broadcast_addr,
3064 sizeof(frame->u) - sizeof(*tx_beacon_cmd));
3065
3066 BUG_ON(frame_size > MAX_MPDU_SIZE);
3067 tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
3068
3069 if ((rate == IWL_RATE_1M_PLCP) || (rate >= IWL_RATE_2M_PLCP))
3070 tx_beacon_cmd->tx.rate_n_flags =
3071 iwl4965_hw_set_rate_n_flags(rate, RATE_MCS_CCK_MSK);
3072 else
3073 tx_beacon_cmd->tx.rate_n_flags =
3074 iwl4965_hw_set_rate_n_flags(rate, 0);
3075
3076 tx_beacon_cmd->tx.tx_flags = (TX_CMD_FLG_SEQ_CTL_MSK |
3077 TX_CMD_FLG_TSF_MSK | TX_CMD_FLG_STA_RATE_MSK);
3078 return (sizeof(*tx_beacon_cmd) + frame_size);
3079}
3080
3081/*
3082 * Tell 4965 where to find circular buffer of Tx Frame Descriptors for
3083 * given Tx queue, and enable the DMA channel used for that queue.
3084 *
3085 * 4965 supports up to 16 Tx queues in DRAM, mapped to up to 8 Tx DMA
3086 * channels supported in hardware.
3087 */
3088int iwl4965_hw_tx_queue_init(struct iwl_priv *priv, struct iwl4965_tx_queue *txq)
3089{ 1660{
3090 int rc; 1661 priv->shared_virt = pci_alloc_consistent(priv->pci_dev,
3091 unsigned long flags; 1662 sizeof(struct iwl4965_shared),
3092 int txq_id = txq->q.id; 1663 &priv->shared_phys);
3093 1664 if (!priv->shared_virt)
3094 spin_lock_irqsave(&priv->lock, flags); 1665 return -ENOMEM;
3095 rc = iwl_grab_nic_access(priv);
3096 if (rc) {
3097 spin_unlock_irqrestore(&priv->lock, flags);
3098 return rc;
3099 }
3100
3101 /* Circular buffer (TFD queue in DRAM) physical base address */
3102 iwl_write_direct32(priv, FH_MEM_CBBC_QUEUE(txq_id),
3103 txq->q.dma_addr >> 8);
3104
3105 /* Enable DMA channel, using same id as for TFD queue */
3106 iwl_write_direct32(
3107 priv, IWL_FH_TCSR_CHNL_TX_CONFIG_REG(txq_id),
3108 IWL_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
3109 IWL_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE_VAL);
3110 iwl_release_nic_access(priv);
3111 spin_unlock_irqrestore(&priv->lock, flags);
3112
3113 return 0;
3114}
3115
3116int iwl4965_hw_txq_attach_buf_to_tfd(struct iwl_priv *priv, void *ptr,
3117 dma_addr_t addr, u16 len)
3118{
3119 int index, is_odd;
3120 struct iwl4965_tfd_frame *tfd = ptr;
3121 u32 num_tbs = IWL_GET_BITS(*tfd, num_tbs);
3122
3123 /* Each TFD can point to a maximum 20 Tx buffers */
3124 if ((num_tbs >= MAX_NUM_OF_TBS) || (num_tbs < 0)) {
3125 IWL_ERROR("Error can not send more than %d chunks\n",
3126 MAX_NUM_OF_TBS);
3127 return -EINVAL;
3128 }
3129
3130 index = num_tbs / 2;
3131 is_odd = num_tbs & 0x1;
3132 1666
3133 if (!is_odd) { 1667 memset(priv->shared_virt, 0, sizeof(struct iwl4965_shared));
3134 tfd->pa[index].tb1_addr = cpu_to_le32(addr);
3135 IWL_SET_BITS(tfd->pa[index], tb1_addr_hi,
3136 iwl_get_dma_hi_address(addr));
3137 IWL_SET_BITS(tfd->pa[index], tb1_len, len);
3138 } else {
3139 IWL_SET_BITS(tfd->pa[index], tb2_addr_lo16,
3140 (u32) (addr & 0xffff));
3141 IWL_SET_BITS(tfd->pa[index], tb2_addr_hi20, addr >> 16);
3142 IWL_SET_BITS(tfd->pa[index], tb2_len, len);
3143 }
3144 1668
3145 IWL_SET_BITS(*tfd, num_tbs, num_tbs + 1); 1669 priv->rb_closed_offset = offsetof(struct iwl4965_shared, rb_closed);
3146 1670
3147 return 0; 1671 return 0;
3148} 1672}
3149 1673
3150static void iwl4965_hw_card_show_info(struct iwl_priv *priv) 1674static void iwl4965_free_shared_mem(struct iwl_priv *priv)
3151{ 1675{
3152 u16 hw_version = priv->eeprom.board_revision_4965; 1676 if (priv->shared_virt)
3153 1677 pci_free_consistent(priv->pci_dev,
3154 IWL_DEBUG_INFO("4965ABGN HW Version %u.%u.%u\n", 1678 sizeof(struct iwl4965_shared),
3155 ((hw_version >> 8) & 0x0F), 1679 priv->shared_virt,
3156 ((hw_version >> 8) >> 4), (hw_version & 0x00FF)); 1680 priv->shared_phys);
3157
3158 IWL_DEBUG_INFO("4965ABGN PBA Number %.16s\n",
3159 priv->eeprom.board_pba_number_4965);
3160} 1681}
3161 1682
3162#define IWL_TX_CRC_SIZE 4
3163#define IWL_TX_DELIMITER_SIZE 4
3164
3165/** 1683/**
3166 * iwl4965_txq_update_byte_cnt_tbl - Set up entry in Tx byte-count array 1684 * iwl4965_txq_update_byte_cnt_tbl - Set up entry in Tx byte-count array
3167 */ 1685 */
3168static void iwl4965_txq_update_byte_cnt_tbl(struct iwl_priv *priv, 1686static void iwl4965_txq_update_byte_cnt_tbl(struct iwl_priv *priv,
3169 struct iwl4965_tx_queue *txq, 1687 struct iwl_tx_queue *txq,
3170 u16 byte_cnt) 1688 u16 byte_cnt)
3171{ 1689{
3172 int len; 1690 int len;
@@ -3180,50 +1698,13 @@ static void iwl4965_txq_update_byte_cnt_tbl(struct iwl_priv *priv,
3180 tfd_offset[txq->q.write_ptr], byte_cnt, len); 1698 tfd_offset[txq->q.write_ptr], byte_cnt, len);
3181 1699
3182 /* If within first 64 entries, duplicate at end */ 1700 /* If within first 64 entries, duplicate at end */
3183 if (txq->q.write_ptr < IWL4965_MAX_WIN_SIZE) 1701 if (txq->q.write_ptr < IWL49_MAX_WIN_SIZE)
3184 IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id]. 1702 IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
3185 tfd_offset[IWL4965_QUEUE_SIZE + txq->q.write_ptr], 1703 tfd_offset[IWL49_QUEUE_SIZE + txq->q.write_ptr],
3186 byte_cnt, len); 1704 byte_cnt, len);
3187} 1705}
3188 1706
3189/** 1707/**
3190 * iwl4965_set_rxon_chain - Set up Rx chain usage in "staging" RXON image
3191 *
3192 * Selects how many and which Rx receivers/antennas/chains to use.
3193 * This should not be used for scan command ... it puts data in wrong place.
3194 */
3195void iwl4965_set_rxon_chain(struct iwl_priv *priv)
3196{
3197 u8 is_single = is_single_stream(priv);
3198 u8 idle_state, rx_state;
3199
3200 priv->staging_rxon.rx_chain = 0;
3201 rx_state = idle_state = 3;
3202
3203 /* Tell uCode which antennas are actually connected.
3204 * Before first association, we assume all antennas are connected.
3205 * Just after first association, iwl4965_noise_calibration()
3206 * checks which antennas actually *are* connected. */
3207 priv->staging_rxon.rx_chain |=
3208 cpu_to_le16(priv->valid_antenna << RXON_RX_CHAIN_VALID_POS);
3209
3210 /* How many receivers should we use? */
3211 iwl4965_get_rx_chain_counter(priv, &idle_state, &rx_state);
3212 priv->staging_rxon.rx_chain |=
3213 cpu_to_le16(rx_state << RXON_RX_CHAIN_MIMO_CNT_POS);
3214 priv->staging_rxon.rx_chain |=
3215 cpu_to_le16(idle_state << RXON_RX_CHAIN_CNT_POS);
3216
3217 if (!is_single && (rx_state >= 2) &&
3218 !test_bit(STATUS_POWER_PMI, &priv->status))
3219 priv->staging_rxon.rx_chain |= RXON_RX_CHAIN_MIMO_FORCE_MSK;
3220 else
3221 priv->staging_rxon.rx_chain &= ~RXON_RX_CHAIN_MIMO_FORCE_MSK;
3222
3223 IWL_DEBUG_ASSOC("rx chain %X\n", priv->staging_rxon.rx_chain);
3224}
3225
3226/**
3227 * sign_extend - Sign extend a value using specified bit as sign-bit 1708 * sign_extend - Sign extend a value using specified bit as sign-bit
3228 * 1709 *
3229 * Example: sign_extend(9, 3) would return -7 as bit3 of 1001b is 1 1710 * Example: sign_extend(9, 3) would return -7 as bit3 of 1001b is 1
@@ -3240,12 +1721,12 @@ static s32 sign_extend(u32 oper, int index)
3240} 1721}
3241 1722
3242/** 1723/**
3243 * iwl4965_get_temperature - return the calibrated temperature (in Kelvin) 1724 * iwl4965_hw_get_temperature - return the calibrated temperature (in Kelvin)
3244 * @statistics: Provides the temperature reading from the uCode 1725 * @statistics: Provides the temperature reading from the uCode
3245 * 1726 *
3246 * A return of <0 indicates bogus data in the statistics 1727 * A return of <0 indicates bogus data in the statistics
3247 */ 1728 */
3248int iwl4965_get_temperature(const struct iwl_priv *priv) 1729static int iwl4965_hw_get_temperature(const struct iwl_priv *priv)
3249{ 1730{
3250 s32 temperature; 1731 s32 temperature;
3251 s32 vt; 1732 s32 vt;
@@ -3280,8 +1761,7 @@ int iwl4965_get_temperature(const struct iwl_priv *priv)
3280 vt = sign_extend( 1761 vt = sign_extend(
3281 le32_to_cpu(priv->statistics.general.temperature), 23); 1762 le32_to_cpu(priv->statistics.general.temperature), 23);
3282 1763
3283 IWL_DEBUG_TEMP("Calib values R[1-3]: %d %d %d R4: %d\n", 1764 IWL_DEBUG_TEMP("Calib values R[1-3]: %d %d %d R4: %d\n", R1, R2, R3, vt);
3284 R1, R2, R3, vt);
3285 1765
3286 if (R3 == R1) { 1766 if (R3 == R1) {
3287 IWL_ERROR("Calibration conflict R1 == R3\n"); 1767 IWL_ERROR("Calibration conflict R1 == R3\n");
@@ -3292,11 +1772,10 @@ int iwl4965_get_temperature(const struct iwl_priv *priv)
3292 * Add offset to center the adjustment around 0 degrees Centigrade. */ 1772 * Add offset to center the adjustment around 0 degrees Centigrade. */
3293 temperature = TEMPERATURE_CALIB_A_VAL * (vt - R2); 1773 temperature = TEMPERATURE_CALIB_A_VAL * (vt - R2);
3294 temperature /= (R3 - R1); 1774 temperature /= (R3 - R1);
3295 temperature = (temperature * 97) / 100 + 1775 temperature = (temperature * 97) / 100 + TEMPERATURE_CALIB_KELVIN_OFFSET;
3296 TEMPERATURE_CALIB_KELVIN_OFFSET;
3297 1776
3298 IWL_DEBUG_TEMP("Calibrated temperature: %dK, %dC\n", temperature, 1777 IWL_DEBUG_TEMP("Calibrated temperature: %dK, %dC\n",
3299 KELVIN_TO_CELSIUS(temperature)); 1778 temperature, KELVIN_TO_CELSIUS(temperature));
3300 1779
3301 return temperature; 1780 return temperature;
3302} 1781}
@@ -3343,89 +1822,11 @@ static int iwl4965_is_temp_calib_needed(struct iwl_priv *priv)
3343 return 1; 1822 return 1;
3344} 1823}
3345 1824
3346/* Calculate noise level, based on measurements during network silence just 1825static void iwl4965_temperature_calib(struct iwl_priv *priv)
3347 * before arriving beacon. This measurement can be done only if we know
3348 * exactly when to expect beacons, therefore only when we're associated. */
3349static void iwl4965_rx_calc_noise(struct iwl_priv *priv)
3350{
3351 struct statistics_rx_non_phy *rx_info
3352 = &(priv->statistics.rx.general);
3353 int num_active_rx = 0;
3354 int total_silence = 0;
3355 int bcn_silence_a =
3356 le32_to_cpu(rx_info->beacon_silence_rssi_a) & IN_BAND_FILTER;
3357 int bcn_silence_b =
3358 le32_to_cpu(rx_info->beacon_silence_rssi_b) & IN_BAND_FILTER;
3359 int bcn_silence_c =
3360 le32_to_cpu(rx_info->beacon_silence_rssi_c) & IN_BAND_FILTER;
3361
3362 if (bcn_silence_a) {
3363 total_silence += bcn_silence_a;
3364 num_active_rx++;
3365 }
3366 if (bcn_silence_b) {
3367 total_silence += bcn_silence_b;
3368 num_active_rx++;
3369 }
3370 if (bcn_silence_c) {
3371 total_silence += bcn_silence_c;
3372 num_active_rx++;
3373 }
3374
3375 /* Average among active antennas */
3376 if (num_active_rx)
3377 priv->last_rx_noise = (total_silence / num_active_rx) - 107;
3378 else
3379 priv->last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
3380
3381 IWL_DEBUG_CALIB("inband silence a %u, b %u, c %u, dBm %d\n",
3382 bcn_silence_a, bcn_silence_b, bcn_silence_c,
3383 priv->last_rx_noise);
3384}
3385
3386void iwl4965_hw_rx_statistics(struct iwl_priv *priv, struct iwl4965_rx_mem_buffer *rxb)
3387{ 1826{
3388 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3389 int change;
3390 s32 temp; 1827 s32 temp;
3391 1828
3392 IWL_DEBUG_RX("Statistics notification received (%d vs %d).\n", 1829 temp = iwl4965_hw_get_temperature(priv);
3393 (int)sizeof(priv->statistics), pkt->len);
3394
3395 change = ((priv->statistics.general.temperature !=
3396 pkt->u.stats.general.temperature) ||
3397 ((priv->statistics.flag &
3398 STATISTICS_REPLY_FLG_FAT_MODE_MSK) !=
3399 (pkt->u.stats.flag & STATISTICS_REPLY_FLG_FAT_MODE_MSK)));
3400
3401 memcpy(&priv->statistics, &pkt->u.stats, sizeof(priv->statistics));
3402
3403 set_bit(STATUS_STATISTICS, &priv->status);
3404
3405 /* Reschedule the statistics timer to occur in
3406 * REG_RECALIB_PERIOD seconds to ensure we get a
3407 * thermal update even if the uCode doesn't give
3408 * us one */
3409 mod_timer(&priv->statistics_periodic, jiffies +
3410 msecs_to_jiffies(REG_RECALIB_PERIOD * 1000));
3411
3412 if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)) &&
3413 (pkt->hdr.cmd == STATISTICS_NOTIFICATION)) {
3414 iwl4965_rx_calc_noise(priv);
3415#ifdef CONFIG_IWL4965_SENSITIVITY
3416 queue_work(priv->workqueue, &priv->sensitivity_work);
3417#endif
3418 }
3419
3420 iwl_leds_background(priv);
3421
3422 /* If the hardware hasn't reported a change in
3423 * temperature then don't bother computing a
3424 * calibrated temperature value */
3425 if (!change)
3426 return;
3427
3428 temp = iwl4965_get_temperature(priv);
3429 if (temp < 0) 1830 if (temp < 0)
3430 return; 1831 return;
3431 1832
@@ -3444,810 +1845,12 @@ void iwl4965_hw_rx_statistics(struct iwl_priv *priv, struct iwl4965_rx_mem_buffe
3444 priv->temperature = temp; 1845 priv->temperature = temp;
3445 set_bit(STATUS_TEMPERATURE, &priv->status); 1846 set_bit(STATUS_TEMPERATURE, &priv->status);
3446 1847
3447 if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)) && 1848 if (!priv->disable_tx_power_cal &&
3448 iwl4965_is_temp_calib_needed(priv)) 1849 unlikely(!test_bit(STATUS_SCANNING, &priv->status)) &&
1850 iwl4965_is_temp_calib_needed(priv))
3449 queue_work(priv->workqueue, &priv->txpower_work); 1851 queue_work(priv->workqueue, &priv->txpower_work);
3450} 1852}
3451 1853
3452static void iwl4965_add_radiotap(struct iwl_priv *priv,
3453 struct sk_buff *skb,
3454 struct iwl4965_rx_phy_res *rx_start,
3455 struct ieee80211_rx_status *stats,
3456 u32 ampdu_status)
3457{
3458 s8 signal = stats->ssi;
3459 s8 noise = 0;
3460 int rate = stats->rate_idx;
3461 u64 tsf = stats->mactime;
3462 __le16 antenna;
3463 __le16 phy_flags_hw = rx_start->phy_flags;
3464 struct iwl4965_rt_rx_hdr {
3465 struct ieee80211_radiotap_header rt_hdr;
3466 __le64 rt_tsf; /* TSF */
3467 u8 rt_flags; /* radiotap packet flags */
3468 u8 rt_rate; /* rate in 500kb/s */
3469 __le16 rt_channelMHz; /* channel in MHz */
3470 __le16 rt_chbitmask; /* channel bitfield */
3471 s8 rt_dbmsignal; /* signal in dBm, kluged to signed */
3472 s8 rt_dbmnoise;
3473 u8 rt_antenna; /* antenna number */
3474 } __attribute__ ((packed)) *iwl4965_rt;
3475
3476 /* TODO: We won't have enough headroom for HT frames. Fix it later. */
3477 if (skb_headroom(skb) < sizeof(*iwl4965_rt)) {
3478 if (net_ratelimit())
3479 printk(KERN_ERR "not enough headroom [%d] for "
3480 "radiotap head [%zd]\n",
3481 skb_headroom(skb), sizeof(*iwl4965_rt));
3482 return;
3483 }
3484
3485 /* put radiotap header in front of 802.11 header and data */
3486 iwl4965_rt = (void *)skb_push(skb, sizeof(*iwl4965_rt));
3487
3488 /* initialise radiotap header */
3489 iwl4965_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
3490 iwl4965_rt->rt_hdr.it_pad = 0;
3491
3492 /* total header + data */
3493 put_unaligned(cpu_to_le16(sizeof(*iwl4965_rt)),
3494 &iwl4965_rt->rt_hdr.it_len);
3495
3496 /* Indicate all the fields we add to the radiotap header */
3497 put_unaligned(cpu_to_le32((1 << IEEE80211_RADIOTAP_TSFT) |
3498 (1 << IEEE80211_RADIOTAP_FLAGS) |
3499 (1 << IEEE80211_RADIOTAP_RATE) |
3500 (1 << IEEE80211_RADIOTAP_CHANNEL) |
3501 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
3502 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
3503 (1 << IEEE80211_RADIOTAP_ANTENNA)),
3504 &iwl4965_rt->rt_hdr.it_present);
3505
3506 /* Zero the flags, we'll add to them as we go */
3507 iwl4965_rt->rt_flags = 0;
3508
3509 put_unaligned(cpu_to_le64(tsf), &iwl4965_rt->rt_tsf);
3510
3511 iwl4965_rt->rt_dbmsignal = signal;
3512 iwl4965_rt->rt_dbmnoise = noise;
3513
3514 /* Convert the channel frequency and set the flags */
3515 put_unaligned(cpu_to_le16(stats->freq), &iwl4965_rt->rt_channelMHz);
3516 if (!(phy_flags_hw & RX_RES_PHY_FLAGS_BAND_24_MSK))
3517 put_unaligned(cpu_to_le16(IEEE80211_CHAN_OFDM |
3518 IEEE80211_CHAN_5GHZ),
3519 &iwl4965_rt->rt_chbitmask);
3520 else if (phy_flags_hw & RX_RES_PHY_FLAGS_MOD_CCK_MSK)
3521 put_unaligned(cpu_to_le16(IEEE80211_CHAN_CCK |
3522 IEEE80211_CHAN_2GHZ),
3523 &iwl4965_rt->rt_chbitmask);
3524 else /* 802.11g */
3525 put_unaligned(cpu_to_le16(IEEE80211_CHAN_OFDM |
3526 IEEE80211_CHAN_2GHZ),
3527 &iwl4965_rt->rt_chbitmask);
3528
3529 if (rate == -1)
3530 iwl4965_rt->rt_rate = 0;
3531 else {
3532 if (stats->band == IEEE80211_BAND_5GHZ)
3533 rate += IWL_FIRST_OFDM_RATE;
3534
3535 iwl4965_rt->rt_rate = iwl4965_rates[rate].ieee;
3536 }
3537
3538 /*
3539 * "antenna number"
3540 *
3541 * It seems that the antenna field in the phy flags value
3542 * is actually a bitfield. This is undefined by radiotap,
3543 * it wants an actual antenna number but I always get "7"
3544 * for most legacy frames I receive indicating that the
3545 * same frame was received on all three RX chains.
3546 *
3547 * I think this field should be removed in favour of a
3548 * new 802.11n radiotap field "RX chains" that is defined
3549 * as a bitmask.
3550 */
3551 antenna = phy_flags_hw & RX_RES_PHY_FLAGS_ANTENNA_MSK;
3552 iwl4965_rt->rt_antenna = le16_to_cpu(antenna) >> 4;
3553
3554 /* set the preamble flag if appropriate */
3555 if (phy_flags_hw & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK)
3556 iwl4965_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
3557
3558 stats->flag |= RX_FLAG_RADIOTAP;
3559}
3560
3561static void iwl_update_rx_stats(struct iwl_priv *priv, u16 fc, u16 len)
3562{
3563 /* 0 - mgmt, 1 - cnt, 2 - data */
3564 int idx = (fc & IEEE80211_FCTL_FTYPE) >> 2;
3565 priv->rx_stats[idx].cnt++;
3566 priv->rx_stats[idx].bytes += len;
3567}
3568
3569static u32 iwl4965_translate_rx_status(u32 decrypt_in)
3570{
3571 u32 decrypt_out = 0;
3572
3573 if ((decrypt_in & RX_RES_STATUS_STATION_FOUND) ==
3574 RX_RES_STATUS_STATION_FOUND)
3575 decrypt_out |= (RX_RES_STATUS_STATION_FOUND |
3576 RX_RES_STATUS_NO_STATION_INFO_MISMATCH);
3577
3578 decrypt_out |= (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK);
3579
3580 /* packet was not encrypted */
3581 if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
3582 RX_RES_STATUS_SEC_TYPE_NONE)
3583 return decrypt_out;
3584
3585 /* packet was encrypted with unknown alg */
3586 if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
3587 RX_RES_STATUS_SEC_TYPE_ERR)
3588 return decrypt_out;
3589
3590 /* decryption was not done in HW */
3591 if ((decrypt_in & RX_MPDU_RES_STATUS_DEC_DONE_MSK) !=
3592 RX_MPDU_RES_STATUS_DEC_DONE_MSK)
3593 return decrypt_out;
3594
3595 switch (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) {
3596
3597 case RX_RES_STATUS_SEC_TYPE_CCMP:
3598 /* alg is CCM: check MIC only */
3599 if (!(decrypt_in & RX_MPDU_RES_STATUS_MIC_OK))
3600 /* Bad MIC */
3601 decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
3602 else
3603 decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
3604
3605 break;
3606
3607 case RX_RES_STATUS_SEC_TYPE_TKIP:
3608 if (!(decrypt_in & RX_MPDU_RES_STATUS_TTAK_OK)) {
3609 /* Bad TTAK */
3610 decrypt_out |= RX_RES_STATUS_BAD_KEY_TTAK;
3611 break;
3612 }
3613 /* fall through if TTAK OK */
3614 default:
3615 if (!(decrypt_in & RX_MPDU_RES_STATUS_ICV_OK))
3616 decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
3617 else
3618 decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
3619 break;
3620 };
3621
3622 IWL_DEBUG_RX("decrypt_in:0x%x decrypt_out = 0x%x\n",
3623 decrypt_in, decrypt_out);
3624
3625 return decrypt_out;
3626}
3627
3628static void iwl4965_handle_data_packet(struct iwl_priv *priv, int is_data,
3629 int include_phy,
3630 struct iwl4965_rx_mem_buffer *rxb,
3631 struct ieee80211_rx_status *stats)
3632{
3633 struct iwl4965_rx_packet *pkt = (struct iwl4965_rx_packet *)rxb->skb->data;
3634 struct iwl4965_rx_phy_res *rx_start = (include_phy) ?
3635 (struct iwl4965_rx_phy_res *)&(pkt->u.raw[0]) : NULL;
3636 struct ieee80211_hdr *hdr;
3637 u16 len;
3638 __le32 *rx_end;
3639 unsigned int skblen;
3640 u32 ampdu_status;
3641 u32 ampdu_status_legacy;
3642
3643 if (!include_phy && priv->last_phy_res[0])
3644 rx_start = (struct iwl4965_rx_phy_res *)&priv->last_phy_res[1];
3645
3646 if (!rx_start) {
3647 IWL_ERROR("MPDU frame without a PHY data\n");
3648 return;
3649 }
3650 if (include_phy) {
3651 hdr = (struct ieee80211_hdr *)((u8 *) & rx_start[1] +
3652 rx_start->cfg_phy_cnt);
3653
3654 len = le16_to_cpu(rx_start->byte_count);
3655
3656 rx_end = (__le32 *) ((u8 *) & pkt->u.raw[0] +
3657 sizeof(struct iwl4965_rx_phy_res) +
3658 rx_start->cfg_phy_cnt + len);
3659
3660 } else {
3661 struct iwl4965_rx_mpdu_res_start *amsdu =
3662 (struct iwl4965_rx_mpdu_res_start *)pkt->u.raw;
3663
3664 hdr = (struct ieee80211_hdr *)(pkt->u.raw +
3665 sizeof(struct iwl4965_rx_mpdu_res_start));
3666 len = le16_to_cpu(amsdu->byte_count);
3667 rx_start->byte_count = amsdu->byte_count;
3668 rx_end = (__le32 *) (((u8 *) hdr) + len);
3669 }
3670 if (len > priv->hw_params.max_pkt_size || len < 16) {
3671 IWL_WARNING("byte count out of range [16,4K] : %d\n", len);
3672 return;
3673 }
3674
3675 ampdu_status = le32_to_cpu(*rx_end);
3676 skblen = ((u8 *) rx_end - (u8 *) & pkt->u.raw[0]) + sizeof(u32);
3677
3678 if (!include_phy) {
3679 /* New status scheme, need to translate */
3680 ampdu_status_legacy = ampdu_status;
3681 ampdu_status = iwl4965_translate_rx_status(ampdu_status);
3682 }
3683
3684 /* start from MAC */
3685 skb_reserve(rxb->skb, (void *)hdr - (void *)pkt);
3686 skb_put(rxb->skb, len); /* end where data ends */
3687
3688 /* We only process data packets if the interface is open */
3689 if (unlikely(!priv->is_open)) {
3690 IWL_DEBUG_DROP_LIMIT
3691 ("Dropping packet while interface is not open.\n");
3692 return;
3693 }
3694
3695 stats->flag = 0;
3696 hdr = (struct ieee80211_hdr *)rxb->skb->data;
3697
3698 if (!priv->cfg->mod_params->sw_crypto)
3699 iwl4965_set_decrypted_flag(priv, rxb->skb, ampdu_status, stats);
3700
3701 if (priv->add_radiotap)
3702 iwl4965_add_radiotap(priv, rxb->skb, rx_start, stats, ampdu_status);
3703
3704 iwl_update_rx_stats(priv, le16_to_cpu(hdr->frame_control), len);
3705 ieee80211_rx_irqsafe(priv->hw, rxb->skb, stats);
3706 priv->alloc_rxb_skb--;
3707 rxb->skb = NULL;
3708}
3709
3710/* Calc max signal level (dBm) among 3 possible receivers */
3711static int iwl4965_calc_rssi(struct iwl4965_rx_phy_res *rx_resp)
3712{
3713 /* data from PHY/DSP regarding signal strength, etc.,
3714 * contents are always there, not configurable by host. */
3715 struct iwl4965_rx_non_cfg_phy *ncphy =
3716 (struct iwl4965_rx_non_cfg_phy *)rx_resp->non_cfg_phy;
3717 u32 agc = (le16_to_cpu(ncphy->agc_info) & IWL_AGC_DB_MASK)
3718 >> IWL_AGC_DB_POS;
3719
3720 u32 valid_antennae =
3721 (le16_to_cpu(rx_resp->phy_flags) & RX_PHY_FLAGS_ANTENNAE_MASK)
3722 >> RX_PHY_FLAGS_ANTENNAE_OFFSET;
3723 u8 max_rssi = 0;
3724 u32 i;
3725
3726 /* Find max rssi among 3 possible receivers.
3727 * These values are measured by the digital signal processor (DSP).
3728 * They should stay fairly constant even as the signal strength varies,
3729 * if the radio's automatic gain control (AGC) is working right.
3730 * AGC value (see below) will provide the "interesting" info. */
3731 for (i = 0; i < 3; i++)
3732 if (valid_antennae & (1 << i))
3733 max_rssi = max(ncphy->rssi_info[i << 1], max_rssi);
3734
3735 IWL_DEBUG_STATS("Rssi In A %d B %d C %d Max %d AGC dB %d\n",
3736 ncphy->rssi_info[0], ncphy->rssi_info[2], ncphy->rssi_info[4],
3737 max_rssi, agc);
3738
3739 /* dBm = max_rssi dB - agc dB - constant.
3740 * Higher AGC (higher radio gain) means lower signal. */
3741 return (max_rssi - agc - IWL_RSSI_OFFSET);
3742}
3743
3744#ifdef CONFIG_IWL4965_HT
3745
3746void iwl4965_init_ht_hw_capab(struct iwl_priv *priv,
3747 struct ieee80211_ht_info *ht_info,
3748 enum ieee80211_band band)
3749{
3750 ht_info->cap = 0;
3751 memset(ht_info->supp_mcs_set, 0, 16);
3752
3753 ht_info->ht_supported = 1;
3754
3755 if (band == IEEE80211_BAND_5GHZ) {
3756 ht_info->cap |= (u16)IEEE80211_HT_CAP_SUP_WIDTH;
3757 ht_info->cap |= (u16)IEEE80211_HT_CAP_SGI_40;
3758 ht_info->supp_mcs_set[4] = 0x01;
3759 }
3760 ht_info->cap |= (u16)IEEE80211_HT_CAP_GRN_FLD;
3761 ht_info->cap |= (u16)IEEE80211_HT_CAP_SGI_20;
3762 ht_info->cap |= (u16)(IEEE80211_HT_CAP_MIMO_PS &
3763 (IWL_MIMO_PS_NONE << 2));
3764
3765 if (priv->cfg->mod_params->amsdu_size_8K)
3766 ht_info->cap |= (u16)IEEE80211_HT_CAP_MAX_AMSDU;
3767
3768 ht_info->ampdu_factor = CFG_HT_RX_AMPDU_FACTOR_DEF;
3769 ht_info->ampdu_density = CFG_HT_MPDU_DENSITY_DEF;
3770
3771 ht_info->supp_mcs_set[0] = 0xFF;
3772 ht_info->supp_mcs_set[1] = 0xFF;
3773}
3774#endif /* CONFIG_IWL4965_HT */
3775
3776static void iwl4965_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id)
3777{
3778 unsigned long flags;
3779
3780 spin_lock_irqsave(&priv->sta_lock, flags);
3781 priv->stations[sta_id].sta.station_flags &= ~STA_FLG_PWR_SAVE_MSK;
3782 priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK;
3783 priv->stations[sta_id].sta.sta.modify_mask = 0;
3784 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
3785 spin_unlock_irqrestore(&priv->sta_lock, flags);
3786
3787 iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
3788}
3789
3790static void iwl4965_update_ps_mode(struct iwl_priv *priv, u16 ps_bit, u8 *addr)
3791{
3792 /* FIXME: need locking over ps_status ??? */
3793 u8 sta_id = iwl4965_hw_find_station(priv, addr);
3794
3795 if (sta_id != IWL_INVALID_STATION) {
3796 u8 sta_awake = priv->stations[sta_id].
3797 ps_status == STA_PS_STATUS_WAKE;
3798
3799 if (sta_awake && ps_bit)
3800 priv->stations[sta_id].ps_status = STA_PS_STATUS_SLEEP;
3801 else if (!sta_awake && !ps_bit) {
3802 iwl4965_sta_modify_ps_wake(priv, sta_id);
3803 priv->stations[sta_id].ps_status = STA_PS_STATUS_WAKE;
3804 }
3805 }
3806}
3807#ifdef CONFIG_IWLWIFI_DEBUG
3808
3809/**
3810 * iwl4965_dbg_report_frame - dump frame to syslog during debug sessions
3811 *
3812 * You may hack this function to show different aspects of received frames,
3813 * including selective frame dumps.
3814 * group100 parameter selects whether to show 1 out of 100 good frames.
3815 *
3816 * TODO: This was originally written for 3945, need to audit for
3817 * proper operation with 4965.
3818 */
3819static void iwl4965_dbg_report_frame(struct iwl_priv *priv,
3820 struct iwl4965_rx_packet *pkt,
3821 struct ieee80211_hdr *header, int group100)
3822{
3823 u32 to_us;
3824 u32 print_summary = 0;
3825 u32 print_dump = 0; /* set to 1 to dump all frames' contents */
3826 u32 hundred = 0;
3827 u32 dataframe = 0;
3828 u16 fc;
3829 u16 seq_ctl;
3830 u16 channel;
3831 u16 phy_flags;
3832 int rate_sym;
3833 u16 length;
3834 u16 status;
3835 u16 bcn_tmr;
3836 u32 tsf_low;
3837 u64 tsf;
3838 u8 rssi;
3839 u8 agc;
3840 u16 sig_avg;
3841 u16 noise_diff;
3842 struct iwl4965_rx_frame_stats *rx_stats = IWL_RX_STATS(pkt);
3843 struct iwl4965_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt);
3844 struct iwl4965_rx_frame_end *rx_end = IWL_RX_END(pkt);
3845 u8 *data = IWL_RX_DATA(pkt);
3846
3847 if (likely(!(iwl_debug_level & IWL_DL_RX)))
3848 return;
3849
3850 /* MAC header */
3851 fc = le16_to_cpu(header->frame_control);
3852 seq_ctl = le16_to_cpu(header->seq_ctrl);
3853
3854 /* metadata */
3855 channel = le16_to_cpu(rx_hdr->channel);
3856 phy_flags = le16_to_cpu(rx_hdr->phy_flags);
3857 rate_sym = rx_hdr->rate;
3858 length = le16_to_cpu(rx_hdr->len);
3859
3860 /* end-of-frame status and timestamp */
3861 status = le32_to_cpu(rx_end->status);
3862 bcn_tmr = le32_to_cpu(rx_end->beacon_timestamp);
3863 tsf_low = le64_to_cpu(rx_end->timestamp) & 0x0ffffffff;
3864 tsf = le64_to_cpu(rx_end->timestamp);
3865
3866 /* signal statistics */
3867 rssi = rx_stats->rssi;
3868 agc = rx_stats->agc;
3869 sig_avg = le16_to_cpu(rx_stats->sig_avg);
3870 noise_diff = le16_to_cpu(rx_stats->noise_diff);
3871
3872 to_us = !compare_ether_addr(header->addr1, priv->mac_addr);
3873
3874 /* if data frame is to us and all is good,
3875 * (optionally) print summary for only 1 out of every 100 */
3876 if (to_us && (fc & ~IEEE80211_FCTL_PROTECTED) ==
3877 (IEEE80211_FCTL_FROMDS | IEEE80211_FTYPE_DATA)) {
3878 dataframe = 1;
3879 if (!group100)
3880 print_summary = 1; /* print each frame */
3881 else if (priv->framecnt_to_us < 100) {
3882 priv->framecnt_to_us++;
3883 print_summary = 0;
3884 } else {
3885 priv->framecnt_to_us = 0;
3886 print_summary = 1;
3887 hundred = 1;
3888 }
3889 } else {
3890 /* print summary for all other frames */
3891 print_summary = 1;
3892 }
3893
3894 if (print_summary) {
3895 char *title;
3896 int rate_idx;
3897 u32 bitrate;
3898
3899 if (hundred)
3900 title = "100Frames";
3901 else if (fc & IEEE80211_FCTL_RETRY)
3902 title = "Retry";
3903 else if (ieee80211_is_assoc_response(fc))
3904 title = "AscRsp";
3905 else if (ieee80211_is_reassoc_response(fc))
3906 title = "RasRsp";
3907 else if (ieee80211_is_probe_response(fc)) {
3908 title = "PrbRsp";
3909 print_dump = 1; /* dump frame contents */
3910 } else if (ieee80211_is_beacon(fc)) {
3911 title = "Beacon";
3912 print_dump = 1; /* dump frame contents */
3913 } else if (ieee80211_is_atim(fc))
3914 title = "ATIM";
3915 else if (ieee80211_is_auth(fc))
3916 title = "Auth";
3917 else if (ieee80211_is_deauth(fc))
3918 title = "DeAuth";
3919 else if (ieee80211_is_disassoc(fc))
3920 title = "DisAssoc";
3921 else
3922 title = "Frame";
3923
3924 rate_idx = iwl4965_hwrate_to_plcp_idx(rate_sym);
3925 if (unlikely(rate_idx == -1))
3926 bitrate = 0;
3927 else
3928 bitrate = iwl4965_rates[rate_idx].ieee / 2;
3929
3930 /* print frame summary.
3931 * MAC addresses show just the last byte (for brevity),
3932 * but you can hack it to show more, if you'd like to. */
3933 if (dataframe)
3934 IWL_DEBUG_RX("%s: mhd=0x%04x, dst=0x%02x, "
3935 "len=%u, rssi=%d, chnl=%d, rate=%u, \n",
3936 title, fc, header->addr1[5],
3937 length, rssi, channel, bitrate);
3938 else {
3939 /* src/dst addresses assume managed mode */
3940 IWL_DEBUG_RX("%s: 0x%04x, dst=0x%02x, "
3941 "src=0x%02x, rssi=%u, tim=%lu usec, "
3942 "phy=0x%02x, chnl=%d\n",
3943 title, fc, header->addr1[5],
3944 header->addr3[5], rssi,
3945 tsf_low - priv->scan_start_tsf,
3946 phy_flags, channel);
3947 }
3948 }
3949 if (print_dump)
3950 iwl_print_hex_dump(IWL_DL_RX, data, length);
3951}
3952#else
3953static inline void iwl4965_dbg_report_frame(struct iwl_priv *priv,
3954 struct iwl4965_rx_packet *pkt,
3955 struct ieee80211_hdr *header,
3956 int group100)
3957{
3958}
3959#endif
3960
3961
3962
3963/* Called for REPLY_RX (legacy ABG frames), or
3964 * REPLY_RX_MPDU_CMD (HT high-throughput N frames). */
3965static void iwl4965_rx_reply_rx(struct iwl_priv *priv,
3966 struct iwl4965_rx_mem_buffer *rxb)
3967{
3968 struct ieee80211_hdr *header;
3969 struct ieee80211_rx_status rx_status;
3970 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3971 /* Use phy data (Rx signal strength, etc.) contained within
3972 * this rx packet for legacy frames,
3973 * or phy data cached from REPLY_RX_PHY_CMD for HT frames. */
3974 int include_phy = (pkt->hdr.cmd == REPLY_RX);
3975 struct iwl4965_rx_phy_res *rx_start = (include_phy) ?
3976 (struct iwl4965_rx_phy_res *)&(pkt->u.raw[0]) :
3977 (struct iwl4965_rx_phy_res *)&priv->last_phy_res[1];
3978 __le32 *rx_end;
3979 unsigned int len = 0;
3980 u16 fc;
3981 u8 network_packet;
3982
3983 rx_status.mactime = le64_to_cpu(rx_start->timestamp);
3984 rx_status.freq =
3985 ieee80211_channel_to_frequency(le16_to_cpu(rx_start->channel));
3986 rx_status.band = (rx_start->phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ?
3987 IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
3988 rx_status.rate_idx =
3989 iwl4965_hwrate_to_plcp_idx(le32_to_cpu(rx_start->rate_n_flags));
3990 if (rx_status.band == IEEE80211_BAND_5GHZ)
3991 rx_status.rate_idx -= IWL_FIRST_OFDM_RATE;
3992
3993 rx_status.antenna = 0;
3994 rx_status.flag = 0;
3995
3996 if ((unlikely(rx_start->cfg_phy_cnt > 20))) {
3997 IWL_DEBUG_DROP("dsp size out of range [0,20]: %d/n",
3998 rx_start->cfg_phy_cnt);
3999 return;
4000 }
4001
4002 if (!include_phy) {
4003 if (priv->last_phy_res[0])
4004 rx_start = (struct iwl4965_rx_phy_res *)
4005 &priv->last_phy_res[1];
4006 else
4007 rx_start = NULL;
4008 }
4009
4010 if (!rx_start) {
4011 IWL_ERROR("MPDU frame without a PHY data\n");
4012 return;
4013 }
4014
4015 if (include_phy) {
4016 header = (struct ieee80211_hdr *)((u8 *) & rx_start[1]
4017 + rx_start->cfg_phy_cnt);
4018
4019 len = le16_to_cpu(rx_start->byte_count);
4020 rx_end = (__le32 *)(pkt->u.raw + rx_start->cfg_phy_cnt +
4021 sizeof(struct iwl4965_rx_phy_res) + len);
4022 } else {
4023 struct iwl4965_rx_mpdu_res_start *amsdu =
4024 (struct iwl4965_rx_mpdu_res_start *)pkt->u.raw;
4025
4026 header = (void *)(pkt->u.raw +
4027 sizeof(struct iwl4965_rx_mpdu_res_start));
4028 len = le16_to_cpu(amsdu->byte_count);
4029 rx_end = (__le32 *) (pkt->u.raw +
4030 sizeof(struct iwl4965_rx_mpdu_res_start) + len);
4031 }
4032
4033 if (!(*rx_end & RX_RES_STATUS_NO_CRC32_ERROR) ||
4034 !(*rx_end & RX_RES_STATUS_NO_RXE_OVERFLOW)) {
4035 IWL_DEBUG_RX("Bad CRC or FIFO: 0x%08X.\n",
4036 le32_to_cpu(*rx_end));
4037 return;
4038 }
4039
4040 priv->ucode_beacon_time = le32_to_cpu(rx_start->beacon_time_stamp);
4041
4042 /* Find max signal strength (dBm) among 3 antenna/receiver chains */
4043 rx_status.ssi = iwl4965_calc_rssi(rx_start);
4044
4045 /* Meaningful noise values are available only from beacon statistics,
4046 * which are gathered only when associated, and indicate noise
4047 * only for the associated network channel ...
4048 * Ignore these noise values while scanning (other channels) */
4049 if (iwl_is_associated(priv) &&
4050 !test_bit(STATUS_SCANNING, &priv->status)) {
4051 rx_status.noise = priv->last_rx_noise;
4052 rx_status.signal = iwl4965_calc_sig_qual(rx_status.ssi,
4053 rx_status.noise);
4054 } else {
4055 rx_status.noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
4056 rx_status.signal = iwl4965_calc_sig_qual(rx_status.ssi, 0);
4057 }
4058
4059 /* Reset beacon noise level if not associated. */
4060 if (!iwl_is_associated(priv))
4061 priv->last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
4062
4063 /* Set "1" to report good data frames in groups of 100 */
4064 /* FIXME: need to optimze the call: */
4065 iwl4965_dbg_report_frame(priv, pkt, header, 1);
4066
4067 IWL_DEBUG_STATS_LIMIT("Rssi %d, noise %d, qual %d, TSF %llu\n",
4068 rx_status.ssi, rx_status.noise, rx_status.signal,
4069 (unsigned long long)rx_status.mactime);
4070
4071 network_packet = iwl4965_is_network_packet(priv, header);
4072 if (network_packet) {
4073 priv->last_rx_rssi = rx_status.ssi;
4074 priv->last_beacon_time = priv->ucode_beacon_time;
4075 priv->last_tsf = le64_to_cpu(rx_start->timestamp);
4076 }
4077
4078 fc = le16_to_cpu(header->frame_control);
4079 switch (fc & IEEE80211_FCTL_FTYPE) {
4080 case IEEE80211_FTYPE_MGMT:
4081 if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
4082 iwl4965_update_ps_mode(priv, fc & IEEE80211_FCTL_PM,
4083 header->addr2);
4084 iwl4965_handle_data_packet(priv, 0, include_phy, rxb, &rx_status);
4085 break;
4086
4087 case IEEE80211_FTYPE_CTL:
4088#ifdef CONFIG_IWL4965_HT
4089 switch (fc & IEEE80211_FCTL_STYPE) {
4090 case IEEE80211_STYPE_BACK_REQ:
4091 IWL_DEBUG_HT("IEEE80211_STYPE_BACK_REQ arrived\n");
4092 iwl4965_handle_data_packet(priv, 0, include_phy,
4093 rxb, &rx_status);
4094 break;
4095 default:
4096 break;
4097 }
4098#endif
4099 break;
4100
4101 case IEEE80211_FTYPE_DATA: {
4102 DECLARE_MAC_BUF(mac1);
4103 DECLARE_MAC_BUF(mac2);
4104 DECLARE_MAC_BUF(mac3);
4105
4106 if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
4107 iwl4965_update_ps_mode(priv, fc & IEEE80211_FCTL_PM,
4108 header->addr2);
4109
4110 if (unlikely(!network_packet))
4111 IWL_DEBUG_DROP("Dropping (non network): "
4112 "%s, %s, %s\n",
4113 print_mac(mac1, header->addr1),
4114 print_mac(mac2, header->addr2),
4115 print_mac(mac3, header->addr3));
4116 else if (unlikely(iwl4965_is_duplicate_packet(priv, header)))
4117 IWL_DEBUG_DROP("Dropping (dup): %s, %s, %s\n",
4118 print_mac(mac1, header->addr1),
4119 print_mac(mac2, header->addr2),
4120 print_mac(mac3, header->addr3));
4121 else
4122 iwl4965_handle_data_packet(priv, 1, include_phy, rxb,
4123 &rx_status);
4124 break;
4125 }
4126 default:
4127 break;
4128
4129 }
4130}
4131
4132/* Cache phy data (Rx signal strength, etc) for HT frame (REPLY_RX_PHY_CMD).
4133 * This will be used later in iwl4965_rx_reply_rx() for REPLY_RX_MPDU_CMD. */
4134static void iwl4965_rx_reply_rx_phy(struct iwl_priv *priv,
4135 struct iwl4965_rx_mem_buffer *rxb)
4136{
4137 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
4138 priv->last_phy_res[0] = 1;
4139 memcpy(&priv->last_phy_res[1], &(pkt->u.raw[0]),
4140 sizeof(struct iwl4965_rx_phy_res));
4141}
4142static void iwl4965_rx_missed_beacon_notif(struct iwl_priv *priv,
4143 struct iwl4965_rx_mem_buffer *rxb)
4144
4145{
4146#ifdef CONFIG_IWL4965_SENSITIVITY
4147 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
4148 struct iwl4965_missed_beacon_notif *missed_beacon;
4149
4150 missed_beacon = &pkt->u.missed_beacon;
4151 if (le32_to_cpu(missed_beacon->consequtive_missed_beacons) > 5) {
4152 IWL_DEBUG_CALIB("missed bcn cnsq %d totl %d rcd %d expctd %d\n",
4153 le32_to_cpu(missed_beacon->consequtive_missed_beacons),
4154 le32_to_cpu(missed_beacon->total_missed_becons),
4155 le32_to_cpu(missed_beacon->num_recvd_beacons),
4156 le32_to_cpu(missed_beacon->num_expected_beacons));
4157 priv->sensitivity_data.state = IWL_SENS_CALIB_NEED_REINIT;
4158 if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)))
4159 queue_work(priv->workqueue, &priv->sensitivity_work);
4160 }
4161#endif /*CONFIG_IWL4965_SENSITIVITY*/
4162}
4163#ifdef CONFIG_IWL4965_HT
4164
4165/**
4166 * iwl4965_sta_modify_enable_tid_tx - Enable Tx for this TID in station table
4167 */
4168static void iwl4965_sta_modify_enable_tid_tx(struct iwl_priv *priv,
4169 int sta_id, int tid)
4170{
4171 unsigned long flags;
4172
4173 /* Remove "disable" flag, to enable Tx for this TID */
4174 spin_lock_irqsave(&priv->sta_lock, flags);
4175 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_TID_DISABLE_TX;
4176 priv->stations[sta_id].sta.tid_disable_tx &= cpu_to_le16(~(1 << tid));
4177 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
4178 spin_unlock_irqrestore(&priv->sta_lock, flags);
4179
4180 iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
4181}
4182
4183/**
4184 * iwl4965_tx_status_reply_compressed_ba - Update tx status from block-ack
4185 *
4186 * Go through block-ack's bitmap of ACK'd frames, update driver's record of
4187 * ACK vs. not. This gets sent to mac80211, then to rate scaling algo.
4188 */
4189static int iwl4965_tx_status_reply_compressed_ba(struct iwl_priv *priv,
4190 struct iwl4965_ht_agg *agg,
4191 struct iwl4965_compressed_ba_resp*
4192 ba_resp)
4193
4194{
4195 int i, sh, ack;
4196 u16 seq_ctl = le16_to_cpu(ba_resp->seq_ctl);
4197 u16 scd_flow = le16_to_cpu(ba_resp->scd_flow);
4198 u64 bitmap;
4199 int successes = 0;
4200 struct ieee80211_tx_status *tx_status;
4201
4202 if (unlikely(!agg->wait_for_ba)) {
4203 IWL_ERROR("Received BA when not expected\n");
4204 return -EINVAL;
4205 }
4206
4207 /* Mark that the expected block-ack response arrived */
4208 agg->wait_for_ba = 0;
4209 IWL_DEBUG_TX_REPLY("BA %d %d\n", agg->start_idx, ba_resp->seq_ctl);
4210
4211 /* Calculate shift to align block-ack bits with our Tx window bits */
4212 sh = agg->start_idx - SEQ_TO_INDEX(seq_ctl>>4);
4213 if (sh < 0) /* tbw something is wrong with indices */
4214 sh += 0x100;
4215
4216 /* don't use 64-bit values for now */
4217 bitmap = le64_to_cpu(ba_resp->bitmap) >> sh;
4218
4219 if (agg->frame_count > (64 - sh)) {
4220 IWL_DEBUG_TX_REPLY("more frames than bitmap size");
4221 return -1;
4222 }
4223
4224 /* check for success or failure according to the
4225 * transmitted bitmap and block-ack bitmap */
4226 bitmap &= agg->bitmap;
4227
4228 /* For each frame attempted in aggregation,
4229 * update driver's record of tx frame's status. */
4230 for (i = 0; i < agg->frame_count ; i++) {
4231 ack = bitmap & (1 << i);
4232 successes += !!ack;
4233 IWL_DEBUG_TX_REPLY("%s ON i=%d idx=%d raw=%d\n",
4234 ack? "ACK":"NACK", i, (agg->start_idx + i) & 0xff,
4235 agg->start_idx + i);
4236 }
4237
4238 tx_status = &priv->txq[scd_flow].txb[agg->start_idx].status;
4239 tx_status->flags = IEEE80211_TX_STATUS_ACK;
4240 tx_status->flags |= IEEE80211_TX_STATUS_AMPDU;
4241 tx_status->ampdu_ack_map = successes;
4242 tx_status->ampdu_ack_len = agg->frame_count;
4243 iwl4965_hwrate_to_tx_control(priv, agg->rate_n_flags,
4244 &tx_status->control);
4245
4246 IWL_DEBUG_TX_REPLY("Bitmap %llx\n", (unsigned long long)bitmap);
4247
4248 return 0;
4249}
4250
4251/** 1854/**
4252 * iwl4965_tx_queue_stop_scheduler - Stop queue, but keep configuration 1855 * iwl4965_tx_queue_stop_scheduler - Stop queue, but keep configuration
4253 */ 1856 */
@@ -4258,22 +1861,24 @@ static void iwl4965_tx_queue_stop_scheduler(struct iwl_priv *priv,
4258 * the SCD_ACT_EN bit is the write-enable mask for the ACTIVE bit. */ 1861 * the SCD_ACT_EN bit is the write-enable mask for the ACTIVE bit. */
4259 iwl_write_prph(priv, 1862 iwl_write_prph(priv,
4260 IWL49_SCD_QUEUE_STATUS_BITS(txq_id), 1863 IWL49_SCD_QUEUE_STATUS_BITS(txq_id),
4261 (0 << SCD_QUEUE_STTS_REG_POS_ACTIVE)| 1864 (0 << IWL49_SCD_QUEUE_STTS_REG_POS_ACTIVE)|
4262 (1 << SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN)); 1865 (1 << IWL49_SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN));
4263} 1866}
4264 1867
4265/** 1868/**
4266 * txq_id must be greater than IWL_BACK_QUEUE_FIRST_ID 1869 * txq_id must be greater than IWL49_FIRST_AMPDU_QUEUE
4267 * priv->lock must be held by the caller 1870 * priv->lock must be held by the caller
4268 */ 1871 */
4269static int iwl4965_tx_queue_agg_disable(struct iwl_priv *priv, u16 txq_id, 1872static int iwl4965_txq_agg_disable(struct iwl_priv *priv, u16 txq_id,
4270 u16 ssn_idx, u8 tx_fifo) 1873 u16 ssn_idx, u8 tx_fifo)
4271{ 1874{
4272 int ret = 0; 1875 int ret = 0;
4273 1876
4274 if (IWL_BACK_QUEUE_FIRST_ID > txq_id) { 1877 if ((IWL49_FIRST_AMPDU_QUEUE > txq_id) ||
4275 IWL_WARNING("queue number too small: %d, must be > %d\n", 1878 (IWL49_FIRST_AMPDU_QUEUE + IWL49_NUM_AMPDU_QUEUES <= txq_id)) {
4276 txq_id, IWL_BACK_QUEUE_FIRST_ID); 1879 IWL_WARNING("queue number out of range: %d, must be %d to %d\n",
1880 txq_id, IWL49_FIRST_AMPDU_QUEUE,
1881 IWL49_FIRST_AMPDU_QUEUE + IWL49_NUM_AMPDU_QUEUES - 1);
4277 return -EINVAL; 1882 return -EINVAL;
4278 } 1883 }
4279 1884
@@ -4291,7 +1896,7 @@ static int iwl4965_tx_queue_agg_disable(struct iwl_priv *priv, u16 txq_id,
4291 iwl4965_set_wr_ptrs(priv, txq_id, ssn_idx); 1896 iwl4965_set_wr_ptrs(priv, txq_id, ssn_idx);
4292 1897
4293 iwl_clear_bits_prph(priv, IWL49_SCD_INTERRUPT_MASK, (1 << txq_id)); 1898 iwl_clear_bits_prph(priv, IWL49_SCD_INTERRUPT_MASK, (1 << txq_id));
4294 iwl4965_txq_ctx_deactivate(priv, txq_id); 1899 iwl_txq_ctx_deactivate(priv, txq_id);
4295 iwl4965_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 0); 1900 iwl4965_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 0);
4296 1901
4297 iwl_release_nic_access(priv); 1902 iwl_release_nic_access(priv);
@@ -4299,121 +1904,6 @@ static int iwl4965_tx_queue_agg_disable(struct iwl_priv *priv, u16 txq_id,
4299 return 0; 1904 return 0;
4300} 1905}
4301 1906
4302int iwl4965_check_empty_hw_queue(struct iwl_priv *priv, int sta_id,
4303 u8 tid, int txq_id)
4304{
4305 struct iwl4965_queue *q = &priv->txq[txq_id].q;
4306 u8 *addr = priv->stations[sta_id].sta.sta.addr;
4307 struct iwl4965_tid_data *tid_data = &priv->stations[sta_id].tid[tid];
4308
4309 switch (priv->stations[sta_id].tid[tid].agg.state) {
4310 case IWL_EMPTYING_HW_QUEUE_DELBA:
4311 /* We are reclaiming the last packet of the */
4312 /* aggregated HW queue */
4313 if (txq_id == tid_data->agg.txq_id &&
4314 q->read_ptr == q->write_ptr) {
4315 u16 ssn = SEQ_TO_SN(tid_data->seq_number);
4316 int tx_fifo = default_tid_to_tx_fifo[tid];
4317 IWL_DEBUG_HT("HW queue empty: continue DELBA flow\n");
4318 iwl4965_tx_queue_agg_disable(priv, txq_id,
4319 ssn, tx_fifo);
4320 tid_data->agg.state = IWL_AGG_OFF;
4321 ieee80211_stop_tx_ba_cb_irqsafe(priv->hw, addr, tid);
4322 }
4323 break;
4324 case IWL_EMPTYING_HW_QUEUE_ADDBA:
4325 /* We are reclaiming the last packet of the queue */
4326 if (tid_data->tfds_in_queue == 0) {
4327 IWL_DEBUG_HT("HW queue empty: continue ADDBA flow\n");
4328 tid_data->agg.state = IWL_AGG_ON;
4329 ieee80211_start_tx_ba_cb_irqsafe(priv->hw, addr, tid);
4330 }
4331 break;
4332 }
4333 return 0;
4334}
4335
4336/**
4337 * iwl4965_queue_dec_wrap - Decrement queue index, wrap back to end if needed
4338 * @index -- current index
4339 * @n_bd -- total number of entries in queue (s/b power of 2)
4340 */
4341static inline int iwl4965_queue_dec_wrap(int index, int n_bd)
4342{
4343 return (index == 0) ? n_bd - 1 : index - 1;
4344}
4345
4346/**
4347 * iwl4965_rx_reply_compressed_ba - Handler for REPLY_COMPRESSED_BA
4348 *
4349 * Handles block-acknowledge notification from device, which reports success
4350 * of frames sent via aggregation.
4351 */
4352static void iwl4965_rx_reply_compressed_ba(struct iwl_priv *priv,
4353 struct iwl4965_rx_mem_buffer *rxb)
4354{
4355 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
4356 struct iwl4965_compressed_ba_resp *ba_resp = &pkt->u.compressed_ba;
4357 int index;
4358 struct iwl4965_tx_queue *txq = NULL;
4359 struct iwl4965_ht_agg *agg;
4360 DECLARE_MAC_BUF(mac);
4361
4362 /* "flow" corresponds to Tx queue */
4363 u16 scd_flow = le16_to_cpu(ba_resp->scd_flow);
4364
4365 /* "ssn" is start of block-ack Tx window, corresponds to index
4366 * (in Tx queue's circular buffer) of first TFD/frame in window */
4367 u16 ba_resp_scd_ssn = le16_to_cpu(ba_resp->scd_ssn);
4368
4369 if (scd_flow >= priv->hw_params.max_txq_num) {
4370 IWL_ERROR("BUG_ON scd_flow is bigger than number of queues");
4371 return;
4372 }
4373
4374 txq = &priv->txq[scd_flow];
4375 agg = &priv->stations[ba_resp->sta_id].tid[ba_resp->tid].agg;
4376
4377 /* Find index just before block-ack window */
4378 index = iwl4965_queue_dec_wrap(ba_resp_scd_ssn & 0xff, txq->q.n_bd);
4379
4380 /* TODO: Need to get this copy more safely - now good for debug */
4381
4382 IWL_DEBUG_TX_REPLY("REPLY_COMPRESSED_BA [%d]Received from %s, "
4383 "sta_id = %d\n",
4384 agg->wait_for_ba,
4385 print_mac(mac, (u8*) &ba_resp->sta_addr_lo32),
4386 ba_resp->sta_id);
4387 IWL_DEBUG_TX_REPLY("TID = %d, SeqCtl = %d, bitmap = 0x%llx, scd_flow = "
4388 "%d, scd_ssn = %d\n",
4389 ba_resp->tid,
4390 ba_resp->seq_ctl,
4391 (unsigned long long)le64_to_cpu(ba_resp->bitmap),
4392 ba_resp->scd_flow,
4393 ba_resp->scd_ssn);
4394 IWL_DEBUG_TX_REPLY("DAT start_idx = %d, bitmap = 0x%llx \n",
4395 agg->start_idx,
4396 (unsigned long long)agg->bitmap);
4397
4398 /* Update driver's record of ACK vs. not for each frame in window */
4399 iwl4965_tx_status_reply_compressed_ba(priv, agg, ba_resp);
4400
4401 /* Release all TFDs before the SSN, i.e. all TFDs in front of
4402 * block-ack window (we assume that they've been successfully
4403 * transmitted ... if not, it's too late anyway). */
4404 if (txq->q.read_ptr != (ba_resp_scd_ssn & 0xff)) {
4405 int freed = iwl4965_tx_queue_reclaim(priv, scd_flow, index);
4406 priv->stations[ba_resp->sta_id].
4407 tid[ba_resp->tid].tfds_in_queue -= freed;
4408 if (iwl4965_queue_space(&txq->q) > txq->q.low_mark &&
4409 priv->mac80211_registered &&
4410 agg->state != IWL_EMPTYING_HW_QUEUE_DELBA)
4411 ieee80211_wake_queue(priv->hw, scd_flow);
4412 iwl4965_check_empty_hw_queue(priv, ba_resp->sta_id,
4413 ba_resp->tid, scd_flow);
4414 }
4415}
4416
4417/** 1907/**
4418 * iwl4965_tx_queue_set_q2ratid - Map unique receiver/tid combination to a queue 1908 * iwl4965_tx_queue_set_q2ratid - Map unique receiver/tid combination to a queue
4419 */ 1909 */
@@ -4424,10 +1914,10 @@ static int iwl4965_tx_queue_set_q2ratid(struct iwl_priv *priv, u16 ra_tid,
4424 u32 tbl_dw; 1914 u32 tbl_dw;
4425 u16 scd_q2ratid; 1915 u16 scd_q2ratid;
4426 1916
4427 scd_q2ratid = ra_tid & SCD_QUEUE_RA_TID_MAP_RATID_MSK; 1917 scd_q2ratid = ra_tid & IWL_SCD_QUEUE_RA_TID_MAP_RATID_MSK;
4428 1918
4429 tbl_dw_addr = priv->scd_base_addr + 1919 tbl_dw_addr = priv->scd_base_addr +
4430 SCD_TRANSLATE_TBL_OFFSET_QUEUE(txq_id); 1920 IWL49_SCD_TRANSLATE_TBL_OFFSET_QUEUE(txq_id);
4431 1921
4432 tbl_dw = iwl_read_targ_mem(priv, tbl_dw_addr); 1922 tbl_dw = iwl_read_targ_mem(priv, tbl_dw_addr);
4433 1923
@@ -4445,31 +1935,34 @@ static int iwl4965_tx_queue_set_q2ratid(struct iwl_priv *priv, u16 ra_tid,
4445/** 1935/**
4446 * iwl4965_tx_queue_agg_enable - Set up & enable aggregation for selected queue 1936 * iwl4965_tx_queue_agg_enable - Set up & enable aggregation for selected queue
4447 * 1937 *
4448 * NOTE: txq_id must be greater than IWL_BACK_QUEUE_FIRST_ID, 1938 * NOTE: txq_id must be greater than IWL49_FIRST_AMPDU_QUEUE,
4449 * i.e. it must be one of the higher queues used for aggregation 1939 * i.e. it must be one of the higher queues used for aggregation
4450 */ 1940 */
4451static int iwl4965_tx_queue_agg_enable(struct iwl_priv *priv, int txq_id, 1941static int iwl4965_txq_agg_enable(struct iwl_priv *priv, int txq_id,
4452 int tx_fifo, int sta_id, int tid, 1942 int tx_fifo, int sta_id, int tid, u16 ssn_idx)
4453 u16 ssn_idx)
4454{ 1943{
4455 unsigned long flags; 1944 unsigned long flags;
4456 int rc; 1945 int ret;
4457 u16 ra_tid; 1946 u16 ra_tid;
4458 1947
4459 if (IWL_BACK_QUEUE_FIRST_ID > txq_id) 1948 if ((IWL49_FIRST_AMPDU_QUEUE > txq_id) ||
4460 IWL_WARNING("queue number too small: %d, must be > %d\n", 1949 (IWL49_FIRST_AMPDU_QUEUE + IWL49_NUM_AMPDU_QUEUES <= txq_id)) {
4461 txq_id, IWL_BACK_QUEUE_FIRST_ID); 1950 IWL_WARNING("queue number out of range: %d, must be %d to %d\n",
1951 txq_id, IWL49_FIRST_AMPDU_QUEUE,
1952 IWL49_FIRST_AMPDU_QUEUE + IWL49_NUM_AMPDU_QUEUES - 1);
1953 return -EINVAL;
1954 }
4462 1955
4463 ra_tid = BUILD_RAxTID(sta_id, tid); 1956 ra_tid = BUILD_RAxTID(sta_id, tid);
4464 1957
4465 /* Modify device's station table to Tx this TID */ 1958 /* Modify device's station table to Tx this TID */
4466 iwl4965_sta_modify_enable_tid_tx(priv, sta_id, tid); 1959 iwl_sta_modify_enable_tid_tx(priv, sta_id, tid);
4467 1960
4468 spin_lock_irqsave(&priv->lock, flags); 1961 spin_lock_irqsave(&priv->lock, flags);
4469 rc = iwl_grab_nic_access(priv); 1962 ret = iwl_grab_nic_access(priv);
4470 if (rc) { 1963 if (ret) {
4471 spin_unlock_irqrestore(&priv->lock, flags); 1964 spin_unlock_irqrestore(&priv->lock, flags);
4472 return rc; 1965 return ret;
4473 } 1966 }
4474 1967
4475 /* Stop this Tx queue before configuring it */ 1968 /* Stop this Tx queue before configuring it */
@@ -4489,14 +1982,14 @@ static int iwl4965_tx_queue_agg_enable(struct iwl_priv *priv, int txq_id,
4489 1982
4490 /* Set up Tx window size and frame limit for this queue */ 1983 /* Set up Tx window size and frame limit for this queue */
4491 iwl_write_targ_mem(priv, 1984 iwl_write_targ_mem(priv,
4492 priv->scd_base_addr + SCD_CONTEXT_QUEUE_OFFSET(txq_id), 1985 priv->scd_base_addr + IWL49_SCD_CONTEXT_QUEUE_OFFSET(txq_id),
4493 (SCD_WIN_SIZE << SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) & 1986 (SCD_WIN_SIZE << IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) &
4494 SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK); 1987 IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK);
4495 1988
4496 iwl_write_targ_mem(priv, priv->scd_base_addr + 1989 iwl_write_targ_mem(priv, priv->scd_base_addr +
4497 SCD_CONTEXT_QUEUE_OFFSET(txq_id) + sizeof(u32), 1990 IWL49_SCD_CONTEXT_QUEUE_OFFSET(txq_id) + sizeof(u32),
4498 (SCD_FRAME_LIMIT << SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) 1991 (SCD_FRAME_LIMIT << IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS)
4499 & SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK); 1992 & IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK);
4500 1993
4501 iwl_set_bits_prph(priv, IWL49_SCD_INTERRUPT_MASK, (1 << txq_id)); 1994 iwl_set_bits_prph(priv, IWL49_SCD_INTERRUPT_MASK, (1 << txq_id));
4502 1995
@@ -4509,444 +2002,314 @@ static int iwl4965_tx_queue_agg_enable(struct iwl_priv *priv, int txq_id,
4509 return 0; 2002 return 0;
4510} 2003}
4511 2004
4512#endif /* CONFIG_IWL4965_HT */
4513 2005
4514/** 2006static u16 iwl4965_get_hcmd_size(u8 cmd_id, u16 len)
4515 * iwl4965_add_station - Initialize a station's hardware rate table
4516 *
4517 * The uCode's station table contains a table of fallback rates
4518 * for automatic fallback during transmission.
4519 *
4520 * NOTE: This sets up a default set of values. These will be replaced later
4521 * if the driver's iwl-4965-rs rate scaling algorithm is used, instead of
4522 * rc80211_simple.
4523 *
4524 * NOTE: Run REPLY_ADD_STA command to set up station table entry, before
4525 * calling this function (which runs REPLY_TX_LINK_QUALITY_CMD,
4526 * which requires station table entry to exist).
4527 */
4528void iwl4965_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
4529{ 2007{
4530 int i, r; 2008 switch (cmd_id) {
4531 struct iwl_link_quality_cmd link_cmd = { 2009 case REPLY_RXON:
4532 .reserved1 = 0, 2010 return (u16) sizeof(struct iwl4965_rxon_cmd);
4533 }; 2011 default:
4534 u16 rate_flags; 2012 return len;
4535
4536 /* Set up the rate scaling to start at selected rate, fall back
4537 * all the way down to 1M in IEEE order, and then spin on 1M */
4538 if (is_ap)
4539 r = IWL_RATE_54M_INDEX;
4540 else if (priv->band == IEEE80211_BAND_5GHZ)
4541 r = IWL_RATE_6M_INDEX;
4542 else
4543 r = IWL_RATE_1M_INDEX;
4544
4545 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
4546 rate_flags = 0;
4547 if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE)
4548 rate_flags |= RATE_MCS_CCK_MSK;
4549
4550 /* Use Tx antenna B only */
4551 rate_flags |= RATE_MCS_ANT_B_MSK;
4552 rate_flags &= ~RATE_MCS_ANT_A_MSK;
4553
4554 link_cmd.rs_table[i].rate_n_flags =
4555 iwl4965_hw_set_rate_n_flags(iwl4965_rates[r].plcp, rate_flags);
4556 r = iwl4965_get_prev_ieee_rate(r);
4557 } 2013 }
4558
4559 link_cmd.general_params.single_stream_ant_msk = 2;
4560 link_cmd.general_params.dual_stream_ant_msk = 3;
4561 link_cmd.agg_params.agg_dis_start_th = 3;
4562 link_cmd.agg_params.agg_time_limit = cpu_to_le16(4000);
4563
4564 /* Update the rate scaling for control frame Tx to AP */
4565 link_cmd.sta_id = is_ap ? IWL_AP_ID : priv->hw_params.bcast_sta_id;
4566
4567 iwl_send_cmd_pdu_async(priv, REPLY_TX_LINK_QUALITY_CMD,
4568 sizeof(link_cmd), &link_cmd, NULL);
4569}
4570
4571#ifdef CONFIG_IWL4965_HT
4572
4573static u8 iwl4965_is_channel_extension(struct iwl_priv *priv,
4574 enum ieee80211_band band,
4575 u16 channel, u8 extension_chan_offset)
4576{
4577 const struct iwl_channel_info *ch_info;
4578
4579 ch_info = iwl_get_channel_info(priv, band, channel);
4580 if (!is_channel_valid(ch_info))
4581 return 0;
4582
4583 if (extension_chan_offset == IWL_EXT_CHANNEL_OFFSET_NONE)
4584 return 0;
4585
4586 if ((ch_info->fat_extension_channel == extension_chan_offset) ||
4587 (ch_info->fat_extension_channel == HT_IE_EXT_CHANNEL_MAX))
4588 return 1;
4589
4590 return 0;
4591} 2014}
4592 2015
4593static u8 iwl4965_is_fat_tx_allowed(struct iwl_priv *priv, 2016static u16 iwl4965_build_addsta_hcmd(const struct iwl_addsta_cmd *cmd, u8 *data)
4594 struct ieee80211_ht_info *sta_ht_inf)
4595{ 2017{
4596 struct iwl_ht_info *iwl_ht_conf = &priv->current_ht_config; 2018 struct iwl4965_addsta_cmd *addsta = (struct iwl4965_addsta_cmd *)data;
4597 2019 addsta->mode = cmd->mode;
4598 if ((!iwl_ht_conf->is_ht) || 2020 memcpy(&addsta->sta, &cmd->sta, sizeof(struct sta_id_modify));
4599 (iwl_ht_conf->supported_chan_width != IWL_CHANNEL_WIDTH_40MHZ) || 2021 memcpy(&addsta->key, &cmd->key, sizeof(struct iwl4965_keyinfo));
4600 (iwl_ht_conf->extension_chan_offset == IWL_EXT_CHANNEL_OFFSET_NONE)) 2022 addsta->station_flags = cmd->station_flags;
4601 return 0; 2023 addsta->station_flags_msk = cmd->station_flags_msk;
2024 addsta->tid_disable_tx = cmd->tid_disable_tx;
2025 addsta->add_immediate_ba_tid = cmd->add_immediate_ba_tid;
2026 addsta->remove_immediate_ba_tid = cmd->remove_immediate_ba_tid;
2027 addsta->add_immediate_ba_ssn = cmd->add_immediate_ba_ssn;
2028 addsta->reserved1 = __constant_cpu_to_le16(0);
2029 addsta->reserved2 = __constant_cpu_to_le32(0);
4602 2030
4603 if (sta_ht_inf) { 2031 return (u16)sizeof(struct iwl4965_addsta_cmd);
4604 if ((!sta_ht_inf->ht_supported) ||
4605 (!(sta_ht_inf->cap & IEEE80211_HT_CAP_SUP_WIDTH)))
4606 return 0;
4607 }
4608
4609 return (iwl4965_is_channel_extension(priv, priv->band,
4610 iwl_ht_conf->control_channel,
4611 iwl_ht_conf->extension_chan_offset));
4612} 2032}
4613 2033
4614void iwl4965_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_info *ht_info) 2034static inline u32 iwl4965_get_scd_ssn(struct iwl4965_tx_resp *tx_resp)
4615{ 2035{
4616 struct iwl4965_rxon_cmd *rxon = &priv->staging_rxon; 2036 return le32_to_cpup(&tx_resp->u.status + tx_resp->frame_count) & MAX_SN;
4617 u32 val;
4618
4619 if (!ht_info->is_ht)
4620 return;
4621
4622 /* Set up channel bandwidth: 20 MHz only, or 20/40 mixed if fat ok */
4623 if (iwl4965_is_fat_tx_allowed(priv, NULL))
4624 rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED_MSK;
4625 else
4626 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK |
4627 RXON_FLG_CHANNEL_MODE_PURE_40_MSK);
4628
4629 if (le16_to_cpu(rxon->channel) != ht_info->control_channel) {
4630 IWL_DEBUG_ASSOC("control diff than current %d %d\n",
4631 le16_to_cpu(rxon->channel),
4632 ht_info->control_channel);
4633 rxon->channel = cpu_to_le16(ht_info->control_channel);
4634 return;
4635 }
4636
4637 /* Note: control channel is opposite of extension channel */
4638 switch (ht_info->extension_chan_offset) {
4639 case IWL_EXT_CHANNEL_OFFSET_ABOVE:
4640 rxon->flags &= ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
4641 break;
4642 case IWL_EXT_CHANNEL_OFFSET_BELOW:
4643 rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
4644 break;
4645 case IWL_EXT_CHANNEL_OFFSET_NONE:
4646 default:
4647 rxon->flags &= ~RXON_FLG_CHANNEL_MODE_MIXED_MSK;
4648 break;
4649 }
4650
4651 val = ht_info->ht_protection;
4652
4653 rxon->flags |= cpu_to_le32(val << RXON_FLG_HT_OPERATING_MODE_POS);
4654
4655 iwl4965_set_rxon_chain(priv);
4656
4657 IWL_DEBUG_ASSOC("supported HT rate 0x%X %X "
4658 "rxon flags 0x%X operation mode :0x%X "
4659 "extension channel offset 0x%x "
4660 "control chan %d\n",
4661 ht_info->supp_mcs_set[0], ht_info->supp_mcs_set[1],
4662 le32_to_cpu(rxon->flags), ht_info->ht_protection,
4663 ht_info->extension_chan_offset,
4664 ht_info->control_channel);
4665 return;
4666} 2037}
4667 2038
4668void iwl4965_set_ht_add_station(struct iwl_priv *priv, u8 index, 2039/**
4669 struct ieee80211_ht_info *sta_ht_inf) 2040 * iwl4965_tx_status_reply_tx - Handle Tx rspnse for frames in aggregation queue
2041 */
2042static int iwl4965_tx_status_reply_tx(struct iwl_priv *priv,
2043 struct iwl_ht_agg *agg,
2044 struct iwl4965_tx_resp *tx_resp,
2045 int txq_id, u16 start_idx)
4670{ 2046{
4671 __le32 sta_flags; 2047 u16 status;
4672 u8 mimo_ps_mode; 2048 struct agg_tx_status *frame_status = tx_resp->u.agg_status;
4673 2049 struct ieee80211_tx_info *info = NULL;
4674 if (!sta_ht_inf || !sta_ht_inf->ht_supported) 2050 struct ieee80211_hdr *hdr = NULL;
4675 goto done; 2051 u32 rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
4676 2052 int i, sh, idx;
4677 mimo_ps_mode = (sta_ht_inf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2; 2053 u16 seq;
2054 if (agg->wait_for_ba)
2055 IWL_DEBUG_TX_REPLY("got tx response w/o block-ack\n");
2056
2057 agg->frame_count = tx_resp->frame_count;
2058 agg->start_idx = start_idx;
2059 agg->rate_n_flags = rate_n_flags;
2060 agg->bitmap = 0;
2061
2062 /* # frames attempted by Tx command */
2063 if (agg->frame_count == 1) {
2064 /* Only one frame was attempted; no block-ack will arrive */
2065 status = le16_to_cpu(frame_status[0].status);
2066 idx = start_idx;
2067
2068 /* FIXME: code repetition */
2069 IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d idx=%d\n",
2070 agg->frame_count, agg->start_idx, idx);
2071
2072 info = IEEE80211_SKB_CB(priv->txq[txq_id].txb[idx].skb[0]);
2073 info->status.retry_count = tx_resp->failure_frame;
2074 info->flags &= ~IEEE80211_TX_CTL_AMPDU;
2075 info->flags |= iwl_is_tx_success(status)?
2076 IEEE80211_TX_STAT_ACK : 0;
2077 iwl_hwrate_to_tx_control(priv, rate_n_flags, info);
2078 /* FIXME: code repetition end */
2079
2080 IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n",
2081 status & 0xff, tx_resp->failure_frame);
2082 IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n", rate_n_flags);
2083
2084 agg->wait_for_ba = 0;
2085 } else {
2086 /* Two or more frames were attempted; expect block-ack */
2087 u64 bitmap = 0;
2088 int start = agg->start_idx;
2089
2090 /* Construct bit-map of pending frames within Tx window */
2091 for (i = 0; i < agg->frame_count; i++) {
2092 u16 sc;
2093 status = le16_to_cpu(frame_status[i].status);
2094 seq = le16_to_cpu(frame_status[i].sequence);
2095 idx = SEQ_TO_INDEX(seq);
2096 txq_id = SEQ_TO_QUEUE(seq);
2097
2098 if (status & (AGG_TX_STATE_FEW_BYTES_MSK |
2099 AGG_TX_STATE_ABORT_MSK))
2100 continue;
2101
2102 IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n",
2103 agg->frame_count, txq_id, idx);
2104
2105 hdr = iwl_tx_queue_get_hdr(priv, txq_id, idx);
2106
2107 sc = le16_to_cpu(hdr->seq_ctrl);
2108 if (idx != (SEQ_TO_SN(sc) & 0xff)) {
2109 IWL_ERROR("BUG_ON idx doesn't match seq control"
2110 " idx=%d, seq_idx=%d, seq=%d\n",
2111 idx, SEQ_TO_SN(sc),
2112 hdr->seq_ctrl);
2113 return -1;
2114 }
4678 2115
4679 sta_flags = priv->stations[index].sta.station_flags; 2116 IWL_DEBUG_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n",
2117 i, idx, SEQ_TO_SN(sc));
2118
2119 sh = idx - start;
2120 if (sh > 64) {
2121 sh = (start - idx) + 0xff;
2122 bitmap = bitmap << sh;
2123 sh = 0;
2124 start = idx;
2125 } else if (sh < -64)
2126 sh = 0xff - (start - idx);
2127 else if (sh < 0) {
2128 sh = start - idx;
2129 start = idx;
2130 bitmap = bitmap << sh;
2131 sh = 0;
2132 }
2133 bitmap |= 1ULL << sh;
2134 IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%llx\n",
2135 start, (unsigned long long)bitmap);
2136 }
4680 2137
4681 sta_flags &= ~(STA_FLG_RTS_MIMO_PROT_MSK | STA_FLG_MIMO_DIS_MSK); 2138 agg->bitmap = bitmap;
2139 agg->start_idx = start;
2140 IWL_DEBUG_TX_REPLY("Frames %d start_idx=%d bitmap=0x%llx\n",
2141 agg->frame_count, agg->start_idx,
2142 (unsigned long long)agg->bitmap);
4682 2143
4683 switch (mimo_ps_mode) { 2144 if (bitmap)
4684 case WLAN_HT_CAP_MIMO_PS_STATIC: 2145 agg->wait_for_ba = 1;
4685 sta_flags |= STA_FLG_MIMO_DIS_MSK;
4686 break;
4687 case WLAN_HT_CAP_MIMO_PS_DYNAMIC:
4688 sta_flags |= STA_FLG_RTS_MIMO_PROT_MSK;
4689 break;
4690 case WLAN_HT_CAP_MIMO_PS_DISABLED:
4691 break;
4692 default:
4693 IWL_WARNING("Invalid MIMO PS mode %d", mimo_ps_mode);
4694 break;
4695 } 2146 }
4696 2147 return 0;
4697 sta_flags |= cpu_to_le32(
4698 (u32)sta_ht_inf->ampdu_factor << STA_FLG_MAX_AGG_SIZE_POS);
4699
4700 sta_flags |= cpu_to_le32(
4701 (u32)sta_ht_inf->ampdu_density << STA_FLG_AGG_MPDU_DENSITY_POS);
4702
4703 if (iwl4965_is_fat_tx_allowed(priv, sta_ht_inf))
4704 sta_flags |= STA_FLG_FAT_EN_MSK;
4705 else
4706 sta_flags &= ~STA_FLG_FAT_EN_MSK;
4707
4708 priv->stations[index].sta.station_flags = sta_flags;
4709 done:
4710 return;
4711}
4712
4713static void iwl4965_sta_modify_add_ba_tid(struct iwl_priv *priv,
4714 int sta_id, int tid, u16 ssn)
4715{
4716 unsigned long flags;
4717
4718 spin_lock_irqsave(&priv->sta_lock, flags);
4719 priv->stations[sta_id].sta.station_flags_msk = 0;
4720 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_ADDBA_TID_MSK;
4721 priv->stations[sta_id].sta.add_immediate_ba_tid = (u8)tid;
4722 priv->stations[sta_id].sta.add_immediate_ba_ssn = cpu_to_le16(ssn);
4723 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
4724 spin_unlock_irqrestore(&priv->sta_lock, flags);
4725
4726 iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
4727}
4728
4729static void iwl4965_sta_modify_del_ba_tid(struct iwl_priv *priv,
4730 int sta_id, int tid)
4731{
4732 unsigned long flags;
4733
4734 spin_lock_irqsave(&priv->sta_lock, flags);
4735 priv->stations[sta_id].sta.station_flags_msk = 0;
4736 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_DELBA_TID_MSK;
4737 priv->stations[sta_id].sta.remove_immediate_ba_tid = (u8)tid;
4738 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
4739 spin_unlock_irqrestore(&priv->sta_lock, flags);
4740
4741 iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
4742} 2148}
4743 2149
4744/* 2150/**
4745 * Find first available (lowest unused) Tx Queue, mark it "active". 2151 * iwl4965_rx_reply_tx - Handle standard (non-aggregation) Tx response
4746 * Called only when finding queue for aggregation.
4747 * Should never return anything < 7, because they should already
4748 * be in use as EDCA AC (0-3), Command (4), HCCA (5, 6).
4749 */ 2152 */
4750static int iwl4965_txq_ctx_activate_free(struct iwl_priv *priv) 2153static void iwl4965_rx_reply_tx(struct iwl_priv *priv,
4751{ 2154 struct iwl_rx_mem_buffer *rxb)
4752 int txq_id; 2155{
4753 2156 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
4754 for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++) 2157 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
4755 if (!test_and_set_bit(txq_id, &priv->txq_ctx_active_msk)) 2158 int txq_id = SEQ_TO_QUEUE(sequence);
4756 return txq_id; 2159 int index = SEQ_TO_INDEX(sequence);
4757 return -1; 2160 struct iwl_tx_queue *txq = &priv->txq[txq_id];
4758} 2161 struct ieee80211_tx_info *info;
4759 2162 struct iwl4965_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
4760static int iwl4965_mac_ht_tx_agg_start(struct ieee80211_hw *hw, const u8 *da, 2163 u32 status = le32_to_cpu(tx_resp->u.status);
4761 u16 tid, u16 *start_seq_num) 2164 int tid = MAX_TID_COUNT, sta_id = IWL_INVALID_STATION;
4762{ 2165 __le16 fc;
4763 struct iwl_priv *priv = hw->priv; 2166 struct ieee80211_hdr *hdr;
4764 int sta_id; 2167 u8 *qc = NULL;
4765 int tx_fifo;
4766 int txq_id;
4767 int ssn = -1;
4768 int ret = 0;
4769 unsigned long flags;
4770 struct iwl4965_tid_data *tid_data;
4771 DECLARE_MAC_BUF(mac);
4772
4773 if (likely(tid < ARRAY_SIZE(default_tid_to_tx_fifo)))
4774 tx_fifo = default_tid_to_tx_fifo[tid];
4775 else
4776 return -EINVAL;
4777
4778 IWL_WARNING("%s on da = %s tid = %d\n",
4779 __func__, print_mac(mac, da), tid);
4780
4781 sta_id = iwl4965_hw_find_station(priv, da);
4782 if (sta_id == IWL_INVALID_STATION)
4783 return -ENXIO;
4784 2168
4785 if (priv->stations[sta_id].tid[tid].agg.state != IWL_AGG_OFF) { 2169 if ((index >= txq->q.n_bd) || (iwl_queue_used(&txq->q, index) == 0)) {
4786 IWL_ERROR("Start AGG when state is not IWL_AGG_OFF !\n"); 2170 IWL_ERROR("Read index for DMA queue txq_id (%d) index %d "
4787 return -ENXIO; 2171 "is out of range [0-%d] %d %d\n", txq_id,
2172 index, txq->q.n_bd, txq->q.write_ptr,
2173 txq->q.read_ptr);
2174 return;
4788 } 2175 }
4789 2176
4790 txq_id = iwl4965_txq_ctx_activate_free(priv); 2177 info = IEEE80211_SKB_CB(txq->txb[txq->q.read_ptr].skb[0]);
4791 if (txq_id == -1) 2178 memset(&info->status, 0, sizeof(info->status));
4792 return -ENXIO;
4793
4794 spin_lock_irqsave(&priv->sta_lock, flags);
4795 tid_data = &priv->stations[sta_id].tid[tid];
4796 ssn = SEQ_TO_SN(tid_data->seq_number);
4797 tid_data->agg.txq_id = txq_id;
4798 spin_unlock_irqrestore(&priv->sta_lock, flags);
4799 2179
4800 *start_seq_num = ssn; 2180 hdr = iwl_tx_queue_get_hdr(priv, txq_id, index);
4801 ret = iwl4965_tx_queue_agg_enable(priv, txq_id, tx_fifo, 2181 fc = hdr->frame_control;
4802 sta_id, tid, ssn); 2182 if (ieee80211_is_data_qos(fc)) {
4803 if (ret) 2183 qc = ieee80211_get_qos_ctl(hdr);
4804 return ret; 2184 tid = qc[0] & 0xf;
4805
4806 ret = 0;
4807 if (tid_data->tfds_in_queue == 0) {
4808 printk(KERN_ERR "HW queue is empty\n");
4809 tid_data->agg.state = IWL_AGG_ON;
4810 ieee80211_start_tx_ba_cb_irqsafe(hw, da, tid);
4811 } else {
4812 IWL_DEBUG_HT("HW queue is NOT empty: %d packets in HW queue\n",
4813 tid_data->tfds_in_queue);
4814 tid_data->agg.state = IWL_EMPTYING_HW_QUEUE_ADDBA;
4815 } 2185 }
4816 return ret;
4817}
4818
4819static int iwl4965_mac_ht_tx_agg_stop(struct ieee80211_hw *hw, const u8 *da,
4820 u16 tid)
4821{
4822 2186
4823 struct iwl_priv *priv = hw->priv; 2187 sta_id = iwl_get_ra_sta_id(priv, hdr);
4824 int tx_fifo_id, txq_id, sta_id, ssn = -1; 2188 if (txq->sched_retry && unlikely(sta_id == IWL_INVALID_STATION)) {
4825 struct iwl4965_tid_data *tid_data; 2189 IWL_ERROR("Station not known\n");
4826 int ret, write_ptr, read_ptr; 2190 return;
4827 unsigned long flags;
4828 DECLARE_MAC_BUF(mac);
4829
4830 if (!da) {
4831 IWL_ERROR("da = NULL\n");
4832 return -EINVAL;
4833 } 2191 }
4834 2192
4835 if (likely(tid < ARRAY_SIZE(default_tid_to_tx_fifo))) 2193 if (txq->sched_retry) {
4836 tx_fifo_id = default_tid_to_tx_fifo[tid]; 2194 const u32 scd_ssn = iwl4965_get_scd_ssn(tx_resp);
4837 else 2195 struct iwl_ht_agg *agg = NULL;
4838 return -EINVAL;
4839 2196
4840 sta_id = iwl4965_hw_find_station(priv, da); 2197 if (!qc)
2198 return;
4841 2199
4842 if (sta_id == IWL_INVALID_STATION) 2200 agg = &priv->stations[sta_id].tid[tid].agg;
4843 return -ENXIO;
4844 2201
4845 if (priv->stations[sta_id].tid[tid].agg.state != IWL_AGG_ON) 2202 iwl4965_tx_status_reply_tx(priv, agg, tx_resp, txq_id, index);
4846 IWL_WARNING("Stopping AGG while state not IWL_AGG_ON\n");
4847 2203
4848 tid_data = &priv->stations[sta_id].tid[tid]; 2204 /* check if BAR is needed */
4849 ssn = (tid_data->seq_number & IEEE80211_SCTL_SEQ) >> 4; 2205 if ((tx_resp->frame_count == 1) && !iwl_is_tx_success(status))
4850 txq_id = tid_data->agg.txq_id; 2206 info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK;
4851 write_ptr = priv->txq[txq_id].q.write_ptr;
4852 read_ptr = priv->txq[txq_id].q.read_ptr;
4853 2207
4854 /* The queue is not empty */ 2208 if (txq->q.read_ptr != (scd_ssn & 0xff)) {
4855 if (write_ptr != read_ptr) { 2209 int freed, ampdu_q;
4856 IWL_DEBUG_HT("Stopping a non empty AGG HW QUEUE\n"); 2210 index = iwl_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd);
4857 priv->stations[sta_id].tid[tid].agg.state = 2211 IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn "
4858 IWL_EMPTYING_HW_QUEUE_DELBA; 2212 "%d index %d\n", scd_ssn , index);
4859 return 0; 2213 freed = iwl_tx_queue_reclaim(priv, txq_id, index);
4860 } 2214 priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
4861 2215
4862 IWL_DEBUG_HT("HW queue empty\n");; 2216 if (iwl_queue_space(&txq->q) > txq->q.low_mark &&
4863 priv->stations[sta_id].tid[tid].agg.state = IWL_AGG_OFF; 2217 txq_id >= 0 && priv->mac80211_registered &&
2218 agg->state != IWL_EMPTYING_HW_QUEUE_DELBA) {
2219 /* calculate mac80211 ampdu sw queue to wake */
2220 ampdu_q = txq_id - IWL49_FIRST_AMPDU_QUEUE +
2221 priv->hw->queues;
2222 if (agg->state == IWL_AGG_OFF)
2223 ieee80211_wake_queue(priv->hw, txq_id);
2224 else
2225 ieee80211_wake_queue(priv->hw, ampdu_q);
2226 }
2227 iwl_txq_check_empty(priv, sta_id, tid, txq_id);
2228 }
2229 } else {
2230 info->status.retry_count = tx_resp->failure_frame;
2231 info->flags |=
2232 iwl_is_tx_success(status) ? IEEE80211_TX_STAT_ACK : 0;
2233 iwl_hwrate_to_tx_control(priv,
2234 le32_to_cpu(tx_resp->rate_n_flags),
2235 info);
2236
2237 IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) rate_n_flags "
2238 "0x%x retries %d\n", txq_id,
2239 iwl_get_tx_fail_reason(status),
2240 status, le32_to_cpu(tx_resp->rate_n_flags),
2241 tx_resp->failure_frame);
2242
2243 IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index);
2244
2245 if (index != -1) {
2246 int freed = iwl_tx_queue_reclaim(priv, txq_id, index);
2247 if (tid != MAX_TID_COUNT)
2248 priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
2249 if (iwl_queue_space(&txq->q) > txq->q.low_mark &&
2250 (txq_id >= 0) && priv->mac80211_registered)
2251 ieee80211_wake_queue(priv->hw, txq_id);
2252 if (tid != MAX_TID_COUNT)
2253 iwl_txq_check_empty(priv, sta_id, tid, txq_id);
2254 }
2255 }
4864 2256
4865 spin_lock_irqsave(&priv->lock, flags); 2257 if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK))
4866 ret = iwl4965_tx_queue_agg_disable(priv, txq_id, ssn, tx_fifo_id); 2258 IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n");
4867 spin_unlock_irqrestore(&priv->lock, flags); 2259}
4868 2260
4869 if (ret) 2261static int iwl4965_calc_rssi(struct iwl_priv *priv,
4870 return ret; 2262 struct iwl_rx_phy_res *rx_resp)
2263{
2264 /* data from PHY/DSP regarding signal strength, etc.,
2265 * contents are always there, not configurable by host. */
2266 struct iwl4965_rx_non_cfg_phy *ncphy =
2267 (struct iwl4965_rx_non_cfg_phy *)rx_resp->non_cfg_phy_buf;
2268 u32 agc = (le16_to_cpu(ncphy->agc_info) & IWL49_AGC_DB_MASK)
2269 >> IWL49_AGC_DB_POS;
4871 2270
4872 ieee80211_stop_tx_ba_cb_irqsafe(priv->hw, da, tid); 2271 u32 valid_antennae =
2272 (le16_to_cpu(rx_resp->phy_flags) & IWL49_RX_PHY_FLAGS_ANTENNAE_MASK)
2273 >> IWL49_RX_PHY_FLAGS_ANTENNAE_OFFSET;
2274 u8 max_rssi = 0;
2275 u32 i;
4873 2276
4874 IWL_DEBUG_INFO("iwl4965_mac_ht_tx_agg_stop on da=%s tid=%d\n", 2277 /* Find max rssi among 3 possible receivers.
4875 print_mac(mac, da), tid); 2278 * These values are measured by the digital signal processor (DSP).
2279 * They should stay fairly constant even as the signal strength varies,
2280 * if the radio's automatic gain control (AGC) is working right.
2281 * AGC value (see below) will provide the "interesting" info. */
2282 for (i = 0; i < 3; i++)
2283 if (valid_antennae & (1 << i))
2284 max_rssi = max(ncphy->rssi_info[i << 1], max_rssi);
4876 2285
4877 return 0; 2286 IWL_DEBUG_STATS("Rssi In A %d B %d C %d Max %d AGC dB %d\n",
4878} 2287 ncphy->rssi_info[0], ncphy->rssi_info[2], ncphy->rssi_info[4],
2288 max_rssi, agc);
4879 2289
4880int iwl4965_mac_ampdu_action(struct ieee80211_hw *hw, 2290 /* dBm = max_rssi dB - agc dB - constant.
4881 enum ieee80211_ampdu_mlme_action action, 2291 * Higher AGC (higher radio gain) means lower signal. */
4882 const u8 *addr, u16 tid, u16 *ssn) 2292 return max_rssi - agc - IWL_RSSI_OFFSET;
4883{
4884 struct iwl_priv *priv = hw->priv;
4885 int sta_id;
4886 DECLARE_MAC_BUF(mac);
4887
4888 IWL_DEBUG_HT("A-MPDU action on da=%s tid=%d ",
4889 print_mac(mac, addr), tid);
4890 sta_id = iwl4965_hw_find_station(priv, addr);
4891 switch (action) {
4892 case IEEE80211_AMPDU_RX_START:
4893 IWL_DEBUG_HT("start Rx\n");
4894 iwl4965_sta_modify_add_ba_tid(priv, sta_id, tid, *ssn);
4895 break;
4896 case IEEE80211_AMPDU_RX_STOP:
4897 IWL_DEBUG_HT("stop Rx\n");
4898 iwl4965_sta_modify_del_ba_tid(priv, sta_id, tid);
4899 break;
4900 case IEEE80211_AMPDU_TX_START:
4901 IWL_DEBUG_HT("start Tx\n");
4902 return iwl4965_mac_ht_tx_agg_start(hw, addr, tid, ssn);
4903 case IEEE80211_AMPDU_TX_STOP:
4904 IWL_DEBUG_HT("stop Tx\n");
4905 return iwl4965_mac_ht_tx_agg_stop(hw, addr, tid);
4906 default:
4907 IWL_DEBUG_HT("unknown\n");
4908 return -EINVAL;
4909 break;
4910 }
4911 return 0;
4912} 2293}
4913 2294
4914#endif /* CONFIG_IWL4965_HT */
4915 2295
4916/* Set up 4965-specific Rx frame reply handlers */ 2296/* Set up 4965-specific Rx frame reply handlers */
4917void iwl4965_hw_rx_handler_setup(struct iwl_priv *priv) 2297static void iwl4965_rx_handler_setup(struct iwl_priv *priv)
4918{ 2298{
4919 /* Legacy Rx frames */ 2299 /* Legacy Rx frames */
4920 priv->rx_handlers[REPLY_RX] = iwl4965_rx_reply_rx; 2300 priv->rx_handlers[REPLY_RX] = iwl_rx_reply_rx;
4921 2301 /* Tx response */
4922 /* High-throughput (HT) Rx frames */ 2302 priv->rx_handlers[REPLY_TX] = iwl4965_rx_reply_tx;
4923 priv->rx_handlers[REPLY_RX_PHY_CMD] = iwl4965_rx_reply_rx_phy;
4924 priv->rx_handlers[REPLY_RX_MPDU_CMD] = iwl4965_rx_reply_rx;
4925
4926 priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] =
4927 iwl4965_rx_missed_beacon_notif;
4928
4929#ifdef CONFIG_IWL4965_HT
4930 priv->rx_handlers[REPLY_COMPRESSED_BA] = iwl4965_rx_reply_compressed_ba;
4931#endif /* CONFIG_IWL4965_HT */
4932} 2303}
4933 2304
4934void iwl4965_hw_setup_deferred_work(struct iwl_priv *priv) 2305static void iwl4965_setup_deferred_work(struct iwl_priv *priv)
4935{ 2306{
4936 INIT_WORK(&priv->txpower_work, iwl4965_bg_txpower_work); 2307 INIT_WORK(&priv->txpower_work, iwl4965_bg_txpower_work);
4937#ifdef CONFIG_IWL4965_SENSITIVITY
4938 INIT_WORK(&priv->sensitivity_work, iwl4965_bg_sensitivity_work);
4939#endif
4940 init_timer(&priv->statistics_periodic);
4941 priv->statistics_periodic.data = (unsigned long)priv;
4942 priv->statistics_periodic.function = iwl4965_bg_statistics_periodic;
4943} 2308}
4944 2309
4945void iwl4965_hw_cancel_deferred_work(struct iwl_priv *priv) 2310static void iwl4965_cancel_deferred_work(struct iwl_priv *priv)
4946{ 2311{
4947 del_timer_sync(&priv->statistics_periodic); 2312 cancel_work_sync(&priv->txpower_work);
4948
4949 cancel_delayed_work(&priv->init_alive_start);
4950} 2313}
4951 2314
4952 2315
@@ -4955,23 +2318,56 @@ static struct iwl_hcmd_ops iwl4965_hcmd = {
4955}; 2318};
4956 2319
4957static struct iwl_hcmd_utils_ops iwl4965_hcmd_utils = { 2320static struct iwl_hcmd_utils_ops iwl4965_hcmd_utils = {
4958 .enqueue_hcmd = iwl4965_enqueue_hcmd, 2321 .get_hcmd_size = iwl4965_get_hcmd_size,
2322 .build_addsta_hcmd = iwl4965_build_addsta_hcmd,
2323 .chain_noise_reset = iwl4965_chain_noise_reset,
2324 .gain_computation = iwl4965_gain_computation,
2325 .rts_tx_cmd_flag = iwl4965_rts_tx_cmd_flag,
2326 .calc_rssi = iwl4965_calc_rssi,
4959}; 2327};
4960 2328
4961static struct iwl_lib_ops iwl4965_lib = { 2329static struct iwl_lib_ops iwl4965_lib = {
4962 .init_drv = iwl4965_init_drv,
4963 .set_hw_params = iwl4965_hw_set_hw_params, 2330 .set_hw_params = iwl4965_hw_set_hw_params,
2331 .alloc_shared_mem = iwl4965_alloc_shared_mem,
2332 .free_shared_mem = iwl4965_free_shared_mem,
2333 .shared_mem_rx_idx = iwl4965_shared_mem_rx_idx,
4964 .txq_update_byte_cnt_tbl = iwl4965_txq_update_byte_cnt_tbl, 2334 .txq_update_byte_cnt_tbl = iwl4965_txq_update_byte_cnt_tbl,
4965 .hw_nic_init = iwl4965_hw_nic_init, 2335 .txq_set_sched = iwl4965_txq_set_sched,
2336 .txq_agg_enable = iwl4965_txq_agg_enable,
2337 .txq_agg_disable = iwl4965_txq_agg_disable,
2338 .rx_handler_setup = iwl4965_rx_handler_setup,
2339 .setup_deferred_work = iwl4965_setup_deferred_work,
2340 .cancel_deferred_work = iwl4965_cancel_deferred_work,
4966 .is_valid_rtc_data_addr = iwl4965_hw_valid_rtc_data_addr, 2341 .is_valid_rtc_data_addr = iwl4965_hw_valid_rtc_data_addr,
4967 .alive_notify = iwl4965_alive_notify, 2342 .alive_notify = iwl4965_alive_notify,
2343 .init_alive_start = iwl4965_init_alive_start,
4968 .load_ucode = iwl4965_load_bsm, 2344 .load_ucode = iwl4965_load_bsm,
2345 .apm_ops = {
2346 .init = iwl4965_apm_init,
2347 .reset = iwl4965_apm_reset,
2348 .stop = iwl4965_apm_stop,
2349 .config = iwl4965_nic_config,
2350 .set_pwr_src = iwl4965_set_pwr_src,
2351 },
4969 .eeprom_ops = { 2352 .eeprom_ops = {
2353 .regulatory_bands = {
2354 EEPROM_REGULATORY_BAND_1_CHANNELS,
2355 EEPROM_REGULATORY_BAND_2_CHANNELS,
2356 EEPROM_REGULATORY_BAND_3_CHANNELS,
2357 EEPROM_REGULATORY_BAND_4_CHANNELS,
2358 EEPROM_REGULATORY_BAND_5_CHANNELS,
2359 EEPROM_4965_REGULATORY_BAND_24_FAT_CHANNELS,
2360 EEPROM_4965_REGULATORY_BAND_52_FAT_CHANNELS
2361 },
4970 .verify_signature = iwlcore_eeprom_verify_signature, 2362 .verify_signature = iwlcore_eeprom_verify_signature,
4971 .acquire_semaphore = iwlcore_eeprom_acquire_semaphore, 2363 .acquire_semaphore = iwlcore_eeprom_acquire_semaphore,
4972 .release_semaphore = iwlcore_eeprom_release_semaphore, 2364 .release_semaphore = iwlcore_eeprom_release_semaphore,
2365 .check_version = iwl4965_eeprom_check_version,
2366 .query_addr = iwlcore_eeprom_query_addr,
4973 }, 2367 },
4974 .radio_kill_sw = iwl4965_radio_kill_sw, 2368 .send_tx_power = iwl4965_send_tx_power,
2369 .update_chain_flags = iwl4965_update_chain_flags,
2370 .temperature = iwl4965_temperature_calib,
4975}; 2371};
4976 2372
4977static struct iwl_ops iwl4965_ops = { 2373static struct iwl_ops iwl4965_ops = {
@@ -4984,16 +2380,20 @@ struct iwl_cfg iwl4965_agn_cfg = {
4984 .name = "4965AGN", 2380 .name = "4965AGN",
4985 .fw_name = "iwlwifi-4965" IWL4965_UCODE_API ".ucode", 2381 .fw_name = "iwlwifi-4965" IWL4965_UCODE_API ".ucode",
4986 .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N, 2382 .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
2383 .eeprom_size = IWL4965_EEPROM_IMG_SIZE,
4987 .ops = &iwl4965_ops, 2384 .ops = &iwl4965_ops,
4988 .mod_params = &iwl4965_mod_params, 2385 .mod_params = &iwl4965_mod_params,
4989}; 2386};
4990 2387
2388/* Module firmware */
2389MODULE_FIRMWARE("iwlwifi-4965" IWL4965_UCODE_API ".ucode");
2390
4991module_param_named(antenna, iwl4965_mod_params.antenna, int, 0444); 2391module_param_named(antenna, iwl4965_mod_params.antenna, int, 0444);
4992MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])"); 2392MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
4993module_param_named(disable, iwl4965_mod_params.disable, int, 0444); 2393module_param_named(disable, iwl4965_mod_params.disable, int, 0444);
4994MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])"); 2394MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
4995module_param_named(swcrypto, iwl4965_mod_params.sw_crypto, int, 0444); 2395module_param_named(swcrypto, iwl4965_mod_params.sw_crypto, int, 0444);
4996MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])\n"); 2396MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])");
4997module_param_named(debug, iwl4965_mod_params.debug, int, 0444); 2397module_param_named(debug, iwl4965_mod_params.debug, int, 0444);
4998MODULE_PARM_DESC(debug, "debug output mask"); 2398MODULE_PARM_DESC(debug, "debug output mask");
4999module_param_named( 2399module_param_named(
@@ -5002,10 +2402,14 @@ MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
5002 2402
5003module_param_named(queues_num, iwl4965_mod_params.num_of_queues, int, 0444); 2403module_param_named(queues_num, iwl4965_mod_params.num_of_queues, int, 0444);
5004MODULE_PARM_DESC(queues_num, "number of hw queues."); 2404MODULE_PARM_DESC(queues_num, "number of hw queues.");
5005
5006/* QoS */ 2405/* QoS */
5007module_param_named(qos_enable, iwl4965_mod_params.enable_qos, int, 0444); 2406module_param_named(qos_enable, iwl4965_mod_params.enable_qos, int, 0444);
5008MODULE_PARM_DESC(qos_enable, "enable all QoS functionality"); 2407MODULE_PARM_DESC(qos_enable, "enable all QoS functionality");
2408/* 11n */
2409module_param_named(11n_disable, iwl4965_mod_params.disable_11n, int, 0444);
2410MODULE_PARM_DESC(11n_disable, "disable 11n functionality");
5009module_param_named(amsdu_size_8K, iwl4965_mod_params.amsdu_size_8K, int, 0444); 2411module_param_named(amsdu_size_8K, iwl4965_mod_params.amsdu_size_8K, int, 0444);
5010MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size"); 2412MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size");
5011 2413
2414module_param_named(fw_restart4965, iwl4965_mod_params.restart_fw, int, 0444);
2415MODULE_PARM_DESC(fw_restart4965, "restart firmware in case of error");
diff --git a/drivers/net/wireless/iwlwifi/iwl-5000-hw.h b/drivers/net/wireless/iwlwifi/iwl-5000-hw.h
new file mode 100644
index 000000000000..c479ee211c5c
--- /dev/null
+++ b/drivers/net/wireless/iwlwifi/iwl-5000-hw.h
@@ -0,0 +1,141 @@
1/******************************************************************************
2 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
8 * Copyright(c) 2007 - 2008 Intel Corporation. All rights reserved.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
22 * USA
23 *
24 * The full GNU General Public License is included in this distribution
25 * in the file called LICENSE.GPL.
26 *
27 * Contact Information:
28 * James P. Ketrenos <ipw2100-admin@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 *
31 * BSD LICENSE
32 *
33 * Copyright(c) 2005 - 2008 Intel Corporation. All rights reserved.
34 * All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 *
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
45 * distribution.
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 *
62 *****************************************************************************/
63/*
64 * Please use this file (iwl-5000-hw.h) only for hardware-related definitions.
65 * Use iwl-5000-commands.h for uCode API definitions.
66 */
67
68#ifndef __iwl_5000_hw_h__
69#define __iwl_5000_hw_h__
70
71#define IWL50_RTC_INST_UPPER_BOUND (0x020000)
72#define IWL50_RTC_DATA_UPPER_BOUND (0x80C000)
73#define IWL50_RTC_INST_SIZE (IWL50_RTC_INST_UPPER_BOUND - RTC_INST_LOWER_BOUND)
74#define IWL50_RTC_DATA_SIZE (IWL50_RTC_DATA_UPPER_BOUND - RTC_DATA_LOWER_BOUND)
75
76/* EERPROM */
77#define IWL_5000_EEPROM_IMG_SIZE 2048
78
79
80#define IWL50_MAX_WIN_SIZE 64
81#define IWL50_QUEUE_SIZE 256
82#define IWL50_CMD_FIFO_NUM 7
83#define IWL50_NUM_QUEUES 20
84#define IWL50_NUM_AMPDU_QUEUES 10
85#define IWL50_FIRST_AMPDU_QUEUE 10
86
87#define IWL_sta_id_POS 12
88#define IWL_sta_id_LEN 4
89#define IWL_sta_id_SYM val
90
91/* Fixed (non-configurable) rx data from phy */
92
93/* Base physical address of iwl5000_shared is provided to SCD_DRAM_BASE_ADDR
94 * and &iwl5000_shared.val0 is provided to FH_RSCSR_CHNL0_STTS_WPTR_REG */
95struct iwl5000_sched_queue_byte_cnt_tbl {
96 struct iwl4965_queue_byte_cnt_entry tfd_offset[IWL50_QUEUE_SIZE +
97 IWL50_MAX_WIN_SIZE];
98} __attribute__ ((packed));
99
100struct iwl5000_shared {
101 struct iwl5000_sched_queue_byte_cnt_tbl
102 queues_byte_cnt_tbls[IWL50_NUM_QUEUES];
103 __le32 rb_closed;
104
105 /* __le32 rb_closed_stts_rb_num:12; */
106#define IWL_rb_closed_stts_rb_num_POS 0
107#define IWL_rb_closed_stts_rb_num_LEN 12
108#define IWL_rb_closed_stts_rb_num_SYM rb_closed
109 /* __le32 rsrv1:4; */
110 /* __le32 rb_closed_stts_rx_frame_num:12; */
111#define IWL_rb_closed_stts_rx_frame_num_POS 16
112#define IWL_rb_closed_stts_rx_frame_num_LEN 12
113#define IWL_rb_closed_stts_rx_frame_num_SYM rb_closed
114 /* __le32 rsrv2:4; */
115
116 __le32 frm_finished;
117 /* __le32 frame_finished_stts_rb_num:12; */
118#define IWL_frame_finished_stts_rb_num_POS 0
119#define IWL_frame_finished_stts_rb_num_LEN 12
120#define IWL_frame_finished_stts_rb_num_SYM frm_finished
121 /* __le32 rsrv3:4; */
122 /* __le32 frame_finished_stts_rx_frame_num:12; */
123#define IWL_frame_finished_stts_rx_frame_num_POS 16
124#define IWL_frame_finished_stts_rx_frame_num_LEN 12
125#define IWL_frame_finished_stts_rx_frame_num_SYM frm_finished
126 /* __le32 rsrv4:4; */
127
128 __le32 padding1; /* so that allocation will be aligned to 16B */
129 __le32 padding2;
130} __attribute__ ((packed));
131
132/* calibrations defined for 5000 */
133/* defines the order in which results should be sent to the runtime uCode */
134enum iwl5000_calib {
135 IWL5000_CALIB_LO,
136 IWL5000_CALIB_TX_IQ,
137 IWL5000_CALIB_TX_IQ_PERD,
138};
139
140#endif /* __iwl_5000_hw_h__ */
141
diff --git a/drivers/net/wireless/iwlwifi/iwl-5000.c b/drivers/net/wireless/iwlwifi/iwl-5000.c
new file mode 100644
index 000000000000..5155b8a760a7
--- /dev/null
+++ b/drivers/net/wireless/iwlwifi/iwl-5000.c
@@ -0,0 +1,1591 @@
1/******************************************************************************
2 *
3 * Copyright(c) 2007-2008 Intel Corporation. All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
20 *
21 * Contact Information:
22 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
23 *
24 *****************************************************************************/
25
26#include <linux/kernel.h>
27#include <linux/module.h>
28#include <linux/init.h>
29#include <linux/pci.h>
30#include <linux/dma-mapping.h>
31#include <linux/delay.h>
32#include <linux/skbuff.h>
33#include <linux/netdevice.h>
34#include <linux/wireless.h>
35#include <net/mac80211.h>
36#include <linux/etherdevice.h>
37#include <asm/unaligned.h>
38
39#include "iwl-eeprom.h"
40#include "iwl-dev.h"
41#include "iwl-core.h"
42#include "iwl-io.h"
43#include "iwl-sta.h"
44#include "iwl-helpers.h"
45#include "iwl-5000-hw.h"
46
47#define IWL5000_UCODE_API "-1"
48
49static const u16 iwl5000_default_queue_to_tx_fifo[] = {
50 IWL_TX_FIFO_AC3,
51 IWL_TX_FIFO_AC2,
52 IWL_TX_FIFO_AC1,
53 IWL_TX_FIFO_AC0,
54 IWL50_CMD_FIFO_NUM,
55 IWL_TX_FIFO_HCCA_1,
56 IWL_TX_FIFO_HCCA_2
57};
58
59/* FIXME: same implementation as 4965 */
60static int iwl5000_apm_stop_master(struct iwl_priv *priv)
61{
62 int ret = 0;
63 unsigned long flags;
64
65 spin_lock_irqsave(&priv->lock, flags);
66
67 /* set stop master bit */
68 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER);
69
70 ret = iwl_poll_bit(priv, CSR_RESET,
71 CSR_RESET_REG_FLAG_MASTER_DISABLED,
72 CSR_RESET_REG_FLAG_MASTER_DISABLED, 100);
73 if (ret < 0)
74 goto out;
75
76out:
77 spin_unlock_irqrestore(&priv->lock, flags);
78 IWL_DEBUG_INFO("stop master\n");
79
80 return ret;
81}
82
83
84static int iwl5000_apm_init(struct iwl_priv *priv)
85{
86 int ret = 0;
87
88 iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
89 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
90
91 /* disable L0s without affecting L1 :don't wait for ICH L0s bug W/A) */
92 iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
93 CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX);
94
95 /* Set FH wait treshold to maximum (HW error during stress W/A) */
96 iwl_set_bit(priv, CSR_DBG_HPET_MEM_REG, CSR_DBG_HPET_MEM_REG_VAL);
97
98 /* enable HAP INTA to move device L1a -> L0s */
99 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
100 CSR_HW_IF_CONFIG_REG_BIT_HAP_WAKE_L1A);
101
102 iwl_set_bit(priv, CSR_ANA_PLL_CFG, CSR50_ANA_PLL_CFG_VAL);
103
104 /* set "initialization complete" bit to move adapter
105 * D0U* --> D0A* state */
106 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
107
108 /* wait for clock stabilization */
109 ret = iwl_poll_bit(priv, CSR_GP_CNTRL,
110 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
111 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
112 if (ret < 0) {
113 IWL_DEBUG_INFO("Failed to init the card\n");
114 return ret;
115 }
116
117 ret = iwl_grab_nic_access(priv);
118 if (ret)
119 return ret;
120
121 /* enable DMA */
122 iwl_write_prph(priv, APMG_CLK_EN_REG, APMG_CLK_VAL_DMA_CLK_RQT);
123
124 udelay(20);
125
126 /* disable L1-Active */
127 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
128 APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
129
130 iwl_release_nic_access(priv);
131
132 return ret;
133}
134
135/* FIXME: this is indentical to 4965 */
136static void iwl5000_apm_stop(struct iwl_priv *priv)
137{
138 unsigned long flags;
139
140 iwl5000_apm_stop_master(priv);
141
142 spin_lock_irqsave(&priv->lock, flags);
143
144 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
145
146 udelay(10);
147
148 /* clear "init complete" move adapter D0A* --> D0U state */
149 iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
150
151 spin_unlock_irqrestore(&priv->lock, flags);
152}
153
154
155static int iwl5000_apm_reset(struct iwl_priv *priv)
156{
157 int ret = 0;
158 unsigned long flags;
159
160 iwl5000_apm_stop_master(priv);
161
162 spin_lock_irqsave(&priv->lock, flags);
163
164 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
165
166 udelay(10);
167
168
169 /* FIXME: put here L1A -L0S w/a */
170
171 iwl_set_bit(priv, CSR_ANA_PLL_CFG, CSR50_ANA_PLL_CFG_VAL);
172
173 /* set "initialization complete" bit to move adapter
174 * D0U* --> D0A* state */
175 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
176
177 /* wait for clock stabilization */
178 ret = iwl_poll_bit(priv, CSR_GP_CNTRL,
179 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
180 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
181 if (ret < 0) {
182 IWL_DEBUG_INFO("Failed to init the card\n");
183 goto out;
184 }
185
186 ret = iwl_grab_nic_access(priv);
187 if (ret)
188 goto out;
189
190 /* enable DMA */
191 iwl_write_prph(priv, APMG_CLK_EN_REG, APMG_CLK_VAL_DMA_CLK_RQT);
192
193 udelay(20);
194
195 /* disable L1-Active */
196 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
197 APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
198
199 iwl_release_nic_access(priv);
200
201out:
202 spin_unlock_irqrestore(&priv->lock, flags);
203
204 return ret;
205}
206
207
208static void iwl5000_nic_config(struct iwl_priv *priv)
209{
210 unsigned long flags;
211 u16 radio_cfg;
212 u16 link;
213
214 spin_lock_irqsave(&priv->lock, flags);
215
216 pci_read_config_word(priv->pci_dev, PCI_CFG_LINK_CTRL, &link);
217
218 /* L1 is enabled by BIOS */
219 if ((link & PCI_CFG_LINK_CTRL_VAL_L1_EN) == PCI_CFG_LINK_CTRL_VAL_L1_EN)
220 /* diable L0S disabled L1A enabled */
221 iwl_set_bit(priv, CSR_GIO_REG, CSR_GIO_REG_VAL_L0S_ENABLED);
222 else
223 /* L0S enabled L1A disabled */
224 iwl_clear_bit(priv, CSR_GIO_REG, CSR_GIO_REG_VAL_L0S_ENABLED);
225
226 radio_cfg = iwl_eeprom_query16(priv, EEPROM_RADIO_CONFIG);
227
228 /* write radio config values to register */
229 if (EEPROM_RF_CFG_TYPE_MSK(radio_cfg) < EEPROM_5000_RF_CFG_TYPE_MAX)
230 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
231 EEPROM_RF_CFG_TYPE_MSK(radio_cfg) |
232 EEPROM_RF_CFG_STEP_MSK(radio_cfg) |
233 EEPROM_RF_CFG_DASH_MSK(radio_cfg));
234
235 /* set CSR_HW_CONFIG_REG for uCode use */
236 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
237 CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |
238 CSR_HW_IF_CONFIG_REG_BIT_MAC_SI);
239
240 /* W/A : NIC is stuck in a reset state after Early PCIe power off
241 * (PCIe power is lost before PERST# is asserted),
242 * causing ME FW to lose ownership and not being able to obtain it back.
243 */
244 iwl_grab_nic_access(priv);
245 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
246 APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS,
247 ~APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS);
248 iwl_release_nic_access(priv);
249
250 spin_unlock_irqrestore(&priv->lock, flags);
251}
252
253
254
255/*
256 * EEPROM
257 */
258static u32 eeprom_indirect_address(const struct iwl_priv *priv, u32 address)
259{
260 u16 offset = 0;
261
262 if ((address & INDIRECT_ADDRESS) == 0)
263 return address;
264
265 switch (address & INDIRECT_TYPE_MSK) {
266 case INDIRECT_HOST:
267 offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_HOST);
268 break;
269 case INDIRECT_GENERAL:
270 offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_GENERAL);
271 break;
272 case INDIRECT_REGULATORY:
273 offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_REGULATORY);
274 break;
275 case INDIRECT_CALIBRATION:
276 offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_CALIBRATION);
277 break;
278 case INDIRECT_PROCESS_ADJST:
279 offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_PROCESS_ADJST);
280 break;
281 case INDIRECT_OTHERS:
282 offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_OTHERS);
283 break;
284 default:
285 IWL_ERROR("illegal indirect type: 0x%X\n",
286 address & INDIRECT_TYPE_MSK);
287 break;
288 }
289
290 /* translate the offset from words to byte */
291 return (address & ADDRESS_MSK) + (offset << 1);
292}
293
294static int iwl5000_eeprom_check_version(struct iwl_priv *priv)
295{
296 u16 eeprom_ver;
297 struct iwl_eeprom_calib_hdr {
298 u8 version;
299 u8 pa_type;
300 u16 voltage;
301 } *hdr;
302
303 eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
304
305 hdr = (struct iwl_eeprom_calib_hdr *)iwl_eeprom_query_addr(priv,
306 EEPROM_5000_CALIB_ALL);
307
308 if (eeprom_ver < EEPROM_5000_EEPROM_VERSION ||
309 hdr->version < EEPROM_5000_TX_POWER_VERSION)
310 goto err;
311
312 return 0;
313err:
314 IWL_ERROR("Unsuported EEPROM VER=0x%x < 0x%x CALIB=0x%x < 0x%x\n",
315 eeprom_ver, EEPROM_5000_EEPROM_VERSION,
316 hdr->version, EEPROM_5000_TX_POWER_VERSION);
317 return -EINVAL;
318
319}
320
321static void iwl5000_gain_computation(struct iwl_priv *priv,
322 u32 average_noise[NUM_RX_CHAINS],
323 u16 min_average_noise_antenna_i,
324 u32 min_average_noise)
325{
326 int i;
327 s32 delta_g;
328 struct iwl_chain_noise_data *data = &priv->chain_noise_data;
329
330 /* Find Gain Code for the antennas B and C */
331 for (i = 1; i < NUM_RX_CHAINS; i++) {
332 if ((data->disconn_array[i])) {
333 data->delta_gain_code[i] = 0;
334 continue;
335 }
336 delta_g = (1000 * ((s32)average_noise[0] -
337 (s32)average_noise[i])) / 1500;
338 /* bound gain by 2 bits value max, 3rd bit is sign */
339 data->delta_gain_code[i] =
340 min(abs(delta_g), CHAIN_NOISE_MAX_DELTA_GAIN_CODE);
341
342 if (delta_g < 0)
343 /* set negative sign */
344 data->delta_gain_code[i] |= (1 << 2);
345 }
346
347 IWL_DEBUG_CALIB("Delta gains: ANT_B = %d ANT_C = %d\n",
348 data->delta_gain_code[1], data->delta_gain_code[2]);
349
350 if (!data->radio_write) {
351 struct iwl5000_calibration_chain_noise_gain_cmd cmd;
352 memset(&cmd, 0, sizeof(cmd));
353
354 cmd.op_code = IWL5000_PHY_CALIBRATE_CHAIN_NOISE_GAIN_CMD;
355 cmd.delta_gain_1 = data->delta_gain_code[1];
356 cmd.delta_gain_2 = data->delta_gain_code[2];
357 iwl_send_cmd_pdu_async(priv, REPLY_PHY_CALIBRATION_CMD,
358 sizeof(cmd), &cmd, NULL);
359
360 data->radio_write = 1;
361 data->state = IWL_CHAIN_NOISE_CALIBRATED;
362 }
363
364 data->chain_noise_a = 0;
365 data->chain_noise_b = 0;
366 data->chain_noise_c = 0;
367 data->chain_signal_a = 0;
368 data->chain_signal_b = 0;
369 data->chain_signal_c = 0;
370 data->beacon_count = 0;
371}
372
373static void iwl5000_chain_noise_reset(struct iwl_priv *priv)
374{
375 struct iwl_chain_noise_data *data = &priv->chain_noise_data;
376
377 if ((data->state == IWL_CHAIN_NOISE_ALIVE) && iwl_is_associated(priv)) {
378 struct iwl5000_calibration_chain_noise_reset_cmd cmd;
379
380 memset(&cmd, 0, sizeof(cmd));
381 cmd.op_code = IWL5000_PHY_CALIBRATE_CHAIN_NOISE_RESET_CMD;
382 if (iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
383 sizeof(cmd), &cmd))
384 IWL_ERROR("Could not send REPLY_PHY_CALIBRATION_CMD\n");
385 data->state = IWL_CHAIN_NOISE_ACCUMULATE;
386 IWL_DEBUG_CALIB("Run chain_noise_calibrate\n");
387 }
388}
389
390static void iwl5000_rts_tx_cmd_flag(struct ieee80211_tx_info *info,
391 __le32 *tx_flags)
392{
393 if ((info->flags & IEEE80211_TX_CTL_USE_RTS_CTS) ||
394 (info->flags & IEEE80211_TX_CTL_USE_CTS_PROTECT))
395 *tx_flags |= TX_CMD_FLG_RTS_CTS_MSK;
396 else
397 *tx_flags &= ~TX_CMD_FLG_RTS_CTS_MSK;
398}
399
400static struct iwl_sensitivity_ranges iwl5000_sensitivity = {
401 .min_nrg_cck = 95,
402 .max_nrg_cck = 0,
403 .auto_corr_min_ofdm = 90,
404 .auto_corr_min_ofdm_mrc = 170,
405 .auto_corr_min_ofdm_x1 = 120,
406 .auto_corr_min_ofdm_mrc_x1 = 240,
407
408 .auto_corr_max_ofdm = 120,
409 .auto_corr_max_ofdm_mrc = 210,
410 .auto_corr_max_ofdm_x1 = 155,
411 .auto_corr_max_ofdm_mrc_x1 = 290,
412
413 .auto_corr_min_cck = 125,
414 .auto_corr_max_cck = 200,
415 .auto_corr_min_cck_mrc = 170,
416 .auto_corr_max_cck_mrc = 400,
417 .nrg_th_cck = 95,
418 .nrg_th_ofdm = 95,
419};
420
421static const u8 *iwl5000_eeprom_query_addr(const struct iwl_priv *priv,
422 size_t offset)
423{
424 u32 address = eeprom_indirect_address(priv, offset);
425 BUG_ON(address >= priv->cfg->eeprom_size);
426 return &priv->eeprom[address];
427}
428
429/*
430 * Calibration
431 */
432static int iwl5000_send_Xtal_calib(struct iwl_priv *priv)
433{
434 u16 *xtal_calib = (u16 *)iwl_eeprom_query_addr(priv, EEPROM_5000_XTAL);
435
436 struct iwl5000_calibration cal_cmd = {
437 .op_code = IWL5000_PHY_CALIBRATE_CRYSTAL_FRQ_CMD,
438 .data = {
439 (u8)xtal_calib[0],
440 (u8)xtal_calib[1],
441 }
442 };
443
444 return iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
445 sizeof(cal_cmd), &cal_cmd);
446}
447
448static int iwl5000_send_calib_cfg(struct iwl_priv *priv)
449{
450 struct iwl5000_calib_cfg_cmd calib_cfg_cmd;
451 struct iwl_host_cmd cmd = {
452 .id = CALIBRATION_CFG_CMD,
453 .len = sizeof(struct iwl5000_calib_cfg_cmd),
454 .data = &calib_cfg_cmd,
455 };
456
457 memset(&calib_cfg_cmd, 0, sizeof(calib_cfg_cmd));
458 calib_cfg_cmd.ucd_calib_cfg.once.is_enable = IWL_CALIB_INIT_CFG_ALL;
459 calib_cfg_cmd.ucd_calib_cfg.once.start = IWL_CALIB_INIT_CFG_ALL;
460 calib_cfg_cmd.ucd_calib_cfg.once.send_res = IWL_CALIB_INIT_CFG_ALL;
461 calib_cfg_cmd.ucd_calib_cfg.flags = IWL_CALIB_INIT_CFG_ALL;
462
463 return iwl_send_cmd(priv, &cmd);
464}
465
466static void iwl5000_rx_calib_result(struct iwl_priv *priv,
467 struct iwl_rx_mem_buffer *rxb)
468{
469 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
470 struct iwl5000_calib_hdr *hdr = (struct iwl5000_calib_hdr *)pkt->u.raw;
471 int len = le32_to_cpu(pkt->len) & FH_RSCSR_FRAME_SIZE_MSK;
472 int index;
473
474 /* reduce the size of the length field itself */
475 len -= 4;
476
477 /* Define the order in which the results will be sent to the runtime
478 * uCode. iwl_send_calib_results sends them in a row according to their
479 * index. We sort them here */
480 switch (hdr->op_code) {
481 case IWL5000_PHY_CALIBRATE_LO_CMD:
482 index = IWL5000_CALIB_LO;
483 break;
484 case IWL5000_PHY_CALIBRATE_TX_IQ_CMD:
485 index = IWL5000_CALIB_TX_IQ;
486 break;
487 case IWL5000_PHY_CALIBRATE_TX_IQ_PERD_CMD:
488 index = IWL5000_CALIB_TX_IQ_PERD;
489 break;
490 default:
491 IWL_ERROR("Unknown calibration notification %d\n",
492 hdr->op_code);
493 return;
494 }
495 iwl_calib_set(&priv->calib_results[index], pkt->u.raw, len);
496}
497
498static void iwl5000_rx_calib_complete(struct iwl_priv *priv,
499 struct iwl_rx_mem_buffer *rxb)
500{
501 IWL_DEBUG_INFO("Init. calibration is completed, restarting fw.\n");
502 queue_work(priv->workqueue, &priv->restart);
503}
504
505/*
506 * ucode
507 */
508static int iwl5000_load_section(struct iwl_priv *priv,
509 struct fw_desc *image,
510 u32 dst_addr)
511{
512 int ret = 0;
513 unsigned long flags;
514
515 dma_addr_t phy_addr = image->p_addr;
516 u32 byte_cnt = image->len;
517
518 spin_lock_irqsave(&priv->lock, flags);
519 ret = iwl_grab_nic_access(priv);
520 if (ret) {
521 spin_unlock_irqrestore(&priv->lock, flags);
522 return ret;
523 }
524
525 iwl_write_direct32(priv,
526 FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL),
527 FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE);
528
529 iwl_write_direct32(priv,
530 FH_SRVC_CHNL_SRAM_ADDR_REG(FH_SRVC_CHNL), dst_addr);
531
532 iwl_write_direct32(priv,
533 FH_TFDIB_CTRL0_REG(FH_SRVC_CHNL),
534 phy_addr & FH_MEM_TFDIB_DRAM_ADDR_LSB_MSK);
535
536 iwl_write_direct32(priv,
537 FH_TFDIB_CTRL1_REG(FH_SRVC_CHNL),
538 (iwl_get_dma_hi_address(phy_addr)
539 << FH_MEM_TFDIB_REG1_ADDR_BITSHIFT) | byte_cnt);
540
541 iwl_write_direct32(priv,
542 FH_TCSR_CHNL_TX_BUF_STS_REG(FH_SRVC_CHNL),
543 1 << FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_NUM |
544 1 << FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_IDX |
545 FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_VALID);
546
547 iwl_write_direct32(priv,
548 FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL),
549 FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
550 FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_DISABLE_VAL |
551 FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_ENDTFD);
552
553 iwl_release_nic_access(priv);
554 spin_unlock_irqrestore(&priv->lock, flags);
555 return 0;
556}
557
558static int iwl5000_load_given_ucode(struct iwl_priv *priv,
559 struct fw_desc *inst_image,
560 struct fw_desc *data_image)
561{
562 int ret = 0;
563
564 ret = iwl5000_load_section(
565 priv, inst_image, RTC_INST_LOWER_BOUND);
566 if (ret)
567 return ret;
568
569 IWL_DEBUG_INFO("INST uCode section being loaded...\n");
570 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
571 priv->ucode_write_complete, 5 * HZ);
572 if (ret == -ERESTARTSYS) {
573 IWL_ERROR("Could not load the INST uCode section due "
574 "to interrupt\n");
575 return ret;
576 }
577 if (!ret) {
578 IWL_ERROR("Could not load the INST uCode section\n");
579 return -ETIMEDOUT;
580 }
581
582 priv->ucode_write_complete = 0;
583
584 ret = iwl5000_load_section(
585 priv, data_image, RTC_DATA_LOWER_BOUND);
586 if (ret)
587 return ret;
588
589 IWL_DEBUG_INFO("DATA uCode section being loaded...\n");
590
591 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
592 priv->ucode_write_complete, 5 * HZ);
593 if (ret == -ERESTARTSYS) {
594 IWL_ERROR("Could not load the INST uCode section due "
595 "to interrupt\n");
596 return ret;
597 } else if (!ret) {
598 IWL_ERROR("Could not load the DATA uCode section\n");
599 return -ETIMEDOUT;
600 } else
601 ret = 0;
602
603 priv->ucode_write_complete = 0;
604
605 return ret;
606}
607
608static int iwl5000_load_ucode(struct iwl_priv *priv)
609{
610 int ret = 0;
611
612 /* check whether init ucode should be loaded, or rather runtime ucode */
613 if (priv->ucode_init.len && (priv->ucode_type == UCODE_NONE)) {
614 IWL_DEBUG_INFO("Init ucode found. Loading init ucode...\n");
615 ret = iwl5000_load_given_ucode(priv,
616 &priv->ucode_init, &priv->ucode_init_data);
617 if (!ret) {
618 IWL_DEBUG_INFO("Init ucode load complete.\n");
619 priv->ucode_type = UCODE_INIT;
620 }
621 } else {
622 IWL_DEBUG_INFO("Init ucode not found, or already loaded. "
623 "Loading runtime ucode...\n");
624 ret = iwl5000_load_given_ucode(priv,
625 &priv->ucode_code, &priv->ucode_data);
626 if (!ret) {
627 IWL_DEBUG_INFO("Runtime ucode load complete.\n");
628 priv->ucode_type = UCODE_RT;
629 }
630 }
631
632 return ret;
633}
634
635static void iwl5000_init_alive_start(struct iwl_priv *priv)
636{
637 int ret = 0;
638
639 /* Check alive response for "valid" sign from uCode */
640 if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
641 /* We had an error bringing up the hardware, so take it
642 * all the way back down so we can try again */
643 IWL_DEBUG_INFO("Initialize Alive failed.\n");
644 goto restart;
645 }
646
647 /* initialize uCode was loaded... verify inst image.
648 * This is a paranoid check, because we would not have gotten the
649 * "initialize" alive if code weren't properly loaded. */
650 if (iwl_verify_ucode(priv)) {
651 /* Runtime instruction load was bad;
652 * take it all the way back down so we can try again */
653 IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n");
654 goto restart;
655 }
656
657 iwl_clear_stations_table(priv);
658 ret = priv->cfg->ops->lib->alive_notify(priv);
659 if (ret) {
660 IWL_WARNING("Could not complete ALIVE transition: %d\n", ret);
661 goto restart;
662 }
663
664 iwl5000_send_calib_cfg(priv);
665 return;
666
667restart:
668 /* real restart (first load init_ucode) */
669 queue_work(priv->workqueue, &priv->restart);
670}
671
672static void iwl5000_set_wr_ptrs(struct iwl_priv *priv,
673 int txq_id, u32 index)
674{
675 iwl_write_direct32(priv, HBUS_TARG_WRPTR,
676 (index & 0xff) | (txq_id << 8));
677 iwl_write_prph(priv, IWL50_SCD_QUEUE_RDPTR(txq_id), index);
678}
679
680static void iwl5000_tx_queue_set_status(struct iwl_priv *priv,
681 struct iwl_tx_queue *txq,
682 int tx_fifo_id, int scd_retry)
683{
684 int txq_id = txq->q.id;
685 int active = test_bit(txq_id, &priv->txq_ctx_active_msk)?1:0;
686
687 iwl_write_prph(priv, IWL50_SCD_QUEUE_STATUS_BITS(txq_id),
688 (active << IWL50_SCD_QUEUE_STTS_REG_POS_ACTIVE) |
689 (tx_fifo_id << IWL50_SCD_QUEUE_STTS_REG_POS_TXF) |
690 (1 << IWL50_SCD_QUEUE_STTS_REG_POS_WSL) |
691 IWL50_SCD_QUEUE_STTS_REG_MSK);
692
693 txq->sched_retry = scd_retry;
694
695 IWL_DEBUG_INFO("%s %s Queue %d on AC %d\n",
696 active ? "Activate" : "Deactivate",
697 scd_retry ? "BA" : "AC", txq_id, tx_fifo_id);
698}
699
700static int iwl5000_send_wimax_coex(struct iwl_priv *priv)
701{
702 struct iwl_wimax_coex_cmd coex_cmd;
703
704 memset(&coex_cmd, 0, sizeof(coex_cmd));
705
706 return iwl_send_cmd_pdu(priv, COEX_PRIORITY_TABLE_CMD,
707 sizeof(coex_cmd), &coex_cmd);
708}
709
710static int iwl5000_alive_notify(struct iwl_priv *priv)
711{
712 u32 a;
713 int i = 0;
714 unsigned long flags;
715 int ret;
716
717 spin_lock_irqsave(&priv->lock, flags);
718
719 ret = iwl_grab_nic_access(priv);
720 if (ret) {
721 spin_unlock_irqrestore(&priv->lock, flags);
722 return ret;
723 }
724
725 priv->scd_base_addr = iwl_read_prph(priv, IWL50_SCD_SRAM_BASE_ADDR);
726 a = priv->scd_base_addr + IWL50_SCD_CONTEXT_DATA_OFFSET;
727 for (; a < priv->scd_base_addr + IWL50_SCD_TX_STTS_BITMAP_OFFSET;
728 a += 4)
729 iwl_write_targ_mem(priv, a, 0);
730 for (; a < priv->scd_base_addr + IWL50_SCD_TRANSLATE_TBL_OFFSET;
731 a += 4)
732 iwl_write_targ_mem(priv, a, 0);
733 for (; a < sizeof(u16) * priv->hw_params.max_txq_num; a += 4)
734 iwl_write_targ_mem(priv, a, 0);
735
736 iwl_write_prph(priv, IWL50_SCD_DRAM_BASE_ADDR,
737 (priv->shared_phys +
738 offsetof(struct iwl5000_shared, queues_byte_cnt_tbls)) >> 10);
739 iwl_write_prph(priv, IWL50_SCD_QUEUECHAIN_SEL,
740 IWL50_SCD_QUEUECHAIN_SEL_ALL(
741 priv->hw_params.max_txq_num));
742 iwl_write_prph(priv, IWL50_SCD_AGGR_SEL, 0);
743
744 /* initiate the queues */
745 for (i = 0; i < priv->hw_params.max_txq_num; i++) {
746 iwl_write_prph(priv, IWL50_SCD_QUEUE_RDPTR(i), 0);
747 iwl_write_direct32(priv, HBUS_TARG_WRPTR, 0 | (i << 8));
748 iwl_write_targ_mem(priv, priv->scd_base_addr +
749 IWL50_SCD_CONTEXT_QUEUE_OFFSET(i), 0);
750 iwl_write_targ_mem(priv, priv->scd_base_addr +
751 IWL50_SCD_CONTEXT_QUEUE_OFFSET(i) +
752 sizeof(u32),
753 ((SCD_WIN_SIZE <<
754 IWL50_SCD_QUEUE_CTX_REG2_WIN_SIZE_POS) &
755 IWL50_SCD_QUEUE_CTX_REG2_WIN_SIZE_MSK) |
756 ((SCD_FRAME_LIMIT <<
757 IWL50_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
758 IWL50_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK));
759 }
760
761 iwl_write_prph(priv, IWL50_SCD_INTERRUPT_MASK,
762 IWL_MASK(0, priv->hw_params.max_txq_num));
763
764 /* Activate all Tx DMA/FIFO channels */
765 priv->cfg->ops->lib->txq_set_sched(priv, IWL_MASK(0, 7));
766
767 iwl5000_set_wr_ptrs(priv, IWL_CMD_QUEUE_NUM, 0);
768 /* map qos queues to fifos one-to-one */
769 for (i = 0; i < ARRAY_SIZE(iwl5000_default_queue_to_tx_fifo); i++) {
770 int ac = iwl5000_default_queue_to_tx_fifo[i];
771 iwl_txq_ctx_activate(priv, i);
772 iwl5000_tx_queue_set_status(priv, &priv->txq[i], ac, 0);
773 }
774 /* TODO - need to initialize those FIFOs inside the loop above,
775 * not only mark them as active */
776 iwl_txq_ctx_activate(priv, 4);
777 iwl_txq_ctx_activate(priv, 7);
778 iwl_txq_ctx_activate(priv, 8);
779 iwl_txq_ctx_activate(priv, 9);
780
781 iwl_release_nic_access(priv);
782 spin_unlock_irqrestore(&priv->lock, flags);
783
784
785 iwl5000_send_wimax_coex(priv);
786
787 iwl5000_send_Xtal_calib(priv);
788
789 if (priv->ucode_type == UCODE_RT)
790 iwl_send_calib_results(priv);
791
792 return 0;
793}
794
795static int iwl5000_hw_set_hw_params(struct iwl_priv *priv)
796{
797 if ((priv->cfg->mod_params->num_of_queues > IWL50_NUM_QUEUES) ||
798 (priv->cfg->mod_params->num_of_queues < IWL_MIN_NUM_QUEUES)) {
799 IWL_ERROR("invalid queues_num, should be between %d and %d\n",
800 IWL_MIN_NUM_QUEUES, IWL50_NUM_QUEUES);
801 return -EINVAL;
802 }
803
804 priv->hw_params.max_txq_num = priv->cfg->mod_params->num_of_queues;
805 priv->hw_params.first_ampdu_q = IWL50_FIRST_AMPDU_QUEUE;
806 priv->hw_params.max_stations = IWL5000_STATION_COUNT;
807 priv->hw_params.bcast_sta_id = IWL5000_BROADCAST_ID;
808 priv->hw_params.max_data_size = IWL50_RTC_DATA_SIZE;
809 priv->hw_params.max_inst_size = IWL50_RTC_INST_SIZE;
810 priv->hw_params.max_bsm_size = 0;
811 priv->hw_params.fat_channel = BIT(IEEE80211_BAND_2GHZ) |
812 BIT(IEEE80211_BAND_5GHZ);
813 priv->hw_params.sens = &iwl5000_sensitivity;
814
815 switch (priv->hw_rev & CSR_HW_REV_TYPE_MSK) {
816 case CSR_HW_REV_TYPE_5100:
817 case CSR_HW_REV_TYPE_5150:
818 priv->hw_params.tx_chains_num = 1;
819 priv->hw_params.rx_chains_num = 2;
820 /* FIXME: move to ANT_A, ANT_B, ANT_C enum */
821 priv->hw_params.valid_tx_ant = ANT_A;
822 priv->hw_params.valid_rx_ant = ANT_AB;
823 break;
824 case CSR_HW_REV_TYPE_5300:
825 case CSR_HW_REV_TYPE_5350:
826 priv->hw_params.tx_chains_num = 3;
827 priv->hw_params.rx_chains_num = 3;
828 priv->hw_params.valid_tx_ant = ANT_ABC;
829 priv->hw_params.valid_rx_ant = ANT_ABC;
830 break;
831 }
832
833 switch (priv->hw_rev & CSR_HW_REV_TYPE_MSK) {
834 case CSR_HW_REV_TYPE_5100:
835 case CSR_HW_REV_TYPE_5300:
836 case CSR_HW_REV_TYPE_5350:
837 /* 5X00 and 5350 wants in Celsius */
838 priv->hw_params.ct_kill_threshold = CT_KILL_THRESHOLD;
839 break;
840 case CSR_HW_REV_TYPE_5150:
841 /* 5150 wants in Kelvin */
842 priv->hw_params.ct_kill_threshold =
843 CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD);
844 break;
845 }
846
847 return 0;
848}
849
850static int iwl5000_alloc_shared_mem(struct iwl_priv *priv)
851{
852 priv->shared_virt = pci_alloc_consistent(priv->pci_dev,
853 sizeof(struct iwl5000_shared),
854 &priv->shared_phys);
855 if (!priv->shared_virt)
856 return -ENOMEM;
857
858 memset(priv->shared_virt, 0, sizeof(struct iwl5000_shared));
859
860 priv->rb_closed_offset = offsetof(struct iwl5000_shared, rb_closed);
861
862 return 0;
863}
864
865static void iwl5000_free_shared_mem(struct iwl_priv *priv)
866{
867 if (priv->shared_virt)
868 pci_free_consistent(priv->pci_dev,
869 sizeof(struct iwl5000_shared),
870 priv->shared_virt,
871 priv->shared_phys);
872}
873
874static int iwl5000_shared_mem_rx_idx(struct iwl_priv *priv)
875{
876 struct iwl5000_shared *s = priv->shared_virt;
877 return le32_to_cpu(s->rb_closed) & 0xFFF;
878}
879
880/**
881 * iwl5000_txq_update_byte_cnt_tbl - Set up entry in Tx byte-count array
882 */
883static void iwl5000_txq_update_byte_cnt_tbl(struct iwl_priv *priv,
884 struct iwl_tx_queue *txq,
885 u16 byte_cnt)
886{
887 struct iwl5000_shared *shared_data = priv->shared_virt;
888 int txq_id = txq->q.id;
889 u8 sec_ctl = 0;
890 u8 sta = 0;
891 int len;
892
893 len = byte_cnt + IWL_TX_CRC_SIZE + IWL_TX_DELIMITER_SIZE;
894
895 if (txq_id != IWL_CMD_QUEUE_NUM) {
896 sta = txq->cmd[txq->q.write_ptr]->cmd.tx.sta_id;
897 sec_ctl = txq->cmd[txq->q.write_ptr]->cmd.tx.sec_ctl;
898
899 switch (sec_ctl & TX_CMD_SEC_MSK) {
900 case TX_CMD_SEC_CCM:
901 len += CCMP_MIC_LEN;
902 break;
903 case TX_CMD_SEC_TKIP:
904 len += TKIP_ICV_LEN;
905 break;
906 case TX_CMD_SEC_WEP:
907 len += WEP_IV_LEN + WEP_ICV_LEN;
908 break;
909 }
910 }
911
912 IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
913 tfd_offset[txq->q.write_ptr], byte_cnt, len);
914
915 IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
916 tfd_offset[txq->q.write_ptr], sta_id, sta);
917
918 if (txq->q.write_ptr < IWL50_MAX_WIN_SIZE) {
919 IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
920 tfd_offset[IWL50_QUEUE_SIZE + txq->q.write_ptr],
921 byte_cnt, len);
922 IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
923 tfd_offset[IWL50_QUEUE_SIZE + txq->q.write_ptr],
924 sta_id, sta);
925 }
926}
927
928static void iwl5000_txq_inval_byte_cnt_tbl(struct iwl_priv *priv,
929 struct iwl_tx_queue *txq)
930{
931 int txq_id = txq->q.id;
932 struct iwl5000_shared *shared_data = priv->shared_virt;
933 u8 sta = 0;
934
935 if (txq_id != IWL_CMD_QUEUE_NUM)
936 sta = txq->cmd[txq->q.read_ptr]->cmd.tx.sta_id;
937
938 shared_data->queues_byte_cnt_tbls[txq_id].tfd_offset[txq->q.read_ptr].
939 val = cpu_to_le16(1 | (sta << 12));
940
941 if (txq->q.write_ptr < IWL50_MAX_WIN_SIZE) {
942 shared_data->queues_byte_cnt_tbls[txq_id].
943 tfd_offset[IWL50_QUEUE_SIZE + txq->q.read_ptr].
944 val = cpu_to_le16(1 | (sta << 12));
945 }
946}
947
948static int iwl5000_tx_queue_set_q2ratid(struct iwl_priv *priv, u16 ra_tid,
949 u16 txq_id)
950{
951 u32 tbl_dw_addr;
952 u32 tbl_dw;
953 u16 scd_q2ratid;
954
955 scd_q2ratid = ra_tid & IWL_SCD_QUEUE_RA_TID_MAP_RATID_MSK;
956
957 tbl_dw_addr = priv->scd_base_addr +
958 IWL50_SCD_TRANSLATE_TBL_OFFSET_QUEUE(txq_id);
959
960 tbl_dw = iwl_read_targ_mem(priv, tbl_dw_addr);
961
962 if (txq_id & 0x1)
963 tbl_dw = (scd_q2ratid << 16) | (tbl_dw & 0x0000FFFF);
964 else
965 tbl_dw = scd_q2ratid | (tbl_dw & 0xFFFF0000);
966
967 iwl_write_targ_mem(priv, tbl_dw_addr, tbl_dw);
968
969 return 0;
970}
971static void iwl5000_tx_queue_stop_scheduler(struct iwl_priv *priv, u16 txq_id)
972{
973 /* Simply stop the queue, but don't change any configuration;
974 * the SCD_ACT_EN bit is the write-enable mask for the ACTIVE bit. */
975 iwl_write_prph(priv,
976 IWL50_SCD_QUEUE_STATUS_BITS(txq_id),
977 (0 << IWL50_SCD_QUEUE_STTS_REG_POS_ACTIVE)|
978 (1 << IWL50_SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN));
979}
980
981static int iwl5000_txq_agg_enable(struct iwl_priv *priv, int txq_id,
982 int tx_fifo, int sta_id, int tid, u16 ssn_idx)
983{
984 unsigned long flags;
985 int ret;
986 u16 ra_tid;
987
988 if ((IWL50_FIRST_AMPDU_QUEUE > txq_id) ||
989 (IWL50_FIRST_AMPDU_QUEUE + IWL50_NUM_AMPDU_QUEUES <= txq_id)) {
990 IWL_WARNING("queue number out of range: %d, must be %d to %d\n",
991 txq_id, IWL50_FIRST_AMPDU_QUEUE,
992 IWL50_FIRST_AMPDU_QUEUE + IWL50_NUM_AMPDU_QUEUES - 1);
993 return -EINVAL;
994 }
995
996 ra_tid = BUILD_RAxTID(sta_id, tid);
997
998 /* Modify device's station table to Tx this TID */
999 iwl_sta_modify_enable_tid_tx(priv, sta_id, tid);
1000
1001 spin_lock_irqsave(&priv->lock, flags);
1002 ret = iwl_grab_nic_access(priv);
1003 if (ret) {
1004 spin_unlock_irqrestore(&priv->lock, flags);
1005 return ret;
1006 }
1007
1008 /* Stop this Tx queue before configuring it */
1009 iwl5000_tx_queue_stop_scheduler(priv, txq_id);
1010
1011 /* Map receiver-address / traffic-ID to this queue */
1012 iwl5000_tx_queue_set_q2ratid(priv, ra_tid, txq_id);
1013
1014 /* Set this queue as a chain-building queue */
1015 iwl_set_bits_prph(priv, IWL50_SCD_QUEUECHAIN_SEL, (1<<txq_id));
1016
1017 /* enable aggregations for the queue */
1018 iwl_set_bits_prph(priv, IWL50_SCD_AGGR_SEL, (1<<txq_id));
1019
1020 /* Place first TFD at index corresponding to start sequence number.
1021 * Assumes that ssn_idx is valid (!= 0xFFF) */
1022 priv->txq[txq_id].q.read_ptr = (ssn_idx & 0xff);
1023 priv->txq[txq_id].q.write_ptr = (ssn_idx & 0xff);
1024 iwl5000_set_wr_ptrs(priv, txq_id, ssn_idx);
1025
1026 /* Set up Tx window size and frame limit for this queue */
1027 iwl_write_targ_mem(priv, priv->scd_base_addr +
1028 IWL50_SCD_CONTEXT_QUEUE_OFFSET(txq_id) +
1029 sizeof(u32),
1030 ((SCD_WIN_SIZE <<
1031 IWL50_SCD_QUEUE_CTX_REG2_WIN_SIZE_POS) &
1032 IWL50_SCD_QUEUE_CTX_REG2_WIN_SIZE_MSK) |
1033 ((SCD_FRAME_LIMIT <<
1034 IWL50_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
1035 IWL50_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK));
1036
1037 iwl_set_bits_prph(priv, IWL50_SCD_INTERRUPT_MASK, (1 << txq_id));
1038
1039 /* Set up Status area in SRAM, map to Tx DMA/FIFO, activate the queue */
1040 iwl5000_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 1);
1041
1042 iwl_release_nic_access(priv);
1043 spin_unlock_irqrestore(&priv->lock, flags);
1044
1045 return 0;
1046}
1047
1048static int iwl5000_txq_agg_disable(struct iwl_priv *priv, u16 txq_id,
1049 u16 ssn_idx, u8 tx_fifo)
1050{
1051 int ret;
1052
1053 if ((IWL50_FIRST_AMPDU_QUEUE > txq_id) ||
1054 (IWL50_FIRST_AMPDU_QUEUE + IWL50_NUM_AMPDU_QUEUES <= txq_id)) {
1055 IWL_WARNING("queue number out of range: %d, must be %d to %d\n",
1056 txq_id, IWL50_FIRST_AMPDU_QUEUE,
1057 IWL50_FIRST_AMPDU_QUEUE + IWL50_NUM_AMPDU_QUEUES - 1);
1058 return -EINVAL;
1059 }
1060
1061 ret = iwl_grab_nic_access(priv);
1062 if (ret)
1063 return ret;
1064
1065 iwl5000_tx_queue_stop_scheduler(priv, txq_id);
1066
1067 iwl_clear_bits_prph(priv, IWL50_SCD_AGGR_SEL, (1 << txq_id));
1068
1069 priv->txq[txq_id].q.read_ptr = (ssn_idx & 0xff);
1070 priv->txq[txq_id].q.write_ptr = (ssn_idx & 0xff);
1071 /* supposes that ssn_idx is valid (!= 0xFFF) */
1072 iwl5000_set_wr_ptrs(priv, txq_id, ssn_idx);
1073
1074 iwl_clear_bits_prph(priv, IWL50_SCD_INTERRUPT_MASK, (1 << txq_id));
1075 iwl_txq_ctx_deactivate(priv, txq_id);
1076 iwl5000_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 0);
1077
1078 iwl_release_nic_access(priv);
1079
1080 return 0;
1081}
1082
1083static u16 iwl5000_build_addsta_hcmd(const struct iwl_addsta_cmd *cmd, u8 *data)
1084{
1085 u16 size = (u16)sizeof(struct iwl_addsta_cmd);
1086 memcpy(data, cmd, size);
1087 return size;
1088}
1089
1090
1091/*
1092 * Activate/Deactivat Tx DMA/FIFO channels according tx fifos mask
1093 * must be called under priv->lock and mac access
1094 */
1095static void iwl5000_txq_set_sched(struct iwl_priv *priv, u32 mask)
1096{
1097 iwl_write_prph(priv, IWL50_SCD_TXFACT, mask);
1098}
1099
1100
1101static inline u32 iwl5000_get_scd_ssn(struct iwl5000_tx_resp *tx_resp)
1102{
1103 return le32_to_cpup((__le32 *)&tx_resp->status +
1104 tx_resp->frame_count) & MAX_SN;
1105}
1106
1107static int iwl5000_tx_status_reply_tx(struct iwl_priv *priv,
1108 struct iwl_ht_agg *agg,
1109 struct iwl5000_tx_resp *tx_resp,
1110 int txq_id, u16 start_idx)
1111{
1112 u16 status;
1113 struct agg_tx_status *frame_status = &tx_resp->status;
1114 struct ieee80211_tx_info *info = NULL;
1115 struct ieee80211_hdr *hdr = NULL;
1116 u32 rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
1117 int i, sh, idx;
1118 u16 seq;
1119
1120 if (agg->wait_for_ba)
1121 IWL_DEBUG_TX_REPLY("got tx response w/o block-ack\n");
1122
1123 agg->frame_count = tx_resp->frame_count;
1124 agg->start_idx = start_idx;
1125 agg->rate_n_flags = rate_n_flags;
1126 agg->bitmap = 0;
1127
1128 /* # frames attempted by Tx command */
1129 if (agg->frame_count == 1) {
1130 /* Only one frame was attempted; no block-ack will arrive */
1131 status = le16_to_cpu(frame_status[0].status);
1132 idx = start_idx;
1133
1134 /* FIXME: code repetition */
1135 IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d idx=%d\n",
1136 agg->frame_count, agg->start_idx, idx);
1137
1138 info = IEEE80211_SKB_CB(priv->txq[txq_id].txb[idx].skb[0]);
1139 info->status.retry_count = tx_resp->failure_frame;
1140 info->flags &= ~IEEE80211_TX_CTL_AMPDU;
1141 info->flags |= iwl_is_tx_success(status)?
1142 IEEE80211_TX_STAT_ACK : 0;
1143 iwl_hwrate_to_tx_control(priv, rate_n_flags, info);
1144
1145 /* FIXME: code repetition end */
1146
1147 IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n",
1148 status & 0xff, tx_resp->failure_frame);
1149 IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n", rate_n_flags);
1150
1151 agg->wait_for_ba = 0;
1152 } else {
1153 /* Two or more frames were attempted; expect block-ack */
1154 u64 bitmap = 0;
1155 int start = agg->start_idx;
1156
1157 /* Construct bit-map of pending frames within Tx window */
1158 for (i = 0; i < agg->frame_count; i++) {
1159 u16 sc;
1160 status = le16_to_cpu(frame_status[i].status);
1161 seq = le16_to_cpu(frame_status[i].sequence);
1162 idx = SEQ_TO_INDEX(seq);
1163 txq_id = SEQ_TO_QUEUE(seq);
1164
1165 if (status & (AGG_TX_STATE_FEW_BYTES_MSK |
1166 AGG_TX_STATE_ABORT_MSK))
1167 continue;
1168
1169 IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n",
1170 agg->frame_count, txq_id, idx);
1171
1172 hdr = iwl_tx_queue_get_hdr(priv, txq_id, idx);
1173
1174 sc = le16_to_cpu(hdr->seq_ctrl);
1175 if (idx != (SEQ_TO_SN(sc) & 0xff)) {
1176 IWL_ERROR("BUG_ON idx doesn't match seq control"
1177 " idx=%d, seq_idx=%d, seq=%d\n",
1178 idx, SEQ_TO_SN(sc),
1179 hdr->seq_ctrl);
1180 return -1;
1181 }
1182
1183 IWL_DEBUG_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n",
1184 i, idx, SEQ_TO_SN(sc));
1185
1186 sh = idx - start;
1187 if (sh > 64) {
1188 sh = (start - idx) + 0xff;
1189 bitmap = bitmap << sh;
1190 sh = 0;
1191 start = idx;
1192 } else if (sh < -64)
1193 sh = 0xff - (start - idx);
1194 else if (sh < 0) {
1195 sh = start - idx;
1196 start = idx;
1197 bitmap = bitmap << sh;
1198 sh = 0;
1199 }
1200 bitmap |= 1ULL << sh;
1201 IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%llx\n",
1202 start, (unsigned long long)bitmap);
1203 }
1204
1205 agg->bitmap = bitmap;
1206 agg->start_idx = start;
1207 IWL_DEBUG_TX_REPLY("Frames %d start_idx=%d bitmap=0x%llx\n",
1208 agg->frame_count, agg->start_idx,
1209 (unsigned long long)agg->bitmap);
1210
1211 if (bitmap)
1212 agg->wait_for_ba = 1;
1213 }
1214 return 0;
1215}
1216
1217static void iwl5000_rx_reply_tx(struct iwl_priv *priv,
1218 struct iwl_rx_mem_buffer *rxb)
1219{
1220 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
1221 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
1222 int txq_id = SEQ_TO_QUEUE(sequence);
1223 int index = SEQ_TO_INDEX(sequence);
1224 struct iwl_tx_queue *txq = &priv->txq[txq_id];
1225 struct ieee80211_tx_info *info;
1226 struct iwl5000_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
1227 u32 status = le16_to_cpu(tx_resp->status.status);
1228 int tid = MAX_TID_COUNT, sta_id = IWL_INVALID_STATION;
1229 struct ieee80211_hdr *hdr;
1230 u8 *qc = NULL;
1231
1232 if ((index >= txq->q.n_bd) || (iwl_queue_used(&txq->q, index) == 0)) {
1233 IWL_ERROR("Read index for DMA queue txq_id (%d) index %d "
1234 "is out of range [0-%d] %d %d\n", txq_id,
1235 index, txq->q.n_bd, txq->q.write_ptr,
1236 txq->q.read_ptr);
1237 return;
1238 }
1239
1240 info = IEEE80211_SKB_CB(txq->txb[txq->q.read_ptr].skb[0]);
1241 memset(&info->status, 0, sizeof(info->status));
1242
1243 hdr = iwl_tx_queue_get_hdr(priv, txq_id, index);
1244 if (ieee80211_is_data_qos(hdr->frame_control)) {
1245 qc = ieee80211_get_qos_ctl(hdr);
1246 tid = qc[0] & 0xf;
1247 }
1248
1249 sta_id = iwl_get_ra_sta_id(priv, hdr);
1250 if (txq->sched_retry && unlikely(sta_id == IWL_INVALID_STATION)) {
1251 IWL_ERROR("Station not known\n");
1252 return;
1253 }
1254
1255 if (txq->sched_retry) {
1256 const u32 scd_ssn = iwl5000_get_scd_ssn(tx_resp);
1257 struct iwl_ht_agg *agg = NULL;
1258
1259 if (!qc)
1260 return;
1261
1262 agg = &priv->stations[sta_id].tid[tid].agg;
1263
1264 iwl5000_tx_status_reply_tx(priv, agg, tx_resp, txq_id, index);
1265
1266 /* check if BAR is needed */
1267 if ((tx_resp->frame_count == 1) && !iwl_is_tx_success(status))
1268 info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK;
1269
1270 if (txq->q.read_ptr != (scd_ssn & 0xff)) {
1271 int freed, ampdu_q;
1272 index = iwl_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd);
1273 IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn "
1274 "%d index %d\n", scd_ssn , index);
1275 freed = iwl_tx_queue_reclaim(priv, txq_id, index);
1276 priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
1277
1278 if (iwl_queue_space(&txq->q) > txq->q.low_mark &&
1279 txq_id >= 0 && priv->mac80211_registered &&
1280 agg->state != IWL_EMPTYING_HW_QUEUE_DELBA) {
1281 /* calculate mac80211 ampdu sw queue to wake */
1282 ampdu_q = txq_id - IWL50_FIRST_AMPDU_QUEUE +
1283 priv->hw->queues;
1284 if (agg->state == IWL_AGG_OFF)
1285 ieee80211_wake_queue(priv->hw, txq_id);
1286 else
1287 ieee80211_wake_queue(priv->hw, ampdu_q);
1288 }
1289 iwl_txq_check_empty(priv, sta_id, tid, txq_id);
1290 }
1291 } else {
1292 info->status.retry_count = tx_resp->failure_frame;
1293 info->flags =
1294 iwl_is_tx_success(status) ? IEEE80211_TX_STAT_ACK : 0;
1295 iwl_hwrate_to_tx_control(priv,
1296 le32_to_cpu(tx_resp->rate_n_flags),
1297 info);
1298
1299 IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) rate_n_flags "
1300 "0x%x retries %d\n", txq_id,
1301 iwl_get_tx_fail_reason(status),
1302 status, le32_to_cpu(tx_resp->rate_n_flags),
1303 tx_resp->failure_frame);
1304
1305 IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index);
1306 if (index != -1) {
1307 int freed = iwl_tx_queue_reclaim(priv, txq_id, index);
1308 if (tid != MAX_TID_COUNT)
1309 priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
1310 if (iwl_queue_space(&txq->q) > txq->q.low_mark &&
1311 (txq_id >= 0) && priv->mac80211_registered)
1312 ieee80211_wake_queue(priv->hw, txq_id);
1313 if (tid != MAX_TID_COUNT)
1314 iwl_txq_check_empty(priv, sta_id, tid, txq_id);
1315 }
1316 }
1317
1318 if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK))
1319 IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n");
1320}
1321
1322/* Currently 5000 is the supperset of everything */
1323static u16 iwl5000_get_hcmd_size(u8 cmd_id, u16 len)
1324{
1325 return len;
1326}
1327
1328static void iwl5000_setup_deferred_work(struct iwl_priv *priv)
1329{
1330 /* in 5000 the tx power calibration is done in uCode */
1331 priv->disable_tx_power_cal = 1;
1332}
1333
1334static void iwl5000_rx_handler_setup(struct iwl_priv *priv)
1335{
1336 /* init calibration handlers */
1337 priv->rx_handlers[CALIBRATION_RES_NOTIFICATION] =
1338 iwl5000_rx_calib_result;
1339 priv->rx_handlers[CALIBRATION_COMPLETE_NOTIFICATION] =
1340 iwl5000_rx_calib_complete;
1341 priv->rx_handlers[REPLY_TX] = iwl5000_rx_reply_tx;
1342}
1343
1344
1345static int iwl5000_hw_valid_rtc_data_addr(u32 addr)
1346{
1347 return (addr >= RTC_DATA_LOWER_BOUND) &&
1348 (addr < IWL50_RTC_DATA_UPPER_BOUND);
1349}
1350
1351static int iwl5000_send_rxon_assoc(struct iwl_priv *priv)
1352{
1353 int ret = 0;
1354 struct iwl5000_rxon_assoc_cmd rxon_assoc;
1355 const struct iwl_rxon_cmd *rxon1 = &priv->staging_rxon;
1356 const struct iwl_rxon_cmd *rxon2 = &priv->active_rxon;
1357
1358 if ((rxon1->flags == rxon2->flags) &&
1359 (rxon1->filter_flags == rxon2->filter_flags) &&
1360 (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
1361 (rxon1->ofdm_ht_single_stream_basic_rates ==
1362 rxon2->ofdm_ht_single_stream_basic_rates) &&
1363 (rxon1->ofdm_ht_dual_stream_basic_rates ==
1364 rxon2->ofdm_ht_dual_stream_basic_rates) &&
1365 (rxon1->ofdm_ht_triple_stream_basic_rates ==
1366 rxon2->ofdm_ht_triple_stream_basic_rates) &&
1367 (rxon1->acquisition_data == rxon2->acquisition_data) &&
1368 (rxon1->rx_chain == rxon2->rx_chain) &&
1369 (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
1370 IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n");
1371 return 0;
1372 }
1373
1374 rxon_assoc.flags = priv->staging_rxon.flags;
1375 rxon_assoc.filter_flags = priv->staging_rxon.filter_flags;
1376 rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates;
1377 rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates;
1378 rxon_assoc.reserved1 = 0;
1379 rxon_assoc.reserved2 = 0;
1380 rxon_assoc.reserved3 = 0;
1381 rxon_assoc.ofdm_ht_single_stream_basic_rates =
1382 priv->staging_rxon.ofdm_ht_single_stream_basic_rates;
1383 rxon_assoc.ofdm_ht_dual_stream_basic_rates =
1384 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates;
1385 rxon_assoc.rx_chain_select_flags = priv->staging_rxon.rx_chain;
1386 rxon_assoc.ofdm_ht_triple_stream_basic_rates =
1387 priv->staging_rxon.ofdm_ht_triple_stream_basic_rates;
1388 rxon_assoc.acquisition_data = priv->staging_rxon.acquisition_data;
1389
1390 ret = iwl_send_cmd_pdu_async(priv, REPLY_RXON_ASSOC,
1391 sizeof(rxon_assoc), &rxon_assoc, NULL);
1392 if (ret)
1393 return ret;
1394
1395 return ret;
1396}
1397static int iwl5000_send_tx_power(struct iwl_priv *priv)
1398{
1399 struct iwl5000_tx_power_dbm_cmd tx_power_cmd;
1400
1401 /* half dBm need to multiply */
1402 tx_power_cmd.global_lmt = (s8)(2 * priv->tx_power_user_lmt);
1403 tx_power_cmd.flags = IWL50_TX_POWER_NO_CLOSED;
1404 tx_power_cmd.srv_chan_lmt = IWL50_TX_POWER_AUTO;
1405 return iwl_send_cmd_pdu_async(priv, REPLY_TX_POWER_DBM_CMD,
1406 sizeof(tx_power_cmd), &tx_power_cmd,
1407 NULL);
1408}
1409
1410static void iwl5000_temperature(struct iwl_priv *priv)
1411{
1412 /* store temperature from statistics (in Celsius) */
1413 priv->temperature = le32_to_cpu(priv->statistics.general.temperature);
1414}
1415
1416/* Calc max signal level (dBm) among 3 possible receivers */
1417static int iwl5000_calc_rssi(struct iwl_priv *priv,
1418 struct iwl_rx_phy_res *rx_resp)
1419{
1420 /* data from PHY/DSP regarding signal strength, etc.,
1421 * contents are always there, not configurable by host
1422 */
1423 struct iwl5000_non_cfg_phy *ncphy =
1424 (struct iwl5000_non_cfg_phy *)rx_resp->non_cfg_phy_buf;
1425 u32 val, rssi_a, rssi_b, rssi_c, max_rssi;
1426 u8 agc;
1427
1428 val = le32_to_cpu(ncphy->non_cfg_phy[IWL50_RX_RES_AGC_IDX]);
1429 agc = (val & IWL50_OFDM_AGC_MSK) >> IWL50_OFDM_AGC_BIT_POS;
1430
1431 /* Find max rssi among 3 possible receivers.
1432 * These values are measured by the digital signal processor (DSP).
1433 * They should stay fairly constant even as the signal strength varies,
1434 * if the radio's automatic gain control (AGC) is working right.
1435 * AGC value (see below) will provide the "interesting" info.
1436 */
1437 val = le32_to_cpu(ncphy->non_cfg_phy[IWL50_RX_RES_RSSI_AB_IDX]);
1438 rssi_a = (val & IWL50_OFDM_RSSI_A_MSK) >> IWL50_OFDM_RSSI_A_BIT_POS;
1439 rssi_b = (val & IWL50_OFDM_RSSI_B_MSK) >> IWL50_OFDM_RSSI_B_BIT_POS;
1440 val = le32_to_cpu(ncphy->non_cfg_phy[IWL50_RX_RES_RSSI_C_IDX]);
1441 rssi_c = (val & IWL50_OFDM_RSSI_C_MSK) >> IWL50_OFDM_RSSI_C_BIT_POS;
1442
1443 max_rssi = max_t(u32, rssi_a, rssi_b);
1444 max_rssi = max_t(u32, max_rssi, rssi_c);
1445
1446 IWL_DEBUG_STATS("Rssi In A %d B %d C %d Max %d AGC dB %d\n",
1447 rssi_a, rssi_b, rssi_c, max_rssi, agc);
1448
1449 /* dBm = max_rssi dB - agc dB - constant.
1450 * Higher AGC (higher radio gain) means lower signal. */
1451 return max_rssi - agc - IWL_RSSI_OFFSET;
1452}
1453
1454static struct iwl_hcmd_ops iwl5000_hcmd = {
1455 .rxon_assoc = iwl5000_send_rxon_assoc,
1456};
1457
1458static struct iwl_hcmd_utils_ops iwl5000_hcmd_utils = {
1459 .get_hcmd_size = iwl5000_get_hcmd_size,
1460 .build_addsta_hcmd = iwl5000_build_addsta_hcmd,
1461 .gain_computation = iwl5000_gain_computation,
1462 .chain_noise_reset = iwl5000_chain_noise_reset,
1463 .rts_tx_cmd_flag = iwl5000_rts_tx_cmd_flag,
1464 .calc_rssi = iwl5000_calc_rssi,
1465};
1466
1467static struct iwl_lib_ops iwl5000_lib = {
1468 .set_hw_params = iwl5000_hw_set_hw_params,
1469 .alloc_shared_mem = iwl5000_alloc_shared_mem,
1470 .free_shared_mem = iwl5000_free_shared_mem,
1471 .shared_mem_rx_idx = iwl5000_shared_mem_rx_idx,
1472 .txq_update_byte_cnt_tbl = iwl5000_txq_update_byte_cnt_tbl,
1473 .txq_inval_byte_cnt_tbl = iwl5000_txq_inval_byte_cnt_tbl,
1474 .txq_set_sched = iwl5000_txq_set_sched,
1475 .txq_agg_enable = iwl5000_txq_agg_enable,
1476 .txq_agg_disable = iwl5000_txq_agg_disable,
1477 .rx_handler_setup = iwl5000_rx_handler_setup,
1478 .setup_deferred_work = iwl5000_setup_deferred_work,
1479 .is_valid_rtc_data_addr = iwl5000_hw_valid_rtc_data_addr,
1480 .load_ucode = iwl5000_load_ucode,
1481 .init_alive_start = iwl5000_init_alive_start,
1482 .alive_notify = iwl5000_alive_notify,
1483 .send_tx_power = iwl5000_send_tx_power,
1484 .temperature = iwl5000_temperature,
1485 .update_chain_flags = iwl4965_update_chain_flags,
1486 .apm_ops = {
1487 .init = iwl5000_apm_init,
1488 .reset = iwl5000_apm_reset,
1489 .stop = iwl5000_apm_stop,
1490 .config = iwl5000_nic_config,
1491 .set_pwr_src = iwl4965_set_pwr_src,
1492 },
1493 .eeprom_ops = {
1494 .regulatory_bands = {
1495 EEPROM_5000_REG_BAND_1_CHANNELS,
1496 EEPROM_5000_REG_BAND_2_CHANNELS,
1497 EEPROM_5000_REG_BAND_3_CHANNELS,
1498 EEPROM_5000_REG_BAND_4_CHANNELS,
1499 EEPROM_5000_REG_BAND_5_CHANNELS,
1500 EEPROM_5000_REG_BAND_24_FAT_CHANNELS,
1501 EEPROM_5000_REG_BAND_52_FAT_CHANNELS
1502 },
1503 .verify_signature = iwlcore_eeprom_verify_signature,
1504 .acquire_semaphore = iwlcore_eeprom_acquire_semaphore,
1505 .release_semaphore = iwlcore_eeprom_release_semaphore,
1506 .check_version = iwl5000_eeprom_check_version,
1507 .query_addr = iwl5000_eeprom_query_addr,
1508 },
1509};
1510
1511static struct iwl_ops iwl5000_ops = {
1512 .lib = &iwl5000_lib,
1513 .hcmd = &iwl5000_hcmd,
1514 .utils = &iwl5000_hcmd_utils,
1515};
1516
1517static struct iwl_mod_params iwl50_mod_params = {
1518 .num_of_queues = IWL50_NUM_QUEUES,
1519 .num_of_ampdu_queues = IWL50_NUM_AMPDU_QUEUES,
1520 .enable_qos = 1,
1521 .amsdu_size_8K = 1,
1522 .restart_fw = 1,
1523 /* the rest are 0 by default */
1524};
1525
1526
1527struct iwl_cfg iwl5300_agn_cfg = {
1528 .name = "5300AGN",
1529 .fw_name = "iwlwifi-5000" IWL5000_UCODE_API ".ucode",
1530 .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
1531 .ops = &iwl5000_ops,
1532 .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
1533 .mod_params = &iwl50_mod_params,
1534};
1535
1536struct iwl_cfg iwl5100_bg_cfg = {
1537 .name = "5100BG",
1538 .fw_name = "iwlwifi-5000" IWL5000_UCODE_API ".ucode",
1539 .sku = IWL_SKU_G,
1540 .ops = &iwl5000_ops,
1541 .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
1542 .mod_params = &iwl50_mod_params,
1543};
1544
1545struct iwl_cfg iwl5100_abg_cfg = {
1546 .name = "5100ABG",
1547 .fw_name = "iwlwifi-5000" IWL5000_UCODE_API ".ucode",
1548 .sku = IWL_SKU_A|IWL_SKU_G,
1549 .ops = &iwl5000_ops,
1550 .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
1551 .mod_params = &iwl50_mod_params,
1552};
1553
1554struct iwl_cfg iwl5100_agn_cfg = {
1555 .name = "5100AGN",
1556 .fw_name = "iwlwifi-5000" IWL5000_UCODE_API ".ucode",
1557 .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
1558 .ops = &iwl5000_ops,
1559 .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
1560 .mod_params = &iwl50_mod_params,
1561};
1562
1563struct iwl_cfg iwl5350_agn_cfg = {
1564 .name = "5350AGN",
1565 .fw_name = "iwlwifi-5000" IWL5000_UCODE_API ".ucode",
1566 .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
1567 .ops = &iwl5000_ops,
1568 .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
1569 .mod_params = &iwl50_mod_params,
1570};
1571
1572MODULE_FIRMWARE("iwlwifi-5000" IWL5000_UCODE_API ".ucode");
1573
1574module_param_named(disable50, iwl50_mod_params.disable, int, 0444);
1575MODULE_PARM_DESC(disable50,
1576 "manually disable the 50XX radio (default 0 [radio on])");
1577module_param_named(swcrypto50, iwl50_mod_params.sw_crypto, bool, 0444);
1578MODULE_PARM_DESC(swcrypto50,
1579 "using software crypto engine (default 0 [hardware])\n");
1580module_param_named(debug50, iwl50_mod_params.debug, int, 0444);
1581MODULE_PARM_DESC(debug50, "50XX debug output mask");
1582module_param_named(queues_num50, iwl50_mod_params.num_of_queues, int, 0444);
1583MODULE_PARM_DESC(queues_num50, "number of hw queues in 50xx series");
1584module_param_named(qos_enable50, iwl50_mod_params.enable_qos, int, 0444);
1585MODULE_PARM_DESC(qos_enable50, "enable all 50XX QoS functionality");
1586module_param_named(11n_disable50, iwl50_mod_params.disable_11n, int, 0444);
1587MODULE_PARM_DESC(11n_disable50, "disable 50XX 11n functionality");
1588module_param_named(amsdu_size_8K50, iwl50_mod_params.amsdu_size_8K, int, 0444);
1589MODULE_PARM_DESC(amsdu_size_8K50, "enable 8K amsdu size in 50XX series");
1590module_param_named(fw_restart50, iwl50_mod_params.restart_fw, int, 0444);
1591MODULE_PARM_DESC(fw_restart50, "restart firmware in case of error");
diff --git a/drivers/net/wireless/iwlwifi/iwl-4965-rs.c b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
index 3a7f0cb710ec..e2a58e477036 100644
--- a/drivers/net/wireless/iwlwifi/iwl-4965-rs.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
@@ -28,7 +28,6 @@
28#include <linux/skbuff.h> 28#include <linux/skbuff.h>
29#include <linux/wireless.h> 29#include <linux/wireless.h>
30#include <net/mac80211.h> 30#include <net/mac80211.h>
31#include <net/ieee80211.h>
32 31
33#include <linux/netdevice.h> 32#include <linux/netdevice.h>
34#include <linux/etherdevice.h> 33#include <linux/etherdevice.h>
@@ -36,15 +35,14 @@
36 35
37#include <linux/workqueue.h> 36#include <linux/workqueue.h>
38 37
39#include "../net/mac80211/rate.h" 38#include "iwl-dev.h"
40 39#include "iwl-sta.h"
41#include "iwl-4965.h"
42#include "iwl-core.h" 40#include "iwl-core.h"
43#include "iwl-helpers.h" 41#include "iwl-helpers.h"
44 42
45#define RS_NAME "iwl-4965-rs" 43#define RS_NAME "iwl-agn-rs"
46 44
47#define NUM_TRY_BEFORE_ANTENNA_TOGGLE 1 45#define NUM_TRY_BEFORE_ANT_TOGGLE 1
48#define IWL_NUMBER_TRY 1 46#define IWL_NUMBER_TRY 1
49#define IWL_HT_NUMBER_TRY 3 47#define IWL_HT_NUMBER_TRY 3
50 48
@@ -65,14 +63,21 @@ static u8 rs_ht_to_legacy[] = {
65 IWL_RATE_48M_INDEX, IWL_RATE_54M_INDEX 63 IWL_RATE_48M_INDEX, IWL_RATE_54M_INDEX
66}; 64};
67 65
68struct iwl4965_rate { 66static const u8 ant_toggle_lookup[] = {
69 u32 rate_n_flags; 67 /*ANT_NONE -> */ ANT_NONE,
70} __attribute__ ((packed)); 68 /*ANT_A -> */ ANT_B,
69 /*ANT_B -> */ ANT_C,
70 /*ANT_AB -> */ ANT_BC,
71 /*ANT_C -> */ ANT_A,
72 /*ANT_AC -> */ ANT_AB,
73 /*ANT_BC -> */ ANT_AC,
74 /*ANT_ABC -> */ ANT_ABC,
75};
71 76
72/** 77/**
73 * struct iwl4965_rate_scale_data -- tx success history for one rate 78 * struct iwl_rate_scale_data -- tx success history for one rate
74 */ 79 */
75struct iwl4965_rate_scale_data { 80struct iwl_rate_scale_data {
76 u64 data; /* bitmap of successful frames */ 81 u64 data; /* bitmap of successful frames */
77 s32 success_counter; /* number of frames successful */ 82 s32 success_counter; /* number of frames successful */
78 s32 success_ratio; /* per-cent * 128 */ 83 s32 success_ratio; /* per-cent * 128 */
@@ -82,26 +87,24 @@ struct iwl4965_rate_scale_data {
82}; 87};
83 88
84/** 89/**
85 * struct iwl4965_scale_tbl_info -- tx params and success history for all rates 90 * struct iwl_scale_tbl_info -- tx params and success history for all rates
86 * 91 *
87 * There are two of these in struct iwl4965_lq_sta, 92 * There are two of these in struct iwl_lq_sta,
88 * one for "active", and one for "search". 93 * one for "active", and one for "search".
89 */ 94 */
90struct iwl4965_scale_tbl_info { 95struct iwl_scale_tbl_info {
91 enum iwl4965_table_type lq_type; 96 enum iwl_table_type lq_type;
92 enum iwl4965_antenna_type antenna_type; 97 u8 ant_type;
93 u8 is_SGI; /* 1 = short guard interval */ 98 u8 is_SGI; /* 1 = short guard interval */
94 u8 is_fat; /* 1 = 40 MHz channel width */ 99 u8 is_fat; /* 1 = 40 MHz channel width */
95 u8 is_dup; /* 1 = duplicated data streams */ 100 u8 is_dup; /* 1 = duplicated data streams */
96 u8 action; /* change modulation; IWL_[LEGACY/SISO/MIMO]_SWITCH_* */ 101 u8 action; /* change modulation; IWL_[LEGACY/SISO/MIMO]_SWITCH_* */
97 s32 *expected_tpt; /* throughput metrics; expected_tpt_G, etc. */ 102 s32 *expected_tpt; /* throughput metrics; expected_tpt_G, etc. */
98 struct iwl4965_rate current_rate; /* rate_n_flags, uCode API format */ 103 u32 current_rate; /* rate_n_flags, uCode API format */
99 struct iwl4965_rate_scale_data win[IWL_RATE_COUNT]; /* rate histories */ 104 struct iwl_rate_scale_data win[IWL_RATE_COUNT]; /* rate histories */
100}; 105};
101 106
102#ifdef CONFIG_IWL4965_HT 107struct iwl_traffic_load {
103
104struct iwl4965_traffic_load {
105 unsigned long time_stamp; /* age of the oldest statistics */ 108 unsigned long time_stamp; /* age of the oldest statistics */
106 u32 packet_count[TID_QUEUE_MAX_SIZE]; /* packet count in this time 109 u32 packet_count[TID_QUEUE_MAX_SIZE]; /* packet count in this time
107 * slice */ 110 * slice */
@@ -112,14 +115,12 @@ struct iwl4965_traffic_load {
112 u8 head; /* start of the circular buffer */ 115 u8 head; /* start of the circular buffer */
113}; 116};
114 117
115#endif /* CONFIG_IWL4965_HT */
116
117/** 118/**
118 * struct iwl4965_lq_sta -- driver's rate scaling private structure 119 * struct iwl_lq_sta -- driver's rate scaling private structure
119 * 120 *
120 * Pointer to this gets passed back and forth between driver and mac80211. 121 * Pointer to this gets passed back and forth between driver and mac80211.
121 */ 122 */
122struct iwl4965_lq_sta { 123struct iwl_lq_sta {
123 u8 active_tbl; /* index of active table, range 0-1 */ 124 u8 active_tbl; /* index of active table, range 0-1 */
124 u8 enable_counter; /* indicates HT mode */ 125 u8 enable_counter; /* indicates HT mode */
125 u8 stay_in_tbl; /* 1: disallow, 0: allow search for new mode */ 126 u8 stay_in_tbl; /* 1: disallow, 0: allow search for new mode */
@@ -136,8 +137,6 @@ struct iwl4965_lq_sta {
136 u32 flush_timer; /* time staying in mode before new search */ 137 u32 flush_timer; /* time staying in mode before new search */
137 138
138 u8 action_counter; /* # mode-switch actions tried */ 139 u8 action_counter; /* # mode-switch actions tried */
139 u8 antenna;
140 u8 valid_antenna;
141 u8 is_green; 140 u8 is_green;
142 u8 is_dup; 141 u8 is_dup;
143 enum ieee80211_band band; 142 enum ieee80211_band band;
@@ -145,43 +144,42 @@ struct iwl4965_lq_sta {
145 144
146 /* The following are bitmaps of rates; IWL_RATE_6M_MASK, etc. */ 145 /* The following are bitmaps of rates; IWL_RATE_6M_MASK, etc. */
147 u32 supp_rates; 146 u32 supp_rates;
148 u16 active_rate; 147 u16 active_legacy_rate;
149 u16 active_siso_rate; 148 u16 active_siso_rate;
150 u16 active_mimo_rate; 149 u16 active_mimo2_rate;
150 u16 active_mimo3_rate;
151 u16 active_rate_basic; 151 u16 active_rate_basic;
152 152
153 struct iwl_link_quality_cmd lq; 153 struct iwl_link_quality_cmd lq;
154 struct iwl4965_scale_tbl_info lq_info[LQ_SIZE]; /* "active", "search" */ 154 struct iwl_scale_tbl_info lq_info[LQ_SIZE]; /* "active", "search" */
155#ifdef CONFIG_IWL4965_HT 155 struct iwl_traffic_load load[TID_MAX_LOAD_COUNT];
156 struct iwl4965_traffic_load load[TID_MAX_LOAD_COUNT];
157 u8 tx_agg_tid_en; 156 u8 tx_agg_tid_en;
158#endif
159#ifdef CONFIG_MAC80211_DEBUGFS 157#ifdef CONFIG_MAC80211_DEBUGFS
160 struct dentry *rs_sta_dbgfs_scale_table_file; 158 struct dentry *rs_sta_dbgfs_scale_table_file;
161 struct dentry *rs_sta_dbgfs_stats_table_file; 159 struct dentry *rs_sta_dbgfs_stats_table_file;
162#ifdef CONFIG_IWL4965_HT
163 struct dentry *rs_sta_dbgfs_tx_agg_tid_en_file; 160 struct dentry *rs_sta_dbgfs_tx_agg_tid_en_file;
164#endif 161 u32 dbg_fixed_rate;
165 struct iwl4965_rate dbg_fixed;
166#endif 162#endif
167 struct iwl_priv *drv; 163 struct iwl_priv *drv;
164
165 /* used to be in sta_info */
166 int last_txrate_idx;
168}; 167};
169 168
170static void rs_rate_scale_perform(struct iwl_priv *priv, 169static void rs_rate_scale_perform(struct iwl_priv *priv,
171 struct net_device *dev,
172 struct ieee80211_hdr *hdr, 170 struct ieee80211_hdr *hdr,
173 struct sta_info *sta); 171 struct ieee80211_sta *sta,
174static void rs_fill_link_cmd(struct iwl4965_lq_sta *lq_sta, 172 struct iwl_lq_sta *lq_sta);
175 struct iwl4965_rate *tx_mcs, 173static void rs_fill_link_cmd(const struct iwl_priv *priv,
176 struct iwl_link_quality_cmd *tbl); 174 struct iwl_lq_sta *lq_sta, u32 rate_n_flags);
177 175
178 176
179#ifdef CONFIG_MAC80211_DEBUGFS 177#ifdef CONFIG_MAC80211_DEBUGFS
180static void rs_dbgfs_set_mcs(struct iwl4965_lq_sta *lq_sta, 178static void rs_dbgfs_set_mcs(struct iwl_lq_sta *lq_sta,
181 struct iwl4965_rate *mcs, int index); 179 u32 *rate_n_flags, int index);
182#else 180#else
183static void rs_dbgfs_set_mcs(struct iwl4965_lq_sta *lq_sta, 181static void rs_dbgfs_set_mcs(struct iwl_lq_sta *lq_sta,
184 struct iwl4965_rate *mcs, int index) 182 u32 *rate_n_flags, int index)
185{} 183{}
186#endif 184#endif
187 185
@@ -190,6 +188,7 @@ static void rs_dbgfs_set_mcs(struct iwl4965_lq_sta *lq_sta,
190 * 1, 2, 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54, 60 MBits 188 * 1, 2, 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54, 60 MBits
191 * "G" is the only table that supports CCK (the first 4 rates). 189 * "G" is the only table that supports CCK (the first 4 rates).
192 */ 190 */
191/*FIXME:RS:need to spearate tables for MIMO2/MIMO3*/
193static s32 expected_tpt_A[IWL_RATE_COUNT] = { 192static s32 expected_tpt_A[IWL_RATE_COUNT] = {
194 0, 0, 0, 0, 40, 57, 72, 98, 121, 154, 177, 186, 186 193 0, 0, 0, 0, 40, 57, 72, 98, 121, 154, 177, 186, 186
195}; 194};
@@ -230,12 +229,12 @@ static s32 expected_tpt_mimo40MHzSGI[IWL_RATE_COUNT] = {
230 0, 0, 0, 0, 131, 131, 191, 222, 242, 270, 284, 289, 293 229 0, 0, 0, 0, 131, 131, 191, 222, 242, 270, 284, 289, 293
231}; 230};
232 231
233static inline u8 iwl4965_rate_get_rate(u32 rate_n_flags) 232static inline u8 rs_extract_rate(u32 rate_n_flags)
234{ 233{
235 return (u8)(rate_n_flags & 0xFF); 234 return (u8)(rate_n_flags & 0xFF);
236} 235}
237 236
238static void rs_rate_scale_clear_window(struct iwl4965_rate_scale_data *window) 237static void rs_rate_scale_clear_window(struct iwl_rate_scale_data *window)
239{ 238{
240 window->data = 0; 239 window->data = 0;
241 window->success_counter = 0; 240 window->success_counter = 0;
@@ -245,12 +244,16 @@ static void rs_rate_scale_clear_window(struct iwl4965_rate_scale_data *window)
245 window->stamp = 0; 244 window->stamp = 0;
246} 245}
247 246
248#ifdef CONFIG_IWL4965_HT 247static inline u8 rs_is_valid_ant(u8 valid_antenna, u8 ant_type)
248{
249 return (ant_type & valid_antenna) == ant_type;
250}
251
249/* 252/*
250 * removes the old data from the statistics. All data that is older than 253 * removes the old data from the statistics. All data that is older than
251 * TID_MAX_TIME_DIFF, will be deleted. 254 * TID_MAX_TIME_DIFF, will be deleted.
252 */ 255 */
253static void rs_tl_rm_old_stats(struct iwl4965_traffic_load *tl, u32 curr_time) 256static void rs_tl_rm_old_stats(struct iwl_traffic_load *tl, u32 curr_time)
254{ 257{
255 /* The oldest age we want to keep */ 258 /* The oldest age we want to keep */
256 u32 oldest_time = curr_time - TID_MAX_TIME_DIFF; 259 u32 oldest_time = curr_time - TID_MAX_TIME_DIFF;
@@ -271,15 +274,21 @@ static void rs_tl_rm_old_stats(struct iwl4965_traffic_load *tl, u32 curr_time)
271 * increment traffic load value for tid and also remove 274 * increment traffic load value for tid and also remove
272 * any old values if passed the certain time period 275 * any old values if passed the certain time period
273 */ 276 */
274static void rs_tl_add_packet(struct iwl4965_lq_sta *lq_data, u8 tid) 277static u8 rs_tl_add_packet(struct iwl_lq_sta *lq_data,
278 struct ieee80211_hdr *hdr)
275{ 279{
276 u32 curr_time = jiffies_to_msecs(jiffies); 280 u32 curr_time = jiffies_to_msecs(jiffies);
277 u32 time_diff; 281 u32 time_diff;
278 s32 index; 282 s32 index;
279 struct iwl4965_traffic_load *tl = NULL; 283 struct iwl_traffic_load *tl = NULL;
284 __le16 fc = hdr->frame_control;
285 u8 tid;
280 286
281 if (tid >= TID_MAX_LOAD_COUNT) 287 if (ieee80211_is_data_qos(fc)) {
282 return; 288 u8 *qc = ieee80211_get_qos_ctl(hdr);
289 tid = qc[0] & 0xf;
290 } else
291 return MAX_TID_COUNT;
283 292
284 tl = &lq_data->load[tid]; 293 tl = &lq_data->load[tid];
285 294
@@ -292,7 +301,7 @@ static void rs_tl_add_packet(struct iwl4965_lq_sta *lq_data, u8 tid)
292 tl->queue_count = 1; 301 tl->queue_count = 1;
293 tl->head = 0; 302 tl->head = 0;
294 tl->packet_count[0] = 1; 303 tl->packet_count[0] = 1;
295 return; 304 return MAX_TID_COUNT;
296 } 305 }
297 306
298 time_diff = TIME_WRAP_AROUND(tl->time_stamp, curr_time); 307 time_diff = TIME_WRAP_AROUND(tl->time_stamp, curr_time);
@@ -309,17 +318,19 @@ static void rs_tl_add_packet(struct iwl4965_lq_sta *lq_data, u8 tid)
309 318
310 if ((index + 1) > tl->queue_count) 319 if ((index + 1) > tl->queue_count)
311 tl->queue_count = index + 1; 320 tl->queue_count = index + 1;
321
322 return tid;
312} 323}
313 324
314/* 325/*
315 get the traffic load value for tid 326 get the traffic load value for tid
316*/ 327*/
317static u32 rs_tl_get_load(struct iwl4965_lq_sta *lq_data, u8 tid) 328static u32 rs_tl_get_load(struct iwl_lq_sta *lq_data, u8 tid)
318{ 329{
319 u32 curr_time = jiffies_to_msecs(jiffies); 330 u32 curr_time = jiffies_to_msecs(jiffies);
320 u32 time_diff; 331 u32 time_diff;
321 s32 index; 332 s32 index;
322 struct iwl4965_traffic_load *tl = NULL; 333 struct iwl_traffic_load *tl = NULL;
323 334
324 if (tid >= TID_MAX_LOAD_COUNT) 335 if (tid >= TID_MAX_LOAD_COUNT)
325 return 0; 336 return 0;
@@ -343,18 +354,12 @@ static u32 rs_tl_get_load(struct iwl4965_lq_sta *lq_data, u8 tid)
343} 354}
344 355
345static void rs_tl_turn_on_agg_for_tid(struct iwl_priv *priv, 356static void rs_tl_turn_on_agg_for_tid(struct iwl_priv *priv,
346 struct iwl4965_lq_sta *lq_data, u8 tid, 357 struct iwl_lq_sta *lq_data, u8 tid,
347 struct sta_info *sta) 358 struct ieee80211_sta *sta)
348{ 359{
349 unsigned long state;
350 DECLARE_MAC_BUF(mac); 360 DECLARE_MAC_BUF(mac);
351 361
352 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx); 362 if (rs_tl_get_load(lq_data, tid) > IWL_AGG_LOAD_THRESHOLD) {
353 state = sta->ampdu_mlme.tid_state_tx[tid];
354 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
355
356 if (state == HT_AGG_STATE_IDLE &&
357 rs_tl_get_load(lq_data, tid) > IWL_AGG_LOAD_THRESHOLD) {
358 IWL_DEBUG_HT("Starting Tx agg: STA: %s tid: %d\n", 363 IWL_DEBUG_HT("Starting Tx agg: STA: %s tid: %d\n",
359 print_mac(mac, sta->addr), tid); 364 print_mac(mac, sta->addr), tid);
360 ieee80211_start_tx_ba_session(priv->hw, sta->addr, tid); 365 ieee80211_start_tx_ba_session(priv->hw, sta->addr, tid);
@@ -362,8 +367,8 @@ static void rs_tl_turn_on_agg_for_tid(struct iwl_priv *priv,
362} 367}
363 368
364static void rs_tl_turn_on_agg(struct iwl_priv *priv, u8 tid, 369static void rs_tl_turn_on_agg(struct iwl_priv *priv, u8 tid,
365 struct iwl4965_lq_sta *lq_data, 370 struct iwl_lq_sta *lq_data,
366 struct sta_info *sta) 371 struct ieee80211_sta *sta)
367{ 372{
368 if ((tid < TID_MAX_LOAD_COUNT)) 373 if ((tid < TID_MAX_LOAD_COUNT))
369 rs_tl_turn_on_agg_for_tid(priv, lq_data, tid, sta); 374 rs_tl_turn_on_agg_for_tid(priv, lq_data, tid, sta);
@@ -372,7 +377,12 @@ static void rs_tl_turn_on_agg(struct iwl_priv *priv, u8 tid,
372 rs_tl_turn_on_agg_for_tid(priv, lq_data, tid, sta); 377 rs_tl_turn_on_agg_for_tid(priv, lq_data, tid, sta);
373} 378}
374 379
375#endif /* CONFIG_IWLWIFI_HT */ 380static inline int get_num_of_ant_from_rate(u32 rate_n_flags)
381{
382 return !!(rate_n_flags & RATE_MCS_ANT_A_MSK) +
383 !!(rate_n_flags & RATE_MCS_ANT_B_MSK) +
384 !!(rate_n_flags & RATE_MCS_ANT_C_MSK);
385}
376 386
377/** 387/**
378 * rs_collect_tx_data - Update the success/failure sliding window 388 * rs_collect_tx_data - Update the success/failure sliding window
@@ -381,13 +391,12 @@ static void rs_tl_turn_on_agg(struct iwl_priv *priv, u8 tid,
381 * at this rate. window->data contains the bitmask of successful 391 * at this rate. window->data contains the bitmask of successful
382 * packets. 392 * packets.
383 */ 393 */
384static int rs_collect_tx_data(struct iwl4965_rate_scale_data *windows, 394static int rs_collect_tx_data(struct iwl_rate_scale_data *windows,
385 int scale_index, s32 tpt, int retries, 395 int scale_index, s32 tpt, int retries,
386 int successes) 396 int successes)
387{ 397{
388 struct iwl4965_rate_scale_data *window = NULL; 398 struct iwl_rate_scale_data *window = NULL;
389 u64 mask; 399 static const u64 mask = (((u64)1) << (IWL_RATE_MAX_WINDOW - 1));
390 u8 win_size = IWL_RATE_MAX_WINDOW;
391 s32 fail_count; 400 s32 fail_count;
392 401
393 if (scale_index < 0 || scale_index >= IWL_RATE_COUNT) 402 if (scale_index < 0 || scale_index >= IWL_RATE_COUNT)
@@ -405,14 +414,14 @@ static int rs_collect_tx_data(struct iwl4965_rate_scale_data *windows,
405 * we keep these bitmaps!). 414 * we keep these bitmaps!).
406 */ 415 */
407 while (retries > 0) { 416 while (retries > 0) {
408 if (window->counter >= win_size) { 417 if (window->counter >= IWL_RATE_MAX_WINDOW) {
409 window->counter = win_size - 1; 418
410 mask = 1; 419 /* remove earliest */
411 mask = (mask << (win_size - 1)); 420 window->counter = IWL_RATE_MAX_WINDOW - 1;
421
412 if (window->data & mask) { 422 if (window->data & mask) {
413 window->data &= ~mask; 423 window->data &= ~mask;
414 window->success_counter = 424 window->success_counter--;
415 window->success_counter - 1;
416 } 425 }
417 } 426 }
418 427
@@ -422,10 +431,9 @@ static int rs_collect_tx_data(struct iwl4965_rate_scale_data *windows,
422 /* Shift bitmap by one frame (throw away oldest history), 431 /* Shift bitmap by one frame (throw away oldest history),
423 * OR in "1", and increment "success" if this 432 * OR in "1", and increment "success" if this
424 * frame was successful. */ 433 * frame was successful. */
425 mask = window->data; 434 window->data <<= 1;
426 window->data = (mask << 1);
427 if (successes > 0) { 435 if (successes > 0) {
428 window->success_counter = window->success_counter + 1; 436 window->success_counter++;
429 window->data |= 0x1; 437 window->data |= 0x1;
430 successes--; 438 successes--;
431 } 439 }
@@ -458,168 +466,162 @@ static int rs_collect_tx_data(struct iwl4965_rate_scale_data *windows,
458/* 466/*
459 * Fill uCode API rate_n_flags field, based on "search" or "active" table. 467 * Fill uCode API rate_n_flags field, based on "search" or "active" table.
460 */ 468 */
461static void rs_mcs_from_tbl(struct iwl4965_rate *mcs_rate, 469/* FIXME:RS:remove this function and put the flags statically in the table */
462 struct iwl4965_scale_tbl_info *tbl, 470static u32 rate_n_flags_from_tbl(struct iwl_scale_tbl_info *tbl,
463 int index, u8 use_green) 471 int index, u8 use_green)
464{ 472{
473 u32 rate_n_flags = 0;
474
465 if (is_legacy(tbl->lq_type)) { 475 if (is_legacy(tbl->lq_type)) {
466 mcs_rate->rate_n_flags = iwl4965_rates[index].plcp; 476 rate_n_flags = iwl_rates[index].plcp;
467 if (index >= IWL_FIRST_CCK_RATE && index <= IWL_LAST_CCK_RATE) 477 if (index >= IWL_FIRST_CCK_RATE && index <= IWL_LAST_CCK_RATE)
468 mcs_rate->rate_n_flags |= RATE_MCS_CCK_MSK; 478 rate_n_flags |= RATE_MCS_CCK_MSK;
469 479
470 } else if (is_siso(tbl->lq_type)) { 480 } else if (is_Ht(tbl->lq_type)) {
471 if (index > IWL_LAST_OFDM_RATE) 481 if (index > IWL_LAST_OFDM_RATE) {
472 index = IWL_LAST_OFDM_RATE; 482 IWL_ERROR("invalid HT rate index %d\n", index);
473 mcs_rate->rate_n_flags = iwl4965_rates[index].plcp_siso |
474 RATE_MCS_HT_MSK;
475 } else {
476 if (index > IWL_LAST_OFDM_RATE)
477 index = IWL_LAST_OFDM_RATE; 483 index = IWL_LAST_OFDM_RATE;
478 mcs_rate->rate_n_flags = iwl4965_rates[index].plcp_mimo | 484 }
479 RATE_MCS_HT_MSK; 485 rate_n_flags = RATE_MCS_HT_MSK;
480 }
481
482 switch (tbl->antenna_type) {
483 case ANT_BOTH:
484 mcs_rate->rate_n_flags |= RATE_MCS_ANT_AB_MSK;
485 break;
486 case ANT_MAIN:
487 mcs_rate->rate_n_flags |= RATE_MCS_ANT_A_MSK;
488 break;
489 case ANT_AUX:
490 mcs_rate->rate_n_flags |= RATE_MCS_ANT_B_MSK;
491 break;
492 case ANT_NONE:
493 break;
494 }
495
496 if (is_legacy(tbl->lq_type))
497 return;
498 486
499 if (tbl->is_fat) { 487 if (is_siso(tbl->lq_type))
500 if (tbl->is_dup) 488 rate_n_flags |= iwl_rates[index].plcp_siso;
501 mcs_rate->rate_n_flags |= RATE_MCS_DUP_MSK; 489 else if (is_mimo2(tbl->lq_type))
490 rate_n_flags |= iwl_rates[index].plcp_mimo2;
502 else 491 else
503 mcs_rate->rate_n_flags |= RATE_MCS_FAT_MSK; 492 rate_n_flags |= iwl_rates[index].plcp_mimo3;
493 } else {
494 IWL_ERROR("Invalid tbl->lq_type %d\n", tbl->lq_type);
504 } 495 }
505 if (tbl->is_SGI)
506 mcs_rate->rate_n_flags |= RATE_MCS_SGI_MSK;
507 496
508 if (use_green) { 497 rate_n_flags |= ((tbl->ant_type << RATE_MCS_ANT_POS) &
509 mcs_rate->rate_n_flags |= RATE_MCS_GF_MSK; 498 RATE_MCS_ANT_ABC_MSK);
510 if (is_siso(tbl->lq_type)) 499
511 mcs_rate->rate_n_flags &= ~RATE_MCS_SGI_MSK; 500 if (is_Ht(tbl->lq_type)) {
501 if (tbl->is_fat) {
502 if (tbl->is_dup)
503 rate_n_flags |= RATE_MCS_DUP_MSK;
504 else
505 rate_n_flags |= RATE_MCS_FAT_MSK;
506 }
507 if (tbl->is_SGI)
508 rate_n_flags |= RATE_MCS_SGI_MSK;
509
510 if (use_green) {
511 rate_n_flags |= RATE_MCS_GF_MSK;
512 if (is_siso(tbl->lq_type) && tbl->is_SGI) {
513 rate_n_flags &= ~RATE_MCS_SGI_MSK;
514 IWL_ERROR("GF was set with SGI:SISO\n");
515 }
516 }
512 } 517 }
518 return rate_n_flags;
513} 519}
514 520
515/* 521/*
516 * Interpret uCode API's rate_n_flags format, 522 * Interpret uCode API's rate_n_flags format,
517 * fill "search" or "active" tx mode table. 523 * fill "search" or "active" tx mode table.
518 */ 524 */
519static int rs_get_tbl_info_from_mcs(const struct iwl4965_rate *mcs_rate, 525static int rs_get_tbl_info_from_mcs(const u32 rate_n_flags,
520 enum ieee80211_band band, 526 enum ieee80211_band band,
521 struct iwl4965_scale_tbl_info *tbl, 527 struct iwl_scale_tbl_info *tbl,
522 int *rate_idx) 528 int *rate_idx)
523{ 529{
524 int index; 530 u32 ant_msk = (rate_n_flags & RATE_MCS_ANT_ABC_MSK);
525 u32 ant_msk; 531 u8 num_of_ant = get_num_of_ant_from_rate(rate_n_flags);
532 u8 mcs;
526 533
527 index = iwl4965_hwrate_to_plcp_idx(mcs_rate->rate_n_flags); 534 *rate_idx = iwl_hwrate_to_plcp_idx(rate_n_flags);
528 535
529 if (index == IWL_RATE_INVALID) { 536 if (*rate_idx == IWL_RATE_INVALID) {
530 *rate_idx = -1; 537 *rate_idx = -1;
531 return -EINVAL; 538 return -EINVAL;
532 } 539 }
533 tbl->is_SGI = 0; /* default legacy setup */ 540 tbl->is_SGI = 0; /* default legacy setup */
534 tbl->is_fat = 0; 541 tbl->is_fat = 0;
535 tbl->is_dup = 0; 542 tbl->is_dup = 0;
536 tbl->antenna_type = ANT_BOTH; /* default MIMO setup */ 543 tbl->ant_type = (ant_msk >> RATE_MCS_ANT_POS);
544 tbl->lq_type = LQ_NONE;
537 545
538 /* legacy rate format */ 546 /* legacy rate format */
539 if (!(mcs_rate->rate_n_flags & RATE_MCS_HT_MSK)) { 547 if (!(rate_n_flags & RATE_MCS_HT_MSK)) {
540 ant_msk = (mcs_rate->rate_n_flags & RATE_MCS_ANT_AB_MSK); 548 if (num_of_ant == 1) {
541
542 if (ant_msk == RATE_MCS_ANT_AB_MSK)
543 tbl->lq_type = LQ_NONE;
544 else {
545
546 if (band == IEEE80211_BAND_5GHZ) 549 if (band == IEEE80211_BAND_5GHZ)
547 tbl->lq_type = LQ_A; 550 tbl->lq_type = LQ_A;
548 else 551 else
549 tbl->lq_type = LQ_G; 552 tbl->lq_type = LQ_G;
550
551 if (mcs_rate->rate_n_flags & RATE_MCS_ANT_A_MSK)
552 tbl->antenna_type = ANT_MAIN;
553 else
554 tbl->antenna_type = ANT_AUX;
555 } 553 }
556 *rate_idx = index; 554 /* HT rate format */
557
558 /* HT rate format, SISO (might be 20 MHz legacy or 40 MHz fat width) */
559 } else if (iwl4965_rate_get_rate(mcs_rate->rate_n_flags)
560 <= IWL_RATE_SISO_60M_PLCP) {
561 tbl->lq_type = LQ_SISO;
562
563 ant_msk = (mcs_rate->rate_n_flags & RATE_MCS_ANT_AB_MSK);
564 if (ant_msk == RATE_MCS_ANT_AB_MSK)
565 tbl->lq_type = LQ_NONE;
566 else {
567 if (mcs_rate->rate_n_flags & RATE_MCS_ANT_A_MSK)
568 tbl->antenna_type = ANT_MAIN;
569 else
570 tbl->antenna_type = ANT_AUX;
571 }
572 if (mcs_rate->rate_n_flags & RATE_MCS_SGI_MSK)
573 tbl->is_SGI = 1;
574
575 if ((mcs_rate->rate_n_flags & RATE_MCS_FAT_MSK) ||
576 (mcs_rate->rate_n_flags & RATE_MCS_DUP_MSK))
577 tbl->is_fat = 1;
578
579 if (mcs_rate->rate_n_flags & RATE_MCS_DUP_MSK)
580 tbl->is_dup = 1;
581
582 *rate_idx = index;
583
584 /* HT rate format, MIMO (might be 20 MHz legacy or 40 MHz fat width) */
585 } else { 555 } else {
586 tbl->lq_type = LQ_MIMO; 556 if (rate_n_flags & RATE_MCS_SGI_MSK)
587 if (mcs_rate->rate_n_flags & RATE_MCS_SGI_MSK)
588 tbl->is_SGI = 1; 557 tbl->is_SGI = 1;
589 558
590 if ((mcs_rate->rate_n_flags & RATE_MCS_FAT_MSK) || 559 if ((rate_n_flags & RATE_MCS_FAT_MSK) ||
591 (mcs_rate->rate_n_flags & RATE_MCS_DUP_MSK)) 560 (rate_n_flags & RATE_MCS_DUP_MSK))
592 tbl->is_fat = 1; 561 tbl->is_fat = 1;
593 562
594 if (mcs_rate->rate_n_flags & RATE_MCS_DUP_MSK) 563 if (rate_n_flags & RATE_MCS_DUP_MSK)
595 tbl->is_dup = 1; 564 tbl->is_dup = 1;
596 *rate_idx = index; 565
566 mcs = rs_extract_rate(rate_n_flags);
567
568 /* SISO */
569 if (mcs <= IWL_RATE_SISO_60M_PLCP) {
570 if (num_of_ant == 1)
571 tbl->lq_type = LQ_SISO; /*else NONE*/
572 /* MIMO2 */
573 } else if (mcs <= IWL_RATE_MIMO2_60M_PLCP) {
574 if (num_of_ant == 2)
575 tbl->lq_type = LQ_MIMO2;
576 /* MIMO3 */
577 } else {
578 if (num_of_ant == 3)
579 tbl->lq_type = LQ_MIMO3;
580 }
597 } 581 }
598 return 0; 582 return 0;
599} 583}
600 584
601static inline void rs_toggle_antenna(struct iwl4965_rate *new_rate, 585/* switch to another antenna/antennas and return 1 */
602 struct iwl4965_scale_tbl_info *tbl) 586/* if no other valid antenna found, return 0 */
587static int rs_toggle_antenna(u32 valid_ant, u32 *rate_n_flags,
588 struct iwl_scale_tbl_info *tbl)
603{ 589{
604 if (tbl->antenna_type == ANT_AUX) { 590 u8 new_ant_type;
605 tbl->antenna_type = ANT_MAIN; 591
606 new_rate->rate_n_flags &= ~RATE_MCS_ANT_B_MSK; 592 if (!tbl->ant_type || tbl->ant_type > ANT_ABC)
607 new_rate->rate_n_flags |= RATE_MCS_ANT_A_MSK; 593 return 0;
608 } else { 594
609 tbl->antenna_type = ANT_AUX; 595 if (!rs_is_valid_ant(valid_ant, tbl->ant_type))
610 new_rate->rate_n_flags &= ~RATE_MCS_ANT_A_MSK; 596 return 0;
611 new_rate->rate_n_flags |= RATE_MCS_ANT_B_MSK; 597
612 } 598 new_ant_type = ant_toggle_lookup[tbl->ant_type];
599
600 while ((new_ant_type != tbl->ant_type) &&
601 !rs_is_valid_ant(valid_ant, new_ant_type))
602 new_ant_type = ant_toggle_lookup[new_ant_type];
603
604 if (new_ant_type == tbl->ant_type)
605 return 0;
606
607 tbl->ant_type = new_ant_type;
608 *rate_n_flags &= ~RATE_MCS_ANT_ABC_MSK;
609 *rate_n_flags |= new_ant_type << RATE_MCS_ANT_POS;
610 return 1;
613} 611}
614 612
615static inline u8 rs_use_green(struct iwl_priv *priv, 613/* FIXME:RS: in 4965 we don't use greenfield at all */
616 struct ieee80211_conf *conf) 614/* FIXME:RS: don't use greenfield for now in TX */
615#if 0
616static inline u8 rs_use_green(struct iwl_priv *priv, struct ieee80211_conf *conf)
617{ 617{
618#ifdef CONFIG_IWL4965_HT 618 return (conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) &&
619 return ((conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) &&
620 priv->current_ht_config.is_green_field && 619 priv->current_ht_config.is_green_field &&
621 !priv->current_ht_config.non_GF_STA_present); 620 !priv->current_ht_config.non_GF_STA_present;
622#endif /* CONFIG_IWL4965_HT */ 621}
622#endif
623static inline u8 rs_use_green(struct iwl_priv *priv, struct ieee80211_conf *conf)
624{
623 return 0; 625 return 0;
624} 626}
625 627
@@ -630,27 +632,28 @@ static inline u8 rs_use_green(struct iwl_priv *priv,
630 * basic available rates. 632 * basic available rates.
631 * 633 *
632 */ 634 */
633static void rs_get_supported_rates(struct iwl4965_lq_sta *lq_sta, 635static u16 rs_get_supported_rates(struct iwl_lq_sta *lq_sta,
634 struct ieee80211_hdr *hdr, 636 struct ieee80211_hdr *hdr,
635 enum iwl4965_table_type rate_type, 637 enum iwl_table_type rate_type)
636 u16 *data_rate)
637{ 638{
638 if (is_legacy(rate_type)) 639 if (hdr && is_multicast_ether_addr(hdr->addr1) &&
639 *data_rate = lq_sta->active_rate; 640 lq_sta->active_rate_basic)
640 else { 641 return lq_sta->active_rate_basic;
642
643 if (is_legacy(rate_type)) {
644 return lq_sta->active_legacy_rate;
645 } else {
641 if (is_siso(rate_type)) 646 if (is_siso(rate_type))
642 *data_rate = lq_sta->active_siso_rate; 647 return lq_sta->active_siso_rate;
648 else if (is_mimo2(rate_type))
649 return lq_sta->active_mimo2_rate;
643 else 650 else
644 *data_rate = lq_sta->active_mimo_rate; 651 return lq_sta->active_mimo3_rate;
645 }
646
647 if (hdr && is_multicast_ether_addr(hdr->addr1) &&
648 lq_sta->active_rate_basic) {
649 *data_rate = lq_sta->active_rate_basic;
650 } 652 }
651} 653}
652 654
653static u16 rs_get_adjacent_rate(u8 index, u16 rate_mask, int rate_type) 655static u16 rs_get_adjacent_rate(struct iwl_priv *priv, u8 index, u16 rate_mask,
656 int rate_type)
654{ 657{
655 u8 high = IWL_RATE_INVALID; 658 u8 high = IWL_RATE_INVALID;
656 u8 low = IWL_RATE_INVALID; 659 u8 low = IWL_RATE_INVALID;
@@ -684,7 +687,7 @@ static u16 rs_get_adjacent_rate(u8 index, u16 rate_mask, int rate_type)
684 687
685 low = index; 688 low = index;
686 while (low != IWL_RATE_INVALID) { 689 while (low != IWL_RATE_INVALID) {
687 low = iwl4965_rates[low].prev_rs; 690 low = iwl_rates[low].prev_rs;
688 if (low == IWL_RATE_INVALID) 691 if (low == IWL_RATE_INVALID)
689 break; 692 break;
690 if (rate_mask & (1 << low)) 693 if (rate_mask & (1 << low))
@@ -694,7 +697,7 @@ static u16 rs_get_adjacent_rate(u8 index, u16 rate_mask, int rate_type)
694 697
695 high = index; 698 high = index;
696 while (high != IWL_RATE_INVALID) { 699 while (high != IWL_RATE_INVALID) {
697 high = iwl4965_rates[high].next_rs; 700 high = iwl_rates[high].next_rs;
698 if (high == IWL_RATE_INVALID) 701 if (high == IWL_RATE_INVALID)
699 break; 702 break;
700 if (rate_mask & (1 << high)) 703 if (rate_mask & (1 << high))
@@ -705,9 +708,9 @@ static u16 rs_get_adjacent_rate(u8 index, u16 rate_mask, int rate_type)
705 return (high << 8) | low; 708 return (high << 8) | low;
706} 709}
707 710
708static void rs_get_lower_rate(struct iwl4965_lq_sta *lq_sta, 711static u32 rs_get_lower_rate(struct iwl_lq_sta *lq_sta,
709 struct iwl4965_scale_tbl_info *tbl, u8 scale_index, 712 struct iwl_scale_tbl_info *tbl,
710 u8 ht_possible, struct iwl4965_rate *mcs_rate) 713 u8 scale_index, u8 ht_possible)
711{ 714{
712 s32 low; 715 s32 low;
713 u16 rate_mask; 716 u16 rate_mask;
@@ -726,15 +729,14 @@ static void rs_get_lower_rate(struct iwl4965_lq_sta *lq_sta,
726 else 729 else
727 tbl->lq_type = LQ_G; 730 tbl->lq_type = LQ_G;
728 731
729 if ((tbl->antenna_type == ANT_BOTH) || 732 if (num_of_ant(tbl->ant_type) > 1)
730 (tbl->antenna_type == ANT_NONE)) 733 tbl->ant_type = ANT_A;/*FIXME:RS*/
731 tbl->antenna_type = ANT_MAIN;
732 734
733 tbl->is_fat = 0; 735 tbl->is_fat = 0;
734 tbl->is_SGI = 0; 736 tbl->is_SGI = 0;
735 } 737 }
736 738
737 rs_get_supported_rates(lq_sta, NULL, tbl->lq_type, &rate_mask); 739 rate_mask = rs_get_supported_rates(lq_sta, NULL, tbl->lq_type);
738 740
739 /* Mask with station rate restriction */ 741 /* Mask with station rate restriction */
740 if (is_legacy(tbl->lq_type)) { 742 if (is_legacy(tbl->lq_type)) {
@@ -748,43 +750,44 @@ static void rs_get_lower_rate(struct iwl4965_lq_sta *lq_sta,
748 750
749 /* If we switched from HT to legacy, check current rate */ 751 /* If we switched from HT to legacy, check current rate */
750 if (switch_to_legacy && (rate_mask & (1 << scale_index))) { 752 if (switch_to_legacy && (rate_mask & (1 << scale_index))) {
751 rs_mcs_from_tbl(mcs_rate, tbl, scale_index, is_green); 753 low = scale_index;
752 return; 754 goto out;
753 } 755 }
754 756
755 high_low = rs_get_adjacent_rate(scale_index, rate_mask, tbl->lq_type); 757 high_low = rs_get_adjacent_rate(lq_sta->drv, scale_index, rate_mask,
758 tbl->lq_type);
756 low = high_low & 0xff; 759 low = high_low & 0xff;
757 760
758 if (low != IWL_RATE_INVALID) 761 if (low == IWL_RATE_INVALID)
759 rs_mcs_from_tbl(mcs_rate, tbl, low, is_green); 762 low = scale_index;
760 else 763
761 rs_mcs_from_tbl(mcs_rate, tbl, scale_index, is_green); 764out:
765 return rate_n_flags_from_tbl(tbl, low, is_green);
762} 766}
763 767
764/* 768/*
765 * mac80211 sends us Tx status 769 * mac80211 sends us Tx status
766 */ 770 */
767static void rs_tx_status(void *priv_rate, struct net_device *dev, 771static void rs_tx_status(void *priv_r, struct ieee80211_supported_band *sband,
768 struct sk_buff *skb, 772 struct ieee80211_sta *sta, void *priv_sta,
769 struct ieee80211_tx_status *tx_resp) 773 struct sk_buff *skb)
770{ 774{
771 int status; 775 int status;
772 u8 retries; 776 u8 retries;
773 int rs_index, index = 0; 777 int rs_index, index = 0;
774 struct iwl4965_lq_sta *lq_sta; 778 struct iwl_lq_sta *lq_sta;
775 struct iwl_link_quality_cmd *table; 779 struct iwl_link_quality_cmd *table;
776 struct sta_info *sta;
777 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 780 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
778 struct iwl_priv *priv = (struct iwl_priv *)priv_rate; 781 struct iwl_priv *priv = (struct iwl_priv *)priv_r;
779 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 782 struct ieee80211_hw *hw = priv->hw;
780 struct ieee80211_hw *hw = local_to_hw(local); 783 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
781 struct iwl4965_rate_scale_data *window = NULL; 784 struct iwl_rate_scale_data *window = NULL;
782 struct iwl4965_rate_scale_data *search_win = NULL; 785 struct iwl_rate_scale_data *search_win = NULL;
783 struct iwl4965_rate tx_mcs; 786 u32 tx_rate;
784 struct iwl4965_scale_tbl_info tbl_type; 787 struct iwl_scale_tbl_info tbl_type;
785 struct iwl4965_scale_tbl_info *curr_tbl, *search_tbl; 788 struct iwl_scale_tbl_info *curr_tbl, *search_tbl;
786 u8 active_index = 0; 789 u8 active_index = 0;
787 u16 fc = le16_to_cpu(hdr->frame_control); 790 __le16 fc = hdr->frame_control;
788 s32 tpt = 0; 791 s32 tpt = 0;
789 792
790 IWL_DEBUG_RATE_LIMIT("get frame ack response, update rate scale window\n"); 793 IWL_DEBUG_RATE_LIMIT("get frame ack response, update rate scale window\n");
@@ -793,50 +796,28 @@ static void rs_tx_status(void *priv_rate, struct net_device *dev,
793 return; 796 return;
794 797
795 /* This packet was aggregated but doesn't carry rate scale info */ 798 /* This packet was aggregated but doesn't carry rate scale info */
796 if ((tx_resp->control.flags & IEEE80211_TXCTL_AMPDU) && 799 if ((info->flags & IEEE80211_TX_CTL_AMPDU) &&
797 !(tx_resp->flags & IEEE80211_TX_STATUS_AMPDU)) 800 !(info->flags & IEEE80211_TX_STAT_AMPDU))
798 return; 801 return;
799 802
800 retries = tx_resp->retry_count; 803 retries = info->status.retry_count;
801 804
802 if (retries > 15) 805 if (retries > 15)
803 retries = 15; 806 retries = 15;
804 807
805 rcu_read_lock(); 808 lq_sta = (struct iwl_lq_sta *)priv_sta;
806
807 sta = sta_info_get(local, hdr->addr1);
808
809 if (!sta || !sta->rate_ctrl_priv)
810 goto out;
811
812
813 lq_sta = (struct iwl4965_lq_sta *)sta->rate_ctrl_priv;
814
815 if (!priv->lq_mngr.lq_ready)
816 goto out;
817 809
818 if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) && 810 if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) &&
819 !lq_sta->ibss_sta_added) 811 !lq_sta->ibss_sta_added)
820 goto out; 812 goto out;
821 813
822 table = &lq_sta->lq; 814 table = &lq_sta->lq;
823 active_index = lq_sta->active_tbl; 815 active_index = lq_sta->active_tbl;
824 816
825 /* Get mac80211 antenna info */
826 lq_sta->antenna =
827 (lq_sta->valid_antenna & local->hw.conf.antenna_sel_tx);
828 if (!lq_sta->antenna)
829 lq_sta->antenna = lq_sta->valid_antenna;
830
831 /* Ignore mac80211 antenna info for now */
832 lq_sta->antenna = lq_sta->valid_antenna;
833
834 curr_tbl = &(lq_sta->lq_info[active_index]); 817 curr_tbl = &(lq_sta->lq_info[active_index]);
835 search_tbl = &(lq_sta->lq_info[(1 - active_index)]); 818 search_tbl = &(lq_sta->lq_info[(1 - active_index)]);
836 window = (struct iwl4965_rate_scale_data *) 819 window = (struct iwl_rate_scale_data *)&(curr_tbl->win[0]);
837 &(curr_tbl->win[0]); 820 search_win = (struct iwl_rate_scale_data *)&(search_tbl->win[0]);
838 search_win = (struct iwl4965_rate_scale_data *)
839 &(search_tbl->win[0]);
840 821
841 /* 822 /*
842 * Ignore this Tx frame response if its initial rate doesn't match 823 * Ignore this Tx frame response if its initial rate doesn't match
@@ -846,28 +827,26 @@ static void rs_tx_status(void *priv_rate, struct net_device *dev,
846 * to check "search" mode, or a prior "search" mode after we've moved 827 * to check "search" mode, or a prior "search" mode after we've moved
847 * to a new "search" mode (which might become the new "active" mode). 828 * to a new "search" mode (which might become the new "active" mode).
848 */ 829 */
849 tx_mcs.rate_n_flags = le32_to_cpu(table->rs_table[0].rate_n_flags); 830 tx_rate = le32_to_cpu(table->rs_table[0].rate_n_flags);
850 rs_get_tbl_info_from_mcs(&tx_mcs, priv->band, &tbl_type, &rs_index); 831 rs_get_tbl_info_from_mcs(tx_rate, priv->band, &tbl_type, &rs_index);
851 if (priv->band == IEEE80211_BAND_5GHZ) 832 if (priv->band == IEEE80211_BAND_5GHZ)
852 rs_index -= IWL_FIRST_OFDM_RATE; 833 rs_index -= IWL_FIRST_OFDM_RATE;
853 834
854 if ((tx_resp->control.tx_rate == NULL) || 835 if ((info->tx_rate_idx < 0) ||
855 (tbl_type.is_SGI ^ 836 (tbl_type.is_SGI ^
856 !!(tx_resp->control.flags & IEEE80211_TXCTL_SHORT_GI)) || 837 !!(info->flags & IEEE80211_TX_CTL_SHORT_GI)) ||
857 (tbl_type.is_fat ^ 838 (tbl_type.is_fat ^
858 !!(tx_resp->control.flags & IEEE80211_TXCTL_40_MHZ_WIDTH)) || 839 !!(info->flags & IEEE80211_TX_CTL_40_MHZ_WIDTH)) ||
859 (tbl_type.is_dup ^ 840 (tbl_type.is_dup ^
860 !!(tx_resp->control.flags & IEEE80211_TXCTL_DUP_DATA)) || 841 !!(info->flags & IEEE80211_TX_CTL_DUP_DATA)) ||
861 (tbl_type.antenna_type ^ 842 (tbl_type.ant_type ^ info->antenna_sel_tx) ||
862 tx_resp->control.antenna_sel_tx) || 843 (!!(tx_rate & RATE_MCS_HT_MSK) ^
863 (!!(tx_mcs.rate_n_flags & RATE_MCS_HT_MSK) ^ 844 !!(info->flags & IEEE80211_TX_CTL_OFDM_HT)) ||
864 !!(tx_resp->control.flags & IEEE80211_TXCTL_OFDM_HT)) || 845 (!!(tx_rate & RATE_MCS_GF_MSK) ^
865 (!!(tx_mcs.rate_n_flags & RATE_MCS_GF_MSK) ^ 846 !!(info->flags & IEEE80211_TX_CTL_GREEN_FIELD)) ||
866 !!(tx_resp->control.flags & IEEE80211_TXCTL_GREEN_FIELD)) ||
867 (hw->wiphy->bands[priv->band]->bitrates[rs_index].bitrate != 847 (hw->wiphy->bands[priv->band]->bitrates[rs_index].bitrate !=
868 tx_resp->control.tx_rate->bitrate)) { 848 hw->wiphy->bands[info->band]->bitrates[info->tx_rate_idx].bitrate)) {
869 IWL_DEBUG_RATE("initial rate does not match 0x%x\n", 849 IWL_DEBUG_RATE("initial rate does not match 0x%x\n", tx_rate);
870 tx_mcs.rate_n_flags);
871 goto out; 850 goto out;
872 } 851 }
873 852
@@ -875,15 +854,14 @@ static void rs_tx_status(void *priv_rate, struct net_device *dev,
875 while (retries) { 854 while (retries) {
876 /* Look up the rate and other info used for each tx attempt. 855 /* Look up the rate and other info used for each tx attempt.
877 * Each tx attempt steps one entry deeper in the rate table. */ 856 * Each tx attempt steps one entry deeper in the rate table. */
878 tx_mcs.rate_n_flags = 857 tx_rate = le32_to_cpu(table->rs_table[index].rate_n_flags);
879 le32_to_cpu(table->rs_table[index].rate_n_flags); 858 rs_get_tbl_info_from_mcs(tx_rate, priv->band,
880 rs_get_tbl_info_from_mcs(&tx_mcs, priv->band,
881 &tbl_type, &rs_index); 859 &tbl_type, &rs_index);
882 860
883 /* If type matches "search" table, 861 /* If type matches "search" table,
884 * add failure to "search" history */ 862 * add failure to "search" history */
885 if ((tbl_type.lq_type == search_tbl->lq_type) && 863 if ((tbl_type.lq_type == search_tbl->lq_type) &&
886 (tbl_type.antenna_type == search_tbl->antenna_type) && 864 (tbl_type.ant_type == search_tbl->ant_type) &&
887 (tbl_type.is_SGI == search_tbl->is_SGI)) { 865 (tbl_type.is_SGI == search_tbl->is_SGI)) {
888 if (search_tbl->expected_tpt) 866 if (search_tbl->expected_tpt)
889 tpt = search_tbl->expected_tpt[rs_index]; 867 tpt = search_tbl->expected_tpt[rs_index];
@@ -894,7 +872,7 @@ static void rs_tx_status(void *priv_rate, struct net_device *dev,
894 /* Else if type matches "current/active" table, 872 /* Else if type matches "current/active" table,
895 * add failure to "current/active" history */ 873 * add failure to "current/active" history */
896 } else if ((tbl_type.lq_type == curr_tbl->lq_type) && 874 } else if ((tbl_type.lq_type == curr_tbl->lq_type) &&
897 (tbl_type.antenna_type == curr_tbl->antenna_type) && 875 (tbl_type.ant_type == curr_tbl->ant_type) &&
898 (tbl_type.is_SGI == curr_tbl->is_SGI)) { 876 (tbl_type.is_SGI == curr_tbl->is_SGI)) {
899 if (curr_tbl->expected_tpt) 877 if (curr_tbl->expected_tpt)
900 tpt = curr_tbl->expected_tpt[rs_index]; 878 tpt = curr_tbl->expected_tpt[rs_index];
@@ -917,44 +895,41 @@ static void rs_tx_status(void *priv_rate, struct net_device *dev,
917 * if Tx was successful first try, use original rate, 895 * if Tx was successful first try, use original rate,
918 * else look up the rate that was, finally, successful. 896 * else look up the rate that was, finally, successful.
919 */ 897 */
920 tx_mcs.rate_n_flags = le32_to_cpu(table->rs_table[index].rate_n_flags); 898 tx_rate = le32_to_cpu(table->rs_table[index].rate_n_flags);
921 rs_get_tbl_info_from_mcs(&tx_mcs, priv->band, &tbl_type, &rs_index); 899 rs_get_tbl_info_from_mcs(tx_rate, priv->band, &tbl_type, &rs_index);
922 900
923 /* Update frame history window with "success" if Tx got ACKed ... */ 901 /* Update frame history window with "success" if Tx got ACKed ... */
924 if (tx_resp->flags & IEEE80211_TX_STATUS_ACK) 902 status = !!(info->flags & IEEE80211_TX_STAT_ACK);
925 status = 1;
926 else
927 status = 0;
928 903
929 /* If type matches "search" table, 904 /* If type matches "search" table,
930 * add final tx status to "search" history */ 905 * add final tx status to "search" history */
931 if ((tbl_type.lq_type == search_tbl->lq_type) && 906 if ((tbl_type.lq_type == search_tbl->lq_type) &&
932 (tbl_type.antenna_type == search_tbl->antenna_type) && 907 (tbl_type.ant_type == search_tbl->ant_type) &&
933 (tbl_type.is_SGI == search_tbl->is_SGI)) { 908 (tbl_type.is_SGI == search_tbl->is_SGI)) {
934 if (search_tbl->expected_tpt) 909 if (search_tbl->expected_tpt)
935 tpt = search_tbl->expected_tpt[rs_index]; 910 tpt = search_tbl->expected_tpt[rs_index];
936 else 911 else
937 tpt = 0; 912 tpt = 0;
938 if (tx_resp->control.flags & IEEE80211_TXCTL_AMPDU) 913 if (info->flags & IEEE80211_TX_CTL_AMPDU)
939 rs_collect_tx_data(search_win, rs_index, tpt, 914 rs_collect_tx_data(search_win, rs_index, tpt,
940 tx_resp->ampdu_ack_len, 915 info->status.ampdu_ack_len,
941 tx_resp->ampdu_ack_map); 916 info->status.ampdu_ack_map);
942 else 917 else
943 rs_collect_tx_data(search_win, rs_index, tpt, 918 rs_collect_tx_data(search_win, rs_index, tpt,
944 1, status); 919 1, status);
945 /* Else if type matches "current/active" table, 920 /* Else if type matches "current/active" table,
946 * add final tx status to "current/active" history */ 921 * add final tx status to "current/active" history */
947 } else if ((tbl_type.lq_type == curr_tbl->lq_type) && 922 } else if ((tbl_type.lq_type == curr_tbl->lq_type) &&
948 (tbl_type.antenna_type == curr_tbl->antenna_type) && 923 (tbl_type.ant_type == curr_tbl->ant_type) &&
949 (tbl_type.is_SGI == curr_tbl->is_SGI)) { 924 (tbl_type.is_SGI == curr_tbl->is_SGI)) {
950 if (curr_tbl->expected_tpt) 925 if (curr_tbl->expected_tpt)
951 tpt = curr_tbl->expected_tpt[rs_index]; 926 tpt = curr_tbl->expected_tpt[rs_index];
952 else 927 else
953 tpt = 0; 928 tpt = 0;
954 if (tx_resp->control.flags & IEEE80211_TXCTL_AMPDU) 929 if (info->flags & IEEE80211_TX_CTL_AMPDU)
955 rs_collect_tx_data(window, rs_index, tpt, 930 rs_collect_tx_data(window, rs_index, tpt,
956 tx_resp->ampdu_ack_len, 931 info->status.ampdu_ack_len,
957 tx_resp->ampdu_ack_map); 932 info->status.ampdu_ack_map);
958 else 933 else
959 rs_collect_tx_data(window, rs_index, tpt, 934 rs_collect_tx_data(window, rs_index, tpt,
960 1, status); 935 1, status);
@@ -963,10 +938,10 @@ static void rs_tx_status(void *priv_rate, struct net_device *dev,
963 /* If not searching for new mode, increment success/failed counter 938 /* If not searching for new mode, increment success/failed counter
964 * ... these help determine when to start searching again */ 939 * ... these help determine when to start searching again */
965 if (lq_sta->stay_in_tbl) { 940 if (lq_sta->stay_in_tbl) {
966 if (tx_resp->control.flags & IEEE80211_TXCTL_AMPDU) { 941 if (info->flags & IEEE80211_TX_CTL_AMPDU) {
967 lq_sta->total_success += tx_resp->ampdu_ack_map; 942 lq_sta->total_success += info->status.ampdu_ack_map;
968 lq_sta->total_failed += 943 lq_sta->total_failed +=
969 (tx_resp->ampdu_ack_len - tx_resp->ampdu_ack_map); 944 (info->status.ampdu_ack_len - info->status.ampdu_ack_map);
970 } else { 945 } else {
971 if (status) 946 if (status)
972 lq_sta->total_success++; 947 lq_sta->total_success++;
@@ -976,36 +951,11 @@ static void rs_tx_status(void *priv_rate, struct net_device *dev,
976 } 951 }
977 952
978 /* See if there's a better rate or modulation mode to try. */ 953 /* See if there's a better rate or modulation mode to try. */
979 rs_rate_scale_perform(priv, dev, hdr, sta); 954 rs_rate_scale_perform(priv, hdr, sta, lq_sta);
980out: 955out:
981 rcu_read_unlock();
982 return; 956 return;
983} 957}
984 958
985static u8 rs_is_ant_connected(u8 valid_antenna,
986 enum iwl4965_antenna_type antenna_type)
987{
988 if (antenna_type == ANT_AUX)
989 return ((valid_antenna & 0x2) ? 1:0);
990 else if (antenna_type == ANT_MAIN)
991 return ((valid_antenna & 0x1) ? 1:0);
992 else if (antenna_type == ANT_BOTH)
993 return ((valid_antenna & 0x3) == 0x3);
994
995 return 1;
996}
997
998static u8 rs_is_other_ant_connected(u8 valid_antenna,
999 enum iwl4965_antenna_type antenna_type)
1000{
1001 if (antenna_type == ANT_AUX)
1002 return rs_is_ant_connected(valid_antenna, ANT_MAIN);
1003 else
1004 return rs_is_ant_connected(valid_antenna, ANT_AUX);
1005
1006 return 0;
1007}
1008
1009/* 959/*
1010 * Begin a period of staying with a selected modulation mode. 960 * Begin a period of staying with a selected modulation mode.
1011 * Set "stay_in_tbl" flag to prevent any mode switches. 961 * Set "stay_in_tbl" flag to prevent any mode switches.
@@ -1014,10 +964,10 @@ static u8 rs_is_other_ant_connected(u8 valid_antenna,
1014 * These control how long we stay using same modulation mode before 964 * These control how long we stay using same modulation mode before
1015 * searching for a new mode. 965 * searching for a new mode.
1016 */ 966 */
1017static void rs_set_stay_in_table(u8 is_legacy, 967static void rs_set_stay_in_table(struct iwl_priv *priv, u8 is_legacy,
1018 struct iwl4965_lq_sta *lq_sta) 968 struct iwl_lq_sta *lq_sta)
1019{ 969{
1020 IWL_DEBUG_HT("we are staying in the same table\n"); 970 IWL_DEBUG_RATE("we are staying in the same table\n");
1021 lq_sta->stay_in_tbl = 1; /* only place this gets set */ 971 lq_sta->stay_in_tbl = 1; /* only place this gets set */
1022 if (is_legacy) { 972 if (is_legacy) {
1023 lq_sta->table_count_limit = IWL_LEGACY_TABLE_COUNT; 973 lq_sta->table_count_limit = IWL_LEGACY_TABLE_COUNT;
@@ -1036,8 +986,8 @@ static void rs_set_stay_in_table(u8 is_legacy,
1036/* 986/*
1037 * Find correct throughput table for given mode of modulation 987 * Find correct throughput table for given mode of modulation
1038 */ 988 */
1039static void rs_get_expected_tpt_table(struct iwl4965_lq_sta *lq_sta, 989static void rs_set_expected_tpt_table(struct iwl_lq_sta *lq_sta,
1040 struct iwl4965_scale_tbl_info *tbl) 990 struct iwl_scale_tbl_info *tbl)
1041{ 991{
1042 if (is_legacy(tbl->lq_type)) { 992 if (is_legacy(tbl->lq_type)) {
1043 if (!is_a_band(tbl->lq_type)) 993 if (!is_a_band(tbl->lq_type))
@@ -1055,7 +1005,7 @@ static void rs_get_expected_tpt_table(struct iwl4965_lq_sta *lq_sta,
1055 else 1005 else
1056 tbl->expected_tpt = expected_tpt_siso20MHz; 1006 tbl->expected_tpt = expected_tpt_siso20MHz;
1057 1007
1058 } else if (is_mimo(tbl->lq_type)) { 1008 } else if (is_mimo(tbl->lq_type)) { /* FIXME:need to separate mimo2/3 */
1059 if (tbl->is_fat && !lq_sta->is_dup) 1009 if (tbl->is_fat && !lq_sta->is_dup)
1060 if (tbl->is_SGI) 1010 if (tbl->is_SGI)
1061 tbl->expected_tpt = expected_tpt_mimo40MHzSGI; 1011 tbl->expected_tpt = expected_tpt_mimo40MHzSGI;
@@ -1069,7 +1019,6 @@ static void rs_get_expected_tpt_table(struct iwl4965_lq_sta *lq_sta,
1069 tbl->expected_tpt = expected_tpt_G; 1019 tbl->expected_tpt = expected_tpt_G;
1070} 1020}
1071 1021
1072#ifdef CONFIG_IWL4965_HT
1073/* 1022/*
1074 * Find starting rate for new "search" high-throughput mode of modulation. 1023 * Find starting rate for new "search" high-throughput mode of modulation.
1075 * Goal is to find lowest expected rate (under perfect conditions) that is 1024 * Goal is to find lowest expected rate (under perfect conditions) that is
@@ -1083,12 +1032,12 @@ static void rs_get_expected_tpt_table(struct iwl4965_lq_sta *lq_sta,
1083 * bit rate will typically need to increase, but not if performance was bad. 1032 * bit rate will typically need to increase, but not if performance was bad.
1084 */ 1033 */
1085static s32 rs_get_best_rate(struct iwl_priv *priv, 1034static s32 rs_get_best_rate(struct iwl_priv *priv,
1086 struct iwl4965_lq_sta *lq_sta, 1035 struct iwl_lq_sta *lq_sta,
1087 struct iwl4965_scale_tbl_info *tbl, /* "search" */ 1036 struct iwl_scale_tbl_info *tbl, /* "search" */
1088 u16 rate_mask, s8 index, s8 rate) 1037 u16 rate_mask, s8 index)
1089{ 1038{
1090 /* "active" values */ 1039 /* "active" values */
1091 struct iwl4965_scale_tbl_info *active_tbl = 1040 struct iwl_scale_tbl_info *active_tbl =
1092 &(lq_sta->lq_info[lq_sta->active_tbl]); 1041 &(lq_sta->lq_info[lq_sta->active_tbl]);
1093 s32 active_sr = active_tbl->win[index].success_ratio; 1042 s32 active_sr = active_tbl->win[index].success_ratio;
1094 s32 active_tpt = active_tbl->expected_tpt[index]; 1043 s32 active_tpt = active_tbl->expected_tpt[index];
@@ -1098,11 +1047,13 @@ static s32 rs_get_best_rate(struct iwl_priv *priv,
1098 1047
1099 s32 new_rate, high, low, start_hi; 1048 s32 new_rate, high, low, start_hi;
1100 u16 high_low; 1049 u16 high_low;
1050 s8 rate = index;
1101 1051
1102 new_rate = high = low = start_hi = IWL_RATE_INVALID; 1052 new_rate = high = low = start_hi = IWL_RATE_INVALID;
1103 1053
1104 for (; ;) { 1054 for (; ;) {
1105 high_low = rs_get_adjacent_rate(rate, rate_mask, tbl->lq_type); 1055 high_low = rs_get_adjacent_rate(priv, rate, rate_mask,
1056 tbl->lq_type);
1106 1057
1107 low = high_low & 0xff; 1058 low = high_low & 0xff;
1108 high = (high_low >> 8) & 0xff; 1059 high = (high_low >> 8) & 0xff;
@@ -1162,6 +1113,7 @@ static s32 rs_get_best_rate(struct iwl_priv *priv,
1162 1113
1163 /* Higher rate not available, use the original */ 1114 /* Higher rate not available, use the original */
1164 } else { 1115 } else {
1116 new_rate = rate;
1165 break; 1117 break;
1166 } 1118 }
1167 } 1119 }
@@ -1169,23 +1121,16 @@ static s32 rs_get_best_rate(struct iwl_priv *priv,
1169 1121
1170 return new_rate; 1122 return new_rate;
1171} 1123}
1172#endif /* CONFIG_IWL4965_HT */
1173
1174static inline u8 rs_is_both_ant_supp(u8 valid_antenna)
1175{
1176 return (rs_is_ant_connected(valid_antenna, ANT_BOTH));
1177}
1178 1124
1179/* 1125/*
1180 * Set up search table for MIMO 1126 * Set up search table for MIMO
1181 */ 1127 */
1182static int rs_switch_to_mimo(struct iwl_priv *priv, 1128static int rs_switch_to_mimo2(struct iwl_priv *priv,
1183 struct iwl4965_lq_sta *lq_sta, 1129 struct iwl_lq_sta *lq_sta,
1184 struct ieee80211_conf *conf, 1130 struct ieee80211_conf *conf,
1185 struct sta_info *sta, 1131 struct ieee80211_sta *sta,
1186 struct iwl4965_scale_tbl_info *tbl, int index) 1132 struct iwl_scale_tbl_info *tbl, int index)
1187{ 1133{
1188#ifdef CONFIG_IWL4965_HT
1189 u16 rate_mask; 1134 u16 rate_mask;
1190 s32 rate; 1135 s32 rate;
1191 s8 is_green = lq_sta->is_green; 1136 s8 is_green = lq_sta->is_green;
@@ -1194,26 +1139,28 @@ static int rs_switch_to_mimo(struct iwl_priv *priv,
1194 !sta->ht_info.ht_supported) 1139 !sta->ht_info.ht_supported)
1195 return -1; 1140 return -1;
1196 1141
1197 IWL_DEBUG_HT("LQ: try to switch to MIMO\n"); 1142 if (((sta->ht_info.cap & IEEE80211_HT_CAP_SM_PS) >> 2)
1198 tbl->lq_type = LQ_MIMO; 1143 == WLAN_HT_CAP_SM_PS_STATIC)
1199 rs_get_supported_rates(lq_sta, NULL, tbl->lq_type,
1200 &rate_mask);
1201
1202 if (priv->current_ht_config.tx_mimo_ps_mode == IWL_MIMO_PS_STATIC)
1203 return -1; 1144 return -1;
1204 1145
1205 /* Need both Tx chains/antennas to support MIMO */ 1146 /* Need both Tx chains/antennas to support MIMO */
1206 if (!rs_is_both_ant_supp(lq_sta->antenna)) 1147 if (priv->hw_params.tx_chains_num < 2)
1207 return -1; 1148 return -1;
1208 1149
1150 IWL_DEBUG_RATE("LQ: try to switch to MIMO2\n");
1151
1152 tbl->lq_type = LQ_MIMO2;
1209 tbl->is_dup = lq_sta->is_dup; 1153 tbl->is_dup = lq_sta->is_dup;
1210 tbl->action = 0; 1154 tbl->action = 0;
1155 rate_mask = lq_sta->active_mimo2_rate;
1156
1211 if (priv->current_ht_config.supported_chan_width 1157 if (priv->current_ht_config.supported_chan_width
1212 == IWL_CHANNEL_WIDTH_40MHZ) 1158 == IWL_CHANNEL_WIDTH_40MHZ)
1213 tbl->is_fat = 1; 1159 tbl->is_fat = 1;
1214 else 1160 else
1215 tbl->is_fat = 0; 1161 tbl->is_fat = 0;
1216 1162
1163 /* FIXME: - don't toggle SGI here
1217 if (tbl->is_fat) { 1164 if (tbl->is_fat) {
1218 if (priv->current_ht_config.sgf & HT_SHORT_GI_40MHZ_ONLY) 1165 if (priv->current_ht_config.sgf & HT_SHORT_GI_40MHZ_ONLY)
1219 tbl->is_SGI = 1; 1166 tbl->is_SGI = 1;
@@ -1223,48 +1170,49 @@ static int rs_switch_to_mimo(struct iwl_priv *priv,
1223 tbl->is_SGI = 1; 1170 tbl->is_SGI = 1;
1224 else 1171 else
1225 tbl->is_SGI = 0; 1172 tbl->is_SGI = 0;
1173 */
1174
1175 rs_set_expected_tpt_table(lq_sta, tbl);
1226 1176
1227 rs_get_expected_tpt_table(lq_sta, tbl); 1177 rate = rs_get_best_rate(priv, lq_sta, tbl, rate_mask, index);
1228 1178
1229 rate = rs_get_best_rate(priv, lq_sta, tbl, rate_mask, index, index); 1179 IWL_DEBUG_RATE("LQ: MIMO2 best rate %d mask %X\n", rate, rate_mask);
1230 1180
1231 IWL_DEBUG_HT("LQ: MIMO best rate %d mask %X\n", rate, rate_mask); 1181 if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) {
1232 if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) 1182 IWL_DEBUG_RATE("Can't switch with index %d rate mask %x\n",
1183 rate, rate_mask);
1233 return -1; 1184 return -1;
1234 rs_mcs_from_tbl(&tbl->current_rate, tbl, rate, is_green); 1185 }
1186 tbl->current_rate = rate_n_flags_from_tbl(tbl, rate, is_green);
1235 1187
1236 IWL_DEBUG_HT("LQ: Switch to new mcs %X index is green %X\n", 1188 IWL_DEBUG_RATE("LQ: Switch to new mcs %X index is green %X\n",
1237 tbl->current_rate.rate_n_flags, is_green); 1189 tbl->current_rate, is_green);
1238 return 0; 1190 return 0;
1239#else
1240 return -1;
1241#endif /*CONFIG_IWL4965_HT */
1242} 1191}
1243 1192
1244/* 1193/*
1245 * Set up search table for SISO 1194 * Set up search table for SISO
1246 */ 1195 */
1247static int rs_switch_to_siso(struct iwl_priv *priv, 1196static int rs_switch_to_siso(struct iwl_priv *priv,
1248 struct iwl4965_lq_sta *lq_sta, 1197 struct iwl_lq_sta *lq_sta,
1249 struct ieee80211_conf *conf, 1198 struct ieee80211_conf *conf,
1250 struct sta_info *sta, 1199 struct ieee80211_sta *sta,
1251 struct iwl4965_scale_tbl_info *tbl, int index) 1200 struct iwl_scale_tbl_info *tbl, int index)
1252{ 1201{
1253#ifdef CONFIG_IWL4965_HT
1254 u16 rate_mask; 1202 u16 rate_mask;
1255 u8 is_green = lq_sta->is_green; 1203 u8 is_green = lq_sta->is_green;
1256 s32 rate; 1204 s32 rate;
1257 1205
1258 IWL_DEBUG_HT("LQ: try to switch to SISO\n");
1259 if (!(conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) || 1206 if (!(conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) ||
1260 !sta->ht_info.ht_supported) 1207 !sta->ht_info.ht_supported)
1261 return -1; 1208 return -1;
1262 1209
1210 IWL_DEBUG_RATE("LQ: try to switch to SISO\n");
1211
1263 tbl->is_dup = lq_sta->is_dup; 1212 tbl->is_dup = lq_sta->is_dup;
1264 tbl->lq_type = LQ_SISO; 1213 tbl->lq_type = LQ_SISO;
1265 tbl->action = 0; 1214 tbl->action = 0;
1266 rs_get_supported_rates(lq_sta, NULL, tbl->lq_type, 1215 rate_mask = lq_sta->active_siso_rate;
1267 &rate_mask);
1268 1216
1269 if (priv->current_ht_config.supported_chan_width 1217 if (priv->current_ht_config.supported_chan_width
1270 == IWL_CHANNEL_WIDTH_40MHZ) 1218 == IWL_CHANNEL_WIDTH_40MHZ)
@@ -1272,6 +1220,7 @@ static int rs_switch_to_siso(struct iwl_priv *priv,
1272 else 1220 else
1273 tbl->is_fat = 0; 1221 tbl->is_fat = 0;
1274 1222
1223 /* FIXME: - don't toggle SGI here
1275 if (tbl->is_fat) { 1224 if (tbl->is_fat) {
1276 if (priv->current_ht_config.sgf & HT_SHORT_GI_40MHZ_ONLY) 1225 if (priv->current_ht_config.sgf & HT_SHORT_GI_40MHZ_ONLY)
1277 tbl->is_SGI = 1; 1226 tbl->is_SGI = 1;
@@ -1281,123 +1230,130 @@ static int rs_switch_to_siso(struct iwl_priv *priv,
1281 tbl->is_SGI = 1; 1230 tbl->is_SGI = 1;
1282 else 1231 else
1283 tbl->is_SGI = 0; 1232 tbl->is_SGI = 0;
1233 */
1284 1234
1285 if (is_green) 1235 if (is_green)
1286 tbl->is_SGI = 0; 1236 tbl->is_SGI = 0; /*11n spec: no SGI in SISO+Greenfield*/
1287 1237
1288 rs_get_expected_tpt_table(lq_sta, tbl); 1238 rs_set_expected_tpt_table(lq_sta, tbl);
1289 rate = rs_get_best_rate(priv, lq_sta, tbl, rate_mask, index, index); 1239 rate = rs_get_best_rate(priv, lq_sta, tbl, rate_mask, index);
1290 1240
1291 IWL_DEBUG_HT("LQ: get best rate %d mask %X\n", rate, rate_mask); 1241 IWL_DEBUG_RATE("LQ: get best rate %d mask %X\n", rate, rate_mask);
1292 if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) { 1242 if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) {
1293 IWL_DEBUG_HT("can not switch with index %d rate mask %x\n", 1243 IWL_DEBUG_RATE("can not switch with index %d rate mask %x\n",
1294 rate, rate_mask); 1244 rate, rate_mask);
1295 return -1; 1245 return -1;
1296 } 1246 }
1297 rs_mcs_from_tbl(&tbl->current_rate, tbl, rate, is_green); 1247 tbl->current_rate = rate_n_flags_from_tbl(tbl, rate, is_green);
1298 IWL_DEBUG_HT("LQ: Switch to new mcs %X index is green %X\n", 1248 IWL_DEBUG_RATE("LQ: Switch to new mcs %X index is green %X\n",
1299 tbl->current_rate.rate_n_flags, is_green); 1249 tbl->current_rate, is_green);
1300 return 0; 1250 return 0;
1301#else
1302 return -1;
1303
1304#endif /*CONFIG_IWL4965_HT */
1305} 1251}
1306 1252
1307/* 1253/*
1308 * Try to switch to new modulation mode from legacy 1254 * Try to switch to new modulation mode from legacy
1309 */ 1255 */
1310static int rs_move_legacy_other(struct iwl_priv *priv, 1256static int rs_move_legacy_other(struct iwl_priv *priv,
1311 struct iwl4965_lq_sta *lq_sta, 1257 struct iwl_lq_sta *lq_sta,
1312 struct ieee80211_conf *conf, 1258 struct ieee80211_conf *conf,
1313 struct sta_info *sta, 1259 struct ieee80211_sta *sta,
1314 int index) 1260 int index)
1315{ 1261{
1316 int ret = 0; 1262 struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
1317 struct iwl4965_scale_tbl_info *tbl = 1263 struct iwl_scale_tbl_info *search_tbl =
1318 &(lq_sta->lq_info[lq_sta->active_tbl]); 1264 &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
1319 struct iwl4965_scale_tbl_info *search_tbl = 1265 struct iwl_rate_scale_data *window = &(tbl->win[index]);
1320 &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]); 1266 u32 sz = (sizeof(struct iwl_scale_tbl_info) -
1321 struct iwl4965_rate_scale_data *window = &(tbl->win[index]); 1267 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
1322 u32 sz = (sizeof(struct iwl4965_scale_tbl_info) -
1323 (sizeof(struct iwl4965_rate_scale_data) * IWL_RATE_COUNT));
1324 u8 start_action = tbl->action; 1268 u8 start_action = tbl->action;
1269 u8 valid_tx_ant = priv->hw_params.valid_tx_ant;
1270 u8 tx_chains_num = priv->hw_params.tx_chains_num;
1271 int ret = 0;
1325 1272
1326 for (; ;) { 1273 for (; ;) {
1327 switch (tbl->action) { 1274 switch (tbl->action) {
1328 case IWL_LEGACY_SWITCH_ANTENNA: 1275 case IWL_LEGACY_SWITCH_ANTENNA1:
1329 IWL_DEBUG_HT("LQ Legacy switch Antenna\n"); 1276 case IWL_LEGACY_SWITCH_ANTENNA2:
1277 IWL_DEBUG_RATE("LQ: Legacy toggle Antenna\n");
1330 1278
1331 search_tbl->lq_type = LQ_NONE;
1332 lq_sta->action_counter++; 1279 lq_sta->action_counter++;
1333 1280
1334 /* Don't change antenna if success has been great */ 1281 if ((tbl->action == IWL_LEGACY_SWITCH_ANTENNA1 &&
1335 if (window->success_ratio >= IWL_RS_GOOD_RATIO) 1282 tx_chains_num <= 1) ||
1283 (tbl->action == IWL_LEGACY_SWITCH_ANTENNA2 &&
1284 tx_chains_num <= 2))
1336 break; 1285 break;
1337 1286
1338 /* Don't change antenna if other one is not connected */ 1287 /* Don't change antenna if success has been great */
1339 if (!rs_is_other_ant_connected(lq_sta->antenna, 1288 if (window->success_ratio >= IWL_RS_GOOD_RATIO)
1340 tbl->antenna_type))
1341 break; 1289 break;
1342 1290
1343 /* Set up search table to try other antenna */ 1291 /* Set up search table to try other antenna */
1344 memcpy(search_tbl, tbl, sz); 1292 memcpy(search_tbl, tbl, sz);
1345 1293
1346 rs_toggle_antenna(&(search_tbl->current_rate), 1294 if (rs_toggle_antenna(valid_tx_ant,
1347 search_tbl); 1295 &search_tbl->current_rate, search_tbl)) {
1348 rs_get_expected_tpt_table(lq_sta, search_tbl); 1296 rs_set_expected_tpt_table(lq_sta, search_tbl);
1349 lq_sta->search_better_tbl = 1; 1297 goto out;
1350 goto out; 1298 }
1351 1299 break;
1352 case IWL_LEGACY_SWITCH_SISO: 1300 case IWL_LEGACY_SWITCH_SISO:
1353 IWL_DEBUG_HT("LQ: Legacy switch to SISO\n"); 1301 IWL_DEBUG_RATE("LQ: Legacy switch to SISO\n");
1354 1302
1355 /* Set up search table to try SISO */ 1303 /* Set up search table to try SISO */
1356 memcpy(search_tbl, tbl, sz); 1304 memcpy(search_tbl, tbl, sz);
1357 search_tbl->lq_type = LQ_SISO;
1358 search_tbl->is_SGI = 0; 1305 search_tbl->is_SGI = 0;
1359 search_tbl->is_fat = 0;
1360 ret = rs_switch_to_siso(priv, lq_sta, conf, sta, 1306 ret = rs_switch_to_siso(priv, lq_sta, conf, sta,
1361 search_tbl, index); 1307 search_tbl, index);
1362 if (!ret) { 1308 if (!ret) {
1363 lq_sta->search_better_tbl = 1;
1364 lq_sta->action_counter = 0; 1309 lq_sta->action_counter = 0;
1365 goto out; 1310 goto out;
1366 } 1311 }
1367 1312
1368 break; 1313 break;
1369 case IWL_LEGACY_SWITCH_MIMO: 1314 case IWL_LEGACY_SWITCH_MIMO2_AB:
1370 IWL_DEBUG_HT("LQ: Legacy switch MIMO\n"); 1315 case IWL_LEGACY_SWITCH_MIMO2_AC:
1316 case IWL_LEGACY_SWITCH_MIMO2_BC:
1317 IWL_DEBUG_RATE("LQ: Legacy switch to MIMO2\n");
1371 1318
1372 /* Set up search table to try MIMO */ 1319 /* Set up search table to try MIMO */
1373 memcpy(search_tbl, tbl, sz); 1320 memcpy(search_tbl, tbl, sz);
1374 search_tbl->lq_type = LQ_MIMO;
1375 search_tbl->is_SGI = 0; 1321 search_tbl->is_SGI = 0;
1376 search_tbl->is_fat = 0; 1322
1377 search_tbl->antenna_type = ANT_BOTH; 1323 if (tbl->action == IWL_LEGACY_SWITCH_MIMO2_AB)
1378 ret = rs_switch_to_mimo(priv, lq_sta, conf, sta, 1324 search_tbl->ant_type = ANT_AB;
1325 else if (tbl->action == IWL_LEGACY_SWITCH_MIMO2_AC)
1326 search_tbl->ant_type = ANT_AC;
1327 else
1328 search_tbl->ant_type = ANT_BC;
1329
1330 if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type))
1331 break;
1332
1333 ret = rs_switch_to_mimo2(priv, lq_sta, conf, sta,
1379 search_tbl, index); 1334 search_tbl, index);
1380 if (!ret) { 1335 if (!ret) {
1381 lq_sta->search_better_tbl = 1;
1382 lq_sta->action_counter = 0; 1336 lq_sta->action_counter = 0;
1383 goto out; 1337 goto out;
1384 } 1338 }
1385 break; 1339 break;
1386 } 1340 }
1387 tbl->action++; 1341 tbl->action++;
1388 if (tbl->action > IWL_LEGACY_SWITCH_MIMO) 1342 if (tbl->action > IWL_LEGACY_SWITCH_MIMO2_BC)
1389 tbl->action = IWL_LEGACY_SWITCH_ANTENNA; 1343 tbl->action = IWL_LEGACY_SWITCH_ANTENNA1;
1390 1344
1391 if (tbl->action == start_action) 1345 if (tbl->action == start_action)
1392 break; 1346 break;
1393 1347
1394 } 1348 }
1349 search_tbl->lq_type = LQ_NONE;
1395 return 0; 1350 return 0;
1396 1351
1397 out: 1352out:
1353 lq_sta->search_better_tbl = 1;
1398 tbl->action++; 1354 tbl->action++;
1399 if (tbl->action > IWL_LEGACY_SWITCH_MIMO) 1355 if (tbl->action > IWL_LEGACY_SWITCH_MIMO2_BC)
1400 tbl->action = IWL_LEGACY_SWITCH_ANTENNA; 1356 tbl->action = IWL_LEGACY_SWITCH_ANTENNA1;
1401 return 0; 1357 return 0;
1402 1358
1403} 1359}
@@ -1406,95 +1362,110 @@ static int rs_move_legacy_other(struct iwl_priv *priv,
1406 * Try to switch to new modulation mode from SISO 1362 * Try to switch to new modulation mode from SISO
1407 */ 1363 */
1408static int rs_move_siso_to_other(struct iwl_priv *priv, 1364static int rs_move_siso_to_other(struct iwl_priv *priv,
1409 struct iwl4965_lq_sta *lq_sta, 1365 struct iwl_lq_sta *lq_sta,
1410 struct ieee80211_conf *conf, 1366 struct ieee80211_conf *conf,
1411 struct sta_info *sta, 1367 struct ieee80211_sta *sta, int index)
1412 int index)
1413{ 1368{
1414 int ret;
1415 u8 is_green = lq_sta->is_green; 1369 u8 is_green = lq_sta->is_green;
1416 struct iwl4965_scale_tbl_info *tbl = 1370 struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
1417 &(lq_sta->lq_info[lq_sta->active_tbl]); 1371 struct iwl_scale_tbl_info *search_tbl =
1418 struct iwl4965_scale_tbl_info *search_tbl = 1372 &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
1419 &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]); 1373 struct iwl_rate_scale_data *window = &(tbl->win[index]);
1420 struct iwl4965_rate_scale_data *window = &(tbl->win[index]); 1374 u32 sz = (sizeof(struct iwl_scale_tbl_info) -
1421 u32 sz = (sizeof(struct iwl4965_scale_tbl_info) - 1375 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
1422 (sizeof(struct iwl4965_rate_scale_data) * IWL_RATE_COUNT));
1423 u8 start_action = tbl->action; 1376 u8 start_action = tbl->action;
1377 u8 valid_tx_ant = priv->hw_params.valid_tx_ant;
1378 u8 tx_chains_num = priv->hw_params.tx_chains_num;
1379 int ret;
1424 1380
1425 for (;;) { 1381 for (;;) {
1426 lq_sta->action_counter++; 1382 lq_sta->action_counter++;
1427 switch (tbl->action) { 1383 switch (tbl->action) {
1428 case IWL_SISO_SWITCH_ANTENNA: 1384 case IWL_SISO_SWITCH_ANTENNA1:
1429 IWL_DEBUG_HT("LQ: SISO SWITCH ANTENNA SISO\n"); 1385 case IWL_SISO_SWITCH_ANTENNA2:
1430 search_tbl->lq_type = LQ_NONE; 1386 IWL_DEBUG_RATE("LQ: SISO toggle Antenna\n");
1431 if (window->success_ratio >= IWL_RS_GOOD_RATIO) 1387
1388 if ((tbl->action == IWL_SISO_SWITCH_ANTENNA1 &&
1389 tx_chains_num <= 1) ||
1390 (tbl->action == IWL_SISO_SWITCH_ANTENNA2 &&
1391 tx_chains_num <= 2))
1432 break; 1392 break;
1433 if (!rs_is_other_ant_connected(lq_sta->antenna, 1393
1434 tbl->antenna_type)) 1394 if (window->success_ratio >= IWL_RS_GOOD_RATIO)
1435 break; 1395 break;
1436 1396
1437 memcpy(search_tbl, tbl, sz); 1397 memcpy(search_tbl, tbl, sz);
1438 search_tbl->action = IWL_SISO_SWITCH_MIMO; 1398 if (rs_toggle_antenna(valid_tx_ant,
1439 rs_toggle_antenna(&(search_tbl->current_rate), 1399 &search_tbl->current_rate, search_tbl))
1440 search_tbl); 1400 goto out;
1441 lq_sta->search_better_tbl = 1; 1401 break;
1442 1402 case IWL_SISO_SWITCH_MIMO2_AB:
1443 goto out; 1403 case IWL_SISO_SWITCH_MIMO2_AC:
1444 1404 case IWL_SISO_SWITCH_MIMO2_BC:
1445 case IWL_SISO_SWITCH_MIMO: 1405 IWL_DEBUG_RATE("LQ: SISO switch to MIMO2\n");
1446 IWL_DEBUG_HT("LQ: SISO SWITCH TO MIMO FROM SISO\n");
1447 memcpy(search_tbl, tbl, sz); 1406 memcpy(search_tbl, tbl, sz);
1448 search_tbl->lq_type = LQ_MIMO;
1449 search_tbl->is_SGI = 0; 1407 search_tbl->is_SGI = 0;
1450 search_tbl->is_fat = 0; 1408
1451 search_tbl->antenna_type = ANT_BOTH; 1409 if (tbl->action == IWL_SISO_SWITCH_MIMO2_AB)
1452 ret = rs_switch_to_mimo(priv, lq_sta, conf, sta, 1410 search_tbl->ant_type = ANT_AB;
1411 else if (tbl->action == IWL_SISO_SWITCH_MIMO2_AC)
1412 search_tbl->ant_type = ANT_AC;
1413 else
1414 search_tbl->ant_type = ANT_BC;
1415
1416 if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type))
1417 break;
1418
1419 ret = rs_switch_to_mimo2(priv, lq_sta, conf, sta,
1453 search_tbl, index); 1420 search_tbl, index);
1454 if (!ret) { 1421 if (!ret)
1455 lq_sta->search_better_tbl = 1;
1456 goto out; 1422 goto out;
1457 }
1458 break; 1423 break;
1459 case IWL_SISO_SWITCH_GI: 1424 case IWL_SISO_SWITCH_GI:
1460 IWL_DEBUG_HT("LQ: SISO SWITCH TO GI\n"); 1425 if (!tbl->is_fat &&
1426 !(priv->current_ht_config.sgf &
1427 HT_SHORT_GI_20MHZ))
1428 break;
1429 if (tbl->is_fat &&
1430 !(priv->current_ht_config.sgf &
1431 HT_SHORT_GI_40MHZ))
1432 break;
1433
1434 IWL_DEBUG_RATE("LQ: SISO toggle SGI/NGI\n");
1461 1435
1462 memcpy(search_tbl, tbl, sz); 1436 memcpy(search_tbl, tbl, sz);
1463 search_tbl->action = 0; 1437 if (is_green) {
1464 if (search_tbl->is_SGI) 1438 if (!tbl->is_SGI)
1465 search_tbl->is_SGI = 0; 1439 break;
1466 else if (!is_green) 1440 else
1467 search_tbl->is_SGI = 1; 1441 IWL_ERROR("SGI was set in GF+SISO\n");
1468 else 1442 }
1469 break; 1443 search_tbl->is_SGI = !tbl->is_SGI;
1470 lq_sta->search_better_tbl = 1; 1444 rs_set_expected_tpt_table(lq_sta, search_tbl);
1471 if ((tbl->lq_type == LQ_SISO) && 1445 if (tbl->is_SGI) {
1472 (tbl->is_SGI)) {
1473 s32 tpt = lq_sta->last_tpt / 100; 1446 s32 tpt = lq_sta->last_tpt / 100;
1474 if (((!tbl->is_fat) && 1447 if (tpt >= search_tbl->expected_tpt[index])
1475 (tpt >= expected_tpt_siso20MHz[index])) || 1448 break;
1476 ((tbl->is_fat) &&
1477 (tpt >= expected_tpt_siso40MHz[index])))
1478 lq_sta->search_better_tbl = 0;
1479 } 1449 }
1480 rs_get_expected_tpt_table(lq_sta, search_tbl); 1450 search_tbl->current_rate = rate_n_flags_from_tbl(
1481 rs_mcs_from_tbl(&search_tbl->current_rate, 1451 search_tbl, index, is_green);
1482 search_tbl, index, is_green);
1483 goto out; 1452 goto out;
1484 } 1453 }
1485 tbl->action++; 1454 tbl->action++;
1486 if (tbl->action > IWL_SISO_SWITCH_GI) 1455 if (tbl->action > IWL_SISO_SWITCH_GI)
1487 tbl->action = IWL_SISO_SWITCH_ANTENNA; 1456 tbl->action = IWL_SISO_SWITCH_ANTENNA1;
1488 1457
1489 if (tbl->action == start_action) 1458 if (tbl->action == start_action)
1490 break; 1459 break;
1491 } 1460 }
1461 search_tbl->lq_type = LQ_NONE;
1492 return 0; 1462 return 0;
1493 1463
1494 out: 1464 out:
1465 lq_sta->search_better_tbl = 1;
1495 tbl->action++; 1466 tbl->action++;
1496 if (tbl->action > IWL_SISO_SWITCH_GI) 1467 if (tbl->action > IWL_SISO_SWITCH_GI)
1497 tbl->action = IWL_SISO_SWITCH_ANTENNA; 1468 tbl->action = IWL_SISO_SWITCH_ANTENNA1;
1498 return 0; 1469 return 0;
1499} 1470}
1500 1471
@@ -1502,95 +1473,111 @@ static int rs_move_siso_to_other(struct iwl_priv *priv,
1502 * Try to switch to new modulation mode from MIMO 1473 * Try to switch to new modulation mode from MIMO
1503 */ 1474 */
1504static int rs_move_mimo_to_other(struct iwl_priv *priv, 1475static int rs_move_mimo_to_other(struct iwl_priv *priv,
1505 struct iwl4965_lq_sta *lq_sta, 1476 struct iwl_lq_sta *lq_sta,
1506 struct ieee80211_conf *conf, 1477 struct ieee80211_conf *conf,
1507 struct sta_info *sta, 1478 struct ieee80211_sta *sta, int index)
1508 int index)
1509{ 1479{
1510 int ret;
1511 s8 is_green = lq_sta->is_green; 1480 s8 is_green = lq_sta->is_green;
1512 struct iwl4965_scale_tbl_info *tbl = 1481 struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
1513 &(lq_sta->lq_info[lq_sta->active_tbl]); 1482 struct iwl_scale_tbl_info *search_tbl =
1514 struct iwl4965_scale_tbl_info *search_tbl = 1483 &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
1515 &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]); 1484 struct iwl_rate_scale_data *window = &(tbl->win[index]);
1516 u32 sz = (sizeof(struct iwl4965_scale_tbl_info) - 1485 u32 sz = (sizeof(struct iwl_scale_tbl_info) -
1517 (sizeof(struct iwl4965_rate_scale_data) * IWL_RATE_COUNT)); 1486 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
1518 u8 start_action = tbl->action; 1487 u8 start_action = tbl->action;
1488 u8 valid_tx_ant = priv->hw_params.valid_tx_ant;
1489 u8 tx_chains_num = priv->hw_params.tx_chains_num;
1490 int ret;
1519 1491
1520 for (;;) { 1492 for (;;) {
1521 lq_sta->action_counter++; 1493 lq_sta->action_counter++;
1522 switch (tbl->action) { 1494 switch (tbl->action) {
1523 case IWL_MIMO_SWITCH_ANTENNA_A: 1495 case IWL_MIMO2_SWITCH_ANTENNA1:
1524 case IWL_MIMO_SWITCH_ANTENNA_B: 1496 case IWL_MIMO2_SWITCH_ANTENNA2:
1525 IWL_DEBUG_HT("LQ: MIMO SWITCH TO SISO\n"); 1497 IWL_DEBUG_RATE("LQ: MIMO toggle Antennas\n");
1498
1499 if (tx_chains_num <= 2)
1500 break;
1526 1501
1502 if (window->success_ratio >= IWL_RS_GOOD_RATIO)
1503 break;
1504
1505 memcpy(search_tbl, tbl, sz);
1506 if (rs_toggle_antenna(valid_tx_ant,
1507 &search_tbl->current_rate, search_tbl))
1508 goto out;
1509 break;
1510 case IWL_MIMO2_SWITCH_SISO_A:
1511 case IWL_MIMO2_SWITCH_SISO_B:
1512 case IWL_MIMO2_SWITCH_SISO_C:
1513 IWL_DEBUG_RATE("LQ: MIMO2 switch to SISO\n");
1527 1514
1528 /* Set up new search table for SISO */ 1515 /* Set up new search table for SISO */
1529 memcpy(search_tbl, tbl, sz); 1516 memcpy(search_tbl, tbl, sz);
1530 search_tbl->lq_type = LQ_SISO; 1517
1531 search_tbl->is_SGI = 0; 1518 if (tbl->action == IWL_MIMO2_SWITCH_SISO_A)
1532 search_tbl->is_fat = 0; 1519 search_tbl->ant_type = ANT_A;
1533 if (tbl->action == IWL_MIMO_SWITCH_ANTENNA_A) 1520 else if (tbl->action == IWL_MIMO2_SWITCH_SISO_B)
1534 search_tbl->antenna_type = ANT_MAIN; 1521 search_tbl->ant_type = ANT_B;
1535 else 1522 else
1536 search_tbl->antenna_type = ANT_AUX; 1523 search_tbl->ant_type = ANT_C;
1524
1525 if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type))
1526 break;
1537 1527
1538 ret = rs_switch_to_siso(priv, lq_sta, conf, sta, 1528 ret = rs_switch_to_siso(priv, lq_sta, conf, sta,
1539 search_tbl, index); 1529 search_tbl, index);
1540 if (!ret) { 1530 if (!ret)
1541 lq_sta->search_better_tbl = 1;
1542 goto out; 1531 goto out;
1543 } 1532
1544 break; 1533 break;
1545 1534
1546 case IWL_MIMO_SWITCH_GI: 1535 case IWL_MIMO2_SWITCH_GI:
1547 IWL_DEBUG_HT("LQ: MIMO SWITCH TO GI\n"); 1536 if (!tbl->is_fat &&
1537 !(priv->current_ht_config.sgf &
1538 HT_SHORT_GI_20MHZ))
1539 break;
1540 if (tbl->is_fat &&
1541 !(priv->current_ht_config.sgf &
1542 HT_SHORT_GI_40MHZ))
1543 break;
1544
1545 IWL_DEBUG_RATE("LQ: MIMO toggle SGI/NGI\n");
1548 1546
1549 /* Set up new search table for MIMO */ 1547 /* Set up new search table for MIMO */
1550 memcpy(search_tbl, tbl, sz); 1548 memcpy(search_tbl, tbl, sz);
1551 search_tbl->lq_type = LQ_MIMO; 1549 search_tbl->is_SGI = !tbl->is_SGI;
1552 search_tbl->antenna_type = ANT_BOTH; 1550 rs_set_expected_tpt_table(lq_sta, search_tbl);
1553 search_tbl->action = 0;
1554 if (search_tbl->is_SGI)
1555 search_tbl->is_SGI = 0;
1556 else
1557 search_tbl->is_SGI = 1;
1558 lq_sta->search_better_tbl = 1;
1559
1560 /* 1551 /*
1561 * If active table already uses the fastest possible 1552 * If active table already uses the fastest possible
1562 * modulation (dual stream with short guard interval), 1553 * modulation (dual stream with short guard interval),
1563 * and it's working well, there's no need to look 1554 * and it's working well, there's no need to look
1564 * for a better type of modulation! 1555 * for a better type of modulation!
1565 */ 1556 */
1566 if ((tbl->lq_type == LQ_MIMO) && 1557 if (tbl->is_SGI) {
1567 (tbl->is_SGI)) {
1568 s32 tpt = lq_sta->last_tpt / 100; 1558 s32 tpt = lq_sta->last_tpt / 100;
1569 if (((!tbl->is_fat) && 1559 if (tpt >= search_tbl->expected_tpt[index])
1570 (tpt >= expected_tpt_mimo20MHz[index])) || 1560 break;
1571 ((tbl->is_fat) &&
1572 (tpt >= expected_tpt_mimo40MHz[index])))
1573 lq_sta->search_better_tbl = 0;
1574 } 1561 }
1575 rs_get_expected_tpt_table(lq_sta, search_tbl); 1562 search_tbl->current_rate = rate_n_flags_from_tbl(
1576 rs_mcs_from_tbl(&search_tbl->current_rate, 1563 search_tbl, index, is_green);
1577 search_tbl, index, is_green);
1578 goto out; 1564 goto out;
1579 1565
1580 } 1566 }
1581 tbl->action++; 1567 tbl->action++;
1582 if (tbl->action > IWL_MIMO_SWITCH_GI) 1568 if (tbl->action > IWL_MIMO2_SWITCH_GI)
1583 tbl->action = IWL_MIMO_SWITCH_ANTENNA_A; 1569 tbl->action = IWL_MIMO2_SWITCH_ANTENNA1;
1584 1570
1585 if (tbl->action == start_action) 1571 if (tbl->action == start_action)
1586 break; 1572 break;
1587 } 1573 }
1588 1574 search_tbl->lq_type = LQ_NONE;
1589 return 0; 1575 return 0;
1590 out: 1576 out:
1577 lq_sta->search_better_tbl = 1;
1591 tbl->action++; 1578 tbl->action++;
1592 if (tbl->action > IWL_MIMO_SWITCH_GI) 1579 if (tbl->action > IWL_MIMO2_SWITCH_GI)
1593 tbl->action = IWL_MIMO_SWITCH_ANTENNA_A; 1580 tbl->action = IWL_MIMO2_SWITCH_ANTENNA1;
1594 return 0; 1581 return 0;
1595 1582
1596} 1583}
@@ -1602,13 +1589,15 @@ static int rs_move_mimo_to_other(struct iwl_priv *priv,
1602 * 2) # times calling this function 1589 * 2) # times calling this function
1603 * 3) elapsed time in this mode (not used, for now) 1590 * 3) elapsed time in this mode (not used, for now)
1604 */ 1591 */
1605static void rs_stay_in_table(struct iwl4965_lq_sta *lq_sta) 1592static void rs_stay_in_table(struct iwl_lq_sta *lq_sta)
1606{ 1593{
1607 struct iwl4965_scale_tbl_info *tbl; 1594 struct iwl_scale_tbl_info *tbl;
1608 int i; 1595 int i;
1609 int active_tbl; 1596 int active_tbl;
1610 int flush_interval_passed = 0; 1597 int flush_interval_passed = 0;
1598 struct iwl_priv *priv;
1611 1599
1600 priv = lq_sta->drv;
1612 active_tbl = lq_sta->active_tbl; 1601 active_tbl = lq_sta->active_tbl;
1613 1602
1614 tbl = &(lq_sta->lq_info[active_tbl]); 1603 tbl = &(lq_sta->lq_info[active_tbl]);
@@ -1623,9 +1612,6 @@ static void rs_stay_in_table(struct iwl4965_lq_sta *lq_sta)
1623 (unsigned long)(lq_sta->flush_timer + 1612 (unsigned long)(lq_sta->flush_timer +
1624 IWL_RATE_SCALE_FLUSH_INTVL)); 1613 IWL_RATE_SCALE_FLUSH_INTVL));
1625 1614
1626 /* For now, disable the elapsed time criterion */
1627 flush_interval_passed = 0;
1628
1629 /* 1615 /*
1630 * Check if we should allow search for new modulation mode. 1616 * Check if we should allow search for new modulation mode.
1631 * If many frames have failed or succeeded, or we've used 1617 * If many frames have failed or succeeded, or we've used
@@ -1638,7 +1624,7 @@ static void rs_stay_in_table(struct iwl4965_lq_sta *lq_sta)
1638 (lq_sta->total_success > lq_sta->max_success_limit) || 1624 (lq_sta->total_success > lq_sta->max_success_limit) ||
1639 ((!lq_sta->search_better_tbl) && (lq_sta->flush_timer) 1625 ((!lq_sta->search_better_tbl) && (lq_sta->flush_timer)
1640 && (flush_interval_passed))) { 1626 && (flush_interval_passed))) {
1641 IWL_DEBUG_HT("LQ: stay is expired %d %d %d\n:", 1627 IWL_DEBUG_RATE("LQ: stay is expired %d %d %d\n:",
1642 lq_sta->total_failed, 1628 lq_sta->total_failed,
1643 lq_sta->total_success, 1629 lq_sta->total_success,
1644 flush_interval_passed); 1630 flush_interval_passed);
@@ -1661,7 +1647,7 @@ static void rs_stay_in_table(struct iwl4965_lq_sta *lq_sta)
1661 lq_sta->table_count_limit) { 1647 lq_sta->table_count_limit) {
1662 lq_sta->table_count = 0; 1648 lq_sta->table_count = 0;
1663 1649
1664 IWL_DEBUG_HT("LQ: stay in table clear win\n"); 1650 IWL_DEBUG_RATE("LQ: stay in table clear win\n");
1665 for (i = 0; i < IWL_RATE_COUNT; i++) 1651 for (i = 0; i < IWL_RATE_COUNT; i++)
1666 rs_rate_scale_clear_window( 1652 rs_rate_scale_clear_window(
1667 &(tbl->win[i])); 1653 &(tbl->win[i]));
@@ -1682,41 +1668,38 @@ static void rs_stay_in_table(struct iwl4965_lq_sta *lq_sta)
1682 * Do rate scaling and search for new modulation mode. 1668 * Do rate scaling and search for new modulation mode.
1683 */ 1669 */
1684static void rs_rate_scale_perform(struct iwl_priv *priv, 1670static void rs_rate_scale_perform(struct iwl_priv *priv,
1685 struct net_device *dev,
1686 struct ieee80211_hdr *hdr, 1671 struct ieee80211_hdr *hdr,
1687 struct sta_info *sta) 1672 struct ieee80211_sta *sta,
1673 struct iwl_lq_sta *lq_sta)
1688{ 1674{
1689 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 1675 struct ieee80211_hw *hw = priv->hw;
1690 struct ieee80211_hw *hw = local_to_hw(local);
1691 struct ieee80211_conf *conf = &hw->conf; 1676 struct ieee80211_conf *conf = &hw->conf;
1692 int low = IWL_RATE_INVALID; 1677 int low = IWL_RATE_INVALID;
1693 int high = IWL_RATE_INVALID; 1678 int high = IWL_RATE_INVALID;
1694 int index; 1679 int index;
1695 int i; 1680 int i;
1696 struct iwl4965_rate_scale_data *window = NULL; 1681 struct iwl_rate_scale_data *window = NULL;
1697 int current_tpt = IWL_INVALID_VALUE; 1682 int current_tpt = IWL_INVALID_VALUE;
1698 int low_tpt = IWL_INVALID_VALUE; 1683 int low_tpt = IWL_INVALID_VALUE;
1699 int high_tpt = IWL_INVALID_VALUE; 1684 int high_tpt = IWL_INVALID_VALUE;
1700 u32 fail_count; 1685 u32 fail_count;
1701 s8 scale_action = 0; 1686 s8 scale_action = 0;
1702 u16 fc, rate_mask; 1687 __le16 fc;
1688 u16 rate_mask;
1703 u8 update_lq = 0; 1689 u8 update_lq = 0;
1704 struct iwl4965_lq_sta *lq_sta; 1690 struct iwl_scale_tbl_info *tbl, *tbl1;
1705 struct iwl4965_scale_tbl_info *tbl, *tbl1;
1706 u16 rate_scale_index_msk = 0; 1691 u16 rate_scale_index_msk = 0;
1707 struct iwl4965_rate mcs_rate; 1692 u32 rate;
1708 u8 is_green = 0; 1693 u8 is_green = 0;
1709 u8 active_tbl = 0; 1694 u8 active_tbl = 0;
1710 u8 done_search = 0; 1695 u8 done_search = 0;
1711 u16 high_low; 1696 u16 high_low;
1712#ifdef CONFIG_IWL4965_HT 1697 s32 sr;
1713 u8 tid = MAX_TID_COUNT; 1698 u8 tid = MAX_TID_COUNT;
1714 __le16 *qc;
1715#endif
1716 1699
1717 IWL_DEBUG_RATE("rate scale calculate new rate for skb\n"); 1700 IWL_DEBUG_RATE("rate scale calculate new rate for skb\n");
1718 1701
1719 fc = le16_to_cpu(hdr->frame_control); 1702 fc = hdr->frame_control;
1720 if (!ieee80211_is_data(fc) || is_multicast_ether_addr(hdr->addr1)) { 1703 if (!ieee80211_is_data(fc) || is_multicast_ether_addr(hdr->addr1)) {
1721 /* Send management frames and broadcast/multicast data using 1704 /* Send management frames and broadcast/multicast data using
1722 * lowest rate. */ 1705 * lowest rate. */
@@ -1724,22 +1707,13 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
1724 return; 1707 return;
1725 } 1708 }
1726 1709
1727 if (!sta || !sta->rate_ctrl_priv) 1710 if (!sta || !lq_sta)
1728 return; 1711 return;
1729 1712
1730 if (!priv->lq_mngr.lq_ready) { 1713 lq_sta->supp_rates = sta->supp_rates[lq_sta->band];
1731 IWL_DEBUG_RATE("still rate scaling not ready\n"); 1714
1732 return; 1715 tid = rs_tl_add_packet(lq_sta, hdr);
1733 }
1734 lq_sta = (struct iwl4965_lq_sta *)sta->rate_ctrl_priv;
1735 1716
1736#ifdef CONFIG_IWL4965_HT
1737 qc = ieee80211_get_qos_ctrl(hdr);
1738 if (qc) {
1739 tid = (u8)(le16_to_cpu(*qc) & 0xf);
1740 rs_tl_add_packet(lq_sta, tid);
1741 }
1742#endif
1743 /* 1717 /*
1744 * Select rate-scale / modulation-mode table to work with in 1718 * Select rate-scale / modulation-mode table to work with in
1745 * the rest of this function: "search" if searching for better 1719 * the rest of this function: "search" if searching for better
@@ -1754,14 +1728,13 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
1754 is_green = lq_sta->is_green; 1728 is_green = lq_sta->is_green;
1755 1729
1756 /* current tx rate */ 1730 /* current tx rate */
1757 index = sta->last_txrate_idx; 1731 index = lq_sta->last_txrate_idx;
1758 1732
1759 IWL_DEBUG_RATE("Rate scale index %d for type %d\n", index, 1733 IWL_DEBUG_RATE("Rate scale index %d for type %d\n", index,
1760 tbl->lq_type); 1734 tbl->lq_type);
1761 1735
1762 /* rates available for this association, and for modulation mode */ 1736 /* rates available for this association, and for modulation mode */
1763 rs_get_supported_rates(lq_sta, hdr, tbl->lq_type, 1737 rate_mask = rs_get_supported_rates(lq_sta, hdr, tbl->lq_type);
1764 &rate_mask);
1765 1738
1766 IWL_DEBUG_RATE("mask 0x%04X \n", rate_mask); 1739 IWL_DEBUG_RATE("mask 0x%04X \n", rate_mask);
1767 1740
@@ -1781,27 +1754,16 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
1781 if (!rate_scale_index_msk) 1754 if (!rate_scale_index_msk)
1782 rate_scale_index_msk = rate_mask; 1755 rate_scale_index_msk = rate_mask;
1783 1756
1784 /* If current rate is no longer supported on current association, 1757 if (!((1 << index) & rate_scale_index_msk)) {
1785 * or user changed preferences for rates, find a new supported rate. */ 1758 IWL_ERROR("Current Rate is not valid\n");
1786 if (index < 0 || !((1 << index) & rate_scale_index_msk)) { 1759 return;
1787 index = IWL_INVALID_VALUE;
1788 update_lq = 1;
1789
1790 /* get the highest available rate */
1791 for (i = 0; i <= IWL_RATE_COUNT; i++) {
1792 if ((1 << i) & rate_scale_index_msk)
1793 index = i;
1794 }
1795
1796 if (index == IWL_INVALID_VALUE) {
1797 IWL_WARNING("Can not find a suitable rate\n");
1798 return;
1799 }
1800 } 1760 }
1801 1761
1802 /* Get expected throughput table and history window for current rate */ 1762 /* Get expected throughput table and history window for current rate */
1803 if (!tbl->expected_tpt) 1763 if (!tbl->expected_tpt) {
1804 rs_get_expected_tpt_table(lq_sta, tbl); 1764 IWL_ERROR("tbl->expected_tpt is NULL\n");
1765 return;
1766 }
1805 1767
1806 window = &(tbl->win[index]); 1768 window = &(tbl->win[index]);
1807 1769
@@ -1813,10 +1775,9 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
1813 * in current association (use new rate found above). 1775 * in current association (use new rate found above).
1814 */ 1776 */
1815 fail_count = window->counter - window->success_counter; 1777 fail_count = window->counter - window->success_counter;
1816 if (((fail_count < IWL_RATE_MIN_FAILURE_TH) && 1778 if ((fail_count < IWL_RATE_MIN_FAILURE_TH) &&
1817 (window->success_counter < IWL_RATE_MIN_SUCCESS_TH)) 1779 (window->success_counter < IWL_RATE_MIN_SUCCESS_TH)) {
1818 || (tbl->expected_tpt == NULL)) { 1780 IWL_DEBUG_RATE("LQ: still below TH. succ=%d total=%d "
1819 IWL_DEBUG_RATE("LQ: still below TH succ %d total %d "
1820 "for index %d\n", 1781 "for index %d\n",
1821 window->success_counter, window->counter, index); 1782 window->success_counter, window->counter, index);
1822 1783
@@ -1827,44 +1788,45 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
1827 * or search for a new one? */ 1788 * or search for a new one? */
1828 rs_stay_in_table(lq_sta); 1789 rs_stay_in_table(lq_sta);
1829 1790
1830 /* Set up new rate table in uCode, if needed */
1831 if (update_lq) {
1832 rs_mcs_from_tbl(&mcs_rate, tbl, index, is_green);
1833 rs_fill_link_cmd(lq_sta, &mcs_rate, &lq_sta->lq);
1834 iwl_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC);
1835 }
1836 goto out; 1791 goto out;
1792 }
1837 1793
1838 /* Else we have enough samples; calculate estimate of 1794 /* Else we have enough samples; calculate estimate of
1839 * actual average throughput */ 1795 * actual average throughput */
1840 } else 1796
1841 window->average_tpt = ((window->success_ratio * 1797 BUG_ON(window->average_tpt != ((window->success_ratio *
1842 tbl->expected_tpt[index] + 64) / 128); 1798 tbl->expected_tpt[index] + 64) / 128));
1843 1799
1844 /* If we are searching for better modulation mode, check success. */ 1800 /* If we are searching for better modulation mode, check success. */
1845 if (lq_sta->search_better_tbl) { 1801 if (lq_sta->search_better_tbl) {
1846 int success_limit = IWL_RATE_SCALE_SWITCH;
1847 1802
1848 /* If good success, continue using the "search" mode; 1803 /* If good success, continue using the "search" mode;
1849 * no need to send new link quality command, since we're 1804 * no need to send new link quality command, since we're
1850 * continuing to use the setup that we've been trying. */ 1805 * continuing to use the setup that we've been trying. */
1851 if ((window->success_ratio > success_limit) || 1806 if (window->average_tpt > lq_sta->last_tpt) {
1852 (window->average_tpt > lq_sta->last_tpt)) { 1807
1853 if (!is_legacy(tbl->lq_type)) { 1808 IWL_DEBUG_RATE("LQ: SWITCHING TO NEW TABLE "
1854 IWL_DEBUG_HT("LQ: we are switching to HT" 1809 "suc=%d cur-tpt=%d old-tpt=%d\n",
1855 " rate suc %d current tpt %d" 1810 window->success_ratio,
1856 " old tpt %d\n", 1811 window->average_tpt,
1857 window->success_ratio, 1812 lq_sta->last_tpt);
1858 window->average_tpt, 1813
1859 lq_sta->last_tpt); 1814 if (!is_legacy(tbl->lq_type))
1860 lq_sta->enable_counter = 1; 1815 lq_sta->enable_counter = 1;
1861 } 1816
1862 /* Swap tables; "search" becomes "active" */ 1817 /* Swap tables; "search" becomes "active" */
1863 lq_sta->active_tbl = active_tbl; 1818 lq_sta->active_tbl = active_tbl;
1864 current_tpt = window->average_tpt; 1819 current_tpt = window->average_tpt;
1865 1820
1866 /* Else poor success; go back to mode in "active" table */ 1821 /* Else poor success; go back to mode in "active" table */
1867 } else { 1822 } else {
1823
1824 IWL_DEBUG_RATE("LQ: GOING BACK TO THE OLD TABLE "
1825 "suc=%d cur-tpt=%d old-tpt=%d\n",
1826 window->success_ratio,
1827 window->average_tpt,
1828 lq_sta->last_tpt);
1829
1868 /* Nullify "search" table */ 1830 /* Nullify "search" table */
1869 tbl->lq_type = LQ_NONE; 1831 tbl->lq_type = LQ_NONE;
1870 1832
@@ -1873,13 +1835,11 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
1873 tbl = &(lq_sta->lq_info[active_tbl]); 1835 tbl = &(lq_sta->lq_info[active_tbl]);
1874 1836
1875 /* Revert to "active" rate and throughput info */ 1837 /* Revert to "active" rate and throughput info */
1876 index = iwl4965_hwrate_to_plcp_idx( 1838 index = iwl_hwrate_to_plcp_idx(tbl->current_rate);
1877 tbl->current_rate.rate_n_flags);
1878 current_tpt = lq_sta->last_tpt; 1839 current_tpt = lq_sta->last_tpt;
1879 1840
1880 /* Need to set up a new rate table in uCode */ 1841 /* Need to set up a new rate table in uCode */
1881 update_lq = 1; 1842 update_lq = 1;
1882 IWL_DEBUG_HT("XXY GO BACK TO OLD TABLE\n");
1883 } 1843 }
1884 1844
1885 /* Either way, we've made a decision; modulation mode 1845 /* Either way, we've made a decision; modulation mode
@@ -1891,11 +1851,13 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
1891 1851
1892 /* (Else) not in search of better modulation mode, try for better 1852 /* (Else) not in search of better modulation mode, try for better
1893 * starting rate, while staying in this mode. */ 1853 * starting rate, while staying in this mode. */
1894 high_low = rs_get_adjacent_rate(index, rate_scale_index_msk, 1854 high_low = rs_get_adjacent_rate(priv, index, rate_scale_index_msk,
1895 tbl->lq_type); 1855 tbl->lq_type);
1896 low = high_low & 0xff; 1856 low = high_low & 0xff;
1897 high = (high_low >> 8) & 0xff; 1857 high = (high_low >> 8) & 0xff;
1898 1858
1859 sr = window->success_ratio;
1860
1899 /* Collect measured throughputs for current and adjacent rates */ 1861 /* Collect measured throughputs for current and adjacent rates */
1900 current_tpt = window->average_tpt; 1862 current_tpt = window->average_tpt;
1901 if (low != IWL_RATE_INVALID) 1863 if (low != IWL_RATE_INVALID)
@@ -1903,19 +1865,22 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
1903 if (high != IWL_RATE_INVALID) 1865 if (high != IWL_RATE_INVALID)
1904 high_tpt = tbl->win[high].average_tpt; 1866 high_tpt = tbl->win[high].average_tpt;
1905 1867
1906 /* Assume rate increase */ 1868 scale_action = 0;
1907 scale_action = 1;
1908 1869
1909 /* Too many failures, decrease rate */ 1870 /* Too many failures, decrease rate */
1910 if ((window->success_ratio <= IWL_RATE_DECREASE_TH) || 1871 if ((sr <= IWL_RATE_DECREASE_TH) || (current_tpt == 0)) {
1911 (current_tpt == 0)) {
1912 IWL_DEBUG_RATE("decrease rate because of low success_ratio\n"); 1872 IWL_DEBUG_RATE("decrease rate because of low success_ratio\n");
1913 scale_action = -1; 1873 scale_action = -1;
1914 1874
1915 /* No throughput measured yet for adjacent rates; try increase. */ 1875 /* No throughput measured yet for adjacent rates; try increase. */
1916 } else if ((low_tpt == IWL_INVALID_VALUE) && 1876 } else if ((low_tpt == IWL_INVALID_VALUE) &&
1917 (high_tpt == IWL_INVALID_VALUE)) 1877 (high_tpt == IWL_INVALID_VALUE)) {
1918 scale_action = 1; 1878
1879 if (high != IWL_RATE_INVALID && sr >= IWL_RATE_INCREASE_TH)
1880 scale_action = 1;
1881 else if (low != IWL_RATE_INVALID)
1882 scale_action = -1;
1883 }
1919 1884
1920 /* Both adjacent throughputs are measured, but neither one has better 1885 /* Both adjacent throughputs are measured, but neither one has better
1921 * throughput; we're using the best rate, don't change it! */ 1886 * throughput; we're using the best rate, don't change it! */
@@ -1931,9 +1896,10 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
1931 /* Higher adjacent rate's throughput is measured */ 1896 /* Higher adjacent rate's throughput is measured */
1932 if (high_tpt != IWL_INVALID_VALUE) { 1897 if (high_tpt != IWL_INVALID_VALUE) {
1933 /* Higher rate has better throughput */ 1898 /* Higher rate has better throughput */
1934 if (high_tpt > current_tpt) 1899 if (high_tpt > current_tpt &&
1900 sr >= IWL_RATE_INCREASE_TH) {
1935 scale_action = 1; 1901 scale_action = 1;
1936 else { 1902 } else {
1937 IWL_DEBUG_RATE 1903 IWL_DEBUG_RATE
1938 ("decrease rate because of high tpt\n"); 1904 ("decrease rate because of high tpt\n");
1939 scale_action = -1; 1905 scale_action = -1;
@@ -1946,23 +1912,17 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
1946 IWL_DEBUG_RATE 1912 IWL_DEBUG_RATE
1947 ("decrease rate because of low tpt\n"); 1913 ("decrease rate because of low tpt\n");
1948 scale_action = -1; 1914 scale_action = -1;
1949 } else 1915 } else if (sr >= IWL_RATE_INCREASE_TH) {
1950 scale_action = 1; 1916 scale_action = 1;
1917 }
1951 } 1918 }
1952 } 1919 }
1953 1920
1954 /* Sanity check; asked for decrease, but success rate or throughput 1921 /* Sanity check; asked for decrease, but success rate or throughput
1955 * has been good at old rate. Don't change it. */ 1922 * has been good at old rate. Don't change it. */
1956 if (scale_action == -1) { 1923 if ((scale_action == -1) && (low != IWL_RATE_INVALID) &&
1957 if ((low != IWL_RATE_INVALID) && 1924 ((sr > IWL_RATE_HIGH_TH) ||
1958 ((window->success_ratio > IWL_RATE_HIGH_TH) ||
1959 (current_tpt > (100 * tbl->expected_tpt[low])))) 1925 (current_tpt > (100 * tbl->expected_tpt[low]))))
1960 scale_action = 0;
1961
1962 /* Sanity check; asked for increase, but success rate has not been great
1963 * even at old rate, higher rate will be worse. Don't change it. */
1964 } else if ((scale_action == 1) &&
1965 (window->success_ratio < IWL_RATE_INCREASE_TH))
1966 scale_action = 0; 1926 scale_action = 0;
1967 1927
1968 switch (scale_action) { 1928 switch (scale_action) {
@@ -1987,15 +1947,15 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
1987 break; 1947 break;
1988 } 1948 }
1989 1949
1990 IWL_DEBUG_HT("choose rate scale index %d action %d low %d " 1950 IWL_DEBUG_RATE("choose rate scale index %d action %d low %d "
1991 "high %d type %d\n", 1951 "high %d type %d\n",
1992 index, scale_action, low, high, tbl->lq_type); 1952 index, scale_action, low, high, tbl->lq_type);
1993 1953
1994 lq_update: 1954lq_update:
1995 /* Replace uCode's rate table for the destination station. */ 1955 /* Replace uCode's rate table for the destination station. */
1996 if (update_lq) { 1956 if (update_lq) {
1997 rs_mcs_from_tbl(&mcs_rate, tbl, index, is_green); 1957 rate = rate_n_flags_from_tbl(tbl, index, is_green);
1998 rs_fill_link_cmd(lq_sta, &mcs_rate, &lq_sta->lq); 1958 rs_fill_link_cmd(priv, lq_sta, rate);
1999 iwl_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC); 1959 iwl_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC);
2000 } 1960 }
2001 1961
@@ -2029,13 +1989,11 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
2029 rs_rate_scale_clear_window(&(tbl->win[i])); 1989 rs_rate_scale_clear_window(&(tbl->win[i]));
2030 1990
2031 /* Use new "search" start rate */ 1991 /* Use new "search" start rate */
2032 index = iwl4965_hwrate_to_plcp_idx( 1992 index = iwl_hwrate_to_plcp_idx(tbl->current_rate);
2033 tbl->current_rate.rate_n_flags);
2034 1993
2035 IWL_DEBUG_HT("Switch current mcs: %X index: %d\n", 1994 IWL_DEBUG_RATE("Switch current mcs: %X index: %d\n",
2036 tbl->current_rate.rate_n_flags, index); 1995 tbl->current_rate, index);
2037 rs_fill_link_cmd(lq_sta, &tbl->current_rate, 1996 rs_fill_link_cmd(priv, lq_sta, tbl->current_rate);
2038 &lq_sta->lq);
2039 iwl_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC); 1997 iwl_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC);
2040 } 1998 }
2041 1999
@@ -2046,13 +2004,11 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
2046 * before next round of mode comparisons. */ 2004 * before next round of mode comparisons. */
2047 tbl1 = &(lq_sta->lq_info[lq_sta->active_tbl]); 2005 tbl1 = &(lq_sta->lq_info[lq_sta->active_tbl]);
2048 if (is_legacy(tbl1->lq_type) && 2006 if (is_legacy(tbl1->lq_type) &&
2049#ifdef CONFIG_IWL4965_HT
2050 (!(conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE)) && 2007 (!(conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE)) &&
2051#endif
2052 (lq_sta->action_counter >= 1)) { 2008 (lq_sta->action_counter >= 1)) {
2053 lq_sta->action_counter = 0; 2009 lq_sta->action_counter = 0;
2054 IWL_DEBUG_HT("LQ: STAY in legacy table\n"); 2010 IWL_DEBUG_RATE("LQ: STAY in legacy table\n");
2055 rs_set_stay_in_table(1, lq_sta); 2011 rs_set_stay_in_table(priv, 1, lq_sta);
2056 } 2012 }
2057 2013
2058 /* If we're in an HT mode, and all 3 mode switch actions 2014 /* If we're in an HT mode, and all 3 mode switch actions
@@ -2060,16 +2016,14 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
2060 * mode for a while before next round of mode comparisons. */ 2016 * mode for a while before next round of mode comparisons. */
2061 if (lq_sta->enable_counter && 2017 if (lq_sta->enable_counter &&
2062 (lq_sta->action_counter >= IWL_ACTION_LIMIT)) { 2018 (lq_sta->action_counter >= IWL_ACTION_LIMIT)) {
2063#ifdef CONFIG_IWL4965_HT
2064 if ((lq_sta->last_tpt > IWL_AGG_TPT_THREHOLD) && 2019 if ((lq_sta->last_tpt > IWL_AGG_TPT_THREHOLD) &&
2065 (lq_sta->tx_agg_tid_en & (1 << tid)) && 2020 (lq_sta->tx_agg_tid_en & (1 << tid)) &&
2066 (tid != MAX_TID_COUNT)) { 2021 (tid != MAX_TID_COUNT)) {
2067 IWL_DEBUG_HT("try to aggregate tid %d\n", tid); 2022 IWL_DEBUG_RATE("try to aggregate tid %d\n", tid);
2068 rs_tl_turn_on_agg(priv, tid, lq_sta, sta); 2023 rs_tl_turn_on_agg(priv, tid, lq_sta, sta);
2069 } 2024 }
2070#endif /*CONFIG_IWL4965_HT */
2071 lq_sta->action_counter = 0; 2025 lq_sta->action_counter = 0;
2072 rs_set_stay_in_table(0, lq_sta); 2026 rs_set_stay_in_table(priv, 0, lq_sta);
2073 } 2027 }
2074 2028
2075 /* 2029 /*
@@ -2085,17 +2039,9 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
2085 } 2039 }
2086 2040
2087out: 2041out:
2088 rs_mcs_from_tbl(&tbl->current_rate, tbl, index, is_green); 2042 tbl->current_rate = rate_n_flags_from_tbl(tbl, index, is_green);
2089 i = index; 2043 i = index;
2090 sta->last_txrate_idx = i; 2044 lq_sta->last_txrate_idx = i;
2091
2092 /* sta->txrate_idx is an index to A mode rates which start
2093 * at IWL_FIRST_OFDM_RATE
2094 */
2095 if (lq_sta->band == IEEE80211_BAND_5GHZ)
2096 sta->txrate_idx = i - IWL_FIRST_OFDM_RATE;
2097 else
2098 sta->txrate_idx = i;
2099 2045
2100 return; 2046 return;
2101} 2047}
@@ -2103,26 +2049,28 @@ out:
2103 2049
2104static void rs_initialize_lq(struct iwl_priv *priv, 2050static void rs_initialize_lq(struct iwl_priv *priv,
2105 struct ieee80211_conf *conf, 2051 struct ieee80211_conf *conf,
2106 struct sta_info *sta) 2052 struct ieee80211_sta *sta,
2053 struct iwl_lq_sta *lq_sta)
2107{ 2054{
2108 int i; 2055 struct iwl_scale_tbl_info *tbl;
2109 struct iwl4965_lq_sta *lq_sta;
2110 struct iwl4965_scale_tbl_info *tbl;
2111 u8 active_tbl = 0;
2112 int rate_idx; 2056 int rate_idx;
2057 int i;
2058 u32 rate;
2113 u8 use_green = rs_use_green(priv, conf); 2059 u8 use_green = rs_use_green(priv, conf);
2114 struct iwl4965_rate mcs_rate; 2060 u8 active_tbl = 0;
2061 u8 valid_tx_ant;
2115 2062
2116 if (!sta || !sta->rate_ctrl_priv) 2063 if (!sta || !lq_sta)
2117 goto out; 2064 goto out;
2118 2065
2119 lq_sta = (struct iwl4965_lq_sta *)sta->rate_ctrl_priv; 2066 i = lq_sta->last_txrate_idx;
2120 i = sta->last_txrate_idx;
2121 2067
2122 if ((lq_sta->lq.sta_id == 0xff) && 2068 if ((lq_sta->lq.sta_id == 0xff) &&
2123 (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)) 2069 (priv->iw_mode == NL80211_IFTYPE_ADHOC))
2124 goto out; 2070 goto out;
2125 2071
2072 valid_tx_ant = priv->hw_params.valid_tx_ant;
2073
2126 if (!lq_sta->search_better_tbl) 2074 if (!lq_sta->search_better_tbl)
2127 active_tbl = lq_sta->active_tbl; 2075 active_tbl = lq_sta->active_tbl;
2128 else 2076 else
@@ -2133,100 +2081,94 @@ static void rs_initialize_lq(struct iwl_priv *priv,
2133 if ((i < 0) || (i >= IWL_RATE_COUNT)) 2081 if ((i < 0) || (i >= IWL_RATE_COUNT))
2134 i = 0; 2082 i = 0;
2135 2083
2136 mcs_rate.rate_n_flags = iwl4965_rates[i].plcp ; 2084 /* FIXME:RS: This is also wrong in 4965 */
2137 mcs_rate.rate_n_flags |= RATE_MCS_ANT_B_MSK; 2085 rate = iwl_rates[i].plcp;
2138 mcs_rate.rate_n_flags &= ~RATE_MCS_ANT_A_MSK; 2086 rate |= RATE_MCS_ANT_B_MSK;
2087 rate &= ~RATE_MCS_ANT_A_MSK;
2139 2088
2140 if (i >= IWL_FIRST_CCK_RATE && i <= IWL_LAST_CCK_RATE) 2089 if (i >= IWL_FIRST_CCK_RATE && i <= IWL_LAST_CCK_RATE)
2141 mcs_rate.rate_n_flags |= RATE_MCS_CCK_MSK; 2090 rate |= RATE_MCS_CCK_MSK;
2142 2091
2143 tbl->antenna_type = ANT_AUX; 2092 tbl->ant_type = ANT_B;
2144 rs_get_tbl_info_from_mcs(&mcs_rate, priv->band, tbl, &rate_idx); 2093 rs_get_tbl_info_from_mcs(rate, priv->band, tbl, &rate_idx);
2145 if (!rs_is_ant_connected(priv->valid_antenna, tbl->antenna_type)) 2094 if (!rs_is_valid_ant(valid_tx_ant, tbl->ant_type))
2146 rs_toggle_antenna(&mcs_rate, tbl); 2095 rs_toggle_antenna(valid_tx_ant, &rate, tbl);
2147 2096
2148 rs_mcs_from_tbl(&mcs_rate, tbl, rate_idx, use_green); 2097 rate = rate_n_flags_from_tbl(tbl, rate_idx, use_green);
2149 tbl->current_rate.rate_n_flags = mcs_rate.rate_n_flags; 2098 tbl->current_rate = rate;
2150 rs_get_expected_tpt_table(lq_sta, tbl); 2099 rs_set_expected_tpt_table(lq_sta, tbl);
2151 rs_fill_link_cmd(lq_sta, &mcs_rate, &lq_sta->lq); 2100 rs_fill_link_cmd(NULL, lq_sta, rate);
2152 iwl_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC); 2101 iwl_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC);
2153 out: 2102 out:
2154 return; 2103 return;
2155} 2104}
2156 2105
2157static void rs_get_rate(void *priv_rate, struct net_device *dev, 2106static void rs_get_rate(void *priv_r, struct ieee80211_supported_band *sband,
2158 struct ieee80211_supported_band *sband, 2107 struct ieee80211_sta *sta, void *priv_sta,
2159 struct sk_buff *skb, 2108 struct sk_buff *skb, struct rate_selection *sel)
2160 struct rate_selection *sel)
2161{ 2109{
2162 2110
2163 int i; 2111 int i;
2164 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 2112 struct iwl_priv *priv = (struct iwl_priv *)priv_r;
2165 struct ieee80211_conf *conf = &local->hw.conf; 2113 struct ieee80211_conf *conf = &priv->hw->conf;
2166 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 2114 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2167 struct sta_info *sta; 2115 __le16 fc;
2168 u16 fc; 2116 struct iwl_lq_sta *lq_sta;
2169 struct iwl_priv *priv = (struct iwl_priv *)priv_rate;
2170 struct iwl4965_lq_sta *lq_sta;
2171 2117
2172 IWL_DEBUG_RATE_LIMIT("rate scale calculate new rate for skb\n"); 2118 IWL_DEBUG_RATE_LIMIT("rate scale calculate new rate for skb\n");
2173 2119
2174 rcu_read_lock();
2175
2176 sta = sta_info_get(local, hdr->addr1);
2177
2178 /* Send management frames and broadcast/multicast data using lowest 2120 /* Send management frames and broadcast/multicast data using lowest
2179 * rate. */ 2121 * rate. */
2180 fc = le16_to_cpu(hdr->frame_control); 2122 fc = hdr->frame_control;
2181 if (!ieee80211_is_data(fc) || is_multicast_ether_addr(hdr->addr1) || 2123 if (!ieee80211_is_data(fc) || is_multicast_ether_addr(hdr->addr1) ||
2182 !sta || !sta->rate_ctrl_priv) { 2124 !sta || !priv_sta) {
2183 sel->rate = rate_lowest(local, sband, sta); 2125 sel->rate_idx = rate_lowest_index(sband, sta);
2184 goto out; 2126 return;
2185 } 2127 }
2186 2128
2187 lq_sta = (struct iwl4965_lq_sta *)sta->rate_ctrl_priv; 2129 lq_sta = (struct iwl_lq_sta *)priv_sta;
2188 i = sta->last_txrate_idx; 2130 i = lq_sta->last_txrate_idx;
2189 2131
2190 if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) && 2132 if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) &&
2191 !lq_sta->ibss_sta_added) { 2133 !lq_sta->ibss_sta_added) {
2192 u8 sta_id = iwl4965_hw_find_station(priv, hdr->addr1); 2134 u8 sta_id = iwl_find_station(priv, hdr->addr1);
2193 DECLARE_MAC_BUF(mac); 2135 DECLARE_MAC_BUF(mac);
2194 2136
2195 if (sta_id == IWL_INVALID_STATION) { 2137 if (sta_id == IWL_INVALID_STATION) {
2196 IWL_DEBUG_RATE("LQ: ADD station %s\n", 2138 IWL_DEBUG_RATE("LQ: ADD station %s\n",
2197 print_mac(mac, hdr->addr1)); 2139 print_mac(mac, hdr->addr1));
2198 sta_id = iwl4965_add_station_flags(priv, hdr->addr1, 2140 sta_id = iwl_add_station_flags(priv, hdr->addr1,
2199 0, CMD_ASYNC, NULL); 2141 0, CMD_ASYNC, NULL);
2200 } 2142 }
2201 if ((sta_id != IWL_INVALID_STATION)) { 2143 if ((sta_id != IWL_INVALID_STATION)) {
2202 lq_sta->lq.sta_id = sta_id; 2144 lq_sta->lq.sta_id = sta_id;
2203 lq_sta->lq.rs_table[0].rate_n_flags = 0; 2145 lq_sta->lq.rs_table[0].rate_n_flags = 0;
2204 lq_sta->ibss_sta_added = 1; 2146 lq_sta->ibss_sta_added = 1;
2205 rs_initialize_lq(priv, conf, sta); 2147 rs_initialize_lq(priv, conf, sta, lq_sta);
2206 } 2148 }
2207 if (!lq_sta->ibss_sta_added)
2208 goto done;
2209 } 2149 }
2210 2150
2211done:
2212 if ((i < 0) || (i > IWL_RATE_COUNT)) { 2151 if ((i < 0) || (i > IWL_RATE_COUNT)) {
2213 sel->rate = rate_lowest(local, sband, sta); 2152 sel->rate_idx = rate_lowest_index(sband, sta);
2214 goto out; 2153 return;
2215 } 2154 }
2216 2155
2217 sel->rate = &priv->ieee_rates[i]; 2156 if (sband->band == IEEE80211_BAND_5GHZ)
2218out: 2157 i -= IWL_FIRST_OFDM_RATE;
2219 rcu_read_unlock(); 2158 sel->rate_idx = i;
2220} 2159}
2221 2160
2222static void *rs_alloc_sta(void *priv, gfp_t gfp) 2161static void *rs_alloc_sta(void *priv_rate, struct ieee80211_sta *sta,
2162 gfp_t gfp)
2223{ 2163{
2224 struct iwl4965_lq_sta *lq_sta; 2164 struct iwl_lq_sta *lq_sta;
2165 struct iwl_priv *priv;
2225 int i, j; 2166 int i, j;
2226 2167
2168 priv = (struct iwl_priv *)priv_rate;
2227 IWL_DEBUG_RATE("create station rate scale window\n"); 2169 IWL_DEBUG_RATE("create station rate scale window\n");
2228 2170
2229 lq_sta = kzalloc(sizeof(struct iwl4965_lq_sta), gfp); 2171 lq_sta = kzalloc(sizeof(struct iwl_lq_sta), gfp);
2230 2172
2231 if (lq_sta == NULL) 2173 if (lq_sta == NULL)
2232 return NULL; 2174 return NULL;
@@ -2235,49 +2177,44 @@ static void *rs_alloc_sta(void *priv, gfp_t gfp)
2235 2177
2236 for (j = 0; j < LQ_SIZE; j++) 2178 for (j = 0; j < LQ_SIZE; j++)
2237 for (i = 0; i < IWL_RATE_COUNT; i++) 2179 for (i = 0; i < IWL_RATE_COUNT; i++)
2238 rs_rate_scale_clear_window(&(lq_sta->lq_info[j].win[i])); 2180 rs_rate_scale_clear_window(&lq_sta->lq_info[j].win[i]);
2239 2181
2240 return lq_sta; 2182 return lq_sta;
2241} 2183}
2242 2184
2243static void rs_rate_init(void *priv_rate, void *priv_sta, 2185static void rs_rate_init(void *priv_r, struct ieee80211_supported_band *sband,
2244 struct ieee80211_local *local, 2186 struct ieee80211_sta *sta, void *priv_sta)
2245 struct sta_info *sta)
2246{ 2187{
2247 int i, j; 2188 int i, j;
2248 struct ieee80211_conf *conf = &local->hw.conf; 2189 struct iwl_priv *priv = (struct iwl_priv *)priv_r;
2249 struct ieee80211_supported_band *sband; 2190 struct ieee80211_conf *conf = &priv->hw->conf;
2250 struct iwl_priv *priv = (struct iwl_priv *)priv_rate; 2191 struct iwl_lq_sta *lq_sta = priv_sta;
2251 struct iwl4965_lq_sta *lq_sta = priv_sta;
2252
2253 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
2254 2192
2255 lq_sta->flush_timer = 0; 2193 lq_sta->flush_timer = 0;
2256 lq_sta->supp_rates = sta->supp_rates[sband->band]; 2194 lq_sta->supp_rates = sta->supp_rates[sband->band];
2257 sta->txrate_idx = 3;
2258 for (j = 0; j < LQ_SIZE; j++) 2195 for (j = 0; j < LQ_SIZE; j++)
2259 for (i = 0; i < IWL_RATE_COUNT; i++) 2196 for (i = 0; i < IWL_RATE_COUNT; i++)
2260 rs_rate_scale_clear_window(&(lq_sta->lq_info[j].win[i])); 2197 rs_rate_scale_clear_window(&lq_sta->lq_info[j].win[i]);
2261 2198
2262 IWL_DEBUG_RATE("rate scale global init\n"); 2199 IWL_DEBUG_RATE("LQ: *** rate scale station global init ***\n");
2263 /* TODO: what is a good starting rate for STA? About middle? Maybe not 2200 /* TODO: what is a good starting rate for STA? About middle? Maybe not
2264 * the lowest or the highest rate.. Could consider using RSSI from 2201 * the lowest or the highest rate.. Could consider using RSSI from
2265 * previous packets? Need to have IEEE 802.1X auth succeed immediately 2202 * previous packets? Need to have IEEE 802.1X auth succeed immediately
2266 * after assoc.. */ 2203 * after assoc.. */
2267 2204
2268 lq_sta->ibss_sta_added = 0; 2205 lq_sta->ibss_sta_added = 0;
2269 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { 2206 if (priv->iw_mode == NL80211_IFTYPE_AP) {
2270 u8 sta_id = iwl4965_hw_find_station(priv, sta->addr); 2207 u8 sta_id = iwl_find_station(priv, sta->addr);
2271 DECLARE_MAC_BUF(mac); 2208 DECLARE_MAC_BUF(mac);
2272 2209
2273 /* for IBSS the call are from tasklet */ 2210 /* for IBSS the call are from tasklet */
2274 IWL_DEBUG_HT("LQ: ADD station %s\n", 2211 IWL_DEBUG_RATE("LQ: ADD station %s\n",
2275 print_mac(mac, sta->addr)); 2212 print_mac(mac, sta->addr));
2276 2213
2277 if (sta_id == IWL_INVALID_STATION) { 2214 if (sta_id == IWL_INVALID_STATION) {
2278 IWL_DEBUG_RATE("LQ: ADD station %s\n", 2215 IWL_DEBUG_RATE("LQ: ADD station %s\n",
2279 print_mac(mac, sta->addr)); 2216 print_mac(mac, sta->addr));
2280 sta_id = iwl4965_add_station_flags(priv, sta->addr, 2217 sta_id = iwl_add_station_flags(priv, sta->addr,
2281 0, CMD_ASYNC, NULL); 2218 0, CMD_ASYNC, NULL);
2282 } 2219 }
2283 if ((sta_id != IWL_INVALID_STATION)) { 2220 if ((sta_id != IWL_INVALID_STATION)) {
@@ -2289,103 +2226,104 @@ static void rs_rate_init(void *priv_rate, void *priv_sta,
2289 } 2226 }
2290 2227
2291 /* Find highest tx rate supported by hardware and destination station */ 2228 /* Find highest tx rate supported by hardware and destination station */
2229 lq_sta->last_txrate_idx = 3;
2292 for (i = 0; i < sband->n_bitrates; i++) 2230 for (i = 0; i < sband->n_bitrates; i++)
2293 if (sta->supp_rates[sband->band] & BIT(i)) 2231 if (sta->supp_rates[sband->band] & BIT(i))
2294 sta->txrate_idx = i; 2232 lq_sta->last_txrate_idx = i;
2295 2233
2296 sta->last_txrate_idx = sta->txrate_idx; 2234 /* For MODE_IEEE80211A, skip over cck rates in global rate table */
2297 /* WTF is with this bogus comment? A doesn't have cck rates */ 2235 if (sband->band == IEEE80211_BAND_5GHZ)
2298 /* For MODE_IEEE80211A, cck rates are at end of rate table */ 2236 lq_sta->last_txrate_idx += IWL_FIRST_OFDM_RATE;
2299 if (local->hw.conf.channel->band == IEEE80211_BAND_5GHZ)
2300 sta->last_txrate_idx += IWL_FIRST_OFDM_RATE;
2301 2237
2302 lq_sta->is_dup = 0; 2238 lq_sta->is_dup = 0;
2303 lq_sta->valid_antenna = priv->valid_antenna;
2304 lq_sta->antenna = priv->antenna;
2305 lq_sta->is_green = rs_use_green(priv, conf); 2239 lq_sta->is_green = rs_use_green(priv, conf);
2306 lq_sta->active_rate = priv->active_rate; 2240 lq_sta->active_legacy_rate = priv->active_rate & ~(0x1000);
2307 lq_sta->active_rate &= ~(0x1000);
2308 lq_sta->active_rate_basic = priv->active_rate_basic; 2241 lq_sta->active_rate_basic = priv->active_rate_basic;
2309 lq_sta->band = priv->band; 2242 lq_sta->band = priv->band;
2310#ifdef CONFIG_IWL4965_HT
2311 /* 2243 /*
2312 * active_siso_rate mask includes 9 MBits (bit 5), and CCK (bits 0-3), 2244 * active_siso_rate mask includes 9 MBits (bit 5), and CCK (bits 0-3),
2313 * supp_rates[] does not; shift to convert format, force 9 MBits off. 2245 * supp_rates[] does not; shift to convert format, force 9 MBits off.
2314 */ 2246 */
2315 lq_sta->active_siso_rate = (priv->current_ht_config.supp_mcs_set[0] << 1); 2247 lq_sta->active_siso_rate = conf->ht_conf.supp_mcs_set[0] << 1;
2316 lq_sta->active_siso_rate |= 2248 lq_sta->active_siso_rate |= conf->ht_conf.supp_mcs_set[0] & 0x1;
2317 (priv->current_ht_config.supp_mcs_set[0] & 0x1);
2318 lq_sta->active_siso_rate &= ~((u16)0x2); 2249 lq_sta->active_siso_rate &= ~((u16)0x2);
2319 lq_sta->active_siso_rate = 2250 lq_sta->active_siso_rate <<= IWL_FIRST_OFDM_RATE;
2320 lq_sta->active_siso_rate << IWL_FIRST_OFDM_RATE;
2321 2251
2322 /* Same here */ 2252 /* Same here */
2323 lq_sta->active_mimo_rate = (priv->current_ht_config.supp_mcs_set[1] << 1); 2253 lq_sta->active_mimo2_rate = conf->ht_conf.supp_mcs_set[1] << 1;
2324 lq_sta->active_mimo_rate |= 2254 lq_sta->active_mimo2_rate |= conf->ht_conf.supp_mcs_set[1] & 0x1;
2325 (priv->current_ht_config.supp_mcs_set[1] & 0x1); 2255 lq_sta->active_mimo2_rate &= ~((u16)0x2);
2326 lq_sta->active_mimo_rate &= ~((u16)0x2); 2256 lq_sta->active_mimo2_rate <<= IWL_FIRST_OFDM_RATE;
2327 lq_sta->active_mimo_rate = 2257
2328 lq_sta->active_mimo_rate << IWL_FIRST_OFDM_RATE; 2258 lq_sta->active_mimo3_rate = conf->ht_conf.supp_mcs_set[2] << 1;
2329 IWL_DEBUG_HT("SISO RATE 0x%X MIMO RATE 0x%X\n", 2259 lq_sta->active_mimo3_rate |= conf->ht_conf.supp_mcs_set[2] & 0x1;
2260 lq_sta->active_mimo3_rate &= ~((u16)0x2);
2261 lq_sta->active_mimo3_rate <<= IWL_FIRST_OFDM_RATE;
2262
2263 IWL_DEBUG_RATE("SISO-RATE=%X MIMO2-RATE=%X MIMO3-RATE=%X\n",
2330 lq_sta->active_siso_rate, 2264 lq_sta->active_siso_rate,
2331 lq_sta->active_mimo_rate); 2265 lq_sta->active_mimo2_rate,
2266 lq_sta->active_mimo3_rate);
2267
2268 /* These values will be overriden later */
2269 lq_sta->lq.general_params.single_stream_ant_msk = ANT_A;
2270 lq_sta->lq.general_params.dual_stream_ant_msk = ANT_AB;
2271
2332 /* as default allow aggregation for all tids */ 2272 /* as default allow aggregation for all tids */
2333 lq_sta->tx_agg_tid_en = IWL_AGG_ALL_TID; 2273 lq_sta->tx_agg_tid_en = IWL_AGG_ALL_TID;
2334#endif /*CONFIG_IWL4965_HT*/
2335#ifdef CONFIG_MAC80211_DEBUGFS
2336 lq_sta->drv = priv; 2274 lq_sta->drv = priv;
2337#endif
2338 2275
2339 if (priv->assoc_station_added) 2276 rs_initialize_lq(priv, conf, sta, lq_sta);
2340 priv->lq_mngr.lq_ready = 1;
2341
2342 rs_initialize_lq(priv, conf, sta);
2343} 2277}
2344 2278
2345static void rs_fill_link_cmd(struct iwl4965_lq_sta *lq_sta, 2279static void rs_fill_link_cmd(const struct iwl_priv *priv,
2346 struct iwl4965_rate *tx_mcs, 2280 struct iwl_lq_sta *lq_sta, u32 new_rate)
2347 struct iwl_link_quality_cmd *lq_cmd)
2348{ 2281{
2282 struct iwl_scale_tbl_info tbl_type;
2349 int index = 0; 2283 int index = 0;
2350 int rate_idx; 2284 int rate_idx;
2351 int repeat_rate = 0; 2285 int repeat_rate = 0;
2352 u8 ant_toggle_count = 0; 2286 u8 ant_toggle_cnt = 0;
2353 u8 use_ht_possible = 1; 2287 u8 use_ht_possible = 1;
2354 struct iwl4965_rate new_rate; 2288 u8 valid_tx_ant = 0;
2355 struct iwl4965_scale_tbl_info tbl_type = { 0 }; 2289 struct iwl_link_quality_cmd *lq_cmd = &lq_sta->lq;
2356 2290
2357 /* Override starting rate (index 0) if needed for debug purposes */ 2291 /* Override starting rate (index 0) if needed for debug purposes */
2358 rs_dbgfs_set_mcs(lq_sta, tx_mcs, index); 2292 rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
2359 2293
2360 /* Interpret rate_n_flags */ 2294 /* Interpret new_rate (rate_n_flags) */
2361 rs_get_tbl_info_from_mcs(tx_mcs, lq_sta->band, 2295 memset(&tbl_type, 0, sizeof(tbl_type));
2296 rs_get_tbl_info_from_mcs(new_rate, lq_sta->band,
2362 &tbl_type, &rate_idx); 2297 &tbl_type, &rate_idx);
2363 2298
2364 /* How many times should we repeat the initial rate? */ 2299 /* How many times should we repeat the initial rate? */
2365 if (is_legacy(tbl_type.lq_type)) { 2300 if (is_legacy(tbl_type.lq_type)) {
2366 ant_toggle_count = 1; 2301 ant_toggle_cnt = 1;
2367 repeat_rate = IWL_NUMBER_TRY; 2302 repeat_rate = IWL_NUMBER_TRY;
2368 } else 2303 } else {
2369 repeat_rate = IWL_HT_NUMBER_TRY; 2304 repeat_rate = IWL_HT_NUMBER_TRY;
2305 }
2370 2306
2371 lq_cmd->general_params.mimo_delimiter = 2307 lq_cmd->general_params.mimo_delimiter =
2372 is_mimo(tbl_type.lq_type) ? 1 : 0; 2308 is_mimo(tbl_type.lq_type) ? 1 : 0;
2373 2309
2374 /* Fill 1st table entry (index 0) */ 2310 /* Fill 1st table entry (index 0) */
2375 lq_cmd->rs_table[index].rate_n_flags = 2311 lq_cmd->rs_table[index].rate_n_flags = cpu_to_le32(new_rate);
2376 cpu_to_le32(tx_mcs->rate_n_flags);
2377 new_rate.rate_n_flags = tx_mcs->rate_n_flags;
2378 2312
2379 if (is_mimo(tbl_type.lq_type) || (tbl_type.antenna_type == ANT_MAIN)) 2313 if (num_of_ant(tbl_type.ant_type) == 1) {
2380 lq_cmd->general_params.single_stream_ant_msk 2314 lq_cmd->general_params.single_stream_ant_msk =
2381 = LINK_QUAL_ANT_A_MSK; 2315 tbl_type.ant_type;
2382 else 2316 } else if (num_of_ant(tbl_type.ant_type) == 2) {
2383 lq_cmd->general_params.single_stream_ant_msk 2317 lq_cmd->general_params.dual_stream_ant_msk =
2384 = LINK_QUAL_ANT_B_MSK; 2318 tbl_type.ant_type;
2319 } /* otherwise we don't modify the existing value */
2385 2320
2386 index++; 2321 index++;
2387 repeat_rate--; 2322 repeat_rate--;
2388 2323
2324 if (priv)
2325 valid_tx_ant = priv->hw_params.valid_tx_ant;
2326
2389 /* Fill rest of rate table */ 2327 /* Fill rest of rate table */
2390 while (index < LINK_QUAL_MAX_RETRY_NUM) { 2328 while (index < LINK_QUAL_MAX_RETRY_NUM) {
2391 /* Repeat initial/next rate. 2329 /* Repeat initial/next rate.
@@ -2393,26 +2331,25 @@ static void rs_fill_link_cmd(struct iwl4965_lq_sta *lq_sta,
2393 * For HT IWL_HT_NUMBER_TRY == 3, this executes twice. */ 2331 * For HT IWL_HT_NUMBER_TRY == 3, this executes twice. */
2394 while (repeat_rate > 0 && (index < LINK_QUAL_MAX_RETRY_NUM)) { 2332 while (repeat_rate > 0 && (index < LINK_QUAL_MAX_RETRY_NUM)) {
2395 if (is_legacy(tbl_type.lq_type)) { 2333 if (is_legacy(tbl_type.lq_type)) {
2396 if (ant_toggle_count < 2334 if (ant_toggle_cnt < NUM_TRY_BEFORE_ANT_TOGGLE)
2397 NUM_TRY_BEFORE_ANTENNA_TOGGLE) 2335 ant_toggle_cnt++;
2398 ant_toggle_count++; 2336 else if (priv &&
2399 else { 2337 rs_toggle_antenna(valid_tx_ant,
2400 rs_toggle_antenna(&new_rate, &tbl_type); 2338 &new_rate, &tbl_type))
2401 ant_toggle_count = 1; 2339 ant_toggle_cnt = 1;
2402 } 2340}
2403 }
2404 2341
2405 /* Override next rate if needed for debug purposes */ 2342 /* Override next rate if needed for debug purposes */
2406 rs_dbgfs_set_mcs(lq_sta, &new_rate, index); 2343 rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
2407 2344
2408 /* Fill next table entry */ 2345 /* Fill next table entry */
2409 lq_cmd->rs_table[index].rate_n_flags = 2346 lq_cmd->rs_table[index].rate_n_flags =
2410 cpu_to_le32(new_rate.rate_n_flags); 2347 cpu_to_le32(new_rate);
2411 repeat_rate--; 2348 repeat_rate--;
2412 index++; 2349 index++;
2413 } 2350 }
2414 2351
2415 rs_get_tbl_info_from_mcs(&new_rate, lq_sta->band, &tbl_type, 2352 rs_get_tbl_info_from_mcs(new_rate, lq_sta->band, &tbl_type,
2416 &rate_idx); 2353 &rate_idx);
2417 2354
2418 /* Indicate to uCode which entries might be MIMO. 2355 /* Indicate to uCode which entries might be MIMO.
@@ -2422,20 +2359,22 @@ static void rs_fill_link_cmd(struct iwl4965_lq_sta *lq_sta,
2422 lq_cmd->general_params.mimo_delimiter = index; 2359 lq_cmd->general_params.mimo_delimiter = index;
2423 2360
2424 /* Get next rate */ 2361 /* Get next rate */
2425 rs_get_lower_rate(lq_sta, &tbl_type, rate_idx, 2362 new_rate = rs_get_lower_rate(lq_sta, &tbl_type, rate_idx,
2426 use_ht_possible, &new_rate); 2363 use_ht_possible);
2427 2364
2428 /* How many times should we repeat the next rate? */ 2365 /* How many times should we repeat the next rate? */
2429 if (is_legacy(tbl_type.lq_type)) { 2366 if (is_legacy(tbl_type.lq_type)) {
2430 if (ant_toggle_count < NUM_TRY_BEFORE_ANTENNA_TOGGLE) 2367 if (ant_toggle_cnt < NUM_TRY_BEFORE_ANT_TOGGLE)
2431 ant_toggle_count++; 2368 ant_toggle_cnt++;
2432 else { 2369 else if (priv &&
2433 rs_toggle_antenna(&new_rate, &tbl_type); 2370 rs_toggle_antenna(valid_tx_ant,
2434 ant_toggle_count = 1; 2371 &new_rate, &tbl_type))
2435 } 2372 ant_toggle_cnt = 1;
2373
2436 repeat_rate = IWL_NUMBER_TRY; 2374 repeat_rate = IWL_NUMBER_TRY;
2437 } else 2375 } else {
2438 repeat_rate = IWL_HT_NUMBER_TRY; 2376 repeat_rate = IWL_HT_NUMBER_TRY;
2377 }
2439 2378
2440 /* Don't allow HT rates after next pass. 2379 /* Don't allow HT rates after next pass.
2441 * rs_get_lower_rate() will change type to LQ_A or LQ_G. */ 2380 * rs_get_lower_rate() will change type to LQ_A or LQ_G. */
@@ -2445,21 +2384,20 @@ static void rs_fill_link_cmd(struct iwl4965_lq_sta *lq_sta,
2445 rs_dbgfs_set_mcs(lq_sta, &new_rate, index); 2384 rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
2446 2385
2447 /* Fill next table entry */ 2386 /* Fill next table entry */
2448 lq_cmd->rs_table[index].rate_n_flags = 2387 lq_cmd->rs_table[index].rate_n_flags = cpu_to_le32(new_rate);
2449 cpu_to_le32(new_rate.rate_n_flags);
2450 2388
2451 index++; 2389 index++;
2452 repeat_rate--; 2390 repeat_rate--;
2453 } 2391 }
2454 2392
2455 lq_cmd->general_params.dual_stream_ant_msk = 3; 2393 lq_cmd->agg_params.agg_frame_cnt_limit = 64;
2456 lq_cmd->agg_params.agg_dis_start_th = 3; 2394 lq_cmd->agg_params.agg_dis_start_th = 3;
2457 lq_cmd->agg_params.agg_time_limit = cpu_to_le16(4000); 2395 lq_cmd->agg_params.agg_time_limit = cpu_to_le16(4000);
2458} 2396}
2459 2397
2460static void *rs_alloc(struct ieee80211_local *local) 2398static void *rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
2461{ 2399{
2462 return local->hw.priv; 2400 return hw->priv;
2463} 2401}
2464/* rate scale requires free function to be implemented */ 2402/* rate scale requires free function to be implemented */
2465static void rs_free(void *priv_rate) 2403static void rs_free(void *priv_rate)
@@ -2469,18 +2407,22 @@ static void rs_free(void *priv_rate)
2469 2407
2470static void rs_clear(void *priv_rate) 2408static void rs_clear(void *priv_rate)
2471{ 2409{
2410#ifdef CONFIG_IWLWIFI_DEBUG
2472 struct iwl_priv *priv = (struct iwl_priv *) priv_rate; 2411 struct iwl_priv *priv = (struct iwl_priv *) priv_rate;
2473 2412
2474 IWL_DEBUG_RATE("enter\n"); 2413 IWL_DEBUG_RATE("enter\n");
2475 2414
2476 priv->lq_mngr.lq_ready = 0; 2415 /* TODO - add rate scale state reset */
2477 2416
2478 IWL_DEBUG_RATE("leave\n"); 2417 IWL_DEBUG_RATE("leave\n");
2418#endif /* CONFIG_IWLWIFI_DEBUG */
2479} 2419}
2480 2420
2481static void rs_free_sta(void *priv, void *priv_sta) 2421static void rs_free_sta(void *priv_r, struct ieee80211_sta *sta,
2422 void *priv_sta)
2482{ 2423{
2483 struct iwl4965_lq_sta *lq_sta = priv_sta; 2424 struct iwl_lq_sta *lq_sta = priv_sta;
2425 struct iwl_priv *priv __maybe_unused = priv_r;
2484 2426
2485 IWL_DEBUG_RATE("enter\n"); 2427 IWL_DEBUG_RATE("enter\n");
2486 kfree(lq_sta); 2428 kfree(lq_sta);
@@ -2494,55 +2436,57 @@ static int open_file_generic(struct inode *inode, struct file *file)
2494 file->private_data = inode->i_private; 2436 file->private_data = inode->i_private;
2495 return 0; 2437 return 0;
2496} 2438}
2497static void rs_dbgfs_set_mcs(struct iwl4965_lq_sta *lq_sta, 2439static void rs_dbgfs_set_mcs(struct iwl_lq_sta *lq_sta,
2498 struct iwl4965_rate *mcs, int index) 2440 u32 *rate_n_flags, int index)
2499{ 2441{
2500 u32 base_rate; 2442 struct iwl_priv *priv;
2501
2502 if (lq_sta->band == IEEE80211_BAND_5GHZ)
2503 base_rate = 0x800D;
2504 else
2505 base_rate = 0x820A;
2506 2443
2507 if (lq_sta->dbg_fixed.rate_n_flags) { 2444 priv = lq_sta->drv;
2508 if (index < 12) 2445 if (lq_sta->dbg_fixed_rate) {
2509 mcs->rate_n_flags = lq_sta->dbg_fixed.rate_n_flags; 2446 if (index < 12) {
2510 else 2447 *rate_n_flags = lq_sta->dbg_fixed_rate;
2511 mcs->rate_n_flags = base_rate; 2448 } else {
2449 if (lq_sta->band == IEEE80211_BAND_5GHZ)
2450 *rate_n_flags = 0x800D;
2451 else
2452 *rate_n_flags = 0x820A;
2453 }
2512 IWL_DEBUG_RATE("Fixed rate ON\n"); 2454 IWL_DEBUG_RATE("Fixed rate ON\n");
2513 return; 2455 } else {
2456 IWL_DEBUG_RATE("Fixed rate OFF\n");
2514 } 2457 }
2515
2516 IWL_DEBUG_RATE("Fixed rate OFF\n");
2517} 2458}
2518 2459
2519static ssize_t rs_sta_dbgfs_scale_table_write(struct file *file, 2460static ssize_t rs_sta_dbgfs_scale_table_write(struct file *file,
2520 const char __user *user_buf, size_t count, loff_t *ppos) 2461 const char __user *user_buf, size_t count, loff_t *ppos)
2521{ 2462{
2522 struct iwl4965_lq_sta *lq_sta = file->private_data; 2463 struct iwl_lq_sta *lq_sta = file->private_data;
2464 struct iwl_priv *priv;
2523 char buf[64]; 2465 char buf[64];
2524 int buf_size; 2466 int buf_size;
2525 u32 parsed_rate; 2467 u32 parsed_rate;
2526 2468
2469 priv = lq_sta->drv;
2527 memset(buf, 0, sizeof(buf)); 2470 memset(buf, 0, sizeof(buf));
2528 buf_size = min(count, sizeof(buf) - 1); 2471 buf_size = min(count, sizeof(buf) - 1);
2529 if (copy_from_user(buf, user_buf, buf_size)) 2472 if (copy_from_user(buf, user_buf, buf_size))
2530 return -EFAULT; 2473 return -EFAULT;
2531 2474
2532 if (sscanf(buf, "%x", &parsed_rate) == 1) 2475 if (sscanf(buf, "%x", &parsed_rate) == 1)
2533 lq_sta->dbg_fixed.rate_n_flags = parsed_rate; 2476 lq_sta->dbg_fixed_rate = parsed_rate;
2534 else 2477 else
2535 lq_sta->dbg_fixed.rate_n_flags = 0; 2478 lq_sta->dbg_fixed_rate = 0;
2536 2479
2537 lq_sta->active_rate = 0x0FFF; /* 1 - 54 MBits, includes CCK */ 2480 lq_sta->active_legacy_rate = 0x0FFF; /* 1 - 54 MBits, includes CCK */
2538 lq_sta->active_siso_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */ 2481 lq_sta->active_siso_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */
2539 lq_sta->active_mimo_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */ 2482 lq_sta->active_mimo2_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */
2483 lq_sta->active_mimo3_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */
2540 2484
2541 IWL_DEBUG_RATE("sta_id %d rate 0x%X\n", 2485 IWL_DEBUG_RATE("sta_id %d rate 0x%X\n",
2542 lq_sta->lq.sta_id, lq_sta->dbg_fixed.rate_n_flags); 2486 lq_sta->lq.sta_id, lq_sta->dbg_fixed_rate);
2543 2487
2544 if (lq_sta->dbg_fixed.rate_n_flags) { 2488 if (lq_sta->dbg_fixed_rate) {
2545 rs_fill_link_cmd(lq_sta, &lq_sta->dbg_fixed, &lq_sta->lq); 2489 rs_fill_link_cmd(NULL, lq_sta, lq_sta->dbg_fixed_rate);
2546 iwl_send_lq_cmd(lq_sta->drv, &lq_sta->lq, CMD_ASYNC); 2490 iwl_send_lq_cmd(lq_sta->drv, &lq_sta->lq, CMD_ASYNC);
2547 } 2491 }
2548 2492
@@ -2556,14 +2500,14 @@ static ssize_t rs_sta_dbgfs_scale_table_read(struct file *file,
2556 int desc = 0; 2500 int desc = 0;
2557 int i = 0; 2501 int i = 0;
2558 2502
2559 struct iwl4965_lq_sta *lq_sta = file->private_data; 2503 struct iwl_lq_sta *lq_sta = file->private_data;
2560 2504
2561 desc += sprintf(buff+desc, "sta_id %d\n", lq_sta->lq.sta_id); 2505 desc += sprintf(buff+desc, "sta_id %d\n", lq_sta->lq.sta_id);
2562 desc += sprintf(buff+desc, "failed=%d success=%d rate=0%X\n", 2506 desc += sprintf(buff+desc, "failed=%d success=%d rate=0%X\n",
2563 lq_sta->total_failed, lq_sta->total_success, 2507 lq_sta->total_failed, lq_sta->total_success,
2564 lq_sta->active_rate); 2508 lq_sta->active_legacy_rate);
2565 desc += sprintf(buff+desc, "fixed rate 0x%X\n", 2509 desc += sprintf(buff+desc, "fixed rate 0x%X\n",
2566 lq_sta->dbg_fixed.rate_n_flags); 2510 lq_sta->dbg_fixed_rate);
2567 desc += sprintf(buff+desc, "general:" 2511 desc += sprintf(buff+desc, "general:"
2568 "flags=0x%X mimo-d=%d s-ant0x%x d-ant=0x%x\n", 2512 "flags=0x%X mimo-d=%d s-ant0x%x d-ant=0x%x\n",
2569 lq_sta->lq.general_params.flags, 2513 lq_sta->lq.general_params.flags,
@@ -2604,7 +2548,7 @@ static ssize_t rs_sta_dbgfs_stats_table_read(struct file *file,
2604 int desc = 0; 2548 int desc = 0;
2605 int i, j; 2549 int i, j;
2606 2550
2607 struct iwl4965_lq_sta *lq_sta = file->private_data; 2551 struct iwl_lq_sta *lq_sta = file->private_data;
2608 for (i = 0; i < LQ_SIZE; i++) { 2552 for (i = 0; i < LQ_SIZE; i++) {
2609 desc += sprintf(buff+desc, "%s type=%d SGI=%d FAT=%d DUP=%d\n" 2553 desc += sprintf(buff+desc, "%s type=%d SGI=%d FAT=%d DUP=%d\n"
2610 "rate=0x%X\n", 2554 "rate=0x%X\n",
@@ -2613,7 +2557,7 @@ static ssize_t rs_sta_dbgfs_stats_table_read(struct file *file,
2613 lq_sta->lq_info[i].is_SGI, 2557 lq_sta->lq_info[i].is_SGI,
2614 lq_sta->lq_info[i].is_fat, 2558 lq_sta->lq_info[i].is_fat,
2615 lq_sta->lq_info[i].is_dup, 2559 lq_sta->lq_info[i].is_dup,
2616 lq_sta->lq_info[i].current_rate.rate_n_flags); 2560 lq_sta->lq_info[i].current_rate);
2617 for (j = 0; j < IWL_RATE_COUNT; j++) { 2561 for (j = 0; j < IWL_RATE_COUNT; j++) {
2618 desc += sprintf(buff+desc, 2562 desc += sprintf(buff+desc,
2619 "counter=%d success=%d %%=%d\n", 2563 "counter=%d success=%d %%=%d\n",
@@ -2633,29 +2577,25 @@ static const struct file_operations rs_sta_dbgfs_stats_table_ops = {
2633static void rs_add_debugfs(void *priv, void *priv_sta, 2577static void rs_add_debugfs(void *priv, void *priv_sta,
2634 struct dentry *dir) 2578 struct dentry *dir)
2635{ 2579{
2636 struct iwl4965_lq_sta *lq_sta = priv_sta; 2580 struct iwl_lq_sta *lq_sta = priv_sta;
2637 lq_sta->rs_sta_dbgfs_scale_table_file = 2581 lq_sta->rs_sta_dbgfs_scale_table_file =
2638 debugfs_create_file("rate_scale_table", 0600, dir, 2582 debugfs_create_file("rate_scale_table", 0600, dir,
2639 lq_sta, &rs_sta_dbgfs_scale_table_ops); 2583 lq_sta, &rs_sta_dbgfs_scale_table_ops);
2640 lq_sta->rs_sta_dbgfs_stats_table_file = 2584 lq_sta->rs_sta_dbgfs_stats_table_file =
2641 debugfs_create_file("rate_stats_table", 0600, dir, 2585 debugfs_create_file("rate_stats_table", 0600, dir,
2642 lq_sta, &rs_sta_dbgfs_stats_table_ops); 2586 lq_sta, &rs_sta_dbgfs_stats_table_ops);
2643#ifdef CONFIG_IWL4965_HT
2644 lq_sta->rs_sta_dbgfs_tx_agg_tid_en_file = 2587 lq_sta->rs_sta_dbgfs_tx_agg_tid_en_file =
2645 debugfs_create_u8("tx_agg_tid_enable", 0600, dir, 2588 debugfs_create_u8("tx_agg_tid_enable", 0600, dir,
2646 &lq_sta->tx_agg_tid_en); 2589 &lq_sta->tx_agg_tid_en);
2647#endif
2648 2590
2649} 2591}
2650 2592
2651static void rs_remove_debugfs(void *priv, void *priv_sta) 2593static void rs_remove_debugfs(void *priv, void *priv_sta)
2652{ 2594{
2653 struct iwl4965_lq_sta *lq_sta = priv_sta; 2595 struct iwl_lq_sta *lq_sta = priv_sta;
2654 debugfs_remove(lq_sta->rs_sta_dbgfs_scale_table_file); 2596 debugfs_remove(lq_sta->rs_sta_dbgfs_scale_table_file);
2655 debugfs_remove(lq_sta->rs_sta_dbgfs_stats_table_file); 2597 debugfs_remove(lq_sta->rs_sta_dbgfs_stats_table_file);
2656#ifdef CONFIG_IWL4965_HT
2657 debugfs_remove(lq_sta->rs_sta_dbgfs_tx_agg_tid_en_file); 2598 debugfs_remove(lq_sta->rs_sta_dbgfs_tx_agg_tid_en_file);
2658#endif
2659} 2599}
2660#endif 2600#endif
2661 2601
@@ -2676,110 +2616,12 @@ static struct rate_control_ops rs_ops = {
2676#endif 2616#endif
2677}; 2617};
2678 2618
2679int iwl4965_fill_rs_info(struct ieee80211_hw *hw, char *buf, u8 sta_id) 2619int iwlagn_rate_control_register(void)
2680{
2681 struct ieee80211_local *local = hw_to_local(hw);
2682 struct iwl_priv *priv = hw->priv;
2683 struct iwl4965_lq_sta *lq_sta;
2684 struct sta_info *sta;
2685 int cnt = 0, i;
2686 u32 samples = 0, success = 0, good = 0;
2687 unsigned long now = jiffies;
2688 u32 max_time = 0;
2689 u8 lq_type, antenna;
2690
2691 rcu_read_lock();
2692
2693 sta = sta_info_get(local, priv->stations[sta_id].sta.sta.addr);
2694 if (!sta || !sta->rate_ctrl_priv) {
2695 if (sta)
2696 IWL_DEBUG_RATE("leave - no private rate data!\n");
2697 else
2698 IWL_DEBUG_RATE("leave - no station!\n");
2699 rcu_read_unlock();
2700 return sprintf(buf, "station %d not found\n", sta_id);
2701 }
2702
2703 lq_sta = (void *)sta->rate_ctrl_priv;
2704
2705 lq_type = lq_sta->lq_info[lq_sta->active_tbl].lq_type;
2706 antenna = lq_sta->lq_info[lq_sta->active_tbl].antenna_type;
2707
2708 if (is_legacy(lq_type))
2709 i = IWL_RATE_54M_INDEX;
2710 else
2711 i = IWL_RATE_60M_INDEX;
2712 while (1) {
2713 u64 mask;
2714 int j;
2715 int active = lq_sta->active_tbl;
2716
2717 cnt +=
2718 sprintf(&buf[cnt], " %2dMbs: ", iwl4965_rates[i].ieee / 2);
2719
2720 mask = (1ULL << (IWL_RATE_MAX_WINDOW - 1));
2721 for (j = 0; j < IWL_RATE_MAX_WINDOW; j++, mask >>= 1)
2722 buf[cnt++] =
2723 (lq_sta->lq_info[active].win[i].data & mask)
2724 ? '1' : '0';
2725
2726 samples += lq_sta->lq_info[active].win[i].counter;
2727 good += lq_sta->lq_info[active].win[i].success_counter;
2728 success += lq_sta->lq_info[active].win[i].success_counter *
2729 iwl4965_rates[i].ieee;
2730
2731 if (lq_sta->lq_info[active].win[i].stamp) {
2732 int delta =
2733 jiffies_to_msecs(now -
2734 lq_sta->lq_info[active].win[i].stamp);
2735
2736 if (delta > max_time)
2737 max_time = delta;
2738
2739 cnt += sprintf(&buf[cnt], "%5dms\n", delta);
2740 } else
2741 buf[cnt++] = '\n';
2742
2743 j = iwl4965_get_prev_ieee_rate(i);
2744 if (j == i)
2745 break;
2746 i = j;
2747 }
2748
2749 /* Display the average rate of all samples taken.
2750 *
2751 * NOTE: We multiply # of samples by 2 since the IEEE measurement
2752 * added from iwl4965_rates is actually 2X the rate */
2753 if (samples)
2754 cnt += sprintf(&buf[cnt],
2755 "\nAverage rate is %3d.%02dMbs over last %4dms\n"
2756 "%3d%% success (%d good packets over %d tries)\n",
2757 success / (2 * samples), (success * 5 / samples) % 10,
2758 max_time, good * 100 / samples, good, samples);
2759 else
2760 cnt += sprintf(&buf[cnt], "\nAverage rate: 0Mbs\n");
2761
2762 cnt += sprintf(&buf[cnt], "\nrate scale type %d antenna %d "
2763 "active_search %d rate index %d\n", lq_type, antenna,
2764 lq_sta->search_better_tbl, sta->last_txrate_idx);
2765
2766 rcu_read_unlock();
2767 return cnt;
2768}
2769
2770void iwl4965_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id)
2771{
2772 struct iwl_priv *priv = hw->priv;
2773
2774 priv->lq_mngr.lq_ready = 1;
2775}
2776
2777int iwl4965_rate_control_register(void)
2778{ 2620{
2779 return ieee80211_rate_control_register(&rs_ops); 2621 return ieee80211_rate_control_register(&rs_ops);
2780} 2622}
2781 2623
2782void iwl4965_rate_control_unregister(void) 2624void iwlagn_rate_control_unregister(void)
2783{ 2625{
2784 ieee80211_rate_control_unregister(&rs_ops); 2626 ieee80211_rate_control_unregister(&rs_ops);
2785} 2627}
diff --git a/drivers/net/wireless/iwlwifi/iwl-4965-rs.h b/drivers/net/wireless/iwlwifi/iwl-agn-rs.h
index 866e378aa385..d148d73635eb 100644
--- a/drivers/net/wireless/iwlwifi/iwl-4965-rs.h
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-rs.h
@@ -24,15 +24,16 @@
24 * 24 *
25 *****************************************************************************/ 25 *****************************************************************************/
26 26
27#ifndef __iwl_4965_rs_h__ 27#ifndef __iwl_agn_rs_h__
28#define __iwl_4965_rs_h__ 28#define __iwl_agn_rs_h__
29 29
30#include "iwl-4965.h" 30#include "iwl-dev.h"
31 31
32struct iwl4965_rate_info { 32struct iwl_rate_info {
33 u8 plcp; /* uCode API: IWL_RATE_6M_PLCP, etc. */ 33 u8 plcp; /* uCode API: IWL_RATE_6M_PLCP, etc. */
34 u8 plcp_siso; /* uCode API: IWL_RATE_SISO_6M_PLCP, etc. */ 34 u8 plcp_siso; /* uCode API: IWL_RATE_SISO_6M_PLCP, etc. */
35 u8 plcp_mimo; /* uCode API: IWL_RATE_MIMO_6M_PLCP, etc. */ 35 u8 plcp_mimo2; /* uCode API: IWL_RATE_MIMO2_6M_PLCP, etc. */
36 u8 plcp_mimo3; /* uCode API: IWL_RATE_MIMO3_6M_PLCP, etc. */
36 u8 ieee; /* MAC header: IWL_RATE_6M_IEEE, etc. */ 37 u8 ieee; /* MAC header: IWL_RATE_6M_IEEE, etc. */
37 u8 prev_ieee; /* previous rate in IEEE speeds */ 38 u8 prev_ieee; /* previous rate in IEEE speeds */
38 u8 next_ieee; /* next rate in IEEE speeds */ 39 u8 next_ieee; /* next rate in IEEE speeds */
@@ -44,7 +45,7 @@ struct iwl4965_rate_info {
44 45
45/* 46/*
46 * These serve as indexes into 47 * These serve as indexes into
47 * struct iwl4965_rate_info iwl4965_rates[IWL_RATE_COUNT]; 48 * struct iwl_rate_info iwl_rates[IWL_RATE_COUNT];
48 */ 49 */
49enum { 50enum {
50 IWL_RATE_1M_INDEX = 0, 51 IWL_RATE_1M_INDEX = 0,
@@ -60,9 +61,9 @@ enum {
60 IWL_RATE_48M_INDEX, 61 IWL_RATE_48M_INDEX,
61 IWL_RATE_54M_INDEX, 62 IWL_RATE_54M_INDEX,
62 IWL_RATE_60M_INDEX, 63 IWL_RATE_60M_INDEX,
63 IWL_RATE_COUNT, 64 IWL_RATE_COUNT, /*FIXME:RS:change to IWL_RATE_INDEX_COUNT,*/
64 IWL_RATE_INVM_INDEX = IWL_RATE_COUNT, 65 IWL_RATE_INVM_INDEX = IWL_RATE_COUNT,
65 IWL_RATE_INVALID = IWL_RATE_INVM_INDEX 66 IWL_RATE_INVALID = IWL_RATE_COUNT,
66}; 67};
67 68
68enum { 69enum {
@@ -87,7 +88,7 @@ enum {
87#define IWL_RATE_5M_MASK (1 << IWL_RATE_5M_INDEX) 88#define IWL_RATE_5M_MASK (1 << IWL_RATE_5M_INDEX)
88#define IWL_RATE_11M_MASK (1 << IWL_RATE_11M_INDEX) 89#define IWL_RATE_11M_MASK (1 << IWL_RATE_11M_INDEX)
89 90
90/* 4965 uCode API values for legacy bit rates, both OFDM and CCK */ 91/* uCode API values for legacy bit rates, both OFDM and CCK */
91enum { 92enum {
92 IWL_RATE_6M_PLCP = 13, 93 IWL_RATE_6M_PLCP = 13,
93 IWL_RATE_9M_PLCP = 15, 94 IWL_RATE_9M_PLCP = 15,
@@ -97,14 +98,16 @@ enum {
97 IWL_RATE_36M_PLCP = 11, 98 IWL_RATE_36M_PLCP = 11,
98 IWL_RATE_48M_PLCP = 1, 99 IWL_RATE_48M_PLCP = 1,
99 IWL_RATE_54M_PLCP = 3, 100 IWL_RATE_54M_PLCP = 3,
100 IWL_RATE_60M_PLCP = 3, 101 IWL_RATE_60M_PLCP = 3,/*FIXME:RS:should be removed*/
101 IWL_RATE_1M_PLCP = 10, 102 IWL_RATE_1M_PLCP = 10,
102 IWL_RATE_2M_PLCP = 20, 103 IWL_RATE_2M_PLCP = 20,
103 IWL_RATE_5M_PLCP = 55, 104 IWL_RATE_5M_PLCP = 55,
104 IWL_RATE_11M_PLCP = 110, 105 IWL_RATE_11M_PLCP = 110,
106 /*FIXME:RS:change to IWL_RATE_LEGACY_??M_PLCP */
107 /*FIXME:RS:add IWL_RATE_LEGACY_INVM_PLCP = 0,*/
105}; 108};
106 109
107/* 4965 uCode API values for OFDM high-throughput (HT) bit rates */ 110/* uCode API values for OFDM high-throughput (HT) bit rates */
108enum { 111enum {
109 IWL_RATE_SISO_6M_PLCP = 0, 112 IWL_RATE_SISO_6M_PLCP = 0,
110 IWL_RATE_SISO_12M_PLCP = 1, 113 IWL_RATE_SISO_12M_PLCP = 1,
@@ -114,16 +117,25 @@ enum {
114 IWL_RATE_SISO_48M_PLCP = 5, 117 IWL_RATE_SISO_48M_PLCP = 5,
115 IWL_RATE_SISO_54M_PLCP = 6, 118 IWL_RATE_SISO_54M_PLCP = 6,
116 IWL_RATE_SISO_60M_PLCP = 7, 119 IWL_RATE_SISO_60M_PLCP = 7,
117 IWL_RATE_MIMO_6M_PLCP = 0x8, 120 IWL_RATE_MIMO2_6M_PLCP = 0x8,
118 IWL_RATE_MIMO_12M_PLCP = 0x9, 121 IWL_RATE_MIMO2_12M_PLCP = 0x9,
119 IWL_RATE_MIMO_18M_PLCP = 0xa, 122 IWL_RATE_MIMO2_18M_PLCP = 0xa,
120 IWL_RATE_MIMO_24M_PLCP = 0xb, 123 IWL_RATE_MIMO2_24M_PLCP = 0xb,
121 IWL_RATE_MIMO_36M_PLCP = 0xc, 124 IWL_RATE_MIMO2_36M_PLCP = 0xc,
122 IWL_RATE_MIMO_48M_PLCP = 0xd, 125 IWL_RATE_MIMO2_48M_PLCP = 0xd,
123 IWL_RATE_MIMO_54M_PLCP = 0xe, 126 IWL_RATE_MIMO2_54M_PLCP = 0xe,
124 IWL_RATE_MIMO_60M_PLCP = 0xf, 127 IWL_RATE_MIMO2_60M_PLCP = 0xf,
128 IWL_RATE_MIMO3_6M_PLCP = 0x10,
129 IWL_RATE_MIMO3_12M_PLCP = 0x11,
130 IWL_RATE_MIMO3_18M_PLCP = 0x12,
131 IWL_RATE_MIMO3_24M_PLCP = 0x13,
132 IWL_RATE_MIMO3_36M_PLCP = 0x14,
133 IWL_RATE_MIMO3_48M_PLCP = 0x15,
134 IWL_RATE_MIMO3_54M_PLCP = 0x16,
135 IWL_RATE_MIMO3_60M_PLCP = 0x17,
125 IWL_RATE_SISO_INVM_PLCP, 136 IWL_RATE_SISO_INVM_PLCP,
126 IWL_RATE_MIMO_INVM_PLCP = IWL_RATE_SISO_INVM_PLCP, 137 IWL_RATE_MIMO2_INVM_PLCP = IWL_RATE_SISO_INVM_PLCP,
138 IWL_RATE_MIMO3_INVM_PLCP = IWL_RATE_SISO_INVM_PLCP,
127}; 139};
128 140
129/* MAC header values for bit rates */ 141/* MAC header values for bit rates */
@@ -194,19 +206,30 @@ enum {
194#define IWL_RATE_DECREASE_TH 1920 /* 15% */ 206#define IWL_RATE_DECREASE_TH 1920 /* 15% */
195 207
196/* possible actions when in legacy mode */ 208/* possible actions when in legacy mode */
197#define IWL_LEGACY_SWITCH_ANTENNA 0 209#define IWL_LEGACY_SWITCH_ANTENNA1 0
198#define IWL_LEGACY_SWITCH_SISO 1 210#define IWL_LEGACY_SWITCH_ANTENNA2 1
199#define IWL_LEGACY_SWITCH_MIMO 2 211#define IWL_LEGACY_SWITCH_SISO 2
212#define IWL_LEGACY_SWITCH_MIMO2_AB 3
213#define IWL_LEGACY_SWITCH_MIMO2_AC 4
214#define IWL_LEGACY_SWITCH_MIMO2_BC 5
200 215
201/* possible actions when in siso mode */ 216/* possible actions when in siso mode */
202#define IWL_SISO_SWITCH_ANTENNA 0 217#define IWL_SISO_SWITCH_ANTENNA1 0
203#define IWL_SISO_SWITCH_MIMO 1 218#define IWL_SISO_SWITCH_ANTENNA2 1
204#define IWL_SISO_SWITCH_GI 2 219#define IWL_SISO_SWITCH_MIMO2_AB 2
220#define IWL_SISO_SWITCH_MIMO2_AC 3
221#define IWL_SISO_SWITCH_MIMO2_BC 4
222#define IWL_SISO_SWITCH_GI 5
205 223
206/* possible actions when in mimo mode */ 224/* possible actions when in mimo mode */
207#define IWL_MIMO_SWITCH_ANTENNA_A 0 225#define IWL_MIMO2_SWITCH_ANTENNA1 0
208#define IWL_MIMO_SWITCH_ANTENNA_B 1 226#define IWL_MIMO2_SWITCH_ANTENNA2 1
209#define IWL_MIMO_SWITCH_GI 2 227#define IWL_MIMO2_SWITCH_SISO_A 2
228#define IWL_MIMO2_SWITCH_SISO_B 3
229#define IWL_MIMO2_SWITCH_SISO_C 4
230#define IWL_MIMO2_SWITCH_GI 5
231
232/*FIXME:RS:add posible acctions for MIMO3*/
210 233
211#define IWL_ACTION_LIMIT 3 /* # possible actions */ 234#define IWL_ACTION_LIMIT 3 /* # possible actions */
212 235
@@ -224,60 +247,52 @@ enum {
224#define TID_MAX_TIME_DIFF ((TID_QUEUE_MAX_SIZE - 1) * TID_QUEUE_CELL_SPACING) 247#define TID_MAX_TIME_DIFF ((TID_QUEUE_MAX_SIZE - 1) * TID_QUEUE_CELL_SPACING)
225#define TIME_WRAP_AROUND(x, y) (((y) > (x)) ? (y) - (x) : (0-(x)) + (y)) 248#define TIME_WRAP_AROUND(x, y) (((y) > (x)) ? (y) - (x) : (0-(x)) + (y))
226 249
227extern const struct iwl4965_rate_info iwl4965_rates[IWL_RATE_COUNT]; 250extern const struct iwl_rate_info iwl_rates[IWL_RATE_COUNT];
228 251
229enum iwl4965_table_type { 252enum iwl_table_type {
230 LQ_NONE, 253 LQ_NONE,
231 LQ_G, /* legacy types */ 254 LQ_G, /* legacy types */
232 LQ_A, 255 LQ_A,
233 LQ_SISO, /* high-throughput types */ 256 LQ_SISO, /* high-throughput types */
234 LQ_MIMO, 257 LQ_MIMO2,
258 LQ_MIMO3,
235 LQ_MAX, 259 LQ_MAX,
236}; 260};
237 261
238#define is_legacy(tbl) (((tbl) == LQ_G) || ((tbl) == LQ_A)) 262#define is_legacy(tbl) (((tbl) == LQ_G) || ((tbl) == LQ_A))
239#define is_siso(tbl) (((tbl) == LQ_SISO)) 263#define is_siso(tbl) ((tbl) == LQ_SISO)
240#define is_mimo(tbl) (((tbl) == LQ_MIMO)) 264#define is_mimo2(tbl) ((tbl) == LQ_MIMO2)
265#define is_mimo3(tbl) ((tbl) == LQ_MIMO3)
266#define is_mimo(tbl) (is_mimo2(tbl) || is_mimo3(tbl))
241#define is_Ht(tbl) (is_siso(tbl) || is_mimo(tbl)) 267#define is_Ht(tbl) (is_siso(tbl) || is_mimo(tbl))
242#define is_a_band(tbl) (((tbl) == LQ_A)) 268#define is_a_band(tbl) ((tbl) == LQ_A)
243#define is_g_and(tbl) (((tbl) == LQ_G)) 269#define is_g_and(tbl) ((tbl) == LQ_G)
244 270
245/* 4965 has 2 antennas/chains for Tx (but 3 for Rx) */ 271#define ANT_NONE 0x0
246enum iwl4965_antenna_type { 272#define ANT_A BIT(0)
247 ANT_NONE, 273#define ANT_B BIT(1)
248 ANT_MAIN, 274#define ANT_AB (ANT_A | ANT_B)
249 ANT_AUX, 275#define ANT_C BIT(2)
250 ANT_BOTH, 276#define ANT_AC (ANT_A | ANT_C)
251}; 277#define ANT_BC (ANT_B | ANT_C)
278#define ANT_ABC (ANT_AB | ANT_C)
279
280static inline u8 num_of_ant(u8 mask)
281{
282 return !!((mask) & ANT_A) +
283 !!((mask) & ANT_B) +
284 !!((mask) & ANT_C);
285}
252 286
253static inline u8 iwl4965_get_prev_ieee_rate(u8 rate_index) 287static inline u8 iwl4965_get_prev_ieee_rate(u8 rate_index)
254{ 288{
255 u8 rate = iwl4965_rates[rate_index].prev_ieee; 289 u8 rate = iwl_rates[rate_index].prev_ieee;
256 290
257 if (rate == IWL_RATE_INVALID) 291 if (rate == IWL_RATE_INVALID)
258 rate = rate_index; 292 rate = rate_index;
259 return rate; 293 return rate;
260} 294}
261 295
262extern int iwl4965_hwrate_to_plcp_idx(u32 rate_n_flags);
263
264/**
265 * iwl4965_fill_rs_info - Fill an output text buffer with the rate representation
266 *
267 * NOTE: This is provided as a quick mechanism for a user to visualize
268 * the performance of the rate control algorithm and is not meant to be
269 * parsed software.
270 */
271extern int iwl4965_fill_rs_info(struct ieee80211_hw *, char *buf, u8 sta_id);
272
273/**
274 * iwl4965_rate_scale_init - Initialize the rate scale table based on assoc info
275 *
276 * The specific throughput table used is based on the type of network
277 * the associated with, including A, B, G, and G w/ TGG protection
278 */
279extern void iwl4965_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id);
280
281/** 296/**
282 * iwl4965_rate_control_register - Register the rate control algorithm callbacks 297 * iwl4965_rate_control_register - Register the rate control algorithm callbacks
283 * 298 *
@@ -288,7 +303,7 @@ extern void iwl4965_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id);
288 * ieee80211_register_hw 303 * ieee80211_register_hw
289 * 304 *
290 */ 305 */
291extern int iwl4965_rate_control_register(void); 306extern int iwlagn_rate_control_register(void);
292 307
293/** 308/**
294 * iwl4965_rate_control_unregister - Unregister the rate control callbacks 309 * iwl4965_rate_control_unregister - Unregister the rate control callbacks
@@ -296,6 +311,6 @@ extern int iwl4965_rate_control_register(void);
296 * This should be called after calling ieee80211_unregister_hw, but before 311 * This should be called after calling ieee80211_unregister_hw, but before
297 * the driver is unloaded. 312 * the driver is unloaded.
298 */ 313 */
299extern void iwl4965_rate_control_unregister(void); 314extern void iwlagn_rate_control_unregister(void);
300 315
301#endif 316#endif /* __iwl_agn__rs__ */
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.c b/drivers/net/wireless/iwlwifi/iwl-agn.c
new file mode 100644
index 000000000000..24a1aeb6448f
--- /dev/null
+++ b/drivers/net/wireless/iwlwifi/iwl-agn.c
@@ -0,0 +1,4549 @@
1/******************************************************************************
2 *
3 * Copyright(c) 2003 - 2008 Intel Corporation. All rights reserved.
4 *
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
20 *
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
23 *
24 * Contact Information:
25 * James P. Ketrenos <ipw2100-admin@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *
28 *****************************************************************************/
29
30#include <linux/kernel.h>
31#include <linux/module.h>
32#include <linux/init.h>
33#include <linux/pci.h>
34#include <linux/dma-mapping.h>
35#include <linux/delay.h>
36#include <linux/skbuff.h>
37#include <linux/netdevice.h>
38#include <linux/wireless.h>
39#include <linux/firmware.h>
40#include <linux/etherdevice.h>
41#include <linux/if_arp.h>
42
43#include <net/mac80211.h>
44
45#include <asm/div64.h>
46
47#include "iwl-eeprom.h"
48#include "iwl-dev.h"
49#include "iwl-core.h"
50#include "iwl-io.h"
51#include "iwl-helpers.h"
52#include "iwl-sta.h"
53#include "iwl-calib.h"
54
55
56/******************************************************************************
57 *
58 * module boiler plate
59 *
60 ******************************************************************************/
61
62/*
63 * module name, copyright, version, etc.
64 * NOTE: DRV_NAME is defined in iwlwifi.h for use by iwl-debug.h and printk
65 */
66
67#define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link AGN driver for Linux"
68
69#ifdef CONFIG_IWLWIFI_DEBUG
70#define VD "d"
71#else
72#define VD
73#endif
74
75#ifdef CONFIG_IWLAGN_SPECTRUM_MEASUREMENT
76#define VS "s"
77#else
78#define VS
79#endif
80
81#define DRV_VERSION IWLWIFI_VERSION VD VS
82
83
84MODULE_DESCRIPTION(DRV_DESCRIPTION);
85MODULE_VERSION(DRV_VERSION);
86MODULE_AUTHOR(DRV_COPYRIGHT);
87MODULE_LICENSE("GPL");
88MODULE_ALIAS("iwl4965");
89
90/*************** STATION TABLE MANAGEMENT ****
91 * mac80211 should be examined to determine if sta_info is duplicating
92 * the functionality provided here
93 */
94
95/**************************************************************/
96
97
98
99static void iwl4965_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt)
100{
101 struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
102
103 if (hw_decrypt)
104 rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
105 else
106 rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
107
108}
109
110/**
111 * iwl4965_check_rxon_cmd - validate RXON structure is valid
112 *
113 * NOTE: This is really only useful during development and can eventually
114 * be #ifdef'd out once the driver is stable and folks aren't actively
115 * making changes
116 */
117static int iwl4965_check_rxon_cmd(struct iwl_rxon_cmd *rxon)
118{
119 int error = 0;
120 int counter = 1;
121
122 if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
123 error |= le32_to_cpu(rxon->flags &
124 (RXON_FLG_TGJ_NARROW_BAND_MSK |
125 RXON_FLG_RADAR_DETECT_MSK));
126 if (error)
127 IWL_WARNING("check 24G fields %d | %d\n",
128 counter++, error);
129 } else {
130 error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ?
131 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK);
132 if (error)
133 IWL_WARNING("check 52 fields %d | %d\n",
134 counter++, error);
135 error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK);
136 if (error)
137 IWL_WARNING("check 52 CCK %d | %d\n",
138 counter++, error);
139 }
140 error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1;
141 if (error)
142 IWL_WARNING("check mac addr %d | %d\n", counter++, error);
143
144 /* make sure basic rates 6Mbps and 1Mbps are supported */
145 error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) &&
146 ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0));
147 if (error)
148 IWL_WARNING("check basic rate %d | %d\n", counter++, error);
149
150 error |= (le16_to_cpu(rxon->assoc_id) > 2007);
151 if (error)
152 IWL_WARNING("check assoc id %d | %d\n", counter++, error);
153
154 error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
155 == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK));
156 if (error)
157 IWL_WARNING("check CCK and short slot %d | %d\n",
158 counter++, error);
159
160 error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
161 == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK));
162 if (error)
163 IWL_WARNING("check CCK & auto detect %d | %d\n",
164 counter++, error);
165
166 error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
167 RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK);
168 if (error)
169 IWL_WARNING("check TGG and auto detect %d | %d\n",
170 counter++, error);
171
172 if (error)
173 IWL_WARNING("Tuning to channel %d\n",
174 le16_to_cpu(rxon->channel));
175
176 if (error) {
177 IWL_ERROR("Not a valid iwl4965_rxon_assoc_cmd field values\n");
178 return -1;
179 }
180 return 0;
181}
182
183/**
184 * iwl_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
185 * @priv: staging_rxon is compared to active_rxon
186 *
187 * If the RXON structure is changing enough to require a new tune,
188 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
189 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
190 */
191static int iwl_full_rxon_required(struct iwl_priv *priv)
192{
193
194 /* These items are only settable from the full RXON command */
195 if (!(iwl_is_associated(priv)) ||
196 compare_ether_addr(priv->staging_rxon.bssid_addr,
197 priv->active_rxon.bssid_addr) ||
198 compare_ether_addr(priv->staging_rxon.node_addr,
199 priv->active_rxon.node_addr) ||
200 compare_ether_addr(priv->staging_rxon.wlap_bssid_addr,
201 priv->active_rxon.wlap_bssid_addr) ||
202 (priv->staging_rxon.dev_type != priv->active_rxon.dev_type) ||
203 (priv->staging_rxon.channel != priv->active_rxon.channel) ||
204 (priv->staging_rxon.air_propagation !=
205 priv->active_rxon.air_propagation) ||
206 (priv->staging_rxon.ofdm_ht_single_stream_basic_rates !=
207 priv->active_rxon.ofdm_ht_single_stream_basic_rates) ||
208 (priv->staging_rxon.ofdm_ht_dual_stream_basic_rates !=
209 priv->active_rxon.ofdm_ht_dual_stream_basic_rates) ||
210 (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id))
211 return 1;
212
213 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
214 * be updated with the RXON_ASSOC command -- however only some
215 * flag transitions are allowed using RXON_ASSOC */
216
217 /* Check if we are not switching bands */
218 if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) !=
219 (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK))
220 return 1;
221
222 /* Check if we are switching association toggle */
223 if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) !=
224 (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK))
225 return 1;
226
227 return 0;
228}
229
230/**
231 * iwl4965_commit_rxon - commit staging_rxon to hardware
232 *
233 * The RXON command in staging_rxon is committed to the hardware and
234 * the active_rxon structure is updated with the new data. This
235 * function correctly transitions out of the RXON_ASSOC_MSK state if
236 * a HW tune is required based on the RXON structure changes.
237 */
238static int iwl4965_commit_rxon(struct iwl_priv *priv)
239{
240 /* cast away the const for active_rxon in this function */
241 struct iwl_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
242 DECLARE_MAC_BUF(mac);
243 int ret;
244 bool new_assoc =
245 !!(priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK);
246
247 if (!iwl_is_alive(priv))
248 return -EBUSY;
249
250 /* always get timestamp with Rx frame */
251 priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK;
252 /* allow CTS-to-self if possible. this is relevant only for
253 * 5000, but will not damage 4965 */
254 priv->staging_rxon.flags |= RXON_FLG_SELF_CTS_EN;
255
256 ret = iwl4965_check_rxon_cmd(&priv->staging_rxon);
257 if (ret) {
258 IWL_ERROR("Invalid RXON configuration. Not committing.\n");
259 return -EINVAL;
260 }
261
262 /* If we don't need to send a full RXON, we can use
263 * iwl4965_rxon_assoc_cmd which is used to reconfigure filter
264 * and other flags for the current radio configuration. */
265 if (!iwl_full_rxon_required(priv)) {
266 ret = iwl_send_rxon_assoc(priv);
267 if (ret) {
268 IWL_ERROR("Error setting RXON_ASSOC (%d)\n", ret);
269 return ret;
270 }
271
272 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
273 return 0;
274 }
275
276 /* station table will be cleared */
277 priv->assoc_station_added = 0;
278
279 /* If we are currently associated and the new config requires
280 * an RXON_ASSOC and the new config wants the associated mask enabled,
281 * we must clear the associated from the active configuration
282 * before we apply the new config */
283 if (iwl_is_associated(priv) && new_assoc) {
284 IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
285 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
286
287 ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
288 sizeof(struct iwl_rxon_cmd),
289 &priv->active_rxon);
290
291 /* If the mask clearing failed then we set
292 * active_rxon back to what it was previously */
293 if (ret) {
294 active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
295 IWL_ERROR("Error clearing ASSOC_MSK (%d)\n", ret);
296 return ret;
297 }
298 }
299
300 IWL_DEBUG_INFO("Sending RXON\n"
301 "* with%s RXON_FILTER_ASSOC_MSK\n"
302 "* channel = %d\n"
303 "* bssid = %s\n",
304 (new_assoc ? "" : "out"),
305 le16_to_cpu(priv->staging_rxon.channel),
306 print_mac(mac, priv->staging_rxon.bssid_addr));
307
308 iwl4965_set_rxon_hwcrypto(priv, !priv->hw_params.sw_crypto);
309
310 /* Apply the new configuration
311 * RXON unassoc clears the station table in uCode, send it before
312 * we add the bcast station. If assoc bit is set, we will send RXON
313 * after having added the bcast and bssid station.
314 */
315 if (!new_assoc) {
316 ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
317 sizeof(struct iwl_rxon_cmd), &priv->staging_rxon);
318 if (ret) {
319 IWL_ERROR("Error setting new RXON (%d)\n", ret);
320 return ret;
321 }
322 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
323 }
324
325 iwl_clear_stations_table(priv);
326
327 if (!priv->error_recovering)
328 priv->start_calib = 0;
329
330 /* Add the broadcast address so we can send broadcast frames */
331 if (iwl_rxon_add_station(priv, iwl_bcast_addr, 0) ==
332 IWL_INVALID_STATION) {
333 IWL_ERROR("Error adding BROADCAST address for transmit.\n");
334 return -EIO;
335 }
336
337 /* If we have set the ASSOC_MSK and we are in BSS mode then
338 * add the IWL_AP_ID to the station rate table */
339 if (new_assoc) {
340 if (priv->iw_mode == NL80211_IFTYPE_STATION) {
341 ret = iwl_rxon_add_station(priv,
342 priv->active_rxon.bssid_addr, 1);
343 if (ret == IWL_INVALID_STATION) {
344 IWL_ERROR("Error adding AP address for TX.\n");
345 return -EIO;
346 }
347 priv->assoc_station_added = 1;
348 if (priv->default_wep_key &&
349 iwl_send_static_wepkey_cmd(priv, 0))
350 IWL_ERROR("Could not send WEP static key.\n");
351 }
352
353 /* Apply the new configuration
354 * RXON assoc doesn't clear the station table in uCode,
355 */
356 ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
357 sizeof(struct iwl_rxon_cmd), &priv->staging_rxon);
358 if (ret) {
359 IWL_ERROR("Error setting new RXON (%d)\n", ret);
360 return ret;
361 }
362 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
363 }
364
365 iwl_init_sensitivity(priv);
366
367 /* If we issue a new RXON command which required a tune then we must
368 * send a new TXPOWER command or we won't be able to Tx any frames */
369 ret = iwl_set_tx_power(priv, priv->tx_power_user_lmt, true);
370 if (ret) {
371 IWL_ERROR("Error sending TX power (%d)\n", ret);
372 return ret;
373 }
374
375 return 0;
376}
377
378void iwl4965_update_chain_flags(struct iwl_priv *priv)
379{
380
381 iwl_set_rxon_chain(priv);
382 iwl4965_commit_rxon(priv);
383}
384
385static int iwl4965_send_bt_config(struct iwl_priv *priv)
386{
387 struct iwl4965_bt_cmd bt_cmd = {
388 .flags = 3,
389 .lead_time = 0xAA,
390 .max_kill = 1,
391 .kill_ack_mask = 0,
392 .kill_cts_mask = 0,
393 };
394
395 return iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG,
396 sizeof(struct iwl4965_bt_cmd), &bt_cmd);
397}
398
399static void iwl_clear_free_frames(struct iwl_priv *priv)
400{
401 struct list_head *element;
402
403 IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
404 priv->frames_count);
405
406 while (!list_empty(&priv->free_frames)) {
407 element = priv->free_frames.next;
408 list_del(element);
409 kfree(list_entry(element, struct iwl_frame, list));
410 priv->frames_count--;
411 }
412
413 if (priv->frames_count) {
414 IWL_WARNING("%d frames still in use. Did we lose one?\n",
415 priv->frames_count);
416 priv->frames_count = 0;
417 }
418}
419
420static struct iwl_frame *iwl_get_free_frame(struct iwl_priv *priv)
421{
422 struct iwl_frame *frame;
423 struct list_head *element;
424 if (list_empty(&priv->free_frames)) {
425 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
426 if (!frame) {
427 IWL_ERROR("Could not allocate frame!\n");
428 return NULL;
429 }
430
431 priv->frames_count++;
432 return frame;
433 }
434
435 element = priv->free_frames.next;
436 list_del(element);
437 return list_entry(element, struct iwl_frame, list);
438}
439
440static void iwl_free_frame(struct iwl_priv *priv, struct iwl_frame *frame)
441{
442 memset(frame, 0, sizeof(*frame));
443 list_add(&frame->list, &priv->free_frames);
444}
445
446static unsigned int iwl_fill_beacon_frame(struct iwl_priv *priv,
447 struct ieee80211_hdr *hdr,
448 const u8 *dest, int left)
449{
450 if (!iwl_is_associated(priv) || !priv->ibss_beacon ||
451 ((priv->iw_mode != NL80211_IFTYPE_ADHOC) &&
452 (priv->iw_mode != NL80211_IFTYPE_AP)))
453 return 0;
454
455 if (priv->ibss_beacon->len > left)
456 return 0;
457
458 memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
459
460 return priv->ibss_beacon->len;
461}
462
463static u8 iwl4965_rate_get_lowest_plcp(struct iwl_priv *priv)
464{
465 int i;
466 int rate_mask;
467
468 /* Set rate mask*/
469 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)
470 rate_mask = priv->active_rate_basic & 0xF;
471 else
472 rate_mask = priv->active_rate_basic & 0xFF0;
473
474 /* Find lowest valid rate */
475 for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID;
476 i = iwl_rates[i].next_ieee) {
477 if (rate_mask & (1 << i))
478 return iwl_rates[i].plcp;
479 }
480
481 /* No valid rate was found. Assign the lowest one */
482 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)
483 return IWL_RATE_1M_PLCP;
484 else
485 return IWL_RATE_6M_PLCP;
486}
487
488static unsigned int iwl4965_hw_get_beacon_cmd(struct iwl_priv *priv,
489 struct iwl_frame *frame, u8 rate)
490{
491 struct iwl_tx_beacon_cmd *tx_beacon_cmd;
492 unsigned int frame_size;
493
494 tx_beacon_cmd = &frame->u.beacon;
495 memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd));
496
497 tx_beacon_cmd->tx.sta_id = priv->hw_params.bcast_sta_id;
498 tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
499
500 frame_size = iwl_fill_beacon_frame(priv, tx_beacon_cmd->frame,
501 iwl_bcast_addr,
502 sizeof(frame->u) - sizeof(*tx_beacon_cmd));
503
504 BUG_ON(frame_size > MAX_MPDU_SIZE);
505 tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
506
507 if ((rate == IWL_RATE_1M_PLCP) || (rate >= IWL_RATE_2M_PLCP))
508 tx_beacon_cmd->tx.rate_n_flags =
509 iwl_hw_set_rate_n_flags(rate, RATE_MCS_CCK_MSK);
510 else
511 tx_beacon_cmd->tx.rate_n_flags =
512 iwl_hw_set_rate_n_flags(rate, 0);
513
514 tx_beacon_cmd->tx.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK |
515 TX_CMD_FLG_TSF_MSK |
516 TX_CMD_FLG_STA_RATE_MSK;
517
518 return sizeof(*tx_beacon_cmd) + frame_size;
519}
520static int iwl4965_send_beacon_cmd(struct iwl_priv *priv)
521{
522 struct iwl_frame *frame;
523 unsigned int frame_size;
524 int rc;
525 u8 rate;
526
527 frame = iwl_get_free_frame(priv);
528
529 if (!frame) {
530 IWL_ERROR("Could not obtain free frame buffer for beacon "
531 "command.\n");
532 return -ENOMEM;
533 }
534
535 rate = iwl4965_rate_get_lowest_plcp(priv);
536
537 frame_size = iwl4965_hw_get_beacon_cmd(priv, frame, rate);
538
539 rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
540 &frame->u.cmd[0]);
541
542 iwl_free_frame(priv, frame);
543
544 return rc;
545}
546
547/******************************************************************************
548 *
549 * Misc. internal state and helper functions
550 *
551 ******************************************************************************/
552
553static void iwl4965_ht_conf(struct iwl_priv *priv,
554 struct ieee80211_bss_conf *bss_conf)
555{
556 struct ieee80211_ht_info *ht_conf = bss_conf->ht_conf;
557 struct ieee80211_ht_bss_info *ht_bss_conf = bss_conf->ht_bss_conf;
558 struct iwl_ht_info *iwl_conf = &priv->current_ht_config;
559
560 IWL_DEBUG_MAC80211("enter: \n");
561
562 iwl_conf->is_ht = bss_conf->assoc_ht;
563
564 if (!iwl_conf->is_ht)
565 return;
566
567 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20)
568 iwl_conf->sgf |= HT_SHORT_GI_20MHZ;
569 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40)
570 iwl_conf->sgf |= HT_SHORT_GI_40MHZ;
571
572 iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD);
573 iwl_conf->max_amsdu_size =
574 !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU);
575
576 iwl_conf->supported_chan_width =
577 !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH);
578 iwl_conf->extension_chan_offset =
579 ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_SEC_OFFSET;
580 /* If no above or below channel supplied disable FAT channel */
581 if (iwl_conf->extension_chan_offset != IEEE80211_HT_IE_CHA_SEC_ABOVE &&
582 iwl_conf->extension_chan_offset != IEEE80211_HT_IE_CHA_SEC_BELOW) {
583 iwl_conf->extension_chan_offset = IEEE80211_HT_IE_CHA_SEC_NONE;
584 iwl_conf->supported_chan_width = 0;
585 }
586
587 iwl_conf->sm_ps = (u8)((ht_conf->cap & IEEE80211_HT_CAP_SM_PS) >> 2);
588
589 memcpy(iwl_conf->supp_mcs_set, ht_conf->supp_mcs_set, 16);
590
591 iwl_conf->control_channel = ht_bss_conf->primary_channel;
592 iwl_conf->tx_chan_width =
593 !!(ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_WIDTH);
594 iwl_conf->ht_protection =
595 ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_HT_PROTECTION;
596 iwl_conf->non_GF_STA_present =
597 !!(ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_NON_GF_STA_PRSNT);
598
599 IWL_DEBUG_MAC80211("control channel %d\n", iwl_conf->control_channel);
600 IWL_DEBUG_MAC80211("leave\n");
601}
602
603/*
604 * QoS support
605*/
606static void iwl_activate_qos(struct iwl_priv *priv, u8 force)
607{
608 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
609 return;
610
611 if (!priv->qos_data.qos_enable)
612 return;
613
614 priv->qos_data.def_qos_parm.qos_flags = 0;
615
616 if (priv->qos_data.qos_cap.q_AP.queue_request &&
617 !priv->qos_data.qos_cap.q_AP.txop_request)
618 priv->qos_data.def_qos_parm.qos_flags |=
619 QOS_PARAM_FLG_TXOP_TYPE_MSK;
620 if (priv->qos_data.qos_active)
621 priv->qos_data.def_qos_parm.qos_flags |=
622 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
623
624 if (priv->current_ht_config.is_ht)
625 priv->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
626
627 if (force || iwl_is_associated(priv)) {
628 IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n",
629 priv->qos_data.qos_active,
630 priv->qos_data.def_qos_parm.qos_flags);
631
632 iwl_send_cmd_pdu_async(priv, REPLY_QOS_PARAM,
633 sizeof(struct iwl_qosparam_cmd),
634 &priv->qos_data.def_qos_parm, NULL);
635 }
636}
637
638#define MAX_UCODE_BEACON_INTERVAL 4096
639
640static __le16 iwl4965_adjust_beacon_interval(u16 beacon_val)
641{
642 u16 new_val = 0;
643 u16 beacon_factor = 0;
644
645 beacon_factor =
646 (beacon_val + MAX_UCODE_BEACON_INTERVAL)
647 / MAX_UCODE_BEACON_INTERVAL;
648 new_val = beacon_val / beacon_factor;
649
650 return cpu_to_le16(new_val);
651}
652
653static void iwl4965_setup_rxon_timing(struct iwl_priv *priv)
654{
655 u64 interval_tm_unit;
656 u64 tsf, result;
657 unsigned long flags;
658 struct ieee80211_conf *conf = NULL;
659 u16 beacon_int = 0;
660
661 conf = ieee80211_get_hw_conf(priv->hw);
662
663 spin_lock_irqsave(&priv->lock, flags);
664 priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp >> 32);
665 priv->rxon_timing.timestamp.dw[0] =
666 cpu_to_le32(priv->timestamp & 0xFFFFFFFF);
667
668 priv->rxon_timing.listen_interval = cpu_to_le16(conf->listen_interval);
669
670 tsf = priv->timestamp;
671
672 beacon_int = priv->beacon_int;
673 spin_unlock_irqrestore(&priv->lock, flags);
674
675 if (priv->iw_mode == NL80211_IFTYPE_STATION) {
676 if (beacon_int == 0) {
677 priv->rxon_timing.beacon_interval = cpu_to_le16(100);
678 priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
679 } else {
680 priv->rxon_timing.beacon_interval =
681 cpu_to_le16(beacon_int);
682 priv->rxon_timing.beacon_interval =
683 iwl4965_adjust_beacon_interval(
684 le16_to_cpu(priv->rxon_timing.beacon_interval));
685 }
686
687 priv->rxon_timing.atim_window = 0;
688 } else {
689 priv->rxon_timing.beacon_interval =
690 iwl4965_adjust_beacon_interval(conf->beacon_int);
691 /* TODO: we need to get atim_window from upper stack
692 * for now we set to 0 */
693 priv->rxon_timing.atim_window = 0;
694 }
695
696 interval_tm_unit =
697 (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024);
698 result = do_div(tsf, interval_tm_unit);
699 priv->rxon_timing.beacon_init_val =
700 cpu_to_le32((u32) ((u64) interval_tm_unit - result));
701
702 IWL_DEBUG_ASSOC
703 ("beacon interval %d beacon timer %d beacon tim %d\n",
704 le16_to_cpu(priv->rxon_timing.beacon_interval),
705 le32_to_cpu(priv->rxon_timing.beacon_init_val),
706 le16_to_cpu(priv->rxon_timing.atim_window));
707}
708
709static void iwl_set_flags_for_band(struct iwl_priv *priv,
710 enum ieee80211_band band)
711{
712 if (band == IEEE80211_BAND_5GHZ) {
713 priv->staging_rxon.flags &=
714 ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
715 | RXON_FLG_CCK_MSK);
716 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
717 } else {
718 /* Copied from iwl4965_post_associate() */
719 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
720 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
721 else
722 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
723
724 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
725 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
726
727 priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
728 priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK;
729 priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK;
730 }
731}
732
733/*
734 * initialize rxon structure with default values from eeprom
735 */
736static void iwl4965_connection_init_rx_config(struct iwl_priv *priv)
737{
738 const struct iwl_channel_info *ch_info;
739
740 memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
741
742 switch (priv->iw_mode) {
743 case NL80211_IFTYPE_AP:
744 priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP;
745 break;
746
747 case NL80211_IFTYPE_STATION:
748 priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS;
749 priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
750 break;
751
752 case NL80211_IFTYPE_ADHOC:
753 priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS;
754 priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
755 priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
756 RXON_FILTER_ACCEPT_GRP_MSK;
757 break;
758
759 case NL80211_IFTYPE_MONITOR:
760 priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER;
761 priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK |
762 RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK;
763 break;
764 default:
765 IWL_ERROR("Unsupported interface type %d\n", priv->iw_mode);
766 break;
767 }
768
769#if 0
770 /* TODO: Figure out when short_preamble would be set and cache from
771 * that */
772 if (!hw_to_local(priv->hw)->short_preamble)
773 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
774 else
775 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
776#endif
777
778 ch_info = iwl_get_channel_info(priv, priv->band,
779 le16_to_cpu(priv->active_rxon.channel));
780
781 if (!ch_info)
782 ch_info = &priv->channel_info[0];
783
784 /*
785 * in some case A channels are all non IBSS
786 * in this case force B/G channel
787 */
788 if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) &&
789 !(is_channel_ibss(ch_info)))
790 ch_info = &priv->channel_info[0];
791
792 priv->staging_rxon.channel = cpu_to_le16(ch_info->channel);
793 priv->band = ch_info->band;
794
795 iwl_set_flags_for_band(priv, priv->band);
796
797 priv->staging_rxon.ofdm_basic_rates =
798 (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
799 priv->staging_rxon.cck_basic_rates =
800 (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
801
802 priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK |
803 RXON_FLG_CHANNEL_MODE_PURE_40_MSK);
804 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
805 memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN);
806 priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff;
807 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff;
808 iwl_set_rxon_chain(priv);
809}
810
811static int iwl4965_set_mode(struct iwl_priv *priv, int mode)
812{
813 priv->iw_mode = mode;
814
815 iwl4965_connection_init_rx_config(priv);
816 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
817
818 iwl_clear_stations_table(priv);
819
820 /* dont commit rxon if rf-kill is on*/
821 if (!iwl_is_ready_rf(priv))
822 return -EAGAIN;
823
824 cancel_delayed_work(&priv->scan_check);
825 if (iwl_scan_cancel_timeout(priv, 100)) {
826 IWL_WARNING("Aborted scan still in progress after 100ms\n");
827 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
828 return -EAGAIN;
829 }
830
831 iwl4965_commit_rxon(priv);
832
833 return 0;
834}
835
836static void iwl4965_set_rate(struct iwl_priv *priv)
837{
838 const struct ieee80211_supported_band *hw = NULL;
839 struct ieee80211_rate *rate;
840 int i;
841
842 hw = iwl_get_hw_mode(priv, priv->band);
843 if (!hw) {
844 IWL_ERROR("Failed to set rate: unable to get hw mode\n");
845 return;
846 }
847
848 priv->active_rate = 0;
849 priv->active_rate_basic = 0;
850
851 for (i = 0; i < hw->n_bitrates; i++) {
852 rate = &(hw->bitrates[i]);
853 if (rate->hw_value < IWL_RATE_COUNT)
854 priv->active_rate |= (1 << rate->hw_value);
855 }
856
857 IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
858 priv->active_rate, priv->active_rate_basic);
859
860 /*
861 * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
862 * otherwise set it to the default of all CCK rates and 6, 12, 24 for
863 * OFDM
864 */
865 if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK)
866 priv->staging_rxon.cck_basic_rates =
867 ((priv->active_rate_basic &
868 IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF;
869 else
870 priv->staging_rxon.cck_basic_rates =
871 (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
872
873 if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK)
874 priv->staging_rxon.ofdm_basic_rates =
875 ((priv->active_rate_basic &
876 (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >>
877 IWL_FIRST_OFDM_RATE) & 0xFF;
878 else
879 priv->staging_rxon.ofdm_basic_rates =
880 (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
881}
882
883#ifdef CONFIG_IWLAGN_SPECTRUM_MEASUREMENT
884
885#include "iwl-spectrum.h"
886
887#define BEACON_TIME_MASK_LOW 0x00FFFFFF
888#define BEACON_TIME_MASK_HIGH 0xFF000000
889#define TIME_UNIT 1024
890
891/*
892 * extended beacon time format
893 * time in usec will be changed into a 32-bit value in 8:24 format
894 * the high 1 byte is the beacon counts
895 * the lower 3 bytes is the time in usec within one beacon interval
896 */
897
898static u32 iwl4965_usecs_to_beacons(u32 usec, u32 beacon_interval)
899{
900 u32 quot;
901 u32 rem;
902 u32 interval = beacon_interval * 1024;
903
904 if (!interval || !usec)
905 return 0;
906
907 quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
908 rem = (usec % interval) & BEACON_TIME_MASK_LOW;
909
910 return (quot << 24) + rem;
911}
912
913/* base is usually what we get from ucode with each received frame,
914 * the same as HW timer counter counting down
915 */
916
917static __le32 iwl4965_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
918{
919 u32 base_low = base & BEACON_TIME_MASK_LOW;
920 u32 addon_low = addon & BEACON_TIME_MASK_LOW;
921 u32 interval = beacon_interval * TIME_UNIT;
922 u32 res = (base & BEACON_TIME_MASK_HIGH) +
923 (addon & BEACON_TIME_MASK_HIGH);
924
925 if (base_low > addon_low)
926 res += base_low - addon_low;
927 else if (base_low < addon_low) {
928 res += interval + base_low - addon_low;
929 res += (1 << 24);
930 } else
931 res += (1 << 24);
932
933 return cpu_to_le32(res);
934}
935
936static int iwl4965_get_measurement(struct iwl_priv *priv,
937 struct ieee80211_measurement_params *params,
938 u8 type)
939{
940 struct iwl4965_spectrum_cmd spectrum;
941 struct iwl_rx_packet *res;
942 struct iwl_host_cmd cmd = {
943 .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
944 .data = (void *)&spectrum,
945 .meta.flags = CMD_WANT_SKB,
946 };
947 u32 add_time = le64_to_cpu(params->start_time);
948 int rc;
949 int spectrum_resp_status;
950 int duration = le16_to_cpu(params->duration);
951
952 if (iwl_is_associated(priv))
953 add_time =
954 iwl4965_usecs_to_beacons(
955 le64_to_cpu(params->start_time) - priv->last_tsf,
956 le16_to_cpu(priv->rxon_timing.beacon_interval));
957
958 memset(&spectrum, 0, sizeof(spectrum));
959
960 spectrum.channel_count = cpu_to_le16(1);
961 spectrum.flags =
962 RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
963 spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
964 cmd.len = sizeof(spectrum);
965 spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
966
967 if (iwl_is_associated(priv))
968 spectrum.start_time =
969 iwl4965_add_beacon_time(priv->last_beacon_time,
970 add_time,
971 le16_to_cpu(priv->rxon_timing.beacon_interval));
972 else
973 spectrum.start_time = 0;
974
975 spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
976 spectrum.channels[0].channel = params->channel;
977 spectrum.channels[0].type = type;
978 if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
979 spectrum.flags |= RXON_FLG_BAND_24G_MSK |
980 RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
981
982 rc = iwl_send_cmd_sync(priv, &cmd);
983 if (rc)
984 return rc;
985
986 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
987 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
988 IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n");
989 rc = -EIO;
990 }
991
992 spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
993 switch (spectrum_resp_status) {
994 case 0: /* Command will be handled */
995 if (res->u.spectrum.id != 0xff) {
996 IWL_DEBUG_INFO
997 ("Replaced existing measurement: %d\n",
998 res->u.spectrum.id);
999 priv->measurement_status &= ~MEASUREMENT_READY;
1000 }
1001 priv->measurement_status |= MEASUREMENT_ACTIVE;
1002 rc = 0;
1003 break;
1004
1005 case 1: /* Command will not be handled */
1006 rc = -EAGAIN;
1007 break;
1008 }
1009
1010 dev_kfree_skb_any(cmd.meta.u.skb);
1011
1012 return rc;
1013}
1014#endif
1015
1016/******************************************************************************
1017 *
1018 * Generic RX handler implementations
1019 *
1020 ******************************************************************************/
1021static void iwl_rx_reply_alive(struct iwl_priv *priv,
1022 struct iwl_rx_mem_buffer *rxb)
1023{
1024 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
1025 struct iwl_alive_resp *palive;
1026 struct delayed_work *pwork;
1027
1028 palive = &pkt->u.alive_frame;
1029
1030 IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
1031 "0x%01X 0x%01X\n",
1032 palive->is_valid, palive->ver_type,
1033 palive->ver_subtype);
1034
1035 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
1036 IWL_DEBUG_INFO("Initialization Alive received.\n");
1037 memcpy(&priv->card_alive_init,
1038 &pkt->u.alive_frame,
1039 sizeof(struct iwl_init_alive_resp));
1040 pwork = &priv->init_alive_start;
1041 } else {
1042 IWL_DEBUG_INFO("Runtime Alive received.\n");
1043 memcpy(&priv->card_alive, &pkt->u.alive_frame,
1044 sizeof(struct iwl_alive_resp));
1045 pwork = &priv->alive_start;
1046 }
1047
1048 /* We delay the ALIVE response by 5ms to
1049 * give the HW RF Kill time to activate... */
1050 if (palive->is_valid == UCODE_VALID_OK)
1051 queue_delayed_work(priv->workqueue, pwork,
1052 msecs_to_jiffies(5));
1053 else
1054 IWL_WARNING("uCode did not respond OK.\n");
1055}
1056
1057static void iwl4965_rx_reply_error(struct iwl_priv *priv,
1058 struct iwl_rx_mem_buffer *rxb)
1059{
1060 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
1061
1062 IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) "
1063 "seq 0x%04X ser 0x%08X\n",
1064 le32_to_cpu(pkt->u.err_resp.error_type),
1065 get_cmd_string(pkt->u.err_resp.cmd_id),
1066 pkt->u.err_resp.cmd_id,
1067 le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
1068 le32_to_cpu(pkt->u.err_resp.error_info));
1069}
1070
1071#define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
1072
1073static void iwl4965_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
1074{
1075 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
1076 struct iwl_rxon_cmd *rxon = (void *)&priv->active_rxon;
1077 struct iwl4965_csa_notification *csa = &(pkt->u.csa_notif);
1078 IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
1079 le16_to_cpu(csa->channel), le32_to_cpu(csa->status));
1080 rxon->channel = csa->channel;
1081 priv->staging_rxon.channel = csa->channel;
1082}
1083
1084static void iwl4965_rx_spectrum_measure_notif(struct iwl_priv *priv,
1085 struct iwl_rx_mem_buffer *rxb)
1086{
1087#ifdef CONFIG_IWLAGN_SPECTRUM_MEASUREMENT
1088 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
1089 struct iwl4965_spectrum_notification *report = &(pkt->u.spectrum_notif);
1090
1091 if (!report->state) {
1092 IWL_DEBUG(IWL_DL_11H,
1093 "Spectrum Measure Notification: Start\n");
1094 return;
1095 }
1096
1097 memcpy(&priv->measure_report, report, sizeof(*report));
1098 priv->measurement_status |= MEASUREMENT_READY;
1099#endif
1100}
1101
1102static void iwl4965_rx_pm_sleep_notif(struct iwl_priv *priv,
1103 struct iwl_rx_mem_buffer *rxb)
1104{
1105#ifdef CONFIG_IWLWIFI_DEBUG
1106 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
1107 struct iwl4965_sleep_notification *sleep = &(pkt->u.sleep_notif);
1108 IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
1109 sleep->pm_sleep_mode, sleep->pm_wakeup_src);
1110#endif
1111}
1112
1113static void iwl4965_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
1114 struct iwl_rx_mem_buffer *rxb)
1115{
1116 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
1117 IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
1118 "notification for %s:\n",
1119 le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd));
1120 iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len));
1121}
1122
1123static void iwl4965_bg_beacon_update(struct work_struct *work)
1124{
1125 struct iwl_priv *priv =
1126 container_of(work, struct iwl_priv, beacon_update);
1127 struct sk_buff *beacon;
1128
1129 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
1130 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
1131
1132 if (!beacon) {
1133 IWL_ERROR("update beacon failed\n");
1134 return;
1135 }
1136
1137 mutex_lock(&priv->mutex);
1138 /* new beacon skb is allocated every time; dispose previous.*/
1139 if (priv->ibss_beacon)
1140 dev_kfree_skb(priv->ibss_beacon);
1141
1142 priv->ibss_beacon = beacon;
1143 mutex_unlock(&priv->mutex);
1144
1145 iwl4965_send_beacon_cmd(priv);
1146}
1147
1148/**
1149 * iwl4965_bg_statistics_periodic - Timer callback to queue statistics
1150 *
1151 * This callback is provided in order to send a statistics request.
1152 *
1153 * This timer function is continually reset to execute within
1154 * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
1155 * was received. We need to ensure we receive the statistics in order
1156 * to update the temperature used for calibrating the TXPOWER.
1157 */
1158static void iwl4965_bg_statistics_periodic(unsigned long data)
1159{
1160 struct iwl_priv *priv = (struct iwl_priv *)data;
1161
1162 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
1163 return;
1164
1165 iwl_send_statistics_request(priv, CMD_ASYNC);
1166}
1167
1168static void iwl4965_rx_beacon_notif(struct iwl_priv *priv,
1169 struct iwl_rx_mem_buffer *rxb)
1170{
1171#ifdef CONFIG_IWLWIFI_DEBUG
1172 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
1173 struct iwl4965_beacon_notif *beacon = &(pkt->u.beacon_status);
1174 u8 rate = iwl_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
1175
1176 IWL_DEBUG_RX("beacon status %x retries %d iss %d "
1177 "tsf %d %d rate %d\n",
1178 le32_to_cpu(beacon->beacon_notify_hdr.u.status) & TX_STATUS_MSK,
1179 beacon->beacon_notify_hdr.failure_frame,
1180 le32_to_cpu(beacon->ibss_mgr_status),
1181 le32_to_cpu(beacon->high_tsf),
1182 le32_to_cpu(beacon->low_tsf), rate);
1183#endif
1184
1185 if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
1186 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
1187 queue_work(priv->workqueue, &priv->beacon_update);
1188}
1189
1190/* Handle notification from uCode that card's power state is changing
1191 * due to software, hardware, or critical temperature RFKILL */
1192static void iwl4965_rx_card_state_notif(struct iwl_priv *priv,
1193 struct iwl_rx_mem_buffer *rxb)
1194{
1195 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
1196 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
1197 unsigned long status = priv->status;
1198
1199 IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
1200 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
1201 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
1202
1203 if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
1204 RF_CARD_DISABLED)) {
1205
1206 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
1207 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
1208
1209 if (!iwl_grab_nic_access(priv)) {
1210 iwl_write_direct32(
1211 priv, HBUS_TARG_MBX_C,
1212 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
1213
1214 iwl_release_nic_access(priv);
1215 }
1216
1217 if (!(flags & RXON_CARD_DISABLED)) {
1218 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
1219 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
1220 if (!iwl_grab_nic_access(priv)) {
1221 iwl_write_direct32(
1222 priv, HBUS_TARG_MBX_C,
1223 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
1224
1225 iwl_release_nic_access(priv);
1226 }
1227 }
1228
1229 if (flags & RF_CARD_DISABLED) {
1230 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
1231 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
1232 iwl_read32(priv, CSR_UCODE_DRV_GP1);
1233 if (!iwl_grab_nic_access(priv))
1234 iwl_release_nic_access(priv);
1235 }
1236 }
1237
1238 if (flags & HW_CARD_DISABLED)
1239 set_bit(STATUS_RF_KILL_HW, &priv->status);
1240 else
1241 clear_bit(STATUS_RF_KILL_HW, &priv->status);
1242
1243
1244 if (flags & SW_CARD_DISABLED)
1245 set_bit(STATUS_RF_KILL_SW, &priv->status);
1246 else
1247 clear_bit(STATUS_RF_KILL_SW, &priv->status);
1248
1249 if (!(flags & RXON_CARD_DISABLED))
1250 iwl_scan_cancel(priv);
1251
1252 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
1253 test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
1254 (test_bit(STATUS_RF_KILL_SW, &status) !=
1255 test_bit(STATUS_RF_KILL_SW, &priv->status)))
1256 queue_work(priv->workqueue, &priv->rf_kill);
1257 else
1258 wake_up_interruptible(&priv->wait_command_queue);
1259}
1260
1261int iwl4965_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src)
1262{
1263 int ret;
1264 unsigned long flags;
1265
1266 spin_lock_irqsave(&priv->lock, flags);
1267 ret = iwl_grab_nic_access(priv);
1268 if (ret)
1269 goto err;
1270
1271 if (src == IWL_PWR_SRC_VAUX) {
1272 u32 val;
1273 ret = pci_read_config_dword(priv->pci_dev, PCI_CFG_POWER_SOURCE,
1274 &val);
1275
1276 if (val & PCI_CFG_PMC_PME_FROM_D3COLD_SUPPORT)
1277 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
1278 APMG_PS_CTRL_VAL_PWR_SRC_VAUX,
1279 ~APMG_PS_CTRL_MSK_PWR_SRC);
1280 } else {
1281 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
1282 APMG_PS_CTRL_VAL_PWR_SRC_VMAIN,
1283 ~APMG_PS_CTRL_MSK_PWR_SRC);
1284 }
1285
1286 iwl_release_nic_access(priv);
1287err:
1288 spin_unlock_irqrestore(&priv->lock, flags);
1289 return ret;
1290}
1291
1292/**
1293 * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks
1294 *
1295 * Setup the RX handlers for each of the reply types sent from the uCode
1296 * to the host.
1297 *
1298 * This function chains into the hardware specific files for them to setup
1299 * any hardware specific handlers as well.
1300 */
1301static void iwl_setup_rx_handlers(struct iwl_priv *priv)
1302{
1303 priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive;
1304 priv->rx_handlers[REPLY_ERROR] = iwl4965_rx_reply_error;
1305 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl4965_rx_csa;
1306 priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
1307 iwl4965_rx_spectrum_measure_notif;
1308 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl4965_rx_pm_sleep_notif;
1309 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
1310 iwl4965_rx_pm_debug_statistics_notif;
1311 priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif;
1312
1313 /*
1314 * The same handler is used for both the REPLY to a discrete
1315 * statistics request from the host as well as for the periodic
1316 * statistics notifications (after received beacons) from the uCode.
1317 */
1318 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl_rx_statistics;
1319 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl_rx_statistics;
1320
1321 iwl_setup_rx_scan_handlers(priv);
1322
1323 /* status change handler */
1324 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl4965_rx_card_state_notif;
1325
1326 priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] =
1327 iwl_rx_missed_beacon_notif;
1328 /* Rx handlers */
1329 priv->rx_handlers[REPLY_RX_PHY_CMD] = iwl_rx_reply_rx_phy;
1330 priv->rx_handlers[REPLY_RX_MPDU_CMD] = iwl_rx_reply_rx;
1331 /* block ack */
1332 priv->rx_handlers[REPLY_COMPRESSED_BA] = iwl_rx_reply_compressed_ba;
1333 /* Set up hardware specific Rx handlers */
1334 priv->cfg->ops->lib->rx_handler_setup(priv);
1335}
1336
1337/*
1338 * this should be called while priv->lock is locked
1339*/
1340static void __iwl_rx_replenish(struct iwl_priv *priv)
1341{
1342 iwl_rx_allocate(priv);
1343 iwl_rx_queue_restock(priv);
1344}
1345
1346
1347/**
1348 * iwl_rx_handle - Main entry function for receiving responses from uCode
1349 *
1350 * Uses the priv->rx_handlers callback function array to invoke
1351 * the appropriate handlers, including command responses,
1352 * frame-received notifications, and other notifications.
1353 */
1354void iwl_rx_handle(struct iwl_priv *priv)
1355{
1356 struct iwl_rx_mem_buffer *rxb;
1357 struct iwl_rx_packet *pkt;
1358 struct iwl_rx_queue *rxq = &priv->rxq;
1359 u32 r, i;
1360 int reclaim;
1361 unsigned long flags;
1362 u8 fill_rx = 0;
1363 u32 count = 8;
1364
1365 /* uCode's read index (stored in shared DRAM) indicates the last Rx
1366 * buffer that the driver may process (last buffer filled by ucode). */
1367 r = priv->cfg->ops->lib->shared_mem_rx_idx(priv);
1368 i = rxq->read;
1369
1370 /* Rx interrupt, but nothing sent from uCode */
1371 if (i == r)
1372 IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d\n", r, i);
1373
1374 if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
1375 fill_rx = 1;
1376
1377 while (i != r) {
1378 rxb = rxq->queue[i];
1379
1380 /* If an RXB doesn't have a Rx queue slot associated with it,
1381 * then a bug has been introduced in the queue refilling
1382 * routines -- catch it here */
1383 BUG_ON(rxb == NULL);
1384
1385 rxq->queue[i] = NULL;
1386
1387 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
1388 priv->hw_params.rx_buf_size,
1389 PCI_DMA_FROMDEVICE);
1390 pkt = (struct iwl_rx_packet *)rxb->skb->data;
1391
1392 /* Reclaim a command buffer only if this packet is a response
1393 * to a (driver-originated) command.
1394 * If the packet (e.g. Rx frame) originated from uCode,
1395 * there is no command buffer to reclaim.
1396 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
1397 * but apparently a few don't get set; catch them here. */
1398 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
1399 (pkt->hdr.cmd != REPLY_RX_PHY_CMD) &&
1400 (pkt->hdr.cmd != REPLY_RX) &&
1401 (pkt->hdr.cmd != REPLY_COMPRESSED_BA) &&
1402 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
1403 (pkt->hdr.cmd != REPLY_TX);
1404
1405 /* Based on type of command response or notification,
1406 * handle those that need handling via function in
1407 * rx_handlers table. See iwl4965_setup_rx_handlers() */
1408 if (priv->rx_handlers[pkt->hdr.cmd]) {
1409 IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d, %s, 0x%02x\n", r,
1410 i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
1411 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
1412 } else {
1413 /* No handling needed */
1414 IWL_DEBUG(IWL_DL_RX,
1415 "r %d i %d No handler needed for %s, 0x%02x\n",
1416 r, i, get_cmd_string(pkt->hdr.cmd),
1417 pkt->hdr.cmd);
1418 }
1419
1420 if (reclaim) {
1421 /* Invoke any callbacks, transfer the skb to caller, and
1422 * fire off the (possibly) blocking iwl_send_cmd()
1423 * as we reclaim the driver command queue */
1424 if (rxb && rxb->skb)
1425 iwl_tx_cmd_complete(priv, rxb);
1426 else
1427 IWL_WARNING("Claim null rxb?\n");
1428 }
1429
1430 /* For now we just don't re-use anything. We can tweak this
1431 * later to try and re-use notification packets and SKBs that
1432 * fail to Rx correctly */
1433 if (rxb->skb != NULL) {
1434 priv->alloc_rxb_skb--;
1435 dev_kfree_skb_any(rxb->skb);
1436 rxb->skb = NULL;
1437 }
1438
1439 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
1440 priv->hw_params.rx_buf_size,
1441 PCI_DMA_FROMDEVICE);
1442 spin_lock_irqsave(&rxq->lock, flags);
1443 list_add_tail(&rxb->list, &priv->rxq.rx_used);
1444 spin_unlock_irqrestore(&rxq->lock, flags);
1445 i = (i + 1) & RX_QUEUE_MASK;
1446 /* If there are a lot of unused frames,
1447 * restock the Rx queue so ucode wont assert. */
1448 if (fill_rx) {
1449 count++;
1450 if (count >= 8) {
1451 priv->rxq.read = i;
1452 __iwl_rx_replenish(priv);
1453 count = 0;
1454 }
1455 }
1456 }
1457
1458 /* Backtrack one entry */
1459 priv->rxq.read = i;
1460 iwl_rx_queue_restock(priv);
1461}
1462
1463#ifdef CONFIG_IWLWIFI_DEBUG
1464static void iwl4965_print_rx_config_cmd(struct iwl_priv *priv)
1465{
1466 struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
1467 DECLARE_MAC_BUF(mac);
1468
1469 IWL_DEBUG_RADIO("RX CONFIG:\n");
1470 iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
1471 IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
1472 IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
1473 IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
1474 le32_to_cpu(rxon->filter_flags));
1475 IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type);
1476 IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
1477 rxon->ofdm_basic_rates);
1478 IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
1479 IWL_DEBUG_RADIO("u8[6] node_addr: %s\n",
1480 print_mac(mac, rxon->node_addr));
1481 IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n",
1482 print_mac(mac, rxon->bssid_addr));
1483 IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
1484}
1485#endif
1486
1487static void iwl4965_enable_interrupts(struct iwl_priv *priv)
1488{
1489 IWL_DEBUG_ISR("Enabling interrupts\n");
1490 set_bit(STATUS_INT_ENABLED, &priv->status);
1491 iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK);
1492}
1493
1494/* call this function to flush any scheduled tasklet */
1495static inline void iwl_synchronize_irq(struct iwl_priv *priv)
1496{
1497 /* wait to make sure we flush pedding tasklet*/
1498 synchronize_irq(priv->pci_dev->irq);
1499 tasklet_kill(&priv->irq_tasklet);
1500}
1501
1502static inline void iwl4965_disable_interrupts(struct iwl_priv *priv)
1503{
1504 clear_bit(STATUS_INT_ENABLED, &priv->status);
1505
1506 /* disable interrupts from uCode/NIC to host */
1507 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
1508
1509 /* acknowledge/clear/reset any interrupts still pending
1510 * from uCode or flow handler (Rx/Tx DMA) */
1511 iwl_write32(priv, CSR_INT, 0xffffffff);
1512 iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff);
1513 IWL_DEBUG_ISR("Disabled interrupts\n");
1514}
1515
1516
1517/**
1518 * iwl4965_irq_handle_error - called for HW or SW error interrupt from card
1519 */
1520static void iwl4965_irq_handle_error(struct iwl_priv *priv)
1521{
1522 /* Set the FW error flag -- cleared on iwl4965_down */
1523 set_bit(STATUS_FW_ERROR, &priv->status);
1524
1525 /* Cancel currently queued command. */
1526 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
1527
1528#ifdef CONFIG_IWLWIFI_DEBUG
1529 if (priv->debug_level & IWL_DL_FW_ERRORS) {
1530 iwl_dump_nic_error_log(priv);
1531 iwl_dump_nic_event_log(priv);
1532 iwl4965_print_rx_config_cmd(priv);
1533 }
1534#endif
1535
1536 wake_up_interruptible(&priv->wait_command_queue);
1537
1538 /* Keep the restart process from trying to send host
1539 * commands by clearing the INIT status bit */
1540 clear_bit(STATUS_READY, &priv->status);
1541
1542 if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
1543 IWL_DEBUG(IWL_DL_FW_ERRORS,
1544 "Restarting adapter due to uCode error.\n");
1545
1546 if (iwl_is_associated(priv)) {
1547 memcpy(&priv->recovery_rxon, &priv->active_rxon,
1548 sizeof(priv->recovery_rxon));
1549 priv->error_recovering = 1;
1550 }
1551 if (priv->cfg->mod_params->restart_fw)
1552 queue_work(priv->workqueue, &priv->restart);
1553 }
1554}
1555
1556static void iwl4965_error_recovery(struct iwl_priv *priv)
1557{
1558 unsigned long flags;
1559
1560 memcpy(&priv->staging_rxon, &priv->recovery_rxon,
1561 sizeof(priv->staging_rxon));
1562 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
1563 iwl4965_commit_rxon(priv);
1564
1565 iwl_rxon_add_station(priv, priv->bssid, 1);
1566
1567 spin_lock_irqsave(&priv->lock, flags);
1568 priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
1569 priv->error_recovering = 0;
1570 spin_unlock_irqrestore(&priv->lock, flags);
1571}
1572
1573static void iwl4965_irq_tasklet(struct iwl_priv *priv)
1574{
1575 u32 inta, handled = 0;
1576 u32 inta_fh;
1577 unsigned long flags;
1578#ifdef CONFIG_IWLWIFI_DEBUG
1579 u32 inta_mask;
1580#endif
1581
1582 spin_lock_irqsave(&priv->lock, flags);
1583
1584 /* Ack/clear/reset pending uCode interrupts.
1585 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
1586 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
1587 inta = iwl_read32(priv, CSR_INT);
1588 iwl_write32(priv, CSR_INT, inta);
1589
1590 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
1591 * Any new interrupts that happen after this, either while we're
1592 * in this tasklet, or later, will show up in next ISR/tasklet. */
1593 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
1594 iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
1595
1596#ifdef CONFIG_IWLWIFI_DEBUG
1597 if (priv->debug_level & IWL_DL_ISR) {
1598 /* just for debug */
1599 inta_mask = iwl_read32(priv, CSR_INT_MASK);
1600 IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
1601 inta, inta_mask, inta_fh);
1602 }
1603#endif
1604
1605 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
1606 * atomic, make sure that inta covers all the interrupts that
1607 * we've discovered, even if FH interrupt came in just after
1608 * reading CSR_INT. */
1609 if (inta_fh & CSR49_FH_INT_RX_MASK)
1610 inta |= CSR_INT_BIT_FH_RX;
1611 if (inta_fh & CSR49_FH_INT_TX_MASK)
1612 inta |= CSR_INT_BIT_FH_TX;
1613
1614 /* Now service all interrupt bits discovered above. */
1615 if (inta & CSR_INT_BIT_HW_ERR) {
1616 IWL_ERROR("Microcode HW error detected. Restarting.\n");
1617
1618 /* Tell the device to stop sending interrupts */
1619 iwl4965_disable_interrupts(priv);
1620
1621 iwl4965_irq_handle_error(priv);
1622
1623 handled |= CSR_INT_BIT_HW_ERR;
1624
1625 spin_unlock_irqrestore(&priv->lock, flags);
1626
1627 return;
1628 }
1629
1630#ifdef CONFIG_IWLWIFI_DEBUG
1631 if (priv->debug_level & (IWL_DL_ISR)) {
1632 /* NIC fires this, but we don't use it, redundant with WAKEUP */
1633 if (inta & CSR_INT_BIT_SCD)
1634 IWL_DEBUG_ISR("Scheduler finished to transmit "
1635 "the frame/frames.\n");
1636
1637 /* Alive notification via Rx interrupt will do the real work */
1638 if (inta & CSR_INT_BIT_ALIVE)
1639 IWL_DEBUG_ISR("Alive interrupt\n");
1640 }
1641#endif
1642 /* Safely ignore these bits for debug checks below */
1643 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
1644
1645 /* HW RF KILL switch toggled */
1646 if (inta & CSR_INT_BIT_RF_KILL) {
1647 int hw_rf_kill = 0;
1648 if (!(iwl_read32(priv, CSR_GP_CNTRL) &
1649 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
1650 hw_rf_kill = 1;
1651
1652 IWL_DEBUG(IWL_DL_RF_KILL, "RF_KILL bit toggled to %s.\n",
1653 hw_rf_kill ? "disable radio":"enable radio");
1654
1655 /* driver only loads ucode once setting the interface up.
1656 * the driver as well won't allow loading if RFKILL is set
1657 * therefore no need to restart the driver from this handler
1658 */
1659 if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status))
1660 clear_bit(STATUS_RF_KILL_HW, &priv->status);
1661
1662 handled |= CSR_INT_BIT_RF_KILL;
1663 }
1664
1665 /* Chip got too hot and stopped itself */
1666 if (inta & CSR_INT_BIT_CT_KILL) {
1667 IWL_ERROR("Microcode CT kill error detected.\n");
1668 handled |= CSR_INT_BIT_CT_KILL;
1669 }
1670
1671 /* Error detected by uCode */
1672 if (inta & CSR_INT_BIT_SW_ERR) {
1673 IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n",
1674 inta);
1675 iwl4965_irq_handle_error(priv);
1676 handled |= CSR_INT_BIT_SW_ERR;
1677 }
1678
1679 /* uCode wakes up after power-down sleep */
1680 if (inta & CSR_INT_BIT_WAKEUP) {
1681 IWL_DEBUG_ISR("Wakeup interrupt\n");
1682 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
1683 iwl_txq_update_write_ptr(priv, &priv->txq[0]);
1684 iwl_txq_update_write_ptr(priv, &priv->txq[1]);
1685 iwl_txq_update_write_ptr(priv, &priv->txq[2]);
1686 iwl_txq_update_write_ptr(priv, &priv->txq[3]);
1687 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
1688 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
1689
1690 handled |= CSR_INT_BIT_WAKEUP;
1691 }
1692
1693 /* All uCode command responses, including Tx command responses,
1694 * Rx "responses" (frame-received notification), and other
1695 * notifications from uCode come through here*/
1696 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
1697 iwl_rx_handle(priv);
1698 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
1699 }
1700
1701 if (inta & CSR_INT_BIT_FH_TX) {
1702 IWL_DEBUG_ISR("Tx interrupt\n");
1703 handled |= CSR_INT_BIT_FH_TX;
1704 /* FH finished to write, send event */
1705 priv->ucode_write_complete = 1;
1706 wake_up_interruptible(&priv->wait_command_queue);
1707 }
1708
1709 if (inta & ~handled)
1710 IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
1711
1712 if (inta & ~CSR_INI_SET_MASK) {
1713 IWL_WARNING("Disabled INTA bits 0x%08x were pending\n",
1714 inta & ~CSR_INI_SET_MASK);
1715 IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh);
1716 }
1717
1718 /* Re-enable all interrupts */
1719 /* only Re-enable if diabled by irq */
1720 if (test_bit(STATUS_INT_ENABLED, &priv->status))
1721 iwl4965_enable_interrupts(priv);
1722
1723#ifdef CONFIG_IWLWIFI_DEBUG
1724 if (priv->debug_level & (IWL_DL_ISR)) {
1725 inta = iwl_read32(priv, CSR_INT);
1726 inta_mask = iwl_read32(priv, CSR_INT_MASK);
1727 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
1728 IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
1729 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
1730 }
1731#endif
1732 spin_unlock_irqrestore(&priv->lock, flags);
1733}
1734
1735static irqreturn_t iwl4965_isr(int irq, void *data)
1736{
1737 struct iwl_priv *priv = data;
1738 u32 inta, inta_mask;
1739 u32 inta_fh;
1740 if (!priv)
1741 return IRQ_NONE;
1742
1743 spin_lock(&priv->lock);
1744
1745 /* Disable (but don't clear!) interrupts here to avoid
1746 * back-to-back ISRs and sporadic interrupts from our NIC.
1747 * If we have something to service, the tasklet will re-enable ints.
1748 * If we *don't* have something, we'll re-enable before leaving here. */
1749 inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
1750 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
1751
1752 /* Discover which interrupts are active/pending */
1753 inta = iwl_read32(priv, CSR_INT);
1754 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
1755
1756 /* Ignore interrupt if there's nothing in NIC to service.
1757 * This may be due to IRQ shared with another device,
1758 * or due to sporadic interrupts thrown from our NIC. */
1759 if (!inta && !inta_fh) {
1760 IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
1761 goto none;
1762 }
1763
1764 if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
1765 /* Hardware disappeared. It might have already raised
1766 * an interrupt */
1767 IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta);
1768 goto unplugged;
1769 }
1770
1771 IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
1772 inta, inta_mask, inta_fh);
1773
1774 inta &= ~CSR_INT_BIT_SCD;
1775
1776 /* iwl4965_irq_tasklet() will service interrupts and re-enable them */
1777 if (likely(inta || inta_fh))
1778 tasklet_schedule(&priv->irq_tasklet);
1779
1780 unplugged:
1781 spin_unlock(&priv->lock);
1782 return IRQ_HANDLED;
1783
1784 none:
1785 /* re-enable interrupts here since we don't have anything to service. */
1786 /* only Re-enable if diabled by irq */
1787 if (test_bit(STATUS_INT_ENABLED, &priv->status))
1788 iwl4965_enable_interrupts(priv);
1789 spin_unlock(&priv->lock);
1790 return IRQ_NONE;
1791}
1792
1793/******************************************************************************
1794 *
1795 * uCode download functions
1796 *
1797 ******************************************************************************/
1798
1799static void iwl4965_dealloc_ucode_pci(struct iwl_priv *priv)
1800{
1801 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
1802 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
1803 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
1804 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
1805 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
1806 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
1807}
1808
1809static void iwl4965_nic_start(struct iwl_priv *priv)
1810{
1811 /* Remove all resets to allow NIC to operate */
1812 iwl_write32(priv, CSR_RESET, 0);
1813}
1814
1815
1816/**
1817 * iwl4965_read_ucode - Read uCode images from disk file.
1818 *
1819 * Copy into buffers for card to fetch via bus-mastering
1820 */
1821static int iwl4965_read_ucode(struct iwl_priv *priv)
1822{
1823 struct iwl_ucode *ucode;
1824 int ret;
1825 const struct firmware *ucode_raw;
1826 const char *name = priv->cfg->fw_name;
1827 u8 *src;
1828 size_t len;
1829 u32 ver, inst_size, data_size, init_size, init_data_size, boot_size;
1830
1831 /* Ask kernel firmware_class module to get the boot firmware off disk.
1832 * request_firmware() is synchronous, file is in memory on return. */
1833 ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev);
1834 if (ret < 0) {
1835 IWL_ERROR("%s firmware file req failed: Reason %d\n",
1836 name, ret);
1837 goto error;
1838 }
1839
1840 IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
1841 name, ucode_raw->size);
1842
1843 /* Make sure that we got at least our header! */
1844 if (ucode_raw->size < sizeof(*ucode)) {
1845 IWL_ERROR("File size way too small!\n");
1846 ret = -EINVAL;
1847 goto err_release;
1848 }
1849
1850 /* Data from ucode file: header followed by uCode images */
1851 ucode = (void *)ucode_raw->data;
1852
1853 ver = le32_to_cpu(ucode->ver);
1854 inst_size = le32_to_cpu(ucode->inst_size);
1855 data_size = le32_to_cpu(ucode->data_size);
1856 init_size = le32_to_cpu(ucode->init_size);
1857 init_data_size = le32_to_cpu(ucode->init_data_size);
1858 boot_size = le32_to_cpu(ucode->boot_size);
1859
1860 IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver);
1861 IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n",
1862 inst_size);
1863 IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n",
1864 data_size);
1865 IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n",
1866 init_size);
1867 IWL_DEBUG_INFO("f/w package hdr init data size = %u\n",
1868 init_data_size);
1869 IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n",
1870 boot_size);
1871
1872 /* Verify size of file vs. image size info in file's header */
1873 if (ucode_raw->size < sizeof(*ucode) +
1874 inst_size + data_size + init_size +
1875 init_data_size + boot_size) {
1876
1877 IWL_DEBUG_INFO("uCode file size %d too small\n",
1878 (int)ucode_raw->size);
1879 ret = -EINVAL;
1880 goto err_release;
1881 }
1882
1883 /* Verify that uCode images will fit in card's SRAM */
1884 if (inst_size > priv->hw_params.max_inst_size) {
1885 IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
1886 inst_size);
1887 ret = -EINVAL;
1888 goto err_release;
1889 }
1890
1891 if (data_size > priv->hw_params.max_data_size) {
1892 IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
1893 data_size);
1894 ret = -EINVAL;
1895 goto err_release;
1896 }
1897 if (init_size > priv->hw_params.max_inst_size) {
1898 IWL_DEBUG_INFO
1899 ("uCode init instr len %d too large to fit in\n",
1900 init_size);
1901 ret = -EINVAL;
1902 goto err_release;
1903 }
1904 if (init_data_size > priv->hw_params.max_data_size) {
1905 IWL_DEBUG_INFO
1906 ("uCode init data len %d too large to fit in\n",
1907 init_data_size);
1908 ret = -EINVAL;
1909 goto err_release;
1910 }
1911 if (boot_size > priv->hw_params.max_bsm_size) {
1912 IWL_DEBUG_INFO
1913 ("uCode boot instr len %d too large to fit in\n",
1914 boot_size);
1915 ret = -EINVAL;
1916 goto err_release;
1917 }
1918
1919 /* Allocate ucode buffers for card's bus-master loading ... */
1920
1921 /* Runtime instructions and 2 copies of data:
1922 * 1) unmodified from disk
1923 * 2) backup cache for save/restore during power-downs */
1924 priv->ucode_code.len = inst_size;
1925 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
1926
1927 priv->ucode_data.len = data_size;
1928 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
1929
1930 priv->ucode_data_backup.len = data_size;
1931 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
1932
1933 /* Initialization instructions and data */
1934 if (init_size && init_data_size) {
1935 priv->ucode_init.len = init_size;
1936 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
1937
1938 priv->ucode_init_data.len = init_data_size;
1939 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
1940
1941 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
1942 goto err_pci_alloc;
1943 }
1944
1945 /* Bootstrap (instructions only, no data) */
1946 if (boot_size) {
1947 priv->ucode_boot.len = boot_size;
1948 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
1949
1950 if (!priv->ucode_boot.v_addr)
1951 goto err_pci_alloc;
1952 }
1953
1954 /* Copy images into buffers for card's bus-master reads ... */
1955
1956 /* Runtime instructions (first block of data in file) */
1957 src = &ucode->data[0];
1958 len = priv->ucode_code.len;
1959 IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len);
1960 memcpy(priv->ucode_code.v_addr, src, len);
1961 IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
1962 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
1963
1964 /* Runtime data (2nd block)
1965 * NOTE: Copy into backup buffer will be done in iwl4965_up() */
1966 src = &ucode->data[inst_size];
1967 len = priv->ucode_data.len;
1968 IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len);
1969 memcpy(priv->ucode_data.v_addr, src, len);
1970 memcpy(priv->ucode_data_backup.v_addr, src, len);
1971
1972 /* Initialization instructions (3rd block) */
1973 if (init_size) {
1974 src = &ucode->data[inst_size + data_size];
1975 len = priv->ucode_init.len;
1976 IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
1977 len);
1978 memcpy(priv->ucode_init.v_addr, src, len);
1979 }
1980
1981 /* Initialization data (4th block) */
1982 if (init_data_size) {
1983 src = &ucode->data[inst_size + data_size + init_size];
1984 len = priv->ucode_init_data.len;
1985 IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n",
1986 len);
1987 memcpy(priv->ucode_init_data.v_addr, src, len);
1988 }
1989
1990 /* Bootstrap instructions (5th block) */
1991 src = &ucode->data[inst_size + data_size + init_size + init_data_size];
1992 len = priv->ucode_boot.len;
1993 IWL_DEBUG_INFO("Copying (but not loading) boot instr len %Zd\n", len);
1994 memcpy(priv->ucode_boot.v_addr, src, len);
1995
1996 /* We have our copies now, allow OS release its copies */
1997 release_firmware(ucode_raw);
1998 return 0;
1999
2000 err_pci_alloc:
2001 IWL_ERROR("failed to allocate pci memory\n");
2002 ret = -ENOMEM;
2003 iwl4965_dealloc_ucode_pci(priv);
2004
2005 err_release:
2006 release_firmware(ucode_raw);
2007
2008 error:
2009 return ret;
2010}
2011
2012/**
2013 * iwl_alive_start - called after REPLY_ALIVE notification received
2014 * from protocol/runtime uCode (initialization uCode's
2015 * Alive gets handled by iwl_init_alive_start()).
2016 */
2017static void iwl_alive_start(struct iwl_priv *priv)
2018{
2019 int ret = 0;
2020
2021 IWL_DEBUG_INFO("Runtime Alive received.\n");
2022
2023 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
2024 /* We had an error bringing up the hardware, so take it
2025 * all the way back down so we can try again */
2026 IWL_DEBUG_INFO("Alive failed.\n");
2027 goto restart;
2028 }
2029
2030 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
2031 * This is a paranoid check, because we would not have gotten the
2032 * "runtime" alive if code weren't properly loaded. */
2033 if (iwl_verify_ucode(priv)) {
2034 /* Runtime instruction load was bad;
2035 * take it all the way back down so we can try again */
2036 IWL_DEBUG_INFO("Bad runtime uCode load.\n");
2037 goto restart;
2038 }
2039
2040 iwl_clear_stations_table(priv);
2041 ret = priv->cfg->ops->lib->alive_notify(priv);
2042 if (ret) {
2043 IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n",
2044 ret);
2045 goto restart;
2046 }
2047
2048 /* After the ALIVE response, we can send host commands to 4965 uCode */
2049 set_bit(STATUS_ALIVE, &priv->status);
2050
2051 if (iwl_is_rfkill(priv))
2052 return;
2053
2054 ieee80211_wake_queues(priv->hw);
2055
2056 priv->active_rate = priv->rates_mask;
2057 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
2058
2059 if (iwl_is_associated(priv)) {
2060 struct iwl_rxon_cmd *active_rxon =
2061 (struct iwl_rxon_cmd *)&priv->active_rxon;
2062
2063 memcpy(&priv->staging_rxon, &priv->active_rxon,
2064 sizeof(priv->staging_rxon));
2065 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2066 } else {
2067 /* Initialize our rx_config data */
2068 iwl4965_connection_init_rx_config(priv);
2069 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
2070 }
2071
2072 /* Configure Bluetooth device coexistence support */
2073 iwl4965_send_bt_config(priv);
2074
2075 iwl_reset_run_time_calib(priv);
2076
2077 /* Configure the adapter for unassociated operation */
2078 iwl4965_commit_rxon(priv);
2079
2080 /* At this point, the NIC is initialized and operational */
2081 iwl_rf_kill_ct_config(priv);
2082
2083 iwl_leds_register(priv);
2084
2085 IWL_DEBUG_INFO("ALIVE processing complete.\n");
2086 set_bit(STATUS_READY, &priv->status);
2087 wake_up_interruptible(&priv->wait_command_queue);
2088
2089 if (priv->error_recovering)
2090 iwl4965_error_recovery(priv);
2091
2092 iwl_power_update_mode(priv, 1);
2093 ieee80211_notify_mac(priv->hw, IEEE80211_NOTIFY_RE_ASSOC);
2094
2095 if (test_and_clear_bit(STATUS_MODE_PENDING, &priv->status))
2096 iwl4965_set_mode(priv, priv->iw_mode);
2097
2098 return;
2099
2100 restart:
2101 queue_work(priv->workqueue, &priv->restart);
2102}
2103
2104static void iwl_cancel_deferred_work(struct iwl_priv *priv);
2105
2106static void __iwl4965_down(struct iwl_priv *priv)
2107{
2108 unsigned long flags;
2109 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
2110
2111 IWL_DEBUG_INFO(DRV_NAME " is going down\n");
2112
2113 if (!exit_pending)
2114 set_bit(STATUS_EXIT_PENDING, &priv->status);
2115
2116 iwl_leds_unregister(priv);
2117
2118 iwl_clear_stations_table(priv);
2119
2120 /* Unblock any waiting calls */
2121 wake_up_interruptible_all(&priv->wait_command_queue);
2122
2123 /* Wipe out the EXIT_PENDING status bit if we are not actually
2124 * exiting the module */
2125 if (!exit_pending)
2126 clear_bit(STATUS_EXIT_PENDING, &priv->status);
2127
2128 /* stop and reset the on-board processor */
2129 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
2130
2131 /* tell the device to stop sending interrupts */
2132 spin_lock_irqsave(&priv->lock, flags);
2133 iwl4965_disable_interrupts(priv);
2134 spin_unlock_irqrestore(&priv->lock, flags);
2135 iwl_synchronize_irq(priv);
2136
2137 if (priv->mac80211_registered)
2138 ieee80211_stop_queues(priv->hw);
2139
2140 /* If we have not previously called iwl4965_init() then
2141 * clear all bits but the RF Kill and SUSPEND bits and return */
2142 if (!iwl_is_init(priv)) {
2143 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
2144 STATUS_RF_KILL_HW |
2145 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
2146 STATUS_RF_KILL_SW |
2147 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2148 STATUS_GEO_CONFIGURED |
2149 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
2150 STATUS_IN_SUSPEND |
2151 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
2152 STATUS_EXIT_PENDING;
2153 goto exit;
2154 }
2155
2156 /* ...otherwise clear out all the status bits but the RF Kill and
2157 * SUSPEND bits and continue taking the NIC down. */
2158 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
2159 STATUS_RF_KILL_HW |
2160 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
2161 STATUS_RF_KILL_SW |
2162 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2163 STATUS_GEO_CONFIGURED |
2164 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
2165 STATUS_IN_SUSPEND |
2166 test_bit(STATUS_FW_ERROR, &priv->status) <<
2167 STATUS_FW_ERROR |
2168 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
2169 STATUS_EXIT_PENDING;
2170
2171 spin_lock_irqsave(&priv->lock, flags);
2172 iwl_clear_bit(priv, CSR_GP_CNTRL,
2173 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
2174 spin_unlock_irqrestore(&priv->lock, flags);
2175
2176 iwl_txq_ctx_stop(priv);
2177 iwl_rxq_stop(priv);
2178
2179 spin_lock_irqsave(&priv->lock, flags);
2180 if (!iwl_grab_nic_access(priv)) {
2181 iwl_write_prph(priv, APMG_CLK_DIS_REG,
2182 APMG_CLK_VAL_DMA_CLK_RQT);
2183 iwl_release_nic_access(priv);
2184 }
2185 spin_unlock_irqrestore(&priv->lock, flags);
2186
2187 udelay(5);
2188
2189 /* FIXME: apm_ops.suspend(priv) */
2190 if (exit_pending || test_bit(STATUS_IN_SUSPEND, &priv->status))
2191 priv->cfg->ops->lib->apm_ops.stop(priv);
2192 else
2193 priv->cfg->ops->lib->apm_ops.reset(priv);
2194 priv->cfg->ops->lib->free_shared_mem(priv);
2195
2196 exit:
2197 memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
2198
2199 if (priv->ibss_beacon)
2200 dev_kfree_skb(priv->ibss_beacon);
2201 priv->ibss_beacon = NULL;
2202
2203 /* clear out any free frames */
2204 iwl_clear_free_frames(priv);
2205}
2206
2207static void iwl4965_down(struct iwl_priv *priv)
2208{
2209 mutex_lock(&priv->mutex);
2210 __iwl4965_down(priv);
2211 mutex_unlock(&priv->mutex);
2212
2213 iwl_cancel_deferred_work(priv);
2214}
2215
2216#define MAX_HW_RESTARTS 5
2217
2218static int __iwl4965_up(struct iwl_priv *priv)
2219{
2220 int i;
2221 int ret;
2222
2223 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
2224 IWL_WARNING("Exit pending; will not bring the NIC up\n");
2225 return -EIO;
2226 }
2227
2228 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
2229 IWL_ERROR("ucode not available for device bringup\n");
2230 return -EIO;
2231 }
2232
2233 /* If platform's RF_KILL switch is NOT set to KILL */
2234 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
2235 clear_bit(STATUS_RF_KILL_HW, &priv->status);
2236 else
2237 set_bit(STATUS_RF_KILL_HW, &priv->status);
2238
2239 if (iwl_is_rfkill(priv)) {
2240 iwl4965_enable_interrupts(priv);
2241 IWL_WARNING("Radio disabled by %s RF Kill switch\n",
2242 test_bit(STATUS_RF_KILL_HW, &priv->status) ? "HW" : "SW");
2243 return 0;
2244 }
2245
2246 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
2247
2248 ret = priv->cfg->ops->lib->alloc_shared_mem(priv);
2249 if (ret) {
2250 IWL_ERROR("Unable to allocate shared memory\n");
2251 return ret;
2252 }
2253
2254 ret = iwl_hw_nic_init(priv);
2255 if (ret) {
2256 IWL_ERROR("Unable to init nic\n");
2257 return ret;
2258 }
2259
2260 /* make sure rfkill handshake bits are cleared */
2261 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2262 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
2263 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
2264
2265 /* clear (again), then enable host interrupts */
2266 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
2267 iwl4965_enable_interrupts(priv);
2268
2269 /* really make sure rfkill handshake bits are cleared */
2270 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2271 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2272
2273 /* Copy original ucode data image from disk into backup cache.
2274 * This will be used to initialize the on-board processor's
2275 * data SRAM for a clean start when the runtime program first loads. */
2276 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
2277 priv->ucode_data.len);
2278
2279 for (i = 0; i < MAX_HW_RESTARTS; i++) {
2280
2281 iwl_clear_stations_table(priv);
2282
2283 /* load bootstrap state machine,
2284 * load bootstrap program into processor's memory,
2285 * prepare to load the "initialize" uCode */
2286 ret = priv->cfg->ops->lib->load_ucode(priv);
2287
2288 if (ret) {
2289 IWL_ERROR("Unable to set up bootstrap uCode: %d\n", ret);
2290 continue;
2291 }
2292
2293 /* Clear out the uCode error bit if it is set */
2294 clear_bit(STATUS_FW_ERROR, &priv->status);
2295
2296 /* start card; "initialize" will load runtime ucode */
2297 iwl4965_nic_start(priv);
2298
2299 IWL_DEBUG_INFO(DRV_NAME " is coming up\n");
2300
2301 return 0;
2302 }
2303
2304 set_bit(STATUS_EXIT_PENDING, &priv->status);
2305 __iwl4965_down(priv);
2306 clear_bit(STATUS_EXIT_PENDING, &priv->status);
2307
2308 /* tried to restart and config the device for as long as our
2309 * patience could withstand */
2310 IWL_ERROR("Unable to initialize device after %d attempts.\n", i);
2311 return -EIO;
2312}
2313
2314
2315/*****************************************************************************
2316 *
2317 * Workqueue callbacks
2318 *
2319 *****************************************************************************/
2320
2321static void iwl_bg_init_alive_start(struct work_struct *data)
2322{
2323 struct iwl_priv *priv =
2324 container_of(data, struct iwl_priv, init_alive_start.work);
2325
2326 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2327 return;
2328
2329 mutex_lock(&priv->mutex);
2330 priv->cfg->ops->lib->init_alive_start(priv);
2331 mutex_unlock(&priv->mutex);
2332}
2333
2334static void iwl_bg_alive_start(struct work_struct *data)
2335{
2336 struct iwl_priv *priv =
2337 container_of(data, struct iwl_priv, alive_start.work);
2338
2339 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2340 return;
2341
2342 mutex_lock(&priv->mutex);
2343 iwl_alive_start(priv);
2344 mutex_unlock(&priv->mutex);
2345}
2346
2347static void iwl4965_bg_rf_kill(struct work_struct *work)
2348{
2349 struct iwl_priv *priv = container_of(work, struct iwl_priv, rf_kill);
2350
2351 wake_up_interruptible(&priv->wait_command_queue);
2352
2353 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2354 return;
2355
2356 mutex_lock(&priv->mutex);
2357
2358 if (!iwl_is_rfkill(priv)) {
2359 IWL_DEBUG(IWL_DL_RF_KILL,
2360 "HW and/or SW RF Kill no longer active, restarting "
2361 "device\n");
2362 if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
2363 queue_work(priv->workqueue, &priv->restart);
2364 } else {
2365 /* make sure mac80211 stop sending Tx frame */
2366 if (priv->mac80211_registered)
2367 ieee80211_stop_queues(priv->hw);
2368
2369 if (!test_bit(STATUS_RF_KILL_HW, &priv->status))
2370 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
2371 "disabled by SW switch\n");
2372 else
2373 IWL_WARNING("Radio Frequency Kill Switch is On:\n"
2374 "Kill switch must be turned off for "
2375 "wireless networking to work.\n");
2376 }
2377 mutex_unlock(&priv->mutex);
2378 iwl_rfkill_set_hw_state(priv);
2379}
2380
2381static void iwl4965_bg_set_monitor(struct work_struct *work)
2382{
2383 struct iwl_priv *priv = container_of(work,
2384 struct iwl_priv, set_monitor);
2385 int ret;
2386
2387 IWL_DEBUG(IWL_DL_STATE, "setting monitor mode\n");
2388
2389 mutex_lock(&priv->mutex);
2390
2391 ret = iwl4965_set_mode(priv, NL80211_IFTYPE_MONITOR);
2392
2393 if (ret) {
2394 if (ret == -EAGAIN)
2395 IWL_DEBUG(IWL_DL_STATE, "leave - not ready\n");
2396 else
2397 IWL_ERROR("iwl4965_set_mode() failed ret = %d\n", ret);
2398 }
2399
2400 mutex_unlock(&priv->mutex);
2401}
2402
2403static void iwl_bg_run_time_calib_work(struct work_struct *work)
2404{
2405 struct iwl_priv *priv = container_of(work, struct iwl_priv,
2406 run_time_calib_work);
2407
2408 mutex_lock(&priv->mutex);
2409
2410 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
2411 test_bit(STATUS_SCANNING, &priv->status)) {
2412 mutex_unlock(&priv->mutex);
2413 return;
2414 }
2415
2416 if (priv->start_calib) {
2417 iwl_chain_noise_calibration(priv, &priv->statistics);
2418
2419 iwl_sensitivity_calibration(priv, &priv->statistics);
2420 }
2421
2422 mutex_unlock(&priv->mutex);
2423 return;
2424}
2425
2426static void iwl4965_bg_up(struct work_struct *data)
2427{
2428 struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
2429
2430 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2431 return;
2432
2433 mutex_lock(&priv->mutex);
2434 __iwl4965_up(priv);
2435 mutex_unlock(&priv->mutex);
2436 iwl_rfkill_set_hw_state(priv);
2437}
2438
2439static void iwl4965_bg_restart(struct work_struct *data)
2440{
2441 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
2442
2443 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2444 return;
2445
2446 iwl4965_down(priv);
2447 queue_work(priv->workqueue, &priv->up);
2448}
2449
2450static void iwl4965_bg_rx_replenish(struct work_struct *data)
2451{
2452 struct iwl_priv *priv =
2453 container_of(data, struct iwl_priv, rx_replenish);
2454
2455 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2456 return;
2457
2458 mutex_lock(&priv->mutex);
2459 iwl_rx_replenish(priv);
2460 mutex_unlock(&priv->mutex);
2461}
2462
2463#define IWL_DELAY_NEXT_SCAN (HZ*2)
2464
2465static void iwl4965_post_associate(struct iwl_priv *priv)
2466{
2467 struct ieee80211_conf *conf = NULL;
2468 int ret = 0;
2469 DECLARE_MAC_BUF(mac);
2470 unsigned long flags;
2471
2472 if (priv->iw_mode == NL80211_IFTYPE_AP) {
2473 IWL_ERROR("%s Should not be called in AP mode\n", __func__);
2474 return;
2475 }
2476
2477 IWL_DEBUG_ASSOC("Associated as %d to: %s\n",
2478 priv->assoc_id,
2479 print_mac(mac, priv->active_rxon.bssid_addr));
2480
2481
2482 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2483 return;
2484
2485
2486 if (!priv->vif || !priv->is_open)
2487 return;
2488
2489 iwl_power_cancel_timeout(priv);
2490 iwl_scan_cancel_timeout(priv, 200);
2491
2492 conf = ieee80211_get_hw_conf(priv->hw);
2493
2494 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2495 iwl4965_commit_rxon(priv);
2496
2497 memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd));
2498 iwl4965_setup_rxon_timing(priv);
2499 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
2500 sizeof(priv->rxon_timing), &priv->rxon_timing);
2501 if (ret)
2502 IWL_WARNING("REPLY_RXON_TIMING failed - "
2503 "Attempting to continue.\n");
2504
2505 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
2506
2507 iwl_set_rxon_ht(priv, &priv->current_ht_config);
2508
2509 iwl_set_rxon_chain(priv);
2510 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
2511
2512 IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
2513 priv->assoc_id, priv->beacon_int);
2514
2515 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
2516 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
2517 else
2518 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
2519
2520 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
2521 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
2522 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
2523 else
2524 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2525
2526 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
2527 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2528
2529 }
2530
2531 iwl4965_commit_rxon(priv);
2532
2533 switch (priv->iw_mode) {
2534 case NL80211_IFTYPE_STATION:
2535 break;
2536
2537 case NL80211_IFTYPE_ADHOC:
2538
2539 /* assume default assoc id */
2540 priv->assoc_id = 1;
2541
2542 iwl_rxon_add_station(priv, priv->bssid, 0);
2543 iwl4965_send_beacon_cmd(priv);
2544
2545 break;
2546
2547 default:
2548 IWL_ERROR("%s Should not be called in %d mode\n",
2549 __func__, priv->iw_mode);
2550 break;
2551 }
2552
2553 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
2554 priv->assoc_station_added = 1;
2555
2556 spin_lock_irqsave(&priv->lock, flags);
2557 iwl_activate_qos(priv, 0);
2558 spin_unlock_irqrestore(&priv->lock, flags);
2559
2560 /* the chain noise calibration will enabled PM upon completion
2561 * If chain noise has already been run, then we need to enable
2562 * power management here */
2563 if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE)
2564 iwl_power_enable_management(priv);
2565
2566 /* Enable Rx differential gain and sensitivity calibrations */
2567 iwl_chain_noise_reset(priv);
2568 priv->start_calib = 1;
2569
2570}
2571
2572/*****************************************************************************
2573 *
2574 * mac80211 entry point functions
2575 *
2576 *****************************************************************************/
2577
2578#define UCODE_READY_TIMEOUT (4 * HZ)
2579
2580static int iwl4965_mac_start(struct ieee80211_hw *hw)
2581{
2582 struct iwl_priv *priv = hw->priv;
2583 int ret;
2584 u16 pci_cmd;
2585
2586 IWL_DEBUG_MAC80211("enter\n");
2587
2588 if (pci_enable_device(priv->pci_dev)) {
2589 IWL_ERROR("Fail to pci_enable_device\n");
2590 return -ENODEV;
2591 }
2592 pci_restore_state(priv->pci_dev);
2593 pci_enable_msi(priv->pci_dev);
2594
2595 /* enable interrupts if needed: hw bug w/a */
2596 pci_read_config_word(priv->pci_dev, PCI_COMMAND, &pci_cmd);
2597 if (pci_cmd & PCI_COMMAND_INTX_DISABLE) {
2598 pci_cmd &= ~PCI_COMMAND_INTX_DISABLE;
2599 pci_write_config_word(priv->pci_dev, PCI_COMMAND, pci_cmd);
2600 }
2601
2602 ret = request_irq(priv->pci_dev->irq, iwl4965_isr, IRQF_SHARED,
2603 DRV_NAME, priv);
2604 if (ret) {
2605 IWL_ERROR("Error allocating IRQ %d\n", priv->pci_dev->irq);
2606 goto out_disable_msi;
2607 }
2608
2609 /* we should be verifying the device is ready to be opened */
2610 mutex_lock(&priv->mutex);
2611
2612 memset(&priv->staging_rxon, 0, sizeof(struct iwl_rxon_cmd));
2613 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
2614 * ucode filename and max sizes are card-specific. */
2615
2616 if (!priv->ucode_code.len) {
2617 ret = iwl4965_read_ucode(priv);
2618 if (ret) {
2619 IWL_ERROR("Could not read microcode: %d\n", ret);
2620 mutex_unlock(&priv->mutex);
2621 goto out_release_irq;
2622 }
2623 }
2624
2625 ret = __iwl4965_up(priv);
2626
2627 mutex_unlock(&priv->mutex);
2628
2629 iwl_rfkill_set_hw_state(priv);
2630
2631 if (ret)
2632 goto out_release_irq;
2633
2634 if (iwl_is_rfkill(priv))
2635 goto out;
2636
2637 IWL_DEBUG_INFO("Start UP work done.\n");
2638
2639 if (test_bit(STATUS_IN_SUSPEND, &priv->status))
2640 return 0;
2641
2642 /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from
2643 * mac80211 will not be run successfully. */
2644 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
2645 test_bit(STATUS_READY, &priv->status),
2646 UCODE_READY_TIMEOUT);
2647 if (!ret) {
2648 if (!test_bit(STATUS_READY, &priv->status)) {
2649 IWL_ERROR("START_ALIVE timeout after %dms.\n",
2650 jiffies_to_msecs(UCODE_READY_TIMEOUT));
2651 ret = -ETIMEDOUT;
2652 goto out_release_irq;
2653 }
2654 }
2655
2656out:
2657 priv->is_open = 1;
2658 IWL_DEBUG_MAC80211("leave\n");
2659 return 0;
2660
2661out_release_irq:
2662 free_irq(priv->pci_dev->irq, priv);
2663out_disable_msi:
2664 pci_disable_msi(priv->pci_dev);
2665 pci_disable_device(priv->pci_dev);
2666 priv->is_open = 0;
2667 IWL_DEBUG_MAC80211("leave - failed\n");
2668 return ret;
2669}
2670
2671static void iwl4965_mac_stop(struct ieee80211_hw *hw)
2672{
2673 struct iwl_priv *priv = hw->priv;
2674
2675 IWL_DEBUG_MAC80211("enter\n");
2676
2677 if (!priv->is_open) {
2678 IWL_DEBUG_MAC80211("leave - skip\n");
2679 return;
2680 }
2681
2682 priv->is_open = 0;
2683
2684 if (iwl_is_ready_rf(priv)) {
2685 /* stop mac, cancel any scan request and clear
2686 * RXON_FILTER_ASSOC_MSK BIT
2687 */
2688 mutex_lock(&priv->mutex);
2689 iwl_scan_cancel_timeout(priv, 100);
2690 mutex_unlock(&priv->mutex);
2691 }
2692
2693 iwl4965_down(priv);
2694
2695 flush_workqueue(priv->workqueue);
2696 free_irq(priv->pci_dev->irq, priv);
2697 pci_disable_msi(priv->pci_dev);
2698 pci_save_state(priv->pci_dev);
2699 pci_disable_device(priv->pci_dev);
2700
2701 IWL_DEBUG_MAC80211("leave\n");
2702}
2703
2704static int iwl4965_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
2705{
2706 struct iwl_priv *priv = hw->priv;
2707
2708 IWL_DEBUG_MACDUMP("enter\n");
2709
2710 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
2711 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
2712
2713 if (iwl_tx_skb(priv, skb))
2714 dev_kfree_skb_any(skb);
2715
2716 IWL_DEBUG_MACDUMP("leave\n");
2717 return 0;
2718}
2719
2720static int iwl4965_mac_add_interface(struct ieee80211_hw *hw,
2721 struct ieee80211_if_init_conf *conf)
2722{
2723 struct iwl_priv *priv = hw->priv;
2724 unsigned long flags;
2725 DECLARE_MAC_BUF(mac);
2726
2727 IWL_DEBUG_MAC80211("enter: type %d\n", conf->type);
2728
2729 if (priv->vif) {
2730 IWL_DEBUG_MAC80211("leave - vif != NULL\n");
2731 return -EOPNOTSUPP;
2732 }
2733
2734 spin_lock_irqsave(&priv->lock, flags);
2735 priv->vif = conf->vif;
2736
2737 spin_unlock_irqrestore(&priv->lock, flags);
2738
2739 mutex_lock(&priv->mutex);
2740
2741 if (conf->mac_addr) {
2742 IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac, conf->mac_addr));
2743 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
2744 }
2745
2746 if (iwl4965_set_mode(priv, conf->type) == -EAGAIN)
2747 /* we are not ready, will run again when ready */
2748 set_bit(STATUS_MODE_PENDING, &priv->status);
2749
2750 mutex_unlock(&priv->mutex);
2751
2752 IWL_DEBUG_MAC80211("leave\n");
2753 return 0;
2754}
2755
2756/**
2757 * iwl4965_mac_config - mac80211 config callback
2758 *
2759 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
2760 * be set inappropriately and the driver currently sets the hardware up to
2761 * use it whenever needed.
2762 */
2763static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf)
2764{
2765 struct iwl_priv *priv = hw->priv;
2766 const struct iwl_channel_info *ch_info;
2767 unsigned long flags;
2768 int ret = 0;
2769 u16 channel;
2770
2771 mutex_lock(&priv->mutex);
2772 IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value);
2773
2774 if (conf->radio_enabled && iwl_radio_kill_sw_enable_radio(priv)) {
2775 IWL_DEBUG_MAC80211("leave - RF-KILL - waiting for uCode\n");
2776 goto out;
2777 }
2778
2779 if (!conf->radio_enabled)
2780 iwl_radio_kill_sw_disable_radio(priv);
2781
2782 if (!iwl_is_ready(priv)) {
2783 IWL_DEBUG_MAC80211("leave - not ready\n");
2784 ret = -EIO;
2785 goto out;
2786 }
2787
2788 if (unlikely(!priv->cfg->mod_params->disable_hw_scan &&
2789 test_bit(STATUS_SCANNING, &priv->status))) {
2790 IWL_DEBUG_MAC80211("leave - scanning\n");
2791 mutex_unlock(&priv->mutex);
2792 return 0;
2793 }
2794
2795 channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
2796 ch_info = iwl_get_channel_info(priv, conf->channel->band, channel);
2797 if (!is_channel_valid(ch_info)) {
2798 IWL_DEBUG_MAC80211("leave - invalid channel\n");
2799 ret = -EINVAL;
2800 goto out;
2801 }
2802
2803 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
2804 !is_channel_ibss(ch_info)) {
2805 IWL_ERROR("channel %d in band %d not IBSS channel\n",
2806 conf->channel->hw_value, conf->channel->band);
2807 ret = -EINVAL;
2808 goto out;
2809 }
2810
2811 spin_lock_irqsave(&priv->lock, flags);
2812
2813
2814 /* if we are switching from ht to 2.4 clear flags
2815 * from any ht related info since 2.4 does not
2816 * support ht */
2817 if ((le16_to_cpu(priv->staging_rxon.channel) != channel)
2818#ifdef IEEE80211_CONF_CHANNEL_SWITCH
2819 && !(conf->flags & IEEE80211_CONF_CHANNEL_SWITCH)
2820#endif
2821 )
2822 priv->staging_rxon.flags = 0;
2823
2824 iwl_set_rxon_channel(priv, conf->channel);
2825
2826 iwl_set_flags_for_band(priv, conf->channel->band);
2827
2828 /* The list of supported rates and rate mask can be different
2829 * for each band; since the band may have changed, reset
2830 * the rate mask to what mac80211 lists */
2831 iwl4965_set_rate(priv);
2832
2833 spin_unlock_irqrestore(&priv->lock, flags);
2834
2835#ifdef IEEE80211_CONF_CHANNEL_SWITCH
2836 if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
2837 iwl4965_hw_channel_switch(priv, conf->channel);
2838 goto out;
2839 }
2840#endif
2841
2842 if (!conf->radio_enabled) {
2843 IWL_DEBUG_MAC80211("leave - radio disabled\n");
2844 goto out;
2845 }
2846
2847 if (iwl_is_rfkill(priv)) {
2848 IWL_DEBUG_MAC80211("leave - RF kill\n");
2849 ret = -EIO;
2850 goto out;
2851 }
2852
2853 if (conf->flags & IEEE80211_CONF_PS)
2854 ret = iwl_power_set_user_mode(priv, IWL_POWER_INDEX_3);
2855 else
2856 ret = iwl_power_set_user_mode(priv, IWL_POWER_MODE_CAM);
2857 if (ret)
2858 IWL_DEBUG_MAC80211("Error setting power level\n");
2859
2860 IWL_DEBUG_MAC80211("TX Power old=%d new=%d\n",
2861 priv->tx_power_user_lmt, conf->power_level);
2862
2863 iwl_set_tx_power(priv, conf->power_level, false);
2864
2865 iwl4965_set_rate(priv);
2866
2867 if (memcmp(&priv->active_rxon,
2868 &priv->staging_rxon, sizeof(priv->staging_rxon)))
2869 iwl4965_commit_rxon(priv);
2870 else
2871 IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
2872
2873 IWL_DEBUG_MAC80211("leave\n");
2874
2875out:
2876 mutex_unlock(&priv->mutex);
2877 return ret;
2878}
2879
2880static void iwl4965_config_ap(struct iwl_priv *priv)
2881{
2882 int ret = 0;
2883 unsigned long flags;
2884
2885 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2886 return;
2887
2888 /* The following should be done only at AP bring up */
2889 if (!(iwl_is_associated(priv))) {
2890
2891 /* RXON - unassoc (to set timing command) */
2892 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2893 iwl4965_commit_rxon(priv);
2894
2895 /* RXON Timing */
2896 memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd));
2897 iwl4965_setup_rxon_timing(priv);
2898 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
2899 sizeof(priv->rxon_timing), &priv->rxon_timing);
2900 if (ret)
2901 IWL_WARNING("REPLY_RXON_TIMING failed - "
2902 "Attempting to continue.\n");
2903
2904 iwl_set_rxon_chain(priv);
2905
2906 /* FIXME: what should be the assoc_id for AP? */
2907 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
2908 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
2909 priv->staging_rxon.flags |=
2910 RXON_FLG_SHORT_PREAMBLE_MSK;
2911 else
2912 priv->staging_rxon.flags &=
2913 ~RXON_FLG_SHORT_PREAMBLE_MSK;
2914
2915 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
2916 if (priv->assoc_capability &
2917 WLAN_CAPABILITY_SHORT_SLOT_TIME)
2918 priv->staging_rxon.flags |=
2919 RXON_FLG_SHORT_SLOT_MSK;
2920 else
2921 priv->staging_rxon.flags &=
2922 ~RXON_FLG_SHORT_SLOT_MSK;
2923
2924 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
2925 priv->staging_rxon.flags &=
2926 ~RXON_FLG_SHORT_SLOT_MSK;
2927 }
2928 /* restore RXON assoc */
2929 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
2930 iwl4965_commit_rxon(priv);
2931 spin_lock_irqsave(&priv->lock, flags);
2932 iwl_activate_qos(priv, 1);
2933 spin_unlock_irqrestore(&priv->lock, flags);
2934 iwl_rxon_add_station(priv, iwl_bcast_addr, 0);
2935 }
2936 iwl4965_send_beacon_cmd(priv);
2937
2938 /* FIXME - we need to add code here to detect a totally new
2939 * configuration, reset the AP, unassoc, rxon timing, assoc,
2940 * clear sta table, add BCAST sta... */
2941}
2942
2943/* temporary */
2944static int iwl4965_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb);
2945
2946static int iwl4965_mac_config_interface(struct ieee80211_hw *hw,
2947 struct ieee80211_vif *vif,
2948 struct ieee80211_if_conf *conf)
2949{
2950 struct iwl_priv *priv = hw->priv;
2951 DECLARE_MAC_BUF(mac);
2952 unsigned long flags;
2953 int rc;
2954
2955 if (conf == NULL)
2956 return -EIO;
2957
2958 if (priv->vif != vif) {
2959 IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
2960 return 0;
2961 }
2962
2963 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
2964 conf->changed & IEEE80211_IFCC_BEACON) {
2965 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
2966 if (!beacon)
2967 return -ENOMEM;
2968 rc = iwl4965_mac_beacon_update(hw, beacon);
2969 if (rc)
2970 return rc;
2971 }
2972
2973 if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
2974 (!conf->ssid_len)) {
2975 IWL_DEBUG_MAC80211
2976 ("Leaving in AP mode because HostAPD is not ready.\n");
2977 return 0;
2978 }
2979
2980 if (!iwl_is_alive(priv))
2981 return -EAGAIN;
2982
2983 mutex_lock(&priv->mutex);
2984
2985 if (conf->bssid)
2986 IWL_DEBUG_MAC80211("bssid: %s\n",
2987 print_mac(mac, conf->bssid));
2988
2989/*
2990 * very dubious code was here; the probe filtering flag is never set:
2991 *
2992 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
2993 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
2994 */
2995
2996 if (priv->iw_mode == NL80211_IFTYPE_AP) {
2997 if (!conf->bssid) {
2998 conf->bssid = priv->mac_addr;
2999 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
3000 IWL_DEBUG_MAC80211("bssid was set to: %s\n",
3001 print_mac(mac, conf->bssid));
3002 }
3003 if (priv->ibss_beacon)
3004 dev_kfree_skb(priv->ibss_beacon);
3005
3006 priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
3007 }
3008
3009 if (iwl_is_rfkill(priv))
3010 goto done;
3011
3012 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
3013 !is_multicast_ether_addr(conf->bssid)) {
3014 /* If there is currently a HW scan going on in the background
3015 * then we need to cancel it else the RXON below will fail. */
3016 if (iwl_scan_cancel_timeout(priv, 100)) {
3017 IWL_WARNING("Aborted scan still in progress "
3018 "after 100ms\n");
3019 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
3020 mutex_unlock(&priv->mutex);
3021 return -EAGAIN;
3022 }
3023 memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
3024
3025 /* TODO: Audit driver for usage of these members and see
3026 * if mac80211 deprecates them (priv->bssid looks like it
3027 * shouldn't be there, but I haven't scanned the IBSS code
3028 * to verify) - jpk */
3029 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
3030
3031 if (priv->iw_mode == NL80211_IFTYPE_AP)
3032 iwl4965_config_ap(priv);
3033 else {
3034 rc = iwl4965_commit_rxon(priv);
3035 if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc)
3036 iwl_rxon_add_station(
3037 priv, priv->active_rxon.bssid_addr, 1);
3038 }
3039
3040 } else {
3041 iwl_scan_cancel_timeout(priv, 100);
3042 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3043 iwl4965_commit_rxon(priv);
3044 }
3045
3046 done:
3047 spin_lock_irqsave(&priv->lock, flags);
3048 if (!conf->ssid_len)
3049 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
3050 else
3051 memcpy(priv->essid, conf->ssid, conf->ssid_len);
3052
3053 priv->essid_len = conf->ssid_len;
3054 spin_unlock_irqrestore(&priv->lock, flags);
3055
3056 IWL_DEBUG_MAC80211("leave\n");
3057 mutex_unlock(&priv->mutex);
3058
3059 return 0;
3060}
3061
3062static void iwl4965_configure_filter(struct ieee80211_hw *hw,
3063 unsigned int changed_flags,
3064 unsigned int *total_flags,
3065 int mc_count, struct dev_addr_list *mc_list)
3066{
3067 struct iwl_priv *priv = hw->priv;
3068
3069 if (changed_flags & (*total_flags) & FIF_OTHER_BSS) {
3070 IWL_DEBUG_MAC80211("Enter: type %d (0x%x, 0x%x)\n",
3071 NL80211_IFTYPE_MONITOR,
3072 changed_flags, *total_flags);
3073 /* queue work 'cuz mac80211 is holding a lock which
3074 * prevents us from issuing (synchronous) f/w cmds */
3075 queue_work(priv->workqueue, &priv->set_monitor);
3076 }
3077 *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI |
3078 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
3079}
3080
3081static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw,
3082 struct ieee80211_if_init_conf *conf)
3083{
3084 struct iwl_priv *priv = hw->priv;
3085
3086 IWL_DEBUG_MAC80211("enter\n");
3087
3088 mutex_lock(&priv->mutex);
3089
3090 if (iwl_is_ready_rf(priv)) {
3091 iwl_scan_cancel_timeout(priv, 100);
3092 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3093 iwl4965_commit_rxon(priv);
3094 }
3095 if (priv->vif == conf->vif) {
3096 priv->vif = NULL;
3097 memset(priv->bssid, 0, ETH_ALEN);
3098 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
3099 priv->essid_len = 0;
3100 }
3101 mutex_unlock(&priv->mutex);
3102
3103 IWL_DEBUG_MAC80211("leave\n");
3104
3105}
3106
3107#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
3108static void iwl4965_bss_info_changed(struct ieee80211_hw *hw,
3109 struct ieee80211_vif *vif,
3110 struct ieee80211_bss_conf *bss_conf,
3111 u32 changes)
3112{
3113 struct iwl_priv *priv = hw->priv;
3114
3115 IWL_DEBUG_MAC80211("changes = 0x%X\n", changes);
3116
3117 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
3118 IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n",
3119 bss_conf->use_short_preamble);
3120 if (bss_conf->use_short_preamble)
3121 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
3122 else
3123 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
3124 }
3125
3126 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
3127 IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf->use_cts_prot);
3128 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
3129 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
3130 else
3131 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
3132 }
3133
3134 if (changes & BSS_CHANGED_HT) {
3135 IWL_DEBUG_MAC80211("HT %d\n", bss_conf->assoc_ht);
3136 iwl4965_ht_conf(priv, bss_conf);
3137 iwl_set_rxon_chain(priv);
3138 }
3139
3140 if (changes & BSS_CHANGED_ASSOC) {
3141 IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf->assoc);
3142 /* This should never happen as this function should
3143 * never be called from interrupt context. */
3144 if (WARN_ON_ONCE(in_interrupt()))
3145 return;
3146 if (bss_conf->assoc) {
3147 priv->assoc_id = bss_conf->aid;
3148 priv->beacon_int = bss_conf->beacon_int;
3149 priv->power_data.dtim_period = bss_conf->dtim_period;
3150 priv->timestamp = bss_conf->timestamp;
3151 priv->assoc_capability = bss_conf->assoc_capability;
3152
3153 /* we have just associated, don't start scan too early
3154 * leave time for EAPOL exchange to complete
3155 */
3156 priv->next_scan_jiffies = jiffies +
3157 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
3158 mutex_lock(&priv->mutex);
3159 iwl4965_post_associate(priv);
3160 mutex_unlock(&priv->mutex);
3161 } else {
3162 priv->assoc_id = 0;
3163 IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf->assoc);
3164 }
3165 } else if (changes && iwl_is_associated(priv) && priv->assoc_id) {
3166 IWL_DEBUG_MAC80211("Associated Changes %d\n", changes);
3167 iwl_send_rxon_assoc(priv);
3168 }
3169
3170}
3171
3172static int iwl_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t ssid_len)
3173{
3174 unsigned long flags;
3175 struct iwl_priv *priv = hw->priv;
3176 int ret;
3177
3178 IWL_DEBUG_MAC80211("enter\n");
3179
3180 mutex_lock(&priv->mutex);
3181 spin_lock_irqsave(&priv->lock, flags);
3182
3183 if (!iwl_is_ready_rf(priv)) {
3184 ret = -EIO;
3185 IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
3186 goto out_unlock;
3187 }
3188
3189 if (priv->iw_mode == NL80211_IFTYPE_AP) { /* APs don't scan */
3190 ret = -EIO;
3191 IWL_ERROR("ERROR: APs don't scan\n");
3192 goto out_unlock;
3193 }
3194
3195 /* We don't schedule scan within next_scan_jiffies period.
3196 * Avoid scanning during possible EAPOL exchange, return
3197 * success immediately.
3198 */
3199 if (priv->next_scan_jiffies &&
3200 time_after(priv->next_scan_jiffies, jiffies)) {
3201 IWL_DEBUG_SCAN("scan rejected: within next scan period\n");
3202 queue_work(priv->workqueue, &priv->scan_completed);
3203 ret = 0;
3204 goto out_unlock;
3205 }
3206
3207 /* if we just finished scan ask for delay */
3208 if (iwl_is_associated(priv) && priv->last_scan_jiffies &&
3209 time_after(priv->last_scan_jiffies + IWL_DELAY_NEXT_SCAN, jiffies)) {
3210 IWL_DEBUG_SCAN("scan rejected: within previous scan period\n");
3211 queue_work(priv->workqueue, &priv->scan_completed);
3212 ret = 0;
3213 goto out_unlock;
3214 }
3215
3216 if (ssid_len) {
3217 priv->one_direct_scan = 1;
3218 priv->direct_ssid_len = min_t(u8, ssid_len, IW_ESSID_MAX_SIZE);
3219 memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len);
3220 } else {
3221 priv->one_direct_scan = 0;
3222 }
3223
3224 ret = iwl_scan_initiate(priv);
3225
3226 IWL_DEBUG_MAC80211("leave\n");
3227
3228out_unlock:
3229 spin_unlock_irqrestore(&priv->lock, flags);
3230 mutex_unlock(&priv->mutex);
3231
3232 return ret;
3233}
3234
3235static void iwl4965_mac_update_tkip_key(struct ieee80211_hw *hw,
3236 struct ieee80211_key_conf *keyconf, const u8 *addr,
3237 u32 iv32, u16 *phase1key)
3238{
3239 struct iwl_priv *priv = hw->priv;
3240 u8 sta_id = IWL_INVALID_STATION;
3241 unsigned long flags;
3242 __le16 key_flags = 0;
3243 int i;
3244 DECLARE_MAC_BUF(mac);
3245
3246 IWL_DEBUG_MAC80211("enter\n");
3247
3248 sta_id = iwl_find_station(priv, addr);
3249 if (sta_id == IWL_INVALID_STATION) {
3250 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
3251 print_mac(mac, addr));
3252 return;
3253 }
3254
3255 iwl_scan_cancel_timeout(priv, 100);
3256
3257 key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK);
3258 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
3259 key_flags &= ~STA_KEY_FLG_INVALID;
3260
3261 if (sta_id == priv->hw_params.bcast_sta_id)
3262 key_flags |= STA_KEY_MULTICAST_MSK;
3263
3264 spin_lock_irqsave(&priv->sta_lock, flags);
3265
3266 priv->stations[sta_id].sta.key.key_flags = key_flags;
3267 priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32;
3268
3269 for (i = 0; i < 5; i++)
3270 priv->stations[sta_id].sta.key.tkip_rx_ttak[i] =
3271 cpu_to_le16(phase1key[i]);
3272
3273 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
3274 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
3275
3276 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
3277
3278 spin_unlock_irqrestore(&priv->sta_lock, flags);
3279
3280 IWL_DEBUG_MAC80211("leave\n");
3281}
3282
3283static int iwl4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3284 const u8 *local_addr, const u8 *addr,
3285 struct ieee80211_key_conf *key)
3286{
3287 struct iwl_priv *priv = hw->priv;
3288 DECLARE_MAC_BUF(mac);
3289 int ret = 0;
3290 u8 sta_id = IWL_INVALID_STATION;
3291 u8 is_default_wep_key = 0;
3292
3293 IWL_DEBUG_MAC80211("enter\n");
3294
3295 if (priv->hw_params.sw_crypto) {
3296 IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
3297 return -EOPNOTSUPP;
3298 }
3299
3300 if (is_zero_ether_addr(addr))
3301 /* only support pairwise keys */
3302 return -EOPNOTSUPP;
3303
3304 sta_id = iwl_find_station(priv, addr);
3305 if (sta_id == IWL_INVALID_STATION) {
3306 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
3307 print_mac(mac, addr));
3308 return -EINVAL;
3309
3310 }
3311
3312 mutex_lock(&priv->mutex);
3313 iwl_scan_cancel_timeout(priv, 100);
3314 mutex_unlock(&priv->mutex);
3315
3316 /* If we are getting WEP group key and we didn't receive any key mapping
3317 * so far, we are in legacy wep mode (group key only), otherwise we are
3318 * in 1X mode.
3319 * In legacy wep mode, we use another host command to the uCode */
3320 if (key->alg == ALG_WEP && sta_id == priv->hw_params.bcast_sta_id &&
3321 priv->iw_mode != NL80211_IFTYPE_AP) {
3322 if (cmd == SET_KEY)
3323 is_default_wep_key = !priv->key_mapping_key;
3324 else
3325 is_default_wep_key =
3326 (key->hw_key_idx == HW_KEY_DEFAULT);
3327 }
3328
3329 switch (cmd) {
3330 case SET_KEY:
3331 if (is_default_wep_key)
3332 ret = iwl_set_default_wep_key(priv, key);
3333 else
3334 ret = iwl_set_dynamic_key(priv, key, sta_id);
3335
3336 IWL_DEBUG_MAC80211("enable hwcrypto key\n");
3337 break;
3338 case DISABLE_KEY:
3339 if (is_default_wep_key)
3340 ret = iwl_remove_default_wep_key(priv, key);
3341 else
3342 ret = iwl_remove_dynamic_key(priv, key, sta_id);
3343
3344 IWL_DEBUG_MAC80211("disable hwcrypto key\n");
3345 break;
3346 default:
3347 ret = -EINVAL;
3348 }
3349
3350 IWL_DEBUG_MAC80211("leave\n");
3351
3352 return ret;
3353}
3354
3355static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
3356 const struct ieee80211_tx_queue_params *params)
3357{
3358 struct iwl_priv *priv = hw->priv;
3359 unsigned long flags;
3360 int q;
3361
3362 IWL_DEBUG_MAC80211("enter\n");
3363
3364 if (!iwl_is_ready_rf(priv)) {
3365 IWL_DEBUG_MAC80211("leave - RF not ready\n");
3366 return -EIO;
3367 }
3368
3369 if (queue >= AC_NUM) {
3370 IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue);
3371 return 0;
3372 }
3373
3374 if (!priv->qos_data.qos_enable) {
3375 priv->qos_data.qos_active = 0;
3376 IWL_DEBUG_MAC80211("leave - qos not enabled\n");
3377 return 0;
3378 }
3379 q = AC_NUM - 1 - queue;
3380
3381 spin_lock_irqsave(&priv->lock, flags);
3382
3383 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
3384 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
3385 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
3386 priv->qos_data.def_qos_parm.ac[q].edca_txop =
3387 cpu_to_le16((params->txop * 32));
3388
3389 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
3390 priv->qos_data.qos_active = 1;
3391
3392 if (priv->iw_mode == NL80211_IFTYPE_AP)
3393 iwl_activate_qos(priv, 1);
3394 else if (priv->assoc_id && iwl_is_associated(priv))
3395 iwl_activate_qos(priv, 0);
3396
3397 spin_unlock_irqrestore(&priv->lock, flags);
3398
3399 IWL_DEBUG_MAC80211("leave\n");
3400 return 0;
3401}
3402
3403static int iwl4965_mac_ampdu_action(struct ieee80211_hw *hw,
3404 enum ieee80211_ampdu_mlme_action action,
3405 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
3406{
3407 struct iwl_priv *priv = hw->priv;
3408 DECLARE_MAC_BUF(mac);
3409
3410 IWL_DEBUG_HT("A-MPDU action on addr %s tid %d\n",
3411 print_mac(mac, sta->addr), tid);
3412
3413 if (!(priv->cfg->sku & IWL_SKU_N))
3414 return -EACCES;
3415
3416 switch (action) {
3417 case IEEE80211_AMPDU_RX_START:
3418 IWL_DEBUG_HT("start Rx\n");
3419 return iwl_rx_agg_start(priv, sta->addr, tid, *ssn);
3420 case IEEE80211_AMPDU_RX_STOP:
3421 IWL_DEBUG_HT("stop Rx\n");
3422 return iwl_rx_agg_stop(priv, sta->addr, tid);
3423 case IEEE80211_AMPDU_TX_START:
3424 IWL_DEBUG_HT("start Tx\n");
3425 return iwl_tx_agg_start(priv, sta->addr, tid, ssn);
3426 case IEEE80211_AMPDU_TX_STOP:
3427 IWL_DEBUG_HT("stop Tx\n");
3428 return iwl_tx_agg_stop(priv, sta->addr, tid);
3429 default:
3430 IWL_DEBUG_HT("unknown\n");
3431 return -EINVAL;
3432 break;
3433 }
3434 return 0;
3435}
3436static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw,
3437 struct ieee80211_tx_queue_stats *stats)
3438{
3439 struct iwl_priv *priv = hw->priv;
3440 int i, avail;
3441 struct iwl_tx_queue *txq;
3442 struct iwl_queue *q;
3443 unsigned long flags;
3444
3445 IWL_DEBUG_MAC80211("enter\n");
3446
3447 if (!iwl_is_ready_rf(priv)) {
3448 IWL_DEBUG_MAC80211("leave - RF not ready\n");
3449 return -EIO;
3450 }
3451
3452 spin_lock_irqsave(&priv->lock, flags);
3453
3454 for (i = 0; i < AC_NUM; i++) {
3455 txq = &priv->txq[i];
3456 q = &txq->q;
3457 avail = iwl_queue_space(q);
3458
3459 stats[i].len = q->n_window - avail;
3460 stats[i].limit = q->n_window - q->high_mark;
3461 stats[i].count = q->n_window;
3462
3463 }
3464 spin_unlock_irqrestore(&priv->lock, flags);
3465
3466 IWL_DEBUG_MAC80211("leave\n");
3467
3468 return 0;
3469}
3470
3471static int iwl4965_mac_get_stats(struct ieee80211_hw *hw,
3472 struct ieee80211_low_level_stats *stats)
3473{
3474 struct iwl_priv *priv = hw->priv;
3475
3476 priv = hw->priv;
3477 IWL_DEBUG_MAC80211("enter\n");
3478 IWL_DEBUG_MAC80211("leave\n");
3479
3480 return 0;
3481}
3482
3483static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw)
3484{
3485 struct iwl_priv *priv = hw->priv;
3486 unsigned long flags;
3487
3488 mutex_lock(&priv->mutex);
3489 IWL_DEBUG_MAC80211("enter\n");
3490
3491 spin_lock_irqsave(&priv->lock, flags);
3492 memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info));
3493 spin_unlock_irqrestore(&priv->lock, flags);
3494
3495 iwl_reset_qos(priv);
3496
3497 spin_lock_irqsave(&priv->lock, flags);
3498 priv->assoc_id = 0;
3499 priv->assoc_capability = 0;
3500 priv->assoc_station_added = 0;
3501
3502 /* new association get rid of ibss beacon skb */
3503 if (priv->ibss_beacon)
3504 dev_kfree_skb(priv->ibss_beacon);
3505
3506 priv->ibss_beacon = NULL;
3507
3508 priv->beacon_int = priv->hw->conf.beacon_int;
3509 priv->timestamp = 0;
3510 if ((priv->iw_mode == NL80211_IFTYPE_STATION))
3511 priv->beacon_int = 0;
3512
3513 spin_unlock_irqrestore(&priv->lock, flags);
3514
3515 if (!iwl_is_ready_rf(priv)) {
3516 IWL_DEBUG_MAC80211("leave - not ready\n");
3517 mutex_unlock(&priv->mutex);
3518 return;
3519 }
3520
3521 /* we are restarting association process
3522 * clear RXON_FILTER_ASSOC_MSK bit
3523 */
3524 if (priv->iw_mode != NL80211_IFTYPE_AP) {
3525 iwl_scan_cancel_timeout(priv, 100);
3526 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3527 iwl4965_commit_rxon(priv);
3528 }
3529
3530 iwl_power_update_mode(priv, 0);
3531
3532 /* Per mac80211.h: This is only used in IBSS mode... */
3533 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
3534
3535 /* switch to CAM during association period.
3536 * the ucode will block any association/authentication
3537 * frome during assiciation period if it can not hear
3538 * the AP because of PM. the timer enable PM back is
3539 * association do not complete
3540 */
3541 if (priv->hw->conf.channel->flags & (IEEE80211_CHAN_PASSIVE_SCAN |
3542 IEEE80211_CHAN_RADAR))
3543 iwl_power_disable_management(priv, 3000);
3544
3545 IWL_DEBUG_MAC80211("leave - not in IBSS\n");
3546 mutex_unlock(&priv->mutex);
3547 return;
3548 }
3549
3550 iwl4965_set_rate(priv);
3551
3552 mutex_unlock(&priv->mutex);
3553
3554 IWL_DEBUG_MAC80211("leave\n");
3555}
3556
3557static int iwl4965_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
3558{
3559 struct iwl_priv *priv = hw->priv;
3560 unsigned long flags;
3561 __le64 timestamp;
3562
3563 mutex_lock(&priv->mutex);
3564 IWL_DEBUG_MAC80211("enter\n");
3565
3566 if (!iwl_is_ready_rf(priv)) {
3567 IWL_DEBUG_MAC80211("leave - RF not ready\n");
3568 mutex_unlock(&priv->mutex);
3569 return -EIO;
3570 }
3571
3572 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
3573 IWL_DEBUG_MAC80211("leave - not IBSS\n");
3574 mutex_unlock(&priv->mutex);
3575 return -EIO;
3576 }
3577
3578 spin_lock_irqsave(&priv->lock, flags);
3579
3580 if (priv->ibss_beacon)
3581 dev_kfree_skb(priv->ibss_beacon);
3582
3583 priv->ibss_beacon = skb;
3584
3585 priv->assoc_id = 0;
3586 timestamp = ((struct ieee80211_mgmt *)skb->data)->u.beacon.timestamp;
3587 priv->timestamp = le64_to_cpu(timestamp);
3588
3589 IWL_DEBUG_MAC80211("leave\n");
3590 spin_unlock_irqrestore(&priv->lock, flags);
3591
3592 iwl_reset_qos(priv);
3593
3594 iwl4965_post_associate(priv);
3595
3596 mutex_unlock(&priv->mutex);
3597
3598 return 0;
3599}
3600
3601/*****************************************************************************
3602 *
3603 * sysfs attributes
3604 *
3605 *****************************************************************************/
3606
3607#ifdef CONFIG_IWLWIFI_DEBUG
3608
3609/*
3610 * The following adds a new attribute to the sysfs representation
3611 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
3612 * used for controlling the debug level.
3613 *
3614 * See the level definitions in iwl for details.
3615 */
3616
3617static ssize_t show_debug_level(struct device *d,
3618 struct device_attribute *attr, char *buf)
3619{
3620 struct iwl_priv *priv = d->driver_data;
3621
3622 return sprintf(buf, "0x%08X\n", priv->debug_level);
3623}
3624static ssize_t store_debug_level(struct device *d,
3625 struct device_attribute *attr,
3626 const char *buf, size_t count)
3627{
3628 struct iwl_priv *priv = d->driver_data;
3629 unsigned long val;
3630 int ret;
3631
3632 ret = strict_strtoul(buf, 0, &val);
3633 if (ret)
3634 printk(KERN_INFO DRV_NAME
3635 ": %s is not in hex or decimal form.\n", buf);
3636 else
3637 priv->debug_level = val;
3638
3639 return strnlen(buf, count);
3640}
3641
3642static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
3643 show_debug_level, store_debug_level);
3644
3645
3646#endif /* CONFIG_IWLWIFI_DEBUG */
3647
3648
3649static ssize_t show_version(struct device *d,
3650 struct device_attribute *attr, char *buf)
3651{
3652 struct iwl_priv *priv = d->driver_data;
3653 struct iwl_alive_resp *palive = &priv->card_alive;
3654 ssize_t pos = 0;
3655 u16 eeprom_ver;
3656
3657 if (palive->is_valid)
3658 pos += sprintf(buf + pos,
3659 "fw version: 0x%01X.0x%01X.0x%01X.0x%01X\n"
3660 "fw type: 0x%01X 0x%01X\n",
3661 palive->ucode_major, palive->ucode_minor,
3662 palive->sw_rev[0], palive->sw_rev[1],
3663 palive->ver_type, palive->ver_subtype);
3664 else
3665 pos += sprintf(buf + pos, "fw not loaded\n");
3666
3667 if (priv->eeprom) {
3668 eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
3669 pos += sprintf(buf + pos, "EEPROM version: 0x%x\n",
3670 eeprom_ver);
3671 } else {
3672 pos += sprintf(buf + pos, "EEPROM not initialzed\n");
3673 }
3674
3675 return pos;
3676}
3677
3678static DEVICE_ATTR(version, S_IWUSR | S_IRUGO, show_version, NULL);
3679
3680static ssize_t show_temperature(struct device *d,
3681 struct device_attribute *attr, char *buf)
3682{
3683 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
3684
3685 if (!iwl_is_alive(priv))
3686 return -EAGAIN;
3687
3688 return sprintf(buf, "%d\n", priv->temperature);
3689}
3690
3691static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
3692
3693static ssize_t show_tx_power(struct device *d,
3694 struct device_attribute *attr, char *buf)
3695{
3696 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
3697 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
3698}
3699
3700static ssize_t store_tx_power(struct device *d,
3701 struct device_attribute *attr,
3702 const char *buf, size_t count)
3703{
3704 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
3705 unsigned long val;
3706 int ret;
3707
3708 ret = strict_strtoul(buf, 10, &val);
3709 if (ret)
3710 printk(KERN_INFO DRV_NAME
3711 ": %s is not in decimal form.\n", buf);
3712 else
3713 iwl_set_tx_power(priv, val, false);
3714
3715 return count;
3716}
3717
3718static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
3719
3720static ssize_t show_flags(struct device *d,
3721 struct device_attribute *attr, char *buf)
3722{
3723 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
3724
3725 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
3726}
3727
3728static ssize_t store_flags(struct device *d,
3729 struct device_attribute *attr,
3730 const char *buf, size_t count)
3731{
3732 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
3733 unsigned long val;
3734 u32 flags;
3735 int ret = strict_strtoul(buf, 0, &val);
3736 if (ret)
3737 return ret;
3738 flags = (u32)val;
3739
3740 mutex_lock(&priv->mutex);
3741 if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
3742 /* Cancel any currently running scans... */
3743 if (iwl_scan_cancel_timeout(priv, 100))
3744 IWL_WARNING("Could not cancel scan.\n");
3745 else {
3746 IWL_DEBUG_INFO("Commit rxon.flags = 0x%04X\n", flags);
3747 priv->staging_rxon.flags = cpu_to_le32(flags);
3748 iwl4965_commit_rxon(priv);
3749 }
3750 }
3751 mutex_unlock(&priv->mutex);
3752
3753 return count;
3754}
3755
3756static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
3757
3758static ssize_t show_filter_flags(struct device *d,
3759 struct device_attribute *attr, char *buf)
3760{
3761 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
3762
3763 return sprintf(buf, "0x%04X\n",
3764 le32_to_cpu(priv->active_rxon.filter_flags));
3765}
3766
3767static ssize_t store_filter_flags(struct device *d,
3768 struct device_attribute *attr,
3769 const char *buf, size_t count)
3770{
3771 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
3772 unsigned long val;
3773 u32 filter_flags;
3774 int ret = strict_strtoul(buf, 0, &val);
3775 if (ret)
3776 return ret;
3777 filter_flags = (u32)val;
3778
3779 mutex_lock(&priv->mutex);
3780 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
3781 /* Cancel any currently running scans... */
3782 if (iwl_scan_cancel_timeout(priv, 100))
3783 IWL_WARNING("Could not cancel scan.\n");
3784 else {
3785 IWL_DEBUG_INFO("Committing rxon.filter_flags = "
3786 "0x%04X\n", filter_flags);
3787 priv->staging_rxon.filter_flags =
3788 cpu_to_le32(filter_flags);
3789 iwl4965_commit_rxon(priv);
3790 }
3791 }
3792 mutex_unlock(&priv->mutex);
3793
3794 return count;
3795}
3796
3797static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
3798 store_filter_flags);
3799
3800#ifdef CONFIG_IWLAGN_SPECTRUM_MEASUREMENT
3801
3802static ssize_t show_measurement(struct device *d,
3803 struct device_attribute *attr, char *buf)
3804{
3805 struct iwl_priv *priv = dev_get_drvdata(d);
3806 struct iwl4965_spectrum_notification measure_report;
3807 u32 size = sizeof(measure_report), len = 0, ofs = 0;
3808 u8 *data = (u8 *)&measure_report;
3809 unsigned long flags;
3810
3811 spin_lock_irqsave(&priv->lock, flags);
3812 if (!(priv->measurement_status & MEASUREMENT_READY)) {
3813 spin_unlock_irqrestore(&priv->lock, flags);
3814 return 0;
3815 }
3816 memcpy(&measure_report, &priv->measure_report, size);
3817 priv->measurement_status = 0;
3818 spin_unlock_irqrestore(&priv->lock, flags);
3819
3820 while (size && (PAGE_SIZE - len)) {
3821 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
3822 PAGE_SIZE - len, 1);
3823 len = strlen(buf);
3824 if (PAGE_SIZE - len)
3825 buf[len++] = '\n';
3826
3827 ofs += 16;
3828 size -= min(size, 16U);
3829 }
3830
3831 return len;
3832}
3833
3834static ssize_t store_measurement(struct device *d,
3835 struct device_attribute *attr,
3836 const char *buf, size_t count)
3837{
3838 struct iwl_priv *priv = dev_get_drvdata(d);
3839 struct ieee80211_measurement_params params = {
3840 .channel = le16_to_cpu(priv->active_rxon.channel),
3841 .start_time = cpu_to_le64(priv->last_tsf),
3842 .duration = cpu_to_le16(1),
3843 };
3844 u8 type = IWL_MEASURE_BASIC;
3845 u8 buffer[32];
3846 u8 channel;
3847
3848 if (count) {
3849 char *p = buffer;
3850 strncpy(buffer, buf, min(sizeof(buffer), count));
3851 channel = simple_strtoul(p, NULL, 0);
3852 if (channel)
3853 params.channel = channel;
3854
3855 p = buffer;
3856 while (*p && *p != ' ')
3857 p++;
3858 if (*p)
3859 type = simple_strtoul(p + 1, NULL, 0);
3860 }
3861
3862 IWL_DEBUG_INFO("Invoking measurement of type %d on "
3863 "channel %d (for '%s')\n", type, params.channel, buf);
3864 iwl4965_get_measurement(priv, &params, type);
3865
3866 return count;
3867}
3868
3869static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
3870 show_measurement, store_measurement);
3871#endif /* CONFIG_IWLAGN_SPECTRUM_MEASUREMENT */
3872
3873static ssize_t store_retry_rate(struct device *d,
3874 struct device_attribute *attr,
3875 const char *buf, size_t count)
3876{
3877 struct iwl_priv *priv = dev_get_drvdata(d);
3878 long val;
3879 int ret = strict_strtol(buf, 10, &val);
3880 if (!ret)
3881 return ret;
3882
3883 priv->retry_rate = (val > 0) ? val : 1;
3884
3885 return count;
3886}
3887
3888static ssize_t show_retry_rate(struct device *d,
3889 struct device_attribute *attr, char *buf)
3890{
3891 struct iwl_priv *priv = dev_get_drvdata(d);
3892 return sprintf(buf, "%d", priv->retry_rate);
3893}
3894
3895static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
3896 store_retry_rate);
3897
3898static ssize_t store_power_level(struct device *d,
3899 struct device_attribute *attr,
3900 const char *buf, size_t count)
3901{
3902 struct iwl_priv *priv = dev_get_drvdata(d);
3903 int ret;
3904 unsigned long mode;
3905
3906
3907 mutex_lock(&priv->mutex);
3908
3909 if (!iwl_is_ready(priv)) {
3910 ret = -EAGAIN;
3911 goto out;
3912 }
3913
3914 ret = strict_strtoul(buf, 10, &mode);
3915 if (ret)
3916 goto out;
3917
3918 ret = iwl_power_set_user_mode(priv, mode);
3919 if (ret) {
3920 IWL_DEBUG_MAC80211("failed setting power mode.\n");
3921 goto out;
3922 }
3923 ret = count;
3924
3925 out:
3926 mutex_unlock(&priv->mutex);
3927 return ret;
3928}
3929
3930static ssize_t show_power_level(struct device *d,
3931 struct device_attribute *attr, char *buf)
3932{
3933 struct iwl_priv *priv = dev_get_drvdata(d);
3934 int mode = priv->power_data.user_power_setting;
3935 int system = priv->power_data.system_power_setting;
3936 int level = priv->power_data.power_mode;
3937 char *p = buf;
3938
3939 switch (system) {
3940 case IWL_POWER_SYS_AUTO:
3941 p += sprintf(p, "SYSTEM:auto");
3942 break;
3943 case IWL_POWER_SYS_AC:
3944 p += sprintf(p, "SYSTEM:ac");
3945 break;
3946 case IWL_POWER_SYS_BATTERY:
3947 p += sprintf(p, "SYSTEM:battery");
3948 break;
3949 }
3950
3951 p += sprintf(p, "\tMODE:%s", (mode < IWL_POWER_AUTO)?"fixed":"auto");
3952 p += sprintf(p, "\tINDEX:%d", level);
3953 p += sprintf(p, "\n");
3954 return p - buf + 1;
3955}
3956
3957static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level,
3958 store_power_level);
3959
3960static ssize_t show_channels(struct device *d,
3961 struct device_attribute *attr, char *buf)
3962{
3963
3964 struct iwl_priv *priv = dev_get_drvdata(d);
3965 struct ieee80211_channel *channels = NULL;
3966 const struct ieee80211_supported_band *supp_band = NULL;
3967 int len = 0, i;
3968 int count = 0;
3969
3970 if (!test_bit(STATUS_GEO_CONFIGURED, &priv->status))
3971 return -EAGAIN;
3972
3973 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
3974 channels = supp_band->channels;
3975 count = supp_band->n_channels;
3976
3977 len += sprintf(&buf[len],
3978 "Displaying %d channels in 2.4GHz band "
3979 "(802.11bg):\n", count);
3980
3981 for (i = 0; i < count; i++)
3982 len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n",
3983 ieee80211_frequency_to_channel(
3984 channels[i].center_freq),
3985 channels[i].max_power,
3986 channels[i].flags & IEEE80211_CHAN_RADAR ?
3987 " (IEEE 802.11h required)" : "",
3988 (!(channels[i].flags & IEEE80211_CHAN_NO_IBSS)
3989 || (channels[i].flags &
3990 IEEE80211_CHAN_RADAR)) ? "" :
3991 ", IBSS",
3992 channels[i].flags &
3993 IEEE80211_CHAN_PASSIVE_SCAN ?
3994 "passive only" : "active/passive");
3995
3996 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
3997 channels = supp_band->channels;
3998 count = supp_band->n_channels;
3999
4000 len += sprintf(&buf[len], "Displaying %d channels in 5.2GHz band "
4001 "(802.11a):\n", count);
4002
4003 for (i = 0; i < count; i++)
4004 len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n",
4005 ieee80211_frequency_to_channel(
4006 channels[i].center_freq),
4007 channels[i].max_power,
4008 channels[i].flags & IEEE80211_CHAN_RADAR ?
4009 " (IEEE 802.11h required)" : "",
4010 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
4011 || (channels[i].flags &
4012 IEEE80211_CHAN_RADAR)) ? "" :
4013 ", IBSS",
4014 channels[i].flags &
4015 IEEE80211_CHAN_PASSIVE_SCAN ?
4016 "passive only" : "active/passive");
4017
4018 return len;
4019}
4020
4021static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
4022
4023static ssize_t show_statistics(struct device *d,
4024 struct device_attribute *attr, char *buf)
4025{
4026 struct iwl_priv *priv = dev_get_drvdata(d);
4027 u32 size = sizeof(struct iwl_notif_statistics);
4028 u32 len = 0, ofs = 0;
4029 u8 *data = (u8 *)&priv->statistics;
4030 int rc = 0;
4031
4032 if (!iwl_is_alive(priv))
4033 return -EAGAIN;
4034
4035 mutex_lock(&priv->mutex);
4036 rc = iwl_send_statistics_request(priv, 0);
4037 mutex_unlock(&priv->mutex);
4038
4039 if (rc) {
4040 len = sprintf(buf,
4041 "Error sending statistics request: 0x%08X\n", rc);
4042 return len;
4043 }
4044
4045 while (size && (PAGE_SIZE - len)) {
4046 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
4047 PAGE_SIZE - len, 1);
4048 len = strlen(buf);
4049 if (PAGE_SIZE - len)
4050 buf[len++] = '\n';
4051
4052 ofs += 16;
4053 size -= min(size, 16U);
4054 }
4055
4056 return len;
4057}
4058
4059static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
4060
4061static ssize_t show_status(struct device *d,
4062 struct device_attribute *attr, char *buf)
4063{
4064 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
4065 if (!iwl_is_alive(priv))
4066 return -EAGAIN;
4067 return sprintf(buf, "0x%08x\n", (int)priv->status);
4068}
4069
4070static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
4071
4072/*****************************************************************************
4073 *
4074 * driver setup and teardown
4075 *
4076 *****************************************************************************/
4077
4078static void iwl_setup_deferred_work(struct iwl_priv *priv)
4079{
4080 priv->workqueue = create_workqueue(DRV_NAME);
4081
4082 init_waitqueue_head(&priv->wait_command_queue);
4083
4084 INIT_WORK(&priv->up, iwl4965_bg_up);
4085 INIT_WORK(&priv->restart, iwl4965_bg_restart);
4086 INIT_WORK(&priv->rx_replenish, iwl4965_bg_rx_replenish);
4087 INIT_WORK(&priv->rf_kill, iwl4965_bg_rf_kill);
4088 INIT_WORK(&priv->beacon_update, iwl4965_bg_beacon_update);
4089 INIT_WORK(&priv->set_monitor, iwl4965_bg_set_monitor);
4090 INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
4091 INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start);
4092 INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start);
4093
4094 iwl_setup_scan_deferred_work(priv);
4095 iwl_setup_power_deferred_work(priv);
4096
4097 if (priv->cfg->ops->lib->setup_deferred_work)
4098 priv->cfg->ops->lib->setup_deferred_work(priv);
4099
4100 init_timer(&priv->statistics_periodic);
4101 priv->statistics_periodic.data = (unsigned long)priv;
4102 priv->statistics_periodic.function = iwl4965_bg_statistics_periodic;
4103
4104 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
4105 iwl4965_irq_tasklet, (unsigned long)priv);
4106}
4107
4108static void iwl_cancel_deferred_work(struct iwl_priv *priv)
4109{
4110 if (priv->cfg->ops->lib->cancel_deferred_work)
4111 priv->cfg->ops->lib->cancel_deferred_work(priv);
4112
4113 cancel_delayed_work_sync(&priv->init_alive_start);
4114 cancel_delayed_work(&priv->scan_check);
4115 cancel_delayed_work_sync(&priv->set_power_save);
4116 cancel_delayed_work(&priv->alive_start);
4117 cancel_work_sync(&priv->beacon_update);
4118 del_timer_sync(&priv->statistics_periodic);
4119}
4120
4121static struct attribute *iwl4965_sysfs_entries[] = {
4122 &dev_attr_channels.attr,
4123 &dev_attr_flags.attr,
4124 &dev_attr_filter_flags.attr,
4125#ifdef CONFIG_IWLAGN_SPECTRUM_MEASUREMENT
4126 &dev_attr_measurement.attr,
4127#endif
4128 &dev_attr_power_level.attr,
4129 &dev_attr_retry_rate.attr,
4130 &dev_attr_statistics.attr,
4131 &dev_attr_status.attr,
4132 &dev_attr_temperature.attr,
4133 &dev_attr_tx_power.attr,
4134#ifdef CONFIG_IWLWIFI_DEBUG
4135 &dev_attr_debug_level.attr,
4136#endif
4137 &dev_attr_version.attr,
4138
4139 NULL
4140};
4141
4142static struct attribute_group iwl4965_attribute_group = {
4143 .name = NULL, /* put in device directory */
4144 .attrs = iwl4965_sysfs_entries,
4145};
4146
4147static struct ieee80211_ops iwl4965_hw_ops = {
4148 .tx = iwl4965_mac_tx,
4149 .start = iwl4965_mac_start,
4150 .stop = iwl4965_mac_stop,
4151 .add_interface = iwl4965_mac_add_interface,
4152 .remove_interface = iwl4965_mac_remove_interface,
4153 .config = iwl4965_mac_config,
4154 .config_interface = iwl4965_mac_config_interface,
4155 .configure_filter = iwl4965_configure_filter,
4156 .set_key = iwl4965_mac_set_key,
4157 .update_tkip_key = iwl4965_mac_update_tkip_key,
4158 .get_stats = iwl4965_mac_get_stats,
4159 .get_tx_stats = iwl4965_mac_get_tx_stats,
4160 .conf_tx = iwl4965_mac_conf_tx,
4161 .reset_tsf = iwl4965_mac_reset_tsf,
4162 .bss_info_changed = iwl4965_bss_info_changed,
4163 .ampdu_action = iwl4965_mac_ampdu_action,
4164 .hw_scan = iwl_mac_hw_scan
4165};
4166
4167static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
4168{
4169 int err = 0;
4170 struct iwl_priv *priv;
4171 struct ieee80211_hw *hw;
4172 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
4173 unsigned long flags;
4174 DECLARE_MAC_BUF(mac);
4175
4176 /************************
4177 * 1. Allocating HW data
4178 ************************/
4179
4180 /* Disabling hardware scan means that mac80211 will perform scans
4181 * "the hard way", rather than using device's scan. */
4182 if (cfg->mod_params->disable_hw_scan) {
4183 if (cfg->mod_params->debug & IWL_DL_INFO)
4184 dev_printk(KERN_DEBUG, &(pdev->dev),
4185 "Disabling hw_scan\n");
4186 iwl4965_hw_ops.hw_scan = NULL;
4187 }
4188
4189 hw = iwl_alloc_all(cfg, &iwl4965_hw_ops);
4190 if (!hw) {
4191 err = -ENOMEM;
4192 goto out;
4193 }
4194 priv = hw->priv;
4195 /* At this point both hw and priv are allocated. */
4196
4197 SET_IEEE80211_DEV(hw, &pdev->dev);
4198
4199 IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
4200 priv->cfg = cfg;
4201 priv->pci_dev = pdev;
4202
4203#ifdef CONFIG_IWLWIFI_DEBUG
4204 priv->debug_level = priv->cfg->mod_params->debug;
4205 atomic_set(&priv->restrict_refcnt, 0);
4206#endif
4207
4208 /**************************
4209 * 2. Initializing PCI bus
4210 **************************/
4211 if (pci_enable_device(pdev)) {
4212 err = -ENODEV;
4213 goto out_ieee80211_free_hw;
4214 }
4215
4216 pci_set_master(pdev);
4217
4218 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(36));
4219 if (!err)
4220 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(36));
4221 if (err) {
4222 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
4223 if (!err)
4224 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
4225 /* both attempts failed: */
4226 if (err) {
4227 printk(KERN_WARNING "%s: No suitable DMA available.\n",
4228 DRV_NAME);
4229 goto out_pci_disable_device;
4230 }
4231 }
4232
4233 err = pci_request_regions(pdev, DRV_NAME);
4234 if (err)
4235 goto out_pci_disable_device;
4236
4237 pci_set_drvdata(pdev, priv);
4238
4239
4240 /***********************
4241 * 3. Read REV register
4242 ***********************/
4243 priv->hw_base = pci_iomap(pdev, 0, 0);
4244 if (!priv->hw_base) {
4245 err = -ENODEV;
4246 goto out_pci_release_regions;
4247 }
4248
4249 IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
4250 (unsigned long long) pci_resource_len(pdev, 0));
4251 IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base);
4252
4253 iwl_hw_detect(priv);
4254 printk(KERN_INFO DRV_NAME
4255 ": Detected Intel Wireless WiFi Link %s REV=0x%X\n",
4256 priv->cfg->name, priv->hw_rev);
4257
4258 /* We disable the RETRY_TIMEOUT register (0x41) to keep
4259 * PCI Tx retries from interfering with C3 CPU state */
4260 pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
4261
4262 /* amp init */
4263 err = priv->cfg->ops->lib->apm_ops.init(priv);
4264 if (err < 0) {
4265 IWL_DEBUG_INFO("Failed to init APMG\n");
4266 goto out_iounmap;
4267 }
4268 /*****************
4269 * 4. Read EEPROM
4270 *****************/
4271 /* Read the EEPROM */
4272 err = iwl_eeprom_init(priv);
4273 if (err) {
4274 IWL_ERROR("Unable to init EEPROM\n");
4275 goto out_iounmap;
4276 }
4277 err = iwl_eeprom_check_version(priv);
4278 if (err)
4279 goto out_iounmap;
4280
4281 /* extract MAC Address */
4282 iwl_eeprom_get_mac(priv, priv->mac_addr);
4283 IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac, priv->mac_addr));
4284 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
4285
4286 /************************
4287 * 5. Setup HW constants
4288 ************************/
4289 if (iwl_set_hw_params(priv)) {
4290 IWL_ERROR("failed to set hw parameters\n");
4291 goto out_free_eeprom;
4292 }
4293
4294 /*******************
4295 * 6. Setup priv
4296 *******************/
4297
4298 err = iwl_init_drv(priv);
4299 if (err)
4300 goto out_free_eeprom;
4301 /* At this point both hw and priv are initialized. */
4302
4303 /**********************************
4304 * 7. Initialize module parameters
4305 **********************************/
4306
4307 /* Disable radio (SW RF KILL) via parameter when loading driver */
4308 if (priv->cfg->mod_params->disable) {
4309 set_bit(STATUS_RF_KILL_SW, &priv->status);
4310 IWL_DEBUG_INFO("Radio disabled.\n");
4311 }
4312
4313 /********************
4314 * 8. Setup services
4315 ********************/
4316 spin_lock_irqsave(&priv->lock, flags);
4317 iwl4965_disable_interrupts(priv);
4318 spin_unlock_irqrestore(&priv->lock, flags);
4319
4320 err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group);
4321 if (err) {
4322 IWL_ERROR("failed to create sysfs device attributes\n");
4323 goto out_uninit_drv;
4324 }
4325
4326
4327 iwl_setup_deferred_work(priv);
4328 iwl_setup_rx_handlers(priv);
4329
4330 /********************
4331 * 9. Conclude
4332 ********************/
4333 pci_save_state(pdev);
4334 pci_disable_device(pdev);
4335
4336 /**********************************
4337 * 10. Setup and register mac80211
4338 **********************************/
4339
4340 err = iwl_setup_mac(priv);
4341 if (err)
4342 goto out_remove_sysfs;
4343
4344 err = iwl_dbgfs_register(priv, DRV_NAME);
4345 if (err)
4346 IWL_ERROR("failed to create debugfs files\n");
4347
4348 err = iwl_rfkill_init(priv);
4349 if (err)
4350 IWL_ERROR("Unable to initialize RFKILL system. "
4351 "Ignoring error: %d\n", err);
4352 iwl_power_initialize(priv);
4353 return 0;
4354
4355 out_remove_sysfs:
4356 sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
4357 out_uninit_drv:
4358 iwl_uninit_drv(priv);
4359 out_free_eeprom:
4360 iwl_eeprom_free(priv);
4361 out_iounmap:
4362 pci_iounmap(pdev, priv->hw_base);
4363 out_pci_release_regions:
4364 pci_release_regions(pdev);
4365 pci_set_drvdata(pdev, NULL);
4366 out_pci_disable_device:
4367 pci_disable_device(pdev);
4368 out_ieee80211_free_hw:
4369 ieee80211_free_hw(priv->hw);
4370 out:
4371 return err;
4372}
4373
4374static void __devexit iwl4965_pci_remove(struct pci_dev *pdev)
4375{
4376 struct iwl_priv *priv = pci_get_drvdata(pdev);
4377 unsigned long flags;
4378
4379 if (!priv)
4380 return;
4381
4382 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
4383
4384 iwl_dbgfs_unregister(priv);
4385 sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
4386
4387 /* ieee80211_unregister_hw call wil cause iwl4965_mac_stop to
4388 * to be called and iwl4965_down since we are removing the device
4389 * we need to set STATUS_EXIT_PENDING bit.
4390 */
4391 set_bit(STATUS_EXIT_PENDING, &priv->status);
4392 if (priv->mac80211_registered) {
4393 ieee80211_unregister_hw(priv->hw);
4394 priv->mac80211_registered = 0;
4395 } else {
4396 iwl4965_down(priv);
4397 }
4398
4399 /* make sure we flush any pending irq or
4400 * tasklet for the driver
4401 */
4402 spin_lock_irqsave(&priv->lock, flags);
4403 iwl4965_disable_interrupts(priv);
4404 spin_unlock_irqrestore(&priv->lock, flags);
4405
4406 iwl_synchronize_irq(priv);
4407
4408 iwl_rfkill_unregister(priv);
4409 iwl4965_dealloc_ucode_pci(priv);
4410
4411 if (priv->rxq.bd)
4412 iwl_rx_queue_free(priv, &priv->rxq);
4413 iwl_hw_txq_ctx_free(priv);
4414
4415 iwl_clear_stations_table(priv);
4416 iwl_eeprom_free(priv);
4417
4418
4419 /*netif_stop_queue(dev); */
4420 flush_workqueue(priv->workqueue);
4421
4422 /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes
4423 * priv->workqueue... so we can't take down the workqueue
4424 * until now... */
4425 destroy_workqueue(priv->workqueue);
4426 priv->workqueue = NULL;
4427
4428 pci_iounmap(pdev, priv->hw_base);
4429 pci_release_regions(pdev);
4430 pci_disable_device(pdev);
4431 pci_set_drvdata(pdev, NULL);
4432
4433 iwl_uninit_drv(priv);
4434
4435 if (priv->ibss_beacon)
4436 dev_kfree_skb(priv->ibss_beacon);
4437
4438 ieee80211_free_hw(priv->hw);
4439}
4440
4441#ifdef CONFIG_PM
4442
4443static int iwl4965_pci_suspend(struct pci_dev *pdev, pm_message_t state)
4444{
4445 struct iwl_priv *priv = pci_get_drvdata(pdev);
4446
4447 if (priv->is_open) {
4448 set_bit(STATUS_IN_SUSPEND, &priv->status);
4449 iwl4965_mac_stop(priv->hw);
4450 priv->is_open = 1;
4451 }
4452
4453 pci_set_power_state(pdev, PCI_D3hot);
4454
4455 return 0;
4456}
4457
4458static int iwl4965_pci_resume(struct pci_dev *pdev)
4459{
4460 struct iwl_priv *priv = pci_get_drvdata(pdev);
4461
4462 pci_set_power_state(pdev, PCI_D0);
4463
4464 if (priv->is_open)
4465 iwl4965_mac_start(priv->hw);
4466
4467 clear_bit(STATUS_IN_SUSPEND, &priv->status);
4468 return 0;
4469}
4470
4471#endif /* CONFIG_PM */
4472
4473/*****************************************************************************
4474 *
4475 * driver and module entry point
4476 *
4477 *****************************************************************************/
4478
4479/* Hardware specific file defines the PCI IDs table for that hardware module */
4480static struct pci_device_id iwl_hw_card_ids[] = {
4481#ifdef CONFIG_IWL4965
4482 {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID, iwl4965_agn_cfg)},
4483 {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID, iwl4965_agn_cfg)},
4484#endif /* CONFIG_IWL4965 */
4485#ifdef CONFIG_IWL5000
4486 {IWL_PCI_DEVICE(0x4232, 0x1205, iwl5100_bg_cfg)},
4487 {IWL_PCI_DEVICE(0x4232, 0x1305, iwl5100_bg_cfg)},
4488 {IWL_PCI_DEVICE(0x4232, 0x1206, iwl5100_abg_cfg)},
4489 {IWL_PCI_DEVICE(0x4232, 0x1306, iwl5100_abg_cfg)},
4490 {IWL_PCI_DEVICE(0x4232, 0x1326, iwl5100_abg_cfg)},
4491 {IWL_PCI_DEVICE(0x4237, 0x1216, iwl5100_abg_cfg)},
4492 {IWL_PCI_DEVICE(0x4232, PCI_ANY_ID, iwl5100_agn_cfg)},
4493 {IWL_PCI_DEVICE(0x4235, PCI_ANY_ID, iwl5300_agn_cfg)},
4494 {IWL_PCI_DEVICE(0x4236, PCI_ANY_ID, iwl5300_agn_cfg)},
4495 {IWL_PCI_DEVICE(0x4237, PCI_ANY_ID, iwl5100_agn_cfg)},
4496/* 5350 WiFi/WiMax */
4497 {IWL_PCI_DEVICE(0x423A, 0x1001, iwl5350_agn_cfg)},
4498 {IWL_PCI_DEVICE(0x423A, 0x1021, iwl5350_agn_cfg)},
4499 {IWL_PCI_DEVICE(0x423B, 0x1011, iwl5350_agn_cfg)},
4500#endif /* CONFIG_IWL5000 */
4501 {0}
4502};
4503MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids);
4504
4505static struct pci_driver iwl_driver = {
4506 .name = DRV_NAME,
4507 .id_table = iwl_hw_card_ids,
4508 .probe = iwl4965_pci_probe,
4509 .remove = __devexit_p(iwl4965_pci_remove),
4510#ifdef CONFIG_PM
4511 .suspend = iwl4965_pci_suspend,
4512 .resume = iwl4965_pci_resume,
4513#endif
4514};
4515
4516static int __init iwl4965_init(void)
4517{
4518
4519 int ret;
4520 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
4521 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
4522
4523 ret = iwlagn_rate_control_register();
4524 if (ret) {
4525 IWL_ERROR("Unable to register rate control algorithm: %d\n", ret);
4526 return ret;
4527 }
4528
4529 ret = pci_register_driver(&iwl_driver);
4530 if (ret) {
4531 IWL_ERROR("Unable to initialize PCI module\n");
4532 goto error_register;
4533 }
4534
4535 return ret;
4536
4537error_register:
4538 iwlagn_rate_control_unregister();
4539 return ret;
4540}
4541
4542static void __exit iwl4965_exit(void)
4543{
4544 pci_unregister_driver(&iwl_driver);
4545 iwlagn_rate_control_unregister();
4546}
4547
4548module_exit(iwl4965_exit);
4549module_init(iwl4965_init);
diff --git a/drivers/net/wireless/iwlwifi/iwl-calib.c b/drivers/net/wireless/iwlwifi/iwl-calib.c
new file mode 100644
index 000000000000..72fbf47229db
--- /dev/null
+++ b/drivers/net/wireless/iwlwifi/iwl-calib.c
@@ -0,0 +1,869 @@
1/******************************************************************************
2 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
8 * Copyright(c) 2008 Intel Corporation. All rights reserved.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
22 * USA
23 *
24 * The full GNU General Public License is included in this distribution
25 * in the file called LICENSE.GPL.
26 *
27 * Contact Information:
28 * Tomas Winkler <tomas.winkler@intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 *
31 * BSD LICENSE
32 *
33 * Copyright(c) 2005 - 2008 Intel Corporation. All rights reserved.
34 * All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 *
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
45 * distribution.
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 *****************************************************************************/
62
63#include <net/mac80211.h>
64
65#include "iwl-dev.h"
66#include "iwl-core.h"
67#include "iwl-calib.h"
68
69/*****************************************************************************
70 * INIT calibrations framework
71 *****************************************************************************/
72
73 int iwl_send_calib_results(struct iwl_priv *priv)
74{
75 int ret = 0;
76 int i = 0;
77
78 struct iwl_host_cmd hcmd = {
79 .id = REPLY_PHY_CALIBRATION_CMD,
80 .meta.flags = CMD_SIZE_HUGE,
81 };
82
83 for (i = 0; i < IWL_CALIB_MAX; i++)
84 if (priv->calib_results[i].buf) {
85 hcmd.len = priv->calib_results[i].buf_len;
86 hcmd.data = priv->calib_results[i].buf;
87 ret = iwl_send_cmd_sync(priv, &hcmd);
88 if (ret)
89 goto err;
90 }
91
92 return 0;
93err:
94 IWL_ERROR("Error %d iteration %d\n", ret, i);
95 return ret;
96}
97EXPORT_SYMBOL(iwl_send_calib_results);
98
99int iwl_calib_set(struct iwl_calib_result *res, const u8 *buf, int len)
100{
101 if (res->buf_len != len) {
102 kfree(res->buf);
103 res->buf = kzalloc(len, GFP_ATOMIC);
104 }
105 if (unlikely(res->buf == NULL))
106 return -ENOMEM;
107
108 res->buf_len = len;
109 memcpy(res->buf, buf, len);
110 return 0;
111}
112EXPORT_SYMBOL(iwl_calib_set);
113
114void iwl_calib_free_results(struct iwl_priv *priv)
115{
116 int i;
117
118 for (i = 0; i < IWL_CALIB_MAX; i++) {
119 kfree(priv->calib_results[i].buf);
120 priv->calib_results[i].buf = NULL;
121 priv->calib_results[i].buf_len = 0;
122 }
123}
124
125/*****************************************************************************
126 * RUNTIME calibrations framework
127 *****************************************************************************/
128
129/* "false alarms" are signals that our DSP tries to lock onto,
130 * but then determines that they are either noise, or transmissions
131 * from a distant wireless network (also "noise", really) that get
132 * "stepped on" by stronger transmissions within our own network.
133 * This algorithm attempts to set a sensitivity level that is high
134 * enough to receive all of our own network traffic, but not so
135 * high that our DSP gets too busy trying to lock onto non-network
136 * activity/noise. */
137static int iwl_sens_energy_cck(struct iwl_priv *priv,
138 u32 norm_fa,
139 u32 rx_enable_time,
140 struct statistics_general_data *rx_info)
141{
142 u32 max_nrg_cck = 0;
143 int i = 0;
144 u8 max_silence_rssi = 0;
145 u32 silence_ref = 0;
146 u8 silence_rssi_a = 0;
147 u8 silence_rssi_b = 0;
148 u8 silence_rssi_c = 0;
149 u32 val;
150
151 /* "false_alarms" values below are cross-multiplications to assess the
152 * numbers of false alarms within the measured period of actual Rx
153 * (Rx is off when we're txing), vs the min/max expected false alarms
154 * (some should be expected if rx is sensitive enough) in a
155 * hypothetical listening period of 200 time units (TU), 204.8 msec:
156 *
157 * MIN_FA/fixed-time < false_alarms/actual-rx-time < MAX_FA/beacon-time
158 *
159 * */
160 u32 false_alarms = norm_fa * 200 * 1024;
161 u32 max_false_alarms = MAX_FA_CCK * rx_enable_time;
162 u32 min_false_alarms = MIN_FA_CCK * rx_enable_time;
163 struct iwl_sensitivity_data *data = NULL;
164 const struct iwl_sensitivity_ranges *ranges = priv->hw_params.sens;
165
166 data = &(priv->sensitivity_data);
167
168 data->nrg_auto_corr_silence_diff = 0;
169
170 /* Find max silence rssi among all 3 receivers.
171 * This is background noise, which may include transmissions from other
172 * networks, measured during silence before our network's beacon */
173 silence_rssi_a = (u8)((rx_info->beacon_silence_rssi_a &
174 ALL_BAND_FILTER) >> 8);
175 silence_rssi_b = (u8)((rx_info->beacon_silence_rssi_b &
176 ALL_BAND_FILTER) >> 8);
177 silence_rssi_c = (u8)((rx_info->beacon_silence_rssi_c &
178 ALL_BAND_FILTER) >> 8);
179
180 val = max(silence_rssi_b, silence_rssi_c);
181 max_silence_rssi = max(silence_rssi_a, (u8) val);
182
183 /* Store silence rssi in 20-beacon history table */
184 data->nrg_silence_rssi[data->nrg_silence_idx] = max_silence_rssi;
185 data->nrg_silence_idx++;
186 if (data->nrg_silence_idx >= NRG_NUM_PREV_STAT_L)
187 data->nrg_silence_idx = 0;
188
189 /* Find max silence rssi across 20 beacon history */
190 for (i = 0; i < NRG_NUM_PREV_STAT_L; i++) {
191 val = data->nrg_silence_rssi[i];
192 silence_ref = max(silence_ref, val);
193 }
194 IWL_DEBUG_CALIB("silence a %u, b %u, c %u, 20-bcn max %u\n",
195 silence_rssi_a, silence_rssi_b, silence_rssi_c,
196 silence_ref);
197
198 /* Find max rx energy (min value!) among all 3 receivers,
199 * measured during beacon frame.
200 * Save it in 10-beacon history table. */
201 i = data->nrg_energy_idx;
202 val = min(rx_info->beacon_energy_b, rx_info->beacon_energy_c);
203 data->nrg_value[i] = min(rx_info->beacon_energy_a, val);
204
205 data->nrg_energy_idx++;
206 if (data->nrg_energy_idx >= 10)
207 data->nrg_energy_idx = 0;
208
209 /* Find min rx energy (max value) across 10 beacon history.
210 * This is the minimum signal level that we want to receive well.
211 * Add backoff (margin so we don't miss slightly lower energy frames).
212 * This establishes an upper bound (min value) for energy threshold. */
213 max_nrg_cck = data->nrg_value[0];
214 for (i = 1; i < 10; i++)
215 max_nrg_cck = (u32) max(max_nrg_cck, (data->nrg_value[i]));
216 max_nrg_cck += 6;
217
218 IWL_DEBUG_CALIB("rx energy a %u, b %u, c %u, 10-bcn max/min %u\n",
219 rx_info->beacon_energy_a, rx_info->beacon_energy_b,
220 rx_info->beacon_energy_c, max_nrg_cck - 6);
221
222 /* Count number of consecutive beacons with fewer-than-desired
223 * false alarms. */
224 if (false_alarms < min_false_alarms)
225 data->num_in_cck_no_fa++;
226 else
227 data->num_in_cck_no_fa = 0;
228 IWL_DEBUG_CALIB("consecutive bcns with few false alarms = %u\n",
229 data->num_in_cck_no_fa);
230
231 /* If we got too many false alarms this time, reduce sensitivity */
232 if ((false_alarms > max_false_alarms) &&
233 (data->auto_corr_cck > AUTO_CORR_MAX_TH_CCK)) {
234 IWL_DEBUG_CALIB("norm FA %u > max FA %u\n",
235 false_alarms, max_false_alarms);
236 IWL_DEBUG_CALIB("... reducing sensitivity\n");
237 data->nrg_curr_state = IWL_FA_TOO_MANY;
238 /* Store for "fewer than desired" on later beacon */
239 data->nrg_silence_ref = silence_ref;
240
241 /* increase energy threshold (reduce nrg value)
242 * to decrease sensitivity */
243 if (data->nrg_th_cck >
244 (ranges->max_nrg_cck + NRG_STEP_CCK))
245 data->nrg_th_cck = data->nrg_th_cck
246 - NRG_STEP_CCK;
247 else
248 data->nrg_th_cck = ranges->max_nrg_cck;
249 /* Else if we got fewer than desired, increase sensitivity */
250 } else if (false_alarms < min_false_alarms) {
251 data->nrg_curr_state = IWL_FA_TOO_FEW;
252
253 /* Compare silence level with silence level for most recent
254 * healthy number or too many false alarms */
255 data->nrg_auto_corr_silence_diff = (s32)data->nrg_silence_ref -
256 (s32)silence_ref;
257
258 IWL_DEBUG_CALIB("norm FA %u < min FA %u, silence diff %d\n",
259 false_alarms, min_false_alarms,
260 data->nrg_auto_corr_silence_diff);
261
262 /* Increase value to increase sensitivity, but only if:
263 * 1a) previous beacon did *not* have *too many* false alarms
264 * 1b) AND there's a significant difference in Rx levels
265 * from a previous beacon with too many, or healthy # FAs
266 * OR 2) We've seen a lot of beacons (100) with too few
267 * false alarms */
268 if ((data->nrg_prev_state != IWL_FA_TOO_MANY) &&
269 ((data->nrg_auto_corr_silence_diff > NRG_DIFF) ||
270 (data->num_in_cck_no_fa > MAX_NUMBER_CCK_NO_FA))) {
271
272 IWL_DEBUG_CALIB("... increasing sensitivity\n");
273 /* Increase nrg value to increase sensitivity */
274 val = data->nrg_th_cck + NRG_STEP_CCK;
275 data->nrg_th_cck = min((u32)ranges->min_nrg_cck, val);
276 } else {
277 IWL_DEBUG_CALIB("... but not changing sensitivity\n");
278 }
279
280 /* Else we got a healthy number of false alarms, keep status quo */
281 } else {
282 IWL_DEBUG_CALIB(" FA in safe zone\n");
283 data->nrg_curr_state = IWL_FA_GOOD_RANGE;
284
285 /* Store for use in "fewer than desired" with later beacon */
286 data->nrg_silence_ref = silence_ref;
287
288 /* If previous beacon had too many false alarms,
289 * give it some extra margin by reducing sensitivity again
290 * (but don't go below measured energy of desired Rx) */
291 if (IWL_FA_TOO_MANY == data->nrg_prev_state) {
292 IWL_DEBUG_CALIB("... increasing margin\n");
293 if (data->nrg_th_cck > (max_nrg_cck + NRG_MARGIN))
294 data->nrg_th_cck -= NRG_MARGIN;
295 else
296 data->nrg_th_cck = max_nrg_cck;
297 }
298 }
299
300 /* Make sure the energy threshold does not go above the measured
301 * energy of the desired Rx signals (reduced by backoff margin),
302 * or else we might start missing Rx frames.
303 * Lower value is higher energy, so we use max()!
304 */
305 data->nrg_th_cck = max(max_nrg_cck, data->nrg_th_cck);
306 IWL_DEBUG_CALIB("new nrg_th_cck %u\n", data->nrg_th_cck);
307
308 data->nrg_prev_state = data->nrg_curr_state;
309
310 /* Auto-correlation CCK algorithm */
311 if (false_alarms > min_false_alarms) {
312
313 /* increase auto_corr values to decrease sensitivity
314 * so the DSP won't be disturbed by the noise
315 */
316 if (data->auto_corr_cck < AUTO_CORR_MAX_TH_CCK)
317 data->auto_corr_cck = AUTO_CORR_MAX_TH_CCK + 1;
318 else {
319 val = data->auto_corr_cck + AUTO_CORR_STEP_CCK;
320 data->auto_corr_cck =
321 min((u32)ranges->auto_corr_max_cck, val);
322 }
323 val = data->auto_corr_cck_mrc + AUTO_CORR_STEP_CCK;
324 data->auto_corr_cck_mrc =
325 min((u32)ranges->auto_corr_max_cck_mrc, val);
326 } else if ((false_alarms < min_false_alarms) &&
327 ((data->nrg_auto_corr_silence_diff > NRG_DIFF) ||
328 (data->num_in_cck_no_fa > MAX_NUMBER_CCK_NO_FA))) {
329
330 /* Decrease auto_corr values to increase sensitivity */
331 val = data->auto_corr_cck - AUTO_CORR_STEP_CCK;
332 data->auto_corr_cck =
333 max((u32)ranges->auto_corr_min_cck, val);
334 val = data->auto_corr_cck_mrc - AUTO_CORR_STEP_CCK;
335 data->auto_corr_cck_mrc =
336 max((u32)ranges->auto_corr_min_cck_mrc, val);
337 }
338
339 return 0;
340}
341
342
343static int iwl_sens_auto_corr_ofdm(struct iwl_priv *priv,
344 u32 norm_fa,
345 u32 rx_enable_time)
346{
347 u32 val;
348 u32 false_alarms = norm_fa * 200 * 1024;
349 u32 max_false_alarms = MAX_FA_OFDM * rx_enable_time;
350 u32 min_false_alarms = MIN_FA_OFDM * rx_enable_time;
351 struct iwl_sensitivity_data *data = NULL;
352 const struct iwl_sensitivity_ranges *ranges = priv->hw_params.sens;
353
354 data = &(priv->sensitivity_data);
355
356 /* If we got too many false alarms this time, reduce sensitivity */
357 if (false_alarms > max_false_alarms) {
358
359 IWL_DEBUG_CALIB("norm FA %u > max FA %u)\n",
360 false_alarms, max_false_alarms);
361
362 val = data->auto_corr_ofdm + AUTO_CORR_STEP_OFDM;
363 data->auto_corr_ofdm =
364 min((u32)ranges->auto_corr_max_ofdm, val);
365
366 val = data->auto_corr_ofdm_mrc + AUTO_CORR_STEP_OFDM;
367 data->auto_corr_ofdm_mrc =
368 min((u32)ranges->auto_corr_max_ofdm_mrc, val);
369
370 val = data->auto_corr_ofdm_x1 + AUTO_CORR_STEP_OFDM;
371 data->auto_corr_ofdm_x1 =
372 min((u32)ranges->auto_corr_max_ofdm_x1, val);
373
374 val = data->auto_corr_ofdm_mrc_x1 + AUTO_CORR_STEP_OFDM;
375 data->auto_corr_ofdm_mrc_x1 =
376 min((u32)ranges->auto_corr_max_ofdm_mrc_x1, val);
377 }
378
379 /* Else if we got fewer than desired, increase sensitivity */
380 else if (false_alarms < min_false_alarms) {
381
382 IWL_DEBUG_CALIB("norm FA %u < min FA %u\n",
383 false_alarms, min_false_alarms);
384
385 val = data->auto_corr_ofdm - AUTO_CORR_STEP_OFDM;
386 data->auto_corr_ofdm =
387 max((u32)ranges->auto_corr_min_ofdm, val);
388
389 val = data->auto_corr_ofdm_mrc - AUTO_CORR_STEP_OFDM;
390 data->auto_corr_ofdm_mrc =
391 max((u32)ranges->auto_corr_min_ofdm_mrc, val);
392
393 val = data->auto_corr_ofdm_x1 - AUTO_CORR_STEP_OFDM;
394 data->auto_corr_ofdm_x1 =
395 max((u32)ranges->auto_corr_min_ofdm_x1, val);
396
397 val = data->auto_corr_ofdm_mrc_x1 - AUTO_CORR_STEP_OFDM;
398 data->auto_corr_ofdm_mrc_x1 =
399 max((u32)ranges->auto_corr_min_ofdm_mrc_x1, val);
400 } else {
401 IWL_DEBUG_CALIB("min FA %u < norm FA %u < max FA %u OK\n",
402 min_false_alarms, false_alarms, max_false_alarms);
403 }
404 return 0;
405}
406
407/* Prepare a SENSITIVITY_CMD, send to uCode if values have changed */
408static int iwl_sensitivity_write(struct iwl_priv *priv)
409{
410 int ret = 0;
411 struct iwl_sensitivity_cmd cmd ;
412 struct iwl_sensitivity_data *data = NULL;
413 struct iwl_host_cmd cmd_out = {
414 .id = SENSITIVITY_CMD,
415 .len = sizeof(struct iwl_sensitivity_cmd),
416 .meta.flags = CMD_ASYNC,
417 .data = &cmd,
418 };
419
420 data = &(priv->sensitivity_data);
421
422 memset(&cmd, 0, sizeof(cmd));
423
424 cmd.table[HD_AUTO_CORR32_X4_TH_ADD_MIN_INDEX] =
425 cpu_to_le16((u16)data->auto_corr_ofdm);
426 cmd.table[HD_AUTO_CORR32_X4_TH_ADD_MIN_MRC_INDEX] =
427 cpu_to_le16((u16)data->auto_corr_ofdm_mrc);
428 cmd.table[HD_AUTO_CORR32_X1_TH_ADD_MIN_INDEX] =
429 cpu_to_le16((u16)data->auto_corr_ofdm_x1);
430 cmd.table[HD_AUTO_CORR32_X1_TH_ADD_MIN_MRC_INDEX] =
431 cpu_to_le16((u16)data->auto_corr_ofdm_mrc_x1);
432
433 cmd.table[HD_AUTO_CORR40_X4_TH_ADD_MIN_INDEX] =
434 cpu_to_le16((u16)data->auto_corr_cck);
435 cmd.table[HD_AUTO_CORR40_X4_TH_ADD_MIN_MRC_INDEX] =
436 cpu_to_le16((u16)data->auto_corr_cck_mrc);
437
438 cmd.table[HD_MIN_ENERGY_CCK_DET_INDEX] =
439 cpu_to_le16((u16)data->nrg_th_cck);
440 cmd.table[HD_MIN_ENERGY_OFDM_DET_INDEX] =
441 cpu_to_le16((u16)data->nrg_th_ofdm);
442
443 cmd.table[HD_BARKER_CORR_TH_ADD_MIN_INDEX] =
444 __constant_cpu_to_le16(190);
445 cmd.table[HD_BARKER_CORR_TH_ADD_MIN_MRC_INDEX] =
446 __constant_cpu_to_le16(390);
447 cmd.table[HD_OFDM_ENERGY_TH_IN_INDEX] =
448 __constant_cpu_to_le16(62);
449
450 IWL_DEBUG_CALIB("ofdm: ac %u mrc %u x1 %u mrc_x1 %u thresh %u\n",
451 data->auto_corr_ofdm, data->auto_corr_ofdm_mrc,
452 data->auto_corr_ofdm_x1, data->auto_corr_ofdm_mrc_x1,
453 data->nrg_th_ofdm);
454
455 IWL_DEBUG_CALIB("cck: ac %u mrc %u thresh %u\n",
456 data->auto_corr_cck, data->auto_corr_cck_mrc,
457 data->nrg_th_cck);
458
459 /* Update uCode's "work" table, and copy it to DSP */
460 cmd.control = SENSITIVITY_CMD_CONTROL_WORK_TABLE;
461
462 /* Don't send command to uCode if nothing has changed */
463 if (!memcmp(&cmd.table[0], &(priv->sensitivity_tbl[0]),
464 sizeof(u16)*HD_TABLE_SIZE)) {
465 IWL_DEBUG_CALIB("No change in SENSITIVITY_CMD\n");
466 return 0;
467 }
468
469 /* Copy table for comparison next time */
470 memcpy(&(priv->sensitivity_tbl[0]), &(cmd.table[0]),
471 sizeof(u16)*HD_TABLE_SIZE);
472
473 ret = iwl_send_cmd(priv, &cmd_out);
474 if (ret)
475 IWL_ERROR("SENSITIVITY_CMD failed\n");
476
477 return ret;
478}
479
480void iwl_init_sensitivity(struct iwl_priv *priv)
481{
482 int ret = 0;
483 int i;
484 struct iwl_sensitivity_data *data = NULL;
485 const struct iwl_sensitivity_ranges *ranges = priv->hw_params.sens;
486
487 if (priv->disable_sens_cal)
488 return;
489
490 IWL_DEBUG_CALIB("Start iwl_init_sensitivity\n");
491
492 /* Clear driver's sensitivity algo data */
493 data = &(priv->sensitivity_data);
494
495 if (ranges == NULL)
496 return;
497
498 memset(data, 0, sizeof(struct iwl_sensitivity_data));
499
500 data->num_in_cck_no_fa = 0;
501 data->nrg_curr_state = IWL_FA_TOO_MANY;
502 data->nrg_prev_state = IWL_FA_TOO_MANY;
503 data->nrg_silence_ref = 0;
504 data->nrg_silence_idx = 0;
505 data->nrg_energy_idx = 0;
506
507 for (i = 0; i < 10; i++)
508 data->nrg_value[i] = 0;
509
510 for (i = 0; i < NRG_NUM_PREV_STAT_L; i++)
511 data->nrg_silence_rssi[i] = 0;
512
513 data->auto_corr_ofdm = 90;
514 data->auto_corr_ofdm_mrc = ranges->auto_corr_min_ofdm_mrc;
515 data->auto_corr_ofdm_x1 = ranges->auto_corr_min_ofdm_x1;
516 data->auto_corr_ofdm_mrc_x1 = ranges->auto_corr_min_ofdm_mrc_x1;
517 data->auto_corr_cck = AUTO_CORR_CCK_MIN_VAL_DEF;
518 data->auto_corr_cck_mrc = ranges->auto_corr_min_cck_mrc;
519 data->nrg_th_cck = ranges->nrg_th_cck;
520 data->nrg_th_ofdm = ranges->nrg_th_ofdm;
521
522 data->last_bad_plcp_cnt_ofdm = 0;
523 data->last_fa_cnt_ofdm = 0;
524 data->last_bad_plcp_cnt_cck = 0;
525 data->last_fa_cnt_cck = 0;
526
527 ret |= iwl_sensitivity_write(priv);
528 IWL_DEBUG_CALIB("<<return 0x%X\n", ret);
529}
530EXPORT_SYMBOL(iwl_init_sensitivity);
531
532void iwl_sensitivity_calibration(struct iwl_priv *priv,
533 struct iwl_notif_statistics *resp)
534{
535 u32 rx_enable_time;
536 u32 fa_cck;
537 u32 fa_ofdm;
538 u32 bad_plcp_cck;
539 u32 bad_plcp_ofdm;
540 u32 norm_fa_ofdm;
541 u32 norm_fa_cck;
542 struct iwl_sensitivity_data *data = NULL;
543 struct statistics_rx_non_phy *rx_info = &(resp->rx.general);
544 struct statistics_rx *statistics = &(resp->rx);
545 unsigned long flags;
546 struct statistics_general_data statis;
547
548 if (priv->disable_sens_cal)
549 return;
550
551 data = &(priv->sensitivity_data);
552
553 if (!iwl_is_associated(priv)) {
554 IWL_DEBUG_CALIB("<< - not associated\n");
555 return;
556 }
557
558 spin_lock_irqsave(&priv->lock, flags);
559 if (rx_info->interference_data_flag != INTERFERENCE_DATA_AVAILABLE) {
560 IWL_DEBUG_CALIB("<< invalid data.\n");
561 spin_unlock_irqrestore(&priv->lock, flags);
562 return;
563 }
564
565 /* Extract Statistics: */
566 rx_enable_time = le32_to_cpu(rx_info->channel_load);
567 fa_cck = le32_to_cpu(statistics->cck.false_alarm_cnt);
568 fa_ofdm = le32_to_cpu(statistics->ofdm.false_alarm_cnt);
569 bad_plcp_cck = le32_to_cpu(statistics->cck.plcp_err);
570 bad_plcp_ofdm = le32_to_cpu(statistics->ofdm.plcp_err);
571
572 statis.beacon_silence_rssi_a =
573 le32_to_cpu(statistics->general.beacon_silence_rssi_a);
574 statis.beacon_silence_rssi_b =
575 le32_to_cpu(statistics->general.beacon_silence_rssi_b);
576 statis.beacon_silence_rssi_c =
577 le32_to_cpu(statistics->general.beacon_silence_rssi_c);
578 statis.beacon_energy_a =
579 le32_to_cpu(statistics->general.beacon_energy_a);
580 statis.beacon_energy_b =
581 le32_to_cpu(statistics->general.beacon_energy_b);
582 statis.beacon_energy_c =
583 le32_to_cpu(statistics->general.beacon_energy_c);
584
585 spin_unlock_irqrestore(&priv->lock, flags);
586
587 IWL_DEBUG_CALIB("rx_enable_time = %u usecs\n", rx_enable_time);
588
589 if (!rx_enable_time) {
590 IWL_DEBUG_CALIB("<< RX Enable Time == 0! \n");
591 return;
592 }
593
594 /* These statistics increase monotonically, and do not reset
595 * at each beacon. Calculate difference from last value, or just
596 * use the new statistics value if it has reset or wrapped around. */
597 if (data->last_bad_plcp_cnt_cck > bad_plcp_cck)
598 data->last_bad_plcp_cnt_cck = bad_plcp_cck;
599 else {
600 bad_plcp_cck -= data->last_bad_plcp_cnt_cck;
601 data->last_bad_plcp_cnt_cck += bad_plcp_cck;
602 }
603
604 if (data->last_bad_plcp_cnt_ofdm > bad_plcp_ofdm)
605 data->last_bad_plcp_cnt_ofdm = bad_plcp_ofdm;
606 else {
607 bad_plcp_ofdm -= data->last_bad_plcp_cnt_ofdm;
608 data->last_bad_plcp_cnt_ofdm += bad_plcp_ofdm;
609 }
610
611 if (data->last_fa_cnt_ofdm > fa_ofdm)
612 data->last_fa_cnt_ofdm = fa_ofdm;
613 else {
614 fa_ofdm -= data->last_fa_cnt_ofdm;
615 data->last_fa_cnt_ofdm += fa_ofdm;
616 }
617
618 if (data->last_fa_cnt_cck > fa_cck)
619 data->last_fa_cnt_cck = fa_cck;
620 else {
621 fa_cck -= data->last_fa_cnt_cck;
622 data->last_fa_cnt_cck += fa_cck;
623 }
624
625 /* Total aborted signal locks */
626 norm_fa_ofdm = fa_ofdm + bad_plcp_ofdm;
627 norm_fa_cck = fa_cck + bad_plcp_cck;
628
629 IWL_DEBUG_CALIB("cck: fa %u badp %u ofdm: fa %u badp %u\n", fa_cck,
630 bad_plcp_cck, fa_ofdm, bad_plcp_ofdm);
631
632 iwl_sens_auto_corr_ofdm(priv, norm_fa_ofdm, rx_enable_time);
633 iwl_sens_energy_cck(priv, norm_fa_cck, rx_enable_time, &statis);
634 iwl_sensitivity_write(priv);
635
636 return;
637}
638EXPORT_SYMBOL(iwl_sensitivity_calibration);
639
640/*
641 * Accumulate 20 beacons of signal and noise statistics for each of
642 * 3 receivers/antennas/rx-chains, then figure out:
643 * 1) Which antennas are connected.
644 * 2) Differential rx gain settings to balance the 3 receivers.
645 */
646void iwl_chain_noise_calibration(struct iwl_priv *priv,
647 struct iwl_notif_statistics *stat_resp)
648{
649 struct iwl_chain_noise_data *data = NULL;
650
651 u32 chain_noise_a;
652 u32 chain_noise_b;
653 u32 chain_noise_c;
654 u32 chain_sig_a;
655 u32 chain_sig_b;
656 u32 chain_sig_c;
657 u32 average_sig[NUM_RX_CHAINS] = {INITIALIZATION_VALUE};
658 u32 average_noise[NUM_RX_CHAINS] = {INITIALIZATION_VALUE};
659 u32 max_average_sig;
660 u16 max_average_sig_antenna_i;
661 u32 min_average_noise = MIN_AVERAGE_NOISE_MAX_VALUE;
662 u16 min_average_noise_antenna_i = INITIALIZATION_VALUE;
663 u16 i = 0;
664 u16 rxon_chnum = INITIALIZATION_VALUE;
665 u16 stat_chnum = INITIALIZATION_VALUE;
666 u8 rxon_band24;
667 u8 stat_band24;
668 u32 active_chains = 0;
669 u8 num_tx_chains;
670 unsigned long flags;
671 struct statistics_rx_non_phy *rx_info = &(stat_resp->rx.general);
672
673 if (priv->disable_chain_noise_cal)
674 return;
675
676 data = &(priv->chain_noise_data);
677
678 /* Accumulate just the first 20 beacons after the first association,
679 * then we're done forever. */
680 if (data->state != IWL_CHAIN_NOISE_ACCUMULATE) {
681 if (data->state == IWL_CHAIN_NOISE_ALIVE)
682 IWL_DEBUG_CALIB("Wait for noise calib reset\n");
683 return;
684 }
685
686 spin_lock_irqsave(&priv->lock, flags);
687 if (rx_info->interference_data_flag != INTERFERENCE_DATA_AVAILABLE) {
688 IWL_DEBUG_CALIB(" << Interference data unavailable\n");
689 spin_unlock_irqrestore(&priv->lock, flags);
690 return;
691 }
692
693 rxon_band24 = !!(priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK);
694 rxon_chnum = le16_to_cpu(priv->staging_rxon.channel);
695 stat_band24 = !!(stat_resp->flag & STATISTICS_REPLY_FLG_BAND_24G_MSK);
696 stat_chnum = le32_to_cpu(stat_resp->flag) >> 16;
697
698 /* Make sure we accumulate data for just the associated channel
699 * (even if scanning). */
700 if ((rxon_chnum != stat_chnum) || (rxon_band24 != stat_band24)) {
701 IWL_DEBUG_CALIB("Stats not from chan=%d, band24=%d\n",
702 rxon_chnum, rxon_band24);
703 spin_unlock_irqrestore(&priv->lock, flags);
704 return;
705 }
706
707 /* Accumulate beacon statistics values across 20 beacons */
708 chain_noise_a = le32_to_cpu(rx_info->beacon_silence_rssi_a) &
709 IN_BAND_FILTER;
710 chain_noise_b = le32_to_cpu(rx_info->beacon_silence_rssi_b) &
711 IN_BAND_FILTER;
712 chain_noise_c = le32_to_cpu(rx_info->beacon_silence_rssi_c) &
713 IN_BAND_FILTER;
714
715 chain_sig_a = le32_to_cpu(rx_info->beacon_rssi_a) & IN_BAND_FILTER;
716 chain_sig_b = le32_to_cpu(rx_info->beacon_rssi_b) & IN_BAND_FILTER;
717 chain_sig_c = le32_to_cpu(rx_info->beacon_rssi_c) & IN_BAND_FILTER;
718
719 spin_unlock_irqrestore(&priv->lock, flags);
720
721 data->beacon_count++;
722
723 data->chain_noise_a = (chain_noise_a + data->chain_noise_a);
724 data->chain_noise_b = (chain_noise_b + data->chain_noise_b);
725 data->chain_noise_c = (chain_noise_c + data->chain_noise_c);
726
727 data->chain_signal_a = (chain_sig_a + data->chain_signal_a);
728 data->chain_signal_b = (chain_sig_b + data->chain_signal_b);
729 data->chain_signal_c = (chain_sig_c + data->chain_signal_c);
730
731 IWL_DEBUG_CALIB("chan=%d, band24=%d, beacon=%d\n",
732 rxon_chnum, rxon_band24, data->beacon_count);
733 IWL_DEBUG_CALIB("chain_sig: a %d b %d c %d\n",
734 chain_sig_a, chain_sig_b, chain_sig_c);
735 IWL_DEBUG_CALIB("chain_noise: a %d b %d c %d\n",
736 chain_noise_a, chain_noise_b, chain_noise_c);
737
738 /* If this is the 20th beacon, determine:
739 * 1) Disconnected antennas (using signal strengths)
740 * 2) Differential gain (using silence noise) to balance receivers */
741 if (data->beacon_count != CAL_NUM_OF_BEACONS)
742 return;
743
744 /* Analyze signal for disconnected antenna */
745 average_sig[0] = (data->chain_signal_a) / CAL_NUM_OF_BEACONS;
746 average_sig[1] = (data->chain_signal_b) / CAL_NUM_OF_BEACONS;
747 average_sig[2] = (data->chain_signal_c) / CAL_NUM_OF_BEACONS;
748
749 if (average_sig[0] >= average_sig[1]) {
750 max_average_sig = average_sig[0];
751 max_average_sig_antenna_i = 0;
752 active_chains = (1 << max_average_sig_antenna_i);
753 } else {
754 max_average_sig = average_sig[1];
755 max_average_sig_antenna_i = 1;
756 active_chains = (1 << max_average_sig_antenna_i);
757 }
758
759 if (average_sig[2] >= max_average_sig) {
760 max_average_sig = average_sig[2];
761 max_average_sig_antenna_i = 2;
762 active_chains = (1 << max_average_sig_antenna_i);
763 }
764
765 IWL_DEBUG_CALIB("average_sig: a %d b %d c %d\n",
766 average_sig[0], average_sig[1], average_sig[2]);
767 IWL_DEBUG_CALIB("max_average_sig = %d, antenna %d\n",
768 max_average_sig, max_average_sig_antenna_i);
769
770 /* Compare signal strengths for all 3 receivers. */
771 for (i = 0; i < NUM_RX_CHAINS; i++) {
772 if (i != max_average_sig_antenna_i) {
773 s32 rssi_delta = (max_average_sig - average_sig[i]);
774
775 /* If signal is very weak, compared with
776 * strongest, mark it as disconnected. */
777 if (rssi_delta > MAXIMUM_ALLOWED_PATHLOSS)
778 data->disconn_array[i] = 1;
779 else
780 active_chains |= (1 << i);
781 IWL_DEBUG_CALIB("i = %d rssiDelta = %d "
782 "disconn_array[i] = %d\n",
783 i, rssi_delta, data->disconn_array[i]);
784 }
785 }
786
787 num_tx_chains = 0;
788 for (i = 0; i < NUM_RX_CHAINS; i++) {
789 /* loops on all the bits of
790 * priv->hw_setting.valid_tx_ant */
791 u8 ant_msk = (1 << i);
792 if (!(priv->hw_params.valid_tx_ant & ant_msk))
793 continue;
794
795 num_tx_chains++;
796 if (data->disconn_array[i] == 0)
797 /* there is a Tx antenna connected */
798 break;
799 if (num_tx_chains == priv->hw_params.tx_chains_num &&
800 data->disconn_array[i]) {
801 /* This is the last TX antenna and is also
802 * disconnected connect it anyway */
803 data->disconn_array[i] = 0;
804 active_chains |= ant_msk;
805 IWL_DEBUG_CALIB("All Tx chains are disconnected W/A - "
806 "declare %d as connected\n", i);
807 break;
808 }
809 }
810
811 /* Save for use within RXON, TX, SCAN commands, etc. */
812 priv->chain_noise_data.active_chains = active_chains;
813 IWL_DEBUG_CALIB("active_chains (bitwise) = 0x%x\n",
814 active_chains);
815
816 /* Analyze noise for rx balance */
817 average_noise[0] = ((data->chain_noise_a)/CAL_NUM_OF_BEACONS);
818 average_noise[1] = ((data->chain_noise_b)/CAL_NUM_OF_BEACONS);
819 average_noise[2] = ((data->chain_noise_c)/CAL_NUM_OF_BEACONS);
820
821 for (i = 0; i < NUM_RX_CHAINS; i++) {
822 if (!(data->disconn_array[i]) &&
823 (average_noise[i] <= min_average_noise)) {
824 /* This means that chain i is active and has
825 * lower noise values so far: */
826 min_average_noise = average_noise[i];
827 min_average_noise_antenna_i = i;
828 }
829 }
830
831 IWL_DEBUG_CALIB("average_noise: a %d b %d c %d\n",
832 average_noise[0], average_noise[1],
833 average_noise[2]);
834
835 IWL_DEBUG_CALIB("min_average_noise = %d, antenna %d\n",
836 min_average_noise, min_average_noise_antenna_i);
837
838 priv->cfg->ops->utils->gain_computation(priv, average_noise,
839 min_average_noise_antenna_i, min_average_noise);
840
841 /* Some power changes may have been made during the calibration.
842 * Update and commit the RXON
843 */
844 if (priv->cfg->ops->lib->update_chain_flags)
845 priv->cfg->ops->lib->update_chain_flags(priv);
846
847 data->state = IWL_CHAIN_NOISE_DONE;
848 iwl_power_enable_management(priv);
849}
850EXPORT_SYMBOL(iwl_chain_noise_calibration);
851
852
853void iwl_reset_run_time_calib(struct iwl_priv *priv)
854{
855 int i;
856 memset(&(priv->sensitivity_data), 0,
857 sizeof(struct iwl_sensitivity_data));
858 memset(&(priv->chain_noise_data), 0,
859 sizeof(struct iwl_chain_noise_data));
860 for (i = 0; i < NUM_RX_CHAINS; i++)
861 priv->chain_noise_data.delta_gain_code[i] =
862 CHAIN_NOISE_DELTA_GAIN_INIT_VAL;
863
864 /* Ask for statistics now, the uCode will send notification
865 * periodically after association */
866 iwl_send_statistics_request(priv, CMD_ASYNC);
867}
868EXPORT_SYMBOL(iwl_reset_run_time_calib);
869
diff --git a/drivers/net/wireless/iwlwifi/iwl-calib.h b/drivers/net/wireless/iwlwifi/iwl-calib.h
new file mode 100644
index 000000000000..94c8e316382a
--- /dev/null
+++ b/drivers/net/wireless/iwlwifi/iwl-calib.h
@@ -0,0 +1,84 @@
1/******************************************************************************
2 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
8 * Copyright(c) 2008 Intel Corporation. All rights reserved.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
22 * USA
23 *
24 * The full GNU General Public License is included in this distribution
25 * in the file called LICENSE.GPL.
26 *
27 * Contact Information:
28 * Tomas Winkler <tomas.winkler@intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 *
31 * BSD LICENSE
32 *
33 * Copyright(c) 2005 - 2008 Intel Corporation. All rights reserved.
34 * All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 *
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
45 * distribution.
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 *****************************************************************************/
62#ifndef __iwl_calib_h__
63#define __iwl_calib_h__
64
65#include "iwl-dev.h"
66#include "iwl-core.h"
67#include "iwl-commands.h"
68
69void iwl_chain_noise_calibration(struct iwl_priv *priv,
70 struct iwl_notif_statistics *stat_resp);
71void iwl_sensitivity_calibration(struct iwl_priv *priv,
72 struct iwl_notif_statistics *resp);
73
74void iwl_init_sensitivity(struct iwl_priv *priv);
75void iwl_reset_run_time_calib(struct iwl_priv *priv);
76static inline void iwl_chain_noise_reset(struct iwl_priv *priv)
77{
78
79 if (!priv->disable_chain_noise_cal &&
80 priv->cfg->ops->utils->chain_noise_reset)
81 priv->cfg->ops->utils->chain_noise_reset(priv);
82}
83
84#endif /* __iwl_calib_h__ */
diff --git a/drivers/net/wireless/iwlwifi/iwl-4965-commands.h b/drivers/net/wireless/iwlwifi/iwl-commands.h
index 3bcd107e2d71..8d04e966ad48 100644
--- a/drivers/net/wireless/iwlwifi/iwl-4965-commands.h
+++ b/drivers/net/wireless/iwlwifi/iwl-commands.h
@@ -61,9 +61,9 @@
61 * 61 *
62 *****************************************************************************/ 62 *****************************************************************************/
63/* 63/*
64 * Please use this file (iwl-4965-commands.h) only for uCode API definitions. 64 * Please use this file (iwl-commands.h) only for uCode API definitions.
65 * Please use iwl-4965-hw.h for hardware-related definitions. 65 * Please use iwl-4965-hw.h for hardware-related definitions.
66 * Please use iwl-4965.h for driver implementation definitions. 66 * Please use iwl-dev.h for driver implementation definitions.
67 */ 67 */
68 68
69#ifndef __iwl4965_commands_h__ 69#ifndef __iwl4965_commands_h__
@@ -93,6 +93,11 @@ enum {
93 REPLY_LEDS_CMD = 0x48, 93 REPLY_LEDS_CMD = 0x48,
94 REPLY_TX_LINK_QUALITY_CMD = 0x4e, /* 4965 only */ 94 REPLY_TX_LINK_QUALITY_CMD = 0x4e, /* 4965 only */
95 95
96 /* WiMAX coexistence */
97 COEX_PRIORITY_TABLE_CMD = 0x5a, /*5000 only */
98 COEX_MEDIUM_NOTIFICATION = 0x5b,
99 COEX_EVENT_CMD = 0x5c,
100
96 /* 802.11h related */ 101 /* 802.11h related */
97 RADAR_NOTIFICATION = 0x70, /* not used */ 102 RADAR_NOTIFICATION = 0x70, /* not used */
98 REPLY_QUIET_CMD = 0x71, /* not used */ 103 REPLY_QUIET_CMD = 0x71, /* not used */
@@ -121,6 +126,7 @@ enum {
121 /* Miscellaneous commands */ 126 /* Miscellaneous commands */
122 QUIET_NOTIFICATION = 0x96, /* not used */ 127 QUIET_NOTIFICATION = 0x96, /* not used */
123 REPLY_TX_PWR_TABLE_CMD = 0x97, 128 REPLY_TX_PWR_TABLE_CMD = 0x97,
129 REPLY_TX_POWER_DBM_CMD = 0x98,
124 MEASURE_ABORT_NOTIFICATION = 0x99, /* not used */ 130 MEASURE_ABORT_NOTIFICATION = 0x99, /* not used */
125 131
126 /* Bluetooth device coexistance config command */ 132 /* Bluetooth device coexistance config command */
@@ -157,6 +163,13 @@ enum {
157/* iwl_cmd_header flags value */ 163/* iwl_cmd_header flags value */
158#define IWL_CMD_FAILED_MSK 0x40 164#define IWL_CMD_FAILED_MSK 0x40
159 165
166#define SEQ_TO_QUEUE(s) (((s) >> 8) & 0x1f)
167#define QUEUE_TO_SEQ(q) (((q) & 0x1f) << 8)
168#define SEQ_TO_INDEX(s) ((s) & 0xff)
169#define INDEX_TO_SEQ(i) ((i) & 0xff)
170#define SEQ_HUGE_FRAME __constant_cpu_to_le16(0x4000)
171#define SEQ_RX_FRAME __constant_cpu_to_le16(0x8000)
172
160/** 173/**
161 * struct iwl_cmd_header 174 * struct iwl_cmd_header
162 * 175 *
@@ -165,7 +178,7 @@ enum {
165 */ 178 */
166struct iwl_cmd_header { 179struct iwl_cmd_header {
167 u8 cmd; /* Command ID: REPLY_RXON, etc. */ 180 u8 cmd; /* Command ID: REPLY_RXON, etc. */
168 u8 flags; /* IWL_CMD_* */ 181 u8 flags; /* 0:5 reserved, 6 abort, 7 internal */
169 /* 182 /*
170 * The driver sets up the sequence number to values of its chosing. 183 * The driver sets up the sequence number to values of its chosing.
171 * uCode does not use this value, but passes it back to the driver 184 * uCode does not use this value, but passes it back to the driver
@@ -181,11 +194,12 @@ struct iwl_cmd_header {
181 * 194 *
182 * The Linux driver uses the following format: 195 * The Linux driver uses the following format:
183 * 196 *
184 * 0:7 index/position within Tx queue 197 * 0:7 tfd index - position within TX queue
185 * 8:13 Tx queue selection 198 * 8:12 TX queue id
186 * 14:14 driver sets this to indicate command is in the 'huge' 199 * 13 reserved
187 * storage at the end of the command buffers, i.e. scan cmd 200 * 14 huge - driver sets this to indicate command is in the
188 * 15:15 uCode sets this in uCode-originated response/notification 201 * 'huge' storage at the end of the command buffers
202 * 15 unsolicited RX or uCode-originated notification
189 */ 203 */
190 __le16 sequence; 204 __le16 sequence;
191 205
@@ -269,21 +283,13 @@ struct iwl_cmd_header {
269 * 10 B active, A inactive 283 * 10 B active, A inactive
270 * 11 Both active 284 * 11 Both active
271 */ 285 */
272#define RATE_MCS_ANT_POS 14 286#define RATE_MCS_ANT_POS 14
273#define RATE_MCS_ANT_A_MSK 0x04000 287#define RATE_MCS_ANT_A_MSK 0x04000
274#define RATE_MCS_ANT_B_MSK 0x08000 288#define RATE_MCS_ANT_B_MSK 0x08000
275#define RATE_MCS_ANT_AB_MSK 0x0C000 289#define RATE_MCS_ANT_C_MSK 0x10000
290#define RATE_MCS_ANT_ABC_MSK 0x1C000
276 291
277 292#define RATE_MCS_ANT_INIT_IND 1
278/**
279 * struct iwl4965_tx_power - txpower format used in REPLY_SCAN_CMD
280 *
281 * Scan uses only one transmitter, so only one analog/dsp gain pair is needed.
282 */
283struct iwl4965_tx_power {
284 u8 tx_gain; /* gain for analog radio */
285 u8 dsp_atten; /* gain for DSP */
286} __attribute__ ((packed));
287 293
288#define POWER_TABLE_NUM_ENTRIES 33 294#define POWER_TABLE_NUM_ENTRIES 33
289#define POWER_TABLE_NUM_HT_OFDM_ENTRIES 32 295#define POWER_TABLE_NUM_HT_OFDM_ENTRIES 32
@@ -333,6 +339,19 @@ struct iwl4965_tx_power_db {
333 struct tx_power_dual_stream power_tbl[POWER_TABLE_NUM_ENTRIES]; 339 struct tx_power_dual_stream power_tbl[POWER_TABLE_NUM_ENTRIES];
334} __attribute__ ((packed)); 340} __attribute__ ((packed));
335 341
342/**
343 * Commad REPLY_TX_POWER_DBM_CMD = 0x98
344 * struct iwl5000_tx_power_dbm_cmd
345 */
346#define IWL50_TX_POWER_AUTO 0x7f
347#define IWL50_TX_POWER_NO_CLOSED (0x1 << 6)
348
349struct iwl5000_tx_power_dbm_cmd {
350 s8 global_lmt; /*in half-dBm (e.g. 30 = 15 dBm) */
351 u8 flags;
352 s8 srv_chan_lmt; /*in half-dBm (e.g. 30 = 15 dBm) */
353 u8 reserved;
354} __attribute__ ((packed));
336 355
337/****************************************************************************** 356/******************************************************************************
338 * (0a) 357 * (0a)
@@ -367,7 +386,7 @@ struct iwl4965_tx_power_db {
367 * 3) Tx gain compensation to balance 4965's 2 Tx chains for MIMO operation, 386 * 3) Tx gain compensation to balance 4965's 2 Tx chains for MIMO operation,
368 * for each of 5 frequency ranges. 387 * for each of 5 frequency ranges.
369 */ 388 */
370struct iwl4965_init_alive_resp { 389struct iwl_init_alive_resp {
371 u8 ucode_minor; 390 u8 ucode_minor;
372 u8 ucode_major; 391 u8 ucode_major;
373 __le16 reserved1; 392 __le16 reserved1;
@@ -443,7 +462,7 @@ struct iwl4965_init_alive_resp {
443 * The Linux driver can print both logs to the system log when a uCode error 462 * The Linux driver can print both logs to the system log when a uCode error
444 * occurs. 463 * occurs.
445 */ 464 */
446struct iwl4965_alive_resp { 465struct iwl_alive_resp {
447 u8 ucode_minor; 466 u8 ucode_minor;
448 u8 ucode_major; 467 u8 ucode_major;
449 __le16 reserved1; 468 __le16 reserved1;
@@ -467,7 +486,7 @@ union tsf {
467/* 486/*
468 * REPLY_ERROR = 0x2 (response only, not a command) 487 * REPLY_ERROR = 0x2 (response only, not a command)
469 */ 488 */
470struct iwl4965_error_resp { 489struct iwl_error_resp {
471 __le32 error_type; 490 __le32 error_type;
472 u8 cmd_id; 491 u8 cmd_id;
473 u8 reserved1; 492 u8 reserved1;
@@ -545,6 +564,8 @@ enum {
545#define RXON_FLG_CHANNEL_MODE_MSK __constant_cpu_to_le32(0x3 << 25) 564#define RXON_FLG_CHANNEL_MODE_MSK __constant_cpu_to_le32(0x3 << 25)
546#define RXON_FLG_CHANNEL_MODE_PURE_40_MSK __constant_cpu_to_le32(0x1 << 25) 565#define RXON_FLG_CHANNEL_MODE_PURE_40_MSK __constant_cpu_to_le32(0x1 << 25)
547#define RXON_FLG_CHANNEL_MODE_MIXED_MSK __constant_cpu_to_le32(0x2 << 25) 566#define RXON_FLG_CHANNEL_MODE_MIXED_MSK __constant_cpu_to_le32(0x2 << 25)
567/* CTS to self (if spec allows) flag */
568#define RXON_FLG_SELF_CTS_EN __constant_cpu_to_le32(0x1<<30)
548 569
549/* rx_config filter flags */ 570/* rx_config filter flags */
550/* accept all data frames */ 571/* accept all data frames */
@@ -599,6 +620,46 @@ struct iwl4965_rxon_cmd {
599 u8 ofdm_ht_dual_stream_basic_rates; 620 u8 ofdm_ht_dual_stream_basic_rates;
600} __attribute__ ((packed)); 621} __attribute__ ((packed));
601 622
623/* 5000 HW just extend this cmmand */
624struct iwl_rxon_cmd {
625 u8 node_addr[6];
626 __le16 reserved1;
627 u8 bssid_addr[6];
628 __le16 reserved2;
629 u8 wlap_bssid_addr[6];
630 __le16 reserved3;
631 u8 dev_type;
632 u8 air_propagation;
633 __le16 rx_chain;
634 u8 ofdm_basic_rates;
635 u8 cck_basic_rates;
636 __le16 assoc_id;
637 __le32 flags;
638 __le32 filter_flags;
639 __le16 channel;
640 u8 ofdm_ht_single_stream_basic_rates;
641 u8 ofdm_ht_dual_stream_basic_rates;
642 u8 ofdm_ht_triple_stream_basic_rates;
643 u8 reserved5;
644 __le16 acquisition_data;
645 __le16 reserved6;
646} __attribute__ ((packed));
647
648struct iwl5000_rxon_assoc_cmd {
649 __le32 flags;
650 __le32 filter_flags;
651 u8 ofdm_basic_rates;
652 u8 cck_basic_rates;
653 __le16 reserved1;
654 u8 ofdm_ht_single_stream_basic_rates;
655 u8 ofdm_ht_dual_stream_basic_rates;
656 u8 ofdm_ht_triple_stream_basic_rates;
657 u8 reserved2;
658 __le16 rx_chain_select_flags;
659 __le16 acquisition_data;
660 __le32 reserved3;
661} __attribute__ ((packed));
662
602/* 663/*
603 * REPLY_RXON_ASSOC = 0x11 (command, has simple generic response) 664 * REPLY_RXON_ASSOC = 0x11 (command, has simple generic response)
604 */ 665 */
@@ -613,6 +674,8 @@ struct iwl4965_rxon_assoc_cmd {
613 __le16 reserved; 674 __le16 reserved;
614} __attribute__ ((packed)); 675} __attribute__ ((packed));
615 676
677#define IWL_CONN_MAX_LISTEN_INTERVAL 10
678
616/* 679/*
617 * REPLY_RXON_TIMING = 0x14 (command, has simple generic response) 680 * REPLY_RXON_TIMING = 0x14 (command, has simple generic response)
618 */ 681 */
@@ -669,7 +732,7 @@ struct iwl4965_csa_notification {
669 * transmission retry. Device uses cw_max as a bit mask, ANDed with new CW 732 * transmission retry. Device uses cw_max as a bit mask, ANDed with new CW
670 * value, to cap the CW value. 733 * value, to cap the CW value.
671 */ 734 */
672struct iwl4965_ac_qos { 735struct iwl_ac_qos {
673 __le16 cw_min; 736 __le16 cw_min;
674 __le16 cw_max; 737 __le16 cw_max;
675 u8 aifsn; 738 u8 aifsn;
@@ -691,9 +754,9 @@ struct iwl4965_ac_qos {
691 * This command sets up timings for each of the 4 prioritized EDCA Tx FIFOs 754 * This command sets up timings for each of the 4 prioritized EDCA Tx FIFOs
692 * 0: Background, 1: Best Effort, 2: Video, 3: Voice. 755 * 0: Background, 1: Best Effort, 2: Video, 3: Voice.
693 */ 756 */
694struct iwl4965_qosparam_cmd { 757struct iwl_qosparam_cmd {
695 __le32 qos_flags; 758 __le32 qos_flags;
696 struct iwl4965_ac_qos ac[AC_NUM]; 759 struct iwl_ac_qos ac[AC_NUM];
697} __attribute__ ((packed)); 760} __attribute__ ((packed));
698 761
699/****************************************************************************** 762/******************************************************************************
@@ -711,6 +774,8 @@ struct iwl4965_qosparam_cmd {
711#define IWL_STA_ID 2 774#define IWL_STA_ID 2
712#define IWL4965_BROADCAST_ID 31 775#define IWL4965_BROADCAST_ID 31
713#define IWL4965_STATION_COUNT 32 776#define IWL4965_STATION_COUNT 32
777#define IWL5000_BROADCAST_ID 15
778#define IWL5000_STATION_COUNT 16
714 779
715#define IWL_STATION_COUNT 32 /* MAX(3945,4965)*/ 780#define IWL_STATION_COUNT 32 /* MAX(3945,4965)*/
716#define IWL_INVALID_STATION 255 781#define IWL_INVALID_STATION 255
@@ -766,6 +831,20 @@ struct iwl4965_keyinfo {
766 u8 key[16]; /* 16-byte unicast decryption key */ 831 u8 key[16]; /* 16-byte unicast decryption key */
767} __attribute__ ((packed)); 832} __attribute__ ((packed));
768 833
834/* 5000 */
835struct iwl_keyinfo {
836 __le16 key_flags;
837 u8 tkip_rx_tsc_byte2; /* TSC[2] for key mix ph1 detection */
838 u8 reserved1;
839 __le16 tkip_rx_ttak[5]; /* 10-byte unicast TKIP TTAK */
840 u8 key_offset;
841 u8 reserved2;
842 u8 key[16]; /* 16-byte unicast decryption key */
843 __le64 tx_secur_seq_cnt;
844 __le64 hw_tkip_mic_rx_key;
845 __le64 hw_tkip_mic_tx_key;
846} __attribute__ ((packed));
847
769/** 848/**
770 * struct sta_id_modify 849 * struct sta_id_modify
771 * @addr[ETH_ALEN]: station's MAC address 850 * @addr[ETH_ALEN]: station's MAC address
@@ -841,6 +920,38 @@ struct iwl4965_addsta_cmd {
841 __le32 reserved2; 920 __le32 reserved2;
842} __attribute__ ((packed)); 921} __attribute__ ((packed));
843 922
923/* 5000 */
924struct iwl_addsta_cmd {
925 u8 mode; /* 1: modify existing, 0: add new station */
926 u8 reserved[3];
927 struct sta_id_modify sta;
928 struct iwl_keyinfo key;
929 __le32 station_flags; /* STA_FLG_* */
930 __le32 station_flags_msk; /* STA_FLG_* */
931
932 /* bit field to disable (1) or enable (0) Tx for Traffic ID (TID)
933 * corresponding to bit (e.g. bit 5 controls TID 5).
934 * Set modify_mask bit STA_MODIFY_TID_DISABLE_TX to use this field. */
935 __le16 tid_disable_tx;
936
937 __le16 reserved1;
938
939 /* TID for which to add block-ack support.
940 * Set modify_mask bit STA_MODIFY_ADDBA_TID_MSK to use this field. */
941 u8 add_immediate_ba_tid;
942
943 /* TID for which to remove block-ack support.
944 * Set modify_mask bit STA_MODIFY_DELBA_TID_MSK to use this field. */
945 u8 remove_immediate_ba_tid;
946
947 /* Starting Sequence Number for added block-ack support.
948 * Set modify_mask bit STA_MODIFY_ADDBA_TID_MSK to use this field. */
949 __le16 add_immediate_ba_ssn;
950
951 __le32 reserved2;
952} __attribute__ ((packed));
953
954
844#define ADD_STA_SUCCESS_MSK 0x1 955#define ADD_STA_SUCCESS_MSK 0x1
845#define ADD_STA_NO_ROOM_IN_TABLE 0x2 956#define ADD_STA_NO_ROOM_IN_TABLE 0x2
846#define ADD_STA_NO_BLOCK_ACK_RESOURCE 0x4 957#define ADD_STA_NO_BLOCK_ACK_RESOURCE 0x4
@@ -848,10 +959,28 @@ struct iwl4965_addsta_cmd {
848/* 959/*
849 * REPLY_ADD_STA = 0x18 (response) 960 * REPLY_ADD_STA = 0x18 (response)
850 */ 961 */
851struct iwl4965_add_sta_resp { 962struct iwl_add_sta_resp {
852 u8 status; /* ADD_STA_* */ 963 u8 status; /* ADD_STA_* */
853} __attribute__ ((packed)); 964} __attribute__ ((packed));
854 965
966#define REM_STA_SUCCESS_MSK 0x1
967/*
968 * REPLY_REM_STA = 0x19 (response)
969 */
970struct iwl_rem_sta_resp {
971 u8 status;
972} __attribute__ ((packed));
973
974/*
975 * REPLY_REM_STA = 0x19 (command)
976 */
977struct iwl_rem_sta_cmd {
978 u8 num_sta; /* number of removed stations */
979 u8 reserved[3];
980 u8 addr[ETH_ALEN]; /* MAC addr of the first station */
981 u8 reserved2[2];
982} __attribute__ ((packed));
983
855/* 984/*
856 * REPLY_WEP_KEY = 0x20 985 * REPLY_WEP_KEY = 0x20
857 */ 986 */
@@ -875,6 +1004,7 @@ struct iwl_wep_cmd {
875#define WEP_KEY_WEP_TYPE 1 1004#define WEP_KEY_WEP_TYPE 1
876#define WEP_KEYS_MAX 4 1005#define WEP_KEYS_MAX 4
877#define WEP_INVALID_OFFSET 0xff 1006#define WEP_INVALID_OFFSET 0xff
1007#define WEP_KEY_LEN_64 5
878#define WEP_KEY_LEN_128 13 1008#define WEP_KEY_LEN_128 13
879 1009
880/****************************************************************************** 1010/******************************************************************************
@@ -953,10 +1083,12 @@ struct iwl4965_rx_frame {
953} __attribute__ ((packed)); 1083} __attribute__ ((packed));
954 1084
955/* Fixed (non-configurable) rx data from phy */ 1085/* Fixed (non-configurable) rx data from phy */
956#define RX_PHY_FLAGS_ANTENNAE_OFFSET (4) 1086
957#define RX_PHY_FLAGS_ANTENNAE_MASK (0x70) 1087#define IWL49_RX_RES_PHY_CNT 14
958#define IWL_AGC_DB_MASK (0x3f80) /* MASK(7,13) */ 1088#define IWL49_RX_PHY_FLAGS_ANTENNAE_OFFSET (4)
959#define IWL_AGC_DB_POS (7) 1089#define IWL49_RX_PHY_FLAGS_ANTENNAE_MASK (0x70)
1090#define IWL49_AGC_DB_MASK (0x3f80) /* MASK(7,13) */
1091#define IWL49_AGC_DB_POS (7)
960struct iwl4965_rx_non_cfg_phy { 1092struct iwl4965_rx_non_cfg_phy {
961 __le16 ant_selection; /* ant A bit 4, ant B bit 5, ant C bit 6 */ 1093 __le16 ant_selection; /* ant A bit 4, ant B bit 5, ant C bit 6 */
962 __le16 agc_info; /* agc code 0:6, agc dB 7:13, reserved 14:15 */ 1094 __le16 agc_info; /* agc code 0:6, agc dB 7:13, reserved 14:15 */
@@ -964,12 +1096,30 @@ struct iwl4965_rx_non_cfg_phy {
964 u8 pad[0]; 1096 u8 pad[0];
965} __attribute__ ((packed)); 1097} __attribute__ ((packed));
966 1098
1099
1100#define IWL50_RX_RES_PHY_CNT 8
1101#define IWL50_RX_RES_AGC_IDX 1
1102#define IWL50_RX_RES_RSSI_AB_IDX 2
1103#define IWL50_RX_RES_RSSI_C_IDX 3
1104#define IWL50_OFDM_AGC_MSK 0xfe00
1105#define IWL50_OFDM_AGC_BIT_POS 9
1106#define IWL50_OFDM_RSSI_A_MSK 0x00ff
1107#define IWL50_OFDM_RSSI_A_BIT_POS 0
1108#define IWL50_OFDM_RSSI_B_MSK 0xff0000
1109#define IWL50_OFDM_RSSI_B_BIT_POS 16
1110#define IWL50_OFDM_RSSI_C_MSK 0x00ff
1111#define IWL50_OFDM_RSSI_C_BIT_POS 0
1112
1113struct iwl5000_non_cfg_phy {
1114 __le32 non_cfg_phy[IWL50_RX_RES_PHY_CNT]; /* upto 8 phy entries */
1115} __attribute__ ((packed));
1116
1117
967/* 1118/*
968 * REPLY_RX = 0xc3 (response only, not a command) 1119 * REPLY_RX = 0xc3 (response only, not a command)
969 * Used only for legacy (non 11n) frames. 1120 * Used only for legacy (non 11n) frames.
970 */ 1121 */
971#define RX_RES_PHY_CNT 14 1122struct iwl_rx_phy_res {
972struct iwl4965_rx_phy_res {
973 u8 non_cfg_phy_cnt; /* non configurable DSP phy data byte count */ 1123 u8 non_cfg_phy_cnt; /* non configurable DSP phy data byte count */
974 u8 cfg_phy_cnt; /* configurable DSP phy data byte count */ 1124 u8 cfg_phy_cnt; /* configurable DSP phy data byte count */
975 u8 stat_id; /* configurable DSP phy data set ID */ 1125 u8 stat_id; /* configurable DSP phy data set ID */
@@ -978,8 +1128,7 @@ struct iwl4965_rx_phy_res {
978 __le32 beacon_time_stamp; /* beacon at on-air rise */ 1128 __le32 beacon_time_stamp; /* beacon at on-air rise */
979 __le16 phy_flags; /* general phy flags: band, modulation, ... */ 1129 __le16 phy_flags; /* general phy flags: band, modulation, ... */
980 __le16 channel; /* channel number */ 1130 __le16 channel; /* channel number */
981 __le16 non_cfg_phy[RX_RES_PHY_CNT]; /* upto 14 phy entries */ 1131 u8 non_cfg_phy_buf[32]; /* for various implementations of non_cfg_phy */
982 __le32 reserved2;
983 __le32 rate_n_flags; /* RATE_MCS_* */ 1132 __le32 rate_n_flags; /* RATE_MCS_* */
984 __le16 byte_count; /* frame's byte-count */ 1133 __le16 byte_count; /* frame's byte-count */
985 __le16 reserved3; 1134 __le16 reserved3;
@@ -1018,6 +1167,11 @@ struct iwl4965_rx_mpdu_res_start {
1018 1167
1019/* REPLY_TX Tx flags field */ 1168/* REPLY_TX Tx flags field */
1020 1169
1170/* 1: Use RTS/CTS protocol or CTS-to-self if spec alows it
1171 * before this frame. if CTS-to-self required check
1172 * RXON_FLG_SELF_CTS_EN status. */
1173#define TX_CMD_FLG_RTS_CTS_MSK __constant_cpu_to_le32(1 << 0)
1174
1021/* 1: Use Request-To-Send protocol before this frame. 1175/* 1: Use Request-To-Send protocol before this frame.
1022 * Mutually exclusive vs. TX_CMD_FLG_CTS_MSK. */ 1176 * Mutually exclusive vs. TX_CMD_FLG_CTS_MSK. */
1023#define TX_CMD_FLG_RTS_MSK __constant_cpu_to_le32(1 << 1) 1177#define TX_CMD_FLG_RTS_MSK __constant_cpu_to_le32(1 << 1)
@@ -1100,6 +1254,14 @@ struct iwl4965_rx_mpdu_res_start {
1100#define TX_CMD_SEC_KEY128 0x08 1254#define TX_CMD_SEC_KEY128 0x08
1101 1255
1102/* 1256/*
1257 * security overhead sizes
1258 */
1259#define WEP_IV_LEN 4
1260#define WEP_ICV_LEN 4
1261#define CCMP_MIC_LEN 8
1262#define TKIP_ICV_LEN 4
1263
1264/*
1103 * 4965 uCode updates these Tx attempt count values in host DRAM. 1265 * 4965 uCode updates these Tx attempt count values in host DRAM.
1104 * Used for managing Tx retries when expecting block-acks. 1266 * Used for managing Tx retries when expecting block-acks.
1105 * Driver should set these fields to 0. 1267 * Driver should set these fields to 0.
@@ -1113,7 +1275,7 @@ struct iwl4965_dram_scratch {
1113/* 1275/*
1114 * REPLY_TX = 0x1c (command) 1276 * REPLY_TX = 0x1c (command)
1115 */ 1277 */
1116struct iwl4965_tx_cmd { 1278struct iwl_tx_cmd {
1117 /* 1279 /*
1118 * MPDU byte count: 1280 * MPDU byte count:
1119 * MAC header (24/26/30/32 bytes) + 2 bytes pad if 26/30 header size, 1281 * MAC header (24/26/30/32 bytes) + 2 bytes pad if 26/30 header size,
@@ -1259,6 +1421,15 @@ enum {
1259 TX_ABORT_REQUIRED_MSK = 0x80000000, /* bits 31:31 */ 1421 TX_ABORT_REQUIRED_MSK = 0x80000000, /* bits 31:31 */
1260}; 1422};
1261 1423
1424static inline int iwl_is_tx_success(u32 status)
1425{
1426 status &= TX_STATUS_MSK;
1427 return (status == TX_STATUS_SUCCESS)
1428 || (status == TX_STATUS_DIRECT_DONE);
1429}
1430
1431
1432
1262/* ******************************* 1433/* *******************************
1263 * TX aggregation status 1434 * TX aggregation status
1264 ******************************* */ 1435 ******************************* */
@@ -1313,6 +1484,11 @@ enum {
1313 * within the sending station (this 4965), rather than whether it was 1484 * within the sending station (this 4965), rather than whether it was
1314 * received successfully by the destination station. 1485 * received successfully by the destination station.
1315 */ 1486 */
1487struct agg_tx_status {
1488 __le16 status;
1489 __le16 sequence;
1490} __attribute__ ((packed));
1491
1316struct iwl4965_tx_resp { 1492struct iwl4965_tx_resp {
1317 u8 frame_count; /* 1 no aggregation, >1 aggregation */ 1493 u8 frame_count; /* 1 no aggregation, >1 aggregation */
1318 u8 bt_kill_count; /* # blocked by bluetooth (unused for agg) */ 1494 u8 bt_kill_count; /* # blocked by bluetooth (unused for agg) */
@@ -1344,34 +1520,56 @@ struct iwl4965_tx_resp {
1344 * table entry used for all frames in the new agg. 1520 * table entry used for all frames in the new agg.
1345 * 31-16: Sequence # for this frame's Tx cmd (not SSN!) 1521 * 31-16: Sequence # for this frame's Tx cmd (not SSN!)
1346 */ 1522 */
1347 __le32 status; /* TX status (for aggregation status of 1st frame) */ 1523 union {
1524 __le32 status;
1525 struct agg_tx_status agg_status[0]; /* for each agg frame */
1526 } u;
1348} __attribute__ ((packed)); 1527} __attribute__ ((packed));
1349 1528
1350struct agg_tx_status { 1529struct iwl5000_tx_resp {
1351 __le16 status; 1530 u8 frame_count; /* 1 no aggregation, >1 aggregation */
1352 __le16 sequence; 1531 u8 bt_kill_count; /* # blocked by bluetooth (unused for agg) */
1353} __attribute__ ((packed)); 1532 u8 failure_rts; /* # failures due to unsuccessful RTS */
1533 u8 failure_frame; /* # failures due to no ACK (unused for agg) */
1354 1534
1355struct iwl4965_tx_resp_agg { 1535 /* For non-agg: Rate at which frame was successful.
1356 u8 frame_count; /* 1 no aggregation, >1 aggregation */ 1536 * For agg: Rate at which all frames were transmitted. */
1357 u8 reserved1; 1537 __le32 rate_n_flags; /* RATE_MCS_* */
1358 u8 failure_rts; 1538
1359 u8 failure_frame; 1539 /* For non-agg: RTS + CTS + frame tx attempts time + ACK.
1360 __le32 rate_n_flags; 1540 * For agg: RTS + CTS + aggregation tx time + block-ack time. */
1361 __le16 wireless_media_time; 1541 __le16 wireless_media_time; /* uSecs */
1362 __le16 reserved3; 1542
1363 __le32 pa_power1; 1543 __le16 reserved;
1544 __le32 pa_power1; /* RF power amplifier measurement (not used) */
1364 __le32 pa_power2; 1545 __le32 pa_power2;
1365 struct agg_tx_status status; /* TX status (for aggregation status */
1366 /* of 1st frame) */
1367} __attribute__ ((packed));
1368 1546
1547 __le32 tfd_info;
1548 __le16 seq_ctl;
1549 __le16 byte_cnt;
1550 __le32 tlc_info;
1551 /*
1552 * For non-agg: frame status TX_STATUS_*
1553 * For agg: status of 1st frame, AGG_TX_STATE_*; other frame status
1554 * fields follow this one, up to frame_count.
1555 * Bit fields:
1556 * 11- 0: AGG_TX_STATE_* status code
1557 * 15-12: Retry count for 1st frame in aggregation (retries
1558 * occur if tx failed for this frame when it was a
1559 * member of a previous aggregation block). If rate
1560 * scaling is used, retry count indicates the rate
1561 * table entry used for all frames in the new agg.
1562 * 31-16: Sequence # for this frame's Tx cmd (not SSN!)
1563 */
1564 struct agg_tx_status status; /* TX status (in aggregation -
1565 * status of 1st frame) */
1566} __attribute__ ((packed));
1369/* 1567/*
1370 * REPLY_COMPRESSED_BA = 0xc5 (response only, not a command) 1568 * REPLY_COMPRESSED_BA = 0xc5 (response only, not a command)
1371 * 1569 *
1372 * Reports Block-Acknowledge from recipient station 1570 * Reports Block-Acknowledge from recipient station
1373 */ 1571 */
1374struct iwl4965_compressed_ba_resp { 1572struct iwl_compressed_ba_resp {
1375 __le32 sta_addr_lo32; 1573 __le32 sta_addr_lo32;
1376 __le16 sta_addr_hi16; 1574 __le16 sta_addr_hi16;
1377 __le16 reserved; 1575 __le16 reserved;
@@ -1821,7 +2019,7 @@ struct iwl4965_spectrum_notification {
1821 *****************************************************************************/ 2019 *****************************************************************************/
1822 2020
1823/** 2021/**
1824 * struct iwl4965_powertable_cmd - Power Table Command 2022 * struct iwl_powertable_cmd - Power Table Command
1825 * @flags: See below: 2023 * @flags: See below:
1826 * 2024 *
1827 * POWER_TABLE_CMD = 0x77 (command, has simple generic response) 2025 * POWER_TABLE_CMD = 0x77 (command, has simple generic response)
@@ -1836,8 +2034,8 @@ struct iwl4965_spectrum_notification {
1836 * bit 2 - '0' PM have to walk up every DTIM 2034 * bit 2 - '0' PM have to walk up every DTIM
1837 * '1' PM could sleep over DTIM till listen Interval. 2035 * '1' PM could sleep over DTIM till listen Interval.
1838 * PCI power managed 2036 * PCI power managed
1839 * bit 3 - '0' (PCI_LINK_CTRL & 0x1) 2037 * bit 3 - '0' (PCI_CFG_LINK_CTRL & 0x1)
1840 * '1' !(PCI_LINK_CTRL & 0x1) 2038 * '1' !(PCI_CFG_LINK_CTRL & 0x1)
1841 * Force sleep Modes 2039 * Force sleep Modes
1842 * bit 31/30- '00' use both mac/xtal sleeps 2040 * bit 31/30- '00' use both mac/xtal sleeps
1843 * '01' force Mac sleep 2041 * '01' force Mac sleep
@@ -1853,8 +2051,9 @@ struct iwl4965_spectrum_notification {
1853#define IWL_POWER_DRIVER_ALLOW_SLEEP_MSK __constant_cpu_to_le16(1 << 0) 2051#define IWL_POWER_DRIVER_ALLOW_SLEEP_MSK __constant_cpu_to_le16(1 << 0)
1854#define IWL_POWER_SLEEP_OVER_DTIM_MSK __constant_cpu_to_le16(1 << 2) 2052#define IWL_POWER_SLEEP_OVER_DTIM_MSK __constant_cpu_to_le16(1 << 2)
1855#define IWL_POWER_PCI_PM_MSK __constant_cpu_to_le16(1 << 3) 2053#define IWL_POWER_PCI_PM_MSK __constant_cpu_to_le16(1 << 3)
2054#define IWL_POWER_FAST_PD __constant_cpu_to_le16(1 << 4)
1856 2055
1857struct iwl4965_powertable_cmd { 2056struct iwl_powertable_cmd {
1858 __le16 flags; 2057 __le16 flags;
1859 u8 keep_alive_seconds; 2058 u8 keep_alive_seconds;
1860 u8 debug_flags; 2059 u8 debug_flags;
@@ -1914,7 +2113,7 @@ struct iwl4965_card_state_notif {
1914#define RF_CARD_DISABLED 0x04 2113#define RF_CARD_DISABLED 0x04
1915#define RXON_CARD_DISABLED 0x10 2114#define RXON_CARD_DISABLED 0x10
1916 2115
1917struct iwl4965_ct_kill_config { 2116struct iwl_ct_kill_config {
1918 __le32 reserved; 2117 __le32 reserved;
1919 __le32 critical_temperature_M; 2118 __le32 critical_temperature_M;
1920 __le32 critical_temperature_R; 2119 __le32 critical_temperature_R;
@@ -1926,8 +2125,11 @@ struct iwl4965_ct_kill_config {
1926 * 2125 *
1927 *****************************************************************************/ 2126 *****************************************************************************/
1928 2127
2128#define SCAN_CHANNEL_TYPE_PASSIVE __constant_cpu_to_le32(0)
2129#define SCAN_CHANNEL_TYPE_ACTIVE __constant_cpu_to_le32(1)
2130
1929/** 2131/**
1930 * struct iwl4965_scan_channel - entry in REPLY_SCAN_CMD channel table 2132 * struct iwl_scan_channel - entry in REPLY_SCAN_CMD channel table
1931 * 2133 *
1932 * One for each channel in the scan list. 2134 * One for each channel in the scan list.
1933 * Each channel can independently select: 2135 * Each channel can independently select:
@@ -1937,7 +2139,7 @@ struct iwl4965_ct_kill_config {
1937 * quiet_plcp_th, good_CRC_th) 2139 * quiet_plcp_th, good_CRC_th)
1938 * 2140 *
1939 * To avoid uCode errors, make sure the following are true (see comments 2141 * To avoid uCode errors, make sure the following are true (see comments
1940 * under struct iwl4965_scan_cmd about max_out_time and quiet_time): 2142 * under struct iwl_scan_cmd about max_out_time and quiet_time):
1941 * 1) If using passive_dwell (i.e. passive_dwell != 0): 2143 * 1) If using passive_dwell (i.e. passive_dwell != 0):
1942 * active_dwell <= passive_dwell (< max_out_time if max_out_time != 0) 2144 * active_dwell <= passive_dwell (< max_out_time if max_out_time != 0)
1943 * 2) quiet_time <= active_dwell 2145 * 2) quiet_time <= active_dwell
@@ -1945,37 +2147,38 @@ struct iwl4965_ct_kill_config {
1945 * passive_dwell < max_out_time 2147 * passive_dwell < max_out_time
1946 * active_dwell < max_out_time 2148 * active_dwell < max_out_time
1947 */ 2149 */
1948struct iwl4965_scan_channel { 2150struct iwl_scan_channel {
1949 /* 2151 /*
1950 * type is defined as: 2152 * type is defined as:
1951 * 0:0 1 = active, 0 = passive 2153 * 0:0 1 = active, 0 = passive
1952 * 1:4 SSID direct bit map; if a bit is set, then corresponding 2154 * 1:20 SSID direct bit map; if a bit is set, then corresponding
1953 * SSID IE is transmitted in probe request. 2155 * SSID IE is transmitted in probe request.
1954 * 5:7 reserved 2156 * 21:31 reserved
1955 */ 2157 */
1956 u8 type; 2158 __le32 type;
1957 u8 channel; /* band is selected by iwl4965_scan_cmd "flags" field */ 2159 __le16 channel; /* band is selected by iwl_scan_cmd "flags" field */
1958 struct iwl4965_tx_power tpc; 2160 u8 tx_gain; /* gain for analog radio */
2161 u8 dsp_atten; /* gain for DSP */
1959 __le16 active_dwell; /* in 1024-uSec TU (time units), typ 5-50 */ 2162 __le16 active_dwell; /* in 1024-uSec TU (time units), typ 5-50 */
1960 __le16 passive_dwell; /* in 1024-uSec TU (time units), typ 20-500 */ 2163 __le16 passive_dwell; /* in 1024-uSec TU (time units), typ 20-500 */
1961} __attribute__ ((packed)); 2164} __attribute__ ((packed));
1962 2165
1963/** 2166/**
1964 * struct iwl4965_ssid_ie - directed scan network information element 2167 * struct iwl_ssid_ie - directed scan network information element
1965 * 2168 *
1966 * Up to 4 of these may appear in REPLY_SCAN_CMD, selected by "type" field 2169 * Up to 4 of these may appear in REPLY_SCAN_CMD, selected by "type" field
1967 * in struct iwl4965_scan_channel; each channel may select different ssids from 2170 * in struct iwl4965_scan_channel; each channel may select different ssids from
1968 * among the 4 entries. SSID IEs get transmitted in reverse order of entry. 2171 * among the 4 entries. SSID IEs get transmitted in reverse order of entry.
1969 */ 2172 */
1970struct iwl4965_ssid_ie { 2173struct iwl_ssid_ie {
1971 u8 id; 2174 u8 id;
1972 u8 len; 2175 u8 len;
1973 u8 ssid[32]; 2176 u8 ssid[32];
1974} __attribute__ ((packed)); 2177} __attribute__ ((packed));
1975 2178
1976#define PROBE_OPTION_MAX 0x4 2179#define PROBE_OPTION_MAX 0x14
1977#define TX_CMD_LIFE_TIME_INFINITE __constant_cpu_to_le32(0xFFFFFFFF) 2180#define TX_CMD_LIFE_TIME_INFINITE __constant_cpu_to_le32(0xFFFFFFFF)
1978#define IWL_GOOD_CRC_TH __constant_cpu_to_le16(1) 2181#define IWL_GOOD_CRC_TH __constant_cpu_to_le16(1)
1979#define IWL_MAX_SCAN_SIZE 1024 2182#define IWL_MAX_SCAN_SIZE 1024
1980 2183
1981/* 2184/*
@@ -2028,9 +2231,9 @@ struct iwl4965_ssid_ie {
2028 * Driver must use separate scan commands for 2.4 vs. 5 GHz bands. 2231 * Driver must use separate scan commands for 2.4 vs. 5 GHz bands.
2029 * 2232 *
2030 * To avoid uCode errors, see timing restrictions described under 2233 * To avoid uCode errors, see timing restrictions described under
2031 * struct iwl4965_scan_channel. 2234 * struct iwl_scan_channel.
2032 */ 2235 */
2033struct iwl4965_scan_cmd { 2236struct iwl_scan_cmd {
2034 __le16 len; 2237 __le16 len;
2035 u8 reserved0; 2238 u8 reserved0;
2036 u8 channel_count; /* # channels in channel list */ 2239 u8 channel_count; /* # channels in channel list */
@@ -2051,10 +2254,10 @@ struct iwl4965_scan_cmd {
2051 2254
2052 /* For active scans (set to all-0s for passive scans). 2255 /* For active scans (set to all-0s for passive scans).
2053 * Does not include payload. Must specify Tx rate; no rate scaling. */ 2256 * Does not include payload. Must specify Tx rate; no rate scaling. */
2054 struct iwl4965_tx_cmd tx_cmd; 2257 struct iwl_tx_cmd tx_cmd;
2055 2258
2056 /* For directed active scans (set to all-0s otherwise) */ 2259 /* For directed active scans (set to all-0s otherwise) */
2057 struct iwl4965_ssid_ie direct_scan[PROBE_OPTION_MAX]; 2260 struct iwl_ssid_ie direct_scan[PROBE_OPTION_MAX];
2058 2261
2059 /* 2262 /*
2060 * Probe request frame, followed by channel list. 2263 * Probe request frame, followed by channel list.
@@ -2082,14 +2285,14 @@ struct iwl4965_scan_cmd {
2082/* 2285/*
2083 * REPLY_SCAN_CMD = 0x80 (response) 2286 * REPLY_SCAN_CMD = 0x80 (response)
2084 */ 2287 */
2085struct iwl4965_scanreq_notification { 2288struct iwl_scanreq_notification {
2086 __le32 status; /* 1: okay, 2: cannot fulfill request */ 2289 __le32 status; /* 1: okay, 2: cannot fulfill request */
2087} __attribute__ ((packed)); 2290} __attribute__ ((packed));
2088 2291
2089/* 2292/*
2090 * SCAN_START_NOTIFICATION = 0x82 (notification only, not a command) 2293 * SCAN_START_NOTIFICATION = 0x82 (notification only, not a command)
2091 */ 2294 */
2092struct iwl4965_scanstart_notification { 2295struct iwl_scanstart_notification {
2093 __le32 tsf_low; 2296 __le32 tsf_low;
2094 __le32 tsf_high; 2297 __le32 tsf_high;
2095 __le32 beacon_timer; 2298 __le32 beacon_timer;
@@ -2106,7 +2309,7 @@ struct iwl4965_scanstart_notification {
2106/* 2309/*
2107 * SCAN_RESULTS_NOTIFICATION = 0x83 (notification only, not a command) 2310 * SCAN_RESULTS_NOTIFICATION = 0x83 (notification only, not a command)
2108 */ 2311 */
2109struct iwl4965_scanresults_notification { 2312struct iwl_scanresults_notification {
2110 u8 channel; 2313 u8 channel;
2111 u8 band; 2314 u8 band;
2112 u8 reserved[2]; 2315 u8 reserved[2];
@@ -2118,7 +2321,7 @@ struct iwl4965_scanresults_notification {
2118/* 2321/*
2119 * SCAN_COMPLETE_NOTIFICATION = 0x84 (notification only, not a command) 2322 * SCAN_COMPLETE_NOTIFICATION = 0x84 (notification only, not a command)
2120 */ 2323 */
2121struct iwl4965_scancomplete_notification { 2324struct iwl_scancomplete_notification {
2122 u8 scanned_channels; 2325 u8 scanned_channels;
2123 u8 status; 2326 u8 status;
2124 u8 reserved; 2327 u8 reserved;
@@ -2147,8 +2350,8 @@ struct iwl4965_beacon_notif {
2147/* 2350/*
2148 * REPLY_TX_BEACON = 0x91 (command, has simple generic response) 2351 * REPLY_TX_BEACON = 0x91 (command, has simple generic response)
2149 */ 2352 */
2150struct iwl4965_tx_beacon_cmd { 2353struct iwl_tx_beacon_cmd {
2151 struct iwl4965_tx_cmd tx; 2354 struct iwl_tx_cmd tx;
2152 __le16 tim_idx; 2355 __le16 tim_idx;
2153 u8 tim_size; 2356 u8 tim_size;
2154 u8 reserved1; 2357 u8 reserved1;
@@ -2339,7 +2542,7 @@ struct statistics_general {
2339 */ 2542 */
2340#define IWL_STATS_CONF_CLEAR_STATS __constant_cpu_to_le32(0x1) /* see above */ 2543#define IWL_STATS_CONF_CLEAR_STATS __constant_cpu_to_le32(0x1) /* see above */
2341#define IWL_STATS_CONF_DISABLE_NOTIF __constant_cpu_to_le32(0x2)/* see above */ 2544#define IWL_STATS_CONF_DISABLE_NOTIF __constant_cpu_to_le32(0x2)/* see above */
2342struct iwl4965_statistics_cmd { 2545struct iwl_statistics_cmd {
2343 __le32 configuration_flags; /* IWL_STATS_CONF_* */ 2546 __le32 configuration_flags; /* IWL_STATS_CONF_* */
2344} __attribute__ ((packed)); 2547} __attribute__ ((packed));
2345 2548
@@ -2360,7 +2563,7 @@ struct iwl4965_statistics_cmd {
2360 */ 2563 */
2361#define STATISTICS_REPLY_FLG_BAND_24G_MSK __constant_cpu_to_le32(0x2) 2564#define STATISTICS_REPLY_FLG_BAND_24G_MSK __constant_cpu_to_le32(0x2)
2362#define STATISTICS_REPLY_FLG_FAT_MODE_MSK __constant_cpu_to_le32(0x8) 2565#define STATISTICS_REPLY_FLG_FAT_MODE_MSK __constant_cpu_to_le32(0x8)
2363struct iwl4965_notif_statistics { 2566struct iwl_notif_statistics {
2364 __le32 flag; 2567 __le32 flag;
2365 struct statistics_rx rx; 2568 struct statistics_rx rx;
2366 struct statistics_tx tx; 2569 struct statistics_tx tx;
@@ -2559,7 +2762,7 @@ struct iwl4965_missed_beacon_notif {
2559 */ 2762 */
2560 2763
2561/* 2764/*
2562 * Table entries in SENSITIVITY_CMD (struct iwl4965_sensitivity_cmd) 2765 * Table entries in SENSITIVITY_CMD (struct iwl_sensitivity_cmd)
2563 */ 2766 */
2564#define HD_TABLE_SIZE (11) /* number of entries */ 2767#define HD_TABLE_SIZE (11) /* number of entries */
2565#define HD_MIN_ENERGY_CCK_DET_INDEX (0) /* table indexes */ 2768#define HD_MIN_ENERGY_CCK_DET_INDEX (0) /* table indexes */
@@ -2574,18 +2777,18 @@ struct iwl4965_missed_beacon_notif {
2574#define HD_AUTO_CORR40_X4_TH_ADD_MIN_INDEX (9) 2777#define HD_AUTO_CORR40_X4_TH_ADD_MIN_INDEX (9)
2575#define HD_OFDM_ENERGY_TH_IN_INDEX (10) 2778#define HD_OFDM_ENERGY_TH_IN_INDEX (10)
2576 2779
2577/* Control field in struct iwl4965_sensitivity_cmd */ 2780/* Control field in struct iwl_sensitivity_cmd */
2578#define SENSITIVITY_CMD_CONTROL_DEFAULT_TABLE __constant_cpu_to_le16(0) 2781#define SENSITIVITY_CMD_CONTROL_DEFAULT_TABLE __constant_cpu_to_le16(0)
2579#define SENSITIVITY_CMD_CONTROL_WORK_TABLE __constant_cpu_to_le16(1) 2782#define SENSITIVITY_CMD_CONTROL_WORK_TABLE __constant_cpu_to_le16(1)
2580 2783
2581/** 2784/**
2582 * struct iwl4965_sensitivity_cmd 2785 * struct iwl_sensitivity_cmd
2583 * @control: (1) updates working table, (0) updates default table 2786 * @control: (1) updates working table, (0) updates default table
2584 * @table: energy threshold values, use HD_* as index into table 2787 * @table: energy threshold values, use HD_* as index into table
2585 * 2788 *
2586 * Always use "1" in "control" to update uCode's working table and DSP. 2789 * Always use "1" in "control" to update uCode's working table and DSP.
2587 */ 2790 */
2588struct iwl4965_sensitivity_cmd { 2791struct iwl_sensitivity_cmd {
2589 __le16 control; /* always use "1" */ 2792 __le16 control; /* always use "1" */
2590 __le16 table[HD_TABLE_SIZE]; /* use HD_* as index */ 2793 __le16 table[HD_TABLE_SIZE]; /* use HD_* as index */
2591} __attribute__ ((packed)); 2794} __attribute__ ((packed));
@@ -2659,6 +2862,86 @@ struct iwl4965_calibration_cmd {
2659 u8 reserved1; 2862 u8 reserved1;
2660} __attribute__ ((packed)); 2863} __attribute__ ((packed));
2661 2864
2865/* Phy calibration command for 5000 series */
2866
2867enum {
2868 IWL5000_PHY_CALIBRATE_DC_CMD = 8,
2869 IWL5000_PHY_CALIBRATE_LO_CMD = 9,
2870 IWL5000_PHY_CALIBRATE_RX_BB_CMD = 10,
2871 IWL5000_PHY_CALIBRATE_TX_IQ_CMD = 11,
2872 IWL5000_PHY_CALIBRATE_RX_IQ_CMD = 12,
2873 IWL5000_PHY_CALIBRATION_NOISE_CMD = 13,
2874 IWL5000_PHY_CALIBRATE_AGC_TABLE_CMD = 14,
2875 IWL5000_PHY_CALIBRATE_CRYSTAL_FRQ_CMD = 15,
2876 IWL5000_PHY_CALIBRATE_BASE_BAND_CMD = 16,
2877 IWL5000_PHY_CALIBRATE_TX_IQ_PERD_CMD = 17,
2878 IWL5000_PHY_CALIBRATE_CHAIN_NOISE_RESET_CMD = 18,
2879 IWL5000_PHY_CALIBRATE_CHAIN_NOISE_GAIN_CMD = 19,
2880};
2881
2882enum {
2883 CALIBRATION_CFG_CMD = 0x65,
2884 CALIBRATION_RES_NOTIFICATION = 0x66,
2885 CALIBRATION_COMPLETE_NOTIFICATION = 0x67
2886};
2887
2888struct iwl_cal_crystal_freq_cmd {
2889 u8 cap_pin1;
2890 u8 cap_pin2;
2891} __attribute__ ((packed));
2892
2893struct iwl5000_calibration {
2894 u8 op_code;
2895 u8 first_group;
2896 u8 num_groups;
2897 u8 all_data_valid;
2898 struct iwl_cal_crystal_freq_cmd data;
2899} __attribute__ ((packed));
2900
2901#define IWL_CALIB_INIT_CFG_ALL __constant_cpu_to_le32(0xffffffff)
2902
2903struct iwl_calib_cfg_elmnt_s {
2904 __le32 is_enable;
2905 __le32 start;
2906 __le32 send_res;
2907 __le32 apply_res;
2908 __le32 reserved;
2909} __attribute__ ((packed));
2910
2911struct iwl_calib_cfg_status_s {
2912 struct iwl_calib_cfg_elmnt_s once;
2913 struct iwl_calib_cfg_elmnt_s perd;
2914 __le32 flags;
2915} __attribute__ ((packed));
2916
2917struct iwl5000_calib_cfg_cmd {
2918 struct iwl_calib_cfg_status_s ucd_calib_cfg;
2919 struct iwl_calib_cfg_status_s drv_calib_cfg;
2920 __le32 reserved1;
2921} __attribute__ ((packed));
2922
2923struct iwl5000_calib_hdr {
2924 u8 op_code;
2925 u8 first_group;
2926 u8 groups_num;
2927 u8 data_valid;
2928} __attribute__ ((packed));
2929
2930struct iwl5000_calibration_chain_noise_reset_cmd {
2931 u8 op_code; /* IWL5000_PHY_CALIBRATE_CHAIN_NOISE_RESET_CMD */
2932 u8 flags; /* not used */
2933 __le16 reserved;
2934} __attribute__ ((packed));
2935
2936struct iwl5000_calibration_chain_noise_gain_cmd {
2937 u8 op_code; /* IWL5000_PHY_CALIBRATE_CHAIN_NOISE_GAIN_CMD */
2938 u8 flags; /* not used */
2939 __le16 reserved;
2940 u8 delta_gain_1;
2941 u8 delta_gain_2;
2942 __le16 reserved1;
2943} __attribute__ ((packed));
2944
2662/****************************************************************************** 2945/******************************************************************************
2663 * (12) 2946 * (12)
2664 * Miscellaneous Commands: 2947 * Miscellaneous Commands:
@@ -2672,7 +2955,7 @@ struct iwl4965_calibration_cmd {
2672 * For each of 3 possible LEDs (Activity/Link/Tech, selected by "id" field), 2955 * For each of 3 possible LEDs (Activity/Link/Tech, selected by "id" field),
2673 * this command turns it on or off, or sets up a periodic blinking cycle. 2956 * this command turns it on or off, or sets up a periodic blinking cycle.
2674 */ 2957 */
2675struct iwl4965_led_cmd { 2958struct iwl_led_cmd {
2676 __le32 interval; /* "interval" in uSec */ 2959 __le32 interval; /* "interval" in uSec */
2677 u8 id; /* 1: Activity, 2: Link, 3: Tech */ 2960 u8 id; /* 1: Activity, 2: Link, 3: Tech */
2678 u8 off; /* # intervals off while blinking; 2961 u8 off; /* # intervals off while blinking;
@@ -2682,30 +2965,81 @@ struct iwl4965_led_cmd {
2682 u8 reserved; 2965 u8 reserved;
2683} __attribute__ ((packed)); 2966} __attribute__ ((packed));
2684 2967
2968/*
2969 * Coexistence WIFI/WIMAX Command
2970 * COEX_PRIORITY_TABLE_CMD = 0x5a
2971 *
2972 */
2973enum {
2974 COEX_UNASSOC_IDLE = 0,
2975 COEX_UNASSOC_MANUAL_SCAN = 1,
2976 COEX_UNASSOC_AUTO_SCAN = 2,
2977 COEX_CALIBRATION = 3,
2978 COEX_PERIODIC_CALIBRATION = 4,
2979 COEX_CONNECTION_ESTAB = 5,
2980 COEX_ASSOCIATED_IDLE = 6,
2981 COEX_ASSOC_MANUAL_SCAN = 7,
2982 COEX_ASSOC_AUTO_SCAN = 8,
2983 COEX_ASSOC_ACTIVE_LEVEL = 9,
2984 COEX_RF_ON = 10,
2985 COEX_RF_OFF = 11,
2986 COEX_STAND_ALONE_DEBUG = 12,
2987 COEX_IPAN_ASSOC_LEVEL = 13,
2988 COEX_RSRVD1 = 14,
2989 COEX_RSRVD2 = 15,
2990 COEX_NUM_OF_EVENTS = 16
2991};
2992
2993struct iwl_wimax_coex_event_entry {
2994 u8 request_prio;
2995 u8 win_medium_prio;
2996 u8 reserved;
2997 u8 flags;
2998} __attribute__ ((packed));
2999
3000/* COEX flag masks */
3001
3002/* Staion table is valid */
3003#define COEX_FLAGS_STA_TABLE_VALID_MSK (0x1)
3004/* UnMask wakeup src at unassociated sleep */
3005#define COEX_FLAGS_UNASSOC_WA_UNMASK_MSK (0x4)
3006/* UnMask wakeup src at associated sleep */
3007#define COEX_FLAGS_ASSOC_WA_UNMASK_MSK (0x8)
3008/* Enable CoEx feature. */
3009#define COEX_FLAGS_COEX_ENABLE_MSK (0x80)
3010
3011struct iwl_wimax_coex_cmd {
3012 u8 flags;
3013 u8 reserved[3];
3014 struct iwl_wimax_coex_event_entry sta_prio[COEX_NUM_OF_EVENTS];
3015} __attribute__ ((packed));
3016
2685/****************************************************************************** 3017/******************************************************************************
2686 * (13) 3018 * (13)
2687 * Union of all expected notifications/responses: 3019 * Union of all expected notifications/responses:
2688 * 3020 *
2689 *****************************************************************************/ 3021 *****************************************************************************/
2690 3022
2691struct iwl4965_rx_packet { 3023struct iwl_rx_packet {
2692 __le32 len; 3024 __le32 len;
2693 struct iwl_cmd_header hdr; 3025 struct iwl_cmd_header hdr;
2694 union { 3026 union {
2695 struct iwl4965_alive_resp alive_frame; 3027 struct iwl_alive_resp alive_frame;
2696 struct iwl4965_rx_frame rx_frame; 3028 struct iwl4965_rx_frame rx_frame;
2697 struct iwl4965_tx_resp tx_resp; 3029 struct iwl4965_tx_resp tx_resp;
2698 struct iwl4965_spectrum_notification spectrum_notif; 3030 struct iwl4965_spectrum_notification spectrum_notif;
2699 struct iwl4965_csa_notification csa_notif; 3031 struct iwl4965_csa_notification csa_notif;
2700 struct iwl4965_error_resp err_resp; 3032 struct iwl_error_resp err_resp;
2701 struct iwl4965_card_state_notif card_state_notif; 3033 struct iwl4965_card_state_notif card_state_notif;
2702 struct iwl4965_beacon_notif beacon_status; 3034 struct iwl4965_beacon_notif beacon_status;
2703 struct iwl4965_add_sta_resp add_sta; 3035 struct iwl_add_sta_resp add_sta;
3036 struct iwl_rem_sta_resp rem_sta;
2704 struct iwl4965_sleep_notification sleep_notif; 3037 struct iwl4965_sleep_notification sleep_notif;
2705 struct iwl4965_spectrum_resp spectrum; 3038 struct iwl4965_spectrum_resp spectrum;
2706 struct iwl4965_notif_statistics stats; 3039 struct iwl_notif_statistics stats;
2707 struct iwl4965_compressed_ba_resp compressed_ba; 3040 struct iwl_compressed_ba_resp compressed_ba;
2708 struct iwl4965_missed_beacon_notif missed_beacon; 3041 struct iwl4965_missed_beacon_notif missed_beacon;
3042 struct iwl5000_calibration calib;
2709 __le32 status; 3043 __le32 status;
2710 u8 raw[0]; 3044 u8 raw[0];
2711 } u; 3045 } u;
diff --git a/drivers/net/wireless/iwlwifi/iwl-core.c b/drivers/net/wireless/iwlwifi/iwl-core.c
index 2dfd982d7d1f..4c312c55f90c 100644
--- a/drivers/net/wireless/iwlwifi/iwl-core.c
+++ b/drivers/net/wireless/iwlwifi/iwl-core.c
@@ -28,15 +28,16 @@
28 28
29#include <linux/kernel.h> 29#include <linux/kernel.h>
30#include <linux/module.h> 30#include <linux/module.h>
31#include <linux/version.h>
32#include <net/mac80211.h> 31#include <net/mac80211.h>
33 32
34struct iwl_priv; /* FIXME: remove */ 33struct iwl_priv; /* FIXME: remove */
35#include "iwl-debug.h" 34#include "iwl-debug.h"
36#include "iwl-eeprom.h" 35#include "iwl-eeprom.h"
37#include "iwl-4965.h" /* FIXME: remove */ 36#include "iwl-dev.h" /* FIXME: remove */
38#include "iwl-core.h" 37#include "iwl-core.h"
38#include "iwl-io.h"
39#include "iwl-rfkill.h" 39#include "iwl-rfkill.h"
40#include "iwl-power.h"
40 41
41 42
42MODULE_DESCRIPTION("iwl core"); 43MODULE_DESCRIPTION("iwl core");
@@ -44,10 +45,106 @@ MODULE_VERSION(IWLWIFI_VERSION);
44MODULE_AUTHOR(DRV_COPYRIGHT); 45MODULE_AUTHOR(DRV_COPYRIGHT);
45MODULE_LICENSE("GPL"); 46MODULE_LICENSE("GPL");
46 47
47#ifdef CONFIG_IWLWIFI_DEBUG 48#define IWL_DECLARE_RATE_INFO(r, s, ip, in, rp, rn, pp, np) \
48u32 iwl_debug_level; 49 [IWL_RATE_##r##M_INDEX] = { IWL_RATE_##r##M_PLCP, \
49EXPORT_SYMBOL(iwl_debug_level); 50 IWL_RATE_SISO_##s##M_PLCP, \
50#endif 51 IWL_RATE_MIMO2_##s##M_PLCP,\
52 IWL_RATE_MIMO3_##s##M_PLCP,\
53 IWL_RATE_##r##M_IEEE, \
54 IWL_RATE_##ip##M_INDEX, \
55 IWL_RATE_##in##M_INDEX, \
56 IWL_RATE_##rp##M_INDEX, \
57 IWL_RATE_##rn##M_INDEX, \
58 IWL_RATE_##pp##M_INDEX, \
59 IWL_RATE_##np##M_INDEX }
60
61/*
62 * Parameter order:
63 * rate, ht rate, prev rate, next rate, prev tgg rate, next tgg rate
64 *
65 * If there isn't a valid next or previous rate then INV is used which
66 * maps to IWL_RATE_INVALID
67 *
68 */
69const struct iwl_rate_info iwl_rates[IWL_RATE_COUNT] = {
70 IWL_DECLARE_RATE_INFO(1, INV, INV, 2, INV, 2, INV, 2), /* 1mbps */
71 IWL_DECLARE_RATE_INFO(2, INV, 1, 5, 1, 5, 1, 5), /* 2mbps */
72 IWL_DECLARE_RATE_INFO(5, INV, 2, 6, 2, 11, 2, 11), /*5.5mbps */
73 IWL_DECLARE_RATE_INFO(11, INV, 9, 12, 9, 12, 5, 18), /* 11mbps */
74 IWL_DECLARE_RATE_INFO(6, 6, 5, 9, 5, 11, 5, 11), /* 6mbps */
75 IWL_DECLARE_RATE_INFO(9, 6, 6, 11, 6, 11, 5, 11), /* 9mbps */
76 IWL_DECLARE_RATE_INFO(12, 12, 11, 18, 11, 18, 11, 18), /* 12mbps */
77 IWL_DECLARE_RATE_INFO(18, 18, 12, 24, 12, 24, 11, 24), /* 18mbps */
78 IWL_DECLARE_RATE_INFO(24, 24, 18, 36, 18, 36, 18, 36), /* 24mbps */
79 IWL_DECLARE_RATE_INFO(36, 36, 24, 48, 24, 48, 24, 48), /* 36mbps */
80 IWL_DECLARE_RATE_INFO(48, 48, 36, 54, 36, 54, 36, 54), /* 48mbps */
81 IWL_DECLARE_RATE_INFO(54, 54, 48, INV, 48, INV, 48, INV),/* 54mbps */
82 IWL_DECLARE_RATE_INFO(60, 60, 48, INV, 48, INV, 48, INV),/* 60mbps */
83 /* FIXME:RS: ^^ should be INV (legacy) */
84};
85EXPORT_SYMBOL(iwl_rates);
86
87/**
88 * translate ucode response to mac80211 tx status control values
89 */
90void iwl_hwrate_to_tx_control(struct iwl_priv *priv, u32 rate_n_flags,
91 struct ieee80211_tx_info *control)
92{
93 int rate_index;
94
95 control->antenna_sel_tx =
96 ((rate_n_flags & RATE_MCS_ANT_ABC_MSK) >> RATE_MCS_ANT_POS);
97 if (rate_n_flags & RATE_MCS_HT_MSK)
98 control->flags |= IEEE80211_TX_CTL_OFDM_HT;
99 if (rate_n_flags & RATE_MCS_GF_MSK)
100 control->flags |= IEEE80211_TX_CTL_GREEN_FIELD;
101 if (rate_n_flags & RATE_MCS_FAT_MSK)
102 control->flags |= IEEE80211_TX_CTL_40_MHZ_WIDTH;
103 if (rate_n_flags & RATE_MCS_DUP_MSK)
104 control->flags |= IEEE80211_TX_CTL_DUP_DATA;
105 if (rate_n_flags & RATE_MCS_SGI_MSK)
106 control->flags |= IEEE80211_TX_CTL_SHORT_GI;
107 rate_index = iwl_hwrate_to_plcp_idx(rate_n_flags);
108 if (control->band == IEEE80211_BAND_5GHZ)
109 rate_index -= IWL_FIRST_OFDM_RATE;
110 control->tx_rate_idx = rate_index;
111}
112EXPORT_SYMBOL(iwl_hwrate_to_tx_control);
113
114int iwl_hwrate_to_plcp_idx(u32 rate_n_flags)
115{
116 int idx = 0;
117
118 /* HT rate format */
119 if (rate_n_flags & RATE_MCS_HT_MSK) {
120 idx = (rate_n_flags & 0xff);
121
122 if (idx >= IWL_RATE_MIMO2_6M_PLCP)
123 idx = idx - IWL_RATE_MIMO2_6M_PLCP;
124
125 idx += IWL_FIRST_OFDM_RATE;
126 /* skip 9M not supported in ht*/
127 if (idx >= IWL_RATE_9M_INDEX)
128 idx += 1;
129 if ((idx >= IWL_FIRST_OFDM_RATE) && (idx <= IWL_LAST_OFDM_RATE))
130 return idx;
131
132 /* legacy rate format, search for match in table */
133 } else {
134 for (idx = 0; idx < ARRAY_SIZE(iwl_rates); idx++)
135 if (iwl_rates[idx].plcp == (rate_n_flags & 0xFF))
136 return idx;
137 }
138
139 return -1;
140}
141EXPORT_SYMBOL(iwl_hwrate_to_plcp_idx);
142
143
144
145const u8 iwl_bcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
146EXPORT_SYMBOL(iwl_bcast_addr);
147
51 148
52/* This function both allocates and initializes hw and priv. */ 149/* This function both allocates and initializes hw and priv. */
53struct ieee80211_hw *iwl_alloc_all(struct iwl_cfg *cfg, 150struct ieee80211_hw *iwl_alloc_all(struct iwl_cfg *cfg,
@@ -72,25 +169,132 @@ out:
72} 169}
73EXPORT_SYMBOL(iwl_alloc_all); 170EXPORT_SYMBOL(iwl_alloc_all);
74 171
172void iwl_hw_detect(struct iwl_priv *priv)
173{
174 priv->hw_rev = _iwl_read32(priv, CSR_HW_REV);
175 priv->hw_wa_rev = _iwl_read32(priv, CSR_HW_REV_WA_REG);
176 pci_read_config_byte(priv->pci_dev, PCI_REVISION_ID, &priv->rev_id);
177}
178EXPORT_SYMBOL(iwl_hw_detect);
179
180/* Tell nic where to find the "keep warm" buffer */
181int iwl_kw_init(struct iwl_priv *priv)
182{
183 unsigned long flags;
184 int ret;
185
186 spin_lock_irqsave(&priv->lock, flags);
187 ret = iwl_grab_nic_access(priv);
188 if (ret)
189 goto out;
190
191 iwl_write_direct32(priv, FH_KW_MEM_ADDR_REG,
192 priv->kw.dma_addr >> 4);
193 iwl_release_nic_access(priv);
194out:
195 spin_unlock_irqrestore(&priv->lock, flags);
196 return ret;
197}
198
199int iwl_kw_alloc(struct iwl_priv *priv)
200{
201 struct pci_dev *dev = priv->pci_dev;
202 struct iwl_kw *kw = &priv->kw;
203
204 kw->size = IWL_KW_SIZE;
205 kw->v_addr = pci_alloc_consistent(dev, kw->size, &kw->dma_addr);
206 if (!kw->v_addr)
207 return -ENOMEM;
208
209 return 0;
210}
211
75/** 212/**
76 * iwlcore_clear_stations_table - Clear the driver's station table 213 * iwl_kw_free - Free the "keep warm" buffer
214 */
215void iwl_kw_free(struct iwl_priv *priv)
216{
217 struct pci_dev *dev = priv->pci_dev;
218 struct iwl_kw *kw = &priv->kw;
219
220 if (kw->v_addr) {
221 pci_free_consistent(dev, kw->size, kw->v_addr, kw->dma_addr);
222 memset(kw, 0, sizeof(*kw));
223 }
224}
225
226int iwl_hw_nic_init(struct iwl_priv *priv)
227{
228 unsigned long flags;
229 struct iwl_rx_queue *rxq = &priv->rxq;
230 int ret;
231
232 /* nic_init */
233 spin_lock_irqsave(&priv->lock, flags);
234 priv->cfg->ops->lib->apm_ops.init(priv);
235 iwl_write32(priv, CSR_INT_COALESCING, 512 / 32);
236 spin_unlock_irqrestore(&priv->lock, flags);
237
238 ret = priv->cfg->ops->lib->apm_ops.set_pwr_src(priv, IWL_PWR_SRC_VMAIN);
239
240 priv->cfg->ops->lib->apm_ops.config(priv);
241
242 /* Allocate the RX queue, or reset if it is already allocated */
243 if (!rxq->bd) {
244 ret = iwl_rx_queue_alloc(priv);
245 if (ret) {
246 IWL_ERROR("Unable to initialize Rx queue\n");
247 return -ENOMEM;
248 }
249 } else
250 iwl_rx_queue_reset(priv, rxq);
251
252 iwl_rx_replenish(priv);
253
254 iwl_rx_init(priv, rxq);
255
256 spin_lock_irqsave(&priv->lock, flags);
257
258 rxq->need_update = 1;
259 iwl_rx_queue_update_write_ptr(priv, rxq);
260
261 spin_unlock_irqrestore(&priv->lock, flags);
262
263 /* Allocate and init all Tx and Command queues */
264 ret = iwl_txq_ctx_reset(priv);
265 if (ret)
266 return ret;
267
268 set_bit(STATUS_INIT, &priv->status);
269
270 return 0;
271}
272EXPORT_SYMBOL(iwl_hw_nic_init);
273
274/**
275 * iwl_clear_stations_table - Clear the driver's station table
77 * 276 *
78 * NOTE: This does not clear or otherwise alter the device's station table. 277 * NOTE: This does not clear or otherwise alter the device's station table.
79 */ 278 */
80void iwlcore_clear_stations_table(struct iwl_priv *priv) 279void iwl_clear_stations_table(struct iwl_priv *priv)
81{ 280{
82 unsigned long flags; 281 unsigned long flags;
83 282
84 spin_lock_irqsave(&priv->sta_lock, flags); 283 spin_lock_irqsave(&priv->sta_lock, flags);
85 284
285 if (iwl_is_alive(priv) &&
286 !test_bit(STATUS_EXIT_PENDING, &priv->status) &&
287 iwl_send_cmd_pdu_async(priv, REPLY_REMOVE_ALL_STA, 0, NULL, NULL))
288 IWL_ERROR("Couldn't clear the station table\n");
289
86 priv->num_stations = 0; 290 priv->num_stations = 0;
87 memset(priv->stations, 0, sizeof(priv->stations)); 291 memset(priv->stations, 0, sizeof(priv->stations));
88 292
89 spin_unlock_irqrestore(&priv->sta_lock, flags); 293 spin_unlock_irqrestore(&priv->sta_lock, flags);
90} 294}
91EXPORT_SYMBOL(iwlcore_clear_stations_table); 295EXPORT_SYMBOL(iwl_clear_stations_table);
92 296
93void iwlcore_reset_qos(struct iwl_priv *priv) 297void iwl_reset_qos(struct iwl_priv *priv)
94{ 298{
95 u16 cw_min = 15; 299 u16 cw_min = 15;
96 u16 cw_max = 1023; 300 u16 cw_max = 1023;
@@ -102,14 +306,14 @@ void iwlcore_reset_qos(struct iwl_priv *priv)
102 spin_lock_irqsave(&priv->lock, flags); 306 spin_lock_irqsave(&priv->lock, flags);
103 priv->qos_data.qos_active = 0; 307 priv->qos_data.qos_active = 0;
104 308
105 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) { 309 if (priv->iw_mode == NL80211_IFTYPE_ADHOC) {
106 if (priv->qos_data.qos_enable) 310 if (priv->qos_data.qos_enable)
107 priv->qos_data.qos_active = 1; 311 priv->qos_data.qos_active = 1;
108 if (!(priv->active_rate & 0xfff0)) { 312 if (!(priv->active_rate & 0xfff0)) {
109 cw_min = 31; 313 cw_min = 31;
110 is_legacy = 1; 314 is_legacy = 1;
111 } 315 }
112 } else if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { 316 } else if (priv->iw_mode == NL80211_IFTYPE_AP) {
113 if (priv->qos_data.qos_enable) 317 if (priv->qos_data.qos_enable)
114 priv->qos_data.qos_active = 1; 318 priv->qos_data.qos_active = 1;
115 } else if (!(priv->staging_rxon.flags & RXON_FLG_SHORT_SLOT_MSK)) { 319 } else if (!(priv->staging_rxon.flags & RXON_FLG_SHORT_SLOT_MSK)) {
@@ -176,10 +380,449 @@ void iwlcore_reset_qos(struct iwl_priv *priv)
176 380
177 spin_unlock_irqrestore(&priv->lock, flags); 381 spin_unlock_irqrestore(&priv->lock, flags);
178} 382}
179EXPORT_SYMBOL(iwlcore_reset_qos); 383EXPORT_SYMBOL(iwl_reset_qos);
384
385#define MAX_BIT_RATE_40_MHZ 0x96 /* 150 Mbps */
386#define MAX_BIT_RATE_20_MHZ 0x48 /* 72 Mbps */
387static void iwlcore_init_ht_hw_capab(const struct iwl_priv *priv,
388 struct ieee80211_ht_info *ht_info,
389 enum ieee80211_band band)
390{
391 u16 max_bit_rate = 0;
392 u8 rx_chains_num = priv->hw_params.rx_chains_num;
393 u8 tx_chains_num = priv->hw_params.tx_chains_num;
394
395 ht_info->cap = 0;
396 memset(ht_info->supp_mcs_set, 0, 16);
397
398 ht_info->ht_supported = 1;
399
400 ht_info->cap |= (u16)IEEE80211_HT_CAP_GRN_FLD;
401 ht_info->cap |= (u16)IEEE80211_HT_CAP_SGI_20;
402 ht_info->cap |= (u16)(IEEE80211_HT_CAP_SM_PS &
403 (WLAN_HT_CAP_SM_PS_DISABLED << 2));
404
405 max_bit_rate = MAX_BIT_RATE_20_MHZ;
406 if (priv->hw_params.fat_channel & BIT(band)) {
407 ht_info->cap |= (u16)IEEE80211_HT_CAP_SUP_WIDTH;
408 ht_info->cap |= (u16)IEEE80211_HT_CAP_SGI_40;
409 ht_info->supp_mcs_set[4] = 0x01;
410 max_bit_rate = MAX_BIT_RATE_40_MHZ;
411 }
412
413 if (priv->cfg->mod_params->amsdu_size_8K)
414 ht_info->cap |= (u16)IEEE80211_HT_CAP_MAX_AMSDU;
415
416 ht_info->ampdu_factor = CFG_HT_RX_AMPDU_FACTOR_DEF;
417 ht_info->ampdu_density = CFG_HT_MPDU_DENSITY_DEF;
418
419 ht_info->supp_mcs_set[0] = 0xFF;
420 if (rx_chains_num >= 2)
421 ht_info->supp_mcs_set[1] = 0xFF;
422 if (rx_chains_num >= 3)
423 ht_info->supp_mcs_set[2] = 0xFF;
424
425 /* Highest supported Rx data rate */
426 max_bit_rate *= rx_chains_num;
427 ht_info->supp_mcs_set[10] = (u8)(max_bit_rate & 0x00FF);
428 ht_info->supp_mcs_set[11] = (u8)((max_bit_rate & 0xFF00) >> 8);
429
430 /* Tx MCS capabilities */
431 ht_info->supp_mcs_set[12] = IEEE80211_HT_CAP_MCS_TX_DEFINED;
432 if (tx_chains_num != rx_chains_num) {
433 ht_info->supp_mcs_set[12] |= IEEE80211_HT_CAP_MCS_TX_RX_DIFF;
434 ht_info->supp_mcs_set[12] |= ((tx_chains_num - 1) << 2);
435 }
436}
437
438static void iwlcore_init_hw_rates(struct iwl_priv *priv,
439 struct ieee80211_rate *rates)
440{
441 int i;
442
443 for (i = 0; i < IWL_RATE_COUNT; i++) {
444 rates[i].bitrate = iwl_rates[i].ieee * 5;
445 rates[i].hw_value = i; /* Rate scaling will work on indexes */
446 rates[i].hw_value_short = i;
447 rates[i].flags = 0;
448 if ((i > IWL_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) {
449 /*
450 * If CCK != 1M then set short preamble rate flag.
451 */
452 rates[i].flags |=
453 (iwl_rates[i].plcp == IWL_RATE_1M_PLCP) ?
454 0 : IEEE80211_RATE_SHORT_PREAMBLE;
455 }
456 }
457}
458
459/**
460 * iwlcore_init_geos - Initialize mac80211's geo/channel info based from eeprom
461 */
462static int iwlcore_init_geos(struct iwl_priv *priv)
463{
464 struct iwl_channel_info *ch;
465 struct ieee80211_supported_band *sband;
466 struct ieee80211_channel *channels;
467 struct ieee80211_channel *geo_ch;
468 struct ieee80211_rate *rates;
469 int i = 0;
470
471 if (priv->bands[IEEE80211_BAND_2GHZ].n_bitrates ||
472 priv->bands[IEEE80211_BAND_5GHZ].n_bitrates) {
473 IWL_DEBUG_INFO("Geography modes already initialized.\n");
474 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
475 return 0;
476 }
477
478 channels = kzalloc(sizeof(struct ieee80211_channel) *
479 priv->channel_count, GFP_KERNEL);
480 if (!channels)
481 return -ENOMEM;
482
483 rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_RATE_COUNT + 1)),
484 GFP_KERNEL);
485 if (!rates) {
486 kfree(channels);
487 return -ENOMEM;
488 }
489
490 /* 5.2GHz channels start after the 2.4GHz channels */
491 sband = &priv->bands[IEEE80211_BAND_5GHZ];
492 sband->channels = &channels[ARRAY_SIZE(iwl_eeprom_band_1)];
493 /* just OFDM */
494 sband->bitrates = &rates[IWL_FIRST_OFDM_RATE];
495 sband->n_bitrates = IWL_RATE_COUNT - IWL_FIRST_OFDM_RATE;
496
497 if (priv->cfg->sku & IWL_SKU_N)
498 iwlcore_init_ht_hw_capab(priv, &sband->ht_info,
499 IEEE80211_BAND_5GHZ);
500
501 sband = &priv->bands[IEEE80211_BAND_2GHZ];
502 sband->channels = channels;
503 /* OFDM & CCK */
504 sband->bitrates = rates;
505 sband->n_bitrates = IWL_RATE_COUNT;
506
507 if (priv->cfg->sku & IWL_SKU_N)
508 iwlcore_init_ht_hw_capab(priv, &sband->ht_info,
509 IEEE80211_BAND_2GHZ);
510
511 priv->ieee_channels = channels;
512 priv->ieee_rates = rates;
513
514 iwlcore_init_hw_rates(priv, rates);
515
516 for (i = 0; i < priv->channel_count; i++) {
517 ch = &priv->channel_info[i];
518
519 /* FIXME: might be removed if scan is OK */
520 if (!is_channel_valid(ch))
521 continue;
522
523 if (is_channel_a_band(ch))
524 sband = &priv->bands[IEEE80211_BAND_5GHZ];
525 else
526 sband = &priv->bands[IEEE80211_BAND_2GHZ];
527
528 geo_ch = &sband->channels[sband->n_channels++];
529
530 geo_ch->center_freq =
531 ieee80211_channel_to_frequency(ch->channel);
532 geo_ch->max_power = ch->max_power_avg;
533 geo_ch->max_antenna_gain = 0xff;
534 geo_ch->hw_value = ch->channel;
535
536 if (is_channel_valid(ch)) {
537 if (!(ch->flags & EEPROM_CHANNEL_IBSS))
538 geo_ch->flags |= IEEE80211_CHAN_NO_IBSS;
539
540 if (!(ch->flags & EEPROM_CHANNEL_ACTIVE))
541 geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN;
542
543 if (ch->flags & EEPROM_CHANNEL_RADAR)
544 geo_ch->flags |= IEEE80211_CHAN_RADAR;
545
546 geo_ch->flags |= ch->fat_extension_channel;
547
548 if (ch->max_power_avg > priv->tx_power_channel_lmt)
549 priv->tx_power_channel_lmt = ch->max_power_avg;
550 } else {
551 geo_ch->flags |= IEEE80211_CHAN_DISABLED;
552 }
553
554 /* Save flags for reg domain usage */
555 geo_ch->orig_flags = geo_ch->flags;
556
557 IWL_DEBUG_INFO("Channel %d Freq=%d[%sGHz] %s flag=0x%X\n",
558 ch->channel, geo_ch->center_freq,
559 is_channel_a_band(ch) ? "5.2" : "2.4",
560 geo_ch->flags & IEEE80211_CHAN_DISABLED ?
561 "restricted" : "valid",
562 geo_ch->flags);
563 }
564
565 if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) &&
566 priv->cfg->sku & IWL_SKU_A) {
567 printk(KERN_INFO DRV_NAME
568 ": Incorrectly detected BG card as ABG. Please send "
569 "your PCI ID 0x%04X:0x%04X to maintainer.\n",
570 priv->pci_dev->device, priv->pci_dev->subsystem_device);
571 priv->cfg->sku &= ~IWL_SKU_A;
572 }
573
574 printk(KERN_INFO DRV_NAME
575 ": Tunable channels: %d 802.11bg, %d 802.11a channels\n",
576 priv->bands[IEEE80211_BAND_2GHZ].n_channels,
577 priv->bands[IEEE80211_BAND_5GHZ].n_channels);
578
579
580 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
581
582 return 0;
583}
584
585/*
586 * iwlcore_free_geos - undo allocations in iwlcore_init_geos
587 */
588static void iwlcore_free_geos(struct iwl_priv *priv)
589{
590 kfree(priv->ieee_channels);
591 kfree(priv->ieee_rates);
592 clear_bit(STATUS_GEO_CONFIGURED, &priv->status);
593}
594
595static bool is_single_rx_stream(struct iwl_priv *priv)
596{
597 return !priv->current_ht_config.is_ht ||
598 ((priv->current_ht_config.supp_mcs_set[1] == 0) &&
599 (priv->current_ht_config.supp_mcs_set[2] == 0));
600}
601
602static u8 iwl_is_channel_extension(struct iwl_priv *priv,
603 enum ieee80211_band band,
604 u16 channel, u8 extension_chan_offset)
605{
606 const struct iwl_channel_info *ch_info;
607
608 ch_info = iwl_get_channel_info(priv, band, channel);
609 if (!is_channel_valid(ch_info))
610 return 0;
611
612 if (extension_chan_offset == IEEE80211_HT_IE_CHA_SEC_ABOVE)
613 return !(ch_info->fat_extension_channel &
614 IEEE80211_CHAN_NO_FAT_ABOVE);
615 else if (extension_chan_offset == IEEE80211_HT_IE_CHA_SEC_BELOW)
616 return !(ch_info->fat_extension_channel &
617 IEEE80211_CHAN_NO_FAT_BELOW);
618
619 return 0;
620}
621
622u8 iwl_is_fat_tx_allowed(struct iwl_priv *priv,
623 struct ieee80211_ht_info *sta_ht_inf)
624{
625 struct iwl_ht_info *iwl_ht_conf = &priv->current_ht_config;
626
627 if ((!iwl_ht_conf->is_ht) ||
628 (iwl_ht_conf->supported_chan_width != IWL_CHANNEL_WIDTH_40MHZ) ||
629 (iwl_ht_conf->extension_chan_offset == IEEE80211_HT_IE_CHA_SEC_NONE))
630 return 0;
631
632 if (sta_ht_inf) {
633 if ((!sta_ht_inf->ht_supported) ||
634 (!(sta_ht_inf->cap & IEEE80211_HT_CAP_SUP_WIDTH)))
635 return 0;
636 }
637
638 return iwl_is_channel_extension(priv, priv->band,
639 iwl_ht_conf->control_channel,
640 iwl_ht_conf->extension_chan_offset);
641}
642EXPORT_SYMBOL(iwl_is_fat_tx_allowed);
643
644void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_info *ht_info)
645{
646 struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
647 u32 val;
648
649 if (!ht_info->is_ht) {
650 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK |
651 RXON_FLG_CHANNEL_MODE_PURE_40_MSK |
652 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK |
653 RXON_FLG_FAT_PROT_MSK |
654 RXON_FLG_HT_PROT_MSK);
655 return;
656 }
657
658 /* Set up channel bandwidth: 20 MHz only, or 20/40 mixed if fat ok */
659 if (iwl_is_fat_tx_allowed(priv, NULL))
660 rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED_MSK;
661 else
662 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK |
663 RXON_FLG_CHANNEL_MODE_PURE_40_MSK);
664
665 if (le16_to_cpu(rxon->channel) != ht_info->control_channel) {
666 IWL_DEBUG_ASSOC("control diff than current %d %d\n",
667 le16_to_cpu(rxon->channel),
668 ht_info->control_channel);
669 return;
670 }
671
672 /* Note: control channel is opposite of extension channel */
673 switch (ht_info->extension_chan_offset) {
674 case IEEE80211_HT_IE_CHA_SEC_ABOVE:
675 rxon->flags &= ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
676 break;
677 case IEEE80211_HT_IE_CHA_SEC_BELOW:
678 rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
679 break;
680 case IEEE80211_HT_IE_CHA_SEC_NONE:
681 default:
682 rxon->flags &= ~RXON_FLG_CHANNEL_MODE_MIXED_MSK;
683 break;
684 }
685
686 val = ht_info->ht_protection;
687
688 rxon->flags |= cpu_to_le32(val << RXON_FLG_HT_OPERATING_MODE_POS);
689
690 iwl_set_rxon_chain(priv);
691
692 IWL_DEBUG_ASSOC("supported HT rate 0x%X 0x%X 0x%X "
693 "rxon flags 0x%X operation mode :0x%X "
694 "extension channel offset 0x%x "
695 "control chan %d\n",
696 ht_info->supp_mcs_set[0],
697 ht_info->supp_mcs_set[1],
698 ht_info->supp_mcs_set[2],
699 le32_to_cpu(rxon->flags), ht_info->ht_protection,
700 ht_info->extension_chan_offset,
701 ht_info->control_channel);
702 return;
703}
704EXPORT_SYMBOL(iwl_set_rxon_ht);
705
706#define IWL_NUM_RX_CHAINS_MULTIPLE 3
707#define IWL_NUM_RX_CHAINS_SINGLE 2
708#define IWL_NUM_IDLE_CHAINS_DUAL 2
709#define IWL_NUM_IDLE_CHAINS_SINGLE 1
710
711/* Determine how many receiver/antenna chains to use.
712 * More provides better reception via diversity. Fewer saves power.
713 * MIMO (dual stream) requires at least 2, but works better with 3.
714 * This does not determine *which* chains to use, just how many.
715 */
716static int iwl_get_active_rx_chain_count(struct iwl_priv *priv)
717{
718 bool is_single = is_single_rx_stream(priv);
719 bool is_cam = !test_bit(STATUS_POWER_PMI, &priv->status);
720
721 /* # of Rx chains to use when expecting MIMO. */
722 if (is_single || (!is_cam && (priv->current_ht_config.sm_ps ==
723 WLAN_HT_CAP_SM_PS_STATIC)))
724 return IWL_NUM_RX_CHAINS_SINGLE;
725 else
726 return IWL_NUM_RX_CHAINS_MULTIPLE;
727}
728
729static int iwl_get_idle_rx_chain_count(struct iwl_priv *priv, int active_cnt)
730{
731 int idle_cnt;
732 bool is_cam = !test_bit(STATUS_POWER_PMI, &priv->status);
733 /* # Rx chains when idling and maybe trying to save power */
734 switch (priv->current_ht_config.sm_ps) {
735 case WLAN_HT_CAP_SM_PS_STATIC:
736 case WLAN_HT_CAP_SM_PS_DYNAMIC:
737 idle_cnt = (is_cam) ? IWL_NUM_IDLE_CHAINS_DUAL :
738 IWL_NUM_IDLE_CHAINS_SINGLE;
739 break;
740 case WLAN_HT_CAP_SM_PS_DISABLED:
741 idle_cnt = (is_cam) ? active_cnt : IWL_NUM_IDLE_CHAINS_SINGLE;
742 break;
743 case WLAN_HT_CAP_SM_PS_INVALID:
744 default:
745 IWL_ERROR("invalide mimo ps mode %d\n",
746 priv->current_ht_config.sm_ps);
747 WARN_ON(1);
748 idle_cnt = -1;
749 break;
750 }
751 return idle_cnt;
752}
753
754/* up to 4 chains */
755static u8 iwl_count_chain_bitmap(u32 chain_bitmap)
756{
757 u8 res;
758 res = (chain_bitmap & BIT(0)) >> 0;
759 res += (chain_bitmap & BIT(1)) >> 1;
760 res += (chain_bitmap & BIT(2)) >> 2;
761 res += (chain_bitmap & BIT(4)) >> 4;
762 return res;
763}
180 764
181/** 765/**
182 * iwlcore_set_rxon_channel - Set the phymode and channel values in staging RXON 766 * iwl_set_rxon_chain - Set up Rx chain usage in "staging" RXON image
767 *
768 * Selects how many and which Rx receivers/antennas/chains to use.
769 * This should not be used for scan command ... it puts data in wrong place.
770 */
771void iwl_set_rxon_chain(struct iwl_priv *priv)
772{
773 bool is_single = is_single_rx_stream(priv);
774 bool is_cam = !test_bit(STATUS_POWER_PMI, &priv->status);
775 u8 idle_rx_cnt, active_rx_cnt, valid_rx_cnt;
776 u32 active_chains;
777 u16 rx_chain;
778
779 /* Tell uCode which antennas are actually connected.
780 * Before first association, we assume all antennas are connected.
781 * Just after first association, iwl_chain_noise_calibration()
782 * checks which antennas actually *are* connected. */
783 if (priv->chain_noise_data.active_chains)
784 active_chains = priv->chain_noise_data.active_chains;
785 else
786 active_chains = priv->hw_params.valid_rx_ant;
787
788 rx_chain = active_chains << RXON_RX_CHAIN_VALID_POS;
789
790 /* How many receivers should we use? */
791 active_rx_cnt = iwl_get_active_rx_chain_count(priv);
792 idle_rx_cnt = iwl_get_idle_rx_chain_count(priv, active_rx_cnt);
793
794
795 /* correct rx chain count according hw settings
796 * and chain noise calibration
797 */
798 valid_rx_cnt = iwl_count_chain_bitmap(active_chains);
799 if (valid_rx_cnt < active_rx_cnt)
800 active_rx_cnt = valid_rx_cnt;
801
802 if (valid_rx_cnt < idle_rx_cnt)
803 idle_rx_cnt = valid_rx_cnt;
804
805 rx_chain |= active_rx_cnt << RXON_RX_CHAIN_MIMO_CNT_POS;
806 rx_chain |= idle_rx_cnt << RXON_RX_CHAIN_CNT_POS;
807
808 priv->staging_rxon.rx_chain = cpu_to_le16(rx_chain);
809
810 if (!is_single && (active_rx_cnt >= IWL_NUM_RX_CHAINS_SINGLE) && is_cam)
811 priv->staging_rxon.rx_chain |= RXON_RX_CHAIN_MIMO_FORCE_MSK;
812 else
813 priv->staging_rxon.rx_chain &= ~RXON_RX_CHAIN_MIMO_FORCE_MSK;
814
815 IWL_DEBUG_ASSOC("rx_chain=0x%X active=%d idle=%d\n",
816 priv->staging_rxon.rx_chain,
817 active_rx_cnt, idle_rx_cnt);
818
819 WARN_ON(active_rx_cnt == 0 || idle_rx_cnt == 0 ||
820 active_rx_cnt < idle_rx_cnt);
821}
822EXPORT_SYMBOL(iwl_set_rxon_chain);
823
824/**
825 * iwl_set_rxon_channel - Set the phymode and channel values in staging RXON
183 * @phymode: MODE_IEEE80211A sets to 5.2GHz; all else set to 2.4GHz 826 * @phymode: MODE_IEEE80211A sets to 5.2GHz; all else set to 2.4GHz
184 * @channel: Any channel valid for the requested phymode 827 * @channel: Any channel valid for the requested phymode
185 828
@@ -188,10 +831,11 @@ EXPORT_SYMBOL(iwlcore_reset_qos);
188 * NOTE: Does not commit to the hardware; it sets appropriate bit fields 831 * NOTE: Does not commit to the hardware; it sets appropriate bit fields
189 * in the staging RXON flag structure based on the phymode 832 * in the staging RXON flag structure based on the phymode
190 */ 833 */
191int iwlcore_set_rxon_channel(struct iwl_priv *priv, 834int iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch)
192 enum ieee80211_band band,
193 u16 channel)
194{ 835{
836 enum ieee80211_band band = ch->band;
837 u16 channel = ieee80211_frequency_to_channel(ch->center_freq);
838
195 if (!iwl_get_channel_info(priv, band, channel)) { 839 if (!iwl_get_channel_info(priv, band, channel)) {
196 IWL_DEBUG_INFO("Could not set channel to %d [%d]\n", 840 IWL_DEBUG_INFO("Could not set channel to %d [%d]\n",
197 channel, band); 841 channel, band);
@@ -214,68 +858,169 @@ int iwlcore_set_rxon_channel(struct iwl_priv *priv,
214 858
215 return 0; 859 return 0;
216} 860}
217EXPORT_SYMBOL(iwlcore_set_rxon_channel); 861EXPORT_SYMBOL(iwl_set_rxon_channel);
218 862
219static void iwlcore_init_hw(struct iwl_priv *priv) 863int iwl_setup_mac(struct iwl_priv *priv)
220{ 864{
865 int ret;
221 struct ieee80211_hw *hw = priv->hw; 866 struct ieee80211_hw *hw = priv->hw;
222 hw->rate_control_algorithm = "iwl-4965-rs"; 867 hw->rate_control_algorithm = "iwl-agn-rs";
223
224 /* Tell mac80211 and its clients (e.g. Wireless Extensions)
225 * the range of signal quality values that we'll provide.
226 * Negative values for level/noise indicate that we'll provide dBm.
227 * For WE, at least, non-0 values here *enable* display of values
228 * in app (iwconfig). */
229 hw->max_rssi = -20; /* signal level, negative indicates dBm */
230 hw->max_noise = -20; /* noise level, negative indicates dBm */
231 hw->max_signal = 100; /* link quality indication (%) */
232
233 /* Tell mac80211 our Tx characteristics */
234 hw->flags = IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE;
235 868
869 /* Tell mac80211 our characteristics */
870 hw->flags = IEEE80211_HW_SIGNAL_DBM |
871 IEEE80211_HW_NOISE_DBM;
872 hw->wiphy->interface_modes =
873 BIT(NL80211_IFTYPE_AP) |
874 BIT(NL80211_IFTYPE_STATION) |
875 BIT(NL80211_IFTYPE_ADHOC);
236 /* Default value; 4 EDCA QOS priorities */ 876 /* Default value; 4 EDCA QOS priorities */
237 hw->queues = 4; 877 hw->queues = 4;
238#ifdef CONFIG_IWL4965_HT 878 /* queues to support 11n aggregation */
239 /* Enhanced value; more queues, to support 11n aggregation */ 879 if (priv->cfg->sku & IWL_SKU_N)
240 hw->queues = 16; 880 hw->ampdu_queues = priv->cfg->mod_params->num_of_ampdu_queues;
241#endif /* CONFIG_IWL4965_HT */ 881
882 hw->conf.beacon_int = 100;
883 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
884
885 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
886 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
887 &priv->bands[IEEE80211_BAND_2GHZ];
888 if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
889 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
890 &priv->bands[IEEE80211_BAND_5GHZ];
891
892 ret = ieee80211_register_hw(priv->hw);
893 if (ret) {
894 IWL_ERROR("Failed to register hw (error %d)\n", ret);
895 return ret;
896 }
897 priv->mac80211_registered = 1;
898
899 return 0;
242} 900}
901EXPORT_SYMBOL(iwl_setup_mac);
243 902
244int iwl_setup(struct iwl_priv *priv) 903int iwl_set_hw_params(struct iwl_priv *priv)
245{ 904{
246 int ret = 0; 905 priv->hw_params.sw_crypto = priv->cfg->mod_params->sw_crypto;
247 iwlcore_init_hw(priv); 906 priv->hw_params.max_rxq_size = RX_QUEUE_SIZE;
248 ret = priv->cfg->ops->lib->init_drv(priv); 907 priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
249 return ret; 908 if (priv->cfg->mod_params->amsdu_size_8K)
909 priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_8K;
910 else
911 priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_4K;
912 priv->hw_params.max_pkt_size = priv->hw_params.rx_buf_size - 256;
913
914 if (priv->cfg->mod_params->disable_11n)
915 priv->cfg->sku &= ~IWL_SKU_N;
916
917 /* Device-specific setup */
918 return priv->cfg->ops->lib->set_hw_params(priv);
250} 919}
251EXPORT_SYMBOL(iwl_setup); 920EXPORT_SYMBOL(iwl_set_hw_params);
252 921
253/* Low level driver call this function to update iwlcore with 922int iwl_init_drv(struct iwl_priv *priv)
254 * driver status.
255 */
256int iwlcore_low_level_notify(struct iwl_priv *priv,
257 enum iwlcore_card_notify notify)
258{ 923{
259 int ret; 924 int ret;
260 switch (notify) { 925
261 case IWLCORE_INIT_EVT: 926 priv->retry_rate = 1;
262 ret = iwl_rfkill_init(priv); 927 priv->ibss_beacon = NULL;
263 if (ret) 928
264 IWL_ERROR("Unable to initialize RFKILL system. " 929 spin_lock_init(&priv->lock);
265 "Ignoring error: %d\n", ret); 930 spin_lock_init(&priv->power_data.lock);
266 break; 931 spin_lock_init(&priv->sta_lock);
267 case IWLCORE_START_EVT: 932 spin_lock_init(&priv->hcmd_lock);
268 break; 933
269 case IWLCORE_STOP_EVT: 934 INIT_LIST_HEAD(&priv->free_frames);
270 break; 935
271 case IWLCORE_REMOVE_EVT: 936 mutex_init(&priv->mutex);
272 iwl_rfkill_unregister(priv); 937
273 break; 938 /* Clear the driver's (not device's) station table */
939 iwl_clear_stations_table(priv);
940
941 priv->data_retry_limit = -1;
942 priv->ieee_channels = NULL;
943 priv->ieee_rates = NULL;
944 priv->band = IEEE80211_BAND_2GHZ;
945
946 priv->iw_mode = NL80211_IFTYPE_STATION;
947
948 priv->use_ant_b_for_management_frame = 1; /* start with ant B */
949 priv->current_ht_config.sm_ps = WLAN_HT_CAP_SM_PS_DISABLED;
950
951 /* Choose which receivers/antennas to use */
952 iwl_set_rxon_chain(priv);
953 iwl_init_scan_params(priv);
954
955 if (priv->cfg->mod_params->enable_qos)
956 priv->qos_data.qos_enable = 1;
957
958 iwl_reset_qos(priv);
959
960 priv->qos_data.qos_active = 0;
961 priv->qos_data.qos_cap.val = 0;
962
963 priv->rates_mask = IWL_RATES_MASK;
964 /* If power management is turned on, default to AC mode */
965 priv->power_mode = IWL_POWER_AC;
966 priv->tx_power_user_lmt = IWL_TX_POWER_TARGET_POWER_MAX;
967
968 ret = iwl_init_channel_map(priv);
969 if (ret) {
970 IWL_ERROR("initializing regulatory failed: %d\n", ret);
971 goto err;
972 }
973
974 ret = iwlcore_init_geos(priv);
975 if (ret) {
976 IWL_ERROR("initializing geos failed: %d\n", ret);
977 goto err_free_channel_map;
274 } 978 }
275 979
276 return 0; 980 return 0;
981
982err_free_channel_map:
983 iwl_free_channel_map(priv);
984err:
985 return ret;
277} 986}
278EXPORT_SYMBOL(iwlcore_low_level_notify); 987EXPORT_SYMBOL(iwl_init_drv);
988
989int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force)
990{
991 int ret = 0;
992 if (tx_power < IWL_TX_POWER_TARGET_POWER_MIN) {
993 IWL_WARNING("Requested user TXPOWER %d below limit.\n",
994 priv->tx_power_user_lmt);
995 return -EINVAL;
996 }
997
998 if (tx_power > IWL_TX_POWER_TARGET_POWER_MAX) {
999 IWL_WARNING("Requested user TXPOWER %d above limit.\n",
1000 priv->tx_power_user_lmt);
1001 return -EINVAL;
1002 }
1003
1004 if (priv->tx_power_user_lmt != tx_power)
1005 force = true;
1006
1007 priv->tx_power_user_lmt = tx_power;
1008
1009 if (force && priv->cfg->ops->lib->send_tx_power)
1010 ret = priv->cfg->ops->lib->send_tx_power(priv);
1011
1012 return ret;
1013}
1014EXPORT_SYMBOL(iwl_set_tx_power);
1015
1016void iwl_uninit_drv(struct iwl_priv *priv)
1017{
1018 iwl_calib_free_results(priv);
1019 iwlcore_free_geos(priv);
1020 iwl_free_channel_map(priv);
1021 kfree(priv->scan);
1022}
1023EXPORT_SYMBOL(iwl_uninit_drv);
279 1024
280int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags) 1025int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags)
281{ 1026{
@@ -290,3 +1035,437 @@ int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags)
290} 1035}
291EXPORT_SYMBOL(iwl_send_statistics_request); 1036EXPORT_SYMBOL(iwl_send_statistics_request);
292 1037
1038/**
1039 * iwl_verify_inst_sparse - verify runtime uCode image in card vs. host,
1040 * using sample data 100 bytes apart. If these sample points are good,
1041 * it's a pretty good bet that everything between them is good, too.
1042 */
1043static int iwlcore_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
1044{
1045 u32 val;
1046 int ret = 0;
1047 u32 errcnt = 0;
1048 u32 i;
1049
1050 IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
1051
1052 ret = iwl_grab_nic_access(priv);
1053 if (ret)
1054 return ret;
1055
1056 for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
1057 /* read data comes through single port, auto-incr addr */
1058 /* NOTE: Use the debugless read so we don't flood kernel log
1059 * if IWL_DL_IO is set */
1060 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
1061 i + RTC_INST_LOWER_BOUND);
1062 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
1063 if (val != le32_to_cpu(*image)) {
1064 ret = -EIO;
1065 errcnt++;
1066 if (errcnt >= 3)
1067 break;
1068 }
1069 }
1070
1071 iwl_release_nic_access(priv);
1072
1073 return ret;
1074}
1075
1076/**
1077 * iwlcore_verify_inst_full - verify runtime uCode image in card vs. host,
1078 * looking at all data.
1079 */
1080static int iwl_verify_inst_full(struct iwl_priv *priv, __le32 *image,
1081 u32 len)
1082{
1083 u32 val;
1084 u32 save_len = len;
1085 int ret = 0;
1086 u32 errcnt;
1087
1088 IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
1089
1090 ret = iwl_grab_nic_access(priv);
1091 if (ret)
1092 return ret;
1093
1094 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, RTC_INST_LOWER_BOUND);
1095
1096 errcnt = 0;
1097 for (; len > 0; len -= sizeof(u32), image++) {
1098 /* read data comes through single port, auto-incr addr */
1099 /* NOTE: Use the debugless read so we don't flood kernel log
1100 * if IWL_DL_IO is set */
1101 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
1102 if (val != le32_to_cpu(*image)) {
1103 IWL_ERROR("uCode INST section is invalid at "
1104 "offset 0x%x, is 0x%x, s/b 0x%x\n",
1105 save_len - len, val, le32_to_cpu(*image));
1106 ret = -EIO;
1107 errcnt++;
1108 if (errcnt >= 20)
1109 break;
1110 }
1111 }
1112
1113 iwl_release_nic_access(priv);
1114
1115 if (!errcnt)
1116 IWL_DEBUG_INFO
1117 ("ucode image in INSTRUCTION memory is good\n");
1118
1119 return ret;
1120}
1121
1122/**
1123 * iwl_verify_ucode - determine which instruction image is in SRAM,
1124 * and verify its contents
1125 */
1126int iwl_verify_ucode(struct iwl_priv *priv)
1127{
1128 __le32 *image;
1129 u32 len;
1130 int ret;
1131
1132 /* Try bootstrap */
1133 image = (__le32 *)priv->ucode_boot.v_addr;
1134 len = priv->ucode_boot.len;
1135 ret = iwlcore_verify_inst_sparse(priv, image, len);
1136 if (!ret) {
1137 IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n");
1138 return 0;
1139 }
1140
1141 /* Try initialize */
1142 image = (__le32 *)priv->ucode_init.v_addr;
1143 len = priv->ucode_init.len;
1144 ret = iwlcore_verify_inst_sparse(priv, image, len);
1145 if (!ret) {
1146 IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n");
1147 return 0;
1148 }
1149
1150 /* Try runtime/protocol */
1151 image = (__le32 *)priv->ucode_code.v_addr;
1152 len = priv->ucode_code.len;
1153 ret = iwlcore_verify_inst_sparse(priv, image, len);
1154 if (!ret) {
1155 IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n");
1156 return 0;
1157 }
1158
1159 IWL_ERROR("NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
1160
1161 /* Since nothing seems to match, show first several data entries in
1162 * instruction SRAM, so maybe visual inspection will give a clue.
1163 * Selection of bootstrap image (vs. other images) is arbitrary. */
1164 image = (__le32 *)priv->ucode_boot.v_addr;
1165 len = priv->ucode_boot.len;
1166 ret = iwl_verify_inst_full(priv, image, len);
1167
1168 return ret;
1169}
1170EXPORT_SYMBOL(iwl_verify_ucode);
1171
1172static const char *desc_lookup(int i)
1173{
1174 switch (i) {
1175 case 1:
1176 return "FAIL";
1177 case 2:
1178 return "BAD_PARAM";
1179 case 3:
1180 return "BAD_CHECKSUM";
1181 case 4:
1182 return "NMI_INTERRUPT";
1183 case 5:
1184 return "SYSASSERT";
1185 case 6:
1186 return "FATAL_ERROR";
1187 }
1188
1189 return "UNKNOWN";
1190}
1191
1192#define ERROR_START_OFFSET (1 * sizeof(u32))
1193#define ERROR_ELEM_SIZE (7 * sizeof(u32))
1194
1195void iwl_dump_nic_error_log(struct iwl_priv *priv)
1196{
1197 u32 data2, line;
1198 u32 desc, time, count, base, data1;
1199 u32 blink1, blink2, ilink1, ilink2;
1200 int ret;
1201
1202 if (priv->ucode_type == UCODE_INIT)
1203 base = le32_to_cpu(priv->card_alive_init.error_event_table_ptr);
1204 else
1205 base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
1206
1207 if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
1208 IWL_ERROR("Not valid error log pointer 0x%08X\n", base);
1209 return;
1210 }
1211
1212 ret = iwl_grab_nic_access(priv);
1213 if (ret) {
1214 IWL_WARNING("Can not read from adapter at this time.\n");
1215 return;
1216 }
1217
1218 count = iwl_read_targ_mem(priv, base);
1219
1220 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
1221 IWL_ERROR("Start IWL Error Log Dump:\n");
1222 IWL_ERROR("Status: 0x%08lX, count: %d\n", priv->status, count);
1223 }
1224
1225 desc = iwl_read_targ_mem(priv, base + 1 * sizeof(u32));
1226 blink1 = iwl_read_targ_mem(priv, base + 3 * sizeof(u32));
1227 blink2 = iwl_read_targ_mem(priv, base + 4 * sizeof(u32));
1228 ilink1 = iwl_read_targ_mem(priv, base + 5 * sizeof(u32));
1229 ilink2 = iwl_read_targ_mem(priv, base + 6 * sizeof(u32));
1230 data1 = iwl_read_targ_mem(priv, base + 7 * sizeof(u32));
1231 data2 = iwl_read_targ_mem(priv, base + 8 * sizeof(u32));
1232 line = iwl_read_targ_mem(priv, base + 9 * sizeof(u32));
1233 time = iwl_read_targ_mem(priv, base + 11 * sizeof(u32));
1234
1235 IWL_ERROR("Desc Time "
1236 "data1 data2 line\n");
1237 IWL_ERROR("%-13s (#%d) %010u 0x%08X 0x%08X %u\n",
1238 desc_lookup(desc), desc, time, data1, data2, line);
1239 IWL_ERROR("blink1 blink2 ilink1 ilink2\n");
1240 IWL_ERROR("0x%05X 0x%05X 0x%05X 0x%05X\n", blink1, blink2,
1241 ilink1, ilink2);
1242
1243 iwl_release_nic_access(priv);
1244}
1245EXPORT_SYMBOL(iwl_dump_nic_error_log);
1246
1247#define EVENT_START_OFFSET (4 * sizeof(u32))
1248
1249/**
1250 * iwl_print_event_log - Dump error event log to syslog
1251 *
1252 * NOTE: Must be called with iwl_grab_nic_access() already obtained!
1253 */
1254static void iwl_print_event_log(struct iwl_priv *priv, u32 start_idx,
1255 u32 num_events, u32 mode)
1256{
1257 u32 i;
1258 u32 base; /* SRAM byte address of event log header */
1259 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
1260 u32 ptr; /* SRAM byte address of log data */
1261 u32 ev, time, data; /* event log data */
1262
1263 if (num_events == 0)
1264 return;
1265 if (priv->ucode_type == UCODE_INIT)
1266 base = le32_to_cpu(priv->card_alive_init.log_event_table_ptr);
1267 else
1268 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
1269
1270 if (mode == 0)
1271 event_size = 2 * sizeof(u32);
1272 else
1273 event_size = 3 * sizeof(u32);
1274
1275 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
1276
1277 /* "time" is actually "data" for mode 0 (no timestamp).
1278 * place event id # at far right for easier visual parsing. */
1279 for (i = 0; i < num_events; i++) {
1280 ev = iwl_read_targ_mem(priv, ptr);
1281 ptr += sizeof(u32);
1282 time = iwl_read_targ_mem(priv, ptr);
1283 ptr += sizeof(u32);
1284 if (mode == 0) {
1285 /* data, ev */
1286 IWL_ERROR("EVT_LOG:0x%08x:%04u\n", time, ev);
1287 } else {
1288 data = iwl_read_targ_mem(priv, ptr);
1289 ptr += sizeof(u32);
1290 IWL_ERROR("EVT_LOGT:%010u:0x%08x:%04u\n",
1291 time, data, ev);
1292 }
1293 }
1294}
1295
1296void iwl_dump_nic_event_log(struct iwl_priv *priv)
1297{
1298 int ret;
1299 u32 base; /* SRAM byte address of event log header */
1300 u32 capacity; /* event log capacity in # entries */
1301 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
1302 u32 num_wraps; /* # times uCode wrapped to top of log */
1303 u32 next_entry; /* index of next entry to be written by uCode */
1304 u32 size; /* # entries that we'll print */
1305
1306 if (priv->ucode_type == UCODE_INIT)
1307 base = le32_to_cpu(priv->card_alive_init.log_event_table_ptr);
1308 else
1309 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
1310
1311 if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
1312 IWL_ERROR("Invalid event log pointer 0x%08X\n", base);
1313 return;
1314 }
1315
1316 ret = iwl_grab_nic_access(priv);
1317 if (ret) {
1318 IWL_WARNING("Can not read from adapter at this time.\n");
1319 return;
1320 }
1321
1322 /* event log header */
1323 capacity = iwl_read_targ_mem(priv, base);
1324 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
1325 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
1326 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
1327
1328 size = num_wraps ? capacity : next_entry;
1329
1330 /* bail out if nothing in log */
1331 if (size == 0) {
1332 IWL_ERROR("Start IWL Event Log Dump: nothing in log\n");
1333 iwl_release_nic_access(priv);
1334 return;
1335 }
1336
1337 IWL_ERROR("Start IWL Event Log Dump: display count %d, wraps %d\n",
1338 size, num_wraps);
1339
1340 /* if uCode has wrapped back to top of log, start at the oldest entry,
1341 * i.e the next one that uCode would fill. */
1342 if (num_wraps)
1343 iwl_print_event_log(priv, next_entry,
1344 capacity - next_entry, mode);
1345 /* (then/else) start at top of log */
1346 iwl_print_event_log(priv, 0, next_entry, mode);
1347
1348 iwl_release_nic_access(priv);
1349}
1350EXPORT_SYMBOL(iwl_dump_nic_event_log);
1351
1352void iwl_rf_kill_ct_config(struct iwl_priv *priv)
1353{
1354 struct iwl_ct_kill_config cmd;
1355 unsigned long flags;
1356 int ret = 0;
1357
1358 spin_lock_irqsave(&priv->lock, flags);
1359 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
1360 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
1361 spin_unlock_irqrestore(&priv->lock, flags);
1362
1363 cmd.critical_temperature_R =
1364 cpu_to_le32(priv->hw_params.ct_kill_threshold);
1365
1366 ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
1367 sizeof(cmd), &cmd);
1368 if (ret)
1369 IWL_ERROR("REPLY_CT_KILL_CONFIG_CMD failed\n");
1370 else
1371 IWL_DEBUG_INFO("REPLY_CT_KILL_CONFIG_CMD succeeded, "
1372 "critical temperature is %d\n",
1373 cmd.critical_temperature_R);
1374}
1375EXPORT_SYMBOL(iwl_rf_kill_ct_config);
1376
1377/*
1378 * CARD_STATE_CMD
1379 *
1380 * Use: Sets the device's internal card state to enable, disable, or halt
1381 *
1382 * When in the 'enable' state the card operates as normal.
1383 * When in the 'disable' state, the card enters into a low power mode.
1384 * When in the 'halt' state, the card is shut down and must be fully
1385 * restarted to come back on.
1386 */
1387static int iwl_send_card_state(struct iwl_priv *priv, u32 flags, u8 meta_flag)
1388{
1389 struct iwl_host_cmd cmd = {
1390 .id = REPLY_CARD_STATE_CMD,
1391 .len = sizeof(u32),
1392 .data = &flags,
1393 .meta.flags = meta_flag,
1394 };
1395
1396 return iwl_send_cmd(priv, &cmd);
1397}
1398
1399void iwl_radio_kill_sw_disable_radio(struct iwl_priv *priv)
1400{
1401 unsigned long flags;
1402
1403 if (test_bit(STATUS_RF_KILL_SW, &priv->status))
1404 return;
1405
1406 IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO OFF\n");
1407
1408 iwl_scan_cancel(priv);
1409 /* FIXME: This is a workaround for AP */
1410 if (priv->iw_mode != NL80211_IFTYPE_AP) {
1411 spin_lock_irqsave(&priv->lock, flags);
1412 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
1413 CSR_UCODE_SW_BIT_RFKILL);
1414 spin_unlock_irqrestore(&priv->lock, flags);
1415 /* call the host command only if no hw rf-kill set */
1416 if (!test_bit(STATUS_RF_KILL_HW, &priv->status) &&
1417 iwl_is_ready(priv))
1418 iwl_send_card_state(priv,
1419 CARD_STATE_CMD_DISABLE, 0);
1420 set_bit(STATUS_RF_KILL_SW, &priv->status);
1421 /* make sure mac80211 stop sending Tx frame */
1422 if (priv->mac80211_registered)
1423 ieee80211_stop_queues(priv->hw);
1424 }
1425}
1426EXPORT_SYMBOL(iwl_radio_kill_sw_disable_radio);
1427
1428int iwl_radio_kill_sw_enable_radio(struct iwl_priv *priv)
1429{
1430 unsigned long flags;
1431
1432 if (!test_bit(STATUS_RF_KILL_SW, &priv->status))
1433 return 0;
1434
1435 IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO ON\n");
1436
1437 spin_lock_irqsave(&priv->lock, flags);
1438 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
1439
1440 /* If the driver is up it will receive CARD_STATE_NOTIFICATION
1441 * notification where it will clear SW rfkill status.
1442 * Setting it here would break the handler. Only if the
1443 * interface is down we can set here since we don't
1444 * receive any further notification.
1445 */
1446 if (!priv->is_open)
1447 clear_bit(STATUS_RF_KILL_SW, &priv->status);
1448 spin_unlock_irqrestore(&priv->lock, flags);
1449
1450 /* wake up ucode */
1451 msleep(10);
1452
1453 spin_lock_irqsave(&priv->lock, flags);
1454 iwl_read32(priv, CSR_UCODE_DRV_GP1);
1455 if (!iwl_grab_nic_access(priv))
1456 iwl_release_nic_access(priv);
1457 spin_unlock_irqrestore(&priv->lock, flags);
1458
1459 if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
1460 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
1461 "disabled by HW switch\n");
1462 return 0;
1463 }
1464
1465 /* If the driver is already loaded, it will receive
1466 * CARD_STATE_NOTIFICATION notifications and the handler will
1467 * call restart to reload the driver.
1468 */
1469 return 1;
1470}
1471EXPORT_SYMBOL(iwl_radio_kill_sw_enable_radio);
diff --git a/drivers/net/wireless/iwlwifi/iwl-core.h b/drivers/net/wireless/iwlwifi/iwl-core.h
index 7193d97630dc..288b6a800e03 100644
--- a/drivers/net/wireless/iwlwifi/iwl-core.h
+++ b/drivers/net/wireless/iwlwifi/iwl-core.h
@@ -70,7 +70,7 @@ struct iwl_host_cmd;
70struct iwl_cmd; 70struct iwl_cmd;
71 71
72 72
73#define IWLWIFI_VERSION "1.2.26k" 73#define IWLWIFI_VERSION "1.3.27k"
74#define DRV_COPYRIGHT "Copyright(c) 2003-2008 Intel Corporation" 74#define DRV_COPYRIGHT "Copyright(c) 2003-2008 Intel Corporation"
75 75
76#define IWL_PCI_DEVICE(dev, subdev, cfg) \ 76#define IWL_PCI_DEVICE(dev, subdev, cfg) \
@@ -86,28 +86,64 @@ struct iwl_hcmd_ops {
86 int (*rxon_assoc)(struct iwl_priv *priv); 86 int (*rxon_assoc)(struct iwl_priv *priv);
87}; 87};
88struct iwl_hcmd_utils_ops { 88struct iwl_hcmd_utils_ops {
89 int (*enqueue_hcmd)(struct iwl_priv *priv, struct iwl_host_cmd *cmd); 89 u16 (*get_hcmd_size)(u8 cmd_id, u16 len);
90 u16 (*build_addsta_hcmd)(const struct iwl_addsta_cmd *cmd, u8 *data);
91 void (*gain_computation)(struct iwl_priv *priv,
92 u32 *average_noise,
93 u16 min_average_noise_antennat_i,
94 u32 min_average_noise);
95 void (*chain_noise_reset)(struct iwl_priv *priv);
96 void (*rts_tx_cmd_flag)(struct ieee80211_tx_info *info,
97 __le32 *tx_flags);
98 int (*calc_rssi)(struct iwl_priv *priv,
99 struct iwl_rx_phy_res *rx_resp);
90}; 100};
91 101
92struct iwl_lib_ops { 102struct iwl_lib_ops {
93 /* iwlwifi driver (priv) init */
94 int (*init_drv)(struct iwl_priv *priv);
95 /* set hw dependant perameters */ 103 /* set hw dependant perameters */
96 int (*set_hw_params)(struct iwl_priv *priv); 104 int (*set_hw_params)(struct iwl_priv *priv);
97 105 /* ucode shared memory */
106 int (*alloc_shared_mem)(struct iwl_priv *priv);
107 void (*free_shared_mem)(struct iwl_priv *priv);
108 int (*shared_mem_rx_idx)(struct iwl_priv *priv);
109 /* Handling TX */
98 void (*txq_update_byte_cnt_tbl)(struct iwl_priv *priv, 110 void (*txq_update_byte_cnt_tbl)(struct iwl_priv *priv,
99 struct iwl4965_tx_queue *txq, 111 struct iwl_tx_queue *txq,
100 u16 byte_cnt); 112 u16 byte_cnt);
101 /* nic init */ 113 void (*txq_inval_byte_cnt_tbl)(struct iwl_priv *priv,
102 int (*hw_nic_init)(struct iwl_priv *priv); 114 struct iwl_tx_queue *txq);
115 void (*txq_set_sched)(struct iwl_priv *priv, u32 mask);
116 /* aggregations */
117 int (*txq_agg_enable)(struct iwl_priv *priv, int txq_id, int tx_fifo,
118 int sta_id, int tid, u16 ssn_idx);
119 int (*txq_agg_disable)(struct iwl_priv *priv, u16 txq_id, u16 ssn_idx,
120 u8 tx_fifo);
121 /* setup Rx handler */
122 void (*rx_handler_setup)(struct iwl_priv *priv);
123 /* setup deferred work */
124 void (*setup_deferred_work)(struct iwl_priv *priv);
125 /* cancel deferred work */
126 void (*cancel_deferred_work)(struct iwl_priv *priv);
127 /* alive notification after init uCode load */
128 void (*init_alive_start)(struct iwl_priv *priv);
103 /* alive notification */ 129 /* alive notification */
104 int (*alive_notify)(struct iwl_priv *priv); 130 int (*alive_notify)(struct iwl_priv *priv);
105 /* check validity of rtc data address */ 131 /* check validity of rtc data address */
106 int (*is_valid_rtc_data_addr)(u32 addr); 132 int (*is_valid_rtc_data_addr)(u32 addr);
107 /* 1st ucode load */ 133 /* 1st ucode load */
108 int (*load_ucode)(struct iwl_priv *priv); 134 int (*load_ucode)(struct iwl_priv *priv);
109 /* rfkill */ 135 /* power management */
110 void (*radio_kill_sw)(struct iwl_priv *priv, int disable_radio); 136 struct {
137 int (*init)(struct iwl_priv *priv);
138 int (*reset)(struct iwl_priv *priv);
139 void (*stop)(struct iwl_priv *priv);
140 void (*config)(struct iwl_priv *priv);
141 int (*set_pwr_src)(struct iwl_priv *priv, enum iwl_pwr_src src);
142 } apm_ops;
143 /* power */
144 int (*send_tx_power) (struct iwl_priv *priv);
145 void (*update_chain_flags)(struct iwl_priv *priv);
146 void (*temperature) (struct iwl_priv *priv);
111 /* eeprom operations (as defined in iwl-eeprom.h) */ 147 /* eeprom operations (as defined in iwl-eeprom.h) */
112 struct iwl_eeprom_ops eeprom_ops; 148 struct iwl_eeprom_ops eeprom_ops;
113}; 149};
@@ -124,15 +160,19 @@ struct iwl_mod_params {
124 int debug; /* def: 0 = minimal debug log messages */ 160 int debug; /* def: 0 = minimal debug log messages */
125 int disable_hw_scan; /* def: 0 = use h/w scan */ 161 int disable_hw_scan; /* def: 0 = use h/w scan */
126 int num_of_queues; /* def: HW dependent */ 162 int num_of_queues; /* def: HW dependent */
163 int num_of_ampdu_queues;/* def: HW dependent */
127 int enable_qos; /* def: 1 = use quality of service */ 164 int enable_qos; /* def: 1 = use quality of service */
165 int disable_11n; /* def: 0 = disable 11n capabilities */
128 int amsdu_size_8K; /* def: 1 = enable 8K amsdu size */ 166 int amsdu_size_8K; /* def: 1 = enable 8K amsdu size */
129 int antenna; /* def: 0 = both antennas (use diversity) */ 167 int antenna; /* def: 0 = both antennas (use diversity) */
168 int restart_fw; /* def: 1 = restart firmware */
130}; 169};
131 170
132struct iwl_cfg { 171struct iwl_cfg {
133 const char *name; 172 const char *name;
134 const char *fw_name; 173 const char *fw_name;
135 unsigned int sku; 174 unsigned int sku;
175 int eeprom_size;
136 const struct iwl_ops *ops; 176 const struct iwl_ops *ops;
137 const struct iwl_mod_params *mod_params; 177 const struct iwl_mod_params *mod_params;
138}; 178};
@@ -143,14 +183,111 @@ struct iwl_cfg {
143 183
144struct ieee80211_hw *iwl_alloc_all(struct iwl_cfg *cfg, 184struct ieee80211_hw *iwl_alloc_all(struct iwl_cfg *cfg,
145 struct ieee80211_ops *hw_ops); 185 struct ieee80211_ops *hw_ops);
186void iwl_hw_detect(struct iwl_priv *priv);
187void iwl_clear_stations_table(struct iwl_priv *priv);
188void iwl_reset_qos(struct iwl_priv *priv);
189void iwl_set_rxon_chain(struct iwl_priv *priv);
190int iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch);
191void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_info *ht_info);
192u8 iwl_is_fat_tx_allowed(struct iwl_priv *priv,
193 struct ieee80211_ht_info *sta_ht_inf);
194int iwl_hw_nic_init(struct iwl_priv *priv);
195int iwl_setup_mac(struct iwl_priv *priv);
196int iwl_set_hw_params(struct iwl_priv *priv);
197int iwl_init_drv(struct iwl_priv *priv);
198void iwl_uninit_drv(struct iwl_priv *priv);
199/* "keep warm" functions */
200int iwl_kw_init(struct iwl_priv *priv);
201int iwl_kw_alloc(struct iwl_priv *priv);
202void iwl_kw_free(struct iwl_priv *priv);
203
204/*****************************************************
205* RX
206******************************************************/
207void iwl_rx_queue_free(struct iwl_priv *priv, struct iwl_rx_queue *rxq);
208int iwl_rx_queue_alloc(struct iwl_priv *priv);
209void iwl_rx_handle(struct iwl_priv *priv);
210int iwl_rx_queue_update_write_ptr(struct iwl_priv *priv,
211 struct iwl_rx_queue *q);
212void iwl_rx_queue_reset(struct iwl_priv *priv, struct iwl_rx_queue *rxq);
213void iwl_rx_replenish(struct iwl_priv *priv);
214int iwl_rx_init(struct iwl_priv *priv, struct iwl_rx_queue *rxq);
215int iwl_rx_agg_start(struct iwl_priv *priv, const u8 *addr, int tid, u16 ssn);
216int iwl_rx_agg_stop(struct iwl_priv *priv, const u8 *addr, int tid);
217int iwl_rx_queue_restock(struct iwl_priv *priv);
218int iwl_rx_queue_space(const struct iwl_rx_queue *q);
219void iwl_rx_allocate(struct iwl_priv *priv);
220void iwl_tx_cmd_complete(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb);
221int iwl_tx_queue_reclaim(struct iwl_priv *priv, int txq_id, int index);
222/* Handlers */
223void iwl_rx_missed_beacon_notif(struct iwl_priv *priv,
224 struct iwl_rx_mem_buffer *rxb);
225void iwl_rx_statistics(struct iwl_priv *priv,
226 struct iwl_rx_mem_buffer *rxb);
227
228/* TX helpers */
146 229
147void iwlcore_clear_stations_table(struct iwl_priv *priv); 230/*****************************************************
148void iwlcore_reset_qos(struct iwl_priv *priv); 231* TX
149int iwlcore_set_rxon_channel(struct iwl_priv *priv, 232******************************************************/
150 enum ieee80211_band band, 233int iwl_txq_ctx_reset(struct iwl_priv *priv);
151 u16 channel); 234int iwl_tx_skb(struct iwl_priv *priv, struct sk_buff *skb);
235void iwl_hw_txq_ctx_free(struct iwl_priv *priv);
236int iwl_txq_update_write_ptr(struct iwl_priv *priv, struct iwl_tx_queue *txq);
237int iwl_tx_agg_start(struct iwl_priv *priv, const u8 *ra, u16 tid, u16 *ssn);
238int iwl_tx_agg_stop(struct iwl_priv *priv , const u8 *ra, u16 tid);
239int iwl_txq_check_empty(struct iwl_priv *priv, int sta_id, u8 tid, int txq_id);
152 240
153int iwl_setup(struct iwl_priv *priv); 241/*****************************************************
242 * TX power
243 ****************************************************/
244int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force);
245
246/*****************************************************
247 * RF -Kill - here and not in iwl-rfkill.h to be available when
248 * RF-kill subsystem is not compiled.
249 ****************************************************/
250void iwl_rf_kill(struct iwl_priv *priv);
251void iwl_radio_kill_sw_disable_radio(struct iwl_priv *priv);
252int iwl_radio_kill_sw_enable_radio(struct iwl_priv *priv);
253
254/*******************************************************************************
255 * Rate
256 ******************************************************************************/
257
258void iwl_hwrate_to_tx_control(struct iwl_priv *priv, u32 rate_n_flags,
259 struct ieee80211_tx_info *info);
260int iwl_hwrate_to_plcp_idx(u32 rate_n_flags);
261
262static inline u8 iwl_hw_get_rate(__le32 rate_n_flags)
263{
264 return le32_to_cpu(rate_n_flags) & 0xFF;
265}
266static inline u32 iwl_hw_get_rate_n_flags(__le32 rate_n_flags)
267{
268 return le32_to_cpu(rate_n_flags) & 0x1FFFF;
269}
270static inline __le32 iwl_hw_set_rate_n_flags(u8 rate, u32 flags)
271{
272 return cpu_to_le32(flags|(u32)rate);
273}
274
275/*******************************************************************************
276 * Scanning
277 ******************************************************************************/
278void iwl_init_scan_params(struct iwl_priv *priv);
279int iwl_scan_cancel(struct iwl_priv *priv);
280int iwl_scan_cancel_timeout(struct iwl_priv *priv, unsigned long ms);
281int iwl_scan_initiate(struct iwl_priv *priv);
282void iwl_setup_rx_scan_handlers(struct iwl_priv *priv);
283void iwl_setup_scan_deferred_work(struct iwl_priv *priv);
284
285/*******************************************************************************
286 * Calibrations - implemented in iwl-calib.c
287 ******************************************************************************/
288int iwl_send_calib_results(struct iwl_priv *priv);
289int iwl_calib_set(struct iwl_calib_result *res, const u8 *buf, int len);
290void iwl_calib_free_results(struct iwl_priv *priv);
154 291
155/***************************************************** 292/*****************************************************
156 * S e n d i n g H o s t C o m m a n d s * 293 * S e n d i n g H o s t C o m m a n d s *
@@ -167,6 +304,15 @@ int iwl_send_cmd_pdu_async(struct iwl_priv *priv, u8 id, u16 len,
167 int (*callback)(struct iwl_priv *priv, 304 int (*callback)(struct iwl_priv *priv,
168 struct iwl_cmd *cmd, 305 struct iwl_cmd *cmd,
169 struct sk_buff *skb)); 306 struct sk_buff *skb));
307
308int iwl_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd);
309
310/*****************************************************
311* Error Handling Debugging
312******************************************************/
313void iwl_dump_nic_error_log(struct iwl_priv *priv);
314void iwl_dump_nic_event_log(struct iwl_priv *priv);
315
170/*************** DRIVER STATUS FUNCTIONS *****/ 316/*************** DRIVER STATUS FUNCTIONS *****/
171 317
172#define STATUS_HCMD_ACTIVE 0 /* host command in progress */ 318#define STATUS_HCMD_ACTIVE 0 /* host command in progress */
@@ -187,7 +333,7 @@ int iwl_send_cmd_pdu_async(struct iwl_priv *priv, u8 id, u16 len,
187#define STATUS_SCAN_HW 15 333#define STATUS_SCAN_HW 15
188#define STATUS_POWER_PMI 16 334#define STATUS_POWER_PMI 16
189#define STATUS_FW_ERROR 17 335#define STATUS_FW_ERROR 17
190#define STATUS_CONF_PENDING 18 336#define STATUS_MODE_PENDING 18
191 337
192 338
193static inline int iwl_is_ready(struct iwl_priv *priv) 339static inline int iwl_is_ready(struct iwl_priv *priv)
@@ -209,10 +355,19 @@ static inline int iwl_is_init(struct iwl_priv *priv)
209 return test_bit(STATUS_INIT, &priv->status); 355 return test_bit(STATUS_INIT, &priv->status);
210} 356}
211 357
358static inline int iwl_is_rfkill_sw(struct iwl_priv *priv)
359{
360 return test_bit(STATUS_RF_KILL_SW, &priv->status);
361}
362
363static inline int iwl_is_rfkill_hw(struct iwl_priv *priv)
364{
365 return test_bit(STATUS_RF_KILL_HW, &priv->status);
366}
367
212static inline int iwl_is_rfkill(struct iwl_priv *priv) 368static inline int iwl_is_rfkill(struct iwl_priv *priv)
213{ 369{
214 return test_bit(STATUS_RF_KILL_HW, &priv->status) || 370 return iwl_is_rfkill_hw(priv) || iwl_is_rfkill_sw(priv);
215 test_bit(STATUS_RF_KILL_SW, &priv->status);
216} 371}
217 372
218static inline int iwl_is_ready_rf(struct iwl_priv *priv) 373static inline int iwl_is_ready_rf(struct iwl_priv *priv)
@@ -224,23 +379,27 @@ static inline int iwl_is_ready_rf(struct iwl_priv *priv)
224 return iwl_is_ready(priv); 379 return iwl_is_ready(priv);
225} 380}
226 381
227 382extern void iwl_rf_kill_ct_config(struct iwl_priv *priv);
228enum iwlcore_card_notify {
229 IWLCORE_INIT_EVT = 0,
230 IWLCORE_START_EVT = 1,
231 IWLCORE_STOP_EVT = 2,
232 IWLCORE_REMOVE_EVT = 3,
233};
234
235int iwlcore_low_level_notify(struct iwl_priv *priv,
236 enum iwlcore_card_notify notify);
237extern int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags); 383extern int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags);
238int iwl_send_lq_cmd(struct iwl_priv *priv, 384extern int iwl_verify_ucode(struct iwl_priv *priv);
239 struct iwl_link_quality_cmd *lq, u8 flags); 385extern int iwl_send_lq_cmd(struct iwl_priv *priv,
386 struct iwl_link_quality_cmd *lq, u8 flags);
387extern void iwl_rx_reply_rx(struct iwl_priv *priv,
388 struct iwl_rx_mem_buffer *rxb);
389extern void iwl_rx_reply_rx_phy(struct iwl_priv *priv,
390 struct iwl_rx_mem_buffer *rxb);
391void iwl_rx_reply_compressed_ba(struct iwl_priv *priv,
392 struct iwl_rx_mem_buffer *rxb);
240 393
241static inline int iwl_send_rxon_assoc(struct iwl_priv *priv) 394static inline int iwl_send_rxon_assoc(struct iwl_priv *priv)
242{ 395{
243 return priv->cfg->ops->hcmd->rxon_assoc(priv); 396 return priv->cfg->ops->hcmd->rxon_assoc(priv);
244} 397}
245 398
399static inline const struct ieee80211_supported_band *iwl_get_hw_mode(
400 struct iwl_priv *priv, enum ieee80211_band band)
401{
402 return priv->hw->wiphy->bands[band];
403}
404
246#endif /* __iwl_core_h__ */ 405#endif /* __iwl_core_h__ */
diff --git a/drivers/net/wireless/iwlwifi/iwl-csr.h b/drivers/net/wireless/iwlwifi/iwl-csr.h
index 12725796ea5f..662edf4f8d22 100644
--- a/drivers/net/wireless/iwlwifi/iwl-csr.h
+++ b/drivers/net/wireless/iwlwifi/iwl-csr.h
@@ -64,7 +64,7 @@
64#define CSR_BASE (0x000) 64#define CSR_BASE (0x000)
65 65
66#define CSR_HW_IF_CONFIG_REG (CSR_BASE+0x000) /* hardware interface config */ 66#define CSR_HW_IF_CONFIG_REG (CSR_BASE+0x000) /* hardware interface config */
67#define CSR_INT_COALESCING (CSR_BASE+0x004) /* accum ints, 32-usec units */ 67#define CSR_INT_COALESCING (CSR_BASE+0x004) /* accum ints, 32-usec units */
68#define CSR_INT (CSR_BASE+0x008) /* host interrupt status/ack */ 68#define CSR_INT (CSR_BASE+0x008) /* host interrupt status/ack */
69#define CSR_INT_MASK (CSR_BASE+0x00c) /* host interrupt enable */ 69#define CSR_INT_MASK (CSR_BASE+0x00c) /* host interrupt enable */
70#define CSR_FH_INT_STATUS (CSR_BASE+0x010) /* busmaster int status/ack*/ 70#define CSR_FH_INT_STATUS (CSR_BASE+0x010) /* busmaster int status/ack*/
@@ -87,16 +87,16 @@
87/* EEPROM reads */ 87/* EEPROM reads */
88#define CSR_EEPROM_REG (CSR_BASE+0x02c) 88#define CSR_EEPROM_REG (CSR_BASE+0x02c)
89#define CSR_EEPROM_GP (CSR_BASE+0x030) 89#define CSR_EEPROM_GP (CSR_BASE+0x030)
90#define CSR_GIO_REG (CSR_BASE+0x03C)
90#define CSR_GP_UCODE (CSR_BASE+0x044) 91#define CSR_GP_UCODE (CSR_BASE+0x044)
91#define CSR_UCODE_DRV_GP1 (CSR_BASE+0x054) 92#define CSR_UCODE_DRV_GP1 (CSR_BASE+0x054)
92#define CSR_UCODE_DRV_GP1_SET (CSR_BASE+0x058) 93#define CSR_UCODE_DRV_GP1_SET (CSR_BASE+0x058)
93#define CSR_UCODE_DRV_GP1_CLR (CSR_BASE+0x05c) 94#define CSR_UCODE_DRV_GP1_CLR (CSR_BASE+0x05c)
94#define CSR_UCODE_DRV_GP2 (CSR_BASE+0x060) 95#define CSR_UCODE_DRV_GP2 (CSR_BASE+0x060)
95#define CSR_GIO_CHICKEN_BITS (CSR_BASE+0x100)
96#define CSR_LED_REG (CSR_BASE+0x094) 96#define CSR_LED_REG (CSR_BASE+0x094)
97#define CSR_GIO_CHICKEN_BITS (CSR_BASE+0x100)
97 98
98/* Analog phase-lock-loop configuration (3945 only) 99/* Analog phase-lock-loop configuration */
99 * Set bit 24. */
100#define CSR_ANA_PLL_CFG (CSR_BASE+0x20c) 100#define CSR_ANA_PLL_CFG (CSR_BASE+0x20c)
101/* 101/*
102 * Indicates hardware rev, to determine CCK backoff for txpower calculation. 102 * Indicates hardware rev, to determine CCK backoff for txpower calculation.
@@ -104,12 +104,13 @@
104 * 3-2: 0 = A, 1 = B, 2 = C, 3 = D step 104 * 3-2: 0 = A, 1 = B, 2 = C, 3 = D step
105 */ 105 */
106#define CSR_HW_REV_WA_REG (CSR_BASE+0x22C) 106#define CSR_HW_REV_WA_REG (CSR_BASE+0x22C)
107#define CSR_DBG_HPET_MEM_REG (CSR_BASE+0x240)
107 108
108/* Bits for CSR_HW_IF_CONFIG_REG */ 109/* Bits for CSR_HW_IF_CONFIG_REG */
109#define CSR49_HW_IF_CONFIG_REG_BIT_4965_R (0x00000010) 110#define CSR49_HW_IF_CONFIG_REG_BIT_4965_R (0x00000010)
110#define CSR49_HW_IF_CONFIG_REG_MSK_BOARD_VER (0x00000C00) 111#define CSR_HW_IF_CONFIG_REG_MSK_BOARD_VER (0x00000C00)
111#define CSR49_HW_IF_CONFIG_REG_BIT_MAC_SI (0x00000100) 112#define CSR_HW_IF_CONFIG_REG_BIT_MAC_SI (0x00000100)
112#define CSR49_HW_IF_CONFIG_REG_BIT_RADIO_SI (0x00000200) 113#define CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI (0x00000200)
113 114
114#define CSR39_HW_IF_CONFIG_REG_BIT_3945_MB (0x00000100) 115#define CSR39_HW_IF_CONFIG_REG_BIT_3945_MB (0x00000100)
115#define CSR39_HW_IF_CONFIG_REG_BIT_3945_MM (0x00000200) 116#define CSR39_HW_IF_CONFIG_REG_BIT_3945_MM (0x00000200)
@@ -118,7 +119,12 @@
118#define CSR39_HW_IF_CONFIG_REG_BITS_SILICON_TYPE_A (0x00000000) 119#define CSR39_HW_IF_CONFIG_REG_BITS_SILICON_TYPE_A (0x00000000)
119#define CSR39_HW_IF_CONFIG_REG_BITS_SILICON_TYPE_B (0x00001000) 120#define CSR39_HW_IF_CONFIG_REG_BITS_SILICON_TYPE_B (0x00001000)
120 121
121#define CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM (0x00200000) 122#define CSR_HW_IF_CONFIG_REG_BIT_HAP_WAKE_L1A (0x00080000)
123#define CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM (0x00200000)
124#define CSR_HW_IF_CONFIG_REG_BIT_PCI_OWN_SEM (0x00400000)
125#define CSR_HW_IF_CONFIG_REG_BIT_ME_OWN (0x02000000)
126#define CSR_HW_IF_CONFIG_REG_BIT_WAKE_ME (0x08000000)
127
122 128
123/* interrupt flags in INTA, set by uCode or hardware (e.g. dma), 129/* interrupt flags in INTA, set by uCode or hardware (e.g. dma),
124 * acknowledged (reset) by host writing "1" to flagged bits. */ 130 * acknowledged (reset) by host writing "1" to flagged bits. */
@@ -170,6 +176,10 @@
170#define CSR49_FH_INT_TX_MASK (CSR_FH_INT_BIT_TX_CHNL1 | \ 176#define CSR49_FH_INT_TX_MASK (CSR_FH_INT_BIT_TX_CHNL1 | \
171 CSR_FH_INT_BIT_TX_CHNL0) 177 CSR_FH_INT_BIT_TX_CHNL0)
172 178
179/* GPIO */
180#define CSR_GPIO_IN_BIT_AUX_POWER (0x00000200)
181#define CSR_GPIO_IN_VAL_VAUX_PWR_SRC (0x00000000)
182#define CSR_GPIO_IN_VAL_VMAIN_PWR_SRC (0x00000200)
173 183
174/* RESET */ 184/* RESET */
175#define CSR_RESET_REG_FLAG_NEVO_RESET (0x00000001) 185#define CSR_RESET_REG_FLAG_NEVO_RESET (0x00000001)
@@ -191,6 +201,16 @@
191#define CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW (0x08000000) 201#define CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW (0x08000000)
192 202
193 203
204/* HW REV */
205#define CSR_HW_REV_TYPE_MSK (0x00000F0)
206#define CSR_HW_REV_TYPE_3945 (0x00000D0)
207#define CSR_HW_REV_TYPE_4965 (0x0000000)
208#define CSR_HW_REV_TYPE_5300 (0x0000020)
209#define CSR_HW_REV_TYPE_5350 (0x0000030)
210#define CSR_HW_REV_TYPE_5100 (0x0000050)
211#define CSR_HW_REV_TYPE_5150 (0x0000040)
212#define CSR_HW_REV_TYPE_NONE (0x00000F0)
213
194/* EEPROM REG */ 214/* EEPROM REG */
195#define CSR_EEPROM_REG_READ_VALID_MSK (0x00000001) 215#define CSR_EEPROM_REG_READ_VALID_MSK (0x00000001)
196#define CSR_EEPROM_REG_BIT_CMD (0x00000002) 216#define CSR_EEPROM_REG_BIT_CMD (0x00000002)
@@ -200,17 +220,15 @@
200#define CSR_EEPROM_GP_BAD_SIGNATURE (0x00000000) 220#define CSR_EEPROM_GP_BAD_SIGNATURE (0x00000000)
201#define CSR_EEPROM_GP_IF_OWNER_MSK (0x00000180) 221#define CSR_EEPROM_GP_IF_OWNER_MSK (0x00000180)
202 222
223/* CSR GIO */
224#define CSR_GIO_REG_VAL_L0S_ENABLED (0x00000002)
225
203/* UCODE DRV GP */ 226/* UCODE DRV GP */
204#define CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP (0x00000001) 227#define CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP (0x00000001)
205#define CSR_UCODE_SW_BIT_RFKILL (0x00000002) 228#define CSR_UCODE_SW_BIT_RFKILL (0x00000002)
206#define CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED (0x00000004) 229#define CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED (0x00000004)
207#define CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT (0x00000008) 230#define CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT (0x00000008)
208 231
209/* GPIO */
210#define CSR_GPIO_IN_BIT_AUX_POWER (0x00000200)
211#define CSR_GPIO_IN_VAL_VAUX_PWR_SRC (0x00000000)
212#define CSR_GPIO_IN_VAL_VMAIN_PWR_SRC CSR_GPIO_IN_BIT_AUX_POWER
213
214/* GI Chicken Bits */ 232/* GI Chicken Bits */
215#define CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX (0x00800000) 233#define CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX (0x00800000)
216#define CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER (0x20000000) 234#define CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER (0x20000000)
@@ -220,6 +238,12 @@
220#define CSR_LED_REG_TRUN_ON (0x78) 238#define CSR_LED_REG_TRUN_ON (0x78)
221#define CSR_LED_REG_TRUN_OFF (0x38) 239#define CSR_LED_REG_TRUN_OFF (0x38)
222 240
241/* ANA_PLL */
242#define CSR39_ANA_PLL_CFG_VAL (0x01000000)
243#define CSR50_ANA_PLL_CFG_VAL (0x00880300)
244
245/* HPET MEM debug */
246#define CSR_DBG_HPET_MEM_REG_VAL (0xFFFF0000)
223/*=== HBUS (Host-side Bus) ===*/ 247/*=== HBUS (Host-side Bus) ===*/
224#define HBUS_BASE (0x400) 248#define HBUS_BASE (0x400)
225/* 249/*
diff --git a/drivers/net/wireless/iwlwifi/iwl-debug.h b/drivers/net/wireless/iwlwifi/iwl-debug.h
index c60724c21db8..e548d67f87fd 100644
--- a/drivers/net/wireless/iwlwifi/iwl-debug.h
+++ b/drivers/net/wireless/iwlwifi/iwl-debug.h
@@ -30,37 +30,35 @@
30#define __iwl_debug_h__ 30#define __iwl_debug_h__
31 31
32#ifdef CONFIG_IWLWIFI_DEBUG 32#ifdef CONFIG_IWLWIFI_DEBUG
33extern u32 iwl_debug_level;
34#define IWL_DEBUG(level, fmt, args...) \ 33#define IWL_DEBUG(level, fmt, args...) \
35do { if (iwl_debug_level & (level)) \ 34do { if (priv->debug_level & (level)) \
36 printk(KERN_ERR DRV_NAME": %c %s " fmt, \ 35 dev_printk(KERN_ERR, &(priv->hw->wiphy->dev), "%c %s " fmt, \
37 in_interrupt() ? 'I' : 'U', __FUNCTION__ , ## args); } while (0) 36 in_interrupt() ? 'I' : 'U', __func__ , ## args); } while (0)
38 37
39#define IWL_DEBUG_LIMIT(level, fmt, args...) \ 38#define IWL_DEBUG_LIMIT(level, fmt, args...) \
40do { if ((iwl_debug_level & (level)) && net_ratelimit()) \ 39do { if ((priv->debug_level & (level)) && net_ratelimit()) \
41 printk(KERN_ERR DRV_NAME": %c %s " fmt, \ 40 dev_printk(KERN_ERR, &(priv->hw->wiphy->dev), "%c %s " fmt, \
42 in_interrupt() ? 'I' : 'U', __FUNCTION__ , ## args); } while (0) 41 in_interrupt() ? 'I' : 'U', __func__ , ## args); } while (0)
43
44static inline void iwl_print_hex_dump(int level, void *p, u32 len)
45{
46 if (!(iwl_debug_level & level))
47 return;
48
49 print_hex_dump(KERN_DEBUG, "iwl data: ", DUMP_PREFIX_OFFSET, 16, 1,
50 p, len, 1);
51}
52 42
53#ifdef CONFIG_IWLWIFI_DEBUGFS 43#ifdef CONFIG_IWLWIFI_DEBUGFS
54struct iwl_debugfs { 44struct iwl_debugfs {
55 const char *name; 45 const char *name;
56 struct dentry *dir_drv; 46 struct dentry *dir_drv;
57 struct dentry *dir_data; 47 struct dentry *dir_data;
58 struct dir_data_files{ 48 struct dentry *dir_rf;
49 struct dir_data_files {
59 struct dentry *file_sram; 50 struct dentry *file_sram;
51 struct dentry *file_eeprom;
60 struct dentry *file_stations; 52 struct dentry *file_stations;
61 struct dentry *file_rx_statistics; 53 struct dentry *file_rx_statistics;
62 struct dentry *file_tx_statistics; 54 struct dentry *file_tx_statistics;
55 struct dentry *file_log_event;
63 } dbgfs_data_files; 56 } dbgfs_data_files;
57 struct dir_rf_files {
58 struct dentry *file_disable_sensitivity;
59 struct dentry *file_disable_chain_noise;
60 struct dentry *file_disable_tx_power;
61 } dbgfs_rf_files;
64 u32 sram_offset; 62 u32 sram_offset;
65 u32 sram_len; 63 u32 sram_len;
66}; 64};
@@ -70,15 +68,8 @@ void iwl_dbgfs_unregister(struct iwl_priv *priv);
70#endif 68#endif
71 69
72#else 70#else
73static inline void IWL_DEBUG(int level, const char *fmt, ...) 71#define IWL_DEBUG(level, fmt, args...)
74{ 72#define IWL_DEBUG_LIMIT(level, fmt, args...)
75}
76static inline void IWL_DEBUG_LIMIT(int level, const char *fmt, ...)
77{
78}
79static inline void iwl_print_hex_dump(int level, void *p, u32 len)
80{
81}
82#endif /* CONFIG_IWLWIFI_DEBUG */ 73#endif /* CONFIG_IWLWIFI_DEBUG */
83 74
84 75
@@ -119,11 +110,12 @@ static inline void iwl_dbgfs_unregister(struct iwl_priv *priv)
119 * 110 *
120 */ 111 */
121 112
122#define IWL_DL_INFO (1 << 0) 113#define IWL_DL_INFO (1 << 0)
123#define IWL_DL_MAC80211 (1 << 1) 114#define IWL_DL_MAC80211 (1 << 1)
124#define IWL_DL_HOST_COMMAND (1 << 2) 115#define IWL_DL_HCMD (1 << 2)
125#define IWL_DL_STATE (1 << 3) 116#define IWL_DL_STATE (1 << 3)
126 117#define IWL_DL_MACDUMP (1 << 4)
118#define IWL_DL_HCMD_DUMP (1 << 5)
127#define IWL_DL_RADIO (1 << 7) 119#define IWL_DL_RADIO (1 << 7)
128#define IWL_DL_POWER (1 << 8) 120#define IWL_DL_POWER (1 << 8)
129#define IWL_DL_TEMP (1 << 9) 121#define IWL_DL_TEMP (1 << 9)
@@ -163,6 +155,7 @@ static inline void iwl_dbgfs_unregister(struct iwl_priv *priv)
163#define IWL_DEBUG_INFO(f, a...) IWL_DEBUG(IWL_DL_INFO, f, ## a) 155#define IWL_DEBUG_INFO(f, a...) IWL_DEBUG(IWL_DL_INFO, f, ## a)
164 156
165#define IWL_DEBUG_MAC80211(f, a...) IWL_DEBUG(IWL_DL_MAC80211, f, ## a) 157#define IWL_DEBUG_MAC80211(f, a...) IWL_DEBUG(IWL_DL_MAC80211, f, ## a)
158#define IWL_DEBUG_MACDUMP(f, a...) IWL_DEBUG(IWL_DL_MACDUMP, f, ## a)
166#define IWL_DEBUG_TEMP(f, a...) IWL_DEBUG(IWL_DL_TEMP, f, ## a) 159#define IWL_DEBUG_TEMP(f, a...) IWL_DEBUG(IWL_DL_TEMP, f, ## a)
167#define IWL_DEBUG_SCAN(f, a...) IWL_DEBUG(IWL_DL_SCAN, f, ## a) 160#define IWL_DEBUG_SCAN(f, a...) IWL_DEBUG(IWL_DL_SCAN, f, ## a)
168#define IWL_DEBUG_RX(f, a...) IWL_DEBUG(IWL_DL_RX, f, ## a) 161#define IWL_DEBUG_RX(f, a...) IWL_DEBUG(IWL_DL_RX, f, ## a)
@@ -170,7 +163,8 @@ static inline void iwl_dbgfs_unregister(struct iwl_priv *priv)
170#define IWL_DEBUG_ISR(f, a...) IWL_DEBUG(IWL_DL_ISR, f, ## a) 163#define IWL_DEBUG_ISR(f, a...) IWL_DEBUG(IWL_DL_ISR, f, ## a)
171#define IWL_DEBUG_LED(f, a...) IWL_DEBUG(IWL_DL_LED, f, ## a) 164#define IWL_DEBUG_LED(f, a...) IWL_DEBUG(IWL_DL_LED, f, ## a)
172#define IWL_DEBUG_WEP(f, a...) IWL_DEBUG(IWL_DL_WEP, f, ## a) 165#define IWL_DEBUG_WEP(f, a...) IWL_DEBUG(IWL_DL_WEP, f, ## a)
173#define IWL_DEBUG_HC(f, a...) IWL_DEBUG(IWL_DL_HOST_COMMAND, f, ## a) 166#define IWL_DEBUG_HC(f, a...) IWL_DEBUG(IWL_DL_HCMD, f, ## a)
167#define IWL_DEBUG_HC_DUMP(f, a...) IWL_DEBUG(IWL_DL_HCMD_DUMP, f, ## a)
174#define IWL_DEBUG_CALIB(f, a...) IWL_DEBUG(IWL_DL_CALIB, f, ## a) 168#define IWL_DEBUG_CALIB(f, a...) IWL_DEBUG(IWL_DL_CALIB, f, ## a)
175#define IWL_DEBUG_FW(f, a...) IWL_DEBUG(IWL_DL_FW, f, ## a) 169#define IWL_DEBUG_FW(f, a...) IWL_DEBUG(IWL_DL_FW, f, ## a)
176#define IWL_DEBUG_RF_KILL(f, a...) IWL_DEBUG(IWL_DL_RF_KILL, f, ## a) 170#define IWL_DEBUG_RF_KILL(f, a...) IWL_DEBUG(IWL_DL_RF_KILL, f, ## a)
diff --git a/drivers/net/wireless/iwlwifi/iwl-debugfs.c b/drivers/net/wireless/iwlwifi/iwl-debugfs.c
index 9a30e1df311d..20db0eb636a8 100644
--- a/drivers/net/wireless/iwlwifi/iwl-debugfs.c
+++ b/drivers/net/wireless/iwlwifi/iwl-debugfs.c
@@ -34,7 +34,7 @@
34#include <net/mac80211.h> 34#include <net/mac80211.h>
35 35
36 36
37#include "iwl-4965.h" 37#include "iwl-dev.h"
38#include "iwl-debug.h" 38#include "iwl-debug.h"
39#include "iwl-core.h" 39#include "iwl-core.h"
40#include "iwl-io.h" 40#include "iwl-io.h"
@@ -55,6 +55,13 @@
55 goto err; \ 55 goto err; \
56} while (0) 56} while (0)
57 57
58#define DEBUGFS_ADD_BOOL(name, parent, ptr) do { \
59 dbgfs->dbgfs_##parent##_files.file_##name = \
60 debugfs_create_bool(#name, 0644, dbgfs->dir_##parent, ptr); \
61 if (IS_ERR(dbgfs->dbgfs_##parent##_files.file_##name)) \
62 goto err; \
63} while (0)
64
58#define DEBUGFS_REMOVE(name) do { \ 65#define DEBUGFS_REMOVE(name) do { \
59 debugfs_remove(name); \ 66 debugfs_remove(name); \
60 name = NULL; \ 67 name = NULL; \
@@ -85,6 +92,14 @@ static const struct file_operations iwl_dbgfs_##name##_ops = { \
85 .open = iwl_dbgfs_open_file_generic, \ 92 .open = iwl_dbgfs_open_file_generic, \
86}; 93};
87 94
95#define DEBUGFS_WRITE_FILE_OPS(name) \
96 DEBUGFS_WRITE_FUNC(name); \
97static const struct file_operations iwl_dbgfs_##name##_ops = { \
98 .write = iwl_dbgfs_##name##_write, \
99 .open = iwl_dbgfs_open_file_generic, \
100};
101
102
88#define DEBUGFS_READ_WRITE_FILE_OPS(name) \ 103#define DEBUGFS_READ_WRITE_FILE_OPS(name) \
89 DEBUGFS_READ_FUNC(name); \ 104 DEBUGFS_READ_FUNC(name); \
90 DEBUGFS_WRITE_FUNC(name); \ 105 DEBUGFS_WRITE_FUNC(name); \
@@ -206,7 +221,7 @@ static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
206 size_t count, loff_t *ppos) 221 size_t count, loff_t *ppos)
207{ 222{
208 struct iwl_priv *priv = (struct iwl_priv *)file->private_data; 223 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
209 struct iwl4965_station_entry *station; 224 struct iwl_station_entry *station;
210 int max_sta = priv->hw_params.max_stations; 225 int max_sta = priv->hw_params.max_stations;
211 char *buf; 226 char *buf;
212 int i, j, pos = 0; 227 int i, j, pos = 0;
@@ -216,7 +231,7 @@ static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
216 DECLARE_MAC_BUF(mac); 231 DECLARE_MAC_BUF(mac);
217 232
218 buf = kmalloc(bufsz, GFP_KERNEL); 233 buf = kmalloc(bufsz, GFP_KERNEL);
219 if(!buf) 234 if (!buf)
220 return -ENOMEM; 235 return -ENOMEM;
221 236
222 pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n", 237 pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
@@ -240,21 +255,18 @@ static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
240 pos += scnprintf(buf + pos, bufsz - pos, "tid data:\n"); 255 pos += scnprintf(buf + pos, bufsz - pos, "tid data:\n");
241 pos += scnprintf(buf + pos, bufsz - pos, 256 pos += scnprintf(buf + pos, bufsz - pos,
242 "seq_num\t\ttxq_id"); 257 "seq_num\t\ttxq_id");
243#ifdef CONFIG_IWL4965_HT
244 pos += scnprintf(buf + pos, bufsz - pos, 258 pos += scnprintf(buf + pos, bufsz - pos,
245 "\tframe_count\twait_for_ba\t"); 259 "\tframe_count\twait_for_ba\t");
246 pos += scnprintf(buf + pos, bufsz - pos, 260 pos += scnprintf(buf + pos, bufsz - pos,
247 "start_idx\tbitmap0\t"); 261 "start_idx\tbitmap0\t");
248 pos += scnprintf(buf + pos, bufsz - pos, 262 pos += scnprintf(buf + pos, bufsz - pos,
249 "bitmap1\trate_n_flags"); 263 "bitmap1\trate_n_flags");
250#endif
251 pos += scnprintf(buf + pos, bufsz - pos, "\n"); 264 pos += scnprintf(buf + pos, bufsz - pos, "\n");
252 265
253 for (j = 0; j < MAX_TID_COUNT; j++) { 266 for (j = 0; j < MAX_TID_COUNT; j++) {
254 pos += scnprintf(buf + pos, bufsz - pos, 267 pos += scnprintf(buf + pos, bufsz - pos,
255 "[%d]:\t\t%u", j, 268 "[%d]:\t\t%u", j,
256 station->tid[j].seq_number); 269 station->tid[j].seq_number);
257#ifdef CONFIG_IWL4965_HT
258 pos += scnprintf(buf + pos, bufsz - pos, 270 pos += scnprintf(buf + pos, bufsz - pos,
259 "\t%u\t\t%u\t\t%u\t\t", 271 "\t%u\t\t%u\t\t%u\t\t",
260 station->tid[j].agg.txq_id, 272 station->tid[j].agg.txq_id,
@@ -265,7 +277,6 @@ static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
265 station->tid[j].agg.start_idx, 277 station->tid[j].agg.start_idx,
266 (unsigned long long)station->tid[j].agg.bitmap, 278 (unsigned long long)station->tid[j].agg.bitmap,
267 station->tid[j].agg.rate_n_flags); 279 station->tid[j].agg.rate_n_flags);
268#endif
269 pos += scnprintf(buf + pos, bufsz - pos, "\n"); 280 pos += scnprintf(buf + pos, bufsz - pos, "\n");
270 } 281 }
271 pos += scnprintf(buf + pos, bufsz - pos, "\n"); 282 pos += scnprintf(buf + pos, bufsz - pos, "\n");
@@ -277,8 +288,70 @@ static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
277 return ret; 288 return ret;
278} 289}
279 290
291static ssize_t iwl_dbgfs_eeprom_read(struct file *file,
292 char __user *user_buf,
293 size_t count,
294 loff_t *ppos)
295{
296 ssize_t ret;
297 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
298 int pos = 0, ofs = 0, buf_size = 0;
299 const u8 *ptr;
300 char *buf;
301 size_t eeprom_len = priv->cfg->eeprom_size;
302 buf_size = 4 * eeprom_len + 256;
303
304 if (eeprom_len % 16) {
305 IWL_ERROR("EEPROM size is not multiple of 16.\n");
306 return -ENODATA;
307 }
308
309 /* 4 characters for byte 0xYY */
310 buf = kzalloc(buf_size, GFP_KERNEL);
311 if (!buf) {
312 IWL_ERROR("Can not allocate Buffer\n");
313 return -ENOMEM;
314 }
315
316 ptr = priv->eeprom;
317 for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) {
318 pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs);
319 hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos,
320 buf_size - pos, 0);
321 pos += strlen(buf);
322 if (buf_size - pos > 0)
323 buf[pos++] = '\n';
324 }
325
326 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
327 kfree(buf);
328 return ret;
329}
330
331static ssize_t iwl_dbgfs_log_event_write(struct file *file,
332 const char __user *user_buf,
333 size_t count, loff_t *ppos)
334{
335 struct iwl_priv *priv = file->private_data;
336 u32 event_log_flag;
337 char buf[8];
338 int buf_size;
339
340 memset(buf, 0, sizeof(buf));
341 buf_size = min(count, sizeof(buf) - 1);
342 if (copy_from_user(buf, user_buf, buf_size))
343 return -EFAULT;
344 if (sscanf(buf, "%d", &event_log_flag) != 1)
345 return -EFAULT;
346 if (event_log_flag == 1)
347 iwl_dump_nic_event_log(priv);
348
349 return count;
350}
280 351
281DEBUGFS_READ_WRITE_FILE_OPS(sram); 352DEBUGFS_READ_WRITE_FILE_OPS(sram);
353DEBUGFS_WRITE_FILE_OPS(log_event);
354DEBUGFS_READ_FILE_OPS(eeprom);
282DEBUGFS_READ_FILE_OPS(stations); 355DEBUGFS_READ_FILE_OPS(stations);
283DEBUGFS_READ_FILE_OPS(rx_statistics); 356DEBUGFS_READ_FILE_OPS(rx_statistics);
284DEBUGFS_READ_FILE_OPS(tx_statistics); 357DEBUGFS_READ_FILE_OPS(tx_statistics);
@@ -290,31 +363,41 @@ DEBUGFS_READ_FILE_OPS(tx_statistics);
290int iwl_dbgfs_register(struct iwl_priv *priv, const char *name) 363int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
291{ 364{
292 struct iwl_debugfs *dbgfs; 365 struct iwl_debugfs *dbgfs;
366 struct dentry *phyd = priv->hw->wiphy->debugfsdir;
367 int ret = 0;
293 368
294 dbgfs = kzalloc(sizeof(struct iwl_debugfs), GFP_KERNEL); 369 dbgfs = kzalloc(sizeof(struct iwl_debugfs), GFP_KERNEL);
295 if (!dbgfs) { 370 if (!dbgfs) {
371 ret = -ENOMEM;
296 goto err; 372 goto err;
297 } 373 }
298 374
299 priv->dbgfs = dbgfs; 375 priv->dbgfs = dbgfs;
300 dbgfs->name = name; 376 dbgfs->name = name;
301 dbgfs->dir_drv = debugfs_create_dir(name, NULL); 377 dbgfs->dir_drv = debugfs_create_dir(name, phyd);
302 if (!dbgfs->dir_drv || IS_ERR(dbgfs->dir_drv)){ 378 if (!dbgfs->dir_drv || IS_ERR(dbgfs->dir_drv)) {
379 ret = -ENOENT;
303 goto err; 380 goto err;
304 } 381 }
305 382
306 DEBUGFS_ADD_DIR(data, dbgfs->dir_drv); 383 DEBUGFS_ADD_DIR(data, dbgfs->dir_drv);
384 DEBUGFS_ADD_DIR(rf, dbgfs->dir_drv);
385 DEBUGFS_ADD_FILE(eeprom, data);
307 DEBUGFS_ADD_FILE(sram, data); 386 DEBUGFS_ADD_FILE(sram, data);
387 DEBUGFS_ADD_FILE(log_event, data);
308 DEBUGFS_ADD_FILE(stations, data); 388 DEBUGFS_ADD_FILE(stations, data);
309 DEBUGFS_ADD_FILE(rx_statistics, data); 389 DEBUGFS_ADD_FILE(rx_statistics, data);
310 DEBUGFS_ADD_FILE(tx_statistics, data); 390 DEBUGFS_ADD_FILE(tx_statistics, data);
311 391 DEBUGFS_ADD_BOOL(disable_sensitivity, rf, &priv->disable_sens_cal);
392 DEBUGFS_ADD_BOOL(disable_chain_noise, rf,
393 &priv->disable_chain_noise_cal);
394 DEBUGFS_ADD_BOOL(disable_tx_power, rf, &priv->disable_tx_power_cal);
312 return 0; 395 return 0;
313 396
314err: 397err:
315 IWL_ERROR("Can't open the debugfs directory\n"); 398 IWL_ERROR("Can't open the debugfs directory\n");
316 iwl_dbgfs_unregister(priv); 399 iwl_dbgfs_unregister(priv);
317 return -ENOENT; 400 return ret;
318} 401}
319EXPORT_SYMBOL(iwl_dbgfs_register); 402EXPORT_SYMBOL(iwl_dbgfs_register);
320 403
@@ -324,14 +407,20 @@ EXPORT_SYMBOL(iwl_dbgfs_register);
324 */ 407 */
325void iwl_dbgfs_unregister(struct iwl_priv *priv) 408void iwl_dbgfs_unregister(struct iwl_priv *priv)
326{ 409{
327 if (!(priv->dbgfs)) 410 if (!priv->dbgfs)
328 return; 411 return;
329 412
413 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_eeprom);
330 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_rx_statistics); 414 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_rx_statistics);
331 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_tx_statistics); 415 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_tx_statistics);
332 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_sram); 416 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_sram);
417 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_log_event);
333 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_stations); 418 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_stations);
334 DEBUGFS_REMOVE(priv->dbgfs->dir_data); 419 DEBUGFS_REMOVE(priv->dbgfs->dir_data);
420 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_sensitivity);
421 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_chain_noise);
422 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_tx_power);
423 DEBUGFS_REMOVE(priv->dbgfs->dir_rf);
335 DEBUGFS_REMOVE(priv->dbgfs->dir_drv); 424 DEBUGFS_REMOVE(priv->dbgfs->dir_drv);
336 kfree(priv->dbgfs); 425 kfree(priv->dbgfs);
337 priv->dbgfs = NULL; 426 priv->dbgfs = NULL;
@@ -339,3 +428,4 @@ void iwl_dbgfs_unregister(struct iwl_priv *priv)
339EXPORT_SYMBOL(iwl_dbgfs_unregister); 428EXPORT_SYMBOL(iwl_dbgfs_unregister);
340 429
341 430
431
diff --git a/drivers/net/wireless/iwlwifi/iwl-4965.h b/drivers/net/wireless/iwlwifi/iwl-dev.h
index 581b98556c86..c018121085e9 100644
--- a/drivers/net/wireless/iwlwifi/iwl-4965.h
+++ b/drivers/net/wireless/iwlwifi/iwl-dev.h
@@ -24,19 +24,19 @@
24 * 24 *
25 *****************************************************************************/ 25 *****************************************************************************/
26/* 26/*
27 * Please use this file (iwl-4965.h) for driver implementation definitions. 27 * Please use this file (iwl-dev.h) for driver implementation definitions.
28 * Please use iwl-4965-commands.h for uCode API definitions. 28 * Please use iwl-commands.h for uCode API definitions.
29 * Please use iwl-4965-hw.h for hardware-related definitions. 29 * Please use iwl-4965-hw.h for hardware-related definitions.
30 */ 30 */
31 31
32#ifndef __iwl_4965_h__ 32#ifndef __iwl_dev_h__
33#define __iwl_4965_h__ 33#define __iwl_dev_h__
34 34
35#include <linux/pci.h> /* for struct pci_device_id */ 35#include <linux/pci.h> /* for struct pci_device_id */
36#include <linux/kernel.h> 36#include <linux/kernel.h>
37#include <net/ieee80211_radiotap.h> 37#include <net/ieee80211_radiotap.h>
38 38
39#define DRV_NAME "iwl4965" 39#define DRV_NAME "iwlagn"
40#include "iwl-rfkill.h" 40#include "iwl-rfkill.h"
41#include "iwl-eeprom.h" 41#include "iwl-eeprom.h"
42#include "iwl-4965-hw.h" 42#include "iwl-4965-hw.h"
@@ -44,16 +44,19 @@
44#include "iwl-prph.h" 44#include "iwl-prph.h"
45#include "iwl-debug.h" 45#include "iwl-debug.h"
46#include "iwl-led.h" 46#include "iwl-led.h"
47#include "iwl-power.h"
48#include "iwl-agn-rs.h"
47 49
48/* configuration for the iwl4965 */ 50/* configuration for the iwl4965 */
49extern struct iwl_cfg iwl4965_agn_cfg; 51extern struct iwl_cfg iwl4965_agn_cfg;
52extern struct iwl_cfg iwl5300_agn_cfg;
53extern struct iwl_cfg iwl5100_agn_cfg;
54extern struct iwl_cfg iwl5350_agn_cfg;
55extern struct iwl_cfg iwl5100_bg_cfg;
56extern struct iwl_cfg iwl5100_abg_cfg;
50 57
51/* Change firmware file name, using "-" and incrementing number, 58/* CT-KILL constants */
52 * *only* when uCode interface or architecture changes so that it 59#define CT_KILL_THRESHOLD 110 /* in Celsius */
53 * is not compatible with earlier drivers.
54 * This number will also appear in << 8 position of 1st dword of uCode file */
55#define IWL4965_UCODE_API "-1"
56
57 60
58/* Default noise level to report when noise measurement is not available. 61/* Default noise level to report when noise measurement is not available.
59 * This may be because we're: 62 * This may be because we're:
@@ -68,12 +71,6 @@ extern struct iwl_cfg iwl4965_agn_cfg;
68 * averages within an s8's (used in some apps) range of negative values. */ 71 * averages within an s8's (used in some apps) range of negative values. */
69#define IWL_NOISE_MEAS_NOT_AVAILABLE (-127) 72#define IWL_NOISE_MEAS_NOT_AVAILABLE (-127)
70 73
71enum iwl4965_antenna {
72 IWL_ANTENNA_DIVERSITY,
73 IWL_ANTENNA_MAIN,
74 IWL_ANTENNA_AUX
75};
76
77/* 74/*
78 * RTS threshold here is total size [2347] minus 4 FCS bytes 75 * RTS threshold here is total size [2347] minus 4 FCS bytes
79 * Per spec: 76 * Per spec:
@@ -91,7 +88,7 @@ enum iwl4965_antenna {
91#define DEFAULT_SHORT_RETRY_LIMIT 7U 88#define DEFAULT_SHORT_RETRY_LIMIT 7U
92#define DEFAULT_LONG_RETRY_LIMIT 4U 89#define DEFAULT_LONG_RETRY_LIMIT 4U
93 90
94struct iwl4965_rx_mem_buffer { 91struct iwl_rx_mem_buffer {
95 dma_addr_t dma_addr; 92 dma_addr_t dma_addr;
96 struct sk_buff *skb; 93 struct sk_buff *skb;
97 struct list_head list; 94 struct list_head list;
@@ -102,7 +99,7 @@ struct iwl4965_rx_mem_buffer {
102 * 99 *
103 * Contains common data for Rx and Tx queues 100 * Contains common data for Rx and Tx queues
104 */ 101 */
105struct iwl4965_queue { 102struct iwl_queue {
106 int n_bd; /* number of BDs in this queue */ 103 int n_bd; /* number of BDs in this queue */
107 int write_ptr; /* 1-st empty entry (index) host_w*/ 104 int write_ptr; /* 1-st empty entry (index) host_w*/
108 int read_ptr; /* last used entry (index) host_r*/ 105 int read_ptr; /* last used entry (index) host_r*/
@@ -118,13 +115,12 @@ struct iwl4965_queue {
118#define MAX_NUM_OF_TBS (20) 115#define MAX_NUM_OF_TBS (20)
119 116
120/* One for each TFD */ 117/* One for each TFD */
121struct iwl4965_tx_info { 118struct iwl_tx_info {
122 struct ieee80211_tx_status status;
123 struct sk_buff *skb[MAX_NUM_OF_TBS]; 119 struct sk_buff *skb[MAX_NUM_OF_TBS];
124}; 120};
125 121
126/** 122/**
127 * struct iwl4965_tx_queue - Tx Queue for DMA 123 * struct iwl_tx_queue - Tx Queue for DMA
128 * @q: generic Rx/Tx queue descriptor 124 * @q: generic Rx/Tx queue descriptor
129 * @bd: base of circular buffer of TFDs 125 * @bd: base of circular buffer of TFDs
130 * @cmd: array of command/Tx buffers 126 * @cmd: array of command/Tx buffers
@@ -136,12 +132,11 @@ struct iwl4965_tx_info {
136 * A Tx queue consists of circular buffer of BDs (a.k.a. TFDs, transmit frame 132 * A Tx queue consists of circular buffer of BDs (a.k.a. TFDs, transmit frame
137 * descriptors) and required locking structures. 133 * descriptors) and required locking structures.
138 */ 134 */
139struct iwl4965_tx_queue { 135struct iwl_tx_queue {
140 struct iwl4965_queue q; 136 struct iwl_queue q;
141 struct iwl4965_tfd_frame *bd; 137 struct iwl_tfd_frame *bd;
142 struct iwl_cmd *cmd; 138 struct iwl_cmd *cmd[TFD_TX_CMD_SLOTS];
143 dma_addr_t dma_addr_cmd; 139 struct iwl_tx_info *txb;
144 struct iwl4965_tx_info *txb;
145 int need_update; 140 int need_update;
146 int sched_retry; 141 int sched_retry;
147 int active; 142 int active;
@@ -158,50 +153,17 @@ struct iwl4965_channel_tgh_info {
158 s64 last_radar_time; 153 s64 last_radar_time;
159}; 154};
160 155
161/* current Tx power values to use, one for each rate for each channel.
162 * requested power is limited by:
163 * -- regulatory EEPROM limits for this channel
164 * -- hardware capabilities (clip-powers)
165 * -- spectrum management
166 * -- user preference (e.g. iwconfig)
167 * when requested power is set, base power index must also be set. */
168struct iwl4965_channel_power_info {
169 struct iwl4965_tx_power tpc; /* actual radio and DSP gain settings */
170 s8 power_table_index; /* actual (compenst'd) index into gain table */
171 s8 base_power_index; /* gain index for power at factory temp. */
172 s8 requested_power; /* power (dBm) requested for this chnl/rate */
173};
174
175/* current scan Tx power values to use, one for each scan rate for each
176 * channel. */
177struct iwl4965_scan_power_info {
178 struct iwl4965_tx_power tpc; /* actual radio and DSP gain settings */
179 s8 power_table_index; /* actual (compenst'd) index into gain table */
180 s8 requested_power; /* scan pwr (dBm) requested for chnl/rate */
181};
182
183/* For fat_extension_channel */
184enum {
185 HT_IE_EXT_CHANNEL_NONE = 0,
186 HT_IE_EXT_CHANNEL_ABOVE,
187 HT_IE_EXT_CHANNEL_INVALID,
188 HT_IE_EXT_CHANNEL_BELOW,
189 HT_IE_EXT_CHANNEL_MAX
190};
191
192/* 156/*
193 * One for each channel, holds all channel setup data 157 * One for each channel, holds all channel setup data
194 * Some of the fields (e.g. eeprom and flags/max_power_avg) are redundant 158 * Some of the fields (e.g. eeprom and flags/max_power_avg) are redundant
195 * with one another! 159 * with one another!
196 */ 160 */
197#define IWL4965_MAX_RATE (33)
198
199struct iwl_channel_info { 161struct iwl_channel_info {
200 struct iwl4965_channel_tgd_info tgd; 162 struct iwl4965_channel_tgd_info tgd;
201 struct iwl4965_channel_tgh_info tgh; 163 struct iwl4965_channel_tgh_info tgh;
202 struct iwl4965_eeprom_channel eeprom; /* EEPROM regulatory limit */ 164 struct iwl_eeprom_channel eeprom; /* EEPROM regulatory limit */
203 struct iwl4965_eeprom_channel fat_eeprom; /* EEPROM regulatory limit for 165 struct iwl_eeprom_channel fat_eeprom; /* EEPROM regulatory limit for
204 * FAT channel */ 166 * FAT channel */
205 167
206 u8 channel; /* channel number */ 168 u8 channel; /* channel number */
207 u8 flags; /* flags copied from EEPROM */ 169 u8 flags; /* flags copied from EEPROM */
@@ -214,11 +176,6 @@ struct iwl_channel_info {
214 u8 band_index; /* 0-4, maps channel to band1/2/3/4/5 */ 176 u8 band_index; /* 0-4, maps channel to band1/2/3/4/5 */
215 enum ieee80211_band band; 177 enum ieee80211_band band;
216 178
217 /* Radio/DSP gain settings for each "normal" data Tx rate.
218 * These include, in addition to RF and DSP gain, a few fields for
219 * remembering/modifying gain settings (indexes). */
220 struct iwl4965_channel_power_info power_info[IWL4965_MAX_RATE];
221
222 /* FAT channel info */ 179 /* FAT channel info */
223 s8 fat_max_power_avg; /* (dBm) regul. eeprom, normal Tx, any rate */ 180 s8 fat_max_power_avg; /* (dBm) regul. eeprom, normal Tx, any rate */
224 s8 fat_curr_txpow; /* (dBm) regulatory/spectrum/user (not h/w) */ 181 s8 fat_curr_txpow; /* (dBm) regulatory/spectrum/user (not h/w) */
@@ -226,9 +183,6 @@ struct iwl_channel_info {
226 s8 fat_scan_power; /* (dBm) eeprom, direct scans, any rate */ 183 s8 fat_scan_power; /* (dBm) eeprom, direct scans, any rate */
227 u8 fat_flags; /* flags copied from EEPROM */ 184 u8 fat_flags; /* flags copied from EEPROM */
228 u8 fat_extension_channel; /* HT_IE_EXT_CHANNEL_* */ 185 u8 fat_extension_channel; /* HT_IE_EXT_CHANNEL_* */
229
230 /* Radio/DSP gain settings for each scan rate, for directed scans. */
231 struct iwl4965_scan_power_info scan_pwr_info[IWL_NUM_SCAN_RATES];
232}; 186};
233 187
234struct iwl4965_clip_group { 188struct iwl4965_clip_group {
@@ -237,7 +191,6 @@ struct iwl4965_clip_group {
237 const s8 clip_powers[IWL_MAX_RATES]; 191 const s8 clip_powers[IWL_MAX_RATES];
238}; 192};
239 193
240#include "iwl-4965-rs.h"
241 194
242#define IWL_TX_FIFO_AC0 0 195#define IWL_TX_FIFO_AC0 0
243#define IWL_TX_FIFO_AC1 1 196#define IWL_TX_FIFO_AC1 1
@@ -252,29 +205,9 @@ struct iwl4965_clip_group {
252 205
253/* Power management (not Tx power) structures */ 206/* Power management (not Tx power) structures */
254 207
255struct iwl4965_power_vec_entry { 208enum iwl_pwr_src {
256 struct iwl4965_powertable_cmd cmd; 209 IWL_PWR_SRC_VMAIN,
257 u8 no_dtim; 210 IWL_PWR_SRC_VAUX,
258};
259#define IWL_POWER_RANGE_0 (0)
260#define IWL_POWER_RANGE_1 (1)
261
262#define IWL_POWER_MODE_CAM 0x00 /* Continuously Aware Mode, always on */
263#define IWL_POWER_INDEX_3 0x03
264#define IWL_POWER_INDEX_5 0x05
265#define IWL_POWER_AC 0x06
266#define IWL_POWER_BATTERY 0x07
267#define IWL_POWER_LIMIT 0x07
268#define IWL_POWER_MASK 0x0F
269#define IWL_POWER_ENABLED 0x10
270#define IWL_POWER_LEVEL(x) ((x) & IWL_POWER_MASK)
271
272struct iwl4965_power_mgr {
273 spinlock_t lock;
274 struct iwl4965_power_vec_entry pwr_range_0[IWL_POWER_AC];
275 struct iwl4965_power_vec_entry pwr_range_1[IWL_POWER_AC];
276 u8 active_index;
277 u32 dtim_val;
278}; 211};
279 212
280#define IEEE80211_DATA_LEN 2304 213#define IEEE80211_DATA_LEN 2304
@@ -282,22 +215,16 @@ struct iwl4965_power_mgr {
282#define IEEE80211_HLEN (IEEE80211_4ADDR_LEN) 215#define IEEE80211_HLEN (IEEE80211_4ADDR_LEN)
283#define IEEE80211_FRAME_LEN (IEEE80211_DATA_LEN + IEEE80211_HLEN) 216#define IEEE80211_FRAME_LEN (IEEE80211_DATA_LEN + IEEE80211_HLEN)
284 217
285struct iwl4965_frame { 218struct iwl_frame {
286 union { 219 union {
287 struct ieee80211_hdr frame; 220 struct ieee80211_hdr frame;
288 struct iwl4965_tx_beacon_cmd beacon; 221 struct iwl_tx_beacon_cmd beacon;
289 u8 raw[IEEE80211_FRAME_LEN]; 222 u8 raw[IEEE80211_FRAME_LEN];
290 u8 cmd[360]; 223 u8 cmd[360];
291 } u; 224 } u;
292 struct list_head list; 225 struct list_head list;
293}; 226};
294 227
295#define SEQ_TO_QUEUE(x) ((x >> 8) & 0xbf)
296#define QUEUE_TO_SEQ(x) ((x & 0xbf) << 8)
297#define SEQ_TO_INDEX(x) ((u8)(x & 0xff))
298#define INDEX_TO_SEQ(x) ((u8)(x & 0xff))
299#define SEQ_HUGE_FRAME (0x4000)
300#define SEQ_RX_FRAME __constant_cpu_to_le16(0x8000)
301#define SEQ_TO_SN(seq) (((seq) & IEEE80211_SCTL_SEQ) >> 4) 228#define SEQ_TO_SN(seq) (((seq) & IEEE80211_SCTL_SEQ) >> 4)
302#define SN_TO_SEQ(ssn) (((ssn) << 4) & IEEE80211_SCTL_SEQ) 229#define SN_TO_SEQ(ssn) (((ssn) << 4) & IEEE80211_SCTL_SEQ)
303#define MAX_SN ((IEEE80211_SCTL_SEQ) >> 4) 230#define MAX_SN ((IEEE80211_SCTL_SEQ) >> 4)
@@ -328,6 +255,8 @@ struct iwl_cmd_meta {
328 255
329} __attribute__ ((packed)); 256} __attribute__ ((packed));
330 257
258#define IWL_CMD_MAX_PAYLOAD 320
259
331/** 260/**
332 * struct iwl_cmd 261 * struct iwl_cmd
333 * 262 *
@@ -339,21 +268,21 @@ struct iwl_cmd {
339 struct iwl_cmd_meta meta; /* driver data */ 268 struct iwl_cmd_meta meta; /* driver data */
340 struct iwl_cmd_header hdr; /* uCode API */ 269 struct iwl_cmd_header hdr; /* uCode API */
341 union { 270 union {
342 struct iwl4965_addsta_cmd addsta; 271 struct iwl_addsta_cmd addsta;
343 struct iwl4965_led_cmd led; 272 struct iwl_led_cmd led;
344 u32 flags; 273 u32 flags;
345 u8 val8; 274 u8 val8;
346 u16 val16; 275 u16 val16;
347 u32 val32; 276 u32 val32;
348 struct iwl4965_bt_cmd bt; 277 struct iwl4965_bt_cmd bt;
349 struct iwl4965_rxon_time_cmd rxon_time; 278 struct iwl4965_rxon_time_cmd rxon_time;
350 struct iwl4965_powertable_cmd powertable; 279 struct iwl_powertable_cmd powertable;
351 struct iwl4965_qosparam_cmd qosparam; 280 struct iwl_qosparam_cmd qosparam;
352 struct iwl4965_tx_cmd tx; 281 struct iwl_tx_cmd tx;
353 struct iwl4965_tx_beacon_cmd tx_beacon;
354 struct iwl4965_rxon_assoc_cmd rxon_assoc; 282 struct iwl4965_rxon_assoc_cmd rxon_assoc;
283 struct iwl_rem_sta_cmd rm_sta;
355 u8 *indirect; 284 u8 *indirect;
356 u8 payload[360]; 285 u8 payload[IWL_CMD_MAX_PAYLOAD];
357 } __attribute__ ((packed)) cmd; 286 } __attribute__ ((packed)) cmd;
358} __attribute__ ((packed)); 287} __attribute__ ((packed));
359 288
@@ -378,7 +307,7 @@ struct iwl_host_cmd {
378#define SUP_RATE_11G_MAX_NUM_CHANNELS 12 307#define SUP_RATE_11G_MAX_NUM_CHANNELS 12
379 308
380/** 309/**
381 * struct iwl4965_rx_queue - Rx queue 310 * struct iwl_rx_queue - Rx queue
382 * @processed: Internal index to last handled Rx packet 311 * @processed: Internal index to last handled Rx packet
383 * @read: Shared index to newest available Rx buffer 312 * @read: Shared index to newest available Rx buffer
384 * @write: Shared index to oldest written Rx packet 313 * @write: Shared index to oldest written Rx packet
@@ -387,13 +316,13 @@ struct iwl_host_cmd {
387 * @rx_used: List of Rx buffers with no SKB 316 * @rx_used: List of Rx buffers with no SKB
388 * @need_update: flag to indicate we need to update read/write index 317 * @need_update: flag to indicate we need to update read/write index
389 * 318 *
390 * NOTE: rx_free and rx_used are used as a FIFO for iwl4965_rx_mem_buffers 319 * NOTE: rx_free and rx_used are used as a FIFO for iwl_rx_mem_buffers
391 */ 320 */
392struct iwl4965_rx_queue { 321struct iwl_rx_queue {
393 __le32 *bd; 322 __le32 *bd;
394 dma_addr_t dma_addr; 323 dma_addr_t dma_addr;
395 struct iwl4965_rx_mem_buffer pool[RX_QUEUE_SIZE + RX_FREE_BUFFERS]; 324 struct iwl_rx_mem_buffer pool[RX_QUEUE_SIZE + RX_FREE_BUFFERS];
396 struct iwl4965_rx_mem_buffer *queue[RX_QUEUE_SIZE]; 325 struct iwl_rx_mem_buffer *queue[RX_QUEUE_SIZE];
397 u32 processed; 326 u32 processed;
398 u32 read; 327 u32 read;
399 u32 write; 328 u32 write;
@@ -419,9 +348,8 @@ struct iwl4965_rx_queue {
419#define IWL_INVALID_RATE 0xFF 348#define IWL_INVALID_RATE 0xFF
420#define IWL_INVALID_VALUE -1 349#define IWL_INVALID_VALUE -1
421 350
422#ifdef CONFIG_IWL4965_HT
423/** 351/**
424 * struct iwl4965_ht_agg -- aggregation status while waiting for block-ack 352 * struct iwl_ht_agg -- aggregation status while waiting for block-ack
425 * @txq_id: Tx queue used for Tx attempt 353 * @txq_id: Tx queue used for Tx attempt
426 * @frame_count: # frames attempted by Tx command 354 * @frame_count: # frames attempted by Tx command
427 * @wait_for_ba: Expect block-ack before next Tx reply 355 * @wait_for_ba: Expect block-ack before next Tx reply
@@ -434,7 +362,7 @@ struct iwl4965_rx_queue {
434 * for block ack (REPLY_COMPRESSED_BA). This struct stores tx reply info 362 * for block ack (REPLY_COMPRESSED_BA). This struct stores tx reply info
435 * until block ack arrives. 363 * until block ack arrives.
436 */ 364 */
437struct iwl4965_ht_agg { 365struct iwl_ht_agg {
438 u16 txq_id; 366 u16 txq_id;
439 u16 frame_count; 367 u16 frame_count;
440 u16 wait_for_ba; 368 u16 wait_for_ba;
@@ -448,21 +376,17 @@ struct iwl4965_ht_agg {
448 u8 state; 376 u8 state;
449}; 377};
450 378
451#endif /* CONFIG_IWL4965_HT */
452 379
453struct iwl4965_tid_data { 380struct iwl_tid_data {
454 u16 seq_number; 381 u16 seq_number;
455 u16 tfds_in_queue; 382 u16 tfds_in_queue;
456#ifdef CONFIG_IWL4965_HT 383 struct iwl_ht_agg agg;
457 struct iwl4965_ht_agg agg;
458#endif /* CONFIG_IWL4965_HT */
459}; 384};
460 385
461struct iwl4965_hw_key { 386struct iwl_hw_key {
462 enum ieee80211_key_alg alg; 387 enum ieee80211_key_alg alg;
463 int keylen; 388 int keylen;
464 u8 keyidx; 389 u8 keyidx;
465 struct ieee80211_key_conf *conf;
466 u8 key[32]; 390 u8 key[32];
467}; 391};
468 392
@@ -474,7 +398,6 @@ union iwl4965_ht_rate_supp {
474 }; 398 };
475}; 399};
476 400
477#ifdef CONFIG_IWL4965_HT
478#define CFG_HT_RX_AMPDU_FACTOR_DEF (0x3) 401#define CFG_HT_RX_AMPDU_FACTOR_DEF (0x3)
479#define CFG_HT_MPDU_DENSITY_2USEC (0x5) 402#define CFG_HT_MPDU_DENSITY_2USEC (0x5)
480#define CFG_HT_MPDU_DENSITY_DEF CFG_HT_MPDU_DENSITY_2USEC 403#define CFG_HT_MPDU_DENSITY_DEF CFG_HT_MPDU_DENSITY_2USEC
@@ -483,7 +406,7 @@ struct iwl_ht_info {
483 /* self configuration data */ 406 /* self configuration data */
484 u8 is_ht; 407 u8 is_ht;
485 u8 supported_chan_width; 408 u8 supported_chan_width;
486 u16 tx_mimo_ps_mode; 409 u8 sm_ps;
487 u8 is_green_field; 410 u8 is_green_field;
488 u8 sgf; /* HT_SHORT_GI_* short guard interval */ 411 u8 sgf; /* HT_SHORT_GI_* short guard interval */
489 u8 max_amsdu_size; 412 u8 max_amsdu_size;
@@ -497,9 +420,8 @@ struct iwl_ht_info {
497 u8 ht_protection; 420 u8 ht_protection;
498 u8 non_GF_STA_present; 421 u8 non_GF_STA_present;
499}; 422};
500#endif /*CONFIG_IWL4965_HT */
501 423
502union iwl4965_qos_capabity { 424union iwl_qos_capabity {
503 struct { 425 struct {
504 u8 edca_count:4; /* bit 0-3 */ 426 u8 edca_count:4; /* bit 0-3 */
505 u8 q_ack:1; /* bit 4 */ 427 u8 q_ack:1; /* bit 4 */
@@ -520,22 +442,22 @@ union iwl4965_qos_capabity {
520}; 442};
521 443
522/* QoS structures */ 444/* QoS structures */
523struct iwl4965_qos_info { 445struct iwl_qos_info {
524 int qos_enable; 446 int qos_enable;
525 int qos_active; 447 int qos_active;
526 union iwl4965_qos_capabity qos_cap; 448 union iwl_qos_capabity qos_cap;
527 struct iwl4965_qosparam_cmd def_qos_parm; 449 struct iwl_qosparam_cmd def_qos_parm;
528}; 450};
529 451
530#define STA_PS_STATUS_WAKE 0 452#define STA_PS_STATUS_WAKE 0
531#define STA_PS_STATUS_SLEEP 1 453#define STA_PS_STATUS_SLEEP 1
532 454
533struct iwl4965_station_entry { 455struct iwl_station_entry {
534 struct iwl4965_addsta_cmd sta; 456 struct iwl_addsta_cmd sta;
535 struct iwl4965_tid_data tid[MAX_TID_COUNT]; 457 struct iwl_tid_data tid[MAX_TID_COUNT];
536 u8 used; 458 u8 used;
537 u8 ps_status; 459 u8 ps_status;
538 struct iwl4965_hw_key keyinfo; 460 struct iwl_hw_key keyinfo;
539}; 461};
540 462
541/* one for each uCode image (inst/data, boot/init/runtime) */ 463/* one for each uCode image (inst/data, boot/init/runtime) */
@@ -546,7 +468,7 @@ struct fw_desc {
546}; 468};
547 469
548/* uCode file layout */ 470/* uCode file layout */
549struct iwl4965_ucode { 471struct iwl_ucode {
550 __le32 ver; /* major/minor/subminor */ 472 __le32 ver; /* major/minor/subminor */
551 __le32 inst_size; /* bytes of runtime instructions */ 473 __le32 inst_size; /* bytes of runtime instructions */
552 __le32 data_size; /* bytes of runtime data */ 474 __le32 data_size; /* bytes of runtime data */
@@ -556,8 +478,6 @@ struct iwl4965_ucode {
556 u8 data[0]; /* data in same order as "size" elements */ 478 u8 data[0]; /* data in same order as "size" elements */
557}; 479};
558 480
559#define IWL_IBSS_MAC_HASH_SIZE 32
560
561struct iwl4965_ibss_seq { 481struct iwl4965_ibss_seq {
562 u8 mac[ETH_ALEN]; 482 u8 mac[ETH_ALEN];
563 u16 seq_num; 483 u16 seq_num;
@@ -566,20 +486,52 @@ struct iwl4965_ibss_seq {
566 struct list_head list; 486 struct list_head list;
567}; 487};
568 488
489struct iwl_sensitivity_ranges {
490 u16 min_nrg_cck;
491 u16 max_nrg_cck;
492
493 u16 nrg_th_cck;
494 u16 nrg_th_ofdm;
495
496 u16 auto_corr_min_ofdm;
497 u16 auto_corr_min_ofdm_mrc;
498 u16 auto_corr_min_ofdm_x1;
499 u16 auto_corr_min_ofdm_mrc_x1;
500
501 u16 auto_corr_max_ofdm;
502 u16 auto_corr_max_ofdm_mrc;
503 u16 auto_corr_max_ofdm_x1;
504 u16 auto_corr_max_ofdm_mrc_x1;
505
506 u16 auto_corr_max_cck;
507 u16 auto_corr_max_cck_mrc;
508 u16 auto_corr_min_cck;
509 u16 auto_corr_min_cck_mrc;
510};
511
512
513#define IWL_FAT_CHANNEL_52 BIT(IEEE80211_BAND_5GHZ)
514
569/** 515/**
570 * struct iwl_hw_params 516 * struct iwl_hw_params
571 * @max_txq_num: Max # Tx queues supported 517 * @max_txq_num: Max # Tx queues supported
572 * @tx_cmd_len: Size of Tx command (but not including frame itself) 518 * @tx/rx_chains_num: Number of TX/RX chains
573 * @tx_ant_num: Number of TX antennas 519 * @valid_tx/rx_ant: usable antennas
574 * @max_rxq_size: Max # Rx frames in Rx queue (must be power-of-2) 520 * @max_rxq_size: Max # Rx frames in Rx queue (must be power-of-2)
575 * @rx_buffer_size:
576 * @max_rxq_log: Log-base-2 of max_rxq_size 521 * @max_rxq_log: Log-base-2 of max_rxq_size
522 * @rx_buf_size: Rx buffer size
577 * @max_stations: 523 * @max_stations:
578 * @bcast_sta_id: 524 * @bcast_sta_id:
525 * @fat_channel: is 40MHz width possible in band 2.4
526 * BIT(IEEE80211_BAND_5GHZ) BIT(IEEE80211_BAND_5GHZ)
527 * @sw_crypto: 0 for hw, 1 for sw
528 * @max_xxx_size: for ucode uses
529 * @ct_kill_threshold: temperature threshold
530 * @struct iwl_sensitivity_ranges: range of sensitivity values
531 * @first_ampdu_q: first HW queue available for ampdu
579 */ 532 */
580struct iwl_hw_params { 533struct iwl_hw_params {
581 u16 max_txq_num; 534 u16 max_txq_num;
582 u16 tx_cmd_len;
583 u8 tx_chains_num; 535 u8 tx_chains_num;
584 u8 rx_chains_num; 536 u8 rx_chains_num;
585 u8 valid_tx_ant; 537 u8 valid_tx_ant;
@@ -590,10 +542,18 @@ struct iwl_hw_params {
590 u32 max_pkt_size; 542 u32 max_pkt_size;
591 u8 max_stations; 543 u8 max_stations;
592 u8 bcast_sta_id; 544 u8 bcast_sta_id;
545 u8 fat_channel;
546 u8 sw_crypto;
547 u32 max_inst_size;
548 u32 max_data_size;
549 u32 max_bsm_size;
550 u32 ct_kill_threshold; /* value in hw-dependent units */
551 const struct iwl_sensitivity_ranges *sens;
552 u8 first_ampdu_q;
593}; 553};
594 554
595#define HT_SHORT_GI_20MHZ_ONLY (1 << 0) 555#define HT_SHORT_GI_20MHZ (1 << 0)
596#define HT_SHORT_GI_40MHZ_ONLY (1 << 1) 556#define HT_SHORT_GI_40MHZ (1 << 1)
597 557
598 558
599#define IWL_RX_HDR(x) ((struct iwl4965_rx_frame_hdr *)(\ 559#define IWL_RX_HDR(x) ((struct iwl4965_rx_frame_hdr *)(\
@@ -605,165 +565,59 @@ struct iwl_hw_params {
605#define IWL_RX_STATS(x) (&x->u.rx_frame.stats) 565#define IWL_RX_STATS(x) (&x->u.rx_frame.stats)
606#define IWL_RX_DATA(x) (IWL_RX_HDR(x)->payload) 566#define IWL_RX_DATA(x) (IWL_RX_HDR(x)->payload)
607 567
608
609/****************************************************************************** 568/******************************************************************************
610 * 569 *
611 * Functions implemented in iwl-base.c which are forward declared here 570 * Functions implemented in core module which are forward declared here
612 * for use by iwl-*.c 571 * for use by iwl-[4-5].c
613 * 572 *
614 *****************************************************************************/ 573 * NOTE: The implementation of these functions are not hardware specific
615struct iwl4965_addsta_cmd; 574 * which is why they are in the core module files.
616extern int iwl4965_send_add_station(struct iwl_priv *priv,
617 struct iwl4965_addsta_cmd *sta, u8 flags);
618extern u8 iwl4965_add_station_flags(struct iwl_priv *priv, const u8 *addr,
619 int is_ap, u8 flags, void *ht_data);
620extern int iwl4965_is_network_packet(struct iwl_priv *priv,
621 struct ieee80211_hdr *header);
622extern int iwl4965_power_init_handle(struct iwl_priv *priv);
623extern void iwl4965_handle_data_packet_monitor(struct iwl_priv *priv,
624 struct iwl4965_rx_mem_buffer *rxb,
625 void *data, short len,
626 struct ieee80211_rx_status *stats,
627 u16 phy_flags);
628extern int iwl4965_is_duplicate_packet(struct iwl_priv *priv,
629 struct ieee80211_hdr *header);
630extern int iwl4965_rx_queue_alloc(struct iwl_priv *priv);
631extern void iwl4965_rx_queue_reset(struct iwl_priv *priv,
632 struct iwl4965_rx_queue *rxq);
633extern int iwl4965_calc_db_from_ratio(int sig_ratio);
634extern int iwl4965_calc_sig_qual(int rssi_dbm, int noise_dbm);
635extern int iwl4965_tx_queue_init(struct iwl_priv *priv,
636 struct iwl4965_tx_queue *txq, int count, u32 id);
637extern void iwl4965_rx_replenish(void *data);
638extern void iwl4965_tx_queue_free(struct iwl_priv *priv, struct iwl4965_tx_queue *txq);
639extern unsigned int iwl4965_fill_beacon_frame(struct iwl_priv *priv,
640 struct ieee80211_hdr *hdr,
641 const u8 *dest, int left);
642extern int iwl4965_rx_queue_update_write_ptr(struct iwl_priv *priv,
643 struct iwl4965_rx_queue *q);
644extern void iwl4965_set_decrypted_flag(struct iwl_priv *priv, struct sk_buff *skb,
645 u32 decrypt_res,
646 struct ieee80211_rx_status *stats);
647extern __le16 *ieee80211_get_qos_ctrl(struct ieee80211_hdr *hdr);
648int iwl4965_init_geos(struct iwl_priv *priv);
649void iwl4965_free_geos(struct iwl_priv *priv);
650
651extern const u8 iwl4965_broadcast_addr[ETH_ALEN];
652int iwl4965_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd);
653
654/*
655 * Currently used by iwl-3945-rs... look at restructuring so that it doesn't
656 * call this... todo... fix that.
657*/
658extern u8 iwl4965_sync_station(struct iwl_priv *priv, int sta_id,
659 u16 tx_rate, u8 flags);
660
661/******************************************************************************
662 *
663 * Functions implemented in iwl-[34]*.c which are forward declared here
664 * for use by iwl-base.c
665 *
666 * NOTE: The implementation of these functions are hardware specific
667 * which is why they are in the hardware specific files (vs. iwl-base.c)
668 * 575 *
669 * Naming convention -- 576 * Naming convention --
670 * iwl4965_ <-- Its part of iwlwifi (should be changed to iwl4965_) 577 * iwl_ <-- Is part of iwlwifi
671 * iwl4965_hw_ <-- Hardware specific (implemented in iwl-XXXX.c by all HW)
672 * iwlXXXX_ <-- Hardware specific (implemented in iwl-XXXX.c for XXXX) 578 * iwlXXXX_ <-- Hardware specific (implemented in iwl-XXXX.c for XXXX)
673 * iwl4965_bg_ <-- Called from work queue context 579 * iwl4965_bg_ <-- Called from work queue context
674 * iwl4965_mac_ <-- mac80211 callback 580 * iwl4965_mac_ <-- mac80211 callback
675 * 581 *
676 ****************************************************************************/ 582 ****************************************************************************/
677extern void iwl4965_hw_rx_handler_setup(struct iwl_priv *priv); 583struct iwl_addsta_cmd;
678extern void iwl4965_hw_setup_deferred_work(struct iwl_priv *priv); 584extern int iwl_send_add_sta(struct iwl_priv *priv,
679extern void iwl4965_hw_cancel_deferred_work(struct iwl_priv *priv); 585 struct iwl_addsta_cmd *sta, u8 flags);
680extern int iwl4965_hw_rxq_stop(struct iwl_priv *priv); 586extern u8 iwl_add_station_flags(struct iwl_priv *priv, const u8 *addr,
681extern int iwl4965_hw_set_hw_params(struct iwl_priv *priv); 587 int is_ap, u8 flags, struct ieee80211_ht_info *ht_info);
682extern int iwl4965_hw_nic_init(struct iwl_priv *priv); 588extern void iwl4965_update_chain_flags(struct iwl_priv *priv);
683extern int iwl4965_hw_nic_stop_master(struct iwl_priv *priv); 589extern int iwl4965_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src);
684extern void iwl4965_hw_txq_ctx_free(struct iwl_priv *priv); 590extern const u8 iwl_bcast_addr[ETH_ALEN];
685extern void iwl4965_hw_txq_ctx_stop(struct iwl_priv *priv); 591extern int iwl_rxq_stop(struct iwl_priv *priv);
686extern int iwl4965_hw_nic_reset(struct iwl_priv *priv); 592extern void iwl_txq_ctx_stop(struct iwl_priv *priv);
687extern int iwl4965_hw_txq_attach_buf_to_tfd(struct iwl_priv *priv, void *tfd, 593extern int iwl_queue_space(const struct iwl_queue *q);
688 dma_addr_t addr, u16 len); 594static inline int iwl_queue_used(const struct iwl_queue *q, int i)
689extern int iwl4965_hw_txq_free_tfd(struct iwl_priv *priv, struct iwl4965_tx_queue *txq); 595{
690extern int iwl4965_hw_get_temperature(struct iwl_priv *priv); 596 return q->write_ptr > q->read_ptr ?
691extern int iwl4965_hw_tx_queue_init(struct iwl_priv *priv, 597 (i >= q->read_ptr && i < q->write_ptr) :
692 struct iwl4965_tx_queue *txq); 598 !(i < q->read_ptr && i >= q->write_ptr);
693extern unsigned int iwl4965_hw_get_beacon_cmd(struct iwl_priv *priv, 599}
694 struct iwl4965_frame *frame, u8 rate); 600
695extern int iwl4965_hw_get_rx_read(struct iwl_priv *priv); 601
696extern void iwl4965_hw_build_tx_cmd_rate(struct iwl_priv *priv, 602static inline u8 get_cmd_index(struct iwl_queue *q, u32 index, int is_huge)
697 struct iwl_cmd *cmd, 603{
698 struct ieee80211_tx_control *ctrl, 604 /* This is for scan command, the big buffer at end of command array */
699 struct ieee80211_hdr *hdr, 605 if (is_huge)
700 int sta_id, int tx_id); 606 return q->n_window; /* must be power of 2 */
701extern int iwl4965_hw_reg_send_txpower(struct iwl_priv *priv); 607
702extern int iwl4965_hw_reg_set_txpower(struct iwl_priv *priv, s8 power); 608 /* Otherwise, use normal size buffers */
703extern void iwl4965_hw_rx_statistics(struct iwl_priv *priv, 609 return index & (q->n_window - 1);
704 struct iwl4965_rx_mem_buffer *rxb); 610}
705extern void iwl4965_disable_events(struct iwl_priv *priv);
706extern int iwl4965_get_temperature(const struct iwl_priv *priv);
707 611
708/**
709 * iwl4965_hw_find_station - Find station id for a given BSSID
710 * @bssid: MAC address of station ID to find
711 *
712 * NOTE: This should not be hardware specific but the code has
713 * not yet been merged into a single common layer for managing the
714 * station tables.
715 */
716extern u8 iwl4965_hw_find_station(struct iwl_priv *priv, const u8 *bssid);
717 612
718extern int iwl4965_hw_channel_switch(struct iwl_priv *priv, u16 channel);
719extern int iwl4965_tx_queue_reclaim(struct iwl_priv *priv, int txq_id, int index);
720extern int iwl4965_queue_space(const struct iwl4965_queue *q);
721struct iwl_priv; 613struct iwl_priv;
722 614
723extern void iwl4965_radio_kill_sw(struct iwl_priv *priv, int disable_radio);
724/*
725 * Forward declare iwl-4965.c functions for iwl-base.c
726 */
727extern int iwl4965_tx_queue_update_wr_ptr(struct iwl_priv *priv,
728 struct iwl4965_tx_queue *txq,
729 u16 byte_cnt);
730extern void iwl4965_add_station(struct iwl_priv *priv, const u8 *addr,
731 int is_ap);
732extern void iwl4965_set_rxon_chain(struct iwl_priv *priv);
733extern int iwl4965_alive_notify(struct iwl_priv *priv);
734extern void iwl4965_update_rate_scaling(struct iwl_priv *priv, u8 mode);
735extern void iwl4965_chain_noise_reset(struct iwl_priv *priv);
736extern void iwl4965_init_sensitivity(struct iwl_priv *priv, u8 flags,
737 u8 force);
738extern void iwl4965_rf_kill_ct_config(struct iwl_priv *priv);
739extern void iwl4965_hwrate_to_tx_control(struct iwl_priv *priv,
740 u32 rate_n_flags,
741 struct ieee80211_tx_control *control);
742
743#ifdef CONFIG_IWL4965_HT
744void iwl4965_init_ht_hw_capab(struct iwl_priv *priv,
745 struct ieee80211_ht_info *ht_info,
746 enum ieee80211_band band);
747void iwl4965_set_rxon_ht(struct iwl_priv *priv,
748 struct iwl_ht_info *ht_info);
749void iwl4965_set_ht_add_station(struct iwl_priv *priv, u8 index,
750 struct ieee80211_ht_info *sta_ht_inf);
751int iwl4965_mac_ampdu_action(struct ieee80211_hw *hw,
752 enum ieee80211_ampdu_mlme_action action,
753 const u8 *addr, u16 tid, u16 *ssn);
754int iwl4965_check_empty_hw_queue(struct iwl_priv *priv, int sta_id,
755 u8 tid, int txq_id);
756#else
757static inline void iwl4965_init_ht_hw_capab(struct iwl_priv *priv,
758 struct ieee80211_ht_info *ht_info,
759 enum ieee80211_band band) {}
760 615
761#endif /*CONFIG_IWL4965_HT */
762/* Structures, enum, and defines specific to the 4965 */ 616/* Structures, enum, and defines specific to the 4965 */
763 617
764#define IWL4965_KW_SIZE 0x1000 /*4k */ 618#define IWL_KW_SIZE 0x1000 /*4k */
765 619
766struct iwl4965_kw { 620struct iwl_kw {
767 dma_addr_t dma_addr; 621 dma_addr_t dma_addr;
768 void *v_addr; 622 void *v_addr;
769 size_t size; 623 size_t size;
@@ -772,39 +626,16 @@ struct iwl4965_kw {
772#define IWL_CHANNEL_WIDTH_20MHZ 0 626#define IWL_CHANNEL_WIDTH_20MHZ 0
773#define IWL_CHANNEL_WIDTH_40MHZ 1 627#define IWL_CHANNEL_WIDTH_40MHZ 1
774 628
775#define IWL_MIMO_PS_STATIC 0
776#define IWL_MIMO_PS_NONE 3
777#define IWL_MIMO_PS_DYNAMIC 1
778#define IWL_MIMO_PS_INVALID 2
779
780#define IWL_OPERATION_MODE_AUTO 0 629#define IWL_OPERATION_MODE_AUTO 0
781#define IWL_OPERATION_MODE_HT_ONLY 1 630#define IWL_OPERATION_MODE_HT_ONLY 1
782#define IWL_OPERATION_MODE_MIXED 2 631#define IWL_OPERATION_MODE_MIXED 2
783#define IWL_OPERATION_MODE_20MHZ 3 632#define IWL_OPERATION_MODE_20MHZ 3
784 633
785#define IWL_EXT_CHANNEL_OFFSET_NONE 0 634#define IWL_TX_CRC_SIZE 4
786#define IWL_EXT_CHANNEL_OFFSET_ABOVE 1 635#define IWL_TX_DELIMITER_SIZE 4
787#define IWL_EXT_CHANNEL_OFFSET_RESERVE1 2
788#define IWL_EXT_CHANNEL_OFFSET_BELOW 3
789
790#define NRG_NUM_PREV_STAT_L 20
791#define NUM_RX_CHAINS (3)
792 636
793#define TX_POWER_IWL_ILLEGAL_VOLTAGE -10000 637#define TX_POWER_IWL_ILLEGAL_VOLTAGE -10000
794 638
795struct iwl4965_lq_mngr {
796 spinlock_t lock;
797 s32 max_window_size;
798 s32 *expected_tpt;
799 u8 *next_higher_rate;
800 u8 *next_lower_rate;
801 unsigned long stamp;
802 unsigned long stamp_last;
803 u32 flush_time;
804 u32 tx_packets;
805 u8 lq_ready;
806};
807
808/* Sensitivity and chain noise calibration */ 639/* Sensitivity and chain noise calibration */
809#define INTERFERENCE_DATA_AVAILABLE __constant_cpu_to_le32(1) 640#define INTERFERENCE_DATA_AVAILABLE __constant_cpu_to_le32(1)
810#define INITIALIZATION_VALUE 0xFFFF 641#define INITIALIZATION_VALUE 0xFFFF
@@ -818,23 +649,8 @@ struct iwl4965_lq_mngr {
818#define MAX_FA_CCK 50 649#define MAX_FA_CCK 50
819#define MIN_FA_CCK 5 650#define MIN_FA_CCK 5
820 651
821#define NRG_MIN_CCK 97
822#define NRG_MAX_CCK 0
823
824#define AUTO_CORR_MIN_OFDM 85
825#define AUTO_CORR_MIN_OFDM_MRC 170
826#define AUTO_CORR_MIN_OFDM_X1 105
827#define AUTO_CORR_MIN_OFDM_MRC_X1 220
828#define AUTO_CORR_MAX_OFDM 120
829#define AUTO_CORR_MAX_OFDM_MRC 210
830#define AUTO_CORR_MAX_OFDM_X1 140
831#define AUTO_CORR_MAX_OFDM_MRC_X1 270
832#define AUTO_CORR_STEP_OFDM 1 652#define AUTO_CORR_STEP_OFDM 1
833 653
834#define AUTO_CORR_MIN_CCK (125)
835#define AUTO_CORR_MAX_CCK (200)
836#define AUTO_CORR_MIN_CCK_MRC 200
837#define AUTO_CORR_MAX_CCK_MRC 400
838#define AUTO_CORR_STEP_CCK 3 654#define AUTO_CORR_STEP_CCK 3
839#define AUTO_CORR_MAX_TH_CCK 160 655#define AUTO_CORR_MAX_TH_CCK 160
840 656
@@ -853,6 +669,9 @@ struct iwl4965_lq_mngr {
853#define IN_BAND_FILTER 0xFF 669#define IN_BAND_FILTER 0xFF
854#define MIN_AVERAGE_NOISE_MAX_VALUE 0xFFFFFFFF 670#define MIN_AVERAGE_NOISE_MAX_VALUE 0xFFFFFFFF
855 671
672#define NRG_NUM_PREV_STAT_L 20
673#define NUM_RX_CHAINS 3
674
856enum iwl4965_false_alarm_state { 675enum iwl4965_false_alarm_state {
857 IWL_FA_TOO_MANY = 0, 676 IWL_FA_TOO_MANY = 0,
858 IWL_FA_TOO_FEW = 1, 677 IWL_FA_TOO_FEW = 1,
@@ -861,13 +680,9 @@ enum iwl4965_false_alarm_state {
861 680
862enum iwl4965_chain_noise_state { 681enum iwl4965_chain_noise_state {
863 IWL_CHAIN_NOISE_ALIVE = 0, /* must be 0 */ 682 IWL_CHAIN_NOISE_ALIVE = 0, /* must be 0 */
864 IWL_CHAIN_NOISE_ACCUMULATE = 1, 683 IWL_CHAIN_NOISE_ACCUMULATE,
865 IWL_CHAIN_NOISE_CALIBRATED = 2, 684 IWL_CHAIN_NOISE_CALIBRATED,
866}; 685 IWL_CHAIN_NOISE_DONE,
867
868enum iwl4965_sensitivity_state {
869 IWL_SENS_CALIB_ALLOWED = 0,
870 IWL_SENS_CALIB_NEED_REINIT = 1,
871}; 686};
872 687
873enum iwl4965_calib_enabled_state { 688enum iwl4965_calib_enabled_state {
@@ -884,8 +699,20 @@ struct statistics_general_data {
884 u32 beacon_energy_c; 699 u32 beacon_energy_c;
885}; 700};
886 701
702/* Opaque calibration results */
703struct iwl_calib_result {
704 void *buf;
705 size_t buf_len;
706};
707
708enum ucode_type {
709 UCODE_NONE = 0,
710 UCODE_INIT,
711 UCODE_RT
712};
713
887/* Sensitivity calib data */ 714/* Sensitivity calib data */
888struct iwl4965_sensitivity_data { 715struct iwl_sensitivity_data {
889 u32 auto_corr_ofdm; 716 u32 auto_corr_ofdm;
890 u32 auto_corr_ofdm_mrc; 717 u32 auto_corr_ofdm_mrc;
891 u32 auto_corr_ofdm_x1; 718 u32 auto_corr_ofdm_x1;
@@ -909,39 +736,36 @@ struct iwl4965_sensitivity_data {
909 s32 nrg_auto_corr_silence_diff; 736 s32 nrg_auto_corr_silence_diff;
910 u32 num_in_cck_no_fa; 737 u32 num_in_cck_no_fa;
911 u32 nrg_th_ofdm; 738 u32 nrg_th_ofdm;
912
913 u8 state;
914}; 739};
915 740
916/* Chain noise (differential Rx gain) calib data */ 741/* Chain noise (differential Rx gain) calib data */
917struct iwl4965_chain_noise_data { 742struct iwl_chain_noise_data {
918 u8 state; 743 u32 active_chains;
919 u16 beacon_count;
920 u32 chain_noise_a; 744 u32 chain_noise_a;
921 u32 chain_noise_b; 745 u32 chain_noise_b;
922 u32 chain_noise_c; 746 u32 chain_noise_c;
923 u32 chain_signal_a; 747 u32 chain_signal_a;
924 u32 chain_signal_b; 748 u32 chain_signal_b;
925 u32 chain_signal_c; 749 u32 chain_signal_c;
750 u16 beacon_count;
926 u8 disconn_array[NUM_RX_CHAINS]; 751 u8 disconn_array[NUM_RX_CHAINS];
927 u8 delta_gain_code[NUM_RX_CHAINS]; 752 u8 delta_gain_code[NUM_RX_CHAINS];
928 u8 radio_write; 753 u8 radio_write;
754 u8 state;
929}; 755};
930 756
931#define EEPROM_SEM_TIMEOUT 10 /* milliseconds */ 757#define EEPROM_SEM_TIMEOUT 10 /* milliseconds */
932#define EEPROM_SEM_RETRY_LIMIT 1000 /* number of attempts (not time) */ 758#define EEPROM_SEM_RETRY_LIMIT 1000 /* number of attempts (not time) */
933 759
934 760
935#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
936
937enum { 761enum {
938 MEASUREMENT_READY = (1 << 0), 762 MEASUREMENT_READY = (1 << 0),
939 MEASUREMENT_ACTIVE = (1 << 1), 763 MEASUREMENT_ACTIVE = (1 << 1),
940}; 764};
941 765
942#endif
943 766
944#define IWL_MAX_NUM_QUEUES 20 /* FIXME: do dynamic allocation */ 767#define IWL_MAX_NUM_QUEUES 20 /* FIXME: do dynamic allocation */
768#define IWL_CALIB_MAX 3
945 769
946struct iwl_priv { 770struct iwl_priv {
947 771
@@ -957,14 +781,13 @@ struct iwl_priv {
957 781
958 enum ieee80211_band band; 782 enum ieee80211_band band;
959 int alloc_rxb_skb; 783 int alloc_rxb_skb;
960 bool add_radiotap;
961 784
962 void (*rx_handlers[REPLY_MAX])(struct iwl_priv *priv, 785 void (*rx_handlers[REPLY_MAX])(struct iwl_priv *priv,
963 struct iwl4965_rx_mem_buffer *rxb); 786 struct iwl_rx_mem_buffer *rxb);
964 787
965 struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS]; 788 struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
966 789
967#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT 790#ifdef CONFIG_IWLAGN_SPECTRUM_MEASUREMENT
968 /* spectrum measurement report caching */ 791 /* spectrum measurement report caching */
969 struct iwl4965_spectrum_notification measure_report; 792 struct iwl4965_spectrum_notification measure_report;
970 u8 measurement_status; 793 u8 measurement_status;
@@ -985,6 +808,9 @@ struct iwl_priv {
985 s32 temperature; /* degrees Kelvin */ 808 s32 temperature; /* degrees Kelvin */
986 s32 last_temperature; 809 s32 last_temperature;
987 810
811 /* init calibration results */
812 struct iwl_calib_result calib_results[IWL_CALIB_MAX];
813
988 /* Scan related variables */ 814 /* Scan related variables */
989 unsigned long last_scan_jiffies; 815 unsigned long last_scan_jiffies;
990 unsigned long next_scan_jiffies; 816 unsigned long next_scan_jiffies;
@@ -995,7 +821,8 @@ struct iwl_priv {
995 int one_direct_scan; 821 int one_direct_scan;
996 u8 direct_ssid_len; 822 u8 direct_ssid_len;
997 u8 direct_ssid[IW_ESSID_MAX_SIZE]; 823 u8 direct_ssid[IW_ESSID_MAX_SIZE];
998 struct iwl4965_scan_cmd *scan; 824 struct iwl_scan_cmd *scan;
825 u32 scan_tx_ant[IEEE80211_NUM_BANDS];
999 826
1000 /* spinlock */ 827 /* spinlock */
1001 spinlock_t lock; /* protect general shared data */ 828 spinlock_t lock; /* protect general shared data */
@@ -1007,6 +834,9 @@ struct iwl_priv {
1007 834
1008 /* pci hardware address support */ 835 /* pci hardware address support */
1009 void __iomem *hw_base; 836 void __iomem *hw_base;
837 u32 hw_rev;
838 u32 hw_wa_rev;
839 u8 rev_id;
1010 840
1011 /* uCode images, save to reload in case of failure */ 841 /* uCode images, save to reload in case of failure */
1012 struct fw_desc ucode_code; /* runtime inst */ 842 struct fw_desc ucode_code; /* runtime inst */
@@ -1015,6 +845,8 @@ struct iwl_priv {
1015 struct fw_desc ucode_init; /* initialization inst */ 845 struct fw_desc ucode_init; /* initialization inst */
1016 struct fw_desc ucode_init_data; /* initialization data */ 846 struct fw_desc ucode_init_data; /* initialization data */
1017 struct fw_desc ucode_boot; /* bootstrap inst */ 847 struct fw_desc ucode_boot; /* bootstrap inst */
848 enum ucode_type ucode_type;
849 u8 ucode_write_complete; /* the image write is complete */
1018 850
1019 851
1020 struct iwl4965_rxon_time_cmd rxon_timing; 852 struct iwl4965_rxon_time_cmd rxon_timing;
@@ -1023,22 +855,22 @@ struct iwl_priv {
1023 * changed via explicit cast within the 855 * changed via explicit cast within the
1024 * routines that actually update the physical 856 * routines that actually update the physical
1025 * hardware */ 857 * hardware */
1026 const struct iwl4965_rxon_cmd active_rxon; 858 const struct iwl_rxon_cmd active_rxon;
1027 struct iwl4965_rxon_cmd staging_rxon; 859 struct iwl_rxon_cmd staging_rxon;
1028 860
1029 int error_recovering; 861 int error_recovering;
1030 struct iwl4965_rxon_cmd recovery_rxon; 862 struct iwl_rxon_cmd recovery_rxon;
1031 863
1032 /* 1st responses from initialize and runtime uCode images. 864 /* 1st responses from initialize and runtime uCode images.
1033 * 4965's initialize alive response contains some calibration data. */ 865 * 4965's initialize alive response contains some calibration data. */
1034 struct iwl4965_init_alive_resp card_alive_init; 866 struct iwl_init_alive_resp card_alive_init;
1035 struct iwl4965_alive_resp card_alive; 867 struct iwl_alive_resp card_alive;
1036#ifdef CONFIG_IWLWIFI_RFKILL 868#ifdef CONFIG_IWLWIFI_RFKILL
1037 struct iwl_rfkill_mngr rfkill_mngr; 869 struct rfkill *rfkill;
1038#endif 870#endif
1039 871
1040#ifdef CONFIG_IWLWIFI_LEDS 872#ifdef CONFIG_IWLWIFI_LEDS
1041 struct iwl4965_led led[IWL_LED_TRG_MAX]; 873 struct iwl_led led[IWL_LED_TRG_MAX];
1042 unsigned long last_blink_time; 874 unsigned long last_blink_time;
1043 u8 last_blink_rate; 875 u8 last_blink_rate;
1044 u8 allow_blinking; 876 u8 allow_blinking;
@@ -1050,23 +882,15 @@ struct iwl_priv {
1050 882
1051 u8 assoc_station_added; 883 u8 assoc_station_added;
1052 u8 use_ant_b_for_management_frame; /* Tx antenna selection */ 884 u8 use_ant_b_for_management_frame; /* Tx antenna selection */
1053 u8 valid_antenna; /* Bit mask of antennas actually connected */
1054#ifdef CONFIG_IWL4965_SENSITIVITY
1055 struct iwl4965_sensitivity_data sensitivity_data;
1056 struct iwl4965_chain_noise_data chain_noise_data;
1057 u8 start_calib; 885 u8 start_calib;
886 struct iwl_sensitivity_data sensitivity_data;
887 struct iwl_chain_noise_data chain_noise_data;
1058 __le16 sensitivity_tbl[HD_TABLE_SIZE]; 888 __le16 sensitivity_tbl[HD_TABLE_SIZE];
1059#endif /*CONFIG_IWL4965_SENSITIVITY*/
1060 889
1061#ifdef CONFIG_IWL4965_HT
1062 struct iwl_ht_info current_ht_config; 890 struct iwl_ht_info current_ht_config;
1063#endif
1064 u8 last_phy_res[100]; 891 u8 last_phy_res[100];
1065 892
1066 /* Rate scaling data */ 893 /* Rate scaling data */
1067 struct iwl4965_lq_mngr lq_mngr;
1068
1069 /* Rate scaling data */
1070 s8 data_retry_limit; 894 s8 data_retry_limit;
1071 u8 retry_rate; 895 u8 retry_rate;
1072 896
@@ -1075,10 +899,10 @@ struct iwl_priv {
1075 int activity_timer_active; 899 int activity_timer_active;
1076 900
1077 /* Rx and Tx DMA processing queues */ 901 /* Rx and Tx DMA processing queues */
1078 struct iwl4965_rx_queue rxq; 902 struct iwl_rx_queue rxq;
1079 struct iwl4965_tx_queue txq[IWL_MAX_NUM_QUEUES]; 903 struct iwl_tx_queue txq[IWL_MAX_NUM_QUEUES];
1080 unsigned long txq_ctx_active_msk; 904 unsigned long txq_ctx_active_msk;
1081 struct iwl4965_kw kw; /* keep warm address */ 905 struct iwl_kw kw; /* keep warm address */
1082 u32 scd_base_addr; /* scheduler sram base address */ 906 u32 scd_base_addr; /* scheduler sram base address */
1083 907
1084 unsigned long status; 908 unsigned long status;
@@ -1092,9 +916,9 @@ struct iwl_priv {
1092 u64 bytes; 916 u64 bytes;
1093 } tx_stats[3], rx_stats[3]; 917 } tx_stats[3], rx_stats[3];
1094 918
1095 struct iwl4965_power_mgr power_data; 919 struct iwl_power_mgr power_data;
1096 920
1097 struct iwl4965_notif_statistics statistics; 921 struct iwl_notif_statistics statistics;
1098 unsigned long last_statistics_time; 922 unsigned long last_statistics_time;
1099 923
1100 /* context information */ 924 /* context information */
@@ -1111,7 +935,7 @@ struct iwl_priv {
1111 /*station table variables */ 935 /*station table variables */
1112 spinlock_t sta_lock; 936 spinlock_t sta_lock;
1113 int num_stations; 937 int num_stations;
1114 struct iwl4965_station_entry stations[IWL_STATION_COUNT]; 938 struct iwl_station_entry stations[IWL_STATION_COUNT];
1115 struct iwl_wep_key wep_keys[WEP_KEYS_MAX]; 939 struct iwl_wep_key wep_keys[WEP_KEYS_MAX];
1116 u8 default_wep_key; 940 u8 default_wep_key;
1117 u8 key_mapping_key; 941 u8 key_mapping_key;
@@ -1122,24 +946,15 @@ struct iwl_priv {
1122 946
1123 u8 mac80211_registered; 947 u8 mac80211_registered;
1124 948
1125 u32 notif_missed_beacons;
1126
1127 /* Rx'd packet timing information */ 949 /* Rx'd packet timing information */
1128 u32 last_beacon_time; 950 u32 last_beacon_time;
1129 u64 last_tsf; 951 u64 last_tsf;
1130 952
1131 /* Duplicate packet detection */
1132 u16 last_seq_num;
1133 u16 last_frag_num;
1134 unsigned long last_packet_time;
1135
1136 /* Hash table for finding stations in IBSS network */
1137 struct list_head ibss_mac_hash[IWL_IBSS_MAC_HASH_SIZE];
1138
1139 /* eeprom */ 953 /* eeprom */
1140 struct iwl4965_eeprom eeprom; 954 u8 *eeprom;
955 struct iwl_eeprom_calib_info *calib_info;
1141 956
1142 enum ieee80211_if_types iw_mode; 957 enum nl80211_iftype iw_mode;
1143 958
1144 struct sk_buff *ibss_beacon; 959 struct sk_buff *ibss_beacon;
1145 960
@@ -1151,6 +966,7 @@ struct iwl_priv {
1151 struct iwl_hw_params hw_params; 966 struct iwl_hw_params hw_params;
1152 /* driver/uCode shared Tx Byte Counts and Rx status */ 967 /* driver/uCode shared Tx Byte Counts and Rx status */
1153 void *shared_virt; 968 void *shared_virt;
969 int rb_closed_offset;
1154 /* Physical Pointer to Tx Byte Counts and Rx status */ 970 /* Physical Pointer to Tx Byte Counts and Rx status */
1155 dma_addr_t shared_phys; 971 dma_addr_t shared_phys;
1156 972
@@ -1158,9 +974,8 @@ struct iwl_priv {
1158 * hardware */ 974 * hardware */
1159 u16 assoc_id; 975 u16 assoc_id;
1160 u16 assoc_capability; 976 u16 assoc_capability;
1161 u8 ps_mode;
1162 977
1163 struct iwl4965_qos_info qos_data; 978 struct iwl_qos_info qos_data;
1164 979
1165 struct workqueue_struct *workqueue; 980 struct workqueue_struct *workqueue;
1166 981
@@ -1176,20 +991,17 @@ struct iwl_priv {
1176 struct work_struct report_work; 991 struct work_struct report_work;
1177 struct work_struct request_scan; 992 struct work_struct request_scan;
1178 struct work_struct beacon_update; 993 struct work_struct beacon_update;
994 struct work_struct set_monitor;
1179 995
1180 struct tasklet_struct irq_tasklet; 996 struct tasklet_struct irq_tasklet;
1181 997
998 struct delayed_work set_power_save;
1182 struct delayed_work init_alive_start; 999 struct delayed_work init_alive_start;
1183 struct delayed_work alive_start; 1000 struct delayed_work alive_start;
1184 struct delayed_work activity_timer;
1185 struct delayed_work thermal_periodic;
1186 struct delayed_work gather_stats;
1187 struct delayed_work scan_check; 1001 struct delayed_work scan_check;
1188 struct delayed_work post_associate; 1002 /* TX Power */
1189 1003 s8 tx_power_user_lmt;
1190#define IWL_DEFAULT_TX_POWER 0x0F 1004 s8 tx_power_channel_lmt;
1191 s8 user_txpower_limit;
1192 s8 max_channel_txpower_limit;
1193 1005
1194#ifdef CONFIG_PM 1006#ifdef CONFIG_PM
1195 u32 pm_state[16]; 1007 u32 pm_state[16];
@@ -1197,6 +1009,7 @@ struct iwl_priv {
1197 1009
1198#ifdef CONFIG_IWLWIFI_DEBUG 1010#ifdef CONFIG_IWLWIFI_DEBUG
1199 /* debugging info */ 1011 /* debugging info */
1012 u32 debug_level;
1200 u32 framecnt_to_us; 1013 u32 framecnt_to_us;
1201 atomic_t restrict_refcnt; 1014 atomic_t restrict_refcnt;
1202#ifdef CONFIG_IWLWIFI_DEBUGFS 1015#ifdef CONFIG_IWLWIFI_DEBUGFS
@@ -1206,12 +1019,40 @@ struct iwl_priv {
1206#endif /* CONFIG_IWLWIFI_DEBUG */ 1019#endif /* CONFIG_IWLWIFI_DEBUG */
1207 1020
1208 struct work_struct txpower_work; 1021 struct work_struct txpower_work;
1209#ifdef CONFIG_IWL4965_SENSITIVITY 1022 u32 disable_sens_cal;
1210 struct work_struct sensitivity_work; 1023 u32 disable_chain_noise_cal;
1211#endif 1024 u32 disable_tx_power_cal;
1025 struct work_struct run_time_calib_work;
1212 struct timer_list statistics_periodic; 1026 struct timer_list statistics_periodic;
1213}; /*iwl_priv */ 1027}; /*iwl_priv */
1214 1028
1029static inline void iwl_txq_ctx_activate(struct iwl_priv *priv, int txq_id)
1030{
1031 set_bit(txq_id, &priv->txq_ctx_active_msk);
1032}
1033
1034static inline void iwl_txq_ctx_deactivate(struct iwl_priv *priv, int txq_id)
1035{
1036 clear_bit(txq_id, &priv->txq_ctx_active_msk);
1037}
1038
1039#ifdef CONFIG_IWLWIFI_DEBUG
1040const char *iwl_get_tx_fail_reason(u32 status);
1041#else
1042static inline const char *iwl_get_tx_fail_reason(u32 status) { return ""; }
1043#endif
1044
1045
1046static inline struct ieee80211_hdr *iwl_tx_queue_get_hdr(struct iwl_priv *priv,
1047 int txq_id, int idx)
1048{
1049 if (priv->txq[txq_id].txb[idx].skb[0])
1050 return (struct ieee80211_hdr *)priv->txq[txq_id].
1051 txb[idx].skb[0]->data;
1052 return NULL;
1053}
1054
1055
1215static inline int iwl_is_associated(struct iwl_priv *priv) 1056static inline int iwl_is_associated(struct iwl_priv *priv)
1216{ 1057{
1217 return (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) ? 1 : 0; 1058 return (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) ? 1 : 0;
@@ -1224,11 +1065,6 @@ static inline int is_channel_valid(const struct iwl_channel_info *ch_info)
1224 return (ch_info->flags & EEPROM_CHANNEL_VALID) ? 1 : 0; 1065 return (ch_info->flags & EEPROM_CHANNEL_VALID) ? 1 : 0;
1225} 1066}
1226 1067
1227static inline int is_channel_narrow(const struct iwl_channel_info *ch_info)
1228{
1229 return (ch_info->flags & EEPROM_CHANNEL_NARROW) ? 1 : 0;
1230}
1231
1232static inline int is_channel_radar(const struct iwl_channel_info *ch_info) 1068static inline int is_channel_radar(const struct iwl_channel_info *ch_info)
1233{ 1069{
1234 return (ch_info->flags & EEPROM_CHANNEL_RADAR) ? 1 : 0; 1070 return (ch_info->flags & EEPROM_CHANNEL_RADAR) ? 1 : 0;
@@ -1254,9 +1090,26 @@ static inline int is_channel_ibss(const struct iwl_channel_info *ch)
1254 return ((ch->flags & EEPROM_CHANNEL_IBSS)) ? 1 : 0; 1090 return ((ch->flags & EEPROM_CHANNEL_IBSS)) ? 1 : 0;
1255} 1091}
1256 1092
1093#ifdef CONFIG_IWLWIFI_DEBUG
1094static inline void iwl_print_hex_dump(struct iwl_priv *priv, int level,
1095 void *p, u32 len)
1096{
1097 if (!(priv->debug_level & level))
1098 return;
1099
1100 print_hex_dump(KERN_DEBUG, "iwl data: ", DUMP_PREFIX_OFFSET, 16, 1,
1101 p, len, 1);
1102}
1103#else
1104static inline void iwl_print_hex_dump(struct iwl_priv *priv, int level,
1105 void *p, u32 len)
1106{
1107}
1108#endif
1109
1257extern const struct iwl_channel_info *iwl_get_channel_info( 1110extern const struct iwl_channel_info *iwl_get_channel_info(
1258 const struct iwl_priv *priv, enum ieee80211_band band, u16 channel); 1111 const struct iwl_priv *priv, enum ieee80211_band band, u16 channel);
1259 1112
1260/* Requires full declaration of iwl_priv before including */ 1113/* Requires full declaration of iwl_priv before including */
1261 1114
1262#endif /* __iwl4965_4965_h__ */ 1115#endif /* __iwl_dev_h__ */
diff --git a/drivers/net/wireless/iwlwifi/iwl-eeprom.c b/drivers/net/wireless/iwlwifi/iwl-eeprom.c
index a07d5dcb7abc..37155755efc5 100644
--- a/drivers/net/wireless/iwlwifi/iwl-eeprom.c
+++ b/drivers/net/wireless/iwlwifi/iwl-eeprom.c
@@ -63,13 +63,12 @@
63 63
64#include <linux/kernel.h> 64#include <linux/kernel.h>
65#include <linux/module.h> 65#include <linux/module.h>
66#include <linux/version.h>
67#include <linux/init.h> 66#include <linux/init.h>
68 67
69#include <net/mac80211.h> 68#include <net/mac80211.h>
70 69
71#include "iwl-4965-commands.h" 70#include "iwl-commands.h"
72#include "iwl-4965.h" 71#include "iwl-dev.h"
73#include "iwl-core.h" 72#include "iwl-core.h"
74#include "iwl-debug.h" 73#include "iwl-debug.h"
75#include "iwl-eeprom.h" 74#include "iwl-eeprom.h"
@@ -146,7 +145,7 @@ int iwlcore_eeprom_verify_signature(struct iwl_priv *priv)
146{ 145{
147 u32 gp = iwl_read32(priv, CSR_EEPROM_GP); 146 u32 gp = iwl_read32(priv, CSR_EEPROM_GP);
148 if ((gp & CSR_EEPROM_GP_VALID_MSK) == CSR_EEPROM_GP_BAD_SIGNATURE) { 147 if ((gp & CSR_EEPROM_GP_VALID_MSK) == CSR_EEPROM_GP_BAD_SIGNATURE) {
149 IWL_ERROR("EEPROM not found, EEPROM_GP=0x%08x", gp); 148 IWL_ERROR("EEPROM not found, EEPROM_GP=0x%08x\n", gp);
150 return -ENOENT; 149 return -ENOENT;
151 } 150 }
152 return 0; 151 return 0;
@@ -193,6 +192,12 @@ void iwlcore_eeprom_release_semaphore(struct iwl_priv *priv)
193} 192}
194EXPORT_SYMBOL(iwlcore_eeprom_release_semaphore); 193EXPORT_SYMBOL(iwlcore_eeprom_release_semaphore);
195 194
195const u8 *iwlcore_eeprom_query_addr(const struct iwl_priv *priv, size_t offset)
196{
197 BUG_ON(offset >= priv->cfg->eeprom_size);
198 return &priv->eeprom[offset];
199}
200EXPORT_SYMBOL(iwlcore_eeprom_query_addr);
196 201
197/** 202/**
198 * iwl_eeprom_init - read EEPROM contents 203 * iwl_eeprom_init - read EEPROM contents
@@ -203,30 +208,35 @@ EXPORT_SYMBOL(iwlcore_eeprom_release_semaphore);
203 */ 208 */
204int iwl_eeprom_init(struct iwl_priv *priv) 209int iwl_eeprom_init(struct iwl_priv *priv)
205{ 210{
206 u16 *e = (u16 *)&priv->eeprom; 211 u16 *e;
207 u32 gp = iwl_read32(priv, CSR_EEPROM_GP); 212 u32 gp = iwl_read32(priv, CSR_EEPROM_GP);
208 u32 r; 213 u32 r;
209 int sz = sizeof(priv->eeprom); 214 int sz = priv->cfg->eeprom_size;
210 int ret; 215 int ret;
211 int i; 216 int i;
212 u16 addr; 217 u16 addr;
213 218
214 /* The EEPROM structure has several padding buffers within it 219 /* allocate eeprom */
215 * and when adding new EEPROM maps is subject to programmer errors 220 priv->eeprom = kzalloc(sz, GFP_KERNEL);
216 * which may be very difficult to identify without explicitly 221 if (!priv->eeprom) {
217 * checking the resulting size of the eeprom map. */ 222 ret = -ENOMEM;
218 BUILD_BUG_ON(sizeof(priv->eeprom) != IWL_EEPROM_IMAGE_SIZE); 223 goto alloc_err;
224 }
225 e = (u16 *)priv->eeprom;
219 226
220 if ((gp & CSR_EEPROM_GP_VALID_MSK) == CSR_EEPROM_GP_BAD_SIGNATURE) { 227 ret = priv->cfg->ops->lib->eeprom_ops.verify_signature(priv);
221 IWL_ERROR("EEPROM not found, EEPROM_GP=0x%08x", gp); 228 if (ret < 0) {
222 return -ENOENT; 229 IWL_ERROR("EEPROM not found, EEPROM_GP=0x%08x\n", gp);
230 ret = -ENOENT;
231 goto err;
223 } 232 }
224 233
225 /* Make sure driver (instead of uCode) is allowed to read EEPROM */ 234 /* Make sure driver (instead of uCode) is allowed to read EEPROM */
226 ret = priv->cfg->ops->lib->eeprom_ops.acquire_semaphore(priv); 235 ret = priv->cfg->ops->lib->eeprom_ops.acquire_semaphore(priv);
227 if (ret < 0) { 236 if (ret < 0) {
228 IWL_ERROR("Failed to acquire EEPROM semaphore.\n"); 237 IWL_ERROR("Failed to acquire EEPROM semaphore.\n");
229 return -ENOENT; 238 ret = -ENOENT;
239 goto err;
230 } 240 }
231 241
232 /* eeprom is an array of 16bit values */ 242 /* eeprom is an array of 16bit values */
@@ -243,68 +253,104 @@ int iwl_eeprom_init(struct iwl_priv *priv)
243 } 253 }
244 254
245 if (!(r & CSR_EEPROM_REG_READ_VALID_MSK)) { 255 if (!(r & CSR_EEPROM_REG_READ_VALID_MSK)) {
246 IWL_ERROR("Time out reading EEPROM[%d]", addr); 256 IWL_ERROR("Time out reading EEPROM[%d]\n", addr);
247 ret = -ETIMEDOUT; 257 ret = -ETIMEDOUT;
248 goto done; 258 goto done;
249 } 259 }
250 e[addr / 2] = le16_to_cpu((__force __le16)(r >> 16)); 260 e[addr / 2] = le16_to_cpu((__force __le16)(r >> 16));
251 } 261 }
252 ret = 0; 262 ret = 0;
253
254done: 263done:
255 priv->cfg->ops->lib->eeprom_ops.release_semaphore(priv); 264 priv->cfg->ops->lib->eeprom_ops.release_semaphore(priv);
265err:
266 if (ret)
267 kfree(priv->eeprom);
268alloc_err:
256 return ret; 269 return ret;
257} 270}
258EXPORT_SYMBOL(iwl_eeprom_init); 271EXPORT_SYMBOL(iwl_eeprom_init);
259 272
273void iwl_eeprom_free(struct iwl_priv *priv)
274{
275 kfree(priv->eeprom);
276 priv->eeprom = NULL;
277}
278EXPORT_SYMBOL(iwl_eeprom_free);
279
280int iwl_eeprom_check_version(struct iwl_priv *priv)
281{
282 return priv->cfg->ops->lib->eeprom_ops.check_version(priv);
283}
284EXPORT_SYMBOL(iwl_eeprom_check_version);
285
286const u8 *iwl_eeprom_query_addr(const struct iwl_priv *priv, size_t offset)
287{
288 return priv->cfg->ops->lib->eeprom_ops.query_addr(priv, offset);
289}
290EXPORT_SYMBOL(iwl_eeprom_query_addr);
291
292u16 iwl_eeprom_query16(const struct iwl_priv *priv, size_t offset)
293{
294 return (u16)priv->eeprom[offset] | ((u16)priv->eeprom[offset + 1] << 8);
295}
296EXPORT_SYMBOL(iwl_eeprom_query16);
260 297
261void iwl_eeprom_get_mac(const struct iwl_priv *priv, u8 *mac) 298void iwl_eeprom_get_mac(const struct iwl_priv *priv, u8 *mac)
262{ 299{
263 memcpy(mac, priv->eeprom.mac_address, 6); 300 const u8 *addr = priv->cfg->ops->lib->eeprom_ops.query_addr(priv,
301 EEPROM_MAC_ADDRESS);
302 memcpy(mac, addr, ETH_ALEN);
264} 303}
265EXPORT_SYMBOL(iwl_eeprom_get_mac); 304EXPORT_SYMBOL(iwl_eeprom_get_mac);
266 305
267static void iwl_init_band_reference(const struct iwl_priv *priv, 306static void iwl_init_band_reference(const struct iwl_priv *priv,
268 int band, 307 int eep_band, int *eeprom_ch_count,
269 int *eeprom_ch_count, 308 const struct iwl_eeprom_channel **eeprom_ch_info,
270 const struct iwl4965_eeprom_channel 309 const u8 **eeprom_ch_index)
271 **eeprom_ch_info,
272 const u8 **eeprom_ch_index)
273{ 310{
274 switch (band) { 311 u32 offset = priv->cfg->ops->lib->
312 eeprom_ops.regulatory_bands[eep_band - 1];
313 switch (eep_band) {
275 case 1: /* 2.4GHz band */ 314 case 1: /* 2.4GHz band */
276 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_1); 315 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_1);
277 *eeprom_ch_info = priv->eeprom.band_1_channels; 316 *eeprom_ch_info = (struct iwl_eeprom_channel *)
317 iwl_eeprom_query_addr(priv, offset);
278 *eeprom_ch_index = iwl_eeprom_band_1; 318 *eeprom_ch_index = iwl_eeprom_band_1;
279 break; 319 break;
280 case 2: /* 4.9GHz band */ 320 case 2: /* 4.9GHz band */
281 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_2); 321 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_2);
282 *eeprom_ch_info = priv->eeprom.band_2_channels; 322 *eeprom_ch_info = (struct iwl_eeprom_channel *)
323 iwl_eeprom_query_addr(priv, offset);
283 *eeprom_ch_index = iwl_eeprom_band_2; 324 *eeprom_ch_index = iwl_eeprom_band_2;
284 break; 325 break;
285 case 3: /* 5.2GHz band */ 326 case 3: /* 5.2GHz band */
286 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_3); 327 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_3);
287 *eeprom_ch_info = priv->eeprom.band_3_channels; 328 *eeprom_ch_info = (struct iwl_eeprom_channel *)
329 iwl_eeprom_query_addr(priv, offset);
288 *eeprom_ch_index = iwl_eeprom_band_3; 330 *eeprom_ch_index = iwl_eeprom_band_3;
289 break; 331 break;
290 case 4: /* 5.5GHz band */ 332 case 4: /* 5.5GHz band */
291 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_4); 333 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_4);
292 *eeprom_ch_info = priv->eeprom.band_4_channels; 334 *eeprom_ch_info = (struct iwl_eeprom_channel *)
335 iwl_eeprom_query_addr(priv, offset);
293 *eeprom_ch_index = iwl_eeprom_band_4; 336 *eeprom_ch_index = iwl_eeprom_band_4;
294 break; 337 break;
295 case 5: /* 5.7GHz band */ 338 case 5: /* 5.7GHz band */
296 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_5); 339 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_5);
297 *eeprom_ch_info = priv->eeprom.band_5_channels; 340 *eeprom_ch_info = (struct iwl_eeprom_channel *)
341 iwl_eeprom_query_addr(priv, offset);
298 *eeprom_ch_index = iwl_eeprom_band_5; 342 *eeprom_ch_index = iwl_eeprom_band_5;
299 break; 343 break;
300 case 6: /* 2.4GHz FAT channels */ 344 case 6: /* 2.4GHz FAT channels */
301 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_6); 345 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_6);
302 *eeprom_ch_info = priv->eeprom.band_24_channels; 346 *eeprom_ch_info = (struct iwl_eeprom_channel *)
347 iwl_eeprom_query_addr(priv, offset);
303 *eeprom_ch_index = iwl_eeprom_band_6; 348 *eeprom_ch_index = iwl_eeprom_band_6;
304 break; 349 break;
305 case 7: /* 5 GHz FAT channels */ 350 case 7: /* 5 GHz FAT channels */
306 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_7); 351 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_7);
307 *eeprom_ch_info = priv->eeprom.band_52_channels; 352 *eeprom_ch_info = (struct iwl_eeprom_channel *)
353 iwl_eeprom_query_addr(priv, offset);
308 *eeprom_ch_index = iwl_eeprom_band_7; 354 *eeprom_ch_index = iwl_eeprom_band_7;
309 break; 355 break;
310 default: 356 default:
@@ -317,13 +363,13 @@ static void iwl_init_band_reference(const struct iwl_priv *priv,
317 ? # x " " : "") 363 ? # x " " : "")
318 364
319/** 365/**
320 * iwl4965_set_fat_chan_info - Copy fat channel info into driver's priv. 366 * iwl_set_fat_chan_info - Copy fat channel info into driver's priv.
321 * 367 *
322 * Does not set up a command, or touch hardware. 368 * Does not set up a command, or touch hardware.
323 */ 369 */
324static int iwl4965_set_fat_chan_info(struct iwl_priv *priv, 370static int iwl_set_fat_chan_info(struct iwl_priv *priv,
325 enum ieee80211_band band, u16 channel, 371 enum ieee80211_band band, u16 channel,
326 const struct iwl4965_eeprom_channel *eeprom_ch, 372 const struct iwl_eeprom_channel *eeprom_ch,
327 u8 fat_extension_channel) 373 u8 fat_extension_channel)
328{ 374{
329 struct iwl_channel_info *ch_info; 375 struct iwl_channel_info *ch_info;
@@ -334,8 +380,8 @@ static int iwl4965_set_fat_chan_info(struct iwl_priv *priv,
334 if (!is_channel_valid(ch_info)) 380 if (!is_channel_valid(ch_info))
335 return -1; 381 return -1;
336 382
337 IWL_DEBUG_INFO("FAT Ch. %d [%sGHz] %s%s%s%s%s%s(0x%02x" 383 IWL_DEBUG_INFO("FAT Ch. %d [%sGHz] %s%s%s%s%s(0x%02x %ddBm):"
338 " %ddBm): Ad-Hoc %ssupported\n", 384 " Ad-Hoc %ssupported\n",
339 ch_info->channel, 385 ch_info->channel,
340 is_channel_a_band(ch_info) ? 386 is_channel_a_band(ch_info) ?
341 "5.2" : "2.4", 387 "5.2" : "2.4",
@@ -343,7 +389,6 @@ static int iwl4965_set_fat_chan_info(struct iwl_priv *priv,
343 CHECK_AND_PRINT(ACTIVE), 389 CHECK_AND_PRINT(ACTIVE),
344 CHECK_AND_PRINT(RADAR), 390 CHECK_AND_PRINT(RADAR),
345 CHECK_AND_PRINT(WIDE), 391 CHECK_AND_PRINT(WIDE),
346 CHECK_AND_PRINT(NARROW),
347 CHECK_AND_PRINT(DFS), 392 CHECK_AND_PRINT(DFS),
348 eeprom_ch->flags, 393 eeprom_ch->flags,
349 eeprom_ch->max_power_avg, 394 eeprom_ch->max_power_avg,
@@ -372,7 +417,7 @@ int iwl_init_channel_map(struct iwl_priv *priv)
372{ 417{
373 int eeprom_ch_count = 0; 418 int eeprom_ch_count = 0;
374 const u8 *eeprom_ch_index = NULL; 419 const u8 *eeprom_ch_index = NULL;
375 const struct iwl4965_eeprom_channel *eeprom_ch_info = NULL; 420 const struct iwl_eeprom_channel *eeprom_ch_info = NULL;
376 int band, ch; 421 int band, ch;
377 struct iwl_channel_info *ch_info; 422 struct iwl_channel_info *ch_info;
378 423
@@ -381,12 +426,6 @@ int iwl_init_channel_map(struct iwl_priv *priv)
381 return 0; 426 return 0;
382 } 427 }
383 428
384 if (priv->eeprom.version < 0x2f) {
385 IWL_WARNING("Unsupported EEPROM version: 0x%04X\n",
386 priv->eeprom.version);
387 return -EINVAL;
388 }
389
390 IWL_DEBUG_INFO("Initializing regulatory info from EEPROM\n"); 429 IWL_DEBUG_INFO("Initializing regulatory info from EEPROM\n");
391 430
392 priv->channel_count = 431 priv->channel_count =
@@ -429,6 +468,11 @@ int iwl_init_channel_map(struct iwl_priv *priv)
429 /* Copy the run-time flags so they are there even on 468 /* Copy the run-time flags so they are there even on
430 * invalid channels */ 469 * invalid channels */
431 ch_info->flags = eeprom_ch_info[ch].flags; 470 ch_info->flags = eeprom_ch_info[ch].flags;
471 /* First write that fat is not enabled, and then enable
472 * one by one */
473 ch_info->fat_extension_channel =
474 (IEEE80211_CHAN_NO_FAT_ABOVE |
475 IEEE80211_CHAN_NO_FAT_BELOW);
432 476
433 if (!(is_channel_valid(ch_info))) { 477 if (!(is_channel_valid(ch_info))) {
434 IWL_DEBUG_INFO("Ch. %d Flags %x [%sGHz] - " 478 IWL_DEBUG_INFO("Ch. %d Flags %x [%sGHz] - "
@@ -447,8 +491,8 @@ int iwl_init_channel_map(struct iwl_priv *priv)
447 ch_info->scan_power = eeprom_ch_info[ch].max_power_avg; 491 ch_info->scan_power = eeprom_ch_info[ch].max_power_avg;
448 ch_info->min_power = 0; 492 ch_info->min_power = 0;
449 493
450 IWL_DEBUG_INFO("Ch. %d [%sGHz] %s%s%s%s%s%s%s(0x%02x" 494 IWL_DEBUG_INFO("Ch. %d [%sGHz] %s%s%s%s%s%s(0x%02x %ddBm):"
451 " %ddBm): Ad-Hoc %ssupported\n", 495 " Ad-Hoc %ssupported\n",
452 ch_info->channel, 496 ch_info->channel,
453 is_channel_a_band(ch_info) ? 497 is_channel_a_band(ch_info) ?
454 "5.2" : "2.4", 498 "5.2" : "2.4",
@@ -457,7 +501,6 @@ int iwl_init_channel_map(struct iwl_priv *priv)
457 CHECK_AND_PRINT_I(ACTIVE), 501 CHECK_AND_PRINT_I(ACTIVE),
458 CHECK_AND_PRINT_I(RADAR), 502 CHECK_AND_PRINT_I(RADAR),
459 CHECK_AND_PRINT_I(WIDE), 503 CHECK_AND_PRINT_I(WIDE),
460 CHECK_AND_PRINT_I(NARROW),
461 CHECK_AND_PRINT_I(DFS), 504 CHECK_AND_PRINT_I(DFS),
462 eeprom_ch_info[ch].flags, 505 eeprom_ch_info[ch].flags,
463 eeprom_ch_info[ch].max_power_avg, 506 eeprom_ch_info[ch].max_power_avg,
@@ -470,8 +513,8 @@ int iwl_init_channel_map(struct iwl_priv *priv)
470 /* Set the user_txpower_limit to the highest power 513 /* Set the user_txpower_limit to the highest power
471 * supported by any channel */ 514 * supported by any channel */
472 if (eeprom_ch_info[ch].max_power_avg > 515 if (eeprom_ch_info[ch].max_power_avg >
473 priv->user_txpower_limit) 516 priv->tx_power_user_lmt)
474 priv->user_txpower_limit = 517 priv->tx_power_user_lmt =
475 eeprom_ch_info[ch].max_power_avg; 518 eeprom_ch_info[ch].max_power_avg;
476 519
477 ch_info++; 520 ch_info++;
@@ -494,24 +537,26 @@ int iwl_init_channel_map(struct iwl_priv *priv)
494 for (ch = 0; ch < eeprom_ch_count; ch++) { 537 for (ch = 0; ch < eeprom_ch_count; ch++) {
495 538
496 if ((band == 6) && 539 if ((band == 6) &&
497 ((eeprom_ch_index[ch] == 5) || 540 ((eeprom_ch_index[ch] == 5) ||
498 (eeprom_ch_index[ch] == 6) || 541 (eeprom_ch_index[ch] == 6) ||
499 (eeprom_ch_index[ch] == 7))) 542 (eeprom_ch_index[ch] == 7)))
500 fat_extension_chan = HT_IE_EXT_CHANNEL_MAX; 543 /* both are allowed: above and below */
544 fat_extension_chan = 0;
501 else 545 else
502 fat_extension_chan = HT_IE_EXT_CHANNEL_ABOVE; 546 fat_extension_chan =
547 IEEE80211_CHAN_NO_FAT_BELOW;
503 548
504 /* Set up driver's info for lower half */ 549 /* Set up driver's info for lower half */
505 iwl4965_set_fat_chan_info(priv, ieeeband, 550 iwl_set_fat_chan_info(priv, ieeeband,
506 eeprom_ch_index[ch], 551 eeprom_ch_index[ch],
507 &(eeprom_ch_info[ch]), 552 &(eeprom_ch_info[ch]),
508 fat_extension_chan); 553 fat_extension_chan);
509 554
510 /* Set up driver's info for upper half */ 555 /* Set up driver's info for upper half */
511 iwl4965_set_fat_chan_info(priv, ieeeband, 556 iwl_set_fat_chan_info(priv, ieeeband,
512 (eeprom_ch_index[ch] + 4), 557 (eeprom_ch_index[ch] + 4),
513 &(eeprom_ch_info[ch]), 558 &(eeprom_ch_info[ch]),
514 HT_IE_EXT_CHANNEL_BELOW); 559 IEEE80211_CHAN_NO_FAT_ABOVE);
515 } 560 }
516 } 561 }
517 562
@@ -520,23 +565,21 @@ int iwl_init_channel_map(struct iwl_priv *priv)
520EXPORT_SYMBOL(iwl_init_channel_map); 565EXPORT_SYMBOL(iwl_init_channel_map);
521 566
522/* 567/*
523 * iwl_free_channel_map - undo allocations in iwl4965_init_channel_map 568 * iwl_free_channel_map - undo allocations in iwl_init_channel_map
524 */ 569 */
525void iwl_free_channel_map(struct iwl_priv *priv) 570void iwl_free_channel_map(struct iwl_priv *priv)
526{ 571{
527 kfree(priv->channel_info); 572 kfree(priv->channel_info);
528 priv->channel_count = 0; 573 priv->channel_count = 0;
529} 574}
530EXPORT_SYMBOL(iwl_free_channel_map);
531 575
532/** 576/**
533 * iwl_get_channel_info - Find driver's private channel info 577 * iwl_get_channel_info - Find driver's private channel info
534 * 578 *
535 * Based on band and channel number. 579 * Based on band and channel number.
536 */ 580 */
537const struct iwl_channel_info *iwl_get_channel_info( 581const struct iwl_channel_info *iwl_get_channel_info(const struct iwl_priv *priv,
538 const struct iwl_priv *priv, 582 enum ieee80211_band band, u16 channel)
539 enum ieee80211_band band, u16 channel)
540{ 583{
541 int i; 584 int i;
542 585
diff --git a/drivers/net/wireless/iwlwifi/iwl-eeprom.h b/drivers/net/wireless/iwlwifi/iwl-eeprom.h
index bd0a042ca77f..d3a2a5b4ac56 100644
--- a/drivers/net/wireless/iwlwifi/iwl-eeprom.h
+++ b/drivers/net/wireless/iwlwifi/iwl-eeprom.h
@@ -106,7 +106,7 @@ enum {
106 EEPROM_CHANNEL_ACTIVE = (1 << 3), /* active scanning allowed */ 106 EEPROM_CHANNEL_ACTIVE = (1 << 3), /* active scanning allowed */
107 EEPROM_CHANNEL_RADAR = (1 << 4), /* radar detection required */ 107 EEPROM_CHANNEL_RADAR = (1 << 4), /* radar detection required */
108 EEPROM_CHANNEL_WIDE = (1 << 5), /* 20 MHz channel okay */ 108 EEPROM_CHANNEL_WIDE = (1 << 5), /* 20 MHz channel okay */
109 EEPROM_CHANNEL_NARROW = (1 << 6), /* 10 MHz channel (not used) */ 109 /* Bit 6 Reserved (was Narrow Channel) */
110 EEPROM_CHANNEL_DFS = (1 << 7), /* dynamic freq selection candidate */ 110 EEPROM_CHANNEL_DFS = (1 << 7), /* dynamic freq selection candidate */
111}; 111};
112 112
@@ -116,7 +116,7 @@ enum {
116 116
117/* *regulatory* channel data format in eeprom, one for each channel. 117/* *regulatory* channel data format in eeprom, one for each channel.
118 * There are separate entries for FAT (40 MHz) vs. normal (20 MHz) channels. */ 118 * There are separate entries for FAT (40 MHz) vs. normal (20 MHz) channels. */
119struct iwl4965_eeprom_channel { 119struct iwl_eeprom_channel {
120 u8 flags; /* EEPROM_CHANNEL_* flags copied from EEPROM */ 120 u8 flags; /* EEPROM_CHANNEL_* flags copied from EEPROM */
121 s8 max_power_avg; /* max power (dBm) on this chnl, limit 31 */ 121 s8 max_power_avg; /* max power (dBm) on this chnl, limit 31 */
122} __attribute__ ((packed)); 122} __attribute__ ((packed));
@@ -131,17 +131,55 @@ struct iwl4965_eeprom_channel {
131 * each of 3 target output levels */ 131 * each of 3 target output levels */
132#define EEPROM_TX_POWER_MEASUREMENTS (3) 132#define EEPROM_TX_POWER_MEASUREMENTS (3)
133 133
134#define EEPROM_4965_TX_POWER_VERSION (2) 134/* 4965 Specific */
135/* 4965 driver does not work with txpower calibration version < 5 */
136#define EEPROM_4965_TX_POWER_VERSION (5)
137#define EEPROM_4965_EEPROM_VERSION (0x2f)
138#define EEPROM_4965_CALIB_VERSION_OFFSET (2*0xB6) /* 2 bytes */
139#define EEPROM_4965_CALIB_TXPOWER_OFFSET (2*0xE8) /* 48 bytes */
140#define EEPROM_4965_BOARD_REVISION (2*0x4F) /* 2 bytes */
141#define EEPROM_4965_BOARD_PBA (2*0x56+1) /* 9 bytes */
142
143/* 5000 Specific */
144#define EEPROM_5000_TX_POWER_VERSION (4)
145#define EEPROM_5000_EEPROM_VERSION (0x11A)
146
147/*5000 calibrations */
148#define EEPROM_5000_CALIB_ALL (INDIRECT_ADDRESS | INDIRECT_CALIBRATION)
149#define EEPROM_5000_XTAL ((2*0x128) | EEPROM_5000_CALIB_ALL)
150
151/* 5000 links */
152#define EEPROM_5000_LINK_HOST (2*0x64)
153#define EEPROM_5000_LINK_GENERAL (2*0x65)
154#define EEPROM_5000_LINK_REGULATORY (2*0x66)
155#define EEPROM_5000_LINK_CALIBRATION (2*0x67)
156#define EEPROM_5000_LINK_PROCESS_ADJST (2*0x68)
157#define EEPROM_5000_LINK_OTHERS (2*0x69)
158
159/* 5000 regulatory - indirect access */
160#define EEPROM_5000_REG_SKU_ID ((0x02)\
161 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 4 bytes */
162#define EEPROM_5000_REG_BAND_1_CHANNELS ((0x08)\
163 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 28 bytes */
164#define EEPROM_5000_REG_BAND_2_CHANNELS ((0x26)\
165 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 26 bytes */
166#define EEPROM_5000_REG_BAND_3_CHANNELS ((0x42)\
167 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 24 bytes */
168#define EEPROM_5000_REG_BAND_4_CHANNELS ((0x5C)\
169 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 22 bytes */
170#define EEPROM_5000_REG_BAND_5_CHANNELS ((0x74)\
171 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 12 bytes */
172#define EEPROM_5000_REG_BAND_24_FAT_CHANNELS ((0x82)\
173 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 14 bytes */
174#define EEPROM_5000_REG_BAND_52_FAT_CHANNELS ((0x92)\
175 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 22 bytes */
135 176
136/* 4965 driver does not work with txpower calibration version < 5.
137 * Look for this in calib_version member of struct iwl4965_eeprom. */
138#define EEPROM_TX_POWER_VERSION_NEW (5)
139 177
140/* 2.4 GHz */ 178/* 2.4 GHz */
141extern const u8 iwl_eeprom_band_1[14]; 179extern const u8 iwl_eeprom_band_1[14];
142 180
143/* 181/*
144 * 4965 factory calibration data for one txpower level, on one channel, 182 * factory calibration data for one txpower level, on one channel,
145 * measured on one of the 2 tx chains (radio transmitter and associated 183 * measured on one of the 2 tx chains (radio transmitter and associated
146 * antenna). EEPROM contains: 184 * antenna). EEPROM contains:
147 * 185 *
@@ -154,7 +192,7 @@ extern const u8 iwl_eeprom_band_1[14];
154 * 192 *
155 * 4) RF power amplifier detector level measurement (not used). 193 * 4) RF power amplifier detector level measurement (not used).
156 */ 194 */
157struct iwl4965_eeprom_calib_measure { 195struct iwl_eeprom_calib_measure {
158 u8 temperature; /* Device temperature (Celsius) */ 196 u8 temperature; /* Device temperature (Celsius) */
159 u8 gain_idx; /* Index into gain table */ 197 u8 gain_idx; /* Index into gain table */
160 u8 actual_pow; /* Measured RF output power, half-dBm */ 198 u8 actual_pow; /* Measured RF output power, half-dBm */
@@ -163,22 +201,22 @@ struct iwl4965_eeprom_calib_measure {
163 201
164 202
165/* 203/*
166 * 4965 measurement set for one channel. EEPROM contains: 204 * measurement set for one channel. EEPROM contains:
167 * 205 *
168 * 1) Channel number measured 206 * 1) Channel number measured
169 * 207 *
170 * 2) Measurements for each of 3 power levels for each of 2 radio transmitters 208 * 2) Measurements for each of 3 power levels for each of 2 radio transmitters
171 * (a.k.a. "tx chains") (6 measurements altogether) 209 * (a.k.a. "tx chains") (6 measurements altogether)
172 */ 210 */
173struct iwl4965_eeprom_calib_ch_info { 211struct iwl_eeprom_calib_ch_info {
174 u8 ch_num; 212 u8 ch_num;
175 struct iwl4965_eeprom_calib_measure 213 struct iwl_eeprom_calib_measure
176 measurements[EEPROM_TX_POWER_TX_CHAINS] 214 measurements[EEPROM_TX_POWER_TX_CHAINS]
177 [EEPROM_TX_POWER_MEASUREMENTS]; 215 [EEPROM_TX_POWER_MEASUREMENTS];
178} __attribute__ ((packed)); 216} __attribute__ ((packed));
179 217
180/* 218/*
181 * 4965 txpower subband info. 219 * txpower subband info.
182 * 220 *
183 * For each frequency subband, EEPROM contains the following: 221 * For each frequency subband, EEPROM contains the following:
184 * 222 *
@@ -187,16 +225,16 @@ struct iwl4965_eeprom_calib_ch_info {
187 * 225 *
188 * 2) Sample measurement sets for 2 channels close to the range endpoints. 226 * 2) Sample measurement sets for 2 channels close to the range endpoints.
189 */ 227 */
190struct iwl4965_eeprom_calib_subband_info { 228struct iwl_eeprom_calib_subband_info {
191 u8 ch_from; /* channel number of lowest channel in subband */ 229 u8 ch_from; /* channel number of lowest channel in subband */
192 u8 ch_to; /* channel number of highest channel in subband */ 230 u8 ch_to; /* channel number of highest channel in subband */
193 struct iwl4965_eeprom_calib_ch_info ch1; 231 struct iwl_eeprom_calib_ch_info ch1;
194 struct iwl4965_eeprom_calib_ch_info ch2; 232 struct iwl_eeprom_calib_ch_info ch2;
195} __attribute__ ((packed)); 233} __attribute__ ((packed));
196 234
197 235
198/* 236/*
199 * 4965 txpower calibration info. EEPROM contains: 237 * txpower calibration info. EEPROM contains:
200 * 238 *
201 * 1) Factory-measured saturation power levels (maximum levels at which 239 * 1) Factory-measured saturation power levels (maximum levels at which
202 * tx power amplifier can output a signal without too much distortion). 240 * tx power amplifier can output a signal without too much distortion).
@@ -212,55 +250,58 @@ struct iwl4965_eeprom_calib_subband_info {
212 * characteristics of the analog radio circuitry vary with frequency. 250 * characteristics of the analog radio circuitry vary with frequency.
213 * 251 *
214 * Not all sets need to be filled with data; 252 * Not all sets need to be filled with data;
215 * struct iwl4965_eeprom_calib_subband_info contains range of channels 253 * struct iwl_eeprom_calib_subband_info contains range of channels
216 * (0 if unused) for each set of data. 254 * (0 if unused) for each set of data.
217 */ 255 */
218struct iwl4965_eeprom_calib_info { 256struct iwl_eeprom_calib_info {
219 u8 saturation_power24; /* half-dBm (e.g. "34" = 17 dBm) */ 257 u8 saturation_power24; /* half-dBm (e.g. "34" = 17 dBm) */
220 u8 saturation_power52; /* half-dBm */ 258 u8 saturation_power52; /* half-dBm */
221 s16 voltage; /* signed */ 259 s16 voltage; /* signed */
222 struct iwl4965_eeprom_calib_subband_info 260 struct iwl_eeprom_calib_subband_info
223 band_info[EEPROM_TX_POWER_BANDS]; 261 band_info[EEPROM_TX_POWER_BANDS];
224} __attribute__ ((packed)); 262} __attribute__ ((packed));
225 263
226 264
227 265#define ADDRESS_MSK 0x0000FFFF
228/* 266#define INDIRECT_TYPE_MSK 0x000F0000
229 * 4965 EEPROM map 267#define INDIRECT_HOST 0x00010000
230 */ 268#define INDIRECT_GENERAL 0x00020000
231struct iwl4965_eeprom { 269#define INDIRECT_REGULATORY 0x00030000
232 u8 reserved0[16]; 270#define INDIRECT_CALIBRATION 0x00040000
233 u16 device_id; /* abs.ofs: 16 */ 271#define INDIRECT_PROCESS_ADJST 0x00050000
234 u8 reserved1[2]; 272#define INDIRECT_OTHERS 0x00060000
235 u16 pmc; /* abs.ofs: 20 */ 273#define INDIRECT_ADDRESS 0x00100000
236 u8 reserved2[20]; 274
237 u8 mac_address[6]; /* abs.ofs: 42 */ 275/* General */
238 u8 reserved3[58]; 276#define EEPROM_DEVICE_ID (2*0x08) /* 2 bytes */
239 u16 board_revision; /* abs.ofs: 106 */ 277#define EEPROM_MAC_ADDRESS (2*0x15) /* 6 bytes */
240 u8 reserved4[11]; 278#define EEPROM_BOARD_REVISION (2*0x35) /* 2 bytes */
241 u8 board_pba_number[9]; /* abs.ofs: 119 */ 279#define EEPROM_BOARD_PBA_NUMBER (2*0x3B+1) /* 9 bytes */
242 u8 reserved5[8]; 280#define EEPROM_VERSION (2*0x44) /* 2 bytes */
243 u16 version; /* abs.ofs: 136 */ 281#define EEPROM_SKU_CAP (2*0x45) /* 1 bytes */
244 u8 sku_cap; /* abs.ofs: 138 */ 282#define EEPROM_LEDS_MODE (2*0x45+1) /* 1 bytes */
245 u8 leds_mode; /* abs.ofs: 139 */ 283#define EEPROM_OEM_MODE (2*0x46) /* 2 bytes */
246 u16 oem_mode; 284#define EEPROM_WOWLAN_MODE (2*0x47) /* 2 bytes */
247 u16 wowlan_mode; /* abs.ofs: 142 */ 285#define EEPROM_RADIO_CONFIG (2*0x48) /* 2 bytes */
248 u16 leds_time_interval; /* abs.ofs: 144 */ 286#define EEPROM_3945_M_VERSION (2*0x4A) /* 1 bytes */
249 u8 leds_off_time; /* abs.ofs: 146 */ 287#define EEPROM_ANTENNA_SWITCH_TYPE (2*0x4A+1) /* 1 bytes */
250 u8 leds_on_time; /* abs.ofs: 147 */ 288
251 u8 almgor_m_version; /* abs.ofs: 148 */ 289/* The following masks are to be applied on EEPROM_RADIO_CONFIG */
252 u8 antenna_switch_type; /* abs.ofs: 149 */ 290#define EEPROM_RF_CFG_TYPE_MSK(x) (x & 0x3) /* bits 0-1 */
253 u8 reserved6[8]; 291#define EEPROM_RF_CFG_STEP_MSK(x) ((x >> 2) & 0x3) /* bits 2-3 */
254 u16 board_revision_4965; /* abs.ofs: 158 */ 292#define EEPROM_RF_CFG_DASH_MSK(x) ((x >> 4) & 0x3) /* bits 4-5 */
255 u8 reserved7[13]; 293#define EEPROM_RF_CFG_PNUM_MSK(x) ((x >> 6) & 0x3) /* bits 6-7 */
256 u8 board_pba_number_4965[9]; /* abs.ofs: 173 */ 294#define EEPROM_RF_CFG_TX_ANT_MSK(x) ((x >> 8) & 0xF) /* bits 8-11 */
257 u8 reserved8[10]; 295#define EEPROM_RF_CFG_RX_ANT_MSK(x) ((x >> 12) & 0xF) /* bits 12-15 */
258 u8 sku_id[4]; /* abs.ofs: 192 */ 296
297#define EEPROM_3945_RF_CFG_TYPE_MAX 0x0
298#define EEPROM_4965_RF_CFG_TYPE_MAX 0x1
299#define EEPROM_5000_RF_CFG_TYPE_MAX 0x3
259 300
260/* 301/*
261 * Per-channel regulatory data. 302 * Per-channel regulatory data.
262 * 303 *
263 * Each channel that *might* be supported by 3945 or 4965 has a fixed location 304 * Each channel that *might* be supported by iwl has a fixed location
264 * in EEPROM containing EEPROM_CHANNEL_* usage flags (LSB) and max regulatory 305 * in EEPROM containing EEPROM_CHANNEL_* usage flags (LSB) and max regulatory
265 * txpower (MSB). 306 * txpower (MSB).
266 * 307 *
@@ -269,40 +310,38 @@ struct iwl4965_eeprom {
269 * 310 *
270 * 2.4 GHz channels 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 311 * 2.4 GHz channels 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
271 */ 312 */
272 u16 band_1_count; /* abs.ofs: 196 */ 313#define EEPROM_REGULATORY_SKU_ID (2*0x60) /* 4 bytes */
273 struct iwl4965_eeprom_channel band_1_channels[14]; /* abs.ofs: 196 */ 314#define EEPROM_REGULATORY_BAND_1 (2*0x62) /* 2 bytes */
315#define EEPROM_REGULATORY_BAND_1_CHANNELS (2*0x63) /* 28 bytes */
274 316
275/* 317/*
276 * 4.9 GHz channels 183, 184, 185, 187, 188, 189, 192, 196, 318 * 4.9 GHz channels 183, 184, 185, 187, 188, 189, 192, 196,
277 * 5.0 GHz channels 7, 8, 11, 12, 16 319 * 5.0 GHz channels 7, 8, 11, 12, 16
278 * (4915-5080MHz) (none of these is ever supported) 320 * (4915-5080MHz) (none of these is ever supported)
279 */ 321 */
280 u16 band_2_count; /* abs.ofs: 226 */ 322#define EEPROM_REGULATORY_BAND_2 (2*0x71) /* 2 bytes */
281 struct iwl4965_eeprom_channel band_2_channels[13]; /* abs.ofs: 228 */ 323#define EEPROM_REGULATORY_BAND_2_CHANNELS (2*0x72) /* 26 bytes */
282 324
283/* 325/*
284 * 5.2 GHz channels 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64 326 * 5.2 GHz channels 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64
285 * (5170-5320MHz) 327 * (5170-5320MHz)
286 */ 328 */
287 u16 band_3_count; /* abs.ofs: 254 */ 329#define EEPROM_REGULATORY_BAND_3 (2*0x7F) /* 2 bytes */
288 struct iwl4965_eeprom_channel band_3_channels[12]; /* abs.ofs: 256 */ 330#define EEPROM_REGULATORY_BAND_3_CHANNELS (2*0x80) /* 24 bytes */
289 331
290/* 332/*
291 * 5.5 GHz channels 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140 333 * 5.5 GHz channels 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140
292 * (5500-5700MHz) 334 * (5500-5700MHz)
293 */ 335 */
294 u16 band_4_count; /* abs.ofs: 280 */ 336#define EEPROM_REGULATORY_BAND_4 (2*0x8C) /* 2 bytes */
295 struct iwl4965_eeprom_channel band_4_channels[11]; /* abs.ofs: 282 */ 337#define EEPROM_REGULATORY_BAND_4_CHANNELS (2*0x8D) /* 22 bytes */
296 338
297/* 339/*
298 * 5.7 GHz channels 145, 149, 153, 157, 161, 165 340 * 5.7 GHz channels 145, 149, 153, 157, 161, 165
299 * (5725-5825MHz) 341 * (5725-5825MHz)
300 */ 342 */
301 u16 band_5_count; /* abs.ofs: 304 */ 343#define EEPROM_REGULATORY_BAND_5 (2*0x98) /* 2 bytes */
302 struct iwl4965_eeprom_channel band_5_channels[6]; /* abs.ofs: 306 */ 344#define EEPROM_REGULATORY_BAND_5_CHANNELS (2*0x99) /* 12 bytes */
303
304 u8 reserved10[2];
305
306 345
307/* 346/*
308 * 2.4 GHz FAT channels 1 (5), 2 (6), 3 (7), 4 (8), 5 (9), 6 (10), 7 (11) 347 * 2.4 GHz FAT channels 1 (5), 2 (6), 3 (7), 4 (8), 5 (9), 6 (10), 7 (11)
@@ -319,52 +358,35 @@ struct iwl4965_eeprom {
319 * 358 *
320 * NOTE: 4965 does not support FAT channels on 2.4 GHz. 359 * NOTE: 4965 does not support FAT channels on 2.4 GHz.
321 */ 360 */
322 struct iwl4965_eeprom_channel band_24_channels[7]; /* abs.ofs: 320 */ 361#define EEPROM_4965_REGULATORY_BAND_24_FAT_CHANNELS (2*0xA0) /* 14 bytes */
323 u8 reserved11[2];
324 362
325/* 363/*
326 * 5.2 GHz FAT channels 36 (40), 44 (48), 52 (56), 60 (64), 364 * 5.2 GHz FAT channels 36 (40), 44 (48), 52 (56), 60 (64),
327 * 100 (104), 108 (112), 116 (120), 124 (128), 132 (136), 149 (153), 157 (161) 365 * 100 (104), 108 (112), 116 (120), 124 (128), 132 (136), 149 (153), 157 (161)
328 */ 366 */
329 struct iwl4965_eeprom_channel band_52_channels[11]; /* abs.ofs: 336 */ 367#define EEPROM_4965_REGULATORY_BAND_52_FAT_CHANNELS (2*0xA8) /* 22 bytes */
330 u8 reserved12[6];
331
332/*
333 * 4965 driver requires txpower calibration format version 5 or greater.
334 * Driver does not work with txpower calibration version < 5.
335 * This value is simply a 16-bit number, no major/minor versions here.
336 */
337 u16 calib_version; /* abs.ofs: 364 */
338 u8 reserved13[2];
339 u8 reserved14[96]; /* abs.ofs: 368 */
340
341/*
342 * 4965 Txpower calibration data.
343 */
344 struct iwl4965_eeprom_calib_info calib_info; /* abs.ofs: 464 */
345
346 u8 reserved16[140]; /* fill out to full 1024 byte block */
347
348
349} __attribute__ ((packed));
350
351#define IWL_EEPROM_IMAGE_SIZE 1024
352
353/* End of EEPROM */
354 368
355struct iwl_eeprom_ops { 369struct iwl_eeprom_ops {
370 const u32 regulatory_bands[7];
356 int (*verify_signature) (struct iwl_priv *priv); 371 int (*verify_signature) (struct iwl_priv *priv);
357 int (*acquire_semaphore) (struct iwl_priv *priv); 372 int (*acquire_semaphore) (struct iwl_priv *priv);
358 void (*release_semaphore) (struct iwl_priv *priv); 373 void (*release_semaphore) (struct iwl_priv *priv);
374 int (*check_version) (struct iwl_priv *priv);
375 const u8* (*query_addr) (const struct iwl_priv *priv, size_t offset);
359}; 376};
360 377
361 378
362void iwl_eeprom_get_mac(const struct iwl_priv *priv, u8 *mac); 379void iwl_eeprom_get_mac(const struct iwl_priv *priv, u8 *mac);
363int iwl_eeprom_init(struct iwl_priv *priv); 380int iwl_eeprom_init(struct iwl_priv *priv);
381void iwl_eeprom_free(struct iwl_priv *priv);
382int iwl_eeprom_check_version(struct iwl_priv *priv);
383const u8 *iwl_eeprom_query_addr(const struct iwl_priv *priv, size_t offset);
384u16 iwl_eeprom_query16(const struct iwl_priv *priv, size_t offset);
364 385
365int iwlcore_eeprom_verify_signature(struct iwl_priv *priv); 386int iwlcore_eeprom_verify_signature(struct iwl_priv *priv);
366int iwlcore_eeprom_acquire_semaphore(struct iwl_priv *priv); 387int iwlcore_eeprom_acquire_semaphore(struct iwl_priv *priv);
367void iwlcore_eeprom_release_semaphore(struct iwl_priv *priv); 388void iwlcore_eeprom_release_semaphore(struct iwl_priv *priv);
389const u8 *iwlcore_eeprom_query_addr(const struct iwl_priv *priv, size_t offset);
368 390
369int iwl_init_channel_map(struct iwl_priv *priv); 391int iwl_init_channel_map(struct iwl_priv *priv);
370void iwl_free_channel_map(struct iwl_priv *priv); 392void iwl_free_channel_map(struct iwl_priv *priv);
diff --git a/drivers/net/wireless/iwlwifi/iwl-fh.h b/drivers/net/wireless/iwlwifi/iwl-fh.h
new file mode 100644
index 000000000000..a72efdf6d1dd
--- /dev/null
+++ b/drivers/net/wireless/iwlwifi/iwl-fh.h
@@ -0,0 +1,393 @@
1/******************************************************************************
2 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
8 * Copyright(c) 2005 - 2008 Intel Corporation. All rights reserved.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
22 * USA
23 *
24 * The full GNU General Public License is included in this distribution
25 * in the file called LICENSE.GPL.
26 *
27 * Contact Information:
28 * James P. Ketrenos <ipw2100-admin@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 *
31 * BSD LICENSE
32 *
33 * Copyright(c) 2005 - 2008 Intel Corporation. All rights reserved.
34 * All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 *
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
45 * distribution.
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 *
62 *****************************************************************************/
63
64/****************************/
65/* Flow Handler Definitions */
66/****************************/
67
68/**
69 * This I/O area is directly read/writable by driver (e.g. Linux uses writel())
70 * Addresses are offsets from device's PCI hardware base address.
71 */
72#define FH_MEM_LOWER_BOUND (0x1000)
73#define FH_MEM_UPPER_BOUND (0x1EF0)
74
75/**
76 * Keep-Warm (KW) buffer base address.
77 *
78 * Driver must allocate a 4KByte buffer that is used by 4965 for keeping the
79 * host DRAM powered on (via dummy accesses to DRAM) to maintain low-latency
80 * DRAM access when 4965 is Txing or Rxing. The dummy accesses prevent host
81 * from going into a power-savings mode that would cause higher DRAM latency,
82 * and possible data over/under-runs, before all Tx/Rx is complete.
83 *
84 * Driver loads FH_KW_MEM_ADDR_REG with the physical address (bits 35:4)
85 * of the buffer, which must be 4K aligned. Once this is set up, the 4965
86 * automatically invokes keep-warm accesses when normal accesses might not
87 * be sufficient to maintain fast DRAM response.
88 *
89 * Bit fields:
90 * 31-0: Keep-warm buffer physical base address [35:4], must be 4K aligned
91 */
92#define FH_KW_MEM_ADDR_REG (FH_MEM_LOWER_BOUND + 0x97C)
93
94
95/**
96 * TFD Circular Buffers Base (CBBC) addresses
97 *
98 * 4965 has 16 base pointer registers, one for each of 16 host-DRAM-resident
99 * circular buffers (CBs/queues) containing Transmit Frame Descriptors (TFDs)
100 * (see struct iwl_tfd_frame). These 16 pointer registers are offset by 0x04
101 * bytes from one another. Each TFD circular buffer in DRAM must be 256-byte
102 * aligned (address bits 0-7 must be 0).
103 *
104 * Bit fields in each pointer register:
105 * 27-0: TFD CB physical base address [35:8], must be 256-byte aligned
106 */
107#define FH_MEM_CBBC_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0x9D0)
108#define FH_MEM_CBBC_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xA10)
109
110/* Find TFD CB base pointer for given queue (range 0-15). */
111#define FH_MEM_CBBC_QUEUE(x) (FH_MEM_CBBC_LOWER_BOUND + (x) * 0x4)
112
113
114/**
115 * Rx SRAM Control and Status Registers (RSCSR)
116 *
117 * These registers provide handshake between driver and 4965 for the Rx queue
118 * (this queue handles *all* command responses, notifications, Rx data, etc.
119 * sent from 4965 uCode to host driver). Unlike Tx, there is only one Rx
120 * queue, and only one Rx DMA/FIFO channel. Also unlike Tx, which can
121 * concatenate up to 20 DRAM buffers to form a Tx frame, each Receive Buffer
122 * Descriptor (RBD) points to only one Rx Buffer (RB); there is a 1:1
123 * mapping between RBDs and RBs.
124 *
125 * Driver must allocate host DRAM memory for the following, and set the
126 * physical address of each into 4965 registers:
127 *
128 * 1) Receive Buffer Descriptor (RBD) circular buffer (CB), typically with 256
129 * entries (although any power of 2, up to 4096, is selectable by driver).
130 * Each entry (1 dword) points to a receive buffer (RB) of consistent size
131 * (typically 4K, although 8K or 16K are also selectable by driver).
132 * Driver sets up RB size and number of RBDs in the CB via Rx config
133 * register FH_MEM_RCSR_CHNL0_CONFIG_REG.
134 *
135 * Bit fields within one RBD:
136 * 27-0: Receive Buffer physical address bits [35:8], 256-byte aligned
137 *
138 * Driver sets physical address [35:8] of base of RBD circular buffer
139 * into FH_RSCSR_CHNL0_RBDCB_BASE_REG [27:0].
140 *
141 * 2) Rx status buffer, 8 bytes, in which 4965 indicates which Rx Buffers
142 * (RBs) have been filled, via a "write pointer", actually the index of
143 * the RB's corresponding RBD within the circular buffer. Driver sets
144 * physical address [35:4] into FH_RSCSR_CHNL0_STTS_WPTR_REG [31:0].
145 *
146 * Bit fields in lower dword of Rx status buffer (upper dword not used
147 * by driver; see struct iwl4965_shared, val0):
148 * 31-12: Not used by driver
149 * 11- 0: Index of last filled Rx buffer descriptor
150 * (4965 writes, driver reads this value)
151 *
152 * As the driver prepares Receive Buffers (RBs) for 4965 to fill, driver must
153 * enter pointers to these RBs into contiguous RBD circular buffer entries,
154 * and update the 4965's "write" index register,
155 * FH_RSCSR_CHNL0_RBDCB_WPTR_REG.
156 *
157 * This "write" index corresponds to the *next* RBD that the driver will make
158 * available, i.e. one RBD past the tail of the ready-to-fill RBDs within
159 * the circular buffer. This value should initially be 0 (before preparing any
160 * RBs), should be 8 after preparing the first 8 RBs (for example), and must
161 * wrap back to 0 at the end of the circular buffer (but don't wrap before
162 * "read" index has advanced past 1! See below).
163 * NOTE: 4965 EXPECTS THE WRITE INDEX TO BE INCREMENTED IN MULTIPLES OF 8.
164 *
165 * As the 4965 fills RBs (referenced from contiguous RBDs within the circular
166 * buffer), it updates the Rx status buffer in host DRAM, 2) described above,
167 * to tell the driver the index of the latest filled RBD. The driver must
168 * read this "read" index from DRAM after receiving an Rx interrupt from 4965.
169 *
170 * The driver must also internally keep track of a third index, which is the
171 * next RBD to process. When receiving an Rx interrupt, driver should process
172 * all filled but unprocessed RBs up to, but not including, the RB
173 * corresponding to the "read" index. For example, if "read" index becomes "1",
174 * driver may process the RB pointed to by RBD 0. Depending on volume of
175 * traffic, there may be many RBs to process.
176 *
177 * If read index == write index, 4965 thinks there is no room to put new data.
178 * Due to this, the maximum number of filled RBs is 255, instead of 256. To
179 * be safe, make sure that there is a gap of at least 2 RBDs between "write"
180 * and "read" indexes; that is, make sure that there are no more than 254
181 * buffers waiting to be filled.
182 */
183#define FH_MEM_RSCSR_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xBC0)
184#define FH_MEM_RSCSR_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xC00)
185#define FH_MEM_RSCSR_CHNL0 (FH_MEM_RSCSR_LOWER_BOUND)
186
187/**
188 * Physical base address of 8-byte Rx Status buffer.
189 * Bit fields:
190 * 31-0: Rx status buffer physical base address [35:4], must 16-byte aligned.
191 */
192#define FH_RSCSR_CHNL0_STTS_WPTR_REG (FH_MEM_RSCSR_CHNL0)
193
194/**
195 * Physical base address of Rx Buffer Descriptor Circular Buffer.
196 * Bit fields:
197 * 27-0: RBD CD physical base address [35:8], must be 256-byte aligned.
198 */
199#define FH_RSCSR_CHNL0_RBDCB_BASE_REG (FH_MEM_RSCSR_CHNL0 + 0x004)
200
201/**
202 * Rx write pointer (index, really!).
203 * Bit fields:
204 * 11-0: Index of driver's most recent prepared-to-be-filled RBD, + 1.
205 * NOTE: For 256-entry circular buffer, use only bits [7:0].
206 */
207#define FH_RSCSR_CHNL0_RBDCB_WPTR_REG (FH_MEM_RSCSR_CHNL0 + 0x008)
208#define FH_RSCSR_CHNL0_WPTR (FH_RSCSR_CHNL0_RBDCB_WPTR_REG)
209
210
211/**
212 * Rx Config/Status Registers (RCSR)
213 * Rx Config Reg for channel 0 (only channel used)
214 *
215 * Driver must initialize FH_MEM_RCSR_CHNL0_CONFIG_REG as follows for
216 * normal operation (see bit fields).
217 *
218 * Clearing FH_MEM_RCSR_CHNL0_CONFIG_REG to 0 turns off Rx DMA.
219 * Driver should poll FH_MEM_RSSR_RX_STATUS_REG for
220 * FH_RSSR_CHNL0_RX_STATUS_CHNL_IDLE (bit 24) before continuing.
221 *
222 * Bit fields:
223 * 31-30: Rx DMA channel enable: '00' off/pause, '01' pause at end of frame,
224 * '10' operate normally
225 * 29-24: reserved
226 * 23-20: # RBDs in circular buffer = 2^value; use "8" for 256 RBDs (normal),
227 * min "5" for 32 RBDs, max "12" for 4096 RBDs.
228 * 19-18: reserved
229 * 17-16: size of each receive buffer; '00' 4K (normal), '01' 8K,
230 * '10' 12K, '11' 16K.
231 * 15-14: reserved
232 * 13-12: IRQ destination; '00' none, '01' host driver (normal operation)
233 * 11- 4: timeout for closing Rx buffer and interrupting host (units 32 usec)
234 * typical value 0x10 (about 1/2 msec)
235 * 3- 0: reserved
236 */
237#define FH_MEM_RCSR_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xC00)
238#define FH_MEM_RCSR_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xCC0)
239#define FH_MEM_RCSR_CHNL0 (FH_MEM_RCSR_LOWER_BOUND)
240
241#define FH_MEM_RCSR_CHNL0_CONFIG_REG (FH_MEM_RCSR_CHNL0)
242
243#define FH_RCSR_CHNL0_RX_CONFIG_RB_TIMEOUT_MSK (0x00000FF0) /* bits 4-11 */
244#define FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_MSK (0x00001000) /* bits 12 */
245#define FH_RCSR_CHNL0_RX_CONFIG_SINGLE_FRAME_MSK (0x00008000) /* bit 15 */
246#define FH_RCSR_CHNL0_RX_CONFIG_RB_SIZE_MSK (0x00030000) /* bits 16-17 */
247#define FH_RCSR_CHNL0_RX_CONFIG_RBDBC_SIZE_MSK (0x00F00000) /* bits 20-23 */
248#define FH_RCSR_CHNL0_RX_CONFIG_DMA_CHNL_EN_MSK (0xC0000000) /* bits 30-31*/
249
250#define FH_RCSR_RX_CONFIG_RBDCB_SIZE_POS (20)
251#define FH_RCSR_RX_CONFIG_REG_IRQ_RBTH_POS (4)
252#define RX_RB_TIMEOUT (0x10)
253
254#define FH_RCSR_RX_CONFIG_CHNL_EN_PAUSE_VAL (0x00000000)
255#define FH_RCSR_RX_CONFIG_CHNL_EN_PAUSE_EOF_VAL (0x40000000)
256#define FH_RCSR_RX_CONFIG_CHNL_EN_ENABLE_VAL (0x80000000)
257
258#define FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_4K (0x00000000)
259#define FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_8K (0x00010000)
260#define FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_12K (0x00020000)
261#define FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_16K (0x00030000)
262
263#define FH_RCSR_CHNL0_RX_IGNORE_RXF_EMPTY (0x00000004)
264#define FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_NO_INT_VAL (0x00000000)
265#define FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_INT_HOST_VAL (0x00001000)
266
267
268/**
269 * Rx Shared Status Registers (RSSR)
270 *
271 * After stopping Rx DMA channel (writing 0 to
272 * FH_MEM_RCSR_CHNL0_CONFIG_REG), driver must poll
273 * FH_MEM_RSSR_RX_STATUS_REG until Rx channel is idle.
274 *
275 * Bit fields:
276 * 24: 1 = Channel 0 is idle
277 *
278 * FH_MEM_RSSR_SHARED_CTRL_REG and FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV
279 * contain default values that should not be altered by the driver.
280 */
281#define FH_MEM_RSSR_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xC40)
282#define FH_MEM_RSSR_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xD00)
283
284#define FH_MEM_RSSR_SHARED_CTRL_REG (FH_MEM_RSSR_LOWER_BOUND)
285#define FH_MEM_RSSR_RX_STATUS_REG (FH_MEM_RSSR_LOWER_BOUND + 0x004)
286#define FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV\
287 (FH_MEM_RSSR_LOWER_BOUND + 0x008)
288
289#define FH_RSSR_CHNL0_RX_STATUS_CHNL_IDLE (0x01000000)
290
291#define FH_MEM_TFDIB_REG1_ADDR_BITSHIFT 28
292
293/**
294 * Transmit DMA Channel Control/Status Registers (TCSR)
295 *
296 * 4965 has one configuration register for each of 8 Tx DMA/FIFO channels
297 * supported in hardware (don't confuse these with the 16 Tx queues in DRAM,
298 * which feed the DMA/FIFO channels); config regs are separated by 0x20 bytes.
299 *
300 * To use a Tx DMA channel, driver must initialize its
301 * FH_TCSR_CHNL_TX_CONFIG_REG(chnl) with:
302 *
303 * FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
304 * FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE_VAL
305 *
306 * All other bits should be 0.
307 *
308 * Bit fields:
309 * 31-30: Tx DMA channel enable: '00' off/pause, '01' pause at end of frame,
310 * '10' operate normally
311 * 29- 4: Reserved, set to "0"
312 * 3: Enable internal DMA requests (1, normal operation), disable (0)
313 * 2- 0: Reserved, set to "0"
314 */
315#define FH_TCSR_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xD00)
316#define FH_TCSR_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xE60)
317
318/* Find Control/Status reg for given Tx DMA/FIFO channel */
319#define FH_TCSR_CHNL_TX_CONFIG_REG(_chnl) \
320 (FH_TCSR_LOWER_BOUND + 0x20 * _chnl)
321
322#define FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_DISABLE_VAL (0x00000000)
323#define FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE_VAL (0x00000008)
324
325#define FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE (0x00000000)
326#define FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE_EOF (0x40000000)
327#define FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE (0x80000000)
328
329#define FH_TCSR_CHNL_NUM (7)
330
331#define FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_EMPTY (0x00000000)
332#define FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_WAIT (0x00002000)
333#define FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_VALID (0x00000003)
334
335#define FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_NOINT (0x00000000)
336#define FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_ENDTFD (0x00100000)
337#define FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_IFTFD (0x00200000)
338
339#define FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_NUM (20)
340#define FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_IDX (12)
341#define FH_TCSR_CHNL_TX_CONFIG_REG(_chnl) \
342 (FH_TCSR_LOWER_BOUND + 0x20 * _chnl)
343#define FH_TCSR_CHNL_TX_CREDIT_REG(_chnl) \
344 (FH_TCSR_LOWER_BOUND + 0x20 * _chnl + 0x4)
345#define FH_TCSR_CHNL_TX_BUF_STS_REG(_chnl) \
346 (FH_TCSR_LOWER_BOUND + 0x20 * _chnl + 0x8)
347
348/**
349 * Tx Shared Status Registers (TSSR)
350 *
351 * After stopping Tx DMA channel (writing 0 to
352 * FH_TCSR_CHNL_TX_CONFIG_REG(chnl)), driver must poll
353 * FH_TSSR_TX_STATUS_REG until selected Tx channel is idle
354 * (channel's buffers empty | no pending requests).
355 *
356 * Bit fields:
357 * 31-24: 1 = Channel buffers empty (channel 7:0)
358 * 23-16: 1 = No pending requests (channel 7:0)
359 */
360#define FH_TSSR_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xEA0)
361#define FH_TSSR_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xEC0)
362
363#define FH_TSSR_TX_STATUS_REG (FH_TSSR_LOWER_BOUND + 0x010)
364
365#define FH_TSSR_TX_STATUS_REG_BIT_BUFS_EMPTY(_chnl) ((1 << (_chnl)) << 24)
366#define FH_TSSR_TX_STATUS_REG_BIT_NO_PEND_REQ(_chnl) ((1 << (_chnl)) << 16)
367
368#define FH_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE(_chnl) \
369 (FH_TSSR_TX_STATUS_REG_BIT_BUFS_EMPTY(_chnl) | \
370 FH_TSSR_TX_STATUS_REG_BIT_NO_PEND_REQ(_chnl))
371
372
373
374#define FH_REGS_LOWER_BOUND (0x1000)
375#define FH_REGS_UPPER_BOUND (0x2000)
376
377/* Tx service channels */
378#define FH_SRVC_CHNL (9)
379#define FH_SRVC_LOWER_BOUND (FH_REGS_LOWER_BOUND + 0x9C8)
380#define FH_SRVC_UPPER_BOUND (FH_REGS_LOWER_BOUND + 0x9D0)
381#define FH_SRVC_CHNL_SRAM_ADDR_REG(_chnl) \
382 (FH_SRVC_LOWER_BOUND + ((_chnl) - 9) * 0x4)
383
384/* TFDB Area - TFDs buffer table */
385#define FH_MEM_TFDIB_DRAM_ADDR_LSB_MSK (0xFFFFFFFF)
386#define FH_TFDIB_LOWER_BOUND (FH_REGS_LOWER_BOUND + 0x900)
387#define FH_TFDIB_UPPER_BOUND (FH_REGS_LOWER_BOUND + 0x958)
388#define FH_TFDIB_CTRL0_REG(_chnl) (FH_TFDIB_LOWER_BOUND + 0x8 * (_chnl))
389#define FH_TFDIB_CTRL1_REG(_chnl) (FH_TFDIB_LOWER_BOUND + 0x8 * (_chnl) + 0x4)
390
391/* TCSR: tx_config register values */
392#define FH_RSCSR_FRAME_SIZE_MSK (0x00003FFF) /* bits 0-13 */
393
diff --git a/drivers/net/wireless/iwlwifi/iwl-hcmd.c b/drivers/net/wireless/iwlwifi/iwl-hcmd.c
index fdb27f1cdc08..8300f3d00a06 100644
--- a/drivers/net/wireless/iwlwifi/iwl-hcmd.c
+++ b/drivers/net/wireless/iwlwifi/iwl-hcmd.c
@@ -28,10 +28,9 @@
28 28
29#include <linux/kernel.h> 29#include <linux/kernel.h>
30#include <linux/module.h> 30#include <linux/module.h>
31#include <linux/version.h>
32#include <net/mac80211.h> 31#include <net/mac80211.h>
33 32
34#include "iwl-4965.h" /* FIXME: remove */ 33#include "iwl-dev.h" /* FIXME: remove */
35#include "iwl-debug.h" 34#include "iwl-debug.h"
36#include "iwl-eeprom.h" 35#include "iwl-eeprom.h"
37#include "iwl-core.h" 36#include "iwl-core.h"
@@ -56,6 +55,7 @@ const char *get_cmd_string(u8 cmd)
56 IWL_CMD(REPLY_RATE_SCALE); 55 IWL_CMD(REPLY_RATE_SCALE);
57 IWL_CMD(REPLY_LEDS_CMD); 56 IWL_CMD(REPLY_LEDS_CMD);
58 IWL_CMD(REPLY_TX_LINK_QUALITY_CMD); 57 IWL_CMD(REPLY_TX_LINK_QUALITY_CMD);
58 IWL_CMD(COEX_PRIORITY_TABLE_CMD);
59 IWL_CMD(RADAR_NOTIFICATION); 59 IWL_CMD(RADAR_NOTIFICATION);
60 IWL_CMD(REPLY_QUIET_CMD); 60 IWL_CMD(REPLY_QUIET_CMD);
61 IWL_CMD(REPLY_CHANNEL_SWITCH); 61 IWL_CMD(REPLY_CHANNEL_SWITCH);
@@ -89,6 +89,10 @@ const char *get_cmd_string(u8 cmd)
89 IWL_CMD(REPLY_RX_MPDU_CMD); 89 IWL_CMD(REPLY_RX_MPDU_CMD);
90 IWL_CMD(REPLY_RX); 90 IWL_CMD(REPLY_RX);
91 IWL_CMD(REPLY_COMPRESSED_BA); 91 IWL_CMD(REPLY_COMPRESSED_BA);
92 IWL_CMD(CALIBRATION_CFG_CMD);
93 IWL_CMD(CALIBRATION_RES_NOTIFICATION);
94 IWL_CMD(CALIBRATION_COMPLETE_NOTIFICATION);
95 IWL_CMD(REPLY_TX_POWER_DBM_CMD);
92 default: 96 default:
93 return "UNKNOWN"; 97 return "UNKNOWN";
94 98
@@ -101,7 +105,7 @@ EXPORT_SYMBOL(get_cmd_string);
101static int iwl_generic_cmd_callback(struct iwl_priv *priv, 105static int iwl_generic_cmd_callback(struct iwl_priv *priv,
102 struct iwl_cmd *cmd, struct sk_buff *skb) 106 struct iwl_cmd *cmd, struct sk_buff *skb)
103{ 107{
104 struct iwl4965_rx_packet *pkt = NULL; 108 struct iwl_rx_packet *pkt = NULL;
105 109
106 if (!skb) { 110 if (!skb) {
107 IWL_ERROR("Error: Response NULL in %s.\n", 111 IWL_ERROR("Error: Response NULL in %s.\n",
@@ -109,15 +113,25 @@ static int iwl_generic_cmd_callback(struct iwl_priv *priv,
109 return 1; 113 return 1;
110 } 114 }
111 115
112 pkt = (struct iwl4965_rx_packet *)skb->data; 116 pkt = (struct iwl_rx_packet *)skb->data;
113 if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) { 117 if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) {
114 IWL_ERROR("Bad return from %s (0x%08X)\n", 118 IWL_ERROR("Bad return from %s (0x%08X)\n",
115 get_cmd_string(cmd->hdr.cmd), pkt->hdr.flags); 119 get_cmd_string(cmd->hdr.cmd), pkt->hdr.flags);
116 return 1; 120 return 1;
117 } 121 }
118 122
119 IWL_DEBUG_HC("back from %s (0x%08X)\n", 123#ifdef CONFIG_IWLWIFI_DEBUG
120 get_cmd_string(cmd->hdr.cmd), pkt->hdr.flags); 124 switch (cmd->hdr.cmd) {
125 case REPLY_TX_LINK_QUALITY_CMD:
126 case SENSITIVITY_CMD:
127 IWL_DEBUG_HC_DUMP("back from %s (0x%08X)\n",
128 get_cmd_string(cmd->hdr.cmd), pkt->hdr.flags);
129 break;
130 default:
131 IWL_DEBUG_HC("back from %s (0x%08X)\n",
132 get_cmd_string(cmd->hdr.cmd), pkt->hdr.flags);
133 }
134#endif
121 135
122 /* Let iwl_tx_complete free the response skb */ 136 /* Let iwl_tx_complete free the response skb */
123 return 1; 137 return 1;
@@ -139,7 +153,7 @@ static int iwl_send_cmd_async(struct iwl_priv *priv, struct iwl_host_cmd *cmd)
139 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) 153 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
140 return -EBUSY; 154 return -EBUSY;
141 155
142 ret = priv->cfg->ops->utils->enqueue_hcmd(priv, cmd); 156 ret = iwl_enqueue_hcmd(priv, cmd);
143 if (ret < 0) { 157 if (ret < 0) {
144 IWL_ERROR("Error sending %s: enqueue_hcmd failed: %d\n", 158 IWL_ERROR("Error sending %s: enqueue_hcmd failed: %d\n",
145 get_cmd_string(cmd->id), ret); 159 get_cmd_string(cmd->id), ret);
@@ -170,7 +184,7 @@ int iwl_send_cmd_sync(struct iwl_priv *priv, struct iwl_host_cmd *cmd)
170 if (cmd->meta.flags & CMD_WANT_SKB) 184 if (cmd->meta.flags & CMD_WANT_SKB)
171 cmd->meta.source = &cmd->meta; 185 cmd->meta.source = &cmd->meta;
172 186
173 cmd_idx = priv->cfg->ops->utils->enqueue_hcmd(priv, cmd); 187 cmd_idx = iwl_enqueue_hcmd(priv, cmd);
174 if (cmd_idx < 0) { 188 if (cmd_idx < 0) {
175 ret = cmd_idx; 189 ret = cmd_idx;
176 IWL_ERROR("Error sending %s: enqueue_hcmd failed: %d\n", 190 IWL_ERROR("Error sending %s: enqueue_hcmd failed: %d\n",
@@ -223,7 +237,7 @@ cancel:
223 * TX cmd queue. Otherwise in case the cmd comes 237 * TX cmd queue. Otherwise in case the cmd comes
224 * in later, it will possibly set an invalid 238 * in later, it will possibly set an invalid
225 * address (cmd->meta.source). */ 239 * address (cmd->meta.source). */
226 qcmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_idx]; 240 qcmd = priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_idx];
227 qcmd->meta.flags &= ~CMD_WANT_SKB; 241 qcmd->meta.flags &= ~CMD_WANT_SKB;
228 } 242 }
229fail: 243fail:
diff --git a/drivers/net/wireless/iwlwifi/iwl-helpers.h b/drivers/net/wireless/iwlwifi/iwl-helpers.h
index a443472bea62..41eed6793328 100644
--- a/drivers/net/wireless/iwlwifi/iwl-helpers.h
+++ b/drivers/net/wireless/iwlwifi/iwl-helpers.h
@@ -136,8 +136,8 @@ static inline void iwl_set_bits16(__le16 *dst, u8 pos, u8 len, int val)
136 136
137#define KELVIN_TO_CELSIUS(x) ((x)-273) 137#define KELVIN_TO_CELSIUS(x) ((x)-273)
138#define CELSIUS_TO_KELVIN(x) ((x)+273) 138#define CELSIUS_TO_KELVIN(x) ((x)+273)
139#define IWL_MASK(lo, hi) ((1 << (hi)) | ((1 << (hi)) - (1 << (lo))))
139 140
140#define IEEE80211_CHAN_W_RADAR_DETECT 0x00000010
141 141
142static inline struct ieee80211_conf *ieee80211_get_hw_conf( 142static inline struct ieee80211_conf *ieee80211_get_hw_conf(
143 struct ieee80211_hw *hw) 143 struct ieee80211_hw *hw)
@@ -145,96 +145,6 @@ static inline struct ieee80211_conf *ieee80211_get_hw_conf(
145 return &hw->conf; 145 return &hw->conf;
146} 146}
147 147
148#define QOS_CONTROL_LEN 2
149
150
151static inline int ieee80211_is_management(u16 fc)
152{
153 return (fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT;
154}
155
156static inline int ieee80211_is_control(u16 fc)
157{
158 return (fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL;
159}
160
161static inline int ieee80211_is_data(u16 fc)
162{
163 return (fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA;
164}
165
166static inline int ieee80211_is_back_request(u16 fc)
167{
168 return ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) &&
169 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BACK_REQ);
170}
171
172static inline int ieee80211_is_probe_response(u16 fc)
173{
174 return ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) &&
175 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP);
176}
177
178static inline int ieee80211_is_probe_request(u16 fc)
179{
180 return ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) &&
181 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_REQ);
182}
183
184static inline int ieee80211_is_beacon(u16 fc)
185{
186 return ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) &&
187 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON);
188}
189
190static inline int ieee80211_is_atim(u16 fc)
191{
192 return ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) &&
193 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ATIM);
194}
195
196static inline int ieee80211_is_assoc_request(u16 fc)
197{
198 return ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) &&
199 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ);
200}
201
202static inline int ieee80211_is_assoc_response(u16 fc)
203{
204 return ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) &&
205 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_RESP);
206}
207
208static inline int ieee80211_is_auth(u16 fc)
209{
210 return ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) &&
211 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ);
212}
213
214static inline int ieee80211_is_deauth(u16 fc)
215{
216 return ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) &&
217 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ);
218}
219
220static inline int ieee80211_is_disassoc(u16 fc)
221{
222 return ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) &&
223 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ);
224}
225
226static inline int ieee80211_is_reassoc_request(u16 fc)
227{
228 return ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) &&
229 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ);
230}
231
232static inline int ieee80211_is_reassoc_response(u16 fc)
233{
234 return ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) &&
235 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_RESP);
236}
237
238static inline int iwl_check_bits(unsigned long field, unsigned long mask) 148static inline int iwl_check_bits(unsigned long field, unsigned long mask)
239{ 149{
240 return ((field & mask) == mask) ? 1 : 0; 150 return ((field & mask) == mask) ? 1 : 0;
diff --git a/drivers/net/wireless/iwlwifi/iwl-io.h b/drivers/net/wireless/iwlwifi/iwl-io.h
index 5bc3df432d2d..9740fcc1805e 100644
--- a/drivers/net/wireless/iwlwifi/iwl-io.h
+++ b/drivers/net/wireless/iwlwifi/iwl-io.h
@@ -61,7 +61,7 @@
61 * 61 *
62 */ 62 */
63 63
64#define _iwl_write32(priv, ofs, val) writel((val), (priv)->hw_base + (ofs)) 64#define _iwl_write32(priv, ofs, val) iowrite32((val), (priv)->hw_base + (ofs))
65#ifdef CONFIG_IWLWIFI_DEBUG 65#ifdef CONFIG_IWLWIFI_DEBUG
66static inline void __iwl_write32(const char *f, u32 l, struct iwl_priv *priv, 66static inline void __iwl_write32(const char *f, u32 l, struct iwl_priv *priv,
67 u32 ofs, u32 val) 67 u32 ofs, u32 val)
@@ -75,7 +75,7 @@ static inline void __iwl_write32(const char *f, u32 l, struct iwl_priv *priv,
75#define iwl_write32(priv, ofs, val) _iwl_write32(priv, ofs, val) 75#define iwl_write32(priv, ofs, val) _iwl_write32(priv, ofs, val)
76#endif 76#endif
77 77
78#define _iwl_read32(priv, ofs) readl((priv)->hw_base + (ofs)) 78#define _iwl_read32(priv, ofs) ioread32((priv)->hw_base + (ofs))
79#ifdef CONFIG_IWLWIFI_DEBUG 79#ifdef CONFIG_IWLWIFI_DEBUG
80static inline u32 __iwl_read32(char *f, u32 l, struct iwl_priv *priv, u32 ofs) 80static inline u32 __iwl_read32(char *f, u32 l, struct iwl_priv *priv, u32 ofs)
81{ 81{
@@ -155,28 +155,10 @@ static inline void __iwl_clear_bit(const char *f, u32 l,
155static inline int _iwl_grab_nic_access(struct iwl_priv *priv) 155static inline int _iwl_grab_nic_access(struct iwl_priv *priv)
156{ 156{
157 int ret; 157 int ret;
158 u32 gp_ctl;
159
160#ifdef CONFIG_IWLWIFI_DEBUG 158#ifdef CONFIG_IWLWIFI_DEBUG
161 if (atomic_read(&priv->restrict_refcnt)) 159 if (atomic_read(&priv->restrict_refcnt))
162 return 0; 160 return 0;
163#endif 161#endif
164 if (test_bit(STATUS_RF_KILL_HW, &priv->status) ||
165 test_bit(STATUS_RF_KILL_SW, &priv->status)) {
166 IWL_WARNING("WARNING: Requesting MAC access during RFKILL "
167 "wakes up NIC\n");
168
169 /* 10 msec allows time for NIC to complete its data save */
170 gp_ctl = _iwl_read32(priv, CSR_GP_CNTRL);
171 if (gp_ctl & CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY) {
172 IWL_DEBUG_RF_KILL("Wait for complete power-down, "
173 "gpctl = 0x%08x\n", gp_ctl);
174 mdelay(10);
175 } else
176 IWL_DEBUG_RF_KILL("power-down complete, "
177 "gpctl = 0x%08x\n", gp_ctl);
178 }
179
180 /* this bit wakes up the NIC */ 162 /* this bit wakes up the NIC */
181 _iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); 163 _iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
182 ret = _iwl_poll_bit(priv, CSR_GP_CNTRL, 164 ret = _iwl_poll_bit(priv, CSR_GP_CNTRL,
diff --git a/drivers/net/wireless/iwlwifi/iwl-led.c b/drivers/net/wireless/iwlwifi/iwl-led.c
index 03fdf5b434a1..4eee1b163cd2 100644
--- a/drivers/net/wireless/iwlwifi/iwl-led.c
+++ b/drivers/net/wireless/iwlwifi/iwl-led.c
@@ -27,7 +27,6 @@
27 27
28#include <linux/kernel.h> 28#include <linux/kernel.h>
29#include <linux/module.h> 29#include <linux/module.h>
30#include <linux/version.h>
31#include <linux/init.h> 30#include <linux/init.h>
32#include <linux/pci.h> 31#include <linux/pci.h>
33#include <linux/dma-mapping.h> 32#include <linux/dma-mapping.h>
@@ -39,19 +38,26 @@
39#include <linux/etherdevice.h> 38#include <linux/etherdevice.h>
40#include <asm/unaligned.h> 39#include <asm/unaligned.h>
41 40
42#include "iwl-4965.h" 41#include "iwl-dev.h"
43#include "iwl-core.h" 42#include "iwl-core.h"
44#include "iwl-io.h" 43#include "iwl-io.h"
45#include "iwl-helpers.h" 44#include "iwl-helpers.h"
46 45
47#define IWL_1MB_RATE (128 * 1024) 46#ifdef CONFIG_IWLWIFI_DEBUG
48#define IWL_LED_THRESHOLD (16) 47static const char *led_type_str[] = {
49#define IWL_MAX_BLINK_TBL (10) 48 __stringify(IWL_LED_TRG_TX),
49 __stringify(IWL_LED_TRG_RX),
50 __stringify(IWL_LED_TRG_ASSOC),
51 __stringify(IWL_LED_TRG_RADIO),
52 NULL
53};
54#endif /* CONFIG_IWLWIFI_DEBUG */
55
50 56
51static const struct { 57static const struct {
52 u16 tpt; 58 u16 tpt;
53 u8 on_time; 59 u8 on_time;
54 u8 of_time; 60 u8 off_time;
55} blink_tbl[] = 61} blink_tbl[] =
56{ 62{
57 {300, 25, 25}, 63 {300, 25, 25},
@@ -63,26 +69,31 @@ static const struct {
63 {15, 95, 95 }, 69 {15, 95, 95 },
64 {10, 110, 110}, 70 {10, 110, 110},
65 {5, 130, 130}, 71 {5, 130, 130},
66 {0, 167, 167} 72 {0, 167, 167},
73/* SOLID_ON */
74 {-1, IWL_LED_SOLID, 0}
67}; 75};
68 76
69static int iwl_led_cmd_callback(struct iwl_priv *priv, 77#define IWL_1MB_RATE (128 * 1024)
70 struct iwl_cmd *cmd, struct sk_buff *skb) 78#define IWL_LED_THRESHOLD (16)
79#define IWL_MAX_BLINK_TBL (ARRAY_SIZE(blink_tbl) - 1) /* exclude SOLID_ON */
80#define IWL_SOLID_BLINK_IDX (ARRAY_SIZE(blink_tbl) - 1)
81
82/* [0-256] -> [0..8] FIXME: we need [0..10] */
83static inline int iwl_brightness_to_idx(enum led_brightness brightness)
71{ 84{
72 return 1; 85 return fls(0x000000FF & (u32)brightness);
73} 86}
74 87
75
76/* Send led command */ 88/* Send led command */
77static int iwl_send_led_cmd(struct iwl_priv *priv, 89static int iwl_send_led_cmd(struct iwl_priv *priv, struct iwl_led_cmd *led_cmd)
78 struct iwl4965_led_cmd *led_cmd)
79{ 90{
80 struct iwl_host_cmd cmd = { 91 struct iwl_host_cmd cmd = {
81 .id = REPLY_LEDS_CMD, 92 .id = REPLY_LEDS_CMD,
82 .len = sizeof(struct iwl4965_led_cmd), 93 .len = sizeof(struct iwl_led_cmd),
83 .data = led_cmd, 94 .data = led_cmd,
84 .meta.flags = CMD_ASYNC, 95 .meta.flags = CMD_ASYNC,
85 .meta.u.callback = iwl_led_cmd_callback 96 .meta.u.callback = NULL,
86 }; 97 };
87 u32 reg; 98 u32 reg;
88 99
@@ -93,33 +104,20 @@ static int iwl_send_led_cmd(struct iwl_priv *priv,
93 return iwl_send_cmd(priv, &cmd); 104 return iwl_send_cmd(priv, &cmd);
94} 105}
95 106
96 107/* Set led pattern command */
97/* Set led on command */
98static int iwl4965_led_on(struct iwl_priv *priv, int led_id)
99{
100 struct iwl4965_led_cmd led_cmd = {
101 .id = led_id,
102 .on = IWL_LED_SOLID,
103 .off = 0,
104 .interval = IWL_DEF_LED_INTRVL
105 };
106 return iwl_send_led_cmd(priv, &led_cmd);
107}
108
109/* Set led on command */
110static int iwl4965_led_pattern(struct iwl_priv *priv, int led_id, 108static int iwl4965_led_pattern(struct iwl_priv *priv, int led_id,
111 enum led_brightness brightness) 109 unsigned int idx)
112{ 110{
113 struct iwl4965_led_cmd led_cmd = { 111 struct iwl_led_cmd led_cmd = {
114 .id = led_id, 112 .id = led_id,
115 .on = brightness,
116 .off = brightness,
117 .interval = IWL_DEF_LED_INTRVL 113 .interval = IWL_DEF_LED_INTRVL
118 }; 114 };
119 if (brightness == LED_FULL) { 115
120 led_cmd.on = IWL_LED_SOLID; 116 BUG_ON(idx > IWL_MAX_BLINK_TBL);
121 led_cmd.off = 0; 117
122 } 118 led_cmd.on = blink_tbl[idx].on_time;
119 led_cmd.off = blink_tbl[idx].off_time;
120
123 return iwl_send_led_cmd(priv, &led_cmd); 121 return iwl_send_led_cmd(priv, &led_cmd);
124} 122}
125 123
@@ -132,10 +130,22 @@ static int iwl4965_led_on_reg(struct iwl_priv *priv, int led_id)
132} 130}
133 131
134#if 0 132#if 0
133/* Set led on command */
134static int iwl4965_led_on(struct iwl_priv *priv, int led_id)
135{
136 struct iwl_led_cmd led_cmd = {
137 .id = led_id,
138 .on = IWL_LED_SOLID,
139 .off = 0,
140 .interval = IWL_DEF_LED_INTRVL
141 };
142 return iwl_send_led_cmd(priv, &led_cmd);
143}
144
135/* Set led off command */ 145/* Set led off command */
136int iwl4965_led_off(struct iwl_priv *priv, int led_id) 146int iwl4965_led_off(struct iwl_priv *priv, int led_id)
137{ 147{
138 struct iwl4965_led_cmd led_cmd = { 148 struct iwl_led_cmd led_cmd = {
139 .id = led_id, 149 .id = led_id,
140 .on = 0, 150 .on = 0,
141 .off = 0, 151 .off = 0,
@@ -150,30 +160,35 @@ int iwl4965_led_off(struct iwl_priv *priv, int led_id)
150/* Set led register off */ 160/* Set led register off */
151static int iwl4965_led_off_reg(struct iwl_priv *priv, int led_id) 161static int iwl4965_led_off_reg(struct iwl_priv *priv, int led_id)
152{ 162{
153 IWL_DEBUG_LED("radio off\n"); 163 IWL_DEBUG_LED("LED Reg off\n");
154 iwl_write32(priv, CSR_LED_REG, CSR_LED_REG_TRUN_OFF); 164 iwl_write32(priv, CSR_LED_REG, CSR_LED_REG_TRUN_OFF);
155 return 0; 165 return 0;
156} 166}
157 167
158/* Set led blink command */ 168/*
159static int iwl4965_led_not_solid(struct iwl_priv *priv, int led_id, 169 * Set led register in case of disassociation according to rfkill state
160 u8 brightness) 170 */
171static int iwl_led_associate(struct iwl_priv *priv, int led_id)
161{ 172{
162 struct iwl4965_led_cmd led_cmd = { 173 IWL_DEBUG_LED("Associated\n");
163 .id = led_id, 174 priv->allow_blinking = 1;
164 .on = brightness, 175 return iwl4965_led_on_reg(priv, led_id);
165 .off = brightness,
166 .interval = IWL_DEF_LED_INTRVL
167 };
168
169 return iwl_send_led_cmd(priv, &led_cmd);
170} 176}
177static int iwl_led_disassociate(struct iwl_priv *priv, int led_id)
178{
179 priv->allow_blinking = 0;
180 if (iwl_is_rfkill(priv))
181 iwl4965_led_off_reg(priv, led_id);
182 else
183 iwl4965_led_on_reg(priv, led_id);
171 184
185 return 0;
186}
172 187
173/* 188/*
174 * brightness call back function for Tx/Rx LED 189 * brightness call back function for Tx/Rx LED
175 */ 190 */
176static int iwl4965_led_associated(struct iwl_priv *priv, int led_id) 191static int iwl_led_associated(struct iwl_priv *priv, int led_id)
177{ 192{
178 if (test_bit(STATUS_EXIT_PENDING, &priv->status) || 193 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
179 !test_bit(STATUS_READY, &priv->status)) 194 !test_bit(STATUS_READY, &priv->status))
@@ -189,34 +204,32 @@ static int iwl4965_led_associated(struct iwl_priv *priv, int led_id)
189/* 204/*
190 * brightness call back for association and radio 205 * brightness call back for association and radio
191 */ 206 */
192static void iwl4965_led_brightness_set(struct led_classdev *led_cdev, 207static void iwl_led_brightness_set(struct led_classdev *led_cdev,
193 enum led_brightness brightness) 208 enum led_brightness brightness)
194{ 209{
195 struct iwl4965_led *led = container_of(led_cdev, 210 struct iwl_led *led = container_of(led_cdev, struct iwl_led, led_dev);
196 struct iwl4965_led, led_dev);
197 struct iwl_priv *priv = led->priv; 211 struct iwl_priv *priv = led->priv;
198 212
199 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) 213 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
200 return; 214 return;
201 215
216
217 IWL_DEBUG_LED("Led type = %s brightness = %d\n",
218 led_type_str[led->type], brightness);
202 switch (brightness) { 219 switch (brightness) {
203 case LED_FULL: 220 case LED_FULL:
204 if (led->type == IWL_LED_TRG_ASSOC)
205 priv->allow_blinking = 1;
206
207 if (led->led_on) 221 if (led->led_on)
208 led->led_on(priv, IWL_LED_LINK); 222 led->led_on(priv, IWL_LED_LINK);
209 break; 223 break;
210 case LED_OFF: 224 case LED_OFF:
211 if (led->type == IWL_LED_TRG_ASSOC)
212 priv->allow_blinking = 0;
213
214 if (led->led_off) 225 if (led->led_off)
215 led->led_off(priv, IWL_LED_LINK); 226 led->led_off(priv, IWL_LED_LINK);
216 break; 227 break;
217 default: 228 default:
218 if (led->led_pattern) 229 if (led->led_pattern) {
219 led->led_pattern(priv, IWL_LED_LINK, brightness); 230 int idx = iwl_brightness_to_idx(brightness);
231 led->led_pattern(priv, IWL_LED_LINK, idx);
232 }
220 break; 233 break;
221 } 234 }
222} 235}
@@ -226,16 +239,15 @@ static void iwl4965_led_brightness_set(struct led_classdev *led_cdev,
226/* 239/*
227 * Register led class with the system 240 * Register led class with the system
228 */ 241 */
229static int iwl_leds_register_led(struct iwl_priv *priv, 242static int iwl_leds_register_led(struct iwl_priv *priv, struct iwl_led *led,
230 struct iwl4965_led *led,
231 enum led_type type, u8 set_led, 243 enum led_type type, u8 set_led,
232 const char *name, char *trigger) 244 char *trigger)
233{ 245{
234 struct device *device = wiphy_dev(priv->hw->wiphy); 246 struct device *device = wiphy_dev(priv->hw->wiphy);
235 int ret; 247 int ret;
236 248
237 led->led_dev.name = name; 249 led->led_dev.name = led->name;
238 led->led_dev.brightness_set = iwl4965_led_brightness_set; 250 led->led_dev.brightness_set = iwl_led_brightness_set;
239 led->led_dev.default_trigger = trigger; 251 led->led_dev.default_trigger = trigger;
240 252
241 led->priv = priv; 253 led->priv = priv;
@@ -259,38 +271,30 @@ static int iwl_leds_register_led(struct iwl_priv *priv,
259/* 271/*
260 * calculate blink rate according to last 2 sec Tx/Rx activities 272 * calculate blink rate according to last 2 sec Tx/Rx activities
261 */ 273 */
262static inline u8 get_blink_rate(struct iwl_priv *priv) 274static int iwl_get_blink_rate(struct iwl_priv *priv)
263{ 275{
264 int i; 276 int i;
265 u8 blink_rate; 277 u64 current_tpt = priv->tx_stats[2].bytes;
266 u64 current_tpt = priv->tx_stats[2].bytes + priv->rx_stats[2].bytes; 278 /* FIXME: + priv->rx_stats[2].bytes; */
267 s64 tpt = current_tpt - priv->led_tpt; 279 s64 tpt = current_tpt - priv->led_tpt;
268 280
269 if (tpt < 0) /* wrapparound */ 281 if (tpt < 0) /* wrapparound */
270 tpt = -tpt; 282 tpt = -tpt;
271 283
284 IWL_DEBUG_LED("tpt %lld current_tpt %llu\n",
285 (long long)tpt,
286 (unsigned long long)current_tpt);
272 priv->led_tpt = current_tpt; 287 priv->led_tpt = current_tpt;
273 288
274 if (tpt < IWL_LED_THRESHOLD) { 289 if (!priv->allow_blinking)
275 i = IWL_MAX_BLINK_TBL; 290 i = IWL_MAX_BLINK_TBL;
276 } else { 291 else
277 for (i = 0; i < IWL_MAX_BLINK_TBL; i++) 292 for (i = 0; i < IWL_MAX_BLINK_TBL; i++)
278 if (tpt > (blink_tbl[i].tpt * IWL_1MB_RATE)) 293 if (tpt > (blink_tbl[i].tpt * IWL_1MB_RATE))
279 break; 294 break;
280 }
281 /* if 0 frame is transfered */
282 if ((i == IWL_MAX_BLINK_TBL) || !priv->allow_blinking)
283 blink_rate = IWL_LED_SOLID;
284 else
285 blink_rate = blink_tbl[i].on_time;
286
287 return blink_rate;
288}
289 295
290static inline int is_rf_kill(struct iwl_priv *priv) 296 IWL_DEBUG_LED("LED BLINK IDX=%d", i);
291{ 297 return i;
292 return test_bit(STATUS_RF_KILL_HW, &priv->status) ||
293 test_bit(STATUS_RF_KILL_SW, &priv->status);
294} 298}
295 299
296/* 300/*
@@ -300,22 +304,23 @@ static inline int is_rf_kill(struct iwl_priv *priv)
300 */ 304 */
301void iwl_leds_background(struct iwl_priv *priv) 305void iwl_leds_background(struct iwl_priv *priv)
302{ 306{
303 u8 blink_rate; 307 u8 blink_idx;
304 308
305 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { 309 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
306 priv->last_blink_time = 0; 310 priv->last_blink_time = 0;
307 return; 311 return;
308 } 312 }
309 if (is_rf_kill(priv)) { 313 if (iwl_is_rfkill(priv)) {
310 priv->last_blink_time = 0; 314 priv->last_blink_time = 0;
311 return; 315 return;
312 } 316 }
313 317
314 if (!priv->allow_blinking) { 318 if (!priv->allow_blinking) {
315 priv->last_blink_time = 0; 319 priv->last_blink_time = 0;
316 if (priv->last_blink_rate != IWL_LED_SOLID) { 320 if (priv->last_blink_rate != IWL_SOLID_BLINK_IDX) {
317 priv->last_blink_rate = IWL_LED_SOLID; 321 priv->last_blink_rate = IWL_SOLID_BLINK_IDX;
318 iwl4965_led_on(priv, IWL_LED_LINK); 322 iwl4965_led_pattern(priv, IWL_LED_LINK,
323 IWL_SOLID_BLINK_IDX);
319 } 324 }
320 return; 325 return;
321 } 326 }
@@ -324,21 +329,14 @@ void iwl_leds_background(struct iwl_priv *priv)
324 msecs_to_jiffies(1000))) 329 msecs_to_jiffies(1000)))
325 return; 330 return;
326 331
327 blink_rate = get_blink_rate(priv); 332 blink_idx = iwl_get_blink_rate(priv);
328 333
329 /* call only if blink rate change */ 334 /* call only if blink rate change */
330 if (blink_rate != priv->last_blink_rate) { 335 if (blink_idx != priv->last_blink_rate)
331 if (blink_rate != IWL_LED_SOLID) { 336 iwl4965_led_pattern(priv, IWL_LED_LINK, blink_idx);
332 priv->last_blink_time = jiffies +
333 msecs_to_jiffies(1000);
334 iwl4965_led_not_solid(priv, IWL_LED_LINK, blink_rate);
335 } else {
336 priv->last_blink_time = 0;
337 iwl4965_led_on(priv, IWL_LED_LINK);
338 }
339 }
340 337
341 priv->last_blink_rate = blink_rate; 338 priv->last_blink_time = jiffies;
339 priv->last_blink_rate = blink_idx;
342} 340}
343EXPORT_SYMBOL(iwl_leds_background); 341EXPORT_SYMBOL(iwl_leds_background);
344 342
@@ -346,7 +344,6 @@ EXPORT_SYMBOL(iwl_leds_background);
346int iwl_leds_register(struct iwl_priv *priv) 344int iwl_leds_register(struct iwl_priv *priv)
347{ 345{
348 char *trigger; 346 char *trigger;
349 char name[32];
350 int ret; 347 int ret;
351 348
352 priv->last_blink_rate = 0; 349 priv->last_blink_rate = 0;
@@ -355,62 +352,60 @@ int iwl_leds_register(struct iwl_priv *priv)
355 priv->allow_blinking = 0; 352 priv->allow_blinking = 0;
356 353
357 trigger = ieee80211_get_radio_led_name(priv->hw); 354 trigger = ieee80211_get_radio_led_name(priv->hw);
358 snprintf(name, sizeof(name), "iwl-%s:radio", 355 snprintf(priv->led[IWL_LED_TRG_RADIO].name,
356 sizeof(priv->led[IWL_LED_TRG_RADIO].name), "iwl-%s:radio",
359 wiphy_name(priv->hw->wiphy)); 357 wiphy_name(priv->hw->wiphy));
360 358
361 priv->led[IWL_LED_TRG_RADIO].led_on = iwl4965_led_on_reg; 359 priv->led[IWL_LED_TRG_RADIO].led_on = iwl4965_led_on_reg;
362 priv->led[IWL_LED_TRG_RADIO].led_off = iwl4965_led_off_reg; 360 priv->led[IWL_LED_TRG_RADIO].led_off = iwl4965_led_off_reg;
363 priv->led[IWL_LED_TRG_RADIO].led_pattern = NULL; 361 priv->led[IWL_LED_TRG_RADIO].led_pattern = NULL;
364 362
365 ret = iwl_leds_register_led(priv, 363 ret = iwl_leds_register_led(priv, &priv->led[IWL_LED_TRG_RADIO],
366 &priv->led[IWL_LED_TRG_RADIO], 364 IWL_LED_TRG_RADIO, 1, trigger);
367 IWL_LED_TRG_RADIO, 1,
368 name, trigger);
369 if (ret) 365 if (ret)
370 goto exit_fail; 366 goto exit_fail;
371 367
372 trigger = ieee80211_get_assoc_led_name(priv->hw); 368 trigger = ieee80211_get_assoc_led_name(priv->hw);
373 snprintf(name, sizeof(name), "iwl-%s:assoc", 369 snprintf(priv->led[IWL_LED_TRG_ASSOC].name,
370 sizeof(priv->led[IWL_LED_TRG_ASSOC].name), "iwl-%s:assoc",
374 wiphy_name(priv->hw->wiphy)); 371 wiphy_name(priv->hw->wiphy));
375 372
376 ret = iwl_leds_register_led(priv, 373 ret = iwl_leds_register_led(priv, &priv->led[IWL_LED_TRG_ASSOC],
377 &priv->led[IWL_LED_TRG_ASSOC], 374 IWL_LED_TRG_ASSOC, 0, trigger);
378 IWL_LED_TRG_ASSOC, 0, 375
379 name, trigger);
380 /* for assoc always turn led on */ 376 /* for assoc always turn led on */
381 priv->led[IWL_LED_TRG_ASSOC].led_on = iwl4965_led_on_reg; 377 priv->led[IWL_LED_TRG_ASSOC].led_on = iwl_led_associate;
382 priv->led[IWL_LED_TRG_ASSOC].led_off = iwl4965_led_on_reg; 378 priv->led[IWL_LED_TRG_ASSOC].led_off = iwl_led_disassociate;
383 priv->led[IWL_LED_TRG_ASSOC].led_pattern = NULL; 379 priv->led[IWL_LED_TRG_ASSOC].led_pattern = NULL;
384 380
385 if (ret) 381 if (ret)
386 goto exit_fail; 382 goto exit_fail;
387 383
388 trigger = ieee80211_get_rx_led_name(priv->hw); 384 trigger = ieee80211_get_rx_led_name(priv->hw);
389 snprintf(name, sizeof(name), "iwl-%s:RX", 385 snprintf(priv->led[IWL_LED_TRG_RX].name,
386 sizeof(priv->led[IWL_LED_TRG_RX].name), "iwl-%s:RX",
390 wiphy_name(priv->hw->wiphy)); 387 wiphy_name(priv->hw->wiphy));
391 388
389 ret = iwl_leds_register_led(priv, &priv->led[IWL_LED_TRG_RX],
390 IWL_LED_TRG_RX, 0, trigger);
392 391
393 ret = iwl_leds_register_led(priv, 392 priv->led[IWL_LED_TRG_RX].led_on = iwl_led_associated;
394 &priv->led[IWL_LED_TRG_RX], 393 priv->led[IWL_LED_TRG_RX].led_off = iwl_led_associated;
395 IWL_LED_TRG_RX, 0,
396 name, trigger);
397
398 priv->led[IWL_LED_TRG_RX].led_on = iwl4965_led_associated;
399 priv->led[IWL_LED_TRG_RX].led_off = iwl4965_led_associated;
400 priv->led[IWL_LED_TRG_RX].led_pattern = iwl4965_led_pattern; 394 priv->led[IWL_LED_TRG_RX].led_pattern = iwl4965_led_pattern;
401 395
402 if (ret) 396 if (ret)
403 goto exit_fail; 397 goto exit_fail;
404 398
405 trigger = ieee80211_get_tx_led_name(priv->hw); 399 trigger = ieee80211_get_tx_led_name(priv->hw);
406 snprintf(name, sizeof(name), "iwl-%s:TX", 400 snprintf(priv->led[IWL_LED_TRG_TX].name,
401 sizeof(priv->led[IWL_LED_TRG_TX].name), "iwl-%s:TX",
407 wiphy_name(priv->hw->wiphy)); 402 wiphy_name(priv->hw->wiphy));
408 ret = iwl_leds_register_led(priv, 403
409 &priv->led[IWL_LED_TRG_TX], 404 ret = iwl_leds_register_led(priv, &priv->led[IWL_LED_TRG_TX],
410 IWL_LED_TRG_TX, 0, 405 IWL_LED_TRG_TX, 0, trigger);
411 name, trigger); 406
412 priv->led[IWL_LED_TRG_TX].led_on = iwl4965_led_associated; 407 priv->led[IWL_LED_TRG_TX].led_on = iwl_led_associated;
413 priv->led[IWL_LED_TRG_TX].led_off = iwl4965_led_associated; 408 priv->led[IWL_LED_TRG_TX].led_off = iwl_led_associated;
414 priv->led[IWL_LED_TRG_TX].led_pattern = iwl4965_led_pattern; 409 priv->led[IWL_LED_TRG_TX].led_pattern = iwl4965_led_pattern;
415 410
416 if (ret) 411 if (ret)
@@ -425,7 +420,7 @@ exit_fail:
425EXPORT_SYMBOL(iwl_leds_register); 420EXPORT_SYMBOL(iwl_leds_register);
426 421
427/* unregister led class */ 422/* unregister led class */
428static void iwl_leds_unregister_led(struct iwl4965_led *led, u8 set_led) 423static void iwl_leds_unregister_led(struct iwl_led *led, u8 set_led)
429{ 424{
430 if (!led->registered) 425 if (!led->registered)
431 return; 426 return;
diff --git a/drivers/net/wireless/iwlwifi/iwl-led.h b/drivers/net/wireless/iwlwifi/iwl-led.h
index 5bb04128cd65..588c9ad20e83 100644
--- a/drivers/net/wireless/iwlwifi/iwl-led.h
+++ b/drivers/net/wireless/iwlwifi/iwl-led.h
@@ -49,14 +49,14 @@ enum led_type {
49}; 49};
50 50
51 51
52struct iwl4965_led { 52struct iwl_led {
53 struct iwl_priv *priv; 53 struct iwl_priv *priv;
54 struct led_classdev led_dev; 54 struct led_classdev led_dev;
55 char name[32];
55 56
56 int (*led_on) (struct iwl_priv *priv, int led_id); 57 int (*led_on) (struct iwl_priv *priv, int led_id);
57 int (*led_off) (struct iwl_priv *priv, int led_id); 58 int (*led_off) (struct iwl_priv *priv, int led_id);
58 int (*led_pattern) (struct iwl_priv *priv, int led_id, 59 int (*led_pattern) (struct iwl_priv *priv, int led_id, unsigned int idx);
59 enum led_brightness brightness);
60 60
61 enum led_type type; 61 enum led_type type;
62 unsigned int registered; 62 unsigned int registered;
diff --git a/drivers/net/wireless/iwlwifi/iwl-power.c b/drivers/net/wireless/iwlwifi/iwl-power.c
new file mode 100644
index 000000000000..60a03d2d2d0e
--- /dev/null
+++ b/drivers/net/wireless/iwlwifi/iwl-power.c
@@ -0,0 +1,465 @@
1/******************************************************************************
2 *
3 * Copyright(c) 2007 - 2008 Intel Corporation. All rights reserved.
4 *
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
20 *
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
23 *
24 * Contact Information:
25 * James P. Ketrenos <ipw2100-admin@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *****************************************************************************/
28
29
30#include <linux/kernel.h>
31#include <linux/module.h>
32#include <linux/init.h>
33
34#include <net/mac80211.h>
35
36#include "iwl-eeprom.h"
37#include "iwl-dev.h"
38#include "iwl-core.h"
39#include "iwl-commands.h"
40#include "iwl-debug.h"
41#include "iwl-power.h"
42#include "iwl-helpers.h"
43
44/*
45 * Setting power level allow the card to go to sleep when not busy
46 * there are three factor that decide the power level to go to, they
47 * are list here with its priority
48 * 1- critical_power_setting this will be set according to card temperature.
49 * 2- system_power_setting this will be set by system PM manager.
50 * 3- user_power_setting this will be set by user either by writing to sys or
51 * mac80211
52 *
53 * if system_power_setting and user_power_setting is set to auto
54 * the power level will be decided according to association status and battery
55 * status.
56 *
57 */
58
59#define MSEC_TO_USEC 1024
60#define IWL_POWER_RANGE_0_MAX (2)
61#define IWL_POWER_RANGE_1_MAX (10)
62
63
64#define NOSLP __constant_cpu_to_le16(0), 0, 0
65#define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK, 0, 0
66#define SLP_TOUT(T) __constant_cpu_to_le32((T) * MSEC_TO_USEC)
67#define SLP_VEC(X0, X1, X2, X3, X4) {__constant_cpu_to_le32(X0), \
68 __constant_cpu_to_le32(X1), \
69 __constant_cpu_to_le32(X2), \
70 __constant_cpu_to_le32(X3), \
71 __constant_cpu_to_le32(X4)}
72
73#define IWL_POWER_ON_BATTERY IWL_POWER_INDEX_5
74#define IWL_POWER_ON_AC_DISASSOC IWL_POWER_MODE_CAM
75#define IWL_POWER_ON_AC_ASSOC IWL_POWER_MODE_CAM
76
77
78#define IWL_CT_KILL_TEMPERATURE 110
79#define IWL_MIN_POWER_TEMPERATURE 100
80#define IWL_REDUCED_POWER_TEMPERATURE 95
81
82/* default power management (not Tx power) table values */
83/* for tim 0-10 */
84static struct iwl_power_vec_entry range_0[IWL_POWER_MAX] = {
85 {{NOSLP, SLP_TOUT(0), SLP_TOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
86 {{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 2, 2, 0xFF)}, 0},
87 {{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(1, 2, 2, 2, 0xFF)}, 0},
88 {{SLP, SLP_TOUT(50), SLP_TOUT(100), SLP_VEC(2, 2, 2, 2, 0xFF)}, 0},
89 {{SLP, SLP_TOUT(50), SLP_TOUT(25), SLP_VEC(2, 2, 4, 4, 0xFF)}, 1},
90 {{SLP, SLP_TOUT(25), SLP_TOUT(25), SLP_VEC(2, 2, 4, 6, 0xFF)}, 2}
91};
92
93
94/* for tim = 3-10 */
95static struct iwl_power_vec_entry range_1[IWL_POWER_MAX] = {
96 {{NOSLP, SLP_TOUT(0), SLP_TOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
97 {{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0},
98 {{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(1, 2, 3, 4, 7)}, 0},
99 {{SLP, SLP_TOUT(50), SLP_TOUT(100), SLP_VEC(2, 4, 6, 7, 9)}, 0},
100 {{SLP, SLP_TOUT(50), SLP_TOUT(25), SLP_VEC(2, 4, 6, 9, 10)}, 1},
101 {{SLP, SLP_TOUT(25), SLP_TOUT(25), SLP_VEC(2, 4, 7, 10, 10)}, 2}
102};
103
104/* for tim > 11 */
105static struct iwl_power_vec_entry range_2[IWL_POWER_MAX] = {
106 {{NOSLP, SLP_TOUT(0), SLP_TOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
107 {{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 3, 4, 0xFF)}, 0},
108 {{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(2, 4, 6, 7, 0xFF)}, 0},
109 {{SLP, SLP_TOUT(50), SLP_TOUT(100), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0},
110 {{SLP, SLP_TOUT(50), SLP_TOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0},
111 {{SLP, SLP_TOUT(25), SLP_TOUT(25), SLP_VEC(4, 7, 10, 10, 0xFF)}, 0}
112};
113
114/* set card power command */
115static int iwl_set_power(struct iwl_priv *priv, void *cmd)
116{
117 return iwl_send_cmd_pdu_async(priv, POWER_TABLE_CMD,
118 sizeof(struct iwl_powertable_cmd),
119 cmd, NULL);
120}
121/* decide the right power level according to association status
122 * and battery status
123 */
124static u16 iwl_get_auto_power_mode(struct iwl_priv *priv)
125{
126 u16 mode;
127
128 switch (priv->power_data.user_power_setting) {
129 case IWL_POWER_AUTO:
130 /* if running on battery */
131 if (priv->power_data.is_battery_active)
132 mode = IWL_POWER_ON_BATTERY;
133 else if (iwl_is_associated(priv))
134 mode = IWL_POWER_ON_AC_ASSOC;
135 else
136 mode = IWL_POWER_ON_AC_DISASSOC;
137 break;
138 /* FIXME: remove battery and ac from here */
139 case IWL_POWER_BATTERY:
140 mode = IWL_POWER_INDEX_3;
141 break;
142 case IWL_POWER_AC:
143 mode = IWL_POWER_MODE_CAM;
144 break;
145 default:
146 mode = priv->power_data.user_power_setting;
147 break;
148 }
149 return mode;
150}
151
152/* initialize to default */
153static int iwl_power_init_handle(struct iwl_priv *priv)
154{
155 struct iwl_power_mgr *pow_data;
156 int size = sizeof(struct iwl_power_vec_entry) * IWL_POWER_MAX;
157 struct iwl_powertable_cmd *cmd;
158 int i;
159 u16 pci_pm;
160
161 IWL_DEBUG_POWER("Initialize power \n");
162
163 pow_data = &(priv->power_data);
164
165 memset(pow_data, 0, sizeof(*pow_data));
166
167 memcpy(&pow_data->pwr_range_0[0], &range_0[0], size);
168 memcpy(&pow_data->pwr_range_1[0], &range_1[0], size);
169 memcpy(&pow_data->pwr_range_2[0], &range_2[0], size);
170
171 pci_read_config_word(priv->pci_dev, PCI_CFG_LINK_CTRL, &pci_pm);
172
173 IWL_DEBUG_POWER("adjust power command flags\n");
174
175 for (i = 0; i < IWL_POWER_MAX; i++) {
176 cmd = &pow_data->pwr_range_0[i].cmd;
177
178 if (pci_pm & PCI_CFG_LINK_CTRL_VAL_L0S_EN)
179 cmd->flags &= ~IWL_POWER_PCI_PM_MSK;
180 else
181 cmd->flags |= IWL_POWER_PCI_PM_MSK;
182 }
183 return 0;
184}
185
186/* adjust power command according to dtim period and power level*/
187static int iwl_update_power_command(struct iwl_priv *priv,
188 struct iwl_powertable_cmd *cmd,
189 u16 mode)
190{
191 int ret = 0, i;
192 u8 skip;
193 u32 max_sleep = 0;
194 struct iwl_power_vec_entry *range;
195 u8 period = 0;
196 struct iwl_power_mgr *pow_data;
197
198 if (mode > IWL_POWER_INDEX_5) {
199 IWL_DEBUG_POWER("Error invalid power mode \n");
200 return -1;
201 }
202 pow_data = &(priv->power_data);
203
204 if (pow_data->dtim_period <= IWL_POWER_RANGE_0_MAX)
205 range = &pow_data->pwr_range_0[0];
206 else if (pow_data->dtim_period <= IWL_POWER_RANGE_1_MAX)
207 range = &pow_data->pwr_range_1[0];
208 else
209 range = &pow_data->pwr_range_2[0];
210
211 period = pow_data->dtim_period;
212 memcpy(cmd, &range[mode].cmd, sizeof(struct iwl_powertable_cmd));
213
214 if (period == 0) {
215 period = 1;
216 skip = 0;
217 } else
218 skip = range[mode].no_dtim;
219
220 if (skip == 0) {
221 max_sleep = period;
222 cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK;
223 } else {
224 __le32 slp_itrvl = cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1];
225 max_sleep = le32_to_cpu(slp_itrvl);
226 if (max_sleep == 0xFF)
227 max_sleep = period * (skip + 1);
228 else if (max_sleep > period)
229 max_sleep = (le32_to_cpu(slp_itrvl) / period) * period;
230 cmd->flags |= IWL_POWER_SLEEP_OVER_DTIM_MSK;
231 }
232
233 for (i = 0; i < IWL_POWER_VEC_SIZE; i++) {
234 if (le32_to_cpu(cmd->sleep_interval[i]) > max_sleep)
235 cmd->sleep_interval[i] = cpu_to_le32(max_sleep);
236 }
237
238 IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd->flags);
239 IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd->tx_data_timeout));
240 IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd->rx_data_timeout));
241 IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n",
242 le32_to_cpu(cmd->sleep_interval[0]),
243 le32_to_cpu(cmd->sleep_interval[1]),
244 le32_to_cpu(cmd->sleep_interval[2]),
245 le32_to_cpu(cmd->sleep_interval[3]),
246 le32_to_cpu(cmd->sleep_interval[4]));
247
248 return ret;
249}
250
251
252/*
253 * compute the final power mode index
254 */
255int iwl_power_update_mode(struct iwl_priv *priv, bool force)
256{
257 struct iwl_power_mgr *setting = &(priv->power_data);
258 int ret = 0;
259 u16 uninitialized_var(final_mode);
260
261 /* Don't update the RX chain when chain noise calibration is running */
262 if (priv->chain_noise_data.state != IWL_CHAIN_NOISE_DONE &&
263 priv->chain_noise_data.state != IWL_CHAIN_NOISE_ALIVE) {
264 IWL_DEBUG_POWER("Cannot update the power, chain noise "
265 "calibration running: %d\n",
266 priv->chain_noise_data.state);
267 return -EAGAIN;
268 }
269
270 /* If on battery, set to 3,
271 * if plugged into AC power, set to CAM ("continuously aware mode"),
272 * else user level */
273
274 switch (setting->system_power_setting) {
275 case IWL_POWER_SYS_AUTO:
276 final_mode = iwl_get_auto_power_mode(priv);
277 break;
278 case IWL_POWER_SYS_BATTERY:
279 final_mode = IWL_POWER_INDEX_3;
280 break;
281 case IWL_POWER_SYS_AC:
282 final_mode = IWL_POWER_MODE_CAM;
283 break;
284 default:
285 final_mode = IWL_POWER_INDEX_3;
286 WARN_ON(1);
287 }
288
289 if (setting->critical_power_setting > final_mode)
290 final_mode = setting->critical_power_setting;
291
292 /* driver only support CAM for non STA network */
293 if (priv->iw_mode != NL80211_IFTYPE_STATION)
294 final_mode = IWL_POWER_MODE_CAM;
295
296 if (!iwl_is_rfkill(priv) && !setting->power_disabled &&
297 ((setting->power_mode != final_mode) || force)) {
298 struct iwl_powertable_cmd cmd;
299
300 if (final_mode != IWL_POWER_MODE_CAM)
301 set_bit(STATUS_POWER_PMI, &priv->status);
302
303 iwl_update_power_command(priv, &cmd, final_mode);
304 cmd.keep_alive_beacons = 0;
305
306 if (final_mode == IWL_POWER_INDEX_5)
307 cmd.flags |= IWL_POWER_FAST_PD;
308
309 ret = iwl_set_power(priv, &cmd);
310
311 if (final_mode == IWL_POWER_MODE_CAM)
312 clear_bit(STATUS_POWER_PMI, &priv->status);
313 else
314 set_bit(STATUS_POWER_PMI, &priv->status);
315
316 if (priv->cfg->ops->lib->update_chain_flags)
317 priv->cfg->ops->lib->update_chain_flags(priv);
318
319 if (!ret)
320 setting->power_mode = final_mode;
321 }
322
323 return ret;
324}
325EXPORT_SYMBOL(iwl_power_update_mode);
326
327/* Allow other iwl code to disable/enable power management active
328 * this will be usefull for rate scale to disable PM during heavy
329 * Tx/Rx activities
330 */
331int iwl_power_disable_management(struct iwl_priv *priv, u32 ms)
332{
333 u16 prev_mode;
334 int ret = 0;
335
336 if (priv->power_data.power_disabled)
337 return -EBUSY;
338
339 prev_mode = priv->power_data.user_power_setting;
340 priv->power_data.user_power_setting = IWL_POWER_MODE_CAM;
341 ret = iwl_power_update_mode(priv, 0);
342 priv->power_data.power_disabled = 1;
343 priv->power_data.user_power_setting = prev_mode;
344 cancel_delayed_work(&priv->set_power_save);
345 if (ms)
346 queue_delayed_work(priv->workqueue, &priv->set_power_save,
347 msecs_to_jiffies(ms));
348
349
350 return ret;
351}
352EXPORT_SYMBOL(iwl_power_disable_management);
353
354/* Allow other iwl code to disable/enable power management active
355 * this will be usefull for rate scale to disable PM during hight
356 * valume activities
357 */
358int iwl_power_enable_management(struct iwl_priv *priv)
359{
360 int ret = 0;
361
362 priv->power_data.power_disabled = 0;
363 ret = iwl_power_update_mode(priv, 0);
364 return ret;
365}
366EXPORT_SYMBOL(iwl_power_enable_management);
367
368/* set user_power_setting */
369int iwl_power_set_user_mode(struct iwl_priv *priv, u16 mode)
370{
371 if (mode > IWL_POWER_LIMIT)
372 return -EINVAL;
373
374 priv->power_data.user_power_setting = mode;
375
376 return iwl_power_update_mode(priv, 0);
377}
378EXPORT_SYMBOL(iwl_power_set_user_mode);
379
380/* set system_power_setting. This should be set by over all
381 * PM application.
382 */
383int iwl_power_set_system_mode(struct iwl_priv *priv, u16 mode)
384{
385 if (mode > IWL_POWER_LIMIT)
386 return -EINVAL;
387
388 priv->power_data.system_power_setting = mode;
389
390 return iwl_power_update_mode(priv, 0);
391}
392EXPORT_SYMBOL(iwl_power_set_system_mode);
393
394/* initilize to default */
395void iwl_power_initialize(struct iwl_priv *priv)
396{
397
398 iwl_power_init_handle(priv);
399 priv->power_data.user_power_setting = IWL_POWER_AUTO;
400 priv->power_data.power_disabled = 0;
401 priv->power_data.system_power_setting = IWL_POWER_SYS_AUTO;
402 priv->power_data.is_battery_active = 0;
403 priv->power_data.power_disabled = 0;
404 priv->power_data.critical_power_setting = 0;
405}
406EXPORT_SYMBOL(iwl_power_initialize);
407
408/* set critical_power_setting according to temperature value */
409int iwl_power_temperature_change(struct iwl_priv *priv)
410{
411 int ret = 0;
412 u16 new_critical = priv->power_data.critical_power_setting;
413 s32 temperature = KELVIN_TO_CELSIUS(priv->last_temperature);
414
415 if (temperature > IWL_CT_KILL_TEMPERATURE)
416 return 0;
417 else if (temperature > IWL_MIN_POWER_TEMPERATURE)
418 new_critical = IWL_POWER_INDEX_5;
419 else if (temperature > IWL_REDUCED_POWER_TEMPERATURE)
420 new_critical = IWL_POWER_INDEX_3;
421 else
422 new_critical = IWL_POWER_MODE_CAM;
423
424 if (new_critical != priv->power_data.critical_power_setting)
425 priv->power_data.critical_power_setting = new_critical;
426
427 if (priv->power_data.critical_power_setting >
428 priv->power_data.power_mode)
429 ret = iwl_power_update_mode(priv, 0);
430
431 return ret;
432}
433EXPORT_SYMBOL(iwl_power_temperature_change);
434
435static void iwl_bg_set_power_save(struct work_struct *work)
436{
437 struct iwl_priv *priv = container_of(work,
438 struct iwl_priv, set_power_save.work);
439 IWL_DEBUG(IWL_DL_STATE, "update power\n");
440
441 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
442 return;
443
444 mutex_lock(&priv->mutex);
445
446 /* on starting association we disable power managment
447 * until association, if association failed then this
448 * timer will expire and enable PM again.
449 */
450 if (!iwl_is_associated(priv))
451 iwl_power_enable_management(priv);
452
453 mutex_unlock(&priv->mutex);
454}
455void iwl_setup_power_deferred_work(struct iwl_priv *priv)
456{
457 INIT_DELAYED_WORK(&priv->set_power_save, iwl_bg_set_power_save);
458}
459EXPORT_SYMBOL(iwl_setup_power_deferred_work);
460
461void iwl_power_cancel_timeout(struct iwl_priv *priv)
462{
463 cancel_delayed_work(&priv->set_power_save);
464}
465EXPORT_SYMBOL(iwl_power_cancel_timeout);
diff --git a/drivers/net/wireless/iwlwifi/iwl-power.h b/drivers/net/wireless/iwlwifi/iwl-power.h
new file mode 100644
index 000000000000..df484a90ae64
--- /dev/null
+++ b/drivers/net/wireless/iwlwifi/iwl-power.h
@@ -0,0 +1,91 @@
1/******************************************************************************
2 *
3 * Copyright(c) 2007 - 2008 Intel Corporation. All rights reserved.
4 *
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
20 *
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
23 *
24 * Contact Information:
25 * James P. Ketrenos <ipw2100-admin@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *****************************************************************************/
28#ifndef __iwl_power_setting_h__
29#define __iwl_power_setting_h__
30
31#include <net/mac80211.h>
32#include "iwl-commands.h"
33
34struct iwl_priv;
35
36enum {
37 IWL_POWER_MODE_CAM, /* Continuously Aware Mode, always on */
38 IWL_POWER_INDEX_1,
39 IWL_POWER_INDEX_2,
40 IWL_POWER_INDEX_3,
41 IWL_POWER_INDEX_4,
42 IWL_POWER_INDEX_5,
43 IWL_POWER_AUTO,
44 IWL_POWER_MAX = IWL_POWER_AUTO,
45 IWL_POWER_AC,
46 IWL_POWER_BATTERY,
47};
48
49enum {
50 IWL_POWER_SYS_AUTO,
51 IWL_POWER_SYS_AC,
52 IWL_POWER_SYS_BATTERY,
53};
54
55#define IWL_POWER_LIMIT 0x08
56#define IWL_POWER_MASK 0x0F
57#define IWL_POWER_ENABLED 0x10
58
59/* Power management (not Tx power) structures */
60
61struct iwl_power_vec_entry {
62 struct iwl_powertable_cmd cmd;
63 u8 no_dtim;
64};
65
66struct iwl_power_mgr {
67 spinlock_t lock;
68 struct iwl_power_vec_entry pwr_range_0[IWL_POWER_MAX];
69 struct iwl_power_vec_entry pwr_range_1[IWL_POWER_MAX];
70 struct iwl_power_vec_entry pwr_range_2[IWL_POWER_MAX];
71 u32 dtim_period;
72 /* final power level that used to calculate final power command */
73 u8 power_mode;
74 u8 user_power_setting; /* set by user through mac80211 or sysfs */
75 u8 system_power_setting; /* set by kernel system tools */
76 u8 critical_power_setting; /* set if driver over heated */
77 u8 is_battery_active; /* DC/AC power */
78 u8 power_disabled; /* flag to disable using power saving level */
79};
80
81void iwl_setup_power_deferred_work(struct iwl_priv *priv);
82void iwl_power_cancel_timeout(struct iwl_priv *priv);
83int iwl_power_update_mode(struct iwl_priv *priv, bool force);
84int iwl_power_disable_management(struct iwl_priv *priv, u32 ms);
85int iwl_power_enable_management(struct iwl_priv *priv);
86int iwl_power_set_user_mode(struct iwl_priv *priv, u16 mode);
87int iwl_power_set_system_mode(struct iwl_priv *priv, u16 mode);
88void iwl_power_initialize(struct iwl_priv *priv);
89int iwl_power_temperature_change(struct iwl_priv *priv);
90
91#endif /* __iwl_power_setting_h__ */
diff --git a/drivers/net/wireless/iwlwifi/iwl-prph.h b/drivers/net/wireless/iwlwifi/iwl-prph.h
index c9cf8eef1a90..ee5afd48d3af 100644
--- a/drivers/net/wireless/iwlwifi/iwl-prph.h
+++ b/drivers/net/wireless/iwlwifi/iwl-prph.h
@@ -84,14 +84,16 @@
84#define APMG_CLK_VAL_DMA_CLK_RQT (0x00000200) 84#define APMG_CLK_VAL_DMA_CLK_RQT (0x00000200)
85#define APMG_CLK_VAL_BSM_CLK_RQT (0x00000800) 85#define APMG_CLK_VAL_BSM_CLK_RQT (0x00000800)
86 86
87#define APMG_PS_CTRL_VAL_RESET_REQ (0x04000000)
88 87
89#define APMG_PCIDEV_STT_VAL_L1_ACT_DIS (0x00000800) 88#define APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS (0x00400000)
89#define APMG_PS_CTRL_VAL_RESET_REQ (0x04000000)
90#define APMG_PS_CTRL_MSK_PWR_SRC (0x03000000)
91#define APMG_PS_CTRL_VAL_PWR_SRC_VMAIN (0x00000000)
92#define APMG_PS_CTRL_VAL_PWR_SRC_MAX (0x01000000) /* 3945 only */
93#define APMG_PS_CTRL_VAL_PWR_SRC_VAUX (0x02000000)
90 94
91#define APMG_PS_CTRL_MSK_PWR_SRC (0x03000000)
92#define APMG_PS_CTRL_VAL_PWR_SRC_VMAIN (0x00000000)
93#define APMG_PS_CTRL_VAL_PWR_SRC_VAUX (0x01000000)
94 95
96#define APMG_PCIDEV_STT_VAL_L1_ACT_DIS (0x00000800)
95 97
96/** 98/**
97 * BSM (Bootstrap State Machine) 99 * BSM (Bootstrap State Machine)
@@ -239,40 +241,307 @@
239#define ALM_SCD_SBYP_MODE_1_REG (ALM_SCD_BASE + 0x02C) 241#define ALM_SCD_SBYP_MODE_1_REG (ALM_SCD_BASE + 0x02C)
240#define ALM_SCD_SBYP_MODE_2_REG (ALM_SCD_BASE + 0x030) 242#define ALM_SCD_SBYP_MODE_2_REG (ALM_SCD_BASE + 0x030)
241 243
244/**
245 * Tx Scheduler
246 *
247 * The Tx Scheduler selects the next frame to be transmitted, chosing TFDs
248 * (Transmit Frame Descriptors) from up to 16 circular Tx queues resident in
249 * host DRAM. It steers each frame's Tx command (which contains the frame
250 * data) into one of up to 7 prioritized Tx DMA FIFO channels within the
251 * device. A queue maps to only one (selectable by driver) Tx DMA channel,
252 * but one DMA channel may take input from several queues.
253 *
254 * Tx DMA channels have dedicated purposes. For 4965, they are used as follows:
255 *
256 * 0 -- EDCA BK (background) frames, lowest priority
257 * 1 -- EDCA BE (best effort) frames, normal priority
258 * 2 -- EDCA VI (video) frames, higher priority
259 * 3 -- EDCA VO (voice) and management frames, highest priority
260 * 4 -- Commands (e.g. RXON, etc.)
261 * 5 -- HCCA short frames
262 * 6 -- HCCA long frames
263 * 7 -- not used by driver (device-internal only)
264 *
265 * Driver should normally map queues 0-6 to Tx DMA/FIFO channels 0-6.
266 * In addition, driver can map queues 7-15 to Tx DMA/FIFO channels 0-3 to
267 * support 11n aggregation via EDCA DMA channels.
268 *
269 * The driver sets up each queue to work in one of two modes:
270 *
271 * 1) Scheduler-Ack, in which the scheduler automatically supports a
272 * block-ack (BA) window of up to 64 TFDs. In this mode, each queue
273 * contains TFDs for a unique combination of Recipient Address (RA)
274 * and Traffic Identifier (TID), that is, traffic of a given
275 * Quality-Of-Service (QOS) priority, destined for a single station.
276 *
277 * In scheduler-ack mode, the scheduler keeps track of the Tx status of
278 * each frame within the BA window, including whether it's been transmitted,
279 * and whether it's been acknowledged by the receiving station. The device
280 * automatically processes block-acks received from the receiving STA,
281 * and reschedules un-acked frames to be retransmitted (successful
282 * Tx completion may end up being out-of-order).
283 *
284 * The driver must maintain the queue's Byte Count table in host DRAM
285 * (struct iwl4965_sched_queue_byte_cnt_tbl) for this mode.
286 * This mode does not support fragmentation.
287 *
288 * 2) FIFO (a.k.a. non-Scheduler-ACK), in which each TFD is processed in order.
289 * The device may automatically retry Tx, but will retry only one frame
290 * at a time, until receiving ACK from receiving station, or reaching
291 * retry limit and giving up.
292 *
293 * The command queue (#4) must use this mode!
294 * This mode does not require use of the Byte Count table in host DRAM.
295 *
296 * Driver controls scheduler operation via 3 means:
297 * 1) Scheduler registers
298 * 2) Shared scheduler data base in internal 4956 SRAM
299 * 3) Shared data in host DRAM
300 *
301 * Initialization:
302 *
303 * When loading, driver should allocate memory for:
304 * 1) 16 TFD circular buffers, each with space for (typically) 256 TFDs.
305 * 2) 16 Byte Count circular buffers in 16 KBytes contiguous memory
306 * (1024 bytes for each queue).
307 *
308 * After receiving "Alive" response from uCode, driver must initialize
309 * the scheduler (especially for queue #4, the command queue, otherwise
310 * the driver can't issue commands!):
311 */
312
313/**
314 * Max Tx window size is the max number of contiguous TFDs that the scheduler
315 * can keep track of at one time when creating block-ack chains of frames.
316 * Note that "64" matches the number of ack bits in a block-ack packet.
317 * Driver should use SCD_WIN_SIZE and SCD_FRAME_LIMIT values to initialize
318 * IWL49_SCD_CONTEXT_QUEUE_OFFSET(x) values.
319 */
320#define SCD_WIN_SIZE 64
321#define SCD_FRAME_LIMIT 64
322
323/* SCD registers are internal, must be accessed via HBUS_TARG_PRPH regs */
324#define IWL49_SCD_START_OFFSET 0xa02c00
325
326/*
327 * 4965 tells driver SRAM address for internal scheduler structs via this reg.
328 * Value is valid only after "Alive" response from uCode.
329 */
330#define IWL49_SCD_SRAM_BASE_ADDR (IWL49_SCD_START_OFFSET + 0x0)
331
332/*
333 * Driver may need to update queue-empty bits after changing queue's
334 * write and read pointers (indexes) during (re-)initialization (i.e. when
335 * scheduler is not tracking what's happening).
336 * Bit fields:
337 * 31-16: Write mask -- 1: update empty bit, 0: don't change empty bit
338 * 15-00: Empty state, one for each queue -- 1: empty, 0: non-empty
339 * NOTE: This register is not used by Linux driver.
340 */
341#define IWL49_SCD_EMPTY_BITS (IWL49_SCD_START_OFFSET + 0x4)
342
343/*
344 * Physical base address of array of byte count (BC) circular buffers (CBs).
345 * Each Tx queue has a BC CB in host DRAM to support Scheduler-ACK mode.
346 * This register points to BC CB for queue 0, must be on 1024-byte boundary.
347 * Others are spaced by 1024 bytes.
348 * Each BC CB is 2 bytes * (256 + 64) = 740 bytes, followed by 384 bytes pad.
349 * (Index into a queue's BC CB) = (index into queue's TFD CB) = (SSN & 0xff).
350 * Bit fields:
351 * 25-00: Byte Count CB physical address [35:10], must be 1024-byte aligned.
352 */
353#define IWL49_SCD_DRAM_BASE_ADDR (IWL49_SCD_START_OFFSET + 0x10)
354
355/*
356 * Enables any/all Tx DMA/FIFO channels.
357 * Scheduler generates requests for only the active channels.
358 * Set this to 0xff to enable all 8 channels (normal usage).
359 * Bit fields:
360 * 7- 0: Enable (1), disable (0), one bit for each channel 0-7
361 */
362#define IWL49_SCD_TXFACT (IWL49_SCD_START_OFFSET + 0x1c)
363/*
364 * Queue (x) Write Pointers (indexes, really!), one for each Tx queue.
365 * Initialized and updated by driver as new TFDs are added to queue.
366 * NOTE: If using Block Ack, index must correspond to frame's
367 * Start Sequence Number; index = (SSN & 0xff)
368 * NOTE: Alternative to HBUS_TARG_WRPTR, which is what Linux driver uses?
369 */
370#define IWL49_SCD_QUEUE_WRPTR(x) (IWL49_SCD_START_OFFSET + 0x24 + (x) * 4)
371
372/*
373 * Queue (x) Read Pointers (indexes, really!), one for each Tx queue.
374 * For FIFO mode, index indicates next frame to transmit.
375 * For Scheduler-ACK mode, index indicates first frame in Tx window.
376 * Initialized by driver, updated by scheduler.
377 */
378#define IWL49_SCD_QUEUE_RDPTR(x) (IWL49_SCD_START_OFFSET + 0x64 + (x) * 4)
379
380/*
381 * Select which queues work in chain mode (1) vs. not (0).
382 * Use chain mode to build chains of aggregated frames.
383 * Bit fields:
384 * 31-16: Reserved
385 * 15-00: Mode, one bit for each queue -- 1: Chain mode, 0: one-at-a-time
386 * NOTE: If driver sets up queue for chain mode, it should be also set up
387 * Scheduler-ACK mode as well, via SCD_QUEUE_STATUS_BITS(x).
388 */
389#define IWL49_SCD_QUEUECHAIN_SEL (IWL49_SCD_START_OFFSET + 0xd0)
390
391/*
392 * Select which queues interrupt driver when scheduler increments
393 * a queue's read pointer (index).
394 * Bit fields:
395 * 31-16: Reserved
396 * 15-00: Interrupt enable, one bit for each queue -- 1: enabled, 0: disabled
397 * NOTE: This functionality is apparently a no-op; driver relies on interrupts
398 * from Rx queue to read Tx command responses and update Tx queues.
399 */
400#define IWL49_SCD_INTERRUPT_MASK (IWL49_SCD_START_OFFSET + 0xe4)
401
402/*
403 * Queue search status registers. One for each queue.
404 * Sets up queue mode and assigns queue to Tx DMA channel.
405 * Bit fields:
406 * 19-10: Write mask/enable bits for bits 0-9
407 * 9: Driver should init to "0"
408 * 8: Scheduler-ACK mode (1), non-Scheduler-ACK (i.e. FIFO) mode (0).
409 * Driver should init to "1" for aggregation mode, or "0" otherwise.
410 * 7-6: Driver should init to "0"
411 * 5: Window Size Left; indicates whether scheduler can request
412 * another TFD, based on window size, etc. Driver should init
413 * this bit to "1" for aggregation mode, or "0" for non-agg.
414 * 4-1: Tx FIFO to use (range 0-7).
415 * 0: Queue is active (1), not active (0).
416 * Other bits should be written as "0"
417 *
418 * NOTE: If enabling Scheduler-ACK mode, chain mode should also be enabled
419 * via SCD_QUEUECHAIN_SEL.
420 */
421#define IWL49_SCD_QUEUE_STATUS_BITS(x)\
422 (IWL49_SCD_START_OFFSET + 0x104 + (x) * 4)
423
424/* Bit field positions */
425#define IWL49_SCD_QUEUE_STTS_REG_POS_ACTIVE (0)
426#define IWL49_SCD_QUEUE_STTS_REG_POS_TXF (1)
427#define IWL49_SCD_QUEUE_STTS_REG_POS_WSL (5)
428#define IWL49_SCD_QUEUE_STTS_REG_POS_SCD_ACK (8)
429
430/* Write masks */
431#define IWL49_SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN (10)
432#define IWL49_SCD_QUEUE_STTS_REG_MSK (0x0007FC00)
433
434/**
435 * 4965 internal SRAM structures for scheduler, shared with driver ...
436 *
437 * Driver should clear and initialize the following areas after receiving
438 * "Alive" response from 4965 uCode, i.e. after initial
439 * uCode load, or after a uCode load done for error recovery:
440 *
441 * SCD_CONTEXT_DATA_OFFSET (size 128 bytes)
442 * SCD_TX_STTS_BITMAP_OFFSET (size 256 bytes)
443 * SCD_TRANSLATE_TBL_OFFSET (size 32 bytes)
444 *
445 * Driver accesses SRAM via HBUS_TARG_MEM_* registers.
446 * Driver reads base address of this scheduler area from SCD_SRAM_BASE_ADDR.
447 * All OFFSET values must be added to this base address.
448 */
449
450/*
451 * Queue context. One 8-byte entry for each of 16 queues.
452 *
453 * Driver should clear this entire area (size 0x80) to 0 after receiving
454 * "Alive" notification from uCode. Additionally, driver should init
455 * each queue's entry as follows:
456 *
457 * LS Dword bit fields:
458 * 0-06: Max Tx window size for Scheduler-ACK. Driver should init to 64.
459 *
460 * MS Dword bit fields:
461 * 16-22: Frame limit. Driver should init to 10 (0xa).
462 *
463 * Driver should init all other bits to 0.
464 *
465 * Init must be done after driver receives "Alive" response from 4965 uCode,
466 * and when setting up queue for aggregation.
467 */
468#define IWL49_SCD_CONTEXT_DATA_OFFSET 0x380
469#define IWL49_SCD_CONTEXT_QUEUE_OFFSET(x) \
470 (IWL49_SCD_CONTEXT_DATA_OFFSET + ((x) * 8))
471
472#define IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_POS (0)
473#define IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK (0x0000007F)
474#define IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS (16)
475#define IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK (0x007F0000)
476
477/*
478 * Tx Status Bitmap
479 *
480 * Driver should clear this entire area (size 0x100) to 0 after receiving
481 * "Alive" notification from uCode. Area is used only by device itself;
482 * no other support (besides clearing) is required from driver.
483 */
484#define IWL49_SCD_TX_STTS_BITMAP_OFFSET 0x400
485
242/* 486/*
243 * 4965 Tx Scheduler registers. 487 * RAxTID to queue translation mapping.
244 * Details are documented in iwl-4965-hw.h 488 *
489 * When queue is in Scheduler-ACK mode, frames placed in a that queue must be
490 * for only one combination of receiver address (RA) and traffic ID (TID), i.e.
491 * one QOS priority level destined for one station (for this wireless link,
492 * not final destination). The SCD_TRANSLATE_TABLE area provides 16 16-bit
493 * mappings, one for each of the 16 queues. If queue is not in Scheduler-ACK
494 * mode, the device ignores the mapping value.
495 *
496 * Bit fields, for each 16-bit map:
497 * 15-9: Reserved, set to 0
498 * 8-4: Index into device's station table for recipient station
499 * 3-0: Traffic ID (tid), range 0-15
500 *
501 * Driver should clear this entire area (size 32 bytes) to 0 after receiving
502 * "Alive" notification from uCode. To update a 16-bit map value, driver
503 * must read a dword-aligned value from device SRAM, replace the 16-bit map
504 * value of interest, and write the dword value back into device SRAM.
245 */ 505 */
246#define IWL49_SCD_BASE (PRPH_BASE + 0xa02c00) 506#define IWL49_SCD_TRANSLATE_TBL_OFFSET 0x500
247 507
248#define IWL49_SCD_SRAM_BASE_ADDR (IWL49_SCD_BASE + 0x0) 508/* Find translation table dword to read/write for given queue */
249#define IWL49_SCD_EMPTY_BITS (IWL49_SCD_BASE + 0x4) 509#define IWL49_SCD_TRANSLATE_TBL_OFFSET_QUEUE(x) \
250#define IWL49_SCD_DRAM_BASE_ADDR (IWL49_SCD_BASE + 0x10) 510 ((IWL49_SCD_TRANSLATE_TBL_OFFSET + ((x) * 2)) & 0xfffffffc)
251#define IWL49_SCD_AIT (IWL49_SCD_BASE + 0x18) 511
252#define IWL49_SCD_TXFACT (IWL49_SCD_BASE + 0x1c) 512#define IWL_SCD_TXFIFO_POS_TID (0)
253#define IWL49_SCD_QUEUE_WRPTR(x) (IWL49_SCD_BASE + 0x24 + (x) * 4) 513#define IWL_SCD_TXFIFO_POS_RA (4)
254#define IWL49_SCD_QUEUE_RDPTR(x) (IWL49_SCD_BASE + 0x64 + (x) * 4) 514#define IWL_SCD_QUEUE_RA_TID_MAP_RATID_MSK (0x01FF)
255#define IWL49_SCD_SETQUEUENUM (IWL49_SCD_BASE + 0xa4) 515
256#define IWL49_SCD_SET_TXSTAT_TXED (IWL49_SCD_BASE + 0xa8) 516/* 5000 SCD */
257#define IWL49_SCD_SET_TXSTAT_DONE (IWL49_SCD_BASE + 0xac) 517#define IWL50_SCD_QUEUE_STTS_REG_POS_TXF (0)
258#define IWL49_SCD_SET_TXSTAT_NOT_SCHD (IWL49_SCD_BASE + 0xb0) 518#define IWL50_SCD_QUEUE_STTS_REG_POS_ACTIVE (3)
259#define IWL49_SCD_DECREASE_CREDIT (IWL49_SCD_BASE + 0xb4) 519#define IWL50_SCD_QUEUE_STTS_REG_POS_WSL (4)
260#define IWL49_SCD_DECREASE_SCREDIT (IWL49_SCD_BASE + 0xb8) 520#define IWL50_SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN (19)
261#define IWL49_SCD_LOAD_CREDIT (IWL49_SCD_BASE + 0xbc) 521#define IWL50_SCD_QUEUE_STTS_REG_MSK (0x00FF0000)
262#define IWL49_SCD_LOAD_SCREDIT (IWL49_SCD_BASE + 0xc0) 522
263#define IWL49_SCD_BAR (IWL49_SCD_BASE + 0xc4) 523#define IWL50_SCD_QUEUE_CTX_REG1_CREDIT_POS (8)
264#define IWL49_SCD_BAR_DW0 (IWL49_SCD_BASE + 0xc8) 524#define IWL50_SCD_QUEUE_CTX_REG1_CREDIT_MSK (0x00FFFF00)
265#define IWL49_SCD_BAR_DW1 (IWL49_SCD_BASE + 0xcc) 525#define IWL50_SCD_QUEUE_CTX_REG1_SUPER_CREDIT_POS (24)
266#define IWL49_SCD_QUEUECHAIN_SEL (IWL49_SCD_BASE + 0xd0) 526#define IWL50_SCD_QUEUE_CTX_REG1_SUPER_CREDIT_MSK (0xFF000000)
267#define IWL49_SCD_QUERY_REQ (IWL49_SCD_BASE + 0xd8) 527#define IWL50_SCD_QUEUE_CTX_REG2_WIN_SIZE_POS (0)
268#define IWL49_SCD_QUERY_RES (IWL49_SCD_BASE + 0xdc) 528#define IWL50_SCD_QUEUE_CTX_REG2_WIN_SIZE_MSK (0x0000007F)
269#define IWL49_SCD_PENDING_FRAMES (IWL49_SCD_BASE + 0xe0) 529#define IWL50_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS (16)
270#define IWL49_SCD_INTERRUPT_MASK (IWL49_SCD_BASE + 0xe4) 530#define IWL50_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK (0x007F0000)
271#define IWL49_SCD_INTERRUPT_THRESHOLD (IWL49_SCD_BASE + 0xe8) 531
272#define IWL49_SCD_QUERY_MIN_FRAME_SIZE (IWL49_SCD_BASE + 0x100) 532#define IWL50_SCD_CONTEXT_DATA_OFFSET (0x600)
273#define IWL49_SCD_QUEUE_STATUS_BITS(x) (IWL49_SCD_BASE + 0x104 + (x) * 4) 533#define IWL50_SCD_TX_STTS_BITMAP_OFFSET (0x7B1)
274 534#define IWL50_SCD_TRANSLATE_TBL_OFFSET (0x7E0)
275/* SP SCD */ 535
536#define IWL50_SCD_CONTEXT_QUEUE_OFFSET(x)\
537 (IWL50_SCD_CONTEXT_DATA_OFFSET + ((x) * 8))
538
539#define IWL50_SCD_TRANSLATE_TBL_OFFSET_QUEUE(x) \
540 ((IWL50_SCD_TRANSLATE_TBL_OFFSET + ((x) * 2)) & 0xfffc)
541
542#define IWL50_SCD_QUEUECHAIN_SEL_ALL(x) (((1<<(x)) - 1) &\
543 (~(1<<IWL_CMD_QUEUE_NUM)))
544
276#define IWL50_SCD_BASE (PRPH_BASE + 0xa02c00) 545#define IWL50_SCD_BASE (PRPH_BASE + 0xa02c00)
277 546
278#define IWL50_SCD_SRAM_BASE_ADDR (IWL50_SCD_BASE + 0x0) 547#define IWL50_SCD_SRAM_BASE_ADDR (IWL50_SCD_BASE + 0x0)
@@ -287,4 +556,6 @@
287#define IWL50_SCD_INTERRUPT_MASK (IWL50_SCD_BASE + 0x108) 556#define IWL50_SCD_INTERRUPT_MASK (IWL50_SCD_BASE + 0x108)
288#define IWL50_SCD_QUEUE_STATUS_BITS(x) (IWL50_SCD_BASE + 0x10c + (x) * 4) 557#define IWL50_SCD_QUEUE_STATUS_BITS(x) (IWL50_SCD_BASE + 0x10c + (x) * 4)
289 558
559/*********************** END TX SCHEDULER *************************************/
560
290#endif /* __iwl_prph_h__ */ 561#endif /* __iwl_prph_h__ */
diff --git a/drivers/net/wireless/iwlwifi/iwl-rfkill.c b/drivers/net/wireless/iwlwifi/iwl-rfkill.c
index 5980a5621cb8..5d642298f04c 100644
--- a/drivers/net/wireless/iwlwifi/iwl-rfkill.c
+++ b/drivers/net/wireless/iwlwifi/iwl-rfkill.c
@@ -27,13 +27,12 @@
27 *****************************************************************************/ 27 *****************************************************************************/
28#include <linux/kernel.h> 28#include <linux/kernel.h>
29#include <linux/module.h> 29#include <linux/module.h>
30#include <linux/version.h>
31#include <linux/init.h> 30#include <linux/init.h>
32 31
33#include <net/mac80211.h> 32#include <net/mac80211.h>
34 33
35#include "iwl-eeprom.h" 34#include "iwl-eeprom.h"
36#include "iwl-4965.h" 35#include "iwl-dev.h"
37#include "iwl-core.h" 36#include "iwl-core.h"
38#include "iwl-helpers.h" 37#include "iwl-helpers.h"
39 38
@@ -44,28 +43,31 @@ static int iwl_rfkill_soft_rf_kill(void *data, enum rfkill_state state)
44 struct iwl_priv *priv = data; 43 struct iwl_priv *priv = data;
45 int err = 0; 44 int err = 0;
46 45
47 if (!priv->rfkill_mngr.rfkill) 46 if (!priv->rfkill)
48 return 0; 47 return 0;
49 48
50 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) 49 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
51 return 0; 50 return 0;
52 51
53 IWL_DEBUG_RF_KILL("we recieved soft RFKILL set to state %d\n", state); 52 IWL_DEBUG_RF_KILL("we received soft RFKILL set to state %d\n", state);
54 mutex_lock(&priv->mutex); 53 mutex_lock(&priv->mutex);
55 54
56 switch (state) { 55 switch (state) {
57 case RFKILL_STATE_ON: 56 case RFKILL_STATE_UNBLOCKED:
58 priv->cfg->ops->lib->radio_kill_sw(priv, 0); 57 if (iwl_is_rfkill_hw(priv)) {
59 /* if HW rf-kill is set dont allow ON state */
60 if (iwl_is_rfkill(priv))
61 err = -EBUSY; 58 err = -EBUSY;
59 goto out_unlock;
60 }
61 iwl_radio_kill_sw_enable_radio(priv);
62 break; 62 break;
63 case RFKILL_STATE_OFF: 63 case RFKILL_STATE_SOFT_BLOCKED:
64 priv->cfg->ops->lib->radio_kill_sw(priv, 1); 64 iwl_radio_kill_sw_disable_radio(priv);
65 if (!iwl_is_rfkill(priv)) 65 break;
66 err = -EBUSY; 66 default:
67 IWL_WARNING("we recieved unexpected RFKILL state %d\n", state);
67 break; 68 break;
68 } 69 }
70out_unlock:
69 mutex_unlock(&priv->mutex); 71 mutex_unlock(&priv->mutex);
70 72
71 return err; 73 return err;
@@ -79,64 +81,35 @@ int iwl_rfkill_init(struct iwl_priv *priv)
79 BUG_ON(device == NULL); 81 BUG_ON(device == NULL);
80 82
81 IWL_DEBUG_RF_KILL("Initializing RFKILL.\n"); 83 IWL_DEBUG_RF_KILL("Initializing RFKILL.\n");
82 priv->rfkill_mngr.rfkill = rfkill_allocate(device, RFKILL_TYPE_WLAN); 84 priv->rfkill = rfkill_allocate(device, RFKILL_TYPE_WLAN);
83 if (!priv->rfkill_mngr.rfkill) { 85 if (!priv->rfkill) {
84 IWL_ERROR("Unable to allocate rfkill device.\n"); 86 IWL_ERROR("Unable to allocate rfkill device.\n");
85 ret = -ENOMEM; 87 ret = -ENOMEM;
86 goto error; 88 goto error;
87 } 89 }
88 90
89 priv->rfkill_mngr.rfkill->name = priv->cfg->name; 91 priv->rfkill->name = priv->cfg->name;
90 priv->rfkill_mngr.rfkill->data = priv; 92 priv->rfkill->data = priv;
91 priv->rfkill_mngr.rfkill->state = RFKILL_STATE_ON; 93 priv->rfkill->state = RFKILL_STATE_UNBLOCKED;
92 priv->rfkill_mngr.rfkill->toggle_radio = iwl_rfkill_soft_rf_kill; 94 priv->rfkill->toggle_radio = iwl_rfkill_soft_rf_kill;
93 priv->rfkill_mngr.rfkill->user_claim_unsupported = 1; 95 priv->rfkill->user_claim_unsupported = 1;
94 96
95 priv->rfkill_mngr.rfkill->dev.class->suspend = NULL; 97 priv->rfkill->dev.class->suspend = NULL;
96 priv->rfkill_mngr.rfkill->dev.class->resume = NULL; 98 priv->rfkill->dev.class->resume = NULL;
97 99
98 priv->rfkill_mngr.input_dev = input_allocate_device(); 100 ret = rfkill_register(priv->rfkill);
99 if (!priv->rfkill_mngr.input_dev) {
100 IWL_ERROR("Unable to allocate rfkill input device.\n");
101 ret = -ENOMEM;
102 goto freed_rfkill;
103 }
104
105 priv->rfkill_mngr.input_dev->name = priv->cfg->name;
106 priv->rfkill_mngr.input_dev->phys = wiphy_name(priv->hw->wiphy);
107 priv->rfkill_mngr.input_dev->id.bustype = BUS_HOST;
108 priv->rfkill_mngr.input_dev->id.vendor = priv->pci_dev->vendor;
109 priv->rfkill_mngr.input_dev->dev.parent = device;
110 priv->rfkill_mngr.input_dev->evbit[0] = BIT(EV_KEY);
111 set_bit(KEY_WLAN, priv->rfkill_mngr.input_dev->keybit);
112
113 ret = rfkill_register(priv->rfkill_mngr.rfkill);
114 if (ret) { 101 if (ret) {
115 IWL_ERROR("Unable to register rfkill: %d\n", ret); 102 IWL_ERROR("Unable to register rfkill: %d\n", ret);
116 goto free_input_dev; 103 goto free_rfkill;
117 }
118
119 ret = input_register_device(priv->rfkill_mngr.input_dev);
120 if (ret) {
121 IWL_ERROR("Unable to register rfkill input device: %d\n", ret);
122 goto unregister_rfkill;
123 } 104 }
124 105
125 IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n"); 106 IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n");
126 return ret; 107 return ret;
127 108
128unregister_rfkill: 109free_rfkill:
129 rfkill_unregister(priv->rfkill_mngr.rfkill); 110 if (priv->rfkill != NULL)
130 priv->rfkill_mngr.rfkill = NULL; 111 rfkill_free(priv->rfkill);
131 112 priv->rfkill = NULL;
132free_input_dev:
133 input_free_device(priv->rfkill_mngr.input_dev);
134 priv->rfkill_mngr.input_dev = NULL;
135
136freed_rfkill:
137 if (priv->rfkill_mngr.rfkill != NULL)
138 rfkill_free(priv->rfkill_mngr.rfkill);
139 priv->rfkill_mngr.rfkill = NULL;
140 113
141error: 114error:
142 IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n"); 115 IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n");
@@ -147,27 +120,27 @@ EXPORT_SYMBOL(iwl_rfkill_init);
147void iwl_rfkill_unregister(struct iwl_priv *priv) 120void iwl_rfkill_unregister(struct iwl_priv *priv)
148{ 121{
149 122
150 if (priv->rfkill_mngr.input_dev) 123 if (priv->rfkill)
151 input_unregister_device(priv->rfkill_mngr.input_dev); 124 rfkill_unregister(priv->rfkill);
152 125
153 if (priv->rfkill_mngr.rfkill) 126 priv->rfkill = NULL;
154 rfkill_unregister(priv->rfkill_mngr.rfkill);
155
156 priv->rfkill_mngr.input_dev = NULL;
157 priv->rfkill_mngr.rfkill = NULL;
158} 127}
159EXPORT_SYMBOL(iwl_rfkill_unregister); 128EXPORT_SYMBOL(iwl_rfkill_unregister);
160 129
161/* set rf-kill to the right state. */ 130/* set rf-kill to the right state. */
162void iwl_rfkill_set_hw_state(struct iwl_priv *priv) 131void iwl_rfkill_set_hw_state(struct iwl_priv *priv)
163{ 132{
133 if (!priv->rfkill)
134 return;
164 135
165 if (!priv->rfkill_mngr.rfkill) 136 if (iwl_is_rfkill_hw(priv)) {
137 rfkill_force_state(priv->rfkill, RFKILL_STATE_HARD_BLOCKED);
166 return; 138 return;
139 }
167 140
168 if (!iwl_is_rfkill(priv)) 141 if (!iwl_is_rfkill_sw(priv))
169 priv->rfkill_mngr.rfkill->state = RFKILL_STATE_ON; 142 rfkill_force_state(priv->rfkill, RFKILL_STATE_UNBLOCKED);
170 else 143 else
171 priv->rfkill_mngr.rfkill->state = RFKILL_STATE_OFF; 144 rfkill_force_state(priv->rfkill, RFKILL_STATE_SOFT_BLOCKED);
172} 145}
173EXPORT_SYMBOL(iwl_rfkill_set_hw_state); 146EXPORT_SYMBOL(iwl_rfkill_set_hw_state);
diff --git a/drivers/net/wireless/iwlwifi/iwl-rfkill.h b/drivers/net/wireless/iwlwifi/iwl-rfkill.h
index a7f04b855403..402fd4c781da 100644
--- a/drivers/net/wireless/iwlwifi/iwl-rfkill.h
+++ b/drivers/net/wireless/iwlwifi/iwl-rfkill.h
@@ -31,14 +31,8 @@
31struct iwl_priv; 31struct iwl_priv;
32 32
33#include <linux/rfkill.h> 33#include <linux/rfkill.h>
34#include <linux/input.h>
35
36 34
37#ifdef CONFIG_IWLWIFI_RFKILL 35#ifdef CONFIG_IWLWIFI_RFKILL
38struct iwl_rfkill_mngr {
39 struct rfkill *rfkill;
40 struct input_dev *input_dev;
41};
42 36
43void iwl_rfkill_set_hw_state(struct iwl_priv *priv); 37void iwl_rfkill_set_hw_state(struct iwl_priv *priv);
44void iwl_rfkill_unregister(struct iwl_priv *priv); 38void iwl_rfkill_unregister(struct iwl_priv *priv);
diff --git a/drivers/net/wireless/iwlwifi/iwl-rx.c b/drivers/net/wireless/iwlwifi/iwl-rx.c
new file mode 100644
index 000000000000..7cde9d76ff5d
--- /dev/null
+++ b/drivers/net/wireless/iwlwifi/iwl-rx.c
@@ -0,0 +1,1220 @@
1/******************************************************************************
2 *
3 * Copyright(c) 2003 - 2008 Intel Corporation. All rights reserved.
4 *
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
20 *
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
23 *
24 * Contact Information:
25 * James P. Ketrenos <ipw2100-admin@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *
28 *****************************************************************************/
29
30#include <linux/etherdevice.h>
31#include <net/mac80211.h>
32#include <asm/unaligned.h>
33#include "iwl-eeprom.h"
34#include "iwl-dev.h"
35#include "iwl-core.h"
36#include "iwl-sta.h"
37#include "iwl-io.h"
38#include "iwl-calib.h"
39#include "iwl-helpers.h"
40/************************** RX-FUNCTIONS ****************************/
41/*
42 * Rx theory of operation
43 *
44 * Driver allocates a circular buffer of Receive Buffer Descriptors (RBDs),
45 * each of which point to Receive Buffers to be filled by the NIC. These get
46 * used not only for Rx frames, but for any command response or notification
47 * from the NIC. The driver and NIC manage the Rx buffers by means
48 * of indexes into the circular buffer.
49 *
50 * Rx Queue Indexes
51 * The host/firmware share two index registers for managing the Rx buffers.
52 *
53 * The READ index maps to the first position that the firmware may be writing
54 * to -- the driver can read up to (but not including) this position and get
55 * good data.
56 * The READ index is managed by the firmware once the card is enabled.
57 *
58 * The WRITE index maps to the last position the driver has read from -- the
59 * position preceding WRITE is the last slot the firmware can place a packet.
60 *
61 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
62 * WRITE = READ.
63 *
64 * During initialization, the host sets up the READ queue position to the first
65 * INDEX position, and WRITE to the last (READ - 1 wrapped)
66 *
67 * When the firmware places a packet in a buffer, it will advance the READ index
68 * and fire the RX interrupt. The driver can then query the READ index and
69 * process as many packets as possible, moving the WRITE index forward as it
70 * resets the Rx queue buffers with new memory.
71 *
72 * The management in the driver is as follows:
73 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
74 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
75 * to replenish the iwl->rxq->rx_free.
76 * + In iwl_rx_replenish (scheduled) if 'processed' != 'read' then the
77 * iwl->rxq is replenished and the READ INDEX is updated (updating the
78 * 'processed' and 'read' driver indexes as well)
79 * + A received packet is processed and handed to the kernel network stack,
80 * detached from the iwl->rxq. The driver 'processed' index is updated.
81 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
82 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
83 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
84 * were enough free buffers and RX_STALLED is set it is cleared.
85 *
86 *
87 * Driver sequence:
88 *
89 * iwl_rx_queue_alloc() Allocates rx_free
90 * iwl_rx_replenish() Replenishes rx_free list from rx_used, and calls
91 * iwl_rx_queue_restock
92 * iwl_rx_queue_restock() Moves available buffers from rx_free into Rx
93 * queue, updates firmware pointers, and updates
94 * the WRITE index. If insufficient rx_free buffers
95 * are available, schedules iwl_rx_replenish
96 *
97 * -- enable interrupts --
98 * ISR - iwl_rx() Detach iwl_rx_mem_buffers from pool up to the
99 * READ INDEX, detaching the SKB from the pool.
100 * Moves the packet buffer from queue to rx_used.
101 * Calls iwl_rx_queue_restock to refill any empty
102 * slots.
103 * ...
104 *
105 */
106
107/**
108 * iwl_rx_queue_space - Return number of free slots available in queue.
109 */
110int iwl_rx_queue_space(const struct iwl_rx_queue *q)
111{
112 int s = q->read - q->write;
113 if (s <= 0)
114 s += RX_QUEUE_SIZE;
115 /* keep some buffer to not confuse full and empty queue */
116 s -= 2;
117 if (s < 0)
118 s = 0;
119 return s;
120}
121EXPORT_SYMBOL(iwl_rx_queue_space);
122
123/**
124 * iwl_rx_queue_update_write_ptr - Update the write pointer for the RX queue
125 */
126int iwl_rx_queue_update_write_ptr(struct iwl_priv *priv, struct iwl_rx_queue *q)
127{
128 u32 reg = 0;
129 int ret = 0;
130 unsigned long flags;
131
132 spin_lock_irqsave(&q->lock, flags);
133
134 if (q->need_update == 0)
135 goto exit_unlock;
136
137 /* If power-saving is in use, make sure device is awake */
138 if (test_bit(STATUS_POWER_PMI, &priv->status)) {
139 reg = iwl_read32(priv, CSR_UCODE_DRV_GP1);
140
141 if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
142 iwl_set_bit(priv, CSR_GP_CNTRL,
143 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
144 goto exit_unlock;
145 }
146
147 ret = iwl_grab_nic_access(priv);
148 if (ret)
149 goto exit_unlock;
150
151 /* Device expects a multiple of 8 */
152 iwl_write_direct32(priv, FH_RSCSR_CHNL0_WPTR,
153 q->write & ~0x7);
154 iwl_release_nic_access(priv);
155
156 /* Else device is assumed to be awake */
157 } else
158 /* Device expects a multiple of 8 */
159 iwl_write32(priv, FH_RSCSR_CHNL0_WPTR, q->write & ~0x7);
160
161
162 q->need_update = 0;
163
164 exit_unlock:
165 spin_unlock_irqrestore(&q->lock, flags);
166 return ret;
167}
168EXPORT_SYMBOL(iwl_rx_queue_update_write_ptr);
169/**
170 * iwl_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
171 */
172static inline __le32 iwl_dma_addr2rbd_ptr(struct iwl_priv *priv,
173 dma_addr_t dma_addr)
174{
175 return cpu_to_le32((u32)(dma_addr >> 8));
176}
177
178/**
179 * iwl_rx_queue_restock - refill RX queue from pre-allocated pool
180 *
181 * If there are slots in the RX queue that need to be restocked,
182 * and we have free pre-allocated buffers, fill the ranks as much
183 * as we can, pulling from rx_free.
184 *
185 * This moves the 'write' index forward to catch up with 'processed', and
186 * also updates the memory address in the firmware to reference the new
187 * target buffer.
188 */
189int iwl_rx_queue_restock(struct iwl_priv *priv)
190{
191 struct iwl_rx_queue *rxq = &priv->rxq;
192 struct list_head *element;
193 struct iwl_rx_mem_buffer *rxb;
194 unsigned long flags;
195 int write;
196 int ret = 0;
197
198 spin_lock_irqsave(&rxq->lock, flags);
199 write = rxq->write & ~0x7;
200 while ((iwl_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
201 /* Get next free Rx buffer, remove from free list */
202 element = rxq->rx_free.next;
203 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
204 list_del(element);
205
206 /* Point to Rx buffer via next RBD in circular buffer */
207 rxq->bd[rxq->write] = iwl_dma_addr2rbd_ptr(priv, rxb->dma_addr);
208 rxq->queue[rxq->write] = rxb;
209 rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
210 rxq->free_count--;
211 }
212 spin_unlock_irqrestore(&rxq->lock, flags);
213 /* If the pre-allocated buffer pool is dropping low, schedule to
214 * refill it */
215 if (rxq->free_count <= RX_LOW_WATERMARK)
216 queue_work(priv->workqueue, &priv->rx_replenish);
217
218
219 /* If we've added more space for the firmware to place data, tell it.
220 * Increment device's write pointer in multiples of 8. */
221 if ((write != (rxq->write & ~0x7))
222 || (abs(rxq->write - rxq->read) > 7)) {
223 spin_lock_irqsave(&rxq->lock, flags);
224 rxq->need_update = 1;
225 spin_unlock_irqrestore(&rxq->lock, flags);
226 ret = iwl_rx_queue_update_write_ptr(priv, rxq);
227 }
228
229 return ret;
230}
231EXPORT_SYMBOL(iwl_rx_queue_restock);
232
233
234/**
235 * iwl_rx_replenish - Move all used packet from rx_used to rx_free
236 *
237 * When moving to rx_free an SKB is allocated for the slot.
238 *
239 * Also restock the Rx queue via iwl_rx_queue_restock.
240 * This is called as a scheduled work item (except for during initialization)
241 */
242void iwl_rx_allocate(struct iwl_priv *priv)
243{
244 struct iwl_rx_queue *rxq = &priv->rxq;
245 struct list_head *element;
246 struct iwl_rx_mem_buffer *rxb;
247 unsigned long flags;
248 spin_lock_irqsave(&rxq->lock, flags);
249 while (!list_empty(&rxq->rx_used)) {
250 element = rxq->rx_used.next;
251 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
252
253 /* Alloc a new receive buffer */
254 rxb->skb = alloc_skb(priv->hw_params.rx_buf_size,
255 __GFP_NOWARN | GFP_ATOMIC);
256 if (!rxb->skb) {
257 if (net_ratelimit())
258 printk(KERN_CRIT DRV_NAME
259 ": Can not allocate SKB buffers\n");
260 /* We don't reschedule replenish work here -- we will
261 * call the restock method and if it still needs
262 * more buffers it will schedule replenish */
263 break;
264 }
265 priv->alloc_rxb_skb++;
266 list_del(element);
267
268 /* Get physical address of RB/SKB */
269 rxb->dma_addr =
270 pci_map_single(priv->pci_dev, rxb->skb->data,
271 priv->hw_params.rx_buf_size, PCI_DMA_FROMDEVICE);
272 list_add_tail(&rxb->list, &rxq->rx_free);
273 rxq->free_count++;
274 }
275 spin_unlock_irqrestore(&rxq->lock, flags);
276}
277EXPORT_SYMBOL(iwl_rx_allocate);
278
279void iwl_rx_replenish(struct iwl_priv *priv)
280{
281 unsigned long flags;
282
283 iwl_rx_allocate(priv);
284
285 spin_lock_irqsave(&priv->lock, flags);
286 iwl_rx_queue_restock(priv);
287 spin_unlock_irqrestore(&priv->lock, flags);
288}
289EXPORT_SYMBOL(iwl_rx_replenish);
290
291
292/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
293 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
294 * This free routine walks the list of POOL entries and if SKB is set to
295 * non NULL it is unmapped and freed
296 */
297void iwl_rx_queue_free(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
298{
299 int i;
300 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
301 if (rxq->pool[i].skb != NULL) {
302 pci_unmap_single(priv->pci_dev,
303 rxq->pool[i].dma_addr,
304 priv->hw_params.rx_buf_size,
305 PCI_DMA_FROMDEVICE);
306 dev_kfree_skb(rxq->pool[i].skb);
307 }
308 }
309
310 pci_free_consistent(priv->pci_dev, 4 * RX_QUEUE_SIZE, rxq->bd,
311 rxq->dma_addr);
312 rxq->bd = NULL;
313}
314EXPORT_SYMBOL(iwl_rx_queue_free);
315
316int iwl_rx_queue_alloc(struct iwl_priv *priv)
317{
318 struct iwl_rx_queue *rxq = &priv->rxq;
319 struct pci_dev *dev = priv->pci_dev;
320 int i;
321
322 spin_lock_init(&rxq->lock);
323 INIT_LIST_HEAD(&rxq->rx_free);
324 INIT_LIST_HEAD(&rxq->rx_used);
325
326 /* Alloc the circular buffer of Read Buffer Descriptors (RBDs) */
327 rxq->bd = pci_alloc_consistent(dev, 4 * RX_QUEUE_SIZE, &rxq->dma_addr);
328 if (!rxq->bd)
329 return -ENOMEM;
330
331 /* Fill the rx_used queue with _all_ of the Rx buffers */
332 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
333 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
334
335 /* Set us so that we have processed and used all buffers, but have
336 * not restocked the Rx queue with fresh buffers */
337 rxq->read = rxq->write = 0;
338 rxq->free_count = 0;
339 rxq->need_update = 0;
340 return 0;
341}
342EXPORT_SYMBOL(iwl_rx_queue_alloc);
343
344void iwl_rx_queue_reset(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
345{
346 unsigned long flags;
347 int i;
348 spin_lock_irqsave(&rxq->lock, flags);
349 INIT_LIST_HEAD(&rxq->rx_free);
350 INIT_LIST_HEAD(&rxq->rx_used);
351 /* Fill the rx_used queue with _all_ of the Rx buffers */
352 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
353 /* In the reset function, these buffers may have been allocated
354 * to an SKB, so we need to unmap and free potential storage */
355 if (rxq->pool[i].skb != NULL) {
356 pci_unmap_single(priv->pci_dev,
357 rxq->pool[i].dma_addr,
358 priv->hw_params.rx_buf_size,
359 PCI_DMA_FROMDEVICE);
360 priv->alloc_rxb_skb--;
361 dev_kfree_skb(rxq->pool[i].skb);
362 rxq->pool[i].skb = NULL;
363 }
364 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
365 }
366
367 /* Set us so that we have processed and used all buffers, but have
368 * not restocked the Rx queue with fresh buffers */
369 rxq->read = rxq->write = 0;
370 rxq->free_count = 0;
371 spin_unlock_irqrestore(&rxq->lock, flags);
372}
373EXPORT_SYMBOL(iwl_rx_queue_reset);
374
375int iwl_rx_init(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
376{
377 int ret;
378 unsigned long flags;
379 u32 rb_size;
380 const u32 rfdnlog = RX_QUEUE_SIZE_LOG; /* 256 RBDs */
381 const u32 rb_timeout = 0; /* FIXME: RX_RB_TIMEOUT why this stalls RX */
382
383 spin_lock_irqsave(&priv->lock, flags);
384 ret = iwl_grab_nic_access(priv);
385 if (ret) {
386 spin_unlock_irqrestore(&priv->lock, flags);
387 return ret;
388 }
389
390 if (priv->cfg->mod_params->amsdu_size_8K)
391 rb_size = FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_8K;
392 else
393 rb_size = FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_4K;
394
395 /* Stop Rx DMA */
396 iwl_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0);
397
398 /* Reset driver's Rx queue write index */
399 iwl_write_direct32(priv, FH_RSCSR_CHNL0_RBDCB_WPTR_REG, 0);
400
401 /* Tell device where to find RBD circular buffer in DRAM */
402 iwl_write_direct32(priv, FH_RSCSR_CHNL0_RBDCB_BASE_REG,
403 (u32)(rxq->dma_addr >> 8));
404
405 /* Tell device where in DRAM to update its Rx status */
406 iwl_write_direct32(priv, FH_RSCSR_CHNL0_STTS_WPTR_REG,
407 (priv->shared_phys + priv->rb_closed_offset) >> 4);
408
409 /* Enable Rx DMA
410 * FH_RCSR_CHNL0_RX_IGNORE_RXF_EMPTY is set becuase of HW bug in
411 * the credit mechanism in 5000 HW RX FIFO
412 * Direct rx interrupts to hosts
413 * Rx buffer size 4 or 8k
414 * RB timeout 0x10
415 * 256 RBDs
416 */
417 iwl_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG,
418 FH_RCSR_RX_CONFIG_CHNL_EN_ENABLE_VAL |
419 FH_RCSR_CHNL0_RX_IGNORE_RXF_EMPTY |
420 FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_INT_HOST_VAL |
421 rb_size|
422 (rb_timeout << FH_RCSR_RX_CONFIG_REG_IRQ_RBTH_POS)|
423 (rfdnlog << FH_RCSR_RX_CONFIG_RBDCB_SIZE_POS));
424
425 iwl_release_nic_access(priv);
426
427 iwl_write32(priv, CSR_INT_COALESCING, 0x40);
428
429 spin_unlock_irqrestore(&priv->lock, flags);
430
431 return 0;
432}
433
434int iwl_rxq_stop(struct iwl_priv *priv)
435{
436 int ret;
437 unsigned long flags;
438
439 spin_lock_irqsave(&priv->lock, flags);
440 ret = iwl_grab_nic_access(priv);
441 if (unlikely(ret)) {
442 spin_unlock_irqrestore(&priv->lock, flags);
443 return ret;
444 }
445
446 /* stop Rx DMA */
447 iwl_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0);
448 ret = iwl_poll_direct_bit(priv, FH_MEM_RSSR_RX_STATUS_REG,
449 (1 << 24), 1000);
450 if (ret < 0)
451 IWL_ERROR("Can't stop Rx DMA.\n");
452
453 iwl_release_nic_access(priv);
454 spin_unlock_irqrestore(&priv->lock, flags);
455
456 return 0;
457}
458EXPORT_SYMBOL(iwl_rxq_stop);
459
460void iwl_rx_missed_beacon_notif(struct iwl_priv *priv,
461 struct iwl_rx_mem_buffer *rxb)
462
463{
464 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
465 struct iwl4965_missed_beacon_notif *missed_beacon;
466
467 missed_beacon = &pkt->u.missed_beacon;
468 if (le32_to_cpu(missed_beacon->consequtive_missed_beacons) > 5) {
469 IWL_DEBUG_CALIB("missed bcn cnsq %d totl %d rcd %d expctd %d\n",
470 le32_to_cpu(missed_beacon->consequtive_missed_beacons),
471 le32_to_cpu(missed_beacon->total_missed_becons),
472 le32_to_cpu(missed_beacon->num_recvd_beacons),
473 le32_to_cpu(missed_beacon->num_expected_beacons));
474 if (!test_bit(STATUS_SCANNING, &priv->status))
475 iwl_init_sensitivity(priv);
476 }
477}
478EXPORT_SYMBOL(iwl_rx_missed_beacon_notif);
479
480int iwl_rx_agg_start(struct iwl_priv *priv, const u8 *addr, int tid, u16 ssn)
481{
482 unsigned long flags;
483 int sta_id;
484
485 sta_id = iwl_find_station(priv, addr);
486 if (sta_id == IWL_INVALID_STATION)
487 return -ENXIO;
488
489 spin_lock_irqsave(&priv->sta_lock, flags);
490 priv->stations[sta_id].sta.station_flags_msk = 0;
491 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_ADDBA_TID_MSK;
492 priv->stations[sta_id].sta.add_immediate_ba_tid = (u8)tid;
493 priv->stations[sta_id].sta.add_immediate_ba_ssn = cpu_to_le16(ssn);
494 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
495 spin_unlock_irqrestore(&priv->sta_lock, flags);
496
497 return iwl_send_add_sta(priv, &priv->stations[sta_id].sta,
498 CMD_ASYNC);
499}
500EXPORT_SYMBOL(iwl_rx_agg_start);
501
502int iwl_rx_agg_stop(struct iwl_priv *priv, const u8 *addr, int tid)
503{
504 unsigned long flags;
505 int sta_id;
506
507 sta_id = iwl_find_station(priv, addr);
508 if (sta_id == IWL_INVALID_STATION)
509 return -ENXIO;
510
511 spin_lock_irqsave(&priv->sta_lock, flags);
512 priv->stations[sta_id].sta.station_flags_msk = 0;
513 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_DELBA_TID_MSK;
514 priv->stations[sta_id].sta.remove_immediate_ba_tid = (u8)tid;
515 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
516 spin_unlock_irqrestore(&priv->sta_lock, flags);
517
518 return iwl_send_add_sta(priv, &priv->stations[sta_id].sta,
519 CMD_ASYNC);
520}
521EXPORT_SYMBOL(iwl_rx_agg_stop);
522
523
524/* Calculate noise level, based on measurements during network silence just
525 * before arriving beacon. This measurement can be done only if we know
526 * exactly when to expect beacons, therefore only when we're associated. */
527static void iwl_rx_calc_noise(struct iwl_priv *priv)
528{
529 struct statistics_rx_non_phy *rx_info
530 = &(priv->statistics.rx.general);
531 int num_active_rx = 0;
532 int total_silence = 0;
533 int bcn_silence_a =
534 le32_to_cpu(rx_info->beacon_silence_rssi_a) & IN_BAND_FILTER;
535 int bcn_silence_b =
536 le32_to_cpu(rx_info->beacon_silence_rssi_b) & IN_BAND_FILTER;
537 int bcn_silence_c =
538 le32_to_cpu(rx_info->beacon_silence_rssi_c) & IN_BAND_FILTER;
539
540 if (bcn_silence_a) {
541 total_silence += bcn_silence_a;
542 num_active_rx++;
543 }
544 if (bcn_silence_b) {
545 total_silence += bcn_silence_b;
546 num_active_rx++;
547 }
548 if (bcn_silence_c) {
549 total_silence += bcn_silence_c;
550 num_active_rx++;
551 }
552
553 /* Average among active antennas */
554 if (num_active_rx)
555 priv->last_rx_noise = (total_silence / num_active_rx) - 107;
556 else
557 priv->last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
558
559 IWL_DEBUG_CALIB("inband silence a %u, b %u, c %u, dBm %d\n",
560 bcn_silence_a, bcn_silence_b, bcn_silence_c,
561 priv->last_rx_noise);
562}
563
564#define REG_RECALIB_PERIOD (60)
565
566void iwl_rx_statistics(struct iwl_priv *priv,
567 struct iwl_rx_mem_buffer *rxb)
568{
569 int change;
570 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
571
572 IWL_DEBUG_RX("Statistics notification received (%d vs %d).\n",
573 (int)sizeof(priv->statistics), pkt->len);
574
575 change = ((priv->statistics.general.temperature !=
576 pkt->u.stats.general.temperature) ||
577 ((priv->statistics.flag &
578 STATISTICS_REPLY_FLG_FAT_MODE_MSK) !=
579 (pkt->u.stats.flag & STATISTICS_REPLY_FLG_FAT_MODE_MSK)));
580
581 memcpy(&priv->statistics, &pkt->u.stats, sizeof(priv->statistics));
582
583 set_bit(STATUS_STATISTICS, &priv->status);
584
585 /* Reschedule the statistics timer to occur in
586 * REG_RECALIB_PERIOD seconds to ensure we get a
587 * thermal update even if the uCode doesn't give
588 * us one */
589 mod_timer(&priv->statistics_periodic, jiffies +
590 msecs_to_jiffies(REG_RECALIB_PERIOD * 1000));
591
592 if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)) &&
593 (pkt->hdr.cmd == STATISTICS_NOTIFICATION)) {
594 iwl_rx_calc_noise(priv);
595 queue_work(priv->workqueue, &priv->run_time_calib_work);
596 }
597
598 iwl_leds_background(priv);
599
600 if (priv->cfg->ops->lib->temperature && change)
601 priv->cfg->ops->lib->temperature(priv);
602}
603EXPORT_SYMBOL(iwl_rx_statistics);
604
605#define PERFECT_RSSI (-20) /* dBm */
606#define WORST_RSSI (-95) /* dBm */
607#define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
608
609/* Calculate an indication of rx signal quality (a percentage, not dBm!).
610 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
611 * about formulas used below. */
612static int iwl_calc_sig_qual(int rssi_dbm, int noise_dbm)
613{
614 int sig_qual;
615 int degradation = PERFECT_RSSI - rssi_dbm;
616
617 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
618 * as indicator; formula is (signal dbm - noise dbm).
619 * SNR at or above 40 is a great signal (100%).
620 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
621 * Weakest usable signal is usually 10 - 15 dB SNR. */
622 if (noise_dbm) {
623 if (rssi_dbm - noise_dbm >= 40)
624 return 100;
625 else if (rssi_dbm < noise_dbm)
626 return 0;
627 sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
628
629 /* Else use just the signal level.
630 * This formula is a least squares fit of data points collected and
631 * compared with a reference system that had a percentage (%) display
632 * for signal quality. */
633 } else
634 sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
635 (15 * RSSI_RANGE + 62 * degradation)) /
636 (RSSI_RANGE * RSSI_RANGE);
637
638 if (sig_qual > 100)
639 sig_qual = 100;
640 else if (sig_qual < 1)
641 sig_qual = 0;
642
643 return sig_qual;
644}
645
646#ifdef CONFIG_IWLWIFI_DEBUG
647
648/**
649 * iwl_dbg_report_frame - dump frame to syslog during debug sessions
650 *
651 * You may hack this function to show different aspects of received frames,
652 * including selective frame dumps.
653 * group100 parameter selects whether to show 1 out of 100 good frames.
654 *
655 * TODO: This was originally written for 3945, need to audit for
656 * proper operation with 4965.
657 */
658static void iwl_dbg_report_frame(struct iwl_priv *priv,
659 struct iwl_rx_packet *pkt,
660 struct ieee80211_hdr *header, int group100)
661{
662 u32 to_us;
663 u32 print_summary = 0;
664 u32 print_dump = 0; /* set to 1 to dump all frames' contents */
665 u32 hundred = 0;
666 u32 dataframe = 0;
667 __le16 fc;
668 u16 seq_ctl;
669 u16 channel;
670 u16 phy_flags;
671 int rate_sym;
672 u16 length;
673 u16 status;
674 u16 bcn_tmr;
675 u32 tsf_low;
676 u64 tsf;
677 u8 rssi;
678 u8 agc;
679 u16 sig_avg;
680 u16 noise_diff;
681 struct iwl4965_rx_frame_stats *rx_stats = IWL_RX_STATS(pkt);
682 struct iwl4965_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt);
683 struct iwl4965_rx_frame_end *rx_end = IWL_RX_END(pkt);
684 u8 *data = IWL_RX_DATA(pkt);
685
686 if (likely(!(priv->debug_level & IWL_DL_RX)))
687 return;
688
689 /* MAC header */
690 fc = header->frame_control;
691 seq_ctl = le16_to_cpu(header->seq_ctrl);
692
693 /* metadata */
694 channel = le16_to_cpu(rx_hdr->channel);
695 phy_flags = le16_to_cpu(rx_hdr->phy_flags);
696 rate_sym = rx_hdr->rate;
697 length = le16_to_cpu(rx_hdr->len);
698
699 /* end-of-frame status and timestamp */
700 status = le32_to_cpu(rx_end->status);
701 bcn_tmr = le32_to_cpu(rx_end->beacon_timestamp);
702 tsf_low = le64_to_cpu(rx_end->timestamp) & 0x0ffffffff;
703 tsf = le64_to_cpu(rx_end->timestamp);
704
705 /* signal statistics */
706 rssi = rx_stats->rssi;
707 agc = rx_stats->agc;
708 sig_avg = le16_to_cpu(rx_stats->sig_avg);
709 noise_diff = le16_to_cpu(rx_stats->noise_diff);
710
711 to_us = !compare_ether_addr(header->addr1, priv->mac_addr);
712
713 /* if data frame is to us and all is good,
714 * (optionally) print summary for only 1 out of every 100 */
715 if (to_us && (fc & ~cpu_to_le16(IEEE80211_FCTL_PROTECTED)) ==
716 cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FTYPE_DATA)) {
717 dataframe = 1;
718 if (!group100)
719 print_summary = 1; /* print each frame */
720 else if (priv->framecnt_to_us < 100) {
721 priv->framecnt_to_us++;
722 print_summary = 0;
723 } else {
724 priv->framecnt_to_us = 0;
725 print_summary = 1;
726 hundred = 1;
727 }
728 } else {
729 /* print summary for all other frames */
730 print_summary = 1;
731 }
732
733 if (print_summary) {
734 char *title;
735 int rate_idx;
736 u32 bitrate;
737
738 if (hundred)
739 title = "100Frames";
740 else if (ieee80211_has_retry(fc))
741 title = "Retry";
742 else if (ieee80211_is_assoc_resp(fc))
743 title = "AscRsp";
744 else if (ieee80211_is_reassoc_resp(fc))
745 title = "RasRsp";
746 else if (ieee80211_is_probe_resp(fc)) {
747 title = "PrbRsp";
748 print_dump = 1; /* dump frame contents */
749 } else if (ieee80211_is_beacon(fc)) {
750 title = "Beacon";
751 print_dump = 1; /* dump frame contents */
752 } else if (ieee80211_is_atim(fc))
753 title = "ATIM";
754 else if (ieee80211_is_auth(fc))
755 title = "Auth";
756 else if (ieee80211_is_deauth(fc))
757 title = "DeAuth";
758 else if (ieee80211_is_disassoc(fc))
759 title = "DisAssoc";
760 else
761 title = "Frame";
762
763 rate_idx = iwl_hwrate_to_plcp_idx(rate_sym);
764 if (unlikely(rate_idx == -1))
765 bitrate = 0;
766 else
767 bitrate = iwl_rates[rate_idx].ieee / 2;
768
769 /* print frame summary.
770 * MAC addresses show just the last byte (for brevity),
771 * but you can hack it to show more, if you'd like to. */
772 if (dataframe)
773 IWL_DEBUG_RX("%s: mhd=0x%04x, dst=0x%02x, "
774 "len=%u, rssi=%d, chnl=%d, rate=%u, \n",
775 title, le16_to_cpu(fc), header->addr1[5],
776 length, rssi, channel, bitrate);
777 else {
778 /* src/dst addresses assume managed mode */
779 IWL_DEBUG_RX("%s: 0x%04x, dst=0x%02x, "
780 "src=0x%02x, rssi=%u, tim=%lu usec, "
781 "phy=0x%02x, chnl=%d\n",
782 title, le16_to_cpu(fc), header->addr1[5],
783 header->addr3[5], rssi,
784 tsf_low - priv->scan_start_tsf,
785 phy_flags, channel);
786 }
787 }
788 if (print_dump)
789 iwl_print_hex_dump(priv, IWL_DL_RX, data, length);
790}
791#else
792static inline void iwl_dbg_report_frame(struct iwl_priv *priv,
793 struct iwl_rx_packet *pkt,
794 struct ieee80211_hdr *header,
795 int group100)
796{
797}
798#endif
799
800static void iwl_update_rx_stats(struct iwl_priv *priv, u16 fc, u16 len)
801{
802 /* 0 - mgmt, 1 - cnt, 2 - data */
803 int idx = (fc & IEEE80211_FCTL_FTYPE) >> 2;
804 priv->rx_stats[idx].cnt++;
805 priv->rx_stats[idx].bytes += len;
806}
807
808/*
809 * returns non-zero if packet should be dropped
810 */
811static int iwl_set_decrypted_flag(struct iwl_priv *priv,
812 struct ieee80211_hdr *hdr,
813 u32 decrypt_res,
814 struct ieee80211_rx_status *stats)
815{
816 u16 fc = le16_to_cpu(hdr->frame_control);
817
818 if (priv->active_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK)
819 return 0;
820
821 if (!(fc & IEEE80211_FCTL_PROTECTED))
822 return 0;
823
824 IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res);
825 switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) {
826 case RX_RES_STATUS_SEC_TYPE_TKIP:
827 /* The uCode has got a bad phase 1 Key, pushes the packet.
828 * Decryption will be done in SW. */
829 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
830 RX_RES_STATUS_BAD_KEY_TTAK)
831 break;
832
833 case RX_RES_STATUS_SEC_TYPE_WEP:
834 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
835 RX_RES_STATUS_BAD_ICV_MIC) {
836 /* bad ICV, the packet is destroyed since the
837 * decryption is inplace, drop it */
838 IWL_DEBUG_RX("Packet destroyed\n");
839 return -1;
840 }
841 case RX_RES_STATUS_SEC_TYPE_CCMP:
842 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
843 RX_RES_STATUS_DECRYPT_OK) {
844 IWL_DEBUG_RX("hw decrypt successfully!!!\n");
845 stats->flag |= RX_FLAG_DECRYPTED;
846 }
847 break;
848
849 default:
850 break;
851 }
852 return 0;
853}
854
855static u32 iwl_translate_rx_status(struct iwl_priv *priv, u32 decrypt_in)
856{
857 u32 decrypt_out = 0;
858
859 if ((decrypt_in & RX_RES_STATUS_STATION_FOUND) ==
860 RX_RES_STATUS_STATION_FOUND)
861 decrypt_out |= (RX_RES_STATUS_STATION_FOUND |
862 RX_RES_STATUS_NO_STATION_INFO_MISMATCH);
863
864 decrypt_out |= (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK);
865
866 /* packet was not encrypted */
867 if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
868 RX_RES_STATUS_SEC_TYPE_NONE)
869 return decrypt_out;
870
871 /* packet was encrypted with unknown alg */
872 if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
873 RX_RES_STATUS_SEC_TYPE_ERR)
874 return decrypt_out;
875
876 /* decryption was not done in HW */
877 if ((decrypt_in & RX_MPDU_RES_STATUS_DEC_DONE_MSK) !=
878 RX_MPDU_RES_STATUS_DEC_DONE_MSK)
879 return decrypt_out;
880
881 switch (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) {
882
883 case RX_RES_STATUS_SEC_TYPE_CCMP:
884 /* alg is CCM: check MIC only */
885 if (!(decrypt_in & RX_MPDU_RES_STATUS_MIC_OK))
886 /* Bad MIC */
887 decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
888 else
889 decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
890
891 break;
892
893 case RX_RES_STATUS_SEC_TYPE_TKIP:
894 if (!(decrypt_in & RX_MPDU_RES_STATUS_TTAK_OK)) {
895 /* Bad TTAK */
896 decrypt_out |= RX_RES_STATUS_BAD_KEY_TTAK;
897 break;
898 }
899 /* fall through if TTAK OK */
900 default:
901 if (!(decrypt_in & RX_MPDU_RES_STATUS_ICV_OK))
902 decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
903 else
904 decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
905 break;
906 };
907
908 IWL_DEBUG_RX("decrypt_in:0x%x decrypt_out = 0x%x\n",
909 decrypt_in, decrypt_out);
910
911 return decrypt_out;
912}
913
914static void iwl_pass_packet_to_mac80211(struct iwl_priv *priv,
915 int include_phy,
916 struct iwl_rx_mem_buffer *rxb,
917 struct ieee80211_rx_status *stats)
918{
919 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
920 struct iwl_rx_phy_res *rx_start = (include_phy) ?
921 (struct iwl_rx_phy_res *)&(pkt->u.raw[0]) : NULL;
922 struct ieee80211_hdr *hdr;
923 u16 len;
924 __le32 *rx_end;
925 unsigned int skblen;
926 u32 ampdu_status;
927 u32 ampdu_status_legacy;
928
929 if (!include_phy && priv->last_phy_res[0])
930 rx_start = (struct iwl_rx_phy_res *)&priv->last_phy_res[1];
931
932 if (!rx_start) {
933 IWL_ERROR("MPDU frame without a PHY data\n");
934 return;
935 }
936 if (include_phy) {
937 hdr = (struct ieee80211_hdr *)((u8 *) &rx_start[1] +
938 rx_start->cfg_phy_cnt);
939
940 len = le16_to_cpu(rx_start->byte_count);
941
942 rx_end = (__le32 *)((u8 *) &pkt->u.raw[0] +
943 sizeof(struct iwl_rx_phy_res) +
944 rx_start->cfg_phy_cnt + len);
945
946 } else {
947 struct iwl4965_rx_mpdu_res_start *amsdu =
948 (struct iwl4965_rx_mpdu_res_start *)pkt->u.raw;
949
950 hdr = (struct ieee80211_hdr *)(pkt->u.raw +
951 sizeof(struct iwl4965_rx_mpdu_res_start));
952 len = le16_to_cpu(amsdu->byte_count);
953 rx_start->byte_count = amsdu->byte_count;
954 rx_end = (__le32 *) (((u8 *) hdr) + len);
955 }
956
957 ampdu_status = le32_to_cpu(*rx_end);
958 skblen = ((u8 *) rx_end - (u8 *) &pkt->u.raw[0]) + sizeof(u32);
959
960 if (!include_phy) {
961 /* New status scheme, need to translate */
962 ampdu_status_legacy = ampdu_status;
963 ampdu_status = iwl_translate_rx_status(priv, ampdu_status);
964 }
965
966 /* start from MAC */
967 skb_reserve(rxb->skb, (void *)hdr - (void *)pkt);
968 skb_put(rxb->skb, len); /* end where data ends */
969
970 /* We only process data packets if the interface is open */
971 if (unlikely(!priv->is_open)) {
972 IWL_DEBUG_DROP_LIMIT
973 ("Dropping packet while interface is not open.\n");
974 return;
975 }
976
977 hdr = (struct ieee80211_hdr *)rxb->skb->data;
978
979 /* in case of HW accelerated crypto and bad decryption, drop */
980 if (!priv->hw_params.sw_crypto &&
981 iwl_set_decrypted_flag(priv, hdr, ampdu_status, stats))
982 return;
983
984 iwl_update_rx_stats(priv, le16_to_cpu(hdr->frame_control), len);
985 ieee80211_rx_irqsafe(priv->hw, rxb->skb, stats);
986 priv->alloc_rxb_skb--;
987 rxb->skb = NULL;
988}
989
990/* Calc max signal level (dBm) among 3 possible receivers */
991static inline int iwl_calc_rssi(struct iwl_priv *priv,
992 struct iwl_rx_phy_res *rx_resp)
993{
994 return priv->cfg->ops->utils->calc_rssi(priv, rx_resp);
995}
996
997
998static void iwl_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id)
999{
1000 unsigned long flags;
1001
1002 spin_lock_irqsave(&priv->sta_lock, flags);
1003 priv->stations[sta_id].sta.station_flags &= ~STA_FLG_PWR_SAVE_MSK;
1004 priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK;
1005 priv->stations[sta_id].sta.sta.modify_mask = 0;
1006 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1007 spin_unlock_irqrestore(&priv->sta_lock, flags);
1008
1009 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
1010}
1011
1012static void iwl_update_ps_mode(struct iwl_priv *priv, u16 ps_bit, u8 *addr)
1013{
1014 /* FIXME: need locking over ps_status ??? */
1015 u8 sta_id = iwl_find_station(priv, addr);
1016
1017 if (sta_id != IWL_INVALID_STATION) {
1018 u8 sta_awake = priv->stations[sta_id].
1019 ps_status == STA_PS_STATUS_WAKE;
1020
1021 if (sta_awake && ps_bit)
1022 priv->stations[sta_id].ps_status = STA_PS_STATUS_SLEEP;
1023 else if (!sta_awake && !ps_bit) {
1024 iwl_sta_modify_ps_wake(priv, sta_id);
1025 priv->stations[sta_id].ps_status = STA_PS_STATUS_WAKE;
1026 }
1027 }
1028}
1029
1030/* This is necessary only for a number of statistics, see the caller. */
1031static int iwl_is_network_packet(struct iwl_priv *priv,
1032 struct ieee80211_hdr *header)
1033{
1034 /* Filter incoming packets to determine if they are targeted toward
1035 * this network, discarding packets coming from ourselves */
1036 switch (priv->iw_mode) {
1037 case NL80211_IFTYPE_ADHOC: /* Header: Dest. | Source | BSSID */
1038 /* packets to our IBSS update information */
1039 return !compare_ether_addr(header->addr3, priv->bssid);
1040 case NL80211_IFTYPE_STATION: /* Header: Dest. | AP{BSSID} | Source */
1041 /* packets to our IBSS update information */
1042 return !compare_ether_addr(header->addr2, priv->bssid);
1043 default:
1044 return 1;
1045 }
1046}
1047
1048/* Called for REPLY_RX (legacy ABG frames), or
1049 * REPLY_RX_MPDU_CMD (HT high-throughput N frames). */
1050void iwl_rx_reply_rx(struct iwl_priv *priv,
1051 struct iwl_rx_mem_buffer *rxb)
1052{
1053 struct ieee80211_hdr *header;
1054 struct ieee80211_rx_status rx_status;
1055 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
1056 /* Use phy data (Rx signal strength, etc.) contained within
1057 * this rx packet for legacy frames,
1058 * or phy data cached from REPLY_RX_PHY_CMD for HT frames. */
1059 int include_phy = (pkt->hdr.cmd == REPLY_RX);
1060 struct iwl_rx_phy_res *rx_start = (include_phy) ?
1061 (struct iwl_rx_phy_res *)&(pkt->u.raw[0]) :
1062 (struct iwl_rx_phy_res *)&priv->last_phy_res[1];
1063 __le32 *rx_end;
1064 unsigned int len = 0;
1065 u16 fc;
1066 u8 network_packet;
1067
1068 rx_status.mactime = le64_to_cpu(rx_start->timestamp);
1069 rx_status.freq =
1070 ieee80211_channel_to_frequency(le16_to_cpu(rx_start->channel));
1071 rx_status.band = (rx_start->phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ?
1072 IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
1073 rx_status.rate_idx =
1074 iwl_hwrate_to_plcp_idx(le32_to_cpu(rx_start->rate_n_flags));
1075 if (rx_status.band == IEEE80211_BAND_5GHZ)
1076 rx_status.rate_idx -= IWL_FIRST_OFDM_RATE;
1077
1078 rx_status.flag = 0;
1079
1080 /* TSF isn't reliable. In order to allow smooth user experience,
1081 * this W/A doesn't propagate it to the mac80211 */
1082 /*rx_status.flag |= RX_FLAG_TSFT;*/
1083
1084 if ((unlikely(rx_start->cfg_phy_cnt > 20))) {
1085 IWL_DEBUG_DROP("dsp size out of range [0,20]: %d/n",
1086 rx_start->cfg_phy_cnt);
1087 return;
1088 }
1089
1090 if (!include_phy) {
1091 if (priv->last_phy_res[0])
1092 rx_start = (struct iwl_rx_phy_res *)
1093 &priv->last_phy_res[1];
1094 else
1095 rx_start = NULL;
1096 }
1097
1098 if (!rx_start) {
1099 IWL_ERROR("MPDU frame without a PHY data\n");
1100 return;
1101 }
1102
1103 if (include_phy) {
1104 header = (struct ieee80211_hdr *)((u8 *) &rx_start[1]
1105 + rx_start->cfg_phy_cnt);
1106
1107 len = le16_to_cpu(rx_start->byte_count);
1108 rx_end = (__le32 *)(pkt->u.raw + rx_start->cfg_phy_cnt +
1109 sizeof(struct iwl_rx_phy_res) + len);
1110 } else {
1111 struct iwl4965_rx_mpdu_res_start *amsdu =
1112 (struct iwl4965_rx_mpdu_res_start *)pkt->u.raw;
1113
1114 header = (void *)(pkt->u.raw +
1115 sizeof(struct iwl4965_rx_mpdu_res_start));
1116 len = le16_to_cpu(amsdu->byte_count);
1117 rx_end = (__le32 *) (pkt->u.raw +
1118 sizeof(struct iwl4965_rx_mpdu_res_start) + len);
1119 }
1120
1121 if (!(*rx_end & RX_RES_STATUS_NO_CRC32_ERROR) ||
1122 !(*rx_end & RX_RES_STATUS_NO_RXE_OVERFLOW)) {
1123 IWL_DEBUG_RX("Bad CRC or FIFO: 0x%08X.\n",
1124 le32_to_cpu(*rx_end));
1125 return;
1126 }
1127
1128 priv->ucode_beacon_time = le32_to_cpu(rx_start->beacon_time_stamp);
1129
1130 /* Find max signal strength (dBm) among 3 antenna/receiver chains */
1131 rx_status.signal = iwl_calc_rssi(priv, rx_start);
1132
1133 /* Meaningful noise values are available only from beacon statistics,
1134 * which are gathered only when associated, and indicate noise
1135 * only for the associated network channel ...
1136 * Ignore these noise values while scanning (other channels) */
1137 if (iwl_is_associated(priv) &&
1138 !test_bit(STATUS_SCANNING, &priv->status)) {
1139 rx_status.noise = priv->last_rx_noise;
1140 rx_status.qual = iwl_calc_sig_qual(rx_status.signal,
1141 rx_status.noise);
1142 } else {
1143 rx_status.noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
1144 rx_status.qual = iwl_calc_sig_qual(rx_status.signal, 0);
1145 }
1146
1147 /* Reset beacon noise level if not associated. */
1148 if (!iwl_is_associated(priv))
1149 priv->last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
1150
1151 /* Set "1" to report good data frames in groups of 100 */
1152 /* FIXME: need to optimze the call: */
1153 iwl_dbg_report_frame(priv, pkt, header, 1);
1154
1155 IWL_DEBUG_STATS_LIMIT("Rssi %d, noise %d, qual %d, TSF %llu\n",
1156 rx_status.signal, rx_status.noise, rx_status.signal,
1157 (unsigned long long)rx_status.mactime);
1158
1159 /*
1160 * "antenna number"
1161 *
1162 * It seems that the antenna field in the phy flags value
1163 * is actually a bitfield. This is undefined by radiotap,
1164 * it wants an actual antenna number but I always get "7"
1165 * for most legacy frames I receive indicating that the
1166 * same frame was received on all three RX chains.
1167 *
1168 * I think this field should be removed in favour of a
1169 * new 802.11n radiotap field "RX chains" that is defined
1170 * as a bitmask.
1171 */
1172 rx_status.antenna = le16_to_cpu(rx_start->phy_flags &
1173 RX_RES_PHY_FLAGS_ANTENNA_MSK) >> 4;
1174
1175 /* set the preamble flag if appropriate */
1176 if (rx_start->phy_flags & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK)
1177 rx_status.flag |= RX_FLAG_SHORTPRE;
1178
1179 /* Take shortcut when only in monitor mode */
1180 if (priv->iw_mode == NL80211_IFTYPE_MONITOR) {
1181 iwl_pass_packet_to_mac80211(priv, include_phy,
1182 rxb, &rx_status);
1183 return;
1184 }
1185
1186 network_packet = iwl_is_network_packet(priv, header);
1187 if (network_packet) {
1188 priv->last_rx_rssi = rx_status.signal;
1189 priv->last_beacon_time = priv->ucode_beacon_time;
1190 priv->last_tsf = le64_to_cpu(rx_start->timestamp);
1191 }
1192
1193 fc = le16_to_cpu(header->frame_control);
1194 switch (fc & IEEE80211_FCTL_FTYPE) {
1195 case IEEE80211_FTYPE_MGMT:
1196 case IEEE80211_FTYPE_DATA:
1197 if (priv->iw_mode == NL80211_IFTYPE_AP)
1198 iwl_update_ps_mode(priv, fc & IEEE80211_FCTL_PM,
1199 header->addr2);
1200 /* fall through */
1201 default:
1202 iwl_pass_packet_to_mac80211(priv, include_phy, rxb,
1203 &rx_status);
1204 break;
1205
1206 }
1207}
1208EXPORT_SYMBOL(iwl_rx_reply_rx);
1209
1210/* Cache phy data (Rx signal strength, etc) for HT frame (REPLY_RX_PHY_CMD).
1211 * This will be used later in iwl_rx_reply_rx() for REPLY_RX_MPDU_CMD. */
1212void iwl_rx_reply_rx_phy(struct iwl_priv *priv,
1213 struct iwl_rx_mem_buffer *rxb)
1214{
1215 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
1216 priv->last_phy_res[0] = 1;
1217 memcpy(&priv->last_phy_res[1], &(pkt->u.raw[0]),
1218 sizeof(struct iwl_rx_phy_res));
1219}
1220EXPORT_SYMBOL(iwl_rx_reply_rx_phy);
diff --git a/drivers/net/wireless/iwlwifi/iwl-scan.c b/drivers/net/wireless/iwlwifi/iwl-scan.c
new file mode 100644
index 000000000000..3b0bee331a33
--- /dev/null
+++ b/drivers/net/wireless/iwlwifi/iwl-scan.c
@@ -0,0 +1,947 @@
1/******************************************************************************
2 *
3 * GPL LICENSE SUMMARY
4 *
5 * Copyright(c) 2008 Intel Corporation. All rights reserved.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
19 * USA
20 *
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
23 *
24 * Contact Information:
25 * Tomas Winkler <tomas.winkler@intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *****************************************************************************/
28#include <net/mac80211.h>
29#include <linux/etherdevice.h>
30
31#include "iwl-eeprom.h"
32#include "iwl-dev.h"
33#include "iwl-core.h"
34#include "iwl-sta.h"
35#include "iwl-io.h"
36#include "iwl-helpers.h"
37
38/* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after
39 * sending probe req. This should be set long enough to hear probe responses
40 * from more than one AP. */
41#define IWL_ACTIVE_DWELL_TIME_24 (30) /* all times in msec */
42#define IWL_ACTIVE_DWELL_TIME_52 (20)
43
44#define IWL_ACTIVE_DWELL_FACTOR_24GHZ (3)
45#define IWL_ACTIVE_DWELL_FACTOR_52GHZ (2)
46
47/* For faster active scanning, scan will move to the next channel if fewer than
48 * PLCP_QUIET_THRESH packets are heard on this channel within
49 * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell
50 * time if it's a quiet channel (nothing responded to our probe, and there's
51 * no other traffic).
52 * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */
53#define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */
54#define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(10) /* msec */
55
56/* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel.
57 * Must be set longer than active dwell time.
58 * For the most reliable scan, set > AP beacon interval (typically 100msec). */
59#define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */
60#define IWL_PASSIVE_DWELL_TIME_52 (10)
61#define IWL_PASSIVE_DWELL_BASE (100)
62#define IWL_CHANNEL_TUNE_TIME 5
63
64#define IWL_SCAN_PROBE_MASK(n) cpu_to_le32((BIT(n) | (BIT(n) - BIT(1))))
65
66
67static int scan_tx_ant[3] = {
68 RATE_MCS_ANT_A_MSK, RATE_MCS_ANT_B_MSK, RATE_MCS_ANT_C_MSK
69};
70
71
72
73static int iwl_is_empty_essid(const char *essid, int essid_len)
74{
75 /* Single white space is for Linksys APs */
76 if (essid_len == 1 && essid[0] == ' ')
77 return 1;
78
79 /* Otherwise, if the entire essid is 0, we assume it is hidden */
80 while (essid_len) {
81 essid_len--;
82 if (essid[essid_len] != '\0')
83 return 0;
84 }
85
86 return 1;
87}
88
89
90
91static const char *iwl_escape_essid(const char *essid, u8 essid_len)
92{
93 static char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
94 const char *s = essid;
95 char *d = escaped;
96
97 if (iwl_is_empty_essid(essid, essid_len)) {
98 memcpy(escaped, "<hidden>", sizeof("<hidden>"));
99 return escaped;
100 }
101
102 essid_len = min(essid_len, (u8) IW_ESSID_MAX_SIZE);
103 while (essid_len--) {
104 if (*s == '\0') {
105 *d++ = '\\';
106 *d++ = '0';
107 s++;
108 } else
109 *d++ = *s++;
110 }
111 *d = '\0';
112 return escaped;
113}
114
115/**
116 * iwl_scan_cancel - Cancel any currently executing HW scan
117 *
118 * NOTE: priv->mutex is not required before calling this function
119 */
120int iwl_scan_cancel(struct iwl_priv *priv)
121{
122 if (!test_bit(STATUS_SCAN_HW, &priv->status)) {
123 clear_bit(STATUS_SCANNING, &priv->status);
124 return 0;
125 }
126
127 if (test_bit(STATUS_SCANNING, &priv->status)) {
128 if (!test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
129 IWL_DEBUG_SCAN("Queuing scan abort.\n");
130 set_bit(STATUS_SCAN_ABORTING, &priv->status);
131 queue_work(priv->workqueue, &priv->abort_scan);
132
133 } else
134 IWL_DEBUG_SCAN("Scan abort already in progress.\n");
135
136 return test_bit(STATUS_SCANNING, &priv->status);
137 }
138
139 return 0;
140}
141EXPORT_SYMBOL(iwl_scan_cancel);
142/**
143 * iwl_scan_cancel_timeout - Cancel any currently executing HW scan
144 * @ms: amount of time to wait (in milliseconds) for scan to abort
145 *
146 * NOTE: priv->mutex must be held before calling this function
147 */
148int iwl_scan_cancel_timeout(struct iwl_priv *priv, unsigned long ms)
149{
150 unsigned long now = jiffies;
151 int ret;
152
153 ret = iwl_scan_cancel(priv);
154 if (ret && ms) {
155 mutex_unlock(&priv->mutex);
156 while (!time_after(jiffies, now + msecs_to_jiffies(ms)) &&
157 test_bit(STATUS_SCANNING, &priv->status))
158 msleep(1);
159 mutex_lock(&priv->mutex);
160
161 return test_bit(STATUS_SCANNING, &priv->status);
162 }
163
164 return ret;
165}
166EXPORT_SYMBOL(iwl_scan_cancel_timeout);
167
168static int iwl_send_scan_abort(struct iwl_priv *priv)
169{
170 int ret = 0;
171 struct iwl_rx_packet *res;
172 struct iwl_host_cmd cmd = {
173 .id = REPLY_SCAN_ABORT_CMD,
174 .meta.flags = CMD_WANT_SKB,
175 };
176
177 /* If there isn't a scan actively going on in the hardware
178 * then we are in between scan bands and not actually
179 * actively scanning, so don't send the abort command */
180 if (!test_bit(STATUS_SCAN_HW, &priv->status)) {
181 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
182 return 0;
183 }
184
185 ret = iwl_send_cmd_sync(priv, &cmd);
186 if (ret) {
187 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
188 return ret;
189 }
190
191 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
192 if (res->u.status != CAN_ABORT_STATUS) {
193 /* The scan abort will return 1 for success or
194 * 2 for "failure". A failure condition can be
195 * due to simply not being in an active scan which
196 * can occur if we send the scan abort before we
197 * the microcode has notified us that a scan is
198 * completed. */
199 IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res->u.status);
200 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
201 clear_bit(STATUS_SCAN_HW, &priv->status);
202 }
203
204 priv->alloc_rxb_skb--;
205 dev_kfree_skb_any(cmd.meta.u.skb);
206
207 return ret;
208}
209
210
211/* Service response to REPLY_SCAN_CMD (0x80) */
212static void iwl_rx_reply_scan(struct iwl_priv *priv,
213 struct iwl_rx_mem_buffer *rxb)
214{
215#ifdef CONFIG_IWLWIFI_DEBUG
216 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
217 struct iwl_scanreq_notification *notif =
218 (struct iwl_scanreq_notification *)pkt->u.raw;
219
220 IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status);
221#endif
222}
223
224/* Service SCAN_START_NOTIFICATION (0x82) */
225static void iwl_rx_scan_start_notif(struct iwl_priv *priv,
226 struct iwl_rx_mem_buffer *rxb)
227{
228 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
229 struct iwl_scanstart_notification *notif =
230 (struct iwl_scanstart_notification *)pkt->u.raw;
231 priv->scan_start_tsf = le32_to_cpu(notif->tsf_low);
232 IWL_DEBUG_SCAN("Scan start: "
233 "%d [802.11%s] "
234 "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n",
235 notif->channel,
236 notif->band ? "bg" : "a",
237 le32_to_cpu(notif->tsf_high),
238 le32_to_cpu(notif->tsf_low),
239 notif->status, notif->beacon_timer);
240}
241
242/* Service SCAN_RESULTS_NOTIFICATION (0x83) */
243static void iwl_rx_scan_results_notif(struct iwl_priv *priv,
244 struct iwl_rx_mem_buffer *rxb)
245{
246#ifdef CONFIG_IWLWIFI_DEBUG
247 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
248 struct iwl_scanresults_notification *notif =
249 (struct iwl_scanresults_notification *)pkt->u.raw;
250
251 IWL_DEBUG_SCAN("Scan ch.res: "
252 "%d [802.11%s] "
253 "(TSF: 0x%08X:%08X) - %d "
254 "elapsed=%lu usec (%dms since last)\n",
255 notif->channel,
256 notif->band ? "bg" : "a",
257 le32_to_cpu(notif->tsf_high),
258 le32_to_cpu(notif->tsf_low),
259 le32_to_cpu(notif->statistics[0]),
260 le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf,
261 jiffies_to_msecs(elapsed_jiffies
262 (priv->last_scan_jiffies, jiffies)));
263#endif
264
265 priv->last_scan_jiffies = jiffies;
266 priv->next_scan_jiffies = 0;
267}
268
269/* Service SCAN_COMPLETE_NOTIFICATION (0x84) */
270static void iwl_rx_scan_complete_notif(struct iwl_priv *priv,
271 struct iwl_rx_mem_buffer *rxb)
272{
273#ifdef CONFIG_IWLWIFI_DEBUG
274 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
275 struct iwl_scancomplete_notification *scan_notif = (void *)pkt->u.raw;
276
277 IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n",
278 scan_notif->scanned_channels,
279 scan_notif->tsf_low,
280 scan_notif->tsf_high, scan_notif->status);
281#endif
282
283 /* The HW is no longer scanning */
284 clear_bit(STATUS_SCAN_HW, &priv->status);
285
286 /* The scan completion notification came in, so kill that timer... */
287 cancel_delayed_work(&priv->scan_check);
288
289 IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n",
290 (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) ?
291 "2.4" : "5.2",
292 jiffies_to_msecs(elapsed_jiffies
293 (priv->scan_pass_start, jiffies)));
294
295 /* Remove this scanned band from the list of pending
296 * bands to scan, band G precedes A in order of scanning
297 * as seen in iwl_bg_request_scan */
298 if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ))
299 priv->scan_bands &= ~BIT(IEEE80211_BAND_2GHZ);
300 else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ))
301 priv->scan_bands &= ~BIT(IEEE80211_BAND_5GHZ);
302
303 /* If a request to abort was given, or the scan did not succeed
304 * then we reset the scan state machine and terminate,
305 * re-queuing another scan if one has been requested */
306 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
307 IWL_DEBUG_INFO("Aborted scan completed.\n");
308 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
309 } else {
310 /* If there are more bands on this scan pass reschedule */
311 if (priv->scan_bands)
312 goto reschedule;
313 }
314
315 priv->last_scan_jiffies = jiffies;
316 priv->next_scan_jiffies = 0;
317 IWL_DEBUG_INFO("Setting scan to off\n");
318
319 clear_bit(STATUS_SCANNING, &priv->status);
320
321 IWL_DEBUG_INFO("Scan took %dms\n",
322 jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies)));
323
324 queue_work(priv->workqueue, &priv->scan_completed);
325
326 return;
327
328reschedule:
329 priv->scan_pass_start = jiffies;
330 queue_work(priv->workqueue, &priv->request_scan);
331}
332
333void iwl_setup_rx_scan_handlers(struct iwl_priv *priv)
334{
335 /* scan handlers */
336 priv->rx_handlers[REPLY_SCAN_CMD] = iwl_rx_reply_scan;
337 priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl_rx_scan_start_notif;
338 priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] =
339 iwl_rx_scan_results_notif;
340 priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] =
341 iwl_rx_scan_complete_notif;
342}
343EXPORT_SYMBOL(iwl_setup_rx_scan_handlers);
344
345static inline u16 iwl_get_active_dwell_time(struct iwl_priv *priv,
346 enum ieee80211_band band,
347 u8 n_probes)
348{
349 if (band == IEEE80211_BAND_5GHZ)
350 return IWL_ACTIVE_DWELL_TIME_52 +
351 IWL_ACTIVE_DWELL_FACTOR_52GHZ * (n_probes + 1);
352 else
353 return IWL_ACTIVE_DWELL_TIME_24 +
354 IWL_ACTIVE_DWELL_FACTOR_24GHZ * (n_probes + 1);
355}
356
357static u16 iwl_get_passive_dwell_time(struct iwl_priv *priv,
358 enum ieee80211_band band)
359{
360 u16 passive = (band == IEEE80211_BAND_2GHZ) ?
361 IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 :
362 IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52;
363
364 if (iwl_is_associated(priv)) {
365 /* If we're associated, we clamp the maximum passive
366 * dwell time to be 98% of the beacon interval (minus
367 * 2 * channel tune time) */
368 passive = priv->beacon_int;
369 if ((passive > IWL_PASSIVE_DWELL_BASE) || !passive)
370 passive = IWL_PASSIVE_DWELL_BASE;
371 passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2;
372 }
373
374 return passive;
375}
376
377static int iwl_get_channels_for_scan(struct iwl_priv *priv,
378 enum ieee80211_band band,
379 u8 is_active, u8 n_probes,
380 struct iwl_scan_channel *scan_ch)
381{
382 const struct ieee80211_channel *channels = NULL;
383 const struct ieee80211_supported_band *sband;
384 const struct iwl_channel_info *ch_info;
385 u16 passive_dwell = 0;
386 u16 active_dwell = 0;
387 int added, i;
388 u16 channel;
389
390 sband = iwl_get_hw_mode(priv, band);
391 if (!sband)
392 return 0;
393
394 channels = sband->channels;
395
396 active_dwell = iwl_get_active_dwell_time(priv, band, n_probes);
397 passive_dwell = iwl_get_passive_dwell_time(priv, band);
398
399 if (passive_dwell <= active_dwell)
400 passive_dwell = active_dwell + 1;
401
402 for (i = 0, added = 0; i < sband->n_channels; i++) {
403 if (channels[i].flags & IEEE80211_CHAN_DISABLED)
404 continue;
405
406 channel =
407 ieee80211_frequency_to_channel(channels[i].center_freq);
408 scan_ch->channel = cpu_to_le16(channel);
409
410 ch_info = iwl_get_channel_info(priv, band, channel);
411 if (!is_channel_valid(ch_info)) {
412 IWL_DEBUG_SCAN("Channel %d is INVALID for this band.\n",
413 channel);
414 continue;
415 }
416
417 if (!is_active || is_channel_passive(ch_info) ||
418 (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN))
419 scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE;
420 else
421 scan_ch->type = SCAN_CHANNEL_TYPE_ACTIVE;
422
423 if (n_probes)
424 scan_ch->type |= IWL_SCAN_PROBE_MASK(n_probes);
425
426 scan_ch->active_dwell = cpu_to_le16(active_dwell);
427 scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
428
429 /* Set txpower levels to defaults */
430 scan_ch->dsp_atten = 110;
431
432 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
433 * power level:
434 * scan_ch->tx_gain = ((1 << 5) | (2 << 3)) | 3;
435 */
436 if (band == IEEE80211_BAND_5GHZ)
437 scan_ch->tx_gain = ((1 << 5) | (3 << 3)) | 3;
438 else
439 scan_ch->tx_gain = ((1 << 5) | (5 << 3));
440
441 IWL_DEBUG_SCAN("Scanning ch=%d prob=0x%X [%s %d]\n",
442 channel, le32_to_cpu(scan_ch->type),
443 (scan_ch->type & SCAN_CHANNEL_TYPE_ACTIVE) ?
444 "ACTIVE" : "PASSIVE",
445 (scan_ch->type & SCAN_CHANNEL_TYPE_ACTIVE) ?
446 active_dwell : passive_dwell);
447
448 scan_ch++;
449 added++;
450 }
451
452 IWL_DEBUG_SCAN("total channels to scan %d \n", added);
453 return added;
454}
455
456void iwl_init_scan_params(struct iwl_priv *priv)
457{
458 if (!priv->scan_tx_ant[IEEE80211_BAND_5GHZ])
459 priv->scan_tx_ant[IEEE80211_BAND_5GHZ] = RATE_MCS_ANT_INIT_IND;
460 if (!priv->scan_tx_ant[IEEE80211_BAND_2GHZ])
461 priv->scan_tx_ant[IEEE80211_BAND_2GHZ] = RATE_MCS_ANT_INIT_IND;
462}
463
464int iwl_scan_initiate(struct iwl_priv *priv)
465{
466 if (!iwl_is_ready_rf(priv)) {
467 IWL_DEBUG_SCAN("Aborting scan due to not ready.\n");
468 return -EIO;
469 }
470
471 if (test_bit(STATUS_SCANNING, &priv->status)) {
472 IWL_DEBUG_SCAN("Scan already in progress.\n");
473 return -EAGAIN;
474 }
475
476 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
477 IWL_DEBUG_SCAN("Scan request while abort pending\n");
478 return -EAGAIN;
479 }
480
481 IWL_DEBUG_INFO("Starting scan...\n");
482 if (priv->cfg->sku & IWL_SKU_G)
483 priv->scan_bands |= BIT(IEEE80211_BAND_2GHZ);
484 if (priv->cfg->sku & IWL_SKU_A)
485 priv->scan_bands |= BIT(IEEE80211_BAND_5GHZ);
486 set_bit(STATUS_SCANNING, &priv->status);
487 priv->scan_start = jiffies;
488 priv->scan_pass_start = priv->scan_start;
489
490 queue_work(priv->workqueue, &priv->request_scan);
491
492 return 0;
493}
494EXPORT_SYMBOL(iwl_scan_initiate);
495
496#define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
497
498static void iwl_bg_scan_check(struct work_struct *data)
499{
500 struct iwl_priv *priv =
501 container_of(data, struct iwl_priv, scan_check.work);
502
503 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
504 return;
505
506 mutex_lock(&priv->mutex);
507 if (test_bit(STATUS_SCANNING, &priv->status) ||
508 test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
509 IWL_DEBUG(IWL_DL_SCAN, "Scan completion watchdog resetting "
510 "adapter (%dms)\n",
511 jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG));
512
513 if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
514 iwl_send_scan_abort(priv);
515 }
516 mutex_unlock(&priv->mutex);
517}
518/**
519 * iwl_supported_rate_to_ie - fill in the supported rate in IE field
520 *
521 * return : set the bit for each supported rate insert in ie
522 */
523static u16 iwl_supported_rate_to_ie(u8 *ie, u16 supported_rate,
524 u16 basic_rate, int *left)
525{
526 u16 ret_rates = 0, bit;
527 int i;
528 u8 *cnt = ie;
529 u8 *rates = ie + 1;
530
531 for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) {
532 if (bit & supported_rate) {
533 ret_rates |= bit;
534 rates[*cnt] = iwl_rates[i].ieee |
535 ((bit & basic_rate) ? 0x80 : 0x00);
536 (*cnt)++;
537 (*left)--;
538 if ((*left <= 0) ||
539 (*cnt >= IWL_SUPPORTED_RATES_IE_LEN))
540 break;
541 }
542 }
543
544 return ret_rates;
545}
546
547
548static void iwl_ht_cap_to_ie(const struct ieee80211_supported_band *sband,
549 u8 *pos, int *left)
550{
551 struct ieee80211_ht_cap *ht_cap;
552
553 if (!sband || !sband->ht_info.ht_supported)
554 return;
555
556 if (*left < sizeof(struct ieee80211_ht_cap))
557 return;
558
559 *pos++ = sizeof(struct ieee80211_ht_cap);
560 ht_cap = (struct ieee80211_ht_cap *) pos;
561
562 ht_cap->cap_info = cpu_to_le16(sband->ht_info.cap);
563 memcpy(ht_cap->supp_mcs_set, sband->ht_info.supp_mcs_set, 16);
564 ht_cap->ampdu_params_info =
565 (sband->ht_info.ampdu_factor & IEEE80211_HT_CAP_AMPDU_FACTOR) |
566 ((sband->ht_info.ampdu_density << 2) &
567 IEEE80211_HT_CAP_AMPDU_DENSITY);
568 *left -= sizeof(struct ieee80211_ht_cap);
569}
570
571/**
572 * iwl_fill_probe_req - fill in all required fields and IE for probe request
573 */
574
575static u16 iwl_fill_probe_req(struct iwl_priv *priv,
576 enum ieee80211_band band,
577 struct ieee80211_mgmt *frame,
578 int left)
579{
580 int len = 0;
581 u8 *pos = NULL;
582 u16 active_rates, ret_rates, cck_rates, active_rate_basic;
583 const struct ieee80211_supported_band *sband =
584 iwl_get_hw_mode(priv, band);
585
586
587 /* Make sure there is enough space for the probe request,
588 * two mandatory IEs and the data */
589 left -= 24;
590 if (left < 0)
591 return 0;
592
593 frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
594 memcpy(frame->da, iwl_bcast_addr, ETH_ALEN);
595 memcpy(frame->sa, priv->mac_addr, ETH_ALEN);
596 memcpy(frame->bssid, iwl_bcast_addr, ETH_ALEN);
597 frame->seq_ctrl = 0;
598
599 len += 24;
600
601 /* ...next IE... */
602 pos = &frame->u.probe_req.variable[0];
603
604 /* fill in our indirect SSID IE */
605 left -= 2;
606 if (left < 0)
607 return 0;
608 *pos++ = WLAN_EID_SSID;
609 *pos++ = 0;
610
611 len += 2;
612
613 /* fill in supported rate */
614 left -= 2;
615 if (left < 0)
616 return 0;
617
618 *pos++ = WLAN_EID_SUPP_RATES;
619 *pos = 0;
620
621 /* exclude 60M rate */
622 active_rates = priv->rates_mask;
623 active_rates &= ~IWL_RATE_60M_MASK;
624
625 active_rate_basic = active_rates & IWL_BASIC_RATES_MASK;
626
627 cck_rates = IWL_CCK_RATES_MASK & active_rates;
628 ret_rates = iwl_supported_rate_to_ie(pos, cck_rates,
629 active_rate_basic, &left);
630 active_rates &= ~ret_rates;
631
632 ret_rates = iwl_supported_rate_to_ie(pos, active_rates,
633 active_rate_basic, &left);
634 active_rates &= ~ret_rates;
635
636 len += 2 + *pos;
637 pos += (*pos) + 1;
638
639 if (active_rates == 0)
640 goto fill_end;
641
642 /* fill in supported extended rate */
643 /* ...next IE... */
644 left -= 2;
645 if (left < 0)
646 return 0;
647 /* ... fill it in... */
648 *pos++ = WLAN_EID_EXT_SUPP_RATES;
649 *pos = 0;
650 iwl_supported_rate_to_ie(pos, active_rates, active_rate_basic, &left);
651 if (*pos > 0) {
652 len += 2 + *pos;
653 pos += (*pos) + 1;
654 } else {
655 pos--;
656 }
657
658 fill_end:
659
660 left -= 2;
661 if (left < 0)
662 return 0;
663
664 *pos++ = WLAN_EID_HT_CAPABILITY;
665 *pos = 0;
666 iwl_ht_cap_to_ie(sband, pos, &left);
667 if (*pos > 0)
668 len += 2 + *pos;
669
670 return (u16)len;
671}
672
673static u32 iwl_scan_tx_ant(struct iwl_priv *priv, enum ieee80211_band band)
674{
675 int i, ind;
676
677 ind = priv->scan_tx_ant[band];
678 for (i = 0; i < priv->hw_params.tx_chains_num; i++) {
679 ind = (ind+1) >= priv->hw_params.tx_chains_num ? 0 : ind+1;
680 if (priv->hw_params.valid_tx_ant & (1 << ind)) {
681 priv->scan_tx_ant[band] = ind;
682 break;
683 }
684 }
685 IWL_DEBUG_SCAN("select TX ANT = %c\n", 'A' + ind);
686 return scan_tx_ant[ind];
687}
688
689
690static void iwl_bg_request_scan(struct work_struct *data)
691{
692 struct iwl_priv *priv =
693 container_of(data, struct iwl_priv, request_scan);
694 struct iwl_host_cmd cmd = {
695 .id = REPLY_SCAN_CMD,
696 .len = sizeof(struct iwl_scan_cmd),
697 .meta.flags = CMD_SIZE_HUGE,
698 };
699 struct iwl_scan_cmd *scan;
700 struct ieee80211_conf *conf = NULL;
701 int ret = 0;
702 u32 tx_ant;
703 u16 cmd_len;
704 enum ieee80211_band band;
705 u8 n_probes = 2;
706 u8 rx_chain = priv->hw_params.valid_rx_ant;
707
708 conf = ieee80211_get_hw_conf(priv->hw);
709
710 mutex_lock(&priv->mutex);
711
712 if (!iwl_is_ready(priv)) {
713 IWL_WARNING("request scan called when driver not ready.\n");
714 goto done;
715 }
716
717 /* Make sure the scan wasn't cancelled before this queued work
718 * was given the chance to run... */
719 if (!test_bit(STATUS_SCANNING, &priv->status))
720 goto done;
721
722 /* This should never be called or scheduled if there is currently
723 * a scan active in the hardware. */
724 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
725 IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. "
726 "Ignoring second request.\n");
727 ret = -EIO;
728 goto done;
729 }
730
731 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
732 IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n");
733 goto done;
734 }
735
736 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
737 IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n");
738 goto done;
739 }
740
741 if (iwl_is_rfkill(priv)) {
742 IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n");
743 goto done;
744 }
745
746 if (!test_bit(STATUS_READY, &priv->status)) {
747 IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n");
748 goto done;
749 }
750
751 if (!priv->scan_bands) {
752 IWL_DEBUG_HC("Aborting scan due to no requested bands\n");
753 goto done;
754 }
755
756 if (!priv->scan) {
757 priv->scan = kmalloc(sizeof(struct iwl_scan_cmd) +
758 IWL_MAX_SCAN_SIZE, GFP_KERNEL);
759 if (!priv->scan) {
760 ret = -ENOMEM;
761 goto done;
762 }
763 }
764 scan = priv->scan;
765 memset(scan, 0, sizeof(struct iwl_scan_cmd) + IWL_MAX_SCAN_SIZE);
766
767 scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
768 scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
769
770 if (iwl_is_associated(priv)) {
771 u16 interval = 0;
772 u32 extra;
773 u32 suspend_time = 100;
774 u32 scan_suspend_time = 100;
775 unsigned long flags;
776
777 IWL_DEBUG_INFO("Scanning while associated...\n");
778
779 spin_lock_irqsave(&priv->lock, flags);
780 interval = priv->beacon_int;
781 spin_unlock_irqrestore(&priv->lock, flags);
782
783 scan->suspend_time = 0;
784 scan->max_out_time = cpu_to_le32(200 * 1024);
785 if (!interval)
786 interval = suspend_time;
787
788 extra = (suspend_time / interval) << 22;
789 scan_suspend_time = (extra |
790 ((suspend_time % interval) * 1024));
791 scan->suspend_time = cpu_to_le32(scan_suspend_time);
792 IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n",
793 scan_suspend_time, interval);
794 }
795
796 /* We should add the ability for user to lock to PASSIVE ONLY */
797 if (priv->one_direct_scan) {
798 IWL_DEBUG_SCAN("Start direct scan for '%s'\n",
799 iwl_escape_essid(priv->direct_ssid,
800 priv->direct_ssid_len));
801 scan->direct_scan[0].id = WLAN_EID_SSID;
802 scan->direct_scan[0].len = priv->direct_ssid_len;
803 memcpy(scan->direct_scan[0].ssid,
804 priv->direct_ssid, priv->direct_ssid_len);
805 n_probes++;
806 } else if (!iwl_is_associated(priv) && priv->essid_len) {
807 IWL_DEBUG_SCAN("Start direct scan for '%s' (not associated)\n",
808 iwl_escape_essid(priv->essid, priv->essid_len));
809 scan->direct_scan[0].id = WLAN_EID_SSID;
810 scan->direct_scan[0].len = priv->essid_len;
811 memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len);
812 n_probes++;
813 } else {
814 IWL_DEBUG_SCAN("Start indirect scan.\n");
815 }
816
817 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
818 scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id;
819 scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
820
821
822 if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) {
823 band = IEEE80211_BAND_2GHZ;
824 scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
825 tx_ant = iwl_scan_tx_ant(priv, band);
826 if (priv->active_rxon.flags & RXON_FLG_CHANNEL_MODE_PURE_40_MSK)
827 scan->tx_cmd.rate_n_flags =
828 iwl_hw_set_rate_n_flags(IWL_RATE_6M_PLCP,
829 tx_ant);
830 else
831 scan->tx_cmd.rate_n_flags =
832 iwl_hw_set_rate_n_flags(IWL_RATE_1M_PLCP,
833 tx_ant |
834 RATE_MCS_CCK_MSK);
835 scan->good_CRC_th = 0;
836 } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) {
837 band = IEEE80211_BAND_5GHZ;
838 tx_ant = iwl_scan_tx_ant(priv, band);
839 scan->tx_cmd.rate_n_flags =
840 iwl_hw_set_rate_n_flags(IWL_RATE_6M_PLCP,
841 tx_ant);
842 scan->good_CRC_th = IWL_GOOD_CRC_TH;
843
844 /* Force use of chains B and C (0x6) for scan Rx for 4965
845 * Avoid A (0x1) because of its off-channel reception on A-band.
846 */
847 if ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_4965)
848 rx_chain = 0x6;
849 } else {
850 IWL_WARNING("Invalid scan band count\n");
851 goto done;
852 }
853
854 /* MIMO is not used here, but value is required */
855 scan->rx_chain = RXON_RX_CHAIN_DRIVER_FORCE_MSK |
856 cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS) |
857 (rx_chain << RXON_RX_CHAIN_FORCE_SEL_POS) |
858 (0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS));
859
860 cmd_len = iwl_fill_probe_req(priv, band,
861 (struct ieee80211_mgmt *)scan->data,
862 IWL_MAX_SCAN_SIZE - sizeof(*scan));
863
864 scan->tx_cmd.len = cpu_to_le16(cmd_len);
865
866 if (priv->iw_mode == NL80211_IFTYPE_MONITOR)
867 scan->filter_flags = RXON_FILTER_PROMISC_MSK;
868
869 scan->filter_flags |= (RXON_FILTER_ACCEPT_GRP_MSK |
870 RXON_FILTER_BCON_AWARE_MSK);
871
872 scan->channel_count =
873 iwl_get_channels_for_scan(priv, band, 1, /* active */
874 n_probes,
875 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
876
877 if (scan->channel_count == 0) {
878 IWL_DEBUG_SCAN("channel count %d\n", scan->channel_count);
879 goto done;
880 }
881
882 cmd.len += le16_to_cpu(scan->tx_cmd.len) +
883 scan->channel_count * sizeof(struct iwl_scan_channel);
884 cmd.data = scan;
885 scan->len = cpu_to_le16(cmd.len);
886
887 set_bit(STATUS_SCAN_HW, &priv->status);
888 ret = iwl_send_cmd_sync(priv, &cmd);
889 if (ret)
890 goto done;
891
892 queue_delayed_work(priv->workqueue, &priv->scan_check,
893 IWL_SCAN_CHECK_WATCHDOG);
894
895 mutex_unlock(&priv->mutex);
896 return;
897
898 done:
899 /* inform mac80211 scan aborted */
900 queue_work(priv->workqueue, &priv->scan_completed);
901 mutex_unlock(&priv->mutex);
902}
903
904static void iwl_bg_abort_scan(struct work_struct *work)
905{
906 struct iwl_priv *priv = container_of(work, struct iwl_priv, abort_scan);
907
908 if (!iwl_is_ready(priv))
909 return;
910
911 mutex_lock(&priv->mutex);
912
913 set_bit(STATUS_SCAN_ABORTING, &priv->status);
914 iwl_send_scan_abort(priv);
915
916 mutex_unlock(&priv->mutex);
917}
918
919static void iwl_bg_scan_completed(struct work_struct *work)
920{
921 struct iwl_priv *priv =
922 container_of(work, struct iwl_priv, scan_completed);
923
924 IWL_DEBUG_SCAN("SCAN complete scan\n");
925
926 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
927 return;
928
929 ieee80211_scan_completed(priv->hw);
930
931 /* Since setting the TXPOWER may have been deferred while
932 * performing the scan, fire one off */
933 mutex_lock(&priv->mutex);
934 iwl_set_tx_power(priv, priv->tx_power_user_lmt, true);
935 mutex_unlock(&priv->mutex);
936}
937
938
939void iwl_setup_scan_deferred_work(struct iwl_priv *priv)
940{
941 INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed);
942 INIT_WORK(&priv->request_scan, iwl_bg_request_scan);
943 INIT_WORK(&priv->abort_scan, iwl_bg_abort_scan);
944 INIT_DELAYED_WORK(&priv->scan_check, iwl_bg_scan_check);
945}
946EXPORT_SYMBOL(iwl_setup_scan_deferred_work);
947
diff --git a/drivers/net/wireless/iwlwifi/iwl-sta.c b/drivers/net/wireless/iwlwifi/iwl-sta.c
index e4fdfaa2b9b2..61797f3f8d5c 100644
--- a/drivers/net/wireless/iwlwifi/iwl-sta.c
+++ b/drivers/net/wireless/iwlwifi/iwl-sta.c
@@ -28,17 +28,446 @@
28 *****************************************************************************/ 28 *****************************************************************************/
29 29
30#include <net/mac80211.h> 30#include <net/mac80211.h>
31#include <linux/etherdevice.h>
31 32
32#include "iwl-eeprom.h" 33#include "iwl-dev.h"
33#include "iwl-4965.h"
34#include "iwl-core.h" 34#include "iwl-core.h"
35#include "iwl-sta.h" 35#include "iwl-sta.h"
36#include "iwl-io.h"
37#include "iwl-helpers.h" 36#include "iwl-helpers.h"
38#include "iwl-4965.h"
39#include "iwl-sta.h"
40 37
41int iwl_get_free_ucode_key_index(struct iwl_priv *priv) 38
39#define IWL_STA_DRIVER_ACTIVE BIT(0) /* driver entry is active */
40#define IWL_STA_UCODE_ACTIVE BIT(1) /* ucode entry is active */
41
42u8 iwl_find_station(struct iwl_priv *priv, const u8 *addr)
43{
44 int i;
45 int start = 0;
46 int ret = IWL_INVALID_STATION;
47 unsigned long flags;
48 DECLARE_MAC_BUF(mac);
49
50 if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) ||
51 (priv->iw_mode == NL80211_IFTYPE_AP))
52 start = IWL_STA_ID;
53
54 if (is_broadcast_ether_addr(addr))
55 return priv->hw_params.bcast_sta_id;
56
57 spin_lock_irqsave(&priv->sta_lock, flags);
58 for (i = start; i < priv->hw_params.max_stations; i++)
59 if (priv->stations[i].used &&
60 (!compare_ether_addr(priv->stations[i].sta.sta.addr,
61 addr))) {
62 ret = i;
63 goto out;
64 }
65
66 IWL_DEBUG_ASSOC_LIMIT("can not find STA %s total %d\n",
67 print_mac(mac, addr), priv->num_stations);
68
69 out:
70 spin_unlock_irqrestore(&priv->sta_lock, flags);
71 return ret;
72}
73EXPORT_SYMBOL(iwl_find_station);
74
75int iwl_get_ra_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
76{
77 if (priv->iw_mode == NL80211_IFTYPE_STATION) {
78 return IWL_AP_ID;
79 } else {
80 u8 *da = ieee80211_get_DA(hdr);
81 return iwl_find_station(priv, da);
82 }
83}
84EXPORT_SYMBOL(iwl_get_ra_sta_id);
85
86static void iwl_sta_ucode_activate(struct iwl_priv *priv, u8 sta_id)
87{
88 unsigned long flags;
89 DECLARE_MAC_BUF(mac);
90
91 spin_lock_irqsave(&priv->sta_lock, flags);
92
93 if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE))
94 IWL_ERROR("ACTIVATE a non DRIVER active station %d\n", sta_id);
95
96 priv->stations[sta_id].used |= IWL_STA_UCODE_ACTIVE;
97 IWL_DEBUG_ASSOC("Added STA to Ucode: %s\n",
98 print_mac(mac, priv->stations[sta_id].sta.sta.addr));
99
100 spin_unlock_irqrestore(&priv->sta_lock, flags);
101}
102
103static int iwl_add_sta_callback(struct iwl_priv *priv,
104 struct iwl_cmd *cmd, struct sk_buff *skb)
105{
106 struct iwl_rx_packet *res = NULL;
107 u8 sta_id = cmd->cmd.addsta.sta.sta_id;
108
109 if (!skb) {
110 IWL_ERROR("Error: Response NULL in REPLY_ADD_STA.\n");
111 return 1;
112 }
113
114 res = (struct iwl_rx_packet *)skb->data;
115 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
116 IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
117 res->hdr.flags);
118 return 1;
119 }
120
121 switch (res->u.add_sta.status) {
122 case ADD_STA_SUCCESS_MSK:
123 iwl_sta_ucode_activate(priv, sta_id);
124 /* fall through */
125 default:
126 IWL_DEBUG_HC("Received REPLY_ADD_STA:(0x%08X)\n",
127 res->u.add_sta.status);
128 break;
129 }
130
131 /* We didn't cache the SKB; let the caller free it */
132 return 1;
133}
134
135int iwl_send_add_sta(struct iwl_priv *priv,
136 struct iwl_addsta_cmd *sta, u8 flags)
137{
138 struct iwl_rx_packet *res = NULL;
139 int ret = 0;
140 u8 data[sizeof(*sta)];
141 struct iwl_host_cmd cmd = {
142 .id = REPLY_ADD_STA,
143 .meta.flags = flags,
144 .data = data,
145 };
146
147 if (flags & CMD_ASYNC)
148 cmd.meta.u.callback = iwl_add_sta_callback;
149 else
150 cmd.meta.flags |= CMD_WANT_SKB;
151
152 cmd.len = priv->cfg->ops->utils->build_addsta_hcmd(sta, data);
153 ret = iwl_send_cmd(priv, &cmd);
154
155 if (ret || (flags & CMD_ASYNC))
156 return ret;
157
158 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
159 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
160 IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
161 res->hdr.flags);
162 ret = -EIO;
163 }
164
165 if (ret == 0) {
166 switch (res->u.add_sta.status) {
167 case ADD_STA_SUCCESS_MSK:
168 iwl_sta_ucode_activate(priv, sta->sta.sta_id);
169 IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n");
170 break;
171 default:
172 ret = -EIO;
173 IWL_WARNING("REPLY_ADD_STA failed\n");
174 break;
175 }
176 }
177
178 priv->alloc_rxb_skb--;
179 dev_kfree_skb_any(cmd.meta.u.skb);
180
181 return ret;
182}
183EXPORT_SYMBOL(iwl_send_add_sta);
184
185static void iwl_set_ht_add_station(struct iwl_priv *priv, u8 index,
186 struct ieee80211_ht_info *sta_ht_inf)
187{
188 __le32 sta_flags;
189 u8 mimo_ps_mode;
190
191 if (!sta_ht_inf || !sta_ht_inf->ht_supported)
192 goto done;
193
194 mimo_ps_mode = (sta_ht_inf->cap & IEEE80211_HT_CAP_SM_PS) >> 2;
195
196 sta_flags = priv->stations[index].sta.station_flags;
197
198 sta_flags &= ~(STA_FLG_RTS_MIMO_PROT_MSK | STA_FLG_MIMO_DIS_MSK);
199
200 switch (mimo_ps_mode) {
201 case WLAN_HT_CAP_SM_PS_STATIC:
202 sta_flags |= STA_FLG_MIMO_DIS_MSK;
203 break;
204 case WLAN_HT_CAP_SM_PS_DYNAMIC:
205 sta_flags |= STA_FLG_RTS_MIMO_PROT_MSK;
206 break;
207 case WLAN_HT_CAP_SM_PS_DISABLED:
208 break;
209 default:
210 IWL_WARNING("Invalid MIMO PS mode %d\n", mimo_ps_mode);
211 break;
212 }
213
214 sta_flags |= cpu_to_le32(
215 (u32)sta_ht_inf->ampdu_factor << STA_FLG_MAX_AGG_SIZE_POS);
216
217 sta_flags |= cpu_to_le32(
218 (u32)sta_ht_inf->ampdu_density << STA_FLG_AGG_MPDU_DENSITY_POS);
219
220 if (iwl_is_fat_tx_allowed(priv, sta_ht_inf))
221 sta_flags |= STA_FLG_FAT_EN_MSK;
222 else
223 sta_flags &= ~STA_FLG_FAT_EN_MSK;
224
225 priv->stations[index].sta.station_flags = sta_flags;
226 done:
227 return;
228}
229
230/**
231 * iwl_add_station_flags - Add station to tables in driver and device
232 */
233u8 iwl_add_station_flags(struct iwl_priv *priv, const u8 *addr, int is_ap,
234 u8 flags, struct ieee80211_ht_info *ht_info)
235{
236 int i;
237 int sta_id = IWL_INVALID_STATION;
238 struct iwl_station_entry *station;
239 unsigned long flags_spin;
240 DECLARE_MAC_BUF(mac);
241
242 spin_lock_irqsave(&priv->sta_lock, flags_spin);
243 if (is_ap)
244 sta_id = IWL_AP_ID;
245 else if (is_broadcast_ether_addr(addr))
246 sta_id = priv->hw_params.bcast_sta_id;
247 else
248 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) {
249 if (!compare_ether_addr(priv->stations[i].sta.sta.addr,
250 addr)) {
251 sta_id = i;
252 break;
253 }
254
255 if (!priv->stations[i].used &&
256 sta_id == IWL_INVALID_STATION)
257 sta_id = i;
258 }
259
260 /* These two conditions have the same outcome, but keep them separate
261 since they have different meanings */
262 if (unlikely(sta_id == IWL_INVALID_STATION)) {
263 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
264 return sta_id;
265 }
266
267 if (priv->stations[sta_id].used &&
268 !compare_ether_addr(priv->stations[sta_id].sta.sta.addr, addr)) {
269 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
270 return sta_id;
271 }
272
273
274 station = &priv->stations[sta_id];
275 station->used = IWL_STA_DRIVER_ACTIVE;
276 IWL_DEBUG_ASSOC("Add STA to driver ID %d: %s\n",
277 sta_id, print_mac(mac, addr));
278 priv->num_stations++;
279
280 /* Set up the REPLY_ADD_STA command to send to device */
281 memset(&station->sta, 0, sizeof(struct iwl_addsta_cmd));
282 memcpy(station->sta.sta.addr, addr, ETH_ALEN);
283 station->sta.mode = 0;
284 station->sta.sta.sta_id = sta_id;
285 station->sta.station_flags = 0;
286
287 /* BCAST station and IBSS stations do not work in HT mode */
288 if (sta_id != priv->hw_params.bcast_sta_id &&
289 priv->iw_mode != NL80211_IFTYPE_ADHOC)
290 iwl_set_ht_add_station(priv, sta_id, ht_info);
291
292 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
293
294 /* Add station to device's station table */
295 iwl_send_add_sta(priv, &station->sta, flags);
296 return sta_id;
297
298}
299EXPORT_SYMBOL(iwl_add_station_flags);
300
301static void iwl_sta_ucode_deactivate(struct iwl_priv *priv, const char *addr)
302{
303 unsigned long flags;
304 DECLARE_MAC_BUF(mac);
305
306 u8 sta_id = iwl_find_station(priv, addr);
307
308 BUG_ON(sta_id == IWL_INVALID_STATION);
309
310 IWL_DEBUG_ASSOC("Removed STA from Ucode: %s\n",
311 print_mac(mac, addr));
312
313 spin_lock_irqsave(&priv->sta_lock, flags);
314
315 /* Ucode must be active and driver must be non active */
316 if (priv->stations[sta_id].used != IWL_STA_UCODE_ACTIVE)
317 IWL_ERROR("removed non active STA %d\n", sta_id);
318
319 priv->stations[sta_id].used &= ~IWL_STA_UCODE_ACTIVE;
320
321 memset(&priv->stations[sta_id], 0, sizeof(struct iwl_station_entry));
322 spin_unlock_irqrestore(&priv->sta_lock, flags);
323}
324
325static int iwl_remove_sta_callback(struct iwl_priv *priv,
326 struct iwl_cmd *cmd, struct sk_buff *skb)
327{
328 struct iwl_rx_packet *res = NULL;
329 const char *addr = cmd->cmd.rm_sta.addr;
330
331 if (!skb) {
332 IWL_ERROR("Error: Response NULL in REPLY_REMOVE_STA.\n");
333 return 1;
334 }
335
336 res = (struct iwl_rx_packet *)skb->data;
337 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
338 IWL_ERROR("Bad return from REPLY_REMOVE_STA (0x%08X)\n",
339 res->hdr.flags);
340 return 1;
341 }
342
343 switch (res->u.rem_sta.status) {
344 case REM_STA_SUCCESS_MSK:
345 iwl_sta_ucode_deactivate(priv, addr);
346 break;
347 default:
348 IWL_ERROR("REPLY_REMOVE_STA failed\n");
349 break;
350 }
351
352 /* We didn't cache the SKB; let the caller free it */
353 return 1;
354}
355
356static int iwl_send_remove_station(struct iwl_priv *priv, const u8 *addr,
357 u8 flags)
358{
359 struct iwl_rx_packet *res = NULL;
360 int ret;
361
362 struct iwl_rem_sta_cmd rm_sta_cmd;
363
364 struct iwl_host_cmd cmd = {
365 .id = REPLY_REMOVE_STA,
366 .len = sizeof(struct iwl_rem_sta_cmd),
367 .meta.flags = flags,
368 .data = &rm_sta_cmd,
369 };
370
371 memset(&rm_sta_cmd, 0, sizeof(rm_sta_cmd));
372 rm_sta_cmd.num_sta = 1;
373 memcpy(&rm_sta_cmd.addr, addr , ETH_ALEN);
374
375 if (flags & CMD_ASYNC)
376 cmd.meta.u.callback = iwl_remove_sta_callback;
377 else
378 cmd.meta.flags |= CMD_WANT_SKB;
379 ret = iwl_send_cmd(priv, &cmd);
380
381 if (ret || (flags & CMD_ASYNC))
382 return ret;
383
384 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
385 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
386 IWL_ERROR("Bad return from REPLY_REMOVE_STA (0x%08X)\n",
387 res->hdr.flags);
388 ret = -EIO;
389 }
390
391 if (!ret) {
392 switch (res->u.rem_sta.status) {
393 case REM_STA_SUCCESS_MSK:
394 iwl_sta_ucode_deactivate(priv, addr);
395 IWL_DEBUG_ASSOC("REPLY_REMOVE_STA PASSED\n");
396 break;
397 default:
398 ret = -EIO;
399 IWL_ERROR("REPLY_REMOVE_STA failed\n");
400 break;
401 }
402 }
403
404 priv->alloc_rxb_skb--;
405 dev_kfree_skb_any(cmd.meta.u.skb);
406
407 return ret;
408}
409
410/**
411 * iwl_remove_station - Remove driver's knowledge of station.
412 */
413int iwl_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
414{
415 int sta_id = IWL_INVALID_STATION;
416 int i, ret = -EINVAL;
417 unsigned long flags;
418 DECLARE_MAC_BUF(mac);
419
420 spin_lock_irqsave(&priv->sta_lock, flags);
421
422 if (is_ap)
423 sta_id = IWL_AP_ID;
424 else if (is_broadcast_ether_addr(addr))
425 sta_id = priv->hw_params.bcast_sta_id;
426 else
427 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++)
428 if (priv->stations[i].used &&
429 !compare_ether_addr(priv->stations[i].sta.sta.addr,
430 addr)) {
431 sta_id = i;
432 break;
433 }
434
435 if (unlikely(sta_id == IWL_INVALID_STATION))
436 goto out;
437
438 IWL_DEBUG_ASSOC("Removing STA from driver:%d %s\n",
439 sta_id, print_mac(mac, addr));
440
441 if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE)) {
442 IWL_ERROR("Removing %s but non DRIVER active\n",
443 print_mac(mac, addr));
444 goto out;
445 }
446
447 if (!(priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE)) {
448 IWL_ERROR("Removing %s but non UCODE active\n",
449 print_mac(mac, addr));
450 goto out;
451 }
452
453
454 priv->stations[sta_id].used &= ~IWL_STA_DRIVER_ACTIVE;
455
456 priv->num_stations--;
457
458 BUG_ON(priv->num_stations < 0);
459
460 spin_unlock_irqrestore(&priv->sta_lock, flags);
461
462 ret = iwl_send_remove_station(priv, addr, CMD_ASYNC);
463 return ret;
464out:
465 spin_unlock_irqrestore(&priv->sta_lock, flags);
466 return ret;
467}
468EXPORT_SYMBOL(iwl_remove_station);
469
470static int iwl_get_free_ucode_key_index(struct iwl_priv *priv)
42{ 471{
43 int i; 472 int i;
44 473
@@ -91,6 +520,7 @@ int iwl_send_static_wepkey_cmd(struct iwl_priv *priv, u8 send_if_empty)
91 else 520 else
92 return 0; 521 return 0;
93} 522}
523EXPORT_SYMBOL(iwl_send_static_wepkey_cmd);
94 524
95int iwl_remove_default_wep_key(struct iwl_priv *priv, 525int iwl_remove_default_wep_key(struct iwl_priv *priv,
96 struct ieee80211_key_conf *keyconf) 526 struct ieee80211_key_conf *keyconf)
@@ -107,10 +537,13 @@ int iwl_remove_default_wep_key(struct iwl_priv *priv,
107 priv->default_wep_key--; 537 priv->default_wep_key--;
108 memset(&priv->wep_keys[keyconf->keyidx], 0, sizeof(priv->wep_keys[0])); 538 memset(&priv->wep_keys[keyconf->keyidx], 0, sizeof(priv->wep_keys[0]));
109 ret = iwl_send_static_wepkey_cmd(priv, 1); 539 ret = iwl_send_static_wepkey_cmd(priv, 1);
540 IWL_DEBUG_WEP("Remove default WEP key: idx=%d ret=%d\n",
541 keyconf->keyidx, ret);
110 spin_unlock_irqrestore(&priv->sta_lock, flags); 542 spin_unlock_irqrestore(&priv->sta_lock, flags);
111 543
112 return ret; 544 return ret;
113} 545}
546EXPORT_SYMBOL(iwl_remove_default_wep_key);
114 547
115int iwl_set_default_wep_key(struct iwl_priv *priv, 548int iwl_set_default_wep_key(struct iwl_priv *priv,
116 struct ieee80211_key_conf *keyconf) 549 struct ieee80211_key_conf *keyconf)
@@ -118,8 +551,14 @@ int iwl_set_default_wep_key(struct iwl_priv *priv,
118 int ret; 551 int ret;
119 unsigned long flags; 552 unsigned long flags;
120 553
554 if (keyconf->keylen != WEP_KEY_LEN_128 &&
555 keyconf->keylen != WEP_KEY_LEN_64) {
556 IWL_DEBUG_WEP("Bad WEP key length %d\n", keyconf->keylen);
557 return -EINVAL;
558 }
559
121 keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV; 560 keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
122 keyconf->hw_key_idx = keyconf->keyidx; 561 keyconf->hw_key_idx = HW_KEY_DEFAULT;
123 priv->stations[IWL_AP_ID].keyinfo.alg = ALG_WEP; 562 priv->stations[IWL_AP_ID].keyinfo.alg = ALG_WEP;
124 563
125 spin_lock_irqsave(&priv->sta_lock, flags); 564 spin_lock_irqsave(&priv->sta_lock, flags);
@@ -134,10 +573,13 @@ int iwl_set_default_wep_key(struct iwl_priv *priv,
134 keyconf->keylen); 573 keyconf->keylen);
135 574
136 ret = iwl_send_static_wepkey_cmd(priv, 0); 575 ret = iwl_send_static_wepkey_cmd(priv, 0);
576 IWL_DEBUG_WEP("Set default WEP key: len=%d idx=%d ret=%d\n",
577 keyconf->keylen, keyconf->keyidx, ret);
137 spin_unlock_irqrestore(&priv->sta_lock, flags); 578 spin_unlock_irqrestore(&priv->sta_lock, flags);
138 579
139 return ret; 580 return ret;
140} 581}
582EXPORT_SYMBOL(iwl_set_default_wep_key);
141 583
142static int iwl_set_wep_dynamic_key_info(struct iwl_priv *priv, 584static int iwl_set_wep_dynamic_key_info(struct iwl_priv *priv,
143 struct ieee80211_key_conf *keyconf, 585 struct ieee80211_key_conf *keyconf,
@@ -148,7 +590,6 @@ static int iwl_set_wep_dynamic_key_info(struct iwl_priv *priv,
148 int ret; 590 int ret;
149 591
150 keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV; 592 keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
151 keyconf->hw_key_idx = keyconf->keyidx;
152 593
153 key_flags |= (STA_KEY_FLG_WEP | STA_KEY_FLG_MAP_KEY_MSK); 594 key_flags |= (STA_KEY_FLG_WEP | STA_KEY_FLG_MAP_KEY_MSK);
154 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); 595 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
@@ -172,15 +613,18 @@ static int iwl_set_wep_dynamic_key_info(struct iwl_priv *priv,
172 memcpy(&priv->stations[sta_id].sta.key.key[3], 613 memcpy(&priv->stations[sta_id].sta.key.key[3],
173 keyconf->key, keyconf->keylen); 614 keyconf->key, keyconf->keylen);
174 615
175 priv->stations[sta_id].sta.key.key_offset = 616 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
617 == STA_KEY_FLG_NO_ENC)
618 priv->stations[sta_id].sta.key.key_offset =
176 iwl_get_free_ucode_key_index(priv); 619 iwl_get_free_ucode_key_index(priv);
177 priv->stations[sta_id].sta.key.key_flags = key_flags; 620 /* else, we are overriding an existing key => no need to allocated room
621 * in uCode. */
178 622
623 priv->stations[sta_id].sta.key.key_flags = key_flags;
179 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; 624 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
180 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; 625 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
181 626
182 ret = iwl4965_send_add_station(priv, 627 ret = iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
183 &priv->stations[sta_id].sta, CMD_ASYNC);
184 628
185 spin_unlock_irqrestore(&priv->sta_lock, flags); 629 spin_unlock_irqrestore(&priv->sta_lock, flags);
186 630
@@ -202,7 +646,6 @@ static int iwl_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
202 key_flags |= STA_KEY_MULTICAST_MSK; 646 key_flags |= STA_KEY_MULTICAST_MSK;
203 647
204 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; 648 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
205 keyconf->hw_key_idx = keyconf->keyidx;
206 649
207 spin_lock_irqsave(&priv->sta_lock, flags); 650 spin_lock_irqsave(&priv->sta_lock, flags);
208 priv->stations[sta_id].keyinfo.alg = keyconf->alg; 651 priv->stations[sta_id].keyinfo.alg = keyconf->alg;
@@ -214,8 +657,13 @@ static int iwl_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
214 memcpy(priv->stations[sta_id].sta.key.key, keyconf->key, 657 memcpy(priv->stations[sta_id].sta.key.key, keyconf->key,
215 keyconf->keylen); 658 keyconf->keylen);
216 659
217 priv->stations[sta_id].sta.key.key_offset = 660 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
218 iwl_get_free_ucode_key_index(priv); 661 == STA_KEY_FLG_NO_ENC)
662 priv->stations[sta_id].sta.key.key_offset =
663 iwl_get_free_ucode_key_index(priv);
664 /* else, we are overriding an existing key => no need to allocated room
665 * in uCode. */
666
219 priv->stations[sta_id].sta.key.key_flags = key_flags; 667 priv->stations[sta_id].sta.key.key_flags = key_flags;
220 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; 668 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
221 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; 669 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
@@ -223,8 +671,7 @@ static int iwl_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
223 spin_unlock_irqrestore(&priv->sta_lock, flags); 671 spin_unlock_irqrestore(&priv->sta_lock, flags);
224 672
225 IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n"); 673 IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n");
226 return iwl4965_send_add_station(priv, 674 return iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
227 &priv->stations[sta_id].sta, CMD_ASYNC);
228} 675}
229 676
230static int iwl_set_tkip_dynamic_key_info(struct iwl_priv *priv, 677static int iwl_set_tkip_dynamic_key_info(struct iwl_priv *priv,
@@ -236,15 +683,18 @@ static int iwl_set_tkip_dynamic_key_info(struct iwl_priv *priv,
236 683
237 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; 684 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
238 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; 685 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
239 keyconf->hw_key_idx = keyconf->keyidx;
240 686
241 spin_lock_irqsave(&priv->sta_lock, flags); 687 spin_lock_irqsave(&priv->sta_lock, flags);
242 688
243 priv->stations[sta_id].keyinfo.alg = keyconf->alg; 689 priv->stations[sta_id].keyinfo.alg = keyconf->alg;
244 priv->stations[sta_id].keyinfo.conf = keyconf;
245 priv->stations[sta_id].keyinfo.keylen = 16; 690 priv->stations[sta_id].keyinfo.keylen = 16;
246 priv->stations[sta_id].sta.key.key_offset = 691
692 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
693 == STA_KEY_FLG_NO_ENC)
694 priv->stations[sta_id].sta.key.key_offset =
247 iwl_get_free_ucode_key_index(priv); 695 iwl_get_free_ucode_key_index(priv);
696 /* else, we are overriding an existing key => no need to allocated room
697 * in uCode. */
248 698
249 /* This copy is acutally not needed: we get the key with each TX */ 699 /* This copy is acutally not needed: we get the key with each TX */
250 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, 16); 700 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, 16);
@@ -256,54 +706,84 @@ static int iwl_set_tkip_dynamic_key_info(struct iwl_priv *priv,
256 return ret; 706 return ret;
257} 707}
258 708
259int iwl_remove_dynamic_key(struct iwl_priv *priv, u8 sta_id) 709int iwl_remove_dynamic_key(struct iwl_priv *priv,
710 struct ieee80211_key_conf *keyconf,
711 u8 sta_id)
260{ 712{
261 unsigned long flags; 713 unsigned long flags;
714 int ret = 0;
715 u16 key_flags;
716 u8 keyidx;
262 717
263 priv->key_mapping_key = 0; 718 priv->key_mapping_key--;
264 719
265 spin_lock_irqsave(&priv->sta_lock, flags); 720 spin_lock_irqsave(&priv->sta_lock, flags);
721 key_flags = le16_to_cpu(priv->stations[sta_id].sta.key.key_flags);
722 keyidx = (key_flags >> STA_KEY_FLG_KEYID_POS) & 0x3;
723
724 IWL_DEBUG_WEP("Remove dynamic key: idx=%d sta=%d\n",
725 keyconf->keyidx, sta_id);
726
727 if (keyconf->keyidx != keyidx) {
728 /* We need to remove a key with index different that the one
729 * in the uCode. This means that the key we need to remove has
730 * been replaced by another one with different index.
731 * Don't do anything and return ok
732 */
733 spin_unlock_irqrestore(&priv->sta_lock, flags);
734 return 0;
735 }
736
266 if (!test_and_clear_bit(priv->stations[sta_id].sta.key.key_offset, 737 if (!test_and_clear_bit(priv->stations[sta_id].sta.key.key_offset,
267 &priv->ucode_key_table)) 738 &priv->ucode_key_table))
268 IWL_ERROR("index %d not used in uCode key table.\n", 739 IWL_ERROR("index %d not used in uCode key table.\n",
269 priv->stations[sta_id].sta.key.key_offset); 740 priv->stations[sta_id].sta.key.key_offset);
270 memset(&priv->stations[sta_id].keyinfo, 0, 741 memset(&priv->stations[sta_id].keyinfo, 0,
271 sizeof(struct iwl4965_hw_key)); 742 sizeof(struct iwl_hw_key));
272 memset(&priv->stations[sta_id].sta.key, 0, 743 memset(&priv->stations[sta_id].sta.key, 0,
273 sizeof(struct iwl4965_keyinfo)); 744 sizeof(struct iwl4965_keyinfo));
274 priv->stations[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC; 745 priv->stations[sta_id].sta.key.key_flags =
746 STA_KEY_FLG_NO_ENC | STA_KEY_FLG_INVALID;
747 priv->stations[sta_id].sta.key.key_offset = WEP_INVALID_OFFSET;
275 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; 748 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
276 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; 749 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
277 spin_unlock_irqrestore(&priv->sta_lock, flags);
278 750
279 IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n"); 751 ret = iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
280 return iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, 0); 752 spin_unlock_irqrestore(&priv->sta_lock, flags);
753 return ret;
281} 754}
755EXPORT_SYMBOL(iwl_remove_dynamic_key);
282 756
283int iwl_set_dynamic_key(struct iwl_priv *priv, 757int iwl_set_dynamic_key(struct iwl_priv *priv,
284 struct ieee80211_key_conf *key, u8 sta_id) 758 struct ieee80211_key_conf *keyconf, u8 sta_id)
285{ 759{
286 int ret; 760 int ret;
287 761
288 priv->key_mapping_key = 1; 762 priv->key_mapping_key++;
763 keyconf->hw_key_idx = HW_KEY_DYNAMIC;
289 764
290 switch (key->alg) { 765 switch (keyconf->alg) {
291 case ALG_CCMP: 766 case ALG_CCMP:
292 ret = iwl_set_ccmp_dynamic_key_info(priv, key, sta_id); 767 ret = iwl_set_ccmp_dynamic_key_info(priv, keyconf, sta_id);
293 break; 768 break;
294 case ALG_TKIP: 769 case ALG_TKIP:
295 ret = iwl_set_tkip_dynamic_key_info(priv, key, sta_id); 770 ret = iwl_set_tkip_dynamic_key_info(priv, keyconf, sta_id);
296 break; 771 break;
297 case ALG_WEP: 772 case ALG_WEP:
298 ret = iwl_set_wep_dynamic_key_info(priv, key, sta_id); 773 ret = iwl_set_wep_dynamic_key_info(priv, keyconf, sta_id);
299 break; 774 break;
300 default: 775 default:
301 IWL_ERROR("Unknown alg: %s alg = %d\n", __func__, key->alg); 776 IWL_ERROR("Unknown alg: %s alg = %d\n", __func__, keyconf->alg);
302 ret = -EINVAL; 777 ret = -EINVAL;
303 } 778 }
304 779
780 IWL_DEBUG_WEP("Set dynamic key: alg= %d len=%d idx=%d sta=%d ret=%d\n",
781 keyconf->alg, keyconf->keylen, keyconf->keyidx,
782 sta_id, ret);
783
305 return ret; 784 return ret;
306} 785}
786EXPORT_SYMBOL(iwl_set_dynamic_key);
307 787
308#ifdef CONFIG_IWLWIFI_DEBUG 788#ifdef CONFIG_IWLWIFI_DEBUG
309static void iwl_dump_lq_cmd(struct iwl_priv *priv, 789static void iwl_dump_lq_cmd(struct iwl_priv *priv,
@@ -337,19 +817,184 @@ int iwl_send_lq_cmd(struct iwl_priv *priv,
337 }; 817 };
338 818
339 if ((lq->sta_id == 0xFF) && 819 if ((lq->sta_id == 0xFF) &&
340 (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)) 820 (priv->iw_mode == NL80211_IFTYPE_ADHOC))
341 return -EINVAL; 821 return -EINVAL;
342 822
343 if (lq->sta_id == 0xFF) 823 if (lq->sta_id == 0xFF)
344 lq->sta_id = IWL_AP_ID; 824 lq->sta_id = IWL_AP_ID;
345 825
346 iwl_dump_lq_cmd(priv,lq); 826 iwl_dump_lq_cmd(priv, lq);
347 827
348 if (iwl_is_associated(priv) && priv->assoc_station_added && 828 if (iwl_is_associated(priv) && priv->assoc_station_added)
349 priv->lq_mngr.lq_ready)
350 return iwl_send_cmd(priv, &cmd); 829 return iwl_send_cmd(priv, &cmd);
351 830
352 return 0; 831 return 0;
353} 832}
354EXPORT_SYMBOL(iwl_send_lq_cmd); 833EXPORT_SYMBOL(iwl_send_lq_cmd);
355 834
835/**
836 * iwl_sta_init_lq - Initialize a station's hardware rate table
837 *
838 * The uCode's station table contains a table of fallback rates
839 * for automatic fallback during transmission.
840 *
841 * NOTE: This sets up a default set of values. These will be replaced later
842 * if the driver's iwl-agn-rs rate scaling algorithm is used, instead of
843 * rc80211_simple.
844 *
845 * NOTE: Run REPLY_ADD_STA command to set up station table entry, before
846 * calling this function (which runs REPLY_TX_LINK_QUALITY_CMD,
847 * which requires station table entry to exist).
848 */
849static void iwl_sta_init_lq(struct iwl_priv *priv, const u8 *addr, int is_ap)
850{
851 int i, r;
852 struct iwl_link_quality_cmd link_cmd = {
853 .reserved1 = 0,
854 };
855 u16 rate_flags;
856
857 /* Set up the rate scaling to start at selected rate, fall back
858 * all the way down to 1M in IEEE order, and then spin on 1M */
859 if (is_ap)
860 r = IWL_RATE_54M_INDEX;
861 else if (priv->band == IEEE80211_BAND_5GHZ)
862 r = IWL_RATE_6M_INDEX;
863 else
864 r = IWL_RATE_1M_INDEX;
865
866 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
867 rate_flags = 0;
868 if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE)
869 rate_flags |= RATE_MCS_CCK_MSK;
870
871 /* Use Tx antenna B only */
872 rate_flags |= RATE_MCS_ANT_B_MSK; /*FIXME:RS*/
873
874 link_cmd.rs_table[i].rate_n_flags =
875 iwl_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags);
876 r = iwl4965_get_prev_ieee_rate(r);
877 }
878
879 link_cmd.general_params.single_stream_ant_msk = 2;
880 link_cmd.general_params.dual_stream_ant_msk = 3;
881 link_cmd.agg_params.agg_dis_start_th = 3;
882 link_cmd.agg_params.agg_time_limit = cpu_to_le16(4000);
883
884 /* Update the rate scaling for control frame Tx to AP */
885 link_cmd.sta_id = is_ap ? IWL_AP_ID : priv->hw_params.bcast_sta_id;
886
887 iwl_send_cmd_pdu_async(priv, REPLY_TX_LINK_QUALITY_CMD,
888 sizeof(link_cmd), &link_cmd, NULL);
889}
890
891/**
892 * iwl_rxon_add_station - add station into station table.
893 *
894 * there is only one AP station with id= IWL_AP_ID
895 * NOTE: mutex must be held before calling this fnction
896 */
897int iwl_rxon_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
898{
899 u8 sta_id;
900
901 /* Add station to device's station table */
902 struct ieee80211_conf *conf = &priv->hw->conf;
903 struct ieee80211_ht_info *cur_ht_config = &conf->ht_conf;
904
905 if ((is_ap) &&
906 (conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) &&
907 (priv->iw_mode == NL80211_IFTYPE_STATION))
908 sta_id = iwl_add_station_flags(priv, addr, is_ap,
909 0, cur_ht_config);
910 else
911 sta_id = iwl_add_station_flags(priv, addr, is_ap,
912 0, NULL);
913
914 /* Set up default rate scaling table in device's station table */
915 iwl_sta_init_lq(priv, addr, is_ap);
916
917 return sta_id;
918}
919EXPORT_SYMBOL(iwl_rxon_add_station);
920
921/**
922 * iwl_get_sta_id - Find station's index within station table
923 *
924 * If new IBSS station, create new entry in station table
925 */
926int iwl_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
927{
928 int sta_id;
929 u16 fc = le16_to_cpu(hdr->frame_control);
930 DECLARE_MAC_BUF(mac);
931
932 /* If this frame is broadcast or management, use broadcast station id */
933 if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
934 is_multicast_ether_addr(hdr->addr1))
935 return priv->hw_params.bcast_sta_id;
936
937 switch (priv->iw_mode) {
938
939 /* If we are a client station in a BSS network, use the special
940 * AP station entry (that's the only station we communicate with) */
941 case NL80211_IFTYPE_STATION:
942 return IWL_AP_ID;
943
944 /* If we are an AP, then find the station, or use BCAST */
945 case NL80211_IFTYPE_AP:
946 sta_id = iwl_find_station(priv, hdr->addr1);
947 if (sta_id != IWL_INVALID_STATION)
948 return sta_id;
949 return priv->hw_params.bcast_sta_id;
950
951 /* If this frame is going out to an IBSS network, find the station,
952 * or create a new station table entry */
953 case NL80211_IFTYPE_ADHOC:
954 sta_id = iwl_find_station(priv, hdr->addr1);
955 if (sta_id != IWL_INVALID_STATION)
956 return sta_id;
957
958 /* Create new station table entry */
959 sta_id = iwl_add_station_flags(priv, hdr->addr1,
960 0, CMD_ASYNC, NULL);
961
962 if (sta_id != IWL_INVALID_STATION)
963 return sta_id;
964
965 IWL_DEBUG_DROP("Station %s not in station map. "
966 "Defaulting to broadcast...\n",
967 print_mac(mac, hdr->addr1));
968 iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
969 return priv->hw_params.bcast_sta_id;
970
971 /* If we are in monitor mode, use BCAST. This is required for
972 * packet injection. */
973 case NL80211_IFTYPE_MONITOR:
974 return priv->hw_params.bcast_sta_id;
975
976 default:
977 IWL_WARNING("Unknown mode of operation: %d\n", priv->iw_mode);
978 return priv->hw_params.bcast_sta_id;
979 }
980}
981EXPORT_SYMBOL(iwl_get_sta_id);
982
983/**
984 * iwl_sta_modify_enable_tid_tx - Enable Tx for this TID in station table
985 */
986void iwl_sta_modify_enable_tid_tx(struct iwl_priv *priv, int sta_id, int tid)
987{
988 unsigned long flags;
989
990 /* Remove "disable" flag, to enable Tx for this TID */
991 spin_lock_irqsave(&priv->sta_lock, flags);
992 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_TID_DISABLE_TX;
993 priv->stations[sta_id].sta.tid_disable_tx &= cpu_to_le16(~(1 << tid));
994 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
995 spin_unlock_irqrestore(&priv->sta_lock, flags);
996
997 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
998}
999EXPORT_SYMBOL(iwl_sta_modify_enable_tid_tx);
1000
diff --git a/drivers/net/wireless/iwlwifi/iwl-sta.h b/drivers/net/wireless/iwlwifi/iwl-sta.h
index 44f272ecc827..221b93e670a6 100644
--- a/drivers/net/wireless/iwlwifi/iwl-sta.h
+++ b/drivers/net/wireless/iwlwifi/iwl-sta.h
@@ -29,21 +29,27 @@
29#ifndef __iwl_sta_h__ 29#ifndef __iwl_sta_h__
30#define __iwl_sta_h__ 30#define __iwl_sta_h__
31 31
32#include <net/mac80211.h> 32#define HW_KEY_DYNAMIC 0
33#define HW_KEY_DEFAULT 1
33 34
34#include "iwl-eeprom.h" 35/**
35#include "iwl-core.h" 36 * iwl_find_station - Find station id for a given BSSID
36#include "iwl-4965.h" 37 * @bssid: MAC address of station ID to find
37#include "iwl-io.h" 38 */
38#include "iwl-helpers.h" 39u8 iwl_find_station(struct iwl_priv *priv, const u8 *bssid);
39 40
40int iwl_get_free_ucode_key_index(struct iwl_priv *priv);
41int iwl_send_static_wepkey_cmd(struct iwl_priv *priv, u8 send_if_empty); 41int iwl_send_static_wepkey_cmd(struct iwl_priv *priv, u8 send_if_empty);
42int iwl_remove_default_wep_key(struct iwl_priv *priv, 42int iwl_remove_default_wep_key(struct iwl_priv *priv,
43 struct ieee80211_key_conf *key); 43 struct ieee80211_key_conf *key);
44int iwl_set_default_wep_key(struct iwl_priv *priv, 44int iwl_set_default_wep_key(struct iwl_priv *priv,
45 struct ieee80211_key_conf *key); 45 struct ieee80211_key_conf *key);
46int iwl_remove_dynamic_key(struct iwl_priv *priv, u8 sta_id);
47int iwl_set_dynamic_key(struct iwl_priv *priv, 46int iwl_set_dynamic_key(struct iwl_priv *priv,
48 struct ieee80211_key_conf *key, u8 sta_id); 47 struct ieee80211_key_conf *key, u8 sta_id);
48int iwl_remove_dynamic_key(struct iwl_priv *priv,
49 struct ieee80211_key_conf *key, u8 sta_id);
50int iwl_rxon_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap);
51int iwl_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap);
52int iwl_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr);
53void iwl_sta_modify_enable_tid_tx(struct iwl_priv *priv, int sta_id, int tid);
54int iwl_get_ra_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr);
49#endif /* __iwl_sta_h__ */ 55#endif /* __iwl_sta_h__ */
diff --git a/drivers/net/wireless/iwlwifi/iwl-tx.c b/drivers/net/wireless/iwlwifi/iwl-tx.c
new file mode 100644
index 000000000000..907a53ebc6e4
--- /dev/null
+++ b/drivers/net/wireless/iwlwifi/iwl-tx.c
@@ -0,0 +1,1561 @@
1/******************************************************************************
2 *
3 * Copyright(c) 2003 - 2008 Intel Corporation. All rights reserved.
4 *
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
20 *
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
23 *
24 * Contact Information:
25 * James P. Ketrenos <ipw2100-admin@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *
28 *****************************************************************************/
29
30#include <linux/etherdevice.h>
31#include <net/mac80211.h>
32#include "iwl-eeprom.h"
33#include "iwl-dev.h"
34#include "iwl-core.h"
35#include "iwl-sta.h"
36#include "iwl-io.h"
37#include "iwl-helpers.h"
38
39static const u16 default_tid_to_tx_fifo[] = {
40 IWL_TX_FIFO_AC1,
41 IWL_TX_FIFO_AC0,
42 IWL_TX_FIFO_AC0,
43 IWL_TX_FIFO_AC1,
44 IWL_TX_FIFO_AC2,
45 IWL_TX_FIFO_AC2,
46 IWL_TX_FIFO_AC3,
47 IWL_TX_FIFO_AC3,
48 IWL_TX_FIFO_NONE,
49 IWL_TX_FIFO_NONE,
50 IWL_TX_FIFO_NONE,
51 IWL_TX_FIFO_NONE,
52 IWL_TX_FIFO_NONE,
53 IWL_TX_FIFO_NONE,
54 IWL_TX_FIFO_NONE,
55 IWL_TX_FIFO_NONE,
56 IWL_TX_FIFO_AC3
57};
58
59
60/**
61 * iwl_hw_txq_free_tfd - Free all chunks referenced by TFD [txq->q.read_ptr]
62 *
63 * Does NOT advance any TFD circular buffer read/write indexes
64 * Does NOT free the TFD itself (which is within circular buffer)
65 */
66static int iwl_hw_txq_free_tfd(struct iwl_priv *priv, struct iwl_tx_queue *txq)
67{
68 struct iwl_tfd_frame *bd_tmp = (struct iwl_tfd_frame *)&txq->bd[0];
69 struct iwl_tfd_frame *bd = &bd_tmp[txq->q.read_ptr];
70 struct pci_dev *dev = priv->pci_dev;
71 int i;
72 int counter = 0;
73 int index, is_odd;
74
75 /* Host command buffers stay mapped in memory, nothing to clean */
76 if (txq->q.id == IWL_CMD_QUEUE_NUM)
77 return 0;
78
79 /* Sanity check on number of chunks */
80 counter = IWL_GET_BITS(*bd, num_tbs);
81 if (counter > MAX_NUM_OF_TBS) {
82 IWL_ERROR("Too many chunks: %i\n", counter);
83 /* @todo issue fatal error, it is quite serious situation */
84 return 0;
85 }
86
87 /* Unmap chunks, if any.
88 * TFD info for odd chunks is different format than for even chunks. */
89 for (i = 0; i < counter; i++) {
90 index = i / 2;
91 is_odd = i & 0x1;
92
93 if (is_odd)
94 pci_unmap_single(
95 dev,
96 IWL_GET_BITS(bd->pa[index], tb2_addr_lo16) |
97 (IWL_GET_BITS(bd->pa[index],
98 tb2_addr_hi20) << 16),
99 IWL_GET_BITS(bd->pa[index], tb2_len),
100 PCI_DMA_TODEVICE);
101
102 else if (i > 0)
103 pci_unmap_single(dev,
104 le32_to_cpu(bd->pa[index].tb1_addr),
105 IWL_GET_BITS(bd->pa[index], tb1_len),
106 PCI_DMA_TODEVICE);
107
108 /* Free SKB, if any, for this chunk */
109 if (txq->txb[txq->q.read_ptr].skb[i]) {
110 struct sk_buff *skb = txq->txb[txq->q.read_ptr].skb[i];
111
112 dev_kfree_skb(skb);
113 txq->txb[txq->q.read_ptr].skb[i] = NULL;
114 }
115 }
116 return 0;
117}
118
119static int iwl_hw_txq_attach_buf_to_tfd(struct iwl_priv *priv, void *ptr,
120 dma_addr_t addr, u16 len)
121{
122 int index, is_odd;
123 struct iwl_tfd_frame *tfd = ptr;
124 u32 num_tbs = IWL_GET_BITS(*tfd, num_tbs);
125
126 /* Each TFD can point to a maximum 20 Tx buffers */
127 if (num_tbs >= MAX_NUM_OF_TBS) {
128 IWL_ERROR("Error can not send more than %d chunks\n",
129 MAX_NUM_OF_TBS);
130 return -EINVAL;
131 }
132
133 index = num_tbs / 2;
134 is_odd = num_tbs & 0x1;
135
136 if (!is_odd) {
137 tfd->pa[index].tb1_addr = cpu_to_le32(addr);
138 IWL_SET_BITS(tfd->pa[index], tb1_addr_hi,
139 iwl_get_dma_hi_address(addr));
140 IWL_SET_BITS(tfd->pa[index], tb1_len, len);
141 } else {
142 IWL_SET_BITS(tfd->pa[index], tb2_addr_lo16,
143 (u32) (addr & 0xffff));
144 IWL_SET_BITS(tfd->pa[index], tb2_addr_hi20, addr >> 16);
145 IWL_SET_BITS(tfd->pa[index], tb2_len, len);
146 }
147
148 IWL_SET_BITS(*tfd, num_tbs, num_tbs + 1);
149
150 return 0;
151}
152
153/**
154 * iwl_txq_update_write_ptr - Send new write index to hardware
155 */
156int iwl_txq_update_write_ptr(struct iwl_priv *priv, struct iwl_tx_queue *txq)
157{
158 u32 reg = 0;
159 int ret = 0;
160 int txq_id = txq->q.id;
161
162 if (txq->need_update == 0)
163 return ret;
164
165 /* if we're trying to save power */
166 if (test_bit(STATUS_POWER_PMI, &priv->status)) {
167 /* wake up nic if it's powered down ...
168 * uCode will wake up, and interrupt us again, so next
169 * time we'll skip this part. */
170 reg = iwl_read32(priv, CSR_UCODE_DRV_GP1);
171
172 if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
173 IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg);
174 iwl_set_bit(priv, CSR_GP_CNTRL,
175 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
176 return ret;
177 }
178
179 /* restore this queue's parameters in nic hardware. */
180 ret = iwl_grab_nic_access(priv);
181 if (ret)
182 return ret;
183 iwl_write_direct32(priv, HBUS_TARG_WRPTR,
184 txq->q.write_ptr | (txq_id << 8));
185 iwl_release_nic_access(priv);
186
187 /* else not in power-save mode, uCode will never sleep when we're
188 * trying to tx (during RFKILL, we're not trying to tx). */
189 } else
190 iwl_write32(priv, HBUS_TARG_WRPTR,
191 txq->q.write_ptr | (txq_id << 8));
192
193 txq->need_update = 0;
194
195 return ret;
196}
197EXPORT_SYMBOL(iwl_txq_update_write_ptr);
198
199
200/**
201 * iwl_tx_queue_free - Deallocate DMA queue.
202 * @txq: Transmit queue to deallocate.
203 *
204 * Empty queue by removing and destroying all BD's.
205 * Free all buffers.
206 * 0-fill, but do not free "txq" descriptor structure.
207 */
208static void iwl_tx_queue_free(struct iwl_priv *priv, int txq_id)
209{
210 struct iwl_tx_queue *txq = &priv->txq[txq_id];
211 struct iwl_queue *q = &txq->q;
212 struct pci_dev *dev = priv->pci_dev;
213 int i, slots_num, len;
214
215 if (q->n_bd == 0)
216 return;
217
218 /* first, empty all BD's */
219 for (; q->write_ptr != q->read_ptr;
220 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd))
221 iwl_hw_txq_free_tfd(priv, txq);
222
223 len = sizeof(struct iwl_cmd) * q->n_window;
224 if (q->id == IWL_CMD_QUEUE_NUM)
225 len += IWL_MAX_SCAN_SIZE;
226
227 /* De-alloc array of command/tx buffers */
228 slots_num = (txq_id == IWL_CMD_QUEUE_NUM) ?
229 TFD_CMD_SLOTS : TFD_TX_CMD_SLOTS;
230 for (i = 0; i < slots_num; i++)
231 kfree(txq->cmd[i]);
232 if (txq_id == IWL_CMD_QUEUE_NUM)
233 kfree(txq->cmd[slots_num]);
234
235 /* De-alloc circular buffer of TFDs */
236 if (txq->q.n_bd)
237 pci_free_consistent(dev, sizeof(struct iwl_tfd_frame) *
238 txq->q.n_bd, txq->bd, txq->q.dma_addr);
239
240 /* De-alloc array of per-TFD driver data */
241 kfree(txq->txb);
242 txq->txb = NULL;
243
244 /* 0-fill queue descriptor structure */
245 memset(txq, 0, sizeof(*txq));
246}
247
248/*************** DMA-QUEUE-GENERAL-FUNCTIONS *****
249 * DMA services
250 *
251 * Theory of operation
252 *
253 * A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer
254 * of buffer descriptors, each of which points to one or more data buffers for
255 * the device to read from or fill. Driver and device exchange status of each
256 * queue via "read" and "write" pointers. Driver keeps minimum of 2 empty
257 * entries in each circular buffer, to protect against confusing empty and full
258 * queue states.
259 *
260 * The device reads or writes the data in the queues via the device's several
261 * DMA/FIFO channels. Each queue is mapped to a single DMA channel.
262 *
263 * For Tx queue, there are low mark and high mark limits. If, after queuing
264 * the packet for Tx, free space become < low mark, Tx queue stopped. When
265 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
266 * Tx queue resumed.
267 *
268 * See more detailed info in iwl-4965-hw.h.
269 ***************************************************/
270
271int iwl_queue_space(const struct iwl_queue *q)
272{
273 int s = q->read_ptr - q->write_ptr;
274
275 if (q->read_ptr > q->write_ptr)
276 s -= q->n_bd;
277
278 if (s <= 0)
279 s += q->n_window;
280 /* keep some reserve to not confuse empty and full situations */
281 s -= 2;
282 if (s < 0)
283 s = 0;
284 return s;
285}
286EXPORT_SYMBOL(iwl_queue_space);
287
288
289/**
290 * iwl_queue_init - Initialize queue's high/low-water and read/write indexes
291 */
292static int iwl_queue_init(struct iwl_priv *priv, struct iwl_queue *q,
293 int count, int slots_num, u32 id)
294{
295 q->n_bd = count;
296 q->n_window = slots_num;
297 q->id = id;
298
299 /* count must be power-of-two size, otherwise iwl_queue_inc_wrap
300 * and iwl_queue_dec_wrap are broken. */
301 BUG_ON(!is_power_of_2(count));
302
303 /* slots_num must be power-of-two size, otherwise
304 * get_cmd_index is broken. */
305 BUG_ON(!is_power_of_2(slots_num));
306
307 q->low_mark = q->n_window / 4;
308 if (q->low_mark < 4)
309 q->low_mark = 4;
310
311 q->high_mark = q->n_window / 8;
312 if (q->high_mark < 2)
313 q->high_mark = 2;
314
315 q->write_ptr = q->read_ptr = 0;
316
317 return 0;
318}
319
320/**
321 * iwl_tx_queue_alloc - Alloc driver data and TFD CB for one Tx/cmd queue
322 */
323static int iwl_tx_queue_alloc(struct iwl_priv *priv,
324 struct iwl_tx_queue *txq, u32 id)
325{
326 struct pci_dev *dev = priv->pci_dev;
327
328 /* Driver private data, only for Tx (not command) queues,
329 * not shared with device. */
330 if (id != IWL_CMD_QUEUE_NUM) {
331 txq->txb = kmalloc(sizeof(txq->txb[0]) *
332 TFD_QUEUE_SIZE_MAX, GFP_KERNEL);
333 if (!txq->txb) {
334 IWL_ERROR("kmalloc for auxiliary BD "
335 "structures failed\n");
336 goto error;
337 }
338 } else
339 txq->txb = NULL;
340
341 /* Circular buffer of transmit frame descriptors (TFDs),
342 * shared with device */
343 txq->bd = pci_alloc_consistent(dev,
344 sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX,
345 &txq->q.dma_addr);
346
347 if (!txq->bd) {
348 IWL_ERROR("pci_alloc_consistent(%zd) failed\n",
349 sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX);
350 goto error;
351 }
352 txq->q.id = id;
353
354 return 0;
355
356 error:
357 kfree(txq->txb);
358 txq->txb = NULL;
359
360 return -ENOMEM;
361}
362
363/*
364 * Tell nic where to find circular buffer of Tx Frame Descriptors for
365 * given Tx queue, and enable the DMA channel used for that queue.
366 *
367 * 4965 supports up to 16 Tx queues in DRAM, mapped to up to 8 Tx DMA
368 * channels supported in hardware.
369 */
370static int iwl_hw_tx_queue_init(struct iwl_priv *priv,
371 struct iwl_tx_queue *txq)
372{
373 int rc;
374 unsigned long flags;
375 int txq_id = txq->q.id;
376
377 spin_lock_irqsave(&priv->lock, flags);
378 rc = iwl_grab_nic_access(priv);
379 if (rc) {
380 spin_unlock_irqrestore(&priv->lock, flags);
381 return rc;
382 }
383
384 /* Circular buffer (TFD queue in DRAM) physical base address */
385 iwl_write_direct32(priv, FH_MEM_CBBC_QUEUE(txq_id),
386 txq->q.dma_addr >> 8);
387
388 /* Enable DMA channel, using same id as for TFD queue */
389 iwl_write_direct32(
390 priv, FH_TCSR_CHNL_TX_CONFIG_REG(txq_id),
391 FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
392 FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE_VAL);
393 iwl_release_nic_access(priv);
394 spin_unlock_irqrestore(&priv->lock, flags);
395
396 return 0;
397}
398
399/**
400 * iwl_tx_queue_init - Allocate and initialize one tx/cmd queue
401 */
402static int iwl_tx_queue_init(struct iwl_priv *priv, struct iwl_tx_queue *txq,
403 int slots_num, u32 txq_id)
404{
405 int i, len;
406 int ret;
407
408 /*
409 * Alloc buffer array for commands (Tx or other types of commands).
410 * For the command queue (#4), allocate command space + one big
411 * command for scan, since scan command is very huge; the system will
412 * not have two scans at the same time, so only one is needed.
413 * For normal Tx queues (all other queues), no super-size command
414 * space is needed.
415 */
416 len = sizeof(struct iwl_cmd);
417 for (i = 0; i <= slots_num; i++) {
418 if (i == slots_num) {
419 if (txq_id == IWL_CMD_QUEUE_NUM)
420 len += IWL_MAX_SCAN_SIZE;
421 else
422 continue;
423 }
424
425 txq->cmd[i] = kmalloc(len, GFP_KERNEL);
426 if (!txq->cmd[i])
427 goto err;
428 }
429
430 /* Alloc driver data array and TFD circular buffer */
431 ret = iwl_tx_queue_alloc(priv, txq, txq_id);
432 if (ret)
433 goto err;
434
435 txq->need_update = 0;
436
437 /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise
438 * iwl_queue_inc_wrap and iwl_queue_dec_wrap are broken. */
439 BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX & (TFD_QUEUE_SIZE_MAX - 1));
440
441 /* Initialize queue's high/low-water marks, and head/tail indexes */
442 iwl_queue_init(priv, &txq->q, TFD_QUEUE_SIZE_MAX, slots_num, txq_id);
443
444 /* Tell device where to find queue */
445 iwl_hw_tx_queue_init(priv, txq);
446
447 return 0;
448err:
449 for (i = 0; i < slots_num; i++) {
450 kfree(txq->cmd[i]);
451 txq->cmd[i] = NULL;
452 }
453
454 if (txq_id == IWL_CMD_QUEUE_NUM) {
455 kfree(txq->cmd[slots_num]);
456 txq->cmd[slots_num] = NULL;
457 }
458 return -ENOMEM;
459}
460/**
461 * iwl_hw_txq_ctx_free - Free TXQ Context
462 *
463 * Destroy all TX DMA queues and structures
464 */
465void iwl_hw_txq_ctx_free(struct iwl_priv *priv)
466{
467 int txq_id;
468
469 /* Tx queues */
470 for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++)
471 iwl_tx_queue_free(priv, txq_id);
472
473 /* Keep-warm buffer */
474 iwl_kw_free(priv);
475}
476EXPORT_SYMBOL(iwl_hw_txq_ctx_free);
477
478/**
479 * iwl_txq_ctx_reset - Reset TX queue context
480 * Destroys all DMA structures and initialise them again
481 *
482 * @param priv
483 * @return error code
484 */
485int iwl_txq_ctx_reset(struct iwl_priv *priv)
486{
487 int ret = 0;
488 int txq_id, slots_num;
489 unsigned long flags;
490
491 iwl_kw_free(priv);
492
493 /* Free all tx/cmd queues and keep-warm buffer */
494 iwl_hw_txq_ctx_free(priv);
495
496 /* Alloc keep-warm buffer */
497 ret = iwl_kw_alloc(priv);
498 if (ret) {
499 IWL_ERROR("Keep Warm allocation failed\n");
500 goto error_kw;
501 }
502 spin_lock_irqsave(&priv->lock, flags);
503 ret = iwl_grab_nic_access(priv);
504 if (unlikely(ret)) {
505 spin_unlock_irqrestore(&priv->lock, flags);
506 goto error_reset;
507 }
508
509 /* Turn off all Tx DMA fifos */
510 priv->cfg->ops->lib->txq_set_sched(priv, 0);
511
512 iwl_release_nic_access(priv);
513 spin_unlock_irqrestore(&priv->lock, flags);
514
515
516 /* Tell nic where to find the keep-warm buffer */
517 ret = iwl_kw_init(priv);
518 if (ret) {
519 IWL_ERROR("kw_init failed\n");
520 goto error_reset;
521 }
522
523 /* Alloc and init all Tx queues, including the command queue (#4) */
524 for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++) {
525 slots_num = (txq_id == IWL_CMD_QUEUE_NUM) ?
526 TFD_CMD_SLOTS : TFD_TX_CMD_SLOTS;
527 ret = iwl_tx_queue_init(priv, &priv->txq[txq_id], slots_num,
528 txq_id);
529 if (ret) {
530 IWL_ERROR("Tx %d queue init failed\n", txq_id);
531 goto error;
532 }
533 }
534
535 return ret;
536
537 error:
538 iwl_hw_txq_ctx_free(priv);
539 error_reset:
540 iwl_kw_free(priv);
541 error_kw:
542 return ret;
543}
544
545/**
546 * iwl_txq_ctx_stop - Stop all Tx DMA channels, free Tx queue memory
547 */
548void iwl_txq_ctx_stop(struct iwl_priv *priv)
549{
550
551 int txq_id;
552 unsigned long flags;
553
554
555 /* Turn off all Tx DMA fifos */
556 spin_lock_irqsave(&priv->lock, flags);
557 if (iwl_grab_nic_access(priv)) {
558 spin_unlock_irqrestore(&priv->lock, flags);
559 return;
560 }
561
562 priv->cfg->ops->lib->txq_set_sched(priv, 0);
563
564 /* Stop each Tx DMA channel, and wait for it to be idle */
565 for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++) {
566 iwl_write_direct32(priv,
567 FH_TCSR_CHNL_TX_CONFIG_REG(txq_id), 0x0);
568 iwl_poll_direct_bit(priv, FH_TSSR_TX_STATUS_REG,
569 FH_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE
570 (txq_id), 200);
571 }
572 iwl_release_nic_access(priv);
573 spin_unlock_irqrestore(&priv->lock, flags);
574
575 /* Deallocate memory for all Tx queues */
576 iwl_hw_txq_ctx_free(priv);
577}
578EXPORT_SYMBOL(iwl_txq_ctx_stop);
579
580/*
581 * handle build REPLY_TX command notification.
582 */
583static void iwl_tx_cmd_build_basic(struct iwl_priv *priv,
584 struct iwl_tx_cmd *tx_cmd,
585 struct ieee80211_tx_info *info,
586 struct ieee80211_hdr *hdr,
587 int is_unicast, u8 std_id)
588{
589 __le16 fc = hdr->frame_control;
590 __le32 tx_flags = tx_cmd->tx_flags;
591
592 tx_cmd->stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
593 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
594 tx_flags |= TX_CMD_FLG_ACK_MSK;
595 if (ieee80211_is_mgmt(fc))
596 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
597 if (ieee80211_is_probe_resp(fc) &&
598 !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
599 tx_flags |= TX_CMD_FLG_TSF_MSK;
600 } else {
601 tx_flags &= (~TX_CMD_FLG_ACK_MSK);
602 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
603 }
604
605 if (ieee80211_is_back_req(fc))
606 tx_flags |= TX_CMD_FLG_ACK_MSK | TX_CMD_FLG_IMM_BA_RSP_MASK;
607
608
609 tx_cmd->sta_id = std_id;
610 if (ieee80211_has_morefrags(fc))
611 tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
612
613 if (ieee80211_is_data_qos(fc)) {
614 u8 *qc = ieee80211_get_qos_ctl(hdr);
615 tx_cmd->tid_tspec = qc[0] & 0xf;
616 tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
617 } else {
618 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
619 }
620
621 priv->cfg->ops->utils->rts_tx_cmd_flag(info, &tx_flags);
622
623 if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK))
624 tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
625
626 tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
627 if (ieee80211_is_mgmt(fc)) {
628 if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc))
629 tx_cmd->timeout.pm_frame_timeout = cpu_to_le16(3);
630 else
631 tx_cmd->timeout.pm_frame_timeout = cpu_to_le16(2);
632 } else {
633 tx_cmd->timeout.pm_frame_timeout = 0;
634 }
635
636 tx_cmd->driver_txop = 0;
637 tx_cmd->tx_flags = tx_flags;
638 tx_cmd->next_frame_len = 0;
639}
640
641#define RTS_HCCA_RETRY_LIMIT 3
642#define RTS_DFAULT_RETRY_LIMIT 60
643
644static void iwl_tx_cmd_build_rate(struct iwl_priv *priv,
645 struct iwl_tx_cmd *tx_cmd,
646 struct ieee80211_tx_info *info,
647 __le16 fc, int sta_id,
648 int is_hcca)
649{
650 u8 rts_retry_limit = 0;
651 u8 data_retry_limit = 0;
652 u8 rate_plcp;
653 u16 rate_flags = 0;
654 int rate_idx;
655
656 rate_idx = min(ieee80211_get_tx_rate(priv->hw, info)->hw_value & 0xffff,
657 IWL_RATE_COUNT - 1);
658
659 rate_plcp = iwl_rates[rate_idx].plcp;
660
661 rts_retry_limit = (is_hcca) ?
662 RTS_HCCA_RETRY_LIMIT : RTS_DFAULT_RETRY_LIMIT;
663
664 if ((rate_idx >= IWL_FIRST_CCK_RATE) && (rate_idx <= IWL_LAST_CCK_RATE))
665 rate_flags |= RATE_MCS_CCK_MSK;
666
667
668 if (ieee80211_is_probe_resp(fc)) {
669 data_retry_limit = 3;
670 if (data_retry_limit < rts_retry_limit)
671 rts_retry_limit = data_retry_limit;
672 } else
673 data_retry_limit = IWL_DEFAULT_TX_RETRY;
674
675 if (priv->data_retry_limit != -1)
676 data_retry_limit = priv->data_retry_limit;
677
678
679 if (ieee80211_is_data(fc)) {
680 tx_cmd->initial_rate_index = 0;
681 tx_cmd->tx_flags |= TX_CMD_FLG_STA_RATE_MSK;
682 } else {
683 switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
684 case cpu_to_le16(IEEE80211_STYPE_AUTH):
685 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
686 case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ):
687 case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ):
688 if (tx_cmd->tx_flags & TX_CMD_FLG_RTS_MSK) {
689 tx_cmd->tx_flags &= ~TX_CMD_FLG_RTS_MSK;
690 tx_cmd->tx_flags |= TX_CMD_FLG_CTS_MSK;
691 }
692 break;
693 default:
694 break;
695 }
696
697 /* Alternate between antenna A and B for successive frames */
698 if (priv->use_ant_b_for_management_frame) {
699 priv->use_ant_b_for_management_frame = 0;
700 rate_flags |= RATE_MCS_ANT_B_MSK;
701 } else {
702 priv->use_ant_b_for_management_frame = 1;
703 rate_flags |= RATE_MCS_ANT_A_MSK;
704 }
705 }
706
707 tx_cmd->rts_retry_limit = rts_retry_limit;
708 tx_cmd->data_retry_limit = data_retry_limit;
709 tx_cmd->rate_n_flags = iwl_hw_set_rate_n_flags(rate_plcp, rate_flags);
710}
711
712static void iwl_tx_cmd_build_hwcrypto(struct iwl_priv *priv,
713 struct ieee80211_tx_info *info,
714 struct iwl_tx_cmd *tx_cmd,
715 struct sk_buff *skb_frag,
716 int sta_id)
717{
718 struct ieee80211_key_conf *keyconf = info->control.hw_key;
719
720 switch (keyconf->alg) {
721 case ALG_CCMP:
722 tx_cmd->sec_ctl = TX_CMD_SEC_CCM;
723 memcpy(tx_cmd->key, keyconf->key, keyconf->keylen);
724 if (info->flags & IEEE80211_TX_CTL_AMPDU)
725 tx_cmd->tx_flags |= TX_CMD_FLG_AGG_CCMP_MSK;
726 IWL_DEBUG_TX("tx_cmd with aes hwcrypto\n");
727 break;
728
729 case ALG_TKIP:
730 tx_cmd->sec_ctl = TX_CMD_SEC_TKIP;
731 ieee80211_get_tkip_key(keyconf, skb_frag,
732 IEEE80211_TKIP_P2_KEY, tx_cmd->key);
733 IWL_DEBUG_TX("tx_cmd with tkip hwcrypto\n");
734 break;
735
736 case ALG_WEP:
737 tx_cmd->sec_ctl |= (TX_CMD_SEC_WEP |
738 (keyconf->keyidx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT);
739
740 if (keyconf->keylen == WEP_KEY_LEN_128)
741 tx_cmd->sec_ctl |= TX_CMD_SEC_KEY128;
742
743 memcpy(&tx_cmd->key[3], keyconf->key, keyconf->keylen);
744
745 IWL_DEBUG_TX("Configuring packet for WEP encryption "
746 "with key %d\n", keyconf->keyidx);
747 break;
748
749 default:
750 printk(KERN_ERR "Unknown encode alg %d\n", keyconf->alg);
751 break;
752 }
753}
754
755static void iwl_update_tx_stats(struct iwl_priv *priv, u16 fc, u16 len)
756{
757 /* 0 - mgmt, 1 - cnt, 2 - data */
758 int idx = (fc & IEEE80211_FCTL_FTYPE) >> 2;
759 priv->tx_stats[idx].cnt++;
760 priv->tx_stats[idx].bytes += len;
761}
762
763/*
764 * start REPLY_TX command process
765 */
766int iwl_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
767{
768 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
769 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
770 struct iwl_tfd_frame *tfd;
771 struct iwl_tx_queue *txq;
772 struct iwl_queue *q;
773 struct iwl_cmd *out_cmd;
774 struct iwl_tx_cmd *tx_cmd;
775 int swq_id, txq_id;
776 dma_addr_t phys_addr;
777 dma_addr_t txcmd_phys;
778 dma_addr_t scratch_phys;
779 u16 len, idx, len_org;
780 u16 seq_number = 0;
781 __le16 fc;
782 u8 hdr_len, unicast;
783 u8 sta_id;
784 u8 wait_write_ptr = 0;
785 u8 tid = 0;
786 u8 *qc = NULL;
787 unsigned long flags;
788 int ret;
789
790 spin_lock_irqsave(&priv->lock, flags);
791 if (iwl_is_rfkill(priv)) {
792 IWL_DEBUG_DROP("Dropping - RF KILL\n");
793 goto drop_unlock;
794 }
795
796 if ((ieee80211_get_tx_rate(priv->hw, info)->hw_value & 0xFF) ==
797 IWL_INVALID_RATE) {
798 IWL_ERROR("ERROR: No TX rate available.\n");
799 goto drop_unlock;
800 }
801
802 unicast = !is_multicast_ether_addr(hdr->addr1);
803
804 fc = hdr->frame_control;
805
806#ifdef CONFIG_IWLWIFI_DEBUG
807 if (ieee80211_is_auth(fc))
808 IWL_DEBUG_TX("Sending AUTH frame\n");
809 else if (ieee80211_is_assoc_req(fc))
810 IWL_DEBUG_TX("Sending ASSOC frame\n");
811 else if (ieee80211_is_reassoc_req(fc))
812 IWL_DEBUG_TX("Sending REASSOC frame\n");
813#endif
814
815 /* drop all data frame if we are not associated */
816 if (ieee80211_is_data(fc) &&
817 (priv->iw_mode != NL80211_IFTYPE_MONITOR ||
818 !(info->flags & IEEE80211_TX_CTL_INJECTED)) && /* packet injection */
819 (!iwl_is_associated(priv) ||
820 ((priv->iw_mode == NL80211_IFTYPE_STATION) && !priv->assoc_id) ||
821 !priv->assoc_station_added)) {
822 IWL_DEBUG_DROP("Dropping - !iwl_is_associated\n");
823 goto drop_unlock;
824 }
825
826 spin_unlock_irqrestore(&priv->lock, flags);
827
828 hdr_len = ieee80211_hdrlen(fc);
829
830 /* Find (or create) index into station table for destination station */
831 sta_id = iwl_get_sta_id(priv, hdr);
832 if (sta_id == IWL_INVALID_STATION) {
833 DECLARE_MAC_BUF(mac);
834
835 IWL_DEBUG_DROP("Dropping - INVALID STATION: %s\n",
836 print_mac(mac, hdr->addr1));
837 goto drop;
838 }
839
840 IWL_DEBUG_TX("station Id %d\n", sta_id);
841
842 swq_id = skb_get_queue_mapping(skb);
843 txq_id = swq_id;
844 if (ieee80211_is_data_qos(fc)) {
845 qc = ieee80211_get_qos_ctl(hdr);
846 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
847 seq_number = priv->stations[sta_id].tid[tid].seq_number;
848 seq_number &= IEEE80211_SCTL_SEQ;
849 hdr->seq_ctrl = hdr->seq_ctrl &
850 __constant_cpu_to_le16(IEEE80211_SCTL_FRAG);
851 hdr->seq_ctrl |= cpu_to_le16(seq_number);
852 seq_number += 0x10;
853 /* aggregation is on for this <sta,tid> */
854 if (info->flags & IEEE80211_TX_CTL_AMPDU)
855 txq_id = priv->stations[sta_id].tid[tid].agg.txq_id;
856 priv->stations[sta_id].tid[tid].tfds_in_queue++;
857 }
858
859 /* Descriptor for chosen Tx queue */
860 txq = &priv->txq[txq_id];
861 q = &txq->q;
862
863 spin_lock_irqsave(&priv->lock, flags);
864
865 /* Set up first empty TFD within this queue's circular TFD buffer */
866 tfd = &txq->bd[q->write_ptr];
867 memset(tfd, 0, sizeof(*tfd));
868 idx = get_cmd_index(q, q->write_ptr, 0);
869
870 /* Set up driver data for this TFD */
871 memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl_tx_info));
872 txq->txb[q->write_ptr].skb[0] = skb;
873
874 /* Set up first empty entry in queue's array of Tx/cmd buffers */
875 out_cmd = txq->cmd[idx];
876 tx_cmd = &out_cmd->cmd.tx;
877 memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
878 memset(tx_cmd, 0, sizeof(struct iwl_tx_cmd));
879
880 /*
881 * Set up the Tx-command (not MAC!) header.
882 * Store the chosen Tx queue and TFD index within the sequence field;
883 * after Tx, uCode's Tx response will return this value so driver can
884 * locate the frame within the tx queue and do post-tx processing.
885 */
886 out_cmd->hdr.cmd = REPLY_TX;
887 out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
888 INDEX_TO_SEQ(q->write_ptr)));
889
890 /* Copy MAC header from skb into command buffer */
891 memcpy(tx_cmd->hdr, hdr, hdr_len);
892
893 /*
894 * Use the first empty entry in this queue's command buffer array
895 * to contain the Tx command and MAC header concatenated together
896 * (payload data will be in another buffer).
897 * Size of this varies, due to varying MAC header length.
898 * If end is not dword aligned, we'll have 2 extra bytes at the end
899 * of the MAC header (device reads on dword boundaries).
900 * We'll tell device about this padding later.
901 */
902 len = sizeof(struct iwl_tx_cmd) +
903 sizeof(struct iwl_cmd_header) + hdr_len;
904
905 len_org = len;
906 len = (len + 3) & ~3;
907
908 if (len_org != len)
909 len_org = 1;
910 else
911 len_org = 0;
912
913 /* Physical address of this Tx command's header (not MAC header!),
914 * within command buffer array. */
915 txcmd_phys = pci_map_single(priv->pci_dev, out_cmd,
916 sizeof(struct iwl_cmd), PCI_DMA_TODEVICE);
917 txcmd_phys += offsetof(struct iwl_cmd, hdr);
918
919 /* Add buffer containing Tx command and MAC(!) header to TFD's
920 * first entry */
921 iwl_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len);
922
923 if (info->control.hw_key)
924 iwl_tx_cmd_build_hwcrypto(priv, info, tx_cmd, skb, sta_id);
925
926 /* Set up TFD's 2nd entry to point directly to remainder of skb,
927 * if any (802.11 null frames have no payload). */
928 len = skb->len - hdr_len;
929 if (len) {
930 phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
931 len, PCI_DMA_TODEVICE);
932 iwl_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, len);
933 }
934
935 /* Tell NIC about any 2-byte padding after MAC header */
936 if (len_org)
937 tx_cmd->tx_flags |= TX_CMD_FLG_MH_PAD_MSK;
938
939 /* Total # bytes to be transmitted */
940 len = (u16)skb->len;
941 tx_cmd->len = cpu_to_le16(len);
942 /* TODO need this for burst mode later on */
943 iwl_tx_cmd_build_basic(priv, tx_cmd, info, hdr, unicast, sta_id);
944
945 /* set is_hcca to 0; it probably will never be implemented */
946 iwl_tx_cmd_build_rate(priv, tx_cmd, info, fc, sta_id, 0);
947
948 iwl_update_tx_stats(priv, le16_to_cpu(fc), len);
949
950 scratch_phys = txcmd_phys + sizeof(struct iwl_cmd_header) +
951 offsetof(struct iwl_tx_cmd, scratch);
952 tx_cmd->dram_lsb_ptr = cpu_to_le32(scratch_phys);
953 tx_cmd->dram_msb_ptr = iwl_get_dma_hi_address(scratch_phys);
954
955 if (!ieee80211_has_morefrags(hdr->frame_control)) {
956 txq->need_update = 1;
957 if (qc)
958 priv->stations[sta_id].tid[tid].seq_number = seq_number;
959 } else {
960 wait_write_ptr = 1;
961 txq->need_update = 0;
962 }
963
964 iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)tx_cmd, sizeof(*tx_cmd));
965
966 iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)tx_cmd->hdr, hdr_len);
967
968 /* Set up entry for this TFD in Tx byte-count array */
969 priv->cfg->ops->lib->txq_update_byte_cnt_tbl(priv, txq, len);
970
971 /* Tell device the write index *just past* this latest filled TFD */
972 q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
973 ret = iwl_txq_update_write_ptr(priv, txq);
974 spin_unlock_irqrestore(&priv->lock, flags);
975
976 if (ret)
977 return ret;
978
979 if ((iwl_queue_space(q) < q->high_mark) && priv->mac80211_registered) {
980 if (wait_write_ptr) {
981 spin_lock_irqsave(&priv->lock, flags);
982 txq->need_update = 1;
983 iwl_txq_update_write_ptr(priv, txq);
984 spin_unlock_irqrestore(&priv->lock, flags);
985 } else {
986 ieee80211_stop_queue(priv->hw, swq_id);
987 }
988 }
989
990 return 0;
991
992drop_unlock:
993 spin_unlock_irqrestore(&priv->lock, flags);
994drop:
995 return -1;
996}
997EXPORT_SYMBOL(iwl_tx_skb);
998
999/*************** HOST COMMAND QUEUE FUNCTIONS *****/
1000
1001/**
1002 * iwl_enqueue_hcmd - enqueue a uCode command
1003 * @priv: device private data point
1004 * @cmd: a point to the ucode command structure
1005 *
1006 * The function returns < 0 values to indicate the operation is
1007 * failed. On success, it turns the index (> 0) of command in the
1008 * command queue.
1009 */
1010int iwl_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd)
1011{
1012 struct iwl_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM];
1013 struct iwl_queue *q = &txq->q;
1014 struct iwl_tfd_frame *tfd;
1015 struct iwl_cmd *out_cmd;
1016 dma_addr_t phys_addr;
1017 unsigned long flags;
1018 int len, ret;
1019 u32 idx;
1020 u16 fix_size;
1021
1022 cmd->len = priv->cfg->ops->utils->get_hcmd_size(cmd->id, cmd->len);
1023 fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr));
1024
1025 /* If any of the command structures end up being larger than
1026 * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then
1027 * we will need to increase the size of the TFD entries */
1028 BUG_ON((fix_size > TFD_MAX_PAYLOAD_SIZE) &&
1029 !(cmd->meta.flags & CMD_SIZE_HUGE));
1030
1031 if (iwl_is_rfkill(priv)) {
1032 IWL_DEBUG_INFO("Not sending command - RF KILL");
1033 return -EIO;
1034 }
1035
1036 if (iwl_queue_space(q) < ((cmd->meta.flags & CMD_ASYNC) ? 2 : 1)) {
1037 IWL_ERROR("No space for Tx\n");
1038 return -ENOSPC;
1039 }
1040
1041 spin_lock_irqsave(&priv->hcmd_lock, flags);
1042
1043 tfd = &txq->bd[q->write_ptr];
1044 memset(tfd, 0, sizeof(*tfd));
1045
1046
1047 idx = get_cmd_index(q, q->write_ptr, cmd->meta.flags & CMD_SIZE_HUGE);
1048 out_cmd = txq->cmd[idx];
1049
1050 out_cmd->hdr.cmd = cmd->id;
1051 memcpy(&out_cmd->meta, &cmd->meta, sizeof(cmd->meta));
1052 memcpy(&out_cmd->cmd.payload, cmd->data, cmd->len);
1053
1054 /* At this point, the out_cmd now has all of the incoming cmd
1055 * information */
1056
1057 out_cmd->hdr.flags = 0;
1058 out_cmd->hdr.sequence = cpu_to_le16(QUEUE_TO_SEQ(IWL_CMD_QUEUE_NUM) |
1059 INDEX_TO_SEQ(q->write_ptr));
1060 if (out_cmd->meta.flags & CMD_SIZE_HUGE)
1061 out_cmd->hdr.sequence |= SEQ_HUGE_FRAME;
1062 len = (idx == TFD_CMD_SLOTS) ?
1063 IWL_MAX_SCAN_SIZE : sizeof(struct iwl_cmd);
1064 phys_addr = pci_map_single(priv->pci_dev, out_cmd, len,
1065 PCI_DMA_TODEVICE);
1066 phys_addr += offsetof(struct iwl_cmd, hdr);
1067 iwl_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, fix_size);
1068
1069#ifdef CONFIG_IWLWIFI_DEBUG
1070 switch (out_cmd->hdr.cmd) {
1071 case REPLY_TX_LINK_QUALITY_CMD:
1072 case SENSITIVITY_CMD:
1073 IWL_DEBUG_HC_DUMP("Sending command %s (#%x), seq: 0x%04X, "
1074 "%d bytes at %d[%d]:%d\n",
1075 get_cmd_string(out_cmd->hdr.cmd),
1076 out_cmd->hdr.cmd,
1077 le16_to_cpu(out_cmd->hdr.sequence), fix_size,
1078 q->write_ptr, idx, IWL_CMD_QUEUE_NUM);
1079 break;
1080 default:
1081 IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, "
1082 "%d bytes at %d[%d]:%d\n",
1083 get_cmd_string(out_cmd->hdr.cmd),
1084 out_cmd->hdr.cmd,
1085 le16_to_cpu(out_cmd->hdr.sequence), fix_size,
1086 q->write_ptr, idx, IWL_CMD_QUEUE_NUM);
1087 }
1088#endif
1089 txq->need_update = 1;
1090
1091 /* Set up entry in queue's byte count circular buffer */
1092 priv->cfg->ops->lib->txq_update_byte_cnt_tbl(priv, txq, 0);
1093
1094 /* Increment and update queue's write index */
1095 q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
1096 ret = iwl_txq_update_write_ptr(priv, txq);
1097
1098 spin_unlock_irqrestore(&priv->hcmd_lock, flags);
1099 return ret ? ret : idx;
1100}
1101
1102int iwl_tx_queue_reclaim(struct iwl_priv *priv, int txq_id, int index)
1103{
1104 struct iwl_tx_queue *txq = &priv->txq[txq_id];
1105 struct iwl_queue *q = &txq->q;
1106 struct iwl_tx_info *tx_info;
1107 int nfreed = 0;
1108
1109 if ((index >= q->n_bd) || (iwl_queue_used(q, index) == 0)) {
1110 IWL_ERROR("Read index for DMA queue txq id (%d), index %d, "
1111 "is out of range [0-%d] %d %d.\n", txq_id,
1112 index, q->n_bd, q->write_ptr, q->read_ptr);
1113 return 0;
1114 }
1115
1116 for (index = iwl_queue_inc_wrap(index, q->n_bd); q->read_ptr != index;
1117 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
1118
1119 tx_info = &txq->txb[txq->q.read_ptr];
1120 ieee80211_tx_status_irqsafe(priv->hw, tx_info->skb[0]);
1121 tx_info->skb[0] = NULL;
1122
1123 if (priv->cfg->ops->lib->txq_inval_byte_cnt_tbl)
1124 priv->cfg->ops->lib->txq_inval_byte_cnt_tbl(priv, txq);
1125
1126 iwl_hw_txq_free_tfd(priv, txq);
1127 nfreed++;
1128 }
1129 return nfreed;
1130}
1131EXPORT_SYMBOL(iwl_tx_queue_reclaim);
1132
1133
1134/**
1135 * iwl_hcmd_queue_reclaim - Reclaim TX command queue entries already Tx'd
1136 *
1137 * When FW advances 'R' index, all entries between old and new 'R' index
1138 * need to be reclaimed. As result, some free space forms. If there is
1139 * enough free space (> low mark), wake the stack that feeds us.
1140 */
1141static void iwl_hcmd_queue_reclaim(struct iwl_priv *priv, int txq_id, int index)
1142{
1143 struct iwl_tx_queue *txq = &priv->txq[txq_id];
1144 struct iwl_queue *q = &txq->q;
1145 struct iwl_tfd_frame *bd = &txq->bd[index];
1146 dma_addr_t dma_addr;
1147 int is_odd, buf_len;
1148 int nfreed = 0;
1149
1150 if ((index >= q->n_bd) || (iwl_queue_used(q, index) == 0)) {
1151 IWL_ERROR("Read index for DMA queue txq id (%d), index %d, "
1152 "is out of range [0-%d] %d %d.\n", txq_id,
1153 index, q->n_bd, q->write_ptr, q->read_ptr);
1154 return;
1155 }
1156
1157 for (index = iwl_queue_inc_wrap(index, q->n_bd); q->read_ptr != index;
1158 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
1159
1160 if (nfreed > 1) {
1161 IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index,
1162 q->write_ptr, q->read_ptr);
1163 queue_work(priv->workqueue, &priv->restart);
1164 }
1165 is_odd = (index/2) & 0x1;
1166 if (is_odd) {
1167 dma_addr = IWL_GET_BITS(bd->pa[index], tb2_addr_lo16) |
1168 (IWL_GET_BITS(bd->pa[index],
1169 tb2_addr_hi20) << 16);
1170 buf_len = IWL_GET_BITS(bd->pa[index], tb2_len);
1171 } else {
1172 dma_addr = le32_to_cpu(bd->pa[index].tb1_addr);
1173 buf_len = IWL_GET_BITS(bd->pa[index], tb1_len);
1174 }
1175
1176 pci_unmap_single(priv->pci_dev, dma_addr, buf_len,
1177 PCI_DMA_TODEVICE);
1178 nfreed++;
1179 }
1180}
1181
1182/**
1183 * iwl_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
1184 * @rxb: Rx buffer to reclaim
1185 *
1186 * If an Rx buffer has an async callback associated with it the callback
1187 * will be executed. The attached skb (if present) will only be freed
1188 * if the callback returns 1
1189 */
1190void iwl_tx_cmd_complete(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
1191{
1192 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
1193 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
1194 int txq_id = SEQ_TO_QUEUE(sequence);
1195 int index = SEQ_TO_INDEX(sequence);
1196 int cmd_index;
1197 bool huge = !!(pkt->hdr.sequence & SEQ_HUGE_FRAME);
1198 struct iwl_cmd *cmd;
1199
1200 /* If a Tx command is being handled and it isn't in the actual
1201 * command queue then there a command routing bug has been introduced
1202 * in the queue management code. */
1203 if (WARN(txq_id != IWL_CMD_QUEUE_NUM,
1204 "wrong command queue %d, command id 0x%X\n", txq_id, pkt->hdr.cmd))
1205 return;
1206
1207 cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge);
1208 cmd = priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index];
1209
1210 /* Input error checking is done when commands are added to queue. */
1211 if (cmd->meta.flags & CMD_WANT_SKB) {
1212 cmd->meta.source->u.skb = rxb->skb;
1213 rxb->skb = NULL;
1214 } else if (cmd->meta.u.callback &&
1215 !cmd->meta.u.callback(priv, cmd, rxb->skb))
1216 rxb->skb = NULL;
1217
1218 iwl_hcmd_queue_reclaim(priv, txq_id, index);
1219
1220 if (!(cmd->meta.flags & CMD_ASYNC)) {
1221 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
1222 wake_up_interruptible(&priv->wait_command_queue);
1223 }
1224}
1225EXPORT_SYMBOL(iwl_tx_cmd_complete);
1226
1227/*
1228 * Find first available (lowest unused) Tx Queue, mark it "active".
1229 * Called only when finding queue for aggregation.
1230 * Should never return anything < 7, because they should already
1231 * be in use as EDCA AC (0-3), Command (4), HCCA (5, 6).
1232 */
1233static int iwl_txq_ctx_activate_free(struct iwl_priv *priv)
1234{
1235 int txq_id;
1236
1237 for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++)
1238 if (!test_and_set_bit(txq_id, &priv->txq_ctx_active_msk))
1239 return txq_id;
1240 return -1;
1241}
1242
1243int iwl_tx_agg_start(struct iwl_priv *priv, const u8 *ra, u16 tid, u16 *ssn)
1244{
1245 int sta_id;
1246 int tx_fifo;
1247 int txq_id;
1248 int ret;
1249 unsigned long flags;
1250 struct iwl_tid_data *tid_data;
1251 DECLARE_MAC_BUF(mac);
1252
1253 if (likely(tid < ARRAY_SIZE(default_tid_to_tx_fifo)))
1254 tx_fifo = default_tid_to_tx_fifo[tid];
1255 else
1256 return -EINVAL;
1257
1258 IWL_WARNING("%s on ra = %s tid = %d\n",
1259 __func__, print_mac(mac, ra), tid);
1260
1261 sta_id = iwl_find_station(priv, ra);
1262 if (sta_id == IWL_INVALID_STATION)
1263 return -ENXIO;
1264
1265 if (priv->stations[sta_id].tid[tid].agg.state != IWL_AGG_OFF) {
1266 IWL_ERROR("Start AGG when state is not IWL_AGG_OFF !\n");
1267 return -ENXIO;
1268 }
1269
1270 txq_id = iwl_txq_ctx_activate_free(priv);
1271 if (txq_id == -1)
1272 return -ENXIO;
1273
1274 spin_lock_irqsave(&priv->sta_lock, flags);
1275 tid_data = &priv->stations[sta_id].tid[tid];
1276 *ssn = SEQ_TO_SN(tid_data->seq_number);
1277 tid_data->agg.txq_id = txq_id;
1278 spin_unlock_irqrestore(&priv->sta_lock, flags);
1279
1280 ret = priv->cfg->ops->lib->txq_agg_enable(priv, txq_id, tx_fifo,
1281 sta_id, tid, *ssn);
1282 if (ret)
1283 return ret;
1284
1285 if (tid_data->tfds_in_queue == 0) {
1286 printk(KERN_ERR "HW queue is empty\n");
1287 tid_data->agg.state = IWL_AGG_ON;
1288 ieee80211_start_tx_ba_cb_irqsafe(priv->hw, ra, tid);
1289 } else {
1290 IWL_DEBUG_HT("HW queue is NOT empty: %d packets in HW queue\n",
1291 tid_data->tfds_in_queue);
1292 tid_data->agg.state = IWL_EMPTYING_HW_QUEUE_ADDBA;
1293 }
1294 return ret;
1295}
1296EXPORT_SYMBOL(iwl_tx_agg_start);
1297
1298int iwl_tx_agg_stop(struct iwl_priv *priv , const u8 *ra, u16 tid)
1299{
1300 int tx_fifo_id, txq_id, sta_id, ssn = -1;
1301 struct iwl_tid_data *tid_data;
1302 int ret, write_ptr, read_ptr;
1303 unsigned long flags;
1304 DECLARE_MAC_BUF(mac);
1305
1306 if (!ra) {
1307 IWL_ERROR("ra = NULL\n");
1308 return -EINVAL;
1309 }
1310
1311 if (likely(tid < ARRAY_SIZE(default_tid_to_tx_fifo)))
1312 tx_fifo_id = default_tid_to_tx_fifo[tid];
1313 else
1314 return -EINVAL;
1315
1316 sta_id = iwl_find_station(priv, ra);
1317
1318 if (sta_id == IWL_INVALID_STATION)
1319 return -ENXIO;
1320
1321 if (priv->stations[sta_id].tid[tid].agg.state != IWL_AGG_ON)
1322 IWL_WARNING("Stopping AGG while state not IWL_AGG_ON\n");
1323
1324 tid_data = &priv->stations[sta_id].tid[tid];
1325 ssn = (tid_data->seq_number & IEEE80211_SCTL_SEQ) >> 4;
1326 txq_id = tid_data->agg.txq_id;
1327 write_ptr = priv->txq[txq_id].q.write_ptr;
1328 read_ptr = priv->txq[txq_id].q.read_ptr;
1329
1330 /* The queue is not empty */
1331 if (write_ptr != read_ptr) {
1332 IWL_DEBUG_HT("Stopping a non empty AGG HW QUEUE\n");
1333 priv->stations[sta_id].tid[tid].agg.state =
1334 IWL_EMPTYING_HW_QUEUE_DELBA;
1335 return 0;
1336 }
1337
1338 IWL_DEBUG_HT("HW queue is empty\n");
1339 priv->stations[sta_id].tid[tid].agg.state = IWL_AGG_OFF;
1340
1341 spin_lock_irqsave(&priv->lock, flags);
1342 ret = priv->cfg->ops->lib->txq_agg_disable(priv, txq_id, ssn,
1343 tx_fifo_id);
1344 spin_unlock_irqrestore(&priv->lock, flags);
1345
1346 if (ret)
1347 return ret;
1348
1349 ieee80211_stop_tx_ba_cb_irqsafe(priv->hw, ra, tid);
1350
1351 return 0;
1352}
1353EXPORT_SYMBOL(iwl_tx_agg_stop);
1354
1355int iwl_txq_check_empty(struct iwl_priv *priv, int sta_id, u8 tid, int txq_id)
1356{
1357 struct iwl_queue *q = &priv->txq[txq_id].q;
1358 u8 *addr = priv->stations[sta_id].sta.sta.addr;
1359 struct iwl_tid_data *tid_data = &priv->stations[sta_id].tid[tid];
1360
1361 switch (priv->stations[sta_id].tid[tid].agg.state) {
1362 case IWL_EMPTYING_HW_QUEUE_DELBA:
1363 /* We are reclaiming the last packet of the */
1364 /* aggregated HW queue */
1365 if (txq_id == tid_data->agg.txq_id &&
1366 q->read_ptr == q->write_ptr) {
1367 u16 ssn = SEQ_TO_SN(tid_data->seq_number);
1368 int tx_fifo = default_tid_to_tx_fifo[tid];
1369 IWL_DEBUG_HT("HW queue empty: continue DELBA flow\n");
1370 priv->cfg->ops->lib->txq_agg_disable(priv, txq_id,
1371 ssn, tx_fifo);
1372 tid_data->agg.state = IWL_AGG_OFF;
1373 ieee80211_stop_tx_ba_cb_irqsafe(priv->hw, addr, tid);
1374 }
1375 break;
1376 case IWL_EMPTYING_HW_QUEUE_ADDBA:
1377 /* We are reclaiming the last packet of the queue */
1378 if (tid_data->tfds_in_queue == 0) {
1379 IWL_DEBUG_HT("HW queue empty: continue ADDBA flow\n");
1380 tid_data->agg.state = IWL_AGG_ON;
1381 ieee80211_start_tx_ba_cb_irqsafe(priv->hw, addr, tid);
1382 }
1383 break;
1384 }
1385 return 0;
1386}
1387EXPORT_SYMBOL(iwl_txq_check_empty);
1388
1389/**
1390 * iwl_tx_status_reply_compressed_ba - Update tx status from block-ack
1391 *
1392 * Go through block-ack's bitmap of ACK'd frames, update driver's record of
1393 * ACK vs. not. This gets sent to mac80211, then to rate scaling algo.
1394 */
1395static int iwl_tx_status_reply_compressed_ba(struct iwl_priv *priv,
1396 struct iwl_ht_agg *agg,
1397 struct iwl_compressed_ba_resp *ba_resp)
1398
1399{
1400 int i, sh, ack;
1401 u16 seq_ctl = le16_to_cpu(ba_resp->seq_ctl);
1402 u16 scd_flow = le16_to_cpu(ba_resp->scd_flow);
1403 u64 bitmap;
1404 int successes = 0;
1405 struct ieee80211_tx_info *info;
1406
1407 if (unlikely(!agg->wait_for_ba)) {
1408 IWL_ERROR("Received BA when not expected\n");
1409 return -EINVAL;
1410 }
1411
1412 /* Mark that the expected block-ack response arrived */
1413 agg->wait_for_ba = 0;
1414 IWL_DEBUG_TX_REPLY("BA %d %d\n", agg->start_idx, ba_resp->seq_ctl);
1415
1416 /* Calculate shift to align block-ack bits with our Tx window bits */
1417 sh = agg->start_idx - SEQ_TO_INDEX(seq_ctl>>4);
1418 if (sh < 0) /* tbw something is wrong with indices */
1419 sh += 0x100;
1420
1421 /* don't use 64-bit values for now */
1422 bitmap = le64_to_cpu(ba_resp->bitmap) >> sh;
1423
1424 if (agg->frame_count > (64 - sh)) {
1425 IWL_DEBUG_TX_REPLY("more frames than bitmap size");
1426 return -1;
1427 }
1428
1429 /* check for success or failure according to the
1430 * transmitted bitmap and block-ack bitmap */
1431 bitmap &= agg->bitmap;
1432
1433 /* For each frame attempted in aggregation,
1434 * update driver's record of tx frame's status. */
1435 for (i = 0; i < agg->frame_count ; i++) {
1436 ack = bitmap & (1ULL << i);
1437 successes += !!ack;
1438 IWL_DEBUG_TX_REPLY("%s ON i=%d idx=%d raw=%d\n",
1439 ack? "ACK":"NACK", i, (agg->start_idx + i) & 0xff,
1440 agg->start_idx + i);
1441 }
1442
1443 info = IEEE80211_SKB_CB(priv->txq[scd_flow].txb[agg->start_idx].skb[0]);
1444 memset(&info->status, 0, sizeof(info->status));
1445 info->flags = IEEE80211_TX_STAT_ACK;
1446 info->flags |= IEEE80211_TX_STAT_AMPDU;
1447 info->status.ampdu_ack_map = successes;
1448 info->status.ampdu_ack_len = agg->frame_count;
1449 iwl_hwrate_to_tx_control(priv, agg->rate_n_flags, info);
1450
1451 IWL_DEBUG_TX_REPLY("Bitmap %llx\n", (unsigned long long)bitmap);
1452
1453 return 0;
1454}
1455
1456/**
1457 * iwl_rx_reply_compressed_ba - Handler for REPLY_COMPRESSED_BA
1458 *
1459 * Handles block-acknowledge notification from device, which reports success
1460 * of frames sent via aggregation.
1461 */
1462void iwl_rx_reply_compressed_ba(struct iwl_priv *priv,
1463 struct iwl_rx_mem_buffer *rxb)
1464{
1465 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
1466 struct iwl_compressed_ba_resp *ba_resp = &pkt->u.compressed_ba;
1467 int index;
1468 struct iwl_tx_queue *txq = NULL;
1469 struct iwl_ht_agg *agg;
1470 DECLARE_MAC_BUF(mac);
1471
1472 /* "flow" corresponds to Tx queue */
1473 u16 scd_flow = le16_to_cpu(ba_resp->scd_flow);
1474
1475 /* "ssn" is start of block-ack Tx window, corresponds to index
1476 * (in Tx queue's circular buffer) of first TFD/frame in window */
1477 u16 ba_resp_scd_ssn = le16_to_cpu(ba_resp->scd_ssn);
1478
1479 if (scd_flow >= priv->hw_params.max_txq_num) {
1480 IWL_ERROR("BUG_ON scd_flow is bigger than number of queues\n");
1481 return;
1482 }
1483
1484 txq = &priv->txq[scd_flow];
1485 agg = &priv->stations[ba_resp->sta_id].tid[ba_resp->tid].agg;
1486
1487 /* Find index just before block-ack window */
1488 index = iwl_queue_dec_wrap(ba_resp_scd_ssn & 0xff, txq->q.n_bd);
1489
1490 /* TODO: Need to get this copy more safely - now good for debug */
1491
1492 IWL_DEBUG_TX_REPLY("REPLY_COMPRESSED_BA [%d]Received from %s, "
1493 "sta_id = %d\n",
1494 agg->wait_for_ba,
1495 print_mac(mac, (u8 *) &ba_resp->sta_addr_lo32),
1496 ba_resp->sta_id);
1497 IWL_DEBUG_TX_REPLY("TID = %d, SeqCtl = %d, bitmap = 0x%llx, scd_flow = "
1498 "%d, scd_ssn = %d\n",
1499 ba_resp->tid,
1500 ba_resp->seq_ctl,
1501 (unsigned long long)le64_to_cpu(ba_resp->bitmap),
1502 ba_resp->scd_flow,
1503 ba_resp->scd_ssn);
1504 IWL_DEBUG_TX_REPLY("DAT start_idx = %d, bitmap = 0x%llx \n",
1505 agg->start_idx,
1506 (unsigned long long)agg->bitmap);
1507
1508 /* Update driver's record of ACK vs. not for each frame in window */
1509 iwl_tx_status_reply_compressed_ba(priv, agg, ba_resp);
1510
1511 /* Release all TFDs before the SSN, i.e. all TFDs in front of
1512 * block-ack window (we assume that they've been successfully
1513 * transmitted ... if not, it's too late anyway). */
1514 if (txq->q.read_ptr != (ba_resp_scd_ssn & 0xff)) {
1515 /* calculate mac80211 ampdu sw queue to wake */
1516 int ampdu_q =
1517 scd_flow - priv->hw_params.first_ampdu_q + priv->hw->queues;
1518 int freed = iwl_tx_queue_reclaim(priv, scd_flow, index);
1519 priv->stations[ba_resp->sta_id].
1520 tid[ba_resp->tid].tfds_in_queue -= freed;
1521 if (iwl_queue_space(&txq->q) > txq->q.low_mark &&
1522 priv->mac80211_registered &&
1523 agg->state != IWL_EMPTYING_HW_QUEUE_DELBA)
1524 ieee80211_wake_queue(priv->hw, ampdu_q);
1525
1526 iwl_txq_check_empty(priv, ba_resp->sta_id,
1527 ba_resp->tid, scd_flow);
1528 }
1529}
1530EXPORT_SYMBOL(iwl_rx_reply_compressed_ba);
1531
1532#ifdef CONFIG_IWLWIFI_DEBUG
1533#define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
1534
1535const char *iwl_get_tx_fail_reason(u32 status)
1536{
1537 switch (status & TX_STATUS_MSK) {
1538 case TX_STATUS_SUCCESS:
1539 return "SUCCESS";
1540 TX_STATUS_ENTRY(SHORT_LIMIT);
1541 TX_STATUS_ENTRY(LONG_LIMIT);
1542 TX_STATUS_ENTRY(FIFO_UNDERRUN);
1543 TX_STATUS_ENTRY(MGMNT_ABORT);
1544 TX_STATUS_ENTRY(NEXT_FRAG);
1545 TX_STATUS_ENTRY(LIFE_EXPIRE);
1546 TX_STATUS_ENTRY(DEST_PS);
1547 TX_STATUS_ENTRY(ABORTED);
1548 TX_STATUS_ENTRY(BT_RETRY);
1549 TX_STATUS_ENTRY(STA_INVALID);
1550 TX_STATUS_ENTRY(FRAG_DROPPED);
1551 TX_STATUS_ENTRY(TID_DISABLE);
1552 TX_STATUS_ENTRY(FRAME_FLUSHED);
1553 TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL);
1554 TX_STATUS_ENTRY(TX_LOCKED);
1555 TX_STATUS_ENTRY(NO_BEACON_ON_RADAR);
1556 }
1557
1558 return "UNKNOWN";
1559}
1560EXPORT_SYMBOL(iwl_get_tx_fail_reason);
1561#endif /* CONFIG_IWLWIFI_DEBUG */
diff --git a/drivers/net/wireless/iwlwifi/iwl3945-base.c b/drivers/net/wireless/iwlwifi/iwl3945-base.c
index 6027e1119c3f..d15a2c997954 100644
--- a/drivers/net/wireless/iwlwifi/iwl3945-base.c
+++ b/drivers/net/wireless/iwlwifi/iwl3945-base.c
@@ -29,7 +29,6 @@
29 29
30#include <linux/kernel.h> 30#include <linux/kernel.h>
31#include <linux/module.h> 31#include <linux/module.h>
32#include <linux/version.h>
33#include <linux/init.h> 32#include <linux/init.h>
34#include <linux/pci.h> 33#include <linux/pci.h>
35#include <linux/dma-mapping.h> 34#include <linux/dma-mapping.h>
@@ -102,16 +101,6 @@ MODULE_VERSION(DRV_VERSION);
102MODULE_AUTHOR(DRV_COPYRIGHT); 101MODULE_AUTHOR(DRV_COPYRIGHT);
103MODULE_LICENSE("GPL"); 102MODULE_LICENSE("GPL");
104 103
105static __le16 *ieee80211_get_qos_ctrl(struct ieee80211_hdr *hdr)
106{
107 u16 fc = le16_to_cpu(hdr->frame_control);
108 int hdr_len = ieee80211_get_hdrlen(fc);
109
110 if ((fc & 0x00cc) == (IEEE80211_STYPE_QOS_DATA | IEEE80211_FTYPE_DATA))
111 return (__le16 *) ((u8 *) hdr + hdr_len - QOS_CONTROL_LEN);
112 return NULL;
113}
114
115static const struct ieee80211_supported_band *iwl3945_get_band( 104static const struct ieee80211_supported_band *iwl3945_get_band(
116 struct iwl3945_priv *priv, enum ieee80211_band band) 105 struct iwl3945_priv *priv, enum ieee80211_band band)
117{ 106{
@@ -285,10 +274,8 @@ static int iwl3945_tx_queue_alloc(struct iwl3945_priv *priv,
285 return 0; 274 return 0;
286 275
287 error: 276 error:
288 if (txq->txb) { 277 kfree(txq->txb);
289 kfree(txq->txb); 278 txq->txb = NULL;
290 txq->txb = NULL;
291 }
292 279
293 return -ENOMEM; 280 return -ENOMEM;
294} 281}
@@ -375,10 +362,8 @@ void iwl3945_tx_queue_free(struct iwl3945_priv *priv, struct iwl3945_tx_queue *t
375 txq->q.n_bd, txq->bd, txq->q.dma_addr); 362 txq->q.n_bd, txq->bd, txq->q.dma_addr);
376 363
377 /* De-alloc array of per-TFD driver data */ 364 /* De-alloc array of per-TFD driver data */
378 if (txq->txb) { 365 kfree(txq->txb);
379 kfree(txq->txb); 366 txq->txb = NULL;
380 txq->txb = NULL;
381 }
382 367
383 /* 0-fill queue descriptor structure */ 368 /* 0-fill queue descriptor structure */
384 memset(txq, 0, sizeof(*txq)); 369 memset(txq, 0, sizeof(*txq));
@@ -547,10 +532,20 @@ static inline int iwl3945_is_init(struct iwl3945_priv *priv)
547 return test_bit(STATUS_INIT, &priv->status); 532 return test_bit(STATUS_INIT, &priv->status);
548} 533}
549 534
535static inline int iwl3945_is_rfkill_sw(struct iwl3945_priv *priv)
536{
537 return test_bit(STATUS_RF_KILL_SW, &priv->status);
538}
539
540static inline int iwl3945_is_rfkill_hw(struct iwl3945_priv *priv)
541{
542 return test_bit(STATUS_RF_KILL_HW, &priv->status);
543}
544
550static inline int iwl3945_is_rfkill(struct iwl3945_priv *priv) 545static inline int iwl3945_is_rfkill(struct iwl3945_priv *priv)
551{ 546{
552 return test_bit(STATUS_RF_KILL_HW, &priv->status) || 547 return iwl3945_is_rfkill_hw(priv) ||
553 test_bit(STATUS_RF_KILL_SW, &priv->status); 548 iwl3945_is_rfkill_sw(priv);
554} 549}
555 550
556static inline int iwl3945_is_ready_rf(struct iwl3945_priv *priv) 551static inline int iwl3945_is_ready_rf(struct iwl3945_priv *priv)
@@ -980,7 +975,7 @@ static int iwl3945_full_rxon_required(struct iwl3945_priv *priv)
980{ 975{
981 976
982 /* These items are only settable from the full RXON command */ 977 /* These items are only settable from the full RXON command */
983 if (!(priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) || 978 if (!(iwl3945_is_associated(priv)) ||
984 compare_ether_addr(priv->staging_rxon.bssid_addr, 979 compare_ether_addr(priv->staging_rxon.bssid_addr,
985 priv->active_rxon.bssid_addr) || 980 priv->active_rxon.bssid_addr) ||
986 compare_ether_addr(priv->staging_rxon.node_addr, 981 compare_ether_addr(priv->staging_rxon.node_addr,
@@ -1165,7 +1160,7 @@ static int iwl3945_commit_rxon(struct iwl3945_priv *priv)
1165 /* If we have set the ASSOC_MSK and we are in BSS mode then 1160 /* If we have set the ASSOC_MSK and we are in BSS mode then
1166 * add the IWL_AP_ID to the station rate table */ 1161 * add the IWL_AP_ID to the station rate table */
1167 if (iwl3945_is_associated(priv) && 1162 if (iwl3945_is_associated(priv) &&
1168 (priv->iw_mode == IEEE80211_IF_TYPE_STA)) 1163 (priv->iw_mode == NL80211_IFTYPE_STATION))
1169 if (iwl3945_add_station(priv, priv->active_rxon.bssid_addr, 1, 0) 1164 if (iwl3945_add_station(priv, priv->active_rxon.bssid_addr, 1, 0)
1170 == IWL_INVALID_STATION) { 1165 == IWL_INVALID_STATION) {
1171 IWL_ERROR("Error adding AP address for transmit.\n"); 1166 IWL_ERROR("Error adding AP address for transmit.\n");
@@ -1452,8 +1447,8 @@ unsigned int iwl3945_fill_beacon_frame(struct iwl3945_priv *priv,
1452{ 1447{
1453 1448
1454 if (!iwl3945_is_associated(priv) || !priv->ibss_beacon || 1449 if (!iwl3945_is_associated(priv) || !priv->ibss_beacon ||
1455 ((priv->iw_mode != IEEE80211_IF_TYPE_IBSS) && 1450 ((priv->iw_mode != NL80211_IFTYPE_ADHOC) &&
1456 (priv->iw_mode != IEEE80211_IF_TYPE_AP))) 1451 (priv->iw_mode != NL80211_IFTYPE_AP)))
1457 return 0; 1452 return 0;
1458 1453
1459 if (priv->ibss_beacon->len > left) 1454 if (priv->ibss_beacon->len > left)
@@ -1562,7 +1557,7 @@ int iwl3945_eeprom_init(struct iwl3945_priv *priv)
1562 BUILD_BUG_ON(sizeof(priv->eeprom) != IWL_EEPROM_IMAGE_SIZE); 1557 BUILD_BUG_ON(sizeof(priv->eeprom) != IWL_EEPROM_IMAGE_SIZE);
1563 1558
1564 if ((gp & CSR_EEPROM_GP_VALID_MSK) == CSR_EEPROM_GP_BAD_SIGNATURE) { 1559 if ((gp & CSR_EEPROM_GP_VALID_MSK) == CSR_EEPROM_GP_BAD_SIGNATURE) {
1565 IWL_ERROR("EEPROM not found, EEPROM_GP=0x%08x", gp); 1560 IWL_ERROR("EEPROM not found, EEPROM_GP=0x%08x\n", gp);
1566 return -ENOENT; 1561 return -ENOENT;
1567 } 1562 }
1568 1563
@@ -1587,7 +1582,7 @@ int iwl3945_eeprom_init(struct iwl3945_priv *priv)
1587 } 1582 }
1588 1583
1589 if (!(r & CSR_EEPROM_REG_READ_VALID_MSK)) { 1584 if (!(r & CSR_EEPROM_REG_READ_VALID_MSK)) {
1590 IWL_ERROR("Time out reading EEPROM[%d]", addr); 1585 IWL_ERROR("Time out reading EEPROM[%d]\n", addr);
1591 return -ETIMEDOUT; 1586 return -ETIMEDOUT;
1592 } 1587 }
1593 e[addr / 2] = le16_to_cpu((__force __le16)(r >> 16)); 1588 e[addr / 2] = le16_to_cpu((__force __le16)(r >> 16));
@@ -1751,14 +1746,14 @@ static void iwl3945_reset_qos(struct iwl3945_priv *priv)
1751 spin_lock_irqsave(&priv->lock, flags); 1746 spin_lock_irqsave(&priv->lock, flags);
1752 priv->qos_data.qos_active = 0; 1747 priv->qos_data.qos_active = 0;
1753 1748
1754 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) { 1749 if (priv->iw_mode == NL80211_IFTYPE_ADHOC) {
1755 if (priv->qos_data.qos_enable) 1750 if (priv->qos_data.qos_enable)
1756 priv->qos_data.qos_active = 1; 1751 priv->qos_data.qos_active = 1;
1757 if (!(priv->active_rate & 0xfff0)) { 1752 if (!(priv->active_rate & 0xfff0)) {
1758 cw_min = 31; 1753 cw_min = 31;
1759 is_legacy = 1; 1754 is_legacy = 1;
1760 } 1755 }
1761 } else if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { 1756 } else if (priv->iw_mode == NL80211_IFTYPE_AP) {
1762 if (priv->qos_data.qos_enable) 1757 if (priv->qos_data.qos_enable)
1763 priv->qos_data.qos_active = 1; 1758 priv->qos_data.qos_active = 1;
1764 } else if (!(priv->staging_rxon.flags & RXON_FLG_SHORT_SLOT_MSK)) { 1759 } else if (!(priv->staging_rxon.flags & RXON_FLG_SHORT_SLOT_MSK)) {
@@ -2035,36 +2030,6 @@ static int iwl3945_send_power_mode(struct iwl3945_priv *priv, u32 mode)
2035 return rc; 2030 return rc;
2036} 2031}
2037 2032
2038int iwl3945_is_network_packet(struct iwl3945_priv *priv, struct ieee80211_hdr *header)
2039{
2040 /* Filter incoming packets to determine if they are targeted toward
2041 * this network, discarding packets coming from ourselves */
2042 switch (priv->iw_mode) {
2043 case IEEE80211_IF_TYPE_IBSS: /* Header: Dest. | Source | BSSID */
2044 /* packets from our adapter are dropped (echo) */
2045 if (!compare_ether_addr(header->addr2, priv->mac_addr))
2046 return 0;
2047 /* {broad,multi}cast packets to our IBSS go through */
2048 if (is_multicast_ether_addr(header->addr1))
2049 return !compare_ether_addr(header->addr3, priv->bssid);
2050 /* packets to our adapter go through */
2051 return !compare_ether_addr(header->addr1, priv->mac_addr);
2052 case IEEE80211_IF_TYPE_STA: /* Header: Dest. | AP{BSSID} | Source */
2053 /* packets from our adapter are dropped (echo) */
2054 if (!compare_ether_addr(header->addr3, priv->mac_addr))
2055 return 0;
2056 /* {broad,multi}cast packets to our BSS go through */
2057 if (is_multicast_ether_addr(header->addr1))
2058 return !compare_ether_addr(header->addr2, priv->bssid);
2059 /* packets to our adapter go through */
2060 return !compare_ether_addr(header->addr1, priv->mac_addr);
2061 default:
2062 return 1;
2063 }
2064
2065 return 1;
2066}
2067
2068/** 2033/**
2069 * iwl3945_scan_cancel - Cancel any currently executing HW scan 2034 * iwl3945_scan_cancel - Cancel any currently executing HW scan
2070 * 2035 *
@@ -2117,20 +2082,6 @@ static int iwl3945_scan_cancel_timeout(struct iwl3945_priv *priv, unsigned long
2117 return ret; 2082 return ret;
2118} 2083}
2119 2084
2120static void iwl3945_sequence_reset(struct iwl3945_priv *priv)
2121{
2122 /* Reset ieee stats */
2123
2124 /* We don't reset the net_device_stats (ieee->stats) on
2125 * re-association */
2126
2127 priv->last_seq_num = -1;
2128 priv->last_frag_num = -1;
2129 priv->last_packet_time = 0;
2130
2131 iwl3945_scan_cancel(priv);
2132}
2133
2134#define MAX_UCODE_BEACON_INTERVAL 1024 2085#define MAX_UCODE_BEACON_INTERVAL 1024
2135#define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA) 2086#define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
2136 2087
@@ -2169,7 +2120,7 @@ static void iwl3945_setup_rxon_timing(struct iwl3945_priv *priv)
2169 beacon_int = priv->beacon_int; 2120 beacon_int = priv->beacon_int;
2170 spin_unlock_irqrestore(&priv->lock, flags); 2121 spin_unlock_irqrestore(&priv->lock, flags);
2171 2122
2172 if (priv->iw_mode == IEEE80211_IF_TYPE_STA) { 2123 if (priv->iw_mode == NL80211_IFTYPE_STATION) {
2173 if (beacon_int == 0) { 2124 if (beacon_int == 0) {
2174 priv->rxon_timing.beacon_interval = cpu_to_le16(100); 2125 priv->rxon_timing.beacon_interval = cpu_to_le16(100);
2175 priv->rxon_timing.beacon_init_val = cpu_to_le32(102400); 2126 priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
@@ -2205,7 +2156,7 @@ static void iwl3945_setup_rxon_timing(struct iwl3945_priv *priv)
2205 2156
2206static int iwl3945_scan_initiate(struct iwl3945_priv *priv) 2157static int iwl3945_scan_initiate(struct iwl3945_priv *priv)
2207{ 2158{
2208 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { 2159 if (priv->iw_mode == NL80211_IFTYPE_AP) {
2209 IWL_ERROR("APs don't scan.\n"); 2160 IWL_ERROR("APs don't scan.\n");
2210 return 0; 2161 return 0;
2211 } 2162 }
@@ -2267,7 +2218,7 @@ static void iwl3945_set_flags_for_phymode(struct iwl3945_priv *priv,
2267 else 2218 else
2268 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; 2219 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2269 2220
2270 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) 2221 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
2271 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; 2222 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2272 2223
2273 priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK; 2224 priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
@@ -2286,23 +2237,23 @@ static void iwl3945_connection_init_rx_config(struct iwl3945_priv *priv)
2286 memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon)); 2237 memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
2287 2238
2288 switch (priv->iw_mode) { 2239 switch (priv->iw_mode) {
2289 case IEEE80211_IF_TYPE_AP: 2240 case NL80211_IFTYPE_AP:
2290 priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP; 2241 priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP;
2291 break; 2242 break;
2292 2243
2293 case IEEE80211_IF_TYPE_STA: 2244 case NL80211_IFTYPE_STATION:
2294 priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS; 2245 priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS;
2295 priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK; 2246 priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
2296 break; 2247 break;
2297 2248
2298 case IEEE80211_IF_TYPE_IBSS: 2249 case NL80211_IFTYPE_ADHOC:
2299 priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS; 2250 priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS;
2300 priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK; 2251 priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
2301 priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK | 2252 priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
2302 RXON_FILTER_ACCEPT_GRP_MSK; 2253 RXON_FILTER_ACCEPT_GRP_MSK;
2303 break; 2254 break;
2304 2255
2305 case IEEE80211_IF_TYPE_MNTR: 2256 case NL80211_IFTYPE_MONITOR:
2306 priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER; 2257 priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER;
2307 priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK | 2258 priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK |
2308 RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK; 2259 RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK;
@@ -2322,7 +2273,7 @@ static void iwl3945_connection_init_rx_config(struct iwl3945_priv *priv)
2322#endif 2273#endif
2323 2274
2324 ch_info = iwl3945_get_channel_info(priv, priv->band, 2275 ch_info = iwl3945_get_channel_info(priv, priv->band,
2325 le16_to_cpu(priv->staging_rxon.channel)); 2276 le16_to_cpu(priv->active_rxon.channel));
2326 2277
2327 if (!ch_info) 2278 if (!ch_info)
2328 ch_info = &priv->channel_info[0]; 2279 ch_info = &priv->channel_info[0];
@@ -2331,7 +2282,7 @@ static void iwl3945_connection_init_rx_config(struct iwl3945_priv *priv)
2331 * in some case A channels are all non IBSS 2282 * in some case A channels are all non IBSS
2332 * in this case force B/G channel 2283 * in this case force B/G channel
2333 */ 2284 */
2334 if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) && 2285 if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) &&
2335 !(is_channel_ibss(ch_info))) 2286 !(is_channel_ibss(ch_info)))
2336 ch_info = &priv->channel_info[0]; 2287 ch_info = &priv->channel_info[0];
2337 2288
@@ -2351,7 +2302,7 @@ static void iwl3945_connection_init_rx_config(struct iwl3945_priv *priv)
2351 2302
2352static int iwl3945_set_mode(struct iwl3945_priv *priv, int mode) 2303static int iwl3945_set_mode(struct iwl3945_priv *priv, int mode)
2353{ 2304{
2354 if (mode == IEEE80211_IF_TYPE_IBSS) { 2305 if (mode == NL80211_IFTYPE_ADHOC) {
2355 const struct iwl3945_channel_info *ch_info; 2306 const struct iwl3945_channel_info *ch_info;
2356 2307
2357 ch_info = iwl3945_get_channel_info(priv, 2308 ch_info = iwl3945_get_channel_info(priv,
@@ -2389,12 +2340,13 @@ static int iwl3945_set_mode(struct iwl3945_priv *priv, int mode)
2389} 2340}
2390 2341
2391static void iwl3945_build_tx_cmd_hwcrypto(struct iwl3945_priv *priv, 2342static void iwl3945_build_tx_cmd_hwcrypto(struct iwl3945_priv *priv,
2392 struct ieee80211_tx_control *ctl, 2343 struct ieee80211_tx_info *info,
2393 struct iwl3945_cmd *cmd, 2344 struct iwl3945_cmd *cmd,
2394 struct sk_buff *skb_frag, 2345 struct sk_buff *skb_frag,
2395 int last_frag) 2346 int last_frag)
2396{ 2347{
2397 struct iwl3945_hw_key *keyinfo = &priv->stations[ctl->key_idx].keyinfo; 2348 struct iwl3945_hw_key *keyinfo =
2349 &priv->stations[info->control.hw_key->hw_key_idx].keyinfo;
2398 2350
2399 switch (keyinfo->alg) { 2351 switch (keyinfo->alg) {
2400 case ALG_CCMP: 2352 case ALG_CCMP:
@@ -2417,7 +2369,7 @@ static void iwl3945_build_tx_cmd_hwcrypto(struct iwl3945_priv *priv,
2417 2369
2418 case ALG_WEP: 2370 case ALG_WEP:
2419 cmd->cmd.tx.sec_ctl = TX_CMD_SEC_WEP | 2371 cmd->cmd.tx.sec_ctl = TX_CMD_SEC_WEP |
2420 (ctl->key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT; 2372 (info->control.hw_key->hw_key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT;
2421 2373
2422 if (keyinfo->keylen == 13) 2374 if (keyinfo->keylen == 13)
2423 cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128; 2375 cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128;
@@ -2425,7 +2377,7 @@ static void iwl3945_build_tx_cmd_hwcrypto(struct iwl3945_priv *priv,
2425 memcpy(&cmd->cmd.tx.key[3], keyinfo->key, keyinfo->keylen); 2377 memcpy(&cmd->cmd.tx.key[3], keyinfo->key, keyinfo->keylen);
2426 2378
2427 IWL_DEBUG_TX("Configuring packet for WEP encryption " 2379 IWL_DEBUG_TX("Configuring packet for WEP encryption "
2428 "with key %d\n", ctl->key_idx); 2380 "with key %d\n", info->control.hw_key->hw_key_idx);
2429 break; 2381 break;
2430 2382
2431 default: 2383 default:
@@ -2439,20 +2391,19 @@ static void iwl3945_build_tx_cmd_hwcrypto(struct iwl3945_priv *priv,
2439 */ 2391 */
2440static void iwl3945_build_tx_cmd_basic(struct iwl3945_priv *priv, 2392static void iwl3945_build_tx_cmd_basic(struct iwl3945_priv *priv,
2441 struct iwl3945_cmd *cmd, 2393 struct iwl3945_cmd *cmd,
2442 struct ieee80211_tx_control *ctrl, 2394 struct ieee80211_tx_info *info,
2443 struct ieee80211_hdr *hdr, 2395 struct ieee80211_hdr *hdr,
2444 int is_unicast, u8 std_id) 2396 int is_unicast, u8 std_id)
2445{ 2397{
2446 __le16 *qc; 2398 __le16 fc = hdr->frame_control;
2447 u16 fc = le16_to_cpu(hdr->frame_control);
2448 __le32 tx_flags = cmd->cmd.tx.tx_flags; 2399 __le32 tx_flags = cmd->cmd.tx.tx_flags;
2449 2400
2450 cmd->cmd.tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; 2401 cmd->cmd.tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
2451 if (!(ctrl->flags & IEEE80211_TXCTL_NO_ACK)) { 2402 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
2452 tx_flags |= TX_CMD_FLG_ACK_MSK; 2403 tx_flags |= TX_CMD_FLG_ACK_MSK;
2453 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) 2404 if (ieee80211_is_mgmt(fc))
2454 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; 2405 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
2455 if (ieee80211_is_probe_response(fc) && 2406 if (ieee80211_is_probe_resp(fc) &&
2456 !(le16_to_cpu(hdr->seq_ctrl) & 0xf)) 2407 !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
2457 tx_flags |= TX_CMD_FLG_TSF_MSK; 2408 tx_flags |= TX_CMD_FLG_TSF_MSK;
2458 } else { 2409 } else {
@@ -2461,20 +2412,21 @@ static void iwl3945_build_tx_cmd_basic(struct iwl3945_priv *priv,
2461 } 2412 }
2462 2413
2463 cmd->cmd.tx.sta_id = std_id; 2414 cmd->cmd.tx.sta_id = std_id;
2464 if (ieee80211_get_morefrag(hdr)) 2415 if (ieee80211_has_morefrags(fc))
2465 tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK; 2416 tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
2466 2417
2467 qc = ieee80211_get_qos_ctrl(hdr); 2418 if (ieee80211_is_data_qos(fc)) {
2468 if (qc) { 2419 u8 *qc = ieee80211_get_qos_ctl(hdr);
2469 cmd->cmd.tx.tid_tspec = (u8) (le16_to_cpu(*qc) & 0xf); 2420 cmd->cmd.tx.tid_tspec = qc[0] & 0xf;
2470 tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK; 2421 tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
2471 } else 2422 } else {
2472 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; 2423 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
2424 }
2473 2425
2474 if (ctrl->flags & IEEE80211_TXCTL_USE_RTS_CTS) { 2426 if (info->flags & IEEE80211_TX_CTL_USE_RTS_CTS) {
2475 tx_flags |= TX_CMD_FLG_RTS_MSK; 2427 tx_flags |= TX_CMD_FLG_RTS_MSK;
2476 tx_flags &= ~TX_CMD_FLG_CTS_MSK; 2428 tx_flags &= ~TX_CMD_FLG_CTS_MSK;
2477 } else if (ctrl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) { 2429 } else if (info->flags & IEEE80211_TX_CTL_USE_CTS_PROTECT) {
2478 tx_flags &= ~TX_CMD_FLG_RTS_MSK; 2430 tx_flags &= ~TX_CMD_FLG_RTS_MSK;
2479 tx_flags |= TX_CMD_FLG_CTS_MSK; 2431 tx_flags |= TX_CMD_FLG_CTS_MSK;
2480 } 2432 }
@@ -2483,9 +2435,8 @@ static void iwl3945_build_tx_cmd_basic(struct iwl3945_priv *priv,
2483 tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK; 2435 tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
2484 2436
2485 tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK); 2437 tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
2486 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) { 2438 if (ieee80211_is_mgmt(fc)) {
2487 if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ || 2439 if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc))
2488 (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ)
2489 cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(3); 2440 cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(3);
2490 else 2441 else
2491 cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(2); 2442 cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(2);
@@ -2518,11 +2469,11 @@ static int iwl3945_get_sta_id(struct iwl3945_priv *priv, struct ieee80211_hdr *h
2518 2469
2519 /* If we are a client station in a BSS network, use the special 2470 /* If we are a client station in a BSS network, use the special
2520 * AP station entry (that's the only station we communicate with) */ 2471 * AP station entry (that's the only station we communicate with) */
2521 case IEEE80211_IF_TYPE_STA: 2472 case NL80211_IFTYPE_STATION:
2522 return IWL_AP_ID; 2473 return IWL_AP_ID;
2523 2474
2524 /* If we are an AP, then find the station, or use BCAST */ 2475 /* If we are an AP, then find the station, or use BCAST */
2525 case IEEE80211_IF_TYPE_AP: 2476 case NL80211_IFTYPE_AP:
2526 sta_id = iwl3945_hw_find_station(priv, hdr->addr1); 2477 sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
2527 if (sta_id != IWL_INVALID_STATION) 2478 if (sta_id != IWL_INVALID_STATION)
2528 return sta_id; 2479 return sta_id;
@@ -2530,7 +2481,7 @@ static int iwl3945_get_sta_id(struct iwl3945_priv *priv, struct ieee80211_hdr *h
2530 2481
2531 /* If this frame is going out to an IBSS network, find the station, 2482 /* If this frame is going out to an IBSS network, find the station,
2532 * or create a new station table entry */ 2483 * or create a new station table entry */
2533 case IEEE80211_IF_TYPE_IBSS: { 2484 case NL80211_IFTYPE_ADHOC: {
2534 DECLARE_MAC_BUF(mac); 2485 DECLARE_MAC_BUF(mac);
2535 2486
2536 /* Create new station table entry */ 2487 /* Create new station table entry */
@@ -2549,8 +2500,13 @@ static int iwl3945_get_sta_id(struct iwl3945_priv *priv, struct ieee80211_hdr *h
2549 iwl3945_print_hex_dump(IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr)); 2500 iwl3945_print_hex_dump(IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
2550 return priv->hw_setting.bcast_sta_id; 2501 return priv->hw_setting.bcast_sta_id;
2551 } 2502 }
2503 /* If we are in monitor mode, use BCAST. This is required for
2504 * packet injection. */
2505 case NL80211_IFTYPE_MONITOR:
2506 return priv->hw_setting.bcast_sta_id;
2507
2552 default: 2508 default:
2553 IWL_WARNING("Unknown mode of operation: %d", priv->iw_mode); 2509 IWL_WARNING("Unknown mode of operation: %d\n", priv->iw_mode);
2554 return priv->hw_setting.bcast_sta_id; 2510 return priv->hw_setting.bcast_sta_id;
2555 } 2511 }
2556} 2512}
@@ -2558,25 +2514,27 @@ static int iwl3945_get_sta_id(struct iwl3945_priv *priv, struct ieee80211_hdr *h
2558/* 2514/*
2559 * start REPLY_TX command process 2515 * start REPLY_TX command process
2560 */ 2516 */
2561static int iwl3945_tx_skb(struct iwl3945_priv *priv, 2517static int iwl3945_tx_skb(struct iwl3945_priv *priv, struct sk_buff *skb)
2562 struct sk_buff *skb, struct ieee80211_tx_control *ctl)
2563{ 2518{
2564 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 2519 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2520 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2565 struct iwl3945_tfd_frame *tfd; 2521 struct iwl3945_tfd_frame *tfd;
2566 u32 *control_flags; 2522 u32 *control_flags;
2567 int txq_id = ctl->queue; 2523 int txq_id = skb_get_queue_mapping(skb);
2568 struct iwl3945_tx_queue *txq = NULL; 2524 struct iwl3945_tx_queue *txq = NULL;
2569 struct iwl3945_queue *q = NULL; 2525 struct iwl3945_queue *q = NULL;
2570 dma_addr_t phys_addr; 2526 dma_addr_t phys_addr;
2571 dma_addr_t txcmd_phys; 2527 dma_addr_t txcmd_phys;
2572 struct iwl3945_cmd *out_cmd = NULL; 2528 struct iwl3945_cmd *out_cmd = NULL;
2573 u16 len, idx, len_org; 2529 u16 len, idx, len_org, hdr_len;
2574 u8 id, hdr_len, unicast; 2530 u8 id;
2531 u8 unicast;
2575 u8 sta_id; 2532 u8 sta_id;
2533 u8 tid = 0;
2576 u16 seq_number = 0; 2534 u16 seq_number = 0;
2577 u16 fc; 2535 __le16 fc;
2578 __le16 *qc;
2579 u8 wait_write_ptr = 0; 2536 u8 wait_write_ptr = 0;
2537 u8 *qc = NULL;
2580 unsigned long flags; 2538 unsigned long flags;
2581 int rc; 2539 int rc;
2582 2540
@@ -2586,12 +2544,7 @@ static int iwl3945_tx_skb(struct iwl3945_priv *priv,
2586 goto drop_unlock; 2544 goto drop_unlock;
2587 } 2545 }
2588 2546
2589 if (!priv->vif) { 2547 if ((ieee80211_get_tx_rate(priv->hw, info)->hw_value & 0xFF) == IWL_INVALID_RATE) {
2590 IWL_DEBUG_DROP("Dropping - !priv->vif\n");
2591 goto drop_unlock;
2592 }
2593
2594 if ((ctl->tx_rate->hw_value & 0xFF) == IWL_INVALID_RATE) {
2595 IWL_ERROR("ERROR: No TX rate available.\n"); 2548 IWL_ERROR("ERROR: No TX rate available.\n");
2596 goto drop_unlock; 2549 goto drop_unlock;
2597 } 2550 }
@@ -2599,28 +2552,29 @@ static int iwl3945_tx_skb(struct iwl3945_priv *priv,
2599 unicast = !is_multicast_ether_addr(hdr->addr1); 2552 unicast = !is_multicast_ether_addr(hdr->addr1);
2600 id = 0; 2553 id = 0;
2601 2554
2602 fc = le16_to_cpu(hdr->frame_control); 2555 fc = hdr->frame_control;
2603 2556
2604#ifdef CONFIG_IWL3945_DEBUG 2557#ifdef CONFIG_IWL3945_DEBUG
2605 if (ieee80211_is_auth(fc)) 2558 if (ieee80211_is_auth(fc))
2606 IWL_DEBUG_TX("Sending AUTH frame\n"); 2559 IWL_DEBUG_TX("Sending AUTH frame\n");
2607 else if (ieee80211_is_assoc_request(fc)) 2560 else if (ieee80211_is_assoc_req(fc))
2608 IWL_DEBUG_TX("Sending ASSOC frame\n"); 2561 IWL_DEBUG_TX("Sending ASSOC frame\n");
2609 else if (ieee80211_is_reassoc_request(fc)) 2562 else if (ieee80211_is_reassoc_req(fc))
2610 IWL_DEBUG_TX("Sending REASSOC frame\n"); 2563 IWL_DEBUG_TX("Sending REASSOC frame\n");
2611#endif 2564#endif
2612 2565
2613 /* drop all data frame if we are not associated */ 2566 /* drop all data frame if we are not associated */
2614 if ((!iwl3945_is_associated(priv) || 2567 if (ieee80211_is_data(fc) &&
2615 ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && !priv->assoc_id)) && 2568 (priv->iw_mode != NL80211_IFTYPE_MONITOR) && /* packet injection */
2616 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)) { 2569 (!iwl3945_is_associated(priv) ||
2570 ((priv->iw_mode == NL80211_IFTYPE_STATION) && !priv->assoc_id))) {
2617 IWL_DEBUG_DROP("Dropping - !iwl3945_is_associated\n"); 2571 IWL_DEBUG_DROP("Dropping - !iwl3945_is_associated\n");
2618 goto drop_unlock; 2572 goto drop_unlock;
2619 } 2573 }
2620 2574
2621 spin_unlock_irqrestore(&priv->lock, flags); 2575 spin_unlock_irqrestore(&priv->lock, flags);
2622 2576
2623 hdr_len = ieee80211_get_hdrlen(fc); 2577 hdr_len = ieee80211_hdrlen(fc);
2624 2578
2625 /* Find (or create) index into station table for destination station */ 2579 /* Find (or create) index into station table for destination station */
2626 sta_id = iwl3945_get_sta_id(priv, hdr); 2580 sta_id = iwl3945_get_sta_id(priv, hdr);
@@ -2634,9 +2588,9 @@ static int iwl3945_tx_skb(struct iwl3945_priv *priv,
2634 2588
2635 IWL_DEBUG_RATE("station Id %d\n", sta_id); 2589 IWL_DEBUG_RATE("station Id %d\n", sta_id);
2636 2590
2637 qc = ieee80211_get_qos_ctrl(hdr); 2591 if (ieee80211_is_data_qos(fc)) {
2638 if (qc) { 2592 qc = ieee80211_get_qos_ctl(hdr);
2639 u8 tid = (u8)(le16_to_cpu(*qc) & 0xf); 2593 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
2640 seq_number = priv->stations[sta_id].tid[tid].seq_number & 2594 seq_number = priv->stations[sta_id].tid[tid].seq_number &
2641 IEEE80211_SCTL_SEQ; 2595 IEEE80211_SCTL_SEQ;
2642 hdr->seq_ctrl = cpu_to_le16(seq_number) | 2596 hdr->seq_ctrl = cpu_to_le16(seq_number) |
@@ -2660,8 +2614,6 @@ static int iwl3945_tx_skb(struct iwl3945_priv *priv,
2660 /* Set up driver data for this TFD */ 2614 /* Set up driver data for this TFD */
2661 memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl3945_tx_info)); 2615 memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl3945_tx_info));
2662 txq->txb[q->write_ptr].skb[0] = skb; 2616 txq->txb[q->write_ptr].skb[0] = skb;
2663 memcpy(&(txq->txb[q->write_ptr].status.control),
2664 ctl, sizeof(struct ieee80211_tx_control));
2665 2617
2666 /* Init first empty entry in queue's array of Tx/cmd buffers */ 2618 /* Init first empty entry in queue's array of Tx/cmd buffers */
2667 out_cmd = &txq->cmd[idx]; 2619 out_cmd = &txq->cmd[idx];
@@ -2710,8 +2662,8 @@ static int iwl3945_tx_skb(struct iwl3945_priv *priv,
2710 * first entry */ 2662 * first entry */
2711 iwl3945_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len); 2663 iwl3945_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len);
2712 2664
2713 if (!(ctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT)) 2665 if (info->control.hw_key)
2714 iwl3945_build_tx_cmd_hwcrypto(priv, ctl, out_cmd, skb, 0); 2666 iwl3945_build_tx_cmd_hwcrypto(priv, info, out_cmd, skb, 0);
2715 2667
2716 /* Set up TFD's 2nd entry to point directly to remainder of skb, 2668 /* Set up TFD's 2nd entry to point directly to remainder of skb,
2717 * if any (802.11 null frames have no payload). */ 2669 * if any (802.11 null frames have no payload). */
@@ -2736,20 +2688,18 @@ static int iwl3945_tx_skb(struct iwl3945_priv *priv,
2736 out_cmd->cmd.tx.len = cpu_to_le16(len); 2688 out_cmd->cmd.tx.len = cpu_to_le16(len);
2737 2689
2738 /* TODO need this for burst mode later on */ 2690 /* TODO need this for burst mode later on */
2739 iwl3945_build_tx_cmd_basic(priv, out_cmd, ctl, hdr, unicast, sta_id); 2691 iwl3945_build_tx_cmd_basic(priv, out_cmd, info, hdr, unicast, sta_id);
2740 2692
2741 /* set is_hcca to 0; it probably will never be implemented */ 2693 /* set is_hcca to 0; it probably will never be implemented */
2742 iwl3945_hw_build_tx_cmd_rate(priv, out_cmd, ctl, hdr, sta_id, 0); 2694 iwl3945_hw_build_tx_cmd_rate(priv, out_cmd, info, hdr, sta_id, 0);
2743 2695
2744 out_cmd->cmd.tx.tx_flags &= ~TX_CMD_FLG_ANT_A_MSK; 2696 out_cmd->cmd.tx.tx_flags &= ~TX_CMD_FLG_ANT_A_MSK;
2745 out_cmd->cmd.tx.tx_flags &= ~TX_CMD_FLG_ANT_B_MSK; 2697 out_cmd->cmd.tx.tx_flags &= ~TX_CMD_FLG_ANT_B_MSK;
2746 2698
2747 if (!ieee80211_get_morefrag(hdr)) { 2699 if (!ieee80211_has_morefrags(hdr->frame_control)) {
2748 txq->need_update = 1; 2700 txq->need_update = 1;
2749 if (qc) { 2701 if (qc)
2750 u8 tid = (u8)(le16_to_cpu(*qc) & 0xf);
2751 priv->stations[sta_id].tid[tid].seq_number = seq_number; 2702 priv->stations[sta_id].tid[tid].seq_number = seq_number;
2752 }
2753 } else { 2703 } else {
2754 wait_write_ptr = 1; 2704 wait_write_ptr = 1;
2755 txq->need_update = 0; 2705 txq->need_update = 0;
@@ -2759,7 +2709,7 @@ static int iwl3945_tx_skb(struct iwl3945_priv *priv,
2759 sizeof(out_cmd->cmd.tx)); 2709 sizeof(out_cmd->cmd.tx));
2760 2710
2761 iwl3945_print_hex_dump(IWL_DL_TX, (u8 *)out_cmd->cmd.tx.hdr, 2711 iwl3945_print_hex_dump(IWL_DL_TX, (u8 *)out_cmd->cmd.tx.hdr,
2762 ieee80211_get_hdrlen(fc)); 2712 ieee80211_hdrlen(fc));
2763 2713
2764 /* Tell device the write index *just past* this latest filled TFD */ 2714 /* Tell device the write index *just past* this latest filled TFD */
2765 q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd); 2715 q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
@@ -2778,7 +2728,7 @@ static int iwl3945_tx_skb(struct iwl3945_priv *priv,
2778 spin_unlock_irqrestore(&priv->lock, flags); 2728 spin_unlock_irqrestore(&priv->lock, flags);
2779 } 2729 }
2780 2730
2781 ieee80211_stop_queue(priv->hw, ctl->queue); 2731 ieee80211_stop_queue(priv->hw, skb_get_queue_mapping(skb));
2782 } 2732 }
2783 2733
2784 return 0; 2734 return 0;
@@ -2856,7 +2806,7 @@ static void iwl3945_radio_kill_sw(struct iwl3945_priv *priv, int disable_radio)
2856 if (disable_radio) { 2806 if (disable_radio) {
2857 iwl3945_scan_cancel(priv); 2807 iwl3945_scan_cancel(priv);
2858 /* FIXME: This is a workaround for AP */ 2808 /* FIXME: This is a workaround for AP */
2859 if (priv->iw_mode != IEEE80211_IF_TYPE_AP) { 2809 if (priv->iw_mode != NL80211_IFTYPE_AP) {
2860 spin_lock_irqsave(&priv->lock, flags); 2810 spin_lock_irqsave(&priv->lock, flags);
2861 iwl3945_write32(priv, CSR_UCODE_DRV_GP1_SET, 2811 iwl3945_write32(priv, CSR_UCODE_DRV_GP1_SET,
2862 CSR_UCODE_SW_BIT_RFKILL); 2812 CSR_UCODE_SW_BIT_RFKILL);
@@ -2888,7 +2838,8 @@ static void iwl3945_radio_kill_sw(struct iwl3945_priv *priv, int disable_radio)
2888 return; 2838 return;
2889 } 2839 }
2890 2840
2891 queue_work(priv->workqueue, &priv->restart); 2841 if (priv->is_open)
2842 queue_work(priv->workqueue, &priv->restart);
2892 return; 2843 return;
2893} 2844}
2894 2845
@@ -2924,72 +2875,6 @@ void iwl3945_set_decrypted_flag(struct iwl3945_priv *priv, struct sk_buff *skb,
2924 } 2875 }
2925} 2876}
2926 2877
2927#define IWL_PACKET_RETRY_TIME HZ
2928
2929int iwl3945_is_duplicate_packet(struct iwl3945_priv *priv, struct ieee80211_hdr *header)
2930{
2931 u16 sc = le16_to_cpu(header->seq_ctrl);
2932 u16 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
2933 u16 frag = sc & IEEE80211_SCTL_FRAG;
2934 u16 *last_seq, *last_frag;
2935 unsigned long *last_time;
2936
2937 switch (priv->iw_mode) {
2938 case IEEE80211_IF_TYPE_IBSS:{
2939 struct list_head *p;
2940 struct iwl3945_ibss_seq *entry = NULL;
2941 u8 *mac = header->addr2;
2942 int index = mac[5] & (IWL_IBSS_MAC_HASH_SIZE - 1);
2943
2944 __list_for_each(p, &priv->ibss_mac_hash[index]) {
2945 entry = list_entry(p, struct iwl3945_ibss_seq, list);
2946 if (!compare_ether_addr(entry->mac, mac))
2947 break;
2948 }
2949 if (p == &priv->ibss_mac_hash[index]) {
2950 entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
2951 if (!entry) {
2952 IWL_ERROR("Cannot malloc new mac entry\n");
2953 return 0;
2954 }
2955 memcpy(entry->mac, mac, ETH_ALEN);
2956 entry->seq_num = seq;
2957 entry->frag_num = frag;
2958 entry->packet_time = jiffies;
2959 list_add(&entry->list, &priv->ibss_mac_hash[index]);
2960 return 0;
2961 }
2962 last_seq = &entry->seq_num;
2963 last_frag = &entry->frag_num;
2964 last_time = &entry->packet_time;
2965 break;
2966 }
2967 case IEEE80211_IF_TYPE_STA:
2968 last_seq = &priv->last_seq_num;
2969 last_frag = &priv->last_frag_num;
2970 last_time = &priv->last_packet_time;
2971 break;
2972 default:
2973 return 0;
2974 }
2975 if ((*last_seq == seq) &&
2976 time_after(*last_time + IWL_PACKET_RETRY_TIME, jiffies)) {
2977 if (*last_frag == frag)
2978 goto drop;
2979 if (*last_frag + 1 != frag)
2980 /* out-of-order fragment */
2981 goto drop;
2982 } else
2983 *last_seq = seq;
2984
2985 *last_frag = frag;
2986 *last_time = jiffies;
2987 return 0;
2988
2989 drop:
2990 return 1;
2991}
2992
2993#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT 2878#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
2994 2879
2995#include "iwl-spectrum.h" 2880#include "iwl-spectrum.h"
@@ -3241,7 +3126,7 @@ static void iwl3945_bg_beacon_update(struct work_struct *work)
3241 struct sk_buff *beacon; 3126 struct sk_buff *beacon;
3242 3127
3243 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */ 3128 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
3244 beacon = ieee80211_beacon_get(priv->hw, priv->vif, NULL); 3129 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
3245 3130
3246 if (!beacon) { 3131 if (!beacon) {
3247 IWL_ERROR("update beacon failed\n"); 3132 IWL_ERROR("update beacon failed\n");
@@ -3276,7 +3161,7 @@ static void iwl3945_rx_beacon_notif(struct iwl3945_priv *priv,
3276 le32_to_cpu(beacon->low_tsf), rate); 3161 le32_to_cpu(beacon->low_tsf), rate);
3277#endif 3162#endif
3278 3163
3279 if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) && 3164 if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
3280 (!test_bit(STATUS_EXIT_PENDING, &priv->status))) 3165 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
3281 queue_work(priv->workqueue, &priv->beacon_update); 3166 queue_work(priv->workqueue, &priv->beacon_update);
3282} 3167}
@@ -3922,7 +3807,7 @@ int iwl3945_calc_db_from_ratio(int sig_ratio)
3922 /* 100:1 or higher, divide by 10 and use table, 3807 /* 100:1 or higher, divide by 10 and use table,
3923 * add 20 dB to make up for divide by 10 */ 3808 * add 20 dB to make up for divide by 10 */
3924 if (sig_ratio >= 100) 3809 if (sig_ratio >= 100)
3925 return (20 + (int)ratio2dB[sig_ratio/10]); 3810 return 20 + (int)ratio2dB[sig_ratio/10];
3926 3811
3927 /* We shouldn't see this */ 3812 /* We shouldn't see this */
3928 if (sig_ratio < 1) 3813 if (sig_ratio < 1)
@@ -4848,7 +4733,7 @@ static int iwl3945_init_channel_map(struct iwl3945_priv *priv)
4848 ch_info->scan_power = eeprom_ch_info[ch].max_power_avg; 4733 ch_info->scan_power = eeprom_ch_info[ch].max_power_avg;
4849 ch_info->min_power = 0; 4734 ch_info->min_power = 0;
4850 4735
4851 IWL_DEBUG_INFO("Ch. %d [%sGHz] %s%s%s%s%s%s%s(0x%02x" 4736 IWL_DEBUG_INFO("Ch. %d [%sGHz] %s%s%s%s%s%s(0x%02x"
4852 " %ddBm): Ad-Hoc %ssupported\n", 4737 " %ddBm): Ad-Hoc %ssupported\n",
4853 ch_info->channel, 4738 ch_info->channel,
4854 is_channel_a_band(ch_info) ? 4739 is_channel_a_band(ch_info) ?
@@ -4858,7 +4743,6 @@ static int iwl3945_init_channel_map(struct iwl3945_priv *priv)
4858 CHECK_AND_PRINT(ACTIVE), 4743 CHECK_AND_PRINT(ACTIVE),
4859 CHECK_AND_PRINT(RADAR), 4744 CHECK_AND_PRINT(RADAR),
4860 CHECK_AND_PRINT(WIDE), 4745 CHECK_AND_PRINT(WIDE),
4861 CHECK_AND_PRINT(NARROW),
4862 CHECK_AND_PRINT(DFS), 4746 CHECK_AND_PRINT(DFS),
4863 eeprom_ch_info[ch].flags, 4747 eeprom_ch_info[ch].flags,
4864 eeprom_ch_info[ch].max_power_avg, 4748 eeprom_ch_info[ch].max_power_avg,
@@ -4898,8 +4782,11 @@ static void iwl3945_free_channel_map(struct iwl3945_priv *priv)
4898/* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after 4782/* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after
4899 * sending probe req. This should be set long enough to hear probe responses 4783 * sending probe req. This should be set long enough to hear probe responses
4900 * from more than one AP. */ 4784 * from more than one AP. */
4901#define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */ 4785#define IWL_ACTIVE_DWELL_TIME_24 (30) /* all times in msec */
4902#define IWL_ACTIVE_DWELL_TIME_52 (10) 4786#define IWL_ACTIVE_DWELL_TIME_52 (20)
4787
4788#define IWL_ACTIVE_DWELL_FACTOR_24GHZ (3)
4789#define IWL_ACTIVE_DWELL_FACTOR_52GHZ (2)
4903 4790
4904/* For faster active scanning, scan will move to the next channel if fewer than 4791/* For faster active scanning, scan will move to the next channel if fewer than
4905 * PLCP_QUIET_THRESH packets are heard on this channel within 4792 * PLCP_QUIET_THRESH packets are heard on this channel within
@@ -4908,7 +4795,7 @@ static void iwl3945_free_channel_map(struct iwl3945_priv *priv)
4908 * no other traffic). 4795 * no other traffic).
4909 * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */ 4796 * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */
4910#define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */ 4797#define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */
4911#define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */ 4798#define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(10) /* msec */
4912 4799
4913/* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel. 4800/* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel.
4914 * Must be set longer than active dwell time. 4801 * Must be set longer than active dwell time.
@@ -4918,19 +4805,23 @@ static void iwl3945_free_channel_map(struct iwl3945_priv *priv)
4918#define IWL_PASSIVE_DWELL_BASE (100) 4805#define IWL_PASSIVE_DWELL_BASE (100)
4919#define IWL_CHANNEL_TUNE_TIME 5 4806#define IWL_CHANNEL_TUNE_TIME 5
4920 4807
4808#define IWL_SCAN_PROBE_MASK(n) cpu_to_le32((BIT(n) | (BIT(n) - BIT(1))))
4809
4921static inline u16 iwl3945_get_active_dwell_time(struct iwl3945_priv *priv, 4810static inline u16 iwl3945_get_active_dwell_time(struct iwl3945_priv *priv,
4922 enum ieee80211_band band) 4811 enum ieee80211_band band,
4812 u8 n_probes)
4923{ 4813{
4924 if (band == IEEE80211_BAND_5GHZ) 4814 if (band == IEEE80211_BAND_5GHZ)
4925 return IWL_ACTIVE_DWELL_TIME_52; 4815 return IWL_ACTIVE_DWELL_TIME_52 +
4816 IWL_ACTIVE_DWELL_FACTOR_52GHZ * (n_probes + 1);
4926 else 4817 else
4927 return IWL_ACTIVE_DWELL_TIME_24; 4818 return IWL_ACTIVE_DWELL_TIME_24 +
4819 IWL_ACTIVE_DWELL_FACTOR_24GHZ * (n_probes + 1);
4928} 4820}
4929 4821
4930static u16 iwl3945_get_passive_dwell_time(struct iwl3945_priv *priv, 4822static u16 iwl3945_get_passive_dwell_time(struct iwl3945_priv *priv,
4931 enum ieee80211_band band) 4823 enum ieee80211_band band)
4932{ 4824{
4933 u16 active = iwl3945_get_active_dwell_time(priv, band);
4934 u16 passive = (band == IEEE80211_BAND_2GHZ) ? 4825 u16 passive = (band == IEEE80211_BAND_2GHZ) ?
4935 IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 : 4826 IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 :
4936 IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52; 4827 IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52;
@@ -4945,15 +4836,12 @@ static u16 iwl3945_get_passive_dwell_time(struct iwl3945_priv *priv,
4945 passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2; 4836 passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2;
4946 } 4837 }
4947 4838
4948 if (passive <= active)
4949 passive = active + 1;
4950
4951 return passive; 4839 return passive;
4952} 4840}
4953 4841
4954static int iwl3945_get_channels_for_scan(struct iwl3945_priv *priv, 4842static int iwl3945_get_channels_for_scan(struct iwl3945_priv *priv,
4955 enum ieee80211_band band, 4843 enum ieee80211_band band,
4956 u8 is_active, u8 direct_mask, 4844 u8 is_active, u8 n_probes,
4957 struct iwl3945_scan_channel *scan_ch) 4845 struct iwl3945_scan_channel *scan_ch)
4958{ 4846{
4959 const struct ieee80211_channel *channels = NULL; 4847 const struct ieee80211_channel *channels = NULL;
@@ -4969,9 +4857,12 @@ static int iwl3945_get_channels_for_scan(struct iwl3945_priv *priv,
4969 4857
4970 channels = sband->channels; 4858 channels = sband->channels;
4971 4859
4972 active_dwell = iwl3945_get_active_dwell_time(priv, band); 4860 active_dwell = iwl3945_get_active_dwell_time(priv, band, n_probes);
4973 passive_dwell = iwl3945_get_passive_dwell_time(priv, band); 4861 passive_dwell = iwl3945_get_passive_dwell_time(priv, band);
4974 4862
4863 if (passive_dwell <= active_dwell)
4864 passive_dwell = active_dwell + 1;
4865
4975 for (i = 0, added = 0; i < sband->n_channels; i++) { 4866 for (i = 0, added = 0; i < sband->n_channels; i++) {
4976 if (channels[i].flags & IEEE80211_CHAN_DISABLED) 4867 if (channels[i].flags & IEEE80211_CHAN_DISABLED)
4977 continue; 4868 continue;
@@ -4991,11 +4882,8 @@ static int iwl3945_get_channels_for_scan(struct iwl3945_priv *priv,
4991 else 4882 else
4992 scan_ch->type = 1; /* active */ 4883 scan_ch->type = 1; /* active */
4993 4884
4994 if (scan_ch->type & 1) 4885 if ((scan_ch->type & 1) && n_probes)
4995 scan_ch->type |= (direct_mask << 1); 4886 scan_ch->type |= IWL_SCAN_PROBE_MASK(n_probes);
4996
4997 if (is_channel_narrow(ch_info))
4998 scan_ch->type |= (1 << 7);
4999 4887
5000 scan_ch->active_dwell = cpu_to_le16(active_dwell); 4888 scan_ch->active_dwell = cpu_to_le16(active_dwell);
5001 scan_ch->passive_dwell = cpu_to_le16(passive_dwell); 4889 scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
@@ -5201,7 +5089,7 @@ static void iwl3945_dealloc_ucode_pci(struct iwl3945_priv *priv)
5201 * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host, 5089 * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host,
5202 * looking at all data. 5090 * looking at all data.
5203 */ 5091 */
5204static int iwl3945_verify_inst_full(struct iwl3945_priv *priv, __le32 * image, u32 len) 5092static int iwl3945_verify_inst_full(struct iwl3945_priv *priv, __le32 *image, u32 len)
5205{ 5093{
5206 u32 val; 5094 u32 val;
5207 u32 save_len = len; 5095 u32 save_len = len;
@@ -5350,7 +5238,7 @@ static int iwl3945_verify_bsm(struct iwl3945_priv *priv)
5350 val = iwl3945_read_prph(priv, BSM_WR_DWCOUNT_REG); 5238 val = iwl3945_read_prph(priv, BSM_WR_DWCOUNT_REG);
5351 for (reg = BSM_SRAM_LOWER_BOUND; 5239 for (reg = BSM_SRAM_LOWER_BOUND;
5352 reg < BSM_SRAM_LOWER_BOUND + len; 5240 reg < BSM_SRAM_LOWER_BOUND + len;
5353 reg += sizeof(u32), image ++) { 5241 reg += sizeof(u32), image++) {
5354 val = iwl3945_read_prph(priv, reg); 5242 val = iwl3945_read_prph(priv, reg);
5355 if (val != le32_to_cpu(*image)) { 5243 if (val != le32_to_cpu(*image)) {
5356 IWL_ERROR("BSM uCode verification failed at " 5244 IWL_ERROR("BSM uCode verification failed at "
@@ -5843,7 +5731,7 @@ static void iwl3945_alive_start(struct iwl3945_priv *priv)
5843 if (iwl3945_is_rfkill(priv)) 5731 if (iwl3945_is_rfkill(priv))
5844 return; 5732 return;
5845 5733
5846 ieee80211_start_queues(priv->hw); 5734 ieee80211_wake_queues(priv->hw);
5847 5735
5848 priv->active_rate = priv->rates_mask; 5736 priv->active_rate = priv->rates_mask;
5849 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK; 5737 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
@@ -5869,9 +5757,6 @@ static void iwl3945_alive_start(struct iwl3945_priv *priv)
5869 /* Configure the adapter for unassociated operation */ 5757 /* Configure the adapter for unassociated operation */
5870 iwl3945_commit_rxon(priv); 5758 iwl3945_commit_rxon(priv);
5871 5759
5872 /* At this point, the NIC is initialized and operational */
5873 priv->notif_missed_beacons = 0;
5874
5875 iwl3945_reg_txpower_periodic(priv); 5760 iwl3945_reg_txpower_periodic(priv);
5876 5761
5877 iwl3945_led_register(priv); 5762 iwl3945_led_register(priv);
@@ -5938,7 +5823,9 @@ static void __iwl3945_down(struct iwl3945_priv *priv)
5938 test_bit(STATUS_GEO_CONFIGURED, &priv->status) << 5823 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
5939 STATUS_GEO_CONFIGURED | 5824 STATUS_GEO_CONFIGURED |
5940 test_bit(STATUS_IN_SUSPEND, &priv->status) << 5825 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
5941 STATUS_IN_SUSPEND; 5826 STATUS_IN_SUSPEND |
5827 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
5828 STATUS_EXIT_PENDING;
5942 goto exit; 5829 goto exit;
5943 } 5830 }
5944 5831
@@ -5953,7 +5840,9 @@ static void __iwl3945_down(struct iwl3945_priv *priv)
5953 test_bit(STATUS_IN_SUSPEND, &priv->status) << 5840 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
5954 STATUS_IN_SUSPEND | 5841 STATUS_IN_SUSPEND |
5955 test_bit(STATUS_FW_ERROR, &priv->status) << 5842 test_bit(STATUS_FW_ERROR, &priv->status) <<
5956 STATUS_FW_ERROR; 5843 STATUS_FW_ERROR |
5844 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
5845 STATUS_EXIT_PENDING;
5957 5846
5958 spin_lock_irqsave(&priv->lock, flags); 5847 spin_lock_irqsave(&priv->lock, flags);
5959 iwl3945_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); 5848 iwl3945_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
@@ -6085,6 +5974,7 @@ static int __iwl3945_up(struct iwl3945_priv *priv)
6085 5974
6086 set_bit(STATUS_EXIT_PENDING, &priv->status); 5975 set_bit(STATUS_EXIT_PENDING, &priv->status);
6087 __iwl3945_down(priv); 5976 __iwl3945_down(priv);
5977 clear_bit(STATUS_EXIT_PENDING, &priv->status);
6088 5978
6089 /* tried to restart and config the device for as long as our 5979 /* tried to restart and config the device for as long as our
6090 * patience could withstand */ 5980 * patience could withstand */
@@ -6152,6 +6042,26 @@ static void iwl3945_bg_rf_kill(struct work_struct *work)
6152 "Kill switch must be turned off for " 6042 "Kill switch must be turned off for "
6153 "wireless networking to work.\n"); 6043 "wireless networking to work.\n");
6154 } 6044 }
6045
6046 mutex_unlock(&priv->mutex);
6047 iwl3945_rfkill_set_hw_state(priv);
6048}
6049
6050static void iwl3945_bg_set_monitor(struct work_struct *work)
6051{
6052 struct iwl3945_priv *priv = container_of(work,
6053 struct iwl3945_priv, set_monitor);
6054
6055 IWL_DEBUG(IWL_DL_STATE, "setting monitor mode\n");
6056
6057 mutex_lock(&priv->mutex);
6058
6059 if (!iwl3945_is_ready(priv))
6060 IWL_DEBUG(IWL_DL_STATE, "leave - not ready\n");
6061 else
6062 if (iwl3945_set_mode(priv, NL80211_IFTYPE_MONITOR) != 0)
6063 IWL_ERROR("iwl3945_set_mode() failed\n");
6064
6155 mutex_unlock(&priv->mutex); 6065 mutex_unlock(&priv->mutex);
6156} 6066}
6157 6067
@@ -6190,7 +6100,7 @@ static void iwl3945_bg_request_scan(struct work_struct *data)
6190 int rc = 0; 6100 int rc = 0;
6191 struct iwl3945_scan_cmd *scan; 6101 struct iwl3945_scan_cmd *scan;
6192 struct ieee80211_conf *conf = NULL; 6102 struct ieee80211_conf *conf = NULL;
6193 u8 direct_mask; 6103 u8 n_probes = 2;
6194 enum ieee80211_band band; 6104 enum ieee80211_band band;
6195 6105
6196 conf = ieee80211_get_hw_conf(priv->hw); 6106 conf = ieee80211_get_hw_conf(priv->hw);
@@ -6298,7 +6208,7 @@ static void iwl3945_bg_request_scan(struct work_struct *data)
6298 scan->direct_scan[0].len = priv->direct_ssid_len; 6208 scan->direct_scan[0].len = priv->direct_ssid_len;
6299 memcpy(scan->direct_scan[0].ssid, 6209 memcpy(scan->direct_scan[0].ssid,
6300 priv->direct_ssid, priv->direct_ssid_len); 6210 priv->direct_ssid, priv->direct_ssid_len);
6301 direct_mask = 1; 6211 n_probes++;
6302 } else if (!iwl3945_is_associated(priv) && priv->essid_len) { 6212 } else if (!iwl3945_is_associated(priv) && priv->essid_len) {
6303 IWL_DEBUG_SCAN 6213 IWL_DEBUG_SCAN
6304 ("Kicking off one direct scan for '%s' when not associated\n", 6214 ("Kicking off one direct scan for '%s' when not associated\n",
@@ -6306,11 +6216,9 @@ static void iwl3945_bg_request_scan(struct work_struct *data)
6306 scan->direct_scan[0].id = WLAN_EID_SSID; 6216 scan->direct_scan[0].id = WLAN_EID_SSID;
6307 scan->direct_scan[0].len = priv->essid_len; 6217 scan->direct_scan[0].len = priv->essid_len;
6308 memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len); 6218 memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len);
6309 direct_mask = 1; 6219 n_probes++;
6310 } else { 6220 } else
6311 IWL_DEBUG_SCAN("Kicking off one indirect scan.\n"); 6221 IWL_DEBUG_SCAN("Kicking off one indirect scan.\n");
6312 direct_mask = 0;
6313 }
6314 6222
6315 /* We don't build a direct scan probe request; the uCode will do 6223 /* We don't build a direct scan probe request; the uCode will do
6316 * that based on the direct_mask added to each channel entry */ 6224 * that based on the direct_mask added to each channel entry */
@@ -6340,21 +6248,13 @@ static void iwl3945_bg_request_scan(struct work_struct *data)
6340 /* select Rx antennas */ 6248 /* select Rx antennas */
6341 scan->flags |= iwl3945_get_antenna_flags(priv); 6249 scan->flags |= iwl3945_get_antenna_flags(priv);
6342 6250
6343 if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) 6251 if (priv->iw_mode == NL80211_IFTYPE_MONITOR)
6344 scan->filter_flags = RXON_FILTER_PROMISC_MSK; 6252 scan->filter_flags = RXON_FILTER_PROMISC_MSK;
6345 6253
6346 if (direct_mask) 6254 scan->channel_count =
6347 scan->channel_count = 6255 iwl3945_get_channels_for_scan(priv, band, 1, /* active */
6348 iwl3945_get_channels_for_scan( 6256 n_probes,
6349 priv, band, 1, /* active */ 6257 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
6350 direct_mask,
6351 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
6352 else
6353 scan->channel_count =
6354 iwl3945_get_channels_for_scan(
6355 priv, band, 0, /* passive */
6356 direct_mask,
6357 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
6358 6258
6359 cmd.len += le16_to_cpu(scan->tx_cmd.len) + 6259 cmd.len += le16_to_cpu(scan->tx_cmd.len) +
6360 scan->channel_count * sizeof(struct iwl3945_scan_channel); 6260 scan->channel_count * sizeof(struct iwl3945_scan_channel);
@@ -6388,6 +6288,7 @@ static void iwl3945_bg_up(struct work_struct *data)
6388 mutex_lock(&priv->mutex); 6288 mutex_lock(&priv->mutex);
6389 __iwl3945_up(priv); 6289 __iwl3945_up(priv);
6390 mutex_unlock(&priv->mutex); 6290 mutex_unlock(&priv->mutex);
6291 iwl3945_rfkill_set_hw_state(priv);
6391} 6292}
6392 6293
6393static void iwl3945_bg_restart(struct work_struct *data) 6294static void iwl3945_bg_restart(struct work_struct *data)
@@ -6416,17 +6317,14 @@ static void iwl3945_bg_rx_replenish(struct work_struct *data)
6416 6317
6417#define IWL_DELAY_NEXT_SCAN (HZ*2) 6318#define IWL_DELAY_NEXT_SCAN (HZ*2)
6418 6319
6419static void iwl3945_bg_post_associate(struct work_struct *data) 6320static void iwl3945_post_associate(struct iwl3945_priv *priv)
6420{ 6321{
6421 struct iwl3945_priv *priv = container_of(data, struct iwl3945_priv,
6422 post_associate.work);
6423
6424 int rc = 0; 6322 int rc = 0;
6425 struct ieee80211_conf *conf = NULL; 6323 struct ieee80211_conf *conf = NULL;
6426 DECLARE_MAC_BUF(mac); 6324 DECLARE_MAC_BUF(mac);
6427 6325
6428 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { 6326 if (priv->iw_mode == NL80211_IFTYPE_AP) {
6429 IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__); 6327 IWL_ERROR("%s Should not be called in AP mode\n", __func__);
6430 return; 6328 return;
6431 } 6329 }
6432 6330
@@ -6438,12 +6336,9 @@ static void iwl3945_bg_post_associate(struct work_struct *data)
6438 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) 6336 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6439 return; 6337 return;
6440 6338
6441 mutex_lock(&priv->mutex); 6339 if (!priv->vif || !priv->is_open)
6442
6443 if (!priv->vif || !priv->is_open) {
6444 mutex_unlock(&priv->mutex);
6445 return; 6340 return;
6446 } 6341
6447 iwl3945_scan_cancel_timeout(priv, 200); 6342 iwl3945_scan_cancel_timeout(priv, 200);
6448 6343
6449 conf = ieee80211_get_hw_conf(priv->hw); 6344 conf = ieee80211_get_hw_conf(priv->hw);
@@ -6477,7 +6372,7 @@ static void iwl3945_bg_post_associate(struct work_struct *data)
6477 else 6372 else
6478 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; 6373 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
6479 6374
6480 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) 6375 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
6481 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; 6376 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
6482 6377
6483 } 6378 }
@@ -6485,11 +6380,11 @@ static void iwl3945_bg_post_associate(struct work_struct *data)
6485 iwl3945_commit_rxon(priv); 6380 iwl3945_commit_rxon(priv);
6486 6381
6487 switch (priv->iw_mode) { 6382 switch (priv->iw_mode) {
6488 case IEEE80211_IF_TYPE_STA: 6383 case NL80211_IFTYPE_STATION:
6489 iwl3945_rate_scale_init(priv->hw, IWL_AP_ID); 6384 iwl3945_rate_scale_init(priv->hw, IWL_AP_ID);
6490 break; 6385 break;
6491 6386
6492 case IEEE80211_IF_TYPE_IBSS: 6387 case NL80211_IFTYPE_ADHOC:
6493 6388
6494 /* clear out the station table */ 6389 /* clear out the station table */
6495 iwl3945_clear_stations_table(priv); 6390 iwl3945_clear_stations_table(priv);
@@ -6507,17 +6402,14 @@ static void iwl3945_bg_post_associate(struct work_struct *data)
6507 6402
6508 default: 6403 default:
6509 IWL_ERROR("%s Should not be called in %d mode\n", 6404 IWL_ERROR("%s Should not be called in %d mode\n",
6510 __FUNCTION__, priv->iw_mode); 6405 __func__, priv->iw_mode);
6511 break; 6406 break;
6512 } 6407 }
6513 6408
6514 iwl3945_sequence_reset(priv);
6515
6516 iwl3945_activate_qos(priv, 0); 6409 iwl3945_activate_qos(priv, 0);
6517 6410
6518 /* we have just associated, don't start scan too early */ 6411 /* we have just associated, don't start scan too early */
6519 priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN; 6412 priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
6520 mutex_unlock(&priv->mutex);
6521} 6413}
6522 6414
6523static void iwl3945_bg_abort_scan(struct work_struct *work) 6415static void iwl3945_bg_abort_scan(struct work_struct *work)
@@ -6608,6 +6500,8 @@ static int iwl3945_mac_start(struct ieee80211_hw *hw)
6608 6500
6609 mutex_unlock(&priv->mutex); 6501 mutex_unlock(&priv->mutex);
6610 6502
6503 iwl3945_rfkill_set_hw_state(priv);
6504
6611 if (ret) 6505 if (ret)
6612 goto out_release_irq; 6506 goto out_release_irq;
6613 6507
@@ -6663,7 +6557,6 @@ static void iwl3945_mac_stop(struct ieee80211_hw *hw)
6663 */ 6557 */
6664 mutex_lock(&priv->mutex); 6558 mutex_lock(&priv->mutex);
6665 iwl3945_scan_cancel_timeout(priv, 100); 6559 iwl3945_scan_cancel_timeout(priv, 100);
6666 cancel_delayed_work(&priv->post_associate);
6667 mutex_unlock(&priv->mutex); 6560 mutex_unlock(&priv->mutex);
6668 } 6561 }
6669 6562
@@ -6678,23 +6571,16 @@ static void iwl3945_mac_stop(struct ieee80211_hw *hw)
6678 IWL_DEBUG_MAC80211("leave\n"); 6571 IWL_DEBUG_MAC80211("leave\n");
6679} 6572}
6680 6573
6681static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb, 6574static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
6682 struct ieee80211_tx_control *ctl)
6683{ 6575{
6684 struct iwl3945_priv *priv = hw->priv; 6576 struct iwl3945_priv *priv = hw->priv;
6685 6577
6686 IWL_DEBUG_MAC80211("enter\n"); 6578 IWL_DEBUG_MAC80211("enter\n");
6687 6579
6688 if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) {
6689 IWL_DEBUG_MAC80211("leave - monitor\n");
6690 dev_kfree_skb_any(skb);
6691 return 0;
6692 }
6693
6694 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len, 6580 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
6695 ctl->tx_rate->bitrate); 6581 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
6696 6582
6697 if (iwl3945_tx_skb(priv, skb, ctl)) 6583 if (iwl3945_tx_skb(priv, skb))
6698 dev_kfree_skb_any(skb); 6584 dev_kfree_skb_any(skb);
6699 6585
6700 IWL_DEBUG_MAC80211("leave\n"); 6586 IWL_DEBUG_MAC80211("leave\n");
@@ -6753,8 +6639,6 @@ static int iwl3945_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *co
6753 mutex_lock(&priv->mutex); 6639 mutex_lock(&priv->mutex);
6754 IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value); 6640 IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value);
6755 6641
6756 priv->add_radiotap = !!(conf->flags & IEEE80211_CONF_RADIOTAP);
6757
6758 if (!iwl3945_is_ready(priv)) { 6642 if (!iwl3945_is_ready(priv)) {
6759 IWL_DEBUG_MAC80211("leave - not ready\n"); 6643 IWL_DEBUG_MAC80211("leave - not ready\n");
6760 ret = -EIO; 6644 ret = -EIO;
@@ -6837,7 +6721,7 @@ static void iwl3945_config_ap(struct iwl3945_priv *priv)
6837 return; 6721 return;
6838 6722
6839 /* The following should be done only at AP bring up */ 6723 /* The following should be done only at AP bring up */
6840 if ((priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) == 0) { 6724 if (!(iwl3945_is_associated(priv))) {
6841 6725
6842 /* RXON - unassoc (to set timing command) */ 6726 /* RXON - unassoc (to set timing command) */
6843 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; 6727 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
@@ -6870,7 +6754,7 @@ static void iwl3945_config_ap(struct iwl3945_priv *priv)
6870 priv->staging_rxon.flags &= 6754 priv->staging_rxon.flags &=
6871 ~RXON_FLG_SHORT_SLOT_MSK; 6755 ~RXON_FLG_SHORT_SLOT_MSK;
6872 6756
6873 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) 6757 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
6874 priv->staging_rxon.flags &= 6758 priv->staging_rxon.flags &=
6875 ~RXON_FLG_SHORT_SLOT_MSK; 6759 ~RXON_FLG_SHORT_SLOT_MSK;
6876 } 6760 }
@@ -6886,6 +6770,9 @@ static void iwl3945_config_ap(struct iwl3945_priv *priv)
6886 * clear sta table, add BCAST sta... */ 6770 * clear sta table, add BCAST sta... */
6887} 6771}
6888 6772
6773/* temporary */
6774static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb);
6775
6889static int iwl3945_mac_config_interface(struct ieee80211_hw *hw, 6776static int iwl3945_mac_config_interface(struct ieee80211_hw *hw,
6890 struct ieee80211_vif *vif, 6777 struct ieee80211_vif *vif,
6891 struct ieee80211_if_conf *conf) 6778 struct ieee80211_if_conf *conf)
@@ -6903,10 +6790,21 @@ static int iwl3945_mac_config_interface(struct ieee80211_hw *hw,
6903 return 0; 6790 return 0;
6904 } 6791 }
6905 6792
6793 /* handle this temporarily here */
6794 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
6795 conf->changed & IEEE80211_IFCC_BEACON) {
6796 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
6797 if (!beacon)
6798 return -ENOMEM;
6799 rc = iwl3945_mac_beacon_update(hw, beacon);
6800 if (rc)
6801 return rc;
6802 }
6803
6906 /* XXX: this MUST use conf->mac_addr */ 6804 /* XXX: this MUST use conf->mac_addr */
6907 6805
6908 if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) && 6806 if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
6909 (!conf->beacon || !conf->ssid_len)) { 6807 (!conf->ssid_len)) {
6910 IWL_DEBUG_MAC80211 6808 IWL_DEBUG_MAC80211
6911 ("Leaving in AP mode because HostAPD is not ready.\n"); 6809 ("Leaving in AP mode because HostAPD is not ready.\n");
6912 return 0; 6810 return 0;
@@ -6928,7 +6826,7 @@ static int iwl3945_mac_config_interface(struct ieee80211_hw *hw,
6928 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) { 6826 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
6929 */ 6827 */
6930 6828
6931 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { 6829 if (priv->iw_mode == NL80211_IFTYPE_AP) {
6932 if (!conf->bssid) { 6830 if (!conf->bssid) {
6933 conf->bssid = priv->mac_addr; 6831 conf->bssid = priv->mac_addr;
6934 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN); 6832 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
@@ -6938,7 +6836,7 @@ static int iwl3945_mac_config_interface(struct ieee80211_hw *hw,
6938 if (priv->ibss_beacon) 6836 if (priv->ibss_beacon)
6939 dev_kfree_skb(priv->ibss_beacon); 6837 dev_kfree_skb(priv->ibss_beacon);
6940 6838
6941 priv->ibss_beacon = conf->beacon; 6839 priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
6942 } 6840 }
6943 6841
6944 if (iwl3945_is_rfkill(priv)) 6842 if (iwl3945_is_rfkill(priv))
@@ -6963,11 +6861,11 @@ static int iwl3945_mac_config_interface(struct ieee80211_hw *hw,
6963 * to verify) - jpk */ 6861 * to verify) - jpk */
6964 memcpy(priv->bssid, conf->bssid, ETH_ALEN); 6862 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
6965 6863
6966 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) 6864 if (priv->iw_mode == NL80211_IFTYPE_AP)
6967 iwl3945_config_ap(priv); 6865 iwl3945_config_ap(priv);
6968 else { 6866 else {
6969 rc = iwl3945_commit_rxon(priv); 6867 rc = iwl3945_commit_rxon(priv);
6970 if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc) 6868 if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc)
6971 iwl3945_add_station(priv, 6869 iwl3945_add_station(priv,
6972 priv->active_rxon.bssid_addr, 1, 0); 6870 priv->active_rxon.bssid_addr, 1, 0);
6973 } 6871 }
@@ -6999,11 +6897,18 @@ static void iwl3945_configure_filter(struct ieee80211_hw *hw,
6999 unsigned int *total_flags, 6897 unsigned int *total_flags,
7000 int mc_count, struct dev_addr_list *mc_list) 6898 int mc_count, struct dev_addr_list *mc_list)
7001{ 6899{
7002 /* 6900 struct iwl3945_priv *priv = hw->priv;
7003 * XXX: dummy 6901
7004 * see also iwl3945_connection_init_rx_config 6902 if (changed_flags & (*total_flags) & FIF_OTHER_BSS) {
7005 */ 6903 IWL_DEBUG_MAC80211("Enter: type %d (0x%x, 0x%x)\n",
7006 *total_flags = 0; 6904 NL80211_IFTYPE_MONITOR,
6905 changed_flags, *total_flags);
6906 /* queue work 'cuz mac80211 is holding a lock which
6907 * prevents us from issuing (synchronous) f/w cmds */
6908 queue_work(priv->workqueue, &priv->set_monitor);
6909 }
6910 *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI |
6911 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
7007} 6912}
7008 6913
7009static void iwl3945_mac_remove_interface(struct ieee80211_hw *hw, 6914static void iwl3945_mac_remove_interface(struct ieee80211_hw *hw,
@@ -7017,7 +6922,6 @@ static void iwl3945_mac_remove_interface(struct ieee80211_hw *hw,
7017 6922
7018 if (iwl3945_is_ready_rf(priv)) { 6923 if (iwl3945_is_ready_rf(priv)) {
7019 iwl3945_scan_cancel_timeout(priv, 100); 6924 iwl3945_scan_cancel_timeout(priv, 100);
7020 cancel_delayed_work(&priv->post_associate);
7021 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; 6925 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
7022 iwl3945_commit_rxon(priv); 6926 iwl3945_commit_rxon(priv);
7023 } 6927 }
@@ -7032,6 +6936,63 @@ static void iwl3945_mac_remove_interface(struct ieee80211_hw *hw,
7032 IWL_DEBUG_MAC80211("leave\n"); 6936 IWL_DEBUG_MAC80211("leave\n");
7033} 6937}
7034 6938
6939#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
6940
6941static void iwl3945_bss_info_changed(struct ieee80211_hw *hw,
6942 struct ieee80211_vif *vif,
6943 struct ieee80211_bss_conf *bss_conf,
6944 u32 changes)
6945{
6946 struct iwl3945_priv *priv = hw->priv;
6947
6948 IWL_DEBUG_MAC80211("changes = 0x%X\n", changes);
6949
6950 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
6951 IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n",
6952 bss_conf->use_short_preamble);
6953 if (bss_conf->use_short_preamble)
6954 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
6955 else
6956 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
6957 }
6958
6959 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
6960 IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf->use_cts_prot);
6961 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
6962 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
6963 else
6964 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
6965 }
6966
6967 if (changes & BSS_CHANGED_ASSOC) {
6968 IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf->assoc);
6969 /* This should never happen as this function should
6970 * never be called from interrupt context. */
6971 if (WARN_ON_ONCE(in_interrupt()))
6972 return;
6973 if (bss_conf->assoc) {
6974 priv->assoc_id = bss_conf->aid;
6975 priv->beacon_int = bss_conf->beacon_int;
6976 priv->timestamp0 = bss_conf->timestamp & 0xFFFFFFFF;
6977 priv->timestamp1 = (bss_conf->timestamp >> 32) &
6978 0xFFFFFFFF;
6979 priv->assoc_capability = bss_conf->assoc_capability;
6980 priv->next_scan_jiffies = jiffies +
6981 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
6982 mutex_lock(&priv->mutex);
6983 iwl3945_post_associate(priv);
6984 mutex_unlock(&priv->mutex);
6985 } else {
6986 priv->assoc_id = 0;
6987 IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf->assoc);
6988 }
6989 } else if (changes && iwl3945_is_associated(priv) && priv->assoc_id) {
6990 IWL_DEBUG_MAC80211("Associated Changes %d\n", changes);
6991 iwl3945_send_rxon_assoc(priv);
6992 }
6993
6994}
6995
7035static int iwl3945_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len) 6996static int iwl3945_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len)
7036{ 6997{
7037 int rc = 0; 6998 int rc = 0;
@@ -7049,7 +7010,7 @@ static int iwl3945_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len)
7049 goto out_unlock; 7010 goto out_unlock;
7050 } 7011 }
7051 7012
7052 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { /* APs don't scan */ 7013 if (priv->iw_mode == NL80211_IFTYPE_AP) { /* APs don't scan */
7053 rc = -EIO; 7014 rc = -EIO;
7054 IWL_ERROR("ERROR: APs don't scan\n"); 7015 IWL_ERROR("ERROR: APs don't scan\n");
7055 goto out_unlock; 7016 goto out_unlock;
@@ -7061,9 +7022,10 @@ static int iwl3945_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len)
7061 rc = -EAGAIN; 7022 rc = -EAGAIN;
7062 goto out_unlock; 7023 goto out_unlock;
7063 } 7024 }
7064 /* if we just finished scan ask for delay */ 7025 /* if we just finished scan ask for delay for a broadcast scan */
7065 if (priv->last_scan_jiffies && time_after(priv->last_scan_jiffies + 7026 if ((len == 0) && priv->last_scan_jiffies &&
7066 IWL_DELAY_NEXT_SCAN, jiffies)) { 7027 time_after(priv->last_scan_jiffies + IWL_DELAY_NEXT_SCAN,
7028 jiffies)) {
7067 rc = -EAGAIN; 7029 rc = -EAGAIN;
7068 goto out_unlock; 7030 goto out_unlock;
7069 } 7031 }
@@ -7150,7 +7112,7 @@ static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
7150 return rc; 7112 return rc;
7151} 7113}
7152 7114
7153static int iwl3945_mac_conf_tx(struct ieee80211_hw *hw, int queue, 7115static int iwl3945_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
7154 const struct ieee80211_tx_queue_params *params) 7116 const struct ieee80211_tx_queue_params *params)
7155{ 7117{
7156 struct iwl3945_priv *priv = hw->priv; 7118 struct iwl3945_priv *priv = hw->priv;
@@ -7190,7 +7152,7 @@ static int iwl3945_mac_conf_tx(struct ieee80211_hw *hw, int queue,
7190 spin_unlock_irqrestore(&priv->lock, flags); 7152 spin_unlock_irqrestore(&priv->lock, flags);
7191 7153
7192 mutex_lock(&priv->mutex); 7154 mutex_lock(&priv->mutex);
7193 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) 7155 if (priv->iw_mode == NL80211_IFTYPE_AP)
7194 iwl3945_activate_qos(priv, 1); 7156 iwl3945_activate_qos(priv, 1);
7195 else if (priv->assoc_id && iwl3945_is_associated(priv)) 7157 else if (priv->assoc_id && iwl3945_is_associated(priv))
7196 iwl3945_activate_qos(priv, 0); 7158 iwl3945_activate_qos(priv, 0);
@@ -7224,9 +7186,9 @@ static int iwl3945_mac_get_tx_stats(struct ieee80211_hw *hw,
7224 q = &txq->q; 7186 q = &txq->q;
7225 avail = iwl3945_queue_space(q); 7187 avail = iwl3945_queue_space(q);
7226 7188
7227 stats->data[i].len = q->n_window - avail; 7189 stats[i].len = q->n_window - avail;
7228 stats->data[i].limit = q->n_window - q->high_mark; 7190 stats[i].limit = q->n_window - q->high_mark;
7229 stats->data[i].count = q->n_window; 7191 stats[i].count = q->n_window;
7230 7192
7231 } 7193 }
7232 spin_unlock_irqrestore(&priv->lock, flags); 7194 spin_unlock_irqrestore(&priv->lock, flags);
@@ -7263,8 +7225,6 @@ static void iwl3945_mac_reset_tsf(struct ieee80211_hw *hw)
7263 7225
7264 iwl3945_reset_qos(priv); 7226 iwl3945_reset_qos(priv);
7265 7227
7266 cancel_delayed_work(&priv->post_associate);
7267
7268 spin_lock_irqsave(&priv->lock, flags); 7228 spin_lock_irqsave(&priv->lock, flags);
7269 priv->assoc_id = 0; 7229 priv->assoc_id = 0;
7270 priv->assoc_capability = 0; 7230 priv->assoc_capability = 0;
@@ -7279,7 +7239,7 @@ static void iwl3945_mac_reset_tsf(struct ieee80211_hw *hw)
7279 priv->beacon_int = priv->hw->conf.beacon_int; 7239 priv->beacon_int = priv->hw->conf.beacon_int;
7280 priv->timestamp1 = 0; 7240 priv->timestamp1 = 0;
7281 priv->timestamp0 = 0; 7241 priv->timestamp0 = 0;
7282 if ((priv->iw_mode == IEEE80211_IF_TYPE_STA)) 7242 if ((priv->iw_mode == NL80211_IFTYPE_STATION))
7283 priv->beacon_int = 0; 7243 priv->beacon_int = 0;
7284 7244
7285 spin_unlock_irqrestore(&priv->lock, flags); 7245 spin_unlock_irqrestore(&priv->lock, flags);
@@ -7293,14 +7253,14 @@ static void iwl3945_mac_reset_tsf(struct ieee80211_hw *hw)
7293 /* we are restarting association process 7253 /* we are restarting association process
7294 * clear RXON_FILTER_ASSOC_MSK bit 7254 * clear RXON_FILTER_ASSOC_MSK bit
7295 */ 7255 */
7296 if (priv->iw_mode != IEEE80211_IF_TYPE_AP) { 7256 if (priv->iw_mode != NL80211_IFTYPE_AP) {
7297 iwl3945_scan_cancel_timeout(priv, 100); 7257 iwl3945_scan_cancel_timeout(priv, 100);
7298 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; 7258 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
7299 iwl3945_commit_rxon(priv); 7259 iwl3945_commit_rxon(priv);
7300 } 7260 }
7301 7261
7302 /* Per mac80211.h: This is only used in IBSS mode... */ 7262 /* Per mac80211.h: This is only used in IBSS mode... */
7303 if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) { 7263 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
7304 7264
7305 IWL_DEBUG_MAC80211("leave - not in IBSS\n"); 7265 IWL_DEBUG_MAC80211("leave - not in IBSS\n");
7306 mutex_unlock(&priv->mutex); 7266 mutex_unlock(&priv->mutex);
@@ -7315,8 +7275,7 @@ static void iwl3945_mac_reset_tsf(struct ieee80211_hw *hw)
7315 7275
7316} 7276}
7317 7277
7318static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb, 7278static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
7319 struct ieee80211_tx_control *control)
7320{ 7279{
7321 struct iwl3945_priv *priv = hw->priv; 7280 struct iwl3945_priv *priv = hw->priv;
7322 unsigned long flags; 7281 unsigned long flags;
@@ -7330,7 +7289,7 @@ static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *sk
7330 return -EIO; 7289 return -EIO;
7331 } 7290 }
7332 7291
7333 if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) { 7292 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
7334 IWL_DEBUG_MAC80211("leave - not IBSS\n"); 7293 IWL_DEBUG_MAC80211("leave - not IBSS\n");
7335 mutex_unlock(&priv->mutex); 7294 mutex_unlock(&priv->mutex);
7336 return -EIO; 7295 return -EIO;
@@ -7350,7 +7309,7 @@ static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *sk
7350 7309
7351 iwl3945_reset_qos(priv); 7310 iwl3945_reset_qos(priv);
7352 7311
7353 queue_work(priv->workqueue, &priv->post_associate.work); 7312 iwl3945_post_associate(priv);
7354 7313
7355 mutex_unlock(&priv->mutex); 7314 mutex_unlock(&priv->mutex);
7356 7315
@@ -7398,37 +7357,6 @@ static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
7398 7357
7399#endif /* CONFIG_IWL3945_DEBUG */ 7358#endif /* CONFIG_IWL3945_DEBUG */
7400 7359
7401static ssize_t show_rf_kill(struct device *d,
7402 struct device_attribute *attr, char *buf)
7403{
7404 /*
7405 * 0 - RF kill not enabled
7406 * 1 - SW based RF kill active (sysfs)
7407 * 2 - HW based RF kill active
7408 * 3 - Both HW and SW based RF kill active
7409 */
7410 struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
7411 int val = (test_bit(STATUS_RF_KILL_SW, &priv->status) ? 0x1 : 0x0) |
7412 (test_bit(STATUS_RF_KILL_HW, &priv->status) ? 0x2 : 0x0);
7413
7414 return sprintf(buf, "%i\n", val);
7415}
7416
7417static ssize_t store_rf_kill(struct device *d,
7418 struct device_attribute *attr,
7419 const char *buf, size_t count)
7420{
7421 struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
7422
7423 mutex_lock(&priv->mutex);
7424 iwl3945_radio_kill_sw(priv, buf[0] == '1');
7425 mutex_unlock(&priv->mutex);
7426
7427 return count;
7428}
7429
7430static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
7431
7432static ssize_t show_temperature(struct device *d, 7360static ssize_t show_temperature(struct device *d,
7433 struct device_attribute *attr, char *buf) 7361 struct device_attribute *attr, char *buf)
7434{ 7362{
@@ -7442,15 +7370,6 @@ static ssize_t show_temperature(struct device *d,
7442 7370
7443static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL); 7371static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
7444 7372
7445static ssize_t show_rs_window(struct device *d,
7446 struct device_attribute *attr,
7447 char *buf)
7448{
7449 struct iwl3945_priv *priv = d->driver_data;
7450 return iwl3945_fill_rs_info(priv->hw, buf, IWL_AP_ID);
7451}
7452static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL);
7453
7454static ssize_t show_tx_power(struct device *d, 7373static ssize_t show_tx_power(struct device *d,
7455 struct device_attribute *attr, char *buf) 7374 struct device_attribute *attr, char *buf)
7456{ 7375{
@@ -7557,7 +7476,7 @@ static ssize_t show_measurement(struct device *d,
7557 struct iwl3945_priv *priv = dev_get_drvdata(d); 7476 struct iwl3945_priv *priv = dev_get_drvdata(d);
7558 struct iwl3945_spectrum_notification measure_report; 7477 struct iwl3945_spectrum_notification measure_report;
7559 u32 size = sizeof(measure_report), len = 0, ofs = 0; 7478 u32 size = sizeof(measure_report), len = 0, ofs = 0;
7560 u8 *data = (u8 *) & measure_report; 7479 u8 *data = (u8 *)&measure_report;
7561 unsigned long flags; 7480 unsigned long flags;
7562 7481
7563 spin_lock_irqsave(&priv->lock, flags); 7482 spin_lock_irqsave(&priv->lock, flags);
@@ -7728,7 +7647,7 @@ static ssize_t show_power_level(struct device *d,
7728 else 7647 else
7729 p += sprintf(p, " \n"); 7648 p += sprintf(p, " \n");
7730 7649
7731 return (p - buf + 1); 7650 return p - buf + 1;
7732 7651
7733} 7652}
7734 7653
@@ -7750,7 +7669,7 @@ static ssize_t show_statistics(struct device *d,
7750 struct iwl3945_priv *priv = dev_get_drvdata(d); 7669 struct iwl3945_priv *priv = dev_get_drvdata(d);
7751 u32 size = sizeof(struct iwl3945_notif_statistics); 7670 u32 size = sizeof(struct iwl3945_notif_statistics);
7752 u32 len = 0, ofs = 0; 7671 u32 len = 0, ofs = 0;
7753 u8 *data = (u8 *) & priv->statistics; 7672 u8 *data = (u8 *)&priv->statistics;
7754 int rc = 0; 7673 int rc = 0;
7755 7674
7756 if (!iwl3945_is_alive(priv)) 7675 if (!iwl3945_is_alive(priv))
@@ -7879,7 +7798,7 @@ static void iwl3945_setup_deferred_work(struct iwl3945_priv *priv)
7879 INIT_WORK(&priv->abort_scan, iwl3945_bg_abort_scan); 7798 INIT_WORK(&priv->abort_scan, iwl3945_bg_abort_scan);
7880 INIT_WORK(&priv->rf_kill, iwl3945_bg_rf_kill); 7799 INIT_WORK(&priv->rf_kill, iwl3945_bg_rf_kill);
7881 INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update); 7800 INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update);
7882 INIT_DELAYED_WORK(&priv->post_associate, iwl3945_bg_post_associate); 7801 INIT_WORK(&priv->set_monitor, iwl3945_bg_set_monitor);
7883 INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start); 7802 INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start);
7884 INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start); 7803 INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start);
7885 INIT_DELAYED_WORK(&priv->scan_check, iwl3945_bg_scan_check); 7804 INIT_DELAYED_WORK(&priv->scan_check, iwl3945_bg_scan_check);
@@ -7897,7 +7816,6 @@ static void iwl3945_cancel_deferred_work(struct iwl3945_priv *priv)
7897 cancel_delayed_work_sync(&priv->init_alive_start); 7816 cancel_delayed_work_sync(&priv->init_alive_start);
7898 cancel_delayed_work(&priv->scan_check); 7817 cancel_delayed_work(&priv->scan_check);
7899 cancel_delayed_work(&priv->alive_start); 7818 cancel_delayed_work(&priv->alive_start);
7900 cancel_delayed_work(&priv->post_associate);
7901 cancel_work_sync(&priv->beacon_update); 7819 cancel_work_sync(&priv->beacon_update);
7902} 7820}
7903 7821
@@ -7913,8 +7831,6 @@ static struct attribute *iwl3945_sysfs_entries[] = {
7913#endif 7831#endif
7914 &dev_attr_power_level.attr, 7832 &dev_attr_power_level.attr,
7915 &dev_attr_retry_rate.attr, 7833 &dev_attr_retry_rate.attr,
7916 &dev_attr_rf_kill.attr,
7917 &dev_attr_rs_window.attr,
7918 &dev_attr_statistics.attr, 7834 &dev_attr_statistics.attr,
7919 &dev_attr_status.attr, 7835 &dev_attr_status.attr,
7920 &dev_attr_temperature.attr, 7836 &dev_attr_temperature.attr,
@@ -7943,7 +7859,7 @@ static struct ieee80211_ops iwl3945_hw_ops = {
7943 .conf_tx = iwl3945_mac_conf_tx, 7859 .conf_tx = iwl3945_mac_conf_tx,
7944 .get_tsf = iwl3945_mac_get_tsf, 7860 .get_tsf = iwl3945_mac_get_tsf,
7945 .reset_tsf = iwl3945_mac_reset_tsf, 7861 .reset_tsf = iwl3945_mac_reset_tsf,
7946 .beacon_update = iwl3945_mac_beacon_update, 7862 .bss_info_changed = iwl3945_bss_info_changed,
7947 .hw_scan = iwl3945_mac_hw_scan 7863 .hw_scan = iwl3945_mac_hw_scan
7948}; 7864};
7949 7865
@@ -7953,7 +7869,6 @@ static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
7953 struct iwl3945_priv *priv; 7869 struct iwl3945_priv *priv;
7954 struct ieee80211_hw *hw; 7870 struct ieee80211_hw *hw;
7955 struct iwl_3945_cfg *cfg = (struct iwl_3945_cfg *)(ent->driver_data); 7871 struct iwl_3945_cfg *cfg = (struct iwl_3945_cfg *)(ent->driver_data);
7956 int i;
7957 unsigned long flags; 7872 unsigned long flags;
7958 DECLARE_MAC_BUF(mac); 7873 DECLARE_MAC_BUF(mac);
7959 7874
@@ -7983,6 +7898,7 @@ static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
7983 SET_IEEE80211_DEV(hw, &pdev->dev); 7898 SET_IEEE80211_DEV(hw, &pdev->dev);
7984 7899
7985 hw->rate_control_algorithm = "iwl-3945-rs"; 7900 hw->rate_control_algorithm = "iwl-3945-rs";
7901 hw->sta_data_size = sizeof(struct iwl3945_sta_priv);
7986 7902
7987 IWL_DEBUG_INFO("*** LOAD DRIVER ***\n"); 7903 IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
7988 priv = hw->priv; 7904 priv = hw->priv;
@@ -8001,17 +7917,14 @@ static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
8001 7917
8002 priv->ibss_beacon = NULL; 7918 priv->ibss_beacon = NULL;
8003 7919
8004 /* Tell mac80211 and its clients (e.g. Wireless Extensions) 7920 /* Tell mac80211 our characteristics */
8005 * the range of signal quality values that we'll provide. 7921 hw->flags = IEEE80211_HW_SIGNAL_DBM |
8006 * Negative values for level/noise indicate that we'll provide dBm. 7922 IEEE80211_HW_NOISE_DBM;
8007 * For WE, at least, non-0 values here *enable* display of values
8008 * in app (iwconfig). */
8009 hw->max_rssi = -20; /* signal level, negative indicates dBm */
8010 hw->max_noise = -20; /* noise level, negative indicates dBm */
8011 hw->max_signal = 100; /* link quality indication (%) */
8012 7923
8013 /* Tell mac80211 our Tx characteristics */ 7924 hw->wiphy->interface_modes =
8014 hw->flags = IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE; 7925 BIT(NL80211_IFTYPE_AP) |
7926 BIT(NL80211_IFTYPE_STATION) |
7927 BIT(NL80211_IFTYPE_ADHOC);
8015 7928
8016 /* 4 EDCA QOS priorities */ 7929 /* 4 EDCA QOS priorities */
8017 hw->queues = 4; 7930 hw->queues = 4;
@@ -8021,9 +7934,6 @@ static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
8021 spin_lock_init(&priv->sta_lock); 7934 spin_lock_init(&priv->sta_lock);
8022 spin_lock_init(&priv->hcmd_lock); 7935 spin_lock_init(&priv->hcmd_lock);
8023 7936
8024 for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++)
8025 INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
8026
8027 INIT_LIST_HEAD(&priv->free_frames); 7937 INIT_LIST_HEAD(&priv->free_frames);
8028 7938
8029 mutex_init(&priv->mutex); 7939 mutex_init(&priv->mutex);
@@ -8077,7 +7987,7 @@ static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
8077 IWL_DEBUG_INFO("Radio disabled.\n"); 7987 IWL_DEBUG_INFO("Radio disabled.\n");
8078 } 7988 }
8079 7989
8080 priv->iw_mode = IEEE80211_IF_TYPE_STA; 7990 priv->iw_mode = NL80211_IFTYPE_STATION;
8081 7991
8082 printk(KERN_INFO DRV_NAME 7992 printk(KERN_INFO DRV_NAME
8083 ": Detected Intel Wireless WiFi Link %s\n", priv->cfg->name); 7993 ": Detected Intel Wireless WiFi Link %s\n", priv->cfg->name);
@@ -8117,16 +8027,16 @@ static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
8117 8027
8118 /* nic init */ 8028 /* nic init */
8119 iwl3945_set_bit(priv, CSR_GIO_CHICKEN_BITS, 8029 iwl3945_set_bit(priv, CSR_GIO_CHICKEN_BITS,
8120 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER); 8030 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
8121 8031
8122 iwl3945_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE); 8032 iwl3945_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
8123 err = iwl3945_poll_bit(priv, CSR_GP_CNTRL, 8033 err = iwl3945_poll_bit(priv, CSR_GP_CNTRL,
8124 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 8034 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
8125 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000); 8035 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
8126 if (err < 0) { 8036 if (err < 0) {
8127 IWL_DEBUG_INFO("Failed to init the card\n"); 8037 IWL_DEBUG_INFO("Failed to init the card\n");
8128 goto out_remove_sysfs; 8038 goto out_remove_sysfs;
8129 } 8039 }
8130 /* Read the EEPROM */ 8040 /* Read the EEPROM */
8131 err = iwl3945_eeprom_init(priv); 8041 err = iwl3945_eeprom_init(priv);
8132 if (err) { 8042 if (err) {
@@ -8161,6 +8071,11 @@ static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
8161 pci_save_state(pdev); 8071 pci_save_state(pdev);
8162 pci_disable_device(pdev); 8072 pci_disable_device(pdev);
8163 8073
8074 err = iwl3945_rfkill_init(priv);
8075 if (err)
8076 IWL_ERROR("Unable to initialize RFKILL system. "
8077 "Ignoring error: %d\n", err);
8078
8164 return 0; 8079 return 0;
8165 8080
8166 out_free_geos: 8081 out_free_geos:
@@ -8191,8 +8106,6 @@ static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
8191static void __devexit iwl3945_pci_remove(struct pci_dev *pdev) 8106static void __devexit iwl3945_pci_remove(struct pci_dev *pdev)
8192{ 8107{
8193 struct iwl3945_priv *priv = pci_get_drvdata(pdev); 8108 struct iwl3945_priv *priv = pci_get_drvdata(pdev);
8194 struct list_head *p, *q;
8195 int i;
8196 unsigned long flags; 8109 unsigned long flags;
8197 8110
8198 if (!priv) 8111 if (!priv)
@@ -8213,16 +8126,9 @@ static void __devexit iwl3945_pci_remove(struct pci_dev *pdev)
8213 8126
8214 iwl_synchronize_irq(priv); 8127 iwl_synchronize_irq(priv);
8215 8128
8216 /* Free MAC hash list for ADHOC */
8217 for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) {
8218 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
8219 list_del(p);
8220 kfree(list_entry(p, struct iwl3945_ibss_seq, list));
8221 }
8222 }
8223
8224 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group); 8129 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
8225 8130
8131 iwl3945_rfkill_unregister(priv);
8226 iwl3945_dealloc_ucode_pci(priv); 8132 iwl3945_dealloc_ucode_pci(priv);
8227 8133
8228 if (priv->rxq.bd) 8134 if (priv->rxq.bd)
@@ -8232,9 +8138,8 @@ static void __devexit iwl3945_pci_remove(struct pci_dev *pdev)
8232 iwl3945_unset_hw_setting(priv); 8138 iwl3945_unset_hw_setting(priv);
8233 iwl3945_clear_stations_table(priv); 8139 iwl3945_clear_stations_table(priv);
8234 8140
8235 if (priv->mac80211_registered) { 8141 if (priv->mac80211_registered)
8236 ieee80211_unregister_hw(priv->hw); 8142 ieee80211_unregister_hw(priv->hw);
8237 }
8238 8143
8239 /*netif_stop_queue(dev); */ 8144 /*netif_stop_queue(dev); */
8240 flush_workqueue(priv->workqueue); 8145 flush_workqueue(priv->workqueue);
@@ -8252,7 +8157,7 @@ static void __devexit iwl3945_pci_remove(struct pci_dev *pdev)
8252 8157
8253 iwl3945_free_channel_map(priv); 8158 iwl3945_free_channel_map(priv);
8254 iwl3945_free_geos(priv); 8159 iwl3945_free_geos(priv);
8255 8160 kfree(priv->scan);
8256 if (priv->ibss_beacon) 8161 if (priv->ibss_beacon)
8257 dev_kfree_skb(priv->ibss_beacon); 8162 dev_kfree_skb(priv->ibss_beacon);
8258 8163
@@ -8291,6 +8196,114 @@ static int iwl3945_pci_resume(struct pci_dev *pdev)
8291 8196
8292#endif /* CONFIG_PM */ 8197#endif /* CONFIG_PM */
8293 8198
8199/*************** RFKILL FUNCTIONS **********/
8200#ifdef CONFIG_IWL3945_RFKILL
8201/* software rf-kill from user */
8202static int iwl3945_rfkill_soft_rf_kill(void *data, enum rfkill_state state)
8203{
8204 struct iwl3945_priv *priv = data;
8205 int err = 0;
8206
8207 if (!priv->rfkill)
8208 return 0;
8209
8210 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
8211 return 0;
8212
8213 IWL_DEBUG_RF_KILL("we recieved soft RFKILL set to state %d\n", state);
8214 mutex_lock(&priv->mutex);
8215
8216 switch (state) {
8217 case RFKILL_STATE_UNBLOCKED:
8218 if (iwl3945_is_rfkill_hw(priv)) {
8219 err = -EBUSY;
8220 goto out_unlock;
8221 }
8222 iwl3945_radio_kill_sw(priv, 0);
8223 break;
8224 case RFKILL_STATE_SOFT_BLOCKED:
8225 iwl3945_radio_kill_sw(priv, 1);
8226 break;
8227 default:
8228 IWL_WARNING("we recieved unexpected RFKILL state %d\n", state);
8229 break;
8230 }
8231out_unlock:
8232 mutex_unlock(&priv->mutex);
8233
8234 return err;
8235}
8236
8237int iwl3945_rfkill_init(struct iwl3945_priv *priv)
8238{
8239 struct device *device = wiphy_dev(priv->hw->wiphy);
8240 int ret = 0;
8241
8242 BUG_ON(device == NULL);
8243
8244 IWL_DEBUG_RF_KILL("Initializing RFKILL.\n");
8245 priv->rfkill = rfkill_allocate(device, RFKILL_TYPE_WLAN);
8246 if (!priv->rfkill) {
8247 IWL_ERROR("Unable to allocate rfkill device.\n");
8248 ret = -ENOMEM;
8249 goto error;
8250 }
8251
8252 priv->rfkill->name = priv->cfg->name;
8253 priv->rfkill->data = priv;
8254 priv->rfkill->state = RFKILL_STATE_UNBLOCKED;
8255 priv->rfkill->toggle_radio = iwl3945_rfkill_soft_rf_kill;
8256 priv->rfkill->user_claim_unsupported = 1;
8257
8258 priv->rfkill->dev.class->suspend = NULL;
8259 priv->rfkill->dev.class->resume = NULL;
8260
8261 ret = rfkill_register(priv->rfkill);
8262 if (ret) {
8263 IWL_ERROR("Unable to register rfkill: %d\n", ret);
8264 goto freed_rfkill;
8265 }
8266
8267 IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n");
8268 return ret;
8269
8270freed_rfkill:
8271 if (priv->rfkill != NULL)
8272 rfkill_free(priv->rfkill);
8273 priv->rfkill = NULL;
8274
8275error:
8276 IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n");
8277 return ret;
8278}
8279
8280void iwl3945_rfkill_unregister(struct iwl3945_priv *priv)
8281{
8282 if (priv->rfkill)
8283 rfkill_unregister(priv->rfkill);
8284
8285 priv->rfkill = NULL;
8286}
8287
8288/* set rf-kill to the right state. */
8289void iwl3945_rfkill_set_hw_state(struct iwl3945_priv *priv)
8290{
8291
8292 if (!priv->rfkill)
8293 return;
8294
8295 if (iwl3945_is_rfkill_hw(priv)) {
8296 rfkill_force_state(priv->rfkill, RFKILL_STATE_HARD_BLOCKED);
8297 return;
8298 }
8299
8300 if (!iwl3945_is_rfkill_sw(priv))
8301 rfkill_force_state(priv->rfkill, RFKILL_STATE_UNBLOCKED);
8302 else
8303 rfkill_force_state(priv->rfkill, RFKILL_STATE_SOFT_BLOCKED);
8304}
8305#endif
8306
8294/***************************************************************************** 8307/*****************************************************************************
8295 * 8308 *
8296 * driver and module entry point 8309 * driver and module entry point
@@ -8354,6 +8367,8 @@ static void __exit iwl3945_exit(void)
8354 iwl3945_rate_control_unregister(); 8367 iwl3945_rate_control_unregister();
8355} 8368}
8356 8369
8370MODULE_FIRMWARE("iwlwifi-3945" IWL3945_UCODE_API ".ucode");
8371
8357module_param_named(antenna, iwl3945_param_antenna, int, 0444); 8372module_param_named(antenna, iwl3945_param_antenna, int, 0444);
8358MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])"); 8373MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
8359module_param_named(disable, iwl3945_param_disable, int, 0444); 8374module_param_named(disable, iwl3945_param_disable, int, 0444);
diff --git a/drivers/net/wireless/iwlwifi/iwl4965-base.c b/drivers/net/wireless/iwlwifi/iwl4965-base.c
deleted file mode 100644
index 0bd55bb19739..000000000000
--- a/drivers/net/wireless/iwlwifi/iwl4965-base.c
+++ /dev/null
@@ -1,8038 +0,0 @@
1/******************************************************************************
2 *
3 * Copyright(c) 2003 - 2008 Intel Corporation. All rights reserved.
4 *
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
20 *
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
23 *
24 * Contact Information:
25 * James P. Ketrenos <ipw2100-admin@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *
28 *****************************************************************************/
29
30#include <linux/kernel.h>
31#include <linux/module.h>
32#include <linux/version.h>
33#include <linux/init.h>
34#include <linux/pci.h>
35#include <linux/dma-mapping.h>
36#include <linux/delay.h>
37#include <linux/skbuff.h>
38#include <linux/netdevice.h>
39#include <linux/wireless.h>
40#include <linux/firmware.h>
41#include <linux/etherdevice.h>
42#include <linux/if_arp.h>
43
44#include <net/mac80211.h>
45
46#include <asm/div64.h>
47
48#include "iwl-eeprom.h"
49#include "iwl-4965.h"
50#include "iwl-core.h"
51#include "iwl-io.h"
52#include "iwl-helpers.h"
53#include "iwl-sta.h"
54
55static int iwl4965_tx_queue_update_write_ptr(struct iwl_priv *priv,
56 struct iwl4965_tx_queue *txq);
57
58/******************************************************************************
59 *
60 * module boiler plate
61 *
62 ******************************************************************************/
63
64/*
65 * module name, copyright, version, etc.
66 * NOTE: DRV_NAME is defined in iwlwifi.h for use by iwl-debug.h and printk
67 */
68
69#define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link 4965AGN driver for Linux"
70
71#ifdef CONFIG_IWLWIFI_DEBUG
72#define VD "d"
73#else
74#define VD
75#endif
76
77#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
78#define VS "s"
79#else
80#define VS
81#endif
82
83#define DRV_VERSION IWLWIFI_VERSION VD VS
84
85
86MODULE_DESCRIPTION(DRV_DESCRIPTION);
87MODULE_VERSION(DRV_VERSION);
88MODULE_AUTHOR(DRV_COPYRIGHT);
89MODULE_LICENSE("GPL");
90
91__le16 *ieee80211_get_qos_ctrl(struct ieee80211_hdr *hdr)
92{
93 u16 fc = le16_to_cpu(hdr->frame_control);
94 int hdr_len = ieee80211_get_hdrlen(fc);
95
96 if ((fc & 0x00cc) == (IEEE80211_STYPE_QOS_DATA | IEEE80211_FTYPE_DATA))
97 return (__le16 *) ((u8 *) hdr + hdr_len - QOS_CONTROL_LEN);
98 return NULL;
99}
100
101static const struct ieee80211_supported_band *iwl4965_get_hw_mode(
102 struct iwl_priv *priv, enum ieee80211_band band)
103{
104 return priv->hw->wiphy->bands[band];
105}
106
107static int iwl4965_is_empty_essid(const char *essid, int essid_len)
108{
109 /* Single white space is for Linksys APs */
110 if (essid_len == 1 && essid[0] == ' ')
111 return 1;
112
113 /* Otherwise, if the entire essid is 0, we assume it is hidden */
114 while (essid_len) {
115 essid_len--;
116 if (essid[essid_len] != '\0')
117 return 0;
118 }
119
120 return 1;
121}
122
123static const char *iwl4965_escape_essid(const char *essid, u8 essid_len)
124{
125 static char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
126 const char *s = essid;
127 char *d = escaped;
128
129 if (iwl4965_is_empty_essid(essid, essid_len)) {
130 memcpy(escaped, "<hidden>", sizeof("<hidden>"));
131 return escaped;
132 }
133
134 essid_len = min(essid_len, (u8) IW_ESSID_MAX_SIZE);
135 while (essid_len--) {
136 if (*s == '\0') {
137 *d++ = '\\';
138 *d++ = '0';
139 s++;
140 } else
141 *d++ = *s++;
142 }
143 *d = '\0';
144 return escaped;
145}
146
147/*************** DMA-QUEUE-GENERAL-FUNCTIONS *****
148 * DMA services
149 *
150 * Theory of operation
151 *
152 * A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer
153 * of buffer descriptors, each of which points to one or more data buffers for
154 * the device to read from or fill. Driver and device exchange status of each
155 * queue via "read" and "write" pointers. Driver keeps minimum of 2 empty
156 * entries in each circular buffer, to protect against confusing empty and full
157 * queue states.
158 *
159 * The device reads or writes the data in the queues via the device's several
160 * DMA/FIFO channels. Each queue is mapped to a single DMA channel.
161 *
162 * For Tx queue, there are low mark and high mark limits. If, after queuing
163 * the packet for Tx, free space become < low mark, Tx queue stopped. When
164 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
165 * Tx queue resumed.
166 *
167 * The 4965 operates with up to 17 queues: One receive queue, one transmit
168 * queue (#4) for sending commands to the device firmware, and 15 other
169 * Tx queues that may be mapped to prioritized Tx DMA/FIFO channels.
170 *
171 * See more detailed info in iwl-4965-hw.h.
172 ***************************************************/
173
174int iwl4965_queue_space(const struct iwl4965_queue *q)
175{
176 int s = q->read_ptr - q->write_ptr;
177
178 if (q->read_ptr > q->write_ptr)
179 s -= q->n_bd;
180
181 if (s <= 0)
182 s += q->n_window;
183 /* keep some reserve to not confuse empty and full situations */
184 s -= 2;
185 if (s < 0)
186 s = 0;
187 return s;
188}
189
190
191static inline int x2_queue_used(const struct iwl4965_queue *q, int i)
192{
193 return q->write_ptr > q->read_ptr ?
194 (i >= q->read_ptr && i < q->write_ptr) :
195 !(i < q->read_ptr && i >= q->write_ptr);
196}
197
198static inline u8 get_cmd_index(struct iwl4965_queue *q, u32 index, int is_huge)
199{
200 /* This is for scan command, the big buffer at end of command array */
201 if (is_huge)
202 return q->n_window; /* must be power of 2 */
203
204 /* Otherwise, use normal size buffers */
205 return index & (q->n_window - 1);
206}
207
208/**
209 * iwl4965_queue_init - Initialize queue's high/low-water and read/write indexes
210 */
211static int iwl4965_queue_init(struct iwl_priv *priv, struct iwl4965_queue *q,
212 int count, int slots_num, u32 id)
213{
214 q->n_bd = count;
215 q->n_window = slots_num;
216 q->id = id;
217
218 /* count must be power-of-two size, otherwise iwl_queue_inc_wrap
219 * and iwl_queue_dec_wrap are broken. */
220 BUG_ON(!is_power_of_2(count));
221
222 /* slots_num must be power-of-two size, otherwise
223 * get_cmd_index is broken. */
224 BUG_ON(!is_power_of_2(slots_num));
225
226 q->low_mark = q->n_window / 4;
227 if (q->low_mark < 4)
228 q->low_mark = 4;
229
230 q->high_mark = q->n_window / 8;
231 if (q->high_mark < 2)
232 q->high_mark = 2;
233
234 q->write_ptr = q->read_ptr = 0;
235
236 return 0;
237}
238
239/**
240 * iwl4965_tx_queue_alloc - Alloc driver data and TFD CB for one Tx/cmd queue
241 */
242static int iwl4965_tx_queue_alloc(struct iwl_priv *priv,
243 struct iwl4965_tx_queue *txq, u32 id)
244{
245 struct pci_dev *dev = priv->pci_dev;
246
247 /* Driver private data, only for Tx (not command) queues,
248 * not shared with device. */
249 if (id != IWL_CMD_QUEUE_NUM) {
250 txq->txb = kmalloc(sizeof(txq->txb[0]) *
251 TFD_QUEUE_SIZE_MAX, GFP_KERNEL);
252 if (!txq->txb) {
253 IWL_ERROR("kmalloc for auxiliary BD "
254 "structures failed\n");
255 goto error;
256 }
257 } else
258 txq->txb = NULL;
259
260 /* Circular buffer of transmit frame descriptors (TFDs),
261 * shared with device */
262 txq->bd = pci_alloc_consistent(dev,
263 sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX,
264 &txq->q.dma_addr);
265
266 if (!txq->bd) {
267 IWL_ERROR("pci_alloc_consistent(%zd) failed\n",
268 sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX);
269 goto error;
270 }
271 txq->q.id = id;
272
273 return 0;
274
275 error:
276 if (txq->txb) {
277 kfree(txq->txb);
278 txq->txb = NULL;
279 }
280
281 return -ENOMEM;
282}
283
284/**
285 * iwl4965_tx_queue_init - Allocate and initialize one tx/cmd queue
286 */
287int iwl4965_tx_queue_init(struct iwl_priv *priv,
288 struct iwl4965_tx_queue *txq, int slots_num, u32 txq_id)
289{
290 struct pci_dev *dev = priv->pci_dev;
291 int len;
292 int rc = 0;
293
294 /*
295 * Alloc buffer array for commands (Tx or other types of commands).
296 * For the command queue (#4), allocate command space + one big
297 * command for scan, since scan command is very huge; the system will
298 * not have two scans at the same time, so only one is needed.
299 * For normal Tx queues (all other queues), no super-size command
300 * space is needed.
301 */
302 len = sizeof(struct iwl_cmd) * slots_num;
303 if (txq_id == IWL_CMD_QUEUE_NUM)
304 len += IWL_MAX_SCAN_SIZE;
305 txq->cmd = pci_alloc_consistent(dev, len, &txq->dma_addr_cmd);
306 if (!txq->cmd)
307 return -ENOMEM;
308
309 /* Alloc driver data array and TFD circular buffer */
310 rc = iwl4965_tx_queue_alloc(priv, txq, txq_id);
311 if (rc) {
312 pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd);
313
314 return -ENOMEM;
315 }
316 txq->need_update = 0;
317
318 /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise
319 * iwl_queue_inc_wrap and iwl_queue_dec_wrap are broken. */
320 BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX & (TFD_QUEUE_SIZE_MAX - 1));
321
322 /* Initialize queue's high/low-water marks, and head/tail indexes */
323 iwl4965_queue_init(priv, &txq->q, TFD_QUEUE_SIZE_MAX, slots_num, txq_id);
324
325 /* Tell device where to find queue */
326 iwl4965_hw_tx_queue_init(priv, txq);
327
328 return 0;
329}
330
331/**
332 * iwl4965_tx_queue_free - Deallocate DMA queue.
333 * @txq: Transmit queue to deallocate.
334 *
335 * Empty queue by removing and destroying all BD's.
336 * Free all buffers.
337 * 0-fill, but do not free "txq" descriptor structure.
338 */
339void iwl4965_tx_queue_free(struct iwl_priv *priv, struct iwl4965_tx_queue *txq)
340{
341 struct iwl4965_queue *q = &txq->q;
342 struct pci_dev *dev = priv->pci_dev;
343 int len;
344
345 if (q->n_bd == 0)
346 return;
347
348 /* first, empty all BD's */
349 for (; q->write_ptr != q->read_ptr;
350 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd))
351 iwl4965_hw_txq_free_tfd(priv, txq);
352
353 len = sizeof(struct iwl_cmd) * q->n_window;
354 if (q->id == IWL_CMD_QUEUE_NUM)
355 len += IWL_MAX_SCAN_SIZE;
356
357 /* De-alloc array of command/tx buffers */
358 pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd);
359
360 /* De-alloc circular buffer of TFDs */
361 if (txq->q.n_bd)
362 pci_free_consistent(dev, sizeof(struct iwl4965_tfd_frame) *
363 txq->q.n_bd, txq->bd, txq->q.dma_addr);
364
365 /* De-alloc array of per-TFD driver data */
366 if (txq->txb) {
367 kfree(txq->txb);
368 txq->txb = NULL;
369 }
370
371 /* 0-fill queue descriptor structure */
372 memset(txq, 0, sizeof(*txq));
373}
374
375const u8 iwl4965_broadcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
376
377/*************** STATION TABLE MANAGEMENT ****
378 * mac80211 should be examined to determine if sta_info is duplicating
379 * the functionality provided here
380 */
381
382/**************************************************************/
383
384#if 0 /* temporary disable till we add real remove station */
385/**
386 * iwl4965_remove_station - Remove driver's knowledge of station.
387 *
388 * NOTE: This does not remove station from device's station table.
389 */
390static u8 iwl4965_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
391{
392 int index = IWL_INVALID_STATION;
393 int i;
394 unsigned long flags;
395
396 spin_lock_irqsave(&priv->sta_lock, flags);
397
398 if (is_ap)
399 index = IWL_AP_ID;
400 else if (is_broadcast_ether_addr(addr))
401 index = priv->hw_params.bcast_sta_id;
402 else
403 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++)
404 if (priv->stations[i].used &&
405 !compare_ether_addr(priv->stations[i].sta.sta.addr,
406 addr)) {
407 index = i;
408 break;
409 }
410
411 if (unlikely(index == IWL_INVALID_STATION))
412 goto out;
413
414 if (priv->stations[index].used) {
415 priv->stations[index].used = 0;
416 priv->num_stations--;
417 }
418
419 BUG_ON(priv->num_stations < 0);
420
421out:
422 spin_unlock_irqrestore(&priv->sta_lock, flags);
423 return 0;
424}
425#endif
426
427/**
428 * iwl4965_add_station_flags - Add station to tables in driver and device
429 */
430u8 iwl4965_add_station_flags(struct iwl_priv *priv, const u8 *addr,
431 int is_ap, u8 flags, void *ht_data)
432{
433 int i;
434 int index = IWL_INVALID_STATION;
435 struct iwl4965_station_entry *station;
436 unsigned long flags_spin;
437 DECLARE_MAC_BUF(mac);
438
439 spin_lock_irqsave(&priv->sta_lock, flags_spin);
440 if (is_ap)
441 index = IWL_AP_ID;
442 else if (is_broadcast_ether_addr(addr))
443 index = priv->hw_params.bcast_sta_id;
444 else
445 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) {
446 if (!compare_ether_addr(priv->stations[i].sta.sta.addr,
447 addr)) {
448 index = i;
449 break;
450 }
451
452 if (!priv->stations[i].used &&
453 index == IWL_INVALID_STATION)
454 index = i;
455 }
456
457
458 /* These two conditions have the same outcome, but keep them separate
459 since they have different meanings */
460 if (unlikely(index == IWL_INVALID_STATION)) {
461 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
462 return index;
463 }
464
465 if (priv->stations[index].used &&
466 !compare_ether_addr(priv->stations[index].sta.sta.addr, addr)) {
467 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
468 return index;
469 }
470
471
472 IWL_DEBUG_ASSOC("Add STA ID %d: %s\n", index, print_mac(mac, addr));
473 station = &priv->stations[index];
474 station->used = 1;
475 priv->num_stations++;
476
477 /* Set up the REPLY_ADD_STA command to send to device */
478 memset(&station->sta, 0, sizeof(struct iwl4965_addsta_cmd));
479 memcpy(station->sta.sta.addr, addr, ETH_ALEN);
480 station->sta.mode = 0;
481 station->sta.sta.sta_id = index;
482 station->sta.station_flags = 0;
483
484#ifdef CONFIG_IWL4965_HT
485 /* BCAST station and IBSS stations do not work in HT mode */
486 if (index != priv->hw_params.bcast_sta_id &&
487 priv->iw_mode != IEEE80211_IF_TYPE_IBSS)
488 iwl4965_set_ht_add_station(priv, index,
489 (struct ieee80211_ht_info *) ht_data);
490#endif /*CONFIG_IWL4965_HT*/
491
492 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
493
494 /* Add station to device's station table */
495 iwl4965_send_add_station(priv, &station->sta, flags);
496 return index;
497
498}
499
500
501
502/*************** HOST COMMAND QUEUE FUNCTIONS *****/
503
504/**
505 * iwl4965_enqueue_hcmd - enqueue a uCode command
506 * @priv: device private data point
507 * @cmd: a point to the ucode command structure
508 *
509 * The function returns < 0 values to indicate the operation is
510 * failed. On success, it turns the index (> 0) of command in the
511 * command queue.
512 */
513int iwl4965_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd)
514{
515 struct iwl4965_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM];
516 struct iwl4965_queue *q = &txq->q;
517 struct iwl4965_tfd_frame *tfd;
518 u32 *control_flags;
519 struct iwl_cmd *out_cmd;
520 u32 idx;
521 u16 fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr));
522 dma_addr_t phys_addr;
523 int ret;
524 unsigned long flags;
525
526 /* If any of the command structures end up being larger than
527 * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then
528 * we will need to increase the size of the TFD entries */
529 BUG_ON((fix_size > TFD_MAX_PAYLOAD_SIZE) &&
530 !(cmd->meta.flags & CMD_SIZE_HUGE));
531
532 if (iwl_is_rfkill(priv)) {
533 IWL_DEBUG_INFO("Not sending command - RF KILL");
534 return -EIO;
535 }
536
537 if (iwl4965_queue_space(q) < ((cmd->meta.flags & CMD_ASYNC) ? 2 : 1)) {
538 IWL_ERROR("No space for Tx\n");
539 return -ENOSPC;
540 }
541
542 spin_lock_irqsave(&priv->hcmd_lock, flags);
543
544 tfd = &txq->bd[q->write_ptr];
545 memset(tfd, 0, sizeof(*tfd));
546
547 control_flags = (u32 *) tfd;
548
549 idx = get_cmd_index(q, q->write_ptr, cmd->meta.flags & CMD_SIZE_HUGE);
550 out_cmd = &txq->cmd[idx];
551
552 out_cmd->hdr.cmd = cmd->id;
553 memcpy(&out_cmd->meta, &cmd->meta, sizeof(cmd->meta));
554 memcpy(&out_cmd->cmd.payload, cmd->data, cmd->len);
555
556 /* At this point, the out_cmd now has all of the incoming cmd
557 * information */
558
559 out_cmd->hdr.flags = 0;
560 out_cmd->hdr.sequence = cpu_to_le16(QUEUE_TO_SEQ(IWL_CMD_QUEUE_NUM) |
561 INDEX_TO_SEQ(q->write_ptr));
562 if (out_cmd->meta.flags & CMD_SIZE_HUGE)
563 out_cmd->hdr.sequence |= cpu_to_le16(SEQ_HUGE_FRAME);
564
565 phys_addr = txq->dma_addr_cmd + sizeof(txq->cmd[0]) * idx +
566 offsetof(struct iwl_cmd, hdr);
567 iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, fix_size);
568
569 IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, "
570 "%d bytes at %d[%d]:%d\n",
571 get_cmd_string(out_cmd->hdr.cmd),
572 out_cmd->hdr.cmd, le16_to_cpu(out_cmd->hdr.sequence),
573 fix_size, q->write_ptr, idx, IWL_CMD_QUEUE_NUM);
574
575 txq->need_update = 1;
576
577 /* Set up entry in queue's byte count circular buffer */
578 priv->cfg->ops->lib->txq_update_byte_cnt_tbl(priv, txq, 0);
579
580 /* Increment and update queue's write index */
581 q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
582 ret = iwl4965_tx_queue_update_write_ptr(priv, txq);
583
584 spin_unlock_irqrestore(&priv->hcmd_lock, flags);
585 return ret ? ret : idx;
586}
587
588static void iwl4965_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt)
589{
590 struct iwl4965_rxon_cmd *rxon = &priv->staging_rxon;
591
592 if (hw_decrypt)
593 rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
594 else
595 rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
596
597}
598
599/**
600 * iwl4965_rxon_add_station - add station into station table.
601 *
602 * there is only one AP station with id= IWL_AP_ID
603 * NOTE: mutex must be held before calling this fnction
604 */
605static int iwl4965_rxon_add_station(struct iwl_priv *priv,
606 const u8 *addr, int is_ap)
607{
608 u8 sta_id;
609
610 /* Add station to device's station table */
611#ifdef CONFIG_IWL4965_HT
612 struct ieee80211_conf *conf = &priv->hw->conf;
613 struct ieee80211_ht_info *cur_ht_config = &conf->ht_conf;
614
615 if ((is_ap) &&
616 (conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) &&
617 (priv->iw_mode == IEEE80211_IF_TYPE_STA))
618 sta_id = iwl4965_add_station_flags(priv, addr, is_ap,
619 0, cur_ht_config);
620 else
621#endif /* CONFIG_IWL4965_HT */
622 sta_id = iwl4965_add_station_flags(priv, addr, is_ap,
623 0, NULL);
624
625 /* Set up default rate scaling table in device's station table */
626 iwl4965_add_station(priv, addr, is_ap);
627
628 return sta_id;
629}
630
631/**
632 * iwl4965_check_rxon_cmd - validate RXON structure is valid
633 *
634 * NOTE: This is really only useful during development and can eventually
635 * be #ifdef'd out once the driver is stable and folks aren't actively
636 * making changes
637 */
638static int iwl4965_check_rxon_cmd(struct iwl4965_rxon_cmd *rxon)
639{
640 int error = 0;
641 int counter = 1;
642
643 if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
644 error |= le32_to_cpu(rxon->flags &
645 (RXON_FLG_TGJ_NARROW_BAND_MSK |
646 RXON_FLG_RADAR_DETECT_MSK));
647 if (error)
648 IWL_WARNING("check 24G fields %d | %d\n",
649 counter++, error);
650 } else {
651 error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ?
652 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK);
653 if (error)
654 IWL_WARNING("check 52 fields %d | %d\n",
655 counter++, error);
656 error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK);
657 if (error)
658 IWL_WARNING("check 52 CCK %d | %d\n",
659 counter++, error);
660 }
661 error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1;
662 if (error)
663 IWL_WARNING("check mac addr %d | %d\n", counter++, error);
664
665 /* make sure basic rates 6Mbps and 1Mbps are supported */
666 error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) &&
667 ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0));
668 if (error)
669 IWL_WARNING("check basic rate %d | %d\n", counter++, error);
670
671 error |= (le16_to_cpu(rxon->assoc_id) > 2007);
672 if (error)
673 IWL_WARNING("check assoc id %d | %d\n", counter++, error);
674
675 error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
676 == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK));
677 if (error)
678 IWL_WARNING("check CCK and short slot %d | %d\n",
679 counter++, error);
680
681 error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
682 == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK));
683 if (error)
684 IWL_WARNING("check CCK & auto detect %d | %d\n",
685 counter++, error);
686
687 error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
688 RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK);
689 if (error)
690 IWL_WARNING("check TGG and auto detect %d | %d\n",
691 counter++, error);
692
693 if (error)
694 IWL_WARNING("Tuning to channel %d\n",
695 le16_to_cpu(rxon->channel));
696
697 if (error) {
698 IWL_ERROR("Not a valid iwl4965_rxon_assoc_cmd field values\n");
699 return -1;
700 }
701 return 0;
702}
703
704/**
705 * iwl4965_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
706 * @priv: staging_rxon is compared to active_rxon
707 *
708 * If the RXON structure is changing enough to require a new tune,
709 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
710 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
711 */
712static int iwl4965_full_rxon_required(struct iwl_priv *priv)
713{
714
715 /* These items are only settable from the full RXON command */
716 if (!(priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) ||
717 compare_ether_addr(priv->staging_rxon.bssid_addr,
718 priv->active_rxon.bssid_addr) ||
719 compare_ether_addr(priv->staging_rxon.node_addr,
720 priv->active_rxon.node_addr) ||
721 compare_ether_addr(priv->staging_rxon.wlap_bssid_addr,
722 priv->active_rxon.wlap_bssid_addr) ||
723 (priv->staging_rxon.dev_type != priv->active_rxon.dev_type) ||
724 (priv->staging_rxon.channel != priv->active_rxon.channel) ||
725 (priv->staging_rxon.air_propagation !=
726 priv->active_rxon.air_propagation) ||
727 (priv->staging_rxon.ofdm_ht_single_stream_basic_rates !=
728 priv->active_rxon.ofdm_ht_single_stream_basic_rates) ||
729 (priv->staging_rxon.ofdm_ht_dual_stream_basic_rates !=
730 priv->active_rxon.ofdm_ht_dual_stream_basic_rates) ||
731 (priv->staging_rxon.rx_chain != priv->active_rxon.rx_chain) ||
732 (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id))
733 return 1;
734
735 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
736 * be updated with the RXON_ASSOC command -- however only some
737 * flag transitions are allowed using RXON_ASSOC */
738
739 /* Check if we are not switching bands */
740 if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) !=
741 (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK))
742 return 1;
743
744 /* Check if we are switching association toggle */
745 if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) !=
746 (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK))
747 return 1;
748
749 return 0;
750}
751
752/**
753 * iwl4965_commit_rxon - commit staging_rxon to hardware
754 *
755 * The RXON command in staging_rxon is committed to the hardware and
756 * the active_rxon structure is updated with the new data. This
757 * function correctly transitions out of the RXON_ASSOC_MSK state if
758 * a HW tune is required based on the RXON structure changes.
759 */
760static int iwl4965_commit_rxon(struct iwl_priv *priv)
761{
762 /* cast away the const for active_rxon in this function */
763 struct iwl4965_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
764 DECLARE_MAC_BUF(mac);
765 int rc = 0;
766
767 if (!iwl_is_alive(priv))
768 return -1;
769
770 /* always get timestamp with Rx frame */
771 priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK;
772
773 rc = iwl4965_check_rxon_cmd(&priv->staging_rxon);
774 if (rc) {
775 IWL_ERROR("Invalid RXON configuration. Not committing.\n");
776 return -EINVAL;
777 }
778
779 /* If we don't need to send a full RXON, we can use
780 * iwl4965_rxon_assoc_cmd which is used to reconfigure filter
781 * and other flags for the current radio configuration. */
782 if (!iwl4965_full_rxon_required(priv)) {
783 rc = iwl_send_rxon_assoc(priv);
784 if (rc) {
785 IWL_ERROR("Error setting RXON_ASSOC "
786 "configuration (%d).\n", rc);
787 return rc;
788 }
789
790 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
791
792 return 0;
793 }
794
795 /* station table will be cleared */
796 priv->assoc_station_added = 0;
797
798#ifdef CONFIG_IWL4965_SENSITIVITY
799 priv->sensitivity_data.state = IWL_SENS_CALIB_NEED_REINIT;
800 if (!priv->error_recovering)
801 priv->start_calib = 0;
802
803 iwl4965_init_sensitivity(priv, CMD_ASYNC, 1);
804#endif /* CONFIG_IWL4965_SENSITIVITY */
805
806 /* If we are currently associated and the new config requires
807 * an RXON_ASSOC and the new config wants the associated mask enabled,
808 * we must clear the associated from the active configuration
809 * before we apply the new config */
810 if (iwl_is_associated(priv) &&
811 (priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) {
812 IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
813 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
814
815 rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
816 sizeof(struct iwl4965_rxon_cmd),
817 &priv->active_rxon);
818
819 /* If the mask clearing failed then we set
820 * active_rxon back to what it was previously */
821 if (rc) {
822 active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
823 IWL_ERROR("Error clearing ASSOC_MSK on current "
824 "configuration (%d).\n", rc);
825 return rc;
826 }
827 }
828
829 IWL_DEBUG_INFO("Sending RXON\n"
830 "* with%s RXON_FILTER_ASSOC_MSK\n"
831 "* channel = %d\n"
832 "* bssid = %s\n",
833 ((priv->staging_rxon.filter_flags &
834 RXON_FILTER_ASSOC_MSK) ? "" : "out"),
835 le16_to_cpu(priv->staging_rxon.channel),
836 print_mac(mac, priv->staging_rxon.bssid_addr));
837
838 iwl4965_set_rxon_hwcrypto(priv, !priv->cfg->mod_params->sw_crypto);
839 /* Apply the new configuration */
840 rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
841 sizeof(struct iwl4965_rxon_cmd), &priv->staging_rxon);
842 if (rc) {
843 IWL_ERROR("Error setting new configuration (%d).\n", rc);
844 return rc;
845 }
846
847 iwlcore_clear_stations_table(priv);
848
849#ifdef CONFIG_IWL4965_SENSITIVITY
850 if (!priv->error_recovering)
851 priv->start_calib = 0;
852
853 priv->sensitivity_data.state = IWL_SENS_CALIB_NEED_REINIT;
854 iwl4965_init_sensitivity(priv, CMD_ASYNC, 1);
855#endif /* CONFIG_IWL4965_SENSITIVITY */
856
857 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
858
859 /* If we issue a new RXON command which required a tune then we must
860 * send a new TXPOWER command or we won't be able to Tx any frames */
861 rc = iwl4965_hw_reg_send_txpower(priv);
862 if (rc) {
863 IWL_ERROR("Error setting Tx power (%d).\n", rc);
864 return rc;
865 }
866
867 /* Add the broadcast address so we can send broadcast frames */
868 if (iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0) ==
869 IWL_INVALID_STATION) {
870 IWL_ERROR("Error adding BROADCAST address for transmit.\n");
871 return -EIO;
872 }
873
874 /* If we have set the ASSOC_MSK and we are in BSS mode then
875 * add the IWL_AP_ID to the station rate table */
876 if (iwl_is_associated(priv) &&
877 (priv->iw_mode == IEEE80211_IF_TYPE_STA)) {
878 if (iwl4965_rxon_add_station(priv, priv->active_rxon.bssid_addr, 1)
879 == IWL_INVALID_STATION) {
880 IWL_ERROR("Error adding AP address for transmit.\n");
881 return -EIO;
882 }
883 priv->assoc_station_added = 1;
884 if (priv->default_wep_key &&
885 iwl_send_static_wepkey_cmd(priv, 0))
886 IWL_ERROR("Could not send WEP static key.\n");
887 }
888
889 return 0;
890}
891
892static int iwl4965_send_bt_config(struct iwl_priv *priv)
893{
894 struct iwl4965_bt_cmd bt_cmd = {
895 .flags = 3,
896 .lead_time = 0xAA,
897 .max_kill = 1,
898 .kill_ack_mask = 0,
899 .kill_cts_mask = 0,
900 };
901
902 return iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG,
903 sizeof(struct iwl4965_bt_cmd), &bt_cmd);
904}
905
906static int iwl4965_send_scan_abort(struct iwl_priv *priv)
907{
908 int rc = 0;
909 struct iwl4965_rx_packet *res;
910 struct iwl_host_cmd cmd = {
911 .id = REPLY_SCAN_ABORT_CMD,
912 .meta.flags = CMD_WANT_SKB,
913 };
914
915 /* If there isn't a scan actively going on in the hardware
916 * then we are in between scan bands and not actually
917 * actively scanning, so don't send the abort command */
918 if (!test_bit(STATUS_SCAN_HW, &priv->status)) {
919 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
920 return 0;
921 }
922
923 rc = iwl_send_cmd_sync(priv, &cmd);
924 if (rc) {
925 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
926 return rc;
927 }
928
929 res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data;
930 if (res->u.status != CAN_ABORT_STATUS) {
931 /* The scan abort will return 1 for success or
932 * 2 for "failure". A failure condition can be
933 * due to simply not being in an active scan which
934 * can occur if we send the scan abort before we
935 * the microcode has notified us that a scan is
936 * completed. */
937 IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res->u.status);
938 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
939 clear_bit(STATUS_SCAN_HW, &priv->status);
940 }
941
942 dev_kfree_skb_any(cmd.meta.u.skb);
943
944 return rc;
945}
946
947static int iwl4965_card_state_sync_callback(struct iwl_priv *priv,
948 struct iwl_cmd *cmd,
949 struct sk_buff *skb)
950{
951 return 1;
952}
953
954/*
955 * CARD_STATE_CMD
956 *
957 * Use: Sets the device's internal card state to enable, disable, or halt
958 *
959 * When in the 'enable' state the card operates as normal.
960 * When in the 'disable' state, the card enters into a low power mode.
961 * When in the 'halt' state, the card is shut down and must be fully
962 * restarted to come back on.
963 */
964static int iwl4965_send_card_state(struct iwl_priv *priv, u32 flags, u8 meta_flag)
965{
966 struct iwl_host_cmd cmd = {
967 .id = REPLY_CARD_STATE_CMD,
968 .len = sizeof(u32),
969 .data = &flags,
970 .meta.flags = meta_flag,
971 };
972
973 if (meta_flag & CMD_ASYNC)
974 cmd.meta.u.callback = iwl4965_card_state_sync_callback;
975
976 return iwl_send_cmd(priv, &cmd);
977}
978
979static int iwl4965_add_sta_sync_callback(struct iwl_priv *priv,
980 struct iwl_cmd *cmd, struct sk_buff *skb)
981{
982 struct iwl4965_rx_packet *res = NULL;
983
984 if (!skb) {
985 IWL_ERROR("Error: Response NULL in REPLY_ADD_STA.\n");
986 return 1;
987 }
988
989 res = (struct iwl4965_rx_packet *)skb->data;
990 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
991 IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
992 res->hdr.flags);
993 return 1;
994 }
995
996 switch (res->u.add_sta.status) {
997 case ADD_STA_SUCCESS_MSK:
998 break;
999 default:
1000 break;
1001 }
1002
1003 /* We didn't cache the SKB; let the caller free it */
1004 return 1;
1005}
1006
1007int iwl4965_send_add_station(struct iwl_priv *priv,
1008 struct iwl4965_addsta_cmd *sta, u8 flags)
1009{
1010 struct iwl4965_rx_packet *res = NULL;
1011 int rc = 0;
1012 struct iwl_host_cmd cmd = {
1013 .id = REPLY_ADD_STA,
1014 .len = sizeof(struct iwl4965_addsta_cmd),
1015 .meta.flags = flags,
1016 .data = sta,
1017 };
1018
1019 if (flags & CMD_ASYNC)
1020 cmd.meta.u.callback = iwl4965_add_sta_sync_callback;
1021 else
1022 cmd.meta.flags |= CMD_WANT_SKB;
1023
1024 rc = iwl_send_cmd(priv, &cmd);
1025
1026 if (rc || (flags & CMD_ASYNC))
1027 return rc;
1028
1029 res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data;
1030 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
1031 IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
1032 res->hdr.flags);
1033 rc = -EIO;
1034 }
1035
1036 if (rc == 0) {
1037 switch (res->u.add_sta.status) {
1038 case ADD_STA_SUCCESS_MSK:
1039 IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n");
1040 break;
1041 default:
1042 rc = -EIO;
1043 IWL_WARNING("REPLY_ADD_STA failed\n");
1044 break;
1045 }
1046 }
1047
1048 priv->alloc_rxb_skb--;
1049 dev_kfree_skb_any(cmd.meta.u.skb);
1050
1051 return rc;
1052}
1053
1054static void iwl4965_clear_free_frames(struct iwl_priv *priv)
1055{
1056 struct list_head *element;
1057
1058 IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
1059 priv->frames_count);
1060
1061 while (!list_empty(&priv->free_frames)) {
1062 element = priv->free_frames.next;
1063 list_del(element);
1064 kfree(list_entry(element, struct iwl4965_frame, list));
1065 priv->frames_count--;
1066 }
1067
1068 if (priv->frames_count) {
1069 IWL_WARNING("%d frames still in use. Did we lose one?\n",
1070 priv->frames_count);
1071 priv->frames_count = 0;
1072 }
1073}
1074
1075static struct iwl4965_frame *iwl4965_get_free_frame(struct iwl_priv *priv)
1076{
1077 struct iwl4965_frame *frame;
1078 struct list_head *element;
1079 if (list_empty(&priv->free_frames)) {
1080 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
1081 if (!frame) {
1082 IWL_ERROR("Could not allocate frame!\n");
1083 return NULL;
1084 }
1085
1086 priv->frames_count++;
1087 return frame;
1088 }
1089
1090 element = priv->free_frames.next;
1091 list_del(element);
1092 return list_entry(element, struct iwl4965_frame, list);
1093}
1094
1095static void iwl4965_free_frame(struct iwl_priv *priv, struct iwl4965_frame *frame)
1096{
1097 memset(frame, 0, sizeof(*frame));
1098 list_add(&frame->list, &priv->free_frames);
1099}
1100
1101unsigned int iwl4965_fill_beacon_frame(struct iwl_priv *priv,
1102 struct ieee80211_hdr *hdr,
1103 const u8 *dest, int left)
1104{
1105
1106 if (!iwl_is_associated(priv) || !priv->ibss_beacon ||
1107 ((priv->iw_mode != IEEE80211_IF_TYPE_IBSS) &&
1108 (priv->iw_mode != IEEE80211_IF_TYPE_AP)))
1109 return 0;
1110
1111 if (priv->ibss_beacon->len > left)
1112 return 0;
1113
1114 memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
1115
1116 return priv->ibss_beacon->len;
1117}
1118
1119static u8 iwl4965_rate_get_lowest_plcp(int rate_mask)
1120{
1121 u8 i;
1122
1123 for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID;
1124 i = iwl4965_rates[i].next_ieee) {
1125 if (rate_mask & (1 << i))
1126 return iwl4965_rates[i].plcp;
1127 }
1128
1129 return IWL_RATE_INVALID;
1130}
1131
1132static int iwl4965_send_beacon_cmd(struct iwl_priv *priv)
1133{
1134 struct iwl4965_frame *frame;
1135 unsigned int frame_size;
1136 int rc;
1137 u8 rate;
1138
1139 frame = iwl4965_get_free_frame(priv);
1140
1141 if (!frame) {
1142 IWL_ERROR("Could not obtain free frame buffer for beacon "
1143 "command.\n");
1144 return -ENOMEM;
1145 }
1146
1147 if (!(priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)) {
1148 rate = iwl4965_rate_get_lowest_plcp(priv->active_rate_basic &
1149 0xFF0);
1150 if (rate == IWL_INVALID_RATE)
1151 rate = IWL_RATE_6M_PLCP;
1152 } else {
1153 rate = iwl4965_rate_get_lowest_plcp(priv->active_rate_basic & 0xF);
1154 if (rate == IWL_INVALID_RATE)
1155 rate = IWL_RATE_1M_PLCP;
1156 }
1157
1158 frame_size = iwl4965_hw_get_beacon_cmd(priv, frame, rate);
1159
1160 rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
1161 &frame->u.cmd[0]);
1162
1163 iwl4965_free_frame(priv, frame);
1164
1165 return rc;
1166}
1167
1168/******************************************************************************
1169 *
1170 * Misc. internal state and helper functions
1171 *
1172 ******************************************************************************/
1173
1174static void iwl4965_unset_hw_params(struct iwl_priv *priv)
1175{
1176 if (priv->shared_virt)
1177 pci_free_consistent(priv->pci_dev,
1178 sizeof(struct iwl4965_shared),
1179 priv->shared_virt,
1180 priv->shared_phys);
1181}
1182
1183/**
1184 * iwl4965_supported_rate_to_ie - fill in the supported rate in IE field
1185 *
1186 * return : set the bit for each supported rate insert in ie
1187 */
1188static u16 iwl4965_supported_rate_to_ie(u8 *ie, u16 supported_rate,
1189 u16 basic_rate, int *left)
1190{
1191 u16 ret_rates = 0, bit;
1192 int i;
1193 u8 *cnt = ie;
1194 u8 *rates = ie + 1;
1195
1196 for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) {
1197 if (bit & supported_rate) {
1198 ret_rates |= bit;
1199 rates[*cnt] = iwl4965_rates[i].ieee |
1200 ((bit & basic_rate) ? 0x80 : 0x00);
1201 (*cnt)++;
1202 (*left)--;
1203 if ((*left <= 0) ||
1204 (*cnt >= IWL_SUPPORTED_RATES_IE_LEN))
1205 break;
1206 }
1207 }
1208
1209 return ret_rates;
1210}
1211
1212/**
1213 * iwl4965_fill_probe_req - fill in all required fields and IE for probe request
1214 */
1215static u16 iwl4965_fill_probe_req(struct iwl_priv *priv,
1216 enum ieee80211_band band,
1217 struct ieee80211_mgmt *frame,
1218 int left, int is_direct)
1219{
1220 int len = 0;
1221 u8 *pos = NULL;
1222 u16 active_rates, ret_rates, cck_rates, active_rate_basic;
1223#ifdef CONFIG_IWL4965_HT
1224 const struct ieee80211_supported_band *sband =
1225 iwl4965_get_hw_mode(priv, band);
1226#endif /* CONFIG_IWL4965_HT */
1227
1228 /* Make sure there is enough space for the probe request,
1229 * two mandatory IEs and the data */
1230 left -= 24;
1231 if (left < 0)
1232 return 0;
1233 len += 24;
1234
1235 frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
1236 memcpy(frame->da, iwl4965_broadcast_addr, ETH_ALEN);
1237 memcpy(frame->sa, priv->mac_addr, ETH_ALEN);
1238 memcpy(frame->bssid, iwl4965_broadcast_addr, ETH_ALEN);
1239 frame->seq_ctrl = 0;
1240
1241 /* fill in our indirect SSID IE */
1242 /* ...next IE... */
1243
1244 left -= 2;
1245 if (left < 0)
1246 return 0;
1247 len += 2;
1248 pos = &(frame->u.probe_req.variable[0]);
1249 *pos++ = WLAN_EID_SSID;
1250 *pos++ = 0;
1251
1252 /* fill in our direct SSID IE... */
1253 if (is_direct) {
1254 /* ...next IE... */
1255 left -= 2 + priv->essid_len;
1256 if (left < 0)
1257 return 0;
1258 /* ... fill it in... */
1259 *pos++ = WLAN_EID_SSID;
1260 *pos++ = priv->essid_len;
1261 memcpy(pos, priv->essid, priv->essid_len);
1262 pos += priv->essid_len;
1263 len += 2 + priv->essid_len;
1264 }
1265
1266 /* fill in supported rate */
1267 /* ...next IE... */
1268 left -= 2;
1269 if (left < 0)
1270 return 0;
1271
1272 /* ... fill it in... */
1273 *pos++ = WLAN_EID_SUPP_RATES;
1274 *pos = 0;
1275
1276 /* exclude 60M rate */
1277 active_rates = priv->rates_mask;
1278 active_rates &= ~IWL_RATE_60M_MASK;
1279
1280 active_rate_basic = active_rates & IWL_BASIC_RATES_MASK;
1281
1282 cck_rates = IWL_CCK_RATES_MASK & active_rates;
1283 ret_rates = iwl4965_supported_rate_to_ie(pos, cck_rates,
1284 active_rate_basic, &left);
1285 active_rates &= ~ret_rates;
1286
1287 ret_rates = iwl4965_supported_rate_to_ie(pos, active_rates,
1288 active_rate_basic, &left);
1289 active_rates &= ~ret_rates;
1290
1291 len += 2 + *pos;
1292 pos += (*pos) + 1;
1293 if (active_rates == 0)
1294 goto fill_end;
1295
1296 /* fill in supported extended rate */
1297 /* ...next IE... */
1298 left -= 2;
1299 if (left < 0)
1300 return 0;
1301 /* ... fill it in... */
1302 *pos++ = WLAN_EID_EXT_SUPP_RATES;
1303 *pos = 0;
1304 iwl4965_supported_rate_to_ie(pos, active_rates,
1305 active_rate_basic, &left);
1306 if (*pos > 0)
1307 len += 2 + *pos;
1308
1309#ifdef CONFIG_IWL4965_HT
1310 if (sband && sband->ht_info.ht_supported) {
1311 struct ieee80211_ht_cap *ht_cap;
1312 pos += (*pos) + 1;
1313 *pos++ = WLAN_EID_HT_CAPABILITY;
1314 *pos++ = sizeof(struct ieee80211_ht_cap);
1315 ht_cap = (struct ieee80211_ht_cap *)pos;
1316 ht_cap->cap_info = cpu_to_le16(sband->ht_info.cap);
1317 memcpy(ht_cap->supp_mcs_set, sband->ht_info.supp_mcs_set, 16);
1318 ht_cap->ampdu_params_info =(sband->ht_info.ampdu_factor &
1319 IEEE80211_HT_CAP_AMPDU_FACTOR) |
1320 ((sband->ht_info.ampdu_density << 2) &
1321 IEEE80211_HT_CAP_AMPDU_DENSITY);
1322 len += 2 + sizeof(struct ieee80211_ht_cap);
1323 }
1324#endif /*CONFIG_IWL4965_HT */
1325
1326 fill_end:
1327 return (u16)len;
1328}
1329
1330/*
1331 * QoS support
1332*/
1333static int iwl4965_send_qos_params_command(struct iwl_priv *priv,
1334 struct iwl4965_qosparam_cmd *qos)
1335{
1336
1337 return iwl_send_cmd_pdu(priv, REPLY_QOS_PARAM,
1338 sizeof(struct iwl4965_qosparam_cmd), qos);
1339}
1340
1341static void iwl4965_activate_qos(struct iwl_priv *priv, u8 force)
1342{
1343 unsigned long flags;
1344
1345 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
1346 return;
1347
1348 if (!priv->qos_data.qos_enable)
1349 return;
1350
1351 spin_lock_irqsave(&priv->lock, flags);
1352 priv->qos_data.def_qos_parm.qos_flags = 0;
1353
1354 if (priv->qos_data.qos_cap.q_AP.queue_request &&
1355 !priv->qos_data.qos_cap.q_AP.txop_request)
1356 priv->qos_data.def_qos_parm.qos_flags |=
1357 QOS_PARAM_FLG_TXOP_TYPE_MSK;
1358 if (priv->qos_data.qos_active)
1359 priv->qos_data.def_qos_parm.qos_flags |=
1360 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
1361
1362#ifdef CONFIG_IWL4965_HT
1363 if (priv->current_ht_config.is_ht)
1364 priv->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
1365#endif /* CONFIG_IWL4965_HT */
1366
1367 spin_unlock_irqrestore(&priv->lock, flags);
1368
1369 if (force || iwl_is_associated(priv)) {
1370 IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n",
1371 priv->qos_data.qos_active,
1372 priv->qos_data.def_qos_parm.qos_flags);
1373
1374 iwl4965_send_qos_params_command(priv,
1375 &(priv->qos_data.def_qos_parm));
1376 }
1377}
1378
1379/*
1380 * Power management (not Tx power!) functions
1381 */
1382#define MSEC_TO_USEC 1024
1383
1384#define NOSLP __constant_cpu_to_le16(0), 0, 0
1385#define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK, 0, 0
1386#define SLP_TIMEOUT(T) __constant_cpu_to_le32((T) * MSEC_TO_USEC)
1387#define SLP_VEC(X0, X1, X2, X3, X4) {__constant_cpu_to_le32(X0), \
1388 __constant_cpu_to_le32(X1), \
1389 __constant_cpu_to_le32(X2), \
1390 __constant_cpu_to_le32(X3), \
1391 __constant_cpu_to_le32(X4)}
1392
1393
1394/* default power management (not Tx power) table values */
1395/* for tim 0-10 */
1396static struct iwl4965_power_vec_entry range_0[IWL_POWER_AC] = {
1397 {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
1398 {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0},
1399 {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0},
1400 {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100), SLP_VEC(2, 6, 9, 9, 10)}, 0},
1401 {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 10)}, 1},
1402 {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25), SLP_VEC(4, 7, 10, 10, 10)}, 1}
1403};
1404
1405/* for tim > 10 */
1406static struct iwl4965_power_vec_entry range_1[IWL_POWER_AC] = {
1407 {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
1408 {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500),
1409 SLP_VEC(1, 2, 3, 4, 0xFF)}, 0},
1410 {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300),
1411 SLP_VEC(2, 4, 6, 7, 0xFF)}, 0},
1412 {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100),
1413 SLP_VEC(2, 6, 9, 9, 0xFF)}, 0},
1414 {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0},
1415 {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25),
1416 SLP_VEC(4, 7, 10, 10, 0xFF)}, 0}
1417};
1418
1419int iwl4965_power_init_handle(struct iwl_priv *priv)
1420{
1421 int rc = 0, i;
1422 struct iwl4965_power_mgr *pow_data;
1423 int size = sizeof(struct iwl4965_power_vec_entry) * IWL_POWER_AC;
1424 u16 pci_pm;
1425
1426 IWL_DEBUG_POWER("Initialize power \n");
1427
1428 pow_data = &(priv->power_data);
1429
1430 memset(pow_data, 0, sizeof(*pow_data));
1431
1432 pow_data->active_index = IWL_POWER_RANGE_0;
1433 pow_data->dtim_val = 0xffff;
1434
1435 memcpy(&pow_data->pwr_range_0[0], &range_0[0], size);
1436 memcpy(&pow_data->pwr_range_1[0], &range_1[0], size);
1437
1438 rc = pci_read_config_word(priv->pci_dev, PCI_LINK_CTRL, &pci_pm);
1439 if (rc != 0)
1440 return 0;
1441 else {
1442 struct iwl4965_powertable_cmd *cmd;
1443
1444 IWL_DEBUG_POWER("adjust power command flags\n");
1445
1446 for (i = 0; i < IWL_POWER_AC; i++) {
1447 cmd = &pow_data->pwr_range_0[i].cmd;
1448
1449 if (pci_pm & 0x1)
1450 cmd->flags &= ~IWL_POWER_PCI_PM_MSK;
1451 else
1452 cmd->flags |= IWL_POWER_PCI_PM_MSK;
1453 }
1454 }
1455 return rc;
1456}
1457
1458static int iwl4965_update_power_cmd(struct iwl_priv *priv,
1459 struct iwl4965_powertable_cmd *cmd, u32 mode)
1460{
1461 int rc = 0, i;
1462 u8 skip;
1463 u32 max_sleep = 0;
1464 struct iwl4965_power_vec_entry *range;
1465 u8 period = 0;
1466 struct iwl4965_power_mgr *pow_data;
1467
1468 if (mode > IWL_POWER_INDEX_5) {
1469 IWL_DEBUG_POWER("Error invalid power mode \n");
1470 return -1;
1471 }
1472 pow_data = &(priv->power_data);
1473
1474 if (pow_data->active_index == IWL_POWER_RANGE_0)
1475 range = &pow_data->pwr_range_0[0];
1476 else
1477 range = &pow_data->pwr_range_1[1];
1478
1479 memcpy(cmd, &range[mode].cmd, sizeof(struct iwl4965_powertable_cmd));
1480
1481#ifdef IWL_MAC80211_DISABLE
1482 if (priv->assoc_network != NULL) {
1483 unsigned long flags;
1484
1485 period = priv->assoc_network->tim.tim_period;
1486 }
1487#endif /*IWL_MAC80211_DISABLE */
1488 skip = range[mode].no_dtim;
1489
1490 if (period == 0) {
1491 period = 1;
1492 skip = 0;
1493 }
1494
1495 if (skip == 0) {
1496 max_sleep = period;
1497 cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK;
1498 } else {
1499 __le32 slp_itrvl = cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1];
1500 max_sleep = (le32_to_cpu(slp_itrvl) / period) * period;
1501 cmd->flags |= IWL_POWER_SLEEP_OVER_DTIM_MSK;
1502 }
1503
1504 for (i = 0; i < IWL_POWER_VEC_SIZE; i++) {
1505 if (le32_to_cpu(cmd->sleep_interval[i]) > max_sleep)
1506 cmd->sleep_interval[i] = cpu_to_le32(max_sleep);
1507 }
1508
1509 IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd->flags);
1510 IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd->tx_data_timeout));
1511 IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd->rx_data_timeout));
1512 IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n",
1513 le32_to_cpu(cmd->sleep_interval[0]),
1514 le32_to_cpu(cmd->sleep_interval[1]),
1515 le32_to_cpu(cmd->sleep_interval[2]),
1516 le32_to_cpu(cmd->sleep_interval[3]),
1517 le32_to_cpu(cmd->sleep_interval[4]));
1518
1519 return rc;
1520}
1521
1522static int iwl4965_send_power_mode(struct iwl_priv *priv, u32 mode)
1523{
1524 u32 uninitialized_var(final_mode);
1525 int rc;
1526 struct iwl4965_powertable_cmd cmd;
1527
1528 /* If on battery, set to 3,
1529 * if plugged into AC power, set to CAM ("continuously aware mode"),
1530 * else user level */
1531 switch (mode) {
1532 case IWL_POWER_BATTERY:
1533 final_mode = IWL_POWER_INDEX_3;
1534 break;
1535 case IWL_POWER_AC:
1536 final_mode = IWL_POWER_MODE_CAM;
1537 break;
1538 default:
1539 final_mode = mode;
1540 break;
1541 }
1542
1543 cmd.keep_alive_beacons = 0;
1544
1545 iwl4965_update_power_cmd(priv, &cmd, final_mode);
1546
1547 rc = iwl_send_cmd_pdu(priv, POWER_TABLE_CMD, sizeof(cmd), &cmd);
1548
1549 if (final_mode == IWL_POWER_MODE_CAM)
1550 clear_bit(STATUS_POWER_PMI, &priv->status);
1551 else
1552 set_bit(STATUS_POWER_PMI, &priv->status);
1553
1554 return rc;
1555}
1556
1557int iwl4965_is_network_packet(struct iwl_priv *priv, struct ieee80211_hdr *header)
1558{
1559 /* Filter incoming packets to determine if they are targeted toward
1560 * this network, discarding packets coming from ourselves */
1561 switch (priv->iw_mode) {
1562 case IEEE80211_IF_TYPE_IBSS: /* Header: Dest. | Source | BSSID */
1563 /* packets from our adapter are dropped (echo) */
1564 if (!compare_ether_addr(header->addr2, priv->mac_addr))
1565 return 0;
1566 /* {broad,multi}cast packets to our IBSS go through */
1567 if (is_multicast_ether_addr(header->addr1))
1568 return !compare_ether_addr(header->addr3, priv->bssid);
1569 /* packets to our adapter go through */
1570 return !compare_ether_addr(header->addr1, priv->mac_addr);
1571 case IEEE80211_IF_TYPE_STA: /* Header: Dest. | AP{BSSID} | Source */
1572 /* packets from our adapter are dropped (echo) */
1573 if (!compare_ether_addr(header->addr3, priv->mac_addr))
1574 return 0;
1575 /* {broad,multi}cast packets to our BSS go through */
1576 if (is_multicast_ether_addr(header->addr1))
1577 return !compare_ether_addr(header->addr2, priv->bssid);
1578 /* packets to our adapter go through */
1579 return !compare_ether_addr(header->addr1, priv->mac_addr);
1580 default:
1581 break;
1582 }
1583
1584 return 1;
1585}
1586
1587#define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
1588
1589static const char *iwl4965_get_tx_fail_reason(u32 status)
1590{
1591 switch (status & TX_STATUS_MSK) {
1592 case TX_STATUS_SUCCESS:
1593 return "SUCCESS";
1594 TX_STATUS_ENTRY(SHORT_LIMIT);
1595 TX_STATUS_ENTRY(LONG_LIMIT);
1596 TX_STATUS_ENTRY(FIFO_UNDERRUN);
1597 TX_STATUS_ENTRY(MGMNT_ABORT);
1598 TX_STATUS_ENTRY(NEXT_FRAG);
1599 TX_STATUS_ENTRY(LIFE_EXPIRE);
1600 TX_STATUS_ENTRY(DEST_PS);
1601 TX_STATUS_ENTRY(ABORTED);
1602 TX_STATUS_ENTRY(BT_RETRY);
1603 TX_STATUS_ENTRY(STA_INVALID);
1604 TX_STATUS_ENTRY(FRAG_DROPPED);
1605 TX_STATUS_ENTRY(TID_DISABLE);
1606 TX_STATUS_ENTRY(FRAME_FLUSHED);
1607 TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL);
1608 TX_STATUS_ENTRY(TX_LOCKED);
1609 TX_STATUS_ENTRY(NO_BEACON_ON_RADAR);
1610 }
1611
1612 return "UNKNOWN";
1613}
1614
1615/**
1616 * iwl4965_scan_cancel - Cancel any currently executing HW scan
1617 *
1618 * NOTE: priv->mutex is not required before calling this function
1619 */
1620static int iwl4965_scan_cancel(struct iwl_priv *priv)
1621{
1622 if (!test_bit(STATUS_SCAN_HW, &priv->status)) {
1623 clear_bit(STATUS_SCANNING, &priv->status);
1624 return 0;
1625 }
1626
1627 if (test_bit(STATUS_SCANNING, &priv->status)) {
1628 if (!test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
1629 IWL_DEBUG_SCAN("Queuing scan abort.\n");
1630 set_bit(STATUS_SCAN_ABORTING, &priv->status);
1631 queue_work(priv->workqueue, &priv->abort_scan);
1632
1633 } else
1634 IWL_DEBUG_SCAN("Scan abort already in progress.\n");
1635
1636 return test_bit(STATUS_SCANNING, &priv->status);
1637 }
1638
1639 return 0;
1640}
1641
1642/**
1643 * iwl4965_scan_cancel_timeout - Cancel any currently executing HW scan
1644 * @ms: amount of time to wait (in milliseconds) for scan to abort
1645 *
1646 * NOTE: priv->mutex must be held before calling this function
1647 */
1648static int iwl4965_scan_cancel_timeout(struct iwl_priv *priv, unsigned long ms)
1649{
1650 unsigned long now = jiffies;
1651 int ret;
1652
1653 ret = iwl4965_scan_cancel(priv);
1654 if (ret && ms) {
1655 mutex_unlock(&priv->mutex);
1656 while (!time_after(jiffies, now + msecs_to_jiffies(ms)) &&
1657 test_bit(STATUS_SCANNING, &priv->status))
1658 msleep(1);
1659 mutex_lock(&priv->mutex);
1660
1661 return test_bit(STATUS_SCANNING, &priv->status);
1662 }
1663
1664 return ret;
1665}
1666
1667static void iwl4965_sequence_reset(struct iwl_priv *priv)
1668{
1669 /* Reset ieee stats */
1670
1671 /* We don't reset the net_device_stats (ieee->stats) on
1672 * re-association */
1673
1674 priv->last_seq_num = -1;
1675 priv->last_frag_num = -1;
1676 priv->last_packet_time = 0;
1677
1678 iwl4965_scan_cancel(priv);
1679}
1680
1681#define MAX_UCODE_BEACON_INTERVAL 4096
1682#define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
1683
1684static __le16 iwl4965_adjust_beacon_interval(u16 beacon_val)
1685{
1686 u16 new_val = 0;
1687 u16 beacon_factor = 0;
1688
1689 beacon_factor =
1690 (beacon_val + MAX_UCODE_BEACON_INTERVAL)
1691 / MAX_UCODE_BEACON_INTERVAL;
1692 new_val = beacon_val / beacon_factor;
1693
1694 return cpu_to_le16(new_val);
1695}
1696
1697static void iwl4965_setup_rxon_timing(struct iwl_priv *priv)
1698{
1699 u64 interval_tm_unit;
1700 u64 tsf, result;
1701 unsigned long flags;
1702 struct ieee80211_conf *conf = NULL;
1703 u16 beacon_int = 0;
1704
1705 conf = ieee80211_get_hw_conf(priv->hw);
1706
1707 spin_lock_irqsave(&priv->lock, flags);
1708 priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp >> 32);
1709 priv->rxon_timing.timestamp.dw[0] =
1710 cpu_to_le32(priv->timestamp & 0xFFFFFFFF);
1711
1712 priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL;
1713
1714 tsf = priv->timestamp;
1715
1716 beacon_int = priv->beacon_int;
1717 spin_unlock_irqrestore(&priv->lock, flags);
1718
1719 if (priv->iw_mode == IEEE80211_IF_TYPE_STA) {
1720 if (beacon_int == 0) {
1721 priv->rxon_timing.beacon_interval = cpu_to_le16(100);
1722 priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
1723 } else {
1724 priv->rxon_timing.beacon_interval =
1725 cpu_to_le16(beacon_int);
1726 priv->rxon_timing.beacon_interval =
1727 iwl4965_adjust_beacon_interval(
1728 le16_to_cpu(priv->rxon_timing.beacon_interval));
1729 }
1730
1731 priv->rxon_timing.atim_window = 0;
1732 } else {
1733 priv->rxon_timing.beacon_interval =
1734 iwl4965_adjust_beacon_interval(conf->beacon_int);
1735 /* TODO: we need to get atim_window from upper stack
1736 * for now we set to 0 */
1737 priv->rxon_timing.atim_window = 0;
1738 }
1739
1740 interval_tm_unit =
1741 (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024);
1742 result = do_div(tsf, interval_tm_unit);
1743 priv->rxon_timing.beacon_init_val =
1744 cpu_to_le32((u32) ((u64) interval_tm_unit - result));
1745
1746 IWL_DEBUG_ASSOC
1747 ("beacon interval %d beacon timer %d beacon tim %d\n",
1748 le16_to_cpu(priv->rxon_timing.beacon_interval),
1749 le32_to_cpu(priv->rxon_timing.beacon_init_val),
1750 le16_to_cpu(priv->rxon_timing.atim_window));
1751}
1752
1753static int iwl4965_scan_initiate(struct iwl_priv *priv)
1754{
1755 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
1756 IWL_ERROR("APs don't scan.\n");
1757 return 0;
1758 }
1759
1760 if (!iwl_is_ready_rf(priv)) {
1761 IWL_DEBUG_SCAN("Aborting scan due to not ready.\n");
1762 return -EIO;
1763 }
1764
1765 if (test_bit(STATUS_SCANNING, &priv->status)) {
1766 IWL_DEBUG_SCAN("Scan already in progress.\n");
1767 return -EAGAIN;
1768 }
1769
1770 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
1771 IWL_DEBUG_SCAN("Scan request while abort pending. "
1772 "Queuing.\n");
1773 return -EAGAIN;
1774 }
1775
1776 IWL_DEBUG_INFO("Starting scan...\n");
1777 if (priv->cfg->sku & IWL_SKU_G)
1778 priv->scan_bands |= BIT(IEEE80211_BAND_2GHZ);
1779 if (priv->cfg->sku & IWL_SKU_A)
1780 priv->scan_bands |= BIT(IEEE80211_BAND_5GHZ);
1781 set_bit(STATUS_SCANNING, &priv->status);
1782 priv->scan_start = jiffies;
1783 priv->scan_pass_start = priv->scan_start;
1784
1785 queue_work(priv->workqueue, &priv->request_scan);
1786
1787 return 0;
1788}
1789
1790
1791static void iwl4965_set_flags_for_phymode(struct iwl_priv *priv,
1792 enum ieee80211_band band)
1793{
1794 if (band == IEEE80211_BAND_5GHZ) {
1795 priv->staging_rxon.flags &=
1796 ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
1797 | RXON_FLG_CCK_MSK);
1798 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
1799 } else {
1800 /* Copied from iwl4965_post_associate() */
1801 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
1802 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
1803 else
1804 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
1805
1806 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
1807 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
1808
1809 priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
1810 priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK;
1811 priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK;
1812 }
1813}
1814
1815/*
1816 * initialize rxon structure with default values from eeprom
1817 */
1818static void iwl4965_connection_init_rx_config(struct iwl_priv *priv)
1819{
1820 const struct iwl_channel_info *ch_info;
1821
1822 memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
1823
1824 switch (priv->iw_mode) {
1825 case IEEE80211_IF_TYPE_AP:
1826 priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP;
1827 break;
1828
1829 case IEEE80211_IF_TYPE_STA:
1830 priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS;
1831 priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
1832 break;
1833
1834 case IEEE80211_IF_TYPE_IBSS:
1835 priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS;
1836 priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
1837 priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
1838 RXON_FILTER_ACCEPT_GRP_MSK;
1839 break;
1840
1841 case IEEE80211_IF_TYPE_MNTR:
1842 priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER;
1843 priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK |
1844 RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK;
1845 break;
1846 default:
1847 IWL_ERROR("Unsupported interface type %d\n", priv->iw_mode);
1848 break;
1849 }
1850
1851#if 0
1852 /* TODO: Figure out when short_preamble would be set and cache from
1853 * that */
1854 if (!hw_to_local(priv->hw)->short_preamble)
1855 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
1856 else
1857 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
1858#endif
1859
1860 ch_info = iwl_get_channel_info(priv, priv->band,
1861 le16_to_cpu(priv->staging_rxon.channel));
1862
1863 if (!ch_info)
1864 ch_info = &priv->channel_info[0];
1865
1866 /*
1867 * in some case A channels are all non IBSS
1868 * in this case force B/G channel
1869 */
1870 if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) &&
1871 !(is_channel_ibss(ch_info)))
1872 ch_info = &priv->channel_info[0];
1873
1874 priv->staging_rxon.channel = cpu_to_le16(ch_info->channel);
1875 priv->band = ch_info->band;
1876
1877 iwl4965_set_flags_for_phymode(priv, priv->band);
1878
1879 priv->staging_rxon.ofdm_basic_rates =
1880 (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
1881 priv->staging_rxon.cck_basic_rates =
1882 (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
1883
1884 priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK |
1885 RXON_FLG_CHANNEL_MODE_PURE_40_MSK);
1886 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
1887 memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN);
1888 priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff;
1889 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff;
1890 iwl4965_set_rxon_chain(priv);
1891}
1892
1893static int iwl4965_set_mode(struct iwl_priv *priv, int mode)
1894{
1895 if (mode == IEEE80211_IF_TYPE_IBSS) {
1896 const struct iwl_channel_info *ch_info;
1897
1898 ch_info = iwl_get_channel_info(priv,
1899 priv->band,
1900 le16_to_cpu(priv->staging_rxon.channel));
1901
1902 if (!ch_info || !is_channel_ibss(ch_info)) {
1903 IWL_ERROR("channel %d not IBSS channel\n",
1904 le16_to_cpu(priv->staging_rxon.channel));
1905 return -EINVAL;
1906 }
1907 }
1908
1909 priv->iw_mode = mode;
1910
1911 iwl4965_connection_init_rx_config(priv);
1912 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
1913
1914 iwlcore_clear_stations_table(priv);
1915
1916 /* dont commit rxon if rf-kill is on*/
1917 if (!iwl_is_ready_rf(priv))
1918 return -EAGAIN;
1919
1920 cancel_delayed_work(&priv->scan_check);
1921 if (iwl4965_scan_cancel_timeout(priv, 100)) {
1922 IWL_WARNING("Aborted scan still in progress after 100ms\n");
1923 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
1924 return -EAGAIN;
1925 }
1926
1927 iwl4965_commit_rxon(priv);
1928
1929 return 0;
1930}
1931
1932static void iwl4965_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
1933 struct ieee80211_tx_control *ctl,
1934 struct iwl_cmd *cmd,
1935 struct sk_buff *skb_frag,
1936 int sta_id)
1937{
1938 struct iwl4965_hw_key *keyinfo = &priv->stations[sta_id].keyinfo;
1939 struct iwl_wep_key *wepkey;
1940 int keyidx = 0;
1941
1942 BUG_ON(ctl->key_idx > 3);
1943
1944 switch (keyinfo->alg) {
1945 case ALG_CCMP:
1946 cmd->cmd.tx.sec_ctl = TX_CMD_SEC_CCM;
1947 memcpy(cmd->cmd.tx.key, keyinfo->key, keyinfo->keylen);
1948 if (ctl->flags & IEEE80211_TXCTL_AMPDU)
1949 cmd->cmd.tx.tx_flags |= TX_CMD_FLG_AGG_CCMP_MSK;
1950 IWL_DEBUG_TX("tx_cmd with aes hwcrypto\n");
1951 break;
1952
1953 case ALG_TKIP:
1954 cmd->cmd.tx.sec_ctl = TX_CMD_SEC_TKIP;
1955 ieee80211_get_tkip_key(keyinfo->conf, skb_frag,
1956 IEEE80211_TKIP_P2_KEY, cmd->cmd.tx.key);
1957 IWL_DEBUG_TX("tx_cmd with tkip hwcrypto\n");
1958 break;
1959
1960 case ALG_WEP:
1961 wepkey = &priv->wep_keys[ctl->key_idx];
1962 cmd->cmd.tx.sec_ctl = 0;
1963 if (priv->default_wep_key) {
1964 /* the WEP key was sent as static */
1965 keyidx = ctl->key_idx;
1966 memcpy(&cmd->cmd.tx.key[3], wepkey->key,
1967 wepkey->key_size);
1968 if (wepkey->key_size == WEP_KEY_LEN_128)
1969 cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128;
1970 } else {
1971 /* the WEP key was sent as dynamic */
1972 keyidx = keyinfo->keyidx;
1973 memcpy(&cmd->cmd.tx.key[3], keyinfo->key,
1974 keyinfo->keylen);
1975 if (keyinfo->keylen == WEP_KEY_LEN_128)
1976 cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128;
1977 }
1978
1979 cmd->cmd.tx.sec_ctl |= (TX_CMD_SEC_WEP |
1980 (keyidx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT);
1981
1982 IWL_DEBUG_TX("Configuring packet for WEP encryption "
1983 "with key %d\n", keyidx);
1984 break;
1985
1986 default:
1987 printk(KERN_ERR "Unknown encode alg %d\n", keyinfo->alg);
1988 break;
1989 }
1990}
1991
1992/*
1993 * handle build REPLY_TX command notification.
1994 */
1995static void iwl4965_build_tx_cmd_basic(struct iwl_priv *priv,
1996 struct iwl_cmd *cmd,
1997 struct ieee80211_tx_control *ctrl,
1998 struct ieee80211_hdr *hdr,
1999 int is_unicast, u8 std_id)
2000{
2001 __le16 *qc;
2002 u16 fc = le16_to_cpu(hdr->frame_control);
2003 __le32 tx_flags = cmd->cmd.tx.tx_flags;
2004
2005 cmd->cmd.tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
2006 if (!(ctrl->flags & IEEE80211_TXCTL_NO_ACK)) {
2007 tx_flags |= TX_CMD_FLG_ACK_MSK;
2008 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)
2009 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
2010 if (ieee80211_is_probe_response(fc) &&
2011 !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
2012 tx_flags |= TX_CMD_FLG_TSF_MSK;
2013 } else {
2014 tx_flags &= (~TX_CMD_FLG_ACK_MSK);
2015 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
2016 }
2017
2018 if (ieee80211_is_back_request(fc))
2019 tx_flags |= TX_CMD_FLG_ACK_MSK | TX_CMD_FLG_IMM_BA_RSP_MASK;
2020
2021
2022 cmd->cmd.tx.sta_id = std_id;
2023 if (ieee80211_get_morefrag(hdr))
2024 tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
2025
2026 qc = ieee80211_get_qos_ctrl(hdr);
2027 if (qc) {
2028 cmd->cmd.tx.tid_tspec = (u8) (le16_to_cpu(*qc) & 0xf);
2029 tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
2030 } else
2031 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
2032
2033 if (ctrl->flags & IEEE80211_TXCTL_USE_RTS_CTS) {
2034 tx_flags |= TX_CMD_FLG_RTS_MSK;
2035 tx_flags &= ~TX_CMD_FLG_CTS_MSK;
2036 } else if (ctrl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) {
2037 tx_flags &= ~TX_CMD_FLG_RTS_MSK;
2038 tx_flags |= TX_CMD_FLG_CTS_MSK;
2039 }
2040
2041 if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK))
2042 tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
2043
2044 tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
2045 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) {
2046 if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ ||
2047 (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ)
2048 cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(3);
2049 else
2050 cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(2);
2051 } else {
2052 cmd->cmd.tx.timeout.pm_frame_timeout = 0;
2053 }
2054
2055 cmd->cmd.tx.driver_txop = 0;
2056 cmd->cmd.tx.tx_flags = tx_flags;
2057 cmd->cmd.tx.next_frame_len = 0;
2058}
2059static void iwl_update_tx_stats(struct iwl_priv *priv, u16 fc, u16 len)
2060{
2061 /* 0 - mgmt, 1 - cnt, 2 - data */
2062 int idx = (fc & IEEE80211_FCTL_FTYPE) >> 2;
2063 priv->tx_stats[idx].cnt++;
2064 priv->tx_stats[idx].bytes += len;
2065}
2066/**
2067 * iwl4965_get_sta_id - Find station's index within station table
2068 *
2069 * If new IBSS station, create new entry in station table
2070 */
2071static int iwl4965_get_sta_id(struct iwl_priv *priv,
2072 struct ieee80211_hdr *hdr)
2073{
2074 int sta_id;
2075 u16 fc = le16_to_cpu(hdr->frame_control);
2076 DECLARE_MAC_BUF(mac);
2077
2078 /* If this frame is broadcast or management, use broadcast station id */
2079 if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
2080 is_multicast_ether_addr(hdr->addr1))
2081 return priv->hw_params.bcast_sta_id;
2082
2083 switch (priv->iw_mode) {
2084
2085 /* If we are a client station in a BSS network, use the special
2086 * AP station entry (that's the only station we communicate with) */
2087 case IEEE80211_IF_TYPE_STA:
2088 return IWL_AP_ID;
2089
2090 /* If we are an AP, then find the station, or use BCAST */
2091 case IEEE80211_IF_TYPE_AP:
2092 sta_id = iwl4965_hw_find_station(priv, hdr->addr1);
2093 if (sta_id != IWL_INVALID_STATION)
2094 return sta_id;
2095 return priv->hw_params.bcast_sta_id;
2096
2097 /* If this frame is going out to an IBSS network, find the station,
2098 * or create a new station table entry */
2099 case IEEE80211_IF_TYPE_IBSS:
2100 sta_id = iwl4965_hw_find_station(priv, hdr->addr1);
2101 if (sta_id != IWL_INVALID_STATION)
2102 return sta_id;
2103
2104 /* Create new station table entry */
2105 sta_id = iwl4965_add_station_flags(priv, hdr->addr1,
2106 0, CMD_ASYNC, NULL);
2107
2108 if (sta_id != IWL_INVALID_STATION)
2109 return sta_id;
2110
2111 IWL_DEBUG_DROP("Station %s not in station map. "
2112 "Defaulting to broadcast...\n",
2113 print_mac(mac, hdr->addr1));
2114 iwl_print_hex_dump(IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
2115 return priv->hw_params.bcast_sta_id;
2116
2117 default:
2118 IWL_WARNING("Unknown mode of operation: %d", priv->iw_mode);
2119 return priv->hw_params.bcast_sta_id;
2120 }
2121}
2122
2123/*
2124 * start REPLY_TX command process
2125 */
2126static int iwl4965_tx_skb(struct iwl_priv *priv,
2127 struct sk_buff *skb, struct ieee80211_tx_control *ctl)
2128{
2129 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2130 struct iwl4965_tfd_frame *tfd;
2131 u32 *control_flags;
2132 int txq_id = ctl->queue;
2133 struct iwl4965_tx_queue *txq = NULL;
2134 struct iwl4965_queue *q = NULL;
2135 dma_addr_t phys_addr;
2136 dma_addr_t txcmd_phys;
2137 dma_addr_t scratch_phys;
2138 struct iwl_cmd *out_cmd = NULL;
2139 u16 len, idx, len_org;
2140 u8 id, hdr_len, unicast;
2141 u8 sta_id;
2142 u16 seq_number = 0;
2143 u16 fc;
2144 __le16 *qc;
2145 u8 wait_write_ptr = 0;
2146 unsigned long flags;
2147 int rc;
2148
2149 spin_lock_irqsave(&priv->lock, flags);
2150 if (iwl_is_rfkill(priv)) {
2151 IWL_DEBUG_DROP("Dropping - RF KILL\n");
2152 goto drop_unlock;
2153 }
2154
2155 if (!priv->vif) {
2156 IWL_DEBUG_DROP("Dropping - !priv->vif\n");
2157 goto drop_unlock;
2158 }
2159
2160 if ((ctl->tx_rate->hw_value & 0xFF) == IWL_INVALID_RATE) {
2161 IWL_ERROR("ERROR: No TX rate available.\n");
2162 goto drop_unlock;
2163 }
2164
2165 unicast = !is_multicast_ether_addr(hdr->addr1);
2166 id = 0;
2167
2168 fc = le16_to_cpu(hdr->frame_control);
2169
2170#ifdef CONFIG_IWLWIFI_DEBUG
2171 if (ieee80211_is_auth(fc))
2172 IWL_DEBUG_TX("Sending AUTH frame\n");
2173 else if (ieee80211_is_assoc_request(fc))
2174 IWL_DEBUG_TX("Sending ASSOC frame\n");
2175 else if (ieee80211_is_reassoc_request(fc))
2176 IWL_DEBUG_TX("Sending REASSOC frame\n");
2177#endif
2178
2179 /* drop all data frame if we are not associated */
2180 if (((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) &&
2181 (!iwl_is_associated(priv) ||
2182 ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && !priv->assoc_id) ||
2183 !priv->assoc_station_added)) {
2184 IWL_DEBUG_DROP("Dropping - !iwl_is_associated\n");
2185 goto drop_unlock;
2186 }
2187
2188 spin_unlock_irqrestore(&priv->lock, flags);
2189
2190 hdr_len = ieee80211_get_hdrlen(fc);
2191
2192 /* Find (or create) index into station table for destination station */
2193 sta_id = iwl4965_get_sta_id(priv, hdr);
2194 if (sta_id == IWL_INVALID_STATION) {
2195 DECLARE_MAC_BUF(mac);
2196
2197 IWL_DEBUG_DROP("Dropping - INVALID STATION: %s\n",
2198 print_mac(mac, hdr->addr1));
2199 goto drop;
2200 }
2201
2202 IWL_DEBUG_RATE("station Id %d\n", sta_id);
2203
2204 qc = ieee80211_get_qos_ctrl(hdr);
2205 if (qc) {
2206 u8 tid = (u8)(le16_to_cpu(*qc) & 0xf);
2207 seq_number = priv->stations[sta_id].tid[tid].seq_number &
2208 IEEE80211_SCTL_SEQ;
2209 hdr->seq_ctrl = cpu_to_le16(seq_number) |
2210 (hdr->seq_ctrl &
2211 __constant_cpu_to_le16(IEEE80211_SCTL_FRAG));
2212 seq_number += 0x10;
2213#ifdef CONFIG_IWL4965_HT
2214 /* aggregation is on for this <sta,tid> */
2215 if (ctl->flags & IEEE80211_TXCTL_AMPDU)
2216 txq_id = priv->stations[sta_id].tid[tid].agg.txq_id;
2217 priv->stations[sta_id].tid[tid].tfds_in_queue++;
2218#endif /* CONFIG_IWL4965_HT */
2219 }
2220
2221 /* Descriptor for chosen Tx queue */
2222 txq = &priv->txq[txq_id];
2223 q = &txq->q;
2224
2225 spin_lock_irqsave(&priv->lock, flags);
2226
2227 /* Set up first empty TFD within this queue's circular TFD buffer */
2228 tfd = &txq->bd[q->write_ptr];
2229 memset(tfd, 0, sizeof(*tfd));
2230 control_flags = (u32 *) tfd;
2231 idx = get_cmd_index(q, q->write_ptr, 0);
2232
2233 /* Set up driver data for this TFD */
2234 memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl4965_tx_info));
2235 txq->txb[q->write_ptr].skb[0] = skb;
2236 memcpy(&(txq->txb[q->write_ptr].status.control),
2237 ctl, sizeof(struct ieee80211_tx_control));
2238
2239 /* Set up first empty entry in queue's array of Tx/cmd buffers */
2240 out_cmd = &txq->cmd[idx];
2241 memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
2242 memset(&out_cmd->cmd.tx, 0, sizeof(out_cmd->cmd.tx));
2243
2244 /*
2245 * Set up the Tx-command (not MAC!) header.
2246 * Store the chosen Tx queue and TFD index within the sequence field;
2247 * after Tx, uCode's Tx response will return this value so driver can
2248 * locate the frame within the tx queue and do post-tx processing.
2249 */
2250 out_cmd->hdr.cmd = REPLY_TX;
2251 out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
2252 INDEX_TO_SEQ(q->write_ptr)));
2253
2254 /* Copy MAC header from skb into command buffer */
2255 memcpy(out_cmd->cmd.tx.hdr, hdr, hdr_len);
2256
2257 /*
2258 * Use the first empty entry in this queue's command buffer array
2259 * to contain the Tx command and MAC header concatenated together
2260 * (payload data will be in another buffer).
2261 * Size of this varies, due to varying MAC header length.
2262 * If end is not dword aligned, we'll have 2 extra bytes at the end
2263 * of the MAC header (device reads on dword boundaries).
2264 * We'll tell device about this padding later.
2265 */
2266 len = priv->hw_params.tx_cmd_len +
2267 sizeof(struct iwl_cmd_header) + hdr_len;
2268
2269 len_org = len;
2270 len = (len + 3) & ~3;
2271
2272 if (len_org != len)
2273 len_org = 1;
2274 else
2275 len_org = 0;
2276
2277 /* Physical address of this Tx command's header (not MAC header!),
2278 * within command buffer array. */
2279 txcmd_phys = txq->dma_addr_cmd + sizeof(struct iwl_cmd) * idx +
2280 offsetof(struct iwl_cmd, hdr);
2281
2282 /* Add buffer containing Tx command and MAC(!) header to TFD's
2283 * first entry */
2284 iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len);
2285
2286 if (!(ctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT))
2287 iwl4965_build_tx_cmd_hwcrypto(priv, ctl, out_cmd, skb, sta_id);
2288
2289 /* Set up TFD's 2nd entry to point directly to remainder of skb,
2290 * if any (802.11 null frames have no payload). */
2291 len = skb->len - hdr_len;
2292 if (len) {
2293 phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
2294 len, PCI_DMA_TODEVICE);
2295 iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, len);
2296 }
2297
2298 /* Tell 4965 about any 2-byte padding after MAC header */
2299 if (len_org)
2300 out_cmd->cmd.tx.tx_flags |= TX_CMD_FLG_MH_PAD_MSK;
2301
2302 /* Total # bytes to be transmitted */
2303 len = (u16)skb->len;
2304 out_cmd->cmd.tx.len = cpu_to_le16(len);
2305
2306 /* TODO need this for burst mode later on */
2307 iwl4965_build_tx_cmd_basic(priv, out_cmd, ctl, hdr, unicast, sta_id);
2308
2309 /* set is_hcca to 0; it probably will never be implemented */
2310 iwl4965_hw_build_tx_cmd_rate(priv, out_cmd, ctl, hdr, sta_id, 0);
2311
2312 iwl_update_tx_stats(priv, fc, len);
2313
2314 scratch_phys = txcmd_phys + sizeof(struct iwl_cmd_header) +
2315 offsetof(struct iwl4965_tx_cmd, scratch);
2316 out_cmd->cmd.tx.dram_lsb_ptr = cpu_to_le32(scratch_phys);
2317 out_cmd->cmd.tx.dram_msb_ptr = iwl_get_dma_hi_address(scratch_phys);
2318
2319 if (!ieee80211_get_morefrag(hdr)) {
2320 txq->need_update = 1;
2321 if (qc) {
2322 u8 tid = (u8)(le16_to_cpu(*qc) & 0xf);
2323 priv->stations[sta_id].tid[tid].seq_number = seq_number;
2324 }
2325 } else {
2326 wait_write_ptr = 1;
2327 txq->need_update = 0;
2328 }
2329
2330 iwl_print_hex_dump(IWL_DL_TX, out_cmd->cmd.payload,
2331 sizeof(out_cmd->cmd.tx));
2332
2333 iwl_print_hex_dump(IWL_DL_TX, (u8 *)out_cmd->cmd.tx.hdr,
2334 ieee80211_get_hdrlen(fc));
2335
2336 /* Set up entry for this TFD in Tx byte-count array */
2337 priv->cfg->ops->lib->txq_update_byte_cnt_tbl(priv, txq, len);
2338
2339 /* Tell device the write index *just past* this latest filled TFD */
2340 q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
2341 rc = iwl4965_tx_queue_update_write_ptr(priv, txq);
2342 spin_unlock_irqrestore(&priv->lock, flags);
2343
2344 if (rc)
2345 return rc;
2346
2347 if ((iwl4965_queue_space(q) < q->high_mark)
2348 && priv->mac80211_registered) {
2349 if (wait_write_ptr) {
2350 spin_lock_irqsave(&priv->lock, flags);
2351 txq->need_update = 1;
2352 iwl4965_tx_queue_update_write_ptr(priv, txq);
2353 spin_unlock_irqrestore(&priv->lock, flags);
2354 }
2355
2356 ieee80211_stop_queue(priv->hw, ctl->queue);
2357 }
2358
2359 return 0;
2360
2361drop_unlock:
2362 spin_unlock_irqrestore(&priv->lock, flags);
2363drop:
2364 return -1;
2365}
2366
2367static void iwl4965_set_rate(struct iwl_priv *priv)
2368{
2369 const struct ieee80211_supported_band *hw = NULL;
2370 struct ieee80211_rate *rate;
2371 int i;
2372
2373 hw = iwl4965_get_hw_mode(priv, priv->band);
2374 if (!hw) {
2375 IWL_ERROR("Failed to set rate: unable to get hw mode\n");
2376 return;
2377 }
2378
2379 priv->active_rate = 0;
2380 priv->active_rate_basic = 0;
2381
2382 for (i = 0; i < hw->n_bitrates; i++) {
2383 rate = &(hw->bitrates[i]);
2384 if (rate->hw_value < IWL_RATE_COUNT)
2385 priv->active_rate |= (1 << rate->hw_value);
2386 }
2387
2388 IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
2389 priv->active_rate, priv->active_rate_basic);
2390
2391 /*
2392 * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
2393 * otherwise set it to the default of all CCK rates and 6, 12, 24 for
2394 * OFDM
2395 */
2396 if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK)
2397 priv->staging_rxon.cck_basic_rates =
2398 ((priv->active_rate_basic &
2399 IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF;
2400 else
2401 priv->staging_rxon.cck_basic_rates =
2402 (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
2403
2404 if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK)
2405 priv->staging_rxon.ofdm_basic_rates =
2406 ((priv->active_rate_basic &
2407 (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >>
2408 IWL_FIRST_OFDM_RATE) & 0xFF;
2409 else
2410 priv->staging_rxon.ofdm_basic_rates =
2411 (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
2412}
2413
2414void iwl4965_radio_kill_sw(struct iwl_priv *priv, int disable_radio)
2415{
2416 unsigned long flags;
2417
2418 if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status))
2419 return;
2420
2421 IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n",
2422 disable_radio ? "OFF" : "ON");
2423
2424 if (disable_radio) {
2425 iwl4965_scan_cancel(priv);
2426 /* FIXME: This is a workaround for AP */
2427 if (priv->iw_mode != IEEE80211_IF_TYPE_AP) {
2428 spin_lock_irqsave(&priv->lock, flags);
2429 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
2430 CSR_UCODE_SW_BIT_RFKILL);
2431 spin_unlock_irqrestore(&priv->lock, flags);
2432 /* call the host command only if no hw rf-kill set */
2433 if (!test_bit(STATUS_RF_KILL_HW, &priv->status) &&
2434 iwl_is_ready(priv))
2435 iwl4965_send_card_state(priv,
2436 CARD_STATE_CMD_DISABLE,
2437 0);
2438 set_bit(STATUS_RF_KILL_SW, &priv->status);
2439
2440 /* make sure mac80211 stop sending Tx frame */
2441 if (priv->mac80211_registered)
2442 ieee80211_stop_queues(priv->hw);
2443 }
2444 return;
2445 }
2446
2447 spin_lock_irqsave(&priv->lock, flags);
2448 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2449
2450 clear_bit(STATUS_RF_KILL_SW, &priv->status);
2451 spin_unlock_irqrestore(&priv->lock, flags);
2452
2453 /* wake up ucode */
2454 msleep(10);
2455
2456 spin_lock_irqsave(&priv->lock, flags);
2457 iwl_read32(priv, CSR_UCODE_DRV_GP1);
2458 if (!iwl_grab_nic_access(priv))
2459 iwl_release_nic_access(priv);
2460 spin_unlock_irqrestore(&priv->lock, flags);
2461
2462 if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
2463 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
2464 "disabled by HW switch\n");
2465 return;
2466 }
2467
2468 queue_work(priv->workqueue, &priv->restart);
2469 return;
2470}
2471
2472void iwl4965_set_decrypted_flag(struct iwl_priv *priv, struct sk_buff *skb,
2473 u32 decrypt_res, struct ieee80211_rx_status *stats)
2474{
2475 u16 fc =
2476 le16_to_cpu(((struct ieee80211_hdr *)skb->data)->frame_control);
2477
2478 if (priv->active_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK)
2479 return;
2480
2481 if (!(fc & IEEE80211_FCTL_PROTECTED))
2482 return;
2483
2484 IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res);
2485 switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) {
2486 case RX_RES_STATUS_SEC_TYPE_TKIP:
2487 /* The uCode has got a bad phase 1 Key, pushes the packet.
2488 * Decryption will be done in SW. */
2489 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
2490 RX_RES_STATUS_BAD_KEY_TTAK)
2491 break;
2492
2493 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
2494 RX_RES_STATUS_BAD_ICV_MIC)
2495 stats->flag |= RX_FLAG_MMIC_ERROR;
2496 case RX_RES_STATUS_SEC_TYPE_WEP:
2497 case RX_RES_STATUS_SEC_TYPE_CCMP:
2498 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
2499 RX_RES_STATUS_DECRYPT_OK) {
2500 IWL_DEBUG_RX("hw decrypt successfully!!!\n");
2501 stats->flag |= RX_FLAG_DECRYPTED;
2502 }
2503 break;
2504
2505 default:
2506 break;
2507 }
2508}
2509
2510
2511#define IWL_PACKET_RETRY_TIME HZ
2512
2513int iwl4965_is_duplicate_packet(struct iwl_priv *priv, struct ieee80211_hdr *header)
2514{
2515 u16 sc = le16_to_cpu(header->seq_ctrl);
2516 u16 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
2517 u16 frag = sc & IEEE80211_SCTL_FRAG;
2518 u16 *last_seq, *last_frag;
2519 unsigned long *last_time;
2520
2521 switch (priv->iw_mode) {
2522 case IEEE80211_IF_TYPE_IBSS:{
2523 struct list_head *p;
2524 struct iwl4965_ibss_seq *entry = NULL;
2525 u8 *mac = header->addr2;
2526 int index = mac[5] & (IWL_IBSS_MAC_HASH_SIZE - 1);
2527
2528 __list_for_each(p, &priv->ibss_mac_hash[index]) {
2529 entry = list_entry(p, struct iwl4965_ibss_seq, list);
2530 if (!compare_ether_addr(entry->mac, mac))
2531 break;
2532 }
2533 if (p == &priv->ibss_mac_hash[index]) {
2534 entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
2535 if (!entry) {
2536 IWL_ERROR("Cannot malloc new mac entry\n");
2537 return 0;
2538 }
2539 memcpy(entry->mac, mac, ETH_ALEN);
2540 entry->seq_num = seq;
2541 entry->frag_num = frag;
2542 entry->packet_time = jiffies;
2543 list_add(&entry->list, &priv->ibss_mac_hash[index]);
2544 return 0;
2545 }
2546 last_seq = &entry->seq_num;
2547 last_frag = &entry->frag_num;
2548 last_time = &entry->packet_time;
2549 break;
2550 }
2551 case IEEE80211_IF_TYPE_STA:
2552 last_seq = &priv->last_seq_num;
2553 last_frag = &priv->last_frag_num;
2554 last_time = &priv->last_packet_time;
2555 break;
2556 default:
2557 return 0;
2558 }
2559 if ((*last_seq == seq) &&
2560 time_after(*last_time + IWL_PACKET_RETRY_TIME, jiffies)) {
2561 if (*last_frag == frag)
2562 goto drop;
2563 if (*last_frag + 1 != frag)
2564 /* out-of-order fragment */
2565 goto drop;
2566 } else
2567 *last_seq = seq;
2568
2569 *last_frag = frag;
2570 *last_time = jiffies;
2571 return 0;
2572
2573 drop:
2574 return 1;
2575}
2576
2577#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
2578
2579#include "iwl-spectrum.h"
2580
2581#define BEACON_TIME_MASK_LOW 0x00FFFFFF
2582#define BEACON_TIME_MASK_HIGH 0xFF000000
2583#define TIME_UNIT 1024
2584
2585/*
2586 * extended beacon time format
2587 * time in usec will be changed into a 32-bit value in 8:24 format
2588 * the high 1 byte is the beacon counts
2589 * the lower 3 bytes is the time in usec within one beacon interval
2590 */
2591
2592static u32 iwl4965_usecs_to_beacons(u32 usec, u32 beacon_interval)
2593{
2594 u32 quot;
2595 u32 rem;
2596 u32 interval = beacon_interval * 1024;
2597
2598 if (!interval || !usec)
2599 return 0;
2600
2601 quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
2602 rem = (usec % interval) & BEACON_TIME_MASK_LOW;
2603
2604 return (quot << 24) + rem;
2605}
2606
2607/* base is usually what we get from ucode with each received frame,
2608 * the same as HW timer counter counting down
2609 */
2610
2611static __le32 iwl4965_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
2612{
2613 u32 base_low = base & BEACON_TIME_MASK_LOW;
2614 u32 addon_low = addon & BEACON_TIME_MASK_LOW;
2615 u32 interval = beacon_interval * TIME_UNIT;
2616 u32 res = (base & BEACON_TIME_MASK_HIGH) +
2617 (addon & BEACON_TIME_MASK_HIGH);
2618
2619 if (base_low > addon_low)
2620 res += base_low - addon_low;
2621 else if (base_low < addon_low) {
2622 res += interval + base_low - addon_low;
2623 res += (1 << 24);
2624 } else
2625 res += (1 << 24);
2626
2627 return cpu_to_le32(res);
2628}
2629
2630static int iwl4965_get_measurement(struct iwl_priv *priv,
2631 struct ieee80211_measurement_params *params,
2632 u8 type)
2633{
2634 struct iwl4965_spectrum_cmd spectrum;
2635 struct iwl4965_rx_packet *res;
2636 struct iwl_host_cmd cmd = {
2637 .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
2638 .data = (void *)&spectrum,
2639 .meta.flags = CMD_WANT_SKB,
2640 };
2641 u32 add_time = le64_to_cpu(params->start_time);
2642 int rc;
2643 int spectrum_resp_status;
2644 int duration = le16_to_cpu(params->duration);
2645
2646 if (iwl_is_associated(priv))
2647 add_time =
2648 iwl4965_usecs_to_beacons(
2649 le64_to_cpu(params->start_time) - priv->last_tsf,
2650 le16_to_cpu(priv->rxon_timing.beacon_interval));
2651
2652 memset(&spectrum, 0, sizeof(spectrum));
2653
2654 spectrum.channel_count = cpu_to_le16(1);
2655 spectrum.flags =
2656 RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
2657 spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
2658 cmd.len = sizeof(spectrum);
2659 spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
2660
2661 if (iwl_is_associated(priv))
2662 spectrum.start_time =
2663 iwl4965_add_beacon_time(priv->last_beacon_time,
2664 add_time,
2665 le16_to_cpu(priv->rxon_timing.beacon_interval));
2666 else
2667 spectrum.start_time = 0;
2668
2669 spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
2670 spectrum.channels[0].channel = params->channel;
2671 spectrum.channels[0].type = type;
2672 if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
2673 spectrum.flags |= RXON_FLG_BAND_24G_MSK |
2674 RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
2675
2676 rc = iwl_send_cmd_sync(priv, &cmd);
2677 if (rc)
2678 return rc;
2679
2680 res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data;
2681 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
2682 IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n");
2683 rc = -EIO;
2684 }
2685
2686 spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
2687 switch (spectrum_resp_status) {
2688 case 0: /* Command will be handled */
2689 if (res->u.spectrum.id != 0xff) {
2690 IWL_DEBUG_INFO
2691 ("Replaced existing measurement: %d\n",
2692 res->u.spectrum.id);
2693 priv->measurement_status &= ~MEASUREMENT_READY;
2694 }
2695 priv->measurement_status |= MEASUREMENT_ACTIVE;
2696 rc = 0;
2697 break;
2698
2699 case 1: /* Command will not be handled */
2700 rc = -EAGAIN;
2701 break;
2702 }
2703
2704 dev_kfree_skb_any(cmd.meta.u.skb);
2705
2706 return rc;
2707}
2708#endif
2709
2710static void iwl4965_txstatus_to_ieee(struct iwl_priv *priv,
2711 struct iwl4965_tx_info *tx_sta)
2712{
2713
2714 tx_sta->status.ack_signal = 0;
2715 tx_sta->status.excessive_retries = 0;
2716 tx_sta->status.queue_length = 0;
2717 tx_sta->status.queue_number = 0;
2718
2719 if (in_interrupt())
2720 ieee80211_tx_status_irqsafe(priv->hw,
2721 tx_sta->skb[0], &(tx_sta->status));
2722 else
2723 ieee80211_tx_status(priv->hw,
2724 tx_sta->skb[0], &(tx_sta->status));
2725
2726 tx_sta->skb[0] = NULL;
2727}
2728
2729/**
2730 * iwl4965_tx_queue_reclaim - Reclaim Tx queue entries already Tx'd
2731 *
2732 * When FW advances 'R' index, all entries between old and new 'R' index
2733 * need to be reclaimed. As result, some free space forms. If there is
2734 * enough free space (> low mark), wake the stack that feeds us.
2735 */
2736int iwl4965_tx_queue_reclaim(struct iwl_priv *priv, int txq_id, int index)
2737{
2738 struct iwl4965_tx_queue *txq = &priv->txq[txq_id];
2739 struct iwl4965_queue *q = &txq->q;
2740 int nfreed = 0;
2741
2742 if ((index >= q->n_bd) || (x2_queue_used(q, index) == 0)) {
2743 IWL_ERROR("Read index for DMA queue txq id (%d), index %d, "
2744 "is out of range [0-%d] %d %d.\n", txq_id,
2745 index, q->n_bd, q->write_ptr, q->read_ptr);
2746 return 0;
2747 }
2748
2749 for (index = iwl_queue_inc_wrap(index, q->n_bd);
2750 q->read_ptr != index;
2751 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
2752 if (txq_id != IWL_CMD_QUEUE_NUM) {
2753 iwl4965_txstatus_to_ieee(priv,
2754 &(txq->txb[txq->q.read_ptr]));
2755 iwl4965_hw_txq_free_tfd(priv, txq);
2756 } else if (nfreed > 1) {
2757 IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index,
2758 q->write_ptr, q->read_ptr);
2759 queue_work(priv->workqueue, &priv->restart);
2760 }
2761 nfreed++;
2762 }
2763
2764/* if (iwl4965_queue_space(q) > q->low_mark && (txq_id >= 0) &&
2765 (txq_id != IWL_CMD_QUEUE_NUM) &&
2766 priv->mac80211_registered)
2767 ieee80211_wake_queue(priv->hw, txq_id); */
2768
2769
2770 return nfreed;
2771}
2772
2773static int iwl4965_is_tx_success(u32 status)
2774{
2775 status &= TX_STATUS_MSK;
2776 return (status == TX_STATUS_SUCCESS)
2777 || (status == TX_STATUS_DIRECT_DONE);
2778}
2779
2780/******************************************************************************
2781 *
2782 * Generic RX handler implementations
2783 *
2784 ******************************************************************************/
2785#ifdef CONFIG_IWL4965_HT
2786
2787static inline int iwl4965_get_ra_sta_id(struct iwl_priv *priv,
2788 struct ieee80211_hdr *hdr)
2789{
2790 if (priv->iw_mode == IEEE80211_IF_TYPE_STA)
2791 return IWL_AP_ID;
2792 else {
2793 u8 *da = ieee80211_get_DA(hdr);
2794 return iwl4965_hw_find_station(priv, da);
2795 }
2796}
2797
2798static struct ieee80211_hdr *iwl4965_tx_queue_get_hdr(
2799 struct iwl_priv *priv, int txq_id, int idx)
2800{
2801 if (priv->txq[txq_id].txb[idx].skb[0])
2802 return (struct ieee80211_hdr *)priv->txq[txq_id].
2803 txb[idx].skb[0]->data;
2804 return NULL;
2805}
2806
2807static inline u32 iwl4965_get_scd_ssn(struct iwl4965_tx_resp *tx_resp)
2808{
2809 __le32 *scd_ssn = (__le32 *)((u32 *)&tx_resp->status +
2810 tx_resp->frame_count);
2811 return le32_to_cpu(*scd_ssn) & MAX_SN;
2812
2813}
2814
2815/**
2816 * iwl4965_tx_status_reply_tx - Handle Tx rspnse for frames in aggregation queue
2817 */
2818static int iwl4965_tx_status_reply_tx(struct iwl_priv *priv,
2819 struct iwl4965_ht_agg *agg,
2820 struct iwl4965_tx_resp_agg *tx_resp,
2821 u16 start_idx)
2822{
2823 u16 status;
2824 struct agg_tx_status *frame_status = &tx_resp->status;
2825 struct ieee80211_tx_status *tx_status = NULL;
2826 struct ieee80211_hdr *hdr = NULL;
2827 int i, sh;
2828 int txq_id, idx;
2829 u16 seq;
2830
2831 if (agg->wait_for_ba)
2832 IWL_DEBUG_TX_REPLY("got tx response w/o block-ack\n");
2833
2834 agg->frame_count = tx_resp->frame_count;
2835 agg->start_idx = start_idx;
2836 agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
2837 agg->bitmap = 0;
2838
2839 /* # frames attempted by Tx command */
2840 if (agg->frame_count == 1) {
2841 /* Only one frame was attempted; no block-ack will arrive */
2842 status = le16_to_cpu(frame_status[0].status);
2843 seq = le16_to_cpu(frame_status[0].sequence);
2844 idx = SEQ_TO_INDEX(seq);
2845 txq_id = SEQ_TO_QUEUE(seq);
2846
2847 /* FIXME: code repetition */
2848 IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d idx=%d\n",
2849 agg->frame_count, agg->start_idx, idx);
2850
2851 tx_status = &(priv->txq[txq_id].txb[idx].status);
2852 tx_status->retry_count = tx_resp->failure_frame;
2853 tx_status->queue_number = status & 0xff;
2854 tx_status->queue_length = tx_resp->failure_rts;
2855 tx_status->control.flags &= ~IEEE80211_TXCTL_AMPDU;
2856 tx_status->flags = iwl4965_is_tx_success(status)?
2857 IEEE80211_TX_STATUS_ACK : 0;
2858 iwl4965_hwrate_to_tx_control(priv,
2859 le32_to_cpu(tx_resp->rate_n_flags),
2860 &tx_status->control);
2861 /* FIXME: code repetition end */
2862
2863 IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n",
2864 status & 0xff, tx_resp->failure_frame);
2865 IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n",
2866 iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags));
2867
2868 agg->wait_for_ba = 0;
2869 } else {
2870 /* Two or more frames were attempted; expect block-ack */
2871 u64 bitmap = 0;
2872 int start = agg->start_idx;
2873
2874 /* Construct bit-map of pending frames within Tx window */
2875 for (i = 0; i < agg->frame_count; i++) {
2876 u16 sc;
2877 status = le16_to_cpu(frame_status[i].status);
2878 seq = le16_to_cpu(frame_status[i].sequence);
2879 idx = SEQ_TO_INDEX(seq);
2880 txq_id = SEQ_TO_QUEUE(seq);
2881
2882 if (status & (AGG_TX_STATE_FEW_BYTES_MSK |
2883 AGG_TX_STATE_ABORT_MSK))
2884 continue;
2885
2886 IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n",
2887 agg->frame_count, txq_id, idx);
2888
2889 hdr = iwl4965_tx_queue_get_hdr(priv, txq_id, idx);
2890
2891 sc = le16_to_cpu(hdr->seq_ctrl);
2892 if (idx != (SEQ_TO_SN(sc) & 0xff)) {
2893 IWL_ERROR("BUG_ON idx doesn't match seq control"
2894 " idx=%d, seq_idx=%d, seq=%d\n",
2895 idx, SEQ_TO_SN(sc),
2896 hdr->seq_ctrl);
2897 return -1;
2898 }
2899
2900 IWL_DEBUG_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n",
2901 i, idx, SEQ_TO_SN(sc));
2902
2903 sh = idx - start;
2904 if (sh > 64) {
2905 sh = (start - idx) + 0xff;
2906 bitmap = bitmap << sh;
2907 sh = 0;
2908 start = idx;
2909 } else if (sh < -64)
2910 sh = 0xff - (start - idx);
2911 else if (sh < 0) {
2912 sh = start - idx;
2913 start = idx;
2914 bitmap = bitmap << sh;
2915 sh = 0;
2916 }
2917 bitmap |= (1 << sh);
2918 IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%x\n",
2919 start, (u32)(bitmap & 0xFFFFFFFF));
2920 }
2921
2922 agg->bitmap = bitmap;
2923 agg->start_idx = start;
2924 agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
2925 IWL_DEBUG_TX_REPLY("Frames %d start_idx=%d bitmap=0x%llx\n",
2926 agg->frame_count, agg->start_idx,
2927 (unsigned long long)agg->bitmap);
2928
2929 if (bitmap)
2930 agg->wait_for_ba = 1;
2931 }
2932 return 0;
2933}
2934#endif
2935
2936/**
2937 * iwl4965_rx_reply_tx - Handle standard (non-aggregation) Tx response
2938 */
2939static void iwl4965_rx_reply_tx(struct iwl_priv *priv,
2940 struct iwl4965_rx_mem_buffer *rxb)
2941{
2942 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
2943 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
2944 int txq_id = SEQ_TO_QUEUE(sequence);
2945 int index = SEQ_TO_INDEX(sequence);
2946 struct iwl4965_tx_queue *txq = &priv->txq[txq_id];
2947 struct ieee80211_tx_status *tx_status;
2948 struct iwl4965_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
2949 u32 status = le32_to_cpu(tx_resp->status);
2950#ifdef CONFIG_IWL4965_HT
2951 int tid = MAX_TID_COUNT, sta_id = IWL_INVALID_STATION;
2952 struct ieee80211_hdr *hdr;
2953 __le16 *qc;
2954#endif
2955
2956 if ((index >= txq->q.n_bd) || (x2_queue_used(&txq->q, index) == 0)) {
2957 IWL_ERROR("Read index for DMA queue txq_id (%d) index %d "
2958 "is out of range [0-%d] %d %d\n", txq_id,
2959 index, txq->q.n_bd, txq->q.write_ptr,
2960 txq->q.read_ptr);
2961 return;
2962 }
2963
2964#ifdef CONFIG_IWL4965_HT
2965 hdr = iwl4965_tx_queue_get_hdr(priv, txq_id, index);
2966 qc = ieee80211_get_qos_ctrl(hdr);
2967
2968 if (qc)
2969 tid = le16_to_cpu(*qc) & 0xf;
2970
2971 sta_id = iwl4965_get_ra_sta_id(priv, hdr);
2972 if (txq->sched_retry && unlikely(sta_id == IWL_INVALID_STATION)) {
2973 IWL_ERROR("Station not known\n");
2974 return;
2975 }
2976
2977 if (txq->sched_retry) {
2978 const u32 scd_ssn = iwl4965_get_scd_ssn(tx_resp);
2979 struct iwl4965_ht_agg *agg = NULL;
2980
2981 if (!qc)
2982 return;
2983
2984 agg = &priv->stations[sta_id].tid[tid].agg;
2985
2986 iwl4965_tx_status_reply_tx(priv, agg,
2987 (struct iwl4965_tx_resp_agg *)tx_resp, index);
2988
2989 if ((tx_resp->frame_count == 1) &&
2990 !iwl4965_is_tx_success(status)) {
2991 /* TODO: send BAR */
2992 }
2993
2994 if (txq->q.read_ptr != (scd_ssn & 0xff)) {
2995 int freed;
2996 index = iwl_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd);
2997 IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn "
2998 "%d index %d\n", scd_ssn , index);
2999 freed = iwl4965_tx_queue_reclaim(priv, txq_id, index);
3000 priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
3001
3002 if (iwl4965_queue_space(&txq->q) > txq->q.low_mark &&
3003 txq_id >= 0 && priv->mac80211_registered &&
3004 agg->state != IWL_EMPTYING_HW_QUEUE_DELBA)
3005 ieee80211_wake_queue(priv->hw, txq_id);
3006
3007 iwl4965_check_empty_hw_queue(priv, sta_id, tid, txq_id);
3008 }
3009 } else {
3010#endif /* CONFIG_IWL4965_HT */
3011 tx_status = &(txq->txb[txq->q.read_ptr].status);
3012
3013 tx_status->retry_count = tx_resp->failure_frame;
3014 tx_status->queue_number = status;
3015 tx_status->queue_length = tx_resp->bt_kill_count;
3016 tx_status->queue_length |= tx_resp->failure_rts;
3017 tx_status->flags =
3018 iwl4965_is_tx_success(status) ? IEEE80211_TX_STATUS_ACK : 0;
3019 iwl4965_hwrate_to_tx_control(priv, le32_to_cpu(tx_resp->rate_n_flags),
3020 &tx_status->control);
3021
3022 IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) rate_n_flags 0x%x "
3023 "retries %d\n", txq_id, iwl4965_get_tx_fail_reason(status),
3024 status, le32_to_cpu(tx_resp->rate_n_flags),
3025 tx_resp->failure_frame);
3026
3027 IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index);
3028 if (index != -1) {
3029#ifdef CONFIG_IWL4965_HT
3030 int freed = iwl4965_tx_queue_reclaim(priv, txq_id, index);
3031
3032 if (tid != MAX_TID_COUNT)
3033 priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
3034 if (iwl4965_queue_space(&txq->q) > txq->q.low_mark &&
3035 (txq_id >= 0) &&
3036 priv->mac80211_registered)
3037 ieee80211_wake_queue(priv->hw, txq_id);
3038 if (tid != MAX_TID_COUNT)
3039 iwl4965_check_empty_hw_queue(priv, sta_id, tid, txq_id);
3040#endif
3041 }
3042#ifdef CONFIG_IWL4965_HT
3043 }
3044#endif /* CONFIG_IWL4965_HT */
3045
3046 if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK))
3047 IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n");
3048}
3049
3050
3051static void iwl4965_rx_reply_alive(struct iwl_priv *priv,
3052 struct iwl4965_rx_mem_buffer *rxb)
3053{
3054 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3055 struct iwl4965_alive_resp *palive;
3056 struct delayed_work *pwork;
3057
3058 palive = &pkt->u.alive_frame;
3059
3060 IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
3061 "0x%01X 0x%01X\n",
3062 palive->is_valid, palive->ver_type,
3063 palive->ver_subtype);
3064
3065 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
3066 IWL_DEBUG_INFO("Initialization Alive received.\n");
3067 memcpy(&priv->card_alive_init,
3068 &pkt->u.alive_frame,
3069 sizeof(struct iwl4965_init_alive_resp));
3070 pwork = &priv->init_alive_start;
3071 } else {
3072 IWL_DEBUG_INFO("Runtime Alive received.\n");
3073 memcpy(&priv->card_alive, &pkt->u.alive_frame,
3074 sizeof(struct iwl4965_alive_resp));
3075 pwork = &priv->alive_start;
3076 }
3077
3078 /* We delay the ALIVE response by 5ms to
3079 * give the HW RF Kill time to activate... */
3080 if (palive->is_valid == UCODE_VALID_OK)
3081 queue_delayed_work(priv->workqueue, pwork,
3082 msecs_to_jiffies(5));
3083 else
3084 IWL_WARNING("uCode did not respond OK.\n");
3085}
3086
3087static void iwl4965_rx_reply_add_sta(struct iwl_priv *priv,
3088 struct iwl4965_rx_mem_buffer *rxb)
3089{
3090 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3091
3092 IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status);
3093 return;
3094}
3095
3096static void iwl4965_rx_reply_error(struct iwl_priv *priv,
3097 struct iwl4965_rx_mem_buffer *rxb)
3098{
3099 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3100
3101 IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) "
3102 "seq 0x%04X ser 0x%08X\n",
3103 le32_to_cpu(pkt->u.err_resp.error_type),
3104 get_cmd_string(pkt->u.err_resp.cmd_id),
3105 pkt->u.err_resp.cmd_id,
3106 le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
3107 le32_to_cpu(pkt->u.err_resp.error_info));
3108}
3109
3110#define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
3111
3112static void iwl4965_rx_csa(struct iwl_priv *priv, struct iwl4965_rx_mem_buffer *rxb)
3113{
3114 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3115 struct iwl4965_rxon_cmd *rxon = (void *)&priv->active_rxon;
3116 struct iwl4965_csa_notification *csa = &(pkt->u.csa_notif);
3117 IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
3118 le16_to_cpu(csa->channel), le32_to_cpu(csa->status));
3119 rxon->channel = csa->channel;
3120 priv->staging_rxon.channel = csa->channel;
3121}
3122
3123static void iwl4965_rx_spectrum_measure_notif(struct iwl_priv *priv,
3124 struct iwl4965_rx_mem_buffer *rxb)
3125{
3126#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
3127 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3128 struct iwl4965_spectrum_notification *report = &(pkt->u.spectrum_notif);
3129
3130 if (!report->state) {
3131 IWL_DEBUG(IWL_DL_11H | IWL_DL_INFO,
3132 "Spectrum Measure Notification: Start\n");
3133 return;
3134 }
3135
3136 memcpy(&priv->measure_report, report, sizeof(*report));
3137 priv->measurement_status |= MEASUREMENT_READY;
3138#endif
3139}
3140
3141static void iwl4965_rx_pm_sleep_notif(struct iwl_priv *priv,
3142 struct iwl4965_rx_mem_buffer *rxb)
3143{
3144#ifdef CONFIG_IWLWIFI_DEBUG
3145 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3146 struct iwl4965_sleep_notification *sleep = &(pkt->u.sleep_notif);
3147 IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
3148 sleep->pm_sleep_mode, sleep->pm_wakeup_src);
3149#endif
3150}
3151
3152static void iwl4965_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
3153 struct iwl4965_rx_mem_buffer *rxb)
3154{
3155 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3156 IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
3157 "notification for %s:\n",
3158 le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd));
3159 iwl_print_hex_dump(IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len));
3160}
3161
3162static void iwl4965_bg_beacon_update(struct work_struct *work)
3163{
3164 struct iwl_priv *priv =
3165 container_of(work, struct iwl_priv, beacon_update);
3166 struct sk_buff *beacon;
3167
3168 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
3169 beacon = ieee80211_beacon_get(priv->hw, priv->vif, NULL);
3170
3171 if (!beacon) {
3172 IWL_ERROR("update beacon failed\n");
3173 return;
3174 }
3175
3176 mutex_lock(&priv->mutex);
3177 /* new beacon skb is allocated every time; dispose previous.*/
3178 if (priv->ibss_beacon)
3179 dev_kfree_skb(priv->ibss_beacon);
3180
3181 priv->ibss_beacon = beacon;
3182 mutex_unlock(&priv->mutex);
3183
3184 iwl4965_send_beacon_cmd(priv);
3185}
3186
3187static void iwl4965_rx_beacon_notif(struct iwl_priv *priv,
3188 struct iwl4965_rx_mem_buffer *rxb)
3189{
3190#ifdef CONFIG_IWLWIFI_DEBUG
3191 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3192 struct iwl4965_beacon_notif *beacon = &(pkt->u.beacon_status);
3193 u8 rate = iwl4965_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
3194
3195 IWL_DEBUG_RX("beacon status %x retries %d iss %d "
3196 "tsf %d %d rate %d\n",
3197 le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
3198 beacon->beacon_notify_hdr.failure_frame,
3199 le32_to_cpu(beacon->ibss_mgr_status),
3200 le32_to_cpu(beacon->high_tsf),
3201 le32_to_cpu(beacon->low_tsf), rate);
3202#endif
3203
3204 if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
3205 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
3206 queue_work(priv->workqueue, &priv->beacon_update);
3207}
3208
3209/* Service response to REPLY_SCAN_CMD (0x80) */
3210static void iwl4965_rx_reply_scan(struct iwl_priv *priv,
3211 struct iwl4965_rx_mem_buffer *rxb)
3212{
3213#ifdef CONFIG_IWLWIFI_DEBUG
3214 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3215 struct iwl4965_scanreq_notification *notif =
3216 (struct iwl4965_scanreq_notification *)pkt->u.raw;
3217
3218 IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status);
3219#endif
3220}
3221
3222/* Service SCAN_START_NOTIFICATION (0x82) */
3223static void iwl4965_rx_scan_start_notif(struct iwl_priv *priv,
3224 struct iwl4965_rx_mem_buffer *rxb)
3225{
3226 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3227 struct iwl4965_scanstart_notification *notif =
3228 (struct iwl4965_scanstart_notification *)pkt->u.raw;
3229 priv->scan_start_tsf = le32_to_cpu(notif->tsf_low);
3230 IWL_DEBUG_SCAN("Scan start: "
3231 "%d [802.11%s] "
3232 "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n",
3233 notif->channel,
3234 notif->band ? "bg" : "a",
3235 notif->tsf_high,
3236 notif->tsf_low, notif->status, notif->beacon_timer);
3237}
3238
3239/* Service SCAN_RESULTS_NOTIFICATION (0x83) */
3240static void iwl4965_rx_scan_results_notif(struct iwl_priv *priv,
3241 struct iwl4965_rx_mem_buffer *rxb)
3242{
3243 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3244 struct iwl4965_scanresults_notification *notif =
3245 (struct iwl4965_scanresults_notification *)pkt->u.raw;
3246
3247 IWL_DEBUG_SCAN("Scan ch.res: "
3248 "%d [802.11%s] "
3249 "(TSF: 0x%08X:%08X) - %d "
3250 "elapsed=%lu usec (%dms since last)\n",
3251 notif->channel,
3252 notif->band ? "bg" : "a",
3253 le32_to_cpu(notif->tsf_high),
3254 le32_to_cpu(notif->tsf_low),
3255 le32_to_cpu(notif->statistics[0]),
3256 le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf,
3257 jiffies_to_msecs(elapsed_jiffies
3258 (priv->last_scan_jiffies, jiffies)));
3259
3260 priv->last_scan_jiffies = jiffies;
3261 priv->next_scan_jiffies = 0;
3262}
3263
3264/* Service SCAN_COMPLETE_NOTIFICATION (0x84) */
3265static void iwl4965_rx_scan_complete_notif(struct iwl_priv *priv,
3266 struct iwl4965_rx_mem_buffer *rxb)
3267{
3268 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3269 struct iwl4965_scancomplete_notification *scan_notif = (void *)pkt->u.raw;
3270
3271 IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n",
3272 scan_notif->scanned_channels,
3273 scan_notif->tsf_low,
3274 scan_notif->tsf_high, scan_notif->status);
3275
3276 /* The HW is no longer scanning */
3277 clear_bit(STATUS_SCAN_HW, &priv->status);
3278
3279 /* The scan completion notification came in, so kill that timer... */
3280 cancel_delayed_work(&priv->scan_check);
3281
3282 IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n",
3283 (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) ?
3284 "2.4" : "5.2",
3285 jiffies_to_msecs(elapsed_jiffies
3286 (priv->scan_pass_start, jiffies)));
3287
3288 /* Remove this scanned band from the list of pending
3289 * bands to scan, band G precedes A in order of scanning
3290 * as seen in iwl_bg_request_scan */
3291 if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ))
3292 priv->scan_bands &= ~BIT(IEEE80211_BAND_2GHZ);
3293 else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ))
3294 priv->scan_bands &= ~BIT(IEEE80211_BAND_5GHZ);
3295
3296 /* If a request to abort was given, or the scan did not succeed
3297 * then we reset the scan state machine and terminate,
3298 * re-queuing another scan if one has been requested */
3299 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
3300 IWL_DEBUG_INFO("Aborted scan completed.\n");
3301 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
3302 } else {
3303 /* If there are more bands on this scan pass reschedule */
3304 if (priv->scan_bands)
3305 goto reschedule;
3306 }
3307
3308 priv->last_scan_jiffies = jiffies;
3309 priv->next_scan_jiffies = 0;
3310 IWL_DEBUG_INFO("Setting scan to off\n");
3311
3312 clear_bit(STATUS_SCANNING, &priv->status);
3313
3314 IWL_DEBUG_INFO("Scan took %dms\n",
3315 jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies)));
3316
3317 queue_work(priv->workqueue, &priv->scan_completed);
3318
3319 return;
3320
3321reschedule:
3322 priv->scan_pass_start = jiffies;
3323 queue_work(priv->workqueue, &priv->request_scan);
3324}
3325
3326/* Handle notification from uCode that card's power state is changing
3327 * due to software, hardware, or critical temperature RFKILL */
3328static void iwl4965_rx_card_state_notif(struct iwl_priv *priv,
3329 struct iwl4965_rx_mem_buffer *rxb)
3330{
3331 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3332 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
3333 unsigned long status = priv->status;
3334
3335 IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
3336 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
3337 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
3338
3339 if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
3340 RF_CARD_DISABLED)) {
3341
3342 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
3343 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
3344
3345 if (!iwl_grab_nic_access(priv)) {
3346 iwl_write_direct32(
3347 priv, HBUS_TARG_MBX_C,
3348 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
3349
3350 iwl_release_nic_access(priv);
3351 }
3352
3353 if (!(flags & RXON_CARD_DISABLED)) {
3354 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
3355 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
3356 if (!iwl_grab_nic_access(priv)) {
3357 iwl_write_direct32(
3358 priv, HBUS_TARG_MBX_C,
3359 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
3360
3361 iwl_release_nic_access(priv);
3362 }
3363 }
3364
3365 if (flags & RF_CARD_DISABLED) {
3366 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
3367 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
3368 iwl_read32(priv, CSR_UCODE_DRV_GP1);
3369 if (!iwl_grab_nic_access(priv))
3370 iwl_release_nic_access(priv);
3371 }
3372 }
3373
3374 if (flags & HW_CARD_DISABLED)
3375 set_bit(STATUS_RF_KILL_HW, &priv->status);
3376 else
3377 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3378
3379
3380 if (flags & SW_CARD_DISABLED)
3381 set_bit(STATUS_RF_KILL_SW, &priv->status);
3382 else
3383 clear_bit(STATUS_RF_KILL_SW, &priv->status);
3384
3385 if (!(flags & RXON_CARD_DISABLED))
3386 iwl4965_scan_cancel(priv);
3387
3388 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
3389 test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
3390 (test_bit(STATUS_RF_KILL_SW, &status) !=
3391 test_bit(STATUS_RF_KILL_SW, &priv->status)))
3392 queue_work(priv->workqueue, &priv->rf_kill);
3393 else
3394 wake_up_interruptible(&priv->wait_command_queue);
3395}
3396
3397/**
3398 * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks
3399 *
3400 * Setup the RX handlers for each of the reply types sent from the uCode
3401 * to the host.
3402 *
3403 * This function chains into the hardware specific files for them to setup
3404 * any hardware specific handlers as well.
3405 */
3406static void iwl4965_setup_rx_handlers(struct iwl_priv *priv)
3407{
3408 priv->rx_handlers[REPLY_ALIVE] = iwl4965_rx_reply_alive;
3409 priv->rx_handlers[REPLY_ADD_STA] = iwl4965_rx_reply_add_sta;
3410 priv->rx_handlers[REPLY_ERROR] = iwl4965_rx_reply_error;
3411 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl4965_rx_csa;
3412 priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
3413 iwl4965_rx_spectrum_measure_notif;
3414 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl4965_rx_pm_sleep_notif;
3415 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
3416 iwl4965_rx_pm_debug_statistics_notif;
3417 priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif;
3418
3419 /*
3420 * The same handler is used for both the REPLY to a discrete
3421 * statistics request from the host as well as for the periodic
3422 * statistics notifications (after received beacons) from the uCode.
3423 */
3424 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl4965_hw_rx_statistics;
3425 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl4965_hw_rx_statistics;
3426
3427 priv->rx_handlers[REPLY_SCAN_CMD] = iwl4965_rx_reply_scan;
3428 priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl4965_rx_scan_start_notif;
3429 priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] =
3430 iwl4965_rx_scan_results_notif;
3431 priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] =
3432 iwl4965_rx_scan_complete_notif;
3433 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl4965_rx_card_state_notif;
3434 priv->rx_handlers[REPLY_TX] = iwl4965_rx_reply_tx;
3435
3436 /* Set up hardware specific Rx handlers */
3437 iwl4965_hw_rx_handler_setup(priv);
3438}
3439
3440/**
3441 * iwl4965_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
3442 * @rxb: Rx buffer to reclaim
3443 *
3444 * If an Rx buffer has an async callback associated with it the callback
3445 * will be executed. The attached skb (if present) will only be freed
3446 * if the callback returns 1
3447 */
3448static void iwl4965_tx_cmd_complete(struct iwl_priv *priv,
3449 struct iwl4965_rx_mem_buffer *rxb)
3450{
3451 struct iwl4965_rx_packet *pkt = (struct iwl4965_rx_packet *)rxb->skb->data;
3452 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
3453 int txq_id = SEQ_TO_QUEUE(sequence);
3454 int index = SEQ_TO_INDEX(sequence);
3455 int huge = sequence & SEQ_HUGE_FRAME;
3456 int cmd_index;
3457 struct iwl_cmd *cmd;
3458
3459 /* If a Tx command is being handled and it isn't in the actual
3460 * command queue then there a command routing bug has been introduced
3461 * in the queue management code. */
3462 if (txq_id != IWL_CMD_QUEUE_NUM)
3463 IWL_ERROR("Error wrong command queue %d command id 0x%X\n",
3464 txq_id, pkt->hdr.cmd);
3465 BUG_ON(txq_id != IWL_CMD_QUEUE_NUM);
3466
3467 cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge);
3468 cmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index];
3469
3470 /* Input error checking is done when commands are added to queue. */
3471 if (cmd->meta.flags & CMD_WANT_SKB) {
3472 cmd->meta.source->u.skb = rxb->skb;
3473 rxb->skb = NULL;
3474 } else if (cmd->meta.u.callback &&
3475 !cmd->meta.u.callback(priv, cmd, rxb->skb))
3476 rxb->skb = NULL;
3477
3478 iwl4965_tx_queue_reclaim(priv, txq_id, index);
3479
3480 if (!(cmd->meta.flags & CMD_ASYNC)) {
3481 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
3482 wake_up_interruptible(&priv->wait_command_queue);
3483 }
3484}
3485
3486/************************** RX-FUNCTIONS ****************************/
3487/*
3488 * Rx theory of operation
3489 *
3490 * Driver allocates a circular buffer of Receive Buffer Descriptors (RBDs),
3491 * each of which point to Receive Buffers to be filled by 4965. These get
3492 * used not only for Rx frames, but for any command response or notification
3493 * from the 4965. The driver and 4965 manage the Rx buffers by means
3494 * of indexes into the circular buffer.
3495 *
3496 * Rx Queue Indexes
3497 * The host/firmware share two index registers for managing the Rx buffers.
3498 *
3499 * The READ index maps to the first position that the firmware may be writing
3500 * to -- the driver can read up to (but not including) this position and get
3501 * good data.
3502 * The READ index is managed by the firmware once the card is enabled.
3503 *
3504 * The WRITE index maps to the last position the driver has read from -- the
3505 * position preceding WRITE is the last slot the firmware can place a packet.
3506 *
3507 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
3508 * WRITE = READ.
3509 *
3510 * During initialization, the host sets up the READ queue position to the first
3511 * INDEX position, and WRITE to the last (READ - 1 wrapped)
3512 *
3513 * When the firmware places a packet in a buffer, it will advance the READ index
3514 * and fire the RX interrupt. The driver can then query the READ index and
3515 * process as many packets as possible, moving the WRITE index forward as it
3516 * resets the Rx queue buffers with new memory.
3517 *
3518 * The management in the driver is as follows:
3519 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
3520 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
3521 * to replenish the iwl->rxq->rx_free.
3522 * + In iwl4965_rx_replenish (scheduled) if 'processed' != 'read' then the
3523 * iwl->rxq is replenished and the READ INDEX is updated (updating the
3524 * 'processed' and 'read' driver indexes as well)
3525 * + A received packet is processed and handed to the kernel network stack,
3526 * detached from the iwl->rxq. The driver 'processed' index is updated.
3527 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
3528 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
3529 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
3530 * were enough free buffers and RX_STALLED is set it is cleared.
3531 *
3532 *
3533 * Driver sequence:
3534 *
3535 * iwl4965_rx_queue_alloc() Allocates rx_free
3536 * iwl4965_rx_replenish() Replenishes rx_free list from rx_used, and calls
3537 * iwl4965_rx_queue_restock
3538 * iwl4965_rx_queue_restock() Moves available buffers from rx_free into Rx
3539 * queue, updates firmware pointers, and updates
3540 * the WRITE index. If insufficient rx_free buffers
3541 * are available, schedules iwl4965_rx_replenish
3542 *
3543 * -- enable interrupts --
3544 * ISR - iwl4965_rx() Detach iwl4965_rx_mem_buffers from pool up to the
3545 * READ INDEX, detaching the SKB from the pool.
3546 * Moves the packet buffer from queue to rx_used.
3547 * Calls iwl4965_rx_queue_restock to refill any empty
3548 * slots.
3549 * ...
3550 *
3551 */
3552
3553/**
3554 * iwl4965_rx_queue_space - Return number of free slots available in queue.
3555 */
3556static int iwl4965_rx_queue_space(const struct iwl4965_rx_queue *q)
3557{
3558 int s = q->read - q->write;
3559 if (s <= 0)
3560 s += RX_QUEUE_SIZE;
3561 /* keep some buffer to not confuse full and empty queue */
3562 s -= 2;
3563 if (s < 0)
3564 s = 0;
3565 return s;
3566}
3567
3568/**
3569 * iwl4965_rx_queue_update_write_ptr - Update the write pointer for the RX queue
3570 */
3571int iwl4965_rx_queue_update_write_ptr(struct iwl_priv *priv, struct iwl4965_rx_queue *q)
3572{
3573 u32 reg = 0;
3574 int rc = 0;
3575 unsigned long flags;
3576
3577 spin_lock_irqsave(&q->lock, flags);
3578
3579 if (q->need_update == 0)
3580 goto exit_unlock;
3581
3582 /* If power-saving is in use, make sure device is awake */
3583 if (test_bit(STATUS_POWER_PMI, &priv->status)) {
3584 reg = iwl_read32(priv, CSR_UCODE_DRV_GP1);
3585
3586 if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
3587 iwl_set_bit(priv, CSR_GP_CNTRL,
3588 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
3589 goto exit_unlock;
3590 }
3591
3592 rc = iwl_grab_nic_access(priv);
3593 if (rc)
3594 goto exit_unlock;
3595
3596 /* Device expects a multiple of 8 */
3597 iwl_write_direct32(priv, FH_RSCSR_CHNL0_WPTR,
3598 q->write & ~0x7);
3599 iwl_release_nic_access(priv);
3600
3601 /* Else device is assumed to be awake */
3602 } else
3603 /* Device expects a multiple of 8 */
3604 iwl_write32(priv, FH_RSCSR_CHNL0_WPTR, q->write & ~0x7);
3605
3606
3607 q->need_update = 0;
3608
3609 exit_unlock:
3610 spin_unlock_irqrestore(&q->lock, flags);
3611 return rc;
3612}
3613
3614/**
3615 * iwl4965_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
3616 */
3617static inline __le32 iwl4965_dma_addr2rbd_ptr(struct iwl_priv *priv,
3618 dma_addr_t dma_addr)
3619{
3620 return cpu_to_le32((u32)(dma_addr >> 8));
3621}
3622
3623
3624/**
3625 * iwl4965_rx_queue_restock - refill RX queue from pre-allocated pool
3626 *
3627 * If there are slots in the RX queue that need to be restocked,
3628 * and we have free pre-allocated buffers, fill the ranks as much
3629 * as we can, pulling from rx_free.
3630 *
3631 * This moves the 'write' index forward to catch up with 'processed', and
3632 * also updates the memory address in the firmware to reference the new
3633 * target buffer.
3634 */
3635static int iwl4965_rx_queue_restock(struct iwl_priv *priv)
3636{
3637 struct iwl4965_rx_queue *rxq = &priv->rxq;
3638 struct list_head *element;
3639 struct iwl4965_rx_mem_buffer *rxb;
3640 unsigned long flags;
3641 int write, rc;
3642
3643 spin_lock_irqsave(&rxq->lock, flags);
3644 write = rxq->write & ~0x7;
3645 while ((iwl4965_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
3646 /* Get next free Rx buffer, remove from free list */
3647 element = rxq->rx_free.next;
3648 rxb = list_entry(element, struct iwl4965_rx_mem_buffer, list);
3649 list_del(element);
3650
3651 /* Point to Rx buffer via next RBD in circular buffer */
3652 rxq->bd[rxq->write] = iwl4965_dma_addr2rbd_ptr(priv, rxb->dma_addr);
3653 rxq->queue[rxq->write] = rxb;
3654 rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
3655 rxq->free_count--;
3656 }
3657 spin_unlock_irqrestore(&rxq->lock, flags);
3658 /* If the pre-allocated buffer pool is dropping low, schedule to
3659 * refill it */
3660 if (rxq->free_count <= RX_LOW_WATERMARK)
3661 queue_work(priv->workqueue, &priv->rx_replenish);
3662
3663
3664 /* If we've added more space for the firmware to place data, tell it.
3665 * Increment device's write pointer in multiples of 8. */
3666 if ((write != (rxq->write & ~0x7))
3667 || (abs(rxq->write - rxq->read) > 7)) {
3668 spin_lock_irqsave(&rxq->lock, flags);
3669 rxq->need_update = 1;
3670 spin_unlock_irqrestore(&rxq->lock, flags);
3671 rc = iwl4965_rx_queue_update_write_ptr(priv, rxq);
3672 if (rc)
3673 return rc;
3674 }
3675
3676 return 0;
3677}
3678
3679/**
3680 * iwl4965_rx_replenish - Move all used packet from rx_used to rx_free
3681 *
3682 * When moving to rx_free an SKB is allocated for the slot.
3683 *
3684 * Also restock the Rx queue via iwl4965_rx_queue_restock.
3685 * This is called as a scheduled work item (except for during initialization)
3686 */
3687static void iwl4965_rx_allocate(struct iwl_priv *priv)
3688{
3689 struct iwl4965_rx_queue *rxq = &priv->rxq;
3690 struct list_head *element;
3691 struct iwl4965_rx_mem_buffer *rxb;
3692 unsigned long flags;
3693 spin_lock_irqsave(&rxq->lock, flags);
3694 while (!list_empty(&rxq->rx_used)) {
3695 element = rxq->rx_used.next;
3696 rxb = list_entry(element, struct iwl4965_rx_mem_buffer, list);
3697
3698 /* Alloc a new receive buffer */
3699 rxb->skb =
3700 alloc_skb(priv->hw_params.rx_buf_size,
3701 __GFP_NOWARN | GFP_ATOMIC);
3702 if (!rxb->skb) {
3703 if (net_ratelimit())
3704 printk(KERN_CRIT DRV_NAME
3705 ": Can not allocate SKB buffers\n");
3706 /* We don't reschedule replenish work here -- we will
3707 * call the restock method and if it still needs
3708 * more buffers it will schedule replenish */
3709 break;
3710 }
3711 priv->alloc_rxb_skb++;
3712 list_del(element);
3713
3714 /* Get physical address of RB/SKB */
3715 rxb->dma_addr =
3716 pci_map_single(priv->pci_dev, rxb->skb->data,
3717 priv->hw_params.rx_buf_size, PCI_DMA_FROMDEVICE);
3718 list_add_tail(&rxb->list, &rxq->rx_free);
3719 rxq->free_count++;
3720 }
3721 spin_unlock_irqrestore(&rxq->lock, flags);
3722}
3723
3724/*
3725 * this should be called while priv->lock is locked
3726*/
3727static void __iwl4965_rx_replenish(void *data)
3728{
3729 struct iwl_priv *priv = data;
3730
3731 iwl4965_rx_allocate(priv);
3732 iwl4965_rx_queue_restock(priv);
3733}
3734
3735
3736void iwl4965_rx_replenish(void *data)
3737{
3738 struct iwl_priv *priv = data;
3739 unsigned long flags;
3740
3741 iwl4965_rx_allocate(priv);
3742
3743 spin_lock_irqsave(&priv->lock, flags);
3744 iwl4965_rx_queue_restock(priv);
3745 spin_unlock_irqrestore(&priv->lock, flags);
3746}
3747
3748/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
3749 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
3750 * This free routine walks the list of POOL entries and if SKB is set to
3751 * non NULL it is unmapped and freed
3752 */
3753static void iwl4965_rx_queue_free(struct iwl_priv *priv, struct iwl4965_rx_queue *rxq)
3754{
3755 int i;
3756 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
3757 if (rxq->pool[i].skb != NULL) {
3758 pci_unmap_single(priv->pci_dev,
3759 rxq->pool[i].dma_addr,
3760 priv->hw_params.rx_buf_size,
3761 PCI_DMA_FROMDEVICE);
3762 dev_kfree_skb(rxq->pool[i].skb);
3763 }
3764 }
3765
3766 pci_free_consistent(priv->pci_dev, 4 * RX_QUEUE_SIZE, rxq->bd,
3767 rxq->dma_addr);
3768 rxq->bd = NULL;
3769}
3770
3771int iwl4965_rx_queue_alloc(struct iwl_priv *priv)
3772{
3773 struct iwl4965_rx_queue *rxq = &priv->rxq;
3774 struct pci_dev *dev = priv->pci_dev;
3775 int i;
3776
3777 spin_lock_init(&rxq->lock);
3778 INIT_LIST_HEAD(&rxq->rx_free);
3779 INIT_LIST_HEAD(&rxq->rx_used);
3780
3781 /* Alloc the circular buffer of Read Buffer Descriptors (RBDs) */
3782 rxq->bd = pci_alloc_consistent(dev, 4 * RX_QUEUE_SIZE, &rxq->dma_addr);
3783 if (!rxq->bd)
3784 return -ENOMEM;
3785
3786 /* Fill the rx_used queue with _all_ of the Rx buffers */
3787 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
3788 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
3789
3790 /* Set us so that we have processed and used all buffers, but have
3791 * not restocked the Rx queue with fresh buffers */
3792 rxq->read = rxq->write = 0;
3793 rxq->free_count = 0;
3794 rxq->need_update = 0;
3795 return 0;
3796}
3797
3798void iwl4965_rx_queue_reset(struct iwl_priv *priv, struct iwl4965_rx_queue *rxq)
3799{
3800 unsigned long flags;
3801 int i;
3802 spin_lock_irqsave(&rxq->lock, flags);
3803 INIT_LIST_HEAD(&rxq->rx_free);
3804 INIT_LIST_HEAD(&rxq->rx_used);
3805 /* Fill the rx_used queue with _all_ of the Rx buffers */
3806 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
3807 /* In the reset function, these buffers may have been allocated
3808 * to an SKB, so we need to unmap and free potential storage */
3809 if (rxq->pool[i].skb != NULL) {
3810 pci_unmap_single(priv->pci_dev,
3811 rxq->pool[i].dma_addr,
3812 priv->hw_params.rx_buf_size,
3813 PCI_DMA_FROMDEVICE);
3814 priv->alloc_rxb_skb--;
3815 dev_kfree_skb(rxq->pool[i].skb);
3816 rxq->pool[i].skb = NULL;
3817 }
3818 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
3819 }
3820
3821 /* Set us so that we have processed and used all buffers, but have
3822 * not restocked the Rx queue with fresh buffers */
3823 rxq->read = rxq->write = 0;
3824 rxq->free_count = 0;
3825 spin_unlock_irqrestore(&rxq->lock, flags);
3826}
3827
3828/* Convert linear signal-to-noise ratio into dB */
3829static u8 ratio2dB[100] = {
3830/* 0 1 2 3 4 5 6 7 8 9 */
3831 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
3832 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
3833 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
3834 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
3835 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
3836 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
3837 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
3838 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
3839 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
3840 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
3841};
3842
3843/* Calculates a relative dB value from a ratio of linear
3844 * (i.e. not dB) signal levels.
3845 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
3846int iwl4965_calc_db_from_ratio(int sig_ratio)
3847{
3848 /* 1000:1 or higher just report as 60 dB */
3849 if (sig_ratio >= 1000)
3850 return 60;
3851
3852 /* 100:1 or higher, divide by 10 and use table,
3853 * add 20 dB to make up for divide by 10 */
3854 if (sig_ratio >= 100)
3855 return (20 + (int)ratio2dB[sig_ratio/10]);
3856
3857 /* We shouldn't see this */
3858 if (sig_ratio < 1)
3859 return 0;
3860
3861 /* Use table for ratios 1:1 - 99:1 */
3862 return (int)ratio2dB[sig_ratio];
3863}
3864
3865#define PERFECT_RSSI (-20) /* dBm */
3866#define WORST_RSSI (-95) /* dBm */
3867#define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
3868
3869/* Calculate an indication of rx signal quality (a percentage, not dBm!).
3870 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
3871 * about formulas used below. */
3872int iwl4965_calc_sig_qual(int rssi_dbm, int noise_dbm)
3873{
3874 int sig_qual;
3875 int degradation = PERFECT_RSSI - rssi_dbm;
3876
3877 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
3878 * as indicator; formula is (signal dbm - noise dbm).
3879 * SNR at or above 40 is a great signal (100%).
3880 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
3881 * Weakest usable signal is usually 10 - 15 dB SNR. */
3882 if (noise_dbm) {
3883 if (rssi_dbm - noise_dbm >= 40)
3884 return 100;
3885 else if (rssi_dbm < noise_dbm)
3886 return 0;
3887 sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
3888
3889 /* Else use just the signal level.
3890 * This formula is a least squares fit of data points collected and
3891 * compared with a reference system that had a percentage (%) display
3892 * for signal quality. */
3893 } else
3894 sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
3895 (15 * RSSI_RANGE + 62 * degradation)) /
3896 (RSSI_RANGE * RSSI_RANGE);
3897
3898 if (sig_qual > 100)
3899 sig_qual = 100;
3900 else if (sig_qual < 1)
3901 sig_qual = 0;
3902
3903 return sig_qual;
3904}
3905
3906/**
3907 * iwl4965_rx_handle - Main entry function for receiving responses from uCode
3908 *
3909 * Uses the priv->rx_handlers callback function array to invoke
3910 * the appropriate handlers, including command responses,
3911 * frame-received notifications, and other notifications.
3912 */
3913static void iwl4965_rx_handle(struct iwl_priv *priv)
3914{
3915 struct iwl4965_rx_mem_buffer *rxb;
3916 struct iwl4965_rx_packet *pkt;
3917 struct iwl4965_rx_queue *rxq = &priv->rxq;
3918 u32 r, i;
3919 int reclaim;
3920 unsigned long flags;
3921 u8 fill_rx = 0;
3922 u32 count = 8;
3923
3924 /* uCode's read index (stored in shared DRAM) indicates the last Rx
3925 * buffer that the driver may process (last buffer filled by ucode). */
3926 r = iwl4965_hw_get_rx_read(priv);
3927 i = rxq->read;
3928
3929 /* Rx interrupt, but nothing sent from uCode */
3930 if (i == r)
3931 IWL_DEBUG(IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i);
3932
3933 if (iwl4965_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
3934 fill_rx = 1;
3935
3936 while (i != r) {
3937 rxb = rxq->queue[i];
3938
3939 /* If an RXB doesn't have a Rx queue slot associated with it,
3940 * then a bug has been introduced in the queue refilling
3941 * routines -- catch it here */
3942 BUG_ON(rxb == NULL);
3943
3944 rxq->queue[i] = NULL;
3945
3946 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
3947 priv->hw_params.rx_buf_size,
3948 PCI_DMA_FROMDEVICE);
3949 pkt = (struct iwl4965_rx_packet *)rxb->skb->data;
3950
3951 /* Reclaim a command buffer only if this packet is a response
3952 * to a (driver-originated) command.
3953 * If the packet (e.g. Rx frame) originated from uCode,
3954 * there is no command buffer to reclaim.
3955 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
3956 * but apparently a few don't get set; catch them here. */
3957 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
3958 (pkt->hdr.cmd != REPLY_RX_PHY_CMD) &&
3959 (pkt->hdr.cmd != REPLY_RX) &&
3960 (pkt->hdr.cmd != REPLY_COMPRESSED_BA) &&
3961 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
3962 (pkt->hdr.cmd != REPLY_TX);
3963
3964 /* Based on type of command response or notification,
3965 * handle those that need handling via function in
3966 * rx_handlers table. See iwl4965_setup_rx_handlers() */
3967 if (priv->rx_handlers[pkt->hdr.cmd]) {
3968 IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR,
3969 "r = %d, i = %d, %s, 0x%02x\n", r, i,
3970 get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
3971 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
3972 } else {
3973 /* No handling needed */
3974 IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR,
3975 "r %d i %d No handler needed for %s, 0x%02x\n",
3976 r, i, get_cmd_string(pkt->hdr.cmd),
3977 pkt->hdr.cmd);
3978 }
3979
3980 if (reclaim) {
3981 /* Invoke any callbacks, transfer the skb to caller, and
3982 * fire off the (possibly) blocking iwl_send_cmd()
3983 * as we reclaim the driver command queue */
3984 if (rxb && rxb->skb)
3985 iwl4965_tx_cmd_complete(priv, rxb);
3986 else
3987 IWL_WARNING("Claim null rxb?\n");
3988 }
3989
3990 /* For now we just don't re-use anything. We can tweak this
3991 * later to try and re-use notification packets and SKBs that
3992 * fail to Rx correctly */
3993 if (rxb->skb != NULL) {
3994 priv->alloc_rxb_skb--;
3995 dev_kfree_skb_any(rxb->skb);
3996 rxb->skb = NULL;
3997 }
3998
3999 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
4000 priv->hw_params.rx_buf_size,
4001 PCI_DMA_FROMDEVICE);
4002 spin_lock_irqsave(&rxq->lock, flags);
4003 list_add_tail(&rxb->list, &priv->rxq.rx_used);
4004 spin_unlock_irqrestore(&rxq->lock, flags);
4005 i = (i + 1) & RX_QUEUE_MASK;
4006 /* If there are a lot of unused frames,
4007 * restock the Rx queue so ucode wont assert. */
4008 if (fill_rx) {
4009 count++;
4010 if (count >= 8) {
4011 priv->rxq.read = i;
4012 __iwl4965_rx_replenish(priv);
4013 count = 0;
4014 }
4015 }
4016 }
4017
4018 /* Backtrack one entry */
4019 priv->rxq.read = i;
4020 iwl4965_rx_queue_restock(priv);
4021}
4022
4023/**
4024 * iwl4965_tx_queue_update_write_ptr - Send new write index to hardware
4025 */
4026static int iwl4965_tx_queue_update_write_ptr(struct iwl_priv *priv,
4027 struct iwl4965_tx_queue *txq)
4028{
4029 u32 reg = 0;
4030 int rc = 0;
4031 int txq_id = txq->q.id;
4032
4033 if (txq->need_update == 0)
4034 return rc;
4035
4036 /* if we're trying to save power */
4037 if (test_bit(STATUS_POWER_PMI, &priv->status)) {
4038 /* wake up nic if it's powered down ...
4039 * uCode will wake up, and interrupt us again, so next
4040 * time we'll skip this part. */
4041 reg = iwl_read32(priv, CSR_UCODE_DRV_GP1);
4042
4043 if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
4044 IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg);
4045 iwl_set_bit(priv, CSR_GP_CNTRL,
4046 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
4047 return rc;
4048 }
4049
4050 /* restore this queue's parameters in nic hardware. */
4051 rc = iwl_grab_nic_access(priv);
4052 if (rc)
4053 return rc;
4054 iwl_write_direct32(priv, HBUS_TARG_WRPTR,
4055 txq->q.write_ptr | (txq_id << 8));
4056 iwl_release_nic_access(priv);
4057
4058 /* else not in power-save mode, uCode will never sleep when we're
4059 * trying to tx (during RFKILL, we're not trying to tx). */
4060 } else
4061 iwl_write32(priv, HBUS_TARG_WRPTR,
4062 txq->q.write_ptr | (txq_id << 8));
4063
4064 txq->need_update = 0;
4065
4066 return rc;
4067}
4068
4069#ifdef CONFIG_IWLWIFI_DEBUG
4070static void iwl4965_print_rx_config_cmd(struct iwl4965_rxon_cmd *rxon)
4071{
4072 DECLARE_MAC_BUF(mac);
4073
4074 IWL_DEBUG_RADIO("RX CONFIG:\n");
4075 iwl_print_hex_dump(IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
4076 IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
4077 IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
4078 IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
4079 le32_to_cpu(rxon->filter_flags));
4080 IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type);
4081 IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
4082 rxon->ofdm_basic_rates);
4083 IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
4084 IWL_DEBUG_RADIO("u8[6] node_addr: %s\n",
4085 print_mac(mac, rxon->node_addr));
4086 IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n",
4087 print_mac(mac, rxon->bssid_addr));
4088 IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
4089}
4090#endif
4091
4092static void iwl4965_enable_interrupts(struct iwl_priv *priv)
4093{
4094 IWL_DEBUG_ISR("Enabling interrupts\n");
4095 set_bit(STATUS_INT_ENABLED, &priv->status);
4096 iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK);
4097}
4098
4099/* call this function to flush any scheduled tasklet */
4100static inline void iwl_synchronize_irq(struct iwl_priv *priv)
4101{
4102 /* wait to make sure we flush pedding tasklet*/
4103 synchronize_irq(priv->pci_dev->irq);
4104 tasklet_kill(&priv->irq_tasklet);
4105}
4106
4107static inline void iwl4965_disable_interrupts(struct iwl_priv *priv)
4108{
4109 clear_bit(STATUS_INT_ENABLED, &priv->status);
4110
4111 /* disable interrupts from uCode/NIC to host */
4112 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
4113
4114 /* acknowledge/clear/reset any interrupts still pending
4115 * from uCode or flow handler (Rx/Tx DMA) */
4116 iwl_write32(priv, CSR_INT, 0xffffffff);
4117 iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff);
4118 IWL_DEBUG_ISR("Disabled interrupts\n");
4119}
4120
4121static const char *desc_lookup(int i)
4122{
4123 switch (i) {
4124 case 1:
4125 return "FAIL";
4126 case 2:
4127 return "BAD_PARAM";
4128 case 3:
4129 return "BAD_CHECKSUM";
4130 case 4:
4131 return "NMI_INTERRUPT";
4132 case 5:
4133 return "SYSASSERT";
4134 case 6:
4135 return "FATAL_ERROR";
4136 }
4137
4138 return "UNKNOWN";
4139}
4140
4141#define ERROR_START_OFFSET (1 * sizeof(u32))
4142#define ERROR_ELEM_SIZE (7 * sizeof(u32))
4143
4144static void iwl4965_dump_nic_error_log(struct iwl_priv *priv)
4145{
4146 u32 data2, line;
4147 u32 desc, time, count, base, data1;
4148 u32 blink1, blink2, ilink1, ilink2;
4149 int rc;
4150
4151 base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
4152
4153 if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
4154 IWL_ERROR("Not valid error log pointer 0x%08X\n", base);
4155 return;
4156 }
4157
4158 rc = iwl_grab_nic_access(priv);
4159 if (rc) {
4160 IWL_WARNING("Can not read from adapter at this time.\n");
4161 return;
4162 }
4163
4164 count = iwl_read_targ_mem(priv, base);
4165
4166 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
4167 IWL_ERROR("Start IWL Error Log Dump:\n");
4168 IWL_ERROR("Status: 0x%08lX, count: %d\n", priv->status, count);
4169 }
4170
4171 desc = iwl_read_targ_mem(priv, base + 1 * sizeof(u32));
4172 blink1 = iwl_read_targ_mem(priv, base + 3 * sizeof(u32));
4173 blink2 = iwl_read_targ_mem(priv, base + 4 * sizeof(u32));
4174 ilink1 = iwl_read_targ_mem(priv, base + 5 * sizeof(u32));
4175 ilink2 = iwl_read_targ_mem(priv, base + 6 * sizeof(u32));
4176 data1 = iwl_read_targ_mem(priv, base + 7 * sizeof(u32));
4177 data2 = iwl_read_targ_mem(priv, base + 8 * sizeof(u32));
4178 line = iwl_read_targ_mem(priv, base + 9 * sizeof(u32));
4179 time = iwl_read_targ_mem(priv, base + 11 * sizeof(u32));
4180
4181 IWL_ERROR("Desc Time "
4182 "data1 data2 line\n");
4183 IWL_ERROR("%-13s (#%d) %010u 0x%08X 0x%08X %u\n",
4184 desc_lookup(desc), desc, time, data1, data2, line);
4185 IWL_ERROR("blink1 blink2 ilink1 ilink2\n");
4186 IWL_ERROR("0x%05X 0x%05X 0x%05X 0x%05X\n", blink1, blink2,
4187 ilink1, ilink2);
4188
4189 iwl_release_nic_access(priv);
4190}
4191
4192#define EVENT_START_OFFSET (4 * sizeof(u32))
4193
4194/**
4195 * iwl4965_print_event_log - Dump error event log to syslog
4196 *
4197 * NOTE: Must be called with iwl_grab_nic_access() already obtained!
4198 */
4199static void iwl4965_print_event_log(struct iwl_priv *priv, u32 start_idx,
4200 u32 num_events, u32 mode)
4201{
4202 u32 i;
4203 u32 base; /* SRAM byte address of event log header */
4204 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
4205 u32 ptr; /* SRAM byte address of log data */
4206 u32 ev, time, data; /* event log data */
4207
4208 if (num_events == 0)
4209 return;
4210
4211 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
4212
4213 if (mode == 0)
4214 event_size = 2 * sizeof(u32);
4215 else
4216 event_size = 3 * sizeof(u32);
4217
4218 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
4219
4220 /* "time" is actually "data" for mode 0 (no timestamp).
4221 * place event id # at far right for easier visual parsing. */
4222 for (i = 0; i < num_events; i++) {
4223 ev = iwl_read_targ_mem(priv, ptr);
4224 ptr += sizeof(u32);
4225 time = iwl_read_targ_mem(priv, ptr);
4226 ptr += sizeof(u32);
4227 if (mode == 0)
4228 IWL_ERROR("0x%08x\t%04u\n", time, ev); /* data, ev */
4229 else {
4230 data = iwl_read_targ_mem(priv, ptr);
4231 ptr += sizeof(u32);
4232 IWL_ERROR("%010u\t0x%08x\t%04u\n", time, data, ev);
4233 }
4234 }
4235}
4236
4237static void iwl4965_dump_nic_event_log(struct iwl_priv *priv)
4238{
4239 int rc;
4240 u32 base; /* SRAM byte address of event log header */
4241 u32 capacity; /* event log capacity in # entries */
4242 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
4243 u32 num_wraps; /* # times uCode wrapped to top of log */
4244 u32 next_entry; /* index of next entry to be written by uCode */
4245 u32 size; /* # entries that we'll print */
4246
4247 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
4248 if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
4249 IWL_ERROR("Invalid event log pointer 0x%08X\n", base);
4250 return;
4251 }
4252
4253 rc = iwl_grab_nic_access(priv);
4254 if (rc) {
4255 IWL_WARNING("Can not read from adapter at this time.\n");
4256 return;
4257 }
4258
4259 /* event log header */
4260 capacity = iwl_read_targ_mem(priv, base);
4261 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
4262 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
4263 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
4264
4265 size = num_wraps ? capacity : next_entry;
4266
4267 /* bail out if nothing in log */
4268 if (size == 0) {
4269 IWL_ERROR("Start IWL Event Log Dump: nothing in log\n");
4270 iwl_release_nic_access(priv);
4271 return;
4272 }
4273
4274 IWL_ERROR("Start IWL Event Log Dump: display count %d, wraps %d\n",
4275 size, num_wraps);
4276
4277 /* if uCode has wrapped back to top of log, start at the oldest entry,
4278 * i.e the next one that uCode would fill. */
4279 if (num_wraps)
4280 iwl4965_print_event_log(priv, next_entry,
4281 capacity - next_entry, mode);
4282
4283 /* (then/else) start at top of log */
4284 iwl4965_print_event_log(priv, 0, next_entry, mode);
4285
4286 iwl_release_nic_access(priv);
4287}
4288
4289/**
4290 * iwl4965_irq_handle_error - called for HW or SW error interrupt from card
4291 */
4292static void iwl4965_irq_handle_error(struct iwl_priv *priv)
4293{
4294 /* Set the FW error flag -- cleared on iwl4965_down */
4295 set_bit(STATUS_FW_ERROR, &priv->status);
4296
4297 /* Cancel currently queued command. */
4298 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
4299
4300#ifdef CONFIG_IWLWIFI_DEBUG
4301 if (iwl_debug_level & IWL_DL_FW_ERRORS) {
4302 iwl4965_dump_nic_error_log(priv);
4303 iwl4965_dump_nic_event_log(priv);
4304 iwl4965_print_rx_config_cmd(&priv->staging_rxon);
4305 }
4306#endif
4307
4308 wake_up_interruptible(&priv->wait_command_queue);
4309
4310 /* Keep the restart process from trying to send host
4311 * commands by clearing the INIT status bit */
4312 clear_bit(STATUS_READY, &priv->status);
4313
4314 if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
4315 IWL_DEBUG(IWL_DL_INFO | IWL_DL_FW_ERRORS,
4316 "Restarting adapter due to uCode error.\n");
4317
4318 if (iwl_is_associated(priv)) {
4319 memcpy(&priv->recovery_rxon, &priv->active_rxon,
4320 sizeof(priv->recovery_rxon));
4321 priv->error_recovering = 1;
4322 }
4323 queue_work(priv->workqueue, &priv->restart);
4324 }
4325}
4326
4327static void iwl4965_error_recovery(struct iwl_priv *priv)
4328{
4329 unsigned long flags;
4330
4331 memcpy(&priv->staging_rxon, &priv->recovery_rxon,
4332 sizeof(priv->staging_rxon));
4333 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
4334 iwl4965_commit_rxon(priv);
4335
4336 iwl4965_rxon_add_station(priv, priv->bssid, 1);
4337
4338 spin_lock_irqsave(&priv->lock, flags);
4339 priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
4340 priv->error_recovering = 0;
4341 spin_unlock_irqrestore(&priv->lock, flags);
4342}
4343
4344static void iwl4965_irq_tasklet(struct iwl_priv *priv)
4345{
4346 u32 inta, handled = 0;
4347 u32 inta_fh;
4348 unsigned long flags;
4349#ifdef CONFIG_IWLWIFI_DEBUG
4350 u32 inta_mask;
4351#endif
4352
4353 spin_lock_irqsave(&priv->lock, flags);
4354
4355 /* Ack/clear/reset pending uCode interrupts.
4356 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
4357 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
4358 inta = iwl_read32(priv, CSR_INT);
4359 iwl_write32(priv, CSR_INT, inta);
4360
4361 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
4362 * Any new interrupts that happen after this, either while we're
4363 * in this tasklet, or later, will show up in next ISR/tasklet. */
4364 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
4365 iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
4366
4367#ifdef CONFIG_IWLWIFI_DEBUG
4368 if (iwl_debug_level & IWL_DL_ISR) {
4369 /* just for debug */
4370 inta_mask = iwl_read32(priv, CSR_INT_MASK);
4371 IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
4372 inta, inta_mask, inta_fh);
4373 }
4374#endif
4375
4376 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
4377 * atomic, make sure that inta covers all the interrupts that
4378 * we've discovered, even if FH interrupt came in just after
4379 * reading CSR_INT. */
4380 if (inta_fh & CSR49_FH_INT_RX_MASK)
4381 inta |= CSR_INT_BIT_FH_RX;
4382 if (inta_fh & CSR49_FH_INT_TX_MASK)
4383 inta |= CSR_INT_BIT_FH_TX;
4384
4385 /* Now service all interrupt bits discovered above. */
4386 if (inta & CSR_INT_BIT_HW_ERR) {
4387 IWL_ERROR("Microcode HW error detected. Restarting.\n");
4388
4389 /* Tell the device to stop sending interrupts */
4390 iwl4965_disable_interrupts(priv);
4391
4392 iwl4965_irq_handle_error(priv);
4393
4394 handled |= CSR_INT_BIT_HW_ERR;
4395
4396 spin_unlock_irqrestore(&priv->lock, flags);
4397
4398 return;
4399 }
4400
4401#ifdef CONFIG_IWLWIFI_DEBUG
4402 if (iwl_debug_level & (IWL_DL_ISR)) {
4403 /* NIC fires this, but we don't use it, redundant with WAKEUP */
4404 if (inta & CSR_INT_BIT_SCD)
4405 IWL_DEBUG_ISR("Scheduler finished to transmit "
4406 "the frame/frames.\n");
4407
4408 /* Alive notification via Rx interrupt will do the real work */
4409 if (inta & CSR_INT_BIT_ALIVE)
4410 IWL_DEBUG_ISR("Alive interrupt\n");
4411 }
4412#endif
4413 /* Safely ignore these bits for debug checks below */
4414 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
4415
4416 /* HW RF KILL switch toggled */
4417 if (inta & CSR_INT_BIT_RF_KILL) {
4418 int hw_rf_kill = 0;
4419 if (!(iwl_read32(priv, CSR_GP_CNTRL) &
4420 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
4421 hw_rf_kill = 1;
4422
4423 IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL | IWL_DL_ISR,
4424 "RF_KILL bit toggled to %s.\n",
4425 hw_rf_kill ? "disable radio":"enable radio");
4426
4427 /* Queue restart only if RF_KILL switch was set to "kill"
4428 * when we loaded driver, and is now set to "enable".
4429 * After we're Alive, RF_KILL gets handled by
4430 * iwl4965_rx_card_state_notif() */
4431 if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) {
4432 clear_bit(STATUS_RF_KILL_HW, &priv->status);
4433 queue_work(priv->workqueue, &priv->restart);
4434 }
4435
4436 handled |= CSR_INT_BIT_RF_KILL;
4437 }
4438
4439 /* Chip got too hot and stopped itself */
4440 if (inta & CSR_INT_BIT_CT_KILL) {
4441 IWL_ERROR("Microcode CT kill error detected.\n");
4442 handled |= CSR_INT_BIT_CT_KILL;
4443 }
4444
4445 /* Error detected by uCode */
4446 if (inta & CSR_INT_BIT_SW_ERR) {
4447 IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n",
4448 inta);
4449 iwl4965_irq_handle_error(priv);
4450 handled |= CSR_INT_BIT_SW_ERR;
4451 }
4452
4453 /* uCode wakes up after power-down sleep */
4454 if (inta & CSR_INT_BIT_WAKEUP) {
4455 IWL_DEBUG_ISR("Wakeup interrupt\n");
4456 iwl4965_rx_queue_update_write_ptr(priv, &priv->rxq);
4457 iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[0]);
4458 iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[1]);
4459 iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[2]);
4460 iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[3]);
4461 iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[4]);
4462 iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[5]);
4463
4464 handled |= CSR_INT_BIT_WAKEUP;
4465 }
4466
4467 /* All uCode command responses, including Tx command responses,
4468 * Rx "responses" (frame-received notification), and other
4469 * notifications from uCode come through here*/
4470 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
4471 iwl4965_rx_handle(priv);
4472 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
4473 }
4474
4475 if (inta & CSR_INT_BIT_FH_TX) {
4476 IWL_DEBUG_ISR("Tx interrupt\n");
4477 handled |= CSR_INT_BIT_FH_TX;
4478 }
4479
4480 if (inta & ~handled)
4481 IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
4482
4483 if (inta & ~CSR_INI_SET_MASK) {
4484 IWL_WARNING("Disabled INTA bits 0x%08x were pending\n",
4485 inta & ~CSR_INI_SET_MASK);
4486 IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh);
4487 }
4488
4489 /* Re-enable all interrupts */
4490 /* only Re-enable if diabled by irq */
4491 if (test_bit(STATUS_INT_ENABLED, &priv->status))
4492 iwl4965_enable_interrupts(priv);
4493
4494#ifdef CONFIG_IWLWIFI_DEBUG
4495 if (iwl_debug_level & (IWL_DL_ISR)) {
4496 inta = iwl_read32(priv, CSR_INT);
4497 inta_mask = iwl_read32(priv, CSR_INT_MASK);
4498 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
4499 IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
4500 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
4501 }
4502#endif
4503 spin_unlock_irqrestore(&priv->lock, flags);
4504}
4505
4506static irqreturn_t iwl4965_isr(int irq, void *data)
4507{
4508 struct iwl_priv *priv = data;
4509 u32 inta, inta_mask;
4510 u32 inta_fh;
4511 if (!priv)
4512 return IRQ_NONE;
4513
4514 spin_lock(&priv->lock);
4515
4516 /* Disable (but don't clear!) interrupts here to avoid
4517 * back-to-back ISRs and sporadic interrupts from our NIC.
4518 * If we have something to service, the tasklet will re-enable ints.
4519 * If we *don't* have something, we'll re-enable before leaving here. */
4520 inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
4521 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
4522
4523 /* Discover which interrupts are active/pending */
4524 inta = iwl_read32(priv, CSR_INT);
4525 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
4526
4527 /* Ignore interrupt if there's nothing in NIC to service.
4528 * This may be due to IRQ shared with another device,
4529 * or due to sporadic interrupts thrown from our NIC. */
4530 if (!inta && !inta_fh) {
4531 IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
4532 goto none;
4533 }
4534
4535 if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
4536 /* Hardware disappeared. It might have already raised
4537 * an interrupt */
4538 IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta);
4539 goto unplugged;
4540 }
4541
4542 IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
4543 inta, inta_mask, inta_fh);
4544
4545 inta &= ~CSR_INT_BIT_SCD;
4546
4547 /* iwl4965_irq_tasklet() will service interrupts and re-enable them */
4548 if (likely(inta || inta_fh))
4549 tasklet_schedule(&priv->irq_tasklet);
4550
4551 unplugged:
4552 spin_unlock(&priv->lock);
4553 return IRQ_HANDLED;
4554
4555 none:
4556 /* re-enable interrupts here since we don't have anything to service. */
4557 /* only Re-enable if diabled by irq */
4558 if (test_bit(STATUS_INT_ENABLED, &priv->status))
4559 iwl4965_enable_interrupts(priv);
4560 spin_unlock(&priv->lock);
4561 return IRQ_NONE;
4562}
4563
4564/* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after
4565 * sending probe req. This should be set long enough to hear probe responses
4566 * from more than one AP. */
4567#define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */
4568#define IWL_ACTIVE_DWELL_TIME_52 (10)
4569
4570/* For faster active scanning, scan will move to the next channel if fewer than
4571 * PLCP_QUIET_THRESH packets are heard on this channel within
4572 * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell
4573 * time if it's a quiet channel (nothing responded to our probe, and there's
4574 * no other traffic).
4575 * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */
4576#define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */
4577#define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */
4578
4579/* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel.
4580 * Must be set longer than active dwell time.
4581 * For the most reliable scan, set > AP beacon interval (typically 100msec). */
4582#define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */
4583#define IWL_PASSIVE_DWELL_TIME_52 (10)
4584#define IWL_PASSIVE_DWELL_BASE (100)
4585#define IWL_CHANNEL_TUNE_TIME 5
4586
4587static inline u16 iwl4965_get_active_dwell_time(struct iwl_priv *priv,
4588 enum ieee80211_band band)
4589{
4590 if (band == IEEE80211_BAND_5GHZ)
4591 return IWL_ACTIVE_DWELL_TIME_52;
4592 else
4593 return IWL_ACTIVE_DWELL_TIME_24;
4594}
4595
4596static u16 iwl4965_get_passive_dwell_time(struct iwl_priv *priv,
4597 enum ieee80211_band band)
4598{
4599 u16 active = iwl4965_get_active_dwell_time(priv, band);
4600 u16 passive = (band != IEEE80211_BAND_5GHZ) ?
4601 IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 :
4602 IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52;
4603
4604 if (iwl_is_associated(priv)) {
4605 /* If we're associated, we clamp the maximum passive
4606 * dwell time to be 98% of the beacon interval (minus
4607 * 2 * channel tune time) */
4608 passive = priv->beacon_int;
4609 if ((passive > IWL_PASSIVE_DWELL_BASE) || !passive)
4610 passive = IWL_PASSIVE_DWELL_BASE;
4611 passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2;
4612 }
4613
4614 if (passive <= active)
4615 passive = active + 1;
4616
4617 return passive;
4618}
4619
4620static int iwl4965_get_channels_for_scan(struct iwl_priv *priv,
4621 enum ieee80211_band band,
4622 u8 is_active, u8 direct_mask,
4623 struct iwl4965_scan_channel *scan_ch)
4624{
4625 const struct ieee80211_channel *channels = NULL;
4626 const struct ieee80211_supported_band *sband;
4627 const struct iwl_channel_info *ch_info;
4628 u16 passive_dwell = 0;
4629 u16 active_dwell = 0;
4630 int added, i;
4631
4632 sband = iwl4965_get_hw_mode(priv, band);
4633 if (!sband)
4634 return 0;
4635
4636 channels = sband->channels;
4637
4638 active_dwell = iwl4965_get_active_dwell_time(priv, band);
4639 passive_dwell = iwl4965_get_passive_dwell_time(priv, band);
4640
4641 for (i = 0, added = 0; i < sband->n_channels; i++) {
4642 if (channels[i].flags & IEEE80211_CHAN_DISABLED)
4643 continue;
4644
4645 scan_ch->channel = ieee80211_frequency_to_channel(channels[i].center_freq);
4646
4647 ch_info = iwl_get_channel_info(priv, band, scan_ch->channel);
4648 if (!is_channel_valid(ch_info)) {
4649 IWL_DEBUG_SCAN("Channel %d is INVALID for this band.\n",
4650 scan_ch->channel);
4651 continue;
4652 }
4653
4654 if (!is_active || is_channel_passive(ch_info) ||
4655 (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN))
4656 scan_ch->type = 0; /* passive */
4657 else
4658 scan_ch->type = 1; /* active */
4659
4660 if (scan_ch->type & 1)
4661 scan_ch->type |= (direct_mask << 1);
4662
4663 if (is_channel_narrow(ch_info))
4664 scan_ch->type |= (1 << 7);
4665
4666 scan_ch->active_dwell = cpu_to_le16(active_dwell);
4667 scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
4668
4669 /* Set txpower levels to defaults */
4670 scan_ch->tpc.dsp_atten = 110;
4671 /* scan_pwr_info->tpc.dsp_atten; */
4672
4673 /*scan_pwr_info->tpc.tx_gain; */
4674 if (band == IEEE80211_BAND_5GHZ)
4675 scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
4676 else {
4677 scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
4678 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
4679 * power level:
4680 * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
4681 */
4682 }
4683
4684 IWL_DEBUG_SCAN("Scanning %d [%s %d]\n",
4685 scan_ch->channel,
4686 (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
4687 (scan_ch->type & 1) ?
4688 active_dwell : passive_dwell);
4689
4690 scan_ch++;
4691 added++;
4692 }
4693
4694 IWL_DEBUG_SCAN("total channels to scan %d \n", added);
4695 return added;
4696}
4697
4698static void iwl4965_init_hw_rates(struct iwl_priv *priv,
4699 struct ieee80211_rate *rates)
4700{
4701 int i;
4702
4703 for (i = 0; i < IWL_RATE_COUNT; i++) {
4704 rates[i].bitrate = iwl4965_rates[i].ieee * 5;
4705 rates[i].hw_value = i; /* Rate scaling will work on indexes */
4706 rates[i].hw_value_short = i;
4707 rates[i].flags = 0;
4708 if ((i > IWL_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) {
4709 /*
4710 * If CCK != 1M then set short preamble rate flag.
4711 */
4712 rates[i].flags |=
4713 (iwl4965_rates[i].plcp == IWL_RATE_1M_PLCP) ?
4714 0 : IEEE80211_RATE_SHORT_PREAMBLE;
4715 }
4716 }
4717}
4718
4719/**
4720 * iwl4965_init_geos - Initialize mac80211's geo/channel info based from eeprom
4721 */
4722int iwl4965_init_geos(struct iwl_priv *priv)
4723{
4724 struct iwl_channel_info *ch;
4725 struct ieee80211_supported_band *sband;
4726 struct ieee80211_channel *channels;
4727 struct ieee80211_channel *geo_ch;
4728 struct ieee80211_rate *rates;
4729 int i = 0;
4730
4731 if (priv->bands[IEEE80211_BAND_2GHZ].n_bitrates ||
4732 priv->bands[IEEE80211_BAND_5GHZ].n_bitrates) {
4733 IWL_DEBUG_INFO("Geography modes already initialized.\n");
4734 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
4735 return 0;
4736 }
4737
4738 channels = kzalloc(sizeof(struct ieee80211_channel) *
4739 priv->channel_count, GFP_KERNEL);
4740 if (!channels)
4741 return -ENOMEM;
4742
4743 rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_RATE_COUNT + 1)),
4744 GFP_KERNEL);
4745 if (!rates) {
4746 kfree(channels);
4747 return -ENOMEM;
4748 }
4749
4750 /* 5.2GHz channels start after the 2.4GHz channels */
4751 sband = &priv->bands[IEEE80211_BAND_5GHZ];
4752 sband->channels = &channels[ARRAY_SIZE(iwl_eeprom_band_1)];
4753 /* just OFDM */
4754 sband->bitrates = &rates[IWL_FIRST_OFDM_RATE];
4755 sband->n_bitrates = IWL_RATE_COUNT - IWL_FIRST_OFDM_RATE;
4756
4757 iwl4965_init_ht_hw_capab(priv, &sband->ht_info, IEEE80211_BAND_5GHZ);
4758
4759 sband = &priv->bands[IEEE80211_BAND_2GHZ];
4760 sband->channels = channels;
4761 /* OFDM & CCK */
4762 sband->bitrates = rates;
4763 sband->n_bitrates = IWL_RATE_COUNT;
4764
4765 iwl4965_init_ht_hw_capab(priv, &sband->ht_info, IEEE80211_BAND_2GHZ);
4766
4767 priv->ieee_channels = channels;
4768 priv->ieee_rates = rates;
4769
4770 iwl4965_init_hw_rates(priv, rates);
4771
4772 for (i = 0; i < priv->channel_count; i++) {
4773 ch = &priv->channel_info[i];
4774
4775 /* FIXME: might be removed if scan is OK */
4776 if (!is_channel_valid(ch))
4777 continue;
4778
4779 if (is_channel_a_band(ch))
4780 sband = &priv->bands[IEEE80211_BAND_5GHZ];
4781 else
4782 sband = &priv->bands[IEEE80211_BAND_2GHZ];
4783
4784 geo_ch = &sband->channels[sband->n_channels++];
4785
4786 geo_ch->center_freq = ieee80211_channel_to_frequency(ch->channel);
4787 geo_ch->max_power = ch->max_power_avg;
4788 geo_ch->max_antenna_gain = 0xff;
4789 geo_ch->hw_value = ch->channel;
4790
4791 if (is_channel_valid(ch)) {
4792 if (!(ch->flags & EEPROM_CHANNEL_IBSS))
4793 geo_ch->flags |= IEEE80211_CHAN_NO_IBSS;
4794
4795 if (!(ch->flags & EEPROM_CHANNEL_ACTIVE))
4796 geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN;
4797
4798 if (ch->flags & EEPROM_CHANNEL_RADAR)
4799 geo_ch->flags |= IEEE80211_CHAN_RADAR;
4800
4801 if (ch->max_power_avg > priv->max_channel_txpower_limit)
4802 priv->max_channel_txpower_limit =
4803 ch->max_power_avg;
4804 } else {
4805 geo_ch->flags |= IEEE80211_CHAN_DISABLED;
4806 }
4807
4808 /* Save flags for reg domain usage */
4809 geo_ch->orig_flags = geo_ch->flags;
4810
4811 IWL_DEBUG_INFO("Channel %d Freq=%d[%sGHz] %s flag=0%X\n",
4812 ch->channel, geo_ch->center_freq,
4813 is_channel_a_band(ch) ? "5.2" : "2.4",
4814 geo_ch->flags & IEEE80211_CHAN_DISABLED ?
4815 "restricted" : "valid",
4816 geo_ch->flags);
4817 }
4818
4819 if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) &&
4820 priv->cfg->sku & IWL_SKU_A) {
4821 printk(KERN_INFO DRV_NAME
4822 ": Incorrectly detected BG card as ABG. Please send "
4823 "your PCI ID 0x%04X:0x%04X to maintainer.\n",
4824 priv->pci_dev->device, priv->pci_dev->subsystem_device);
4825 priv->cfg->sku &= ~IWL_SKU_A;
4826 }
4827
4828 printk(KERN_INFO DRV_NAME
4829 ": Tunable channels: %d 802.11bg, %d 802.11a channels\n",
4830 priv->bands[IEEE80211_BAND_2GHZ].n_channels,
4831 priv->bands[IEEE80211_BAND_5GHZ].n_channels);
4832
4833 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
4834 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
4835 &priv->bands[IEEE80211_BAND_2GHZ];
4836 if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
4837 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
4838 &priv->bands[IEEE80211_BAND_5GHZ];
4839
4840 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
4841
4842 return 0;
4843}
4844
4845/*
4846 * iwl4965_free_geos - undo allocations in iwl4965_init_geos
4847 */
4848void iwl4965_free_geos(struct iwl_priv *priv)
4849{
4850 kfree(priv->ieee_channels);
4851 kfree(priv->ieee_rates);
4852 clear_bit(STATUS_GEO_CONFIGURED, &priv->status);
4853}
4854
4855/******************************************************************************
4856 *
4857 * uCode download functions
4858 *
4859 ******************************************************************************/
4860
4861static void iwl4965_dealloc_ucode_pci(struct iwl_priv *priv)
4862{
4863 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
4864 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
4865 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
4866 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
4867 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
4868 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
4869}
4870
4871/**
4872 * iwl4965_verify_inst_full - verify runtime uCode image in card vs. host,
4873 * looking at all data.
4874 */
4875static int iwl4965_verify_inst_full(struct iwl_priv *priv, __le32 *image,
4876 u32 len)
4877{
4878 u32 val;
4879 u32 save_len = len;
4880 int rc = 0;
4881 u32 errcnt;
4882
4883 IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
4884
4885 rc = iwl_grab_nic_access(priv);
4886 if (rc)
4887 return rc;
4888
4889 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, RTC_INST_LOWER_BOUND);
4890
4891 errcnt = 0;
4892 for (; len > 0; len -= sizeof(u32), image++) {
4893 /* read data comes through single port, auto-incr addr */
4894 /* NOTE: Use the debugless read so we don't flood kernel log
4895 * if IWL_DL_IO is set */
4896 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
4897 if (val != le32_to_cpu(*image)) {
4898 IWL_ERROR("uCode INST section is invalid at "
4899 "offset 0x%x, is 0x%x, s/b 0x%x\n",
4900 save_len - len, val, le32_to_cpu(*image));
4901 rc = -EIO;
4902 errcnt++;
4903 if (errcnt >= 20)
4904 break;
4905 }
4906 }
4907
4908 iwl_release_nic_access(priv);
4909
4910 if (!errcnt)
4911 IWL_DEBUG_INFO
4912 ("ucode image in INSTRUCTION memory is good\n");
4913
4914 return rc;
4915}
4916
4917
4918/**
4919 * iwl4965_verify_inst_sparse - verify runtime uCode image in card vs. host,
4920 * using sample data 100 bytes apart. If these sample points are good,
4921 * it's a pretty good bet that everything between them is good, too.
4922 */
4923static int iwl4965_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
4924{
4925 u32 val;
4926 int rc = 0;
4927 u32 errcnt = 0;
4928 u32 i;
4929
4930 IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
4931
4932 rc = iwl_grab_nic_access(priv);
4933 if (rc)
4934 return rc;
4935
4936 for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
4937 /* read data comes through single port, auto-incr addr */
4938 /* NOTE: Use the debugless read so we don't flood kernel log
4939 * if IWL_DL_IO is set */
4940 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
4941 i + RTC_INST_LOWER_BOUND);
4942 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
4943 if (val != le32_to_cpu(*image)) {
4944#if 0 /* Enable this if you want to see details */
4945 IWL_ERROR("uCode INST section is invalid at "
4946 "offset 0x%x, is 0x%x, s/b 0x%x\n",
4947 i, val, *image);
4948#endif
4949 rc = -EIO;
4950 errcnt++;
4951 if (errcnt >= 3)
4952 break;
4953 }
4954 }
4955
4956 iwl_release_nic_access(priv);
4957
4958 return rc;
4959}
4960
4961
4962/**
4963 * iwl4965_verify_ucode - determine which instruction image is in SRAM,
4964 * and verify its contents
4965 */
4966static int iwl4965_verify_ucode(struct iwl_priv *priv)
4967{
4968 __le32 *image;
4969 u32 len;
4970 int rc = 0;
4971
4972 /* Try bootstrap */
4973 image = (__le32 *)priv->ucode_boot.v_addr;
4974 len = priv->ucode_boot.len;
4975 rc = iwl4965_verify_inst_sparse(priv, image, len);
4976 if (rc == 0) {
4977 IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n");
4978 return 0;
4979 }
4980
4981 /* Try initialize */
4982 image = (__le32 *)priv->ucode_init.v_addr;
4983 len = priv->ucode_init.len;
4984 rc = iwl4965_verify_inst_sparse(priv, image, len);
4985 if (rc == 0) {
4986 IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n");
4987 return 0;
4988 }
4989
4990 /* Try runtime/protocol */
4991 image = (__le32 *)priv->ucode_code.v_addr;
4992 len = priv->ucode_code.len;
4993 rc = iwl4965_verify_inst_sparse(priv, image, len);
4994 if (rc == 0) {
4995 IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n");
4996 return 0;
4997 }
4998
4999 IWL_ERROR("NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
5000
5001 /* Since nothing seems to match, show first several data entries in
5002 * instruction SRAM, so maybe visual inspection will give a clue.
5003 * Selection of bootstrap image (vs. other images) is arbitrary. */
5004 image = (__le32 *)priv->ucode_boot.v_addr;
5005 len = priv->ucode_boot.len;
5006 rc = iwl4965_verify_inst_full(priv, image, len);
5007
5008 return rc;
5009}
5010
5011static void iwl4965_nic_start(struct iwl_priv *priv)
5012{
5013 /* Remove all resets to allow NIC to operate */
5014 iwl_write32(priv, CSR_RESET, 0);
5015}
5016
5017
5018/**
5019 * iwl4965_read_ucode - Read uCode images from disk file.
5020 *
5021 * Copy into buffers for card to fetch via bus-mastering
5022 */
5023static int iwl4965_read_ucode(struct iwl_priv *priv)
5024{
5025 struct iwl4965_ucode *ucode;
5026 int ret;
5027 const struct firmware *ucode_raw;
5028 const char *name = priv->cfg->fw_name;
5029 u8 *src;
5030 size_t len;
5031 u32 ver, inst_size, data_size, init_size, init_data_size, boot_size;
5032
5033 /* Ask kernel firmware_class module to get the boot firmware off disk.
5034 * request_firmware() is synchronous, file is in memory on return. */
5035 ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev);
5036 if (ret < 0) {
5037 IWL_ERROR("%s firmware file req failed: Reason %d\n",
5038 name, ret);
5039 goto error;
5040 }
5041
5042 IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
5043 name, ucode_raw->size);
5044
5045 /* Make sure that we got at least our header! */
5046 if (ucode_raw->size < sizeof(*ucode)) {
5047 IWL_ERROR("File size way too small!\n");
5048 ret = -EINVAL;
5049 goto err_release;
5050 }
5051
5052 /* Data from ucode file: header followed by uCode images */
5053 ucode = (void *)ucode_raw->data;
5054
5055 ver = le32_to_cpu(ucode->ver);
5056 inst_size = le32_to_cpu(ucode->inst_size);
5057 data_size = le32_to_cpu(ucode->data_size);
5058 init_size = le32_to_cpu(ucode->init_size);
5059 init_data_size = le32_to_cpu(ucode->init_data_size);
5060 boot_size = le32_to_cpu(ucode->boot_size);
5061
5062 IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver);
5063 IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n",
5064 inst_size);
5065 IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n",
5066 data_size);
5067 IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n",
5068 init_size);
5069 IWL_DEBUG_INFO("f/w package hdr init data size = %u\n",
5070 init_data_size);
5071 IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n",
5072 boot_size);
5073
5074 /* Verify size of file vs. image size info in file's header */
5075 if (ucode_raw->size < sizeof(*ucode) +
5076 inst_size + data_size + init_size +
5077 init_data_size + boot_size) {
5078
5079 IWL_DEBUG_INFO("uCode file size %d too small\n",
5080 (int)ucode_raw->size);
5081 ret = -EINVAL;
5082 goto err_release;
5083 }
5084
5085 /* Verify that uCode images will fit in card's SRAM */
5086 if (inst_size > IWL_MAX_INST_SIZE) {
5087 IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
5088 inst_size);
5089 ret = -EINVAL;
5090 goto err_release;
5091 }
5092
5093 if (data_size > IWL_MAX_DATA_SIZE) {
5094 IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
5095 data_size);
5096 ret = -EINVAL;
5097 goto err_release;
5098 }
5099 if (init_size > IWL_MAX_INST_SIZE) {
5100 IWL_DEBUG_INFO
5101 ("uCode init instr len %d too large to fit in\n",
5102 init_size);
5103 ret = -EINVAL;
5104 goto err_release;
5105 }
5106 if (init_data_size > IWL_MAX_DATA_SIZE) {
5107 IWL_DEBUG_INFO
5108 ("uCode init data len %d too large to fit in\n",
5109 init_data_size);
5110 ret = -EINVAL;
5111 goto err_release;
5112 }
5113 if (boot_size > IWL_MAX_BSM_SIZE) {
5114 IWL_DEBUG_INFO
5115 ("uCode boot instr len %d too large to fit in\n",
5116 boot_size);
5117 ret = -EINVAL;
5118 goto err_release;
5119 }
5120
5121 /* Allocate ucode buffers for card's bus-master loading ... */
5122
5123 /* Runtime instructions and 2 copies of data:
5124 * 1) unmodified from disk
5125 * 2) backup cache for save/restore during power-downs */
5126 priv->ucode_code.len = inst_size;
5127 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
5128
5129 priv->ucode_data.len = data_size;
5130 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
5131
5132 priv->ucode_data_backup.len = data_size;
5133 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
5134
5135 /* Initialization instructions and data */
5136 if (init_size && init_data_size) {
5137 priv->ucode_init.len = init_size;
5138 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
5139
5140 priv->ucode_init_data.len = init_data_size;
5141 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
5142
5143 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
5144 goto err_pci_alloc;
5145 }
5146
5147 /* Bootstrap (instructions only, no data) */
5148 if (boot_size) {
5149 priv->ucode_boot.len = boot_size;
5150 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
5151
5152 if (!priv->ucode_boot.v_addr)
5153 goto err_pci_alloc;
5154 }
5155
5156 /* Copy images into buffers for card's bus-master reads ... */
5157
5158 /* Runtime instructions (first block of data in file) */
5159 src = &ucode->data[0];
5160 len = priv->ucode_code.len;
5161 IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len);
5162 memcpy(priv->ucode_code.v_addr, src, len);
5163 IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
5164 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
5165
5166 /* Runtime data (2nd block)
5167 * NOTE: Copy into backup buffer will be done in iwl4965_up() */
5168 src = &ucode->data[inst_size];
5169 len = priv->ucode_data.len;
5170 IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len);
5171 memcpy(priv->ucode_data.v_addr, src, len);
5172 memcpy(priv->ucode_data_backup.v_addr, src, len);
5173
5174 /* Initialization instructions (3rd block) */
5175 if (init_size) {
5176 src = &ucode->data[inst_size + data_size];
5177 len = priv->ucode_init.len;
5178 IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
5179 len);
5180 memcpy(priv->ucode_init.v_addr, src, len);
5181 }
5182
5183 /* Initialization data (4th block) */
5184 if (init_data_size) {
5185 src = &ucode->data[inst_size + data_size + init_size];
5186 len = priv->ucode_init_data.len;
5187 IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n",
5188 len);
5189 memcpy(priv->ucode_init_data.v_addr, src, len);
5190 }
5191
5192 /* Bootstrap instructions (5th block) */
5193 src = &ucode->data[inst_size + data_size + init_size + init_data_size];
5194 len = priv->ucode_boot.len;
5195 IWL_DEBUG_INFO("Copying (but not loading) boot instr len %Zd\n", len);
5196 memcpy(priv->ucode_boot.v_addr, src, len);
5197
5198 /* We have our copies now, allow OS release its copies */
5199 release_firmware(ucode_raw);
5200 return 0;
5201
5202 err_pci_alloc:
5203 IWL_ERROR("failed to allocate pci memory\n");
5204 ret = -ENOMEM;
5205 iwl4965_dealloc_ucode_pci(priv);
5206
5207 err_release:
5208 release_firmware(ucode_raw);
5209
5210 error:
5211 return ret;
5212}
5213
5214
5215/**
5216 * iwl4965_set_ucode_ptrs - Set uCode address location
5217 *
5218 * Tell initialization uCode where to find runtime uCode.
5219 *
5220 * BSM registers initially contain pointers to initialization uCode.
5221 * We need to replace them to load runtime uCode inst and data,
5222 * and to save runtime data when powering down.
5223 */
5224static int iwl4965_set_ucode_ptrs(struct iwl_priv *priv)
5225{
5226 dma_addr_t pinst;
5227 dma_addr_t pdata;
5228 int rc = 0;
5229 unsigned long flags;
5230
5231 /* bits 35:4 for 4965 */
5232 pinst = priv->ucode_code.p_addr >> 4;
5233 pdata = priv->ucode_data_backup.p_addr >> 4;
5234
5235 spin_lock_irqsave(&priv->lock, flags);
5236 rc = iwl_grab_nic_access(priv);
5237 if (rc) {
5238 spin_unlock_irqrestore(&priv->lock, flags);
5239 return rc;
5240 }
5241
5242 /* Tell bootstrap uCode where to find image to load */
5243 iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
5244 iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
5245 iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
5246 priv->ucode_data.len);
5247
5248 /* Inst bytecount must be last to set up, bit 31 signals uCode
5249 * that all new ptr/size info is in place */
5250 iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
5251 priv->ucode_code.len | BSM_DRAM_INST_LOAD);
5252
5253 iwl_release_nic_access(priv);
5254
5255 spin_unlock_irqrestore(&priv->lock, flags);
5256
5257 IWL_DEBUG_INFO("Runtime uCode pointers are set.\n");
5258
5259 return rc;
5260}
5261
5262/**
5263 * iwl4965_init_alive_start - Called after REPLY_ALIVE notification received
5264 *
5265 * Called after REPLY_ALIVE notification received from "initialize" uCode.
5266 *
5267 * The 4965 "initialize" ALIVE reply contains calibration data for:
5268 * Voltage, temperature, and MIMO tx gain correction, now stored in priv
5269 * (3945 does not contain this data).
5270 *
5271 * Tell "initialize" uCode to go ahead and load the runtime uCode.
5272*/
5273static void iwl4965_init_alive_start(struct iwl_priv *priv)
5274{
5275 /* Check alive response for "valid" sign from uCode */
5276 if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
5277 /* We had an error bringing up the hardware, so take it
5278 * all the way back down so we can try again */
5279 IWL_DEBUG_INFO("Initialize Alive failed.\n");
5280 goto restart;
5281 }
5282
5283 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
5284 * This is a paranoid check, because we would not have gotten the
5285 * "initialize" alive if code weren't properly loaded. */
5286 if (iwl4965_verify_ucode(priv)) {
5287 /* Runtime instruction load was bad;
5288 * take it all the way back down so we can try again */
5289 IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n");
5290 goto restart;
5291 }
5292
5293 /* Calculate temperature */
5294 priv->temperature = iwl4965_get_temperature(priv);
5295
5296 /* Send pointers to protocol/runtime uCode image ... init code will
5297 * load and launch runtime uCode, which will send us another "Alive"
5298 * notification. */
5299 IWL_DEBUG_INFO("Initialization Alive received.\n");
5300 if (iwl4965_set_ucode_ptrs(priv)) {
5301 /* Runtime instruction load won't happen;
5302 * take it all the way back down so we can try again */
5303 IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n");
5304 goto restart;
5305 }
5306 return;
5307
5308 restart:
5309 queue_work(priv->workqueue, &priv->restart);
5310}
5311
5312
5313/**
5314 * iwl4965_alive_start - called after REPLY_ALIVE notification received
5315 * from protocol/runtime uCode (initialization uCode's
5316 * Alive gets handled by iwl4965_init_alive_start()).
5317 */
5318static void iwl4965_alive_start(struct iwl_priv *priv)
5319{
5320 int ret = 0;
5321
5322 IWL_DEBUG_INFO("Runtime Alive received.\n");
5323
5324 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
5325 /* We had an error bringing up the hardware, so take it
5326 * all the way back down so we can try again */
5327 IWL_DEBUG_INFO("Alive failed.\n");
5328 goto restart;
5329 }
5330
5331 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
5332 * This is a paranoid check, because we would not have gotten the
5333 * "runtime" alive if code weren't properly loaded. */
5334 if (iwl4965_verify_ucode(priv)) {
5335 /* Runtime instruction load was bad;
5336 * take it all the way back down so we can try again */
5337 IWL_DEBUG_INFO("Bad runtime uCode load.\n");
5338 goto restart;
5339 }
5340
5341 iwlcore_clear_stations_table(priv);
5342
5343 ret = priv->cfg->ops->lib->alive_notify(priv);
5344 if (ret) {
5345 IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n",
5346 ret);
5347 goto restart;
5348 }
5349
5350 /* After the ALIVE response, we can send host commands to 4965 uCode */
5351 set_bit(STATUS_ALIVE, &priv->status);
5352
5353 /* Clear out the uCode error bit if it is set */
5354 clear_bit(STATUS_FW_ERROR, &priv->status);
5355
5356 if (iwl_is_rfkill(priv))
5357 return;
5358
5359 ieee80211_start_queues(priv->hw);
5360
5361 priv->active_rate = priv->rates_mask;
5362 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
5363
5364 iwl4965_send_power_mode(priv, IWL_POWER_LEVEL(priv->power_mode));
5365
5366 if (iwl_is_associated(priv)) {
5367 struct iwl4965_rxon_cmd *active_rxon =
5368 (struct iwl4965_rxon_cmd *)(&priv->active_rxon);
5369
5370 memcpy(&priv->staging_rxon, &priv->active_rxon,
5371 sizeof(priv->staging_rxon));
5372 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
5373 } else {
5374 /* Initialize our rx_config data */
5375 iwl4965_connection_init_rx_config(priv);
5376 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
5377 }
5378
5379 /* Configure Bluetooth device coexistence support */
5380 iwl4965_send_bt_config(priv);
5381
5382 /* Configure the adapter for unassociated operation */
5383 iwl4965_commit_rxon(priv);
5384
5385 /* At this point, the NIC is initialized and operational */
5386 priv->notif_missed_beacons = 0;
5387
5388 iwl4965_rf_kill_ct_config(priv);
5389
5390 iwl_leds_register(priv);
5391
5392 IWL_DEBUG_INFO("ALIVE processing complete.\n");
5393 set_bit(STATUS_READY, &priv->status);
5394 wake_up_interruptible(&priv->wait_command_queue);
5395
5396 if (priv->error_recovering)
5397 iwl4965_error_recovery(priv);
5398
5399 iwlcore_low_level_notify(priv, IWLCORE_START_EVT);
5400 ieee80211_notify_mac(priv->hw, IEEE80211_NOTIFY_RE_ASSOC);
5401 return;
5402
5403 restart:
5404 queue_work(priv->workqueue, &priv->restart);
5405}
5406
5407static void iwl4965_cancel_deferred_work(struct iwl_priv *priv);
5408
5409static void __iwl4965_down(struct iwl_priv *priv)
5410{
5411 unsigned long flags;
5412 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
5413 struct ieee80211_conf *conf = NULL;
5414
5415 IWL_DEBUG_INFO(DRV_NAME " is going down\n");
5416
5417 conf = ieee80211_get_hw_conf(priv->hw);
5418
5419 if (!exit_pending)
5420 set_bit(STATUS_EXIT_PENDING, &priv->status);
5421
5422 iwl_leds_unregister(priv);
5423
5424 iwlcore_low_level_notify(priv, IWLCORE_STOP_EVT);
5425
5426 iwlcore_clear_stations_table(priv);
5427
5428 /* Unblock any waiting calls */
5429 wake_up_interruptible_all(&priv->wait_command_queue);
5430
5431 /* Wipe out the EXIT_PENDING status bit if we are not actually
5432 * exiting the module */
5433 if (!exit_pending)
5434 clear_bit(STATUS_EXIT_PENDING, &priv->status);
5435
5436 /* stop and reset the on-board processor */
5437 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
5438
5439 /* tell the device to stop sending interrupts */
5440 spin_lock_irqsave(&priv->lock, flags);
5441 iwl4965_disable_interrupts(priv);
5442 spin_unlock_irqrestore(&priv->lock, flags);
5443 iwl_synchronize_irq(priv);
5444
5445 if (priv->mac80211_registered)
5446 ieee80211_stop_queues(priv->hw);
5447
5448 /* If we have not previously called iwl4965_init() then
5449 * clear all bits but the RF Kill and SUSPEND bits and return */
5450 if (!iwl_is_init(priv)) {
5451 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
5452 STATUS_RF_KILL_HW |
5453 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
5454 STATUS_RF_KILL_SW |
5455 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
5456 STATUS_GEO_CONFIGURED |
5457 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
5458 STATUS_IN_SUSPEND;
5459 goto exit;
5460 }
5461
5462 /* ...otherwise clear out all the status bits but the RF Kill and
5463 * SUSPEND bits and continue taking the NIC down. */
5464 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
5465 STATUS_RF_KILL_HW |
5466 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
5467 STATUS_RF_KILL_SW |
5468 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
5469 STATUS_GEO_CONFIGURED |
5470 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
5471 STATUS_IN_SUSPEND |
5472 test_bit(STATUS_FW_ERROR, &priv->status) <<
5473 STATUS_FW_ERROR;
5474
5475 spin_lock_irqsave(&priv->lock, flags);
5476 iwl_clear_bit(priv, CSR_GP_CNTRL,
5477 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
5478 spin_unlock_irqrestore(&priv->lock, flags);
5479
5480 iwl4965_hw_txq_ctx_stop(priv);
5481 iwl4965_hw_rxq_stop(priv);
5482
5483 spin_lock_irqsave(&priv->lock, flags);
5484 if (!iwl_grab_nic_access(priv)) {
5485 iwl_write_prph(priv, APMG_CLK_DIS_REG,
5486 APMG_CLK_VAL_DMA_CLK_RQT);
5487 iwl_release_nic_access(priv);
5488 }
5489 spin_unlock_irqrestore(&priv->lock, flags);
5490
5491 udelay(5);
5492
5493 iwl4965_hw_nic_stop_master(priv);
5494 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
5495 iwl4965_hw_nic_reset(priv);
5496
5497 exit:
5498 memset(&priv->card_alive, 0, sizeof(struct iwl4965_alive_resp));
5499
5500 if (priv->ibss_beacon)
5501 dev_kfree_skb(priv->ibss_beacon);
5502 priv->ibss_beacon = NULL;
5503
5504 /* clear out any free frames */
5505 iwl4965_clear_free_frames(priv);
5506}
5507
5508static void iwl4965_down(struct iwl_priv *priv)
5509{
5510 mutex_lock(&priv->mutex);
5511 __iwl4965_down(priv);
5512 mutex_unlock(&priv->mutex);
5513
5514 iwl4965_cancel_deferred_work(priv);
5515}
5516
5517#define MAX_HW_RESTARTS 5
5518
5519static int __iwl4965_up(struct iwl_priv *priv)
5520{
5521 int i;
5522 int ret;
5523
5524 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
5525 IWL_WARNING("Exit pending; will not bring the NIC up\n");
5526 return -EIO;
5527 }
5528
5529 if (test_bit(STATUS_RF_KILL_SW, &priv->status)) {
5530 IWL_WARNING("Radio disabled by SW RF kill (module "
5531 "parameter)\n");
5532 iwl_rfkill_set_hw_state(priv);
5533 return -ENODEV;
5534 }
5535
5536 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
5537 IWL_ERROR("ucode not available for device bringup\n");
5538 return -EIO;
5539 }
5540
5541 /* If platform's RF_KILL switch is NOT set to KILL */
5542 if (iwl_read32(priv, CSR_GP_CNTRL) &
5543 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
5544 clear_bit(STATUS_RF_KILL_HW, &priv->status);
5545 else {
5546 set_bit(STATUS_RF_KILL_HW, &priv->status);
5547 if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) {
5548 iwl_rfkill_set_hw_state(priv);
5549 IWL_WARNING("Radio disabled by HW RF Kill switch\n");
5550 return -ENODEV;
5551 }
5552 }
5553
5554 iwl_rfkill_set_hw_state(priv);
5555 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
5556
5557 ret = priv->cfg->ops->lib->hw_nic_init(priv);
5558 if (ret) {
5559 IWL_ERROR("Unable to init nic\n");
5560 return ret;
5561 }
5562
5563 /* make sure rfkill handshake bits are cleared */
5564 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
5565 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
5566 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
5567
5568 /* clear (again), then enable host interrupts */
5569 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
5570 iwl4965_enable_interrupts(priv);
5571
5572 /* really make sure rfkill handshake bits are cleared */
5573 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
5574 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
5575
5576 /* Copy original ucode data image from disk into backup cache.
5577 * This will be used to initialize the on-board processor's
5578 * data SRAM for a clean start when the runtime program first loads. */
5579 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
5580 priv->ucode_data.len);
5581
5582 /* We return success when we resume from suspend and rf_kill is on. */
5583 if (test_bit(STATUS_RF_KILL_HW, &priv->status))
5584 return 0;
5585
5586 for (i = 0; i < MAX_HW_RESTARTS; i++) {
5587
5588 iwlcore_clear_stations_table(priv);
5589
5590 /* load bootstrap state machine,
5591 * load bootstrap program into processor's memory,
5592 * prepare to load the "initialize" uCode */
5593 ret = priv->cfg->ops->lib->load_ucode(priv);
5594
5595 if (ret) {
5596 IWL_ERROR("Unable to set up bootstrap uCode: %d\n", ret);
5597 continue;
5598 }
5599
5600 /* start card; "initialize" will load runtime ucode */
5601 iwl4965_nic_start(priv);
5602
5603 IWL_DEBUG_INFO(DRV_NAME " is coming up\n");
5604
5605 return 0;
5606 }
5607
5608 set_bit(STATUS_EXIT_PENDING, &priv->status);
5609 __iwl4965_down(priv);
5610
5611 /* tried to restart and config the device for as long as our
5612 * patience could withstand */
5613 IWL_ERROR("Unable to initialize device after %d attempts.\n", i);
5614 return -EIO;
5615}
5616
5617
5618/*****************************************************************************
5619 *
5620 * Workqueue callbacks
5621 *
5622 *****************************************************************************/
5623
5624static void iwl4965_bg_init_alive_start(struct work_struct *data)
5625{
5626 struct iwl_priv *priv =
5627 container_of(data, struct iwl_priv, init_alive_start.work);
5628
5629 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
5630 return;
5631
5632 mutex_lock(&priv->mutex);
5633 iwl4965_init_alive_start(priv);
5634 mutex_unlock(&priv->mutex);
5635}
5636
5637static void iwl4965_bg_alive_start(struct work_struct *data)
5638{
5639 struct iwl_priv *priv =
5640 container_of(data, struct iwl_priv, alive_start.work);
5641
5642 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
5643 return;
5644
5645 mutex_lock(&priv->mutex);
5646 iwl4965_alive_start(priv);
5647 mutex_unlock(&priv->mutex);
5648}
5649
5650static void iwl4965_bg_rf_kill(struct work_struct *work)
5651{
5652 struct iwl_priv *priv = container_of(work, struct iwl_priv, rf_kill);
5653
5654 wake_up_interruptible(&priv->wait_command_queue);
5655
5656 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
5657 return;
5658
5659 mutex_lock(&priv->mutex);
5660
5661 if (!iwl_is_rfkill(priv)) {
5662 IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL,
5663 "HW and/or SW RF Kill no longer active, restarting "
5664 "device\n");
5665 if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
5666 queue_work(priv->workqueue, &priv->restart);
5667 } else {
5668 /* make sure mac80211 stop sending Tx frame */
5669 if (priv->mac80211_registered)
5670 ieee80211_stop_queues(priv->hw);
5671
5672 if (!test_bit(STATUS_RF_KILL_HW, &priv->status))
5673 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
5674 "disabled by SW switch\n");
5675 else
5676 IWL_WARNING("Radio Frequency Kill Switch is On:\n"
5677 "Kill switch must be turned off for "
5678 "wireless networking to work.\n");
5679 }
5680 iwl_rfkill_set_hw_state(priv);
5681
5682 mutex_unlock(&priv->mutex);
5683}
5684
5685#define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
5686
5687static void iwl4965_bg_scan_check(struct work_struct *data)
5688{
5689 struct iwl_priv *priv =
5690 container_of(data, struct iwl_priv, scan_check.work);
5691
5692 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
5693 return;
5694
5695 mutex_lock(&priv->mutex);
5696 if (test_bit(STATUS_SCANNING, &priv->status) ||
5697 test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
5698 IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN,
5699 "Scan completion watchdog resetting adapter (%dms)\n",
5700 jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG));
5701
5702 if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
5703 iwl4965_send_scan_abort(priv);
5704 }
5705 mutex_unlock(&priv->mutex);
5706}
5707
5708static void iwl4965_bg_request_scan(struct work_struct *data)
5709{
5710 struct iwl_priv *priv =
5711 container_of(data, struct iwl_priv, request_scan);
5712 struct iwl_host_cmd cmd = {
5713 .id = REPLY_SCAN_CMD,
5714 .len = sizeof(struct iwl4965_scan_cmd),
5715 .meta.flags = CMD_SIZE_HUGE,
5716 };
5717 struct iwl4965_scan_cmd *scan;
5718 struct ieee80211_conf *conf = NULL;
5719 u16 cmd_len;
5720 enum ieee80211_band band;
5721 u8 direct_mask;
5722 int ret = 0;
5723
5724 conf = ieee80211_get_hw_conf(priv->hw);
5725
5726 mutex_lock(&priv->mutex);
5727
5728 if (!iwl_is_ready(priv)) {
5729 IWL_WARNING("request scan called when driver not ready.\n");
5730 goto done;
5731 }
5732
5733 /* Make sure the scan wasn't cancelled before this queued work
5734 * was given the chance to run... */
5735 if (!test_bit(STATUS_SCANNING, &priv->status))
5736 goto done;
5737
5738 /* This should never be called or scheduled if there is currently
5739 * a scan active in the hardware. */
5740 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
5741 IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. "
5742 "Ignoring second request.\n");
5743 ret = -EIO;
5744 goto done;
5745 }
5746
5747 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
5748 IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n");
5749 goto done;
5750 }
5751
5752 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
5753 IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n");
5754 goto done;
5755 }
5756
5757 if (iwl_is_rfkill(priv)) {
5758 IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n");
5759 goto done;
5760 }
5761
5762 if (!test_bit(STATUS_READY, &priv->status)) {
5763 IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n");
5764 goto done;
5765 }
5766
5767 if (!priv->scan_bands) {
5768 IWL_DEBUG_HC("Aborting scan due to no requested bands\n");
5769 goto done;
5770 }
5771
5772 if (!priv->scan) {
5773 priv->scan = kmalloc(sizeof(struct iwl4965_scan_cmd) +
5774 IWL_MAX_SCAN_SIZE, GFP_KERNEL);
5775 if (!priv->scan) {
5776 ret = -ENOMEM;
5777 goto done;
5778 }
5779 }
5780 scan = priv->scan;
5781 memset(scan, 0, sizeof(struct iwl4965_scan_cmd) + IWL_MAX_SCAN_SIZE);
5782
5783 scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
5784 scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
5785
5786 if (iwl_is_associated(priv)) {
5787 u16 interval = 0;
5788 u32 extra;
5789 u32 suspend_time = 100;
5790 u32 scan_suspend_time = 100;
5791 unsigned long flags;
5792
5793 IWL_DEBUG_INFO("Scanning while associated...\n");
5794
5795 spin_lock_irqsave(&priv->lock, flags);
5796 interval = priv->beacon_int;
5797 spin_unlock_irqrestore(&priv->lock, flags);
5798
5799 scan->suspend_time = 0;
5800 scan->max_out_time = cpu_to_le32(200 * 1024);
5801 if (!interval)
5802 interval = suspend_time;
5803
5804 extra = (suspend_time / interval) << 22;
5805 scan_suspend_time = (extra |
5806 ((suspend_time % interval) * 1024));
5807 scan->suspend_time = cpu_to_le32(scan_suspend_time);
5808 IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n",
5809 scan_suspend_time, interval);
5810 }
5811
5812 /* We should add the ability for user to lock to PASSIVE ONLY */
5813 if (priv->one_direct_scan) {
5814 IWL_DEBUG_SCAN
5815 ("Kicking off one direct scan for '%s'\n",
5816 iwl4965_escape_essid(priv->direct_ssid,
5817 priv->direct_ssid_len));
5818 scan->direct_scan[0].id = WLAN_EID_SSID;
5819 scan->direct_scan[0].len = priv->direct_ssid_len;
5820 memcpy(scan->direct_scan[0].ssid,
5821 priv->direct_ssid, priv->direct_ssid_len);
5822 direct_mask = 1;
5823 } else if (!iwl_is_associated(priv) && priv->essid_len) {
5824 IWL_DEBUG_SCAN
5825 ("Kicking off one direct scan for '%s' when not associated\n",
5826 iwl4965_escape_essid(priv->essid, priv->essid_len));
5827 scan->direct_scan[0].id = WLAN_EID_SSID;
5828 scan->direct_scan[0].len = priv->essid_len;
5829 memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len);
5830 direct_mask = 1;
5831 } else {
5832 IWL_DEBUG_SCAN("Kicking off one indirect scan.\n");
5833 direct_mask = 0;
5834 }
5835
5836 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
5837 scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id;
5838 scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
5839
5840
5841 if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) {
5842 scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
5843 scan->tx_cmd.rate_n_flags =
5844 iwl4965_hw_set_rate_n_flags(IWL_RATE_1M_PLCP,
5845 RATE_MCS_ANT_B_MSK|RATE_MCS_CCK_MSK);
5846
5847 scan->good_CRC_th = 0;
5848 band = IEEE80211_BAND_2GHZ;
5849 } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) {
5850 scan->tx_cmd.rate_n_flags =
5851 iwl4965_hw_set_rate_n_flags(IWL_RATE_6M_PLCP,
5852 RATE_MCS_ANT_B_MSK);
5853 scan->good_CRC_th = IWL_GOOD_CRC_TH;
5854 band = IEEE80211_BAND_5GHZ;
5855 } else {
5856 IWL_WARNING("Invalid scan band count\n");
5857 goto done;
5858 }
5859
5860 /* We don't build a direct scan probe request; the uCode will do
5861 * that based on the direct_mask added to each channel entry */
5862 cmd_len = iwl4965_fill_probe_req(priv, band,
5863 (struct ieee80211_mgmt *)scan->data,
5864 IWL_MAX_SCAN_SIZE - sizeof(*scan), 0);
5865
5866 scan->tx_cmd.len = cpu_to_le16(cmd_len);
5867 /* select Rx chains */
5868
5869 /* Force use of chains B and C (0x6) for scan Rx.
5870 * Avoid A (0x1) because of its off-channel reception on A-band.
5871 * MIMO is not used here, but value is required to make uCode happy. */
5872 scan->rx_chain = RXON_RX_CHAIN_DRIVER_FORCE_MSK |
5873 cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS) |
5874 (0x6 << RXON_RX_CHAIN_FORCE_SEL_POS) |
5875 (0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS));
5876
5877 if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR)
5878 scan->filter_flags = RXON_FILTER_PROMISC_MSK;
5879
5880 if (direct_mask)
5881 scan->channel_count =
5882 iwl4965_get_channels_for_scan(
5883 priv, band, 1, /* active */
5884 direct_mask,
5885 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
5886 else
5887 scan->channel_count =
5888 iwl4965_get_channels_for_scan(
5889 priv, band, 0, /* passive */
5890 direct_mask,
5891 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
5892
5893 cmd.len += le16_to_cpu(scan->tx_cmd.len) +
5894 scan->channel_count * sizeof(struct iwl4965_scan_channel);
5895 cmd.data = scan;
5896 scan->len = cpu_to_le16(cmd.len);
5897
5898 set_bit(STATUS_SCAN_HW, &priv->status);
5899 ret = iwl_send_cmd_sync(priv, &cmd);
5900 if (ret)
5901 goto done;
5902
5903 queue_delayed_work(priv->workqueue, &priv->scan_check,
5904 IWL_SCAN_CHECK_WATCHDOG);
5905
5906 mutex_unlock(&priv->mutex);
5907 return;
5908
5909 done:
5910 /* inform mac80211 scan aborted */
5911 queue_work(priv->workqueue, &priv->scan_completed);
5912 mutex_unlock(&priv->mutex);
5913}
5914
5915static void iwl4965_bg_up(struct work_struct *data)
5916{
5917 struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
5918
5919 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
5920 return;
5921
5922 mutex_lock(&priv->mutex);
5923 __iwl4965_up(priv);
5924 mutex_unlock(&priv->mutex);
5925}
5926
5927static void iwl4965_bg_restart(struct work_struct *data)
5928{
5929 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
5930
5931 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
5932 return;
5933
5934 iwl4965_down(priv);
5935 queue_work(priv->workqueue, &priv->up);
5936}
5937
5938static void iwl4965_bg_rx_replenish(struct work_struct *data)
5939{
5940 struct iwl_priv *priv =
5941 container_of(data, struct iwl_priv, rx_replenish);
5942
5943 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
5944 return;
5945
5946 mutex_lock(&priv->mutex);
5947 iwl4965_rx_replenish(priv);
5948 mutex_unlock(&priv->mutex);
5949}
5950
5951#define IWL_DELAY_NEXT_SCAN (HZ*2)
5952
5953static void iwl4965_post_associate(struct iwl_priv *priv)
5954{
5955 struct ieee80211_conf *conf = NULL;
5956 int ret = 0;
5957 DECLARE_MAC_BUF(mac);
5958
5959 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
5960 IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__);
5961 return;
5962 }
5963
5964 IWL_DEBUG_ASSOC("Associated as %d to: %s\n",
5965 priv->assoc_id,
5966 print_mac(mac, priv->active_rxon.bssid_addr));
5967
5968
5969 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
5970 return;
5971
5972
5973 if (!priv->vif || !priv->is_open)
5974 return;
5975
5976 iwl4965_scan_cancel_timeout(priv, 200);
5977
5978 conf = ieee80211_get_hw_conf(priv->hw);
5979
5980 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
5981 iwl4965_commit_rxon(priv);
5982
5983 memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd));
5984 iwl4965_setup_rxon_timing(priv);
5985 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
5986 sizeof(priv->rxon_timing), &priv->rxon_timing);
5987 if (ret)
5988 IWL_WARNING("REPLY_RXON_TIMING failed - "
5989 "Attempting to continue.\n");
5990
5991 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
5992
5993#ifdef CONFIG_IWL4965_HT
5994 if (priv->current_ht_config.is_ht)
5995 iwl4965_set_rxon_ht(priv, &priv->current_ht_config);
5996#endif /* CONFIG_IWL4965_HT*/
5997 iwl4965_set_rxon_chain(priv);
5998 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
5999
6000 IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
6001 priv->assoc_id, priv->beacon_int);
6002
6003 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
6004 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
6005 else
6006 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
6007
6008 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
6009 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
6010 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
6011 else
6012 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
6013
6014 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
6015 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
6016
6017 }
6018
6019 iwl4965_commit_rxon(priv);
6020
6021 switch (priv->iw_mode) {
6022 case IEEE80211_IF_TYPE_STA:
6023 iwl4965_rate_scale_init(priv->hw, IWL_AP_ID);
6024 break;
6025
6026 case IEEE80211_IF_TYPE_IBSS:
6027
6028 /* clear out the station table */
6029 iwlcore_clear_stations_table(priv);
6030
6031 iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0);
6032 iwl4965_rxon_add_station(priv, priv->bssid, 0);
6033 iwl4965_rate_scale_init(priv->hw, IWL_STA_ID);
6034 iwl4965_send_beacon_cmd(priv);
6035
6036 break;
6037
6038 default:
6039 IWL_ERROR("%s Should not be called in %d mode\n",
6040 __FUNCTION__, priv->iw_mode);
6041 break;
6042 }
6043
6044 iwl4965_sequence_reset(priv);
6045
6046#ifdef CONFIG_IWL4965_SENSITIVITY
6047 /* Enable Rx differential gain and sensitivity calibrations */
6048 iwl4965_chain_noise_reset(priv);
6049 priv->start_calib = 1;
6050#endif /* CONFIG_IWL4965_SENSITIVITY */
6051
6052 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
6053 priv->assoc_station_added = 1;
6054
6055 iwl4965_activate_qos(priv, 0);
6056
6057 /* we have just associated, don't start scan too early */
6058 priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
6059}
6060
6061
6062static void iwl4965_bg_post_associate(struct work_struct *data)
6063{
6064 struct iwl_priv *priv = container_of(data, struct iwl_priv,
6065 post_associate.work);
6066
6067 mutex_lock(&priv->mutex);
6068 iwl4965_post_associate(priv);
6069 mutex_unlock(&priv->mutex);
6070
6071}
6072
6073static void iwl4965_bg_abort_scan(struct work_struct *work)
6074{
6075 struct iwl_priv *priv = container_of(work, struct iwl_priv, abort_scan);
6076
6077 if (!iwl_is_ready(priv))
6078 return;
6079
6080 mutex_lock(&priv->mutex);
6081
6082 set_bit(STATUS_SCAN_ABORTING, &priv->status);
6083 iwl4965_send_scan_abort(priv);
6084
6085 mutex_unlock(&priv->mutex);
6086}
6087
6088static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf);
6089
6090static void iwl4965_bg_scan_completed(struct work_struct *work)
6091{
6092 struct iwl_priv *priv =
6093 container_of(work, struct iwl_priv, scan_completed);
6094
6095 IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, "SCAN complete scan\n");
6096
6097 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6098 return;
6099
6100 if (test_bit(STATUS_CONF_PENDING, &priv->status))
6101 iwl4965_mac_config(priv->hw, ieee80211_get_hw_conf(priv->hw));
6102
6103 ieee80211_scan_completed(priv->hw);
6104
6105 /* Since setting the TXPOWER may have been deferred while
6106 * performing the scan, fire one off */
6107 mutex_lock(&priv->mutex);
6108 iwl4965_hw_reg_send_txpower(priv);
6109 mutex_unlock(&priv->mutex);
6110}
6111
6112/*****************************************************************************
6113 *
6114 * mac80211 entry point functions
6115 *
6116 *****************************************************************************/
6117
6118#define UCODE_READY_TIMEOUT (2 * HZ)
6119
6120static int iwl4965_mac_start(struct ieee80211_hw *hw)
6121{
6122 struct iwl_priv *priv = hw->priv;
6123 int ret;
6124
6125 IWL_DEBUG_MAC80211("enter\n");
6126
6127 if (pci_enable_device(priv->pci_dev)) {
6128 IWL_ERROR("Fail to pci_enable_device\n");
6129 return -ENODEV;
6130 }
6131 pci_restore_state(priv->pci_dev);
6132 pci_enable_msi(priv->pci_dev);
6133
6134 ret = request_irq(priv->pci_dev->irq, iwl4965_isr, IRQF_SHARED,
6135 DRV_NAME, priv);
6136 if (ret) {
6137 IWL_ERROR("Error allocating IRQ %d\n", priv->pci_dev->irq);
6138 goto out_disable_msi;
6139 }
6140
6141 /* we should be verifying the device is ready to be opened */
6142 mutex_lock(&priv->mutex);
6143
6144 memset(&priv->staging_rxon, 0, sizeof(struct iwl4965_rxon_cmd));
6145 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
6146 * ucode filename and max sizes are card-specific. */
6147
6148 if (!priv->ucode_code.len) {
6149 ret = iwl4965_read_ucode(priv);
6150 if (ret) {
6151 IWL_ERROR("Could not read microcode: %d\n", ret);
6152 mutex_unlock(&priv->mutex);
6153 goto out_release_irq;
6154 }
6155 }
6156
6157 ret = __iwl4965_up(priv);
6158
6159 mutex_unlock(&priv->mutex);
6160
6161 if (ret)
6162 goto out_release_irq;
6163
6164 IWL_DEBUG_INFO("Start UP work done.\n");
6165
6166 if (test_bit(STATUS_IN_SUSPEND, &priv->status))
6167 return 0;
6168
6169 /* Wait for START_ALIVE from ucode. Otherwise callbacks from
6170 * mac80211 will not be run successfully. */
6171 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
6172 test_bit(STATUS_READY, &priv->status),
6173 UCODE_READY_TIMEOUT);
6174 if (!ret) {
6175 if (!test_bit(STATUS_READY, &priv->status)) {
6176 IWL_ERROR("Wait for START_ALIVE timeout after %dms.\n",
6177 jiffies_to_msecs(UCODE_READY_TIMEOUT));
6178 ret = -ETIMEDOUT;
6179 goto out_release_irq;
6180 }
6181 }
6182
6183 priv->is_open = 1;
6184 IWL_DEBUG_MAC80211("leave\n");
6185 return 0;
6186
6187out_release_irq:
6188 free_irq(priv->pci_dev->irq, priv);
6189out_disable_msi:
6190 pci_disable_msi(priv->pci_dev);
6191 pci_disable_device(priv->pci_dev);
6192 priv->is_open = 0;
6193 IWL_DEBUG_MAC80211("leave - failed\n");
6194 return ret;
6195}
6196
6197static void iwl4965_mac_stop(struct ieee80211_hw *hw)
6198{
6199 struct iwl_priv *priv = hw->priv;
6200
6201 IWL_DEBUG_MAC80211("enter\n");
6202
6203 if (!priv->is_open) {
6204 IWL_DEBUG_MAC80211("leave - skip\n");
6205 return;
6206 }
6207
6208 priv->is_open = 0;
6209
6210 if (iwl_is_ready_rf(priv)) {
6211 /* stop mac, cancel any scan request and clear
6212 * RXON_FILTER_ASSOC_MSK BIT
6213 */
6214 mutex_lock(&priv->mutex);
6215 iwl4965_scan_cancel_timeout(priv, 100);
6216 cancel_delayed_work(&priv->post_associate);
6217 mutex_unlock(&priv->mutex);
6218 }
6219
6220 iwl4965_down(priv);
6221
6222 flush_workqueue(priv->workqueue);
6223 free_irq(priv->pci_dev->irq, priv);
6224 pci_disable_msi(priv->pci_dev);
6225 pci_save_state(priv->pci_dev);
6226 pci_disable_device(priv->pci_dev);
6227
6228 IWL_DEBUG_MAC80211("leave\n");
6229}
6230
6231static int iwl4965_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
6232 struct ieee80211_tx_control *ctl)
6233{
6234 struct iwl_priv *priv = hw->priv;
6235
6236 IWL_DEBUG_MAC80211("enter\n");
6237
6238 if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) {
6239 IWL_DEBUG_MAC80211("leave - monitor\n");
6240 dev_kfree_skb_any(skb);
6241 return 0;
6242 }
6243
6244 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
6245 ctl->tx_rate->bitrate);
6246
6247 if (iwl4965_tx_skb(priv, skb, ctl))
6248 dev_kfree_skb_any(skb);
6249
6250 IWL_DEBUG_MAC80211("leave\n");
6251 return 0;
6252}
6253
6254static int iwl4965_mac_add_interface(struct ieee80211_hw *hw,
6255 struct ieee80211_if_init_conf *conf)
6256{
6257 struct iwl_priv *priv = hw->priv;
6258 unsigned long flags;
6259 DECLARE_MAC_BUF(mac);
6260
6261 IWL_DEBUG_MAC80211("enter: type %d\n", conf->type);
6262
6263 if (priv->vif) {
6264 IWL_DEBUG_MAC80211("leave - vif != NULL\n");
6265 return -EOPNOTSUPP;
6266 }
6267
6268 spin_lock_irqsave(&priv->lock, flags);
6269 priv->vif = conf->vif;
6270
6271 spin_unlock_irqrestore(&priv->lock, flags);
6272
6273 mutex_lock(&priv->mutex);
6274
6275 if (conf->mac_addr) {
6276 IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac, conf->mac_addr));
6277 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
6278 }
6279
6280 if (iwl_is_ready(priv))
6281 iwl4965_set_mode(priv, conf->type);
6282
6283 mutex_unlock(&priv->mutex);
6284
6285 IWL_DEBUG_MAC80211("leave\n");
6286 return 0;
6287}
6288
6289/**
6290 * iwl4965_mac_config - mac80211 config callback
6291 *
6292 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
6293 * be set inappropriately and the driver currently sets the hardware up to
6294 * use it whenever needed.
6295 */
6296static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf)
6297{
6298 struct iwl_priv *priv = hw->priv;
6299 const struct iwl_channel_info *ch_info;
6300 unsigned long flags;
6301 int ret = 0;
6302
6303 mutex_lock(&priv->mutex);
6304 IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value);
6305
6306 priv->add_radiotap = !!(conf->flags & IEEE80211_CONF_RADIOTAP);
6307
6308 if (!iwl_is_ready(priv)) {
6309 IWL_DEBUG_MAC80211("leave - not ready\n");
6310 ret = -EIO;
6311 goto out;
6312 }
6313
6314 if (unlikely(!priv->cfg->mod_params->disable_hw_scan &&
6315 test_bit(STATUS_SCANNING, &priv->status))) {
6316 IWL_DEBUG_MAC80211("leave - scanning\n");
6317 set_bit(STATUS_CONF_PENDING, &priv->status);
6318 mutex_unlock(&priv->mutex);
6319 return 0;
6320 }
6321
6322 spin_lock_irqsave(&priv->lock, flags);
6323
6324 ch_info = iwl_get_channel_info(priv, conf->channel->band,
6325 ieee80211_frequency_to_channel(conf->channel->center_freq));
6326 if (!is_channel_valid(ch_info)) {
6327 IWL_DEBUG_MAC80211("leave - invalid channel\n");
6328 spin_unlock_irqrestore(&priv->lock, flags);
6329 ret = -EINVAL;
6330 goto out;
6331 }
6332
6333#ifdef CONFIG_IWL4965_HT
6334 /* if we are switching from ht to 2.4 clear flags
6335 * from any ht related info since 2.4 does not
6336 * support ht */
6337 if ((le16_to_cpu(priv->staging_rxon.channel) != conf->channel->hw_value)
6338#ifdef IEEE80211_CONF_CHANNEL_SWITCH
6339 && !(conf->flags & IEEE80211_CONF_CHANNEL_SWITCH)
6340#endif
6341 )
6342 priv->staging_rxon.flags = 0;
6343#endif /* CONFIG_IWL4965_HT */
6344
6345 iwlcore_set_rxon_channel(priv, conf->channel->band,
6346 ieee80211_frequency_to_channel(conf->channel->center_freq));
6347
6348 iwl4965_set_flags_for_phymode(priv, conf->channel->band);
6349
6350 /* The list of supported rates and rate mask can be different
6351 * for each band; since the band may have changed, reset
6352 * the rate mask to what mac80211 lists */
6353 iwl4965_set_rate(priv);
6354
6355 spin_unlock_irqrestore(&priv->lock, flags);
6356
6357#ifdef IEEE80211_CONF_CHANNEL_SWITCH
6358 if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
6359 iwl4965_hw_channel_switch(priv, conf->channel);
6360 goto out;
6361 }
6362#endif
6363
6364 if (priv->cfg->ops->lib->radio_kill_sw)
6365 priv->cfg->ops->lib->radio_kill_sw(priv, !conf->radio_enabled);
6366
6367 if (!conf->radio_enabled) {
6368 IWL_DEBUG_MAC80211("leave - radio disabled\n");
6369 goto out;
6370 }
6371
6372 if (iwl_is_rfkill(priv)) {
6373 IWL_DEBUG_MAC80211("leave - RF kill\n");
6374 ret = -EIO;
6375 goto out;
6376 }
6377
6378 iwl4965_set_rate(priv);
6379
6380 if (memcmp(&priv->active_rxon,
6381 &priv->staging_rxon, sizeof(priv->staging_rxon)))
6382 iwl4965_commit_rxon(priv);
6383 else
6384 IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
6385
6386 IWL_DEBUG_MAC80211("leave\n");
6387
6388out:
6389 clear_bit(STATUS_CONF_PENDING, &priv->status);
6390 mutex_unlock(&priv->mutex);
6391 return ret;
6392}
6393
6394static void iwl4965_config_ap(struct iwl_priv *priv)
6395{
6396 int ret = 0;
6397
6398 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6399 return;
6400
6401 /* The following should be done only at AP bring up */
6402 if ((priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) == 0) {
6403
6404 /* RXON - unassoc (to set timing command) */
6405 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
6406 iwl4965_commit_rxon(priv);
6407
6408 /* RXON Timing */
6409 memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd));
6410 iwl4965_setup_rxon_timing(priv);
6411 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
6412 sizeof(priv->rxon_timing), &priv->rxon_timing);
6413 if (ret)
6414 IWL_WARNING("REPLY_RXON_TIMING failed - "
6415 "Attempting to continue.\n");
6416
6417 iwl4965_set_rxon_chain(priv);
6418
6419 /* FIXME: what should be the assoc_id for AP? */
6420 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
6421 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
6422 priv->staging_rxon.flags |=
6423 RXON_FLG_SHORT_PREAMBLE_MSK;
6424 else
6425 priv->staging_rxon.flags &=
6426 ~RXON_FLG_SHORT_PREAMBLE_MSK;
6427
6428 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
6429 if (priv->assoc_capability &
6430 WLAN_CAPABILITY_SHORT_SLOT_TIME)
6431 priv->staging_rxon.flags |=
6432 RXON_FLG_SHORT_SLOT_MSK;
6433 else
6434 priv->staging_rxon.flags &=
6435 ~RXON_FLG_SHORT_SLOT_MSK;
6436
6437 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
6438 priv->staging_rxon.flags &=
6439 ~RXON_FLG_SHORT_SLOT_MSK;
6440 }
6441 /* restore RXON assoc */
6442 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
6443 iwl4965_commit_rxon(priv);
6444 iwl4965_activate_qos(priv, 1);
6445 iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0);
6446 }
6447 iwl4965_send_beacon_cmd(priv);
6448
6449 /* FIXME - we need to add code here to detect a totally new
6450 * configuration, reset the AP, unassoc, rxon timing, assoc,
6451 * clear sta table, add BCAST sta... */
6452}
6453
6454static int iwl4965_mac_config_interface(struct ieee80211_hw *hw,
6455 struct ieee80211_vif *vif,
6456 struct ieee80211_if_conf *conf)
6457{
6458 struct iwl_priv *priv = hw->priv;
6459 DECLARE_MAC_BUF(mac);
6460 unsigned long flags;
6461 int rc;
6462
6463 if (conf == NULL)
6464 return -EIO;
6465
6466 if (priv->vif != vif) {
6467 IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
6468 return 0;
6469 }
6470
6471 if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
6472 (!conf->beacon || !conf->ssid_len)) {
6473 IWL_DEBUG_MAC80211
6474 ("Leaving in AP mode because HostAPD is not ready.\n");
6475 return 0;
6476 }
6477
6478 if (!iwl_is_alive(priv))
6479 return -EAGAIN;
6480
6481 mutex_lock(&priv->mutex);
6482
6483 if (conf->bssid)
6484 IWL_DEBUG_MAC80211("bssid: %s\n",
6485 print_mac(mac, conf->bssid));
6486
6487/*
6488 * very dubious code was here; the probe filtering flag is never set:
6489 *
6490 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
6491 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
6492 */
6493
6494 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
6495 if (!conf->bssid) {
6496 conf->bssid = priv->mac_addr;
6497 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
6498 IWL_DEBUG_MAC80211("bssid was set to: %s\n",
6499 print_mac(mac, conf->bssid));
6500 }
6501 if (priv->ibss_beacon)
6502 dev_kfree_skb(priv->ibss_beacon);
6503
6504 priv->ibss_beacon = conf->beacon;
6505 }
6506
6507 if (iwl_is_rfkill(priv))
6508 goto done;
6509
6510 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
6511 !is_multicast_ether_addr(conf->bssid)) {
6512 /* If there is currently a HW scan going on in the background
6513 * then we need to cancel it else the RXON below will fail. */
6514 if (iwl4965_scan_cancel_timeout(priv, 100)) {
6515 IWL_WARNING("Aborted scan still in progress "
6516 "after 100ms\n");
6517 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
6518 mutex_unlock(&priv->mutex);
6519 return -EAGAIN;
6520 }
6521 memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
6522
6523 /* TODO: Audit driver for usage of these members and see
6524 * if mac80211 deprecates them (priv->bssid looks like it
6525 * shouldn't be there, but I haven't scanned the IBSS code
6526 * to verify) - jpk */
6527 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
6528
6529 if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
6530 iwl4965_config_ap(priv);
6531 else {
6532 rc = iwl4965_commit_rxon(priv);
6533 if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc)
6534 iwl4965_rxon_add_station(
6535 priv, priv->active_rxon.bssid_addr, 1);
6536 }
6537
6538 } else {
6539 iwl4965_scan_cancel_timeout(priv, 100);
6540 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
6541 iwl4965_commit_rxon(priv);
6542 }
6543
6544 done:
6545 spin_lock_irqsave(&priv->lock, flags);
6546 if (!conf->ssid_len)
6547 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
6548 else
6549 memcpy(priv->essid, conf->ssid, conf->ssid_len);
6550
6551 priv->essid_len = conf->ssid_len;
6552 spin_unlock_irqrestore(&priv->lock, flags);
6553
6554 IWL_DEBUG_MAC80211("leave\n");
6555 mutex_unlock(&priv->mutex);
6556
6557 return 0;
6558}
6559
6560static void iwl4965_configure_filter(struct ieee80211_hw *hw,
6561 unsigned int changed_flags,
6562 unsigned int *total_flags,
6563 int mc_count, struct dev_addr_list *mc_list)
6564{
6565 /*
6566 * XXX: dummy
6567 * see also iwl4965_connection_init_rx_config
6568 */
6569 *total_flags = 0;
6570}
6571
6572static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw,
6573 struct ieee80211_if_init_conf *conf)
6574{
6575 struct iwl_priv *priv = hw->priv;
6576
6577 IWL_DEBUG_MAC80211("enter\n");
6578
6579 mutex_lock(&priv->mutex);
6580
6581 if (iwl_is_ready_rf(priv)) {
6582 iwl4965_scan_cancel_timeout(priv, 100);
6583 cancel_delayed_work(&priv->post_associate);
6584 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
6585 iwl4965_commit_rxon(priv);
6586 }
6587 if (priv->vif == conf->vif) {
6588 priv->vif = NULL;
6589 memset(priv->bssid, 0, ETH_ALEN);
6590 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
6591 priv->essid_len = 0;
6592 }
6593 mutex_unlock(&priv->mutex);
6594
6595 IWL_DEBUG_MAC80211("leave\n");
6596
6597}
6598
6599
6600#ifdef CONFIG_IWL4965_HT
6601static void iwl4965_ht_conf(struct iwl_priv *priv,
6602 struct ieee80211_bss_conf *bss_conf)
6603{
6604 struct ieee80211_ht_info *ht_conf = bss_conf->ht_conf;
6605 struct ieee80211_ht_bss_info *ht_bss_conf = bss_conf->ht_bss_conf;
6606 struct iwl_ht_info *iwl_conf = &priv->current_ht_config;
6607
6608 IWL_DEBUG_MAC80211("enter: \n");
6609
6610 iwl_conf->is_ht = bss_conf->assoc_ht;
6611
6612 if (!iwl_conf->is_ht)
6613 return;
6614
6615 priv->ps_mode = (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2);
6616
6617 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20)
6618 iwl_conf->sgf |= 0x1;
6619 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40)
6620 iwl_conf->sgf |= 0x2;
6621
6622 iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD);
6623 iwl_conf->max_amsdu_size =
6624 !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU);
6625
6626 iwl_conf->supported_chan_width =
6627 !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH);
6628 iwl_conf->extension_chan_offset =
6629 ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_SEC_OFFSET;
6630 /* If no above or below channel supplied disable FAT channel */
6631 if (iwl_conf->extension_chan_offset != IWL_EXT_CHANNEL_OFFSET_ABOVE &&
6632 iwl_conf->extension_chan_offset != IWL_EXT_CHANNEL_OFFSET_BELOW)
6633 iwl_conf->supported_chan_width = 0;
6634
6635 iwl_conf->tx_mimo_ps_mode =
6636 (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2);
6637 memcpy(iwl_conf->supp_mcs_set, ht_conf->supp_mcs_set, 16);
6638
6639 iwl_conf->control_channel = ht_bss_conf->primary_channel;
6640 iwl_conf->tx_chan_width =
6641 !!(ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_WIDTH);
6642 iwl_conf->ht_protection =
6643 ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_HT_PROTECTION;
6644 iwl_conf->non_GF_STA_present =
6645 !!(ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_NON_GF_STA_PRSNT);
6646
6647 IWL_DEBUG_MAC80211("control channel %d\n", iwl_conf->control_channel);
6648 IWL_DEBUG_MAC80211("leave\n");
6649}
6650#else
6651static inline void iwl4965_ht_conf(struct iwl_priv *priv,
6652 struct ieee80211_bss_conf *bss_conf)
6653{
6654}
6655#endif
6656
6657#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
6658static void iwl4965_bss_info_changed(struct ieee80211_hw *hw,
6659 struct ieee80211_vif *vif,
6660 struct ieee80211_bss_conf *bss_conf,
6661 u32 changes)
6662{
6663 struct iwl_priv *priv = hw->priv;
6664
6665 IWL_DEBUG_MAC80211("changes = 0x%X\n", changes);
6666
6667 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
6668 IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n",
6669 bss_conf->use_short_preamble);
6670 if (bss_conf->use_short_preamble)
6671 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
6672 else
6673 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
6674 }
6675
6676 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
6677 IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf->use_cts_prot);
6678 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
6679 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
6680 else
6681 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
6682 }
6683
6684 if (changes & BSS_CHANGED_HT) {
6685 IWL_DEBUG_MAC80211("HT %d\n", bss_conf->assoc_ht);
6686 iwl4965_ht_conf(priv, bss_conf);
6687 iwl4965_set_rxon_chain(priv);
6688 }
6689
6690 if (changes & BSS_CHANGED_ASSOC) {
6691 IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf->assoc);
6692 /* This should never happen as this function should
6693 * never be called from interrupt context. */
6694 if (WARN_ON_ONCE(in_interrupt()))
6695 return;
6696 if (bss_conf->assoc) {
6697 priv->assoc_id = bss_conf->aid;
6698 priv->beacon_int = bss_conf->beacon_int;
6699 priv->timestamp = bss_conf->timestamp;
6700 priv->assoc_capability = bss_conf->assoc_capability;
6701 priv->next_scan_jiffies = jiffies +
6702 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
6703 mutex_lock(&priv->mutex);
6704 iwl4965_post_associate(priv);
6705 mutex_unlock(&priv->mutex);
6706 } else {
6707 priv->assoc_id = 0;
6708 IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf->assoc);
6709 }
6710 } else if (changes && iwl_is_associated(priv) && priv->assoc_id) {
6711 IWL_DEBUG_MAC80211("Associated Changes %d\n", changes);
6712 iwl_send_rxon_assoc(priv);
6713 }
6714
6715}
6716
6717static int iwl4965_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len)
6718{
6719 int rc = 0;
6720 unsigned long flags;
6721 struct iwl_priv *priv = hw->priv;
6722
6723 IWL_DEBUG_MAC80211("enter\n");
6724
6725 mutex_lock(&priv->mutex);
6726 spin_lock_irqsave(&priv->lock, flags);
6727
6728 if (!iwl_is_ready_rf(priv)) {
6729 rc = -EIO;
6730 IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
6731 goto out_unlock;
6732 }
6733
6734 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { /* APs don't scan */
6735 rc = -EIO;
6736 IWL_ERROR("ERROR: APs don't scan\n");
6737 goto out_unlock;
6738 }
6739
6740 /* we don't schedule scan within next_scan_jiffies period */
6741 if (priv->next_scan_jiffies &&
6742 time_after(priv->next_scan_jiffies, jiffies)) {
6743 rc = -EAGAIN;
6744 goto out_unlock;
6745 }
6746 /* if we just finished scan ask for delay */
6747 if (priv->last_scan_jiffies && time_after(priv->last_scan_jiffies +
6748 IWL_DELAY_NEXT_SCAN, jiffies)) {
6749 rc = -EAGAIN;
6750 goto out_unlock;
6751 }
6752 if (len) {
6753 IWL_DEBUG_SCAN("direct scan for %s [%d]\n ",
6754 iwl4965_escape_essid(ssid, len), (int)len);
6755
6756 priv->one_direct_scan = 1;
6757 priv->direct_ssid_len = (u8)
6758 min((u8) len, (u8) IW_ESSID_MAX_SIZE);
6759 memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len);
6760 } else
6761 priv->one_direct_scan = 0;
6762
6763 rc = iwl4965_scan_initiate(priv);
6764
6765 IWL_DEBUG_MAC80211("leave\n");
6766
6767out_unlock:
6768 spin_unlock_irqrestore(&priv->lock, flags);
6769 mutex_unlock(&priv->mutex);
6770
6771 return rc;
6772}
6773
6774static void iwl4965_mac_update_tkip_key(struct ieee80211_hw *hw,
6775 struct ieee80211_key_conf *keyconf, const u8 *addr,
6776 u32 iv32, u16 *phase1key)
6777{
6778 struct iwl_priv *priv = hw->priv;
6779 u8 sta_id = IWL_INVALID_STATION;
6780 unsigned long flags;
6781 __le16 key_flags = 0;
6782 int i;
6783 DECLARE_MAC_BUF(mac);
6784
6785 IWL_DEBUG_MAC80211("enter\n");
6786
6787 sta_id = iwl4965_hw_find_station(priv, addr);
6788 if (sta_id == IWL_INVALID_STATION) {
6789 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
6790 print_mac(mac, addr));
6791 return;
6792 }
6793
6794 iwl4965_scan_cancel_timeout(priv, 100);
6795
6796 key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK);
6797 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
6798 key_flags &= ~STA_KEY_FLG_INVALID;
6799
6800 if (sta_id == priv->hw_params.bcast_sta_id)
6801 key_flags |= STA_KEY_MULTICAST_MSK;
6802
6803 spin_lock_irqsave(&priv->sta_lock, flags);
6804
6805 priv->stations[sta_id].sta.key.key_flags = key_flags;
6806 priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32;
6807
6808 for (i = 0; i < 5; i++)
6809 priv->stations[sta_id].sta.key.tkip_rx_ttak[i] =
6810 cpu_to_le16(phase1key[i]);
6811
6812 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
6813 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
6814
6815 iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
6816
6817 spin_unlock_irqrestore(&priv->sta_lock, flags);
6818
6819 IWL_DEBUG_MAC80211("leave\n");
6820}
6821
6822static int iwl4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
6823 const u8 *local_addr, const u8 *addr,
6824 struct ieee80211_key_conf *key)
6825{
6826 struct iwl_priv *priv = hw->priv;
6827 DECLARE_MAC_BUF(mac);
6828 int ret = 0;
6829 u8 sta_id = IWL_INVALID_STATION;
6830 u8 is_default_wep_key = 0;
6831
6832 IWL_DEBUG_MAC80211("enter\n");
6833
6834 if (priv->cfg->mod_params->sw_crypto) {
6835 IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
6836 return -EOPNOTSUPP;
6837 }
6838
6839 if (is_zero_ether_addr(addr))
6840 /* only support pairwise keys */
6841 return -EOPNOTSUPP;
6842
6843 sta_id = iwl4965_hw_find_station(priv, addr);
6844 if (sta_id == IWL_INVALID_STATION) {
6845 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
6846 print_mac(mac, addr));
6847 return -EINVAL;
6848
6849 }
6850
6851 mutex_lock(&priv->mutex);
6852 iwl4965_scan_cancel_timeout(priv, 100);
6853 mutex_unlock(&priv->mutex);
6854
6855 /* If we are getting WEP group key and we didn't receive any key mapping
6856 * so far, we are in legacy wep mode (group key only), otherwise we are
6857 * in 1X mode.
6858 * In legacy wep mode, we use another host command to the uCode */
6859 if (key->alg == ALG_WEP && sta_id == priv->hw_params.bcast_sta_id &&
6860 priv->iw_mode != IEEE80211_IF_TYPE_AP) {
6861 if (cmd == SET_KEY)
6862 is_default_wep_key = !priv->key_mapping_key;
6863 else
6864 is_default_wep_key = priv->default_wep_key;
6865 }
6866
6867 switch (cmd) {
6868 case SET_KEY:
6869 if (is_default_wep_key)
6870 ret = iwl_set_default_wep_key(priv, key);
6871 else
6872 ret = iwl_set_dynamic_key(priv, key, sta_id);
6873
6874 IWL_DEBUG_MAC80211("enable hwcrypto key\n");
6875 break;
6876 case DISABLE_KEY:
6877 if (is_default_wep_key)
6878 ret = iwl_remove_default_wep_key(priv, key);
6879 else
6880 ret = iwl_remove_dynamic_key(priv, sta_id);
6881
6882 IWL_DEBUG_MAC80211("disable hwcrypto key\n");
6883 break;
6884 default:
6885 ret = -EINVAL;
6886 }
6887
6888 IWL_DEBUG_MAC80211("leave\n");
6889
6890 return ret;
6891}
6892
6893static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, int queue,
6894 const struct ieee80211_tx_queue_params *params)
6895{
6896 struct iwl_priv *priv = hw->priv;
6897 unsigned long flags;
6898 int q;
6899
6900 IWL_DEBUG_MAC80211("enter\n");
6901
6902 if (!iwl_is_ready_rf(priv)) {
6903 IWL_DEBUG_MAC80211("leave - RF not ready\n");
6904 return -EIO;
6905 }
6906
6907 if (queue >= AC_NUM) {
6908 IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue);
6909 return 0;
6910 }
6911
6912 if (!priv->qos_data.qos_enable) {
6913 priv->qos_data.qos_active = 0;
6914 IWL_DEBUG_MAC80211("leave - qos not enabled\n");
6915 return 0;
6916 }
6917 q = AC_NUM - 1 - queue;
6918
6919 spin_lock_irqsave(&priv->lock, flags);
6920
6921 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
6922 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
6923 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
6924 priv->qos_data.def_qos_parm.ac[q].edca_txop =
6925 cpu_to_le16((params->txop * 32));
6926
6927 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
6928 priv->qos_data.qos_active = 1;
6929
6930 spin_unlock_irqrestore(&priv->lock, flags);
6931
6932 mutex_lock(&priv->mutex);
6933 if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
6934 iwl4965_activate_qos(priv, 1);
6935 else if (priv->assoc_id && iwl_is_associated(priv))
6936 iwl4965_activate_qos(priv, 0);
6937
6938 mutex_unlock(&priv->mutex);
6939
6940 IWL_DEBUG_MAC80211("leave\n");
6941 return 0;
6942}
6943
6944static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw,
6945 struct ieee80211_tx_queue_stats *stats)
6946{
6947 struct iwl_priv *priv = hw->priv;
6948 int i, avail;
6949 struct iwl4965_tx_queue *txq;
6950 struct iwl4965_queue *q;
6951 unsigned long flags;
6952
6953 IWL_DEBUG_MAC80211("enter\n");
6954
6955 if (!iwl_is_ready_rf(priv)) {
6956 IWL_DEBUG_MAC80211("leave - RF not ready\n");
6957 return -EIO;
6958 }
6959
6960 spin_lock_irqsave(&priv->lock, flags);
6961
6962 for (i = 0; i < AC_NUM; i++) {
6963 txq = &priv->txq[i];
6964 q = &txq->q;
6965 avail = iwl4965_queue_space(q);
6966
6967 stats->data[i].len = q->n_window - avail;
6968 stats->data[i].limit = q->n_window - q->high_mark;
6969 stats->data[i].count = q->n_window;
6970
6971 }
6972 spin_unlock_irqrestore(&priv->lock, flags);
6973
6974 IWL_DEBUG_MAC80211("leave\n");
6975
6976 return 0;
6977}
6978
6979static int iwl4965_mac_get_stats(struct ieee80211_hw *hw,
6980 struct ieee80211_low_level_stats *stats)
6981{
6982 IWL_DEBUG_MAC80211("enter\n");
6983 IWL_DEBUG_MAC80211("leave\n");
6984
6985 return 0;
6986}
6987
6988static u64 iwl4965_mac_get_tsf(struct ieee80211_hw *hw)
6989{
6990 IWL_DEBUG_MAC80211("enter\n");
6991 IWL_DEBUG_MAC80211("leave\n");
6992
6993 return 0;
6994}
6995
6996static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw)
6997{
6998 struct iwl_priv *priv = hw->priv;
6999 unsigned long flags;
7000
7001 mutex_lock(&priv->mutex);
7002 IWL_DEBUG_MAC80211("enter\n");
7003
7004 priv->lq_mngr.lq_ready = 0;
7005#ifdef CONFIG_IWL4965_HT
7006 spin_lock_irqsave(&priv->lock, flags);
7007 memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info));
7008 spin_unlock_irqrestore(&priv->lock, flags);
7009#endif /* CONFIG_IWL4965_HT */
7010
7011 iwlcore_reset_qos(priv);
7012
7013 cancel_delayed_work(&priv->post_associate);
7014
7015 spin_lock_irqsave(&priv->lock, flags);
7016 priv->assoc_id = 0;
7017 priv->assoc_capability = 0;
7018 priv->assoc_station_added = 0;
7019
7020 /* new association get rid of ibss beacon skb */
7021 if (priv->ibss_beacon)
7022 dev_kfree_skb(priv->ibss_beacon);
7023
7024 priv->ibss_beacon = NULL;
7025
7026 priv->beacon_int = priv->hw->conf.beacon_int;
7027 priv->timestamp = 0;
7028 if ((priv->iw_mode == IEEE80211_IF_TYPE_STA))
7029 priv->beacon_int = 0;
7030
7031 spin_unlock_irqrestore(&priv->lock, flags);
7032
7033 if (!iwl_is_ready_rf(priv)) {
7034 IWL_DEBUG_MAC80211("leave - not ready\n");
7035 mutex_unlock(&priv->mutex);
7036 return;
7037 }
7038
7039 /* we are restarting association process
7040 * clear RXON_FILTER_ASSOC_MSK bit
7041 */
7042 if (priv->iw_mode != IEEE80211_IF_TYPE_AP) {
7043 iwl4965_scan_cancel_timeout(priv, 100);
7044 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
7045 iwl4965_commit_rxon(priv);
7046 }
7047
7048 /* Per mac80211.h: This is only used in IBSS mode... */
7049 if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
7050
7051 IWL_DEBUG_MAC80211("leave - not in IBSS\n");
7052 mutex_unlock(&priv->mutex);
7053 return;
7054 }
7055
7056 iwl4965_set_rate(priv);
7057
7058 mutex_unlock(&priv->mutex);
7059
7060 IWL_DEBUG_MAC80211("leave\n");
7061}
7062
7063static int iwl4965_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb,
7064 struct ieee80211_tx_control *control)
7065{
7066 struct iwl_priv *priv = hw->priv;
7067 unsigned long flags;
7068
7069 mutex_lock(&priv->mutex);
7070 IWL_DEBUG_MAC80211("enter\n");
7071
7072 if (!iwl_is_ready_rf(priv)) {
7073 IWL_DEBUG_MAC80211("leave - RF not ready\n");
7074 mutex_unlock(&priv->mutex);
7075 return -EIO;
7076 }
7077
7078 if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
7079 IWL_DEBUG_MAC80211("leave - not IBSS\n");
7080 mutex_unlock(&priv->mutex);
7081 return -EIO;
7082 }
7083
7084 spin_lock_irqsave(&priv->lock, flags);
7085
7086 if (priv->ibss_beacon)
7087 dev_kfree_skb(priv->ibss_beacon);
7088
7089 priv->ibss_beacon = skb;
7090
7091 priv->assoc_id = 0;
7092
7093 IWL_DEBUG_MAC80211("leave\n");
7094 spin_unlock_irqrestore(&priv->lock, flags);
7095
7096 iwlcore_reset_qos(priv);
7097
7098 queue_work(priv->workqueue, &priv->post_associate.work);
7099
7100 mutex_unlock(&priv->mutex);
7101
7102 return 0;
7103}
7104
7105/*****************************************************************************
7106 *
7107 * sysfs attributes
7108 *
7109 *****************************************************************************/
7110
7111#ifdef CONFIG_IWLWIFI_DEBUG
7112
7113/*
7114 * The following adds a new attribute to the sysfs representation
7115 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
7116 * used for controlling the debug level.
7117 *
7118 * See the level definitions in iwl for details.
7119 */
7120
7121static ssize_t show_debug_level(struct device_driver *d, char *buf)
7122{
7123 return sprintf(buf, "0x%08X\n", iwl_debug_level);
7124}
7125static ssize_t store_debug_level(struct device_driver *d,
7126 const char *buf, size_t count)
7127{
7128 char *p = (char *)buf;
7129 u32 val;
7130
7131 val = simple_strtoul(p, &p, 0);
7132 if (p == buf)
7133 printk(KERN_INFO DRV_NAME
7134 ": %s is not in hex or decimal form.\n", buf);
7135 else
7136 iwl_debug_level = val;
7137
7138 return strnlen(buf, count);
7139}
7140
7141static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
7142 show_debug_level, store_debug_level);
7143
7144#endif /* CONFIG_IWLWIFI_DEBUG */
7145
7146
7147static ssize_t show_temperature(struct device *d,
7148 struct device_attribute *attr, char *buf)
7149{
7150 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
7151
7152 if (!iwl_is_alive(priv))
7153 return -EAGAIN;
7154
7155 return sprintf(buf, "%d\n", iwl4965_hw_get_temperature(priv));
7156}
7157
7158static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
7159
7160static ssize_t show_rs_window(struct device *d,
7161 struct device_attribute *attr,
7162 char *buf)
7163{
7164 struct iwl_priv *priv = d->driver_data;
7165 return iwl4965_fill_rs_info(priv->hw, buf, IWL_AP_ID);
7166}
7167static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL);
7168
7169static ssize_t show_tx_power(struct device *d,
7170 struct device_attribute *attr, char *buf)
7171{
7172 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
7173 return sprintf(buf, "%d\n", priv->user_txpower_limit);
7174}
7175
7176static ssize_t store_tx_power(struct device *d,
7177 struct device_attribute *attr,
7178 const char *buf, size_t count)
7179{
7180 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
7181 char *p = (char *)buf;
7182 u32 val;
7183
7184 val = simple_strtoul(p, &p, 10);
7185 if (p == buf)
7186 printk(KERN_INFO DRV_NAME
7187 ": %s is not in decimal form.\n", buf);
7188 else
7189 iwl4965_hw_reg_set_txpower(priv, val);
7190
7191 return count;
7192}
7193
7194static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
7195
7196static ssize_t show_flags(struct device *d,
7197 struct device_attribute *attr, char *buf)
7198{
7199 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
7200
7201 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
7202}
7203
7204static ssize_t store_flags(struct device *d,
7205 struct device_attribute *attr,
7206 const char *buf, size_t count)
7207{
7208 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
7209 u32 flags = simple_strtoul(buf, NULL, 0);
7210
7211 mutex_lock(&priv->mutex);
7212 if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
7213 /* Cancel any currently running scans... */
7214 if (iwl4965_scan_cancel_timeout(priv, 100))
7215 IWL_WARNING("Could not cancel scan.\n");
7216 else {
7217 IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n",
7218 flags);
7219 priv->staging_rxon.flags = cpu_to_le32(flags);
7220 iwl4965_commit_rxon(priv);
7221 }
7222 }
7223 mutex_unlock(&priv->mutex);
7224
7225 return count;
7226}
7227
7228static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
7229
7230static ssize_t show_filter_flags(struct device *d,
7231 struct device_attribute *attr, char *buf)
7232{
7233 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
7234
7235 return sprintf(buf, "0x%04X\n",
7236 le32_to_cpu(priv->active_rxon.filter_flags));
7237}
7238
7239static ssize_t store_filter_flags(struct device *d,
7240 struct device_attribute *attr,
7241 const char *buf, size_t count)
7242{
7243 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
7244 u32 filter_flags = simple_strtoul(buf, NULL, 0);
7245
7246 mutex_lock(&priv->mutex);
7247 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
7248 /* Cancel any currently running scans... */
7249 if (iwl4965_scan_cancel_timeout(priv, 100))
7250 IWL_WARNING("Could not cancel scan.\n");
7251 else {
7252 IWL_DEBUG_INFO("Committing rxon.filter_flags = "
7253 "0x%04X\n", filter_flags);
7254 priv->staging_rxon.filter_flags =
7255 cpu_to_le32(filter_flags);
7256 iwl4965_commit_rxon(priv);
7257 }
7258 }
7259 mutex_unlock(&priv->mutex);
7260
7261 return count;
7262}
7263
7264static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
7265 store_filter_flags);
7266
7267#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
7268
7269static ssize_t show_measurement(struct device *d,
7270 struct device_attribute *attr, char *buf)
7271{
7272 struct iwl_priv *priv = dev_get_drvdata(d);
7273 struct iwl4965_spectrum_notification measure_report;
7274 u32 size = sizeof(measure_report), len = 0, ofs = 0;
7275 u8 *data = (u8 *) & measure_report;
7276 unsigned long flags;
7277
7278 spin_lock_irqsave(&priv->lock, flags);
7279 if (!(priv->measurement_status & MEASUREMENT_READY)) {
7280 spin_unlock_irqrestore(&priv->lock, flags);
7281 return 0;
7282 }
7283 memcpy(&measure_report, &priv->measure_report, size);
7284 priv->measurement_status = 0;
7285 spin_unlock_irqrestore(&priv->lock, flags);
7286
7287 while (size && (PAGE_SIZE - len)) {
7288 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
7289 PAGE_SIZE - len, 1);
7290 len = strlen(buf);
7291 if (PAGE_SIZE - len)
7292 buf[len++] = '\n';
7293
7294 ofs += 16;
7295 size -= min(size, 16U);
7296 }
7297
7298 return len;
7299}
7300
7301static ssize_t store_measurement(struct device *d,
7302 struct device_attribute *attr,
7303 const char *buf, size_t count)
7304{
7305 struct iwl_priv *priv = dev_get_drvdata(d);
7306 struct ieee80211_measurement_params params = {
7307 .channel = le16_to_cpu(priv->active_rxon.channel),
7308 .start_time = cpu_to_le64(priv->last_tsf),
7309 .duration = cpu_to_le16(1),
7310 };
7311 u8 type = IWL_MEASURE_BASIC;
7312 u8 buffer[32];
7313 u8 channel;
7314
7315 if (count) {
7316 char *p = buffer;
7317 strncpy(buffer, buf, min(sizeof(buffer), count));
7318 channel = simple_strtoul(p, NULL, 0);
7319 if (channel)
7320 params.channel = channel;
7321
7322 p = buffer;
7323 while (*p && *p != ' ')
7324 p++;
7325 if (*p)
7326 type = simple_strtoul(p + 1, NULL, 0);
7327 }
7328
7329 IWL_DEBUG_INFO("Invoking measurement of type %d on "
7330 "channel %d (for '%s')\n", type, params.channel, buf);
7331 iwl4965_get_measurement(priv, &params, type);
7332
7333 return count;
7334}
7335
7336static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
7337 show_measurement, store_measurement);
7338#endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */
7339
7340static ssize_t store_retry_rate(struct device *d,
7341 struct device_attribute *attr,
7342 const char *buf, size_t count)
7343{
7344 struct iwl_priv *priv = dev_get_drvdata(d);
7345
7346 priv->retry_rate = simple_strtoul(buf, NULL, 0);
7347 if (priv->retry_rate <= 0)
7348 priv->retry_rate = 1;
7349
7350 return count;
7351}
7352
7353static ssize_t show_retry_rate(struct device *d,
7354 struct device_attribute *attr, char *buf)
7355{
7356 struct iwl_priv *priv = dev_get_drvdata(d);
7357 return sprintf(buf, "%d", priv->retry_rate);
7358}
7359
7360static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
7361 store_retry_rate);
7362
7363static ssize_t store_power_level(struct device *d,
7364 struct device_attribute *attr,
7365 const char *buf, size_t count)
7366{
7367 struct iwl_priv *priv = dev_get_drvdata(d);
7368 int rc;
7369 int mode;
7370
7371 mode = simple_strtoul(buf, NULL, 0);
7372 mutex_lock(&priv->mutex);
7373
7374 if (!iwl_is_ready(priv)) {
7375 rc = -EAGAIN;
7376 goto out;
7377 }
7378
7379 if ((mode < 1) || (mode > IWL_POWER_LIMIT) || (mode == IWL_POWER_AC))
7380 mode = IWL_POWER_AC;
7381 else
7382 mode |= IWL_POWER_ENABLED;
7383
7384 if (mode != priv->power_mode) {
7385 rc = iwl4965_send_power_mode(priv, IWL_POWER_LEVEL(mode));
7386 if (rc) {
7387 IWL_DEBUG_MAC80211("failed setting power mode.\n");
7388 goto out;
7389 }
7390 priv->power_mode = mode;
7391 }
7392
7393 rc = count;
7394
7395 out:
7396 mutex_unlock(&priv->mutex);
7397 return rc;
7398}
7399
7400#define MAX_WX_STRING 80
7401
7402/* Values are in microsecond */
7403static const s32 timeout_duration[] = {
7404 350000,
7405 250000,
7406 75000,
7407 37000,
7408 25000,
7409};
7410static const s32 period_duration[] = {
7411 400000,
7412 700000,
7413 1000000,
7414 1000000,
7415 1000000
7416};
7417
7418static ssize_t show_power_level(struct device *d,
7419 struct device_attribute *attr, char *buf)
7420{
7421 struct iwl_priv *priv = dev_get_drvdata(d);
7422 int level = IWL_POWER_LEVEL(priv->power_mode);
7423 char *p = buf;
7424
7425 p += sprintf(p, "%d ", level);
7426 switch (level) {
7427 case IWL_POWER_MODE_CAM:
7428 case IWL_POWER_AC:
7429 p += sprintf(p, "(AC)");
7430 break;
7431 case IWL_POWER_BATTERY:
7432 p += sprintf(p, "(BATTERY)");
7433 break;
7434 default:
7435 p += sprintf(p,
7436 "(Timeout %dms, Period %dms)",
7437 timeout_duration[level - 1] / 1000,
7438 period_duration[level - 1] / 1000);
7439 }
7440
7441 if (!(priv->power_mode & IWL_POWER_ENABLED))
7442 p += sprintf(p, " OFF\n");
7443 else
7444 p += sprintf(p, " \n");
7445
7446 return (p - buf + 1);
7447
7448}
7449
7450static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level,
7451 store_power_level);
7452
7453static ssize_t show_channels(struct device *d,
7454 struct device_attribute *attr, char *buf)
7455{
7456 /* all this shit doesn't belong into sysfs anyway */
7457 return 0;
7458}
7459
7460static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
7461
7462static ssize_t show_statistics(struct device *d,
7463 struct device_attribute *attr, char *buf)
7464{
7465 struct iwl_priv *priv = dev_get_drvdata(d);
7466 u32 size = sizeof(struct iwl4965_notif_statistics);
7467 u32 len = 0, ofs = 0;
7468 u8 *data = (u8 *) & priv->statistics;
7469 int rc = 0;
7470
7471 if (!iwl_is_alive(priv))
7472 return -EAGAIN;
7473
7474 mutex_lock(&priv->mutex);
7475 rc = iwl_send_statistics_request(priv, 0);
7476 mutex_unlock(&priv->mutex);
7477
7478 if (rc) {
7479 len = sprintf(buf,
7480 "Error sending statistics request: 0x%08X\n", rc);
7481 return len;
7482 }
7483
7484 while (size && (PAGE_SIZE - len)) {
7485 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
7486 PAGE_SIZE - len, 1);
7487 len = strlen(buf);
7488 if (PAGE_SIZE - len)
7489 buf[len++] = '\n';
7490
7491 ofs += 16;
7492 size -= min(size, 16U);
7493 }
7494
7495 return len;
7496}
7497
7498static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
7499
7500static ssize_t show_antenna(struct device *d,
7501 struct device_attribute *attr, char *buf)
7502{
7503 struct iwl_priv *priv = dev_get_drvdata(d);
7504
7505 if (!iwl_is_alive(priv))
7506 return -EAGAIN;
7507
7508 return sprintf(buf, "%d\n", priv->antenna);
7509}
7510
7511static ssize_t store_antenna(struct device *d,
7512 struct device_attribute *attr,
7513 const char *buf, size_t count)
7514{
7515 int ant;
7516 struct iwl_priv *priv = dev_get_drvdata(d);
7517
7518 if (count == 0)
7519 return 0;
7520
7521 if (sscanf(buf, "%1i", &ant) != 1) {
7522 IWL_DEBUG_INFO("not in hex or decimal form.\n");
7523 return count;
7524 }
7525
7526 if ((ant >= 0) && (ant <= 2)) {
7527 IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant);
7528 priv->antenna = (enum iwl4965_antenna)ant;
7529 } else
7530 IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant);
7531
7532
7533 return count;
7534}
7535
7536static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
7537
7538static ssize_t show_status(struct device *d,
7539 struct device_attribute *attr, char *buf)
7540{
7541 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
7542 if (!iwl_is_alive(priv))
7543 return -EAGAIN;
7544 return sprintf(buf, "0x%08x\n", (int)priv->status);
7545}
7546
7547static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
7548
7549static ssize_t dump_error_log(struct device *d,
7550 struct device_attribute *attr,
7551 const char *buf, size_t count)
7552{
7553 char *p = (char *)buf;
7554
7555 if (p[0] == '1')
7556 iwl4965_dump_nic_error_log((struct iwl_priv *)d->driver_data);
7557
7558 return strnlen(buf, count);
7559}
7560
7561static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
7562
7563static ssize_t dump_event_log(struct device *d,
7564 struct device_attribute *attr,
7565 const char *buf, size_t count)
7566{
7567 char *p = (char *)buf;
7568
7569 if (p[0] == '1')
7570 iwl4965_dump_nic_event_log((struct iwl_priv *)d->driver_data);
7571
7572 return strnlen(buf, count);
7573}
7574
7575static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
7576
7577/*****************************************************************************
7578 *
7579 * driver setup and teardown
7580 *
7581 *****************************************************************************/
7582
7583static void iwl4965_setup_deferred_work(struct iwl_priv *priv)
7584{
7585 priv->workqueue = create_workqueue(DRV_NAME);
7586
7587 init_waitqueue_head(&priv->wait_command_queue);
7588
7589 INIT_WORK(&priv->up, iwl4965_bg_up);
7590 INIT_WORK(&priv->restart, iwl4965_bg_restart);
7591 INIT_WORK(&priv->rx_replenish, iwl4965_bg_rx_replenish);
7592 INIT_WORK(&priv->scan_completed, iwl4965_bg_scan_completed);
7593 INIT_WORK(&priv->request_scan, iwl4965_bg_request_scan);
7594 INIT_WORK(&priv->abort_scan, iwl4965_bg_abort_scan);
7595 INIT_WORK(&priv->rf_kill, iwl4965_bg_rf_kill);
7596 INIT_WORK(&priv->beacon_update, iwl4965_bg_beacon_update);
7597 INIT_DELAYED_WORK(&priv->post_associate, iwl4965_bg_post_associate);
7598 INIT_DELAYED_WORK(&priv->init_alive_start, iwl4965_bg_init_alive_start);
7599 INIT_DELAYED_WORK(&priv->alive_start, iwl4965_bg_alive_start);
7600 INIT_DELAYED_WORK(&priv->scan_check, iwl4965_bg_scan_check);
7601
7602 iwl4965_hw_setup_deferred_work(priv);
7603
7604 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
7605 iwl4965_irq_tasklet, (unsigned long)priv);
7606}
7607
7608static void iwl4965_cancel_deferred_work(struct iwl_priv *priv)
7609{
7610 iwl4965_hw_cancel_deferred_work(priv);
7611
7612 cancel_delayed_work_sync(&priv->init_alive_start);
7613 cancel_delayed_work(&priv->scan_check);
7614 cancel_delayed_work(&priv->alive_start);
7615 cancel_delayed_work(&priv->post_associate);
7616 cancel_work_sync(&priv->beacon_update);
7617}
7618
7619static struct attribute *iwl4965_sysfs_entries[] = {
7620 &dev_attr_antenna.attr,
7621 &dev_attr_channels.attr,
7622 &dev_attr_dump_errors.attr,
7623 &dev_attr_dump_events.attr,
7624 &dev_attr_flags.attr,
7625 &dev_attr_filter_flags.attr,
7626#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
7627 &dev_attr_measurement.attr,
7628#endif
7629 &dev_attr_power_level.attr,
7630 &dev_attr_retry_rate.attr,
7631 &dev_attr_rs_window.attr,
7632 &dev_attr_statistics.attr,
7633 &dev_attr_status.attr,
7634 &dev_attr_temperature.attr,
7635 &dev_attr_tx_power.attr,
7636
7637 NULL
7638};
7639
7640static struct attribute_group iwl4965_attribute_group = {
7641 .name = NULL, /* put in device directory */
7642 .attrs = iwl4965_sysfs_entries,
7643};
7644
7645static struct ieee80211_ops iwl4965_hw_ops = {
7646 .tx = iwl4965_mac_tx,
7647 .start = iwl4965_mac_start,
7648 .stop = iwl4965_mac_stop,
7649 .add_interface = iwl4965_mac_add_interface,
7650 .remove_interface = iwl4965_mac_remove_interface,
7651 .config = iwl4965_mac_config,
7652 .config_interface = iwl4965_mac_config_interface,
7653 .configure_filter = iwl4965_configure_filter,
7654 .set_key = iwl4965_mac_set_key,
7655 .update_tkip_key = iwl4965_mac_update_tkip_key,
7656 .get_stats = iwl4965_mac_get_stats,
7657 .get_tx_stats = iwl4965_mac_get_tx_stats,
7658 .conf_tx = iwl4965_mac_conf_tx,
7659 .get_tsf = iwl4965_mac_get_tsf,
7660 .reset_tsf = iwl4965_mac_reset_tsf,
7661 .beacon_update = iwl4965_mac_beacon_update,
7662 .bss_info_changed = iwl4965_bss_info_changed,
7663#ifdef CONFIG_IWL4965_HT
7664 .ampdu_action = iwl4965_mac_ampdu_action,
7665#endif /* CONFIG_IWL4965_HT */
7666 .hw_scan = iwl4965_mac_hw_scan
7667};
7668
7669static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
7670{
7671 int err = 0;
7672 struct iwl_priv *priv;
7673 struct ieee80211_hw *hw;
7674 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
7675 unsigned long flags;
7676 DECLARE_MAC_BUF(mac);
7677
7678 /************************
7679 * 1. Allocating HW data
7680 ************************/
7681
7682 /* Disabling hardware scan means that mac80211 will perform scans
7683 * "the hard way", rather than using device's scan. */
7684 if (cfg->mod_params->disable_hw_scan) {
7685 IWL_DEBUG_INFO("Disabling hw_scan\n");
7686 iwl4965_hw_ops.hw_scan = NULL;
7687 }
7688
7689 hw = iwl_alloc_all(cfg, &iwl4965_hw_ops);
7690 if (!hw) {
7691 err = -ENOMEM;
7692 goto out;
7693 }
7694 priv = hw->priv;
7695 /* At this point both hw and priv are allocated. */
7696
7697 SET_IEEE80211_DEV(hw, &pdev->dev);
7698
7699 IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
7700 priv->cfg = cfg;
7701 priv->pci_dev = pdev;
7702
7703#ifdef CONFIG_IWLWIFI_DEBUG
7704 iwl_debug_level = priv->cfg->mod_params->debug;
7705 atomic_set(&priv->restrict_refcnt, 0);
7706#endif
7707
7708 /**************************
7709 * 2. Initializing PCI bus
7710 **************************/
7711 if (pci_enable_device(pdev)) {
7712 err = -ENODEV;
7713 goto out_ieee80211_free_hw;
7714 }
7715
7716 pci_set_master(pdev);
7717
7718 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
7719 if (!err)
7720 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
7721 if (err) {
7722 printk(KERN_WARNING DRV_NAME
7723 ": No suitable DMA available.\n");
7724 goto out_pci_disable_device;
7725 }
7726
7727 err = pci_request_regions(pdev, DRV_NAME);
7728 if (err)
7729 goto out_pci_disable_device;
7730
7731 pci_set_drvdata(pdev, priv);
7732
7733 /* We disable the RETRY_TIMEOUT register (0x41) to keep
7734 * PCI Tx retries from interfering with C3 CPU state */
7735 pci_write_config_byte(pdev, 0x41, 0x00);
7736
7737 /***********************
7738 * 3. Read REV register
7739 ***********************/
7740 priv->hw_base = pci_iomap(pdev, 0, 0);
7741 if (!priv->hw_base) {
7742 err = -ENODEV;
7743 goto out_pci_release_regions;
7744 }
7745
7746 IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
7747 (unsigned long long) pci_resource_len(pdev, 0));
7748 IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base);
7749
7750 printk(KERN_INFO DRV_NAME
7751 ": Detected Intel Wireless WiFi Link %s\n", priv->cfg->name);
7752
7753 /*****************
7754 * 4. Read EEPROM
7755 *****************/
7756 /* nic init */
7757 iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
7758 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
7759
7760 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
7761 err = iwl_poll_bit(priv, CSR_GP_CNTRL,
7762 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
7763 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
7764 if (err < 0) {
7765 IWL_DEBUG_INFO("Failed to init the card\n");
7766 goto out_iounmap;
7767 }
7768 /* Read the EEPROM */
7769 err = iwl_eeprom_init(priv);
7770 if (err) {
7771 IWL_ERROR("Unable to init EEPROM\n");
7772 goto out_iounmap;
7773 }
7774 /* MAC Address location in EEPROM same for 3945/4965 */
7775 iwl_eeprom_get_mac(priv, priv->mac_addr);
7776 IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac, priv->mac_addr));
7777 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
7778
7779 /************************
7780 * 5. Setup HW constants
7781 ************************/
7782 /* Device-specific setup */
7783 if (priv->cfg->ops->lib->set_hw_params(priv)) {
7784 IWL_ERROR("failed to set hw parameters\n");
7785 goto out_iounmap;
7786 }
7787
7788 /*******************
7789 * 6. Setup hw/priv
7790 *******************/
7791
7792 err = iwl_setup(priv);
7793 if (err)
7794 goto out_unset_hw_params;
7795 /* At this point both hw and priv are initialized. */
7796
7797 /**********************************
7798 * 7. Initialize module parameters
7799 **********************************/
7800
7801 /* Disable radio (SW RF KILL) via parameter when loading driver */
7802 if (priv->cfg->mod_params->disable) {
7803 set_bit(STATUS_RF_KILL_SW, &priv->status);
7804 IWL_DEBUG_INFO("Radio disabled.\n");
7805 }
7806
7807 if (priv->cfg->mod_params->enable_qos)
7808 priv->qos_data.qos_enable = 1;
7809
7810 /********************
7811 * 8. Setup services
7812 ********************/
7813 spin_lock_irqsave(&priv->lock, flags);
7814 iwl4965_disable_interrupts(priv);
7815 spin_unlock_irqrestore(&priv->lock, flags);
7816
7817 err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group);
7818 if (err) {
7819 IWL_ERROR("failed to create sysfs device attributes\n");
7820 goto out_unset_hw_params;
7821 }
7822
7823 err = iwl_dbgfs_register(priv, DRV_NAME);
7824 if (err) {
7825 IWL_ERROR("failed to create debugfs files\n");
7826 goto out_remove_sysfs;
7827 }
7828
7829 iwl4965_setup_deferred_work(priv);
7830 iwl4965_setup_rx_handlers(priv);
7831
7832 /********************
7833 * 9. Conclude
7834 ********************/
7835 pci_save_state(pdev);
7836 pci_disable_device(pdev);
7837
7838 /* notify iwlcore to init */
7839 iwlcore_low_level_notify(priv, IWLCORE_INIT_EVT);
7840 return 0;
7841
7842 out_remove_sysfs:
7843 sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
7844 out_unset_hw_params:
7845 iwl4965_unset_hw_params(priv);
7846 out_iounmap:
7847 pci_iounmap(pdev, priv->hw_base);
7848 out_pci_release_regions:
7849 pci_release_regions(pdev);
7850 pci_set_drvdata(pdev, NULL);
7851 out_pci_disable_device:
7852 pci_disable_device(pdev);
7853 out_ieee80211_free_hw:
7854 ieee80211_free_hw(priv->hw);
7855 out:
7856 return err;
7857}
7858
7859static void __devexit iwl4965_pci_remove(struct pci_dev *pdev)
7860{
7861 struct iwl_priv *priv = pci_get_drvdata(pdev);
7862 struct list_head *p, *q;
7863 int i;
7864 unsigned long flags;
7865
7866 if (!priv)
7867 return;
7868
7869 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
7870
7871 if (priv->mac80211_registered) {
7872 ieee80211_unregister_hw(priv->hw);
7873 priv->mac80211_registered = 0;
7874 }
7875
7876 set_bit(STATUS_EXIT_PENDING, &priv->status);
7877
7878 iwl4965_down(priv);
7879
7880 /* make sure we flush any pending irq or
7881 * tasklet for the driver
7882 */
7883 spin_lock_irqsave(&priv->lock, flags);
7884 iwl4965_disable_interrupts(priv);
7885 spin_unlock_irqrestore(&priv->lock, flags);
7886
7887 iwl_synchronize_irq(priv);
7888
7889 /* Free MAC hash list for ADHOC */
7890 for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) {
7891 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
7892 list_del(p);
7893 kfree(list_entry(p, struct iwl4965_ibss_seq, list));
7894 }
7895 }
7896
7897 iwlcore_low_level_notify(priv, IWLCORE_REMOVE_EVT);
7898 iwl_dbgfs_unregister(priv);
7899 sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
7900
7901 iwl4965_dealloc_ucode_pci(priv);
7902
7903 if (priv->rxq.bd)
7904 iwl4965_rx_queue_free(priv, &priv->rxq);
7905 iwl4965_hw_txq_ctx_free(priv);
7906
7907 iwl4965_unset_hw_params(priv);
7908 iwlcore_clear_stations_table(priv);
7909
7910
7911 /*netif_stop_queue(dev); */
7912 flush_workqueue(priv->workqueue);
7913
7914 /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes
7915 * priv->workqueue... so we can't take down the workqueue
7916 * until now... */
7917 destroy_workqueue(priv->workqueue);
7918 priv->workqueue = NULL;
7919
7920 pci_iounmap(pdev, priv->hw_base);
7921 pci_release_regions(pdev);
7922 pci_disable_device(pdev);
7923 pci_set_drvdata(pdev, NULL);
7924
7925 iwl_free_channel_map(priv);
7926 iwl4965_free_geos(priv);
7927
7928 if (priv->ibss_beacon)
7929 dev_kfree_skb(priv->ibss_beacon);
7930
7931 ieee80211_free_hw(priv->hw);
7932}
7933
7934#ifdef CONFIG_PM
7935
7936static int iwl4965_pci_suspend(struct pci_dev *pdev, pm_message_t state)
7937{
7938 struct iwl_priv *priv = pci_get_drvdata(pdev);
7939
7940 if (priv->is_open) {
7941 set_bit(STATUS_IN_SUSPEND, &priv->status);
7942 iwl4965_mac_stop(priv->hw);
7943 priv->is_open = 1;
7944 }
7945
7946 pci_set_power_state(pdev, PCI_D3hot);
7947
7948 return 0;
7949}
7950
7951static int iwl4965_pci_resume(struct pci_dev *pdev)
7952{
7953 struct iwl_priv *priv = pci_get_drvdata(pdev);
7954
7955 pci_set_power_state(pdev, PCI_D0);
7956
7957 if (priv->is_open)
7958 iwl4965_mac_start(priv->hw);
7959
7960 clear_bit(STATUS_IN_SUSPEND, &priv->status);
7961 return 0;
7962}
7963
7964#endif /* CONFIG_PM */
7965
7966/*****************************************************************************
7967 *
7968 * driver and module entry point
7969 *
7970 *****************************************************************************/
7971
7972/* Hardware specific file defines the PCI IDs table for that hardware module */
7973static struct pci_device_id iwl_hw_card_ids[] = {
7974 {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID, iwl4965_agn_cfg)},
7975 {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID, iwl4965_agn_cfg)},
7976 {0}
7977};
7978MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids);
7979
7980static struct pci_driver iwl_driver = {
7981 .name = DRV_NAME,
7982 .id_table = iwl_hw_card_ids,
7983 .probe = iwl4965_pci_probe,
7984 .remove = __devexit_p(iwl4965_pci_remove),
7985#ifdef CONFIG_PM
7986 .suspend = iwl4965_pci_suspend,
7987 .resume = iwl4965_pci_resume,
7988#endif
7989};
7990
7991static int __init iwl4965_init(void)
7992{
7993
7994 int ret;
7995 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
7996 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
7997
7998 ret = iwl4965_rate_control_register();
7999 if (ret) {
8000 IWL_ERROR("Unable to register rate control algorithm: %d\n", ret);
8001 return ret;
8002 }
8003
8004 ret = pci_register_driver(&iwl_driver);
8005 if (ret) {
8006 IWL_ERROR("Unable to initialize PCI module\n");
8007 goto error_register;
8008 }
8009#ifdef CONFIG_IWLWIFI_DEBUG
8010 ret = driver_create_file(&iwl_driver.driver, &driver_attr_debug_level);
8011 if (ret) {
8012 IWL_ERROR("Unable to create driver sysfs file\n");
8013 goto error_debug;
8014 }
8015#endif
8016
8017 return ret;
8018
8019#ifdef CONFIG_IWLWIFI_DEBUG
8020error_debug:
8021 pci_unregister_driver(&iwl_driver);
8022#endif
8023error_register:
8024 iwl4965_rate_control_unregister();
8025 return ret;
8026}
8027
8028static void __exit iwl4965_exit(void)
8029{
8030#ifdef CONFIG_IWLWIFI_DEBUG
8031 driver_remove_file(&iwl_driver.driver, &driver_attr_debug_level);
8032#endif
8033 pci_unregister_driver(&iwl_driver);
8034 iwl4965_rate_control_unregister();
8035}
8036
8037module_exit(iwl4965_exit);
8038module_init(iwl4965_init);