diff options
author | John W. Linville <linville@tuxdriver.com> | 2008-11-11 16:22:09 -0500 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2008-11-21 11:08:17 -0500 |
commit | 0795cd29b6fe05107b40080cb1fccadb96320c96 (patch) | |
tree | 36618d9489bb4e9dc8abd2505e48528c92facb65 /drivers/net/wireless/ipw2x00 | |
parent | 2ba4b32ecf748d5f45f298fc9677fa46d1dd9aff (diff) |
ipw2x00: relocate ipw2100/ipw2200 to common directory
Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net/wireless/ipw2x00')
-rw-r--r-- | drivers/net/wireless/ipw2x00/Kconfig | 150 | ||||
-rw-r--r-- | drivers/net/wireless/ipw2x00/Makefile | 6 | ||||
-rw-r--r-- | drivers/net/wireless/ipw2x00/ipw2100.c | 8649 | ||||
-rw-r--r-- | drivers/net/wireless/ipw2x00/ipw2100.h | 1162 | ||||
-rw-r--r-- | drivers/net/wireless/ipw2x00/ipw2200.c | 11984 | ||||
-rw-r--r-- | drivers/net/wireless/ipw2x00/ipw2200.h | 2011 |
6 files changed, 23962 insertions, 0 deletions
diff --git a/drivers/net/wireless/ipw2x00/Kconfig b/drivers/net/wireless/ipw2x00/Kconfig new file mode 100644 index 000000000000..67c57bfa5c1a --- /dev/null +++ b/drivers/net/wireless/ipw2x00/Kconfig | |||
@@ -0,0 +1,150 @@ | |||
1 | # | ||
2 | # Intel Centrino wireless drivers | ||
3 | # | ||
4 | |||
5 | config IPW2100 | ||
6 | tristate "Intel PRO/Wireless 2100 Network Connection" | ||
7 | depends on PCI && WLAN_80211 | ||
8 | select WIRELESS_EXT | ||
9 | select FW_LOADER | ||
10 | select LIB80211 | ||
11 | select IEEE80211 | ||
12 | ---help--- | ||
13 | A driver for the Intel PRO/Wireless 2100 Network | ||
14 | Connection 802.11b wireless network adapter. | ||
15 | |||
16 | See <file:Documentation/networking/README.ipw2100> for information on | ||
17 | the capabilities currently enabled in this driver and for tips | ||
18 | for debugging issues and problems. | ||
19 | |||
20 | In order to use this driver, you will need a firmware image for it. | ||
21 | You can obtain the firmware from | ||
22 | <http://ipw2100.sf.net/>. Once you have the firmware image, you | ||
23 | will need to place it in /lib/firmware. | ||
24 | |||
25 | You will also very likely need the Wireless Tools in order to | ||
26 | configure your card: | ||
27 | |||
28 | <http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/Tools.html>. | ||
29 | |||
30 | It is recommended that you compile this driver as a module (M) | ||
31 | rather than built-in (Y). This driver requires firmware at device | ||
32 | initialization time, and when built-in this typically happens | ||
33 | before the filesystem is accessible (hence firmware will be | ||
34 | unavailable and initialization will fail). If you do choose to build | ||
35 | this driver into your kernel image, you can avoid this problem by | ||
36 | including the firmware and a firmware loader in an initramfs. | ||
37 | |||
38 | config IPW2100_MONITOR | ||
39 | bool "Enable promiscuous mode" | ||
40 | depends on IPW2100 | ||
41 | ---help--- | ||
42 | Enables promiscuous/monitor mode support for the ipw2100 driver. | ||
43 | With this feature compiled into the driver, you can switch to | ||
44 | promiscuous mode via the Wireless Tool's Monitor mode. While in this | ||
45 | mode, no packets can be sent. | ||
46 | |||
47 | config IPW2100_DEBUG | ||
48 | bool "Enable full debugging output in IPW2100 module." | ||
49 | depends on IPW2100 | ||
50 | ---help--- | ||
51 | This option will enable debug tracing output for the IPW2100. | ||
52 | |||
53 | This will result in the kernel module being ~60k larger. You can | ||
54 | control which debug output is sent to the kernel log by setting the | ||
55 | value in | ||
56 | |||
57 | /sys/bus/pci/drivers/ipw2100/debug_level | ||
58 | |||
59 | This entry will only exist if this option is enabled. | ||
60 | |||
61 | If you are not trying to debug or develop the IPW2100 driver, you | ||
62 | most likely want to say N here. | ||
63 | |||
64 | config IPW2200 | ||
65 | tristate "Intel PRO/Wireless 2200BG and 2915ABG Network Connection" | ||
66 | depends on PCI && WLAN_80211 | ||
67 | select WIRELESS_EXT | ||
68 | select FW_LOADER | ||
69 | select LIB80211 | ||
70 | select IEEE80211 | ||
71 | ---help--- | ||
72 | A driver for the Intel PRO/Wireless 2200BG and 2915ABG Network | ||
73 | Connection adapters. | ||
74 | |||
75 | See <file:Documentation/networking/README.ipw2200> for | ||
76 | information on the capabilities currently enabled in this | ||
77 | driver and for tips for debugging issues and problems. | ||
78 | |||
79 | In order to use this driver, you will need a firmware image for it. | ||
80 | You can obtain the firmware from | ||
81 | <http://ipw2200.sf.net/>. See the above referenced README.ipw2200 | ||
82 | for information on where to install the firmware images. | ||
83 | |||
84 | You will also very likely need the Wireless Tools in order to | ||
85 | configure your card: | ||
86 | |||
87 | <http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/Tools.html>. | ||
88 | |||
89 | It is recommended that you compile this driver as a module (M) | ||
90 | rather than built-in (Y). This driver requires firmware at device | ||
91 | initialization time, and when built-in this typically happens | ||
92 | before the filesystem is accessible (hence firmware will be | ||
93 | unavailable and initialization will fail). If you do choose to build | ||
94 | this driver into your kernel image, you can avoid this problem by | ||
95 | including the firmware and a firmware loader in an initramfs. | ||
96 | |||
97 | config IPW2200_MONITOR | ||
98 | bool "Enable promiscuous mode" | ||
99 | depends on IPW2200 | ||
100 | ---help--- | ||
101 | Enables promiscuous/monitor mode support for the ipw2200 driver. | ||
102 | With this feature compiled into the driver, you can switch to | ||
103 | promiscuous mode via the Wireless Tool's Monitor mode. While in this | ||
104 | mode, no packets can be sent. | ||
105 | |||
106 | config IPW2200_RADIOTAP | ||
107 | bool "Enable radiotap format 802.11 raw packet support" | ||
108 | depends on IPW2200_MONITOR | ||
109 | |||
110 | config IPW2200_PROMISCUOUS | ||
111 | bool "Enable creation of a RF radiotap promiscuous interface" | ||
112 | depends on IPW2200_MONITOR | ||
113 | select IPW2200_RADIOTAP | ||
114 | ---help--- | ||
115 | Enables the creation of a second interface prefixed 'rtap'. | ||
116 | This second interface will provide every received in radiotap | ||
117 | format. | ||
118 | |||
119 | This is useful for performing wireless network analysis while | ||
120 | maintaining an active association. | ||
121 | |||
122 | Example usage: | ||
123 | |||
124 | % modprobe ipw2200 rtap_iface=1 | ||
125 | % ifconfig rtap0 up | ||
126 | % tethereal -i rtap0 | ||
127 | |||
128 | If you do not specify 'rtap_iface=1' as a module parameter then | ||
129 | the rtap interface will not be created and you will need to turn | ||
130 | it on via sysfs: | ||
131 | |||
132 | % echo 1 > /sys/bus/pci/drivers/ipw2200/*/rtap_iface | ||
133 | |||
134 | config IPW2200_QOS | ||
135 | bool "Enable QoS support" | ||
136 | depends on IPW2200 && EXPERIMENTAL | ||
137 | |||
138 | config IPW2200_DEBUG | ||
139 | bool "Enable full debugging output in IPW2200 module." | ||
140 | depends on IPW2200 | ||
141 | ---help--- | ||
142 | This option will enable low level debug tracing output for IPW2200. | ||
143 | |||
144 | Note, normal debug code is already compiled in. This low level | ||
145 | debug option enables debug on hot paths (e.g Tx, Rx, ISR) and | ||
146 | will result in the kernel module being ~70 larger. Most users | ||
147 | will typically not need this high verbosity debug information. | ||
148 | |||
149 | If you are not sure, say N here. | ||
150 | |||
diff --git a/drivers/net/wireless/ipw2x00/Makefile b/drivers/net/wireless/ipw2x00/Makefile new file mode 100644 index 000000000000..dbc0d81b6faa --- /dev/null +++ b/drivers/net/wireless/ipw2x00/Makefile | |||
@@ -0,0 +1,6 @@ | |||
1 | # | ||
2 | # Makefile for the Intel Centrino wireless drivers | ||
3 | # | ||
4 | |||
5 | obj-$(CONFIG_IPW2100) += ipw2100.o | ||
6 | obj-$(CONFIG_IPW2200) += ipw2200.o | ||
diff --git a/drivers/net/wireless/ipw2x00/ipw2100.c b/drivers/net/wireless/ipw2x00/ipw2100.c new file mode 100644 index 000000000000..2d2044d3d1c9 --- /dev/null +++ b/drivers/net/wireless/ipw2x00/ipw2100.c | |||
@@ -0,0 +1,8649 @@ | |||
1 | /****************************************************************************** | ||
2 | |||
3 | Copyright(c) 2003 - 2006 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., 59 | ||
16 | Temple Place - Suite 330, Boston, MA 02111-1307, 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 | James P. Ketrenos <ipw2100-admin@linux.intel.com> | ||
23 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
24 | |||
25 | Portions of this file are based on the sample_* files provided by Wireless | ||
26 | Extensions 0.26 package and copyright (c) 1997-2003 Jean Tourrilhes | ||
27 | <jt@hpl.hp.com> | ||
28 | |||
29 | Portions of this file are based on the Host AP project, | ||
30 | Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen | ||
31 | <j@w1.fi> | ||
32 | Copyright (c) 2002-2003, Jouni Malinen <j@w1.fi> | ||
33 | |||
34 | Portions of ipw2100_mod_firmware_load, ipw2100_do_mod_firmware_load, and | ||
35 | ipw2100_fw_load are loosely based on drivers/sound/sound_firmware.c | ||
36 | available in the 2.4.25 kernel sources, and are copyright (c) Alan Cox | ||
37 | |||
38 | ******************************************************************************/ | ||
39 | /* | ||
40 | |||
41 | Initial driver on which this is based was developed by Janusz Gorycki, | ||
42 | Maciej Urbaniak, and Maciej Sosnowski. | ||
43 | |||
44 | Promiscuous mode support added by Jacek Wysoczynski and Maciej Urbaniak. | ||
45 | |||
46 | Theory of Operation | ||
47 | |||
48 | Tx - Commands and Data | ||
49 | |||
50 | Firmware and host share a circular queue of Transmit Buffer Descriptors (TBDs) | ||
51 | Each TBD contains a pointer to the physical (dma_addr_t) address of data being | ||
52 | sent to the firmware as well as the length of the data. | ||
53 | |||
54 | The host writes to the TBD queue at the WRITE index. The WRITE index points | ||
55 | to the _next_ packet to be written and is advanced when after the TBD has been | ||
56 | filled. | ||
57 | |||
58 | The firmware pulls from the TBD queue at the READ index. The READ index points | ||
59 | to the currently being read entry, and is advanced once the firmware is | ||
60 | done with a packet. | ||
61 | |||
62 | When data is sent to the firmware, the first TBD is used to indicate to the | ||
63 | firmware if a Command or Data is being sent. If it is Command, all of the | ||
64 | command information is contained within the physical address referred to by the | ||
65 | TBD. If it is Data, the first TBD indicates the type of data packet, number | ||
66 | of fragments, etc. The next TBD then referrs to the actual packet location. | ||
67 | |||
68 | The Tx flow cycle is as follows: | ||
69 | |||
70 | 1) ipw2100_tx() is called by kernel with SKB to transmit | ||
71 | 2) Packet is move from the tx_free_list and appended to the transmit pending | ||
72 | list (tx_pend_list) | ||
73 | 3) work is scheduled to move pending packets into the shared circular queue. | ||
74 | 4) when placing packet in the circular queue, the incoming SKB is DMA mapped | ||
75 | to a physical address. That address is entered into a TBD. Two TBDs are | ||
76 | filled out. The first indicating a data packet, the second referring to the | ||
77 | actual payload data. | ||
78 | 5) the packet is removed from tx_pend_list and placed on the end of the | ||
79 | firmware pending list (fw_pend_list) | ||
80 | 6) firmware is notified that the WRITE index has | ||
81 | 7) Once the firmware has processed the TBD, INTA is triggered. | ||
82 | 8) For each Tx interrupt received from the firmware, the READ index is checked | ||
83 | to see which TBDs are done being processed. | ||
84 | 9) For each TBD that has been processed, the ISR pulls the oldest packet | ||
85 | from the fw_pend_list. | ||
86 | 10)The packet structure contained in the fw_pend_list is then used | ||
87 | to unmap the DMA address and to free the SKB originally passed to the driver | ||
88 | from the kernel. | ||
89 | 11)The packet structure is placed onto the tx_free_list | ||
90 | |||
91 | The above steps are the same for commands, only the msg_free_list/msg_pend_list | ||
92 | are used instead of tx_free_list/tx_pend_list | ||
93 | |||
94 | ... | ||
95 | |||
96 | Critical Sections / Locking : | ||
97 | |||
98 | There are two locks utilized. The first is the low level lock (priv->low_lock) | ||
99 | that protects the following: | ||
100 | |||
101 | - Access to the Tx/Rx queue lists via priv->low_lock. The lists are as follows: | ||
102 | |||
103 | tx_free_list : Holds pre-allocated Tx buffers. | ||
104 | TAIL modified in __ipw2100_tx_process() | ||
105 | HEAD modified in ipw2100_tx() | ||
106 | |||
107 | tx_pend_list : Holds used Tx buffers waiting to go into the TBD ring | ||
108 | TAIL modified ipw2100_tx() | ||
109 | HEAD modified by ipw2100_tx_send_data() | ||
110 | |||
111 | msg_free_list : Holds pre-allocated Msg (Command) buffers | ||
112 | TAIL modified in __ipw2100_tx_process() | ||
113 | HEAD modified in ipw2100_hw_send_command() | ||
114 | |||
115 | msg_pend_list : Holds used Msg buffers waiting to go into the TBD ring | ||
116 | TAIL modified in ipw2100_hw_send_command() | ||
117 | HEAD modified in ipw2100_tx_send_commands() | ||
118 | |||
119 | The flow of data on the TX side is as follows: | ||
120 | |||
121 | MSG_FREE_LIST + COMMAND => MSG_PEND_LIST => TBD => MSG_FREE_LIST | ||
122 | TX_FREE_LIST + DATA => TX_PEND_LIST => TBD => TX_FREE_LIST | ||
123 | |||
124 | The methods that work on the TBD ring are protected via priv->low_lock. | ||
125 | |||
126 | - The internal data state of the device itself | ||
127 | - Access to the firmware read/write indexes for the BD queues | ||
128 | and associated logic | ||
129 | |||
130 | All external entry functions are locked with the priv->action_lock to ensure | ||
131 | that only one external action is invoked at a time. | ||
132 | |||
133 | |||
134 | */ | ||
135 | |||
136 | #include <linux/compiler.h> | ||
137 | #include <linux/errno.h> | ||
138 | #include <linux/if_arp.h> | ||
139 | #include <linux/in6.h> | ||
140 | #include <linux/in.h> | ||
141 | #include <linux/ip.h> | ||
142 | #include <linux/kernel.h> | ||
143 | #include <linux/kmod.h> | ||
144 | #include <linux/module.h> | ||
145 | #include <linux/netdevice.h> | ||
146 | #include <linux/ethtool.h> | ||
147 | #include <linux/pci.h> | ||
148 | #include <linux/dma-mapping.h> | ||
149 | #include <linux/proc_fs.h> | ||
150 | #include <linux/skbuff.h> | ||
151 | #include <asm/uaccess.h> | ||
152 | #include <asm/io.h> | ||
153 | #include <linux/fs.h> | ||
154 | #include <linux/mm.h> | ||
155 | #include <linux/slab.h> | ||
156 | #include <linux/unistd.h> | ||
157 | #include <linux/stringify.h> | ||
158 | #include <linux/tcp.h> | ||
159 | #include <linux/types.h> | ||
160 | #include <linux/time.h> | ||
161 | #include <linux/firmware.h> | ||
162 | #include <linux/acpi.h> | ||
163 | #include <linux/ctype.h> | ||
164 | #include <linux/pm_qos_params.h> | ||
165 | |||
166 | #include <net/lib80211.h> | ||
167 | |||
168 | #include "ipw2100.h" | ||
169 | |||
170 | #define IPW2100_VERSION "git-1.2.2" | ||
171 | |||
172 | #define DRV_NAME "ipw2100" | ||
173 | #define DRV_VERSION IPW2100_VERSION | ||
174 | #define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2100 Network Driver" | ||
175 | #define DRV_COPYRIGHT "Copyright(c) 2003-2006 Intel Corporation" | ||
176 | |||
177 | /* Debugging stuff */ | ||
178 | #ifdef CONFIG_IPW2100_DEBUG | ||
179 | #define IPW2100_RX_DEBUG /* Reception debugging */ | ||
180 | #endif | ||
181 | |||
182 | MODULE_DESCRIPTION(DRV_DESCRIPTION); | ||
183 | MODULE_VERSION(DRV_VERSION); | ||
184 | MODULE_AUTHOR(DRV_COPYRIGHT); | ||
185 | MODULE_LICENSE("GPL"); | ||
186 | |||
187 | static int debug = 0; | ||
188 | static int mode = 0; | ||
189 | static int channel = 0; | ||
190 | static int associate = 0; | ||
191 | static int disable = 0; | ||
192 | #ifdef CONFIG_PM | ||
193 | static struct ipw2100_fw ipw2100_firmware; | ||
194 | #endif | ||
195 | |||
196 | #include <linux/moduleparam.h> | ||
197 | module_param(debug, int, 0444); | ||
198 | module_param(mode, int, 0444); | ||
199 | module_param(channel, int, 0444); | ||
200 | module_param(associate, int, 0444); | ||
201 | module_param(disable, int, 0444); | ||
202 | |||
203 | MODULE_PARM_DESC(debug, "debug level"); | ||
204 | MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)"); | ||
205 | MODULE_PARM_DESC(channel, "channel"); | ||
206 | MODULE_PARM_DESC(associate, "auto associate when scanning (default off)"); | ||
207 | MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])"); | ||
208 | |||
209 | static u32 ipw2100_debug_level = IPW_DL_NONE; | ||
210 | |||
211 | #ifdef CONFIG_IPW2100_DEBUG | ||
212 | #define IPW_DEBUG(level, message...) \ | ||
213 | do { \ | ||
214 | if (ipw2100_debug_level & (level)) { \ | ||
215 | printk(KERN_DEBUG "ipw2100: %c %s ", \ | ||
216 | in_interrupt() ? 'I' : 'U', __func__); \ | ||
217 | printk(message); \ | ||
218 | } \ | ||
219 | } while (0) | ||
220 | #else | ||
221 | #define IPW_DEBUG(level, message...) do {} while (0) | ||
222 | #endif /* CONFIG_IPW2100_DEBUG */ | ||
223 | |||
224 | #ifdef CONFIG_IPW2100_DEBUG | ||
225 | static const char *command_types[] = { | ||
226 | "undefined", | ||
227 | "unused", /* HOST_ATTENTION */ | ||
228 | "HOST_COMPLETE", | ||
229 | "unused", /* SLEEP */ | ||
230 | "unused", /* HOST_POWER_DOWN */ | ||
231 | "unused", | ||
232 | "SYSTEM_CONFIG", | ||
233 | "unused", /* SET_IMR */ | ||
234 | "SSID", | ||
235 | "MANDATORY_BSSID", | ||
236 | "AUTHENTICATION_TYPE", | ||
237 | "ADAPTER_ADDRESS", | ||
238 | "PORT_TYPE", | ||
239 | "INTERNATIONAL_MODE", | ||
240 | "CHANNEL", | ||
241 | "RTS_THRESHOLD", | ||
242 | "FRAG_THRESHOLD", | ||
243 | "POWER_MODE", | ||
244 | "TX_RATES", | ||
245 | "BASIC_TX_RATES", | ||
246 | "WEP_KEY_INFO", | ||
247 | "unused", | ||
248 | "unused", | ||
249 | "unused", | ||
250 | "unused", | ||
251 | "WEP_KEY_INDEX", | ||
252 | "WEP_FLAGS", | ||
253 | "ADD_MULTICAST", | ||
254 | "CLEAR_ALL_MULTICAST", | ||
255 | "BEACON_INTERVAL", | ||
256 | "ATIM_WINDOW", | ||
257 | "CLEAR_STATISTICS", | ||
258 | "undefined", | ||
259 | "undefined", | ||
260 | "undefined", | ||
261 | "undefined", | ||
262 | "TX_POWER_INDEX", | ||
263 | "undefined", | ||
264 | "undefined", | ||
265 | "undefined", | ||
266 | "undefined", | ||
267 | "undefined", | ||
268 | "undefined", | ||
269 | "BROADCAST_SCAN", | ||
270 | "CARD_DISABLE", | ||
271 | "PREFERRED_BSSID", | ||
272 | "SET_SCAN_OPTIONS", | ||
273 | "SCAN_DWELL_TIME", | ||
274 | "SWEEP_TABLE", | ||
275 | "AP_OR_STATION_TABLE", | ||
276 | "GROUP_ORDINALS", | ||
277 | "SHORT_RETRY_LIMIT", | ||
278 | "LONG_RETRY_LIMIT", | ||
279 | "unused", /* SAVE_CALIBRATION */ | ||
280 | "unused", /* RESTORE_CALIBRATION */ | ||
281 | "undefined", | ||
282 | "undefined", | ||
283 | "undefined", | ||
284 | "HOST_PRE_POWER_DOWN", | ||
285 | "unused", /* HOST_INTERRUPT_COALESCING */ | ||
286 | "undefined", | ||
287 | "CARD_DISABLE_PHY_OFF", | ||
288 | "MSDU_TX_RATES" "undefined", | ||
289 | "undefined", | ||
290 | "SET_STATION_STAT_BITS", | ||
291 | "CLEAR_STATIONS_STAT_BITS", | ||
292 | "LEAP_ROGUE_MODE", | ||
293 | "SET_SECURITY_INFORMATION", | ||
294 | "DISASSOCIATION_BSSID", | ||
295 | "SET_WPA_ASS_IE" | ||
296 | }; | ||
297 | #endif | ||
298 | |||
299 | /* Pre-decl until we get the code solid and then we can clean it up */ | ||
300 | static void ipw2100_tx_send_commands(struct ipw2100_priv *priv); | ||
301 | static void ipw2100_tx_send_data(struct ipw2100_priv *priv); | ||
302 | static int ipw2100_adapter_setup(struct ipw2100_priv *priv); | ||
303 | |||
304 | static void ipw2100_queues_initialize(struct ipw2100_priv *priv); | ||
305 | static void ipw2100_queues_free(struct ipw2100_priv *priv); | ||
306 | static int ipw2100_queues_allocate(struct ipw2100_priv *priv); | ||
307 | |||
308 | static int ipw2100_fw_download(struct ipw2100_priv *priv, | ||
309 | struct ipw2100_fw *fw); | ||
310 | static int ipw2100_get_firmware(struct ipw2100_priv *priv, | ||
311 | struct ipw2100_fw *fw); | ||
312 | static int ipw2100_get_fwversion(struct ipw2100_priv *priv, char *buf, | ||
313 | size_t max); | ||
314 | static int ipw2100_get_ucodeversion(struct ipw2100_priv *priv, char *buf, | ||
315 | size_t max); | ||
316 | static void ipw2100_release_firmware(struct ipw2100_priv *priv, | ||
317 | struct ipw2100_fw *fw); | ||
318 | static int ipw2100_ucode_download(struct ipw2100_priv *priv, | ||
319 | struct ipw2100_fw *fw); | ||
320 | static void ipw2100_wx_event_work(struct work_struct *work); | ||
321 | static struct iw_statistics *ipw2100_wx_wireless_stats(struct net_device *dev); | ||
322 | static struct iw_handler_def ipw2100_wx_handler_def; | ||
323 | |||
324 | static inline void read_register(struct net_device *dev, u32 reg, u32 * val) | ||
325 | { | ||
326 | *val = readl((void __iomem *)(dev->base_addr + reg)); | ||
327 | IPW_DEBUG_IO("r: 0x%08X => 0x%08X\n", reg, *val); | ||
328 | } | ||
329 | |||
330 | static inline void write_register(struct net_device *dev, u32 reg, u32 val) | ||
331 | { | ||
332 | writel(val, (void __iomem *)(dev->base_addr + reg)); | ||
333 | IPW_DEBUG_IO("w: 0x%08X <= 0x%08X\n", reg, val); | ||
334 | } | ||
335 | |||
336 | static inline void read_register_word(struct net_device *dev, u32 reg, | ||
337 | u16 * val) | ||
338 | { | ||
339 | *val = readw((void __iomem *)(dev->base_addr + reg)); | ||
340 | IPW_DEBUG_IO("r: 0x%08X => %04X\n", reg, *val); | ||
341 | } | ||
342 | |||
343 | static inline void read_register_byte(struct net_device *dev, u32 reg, u8 * val) | ||
344 | { | ||
345 | *val = readb((void __iomem *)(dev->base_addr + reg)); | ||
346 | IPW_DEBUG_IO("r: 0x%08X => %02X\n", reg, *val); | ||
347 | } | ||
348 | |||
349 | static inline void write_register_word(struct net_device *dev, u32 reg, u16 val) | ||
350 | { | ||
351 | writew(val, (void __iomem *)(dev->base_addr + reg)); | ||
352 | IPW_DEBUG_IO("w: 0x%08X <= %04X\n", reg, val); | ||
353 | } | ||
354 | |||
355 | static inline void write_register_byte(struct net_device *dev, u32 reg, u8 val) | ||
356 | { | ||
357 | writeb(val, (void __iomem *)(dev->base_addr + reg)); | ||
358 | IPW_DEBUG_IO("w: 0x%08X =< %02X\n", reg, val); | ||
359 | } | ||
360 | |||
361 | static inline void read_nic_dword(struct net_device *dev, u32 addr, u32 * val) | ||
362 | { | ||
363 | write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, | ||
364 | addr & IPW_REG_INDIRECT_ADDR_MASK); | ||
365 | read_register(dev, IPW_REG_INDIRECT_ACCESS_DATA, val); | ||
366 | } | ||
367 | |||
368 | static inline void write_nic_dword(struct net_device *dev, u32 addr, u32 val) | ||
369 | { | ||
370 | write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, | ||
371 | addr & IPW_REG_INDIRECT_ADDR_MASK); | ||
372 | write_register(dev, IPW_REG_INDIRECT_ACCESS_DATA, val); | ||
373 | } | ||
374 | |||
375 | static inline void read_nic_word(struct net_device *dev, u32 addr, u16 * val) | ||
376 | { | ||
377 | write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, | ||
378 | addr & IPW_REG_INDIRECT_ADDR_MASK); | ||
379 | read_register_word(dev, IPW_REG_INDIRECT_ACCESS_DATA, val); | ||
380 | } | ||
381 | |||
382 | static inline void write_nic_word(struct net_device *dev, u32 addr, u16 val) | ||
383 | { | ||
384 | write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, | ||
385 | addr & IPW_REG_INDIRECT_ADDR_MASK); | ||
386 | write_register_word(dev, IPW_REG_INDIRECT_ACCESS_DATA, val); | ||
387 | } | ||
388 | |||
389 | static inline void read_nic_byte(struct net_device *dev, u32 addr, u8 * val) | ||
390 | { | ||
391 | write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, | ||
392 | addr & IPW_REG_INDIRECT_ADDR_MASK); | ||
393 | read_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA, val); | ||
394 | } | ||
395 | |||
396 | static inline void write_nic_byte(struct net_device *dev, u32 addr, u8 val) | ||
397 | { | ||
398 | write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, | ||
399 | addr & IPW_REG_INDIRECT_ADDR_MASK); | ||
400 | write_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA, val); | ||
401 | } | ||
402 | |||
403 | static inline void write_nic_auto_inc_address(struct net_device *dev, u32 addr) | ||
404 | { | ||
405 | write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS, | ||
406 | addr & IPW_REG_INDIRECT_ADDR_MASK); | ||
407 | } | ||
408 | |||
409 | static inline void write_nic_dword_auto_inc(struct net_device *dev, u32 val) | ||
410 | { | ||
411 | write_register(dev, IPW_REG_AUTOINCREMENT_DATA, val); | ||
412 | } | ||
413 | |||
414 | static void write_nic_memory(struct net_device *dev, u32 addr, u32 len, | ||
415 | const u8 * buf) | ||
416 | { | ||
417 | u32 aligned_addr; | ||
418 | u32 aligned_len; | ||
419 | u32 dif_len; | ||
420 | u32 i; | ||
421 | |||
422 | /* read first nibble byte by byte */ | ||
423 | aligned_addr = addr & (~0x3); | ||
424 | dif_len = addr - aligned_addr; | ||
425 | if (dif_len) { | ||
426 | /* Start reading at aligned_addr + dif_len */ | ||
427 | write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, | ||
428 | aligned_addr); | ||
429 | for (i = dif_len; i < 4; i++, buf++) | ||
430 | write_register_byte(dev, | ||
431 | IPW_REG_INDIRECT_ACCESS_DATA + i, | ||
432 | *buf); | ||
433 | |||
434 | len -= dif_len; | ||
435 | aligned_addr += 4; | ||
436 | } | ||
437 | |||
438 | /* read DWs through autoincrement registers */ | ||
439 | write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS, aligned_addr); | ||
440 | aligned_len = len & (~0x3); | ||
441 | for (i = 0; i < aligned_len; i += 4, buf += 4, aligned_addr += 4) | ||
442 | write_register(dev, IPW_REG_AUTOINCREMENT_DATA, *(u32 *) buf); | ||
443 | |||
444 | /* copy the last nibble */ | ||
445 | dif_len = len - aligned_len; | ||
446 | write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, aligned_addr); | ||
447 | for (i = 0; i < dif_len; i++, buf++) | ||
448 | write_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA + i, | ||
449 | *buf); | ||
450 | } | ||
451 | |||
452 | static void read_nic_memory(struct net_device *dev, u32 addr, u32 len, | ||
453 | u8 * buf) | ||
454 | { | ||
455 | u32 aligned_addr; | ||
456 | u32 aligned_len; | ||
457 | u32 dif_len; | ||
458 | u32 i; | ||
459 | |||
460 | /* read first nibble byte by byte */ | ||
461 | aligned_addr = addr & (~0x3); | ||
462 | dif_len = addr - aligned_addr; | ||
463 | if (dif_len) { | ||
464 | /* Start reading at aligned_addr + dif_len */ | ||
465 | write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, | ||
466 | aligned_addr); | ||
467 | for (i = dif_len; i < 4; i++, buf++) | ||
468 | read_register_byte(dev, | ||
469 | IPW_REG_INDIRECT_ACCESS_DATA + i, | ||
470 | buf); | ||
471 | |||
472 | len -= dif_len; | ||
473 | aligned_addr += 4; | ||
474 | } | ||
475 | |||
476 | /* read DWs through autoincrement registers */ | ||
477 | write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS, aligned_addr); | ||
478 | aligned_len = len & (~0x3); | ||
479 | for (i = 0; i < aligned_len; i += 4, buf += 4, aligned_addr += 4) | ||
480 | read_register(dev, IPW_REG_AUTOINCREMENT_DATA, (u32 *) buf); | ||
481 | |||
482 | /* copy the last nibble */ | ||
483 | dif_len = len - aligned_len; | ||
484 | write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, aligned_addr); | ||
485 | for (i = 0; i < dif_len; i++, buf++) | ||
486 | read_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA + i, buf); | ||
487 | } | ||
488 | |||
489 | static inline int ipw2100_hw_is_adapter_in_system(struct net_device *dev) | ||
490 | { | ||
491 | return (dev->base_addr && | ||
492 | (readl | ||
493 | ((void __iomem *)(dev->base_addr + | ||
494 | IPW_REG_DOA_DEBUG_AREA_START)) | ||
495 | == IPW_DATA_DOA_DEBUG_VALUE)); | ||
496 | } | ||
497 | |||
498 | static int ipw2100_get_ordinal(struct ipw2100_priv *priv, u32 ord, | ||
499 | void *val, u32 * len) | ||
500 | { | ||
501 | struct ipw2100_ordinals *ordinals = &priv->ordinals; | ||
502 | u32 addr; | ||
503 | u32 field_info; | ||
504 | u16 field_len; | ||
505 | u16 field_count; | ||
506 | u32 total_length; | ||
507 | |||
508 | if (ordinals->table1_addr == 0) { | ||
509 | printk(KERN_WARNING DRV_NAME ": attempt to use fw ordinals " | ||
510 | "before they have been loaded.\n"); | ||
511 | return -EINVAL; | ||
512 | } | ||
513 | |||
514 | if (IS_ORDINAL_TABLE_ONE(ordinals, ord)) { | ||
515 | if (*len < IPW_ORD_TAB_1_ENTRY_SIZE) { | ||
516 | *len = IPW_ORD_TAB_1_ENTRY_SIZE; | ||
517 | |||
518 | printk(KERN_WARNING DRV_NAME | ||
519 | ": ordinal buffer length too small, need %zd\n", | ||
520 | IPW_ORD_TAB_1_ENTRY_SIZE); | ||
521 | |||
522 | return -EINVAL; | ||
523 | } | ||
524 | |||
525 | read_nic_dword(priv->net_dev, | ||
526 | ordinals->table1_addr + (ord << 2), &addr); | ||
527 | read_nic_dword(priv->net_dev, addr, val); | ||
528 | |||
529 | *len = IPW_ORD_TAB_1_ENTRY_SIZE; | ||
530 | |||
531 | return 0; | ||
532 | } | ||
533 | |||
534 | if (IS_ORDINAL_TABLE_TWO(ordinals, ord)) { | ||
535 | |||
536 | ord -= IPW_START_ORD_TAB_2; | ||
537 | |||
538 | /* get the address of statistic */ | ||
539 | read_nic_dword(priv->net_dev, | ||
540 | ordinals->table2_addr + (ord << 3), &addr); | ||
541 | |||
542 | /* get the second DW of statistics ; | ||
543 | * two 16-bit words - first is length, second is count */ | ||
544 | read_nic_dword(priv->net_dev, | ||
545 | ordinals->table2_addr + (ord << 3) + sizeof(u32), | ||
546 | &field_info); | ||
547 | |||
548 | /* get each entry length */ | ||
549 | field_len = *((u16 *) & field_info); | ||
550 | |||
551 | /* get number of entries */ | ||
552 | field_count = *(((u16 *) & field_info) + 1); | ||
553 | |||
554 | /* abort if no enought memory */ | ||
555 | total_length = field_len * field_count; | ||
556 | if (total_length > *len) { | ||
557 | *len = total_length; | ||
558 | return -EINVAL; | ||
559 | } | ||
560 | |||
561 | *len = total_length; | ||
562 | if (!total_length) | ||
563 | return 0; | ||
564 | |||
565 | /* read the ordinal data from the SRAM */ | ||
566 | read_nic_memory(priv->net_dev, addr, total_length, val); | ||
567 | |||
568 | return 0; | ||
569 | } | ||
570 | |||
571 | printk(KERN_WARNING DRV_NAME ": ordinal %d neither in table 1 nor " | ||
572 | "in table 2\n", ord); | ||
573 | |||
574 | return -EINVAL; | ||
575 | } | ||
576 | |||
577 | static int ipw2100_set_ordinal(struct ipw2100_priv *priv, u32 ord, u32 * val, | ||
578 | u32 * len) | ||
579 | { | ||
580 | struct ipw2100_ordinals *ordinals = &priv->ordinals; | ||
581 | u32 addr; | ||
582 | |||
583 | if (IS_ORDINAL_TABLE_ONE(ordinals, ord)) { | ||
584 | if (*len != IPW_ORD_TAB_1_ENTRY_SIZE) { | ||
585 | *len = IPW_ORD_TAB_1_ENTRY_SIZE; | ||
586 | IPW_DEBUG_INFO("wrong size\n"); | ||
587 | return -EINVAL; | ||
588 | } | ||
589 | |||
590 | read_nic_dword(priv->net_dev, | ||
591 | ordinals->table1_addr + (ord << 2), &addr); | ||
592 | |||
593 | write_nic_dword(priv->net_dev, addr, *val); | ||
594 | |||
595 | *len = IPW_ORD_TAB_1_ENTRY_SIZE; | ||
596 | |||
597 | return 0; | ||
598 | } | ||
599 | |||
600 | IPW_DEBUG_INFO("wrong table\n"); | ||
601 | if (IS_ORDINAL_TABLE_TWO(ordinals, ord)) | ||
602 | return -EINVAL; | ||
603 | |||
604 | return -EINVAL; | ||
605 | } | ||
606 | |||
607 | static char *snprint_line(char *buf, size_t count, | ||
608 | const u8 * data, u32 len, u32 ofs) | ||
609 | { | ||
610 | int out, i, j, l; | ||
611 | char c; | ||
612 | |||
613 | out = snprintf(buf, count, "%08X", ofs); | ||
614 | |||
615 | for (l = 0, i = 0; i < 2; i++) { | ||
616 | out += snprintf(buf + out, count - out, " "); | ||
617 | for (j = 0; j < 8 && l < len; j++, l++) | ||
618 | out += snprintf(buf + out, count - out, "%02X ", | ||
619 | data[(i * 8 + j)]); | ||
620 | for (; j < 8; j++) | ||
621 | out += snprintf(buf + out, count - out, " "); | ||
622 | } | ||
623 | |||
624 | out += snprintf(buf + out, count - out, " "); | ||
625 | for (l = 0, i = 0; i < 2; i++) { | ||
626 | out += snprintf(buf + out, count - out, " "); | ||
627 | for (j = 0; j < 8 && l < len; j++, l++) { | ||
628 | c = data[(i * 8 + j)]; | ||
629 | if (!isascii(c) || !isprint(c)) | ||
630 | c = '.'; | ||
631 | |||
632 | out += snprintf(buf + out, count - out, "%c", c); | ||
633 | } | ||
634 | |||
635 | for (; j < 8; j++) | ||
636 | out += snprintf(buf + out, count - out, " "); | ||
637 | } | ||
638 | |||
639 | return buf; | ||
640 | } | ||
641 | |||
642 | static void printk_buf(int level, const u8 * data, u32 len) | ||
643 | { | ||
644 | char line[81]; | ||
645 | u32 ofs = 0; | ||
646 | if (!(ipw2100_debug_level & level)) | ||
647 | return; | ||
648 | |||
649 | while (len) { | ||
650 | printk(KERN_DEBUG "%s\n", | ||
651 | snprint_line(line, sizeof(line), &data[ofs], | ||
652 | min(len, 16U), ofs)); | ||
653 | ofs += 16; | ||
654 | len -= min(len, 16U); | ||
655 | } | ||
656 | } | ||
657 | |||
658 | #define MAX_RESET_BACKOFF 10 | ||
659 | |||
660 | static void schedule_reset(struct ipw2100_priv *priv) | ||
661 | { | ||
662 | unsigned long now = get_seconds(); | ||
663 | |||
664 | /* If we haven't received a reset request within the backoff period, | ||
665 | * then we can reset the backoff interval so this reset occurs | ||
666 | * immediately */ | ||
667 | if (priv->reset_backoff && | ||
668 | (now - priv->last_reset > priv->reset_backoff)) | ||
669 | priv->reset_backoff = 0; | ||
670 | |||
671 | priv->last_reset = get_seconds(); | ||
672 | |||
673 | if (!(priv->status & STATUS_RESET_PENDING)) { | ||
674 | IPW_DEBUG_INFO("%s: Scheduling firmware restart (%ds).\n", | ||
675 | priv->net_dev->name, priv->reset_backoff); | ||
676 | netif_carrier_off(priv->net_dev); | ||
677 | netif_stop_queue(priv->net_dev); | ||
678 | priv->status |= STATUS_RESET_PENDING; | ||
679 | if (priv->reset_backoff) | ||
680 | queue_delayed_work(priv->workqueue, &priv->reset_work, | ||
681 | priv->reset_backoff * HZ); | ||
682 | else | ||
683 | queue_delayed_work(priv->workqueue, &priv->reset_work, | ||
684 | 0); | ||
685 | |||
686 | if (priv->reset_backoff < MAX_RESET_BACKOFF) | ||
687 | priv->reset_backoff++; | ||
688 | |||
689 | wake_up_interruptible(&priv->wait_command_queue); | ||
690 | } else | ||
691 | IPW_DEBUG_INFO("%s: Firmware restart already in progress.\n", | ||
692 | priv->net_dev->name); | ||
693 | |||
694 | } | ||
695 | |||
696 | #define HOST_COMPLETE_TIMEOUT (2 * HZ) | ||
697 | static int ipw2100_hw_send_command(struct ipw2100_priv *priv, | ||
698 | struct host_command *cmd) | ||
699 | { | ||
700 | struct list_head *element; | ||
701 | struct ipw2100_tx_packet *packet; | ||
702 | unsigned long flags; | ||
703 | int err = 0; | ||
704 | |||
705 | IPW_DEBUG_HC("Sending %s command (#%d), %d bytes\n", | ||
706 | command_types[cmd->host_command], cmd->host_command, | ||
707 | cmd->host_command_length); | ||
708 | printk_buf(IPW_DL_HC, (u8 *) cmd->host_command_parameters, | ||
709 | cmd->host_command_length); | ||
710 | |||
711 | spin_lock_irqsave(&priv->low_lock, flags); | ||
712 | |||
713 | if (priv->fatal_error) { | ||
714 | IPW_DEBUG_INFO | ||
715 | ("Attempt to send command while hardware in fatal error condition.\n"); | ||
716 | err = -EIO; | ||
717 | goto fail_unlock; | ||
718 | } | ||
719 | |||
720 | if (!(priv->status & STATUS_RUNNING)) { | ||
721 | IPW_DEBUG_INFO | ||
722 | ("Attempt to send command while hardware is not running.\n"); | ||
723 | err = -EIO; | ||
724 | goto fail_unlock; | ||
725 | } | ||
726 | |||
727 | if (priv->status & STATUS_CMD_ACTIVE) { | ||
728 | IPW_DEBUG_INFO | ||
729 | ("Attempt to send command while another command is pending.\n"); | ||
730 | err = -EBUSY; | ||
731 | goto fail_unlock; | ||
732 | } | ||
733 | |||
734 | if (list_empty(&priv->msg_free_list)) { | ||
735 | IPW_DEBUG_INFO("no available msg buffers\n"); | ||
736 | goto fail_unlock; | ||
737 | } | ||
738 | |||
739 | priv->status |= STATUS_CMD_ACTIVE; | ||
740 | priv->messages_sent++; | ||
741 | |||
742 | element = priv->msg_free_list.next; | ||
743 | |||
744 | packet = list_entry(element, struct ipw2100_tx_packet, list); | ||
745 | packet->jiffy_start = jiffies; | ||
746 | |||
747 | /* initialize the firmware command packet */ | ||
748 | packet->info.c_struct.cmd->host_command_reg = cmd->host_command; | ||
749 | packet->info.c_struct.cmd->host_command_reg1 = cmd->host_command1; | ||
750 | packet->info.c_struct.cmd->host_command_len_reg = | ||
751 | cmd->host_command_length; | ||
752 | packet->info.c_struct.cmd->sequence = cmd->host_command_sequence; | ||
753 | |||
754 | memcpy(packet->info.c_struct.cmd->host_command_params_reg, | ||
755 | cmd->host_command_parameters, | ||
756 | sizeof(packet->info.c_struct.cmd->host_command_params_reg)); | ||
757 | |||
758 | list_del(element); | ||
759 | DEC_STAT(&priv->msg_free_stat); | ||
760 | |||
761 | list_add_tail(element, &priv->msg_pend_list); | ||
762 | INC_STAT(&priv->msg_pend_stat); | ||
763 | |||
764 | ipw2100_tx_send_commands(priv); | ||
765 | ipw2100_tx_send_data(priv); | ||
766 | |||
767 | spin_unlock_irqrestore(&priv->low_lock, flags); | ||
768 | |||
769 | /* | ||
770 | * We must wait for this command to complete before another | ||
771 | * command can be sent... but if we wait more than 3 seconds | ||
772 | * then there is a problem. | ||
773 | */ | ||
774 | |||
775 | err = | ||
776 | wait_event_interruptible_timeout(priv->wait_command_queue, | ||
777 | !(priv-> | ||
778 | status & STATUS_CMD_ACTIVE), | ||
779 | HOST_COMPLETE_TIMEOUT); | ||
780 | |||
781 | if (err == 0) { | ||
782 | IPW_DEBUG_INFO("Command completion failed out after %dms.\n", | ||
783 | 1000 * (HOST_COMPLETE_TIMEOUT / HZ)); | ||
784 | priv->fatal_error = IPW2100_ERR_MSG_TIMEOUT; | ||
785 | priv->status &= ~STATUS_CMD_ACTIVE; | ||
786 | schedule_reset(priv); | ||
787 | return -EIO; | ||
788 | } | ||
789 | |||
790 | if (priv->fatal_error) { | ||
791 | printk(KERN_WARNING DRV_NAME ": %s: firmware fatal error\n", | ||
792 | priv->net_dev->name); | ||
793 | return -EIO; | ||
794 | } | ||
795 | |||
796 | /* !!!!! HACK TEST !!!!! | ||
797 | * When lots of debug trace statements are enabled, the driver | ||
798 | * doesn't seem to have as many firmware restart cycles... | ||
799 | * | ||
800 | * As a test, we're sticking in a 1/100s delay here */ | ||
801 | schedule_timeout_uninterruptible(msecs_to_jiffies(10)); | ||
802 | |||
803 | return 0; | ||
804 | |||
805 | fail_unlock: | ||
806 | spin_unlock_irqrestore(&priv->low_lock, flags); | ||
807 | |||
808 | return err; | ||
809 | } | ||
810 | |||
811 | /* | ||
812 | * Verify the values and data access of the hardware | ||
813 | * No locks needed or used. No functions called. | ||
814 | */ | ||
815 | static int ipw2100_verify(struct ipw2100_priv *priv) | ||
816 | { | ||
817 | u32 data1, data2; | ||
818 | u32 address; | ||
819 | |||
820 | u32 val1 = 0x76543210; | ||
821 | u32 val2 = 0xFEDCBA98; | ||
822 | |||
823 | /* Domain 0 check - all values should be DOA_DEBUG */ | ||
824 | for (address = IPW_REG_DOA_DEBUG_AREA_START; | ||
825 | address < IPW_REG_DOA_DEBUG_AREA_END; address += sizeof(u32)) { | ||
826 | read_register(priv->net_dev, address, &data1); | ||
827 | if (data1 != IPW_DATA_DOA_DEBUG_VALUE) | ||
828 | return -EIO; | ||
829 | } | ||
830 | |||
831 | /* Domain 1 check - use arbitrary read/write compare */ | ||
832 | for (address = 0; address < 5; address++) { | ||
833 | /* The memory area is not used now */ | ||
834 | write_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x32, | ||
835 | val1); | ||
836 | write_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x36, | ||
837 | val2); | ||
838 | read_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x32, | ||
839 | &data1); | ||
840 | read_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x36, | ||
841 | &data2); | ||
842 | if (val1 == data1 && val2 == data2) | ||
843 | return 0; | ||
844 | } | ||
845 | |||
846 | return -EIO; | ||
847 | } | ||
848 | |||
849 | /* | ||
850 | * | ||
851 | * Loop until the CARD_DISABLED bit is the same value as the | ||
852 | * supplied parameter | ||
853 | * | ||
854 | * TODO: See if it would be more efficient to do a wait/wake | ||
855 | * cycle and have the completion event trigger the wakeup | ||
856 | * | ||
857 | */ | ||
858 | #define IPW_CARD_DISABLE_COMPLETE_WAIT 100 // 100 milli | ||
859 | static int ipw2100_wait_for_card_state(struct ipw2100_priv *priv, int state) | ||
860 | { | ||
861 | int i; | ||
862 | u32 card_state; | ||
863 | u32 len = sizeof(card_state); | ||
864 | int err; | ||
865 | |||
866 | for (i = 0; i <= IPW_CARD_DISABLE_COMPLETE_WAIT * 1000; i += 50) { | ||
867 | err = ipw2100_get_ordinal(priv, IPW_ORD_CARD_DISABLED, | ||
868 | &card_state, &len); | ||
869 | if (err) { | ||
870 | IPW_DEBUG_INFO("Query of CARD_DISABLED ordinal " | ||
871 | "failed.\n"); | ||
872 | return 0; | ||
873 | } | ||
874 | |||
875 | /* We'll break out if either the HW state says it is | ||
876 | * in the state we want, or if HOST_COMPLETE command | ||
877 | * finishes */ | ||
878 | if ((card_state == state) || | ||
879 | ((priv->status & STATUS_ENABLED) ? | ||
880 | IPW_HW_STATE_ENABLED : IPW_HW_STATE_DISABLED) == state) { | ||
881 | if (state == IPW_HW_STATE_ENABLED) | ||
882 | priv->status |= STATUS_ENABLED; | ||
883 | else | ||
884 | priv->status &= ~STATUS_ENABLED; | ||
885 | |||
886 | return 0; | ||
887 | } | ||
888 | |||
889 | udelay(50); | ||
890 | } | ||
891 | |||
892 | IPW_DEBUG_INFO("ipw2100_wait_for_card_state to %s state timed out\n", | ||
893 | state ? "DISABLED" : "ENABLED"); | ||
894 | return -EIO; | ||
895 | } | ||
896 | |||
897 | /********************************************************************* | ||
898 | Procedure : sw_reset_and_clock | ||
899 | Purpose : Asserts s/w reset, asserts clock initialization | ||
900 | and waits for clock stabilization | ||
901 | ********************************************************************/ | ||
902 | static int sw_reset_and_clock(struct ipw2100_priv *priv) | ||
903 | { | ||
904 | int i; | ||
905 | u32 r; | ||
906 | |||
907 | // assert s/w reset | ||
908 | write_register(priv->net_dev, IPW_REG_RESET_REG, | ||
909 | IPW_AUX_HOST_RESET_REG_SW_RESET); | ||
910 | |||
911 | // wait for clock stabilization | ||
912 | for (i = 0; i < 1000; i++) { | ||
913 | udelay(IPW_WAIT_RESET_ARC_COMPLETE_DELAY); | ||
914 | |||
915 | // check clock ready bit | ||
916 | read_register(priv->net_dev, IPW_REG_RESET_REG, &r); | ||
917 | if (r & IPW_AUX_HOST_RESET_REG_PRINCETON_RESET) | ||
918 | break; | ||
919 | } | ||
920 | |||
921 | if (i == 1000) | ||
922 | return -EIO; // TODO: better error value | ||
923 | |||
924 | /* set "initialization complete" bit to move adapter to | ||
925 | * D0 state */ | ||
926 | write_register(priv->net_dev, IPW_REG_GP_CNTRL, | ||
927 | IPW_AUX_HOST_GP_CNTRL_BIT_INIT_DONE); | ||
928 | |||
929 | /* wait for clock stabilization */ | ||
930 | for (i = 0; i < 10000; i++) { | ||
931 | udelay(IPW_WAIT_CLOCK_STABILIZATION_DELAY * 4); | ||
932 | |||
933 | /* check clock ready bit */ | ||
934 | read_register(priv->net_dev, IPW_REG_GP_CNTRL, &r); | ||
935 | if (r & IPW_AUX_HOST_GP_CNTRL_BIT_CLOCK_READY) | ||
936 | break; | ||
937 | } | ||
938 | |||
939 | if (i == 10000) | ||
940 | return -EIO; /* TODO: better error value */ | ||
941 | |||
942 | /* set D0 standby bit */ | ||
943 | read_register(priv->net_dev, IPW_REG_GP_CNTRL, &r); | ||
944 | write_register(priv->net_dev, IPW_REG_GP_CNTRL, | ||
945 | r | IPW_AUX_HOST_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY); | ||
946 | |||
947 | return 0; | ||
948 | } | ||
949 | |||
950 | /********************************************************************* | ||
951 | Procedure : ipw2100_download_firmware | ||
952 | Purpose : Initiaze adapter after power on. | ||
953 | The sequence is: | ||
954 | 1. assert s/w reset first! | ||
955 | 2. awake clocks & wait for clock stabilization | ||
956 | 3. hold ARC (don't ask me why...) | ||
957 | 4. load Dino ucode and reset/clock init again | ||
958 | 5. zero-out shared mem | ||
959 | 6. download f/w | ||
960 | *******************************************************************/ | ||
961 | static int ipw2100_download_firmware(struct ipw2100_priv *priv) | ||
962 | { | ||
963 | u32 address; | ||
964 | int err; | ||
965 | |||
966 | #ifndef CONFIG_PM | ||
967 | /* Fetch the firmware and microcode */ | ||
968 | struct ipw2100_fw ipw2100_firmware; | ||
969 | #endif | ||
970 | |||
971 | if (priv->fatal_error) { | ||
972 | IPW_DEBUG_ERROR("%s: ipw2100_download_firmware called after " | ||
973 | "fatal error %d. Interface must be brought down.\n", | ||
974 | priv->net_dev->name, priv->fatal_error); | ||
975 | return -EINVAL; | ||
976 | } | ||
977 | #ifdef CONFIG_PM | ||
978 | if (!ipw2100_firmware.version) { | ||
979 | err = ipw2100_get_firmware(priv, &ipw2100_firmware); | ||
980 | if (err) { | ||
981 | IPW_DEBUG_ERROR("%s: ipw2100_get_firmware failed: %d\n", | ||
982 | priv->net_dev->name, err); | ||
983 | priv->fatal_error = IPW2100_ERR_FW_LOAD; | ||
984 | goto fail; | ||
985 | } | ||
986 | } | ||
987 | #else | ||
988 | err = ipw2100_get_firmware(priv, &ipw2100_firmware); | ||
989 | if (err) { | ||
990 | IPW_DEBUG_ERROR("%s: ipw2100_get_firmware failed: %d\n", | ||
991 | priv->net_dev->name, err); | ||
992 | priv->fatal_error = IPW2100_ERR_FW_LOAD; | ||
993 | goto fail; | ||
994 | } | ||
995 | #endif | ||
996 | priv->firmware_version = ipw2100_firmware.version; | ||
997 | |||
998 | /* s/w reset and clock stabilization */ | ||
999 | err = sw_reset_and_clock(priv); | ||
1000 | if (err) { | ||
1001 | IPW_DEBUG_ERROR("%s: sw_reset_and_clock failed: %d\n", | ||
1002 | priv->net_dev->name, err); | ||
1003 | goto fail; | ||
1004 | } | ||
1005 | |||
1006 | err = ipw2100_verify(priv); | ||
1007 | if (err) { | ||
1008 | IPW_DEBUG_ERROR("%s: ipw2100_verify failed: %d\n", | ||
1009 | priv->net_dev->name, err); | ||
1010 | goto fail; | ||
1011 | } | ||
1012 | |||
1013 | /* Hold ARC */ | ||
1014 | write_nic_dword(priv->net_dev, | ||
1015 | IPW_INTERNAL_REGISTER_HALT_AND_RESET, 0x80000000); | ||
1016 | |||
1017 | /* allow ARC to run */ | ||
1018 | write_register(priv->net_dev, IPW_REG_RESET_REG, 0); | ||
1019 | |||
1020 | /* load microcode */ | ||
1021 | err = ipw2100_ucode_download(priv, &ipw2100_firmware); | ||
1022 | if (err) { | ||
1023 | printk(KERN_ERR DRV_NAME ": %s: Error loading microcode: %d\n", | ||
1024 | priv->net_dev->name, err); | ||
1025 | goto fail; | ||
1026 | } | ||
1027 | |||
1028 | /* release ARC */ | ||
1029 | write_nic_dword(priv->net_dev, | ||
1030 | IPW_INTERNAL_REGISTER_HALT_AND_RESET, 0x00000000); | ||
1031 | |||
1032 | /* s/w reset and clock stabilization (again!!!) */ | ||
1033 | err = sw_reset_and_clock(priv); | ||
1034 | if (err) { | ||
1035 | printk(KERN_ERR DRV_NAME | ||
1036 | ": %s: sw_reset_and_clock failed: %d\n", | ||
1037 | priv->net_dev->name, err); | ||
1038 | goto fail; | ||
1039 | } | ||
1040 | |||
1041 | /* load f/w */ | ||
1042 | err = ipw2100_fw_download(priv, &ipw2100_firmware); | ||
1043 | if (err) { | ||
1044 | IPW_DEBUG_ERROR("%s: Error loading firmware: %d\n", | ||
1045 | priv->net_dev->name, err); | ||
1046 | goto fail; | ||
1047 | } | ||
1048 | #ifndef CONFIG_PM | ||
1049 | /* | ||
1050 | * When the .resume method of the driver is called, the other | ||
1051 | * part of the system, i.e. the ide driver could still stay in | ||
1052 | * the suspend stage. This prevents us from loading the firmware | ||
1053 | * from the disk. --YZ | ||
1054 | */ | ||
1055 | |||
1056 | /* free any storage allocated for firmware image */ | ||
1057 | ipw2100_release_firmware(priv, &ipw2100_firmware); | ||
1058 | #endif | ||
1059 | |||
1060 | /* zero out Domain 1 area indirectly (Si requirement) */ | ||
1061 | for (address = IPW_HOST_FW_SHARED_AREA0; | ||
1062 | address < IPW_HOST_FW_SHARED_AREA0_END; address += 4) | ||
1063 | write_nic_dword(priv->net_dev, address, 0); | ||
1064 | for (address = IPW_HOST_FW_SHARED_AREA1; | ||
1065 | address < IPW_HOST_FW_SHARED_AREA1_END; address += 4) | ||
1066 | write_nic_dword(priv->net_dev, address, 0); | ||
1067 | for (address = IPW_HOST_FW_SHARED_AREA2; | ||
1068 | address < IPW_HOST_FW_SHARED_AREA2_END; address += 4) | ||
1069 | write_nic_dword(priv->net_dev, address, 0); | ||
1070 | for (address = IPW_HOST_FW_SHARED_AREA3; | ||
1071 | address < IPW_HOST_FW_SHARED_AREA3_END; address += 4) | ||
1072 | write_nic_dword(priv->net_dev, address, 0); | ||
1073 | for (address = IPW_HOST_FW_INTERRUPT_AREA; | ||
1074 | address < IPW_HOST_FW_INTERRUPT_AREA_END; address += 4) | ||
1075 | write_nic_dword(priv->net_dev, address, 0); | ||
1076 | |||
1077 | return 0; | ||
1078 | |||
1079 | fail: | ||
1080 | ipw2100_release_firmware(priv, &ipw2100_firmware); | ||
1081 | return err; | ||
1082 | } | ||
1083 | |||
1084 | static inline void ipw2100_enable_interrupts(struct ipw2100_priv *priv) | ||
1085 | { | ||
1086 | if (priv->status & STATUS_INT_ENABLED) | ||
1087 | return; | ||
1088 | priv->status |= STATUS_INT_ENABLED; | ||
1089 | write_register(priv->net_dev, IPW_REG_INTA_MASK, IPW_INTERRUPT_MASK); | ||
1090 | } | ||
1091 | |||
1092 | static inline void ipw2100_disable_interrupts(struct ipw2100_priv *priv) | ||
1093 | { | ||
1094 | if (!(priv->status & STATUS_INT_ENABLED)) | ||
1095 | return; | ||
1096 | priv->status &= ~STATUS_INT_ENABLED; | ||
1097 | write_register(priv->net_dev, IPW_REG_INTA_MASK, 0x0); | ||
1098 | } | ||
1099 | |||
1100 | static void ipw2100_initialize_ordinals(struct ipw2100_priv *priv) | ||
1101 | { | ||
1102 | struct ipw2100_ordinals *ord = &priv->ordinals; | ||
1103 | |||
1104 | IPW_DEBUG_INFO("enter\n"); | ||
1105 | |||
1106 | read_register(priv->net_dev, IPW_MEM_HOST_SHARED_ORDINALS_TABLE_1, | ||
1107 | &ord->table1_addr); | ||
1108 | |||
1109 | read_register(priv->net_dev, IPW_MEM_HOST_SHARED_ORDINALS_TABLE_2, | ||
1110 | &ord->table2_addr); | ||
1111 | |||
1112 | read_nic_dword(priv->net_dev, ord->table1_addr, &ord->table1_size); | ||
1113 | read_nic_dword(priv->net_dev, ord->table2_addr, &ord->table2_size); | ||
1114 | |||
1115 | ord->table2_size &= 0x0000FFFF; | ||
1116 | |||
1117 | IPW_DEBUG_INFO("table 1 size: %d\n", ord->table1_size); | ||
1118 | IPW_DEBUG_INFO("table 2 size: %d\n", ord->table2_size); | ||
1119 | IPW_DEBUG_INFO("exit\n"); | ||
1120 | } | ||
1121 | |||
1122 | static inline void ipw2100_hw_set_gpio(struct ipw2100_priv *priv) | ||
1123 | { | ||
1124 | u32 reg = 0; | ||
1125 | /* | ||
1126 | * Set GPIO 3 writable by FW; GPIO 1 writable | ||
1127 | * by driver and enable clock | ||
1128 | */ | ||
1129 | reg = (IPW_BIT_GPIO_GPIO3_MASK | IPW_BIT_GPIO_GPIO1_ENABLE | | ||
1130 | IPW_BIT_GPIO_LED_OFF); | ||
1131 | write_register(priv->net_dev, IPW_REG_GPIO, reg); | ||
1132 | } | ||
1133 | |||
1134 | static int rf_kill_active(struct ipw2100_priv *priv) | ||
1135 | { | ||
1136 | #define MAX_RF_KILL_CHECKS 5 | ||
1137 | #define RF_KILL_CHECK_DELAY 40 | ||
1138 | |||
1139 | unsigned short value = 0; | ||
1140 | u32 reg = 0; | ||
1141 | int i; | ||
1142 | |||
1143 | if (!(priv->hw_features & HW_FEATURE_RFKILL)) { | ||
1144 | priv->status &= ~STATUS_RF_KILL_HW; | ||
1145 | return 0; | ||
1146 | } | ||
1147 | |||
1148 | for (i = 0; i < MAX_RF_KILL_CHECKS; i++) { | ||
1149 | udelay(RF_KILL_CHECK_DELAY); | ||
1150 | read_register(priv->net_dev, IPW_REG_GPIO, ®); | ||
1151 | value = (value << 1) | ((reg & IPW_BIT_GPIO_RF_KILL) ? 0 : 1); | ||
1152 | } | ||
1153 | |||
1154 | if (value == 0) | ||
1155 | priv->status |= STATUS_RF_KILL_HW; | ||
1156 | else | ||
1157 | priv->status &= ~STATUS_RF_KILL_HW; | ||
1158 | |||
1159 | return (value == 0); | ||
1160 | } | ||
1161 | |||
1162 | static int ipw2100_get_hw_features(struct ipw2100_priv *priv) | ||
1163 | { | ||
1164 | u32 addr, len; | ||
1165 | u32 val; | ||
1166 | |||
1167 | /* | ||
1168 | * EEPROM_SRAM_DB_START_ADDRESS using ordinal in ordinal table 1 | ||
1169 | */ | ||
1170 | len = sizeof(addr); | ||
1171 | if (ipw2100_get_ordinal | ||
1172 | (priv, IPW_ORD_EEPROM_SRAM_DB_BLOCK_START_ADDRESS, &addr, &len)) { | ||
1173 | IPW_DEBUG_INFO("failed querying ordinals at line %d\n", | ||
1174 | __LINE__); | ||
1175 | return -EIO; | ||
1176 | } | ||
1177 | |||
1178 | IPW_DEBUG_INFO("EEPROM address: %08X\n", addr); | ||
1179 | |||
1180 | /* | ||
1181 | * EEPROM version is the byte at offset 0xfd in firmware | ||
1182 | * We read 4 bytes, then shift out the byte we actually want */ | ||
1183 | read_nic_dword(priv->net_dev, addr + 0xFC, &val); | ||
1184 | priv->eeprom_version = (val >> 24) & 0xFF; | ||
1185 | IPW_DEBUG_INFO("EEPROM version: %d\n", priv->eeprom_version); | ||
1186 | |||
1187 | /* | ||
1188 | * HW RF Kill enable is bit 0 in byte at offset 0x21 in firmware | ||
1189 | * | ||
1190 | * notice that the EEPROM bit is reverse polarity, i.e. | ||
1191 | * bit = 0 signifies HW RF kill switch is supported | ||
1192 | * bit = 1 signifies HW RF kill switch is NOT supported | ||
1193 | */ | ||
1194 | read_nic_dword(priv->net_dev, addr + 0x20, &val); | ||
1195 | if (!((val >> 24) & 0x01)) | ||
1196 | priv->hw_features |= HW_FEATURE_RFKILL; | ||
1197 | |||
1198 | IPW_DEBUG_INFO("HW RF Kill: %ssupported.\n", | ||
1199 | (priv->hw_features & HW_FEATURE_RFKILL) ? "" : "not "); | ||
1200 | |||
1201 | return 0; | ||
1202 | } | ||
1203 | |||
1204 | /* | ||
1205 | * Start firmware execution after power on and intialization | ||
1206 | * The sequence is: | ||
1207 | * 1. Release ARC | ||
1208 | * 2. Wait for f/w initialization completes; | ||
1209 | */ | ||
1210 | static int ipw2100_start_adapter(struct ipw2100_priv *priv) | ||
1211 | { | ||
1212 | int i; | ||
1213 | u32 inta, inta_mask, gpio; | ||
1214 | |||
1215 | IPW_DEBUG_INFO("enter\n"); | ||
1216 | |||
1217 | if (priv->status & STATUS_RUNNING) | ||
1218 | return 0; | ||
1219 | |||
1220 | /* | ||
1221 | * Initialize the hw - drive adapter to DO state by setting | ||
1222 | * init_done bit. Wait for clk_ready bit and Download | ||
1223 | * fw & dino ucode | ||
1224 | */ | ||
1225 | if (ipw2100_download_firmware(priv)) { | ||
1226 | printk(KERN_ERR DRV_NAME | ||
1227 | ": %s: Failed to power on the adapter.\n", | ||
1228 | priv->net_dev->name); | ||
1229 | return -EIO; | ||
1230 | } | ||
1231 | |||
1232 | /* Clear the Tx, Rx and Msg queues and the r/w indexes | ||
1233 | * in the firmware RBD and TBD ring queue */ | ||
1234 | ipw2100_queues_initialize(priv); | ||
1235 | |||
1236 | ipw2100_hw_set_gpio(priv); | ||
1237 | |||
1238 | /* TODO -- Look at disabling interrupts here to make sure none | ||
1239 | * get fired during FW initialization */ | ||
1240 | |||
1241 | /* Release ARC - clear reset bit */ | ||
1242 | write_register(priv->net_dev, IPW_REG_RESET_REG, 0); | ||
1243 | |||
1244 | /* wait for f/w intialization complete */ | ||
1245 | IPW_DEBUG_FW("Waiting for f/w initialization to complete...\n"); | ||
1246 | i = 5000; | ||
1247 | do { | ||
1248 | schedule_timeout_uninterruptible(msecs_to_jiffies(40)); | ||
1249 | /* Todo... wait for sync command ... */ | ||
1250 | |||
1251 | read_register(priv->net_dev, IPW_REG_INTA, &inta); | ||
1252 | |||
1253 | /* check "init done" bit */ | ||
1254 | if (inta & IPW2100_INTA_FW_INIT_DONE) { | ||
1255 | /* reset "init done" bit */ | ||
1256 | write_register(priv->net_dev, IPW_REG_INTA, | ||
1257 | IPW2100_INTA_FW_INIT_DONE); | ||
1258 | break; | ||
1259 | } | ||
1260 | |||
1261 | /* check error conditions : we check these after the firmware | ||
1262 | * check so that if there is an error, the interrupt handler | ||
1263 | * will see it and the adapter will be reset */ | ||
1264 | if (inta & | ||
1265 | (IPW2100_INTA_FATAL_ERROR | IPW2100_INTA_PARITY_ERROR)) { | ||
1266 | /* clear error conditions */ | ||
1267 | write_register(priv->net_dev, IPW_REG_INTA, | ||
1268 | IPW2100_INTA_FATAL_ERROR | | ||
1269 | IPW2100_INTA_PARITY_ERROR); | ||
1270 | } | ||
1271 | } while (--i); | ||
1272 | |||
1273 | /* Clear out any pending INTAs since we aren't supposed to have | ||
1274 | * interrupts enabled at this point... */ | ||
1275 | read_register(priv->net_dev, IPW_REG_INTA, &inta); | ||
1276 | read_register(priv->net_dev, IPW_REG_INTA_MASK, &inta_mask); | ||
1277 | inta &= IPW_INTERRUPT_MASK; | ||
1278 | /* Clear out any pending interrupts */ | ||
1279 | if (inta & inta_mask) | ||
1280 | write_register(priv->net_dev, IPW_REG_INTA, inta); | ||
1281 | |||
1282 | IPW_DEBUG_FW("f/w initialization complete: %s\n", | ||
1283 | i ? "SUCCESS" : "FAILED"); | ||
1284 | |||
1285 | if (!i) { | ||
1286 | printk(KERN_WARNING DRV_NAME | ||
1287 | ": %s: Firmware did not initialize.\n", | ||
1288 | priv->net_dev->name); | ||
1289 | return -EIO; | ||
1290 | } | ||
1291 | |||
1292 | /* allow firmware to write to GPIO1 & GPIO3 */ | ||
1293 | read_register(priv->net_dev, IPW_REG_GPIO, &gpio); | ||
1294 | |||
1295 | gpio |= (IPW_BIT_GPIO_GPIO1_MASK | IPW_BIT_GPIO_GPIO3_MASK); | ||
1296 | |||
1297 | write_register(priv->net_dev, IPW_REG_GPIO, gpio); | ||
1298 | |||
1299 | /* Ready to receive commands */ | ||
1300 | priv->status |= STATUS_RUNNING; | ||
1301 | |||
1302 | /* The adapter has been reset; we are not associated */ | ||
1303 | priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED); | ||
1304 | |||
1305 | IPW_DEBUG_INFO("exit\n"); | ||
1306 | |||
1307 | return 0; | ||
1308 | } | ||
1309 | |||
1310 | static inline void ipw2100_reset_fatalerror(struct ipw2100_priv *priv) | ||
1311 | { | ||
1312 | if (!priv->fatal_error) | ||
1313 | return; | ||
1314 | |||
1315 | priv->fatal_errors[priv->fatal_index++] = priv->fatal_error; | ||
1316 | priv->fatal_index %= IPW2100_ERROR_QUEUE; | ||
1317 | priv->fatal_error = 0; | ||
1318 | } | ||
1319 | |||
1320 | /* NOTE: Our interrupt is disabled when this method is called */ | ||
1321 | static int ipw2100_power_cycle_adapter(struct ipw2100_priv *priv) | ||
1322 | { | ||
1323 | u32 reg; | ||
1324 | int i; | ||
1325 | |||
1326 | IPW_DEBUG_INFO("Power cycling the hardware.\n"); | ||
1327 | |||
1328 | ipw2100_hw_set_gpio(priv); | ||
1329 | |||
1330 | /* Step 1. Stop Master Assert */ | ||
1331 | write_register(priv->net_dev, IPW_REG_RESET_REG, | ||
1332 | IPW_AUX_HOST_RESET_REG_STOP_MASTER); | ||
1333 | |||
1334 | /* Step 2. Wait for stop Master Assert | ||
1335 | * (not more then 50us, otherwise ret error */ | ||
1336 | i = 5; | ||
1337 | do { | ||
1338 | udelay(IPW_WAIT_RESET_MASTER_ASSERT_COMPLETE_DELAY); | ||
1339 | read_register(priv->net_dev, IPW_REG_RESET_REG, ®); | ||
1340 | |||
1341 | if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED) | ||
1342 | break; | ||
1343 | } while (--i); | ||
1344 | |||
1345 | priv->status &= ~STATUS_RESET_PENDING; | ||
1346 | |||
1347 | if (!i) { | ||
1348 | IPW_DEBUG_INFO | ||
1349 | ("exit - waited too long for master assert stop\n"); | ||
1350 | return -EIO; | ||
1351 | } | ||
1352 | |||
1353 | write_register(priv->net_dev, IPW_REG_RESET_REG, | ||
1354 | IPW_AUX_HOST_RESET_REG_SW_RESET); | ||
1355 | |||
1356 | /* Reset any fatal_error conditions */ | ||
1357 | ipw2100_reset_fatalerror(priv); | ||
1358 | |||
1359 | /* At this point, the adapter is now stopped and disabled */ | ||
1360 | priv->status &= ~(STATUS_RUNNING | STATUS_ASSOCIATING | | ||
1361 | STATUS_ASSOCIATED | STATUS_ENABLED); | ||
1362 | |||
1363 | return 0; | ||
1364 | } | ||
1365 | |||
1366 | /* | ||
1367 | * Send the CARD_DISABLE_PHY_OFF comamnd to the card to disable it | ||
1368 | * | ||
1369 | * After disabling, if the card was associated, a STATUS_ASSN_LOST will be sent. | ||
1370 | * | ||
1371 | * STATUS_CARD_DISABLE_NOTIFICATION will be sent regardless of | ||
1372 | * if STATUS_ASSN_LOST is sent. | ||
1373 | */ | ||
1374 | static int ipw2100_hw_phy_off(struct ipw2100_priv *priv) | ||
1375 | { | ||
1376 | |||
1377 | #define HW_PHY_OFF_LOOP_DELAY (HZ / 5000) | ||
1378 | |||
1379 | struct host_command cmd = { | ||
1380 | .host_command = CARD_DISABLE_PHY_OFF, | ||
1381 | .host_command_sequence = 0, | ||
1382 | .host_command_length = 0, | ||
1383 | }; | ||
1384 | int err, i; | ||
1385 | u32 val1, val2; | ||
1386 | |||
1387 | IPW_DEBUG_HC("CARD_DISABLE_PHY_OFF\n"); | ||
1388 | |||
1389 | /* Turn off the radio */ | ||
1390 | err = ipw2100_hw_send_command(priv, &cmd); | ||
1391 | if (err) | ||
1392 | return err; | ||
1393 | |||
1394 | for (i = 0; i < 2500; i++) { | ||
1395 | read_nic_dword(priv->net_dev, IPW2100_CONTROL_REG, &val1); | ||
1396 | read_nic_dword(priv->net_dev, IPW2100_COMMAND, &val2); | ||
1397 | |||
1398 | if ((val1 & IPW2100_CONTROL_PHY_OFF) && | ||
1399 | (val2 & IPW2100_COMMAND_PHY_OFF)) | ||
1400 | return 0; | ||
1401 | |||
1402 | schedule_timeout_uninterruptible(HW_PHY_OFF_LOOP_DELAY); | ||
1403 | } | ||
1404 | |||
1405 | return -EIO; | ||
1406 | } | ||
1407 | |||
1408 | static int ipw2100_enable_adapter(struct ipw2100_priv *priv) | ||
1409 | { | ||
1410 | struct host_command cmd = { | ||
1411 | .host_command = HOST_COMPLETE, | ||
1412 | .host_command_sequence = 0, | ||
1413 | .host_command_length = 0 | ||
1414 | }; | ||
1415 | int err = 0; | ||
1416 | |||
1417 | IPW_DEBUG_HC("HOST_COMPLETE\n"); | ||
1418 | |||
1419 | if (priv->status & STATUS_ENABLED) | ||
1420 | return 0; | ||
1421 | |||
1422 | mutex_lock(&priv->adapter_mutex); | ||
1423 | |||
1424 | if (rf_kill_active(priv)) { | ||
1425 | IPW_DEBUG_HC("Command aborted due to RF kill active.\n"); | ||
1426 | goto fail_up; | ||
1427 | } | ||
1428 | |||
1429 | err = ipw2100_hw_send_command(priv, &cmd); | ||
1430 | if (err) { | ||
1431 | IPW_DEBUG_INFO("Failed to send HOST_COMPLETE command\n"); | ||
1432 | goto fail_up; | ||
1433 | } | ||
1434 | |||
1435 | err = ipw2100_wait_for_card_state(priv, IPW_HW_STATE_ENABLED); | ||
1436 | if (err) { | ||
1437 | IPW_DEBUG_INFO("%s: card not responding to init command.\n", | ||
1438 | priv->net_dev->name); | ||
1439 | goto fail_up; | ||
1440 | } | ||
1441 | |||
1442 | if (priv->stop_hang_check) { | ||
1443 | priv->stop_hang_check = 0; | ||
1444 | queue_delayed_work(priv->workqueue, &priv->hang_check, HZ / 2); | ||
1445 | } | ||
1446 | |||
1447 | fail_up: | ||
1448 | mutex_unlock(&priv->adapter_mutex); | ||
1449 | return err; | ||
1450 | } | ||
1451 | |||
1452 | static int ipw2100_hw_stop_adapter(struct ipw2100_priv *priv) | ||
1453 | { | ||
1454 | #define HW_POWER_DOWN_DELAY (msecs_to_jiffies(100)) | ||
1455 | |||
1456 | struct host_command cmd = { | ||
1457 | .host_command = HOST_PRE_POWER_DOWN, | ||
1458 | .host_command_sequence = 0, | ||
1459 | .host_command_length = 0, | ||
1460 | }; | ||
1461 | int err, i; | ||
1462 | u32 reg; | ||
1463 | |||
1464 | if (!(priv->status & STATUS_RUNNING)) | ||
1465 | return 0; | ||
1466 | |||
1467 | priv->status |= STATUS_STOPPING; | ||
1468 | |||
1469 | /* We can only shut down the card if the firmware is operational. So, | ||
1470 | * if we haven't reset since a fatal_error, then we can not send the | ||
1471 | * shutdown commands. */ | ||
1472 | if (!priv->fatal_error) { | ||
1473 | /* First, make sure the adapter is enabled so that the PHY_OFF | ||
1474 | * command can shut it down */ | ||
1475 | ipw2100_enable_adapter(priv); | ||
1476 | |||
1477 | err = ipw2100_hw_phy_off(priv); | ||
1478 | if (err) | ||
1479 | printk(KERN_WARNING DRV_NAME | ||
1480 | ": Error disabling radio %d\n", err); | ||
1481 | |||
1482 | /* | ||
1483 | * If in D0-standby mode going directly to D3 may cause a | ||
1484 | * PCI bus violation. Therefore we must change out of the D0 | ||
1485 | * state. | ||
1486 | * | ||
1487 | * Sending the PREPARE_FOR_POWER_DOWN will restrict the | ||
1488 | * hardware from going into standby mode and will transition | ||
1489 | * out of D0-standby if it is already in that state. | ||
1490 | * | ||
1491 | * STATUS_PREPARE_POWER_DOWN_COMPLETE will be sent by the | ||
1492 | * driver upon completion. Once received, the driver can | ||
1493 | * proceed to the D3 state. | ||
1494 | * | ||
1495 | * Prepare for power down command to fw. This command would | ||
1496 | * take HW out of D0-standby and prepare it for D3 state. | ||
1497 | * | ||
1498 | * Currently FW does not support event notification for this | ||
1499 | * event. Therefore, skip waiting for it. Just wait a fixed | ||
1500 | * 100ms | ||
1501 | */ | ||
1502 | IPW_DEBUG_HC("HOST_PRE_POWER_DOWN\n"); | ||
1503 | |||
1504 | err = ipw2100_hw_send_command(priv, &cmd); | ||
1505 | if (err) | ||
1506 | printk(KERN_WARNING DRV_NAME ": " | ||
1507 | "%s: Power down command failed: Error %d\n", | ||
1508 | priv->net_dev->name, err); | ||
1509 | else | ||
1510 | schedule_timeout_uninterruptible(HW_POWER_DOWN_DELAY); | ||
1511 | } | ||
1512 | |||
1513 | priv->status &= ~STATUS_ENABLED; | ||
1514 | |||
1515 | /* | ||
1516 | * Set GPIO 3 writable by FW; GPIO 1 writable | ||
1517 | * by driver and enable clock | ||
1518 | */ | ||
1519 | ipw2100_hw_set_gpio(priv); | ||
1520 | |||
1521 | /* | ||
1522 | * Power down adapter. Sequence: | ||
1523 | * 1. Stop master assert (RESET_REG[9]=1) | ||
1524 | * 2. Wait for stop master (RESET_REG[8]==1) | ||
1525 | * 3. S/w reset assert (RESET_REG[7] = 1) | ||
1526 | */ | ||
1527 | |||
1528 | /* Stop master assert */ | ||
1529 | write_register(priv->net_dev, IPW_REG_RESET_REG, | ||
1530 | IPW_AUX_HOST_RESET_REG_STOP_MASTER); | ||
1531 | |||
1532 | /* wait stop master not more than 50 usec. | ||
1533 | * Otherwise return error. */ | ||
1534 | for (i = 5; i > 0; i--) { | ||
1535 | udelay(10); | ||
1536 | |||
1537 | /* Check master stop bit */ | ||
1538 | read_register(priv->net_dev, IPW_REG_RESET_REG, ®); | ||
1539 | |||
1540 | if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED) | ||
1541 | break; | ||
1542 | } | ||
1543 | |||
1544 | if (i == 0) | ||
1545 | printk(KERN_WARNING DRV_NAME | ||
1546 | ": %s: Could now power down adapter.\n", | ||
1547 | priv->net_dev->name); | ||
1548 | |||
1549 | /* assert s/w reset */ | ||
1550 | write_register(priv->net_dev, IPW_REG_RESET_REG, | ||
1551 | IPW_AUX_HOST_RESET_REG_SW_RESET); | ||
1552 | |||
1553 | priv->status &= ~(STATUS_RUNNING | STATUS_STOPPING); | ||
1554 | |||
1555 | return 0; | ||
1556 | } | ||
1557 | |||
1558 | static int ipw2100_disable_adapter(struct ipw2100_priv *priv) | ||
1559 | { | ||
1560 | struct host_command cmd = { | ||
1561 | .host_command = CARD_DISABLE, | ||
1562 | .host_command_sequence = 0, | ||
1563 | .host_command_length = 0 | ||
1564 | }; | ||
1565 | int err = 0; | ||
1566 | |||
1567 | IPW_DEBUG_HC("CARD_DISABLE\n"); | ||
1568 | |||
1569 | if (!(priv->status & STATUS_ENABLED)) | ||
1570 | return 0; | ||
1571 | |||
1572 | /* Make sure we clear the associated state */ | ||
1573 | priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING); | ||
1574 | |||
1575 | if (!priv->stop_hang_check) { | ||
1576 | priv->stop_hang_check = 1; | ||
1577 | cancel_delayed_work(&priv->hang_check); | ||
1578 | } | ||
1579 | |||
1580 | mutex_lock(&priv->adapter_mutex); | ||
1581 | |||
1582 | err = ipw2100_hw_send_command(priv, &cmd); | ||
1583 | if (err) { | ||
1584 | printk(KERN_WARNING DRV_NAME | ||
1585 | ": exit - failed to send CARD_DISABLE command\n"); | ||
1586 | goto fail_up; | ||
1587 | } | ||
1588 | |||
1589 | err = ipw2100_wait_for_card_state(priv, IPW_HW_STATE_DISABLED); | ||
1590 | if (err) { | ||
1591 | printk(KERN_WARNING DRV_NAME | ||
1592 | ": exit - card failed to change to DISABLED\n"); | ||
1593 | goto fail_up; | ||
1594 | } | ||
1595 | |||
1596 | IPW_DEBUG_INFO("TODO: implement scan state machine\n"); | ||
1597 | |||
1598 | fail_up: | ||
1599 | mutex_unlock(&priv->adapter_mutex); | ||
1600 | return err; | ||
1601 | } | ||
1602 | |||
1603 | static int ipw2100_set_scan_options(struct ipw2100_priv *priv) | ||
1604 | { | ||
1605 | struct host_command cmd = { | ||
1606 | .host_command = SET_SCAN_OPTIONS, | ||
1607 | .host_command_sequence = 0, | ||
1608 | .host_command_length = 8 | ||
1609 | }; | ||
1610 | int err; | ||
1611 | |||
1612 | IPW_DEBUG_INFO("enter\n"); | ||
1613 | |||
1614 | IPW_DEBUG_SCAN("setting scan options\n"); | ||
1615 | |||
1616 | cmd.host_command_parameters[0] = 0; | ||
1617 | |||
1618 | if (!(priv->config & CFG_ASSOCIATE)) | ||
1619 | cmd.host_command_parameters[0] |= IPW_SCAN_NOASSOCIATE; | ||
1620 | if ((priv->ieee->sec.flags & SEC_ENABLED) && priv->ieee->sec.enabled) | ||
1621 | cmd.host_command_parameters[0] |= IPW_SCAN_MIXED_CELL; | ||
1622 | if (priv->config & CFG_PASSIVE_SCAN) | ||
1623 | cmd.host_command_parameters[0] |= IPW_SCAN_PASSIVE; | ||
1624 | |||
1625 | cmd.host_command_parameters[1] = priv->channel_mask; | ||
1626 | |||
1627 | err = ipw2100_hw_send_command(priv, &cmd); | ||
1628 | |||
1629 | IPW_DEBUG_HC("SET_SCAN_OPTIONS 0x%04X\n", | ||
1630 | cmd.host_command_parameters[0]); | ||
1631 | |||
1632 | return err; | ||
1633 | } | ||
1634 | |||
1635 | static int ipw2100_start_scan(struct ipw2100_priv *priv) | ||
1636 | { | ||
1637 | struct host_command cmd = { | ||
1638 | .host_command = BROADCAST_SCAN, | ||
1639 | .host_command_sequence = 0, | ||
1640 | .host_command_length = 4 | ||
1641 | }; | ||
1642 | int err; | ||
1643 | |||
1644 | IPW_DEBUG_HC("START_SCAN\n"); | ||
1645 | |||
1646 | cmd.host_command_parameters[0] = 0; | ||
1647 | |||
1648 | /* No scanning if in monitor mode */ | ||
1649 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) | ||
1650 | return 1; | ||
1651 | |||
1652 | if (priv->status & STATUS_SCANNING) { | ||
1653 | IPW_DEBUG_SCAN("Scan requested while already in scan...\n"); | ||
1654 | return 0; | ||
1655 | } | ||
1656 | |||
1657 | IPW_DEBUG_INFO("enter\n"); | ||
1658 | |||
1659 | /* Not clearing here; doing so makes iwlist always return nothing... | ||
1660 | * | ||
1661 | * We should modify the table logic to use aging tables vs. clearing | ||
1662 | * the table on each scan start. | ||
1663 | */ | ||
1664 | IPW_DEBUG_SCAN("starting scan\n"); | ||
1665 | |||
1666 | priv->status |= STATUS_SCANNING; | ||
1667 | err = ipw2100_hw_send_command(priv, &cmd); | ||
1668 | if (err) | ||
1669 | priv->status &= ~STATUS_SCANNING; | ||
1670 | |||
1671 | IPW_DEBUG_INFO("exit\n"); | ||
1672 | |||
1673 | return err; | ||
1674 | } | ||
1675 | |||
1676 | static const struct ieee80211_geo ipw_geos[] = { | ||
1677 | { /* Restricted */ | ||
1678 | "---", | ||
1679 | .bg_channels = 14, | ||
1680 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | ||
1681 | {2427, 4}, {2432, 5}, {2437, 6}, | ||
1682 | {2442, 7}, {2447, 8}, {2452, 9}, | ||
1683 | {2457, 10}, {2462, 11}, {2467, 12}, | ||
1684 | {2472, 13}, {2484, 14}}, | ||
1685 | }, | ||
1686 | }; | ||
1687 | |||
1688 | static int ipw2100_up(struct ipw2100_priv *priv, int deferred) | ||
1689 | { | ||
1690 | unsigned long flags; | ||
1691 | int rc = 0; | ||
1692 | u32 lock; | ||
1693 | u32 ord_len = sizeof(lock); | ||
1694 | |||
1695 | /* Quite if manually disabled. */ | ||
1696 | if (priv->status & STATUS_RF_KILL_SW) { | ||
1697 | IPW_DEBUG_INFO("%s: Radio is disabled by Manual Disable " | ||
1698 | "switch\n", priv->net_dev->name); | ||
1699 | return 0; | ||
1700 | } | ||
1701 | |||
1702 | /* the ipw2100 hardware really doesn't want power management delays | ||
1703 | * longer than 175usec | ||
1704 | */ | ||
1705 | pm_qos_update_requirement(PM_QOS_CPU_DMA_LATENCY, "ipw2100", 175); | ||
1706 | |||
1707 | /* If the interrupt is enabled, turn it off... */ | ||
1708 | spin_lock_irqsave(&priv->low_lock, flags); | ||
1709 | ipw2100_disable_interrupts(priv); | ||
1710 | |||
1711 | /* Reset any fatal_error conditions */ | ||
1712 | ipw2100_reset_fatalerror(priv); | ||
1713 | spin_unlock_irqrestore(&priv->low_lock, flags); | ||
1714 | |||
1715 | if (priv->status & STATUS_POWERED || | ||
1716 | (priv->status & STATUS_RESET_PENDING)) { | ||
1717 | /* Power cycle the card ... */ | ||
1718 | if (ipw2100_power_cycle_adapter(priv)) { | ||
1719 | printk(KERN_WARNING DRV_NAME | ||
1720 | ": %s: Could not cycle adapter.\n", | ||
1721 | priv->net_dev->name); | ||
1722 | rc = 1; | ||
1723 | goto exit; | ||
1724 | } | ||
1725 | } else | ||
1726 | priv->status |= STATUS_POWERED; | ||
1727 | |||
1728 | /* Load the firmware, start the clocks, etc. */ | ||
1729 | if (ipw2100_start_adapter(priv)) { | ||
1730 | printk(KERN_ERR DRV_NAME | ||
1731 | ": %s: Failed to start the firmware.\n", | ||
1732 | priv->net_dev->name); | ||
1733 | rc = 1; | ||
1734 | goto exit; | ||
1735 | } | ||
1736 | |||
1737 | ipw2100_initialize_ordinals(priv); | ||
1738 | |||
1739 | /* Determine capabilities of this particular HW configuration */ | ||
1740 | if (ipw2100_get_hw_features(priv)) { | ||
1741 | printk(KERN_ERR DRV_NAME | ||
1742 | ": %s: Failed to determine HW features.\n", | ||
1743 | priv->net_dev->name); | ||
1744 | rc = 1; | ||
1745 | goto exit; | ||
1746 | } | ||
1747 | |||
1748 | /* Initialize the geo */ | ||
1749 | if (ieee80211_set_geo(priv->ieee, &ipw_geos[0])) { | ||
1750 | printk(KERN_WARNING DRV_NAME "Could not set geo\n"); | ||
1751 | return 0; | ||
1752 | } | ||
1753 | priv->ieee->freq_band = IEEE80211_24GHZ_BAND; | ||
1754 | |||
1755 | lock = LOCK_NONE; | ||
1756 | if (ipw2100_set_ordinal(priv, IPW_ORD_PERS_DB_LOCK, &lock, &ord_len)) { | ||
1757 | printk(KERN_ERR DRV_NAME | ||
1758 | ": %s: Failed to clear ordinal lock.\n", | ||
1759 | priv->net_dev->name); | ||
1760 | rc = 1; | ||
1761 | goto exit; | ||
1762 | } | ||
1763 | |||
1764 | priv->status &= ~STATUS_SCANNING; | ||
1765 | |||
1766 | if (rf_kill_active(priv)) { | ||
1767 | printk(KERN_INFO "%s: Radio is disabled by RF switch.\n", | ||
1768 | priv->net_dev->name); | ||
1769 | |||
1770 | if (priv->stop_rf_kill) { | ||
1771 | priv->stop_rf_kill = 0; | ||
1772 | queue_delayed_work(priv->workqueue, &priv->rf_kill, | ||
1773 | round_jiffies_relative(HZ)); | ||
1774 | } | ||
1775 | |||
1776 | deferred = 1; | ||
1777 | } | ||
1778 | |||
1779 | /* Turn on the interrupt so that commands can be processed */ | ||
1780 | ipw2100_enable_interrupts(priv); | ||
1781 | |||
1782 | /* Send all of the commands that must be sent prior to | ||
1783 | * HOST_COMPLETE */ | ||
1784 | if (ipw2100_adapter_setup(priv)) { | ||
1785 | printk(KERN_ERR DRV_NAME ": %s: Failed to start the card.\n", | ||
1786 | priv->net_dev->name); | ||
1787 | rc = 1; | ||
1788 | goto exit; | ||
1789 | } | ||
1790 | |||
1791 | if (!deferred) { | ||
1792 | /* Enable the adapter - sends HOST_COMPLETE */ | ||
1793 | if (ipw2100_enable_adapter(priv)) { | ||
1794 | printk(KERN_ERR DRV_NAME ": " | ||
1795 | "%s: failed in call to enable adapter.\n", | ||
1796 | priv->net_dev->name); | ||
1797 | ipw2100_hw_stop_adapter(priv); | ||
1798 | rc = 1; | ||
1799 | goto exit; | ||
1800 | } | ||
1801 | |||
1802 | /* Start a scan . . . */ | ||
1803 | ipw2100_set_scan_options(priv); | ||
1804 | ipw2100_start_scan(priv); | ||
1805 | } | ||
1806 | |||
1807 | exit: | ||
1808 | return rc; | ||
1809 | } | ||
1810 | |||
1811 | /* Called by register_netdev() */ | ||
1812 | static int ipw2100_net_init(struct net_device *dev) | ||
1813 | { | ||
1814 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
1815 | return ipw2100_up(priv, 1); | ||
1816 | } | ||
1817 | |||
1818 | static void ipw2100_down(struct ipw2100_priv *priv) | ||
1819 | { | ||
1820 | unsigned long flags; | ||
1821 | union iwreq_data wrqu = { | ||
1822 | .ap_addr = { | ||
1823 | .sa_family = ARPHRD_ETHER} | ||
1824 | }; | ||
1825 | int associated = priv->status & STATUS_ASSOCIATED; | ||
1826 | |||
1827 | /* Kill the RF switch timer */ | ||
1828 | if (!priv->stop_rf_kill) { | ||
1829 | priv->stop_rf_kill = 1; | ||
1830 | cancel_delayed_work(&priv->rf_kill); | ||
1831 | } | ||
1832 | |||
1833 | /* Kill the firmare hang check timer */ | ||
1834 | if (!priv->stop_hang_check) { | ||
1835 | priv->stop_hang_check = 1; | ||
1836 | cancel_delayed_work(&priv->hang_check); | ||
1837 | } | ||
1838 | |||
1839 | /* Kill any pending resets */ | ||
1840 | if (priv->status & STATUS_RESET_PENDING) | ||
1841 | cancel_delayed_work(&priv->reset_work); | ||
1842 | |||
1843 | /* Make sure the interrupt is on so that FW commands will be | ||
1844 | * processed correctly */ | ||
1845 | spin_lock_irqsave(&priv->low_lock, flags); | ||
1846 | ipw2100_enable_interrupts(priv); | ||
1847 | spin_unlock_irqrestore(&priv->low_lock, flags); | ||
1848 | |||
1849 | if (ipw2100_hw_stop_adapter(priv)) | ||
1850 | printk(KERN_ERR DRV_NAME ": %s: Error stopping adapter.\n", | ||
1851 | priv->net_dev->name); | ||
1852 | |||
1853 | /* Do not disable the interrupt until _after_ we disable | ||
1854 | * the adaptor. Otherwise the CARD_DISABLE command will never | ||
1855 | * be ack'd by the firmware */ | ||
1856 | spin_lock_irqsave(&priv->low_lock, flags); | ||
1857 | ipw2100_disable_interrupts(priv); | ||
1858 | spin_unlock_irqrestore(&priv->low_lock, flags); | ||
1859 | |||
1860 | pm_qos_update_requirement(PM_QOS_CPU_DMA_LATENCY, "ipw2100", | ||
1861 | PM_QOS_DEFAULT_VALUE); | ||
1862 | |||
1863 | /* We have to signal any supplicant if we are disassociating */ | ||
1864 | if (associated) | ||
1865 | wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL); | ||
1866 | |||
1867 | priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING); | ||
1868 | netif_carrier_off(priv->net_dev); | ||
1869 | netif_stop_queue(priv->net_dev); | ||
1870 | } | ||
1871 | |||
1872 | static void ipw2100_reset_adapter(struct work_struct *work) | ||
1873 | { | ||
1874 | struct ipw2100_priv *priv = | ||
1875 | container_of(work, struct ipw2100_priv, reset_work.work); | ||
1876 | unsigned long flags; | ||
1877 | union iwreq_data wrqu = { | ||
1878 | .ap_addr = { | ||
1879 | .sa_family = ARPHRD_ETHER} | ||
1880 | }; | ||
1881 | int associated = priv->status & STATUS_ASSOCIATED; | ||
1882 | |||
1883 | spin_lock_irqsave(&priv->low_lock, flags); | ||
1884 | IPW_DEBUG_INFO(": %s: Restarting adapter.\n", priv->net_dev->name); | ||
1885 | priv->resets++; | ||
1886 | priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING); | ||
1887 | priv->status |= STATUS_SECURITY_UPDATED; | ||
1888 | |||
1889 | /* Force a power cycle even if interface hasn't been opened | ||
1890 | * yet */ | ||
1891 | cancel_delayed_work(&priv->reset_work); | ||
1892 | priv->status |= STATUS_RESET_PENDING; | ||
1893 | spin_unlock_irqrestore(&priv->low_lock, flags); | ||
1894 | |||
1895 | mutex_lock(&priv->action_mutex); | ||
1896 | /* stop timed checks so that they don't interfere with reset */ | ||
1897 | priv->stop_hang_check = 1; | ||
1898 | cancel_delayed_work(&priv->hang_check); | ||
1899 | |||
1900 | /* We have to signal any supplicant if we are disassociating */ | ||
1901 | if (associated) | ||
1902 | wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL); | ||
1903 | |||
1904 | ipw2100_up(priv, 0); | ||
1905 | mutex_unlock(&priv->action_mutex); | ||
1906 | |||
1907 | } | ||
1908 | |||
1909 | static void isr_indicate_associated(struct ipw2100_priv *priv, u32 status) | ||
1910 | { | ||
1911 | |||
1912 | #define MAC_ASSOCIATION_READ_DELAY (HZ) | ||
1913 | int ret, len, essid_len; | ||
1914 | char essid[IW_ESSID_MAX_SIZE]; | ||
1915 | u32 txrate; | ||
1916 | u32 chan; | ||
1917 | char *txratename; | ||
1918 | u8 bssid[ETH_ALEN]; | ||
1919 | DECLARE_SSID_BUF(ssid); | ||
1920 | |||
1921 | /* | ||
1922 | * TBD: BSSID is usually 00:00:00:00:00:00 here and not | ||
1923 | * an actual MAC of the AP. Seems like FW sets this | ||
1924 | * address too late. Read it later and expose through | ||
1925 | * /proc or schedule a later task to query and update | ||
1926 | */ | ||
1927 | |||
1928 | essid_len = IW_ESSID_MAX_SIZE; | ||
1929 | ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_SSID, | ||
1930 | essid, &essid_len); | ||
1931 | if (ret) { | ||
1932 | IPW_DEBUG_INFO("failed querying ordinals at line %d\n", | ||
1933 | __LINE__); | ||
1934 | return; | ||
1935 | } | ||
1936 | |||
1937 | len = sizeof(u32); | ||
1938 | ret = ipw2100_get_ordinal(priv, IPW_ORD_CURRENT_TX_RATE, &txrate, &len); | ||
1939 | if (ret) { | ||
1940 | IPW_DEBUG_INFO("failed querying ordinals at line %d\n", | ||
1941 | __LINE__); | ||
1942 | return; | ||
1943 | } | ||
1944 | |||
1945 | len = sizeof(u32); | ||
1946 | ret = ipw2100_get_ordinal(priv, IPW_ORD_OUR_FREQ, &chan, &len); | ||
1947 | if (ret) { | ||
1948 | IPW_DEBUG_INFO("failed querying ordinals at line %d\n", | ||
1949 | __LINE__); | ||
1950 | return; | ||
1951 | } | ||
1952 | len = ETH_ALEN; | ||
1953 | ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID, &bssid, &len); | ||
1954 | if (ret) { | ||
1955 | IPW_DEBUG_INFO("failed querying ordinals at line %d\n", | ||
1956 | __LINE__); | ||
1957 | return; | ||
1958 | } | ||
1959 | memcpy(priv->ieee->bssid, bssid, ETH_ALEN); | ||
1960 | |||
1961 | switch (txrate) { | ||
1962 | case TX_RATE_1_MBIT: | ||
1963 | txratename = "1Mbps"; | ||
1964 | break; | ||
1965 | case TX_RATE_2_MBIT: | ||
1966 | txratename = "2Mbsp"; | ||
1967 | break; | ||
1968 | case TX_RATE_5_5_MBIT: | ||
1969 | txratename = "5.5Mbps"; | ||
1970 | break; | ||
1971 | case TX_RATE_11_MBIT: | ||
1972 | txratename = "11Mbps"; | ||
1973 | break; | ||
1974 | default: | ||
1975 | IPW_DEBUG_INFO("Unknown rate: %d\n", txrate); | ||
1976 | txratename = "unknown rate"; | ||
1977 | break; | ||
1978 | } | ||
1979 | |||
1980 | IPW_DEBUG_INFO("%s: Associated with '%s' at %s, channel %d (BSSID=%pM)\n", | ||
1981 | priv->net_dev->name, print_ssid(ssid, essid, essid_len), | ||
1982 | txratename, chan, bssid); | ||
1983 | |||
1984 | /* now we copy read ssid into dev */ | ||
1985 | if (!(priv->config & CFG_STATIC_ESSID)) { | ||
1986 | priv->essid_len = min((u8) essid_len, (u8) IW_ESSID_MAX_SIZE); | ||
1987 | memcpy(priv->essid, essid, priv->essid_len); | ||
1988 | } | ||
1989 | priv->channel = chan; | ||
1990 | memcpy(priv->bssid, bssid, ETH_ALEN); | ||
1991 | |||
1992 | priv->status |= STATUS_ASSOCIATING; | ||
1993 | priv->connect_start = get_seconds(); | ||
1994 | |||
1995 | queue_delayed_work(priv->workqueue, &priv->wx_event_work, HZ / 10); | ||
1996 | } | ||
1997 | |||
1998 | static int ipw2100_set_essid(struct ipw2100_priv *priv, char *essid, | ||
1999 | int length, int batch_mode) | ||
2000 | { | ||
2001 | int ssid_len = min(length, IW_ESSID_MAX_SIZE); | ||
2002 | struct host_command cmd = { | ||
2003 | .host_command = SSID, | ||
2004 | .host_command_sequence = 0, | ||
2005 | .host_command_length = ssid_len | ||
2006 | }; | ||
2007 | int err; | ||
2008 | DECLARE_SSID_BUF(ssid); | ||
2009 | |||
2010 | IPW_DEBUG_HC("SSID: '%s'\n", print_ssid(ssid, essid, ssid_len)); | ||
2011 | |||
2012 | if (ssid_len) | ||
2013 | memcpy(cmd.host_command_parameters, essid, ssid_len); | ||
2014 | |||
2015 | if (!batch_mode) { | ||
2016 | err = ipw2100_disable_adapter(priv); | ||
2017 | if (err) | ||
2018 | return err; | ||
2019 | } | ||
2020 | |||
2021 | /* Bug in FW currently doesn't honor bit 0 in SET_SCAN_OPTIONS to | ||
2022 | * disable auto association -- so we cheat by setting a bogus SSID */ | ||
2023 | if (!ssid_len && !(priv->config & CFG_ASSOCIATE)) { | ||
2024 | int i; | ||
2025 | u8 *bogus = (u8 *) cmd.host_command_parameters; | ||
2026 | for (i = 0; i < IW_ESSID_MAX_SIZE; i++) | ||
2027 | bogus[i] = 0x18 + i; | ||
2028 | cmd.host_command_length = IW_ESSID_MAX_SIZE; | ||
2029 | } | ||
2030 | |||
2031 | /* NOTE: We always send the SSID command even if the provided ESSID is | ||
2032 | * the same as what we currently think is set. */ | ||
2033 | |||
2034 | err = ipw2100_hw_send_command(priv, &cmd); | ||
2035 | if (!err) { | ||
2036 | memset(priv->essid + ssid_len, 0, IW_ESSID_MAX_SIZE - ssid_len); | ||
2037 | memcpy(priv->essid, essid, ssid_len); | ||
2038 | priv->essid_len = ssid_len; | ||
2039 | } | ||
2040 | |||
2041 | if (!batch_mode) { | ||
2042 | if (ipw2100_enable_adapter(priv)) | ||
2043 | err = -EIO; | ||
2044 | } | ||
2045 | |||
2046 | return err; | ||
2047 | } | ||
2048 | |||
2049 | static void isr_indicate_association_lost(struct ipw2100_priv *priv, u32 status) | ||
2050 | { | ||
2051 | DECLARE_SSID_BUF(ssid); | ||
2052 | |||
2053 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | IPW_DL_ASSOC, | ||
2054 | "disassociated: '%s' %pM \n", | ||
2055 | print_ssid(ssid, priv->essid, priv->essid_len), | ||
2056 | priv->bssid); | ||
2057 | |||
2058 | priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING); | ||
2059 | |||
2060 | if (priv->status & STATUS_STOPPING) { | ||
2061 | IPW_DEBUG_INFO("Card is stopping itself, discard ASSN_LOST.\n"); | ||
2062 | return; | ||
2063 | } | ||
2064 | |||
2065 | memset(priv->bssid, 0, ETH_ALEN); | ||
2066 | memset(priv->ieee->bssid, 0, ETH_ALEN); | ||
2067 | |||
2068 | netif_carrier_off(priv->net_dev); | ||
2069 | netif_stop_queue(priv->net_dev); | ||
2070 | |||
2071 | if (!(priv->status & STATUS_RUNNING)) | ||
2072 | return; | ||
2073 | |||
2074 | if (priv->status & STATUS_SECURITY_UPDATED) | ||
2075 | queue_delayed_work(priv->workqueue, &priv->security_work, 0); | ||
2076 | |||
2077 | queue_delayed_work(priv->workqueue, &priv->wx_event_work, 0); | ||
2078 | } | ||
2079 | |||
2080 | static void isr_indicate_rf_kill(struct ipw2100_priv *priv, u32 status) | ||
2081 | { | ||
2082 | IPW_DEBUG_INFO("%s: RF Kill state changed to radio OFF.\n", | ||
2083 | priv->net_dev->name); | ||
2084 | |||
2085 | /* RF_KILL is now enabled (else we wouldn't be here) */ | ||
2086 | priv->status |= STATUS_RF_KILL_HW; | ||
2087 | |||
2088 | /* Make sure the RF Kill check timer is running */ | ||
2089 | priv->stop_rf_kill = 0; | ||
2090 | cancel_delayed_work(&priv->rf_kill); | ||
2091 | queue_delayed_work(priv->workqueue, &priv->rf_kill, | ||
2092 | round_jiffies_relative(HZ)); | ||
2093 | } | ||
2094 | |||
2095 | static void send_scan_event(void *data) | ||
2096 | { | ||
2097 | struct ipw2100_priv *priv = data; | ||
2098 | union iwreq_data wrqu; | ||
2099 | |||
2100 | wrqu.data.length = 0; | ||
2101 | wrqu.data.flags = 0; | ||
2102 | wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL); | ||
2103 | } | ||
2104 | |||
2105 | static void ipw2100_scan_event_later(struct work_struct *work) | ||
2106 | { | ||
2107 | send_scan_event(container_of(work, struct ipw2100_priv, | ||
2108 | scan_event_later.work)); | ||
2109 | } | ||
2110 | |||
2111 | static void ipw2100_scan_event_now(struct work_struct *work) | ||
2112 | { | ||
2113 | send_scan_event(container_of(work, struct ipw2100_priv, | ||
2114 | scan_event_now)); | ||
2115 | } | ||
2116 | |||
2117 | static void isr_scan_complete(struct ipw2100_priv *priv, u32 status) | ||
2118 | { | ||
2119 | IPW_DEBUG_SCAN("scan complete\n"); | ||
2120 | /* Age the scan results... */ | ||
2121 | priv->ieee->scans++; | ||
2122 | priv->status &= ~STATUS_SCANNING; | ||
2123 | |||
2124 | /* Only userspace-requested scan completion events go out immediately */ | ||
2125 | if (!priv->user_requested_scan) { | ||
2126 | if (!delayed_work_pending(&priv->scan_event_later)) | ||
2127 | queue_delayed_work(priv->workqueue, | ||
2128 | &priv->scan_event_later, | ||
2129 | round_jiffies_relative(msecs_to_jiffies(4000))); | ||
2130 | } else { | ||
2131 | priv->user_requested_scan = 0; | ||
2132 | cancel_delayed_work(&priv->scan_event_later); | ||
2133 | queue_work(priv->workqueue, &priv->scan_event_now); | ||
2134 | } | ||
2135 | } | ||
2136 | |||
2137 | #ifdef CONFIG_IPW2100_DEBUG | ||
2138 | #define IPW2100_HANDLER(v, f) { v, f, # v } | ||
2139 | struct ipw2100_status_indicator { | ||
2140 | int status; | ||
2141 | void (*cb) (struct ipw2100_priv * priv, u32 status); | ||
2142 | char *name; | ||
2143 | }; | ||
2144 | #else | ||
2145 | #define IPW2100_HANDLER(v, f) { v, f } | ||
2146 | struct ipw2100_status_indicator { | ||
2147 | int status; | ||
2148 | void (*cb) (struct ipw2100_priv * priv, u32 status); | ||
2149 | }; | ||
2150 | #endif /* CONFIG_IPW2100_DEBUG */ | ||
2151 | |||
2152 | static void isr_indicate_scanning(struct ipw2100_priv *priv, u32 status) | ||
2153 | { | ||
2154 | IPW_DEBUG_SCAN("Scanning...\n"); | ||
2155 | priv->status |= STATUS_SCANNING; | ||
2156 | } | ||
2157 | |||
2158 | static const struct ipw2100_status_indicator status_handlers[] = { | ||
2159 | IPW2100_HANDLER(IPW_STATE_INITIALIZED, NULL), | ||
2160 | IPW2100_HANDLER(IPW_STATE_COUNTRY_FOUND, NULL), | ||
2161 | IPW2100_HANDLER(IPW_STATE_ASSOCIATED, isr_indicate_associated), | ||
2162 | IPW2100_HANDLER(IPW_STATE_ASSN_LOST, isr_indicate_association_lost), | ||
2163 | IPW2100_HANDLER(IPW_STATE_ASSN_CHANGED, NULL), | ||
2164 | IPW2100_HANDLER(IPW_STATE_SCAN_COMPLETE, isr_scan_complete), | ||
2165 | IPW2100_HANDLER(IPW_STATE_ENTERED_PSP, NULL), | ||
2166 | IPW2100_HANDLER(IPW_STATE_LEFT_PSP, NULL), | ||
2167 | IPW2100_HANDLER(IPW_STATE_RF_KILL, isr_indicate_rf_kill), | ||
2168 | IPW2100_HANDLER(IPW_STATE_DISABLED, NULL), | ||
2169 | IPW2100_HANDLER(IPW_STATE_POWER_DOWN, NULL), | ||
2170 | IPW2100_HANDLER(IPW_STATE_SCANNING, isr_indicate_scanning), | ||
2171 | IPW2100_HANDLER(-1, NULL) | ||
2172 | }; | ||
2173 | |||
2174 | static void isr_status_change(struct ipw2100_priv *priv, int status) | ||
2175 | { | ||
2176 | int i; | ||
2177 | |||
2178 | if (status == IPW_STATE_SCANNING && | ||
2179 | priv->status & STATUS_ASSOCIATED && | ||
2180 | !(priv->status & STATUS_SCANNING)) { | ||
2181 | IPW_DEBUG_INFO("Scan detected while associated, with " | ||
2182 | "no scan request. Restarting firmware.\n"); | ||
2183 | |||
2184 | /* Wake up any sleeping jobs */ | ||
2185 | schedule_reset(priv); | ||
2186 | } | ||
2187 | |||
2188 | for (i = 0; status_handlers[i].status != -1; i++) { | ||
2189 | if (status == status_handlers[i].status) { | ||
2190 | IPW_DEBUG_NOTIF("Status change: %s\n", | ||
2191 | status_handlers[i].name); | ||
2192 | if (status_handlers[i].cb) | ||
2193 | status_handlers[i].cb(priv, status); | ||
2194 | priv->wstats.status = status; | ||
2195 | return; | ||
2196 | } | ||
2197 | } | ||
2198 | |||
2199 | IPW_DEBUG_NOTIF("unknown status received: %04x\n", status); | ||
2200 | } | ||
2201 | |||
2202 | static void isr_rx_complete_command(struct ipw2100_priv *priv, | ||
2203 | struct ipw2100_cmd_header *cmd) | ||
2204 | { | ||
2205 | #ifdef CONFIG_IPW2100_DEBUG | ||
2206 | if (cmd->host_command_reg < ARRAY_SIZE(command_types)) { | ||
2207 | IPW_DEBUG_HC("Command completed '%s (%d)'\n", | ||
2208 | command_types[cmd->host_command_reg], | ||
2209 | cmd->host_command_reg); | ||
2210 | } | ||
2211 | #endif | ||
2212 | if (cmd->host_command_reg == HOST_COMPLETE) | ||
2213 | priv->status |= STATUS_ENABLED; | ||
2214 | |||
2215 | if (cmd->host_command_reg == CARD_DISABLE) | ||
2216 | priv->status &= ~STATUS_ENABLED; | ||
2217 | |||
2218 | priv->status &= ~STATUS_CMD_ACTIVE; | ||
2219 | |||
2220 | wake_up_interruptible(&priv->wait_command_queue); | ||
2221 | } | ||
2222 | |||
2223 | #ifdef CONFIG_IPW2100_DEBUG | ||
2224 | static const char *frame_types[] = { | ||
2225 | "COMMAND_STATUS_VAL", | ||
2226 | "STATUS_CHANGE_VAL", | ||
2227 | "P80211_DATA_VAL", | ||
2228 | "P8023_DATA_VAL", | ||
2229 | "HOST_NOTIFICATION_VAL" | ||
2230 | }; | ||
2231 | #endif | ||
2232 | |||
2233 | static int ipw2100_alloc_skb(struct ipw2100_priv *priv, | ||
2234 | struct ipw2100_rx_packet *packet) | ||
2235 | { | ||
2236 | packet->skb = dev_alloc_skb(sizeof(struct ipw2100_rx)); | ||
2237 | if (!packet->skb) | ||
2238 | return -ENOMEM; | ||
2239 | |||
2240 | packet->rxp = (struct ipw2100_rx *)packet->skb->data; | ||
2241 | packet->dma_addr = pci_map_single(priv->pci_dev, packet->skb->data, | ||
2242 | sizeof(struct ipw2100_rx), | ||
2243 | PCI_DMA_FROMDEVICE); | ||
2244 | /* NOTE: pci_map_single does not return an error code, and 0 is a valid | ||
2245 | * dma_addr */ | ||
2246 | |||
2247 | return 0; | ||
2248 | } | ||
2249 | |||
2250 | #define SEARCH_ERROR 0xffffffff | ||
2251 | #define SEARCH_FAIL 0xfffffffe | ||
2252 | #define SEARCH_SUCCESS 0xfffffff0 | ||
2253 | #define SEARCH_DISCARD 0 | ||
2254 | #define SEARCH_SNAPSHOT 1 | ||
2255 | |||
2256 | #define SNAPSHOT_ADDR(ofs) (priv->snapshot[((ofs) >> 12) & 0xff] + ((ofs) & 0xfff)) | ||
2257 | static void ipw2100_snapshot_free(struct ipw2100_priv *priv) | ||
2258 | { | ||
2259 | int i; | ||
2260 | if (!priv->snapshot[0]) | ||
2261 | return; | ||
2262 | for (i = 0; i < 0x30; i++) | ||
2263 | kfree(priv->snapshot[i]); | ||
2264 | priv->snapshot[0] = NULL; | ||
2265 | } | ||
2266 | |||
2267 | #ifdef IPW2100_DEBUG_C3 | ||
2268 | static int ipw2100_snapshot_alloc(struct ipw2100_priv *priv) | ||
2269 | { | ||
2270 | int i; | ||
2271 | if (priv->snapshot[0]) | ||
2272 | return 1; | ||
2273 | for (i = 0; i < 0x30; i++) { | ||
2274 | priv->snapshot[i] = kmalloc(0x1000, GFP_ATOMIC); | ||
2275 | if (!priv->snapshot[i]) { | ||
2276 | IPW_DEBUG_INFO("%s: Error allocating snapshot " | ||
2277 | "buffer %d\n", priv->net_dev->name, i); | ||
2278 | while (i > 0) | ||
2279 | kfree(priv->snapshot[--i]); | ||
2280 | priv->snapshot[0] = NULL; | ||
2281 | return 0; | ||
2282 | } | ||
2283 | } | ||
2284 | |||
2285 | return 1; | ||
2286 | } | ||
2287 | |||
2288 | static u32 ipw2100_match_buf(struct ipw2100_priv *priv, u8 * in_buf, | ||
2289 | size_t len, int mode) | ||
2290 | { | ||
2291 | u32 i, j; | ||
2292 | u32 tmp; | ||
2293 | u8 *s, *d; | ||
2294 | u32 ret; | ||
2295 | |||
2296 | s = in_buf; | ||
2297 | if (mode == SEARCH_SNAPSHOT) { | ||
2298 | if (!ipw2100_snapshot_alloc(priv)) | ||
2299 | mode = SEARCH_DISCARD; | ||
2300 | } | ||
2301 | |||
2302 | for (ret = SEARCH_FAIL, i = 0; i < 0x30000; i += 4) { | ||
2303 | read_nic_dword(priv->net_dev, i, &tmp); | ||
2304 | if (mode == SEARCH_SNAPSHOT) | ||
2305 | *(u32 *) SNAPSHOT_ADDR(i) = tmp; | ||
2306 | if (ret == SEARCH_FAIL) { | ||
2307 | d = (u8 *) & tmp; | ||
2308 | for (j = 0; j < 4; j++) { | ||
2309 | if (*s != *d) { | ||
2310 | s = in_buf; | ||
2311 | continue; | ||
2312 | } | ||
2313 | |||
2314 | s++; | ||
2315 | d++; | ||
2316 | |||
2317 | if ((s - in_buf) == len) | ||
2318 | ret = (i + j) - len + 1; | ||
2319 | } | ||
2320 | } else if (mode == SEARCH_DISCARD) | ||
2321 | return ret; | ||
2322 | } | ||
2323 | |||
2324 | return ret; | ||
2325 | } | ||
2326 | #endif | ||
2327 | |||
2328 | /* | ||
2329 | * | ||
2330 | * 0) Disconnect the SKB from the firmware (just unmap) | ||
2331 | * 1) Pack the ETH header into the SKB | ||
2332 | * 2) Pass the SKB to the network stack | ||
2333 | * | ||
2334 | * When packet is provided by the firmware, it contains the following: | ||
2335 | * | ||
2336 | * . ieee80211_hdr | ||
2337 | * . ieee80211_snap_hdr | ||
2338 | * | ||
2339 | * The size of the constructed ethernet | ||
2340 | * | ||
2341 | */ | ||
2342 | #ifdef IPW2100_RX_DEBUG | ||
2343 | static u8 packet_data[IPW_RX_NIC_BUFFER_LENGTH]; | ||
2344 | #endif | ||
2345 | |||
2346 | static void ipw2100_corruption_detected(struct ipw2100_priv *priv, int i) | ||
2347 | { | ||
2348 | #ifdef IPW2100_DEBUG_C3 | ||
2349 | struct ipw2100_status *status = &priv->status_queue.drv[i]; | ||
2350 | u32 match, reg; | ||
2351 | int j; | ||
2352 | #endif | ||
2353 | |||
2354 | IPW_DEBUG_INFO(": PCI latency error detected at 0x%04zX.\n", | ||
2355 | i * sizeof(struct ipw2100_status)); | ||
2356 | |||
2357 | #ifdef IPW2100_DEBUG_C3 | ||
2358 | /* Halt the fimrware so we can get a good image */ | ||
2359 | write_register(priv->net_dev, IPW_REG_RESET_REG, | ||
2360 | IPW_AUX_HOST_RESET_REG_STOP_MASTER); | ||
2361 | j = 5; | ||
2362 | do { | ||
2363 | udelay(IPW_WAIT_RESET_MASTER_ASSERT_COMPLETE_DELAY); | ||
2364 | read_register(priv->net_dev, IPW_REG_RESET_REG, ®); | ||
2365 | |||
2366 | if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED) | ||
2367 | break; | ||
2368 | } while (j--); | ||
2369 | |||
2370 | match = ipw2100_match_buf(priv, (u8 *) status, | ||
2371 | sizeof(struct ipw2100_status), | ||
2372 | SEARCH_SNAPSHOT); | ||
2373 | if (match < SEARCH_SUCCESS) | ||
2374 | IPW_DEBUG_INFO("%s: DMA status match in Firmware at " | ||
2375 | "offset 0x%06X, length %d:\n", | ||
2376 | priv->net_dev->name, match, | ||
2377 | sizeof(struct ipw2100_status)); | ||
2378 | else | ||
2379 | IPW_DEBUG_INFO("%s: No DMA status match in " | ||
2380 | "Firmware.\n", priv->net_dev->name); | ||
2381 | |||
2382 | printk_buf((u8 *) priv->status_queue.drv, | ||
2383 | sizeof(struct ipw2100_status) * RX_QUEUE_LENGTH); | ||
2384 | #endif | ||
2385 | |||
2386 | priv->fatal_error = IPW2100_ERR_C3_CORRUPTION; | ||
2387 | priv->ieee->stats.rx_errors++; | ||
2388 | schedule_reset(priv); | ||
2389 | } | ||
2390 | |||
2391 | static void isr_rx(struct ipw2100_priv *priv, int i, | ||
2392 | struct ieee80211_rx_stats *stats) | ||
2393 | { | ||
2394 | struct ipw2100_status *status = &priv->status_queue.drv[i]; | ||
2395 | struct ipw2100_rx_packet *packet = &priv->rx_buffers[i]; | ||
2396 | |||
2397 | IPW_DEBUG_RX("Handler...\n"); | ||
2398 | |||
2399 | if (unlikely(status->frame_size > skb_tailroom(packet->skb))) { | ||
2400 | IPW_DEBUG_INFO("%s: frame_size (%u) > skb_tailroom (%u)!" | ||
2401 | " Dropping.\n", | ||
2402 | priv->net_dev->name, | ||
2403 | status->frame_size, skb_tailroom(packet->skb)); | ||
2404 | priv->ieee->stats.rx_errors++; | ||
2405 | return; | ||
2406 | } | ||
2407 | |||
2408 | if (unlikely(!netif_running(priv->net_dev))) { | ||
2409 | priv->ieee->stats.rx_errors++; | ||
2410 | priv->wstats.discard.misc++; | ||
2411 | IPW_DEBUG_DROP("Dropping packet while interface is not up.\n"); | ||
2412 | return; | ||
2413 | } | ||
2414 | |||
2415 | if (unlikely(priv->ieee->iw_mode != IW_MODE_MONITOR && | ||
2416 | !(priv->status & STATUS_ASSOCIATED))) { | ||
2417 | IPW_DEBUG_DROP("Dropping packet while not associated.\n"); | ||
2418 | priv->wstats.discard.misc++; | ||
2419 | return; | ||
2420 | } | ||
2421 | |||
2422 | pci_unmap_single(priv->pci_dev, | ||
2423 | packet->dma_addr, | ||
2424 | sizeof(struct ipw2100_rx), PCI_DMA_FROMDEVICE); | ||
2425 | |||
2426 | skb_put(packet->skb, status->frame_size); | ||
2427 | |||
2428 | #ifdef IPW2100_RX_DEBUG | ||
2429 | /* Make a copy of the frame so we can dump it to the logs if | ||
2430 | * ieee80211_rx fails */ | ||
2431 | skb_copy_from_linear_data(packet->skb, packet_data, | ||
2432 | min_t(u32, status->frame_size, | ||
2433 | IPW_RX_NIC_BUFFER_LENGTH)); | ||
2434 | #endif | ||
2435 | |||
2436 | if (!ieee80211_rx(priv->ieee, packet->skb, stats)) { | ||
2437 | #ifdef IPW2100_RX_DEBUG | ||
2438 | IPW_DEBUG_DROP("%s: Non consumed packet:\n", | ||
2439 | priv->net_dev->name); | ||
2440 | printk_buf(IPW_DL_DROP, packet_data, status->frame_size); | ||
2441 | #endif | ||
2442 | priv->ieee->stats.rx_errors++; | ||
2443 | |||
2444 | /* ieee80211_rx failed, so it didn't free the SKB */ | ||
2445 | dev_kfree_skb_any(packet->skb); | ||
2446 | packet->skb = NULL; | ||
2447 | } | ||
2448 | |||
2449 | /* We need to allocate a new SKB and attach it to the RDB. */ | ||
2450 | if (unlikely(ipw2100_alloc_skb(priv, packet))) { | ||
2451 | printk(KERN_WARNING DRV_NAME ": " | ||
2452 | "%s: Unable to allocate SKB onto RBD ring - disabling " | ||
2453 | "adapter.\n", priv->net_dev->name); | ||
2454 | /* TODO: schedule adapter shutdown */ | ||
2455 | IPW_DEBUG_INFO("TODO: Shutdown adapter...\n"); | ||
2456 | } | ||
2457 | |||
2458 | /* Update the RDB entry */ | ||
2459 | priv->rx_queue.drv[i].host_addr = packet->dma_addr; | ||
2460 | } | ||
2461 | |||
2462 | #ifdef CONFIG_IPW2100_MONITOR | ||
2463 | |||
2464 | static void isr_rx_monitor(struct ipw2100_priv *priv, int i, | ||
2465 | struct ieee80211_rx_stats *stats) | ||
2466 | { | ||
2467 | struct ipw2100_status *status = &priv->status_queue.drv[i]; | ||
2468 | struct ipw2100_rx_packet *packet = &priv->rx_buffers[i]; | ||
2469 | |||
2470 | /* Magic struct that slots into the radiotap header -- no reason | ||
2471 | * to build this manually element by element, we can write it much | ||
2472 | * more efficiently than we can parse it. ORDER MATTERS HERE */ | ||
2473 | struct ipw_rt_hdr { | ||
2474 | struct ieee80211_radiotap_header rt_hdr; | ||
2475 | s8 rt_dbmsignal; /* signal in dbM, kluged to signed */ | ||
2476 | } *ipw_rt; | ||
2477 | |||
2478 | IPW_DEBUG_RX("Handler...\n"); | ||
2479 | |||
2480 | if (unlikely(status->frame_size > skb_tailroom(packet->skb) - | ||
2481 | sizeof(struct ipw_rt_hdr))) { | ||
2482 | IPW_DEBUG_INFO("%s: frame_size (%u) > skb_tailroom (%u)!" | ||
2483 | " Dropping.\n", | ||
2484 | priv->net_dev->name, | ||
2485 | status->frame_size, | ||
2486 | skb_tailroom(packet->skb)); | ||
2487 | priv->ieee->stats.rx_errors++; | ||
2488 | return; | ||
2489 | } | ||
2490 | |||
2491 | if (unlikely(!netif_running(priv->net_dev))) { | ||
2492 | priv->ieee->stats.rx_errors++; | ||
2493 | priv->wstats.discard.misc++; | ||
2494 | IPW_DEBUG_DROP("Dropping packet while interface is not up.\n"); | ||
2495 | return; | ||
2496 | } | ||
2497 | |||
2498 | if (unlikely(priv->config & CFG_CRC_CHECK && | ||
2499 | status->flags & IPW_STATUS_FLAG_CRC_ERROR)) { | ||
2500 | IPW_DEBUG_RX("CRC error in packet. Dropping.\n"); | ||
2501 | priv->ieee->stats.rx_errors++; | ||
2502 | return; | ||
2503 | } | ||
2504 | |||
2505 | pci_unmap_single(priv->pci_dev, packet->dma_addr, | ||
2506 | sizeof(struct ipw2100_rx), PCI_DMA_FROMDEVICE); | ||
2507 | memmove(packet->skb->data + sizeof(struct ipw_rt_hdr), | ||
2508 | packet->skb->data, status->frame_size); | ||
2509 | |||
2510 | ipw_rt = (struct ipw_rt_hdr *) packet->skb->data; | ||
2511 | |||
2512 | ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION; | ||
2513 | ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */ | ||
2514 | ipw_rt->rt_hdr.it_len = cpu_to_le16(sizeof(struct ipw_rt_hdr)); /* total hdr+data */ | ||
2515 | |||
2516 | ipw_rt->rt_hdr.it_present = cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL); | ||
2517 | |||
2518 | ipw_rt->rt_dbmsignal = status->rssi + IPW2100_RSSI_TO_DBM; | ||
2519 | |||
2520 | skb_put(packet->skb, status->frame_size + sizeof(struct ipw_rt_hdr)); | ||
2521 | |||
2522 | if (!ieee80211_rx(priv->ieee, packet->skb, stats)) { | ||
2523 | priv->ieee->stats.rx_errors++; | ||
2524 | |||
2525 | /* ieee80211_rx failed, so it didn't free the SKB */ | ||
2526 | dev_kfree_skb_any(packet->skb); | ||
2527 | packet->skb = NULL; | ||
2528 | } | ||
2529 | |||
2530 | /* We need to allocate a new SKB and attach it to the RDB. */ | ||
2531 | if (unlikely(ipw2100_alloc_skb(priv, packet))) { | ||
2532 | IPW_DEBUG_WARNING( | ||
2533 | "%s: Unable to allocate SKB onto RBD ring - disabling " | ||
2534 | "adapter.\n", priv->net_dev->name); | ||
2535 | /* TODO: schedule adapter shutdown */ | ||
2536 | IPW_DEBUG_INFO("TODO: Shutdown adapter...\n"); | ||
2537 | } | ||
2538 | |||
2539 | /* Update the RDB entry */ | ||
2540 | priv->rx_queue.drv[i].host_addr = packet->dma_addr; | ||
2541 | } | ||
2542 | |||
2543 | #endif | ||
2544 | |||
2545 | static int ipw2100_corruption_check(struct ipw2100_priv *priv, int i) | ||
2546 | { | ||
2547 | struct ipw2100_status *status = &priv->status_queue.drv[i]; | ||
2548 | struct ipw2100_rx *u = priv->rx_buffers[i].rxp; | ||
2549 | u16 frame_type = status->status_fields & STATUS_TYPE_MASK; | ||
2550 | |||
2551 | switch (frame_type) { | ||
2552 | case COMMAND_STATUS_VAL: | ||
2553 | return (status->frame_size != sizeof(u->rx_data.command)); | ||
2554 | case STATUS_CHANGE_VAL: | ||
2555 | return (status->frame_size != sizeof(u->rx_data.status)); | ||
2556 | case HOST_NOTIFICATION_VAL: | ||
2557 | return (status->frame_size < sizeof(u->rx_data.notification)); | ||
2558 | case P80211_DATA_VAL: | ||
2559 | case P8023_DATA_VAL: | ||
2560 | #ifdef CONFIG_IPW2100_MONITOR | ||
2561 | return 0; | ||
2562 | #else | ||
2563 | switch (WLAN_FC_GET_TYPE(le16_to_cpu(u->rx_data.header.frame_ctl))) { | ||
2564 | case IEEE80211_FTYPE_MGMT: | ||
2565 | case IEEE80211_FTYPE_CTL: | ||
2566 | return 0; | ||
2567 | case IEEE80211_FTYPE_DATA: | ||
2568 | return (status->frame_size > | ||
2569 | IPW_MAX_802_11_PAYLOAD_LENGTH); | ||
2570 | } | ||
2571 | #endif | ||
2572 | } | ||
2573 | |||
2574 | return 1; | ||
2575 | } | ||
2576 | |||
2577 | /* | ||
2578 | * ipw2100 interrupts are disabled at this point, and the ISR | ||
2579 | * is the only code that calls this method. So, we do not need | ||
2580 | * to play with any locks. | ||
2581 | * | ||
2582 | * RX Queue works as follows: | ||
2583 | * | ||
2584 | * Read index - firmware places packet in entry identified by the | ||
2585 | * Read index and advances Read index. In this manner, | ||
2586 | * Read index will always point to the next packet to | ||
2587 | * be filled--but not yet valid. | ||
2588 | * | ||
2589 | * Write index - driver fills this entry with an unused RBD entry. | ||
2590 | * This entry has not filled by the firmware yet. | ||
2591 | * | ||
2592 | * In between the W and R indexes are the RBDs that have been received | ||
2593 | * but not yet processed. | ||
2594 | * | ||
2595 | * The process of handling packets will start at WRITE + 1 and advance | ||
2596 | * until it reaches the READ index. | ||
2597 | * | ||
2598 | * The WRITE index is cached in the variable 'priv->rx_queue.next'. | ||
2599 | * | ||
2600 | */ | ||
2601 | static void __ipw2100_rx_process(struct ipw2100_priv *priv) | ||
2602 | { | ||
2603 | struct ipw2100_bd_queue *rxq = &priv->rx_queue; | ||
2604 | struct ipw2100_status_queue *sq = &priv->status_queue; | ||
2605 | struct ipw2100_rx_packet *packet; | ||
2606 | u16 frame_type; | ||
2607 | u32 r, w, i, s; | ||
2608 | struct ipw2100_rx *u; | ||
2609 | struct ieee80211_rx_stats stats = { | ||
2610 | .mac_time = jiffies, | ||
2611 | }; | ||
2612 | |||
2613 | read_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_READ_INDEX, &r); | ||
2614 | read_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_WRITE_INDEX, &w); | ||
2615 | |||
2616 | if (r >= rxq->entries) { | ||
2617 | IPW_DEBUG_RX("exit - bad read index\n"); | ||
2618 | return; | ||
2619 | } | ||
2620 | |||
2621 | i = (rxq->next + 1) % rxq->entries; | ||
2622 | s = i; | ||
2623 | while (i != r) { | ||
2624 | /* IPW_DEBUG_RX("r = %d : w = %d : processing = %d\n", | ||
2625 | r, rxq->next, i); */ | ||
2626 | |||
2627 | packet = &priv->rx_buffers[i]; | ||
2628 | |||
2629 | /* Sync the DMA for the STATUS buffer so CPU is sure to get | ||
2630 | * the correct values */ | ||
2631 | pci_dma_sync_single_for_cpu(priv->pci_dev, | ||
2632 | sq->nic + | ||
2633 | sizeof(struct ipw2100_status) * i, | ||
2634 | sizeof(struct ipw2100_status), | ||
2635 | PCI_DMA_FROMDEVICE); | ||
2636 | |||
2637 | /* Sync the DMA for the RX buffer so CPU is sure to get | ||
2638 | * the correct values */ | ||
2639 | pci_dma_sync_single_for_cpu(priv->pci_dev, packet->dma_addr, | ||
2640 | sizeof(struct ipw2100_rx), | ||
2641 | PCI_DMA_FROMDEVICE); | ||
2642 | |||
2643 | if (unlikely(ipw2100_corruption_check(priv, i))) { | ||
2644 | ipw2100_corruption_detected(priv, i); | ||
2645 | goto increment; | ||
2646 | } | ||
2647 | |||
2648 | u = packet->rxp; | ||
2649 | frame_type = sq->drv[i].status_fields & STATUS_TYPE_MASK; | ||
2650 | stats.rssi = sq->drv[i].rssi + IPW2100_RSSI_TO_DBM; | ||
2651 | stats.len = sq->drv[i].frame_size; | ||
2652 | |||
2653 | stats.mask = 0; | ||
2654 | if (stats.rssi != 0) | ||
2655 | stats.mask |= IEEE80211_STATMASK_RSSI; | ||
2656 | stats.freq = IEEE80211_24GHZ_BAND; | ||
2657 | |||
2658 | IPW_DEBUG_RX("%s: '%s' frame type received (%d).\n", | ||
2659 | priv->net_dev->name, frame_types[frame_type], | ||
2660 | stats.len); | ||
2661 | |||
2662 | switch (frame_type) { | ||
2663 | case COMMAND_STATUS_VAL: | ||
2664 | /* Reset Rx watchdog */ | ||
2665 | isr_rx_complete_command(priv, &u->rx_data.command); | ||
2666 | break; | ||
2667 | |||
2668 | case STATUS_CHANGE_VAL: | ||
2669 | isr_status_change(priv, u->rx_data.status); | ||
2670 | break; | ||
2671 | |||
2672 | case P80211_DATA_VAL: | ||
2673 | case P8023_DATA_VAL: | ||
2674 | #ifdef CONFIG_IPW2100_MONITOR | ||
2675 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { | ||
2676 | isr_rx_monitor(priv, i, &stats); | ||
2677 | break; | ||
2678 | } | ||
2679 | #endif | ||
2680 | if (stats.len < sizeof(struct ieee80211_hdr_3addr)) | ||
2681 | break; | ||
2682 | switch (WLAN_FC_GET_TYPE(le16_to_cpu(u->rx_data.header.frame_ctl))) { | ||
2683 | case IEEE80211_FTYPE_MGMT: | ||
2684 | ieee80211_rx_mgt(priv->ieee, | ||
2685 | &u->rx_data.header, &stats); | ||
2686 | break; | ||
2687 | |||
2688 | case IEEE80211_FTYPE_CTL: | ||
2689 | break; | ||
2690 | |||
2691 | case IEEE80211_FTYPE_DATA: | ||
2692 | isr_rx(priv, i, &stats); | ||
2693 | break; | ||
2694 | |||
2695 | } | ||
2696 | break; | ||
2697 | } | ||
2698 | |||
2699 | increment: | ||
2700 | /* clear status field associated with this RBD */ | ||
2701 | rxq->drv[i].status.info.field = 0; | ||
2702 | |||
2703 | i = (i + 1) % rxq->entries; | ||
2704 | } | ||
2705 | |||
2706 | if (i != s) { | ||
2707 | /* backtrack one entry, wrapping to end if at 0 */ | ||
2708 | rxq->next = (i ? i : rxq->entries) - 1; | ||
2709 | |||
2710 | write_register(priv->net_dev, | ||
2711 | IPW_MEM_HOST_SHARED_RX_WRITE_INDEX, rxq->next); | ||
2712 | } | ||
2713 | } | ||
2714 | |||
2715 | /* | ||
2716 | * __ipw2100_tx_process | ||
2717 | * | ||
2718 | * This routine will determine whether the next packet on | ||
2719 | * the fw_pend_list has been processed by the firmware yet. | ||
2720 | * | ||
2721 | * If not, then it does nothing and returns. | ||
2722 | * | ||
2723 | * If so, then it removes the item from the fw_pend_list, frees | ||
2724 | * any associated storage, and places the item back on the | ||
2725 | * free list of its source (either msg_free_list or tx_free_list) | ||
2726 | * | ||
2727 | * TX Queue works as follows: | ||
2728 | * | ||
2729 | * Read index - points to the next TBD that the firmware will | ||
2730 | * process. The firmware will read the data, and once | ||
2731 | * done processing, it will advance the Read index. | ||
2732 | * | ||
2733 | * Write index - driver fills this entry with an constructed TBD | ||
2734 | * entry. The Write index is not advanced until the | ||
2735 | * packet has been configured. | ||
2736 | * | ||
2737 | * In between the W and R indexes are the TBDs that have NOT been | ||
2738 | * processed. Lagging behind the R index are packets that have | ||
2739 | * been processed but have not been freed by the driver. | ||
2740 | * | ||
2741 | * In order to free old storage, an internal index will be maintained | ||
2742 | * that points to the next packet to be freed. When all used | ||
2743 | * packets have been freed, the oldest index will be the same as the | ||
2744 | * firmware's read index. | ||
2745 | * | ||
2746 | * The OLDEST index is cached in the variable 'priv->tx_queue.oldest' | ||
2747 | * | ||
2748 | * Because the TBD structure can not contain arbitrary data, the | ||
2749 | * driver must keep an internal queue of cached allocations such that | ||
2750 | * it can put that data back into the tx_free_list and msg_free_list | ||
2751 | * for use by future command and data packets. | ||
2752 | * | ||
2753 | */ | ||
2754 | static int __ipw2100_tx_process(struct ipw2100_priv *priv) | ||
2755 | { | ||
2756 | struct ipw2100_bd_queue *txq = &priv->tx_queue; | ||
2757 | struct ipw2100_bd *tbd; | ||
2758 | struct list_head *element; | ||
2759 | struct ipw2100_tx_packet *packet; | ||
2760 | int descriptors_used; | ||
2761 | int e, i; | ||
2762 | u32 r, w, frag_num = 0; | ||
2763 | |||
2764 | if (list_empty(&priv->fw_pend_list)) | ||
2765 | return 0; | ||
2766 | |||
2767 | element = priv->fw_pend_list.next; | ||
2768 | |||
2769 | packet = list_entry(element, struct ipw2100_tx_packet, list); | ||
2770 | tbd = &txq->drv[packet->index]; | ||
2771 | |||
2772 | /* Determine how many TBD entries must be finished... */ | ||
2773 | switch (packet->type) { | ||
2774 | case COMMAND: | ||
2775 | /* COMMAND uses only one slot; don't advance */ | ||
2776 | descriptors_used = 1; | ||
2777 | e = txq->oldest; | ||
2778 | break; | ||
2779 | |||
2780 | case DATA: | ||
2781 | /* DATA uses two slots; advance and loop position. */ | ||
2782 | descriptors_used = tbd->num_fragments; | ||
2783 | frag_num = tbd->num_fragments - 1; | ||
2784 | e = txq->oldest + frag_num; | ||
2785 | e %= txq->entries; | ||
2786 | break; | ||
2787 | |||
2788 | default: | ||
2789 | printk(KERN_WARNING DRV_NAME ": %s: Bad fw_pend_list entry!\n", | ||
2790 | priv->net_dev->name); | ||
2791 | return 0; | ||
2792 | } | ||
2793 | |||
2794 | /* if the last TBD is not done by NIC yet, then packet is | ||
2795 | * not ready to be released. | ||
2796 | * | ||
2797 | */ | ||
2798 | read_register(priv->net_dev, IPW_MEM_HOST_SHARED_TX_QUEUE_READ_INDEX, | ||
2799 | &r); | ||
2800 | read_register(priv->net_dev, IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX, | ||
2801 | &w); | ||
2802 | if (w != txq->next) | ||
2803 | printk(KERN_WARNING DRV_NAME ": %s: write index mismatch\n", | ||
2804 | priv->net_dev->name); | ||
2805 | |||
2806 | /* | ||
2807 | * txq->next is the index of the last packet written txq->oldest is | ||
2808 | * the index of the r is the index of the next packet to be read by | ||
2809 | * firmware | ||
2810 | */ | ||
2811 | |||
2812 | /* | ||
2813 | * Quick graphic to help you visualize the following | ||
2814 | * if / else statement | ||
2815 | * | ||
2816 | * ===>| s---->|=============== | ||
2817 | * e>| | ||
2818 | * | a | b | c | d | e | f | g | h | i | j | k | l | ||
2819 | * r---->| | ||
2820 | * w | ||
2821 | * | ||
2822 | * w - updated by driver | ||
2823 | * r - updated by firmware | ||
2824 | * s - start of oldest BD entry (txq->oldest) | ||
2825 | * e - end of oldest BD entry | ||
2826 | * | ||
2827 | */ | ||
2828 | if (!((r <= w && (e < r || e >= w)) || (e < r && e >= w))) { | ||
2829 | IPW_DEBUG_TX("exit - no processed packets ready to release.\n"); | ||
2830 | return 0; | ||
2831 | } | ||
2832 | |||
2833 | list_del(element); | ||
2834 | DEC_STAT(&priv->fw_pend_stat); | ||
2835 | |||
2836 | #ifdef CONFIG_IPW2100_DEBUG | ||
2837 | { | ||
2838 | int i = txq->oldest; | ||
2839 | IPW_DEBUG_TX("TX%d V=%p P=%04X T=%04X L=%d\n", i, | ||
2840 | &txq->drv[i], | ||
2841 | (u32) (txq->nic + i * sizeof(struct ipw2100_bd)), | ||
2842 | txq->drv[i].host_addr, txq->drv[i].buf_length); | ||
2843 | |||
2844 | if (packet->type == DATA) { | ||
2845 | i = (i + 1) % txq->entries; | ||
2846 | |||
2847 | IPW_DEBUG_TX("TX%d V=%p P=%04X T=%04X L=%d\n", i, | ||
2848 | &txq->drv[i], | ||
2849 | (u32) (txq->nic + i * | ||
2850 | sizeof(struct ipw2100_bd)), | ||
2851 | (u32) txq->drv[i].host_addr, | ||
2852 | txq->drv[i].buf_length); | ||
2853 | } | ||
2854 | } | ||
2855 | #endif | ||
2856 | |||
2857 | switch (packet->type) { | ||
2858 | case DATA: | ||
2859 | if (txq->drv[txq->oldest].status.info.fields.txType != 0) | ||
2860 | printk(KERN_WARNING DRV_NAME ": %s: Queue mismatch. " | ||
2861 | "Expecting DATA TBD but pulled " | ||
2862 | "something else: ids %d=%d.\n", | ||
2863 | priv->net_dev->name, txq->oldest, packet->index); | ||
2864 | |||
2865 | /* DATA packet; we have to unmap and free the SKB */ | ||
2866 | for (i = 0; i < frag_num; i++) { | ||
2867 | tbd = &txq->drv[(packet->index + 1 + i) % txq->entries]; | ||
2868 | |||
2869 | IPW_DEBUG_TX("TX%d P=%08x L=%d\n", | ||
2870 | (packet->index + 1 + i) % txq->entries, | ||
2871 | tbd->host_addr, tbd->buf_length); | ||
2872 | |||
2873 | pci_unmap_single(priv->pci_dev, | ||
2874 | tbd->host_addr, | ||
2875 | tbd->buf_length, PCI_DMA_TODEVICE); | ||
2876 | } | ||
2877 | |||
2878 | ieee80211_txb_free(packet->info.d_struct.txb); | ||
2879 | packet->info.d_struct.txb = NULL; | ||
2880 | |||
2881 | list_add_tail(element, &priv->tx_free_list); | ||
2882 | INC_STAT(&priv->tx_free_stat); | ||
2883 | |||
2884 | /* We have a free slot in the Tx queue, so wake up the | ||
2885 | * transmit layer if it is stopped. */ | ||
2886 | if (priv->status & STATUS_ASSOCIATED) | ||
2887 | netif_wake_queue(priv->net_dev); | ||
2888 | |||
2889 | /* A packet was processed by the hardware, so update the | ||
2890 | * watchdog */ | ||
2891 | priv->net_dev->trans_start = jiffies; | ||
2892 | |||
2893 | break; | ||
2894 | |||
2895 | case COMMAND: | ||
2896 | if (txq->drv[txq->oldest].status.info.fields.txType != 1) | ||
2897 | printk(KERN_WARNING DRV_NAME ": %s: Queue mismatch. " | ||
2898 | "Expecting COMMAND TBD but pulled " | ||
2899 | "something else: ids %d=%d.\n", | ||
2900 | priv->net_dev->name, txq->oldest, packet->index); | ||
2901 | |||
2902 | #ifdef CONFIG_IPW2100_DEBUG | ||
2903 | if (packet->info.c_struct.cmd->host_command_reg < | ||
2904 | ARRAY_SIZE(command_types)) | ||
2905 | IPW_DEBUG_TX("Command '%s (%d)' processed: %d.\n", | ||
2906 | command_types[packet->info.c_struct.cmd-> | ||
2907 | host_command_reg], | ||
2908 | packet->info.c_struct.cmd-> | ||
2909 | host_command_reg, | ||
2910 | packet->info.c_struct.cmd->cmd_status_reg); | ||
2911 | #endif | ||
2912 | |||
2913 | list_add_tail(element, &priv->msg_free_list); | ||
2914 | INC_STAT(&priv->msg_free_stat); | ||
2915 | break; | ||
2916 | } | ||
2917 | |||
2918 | /* advance oldest used TBD pointer to start of next entry */ | ||
2919 | txq->oldest = (e + 1) % txq->entries; | ||
2920 | /* increase available TBDs number */ | ||
2921 | txq->available += descriptors_used; | ||
2922 | SET_STAT(&priv->txq_stat, txq->available); | ||
2923 | |||
2924 | IPW_DEBUG_TX("packet latency (send to process) %ld jiffies\n", | ||
2925 | jiffies - packet->jiffy_start); | ||
2926 | |||
2927 | return (!list_empty(&priv->fw_pend_list)); | ||
2928 | } | ||
2929 | |||
2930 | static inline void __ipw2100_tx_complete(struct ipw2100_priv *priv) | ||
2931 | { | ||
2932 | int i = 0; | ||
2933 | |||
2934 | while (__ipw2100_tx_process(priv) && i < 200) | ||
2935 | i++; | ||
2936 | |||
2937 | if (i == 200) { | ||
2938 | printk(KERN_WARNING DRV_NAME ": " | ||
2939 | "%s: Driver is running slow (%d iters).\n", | ||
2940 | priv->net_dev->name, i); | ||
2941 | } | ||
2942 | } | ||
2943 | |||
2944 | static void ipw2100_tx_send_commands(struct ipw2100_priv *priv) | ||
2945 | { | ||
2946 | struct list_head *element; | ||
2947 | struct ipw2100_tx_packet *packet; | ||
2948 | struct ipw2100_bd_queue *txq = &priv->tx_queue; | ||
2949 | struct ipw2100_bd *tbd; | ||
2950 | int next = txq->next; | ||
2951 | |||
2952 | while (!list_empty(&priv->msg_pend_list)) { | ||
2953 | /* if there isn't enough space in TBD queue, then | ||
2954 | * don't stuff a new one in. | ||
2955 | * NOTE: 3 are needed as a command will take one, | ||
2956 | * and there is a minimum of 2 that must be | ||
2957 | * maintained between the r and w indexes | ||
2958 | */ | ||
2959 | if (txq->available <= 3) { | ||
2960 | IPW_DEBUG_TX("no room in tx_queue\n"); | ||
2961 | break; | ||
2962 | } | ||
2963 | |||
2964 | element = priv->msg_pend_list.next; | ||
2965 | list_del(element); | ||
2966 | DEC_STAT(&priv->msg_pend_stat); | ||
2967 | |||
2968 | packet = list_entry(element, struct ipw2100_tx_packet, list); | ||
2969 | |||
2970 | IPW_DEBUG_TX("using TBD at virt=%p, phys=%p\n", | ||
2971 | &txq->drv[txq->next], | ||
2972 | (void *)(txq->nic + txq->next * | ||
2973 | sizeof(struct ipw2100_bd))); | ||
2974 | |||
2975 | packet->index = txq->next; | ||
2976 | |||
2977 | tbd = &txq->drv[txq->next]; | ||
2978 | |||
2979 | /* initialize TBD */ | ||
2980 | tbd->host_addr = packet->info.c_struct.cmd_phys; | ||
2981 | tbd->buf_length = sizeof(struct ipw2100_cmd_header); | ||
2982 | /* not marking number of fragments causes problems | ||
2983 | * with f/w debug version */ | ||
2984 | tbd->num_fragments = 1; | ||
2985 | tbd->status.info.field = | ||
2986 | IPW_BD_STATUS_TX_FRAME_COMMAND | | ||
2987 | IPW_BD_STATUS_TX_INTERRUPT_ENABLE; | ||
2988 | |||
2989 | /* update TBD queue counters */ | ||
2990 | txq->next++; | ||
2991 | txq->next %= txq->entries; | ||
2992 | txq->available--; | ||
2993 | DEC_STAT(&priv->txq_stat); | ||
2994 | |||
2995 | list_add_tail(element, &priv->fw_pend_list); | ||
2996 | INC_STAT(&priv->fw_pend_stat); | ||
2997 | } | ||
2998 | |||
2999 | if (txq->next != next) { | ||
3000 | /* kick off the DMA by notifying firmware the | ||
3001 | * write index has moved; make sure TBD stores are sync'd */ | ||
3002 | wmb(); | ||
3003 | write_register(priv->net_dev, | ||
3004 | IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX, | ||
3005 | txq->next); | ||
3006 | } | ||
3007 | } | ||
3008 | |||
3009 | /* | ||
3010 | * ipw2100_tx_send_data | ||
3011 | * | ||
3012 | */ | ||
3013 | static void ipw2100_tx_send_data(struct ipw2100_priv *priv) | ||
3014 | { | ||
3015 | struct list_head *element; | ||
3016 | struct ipw2100_tx_packet *packet; | ||
3017 | struct ipw2100_bd_queue *txq = &priv->tx_queue; | ||
3018 | struct ipw2100_bd *tbd; | ||
3019 | int next = txq->next; | ||
3020 | int i = 0; | ||
3021 | struct ipw2100_data_header *ipw_hdr; | ||
3022 | struct ieee80211_hdr_3addr *hdr; | ||
3023 | |||
3024 | while (!list_empty(&priv->tx_pend_list)) { | ||
3025 | /* if there isn't enough space in TBD queue, then | ||
3026 | * don't stuff a new one in. | ||
3027 | * NOTE: 4 are needed as a data will take two, | ||
3028 | * and there is a minimum of 2 that must be | ||
3029 | * maintained between the r and w indexes | ||
3030 | */ | ||
3031 | element = priv->tx_pend_list.next; | ||
3032 | packet = list_entry(element, struct ipw2100_tx_packet, list); | ||
3033 | |||
3034 | if (unlikely(1 + packet->info.d_struct.txb->nr_frags > | ||
3035 | IPW_MAX_BDS)) { | ||
3036 | /* TODO: Support merging buffers if more than | ||
3037 | * IPW_MAX_BDS are used */ | ||
3038 | IPW_DEBUG_INFO("%s: Maximum BD theshold exceeded. " | ||
3039 | "Increase fragmentation level.\n", | ||
3040 | priv->net_dev->name); | ||
3041 | } | ||
3042 | |||
3043 | if (txq->available <= 3 + packet->info.d_struct.txb->nr_frags) { | ||
3044 | IPW_DEBUG_TX("no room in tx_queue\n"); | ||
3045 | break; | ||
3046 | } | ||
3047 | |||
3048 | list_del(element); | ||
3049 | DEC_STAT(&priv->tx_pend_stat); | ||
3050 | |||
3051 | tbd = &txq->drv[txq->next]; | ||
3052 | |||
3053 | packet->index = txq->next; | ||
3054 | |||
3055 | ipw_hdr = packet->info.d_struct.data; | ||
3056 | hdr = (struct ieee80211_hdr_3addr *)packet->info.d_struct.txb-> | ||
3057 | fragments[0]->data; | ||
3058 | |||
3059 | if (priv->ieee->iw_mode == IW_MODE_INFRA) { | ||
3060 | /* To DS: Addr1 = BSSID, Addr2 = SA, | ||
3061 | Addr3 = DA */ | ||
3062 | memcpy(ipw_hdr->src_addr, hdr->addr2, ETH_ALEN); | ||
3063 | memcpy(ipw_hdr->dst_addr, hdr->addr3, ETH_ALEN); | ||
3064 | } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) { | ||
3065 | /* not From/To DS: Addr1 = DA, Addr2 = SA, | ||
3066 | Addr3 = BSSID */ | ||
3067 | memcpy(ipw_hdr->src_addr, hdr->addr2, ETH_ALEN); | ||
3068 | memcpy(ipw_hdr->dst_addr, hdr->addr1, ETH_ALEN); | ||
3069 | } | ||
3070 | |||
3071 | ipw_hdr->host_command_reg = SEND; | ||
3072 | ipw_hdr->host_command_reg1 = 0; | ||
3073 | |||
3074 | /* For now we only support host based encryption */ | ||
3075 | ipw_hdr->needs_encryption = 0; | ||
3076 | ipw_hdr->encrypted = packet->info.d_struct.txb->encrypted; | ||
3077 | if (packet->info.d_struct.txb->nr_frags > 1) | ||
3078 | ipw_hdr->fragment_size = | ||
3079 | packet->info.d_struct.txb->frag_size - | ||
3080 | IEEE80211_3ADDR_LEN; | ||
3081 | else | ||
3082 | ipw_hdr->fragment_size = 0; | ||
3083 | |||
3084 | tbd->host_addr = packet->info.d_struct.data_phys; | ||
3085 | tbd->buf_length = sizeof(struct ipw2100_data_header); | ||
3086 | tbd->num_fragments = 1 + packet->info.d_struct.txb->nr_frags; | ||
3087 | tbd->status.info.field = | ||
3088 | IPW_BD_STATUS_TX_FRAME_802_3 | | ||
3089 | IPW_BD_STATUS_TX_FRAME_NOT_LAST_FRAGMENT; | ||
3090 | txq->next++; | ||
3091 | txq->next %= txq->entries; | ||
3092 | |||
3093 | IPW_DEBUG_TX("data header tbd TX%d P=%08x L=%d\n", | ||
3094 | packet->index, tbd->host_addr, tbd->buf_length); | ||
3095 | #ifdef CONFIG_IPW2100_DEBUG | ||
3096 | if (packet->info.d_struct.txb->nr_frags > 1) | ||
3097 | IPW_DEBUG_FRAG("fragment Tx: %d frames\n", | ||
3098 | packet->info.d_struct.txb->nr_frags); | ||
3099 | #endif | ||
3100 | |||
3101 | for (i = 0; i < packet->info.d_struct.txb->nr_frags; i++) { | ||
3102 | tbd = &txq->drv[txq->next]; | ||
3103 | if (i == packet->info.d_struct.txb->nr_frags - 1) | ||
3104 | tbd->status.info.field = | ||
3105 | IPW_BD_STATUS_TX_FRAME_802_3 | | ||
3106 | IPW_BD_STATUS_TX_INTERRUPT_ENABLE; | ||
3107 | else | ||
3108 | tbd->status.info.field = | ||
3109 | IPW_BD_STATUS_TX_FRAME_802_3 | | ||
3110 | IPW_BD_STATUS_TX_FRAME_NOT_LAST_FRAGMENT; | ||
3111 | |||
3112 | tbd->buf_length = packet->info.d_struct.txb-> | ||
3113 | fragments[i]->len - IEEE80211_3ADDR_LEN; | ||
3114 | |||
3115 | tbd->host_addr = pci_map_single(priv->pci_dev, | ||
3116 | packet->info.d_struct. | ||
3117 | txb->fragments[i]-> | ||
3118 | data + | ||
3119 | IEEE80211_3ADDR_LEN, | ||
3120 | tbd->buf_length, | ||
3121 | PCI_DMA_TODEVICE); | ||
3122 | |||
3123 | IPW_DEBUG_TX("data frag tbd TX%d P=%08x L=%d\n", | ||
3124 | txq->next, tbd->host_addr, | ||
3125 | tbd->buf_length); | ||
3126 | |||
3127 | pci_dma_sync_single_for_device(priv->pci_dev, | ||
3128 | tbd->host_addr, | ||
3129 | tbd->buf_length, | ||
3130 | PCI_DMA_TODEVICE); | ||
3131 | |||
3132 | txq->next++; | ||
3133 | txq->next %= txq->entries; | ||
3134 | } | ||
3135 | |||
3136 | txq->available -= 1 + packet->info.d_struct.txb->nr_frags; | ||
3137 | SET_STAT(&priv->txq_stat, txq->available); | ||
3138 | |||
3139 | list_add_tail(element, &priv->fw_pend_list); | ||
3140 | INC_STAT(&priv->fw_pend_stat); | ||
3141 | } | ||
3142 | |||
3143 | if (txq->next != next) { | ||
3144 | /* kick off the DMA by notifying firmware the | ||
3145 | * write index has moved; make sure TBD stores are sync'd */ | ||
3146 | write_register(priv->net_dev, | ||
3147 | IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX, | ||
3148 | txq->next); | ||
3149 | } | ||
3150 | return; | ||
3151 | } | ||
3152 | |||
3153 | static void ipw2100_irq_tasklet(struct ipw2100_priv *priv) | ||
3154 | { | ||
3155 | struct net_device *dev = priv->net_dev; | ||
3156 | unsigned long flags; | ||
3157 | u32 inta, tmp; | ||
3158 | |||
3159 | spin_lock_irqsave(&priv->low_lock, flags); | ||
3160 | ipw2100_disable_interrupts(priv); | ||
3161 | |||
3162 | read_register(dev, IPW_REG_INTA, &inta); | ||
3163 | |||
3164 | IPW_DEBUG_ISR("enter - INTA: 0x%08lX\n", | ||
3165 | (unsigned long)inta & IPW_INTERRUPT_MASK); | ||
3166 | |||
3167 | priv->in_isr++; | ||
3168 | priv->interrupts++; | ||
3169 | |||
3170 | /* We do not loop and keep polling for more interrupts as this | ||
3171 | * is frowned upon and doesn't play nicely with other potentially | ||
3172 | * chained IRQs */ | ||
3173 | IPW_DEBUG_ISR("INTA: 0x%08lX\n", | ||
3174 | (unsigned long)inta & IPW_INTERRUPT_MASK); | ||
3175 | |||
3176 | if (inta & IPW2100_INTA_FATAL_ERROR) { | ||
3177 | printk(KERN_WARNING DRV_NAME | ||
3178 | ": Fatal interrupt. Scheduling firmware restart.\n"); | ||
3179 | priv->inta_other++; | ||
3180 | write_register(dev, IPW_REG_INTA, IPW2100_INTA_FATAL_ERROR); | ||
3181 | |||
3182 | read_nic_dword(dev, IPW_NIC_FATAL_ERROR, &priv->fatal_error); | ||
3183 | IPW_DEBUG_INFO("%s: Fatal error value: 0x%08X\n", | ||
3184 | priv->net_dev->name, priv->fatal_error); | ||
3185 | |||
3186 | read_nic_dword(dev, IPW_ERROR_ADDR(priv->fatal_error), &tmp); | ||
3187 | IPW_DEBUG_INFO("%s: Fatal error address value: 0x%08X\n", | ||
3188 | priv->net_dev->name, tmp); | ||
3189 | |||
3190 | /* Wake up any sleeping jobs */ | ||
3191 | schedule_reset(priv); | ||
3192 | } | ||
3193 | |||
3194 | if (inta & IPW2100_INTA_PARITY_ERROR) { | ||
3195 | printk(KERN_ERR DRV_NAME | ||
3196 | ": ***** PARITY ERROR INTERRUPT !!!! \n"); | ||
3197 | priv->inta_other++; | ||
3198 | write_register(dev, IPW_REG_INTA, IPW2100_INTA_PARITY_ERROR); | ||
3199 | } | ||
3200 | |||
3201 | if (inta & IPW2100_INTA_RX_TRANSFER) { | ||
3202 | IPW_DEBUG_ISR("RX interrupt\n"); | ||
3203 | |||
3204 | priv->rx_interrupts++; | ||
3205 | |||
3206 | write_register(dev, IPW_REG_INTA, IPW2100_INTA_RX_TRANSFER); | ||
3207 | |||
3208 | __ipw2100_rx_process(priv); | ||
3209 | __ipw2100_tx_complete(priv); | ||
3210 | } | ||
3211 | |||
3212 | if (inta & IPW2100_INTA_TX_TRANSFER) { | ||
3213 | IPW_DEBUG_ISR("TX interrupt\n"); | ||
3214 | |||
3215 | priv->tx_interrupts++; | ||
3216 | |||
3217 | write_register(dev, IPW_REG_INTA, IPW2100_INTA_TX_TRANSFER); | ||
3218 | |||
3219 | __ipw2100_tx_complete(priv); | ||
3220 | ipw2100_tx_send_commands(priv); | ||
3221 | ipw2100_tx_send_data(priv); | ||
3222 | } | ||
3223 | |||
3224 | if (inta & IPW2100_INTA_TX_COMPLETE) { | ||
3225 | IPW_DEBUG_ISR("TX complete\n"); | ||
3226 | priv->inta_other++; | ||
3227 | write_register(dev, IPW_REG_INTA, IPW2100_INTA_TX_COMPLETE); | ||
3228 | |||
3229 | __ipw2100_tx_complete(priv); | ||
3230 | } | ||
3231 | |||
3232 | if (inta & IPW2100_INTA_EVENT_INTERRUPT) { | ||
3233 | /* ipw2100_handle_event(dev); */ | ||
3234 | priv->inta_other++; | ||
3235 | write_register(dev, IPW_REG_INTA, IPW2100_INTA_EVENT_INTERRUPT); | ||
3236 | } | ||
3237 | |||
3238 | if (inta & IPW2100_INTA_FW_INIT_DONE) { | ||
3239 | IPW_DEBUG_ISR("FW init done interrupt\n"); | ||
3240 | priv->inta_other++; | ||
3241 | |||
3242 | read_register(dev, IPW_REG_INTA, &tmp); | ||
3243 | if (tmp & (IPW2100_INTA_FATAL_ERROR | | ||
3244 | IPW2100_INTA_PARITY_ERROR)) { | ||
3245 | write_register(dev, IPW_REG_INTA, | ||
3246 | IPW2100_INTA_FATAL_ERROR | | ||
3247 | IPW2100_INTA_PARITY_ERROR); | ||
3248 | } | ||
3249 | |||
3250 | write_register(dev, IPW_REG_INTA, IPW2100_INTA_FW_INIT_DONE); | ||
3251 | } | ||
3252 | |||
3253 | if (inta & IPW2100_INTA_STATUS_CHANGE) { | ||
3254 | IPW_DEBUG_ISR("Status change interrupt\n"); | ||
3255 | priv->inta_other++; | ||
3256 | write_register(dev, IPW_REG_INTA, IPW2100_INTA_STATUS_CHANGE); | ||
3257 | } | ||
3258 | |||
3259 | if (inta & IPW2100_INTA_SLAVE_MODE_HOST_COMMAND_DONE) { | ||
3260 | IPW_DEBUG_ISR("slave host mode interrupt\n"); | ||
3261 | priv->inta_other++; | ||
3262 | write_register(dev, IPW_REG_INTA, | ||
3263 | IPW2100_INTA_SLAVE_MODE_HOST_COMMAND_DONE); | ||
3264 | } | ||
3265 | |||
3266 | priv->in_isr--; | ||
3267 | ipw2100_enable_interrupts(priv); | ||
3268 | |||
3269 | spin_unlock_irqrestore(&priv->low_lock, flags); | ||
3270 | |||
3271 | IPW_DEBUG_ISR("exit\n"); | ||
3272 | } | ||
3273 | |||
3274 | static irqreturn_t ipw2100_interrupt(int irq, void *data) | ||
3275 | { | ||
3276 | struct ipw2100_priv *priv = data; | ||
3277 | u32 inta, inta_mask; | ||
3278 | |||
3279 | if (!data) | ||
3280 | return IRQ_NONE; | ||
3281 | |||
3282 | spin_lock(&priv->low_lock); | ||
3283 | |||
3284 | /* We check to see if we should be ignoring interrupts before | ||
3285 | * we touch the hardware. During ucode load if we try and handle | ||
3286 | * an interrupt we can cause keyboard problems as well as cause | ||
3287 | * the ucode to fail to initialize */ | ||
3288 | if (!(priv->status & STATUS_INT_ENABLED)) { | ||
3289 | /* Shared IRQ */ | ||
3290 | goto none; | ||
3291 | } | ||
3292 | |||
3293 | read_register(priv->net_dev, IPW_REG_INTA_MASK, &inta_mask); | ||
3294 | read_register(priv->net_dev, IPW_REG_INTA, &inta); | ||
3295 | |||
3296 | if (inta == 0xFFFFFFFF) { | ||
3297 | /* Hardware disappeared */ | ||
3298 | printk(KERN_WARNING DRV_NAME ": IRQ INTA == 0xFFFFFFFF\n"); | ||
3299 | goto none; | ||
3300 | } | ||
3301 | |||
3302 | inta &= IPW_INTERRUPT_MASK; | ||
3303 | |||
3304 | if (!(inta & inta_mask)) { | ||
3305 | /* Shared interrupt */ | ||
3306 | goto none; | ||
3307 | } | ||
3308 | |||
3309 | /* We disable the hardware interrupt here just to prevent unneeded | ||
3310 | * calls to be made. We disable this again within the actual | ||
3311 | * work tasklet, so if another part of the code re-enables the | ||
3312 | * interrupt, that is fine */ | ||
3313 | ipw2100_disable_interrupts(priv); | ||
3314 | |||
3315 | tasklet_schedule(&priv->irq_tasklet); | ||
3316 | spin_unlock(&priv->low_lock); | ||
3317 | |||
3318 | return IRQ_HANDLED; | ||
3319 | none: | ||
3320 | spin_unlock(&priv->low_lock); | ||
3321 | return IRQ_NONE; | ||
3322 | } | ||
3323 | |||
3324 | static int ipw2100_tx(struct ieee80211_txb *txb, struct net_device *dev, | ||
3325 | int pri) | ||
3326 | { | ||
3327 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
3328 | struct list_head *element; | ||
3329 | struct ipw2100_tx_packet *packet; | ||
3330 | unsigned long flags; | ||
3331 | |||
3332 | spin_lock_irqsave(&priv->low_lock, flags); | ||
3333 | |||
3334 | if (!(priv->status & STATUS_ASSOCIATED)) { | ||
3335 | IPW_DEBUG_INFO("Can not transmit when not connected.\n"); | ||
3336 | priv->ieee->stats.tx_carrier_errors++; | ||
3337 | netif_stop_queue(dev); | ||
3338 | goto fail_unlock; | ||
3339 | } | ||
3340 | |||
3341 | if (list_empty(&priv->tx_free_list)) | ||
3342 | goto fail_unlock; | ||
3343 | |||
3344 | element = priv->tx_free_list.next; | ||
3345 | packet = list_entry(element, struct ipw2100_tx_packet, list); | ||
3346 | |||
3347 | packet->info.d_struct.txb = txb; | ||
3348 | |||
3349 | IPW_DEBUG_TX("Sending fragment (%d bytes):\n", txb->fragments[0]->len); | ||
3350 | printk_buf(IPW_DL_TX, txb->fragments[0]->data, txb->fragments[0]->len); | ||
3351 | |||
3352 | packet->jiffy_start = jiffies; | ||
3353 | |||
3354 | list_del(element); | ||
3355 | DEC_STAT(&priv->tx_free_stat); | ||
3356 | |||
3357 | list_add_tail(element, &priv->tx_pend_list); | ||
3358 | INC_STAT(&priv->tx_pend_stat); | ||
3359 | |||
3360 | ipw2100_tx_send_data(priv); | ||
3361 | |||
3362 | spin_unlock_irqrestore(&priv->low_lock, flags); | ||
3363 | return 0; | ||
3364 | |||
3365 | fail_unlock: | ||
3366 | netif_stop_queue(dev); | ||
3367 | spin_unlock_irqrestore(&priv->low_lock, flags); | ||
3368 | return 1; | ||
3369 | } | ||
3370 | |||
3371 | static int ipw2100_msg_allocate(struct ipw2100_priv *priv) | ||
3372 | { | ||
3373 | int i, j, err = -EINVAL; | ||
3374 | void *v; | ||
3375 | dma_addr_t p; | ||
3376 | |||
3377 | priv->msg_buffers = | ||
3378 | (struct ipw2100_tx_packet *)kmalloc(IPW_COMMAND_POOL_SIZE * | ||
3379 | sizeof(struct | ||
3380 | ipw2100_tx_packet), | ||
3381 | GFP_KERNEL); | ||
3382 | if (!priv->msg_buffers) { | ||
3383 | printk(KERN_ERR DRV_NAME ": %s: PCI alloc failed for msg " | ||
3384 | "buffers.\n", priv->net_dev->name); | ||
3385 | return -ENOMEM; | ||
3386 | } | ||
3387 | |||
3388 | for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++) { | ||
3389 | v = pci_alloc_consistent(priv->pci_dev, | ||
3390 | sizeof(struct ipw2100_cmd_header), &p); | ||
3391 | if (!v) { | ||
3392 | printk(KERN_ERR DRV_NAME ": " | ||
3393 | "%s: PCI alloc failed for msg " | ||
3394 | "buffers.\n", priv->net_dev->name); | ||
3395 | err = -ENOMEM; | ||
3396 | break; | ||
3397 | } | ||
3398 | |||
3399 | memset(v, 0, sizeof(struct ipw2100_cmd_header)); | ||
3400 | |||
3401 | priv->msg_buffers[i].type = COMMAND; | ||
3402 | priv->msg_buffers[i].info.c_struct.cmd = | ||
3403 | (struct ipw2100_cmd_header *)v; | ||
3404 | priv->msg_buffers[i].info.c_struct.cmd_phys = p; | ||
3405 | } | ||
3406 | |||
3407 | if (i == IPW_COMMAND_POOL_SIZE) | ||
3408 | return 0; | ||
3409 | |||
3410 | for (j = 0; j < i; j++) { | ||
3411 | pci_free_consistent(priv->pci_dev, | ||
3412 | sizeof(struct ipw2100_cmd_header), | ||
3413 | priv->msg_buffers[j].info.c_struct.cmd, | ||
3414 | priv->msg_buffers[j].info.c_struct. | ||
3415 | cmd_phys); | ||
3416 | } | ||
3417 | |||
3418 | kfree(priv->msg_buffers); | ||
3419 | priv->msg_buffers = NULL; | ||
3420 | |||
3421 | return err; | ||
3422 | } | ||
3423 | |||
3424 | static int ipw2100_msg_initialize(struct ipw2100_priv *priv) | ||
3425 | { | ||
3426 | int i; | ||
3427 | |||
3428 | INIT_LIST_HEAD(&priv->msg_free_list); | ||
3429 | INIT_LIST_HEAD(&priv->msg_pend_list); | ||
3430 | |||
3431 | for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++) | ||
3432 | list_add_tail(&priv->msg_buffers[i].list, &priv->msg_free_list); | ||
3433 | SET_STAT(&priv->msg_free_stat, i); | ||
3434 | |||
3435 | return 0; | ||
3436 | } | ||
3437 | |||
3438 | static void ipw2100_msg_free(struct ipw2100_priv *priv) | ||
3439 | { | ||
3440 | int i; | ||
3441 | |||
3442 | if (!priv->msg_buffers) | ||
3443 | return; | ||
3444 | |||
3445 | for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++) { | ||
3446 | pci_free_consistent(priv->pci_dev, | ||
3447 | sizeof(struct ipw2100_cmd_header), | ||
3448 | priv->msg_buffers[i].info.c_struct.cmd, | ||
3449 | priv->msg_buffers[i].info.c_struct. | ||
3450 | cmd_phys); | ||
3451 | } | ||
3452 | |||
3453 | kfree(priv->msg_buffers); | ||
3454 | priv->msg_buffers = NULL; | ||
3455 | } | ||
3456 | |||
3457 | static ssize_t show_pci(struct device *d, struct device_attribute *attr, | ||
3458 | char *buf) | ||
3459 | { | ||
3460 | struct pci_dev *pci_dev = container_of(d, struct pci_dev, dev); | ||
3461 | char *out = buf; | ||
3462 | int i, j; | ||
3463 | u32 val; | ||
3464 | |||
3465 | for (i = 0; i < 16; i++) { | ||
3466 | out += sprintf(out, "[%08X] ", i * 16); | ||
3467 | for (j = 0; j < 16; j += 4) { | ||
3468 | pci_read_config_dword(pci_dev, i * 16 + j, &val); | ||
3469 | out += sprintf(out, "%08X ", val); | ||
3470 | } | ||
3471 | out += sprintf(out, "\n"); | ||
3472 | } | ||
3473 | |||
3474 | return out - buf; | ||
3475 | } | ||
3476 | |||
3477 | static DEVICE_ATTR(pci, S_IRUGO, show_pci, NULL); | ||
3478 | |||
3479 | static ssize_t show_cfg(struct device *d, struct device_attribute *attr, | ||
3480 | char *buf) | ||
3481 | { | ||
3482 | struct ipw2100_priv *p = d->driver_data; | ||
3483 | return sprintf(buf, "0x%08x\n", (int)p->config); | ||
3484 | } | ||
3485 | |||
3486 | static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL); | ||
3487 | |||
3488 | static ssize_t show_status(struct device *d, struct device_attribute *attr, | ||
3489 | char *buf) | ||
3490 | { | ||
3491 | struct ipw2100_priv *p = d->driver_data; | ||
3492 | return sprintf(buf, "0x%08x\n", (int)p->status); | ||
3493 | } | ||
3494 | |||
3495 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); | ||
3496 | |||
3497 | static ssize_t show_capability(struct device *d, struct device_attribute *attr, | ||
3498 | char *buf) | ||
3499 | { | ||
3500 | struct ipw2100_priv *p = d->driver_data; | ||
3501 | return sprintf(buf, "0x%08x\n", (int)p->capability); | ||
3502 | } | ||
3503 | |||
3504 | static DEVICE_ATTR(capability, S_IRUGO, show_capability, NULL); | ||
3505 | |||
3506 | #define IPW2100_REG(x) { IPW_ ##x, #x } | ||
3507 | static const struct { | ||
3508 | u32 addr; | ||
3509 | const char *name; | ||
3510 | } hw_data[] = { | ||
3511 | IPW2100_REG(REG_GP_CNTRL), | ||
3512 | IPW2100_REG(REG_GPIO), | ||
3513 | IPW2100_REG(REG_INTA), | ||
3514 | IPW2100_REG(REG_INTA_MASK), IPW2100_REG(REG_RESET_REG),}; | ||
3515 | #define IPW2100_NIC(x, s) { x, #x, s } | ||
3516 | static const struct { | ||
3517 | u32 addr; | ||
3518 | const char *name; | ||
3519 | size_t size; | ||
3520 | } nic_data[] = { | ||
3521 | IPW2100_NIC(IPW2100_CONTROL_REG, 2), | ||
3522 | IPW2100_NIC(0x210014, 1), IPW2100_NIC(0x210000, 1),}; | ||
3523 | #define IPW2100_ORD(x, d) { IPW_ORD_ ##x, #x, d } | ||
3524 | static const struct { | ||
3525 | u8 index; | ||
3526 | const char *name; | ||
3527 | const char *desc; | ||
3528 | } ord_data[] = { | ||
3529 | IPW2100_ORD(STAT_TX_HOST_REQUESTS, "requested Host Tx's (MSDU)"), | ||
3530 | IPW2100_ORD(STAT_TX_HOST_COMPLETE, | ||
3531 | "successful Host Tx's (MSDU)"), | ||
3532 | IPW2100_ORD(STAT_TX_DIR_DATA, | ||
3533 | "successful Directed Tx's (MSDU)"), | ||
3534 | IPW2100_ORD(STAT_TX_DIR_DATA1, | ||
3535 | "successful Directed Tx's (MSDU) @ 1MB"), | ||
3536 | IPW2100_ORD(STAT_TX_DIR_DATA2, | ||
3537 | "successful Directed Tx's (MSDU) @ 2MB"), | ||
3538 | IPW2100_ORD(STAT_TX_DIR_DATA5_5, | ||
3539 | "successful Directed Tx's (MSDU) @ 5_5MB"), | ||
3540 | IPW2100_ORD(STAT_TX_DIR_DATA11, | ||
3541 | "successful Directed Tx's (MSDU) @ 11MB"), | ||
3542 | IPW2100_ORD(STAT_TX_NODIR_DATA1, | ||
3543 | "successful Non_Directed Tx's (MSDU) @ 1MB"), | ||
3544 | IPW2100_ORD(STAT_TX_NODIR_DATA2, | ||
3545 | "successful Non_Directed Tx's (MSDU) @ 2MB"), | ||
3546 | IPW2100_ORD(STAT_TX_NODIR_DATA5_5, | ||
3547 | "successful Non_Directed Tx's (MSDU) @ 5.5MB"), | ||
3548 | IPW2100_ORD(STAT_TX_NODIR_DATA11, | ||
3549 | "successful Non_Directed Tx's (MSDU) @ 11MB"), | ||
3550 | IPW2100_ORD(STAT_NULL_DATA, "successful NULL data Tx's"), | ||
3551 | IPW2100_ORD(STAT_TX_RTS, "successful Tx RTS"), | ||
3552 | IPW2100_ORD(STAT_TX_CTS, "successful Tx CTS"), | ||
3553 | IPW2100_ORD(STAT_TX_ACK, "successful Tx ACK"), | ||
3554 | IPW2100_ORD(STAT_TX_ASSN, "successful Association Tx's"), | ||
3555 | IPW2100_ORD(STAT_TX_ASSN_RESP, | ||
3556 | "successful Association response Tx's"), | ||
3557 | IPW2100_ORD(STAT_TX_REASSN, | ||
3558 | "successful Reassociation Tx's"), | ||
3559 | IPW2100_ORD(STAT_TX_REASSN_RESP, | ||
3560 | "successful Reassociation response Tx's"), | ||
3561 | IPW2100_ORD(STAT_TX_PROBE, | ||
3562 | "probes successfully transmitted"), | ||
3563 | IPW2100_ORD(STAT_TX_PROBE_RESP, | ||
3564 | "probe responses successfully transmitted"), | ||
3565 | IPW2100_ORD(STAT_TX_BEACON, "tx beacon"), | ||
3566 | IPW2100_ORD(STAT_TX_ATIM, "Tx ATIM"), | ||
3567 | IPW2100_ORD(STAT_TX_DISASSN, | ||
3568 | "successful Disassociation TX"), | ||
3569 | IPW2100_ORD(STAT_TX_AUTH, "successful Authentication Tx"), | ||
3570 | IPW2100_ORD(STAT_TX_DEAUTH, | ||
3571 | "successful Deauthentication TX"), | ||
3572 | IPW2100_ORD(STAT_TX_TOTAL_BYTES, | ||
3573 | "Total successful Tx data bytes"), | ||
3574 | IPW2100_ORD(STAT_TX_RETRIES, "Tx retries"), | ||
3575 | IPW2100_ORD(STAT_TX_RETRY1, "Tx retries at 1MBPS"), | ||
3576 | IPW2100_ORD(STAT_TX_RETRY2, "Tx retries at 2MBPS"), | ||
3577 | IPW2100_ORD(STAT_TX_RETRY5_5, "Tx retries at 5.5MBPS"), | ||
3578 | IPW2100_ORD(STAT_TX_RETRY11, "Tx retries at 11MBPS"), | ||
3579 | IPW2100_ORD(STAT_TX_FAILURES, "Tx Failures"), | ||
3580 | IPW2100_ORD(STAT_TX_MAX_TRIES_IN_HOP, | ||
3581 | "times max tries in a hop failed"), | ||
3582 | IPW2100_ORD(STAT_TX_DISASSN_FAIL, | ||
3583 | "times disassociation failed"), | ||
3584 | IPW2100_ORD(STAT_TX_ERR_CTS, "missed/bad CTS frames"), | ||
3585 | IPW2100_ORD(STAT_TX_ERR_ACK, "tx err due to acks"), | ||
3586 | IPW2100_ORD(STAT_RX_HOST, "packets passed to host"), | ||
3587 | IPW2100_ORD(STAT_RX_DIR_DATA, "directed packets"), | ||
3588 | IPW2100_ORD(STAT_RX_DIR_DATA1, "directed packets at 1MB"), | ||
3589 | IPW2100_ORD(STAT_RX_DIR_DATA2, "directed packets at 2MB"), | ||
3590 | IPW2100_ORD(STAT_RX_DIR_DATA5_5, | ||
3591 | "directed packets at 5.5MB"), | ||
3592 | IPW2100_ORD(STAT_RX_DIR_DATA11, "directed packets at 11MB"), | ||
3593 | IPW2100_ORD(STAT_RX_NODIR_DATA, "nondirected packets"), | ||
3594 | IPW2100_ORD(STAT_RX_NODIR_DATA1, | ||
3595 | "nondirected packets at 1MB"), | ||
3596 | IPW2100_ORD(STAT_RX_NODIR_DATA2, | ||
3597 | "nondirected packets at 2MB"), | ||
3598 | IPW2100_ORD(STAT_RX_NODIR_DATA5_5, | ||
3599 | "nondirected packets at 5.5MB"), | ||
3600 | IPW2100_ORD(STAT_RX_NODIR_DATA11, | ||
3601 | "nondirected packets at 11MB"), | ||
3602 | IPW2100_ORD(STAT_RX_NULL_DATA, "null data rx's"), | ||
3603 | IPW2100_ORD(STAT_RX_RTS, "Rx RTS"), IPW2100_ORD(STAT_RX_CTS, | ||
3604 | "Rx CTS"), | ||
3605 | IPW2100_ORD(STAT_RX_ACK, "Rx ACK"), | ||
3606 | IPW2100_ORD(STAT_RX_CFEND, "Rx CF End"), | ||
3607 | IPW2100_ORD(STAT_RX_CFEND_ACK, "Rx CF End + CF Ack"), | ||
3608 | IPW2100_ORD(STAT_RX_ASSN, "Association Rx's"), | ||
3609 | IPW2100_ORD(STAT_RX_ASSN_RESP, "Association response Rx's"), | ||
3610 | IPW2100_ORD(STAT_RX_REASSN, "Reassociation Rx's"), | ||
3611 | IPW2100_ORD(STAT_RX_REASSN_RESP, | ||
3612 | "Reassociation response Rx's"), | ||
3613 | IPW2100_ORD(STAT_RX_PROBE, "probe Rx's"), | ||
3614 | IPW2100_ORD(STAT_RX_PROBE_RESP, "probe response Rx's"), | ||
3615 | IPW2100_ORD(STAT_RX_BEACON, "Rx beacon"), | ||
3616 | IPW2100_ORD(STAT_RX_ATIM, "Rx ATIM"), | ||
3617 | IPW2100_ORD(STAT_RX_DISASSN, "disassociation Rx"), | ||
3618 | IPW2100_ORD(STAT_RX_AUTH, "authentication Rx"), | ||
3619 | IPW2100_ORD(STAT_RX_DEAUTH, "deauthentication Rx"), | ||
3620 | IPW2100_ORD(STAT_RX_TOTAL_BYTES, | ||
3621 | "Total rx data bytes received"), | ||
3622 | IPW2100_ORD(STAT_RX_ERR_CRC, "packets with Rx CRC error"), | ||
3623 | IPW2100_ORD(STAT_RX_ERR_CRC1, "Rx CRC errors at 1MB"), | ||
3624 | IPW2100_ORD(STAT_RX_ERR_CRC2, "Rx CRC errors at 2MB"), | ||
3625 | IPW2100_ORD(STAT_RX_ERR_CRC5_5, "Rx CRC errors at 5.5MB"), | ||
3626 | IPW2100_ORD(STAT_RX_ERR_CRC11, "Rx CRC errors at 11MB"), | ||
3627 | IPW2100_ORD(STAT_RX_DUPLICATE1, | ||
3628 | "duplicate rx packets at 1MB"), | ||
3629 | IPW2100_ORD(STAT_RX_DUPLICATE2, | ||
3630 | "duplicate rx packets at 2MB"), | ||
3631 | IPW2100_ORD(STAT_RX_DUPLICATE5_5, | ||
3632 | "duplicate rx packets at 5.5MB"), | ||
3633 | IPW2100_ORD(STAT_RX_DUPLICATE11, | ||
3634 | "duplicate rx packets at 11MB"), | ||
3635 | IPW2100_ORD(STAT_RX_DUPLICATE, "duplicate rx packets"), | ||
3636 | IPW2100_ORD(PERS_DB_LOCK, "locking fw permanent db"), | ||
3637 | IPW2100_ORD(PERS_DB_SIZE, "size of fw permanent db"), | ||
3638 | IPW2100_ORD(PERS_DB_ADDR, "address of fw permanent db"), | ||
3639 | IPW2100_ORD(STAT_RX_INVALID_PROTOCOL, | ||
3640 | "rx frames with invalid protocol"), | ||
3641 | IPW2100_ORD(SYS_BOOT_TIME, "Boot time"), | ||
3642 | IPW2100_ORD(STAT_RX_NO_BUFFER, | ||
3643 | "rx frames rejected due to no buffer"), | ||
3644 | IPW2100_ORD(STAT_RX_MISSING_FRAG, | ||
3645 | "rx frames dropped due to missing fragment"), | ||
3646 | IPW2100_ORD(STAT_RX_ORPHAN_FRAG, | ||
3647 | "rx frames dropped due to non-sequential fragment"), | ||
3648 | IPW2100_ORD(STAT_RX_ORPHAN_FRAME, | ||
3649 | "rx frames dropped due to unmatched 1st frame"), | ||
3650 | IPW2100_ORD(STAT_RX_FRAG_AGEOUT, | ||
3651 | "rx frames dropped due to uncompleted frame"), | ||
3652 | IPW2100_ORD(STAT_RX_ICV_ERRORS, | ||
3653 | "ICV errors during decryption"), | ||
3654 | IPW2100_ORD(STAT_PSP_SUSPENSION, "times adapter suspended"), | ||
3655 | IPW2100_ORD(STAT_PSP_BCN_TIMEOUT, "beacon timeout"), | ||
3656 | IPW2100_ORD(STAT_PSP_POLL_TIMEOUT, | ||
3657 | "poll response timeouts"), | ||
3658 | IPW2100_ORD(STAT_PSP_NONDIR_TIMEOUT, | ||
3659 | "timeouts waiting for last {broad,multi}cast pkt"), | ||
3660 | IPW2100_ORD(STAT_PSP_RX_DTIMS, "PSP DTIMs received"), | ||
3661 | IPW2100_ORD(STAT_PSP_RX_TIMS, "PSP TIMs received"), | ||
3662 | IPW2100_ORD(STAT_PSP_STATION_ID, "PSP Station ID"), | ||
3663 | IPW2100_ORD(LAST_ASSN_TIME, "RTC time of last association"), | ||
3664 | IPW2100_ORD(STAT_PERCENT_MISSED_BCNS, | ||
3665 | "current calculation of % missed beacons"), | ||
3666 | IPW2100_ORD(STAT_PERCENT_RETRIES, | ||
3667 | "current calculation of % missed tx retries"), | ||
3668 | IPW2100_ORD(ASSOCIATED_AP_PTR, | ||
3669 | "0 if not associated, else pointer to AP table entry"), | ||
3670 | IPW2100_ORD(AVAILABLE_AP_CNT, | ||
3671 | "AP's decsribed in the AP table"), | ||
3672 | IPW2100_ORD(AP_LIST_PTR, "Ptr to list of available APs"), | ||
3673 | IPW2100_ORD(STAT_AP_ASSNS, "associations"), | ||
3674 | IPW2100_ORD(STAT_ASSN_FAIL, "association failures"), | ||
3675 | IPW2100_ORD(STAT_ASSN_RESP_FAIL, | ||
3676 | "failures due to response fail"), | ||
3677 | IPW2100_ORD(STAT_FULL_SCANS, "full scans"), | ||
3678 | IPW2100_ORD(CARD_DISABLED, "Card Disabled"), | ||
3679 | IPW2100_ORD(STAT_ROAM_INHIBIT, | ||
3680 | "times roaming was inhibited due to activity"), | ||
3681 | IPW2100_ORD(RSSI_AT_ASSN, | ||
3682 | "RSSI of associated AP at time of association"), | ||
3683 | IPW2100_ORD(STAT_ASSN_CAUSE1, | ||
3684 | "reassociation: no probe response or TX on hop"), | ||
3685 | IPW2100_ORD(STAT_ASSN_CAUSE2, | ||
3686 | "reassociation: poor tx/rx quality"), | ||
3687 | IPW2100_ORD(STAT_ASSN_CAUSE3, | ||
3688 | "reassociation: tx/rx quality (excessive AP load"), | ||
3689 | IPW2100_ORD(STAT_ASSN_CAUSE4, | ||
3690 | "reassociation: AP RSSI level"), | ||
3691 | IPW2100_ORD(STAT_ASSN_CAUSE5, | ||
3692 | "reassociations due to load leveling"), | ||
3693 | IPW2100_ORD(STAT_AUTH_FAIL, "times authentication failed"), | ||
3694 | IPW2100_ORD(STAT_AUTH_RESP_FAIL, | ||
3695 | "times authentication response failed"), | ||
3696 | IPW2100_ORD(STATION_TABLE_CNT, | ||
3697 | "entries in association table"), | ||
3698 | IPW2100_ORD(RSSI_AVG_CURR, "Current avg RSSI"), | ||
3699 | IPW2100_ORD(POWER_MGMT_MODE, "Power mode - 0=CAM, 1=PSP"), | ||
3700 | IPW2100_ORD(COUNTRY_CODE, | ||
3701 | "IEEE country code as recv'd from beacon"), | ||
3702 | IPW2100_ORD(COUNTRY_CHANNELS, | ||
3703 | "channels suported by country"), | ||
3704 | IPW2100_ORD(RESET_CNT, "adapter resets (warm)"), | ||
3705 | IPW2100_ORD(BEACON_INTERVAL, "Beacon interval"), | ||
3706 | IPW2100_ORD(ANTENNA_DIVERSITY, | ||
3707 | "TRUE if antenna diversity is disabled"), | ||
3708 | IPW2100_ORD(DTIM_PERIOD, "beacon intervals between DTIMs"), | ||
3709 | IPW2100_ORD(OUR_FREQ, | ||
3710 | "current radio freq lower digits - channel ID"), | ||
3711 | IPW2100_ORD(RTC_TIME, "current RTC time"), | ||
3712 | IPW2100_ORD(PORT_TYPE, "operating mode"), | ||
3713 | IPW2100_ORD(CURRENT_TX_RATE, "current tx rate"), | ||
3714 | IPW2100_ORD(SUPPORTED_RATES, "supported tx rates"), | ||
3715 | IPW2100_ORD(ATIM_WINDOW, "current ATIM Window"), | ||
3716 | IPW2100_ORD(BASIC_RATES, "basic tx rates"), | ||
3717 | IPW2100_ORD(NIC_HIGHEST_RATE, "NIC highest tx rate"), | ||
3718 | IPW2100_ORD(AP_HIGHEST_RATE, "AP highest tx rate"), | ||
3719 | IPW2100_ORD(CAPABILITIES, | ||
3720 | "Management frame capability field"), | ||
3721 | IPW2100_ORD(AUTH_TYPE, "Type of authentication"), | ||
3722 | IPW2100_ORD(RADIO_TYPE, "Adapter card platform type"), | ||
3723 | IPW2100_ORD(RTS_THRESHOLD, | ||
3724 | "Min packet length for RTS handshaking"), | ||
3725 | IPW2100_ORD(INT_MODE, "International mode"), | ||
3726 | IPW2100_ORD(FRAGMENTATION_THRESHOLD, | ||
3727 | "protocol frag threshold"), | ||
3728 | IPW2100_ORD(EEPROM_SRAM_DB_BLOCK_START_ADDRESS, | ||
3729 | "EEPROM offset in SRAM"), | ||
3730 | IPW2100_ORD(EEPROM_SRAM_DB_BLOCK_SIZE, | ||
3731 | "EEPROM size in SRAM"), | ||
3732 | IPW2100_ORD(EEPROM_SKU_CAPABILITY, "EEPROM SKU Capability"), | ||
3733 | IPW2100_ORD(EEPROM_IBSS_11B_CHANNELS, | ||
3734 | "EEPROM IBSS 11b channel set"), | ||
3735 | IPW2100_ORD(MAC_VERSION, "MAC Version"), | ||
3736 | IPW2100_ORD(MAC_REVISION, "MAC Revision"), | ||
3737 | IPW2100_ORD(RADIO_VERSION, "Radio Version"), | ||
3738 | IPW2100_ORD(NIC_MANF_DATE_TIME, "MANF Date/Time STAMP"), | ||
3739 | IPW2100_ORD(UCODE_VERSION, "Ucode Version"),}; | ||
3740 | |||
3741 | static ssize_t show_registers(struct device *d, struct device_attribute *attr, | ||
3742 | char *buf) | ||
3743 | { | ||
3744 | int i; | ||
3745 | struct ipw2100_priv *priv = dev_get_drvdata(d); | ||
3746 | struct net_device *dev = priv->net_dev; | ||
3747 | char *out = buf; | ||
3748 | u32 val = 0; | ||
3749 | |||
3750 | out += sprintf(out, "%30s [Address ] : Hex\n", "Register"); | ||
3751 | |||
3752 | for (i = 0; i < ARRAY_SIZE(hw_data); i++) { | ||
3753 | read_register(dev, hw_data[i].addr, &val); | ||
3754 | out += sprintf(out, "%30s [%08X] : %08X\n", | ||
3755 | hw_data[i].name, hw_data[i].addr, val); | ||
3756 | } | ||
3757 | |||
3758 | return out - buf; | ||
3759 | } | ||
3760 | |||
3761 | static DEVICE_ATTR(registers, S_IRUGO, show_registers, NULL); | ||
3762 | |||
3763 | static ssize_t show_hardware(struct device *d, struct device_attribute *attr, | ||
3764 | char *buf) | ||
3765 | { | ||
3766 | struct ipw2100_priv *priv = dev_get_drvdata(d); | ||
3767 | struct net_device *dev = priv->net_dev; | ||
3768 | char *out = buf; | ||
3769 | int i; | ||
3770 | |||
3771 | out += sprintf(out, "%30s [Address ] : Hex\n", "NIC entry"); | ||
3772 | |||
3773 | for (i = 0; i < ARRAY_SIZE(nic_data); i++) { | ||
3774 | u8 tmp8; | ||
3775 | u16 tmp16; | ||
3776 | u32 tmp32; | ||
3777 | |||
3778 | switch (nic_data[i].size) { | ||
3779 | case 1: | ||
3780 | read_nic_byte(dev, nic_data[i].addr, &tmp8); | ||
3781 | out += sprintf(out, "%30s [%08X] : %02X\n", | ||
3782 | nic_data[i].name, nic_data[i].addr, | ||
3783 | tmp8); | ||
3784 | break; | ||
3785 | case 2: | ||
3786 | read_nic_word(dev, nic_data[i].addr, &tmp16); | ||
3787 | out += sprintf(out, "%30s [%08X] : %04X\n", | ||
3788 | nic_data[i].name, nic_data[i].addr, | ||
3789 | tmp16); | ||
3790 | break; | ||
3791 | case 4: | ||
3792 | read_nic_dword(dev, nic_data[i].addr, &tmp32); | ||
3793 | out += sprintf(out, "%30s [%08X] : %08X\n", | ||
3794 | nic_data[i].name, nic_data[i].addr, | ||
3795 | tmp32); | ||
3796 | break; | ||
3797 | } | ||
3798 | } | ||
3799 | return out - buf; | ||
3800 | } | ||
3801 | |||
3802 | static DEVICE_ATTR(hardware, S_IRUGO, show_hardware, NULL); | ||
3803 | |||
3804 | static ssize_t show_memory(struct device *d, struct device_attribute *attr, | ||
3805 | char *buf) | ||
3806 | { | ||
3807 | struct ipw2100_priv *priv = dev_get_drvdata(d); | ||
3808 | struct net_device *dev = priv->net_dev; | ||
3809 | static unsigned long loop = 0; | ||
3810 | int len = 0; | ||
3811 | u32 buffer[4]; | ||
3812 | int i; | ||
3813 | char line[81]; | ||
3814 | |||
3815 | if (loop >= 0x30000) | ||
3816 | loop = 0; | ||
3817 | |||
3818 | /* sysfs provides us PAGE_SIZE buffer */ | ||
3819 | while (len < PAGE_SIZE - 128 && loop < 0x30000) { | ||
3820 | |||
3821 | if (priv->snapshot[0]) | ||
3822 | for (i = 0; i < 4; i++) | ||
3823 | buffer[i] = | ||
3824 | *(u32 *) SNAPSHOT_ADDR(loop + i * 4); | ||
3825 | else | ||
3826 | for (i = 0; i < 4; i++) | ||
3827 | read_nic_dword(dev, loop + i * 4, &buffer[i]); | ||
3828 | |||
3829 | if (priv->dump_raw) | ||
3830 | len += sprintf(buf + len, | ||
3831 | "%c%c%c%c" | ||
3832 | "%c%c%c%c" | ||
3833 | "%c%c%c%c" | ||
3834 | "%c%c%c%c", | ||
3835 | ((u8 *) buffer)[0x0], | ||
3836 | ((u8 *) buffer)[0x1], | ||
3837 | ((u8 *) buffer)[0x2], | ||
3838 | ((u8 *) buffer)[0x3], | ||
3839 | ((u8 *) buffer)[0x4], | ||
3840 | ((u8 *) buffer)[0x5], | ||
3841 | ((u8 *) buffer)[0x6], | ||
3842 | ((u8 *) buffer)[0x7], | ||
3843 | ((u8 *) buffer)[0x8], | ||
3844 | ((u8 *) buffer)[0x9], | ||
3845 | ((u8 *) buffer)[0xa], | ||
3846 | ((u8 *) buffer)[0xb], | ||
3847 | ((u8 *) buffer)[0xc], | ||
3848 | ((u8 *) buffer)[0xd], | ||
3849 | ((u8 *) buffer)[0xe], | ||
3850 | ((u8 *) buffer)[0xf]); | ||
3851 | else | ||
3852 | len += sprintf(buf + len, "%s\n", | ||
3853 | snprint_line(line, sizeof(line), | ||
3854 | (u8 *) buffer, 16, loop)); | ||
3855 | loop += 16; | ||
3856 | } | ||
3857 | |||
3858 | return len; | ||
3859 | } | ||
3860 | |||
3861 | static ssize_t store_memory(struct device *d, struct device_attribute *attr, | ||
3862 | const char *buf, size_t count) | ||
3863 | { | ||
3864 | struct ipw2100_priv *priv = dev_get_drvdata(d); | ||
3865 | struct net_device *dev = priv->net_dev; | ||
3866 | const char *p = buf; | ||
3867 | |||
3868 | (void)dev; /* kill unused-var warning for debug-only code */ | ||
3869 | |||
3870 | if (count < 1) | ||
3871 | return count; | ||
3872 | |||
3873 | if (p[0] == '1' || | ||
3874 | (count >= 2 && tolower(p[0]) == 'o' && tolower(p[1]) == 'n')) { | ||
3875 | IPW_DEBUG_INFO("%s: Setting memory dump to RAW mode.\n", | ||
3876 | dev->name); | ||
3877 | priv->dump_raw = 1; | ||
3878 | |||
3879 | } else if (p[0] == '0' || (count >= 2 && tolower(p[0]) == 'o' && | ||
3880 | tolower(p[1]) == 'f')) { | ||
3881 | IPW_DEBUG_INFO("%s: Setting memory dump to HEX mode.\n", | ||
3882 | dev->name); | ||
3883 | priv->dump_raw = 0; | ||
3884 | |||
3885 | } else if (tolower(p[0]) == 'r') { | ||
3886 | IPW_DEBUG_INFO("%s: Resetting firmware snapshot.\n", dev->name); | ||
3887 | ipw2100_snapshot_free(priv); | ||
3888 | |||
3889 | } else | ||
3890 | IPW_DEBUG_INFO("%s: Usage: 0|on = HEX, 1|off = RAW, " | ||
3891 | "reset = clear memory snapshot\n", dev->name); | ||
3892 | |||
3893 | return count; | ||
3894 | } | ||
3895 | |||
3896 | static DEVICE_ATTR(memory, S_IWUSR | S_IRUGO, show_memory, store_memory); | ||
3897 | |||
3898 | static ssize_t show_ordinals(struct device *d, struct device_attribute *attr, | ||
3899 | char *buf) | ||
3900 | { | ||
3901 | struct ipw2100_priv *priv = dev_get_drvdata(d); | ||
3902 | u32 val = 0; | ||
3903 | int len = 0; | ||
3904 | u32 val_len; | ||
3905 | static int loop = 0; | ||
3906 | |||
3907 | if (priv->status & STATUS_RF_KILL_MASK) | ||
3908 | return 0; | ||
3909 | |||
3910 | if (loop >= ARRAY_SIZE(ord_data)) | ||
3911 | loop = 0; | ||
3912 | |||
3913 | /* sysfs provides us PAGE_SIZE buffer */ | ||
3914 | while (len < PAGE_SIZE - 128 && loop < ARRAY_SIZE(ord_data)) { | ||
3915 | val_len = sizeof(u32); | ||
3916 | |||
3917 | if (ipw2100_get_ordinal(priv, ord_data[loop].index, &val, | ||
3918 | &val_len)) | ||
3919 | len += sprintf(buf + len, "[0x%02X] = ERROR %s\n", | ||
3920 | ord_data[loop].index, | ||
3921 | ord_data[loop].desc); | ||
3922 | else | ||
3923 | len += sprintf(buf + len, "[0x%02X] = 0x%08X %s\n", | ||
3924 | ord_data[loop].index, val, | ||
3925 | ord_data[loop].desc); | ||
3926 | loop++; | ||
3927 | } | ||
3928 | |||
3929 | return len; | ||
3930 | } | ||
3931 | |||
3932 | static DEVICE_ATTR(ordinals, S_IRUGO, show_ordinals, NULL); | ||
3933 | |||
3934 | static ssize_t show_stats(struct device *d, struct device_attribute *attr, | ||
3935 | char *buf) | ||
3936 | { | ||
3937 | struct ipw2100_priv *priv = dev_get_drvdata(d); | ||
3938 | char *out = buf; | ||
3939 | |||
3940 | out += sprintf(out, "interrupts: %d {tx: %d, rx: %d, other: %d}\n", | ||
3941 | priv->interrupts, priv->tx_interrupts, | ||
3942 | priv->rx_interrupts, priv->inta_other); | ||
3943 | out += sprintf(out, "firmware resets: %d\n", priv->resets); | ||
3944 | out += sprintf(out, "firmware hangs: %d\n", priv->hangs); | ||
3945 | #ifdef CONFIG_IPW2100_DEBUG | ||
3946 | out += sprintf(out, "packet mismatch image: %s\n", | ||
3947 | priv->snapshot[0] ? "YES" : "NO"); | ||
3948 | #endif | ||
3949 | |||
3950 | return out - buf; | ||
3951 | } | ||
3952 | |||
3953 | static DEVICE_ATTR(stats, S_IRUGO, show_stats, NULL); | ||
3954 | |||
3955 | static int ipw2100_switch_mode(struct ipw2100_priv *priv, u32 mode) | ||
3956 | { | ||
3957 | int err; | ||
3958 | |||
3959 | if (mode == priv->ieee->iw_mode) | ||
3960 | return 0; | ||
3961 | |||
3962 | err = ipw2100_disable_adapter(priv); | ||
3963 | if (err) { | ||
3964 | printk(KERN_ERR DRV_NAME ": %s: Could not disable adapter %d\n", | ||
3965 | priv->net_dev->name, err); | ||
3966 | return err; | ||
3967 | } | ||
3968 | |||
3969 | switch (mode) { | ||
3970 | case IW_MODE_INFRA: | ||
3971 | priv->net_dev->type = ARPHRD_ETHER; | ||
3972 | break; | ||
3973 | case IW_MODE_ADHOC: | ||
3974 | priv->net_dev->type = ARPHRD_ETHER; | ||
3975 | break; | ||
3976 | #ifdef CONFIG_IPW2100_MONITOR | ||
3977 | case IW_MODE_MONITOR: | ||
3978 | priv->last_mode = priv->ieee->iw_mode; | ||
3979 | priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; | ||
3980 | break; | ||
3981 | #endif /* CONFIG_IPW2100_MONITOR */ | ||
3982 | } | ||
3983 | |||
3984 | priv->ieee->iw_mode = mode; | ||
3985 | |||
3986 | #ifdef CONFIG_PM | ||
3987 | /* Indicate ipw2100_download_firmware download firmware | ||
3988 | * from disk instead of memory. */ | ||
3989 | ipw2100_firmware.version = 0; | ||
3990 | #endif | ||
3991 | |||
3992 | printk(KERN_INFO "%s: Reseting on mode change.\n", priv->net_dev->name); | ||
3993 | priv->reset_backoff = 0; | ||
3994 | schedule_reset(priv); | ||
3995 | |||
3996 | return 0; | ||
3997 | } | ||
3998 | |||
3999 | static ssize_t show_internals(struct device *d, struct device_attribute *attr, | ||
4000 | char *buf) | ||
4001 | { | ||
4002 | struct ipw2100_priv *priv = dev_get_drvdata(d); | ||
4003 | int len = 0; | ||
4004 | |||
4005 | #define DUMP_VAR(x,y) len += sprintf(buf + len, # x ": %" y "\n", priv-> x) | ||
4006 | |||
4007 | if (priv->status & STATUS_ASSOCIATED) | ||
4008 | len += sprintf(buf + len, "connected: %lu\n", | ||
4009 | get_seconds() - priv->connect_start); | ||
4010 | else | ||
4011 | len += sprintf(buf + len, "not connected\n"); | ||
4012 | |||
4013 | DUMP_VAR(ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx], "p"); | ||
4014 | DUMP_VAR(status, "08lx"); | ||
4015 | DUMP_VAR(config, "08lx"); | ||
4016 | DUMP_VAR(capability, "08lx"); | ||
4017 | |||
4018 | len += | ||
4019 | sprintf(buf + len, "last_rtc: %lu\n", | ||
4020 | (unsigned long)priv->last_rtc); | ||
4021 | |||
4022 | DUMP_VAR(fatal_error, "d"); | ||
4023 | DUMP_VAR(stop_hang_check, "d"); | ||
4024 | DUMP_VAR(stop_rf_kill, "d"); | ||
4025 | DUMP_VAR(messages_sent, "d"); | ||
4026 | |||
4027 | DUMP_VAR(tx_pend_stat.value, "d"); | ||
4028 | DUMP_VAR(tx_pend_stat.hi, "d"); | ||
4029 | |||
4030 | DUMP_VAR(tx_free_stat.value, "d"); | ||
4031 | DUMP_VAR(tx_free_stat.lo, "d"); | ||
4032 | |||
4033 | DUMP_VAR(msg_free_stat.value, "d"); | ||
4034 | DUMP_VAR(msg_free_stat.lo, "d"); | ||
4035 | |||
4036 | DUMP_VAR(msg_pend_stat.value, "d"); | ||
4037 | DUMP_VAR(msg_pend_stat.hi, "d"); | ||
4038 | |||
4039 | DUMP_VAR(fw_pend_stat.value, "d"); | ||
4040 | DUMP_VAR(fw_pend_stat.hi, "d"); | ||
4041 | |||
4042 | DUMP_VAR(txq_stat.value, "d"); | ||
4043 | DUMP_VAR(txq_stat.lo, "d"); | ||
4044 | |||
4045 | DUMP_VAR(ieee->scans, "d"); | ||
4046 | DUMP_VAR(reset_backoff, "d"); | ||
4047 | |||
4048 | return len; | ||
4049 | } | ||
4050 | |||
4051 | static DEVICE_ATTR(internals, S_IRUGO, show_internals, NULL); | ||
4052 | |||
4053 | static ssize_t show_bssinfo(struct device *d, struct device_attribute *attr, | ||
4054 | char *buf) | ||
4055 | { | ||
4056 | struct ipw2100_priv *priv = dev_get_drvdata(d); | ||
4057 | char essid[IW_ESSID_MAX_SIZE + 1]; | ||
4058 | u8 bssid[ETH_ALEN]; | ||
4059 | u32 chan = 0; | ||
4060 | char *out = buf; | ||
4061 | int length; | ||
4062 | int ret; | ||
4063 | |||
4064 | if (priv->status & STATUS_RF_KILL_MASK) | ||
4065 | return 0; | ||
4066 | |||
4067 | memset(essid, 0, sizeof(essid)); | ||
4068 | memset(bssid, 0, sizeof(bssid)); | ||
4069 | |||
4070 | length = IW_ESSID_MAX_SIZE; | ||
4071 | ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_SSID, essid, &length); | ||
4072 | if (ret) | ||
4073 | IPW_DEBUG_INFO("failed querying ordinals at line %d\n", | ||
4074 | __LINE__); | ||
4075 | |||
4076 | length = sizeof(bssid); | ||
4077 | ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID, | ||
4078 | bssid, &length); | ||
4079 | if (ret) | ||
4080 | IPW_DEBUG_INFO("failed querying ordinals at line %d\n", | ||
4081 | __LINE__); | ||
4082 | |||
4083 | length = sizeof(u32); | ||
4084 | ret = ipw2100_get_ordinal(priv, IPW_ORD_OUR_FREQ, &chan, &length); | ||
4085 | if (ret) | ||
4086 | IPW_DEBUG_INFO("failed querying ordinals at line %d\n", | ||
4087 | __LINE__); | ||
4088 | |||
4089 | out += sprintf(out, "ESSID: %s\n", essid); | ||
4090 | out += sprintf(out, "BSSID: %pM\n", bssid); | ||
4091 | out += sprintf(out, "Channel: %d\n", chan); | ||
4092 | |||
4093 | return out - buf; | ||
4094 | } | ||
4095 | |||
4096 | static DEVICE_ATTR(bssinfo, S_IRUGO, show_bssinfo, NULL); | ||
4097 | |||
4098 | #ifdef CONFIG_IPW2100_DEBUG | ||
4099 | static ssize_t show_debug_level(struct device_driver *d, char *buf) | ||
4100 | { | ||
4101 | return sprintf(buf, "0x%08X\n", ipw2100_debug_level); | ||
4102 | } | ||
4103 | |||
4104 | static ssize_t store_debug_level(struct device_driver *d, | ||
4105 | const char *buf, size_t count) | ||
4106 | { | ||
4107 | char *p = (char *)buf; | ||
4108 | u32 val; | ||
4109 | |||
4110 | if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') { | ||
4111 | p++; | ||
4112 | if (p[0] == 'x' || p[0] == 'X') | ||
4113 | p++; | ||
4114 | val = simple_strtoul(p, &p, 16); | ||
4115 | } else | ||
4116 | val = simple_strtoul(p, &p, 10); | ||
4117 | if (p == buf) | ||
4118 | IPW_DEBUG_INFO(": %s is not in hex or decimal form.\n", buf); | ||
4119 | else | ||
4120 | ipw2100_debug_level = val; | ||
4121 | |||
4122 | return strnlen(buf, count); | ||
4123 | } | ||
4124 | |||
4125 | static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, show_debug_level, | ||
4126 | store_debug_level); | ||
4127 | #endif /* CONFIG_IPW2100_DEBUG */ | ||
4128 | |||
4129 | static ssize_t show_fatal_error(struct device *d, | ||
4130 | struct device_attribute *attr, char *buf) | ||
4131 | { | ||
4132 | struct ipw2100_priv *priv = dev_get_drvdata(d); | ||
4133 | char *out = buf; | ||
4134 | int i; | ||
4135 | |||
4136 | if (priv->fatal_error) | ||
4137 | out += sprintf(out, "0x%08X\n", priv->fatal_error); | ||
4138 | else | ||
4139 | out += sprintf(out, "0\n"); | ||
4140 | |||
4141 | for (i = 1; i <= IPW2100_ERROR_QUEUE; i++) { | ||
4142 | if (!priv->fatal_errors[(priv->fatal_index - i) % | ||
4143 | IPW2100_ERROR_QUEUE]) | ||
4144 | continue; | ||
4145 | |||
4146 | out += sprintf(out, "%d. 0x%08X\n", i, | ||
4147 | priv->fatal_errors[(priv->fatal_index - i) % | ||
4148 | IPW2100_ERROR_QUEUE]); | ||
4149 | } | ||
4150 | |||
4151 | return out - buf; | ||
4152 | } | ||
4153 | |||
4154 | static ssize_t store_fatal_error(struct device *d, | ||
4155 | struct device_attribute *attr, const char *buf, | ||
4156 | size_t count) | ||
4157 | { | ||
4158 | struct ipw2100_priv *priv = dev_get_drvdata(d); | ||
4159 | schedule_reset(priv); | ||
4160 | return count; | ||
4161 | } | ||
4162 | |||
4163 | static DEVICE_ATTR(fatal_error, S_IWUSR | S_IRUGO, show_fatal_error, | ||
4164 | store_fatal_error); | ||
4165 | |||
4166 | static ssize_t show_scan_age(struct device *d, struct device_attribute *attr, | ||
4167 | char *buf) | ||
4168 | { | ||
4169 | struct ipw2100_priv *priv = dev_get_drvdata(d); | ||
4170 | return sprintf(buf, "%d\n", priv->ieee->scan_age); | ||
4171 | } | ||
4172 | |||
4173 | static ssize_t store_scan_age(struct device *d, struct device_attribute *attr, | ||
4174 | const char *buf, size_t count) | ||
4175 | { | ||
4176 | struct ipw2100_priv *priv = dev_get_drvdata(d); | ||
4177 | struct net_device *dev = priv->net_dev; | ||
4178 | char buffer[] = "00000000"; | ||
4179 | unsigned long len = | ||
4180 | (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1; | ||
4181 | unsigned long val; | ||
4182 | char *p = buffer; | ||
4183 | |||
4184 | (void)dev; /* kill unused-var warning for debug-only code */ | ||
4185 | |||
4186 | IPW_DEBUG_INFO("enter\n"); | ||
4187 | |||
4188 | strncpy(buffer, buf, len); | ||
4189 | buffer[len] = 0; | ||
4190 | |||
4191 | if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') { | ||
4192 | p++; | ||
4193 | if (p[0] == 'x' || p[0] == 'X') | ||
4194 | p++; | ||
4195 | val = simple_strtoul(p, &p, 16); | ||
4196 | } else | ||
4197 | val = simple_strtoul(p, &p, 10); | ||
4198 | if (p == buffer) { | ||
4199 | IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name); | ||
4200 | } else { | ||
4201 | priv->ieee->scan_age = val; | ||
4202 | IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age); | ||
4203 | } | ||
4204 | |||
4205 | IPW_DEBUG_INFO("exit\n"); | ||
4206 | return len; | ||
4207 | } | ||
4208 | |||
4209 | static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age); | ||
4210 | |||
4211 | static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr, | ||
4212 | char *buf) | ||
4213 | { | ||
4214 | /* 0 - RF kill not enabled | ||
4215 | 1 - SW based RF kill active (sysfs) | ||
4216 | 2 - HW based RF kill active | ||
4217 | 3 - Both HW and SW baed RF kill active */ | ||
4218 | struct ipw2100_priv *priv = (struct ipw2100_priv *)d->driver_data; | ||
4219 | int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) | | ||
4220 | (rf_kill_active(priv) ? 0x2 : 0x0); | ||
4221 | return sprintf(buf, "%i\n", val); | ||
4222 | } | ||
4223 | |||
4224 | static int ipw_radio_kill_sw(struct ipw2100_priv *priv, int disable_radio) | ||
4225 | { | ||
4226 | if ((disable_radio ? 1 : 0) == | ||
4227 | (priv->status & STATUS_RF_KILL_SW ? 1 : 0)) | ||
4228 | return 0; | ||
4229 | |||
4230 | IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n", | ||
4231 | disable_radio ? "OFF" : "ON"); | ||
4232 | |||
4233 | mutex_lock(&priv->action_mutex); | ||
4234 | |||
4235 | if (disable_radio) { | ||
4236 | priv->status |= STATUS_RF_KILL_SW; | ||
4237 | ipw2100_down(priv); | ||
4238 | } else { | ||
4239 | priv->status &= ~STATUS_RF_KILL_SW; | ||
4240 | if (rf_kill_active(priv)) { | ||
4241 | IPW_DEBUG_RF_KILL("Can not turn radio back on - " | ||
4242 | "disabled by HW switch\n"); | ||
4243 | /* Make sure the RF_KILL check timer is running */ | ||
4244 | priv->stop_rf_kill = 0; | ||
4245 | cancel_delayed_work(&priv->rf_kill); | ||
4246 | queue_delayed_work(priv->workqueue, &priv->rf_kill, | ||
4247 | round_jiffies_relative(HZ)); | ||
4248 | } else | ||
4249 | schedule_reset(priv); | ||
4250 | } | ||
4251 | |||
4252 | mutex_unlock(&priv->action_mutex); | ||
4253 | return 1; | ||
4254 | } | ||
4255 | |||
4256 | static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr, | ||
4257 | const char *buf, size_t count) | ||
4258 | { | ||
4259 | struct ipw2100_priv *priv = dev_get_drvdata(d); | ||
4260 | ipw_radio_kill_sw(priv, buf[0] == '1'); | ||
4261 | return count; | ||
4262 | } | ||
4263 | |||
4264 | static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill); | ||
4265 | |||
4266 | static struct attribute *ipw2100_sysfs_entries[] = { | ||
4267 | &dev_attr_hardware.attr, | ||
4268 | &dev_attr_registers.attr, | ||
4269 | &dev_attr_ordinals.attr, | ||
4270 | &dev_attr_pci.attr, | ||
4271 | &dev_attr_stats.attr, | ||
4272 | &dev_attr_internals.attr, | ||
4273 | &dev_attr_bssinfo.attr, | ||
4274 | &dev_attr_memory.attr, | ||
4275 | &dev_attr_scan_age.attr, | ||
4276 | &dev_attr_fatal_error.attr, | ||
4277 | &dev_attr_rf_kill.attr, | ||
4278 | &dev_attr_cfg.attr, | ||
4279 | &dev_attr_status.attr, | ||
4280 | &dev_attr_capability.attr, | ||
4281 | NULL, | ||
4282 | }; | ||
4283 | |||
4284 | static struct attribute_group ipw2100_attribute_group = { | ||
4285 | .attrs = ipw2100_sysfs_entries, | ||
4286 | }; | ||
4287 | |||
4288 | static int status_queue_allocate(struct ipw2100_priv *priv, int entries) | ||
4289 | { | ||
4290 | struct ipw2100_status_queue *q = &priv->status_queue; | ||
4291 | |||
4292 | IPW_DEBUG_INFO("enter\n"); | ||
4293 | |||
4294 | q->size = entries * sizeof(struct ipw2100_status); | ||
4295 | q->drv = | ||
4296 | (struct ipw2100_status *)pci_alloc_consistent(priv->pci_dev, | ||
4297 | q->size, &q->nic); | ||
4298 | if (!q->drv) { | ||
4299 | IPW_DEBUG_WARNING("Can not allocate status queue.\n"); | ||
4300 | return -ENOMEM; | ||
4301 | } | ||
4302 | |||
4303 | memset(q->drv, 0, q->size); | ||
4304 | |||
4305 | IPW_DEBUG_INFO("exit\n"); | ||
4306 | |||
4307 | return 0; | ||
4308 | } | ||
4309 | |||
4310 | static void status_queue_free(struct ipw2100_priv *priv) | ||
4311 | { | ||
4312 | IPW_DEBUG_INFO("enter\n"); | ||
4313 | |||
4314 | if (priv->status_queue.drv) { | ||
4315 | pci_free_consistent(priv->pci_dev, priv->status_queue.size, | ||
4316 | priv->status_queue.drv, | ||
4317 | priv->status_queue.nic); | ||
4318 | priv->status_queue.drv = NULL; | ||
4319 | } | ||
4320 | |||
4321 | IPW_DEBUG_INFO("exit\n"); | ||
4322 | } | ||
4323 | |||
4324 | static int bd_queue_allocate(struct ipw2100_priv *priv, | ||
4325 | struct ipw2100_bd_queue *q, int entries) | ||
4326 | { | ||
4327 | IPW_DEBUG_INFO("enter\n"); | ||
4328 | |||
4329 | memset(q, 0, sizeof(struct ipw2100_bd_queue)); | ||
4330 | |||
4331 | q->entries = entries; | ||
4332 | q->size = entries * sizeof(struct ipw2100_bd); | ||
4333 | q->drv = pci_alloc_consistent(priv->pci_dev, q->size, &q->nic); | ||
4334 | if (!q->drv) { | ||
4335 | IPW_DEBUG_INFO | ||
4336 | ("can't allocate shared memory for buffer descriptors\n"); | ||
4337 | return -ENOMEM; | ||
4338 | } | ||
4339 | memset(q->drv, 0, q->size); | ||
4340 | |||
4341 | IPW_DEBUG_INFO("exit\n"); | ||
4342 | |||
4343 | return 0; | ||
4344 | } | ||
4345 | |||
4346 | static void bd_queue_free(struct ipw2100_priv *priv, struct ipw2100_bd_queue *q) | ||
4347 | { | ||
4348 | IPW_DEBUG_INFO("enter\n"); | ||
4349 | |||
4350 | if (!q) | ||
4351 | return; | ||
4352 | |||
4353 | if (q->drv) { | ||
4354 | pci_free_consistent(priv->pci_dev, q->size, q->drv, q->nic); | ||
4355 | q->drv = NULL; | ||
4356 | } | ||
4357 | |||
4358 | IPW_DEBUG_INFO("exit\n"); | ||
4359 | } | ||
4360 | |||
4361 | static void bd_queue_initialize(struct ipw2100_priv *priv, | ||
4362 | struct ipw2100_bd_queue *q, u32 base, u32 size, | ||
4363 | u32 r, u32 w) | ||
4364 | { | ||
4365 | IPW_DEBUG_INFO("enter\n"); | ||
4366 | |||
4367 | IPW_DEBUG_INFO("initializing bd queue at virt=%p, phys=%08x\n", q->drv, | ||
4368 | (u32) q->nic); | ||
4369 | |||
4370 | write_register(priv->net_dev, base, q->nic); | ||
4371 | write_register(priv->net_dev, size, q->entries); | ||
4372 | write_register(priv->net_dev, r, q->oldest); | ||
4373 | write_register(priv->net_dev, w, q->next); | ||
4374 | |||
4375 | IPW_DEBUG_INFO("exit\n"); | ||
4376 | } | ||
4377 | |||
4378 | static void ipw2100_kill_workqueue(struct ipw2100_priv *priv) | ||
4379 | { | ||
4380 | if (priv->workqueue) { | ||
4381 | priv->stop_rf_kill = 1; | ||
4382 | priv->stop_hang_check = 1; | ||
4383 | cancel_delayed_work(&priv->reset_work); | ||
4384 | cancel_delayed_work(&priv->security_work); | ||
4385 | cancel_delayed_work(&priv->wx_event_work); | ||
4386 | cancel_delayed_work(&priv->hang_check); | ||
4387 | cancel_delayed_work(&priv->rf_kill); | ||
4388 | cancel_delayed_work(&priv->scan_event_later); | ||
4389 | destroy_workqueue(priv->workqueue); | ||
4390 | priv->workqueue = NULL; | ||
4391 | } | ||
4392 | } | ||
4393 | |||
4394 | static int ipw2100_tx_allocate(struct ipw2100_priv *priv) | ||
4395 | { | ||
4396 | int i, j, err = -EINVAL; | ||
4397 | void *v; | ||
4398 | dma_addr_t p; | ||
4399 | |||
4400 | IPW_DEBUG_INFO("enter\n"); | ||
4401 | |||
4402 | err = bd_queue_allocate(priv, &priv->tx_queue, TX_QUEUE_LENGTH); | ||
4403 | if (err) { | ||
4404 | IPW_DEBUG_ERROR("%s: failed bd_queue_allocate\n", | ||
4405 | priv->net_dev->name); | ||
4406 | return err; | ||
4407 | } | ||
4408 | |||
4409 | priv->tx_buffers = | ||
4410 | (struct ipw2100_tx_packet *)kmalloc(TX_PENDED_QUEUE_LENGTH * | ||
4411 | sizeof(struct | ||
4412 | ipw2100_tx_packet), | ||
4413 | GFP_ATOMIC); | ||
4414 | if (!priv->tx_buffers) { | ||
4415 | printk(KERN_ERR DRV_NAME | ||
4416 | ": %s: alloc failed form tx buffers.\n", | ||
4417 | priv->net_dev->name); | ||
4418 | bd_queue_free(priv, &priv->tx_queue); | ||
4419 | return -ENOMEM; | ||
4420 | } | ||
4421 | |||
4422 | for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) { | ||
4423 | v = pci_alloc_consistent(priv->pci_dev, | ||
4424 | sizeof(struct ipw2100_data_header), | ||
4425 | &p); | ||
4426 | if (!v) { | ||
4427 | printk(KERN_ERR DRV_NAME | ||
4428 | ": %s: PCI alloc failed for tx " "buffers.\n", | ||
4429 | priv->net_dev->name); | ||
4430 | err = -ENOMEM; | ||
4431 | break; | ||
4432 | } | ||
4433 | |||
4434 | priv->tx_buffers[i].type = DATA; | ||
4435 | priv->tx_buffers[i].info.d_struct.data = | ||
4436 | (struct ipw2100_data_header *)v; | ||
4437 | priv->tx_buffers[i].info.d_struct.data_phys = p; | ||
4438 | priv->tx_buffers[i].info.d_struct.txb = NULL; | ||
4439 | } | ||
4440 | |||
4441 | if (i == TX_PENDED_QUEUE_LENGTH) | ||
4442 | return 0; | ||
4443 | |||
4444 | for (j = 0; j < i; j++) { | ||
4445 | pci_free_consistent(priv->pci_dev, | ||
4446 | sizeof(struct ipw2100_data_header), | ||
4447 | priv->tx_buffers[j].info.d_struct.data, | ||
4448 | priv->tx_buffers[j].info.d_struct. | ||
4449 | data_phys); | ||
4450 | } | ||
4451 | |||
4452 | kfree(priv->tx_buffers); | ||
4453 | priv->tx_buffers = NULL; | ||
4454 | |||
4455 | return err; | ||
4456 | } | ||
4457 | |||
4458 | static void ipw2100_tx_initialize(struct ipw2100_priv *priv) | ||
4459 | { | ||
4460 | int i; | ||
4461 | |||
4462 | IPW_DEBUG_INFO("enter\n"); | ||
4463 | |||
4464 | /* | ||
4465 | * reinitialize packet info lists | ||
4466 | */ | ||
4467 | INIT_LIST_HEAD(&priv->fw_pend_list); | ||
4468 | INIT_STAT(&priv->fw_pend_stat); | ||
4469 | |||
4470 | /* | ||
4471 | * reinitialize lists | ||
4472 | */ | ||
4473 | INIT_LIST_HEAD(&priv->tx_pend_list); | ||
4474 | INIT_LIST_HEAD(&priv->tx_free_list); | ||
4475 | INIT_STAT(&priv->tx_pend_stat); | ||
4476 | INIT_STAT(&priv->tx_free_stat); | ||
4477 | |||
4478 | for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) { | ||
4479 | /* We simply drop any SKBs that have been queued for | ||
4480 | * transmit */ | ||
4481 | if (priv->tx_buffers[i].info.d_struct.txb) { | ||
4482 | ieee80211_txb_free(priv->tx_buffers[i].info.d_struct. | ||
4483 | txb); | ||
4484 | priv->tx_buffers[i].info.d_struct.txb = NULL; | ||
4485 | } | ||
4486 | |||
4487 | list_add_tail(&priv->tx_buffers[i].list, &priv->tx_free_list); | ||
4488 | } | ||
4489 | |||
4490 | SET_STAT(&priv->tx_free_stat, i); | ||
4491 | |||
4492 | priv->tx_queue.oldest = 0; | ||
4493 | priv->tx_queue.available = priv->tx_queue.entries; | ||
4494 | priv->tx_queue.next = 0; | ||
4495 | INIT_STAT(&priv->txq_stat); | ||
4496 | SET_STAT(&priv->txq_stat, priv->tx_queue.available); | ||
4497 | |||
4498 | bd_queue_initialize(priv, &priv->tx_queue, | ||
4499 | IPW_MEM_HOST_SHARED_TX_QUEUE_BD_BASE, | ||
4500 | IPW_MEM_HOST_SHARED_TX_QUEUE_BD_SIZE, | ||
4501 | IPW_MEM_HOST_SHARED_TX_QUEUE_READ_INDEX, | ||
4502 | IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX); | ||
4503 | |||
4504 | IPW_DEBUG_INFO("exit\n"); | ||
4505 | |||
4506 | } | ||
4507 | |||
4508 | static void ipw2100_tx_free(struct ipw2100_priv *priv) | ||
4509 | { | ||
4510 | int i; | ||
4511 | |||
4512 | IPW_DEBUG_INFO("enter\n"); | ||
4513 | |||
4514 | bd_queue_free(priv, &priv->tx_queue); | ||
4515 | |||
4516 | if (!priv->tx_buffers) | ||
4517 | return; | ||
4518 | |||
4519 | for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) { | ||
4520 | if (priv->tx_buffers[i].info.d_struct.txb) { | ||
4521 | ieee80211_txb_free(priv->tx_buffers[i].info.d_struct. | ||
4522 | txb); | ||
4523 | priv->tx_buffers[i].info.d_struct.txb = NULL; | ||
4524 | } | ||
4525 | if (priv->tx_buffers[i].info.d_struct.data) | ||
4526 | pci_free_consistent(priv->pci_dev, | ||
4527 | sizeof(struct ipw2100_data_header), | ||
4528 | priv->tx_buffers[i].info.d_struct. | ||
4529 | data, | ||
4530 | priv->tx_buffers[i].info.d_struct. | ||
4531 | data_phys); | ||
4532 | } | ||
4533 | |||
4534 | kfree(priv->tx_buffers); | ||
4535 | priv->tx_buffers = NULL; | ||
4536 | |||
4537 | IPW_DEBUG_INFO("exit\n"); | ||
4538 | } | ||
4539 | |||
4540 | static int ipw2100_rx_allocate(struct ipw2100_priv *priv) | ||
4541 | { | ||
4542 | int i, j, err = -EINVAL; | ||
4543 | |||
4544 | IPW_DEBUG_INFO("enter\n"); | ||
4545 | |||
4546 | err = bd_queue_allocate(priv, &priv->rx_queue, RX_QUEUE_LENGTH); | ||
4547 | if (err) { | ||
4548 | IPW_DEBUG_INFO("failed bd_queue_allocate\n"); | ||
4549 | return err; | ||
4550 | } | ||
4551 | |||
4552 | err = status_queue_allocate(priv, RX_QUEUE_LENGTH); | ||
4553 | if (err) { | ||
4554 | IPW_DEBUG_INFO("failed status_queue_allocate\n"); | ||
4555 | bd_queue_free(priv, &priv->rx_queue); | ||
4556 | return err; | ||
4557 | } | ||
4558 | |||
4559 | /* | ||
4560 | * allocate packets | ||
4561 | */ | ||
4562 | priv->rx_buffers = (struct ipw2100_rx_packet *) | ||
4563 | kmalloc(RX_QUEUE_LENGTH * sizeof(struct ipw2100_rx_packet), | ||
4564 | GFP_KERNEL); | ||
4565 | if (!priv->rx_buffers) { | ||
4566 | IPW_DEBUG_INFO("can't allocate rx packet buffer table\n"); | ||
4567 | |||
4568 | bd_queue_free(priv, &priv->rx_queue); | ||
4569 | |||
4570 | status_queue_free(priv); | ||
4571 | |||
4572 | return -ENOMEM; | ||
4573 | } | ||
4574 | |||
4575 | for (i = 0; i < RX_QUEUE_LENGTH; i++) { | ||
4576 | struct ipw2100_rx_packet *packet = &priv->rx_buffers[i]; | ||
4577 | |||
4578 | err = ipw2100_alloc_skb(priv, packet); | ||
4579 | if (unlikely(err)) { | ||
4580 | err = -ENOMEM; | ||
4581 | break; | ||
4582 | } | ||
4583 | |||
4584 | /* The BD holds the cache aligned address */ | ||
4585 | priv->rx_queue.drv[i].host_addr = packet->dma_addr; | ||
4586 | priv->rx_queue.drv[i].buf_length = IPW_RX_NIC_BUFFER_LENGTH; | ||
4587 | priv->status_queue.drv[i].status_fields = 0; | ||
4588 | } | ||
4589 | |||
4590 | if (i == RX_QUEUE_LENGTH) | ||
4591 | return 0; | ||
4592 | |||
4593 | for (j = 0; j < i; j++) { | ||
4594 | pci_unmap_single(priv->pci_dev, priv->rx_buffers[j].dma_addr, | ||
4595 | sizeof(struct ipw2100_rx_packet), | ||
4596 | PCI_DMA_FROMDEVICE); | ||
4597 | dev_kfree_skb(priv->rx_buffers[j].skb); | ||
4598 | } | ||
4599 | |||
4600 | kfree(priv->rx_buffers); | ||
4601 | priv->rx_buffers = NULL; | ||
4602 | |||
4603 | bd_queue_free(priv, &priv->rx_queue); | ||
4604 | |||
4605 | status_queue_free(priv); | ||
4606 | |||
4607 | return err; | ||
4608 | } | ||
4609 | |||
4610 | static void ipw2100_rx_initialize(struct ipw2100_priv *priv) | ||
4611 | { | ||
4612 | IPW_DEBUG_INFO("enter\n"); | ||
4613 | |||
4614 | priv->rx_queue.oldest = 0; | ||
4615 | priv->rx_queue.available = priv->rx_queue.entries - 1; | ||
4616 | priv->rx_queue.next = priv->rx_queue.entries - 1; | ||
4617 | |||
4618 | INIT_STAT(&priv->rxq_stat); | ||
4619 | SET_STAT(&priv->rxq_stat, priv->rx_queue.available); | ||
4620 | |||
4621 | bd_queue_initialize(priv, &priv->rx_queue, | ||
4622 | IPW_MEM_HOST_SHARED_RX_BD_BASE, | ||
4623 | IPW_MEM_HOST_SHARED_RX_BD_SIZE, | ||
4624 | IPW_MEM_HOST_SHARED_RX_READ_INDEX, | ||
4625 | IPW_MEM_HOST_SHARED_RX_WRITE_INDEX); | ||
4626 | |||
4627 | /* set up the status queue */ | ||
4628 | write_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_STATUS_BASE, | ||
4629 | priv->status_queue.nic); | ||
4630 | |||
4631 | IPW_DEBUG_INFO("exit\n"); | ||
4632 | } | ||
4633 | |||
4634 | static void ipw2100_rx_free(struct ipw2100_priv *priv) | ||
4635 | { | ||
4636 | int i; | ||
4637 | |||
4638 | IPW_DEBUG_INFO("enter\n"); | ||
4639 | |||
4640 | bd_queue_free(priv, &priv->rx_queue); | ||
4641 | status_queue_free(priv); | ||
4642 | |||
4643 | if (!priv->rx_buffers) | ||
4644 | return; | ||
4645 | |||
4646 | for (i = 0; i < RX_QUEUE_LENGTH; i++) { | ||
4647 | if (priv->rx_buffers[i].rxp) { | ||
4648 | pci_unmap_single(priv->pci_dev, | ||
4649 | priv->rx_buffers[i].dma_addr, | ||
4650 | sizeof(struct ipw2100_rx), | ||
4651 | PCI_DMA_FROMDEVICE); | ||
4652 | dev_kfree_skb(priv->rx_buffers[i].skb); | ||
4653 | } | ||
4654 | } | ||
4655 | |||
4656 | kfree(priv->rx_buffers); | ||
4657 | priv->rx_buffers = NULL; | ||
4658 | |||
4659 | IPW_DEBUG_INFO("exit\n"); | ||
4660 | } | ||
4661 | |||
4662 | static int ipw2100_read_mac_address(struct ipw2100_priv *priv) | ||
4663 | { | ||
4664 | u32 length = ETH_ALEN; | ||
4665 | u8 addr[ETH_ALEN]; | ||
4666 | |||
4667 | int err; | ||
4668 | |||
4669 | err = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ADAPTER_MAC, addr, &length); | ||
4670 | if (err) { | ||
4671 | IPW_DEBUG_INFO("MAC address read failed\n"); | ||
4672 | return -EIO; | ||
4673 | } | ||
4674 | |||
4675 | memcpy(priv->net_dev->dev_addr, addr, ETH_ALEN); | ||
4676 | IPW_DEBUG_INFO("card MAC is %pM\n", priv->net_dev->dev_addr); | ||
4677 | |||
4678 | return 0; | ||
4679 | } | ||
4680 | |||
4681 | /******************************************************************** | ||
4682 | * | ||
4683 | * Firmware Commands | ||
4684 | * | ||
4685 | ********************************************************************/ | ||
4686 | |||
4687 | static int ipw2100_set_mac_address(struct ipw2100_priv *priv, int batch_mode) | ||
4688 | { | ||
4689 | struct host_command cmd = { | ||
4690 | .host_command = ADAPTER_ADDRESS, | ||
4691 | .host_command_sequence = 0, | ||
4692 | .host_command_length = ETH_ALEN | ||
4693 | }; | ||
4694 | int err; | ||
4695 | |||
4696 | IPW_DEBUG_HC("SET_MAC_ADDRESS\n"); | ||
4697 | |||
4698 | IPW_DEBUG_INFO("enter\n"); | ||
4699 | |||
4700 | if (priv->config & CFG_CUSTOM_MAC) { | ||
4701 | memcpy(cmd.host_command_parameters, priv->mac_addr, ETH_ALEN); | ||
4702 | memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN); | ||
4703 | } else | ||
4704 | memcpy(cmd.host_command_parameters, priv->net_dev->dev_addr, | ||
4705 | ETH_ALEN); | ||
4706 | |||
4707 | err = ipw2100_hw_send_command(priv, &cmd); | ||
4708 | |||
4709 | IPW_DEBUG_INFO("exit\n"); | ||
4710 | return err; | ||
4711 | } | ||
4712 | |||
4713 | static int ipw2100_set_port_type(struct ipw2100_priv *priv, u32 port_type, | ||
4714 | int batch_mode) | ||
4715 | { | ||
4716 | struct host_command cmd = { | ||
4717 | .host_command = PORT_TYPE, | ||
4718 | .host_command_sequence = 0, | ||
4719 | .host_command_length = sizeof(u32) | ||
4720 | }; | ||
4721 | int err; | ||
4722 | |||
4723 | switch (port_type) { | ||
4724 | case IW_MODE_INFRA: | ||
4725 | cmd.host_command_parameters[0] = IPW_BSS; | ||
4726 | break; | ||
4727 | case IW_MODE_ADHOC: | ||
4728 | cmd.host_command_parameters[0] = IPW_IBSS; | ||
4729 | break; | ||
4730 | } | ||
4731 | |||
4732 | IPW_DEBUG_HC("PORT_TYPE: %s\n", | ||
4733 | port_type == IPW_IBSS ? "Ad-Hoc" : "Managed"); | ||
4734 | |||
4735 | if (!batch_mode) { | ||
4736 | err = ipw2100_disable_adapter(priv); | ||
4737 | if (err) { | ||
4738 | printk(KERN_ERR DRV_NAME | ||
4739 | ": %s: Could not disable adapter %d\n", | ||
4740 | priv->net_dev->name, err); | ||
4741 | return err; | ||
4742 | } | ||
4743 | } | ||
4744 | |||
4745 | /* send cmd to firmware */ | ||
4746 | err = ipw2100_hw_send_command(priv, &cmd); | ||
4747 | |||
4748 | if (!batch_mode) | ||
4749 | ipw2100_enable_adapter(priv); | ||
4750 | |||
4751 | return err; | ||
4752 | } | ||
4753 | |||
4754 | static int ipw2100_set_channel(struct ipw2100_priv *priv, u32 channel, | ||
4755 | int batch_mode) | ||
4756 | { | ||
4757 | struct host_command cmd = { | ||
4758 | .host_command = CHANNEL, | ||
4759 | .host_command_sequence = 0, | ||
4760 | .host_command_length = sizeof(u32) | ||
4761 | }; | ||
4762 | int err; | ||
4763 | |||
4764 | cmd.host_command_parameters[0] = channel; | ||
4765 | |||
4766 | IPW_DEBUG_HC("CHANNEL: %d\n", channel); | ||
4767 | |||
4768 | /* If BSS then we don't support channel selection */ | ||
4769 | if (priv->ieee->iw_mode == IW_MODE_INFRA) | ||
4770 | return 0; | ||
4771 | |||
4772 | if ((channel != 0) && | ||
4773 | ((channel < REG_MIN_CHANNEL) || (channel > REG_MAX_CHANNEL))) | ||
4774 | return -EINVAL; | ||
4775 | |||
4776 | if (!batch_mode) { | ||
4777 | err = ipw2100_disable_adapter(priv); | ||
4778 | if (err) | ||
4779 | return err; | ||
4780 | } | ||
4781 | |||
4782 | err = ipw2100_hw_send_command(priv, &cmd); | ||
4783 | if (err) { | ||
4784 | IPW_DEBUG_INFO("Failed to set channel to %d", channel); | ||
4785 | return err; | ||
4786 | } | ||
4787 | |||
4788 | if (channel) | ||
4789 | priv->config |= CFG_STATIC_CHANNEL; | ||
4790 | else | ||
4791 | priv->config &= ~CFG_STATIC_CHANNEL; | ||
4792 | |||
4793 | priv->channel = channel; | ||
4794 | |||
4795 | if (!batch_mode) { | ||
4796 | err = ipw2100_enable_adapter(priv); | ||
4797 | if (err) | ||
4798 | return err; | ||
4799 | } | ||
4800 | |||
4801 | return 0; | ||
4802 | } | ||
4803 | |||
4804 | static int ipw2100_system_config(struct ipw2100_priv *priv, int batch_mode) | ||
4805 | { | ||
4806 | struct host_command cmd = { | ||
4807 | .host_command = SYSTEM_CONFIG, | ||
4808 | .host_command_sequence = 0, | ||
4809 | .host_command_length = 12, | ||
4810 | }; | ||
4811 | u32 ibss_mask, len = sizeof(u32); | ||
4812 | int err; | ||
4813 | |||
4814 | /* Set system configuration */ | ||
4815 | |||
4816 | if (!batch_mode) { | ||
4817 | err = ipw2100_disable_adapter(priv); | ||
4818 | if (err) | ||
4819 | return err; | ||
4820 | } | ||
4821 | |||
4822 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) | ||
4823 | cmd.host_command_parameters[0] |= IPW_CFG_IBSS_AUTO_START; | ||
4824 | |||
4825 | cmd.host_command_parameters[0] |= IPW_CFG_IBSS_MASK | | ||
4826 | IPW_CFG_BSS_MASK | IPW_CFG_802_1x_ENABLE; | ||
4827 | |||
4828 | if (!(priv->config & CFG_LONG_PREAMBLE)) | ||
4829 | cmd.host_command_parameters[0] |= IPW_CFG_PREAMBLE_AUTO; | ||
4830 | |||
4831 | err = ipw2100_get_ordinal(priv, | ||
4832 | IPW_ORD_EEPROM_IBSS_11B_CHANNELS, | ||
4833 | &ibss_mask, &len); | ||
4834 | if (err) | ||
4835 | ibss_mask = IPW_IBSS_11B_DEFAULT_MASK; | ||
4836 | |||
4837 | cmd.host_command_parameters[1] = REG_CHANNEL_MASK; | ||
4838 | cmd.host_command_parameters[2] = REG_CHANNEL_MASK & ibss_mask; | ||
4839 | |||
4840 | /* 11b only */ | ||
4841 | /*cmd.host_command_parameters[0] |= DIVERSITY_ANTENNA_A; */ | ||
4842 | |||
4843 | err = ipw2100_hw_send_command(priv, &cmd); | ||
4844 | if (err) | ||
4845 | return err; | ||
4846 | |||
4847 | /* If IPv6 is configured in the kernel then we don't want to filter out all | ||
4848 | * of the multicast packets as IPv6 needs some. */ | ||
4849 | #if !defined(CONFIG_IPV6) && !defined(CONFIG_IPV6_MODULE) | ||
4850 | cmd.host_command = ADD_MULTICAST; | ||
4851 | cmd.host_command_sequence = 0; | ||
4852 | cmd.host_command_length = 0; | ||
4853 | |||
4854 | ipw2100_hw_send_command(priv, &cmd); | ||
4855 | #endif | ||
4856 | if (!batch_mode) { | ||
4857 | err = ipw2100_enable_adapter(priv); | ||
4858 | if (err) | ||
4859 | return err; | ||
4860 | } | ||
4861 | |||
4862 | return 0; | ||
4863 | } | ||
4864 | |||
4865 | static int ipw2100_set_tx_rates(struct ipw2100_priv *priv, u32 rate, | ||
4866 | int batch_mode) | ||
4867 | { | ||
4868 | struct host_command cmd = { | ||
4869 | .host_command = BASIC_TX_RATES, | ||
4870 | .host_command_sequence = 0, | ||
4871 | .host_command_length = 4 | ||
4872 | }; | ||
4873 | int err; | ||
4874 | |||
4875 | cmd.host_command_parameters[0] = rate & TX_RATE_MASK; | ||
4876 | |||
4877 | if (!batch_mode) { | ||
4878 | err = ipw2100_disable_adapter(priv); | ||
4879 | if (err) | ||
4880 | return err; | ||
4881 | } | ||
4882 | |||
4883 | /* Set BASIC TX Rate first */ | ||
4884 | ipw2100_hw_send_command(priv, &cmd); | ||
4885 | |||
4886 | /* Set TX Rate */ | ||
4887 | cmd.host_command = TX_RATES; | ||
4888 | ipw2100_hw_send_command(priv, &cmd); | ||
4889 | |||
4890 | /* Set MSDU TX Rate */ | ||
4891 | cmd.host_command = MSDU_TX_RATES; | ||
4892 | ipw2100_hw_send_command(priv, &cmd); | ||
4893 | |||
4894 | if (!batch_mode) { | ||
4895 | err = ipw2100_enable_adapter(priv); | ||
4896 | if (err) | ||
4897 | return err; | ||
4898 | } | ||
4899 | |||
4900 | priv->tx_rates = rate; | ||
4901 | |||
4902 | return 0; | ||
4903 | } | ||
4904 | |||
4905 | static int ipw2100_set_power_mode(struct ipw2100_priv *priv, int power_level) | ||
4906 | { | ||
4907 | struct host_command cmd = { | ||
4908 | .host_command = POWER_MODE, | ||
4909 | .host_command_sequence = 0, | ||
4910 | .host_command_length = 4 | ||
4911 | }; | ||
4912 | int err; | ||
4913 | |||
4914 | cmd.host_command_parameters[0] = power_level; | ||
4915 | |||
4916 | err = ipw2100_hw_send_command(priv, &cmd); | ||
4917 | if (err) | ||
4918 | return err; | ||
4919 | |||
4920 | if (power_level == IPW_POWER_MODE_CAM) | ||
4921 | priv->power_mode = IPW_POWER_LEVEL(priv->power_mode); | ||
4922 | else | ||
4923 | priv->power_mode = IPW_POWER_ENABLED | power_level; | ||
4924 | |||
4925 | #ifdef IPW2100_TX_POWER | ||
4926 | if (priv->port_type == IBSS && priv->adhoc_power != DFTL_IBSS_TX_POWER) { | ||
4927 | /* Set beacon interval */ | ||
4928 | cmd.host_command = TX_POWER_INDEX; | ||
4929 | cmd.host_command_parameters[0] = (u32) priv->adhoc_power; | ||
4930 | |||
4931 | err = ipw2100_hw_send_command(priv, &cmd); | ||
4932 | if (err) | ||
4933 | return err; | ||
4934 | } | ||
4935 | #endif | ||
4936 | |||
4937 | return 0; | ||
4938 | } | ||
4939 | |||
4940 | static int ipw2100_set_rts_threshold(struct ipw2100_priv *priv, u32 threshold) | ||
4941 | { | ||
4942 | struct host_command cmd = { | ||
4943 | .host_command = RTS_THRESHOLD, | ||
4944 | .host_command_sequence = 0, | ||
4945 | .host_command_length = 4 | ||
4946 | }; | ||
4947 | int err; | ||
4948 | |||
4949 | if (threshold & RTS_DISABLED) | ||
4950 | cmd.host_command_parameters[0] = MAX_RTS_THRESHOLD; | ||
4951 | else | ||
4952 | cmd.host_command_parameters[0] = threshold & ~RTS_DISABLED; | ||
4953 | |||
4954 | err = ipw2100_hw_send_command(priv, &cmd); | ||
4955 | if (err) | ||
4956 | return err; | ||
4957 | |||
4958 | priv->rts_threshold = threshold; | ||
4959 | |||
4960 | return 0; | ||
4961 | } | ||
4962 | |||
4963 | #if 0 | ||
4964 | int ipw2100_set_fragmentation_threshold(struct ipw2100_priv *priv, | ||
4965 | u32 threshold, int batch_mode) | ||
4966 | { | ||
4967 | struct host_command cmd = { | ||
4968 | .host_command = FRAG_THRESHOLD, | ||
4969 | .host_command_sequence = 0, | ||
4970 | .host_command_length = 4, | ||
4971 | .host_command_parameters[0] = 0, | ||
4972 | }; | ||
4973 | int err; | ||
4974 | |||
4975 | if (!batch_mode) { | ||
4976 | err = ipw2100_disable_adapter(priv); | ||
4977 | if (err) | ||
4978 | return err; | ||
4979 | } | ||
4980 | |||
4981 | if (threshold == 0) | ||
4982 | threshold = DEFAULT_FRAG_THRESHOLD; | ||
4983 | else { | ||
4984 | threshold = max(threshold, MIN_FRAG_THRESHOLD); | ||
4985 | threshold = min(threshold, MAX_FRAG_THRESHOLD); | ||
4986 | } | ||
4987 | |||
4988 | cmd.host_command_parameters[0] = threshold; | ||
4989 | |||
4990 | IPW_DEBUG_HC("FRAG_THRESHOLD: %u\n", threshold); | ||
4991 | |||
4992 | err = ipw2100_hw_send_command(priv, &cmd); | ||
4993 | |||
4994 | if (!batch_mode) | ||
4995 | ipw2100_enable_adapter(priv); | ||
4996 | |||
4997 | if (!err) | ||
4998 | priv->frag_threshold = threshold; | ||
4999 | |||
5000 | return err; | ||
5001 | } | ||
5002 | #endif | ||
5003 | |||
5004 | static int ipw2100_set_short_retry(struct ipw2100_priv *priv, u32 retry) | ||
5005 | { | ||
5006 | struct host_command cmd = { | ||
5007 | .host_command = SHORT_RETRY_LIMIT, | ||
5008 | .host_command_sequence = 0, | ||
5009 | .host_command_length = 4 | ||
5010 | }; | ||
5011 | int err; | ||
5012 | |||
5013 | cmd.host_command_parameters[0] = retry; | ||
5014 | |||
5015 | err = ipw2100_hw_send_command(priv, &cmd); | ||
5016 | if (err) | ||
5017 | return err; | ||
5018 | |||
5019 | priv->short_retry_limit = retry; | ||
5020 | |||
5021 | return 0; | ||
5022 | } | ||
5023 | |||
5024 | static int ipw2100_set_long_retry(struct ipw2100_priv *priv, u32 retry) | ||
5025 | { | ||
5026 | struct host_command cmd = { | ||
5027 | .host_command = LONG_RETRY_LIMIT, | ||
5028 | .host_command_sequence = 0, | ||
5029 | .host_command_length = 4 | ||
5030 | }; | ||
5031 | int err; | ||
5032 | |||
5033 | cmd.host_command_parameters[0] = retry; | ||
5034 | |||
5035 | err = ipw2100_hw_send_command(priv, &cmd); | ||
5036 | if (err) | ||
5037 | return err; | ||
5038 | |||
5039 | priv->long_retry_limit = retry; | ||
5040 | |||
5041 | return 0; | ||
5042 | } | ||
5043 | |||
5044 | static int ipw2100_set_mandatory_bssid(struct ipw2100_priv *priv, u8 * bssid, | ||
5045 | int batch_mode) | ||
5046 | { | ||
5047 | struct host_command cmd = { | ||
5048 | .host_command = MANDATORY_BSSID, | ||
5049 | .host_command_sequence = 0, | ||
5050 | .host_command_length = (bssid == NULL) ? 0 : ETH_ALEN | ||
5051 | }; | ||
5052 | int err; | ||
5053 | |||
5054 | #ifdef CONFIG_IPW2100_DEBUG | ||
5055 | if (bssid != NULL) | ||
5056 | IPW_DEBUG_HC("MANDATORY_BSSID: %pM\n", bssid); | ||
5057 | else | ||
5058 | IPW_DEBUG_HC("MANDATORY_BSSID: <clear>\n"); | ||
5059 | #endif | ||
5060 | /* if BSSID is empty then we disable mandatory bssid mode */ | ||
5061 | if (bssid != NULL) | ||
5062 | memcpy(cmd.host_command_parameters, bssid, ETH_ALEN); | ||
5063 | |||
5064 | if (!batch_mode) { | ||
5065 | err = ipw2100_disable_adapter(priv); | ||
5066 | if (err) | ||
5067 | return err; | ||
5068 | } | ||
5069 | |||
5070 | err = ipw2100_hw_send_command(priv, &cmd); | ||
5071 | |||
5072 | if (!batch_mode) | ||
5073 | ipw2100_enable_adapter(priv); | ||
5074 | |||
5075 | return err; | ||
5076 | } | ||
5077 | |||
5078 | static int ipw2100_disassociate_bssid(struct ipw2100_priv *priv) | ||
5079 | { | ||
5080 | struct host_command cmd = { | ||
5081 | .host_command = DISASSOCIATION_BSSID, | ||
5082 | .host_command_sequence = 0, | ||
5083 | .host_command_length = ETH_ALEN | ||
5084 | }; | ||
5085 | int err; | ||
5086 | int len; | ||
5087 | |||
5088 | IPW_DEBUG_HC("DISASSOCIATION_BSSID\n"); | ||
5089 | |||
5090 | len = ETH_ALEN; | ||
5091 | /* The Firmware currently ignores the BSSID and just disassociates from | ||
5092 | * the currently associated AP -- but in the off chance that a future | ||
5093 | * firmware does use the BSSID provided here, we go ahead and try and | ||
5094 | * set it to the currently associated AP's BSSID */ | ||
5095 | memcpy(cmd.host_command_parameters, priv->bssid, ETH_ALEN); | ||
5096 | |||
5097 | err = ipw2100_hw_send_command(priv, &cmd); | ||
5098 | |||
5099 | return err; | ||
5100 | } | ||
5101 | |||
5102 | static int ipw2100_set_wpa_ie(struct ipw2100_priv *, | ||
5103 | struct ipw2100_wpa_assoc_frame *, int) | ||
5104 | __attribute__ ((unused)); | ||
5105 | |||
5106 | static int ipw2100_set_wpa_ie(struct ipw2100_priv *priv, | ||
5107 | struct ipw2100_wpa_assoc_frame *wpa_frame, | ||
5108 | int batch_mode) | ||
5109 | { | ||
5110 | struct host_command cmd = { | ||
5111 | .host_command = SET_WPA_IE, | ||
5112 | .host_command_sequence = 0, | ||
5113 | .host_command_length = sizeof(struct ipw2100_wpa_assoc_frame), | ||
5114 | }; | ||
5115 | int err; | ||
5116 | |||
5117 | IPW_DEBUG_HC("SET_WPA_IE\n"); | ||
5118 | |||
5119 | if (!batch_mode) { | ||
5120 | err = ipw2100_disable_adapter(priv); | ||
5121 | if (err) | ||
5122 | return err; | ||
5123 | } | ||
5124 | |||
5125 | memcpy(cmd.host_command_parameters, wpa_frame, | ||
5126 | sizeof(struct ipw2100_wpa_assoc_frame)); | ||
5127 | |||
5128 | err = ipw2100_hw_send_command(priv, &cmd); | ||
5129 | |||
5130 | if (!batch_mode) { | ||
5131 | if (ipw2100_enable_adapter(priv)) | ||
5132 | err = -EIO; | ||
5133 | } | ||
5134 | |||
5135 | return err; | ||
5136 | } | ||
5137 | |||
5138 | struct security_info_params { | ||
5139 | u32 allowed_ciphers; | ||
5140 | u16 version; | ||
5141 | u8 auth_mode; | ||
5142 | u8 replay_counters_number; | ||
5143 | u8 unicast_using_group; | ||
5144 | } __attribute__ ((packed)); | ||
5145 | |||
5146 | static int ipw2100_set_security_information(struct ipw2100_priv *priv, | ||
5147 | int auth_mode, | ||
5148 | int security_level, | ||
5149 | int unicast_using_group, | ||
5150 | int batch_mode) | ||
5151 | { | ||
5152 | struct host_command cmd = { | ||
5153 | .host_command = SET_SECURITY_INFORMATION, | ||
5154 | .host_command_sequence = 0, | ||
5155 | .host_command_length = sizeof(struct security_info_params) | ||
5156 | }; | ||
5157 | struct security_info_params *security = | ||
5158 | (struct security_info_params *)&cmd.host_command_parameters; | ||
5159 | int err; | ||
5160 | memset(security, 0, sizeof(*security)); | ||
5161 | |||
5162 | /* If shared key AP authentication is turned on, then we need to | ||
5163 | * configure the firmware to try and use it. | ||
5164 | * | ||
5165 | * Actual data encryption/decryption is handled by the host. */ | ||
5166 | security->auth_mode = auth_mode; | ||
5167 | security->unicast_using_group = unicast_using_group; | ||
5168 | |||
5169 | switch (security_level) { | ||
5170 | default: | ||
5171 | case SEC_LEVEL_0: | ||
5172 | security->allowed_ciphers = IPW_NONE_CIPHER; | ||
5173 | break; | ||
5174 | case SEC_LEVEL_1: | ||
5175 | security->allowed_ciphers = IPW_WEP40_CIPHER | | ||
5176 | IPW_WEP104_CIPHER; | ||
5177 | break; | ||
5178 | case SEC_LEVEL_2: | ||
5179 | security->allowed_ciphers = IPW_WEP40_CIPHER | | ||
5180 | IPW_WEP104_CIPHER | IPW_TKIP_CIPHER; | ||
5181 | break; | ||
5182 | case SEC_LEVEL_2_CKIP: | ||
5183 | security->allowed_ciphers = IPW_WEP40_CIPHER | | ||
5184 | IPW_WEP104_CIPHER | IPW_CKIP_CIPHER; | ||
5185 | break; | ||
5186 | case SEC_LEVEL_3: | ||
5187 | security->allowed_ciphers = IPW_WEP40_CIPHER | | ||
5188 | IPW_WEP104_CIPHER | IPW_TKIP_CIPHER | IPW_CCMP_CIPHER; | ||
5189 | break; | ||
5190 | } | ||
5191 | |||
5192 | IPW_DEBUG_HC | ||
5193 | ("SET_SECURITY_INFORMATION: auth:%d cipher:0x%02X (level %d)\n", | ||
5194 | security->auth_mode, security->allowed_ciphers, security_level); | ||
5195 | |||
5196 | security->replay_counters_number = 0; | ||
5197 | |||
5198 | if (!batch_mode) { | ||
5199 | err = ipw2100_disable_adapter(priv); | ||
5200 | if (err) | ||
5201 | return err; | ||
5202 | } | ||
5203 | |||
5204 | err = ipw2100_hw_send_command(priv, &cmd); | ||
5205 | |||
5206 | if (!batch_mode) | ||
5207 | ipw2100_enable_adapter(priv); | ||
5208 | |||
5209 | return err; | ||
5210 | } | ||
5211 | |||
5212 | static int ipw2100_set_tx_power(struct ipw2100_priv *priv, u32 tx_power) | ||
5213 | { | ||
5214 | struct host_command cmd = { | ||
5215 | .host_command = TX_POWER_INDEX, | ||
5216 | .host_command_sequence = 0, | ||
5217 | .host_command_length = 4 | ||
5218 | }; | ||
5219 | int err = 0; | ||
5220 | u32 tmp = tx_power; | ||
5221 | |||
5222 | if (tx_power != IPW_TX_POWER_DEFAULT) | ||
5223 | tmp = (tx_power - IPW_TX_POWER_MIN_DBM) * 16 / | ||
5224 | (IPW_TX_POWER_MAX_DBM - IPW_TX_POWER_MIN_DBM); | ||
5225 | |||
5226 | cmd.host_command_parameters[0] = tmp; | ||
5227 | |||
5228 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) | ||
5229 | err = ipw2100_hw_send_command(priv, &cmd); | ||
5230 | if (!err) | ||
5231 | priv->tx_power = tx_power; | ||
5232 | |||
5233 | return 0; | ||
5234 | } | ||
5235 | |||
5236 | static int ipw2100_set_ibss_beacon_interval(struct ipw2100_priv *priv, | ||
5237 | u32 interval, int batch_mode) | ||
5238 | { | ||
5239 | struct host_command cmd = { | ||
5240 | .host_command = BEACON_INTERVAL, | ||
5241 | .host_command_sequence = 0, | ||
5242 | .host_command_length = 4 | ||
5243 | }; | ||
5244 | int err; | ||
5245 | |||
5246 | cmd.host_command_parameters[0] = interval; | ||
5247 | |||
5248 | IPW_DEBUG_INFO("enter\n"); | ||
5249 | |||
5250 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { | ||
5251 | if (!batch_mode) { | ||
5252 | err = ipw2100_disable_adapter(priv); | ||
5253 | if (err) | ||
5254 | return err; | ||
5255 | } | ||
5256 | |||
5257 | ipw2100_hw_send_command(priv, &cmd); | ||
5258 | |||
5259 | if (!batch_mode) { | ||
5260 | err = ipw2100_enable_adapter(priv); | ||
5261 | if (err) | ||
5262 | return err; | ||
5263 | } | ||
5264 | } | ||
5265 | |||
5266 | IPW_DEBUG_INFO("exit\n"); | ||
5267 | |||
5268 | return 0; | ||
5269 | } | ||
5270 | |||
5271 | void ipw2100_queues_initialize(struct ipw2100_priv *priv) | ||
5272 | { | ||
5273 | ipw2100_tx_initialize(priv); | ||
5274 | ipw2100_rx_initialize(priv); | ||
5275 | ipw2100_msg_initialize(priv); | ||
5276 | } | ||
5277 | |||
5278 | void ipw2100_queues_free(struct ipw2100_priv *priv) | ||
5279 | { | ||
5280 | ipw2100_tx_free(priv); | ||
5281 | ipw2100_rx_free(priv); | ||
5282 | ipw2100_msg_free(priv); | ||
5283 | } | ||
5284 | |||
5285 | int ipw2100_queues_allocate(struct ipw2100_priv *priv) | ||
5286 | { | ||
5287 | if (ipw2100_tx_allocate(priv) || | ||
5288 | ipw2100_rx_allocate(priv) || ipw2100_msg_allocate(priv)) | ||
5289 | goto fail; | ||
5290 | |||
5291 | return 0; | ||
5292 | |||
5293 | fail: | ||
5294 | ipw2100_tx_free(priv); | ||
5295 | ipw2100_rx_free(priv); | ||
5296 | ipw2100_msg_free(priv); | ||
5297 | return -ENOMEM; | ||
5298 | } | ||
5299 | |||
5300 | #define IPW_PRIVACY_CAPABLE 0x0008 | ||
5301 | |||
5302 | static int ipw2100_set_wep_flags(struct ipw2100_priv *priv, u32 flags, | ||
5303 | int batch_mode) | ||
5304 | { | ||
5305 | struct host_command cmd = { | ||
5306 | .host_command = WEP_FLAGS, | ||
5307 | .host_command_sequence = 0, | ||
5308 | .host_command_length = 4 | ||
5309 | }; | ||
5310 | int err; | ||
5311 | |||
5312 | cmd.host_command_parameters[0] = flags; | ||
5313 | |||
5314 | IPW_DEBUG_HC("WEP_FLAGS: flags = 0x%08X\n", flags); | ||
5315 | |||
5316 | if (!batch_mode) { | ||
5317 | err = ipw2100_disable_adapter(priv); | ||
5318 | if (err) { | ||
5319 | printk(KERN_ERR DRV_NAME | ||
5320 | ": %s: Could not disable adapter %d\n", | ||
5321 | priv->net_dev->name, err); | ||
5322 | return err; | ||
5323 | } | ||
5324 | } | ||
5325 | |||
5326 | /* send cmd to firmware */ | ||
5327 | err = ipw2100_hw_send_command(priv, &cmd); | ||
5328 | |||
5329 | if (!batch_mode) | ||
5330 | ipw2100_enable_adapter(priv); | ||
5331 | |||
5332 | return err; | ||
5333 | } | ||
5334 | |||
5335 | struct ipw2100_wep_key { | ||
5336 | u8 idx; | ||
5337 | u8 len; | ||
5338 | u8 key[13]; | ||
5339 | }; | ||
5340 | |||
5341 | /* Macros to ease up priting WEP keys */ | ||
5342 | #define WEP_FMT_64 "%02X%02X%02X%02X-%02X" | ||
5343 | #define WEP_FMT_128 "%02X%02X%02X%02X-%02X%02X%02X%02X-%02X%02X%02X" | ||
5344 | #define WEP_STR_64(x) x[0],x[1],x[2],x[3],x[4] | ||
5345 | #define WEP_STR_128(x) x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],x[8],x[9],x[10] | ||
5346 | |||
5347 | /** | ||
5348 | * Set a the wep key | ||
5349 | * | ||
5350 | * @priv: struct to work on | ||
5351 | * @idx: index of the key we want to set | ||
5352 | * @key: ptr to the key data to set | ||
5353 | * @len: length of the buffer at @key | ||
5354 | * @batch_mode: FIXME perform the operation in batch mode, not | ||
5355 | * disabling the device. | ||
5356 | * | ||
5357 | * @returns 0 if OK, < 0 errno code on error. | ||
5358 | * | ||
5359 | * Fill out a command structure with the new wep key, length an | ||
5360 | * index and send it down the wire. | ||
5361 | */ | ||
5362 | static int ipw2100_set_key(struct ipw2100_priv *priv, | ||
5363 | int idx, char *key, int len, int batch_mode) | ||
5364 | { | ||
5365 | int keylen = len ? (len <= 5 ? 5 : 13) : 0; | ||
5366 | struct host_command cmd = { | ||
5367 | .host_command = WEP_KEY_INFO, | ||
5368 | .host_command_sequence = 0, | ||
5369 | .host_command_length = sizeof(struct ipw2100_wep_key), | ||
5370 | }; | ||
5371 | struct ipw2100_wep_key *wep_key = (void *)cmd.host_command_parameters; | ||
5372 | int err; | ||
5373 | |||
5374 | IPW_DEBUG_HC("WEP_KEY_INFO: index = %d, len = %d/%d\n", | ||
5375 | idx, keylen, len); | ||
5376 | |||
5377 | /* NOTE: We don't check cached values in case the firmware was reset | ||
5378 | * or some other problem is occurring. If the user is setting the key, | ||
5379 | * then we push the change */ | ||
5380 | |||
5381 | wep_key->idx = idx; | ||
5382 | wep_key->len = keylen; | ||
5383 | |||
5384 | if (keylen) { | ||
5385 | memcpy(wep_key->key, key, len); | ||
5386 | memset(wep_key->key + len, 0, keylen - len); | ||
5387 | } | ||
5388 | |||
5389 | /* Will be optimized out on debug not being configured in */ | ||
5390 | if (keylen == 0) | ||
5391 | IPW_DEBUG_WEP("%s: Clearing key %d\n", | ||
5392 | priv->net_dev->name, wep_key->idx); | ||
5393 | else if (keylen == 5) | ||
5394 | IPW_DEBUG_WEP("%s: idx: %d, len: %d key: " WEP_FMT_64 "\n", | ||
5395 | priv->net_dev->name, wep_key->idx, wep_key->len, | ||
5396 | WEP_STR_64(wep_key->key)); | ||
5397 | else | ||
5398 | IPW_DEBUG_WEP("%s: idx: %d, len: %d key: " WEP_FMT_128 | ||
5399 | "\n", | ||
5400 | priv->net_dev->name, wep_key->idx, wep_key->len, | ||
5401 | WEP_STR_128(wep_key->key)); | ||
5402 | |||
5403 | if (!batch_mode) { | ||
5404 | err = ipw2100_disable_adapter(priv); | ||
5405 | /* FIXME: IPG: shouldn't this prink be in _disable_adapter()? */ | ||
5406 | if (err) { | ||
5407 | printk(KERN_ERR DRV_NAME | ||
5408 | ": %s: Could not disable adapter %d\n", | ||
5409 | priv->net_dev->name, err); | ||
5410 | return err; | ||
5411 | } | ||
5412 | } | ||
5413 | |||
5414 | /* send cmd to firmware */ | ||
5415 | err = ipw2100_hw_send_command(priv, &cmd); | ||
5416 | |||
5417 | if (!batch_mode) { | ||
5418 | int err2 = ipw2100_enable_adapter(priv); | ||
5419 | if (err == 0) | ||
5420 | err = err2; | ||
5421 | } | ||
5422 | return err; | ||
5423 | } | ||
5424 | |||
5425 | static int ipw2100_set_key_index(struct ipw2100_priv *priv, | ||
5426 | int idx, int batch_mode) | ||
5427 | { | ||
5428 | struct host_command cmd = { | ||
5429 | .host_command = WEP_KEY_INDEX, | ||
5430 | .host_command_sequence = 0, | ||
5431 | .host_command_length = 4, | ||
5432 | .host_command_parameters = {idx}, | ||
5433 | }; | ||
5434 | int err; | ||
5435 | |||
5436 | IPW_DEBUG_HC("WEP_KEY_INDEX: index = %d\n", idx); | ||
5437 | |||
5438 | if (idx < 0 || idx > 3) | ||
5439 | return -EINVAL; | ||
5440 | |||
5441 | if (!batch_mode) { | ||
5442 | err = ipw2100_disable_adapter(priv); | ||
5443 | if (err) { | ||
5444 | printk(KERN_ERR DRV_NAME | ||
5445 | ": %s: Could not disable adapter %d\n", | ||
5446 | priv->net_dev->name, err); | ||
5447 | return err; | ||
5448 | } | ||
5449 | } | ||
5450 | |||
5451 | /* send cmd to firmware */ | ||
5452 | err = ipw2100_hw_send_command(priv, &cmd); | ||
5453 | |||
5454 | if (!batch_mode) | ||
5455 | ipw2100_enable_adapter(priv); | ||
5456 | |||
5457 | return err; | ||
5458 | } | ||
5459 | |||
5460 | static int ipw2100_configure_security(struct ipw2100_priv *priv, int batch_mode) | ||
5461 | { | ||
5462 | int i, err, auth_mode, sec_level, use_group; | ||
5463 | |||
5464 | if (!(priv->status & STATUS_RUNNING)) | ||
5465 | return 0; | ||
5466 | |||
5467 | if (!batch_mode) { | ||
5468 | err = ipw2100_disable_adapter(priv); | ||
5469 | if (err) | ||
5470 | return err; | ||
5471 | } | ||
5472 | |||
5473 | if (!priv->ieee->sec.enabled) { | ||
5474 | err = | ||
5475 | ipw2100_set_security_information(priv, IPW_AUTH_OPEN, | ||
5476 | SEC_LEVEL_0, 0, 1); | ||
5477 | } else { | ||
5478 | auth_mode = IPW_AUTH_OPEN; | ||
5479 | if (priv->ieee->sec.flags & SEC_AUTH_MODE) { | ||
5480 | if (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY) | ||
5481 | auth_mode = IPW_AUTH_SHARED; | ||
5482 | else if (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP) | ||
5483 | auth_mode = IPW_AUTH_LEAP_CISCO_ID; | ||
5484 | } | ||
5485 | |||
5486 | sec_level = SEC_LEVEL_0; | ||
5487 | if (priv->ieee->sec.flags & SEC_LEVEL) | ||
5488 | sec_level = priv->ieee->sec.level; | ||
5489 | |||
5490 | use_group = 0; | ||
5491 | if (priv->ieee->sec.flags & SEC_UNICAST_GROUP) | ||
5492 | use_group = priv->ieee->sec.unicast_uses_group; | ||
5493 | |||
5494 | err = | ||
5495 | ipw2100_set_security_information(priv, auth_mode, sec_level, | ||
5496 | use_group, 1); | ||
5497 | } | ||
5498 | |||
5499 | if (err) | ||
5500 | goto exit; | ||
5501 | |||
5502 | if (priv->ieee->sec.enabled) { | ||
5503 | for (i = 0; i < 4; i++) { | ||
5504 | if (!(priv->ieee->sec.flags & (1 << i))) { | ||
5505 | memset(priv->ieee->sec.keys[i], 0, WEP_KEY_LEN); | ||
5506 | priv->ieee->sec.key_sizes[i] = 0; | ||
5507 | } else { | ||
5508 | err = ipw2100_set_key(priv, i, | ||
5509 | priv->ieee->sec.keys[i], | ||
5510 | priv->ieee->sec. | ||
5511 | key_sizes[i], 1); | ||
5512 | if (err) | ||
5513 | goto exit; | ||
5514 | } | ||
5515 | } | ||
5516 | |||
5517 | ipw2100_set_key_index(priv, priv->ieee->crypt_info.tx_keyidx, 1); | ||
5518 | } | ||
5519 | |||
5520 | /* Always enable privacy so the Host can filter WEP packets if | ||
5521 | * encrypted data is sent up */ | ||
5522 | err = | ||
5523 | ipw2100_set_wep_flags(priv, | ||
5524 | priv->ieee->sec. | ||
5525 | enabled ? IPW_PRIVACY_CAPABLE : 0, 1); | ||
5526 | if (err) | ||
5527 | goto exit; | ||
5528 | |||
5529 | priv->status &= ~STATUS_SECURITY_UPDATED; | ||
5530 | |||
5531 | exit: | ||
5532 | if (!batch_mode) | ||
5533 | ipw2100_enable_adapter(priv); | ||
5534 | |||
5535 | return err; | ||
5536 | } | ||
5537 | |||
5538 | static void ipw2100_security_work(struct work_struct *work) | ||
5539 | { | ||
5540 | struct ipw2100_priv *priv = | ||
5541 | container_of(work, struct ipw2100_priv, security_work.work); | ||
5542 | |||
5543 | /* If we happen to have reconnected before we get a chance to | ||
5544 | * process this, then update the security settings--which causes | ||
5545 | * a disassociation to occur */ | ||
5546 | if (!(priv->status & STATUS_ASSOCIATED) && | ||
5547 | priv->status & STATUS_SECURITY_UPDATED) | ||
5548 | ipw2100_configure_security(priv, 0); | ||
5549 | } | ||
5550 | |||
5551 | static void shim__set_security(struct net_device *dev, | ||
5552 | struct ieee80211_security *sec) | ||
5553 | { | ||
5554 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
5555 | int i, force_update = 0; | ||
5556 | |||
5557 | mutex_lock(&priv->action_mutex); | ||
5558 | if (!(priv->status & STATUS_INITIALIZED)) | ||
5559 | goto done; | ||
5560 | |||
5561 | for (i = 0; i < 4; i++) { | ||
5562 | if (sec->flags & (1 << i)) { | ||
5563 | priv->ieee->sec.key_sizes[i] = sec->key_sizes[i]; | ||
5564 | if (sec->key_sizes[i] == 0) | ||
5565 | priv->ieee->sec.flags &= ~(1 << i); | ||
5566 | else | ||
5567 | memcpy(priv->ieee->sec.keys[i], sec->keys[i], | ||
5568 | sec->key_sizes[i]); | ||
5569 | if (sec->level == SEC_LEVEL_1) { | ||
5570 | priv->ieee->sec.flags |= (1 << i); | ||
5571 | priv->status |= STATUS_SECURITY_UPDATED; | ||
5572 | } else | ||
5573 | priv->ieee->sec.flags &= ~(1 << i); | ||
5574 | } | ||
5575 | } | ||
5576 | |||
5577 | if ((sec->flags & SEC_ACTIVE_KEY) && | ||
5578 | priv->ieee->sec.active_key != sec->active_key) { | ||
5579 | if (sec->active_key <= 3) { | ||
5580 | priv->ieee->sec.active_key = sec->active_key; | ||
5581 | priv->ieee->sec.flags |= SEC_ACTIVE_KEY; | ||
5582 | } else | ||
5583 | priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY; | ||
5584 | |||
5585 | priv->status |= STATUS_SECURITY_UPDATED; | ||
5586 | } | ||
5587 | |||
5588 | if ((sec->flags & SEC_AUTH_MODE) && | ||
5589 | (priv->ieee->sec.auth_mode != sec->auth_mode)) { | ||
5590 | priv->ieee->sec.auth_mode = sec->auth_mode; | ||
5591 | priv->ieee->sec.flags |= SEC_AUTH_MODE; | ||
5592 | priv->status |= STATUS_SECURITY_UPDATED; | ||
5593 | } | ||
5594 | |||
5595 | if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) { | ||
5596 | priv->ieee->sec.flags |= SEC_ENABLED; | ||
5597 | priv->ieee->sec.enabled = sec->enabled; | ||
5598 | priv->status |= STATUS_SECURITY_UPDATED; | ||
5599 | force_update = 1; | ||
5600 | } | ||
5601 | |||
5602 | if (sec->flags & SEC_ENCRYPT) | ||
5603 | priv->ieee->sec.encrypt = sec->encrypt; | ||
5604 | |||
5605 | if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) { | ||
5606 | priv->ieee->sec.level = sec->level; | ||
5607 | priv->ieee->sec.flags |= SEC_LEVEL; | ||
5608 | priv->status |= STATUS_SECURITY_UPDATED; | ||
5609 | } | ||
5610 | |||
5611 | IPW_DEBUG_WEP("Security flags: %c %c%c%c%c %c%c%c%c\n", | ||
5612 | priv->ieee->sec.flags & (1 << 8) ? '1' : '0', | ||
5613 | priv->ieee->sec.flags & (1 << 7) ? '1' : '0', | ||
5614 | priv->ieee->sec.flags & (1 << 6) ? '1' : '0', | ||
5615 | priv->ieee->sec.flags & (1 << 5) ? '1' : '0', | ||
5616 | priv->ieee->sec.flags & (1 << 4) ? '1' : '0', | ||
5617 | priv->ieee->sec.flags & (1 << 3) ? '1' : '0', | ||
5618 | priv->ieee->sec.flags & (1 << 2) ? '1' : '0', | ||
5619 | priv->ieee->sec.flags & (1 << 1) ? '1' : '0', | ||
5620 | priv->ieee->sec.flags & (1 << 0) ? '1' : '0'); | ||
5621 | |||
5622 | /* As a temporary work around to enable WPA until we figure out why | ||
5623 | * wpa_supplicant toggles the security capability of the driver, which | ||
5624 | * forces a disassocation with force_update... | ||
5625 | * | ||
5626 | * if (force_update || !(priv->status & STATUS_ASSOCIATED))*/ | ||
5627 | if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) | ||
5628 | ipw2100_configure_security(priv, 0); | ||
5629 | done: | ||
5630 | mutex_unlock(&priv->action_mutex); | ||
5631 | } | ||
5632 | |||
5633 | static int ipw2100_adapter_setup(struct ipw2100_priv *priv) | ||
5634 | { | ||
5635 | int err; | ||
5636 | int batch_mode = 1; | ||
5637 | u8 *bssid; | ||
5638 | |||
5639 | IPW_DEBUG_INFO("enter\n"); | ||
5640 | |||
5641 | err = ipw2100_disable_adapter(priv); | ||
5642 | if (err) | ||
5643 | return err; | ||
5644 | #ifdef CONFIG_IPW2100_MONITOR | ||
5645 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { | ||
5646 | err = ipw2100_set_channel(priv, priv->channel, batch_mode); | ||
5647 | if (err) | ||
5648 | return err; | ||
5649 | |||
5650 | IPW_DEBUG_INFO("exit\n"); | ||
5651 | |||
5652 | return 0; | ||
5653 | } | ||
5654 | #endif /* CONFIG_IPW2100_MONITOR */ | ||
5655 | |||
5656 | err = ipw2100_read_mac_address(priv); | ||
5657 | if (err) | ||
5658 | return -EIO; | ||
5659 | |||
5660 | err = ipw2100_set_mac_address(priv, batch_mode); | ||
5661 | if (err) | ||
5662 | return err; | ||
5663 | |||
5664 | err = ipw2100_set_port_type(priv, priv->ieee->iw_mode, batch_mode); | ||
5665 | if (err) | ||
5666 | return err; | ||
5667 | |||
5668 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { | ||
5669 | err = ipw2100_set_channel(priv, priv->channel, batch_mode); | ||
5670 | if (err) | ||
5671 | return err; | ||
5672 | } | ||
5673 | |||
5674 | err = ipw2100_system_config(priv, batch_mode); | ||
5675 | if (err) | ||
5676 | return err; | ||
5677 | |||
5678 | err = ipw2100_set_tx_rates(priv, priv->tx_rates, batch_mode); | ||
5679 | if (err) | ||
5680 | return err; | ||
5681 | |||
5682 | /* Default to power mode OFF */ | ||
5683 | err = ipw2100_set_power_mode(priv, IPW_POWER_MODE_CAM); | ||
5684 | if (err) | ||
5685 | return err; | ||
5686 | |||
5687 | err = ipw2100_set_rts_threshold(priv, priv->rts_threshold); | ||
5688 | if (err) | ||
5689 | return err; | ||
5690 | |||
5691 | if (priv->config & CFG_STATIC_BSSID) | ||
5692 | bssid = priv->bssid; | ||
5693 | else | ||
5694 | bssid = NULL; | ||
5695 | err = ipw2100_set_mandatory_bssid(priv, bssid, batch_mode); | ||
5696 | if (err) | ||
5697 | return err; | ||
5698 | |||
5699 | if (priv->config & CFG_STATIC_ESSID) | ||
5700 | err = ipw2100_set_essid(priv, priv->essid, priv->essid_len, | ||
5701 | batch_mode); | ||
5702 | else | ||
5703 | err = ipw2100_set_essid(priv, NULL, 0, batch_mode); | ||
5704 | if (err) | ||
5705 | return err; | ||
5706 | |||
5707 | err = ipw2100_configure_security(priv, batch_mode); | ||
5708 | if (err) | ||
5709 | return err; | ||
5710 | |||
5711 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { | ||
5712 | err = | ||
5713 | ipw2100_set_ibss_beacon_interval(priv, | ||
5714 | priv->beacon_interval, | ||
5715 | batch_mode); | ||
5716 | if (err) | ||
5717 | return err; | ||
5718 | |||
5719 | err = ipw2100_set_tx_power(priv, priv->tx_power); | ||
5720 | if (err) | ||
5721 | return err; | ||
5722 | } | ||
5723 | |||
5724 | /* | ||
5725 | err = ipw2100_set_fragmentation_threshold( | ||
5726 | priv, priv->frag_threshold, batch_mode); | ||
5727 | if (err) | ||
5728 | return err; | ||
5729 | */ | ||
5730 | |||
5731 | IPW_DEBUG_INFO("exit\n"); | ||
5732 | |||
5733 | return 0; | ||
5734 | } | ||
5735 | |||
5736 | /************************************************************************* | ||
5737 | * | ||
5738 | * EXTERNALLY CALLED METHODS | ||
5739 | * | ||
5740 | *************************************************************************/ | ||
5741 | |||
5742 | /* This method is called by the network layer -- not to be confused with | ||
5743 | * ipw2100_set_mac_address() declared above called by this driver (and this | ||
5744 | * method as well) to talk to the firmware */ | ||
5745 | static int ipw2100_set_address(struct net_device *dev, void *p) | ||
5746 | { | ||
5747 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
5748 | struct sockaddr *addr = p; | ||
5749 | int err = 0; | ||
5750 | |||
5751 | if (!is_valid_ether_addr(addr->sa_data)) | ||
5752 | return -EADDRNOTAVAIL; | ||
5753 | |||
5754 | mutex_lock(&priv->action_mutex); | ||
5755 | |||
5756 | priv->config |= CFG_CUSTOM_MAC; | ||
5757 | memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN); | ||
5758 | |||
5759 | err = ipw2100_set_mac_address(priv, 0); | ||
5760 | if (err) | ||
5761 | goto done; | ||
5762 | |||
5763 | priv->reset_backoff = 0; | ||
5764 | mutex_unlock(&priv->action_mutex); | ||
5765 | ipw2100_reset_adapter(&priv->reset_work.work); | ||
5766 | return 0; | ||
5767 | |||
5768 | done: | ||
5769 | mutex_unlock(&priv->action_mutex); | ||
5770 | return err; | ||
5771 | } | ||
5772 | |||
5773 | static int ipw2100_open(struct net_device *dev) | ||
5774 | { | ||
5775 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
5776 | unsigned long flags; | ||
5777 | IPW_DEBUG_INFO("dev->open\n"); | ||
5778 | |||
5779 | spin_lock_irqsave(&priv->low_lock, flags); | ||
5780 | if (priv->status & STATUS_ASSOCIATED) { | ||
5781 | netif_carrier_on(dev); | ||
5782 | netif_start_queue(dev); | ||
5783 | } | ||
5784 | spin_unlock_irqrestore(&priv->low_lock, flags); | ||
5785 | |||
5786 | return 0; | ||
5787 | } | ||
5788 | |||
5789 | static int ipw2100_close(struct net_device *dev) | ||
5790 | { | ||
5791 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
5792 | unsigned long flags; | ||
5793 | struct list_head *element; | ||
5794 | struct ipw2100_tx_packet *packet; | ||
5795 | |||
5796 | IPW_DEBUG_INFO("enter\n"); | ||
5797 | |||
5798 | spin_lock_irqsave(&priv->low_lock, flags); | ||
5799 | |||
5800 | if (priv->status & STATUS_ASSOCIATED) | ||
5801 | netif_carrier_off(dev); | ||
5802 | netif_stop_queue(dev); | ||
5803 | |||
5804 | /* Flush the TX queue ... */ | ||
5805 | while (!list_empty(&priv->tx_pend_list)) { | ||
5806 | element = priv->tx_pend_list.next; | ||
5807 | packet = list_entry(element, struct ipw2100_tx_packet, list); | ||
5808 | |||
5809 | list_del(element); | ||
5810 | DEC_STAT(&priv->tx_pend_stat); | ||
5811 | |||
5812 | ieee80211_txb_free(packet->info.d_struct.txb); | ||
5813 | packet->info.d_struct.txb = NULL; | ||
5814 | |||
5815 | list_add_tail(element, &priv->tx_free_list); | ||
5816 | INC_STAT(&priv->tx_free_stat); | ||
5817 | } | ||
5818 | spin_unlock_irqrestore(&priv->low_lock, flags); | ||
5819 | |||
5820 | IPW_DEBUG_INFO("exit\n"); | ||
5821 | |||
5822 | return 0; | ||
5823 | } | ||
5824 | |||
5825 | /* | ||
5826 | * TODO: Fix this function... its just wrong | ||
5827 | */ | ||
5828 | static void ipw2100_tx_timeout(struct net_device *dev) | ||
5829 | { | ||
5830 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
5831 | |||
5832 | priv->ieee->stats.tx_errors++; | ||
5833 | |||
5834 | #ifdef CONFIG_IPW2100_MONITOR | ||
5835 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) | ||
5836 | return; | ||
5837 | #endif | ||
5838 | |||
5839 | IPW_DEBUG_INFO("%s: TX timed out. Scheduling firmware restart.\n", | ||
5840 | dev->name); | ||
5841 | schedule_reset(priv); | ||
5842 | } | ||
5843 | |||
5844 | static int ipw2100_wpa_enable(struct ipw2100_priv *priv, int value) | ||
5845 | { | ||
5846 | /* This is called when wpa_supplicant loads and closes the driver | ||
5847 | * interface. */ | ||
5848 | priv->ieee->wpa_enabled = value; | ||
5849 | return 0; | ||
5850 | } | ||
5851 | |||
5852 | static int ipw2100_wpa_set_auth_algs(struct ipw2100_priv *priv, int value) | ||
5853 | { | ||
5854 | |||
5855 | struct ieee80211_device *ieee = priv->ieee; | ||
5856 | struct ieee80211_security sec = { | ||
5857 | .flags = SEC_AUTH_MODE, | ||
5858 | }; | ||
5859 | int ret = 0; | ||
5860 | |||
5861 | if (value & IW_AUTH_ALG_SHARED_KEY) { | ||
5862 | sec.auth_mode = WLAN_AUTH_SHARED_KEY; | ||
5863 | ieee->open_wep = 0; | ||
5864 | } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) { | ||
5865 | sec.auth_mode = WLAN_AUTH_OPEN; | ||
5866 | ieee->open_wep = 1; | ||
5867 | } else if (value & IW_AUTH_ALG_LEAP) { | ||
5868 | sec.auth_mode = WLAN_AUTH_LEAP; | ||
5869 | ieee->open_wep = 1; | ||
5870 | } else | ||
5871 | return -EINVAL; | ||
5872 | |||
5873 | if (ieee->set_security) | ||
5874 | ieee->set_security(ieee->dev, &sec); | ||
5875 | else | ||
5876 | ret = -EOPNOTSUPP; | ||
5877 | |||
5878 | return ret; | ||
5879 | } | ||
5880 | |||
5881 | static void ipw2100_wpa_assoc_frame(struct ipw2100_priv *priv, | ||
5882 | char *wpa_ie, int wpa_ie_len) | ||
5883 | { | ||
5884 | |||
5885 | struct ipw2100_wpa_assoc_frame frame; | ||
5886 | |||
5887 | frame.fixed_ie_mask = 0; | ||
5888 | |||
5889 | /* copy WPA IE */ | ||
5890 | memcpy(frame.var_ie, wpa_ie, wpa_ie_len); | ||
5891 | frame.var_ie_len = wpa_ie_len; | ||
5892 | |||
5893 | /* make sure WPA is enabled */ | ||
5894 | ipw2100_wpa_enable(priv, 1); | ||
5895 | ipw2100_set_wpa_ie(priv, &frame, 0); | ||
5896 | } | ||
5897 | |||
5898 | static void ipw_ethtool_get_drvinfo(struct net_device *dev, | ||
5899 | struct ethtool_drvinfo *info) | ||
5900 | { | ||
5901 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
5902 | char fw_ver[64], ucode_ver[64]; | ||
5903 | |||
5904 | strcpy(info->driver, DRV_NAME); | ||
5905 | strcpy(info->version, DRV_VERSION); | ||
5906 | |||
5907 | ipw2100_get_fwversion(priv, fw_ver, sizeof(fw_ver)); | ||
5908 | ipw2100_get_ucodeversion(priv, ucode_ver, sizeof(ucode_ver)); | ||
5909 | |||
5910 | snprintf(info->fw_version, sizeof(info->fw_version), "%s:%d:%s", | ||
5911 | fw_ver, priv->eeprom_version, ucode_ver); | ||
5912 | |||
5913 | strcpy(info->bus_info, pci_name(priv->pci_dev)); | ||
5914 | } | ||
5915 | |||
5916 | static u32 ipw2100_ethtool_get_link(struct net_device *dev) | ||
5917 | { | ||
5918 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
5919 | return (priv->status & STATUS_ASSOCIATED) ? 1 : 0; | ||
5920 | } | ||
5921 | |||
5922 | static const struct ethtool_ops ipw2100_ethtool_ops = { | ||
5923 | .get_link = ipw2100_ethtool_get_link, | ||
5924 | .get_drvinfo = ipw_ethtool_get_drvinfo, | ||
5925 | }; | ||
5926 | |||
5927 | static void ipw2100_hang_check(struct work_struct *work) | ||
5928 | { | ||
5929 | struct ipw2100_priv *priv = | ||
5930 | container_of(work, struct ipw2100_priv, hang_check.work); | ||
5931 | unsigned long flags; | ||
5932 | u32 rtc = 0xa5a5a5a5; | ||
5933 | u32 len = sizeof(rtc); | ||
5934 | int restart = 0; | ||
5935 | |||
5936 | spin_lock_irqsave(&priv->low_lock, flags); | ||
5937 | |||
5938 | if (priv->fatal_error != 0) { | ||
5939 | /* If fatal_error is set then we need to restart */ | ||
5940 | IPW_DEBUG_INFO("%s: Hardware fatal error detected.\n", | ||
5941 | priv->net_dev->name); | ||
5942 | |||
5943 | restart = 1; | ||
5944 | } else if (ipw2100_get_ordinal(priv, IPW_ORD_RTC_TIME, &rtc, &len) || | ||
5945 | (rtc == priv->last_rtc)) { | ||
5946 | /* Check if firmware is hung */ | ||
5947 | IPW_DEBUG_INFO("%s: Firmware RTC stalled.\n", | ||
5948 | priv->net_dev->name); | ||
5949 | |||
5950 | restart = 1; | ||
5951 | } | ||
5952 | |||
5953 | if (restart) { | ||
5954 | /* Kill timer */ | ||
5955 | priv->stop_hang_check = 1; | ||
5956 | priv->hangs++; | ||
5957 | |||
5958 | /* Restart the NIC */ | ||
5959 | schedule_reset(priv); | ||
5960 | } | ||
5961 | |||
5962 | priv->last_rtc = rtc; | ||
5963 | |||
5964 | if (!priv->stop_hang_check) | ||
5965 | queue_delayed_work(priv->workqueue, &priv->hang_check, HZ / 2); | ||
5966 | |||
5967 | spin_unlock_irqrestore(&priv->low_lock, flags); | ||
5968 | } | ||
5969 | |||
5970 | static void ipw2100_rf_kill(struct work_struct *work) | ||
5971 | { | ||
5972 | struct ipw2100_priv *priv = | ||
5973 | container_of(work, struct ipw2100_priv, rf_kill.work); | ||
5974 | unsigned long flags; | ||
5975 | |||
5976 | spin_lock_irqsave(&priv->low_lock, flags); | ||
5977 | |||
5978 | if (rf_kill_active(priv)) { | ||
5979 | IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n"); | ||
5980 | if (!priv->stop_rf_kill) | ||
5981 | queue_delayed_work(priv->workqueue, &priv->rf_kill, | ||
5982 | round_jiffies_relative(HZ)); | ||
5983 | goto exit_unlock; | ||
5984 | } | ||
5985 | |||
5986 | /* RF Kill is now disabled, so bring the device back up */ | ||
5987 | |||
5988 | if (!(priv->status & STATUS_RF_KILL_MASK)) { | ||
5989 | IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting " | ||
5990 | "device\n"); | ||
5991 | schedule_reset(priv); | ||
5992 | } else | ||
5993 | IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still " | ||
5994 | "enabled\n"); | ||
5995 | |||
5996 | exit_unlock: | ||
5997 | spin_unlock_irqrestore(&priv->low_lock, flags); | ||
5998 | } | ||
5999 | |||
6000 | static void ipw2100_irq_tasklet(struct ipw2100_priv *priv); | ||
6001 | |||
6002 | /* Look into using netdev destructor to shutdown ieee80211? */ | ||
6003 | |||
6004 | static struct net_device *ipw2100_alloc_device(struct pci_dev *pci_dev, | ||
6005 | void __iomem * base_addr, | ||
6006 | unsigned long mem_start, | ||
6007 | unsigned long mem_len) | ||
6008 | { | ||
6009 | struct ipw2100_priv *priv; | ||
6010 | struct net_device *dev; | ||
6011 | |||
6012 | dev = alloc_ieee80211(sizeof(struct ipw2100_priv)); | ||
6013 | if (!dev) | ||
6014 | return NULL; | ||
6015 | priv = ieee80211_priv(dev); | ||
6016 | priv->ieee = netdev_priv(dev); | ||
6017 | priv->pci_dev = pci_dev; | ||
6018 | priv->net_dev = dev; | ||
6019 | |||
6020 | priv->ieee->hard_start_xmit = ipw2100_tx; | ||
6021 | priv->ieee->set_security = shim__set_security; | ||
6022 | |||
6023 | priv->ieee->perfect_rssi = -20; | ||
6024 | priv->ieee->worst_rssi = -85; | ||
6025 | |||
6026 | dev->open = ipw2100_open; | ||
6027 | dev->stop = ipw2100_close; | ||
6028 | dev->init = ipw2100_net_init; | ||
6029 | dev->ethtool_ops = &ipw2100_ethtool_ops; | ||
6030 | dev->tx_timeout = ipw2100_tx_timeout; | ||
6031 | dev->wireless_handlers = &ipw2100_wx_handler_def; | ||
6032 | priv->wireless_data.ieee80211 = priv->ieee; | ||
6033 | dev->wireless_data = &priv->wireless_data; | ||
6034 | dev->set_mac_address = ipw2100_set_address; | ||
6035 | dev->watchdog_timeo = 3 * HZ; | ||
6036 | dev->irq = 0; | ||
6037 | |||
6038 | dev->base_addr = (unsigned long)base_addr; | ||
6039 | dev->mem_start = mem_start; | ||
6040 | dev->mem_end = dev->mem_start + mem_len - 1; | ||
6041 | |||
6042 | /* NOTE: We don't use the wireless_handlers hook | ||
6043 | * in dev as the system will start throwing WX requests | ||
6044 | * to us before we're actually initialized and it just | ||
6045 | * ends up causing problems. So, we just handle | ||
6046 | * the WX extensions through the ipw2100_ioctl interface */ | ||
6047 | |||
6048 | /* memset() puts everything to 0, so we only have explicitly set | ||
6049 | * those values that need to be something else */ | ||
6050 | |||
6051 | /* If power management is turned on, default to AUTO mode */ | ||
6052 | priv->power_mode = IPW_POWER_AUTO; | ||
6053 | |||
6054 | #ifdef CONFIG_IPW2100_MONITOR | ||
6055 | priv->config |= CFG_CRC_CHECK; | ||
6056 | #endif | ||
6057 | priv->ieee->wpa_enabled = 0; | ||
6058 | priv->ieee->drop_unencrypted = 0; | ||
6059 | priv->ieee->privacy_invoked = 0; | ||
6060 | priv->ieee->ieee802_1x = 1; | ||
6061 | |||
6062 | /* Set module parameters */ | ||
6063 | switch (mode) { | ||
6064 | case 1: | ||
6065 | priv->ieee->iw_mode = IW_MODE_ADHOC; | ||
6066 | break; | ||
6067 | #ifdef CONFIG_IPW2100_MONITOR | ||
6068 | case 2: | ||
6069 | priv->ieee->iw_mode = IW_MODE_MONITOR; | ||
6070 | break; | ||
6071 | #endif | ||
6072 | default: | ||
6073 | case 0: | ||
6074 | priv->ieee->iw_mode = IW_MODE_INFRA; | ||
6075 | break; | ||
6076 | } | ||
6077 | |||
6078 | if (disable == 1) | ||
6079 | priv->status |= STATUS_RF_KILL_SW; | ||
6080 | |||
6081 | if (channel != 0 && | ||
6082 | ((channel >= REG_MIN_CHANNEL) && (channel <= REG_MAX_CHANNEL))) { | ||
6083 | priv->config |= CFG_STATIC_CHANNEL; | ||
6084 | priv->channel = channel; | ||
6085 | } | ||
6086 | |||
6087 | if (associate) | ||
6088 | priv->config |= CFG_ASSOCIATE; | ||
6089 | |||
6090 | priv->beacon_interval = DEFAULT_BEACON_INTERVAL; | ||
6091 | priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT; | ||
6092 | priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT; | ||
6093 | priv->rts_threshold = DEFAULT_RTS_THRESHOLD | RTS_DISABLED; | ||
6094 | priv->frag_threshold = DEFAULT_FTS | FRAG_DISABLED; | ||
6095 | priv->tx_power = IPW_TX_POWER_DEFAULT; | ||
6096 | priv->tx_rates = DEFAULT_TX_RATES; | ||
6097 | |||
6098 | strcpy(priv->nick, "ipw2100"); | ||
6099 | |||
6100 | spin_lock_init(&priv->low_lock); | ||
6101 | mutex_init(&priv->action_mutex); | ||
6102 | mutex_init(&priv->adapter_mutex); | ||
6103 | |||
6104 | init_waitqueue_head(&priv->wait_command_queue); | ||
6105 | |||
6106 | netif_carrier_off(dev); | ||
6107 | |||
6108 | INIT_LIST_HEAD(&priv->msg_free_list); | ||
6109 | INIT_LIST_HEAD(&priv->msg_pend_list); | ||
6110 | INIT_STAT(&priv->msg_free_stat); | ||
6111 | INIT_STAT(&priv->msg_pend_stat); | ||
6112 | |||
6113 | INIT_LIST_HEAD(&priv->tx_free_list); | ||
6114 | INIT_LIST_HEAD(&priv->tx_pend_list); | ||
6115 | INIT_STAT(&priv->tx_free_stat); | ||
6116 | INIT_STAT(&priv->tx_pend_stat); | ||
6117 | |||
6118 | INIT_LIST_HEAD(&priv->fw_pend_list); | ||
6119 | INIT_STAT(&priv->fw_pend_stat); | ||
6120 | |||
6121 | priv->workqueue = create_workqueue(DRV_NAME); | ||
6122 | |||
6123 | INIT_DELAYED_WORK(&priv->reset_work, ipw2100_reset_adapter); | ||
6124 | INIT_DELAYED_WORK(&priv->security_work, ipw2100_security_work); | ||
6125 | INIT_DELAYED_WORK(&priv->wx_event_work, ipw2100_wx_event_work); | ||
6126 | INIT_DELAYED_WORK(&priv->hang_check, ipw2100_hang_check); | ||
6127 | INIT_DELAYED_WORK(&priv->rf_kill, ipw2100_rf_kill); | ||
6128 | INIT_WORK(&priv->scan_event_now, ipw2100_scan_event_now); | ||
6129 | INIT_DELAYED_WORK(&priv->scan_event_later, ipw2100_scan_event_later); | ||
6130 | |||
6131 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) | ||
6132 | ipw2100_irq_tasklet, (unsigned long)priv); | ||
6133 | |||
6134 | /* NOTE: We do not start the deferred work for status checks yet */ | ||
6135 | priv->stop_rf_kill = 1; | ||
6136 | priv->stop_hang_check = 1; | ||
6137 | |||
6138 | return dev; | ||
6139 | } | ||
6140 | |||
6141 | static int ipw2100_pci_init_one(struct pci_dev *pci_dev, | ||
6142 | const struct pci_device_id *ent) | ||
6143 | { | ||
6144 | unsigned long mem_start, mem_len, mem_flags; | ||
6145 | void __iomem *base_addr = NULL; | ||
6146 | struct net_device *dev = NULL; | ||
6147 | struct ipw2100_priv *priv = NULL; | ||
6148 | int err = 0; | ||
6149 | int registered = 0; | ||
6150 | u32 val; | ||
6151 | |||
6152 | IPW_DEBUG_INFO("enter\n"); | ||
6153 | |||
6154 | mem_start = pci_resource_start(pci_dev, 0); | ||
6155 | mem_len = pci_resource_len(pci_dev, 0); | ||
6156 | mem_flags = pci_resource_flags(pci_dev, 0); | ||
6157 | |||
6158 | if ((mem_flags & IORESOURCE_MEM) != IORESOURCE_MEM) { | ||
6159 | IPW_DEBUG_INFO("weird - resource type is not memory\n"); | ||
6160 | err = -ENODEV; | ||
6161 | goto fail; | ||
6162 | } | ||
6163 | |||
6164 | base_addr = ioremap_nocache(mem_start, mem_len); | ||
6165 | if (!base_addr) { | ||
6166 | printk(KERN_WARNING DRV_NAME | ||
6167 | "Error calling ioremap_nocache.\n"); | ||
6168 | err = -EIO; | ||
6169 | goto fail; | ||
6170 | } | ||
6171 | |||
6172 | /* allocate and initialize our net_device */ | ||
6173 | dev = ipw2100_alloc_device(pci_dev, base_addr, mem_start, mem_len); | ||
6174 | if (!dev) { | ||
6175 | printk(KERN_WARNING DRV_NAME | ||
6176 | "Error calling ipw2100_alloc_device.\n"); | ||
6177 | err = -ENOMEM; | ||
6178 | goto fail; | ||
6179 | } | ||
6180 | |||
6181 | /* set up PCI mappings for device */ | ||
6182 | err = pci_enable_device(pci_dev); | ||
6183 | if (err) { | ||
6184 | printk(KERN_WARNING DRV_NAME | ||
6185 | "Error calling pci_enable_device.\n"); | ||
6186 | return err; | ||
6187 | } | ||
6188 | |||
6189 | priv = ieee80211_priv(dev); | ||
6190 | |||
6191 | pci_set_master(pci_dev); | ||
6192 | pci_set_drvdata(pci_dev, priv); | ||
6193 | |||
6194 | err = pci_set_dma_mask(pci_dev, DMA_32BIT_MASK); | ||
6195 | if (err) { | ||
6196 | printk(KERN_WARNING DRV_NAME | ||
6197 | "Error calling pci_set_dma_mask.\n"); | ||
6198 | pci_disable_device(pci_dev); | ||
6199 | return err; | ||
6200 | } | ||
6201 | |||
6202 | err = pci_request_regions(pci_dev, DRV_NAME); | ||
6203 | if (err) { | ||
6204 | printk(KERN_WARNING DRV_NAME | ||
6205 | "Error calling pci_request_regions.\n"); | ||
6206 | pci_disable_device(pci_dev); | ||
6207 | return err; | ||
6208 | } | ||
6209 | |||
6210 | /* We disable the RETRY_TIMEOUT register (0x41) to keep | ||
6211 | * PCI Tx retries from interfering with C3 CPU state */ | ||
6212 | pci_read_config_dword(pci_dev, 0x40, &val); | ||
6213 | if ((val & 0x0000ff00) != 0) | ||
6214 | pci_write_config_dword(pci_dev, 0x40, val & 0xffff00ff); | ||
6215 | |||
6216 | pci_set_power_state(pci_dev, PCI_D0); | ||
6217 | |||
6218 | if (!ipw2100_hw_is_adapter_in_system(dev)) { | ||
6219 | printk(KERN_WARNING DRV_NAME | ||
6220 | "Device not found via register read.\n"); | ||
6221 | err = -ENODEV; | ||
6222 | goto fail; | ||
6223 | } | ||
6224 | |||
6225 | SET_NETDEV_DEV(dev, &pci_dev->dev); | ||
6226 | |||
6227 | /* Force interrupts to be shut off on the device */ | ||
6228 | priv->status |= STATUS_INT_ENABLED; | ||
6229 | ipw2100_disable_interrupts(priv); | ||
6230 | |||
6231 | /* Allocate and initialize the Tx/Rx queues and lists */ | ||
6232 | if (ipw2100_queues_allocate(priv)) { | ||
6233 | printk(KERN_WARNING DRV_NAME | ||
6234 | "Error calling ipw2100_queues_allocate.\n"); | ||
6235 | err = -ENOMEM; | ||
6236 | goto fail; | ||
6237 | } | ||
6238 | ipw2100_queues_initialize(priv); | ||
6239 | |||
6240 | err = request_irq(pci_dev->irq, | ||
6241 | ipw2100_interrupt, IRQF_SHARED, dev->name, priv); | ||
6242 | if (err) { | ||
6243 | printk(KERN_WARNING DRV_NAME | ||
6244 | "Error calling request_irq: %d.\n", pci_dev->irq); | ||
6245 | goto fail; | ||
6246 | } | ||
6247 | dev->irq = pci_dev->irq; | ||
6248 | |||
6249 | IPW_DEBUG_INFO("Attempting to register device...\n"); | ||
6250 | |||
6251 | printk(KERN_INFO DRV_NAME | ||
6252 | ": Detected Intel PRO/Wireless 2100 Network Connection\n"); | ||
6253 | |||
6254 | /* Bring up the interface. Pre 0.46, after we registered the | ||
6255 | * network device we would call ipw2100_up. This introduced a race | ||
6256 | * condition with newer hotplug configurations (network was coming | ||
6257 | * up and making calls before the device was initialized). | ||
6258 | * | ||
6259 | * If we called ipw2100_up before we registered the device, then the | ||
6260 | * device name wasn't registered. So, we instead use the net_dev->init | ||
6261 | * member to call a function that then just turns and calls ipw2100_up. | ||
6262 | * net_dev->init is called after name allocation but before the | ||
6263 | * notifier chain is called */ | ||
6264 | err = register_netdev(dev); | ||
6265 | if (err) { | ||
6266 | printk(KERN_WARNING DRV_NAME | ||
6267 | "Error calling register_netdev.\n"); | ||
6268 | goto fail; | ||
6269 | } | ||
6270 | |||
6271 | mutex_lock(&priv->action_mutex); | ||
6272 | registered = 1; | ||
6273 | |||
6274 | IPW_DEBUG_INFO("%s: Bound to %s\n", dev->name, pci_name(pci_dev)); | ||
6275 | |||
6276 | /* perform this after register_netdev so that dev->name is set */ | ||
6277 | err = sysfs_create_group(&pci_dev->dev.kobj, &ipw2100_attribute_group); | ||
6278 | if (err) | ||
6279 | goto fail_unlock; | ||
6280 | |||
6281 | /* If the RF Kill switch is disabled, go ahead and complete the | ||
6282 | * startup sequence */ | ||
6283 | if (!(priv->status & STATUS_RF_KILL_MASK)) { | ||
6284 | /* Enable the adapter - sends HOST_COMPLETE */ | ||
6285 | if (ipw2100_enable_adapter(priv)) { | ||
6286 | printk(KERN_WARNING DRV_NAME | ||
6287 | ": %s: failed in call to enable adapter.\n", | ||
6288 | priv->net_dev->name); | ||
6289 | ipw2100_hw_stop_adapter(priv); | ||
6290 | err = -EIO; | ||
6291 | goto fail_unlock; | ||
6292 | } | ||
6293 | |||
6294 | /* Start a scan . . . */ | ||
6295 | ipw2100_set_scan_options(priv); | ||
6296 | ipw2100_start_scan(priv); | ||
6297 | } | ||
6298 | |||
6299 | IPW_DEBUG_INFO("exit\n"); | ||
6300 | |||
6301 | priv->status |= STATUS_INITIALIZED; | ||
6302 | |||
6303 | mutex_unlock(&priv->action_mutex); | ||
6304 | |||
6305 | return 0; | ||
6306 | |||
6307 | fail_unlock: | ||
6308 | mutex_unlock(&priv->action_mutex); | ||
6309 | |||
6310 | fail: | ||
6311 | if (dev) { | ||
6312 | if (registered) | ||
6313 | unregister_netdev(dev); | ||
6314 | |||
6315 | ipw2100_hw_stop_adapter(priv); | ||
6316 | |||
6317 | ipw2100_disable_interrupts(priv); | ||
6318 | |||
6319 | if (dev->irq) | ||
6320 | free_irq(dev->irq, priv); | ||
6321 | |||
6322 | ipw2100_kill_workqueue(priv); | ||
6323 | |||
6324 | /* These are safe to call even if they weren't allocated */ | ||
6325 | ipw2100_queues_free(priv); | ||
6326 | sysfs_remove_group(&pci_dev->dev.kobj, | ||
6327 | &ipw2100_attribute_group); | ||
6328 | |||
6329 | free_ieee80211(dev); | ||
6330 | pci_set_drvdata(pci_dev, NULL); | ||
6331 | } | ||
6332 | |||
6333 | if (base_addr) | ||
6334 | iounmap(base_addr); | ||
6335 | |||
6336 | pci_release_regions(pci_dev); | ||
6337 | pci_disable_device(pci_dev); | ||
6338 | |||
6339 | return err; | ||
6340 | } | ||
6341 | |||
6342 | static void __devexit ipw2100_pci_remove_one(struct pci_dev *pci_dev) | ||
6343 | { | ||
6344 | struct ipw2100_priv *priv = pci_get_drvdata(pci_dev); | ||
6345 | struct net_device *dev; | ||
6346 | |||
6347 | if (priv) { | ||
6348 | mutex_lock(&priv->action_mutex); | ||
6349 | |||
6350 | priv->status &= ~STATUS_INITIALIZED; | ||
6351 | |||
6352 | dev = priv->net_dev; | ||
6353 | sysfs_remove_group(&pci_dev->dev.kobj, | ||
6354 | &ipw2100_attribute_group); | ||
6355 | |||
6356 | #ifdef CONFIG_PM | ||
6357 | if (ipw2100_firmware.version) | ||
6358 | ipw2100_release_firmware(priv, &ipw2100_firmware); | ||
6359 | #endif | ||
6360 | /* Take down the hardware */ | ||
6361 | ipw2100_down(priv); | ||
6362 | |||
6363 | /* Release the mutex so that the network subsystem can | ||
6364 | * complete any needed calls into the driver... */ | ||
6365 | mutex_unlock(&priv->action_mutex); | ||
6366 | |||
6367 | /* Unregister the device first - this results in close() | ||
6368 | * being called if the device is open. If we free storage | ||
6369 | * first, then close() will crash. */ | ||
6370 | unregister_netdev(dev); | ||
6371 | |||
6372 | /* ipw2100_down will ensure that there is no more pending work | ||
6373 | * in the workqueue's, so we can safely remove them now. */ | ||
6374 | ipw2100_kill_workqueue(priv); | ||
6375 | |||
6376 | ipw2100_queues_free(priv); | ||
6377 | |||
6378 | /* Free potential debugging firmware snapshot */ | ||
6379 | ipw2100_snapshot_free(priv); | ||
6380 | |||
6381 | if (dev->irq) | ||
6382 | free_irq(dev->irq, priv); | ||
6383 | |||
6384 | if (dev->base_addr) | ||
6385 | iounmap((void __iomem *)dev->base_addr); | ||
6386 | |||
6387 | free_ieee80211(dev); | ||
6388 | } | ||
6389 | |||
6390 | pci_release_regions(pci_dev); | ||
6391 | pci_disable_device(pci_dev); | ||
6392 | |||
6393 | IPW_DEBUG_INFO("exit\n"); | ||
6394 | } | ||
6395 | |||
6396 | #ifdef CONFIG_PM | ||
6397 | static int ipw2100_suspend(struct pci_dev *pci_dev, pm_message_t state) | ||
6398 | { | ||
6399 | struct ipw2100_priv *priv = pci_get_drvdata(pci_dev); | ||
6400 | struct net_device *dev = priv->net_dev; | ||
6401 | |||
6402 | IPW_DEBUG_INFO("%s: Going into suspend...\n", dev->name); | ||
6403 | |||
6404 | mutex_lock(&priv->action_mutex); | ||
6405 | if (priv->status & STATUS_INITIALIZED) { | ||
6406 | /* Take down the device; powers it off, etc. */ | ||
6407 | ipw2100_down(priv); | ||
6408 | } | ||
6409 | |||
6410 | /* Remove the PRESENT state of the device */ | ||
6411 | netif_device_detach(dev); | ||
6412 | |||
6413 | pci_save_state(pci_dev); | ||
6414 | pci_disable_device(pci_dev); | ||
6415 | pci_set_power_state(pci_dev, PCI_D3hot); | ||
6416 | |||
6417 | mutex_unlock(&priv->action_mutex); | ||
6418 | |||
6419 | return 0; | ||
6420 | } | ||
6421 | |||
6422 | static int ipw2100_resume(struct pci_dev *pci_dev) | ||
6423 | { | ||
6424 | struct ipw2100_priv *priv = pci_get_drvdata(pci_dev); | ||
6425 | struct net_device *dev = priv->net_dev; | ||
6426 | int err; | ||
6427 | u32 val; | ||
6428 | |||
6429 | if (IPW2100_PM_DISABLED) | ||
6430 | return 0; | ||
6431 | |||
6432 | mutex_lock(&priv->action_mutex); | ||
6433 | |||
6434 | IPW_DEBUG_INFO("%s: Coming out of suspend...\n", dev->name); | ||
6435 | |||
6436 | pci_set_power_state(pci_dev, PCI_D0); | ||
6437 | err = pci_enable_device(pci_dev); | ||
6438 | if (err) { | ||
6439 | printk(KERN_ERR "%s: pci_enable_device failed on resume\n", | ||
6440 | dev->name); | ||
6441 | mutex_unlock(&priv->action_mutex); | ||
6442 | return err; | ||
6443 | } | ||
6444 | pci_restore_state(pci_dev); | ||
6445 | |||
6446 | /* | ||
6447 | * Suspend/Resume resets the PCI configuration space, so we have to | ||
6448 | * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries | ||
6449 | * from interfering with C3 CPU state. pci_restore_state won't help | ||
6450 | * here since it only restores the first 64 bytes pci config header. | ||
6451 | */ | ||
6452 | pci_read_config_dword(pci_dev, 0x40, &val); | ||
6453 | if ((val & 0x0000ff00) != 0) | ||
6454 | pci_write_config_dword(pci_dev, 0x40, val & 0xffff00ff); | ||
6455 | |||
6456 | /* Set the device back into the PRESENT state; this will also wake | ||
6457 | * the queue of needed */ | ||
6458 | netif_device_attach(dev); | ||
6459 | |||
6460 | /* Bring the device back up */ | ||
6461 | if (!(priv->status & STATUS_RF_KILL_SW)) | ||
6462 | ipw2100_up(priv, 0); | ||
6463 | |||
6464 | mutex_unlock(&priv->action_mutex); | ||
6465 | |||
6466 | return 0; | ||
6467 | } | ||
6468 | #endif | ||
6469 | |||
6470 | #define IPW2100_DEV_ID(x) { PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, x } | ||
6471 | |||
6472 | static struct pci_device_id ipw2100_pci_id_table[] __devinitdata = { | ||
6473 | IPW2100_DEV_ID(0x2520), /* IN 2100A mPCI 3A */ | ||
6474 | IPW2100_DEV_ID(0x2521), /* IN 2100A mPCI 3B */ | ||
6475 | IPW2100_DEV_ID(0x2524), /* IN 2100A mPCI 3B */ | ||
6476 | IPW2100_DEV_ID(0x2525), /* IN 2100A mPCI 3B */ | ||
6477 | IPW2100_DEV_ID(0x2526), /* IN 2100A mPCI Gen A3 */ | ||
6478 | IPW2100_DEV_ID(0x2522), /* IN 2100 mPCI 3B */ | ||
6479 | IPW2100_DEV_ID(0x2523), /* IN 2100 mPCI 3A */ | ||
6480 | IPW2100_DEV_ID(0x2527), /* IN 2100 mPCI 3B */ | ||
6481 | IPW2100_DEV_ID(0x2528), /* IN 2100 mPCI 3B */ | ||
6482 | IPW2100_DEV_ID(0x2529), /* IN 2100 mPCI 3B */ | ||
6483 | IPW2100_DEV_ID(0x252B), /* IN 2100 mPCI 3A */ | ||
6484 | IPW2100_DEV_ID(0x252C), /* IN 2100 mPCI 3A */ | ||
6485 | IPW2100_DEV_ID(0x252D), /* IN 2100 mPCI 3A */ | ||
6486 | |||
6487 | IPW2100_DEV_ID(0x2550), /* IB 2100A mPCI 3B */ | ||
6488 | IPW2100_DEV_ID(0x2551), /* IB 2100 mPCI 3B */ | ||
6489 | IPW2100_DEV_ID(0x2553), /* IB 2100 mPCI 3B */ | ||
6490 | IPW2100_DEV_ID(0x2554), /* IB 2100 mPCI 3B */ | ||
6491 | IPW2100_DEV_ID(0x2555), /* IB 2100 mPCI 3B */ | ||
6492 | |||
6493 | IPW2100_DEV_ID(0x2560), /* DE 2100A mPCI 3A */ | ||
6494 | IPW2100_DEV_ID(0x2562), /* DE 2100A mPCI 3A */ | ||
6495 | IPW2100_DEV_ID(0x2563), /* DE 2100A mPCI 3A */ | ||
6496 | IPW2100_DEV_ID(0x2561), /* DE 2100 mPCI 3A */ | ||
6497 | IPW2100_DEV_ID(0x2565), /* DE 2100 mPCI 3A */ | ||
6498 | IPW2100_DEV_ID(0x2566), /* DE 2100 mPCI 3A */ | ||
6499 | IPW2100_DEV_ID(0x2567), /* DE 2100 mPCI 3A */ | ||
6500 | |||
6501 | IPW2100_DEV_ID(0x2570), /* GA 2100 mPCI 3B */ | ||
6502 | |||
6503 | IPW2100_DEV_ID(0x2580), /* TO 2100A mPCI 3B */ | ||
6504 | IPW2100_DEV_ID(0x2582), /* TO 2100A mPCI 3B */ | ||
6505 | IPW2100_DEV_ID(0x2583), /* TO 2100A mPCI 3B */ | ||
6506 | IPW2100_DEV_ID(0x2581), /* TO 2100 mPCI 3B */ | ||
6507 | IPW2100_DEV_ID(0x2585), /* TO 2100 mPCI 3B */ | ||
6508 | IPW2100_DEV_ID(0x2586), /* TO 2100 mPCI 3B */ | ||
6509 | IPW2100_DEV_ID(0x2587), /* TO 2100 mPCI 3B */ | ||
6510 | |||
6511 | IPW2100_DEV_ID(0x2590), /* SO 2100A mPCI 3B */ | ||
6512 | IPW2100_DEV_ID(0x2592), /* SO 2100A mPCI 3B */ | ||
6513 | IPW2100_DEV_ID(0x2591), /* SO 2100 mPCI 3B */ | ||
6514 | IPW2100_DEV_ID(0x2593), /* SO 2100 mPCI 3B */ | ||
6515 | IPW2100_DEV_ID(0x2596), /* SO 2100 mPCI 3B */ | ||
6516 | IPW2100_DEV_ID(0x2598), /* SO 2100 mPCI 3B */ | ||
6517 | |||
6518 | IPW2100_DEV_ID(0x25A0), /* HP 2100 mPCI 3B */ | ||
6519 | {0,}, | ||
6520 | }; | ||
6521 | |||
6522 | MODULE_DEVICE_TABLE(pci, ipw2100_pci_id_table); | ||
6523 | |||
6524 | static struct pci_driver ipw2100_pci_driver = { | ||
6525 | .name = DRV_NAME, | ||
6526 | .id_table = ipw2100_pci_id_table, | ||
6527 | .probe = ipw2100_pci_init_one, | ||
6528 | .remove = __devexit_p(ipw2100_pci_remove_one), | ||
6529 | #ifdef CONFIG_PM | ||
6530 | .suspend = ipw2100_suspend, | ||
6531 | .resume = ipw2100_resume, | ||
6532 | #endif | ||
6533 | }; | ||
6534 | |||
6535 | /** | ||
6536 | * Initialize the ipw2100 driver/module | ||
6537 | * | ||
6538 | * @returns 0 if ok, < 0 errno node con error. | ||
6539 | * | ||
6540 | * Note: we cannot init the /proc stuff until the PCI driver is there, | ||
6541 | * or we risk an unlikely race condition on someone accessing | ||
6542 | * uninitialized data in the PCI dev struct through /proc. | ||
6543 | */ | ||
6544 | static int __init ipw2100_init(void) | ||
6545 | { | ||
6546 | int ret; | ||
6547 | |||
6548 | printk(KERN_INFO DRV_NAME ": %s, %s\n", DRV_DESCRIPTION, DRV_VERSION); | ||
6549 | printk(KERN_INFO DRV_NAME ": %s\n", DRV_COPYRIGHT); | ||
6550 | |||
6551 | ret = pci_register_driver(&ipw2100_pci_driver); | ||
6552 | if (ret) | ||
6553 | goto out; | ||
6554 | |||
6555 | pm_qos_add_requirement(PM_QOS_CPU_DMA_LATENCY, "ipw2100", | ||
6556 | PM_QOS_DEFAULT_VALUE); | ||
6557 | #ifdef CONFIG_IPW2100_DEBUG | ||
6558 | ipw2100_debug_level = debug; | ||
6559 | ret = driver_create_file(&ipw2100_pci_driver.driver, | ||
6560 | &driver_attr_debug_level); | ||
6561 | #endif | ||
6562 | |||
6563 | out: | ||
6564 | return ret; | ||
6565 | } | ||
6566 | |||
6567 | /** | ||
6568 | * Cleanup ipw2100 driver registration | ||
6569 | */ | ||
6570 | static void __exit ipw2100_exit(void) | ||
6571 | { | ||
6572 | /* FIXME: IPG: check that we have no instances of the devices open */ | ||
6573 | #ifdef CONFIG_IPW2100_DEBUG | ||
6574 | driver_remove_file(&ipw2100_pci_driver.driver, | ||
6575 | &driver_attr_debug_level); | ||
6576 | #endif | ||
6577 | pci_unregister_driver(&ipw2100_pci_driver); | ||
6578 | pm_qos_remove_requirement(PM_QOS_CPU_DMA_LATENCY, "ipw2100"); | ||
6579 | } | ||
6580 | |||
6581 | module_init(ipw2100_init); | ||
6582 | module_exit(ipw2100_exit); | ||
6583 | |||
6584 | #define WEXT_USECHANNELS 1 | ||
6585 | |||
6586 | static const long ipw2100_frequencies[] = { | ||
6587 | 2412, 2417, 2422, 2427, | ||
6588 | 2432, 2437, 2442, 2447, | ||
6589 | 2452, 2457, 2462, 2467, | ||
6590 | 2472, 2484 | ||
6591 | }; | ||
6592 | |||
6593 | #define FREQ_COUNT ARRAY_SIZE(ipw2100_frequencies) | ||
6594 | |||
6595 | static const long ipw2100_rates_11b[] = { | ||
6596 | 1000000, | ||
6597 | 2000000, | ||
6598 | 5500000, | ||
6599 | 11000000 | ||
6600 | }; | ||
6601 | |||
6602 | #define RATE_COUNT ARRAY_SIZE(ipw2100_rates_11b) | ||
6603 | |||
6604 | static int ipw2100_wx_get_name(struct net_device *dev, | ||
6605 | struct iw_request_info *info, | ||
6606 | union iwreq_data *wrqu, char *extra) | ||
6607 | { | ||
6608 | /* | ||
6609 | * This can be called at any time. No action lock required | ||
6610 | */ | ||
6611 | |||
6612 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
6613 | if (!(priv->status & STATUS_ASSOCIATED)) | ||
6614 | strcpy(wrqu->name, "unassociated"); | ||
6615 | else | ||
6616 | snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11b"); | ||
6617 | |||
6618 | IPW_DEBUG_WX("Name: %s\n", wrqu->name); | ||
6619 | return 0; | ||
6620 | } | ||
6621 | |||
6622 | static int ipw2100_wx_set_freq(struct net_device *dev, | ||
6623 | struct iw_request_info *info, | ||
6624 | union iwreq_data *wrqu, char *extra) | ||
6625 | { | ||
6626 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
6627 | struct iw_freq *fwrq = &wrqu->freq; | ||
6628 | int err = 0; | ||
6629 | |||
6630 | if (priv->ieee->iw_mode == IW_MODE_INFRA) | ||
6631 | return -EOPNOTSUPP; | ||
6632 | |||
6633 | mutex_lock(&priv->action_mutex); | ||
6634 | if (!(priv->status & STATUS_INITIALIZED)) { | ||
6635 | err = -EIO; | ||
6636 | goto done; | ||
6637 | } | ||
6638 | |||
6639 | /* if setting by freq convert to channel */ | ||
6640 | if (fwrq->e == 1) { | ||
6641 | if ((fwrq->m >= (int)2.412e8 && fwrq->m <= (int)2.487e8)) { | ||
6642 | int f = fwrq->m / 100000; | ||
6643 | int c = 0; | ||
6644 | |||
6645 | while ((c < REG_MAX_CHANNEL) && | ||
6646 | (f != ipw2100_frequencies[c])) | ||
6647 | c++; | ||
6648 | |||
6649 | /* hack to fall through */ | ||
6650 | fwrq->e = 0; | ||
6651 | fwrq->m = c + 1; | ||
6652 | } | ||
6653 | } | ||
6654 | |||
6655 | if (fwrq->e > 0 || fwrq->m > 1000) { | ||
6656 | err = -EOPNOTSUPP; | ||
6657 | goto done; | ||
6658 | } else { /* Set the channel */ | ||
6659 | IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m); | ||
6660 | err = ipw2100_set_channel(priv, fwrq->m, 0); | ||
6661 | } | ||
6662 | |||
6663 | done: | ||
6664 | mutex_unlock(&priv->action_mutex); | ||
6665 | return err; | ||
6666 | } | ||
6667 | |||
6668 | static int ipw2100_wx_get_freq(struct net_device *dev, | ||
6669 | struct iw_request_info *info, | ||
6670 | union iwreq_data *wrqu, char *extra) | ||
6671 | { | ||
6672 | /* | ||
6673 | * This can be called at any time. No action lock required | ||
6674 | */ | ||
6675 | |||
6676 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
6677 | |||
6678 | wrqu->freq.e = 0; | ||
6679 | |||
6680 | /* If we are associated, trying to associate, or have a statically | ||
6681 | * configured CHANNEL then return that; otherwise return ANY */ | ||
6682 | if (priv->config & CFG_STATIC_CHANNEL || | ||
6683 | priv->status & STATUS_ASSOCIATED) | ||
6684 | wrqu->freq.m = priv->channel; | ||
6685 | else | ||
6686 | wrqu->freq.m = 0; | ||
6687 | |||
6688 | IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel); | ||
6689 | return 0; | ||
6690 | |||
6691 | } | ||
6692 | |||
6693 | static int ipw2100_wx_set_mode(struct net_device *dev, | ||
6694 | struct iw_request_info *info, | ||
6695 | union iwreq_data *wrqu, char *extra) | ||
6696 | { | ||
6697 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
6698 | int err = 0; | ||
6699 | |||
6700 | IPW_DEBUG_WX("SET Mode -> %d \n", wrqu->mode); | ||
6701 | |||
6702 | if (wrqu->mode == priv->ieee->iw_mode) | ||
6703 | return 0; | ||
6704 | |||
6705 | mutex_lock(&priv->action_mutex); | ||
6706 | if (!(priv->status & STATUS_INITIALIZED)) { | ||
6707 | err = -EIO; | ||
6708 | goto done; | ||
6709 | } | ||
6710 | |||
6711 | switch (wrqu->mode) { | ||
6712 | #ifdef CONFIG_IPW2100_MONITOR | ||
6713 | case IW_MODE_MONITOR: | ||
6714 | err = ipw2100_switch_mode(priv, IW_MODE_MONITOR); | ||
6715 | break; | ||
6716 | #endif /* CONFIG_IPW2100_MONITOR */ | ||
6717 | case IW_MODE_ADHOC: | ||
6718 | err = ipw2100_switch_mode(priv, IW_MODE_ADHOC); | ||
6719 | break; | ||
6720 | case IW_MODE_INFRA: | ||
6721 | case IW_MODE_AUTO: | ||
6722 | default: | ||
6723 | err = ipw2100_switch_mode(priv, IW_MODE_INFRA); | ||
6724 | break; | ||
6725 | } | ||
6726 | |||
6727 | done: | ||
6728 | mutex_unlock(&priv->action_mutex); | ||
6729 | return err; | ||
6730 | } | ||
6731 | |||
6732 | static int ipw2100_wx_get_mode(struct net_device *dev, | ||
6733 | struct iw_request_info *info, | ||
6734 | union iwreq_data *wrqu, char *extra) | ||
6735 | { | ||
6736 | /* | ||
6737 | * This can be called at any time. No action lock required | ||
6738 | */ | ||
6739 | |||
6740 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
6741 | |||
6742 | wrqu->mode = priv->ieee->iw_mode; | ||
6743 | IPW_DEBUG_WX("GET Mode -> %d\n", wrqu->mode); | ||
6744 | |||
6745 | return 0; | ||
6746 | } | ||
6747 | |||
6748 | #define POWER_MODES 5 | ||
6749 | |||
6750 | /* Values are in microsecond */ | ||
6751 | static const s32 timeout_duration[POWER_MODES] = { | ||
6752 | 350000, | ||
6753 | 250000, | ||
6754 | 75000, | ||
6755 | 37000, | ||
6756 | 25000, | ||
6757 | }; | ||
6758 | |||
6759 | static const s32 period_duration[POWER_MODES] = { | ||
6760 | 400000, | ||
6761 | 700000, | ||
6762 | 1000000, | ||
6763 | 1000000, | ||
6764 | 1000000 | ||
6765 | }; | ||
6766 | |||
6767 | static int ipw2100_wx_get_range(struct net_device *dev, | ||
6768 | struct iw_request_info *info, | ||
6769 | union iwreq_data *wrqu, char *extra) | ||
6770 | { | ||
6771 | /* | ||
6772 | * This can be called at any time. No action lock required | ||
6773 | */ | ||
6774 | |||
6775 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
6776 | struct iw_range *range = (struct iw_range *)extra; | ||
6777 | u16 val; | ||
6778 | int i, level; | ||
6779 | |||
6780 | wrqu->data.length = sizeof(*range); | ||
6781 | memset(range, 0, sizeof(*range)); | ||
6782 | |||
6783 | /* Let's try to keep this struct in the same order as in | ||
6784 | * linux/include/wireless.h | ||
6785 | */ | ||
6786 | |||
6787 | /* TODO: See what values we can set, and remove the ones we can't | ||
6788 | * set, or fill them with some default data. | ||
6789 | */ | ||
6790 | |||
6791 | /* ~5 Mb/s real (802.11b) */ | ||
6792 | range->throughput = 5 * 1000 * 1000; | ||
6793 | |||
6794 | // range->sensitivity; /* signal level threshold range */ | ||
6795 | |||
6796 | range->max_qual.qual = 100; | ||
6797 | /* TODO: Find real max RSSI and stick here */ | ||
6798 | range->max_qual.level = 0; | ||
6799 | range->max_qual.noise = 0; | ||
6800 | range->max_qual.updated = 7; /* Updated all three */ | ||
6801 | |||
6802 | range->avg_qual.qual = 70; /* > 8% missed beacons is 'bad' */ | ||
6803 | /* TODO: Find real 'good' to 'bad' threshol value for RSSI */ | ||
6804 | range->avg_qual.level = 20 + IPW2100_RSSI_TO_DBM; | ||
6805 | range->avg_qual.noise = 0; | ||
6806 | range->avg_qual.updated = 7; /* Updated all three */ | ||
6807 | |||
6808 | range->num_bitrates = RATE_COUNT; | ||
6809 | |||
6810 | for (i = 0; i < RATE_COUNT && i < IW_MAX_BITRATES; i++) { | ||
6811 | range->bitrate[i] = ipw2100_rates_11b[i]; | ||
6812 | } | ||
6813 | |||
6814 | range->min_rts = MIN_RTS_THRESHOLD; | ||
6815 | range->max_rts = MAX_RTS_THRESHOLD; | ||
6816 | range->min_frag = MIN_FRAG_THRESHOLD; | ||
6817 | range->max_frag = MAX_FRAG_THRESHOLD; | ||
6818 | |||
6819 | range->min_pmp = period_duration[0]; /* Minimal PM period */ | ||
6820 | range->max_pmp = period_duration[POWER_MODES - 1]; /* Maximal PM period */ | ||
6821 | range->min_pmt = timeout_duration[POWER_MODES - 1]; /* Minimal PM timeout */ | ||
6822 | range->max_pmt = timeout_duration[0]; /* Maximal PM timeout */ | ||
6823 | |||
6824 | /* How to decode max/min PM period */ | ||
6825 | range->pmp_flags = IW_POWER_PERIOD; | ||
6826 | /* How to decode max/min PM period */ | ||
6827 | range->pmt_flags = IW_POWER_TIMEOUT; | ||
6828 | /* What PM options are supported */ | ||
6829 | range->pm_capa = IW_POWER_TIMEOUT | IW_POWER_PERIOD; | ||
6830 | |||
6831 | range->encoding_size[0] = 5; | ||
6832 | range->encoding_size[1] = 13; /* Different token sizes */ | ||
6833 | range->num_encoding_sizes = 2; /* Number of entry in the list */ | ||
6834 | range->max_encoding_tokens = WEP_KEYS; /* Max number of tokens */ | ||
6835 | // range->encoding_login_index; /* token index for login token */ | ||
6836 | |||
6837 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { | ||
6838 | range->txpower_capa = IW_TXPOW_DBM; | ||
6839 | range->num_txpower = IW_MAX_TXPOWER; | ||
6840 | for (i = 0, level = (IPW_TX_POWER_MAX_DBM * 16); | ||
6841 | i < IW_MAX_TXPOWER; | ||
6842 | i++, level -= | ||
6843 | ((IPW_TX_POWER_MAX_DBM - | ||
6844 | IPW_TX_POWER_MIN_DBM) * 16) / (IW_MAX_TXPOWER - 1)) | ||
6845 | range->txpower[i] = level / 16; | ||
6846 | } else { | ||
6847 | range->txpower_capa = 0; | ||
6848 | range->num_txpower = 0; | ||
6849 | } | ||
6850 | |||
6851 | /* Set the Wireless Extension versions */ | ||
6852 | range->we_version_compiled = WIRELESS_EXT; | ||
6853 | range->we_version_source = 18; | ||
6854 | |||
6855 | // range->retry_capa; /* What retry options are supported */ | ||
6856 | // range->retry_flags; /* How to decode max/min retry limit */ | ||
6857 | // range->r_time_flags; /* How to decode max/min retry life */ | ||
6858 | // range->min_retry; /* Minimal number of retries */ | ||
6859 | // range->max_retry; /* Maximal number of retries */ | ||
6860 | // range->min_r_time; /* Minimal retry lifetime */ | ||
6861 | // range->max_r_time; /* Maximal retry lifetime */ | ||
6862 | |||
6863 | range->num_channels = FREQ_COUNT; | ||
6864 | |||
6865 | val = 0; | ||
6866 | for (i = 0; i < FREQ_COUNT; i++) { | ||
6867 | // TODO: Include only legal frequencies for some countries | ||
6868 | // if (local->channel_mask & (1 << i)) { | ||
6869 | range->freq[val].i = i + 1; | ||
6870 | range->freq[val].m = ipw2100_frequencies[i] * 100000; | ||
6871 | range->freq[val].e = 1; | ||
6872 | val++; | ||
6873 | // } | ||
6874 | if (val == IW_MAX_FREQUENCIES) | ||
6875 | break; | ||
6876 | } | ||
6877 | range->num_frequency = val; | ||
6878 | |||
6879 | /* Event capability (kernel + driver) */ | ||
6880 | range->event_capa[0] = (IW_EVENT_CAPA_K_0 | | ||
6881 | IW_EVENT_CAPA_MASK(SIOCGIWAP)); | ||
6882 | range->event_capa[1] = IW_EVENT_CAPA_K_1; | ||
6883 | |||
6884 | range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 | | ||
6885 | IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP; | ||
6886 | |||
6887 | IPW_DEBUG_WX("GET Range\n"); | ||
6888 | |||
6889 | return 0; | ||
6890 | } | ||
6891 | |||
6892 | static int ipw2100_wx_set_wap(struct net_device *dev, | ||
6893 | struct iw_request_info *info, | ||
6894 | union iwreq_data *wrqu, char *extra) | ||
6895 | { | ||
6896 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
6897 | int err = 0; | ||
6898 | |||
6899 | static const unsigned char any[] = { | ||
6900 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff | ||
6901 | }; | ||
6902 | static const unsigned char off[] = { | ||
6903 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | ||
6904 | }; | ||
6905 | |||
6906 | // sanity checks | ||
6907 | if (wrqu->ap_addr.sa_family != ARPHRD_ETHER) | ||
6908 | return -EINVAL; | ||
6909 | |||
6910 | mutex_lock(&priv->action_mutex); | ||
6911 | if (!(priv->status & STATUS_INITIALIZED)) { | ||
6912 | err = -EIO; | ||
6913 | goto done; | ||
6914 | } | ||
6915 | |||
6916 | if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) || | ||
6917 | !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) { | ||
6918 | /* we disable mandatory BSSID association */ | ||
6919 | IPW_DEBUG_WX("exit - disable mandatory BSSID\n"); | ||
6920 | priv->config &= ~CFG_STATIC_BSSID; | ||
6921 | err = ipw2100_set_mandatory_bssid(priv, NULL, 0); | ||
6922 | goto done; | ||
6923 | } | ||
6924 | |||
6925 | priv->config |= CFG_STATIC_BSSID; | ||
6926 | memcpy(priv->mandatory_bssid_mac, wrqu->ap_addr.sa_data, ETH_ALEN); | ||
6927 | |||
6928 | err = ipw2100_set_mandatory_bssid(priv, wrqu->ap_addr.sa_data, 0); | ||
6929 | |||
6930 | IPW_DEBUG_WX("SET BSSID -> %pM\n", wrqu->ap_addr.sa_data); | ||
6931 | |||
6932 | done: | ||
6933 | mutex_unlock(&priv->action_mutex); | ||
6934 | return err; | ||
6935 | } | ||
6936 | |||
6937 | static int ipw2100_wx_get_wap(struct net_device *dev, | ||
6938 | struct iw_request_info *info, | ||
6939 | union iwreq_data *wrqu, char *extra) | ||
6940 | { | ||
6941 | /* | ||
6942 | * This can be called at any time. No action lock required | ||
6943 | */ | ||
6944 | |||
6945 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
6946 | |||
6947 | /* If we are associated, trying to associate, or have a statically | ||
6948 | * configured BSSID then return that; otherwise return ANY */ | ||
6949 | if (priv->config & CFG_STATIC_BSSID || priv->status & STATUS_ASSOCIATED) { | ||
6950 | wrqu->ap_addr.sa_family = ARPHRD_ETHER; | ||
6951 | memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN); | ||
6952 | } else | ||
6953 | memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN); | ||
6954 | |||
6955 | IPW_DEBUG_WX("Getting WAP BSSID: %pM\n", wrqu->ap_addr.sa_data); | ||
6956 | return 0; | ||
6957 | } | ||
6958 | |||
6959 | static int ipw2100_wx_set_essid(struct net_device *dev, | ||
6960 | struct iw_request_info *info, | ||
6961 | union iwreq_data *wrqu, char *extra) | ||
6962 | { | ||
6963 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
6964 | char *essid = ""; /* ANY */ | ||
6965 | int length = 0; | ||
6966 | int err = 0; | ||
6967 | DECLARE_SSID_BUF(ssid); | ||
6968 | |||
6969 | mutex_lock(&priv->action_mutex); | ||
6970 | if (!(priv->status & STATUS_INITIALIZED)) { | ||
6971 | err = -EIO; | ||
6972 | goto done; | ||
6973 | } | ||
6974 | |||
6975 | if (wrqu->essid.flags && wrqu->essid.length) { | ||
6976 | length = wrqu->essid.length; | ||
6977 | essid = extra; | ||
6978 | } | ||
6979 | |||
6980 | if (length == 0) { | ||
6981 | IPW_DEBUG_WX("Setting ESSID to ANY\n"); | ||
6982 | priv->config &= ~CFG_STATIC_ESSID; | ||
6983 | err = ipw2100_set_essid(priv, NULL, 0, 0); | ||
6984 | goto done; | ||
6985 | } | ||
6986 | |||
6987 | length = min(length, IW_ESSID_MAX_SIZE); | ||
6988 | |||
6989 | priv->config |= CFG_STATIC_ESSID; | ||
6990 | |||
6991 | if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) { | ||
6992 | IPW_DEBUG_WX("ESSID set to current ESSID.\n"); | ||
6993 | err = 0; | ||
6994 | goto done; | ||
6995 | } | ||
6996 | |||
6997 | IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", | ||
6998 | print_ssid(ssid, essid, length), length); | ||
6999 | |||
7000 | priv->essid_len = length; | ||
7001 | memcpy(priv->essid, essid, priv->essid_len); | ||
7002 | |||
7003 | err = ipw2100_set_essid(priv, essid, length, 0); | ||
7004 | |||
7005 | done: | ||
7006 | mutex_unlock(&priv->action_mutex); | ||
7007 | return err; | ||
7008 | } | ||
7009 | |||
7010 | static int ipw2100_wx_get_essid(struct net_device *dev, | ||
7011 | struct iw_request_info *info, | ||
7012 | union iwreq_data *wrqu, char *extra) | ||
7013 | { | ||
7014 | /* | ||
7015 | * This can be called at any time. No action lock required | ||
7016 | */ | ||
7017 | |||
7018 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
7019 | DECLARE_SSID_BUF(ssid); | ||
7020 | |||
7021 | /* If we are associated, trying to associate, or have a statically | ||
7022 | * configured ESSID then return that; otherwise return ANY */ | ||
7023 | if (priv->config & CFG_STATIC_ESSID || priv->status & STATUS_ASSOCIATED) { | ||
7024 | IPW_DEBUG_WX("Getting essid: '%s'\n", | ||
7025 | print_ssid(ssid, priv->essid, priv->essid_len)); | ||
7026 | memcpy(extra, priv->essid, priv->essid_len); | ||
7027 | wrqu->essid.length = priv->essid_len; | ||
7028 | wrqu->essid.flags = 1; /* active */ | ||
7029 | } else { | ||
7030 | IPW_DEBUG_WX("Getting essid: ANY\n"); | ||
7031 | wrqu->essid.length = 0; | ||
7032 | wrqu->essid.flags = 0; /* active */ | ||
7033 | } | ||
7034 | |||
7035 | return 0; | ||
7036 | } | ||
7037 | |||
7038 | static int ipw2100_wx_set_nick(struct net_device *dev, | ||
7039 | struct iw_request_info *info, | ||
7040 | union iwreq_data *wrqu, char *extra) | ||
7041 | { | ||
7042 | /* | ||
7043 | * This can be called at any time. No action lock required | ||
7044 | */ | ||
7045 | |||
7046 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
7047 | |||
7048 | if (wrqu->data.length > IW_ESSID_MAX_SIZE) | ||
7049 | return -E2BIG; | ||
7050 | |||
7051 | wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick)); | ||
7052 | memset(priv->nick, 0, sizeof(priv->nick)); | ||
7053 | memcpy(priv->nick, extra, wrqu->data.length); | ||
7054 | |||
7055 | IPW_DEBUG_WX("SET Nickname -> %s \n", priv->nick); | ||
7056 | |||
7057 | return 0; | ||
7058 | } | ||
7059 | |||
7060 | static int ipw2100_wx_get_nick(struct net_device *dev, | ||
7061 | struct iw_request_info *info, | ||
7062 | union iwreq_data *wrqu, char *extra) | ||
7063 | { | ||
7064 | /* | ||
7065 | * This can be called at any time. No action lock required | ||
7066 | */ | ||
7067 | |||
7068 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
7069 | |||
7070 | wrqu->data.length = strlen(priv->nick); | ||
7071 | memcpy(extra, priv->nick, wrqu->data.length); | ||
7072 | wrqu->data.flags = 1; /* active */ | ||
7073 | |||
7074 | IPW_DEBUG_WX("GET Nickname -> %s \n", extra); | ||
7075 | |||
7076 | return 0; | ||
7077 | } | ||
7078 | |||
7079 | static int ipw2100_wx_set_rate(struct net_device *dev, | ||
7080 | struct iw_request_info *info, | ||
7081 | union iwreq_data *wrqu, char *extra) | ||
7082 | { | ||
7083 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
7084 | u32 target_rate = wrqu->bitrate.value; | ||
7085 | u32 rate; | ||
7086 | int err = 0; | ||
7087 | |||
7088 | mutex_lock(&priv->action_mutex); | ||
7089 | if (!(priv->status & STATUS_INITIALIZED)) { | ||
7090 | err = -EIO; | ||
7091 | goto done; | ||
7092 | } | ||
7093 | |||
7094 | rate = 0; | ||
7095 | |||
7096 | if (target_rate == 1000000 || | ||
7097 | (!wrqu->bitrate.fixed && target_rate > 1000000)) | ||
7098 | rate |= TX_RATE_1_MBIT; | ||
7099 | if (target_rate == 2000000 || | ||
7100 | (!wrqu->bitrate.fixed && target_rate > 2000000)) | ||
7101 | rate |= TX_RATE_2_MBIT; | ||
7102 | if (target_rate == 5500000 || | ||
7103 | (!wrqu->bitrate.fixed && target_rate > 5500000)) | ||
7104 | rate |= TX_RATE_5_5_MBIT; | ||
7105 | if (target_rate == 11000000 || | ||
7106 | (!wrqu->bitrate.fixed && target_rate > 11000000)) | ||
7107 | rate |= TX_RATE_11_MBIT; | ||
7108 | if (rate == 0) | ||
7109 | rate = DEFAULT_TX_RATES; | ||
7110 | |||
7111 | err = ipw2100_set_tx_rates(priv, rate, 0); | ||
7112 | |||
7113 | IPW_DEBUG_WX("SET Rate -> %04X \n", rate); | ||
7114 | done: | ||
7115 | mutex_unlock(&priv->action_mutex); | ||
7116 | return err; | ||
7117 | } | ||
7118 | |||
7119 | static int ipw2100_wx_get_rate(struct net_device *dev, | ||
7120 | struct iw_request_info *info, | ||
7121 | union iwreq_data *wrqu, char *extra) | ||
7122 | { | ||
7123 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
7124 | int val; | ||
7125 | int len = sizeof(val); | ||
7126 | int err = 0; | ||
7127 | |||
7128 | if (!(priv->status & STATUS_ENABLED) || | ||
7129 | priv->status & STATUS_RF_KILL_MASK || | ||
7130 | !(priv->status & STATUS_ASSOCIATED)) { | ||
7131 | wrqu->bitrate.value = 0; | ||
7132 | return 0; | ||
7133 | } | ||
7134 | |||
7135 | mutex_lock(&priv->action_mutex); | ||
7136 | if (!(priv->status & STATUS_INITIALIZED)) { | ||
7137 | err = -EIO; | ||
7138 | goto done; | ||
7139 | } | ||
7140 | |||
7141 | err = ipw2100_get_ordinal(priv, IPW_ORD_CURRENT_TX_RATE, &val, &len); | ||
7142 | if (err) { | ||
7143 | IPW_DEBUG_WX("failed querying ordinals.\n"); | ||
7144 | goto done; | ||
7145 | } | ||
7146 | |||
7147 | switch (val & TX_RATE_MASK) { | ||
7148 | case TX_RATE_1_MBIT: | ||
7149 | wrqu->bitrate.value = 1000000; | ||
7150 | break; | ||
7151 | case TX_RATE_2_MBIT: | ||
7152 | wrqu->bitrate.value = 2000000; | ||
7153 | break; | ||
7154 | case TX_RATE_5_5_MBIT: | ||
7155 | wrqu->bitrate.value = 5500000; | ||
7156 | break; | ||
7157 | case TX_RATE_11_MBIT: | ||
7158 | wrqu->bitrate.value = 11000000; | ||
7159 | break; | ||
7160 | default: | ||
7161 | wrqu->bitrate.value = 0; | ||
7162 | } | ||
7163 | |||
7164 | IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value); | ||
7165 | |||
7166 | done: | ||
7167 | mutex_unlock(&priv->action_mutex); | ||
7168 | return err; | ||
7169 | } | ||
7170 | |||
7171 | static int ipw2100_wx_set_rts(struct net_device *dev, | ||
7172 | struct iw_request_info *info, | ||
7173 | union iwreq_data *wrqu, char *extra) | ||
7174 | { | ||
7175 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
7176 | int value, err; | ||
7177 | |||
7178 | /* Auto RTS not yet supported */ | ||
7179 | if (wrqu->rts.fixed == 0) | ||
7180 | return -EINVAL; | ||
7181 | |||
7182 | mutex_lock(&priv->action_mutex); | ||
7183 | if (!(priv->status & STATUS_INITIALIZED)) { | ||
7184 | err = -EIO; | ||
7185 | goto done; | ||
7186 | } | ||
7187 | |||
7188 | if (wrqu->rts.disabled) | ||
7189 | value = priv->rts_threshold | RTS_DISABLED; | ||
7190 | else { | ||
7191 | if (wrqu->rts.value < 1 || wrqu->rts.value > 2304) { | ||
7192 | err = -EINVAL; | ||
7193 | goto done; | ||
7194 | } | ||
7195 | value = wrqu->rts.value; | ||
7196 | } | ||
7197 | |||
7198 | err = ipw2100_set_rts_threshold(priv, value); | ||
7199 | |||
7200 | IPW_DEBUG_WX("SET RTS Threshold -> 0x%08X \n", value); | ||
7201 | done: | ||
7202 | mutex_unlock(&priv->action_mutex); | ||
7203 | return err; | ||
7204 | } | ||
7205 | |||
7206 | static int ipw2100_wx_get_rts(struct net_device *dev, | ||
7207 | struct iw_request_info *info, | ||
7208 | union iwreq_data *wrqu, char *extra) | ||
7209 | { | ||
7210 | /* | ||
7211 | * This can be called at any time. No action lock required | ||
7212 | */ | ||
7213 | |||
7214 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
7215 | |||
7216 | wrqu->rts.value = priv->rts_threshold & ~RTS_DISABLED; | ||
7217 | wrqu->rts.fixed = 1; /* no auto select */ | ||
7218 | |||
7219 | /* If RTS is set to the default value, then it is disabled */ | ||
7220 | wrqu->rts.disabled = (priv->rts_threshold & RTS_DISABLED) ? 1 : 0; | ||
7221 | |||
7222 | IPW_DEBUG_WX("GET RTS Threshold -> 0x%08X \n", wrqu->rts.value); | ||
7223 | |||
7224 | return 0; | ||
7225 | } | ||
7226 | |||
7227 | static int ipw2100_wx_set_txpow(struct net_device *dev, | ||
7228 | struct iw_request_info *info, | ||
7229 | union iwreq_data *wrqu, char *extra) | ||
7230 | { | ||
7231 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
7232 | int err = 0, value; | ||
7233 | |||
7234 | if (ipw_radio_kill_sw(priv, wrqu->txpower.disabled)) | ||
7235 | return -EINPROGRESS; | ||
7236 | |||
7237 | if (priv->ieee->iw_mode != IW_MODE_ADHOC) | ||
7238 | return 0; | ||
7239 | |||
7240 | if ((wrqu->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM) | ||
7241 | return -EINVAL; | ||
7242 | |||
7243 | if (wrqu->txpower.fixed == 0) | ||
7244 | value = IPW_TX_POWER_DEFAULT; | ||
7245 | else { | ||
7246 | if (wrqu->txpower.value < IPW_TX_POWER_MIN_DBM || | ||
7247 | wrqu->txpower.value > IPW_TX_POWER_MAX_DBM) | ||
7248 | return -EINVAL; | ||
7249 | |||
7250 | value = wrqu->txpower.value; | ||
7251 | } | ||
7252 | |||
7253 | mutex_lock(&priv->action_mutex); | ||
7254 | if (!(priv->status & STATUS_INITIALIZED)) { | ||
7255 | err = -EIO; | ||
7256 | goto done; | ||
7257 | } | ||
7258 | |||
7259 | err = ipw2100_set_tx_power(priv, value); | ||
7260 | |||
7261 | IPW_DEBUG_WX("SET TX Power -> %d \n", value); | ||
7262 | |||
7263 | done: | ||
7264 | mutex_unlock(&priv->action_mutex); | ||
7265 | return err; | ||
7266 | } | ||
7267 | |||
7268 | static int ipw2100_wx_get_txpow(struct net_device *dev, | ||
7269 | struct iw_request_info *info, | ||
7270 | union iwreq_data *wrqu, char *extra) | ||
7271 | { | ||
7272 | /* | ||
7273 | * This can be called at any time. No action lock required | ||
7274 | */ | ||
7275 | |||
7276 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
7277 | |||
7278 | wrqu->txpower.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0; | ||
7279 | |||
7280 | if (priv->tx_power == IPW_TX_POWER_DEFAULT) { | ||
7281 | wrqu->txpower.fixed = 0; | ||
7282 | wrqu->txpower.value = IPW_TX_POWER_MAX_DBM; | ||
7283 | } else { | ||
7284 | wrqu->txpower.fixed = 1; | ||
7285 | wrqu->txpower.value = priv->tx_power; | ||
7286 | } | ||
7287 | |||
7288 | wrqu->txpower.flags = IW_TXPOW_DBM; | ||
7289 | |||
7290 | IPW_DEBUG_WX("GET TX Power -> %d \n", wrqu->txpower.value); | ||
7291 | |||
7292 | return 0; | ||
7293 | } | ||
7294 | |||
7295 | static int ipw2100_wx_set_frag(struct net_device *dev, | ||
7296 | struct iw_request_info *info, | ||
7297 | union iwreq_data *wrqu, char *extra) | ||
7298 | { | ||
7299 | /* | ||
7300 | * This can be called at any time. No action lock required | ||
7301 | */ | ||
7302 | |||
7303 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
7304 | |||
7305 | if (!wrqu->frag.fixed) | ||
7306 | return -EINVAL; | ||
7307 | |||
7308 | if (wrqu->frag.disabled) { | ||
7309 | priv->frag_threshold |= FRAG_DISABLED; | ||
7310 | priv->ieee->fts = DEFAULT_FTS; | ||
7311 | } else { | ||
7312 | if (wrqu->frag.value < MIN_FRAG_THRESHOLD || | ||
7313 | wrqu->frag.value > MAX_FRAG_THRESHOLD) | ||
7314 | return -EINVAL; | ||
7315 | |||
7316 | priv->ieee->fts = wrqu->frag.value & ~0x1; | ||
7317 | priv->frag_threshold = priv->ieee->fts; | ||
7318 | } | ||
7319 | |||
7320 | IPW_DEBUG_WX("SET Frag Threshold -> %d \n", priv->ieee->fts); | ||
7321 | |||
7322 | return 0; | ||
7323 | } | ||
7324 | |||
7325 | static int ipw2100_wx_get_frag(struct net_device *dev, | ||
7326 | struct iw_request_info *info, | ||
7327 | union iwreq_data *wrqu, char *extra) | ||
7328 | { | ||
7329 | /* | ||
7330 | * This can be called at any time. No action lock required | ||
7331 | */ | ||
7332 | |||
7333 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
7334 | wrqu->frag.value = priv->frag_threshold & ~FRAG_DISABLED; | ||
7335 | wrqu->frag.fixed = 0; /* no auto select */ | ||
7336 | wrqu->frag.disabled = (priv->frag_threshold & FRAG_DISABLED) ? 1 : 0; | ||
7337 | |||
7338 | IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value); | ||
7339 | |||
7340 | return 0; | ||
7341 | } | ||
7342 | |||
7343 | static int ipw2100_wx_set_retry(struct net_device *dev, | ||
7344 | struct iw_request_info *info, | ||
7345 | union iwreq_data *wrqu, char *extra) | ||
7346 | { | ||
7347 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
7348 | int err = 0; | ||
7349 | |||
7350 | if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled) | ||
7351 | return -EINVAL; | ||
7352 | |||
7353 | if (!(wrqu->retry.flags & IW_RETRY_LIMIT)) | ||
7354 | return 0; | ||
7355 | |||
7356 | mutex_lock(&priv->action_mutex); | ||
7357 | if (!(priv->status & STATUS_INITIALIZED)) { | ||
7358 | err = -EIO; | ||
7359 | goto done; | ||
7360 | } | ||
7361 | |||
7362 | if (wrqu->retry.flags & IW_RETRY_SHORT) { | ||
7363 | err = ipw2100_set_short_retry(priv, wrqu->retry.value); | ||
7364 | IPW_DEBUG_WX("SET Short Retry Limit -> %d \n", | ||
7365 | wrqu->retry.value); | ||
7366 | goto done; | ||
7367 | } | ||
7368 | |||
7369 | if (wrqu->retry.flags & IW_RETRY_LONG) { | ||
7370 | err = ipw2100_set_long_retry(priv, wrqu->retry.value); | ||
7371 | IPW_DEBUG_WX("SET Long Retry Limit -> %d \n", | ||
7372 | wrqu->retry.value); | ||
7373 | goto done; | ||
7374 | } | ||
7375 | |||
7376 | err = ipw2100_set_short_retry(priv, wrqu->retry.value); | ||
7377 | if (!err) | ||
7378 | err = ipw2100_set_long_retry(priv, wrqu->retry.value); | ||
7379 | |||
7380 | IPW_DEBUG_WX("SET Both Retry Limits -> %d \n", wrqu->retry.value); | ||
7381 | |||
7382 | done: | ||
7383 | mutex_unlock(&priv->action_mutex); | ||
7384 | return err; | ||
7385 | } | ||
7386 | |||
7387 | static int ipw2100_wx_get_retry(struct net_device *dev, | ||
7388 | struct iw_request_info *info, | ||
7389 | union iwreq_data *wrqu, char *extra) | ||
7390 | { | ||
7391 | /* | ||
7392 | * This can be called at any time. No action lock required | ||
7393 | */ | ||
7394 | |||
7395 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
7396 | |||
7397 | wrqu->retry.disabled = 0; /* can't be disabled */ | ||
7398 | |||
7399 | if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) | ||
7400 | return -EINVAL; | ||
7401 | |||
7402 | if (wrqu->retry.flags & IW_RETRY_LONG) { | ||
7403 | wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_LONG; | ||
7404 | wrqu->retry.value = priv->long_retry_limit; | ||
7405 | } else { | ||
7406 | wrqu->retry.flags = | ||
7407 | (priv->short_retry_limit != | ||
7408 | priv->long_retry_limit) ? | ||
7409 | IW_RETRY_LIMIT | IW_RETRY_SHORT : IW_RETRY_LIMIT; | ||
7410 | |||
7411 | wrqu->retry.value = priv->short_retry_limit; | ||
7412 | } | ||
7413 | |||
7414 | IPW_DEBUG_WX("GET Retry -> %d \n", wrqu->retry.value); | ||
7415 | |||
7416 | return 0; | ||
7417 | } | ||
7418 | |||
7419 | static int ipw2100_wx_set_scan(struct net_device *dev, | ||
7420 | struct iw_request_info *info, | ||
7421 | union iwreq_data *wrqu, char *extra) | ||
7422 | { | ||
7423 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
7424 | int err = 0; | ||
7425 | |||
7426 | mutex_lock(&priv->action_mutex); | ||
7427 | if (!(priv->status & STATUS_INITIALIZED)) { | ||
7428 | err = -EIO; | ||
7429 | goto done; | ||
7430 | } | ||
7431 | |||
7432 | IPW_DEBUG_WX("Initiating scan...\n"); | ||
7433 | |||
7434 | priv->user_requested_scan = 1; | ||
7435 | if (ipw2100_set_scan_options(priv) || ipw2100_start_scan(priv)) { | ||
7436 | IPW_DEBUG_WX("Start scan failed.\n"); | ||
7437 | |||
7438 | /* TODO: Mark a scan as pending so when hardware initialized | ||
7439 | * a scan starts */ | ||
7440 | } | ||
7441 | |||
7442 | done: | ||
7443 | mutex_unlock(&priv->action_mutex); | ||
7444 | return err; | ||
7445 | } | ||
7446 | |||
7447 | static int ipw2100_wx_get_scan(struct net_device *dev, | ||
7448 | struct iw_request_info *info, | ||
7449 | union iwreq_data *wrqu, char *extra) | ||
7450 | { | ||
7451 | /* | ||
7452 | * This can be called at any time. No action lock required | ||
7453 | */ | ||
7454 | |||
7455 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
7456 | return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra); | ||
7457 | } | ||
7458 | |||
7459 | /* | ||
7460 | * Implementation based on code in hostap-driver v0.1.3 hostap_ioctl.c | ||
7461 | */ | ||
7462 | static int ipw2100_wx_set_encode(struct net_device *dev, | ||
7463 | struct iw_request_info *info, | ||
7464 | union iwreq_data *wrqu, char *key) | ||
7465 | { | ||
7466 | /* | ||
7467 | * No check of STATUS_INITIALIZED required | ||
7468 | */ | ||
7469 | |||
7470 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
7471 | return ieee80211_wx_set_encode(priv->ieee, info, wrqu, key); | ||
7472 | } | ||
7473 | |||
7474 | static int ipw2100_wx_get_encode(struct net_device *dev, | ||
7475 | struct iw_request_info *info, | ||
7476 | union iwreq_data *wrqu, char *key) | ||
7477 | { | ||
7478 | /* | ||
7479 | * This can be called at any time. No action lock required | ||
7480 | */ | ||
7481 | |||
7482 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
7483 | return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key); | ||
7484 | } | ||
7485 | |||
7486 | static int ipw2100_wx_set_power(struct net_device *dev, | ||
7487 | struct iw_request_info *info, | ||
7488 | union iwreq_data *wrqu, char *extra) | ||
7489 | { | ||
7490 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
7491 | int err = 0; | ||
7492 | |||
7493 | mutex_lock(&priv->action_mutex); | ||
7494 | if (!(priv->status & STATUS_INITIALIZED)) { | ||
7495 | err = -EIO; | ||
7496 | goto done; | ||
7497 | } | ||
7498 | |||
7499 | if (wrqu->power.disabled) { | ||
7500 | priv->power_mode = IPW_POWER_LEVEL(priv->power_mode); | ||
7501 | err = ipw2100_set_power_mode(priv, IPW_POWER_MODE_CAM); | ||
7502 | IPW_DEBUG_WX("SET Power Management Mode -> off\n"); | ||
7503 | goto done; | ||
7504 | } | ||
7505 | |||
7506 | switch (wrqu->power.flags & IW_POWER_MODE) { | ||
7507 | case IW_POWER_ON: /* If not specified */ | ||
7508 | case IW_POWER_MODE: /* If set all mask */ | ||
7509 | case IW_POWER_ALL_R: /* If explicitly state all */ | ||
7510 | break; | ||
7511 | default: /* Otherwise we don't support it */ | ||
7512 | IPW_DEBUG_WX("SET PM Mode: %X not supported.\n", | ||
7513 | wrqu->power.flags); | ||
7514 | err = -EOPNOTSUPP; | ||
7515 | goto done; | ||
7516 | } | ||
7517 | |||
7518 | /* If the user hasn't specified a power management mode yet, default | ||
7519 | * to BATTERY */ | ||
7520 | priv->power_mode = IPW_POWER_ENABLED | priv->power_mode; | ||
7521 | err = ipw2100_set_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode)); | ||
7522 | |||
7523 | IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode); | ||
7524 | |||
7525 | done: | ||
7526 | mutex_unlock(&priv->action_mutex); | ||
7527 | return err; | ||
7528 | |||
7529 | } | ||
7530 | |||
7531 | static int ipw2100_wx_get_power(struct net_device *dev, | ||
7532 | struct iw_request_info *info, | ||
7533 | union iwreq_data *wrqu, char *extra) | ||
7534 | { | ||
7535 | /* | ||
7536 | * This can be called at any time. No action lock required | ||
7537 | */ | ||
7538 | |||
7539 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
7540 | |||
7541 | if (!(priv->power_mode & IPW_POWER_ENABLED)) | ||
7542 | wrqu->power.disabled = 1; | ||
7543 | else { | ||
7544 | wrqu->power.disabled = 0; | ||
7545 | wrqu->power.flags = 0; | ||
7546 | } | ||
7547 | |||
7548 | IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode); | ||
7549 | |||
7550 | return 0; | ||
7551 | } | ||
7552 | |||
7553 | /* | ||
7554 | * WE-18 WPA support | ||
7555 | */ | ||
7556 | |||
7557 | /* SIOCSIWGENIE */ | ||
7558 | static int ipw2100_wx_set_genie(struct net_device *dev, | ||
7559 | struct iw_request_info *info, | ||
7560 | union iwreq_data *wrqu, char *extra) | ||
7561 | { | ||
7562 | |||
7563 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
7564 | struct ieee80211_device *ieee = priv->ieee; | ||
7565 | u8 *buf; | ||
7566 | |||
7567 | if (!ieee->wpa_enabled) | ||
7568 | return -EOPNOTSUPP; | ||
7569 | |||
7570 | if (wrqu->data.length > MAX_WPA_IE_LEN || | ||
7571 | (wrqu->data.length && extra == NULL)) | ||
7572 | return -EINVAL; | ||
7573 | |||
7574 | if (wrqu->data.length) { | ||
7575 | buf = kmemdup(extra, wrqu->data.length, GFP_KERNEL); | ||
7576 | if (buf == NULL) | ||
7577 | return -ENOMEM; | ||
7578 | |||
7579 | kfree(ieee->wpa_ie); | ||
7580 | ieee->wpa_ie = buf; | ||
7581 | ieee->wpa_ie_len = wrqu->data.length; | ||
7582 | } else { | ||
7583 | kfree(ieee->wpa_ie); | ||
7584 | ieee->wpa_ie = NULL; | ||
7585 | ieee->wpa_ie_len = 0; | ||
7586 | } | ||
7587 | |||
7588 | ipw2100_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len); | ||
7589 | |||
7590 | return 0; | ||
7591 | } | ||
7592 | |||
7593 | /* SIOCGIWGENIE */ | ||
7594 | static int ipw2100_wx_get_genie(struct net_device *dev, | ||
7595 | struct iw_request_info *info, | ||
7596 | union iwreq_data *wrqu, char *extra) | ||
7597 | { | ||
7598 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
7599 | struct ieee80211_device *ieee = priv->ieee; | ||
7600 | |||
7601 | if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) { | ||
7602 | wrqu->data.length = 0; | ||
7603 | return 0; | ||
7604 | } | ||
7605 | |||
7606 | if (wrqu->data.length < ieee->wpa_ie_len) | ||
7607 | return -E2BIG; | ||
7608 | |||
7609 | wrqu->data.length = ieee->wpa_ie_len; | ||
7610 | memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len); | ||
7611 | |||
7612 | return 0; | ||
7613 | } | ||
7614 | |||
7615 | /* SIOCSIWAUTH */ | ||
7616 | static int ipw2100_wx_set_auth(struct net_device *dev, | ||
7617 | struct iw_request_info *info, | ||
7618 | union iwreq_data *wrqu, char *extra) | ||
7619 | { | ||
7620 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
7621 | struct ieee80211_device *ieee = priv->ieee; | ||
7622 | struct iw_param *param = &wrqu->param; | ||
7623 | struct lib80211_crypt_data *crypt; | ||
7624 | unsigned long flags; | ||
7625 | int ret = 0; | ||
7626 | |||
7627 | switch (param->flags & IW_AUTH_INDEX) { | ||
7628 | case IW_AUTH_WPA_VERSION: | ||
7629 | case IW_AUTH_CIPHER_PAIRWISE: | ||
7630 | case IW_AUTH_CIPHER_GROUP: | ||
7631 | case IW_AUTH_KEY_MGMT: | ||
7632 | /* | ||
7633 | * ipw2200 does not use these parameters | ||
7634 | */ | ||
7635 | break; | ||
7636 | |||
7637 | case IW_AUTH_TKIP_COUNTERMEASURES: | ||
7638 | crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx]; | ||
7639 | if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags) | ||
7640 | break; | ||
7641 | |||
7642 | flags = crypt->ops->get_flags(crypt->priv); | ||
7643 | |||
7644 | if (param->value) | ||
7645 | flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES; | ||
7646 | else | ||
7647 | flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES; | ||
7648 | |||
7649 | crypt->ops->set_flags(flags, crypt->priv); | ||
7650 | |||
7651 | break; | ||
7652 | |||
7653 | case IW_AUTH_DROP_UNENCRYPTED:{ | ||
7654 | /* HACK: | ||
7655 | * | ||
7656 | * wpa_supplicant calls set_wpa_enabled when the driver | ||
7657 | * is loaded and unloaded, regardless of if WPA is being | ||
7658 | * used. No other calls are made which can be used to | ||
7659 | * determine if encryption will be used or not prior to | ||
7660 | * association being expected. If encryption is not being | ||
7661 | * used, drop_unencrypted is set to false, else true -- we | ||
7662 | * can use this to determine if the CAP_PRIVACY_ON bit should | ||
7663 | * be set. | ||
7664 | */ | ||
7665 | struct ieee80211_security sec = { | ||
7666 | .flags = SEC_ENABLED, | ||
7667 | .enabled = param->value, | ||
7668 | }; | ||
7669 | priv->ieee->drop_unencrypted = param->value; | ||
7670 | /* We only change SEC_LEVEL for open mode. Others | ||
7671 | * are set by ipw_wpa_set_encryption. | ||
7672 | */ | ||
7673 | if (!param->value) { | ||
7674 | sec.flags |= SEC_LEVEL; | ||
7675 | sec.level = SEC_LEVEL_0; | ||
7676 | } else { | ||
7677 | sec.flags |= SEC_LEVEL; | ||
7678 | sec.level = SEC_LEVEL_1; | ||
7679 | } | ||
7680 | if (priv->ieee->set_security) | ||
7681 | priv->ieee->set_security(priv->ieee->dev, &sec); | ||
7682 | break; | ||
7683 | } | ||
7684 | |||
7685 | case IW_AUTH_80211_AUTH_ALG: | ||
7686 | ret = ipw2100_wpa_set_auth_algs(priv, param->value); | ||
7687 | break; | ||
7688 | |||
7689 | case IW_AUTH_WPA_ENABLED: | ||
7690 | ret = ipw2100_wpa_enable(priv, param->value); | ||
7691 | break; | ||
7692 | |||
7693 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: | ||
7694 | ieee->ieee802_1x = param->value; | ||
7695 | break; | ||
7696 | |||
7697 | //case IW_AUTH_ROAMING_CONTROL: | ||
7698 | case IW_AUTH_PRIVACY_INVOKED: | ||
7699 | ieee->privacy_invoked = param->value; | ||
7700 | break; | ||
7701 | |||
7702 | default: | ||
7703 | return -EOPNOTSUPP; | ||
7704 | } | ||
7705 | return ret; | ||
7706 | } | ||
7707 | |||
7708 | /* SIOCGIWAUTH */ | ||
7709 | static int ipw2100_wx_get_auth(struct net_device *dev, | ||
7710 | struct iw_request_info *info, | ||
7711 | union iwreq_data *wrqu, char *extra) | ||
7712 | { | ||
7713 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
7714 | struct ieee80211_device *ieee = priv->ieee; | ||
7715 | struct lib80211_crypt_data *crypt; | ||
7716 | struct iw_param *param = &wrqu->param; | ||
7717 | int ret = 0; | ||
7718 | |||
7719 | switch (param->flags & IW_AUTH_INDEX) { | ||
7720 | case IW_AUTH_WPA_VERSION: | ||
7721 | case IW_AUTH_CIPHER_PAIRWISE: | ||
7722 | case IW_AUTH_CIPHER_GROUP: | ||
7723 | case IW_AUTH_KEY_MGMT: | ||
7724 | /* | ||
7725 | * wpa_supplicant will control these internally | ||
7726 | */ | ||
7727 | ret = -EOPNOTSUPP; | ||
7728 | break; | ||
7729 | |||
7730 | case IW_AUTH_TKIP_COUNTERMEASURES: | ||
7731 | crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx]; | ||
7732 | if (!crypt || !crypt->ops->get_flags) { | ||
7733 | IPW_DEBUG_WARNING("Can't get TKIP countermeasures: " | ||
7734 | "crypt not set!\n"); | ||
7735 | break; | ||
7736 | } | ||
7737 | |||
7738 | param->value = (crypt->ops->get_flags(crypt->priv) & | ||
7739 | IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0; | ||
7740 | |||
7741 | break; | ||
7742 | |||
7743 | case IW_AUTH_DROP_UNENCRYPTED: | ||
7744 | param->value = ieee->drop_unencrypted; | ||
7745 | break; | ||
7746 | |||
7747 | case IW_AUTH_80211_AUTH_ALG: | ||
7748 | param->value = priv->ieee->sec.auth_mode; | ||
7749 | break; | ||
7750 | |||
7751 | case IW_AUTH_WPA_ENABLED: | ||
7752 | param->value = ieee->wpa_enabled; | ||
7753 | break; | ||
7754 | |||
7755 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: | ||
7756 | param->value = ieee->ieee802_1x; | ||
7757 | break; | ||
7758 | |||
7759 | case IW_AUTH_ROAMING_CONTROL: | ||
7760 | case IW_AUTH_PRIVACY_INVOKED: | ||
7761 | param->value = ieee->privacy_invoked; | ||
7762 | break; | ||
7763 | |||
7764 | default: | ||
7765 | return -EOPNOTSUPP; | ||
7766 | } | ||
7767 | return 0; | ||
7768 | } | ||
7769 | |||
7770 | /* SIOCSIWENCODEEXT */ | ||
7771 | static int ipw2100_wx_set_encodeext(struct net_device *dev, | ||
7772 | struct iw_request_info *info, | ||
7773 | union iwreq_data *wrqu, char *extra) | ||
7774 | { | ||
7775 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
7776 | return ieee80211_wx_set_encodeext(priv->ieee, info, wrqu, extra); | ||
7777 | } | ||
7778 | |||
7779 | /* SIOCGIWENCODEEXT */ | ||
7780 | static int ipw2100_wx_get_encodeext(struct net_device *dev, | ||
7781 | struct iw_request_info *info, | ||
7782 | union iwreq_data *wrqu, char *extra) | ||
7783 | { | ||
7784 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
7785 | return ieee80211_wx_get_encodeext(priv->ieee, info, wrqu, extra); | ||
7786 | } | ||
7787 | |||
7788 | /* SIOCSIWMLME */ | ||
7789 | static int ipw2100_wx_set_mlme(struct net_device *dev, | ||
7790 | struct iw_request_info *info, | ||
7791 | union iwreq_data *wrqu, char *extra) | ||
7792 | { | ||
7793 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
7794 | struct iw_mlme *mlme = (struct iw_mlme *)extra; | ||
7795 | __le16 reason; | ||
7796 | |||
7797 | reason = cpu_to_le16(mlme->reason_code); | ||
7798 | |||
7799 | switch (mlme->cmd) { | ||
7800 | case IW_MLME_DEAUTH: | ||
7801 | // silently ignore | ||
7802 | break; | ||
7803 | |||
7804 | case IW_MLME_DISASSOC: | ||
7805 | ipw2100_disassociate_bssid(priv); | ||
7806 | break; | ||
7807 | |||
7808 | default: | ||
7809 | return -EOPNOTSUPP; | ||
7810 | } | ||
7811 | return 0; | ||
7812 | } | ||
7813 | |||
7814 | /* | ||
7815 | * | ||
7816 | * IWPRIV handlers | ||
7817 | * | ||
7818 | */ | ||
7819 | #ifdef CONFIG_IPW2100_MONITOR | ||
7820 | static int ipw2100_wx_set_promisc(struct net_device *dev, | ||
7821 | struct iw_request_info *info, | ||
7822 | union iwreq_data *wrqu, char *extra) | ||
7823 | { | ||
7824 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
7825 | int *parms = (int *)extra; | ||
7826 | int enable = (parms[0] > 0); | ||
7827 | int err = 0; | ||
7828 | |||
7829 | mutex_lock(&priv->action_mutex); | ||
7830 | if (!(priv->status & STATUS_INITIALIZED)) { | ||
7831 | err = -EIO; | ||
7832 | goto done; | ||
7833 | } | ||
7834 | |||
7835 | if (enable) { | ||
7836 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { | ||
7837 | err = ipw2100_set_channel(priv, parms[1], 0); | ||
7838 | goto done; | ||
7839 | } | ||
7840 | priv->channel = parms[1]; | ||
7841 | err = ipw2100_switch_mode(priv, IW_MODE_MONITOR); | ||
7842 | } else { | ||
7843 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) | ||
7844 | err = ipw2100_switch_mode(priv, priv->last_mode); | ||
7845 | } | ||
7846 | done: | ||
7847 | mutex_unlock(&priv->action_mutex); | ||
7848 | return err; | ||
7849 | } | ||
7850 | |||
7851 | static int ipw2100_wx_reset(struct net_device *dev, | ||
7852 | struct iw_request_info *info, | ||
7853 | union iwreq_data *wrqu, char *extra) | ||
7854 | { | ||
7855 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
7856 | if (priv->status & STATUS_INITIALIZED) | ||
7857 | schedule_reset(priv); | ||
7858 | return 0; | ||
7859 | } | ||
7860 | |||
7861 | #endif | ||
7862 | |||
7863 | static int ipw2100_wx_set_powermode(struct net_device *dev, | ||
7864 | struct iw_request_info *info, | ||
7865 | union iwreq_data *wrqu, char *extra) | ||
7866 | { | ||
7867 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
7868 | int err = 0, mode = *(int *)extra; | ||
7869 | |||
7870 | mutex_lock(&priv->action_mutex); | ||
7871 | if (!(priv->status & STATUS_INITIALIZED)) { | ||
7872 | err = -EIO; | ||
7873 | goto done; | ||
7874 | } | ||
7875 | |||
7876 | if ((mode < 0) || (mode > POWER_MODES)) | ||
7877 | mode = IPW_POWER_AUTO; | ||
7878 | |||
7879 | if (IPW_POWER_LEVEL(priv->power_mode) != mode) | ||
7880 | err = ipw2100_set_power_mode(priv, mode); | ||
7881 | done: | ||
7882 | mutex_unlock(&priv->action_mutex); | ||
7883 | return err; | ||
7884 | } | ||
7885 | |||
7886 | #define MAX_POWER_STRING 80 | ||
7887 | static int ipw2100_wx_get_powermode(struct net_device *dev, | ||
7888 | struct iw_request_info *info, | ||
7889 | union iwreq_data *wrqu, char *extra) | ||
7890 | { | ||
7891 | /* | ||
7892 | * This can be called at any time. No action lock required | ||
7893 | */ | ||
7894 | |||
7895 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
7896 | int level = IPW_POWER_LEVEL(priv->power_mode); | ||
7897 | s32 timeout, period; | ||
7898 | |||
7899 | if (!(priv->power_mode & IPW_POWER_ENABLED)) { | ||
7900 | snprintf(extra, MAX_POWER_STRING, | ||
7901 | "Power save level: %d (Off)", level); | ||
7902 | } else { | ||
7903 | switch (level) { | ||
7904 | case IPW_POWER_MODE_CAM: | ||
7905 | snprintf(extra, MAX_POWER_STRING, | ||
7906 | "Power save level: %d (None)", level); | ||
7907 | break; | ||
7908 | case IPW_POWER_AUTO: | ||
7909 | snprintf(extra, MAX_POWER_STRING, | ||
7910 | "Power save level: %d (Auto)", level); | ||
7911 | break; | ||
7912 | default: | ||
7913 | timeout = timeout_duration[level - 1] / 1000; | ||
7914 | period = period_duration[level - 1] / 1000; | ||
7915 | snprintf(extra, MAX_POWER_STRING, | ||
7916 | "Power save level: %d " | ||
7917 | "(Timeout %dms, Period %dms)", | ||
7918 | level, timeout, period); | ||
7919 | } | ||
7920 | } | ||
7921 | |||
7922 | wrqu->data.length = strlen(extra) + 1; | ||
7923 | |||
7924 | return 0; | ||
7925 | } | ||
7926 | |||
7927 | static int ipw2100_wx_set_preamble(struct net_device *dev, | ||
7928 | struct iw_request_info *info, | ||
7929 | union iwreq_data *wrqu, char *extra) | ||
7930 | { | ||
7931 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
7932 | int err, mode = *(int *)extra; | ||
7933 | |||
7934 | mutex_lock(&priv->action_mutex); | ||
7935 | if (!(priv->status & STATUS_INITIALIZED)) { | ||
7936 | err = -EIO; | ||
7937 | goto done; | ||
7938 | } | ||
7939 | |||
7940 | if (mode == 1) | ||
7941 | priv->config |= CFG_LONG_PREAMBLE; | ||
7942 | else if (mode == 0) | ||
7943 | priv->config &= ~CFG_LONG_PREAMBLE; | ||
7944 | else { | ||
7945 | err = -EINVAL; | ||
7946 | goto done; | ||
7947 | } | ||
7948 | |||
7949 | err = ipw2100_system_config(priv, 0); | ||
7950 | |||
7951 | done: | ||
7952 | mutex_unlock(&priv->action_mutex); | ||
7953 | return err; | ||
7954 | } | ||
7955 | |||
7956 | static int ipw2100_wx_get_preamble(struct net_device *dev, | ||
7957 | struct iw_request_info *info, | ||
7958 | union iwreq_data *wrqu, char *extra) | ||
7959 | { | ||
7960 | /* | ||
7961 | * This can be called at any time. No action lock required | ||
7962 | */ | ||
7963 | |||
7964 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
7965 | |||
7966 | if (priv->config & CFG_LONG_PREAMBLE) | ||
7967 | snprintf(wrqu->name, IFNAMSIZ, "long (1)"); | ||
7968 | else | ||
7969 | snprintf(wrqu->name, IFNAMSIZ, "auto (0)"); | ||
7970 | |||
7971 | return 0; | ||
7972 | } | ||
7973 | |||
7974 | #ifdef CONFIG_IPW2100_MONITOR | ||
7975 | static int ipw2100_wx_set_crc_check(struct net_device *dev, | ||
7976 | struct iw_request_info *info, | ||
7977 | union iwreq_data *wrqu, char *extra) | ||
7978 | { | ||
7979 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
7980 | int err, mode = *(int *)extra; | ||
7981 | |||
7982 | mutex_lock(&priv->action_mutex); | ||
7983 | if (!(priv->status & STATUS_INITIALIZED)) { | ||
7984 | err = -EIO; | ||
7985 | goto done; | ||
7986 | } | ||
7987 | |||
7988 | if (mode == 1) | ||
7989 | priv->config |= CFG_CRC_CHECK; | ||
7990 | else if (mode == 0) | ||
7991 | priv->config &= ~CFG_CRC_CHECK; | ||
7992 | else { | ||
7993 | err = -EINVAL; | ||
7994 | goto done; | ||
7995 | } | ||
7996 | err = 0; | ||
7997 | |||
7998 | done: | ||
7999 | mutex_unlock(&priv->action_mutex); | ||
8000 | return err; | ||
8001 | } | ||
8002 | |||
8003 | static int ipw2100_wx_get_crc_check(struct net_device *dev, | ||
8004 | struct iw_request_info *info, | ||
8005 | union iwreq_data *wrqu, char *extra) | ||
8006 | { | ||
8007 | /* | ||
8008 | * This can be called at any time. No action lock required | ||
8009 | */ | ||
8010 | |||
8011 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
8012 | |||
8013 | if (priv->config & CFG_CRC_CHECK) | ||
8014 | snprintf(wrqu->name, IFNAMSIZ, "CRC checked (1)"); | ||
8015 | else | ||
8016 | snprintf(wrqu->name, IFNAMSIZ, "CRC ignored (0)"); | ||
8017 | |||
8018 | return 0; | ||
8019 | } | ||
8020 | #endif /* CONFIG_IPW2100_MONITOR */ | ||
8021 | |||
8022 | static iw_handler ipw2100_wx_handlers[] = { | ||
8023 | NULL, /* SIOCSIWCOMMIT */ | ||
8024 | ipw2100_wx_get_name, /* SIOCGIWNAME */ | ||
8025 | NULL, /* SIOCSIWNWID */ | ||
8026 | NULL, /* SIOCGIWNWID */ | ||
8027 | ipw2100_wx_set_freq, /* SIOCSIWFREQ */ | ||
8028 | ipw2100_wx_get_freq, /* SIOCGIWFREQ */ | ||
8029 | ipw2100_wx_set_mode, /* SIOCSIWMODE */ | ||
8030 | ipw2100_wx_get_mode, /* SIOCGIWMODE */ | ||
8031 | NULL, /* SIOCSIWSENS */ | ||
8032 | NULL, /* SIOCGIWSENS */ | ||
8033 | NULL, /* SIOCSIWRANGE */ | ||
8034 | ipw2100_wx_get_range, /* SIOCGIWRANGE */ | ||
8035 | NULL, /* SIOCSIWPRIV */ | ||
8036 | NULL, /* SIOCGIWPRIV */ | ||
8037 | NULL, /* SIOCSIWSTATS */ | ||
8038 | NULL, /* SIOCGIWSTATS */ | ||
8039 | NULL, /* SIOCSIWSPY */ | ||
8040 | NULL, /* SIOCGIWSPY */ | ||
8041 | NULL, /* SIOCGIWTHRSPY */ | ||
8042 | NULL, /* SIOCWIWTHRSPY */ | ||
8043 | ipw2100_wx_set_wap, /* SIOCSIWAP */ | ||
8044 | ipw2100_wx_get_wap, /* SIOCGIWAP */ | ||
8045 | ipw2100_wx_set_mlme, /* SIOCSIWMLME */ | ||
8046 | NULL, /* SIOCGIWAPLIST -- deprecated */ | ||
8047 | ipw2100_wx_set_scan, /* SIOCSIWSCAN */ | ||
8048 | ipw2100_wx_get_scan, /* SIOCGIWSCAN */ | ||
8049 | ipw2100_wx_set_essid, /* SIOCSIWESSID */ | ||
8050 | ipw2100_wx_get_essid, /* SIOCGIWESSID */ | ||
8051 | ipw2100_wx_set_nick, /* SIOCSIWNICKN */ | ||
8052 | ipw2100_wx_get_nick, /* SIOCGIWNICKN */ | ||
8053 | NULL, /* -- hole -- */ | ||
8054 | NULL, /* -- hole -- */ | ||
8055 | ipw2100_wx_set_rate, /* SIOCSIWRATE */ | ||
8056 | ipw2100_wx_get_rate, /* SIOCGIWRATE */ | ||
8057 | ipw2100_wx_set_rts, /* SIOCSIWRTS */ | ||
8058 | ipw2100_wx_get_rts, /* SIOCGIWRTS */ | ||
8059 | ipw2100_wx_set_frag, /* SIOCSIWFRAG */ | ||
8060 | ipw2100_wx_get_frag, /* SIOCGIWFRAG */ | ||
8061 | ipw2100_wx_set_txpow, /* SIOCSIWTXPOW */ | ||
8062 | ipw2100_wx_get_txpow, /* SIOCGIWTXPOW */ | ||
8063 | ipw2100_wx_set_retry, /* SIOCSIWRETRY */ | ||
8064 | ipw2100_wx_get_retry, /* SIOCGIWRETRY */ | ||
8065 | ipw2100_wx_set_encode, /* SIOCSIWENCODE */ | ||
8066 | ipw2100_wx_get_encode, /* SIOCGIWENCODE */ | ||
8067 | ipw2100_wx_set_power, /* SIOCSIWPOWER */ | ||
8068 | ipw2100_wx_get_power, /* SIOCGIWPOWER */ | ||
8069 | NULL, /* -- hole -- */ | ||
8070 | NULL, /* -- hole -- */ | ||
8071 | ipw2100_wx_set_genie, /* SIOCSIWGENIE */ | ||
8072 | ipw2100_wx_get_genie, /* SIOCGIWGENIE */ | ||
8073 | ipw2100_wx_set_auth, /* SIOCSIWAUTH */ | ||
8074 | ipw2100_wx_get_auth, /* SIOCGIWAUTH */ | ||
8075 | ipw2100_wx_set_encodeext, /* SIOCSIWENCODEEXT */ | ||
8076 | ipw2100_wx_get_encodeext, /* SIOCGIWENCODEEXT */ | ||
8077 | NULL, /* SIOCSIWPMKSA */ | ||
8078 | }; | ||
8079 | |||
8080 | #define IPW2100_PRIV_SET_MONITOR SIOCIWFIRSTPRIV | ||
8081 | #define IPW2100_PRIV_RESET SIOCIWFIRSTPRIV+1 | ||
8082 | #define IPW2100_PRIV_SET_POWER SIOCIWFIRSTPRIV+2 | ||
8083 | #define IPW2100_PRIV_GET_POWER SIOCIWFIRSTPRIV+3 | ||
8084 | #define IPW2100_PRIV_SET_LONGPREAMBLE SIOCIWFIRSTPRIV+4 | ||
8085 | #define IPW2100_PRIV_GET_LONGPREAMBLE SIOCIWFIRSTPRIV+5 | ||
8086 | #define IPW2100_PRIV_SET_CRC_CHECK SIOCIWFIRSTPRIV+6 | ||
8087 | #define IPW2100_PRIV_GET_CRC_CHECK SIOCIWFIRSTPRIV+7 | ||
8088 | |||
8089 | static const struct iw_priv_args ipw2100_private_args[] = { | ||
8090 | |||
8091 | #ifdef CONFIG_IPW2100_MONITOR | ||
8092 | { | ||
8093 | IPW2100_PRIV_SET_MONITOR, | ||
8094 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"}, | ||
8095 | { | ||
8096 | IPW2100_PRIV_RESET, | ||
8097 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"}, | ||
8098 | #endif /* CONFIG_IPW2100_MONITOR */ | ||
8099 | |||
8100 | { | ||
8101 | IPW2100_PRIV_SET_POWER, | ||
8102 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_power"}, | ||
8103 | { | ||
8104 | IPW2100_PRIV_GET_POWER, | ||
8105 | 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_POWER_STRING, | ||
8106 | "get_power"}, | ||
8107 | { | ||
8108 | IPW2100_PRIV_SET_LONGPREAMBLE, | ||
8109 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_preamble"}, | ||
8110 | { | ||
8111 | IPW2100_PRIV_GET_LONGPREAMBLE, | ||
8112 | 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, "get_preamble"}, | ||
8113 | #ifdef CONFIG_IPW2100_MONITOR | ||
8114 | { | ||
8115 | IPW2100_PRIV_SET_CRC_CHECK, | ||
8116 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_crc_check"}, | ||
8117 | { | ||
8118 | IPW2100_PRIV_GET_CRC_CHECK, | ||
8119 | 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, "get_crc_check"}, | ||
8120 | #endif /* CONFIG_IPW2100_MONITOR */ | ||
8121 | }; | ||
8122 | |||
8123 | static iw_handler ipw2100_private_handler[] = { | ||
8124 | #ifdef CONFIG_IPW2100_MONITOR | ||
8125 | ipw2100_wx_set_promisc, | ||
8126 | ipw2100_wx_reset, | ||
8127 | #else /* CONFIG_IPW2100_MONITOR */ | ||
8128 | NULL, | ||
8129 | NULL, | ||
8130 | #endif /* CONFIG_IPW2100_MONITOR */ | ||
8131 | ipw2100_wx_set_powermode, | ||
8132 | ipw2100_wx_get_powermode, | ||
8133 | ipw2100_wx_set_preamble, | ||
8134 | ipw2100_wx_get_preamble, | ||
8135 | #ifdef CONFIG_IPW2100_MONITOR | ||
8136 | ipw2100_wx_set_crc_check, | ||
8137 | ipw2100_wx_get_crc_check, | ||
8138 | #else /* CONFIG_IPW2100_MONITOR */ | ||
8139 | NULL, | ||
8140 | NULL, | ||
8141 | #endif /* CONFIG_IPW2100_MONITOR */ | ||
8142 | }; | ||
8143 | |||
8144 | /* | ||
8145 | * Get wireless statistics. | ||
8146 | * Called by /proc/net/wireless | ||
8147 | * Also called by SIOCGIWSTATS | ||
8148 | */ | ||
8149 | static struct iw_statistics *ipw2100_wx_wireless_stats(struct net_device *dev) | ||
8150 | { | ||
8151 | enum { | ||
8152 | POOR = 30, | ||
8153 | FAIR = 60, | ||
8154 | GOOD = 80, | ||
8155 | VERY_GOOD = 90, | ||
8156 | EXCELLENT = 95, | ||
8157 | PERFECT = 100 | ||
8158 | }; | ||
8159 | int rssi_qual; | ||
8160 | int tx_qual; | ||
8161 | int beacon_qual; | ||
8162 | |||
8163 | struct ipw2100_priv *priv = ieee80211_priv(dev); | ||
8164 | struct iw_statistics *wstats; | ||
8165 | u32 rssi, quality, tx_retries, missed_beacons, tx_failures; | ||
8166 | u32 ord_len = sizeof(u32); | ||
8167 | |||
8168 | if (!priv) | ||
8169 | return (struct iw_statistics *)NULL; | ||
8170 | |||
8171 | wstats = &priv->wstats; | ||
8172 | |||
8173 | /* if hw is disabled, then ipw2100_get_ordinal() can't be called. | ||
8174 | * ipw2100_wx_wireless_stats seems to be called before fw is | ||
8175 | * initialized. STATUS_ASSOCIATED will only be set if the hw is up | ||
8176 | * and associated; if not associcated, the values are all meaningless | ||
8177 | * anyway, so set them all to NULL and INVALID */ | ||
8178 | if (!(priv->status & STATUS_ASSOCIATED)) { | ||
8179 | wstats->miss.beacon = 0; | ||
8180 | wstats->discard.retries = 0; | ||
8181 | wstats->qual.qual = 0; | ||
8182 | wstats->qual.level = 0; | ||
8183 | wstats->qual.noise = 0; | ||
8184 | wstats->qual.updated = 7; | ||
8185 | wstats->qual.updated |= IW_QUAL_NOISE_INVALID | | ||
8186 | IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID; | ||
8187 | return wstats; | ||
8188 | } | ||
8189 | |||
8190 | if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_PERCENT_MISSED_BCNS, | ||
8191 | &missed_beacons, &ord_len)) | ||
8192 | goto fail_get_ordinal; | ||
8193 | |||
8194 | /* If we don't have a connection the quality and level is 0 */ | ||
8195 | if (!(priv->status & STATUS_ASSOCIATED)) { | ||
8196 | wstats->qual.qual = 0; | ||
8197 | wstats->qual.level = 0; | ||
8198 | } else { | ||
8199 | if (ipw2100_get_ordinal(priv, IPW_ORD_RSSI_AVG_CURR, | ||
8200 | &rssi, &ord_len)) | ||
8201 | goto fail_get_ordinal; | ||
8202 | wstats->qual.level = rssi + IPW2100_RSSI_TO_DBM; | ||
8203 | if (rssi < 10) | ||
8204 | rssi_qual = rssi * POOR / 10; | ||
8205 | else if (rssi < 15) | ||
8206 | rssi_qual = (rssi - 10) * (FAIR - POOR) / 5 + POOR; | ||
8207 | else if (rssi < 20) | ||
8208 | rssi_qual = (rssi - 15) * (GOOD - FAIR) / 5 + FAIR; | ||
8209 | else if (rssi < 30) | ||
8210 | rssi_qual = (rssi - 20) * (VERY_GOOD - GOOD) / | ||
8211 | 10 + GOOD; | ||
8212 | else | ||
8213 | rssi_qual = (rssi - 30) * (PERFECT - VERY_GOOD) / | ||
8214 | 10 + VERY_GOOD; | ||
8215 | |||
8216 | if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_PERCENT_RETRIES, | ||
8217 | &tx_retries, &ord_len)) | ||
8218 | goto fail_get_ordinal; | ||
8219 | |||
8220 | if (tx_retries > 75) | ||
8221 | tx_qual = (90 - tx_retries) * POOR / 15; | ||
8222 | else if (tx_retries > 70) | ||
8223 | tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR; | ||
8224 | else if (tx_retries > 65) | ||
8225 | tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR; | ||
8226 | else if (tx_retries > 50) | ||
8227 | tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) / | ||
8228 | 15 + GOOD; | ||
8229 | else | ||
8230 | tx_qual = (50 - tx_retries) * | ||
8231 | (PERFECT - VERY_GOOD) / 50 + VERY_GOOD; | ||
8232 | |||
8233 | if (missed_beacons > 50) | ||
8234 | beacon_qual = (60 - missed_beacons) * POOR / 10; | ||
8235 | else if (missed_beacons > 40) | ||
8236 | beacon_qual = (50 - missed_beacons) * (FAIR - POOR) / | ||
8237 | 10 + POOR; | ||
8238 | else if (missed_beacons > 32) | ||
8239 | beacon_qual = (40 - missed_beacons) * (GOOD - FAIR) / | ||
8240 | 18 + FAIR; | ||
8241 | else if (missed_beacons > 20) | ||
8242 | beacon_qual = (32 - missed_beacons) * | ||
8243 | (VERY_GOOD - GOOD) / 20 + GOOD; | ||
8244 | else | ||
8245 | beacon_qual = (20 - missed_beacons) * | ||
8246 | (PERFECT - VERY_GOOD) / 20 + VERY_GOOD; | ||
8247 | |||
8248 | quality = min(beacon_qual, min(tx_qual, rssi_qual)); | ||
8249 | |||
8250 | #ifdef CONFIG_IPW2100_DEBUG | ||
8251 | if (beacon_qual == quality) | ||
8252 | IPW_DEBUG_WX("Quality clamped by Missed Beacons\n"); | ||
8253 | else if (tx_qual == quality) | ||
8254 | IPW_DEBUG_WX("Quality clamped by Tx Retries\n"); | ||
8255 | else if (quality != 100) | ||
8256 | IPW_DEBUG_WX("Quality clamped by Signal Strength\n"); | ||
8257 | else | ||
8258 | IPW_DEBUG_WX("Quality not clamped.\n"); | ||
8259 | #endif | ||
8260 | |||
8261 | wstats->qual.qual = quality; | ||
8262 | wstats->qual.level = rssi + IPW2100_RSSI_TO_DBM; | ||
8263 | } | ||
8264 | |||
8265 | wstats->qual.noise = 0; | ||
8266 | wstats->qual.updated = 7; | ||
8267 | wstats->qual.updated |= IW_QUAL_NOISE_INVALID; | ||
8268 | |||
8269 | /* FIXME: this is percent and not a # */ | ||
8270 | wstats->miss.beacon = missed_beacons; | ||
8271 | |||
8272 | if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURES, | ||
8273 | &tx_failures, &ord_len)) | ||
8274 | goto fail_get_ordinal; | ||
8275 | wstats->discard.retries = tx_failures; | ||
8276 | |||
8277 | return wstats; | ||
8278 | |||
8279 | fail_get_ordinal: | ||
8280 | IPW_DEBUG_WX("failed querying ordinals.\n"); | ||
8281 | |||
8282 | return (struct iw_statistics *)NULL; | ||
8283 | } | ||
8284 | |||
8285 | static struct iw_handler_def ipw2100_wx_handler_def = { | ||
8286 | .standard = ipw2100_wx_handlers, | ||
8287 | .num_standard = ARRAY_SIZE(ipw2100_wx_handlers), | ||
8288 | .num_private = ARRAY_SIZE(ipw2100_private_handler), | ||
8289 | .num_private_args = ARRAY_SIZE(ipw2100_private_args), | ||
8290 | .private = (iw_handler *) ipw2100_private_handler, | ||
8291 | .private_args = (struct iw_priv_args *)ipw2100_private_args, | ||
8292 | .get_wireless_stats = ipw2100_wx_wireless_stats, | ||
8293 | }; | ||
8294 | |||
8295 | static void ipw2100_wx_event_work(struct work_struct *work) | ||
8296 | { | ||
8297 | struct ipw2100_priv *priv = | ||
8298 | container_of(work, struct ipw2100_priv, wx_event_work.work); | ||
8299 | union iwreq_data wrqu; | ||
8300 | int len = ETH_ALEN; | ||
8301 | |||
8302 | if (priv->status & STATUS_STOPPING) | ||
8303 | return; | ||
8304 | |||
8305 | mutex_lock(&priv->action_mutex); | ||
8306 | |||
8307 | IPW_DEBUG_WX("enter\n"); | ||
8308 | |||
8309 | mutex_unlock(&priv->action_mutex); | ||
8310 | |||
8311 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; | ||
8312 | |||
8313 | /* Fetch BSSID from the hardware */ | ||
8314 | if (!(priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) || | ||
8315 | priv->status & STATUS_RF_KILL_MASK || | ||
8316 | ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID, | ||
8317 | &priv->bssid, &len)) { | ||
8318 | memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN); | ||
8319 | } else { | ||
8320 | /* We now have the BSSID, so can finish setting to the full | ||
8321 | * associated state */ | ||
8322 | memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN); | ||
8323 | memcpy(priv->ieee->bssid, priv->bssid, ETH_ALEN); | ||
8324 | priv->status &= ~STATUS_ASSOCIATING; | ||
8325 | priv->status |= STATUS_ASSOCIATED; | ||
8326 | netif_carrier_on(priv->net_dev); | ||
8327 | netif_wake_queue(priv->net_dev); | ||
8328 | } | ||
8329 | |||
8330 | if (!(priv->status & STATUS_ASSOCIATED)) { | ||
8331 | IPW_DEBUG_WX("Configuring ESSID\n"); | ||
8332 | mutex_lock(&priv->action_mutex); | ||
8333 | /* This is a disassociation event, so kick the firmware to | ||
8334 | * look for another AP */ | ||
8335 | if (priv->config & CFG_STATIC_ESSID) | ||
8336 | ipw2100_set_essid(priv, priv->essid, priv->essid_len, | ||
8337 | 0); | ||
8338 | else | ||
8339 | ipw2100_set_essid(priv, NULL, 0, 0); | ||
8340 | mutex_unlock(&priv->action_mutex); | ||
8341 | } | ||
8342 | |||
8343 | wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL); | ||
8344 | } | ||
8345 | |||
8346 | #define IPW2100_FW_MAJOR_VERSION 1 | ||
8347 | #define IPW2100_FW_MINOR_VERSION 3 | ||
8348 | |||
8349 | #define IPW2100_FW_MINOR(x) ((x & 0xff) >> 8) | ||
8350 | #define IPW2100_FW_MAJOR(x) (x & 0xff) | ||
8351 | |||
8352 | #define IPW2100_FW_VERSION ((IPW2100_FW_MINOR_VERSION << 8) | \ | ||
8353 | IPW2100_FW_MAJOR_VERSION) | ||
8354 | |||
8355 | #define IPW2100_FW_PREFIX "ipw2100-" __stringify(IPW2100_FW_MAJOR_VERSION) \ | ||
8356 | "." __stringify(IPW2100_FW_MINOR_VERSION) | ||
8357 | |||
8358 | #define IPW2100_FW_NAME(x) IPW2100_FW_PREFIX "" x ".fw" | ||
8359 | |||
8360 | /* | ||
8361 | |||
8362 | BINARY FIRMWARE HEADER FORMAT | ||
8363 | |||
8364 | offset length desc | ||
8365 | 0 2 version | ||
8366 | 2 2 mode == 0:BSS,1:IBSS,2:MONITOR | ||
8367 | 4 4 fw_len | ||
8368 | 8 4 uc_len | ||
8369 | C fw_len firmware data | ||
8370 | 12 + fw_len uc_len microcode data | ||
8371 | |||
8372 | */ | ||
8373 | |||
8374 | struct ipw2100_fw_header { | ||
8375 | short version; | ||
8376 | short mode; | ||
8377 | unsigned int fw_size; | ||
8378 | unsigned int uc_size; | ||
8379 | } __attribute__ ((packed)); | ||
8380 | |||
8381 | static int ipw2100_mod_firmware_load(struct ipw2100_fw *fw) | ||
8382 | { | ||
8383 | struct ipw2100_fw_header *h = | ||
8384 | (struct ipw2100_fw_header *)fw->fw_entry->data; | ||
8385 | |||
8386 | if (IPW2100_FW_MAJOR(h->version) != IPW2100_FW_MAJOR_VERSION) { | ||
8387 | printk(KERN_WARNING DRV_NAME ": Firmware image not compatible " | ||
8388 | "(detected version id of %u). " | ||
8389 | "See Documentation/networking/README.ipw2100\n", | ||
8390 | h->version); | ||
8391 | return 1; | ||
8392 | } | ||
8393 | |||
8394 | fw->version = h->version; | ||
8395 | fw->fw.data = fw->fw_entry->data + sizeof(struct ipw2100_fw_header); | ||
8396 | fw->fw.size = h->fw_size; | ||
8397 | fw->uc.data = fw->fw.data + h->fw_size; | ||
8398 | fw->uc.size = h->uc_size; | ||
8399 | |||
8400 | return 0; | ||
8401 | } | ||
8402 | |||
8403 | static int ipw2100_get_firmware(struct ipw2100_priv *priv, | ||
8404 | struct ipw2100_fw *fw) | ||
8405 | { | ||
8406 | char *fw_name; | ||
8407 | int rc; | ||
8408 | |||
8409 | IPW_DEBUG_INFO("%s: Using hotplug firmware load.\n", | ||
8410 | priv->net_dev->name); | ||
8411 | |||
8412 | switch (priv->ieee->iw_mode) { | ||
8413 | case IW_MODE_ADHOC: | ||
8414 | fw_name = IPW2100_FW_NAME("-i"); | ||
8415 | break; | ||
8416 | #ifdef CONFIG_IPW2100_MONITOR | ||
8417 | case IW_MODE_MONITOR: | ||
8418 | fw_name = IPW2100_FW_NAME("-p"); | ||
8419 | break; | ||
8420 | #endif | ||
8421 | case IW_MODE_INFRA: | ||
8422 | default: | ||
8423 | fw_name = IPW2100_FW_NAME(""); | ||
8424 | break; | ||
8425 | } | ||
8426 | |||
8427 | rc = request_firmware(&fw->fw_entry, fw_name, &priv->pci_dev->dev); | ||
8428 | |||
8429 | if (rc < 0) { | ||
8430 | printk(KERN_ERR DRV_NAME ": " | ||
8431 | "%s: Firmware '%s' not available or load failed.\n", | ||
8432 | priv->net_dev->name, fw_name); | ||
8433 | return rc; | ||
8434 | } | ||
8435 | IPW_DEBUG_INFO("firmware data %p size %zd\n", fw->fw_entry->data, | ||
8436 | fw->fw_entry->size); | ||
8437 | |||
8438 | ipw2100_mod_firmware_load(fw); | ||
8439 | |||
8440 | return 0; | ||
8441 | } | ||
8442 | |||
8443 | static void ipw2100_release_firmware(struct ipw2100_priv *priv, | ||
8444 | struct ipw2100_fw *fw) | ||
8445 | { | ||
8446 | fw->version = 0; | ||
8447 | if (fw->fw_entry) | ||
8448 | release_firmware(fw->fw_entry); | ||
8449 | fw->fw_entry = NULL; | ||
8450 | } | ||
8451 | |||
8452 | static int ipw2100_get_fwversion(struct ipw2100_priv *priv, char *buf, | ||
8453 | size_t max) | ||
8454 | { | ||
8455 | char ver[MAX_FW_VERSION_LEN]; | ||
8456 | u32 len = MAX_FW_VERSION_LEN; | ||
8457 | u32 tmp; | ||
8458 | int i; | ||
8459 | /* firmware version is an ascii string (max len of 14) */ | ||
8460 | if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_FW_VER_NUM, ver, &len)) | ||
8461 | return -EIO; | ||
8462 | tmp = max; | ||
8463 | if (len >= max) | ||
8464 | len = max - 1; | ||
8465 | for (i = 0; i < len; i++) | ||
8466 | buf[i] = ver[i]; | ||
8467 | buf[i] = '\0'; | ||
8468 | return tmp; | ||
8469 | } | ||
8470 | |||
8471 | static int ipw2100_get_ucodeversion(struct ipw2100_priv *priv, char *buf, | ||
8472 | size_t max) | ||
8473 | { | ||
8474 | u32 ver; | ||
8475 | u32 len = sizeof(ver); | ||
8476 | /* microcode version is a 32 bit integer */ | ||
8477 | if (ipw2100_get_ordinal(priv, IPW_ORD_UCODE_VERSION, &ver, &len)) | ||
8478 | return -EIO; | ||
8479 | return snprintf(buf, max, "%08X", ver); | ||
8480 | } | ||
8481 | |||
8482 | /* | ||
8483 | * On exit, the firmware will have been freed from the fw list | ||
8484 | */ | ||
8485 | static int ipw2100_fw_download(struct ipw2100_priv *priv, struct ipw2100_fw *fw) | ||
8486 | { | ||
8487 | /* firmware is constructed of N contiguous entries, each entry is | ||
8488 | * structured as: | ||
8489 | * | ||
8490 | * offset sie desc | ||
8491 | * 0 4 address to write to | ||
8492 | * 4 2 length of data run | ||
8493 | * 6 length data | ||
8494 | */ | ||
8495 | unsigned int addr; | ||
8496 | unsigned short len; | ||
8497 | |||
8498 | const unsigned char *firmware_data = fw->fw.data; | ||
8499 | unsigned int firmware_data_left = fw->fw.size; | ||
8500 | |||
8501 | while (firmware_data_left > 0) { | ||
8502 | addr = *(u32 *) (firmware_data); | ||
8503 | firmware_data += 4; | ||
8504 | firmware_data_left -= 4; | ||
8505 | |||
8506 | len = *(u16 *) (firmware_data); | ||
8507 | firmware_data += 2; | ||
8508 | firmware_data_left -= 2; | ||
8509 | |||
8510 | if (len > 32) { | ||
8511 | printk(KERN_ERR DRV_NAME ": " | ||
8512 | "Invalid firmware run-length of %d bytes\n", | ||
8513 | len); | ||
8514 | return -EINVAL; | ||
8515 | } | ||
8516 | |||
8517 | write_nic_memory(priv->net_dev, addr, len, firmware_data); | ||
8518 | firmware_data += len; | ||
8519 | firmware_data_left -= len; | ||
8520 | } | ||
8521 | |||
8522 | return 0; | ||
8523 | } | ||
8524 | |||
8525 | struct symbol_alive_response { | ||
8526 | u8 cmd_id; | ||
8527 | u8 seq_num; | ||
8528 | u8 ucode_rev; | ||
8529 | u8 eeprom_valid; | ||
8530 | u16 valid_flags; | ||
8531 | u8 IEEE_addr[6]; | ||
8532 | u16 flags; | ||
8533 | u16 pcb_rev; | ||
8534 | u16 clock_settle_time; // 1us LSB | ||
8535 | u16 powerup_settle_time; // 1us LSB | ||
8536 | u16 hop_settle_time; // 1us LSB | ||
8537 | u8 date[3]; // month, day, year | ||
8538 | u8 time[2]; // hours, minutes | ||
8539 | u8 ucode_valid; | ||
8540 | }; | ||
8541 | |||
8542 | static int ipw2100_ucode_download(struct ipw2100_priv *priv, | ||
8543 | struct ipw2100_fw *fw) | ||
8544 | { | ||
8545 | struct net_device *dev = priv->net_dev; | ||
8546 | const unsigned char *microcode_data = fw->uc.data; | ||
8547 | unsigned int microcode_data_left = fw->uc.size; | ||
8548 | void __iomem *reg = (void __iomem *)dev->base_addr; | ||
8549 | |||
8550 | struct symbol_alive_response response; | ||
8551 | int i, j; | ||
8552 | u8 data; | ||
8553 | |||
8554 | /* Symbol control */ | ||
8555 | write_nic_word(dev, IPW2100_CONTROL_REG, 0x703); | ||
8556 | readl(reg); | ||
8557 | write_nic_word(dev, IPW2100_CONTROL_REG, 0x707); | ||
8558 | readl(reg); | ||
8559 | |||
8560 | /* HW config */ | ||
8561 | write_nic_byte(dev, 0x210014, 0x72); /* fifo width =16 */ | ||
8562 | readl(reg); | ||
8563 | write_nic_byte(dev, 0x210014, 0x72); /* fifo width =16 */ | ||
8564 | readl(reg); | ||
8565 | |||
8566 | /* EN_CS_ACCESS bit to reset control store pointer */ | ||
8567 | write_nic_byte(dev, 0x210000, 0x40); | ||
8568 | readl(reg); | ||
8569 | write_nic_byte(dev, 0x210000, 0x0); | ||
8570 | readl(reg); | ||
8571 | write_nic_byte(dev, 0x210000, 0x40); | ||
8572 | readl(reg); | ||
8573 | |||
8574 | /* copy microcode from buffer into Symbol */ | ||
8575 | |||
8576 | while (microcode_data_left > 0) { | ||
8577 | write_nic_byte(dev, 0x210010, *microcode_data++); | ||
8578 | write_nic_byte(dev, 0x210010, *microcode_data++); | ||
8579 | microcode_data_left -= 2; | ||
8580 | } | ||
8581 | |||
8582 | /* EN_CS_ACCESS bit to reset the control store pointer */ | ||
8583 | write_nic_byte(dev, 0x210000, 0x0); | ||
8584 | readl(reg); | ||
8585 | |||
8586 | /* Enable System (Reg 0) | ||
8587 | * first enable causes garbage in RX FIFO */ | ||
8588 | write_nic_byte(dev, 0x210000, 0x0); | ||
8589 | readl(reg); | ||
8590 | write_nic_byte(dev, 0x210000, 0x80); | ||
8591 | readl(reg); | ||
8592 | |||
8593 | /* Reset External Baseband Reg */ | ||
8594 | write_nic_word(dev, IPW2100_CONTROL_REG, 0x703); | ||
8595 | readl(reg); | ||
8596 | write_nic_word(dev, IPW2100_CONTROL_REG, 0x707); | ||
8597 | readl(reg); | ||
8598 | |||
8599 | /* HW Config (Reg 5) */ | ||
8600 | write_nic_byte(dev, 0x210014, 0x72); // fifo width =16 | ||
8601 | readl(reg); | ||
8602 | write_nic_byte(dev, 0x210014, 0x72); // fifo width =16 | ||
8603 | readl(reg); | ||
8604 | |||
8605 | /* Enable System (Reg 0) | ||
8606 | * second enable should be OK */ | ||
8607 | write_nic_byte(dev, 0x210000, 0x00); // clear enable system | ||
8608 | readl(reg); | ||
8609 | write_nic_byte(dev, 0x210000, 0x80); // set enable system | ||
8610 | |||
8611 | /* check Symbol is enabled - upped this from 5 as it wasn't always | ||
8612 | * catching the update */ | ||
8613 | for (i = 0; i < 10; i++) { | ||
8614 | udelay(10); | ||
8615 | |||
8616 | /* check Dino is enabled bit */ | ||
8617 | read_nic_byte(dev, 0x210000, &data); | ||
8618 | if (data & 0x1) | ||
8619 | break; | ||
8620 | } | ||
8621 | |||
8622 | if (i == 10) { | ||
8623 | printk(KERN_ERR DRV_NAME ": %s: Error initializing Symbol\n", | ||
8624 | dev->name); | ||
8625 | return -EIO; | ||
8626 | } | ||
8627 | |||
8628 | /* Get Symbol alive response */ | ||
8629 | for (i = 0; i < 30; i++) { | ||
8630 | /* Read alive response structure */ | ||
8631 | for (j = 0; | ||
8632 | j < (sizeof(struct symbol_alive_response) >> 1); j++) | ||
8633 | read_nic_word(dev, 0x210004, ((u16 *) & response) + j); | ||
8634 | |||
8635 | if ((response.cmd_id == 1) && (response.ucode_valid == 0x1)) | ||
8636 | break; | ||
8637 | udelay(10); | ||
8638 | } | ||
8639 | |||
8640 | if (i == 30) { | ||
8641 | printk(KERN_ERR DRV_NAME | ||
8642 | ": %s: No response from Symbol - hw not alive\n", | ||
8643 | dev->name); | ||
8644 | printk_buf(IPW_DL_ERROR, (u8 *) & response, sizeof(response)); | ||
8645 | return -EIO; | ||
8646 | } | ||
8647 | |||
8648 | return 0; | ||
8649 | } | ||
diff --git a/drivers/net/wireless/ipw2x00/ipw2100.h b/drivers/net/wireless/ipw2x00/ipw2100.h new file mode 100644 index 000000000000..bbf1ddcafba8 --- /dev/null +++ b/drivers/net/wireless/ipw2x00/ipw2100.h | |||
@@ -0,0 +1,1162 @@ | |||
1 | /****************************************************************************** | ||
2 | |||
3 | Copyright(c) 2003 - 2006 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., 59 | ||
16 | Temple Place - Suite 330, Boston, MA 02111-1307, 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 | James P. Ketrenos <ipw2100-admin@linux.intel.com> | ||
23 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
24 | |||
25 | ******************************************************************************/ | ||
26 | #ifndef _IPW2100_H | ||
27 | #define _IPW2100_H | ||
28 | |||
29 | #include <linux/sched.h> | ||
30 | #include <linux/interrupt.h> | ||
31 | #include <linux/netdevice.h> | ||
32 | #include <linux/etherdevice.h> | ||
33 | #include <linux/list.h> | ||
34 | #include <linux/delay.h> | ||
35 | #include <linux/skbuff.h> | ||
36 | #include <asm/io.h> | ||
37 | #include <linux/socket.h> | ||
38 | #include <linux/if_arp.h> | ||
39 | #include <linux/wireless.h> | ||
40 | #include <net/iw_handler.h> // new driver API | ||
41 | |||
42 | #include <net/ieee80211.h> | ||
43 | |||
44 | #ifdef CONFIG_IPW2100_MONITOR | ||
45 | #include <net/ieee80211_radiotap.h> | ||
46 | #endif | ||
47 | |||
48 | #include <linux/workqueue.h> | ||
49 | #include <linux/mutex.h> | ||
50 | |||
51 | struct ipw2100_priv; | ||
52 | struct ipw2100_tx_packet; | ||
53 | struct ipw2100_rx_packet; | ||
54 | |||
55 | #define IPW_DL_UNINIT 0x80000000 | ||
56 | #define IPW_DL_NONE 0x00000000 | ||
57 | #define IPW_DL_ALL 0x7FFFFFFF | ||
58 | |||
59 | /* | ||
60 | * To use the debug system; | ||
61 | * | ||
62 | * If you are defining a new debug classification, simply add it to the #define | ||
63 | * list here in the form of: | ||
64 | * | ||
65 | * #define IPW_DL_xxxx VALUE | ||
66 | * | ||
67 | * shifting value to the left one bit from the previous entry. xxxx should be | ||
68 | * the name of the classification (for example, WEP) | ||
69 | * | ||
70 | * You then need to either add a IPW2100_xxxx_DEBUG() macro definition for your | ||
71 | * classification, or use IPW_DEBUG(IPW_DL_xxxx, ...) whenever you want | ||
72 | * to send output to that classification. | ||
73 | * | ||
74 | * To add your debug level to the list of levels seen when you perform | ||
75 | * | ||
76 | * % cat /proc/net/ipw2100/debug_level | ||
77 | * | ||
78 | * you simply need to add your entry to the ipw2100_debug_levels array. | ||
79 | * | ||
80 | * If you do not see debug_level in /proc/net/ipw2100 then you do not have | ||
81 | * CONFIG_IPW2100_DEBUG defined in your kernel configuration | ||
82 | * | ||
83 | */ | ||
84 | |||
85 | #define IPW_DL_ERROR (1<<0) | ||
86 | #define IPW_DL_WARNING (1<<1) | ||
87 | #define IPW_DL_INFO (1<<2) | ||
88 | #define IPW_DL_WX (1<<3) | ||
89 | #define IPW_DL_HC (1<<5) | ||
90 | #define IPW_DL_STATE (1<<6) | ||
91 | |||
92 | #define IPW_DL_NOTIF (1<<10) | ||
93 | #define IPW_DL_SCAN (1<<11) | ||
94 | #define IPW_DL_ASSOC (1<<12) | ||
95 | #define IPW_DL_DROP (1<<13) | ||
96 | |||
97 | #define IPW_DL_IOCTL (1<<14) | ||
98 | #define IPW_DL_RF_KILL (1<<17) | ||
99 | |||
100 | #define IPW_DL_MANAGE (1<<15) | ||
101 | #define IPW_DL_FW (1<<16) | ||
102 | |||
103 | #define IPW_DL_FRAG (1<<21) | ||
104 | #define IPW_DL_WEP (1<<22) | ||
105 | #define IPW_DL_TX (1<<23) | ||
106 | #define IPW_DL_RX (1<<24) | ||
107 | #define IPW_DL_ISR (1<<25) | ||
108 | #define IPW_DL_IO (1<<26) | ||
109 | #define IPW_DL_TRACE (1<<28) | ||
110 | |||
111 | #define IPW_DEBUG_ERROR(f, a...) printk(KERN_ERR DRV_NAME ": " f, ## a) | ||
112 | #define IPW_DEBUG_WARNING(f, a...) printk(KERN_WARNING DRV_NAME ": " f, ## a) | ||
113 | #define IPW_DEBUG_INFO(f...) IPW_DEBUG(IPW_DL_INFO, ## f) | ||
114 | #define IPW_DEBUG_WX(f...) IPW_DEBUG(IPW_DL_WX, ## f) | ||
115 | #define IPW_DEBUG_SCAN(f...) IPW_DEBUG(IPW_DL_SCAN, ## f) | ||
116 | #define IPW_DEBUG_NOTIF(f...) IPW_DEBUG(IPW_DL_NOTIF, ## f) | ||
117 | #define IPW_DEBUG_TRACE(f...) IPW_DEBUG(IPW_DL_TRACE, ## f) | ||
118 | #define IPW_DEBUG_RX(f...) IPW_DEBUG(IPW_DL_RX, ## f) | ||
119 | #define IPW_DEBUG_TX(f...) IPW_DEBUG(IPW_DL_TX, ## f) | ||
120 | #define IPW_DEBUG_ISR(f...) IPW_DEBUG(IPW_DL_ISR, ## f) | ||
121 | #define IPW_DEBUG_MANAGEMENT(f...) IPW_DEBUG(IPW_DL_MANAGE, ## f) | ||
122 | #define IPW_DEBUG_WEP(f...) IPW_DEBUG(IPW_DL_WEP, ## f) | ||
123 | #define IPW_DEBUG_HC(f...) IPW_DEBUG(IPW_DL_HC, ## f) | ||
124 | #define IPW_DEBUG_FRAG(f...) IPW_DEBUG(IPW_DL_FRAG, ## f) | ||
125 | #define IPW_DEBUG_FW(f...) IPW_DEBUG(IPW_DL_FW, ## f) | ||
126 | #define IPW_DEBUG_RF_KILL(f...) IPW_DEBUG(IPW_DL_RF_KILL, ## f) | ||
127 | #define IPW_DEBUG_DROP(f...) IPW_DEBUG(IPW_DL_DROP, ## f) | ||
128 | #define IPW_DEBUG_IO(f...) IPW_DEBUG(IPW_DL_IO, ## f) | ||
129 | #define IPW_DEBUG_IOCTL(f...) IPW_DEBUG(IPW_DL_IOCTL, ## f) | ||
130 | #define IPW_DEBUG_STATE(f, a...) IPW_DEBUG(IPW_DL_STATE | IPW_DL_ASSOC | IPW_DL_INFO, f, ## a) | ||
131 | #define IPW_DEBUG_ASSOC(f, a...) IPW_DEBUG(IPW_DL_ASSOC | IPW_DL_INFO, f, ## a) | ||
132 | |||
133 | enum { | ||
134 | IPW_HW_STATE_DISABLED = 1, | ||
135 | IPW_HW_STATE_ENABLED = 0 | ||
136 | }; | ||
137 | |||
138 | struct ssid_context { | ||
139 | char ssid[IW_ESSID_MAX_SIZE + 1]; | ||
140 | int ssid_len; | ||
141 | unsigned char bssid[ETH_ALEN]; | ||
142 | int port_type; | ||
143 | int channel; | ||
144 | |||
145 | }; | ||
146 | |||
147 | extern const char *port_type_str[]; | ||
148 | extern const char *band_str[]; | ||
149 | |||
150 | #define NUMBER_OF_BD_PER_COMMAND_PACKET 1 | ||
151 | #define NUMBER_OF_BD_PER_DATA_PACKET 2 | ||
152 | |||
153 | #define IPW_MAX_BDS 6 | ||
154 | #define NUMBER_OF_OVERHEAD_BDS_PER_PACKETR 2 | ||
155 | #define NUMBER_OF_BDS_TO_LEAVE_FOR_COMMANDS 1 | ||
156 | |||
157 | #define REQUIRED_SPACE_IN_RING_FOR_COMMAND_PACKET \ | ||
158 | (IPW_BD_QUEUE_W_R_MIN_SPARE + NUMBER_OF_BD_PER_COMMAND_PACKET) | ||
159 | |||
160 | struct bd_status { | ||
161 | union { | ||
162 | struct { | ||
163 | u8 nlf:1, txType:2, intEnabled:1, reserved:4; | ||
164 | } fields; | ||
165 | u8 field; | ||
166 | } info; | ||
167 | } __attribute__ ((packed)); | ||
168 | |||
169 | struct ipw2100_bd { | ||
170 | u32 host_addr; | ||
171 | u32 buf_length; | ||
172 | struct bd_status status; | ||
173 | /* number of fragments for frame (should be set only for | ||
174 | * 1st TBD) */ | ||
175 | u8 num_fragments; | ||
176 | u8 reserved[6]; | ||
177 | } __attribute__ ((packed)); | ||
178 | |||
179 | #define IPW_BD_QUEUE_LENGTH(n) (1<<n) | ||
180 | #define IPW_BD_ALIGNMENT(L) (L*sizeof(struct ipw2100_bd)) | ||
181 | |||
182 | #define IPW_BD_STATUS_TX_FRAME_802_3 0x00 | ||
183 | #define IPW_BD_STATUS_TX_FRAME_NOT_LAST_FRAGMENT 0x01 | ||
184 | #define IPW_BD_STATUS_TX_FRAME_COMMAND 0x02 | ||
185 | #define IPW_BD_STATUS_TX_FRAME_802_11 0x04 | ||
186 | #define IPW_BD_STATUS_TX_INTERRUPT_ENABLE 0x08 | ||
187 | |||
188 | struct ipw2100_bd_queue { | ||
189 | /* driver (virtual) pointer to queue */ | ||
190 | struct ipw2100_bd *drv; | ||
191 | |||
192 | /* firmware (physical) pointer to queue */ | ||
193 | dma_addr_t nic; | ||
194 | |||
195 | /* Length of phy memory allocated for BDs */ | ||
196 | u32 size; | ||
197 | |||
198 | /* Number of BDs in queue (and in array) */ | ||
199 | u32 entries; | ||
200 | |||
201 | /* Number of available BDs (invalid for NIC BDs) */ | ||
202 | u32 available; | ||
203 | |||
204 | /* Offset of oldest used BD in array (next one to | ||
205 | * check for completion) */ | ||
206 | u32 oldest; | ||
207 | |||
208 | /* Offset of next available (unused) BD */ | ||
209 | u32 next; | ||
210 | }; | ||
211 | |||
212 | #define RX_QUEUE_LENGTH 256 | ||
213 | #define TX_QUEUE_LENGTH 256 | ||
214 | #define HW_QUEUE_LENGTH 256 | ||
215 | |||
216 | #define TX_PENDED_QUEUE_LENGTH (TX_QUEUE_LENGTH / NUMBER_OF_BD_PER_DATA_PACKET) | ||
217 | |||
218 | #define STATUS_TYPE_MASK 0x0000000f | ||
219 | #define COMMAND_STATUS_VAL 0 | ||
220 | #define STATUS_CHANGE_VAL 1 | ||
221 | #define P80211_DATA_VAL 2 | ||
222 | #define P8023_DATA_VAL 3 | ||
223 | #define HOST_NOTIFICATION_VAL 4 | ||
224 | |||
225 | #define IPW2100_RSSI_TO_DBM (-98) | ||
226 | |||
227 | struct ipw2100_status { | ||
228 | u32 frame_size; | ||
229 | u16 status_fields; | ||
230 | u8 flags; | ||
231 | #define IPW_STATUS_FLAG_DECRYPTED (1<<0) | ||
232 | #define IPW_STATUS_FLAG_WEP_ENCRYPTED (1<<1) | ||
233 | #define IPW_STATUS_FLAG_CRC_ERROR (1<<2) | ||
234 | u8 rssi; | ||
235 | } __attribute__ ((packed)); | ||
236 | |||
237 | struct ipw2100_status_queue { | ||
238 | /* driver (virtual) pointer to queue */ | ||
239 | struct ipw2100_status *drv; | ||
240 | |||
241 | /* firmware (physical) pointer to queue */ | ||
242 | dma_addr_t nic; | ||
243 | |||
244 | /* Length of phy memory allocated for BDs */ | ||
245 | u32 size; | ||
246 | }; | ||
247 | |||
248 | #define HOST_COMMAND_PARAMS_REG_LEN 100 | ||
249 | #define CMD_STATUS_PARAMS_REG_LEN 3 | ||
250 | |||
251 | #define IPW_WPA_CAPABILITIES 0x1 | ||
252 | #define IPW_WPA_LISTENINTERVAL 0x2 | ||
253 | #define IPW_WPA_AP_ADDRESS 0x4 | ||
254 | |||
255 | #define IPW_MAX_VAR_IE_LEN ((HOST_COMMAND_PARAMS_REG_LEN - 4) * sizeof(u32)) | ||
256 | |||
257 | struct ipw2100_wpa_assoc_frame { | ||
258 | u16 fixed_ie_mask; | ||
259 | struct { | ||
260 | u16 capab_info; | ||
261 | u16 listen_interval; | ||
262 | u8 current_ap[ETH_ALEN]; | ||
263 | } fixed_ies; | ||
264 | u32 var_ie_len; | ||
265 | u8 var_ie[IPW_MAX_VAR_IE_LEN]; | ||
266 | }; | ||
267 | |||
268 | #define IPW_BSS 1 | ||
269 | #define IPW_MONITOR 2 | ||
270 | #define IPW_IBSS 3 | ||
271 | |||
272 | /** | ||
273 | * @struct _tx_cmd - HWCommand | ||
274 | * @brief H/W command structure. | ||
275 | */ | ||
276 | struct ipw2100_cmd_header { | ||
277 | u32 host_command_reg; | ||
278 | u32 host_command_reg1; | ||
279 | u32 sequence; | ||
280 | u32 host_command_len_reg; | ||
281 | u32 host_command_params_reg[HOST_COMMAND_PARAMS_REG_LEN]; | ||
282 | u32 cmd_status_reg; | ||
283 | u32 cmd_status_params_reg[CMD_STATUS_PARAMS_REG_LEN]; | ||
284 | u32 rxq_base_ptr; | ||
285 | u32 rxq_next_ptr; | ||
286 | u32 rxq_host_ptr; | ||
287 | u32 txq_base_ptr; | ||
288 | u32 txq_next_ptr; | ||
289 | u32 txq_host_ptr; | ||
290 | u32 tx_status_reg; | ||
291 | u32 reserved; | ||
292 | u32 status_change_reg; | ||
293 | u32 reserved1[3]; | ||
294 | u32 *ordinal1_ptr; | ||
295 | u32 *ordinal2_ptr; | ||
296 | } __attribute__ ((packed)); | ||
297 | |||
298 | struct ipw2100_data_header { | ||
299 | u32 host_command_reg; | ||
300 | u32 host_command_reg1; | ||
301 | u8 encrypted; // BOOLEAN in win! TRUE if frame is enc by driver | ||
302 | u8 needs_encryption; // BOOLEAN in win! TRUE if frma need to be enc in NIC | ||
303 | u8 wep_index; // 0 no key, 1-4 key index, 0xff immediate key | ||
304 | u8 key_size; // 0 no imm key, 0x5 64bit encr, 0xd 128bit encr, 0x10 128bit encr and 128bit IV | ||
305 | u8 key[16]; | ||
306 | u8 reserved[10]; // f/w reserved | ||
307 | u8 src_addr[ETH_ALEN]; | ||
308 | u8 dst_addr[ETH_ALEN]; | ||
309 | u16 fragment_size; | ||
310 | } __attribute__ ((packed)); | ||
311 | |||
312 | /* Host command data structure */ | ||
313 | struct host_command { | ||
314 | u32 host_command; // COMMAND ID | ||
315 | u32 host_command1; // COMMAND ID | ||
316 | u32 host_command_sequence; // UNIQUE COMMAND NUMBER (ID) | ||
317 | u32 host_command_length; // LENGTH | ||
318 | u32 host_command_parameters[HOST_COMMAND_PARAMS_REG_LEN]; // COMMAND PARAMETERS | ||
319 | } __attribute__ ((packed)); | ||
320 | |||
321 | typedef enum { | ||
322 | POWER_ON_RESET, | ||
323 | EXIT_POWER_DOWN_RESET, | ||
324 | SW_RESET, | ||
325 | EEPROM_RW, | ||
326 | SW_RE_INIT | ||
327 | } ipw2100_reset_event; | ||
328 | |||
329 | enum { | ||
330 | COMMAND = 0xCAFE, | ||
331 | DATA, | ||
332 | RX | ||
333 | }; | ||
334 | |||
335 | struct ipw2100_tx_packet { | ||
336 | int type; | ||
337 | int index; | ||
338 | union { | ||
339 | struct { /* COMMAND */ | ||
340 | struct ipw2100_cmd_header *cmd; | ||
341 | dma_addr_t cmd_phys; | ||
342 | } c_struct; | ||
343 | struct { /* DATA */ | ||
344 | struct ipw2100_data_header *data; | ||
345 | dma_addr_t data_phys; | ||
346 | struct ieee80211_txb *txb; | ||
347 | } d_struct; | ||
348 | } info; | ||
349 | int jiffy_start; | ||
350 | |||
351 | struct list_head list; | ||
352 | }; | ||
353 | |||
354 | struct ipw2100_rx_packet { | ||
355 | struct ipw2100_rx *rxp; | ||
356 | dma_addr_t dma_addr; | ||
357 | int jiffy_start; | ||
358 | struct sk_buff *skb; | ||
359 | struct list_head list; | ||
360 | }; | ||
361 | |||
362 | #define FRAG_DISABLED (1<<31) | ||
363 | #define RTS_DISABLED (1<<31) | ||
364 | #define MAX_RTS_THRESHOLD 2304U | ||
365 | #define MIN_RTS_THRESHOLD 1U | ||
366 | #define DEFAULT_RTS_THRESHOLD 1000U | ||
367 | |||
368 | #define DEFAULT_BEACON_INTERVAL 100U | ||
369 | #define DEFAULT_SHORT_RETRY_LIMIT 7U | ||
370 | #define DEFAULT_LONG_RETRY_LIMIT 4U | ||
371 | |||
372 | struct ipw2100_ordinals { | ||
373 | u32 table1_addr; | ||
374 | u32 table2_addr; | ||
375 | u32 table1_size; | ||
376 | u32 table2_size; | ||
377 | }; | ||
378 | |||
379 | /* Host Notification header */ | ||
380 | struct ipw2100_notification { | ||
381 | u32 hnhdr_subtype; /* type of host notification */ | ||
382 | u32 hnhdr_size; /* size in bytes of data | ||
383 | or number of entries, if table. | ||
384 | Does NOT include header */ | ||
385 | } __attribute__ ((packed)); | ||
386 | |||
387 | #define MAX_KEY_SIZE 16 | ||
388 | #define MAX_KEYS 8 | ||
389 | |||
390 | #define IPW2100_WEP_ENABLE (1<<1) | ||
391 | #define IPW2100_WEP_DROP_CLEAR (1<<2) | ||
392 | |||
393 | #define IPW_NONE_CIPHER (1<<0) | ||
394 | #define IPW_WEP40_CIPHER (1<<1) | ||
395 | #define IPW_TKIP_CIPHER (1<<2) | ||
396 | #define IPW_CCMP_CIPHER (1<<4) | ||
397 | #define IPW_WEP104_CIPHER (1<<5) | ||
398 | #define IPW_CKIP_CIPHER (1<<6) | ||
399 | |||
400 | #define IPW_AUTH_OPEN 0 | ||
401 | #define IPW_AUTH_SHARED 1 | ||
402 | #define IPW_AUTH_LEAP 2 | ||
403 | #define IPW_AUTH_LEAP_CISCO_ID 0x80 | ||
404 | |||
405 | struct statistic { | ||
406 | int value; | ||
407 | int hi; | ||
408 | int lo; | ||
409 | }; | ||
410 | |||
411 | #define INIT_STAT(x) do { \ | ||
412 | (x)->value = (x)->hi = 0; \ | ||
413 | (x)->lo = 0x7fffffff; \ | ||
414 | } while (0) | ||
415 | #define SET_STAT(x,y) do { \ | ||
416 | (x)->value = y; \ | ||
417 | if ((x)->value > (x)->hi) (x)->hi = (x)->value; \ | ||
418 | if ((x)->value < (x)->lo) (x)->lo = (x)->value; \ | ||
419 | } while (0) | ||
420 | #define INC_STAT(x) do { if (++(x)->value > (x)->hi) (x)->hi = (x)->value; } \ | ||
421 | while (0) | ||
422 | #define DEC_STAT(x) do { if (--(x)->value < (x)->lo) (x)->lo = (x)->value; } \ | ||
423 | while (0) | ||
424 | |||
425 | #define IPW2100_ERROR_QUEUE 5 | ||
426 | |||
427 | /* Power management code: enable or disable? */ | ||
428 | enum { | ||
429 | #ifdef CONFIG_PM | ||
430 | IPW2100_PM_DISABLED = 0, | ||
431 | PM_STATE_SIZE = 16, | ||
432 | #else | ||
433 | IPW2100_PM_DISABLED = 1, | ||
434 | PM_STATE_SIZE = 0, | ||
435 | #endif | ||
436 | }; | ||
437 | |||
438 | #define STATUS_POWERED (1<<0) | ||
439 | #define STATUS_CMD_ACTIVE (1<<1) /**< host command in progress */ | ||
440 | #define STATUS_RUNNING (1<<2) /* Card initialized, but not enabled */ | ||
441 | #define STATUS_ENABLED (1<<3) /* Card enabled -- can scan,Tx,Rx */ | ||
442 | #define STATUS_STOPPING (1<<4) /* Card is in shutdown phase */ | ||
443 | #define STATUS_INITIALIZED (1<<5) /* Card is ready for external calls */ | ||
444 | #define STATUS_ASSOCIATING (1<<9) /* Associated, but no BSSID yet */ | ||
445 | #define STATUS_ASSOCIATED (1<<10) /* Associated and BSSID valid */ | ||
446 | #define STATUS_INT_ENABLED (1<<11) | ||
447 | #define STATUS_RF_KILL_HW (1<<12) | ||
448 | #define STATUS_RF_KILL_SW (1<<13) | ||
449 | #define STATUS_RF_KILL_MASK (STATUS_RF_KILL_HW | STATUS_RF_KILL_SW) | ||
450 | #define STATUS_EXIT_PENDING (1<<14) | ||
451 | |||
452 | #define STATUS_SCAN_PENDING (1<<23) | ||
453 | #define STATUS_SCANNING (1<<24) | ||
454 | #define STATUS_SCAN_ABORTING (1<<25) | ||
455 | #define STATUS_SCAN_COMPLETE (1<<26) | ||
456 | #define STATUS_WX_EVENT_PENDING (1<<27) | ||
457 | #define STATUS_RESET_PENDING (1<<29) | ||
458 | #define STATUS_SECURITY_UPDATED (1<<30) /* Security sync needed */ | ||
459 | |||
460 | /* Internal NIC states */ | ||
461 | #define IPW_STATE_INITIALIZED (1<<0) | ||
462 | #define IPW_STATE_COUNTRY_FOUND (1<<1) | ||
463 | #define IPW_STATE_ASSOCIATED (1<<2) | ||
464 | #define IPW_STATE_ASSN_LOST (1<<3) | ||
465 | #define IPW_STATE_ASSN_CHANGED (1<<4) | ||
466 | #define IPW_STATE_SCAN_COMPLETE (1<<5) | ||
467 | #define IPW_STATE_ENTERED_PSP (1<<6) | ||
468 | #define IPW_STATE_LEFT_PSP (1<<7) | ||
469 | #define IPW_STATE_RF_KILL (1<<8) | ||
470 | #define IPW_STATE_DISABLED (1<<9) | ||
471 | #define IPW_STATE_POWER_DOWN (1<<10) | ||
472 | #define IPW_STATE_SCANNING (1<<11) | ||
473 | |||
474 | #define CFG_STATIC_CHANNEL (1<<0) /* Restrict assoc. to single channel */ | ||
475 | #define CFG_STATIC_ESSID (1<<1) /* Restrict assoc. to single SSID */ | ||
476 | #define CFG_STATIC_BSSID (1<<2) /* Restrict assoc. to single BSSID */ | ||
477 | #define CFG_CUSTOM_MAC (1<<3) | ||
478 | #define CFG_LONG_PREAMBLE (1<<4) | ||
479 | #define CFG_ASSOCIATE (1<<6) | ||
480 | #define CFG_FIXED_RATE (1<<7) | ||
481 | #define CFG_ADHOC_CREATE (1<<8) | ||
482 | #define CFG_PASSIVE_SCAN (1<<10) | ||
483 | #ifdef CONFIG_IPW2100_MONITOR | ||
484 | #define CFG_CRC_CHECK (1<<11) | ||
485 | #endif | ||
486 | |||
487 | #define CAP_SHARED_KEY (1<<0) /* Off = OPEN */ | ||
488 | #define CAP_PRIVACY_ON (1<<1) /* Off = No privacy */ | ||
489 | |||
490 | struct ipw2100_priv { | ||
491 | |||
492 | int stop_hang_check; /* Set 1 when shutting down to kill hang_check */ | ||
493 | int stop_rf_kill; /* Set 1 when shutting down to kill rf_kill */ | ||
494 | |||
495 | struct ieee80211_device *ieee; | ||
496 | unsigned long status; | ||
497 | unsigned long config; | ||
498 | unsigned long capability; | ||
499 | |||
500 | /* Statistics */ | ||
501 | int resets; | ||
502 | int reset_backoff; | ||
503 | |||
504 | /* Context */ | ||
505 | u8 essid[IW_ESSID_MAX_SIZE]; | ||
506 | u8 essid_len; | ||
507 | u8 bssid[ETH_ALEN]; | ||
508 | u8 channel; | ||
509 | int last_mode; | ||
510 | |||
511 | unsigned long connect_start; | ||
512 | unsigned long last_reset; | ||
513 | |||
514 | u32 channel_mask; | ||
515 | u32 fatal_error; | ||
516 | u32 fatal_errors[IPW2100_ERROR_QUEUE]; | ||
517 | u32 fatal_index; | ||
518 | int eeprom_version; | ||
519 | int firmware_version; | ||
520 | unsigned long hw_features; | ||
521 | int hangs; | ||
522 | u32 last_rtc; | ||
523 | int dump_raw; /* 1 to dump raw bytes in /sys/.../memory */ | ||
524 | u8 *snapshot[0x30]; | ||
525 | |||
526 | u8 mandatory_bssid_mac[ETH_ALEN]; | ||
527 | u8 mac_addr[ETH_ALEN]; | ||
528 | |||
529 | int power_mode; | ||
530 | |||
531 | int messages_sent; | ||
532 | |||
533 | int short_retry_limit; | ||
534 | int long_retry_limit; | ||
535 | |||
536 | u32 rts_threshold; | ||
537 | u32 frag_threshold; | ||
538 | |||
539 | int in_isr; | ||
540 | |||
541 | u32 tx_rates; | ||
542 | int tx_power; | ||
543 | u32 beacon_interval; | ||
544 | |||
545 | char nick[IW_ESSID_MAX_SIZE + 1]; | ||
546 | |||
547 | struct ipw2100_status_queue status_queue; | ||
548 | |||
549 | struct statistic txq_stat; | ||
550 | struct statistic rxq_stat; | ||
551 | struct ipw2100_bd_queue rx_queue; | ||
552 | struct ipw2100_bd_queue tx_queue; | ||
553 | struct ipw2100_rx_packet *rx_buffers; | ||
554 | |||
555 | struct statistic fw_pend_stat; | ||
556 | struct list_head fw_pend_list; | ||
557 | |||
558 | struct statistic msg_free_stat; | ||
559 | struct statistic msg_pend_stat; | ||
560 | struct list_head msg_free_list; | ||
561 | struct list_head msg_pend_list; | ||
562 | struct ipw2100_tx_packet *msg_buffers; | ||
563 | |||
564 | struct statistic tx_free_stat; | ||
565 | struct statistic tx_pend_stat; | ||
566 | struct list_head tx_free_list; | ||
567 | struct list_head tx_pend_list; | ||
568 | struct ipw2100_tx_packet *tx_buffers; | ||
569 | |||
570 | struct ipw2100_ordinals ordinals; | ||
571 | |||
572 | struct pci_dev *pci_dev; | ||
573 | |||
574 | struct proc_dir_entry *dir_dev; | ||
575 | |||
576 | struct net_device *net_dev; | ||
577 | struct iw_statistics wstats; | ||
578 | |||
579 | struct iw_public_data wireless_data; | ||
580 | |||
581 | struct tasklet_struct irq_tasklet; | ||
582 | |||
583 | struct workqueue_struct *workqueue; | ||
584 | struct delayed_work reset_work; | ||
585 | struct delayed_work security_work; | ||
586 | struct delayed_work wx_event_work; | ||
587 | struct delayed_work hang_check; | ||
588 | struct delayed_work rf_kill; | ||
589 | struct work_struct scan_event_now; | ||
590 | struct delayed_work scan_event_later; | ||
591 | |||
592 | int user_requested_scan; | ||
593 | |||
594 | u32 interrupts; | ||
595 | int tx_interrupts; | ||
596 | int rx_interrupts; | ||
597 | int inta_other; | ||
598 | |||
599 | spinlock_t low_lock; | ||
600 | struct mutex action_mutex; | ||
601 | struct mutex adapter_mutex; | ||
602 | |||
603 | wait_queue_head_t wait_command_queue; | ||
604 | }; | ||
605 | |||
606 | /********************************************************* | ||
607 | * Host Command -> From Driver to FW | ||
608 | *********************************************************/ | ||
609 | |||
610 | /** | ||
611 | * Host command identifiers | ||
612 | */ | ||
613 | #define HOST_COMPLETE 2 | ||
614 | #define SYSTEM_CONFIG 6 | ||
615 | #define SSID 8 | ||
616 | #define MANDATORY_BSSID 9 | ||
617 | #define AUTHENTICATION_TYPE 10 | ||
618 | #define ADAPTER_ADDRESS 11 | ||
619 | #define PORT_TYPE 12 | ||
620 | #define INTERNATIONAL_MODE 13 | ||
621 | #define CHANNEL 14 | ||
622 | #define RTS_THRESHOLD 15 | ||
623 | #define FRAG_THRESHOLD 16 | ||
624 | #define POWER_MODE 17 | ||
625 | #define TX_RATES 18 | ||
626 | #define BASIC_TX_RATES 19 | ||
627 | #define WEP_KEY_INFO 20 | ||
628 | #define WEP_KEY_INDEX 25 | ||
629 | #define WEP_FLAGS 26 | ||
630 | #define ADD_MULTICAST 27 | ||
631 | #define CLEAR_ALL_MULTICAST 28 | ||
632 | #define BEACON_INTERVAL 29 | ||
633 | #define ATIM_WINDOW 30 | ||
634 | #define CLEAR_STATISTICS 31 | ||
635 | #define SEND 33 | ||
636 | #define TX_POWER_INDEX 36 | ||
637 | #define BROADCAST_SCAN 43 | ||
638 | #define CARD_DISABLE 44 | ||
639 | #define PREFERRED_BSSID 45 | ||
640 | #define SET_SCAN_OPTIONS 46 | ||
641 | #define SCAN_DWELL_TIME 47 | ||
642 | #define SWEEP_TABLE 48 | ||
643 | #define AP_OR_STATION_TABLE 49 | ||
644 | #define GROUP_ORDINALS 50 | ||
645 | #define SHORT_RETRY_LIMIT 51 | ||
646 | #define LONG_RETRY_LIMIT 52 | ||
647 | |||
648 | #define HOST_PRE_POWER_DOWN 58 | ||
649 | #define CARD_DISABLE_PHY_OFF 61 | ||
650 | #define MSDU_TX_RATES 62 | ||
651 | |||
652 | /* Rogue AP Detection */ | ||
653 | #define SET_STATION_STAT_BITS 64 | ||
654 | #define CLEAR_STATIONS_STAT_BITS 65 | ||
655 | #define LEAP_ROGUE_MODE 66 //TODO tbw replaced by CFG_LEAP_ROGUE_AP | ||
656 | #define SET_SECURITY_INFORMATION 67 | ||
657 | #define DISASSOCIATION_BSSID 68 | ||
658 | #define SET_WPA_IE 69 | ||
659 | |||
660 | /* system configuration bit mask: */ | ||
661 | #define IPW_CFG_MONITOR 0x00004 | ||
662 | #define IPW_CFG_PREAMBLE_AUTO 0x00010 | ||
663 | #define IPW_CFG_IBSS_AUTO_START 0x00020 | ||
664 | #define IPW_CFG_LOOPBACK 0x00100 | ||
665 | #define IPW_CFG_ANSWER_BCSSID_PROBE 0x00800 | ||
666 | #define IPW_CFG_BT_SIDEBAND_SIGNAL 0x02000 | ||
667 | #define IPW_CFG_802_1x_ENABLE 0x04000 | ||
668 | #define IPW_CFG_BSS_MASK 0x08000 | ||
669 | #define IPW_CFG_IBSS_MASK 0x10000 | ||
670 | |||
671 | #define IPW_SCAN_NOASSOCIATE (1<<0) | ||
672 | #define IPW_SCAN_MIXED_CELL (1<<1) | ||
673 | /* RESERVED (1<<2) */ | ||
674 | #define IPW_SCAN_PASSIVE (1<<3) | ||
675 | |||
676 | #define IPW_NIC_FATAL_ERROR 0x2A7F0 | ||
677 | #define IPW_ERROR_ADDR(x) (x & 0x3FFFF) | ||
678 | #define IPW_ERROR_CODE(x) ((x & 0xFF000000) >> 24) | ||
679 | #define IPW2100_ERR_C3_CORRUPTION (0x10 << 24) | ||
680 | #define IPW2100_ERR_MSG_TIMEOUT (0x11 << 24) | ||
681 | #define IPW2100_ERR_FW_LOAD (0x12 << 24) | ||
682 | |||
683 | #define IPW_MEM_SRAM_HOST_SHARED_LOWER_BOUND 0x200 | ||
684 | #define IPW_MEM_SRAM_HOST_INTERRUPT_AREA_LOWER_BOUND IPW_MEM_SRAM_HOST_SHARED_LOWER_BOUND + 0x0D80 | ||
685 | |||
686 | #define IPW_MEM_HOST_SHARED_RX_BD_BASE (IPW_MEM_SRAM_HOST_SHARED_LOWER_BOUND + 0x40) | ||
687 | #define IPW_MEM_HOST_SHARED_RX_STATUS_BASE (IPW_MEM_SRAM_HOST_SHARED_LOWER_BOUND + 0x44) | ||
688 | #define IPW_MEM_HOST_SHARED_RX_BD_SIZE (IPW_MEM_SRAM_HOST_SHARED_LOWER_BOUND + 0x48) | ||
689 | #define IPW_MEM_HOST_SHARED_RX_READ_INDEX (IPW_MEM_SRAM_HOST_SHARED_LOWER_BOUND + 0xa0) | ||
690 | |||
691 | #define IPW_MEM_HOST_SHARED_TX_QUEUE_BD_BASE (IPW_MEM_SRAM_HOST_SHARED_LOWER_BOUND + 0x00) | ||
692 | #define IPW_MEM_HOST_SHARED_TX_QUEUE_BD_SIZE (IPW_MEM_SRAM_HOST_SHARED_LOWER_BOUND + 0x04) | ||
693 | #define IPW_MEM_HOST_SHARED_TX_QUEUE_READ_INDEX (IPW_MEM_SRAM_HOST_SHARED_LOWER_BOUND + 0x80) | ||
694 | |||
695 | #define IPW_MEM_HOST_SHARED_RX_WRITE_INDEX \ | ||
696 | (IPW_MEM_SRAM_HOST_INTERRUPT_AREA_LOWER_BOUND + 0x20) | ||
697 | |||
698 | #define IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX \ | ||
699 | (IPW_MEM_SRAM_HOST_INTERRUPT_AREA_LOWER_BOUND) | ||
700 | |||
701 | #define IPW_MEM_HOST_SHARED_ORDINALS_TABLE_1 (IPW_MEM_SRAM_HOST_SHARED_LOWER_BOUND + 0x180) | ||
702 | #define IPW_MEM_HOST_SHARED_ORDINALS_TABLE_2 (IPW_MEM_SRAM_HOST_SHARED_LOWER_BOUND + 0x184) | ||
703 | |||
704 | #define IPW2100_INTA_TX_TRANSFER (0x00000001) // Bit 0 (LSB) | ||
705 | #define IPW2100_INTA_RX_TRANSFER (0x00000002) // Bit 1 | ||
706 | #define IPW2100_INTA_TX_COMPLETE (0x00000004) // Bit 2 | ||
707 | #define IPW2100_INTA_EVENT_INTERRUPT (0x00000008) // Bit 3 | ||
708 | #define IPW2100_INTA_STATUS_CHANGE (0x00000010) // Bit 4 | ||
709 | #define IPW2100_INTA_BEACON_PERIOD_EXPIRED (0x00000020) // Bit 5 | ||
710 | #define IPW2100_INTA_SLAVE_MODE_HOST_COMMAND_DONE (0x00010000) // Bit 16 | ||
711 | #define IPW2100_INTA_FW_INIT_DONE (0x01000000) // Bit 24 | ||
712 | #define IPW2100_INTA_FW_CALIBRATION_CALC (0x02000000) // Bit 25 | ||
713 | #define IPW2100_INTA_FATAL_ERROR (0x40000000) // Bit 30 | ||
714 | #define IPW2100_INTA_PARITY_ERROR (0x80000000) // Bit 31 (MSB) | ||
715 | |||
716 | #define IPW_AUX_HOST_RESET_REG_PRINCETON_RESET (0x00000001) | ||
717 | #define IPW_AUX_HOST_RESET_REG_FORCE_NMI (0x00000002) | ||
718 | #define IPW_AUX_HOST_RESET_REG_PCI_HOST_CLUSTER_FATAL_NMI (0x00000004) | ||
719 | #define IPW_AUX_HOST_RESET_REG_CORE_FATAL_NMI (0x00000008) | ||
720 | #define IPW_AUX_HOST_RESET_REG_SW_RESET (0x00000080) | ||
721 | #define IPW_AUX_HOST_RESET_REG_MASTER_DISABLED (0x00000100) | ||
722 | #define IPW_AUX_HOST_RESET_REG_STOP_MASTER (0x00000200) | ||
723 | |||
724 | #define IPW_AUX_HOST_GP_CNTRL_BIT_CLOCK_READY (0x00000001) // Bit 0 (LSB) | ||
725 | #define IPW_AUX_HOST_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY (0x00000002) // Bit 1 | ||
726 | #define IPW_AUX_HOST_GP_CNTRL_BIT_INIT_DONE (0x00000004) // Bit 2 | ||
727 | #define IPW_AUX_HOST_GP_CNTRL_BITS_SYS_CONFIG (0x000007c0) // Bits 6-10 | ||
728 | #define IPW_AUX_HOST_GP_CNTRL_BIT_BUS_TYPE (0x00000200) // Bit 9 | ||
729 | #define IPW_AUX_HOST_GP_CNTRL_BIT_BAR0_BLOCK_SIZE (0x00000400) // Bit 10 | ||
730 | #define IPW_AUX_HOST_GP_CNTRL_BIT_USB_MODE (0x20000000) // Bit 29 | ||
731 | #define IPW_AUX_HOST_GP_CNTRL_BIT_HOST_FORCES_SYS_CLK (0x40000000) // Bit 30 | ||
732 | #define IPW_AUX_HOST_GP_CNTRL_BIT_FW_FORCES_SYS_CLK (0x80000000) // Bit 31 (MSB) | ||
733 | |||
734 | #define IPW_BIT_GPIO_GPIO1_MASK 0x0000000C | ||
735 | #define IPW_BIT_GPIO_GPIO3_MASK 0x000000C0 | ||
736 | #define IPW_BIT_GPIO_GPIO1_ENABLE 0x00000008 | ||
737 | #define IPW_BIT_GPIO_RF_KILL 0x00010000 | ||
738 | |||
739 | #define IPW_BIT_GPIO_LED_OFF 0x00002000 // Bit 13 = 1 | ||
740 | |||
741 | #define IPW_REG_DOMAIN_0_OFFSET 0x0000 | ||
742 | #define IPW_REG_DOMAIN_1_OFFSET IPW_MEM_SRAM_HOST_SHARED_LOWER_BOUND | ||
743 | |||
744 | #define IPW_REG_INTA IPW_REG_DOMAIN_0_OFFSET + 0x0008 | ||
745 | #define IPW_REG_INTA_MASK IPW_REG_DOMAIN_0_OFFSET + 0x000C | ||
746 | #define IPW_REG_INDIRECT_ACCESS_ADDRESS IPW_REG_DOMAIN_0_OFFSET + 0x0010 | ||
747 | #define IPW_REG_INDIRECT_ACCESS_DATA IPW_REG_DOMAIN_0_OFFSET + 0x0014 | ||
748 | #define IPW_REG_AUTOINCREMENT_ADDRESS IPW_REG_DOMAIN_0_OFFSET + 0x0018 | ||
749 | #define IPW_REG_AUTOINCREMENT_DATA IPW_REG_DOMAIN_0_OFFSET + 0x001C | ||
750 | #define IPW_REG_RESET_REG IPW_REG_DOMAIN_0_OFFSET + 0x0020 | ||
751 | #define IPW_REG_GP_CNTRL IPW_REG_DOMAIN_0_OFFSET + 0x0024 | ||
752 | #define IPW_REG_GPIO IPW_REG_DOMAIN_0_OFFSET + 0x0030 | ||
753 | #define IPW_REG_FW_TYPE IPW_REG_DOMAIN_1_OFFSET + 0x0188 | ||
754 | #define IPW_REG_FW_VERSION IPW_REG_DOMAIN_1_OFFSET + 0x018C | ||
755 | #define IPW_REG_FW_COMPATABILITY_VERSION IPW_REG_DOMAIN_1_OFFSET + 0x0190 | ||
756 | |||
757 | #define IPW_REG_INDIRECT_ADDR_MASK 0x00FFFFFC | ||
758 | |||
759 | #define IPW_INTERRUPT_MASK 0xC1010013 | ||
760 | |||
761 | #define IPW2100_CONTROL_REG 0x220000 | ||
762 | #define IPW2100_CONTROL_PHY_OFF 0x8 | ||
763 | |||
764 | #define IPW2100_COMMAND 0x00300004 | ||
765 | #define IPW2100_COMMAND_PHY_ON 0x0 | ||
766 | #define IPW2100_COMMAND_PHY_OFF 0x1 | ||
767 | |||
768 | /* in DEBUG_AREA, values of memory always 0xd55555d5 */ | ||
769 | #define IPW_REG_DOA_DEBUG_AREA_START IPW_REG_DOMAIN_0_OFFSET + 0x0090 | ||
770 | #define IPW_REG_DOA_DEBUG_AREA_END IPW_REG_DOMAIN_0_OFFSET + 0x00FF | ||
771 | #define IPW_DATA_DOA_DEBUG_VALUE 0xd55555d5 | ||
772 | |||
773 | #define IPW_INTERNAL_REGISTER_HALT_AND_RESET 0x003000e0 | ||
774 | |||
775 | #define IPW_WAIT_CLOCK_STABILIZATION_DELAY 50 // micro seconds | ||
776 | #define IPW_WAIT_RESET_ARC_COMPLETE_DELAY 10 // micro seconds | ||
777 | #define IPW_WAIT_RESET_MASTER_ASSERT_COMPLETE_DELAY 10 // micro seconds | ||
778 | |||
779 | // BD ring queue read/write difference | ||
780 | #define IPW_BD_QUEUE_W_R_MIN_SPARE 2 | ||
781 | |||
782 | #define IPW_CACHE_LINE_LENGTH_DEFAULT 0x80 | ||
783 | |||
784 | #define IPW_CARD_DISABLE_PHY_OFF_COMPLETE_WAIT 100 // 100 milli | ||
785 | #define IPW_PREPARE_POWER_DOWN_COMPLETE_WAIT 100 // 100 milli | ||
786 | |||
787 | #define IPW_HEADER_802_11_SIZE sizeof(struct ieee80211_hdr_3addr) | ||
788 | #define IPW_MAX_80211_PAYLOAD_SIZE 2304U | ||
789 | #define IPW_MAX_802_11_PAYLOAD_LENGTH 2312 | ||
790 | #define IPW_MAX_ACCEPTABLE_TX_FRAME_LENGTH 1536 | ||
791 | #define IPW_MIN_ACCEPTABLE_RX_FRAME_LENGTH 60 | ||
792 | #define IPW_MAX_ACCEPTABLE_RX_FRAME_LENGTH \ | ||
793 | (IPW_MAX_ACCEPTABLE_TX_FRAME_LENGTH + IPW_HEADER_802_11_SIZE - \ | ||
794 | sizeof(struct ethhdr)) | ||
795 | |||
796 | #define IPW_802_11_FCS_LENGTH 4 | ||
797 | #define IPW_RX_NIC_BUFFER_LENGTH \ | ||
798 | (IPW_MAX_802_11_PAYLOAD_LENGTH + IPW_HEADER_802_11_SIZE + \ | ||
799 | IPW_802_11_FCS_LENGTH) | ||
800 | |||
801 | #define IPW_802_11_PAYLOAD_OFFSET \ | ||
802 | (sizeof(struct ieee80211_hdr_3addr) + \ | ||
803 | sizeof(struct ieee80211_snap_hdr)) | ||
804 | |||
805 | struct ipw2100_rx { | ||
806 | union { | ||
807 | unsigned char payload[IPW_RX_NIC_BUFFER_LENGTH]; | ||
808 | struct ieee80211_hdr_4addr header; | ||
809 | u32 status; | ||
810 | struct ipw2100_notification notification; | ||
811 | struct ipw2100_cmd_header command; | ||
812 | } rx_data; | ||
813 | } __attribute__ ((packed)); | ||
814 | |||
815 | /* Bit 0-7 are for 802.11b tx rates - . Bit 5-7 are reserved */ | ||
816 | #define TX_RATE_1_MBIT 0x0001 | ||
817 | #define TX_RATE_2_MBIT 0x0002 | ||
818 | #define TX_RATE_5_5_MBIT 0x0004 | ||
819 | #define TX_RATE_11_MBIT 0x0008 | ||
820 | #define TX_RATE_MASK 0x000F | ||
821 | #define DEFAULT_TX_RATES 0x000F | ||
822 | |||
823 | #define IPW_POWER_MODE_CAM 0x00 //(always on) | ||
824 | #define IPW_POWER_INDEX_1 0x01 | ||
825 | #define IPW_POWER_INDEX_2 0x02 | ||
826 | #define IPW_POWER_INDEX_3 0x03 | ||
827 | #define IPW_POWER_INDEX_4 0x04 | ||
828 | #define IPW_POWER_INDEX_5 0x05 | ||
829 | #define IPW_POWER_AUTO 0x06 | ||
830 | #define IPW_POWER_MASK 0x0F | ||
831 | #define IPW_POWER_ENABLED 0x10 | ||
832 | #define IPW_POWER_LEVEL(x) ((x) & IPW_POWER_MASK) | ||
833 | |||
834 | #define IPW_TX_POWER_AUTO 0 | ||
835 | #define IPW_TX_POWER_ENHANCED 1 | ||
836 | |||
837 | #define IPW_TX_POWER_DEFAULT 32 | ||
838 | #define IPW_TX_POWER_MIN 0 | ||
839 | #define IPW_TX_POWER_MAX 16 | ||
840 | #define IPW_TX_POWER_MIN_DBM (-12) | ||
841 | #define IPW_TX_POWER_MAX_DBM 16 | ||
842 | |||
843 | #define FW_SCAN_DONOT_ASSOCIATE 0x0001 // Dont Attempt to Associate after Scan | ||
844 | #define FW_SCAN_PASSIVE 0x0008 // Force PASSSIVE Scan | ||
845 | |||
846 | #define REG_MIN_CHANNEL 0 | ||
847 | #define REG_MAX_CHANNEL 14 | ||
848 | |||
849 | #define REG_CHANNEL_MASK 0x00003FFF | ||
850 | #define IPW_IBSS_11B_DEFAULT_MASK 0x87ff | ||
851 | |||
852 | #define DIVERSITY_EITHER 0 // Use both antennas | ||
853 | #define DIVERSITY_ANTENNA_A 1 // Use antenna A | ||
854 | #define DIVERSITY_ANTENNA_B 2 // Use antenna B | ||
855 | |||
856 | #define HOST_COMMAND_WAIT 0 | ||
857 | #define HOST_COMMAND_NO_WAIT 1 | ||
858 | |||
859 | #define LOCK_NONE 0 | ||
860 | #define LOCK_DRIVER 1 | ||
861 | #define LOCK_FW 2 | ||
862 | |||
863 | #define TYPE_SWEEP_ORD 0x000D | ||
864 | #define TYPE_IBSS_STTN_ORD 0x000E | ||
865 | #define TYPE_BSS_AP_ORD 0x000F | ||
866 | #define TYPE_RAW_BEACON_ENTRY 0x0010 | ||
867 | #define TYPE_CALIBRATION_DATA 0x0011 | ||
868 | #define TYPE_ROGUE_AP_DATA 0x0012 | ||
869 | #define TYPE_ASSOCIATION_REQUEST 0x0013 | ||
870 | #define TYPE_REASSOCIATION_REQUEST 0x0014 | ||
871 | |||
872 | #define HW_FEATURE_RFKILL 0x0001 | ||
873 | #define RF_KILLSWITCH_OFF 1 | ||
874 | #define RF_KILLSWITCH_ON 0 | ||
875 | |||
876 | #define IPW_COMMAND_POOL_SIZE 40 | ||
877 | |||
878 | #define IPW_START_ORD_TAB_1 1 | ||
879 | #define IPW_START_ORD_TAB_2 1000 | ||
880 | |||
881 | #define IPW_ORD_TAB_1_ENTRY_SIZE sizeof(u32) | ||
882 | |||
883 | #define IS_ORDINAL_TABLE_ONE(mgr,id) \ | ||
884 | ((id >= IPW_START_ORD_TAB_1) && (id < mgr->table1_size)) | ||
885 | #define IS_ORDINAL_TABLE_TWO(mgr,id) \ | ||
886 | ((id >= IPW_START_ORD_TAB_2) && (id < (mgr->table2_size + IPW_START_ORD_TAB_2))) | ||
887 | |||
888 | #define BSS_ID_LENGTH 6 | ||
889 | |||
890 | // Fixed size data: Ordinal Table 1 | ||
891 | typedef enum _ORDINAL_TABLE_1 { // NS - means Not Supported by FW | ||
892 | // Transmit statistics | ||
893 | IPW_ORD_STAT_TX_HOST_REQUESTS = 1, // # of requested Host Tx's (MSDU) | ||
894 | IPW_ORD_STAT_TX_HOST_COMPLETE, // # of successful Host Tx's (MSDU) | ||
895 | IPW_ORD_STAT_TX_DIR_DATA, // # of successful Directed Tx's (MSDU) | ||
896 | |||
897 | IPW_ORD_STAT_TX_DIR_DATA1 = 4, // # of successful Directed Tx's (MSDU) @ 1MB | ||
898 | IPW_ORD_STAT_TX_DIR_DATA2, // # of successful Directed Tx's (MSDU) @ 2MB | ||
899 | IPW_ORD_STAT_TX_DIR_DATA5_5, // # of successful Directed Tx's (MSDU) @ 5_5MB | ||
900 | IPW_ORD_STAT_TX_DIR_DATA11, // # of successful Directed Tx's (MSDU) @ 11MB | ||
901 | IPW_ORD_STAT_TX_DIR_DATA22, // # of successful Directed Tx's (MSDU) @ 22MB | ||
902 | |||
903 | IPW_ORD_STAT_TX_NODIR_DATA1 = 13, // # of successful Non_Directed Tx's (MSDU) @ 1MB | ||
904 | IPW_ORD_STAT_TX_NODIR_DATA2, // # of successful Non_Directed Tx's (MSDU) @ 2MB | ||
905 | IPW_ORD_STAT_TX_NODIR_DATA5_5, // # of successful Non_Directed Tx's (MSDU) @ 5.5MB | ||
906 | IPW_ORD_STAT_TX_NODIR_DATA11, // # of successful Non_Directed Tx's (MSDU) @ 11MB | ||
907 | |||
908 | IPW_ORD_STAT_NULL_DATA = 21, // # of successful NULL data Tx's | ||
909 | IPW_ORD_STAT_TX_RTS, // # of successful Tx RTS | ||
910 | IPW_ORD_STAT_TX_CTS, // # of successful Tx CTS | ||
911 | IPW_ORD_STAT_TX_ACK, // # of successful Tx ACK | ||
912 | IPW_ORD_STAT_TX_ASSN, // # of successful Association Tx's | ||
913 | IPW_ORD_STAT_TX_ASSN_RESP, // # of successful Association response Tx's | ||
914 | IPW_ORD_STAT_TX_REASSN, // # of successful Reassociation Tx's | ||
915 | IPW_ORD_STAT_TX_REASSN_RESP, // # of successful Reassociation response Tx's | ||
916 | IPW_ORD_STAT_TX_PROBE, // # of probes successfully transmitted | ||
917 | IPW_ORD_STAT_TX_PROBE_RESP, // # of probe responses successfully transmitted | ||
918 | IPW_ORD_STAT_TX_BEACON, // # of tx beacon | ||
919 | IPW_ORD_STAT_TX_ATIM, // # of Tx ATIM | ||
920 | IPW_ORD_STAT_TX_DISASSN, // # of successful Disassociation TX | ||
921 | IPW_ORD_STAT_TX_AUTH, // # of successful Authentication Tx | ||
922 | IPW_ORD_STAT_TX_DEAUTH, // # of successful Deauthentication TX | ||
923 | |||
924 | IPW_ORD_STAT_TX_TOTAL_BYTES = 41, // Total successful Tx data bytes | ||
925 | IPW_ORD_STAT_TX_RETRIES, // # of Tx retries | ||
926 | IPW_ORD_STAT_TX_RETRY1, // # of Tx retries at 1MBPS | ||
927 | IPW_ORD_STAT_TX_RETRY2, // # of Tx retries at 2MBPS | ||
928 | IPW_ORD_STAT_TX_RETRY5_5, // # of Tx retries at 5.5MBPS | ||
929 | IPW_ORD_STAT_TX_RETRY11, // # of Tx retries at 11MBPS | ||
930 | |||
931 | IPW_ORD_STAT_TX_FAILURES = 51, // # of Tx Failures | ||
932 | IPW_ORD_STAT_TX_ABORT_AT_HOP, //NS // # of Tx's aborted at hop time | ||
933 | IPW_ORD_STAT_TX_MAX_TRIES_IN_HOP, // # of times max tries in a hop failed | ||
934 | IPW_ORD_STAT_TX_ABORT_LATE_DMA, //NS // # of times tx aborted due to late dma setup | ||
935 | IPW_ORD_STAT_TX_ABORT_STX, //NS // # of times backoff aborted | ||
936 | IPW_ORD_STAT_TX_DISASSN_FAIL, // # of times disassociation failed | ||
937 | IPW_ORD_STAT_TX_ERR_CTS, // # of missed/bad CTS frames | ||
938 | IPW_ORD_STAT_TX_BPDU, //NS // # of spanning tree BPDUs sent | ||
939 | IPW_ORD_STAT_TX_ERR_ACK, // # of tx err due to acks | ||
940 | |||
941 | // Receive statistics | ||
942 | IPW_ORD_STAT_RX_HOST = 61, // # of packets passed to host | ||
943 | IPW_ORD_STAT_RX_DIR_DATA, // # of directed packets | ||
944 | IPW_ORD_STAT_RX_DIR_DATA1, // # of directed packets at 1MB | ||
945 | IPW_ORD_STAT_RX_DIR_DATA2, // # of directed packets at 2MB | ||
946 | IPW_ORD_STAT_RX_DIR_DATA5_5, // # of directed packets at 5.5MB | ||
947 | IPW_ORD_STAT_RX_DIR_DATA11, // # of directed packets at 11MB | ||
948 | IPW_ORD_STAT_RX_DIR_DATA22, // # of directed packets at 22MB | ||
949 | |||
950 | IPW_ORD_STAT_RX_NODIR_DATA = 71, // # of nondirected packets | ||
951 | IPW_ORD_STAT_RX_NODIR_DATA1, // # of nondirected packets at 1MB | ||
952 | IPW_ORD_STAT_RX_NODIR_DATA2, // # of nondirected packets at 2MB | ||
953 | IPW_ORD_STAT_RX_NODIR_DATA5_5, // # of nondirected packets at 5.5MB | ||
954 | IPW_ORD_STAT_RX_NODIR_DATA11, // # of nondirected packets at 11MB | ||
955 | |||
956 | IPW_ORD_STAT_RX_NULL_DATA = 80, // # of null data rx's | ||
957 | IPW_ORD_STAT_RX_POLL, //NS // # of poll rx | ||
958 | IPW_ORD_STAT_RX_RTS, // # of Rx RTS | ||
959 | IPW_ORD_STAT_RX_CTS, // # of Rx CTS | ||
960 | IPW_ORD_STAT_RX_ACK, // # of Rx ACK | ||
961 | IPW_ORD_STAT_RX_CFEND, // # of Rx CF End | ||
962 | IPW_ORD_STAT_RX_CFEND_ACK, // # of Rx CF End + CF Ack | ||
963 | IPW_ORD_STAT_RX_ASSN, // # of Association Rx's | ||
964 | IPW_ORD_STAT_RX_ASSN_RESP, // # of Association response Rx's | ||
965 | IPW_ORD_STAT_RX_REASSN, // # of Reassociation Rx's | ||
966 | IPW_ORD_STAT_RX_REASSN_RESP, // # of Reassociation response Rx's | ||
967 | IPW_ORD_STAT_RX_PROBE, // # of probe Rx's | ||
968 | IPW_ORD_STAT_RX_PROBE_RESP, // # of probe response Rx's | ||
969 | IPW_ORD_STAT_RX_BEACON, // # of Rx beacon | ||
970 | IPW_ORD_STAT_RX_ATIM, // # of Rx ATIM | ||
971 | IPW_ORD_STAT_RX_DISASSN, // # of disassociation Rx | ||
972 | IPW_ORD_STAT_RX_AUTH, // # of authentication Rx | ||
973 | IPW_ORD_STAT_RX_DEAUTH, // # of deauthentication Rx | ||
974 | |||
975 | IPW_ORD_STAT_RX_TOTAL_BYTES = 101, // Total rx data bytes received | ||
976 | IPW_ORD_STAT_RX_ERR_CRC, // # of packets with Rx CRC error | ||
977 | IPW_ORD_STAT_RX_ERR_CRC1, // # of Rx CRC errors at 1MB | ||
978 | IPW_ORD_STAT_RX_ERR_CRC2, // # of Rx CRC errors at 2MB | ||
979 | IPW_ORD_STAT_RX_ERR_CRC5_5, // # of Rx CRC errors at 5.5MB | ||
980 | IPW_ORD_STAT_RX_ERR_CRC11, // # of Rx CRC errors at 11MB | ||
981 | |||
982 | IPW_ORD_STAT_RX_DUPLICATE1 = 112, // # of duplicate rx packets at 1MB | ||
983 | IPW_ORD_STAT_RX_DUPLICATE2, // # of duplicate rx packets at 2MB | ||
984 | IPW_ORD_STAT_RX_DUPLICATE5_5, // # of duplicate rx packets at 5.5MB | ||
985 | IPW_ORD_STAT_RX_DUPLICATE11, // # of duplicate rx packets at 11MB | ||
986 | IPW_ORD_STAT_RX_DUPLICATE = 119, // # of duplicate rx packets | ||
987 | |||
988 | IPW_ORD_PERS_DB_LOCK = 120, // # locking fw permanent db | ||
989 | IPW_ORD_PERS_DB_SIZE, // # size of fw permanent db | ||
990 | IPW_ORD_PERS_DB_ADDR, // # address of fw permanent db | ||
991 | IPW_ORD_STAT_RX_INVALID_PROTOCOL, // # of rx frames with invalid protocol | ||
992 | IPW_ORD_SYS_BOOT_TIME, // # Boot time | ||
993 | IPW_ORD_STAT_RX_NO_BUFFER, // # of rx frames rejected due to no buffer | ||
994 | IPW_ORD_STAT_RX_ABORT_LATE_DMA, //NS // # of rx frames rejected due to dma setup too late | ||
995 | IPW_ORD_STAT_RX_ABORT_AT_HOP, //NS // # of rx frames aborted due to hop | ||
996 | IPW_ORD_STAT_RX_MISSING_FRAG, // # of rx frames dropped due to missing fragment | ||
997 | IPW_ORD_STAT_RX_ORPHAN_FRAG, // # of rx frames dropped due to non-sequential fragment | ||
998 | IPW_ORD_STAT_RX_ORPHAN_FRAME, // # of rx frames dropped due to unmatched 1st frame | ||
999 | IPW_ORD_STAT_RX_FRAG_AGEOUT, // # of rx frames dropped due to uncompleted frame | ||
1000 | IPW_ORD_STAT_RX_BAD_SSID, //NS // Bad SSID (unused) | ||
1001 | IPW_ORD_STAT_RX_ICV_ERRORS, // # of ICV errors during decryption | ||
1002 | |||
1003 | // PSP Statistics | ||
1004 | IPW_ORD_STAT_PSP_SUSPENSION = 137, // # of times adapter suspended | ||
1005 | IPW_ORD_STAT_PSP_BCN_TIMEOUT, // # of beacon timeout | ||
1006 | IPW_ORD_STAT_PSP_POLL_TIMEOUT, // # of poll response timeouts | ||
1007 | IPW_ORD_STAT_PSP_NONDIR_TIMEOUT, // # of timeouts waiting for last broadcast/muticast pkt | ||
1008 | IPW_ORD_STAT_PSP_RX_DTIMS, // # of PSP DTIMs received | ||
1009 | IPW_ORD_STAT_PSP_RX_TIMS, // # of PSP TIMs received | ||
1010 | IPW_ORD_STAT_PSP_STATION_ID, // PSP Station ID | ||
1011 | |||
1012 | // Association and roaming | ||
1013 | IPW_ORD_LAST_ASSN_TIME = 147, // RTC time of last association | ||
1014 | IPW_ORD_STAT_PERCENT_MISSED_BCNS, // current calculation of % missed beacons | ||
1015 | IPW_ORD_STAT_PERCENT_RETRIES, // current calculation of % missed tx retries | ||
1016 | IPW_ORD_ASSOCIATED_AP_PTR, // If associated, this is ptr to the associated | ||
1017 | // AP table entry. set to 0 if not associated | ||
1018 | IPW_ORD_AVAILABLE_AP_CNT, // # of AP's decsribed in the AP table | ||
1019 | IPW_ORD_AP_LIST_PTR, // Ptr to list of available APs | ||
1020 | IPW_ORD_STAT_AP_ASSNS, // # of associations | ||
1021 | IPW_ORD_STAT_ASSN_FAIL, // # of association failures | ||
1022 | IPW_ORD_STAT_ASSN_RESP_FAIL, // # of failuresdue to response fail | ||
1023 | IPW_ORD_STAT_FULL_SCANS, // # of full scans | ||
1024 | |||
1025 | IPW_ORD_CARD_DISABLED, // # Card Disabled | ||
1026 | IPW_ORD_STAT_ROAM_INHIBIT, // # of times roaming was inhibited due to ongoing activity | ||
1027 | IPW_FILLER_40, | ||
1028 | IPW_ORD_RSSI_AT_ASSN = 160, // RSSI of associated AP at time of association | ||
1029 | IPW_ORD_STAT_ASSN_CAUSE1, // # of reassociations due to no tx from AP in last N | ||
1030 | // hops or no prob_ responses in last 3 minutes | ||
1031 | IPW_ORD_STAT_ASSN_CAUSE2, // # of reassociations due to poor tx/rx quality | ||
1032 | IPW_ORD_STAT_ASSN_CAUSE3, // # of reassociations due to tx/rx quality with excessive | ||
1033 | // load at the AP | ||
1034 | IPW_ORD_STAT_ASSN_CAUSE4, // # of reassociations due to AP RSSI level fell below | ||
1035 | // eligible group | ||
1036 | IPW_ORD_STAT_ASSN_CAUSE5, // # of reassociations due to load leveling | ||
1037 | IPW_ORD_STAT_ASSN_CAUSE6, //NS // # of reassociations due to dropped by Ap | ||
1038 | IPW_FILLER_41, | ||
1039 | IPW_FILLER_42, | ||
1040 | IPW_FILLER_43, | ||
1041 | IPW_ORD_STAT_AUTH_FAIL, // # of times authentication failed | ||
1042 | IPW_ORD_STAT_AUTH_RESP_FAIL, // # of times authentication response failed | ||
1043 | IPW_ORD_STATION_TABLE_CNT, // # of entries in association table | ||
1044 | |||
1045 | // Other statistics | ||
1046 | IPW_ORD_RSSI_AVG_CURR = 173, // Current avg RSSI | ||
1047 | IPW_ORD_STEST_RESULTS_CURR, //NS // Current self test results word | ||
1048 | IPW_ORD_STEST_RESULTS_CUM, //NS // Cummulative self test results word | ||
1049 | IPW_ORD_SELF_TEST_STATUS, //NS // | ||
1050 | IPW_ORD_POWER_MGMT_MODE, // Power mode - 0=CAM, 1=PSP | ||
1051 | IPW_ORD_POWER_MGMT_INDEX, //NS // | ||
1052 | IPW_ORD_COUNTRY_CODE, // IEEE country code as recv'd from beacon | ||
1053 | IPW_ORD_COUNTRY_CHANNELS, // channels suported by country | ||
1054 | // IPW_ORD_COUNTRY_CHANNELS: | ||
1055 | // For 11b the lower 2-byte are used for channels from 1-14 | ||
1056 | // and the higher 2-byte are not used. | ||
1057 | IPW_ORD_RESET_CNT, // # of adapter resets (warm) | ||
1058 | IPW_ORD_BEACON_INTERVAL, // Beacon interval | ||
1059 | |||
1060 | IPW_ORD_PRINCETON_VERSION = 184, //NS // Princeton Version | ||
1061 | IPW_ORD_ANTENNA_DIVERSITY, // TRUE if antenna diversity is disabled | ||
1062 | IPW_ORD_CCA_RSSI, //NS // CCA RSSI value (factory programmed) | ||
1063 | IPW_ORD_STAT_EEPROM_UPDATE, //NS // # of times config EEPROM updated | ||
1064 | IPW_ORD_DTIM_PERIOD, // # of beacon intervals between DTIMs | ||
1065 | IPW_ORD_OUR_FREQ, // current radio freq lower digits - channel ID | ||
1066 | |||
1067 | IPW_ORD_RTC_TIME = 190, // current RTC time | ||
1068 | IPW_ORD_PORT_TYPE, // operating mode | ||
1069 | IPW_ORD_CURRENT_TX_RATE, // current tx rate | ||
1070 | IPW_ORD_SUPPORTED_RATES, // Bitmap of supported tx rates | ||
1071 | IPW_ORD_ATIM_WINDOW, // current ATIM Window | ||
1072 | IPW_ORD_BASIC_RATES, // bitmap of basic tx rates | ||
1073 | IPW_ORD_NIC_HIGHEST_RATE, // bitmap of basic tx rates | ||
1074 | IPW_ORD_AP_HIGHEST_RATE, // bitmap of basic tx rates | ||
1075 | IPW_ORD_CAPABILITIES, // Management frame capability field | ||
1076 | IPW_ORD_AUTH_TYPE, // Type of authentication | ||
1077 | IPW_ORD_RADIO_TYPE, // Adapter card platform type | ||
1078 | IPW_ORD_RTS_THRESHOLD = 201, // Min length of packet after which RTS handshaking is used | ||
1079 | IPW_ORD_INT_MODE, // International mode | ||
1080 | IPW_ORD_FRAGMENTATION_THRESHOLD, // protocol frag threshold | ||
1081 | IPW_ORD_EEPROM_SRAM_DB_BLOCK_START_ADDRESS, // EEPROM offset in SRAM | ||
1082 | IPW_ORD_EEPROM_SRAM_DB_BLOCK_SIZE, // EEPROM size in SRAM | ||
1083 | IPW_ORD_EEPROM_SKU_CAPABILITY, // EEPROM SKU Capability 206 = | ||
1084 | IPW_ORD_EEPROM_IBSS_11B_CHANNELS, // EEPROM IBSS 11b channel set | ||
1085 | |||
1086 | IPW_ORD_MAC_VERSION = 209, // MAC Version | ||
1087 | IPW_ORD_MAC_REVISION, // MAC Revision | ||
1088 | IPW_ORD_RADIO_VERSION, // Radio Version | ||
1089 | IPW_ORD_NIC_MANF_DATE_TIME, // MANF Date/Time STAMP | ||
1090 | IPW_ORD_UCODE_VERSION, // Ucode Version | ||
1091 | IPW_ORD_HW_RF_SWITCH_STATE = 214, // HW RF Kill Switch State | ||
1092 | } ORDINALTABLE1; | ||
1093 | |||
1094 | // ordinal table 2 | ||
1095 | // Variable length data: | ||
1096 | #define IPW_FIRST_VARIABLE_LENGTH_ORDINAL 1001 | ||
1097 | |||
1098 | typedef enum _ORDINAL_TABLE_2 { // NS - means Not Supported by FW | ||
1099 | IPW_ORD_STAT_BASE = 1000, // contains number of variable ORDs | ||
1100 | IPW_ORD_STAT_ADAPTER_MAC = 1001, // 6 bytes: our adapter MAC address | ||
1101 | IPW_ORD_STAT_PREFERRED_BSSID = 1002, // 6 bytes: BSSID of the preferred AP | ||
1102 | IPW_ORD_STAT_MANDATORY_BSSID = 1003, // 6 bytes: BSSID of the mandatory AP | ||
1103 | IPW_FILL_1, //NS // | ||
1104 | IPW_ORD_STAT_COUNTRY_TEXT = 1005, // 36 bytes: Country name text, First two bytes are Country code | ||
1105 | IPW_ORD_STAT_ASSN_SSID = 1006, // 32 bytes: ESSID String | ||
1106 | IPW_ORD_STATION_TABLE = 1007, // ? bytes: Station/AP table (via Direct SSID Scans) | ||
1107 | IPW_ORD_STAT_SWEEP_TABLE = 1008, // ? bytes: Sweep/Host Table table (via Broadcast Scans) | ||
1108 | IPW_ORD_STAT_ROAM_LOG = 1009, // ? bytes: Roaming log | ||
1109 | IPW_ORD_STAT_RATE_LOG = 1010, //NS // 0 bytes: Rate log | ||
1110 | IPW_ORD_STAT_FIFO = 1011, //NS // 0 bytes: Fifo buffer data structures | ||
1111 | IPW_ORD_STAT_FW_VER_NUM = 1012, // 14 bytes: fw version ID string as in (a.bb.ccc; "0.08.011") | ||
1112 | IPW_ORD_STAT_FW_DATE = 1013, // 14 bytes: fw date string (mmm dd yyyy; "Mar 13 2002") | ||
1113 | IPW_ORD_STAT_ASSN_AP_BSSID = 1014, // 6 bytes: MAC address of associated AP | ||
1114 | IPW_ORD_STAT_DEBUG = 1015, //NS // ? bytes: | ||
1115 | IPW_ORD_STAT_NIC_BPA_NUM = 1016, // 11 bytes: NIC BPA number in ASCII | ||
1116 | IPW_ORD_STAT_UCODE_DATE = 1017, // 5 bytes: uCode date | ||
1117 | IPW_ORD_SECURITY_NGOTIATION_RESULT = 1018, | ||
1118 | } ORDINALTABLE2; // NS - means Not Supported by FW | ||
1119 | |||
1120 | #define IPW_LAST_VARIABLE_LENGTH_ORDINAL 1018 | ||
1121 | |||
1122 | #ifndef WIRELESS_SPY | ||
1123 | #define WIRELESS_SPY // enable iwspy support | ||
1124 | #endif | ||
1125 | |||
1126 | #define IPW_HOST_FW_SHARED_AREA0 0x0002f200 | ||
1127 | #define IPW_HOST_FW_SHARED_AREA0_END 0x0002f510 // 0x310 bytes | ||
1128 | |||
1129 | #define IPW_HOST_FW_SHARED_AREA1 0x0002f610 | ||
1130 | #define IPW_HOST_FW_SHARED_AREA1_END 0x0002f630 // 0x20 bytes | ||
1131 | |||
1132 | #define IPW_HOST_FW_SHARED_AREA2 0x0002fa00 | ||
1133 | #define IPW_HOST_FW_SHARED_AREA2_END 0x0002fa20 // 0x20 bytes | ||
1134 | |||
1135 | #define IPW_HOST_FW_SHARED_AREA3 0x0002fc00 | ||
1136 | #define IPW_HOST_FW_SHARED_AREA3_END 0x0002fc10 // 0x10 bytes | ||
1137 | |||
1138 | #define IPW_HOST_FW_INTERRUPT_AREA 0x0002ff80 | ||
1139 | #define IPW_HOST_FW_INTERRUPT_AREA_END 0x00030000 // 0x80 bytes | ||
1140 | |||
1141 | struct ipw2100_fw_chunk { | ||
1142 | unsigned char *buf; | ||
1143 | long len; | ||
1144 | long pos; | ||
1145 | struct list_head list; | ||
1146 | }; | ||
1147 | |||
1148 | struct ipw2100_fw_chunk_set { | ||
1149 | const void *data; | ||
1150 | unsigned long size; | ||
1151 | }; | ||
1152 | |||
1153 | struct ipw2100_fw { | ||
1154 | int version; | ||
1155 | struct ipw2100_fw_chunk_set fw; | ||
1156 | struct ipw2100_fw_chunk_set uc; | ||
1157 | const struct firmware *fw_entry; | ||
1158 | }; | ||
1159 | |||
1160 | #define MAX_FW_VERSION_LEN 14 | ||
1161 | |||
1162 | #endif /* _IPW2100_H */ | ||
diff --git a/drivers/net/wireless/ipw2x00/ipw2200.c b/drivers/net/wireless/ipw2x00/ipw2200.c new file mode 100644 index 000000000000..d2a2b7586d08 --- /dev/null +++ b/drivers/net/wireless/ipw2x00/ipw2200.c | |||
@@ -0,0 +1,11984 @@ | |||
1 | /****************************************************************************** | ||
2 | |||
3 | Copyright(c) 2003 - 2006 Intel Corporation. All rights reserved. | ||
4 | |||
5 | 802.11 status code portion of this file from ethereal-0.10.6: | ||
6 | Copyright 2000, Axis Communications AB | ||
7 | Ethereal - Network traffic analyzer | ||
8 | By Gerald Combs <gerald@ethereal.com> | ||
9 | Copyright 1998 Gerald Combs | ||
10 | |||
11 | This program is free software; you can redistribute it and/or modify it | ||
12 | under the terms of version 2 of the GNU General Public License as | ||
13 | published by the Free Software Foundation. | ||
14 | |||
15 | This program is distributed in the hope that it will be useful, but WITHOUT | ||
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
17 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
18 | more details. | ||
19 | |||
20 | You should have received a copy of the GNU General Public License along with | ||
21 | this program; if not, write to the Free Software Foundation, Inc., 59 | ||
22 | Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
23 | |||
24 | The full GNU General Public License is included in this distribution in the | ||
25 | file called LICENSE. | ||
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 | ******************************************************************************/ | ||
32 | |||
33 | #include "ipw2200.h" | ||
34 | |||
35 | |||
36 | #ifndef KBUILD_EXTMOD | ||
37 | #define VK "k" | ||
38 | #else | ||
39 | #define VK | ||
40 | #endif | ||
41 | |||
42 | #ifdef CONFIG_IPW2200_DEBUG | ||
43 | #define VD "d" | ||
44 | #else | ||
45 | #define VD | ||
46 | #endif | ||
47 | |||
48 | #ifdef CONFIG_IPW2200_MONITOR | ||
49 | #define VM "m" | ||
50 | #else | ||
51 | #define VM | ||
52 | #endif | ||
53 | |||
54 | #ifdef CONFIG_IPW2200_PROMISCUOUS | ||
55 | #define VP "p" | ||
56 | #else | ||
57 | #define VP | ||
58 | #endif | ||
59 | |||
60 | #ifdef CONFIG_IPW2200_RADIOTAP | ||
61 | #define VR "r" | ||
62 | #else | ||
63 | #define VR | ||
64 | #endif | ||
65 | |||
66 | #ifdef CONFIG_IPW2200_QOS | ||
67 | #define VQ "q" | ||
68 | #else | ||
69 | #define VQ | ||
70 | #endif | ||
71 | |||
72 | #define IPW2200_VERSION "1.2.2" VK VD VM VP VR VQ | ||
73 | #define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2200/2915 Network Driver" | ||
74 | #define DRV_COPYRIGHT "Copyright(c) 2003-2006 Intel Corporation" | ||
75 | #define DRV_VERSION IPW2200_VERSION | ||
76 | |||
77 | #define ETH_P_80211_STATS (ETH_P_80211_RAW + 1) | ||
78 | |||
79 | MODULE_DESCRIPTION(DRV_DESCRIPTION); | ||
80 | MODULE_VERSION(DRV_VERSION); | ||
81 | MODULE_AUTHOR(DRV_COPYRIGHT); | ||
82 | MODULE_LICENSE("GPL"); | ||
83 | |||
84 | static int cmdlog = 0; | ||
85 | static int debug = 0; | ||
86 | static int channel = 0; | ||
87 | static int mode = 0; | ||
88 | |||
89 | static u32 ipw_debug_level; | ||
90 | static int associate; | ||
91 | static int auto_create = 1; | ||
92 | static int led = 0; | ||
93 | static int disable = 0; | ||
94 | static int bt_coexist = 0; | ||
95 | static int hwcrypto = 0; | ||
96 | static int roaming = 1; | ||
97 | static const char ipw_modes[] = { | ||
98 | 'a', 'b', 'g', '?' | ||
99 | }; | ||
100 | static int antenna = CFG_SYS_ANTENNA_BOTH; | ||
101 | |||
102 | #ifdef CONFIG_IPW2200_PROMISCUOUS | ||
103 | static int rtap_iface = 0; /* def: 0 -- do not create rtap interface */ | ||
104 | #endif | ||
105 | |||
106 | |||
107 | #ifdef CONFIG_IPW2200_QOS | ||
108 | static int qos_enable = 0; | ||
109 | static int qos_burst_enable = 0; | ||
110 | static int qos_no_ack_mask = 0; | ||
111 | static int burst_duration_CCK = 0; | ||
112 | static int burst_duration_OFDM = 0; | ||
113 | |||
114 | static struct ieee80211_qos_parameters def_qos_parameters_OFDM = { | ||
115 | {QOS_TX0_CW_MIN_OFDM, QOS_TX1_CW_MIN_OFDM, QOS_TX2_CW_MIN_OFDM, | ||
116 | QOS_TX3_CW_MIN_OFDM}, | ||
117 | {QOS_TX0_CW_MAX_OFDM, QOS_TX1_CW_MAX_OFDM, QOS_TX2_CW_MAX_OFDM, | ||
118 | QOS_TX3_CW_MAX_OFDM}, | ||
119 | {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS}, | ||
120 | {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM}, | ||
121 | {QOS_TX0_TXOP_LIMIT_OFDM, QOS_TX1_TXOP_LIMIT_OFDM, | ||
122 | QOS_TX2_TXOP_LIMIT_OFDM, QOS_TX3_TXOP_LIMIT_OFDM} | ||
123 | }; | ||
124 | |||
125 | static struct ieee80211_qos_parameters def_qos_parameters_CCK = { | ||
126 | {QOS_TX0_CW_MIN_CCK, QOS_TX1_CW_MIN_CCK, QOS_TX2_CW_MIN_CCK, | ||
127 | QOS_TX3_CW_MIN_CCK}, | ||
128 | {QOS_TX0_CW_MAX_CCK, QOS_TX1_CW_MAX_CCK, QOS_TX2_CW_MAX_CCK, | ||
129 | QOS_TX3_CW_MAX_CCK}, | ||
130 | {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS}, | ||
131 | {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM}, | ||
132 | {QOS_TX0_TXOP_LIMIT_CCK, QOS_TX1_TXOP_LIMIT_CCK, QOS_TX2_TXOP_LIMIT_CCK, | ||
133 | QOS_TX3_TXOP_LIMIT_CCK} | ||
134 | }; | ||
135 | |||
136 | static struct ieee80211_qos_parameters def_parameters_OFDM = { | ||
137 | {DEF_TX0_CW_MIN_OFDM, DEF_TX1_CW_MIN_OFDM, DEF_TX2_CW_MIN_OFDM, | ||
138 | DEF_TX3_CW_MIN_OFDM}, | ||
139 | {DEF_TX0_CW_MAX_OFDM, DEF_TX1_CW_MAX_OFDM, DEF_TX2_CW_MAX_OFDM, | ||
140 | DEF_TX3_CW_MAX_OFDM}, | ||
141 | {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS}, | ||
142 | {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM}, | ||
143 | {DEF_TX0_TXOP_LIMIT_OFDM, DEF_TX1_TXOP_LIMIT_OFDM, | ||
144 | DEF_TX2_TXOP_LIMIT_OFDM, DEF_TX3_TXOP_LIMIT_OFDM} | ||
145 | }; | ||
146 | |||
147 | static struct ieee80211_qos_parameters def_parameters_CCK = { | ||
148 | {DEF_TX0_CW_MIN_CCK, DEF_TX1_CW_MIN_CCK, DEF_TX2_CW_MIN_CCK, | ||
149 | DEF_TX3_CW_MIN_CCK}, | ||
150 | {DEF_TX0_CW_MAX_CCK, DEF_TX1_CW_MAX_CCK, DEF_TX2_CW_MAX_CCK, | ||
151 | DEF_TX3_CW_MAX_CCK}, | ||
152 | {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS}, | ||
153 | {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM}, | ||
154 | {DEF_TX0_TXOP_LIMIT_CCK, DEF_TX1_TXOP_LIMIT_CCK, DEF_TX2_TXOP_LIMIT_CCK, | ||
155 | DEF_TX3_TXOP_LIMIT_CCK} | ||
156 | }; | ||
157 | |||
158 | static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 }; | ||
159 | |||
160 | static int from_priority_to_tx_queue[] = { | ||
161 | IPW_TX_QUEUE_1, IPW_TX_QUEUE_2, IPW_TX_QUEUE_2, IPW_TX_QUEUE_1, | ||
162 | IPW_TX_QUEUE_3, IPW_TX_QUEUE_3, IPW_TX_QUEUE_4, IPW_TX_QUEUE_4 | ||
163 | }; | ||
164 | |||
165 | static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv); | ||
166 | |||
167 | static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters | ||
168 | *qos_param); | ||
169 | static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element | ||
170 | *qos_param); | ||
171 | #endif /* CONFIG_IPW2200_QOS */ | ||
172 | |||
173 | static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev); | ||
174 | static void ipw_remove_current_network(struct ipw_priv *priv); | ||
175 | static void ipw_rx(struct ipw_priv *priv); | ||
176 | static int ipw_queue_tx_reclaim(struct ipw_priv *priv, | ||
177 | struct clx2_tx_queue *txq, int qindex); | ||
178 | static int ipw_queue_reset(struct ipw_priv *priv); | ||
179 | |||
180 | static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf, | ||
181 | int len, int sync); | ||
182 | |||
183 | static void ipw_tx_queue_free(struct ipw_priv *); | ||
184 | |||
185 | static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *); | ||
186 | static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *); | ||
187 | static void ipw_rx_queue_replenish(void *); | ||
188 | static int ipw_up(struct ipw_priv *); | ||
189 | static void ipw_bg_up(struct work_struct *work); | ||
190 | static void ipw_down(struct ipw_priv *); | ||
191 | static void ipw_bg_down(struct work_struct *work); | ||
192 | static int ipw_config(struct ipw_priv *); | ||
193 | static int init_supported_rates(struct ipw_priv *priv, | ||
194 | struct ipw_supported_rates *prates); | ||
195 | static void ipw_set_hwcrypto_keys(struct ipw_priv *); | ||
196 | static void ipw_send_wep_keys(struct ipw_priv *, int); | ||
197 | |||
198 | static int snprint_line(char *buf, size_t count, | ||
199 | const u8 * data, u32 len, u32 ofs) | ||
200 | { | ||
201 | int out, i, j, l; | ||
202 | char c; | ||
203 | |||
204 | out = snprintf(buf, count, "%08X", ofs); | ||
205 | |||
206 | for (l = 0, i = 0; i < 2; i++) { | ||
207 | out += snprintf(buf + out, count - out, " "); | ||
208 | for (j = 0; j < 8 && l < len; j++, l++) | ||
209 | out += snprintf(buf + out, count - out, "%02X ", | ||
210 | data[(i * 8 + j)]); | ||
211 | for (; j < 8; j++) | ||
212 | out += snprintf(buf + out, count - out, " "); | ||
213 | } | ||
214 | |||
215 | out += snprintf(buf + out, count - out, " "); | ||
216 | for (l = 0, i = 0; i < 2; i++) { | ||
217 | out += snprintf(buf + out, count - out, " "); | ||
218 | for (j = 0; j < 8 && l < len; j++, l++) { | ||
219 | c = data[(i * 8 + j)]; | ||
220 | if (!isascii(c) || !isprint(c)) | ||
221 | c = '.'; | ||
222 | |||
223 | out += snprintf(buf + out, count - out, "%c", c); | ||
224 | } | ||
225 | |||
226 | for (; j < 8; j++) | ||
227 | out += snprintf(buf + out, count - out, " "); | ||
228 | } | ||
229 | |||
230 | return out; | ||
231 | } | ||
232 | |||
233 | static void printk_buf(int level, const u8 * data, u32 len) | ||
234 | { | ||
235 | char line[81]; | ||
236 | u32 ofs = 0; | ||
237 | if (!(ipw_debug_level & level)) | ||
238 | return; | ||
239 | |||
240 | while (len) { | ||
241 | snprint_line(line, sizeof(line), &data[ofs], | ||
242 | min(len, 16U), ofs); | ||
243 | printk(KERN_DEBUG "%s\n", line); | ||
244 | ofs += 16; | ||
245 | len -= min(len, 16U); | ||
246 | } | ||
247 | } | ||
248 | |||
249 | static int snprintk_buf(u8 * output, size_t size, const u8 * data, size_t len) | ||
250 | { | ||
251 | size_t out = size; | ||
252 | u32 ofs = 0; | ||
253 | int total = 0; | ||
254 | |||
255 | while (size && len) { | ||
256 | out = snprint_line(output, size, &data[ofs], | ||
257 | min_t(size_t, len, 16U), ofs); | ||
258 | |||
259 | ofs += 16; | ||
260 | output += out; | ||
261 | size -= out; | ||
262 | len -= min_t(size_t, len, 16U); | ||
263 | total += out; | ||
264 | } | ||
265 | return total; | ||
266 | } | ||
267 | |||
268 | /* alias for 32-bit indirect read (for SRAM/reg above 4K), with debug wrapper */ | ||
269 | static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg); | ||
270 | #define ipw_read_reg32(a, b) _ipw_read_reg32(a, b) | ||
271 | |||
272 | /* alias for 8-bit indirect read (for SRAM/reg above 4K), with debug wrapper */ | ||
273 | static u8 _ipw_read_reg8(struct ipw_priv *ipw, u32 reg); | ||
274 | #define ipw_read_reg8(a, b) _ipw_read_reg8(a, b) | ||
275 | |||
276 | /* 8-bit indirect write (for SRAM/reg above 4K), with debug wrapper */ | ||
277 | static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value); | ||
278 | static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c) | ||
279 | { | ||
280 | IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__, | ||
281 | __LINE__, (u32) (b), (u32) (c)); | ||
282 | _ipw_write_reg8(a, b, c); | ||
283 | } | ||
284 | |||
285 | /* 16-bit indirect write (for SRAM/reg above 4K), with debug wrapper */ | ||
286 | static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value); | ||
287 | static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c) | ||
288 | { | ||
289 | IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__, | ||
290 | __LINE__, (u32) (b), (u32) (c)); | ||
291 | _ipw_write_reg16(a, b, c); | ||
292 | } | ||
293 | |||
294 | /* 32-bit indirect write (for SRAM/reg above 4K), with debug wrapper */ | ||
295 | static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value); | ||
296 | static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c) | ||
297 | { | ||
298 | IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__, | ||
299 | __LINE__, (u32) (b), (u32) (c)); | ||
300 | _ipw_write_reg32(a, b, c); | ||
301 | } | ||
302 | |||
303 | /* 8-bit direct write (low 4K) */ | ||
304 | #define _ipw_write8(ipw, ofs, val) writeb((val), (ipw)->hw_base + (ofs)) | ||
305 | |||
306 | /* 8-bit direct write (for low 4K of SRAM/regs), with debug wrapper */ | ||
307 | #define ipw_write8(ipw, ofs, val) do { \ | ||
308 | IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \ | ||
309 | _ipw_write8(ipw, ofs, val); \ | ||
310 | } while (0) | ||
311 | |||
312 | /* 16-bit direct write (low 4K) */ | ||
313 | #define _ipw_write16(ipw, ofs, val) writew((val), (ipw)->hw_base + (ofs)) | ||
314 | |||
315 | /* 16-bit direct write (for low 4K of SRAM/regs), with debug wrapper */ | ||
316 | #define ipw_write16(ipw, ofs, val) \ | ||
317 | IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \ | ||
318 | _ipw_write16(ipw, ofs, val) | ||
319 | |||
320 | /* 32-bit direct write (low 4K) */ | ||
321 | #define _ipw_write32(ipw, ofs, val) writel((val), (ipw)->hw_base + (ofs)) | ||
322 | |||
323 | /* 32-bit direct write (for low 4K of SRAM/regs), with debug wrapper */ | ||
324 | #define ipw_write32(ipw, ofs, val) \ | ||
325 | IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \ | ||
326 | _ipw_write32(ipw, ofs, val) | ||
327 | |||
328 | /* 8-bit direct read (low 4K) */ | ||
329 | #define _ipw_read8(ipw, ofs) readb((ipw)->hw_base + (ofs)) | ||
330 | |||
331 | /* 8-bit direct read (low 4K), with debug wrapper */ | ||
332 | static inline u8 __ipw_read8(char *f, u32 l, struct ipw_priv *ipw, u32 ofs) | ||
333 | { | ||
334 | IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", f, l, (u32) (ofs)); | ||
335 | return _ipw_read8(ipw, ofs); | ||
336 | } | ||
337 | |||
338 | /* alias to 8-bit direct read (low 4K of SRAM/regs), with debug wrapper */ | ||
339 | #define ipw_read8(ipw, ofs) __ipw_read8(__FILE__, __LINE__, ipw, ofs) | ||
340 | |||
341 | /* 16-bit direct read (low 4K) */ | ||
342 | #define _ipw_read16(ipw, ofs) readw((ipw)->hw_base + (ofs)) | ||
343 | |||
344 | /* 16-bit direct read (low 4K), with debug wrapper */ | ||
345 | static inline u16 __ipw_read16(char *f, u32 l, struct ipw_priv *ipw, u32 ofs) | ||
346 | { | ||
347 | IPW_DEBUG_IO("%s %d: read_direct16(0x%08X)\n", f, l, (u32) (ofs)); | ||
348 | return _ipw_read16(ipw, ofs); | ||
349 | } | ||
350 | |||
351 | /* alias to 16-bit direct read (low 4K of SRAM/regs), with debug wrapper */ | ||
352 | #define ipw_read16(ipw, ofs) __ipw_read16(__FILE__, __LINE__, ipw, ofs) | ||
353 | |||
354 | /* 32-bit direct read (low 4K) */ | ||
355 | #define _ipw_read32(ipw, ofs) readl((ipw)->hw_base + (ofs)) | ||
356 | |||
357 | /* 32-bit direct read (low 4K), with debug wrapper */ | ||
358 | static inline u32 __ipw_read32(char *f, u32 l, struct ipw_priv *ipw, u32 ofs) | ||
359 | { | ||
360 | IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", f, l, (u32) (ofs)); | ||
361 | return _ipw_read32(ipw, ofs); | ||
362 | } | ||
363 | |||
364 | /* alias to 32-bit direct read (low 4K of SRAM/regs), with debug wrapper */ | ||
365 | #define ipw_read32(ipw, ofs) __ipw_read32(__FILE__, __LINE__, ipw, ofs) | ||
366 | |||
367 | /* multi-byte read (above 4K), with debug wrapper */ | ||
368 | static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int); | ||
369 | static inline void __ipw_read_indirect(const char *f, int l, | ||
370 | struct ipw_priv *a, u32 b, u8 * c, int d) | ||
371 | { | ||
372 | IPW_DEBUG_IO("%s %d: read_indirect(0x%08X) %d bytes\n", f, l, (u32) (b), | ||
373 | d); | ||
374 | _ipw_read_indirect(a, b, c, d); | ||
375 | } | ||
376 | |||
377 | /* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */ | ||
378 | #define ipw_read_indirect(a, b, c, d) __ipw_read_indirect(__FILE__, __LINE__, a, b, c, d) | ||
379 | |||
380 | /* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */ | ||
381 | static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data, | ||
382 | int num); | ||
383 | #define ipw_write_indirect(a, b, c, d) \ | ||
384 | IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \ | ||
385 | _ipw_write_indirect(a, b, c, d) | ||
386 | |||
387 | /* 32-bit indirect write (above 4K) */ | ||
388 | static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value) | ||
389 | { | ||
390 | IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", priv, reg, value); | ||
391 | _ipw_write32(priv, IPW_INDIRECT_ADDR, reg); | ||
392 | _ipw_write32(priv, IPW_INDIRECT_DATA, value); | ||
393 | } | ||
394 | |||
395 | /* 8-bit indirect write (above 4K) */ | ||
396 | static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value) | ||
397 | { | ||
398 | u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */ | ||
399 | u32 dif_len = reg - aligned_addr; | ||
400 | |||
401 | IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value); | ||
402 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); | ||
403 | _ipw_write8(priv, IPW_INDIRECT_DATA + dif_len, value); | ||
404 | } | ||
405 | |||
406 | /* 16-bit indirect write (above 4K) */ | ||
407 | static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value) | ||
408 | { | ||
409 | u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */ | ||
410 | u32 dif_len = (reg - aligned_addr) & (~0x1ul); | ||
411 | |||
412 | IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value); | ||
413 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); | ||
414 | _ipw_write16(priv, IPW_INDIRECT_DATA + dif_len, value); | ||
415 | } | ||
416 | |||
417 | /* 8-bit indirect read (above 4K) */ | ||
418 | static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg) | ||
419 | { | ||
420 | u32 word; | ||
421 | _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK); | ||
422 | IPW_DEBUG_IO(" reg = 0x%8X : \n", reg); | ||
423 | word = _ipw_read32(priv, IPW_INDIRECT_DATA); | ||
424 | return (word >> ((reg & 0x3) * 8)) & 0xff; | ||
425 | } | ||
426 | |||
427 | /* 32-bit indirect read (above 4K) */ | ||
428 | static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg) | ||
429 | { | ||
430 | u32 value; | ||
431 | |||
432 | IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg); | ||
433 | |||
434 | _ipw_write32(priv, IPW_INDIRECT_ADDR, reg); | ||
435 | value = _ipw_read32(priv, IPW_INDIRECT_DATA); | ||
436 | IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x \n", reg, value); | ||
437 | return value; | ||
438 | } | ||
439 | |||
440 | /* General purpose, no alignment requirement, iterative (multi-byte) read, */ | ||
441 | /* for area above 1st 4K of SRAM/reg space */ | ||
442 | static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf, | ||
443 | int num) | ||
444 | { | ||
445 | u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */ | ||
446 | u32 dif_len = addr - aligned_addr; | ||
447 | u32 i; | ||
448 | |||
449 | IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num); | ||
450 | |||
451 | if (num <= 0) { | ||
452 | return; | ||
453 | } | ||
454 | |||
455 | /* Read the first dword (or portion) byte by byte */ | ||
456 | if (unlikely(dif_len)) { | ||
457 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); | ||
458 | /* Start reading at aligned_addr + dif_len */ | ||
459 | for (i = dif_len; ((i < 4) && (num > 0)); i++, num--) | ||
460 | *buf++ = _ipw_read8(priv, IPW_INDIRECT_DATA + i); | ||
461 | aligned_addr += 4; | ||
462 | } | ||
463 | |||
464 | /* Read all of the middle dwords as dwords, with auto-increment */ | ||
465 | _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr); | ||
466 | for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4) | ||
467 | *(u32 *) buf = _ipw_read32(priv, IPW_AUTOINC_DATA); | ||
468 | |||
469 | /* Read the last dword (or portion) byte by byte */ | ||
470 | if (unlikely(num)) { | ||
471 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); | ||
472 | for (i = 0; num > 0; i++, num--) | ||
473 | *buf++ = ipw_read8(priv, IPW_INDIRECT_DATA + i); | ||
474 | } | ||
475 | } | ||
476 | |||
477 | /* General purpose, no alignment requirement, iterative (multi-byte) write, */ | ||
478 | /* for area above 1st 4K of SRAM/reg space */ | ||
479 | static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * buf, | ||
480 | int num) | ||
481 | { | ||
482 | u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */ | ||
483 | u32 dif_len = addr - aligned_addr; | ||
484 | u32 i; | ||
485 | |||
486 | IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num); | ||
487 | |||
488 | if (num <= 0) { | ||
489 | return; | ||
490 | } | ||
491 | |||
492 | /* Write the first dword (or portion) byte by byte */ | ||
493 | if (unlikely(dif_len)) { | ||
494 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); | ||
495 | /* Start writing at aligned_addr + dif_len */ | ||
496 | for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++) | ||
497 | _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf); | ||
498 | aligned_addr += 4; | ||
499 | } | ||
500 | |||
501 | /* Write all of the middle dwords as dwords, with auto-increment */ | ||
502 | _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr); | ||
503 | for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4) | ||
504 | _ipw_write32(priv, IPW_AUTOINC_DATA, *(u32 *) buf); | ||
505 | |||
506 | /* Write the last dword (or portion) byte by byte */ | ||
507 | if (unlikely(num)) { | ||
508 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); | ||
509 | for (i = 0; num > 0; i++, num--, buf++) | ||
510 | _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf); | ||
511 | } | ||
512 | } | ||
513 | |||
514 | /* General purpose, no alignment requirement, iterative (multi-byte) write, */ | ||
515 | /* for 1st 4K of SRAM/regs space */ | ||
516 | static void ipw_write_direct(struct ipw_priv *priv, u32 addr, void *buf, | ||
517 | int num) | ||
518 | { | ||
519 | memcpy_toio((priv->hw_base + addr), buf, num); | ||
520 | } | ||
521 | |||
522 | /* Set bit(s) in low 4K of SRAM/regs */ | ||
523 | static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask) | ||
524 | { | ||
525 | ipw_write32(priv, reg, ipw_read32(priv, reg) | mask); | ||
526 | } | ||
527 | |||
528 | /* Clear bit(s) in low 4K of SRAM/regs */ | ||
529 | static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask) | ||
530 | { | ||
531 | ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask); | ||
532 | } | ||
533 | |||
534 | static inline void __ipw_enable_interrupts(struct ipw_priv *priv) | ||
535 | { | ||
536 | if (priv->status & STATUS_INT_ENABLED) | ||
537 | return; | ||
538 | priv->status |= STATUS_INT_ENABLED; | ||
539 | ipw_write32(priv, IPW_INTA_MASK_R, IPW_INTA_MASK_ALL); | ||
540 | } | ||
541 | |||
542 | static inline void __ipw_disable_interrupts(struct ipw_priv *priv) | ||
543 | { | ||
544 | if (!(priv->status & STATUS_INT_ENABLED)) | ||
545 | return; | ||
546 | priv->status &= ~STATUS_INT_ENABLED; | ||
547 | ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL); | ||
548 | } | ||
549 | |||
550 | static inline void ipw_enable_interrupts(struct ipw_priv *priv) | ||
551 | { | ||
552 | unsigned long flags; | ||
553 | |||
554 | spin_lock_irqsave(&priv->irq_lock, flags); | ||
555 | __ipw_enable_interrupts(priv); | ||
556 | spin_unlock_irqrestore(&priv->irq_lock, flags); | ||
557 | } | ||
558 | |||
559 | static inline void ipw_disable_interrupts(struct ipw_priv *priv) | ||
560 | { | ||
561 | unsigned long flags; | ||
562 | |||
563 | spin_lock_irqsave(&priv->irq_lock, flags); | ||
564 | __ipw_disable_interrupts(priv); | ||
565 | spin_unlock_irqrestore(&priv->irq_lock, flags); | ||
566 | } | ||
567 | |||
568 | static char *ipw_error_desc(u32 val) | ||
569 | { | ||
570 | switch (val) { | ||
571 | case IPW_FW_ERROR_OK: | ||
572 | return "ERROR_OK"; | ||
573 | case IPW_FW_ERROR_FAIL: | ||
574 | return "ERROR_FAIL"; | ||
575 | case IPW_FW_ERROR_MEMORY_UNDERFLOW: | ||
576 | return "MEMORY_UNDERFLOW"; | ||
577 | case IPW_FW_ERROR_MEMORY_OVERFLOW: | ||
578 | return "MEMORY_OVERFLOW"; | ||
579 | case IPW_FW_ERROR_BAD_PARAM: | ||
580 | return "BAD_PARAM"; | ||
581 | case IPW_FW_ERROR_BAD_CHECKSUM: | ||
582 | return "BAD_CHECKSUM"; | ||
583 | case IPW_FW_ERROR_NMI_INTERRUPT: | ||
584 | return "NMI_INTERRUPT"; | ||
585 | case IPW_FW_ERROR_BAD_DATABASE: | ||
586 | return "BAD_DATABASE"; | ||
587 | case IPW_FW_ERROR_ALLOC_FAIL: | ||
588 | return "ALLOC_FAIL"; | ||
589 | case IPW_FW_ERROR_DMA_UNDERRUN: | ||
590 | return "DMA_UNDERRUN"; | ||
591 | case IPW_FW_ERROR_DMA_STATUS: | ||
592 | return "DMA_STATUS"; | ||
593 | case IPW_FW_ERROR_DINO_ERROR: | ||
594 | return "DINO_ERROR"; | ||
595 | case IPW_FW_ERROR_EEPROM_ERROR: | ||
596 | return "EEPROM_ERROR"; | ||
597 | case IPW_FW_ERROR_SYSASSERT: | ||
598 | return "SYSASSERT"; | ||
599 | case IPW_FW_ERROR_FATAL_ERROR: | ||
600 | return "FATAL_ERROR"; | ||
601 | default: | ||
602 | return "UNKNOWN_ERROR"; | ||
603 | } | ||
604 | } | ||
605 | |||
606 | static void ipw_dump_error_log(struct ipw_priv *priv, | ||
607 | struct ipw_fw_error *error) | ||
608 | { | ||
609 | u32 i; | ||
610 | |||
611 | if (!error) { | ||
612 | IPW_ERROR("Error allocating and capturing error log. " | ||
613 | "Nothing to dump.\n"); | ||
614 | return; | ||
615 | } | ||
616 | |||
617 | IPW_ERROR("Start IPW Error Log Dump:\n"); | ||
618 | IPW_ERROR("Status: 0x%08X, Config: %08X\n", | ||
619 | error->status, error->config); | ||
620 | |||
621 | for (i = 0; i < error->elem_len; i++) | ||
622 | IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n", | ||
623 | ipw_error_desc(error->elem[i].desc), | ||
624 | error->elem[i].time, | ||
625 | error->elem[i].blink1, | ||
626 | error->elem[i].blink2, | ||
627 | error->elem[i].link1, | ||
628 | error->elem[i].link2, error->elem[i].data); | ||
629 | for (i = 0; i < error->log_len; i++) | ||
630 | IPW_ERROR("%i\t0x%08x\t%i\n", | ||
631 | error->log[i].time, | ||
632 | error->log[i].data, error->log[i].event); | ||
633 | } | ||
634 | |||
635 | static inline int ipw_is_init(struct ipw_priv *priv) | ||
636 | { | ||
637 | return (priv->status & STATUS_INIT) ? 1 : 0; | ||
638 | } | ||
639 | |||
640 | static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len) | ||
641 | { | ||
642 | u32 addr, field_info, field_len, field_count, total_len; | ||
643 | |||
644 | IPW_DEBUG_ORD("ordinal = %i\n", ord); | ||
645 | |||
646 | if (!priv || !val || !len) { | ||
647 | IPW_DEBUG_ORD("Invalid argument\n"); | ||
648 | return -EINVAL; | ||
649 | } | ||
650 | |||
651 | /* verify device ordinal tables have been initialized */ | ||
652 | if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) { | ||
653 | IPW_DEBUG_ORD("Access ordinals before initialization\n"); | ||
654 | return -EINVAL; | ||
655 | } | ||
656 | |||
657 | switch (IPW_ORD_TABLE_ID_MASK & ord) { | ||
658 | case IPW_ORD_TABLE_0_MASK: | ||
659 | /* | ||
660 | * TABLE 0: Direct access to a table of 32 bit values | ||
661 | * | ||
662 | * This is a very simple table with the data directly | ||
663 | * read from the table | ||
664 | */ | ||
665 | |||
666 | /* remove the table id from the ordinal */ | ||
667 | ord &= IPW_ORD_TABLE_VALUE_MASK; | ||
668 | |||
669 | /* boundary check */ | ||
670 | if (ord > priv->table0_len) { | ||
671 | IPW_DEBUG_ORD("ordinal value (%i) longer then " | ||
672 | "max (%i)\n", ord, priv->table0_len); | ||
673 | return -EINVAL; | ||
674 | } | ||
675 | |||
676 | /* verify we have enough room to store the value */ | ||
677 | if (*len < sizeof(u32)) { | ||
678 | IPW_DEBUG_ORD("ordinal buffer length too small, " | ||
679 | "need %zd\n", sizeof(u32)); | ||
680 | return -EINVAL; | ||
681 | } | ||
682 | |||
683 | IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n", | ||
684 | ord, priv->table0_addr + (ord << 2)); | ||
685 | |||
686 | *len = sizeof(u32); | ||
687 | ord <<= 2; | ||
688 | *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord); | ||
689 | break; | ||
690 | |||
691 | case IPW_ORD_TABLE_1_MASK: | ||
692 | /* | ||
693 | * TABLE 1: Indirect access to a table of 32 bit values | ||
694 | * | ||
695 | * This is a fairly large table of u32 values each | ||
696 | * representing starting addr for the data (which is | ||
697 | * also a u32) | ||
698 | */ | ||
699 | |||
700 | /* remove the table id from the ordinal */ | ||
701 | ord &= IPW_ORD_TABLE_VALUE_MASK; | ||
702 | |||
703 | /* boundary check */ | ||
704 | if (ord > priv->table1_len) { | ||
705 | IPW_DEBUG_ORD("ordinal value too long\n"); | ||
706 | return -EINVAL; | ||
707 | } | ||
708 | |||
709 | /* verify we have enough room to store the value */ | ||
710 | if (*len < sizeof(u32)) { | ||
711 | IPW_DEBUG_ORD("ordinal buffer length too small, " | ||
712 | "need %zd\n", sizeof(u32)); | ||
713 | return -EINVAL; | ||
714 | } | ||
715 | |||
716 | *((u32 *) val) = | ||
717 | ipw_read_reg32(priv, (priv->table1_addr + (ord << 2))); | ||
718 | *len = sizeof(u32); | ||
719 | break; | ||
720 | |||
721 | case IPW_ORD_TABLE_2_MASK: | ||
722 | /* | ||
723 | * TABLE 2: Indirect access to a table of variable sized values | ||
724 | * | ||
725 | * This table consist of six values, each containing | ||
726 | * - dword containing the starting offset of the data | ||
727 | * - dword containing the lengh in the first 16bits | ||
728 | * and the count in the second 16bits | ||
729 | */ | ||
730 | |||
731 | /* remove the table id from the ordinal */ | ||
732 | ord &= IPW_ORD_TABLE_VALUE_MASK; | ||
733 | |||
734 | /* boundary check */ | ||
735 | if (ord > priv->table2_len) { | ||
736 | IPW_DEBUG_ORD("ordinal value too long\n"); | ||
737 | return -EINVAL; | ||
738 | } | ||
739 | |||
740 | /* get the address of statistic */ | ||
741 | addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3)); | ||
742 | |||
743 | /* get the second DW of statistics ; | ||
744 | * two 16-bit words - first is length, second is count */ | ||
745 | field_info = | ||
746 | ipw_read_reg32(priv, | ||
747 | priv->table2_addr + (ord << 3) + | ||
748 | sizeof(u32)); | ||
749 | |||
750 | /* get each entry length */ | ||
751 | field_len = *((u16 *) & field_info); | ||
752 | |||
753 | /* get number of entries */ | ||
754 | field_count = *(((u16 *) & field_info) + 1); | ||
755 | |||
756 | /* abort if not enought memory */ | ||
757 | total_len = field_len * field_count; | ||
758 | if (total_len > *len) { | ||
759 | *len = total_len; | ||
760 | return -EINVAL; | ||
761 | } | ||
762 | |||
763 | *len = total_len; | ||
764 | if (!total_len) | ||
765 | return 0; | ||
766 | |||
767 | IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, " | ||
768 | "field_info = 0x%08x\n", | ||
769 | addr, total_len, field_info); | ||
770 | ipw_read_indirect(priv, addr, val, total_len); | ||
771 | break; | ||
772 | |||
773 | default: | ||
774 | IPW_DEBUG_ORD("Invalid ordinal!\n"); | ||
775 | return -EINVAL; | ||
776 | |||
777 | } | ||
778 | |||
779 | return 0; | ||
780 | } | ||
781 | |||
782 | static void ipw_init_ordinals(struct ipw_priv *priv) | ||
783 | { | ||
784 | priv->table0_addr = IPW_ORDINALS_TABLE_LOWER; | ||
785 | priv->table0_len = ipw_read32(priv, priv->table0_addr); | ||
786 | |||
787 | IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n", | ||
788 | priv->table0_addr, priv->table0_len); | ||
789 | |||
790 | priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1); | ||
791 | priv->table1_len = ipw_read_reg32(priv, priv->table1_addr); | ||
792 | |||
793 | IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n", | ||
794 | priv->table1_addr, priv->table1_len); | ||
795 | |||
796 | priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2); | ||
797 | priv->table2_len = ipw_read_reg32(priv, priv->table2_addr); | ||
798 | priv->table2_len &= 0x0000ffff; /* use first two bytes */ | ||
799 | |||
800 | IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n", | ||
801 | priv->table2_addr, priv->table2_len); | ||
802 | |||
803 | } | ||
804 | |||
805 | static u32 ipw_register_toggle(u32 reg) | ||
806 | { | ||
807 | reg &= ~IPW_START_STANDBY; | ||
808 | if (reg & IPW_GATE_ODMA) | ||
809 | reg &= ~IPW_GATE_ODMA; | ||
810 | if (reg & IPW_GATE_IDMA) | ||
811 | reg &= ~IPW_GATE_IDMA; | ||
812 | if (reg & IPW_GATE_ADMA) | ||
813 | reg &= ~IPW_GATE_ADMA; | ||
814 | return reg; | ||
815 | } | ||
816 | |||
817 | /* | ||
818 | * LED behavior: | ||
819 | * - On radio ON, turn on any LEDs that require to be on during start | ||
820 | * - On initialization, start unassociated blink | ||
821 | * - On association, disable unassociated blink | ||
822 | * - On disassociation, start unassociated blink | ||
823 | * - On radio OFF, turn off any LEDs started during radio on | ||
824 | * | ||
825 | */ | ||
826 | #define LD_TIME_LINK_ON msecs_to_jiffies(300) | ||
827 | #define LD_TIME_LINK_OFF msecs_to_jiffies(2700) | ||
828 | #define LD_TIME_ACT_ON msecs_to_jiffies(250) | ||
829 | |||
830 | static void ipw_led_link_on(struct ipw_priv *priv) | ||
831 | { | ||
832 | unsigned long flags; | ||
833 | u32 led; | ||
834 | |||
835 | /* If configured to not use LEDs, or nic_type is 1, | ||
836 | * then we don't toggle a LINK led */ | ||
837 | if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1) | ||
838 | return; | ||
839 | |||
840 | spin_lock_irqsave(&priv->lock, flags); | ||
841 | |||
842 | if (!(priv->status & STATUS_RF_KILL_MASK) && | ||
843 | !(priv->status & STATUS_LED_LINK_ON)) { | ||
844 | IPW_DEBUG_LED("Link LED On\n"); | ||
845 | led = ipw_read_reg32(priv, IPW_EVENT_REG); | ||
846 | led |= priv->led_association_on; | ||
847 | |||
848 | led = ipw_register_toggle(led); | ||
849 | |||
850 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); | ||
851 | ipw_write_reg32(priv, IPW_EVENT_REG, led); | ||
852 | |||
853 | priv->status |= STATUS_LED_LINK_ON; | ||
854 | |||
855 | /* If we aren't associated, schedule turning the LED off */ | ||
856 | if (!(priv->status & STATUS_ASSOCIATED)) | ||
857 | queue_delayed_work(priv->workqueue, | ||
858 | &priv->led_link_off, | ||
859 | LD_TIME_LINK_ON); | ||
860 | } | ||
861 | |||
862 | spin_unlock_irqrestore(&priv->lock, flags); | ||
863 | } | ||
864 | |||
865 | static void ipw_bg_led_link_on(struct work_struct *work) | ||
866 | { | ||
867 | struct ipw_priv *priv = | ||
868 | container_of(work, struct ipw_priv, led_link_on.work); | ||
869 | mutex_lock(&priv->mutex); | ||
870 | ipw_led_link_on(priv); | ||
871 | mutex_unlock(&priv->mutex); | ||
872 | } | ||
873 | |||
874 | static void ipw_led_link_off(struct ipw_priv *priv) | ||
875 | { | ||
876 | unsigned long flags; | ||
877 | u32 led; | ||
878 | |||
879 | /* If configured not to use LEDs, or nic type is 1, | ||
880 | * then we don't goggle the LINK led. */ | ||
881 | if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1) | ||
882 | return; | ||
883 | |||
884 | spin_lock_irqsave(&priv->lock, flags); | ||
885 | |||
886 | if (priv->status & STATUS_LED_LINK_ON) { | ||
887 | led = ipw_read_reg32(priv, IPW_EVENT_REG); | ||
888 | led &= priv->led_association_off; | ||
889 | led = ipw_register_toggle(led); | ||
890 | |||
891 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); | ||
892 | ipw_write_reg32(priv, IPW_EVENT_REG, led); | ||
893 | |||
894 | IPW_DEBUG_LED("Link LED Off\n"); | ||
895 | |||
896 | priv->status &= ~STATUS_LED_LINK_ON; | ||
897 | |||
898 | /* If we aren't associated and the radio is on, schedule | ||
899 | * turning the LED on (blink while unassociated) */ | ||
900 | if (!(priv->status & STATUS_RF_KILL_MASK) && | ||
901 | !(priv->status & STATUS_ASSOCIATED)) | ||
902 | queue_delayed_work(priv->workqueue, &priv->led_link_on, | ||
903 | LD_TIME_LINK_OFF); | ||
904 | |||
905 | } | ||
906 | |||
907 | spin_unlock_irqrestore(&priv->lock, flags); | ||
908 | } | ||
909 | |||
910 | static void ipw_bg_led_link_off(struct work_struct *work) | ||
911 | { | ||
912 | struct ipw_priv *priv = | ||
913 | container_of(work, struct ipw_priv, led_link_off.work); | ||
914 | mutex_lock(&priv->mutex); | ||
915 | ipw_led_link_off(priv); | ||
916 | mutex_unlock(&priv->mutex); | ||
917 | } | ||
918 | |||
919 | static void __ipw_led_activity_on(struct ipw_priv *priv) | ||
920 | { | ||
921 | u32 led; | ||
922 | |||
923 | if (priv->config & CFG_NO_LED) | ||
924 | return; | ||
925 | |||
926 | if (priv->status & STATUS_RF_KILL_MASK) | ||
927 | return; | ||
928 | |||
929 | if (!(priv->status & STATUS_LED_ACT_ON)) { | ||
930 | led = ipw_read_reg32(priv, IPW_EVENT_REG); | ||
931 | led |= priv->led_activity_on; | ||
932 | |||
933 | led = ipw_register_toggle(led); | ||
934 | |||
935 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); | ||
936 | ipw_write_reg32(priv, IPW_EVENT_REG, led); | ||
937 | |||
938 | IPW_DEBUG_LED("Activity LED On\n"); | ||
939 | |||
940 | priv->status |= STATUS_LED_ACT_ON; | ||
941 | |||
942 | cancel_delayed_work(&priv->led_act_off); | ||
943 | queue_delayed_work(priv->workqueue, &priv->led_act_off, | ||
944 | LD_TIME_ACT_ON); | ||
945 | } else { | ||
946 | /* Reschedule LED off for full time period */ | ||
947 | cancel_delayed_work(&priv->led_act_off); | ||
948 | queue_delayed_work(priv->workqueue, &priv->led_act_off, | ||
949 | LD_TIME_ACT_ON); | ||
950 | } | ||
951 | } | ||
952 | |||
953 | #if 0 | ||
954 | void ipw_led_activity_on(struct ipw_priv *priv) | ||
955 | { | ||
956 | unsigned long flags; | ||
957 | spin_lock_irqsave(&priv->lock, flags); | ||
958 | __ipw_led_activity_on(priv); | ||
959 | spin_unlock_irqrestore(&priv->lock, flags); | ||
960 | } | ||
961 | #endif /* 0 */ | ||
962 | |||
963 | static void ipw_led_activity_off(struct ipw_priv *priv) | ||
964 | { | ||
965 | unsigned long flags; | ||
966 | u32 led; | ||
967 | |||
968 | if (priv->config & CFG_NO_LED) | ||
969 | return; | ||
970 | |||
971 | spin_lock_irqsave(&priv->lock, flags); | ||
972 | |||
973 | if (priv->status & STATUS_LED_ACT_ON) { | ||
974 | led = ipw_read_reg32(priv, IPW_EVENT_REG); | ||
975 | led &= priv->led_activity_off; | ||
976 | |||
977 | led = ipw_register_toggle(led); | ||
978 | |||
979 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); | ||
980 | ipw_write_reg32(priv, IPW_EVENT_REG, led); | ||
981 | |||
982 | IPW_DEBUG_LED("Activity LED Off\n"); | ||
983 | |||
984 | priv->status &= ~STATUS_LED_ACT_ON; | ||
985 | } | ||
986 | |||
987 | spin_unlock_irqrestore(&priv->lock, flags); | ||
988 | } | ||
989 | |||
990 | static void ipw_bg_led_activity_off(struct work_struct *work) | ||
991 | { | ||
992 | struct ipw_priv *priv = | ||
993 | container_of(work, struct ipw_priv, led_act_off.work); | ||
994 | mutex_lock(&priv->mutex); | ||
995 | ipw_led_activity_off(priv); | ||
996 | mutex_unlock(&priv->mutex); | ||
997 | } | ||
998 | |||
999 | static void ipw_led_band_on(struct ipw_priv *priv) | ||
1000 | { | ||
1001 | unsigned long flags; | ||
1002 | u32 led; | ||
1003 | |||
1004 | /* Only nic type 1 supports mode LEDs */ | ||
1005 | if (priv->config & CFG_NO_LED || | ||
1006 | priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network) | ||
1007 | return; | ||
1008 | |||
1009 | spin_lock_irqsave(&priv->lock, flags); | ||
1010 | |||
1011 | led = ipw_read_reg32(priv, IPW_EVENT_REG); | ||
1012 | if (priv->assoc_network->mode == IEEE_A) { | ||
1013 | led |= priv->led_ofdm_on; | ||
1014 | led &= priv->led_association_off; | ||
1015 | IPW_DEBUG_LED("Mode LED On: 802.11a\n"); | ||
1016 | } else if (priv->assoc_network->mode == IEEE_G) { | ||
1017 | led |= priv->led_ofdm_on; | ||
1018 | led |= priv->led_association_on; | ||
1019 | IPW_DEBUG_LED("Mode LED On: 802.11g\n"); | ||
1020 | } else { | ||
1021 | led &= priv->led_ofdm_off; | ||
1022 | led |= priv->led_association_on; | ||
1023 | IPW_DEBUG_LED("Mode LED On: 802.11b\n"); | ||
1024 | } | ||
1025 | |||
1026 | led = ipw_register_toggle(led); | ||
1027 | |||
1028 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); | ||
1029 | ipw_write_reg32(priv, IPW_EVENT_REG, led); | ||
1030 | |||
1031 | spin_unlock_irqrestore(&priv->lock, flags); | ||
1032 | } | ||
1033 | |||
1034 | static void ipw_led_band_off(struct ipw_priv *priv) | ||
1035 | { | ||
1036 | unsigned long flags; | ||
1037 | u32 led; | ||
1038 | |||
1039 | /* Only nic type 1 supports mode LEDs */ | ||
1040 | if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1) | ||
1041 | return; | ||
1042 | |||
1043 | spin_lock_irqsave(&priv->lock, flags); | ||
1044 | |||
1045 | led = ipw_read_reg32(priv, IPW_EVENT_REG); | ||
1046 | led &= priv->led_ofdm_off; | ||
1047 | led &= priv->led_association_off; | ||
1048 | |||
1049 | led = ipw_register_toggle(led); | ||
1050 | |||
1051 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); | ||
1052 | ipw_write_reg32(priv, IPW_EVENT_REG, led); | ||
1053 | |||
1054 | spin_unlock_irqrestore(&priv->lock, flags); | ||
1055 | } | ||
1056 | |||
1057 | static void ipw_led_radio_on(struct ipw_priv *priv) | ||
1058 | { | ||
1059 | ipw_led_link_on(priv); | ||
1060 | } | ||
1061 | |||
1062 | static void ipw_led_radio_off(struct ipw_priv *priv) | ||
1063 | { | ||
1064 | ipw_led_activity_off(priv); | ||
1065 | ipw_led_link_off(priv); | ||
1066 | } | ||
1067 | |||
1068 | static void ipw_led_link_up(struct ipw_priv *priv) | ||
1069 | { | ||
1070 | /* Set the Link Led on for all nic types */ | ||
1071 | ipw_led_link_on(priv); | ||
1072 | } | ||
1073 | |||
1074 | static void ipw_led_link_down(struct ipw_priv *priv) | ||
1075 | { | ||
1076 | ipw_led_activity_off(priv); | ||
1077 | ipw_led_link_off(priv); | ||
1078 | |||
1079 | if (priv->status & STATUS_RF_KILL_MASK) | ||
1080 | ipw_led_radio_off(priv); | ||
1081 | } | ||
1082 | |||
1083 | static void ipw_led_init(struct ipw_priv *priv) | ||
1084 | { | ||
1085 | priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE]; | ||
1086 | |||
1087 | /* Set the default PINs for the link and activity leds */ | ||
1088 | priv->led_activity_on = IPW_ACTIVITY_LED; | ||
1089 | priv->led_activity_off = ~(IPW_ACTIVITY_LED); | ||
1090 | |||
1091 | priv->led_association_on = IPW_ASSOCIATED_LED; | ||
1092 | priv->led_association_off = ~(IPW_ASSOCIATED_LED); | ||
1093 | |||
1094 | /* Set the default PINs for the OFDM leds */ | ||
1095 | priv->led_ofdm_on = IPW_OFDM_LED; | ||
1096 | priv->led_ofdm_off = ~(IPW_OFDM_LED); | ||
1097 | |||
1098 | switch (priv->nic_type) { | ||
1099 | case EEPROM_NIC_TYPE_1: | ||
1100 | /* In this NIC type, the LEDs are reversed.... */ | ||
1101 | priv->led_activity_on = IPW_ASSOCIATED_LED; | ||
1102 | priv->led_activity_off = ~(IPW_ASSOCIATED_LED); | ||
1103 | priv->led_association_on = IPW_ACTIVITY_LED; | ||
1104 | priv->led_association_off = ~(IPW_ACTIVITY_LED); | ||
1105 | |||
1106 | if (!(priv->config & CFG_NO_LED)) | ||
1107 | ipw_led_band_on(priv); | ||
1108 | |||
1109 | /* And we don't blink link LEDs for this nic, so | ||
1110 | * just return here */ | ||
1111 | return; | ||
1112 | |||
1113 | case EEPROM_NIC_TYPE_3: | ||
1114 | case EEPROM_NIC_TYPE_2: | ||
1115 | case EEPROM_NIC_TYPE_4: | ||
1116 | case EEPROM_NIC_TYPE_0: | ||
1117 | break; | ||
1118 | |||
1119 | default: | ||
1120 | IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n", | ||
1121 | priv->nic_type); | ||
1122 | priv->nic_type = EEPROM_NIC_TYPE_0; | ||
1123 | break; | ||
1124 | } | ||
1125 | |||
1126 | if (!(priv->config & CFG_NO_LED)) { | ||
1127 | if (priv->status & STATUS_ASSOCIATED) | ||
1128 | ipw_led_link_on(priv); | ||
1129 | else | ||
1130 | ipw_led_link_off(priv); | ||
1131 | } | ||
1132 | } | ||
1133 | |||
1134 | static void ipw_led_shutdown(struct ipw_priv *priv) | ||
1135 | { | ||
1136 | ipw_led_activity_off(priv); | ||
1137 | ipw_led_link_off(priv); | ||
1138 | ipw_led_band_off(priv); | ||
1139 | cancel_delayed_work(&priv->led_link_on); | ||
1140 | cancel_delayed_work(&priv->led_link_off); | ||
1141 | cancel_delayed_work(&priv->led_act_off); | ||
1142 | } | ||
1143 | |||
1144 | /* | ||
1145 | * The following adds a new attribute to the sysfs representation | ||
1146 | * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/) | ||
1147 | * used for controling the debug level. | ||
1148 | * | ||
1149 | * See the level definitions in ipw for details. | ||
1150 | */ | ||
1151 | static ssize_t show_debug_level(struct device_driver *d, char *buf) | ||
1152 | { | ||
1153 | return sprintf(buf, "0x%08X\n", ipw_debug_level); | ||
1154 | } | ||
1155 | |||
1156 | static ssize_t store_debug_level(struct device_driver *d, const char *buf, | ||
1157 | size_t count) | ||
1158 | { | ||
1159 | char *p = (char *)buf; | ||
1160 | u32 val; | ||
1161 | |||
1162 | if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') { | ||
1163 | p++; | ||
1164 | if (p[0] == 'x' || p[0] == 'X') | ||
1165 | p++; | ||
1166 | val = simple_strtoul(p, &p, 16); | ||
1167 | } else | ||
1168 | val = simple_strtoul(p, &p, 10); | ||
1169 | if (p == buf) | ||
1170 | printk(KERN_INFO DRV_NAME | ||
1171 | ": %s is not in hex or decimal form.\n", buf); | ||
1172 | else | ||
1173 | ipw_debug_level = val; | ||
1174 | |||
1175 | return strnlen(buf, count); | ||
1176 | } | ||
1177 | |||
1178 | static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, | ||
1179 | show_debug_level, store_debug_level); | ||
1180 | |||
1181 | static inline u32 ipw_get_event_log_len(struct ipw_priv *priv) | ||
1182 | { | ||
1183 | /* length = 1st dword in log */ | ||
1184 | return ipw_read_reg32(priv, ipw_read32(priv, IPW_EVENT_LOG)); | ||
1185 | } | ||
1186 | |||
1187 | static void ipw_capture_event_log(struct ipw_priv *priv, | ||
1188 | u32 log_len, struct ipw_event *log) | ||
1189 | { | ||
1190 | u32 base; | ||
1191 | |||
1192 | if (log_len) { | ||
1193 | base = ipw_read32(priv, IPW_EVENT_LOG); | ||
1194 | ipw_read_indirect(priv, base + sizeof(base) + sizeof(u32), | ||
1195 | (u8 *) log, sizeof(*log) * log_len); | ||
1196 | } | ||
1197 | } | ||
1198 | |||
1199 | static struct ipw_fw_error *ipw_alloc_error_log(struct ipw_priv *priv) | ||
1200 | { | ||
1201 | struct ipw_fw_error *error; | ||
1202 | u32 log_len = ipw_get_event_log_len(priv); | ||
1203 | u32 base = ipw_read32(priv, IPW_ERROR_LOG); | ||
1204 | u32 elem_len = ipw_read_reg32(priv, base); | ||
1205 | |||
1206 | error = kmalloc(sizeof(*error) + | ||
1207 | sizeof(*error->elem) * elem_len + | ||
1208 | sizeof(*error->log) * log_len, GFP_ATOMIC); | ||
1209 | if (!error) { | ||
1210 | IPW_ERROR("Memory allocation for firmware error log " | ||
1211 | "failed.\n"); | ||
1212 | return NULL; | ||
1213 | } | ||
1214 | error->jiffies = jiffies; | ||
1215 | error->status = priv->status; | ||
1216 | error->config = priv->config; | ||
1217 | error->elem_len = elem_len; | ||
1218 | error->log_len = log_len; | ||
1219 | error->elem = (struct ipw_error_elem *)error->payload; | ||
1220 | error->log = (struct ipw_event *)(error->elem + elem_len); | ||
1221 | |||
1222 | ipw_capture_event_log(priv, log_len, error->log); | ||
1223 | |||
1224 | if (elem_len) | ||
1225 | ipw_read_indirect(priv, base + sizeof(base), (u8 *) error->elem, | ||
1226 | sizeof(*error->elem) * elem_len); | ||
1227 | |||
1228 | return error; | ||
1229 | } | ||
1230 | |||
1231 | static ssize_t show_event_log(struct device *d, | ||
1232 | struct device_attribute *attr, char *buf) | ||
1233 | { | ||
1234 | struct ipw_priv *priv = dev_get_drvdata(d); | ||
1235 | u32 log_len = ipw_get_event_log_len(priv); | ||
1236 | u32 log_size; | ||
1237 | struct ipw_event *log; | ||
1238 | u32 len = 0, i; | ||
1239 | |||
1240 | /* not using min() because of its strict type checking */ | ||
1241 | log_size = PAGE_SIZE / sizeof(*log) > log_len ? | ||
1242 | sizeof(*log) * log_len : PAGE_SIZE; | ||
1243 | log = kzalloc(log_size, GFP_KERNEL); | ||
1244 | if (!log) { | ||
1245 | IPW_ERROR("Unable to allocate memory for log\n"); | ||
1246 | return 0; | ||
1247 | } | ||
1248 | log_len = log_size / sizeof(*log); | ||
1249 | ipw_capture_event_log(priv, log_len, log); | ||
1250 | |||
1251 | len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len); | ||
1252 | for (i = 0; i < log_len; i++) | ||
1253 | len += snprintf(buf + len, PAGE_SIZE - len, | ||
1254 | "\n%08X%08X%08X", | ||
1255 | log[i].time, log[i].event, log[i].data); | ||
1256 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); | ||
1257 | kfree(log); | ||
1258 | return len; | ||
1259 | } | ||
1260 | |||
1261 | static DEVICE_ATTR(event_log, S_IRUGO, show_event_log, NULL); | ||
1262 | |||
1263 | static ssize_t show_error(struct device *d, | ||
1264 | struct device_attribute *attr, char *buf) | ||
1265 | { | ||
1266 | struct ipw_priv *priv = dev_get_drvdata(d); | ||
1267 | u32 len = 0, i; | ||
1268 | if (!priv->error) | ||
1269 | return 0; | ||
1270 | len += snprintf(buf + len, PAGE_SIZE - len, | ||
1271 | "%08lX%08X%08X%08X", | ||
1272 | priv->error->jiffies, | ||
1273 | priv->error->status, | ||
1274 | priv->error->config, priv->error->elem_len); | ||
1275 | for (i = 0; i < priv->error->elem_len; i++) | ||
1276 | len += snprintf(buf + len, PAGE_SIZE - len, | ||
1277 | "\n%08X%08X%08X%08X%08X%08X%08X", | ||
1278 | priv->error->elem[i].time, | ||
1279 | priv->error->elem[i].desc, | ||
1280 | priv->error->elem[i].blink1, | ||
1281 | priv->error->elem[i].blink2, | ||
1282 | priv->error->elem[i].link1, | ||
1283 | priv->error->elem[i].link2, | ||
1284 | priv->error->elem[i].data); | ||
1285 | |||
1286 | len += snprintf(buf + len, PAGE_SIZE - len, | ||
1287 | "\n%08X", priv->error->log_len); | ||
1288 | for (i = 0; i < priv->error->log_len; i++) | ||
1289 | len += snprintf(buf + len, PAGE_SIZE - len, | ||
1290 | "\n%08X%08X%08X", | ||
1291 | priv->error->log[i].time, | ||
1292 | priv->error->log[i].event, | ||
1293 | priv->error->log[i].data); | ||
1294 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); | ||
1295 | return len; | ||
1296 | } | ||
1297 | |||
1298 | static ssize_t clear_error(struct device *d, | ||
1299 | struct device_attribute *attr, | ||
1300 | const char *buf, size_t count) | ||
1301 | { | ||
1302 | struct ipw_priv *priv = dev_get_drvdata(d); | ||
1303 | |||
1304 | kfree(priv->error); | ||
1305 | priv->error = NULL; | ||
1306 | return count; | ||
1307 | } | ||
1308 | |||
1309 | static DEVICE_ATTR(error, S_IRUGO | S_IWUSR, show_error, clear_error); | ||
1310 | |||
1311 | static ssize_t show_cmd_log(struct device *d, | ||
1312 | struct device_attribute *attr, char *buf) | ||
1313 | { | ||
1314 | struct ipw_priv *priv = dev_get_drvdata(d); | ||
1315 | u32 len = 0, i; | ||
1316 | if (!priv->cmdlog) | ||
1317 | return 0; | ||
1318 | for (i = (priv->cmdlog_pos + 1) % priv->cmdlog_len; | ||
1319 | (i != priv->cmdlog_pos) && (PAGE_SIZE - len); | ||
1320 | i = (i + 1) % priv->cmdlog_len) { | ||
1321 | len += | ||
1322 | snprintf(buf + len, PAGE_SIZE - len, | ||
1323 | "\n%08lX%08X%08X%08X\n", priv->cmdlog[i].jiffies, | ||
1324 | priv->cmdlog[i].retcode, priv->cmdlog[i].cmd.cmd, | ||
1325 | priv->cmdlog[i].cmd.len); | ||
1326 | len += | ||
1327 | snprintk_buf(buf + len, PAGE_SIZE - len, | ||
1328 | (u8 *) priv->cmdlog[i].cmd.param, | ||
1329 | priv->cmdlog[i].cmd.len); | ||
1330 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); | ||
1331 | } | ||
1332 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); | ||
1333 | return len; | ||
1334 | } | ||
1335 | |||
1336 | static DEVICE_ATTR(cmd_log, S_IRUGO, show_cmd_log, NULL); | ||
1337 | |||
1338 | #ifdef CONFIG_IPW2200_PROMISCUOUS | ||
1339 | static void ipw_prom_free(struct ipw_priv *priv); | ||
1340 | static int ipw_prom_alloc(struct ipw_priv *priv); | ||
1341 | static ssize_t store_rtap_iface(struct device *d, | ||
1342 | struct device_attribute *attr, | ||
1343 | const char *buf, size_t count) | ||
1344 | { | ||
1345 | struct ipw_priv *priv = dev_get_drvdata(d); | ||
1346 | int rc = 0; | ||
1347 | |||
1348 | if (count < 1) | ||
1349 | return -EINVAL; | ||
1350 | |||
1351 | switch (buf[0]) { | ||
1352 | case '0': | ||
1353 | if (!rtap_iface) | ||
1354 | return count; | ||
1355 | |||
1356 | if (netif_running(priv->prom_net_dev)) { | ||
1357 | IPW_WARNING("Interface is up. Cannot unregister.\n"); | ||
1358 | return count; | ||
1359 | } | ||
1360 | |||
1361 | ipw_prom_free(priv); | ||
1362 | rtap_iface = 0; | ||
1363 | break; | ||
1364 | |||
1365 | case '1': | ||
1366 | if (rtap_iface) | ||
1367 | return count; | ||
1368 | |||
1369 | rc = ipw_prom_alloc(priv); | ||
1370 | if (!rc) | ||
1371 | rtap_iface = 1; | ||
1372 | break; | ||
1373 | |||
1374 | default: | ||
1375 | return -EINVAL; | ||
1376 | } | ||
1377 | |||
1378 | if (rc) { | ||
1379 | IPW_ERROR("Failed to register promiscuous network " | ||
1380 | "device (error %d).\n", rc); | ||
1381 | } | ||
1382 | |||
1383 | return count; | ||
1384 | } | ||
1385 | |||
1386 | static ssize_t show_rtap_iface(struct device *d, | ||
1387 | struct device_attribute *attr, | ||
1388 | char *buf) | ||
1389 | { | ||
1390 | struct ipw_priv *priv = dev_get_drvdata(d); | ||
1391 | if (rtap_iface) | ||
1392 | return sprintf(buf, "%s", priv->prom_net_dev->name); | ||
1393 | else { | ||
1394 | buf[0] = '-'; | ||
1395 | buf[1] = '1'; | ||
1396 | buf[2] = '\0'; | ||
1397 | return 3; | ||
1398 | } | ||
1399 | } | ||
1400 | |||
1401 | static DEVICE_ATTR(rtap_iface, S_IWUSR | S_IRUSR, show_rtap_iface, | ||
1402 | store_rtap_iface); | ||
1403 | |||
1404 | static ssize_t store_rtap_filter(struct device *d, | ||
1405 | struct device_attribute *attr, | ||
1406 | const char *buf, size_t count) | ||
1407 | { | ||
1408 | struct ipw_priv *priv = dev_get_drvdata(d); | ||
1409 | |||
1410 | if (!priv->prom_priv) { | ||
1411 | IPW_ERROR("Attempting to set filter without " | ||
1412 | "rtap_iface enabled.\n"); | ||
1413 | return -EPERM; | ||
1414 | } | ||
1415 | |||
1416 | priv->prom_priv->filter = simple_strtol(buf, NULL, 0); | ||
1417 | |||
1418 | IPW_DEBUG_INFO("Setting rtap filter to " BIT_FMT16 "\n", | ||
1419 | BIT_ARG16(priv->prom_priv->filter)); | ||
1420 | |||
1421 | return count; | ||
1422 | } | ||
1423 | |||
1424 | static ssize_t show_rtap_filter(struct device *d, | ||
1425 | struct device_attribute *attr, | ||
1426 | char *buf) | ||
1427 | { | ||
1428 | struct ipw_priv *priv = dev_get_drvdata(d); | ||
1429 | return sprintf(buf, "0x%04X", | ||
1430 | priv->prom_priv ? priv->prom_priv->filter : 0); | ||
1431 | } | ||
1432 | |||
1433 | static DEVICE_ATTR(rtap_filter, S_IWUSR | S_IRUSR, show_rtap_filter, | ||
1434 | store_rtap_filter); | ||
1435 | #endif | ||
1436 | |||
1437 | static ssize_t show_scan_age(struct device *d, struct device_attribute *attr, | ||
1438 | char *buf) | ||
1439 | { | ||
1440 | struct ipw_priv *priv = dev_get_drvdata(d); | ||
1441 | return sprintf(buf, "%d\n", priv->ieee->scan_age); | ||
1442 | } | ||
1443 | |||
1444 | static ssize_t store_scan_age(struct device *d, struct device_attribute *attr, | ||
1445 | const char *buf, size_t count) | ||
1446 | { | ||
1447 | struct ipw_priv *priv = dev_get_drvdata(d); | ||
1448 | struct net_device *dev = priv->net_dev; | ||
1449 | char buffer[] = "00000000"; | ||
1450 | unsigned long len = | ||
1451 | (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1; | ||
1452 | unsigned long val; | ||
1453 | char *p = buffer; | ||
1454 | |||
1455 | IPW_DEBUG_INFO("enter\n"); | ||
1456 | |||
1457 | strncpy(buffer, buf, len); | ||
1458 | buffer[len] = 0; | ||
1459 | |||
1460 | if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') { | ||
1461 | p++; | ||
1462 | if (p[0] == 'x' || p[0] == 'X') | ||
1463 | p++; | ||
1464 | val = simple_strtoul(p, &p, 16); | ||
1465 | } else | ||
1466 | val = simple_strtoul(p, &p, 10); | ||
1467 | if (p == buffer) { | ||
1468 | IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name); | ||
1469 | } else { | ||
1470 | priv->ieee->scan_age = val; | ||
1471 | IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age); | ||
1472 | } | ||
1473 | |||
1474 | IPW_DEBUG_INFO("exit\n"); | ||
1475 | return len; | ||
1476 | } | ||
1477 | |||
1478 | static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age); | ||
1479 | |||
1480 | static ssize_t show_led(struct device *d, struct device_attribute *attr, | ||
1481 | char *buf) | ||
1482 | { | ||
1483 | struct ipw_priv *priv = dev_get_drvdata(d); | ||
1484 | return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1); | ||
1485 | } | ||
1486 | |||
1487 | static ssize_t store_led(struct device *d, struct device_attribute *attr, | ||
1488 | const char *buf, size_t count) | ||
1489 | { | ||
1490 | struct ipw_priv *priv = dev_get_drvdata(d); | ||
1491 | |||
1492 | IPW_DEBUG_INFO("enter\n"); | ||
1493 | |||
1494 | if (count == 0) | ||
1495 | return 0; | ||
1496 | |||
1497 | if (*buf == 0) { | ||
1498 | IPW_DEBUG_LED("Disabling LED control.\n"); | ||
1499 | priv->config |= CFG_NO_LED; | ||
1500 | ipw_led_shutdown(priv); | ||
1501 | } else { | ||
1502 | IPW_DEBUG_LED("Enabling LED control.\n"); | ||
1503 | priv->config &= ~CFG_NO_LED; | ||
1504 | ipw_led_init(priv); | ||
1505 | } | ||
1506 | |||
1507 | IPW_DEBUG_INFO("exit\n"); | ||
1508 | return count; | ||
1509 | } | ||
1510 | |||
1511 | static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led); | ||
1512 | |||
1513 | static ssize_t show_status(struct device *d, | ||
1514 | struct device_attribute *attr, char *buf) | ||
1515 | { | ||
1516 | struct ipw_priv *p = d->driver_data; | ||
1517 | return sprintf(buf, "0x%08x\n", (int)p->status); | ||
1518 | } | ||
1519 | |||
1520 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); | ||
1521 | |||
1522 | static ssize_t show_cfg(struct device *d, struct device_attribute *attr, | ||
1523 | char *buf) | ||
1524 | { | ||
1525 | struct ipw_priv *p = d->driver_data; | ||
1526 | return sprintf(buf, "0x%08x\n", (int)p->config); | ||
1527 | } | ||
1528 | |||
1529 | static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL); | ||
1530 | |||
1531 | static ssize_t show_nic_type(struct device *d, | ||
1532 | struct device_attribute *attr, char *buf) | ||
1533 | { | ||
1534 | struct ipw_priv *priv = d->driver_data; | ||
1535 | return sprintf(buf, "TYPE: %d\n", priv->nic_type); | ||
1536 | } | ||
1537 | |||
1538 | static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL); | ||
1539 | |||
1540 | static ssize_t show_ucode_version(struct device *d, | ||
1541 | struct device_attribute *attr, char *buf) | ||
1542 | { | ||
1543 | u32 len = sizeof(u32), tmp = 0; | ||
1544 | struct ipw_priv *p = d->driver_data; | ||
1545 | |||
1546 | if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len)) | ||
1547 | return 0; | ||
1548 | |||
1549 | return sprintf(buf, "0x%08x\n", tmp); | ||
1550 | } | ||
1551 | |||
1552 | static DEVICE_ATTR(ucode_version, S_IWUSR | S_IRUGO, show_ucode_version, NULL); | ||
1553 | |||
1554 | static ssize_t show_rtc(struct device *d, struct device_attribute *attr, | ||
1555 | char *buf) | ||
1556 | { | ||
1557 | u32 len = sizeof(u32), tmp = 0; | ||
1558 | struct ipw_priv *p = d->driver_data; | ||
1559 | |||
1560 | if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len)) | ||
1561 | return 0; | ||
1562 | |||
1563 | return sprintf(buf, "0x%08x\n", tmp); | ||
1564 | } | ||
1565 | |||
1566 | static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL); | ||
1567 | |||
1568 | /* | ||
1569 | * Add a device attribute to view/control the delay between eeprom | ||
1570 | * operations. | ||
1571 | */ | ||
1572 | static ssize_t show_eeprom_delay(struct device *d, | ||
1573 | struct device_attribute *attr, char *buf) | ||
1574 | { | ||
1575 | int n = ((struct ipw_priv *)d->driver_data)->eeprom_delay; | ||
1576 | return sprintf(buf, "%i\n", n); | ||
1577 | } | ||
1578 | static ssize_t store_eeprom_delay(struct device *d, | ||
1579 | struct device_attribute *attr, | ||
1580 | const char *buf, size_t count) | ||
1581 | { | ||
1582 | struct ipw_priv *p = d->driver_data; | ||
1583 | sscanf(buf, "%i", &p->eeprom_delay); | ||
1584 | return strnlen(buf, count); | ||
1585 | } | ||
1586 | |||
1587 | static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO, | ||
1588 | show_eeprom_delay, store_eeprom_delay); | ||
1589 | |||
1590 | static ssize_t show_command_event_reg(struct device *d, | ||
1591 | struct device_attribute *attr, char *buf) | ||
1592 | { | ||
1593 | u32 reg = 0; | ||
1594 | struct ipw_priv *p = d->driver_data; | ||
1595 | |||
1596 | reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT); | ||
1597 | return sprintf(buf, "0x%08x\n", reg); | ||
1598 | } | ||
1599 | static ssize_t store_command_event_reg(struct device *d, | ||
1600 | struct device_attribute *attr, | ||
1601 | const char *buf, size_t count) | ||
1602 | { | ||
1603 | u32 reg; | ||
1604 | struct ipw_priv *p = d->driver_data; | ||
1605 | |||
1606 | sscanf(buf, "%x", ®); | ||
1607 | ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg); | ||
1608 | return strnlen(buf, count); | ||
1609 | } | ||
1610 | |||
1611 | static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO, | ||
1612 | show_command_event_reg, store_command_event_reg); | ||
1613 | |||
1614 | static ssize_t show_mem_gpio_reg(struct device *d, | ||
1615 | struct device_attribute *attr, char *buf) | ||
1616 | { | ||
1617 | u32 reg = 0; | ||
1618 | struct ipw_priv *p = d->driver_data; | ||
1619 | |||
1620 | reg = ipw_read_reg32(p, 0x301100); | ||
1621 | return sprintf(buf, "0x%08x\n", reg); | ||
1622 | } | ||
1623 | static ssize_t store_mem_gpio_reg(struct device *d, | ||
1624 | struct device_attribute *attr, | ||
1625 | const char *buf, size_t count) | ||
1626 | { | ||
1627 | u32 reg; | ||
1628 | struct ipw_priv *p = d->driver_data; | ||
1629 | |||
1630 | sscanf(buf, "%x", ®); | ||
1631 | ipw_write_reg32(p, 0x301100, reg); | ||
1632 | return strnlen(buf, count); | ||
1633 | } | ||
1634 | |||
1635 | static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO, | ||
1636 | show_mem_gpio_reg, store_mem_gpio_reg); | ||
1637 | |||
1638 | static ssize_t show_indirect_dword(struct device *d, | ||
1639 | struct device_attribute *attr, char *buf) | ||
1640 | { | ||
1641 | u32 reg = 0; | ||
1642 | struct ipw_priv *priv = d->driver_data; | ||
1643 | |||
1644 | if (priv->status & STATUS_INDIRECT_DWORD) | ||
1645 | reg = ipw_read_reg32(priv, priv->indirect_dword); | ||
1646 | else | ||
1647 | reg = 0; | ||
1648 | |||
1649 | return sprintf(buf, "0x%08x\n", reg); | ||
1650 | } | ||
1651 | static ssize_t store_indirect_dword(struct device *d, | ||
1652 | struct device_attribute *attr, | ||
1653 | const char *buf, size_t count) | ||
1654 | { | ||
1655 | struct ipw_priv *priv = d->driver_data; | ||
1656 | |||
1657 | sscanf(buf, "%x", &priv->indirect_dword); | ||
1658 | priv->status |= STATUS_INDIRECT_DWORD; | ||
1659 | return strnlen(buf, count); | ||
1660 | } | ||
1661 | |||
1662 | static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO, | ||
1663 | show_indirect_dword, store_indirect_dword); | ||
1664 | |||
1665 | static ssize_t show_indirect_byte(struct device *d, | ||
1666 | struct device_attribute *attr, char *buf) | ||
1667 | { | ||
1668 | u8 reg = 0; | ||
1669 | struct ipw_priv *priv = d->driver_data; | ||
1670 | |||
1671 | if (priv->status & STATUS_INDIRECT_BYTE) | ||
1672 | reg = ipw_read_reg8(priv, priv->indirect_byte); | ||
1673 | else | ||
1674 | reg = 0; | ||
1675 | |||
1676 | return sprintf(buf, "0x%02x\n", reg); | ||
1677 | } | ||
1678 | static ssize_t store_indirect_byte(struct device *d, | ||
1679 | struct device_attribute *attr, | ||
1680 | const char *buf, size_t count) | ||
1681 | { | ||
1682 | struct ipw_priv *priv = d->driver_data; | ||
1683 | |||
1684 | sscanf(buf, "%x", &priv->indirect_byte); | ||
1685 | priv->status |= STATUS_INDIRECT_BYTE; | ||
1686 | return strnlen(buf, count); | ||
1687 | } | ||
1688 | |||
1689 | static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO, | ||
1690 | show_indirect_byte, store_indirect_byte); | ||
1691 | |||
1692 | static ssize_t show_direct_dword(struct device *d, | ||
1693 | struct device_attribute *attr, char *buf) | ||
1694 | { | ||
1695 | u32 reg = 0; | ||
1696 | struct ipw_priv *priv = d->driver_data; | ||
1697 | |||
1698 | if (priv->status & STATUS_DIRECT_DWORD) | ||
1699 | reg = ipw_read32(priv, priv->direct_dword); | ||
1700 | else | ||
1701 | reg = 0; | ||
1702 | |||
1703 | return sprintf(buf, "0x%08x\n", reg); | ||
1704 | } | ||
1705 | static ssize_t store_direct_dword(struct device *d, | ||
1706 | struct device_attribute *attr, | ||
1707 | const char *buf, size_t count) | ||
1708 | { | ||
1709 | struct ipw_priv *priv = d->driver_data; | ||
1710 | |||
1711 | sscanf(buf, "%x", &priv->direct_dword); | ||
1712 | priv->status |= STATUS_DIRECT_DWORD; | ||
1713 | return strnlen(buf, count); | ||
1714 | } | ||
1715 | |||
1716 | static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO, | ||
1717 | show_direct_dword, store_direct_dword); | ||
1718 | |||
1719 | static int rf_kill_active(struct ipw_priv *priv) | ||
1720 | { | ||
1721 | if (0 == (ipw_read32(priv, 0x30) & 0x10000)) | ||
1722 | priv->status |= STATUS_RF_KILL_HW; | ||
1723 | else | ||
1724 | priv->status &= ~STATUS_RF_KILL_HW; | ||
1725 | |||
1726 | return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0; | ||
1727 | } | ||
1728 | |||
1729 | static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr, | ||
1730 | char *buf) | ||
1731 | { | ||
1732 | /* 0 - RF kill not enabled | ||
1733 | 1 - SW based RF kill active (sysfs) | ||
1734 | 2 - HW based RF kill active | ||
1735 | 3 - Both HW and SW baed RF kill active */ | ||
1736 | struct ipw_priv *priv = d->driver_data; | ||
1737 | int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) | | ||
1738 | (rf_kill_active(priv) ? 0x2 : 0x0); | ||
1739 | return sprintf(buf, "%i\n", val); | ||
1740 | } | ||
1741 | |||
1742 | static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio) | ||
1743 | { | ||
1744 | if ((disable_radio ? 1 : 0) == | ||
1745 | ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0)) | ||
1746 | return 0; | ||
1747 | |||
1748 | IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n", | ||
1749 | disable_radio ? "OFF" : "ON"); | ||
1750 | |||
1751 | if (disable_radio) { | ||
1752 | priv->status |= STATUS_RF_KILL_SW; | ||
1753 | |||
1754 | if (priv->workqueue) { | ||
1755 | cancel_delayed_work(&priv->request_scan); | ||
1756 | cancel_delayed_work(&priv->request_direct_scan); | ||
1757 | cancel_delayed_work(&priv->request_passive_scan); | ||
1758 | cancel_delayed_work(&priv->scan_event); | ||
1759 | } | ||
1760 | queue_work(priv->workqueue, &priv->down); | ||
1761 | } else { | ||
1762 | priv->status &= ~STATUS_RF_KILL_SW; | ||
1763 | if (rf_kill_active(priv)) { | ||
1764 | IPW_DEBUG_RF_KILL("Can not turn radio back on - " | ||
1765 | "disabled by HW switch\n"); | ||
1766 | /* Make sure the RF_KILL check timer is running */ | ||
1767 | cancel_delayed_work(&priv->rf_kill); | ||
1768 | queue_delayed_work(priv->workqueue, &priv->rf_kill, | ||
1769 | round_jiffies_relative(2 * HZ)); | ||
1770 | } else | ||
1771 | queue_work(priv->workqueue, &priv->up); | ||
1772 | } | ||
1773 | |||
1774 | return 1; | ||
1775 | } | ||
1776 | |||
1777 | static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr, | ||
1778 | const char *buf, size_t count) | ||
1779 | { | ||
1780 | struct ipw_priv *priv = d->driver_data; | ||
1781 | |||
1782 | ipw_radio_kill_sw(priv, buf[0] == '1'); | ||
1783 | |||
1784 | return count; | ||
1785 | } | ||
1786 | |||
1787 | static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill); | ||
1788 | |||
1789 | static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr, | ||
1790 | char *buf) | ||
1791 | { | ||
1792 | struct ipw_priv *priv = (struct ipw_priv *)d->driver_data; | ||
1793 | int pos = 0, len = 0; | ||
1794 | if (priv->config & CFG_SPEED_SCAN) { | ||
1795 | while (priv->speed_scan[pos] != 0) | ||
1796 | len += sprintf(&buf[len], "%d ", | ||
1797 | priv->speed_scan[pos++]); | ||
1798 | return len + sprintf(&buf[len], "\n"); | ||
1799 | } | ||
1800 | |||
1801 | return sprintf(buf, "0\n"); | ||
1802 | } | ||
1803 | |||
1804 | static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr, | ||
1805 | const char *buf, size_t count) | ||
1806 | { | ||
1807 | struct ipw_priv *priv = (struct ipw_priv *)d->driver_data; | ||
1808 | int channel, pos = 0; | ||
1809 | const char *p = buf; | ||
1810 | |||
1811 | /* list of space separated channels to scan, optionally ending with 0 */ | ||
1812 | while ((channel = simple_strtol(p, NULL, 0))) { | ||
1813 | if (pos == MAX_SPEED_SCAN - 1) { | ||
1814 | priv->speed_scan[pos] = 0; | ||
1815 | break; | ||
1816 | } | ||
1817 | |||
1818 | if (ieee80211_is_valid_channel(priv->ieee, channel)) | ||
1819 | priv->speed_scan[pos++] = channel; | ||
1820 | else | ||
1821 | IPW_WARNING("Skipping invalid channel request: %d\n", | ||
1822 | channel); | ||
1823 | p = strchr(p, ' '); | ||
1824 | if (!p) | ||
1825 | break; | ||
1826 | while (*p == ' ' || *p == '\t') | ||
1827 | p++; | ||
1828 | } | ||
1829 | |||
1830 | if (pos == 0) | ||
1831 | priv->config &= ~CFG_SPEED_SCAN; | ||
1832 | else { | ||
1833 | priv->speed_scan_pos = 0; | ||
1834 | priv->config |= CFG_SPEED_SCAN; | ||
1835 | } | ||
1836 | |||
1837 | return count; | ||
1838 | } | ||
1839 | |||
1840 | static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan, | ||
1841 | store_speed_scan); | ||
1842 | |||
1843 | static ssize_t show_net_stats(struct device *d, struct device_attribute *attr, | ||
1844 | char *buf) | ||
1845 | { | ||
1846 | struct ipw_priv *priv = (struct ipw_priv *)d->driver_data; | ||
1847 | return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0'); | ||
1848 | } | ||
1849 | |||
1850 | static ssize_t store_net_stats(struct device *d, struct device_attribute *attr, | ||
1851 | const char *buf, size_t count) | ||
1852 | { | ||
1853 | struct ipw_priv *priv = (struct ipw_priv *)d->driver_data; | ||
1854 | if (buf[0] == '1') | ||
1855 | priv->config |= CFG_NET_STATS; | ||
1856 | else | ||
1857 | priv->config &= ~CFG_NET_STATS; | ||
1858 | |||
1859 | return count; | ||
1860 | } | ||
1861 | |||
1862 | static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO, | ||
1863 | show_net_stats, store_net_stats); | ||
1864 | |||
1865 | static ssize_t show_channels(struct device *d, | ||
1866 | struct device_attribute *attr, | ||
1867 | char *buf) | ||
1868 | { | ||
1869 | struct ipw_priv *priv = dev_get_drvdata(d); | ||
1870 | const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee); | ||
1871 | int len = 0, i; | ||
1872 | |||
1873 | len = sprintf(&buf[len], | ||
1874 | "Displaying %d channels in 2.4Ghz band " | ||
1875 | "(802.11bg):\n", geo->bg_channels); | ||
1876 | |||
1877 | for (i = 0; i < geo->bg_channels; i++) { | ||
1878 | len += sprintf(&buf[len], "%d: BSS%s%s, %s, Band %s.\n", | ||
1879 | geo->bg[i].channel, | ||
1880 | geo->bg[i].flags & IEEE80211_CH_RADAR_DETECT ? | ||
1881 | " (radar spectrum)" : "", | ||
1882 | ((geo->bg[i].flags & IEEE80211_CH_NO_IBSS) || | ||
1883 | (geo->bg[i].flags & IEEE80211_CH_RADAR_DETECT)) | ||
1884 | ? "" : ", IBSS", | ||
1885 | geo->bg[i].flags & IEEE80211_CH_PASSIVE_ONLY ? | ||
1886 | "passive only" : "active/passive", | ||
1887 | geo->bg[i].flags & IEEE80211_CH_B_ONLY ? | ||
1888 | "B" : "B/G"); | ||
1889 | } | ||
1890 | |||
1891 | len += sprintf(&buf[len], | ||
1892 | "Displaying %d channels in 5.2Ghz band " | ||
1893 | "(802.11a):\n", geo->a_channels); | ||
1894 | for (i = 0; i < geo->a_channels; i++) { | ||
1895 | len += sprintf(&buf[len], "%d: BSS%s%s, %s.\n", | ||
1896 | geo->a[i].channel, | ||
1897 | geo->a[i].flags & IEEE80211_CH_RADAR_DETECT ? | ||
1898 | " (radar spectrum)" : "", | ||
1899 | ((geo->a[i].flags & IEEE80211_CH_NO_IBSS) || | ||
1900 | (geo->a[i].flags & IEEE80211_CH_RADAR_DETECT)) | ||
1901 | ? "" : ", IBSS", | ||
1902 | geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY ? | ||
1903 | "passive only" : "active/passive"); | ||
1904 | } | ||
1905 | |||
1906 | return len; | ||
1907 | } | ||
1908 | |||
1909 | static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL); | ||
1910 | |||
1911 | static void notify_wx_assoc_event(struct ipw_priv *priv) | ||
1912 | { | ||
1913 | union iwreq_data wrqu; | ||
1914 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; | ||
1915 | if (priv->status & STATUS_ASSOCIATED) | ||
1916 | memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN); | ||
1917 | else | ||
1918 | memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN); | ||
1919 | wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL); | ||
1920 | } | ||
1921 | |||
1922 | static void ipw_irq_tasklet(struct ipw_priv *priv) | ||
1923 | { | ||
1924 | u32 inta, inta_mask, handled = 0; | ||
1925 | unsigned long flags; | ||
1926 | int rc = 0; | ||
1927 | |||
1928 | spin_lock_irqsave(&priv->irq_lock, flags); | ||
1929 | |||
1930 | inta = ipw_read32(priv, IPW_INTA_RW); | ||
1931 | inta_mask = ipw_read32(priv, IPW_INTA_MASK_R); | ||
1932 | inta &= (IPW_INTA_MASK_ALL & inta_mask); | ||
1933 | |||
1934 | /* Add any cached INTA values that need to be handled */ | ||
1935 | inta |= priv->isr_inta; | ||
1936 | |||
1937 | spin_unlock_irqrestore(&priv->irq_lock, flags); | ||
1938 | |||
1939 | spin_lock_irqsave(&priv->lock, flags); | ||
1940 | |||
1941 | /* handle all the justifications for the interrupt */ | ||
1942 | if (inta & IPW_INTA_BIT_RX_TRANSFER) { | ||
1943 | ipw_rx(priv); | ||
1944 | handled |= IPW_INTA_BIT_RX_TRANSFER; | ||
1945 | } | ||
1946 | |||
1947 | if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) { | ||
1948 | IPW_DEBUG_HC("Command completed.\n"); | ||
1949 | rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1); | ||
1950 | priv->status &= ~STATUS_HCMD_ACTIVE; | ||
1951 | wake_up_interruptible(&priv->wait_command_queue); | ||
1952 | handled |= IPW_INTA_BIT_TX_CMD_QUEUE; | ||
1953 | } | ||
1954 | |||
1955 | if (inta & IPW_INTA_BIT_TX_QUEUE_1) { | ||
1956 | IPW_DEBUG_TX("TX_QUEUE_1\n"); | ||
1957 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0); | ||
1958 | handled |= IPW_INTA_BIT_TX_QUEUE_1; | ||
1959 | } | ||
1960 | |||
1961 | if (inta & IPW_INTA_BIT_TX_QUEUE_2) { | ||
1962 | IPW_DEBUG_TX("TX_QUEUE_2\n"); | ||
1963 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1); | ||
1964 | handled |= IPW_INTA_BIT_TX_QUEUE_2; | ||
1965 | } | ||
1966 | |||
1967 | if (inta & IPW_INTA_BIT_TX_QUEUE_3) { | ||
1968 | IPW_DEBUG_TX("TX_QUEUE_3\n"); | ||
1969 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2); | ||
1970 | handled |= IPW_INTA_BIT_TX_QUEUE_3; | ||
1971 | } | ||
1972 | |||
1973 | if (inta & IPW_INTA_BIT_TX_QUEUE_4) { | ||
1974 | IPW_DEBUG_TX("TX_QUEUE_4\n"); | ||
1975 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3); | ||
1976 | handled |= IPW_INTA_BIT_TX_QUEUE_4; | ||
1977 | } | ||
1978 | |||
1979 | if (inta & IPW_INTA_BIT_STATUS_CHANGE) { | ||
1980 | IPW_WARNING("STATUS_CHANGE\n"); | ||
1981 | handled |= IPW_INTA_BIT_STATUS_CHANGE; | ||
1982 | } | ||
1983 | |||
1984 | if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) { | ||
1985 | IPW_WARNING("TX_PERIOD_EXPIRED\n"); | ||
1986 | handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED; | ||
1987 | } | ||
1988 | |||
1989 | if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) { | ||
1990 | IPW_WARNING("HOST_CMD_DONE\n"); | ||
1991 | handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE; | ||
1992 | } | ||
1993 | |||
1994 | if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) { | ||
1995 | IPW_WARNING("FW_INITIALIZATION_DONE\n"); | ||
1996 | handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE; | ||
1997 | } | ||
1998 | |||
1999 | if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) { | ||
2000 | IPW_WARNING("PHY_OFF_DONE\n"); | ||
2001 | handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE; | ||
2002 | } | ||
2003 | |||
2004 | if (inta & IPW_INTA_BIT_RF_KILL_DONE) { | ||
2005 | IPW_DEBUG_RF_KILL("RF_KILL_DONE\n"); | ||
2006 | priv->status |= STATUS_RF_KILL_HW; | ||
2007 | wake_up_interruptible(&priv->wait_command_queue); | ||
2008 | priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING); | ||
2009 | cancel_delayed_work(&priv->request_scan); | ||
2010 | cancel_delayed_work(&priv->request_direct_scan); | ||
2011 | cancel_delayed_work(&priv->request_passive_scan); | ||
2012 | cancel_delayed_work(&priv->scan_event); | ||
2013 | schedule_work(&priv->link_down); | ||
2014 | queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ); | ||
2015 | handled |= IPW_INTA_BIT_RF_KILL_DONE; | ||
2016 | } | ||
2017 | |||
2018 | if (inta & IPW_INTA_BIT_FATAL_ERROR) { | ||
2019 | IPW_WARNING("Firmware error detected. Restarting.\n"); | ||
2020 | if (priv->error) { | ||
2021 | IPW_DEBUG_FW("Sysfs 'error' log already exists.\n"); | ||
2022 | if (ipw_debug_level & IPW_DL_FW_ERRORS) { | ||
2023 | struct ipw_fw_error *error = | ||
2024 | ipw_alloc_error_log(priv); | ||
2025 | ipw_dump_error_log(priv, error); | ||
2026 | kfree(error); | ||
2027 | } | ||
2028 | } else { | ||
2029 | priv->error = ipw_alloc_error_log(priv); | ||
2030 | if (priv->error) | ||
2031 | IPW_DEBUG_FW("Sysfs 'error' log captured.\n"); | ||
2032 | else | ||
2033 | IPW_DEBUG_FW("Error allocating sysfs 'error' " | ||
2034 | "log.\n"); | ||
2035 | if (ipw_debug_level & IPW_DL_FW_ERRORS) | ||
2036 | ipw_dump_error_log(priv, priv->error); | ||
2037 | } | ||
2038 | |||
2039 | /* XXX: If hardware encryption is for WPA/WPA2, | ||
2040 | * we have to notify the supplicant. */ | ||
2041 | if (priv->ieee->sec.encrypt) { | ||
2042 | priv->status &= ~STATUS_ASSOCIATED; | ||
2043 | notify_wx_assoc_event(priv); | ||
2044 | } | ||
2045 | |||
2046 | /* Keep the restart process from trying to send host | ||
2047 | * commands by clearing the INIT status bit */ | ||
2048 | priv->status &= ~STATUS_INIT; | ||
2049 | |||
2050 | /* Cancel currently queued command. */ | ||
2051 | priv->status &= ~STATUS_HCMD_ACTIVE; | ||
2052 | wake_up_interruptible(&priv->wait_command_queue); | ||
2053 | |||
2054 | queue_work(priv->workqueue, &priv->adapter_restart); | ||
2055 | handled |= IPW_INTA_BIT_FATAL_ERROR; | ||
2056 | } | ||
2057 | |||
2058 | if (inta & IPW_INTA_BIT_PARITY_ERROR) { | ||
2059 | IPW_ERROR("Parity error\n"); | ||
2060 | handled |= IPW_INTA_BIT_PARITY_ERROR; | ||
2061 | } | ||
2062 | |||
2063 | if (handled != inta) { | ||
2064 | IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled); | ||
2065 | } | ||
2066 | |||
2067 | spin_unlock_irqrestore(&priv->lock, flags); | ||
2068 | |||
2069 | /* enable all interrupts */ | ||
2070 | ipw_enable_interrupts(priv); | ||
2071 | } | ||
2072 | |||
2073 | #define IPW_CMD(x) case IPW_CMD_ ## x : return #x | ||
2074 | static char *get_cmd_string(u8 cmd) | ||
2075 | { | ||
2076 | switch (cmd) { | ||
2077 | IPW_CMD(HOST_COMPLETE); | ||
2078 | IPW_CMD(POWER_DOWN); | ||
2079 | IPW_CMD(SYSTEM_CONFIG); | ||
2080 | IPW_CMD(MULTICAST_ADDRESS); | ||
2081 | IPW_CMD(SSID); | ||
2082 | IPW_CMD(ADAPTER_ADDRESS); | ||
2083 | IPW_CMD(PORT_TYPE); | ||
2084 | IPW_CMD(RTS_THRESHOLD); | ||
2085 | IPW_CMD(FRAG_THRESHOLD); | ||
2086 | IPW_CMD(POWER_MODE); | ||
2087 | IPW_CMD(WEP_KEY); | ||
2088 | IPW_CMD(TGI_TX_KEY); | ||
2089 | IPW_CMD(SCAN_REQUEST); | ||
2090 | IPW_CMD(SCAN_REQUEST_EXT); | ||
2091 | IPW_CMD(ASSOCIATE); | ||
2092 | IPW_CMD(SUPPORTED_RATES); | ||
2093 | IPW_CMD(SCAN_ABORT); | ||
2094 | IPW_CMD(TX_FLUSH); | ||
2095 | IPW_CMD(QOS_PARAMETERS); | ||
2096 | IPW_CMD(DINO_CONFIG); | ||
2097 | IPW_CMD(RSN_CAPABILITIES); | ||
2098 | IPW_CMD(RX_KEY); | ||
2099 | IPW_CMD(CARD_DISABLE); | ||
2100 | IPW_CMD(SEED_NUMBER); | ||
2101 | IPW_CMD(TX_POWER); | ||
2102 | IPW_CMD(COUNTRY_INFO); | ||
2103 | IPW_CMD(AIRONET_INFO); | ||
2104 | IPW_CMD(AP_TX_POWER); | ||
2105 | IPW_CMD(CCKM_INFO); | ||
2106 | IPW_CMD(CCX_VER_INFO); | ||
2107 | IPW_CMD(SET_CALIBRATION); | ||
2108 | IPW_CMD(SENSITIVITY_CALIB); | ||
2109 | IPW_CMD(RETRY_LIMIT); | ||
2110 | IPW_CMD(IPW_PRE_POWER_DOWN); | ||
2111 | IPW_CMD(VAP_BEACON_TEMPLATE); | ||
2112 | IPW_CMD(VAP_DTIM_PERIOD); | ||
2113 | IPW_CMD(EXT_SUPPORTED_RATES); | ||
2114 | IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT); | ||
2115 | IPW_CMD(VAP_QUIET_INTERVALS); | ||
2116 | IPW_CMD(VAP_CHANNEL_SWITCH); | ||
2117 | IPW_CMD(VAP_MANDATORY_CHANNELS); | ||
2118 | IPW_CMD(VAP_CELL_PWR_LIMIT); | ||
2119 | IPW_CMD(VAP_CF_PARAM_SET); | ||
2120 | IPW_CMD(VAP_SET_BEACONING_STATE); | ||
2121 | IPW_CMD(MEASUREMENT); | ||
2122 | IPW_CMD(POWER_CAPABILITY); | ||
2123 | IPW_CMD(SUPPORTED_CHANNELS); | ||
2124 | IPW_CMD(TPC_REPORT); | ||
2125 | IPW_CMD(WME_INFO); | ||
2126 | IPW_CMD(PRODUCTION_COMMAND); | ||
2127 | default: | ||
2128 | return "UNKNOWN"; | ||
2129 | } | ||
2130 | } | ||
2131 | |||
2132 | #define HOST_COMPLETE_TIMEOUT HZ | ||
2133 | |||
2134 | static int __ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd) | ||
2135 | { | ||
2136 | int rc = 0; | ||
2137 | unsigned long flags; | ||
2138 | |||
2139 | spin_lock_irqsave(&priv->lock, flags); | ||
2140 | if (priv->status & STATUS_HCMD_ACTIVE) { | ||
2141 | IPW_ERROR("Failed to send %s: Already sending a command.\n", | ||
2142 | get_cmd_string(cmd->cmd)); | ||
2143 | spin_unlock_irqrestore(&priv->lock, flags); | ||
2144 | return -EAGAIN; | ||
2145 | } | ||
2146 | |||
2147 | priv->status |= STATUS_HCMD_ACTIVE; | ||
2148 | |||
2149 | if (priv->cmdlog) { | ||
2150 | priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies; | ||
2151 | priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd; | ||
2152 | priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len; | ||
2153 | memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param, | ||
2154 | cmd->len); | ||
2155 | priv->cmdlog[priv->cmdlog_pos].retcode = -1; | ||
2156 | } | ||
2157 | |||
2158 | IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n", | ||
2159 | get_cmd_string(cmd->cmd), cmd->cmd, cmd->len, | ||
2160 | priv->status); | ||
2161 | |||
2162 | #ifndef DEBUG_CMD_WEP_KEY | ||
2163 | if (cmd->cmd == IPW_CMD_WEP_KEY) | ||
2164 | IPW_DEBUG_HC("WEP_KEY command masked out for secure.\n"); | ||
2165 | else | ||
2166 | #endif | ||
2167 | printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len); | ||
2168 | |||
2169 | rc = ipw_queue_tx_hcmd(priv, cmd->cmd, cmd->param, cmd->len, 0); | ||
2170 | if (rc) { | ||
2171 | priv->status &= ~STATUS_HCMD_ACTIVE; | ||
2172 | IPW_ERROR("Failed to send %s: Reason %d\n", | ||
2173 | get_cmd_string(cmd->cmd), rc); | ||
2174 | spin_unlock_irqrestore(&priv->lock, flags); | ||
2175 | goto exit; | ||
2176 | } | ||
2177 | spin_unlock_irqrestore(&priv->lock, flags); | ||
2178 | |||
2179 | rc = wait_event_interruptible_timeout(priv->wait_command_queue, | ||
2180 | !(priv-> | ||
2181 | status & STATUS_HCMD_ACTIVE), | ||
2182 | HOST_COMPLETE_TIMEOUT); | ||
2183 | if (rc == 0) { | ||
2184 | spin_lock_irqsave(&priv->lock, flags); | ||
2185 | if (priv->status & STATUS_HCMD_ACTIVE) { | ||
2186 | IPW_ERROR("Failed to send %s: Command timed out.\n", | ||
2187 | get_cmd_string(cmd->cmd)); | ||
2188 | priv->status &= ~STATUS_HCMD_ACTIVE; | ||
2189 | spin_unlock_irqrestore(&priv->lock, flags); | ||
2190 | rc = -EIO; | ||
2191 | goto exit; | ||
2192 | } | ||
2193 | spin_unlock_irqrestore(&priv->lock, flags); | ||
2194 | } else | ||
2195 | rc = 0; | ||
2196 | |||
2197 | if (priv->status & STATUS_RF_KILL_HW) { | ||
2198 | IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n", | ||
2199 | get_cmd_string(cmd->cmd)); | ||
2200 | rc = -EIO; | ||
2201 | goto exit; | ||
2202 | } | ||
2203 | |||
2204 | exit: | ||
2205 | if (priv->cmdlog) { | ||
2206 | priv->cmdlog[priv->cmdlog_pos++].retcode = rc; | ||
2207 | priv->cmdlog_pos %= priv->cmdlog_len; | ||
2208 | } | ||
2209 | return rc; | ||
2210 | } | ||
2211 | |||
2212 | static int ipw_send_cmd_simple(struct ipw_priv *priv, u8 command) | ||
2213 | { | ||
2214 | struct host_cmd cmd = { | ||
2215 | .cmd = command, | ||
2216 | }; | ||
2217 | |||
2218 | return __ipw_send_cmd(priv, &cmd); | ||
2219 | } | ||
2220 | |||
2221 | static int ipw_send_cmd_pdu(struct ipw_priv *priv, u8 command, u8 len, | ||
2222 | void *data) | ||
2223 | { | ||
2224 | struct host_cmd cmd = { | ||
2225 | .cmd = command, | ||
2226 | .len = len, | ||
2227 | .param = data, | ||
2228 | }; | ||
2229 | |||
2230 | return __ipw_send_cmd(priv, &cmd); | ||
2231 | } | ||
2232 | |||
2233 | static int ipw_send_host_complete(struct ipw_priv *priv) | ||
2234 | { | ||
2235 | if (!priv) { | ||
2236 | IPW_ERROR("Invalid args\n"); | ||
2237 | return -1; | ||
2238 | } | ||
2239 | |||
2240 | return ipw_send_cmd_simple(priv, IPW_CMD_HOST_COMPLETE); | ||
2241 | } | ||
2242 | |||
2243 | static int ipw_send_system_config(struct ipw_priv *priv) | ||
2244 | { | ||
2245 | return ipw_send_cmd_pdu(priv, IPW_CMD_SYSTEM_CONFIG, | ||
2246 | sizeof(priv->sys_config), | ||
2247 | &priv->sys_config); | ||
2248 | } | ||
2249 | |||
2250 | static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len) | ||
2251 | { | ||
2252 | if (!priv || !ssid) { | ||
2253 | IPW_ERROR("Invalid args\n"); | ||
2254 | return -1; | ||
2255 | } | ||
2256 | |||
2257 | return ipw_send_cmd_pdu(priv, IPW_CMD_SSID, min(len, IW_ESSID_MAX_SIZE), | ||
2258 | ssid); | ||
2259 | } | ||
2260 | |||
2261 | static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac) | ||
2262 | { | ||
2263 | if (!priv || !mac) { | ||
2264 | IPW_ERROR("Invalid args\n"); | ||
2265 | return -1; | ||
2266 | } | ||
2267 | |||
2268 | IPW_DEBUG_INFO("%s: Setting MAC to %pM\n", | ||
2269 | priv->net_dev->name, mac); | ||
2270 | |||
2271 | return ipw_send_cmd_pdu(priv, IPW_CMD_ADAPTER_ADDRESS, ETH_ALEN, mac); | ||
2272 | } | ||
2273 | |||
2274 | /* | ||
2275 | * NOTE: This must be executed from our workqueue as it results in udelay | ||
2276 | * being called which may corrupt the keyboard if executed on default | ||
2277 | * workqueue | ||
2278 | */ | ||
2279 | static void ipw_adapter_restart(void *adapter) | ||
2280 | { | ||
2281 | struct ipw_priv *priv = adapter; | ||
2282 | |||
2283 | if (priv->status & STATUS_RF_KILL_MASK) | ||
2284 | return; | ||
2285 | |||
2286 | ipw_down(priv); | ||
2287 | |||
2288 | if (priv->assoc_network && | ||
2289 | (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS)) | ||
2290 | ipw_remove_current_network(priv); | ||
2291 | |||
2292 | if (ipw_up(priv)) { | ||
2293 | IPW_ERROR("Failed to up device\n"); | ||
2294 | return; | ||
2295 | } | ||
2296 | } | ||
2297 | |||
2298 | static void ipw_bg_adapter_restart(struct work_struct *work) | ||
2299 | { | ||
2300 | struct ipw_priv *priv = | ||
2301 | container_of(work, struct ipw_priv, adapter_restart); | ||
2302 | mutex_lock(&priv->mutex); | ||
2303 | ipw_adapter_restart(priv); | ||
2304 | mutex_unlock(&priv->mutex); | ||
2305 | } | ||
2306 | |||
2307 | #define IPW_SCAN_CHECK_WATCHDOG (5 * HZ) | ||
2308 | |||
2309 | static void ipw_scan_check(void *data) | ||
2310 | { | ||
2311 | struct ipw_priv *priv = data; | ||
2312 | if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) { | ||
2313 | IPW_DEBUG_SCAN("Scan completion watchdog resetting " | ||
2314 | "adapter after (%dms).\n", | ||
2315 | jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG)); | ||
2316 | queue_work(priv->workqueue, &priv->adapter_restart); | ||
2317 | } | ||
2318 | } | ||
2319 | |||
2320 | static void ipw_bg_scan_check(struct work_struct *work) | ||
2321 | { | ||
2322 | struct ipw_priv *priv = | ||
2323 | container_of(work, struct ipw_priv, scan_check.work); | ||
2324 | mutex_lock(&priv->mutex); | ||
2325 | ipw_scan_check(priv); | ||
2326 | mutex_unlock(&priv->mutex); | ||
2327 | } | ||
2328 | |||
2329 | static int ipw_send_scan_request_ext(struct ipw_priv *priv, | ||
2330 | struct ipw_scan_request_ext *request) | ||
2331 | { | ||
2332 | return ipw_send_cmd_pdu(priv, IPW_CMD_SCAN_REQUEST_EXT, | ||
2333 | sizeof(*request), request); | ||
2334 | } | ||
2335 | |||
2336 | static int ipw_send_scan_abort(struct ipw_priv *priv) | ||
2337 | { | ||
2338 | if (!priv) { | ||
2339 | IPW_ERROR("Invalid args\n"); | ||
2340 | return -1; | ||
2341 | } | ||
2342 | |||
2343 | return ipw_send_cmd_simple(priv, IPW_CMD_SCAN_ABORT); | ||
2344 | } | ||
2345 | |||
2346 | static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens) | ||
2347 | { | ||
2348 | struct ipw_sensitivity_calib calib = { | ||
2349 | .beacon_rssi_raw = cpu_to_le16(sens), | ||
2350 | }; | ||
2351 | |||
2352 | return ipw_send_cmd_pdu(priv, IPW_CMD_SENSITIVITY_CALIB, sizeof(calib), | ||
2353 | &calib); | ||
2354 | } | ||
2355 | |||
2356 | static int ipw_send_associate(struct ipw_priv *priv, | ||
2357 | struct ipw_associate *associate) | ||
2358 | { | ||
2359 | if (!priv || !associate) { | ||
2360 | IPW_ERROR("Invalid args\n"); | ||
2361 | return -1; | ||
2362 | } | ||
2363 | |||
2364 | return ipw_send_cmd_pdu(priv, IPW_CMD_ASSOCIATE, sizeof(*associate), | ||
2365 | associate); | ||
2366 | } | ||
2367 | |||
2368 | static int ipw_send_supported_rates(struct ipw_priv *priv, | ||
2369 | struct ipw_supported_rates *rates) | ||
2370 | { | ||
2371 | if (!priv || !rates) { | ||
2372 | IPW_ERROR("Invalid args\n"); | ||
2373 | return -1; | ||
2374 | } | ||
2375 | |||
2376 | return ipw_send_cmd_pdu(priv, IPW_CMD_SUPPORTED_RATES, sizeof(*rates), | ||
2377 | rates); | ||
2378 | } | ||
2379 | |||
2380 | static int ipw_set_random_seed(struct ipw_priv *priv) | ||
2381 | { | ||
2382 | u32 val; | ||
2383 | |||
2384 | if (!priv) { | ||
2385 | IPW_ERROR("Invalid args\n"); | ||
2386 | return -1; | ||
2387 | } | ||
2388 | |||
2389 | get_random_bytes(&val, sizeof(val)); | ||
2390 | |||
2391 | return ipw_send_cmd_pdu(priv, IPW_CMD_SEED_NUMBER, sizeof(val), &val); | ||
2392 | } | ||
2393 | |||
2394 | static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off) | ||
2395 | { | ||
2396 | __le32 v = cpu_to_le32(phy_off); | ||
2397 | if (!priv) { | ||
2398 | IPW_ERROR("Invalid args\n"); | ||
2399 | return -1; | ||
2400 | } | ||
2401 | |||
2402 | return ipw_send_cmd_pdu(priv, IPW_CMD_CARD_DISABLE, sizeof(v), &v); | ||
2403 | } | ||
2404 | |||
2405 | static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power) | ||
2406 | { | ||
2407 | if (!priv || !power) { | ||
2408 | IPW_ERROR("Invalid args\n"); | ||
2409 | return -1; | ||
2410 | } | ||
2411 | |||
2412 | return ipw_send_cmd_pdu(priv, IPW_CMD_TX_POWER, sizeof(*power), power); | ||
2413 | } | ||
2414 | |||
2415 | static int ipw_set_tx_power(struct ipw_priv *priv) | ||
2416 | { | ||
2417 | const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee); | ||
2418 | struct ipw_tx_power tx_power; | ||
2419 | s8 max_power; | ||
2420 | int i; | ||
2421 | |||
2422 | memset(&tx_power, 0, sizeof(tx_power)); | ||
2423 | |||
2424 | /* configure device for 'G' band */ | ||
2425 | tx_power.ieee_mode = IPW_G_MODE; | ||
2426 | tx_power.num_channels = geo->bg_channels; | ||
2427 | for (i = 0; i < geo->bg_channels; i++) { | ||
2428 | max_power = geo->bg[i].max_power; | ||
2429 | tx_power.channels_tx_power[i].channel_number = | ||
2430 | geo->bg[i].channel; | ||
2431 | tx_power.channels_tx_power[i].tx_power = max_power ? | ||
2432 | min(max_power, priv->tx_power) : priv->tx_power; | ||
2433 | } | ||
2434 | if (ipw_send_tx_power(priv, &tx_power)) | ||
2435 | return -EIO; | ||
2436 | |||
2437 | /* configure device to also handle 'B' band */ | ||
2438 | tx_power.ieee_mode = IPW_B_MODE; | ||
2439 | if (ipw_send_tx_power(priv, &tx_power)) | ||
2440 | return -EIO; | ||
2441 | |||
2442 | /* configure device to also handle 'A' band */ | ||
2443 | if (priv->ieee->abg_true) { | ||
2444 | tx_power.ieee_mode = IPW_A_MODE; | ||
2445 | tx_power.num_channels = geo->a_channels; | ||
2446 | for (i = 0; i < tx_power.num_channels; i++) { | ||
2447 | max_power = geo->a[i].max_power; | ||
2448 | tx_power.channels_tx_power[i].channel_number = | ||
2449 | geo->a[i].channel; | ||
2450 | tx_power.channels_tx_power[i].tx_power = max_power ? | ||
2451 | min(max_power, priv->tx_power) : priv->tx_power; | ||
2452 | } | ||
2453 | if (ipw_send_tx_power(priv, &tx_power)) | ||
2454 | return -EIO; | ||
2455 | } | ||
2456 | return 0; | ||
2457 | } | ||
2458 | |||
2459 | static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts) | ||
2460 | { | ||
2461 | struct ipw_rts_threshold rts_threshold = { | ||
2462 | .rts_threshold = cpu_to_le16(rts), | ||
2463 | }; | ||
2464 | |||
2465 | if (!priv) { | ||
2466 | IPW_ERROR("Invalid args\n"); | ||
2467 | return -1; | ||
2468 | } | ||
2469 | |||
2470 | return ipw_send_cmd_pdu(priv, IPW_CMD_RTS_THRESHOLD, | ||
2471 | sizeof(rts_threshold), &rts_threshold); | ||
2472 | } | ||
2473 | |||
2474 | static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag) | ||
2475 | { | ||
2476 | struct ipw_frag_threshold frag_threshold = { | ||
2477 | .frag_threshold = cpu_to_le16(frag), | ||
2478 | }; | ||
2479 | |||
2480 | if (!priv) { | ||
2481 | IPW_ERROR("Invalid args\n"); | ||
2482 | return -1; | ||
2483 | } | ||
2484 | |||
2485 | return ipw_send_cmd_pdu(priv, IPW_CMD_FRAG_THRESHOLD, | ||
2486 | sizeof(frag_threshold), &frag_threshold); | ||
2487 | } | ||
2488 | |||
2489 | static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode) | ||
2490 | { | ||
2491 | __le32 param; | ||
2492 | |||
2493 | if (!priv) { | ||
2494 | IPW_ERROR("Invalid args\n"); | ||
2495 | return -1; | ||
2496 | } | ||
2497 | |||
2498 | /* If on battery, set to 3, if AC set to CAM, else user | ||
2499 | * level */ | ||
2500 | switch (mode) { | ||
2501 | case IPW_POWER_BATTERY: | ||
2502 | param = cpu_to_le32(IPW_POWER_INDEX_3); | ||
2503 | break; | ||
2504 | case IPW_POWER_AC: | ||
2505 | param = cpu_to_le32(IPW_POWER_MODE_CAM); | ||
2506 | break; | ||
2507 | default: | ||
2508 | param = cpu_to_le32(mode); | ||
2509 | break; | ||
2510 | } | ||
2511 | |||
2512 | return ipw_send_cmd_pdu(priv, IPW_CMD_POWER_MODE, sizeof(param), | ||
2513 | ¶m); | ||
2514 | } | ||
2515 | |||
2516 | static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit) | ||
2517 | { | ||
2518 | struct ipw_retry_limit retry_limit = { | ||
2519 | .short_retry_limit = slimit, | ||
2520 | .long_retry_limit = llimit | ||
2521 | }; | ||
2522 | |||
2523 | if (!priv) { | ||
2524 | IPW_ERROR("Invalid args\n"); | ||
2525 | return -1; | ||
2526 | } | ||
2527 | |||
2528 | return ipw_send_cmd_pdu(priv, IPW_CMD_RETRY_LIMIT, sizeof(retry_limit), | ||
2529 | &retry_limit); | ||
2530 | } | ||
2531 | |||
2532 | /* | ||
2533 | * The IPW device contains a Microwire compatible EEPROM that stores | ||
2534 | * various data like the MAC address. Usually the firmware has exclusive | ||
2535 | * access to the eeprom, but during device initialization (before the | ||
2536 | * device driver has sent the HostComplete command to the firmware) the | ||
2537 | * device driver has read access to the EEPROM by way of indirect addressing | ||
2538 | * through a couple of memory mapped registers. | ||
2539 | * | ||
2540 | * The following is a simplified implementation for pulling data out of the | ||
2541 | * the eeprom, along with some helper functions to find information in | ||
2542 | * the per device private data's copy of the eeprom. | ||
2543 | * | ||
2544 | * NOTE: To better understand how these functions work (i.e what is a chip | ||
2545 | * select and why do have to keep driving the eeprom clock?), read | ||
2546 | * just about any data sheet for a Microwire compatible EEPROM. | ||
2547 | */ | ||
2548 | |||
2549 | /* write a 32 bit value into the indirect accessor register */ | ||
2550 | static inline void eeprom_write_reg(struct ipw_priv *p, u32 data) | ||
2551 | { | ||
2552 | ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data); | ||
2553 | |||
2554 | /* the eeprom requires some time to complete the operation */ | ||
2555 | udelay(p->eeprom_delay); | ||
2556 | |||
2557 | return; | ||
2558 | } | ||
2559 | |||
2560 | /* perform a chip select operation */ | ||
2561 | static void eeprom_cs(struct ipw_priv *priv) | ||
2562 | { | ||
2563 | eeprom_write_reg(priv, 0); | ||
2564 | eeprom_write_reg(priv, EEPROM_BIT_CS); | ||
2565 | eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK); | ||
2566 | eeprom_write_reg(priv, EEPROM_BIT_CS); | ||
2567 | } | ||
2568 | |||
2569 | /* perform a chip select operation */ | ||
2570 | static void eeprom_disable_cs(struct ipw_priv *priv) | ||
2571 | { | ||
2572 | eeprom_write_reg(priv, EEPROM_BIT_CS); | ||
2573 | eeprom_write_reg(priv, 0); | ||
2574 | eeprom_write_reg(priv, EEPROM_BIT_SK); | ||
2575 | } | ||
2576 | |||
2577 | /* push a single bit down to the eeprom */ | ||
2578 | static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit) | ||
2579 | { | ||
2580 | int d = (bit ? EEPROM_BIT_DI : 0); | ||
2581 | eeprom_write_reg(p, EEPROM_BIT_CS | d); | ||
2582 | eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK); | ||
2583 | } | ||
2584 | |||
2585 | /* push an opcode followed by an address down to the eeprom */ | ||
2586 | static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr) | ||
2587 | { | ||
2588 | int i; | ||
2589 | |||
2590 | eeprom_cs(priv); | ||
2591 | eeprom_write_bit(priv, 1); | ||
2592 | eeprom_write_bit(priv, op & 2); | ||
2593 | eeprom_write_bit(priv, op & 1); | ||
2594 | for (i = 7; i >= 0; i--) { | ||
2595 | eeprom_write_bit(priv, addr & (1 << i)); | ||
2596 | } | ||
2597 | } | ||
2598 | |||
2599 | /* pull 16 bits off the eeprom, one bit at a time */ | ||
2600 | static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr) | ||
2601 | { | ||
2602 | int i; | ||
2603 | u16 r = 0; | ||
2604 | |||
2605 | /* Send READ Opcode */ | ||
2606 | eeprom_op(priv, EEPROM_CMD_READ, addr); | ||
2607 | |||
2608 | /* Send dummy bit */ | ||
2609 | eeprom_write_reg(priv, EEPROM_BIT_CS); | ||
2610 | |||
2611 | /* Read the byte off the eeprom one bit at a time */ | ||
2612 | for (i = 0; i < 16; i++) { | ||
2613 | u32 data = 0; | ||
2614 | eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK); | ||
2615 | eeprom_write_reg(priv, EEPROM_BIT_CS); | ||
2616 | data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS); | ||
2617 | r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0); | ||
2618 | } | ||
2619 | |||
2620 | /* Send another dummy bit */ | ||
2621 | eeprom_write_reg(priv, 0); | ||
2622 | eeprom_disable_cs(priv); | ||
2623 | |||
2624 | return r; | ||
2625 | } | ||
2626 | |||
2627 | /* helper function for pulling the mac address out of the private */ | ||
2628 | /* data's copy of the eeprom data */ | ||
2629 | static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac) | ||
2630 | { | ||
2631 | memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6); | ||
2632 | } | ||
2633 | |||
2634 | /* | ||
2635 | * Either the device driver (i.e. the host) or the firmware can | ||
2636 | * load eeprom data into the designated region in SRAM. If neither | ||
2637 | * happens then the FW will shutdown with a fatal error. | ||
2638 | * | ||
2639 | * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE | ||
2640 | * bit needs region of shared SRAM needs to be non-zero. | ||
2641 | */ | ||
2642 | static void ipw_eeprom_init_sram(struct ipw_priv *priv) | ||
2643 | { | ||
2644 | int i; | ||
2645 | __le16 *eeprom = (__le16 *) priv->eeprom; | ||
2646 | |||
2647 | IPW_DEBUG_TRACE(">>\n"); | ||
2648 | |||
2649 | /* read entire contents of eeprom into private buffer */ | ||
2650 | for (i = 0; i < 128; i++) | ||
2651 | eeprom[i] = cpu_to_le16(eeprom_read_u16(priv, (u8) i)); | ||
2652 | |||
2653 | /* | ||
2654 | If the data looks correct, then copy it to our private | ||
2655 | copy. Otherwise let the firmware know to perform the operation | ||
2656 | on its own. | ||
2657 | */ | ||
2658 | if (priv->eeprom[EEPROM_VERSION] != 0) { | ||
2659 | IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n"); | ||
2660 | |||
2661 | /* write the eeprom data to sram */ | ||
2662 | for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++) | ||
2663 | ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]); | ||
2664 | |||
2665 | /* Do not load eeprom data on fatal error or suspend */ | ||
2666 | ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0); | ||
2667 | } else { | ||
2668 | IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n"); | ||
2669 | |||
2670 | /* Load eeprom data on fatal error or suspend */ | ||
2671 | ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1); | ||
2672 | } | ||
2673 | |||
2674 | IPW_DEBUG_TRACE("<<\n"); | ||
2675 | } | ||
2676 | |||
2677 | static void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count) | ||
2678 | { | ||
2679 | count >>= 2; | ||
2680 | if (!count) | ||
2681 | return; | ||
2682 | _ipw_write32(priv, IPW_AUTOINC_ADDR, start); | ||
2683 | while (count--) | ||
2684 | _ipw_write32(priv, IPW_AUTOINC_DATA, 0); | ||
2685 | } | ||
2686 | |||
2687 | static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv) | ||
2688 | { | ||
2689 | ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL, | ||
2690 | CB_NUMBER_OF_ELEMENTS_SMALL * | ||
2691 | sizeof(struct command_block)); | ||
2692 | } | ||
2693 | |||
2694 | static int ipw_fw_dma_enable(struct ipw_priv *priv) | ||
2695 | { /* start dma engine but no transfers yet */ | ||
2696 | |||
2697 | IPW_DEBUG_FW(">> : \n"); | ||
2698 | |||
2699 | /* Start the dma */ | ||
2700 | ipw_fw_dma_reset_command_blocks(priv); | ||
2701 | |||
2702 | /* Write CB base address */ | ||
2703 | ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL); | ||
2704 | |||
2705 | IPW_DEBUG_FW("<< : \n"); | ||
2706 | return 0; | ||
2707 | } | ||
2708 | |||
2709 | static void ipw_fw_dma_abort(struct ipw_priv *priv) | ||
2710 | { | ||
2711 | u32 control = 0; | ||
2712 | |||
2713 | IPW_DEBUG_FW(">> :\n"); | ||
2714 | |||
2715 | /* set the Stop and Abort bit */ | ||
2716 | control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT; | ||
2717 | ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control); | ||
2718 | priv->sram_desc.last_cb_index = 0; | ||
2719 | |||
2720 | IPW_DEBUG_FW("<< \n"); | ||
2721 | } | ||
2722 | |||
2723 | static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index, | ||
2724 | struct command_block *cb) | ||
2725 | { | ||
2726 | u32 address = | ||
2727 | IPW_SHARED_SRAM_DMA_CONTROL + | ||
2728 | (sizeof(struct command_block) * index); | ||
2729 | IPW_DEBUG_FW(">> :\n"); | ||
2730 | |||
2731 | ipw_write_indirect(priv, address, (u8 *) cb, | ||
2732 | (int)sizeof(struct command_block)); | ||
2733 | |||
2734 | IPW_DEBUG_FW("<< :\n"); | ||
2735 | return 0; | ||
2736 | |||
2737 | } | ||
2738 | |||
2739 | static int ipw_fw_dma_kick(struct ipw_priv *priv) | ||
2740 | { | ||
2741 | u32 control = 0; | ||
2742 | u32 index = 0; | ||
2743 | |||
2744 | IPW_DEBUG_FW(">> :\n"); | ||
2745 | |||
2746 | for (index = 0; index < priv->sram_desc.last_cb_index; index++) | ||
2747 | ipw_fw_dma_write_command_block(priv, index, | ||
2748 | &priv->sram_desc.cb_list[index]); | ||
2749 | |||
2750 | /* Enable the DMA in the CSR register */ | ||
2751 | ipw_clear_bit(priv, IPW_RESET_REG, | ||
2752 | IPW_RESET_REG_MASTER_DISABLED | | ||
2753 | IPW_RESET_REG_STOP_MASTER); | ||
2754 | |||
2755 | /* Set the Start bit. */ | ||
2756 | control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START; | ||
2757 | ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control); | ||
2758 | |||
2759 | IPW_DEBUG_FW("<< :\n"); | ||
2760 | return 0; | ||
2761 | } | ||
2762 | |||
2763 | static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv) | ||
2764 | { | ||
2765 | u32 address; | ||
2766 | u32 register_value = 0; | ||
2767 | u32 cb_fields_address = 0; | ||
2768 | |||
2769 | IPW_DEBUG_FW(">> :\n"); | ||
2770 | address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB); | ||
2771 | IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address); | ||
2772 | |||
2773 | /* Read the DMA Controlor register */ | ||
2774 | register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL); | ||
2775 | IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x \n", register_value); | ||
2776 | |||
2777 | /* Print the CB values */ | ||
2778 | cb_fields_address = address; | ||
2779 | register_value = ipw_read_reg32(priv, cb_fields_address); | ||
2780 | IPW_DEBUG_FW_INFO("Current CB ControlField is 0x%x \n", register_value); | ||
2781 | |||
2782 | cb_fields_address += sizeof(u32); | ||
2783 | register_value = ipw_read_reg32(priv, cb_fields_address); | ||
2784 | IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x \n", register_value); | ||
2785 | |||
2786 | cb_fields_address += sizeof(u32); | ||
2787 | register_value = ipw_read_reg32(priv, cb_fields_address); | ||
2788 | IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n", | ||
2789 | register_value); | ||
2790 | |||
2791 | cb_fields_address += sizeof(u32); | ||
2792 | register_value = ipw_read_reg32(priv, cb_fields_address); | ||
2793 | IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x \n", register_value); | ||
2794 | |||
2795 | IPW_DEBUG_FW(">> :\n"); | ||
2796 | } | ||
2797 | |||
2798 | static int ipw_fw_dma_command_block_index(struct ipw_priv *priv) | ||
2799 | { | ||
2800 | u32 current_cb_address = 0; | ||
2801 | u32 current_cb_index = 0; | ||
2802 | |||
2803 | IPW_DEBUG_FW("<< :\n"); | ||
2804 | current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB); | ||
2805 | |||
2806 | current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) / | ||
2807 | sizeof(struct command_block); | ||
2808 | |||
2809 | IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n", | ||
2810 | current_cb_index, current_cb_address); | ||
2811 | |||
2812 | IPW_DEBUG_FW(">> :\n"); | ||
2813 | return current_cb_index; | ||
2814 | |||
2815 | } | ||
2816 | |||
2817 | static int ipw_fw_dma_add_command_block(struct ipw_priv *priv, | ||
2818 | u32 src_address, | ||
2819 | u32 dest_address, | ||
2820 | u32 length, | ||
2821 | int interrupt_enabled, int is_last) | ||
2822 | { | ||
2823 | |||
2824 | u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC | | ||
2825 | CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG | | ||
2826 | CB_DEST_SIZE_LONG; | ||
2827 | struct command_block *cb; | ||
2828 | u32 last_cb_element = 0; | ||
2829 | |||
2830 | IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n", | ||
2831 | src_address, dest_address, length); | ||
2832 | |||
2833 | if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL) | ||
2834 | return -1; | ||
2835 | |||
2836 | last_cb_element = priv->sram_desc.last_cb_index; | ||
2837 | cb = &priv->sram_desc.cb_list[last_cb_element]; | ||
2838 | priv->sram_desc.last_cb_index++; | ||
2839 | |||
2840 | /* Calculate the new CB control word */ | ||
2841 | if (interrupt_enabled) | ||
2842 | control |= CB_INT_ENABLED; | ||
2843 | |||
2844 | if (is_last) | ||
2845 | control |= CB_LAST_VALID; | ||
2846 | |||
2847 | control |= length; | ||
2848 | |||
2849 | /* Calculate the CB Element's checksum value */ | ||
2850 | cb->status = control ^ src_address ^ dest_address; | ||
2851 | |||
2852 | /* Copy the Source and Destination addresses */ | ||
2853 | cb->dest_addr = dest_address; | ||
2854 | cb->source_addr = src_address; | ||
2855 | |||
2856 | /* Copy the Control Word last */ | ||
2857 | cb->control = control; | ||
2858 | |||
2859 | return 0; | ||
2860 | } | ||
2861 | |||
2862 | static int ipw_fw_dma_add_buffer(struct ipw_priv *priv, | ||
2863 | u32 src_phys, u32 dest_address, u32 length) | ||
2864 | { | ||
2865 | u32 bytes_left = length; | ||
2866 | u32 src_offset = 0; | ||
2867 | u32 dest_offset = 0; | ||
2868 | int status = 0; | ||
2869 | IPW_DEBUG_FW(">> \n"); | ||
2870 | IPW_DEBUG_FW_INFO("src_phys=0x%x dest_address=0x%x length=0x%x\n", | ||
2871 | src_phys, dest_address, length); | ||
2872 | while (bytes_left > CB_MAX_LENGTH) { | ||
2873 | status = ipw_fw_dma_add_command_block(priv, | ||
2874 | src_phys + src_offset, | ||
2875 | dest_address + | ||
2876 | dest_offset, | ||
2877 | CB_MAX_LENGTH, 0, 0); | ||
2878 | if (status) { | ||
2879 | IPW_DEBUG_FW_INFO(": Failed\n"); | ||
2880 | return -1; | ||
2881 | } else | ||
2882 | IPW_DEBUG_FW_INFO(": Added new cb\n"); | ||
2883 | |||
2884 | src_offset += CB_MAX_LENGTH; | ||
2885 | dest_offset += CB_MAX_LENGTH; | ||
2886 | bytes_left -= CB_MAX_LENGTH; | ||
2887 | } | ||
2888 | |||
2889 | /* add the buffer tail */ | ||
2890 | if (bytes_left > 0) { | ||
2891 | status = | ||
2892 | ipw_fw_dma_add_command_block(priv, src_phys + src_offset, | ||
2893 | dest_address + dest_offset, | ||
2894 | bytes_left, 0, 0); | ||
2895 | if (status) { | ||
2896 | IPW_DEBUG_FW_INFO(": Failed on the buffer tail\n"); | ||
2897 | return -1; | ||
2898 | } else | ||
2899 | IPW_DEBUG_FW_INFO | ||
2900 | (": Adding new cb - the buffer tail\n"); | ||
2901 | } | ||
2902 | |||
2903 | IPW_DEBUG_FW("<< \n"); | ||
2904 | return 0; | ||
2905 | } | ||
2906 | |||
2907 | static int ipw_fw_dma_wait(struct ipw_priv *priv) | ||
2908 | { | ||
2909 | u32 current_index = 0, previous_index; | ||
2910 | u32 watchdog = 0; | ||
2911 | |||
2912 | IPW_DEBUG_FW(">> : \n"); | ||
2913 | |||
2914 | current_index = ipw_fw_dma_command_block_index(priv); | ||
2915 | IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%08X\n", | ||
2916 | (int)priv->sram_desc.last_cb_index); | ||
2917 | |||
2918 | while (current_index < priv->sram_desc.last_cb_index) { | ||
2919 | udelay(50); | ||
2920 | previous_index = current_index; | ||
2921 | current_index = ipw_fw_dma_command_block_index(priv); | ||
2922 | |||
2923 | if (previous_index < current_index) { | ||
2924 | watchdog = 0; | ||
2925 | continue; | ||
2926 | } | ||
2927 | if (++watchdog > 400) { | ||
2928 | IPW_DEBUG_FW_INFO("Timeout\n"); | ||
2929 | ipw_fw_dma_dump_command_block(priv); | ||
2930 | ipw_fw_dma_abort(priv); | ||
2931 | return -1; | ||
2932 | } | ||
2933 | } | ||
2934 | |||
2935 | ipw_fw_dma_abort(priv); | ||
2936 | |||
2937 | /*Disable the DMA in the CSR register */ | ||
2938 | ipw_set_bit(priv, IPW_RESET_REG, | ||
2939 | IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER); | ||
2940 | |||
2941 | IPW_DEBUG_FW("<< dmaWaitSync \n"); | ||
2942 | return 0; | ||
2943 | } | ||
2944 | |||
2945 | static void ipw_remove_current_network(struct ipw_priv *priv) | ||
2946 | { | ||
2947 | struct list_head *element, *safe; | ||
2948 | struct ieee80211_network *network = NULL; | ||
2949 | unsigned long flags; | ||
2950 | |||
2951 | spin_lock_irqsave(&priv->ieee->lock, flags); | ||
2952 | list_for_each_safe(element, safe, &priv->ieee->network_list) { | ||
2953 | network = list_entry(element, struct ieee80211_network, list); | ||
2954 | if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) { | ||
2955 | list_del(element); | ||
2956 | list_add_tail(&network->list, | ||
2957 | &priv->ieee->network_free_list); | ||
2958 | } | ||
2959 | } | ||
2960 | spin_unlock_irqrestore(&priv->ieee->lock, flags); | ||
2961 | } | ||
2962 | |||
2963 | /** | ||
2964 | * Check that card is still alive. | ||
2965 | * Reads debug register from domain0. | ||
2966 | * If card is present, pre-defined value should | ||
2967 | * be found there. | ||
2968 | * | ||
2969 | * @param priv | ||
2970 | * @return 1 if card is present, 0 otherwise | ||
2971 | */ | ||
2972 | static inline int ipw_alive(struct ipw_priv *priv) | ||
2973 | { | ||
2974 | return ipw_read32(priv, 0x90) == 0xd55555d5; | ||
2975 | } | ||
2976 | |||
2977 | /* timeout in msec, attempted in 10-msec quanta */ | ||
2978 | static int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask, | ||
2979 | int timeout) | ||
2980 | { | ||
2981 | int i = 0; | ||
2982 | |||
2983 | do { | ||
2984 | if ((ipw_read32(priv, addr) & mask) == mask) | ||
2985 | return i; | ||
2986 | mdelay(10); | ||
2987 | i += 10; | ||
2988 | } while (i < timeout); | ||
2989 | |||
2990 | return -ETIME; | ||
2991 | } | ||
2992 | |||
2993 | /* These functions load the firmware and micro code for the operation of | ||
2994 | * the ipw hardware. It assumes the buffer has all the bits for the | ||
2995 | * image and the caller is handling the memory allocation and clean up. | ||
2996 | */ | ||
2997 | |||
2998 | static int ipw_stop_master(struct ipw_priv *priv) | ||
2999 | { | ||
3000 | int rc; | ||
3001 | |||
3002 | IPW_DEBUG_TRACE(">> \n"); | ||
3003 | /* stop master. typical delay - 0 */ | ||
3004 | ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER); | ||
3005 | |||
3006 | /* timeout is in msec, polled in 10-msec quanta */ | ||
3007 | rc = ipw_poll_bit(priv, IPW_RESET_REG, | ||
3008 | IPW_RESET_REG_MASTER_DISABLED, 100); | ||
3009 | if (rc < 0) { | ||
3010 | IPW_ERROR("wait for stop master failed after 100ms\n"); | ||
3011 | return -1; | ||
3012 | } | ||
3013 | |||
3014 | IPW_DEBUG_INFO("stop master %dms\n", rc); | ||
3015 | |||
3016 | return rc; | ||
3017 | } | ||
3018 | |||
3019 | static void ipw_arc_release(struct ipw_priv *priv) | ||
3020 | { | ||
3021 | IPW_DEBUG_TRACE(">> \n"); | ||
3022 | mdelay(5); | ||
3023 | |||
3024 | ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET); | ||
3025 | |||
3026 | /* no one knows timing, for safety add some delay */ | ||
3027 | mdelay(5); | ||
3028 | } | ||
3029 | |||
3030 | struct fw_chunk { | ||
3031 | __le32 address; | ||
3032 | __le32 length; | ||
3033 | }; | ||
3034 | |||
3035 | static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len) | ||
3036 | { | ||
3037 | int rc = 0, i, addr; | ||
3038 | u8 cr = 0; | ||
3039 | __le16 *image; | ||
3040 | |||
3041 | image = (__le16 *) data; | ||
3042 | |||
3043 | IPW_DEBUG_TRACE(">> \n"); | ||
3044 | |||
3045 | rc = ipw_stop_master(priv); | ||
3046 | |||
3047 | if (rc < 0) | ||
3048 | return rc; | ||
3049 | |||
3050 | for (addr = IPW_SHARED_LOWER_BOUND; | ||
3051 | addr < IPW_REGISTER_DOMAIN1_END; addr += 4) { | ||
3052 | ipw_write32(priv, addr, 0); | ||
3053 | } | ||
3054 | |||
3055 | /* no ucode (yet) */ | ||
3056 | memset(&priv->dino_alive, 0, sizeof(priv->dino_alive)); | ||
3057 | /* destroy DMA queues */ | ||
3058 | /* reset sequence */ | ||
3059 | |||
3060 | ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON); | ||
3061 | ipw_arc_release(priv); | ||
3062 | ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF); | ||
3063 | mdelay(1); | ||
3064 | |||
3065 | /* reset PHY */ | ||
3066 | ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN); | ||
3067 | mdelay(1); | ||
3068 | |||
3069 | ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0); | ||
3070 | mdelay(1); | ||
3071 | |||
3072 | /* enable ucode store */ | ||
3073 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0x0); | ||
3074 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_CS); | ||
3075 | mdelay(1); | ||
3076 | |||
3077 | /* write ucode */ | ||
3078 | /** | ||
3079 | * @bug | ||
3080 | * Do NOT set indirect address register once and then | ||
3081 | * store data to indirect data register in the loop. | ||
3082 | * It seems very reasonable, but in this case DINO do not | ||
3083 | * accept ucode. It is essential to set address each time. | ||
3084 | */ | ||
3085 | /* load new ipw uCode */ | ||
3086 | for (i = 0; i < len / 2; i++) | ||
3087 | ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE, | ||
3088 | le16_to_cpu(image[i])); | ||
3089 | |||
3090 | /* enable DINO */ | ||
3091 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0); | ||
3092 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM); | ||
3093 | |||
3094 | /* this is where the igx / win driver deveates from the VAP driver. */ | ||
3095 | |||
3096 | /* wait for alive response */ | ||
3097 | for (i = 0; i < 100; i++) { | ||
3098 | /* poll for incoming data */ | ||
3099 | cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS); | ||
3100 | if (cr & DINO_RXFIFO_DATA) | ||
3101 | break; | ||
3102 | mdelay(1); | ||
3103 | } | ||
3104 | |||
3105 | if (cr & DINO_RXFIFO_DATA) { | ||
3106 | /* alive_command_responce size is NOT multiple of 4 */ | ||
3107 | __le32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4]; | ||
3108 | |||
3109 | for (i = 0; i < ARRAY_SIZE(response_buffer); i++) | ||
3110 | response_buffer[i] = | ||
3111 | cpu_to_le32(ipw_read_reg32(priv, | ||
3112 | IPW_BASEBAND_RX_FIFO_READ)); | ||
3113 | memcpy(&priv->dino_alive, response_buffer, | ||
3114 | sizeof(priv->dino_alive)); | ||
3115 | if (priv->dino_alive.alive_command == 1 | ||
3116 | && priv->dino_alive.ucode_valid == 1) { | ||
3117 | rc = 0; | ||
3118 | IPW_DEBUG_INFO | ||
3119 | ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) " | ||
3120 | "of %02d/%02d/%02d %02d:%02d\n", | ||
3121 | priv->dino_alive.software_revision, | ||
3122 | priv->dino_alive.software_revision, | ||
3123 | priv->dino_alive.device_identifier, | ||
3124 | priv->dino_alive.device_identifier, | ||
3125 | priv->dino_alive.time_stamp[0], | ||
3126 | priv->dino_alive.time_stamp[1], | ||
3127 | priv->dino_alive.time_stamp[2], | ||
3128 | priv->dino_alive.time_stamp[3], | ||
3129 | priv->dino_alive.time_stamp[4]); | ||
3130 | } else { | ||
3131 | IPW_DEBUG_INFO("Microcode is not alive\n"); | ||
3132 | rc = -EINVAL; | ||
3133 | } | ||
3134 | } else { | ||
3135 | IPW_DEBUG_INFO("No alive response from DINO\n"); | ||
3136 | rc = -ETIME; | ||
3137 | } | ||
3138 | |||
3139 | /* disable DINO, otherwise for some reason | ||
3140 | firmware have problem getting alive resp. */ | ||
3141 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0); | ||
3142 | |||
3143 | return rc; | ||
3144 | } | ||
3145 | |||
3146 | static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len) | ||
3147 | { | ||
3148 | int rc = -1; | ||
3149 | int offset = 0; | ||
3150 | struct fw_chunk *chunk; | ||
3151 | dma_addr_t shared_phys; | ||
3152 | u8 *shared_virt; | ||
3153 | |||
3154 | IPW_DEBUG_TRACE("<< : \n"); | ||
3155 | shared_virt = pci_alloc_consistent(priv->pci_dev, len, &shared_phys); | ||
3156 | |||
3157 | if (!shared_virt) | ||
3158 | return -ENOMEM; | ||
3159 | |||
3160 | memmove(shared_virt, data, len); | ||
3161 | |||
3162 | /* Start the Dma */ | ||
3163 | rc = ipw_fw_dma_enable(priv); | ||
3164 | |||
3165 | if (priv->sram_desc.last_cb_index > 0) { | ||
3166 | /* the DMA is already ready this would be a bug. */ | ||
3167 | BUG(); | ||
3168 | goto out; | ||
3169 | } | ||
3170 | |||
3171 | do { | ||
3172 | chunk = (struct fw_chunk *)(data + offset); | ||
3173 | offset += sizeof(struct fw_chunk); | ||
3174 | /* build DMA packet and queue up for sending */ | ||
3175 | /* dma to chunk->address, the chunk->length bytes from data + | ||
3176 | * offeset*/ | ||
3177 | /* Dma loading */ | ||
3178 | rc = ipw_fw_dma_add_buffer(priv, shared_phys + offset, | ||
3179 | le32_to_cpu(chunk->address), | ||
3180 | le32_to_cpu(chunk->length)); | ||
3181 | if (rc) { | ||
3182 | IPW_DEBUG_INFO("dmaAddBuffer Failed\n"); | ||
3183 | goto out; | ||
3184 | } | ||
3185 | |||
3186 | offset += le32_to_cpu(chunk->length); | ||
3187 | } while (offset < len); | ||
3188 | |||
3189 | /* Run the DMA and wait for the answer */ | ||
3190 | rc = ipw_fw_dma_kick(priv); | ||
3191 | if (rc) { | ||
3192 | IPW_ERROR("dmaKick Failed\n"); | ||
3193 | goto out; | ||
3194 | } | ||
3195 | |||
3196 | rc = ipw_fw_dma_wait(priv); | ||
3197 | if (rc) { | ||
3198 | IPW_ERROR("dmaWaitSync Failed\n"); | ||
3199 | goto out; | ||
3200 | } | ||
3201 | out: | ||
3202 | pci_free_consistent(priv->pci_dev, len, shared_virt, shared_phys); | ||
3203 | return rc; | ||
3204 | } | ||
3205 | |||
3206 | /* stop nic */ | ||
3207 | static int ipw_stop_nic(struct ipw_priv *priv) | ||
3208 | { | ||
3209 | int rc = 0; | ||
3210 | |||
3211 | /* stop */ | ||
3212 | ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER); | ||
3213 | |||
3214 | rc = ipw_poll_bit(priv, IPW_RESET_REG, | ||
3215 | IPW_RESET_REG_MASTER_DISABLED, 500); | ||
3216 | if (rc < 0) { | ||
3217 | IPW_ERROR("wait for reg master disabled failed after 500ms\n"); | ||
3218 | return rc; | ||
3219 | } | ||
3220 | |||
3221 | ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET); | ||
3222 | |||
3223 | return rc; | ||
3224 | } | ||
3225 | |||
3226 | static void ipw_start_nic(struct ipw_priv *priv) | ||
3227 | { | ||
3228 | IPW_DEBUG_TRACE(">>\n"); | ||
3229 | |||
3230 | /* prvHwStartNic release ARC */ | ||
3231 | ipw_clear_bit(priv, IPW_RESET_REG, | ||
3232 | IPW_RESET_REG_MASTER_DISABLED | | ||
3233 | IPW_RESET_REG_STOP_MASTER | | ||
3234 | CBD_RESET_REG_PRINCETON_RESET); | ||
3235 | |||
3236 | /* enable power management */ | ||
3237 | ipw_set_bit(priv, IPW_GP_CNTRL_RW, | ||
3238 | IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY); | ||
3239 | |||
3240 | IPW_DEBUG_TRACE("<<\n"); | ||
3241 | } | ||
3242 | |||
3243 | static int ipw_init_nic(struct ipw_priv *priv) | ||
3244 | { | ||
3245 | int rc; | ||
3246 | |||
3247 | IPW_DEBUG_TRACE(">>\n"); | ||
3248 | /* reset */ | ||
3249 | /*prvHwInitNic */ | ||
3250 | /* set "initialization complete" bit to move adapter to D0 state */ | ||
3251 | ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE); | ||
3252 | |||
3253 | /* low-level PLL activation */ | ||
3254 | ipw_write32(priv, IPW_READ_INT_REGISTER, | ||
3255 | IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER); | ||
3256 | |||
3257 | /* wait for clock stabilization */ | ||
3258 | rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW, | ||
3259 | IPW_GP_CNTRL_BIT_CLOCK_READY, 250); | ||
3260 | if (rc < 0) | ||
3261 | IPW_DEBUG_INFO("FAILED wait for clock stablization\n"); | ||
3262 | |||
3263 | /* assert SW reset */ | ||
3264 | ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET); | ||
3265 | |||
3266 | udelay(10); | ||
3267 | |||
3268 | /* set "initialization complete" bit to move adapter to D0 state */ | ||
3269 | ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE); | ||
3270 | |||
3271 | IPW_DEBUG_TRACE(">>\n"); | ||
3272 | return 0; | ||
3273 | } | ||
3274 | |||
3275 | /* Call this function from process context, it will sleep in request_firmware. | ||
3276 | * Probe is an ok place to call this from. | ||
3277 | */ | ||
3278 | static int ipw_reset_nic(struct ipw_priv *priv) | ||
3279 | { | ||
3280 | int rc = 0; | ||
3281 | unsigned long flags; | ||
3282 | |||
3283 | IPW_DEBUG_TRACE(">>\n"); | ||
3284 | |||
3285 | rc = ipw_init_nic(priv); | ||
3286 | |||
3287 | spin_lock_irqsave(&priv->lock, flags); | ||
3288 | /* Clear the 'host command active' bit... */ | ||
3289 | priv->status &= ~STATUS_HCMD_ACTIVE; | ||
3290 | wake_up_interruptible(&priv->wait_command_queue); | ||
3291 | priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING); | ||
3292 | wake_up_interruptible(&priv->wait_state); | ||
3293 | spin_unlock_irqrestore(&priv->lock, flags); | ||
3294 | |||
3295 | IPW_DEBUG_TRACE("<<\n"); | ||
3296 | return rc; | ||
3297 | } | ||
3298 | |||
3299 | |||
3300 | struct ipw_fw { | ||
3301 | __le32 ver; | ||
3302 | __le32 boot_size; | ||
3303 | __le32 ucode_size; | ||
3304 | __le32 fw_size; | ||
3305 | u8 data[0]; | ||
3306 | }; | ||
3307 | |||
3308 | static int ipw_get_fw(struct ipw_priv *priv, | ||
3309 | const struct firmware **raw, const char *name) | ||
3310 | { | ||
3311 | struct ipw_fw *fw; | ||
3312 | int rc; | ||
3313 | |||
3314 | /* ask firmware_class module to get the boot firmware off disk */ | ||
3315 | rc = request_firmware(raw, name, &priv->pci_dev->dev); | ||
3316 | if (rc < 0) { | ||
3317 | IPW_ERROR("%s request_firmware failed: Reason %d\n", name, rc); | ||
3318 | return rc; | ||
3319 | } | ||
3320 | |||
3321 | if ((*raw)->size < sizeof(*fw)) { | ||
3322 | IPW_ERROR("%s is too small (%zd)\n", name, (*raw)->size); | ||
3323 | return -EINVAL; | ||
3324 | } | ||
3325 | |||
3326 | fw = (void *)(*raw)->data; | ||
3327 | |||
3328 | if ((*raw)->size < sizeof(*fw) + le32_to_cpu(fw->boot_size) + | ||
3329 | le32_to_cpu(fw->ucode_size) + le32_to_cpu(fw->fw_size)) { | ||
3330 | IPW_ERROR("%s is too small or corrupt (%zd)\n", | ||
3331 | name, (*raw)->size); | ||
3332 | return -EINVAL; | ||
3333 | } | ||
3334 | |||
3335 | IPW_DEBUG_INFO("Read firmware '%s' image v%d.%d (%zd bytes)\n", | ||
3336 | name, | ||
3337 | le32_to_cpu(fw->ver) >> 16, | ||
3338 | le32_to_cpu(fw->ver) & 0xff, | ||
3339 | (*raw)->size - sizeof(*fw)); | ||
3340 | return 0; | ||
3341 | } | ||
3342 | |||
3343 | #define IPW_RX_BUF_SIZE (3000) | ||
3344 | |||
3345 | static void ipw_rx_queue_reset(struct ipw_priv *priv, | ||
3346 | struct ipw_rx_queue *rxq) | ||
3347 | { | ||
3348 | unsigned long flags; | ||
3349 | int i; | ||
3350 | |||
3351 | spin_lock_irqsave(&rxq->lock, flags); | ||
3352 | |||
3353 | INIT_LIST_HEAD(&rxq->rx_free); | ||
3354 | INIT_LIST_HEAD(&rxq->rx_used); | ||
3355 | |||
3356 | /* Fill the rx_used queue with _all_ of the Rx buffers */ | ||
3357 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) { | ||
3358 | /* In the reset function, these buffers may have been allocated | ||
3359 | * to an SKB, so we need to unmap and free potential storage */ | ||
3360 | if (rxq->pool[i].skb != NULL) { | ||
3361 | pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr, | ||
3362 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); | ||
3363 | dev_kfree_skb(rxq->pool[i].skb); | ||
3364 | rxq->pool[i].skb = NULL; | ||
3365 | } | ||
3366 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); | ||
3367 | } | ||
3368 | |||
3369 | /* Set us so that we have processed and used all buffers, but have | ||
3370 | * not restocked the Rx queue with fresh buffers */ | ||
3371 | rxq->read = rxq->write = 0; | ||
3372 | rxq->free_count = 0; | ||
3373 | spin_unlock_irqrestore(&rxq->lock, flags); | ||
3374 | } | ||
3375 | |||
3376 | #ifdef CONFIG_PM | ||
3377 | static int fw_loaded = 0; | ||
3378 | static const struct firmware *raw = NULL; | ||
3379 | |||
3380 | static void free_firmware(void) | ||
3381 | { | ||
3382 | if (fw_loaded) { | ||
3383 | release_firmware(raw); | ||
3384 | raw = NULL; | ||
3385 | fw_loaded = 0; | ||
3386 | } | ||
3387 | } | ||
3388 | #else | ||
3389 | #define free_firmware() do {} while (0) | ||
3390 | #endif | ||
3391 | |||
3392 | static int ipw_load(struct ipw_priv *priv) | ||
3393 | { | ||
3394 | #ifndef CONFIG_PM | ||
3395 | const struct firmware *raw = NULL; | ||
3396 | #endif | ||
3397 | struct ipw_fw *fw; | ||
3398 | u8 *boot_img, *ucode_img, *fw_img; | ||
3399 | u8 *name = NULL; | ||
3400 | int rc = 0, retries = 3; | ||
3401 | |||
3402 | switch (priv->ieee->iw_mode) { | ||
3403 | case IW_MODE_ADHOC: | ||
3404 | name = "ipw2200-ibss.fw"; | ||
3405 | break; | ||
3406 | #ifdef CONFIG_IPW2200_MONITOR | ||
3407 | case IW_MODE_MONITOR: | ||
3408 | name = "ipw2200-sniffer.fw"; | ||
3409 | break; | ||
3410 | #endif | ||
3411 | case IW_MODE_INFRA: | ||
3412 | name = "ipw2200-bss.fw"; | ||
3413 | break; | ||
3414 | } | ||
3415 | |||
3416 | if (!name) { | ||
3417 | rc = -EINVAL; | ||
3418 | goto error; | ||
3419 | } | ||
3420 | |||
3421 | #ifdef CONFIG_PM | ||
3422 | if (!fw_loaded) { | ||
3423 | #endif | ||
3424 | rc = ipw_get_fw(priv, &raw, name); | ||
3425 | if (rc < 0) | ||
3426 | goto error; | ||
3427 | #ifdef CONFIG_PM | ||
3428 | } | ||
3429 | #endif | ||
3430 | |||
3431 | fw = (void *)raw->data; | ||
3432 | boot_img = &fw->data[0]; | ||
3433 | ucode_img = &fw->data[le32_to_cpu(fw->boot_size)]; | ||
3434 | fw_img = &fw->data[le32_to_cpu(fw->boot_size) + | ||
3435 | le32_to_cpu(fw->ucode_size)]; | ||
3436 | |||
3437 | if (rc < 0) | ||
3438 | goto error; | ||
3439 | |||
3440 | if (!priv->rxq) | ||
3441 | priv->rxq = ipw_rx_queue_alloc(priv); | ||
3442 | else | ||
3443 | ipw_rx_queue_reset(priv, priv->rxq); | ||
3444 | if (!priv->rxq) { | ||
3445 | IPW_ERROR("Unable to initialize Rx queue\n"); | ||
3446 | goto error; | ||
3447 | } | ||
3448 | |||
3449 | retry: | ||
3450 | /* Ensure interrupts are disabled */ | ||
3451 | ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL); | ||
3452 | priv->status &= ~STATUS_INT_ENABLED; | ||
3453 | |||
3454 | /* ack pending interrupts */ | ||
3455 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); | ||
3456 | |||
3457 | ipw_stop_nic(priv); | ||
3458 | |||
3459 | rc = ipw_reset_nic(priv); | ||
3460 | if (rc < 0) { | ||
3461 | IPW_ERROR("Unable to reset NIC\n"); | ||
3462 | goto error; | ||
3463 | } | ||
3464 | |||
3465 | ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND, | ||
3466 | IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND); | ||
3467 | |||
3468 | /* DMA the initial boot firmware into the device */ | ||
3469 | rc = ipw_load_firmware(priv, boot_img, le32_to_cpu(fw->boot_size)); | ||
3470 | if (rc < 0) { | ||
3471 | IPW_ERROR("Unable to load boot firmware: %d\n", rc); | ||
3472 | goto error; | ||
3473 | } | ||
3474 | |||
3475 | /* kick start the device */ | ||
3476 | ipw_start_nic(priv); | ||
3477 | |||
3478 | /* wait for the device to finish its initial startup sequence */ | ||
3479 | rc = ipw_poll_bit(priv, IPW_INTA_RW, | ||
3480 | IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500); | ||
3481 | if (rc < 0) { | ||
3482 | IPW_ERROR("device failed to boot initial fw image\n"); | ||
3483 | goto error; | ||
3484 | } | ||
3485 | IPW_DEBUG_INFO("initial device response after %dms\n", rc); | ||
3486 | |||
3487 | /* ack fw init done interrupt */ | ||
3488 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE); | ||
3489 | |||
3490 | /* DMA the ucode into the device */ | ||
3491 | rc = ipw_load_ucode(priv, ucode_img, le32_to_cpu(fw->ucode_size)); | ||
3492 | if (rc < 0) { | ||
3493 | IPW_ERROR("Unable to load ucode: %d\n", rc); | ||
3494 | goto error; | ||
3495 | } | ||
3496 | |||
3497 | /* stop nic */ | ||
3498 | ipw_stop_nic(priv); | ||
3499 | |||
3500 | /* DMA bss firmware into the device */ | ||
3501 | rc = ipw_load_firmware(priv, fw_img, le32_to_cpu(fw->fw_size)); | ||
3502 | if (rc < 0) { | ||
3503 | IPW_ERROR("Unable to load firmware: %d\n", rc); | ||
3504 | goto error; | ||
3505 | } | ||
3506 | #ifdef CONFIG_PM | ||
3507 | fw_loaded = 1; | ||
3508 | #endif | ||
3509 | |||
3510 | ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0); | ||
3511 | |||
3512 | rc = ipw_queue_reset(priv); | ||
3513 | if (rc < 0) { | ||
3514 | IPW_ERROR("Unable to initialize queues\n"); | ||
3515 | goto error; | ||
3516 | } | ||
3517 | |||
3518 | /* Ensure interrupts are disabled */ | ||
3519 | ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL); | ||
3520 | /* ack pending interrupts */ | ||
3521 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); | ||
3522 | |||
3523 | /* kick start the device */ | ||
3524 | ipw_start_nic(priv); | ||
3525 | |||
3526 | if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) { | ||
3527 | if (retries > 0) { | ||
3528 | IPW_WARNING("Parity error. Retrying init.\n"); | ||
3529 | retries--; | ||
3530 | goto retry; | ||
3531 | } | ||
3532 | |||
3533 | IPW_ERROR("TODO: Handle parity error -- schedule restart?\n"); | ||
3534 | rc = -EIO; | ||
3535 | goto error; | ||
3536 | } | ||
3537 | |||
3538 | /* wait for the device */ | ||
3539 | rc = ipw_poll_bit(priv, IPW_INTA_RW, | ||
3540 | IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500); | ||
3541 | if (rc < 0) { | ||
3542 | IPW_ERROR("device failed to start within 500ms\n"); | ||
3543 | goto error; | ||
3544 | } | ||
3545 | IPW_DEBUG_INFO("device response after %dms\n", rc); | ||
3546 | |||
3547 | /* ack fw init done interrupt */ | ||
3548 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE); | ||
3549 | |||
3550 | /* read eeprom data and initialize the eeprom region of sram */ | ||
3551 | priv->eeprom_delay = 1; | ||
3552 | ipw_eeprom_init_sram(priv); | ||
3553 | |||
3554 | /* enable interrupts */ | ||
3555 | ipw_enable_interrupts(priv); | ||
3556 | |||
3557 | /* Ensure our queue has valid packets */ | ||
3558 | ipw_rx_queue_replenish(priv); | ||
3559 | |||
3560 | ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read); | ||
3561 | |||
3562 | /* ack pending interrupts */ | ||
3563 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); | ||
3564 | |||
3565 | #ifndef CONFIG_PM | ||
3566 | release_firmware(raw); | ||
3567 | #endif | ||
3568 | return 0; | ||
3569 | |||
3570 | error: | ||
3571 | if (priv->rxq) { | ||
3572 | ipw_rx_queue_free(priv, priv->rxq); | ||
3573 | priv->rxq = NULL; | ||
3574 | } | ||
3575 | ipw_tx_queue_free(priv); | ||
3576 | if (raw) | ||
3577 | release_firmware(raw); | ||
3578 | #ifdef CONFIG_PM | ||
3579 | fw_loaded = 0; | ||
3580 | raw = NULL; | ||
3581 | #endif | ||
3582 | |||
3583 | return rc; | ||
3584 | } | ||
3585 | |||
3586 | /** | ||
3587 | * DMA services | ||
3588 | * | ||
3589 | * Theory of operation | ||
3590 | * | ||
3591 | * A queue is a circular buffers with 'Read' and 'Write' pointers. | ||
3592 | * 2 empty entries always kept in the buffer to protect from overflow. | ||
3593 | * | ||
3594 | * For Tx queue, there are low mark and high mark limits. If, after queuing | ||
3595 | * the packet for Tx, free space become < low mark, Tx queue stopped. When | ||
3596 | * reclaiming packets (on 'tx done IRQ), if free space become > high mark, | ||
3597 | * Tx queue resumed. | ||
3598 | * | ||
3599 | * The IPW operates with six queues, one receive queue in the device's | ||
3600 | * sram, one transmit queue for sending commands to the device firmware, | ||
3601 | * and four transmit queues for data. | ||
3602 | * | ||
3603 | * The four transmit queues allow for performing quality of service (qos) | ||
3604 | * transmissions as per the 802.11 protocol. Currently Linux does not | ||
3605 | * provide a mechanism to the user for utilizing prioritized queues, so | ||
3606 | * we only utilize the first data transmit queue (queue1). | ||
3607 | */ | ||
3608 | |||
3609 | /** | ||
3610 | * Driver allocates buffers of this size for Rx | ||
3611 | */ | ||
3612 | |||
3613 | /** | ||
3614 | * ipw_rx_queue_space - Return number of free slots available in queue. | ||
3615 | */ | ||
3616 | static int ipw_rx_queue_space(const struct ipw_rx_queue *q) | ||
3617 | { | ||
3618 | int s = q->read - q->write; | ||
3619 | if (s <= 0) | ||
3620 | s += RX_QUEUE_SIZE; | ||
3621 | /* keep some buffer to not confuse full and empty queue */ | ||
3622 | s -= 2; | ||
3623 | if (s < 0) | ||
3624 | s = 0; | ||
3625 | return s; | ||
3626 | } | ||
3627 | |||
3628 | static inline int ipw_tx_queue_space(const struct clx2_queue *q) | ||
3629 | { | ||
3630 | int s = q->last_used - q->first_empty; | ||
3631 | if (s <= 0) | ||
3632 | s += q->n_bd; | ||
3633 | s -= 2; /* keep some reserve to not confuse empty and full situations */ | ||
3634 | if (s < 0) | ||
3635 | s = 0; | ||
3636 | return s; | ||
3637 | } | ||
3638 | |||
3639 | static inline int ipw_queue_inc_wrap(int index, int n_bd) | ||
3640 | { | ||
3641 | return (++index == n_bd) ? 0 : index; | ||
3642 | } | ||
3643 | |||
3644 | /** | ||
3645 | * Initialize common DMA queue structure | ||
3646 | * | ||
3647 | * @param q queue to init | ||
3648 | * @param count Number of BD's to allocate. Should be power of 2 | ||
3649 | * @param read_register Address for 'read' register | ||
3650 | * (not offset within BAR, full address) | ||
3651 | * @param write_register Address for 'write' register | ||
3652 | * (not offset within BAR, full address) | ||
3653 | * @param base_register Address for 'base' register | ||
3654 | * (not offset within BAR, full address) | ||
3655 | * @param size Address for 'size' register | ||
3656 | * (not offset within BAR, full address) | ||
3657 | */ | ||
3658 | static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q, | ||
3659 | int count, u32 read, u32 write, u32 base, u32 size) | ||
3660 | { | ||
3661 | q->n_bd = count; | ||
3662 | |||
3663 | q->low_mark = q->n_bd / 4; | ||
3664 | if (q->low_mark < 4) | ||
3665 | q->low_mark = 4; | ||
3666 | |||
3667 | q->high_mark = q->n_bd / 8; | ||
3668 | if (q->high_mark < 2) | ||
3669 | q->high_mark = 2; | ||
3670 | |||
3671 | q->first_empty = q->last_used = 0; | ||
3672 | q->reg_r = read; | ||
3673 | q->reg_w = write; | ||
3674 | |||
3675 | ipw_write32(priv, base, q->dma_addr); | ||
3676 | ipw_write32(priv, size, count); | ||
3677 | ipw_write32(priv, read, 0); | ||
3678 | ipw_write32(priv, write, 0); | ||
3679 | |||
3680 | _ipw_read32(priv, 0x90); | ||
3681 | } | ||
3682 | |||
3683 | static int ipw_queue_tx_init(struct ipw_priv *priv, | ||
3684 | struct clx2_tx_queue *q, | ||
3685 | int count, u32 read, u32 write, u32 base, u32 size) | ||
3686 | { | ||
3687 | struct pci_dev *dev = priv->pci_dev; | ||
3688 | |||
3689 | q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL); | ||
3690 | if (!q->txb) { | ||
3691 | IPW_ERROR("vmalloc for auxilary BD structures failed\n"); | ||
3692 | return -ENOMEM; | ||
3693 | } | ||
3694 | |||
3695 | q->bd = | ||
3696 | pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr); | ||
3697 | if (!q->bd) { | ||
3698 | IPW_ERROR("pci_alloc_consistent(%zd) failed\n", | ||
3699 | sizeof(q->bd[0]) * count); | ||
3700 | kfree(q->txb); | ||
3701 | q->txb = NULL; | ||
3702 | return -ENOMEM; | ||
3703 | } | ||
3704 | |||
3705 | ipw_queue_init(priv, &q->q, count, read, write, base, size); | ||
3706 | return 0; | ||
3707 | } | ||
3708 | |||
3709 | /** | ||
3710 | * Free one TFD, those at index [txq->q.last_used]. | ||
3711 | * Do NOT advance any indexes | ||
3712 | * | ||
3713 | * @param dev | ||
3714 | * @param txq | ||
3715 | */ | ||
3716 | static void ipw_queue_tx_free_tfd(struct ipw_priv *priv, | ||
3717 | struct clx2_tx_queue *txq) | ||
3718 | { | ||
3719 | struct tfd_frame *bd = &txq->bd[txq->q.last_used]; | ||
3720 | struct pci_dev *dev = priv->pci_dev; | ||
3721 | int i; | ||
3722 | |||
3723 | /* classify bd */ | ||
3724 | if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE) | ||
3725 | /* nothing to cleanup after for host commands */ | ||
3726 | return; | ||
3727 | |||
3728 | /* sanity check */ | ||
3729 | if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) { | ||
3730 | IPW_ERROR("Too many chunks: %i\n", | ||
3731 | le32_to_cpu(bd->u.data.num_chunks)); | ||
3732 | /** @todo issue fatal error, it is quite serious situation */ | ||
3733 | return; | ||
3734 | } | ||
3735 | |||
3736 | /* unmap chunks if any */ | ||
3737 | for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) { | ||
3738 | pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]), | ||
3739 | le16_to_cpu(bd->u.data.chunk_len[i]), | ||
3740 | PCI_DMA_TODEVICE); | ||
3741 | if (txq->txb[txq->q.last_used]) { | ||
3742 | ieee80211_txb_free(txq->txb[txq->q.last_used]); | ||
3743 | txq->txb[txq->q.last_used] = NULL; | ||
3744 | } | ||
3745 | } | ||
3746 | } | ||
3747 | |||
3748 | /** | ||
3749 | * Deallocate DMA queue. | ||
3750 | * | ||
3751 | * Empty queue by removing and destroying all BD's. | ||
3752 | * Free all buffers. | ||
3753 | * | ||
3754 | * @param dev | ||
3755 | * @param q | ||
3756 | */ | ||
3757 | static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq) | ||
3758 | { | ||
3759 | struct clx2_queue *q = &txq->q; | ||
3760 | struct pci_dev *dev = priv->pci_dev; | ||
3761 | |||
3762 | if (q->n_bd == 0) | ||
3763 | return; | ||
3764 | |||
3765 | /* first, empty all BD's */ | ||
3766 | for (; q->first_empty != q->last_used; | ||
3767 | q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) { | ||
3768 | ipw_queue_tx_free_tfd(priv, txq); | ||
3769 | } | ||
3770 | |||
3771 | /* free buffers belonging to queue itself */ | ||
3772 | pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd, | ||
3773 | q->dma_addr); | ||
3774 | kfree(txq->txb); | ||
3775 | |||
3776 | /* 0 fill whole structure */ | ||
3777 | memset(txq, 0, sizeof(*txq)); | ||
3778 | } | ||
3779 | |||
3780 | /** | ||
3781 | * Destroy all DMA queues and structures | ||
3782 | * | ||
3783 | * @param priv | ||
3784 | */ | ||
3785 | static void ipw_tx_queue_free(struct ipw_priv *priv) | ||
3786 | { | ||
3787 | /* Tx CMD queue */ | ||
3788 | ipw_queue_tx_free(priv, &priv->txq_cmd); | ||
3789 | |||
3790 | /* Tx queues */ | ||
3791 | ipw_queue_tx_free(priv, &priv->txq[0]); | ||
3792 | ipw_queue_tx_free(priv, &priv->txq[1]); | ||
3793 | ipw_queue_tx_free(priv, &priv->txq[2]); | ||
3794 | ipw_queue_tx_free(priv, &priv->txq[3]); | ||
3795 | } | ||
3796 | |||
3797 | static void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid) | ||
3798 | { | ||
3799 | /* First 3 bytes are manufacturer */ | ||
3800 | bssid[0] = priv->mac_addr[0]; | ||
3801 | bssid[1] = priv->mac_addr[1]; | ||
3802 | bssid[2] = priv->mac_addr[2]; | ||
3803 | |||
3804 | /* Last bytes are random */ | ||
3805 | get_random_bytes(&bssid[3], ETH_ALEN - 3); | ||
3806 | |||
3807 | bssid[0] &= 0xfe; /* clear multicast bit */ | ||
3808 | bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */ | ||
3809 | } | ||
3810 | |||
3811 | static u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid) | ||
3812 | { | ||
3813 | struct ipw_station_entry entry; | ||
3814 | int i; | ||
3815 | |||
3816 | for (i = 0; i < priv->num_stations; i++) { | ||
3817 | if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) { | ||
3818 | /* Another node is active in network */ | ||
3819 | priv->missed_adhoc_beacons = 0; | ||
3820 | if (!(priv->config & CFG_STATIC_CHANNEL)) | ||
3821 | /* when other nodes drop out, we drop out */ | ||
3822 | priv->config &= ~CFG_ADHOC_PERSIST; | ||
3823 | |||
3824 | return i; | ||
3825 | } | ||
3826 | } | ||
3827 | |||
3828 | if (i == MAX_STATIONS) | ||
3829 | return IPW_INVALID_STATION; | ||
3830 | |||
3831 | IPW_DEBUG_SCAN("Adding AdHoc station: %pM\n", bssid); | ||
3832 | |||
3833 | entry.reserved = 0; | ||
3834 | entry.support_mode = 0; | ||
3835 | memcpy(entry.mac_addr, bssid, ETH_ALEN); | ||
3836 | memcpy(priv->stations[i], bssid, ETH_ALEN); | ||
3837 | ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry), | ||
3838 | &entry, sizeof(entry)); | ||
3839 | priv->num_stations++; | ||
3840 | |||
3841 | return i; | ||
3842 | } | ||
3843 | |||
3844 | static u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid) | ||
3845 | { | ||
3846 | int i; | ||
3847 | |||
3848 | for (i = 0; i < priv->num_stations; i++) | ||
3849 | if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) | ||
3850 | return i; | ||
3851 | |||
3852 | return IPW_INVALID_STATION; | ||
3853 | } | ||
3854 | |||
3855 | static void ipw_send_disassociate(struct ipw_priv *priv, int quiet) | ||
3856 | { | ||
3857 | int err; | ||
3858 | |||
3859 | if (priv->status & STATUS_ASSOCIATING) { | ||
3860 | IPW_DEBUG_ASSOC("Disassociating while associating.\n"); | ||
3861 | queue_work(priv->workqueue, &priv->disassociate); | ||
3862 | return; | ||
3863 | } | ||
3864 | |||
3865 | if (!(priv->status & STATUS_ASSOCIATED)) { | ||
3866 | IPW_DEBUG_ASSOC("Disassociating while not associated.\n"); | ||
3867 | return; | ||
3868 | } | ||
3869 | |||
3870 | IPW_DEBUG_ASSOC("Disassocation attempt from %pM " | ||
3871 | "on channel %d.\n", | ||
3872 | priv->assoc_request.bssid, | ||
3873 | priv->assoc_request.channel); | ||
3874 | |||
3875 | priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED); | ||
3876 | priv->status |= STATUS_DISASSOCIATING; | ||
3877 | |||
3878 | if (quiet) | ||
3879 | priv->assoc_request.assoc_type = HC_DISASSOC_QUIET; | ||
3880 | else | ||
3881 | priv->assoc_request.assoc_type = HC_DISASSOCIATE; | ||
3882 | |||
3883 | err = ipw_send_associate(priv, &priv->assoc_request); | ||
3884 | if (err) { | ||
3885 | IPW_DEBUG_HC("Attempt to send [dis]associate command " | ||
3886 | "failed.\n"); | ||
3887 | return; | ||
3888 | } | ||
3889 | |||
3890 | } | ||
3891 | |||
3892 | static int ipw_disassociate(void *data) | ||
3893 | { | ||
3894 | struct ipw_priv *priv = data; | ||
3895 | if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) | ||
3896 | return 0; | ||
3897 | ipw_send_disassociate(data, 0); | ||
3898 | return 1; | ||
3899 | } | ||
3900 | |||
3901 | static void ipw_bg_disassociate(struct work_struct *work) | ||
3902 | { | ||
3903 | struct ipw_priv *priv = | ||
3904 | container_of(work, struct ipw_priv, disassociate); | ||
3905 | mutex_lock(&priv->mutex); | ||
3906 | ipw_disassociate(priv); | ||
3907 | mutex_unlock(&priv->mutex); | ||
3908 | } | ||
3909 | |||
3910 | static void ipw_system_config(struct work_struct *work) | ||
3911 | { | ||
3912 | struct ipw_priv *priv = | ||
3913 | container_of(work, struct ipw_priv, system_config); | ||
3914 | |||
3915 | #ifdef CONFIG_IPW2200_PROMISCUOUS | ||
3916 | if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) { | ||
3917 | priv->sys_config.accept_all_data_frames = 1; | ||
3918 | priv->sys_config.accept_non_directed_frames = 1; | ||
3919 | priv->sys_config.accept_all_mgmt_bcpr = 1; | ||
3920 | priv->sys_config.accept_all_mgmt_frames = 1; | ||
3921 | } | ||
3922 | #endif | ||
3923 | |||
3924 | ipw_send_system_config(priv); | ||
3925 | } | ||
3926 | |||
3927 | struct ipw_status_code { | ||
3928 | u16 status; | ||
3929 | const char *reason; | ||
3930 | }; | ||
3931 | |||
3932 | static const struct ipw_status_code ipw_status_codes[] = { | ||
3933 | {0x00, "Successful"}, | ||
3934 | {0x01, "Unspecified failure"}, | ||
3935 | {0x0A, "Cannot support all requested capabilities in the " | ||
3936 | "Capability information field"}, | ||
3937 | {0x0B, "Reassociation denied due to inability to confirm that " | ||
3938 | "association exists"}, | ||
3939 | {0x0C, "Association denied due to reason outside the scope of this " | ||
3940 | "standard"}, | ||
3941 | {0x0D, | ||
3942 | "Responding station does not support the specified authentication " | ||
3943 | "algorithm"}, | ||
3944 | {0x0E, | ||
3945 | "Received an Authentication frame with authentication sequence " | ||
3946 | "transaction sequence number out of expected sequence"}, | ||
3947 | {0x0F, "Authentication rejected because of challenge failure"}, | ||
3948 | {0x10, "Authentication rejected due to timeout waiting for next " | ||
3949 | "frame in sequence"}, | ||
3950 | {0x11, "Association denied because AP is unable to handle additional " | ||
3951 | "associated stations"}, | ||
3952 | {0x12, | ||
3953 | "Association denied due to requesting station not supporting all " | ||
3954 | "of the datarates in the BSSBasicServiceSet Parameter"}, | ||
3955 | {0x13, | ||
3956 | "Association denied due to requesting station not supporting " | ||
3957 | "short preamble operation"}, | ||
3958 | {0x14, | ||
3959 | "Association denied due to requesting station not supporting " | ||
3960 | "PBCC encoding"}, | ||
3961 | {0x15, | ||
3962 | "Association denied due to requesting station not supporting " | ||
3963 | "channel agility"}, | ||
3964 | {0x19, | ||
3965 | "Association denied due to requesting station not supporting " | ||
3966 | "short slot operation"}, | ||
3967 | {0x1A, | ||
3968 | "Association denied due to requesting station not supporting " | ||
3969 | "DSSS-OFDM operation"}, | ||
3970 | {0x28, "Invalid Information Element"}, | ||
3971 | {0x29, "Group Cipher is not valid"}, | ||
3972 | {0x2A, "Pairwise Cipher is not valid"}, | ||
3973 | {0x2B, "AKMP is not valid"}, | ||
3974 | {0x2C, "Unsupported RSN IE version"}, | ||
3975 | {0x2D, "Invalid RSN IE Capabilities"}, | ||
3976 | {0x2E, "Cipher suite is rejected per security policy"}, | ||
3977 | }; | ||
3978 | |||
3979 | static const char *ipw_get_status_code(u16 status) | ||
3980 | { | ||
3981 | int i; | ||
3982 | for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++) | ||
3983 | if (ipw_status_codes[i].status == (status & 0xff)) | ||
3984 | return ipw_status_codes[i].reason; | ||
3985 | return "Unknown status value."; | ||
3986 | } | ||
3987 | |||
3988 | static void inline average_init(struct average *avg) | ||
3989 | { | ||
3990 | memset(avg, 0, sizeof(*avg)); | ||
3991 | } | ||
3992 | |||
3993 | #define DEPTH_RSSI 8 | ||
3994 | #define DEPTH_NOISE 16 | ||
3995 | static s16 exponential_average(s16 prev_avg, s16 val, u8 depth) | ||
3996 | { | ||
3997 | return ((depth-1)*prev_avg + val)/depth; | ||
3998 | } | ||
3999 | |||
4000 | static void average_add(struct average *avg, s16 val) | ||
4001 | { | ||
4002 | avg->sum -= avg->entries[avg->pos]; | ||
4003 | avg->sum += val; | ||
4004 | avg->entries[avg->pos++] = val; | ||
4005 | if (unlikely(avg->pos == AVG_ENTRIES)) { | ||
4006 | avg->init = 1; | ||
4007 | avg->pos = 0; | ||
4008 | } | ||
4009 | } | ||
4010 | |||
4011 | static s16 average_value(struct average *avg) | ||
4012 | { | ||
4013 | if (!unlikely(avg->init)) { | ||
4014 | if (avg->pos) | ||
4015 | return avg->sum / avg->pos; | ||
4016 | return 0; | ||
4017 | } | ||
4018 | |||
4019 | return avg->sum / AVG_ENTRIES; | ||
4020 | } | ||
4021 | |||
4022 | static void ipw_reset_stats(struct ipw_priv *priv) | ||
4023 | { | ||
4024 | u32 len = sizeof(u32); | ||
4025 | |||
4026 | priv->quality = 0; | ||
4027 | |||
4028 | average_init(&priv->average_missed_beacons); | ||
4029 | priv->exp_avg_rssi = -60; | ||
4030 | priv->exp_avg_noise = -85 + 0x100; | ||
4031 | |||
4032 | priv->last_rate = 0; | ||
4033 | priv->last_missed_beacons = 0; | ||
4034 | priv->last_rx_packets = 0; | ||
4035 | priv->last_tx_packets = 0; | ||
4036 | priv->last_tx_failures = 0; | ||
4037 | |||
4038 | /* Firmware managed, reset only when NIC is restarted, so we have to | ||
4039 | * normalize on the current value */ | ||
4040 | ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, | ||
4041 | &priv->last_rx_err, &len); | ||
4042 | ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, | ||
4043 | &priv->last_tx_failures, &len); | ||
4044 | |||
4045 | /* Driver managed, reset with each association */ | ||
4046 | priv->missed_adhoc_beacons = 0; | ||
4047 | priv->missed_beacons = 0; | ||
4048 | priv->tx_packets = 0; | ||
4049 | priv->rx_packets = 0; | ||
4050 | |||
4051 | } | ||
4052 | |||
4053 | static u32 ipw_get_max_rate(struct ipw_priv *priv) | ||
4054 | { | ||
4055 | u32 i = 0x80000000; | ||
4056 | u32 mask = priv->rates_mask; | ||
4057 | /* If currently associated in B mode, restrict the maximum | ||
4058 | * rate match to B rates */ | ||
4059 | if (priv->assoc_request.ieee_mode == IPW_B_MODE) | ||
4060 | mask &= IEEE80211_CCK_RATES_MASK; | ||
4061 | |||
4062 | /* TODO: Verify that the rate is supported by the current rates | ||
4063 | * list. */ | ||
4064 | |||
4065 | while (i && !(mask & i)) | ||
4066 | i >>= 1; | ||
4067 | switch (i) { | ||
4068 | case IEEE80211_CCK_RATE_1MB_MASK: | ||
4069 | return 1000000; | ||
4070 | case IEEE80211_CCK_RATE_2MB_MASK: | ||
4071 | return 2000000; | ||
4072 | case IEEE80211_CCK_RATE_5MB_MASK: | ||
4073 | return 5500000; | ||
4074 | case IEEE80211_OFDM_RATE_6MB_MASK: | ||
4075 | return 6000000; | ||
4076 | case IEEE80211_OFDM_RATE_9MB_MASK: | ||
4077 | return 9000000; | ||
4078 | case IEEE80211_CCK_RATE_11MB_MASK: | ||
4079 | return 11000000; | ||
4080 | case IEEE80211_OFDM_RATE_12MB_MASK: | ||
4081 | return 12000000; | ||
4082 | case IEEE80211_OFDM_RATE_18MB_MASK: | ||
4083 | return 18000000; | ||
4084 | case IEEE80211_OFDM_RATE_24MB_MASK: | ||
4085 | return 24000000; | ||
4086 | case IEEE80211_OFDM_RATE_36MB_MASK: | ||
4087 | return 36000000; | ||
4088 | case IEEE80211_OFDM_RATE_48MB_MASK: | ||
4089 | return 48000000; | ||
4090 | case IEEE80211_OFDM_RATE_54MB_MASK: | ||
4091 | return 54000000; | ||
4092 | } | ||
4093 | |||
4094 | if (priv->ieee->mode == IEEE_B) | ||
4095 | return 11000000; | ||
4096 | else | ||
4097 | return 54000000; | ||
4098 | } | ||
4099 | |||
4100 | static u32 ipw_get_current_rate(struct ipw_priv *priv) | ||
4101 | { | ||
4102 | u32 rate, len = sizeof(rate); | ||
4103 | int err; | ||
4104 | |||
4105 | if (!(priv->status & STATUS_ASSOCIATED)) | ||
4106 | return 0; | ||
4107 | |||
4108 | if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) { | ||
4109 | err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate, | ||
4110 | &len); | ||
4111 | if (err) { | ||
4112 | IPW_DEBUG_INFO("failed querying ordinals.\n"); | ||
4113 | return 0; | ||
4114 | } | ||
4115 | } else | ||
4116 | return ipw_get_max_rate(priv); | ||
4117 | |||
4118 | switch (rate) { | ||
4119 | case IPW_TX_RATE_1MB: | ||
4120 | return 1000000; | ||
4121 | case IPW_TX_RATE_2MB: | ||
4122 | return 2000000; | ||
4123 | case IPW_TX_RATE_5MB: | ||
4124 | return 5500000; | ||
4125 | case IPW_TX_RATE_6MB: | ||
4126 | return 6000000; | ||
4127 | case IPW_TX_RATE_9MB: | ||
4128 | return 9000000; | ||
4129 | case IPW_TX_RATE_11MB: | ||
4130 | return 11000000; | ||
4131 | case IPW_TX_RATE_12MB: | ||
4132 | return 12000000; | ||
4133 | case IPW_TX_RATE_18MB: | ||
4134 | return 18000000; | ||
4135 | case IPW_TX_RATE_24MB: | ||
4136 | return 24000000; | ||
4137 | case IPW_TX_RATE_36MB: | ||
4138 | return 36000000; | ||
4139 | case IPW_TX_RATE_48MB: | ||
4140 | return 48000000; | ||
4141 | case IPW_TX_RATE_54MB: | ||
4142 | return 54000000; | ||
4143 | } | ||
4144 | |||
4145 | return 0; | ||
4146 | } | ||
4147 | |||
4148 | #define IPW_STATS_INTERVAL (2 * HZ) | ||
4149 | static void ipw_gather_stats(struct ipw_priv *priv) | ||
4150 | { | ||
4151 | u32 rx_err, rx_err_delta, rx_packets_delta; | ||
4152 | u32 tx_failures, tx_failures_delta, tx_packets_delta; | ||
4153 | u32 missed_beacons_percent, missed_beacons_delta; | ||
4154 | u32 quality = 0; | ||
4155 | u32 len = sizeof(u32); | ||
4156 | s16 rssi; | ||
4157 | u32 beacon_quality, signal_quality, tx_quality, rx_quality, | ||
4158 | rate_quality; | ||
4159 | u32 max_rate; | ||
4160 | |||
4161 | if (!(priv->status & STATUS_ASSOCIATED)) { | ||
4162 | priv->quality = 0; | ||
4163 | return; | ||
4164 | } | ||
4165 | |||
4166 | /* Update the statistics */ | ||
4167 | ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS, | ||
4168 | &priv->missed_beacons, &len); | ||
4169 | missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons; | ||
4170 | priv->last_missed_beacons = priv->missed_beacons; | ||
4171 | if (priv->assoc_request.beacon_interval) { | ||
4172 | missed_beacons_percent = missed_beacons_delta * | ||
4173 | (HZ * le16_to_cpu(priv->assoc_request.beacon_interval)) / | ||
4174 | (IPW_STATS_INTERVAL * 10); | ||
4175 | } else { | ||
4176 | missed_beacons_percent = 0; | ||
4177 | } | ||
4178 | average_add(&priv->average_missed_beacons, missed_beacons_percent); | ||
4179 | |||
4180 | ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len); | ||
4181 | rx_err_delta = rx_err - priv->last_rx_err; | ||
4182 | priv->last_rx_err = rx_err; | ||
4183 | |||
4184 | ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len); | ||
4185 | tx_failures_delta = tx_failures - priv->last_tx_failures; | ||
4186 | priv->last_tx_failures = tx_failures; | ||
4187 | |||
4188 | rx_packets_delta = priv->rx_packets - priv->last_rx_packets; | ||
4189 | priv->last_rx_packets = priv->rx_packets; | ||
4190 | |||
4191 | tx_packets_delta = priv->tx_packets - priv->last_tx_packets; | ||
4192 | priv->last_tx_packets = priv->tx_packets; | ||
4193 | |||
4194 | /* Calculate quality based on the following: | ||
4195 | * | ||
4196 | * Missed beacon: 100% = 0, 0% = 70% missed | ||
4197 | * Rate: 60% = 1Mbs, 100% = Max | ||
4198 | * Rx and Tx errors represent a straight % of total Rx/Tx | ||
4199 | * RSSI: 100% = > -50, 0% = < -80 | ||
4200 | * Rx errors: 100% = 0, 0% = 50% missed | ||
4201 | * | ||
4202 | * The lowest computed quality is used. | ||
4203 | * | ||
4204 | */ | ||
4205 | #define BEACON_THRESHOLD 5 | ||
4206 | beacon_quality = 100 - missed_beacons_percent; | ||
4207 | if (beacon_quality < BEACON_THRESHOLD) | ||
4208 | beacon_quality = 0; | ||
4209 | else | ||
4210 | beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 / | ||
4211 | (100 - BEACON_THRESHOLD); | ||
4212 | IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n", | ||
4213 | beacon_quality, missed_beacons_percent); | ||
4214 | |||
4215 | priv->last_rate = ipw_get_current_rate(priv); | ||
4216 | max_rate = ipw_get_max_rate(priv); | ||
4217 | rate_quality = priv->last_rate * 40 / max_rate + 60; | ||
4218 | IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n", | ||
4219 | rate_quality, priv->last_rate / 1000000); | ||
4220 | |||
4221 | if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta) | ||
4222 | rx_quality = 100 - (rx_err_delta * 100) / | ||
4223 | (rx_packets_delta + rx_err_delta); | ||
4224 | else | ||
4225 | rx_quality = 100; | ||
4226 | IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n", | ||
4227 | rx_quality, rx_err_delta, rx_packets_delta); | ||
4228 | |||
4229 | if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta) | ||
4230 | tx_quality = 100 - (tx_failures_delta * 100) / | ||
4231 | (tx_packets_delta + tx_failures_delta); | ||
4232 | else | ||
4233 | tx_quality = 100; | ||
4234 | IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n", | ||
4235 | tx_quality, tx_failures_delta, tx_packets_delta); | ||
4236 | |||
4237 | rssi = priv->exp_avg_rssi; | ||
4238 | signal_quality = | ||
4239 | (100 * | ||
4240 | (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) * | ||
4241 | (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) - | ||
4242 | (priv->ieee->perfect_rssi - rssi) * | ||
4243 | (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) + | ||
4244 | 62 * (priv->ieee->perfect_rssi - rssi))) / | ||
4245 | ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) * | ||
4246 | (priv->ieee->perfect_rssi - priv->ieee->worst_rssi)); | ||
4247 | if (signal_quality > 100) | ||
4248 | signal_quality = 100; | ||
4249 | else if (signal_quality < 1) | ||
4250 | signal_quality = 0; | ||
4251 | |||
4252 | IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n", | ||
4253 | signal_quality, rssi); | ||
4254 | |||
4255 | quality = min(beacon_quality, | ||
4256 | min(rate_quality, | ||
4257 | min(tx_quality, min(rx_quality, signal_quality)))); | ||
4258 | if (quality == beacon_quality) | ||
4259 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n", | ||
4260 | quality); | ||
4261 | if (quality == rate_quality) | ||
4262 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n", | ||
4263 | quality); | ||
4264 | if (quality == tx_quality) | ||
4265 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n", | ||
4266 | quality); | ||
4267 | if (quality == rx_quality) | ||
4268 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n", | ||
4269 | quality); | ||
4270 | if (quality == signal_quality) | ||
4271 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n", | ||
4272 | quality); | ||
4273 | |||
4274 | priv->quality = quality; | ||
4275 | |||
4276 | queue_delayed_work(priv->workqueue, &priv->gather_stats, | ||
4277 | IPW_STATS_INTERVAL); | ||
4278 | } | ||
4279 | |||
4280 | static void ipw_bg_gather_stats(struct work_struct *work) | ||
4281 | { | ||
4282 | struct ipw_priv *priv = | ||
4283 | container_of(work, struct ipw_priv, gather_stats.work); | ||
4284 | mutex_lock(&priv->mutex); | ||
4285 | ipw_gather_stats(priv); | ||
4286 | mutex_unlock(&priv->mutex); | ||
4287 | } | ||
4288 | |||
4289 | /* Missed beacon behavior: | ||
4290 | * 1st missed -> roaming_threshold, just wait, don't do any scan/roam. | ||
4291 | * roaming_threshold -> disassociate_threshold, scan and roam for better signal. | ||
4292 | * Above disassociate threshold, give up and stop scanning. | ||
4293 | * Roaming is disabled if disassociate_threshold <= roaming_threshold */ | ||
4294 | static void ipw_handle_missed_beacon(struct ipw_priv *priv, | ||
4295 | int missed_count) | ||
4296 | { | ||
4297 | priv->notif_missed_beacons = missed_count; | ||
4298 | |||
4299 | if (missed_count > priv->disassociate_threshold && | ||
4300 | priv->status & STATUS_ASSOCIATED) { | ||
4301 | /* If associated and we've hit the missed | ||
4302 | * beacon threshold, disassociate, turn | ||
4303 | * off roaming, and abort any active scans */ | ||
4304 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | | ||
4305 | IPW_DL_STATE | IPW_DL_ASSOC, | ||
4306 | "Missed beacon: %d - disassociate\n", missed_count); | ||
4307 | priv->status &= ~STATUS_ROAMING; | ||
4308 | if (priv->status & STATUS_SCANNING) { | ||
4309 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | | ||
4310 | IPW_DL_STATE, | ||
4311 | "Aborting scan with missed beacon.\n"); | ||
4312 | queue_work(priv->workqueue, &priv->abort_scan); | ||
4313 | } | ||
4314 | |||
4315 | queue_work(priv->workqueue, &priv->disassociate); | ||
4316 | return; | ||
4317 | } | ||
4318 | |||
4319 | if (priv->status & STATUS_ROAMING) { | ||
4320 | /* If we are currently roaming, then just | ||
4321 | * print a debug statement... */ | ||
4322 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, | ||
4323 | "Missed beacon: %d - roam in progress\n", | ||
4324 | missed_count); | ||
4325 | return; | ||
4326 | } | ||
4327 | |||
4328 | if (roaming && | ||
4329 | (missed_count > priv->roaming_threshold && | ||
4330 | missed_count <= priv->disassociate_threshold)) { | ||
4331 | /* If we are not already roaming, set the ROAM | ||
4332 | * bit in the status and kick off a scan. | ||
4333 | * This can happen several times before we reach | ||
4334 | * disassociate_threshold. */ | ||
4335 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, | ||
4336 | "Missed beacon: %d - initiate " | ||
4337 | "roaming\n", missed_count); | ||
4338 | if (!(priv->status & STATUS_ROAMING)) { | ||
4339 | priv->status |= STATUS_ROAMING; | ||
4340 | if (!(priv->status & STATUS_SCANNING)) | ||
4341 | queue_delayed_work(priv->workqueue, | ||
4342 | &priv->request_scan, 0); | ||
4343 | } | ||
4344 | return; | ||
4345 | } | ||
4346 | |||
4347 | if (priv->status & STATUS_SCANNING) { | ||
4348 | /* Stop scan to keep fw from getting | ||
4349 | * stuck (only if we aren't roaming -- | ||
4350 | * otherwise we'll never scan more than 2 or 3 | ||
4351 | * channels..) */ | ||
4352 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE, | ||
4353 | "Aborting scan with missed beacon.\n"); | ||
4354 | queue_work(priv->workqueue, &priv->abort_scan); | ||
4355 | } | ||
4356 | |||
4357 | IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count); | ||
4358 | } | ||
4359 | |||
4360 | static void ipw_scan_event(struct work_struct *work) | ||
4361 | { | ||
4362 | union iwreq_data wrqu; | ||
4363 | |||
4364 | struct ipw_priv *priv = | ||
4365 | container_of(work, struct ipw_priv, scan_event.work); | ||
4366 | |||
4367 | wrqu.data.length = 0; | ||
4368 | wrqu.data.flags = 0; | ||
4369 | wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL); | ||
4370 | } | ||
4371 | |||
4372 | static void handle_scan_event(struct ipw_priv *priv) | ||
4373 | { | ||
4374 | /* Only userspace-requested scan completion events go out immediately */ | ||
4375 | if (!priv->user_requested_scan) { | ||
4376 | if (!delayed_work_pending(&priv->scan_event)) | ||
4377 | queue_delayed_work(priv->workqueue, &priv->scan_event, | ||
4378 | round_jiffies_relative(msecs_to_jiffies(4000))); | ||
4379 | } else { | ||
4380 | union iwreq_data wrqu; | ||
4381 | |||
4382 | priv->user_requested_scan = 0; | ||
4383 | cancel_delayed_work(&priv->scan_event); | ||
4384 | |||
4385 | wrqu.data.length = 0; | ||
4386 | wrqu.data.flags = 0; | ||
4387 | wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL); | ||
4388 | } | ||
4389 | } | ||
4390 | |||
4391 | /** | ||
4392 | * Handle host notification packet. | ||
4393 | * Called from interrupt routine | ||
4394 | */ | ||
4395 | static void ipw_rx_notification(struct ipw_priv *priv, | ||
4396 | struct ipw_rx_notification *notif) | ||
4397 | { | ||
4398 | DECLARE_SSID_BUF(ssid); | ||
4399 | u16 size = le16_to_cpu(notif->size); | ||
4400 | notif->size = le16_to_cpu(notif->size); | ||
4401 | |||
4402 | IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, size); | ||
4403 | |||
4404 | switch (notif->subtype) { | ||
4405 | case HOST_NOTIFICATION_STATUS_ASSOCIATED:{ | ||
4406 | struct notif_association *assoc = ¬if->u.assoc; | ||
4407 | |||
4408 | switch (assoc->state) { | ||
4409 | case CMAS_ASSOCIATED:{ | ||
4410 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | ||
4411 | IPW_DL_ASSOC, | ||
4412 | "associated: '%s' %pM \n", | ||
4413 | print_ssid(ssid, priv->essid, | ||
4414 | priv->essid_len), | ||
4415 | priv->bssid); | ||
4416 | |||
4417 | switch (priv->ieee->iw_mode) { | ||
4418 | case IW_MODE_INFRA: | ||
4419 | memcpy(priv->ieee->bssid, | ||
4420 | priv->bssid, ETH_ALEN); | ||
4421 | break; | ||
4422 | |||
4423 | case IW_MODE_ADHOC: | ||
4424 | memcpy(priv->ieee->bssid, | ||
4425 | priv->bssid, ETH_ALEN); | ||
4426 | |||
4427 | /* clear out the station table */ | ||
4428 | priv->num_stations = 0; | ||
4429 | |||
4430 | IPW_DEBUG_ASSOC | ||
4431 | ("queueing adhoc check\n"); | ||
4432 | queue_delayed_work(priv-> | ||
4433 | workqueue, | ||
4434 | &priv-> | ||
4435 | adhoc_check, | ||
4436 | le16_to_cpu(priv-> | ||
4437 | assoc_request. | ||
4438 | beacon_interval)); | ||
4439 | break; | ||
4440 | } | ||
4441 | |||
4442 | priv->status &= ~STATUS_ASSOCIATING; | ||
4443 | priv->status |= STATUS_ASSOCIATED; | ||
4444 | queue_work(priv->workqueue, | ||
4445 | &priv->system_config); | ||
4446 | |||
4447 | #ifdef CONFIG_IPW2200_QOS | ||
4448 | #define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \ | ||
4449 | le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_control)) | ||
4450 | if ((priv->status & STATUS_AUTH) && | ||
4451 | (IPW_GET_PACKET_STYPE(¬if->u.raw) | ||
4452 | == IEEE80211_STYPE_ASSOC_RESP)) { | ||
4453 | if ((sizeof | ||
4454 | (struct | ||
4455 | ieee80211_assoc_response) | ||
4456 | <= size) | ||
4457 | && (size <= 2314)) { | ||
4458 | struct | ||
4459 | ieee80211_rx_stats | ||
4460 | stats = { | ||
4461 | .len = size - 1, | ||
4462 | }; | ||
4463 | |||
4464 | IPW_DEBUG_QOS | ||
4465 | ("QoS Associate " | ||
4466 | "size %d\n", size); | ||
4467 | ieee80211_rx_mgt(priv-> | ||
4468 | ieee, | ||
4469 | (struct | ||
4470 | ieee80211_hdr_4addr | ||
4471 | *) | ||
4472 | ¬if->u.raw, &stats); | ||
4473 | } | ||
4474 | } | ||
4475 | #endif | ||
4476 | |||
4477 | schedule_work(&priv->link_up); | ||
4478 | |||
4479 | break; | ||
4480 | } | ||
4481 | |||
4482 | case CMAS_AUTHENTICATED:{ | ||
4483 | if (priv-> | ||
4484 | status & (STATUS_ASSOCIATED | | ||
4485 | STATUS_AUTH)) { | ||
4486 | struct notif_authenticate *auth | ||
4487 | = ¬if->u.auth; | ||
4488 | IPW_DEBUG(IPW_DL_NOTIF | | ||
4489 | IPW_DL_STATE | | ||
4490 | IPW_DL_ASSOC, | ||
4491 | "deauthenticated: '%s' " | ||
4492 | "%pM" | ||
4493 | ": (0x%04X) - %s \n", | ||
4494 | print_ssid(ssid, | ||
4495 | priv-> | ||
4496 | essid, | ||
4497 | priv-> | ||
4498 | essid_len), | ||
4499 | priv->bssid, | ||
4500 | le16_to_cpu(auth->status), | ||
4501 | ipw_get_status_code | ||
4502 | (le16_to_cpu | ||
4503 | (auth->status))); | ||
4504 | |||
4505 | priv->status &= | ||
4506 | ~(STATUS_ASSOCIATING | | ||
4507 | STATUS_AUTH | | ||
4508 | STATUS_ASSOCIATED); | ||
4509 | |||
4510 | schedule_work(&priv->link_down); | ||
4511 | break; | ||
4512 | } | ||
4513 | |||
4514 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | ||
4515 | IPW_DL_ASSOC, | ||
4516 | "authenticated: '%s' %pM\n", | ||
4517 | print_ssid(ssid, priv->essid, | ||
4518 | priv->essid_len), | ||
4519 | priv->bssid); | ||
4520 | break; | ||
4521 | } | ||
4522 | |||
4523 | case CMAS_INIT:{ | ||
4524 | if (priv->status & STATUS_AUTH) { | ||
4525 | struct | ||
4526 | ieee80211_assoc_response | ||
4527 | *resp; | ||
4528 | resp = | ||
4529 | (struct | ||
4530 | ieee80211_assoc_response | ||
4531 | *)¬if->u.raw; | ||
4532 | IPW_DEBUG(IPW_DL_NOTIF | | ||
4533 | IPW_DL_STATE | | ||
4534 | IPW_DL_ASSOC, | ||
4535 | "association failed (0x%04X): %s\n", | ||
4536 | le16_to_cpu(resp->status), | ||
4537 | ipw_get_status_code | ||
4538 | (le16_to_cpu | ||
4539 | (resp->status))); | ||
4540 | } | ||
4541 | |||
4542 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | ||
4543 | IPW_DL_ASSOC, | ||
4544 | "disassociated: '%s' %pM \n", | ||
4545 | print_ssid(ssid, priv->essid, | ||
4546 | priv->essid_len), | ||
4547 | priv->bssid); | ||
4548 | |||
4549 | priv->status &= | ||
4550 | ~(STATUS_DISASSOCIATING | | ||
4551 | STATUS_ASSOCIATING | | ||
4552 | STATUS_ASSOCIATED | STATUS_AUTH); | ||
4553 | if (priv->assoc_network | ||
4554 | && (priv->assoc_network-> | ||
4555 | capability & | ||
4556 | WLAN_CAPABILITY_IBSS)) | ||
4557 | ipw_remove_current_network | ||
4558 | (priv); | ||
4559 | |||
4560 | schedule_work(&priv->link_down); | ||
4561 | |||
4562 | break; | ||
4563 | } | ||
4564 | |||
4565 | case CMAS_RX_ASSOC_RESP: | ||
4566 | break; | ||
4567 | |||
4568 | default: | ||
4569 | IPW_ERROR("assoc: unknown (%d)\n", | ||
4570 | assoc->state); | ||
4571 | break; | ||
4572 | } | ||
4573 | |||
4574 | break; | ||
4575 | } | ||
4576 | |||
4577 | case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{ | ||
4578 | struct notif_authenticate *auth = ¬if->u.auth; | ||
4579 | switch (auth->state) { | ||
4580 | case CMAS_AUTHENTICATED: | ||
4581 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, | ||
4582 | "authenticated: '%s' %pM \n", | ||
4583 | print_ssid(ssid, priv->essid, | ||
4584 | priv->essid_len), | ||
4585 | priv->bssid); | ||
4586 | priv->status |= STATUS_AUTH; | ||
4587 | break; | ||
4588 | |||
4589 | case CMAS_INIT: | ||
4590 | if (priv->status & STATUS_AUTH) { | ||
4591 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | ||
4592 | IPW_DL_ASSOC, | ||
4593 | "authentication failed (0x%04X): %s\n", | ||
4594 | le16_to_cpu(auth->status), | ||
4595 | ipw_get_status_code(le16_to_cpu | ||
4596 | (auth-> | ||
4597 | status))); | ||
4598 | } | ||
4599 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | ||
4600 | IPW_DL_ASSOC, | ||
4601 | "deauthenticated: '%s' %pM\n", | ||
4602 | print_ssid(ssid, priv->essid, | ||
4603 | priv->essid_len), | ||
4604 | priv->bssid); | ||
4605 | |||
4606 | priv->status &= ~(STATUS_ASSOCIATING | | ||
4607 | STATUS_AUTH | | ||
4608 | STATUS_ASSOCIATED); | ||
4609 | |||
4610 | schedule_work(&priv->link_down); | ||
4611 | break; | ||
4612 | |||
4613 | case CMAS_TX_AUTH_SEQ_1: | ||
4614 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | ||
4615 | IPW_DL_ASSOC, "AUTH_SEQ_1\n"); | ||
4616 | break; | ||
4617 | case CMAS_RX_AUTH_SEQ_2: | ||
4618 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | ||
4619 | IPW_DL_ASSOC, "AUTH_SEQ_2\n"); | ||
4620 | break; | ||
4621 | case CMAS_AUTH_SEQ_1_PASS: | ||
4622 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | ||
4623 | IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n"); | ||
4624 | break; | ||
4625 | case CMAS_AUTH_SEQ_1_FAIL: | ||
4626 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | ||
4627 | IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n"); | ||
4628 | break; | ||
4629 | case CMAS_TX_AUTH_SEQ_3: | ||
4630 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | ||
4631 | IPW_DL_ASSOC, "AUTH_SEQ_3\n"); | ||
4632 | break; | ||
4633 | case CMAS_RX_AUTH_SEQ_4: | ||
4634 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | ||
4635 | IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n"); | ||
4636 | break; | ||
4637 | case CMAS_AUTH_SEQ_2_PASS: | ||
4638 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | ||
4639 | IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n"); | ||
4640 | break; | ||
4641 | case CMAS_AUTH_SEQ_2_FAIL: | ||
4642 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | ||
4643 | IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n"); | ||
4644 | break; | ||
4645 | case CMAS_TX_ASSOC: | ||
4646 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | ||
4647 | IPW_DL_ASSOC, "TX_ASSOC\n"); | ||
4648 | break; | ||
4649 | case CMAS_RX_ASSOC_RESP: | ||
4650 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | ||
4651 | IPW_DL_ASSOC, "RX_ASSOC_RESP\n"); | ||
4652 | |||
4653 | break; | ||
4654 | case CMAS_ASSOCIATED: | ||
4655 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | ||
4656 | IPW_DL_ASSOC, "ASSOCIATED\n"); | ||
4657 | break; | ||
4658 | default: | ||
4659 | IPW_DEBUG_NOTIF("auth: failure - %d\n", | ||
4660 | auth->state); | ||
4661 | break; | ||
4662 | } | ||
4663 | break; | ||
4664 | } | ||
4665 | |||
4666 | case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{ | ||
4667 | struct notif_channel_result *x = | ||
4668 | ¬if->u.channel_result; | ||
4669 | |||
4670 | if (size == sizeof(*x)) { | ||
4671 | IPW_DEBUG_SCAN("Scan result for channel %d\n", | ||
4672 | x->channel_num); | ||
4673 | } else { | ||
4674 | IPW_DEBUG_SCAN("Scan result of wrong size %d " | ||
4675 | "(should be %zd)\n", | ||
4676 | size, sizeof(*x)); | ||
4677 | } | ||
4678 | break; | ||
4679 | } | ||
4680 | |||
4681 | case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{ | ||
4682 | struct notif_scan_complete *x = ¬if->u.scan_complete; | ||
4683 | if (size == sizeof(*x)) { | ||
4684 | IPW_DEBUG_SCAN | ||
4685 | ("Scan completed: type %d, %d channels, " | ||
4686 | "%d status\n", x->scan_type, | ||
4687 | x->num_channels, x->status); | ||
4688 | } else { | ||
4689 | IPW_ERROR("Scan completed of wrong size %d " | ||
4690 | "(should be %zd)\n", | ||
4691 | size, sizeof(*x)); | ||
4692 | } | ||
4693 | |||
4694 | priv->status &= | ||
4695 | ~(STATUS_SCANNING | STATUS_SCAN_ABORTING); | ||
4696 | |||
4697 | wake_up_interruptible(&priv->wait_state); | ||
4698 | cancel_delayed_work(&priv->scan_check); | ||
4699 | |||
4700 | if (priv->status & STATUS_EXIT_PENDING) | ||
4701 | break; | ||
4702 | |||
4703 | priv->ieee->scans++; | ||
4704 | |||
4705 | #ifdef CONFIG_IPW2200_MONITOR | ||
4706 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { | ||
4707 | priv->status |= STATUS_SCAN_FORCED; | ||
4708 | queue_delayed_work(priv->workqueue, | ||
4709 | &priv->request_scan, 0); | ||
4710 | break; | ||
4711 | } | ||
4712 | priv->status &= ~STATUS_SCAN_FORCED; | ||
4713 | #endif /* CONFIG_IPW2200_MONITOR */ | ||
4714 | |||
4715 | /* Do queued direct scans first */ | ||
4716 | if (priv->status & STATUS_DIRECT_SCAN_PENDING) { | ||
4717 | queue_delayed_work(priv->workqueue, | ||
4718 | &priv->request_direct_scan, 0); | ||
4719 | } | ||
4720 | |||
4721 | if (!(priv->status & (STATUS_ASSOCIATED | | ||
4722 | STATUS_ASSOCIATING | | ||
4723 | STATUS_ROAMING | | ||
4724 | STATUS_DISASSOCIATING))) | ||
4725 | queue_work(priv->workqueue, &priv->associate); | ||
4726 | else if (priv->status & STATUS_ROAMING) { | ||
4727 | if (x->status == SCAN_COMPLETED_STATUS_COMPLETE) | ||
4728 | /* If a scan completed and we are in roam mode, then | ||
4729 | * the scan that completed was the one requested as a | ||
4730 | * result of entering roam... so, schedule the | ||
4731 | * roam work */ | ||
4732 | queue_work(priv->workqueue, | ||
4733 | &priv->roam); | ||
4734 | else | ||
4735 | /* Don't schedule if we aborted the scan */ | ||
4736 | priv->status &= ~STATUS_ROAMING; | ||
4737 | } else if (priv->status & STATUS_SCAN_PENDING) | ||
4738 | queue_delayed_work(priv->workqueue, | ||
4739 | &priv->request_scan, 0); | ||
4740 | else if (priv->config & CFG_BACKGROUND_SCAN | ||
4741 | && priv->status & STATUS_ASSOCIATED) | ||
4742 | queue_delayed_work(priv->workqueue, | ||
4743 | &priv->request_scan, | ||
4744 | round_jiffies_relative(HZ)); | ||
4745 | |||
4746 | /* Send an empty event to user space. | ||
4747 | * We don't send the received data on the event because | ||
4748 | * it would require us to do complex transcoding, and | ||
4749 | * we want to minimise the work done in the irq handler | ||
4750 | * Use a request to extract the data. | ||
4751 | * Also, we generate this even for any scan, regardless | ||
4752 | * on how the scan was initiated. User space can just | ||
4753 | * sync on periodic scan to get fresh data... | ||
4754 | * Jean II */ | ||
4755 | if (x->status == SCAN_COMPLETED_STATUS_COMPLETE) | ||
4756 | handle_scan_event(priv); | ||
4757 | break; | ||
4758 | } | ||
4759 | |||
4760 | case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{ | ||
4761 | struct notif_frag_length *x = ¬if->u.frag_len; | ||
4762 | |||
4763 | if (size == sizeof(*x)) | ||
4764 | IPW_ERROR("Frag length: %d\n", | ||
4765 | le16_to_cpu(x->frag_length)); | ||
4766 | else | ||
4767 | IPW_ERROR("Frag length of wrong size %d " | ||
4768 | "(should be %zd)\n", | ||
4769 | size, sizeof(*x)); | ||
4770 | break; | ||
4771 | } | ||
4772 | |||
4773 | case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{ | ||
4774 | struct notif_link_deterioration *x = | ||
4775 | ¬if->u.link_deterioration; | ||
4776 | |||
4777 | if (size == sizeof(*x)) { | ||
4778 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, | ||
4779 | "link deterioration: type %d, cnt %d\n", | ||
4780 | x->silence_notification_type, | ||
4781 | x->silence_count); | ||
4782 | memcpy(&priv->last_link_deterioration, x, | ||
4783 | sizeof(*x)); | ||
4784 | } else { | ||
4785 | IPW_ERROR("Link Deterioration of wrong size %d " | ||
4786 | "(should be %zd)\n", | ||
4787 | size, sizeof(*x)); | ||
4788 | } | ||
4789 | break; | ||
4790 | } | ||
4791 | |||
4792 | case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{ | ||
4793 | IPW_ERROR("Dino config\n"); | ||
4794 | if (priv->hcmd | ||
4795 | && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG) | ||
4796 | IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n"); | ||
4797 | |||
4798 | break; | ||
4799 | } | ||
4800 | |||
4801 | case HOST_NOTIFICATION_STATUS_BEACON_STATE:{ | ||
4802 | struct notif_beacon_state *x = ¬if->u.beacon_state; | ||
4803 | if (size != sizeof(*x)) { | ||
4804 | IPW_ERROR | ||
4805 | ("Beacon state of wrong size %d (should " | ||
4806 | "be %zd)\n", size, sizeof(*x)); | ||
4807 | break; | ||
4808 | } | ||
4809 | |||
4810 | if (le32_to_cpu(x->state) == | ||
4811 | HOST_NOTIFICATION_STATUS_BEACON_MISSING) | ||
4812 | ipw_handle_missed_beacon(priv, | ||
4813 | le32_to_cpu(x-> | ||
4814 | number)); | ||
4815 | |||
4816 | break; | ||
4817 | } | ||
4818 | |||
4819 | case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{ | ||
4820 | struct notif_tgi_tx_key *x = ¬if->u.tgi_tx_key; | ||
4821 | if (size == sizeof(*x)) { | ||
4822 | IPW_ERROR("TGi Tx Key: state 0x%02x sec type " | ||
4823 | "0x%02x station %d\n", | ||
4824 | x->key_state, x->security_type, | ||
4825 | x->station_index); | ||
4826 | break; | ||
4827 | } | ||
4828 | |||
4829 | IPW_ERROR | ||
4830 | ("TGi Tx Key of wrong size %d (should be %zd)\n", | ||
4831 | size, sizeof(*x)); | ||
4832 | break; | ||
4833 | } | ||
4834 | |||
4835 | case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{ | ||
4836 | struct notif_calibration *x = ¬if->u.calibration; | ||
4837 | |||
4838 | if (size == sizeof(*x)) { | ||
4839 | memcpy(&priv->calib, x, sizeof(*x)); | ||
4840 | IPW_DEBUG_INFO("TODO: Calibration\n"); | ||
4841 | break; | ||
4842 | } | ||
4843 | |||
4844 | IPW_ERROR | ||
4845 | ("Calibration of wrong size %d (should be %zd)\n", | ||
4846 | size, sizeof(*x)); | ||
4847 | break; | ||
4848 | } | ||
4849 | |||
4850 | case HOST_NOTIFICATION_NOISE_STATS:{ | ||
4851 | if (size == sizeof(u32)) { | ||
4852 | priv->exp_avg_noise = | ||
4853 | exponential_average(priv->exp_avg_noise, | ||
4854 | (u8) (le32_to_cpu(notif->u.noise.value) & 0xff), | ||
4855 | DEPTH_NOISE); | ||
4856 | break; | ||
4857 | } | ||
4858 | |||
4859 | IPW_ERROR | ||
4860 | ("Noise stat is wrong size %d (should be %zd)\n", | ||
4861 | size, sizeof(u32)); | ||
4862 | break; | ||
4863 | } | ||
4864 | |||
4865 | default: | ||
4866 | IPW_DEBUG_NOTIF("Unknown notification: " | ||
4867 | "subtype=%d,flags=0x%2x,size=%d\n", | ||
4868 | notif->subtype, notif->flags, size); | ||
4869 | } | ||
4870 | } | ||
4871 | |||
4872 | /** | ||
4873 | * Destroys all DMA structures and initialise them again | ||
4874 | * | ||
4875 | * @param priv | ||
4876 | * @return error code | ||
4877 | */ | ||
4878 | static int ipw_queue_reset(struct ipw_priv *priv) | ||
4879 | { | ||
4880 | int rc = 0; | ||
4881 | /** @todo customize queue sizes */ | ||
4882 | int nTx = 64, nTxCmd = 8; | ||
4883 | ipw_tx_queue_free(priv); | ||
4884 | /* Tx CMD queue */ | ||
4885 | rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd, | ||
4886 | IPW_TX_CMD_QUEUE_READ_INDEX, | ||
4887 | IPW_TX_CMD_QUEUE_WRITE_INDEX, | ||
4888 | IPW_TX_CMD_QUEUE_BD_BASE, | ||
4889 | IPW_TX_CMD_QUEUE_BD_SIZE); | ||
4890 | if (rc) { | ||
4891 | IPW_ERROR("Tx Cmd queue init failed\n"); | ||
4892 | goto error; | ||
4893 | } | ||
4894 | /* Tx queue(s) */ | ||
4895 | rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx, | ||
4896 | IPW_TX_QUEUE_0_READ_INDEX, | ||
4897 | IPW_TX_QUEUE_0_WRITE_INDEX, | ||
4898 | IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE); | ||
4899 | if (rc) { | ||
4900 | IPW_ERROR("Tx 0 queue init failed\n"); | ||
4901 | goto error; | ||
4902 | } | ||
4903 | rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx, | ||
4904 | IPW_TX_QUEUE_1_READ_INDEX, | ||
4905 | IPW_TX_QUEUE_1_WRITE_INDEX, | ||
4906 | IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE); | ||
4907 | if (rc) { | ||
4908 | IPW_ERROR("Tx 1 queue init failed\n"); | ||
4909 | goto error; | ||
4910 | } | ||
4911 | rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx, | ||
4912 | IPW_TX_QUEUE_2_READ_INDEX, | ||
4913 | IPW_TX_QUEUE_2_WRITE_INDEX, | ||
4914 | IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE); | ||
4915 | if (rc) { | ||
4916 | IPW_ERROR("Tx 2 queue init failed\n"); | ||
4917 | goto error; | ||
4918 | } | ||
4919 | rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx, | ||
4920 | IPW_TX_QUEUE_3_READ_INDEX, | ||
4921 | IPW_TX_QUEUE_3_WRITE_INDEX, | ||
4922 | IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE); | ||
4923 | if (rc) { | ||
4924 | IPW_ERROR("Tx 3 queue init failed\n"); | ||
4925 | goto error; | ||
4926 | } | ||
4927 | /* statistics */ | ||
4928 | priv->rx_bufs_min = 0; | ||
4929 | priv->rx_pend_max = 0; | ||
4930 | return rc; | ||
4931 | |||
4932 | error: | ||
4933 | ipw_tx_queue_free(priv); | ||
4934 | return rc; | ||
4935 | } | ||
4936 | |||
4937 | /** | ||
4938 | * Reclaim Tx queue entries no more used by NIC. | ||
4939 | * | ||
4940 | * When FW advances 'R' index, all entries between old and | ||
4941 | * new 'R' index need to be reclaimed. As result, some free space | ||
4942 | * forms. If there is enough free space (> low mark), wake Tx queue. | ||
4943 | * | ||
4944 | * @note Need to protect against garbage in 'R' index | ||
4945 | * @param priv | ||
4946 | * @param txq | ||
4947 | * @param qindex | ||
4948 | * @return Number of used entries remains in the queue | ||
4949 | */ | ||
4950 | static int ipw_queue_tx_reclaim(struct ipw_priv *priv, | ||
4951 | struct clx2_tx_queue *txq, int qindex) | ||
4952 | { | ||
4953 | u32 hw_tail; | ||
4954 | int used; | ||
4955 | struct clx2_queue *q = &txq->q; | ||
4956 | |||
4957 | hw_tail = ipw_read32(priv, q->reg_r); | ||
4958 | if (hw_tail >= q->n_bd) { | ||
4959 | IPW_ERROR | ||
4960 | ("Read index for DMA queue (%d) is out of range [0-%d)\n", | ||
4961 | hw_tail, q->n_bd); | ||
4962 | goto done; | ||
4963 | } | ||
4964 | for (; q->last_used != hw_tail; | ||
4965 | q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) { | ||
4966 | ipw_queue_tx_free_tfd(priv, txq); | ||
4967 | priv->tx_packets++; | ||
4968 | } | ||
4969 | done: | ||
4970 | if ((ipw_tx_queue_space(q) > q->low_mark) && | ||
4971 | (qindex >= 0)) | ||
4972 | netif_wake_queue(priv->net_dev); | ||
4973 | used = q->first_empty - q->last_used; | ||
4974 | if (used < 0) | ||
4975 | used += q->n_bd; | ||
4976 | |||
4977 | return used; | ||
4978 | } | ||
4979 | |||
4980 | static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf, | ||
4981 | int len, int sync) | ||
4982 | { | ||
4983 | struct clx2_tx_queue *txq = &priv->txq_cmd; | ||
4984 | struct clx2_queue *q = &txq->q; | ||
4985 | struct tfd_frame *tfd; | ||
4986 | |||
4987 | if (ipw_tx_queue_space(q) < (sync ? 1 : 2)) { | ||
4988 | IPW_ERROR("No space for Tx\n"); | ||
4989 | return -EBUSY; | ||
4990 | } | ||
4991 | |||
4992 | tfd = &txq->bd[q->first_empty]; | ||
4993 | txq->txb[q->first_empty] = NULL; | ||
4994 | |||
4995 | memset(tfd, 0, sizeof(*tfd)); | ||
4996 | tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE; | ||
4997 | tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK; | ||
4998 | priv->hcmd_seq++; | ||
4999 | tfd->u.cmd.index = hcmd; | ||
5000 | tfd->u.cmd.length = len; | ||
5001 | memcpy(tfd->u.cmd.payload, buf, len); | ||
5002 | q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd); | ||
5003 | ipw_write32(priv, q->reg_w, q->first_empty); | ||
5004 | _ipw_read32(priv, 0x90); | ||
5005 | |||
5006 | return 0; | ||
5007 | } | ||
5008 | |||
5009 | /* | ||
5010 | * Rx theory of operation | ||
5011 | * | ||
5012 | * The host allocates 32 DMA target addresses and passes the host address | ||
5013 | * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is | ||
5014 | * 0 to 31 | ||
5015 | * | ||
5016 | * Rx Queue Indexes | ||
5017 | * The host/firmware share two index registers for managing the Rx buffers. | ||
5018 | * | ||
5019 | * The READ index maps to the first position that the firmware may be writing | ||
5020 | * to -- the driver can read up to (but not including) this position and get | ||
5021 | * good data. | ||
5022 | * The READ index is managed by the firmware once the card is enabled. | ||
5023 | * | ||
5024 | * The WRITE index maps to the last position the driver has read from -- the | ||
5025 | * position preceding WRITE is the last slot the firmware can place a packet. | ||
5026 | * | ||
5027 | * The queue is empty (no good data) if WRITE = READ - 1, and is full if | ||
5028 | * WRITE = READ. | ||
5029 | * | ||
5030 | * During initialization the host sets up the READ queue position to the first | ||
5031 | * INDEX position, and WRITE to the last (READ - 1 wrapped) | ||
5032 | * | ||
5033 | * When the firmware places a packet in a buffer it will advance the READ index | ||
5034 | * and fire the RX interrupt. The driver can then query the READ index and | ||
5035 | * process as many packets as possible, moving the WRITE index forward as it | ||
5036 | * resets the Rx queue buffers with new memory. | ||
5037 | * | ||
5038 | * The management in the driver is as follows: | ||
5039 | * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When | ||
5040 | * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled | ||
5041 | * to replensish the ipw->rxq->rx_free. | ||
5042 | * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the | ||
5043 | * ipw->rxq is replenished and the READ INDEX is updated (updating the | ||
5044 | * 'processed' and 'read' driver indexes as well) | ||
5045 | * + A received packet is processed and handed to the kernel network stack, | ||
5046 | * detached from the ipw->rxq. The driver 'processed' index is updated. | ||
5047 | * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free | ||
5048 | * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ | ||
5049 | * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there | ||
5050 | * were enough free buffers and RX_STALLED is set it is cleared. | ||
5051 | * | ||
5052 | * | ||
5053 | * Driver sequence: | ||
5054 | * | ||
5055 | * ipw_rx_queue_alloc() Allocates rx_free | ||
5056 | * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls | ||
5057 | * ipw_rx_queue_restock | ||
5058 | * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx | ||
5059 | * queue, updates firmware pointers, and updates | ||
5060 | * the WRITE index. If insufficient rx_free buffers | ||
5061 | * are available, schedules ipw_rx_queue_replenish | ||
5062 | * | ||
5063 | * -- enable interrupts -- | ||
5064 | * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the | ||
5065 | * READ INDEX, detaching the SKB from the pool. | ||
5066 | * Moves the packet buffer from queue to rx_used. | ||
5067 | * Calls ipw_rx_queue_restock to refill any empty | ||
5068 | * slots. | ||
5069 | * ... | ||
5070 | * | ||
5071 | */ | ||
5072 | |||
5073 | /* | ||
5074 | * If there are slots in the RX queue that need to be restocked, | ||
5075 | * and we have free pre-allocated buffers, fill the ranks as much | ||
5076 | * as we can pulling from rx_free. | ||
5077 | * | ||
5078 | * This moves the 'write' index forward to catch up with 'processed', and | ||
5079 | * also updates the memory address in the firmware to reference the new | ||
5080 | * target buffer. | ||
5081 | */ | ||
5082 | static void ipw_rx_queue_restock(struct ipw_priv *priv) | ||
5083 | { | ||
5084 | struct ipw_rx_queue *rxq = priv->rxq; | ||
5085 | struct list_head *element; | ||
5086 | struct ipw_rx_mem_buffer *rxb; | ||
5087 | unsigned long flags; | ||
5088 | int write; | ||
5089 | |||
5090 | spin_lock_irqsave(&rxq->lock, flags); | ||
5091 | write = rxq->write; | ||
5092 | while ((ipw_rx_queue_space(rxq) > 0) && (rxq->free_count)) { | ||
5093 | element = rxq->rx_free.next; | ||
5094 | rxb = list_entry(element, struct ipw_rx_mem_buffer, list); | ||
5095 | list_del(element); | ||
5096 | |||
5097 | ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE, | ||
5098 | rxb->dma_addr); | ||
5099 | rxq->queue[rxq->write] = rxb; | ||
5100 | rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE; | ||
5101 | rxq->free_count--; | ||
5102 | } | ||
5103 | spin_unlock_irqrestore(&rxq->lock, flags); | ||
5104 | |||
5105 | /* If the pre-allocated buffer pool is dropping low, schedule to | ||
5106 | * refill it */ | ||
5107 | if (rxq->free_count <= RX_LOW_WATERMARK) | ||
5108 | queue_work(priv->workqueue, &priv->rx_replenish); | ||
5109 | |||
5110 | /* If we've added more space for the firmware to place data, tell it */ | ||
5111 | if (write != rxq->write) | ||
5112 | ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write); | ||
5113 | } | ||
5114 | |||
5115 | /* | ||
5116 | * Move all used packet from rx_used to rx_free, allocating a new SKB for each. | ||
5117 | * Also restock the Rx queue via ipw_rx_queue_restock. | ||
5118 | * | ||
5119 | * This is called as a scheduled work item (except for during intialization) | ||
5120 | */ | ||
5121 | static void ipw_rx_queue_replenish(void *data) | ||
5122 | { | ||
5123 | struct ipw_priv *priv = data; | ||
5124 | struct ipw_rx_queue *rxq = priv->rxq; | ||
5125 | struct list_head *element; | ||
5126 | struct ipw_rx_mem_buffer *rxb; | ||
5127 | unsigned long flags; | ||
5128 | |||
5129 | spin_lock_irqsave(&rxq->lock, flags); | ||
5130 | while (!list_empty(&rxq->rx_used)) { | ||
5131 | element = rxq->rx_used.next; | ||
5132 | rxb = list_entry(element, struct ipw_rx_mem_buffer, list); | ||
5133 | rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC); | ||
5134 | if (!rxb->skb) { | ||
5135 | printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n", | ||
5136 | priv->net_dev->name); | ||
5137 | /* We don't reschedule replenish work here -- we will | ||
5138 | * call the restock method and if it still needs | ||
5139 | * more buffers it will schedule replenish */ | ||
5140 | break; | ||
5141 | } | ||
5142 | list_del(element); | ||
5143 | |||
5144 | rxb->dma_addr = | ||
5145 | pci_map_single(priv->pci_dev, rxb->skb->data, | ||
5146 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); | ||
5147 | |||
5148 | list_add_tail(&rxb->list, &rxq->rx_free); | ||
5149 | rxq->free_count++; | ||
5150 | } | ||
5151 | spin_unlock_irqrestore(&rxq->lock, flags); | ||
5152 | |||
5153 | ipw_rx_queue_restock(priv); | ||
5154 | } | ||
5155 | |||
5156 | static void ipw_bg_rx_queue_replenish(struct work_struct *work) | ||
5157 | { | ||
5158 | struct ipw_priv *priv = | ||
5159 | container_of(work, struct ipw_priv, rx_replenish); | ||
5160 | mutex_lock(&priv->mutex); | ||
5161 | ipw_rx_queue_replenish(priv); | ||
5162 | mutex_unlock(&priv->mutex); | ||
5163 | } | ||
5164 | |||
5165 | /* Assumes that the skb field of the buffers in 'pool' is kept accurate. | ||
5166 | * If an SKB has been detached, the POOL needs to have its SKB set to NULL | ||
5167 | * This free routine walks the list of POOL entries and if SKB is set to | ||
5168 | * non NULL it is unmapped and freed | ||
5169 | */ | ||
5170 | static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq) | ||
5171 | { | ||
5172 | int i; | ||
5173 | |||
5174 | if (!rxq) | ||
5175 | return; | ||
5176 | |||
5177 | for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) { | ||
5178 | if (rxq->pool[i].skb != NULL) { | ||
5179 | pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr, | ||
5180 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); | ||
5181 | dev_kfree_skb(rxq->pool[i].skb); | ||
5182 | } | ||
5183 | } | ||
5184 | |||
5185 | kfree(rxq); | ||
5186 | } | ||
5187 | |||
5188 | static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv) | ||
5189 | { | ||
5190 | struct ipw_rx_queue *rxq; | ||
5191 | int i; | ||
5192 | |||
5193 | rxq = kzalloc(sizeof(*rxq), GFP_KERNEL); | ||
5194 | if (unlikely(!rxq)) { | ||
5195 | IPW_ERROR("memory allocation failed\n"); | ||
5196 | return NULL; | ||
5197 | } | ||
5198 | spin_lock_init(&rxq->lock); | ||
5199 | INIT_LIST_HEAD(&rxq->rx_free); | ||
5200 | INIT_LIST_HEAD(&rxq->rx_used); | ||
5201 | |||
5202 | /* Fill the rx_used queue with _all_ of the Rx buffers */ | ||
5203 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) | ||
5204 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); | ||
5205 | |||
5206 | /* Set us so that we have processed and used all buffers, but have | ||
5207 | * not restocked the Rx queue with fresh buffers */ | ||
5208 | rxq->read = rxq->write = 0; | ||
5209 | rxq->free_count = 0; | ||
5210 | |||
5211 | return rxq; | ||
5212 | } | ||
5213 | |||
5214 | static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate) | ||
5215 | { | ||
5216 | rate &= ~IEEE80211_BASIC_RATE_MASK; | ||
5217 | if (ieee_mode == IEEE_A) { | ||
5218 | switch (rate) { | ||
5219 | case IEEE80211_OFDM_RATE_6MB: | ||
5220 | return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? | ||
5221 | 1 : 0; | ||
5222 | case IEEE80211_OFDM_RATE_9MB: | ||
5223 | return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? | ||
5224 | 1 : 0; | ||
5225 | case IEEE80211_OFDM_RATE_12MB: | ||
5226 | return priv-> | ||
5227 | rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0; | ||
5228 | case IEEE80211_OFDM_RATE_18MB: | ||
5229 | return priv-> | ||
5230 | rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0; | ||
5231 | case IEEE80211_OFDM_RATE_24MB: | ||
5232 | return priv-> | ||
5233 | rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0; | ||
5234 | case IEEE80211_OFDM_RATE_36MB: | ||
5235 | return priv-> | ||
5236 | rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0; | ||
5237 | case IEEE80211_OFDM_RATE_48MB: | ||
5238 | return priv-> | ||
5239 | rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0; | ||
5240 | case IEEE80211_OFDM_RATE_54MB: | ||
5241 | return priv-> | ||
5242 | rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0; | ||
5243 | default: | ||
5244 | return 0; | ||
5245 | } | ||
5246 | } | ||
5247 | |||
5248 | /* B and G mixed */ | ||
5249 | switch (rate) { | ||
5250 | case IEEE80211_CCK_RATE_1MB: | ||
5251 | return priv->rates_mask & IEEE80211_CCK_RATE_1MB_MASK ? 1 : 0; | ||
5252 | case IEEE80211_CCK_RATE_2MB: | ||
5253 | return priv->rates_mask & IEEE80211_CCK_RATE_2MB_MASK ? 1 : 0; | ||
5254 | case IEEE80211_CCK_RATE_5MB: | ||
5255 | return priv->rates_mask & IEEE80211_CCK_RATE_5MB_MASK ? 1 : 0; | ||
5256 | case IEEE80211_CCK_RATE_11MB: | ||
5257 | return priv->rates_mask & IEEE80211_CCK_RATE_11MB_MASK ? 1 : 0; | ||
5258 | } | ||
5259 | |||
5260 | /* If we are limited to B modulations, bail at this point */ | ||
5261 | if (ieee_mode == IEEE_B) | ||
5262 | return 0; | ||
5263 | |||
5264 | /* G */ | ||
5265 | switch (rate) { | ||
5266 | case IEEE80211_OFDM_RATE_6MB: | ||
5267 | return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? 1 : 0; | ||
5268 | case IEEE80211_OFDM_RATE_9MB: | ||
5269 | return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? 1 : 0; | ||
5270 | case IEEE80211_OFDM_RATE_12MB: | ||
5271 | return priv->rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0; | ||
5272 | case IEEE80211_OFDM_RATE_18MB: | ||
5273 | return priv->rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0; | ||
5274 | case IEEE80211_OFDM_RATE_24MB: | ||
5275 | return priv->rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0; | ||
5276 | case IEEE80211_OFDM_RATE_36MB: | ||
5277 | return priv->rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0; | ||
5278 | case IEEE80211_OFDM_RATE_48MB: | ||
5279 | return priv->rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0; | ||
5280 | case IEEE80211_OFDM_RATE_54MB: | ||
5281 | return priv->rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0; | ||
5282 | } | ||
5283 | |||
5284 | return 0; | ||
5285 | } | ||
5286 | |||
5287 | static int ipw_compatible_rates(struct ipw_priv *priv, | ||
5288 | const struct ieee80211_network *network, | ||
5289 | struct ipw_supported_rates *rates) | ||
5290 | { | ||
5291 | int num_rates, i; | ||
5292 | |||
5293 | memset(rates, 0, sizeof(*rates)); | ||
5294 | num_rates = min(network->rates_len, (u8) IPW_MAX_RATES); | ||
5295 | rates->num_rates = 0; | ||
5296 | for (i = 0; i < num_rates; i++) { | ||
5297 | if (!ipw_is_rate_in_mask(priv, network->mode, | ||
5298 | network->rates[i])) { | ||
5299 | |||
5300 | if (network->rates[i] & IEEE80211_BASIC_RATE_MASK) { | ||
5301 | IPW_DEBUG_SCAN("Adding masked mandatory " | ||
5302 | "rate %02X\n", | ||
5303 | network->rates[i]); | ||
5304 | rates->supported_rates[rates->num_rates++] = | ||
5305 | network->rates[i]; | ||
5306 | continue; | ||
5307 | } | ||
5308 | |||
5309 | IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n", | ||
5310 | network->rates[i], priv->rates_mask); | ||
5311 | continue; | ||
5312 | } | ||
5313 | |||
5314 | rates->supported_rates[rates->num_rates++] = network->rates[i]; | ||
5315 | } | ||
5316 | |||
5317 | num_rates = min(network->rates_ex_len, | ||
5318 | (u8) (IPW_MAX_RATES - num_rates)); | ||
5319 | for (i = 0; i < num_rates; i++) { | ||
5320 | if (!ipw_is_rate_in_mask(priv, network->mode, | ||
5321 | network->rates_ex[i])) { | ||
5322 | if (network->rates_ex[i] & IEEE80211_BASIC_RATE_MASK) { | ||
5323 | IPW_DEBUG_SCAN("Adding masked mandatory " | ||
5324 | "rate %02X\n", | ||
5325 | network->rates_ex[i]); | ||
5326 | rates->supported_rates[rates->num_rates++] = | ||
5327 | network->rates[i]; | ||
5328 | continue; | ||
5329 | } | ||
5330 | |||
5331 | IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n", | ||
5332 | network->rates_ex[i], priv->rates_mask); | ||
5333 | continue; | ||
5334 | } | ||
5335 | |||
5336 | rates->supported_rates[rates->num_rates++] = | ||
5337 | network->rates_ex[i]; | ||
5338 | } | ||
5339 | |||
5340 | return 1; | ||
5341 | } | ||
5342 | |||
5343 | static void ipw_copy_rates(struct ipw_supported_rates *dest, | ||
5344 | const struct ipw_supported_rates *src) | ||
5345 | { | ||
5346 | u8 i; | ||
5347 | for (i = 0; i < src->num_rates; i++) | ||
5348 | dest->supported_rates[i] = src->supported_rates[i]; | ||
5349 | dest->num_rates = src->num_rates; | ||
5350 | } | ||
5351 | |||
5352 | /* TODO: Look at sniffed packets in the air to determine if the basic rate | ||
5353 | * mask should ever be used -- right now all callers to add the scan rates are | ||
5354 | * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */ | ||
5355 | static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates, | ||
5356 | u8 modulation, u32 rate_mask) | ||
5357 | { | ||
5358 | u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ? | ||
5359 | IEEE80211_BASIC_RATE_MASK : 0; | ||
5360 | |||
5361 | if (rate_mask & IEEE80211_CCK_RATE_1MB_MASK) | ||
5362 | rates->supported_rates[rates->num_rates++] = | ||
5363 | IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB; | ||
5364 | |||
5365 | if (rate_mask & IEEE80211_CCK_RATE_2MB_MASK) | ||
5366 | rates->supported_rates[rates->num_rates++] = | ||
5367 | IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB; | ||
5368 | |||
5369 | if (rate_mask & IEEE80211_CCK_RATE_5MB_MASK) | ||
5370 | rates->supported_rates[rates->num_rates++] = basic_mask | | ||
5371 | IEEE80211_CCK_RATE_5MB; | ||
5372 | |||
5373 | if (rate_mask & IEEE80211_CCK_RATE_11MB_MASK) | ||
5374 | rates->supported_rates[rates->num_rates++] = basic_mask | | ||
5375 | IEEE80211_CCK_RATE_11MB; | ||
5376 | } | ||
5377 | |||
5378 | static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates, | ||
5379 | u8 modulation, u32 rate_mask) | ||
5380 | { | ||
5381 | u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ? | ||
5382 | IEEE80211_BASIC_RATE_MASK : 0; | ||
5383 | |||
5384 | if (rate_mask & IEEE80211_OFDM_RATE_6MB_MASK) | ||
5385 | rates->supported_rates[rates->num_rates++] = basic_mask | | ||
5386 | IEEE80211_OFDM_RATE_6MB; | ||
5387 | |||
5388 | if (rate_mask & IEEE80211_OFDM_RATE_9MB_MASK) | ||
5389 | rates->supported_rates[rates->num_rates++] = | ||
5390 | IEEE80211_OFDM_RATE_9MB; | ||
5391 | |||
5392 | if (rate_mask & IEEE80211_OFDM_RATE_12MB_MASK) | ||
5393 | rates->supported_rates[rates->num_rates++] = basic_mask | | ||
5394 | IEEE80211_OFDM_RATE_12MB; | ||
5395 | |||
5396 | if (rate_mask & IEEE80211_OFDM_RATE_18MB_MASK) | ||
5397 | rates->supported_rates[rates->num_rates++] = | ||
5398 | IEEE80211_OFDM_RATE_18MB; | ||
5399 | |||
5400 | if (rate_mask & IEEE80211_OFDM_RATE_24MB_MASK) | ||
5401 | rates->supported_rates[rates->num_rates++] = basic_mask | | ||
5402 | IEEE80211_OFDM_RATE_24MB; | ||
5403 | |||
5404 | if (rate_mask & IEEE80211_OFDM_RATE_36MB_MASK) | ||
5405 | rates->supported_rates[rates->num_rates++] = | ||
5406 | IEEE80211_OFDM_RATE_36MB; | ||
5407 | |||
5408 | if (rate_mask & IEEE80211_OFDM_RATE_48MB_MASK) | ||
5409 | rates->supported_rates[rates->num_rates++] = | ||
5410 | IEEE80211_OFDM_RATE_48MB; | ||
5411 | |||
5412 | if (rate_mask & IEEE80211_OFDM_RATE_54MB_MASK) | ||
5413 | rates->supported_rates[rates->num_rates++] = | ||
5414 | IEEE80211_OFDM_RATE_54MB; | ||
5415 | } | ||
5416 | |||
5417 | struct ipw_network_match { | ||
5418 | struct ieee80211_network *network; | ||
5419 | struct ipw_supported_rates rates; | ||
5420 | }; | ||
5421 | |||
5422 | static int ipw_find_adhoc_network(struct ipw_priv *priv, | ||
5423 | struct ipw_network_match *match, | ||
5424 | struct ieee80211_network *network, | ||
5425 | int roaming) | ||
5426 | { | ||
5427 | struct ipw_supported_rates rates; | ||
5428 | DECLARE_SSID_BUF(ssid); | ||
5429 | |||
5430 | /* Verify that this network's capability is compatible with the | ||
5431 | * current mode (AdHoc or Infrastructure) */ | ||
5432 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC && | ||
5433 | !(network->capability & WLAN_CAPABILITY_IBSS))) { | ||
5434 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded due to " | ||
5435 | "capability mismatch.\n", | ||
5436 | print_ssid(ssid, network->ssid, | ||
5437 | network->ssid_len), | ||
5438 | network->bssid); | ||
5439 | return 0; | ||
5440 | } | ||
5441 | |||
5442 | if (unlikely(roaming)) { | ||
5443 | /* If we are roaming, then ensure check if this is a valid | ||
5444 | * network to try and roam to */ | ||
5445 | if ((network->ssid_len != match->network->ssid_len) || | ||
5446 | memcmp(network->ssid, match->network->ssid, | ||
5447 | network->ssid_len)) { | ||
5448 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " | ||
5449 | "because of non-network ESSID.\n", | ||
5450 | print_ssid(ssid, network->ssid, | ||
5451 | network->ssid_len), | ||
5452 | network->bssid); | ||
5453 | return 0; | ||
5454 | } | ||
5455 | } else { | ||
5456 | /* If an ESSID has been configured then compare the broadcast | ||
5457 | * ESSID to ours */ | ||
5458 | if ((priv->config & CFG_STATIC_ESSID) && | ||
5459 | ((network->ssid_len != priv->essid_len) || | ||
5460 | memcmp(network->ssid, priv->essid, | ||
5461 | min(network->ssid_len, priv->essid_len)))) { | ||
5462 | char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; | ||
5463 | |||
5464 | strncpy(escaped, | ||
5465 | print_ssid(ssid, network->ssid, | ||
5466 | network->ssid_len), | ||
5467 | sizeof(escaped)); | ||
5468 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " | ||
5469 | "because of ESSID mismatch: '%s'.\n", | ||
5470 | escaped, network->bssid, | ||
5471 | print_ssid(ssid, priv->essid, | ||
5472 | priv->essid_len)); | ||
5473 | return 0; | ||
5474 | } | ||
5475 | } | ||
5476 | |||
5477 | /* If the old network rate is better than this one, don't bother | ||
5478 | * testing everything else. */ | ||
5479 | |||
5480 | if (network->time_stamp[0] < match->network->time_stamp[0]) { | ||
5481 | IPW_DEBUG_MERGE("Network '%s excluded because newer than " | ||
5482 | "current network.\n", | ||
5483 | print_ssid(ssid, match->network->ssid, | ||
5484 | match->network->ssid_len)); | ||
5485 | return 0; | ||
5486 | } else if (network->time_stamp[1] < match->network->time_stamp[1]) { | ||
5487 | IPW_DEBUG_MERGE("Network '%s excluded because newer than " | ||
5488 | "current network.\n", | ||
5489 | print_ssid(ssid, match->network->ssid, | ||
5490 | match->network->ssid_len)); | ||
5491 | return 0; | ||
5492 | } | ||
5493 | |||
5494 | /* Now go through and see if the requested network is valid... */ | ||
5495 | if (priv->ieee->scan_age != 0 && | ||
5496 | time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) { | ||
5497 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " | ||
5498 | "because of age: %ums.\n", | ||
5499 | print_ssid(ssid, network->ssid, | ||
5500 | network->ssid_len), | ||
5501 | network->bssid, | ||
5502 | jiffies_to_msecs(jiffies - | ||
5503 | network->last_scanned)); | ||
5504 | return 0; | ||
5505 | } | ||
5506 | |||
5507 | if ((priv->config & CFG_STATIC_CHANNEL) && | ||
5508 | (network->channel != priv->channel)) { | ||
5509 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " | ||
5510 | "because of channel mismatch: %d != %d.\n", | ||
5511 | print_ssid(ssid, network->ssid, | ||
5512 | network->ssid_len), | ||
5513 | network->bssid, | ||
5514 | network->channel, priv->channel); | ||
5515 | return 0; | ||
5516 | } | ||
5517 | |||
5518 | /* Verify privacy compatability */ | ||
5519 | if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) != | ||
5520 | ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) { | ||
5521 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " | ||
5522 | "because of privacy mismatch: %s != %s.\n", | ||
5523 | print_ssid(ssid, network->ssid, | ||
5524 | network->ssid_len), | ||
5525 | network->bssid, | ||
5526 | priv-> | ||
5527 | capability & CAP_PRIVACY_ON ? "on" : "off", | ||
5528 | network-> | ||
5529 | capability & WLAN_CAPABILITY_PRIVACY ? "on" : | ||
5530 | "off"); | ||
5531 | return 0; | ||
5532 | } | ||
5533 | |||
5534 | if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) { | ||
5535 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " | ||
5536 | "because of the same BSSID match: %pM" | ||
5537 | ".\n", print_ssid(ssid, network->ssid, | ||
5538 | network->ssid_len), | ||
5539 | network->bssid, | ||
5540 | priv->bssid); | ||
5541 | return 0; | ||
5542 | } | ||
5543 | |||
5544 | /* Filter out any incompatible freq / mode combinations */ | ||
5545 | if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) { | ||
5546 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " | ||
5547 | "because of invalid frequency/mode " | ||
5548 | "combination.\n", | ||
5549 | print_ssid(ssid, network->ssid, | ||
5550 | network->ssid_len), | ||
5551 | network->bssid); | ||
5552 | return 0; | ||
5553 | } | ||
5554 | |||
5555 | /* Ensure that the rates supported by the driver are compatible with | ||
5556 | * this AP, including verification of basic rates (mandatory) */ | ||
5557 | if (!ipw_compatible_rates(priv, network, &rates)) { | ||
5558 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " | ||
5559 | "because configured rate mask excludes " | ||
5560 | "AP mandatory rate.\n", | ||
5561 | print_ssid(ssid, network->ssid, | ||
5562 | network->ssid_len), | ||
5563 | network->bssid); | ||
5564 | return 0; | ||
5565 | } | ||
5566 | |||
5567 | if (rates.num_rates == 0) { | ||
5568 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " | ||
5569 | "because of no compatible rates.\n", | ||
5570 | print_ssid(ssid, network->ssid, | ||
5571 | network->ssid_len), | ||
5572 | network->bssid); | ||
5573 | return 0; | ||
5574 | } | ||
5575 | |||
5576 | /* TODO: Perform any further minimal comparititive tests. We do not | ||
5577 | * want to put too much policy logic here; intelligent scan selection | ||
5578 | * should occur within a generic IEEE 802.11 user space tool. */ | ||
5579 | |||
5580 | /* Set up 'new' AP to this network */ | ||
5581 | ipw_copy_rates(&match->rates, &rates); | ||
5582 | match->network = network; | ||
5583 | IPW_DEBUG_MERGE("Network '%s (%pM)' is a viable match.\n", | ||
5584 | print_ssid(ssid, network->ssid, network->ssid_len), | ||
5585 | network->bssid); | ||
5586 | |||
5587 | return 1; | ||
5588 | } | ||
5589 | |||
5590 | static void ipw_merge_adhoc_network(struct work_struct *work) | ||
5591 | { | ||
5592 | DECLARE_SSID_BUF(ssid); | ||
5593 | struct ipw_priv *priv = | ||
5594 | container_of(work, struct ipw_priv, merge_networks); | ||
5595 | struct ieee80211_network *network = NULL; | ||
5596 | struct ipw_network_match match = { | ||
5597 | .network = priv->assoc_network | ||
5598 | }; | ||
5599 | |||
5600 | if ((priv->status & STATUS_ASSOCIATED) && | ||
5601 | (priv->ieee->iw_mode == IW_MODE_ADHOC)) { | ||
5602 | /* First pass through ROAM process -- look for a better | ||
5603 | * network */ | ||
5604 | unsigned long flags; | ||
5605 | |||
5606 | spin_lock_irqsave(&priv->ieee->lock, flags); | ||
5607 | list_for_each_entry(network, &priv->ieee->network_list, list) { | ||
5608 | if (network != priv->assoc_network) | ||
5609 | ipw_find_adhoc_network(priv, &match, network, | ||
5610 | 1); | ||
5611 | } | ||
5612 | spin_unlock_irqrestore(&priv->ieee->lock, flags); | ||
5613 | |||
5614 | if (match.network == priv->assoc_network) { | ||
5615 | IPW_DEBUG_MERGE("No better ADHOC in this network to " | ||
5616 | "merge to.\n"); | ||
5617 | return; | ||
5618 | } | ||
5619 | |||
5620 | mutex_lock(&priv->mutex); | ||
5621 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) { | ||
5622 | IPW_DEBUG_MERGE("remove network %s\n", | ||
5623 | print_ssid(ssid, priv->essid, | ||
5624 | priv->essid_len)); | ||
5625 | ipw_remove_current_network(priv); | ||
5626 | } | ||
5627 | |||
5628 | ipw_disassociate(priv); | ||
5629 | priv->assoc_network = match.network; | ||
5630 | mutex_unlock(&priv->mutex); | ||
5631 | return; | ||
5632 | } | ||
5633 | } | ||
5634 | |||
5635 | static int ipw_best_network(struct ipw_priv *priv, | ||
5636 | struct ipw_network_match *match, | ||
5637 | struct ieee80211_network *network, int roaming) | ||
5638 | { | ||
5639 | struct ipw_supported_rates rates; | ||
5640 | DECLARE_SSID_BUF(ssid); | ||
5641 | |||
5642 | /* Verify that this network's capability is compatible with the | ||
5643 | * current mode (AdHoc or Infrastructure) */ | ||
5644 | if ((priv->ieee->iw_mode == IW_MODE_INFRA && | ||
5645 | !(network->capability & WLAN_CAPABILITY_ESS)) || | ||
5646 | (priv->ieee->iw_mode == IW_MODE_ADHOC && | ||
5647 | !(network->capability & WLAN_CAPABILITY_IBSS))) { | ||
5648 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded due to " | ||
5649 | "capability mismatch.\n", | ||
5650 | print_ssid(ssid, network->ssid, | ||
5651 | network->ssid_len), | ||
5652 | network->bssid); | ||
5653 | return 0; | ||
5654 | } | ||
5655 | |||
5656 | if (unlikely(roaming)) { | ||
5657 | /* If we are roaming, then ensure check if this is a valid | ||
5658 | * network to try and roam to */ | ||
5659 | if ((network->ssid_len != match->network->ssid_len) || | ||
5660 | memcmp(network->ssid, match->network->ssid, | ||
5661 | network->ssid_len)) { | ||
5662 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " | ||
5663 | "because of non-network ESSID.\n", | ||
5664 | print_ssid(ssid, network->ssid, | ||
5665 | network->ssid_len), | ||
5666 | network->bssid); | ||
5667 | return 0; | ||
5668 | } | ||
5669 | } else { | ||
5670 | /* If an ESSID has been configured then compare the broadcast | ||
5671 | * ESSID to ours */ | ||
5672 | if ((priv->config & CFG_STATIC_ESSID) && | ||
5673 | ((network->ssid_len != priv->essid_len) || | ||
5674 | memcmp(network->ssid, priv->essid, | ||
5675 | min(network->ssid_len, priv->essid_len)))) { | ||
5676 | char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; | ||
5677 | strncpy(escaped, | ||
5678 | print_ssid(ssid, network->ssid, | ||
5679 | network->ssid_len), | ||
5680 | sizeof(escaped)); | ||
5681 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " | ||
5682 | "because of ESSID mismatch: '%s'.\n", | ||
5683 | escaped, network->bssid, | ||
5684 | print_ssid(ssid, priv->essid, | ||
5685 | priv->essid_len)); | ||
5686 | return 0; | ||
5687 | } | ||
5688 | } | ||
5689 | |||
5690 | /* If the old network rate is better than this one, don't bother | ||
5691 | * testing everything else. */ | ||
5692 | if (match->network && match->network->stats.rssi > network->stats.rssi) { | ||
5693 | char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; | ||
5694 | strncpy(escaped, | ||
5695 | print_ssid(ssid, network->ssid, network->ssid_len), | ||
5696 | sizeof(escaped)); | ||
5697 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded because " | ||
5698 | "'%s (%pM)' has a stronger signal.\n", | ||
5699 | escaped, network->bssid, | ||
5700 | print_ssid(ssid, match->network->ssid, | ||
5701 | match->network->ssid_len), | ||
5702 | match->network->bssid); | ||
5703 | return 0; | ||
5704 | } | ||
5705 | |||
5706 | /* If this network has already had an association attempt within the | ||
5707 | * last 3 seconds, do not try and associate again... */ | ||
5708 | if (network->last_associate && | ||
5709 | time_after(network->last_associate + (HZ * 3UL), jiffies)) { | ||
5710 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " | ||
5711 | "because of storming (%ums since last " | ||
5712 | "assoc attempt).\n", | ||
5713 | print_ssid(ssid, network->ssid, | ||
5714 | network->ssid_len), | ||
5715 | network->bssid, | ||
5716 | jiffies_to_msecs(jiffies - | ||
5717 | network->last_associate)); | ||
5718 | return 0; | ||
5719 | } | ||
5720 | |||
5721 | /* Now go through and see if the requested network is valid... */ | ||
5722 | if (priv->ieee->scan_age != 0 && | ||
5723 | time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) { | ||
5724 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " | ||
5725 | "because of age: %ums.\n", | ||
5726 | print_ssid(ssid, network->ssid, | ||
5727 | network->ssid_len), | ||
5728 | network->bssid, | ||
5729 | jiffies_to_msecs(jiffies - | ||
5730 | network->last_scanned)); | ||
5731 | return 0; | ||
5732 | } | ||
5733 | |||
5734 | if ((priv->config & CFG_STATIC_CHANNEL) && | ||
5735 | (network->channel != priv->channel)) { | ||
5736 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " | ||
5737 | "because of channel mismatch: %d != %d.\n", | ||
5738 | print_ssid(ssid, network->ssid, | ||
5739 | network->ssid_len), | ||
5740 | network->bssid, | ||
5741 | network->channel, priv->channel); | ||
5742 | return 0; | ||
5743 | } | ||
5744 | |||
5745 | /* Verify privacy compatability */ | ||
5746 | if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) != | ||
5747 | ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) { | ||
5748 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " | ||
5749 | "because of privacy mismatch: %s != %s.\n", | ||
5750 | print_ssid(ssid, network->ssid, | ||
5751 | network->ssid_len), | ||
5752 | network->bssid, | ||
5753 | priv->capability & CAP_PRIVACY_ON ? "on" : | ||
5754 | "off", | ||
5755 | network->capability & | ||
5756 | WLAN_CAPABILITY_PRIVACY ? "on" : "off"); | ||
5757 | return 0; | ||
5758 | } | ||
5759 | |||
5760 | if ((priv->config & CFG_STATIC_BSSID) && | ||
5761 | memcmp(network->bssid, priv->bssid, ETH_ALEN)) { | ||
5762 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " | ||
5763 | "because of BSSID mismatch: %pM.\n", | ||
5764 | print_ssid(ssid, network->ssid, | ||
5765 | network->ssid_len), | ||
5766 | network->bssid, priv->bssid); | ||
5767 | return 0; | ||
5768 | } | ||
5769 | |||
5770 | /* Filter out any incompatible freq / mode combinations */ | ||
5771 | if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) { | ||
5772 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " | ||
5773 | "because of invalid frequency/mode " | ||
5774 | "combination.\n", | ||
5775 | print_ssid(ssid, network->ssid, | ||
5776 | network->ssid_len), | ||
5777 | network->bssid); | ||
5778 | return 0; | ||
5779 | } | ||
5780 | |||
5781 | /* Filter out invalid channel in current GEO */ | ||
5782 | if (!ieee80211_is_valid_channel(priv->ieee, network->channel)) { | ||
5783 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " | ||
5784 | "because of invalid channel in current GEO\n", | ||
5785 | print_ssid(ssid, network->ssid, | ||
5786 | network->ssid_len), | ||
5787 | network->bssid); | ||
5788 | return 0; | ||
5789 | } | ||
5790 | |||
5791 | /* Ensure that the rates supported by the driver are compatible with | ||
5792 | * this AP, including verification of basic rates (mandatory) */ | ||
5793 | if (!ipw_compatible_rates(priv, network, &rates)) { | ||
5794 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " | ||
5795 | "because configured rate mask excludes " | ||
5796 | "AP mandatory rate.\n", | ||
5797 | print_ssid(ssid, network->ssid, | ||
5798 | network->ssid_len), | ||
5799 | network->bssid); | ||
5800 | return 0; | ||
5801 | } | ||
5802 | |||
5803 | if (rates.num_rates == 0) { | ||
5804 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " | ||
5805 | "because of no compatible rates.\n", | ||
5806 | print_ssid(ssid, network->ssid, | ||
5807 | network->ssid_len), | ||
5808 | network->bssid); | ||
5809 | return 0; | ||
5810 | } | ||
5811 | |||
5812 | /* TODO: Perform any further minimal comparititive tests. We do not | ||
5813 | * want to put too much policy logic here; intelligent scan selection | ||
5814 | * should occur within a generic IEEE 802.11 user space tool. */ | ||
5815 | |||
5816 | /* Set up 'new' AP to this network */ | ||
5817 | ipw_copy_rates(&match->rates, &rates); | ||
5818 | match->network = network; | ||
5819 | |||
5820 | IPW_DEBUG_ASSOC("Network '%s (%pM)' is a viable match.\n", | ||
5821 | print_ssid(ssid, network->ssid, network->ssid_len), | ||
5822 | network->bssid); | ||
5823 | |||
5824 | return 1; | ||
5825 | } | ||
5826 | |||
5827 | static void ipw_adhoc_create(struct ipw_priv *priv, | ||
5828 | struct ieee80211_network *network) | ||
5829 | { | ||
5830 | const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee); | ||
5831 | int i; | ||
5832 | |||
5833 | /* | ||
5834 | * For the purposes of scanning, we can set our wireless mode | ||
5835 | * to trigger scans across combinations of bands, but when it | ||
5836 | * comes to creating a new ad-hoc network, we have tell the FW | ||
5837 | * exactly which band to use. | ||
5838 | * | ||
5839 | * We also have the possibility of an invalid channel for the | ||
5840 | * chossen band. Attempting to create a new ad-hoc network | ||
5841 | * with an invalid channel for wireless mode will trigger a | ||
5842 | * FW fatal error. | ||
5843 | * | ||
5844 | */ | ||
5845 | switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) { | ||
5846 | case IEEE80211_52GHZ_BAND: | ||
5847 | network->mode = IEEE_A; | ||
5848 | i = ieee80211_channel_to_index(priv->ieee, priv->channel); | ||
5849 | BUG_ON(i == -1); | ||
5850 | if (geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY) { | ||
5851 | IPW_WARNING("Overriding invalid channel\n"); | ||
5852 | priv->channel = geo->a[0].channel; | ||
5853 | } | ||
5854 | break; | ||
5855 | |||
5856 | case IEEE80211_24GHZ_BAND: | ||
5857 | if (priv->ieee->mode & IEEE_G) | ||
5858 | network->mode = IEEE_G; | ||
5859 | else | ||
5860 | network->mode = IEEE_B; | ||
5861 | i = ieee80211_channel_to_index(priv->ieee, priv->channel); | ||
5862 | BUG_ON(i == -1); | ||
5863 | if (geo->bg[i].flags & IEEE80211_CH_PASSIVE_ONLY) { | ||
5864 | IPW_WARNING("Overriding invalid channel\n"); | ||
5865 | priv->channel = geo->bg[0].channel; | ||
5866 | } | ||
5867 | break; | ||
5868 | |||
5869 | default: | ||
5870 | IPW_WARNING("Overriding invalid channel\n"); | ||
5871 | if (priv->ieee->mode & IEEE_A) { | ||
5872 | network->mode = IEEE_A; | ||
5873 | priv->channel = geo->a[0].channel; | ||
5874 | } else if (priv->ieee->mode & IEEE_G) { | ||
5875 | network->mode = IEEE_G; | ||
5876 | priv->channel = geo->bg[0].channel; | ||
5877 | } else { | ||
5878 | network->mode = IEEE_B; | ||
5879 | priv->channel = geo->bg[0].channel; | ||
5880 | } | ||
5881 | break; | ||
5882 | } | ||
5883 | |||
5884 | network->channel = priv->channel; | ||
5885 | priv->config |= CFG_ADHOC_PERSIST; | ||
5886 | ipw_create_bssid(priv, network->bssid); | ||
5887 | network->ssid_len = priv->essid_len; | ||
5888 | memcpy(network->ssid, priv->essid, priv->essid_len); | ||
5889 | memset(&network->stats, 0, sizeof(network->stats)); | ||
5890 | network->capability = WLAN_CAPABILITY_IBSS; | ||
5891 | if (!(priv->config & CFG_PREAMBLE_LONG)) | ||
5892 | network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE; | ||
5893 | if (priv->capability & CAP_PRIVACY_ON) | ||
5894 | network->capability |= WLAN_CAPABILITY_PRIVACY; | ||
5895 | network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH); | ||
5896 | memcpy(network->rates, priv->rates.supported_rates, network->rates_len); | ||
5897 | network->rates_ex_len = priv->rates.num_rates - network->rates_len; | ||
5898 | memcpy(network->rates_ex, | ||
5899 | &priv->rates.supported_rates[network->rates_len], | ||
5900 | network->rates_ex_len); | ||
5901 | network->last_scanned = 0; | ||
5902 | network->flags = 0; | ||
5903 | network->last_associate = 0; | ||
5904 | network->time_stamp[0] = 0; | ||
5905 | network->time_stamp[1] = 0; | ||
5906 | network->beacon_interval = 100; /* Default */ | ||
5907 | network->listen_interval = 10; /* Default */ | ||
5908 | network->atim_window = 0; /* Default */ | ||
5909 | network->wpa_ie_len = 0; | ||
5910 | network->rsn_ie_len = 0; | ||
5911 | } | ||
5912 | |||
5913 | static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index) | ||
5914 | { | ||
5915 | struct ipw_tgi_tx_key key; | ||
5916 | |||
5917 | if (!(priv->ieee->sec.flags & (1 << index))) | ||
5918 | return; | ||
5919 | |||
5920 | key.key_id = index; | ||
5921 | memcpy(key.key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH); | ||
5922 | key.security_type = type; | ||
5923 | key.station_index = 0; /* always 0 for BSS */ | ||
5924 | key.flags = 0; | ||
5925 | /* 0 for new key; previous value of counter (after fatal error) */ | ||
5926 | key.tx_counter[0] = cpu_to_le32(0); | ||
5927 | key.tx_counter[1] = cpu_to_le32(0); | ||
5928 | |||
5929 | ipw_send_cmd_pdu(priv, IPW_CMD_TGI_TX_KEY, sizeof(key), &key); | ||
5930 | } | ||
5931 | |||
5932 | static void ipw_send_wep_keys(struct ipw_priv *priv, int type) | ||
5933 | { | ||
5934 | struct ipw_wep_key key; | ||
5935 | int i; | ||
5936 | |||
5937 | key.cmd_id = DINO_CMD_WEP_KEY; | ||
5938 | key.seq_num = 0; | ||
5939 | |||
5940 | /* Note: AES keys cannot be set for multiple times. | ||
5941 | * Only set it at the first time. */ | ||
5942 | for (i = 0; i < 4; i++) { | ||
5943 | key.key_index = i | type; | ||
5944 | if (!(priv->ieee->sec.flags & (1 << i))) { | ||
5945 | key.key_size = 0; | ||
5946 | continue; | ||
5947 | } | ||
5948 | |||
5949 | key.key_size = priv->ieee->sec.key_sizes[i]; | ||
5950 | memcpy(key.key, priv->ieee->sec.keys[i], key.key_size); | ||
5951 | |||
5952 | ipw_send_cmd_pdu(priv, IPW_CMD_WEP_KEY, sizeof(key), &key); | ||
5953 | } | ||
5954 | } | ||
5955 | |||
5956 | static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level) | ||
5957 | { | ||
5958 | if (priv->ieee->host_encrypt) | ||
5959 | return; | ||
5960 | |||
5961 | switch (level) { | ||
5962 | case SEC_LEVEL_3: | ||
5963 | priv->sys_config.disable_unicast_decryption = 0; | ||
5964 | priv->ieee->host_decrypt = 0; | ||
5965 | break; | ||
5966 | case SEC_LEVEL_2: | ||
5967 | priv->sys_config.disable_unicast_decryption = 1; | ||
5968 | priv->ieee->host_decrypt = 1; | ||
5969 | break; | ||
5970 | case SEC_LEVEL_1: | ||
5971 | priv->sys_config.disable_unicast_decryption = 0; | ||
5972 | priv->ieee->host_decrypt = 0; | ||
5973 | break; | ||
5974 | case SEC_LEVEL_0: | ||
5975 | priv->sys_config.disable_unicast_decryption = 1; | ||
5976 | break; | ||
5977 | default: | ||
5978 | break; | ||
5979 | } | ||
5980 | } | ||
5981 | |||
5982 | static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level) | ||
5983 | { | ||
5984 | if (priv->ieee->host_encrypt) | ||
5985 | return; | ||
5986 | |||
5987 | switch (level) { | ||
5988 | case SEC_LEVEL_3: | ||
5989 | priv->sys_config.disable_multicast_decryption = 0; | ||
5990 | break; | ||
5991 | case SEC_LEVEL_2: | ||
5992 | priv->sys_config.disable_multicast_decryption = 1; | ||
5993 | break; | ||
5994 | case SEC_LEVEL_1: | ||
5995 | priv->sys_config.disable_multicast_decryption = 0; | ||
5996 | break; | ||
5997 | case SEC_LEVEL_0: | ||
5998 | priv->sys_config.disable_multicast_decryption = 1; | ||
5999 | break; | ||
6000 | default: | ||
6001 | break; | ||
6002 | } | ||
6003 | } | ||
6004 | |||
6005 | static void ipw_set_hwcrypto_keys(struct ipw_priv *priv) | ||
6006 | { | ||
6007 | switch (priv->ieee->sec.level) { | ||
6008 | case SEC_LEVEL_3: | ||
6009 | if (priv->ieee->sec.flags & SEC_ACTIVE_KEY) | ||
6010 | ipw_send_tgi_tx_key(priv, | ||
6011 | DCT_FLAG_EXT_SECURITY_CCM, | ||
6012 | priv->ieee->sec.active_key); | ||
6013 | |||
6014 | if (!priv->ieee->host_mc_decrypt) | ||
6015 | ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM); | ||
6016 | break; | ||
6017 | case SEC_LEVEL_2: | ||
6018 | if (priv->ieee->sec.flags & SEC_ACTIVE_KEY) | ||
6019 | ipw_send_tgi_tx_key(priv, | ||
6020 | DCT_FLAG_EXT_SECURITY_TKIP, | ||
6021 | priv->ieee->sec.active_key); | ||
6022 | break; | ||
6023 | case SEC_LEVEL_1: | ||
6024 | ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP); | ||
6025 | ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level); | ||
6026 | ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level); | ||
6027 | break; | ||
6028 | case SEC_LEVEL_0: | ||
6029 | default: | ||
6030 | break; | ||
6031 | } | ||
6032 | } | ||
6033 | |||
6034 | static void ipw_adhoc_check(void *data) | ||
6035 | { | ||
6036 | struct ipw_priv *priv = data; | ||
6037 | |||
6038 | if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold && | ||
6039 | !(priv->config & CFG_ADHOC_PERSIST)) { | ||
6040 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | | ||
6041 | IPW_DL_STATE | IPW_DL_ASSOC, | ||
6042 | "Missed beacon: %d - disassociate\n", | ||
6043 | priv->missed_adhoc_beacons); | ||
6044 | ipw_remove_current_network(priv); | ||
6045 | ipw_disassociate(priv); | ||
6046 | return; | ||
6047 | } | ||
6048 | |||
6049 | queue_delayed_work(priv->workqueue, &priv->adhoc_check, | ||
6050 | le16_to_cpu(priv->assoc_request.beacon_interval)); | ||
6051 | } | ||
6052 | |||
6053 | static void ipw_bg_adhoc_check(struct work_struct *work) | ||
6054 | { | ||
6055 | struct ipw_priv *priv = | ||
6056 | container_of(work, struct ipw_priv, adhoc_check.work); | ||
6057 | mutex_lock(&priv->mutex); | ||
6058 | ipw_adhoc_check(priv); | ||
6059 | mutex_unlock(&priv->mutex); | ||
6060 | } | ||
6061 | |||
6062 | static void ipw_debug_config(struct ipw_priv *priv) | ||
6063 | { | ||
6064 | DECLARE_SSID_BUF(ssid); | ||
6065 | IPW_DEBUG_INFO("Scan completed, no valid APs matched " | ||
6066 | "[CFG 0x%08X]\n", priv->config); | ||
6067 | if (priv->config & CFG_STATIC_CHANNEL) | ||
6068 | IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel); | ||
6069 | else | ||
6070 | IPW_DEBUG_INFO("Channel unlocked.\n"); | ||
6071 | if (priv->config & CFG_STATIC_ESSID) | ||
6072 | IPW_DEBUG_INFO("ESSID locked to '%s'\n", | ||
6073 | print_ssid(ssid, priv->essid, priv->essid_len)); | ||
6074 | else | ||
6075 | IPW_DEBUG_INFO("ESSID unlocked.\n"); | ||
6076 | if (priv->config & CFG_STATIC_BSSID) | ||
6077 | IPW_DEBUG_INFO("BSSID locked to %pM\n", priv->bssid); | ||
6078 | else | ||
6079 | IPW_DEBUG_INFO("BSSID unlocked.\n"); | ||
6080 | if (priv->capability & CAP_PRIVACY_ON) | ||
6081 | IPW_DEBUG_INFO("PRIVACY on\n"); | ||
6082 | else | ||
6083 | IPW_DEBUG_INFO("PRIVACY off\n"); | ||
6084 | IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask); | ||
6085 | } | ||
6086 | |||
6087 | static void ipw_set_fixed_rate(struct ipw_priv *priv, int mode) | ||
6088 | { | ||
6089 | /* TODO: Verify that this works... */ | ||
6090 | struct ipw_fixed_rate fr = { | ||
6091 | .tx_rates = priv->rates_mask | ||
6092 | }; | ||
6093 | u32 reg; | ||
6094 | u16 mask = 0; | ||
6095 | |||
6096 | /* Identify 'current FW band' and match it with the fixed | ||
6097 | * Tx rates */ | ||
6098 | |||
6099 | switch (priv->ieee->freq_band) { | ||
6100 | case IEEE80211_52GHZ_BAND: /* A only */ | ||
6101 | /* IEEE_A */ | ||
6102 | if (priv->rates_mask & ~IEEE80211_OFDM_RATES_MASK) { | ||
6103 | /* Invalid fixed rate mask */ | ||
6104 | IPW_DEBUG_WX | ||
6105 | ("invalid fixed rate mask in ipw_set_fixed_rate\n"); | ||
6106 | fr.tx_rates = 0; | ||
6107 | break; | ||
6108 | } | ||
6109 | |||
6110 | fr.tx_rates >>= IEEE80211_OFDM_SHIFT_MASK_A; | ||
6111 | break; | ||
6112 | |||
6113 | default: /* 2.4Ghz or Mixed */ | ||
6114 | /* IEEE_B */ | ||
6115 | if (mode == IEEE_B) { | ||
6116 | if (fr.tx_rates & ~IEEE80211_CCK_RATES_MASK) { | ||
6117 | /* Invalid fixed rate mask */ | ||
6118 | IPW_DEBUG_WX | ||
6119 | ("invalid fixed rate mask in ipw_set_fixed_rate\n"); | ||
6120 | fr.tx_rates = 0; | ||
6121 | } | ||
6122 | break; | ||
6123 | } | ||
6124 | |||
6125 | /* IEEE_G */ | ||
6126 | if (fr.tx_rates & ~(IEEE80211_CCK_RATES_MASK | | ||
6127 | IEEE80211_OFDM_RATES_MASK)) { | ||
6128 | /* Invalid fixed rate mask */ | ||
6129 | IPW_DEBUG_WX | ||
6130 | ("invalid fixed rate mask in ipw_set_fixed_rate\n"); | ||
6131 | fr.tx_rates = 0; | ||
6132 | break; | ||
6133 | } | ||
6134 | |||
6135 | if (IEEE80211_OFDM_RATE_6MB_MASK & fr.tx_rates) { | ||
6136 | mask |= (IEEE80211_OFDM_RATE_6MB_MASK >> 1); | ||
6137 | fr.tx_rates &= ~IEEE80211_OFDM_RATE_6MB_MASK; | ||
6138 | } | ||
6139 | |||
6140 | if (IEEE80211_OFDM_RATE_9MB_MASK & fr.tx_rates) { | ||
6141 | mask |= (IEEE80211_OFDM_RATE_9MB_MASK >> 1); | ||
6142 | fr.tx_rates &= ~IEEE80211_OFDM_RATE_9MB_MASK; | ||
6143 | } | ||
6144 | |||
6145 | if (IEEE80211_OFDM_RATE_12MB_MASK & fr.tx_rates) { | ||
6146 | mask |= (IEEE80211_OFDM_RATE_12MB_MASK >> 1); | ||
6147 | fr.tx_rates &= ~IEEE80211_OFDM_RATE_12MB_MASK; | ||
6148 | } | ||
6149 | |||
6150 | fr.tx_rates |= mask; | ||
6151 | break; | ||
6152 | } | ||
6153 | |||
6154 | reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE); | ||
6155 | ipw_write_reg32(priv, reg, *(u32 *) & fr); | ||
6156 | } | ||
6157 | |||
6158 | static void ipw_abort_scan(struct ipw_priv *priv) | ||
6159 | { | ||
6160 | int err; | ||
6161 | |||
6162 | if (priv->status & STATUS_SCAN_ABORTING) { | ||
6163 | IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n"); | ||
6164 | return; | ||
6165 | } | ||
6166 | priv->status |= STATUS_SCAN_ABORTING; | ||
6167 | |||
6168 | err = ipw_send_scan_abort(priv); | ||
6169 | if (err) | ||
6170 | IPW_DEBUG_HC("Request to abort scan failed.\n"); | ||
6171 | } | ||
6172 | |||
6173 | static void ipw_add_scan_channels(struct ipw_priv *priv, | ||
6174 | struct ipw_scan_request_ext *scan, | ||
6175 | int scan_type) | ||
6176 | { | ||
6177 | int channel_index = 0; | ||
6178 | const struct ieee80211_geo *geo; | ||
6179 | int i; | ||
6180 | |||
6181 | geo = ieee80211_get_geo(priv->ieee); | ||
6182 | |||
6183 | if (priv->ieee->freq_band & IEEE80211_52GHZ_BAND) { | ||
6184 | int start = channel_index; | ||
6185 | for (i = 0; i < geo->a_channels; i++) { | ||
6186 | if ((priv->status & STATUS_ASSOCIATED) && | ||
6187 | geo->a[i].channel == priv->channel) | ||
6188 | continue; | ||
6189 | channel_index++; | ||
6190 | scan->channels_list[channel_index] = geo->a[i].channel; | ||
6191 | ipw_set_scan_type(scan, channel_index, | ||
6192 | geo->a[i]. | ||
6193 | flags & IEEE80211_CH_PASSIVE_ONLY ? | ||
6194 | IPW_SCAN_PASSIVE_FULL_DWELL_SCAN : | ||
6195 | scan_type); | ||
6196 | } | ||
6197 | |||
6198 | if (start != channel_index) { | ||
6199 | scan->channels_list[start] = (u8) (IPW_A_MODE << 6) | | ||
6200 | (channel_index - start); | ||
6201 | channel_index++; | ||
6202 | } | ||
6203 | } | ||
6204 | |||
6205 | if (priv->ieee->freq_band & IEEE80211_24GHZ_BAND) { | ||
6206 | int start = channel_index; | ||
6207 | if (priv->config & CFG_SPEED_SCAN) { | ||
6208 | int index; | ||
6209 | u8 channels[IEEE80211_24GHZ_CHANNELS] = { | ||
6210 | /* nop out the list */ | ||
6211 | [0] = 0 | ||
6212 | }; | ||
6213 | |||
6214 | u8 channel; | ||
6215 | while (channel_index < IPW_SCAN_CHANNELS) { | ||
6216 | channel = | ||
6217 | priv->speed_scan[priv->speed_scan_pos]; | ||
6218 | if (channel == 0) { | ||
6219 | priv->speed_scan_pos = 0; | ||
6220 | channel = priv->speed_scan[0]; | ||
6221 | } | ||
6222 | if ((priv->status & STATUS_ASSOCIATED) && | ||
6223 | channel == priv->channel) { | ||
6224 | priv->speed_scan_pos++; | ||
6225 | continue; | ||
6226 | } | ||
6227 | |||
6228 | /* If this channel has already been | ||
6229 | * added in scan, break from loop | ||
6230 | * and this will be the first channel | ||
6231 | * in the next scan. | ||
6232 | */ | ||
6233 | if (channels[channel - 1] != 0) | ||
6234 | break; | ||
6235 | |||
6236 | channels[channel - 1] = 1; | ||
6237 | priv->speed_scan_pos++; | ||
6238 | channel_index++; | ||
6239 | scan->channels_list[channel_index] = channel; | ||
6240 | index = | ||
6241 | ieee80211_channel_to_index(priv->ieee, channel); | ||
6242 | ipw_set_scan_type(scan, channel_index, | ||
6243 | geo->bg[index]. | ||
6244 | flags & | ||
6245 | IEEE80211_CH_PASSIVE_ONLY ? | ||
6246 | IPW_SCAN_PASSIVE_FULL_DWELL_SCAN | ||
6247 | : scan_type); | ||
6248 | } | ||
6249 | } else { | ||
6250 | for (i = 0; i < geo->bg_channels; i++) { | ||
6251 | if ((priv->status & STATUS_ASSOCIATED) && | ||
6252 | geo->bg[i].channel == priv->channel) | ||
6253 | continue; | ||
6254 | channel_index++; | ||
6255 | scan->channels_list[channel_index] = | ||
6256 | geo->bg[i].channel; | ||
6257 | ipw_set_scan_type(scan, channel_index, | ||
6258 | geo->bg[i]. | ||
6259 | flags & | ||
6260 | IEEE80211_CH_PASSIVE_ONLY ? | ||
6261 | IPW_SCAN_PASSIVE_FULL_DWELL_SCAN | ||
6262 | : scan_type); | ||
6263 | } | ||
6264 | } | ||
6265 | |||
6266 | if (start != channel_index) { | ||
6267 | scan->channels_list[start] = (u8) (IPW_B_MODE << 6) | | ||
6268 | (channel_index - start); | ||
6269 | } | ||
6270 | } | ||
6271 | } | ||
6272 | |||
6273 | static int ipw_request_scan_helper(struct ipw_priv *priv, int type, int direct) | ||
6274 | { | ||
6275 | struct ipw_scan_request_ext scan; | ||
6276 | int err = 0, scan_type; | ||
6277 | |||
6278 | if (!(priv->status & STATUS_INIT) || | ||
6279 | (priv->status & STATUS_EXIT_PENDING)) | ||
6280 | return 0; | ||
6281 | |||
6282 | mutex_lock(&priv->mutex); | ||
6283 | |||
6284 | if (direct && (priv->direct_scan_ssid_len == 0)) { | ||
6285 | IPW_DEBUG_HC("Direct scan requested but no SSID to scan for\n"); | ||
6286 | priv->status &= ~STATUS_DIRECT_SCAN_PENDING; | ||
6287 | goto done; | ||
6288 | } | ||
6289 | |||
6290 | if (priv->status & STATUS_SCANNING) { | ||
6291 | IPW_DEBUG_HC("Concurrent scan requested. Queuing.\n"); | ||
6292 | priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING : | ||
6293 | STATUS_SCAN_PENDING; | ||
6294 | goto done; | ||
6295 | } | ||
6296 | |||
6297 | if (!(priv->status & STATUS_SCAN_FORCED) && | ||
6298 | priv->status & STATUS_SCAN_ABORTING) { | ||
6299 | IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n"); | ||
6300 | priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING : | ||
6301 | STATUS_SCAN_PENDING; | ||
6302 | goto done; | ||
6303 | } | ||
6304 | |||
6305 | if (priv->status & STATUS_RF_KILL_MASK) { | ||
6306 | IPW_DEBUG_HC("Queuing scan due to RF Kill activation\n"); | ||
6307 | priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING : | ||
6308 | STATUS_SCAN_PENDING; | ||
6309 | goto done; | ||
6310 | } | ||
6311 | |||
6312 | memset(&scan, 0, sizeof(scan)); | ||
6313 | scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee)); | ||
6314 | |||
6315 | if (type == IW_SCAN_TYPE_PASSIVE) { | ||
6316 | IPW_DEBUG_WX("use passive scanning\n"); | ||
6317 | scan_type = IPW_SCAN_PASSIVE_FULL_DWELL_SCAN; | ||
6318 | scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = | ||
6319 | cpu_to_le16(120); | ||
6320 | ipw_add_scan_channels(priv, &scan, scan_type); | ||
6321 | goto send_request; | ||
6322 | } | ||
6323 | |||
6324 | /* Use active scan by default. */ | ||
6325 | if (priv->config & CFG_SPEED_SCAN) | ||
6326 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = | ||
6327 | cpu_to_le16(30); | ||
6328 | else | ||
6329 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = | ||
6330 | cpu_to_le16(20); | ||
6331 | |||
6332 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] = | ||
6333 | cpu_to_le16(20); | ||
6334 | |||
6335 | scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120); | ||
6336 | scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20); | ||
6337 | |||
6338 | #ifdef CONFIG_IPW2200_MONITOR | ||
6339 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { | ||
6340 | u8 channel; | ||
6341 | u8 band = 0; | ||
6342 | |||
6343 | switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) { | ||
6344 | case IEEE80211_52GHZ_BAND: | ||
6345 | band = (u8) (IPW_A_MODE << 6) | 1; | ||
6346 | channel = priv->channel; | ||
6347 | break; | ||
6348 | |||
6349 | case IEEE80211_24GHZ_BAND: | ||
6350 | band = (u8) (IPW_B_MODE << 6) | 1; | ||
6351 | channel = priv->channel; | ||
6352 | break; | ||
6353 | |||
6354 | default: | ||
6355 | band = (u8) (IPW_B_MODE << 6) | 1; | ||
6356 | channel = 9; | ||
6357 | break; | ||
6358 | } | ||
6359 | |||
6360 | scan.channels_list[0] = band; | ||
6361 | scan.channels_list[1] = channel; | ||
6362 | ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN); | ||
6363 | |||
6364 | /* NOTE: The card will sit on this channel for this time | ||
6365 | * period. Scan aborts are timing sensitive and frequently | ||
6366 | * result in firmware restarts. As such, it is best to | ||
6367 | * set a small dwell_time here and just keep re-issuing | ||
6368 | * scans. Otherwise fast channel hopping will not actually | ||
6369 | * hop channels. | ||
6370 | * | ||
6371 | * TODO: Move SPEED SCAN support to all modes and bands */ | ||
6372 | scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = | ||
6373 | cpu_to_le16(2000); | ||
6374 | } else { | ||
6375 | #endif /* CONFIG_IPW2200_MONITOR */ | ||
6376 | /* Honor direct scans first, otherwise if we are roaming make | ||
6377 | * this a direct scan for the current network. Finally, | ||
6378 | * ensure that every other scan is a fast channel hop scan */ | ||
6379 | if (direct) { | ||
6380 | err = ipw_send_ssid(priv, priv->direct_scan_ssid, | ||
6381 | priv->direct_scan_ssid_len); | ||
6382 | if (err) { | ||
6383 | IPW_DEBUG_HC("Attempt to send SSID command " | ||
6384 | "failed\n"); | ||
6385 | goto done; | ||
6386 | } | ||
6387 | |||
6388 | scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN; | ||
6389 | } else if ((priv->status & STATUS_ROAMING) | ||
6390 | || (!(priv->status & STATUS_ASSOCIATED) | ||
6391 | && (priv->config & CFG_STATIC_ESSID) | ||
6392 | && (le32_to_cpu(scan.full_scan_index) % 2))) { | ||
6393 | err = ipw_send_ssid(priv, priv->essid, priv->essid_len); | ||
6394 | if (err) { | ||
6395 | IPW_DEBUG_HC("Attempt to send SSID command " | ||
6396 | "failed.\n"); | ||
6397 | goto done; | ||
6398 | } | ||
6399 | |||
6400 | scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN; | ||
6401 | } else | ||
6402 | scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN; | ||
6403 | |||
6404 | ipw_add_scan_channels(priv, &scan, scan_type); | ||
6405 | #ifdef CONFIG_IPW2200_MONITOR | ||
6406 | } | ||
6407 | #endif | ||
6408 | |||
6409 | send_request: | ||
6410 | err = ipw_send_scan_request_ext(priv, &scan); | ||
6411 | if (err) { | ||
6412 | IPW_DEBUG_HC("Sending scan command failed: %08X\n", err); | ||
6413 | goto done; | ||
6414 | } | ||
6415 | |||
6416 | priv->status |= STATUS_SCANNING; | ||
6417 | if (direct) { | ||
6418 | priv->status &= ~STATUS_DIRECT_SCAN_PENDING; | ||
6419 | priv->direct_scan_ssid_len = 0; | ||
6420 | } else | ||
6421 | priv->status &= ~STATUS_SCAN_PENDING; | ||
6422 | |||
6423 | queue_delayed_work(priv->workqueue, &priv->scan_check, | ||
6424 | IPW_SCAN_CHECK_WATCHDOG); | ||
6425 | done: | ||
6426 | mutex_unlock(&priv->mutex); | ||
6427 | return err; | ||
6428 | } | ||
6429 | |||
6430 | static void ipw_request_passive_scan(struct work_struct *work) | ||
6431 | { | ||
6432 | struct ipw_priv *priv = | ||
6433 | container_of(work, struct ipw_priv, request_passive_scan.work); | ||
6434 | ipw_request_scan_helper(priv, IW_SCAN_TYPE_PASSIVE, 0); | ||
6435 | } | ||
6436 | |||
6437 | static void ipw_request_scan(struct work_struct *work) | ||
6438 | { | ||
6439 | struct ipw_priv *priv = | ||
6440 | container_of(work, struct ipw_priv, request_scan.work); | ||
6441 | ipw_request_scan_helper(priv, IW_SCAN_TYPE_ACTIVE, 0); | ||
6442 | } | ||
6443 | |||
6444 | static void ipw_request_direct_scan(struct work_struct *work) | ||
6445 | { | ||
6446 | struct ipw_priv *priv = | ||
6447 | container_of(work, struct ipw_priv, request_direct_scan.work); | ||
6448 | ipw_request_scan_helper(priv, IW_SCAN_TYPE_ACTIVE, 1); | ||
6449 | } | ||
6450 | |||
6451 | static void ipw_bg_abort_scan(struct work_struct *work) | ||
6452 | { | ||
6453 | struct ipw_priv *priv = | ||
6454 | container_of(work, struct ipw_priv, abort_scan); | ||
6455 | mutex_lock(&priv->mutex); | ||
6456 | ipw_abort_scan(priv); | ||
6457 | mutex_unlock(&priv->mutex); | ||
6458 | } | ||
6459 | |||
6460 | static int ipw_wpa_enable(struct ipw_priv *priv, int value) | ||
6461 | { | ||
6462 | /* This is called when wpa_supplicant loads and closes the driver | ||
6463 | * interface. */ | ||
6464 | priv->ieee->wpa_enabled = value; | ||
6465 | return 0; | ||
6466 | } | ||
6467 | |||
6468 | static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value) | ||
6469 | { | ||
6470 | struct ieee80211_device *ieee = priv->ieee; | ||
6471 | struct ieee80211_security sec = { | ||
6472 | .flags = SEC_AUTH_MODE, | ||
6473 | }; | ||
6474 | int ret = 0; | ||
6475 | |||
6476 | if (value & IW_AUTH_ALG_SHARED_KEY) { | ||
6477 | sec.auth_mode = WLAN_AUTH_SHARED_KEY; | ||
6478 | ieee->open_wep = 0; | ||
6479 | } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) { | ||
6480 | sec.auth_mode = WLAN_AUTH_OPEN; | ||
6481 | ieee->open_wep = 1; | ||
6482 | } else if (value & IW_AUTH_ALG_LEAP) { | ||
6483 | sec.auth_mode = WLAN_AUTH_LEAP; | ||
6484 | ieee->open_wep = 1; | ||
6485 | } else | ||
6486 | return -EINVAL; | ||
6487 | |||
6488 | if (ieee->set_security) | ||
6489 | ieee->set_security(ieee->dev, &sec); | ||
6490 | else | ||
6491 | ret = -EOPNOTSUPP; | ||
6492 | |||
6493 | return ret; | ||
6494 | } | ||
6495 | |||
6496 | static void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie, | ||
6497 | int wpa_ie_len) | ||
6498 | { | ||
6499 | /* make sure WPA is enabled */ | ||
6500 | ipw_wpa_enable(priv, 1); | ||
6501 | } | ||
6502 | |||
6503 | static int ipw_set_rsn_capa(struct ipw_priv *priv, | ||
6504 | char *capabilities, int length) | ||
6505 | { | ||
6506 | IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n"); | ||
6507 | |||
6508 | return ipw_send_cmd_pdu(priv, IPW_CMD_RSN_CAPABILITIES, length, | ||
6509 | capabilities); | ||
6510 | } | ||
6511 | |||
6512 | /* | ||
6513 | * WE-18 support | ||
6514 | */ | ||
6515 | |||
6516 | /* SIOCSIWGENIE */ | ||
6517 | static int ipw_wx_set_genie(struct net_device *dev, | ||
6518 | struct iw_request_info *info, | ||
6519 | union iwreq_data *wrqu, char *extra) | ||
6520 | { | ||
6521 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
6522 | struct ieee80211_device *ieee = priv->ieee; | ||
6523 | u8 *buf; | ||
6524 | int err = 0; | ||
6525 | |||
6526 | if (wrqu->data.length > MAX_WPA_IE_LEN || | ||
6527 | (wrqu->data.length && extra == NULL)) | ||
6528 | return -EINVAL; | ||
6529 | |||
6530 | if (wrqu->data.length) { | ||
6531 | buf = kmalloc(wrqu->data.length, GFP_KERNEL); | ||
6532 | if (buf == NULL) { | ||
6533 | err = -ENOMEM; | ||
6534 | goto out; | ||
6535 | } | ||
6536 | |||
6537 | memcpy(buf, extra, wrqu->data.length); | ||
6538 | kfree(ieee->wpa_ie); | ||
6539 | ieee->wpa_ie = buf; | ||
6540 | ieee->wpa_ie_len = wrqu->data.length; | ||
6541 | } else { | ||
6542 | kfree(ieee->wpa_ie); | ||
6543 | ieee->wpa_ie = NULL; | ||
6544 | ieee->wpa_ie_len = 0; | ||
6545 | } | ||
6546 | |||
6547 | ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len); | ||
6548 | out: | ||
6549 | return err; | ||
6550 | } | ||
6551 | |||
6552 | /* SIOCGIWGENIE */ | ||
6553 | static int ipw_wx_get_genie(struct net_device *dev, | ||
6554 | struct iw_request_info *info, | ||
6555 | union iwreq_data *wrqu, char *extra) | ||
6556 | { | ||
6557 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
6558 | struct ieee80211_device *ieee = priv->ieee; | ||
6559 | int err = 0; | ||
6560 | |||
6561 | if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) { | ||
6562 | wrqu->data.length = 0; | ||
6563 | goto out; | ||
6564 | } | ||
6565 | |||
6566 | if (wrqu->data.length < ieee->wpa_ie_len) { | ||
6567 | err = -E2BIG; | ||
6568 | goto out; | ||
6569 | } | ||
6570 | |||
6571 | wrqu->data.length = ieee->wpa_ie_len; | ||
6572 | memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len); | ||
6573 | |||
6574 | out: | ||
6575 | return err; | ||
6576 | } | ||
6577 | |||
6578 | static int wext_cipher2level(int cipher) | ||
6579 | { | ||
6580 | switch (cipher) { | ||
6581 | case IW_AUTH_CIPHER_NONE: | ||
6582 | return SEC_LEVEL_0; | ||
6583 | case IW_AUTH_CIPHER_WEP40: | ||
6584 | case IW_AUTH_CIPHER_WEP104: | ||
6585 | return SEC_LEVEL_1; | ||
6586 | case IW_AUTH_CIPHER_TKIP: | ||
6587 | return SEC_LEVEL_2; | ||
6588 | case IW_AUTH_CIPHER_CCMP: | ||
6589 | return SEC_LEVEL_3; | ||
6590 | default: | ||
6591 | return -1; | ||
6592 | } | ||
6593 | } | ||
6594 | |||
6595 | /* SIOCSIWAUTH */ | ||
6596 | static int ipw_wx_set_auth(struct net_device *dev, | ||
6597 | struct iw_request_info *info, | ||
6598 | union iwreq_data *wrqu, char *extra) | ||
6599 | { | ||
6600 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
6601 | struct ieee80211_device *ieee = priv->ieee; | ||
6602 | struct iw_param *param = &wrqu->param; | ||
6603 | struct lib80211_crypt_data *crypt; | ||
6604 | unsigned long flags; | ||
6605 | int ret = 0; | ||
6606 | |||
6607 | switch (param->flags & IW_AUTH_INDEX) { | ||
6608 | case IW_AUTH_WPA_VERSION: | ||
6609 | break; | ||
6610 | case IW_AUTH_CIPHER_PAIRWISE: | ||
6611 | ipw_set_hw_decrypt_unicast(priv, | ||
6612 | wext_cipher2level(param->value)); | ||
6613 | break; | ||
6614 | case IW_AUTH_CIPHER_GROUP: | ||
6615 | ipw_set_hw_decrypt_multicast(priv, | ||
6616 | wext_cipher2level(param->value)); | ||
6617 | break; | ||
6618 | case IW_AUTH_KEY_MGMT: | ||
6619 | /* | ||
6620 | * ipw2200 does not use these parameters | ||
6621 | */ | ||
6622 | break; | ||
6623 | |||
6624 | case IW_AUTH_TKIP_COUNTERMEASURES: | ||
6625 | crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx]; | ||
6626 | if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags) | ||
6627 | break; | ||
6628 | |||
6629 | flags = crypt->ops->get_flags(crypt->priv); | ||
6630 | |||
6631 | if (param->value) | ||
6632 | flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES; | ||
6633 | else | ||
6634 | flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES; | ||
6635 | |||
6636 | crypt->ops->set_flags(flags, crypt->priv); | ||
6637 | |||
6638 | break; | ||
6639 | |||
6640 | case IW_AUTH_DROP_UNENCRYPTED:{ | ||
6641 | /* HACK: | ||
6642 | * | ||
6643 | * wpa_supplicant calls set_wpa_enabled when the driver | ||
6644 | * is loaded and unloaded, regardless of if WPA is being | ||
6645 | * used. No other calls are made which can be used to | ||
6646 | * determine if encryption will be used or not prior to | ||
6647 | * association being expected. If encryption is not being | ||
6648 | * used, drop_unencrypted is set to false, else true -- we | ||
6649 | * can use this to determine if the CAP_PRIVACY_ON bit should | ||
6650 | * be set. | ||
6651 | */ | ||
6652 | struct ieee80211_security sec = { | ||
6653 | .flags = SEC_ENABLED, | ||
6654 | .enabled = param->value, | ||
6655 | }; | ||
6656 | priv->ieee->drop_unencrypted = param->value; | ||
6657 | /* We only change SEC_LEVEL for open mode. Others | ||
6658 | * are set by ipw_wpa_set_encryption. | ||
6659 | */ | ||
6660 | if (!param->value) { | ||
6661 | sec.flags |= SEC_LEVEL; | ||
6662 | sec.level = SEC_LEVEL_0; | ||
6663 | } else { | ||
6664 | sec.flags |= SEC_LEVEL; | ||
6665 | sec.level = SEC_LEVEL_1; | ||
6666 | } | ||
6667 | if (priv->ieee->set_security) | ||
6668 | priv->ieee->set_security(priv->ieee->dev, &sec); | ||
6669 | break; | ||
6670 | } | ||
6671 | |||
6672 | case IW_AUTH_80211_AUTH_ALG: | ||
6673 | ret = ipw_wpa_set_auth_algs(priv, param->value); | ||
6674 | break; | ||
6675 | |||
6676 | case IW_AUTH_WPA_ENABLED: | ||
6677 | ret = ipw_wpa_enable(priv, param->value); | ||
6678 | ipw_disassociate(priv); | ||
6679 | break; | ||
6680 | |||
6681 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: | ||
6682 | ieee->ieee802_1x = param->value; | ||
6683 | break; | ||
6684 | |||
6685 | case IW_AUTH_PRIVACY_INVOKED: | ||
6686 | ieee->privacy_invoked = param->value; | ||
6687 | break; | ||
6688 | |||
6689 | default: | ||
6690 | return -EOPNOTSUPP; | ||
6691 | } | ||
6692 | return ret; | ||
6693 | } | ||
6694 | |||
6695 | /* SIOCGIWAUTH */ | ||
6696 | static int ipw_wx_get_auth(struct net_device *dev, | ||
6697 | struct iw_request_info *info, | ||
6698 | union iwreq_data *wrqu, char *extra) | ||
6699 | { | ||
6700 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
6701 | struct ieee80211_device *ieee = priv->ieee; | ||
6702 | struct lib80211_crypt_data *crypt; | ||
6703 | struct iw_param *param = &wrqu->param; | ||
6704 | int ret = 0; | ||
6705 | |||
6706 | switch (param->flags & IW_AUTH_INDEX) { | ||
6707 | case IW_AUTH_WPA_VERSION: | ||
6708 | case IW_AUTH_CIPHER_PAIRWISE: | ||
6709 | case IW_AUTH_CIPHER_GROUP: | ||
6710 | case IW_AUTH_KEY_MGMT: | ||
6711 | /* | ||
6712 | * wpa_supplicant will control these internally | ||
6713 | */ | ||
6714 | ret = -EOPNOTSUPP; | ||
6715 | break; | ||
6716 | |||
6717 | case IW_AUTH_TKIP_COUNTERMEASURES: | ||
6718 | crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx]; | ||
6719 | if (!crypt || !crypt->ops->get_flags) | ||
6720 | break; | ||
6721 | |||
6722 | param->value = (crypt->ops->get_flags(crypt->priv) & | ||
6723 | IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0; | ||
6724 | |||
6725 | break; | ||
6726 | |||
6727 | case IW_AUTH_DROP_UNENCRYPTED: | ||
6728 | param->value = ieee->drop_unencrypted; | ||
6729 | break; | ||
6730 | |||
6731 | case IW_AUTH_80211_AUTH_ALG: | ||
6732 | param->value = ieee->sec.auth_mode; | ||
6733 | break; | ||
6734 | |||
6735 | case IW_AUTH_WPA_ENABLED: | ||
6736 | param->value = ieee->wpa_enabled; | ||
6737 | break; | ||
6738 | |||
6739 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: | ||
6740 | param->value = ieee->ieee802_1x; | ||
6741 | break; | ||
6742 | |||
6743 | case IW_AUTH_ROAMING_CONTROL: | ||
6744 | case IW_AUTH_PRIVACY_INVOKED: | ||
6745 | param->value = ieee->privacy_invoked; | ||
6746 | break; | ||
6747 | |||
6748 | default: | ||
6749 | return -EOPNOTSUPP; | ||
6750 | } | ||
6751 | return 0; | ||
6752 | } | ||
6753 | |||
6754 | /* SIOCSIWENCODEEXT */ | ||
6755 | static int ipw_wx_set_encodeext(struct net_device *dev, | ||
6756 | struct iw_request_info *info, | ||
6757 | union iwreq_data *wrqu, char *extra) | ||
6758 | { | ||
6759 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
6760 | struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; | ||
6761 | |||
6762 | if (hwcrypto) { | ||
6763 | if (ext->alg == IW_ENCODE_ALG_TKIP) { | ||
6764 | /* IPW HW can't build TKIP MIC, | ||
6765 | host decryption still needed */ | ||
6766 | if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) | ||
6767 | priv->ieee->host_mc_decrypt = 1; | ||
6768 | else { | ||
6769 | priv->ieee->host_encrypt = 0; | ||
6770 | priv->ieee->host_encrypt_msdu = 1; | ||
6771 | priv->ieee->host_decrypt = 1; | ||
6772 | } | ||
6773 | } else { | ||
6774 | priv->ieee->host_encrypt = 0; | ||
6775 | priv->ieee->host_encrypt_msdu = 0; | ||
6776 | priv->ieee->host_decrypt = 0; | ||
6777 | priv->ieee->host_mc_decrypt = 0; | ||
6778 | } | ||
6779 | } | ||
6780 | |||
6781 | return ieee80211_wx_set_encodeext(priv->ieee, info, wrqu, extra); | ||
6782 | } | ||
6783 | |||
6784 | /* SIOCGIWENCODEEXT */ | ||
6785 | static int ipw_wx_get_encodeext(struct net_device *dev, | ||
6786 | struct iw_request_info *info, | ||
6787 | union iwreq_data *wrqu, char *extra) | ||
6788 | { | ||
6789 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
6790 | return ieee80211_wx_get_encodeext(priv->ieee, info, wrqu, extra); | ||
6791 | } | ||
6792 | |||
6793 | /* SIOCSIWMLME */ | ||
6794 | static int ipw_wx_set_mlme(struct net_device *dev, | ||
6795 | struct iw_request_info *info, | ||
6796 | union iwreq_data *wrqu, char *extra) | ||
6797 | { | ||
6798 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
6799 | struct iw_mlme *mlme = (struct iw_mlme *)extra; | ||
6800 | __le16 reason; | ||
6801 | |||
6802 | reason = cpu_to_le16(mlme->reason_code); | ||
6803 | |||
6804 | switch (mlme->cmd) { | ||
6805 | case IW_MLME_DEAUTH: | ||
6806 | /* silently ignore */ | ||
6807 | break; | ||
6808 | |||
6809 | case IW_MLME_DISASSOC: | ||
6810 | ipw_disassociate(priv); | ||
6811 | break; | ||
6812 | |||
6813 | default: | ||
6814 | return -EOPNOTSUPP; | ||
6815 | } | ||
6816 | return 0; | ||
6817 | } | ||
6818 | |||
6819 | #ifdef CONFIG_IPW2200_QOS | ||
6820 | |||
6821 | /* QoS */ | ||
6822 | /* | ||
6823 | * get the modulation type of the current network or | ||
6824 | * the card current mode | ||
6825 | */ | ||
6826 | static u8 ipw_qos_current_mode(struct ipw_priv * priv) | ||
6827 | { | ||
6828 | u8 mode = 0; | ||
6829 | |||
6830 | if (priv->status & STATUS_ASSOCIATED) { | ||
6831 | unsigned long flags; | ||
6832 | |||
6833 | spin_lock_irqsave(&priv->ieee->lock, flags); | ||
6834 | mode = priv->assoc_network->mode; | ||
6835 | spin_unlock_irqrestore(&priv->ieee->lock, flags); | ||
6836 | } else { | ||
6837 | mode = priv->ieee->mode; | ||
6838 | } | ||
6839 | IPW_DEBUG_QOS("QoS network/card mode %d \n", mode); | ||
6840 | return mode; | ||
6841 | } | ||
6842 | |||
6843 | /* | ||
6844 | * Handle management frame beacon and probe response | ||
6845 | */ | ||
6846 | static int ipw_qos_handle_probe_response(struct ipw_priv *priv, | ||
6847 | int active_network, | ||
6848 | struct ieee80211_network *network) | ||
6849 | { | ||
6850 | u32 size = sizeof(struct ieee80211_qos_parameters); | ||
6851 | |||
6852 | if (network->capability & WLAN_CAPABILITY_IBSS) | ||
6853 | network->qos_data.active = network->qos_data.supported; | ||
6854 | |||
6855 | if (network->flags & NETWORK_HAS_QOS_MASK) { | ||
6856 | if (active_network && | ||
6857 | (network->flags & NETWORK_HAS_QOS_PARAMETERS)) | ||
6858 | network->qos_data.active = network->qos_data.supported; | ||
6859 | |||
6860 | if ((network->qos_data.active == 1) && (active_network == 1) && | ||
6861 | (network->flags & NETWORK_HAS_QOS_PARAMETERS) && | ||
6862 | (network->qos_data.old_param_count != | ||
6863 | network->qos_data.param_count)) { | ||
6864 | network->qos_data.old_param_count = | ||
6865 | network->qos_data.param_count; | ||
6866 | schedule_work(&priv->qos_activate); | ||
6867 | IPW_DEBUG_QOS("QoS parameters change call " | ||
6868 | "qos_activate\n"); | ||
6869 | } | ||
6870 | } else { | ||
6871 | if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B)) | ||
6872 | memcpy(&network->qos_data.parameters, | ||
6873 | &def_parameters_CCK, size); | ||
6874 | else | ||
6875 | memcpy(&network->qos_data.parameters, | ||
6876 | &def_parameters_OFDM, size); | ||
6877 | |||
6878 | if ((network->qos_data.active == 1) && (active_network == 1)) { | ||
6879 | IPW_DEBUG_QOS("QoS was disabled call qos_activate \n"); | ||
6880 | schedule_work(&priv->qos_activate); | ||
6881 | } | ||
6882 | |||
6883 | network->qos_data.active = 0; | ||
6884 | network->qos_data.supported = 0; | ||
6885 | } | ||
6886 | if ((priv->status & STATUS_ASSOCIATED) && | ||
6887 | (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) { | ||
6888 | if (memcmp(network->bssid, priv->bssid, ETH_ALEN)) | ||
6889 | if (network->capability & WLAN_CAPABILITY_IBSS) | ||
6890 | if ((network->ssid_len == | ||
6891 | priv->assoc_network->ssid_len) && | ||
6892 | !memcmp(network->ssid, | ||
6893 | priv->assoc_network->ssid, | ||
6894 | network->ssid_len)) { | ||
6895 | queue_work(priv->workqueue, | ||
6896 | &priv->merge_networks); | ||
6897 | } | ||
6898 | } | ||
6899 | |||
6900 | return 0; | ||
6901 | } | ||
6902 | |||
6903 | /* | ||
6904 | * This function set up the firmware to support QoS. It sends | ||
6905 | * IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO | ||
6906 | */ | ||
6907 | static int ipw_qos_activate(struct ipw_priv *priv, | ||
6908 | struct ieee80211_qos_data *qos_network_data) | ||
6909 | { | ||
6910 | int err; | ||
6911 | struct ieee80211_qos_parameters qos_parameters[QOS_QOS_SETS]; | ||
6912 | struct ieee80211_qos_parameters *active_one = NULL; | ||
6913 | u32 size = sizeof(struct ieee80211_qos_parameters); | ||
6914 | u32 burst_duration; | ||
6915 | int i; | ||
6916 | u8 type; | ||
6917 | |||
6918 | type = ipw_qos_current_mode(priv); | ||
6919 | |||
6920 | active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]); | ||
6921 | memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size); | ||
6922 | active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]); | ||
6923 | memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size); | ||
6924 | |||
6925 | if (qos_network_data == NULL) { | ||
6926 | if (type == IEEE_B) { | ||
6927 | IPW_DEBUG_QOS("QoS activate network mode %d\n", type); | ||
6928 | active_one = &def_parameters_CCK; | ||
6929 | } else | ||
6930 | active_one = &def_parameters_OFDM; | ||
6931 | |||
6932 | memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); | ||
6933 | burst_duration = ipw_qos_get_burst_duration(priv); | ||
6934 | for (i = 0; i < QOS_QUEUE_NUM; i++) | ||
6935 | qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] = | ||
6936 | cpu_to_le16(burst_duration); | ||
6937 | } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) { | ||
6938 | if (type == IEEE_B) { | ||
6939 | IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n", | ||
6940 | type); | ||
6941 | if (priv->qos_data.qos_enable == 0) | ||
6942 | active_one = &def_parameters_CCK; | ||
6943 | else | ||
6944 | active_one = priv->qos_data.def_qos_parm_CCK; | ||
6945 | } else { | ||
6946 | if (priv->qos_data.qos_enable == 0) | ||
6947 | active_one = &def_parameters_OFDM; | ||
6948 | else | ||
6949 | active_one = priv->qos_data.def_qos_parm_OFDM; | ||
6950 | } | ||
6951 | memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); | ||
6952 | } else { | ||
6953 | unsigned long flags; | ||
6954 | int active; | ||
6955 | |||
6956 | spin_lock_irqsave(&priv->ieee->lock, flags); | ||
6957 | active_one = &(qos_network_data->parameters); | ||
6958 | qos_network_data->old_param_count = | ||
6959 | qos_network_data->param_count; | ||
6960 | memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); | ||
6961 | active = qos_network_data->supported; | ||
6962 | spin_unlock_irqrestore(&priv->ieee->lock, flags); | ||
6963 | |||
6964 | if (active == 0) { | ||
6965 | burst_duration = ipw_qos_get_burst_duration(priv); | ||
6966 | for (i = 0; i < QOS_QUEUE_NUM; i++) | ||
6967 | qos_parameters[QOS_PARAM_SET_ACTIVE]. | ||
6968 | tx_op_limit[i] = cpu_to_le16(burst_duration); | ||
6969 | } | ||
6970 | } | ||
6971 | |||
6972 | IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n"); | ||
6973 | err = ipw_send_qos_params_command(priv, | ||
6974 | (struct ieee80211_qos_parameters *) | ||
6975 | &(qos_parameters[0])); | ||
6976 | if (err) | ||
6977 | IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n"); | ||
6978 | |||
6979 | return err; | ||
6980 | } | ||
6981 | |||
6982 | /* | ||
6983 | * send IPW_CMD_WME_INFO to the firmware | ||
6984 | */ | ||
6985 | static int ipw_qos_set_info_element(struct ipw_priv *priv) | ||
6986 | { | ||
6987 | int ret = 0; | ||
6988 | struct ieee80211_qos_information_element qos_info; | ||
6989 | |||
6990 | if (priv == NULL) | ||
6991 | return -1; | ||
6992 | |||
6993 | qos_info.elementID = QOS_ELEMENT_ID; | ||
6994 | qos_info.length = sizeof(struct ieee80211_qos_information_element) - 2; | ||
6995 | |||
6996 | qos_info.version = QOS_VERSION_1; | ||
6997 | qos_info.ac_info = 0; | ||
6998 | |||
6999 | memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN); | ||
7000 | qos_info.qui_type = QOS_OUI_TYPE; | ||
7001 | qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE; | ||
7002 | |||
7003 | ret = ipw_send_qos_info_command(priv, &qos_info); | ||
7004 | if (ret != 0) { | ||
7005 | IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n"); | ||
7006 | } | ||
7007 | return ret; | ||
7008 | } | ||
7009 | |||
7010 | /* | ||
7011 | * Set the QoS parameter with the association request structure | ||
7012 | */ | ||
7013 | static int ipw_qos_association(struct ipw_priv *priv, | ||
7014 | struct ieee80211_network *network) | ||
7015 | { | ||
7016 | int err = 0; | ||
7017 | struct ieee80211_qos_data *qos_data = NULL; | ||
7018 | struct ieee80211_qos_data ibss_data = { | ||
7019 | .supported = 1, | ||
7020 | .active = 1, | ||
7021 | }; | ||
7022 | |||
7023 | switch (priv->ieee->iw_mode) { | ||
7024 | case IW_MODE_ADHOC: | ||
7025 | BUG_ON(!(network->capability & WLAN_CAPABILITY_IBSS)); | ||
7026 | |||
7027 | qos_data = &ibss_data; | ||
7028 | break; | ||
7029 | |||
7030 | case IW_MODE_INFRA: | ||
7031 | qos_data = &network->qos_data; | ||
7032 | break; | ||
7033 | |||
7034 | default: | ||
7035 | BUG(); | ||
7036 | break; | ||
7037 | } | ||
7038 | |||
7039 | err = ipw_qos_activate(priv, qos_data); | ||
7040 | if (err) { | ||
7041 | priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC; | ||
7042 | return err; | ||
7043 | } | ||
7044 | |||
7045 | if (priv->qos_data.qos_enable && qos_data->supported) { | ||
7046 | IPW_DEBUG_QOS("QoS will be enabled for this association\n"); | ||
7047 | priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC; | ||
7048 | return ipw_qos_set_info_element(priv); | ||
7049 | } | ||
7050 | |||
7051 | return 0; | ||
7052 | } | ||
7053 | |||
7054 | /* | ||
7055 | * handling the beaconing responses. if we get different QoS setting | ||
7056 | * off the network from the associated setting, adjust the QoS | ||
7057 | * setting | ||
7058 | */ | ||
7059 | static int ipw_qos_association_resp(struct ipw_priv *priv, | ||
7060 | struct ieee80211_network *network) | ||
7061 | { | ||
7062 | int ret = 0; | ||
7063 | unsigned long flags; | ||
7064 | u32 size = sizeof(struct ieee80211_qos_parameters); | ||
7065 | int set_qos_param = 0; | ||
7066 | |||
7067 | if ((priv == NULL) || (network == NULL) || | ||
7068 | (priv->assoc_network == NULL)) | ||
7069 | return ret; | ||
7070 | |||
7071 | if (!(priv->status & STATUS_ASSOCIATED)) | ||
7072 | return ret; | ||
7073 | |||
7074 | if ((priv->ieee->iw_mode != IW_MODE_INFRA)) | ||
7075 | return ret; | ||
7076 | |||
7077 | spin_lock_irqsave(&priv->ieee->lock, flags); | ||
7078 | if (network->flags & NETWORK_HAS_QOS_PARAMETERS) { | ||
7079 | memcpy(&priv->assoc_network->qos_data, &network->qos_data, | ||
7080 | sizeof(struct ieee80211_qos_data)); | ||
7081 | priv->assoc_network->qos_data.active = 1; | ||
7082 | if ((network->qos_data.old_param_count != | ||
7083 | network->qos_data.param_count)) { | ||
7084 | set_qos_param = 1; | ||
7085 | network->qos_data.old_param_count = | ||
7086 | network->qos_data.param_count; | ||
7087 | } | ||
7088 | |||
7089 | } else { | ||
7090 | if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B)) | ||
7091 | memcpy(&priv->assoc_network->qos_data.parameters, | ||
7092 | &def_parameters_CCK, size); | ||
7093 | else | ||
7094 | memcpy(&priv->assoc_network->qos_data.parameters, | ||
7095 | &def_parameters_OFDM, size); | ||
7096 | priv->assoc_network->qos_data.active = 0; | ||
7097 | priv->assoc_network->qos_data.supported = 0; | ||
7098 | set_qos_param = 1; | ||
7099 | } | ||
7100 | |||
7101 | spin_unlock_irqrestore(&priv->ieee->lock, flags); | ||
7102 | |||
7103 | if (set_qos_param == 1) | ||
7104 | schedule_work(&priv->qos_activate); | ||
7105 | |||
7106 | return ret; | ||
7107 | } | ||
7108 | |||
7109 | static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv) | ||
7110 | { | ||
7111 | u32 ret = 0; | ||
7112 | |||
7113 | if ((priv == NULL)) | ||
7114 | return 0; | ||
7115 | |||
7116 | if (!(priv->ieee->modulation & IEEE80211_OFDM_MODULATION)) | ||
7117 | ret = priv->qos_data.burst_duration_CCK; | ||
7118 | else | ||
7119 | ret = priv->qos_data.burst_duration_OFDM; | ||
7120 | |||
7121 | return ret; | ||
7122 | } | ||
7123 | |||
7124 | /* | ||
7125 | * Initialize the setting of QoS global | ||
7126 | */ | ||
7127 | static void ipw_qos_init(struct ipw_priv *priv, int enable, | ||
7128 | int burst_enable, u32 burst_duration_CCK, | ||
7129 | u32 burst_duration_OFDM) | ||
7130 | { | ||
7131 | priv->qos_data.qos_enable = enable; | ||
7132 | |||
7133 | if (priv->qos_data.qos_enable) { | ||
7134 | priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK; | ||
7135 | priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM; | ||
7136 | IPW_DEBUG_QOS("QoS is enabled\n"); | ||
7137 | } else { | ||
7138 | priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK; | ||
7139 | priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM; | ||
7140 | IPW_DEBUG_QOS("QoS is not enabled\n"); | ||
7141 | } | ||
7142 | |||
7143 | priv->qos_data.burst_enable = burst_enable; | ||
7144 | |||
7145 | if (burst_enable) { | ||
7146 | priv->qos_data.burst_duration_CCK = burst_duration_CCK; | ||
7147 | priv->qos_data.burst_duration_OFDM = burst_duration_OFDM; | ||
7148 | } else { | ||
7149 | priv->qos_data.burst_duration_CCK = 0; | ||
7150 | priv->qos_data.burst_duration_OFDM = 0; | ||
7151 | } | ||
7152 | } | ||
7153 | |||
7154 | /* | ||
7155 | * map the packet priority to the right TX Queue | ||
7156 | */ | ||
7157 | static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority) | ||
7158 | { | ||
7159 | if (priority > 7 || !priv->qos_data.qos_enable) | ||
7160 | priority = 0; | ||
7161 | |||
7162 | return from_priority_to_tx_queue[priority] - 1; | ||
7163 | } | ||
7164 | |||
7165 | static int ipw_is_qos_active(struct net_device *dev, | ||
7166 | struct sk_buff *skb) | ||
7167 | { | ||
7168 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
7169 | struct ieee80211_qos_data *qos_data = NULL; | ||
7170 | int active, supported; | ||
7171 | u8 *daddr = skb->data + ETH_ALEN; | ||
7172 | int unicast = !is_multicast_ether_addr(daddr); | ||
7173 | |||
7174 | if (!(priv->status & STATUS_ASSOCIATED)) | ||
7175 | return 0; | ||
7176 | |||
7177 | qos_data = &priv->assoc_network->qos_data; | ||
7178 | |||
7179 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { | ||
7180 | if (unicast == 0) | ||
7181 | qos_data->active = 0; | ||
7182 | else | ||
7183 | qos_data->active = qos_data->supported; | ||
7184 | } | ||
7185 | active = qos_data->active; | ||
7186 | supported = qos_data->supported; | ||
7187 | IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d " | ||
7188 | "unicast %d\n", | ||
7189 | priv->qos_data.qos_enable, active, supported, unicast); | ||
7190 | if (active && priv->qos_data.qos_enable) | ||
7191 | return 1; | ||
7192 | |||
7193 | return 0; | ||
7194 | |||
7195 | } | ||
7196 | /* | ||
7197 | * add QoS parameter to the TX command | ||
7198 | */ | ||
7199 | static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv, | ||
7200 | u16 priority, | ||
7201 | struct tfd_data *tfd) | ||
7202 | { | ||
7203 | int tx_queue_id = 0; | ||
7204 | |||
7205 | |||
7206 | tx_queue_id = from_priority_to_tx_queue[priority] - 1; | ||
7207 | tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED; | ||
7208 | |||
7209 | if (priv->qos_data.qos_no_ack_mask & (1UL << tx_queue_id)) { | ||
7210 | tfd->tx_flags &= ~DCT_FLAG_ACK_REQD; | ||
7211 | tfd->tfd.tfd_26.mchdr.qos_ctrl |= cpu_to_le16(CTRL_QOS_NO_ACK); | ||
7212 | } | ||
7213 | return 0; | ||
7214 | } | ||
7215 | |||
7216 | /* | ||
7217 | * background support to run QoS activate functionality | ||
7218 | */ | ||
7219 | static void ipw_bg_qos_activate(struct work_struct *work) | ||
7220 | { | ||
7221 | struct ipw_priv *priv = | ||
7222 | container_of(work, struct ipw_priv, qos_activate); | ||
7223 | |||
7224 | if (priv == NULL) | ||
7225 | return; | ||
7226 | |||
7227 | mutex_lock(&priv->mutex); | ||
7228 | |||
7229 | if (priv->status & STATUS_ASSOCIATED) | ||
7230 | ipw_qos_activate(priv, &(priv->assoc_network->qos_data)); | ||
7231 | |||
7232 | mutex_unlock(&priv->mutex); | ||
7233 | } | ||
7234 | |||
7235 | static int ipw_handle_probe_response(struct net_device *dev, | ||
7236 | struct ieee80211_probe_response *resp, | ||
7237 | struct ieee80211_network *network) | ||
7238 | { | ||
7239 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
7240 | int active_network = ((priv->status & STATUS_ASSOCIATED) && | ||
7241 | (network == priv->assoc_network)); | ||
7242 | |||
7243 | ipw_qos_handle_probe_response(priv, active_network, network); | ||
7244 | |||
7245 | return 0; | ||
7246 | } | ||
7247 | |||
7248 | static int ipw_handle_beacon(struct net_device *dev, | ||
7249 | struct ieee80211_beacon *resp, | ||
7250 | struct ieee80211_network *network) | ||
7251 | { | ||
7252 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
7253 | int active_network = ((priv->status & STATUS_ASSOCIATED) && | ||
7254 | (network == priv->assoc_network)); | ||
7255 | |||
7256 | ipw_qos_handle_probe_response(priv, active_network, network); | ||
7257 | |||
7258 | return 0; | ||
7259 | } | ||
7260 | |||
7261 | static int ipw_handle_assoc_response(struct net_device *dev, | ||
7262 | struct ieee80211_assoc_response *resp, | ||
7263 | struct ieee80211_network *network) | ||
7264 | { | ||
7265 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
7266 | ipw_qos_association_resp(priv, network); | ||
7267 | return 0; | ||
7268 | } | ||
7269 | |||
7270 | static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters | ||
7271 | *qos_param) | ||
7272 | { | ||
7273 | return ipw_send_cmd_pdu(priv, IPW_CMD_QOS_PARAMETERS, | ||
7274 | sizeof(*qos_param) * 3, qos_param); | ||
7275 | } | ||
7276 | |||
7277 | static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element | ||
7278 | *qos_param) | ||
7279 | { | ||
7280 | return ipw_send_cmd_pdu(priv, IPW_CMD_WME_INFO, sizeof(*qos_param), | ||
7281 | qos_param); | ||
7282 | } | ||
7283 | |||
7284 | #endif /* CONFIG_IPW2200_QOS */ | ||
7285 | |||
7286 | static int ipw_associate_network(struct ipw_priv *priv, | ||
7287 | struct ieee80211_network *network, | ||
7288 | struct ipw_supported_rates *rates, int roaming) | ||
7289 | { | ||
7290 | int err; | ||
7291 | DECLARE_SSID_BUF(ssid); | ||
7292 | |||
7293 | if (priv->config & CFG_FIXED_RATE) | ||
7294 | ipw_set_fixed_rate(priv, network->mode); | ||
7295 | |||
7296 | if (!(priv->config & CFG_STATIC_ESSID)) { | ||
7297 | priv->essid_len = min(network->ssid_len, | ||
7298 | (u8) IW_ESSID_MAX_SIZE); | ||
7299 | memcpy(priv->essid, network->ssid, priv->essid_len); | ||
7300 | } | ||
7301 | |||
7302 | network->last_associate = jiffies; | ||
7303 | |||
7304 | memset(&priv->assoc_request, 0, sizeof(priv->assoc_request)); | ||
7305 | priv->assoc_request.channel = network->channel; | ||
7306 | priv->assoc_request.auth_key = 0; | ||
7307 | |||
7308 | if ((priv->capability & CAP_PRIVACY_ON) && | ||
7309 | (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) { | ||
7310 | priv->assoc_request.auth_type = AUTH_SHARED_KEY; | ||
7311 | priv->assoc_request.auth_key = priv->ieee->sec.active_key; | ||
7312 | |||
7313 | if (priv->ieee->sec.level == SEC_LEVEL_1) | ||
7314 | ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP); | ||
7315 | |||
7316 | } else if ((priv->capability & CAP_PRIVACY_ON) && | ||
7317 | (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP)) | ||
7318 | priv->assoc_request.auth_type = AUTH_LEAP; | ||
7319 | else | ||
7320 | priv->assoc_request.auth_type = AUTH_OPEN; | ||
7321 | |||
7322 | if (priv->ieee->wpa_ie_len) { | ||
7323 | priv->assoc_request.policy_support = cpu_to_le16(0x02); /* RSN active */ | ||
7324 | ipw_set_rsn_capa(priv, priv->ieee->wpa_ie, | ||
7325 | priv->ieee->wpa_ie_len); | ||
7326 | } | ||
7327 | |||
7328 | /* | ||
7329 | * It is valid for our ieee device to support multiple modes, but | ||
7330 | * when it comes to associating to a given network we have to choose | ||
7331 | * just one mode. | ||
7332 | */ | ||
7333 | if (network->mode & priv->ieee->mode & IEEE_A) | ||
7334 | priv->assoc_request.ieee_mode = IPW_A_MODE; | ||
7335 | else if (network->mode & priv->ieee->mode & IEEE_G) | ||
7336 | priv->assoc_request.ieee_mode = IPW_G_MODE; | ||
7337 | else if (network->mode & priv->ieee->mode & IEEE_B) | ||
7338 | priv->assoc_request.ieee_mode = IPW_B_MODE; | ||
7339 | |||
7340 | priv->assoc_request.capability = cpu_to_le16(network->capability); | ||
7341 | if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) | ||
7342 | && !(priv->config & CFG_PREAMBLE_LONG)) { | ||
7343 | priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE; | ||
7344 | } else { | ||
7345 | priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE; | ||
7346 | |||
7347 | /* Clear the short preamble if we won't be supporting it */ | ||
7348 | priv->assoc_request.capability &= | ||
7349 | ~cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE); | ||
7350 | } | ||
7351 | |||
7352 | /* Clear capability bits that aren't used in Ad Hoc */ | ||
7353 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) | ||
7354 | priv->assoc_request.capability &= | ||
7355 | ~cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME); | ||
7356 | |||
7357 | IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, " | ||
7358 | "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n", | ||
7359 | roaming ? "Rea" : "A", | ||
7360 | print_ssid(ssid, priv->essid, priv->essid_len), | ||
7361 | network->channel, | ||
7362 | ipw_modes[priv->assoc_request.ieee_mode], | ||
7363 | rates->num_rates, | ||
7364 | (priv->assoc_request.preamble_length == | ||
7365 | DCT_FLAG_LONG_PREAMBLE) ? "long" : "short", | ||
7366 | network->capability & | ||
7367 | WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long", | ||
7368 | priv->capability & CAP_PRIVACY_ON ? "on " : "off", | ||
7369 | priv->capability & CAP_PRIVACY_ON ? | ||
7370 | (priv->capability & CAP_SHARED_KEY ? "(shared)" : | ||
7371 | "(open)") : "", | ||
7372 | priv->capability & CAP_PRIVACY_ON ? " key=" : "", | ||
7373 | priv->capability & CAP_PRIVACY_ON ? | ||
7374 | '1' + priv->ieee->sec.active_key : '.', | ||
7375 | priv->capability & CAP_PRIVACY_ON ? '.' : ' '); | ||
7376 | |||
7377 | priv->assoc_request.beacon_interval = cpu_to_le16(network->beacon_interval); | ||
7378 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC) && | ||
7379 | (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) { | ||
7380 | priv->assoc_request.assoc_type = HC_IBSS_START; | ||
7381 | priv->assoc_request.assoc_tsf_msw = 0; | ||
7382 | priv->assoc_request.assoc_tsf_lsw = 0; | ||
7383 | } else { | ||
7384 | if (unlikely(roaming)) | ||
7385 | priv->assoc_request.assoc_type = HC_REASSOCIATE; | ||
7386 | else | ||
7387 | priv->assoc_request.assoc_type = HC_ASSOCIATE; | ||
7388 | priv->assoc_request.assoc_tsf_msw = cpu_to_le32(network->time_stamp[1]); | ||
7389 | priv->assoc_request.assoc_tsf_lsw = cpu_to_le32(network->time_stamp[0]); | ||
7390 | } | ||
7391 | |||
7392 | memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN); | ||
7393 | |||
7394 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { | ||
7395 | memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN); | ||
7396 | priv->assoc_request.atim_window = cpu_to_le16(network->atim_window); | ||
7397 | } else { | ||
7398 | memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN); | ||
7399 | priv->assoc_request.atim_window = 0; | ||
7400 | } | ||
7401 | |||
7402 | priv->assoc_request.listen_interval = cpu_to_le16(network->listen_interval); | ||
7403 | |||
7404 | err = ipw_send_ssid(priv, priv->essid, priv->essid_len); | ||
7405 | if (err) { | ||
7406 | IPW_DEBUG_HC("Attempt to send SSID command failed.\n"); | ||
7407 | return err; | ||
7408 | } | ||
7409 | |||
7410 | rates->ieee_mode = priv->assoc_request.ieee_mode; | ||
7411 | rates->purpose = IPW_RATE_CONNECT; | ||
7412 | ipw_send_supported_rates(priv, rates); | ||
7413 | |||
7414 | if (priv->assoc_request.ieee_mode == IPW_G_MODE) | ||
7415 | priv->sys_config.dot11g_auto_detection = 1; | ||
7416 | else | ||
7417 | priv->sys_config.dot11g_auto_detection = 0; | ||
7418 | |||
7419 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) | ||
7420 | priv->sys_config.answer_broadcast_ssid_probe = 1; | ||
7421 | else | ||
7422 | priv->sys_config.answer_broadcast_ssid_probe = 0; | ||
7423 | |||
7424 | err = ipw_send_system_config(priv); | ||
7425 | if (err) { | ||
7426 | IPW_DEBUG_HC("Attempt to send sys config command failed.\n"); | ||
7427 | return err; | ||
7428 | } | ||
7429 | |||
7430 | IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi); | ||
7431 | err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM); | ||
7432 | if (err) { | ||
7433 | IPW_DEBUG_HC("Attempt to send associate command failed.\n"); | ||
7434 | return err; | ||
7435 | } | ||
7436 | |||
7437 | /* | ||
7438 | * If preemption is enabled, it is possible for the association | ||
7439 | * to complete before we return from ipw_send_associate. Therefore | ||
7440 | * we have to be sure and update our priviate data first. | ||
7441 | */ | ||
7442 | priv->channel = network->channel; | ||
7443 | memcpy(priv->bssid, network->bssid, ETH_ALEN); | ||
7444 | priv->status |= STATUS_ASSOCIATING; | ||
7445 | priv->status &= ~STATUS_SECURITY_UPDATED; | ||
7446 | |||
7447 | priv->assoc_network = network; | ||
7448 | |||
7449 | #ifdef CONFIG_IPW2200_QOS | ||
7450 | ipw_qos_association(priv, network); | ||
7451 | #endif | ||
7452 | |||
7453 | err = ipw_send_associate(priv, &priv->assoc_request); | ||
7454 | if (err) { | ||
7455 | IPW_DEBUG_HC("Attempt to send associate command failed.\n"); | ||
7456 | return err; | ||
7457 | } | ||
7458 | |||
7459 | IPW_DEBUG(IPW_DL_STATE, "associating: '%s' %pM \n", | ||
7460 | print_ssid(ssid, priv->essid, priv->essid_len), | ||
7461 | priv->bssid); | ||
7462 | |||
7463 | return 0; | ||
7464 | } | ||
7465 | |||
7466 | static void ipw_roam(void *data) | ||
7467 | { | ||
7468 | struct ipw_priv *priv = data; | ||
7469 | struct ieee80211_network *network = NULL; | ||
7470 | struct ipw_network_match match = { | ||
7471 | .network = priv->assoc_network | ||
7472 | }; | ||
7473 | |||
7474 | /* The roaming process is as follows: | ||
7475 | * | ||
7476 | * 1. Missed beacon threshold triggers the roaming process by | ||
7477 | * setting the status ROAM bit and requesting a scan. | ||
7478 | * 2. When the scan completes, it schedules the ROAM work | ||
7479 | * 3. The ROAM work looks at all of the known networks for one that | ||
7480 | * is a better network than the currently associated. If none | ||
7481 | * found, the ROAM process is over (ROAM bit cleared) | ||
7482 | * 4. If a better network is found, a disassociation request is | ||
7483 | * sent. | ||
7484 | * 5. When the disassociation completes, the roam work is again | ||
7485 | * scheduled. The second time through, the driver is no longer | ||
7486 | * associated, and the newly selected network is sent an | ||
7487 | * association request. | ||
7488 | * 6. At this point ,the roaming process is complete and the ROAM | ||
7489 | * status bit is cleared. | ||
7490 | */ | ||
7491 | |||
7492 | /* If we are no longer associated, and the roaming bit is no longer | ||
7493 | * set, then we are not actively roaming, so just return */ | ||
7494 | if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING))) | ||
7495 | return; | ||
7496 | |||
7497 | if (priv->status & STATUS_ASSOCIATED) { | ||
7498 | /* First pass through ROAM process -- look for a better | ||
7499 | * network */ | ||
7500 | unsigned long flags; | ||
7501 | u8 rssi = priv->assoc_network->stats.rssi; | ||
7502 | priv->assoc_network->stats.rssi = -128; | ||
7503 | spin_lock_irqsave(&priv->ieee->lock, flags); | ||
7504 | list_for_each_entry(network, &priv->ieee->network_list, list) { | ||
7505 | if (network != priv->assoc_network) | ||
7506 | ipw_best_network(priv, &match, network, 1); | ||
7507 | } | ||
7508 | spin_unlock_irqrestore(&priv->ieee->lock, flags); | ||
7509 | priv->assoc_network->stats.rssi = rssi; | ||
7510 | |||
7511 | if (match.network == priv->assoc_network) { | ||
7512 | IPW_DEBUG_ASSOC("No better APs in this network to " | ||
7513 | "roam to.\n"); | ||
7514 | priv->status &= ~STATUS_ROAMING; | ||
7515 | ipw_debug_config(priv); | ||
7516 | return; | ||
7517 | } | ||
7518 | |||
7519 | ipw_send_disassociate(priv, 1); | ||
7520 | priv->assoc_network = match.network; | ||
7521 | |||
7522 | return; | ||
7523 | } | ||
7524 | |||
7525 | /* Second pass through ROAM process -- request association */ | ||
7526 | ipw_compatible_rates(priv, priv->assoc_network, &match.rates); | ||
7527 | ipw_associate_network(priv, priv->assoc_network, &match.rates, 1); | ||
7528 | priv->status &= ~STATUS_ROAMING; | ||
7529 | } | ||
7530 | |||
7531 | static void ipw_bg_roam(struct work_struct *work) | ||
7532 | { | ||
7533 | struct ipw_priv *priv = | ||
7534 | container_of(work, struct ipw_priv, roam); | ||
7535 | mutex_lock(&priv->mutex); | ||
7536 | ipw_roam(priv); | ||
7537 | mutex_unlock(&priv->mutex); | ||
7538 | } | ||
7539 | |||
7540 | static int ipw_associate(void *data) | ||
7541 | { | ||
7542 | struct ipw_priv *priv = data; | ||
7543 | |||
7544 | struct ieee80211_network *network = NULL; | ||
7545 | struct ipw_network_match match = { | ||
7546 | .network = NULL | ||
7547 | }; | ||
7548 | struct ipw_supported_rates *rates; | ||
7549 | struct list_head *element; | ||
7550 | unsigned long flags; | ||
7551 | DECLARE_SSID_BUF(ssid); | ||
7552 | |||
7553 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { | ||
7554 | IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n"); | ||
7555 | return 0; | ||
7556 | } | ||
7557 | |||
7558 | if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { | ||
7559 | IPW_DEBUG_ASSOC("Not attempting association (already in " | ||
7560 | "progress)\n"); | ||
7561 | return 0; | ||
7562 | } | ||
7563 | |||
7564 | if (priv->status & STATUS_DISASSOCIATING) { | ||
7565 | IPW_DEBUG_ASSOC("Not attempting association (in " | ||
7566 | "disassociating)\n "); | ||
7567 | queue_work(priv->workqueue, &priv->associate); | ||
7568 | return 0; | ||
7569 | } | ||
7570 | |||
7571 | if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) { | ||
7572 | IPW_DEBUG_ASSOC("Not attempting association (scanning or not " | ||
7573 | "initialized)\n"); | ||
7574 | return 0; | ||
7575 | } | ||
7576 | |||
7577 | if (!(priv->config & CFG_ASSOCIATE) && | ||
7578 | !(priv->config & (CFG_STATIC_ESSID | CFG_STATIC_BSSID))) { | ||
7579 | IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n"); | ||
7580 | return 0; | ||
7581 | } | ||
7582 | |||
7583 | /* Protect our use of the network_list */ | ||
7584 | spin_lock_irqsave(&priv->ieee->lock, flags); | ||
7585 | list_for_each_entry(network, &priv->ieee->network_list, list) | ||
7586 | ipw_best_network(priv, &match, network, 0); | ||
7587 | |||
7588 | network = match.network; | ||
7589 | rates = &match.rates; | ||
7590 | |||
7591 | if (network == NULL && | ||
7592 | priv->ieee->iw_mode == IW_MODE_ADHOC && | ||
7593 | priv->config & CFG_ADHOC_CREATE && | ||
7594 | priv->config & CFG_STATIC_ESSID && | ||
7595 | priv->config & CFG_STATIC_CHANNEL) { | ||
7596 | /* Use oldest network if the free list is empty */ | ||
7597 | if (list_empty(&priv->ieee->network_free_list)) { | ||
7598 | struct ieee80211_network *oldest = NULL; | ||
7599 | struct ieee80211_network *target; | ||
7600 | |||
7601 | list_for_each_entry(target, &priv->ieee->network_list, list) { | ||
7602 | if ((oldest == NULL) || | ||
7603 | (target->last_scanned < oldest->last_scanned)) | ||
7604 | oldest = target; | ||
7605 | } | ||
7606 | |||
7607 | /* If there are no more slots, expire the oldest */ | ||
7608 | list_del(&oldest->list); | ||
7609 | target = oldest; | ||
7610 | IPW_DEBUG_ASSOC("Expired '%s' (%pM) from " | ||
7611 | "network list.\n", | ||
7612 | print_ssid(ssid, target->ssid, | ||
7613 | target->ssid_len), | ||
7614 | target->bssid); | ||
7615 | list_add_tail(&target->list, | ||
7616 | &priv->ieee->network_free_list); | ||
7617 | } | ||
7618 | |||
7619 | element = priv->ieee->network_free_list.next; | ||
7620 | network = list_entry(element, struct ieee80211_network, list); | ||
7621 | ipw_adhoc_create(priv, network); | ||
7622 | rates = &priv->rates; | ||
7623 | list_del(element); | ||
7624 | list_add_tail(&network->list, &priv->ieee->network_list); | ||
7625 | } | ||
7626 | spin_unlock_irqrestore(&priv->ieee->lock, flags); | ||
7627 | |||
7628 | /* If we reached the end of the list, then we don't have any valid | ||
7629 | * matching APs */ | ||
7630 | if (!network) { | ||
7631 | ipw_debug_config(priv); | ||
7632 | |||
7633 | if (!(priv->status & STATUS_SCANNING)) { | ||
7634 | if (!(priv->config & CFG_SPEED_SCAN)) | ||
7635 | queue_delayed_work(priv->workqueue, | ||
7636 | &priv->request_scan, | ||
7637 | SCAN_INTERVAL); | ||
7638 | else | ||
7639 | queue_delayed_work(priv->workqueue, | ||
7640 | &priv->request_scan, 0); | ||
7641 | } | ||
7642 | |||
7643 | return 0; | ||
7644 | } | ||
7645 | |||
7646 | ipw_associate_network(priv, network, rates, 0); | ||
7647 | |||
7648 | return 1; | ||
7649 | } | ||
7650 | |||
7651 | static void ipw_bg_associate(struct work_struct *work) | ||
7652 | { | ||
7653 | struct ipw_priv *priv = | ||
7654 | container_of(work, struct ipw_priv, associate); | ||
7655 | mutex_lock(&priv->mutex); | ||
7656 | ipw_associate(priv); | ||
7657 | mutex_unlock(&priv->mutex); | ||
7658 | } | ||
7659 | |||
7660 | static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv, | ||
7661 | struct sk_buff *skb) | ||
7662 | { | ||
7663 | struct ieee80211_hdr *hdr; | ||
7664 | u16 fc; | ||
7665 | |||
7666 | hdr = (struct ieee80211_hdr *)skb->data; | ||
7667 | fc = le16_to_cpu(hdr->frame_control); | ||
7668 | if (!(fc & IEEE80211_FCTL_PROTECTED)) | ||
7669 | return; | ||
7670 | |||
7671 | fc &= ~IEEE80211_FCTL_PROTECTED; | ||
7672 | hdr->frame_control = cpu_to_le16(fc); | ||
7673 | switch (priv->ieee->sec.level) { | ||
7674 | case SEC_LEVEL_3: | ||
7675 | /* Remove CCMP HDR */ | ||
7676 | memmove(skb->data + IEEE80211_3ADDR_LEN, | ||
7677 | skb->data + IEEE80211_3ADDR_LEN + 8, | ||
7678 | skb->len - IEEE80211_3ADDR_LEN - 8); | ||
7679 | skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */ | ||
7680 | break; | ||
7681 | case SEC_LEVEL_2: | ||
7682 | break; | ||
7683 | case SEC_LEVEL_1: | ||
7684 | /* Remove IV */ | ||
7685 | memmove(skb->data + IEEE80211_3ADDR_LEN, | ||
7686 | skb->data + IEEE80211_3ADDR_LEN + 4, | ||
7687 | skb->len - IEEE80211_3ADDR_LEN - 4); | ||
7688 | skb_trim(skb, skb->len - 8); /* IV + ICV */ | ||
7689 | break; | ||
7690 | case SEC_LEVEL_0: | ||
7691 | break; | ||
7692 | default: | ||
7693 | printk(KERN_ERR "Unknow security level %d\n", | ||
7694 | priv->ieee->sec.level); | ||
7695 | break; | ||
7696 | } | ||
7697 | } | ||
7698 | |||
7699 | static void ipw_handle_data_packet(struct ipw_priv *priv, | ||
7700 | struct ipw_rx_mem_buffer *rxb, | ||
7701 | struct ieee80211_rx_stats *stats) | ||
7702 | { | ||
7703 | struct ieee80211_hdr_4addr *hdr; | ||
7704 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data; | ||
7705 | |||
7706 | /* We received data from the HW, so stop the watchdog */ | ||
7707 | priv->net_dev->trans_start = jiffies; | ||
7708 | |||
7709 | /* We only process data packets if the | ||
7710 | * interface is open */ | ||
7711 | if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) > | ||
7712 | skb_tailroom(rxb->skb))) { | ||
7713 | priv->ieee->stats.rx_errors++; | ||
7714 | priv->wstats.discard.misc++; | ||
7715 | IPW_DEBUG_DROP("Corruption detected! Oh no!\n"); | ||
7716 | return; | ||
7717 | } else if (unlikely(!netif_running(priv->net_dev))) { | ||
7718 | priv->ieee->stats.rx_dropped++; | ||
7719 | priv->wstats.discard.misc++; | ||
7720 | IPW_DEBUG_DROP("Dropping packet while interface is not up.\n"); | ||
7721 | return; | ||
7722 | } | ||
7723 | |||
7724 | /* Advance skb->data to the start of the actual payload */ | ||
7725 | skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data)); | ||
7726 | |||
7727 | /* Set the size of the skb to the size of the frame */ | ||
7728 | skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length)); | ||
7729 | |||
7730 | IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len); | ||
7731 | |||
7732 | /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */ | ||
7733 | hdr = (struct ieee80211_hdr_4addr *)rxb->skb->data; | ||
7734 | if (priv->ieee->iw_mode != IW_MODE_MONITOR && | ||
7735 | (is_multicast_ether_addr(hdr->addr1) ? | ||
7736 | !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt)) | ||
7737 | ipw_rebuild_decrypted_skb(priv, rxb->skb); | ||
7738 | |||
7739 | if (!ieee80211_rx(priv->ieee, rxb->skb, stats)) | ||
7740 | priv->ieee->stats.rx_errors++; | ||
7741 | else { /* ieee80211_rx succeeded, so it now owns the SKB */ | ||
7742 | rxb->skb = NULL; | ||
7743 | __ipw_led_activity_on(priv); | ||
7744 | } | ||
7745 | } | ||
7746 | |||
7747 | #ifdef CONFIG_IPW2200_RADIOTAP | ||
7748 | static void ipw_handle_data_packet_monitor(struct ipw_priv *priv, | ||
7749 | struct ipw_rx_mem_buffer *rxb, | ||
7750 | struct ieee80211_rx_stats *stats) | ||
7751 | { | ||
7752 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data; | ||
7753 | struct ipw_rx_frame *frame = &pkt->u.frame; | ||
7754 | |||
7755 | /* initial pull of some data */ | ||
7756 | u16 received_channel = frame->received_channel; | ||
7757 | u8 antennaAndPhy = frame->antennaAndPhy; | ||
7758 | s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */ | ||
7759 | u16 pktrate = frame->rate; | ||
7760 | |||
7761 | /* Magic struct that slots into the radiotap header -- no reason | ||
7762 | * to build this manually element by element, we can write it much | ||
7763 | * more efficiently than we can parse it. ORDER MATTERS HERE */ | ||
7764 | struct ipw_rt_hdr *ipw_rt; | ||
7765 | |||
7766 | short len = le16_to_cpu(pkt->u.frame.length); | ||
7767 | |||
7768 | /* We received data from the HW, so stop the watchdog */ | ||
7769 | priv->net_dev->trans_start = jiffies; | ||
7770 | |||
7771 | /* We only process data packets if the | ||
7772 | * interface is open */ | ||
7773 | if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) > | ||
7774 | skb_tailroom(rxb->skb))) { | ||
7775 | priv->ieee->stats.rx_errors++; | ||
7776 | priv->wstats.discard.misc++; | ||
7777 | IPW_DEBUG_DROP("Corruption detected! Oh no!\n"); | ||
7778 | return; | ||
7779 | } else if (unlikely(!netif_running(priv->net_dev))) { | ||
7780 | priv->ieee->stats.rx_dropped++; | ||
7781 | priv->wstats.discard.misc++; | ||
7782 | IPW_DEBUG_DROP("Dropping packet while interface is not up.\n"); | ||
7783 | return; | ||
7784 | } | ||
7785 | |||
7786 | /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use | ||
7787 | * that now */ | ||
7788 | if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) { | ||
7789 | /* FIXME: Should alloc bigger skb instead */ | ||
7790 | priv->ieee->stats.rx_dropped++; | ||
7791 | priv->wstats.discard.misc++; | ||
7792 | IPW_DEBUG_DROP("Dropping too large packet in monitor\n"); | ||
7793 | return; | ||
7794 | } | ||
7795 | |||
7796 | /* copy the frame itself */ | ||
7797 | memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr), | ||
7798 | rxb->skb->data + IPW_RX_FRAME_SIZE, len); | ||
7799 | |||
7800 | /* Zero the radiotap static buffer ... We only need to zero the bytes NOT | ||
7801 | * part of our real header, saves a little time. | ||
7802 | * | ||
7803 | * No longer necessary since we fill in all our data. Purge before merging | ||
7804 | * patch officially. | ||
7805 | * memset(rxb->skb->data + sizeof(struct ipw_rt_hdr), 0, | ||
7806 | * IEEE80211_RADIOTAP_HDRLEN - sizeof(struct ipw_rt_hdr)); | ||
7807 | */ | ||
7808 | |||
7809 | ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data; | ||
7810 | |||
7811 | ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION; | ||
7812 | ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */ | ||
7813 | ipw_rt->rt_hdr.it_len = cpu_to_le16(sizeof(struct ipw_rt_hdr)); /* total header+data */ | ||
7814 | |||
7815 | /* Big bitfield of all the fields we provide in radiotap */ | ||
7816 | ipw_rt->rt_hdr.it_present = cpu_to_le32( | ||
7817 | (1 << IEEE80211_RADIOTAP_TSFT) | | ||
7818 | (1 << IEEE80211_RADIOTAP_FLAGS) | | ||
7819 | (1 << IEEE80211_RADIOTAP_RATE) | | ||
7820 | (1 << IEEE80211_RADIOTAP_CHANNEL) | | ||
7821 | (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | | ||
7822 | (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) | | ||
7823 | (1 << IEEE80211_RADIOTAP_ANTENNA)); | ||
7824 | |||
7825 | /* Zero the flags, we'll add to them as we go */ | ||
7826 | ipw_rt->rt_flags = 0; | ||
7827 | ipw_rt->rt_tsf = (u64)(frame->parent_tsf[3] << 24 | | ||
7828 | frame->parent_tsf[2] << 16 | | ||
7829 | frame->parent_tsf[1] << 8 | | ||
7830 | frame->parent_tsf[0]); | ||
7831 | |||
7832 | /* Convert signal to DBM */ | ||
7833 | ipw_rt->rt_dbmsignal = antsignal; | ||
7834 | ipw_rt->rt_dbmnoise = frame->noise; | ||
7835 | |||
7836 | /* Convert the channel data and set the flags */ | ||
7837 | ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel)); | ||
7838 | if (received_channel > 14) { /* 802.11a */ | ||
7839 | ipw_rt->rt_chbitmask = | ||
7840 | cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ)); | ||
7841 | } else if (antennaAndPhy & 32) { /* 802.11b */ | ||
7842 | ipw_rt->rt_chbitmask = | ||
7843 | cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ)); | ||
7844 | } else { /* 802.11g */ | ||
7845 | ipw_rt->rt_chbitmask = | ||
7846 | cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ); | ||
7847 | } | ||
7848 | |||
7849 | /* set the rate in multiples of 500k/s */ | ||
7850 | switch (pktrate) { | ||
7851 | case IPW_TX_RATE_1MB: | ||
7852 | ipw_rt->rt_rate = 2; | ||
7853 | break; | ||
7854 | case IPW_TX_RATE_2MB: | ||
7855 | ipw_rt->rt_rate = 4; | ||
7856 | break; | ||
7857 | case IPW_TX_RATE_5MB: | ||
7858 | ipw_rt->rt_rate = 10; | ||
7859 | break; | ||
7860 | case IPW_TX_RATE_6MB: | ||
7861 | ipw_rt->rt_rate = 12; | ||
7862 | break; | ||
7863 | case IPW_TX_RATE_9MB: | ||
7864 | ipw_rt->rt_rate = 18; | ||
7865 | break; | ||
7866 | case IPW_TX_RATE_11MB: | ||
7867 | ipw_rt->rt_rate = 22; | ||
7868 | break; | ||
7869 | case IPW_TX_RATE_12MB: | ||
7870 | ipw_rt->rt_rate = 24; | ||
7871 | break; | ||
7872 | case IPW_TX_RATE_18MB: | ||
7873 | ipw_rt->rt_rate = 36; | ||
7874 | break; | ||
7875 | case IPW_TX_RATE_24MB: | ||
7876 | ipw_rt->rt_rate = 48; | ||
7877 | break; | ||
7878 | case IPW_TX_RATE_36MB: | ||
7879 | ipw_rt->rt_rate = 72; | ||
7880 | break; | ||
7881 | case IPW_TX_RATE_48MB: | ||
7882 | ipw_rt->rt_rate = 96; | ||
7883 | break; | ||
7884 | case IPW_TX_RATE_54MB: | ||
7885 | ipw_rt->rt_rate = 108; | ||
7886 | break; | ||
7887 | default: | ||
7888 | ipw_rt->rt_rate = 0; | ||
7889 | break; | ||
7890 | } | ||
7891 | |||
7892 | /* antenna number */ | ||
7893 | ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */ | ||
7894 | |||
7895 | /* set the preamble flag if we have it */ | ||
7896 | if ((antennaAndPhy & 64)) | ||
7897 | ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; | ||
7898 | |||
7899 | /* Set the size of the skb to the size of the frame */ | ||
7900 | skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr)); | ||
7901 | |||
7902 | IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len); | ||
7903 | |||
7904 | if (!ieee80211_rx(priv->ieee, rxb->skb, stats)) | ||
7905 | priv->ieee->stats.rx_errors++; | ||
7906 | else { /* ieee80211_rx succeeded, so it now owns the SKB */ | ||
7907 | rxb->skb = NULL; | ||
7908 | /* no LED during capture */ | ||
7909 | } | ||
7910 | } | ||
7911 | #endif | ||
7912 | |||
7913 | #ifdef CONFIG_IPW2200_PROMISCUOUS | ||
7914 | #define ieee80211_is_probe_response(fc) \ | ||
7915 | ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT && \ | ||
7916 | (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP ) | ||
7917 | |||
7918 | #define ieee80211_is_management(fc) \ | ||
7919 | ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) | ||
7920 | |||
7921 | #define ieee80211_is_control(fc) \ | ||
7922 | ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) | ||
7923 | |||
7924 | #define ieee80211_is_data(fc) \ | ||
7925 | ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) | ||
7926 | |||
7927 | #define ieee80211_is_assoc_request(fc) \ | ||
7928 | ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ) | ||
7929 | |||
7930 | #define ieee80211_is_reassoc_request(fc) \ | ||
7931 | ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ) | ||
7932 | |||
7933 | static void ipw_handle_promiscuous_rx(struct ipw_priv *priv, | ||
7934 | struct ipw_rx_mem_buffer *rxb, | ||
7935 | struct ieee80211_rx_stats *stats) | ||
7936 | { | ||
7937 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data; | ||
7938 | struct ipw_rx_frame *frame = &pkt->u.frame; | ||
7939 | struct ipw_rt_hdr *ipw_rt; | ||
7940 | |||
7941 | /* First cache any information we need before we overwrite | ||
7942 | * the information provided in the skb from the hardware */ | ||
7943 | struct ieee80211_hdr *hdr; | ||
7944 | u16 channel = frame->received_channel; | ||
7945 | u8 phy_flags = frame->antennaAndPhy; | ||
7946 | s8 signal = frame->rssi_dbm - IPW_RSSI_TO_DBM; | ||
7947 | s8 noise = frame->noise; | ||
7948 | u8 rate = frame->rate; | ||
7949 | short len = le16_to_cpu(pkt->u.frame.length); | ||
7950 | struct sk_buff *skb; | ||
7951 | int hdr_only = 0; | ||
7952 | u16 filter = priv->prom_priv->filter; | ||
7953 | |||
7954 | /* If the filter is set to not include Rx frames then return */ | ||
7955 | if (filter & IPW_PROM_NO_RX) | ||
7956 | return; | ||
7957 | |||
7958 | /* We received data from the HW, so stop the watchdog */ | ||
7959 | priv->prom_net_dev->trans_start = jiffies; | ||
7960 | |||
7961 | if (unlikely((len + IPW_RX_FRAME_SIZE) > skb_tailroom(rxb->skb))) { | ||
7962 | priv->prom_priv->ieee->stats.rx_errors++; | ||
7963 | IPW_DEBUG_DROP("Corruption detected! Oh no!\n"); | ||
7964 | return; | ||
7965 | } | ||
7966 | |||
7967 | /* We only process data packets if the interface is open */ | ||
7968 | if (unlikely(!netif_running(priv->prom_net_dev))) { | ||
7969 | priv->prom_priv->ieee->stats.rx_dropped++; | ||
7970 | IPW_DEBUG_DROP("Dropping packet while interface is not up.\n"); | ||
7971 | return; | ||
7972 | } | ||
7973 | |||
7974 | /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use | ||
7975 | * that now */ | ||
7976 | if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) { | ||
7977 | /* FIXME: Should alloc bigger skb instead */ | ||
7978 | priv->prom_priv->ieee->stats.rx_dropped++; | ||
7979 | IPW_DEBUG_DROP("Dropping too large packet in monitor\n"); | ||
7980 | return; | ||
7981 | } | ||
7982 | |||
7983 | hdr = (void *)rxb->skb->data + IPW_RX_FRAME_SIZE; | ||
7984 | if (ieee80211_is_management(le16_to_cpu(hdr->frame_control))) { | ||
7985 | if (filter & IPW_PROM_NO_MGMT) | ||
7986 | return; | ||
7987 | if (filter & IPW_PROM_MGMT_HEADER_ONLY) | ||
7988 | hdr_only = 1; | ||
7989 | } else if (ieee80211_is_control(le16_to_cpu(hdr->frame_control))) { | ||
7990 | if (filter & IPW_PROM_NO_CTL) | ||
7991 | return; | ||
7992 | if (filter & IPW_PROM_CTL_HEADER_ONLY) | ||
7993 | hdr_only = 1; | ||
7994 | } else if (ieee80211_is_data(le16_to_cpu(hdr->frame_control))) { | ||
7995 | if (filter & IPW_PROM_NO_DATA) | ||
7996 | return; | ||
7997 | if (filter & IPW_PROM_DATA_HEADER_ONLY) | ||
7998 | hdr_only = 1; | ||
7999 | } | ||
8000 | |||
8001 | /* Copy the SKB since this is for the promiscuous side */ | ||
8002 | skb = skb_copy(rxb->skb, GFP_ATOMIC); | ||
8003 | if (skb == NULL) { | ||
8004 | IPW_ERROR("skb_clone failed for promiscuous copy.\n"); | ||
8005 | return; | ||
8006 | } | ||
8007 | |||
8008 | /* copy the frame data to write after where the radiotap header goes */ | ||
8009 | ipw_rt = (void *)skb->data; | ||
8010 | |||
8011 | if (hdr_only) | ||
8012 | len = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_control)); | ||
8013 | |||
8014 | memcpy(ipw_rt->payload, hdr, len); | ||
8015 | |||
8016 | /* Zero the radiotap static buffer ... We only need to zero the bytes | ||
8017 | * NOT part of our real header, saves a little time. | ||
8018 | * | ||
8019 | * No longer necessary since we fill in all our data. Purge before | ||
8020 | * merging patch officially. | ||
8021 | * memset(rxb->skb->data + sizeof(struct ipw_rt_hdr), 0, | ||
8022 | * IEEE80211_RADIOTAP_HDRLEN - sizeof(struct ipw_rt_hdr)); | ||
8023 | */ | ||
8024 | |||
8025 | ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION; | ||
8026 | ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */ | ||
8027 | ipw_rt->rt_hdr.it_len = cpu_to_le16(sizeof(*ipw_rt)); /* total header+data */ | ||
8028 | |||
8029 | /* Set the size of the skb to the size of the frame */ | ||
8030 | skb_put(skb, sizeof(*ipw_rt) + len); | ||
8031 | |||
8032 | /* Big bitfield of all the fields we provide in radiotap */ | ||
8033 | ipw_rt->rt_hdr.it_present = cpu_to_le32( | ||
8034 | (1 << IEEE80211_RADIOTAP_TSFT) | | ||
8035 | (1 << IEEE80211_RADIOTAP_FLAGS) | | ||
8036 | (1 << IEEE80211_RADIOTAP_RATE) | | ||
8037 | (1 << IEEE80211_RADIOTAP_CHANNEL) | | ||
8038 | (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | | ||
8039 | (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) | | ||
8040 | (1 << IEEE80211_RADIOTAP_ANTENNA)); | ||
8041 | |||
8042 | /* Zero the flags, we'll add to them as we go */ | ||
8043 | ipw_rt->rt_flags = 0; | ||
8044 | ipw_rt->rt_tsf = (u64)(frame->parent_tsf[3] << 24 | | ||
8045 | frame->parent_tsf[2] << 16 | | ||
8046 | frame->parent_tsf[1] << 8 | | ||
8047 | frame->parent_tsf[0]); | ||
8048 | |||
8049 | /* Convert to DBM */ | ||
8050 | ipw_rt->rt_dbmsignal = signal; | ||
8051 | ipw_rt->rt_dbmnoise = noise; | ||
8052 | |||
8053 | /* Convert the channel data and set the flags */ | ||
8054 | ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(channel)); | ||
8055 | if (channel > 14) { /* 802.11a */ | ||
8056 | ipw_rt->rt_chbitmask = | ||
8057 | cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ)); | ||
8058 | } else if (phy_flags & (1 << 5)) { /* 802.11b */ | ||
8059 | ipw_rt->rt_chbitmask = | ||
8060 | cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ)); | ||
8061 | } else { /* 802.11g */ | ||
8062 | ipw_rt->rt_chbitmask = | ||
8063 | cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ); | ||
8064 | } | ||
8065 | |||
8066 | /* set the rate in multiples of 500k/s */ | ||
8067 | switch (rate) { | ||
8068 | case IPW_TX_RATE_1MB: | ||
8069 | ipw_rt->rt_rate = 2; | ||
8070 | break; | ||
8071 | case IPW_TX_RATE_2MB: | ||
8072 | ipw_rt->rt_rate = 4; | ||
8073 | break; | ||
8074 | case IPW_TX_RATE_5MB: | ||
8075 | ipw_rt->rt_rate = 10; | ||
8076 | break; | ||
8077 | case IPW_TX_RATE_6MB: | ||
8078 | ipw_rt->rt_rate = 12; | ||
8079 | break; | ||
8080 | case IPW_TX_RATE_9MB: | ||
8081 | ipw_rt->rt_rate = 18; | ||
8082 | break; | ||
8083 | case IPW_TX_RATE_11MB: | ||
8084 | ipw_rt->rt_rate = 22; | ||
8085 | break; | ||
8086 | case IPW_TX_RATE_12MB: | ||
8087 | ipw_rt->rt_rate = 24; | ||
8088 | break; | ||
8089 | case IPW_TX_RATE_18MB: | ||
8090 | ipw_rt->rt_rate = 36; | ||
8091 | break; | ||
8092 | case IPW_TX_RATE_24MB: | ||
8093 | ipw_rt->rt_rate = 48; | ||
8094 | break; | ||
8095 | case IPW_TX_RATE_36MB: | ||
8096 | ipw_rt->rt_rate = 72; | ||
8097 | break; | ||
8098 | case IPW_TX_RATE_48MB: | ||
8099 | ipw_rt->rt_rate = 96; | ||
8100 | break; | ||
8101 | case IPW_TX_RATE_54MB: | ||
8102 | ipw_rt->rt_rate = 108; | ||
8103 | break; | ||
8104 | default: | ||
8105 | ipw_rt->rt_rate = 0; | ||
8106 | break; | ||
8107 | } | ||
8108 | |||
8109 | /* antenna number */ | ||
8110 | ipw_rt->rt_antenna = (phy_flags & 3); | ||
8111 | |||
8112 | /* set the preamble flag if we have it */ | ||
8113 | if (phy_flags & (1 << 6)) | ||
8114 | ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; | ||
8115 | |||
8116 | IPW_DEBUG_RX("Rx packet of %d bytes.\n", skb->len); | ||
8117 | |||
8118 | if (!ieee80211_rx(priv->prom_priv->ieee, skb, stats)) { | ||
8119 | priv->prom_priv->ieee->stats.rx_errors++; | ||
8120 | dev_kfree_skb_any(skb); | ||
8121 | } | ||
8122 | } | ||
8123 | #endif | ||
8124 | |||
8125 | static int is_network_packet(struct ipw_priv *priv, | ||
8126 | struct ieee80211_hdr_4addr *header) | ||
8127 | { | ||
8128 | /* Filter incoming packets to determine if they are targetted toward | ||
8129 | * this network, discarding packets coming from ourselves */ | ||
8130 | switch (priv->ieee->iw_mode) { | ||
8131 | case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */ | ||
8132 | /* packets from our adapter are dropped (echo) */ | ||
8133 | if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN)) | ||
8134 | return 0; | ||
8135 | |||
8136 | /* {broad,multi}cast packets to our BSSID go through */ | ||
8137 | if (is_multicast_ether_addr(header->addr1)) | ||
8138 | return !memcmp(header->addr3, priv->bssid, ETH_ALEN); | ||
8139 | |||
8140 | /* packets to our adapter go through */ | ||
8141 | return !memcmp(header->addr1, priv->net_dev->dev_addr, | ||
8142 | ETH_ALEN); | ||
8143 | |||
8144 | case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */ | ||
8145 | /* packets from our adapter are dropped (echo) */ | ||
8146 | if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN)) | ||
8147 | return 0; | ||
8148 | |||
8149 | /* {broad,multi}cast packets to our BSS go through */ | ||
8150 | if (is_multicast_ether_addr(header->addr1)) | ||
8151 | return !memcmp(header->addr2, priv->bssid, ETH_ALEN); | ||
8152 | |||
8153 | /* packets to our adapter go through */ | ||
8154 | return !memcmp(header->addr1, priv->net_dev->dev_addr, | ||
8155 | ETH_ALEN); | ||
8156 | } | ||
8157 | |||
8158 | return 1; | ||
8159 | } | ||
8160 | |||
8161 | #define IPW_PACKET_RETRY_TIME HZ | ||
8162 | |||
8163 | static int is_duplicate_packet(struct ipw_priv *priv, | ||
8164 | struct ieee80211_hdr_4addr *header) | ||
8165 | { | ||
8166 | u16 sc = le16_to_cpu(header->seq_ctl); | ||
8167 | u16 seq = WLAN_GET_SEQ_SEQ(sc); | ||
8168 | u16 frag = WLAN_GET_SEQ_FRAG(sc); | ||
8169 | u16 *last_seq, *last_frag; | ||
8170 | unsigned long *last_time; | ||
8171 | |||
8172 | switch (priv->ieee->iw_mode) { | ||
8173 | case IW_MODE_ADHOC: | ||
8174 | { | ||
8175 | struct list_head *p; | ||
8176 | struct ipw_ibss_seq *entry = NULL; | ||
8177 | u8 *mac = header->addr2; | ||
8178 | int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE; | ||
8179 | |||
8180 | __list_for_each(p, &priv->ibss_mac_hash[index]) { | ||
8181 | entry = | ||
8182 | list_entry(p, struct ipw_ibss_seq, list); | ||
8183 | if (!memcmp(entry->mac, mac, ETH_ALEN)) | ||
8184 | break; | ||
8185 | } | ||
8186 | if (p == &priv->ibss_mac_hash[index]) { | ||
8187 | entry = kmalloc(sizeof(*entry), GFP_ATOMIC); | ||
8188 | if (!entry) { | ||
8189 | IPW_ERROR | ||
8190 | ("Cannot malloc new mac entry\n"); | ||
8191 | return 0; | ||
8192 | } | ||
8193 | memcpy(entry->mac, mac, ETH_ALEN); | ||
8194 | entry->seq_num = seq; | ||
8195 | entry->frag_num = frag; | ||
8196 | entry->packet_time = jiffies; | ||
8197 | list_add(&entry->list, | ||
8198 | &priv->ibss_mac_hash[index]); | ||
8199 | return 0; | ||
8200 | } | ||
8201 | last_seq = &entry->seq_num; | ||
8202 | last_frag = &entry->frag_num; | ||
8203 | last_time = &entry->packet_time; | ||
8204 | break; | ||
8205 | } | ||
8206 | case IW_MODE_INFRA: | ||
8207 | last_seq = &priv->last_seq_num; | ||
8208 | last_frag = &priv->last_frag_num; | ||
8209 | last_time = &priv->last_packet_time; | ||
8210 | break; | ||
8211 | default: | ||
8212 | return 0; | ||
8213 | } | ||
8214 | if ((*last_seq == seq) && | ||
8215 | time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) { | ||
8216 | if (*last_frag == frag) | ||
8217 | goto drop; | ||
8218 | if (*last_frag + 1 != frag) | ||
8219 | /* out-of-order fragment */ | ||
8220 | goto drop; | ||
8221 | } else | ||
8222 | *last_seq = seq; | ||
8223 | |||
8224 | *last_frag = frag; | ||
8225 | *last_time = jiffies; | ||
8226 | return 0; | ||
8227 | |||
8228 | drop: | ||
8229 | /* Comment this line now since we observed the card receives | ||
8230 | * duplicate packets but the FCTL_RETRY bit is not set in the | ||
8231 | * IBSS mode with fragmentation enabled. | ||
8232 | BUG_ON(!(le16_to_cpu(header->frame_control) & IEEE80211_FCTL_RETRY)); */ | ||
8233 | return 1; | ||
8234 | } | ||
8235 | |||
8236 | static void ipw_handle_mgmt_packet(struct ipw_priv *priv, | ||
8237 | struct ipw_rx_mem_buffer *rxb, | ||
8238 | struct ieee80211_rx_stats *stats) | ||
8239 | { | ||
8240 | struct sk_buff *skb = rxb->skb; | ||
8241 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data; | ||
8242 | struct ieee80211_hdr_4addr *header = (struct ieee80211_hdr_4addr *) | ||
8243 | (skb->data + IPW_RX_FRAME_SIZE); | ||
8244 | |||
8245 | ieee80211_rx_mgt(priv->ieee, header, stats); | ||
8246 | |||
8247 | if (priv->ieee->iw_mode == IW_MODE_ADHOC && | ||
8248 | ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) == | ||
8249 | IEEE80211_STYPE_PROBE_RESP) || | ||
8250 | (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) == | ||
8251 | IEEE80211_STYPE_BEACON))) { | ||
8252 | if (!memcmp(header->addr3, priv->bssid, ETH_ALEN)) | ||
8253 | ipw_add_station(priv, header->addr2); | ||
8254 | } | ||
8255 | |||
8256 | if (priv->config & CFG_NET_STATS) { | ||
8257 | IPW_DEBUG_HC("sending stat packet\n"); | ||
8258 | |||
8259 | /* Set the size of the skb to the size of the full | ||
8260 | * ipw header and 802.11 frame */ | ||
8261 | skb_put(skb, le16_to_cpu(pkt->u.frame.length) + | ||
8262 | IPW_RX_FRAME_SIZE); | ||
8263 | |||
8264 | /* Advance past the ipw packet header to the 802.11 frame */ | ||
8265 | skb_pull(skb, IPW_RX_FRAME_SIZE); | ||
8266 | |||
8267 | /* Push the ieee80211_rx_stats before the 802.11 frame */ | ||
8268 | memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats)); | ||
8269 | |||
8270 | skb->dev = priv->ieee->dev; | ||
8271 | |||
8272 | /* Point raw at the ieee80211_stats */ | ||
8273 | skb_reset_mac_header(skb); | ||
8274 | |||
8275 | skb->pkt_type = PACKET_OTHERHOST; | ||
8276 | skb->protocol = __constant_htons(ETH_P_80211_STATS); | ||
8277 | memset(skb->cb, 0, sizeof(rxb->skb->cb)); | ||
8278 | netif_rx(skb); | ||
8279 | rxb->skb = NULL; | ||
8280 | } | ||
8281 | } | ||
8282 | |||
8283 | /* | ||
8284 | * Main entry function for recieving a packet with 80211 headers. This | ||
8285 | * should be called when ever the FW has notified us that there is a new | ||
8286 | * skb in the recieve queue. | ||
8287 | */ | ||
8288 | static void ipw_rx(struct ipw_priv *priv) | ||
8289 | { | ||
8290 | struct ipw_rx_mem_buffer *rxb; | ||
8291 | struct ipw_rx_packet *pkt; | ||
8292 | struct ieee80211_hdr_4addr *header; | ||
8293 | u32 r, w, i; | ||
8294 | u8 network_packet; | ||
8295 | u8 fill_rx = 0; | ||
8296 | |||
8297 | r = ipw_read32(priv, IPW_RX_READ_INDEX); | ||
8298 | w = ipw_read32(priv, IPW_RX_WRITE_INDEX); | ||
8299 | i = priv->rxq->read; | ||
8300 | |||
8301 | if (ipw_rx_queue_space (priv->rxq) > (RX_QUEUE_SIZE / 2)) | ||
8302 | fill_rx = 1; | ||
8303 | |||
8304 | while (i != r) { | ||
8305 | rxb = priv->rxq->queue[i]; | ||
8306 | if (unlikely(rxb == NULL)) { | ||
8307 | printk(KERN_CRIT "Queue not allocated!\n"); | ||
8308 | break; | ||
8309 | } | ||
8310 | priv->rxq->queue[i] = NULL; | ||
8311 | |||
8312 | pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr, | ||
8313 | IPW_RX_BUF_SIZE, | ||
8314 | PCI_DMA_FROMDEVICE); | ||
8315 | |||
8316 | pkt = (struct ipw_rx_packet *)rxb->skb->data; | ||
8317 | IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n", | ||
8318 | pkt->header.message_type, | ||
8319 | pkt->header.rx_seq_num, pkt->header.control_bits); | ||
8320 | |||
8321 | switch (pkt->header.message_type) { | ||
8322 | case RX_FRAME_TYPE: /* 802.11 frame */ { | ||
8323 | struct ieee80211_rx_stats stats = { | ||
8324 | .rssi = pkt->u.frame.rssi_dbm - | ||
8325 | IPW_RSSI_TO_DBM, | ||
8326 | .signal = | ||
8327 | le16_to_cpu(pkt->u.frame.rssi_dbm) - | ||
8328 | IPW_RSSI_TO_DBM + 0x100, | ||
8329 | .noise = | ||
8330 | le16_to_cpu(pkt->u.frame.noise), | ||
8331 | .rate = pkt->u.frame.rate, | ||
8332 | .mac_time = jiffies, | ||
8333 | .received_channel = | ||
8334 | pkt->u.frame.received_channel, | ||
8335 | .freq = | ||
8336 | (pkt->u.frame. | ||
8337 | control & (1 << 0)) ? | ||
8338 | IEEE80211_24GHZ_BAND : | ||
8339 | IEEE80211_52GHZ_BAND, | ||
8340 | .len = le16_to_cpu(pkt->u.frame.length), | ||
8341 | }; | ||
8342 | |||
8343 | if (stats.rssi != 0) | ||
8344 | stats.mask |= IEEE80211_STATMASK_RSSI; | ||
8345 | if (stats.signal != 0) | ||
8346 | stats.mask |= IEEE80211_STATMASK_SIGNAL; | ||
8347 | if (stats.noise != 0) | ||
8348 | stats.mask |= IEEE80211_STATMASK_NOISE; | ||
8349 | if (stats.rate != 0) | ||
8350 | stats.mask |= IEEE80211_STATMASK_RATE; | ||
8351 | |||
8352 | priv->rx_packets++; | ||
8353 | |||
8354 | #ifdef CONFIG_IPW2200_PROMISCUOUS | ||
8355 | if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) | ||
8356 | ipw_handle_promiscuous_rx(priv, rxb, &stats); | ||
8357 | #endif | ||
8358 | |||
8359 | #ifdef CONFIG_IPW2200_MONITOR | ||
8360 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { | ||
8361 | #ifdef CONFIG_IPW2200_RADIOTAP | ||
8362 | |||
8363 | ipw_handle_data_packet_monitor(priv, | ||
8364 | rxb, | ||
8365 | &stats); | ||
8366 | #else | ||
8367 | ipw_handle_data_packet(priv, rxb, | ||
8368 | &stats); | ||
8369 | #endif | ||
8370 | break; | ||
8371 | } | ||
8372 | #endif | ||
8373 | |||
8374 | header = | ||
8375 | (struct ieee80211_hdr_4addr *)(rxb->skb-> | ||
8376 | data + | ||
8377 | IPW_RX_FRAME_SIZE); | ||
8378 | /* TODO: Check Ad-Hoc dest/source and make sure | ||
8379 | * that we are actually parsing these packets | ||
8380 | * correctly -- we should probably use the | ||
8381 | * frame control of the packet and disregard | ||
8382 | * the current iw_mode */ | ||
8383 | |||
8384 | network_packet = | ||
8385 | is_network_packet(priv, header); | ||
8386 | if (network_packet && priv->assoc_network) { | ||
8387 | priv->assoc_network->stats.rssi = | ||
8388 | stats.rssi; | ||
8389 | priv->exp_avg_rssi = | ||
8390 | exponential_average(priv->exp_avg_rssi, | ||
8391 | stats.rssi, DEPTH_RSSI); | ||
8392 | } | ||
8393 | |||
8394 | IPW_DEBUG_RX("Frame: len=%u\n", | ||
8395 | le16_to_cpu(pkt->u.frame.length)); | ||
8396 | |||
8397 | if (le16_to_cpu(pkt->u.frame.length) < | ||
8398 | ieee80211_get_hdrlen(le16_to_cpu( | ||
8399 | header->frame_ctl))) { | ||
8400 | IPW_DEBUG_DROP | ||
8401 | ("Received packet is too small. " | ||
8402 | "Dropping.\n"); | ||
8403 | priv->ieee->stats.rx_errors++; | ||
8404 | priv->wstats.discard.misc++; | ||
8405 | break; | ||
8406 | } | ||
8407 | |||
8408 | switch (WLAN_FC_GET_TYPE | ||
8409 | (le16_to_cpu(header->frame_ctl))) { | ||
8410 | |||
8411 | case IEEE80211_FTYPE_MGMT: | ||
8412 | ipw_handle_mgmt_packet(priv, rxb, | ||
8413 | &stats); | ||
8414 | break; | ||
8415 | |||
8416 | case IEEE80211_FTYPE_CTL: | ||
8417 | break; | ||
8418 | |||
8419 | case IEEE80211_FTYPE_DATA: | ||
8420 | if (unlikely(!network_packet || | ||
8421 | is_duplicate_packet(priv, | ||
8422 | header))) | ||
8423 | { | ||
8424 | IPW_DEBUG_DROP("Dropping: " | ||
8425 | "%pM, " | ||
8426 | "%pM, " | ||
8427 | "%pM\n", | ||
8428 | header->addr1, | ||
8429 | header->addr2, | ||
8430 | header->addr3); | ||
8431 | break; | ||
8432 | } | ||
8433 | |||
8434 | ipw_handle_data_packet(priv, rxb, | ||
8435 | &stats); | ||
8436 | |||
8437 | break; | ||
8438 | } | ||
8439 | break; | ||
8440 | } | ||
8441 | |||
8442 | case RX_HOST_NOTIFICATION_TYPE:{ | ||
8443 | IPW_DEBUG_RX | ||
8444 | ("Notification: subtype=%02X flags=%02X size=%d\n", | ||
8445 | pkt->u.notification.subtype, | ||
8446 | pkt->u.notification.flags, | ||
8447 | le16_to_cpu(pkt->u.notification.size)); | ||
8448 | ipw_rx_notification(priv, &pkt->u.notification); | ||
8449 | break; | ||
8450 | } | ||
8451 | |||
8452 | default: | ||
8453 | IPW_DEBUG_RX("Bad Rx packet of type %d\n", | ||
8454 | pkt->header.message_type); | ||
8455 | break; | ||
8456 | } | ||
8457 | |||
8458 | /* For now we just don't re-use anything. We can tweak this | ||
8459 | * later to try and re-use notification packets and SKBs that | ||
8460 | * fail to Rx correctly */ | ||
8461 | if (rxb->skb != NULL) { | ||
8462 | dev_kfree_skb_any(rxb->skb); | ||
8463 | rxb->skb = NULL; | ||
8464 | } | ||
8465 | |||
8466 | pci_unmap_single(priv->pci_dev, rxb->dma_addr, | ||
8467 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); | ||
8468 | list_add_tail(&rxb->list, &priv->rxq->rx_used); | ||
8469 | |||
8470 | i = (i + 1) % RX_QUEUE_SIZE; | ||
8471 | |||
8472 | /* If there are a lot of unsued frames, restock the Rx queue | ||
8473 | * so the ucode won't assert */ | ||
8474 | if (fill_rx) { | ||
8475 | priv->rxq->read = i; | ||
8476 | ipw_rx_queue_replenish(priv); | ||
8477 | } | ||
8478 | } | ||
8479 | |||
8480 | /* Backtrack one entry */ | ||
8481 | priv->rxq->read = i; | ||
8482 | ipw_rx_queue_restock(priv); | ||
8483 | } | ||
8484 | |||
8485 | #define DEFAULT_RTS_THRESHOLD 2304U | ||
8486 | #define MIN_RTS_THRESHOLD 1U | ||
8487 | #define MAX_RTS_THRESHOLD 2304U | ||
8488 | #define DEFAULT_BEACON_INTERVAL 100U | ||
8489 | #define DEFAULT_SHORT_RETRY_LIMIT 7U | ||
8490 | #define DEFAULT_LONG_RETRY_LIMIT 4U | ||
8491 | |||
8492 | /** | ||
8493 | * ipw_sw_reset | ||
8494 | * @option: options to control different reset behaviour | ||
8495 | * 0 = reset everything except the 'disable' module_param | ||
8496 | * 1 = reset everything and print out driver info (for probe only) | ||
8497 | * 2 = reset everything | ||
8498 | */ | ||
8499 | static int ipw_sw_reset(struct ipw_priv *priv, int option) | ||
8500 | { | ||
8501 | int band, modulation; | ||
8502 | int old_mode = priv->ieee->iw_mode; | ||
8503 | |||
8504 | /* Initialize module parameter values here */ | ||
8505 | priv->config = 0; | ||
8506 | |||
8507 | /* We default to disabling the LED code as right now it causes | ||
8508 | * too many systems to lock up... */ | ||
8509 | if (!led) | ||
8510 | priv->config |= CFG_NO_LED; | ||
8511 | |||
8512 | if (associate) | ||
8513 | priv->config |= CFG_ASSOCIATE; | ||
8514 | else | ||
8515 | IPW_DEBUG_INFO("Auto associate disabled.\n"); | ||
8516 | |||
8517 | if (auto_create) | ||
8518 | priv->config |= CFG_ADHOC_CREATE; | ||
8519 | else | ||
8520 | IPW_DEBUG_INFO("Auto adhoc creation disabled.\n"); | ||
8521 | |||
8522 | priv->config &= ~CFG_STATIC_ESSID; | ||
8523 | priv->essid_len = 0; | ||
8524 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); | ||
8525 | |||
8526 | if (disable && option) { | ||
8527 | priv->status |= STATUS_RF_KILL_SW; | ||
8528 | IPW_DEBUG_INFO("Radio disabled.\n"); | ||
8529 | } | ||
8530 | |||
8531 | if (channel != 0) { | ||
8532 | priv->config |= CFG_STATIC_CHANNEL; | ||
8533 | priv->channel = channel; | ||
8534 | IPW_DEBUG_INFO("Bind to static channel %d\n", channel); | ||
8535 | /* TODO: Validate that provided channel is in range */ | ||
8536 | } | ||
8537 | #ifdef CONFIG_IPW2200_QOS | ||
8538 | ipw_qos_init(priv, qos_enable, qos_burst_enable, | ||
8539 | burst_duration_CCK, burst_duration_OFDM); | ||
8540 | #endif /* CONFIG_IPW2200_QOS */ | ||
8541 | |||
8542 | switch (mode) { | ||
8543 | case 1: | ||
8544 | priv->ieee->iw_mode = IW_MODE_ADHOC; | ||
8545 | priv->net_dev->type = ARPHRD_ETHER; | ||
8546 | |||
8547 | break; | ||
8548 | #ifdef CONFIG_IPW2200_MONITOR | ||
8549 | case 2: | ||
8550 | priv->ieee->iw_mode = IW_MODE_MONITOR; | ||
8551 | #ifdef CONFIG_IPW2200_RADIOTAP | ||
8552 | priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; | ||
8553 | #else | ||
8554 | priv->net_dev->type = ARPHRD_IEEE80211; | ||
8555 | #endif | ||
8556 | break; | ||
8557 | #endif | ||
8558 | default: | ||
8559 | case 0: | ||
8560 | priv->net_dev->type = ARPHRD_ETHER; | ||
8561 | priv->ieee->iw_mode = IW_MODE_INFRA; | ||
8562 | break; | ||
8563 | } | ||
8564 | |||
8565 | if (hwcrypto) { | ||
8566 | priv->ieee->host_encrypt = 0; | ||
8567 | priv->ieee->host_encrypt_msdu = 0; | ||
8568 | priv->ieee->host_decrypt = 0; | ||
8569 | priv->ieee->host_mc_decrypt = 0; | ||
8570 | } | ||
8571 | IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off"); | ||
8572 | |||
8573 | /* IPW2200/2915 is abled to do hardware fragmentation. */ | ||
8574 | priv->ieee->host_open_frag = 0; | ||
8575 | |||
8576 | if ((priv->pci_dev->device == 0x4223) || | ||
8577 | (priv->pci_dev->device == 0x4224)) { | ||
8578 | if (option == 1) | ||
8579 | printk(KERN_INFO DRV_NAME | ||
8580 | ": Detected Intel PRO/Wireless 2915ABG Network " | ||
8581 | "Connection\n"); | ||
8582 | priv->ieee->abg_true = 1; | ||
8583 | band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND; | ||
8584 | modulation = IEEE80211_OFDM_MODULATION | | ||
8585 | IEEE80211_CCK_MODULATION; | ||
8586 | priv->adapter = IPW_2915ABG; | ||
8587 | priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B; | ||
8588 | } else { | ||
8589 | if (option == 1) | ||
8590 | printk(KERN_INFO DRV_NAME | ||
8591 | ": Detected Intel PRO/Wireless 2200BG Network " | ||
8592 | "Connection\n"); | ||
8593 | |||
8594 | priv->ieee->abg_true = 0; | ||
8595 | band = IEEE80211_24GHZ_BAND; | ||
8596 | modulation = IEEE80211_OFDM_MODULATION | | ||
8597 | IEEE80211_CCK_MODULATION; | ||
8598 | priv->adapter = IPW_2200BG; | ||
8599 | priv->ieee->mode = IEEE_G | IEEE_B; | ||
8600 | } | ||
8601 | |||
8602 | priv->ieee->freq_band = band; | ||
8603 | priv->ieee->modulation = modulation; | ||
8604 | |||
8605 | priv->rates_mask = IEEE80211_DEFAULT_RATES_MASK; | ||
8606 | |||
8607 | priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT; | ||
8608 | priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT; | ||
8609 | |||
8610 | priv->rts_threshold = DEFAULT_RTS_THRESHOLD; | ||
8611 | priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT; | ||
8612 | priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT; | ||
8613 | |||
8614 | /* If power management is turned on, default to AC mode */ | ||
8615 | priv->power_mode = IPW_POWER_AC; | ||
8616 | priv->tx_power = IPW_TX_POWER_DEFAULT; | ||
8617 | |||
8618 | return old_mode == priv->ieee->iw_mode; | ||
8619 | } | ||
8620 | |||
8621 | /* | ||
8622 | * This file defines the Wireless Extension handlers. It does not | ||
8623 | * define any methods of hardware manipulation and relies on the | ||
8624 | * functions defined in ipw_main to provide the HW interaction. | ||
8625 | * | ||
8626 | * The exception to this is the use of the ipw_get_ordinal() | ||
8627 | * function used to poll the hardware vs. making unecessary calls. | ||
8628 | * | ||
8629 | */ | ||
8630 | |||
8631 | static int ipw_wx_get_name(struct net_device *dev, | ||
8632 | struct iw_request_info *info, | ||
8633 | union iwreq_data *wrqu, char *extra) | ||
8634 | { | ||
8635 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
8636 | mutex_lock(&priv->mutex); | ||
8637 | if (priv->status & STATUS_RF_KILL_MASK) | ||
8638 | strcpy(wrqu->name, "radio off"); | ||
8639 | else if (!(priv->status & STATUS_ASSOCIATED)) | ||
8640 | strcpy(wrqu->name, "unassociated"); | ||
8641 | else | ||
8642 | snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11%c", | ||
8643 | ipw_modes[priv->assoc_request.ieee_mode]); | ||
8644 | IPW_DEBUG_WX("Name: %s\n", wrqu->name); | ||
8645 | mutex_unlock(&priv->mutex); | ||
8646 | return 0; | ||
8647 | } | ||
8648 | |||
8649 | static int ipw_set_channel(struct ipw_priv *priv, u8 channel) | ||
8650 | { | ||
8651 | if (channel == 0) { | ||
8652 | IPW_DEBUG_INFO("Setting channel to ANY (0)\n"); | ||
8653 | priv->config &= ~CFG_STATIC_CHANNEL; | ||
8654 | IPW_DEBUG_ASSOC("Attempting to associate with new " | ||
8655 | "parameters.\n"); | ||
8656 | ipw_associate(priv); | ||
8657 | return 0; | ||
8658 | } | ||
8659 | |||
8660 | priv->config |= CFG_STATIC_CHANNEL; | ||
8661 | |||
8662 | if (priv->channel == channel) { | ||
8663 | IPW_DEBUG_INFO("Request to set channel to current value (%d)\n", | ||
8664 | channel); | ||
8665 | return 0; | ||
8666 | } | ||
8667 | |||
8668 | IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel); | ||
8669 | priv->channel = channel; | ||
8670 | |||
8671 | #ifdef CONFIG_IPW2200_MONITOR | ||
8672 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { | ||
8673 | int i; | ||
8674 | if (priv->status & STATUS_SCANNING) { | ||
8675 | IPW_DEBUG_SCAN("Scan abort triggered due to " | ||
8676 | "channel change.\n"); | ||
8677 | ipw_abort_scan(priv); | ||
8678 | } | ||
8679 | |||
8680 | for (i = 1000; i && (priv->status & STATUS_SCANNING); i--) | ||
8681 | udelay(10); | ||
8682 | |||
8683 | if (priv->status & STATUS_SCANNING) | ||
8684 | IPW_DEBUG_SCAN("Still scanning...\n"); | ||
8685 | else | ||
8686 | IPW_DEBUG_SCAN("Took %dms to abort current scan\n", | ||
8687 | 1000 - i); | ||
8688 | |||
8689 | return 0; | ||
8690 | } | ||
8691 | #endif /* CONFIG_IPW2200_MONITOR */ | ||
8692 | |||
8693 | /* Network configuration changed -- force [re]association */ | ||
8694 | IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n"); | ||
8695 | if (!ipw_disassociate(priv)) | ||
8696 | ipw_associate(priv); | ||
8697 | |||
8698 | return 0; | ||
8699 | } | ||
8700 | |||
8701 | static int ipw_wx_set_freq(struct net_device *dev, | ||
8702 | struct iw_request_info *info, | ||
8703 | union iwreq_data *wrqu, char *extra) | ||
8704 | { | ||
8705 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
8706 | const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee); | ||
8707 | struct iw_freq *fwrq = &wrqu->freq; | ||
8708 | int ret = 0, i; | ||
8709 | u8 channel, flags; | ||
8710 | int band; | ||
8711 | |||
8712 | if (fwrq->m == 0) { | ||
8713 | IPW_DEBUG_WX("SET Freq/Channel -> any\n"); | ||
8714 | mutex_lock(&priv->mutex); | ||
8715 | ret = ipw_set_channel(priv, 0); | ||
8716 | mutex_unlock(&priv->mutex); | ||
8717 | return ret; | ||
8718 | } | ||
8719 | /* if setting by freq convert to channel */ | ||
8720 | if (fwrq->e == 1) { | ||
8721 | channel = ieee80211_freq_to_channel(priv->ieee, fwrq->m); | ||
8722 | if (channel == 0) | ||
8723 | return -EINVAL; | ||
8724 | } else | ||
8725 | channel = fwrq->m; | ||
8726 | |||
8727 | if (!(band = ieee80211_is_valid_channel(priv->ieee, channel))) | ||
8728 | return -EINVAL; | ||
8729 | |||
8730 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { | ||
8731 | i = ieee80211_channel_to_index(priv->ieee, channel); | ||
8732 | if (i == -1) | ||
8733 | return -EINVAL; | ||
8734 | |||
8735 | flags = (band == IEEE80211_24GHZ_BAND) ? | ||
8736 | geo->bg[i].flags : geo->a[i].flags; | ||
8737 | if (flags & IEEE80211_CH_PASSIVE_ONLY) { | ||
8738 | IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n"); | ||
8739 | return -EINVAL; | ||
8740 | } | ||
8741 | } | ||
8742 | |||
8743 | IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m); | ||
8744 | mutex_lock(&priv->mutex); | ||
8745 | ret = ipw_set_channel(priv, channel); | ||
8746 | mutex_unlock(&priv->mutex); | ||
8747 | return ret; | ||
8748 | } | ||
8749 | |||
8750 | static int ipw_wx_get_freq(struct net_device *dev, | ||
8751 | struct iw_request_info *info, | ||
8752 | union iwreq_data *wrqu, char *extra) | ||
8753 | { | ||
8754 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
8755 | |||
8756 | wrqu->freq.e = 0; | ||
8757 | |||
8758 | /* If we are associated, trying to associate, or have a statically | ||
8759 | * configured CHANNEL then return that; otherwise return ANY */ | ||
8760 | mutex_lock(&priv->mutex); | ||
8761 | if (priv->config & CFG_STATIC_CHANNEL || | ||
8762 | priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) { | ||
8763 | int i; | ||
8764 | |||
8765 | i = ieee80211_channel_to_index(priv->ieee, priv->channel); | ||
8766 | BUG_ON(i == -1); | ||
8767 | wrqu->freq.e = 1; | ||
8768 | |||
8769 | switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) { | ||
8770 | case IEEE80211_52GHZ_BAND: | ||
8771 | wrqu->freq.m = priv->ieee->geo.a[i].freq * 100000; | ||
8772 | break; | ||
8773 | |||
8774 | case IEEE80211_24GHZ_BAND: | ||
8775 | wrqu->freq.m = priv->ieee->geo.bg[i].freq * 100000; | ||
8776 | break; | ||
8777 | |||
8778 | default: | ||
8779 | BUG(); | ||
8780 | } | ||
8781 | } else | ||
8782 | wrqu->freq.m = 0; | ||
8783 | |||
8784 | mutex_unlock(&priv->mutex); | ||
8785 | IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel); | ||
8786 | return 0; | ||
8787 | } | ||
8788 | |||
8789 | static int ipw_wx_set_mode(struct net_device *dev, | ||
8790 | struct iw_request_info *info, | ||
8791 | union iwreq_data *wrqu, char *extra) | ||
8792 | { | ||
8793 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
8794 | int err = 0; | ||
8795 | |||
8796 | IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode); | ||
8797 | |||
8798 | switch (wrqu->mode) { | ||
8799 | #ifdef CONFIG_IPW2200_MONITOR | ||
8800 | case IW_MODE_MONITOR: | ||
8801 | #endif | ||
8802 | case IW_MODE_ADHOC: | ||
8803 | case IW_MODE_INFRA: | ||
8804 | break; | ||
8805 | case IW_MODE_AUTO: | ||
8806 | wrqu->mode = IW_MODE_INFRA; | ||
8807 | break; | ||
8808 | default: | ||
8809 | return -EINVAL; | ||
8810 | } | ||
8811 | if (wrqu->mode == priv->ieee->iw_mode) | ||
8812 | return 0; | ||
8813 | |||
8814 | mutex_lock(&priv->mutex); | ||
8815 | |||
8816 | ipw_sw_reset(priv, 0); | ||
8817 | |||
8818 | #ifdef CONFIG_IPW2200_MONITOR | ||
8819 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) | ||
8820 | priv->net_dev->type = ARPHRD_ETHER; | ||
8821 | |||
8822 | if (wrqu->mode == IW_MODE_MONITOR) | ||
8823 | #ifdef CONFIG_IPW2200_RADIOTAP | ||
8824 | priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; | ||
8825 | #else | ||
8826 | priv->net_dev->type = ARPHRD_IEEE80211; | ||
8827 | #endif | ||
8828 | #endif /* CONFIG_IPW2200_MONITOR */ | ||
8829 | |||
8830 | /* Free the existing firmware and reset the fw_loaded | ||
8831 | * flag so ipw_load() will bring in the new firmawre */ | ||
8832 | free_firmware(); | ||
8833 | |||
8834 | priv->ieee->iw_mode = wrqu->mode; | ||
8835 | |||
8836 | queue_work(priv->workqueue, &priv->adapter_restart); | ||
8837 | mutex_unlock(&priv->mutex); | ||
8838 | return err; | ||
8839 | } | ||
8840 | |||
8841 | static int ipw_wx_get_mode(struct net_device *dev, | ||
8842 | struct iw_request_info *info, | ||
8843 | union iwreq_data *wrqu, char *extra) | ||
8844 | { | ||
8845 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
8846 | mutex_lock(&priv->mutex); | ||
8847 | wrqu->mode = priv->ieee->iw_mode; | ||
8848 | IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode); | ||
8849 | mutex_unlock(&priv->mutex); | ||
8850 | return 0; | ||
8851 | } | ||
8852 | |||
8853 | /* Values are in microsecond */ | ||
8854 | static const s32 timeout_duration[] = { | ||
8855 | 350000, | ||
8856 | 250000, | ||
8857 | 75000, | ||
8858 | 37000, | ||
8859 | 25000, | ||
8860 | }; | ||
8861 | |||
8862 | static const s32 period_duration[] = { | ||
8863 | 400000, | ||
8864 | 700000, | ||
8865 | 1000000, | ||
8866 | 1000000, | ||
8867 | 1000000 | ||
8868 | }; | ||
8869 | |||
8870 | static int ipw_wx_get_range(struct net_device *dev, | ||
8871 | struct iw_request_info *info, | ||
8872 | union iwreq_data *wrqu, char *extra) | ||
8873 | { | ||
8874 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
8875 | struct iw_range *range = (struct iw_range *)extra; | ||
8876 | const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee); | ||
8877 | int i = 0, j; | ||
8878 | |||
8879 | wrqu->data.length = sizeof(*range); | ||
8880 | memset(range, 0, sizeof(*range)); | ||
8881 | |||
8882 | /* 54Mbs == ~27 Mb/s real (802.11g) */ | ||
8883 | range->throughput = 27 * 1000 * 1000; | ||
8884 | |||
8885 | range->max_qual.qual = 100; | ||
8886 | /* TODO: Find real max RSSI and stick here */ | ||
8887 | range->max_qual.level = 0; | ||
8888 | range->max_qual.noise = 0; | ||
8889 | range->max_qual.updated = 7; /* Updated all three */ | ||
8890 | |||
8891 | range->avg_qual.qual = 70; | ||
8892 | /* TODO: Find real 'good' to 'bad' threshol value for RSSI */ | ||
8893 | range->avg_qual.level = 0; /* FIXME to real average level */ | ||
8894 | range->avg_qual.noise = 0; | ||
8895 | range->avg_qual.updated = 7; /* Updated all three */ | ||
8896 | mutex_lock(&priv->mutex); | ||
8897 | range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES); | ||
8898 | |||
8899 | for (i = 0; i < range->num_bitrates; i++) | ||
8900 | range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) * | ||
8901 | 500000; | ||
8902 | |||
8903 | range->max_rts = DEFAULT_RTS_THRESHOLD; | ||
8904 | range->min_frag = MIN_FRAG_THRESHOLD; | ||
8905 | range->max_frag = MAX_FRAG_THRESHOLD; | ||
8906 | |||
8907 | range->encoding_size[0] = 5; | ||
8908 | range->encoding_size[1] = 13; | ||
8909 | range->num_encoding_sizes = 2; | ||
8910 | range->max_encoding_tokens = WEP_KEYS; | ||
8911 | |||
8912 | /* Set the Wireless Extension versions */ | ||
8913 | range->we_version_compiled = WIRELESS_EXT; | ||
8914 | range->we_version_source = 18; | ||
8915 | |||
8916 | i = 0; | ||
8917 | if (priv->ieee->mode & (IEEE_B | IEEE_G)) { | ||
8918 | for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES; j++) { | ||
8919 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC) && | ||
8920 | (geo->bg[j].flags & IEEE80211_CH_PASSIVE_ONLY)) | ||
8921 | continue; | ||
8922 | |||
8923 | range->freq[i].i = geo->bg[j].channel; | ||
8924 | range->freq[i].m = geo->bg[j].freq * 100000; | ||
8925 | range->freq[i].e = 1; | ||
8926 | i++; | ||
8927 | } | ||
8928 | } | ||
8929 | |||
8930 | if (priv->ieee->mode & IEEE_A) { | ||
8931 | for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES; j++) { | ||
8932 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC) && | ||
8933 | (geo->a[j].flags & IEEE80211_CH_PASSIVE_ONLY)) | ||
8934 | continue; | ||
8935 | |||
8936 | range->freq[i].i = geo->a[j].channel; | ||
8937 | range->freq[i].m = geo->a[j].freq * 100000; | ||
8938 | range->freq[i].e = 1; | ||
8939 | i++; | ||
8940 | } | ||
8941 | } | ||
8942 | |||
8943 | range->num_channels = i; | ||
8944 | range->num_frequency = i; | ||
8945 | |||
8946 | mutex_unlock(&priv->mutex); | ||
8947 | |||
8948 | /* Event capability (kernel + driver) */ | ||
8949 | range->event_capa[0] = (IW_EVENT_CAPA_K_0 | | ||
8950 | IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) | | ||
8951 | IW_EVENT_CAPA_MASK(SIOCGIWAP) | | ||
8952 | IW_EVENT_CAPA_MASK(SIOCGIWSCAN)); | ||
8953 | range->event_capa[1] = IW_EVENT_CAPA_K_1; | ||
8954 | |||
8955 | range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 | | ||
8956 | IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP; | ||
8957 | |||
8958 | range->scan_capa = IW_SCAN_CAPA_ESSID | IW_SCAN_CAPA_TYPE; | ||
8959 | |||
8960 | IPW_DEBUG_WX("GET Range\n"); | ||
8961 | return 0; | ||
8962 | } | ||
8963 | |||
8964 | static int ipw_wx_set_wap(struct net_device *dev, | ||
8965 | struct iw_request_info *info, | ||
8966 | union iwreq_data *wrqu, char *extra) | ||
8967 | { | ||
8968 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
8969 | |||
8970 | static const unsigned char any[] = { | ||
8971 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff | ||
8972 | }; | ||
8973 | static const unsigned char off[] = { | ||
8974 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | ||
8975 | }; | ||
8976 | |||
8977 | if (wrqu->ap_addr.sa_family != ARPHRD_ETHER) | ||
8978 | return -EINVAL; | ||
8979 | mutex_lock(&priv->mutex); | ||
8980 | if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) || | ||
8981 | !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) { | ||
8982 | /* we disable mandatory BSSID association */ | ||
8983 | IPW_DEBUG_WX("Setting AP BSSID to ANY\n"); | ||
8984 | priv->config &= ~CFG_STATIC_BSSID; | ||
8985 | IPW_DEBUG_ASSOC("Attempting to associate with new " | ||
8986 | "parameters.\n"); | ||
8987 | ipw_associate(priv); | ||
8988 | mutex_unlock(&priv->mutex); | ||
8989 | return 0; | ||
8990 | } | ||
8991 | |||
8992 | priv->config |= CFG_STATIC_BSSID; | ||
8993 | if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) { | ||
8994 | IPW_DEBUG_WX("BSSID set to current BSSID.\n"); | ||
8995 | mutex_unlock(&priv->mutex); | ||
8996 | return 0; | ||
8997 | } | ||
8998 | |||
8999 | IPW_DEBUG_WX("Setting mandatory BSSID to %pM\n", | ||
9000 | wrqu->ap_addr.sa_data); | ||
9001 | |||
9002 | memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN); | ||
9003 | |||
9004 | /* Network configuration changed -- force [re]association */ | ||
9005 | IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n"); | ||
9006 | if (!ipw_disassociate(priv)) | ||
9007 | ipw_associate(priv); | ||
9008 | |||
9009 | mutex_unlock(&priv->mutex); | ||
9010 | return 0; | ||
9011 | } | ||
9012 | |||
9013 | static int ipw_wx_get_wap(struct net_device *dev, | ||
9014 | struct iw_request_info *info, | ||
9015 | union iwreq_data *wrqu, char *extra) | ||
9016 | { | ||
9017 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
9018 | |||
9019 | /* If we are associated, trying to associate, or have a statically | ||
9020 | * configured BSSID then return that; otherwise return ANY */ | ||
9021 | mutex_lock(&priv->mutex); | ||
9022 | if (priv->config & CFG_STATIC_BSSID || | ||
9023 | priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { | ||
9024 | wrqu->ap_addr.sa_family = ARPHRD_ETHER; | ||
9025 | memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN); | ||
9026 | } else | ||
9027 | memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN); | ||
9028 | |||
9029 | IPW_DEBUG_WX("Getting WAP BSSID: %pM\n", | ||
9030 | wrqu->ap_addr.sa_data); | ||
9031 | mutex_unlock(&priv->mutex); | ||
9032 | return 0; | ||
9033 | } | ||
9034 | |||
9035 | static int ipw_wx_set_essid(struct net_device *dev, | ||
9036 | struct iw_request_info *info, | ||
9037 | union iwreq_data *wrqu, char *extra) | ||
9038 | { | ||
9039 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
9040 | int length; | ||
9041 | DECLARE_SSID_BUF(ssid); | ||
9042 | |||
9043 | mutex_lock(&priv->mutex); | ||
9044 | |||
9045 | if (!wrqu->essid.flags) | ||
9046 | { | ||
9047 | IPW_DEBUG_WX("Setting ESSID to ANY\n"); | ||
9048 | ipw_disassociate(priv); | ||
9049 | priv->config &= ~CFG_STATIC_ESSID; | ||
9050 | ipw_associate(priv); | ||
9051 | mutex_unlock(&priv->mutex); | ||
9052 | return 0; | ||
9053 | } | ||
9054 | |||
9055 | length = min((int)wrqu->essid.length, IW_ESSID_MAX_SIZE); | ||
9056 | |||
9057 | priv->config |= CFG_STATIC_ESSID; | ||
9058 | |||
9059 | if (priv->essid_len == length && !memcmp(priv->essid, extra, length) | ||
9060 | && (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) { | ||
9061 | IPW_DEBUG_WX("ESSID set to current ESSID.\n"); | ||
9062 | mutex_unlock(&priv->mutex); | ||
9063 | return 0; | ||
9064 | } | ||
9065 | |||
9066 | IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", | ||
9067 | print_ssid(ssid, extra, length), length); | ||
9068 | |||
9069 | priv->essid_len = length; | ||
9070 | memcpy(priv->essid, extra, priv->essid_len); | ||
9071 | |||
9072 | /* Network configuration changed -- force [re]association */ | ||
9073 | IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n"); | ||
9074 | if (!ipw_disassociate(priv)) | ||
9075 | ipw_associate(priv); | ||
9076 | |||
9077 | mutex_unlock(&priv->mutex); | ||
9078 | return 0; | ||
9079 | } | ||
9080 | |||
9081 | static int ipw_wx_get_essid(struct net_device *dev, | ||
9082 | struct iw_request_info *info, | ||
9083 | union iwreq_data *wrqu, char *extra) | ||
9084 | { | ||
9085 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
9086 | DECLARE_SSID_BUF(ssid); | ||
9087 | |||
9088 | /* If we are associated, trying to associate, or have a statically | ||
9089 | * configured ESSID then return that; otherwise return ANY */ | ||
9090 | mutex_lock(&priv->mutex); | ||
9091 | if (priv->config & CFG_STATIC_ESSID || | ||
9092 | priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { | ||
9093 | IPW_DEBUG_WX("Getting essid: '%s'\n", | ||
9094 | print_ssid(ssid, priv->essid, priv->essid_len)); | ||
9095 | memcpy(extra, priv->essid, priv->essid_len); | ||
9096 | wrqu->essid.length = priv->essid_len; | ||
9097 | wrqu->essid.flags = 1; /* active */ | ||
9098 | } else { | ||
9099 | IPW_DEBUG_WX("Getting essid: ANY\n"); | ||
9100 | wrqu->essid.length = 0; | ||
9101 | wrqu->essid.flags = 0; /* active */ | ||
9102 | } | ||
9103 | mutex_unlock(&priv->mutex); | ||
9104 | return 0; | ||
9105 | } | ||
9106 | |||
9107 | static int ipw_wx_set_nick(struct net_device *dev, | ||
9108 | struct iw_request_info *info, | ||
9109 | union iwreq_data *wrqu, char *extra) | ||
9110 | { | ||
9111 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
9112 | |||
9113 | IPW_DEBUG_WX("Setting nick to '%s'\n", extra); | ||
9114 | if (wrqu->data.length > IW_ESSID_MAX_SIZE) | ||
9115 | return -E2BIG; | ||
9116 | mutex_lock(&priv->mutex); | ||
9117 | wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick)); | ||
9118 | memset(priv->nick, 0, sizeof(priv->nick)); | ||
9119 | memcpy(priv->nick, extra, wrqu->data.length); | ||
9120 | IPW_DEBUG_TRACE("<<\n"); | ||
9121 | mutex_unlock(&priv->mutex); | ||
9122 | return 0; | ||
9123 | |||
9124 | } | ||
9125 | |||
9126 | static int ipw_wx_get_nick(struct net_device *dev, | ||
9127 | struct iw_request_info *info, | ||
9128 | union iwreq_data *wrqu, char *extra) | ||
9129 | { | ||
9130 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
9131 | IPW_DEBUG_WX("Getting nick\n"); | ||
9132 | mutex_lock(&priv->mutex); | ||
9133 | wrqu->data.length = strlen(priv->nick); | ||
9134 | memcpy(extra, priv->nick, wrqu->data.length); | ||
9135 | wrqu->data.flags = 1; /* active */ | ||
9136 | mutex_unlock(&priv->mutex); | ||
9137 | return 0; | ||
9138 | } | ||
9139 | |||
9140 | static int ipw_wx_set_sens(struct net_device *dev, | ||
9141 | struct iw_request_info *info, | ||
9142 | union iwreq_data *wrqu, char *extra) | ||
9143 | { | ||
9144 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
9145 | int err = 0; | ||
9146 | |||
9147 | IPW_DEBUG_WX("Setting roaming threshold to %d\n", wrqu->sens.value); | ||
9148 | IPW_DEBUG_WX("Setting disassociate threshold to %d\n", 3*wrqu->sens.value); | ||
9149 | mutex_lock(&priv->mutex); | ||
9150 | |||
9151 | if (wrqu->sens.fixed == 0) | ||
9152 | { | ||
9153 | priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT; | ||
9154 | priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT; | ||
9155 | goto out; | ||
9156 | } | ||
9157 | if ((wrqu->sens.value > IPW_MB_ROAMING_THRESHOLD_MAX) || | ||
9158 | (wrqu->sens.value < IPW_MB_ROAMING_THRESHOLD_MIN)) { | ||
9159 | err = -EINVAL; | ||
9160 | goto out; | ||
9161 | } | ||
9162 | |||
9163 | priv->roaming_threshold = wrqu->sens.value; | ||
9164 | priv->disassociate_threshold = 3*wrqu->sens.value; | ||
9165 | out: | ||
9166 | mutex_unlock(&priv->mutex); | ||
9167 | return err; | ||
9168 | } | ||
9169 | |||
9170 | static int ipw_wx_get_sens(struct net_device *dev, | ||
9171 | struct iw_request_info *info, | ||
9172 | union iwreq_data *wrqu, char *extra) | ||
9173 | { | ||
9174 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
9175 | mutex_lock(&priv->mutex); | ||
9176 | wrqu->sens.fixed = 1; | ||
9177 | wrqu->sens.value = priv->roaming_threshold; | ||
9178 | mutex_unlock(&priv->mutex); | ||
9179 | |||
9180 | IPW_DEBUG_WX("GET roaming threshold -> %s %d \n", | ||
9181 | wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value); | ||
9182 | |||
9183 | return 0; | ||
9184 | } | ||
9185 | |||
9186 | static int ipw_wx_set_rate(struct net_device *dev, | ||
9187 | struct iw_request_info *info, | ||
9188 | union iwreq_data *wrqu, char *extra) | ||
9189 | { | ||
9190 | /* TODO: We should use semaphores or locks for access to priv */ | ||
9191 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
9192 | u32 target_rate = wrqu->bitrate.value; | ||
9193 | u32 fixed, mask; | ||
9194 | |||
9195 | /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */ | ||
9196 | /* value = X, fixed = 1 means only rate X */ | ||
9197 | /* value = X, fixed = 0 means all rates lower equal X */ | ||
9198 | |||
9199 | if (target_rate == -1) { | ||
9200 | fixed = 0; | ||
9201 | mask = IEEE80211_DEFAULT_RATES_MASK; | ||
9202 | /* Now we should reassociate */ | ||
9203 | goto apply; | ||
9204 | } | ||
9205 | |||
9206 | mask = 0; | ||
9207 | fixed = wrqu->bitrate.fixed; | ||
9208 | |||
9209 | if (target_rate == 1000000 || !fixed) | ||
9210 | mask |= IEEE80211_CCK_RATE_1MB_MASK; | ||
9211 | if (target_rate == 1000000) | ||
9212 | goto apply; | ||
9213 | |||
9214 | if (target_rate == 2000000 || !fixed) | ||
9215 | mask |= IEEE80211_CCK_RATE_2MB_MASK; | ||
9216 | if (target_rate == 2000000) | ||
9217 | goto apply; | ||
9218 | |||
9219 | if (target_rate == 5500000 || !fixed) | ||
9220 | mask |= IEEE80211_CCK_RATE_5MB_MASK; | ||
9221 | if (target_rate == 5500000) | ||
9222 | goto apply; | ||
9223 | |||
9224 | if (target_rate == 6000000 || !fixed) | ||
9225 | mask |= IEEE80211_OFDM_RATE_6MB_MASK; | ||
9226 | if (target_rate == 6000000) | ||
9227 | goto apply; | ||
9228 | |||
9229 | if (target_rate == 9000000 || !fixed) | ||
9230 | mask |= IEEE80211_OFDM_RATE_9MB_MASK; | ||
9231 | if (target_rate == 9000000) | ||
9232 | goto apply; | ||
9233 | |||
9234 | if (target_rate == 11000000 || !fixed) | ||
9235 | mask |= IEEE80211_CCK_RATE_11MB_MASK; | ||
9236 | if (target_rate == 11000000) | ||
9237 | goto apply; | ||
9238 | |||
9239 | if (target_rate == 12000000 || !fixed) | ||
9240 | mask |= IEEE80211_OFDM_RATE_12MB_MASK; | ||
9241 | if (target_rate == 12000000) | ||
9242 | goto apply; | ||
9243 | |||
9244 | if (target_rate == 18000000 || !fixed) | ||
9245 | mask |= IEEE80211_OFDM_RATE_18MB_MASK; | ||
9246 | if (target_rate == 18000000) | ||
9247 | goto apply; | ||
9248 | |||
9249 | if (target_rate == 24000000 || !fixed) | ||
9250 | mask |= IEEE80211_OFDM_RATE_24MB_MASK; | ||
9251 | if (target_rate == 24000000) | ||
9252 | goto apply; | ||
9253 | |||
9254 | if (target_rate == 36000000 || !fixed) | ||
9255 | mask |= IEEE80211_OFDM_RATE_36MB_MASK; | ||
9256 | if (target_rate == 36000000) | ||
9257 | goto apply; | ||
9258 | |||
9259 | if (target_rate == 48000000 || !fixed) | ||
9260 | mask |= IEEE80211_OFDM_RATE_48MB_MASK; | ||
9261 | if (target_rate == 48000000) | ||
9262 | goto apply; | ||
9263 | |||
9264 | if (target_rate == 54000000 || !fixed) | ||
9265 | mask |= IEEE80211_OFDM_RATE_54MB_MASK; | ||
9266 | if (target_rate == 54000000) | ||
9267 | goto apply; | ||
9268 | |||
9269 | IPW_DEBUG_WX("invalid rate specified, returning error\n"); | ||
9270 | return -EINVAL; | ||
9271 | |||
9272 | apply: | ||
9273 | IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n", | ||
9274 | mask, fixed ? "fixed" : "sub-rates"); | ||
9275 | mutex_lock(&priv->mutex); | ||
9276 | if (mask == IEEE80211_DEFAULT_RATES_MASK) { | ||
9277 | priv->config &= ~CFG_FIXED_RATE; | ||
9278 | ipw_set_fixed_rate(priv, priv->ieee->mode); | ||
9279 | } else | ||
9280 | priv->config |= CFG_FIXED_RATE; | ||
9281 | |||
9282 | if (priv->rates_mask == mask) { | ||
9283 | IPW_DEBUG_WX("Mask set to current mask.\n"); | ||
9284 | mutex_unlock(&priv->mutex); | ||
9285 | return 0; | ||
9286 | } | ||
9287 | |||
9288 | priv->rates_mask = mask; | ||
9289 | |||
9290 | /* Network configuration changed -- force [re]association */ | ||
9291 | IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n"); | ||
9292 | if (!ipw_disassociate(priv)) | ||
9293 | ipw_associate(priv); | ||
9294 | |||
9295 | mutex_unlock(&priv->mutex); | ||
9296 | return 0; | ||
9297 | } | ||
9298 | |||
9299 | static int ipw_wx_get_rate(struct net_device *dev, | ||
9300 | struct iw_request_info *info, | ||
9301 | union iwreq_data *wrqu, char *extra) | ||
9302 | { | ||
9303 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
9304 | mutex_lock(&priv->mutex); | ||
9305 | wrqu->bitrate.value = priv->last_rate; | ||
9306 | wrqu->bitrate.fixed = (priv->config & CFG_FIXED_RATE) ? 1 : 0; | ||
9307 | mutex_unlock(&priv->mutex); | ||
9308 | IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value); | ||
9309 | return 0; | ||
9310 | } | ||
9311 | |||
9312 | static int ipw_wx_set_rts(struct net_device *dev, | ||
9313 | struct iw_request_info *info, | ||
9314 | union iwreq_data *wrqu, char *extra) | ||
9315 | { | ||
9316 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
9317 | mutex_lock(&priv->mutex); | ||
9318 | if (wrqu->rts.disabled || !wrqu->rts.fixed) | ||
9319 | priv->rts_threshold = DEFAULT_RTS_THRESHOLD; | ||
9320 | else { | ||
9321 | if (wrqu->rts.value < MIN_RTS_THRESHOLD || | ||
9322 | wrqu->rts.value > MAX_RTS_THRESHOLD) { | ||
9323 | mutex_unlock(&priv->mutex); | ||
9324 | return -EINVAL; | ||
9325 | } | ||
9326 | priv->rts_threshold = wrqu->rts.value; | ||
9327 | } | ||
9328 | |||
9329 | ipw_send_rts_threshold(priv, priv->rts_threshold); | ||
9330 | mutex_unlock(&priv->mutex); | ||
9331 | IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold); | ||
9332 | return 0; | ||
9333 | } | ||
9334 | |||
9335 | static int ipw_wx_get_rts(struct net_device *dev, | ||
9336 | struct iw_request_info *info, | ||
9337 | union iwreq_data *wrqu, char *extra) | ||
9338 | { | ||
9339 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
9340 | mutex_lock(&priv->mutex); | ||
9341 | wrqu->rts.value = priv->rts_threshold; | ||
9342 | wrqu->rts.fixed = 0; /* no auto select */ | ||
9343 | wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD); | ||
9344 | mutex_unlock(&priv->mutex); | ||
9345 | IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value); | ||
9346 | return 0; | ||
9347 | } | ||
9348 | |||
9349 | static int ipw_wx_set_txpow(struct net_device *dev, | ||
9350 | struct iw_request_info *info, | ||
9351 | union iwreq_data *wrqu, char *extra) | ||
9352 | { | ||
9353 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
9354 | int err = 0; | ||
9355 | |||
9356 | mutex_lock(&priv->mutex); | ||
9357 | if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) { | ||
9358 | err = -EINPROGRESS; | ||
9359 | goto out; | ||
9360 | } | ||
9361 | |||
9362 | if (!wrqu->power.fixed) | ||
9363 | wrqu->power.value = IPW_TX_POWER_DEFAULT; | ||
9364 | |||
9365 | if (wrqu->power.flags != IW_TXPOW_DBM) { | ||
9366 | err = -EINVAL; | ||
9367 | goto out; | ||
9368 | } | ||
9369 | |||
9370 | if ((wrqu->power.value > IPW_TX_POWER_MAX) || | ||
9371 | (wrqu->power.value < IPW_TX_POWER_MIN)) { | ||
9372 | err = -EINVAL; | ||
9373 | goto out; | ||
9374 | } | ||
9375 | |||
9376 | priv->tx_power = wrqu->power.value; | ||
9377 | err = ipw_set_tx_power(priv); | ||
9378 | out: | ||
9379 | mutex_unlock(&priv->mutex); | ||
9380 | return err; | ||
9381 | } | ||
9382 | |||
9383 | static int ipw_wx_get_txpow(struct net_device *dev, | ||
9384 | struct iw_request_info *info, | ||
9385 | union iwreq_data *wrqu, char *extra) | ||
9386 | { | ||
9387 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
9388 | mutex_lock(&priv->mutex); | ||
9389 | wrqu->power.value = priv->tx_power; | ||
9390 | wrqu->power.fixed = 1; | ||
9391 | wrqu->power.flags = IW_TXPOW_DBM; | ||
9392 | wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0; | ||
9393 | mutex_unlock(&priv->mutex); | ||
9394 | |||
9395 | IPW_DEBUG_WX("GET TX Power -> %s %d \n", | ||
9396 | wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value); | ||
9397 | |||
9398 | return 0; | ||
9399 | } | ||
9400 | |||
9401 | static int ipw_wx_set_frag(struct net_device *dev, | ||
9402 | struct iw_request_info *info, | ||
9403 | union iwreq_data *wrqu, char *extra) | ||
9404 | { | ||
9405 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
9406 | mutex_lock(&priv->mutex); | ||
9407 | if (wrqu->frag.disabled || !wrqu->frag.fixed) | ||
9408 | priv->ieee->fts = DEFAULT_FTS; | ||
9409 | else { | ||
9410 | if (wrqu->frag.value < MIN_FRAG_THRESHOLD || | ||
9411 | wrqu->frag.value > MAX_FRAG_THRESHOLD) { | ||
9412 | mutex_unlock(&priv->mutex); | ||
9413 | return -EINVAL; | ||
9414 | } | ||
9415 | |||
9416 | priv->ieee->fts = wrqu->frag.value & ~0x1; | ||
9417 | } | ||
9418 | |||
9419 | ipw_send_frag_threshold(priv, wrqu->frag.value); | ||
9420 | mutex_unlock(&priv->mutex); | ||
9421 | IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value); | ||
9422 | return 0; | ||
9423 | } | ||
9424 | |||
9425 | static int ipw_wx_get_frag(struct net_device *dev, | ||
9426 | struct iw_request_info *info, | ||
9427 | union iwreq_data *wrqu, char *extra) | ||
9428 | { | ||
9429 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
9430 | mutex_lock(&priv->mutex); | ||
9431 | wrqu->frag.value = priv->ieee->fts; | ||
9432 | wrqu->frag.fixed = 0; /* no auto select */ | ||
9433 | wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS); | ||
9434 | mutex_unlock(&priv->mutex); | ||
9435 | IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value); | ||
9436 | |||
9437 | return 0; | ||
9438 | } | ||
9439 | |||
9440 | static int ipw_wx_set_retry(struct net_device *dev, | ||
9441 | struct iw_request_info *info, | ||
9442 | union iwreq_data *wrqu, char *extra) | ||
9443 | { | ||
9444 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
9445 | |||
9446 | if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled) | ||
9447 | return -EINVAL; | ||
9448 | |||
9449 | if (!(wrqu->retry.flags & IW_RETRY_LIMIT)) | ||
9450 | return 0; | ||
9451 | |||
9452 | if (wrqu->retry.value < 0 || wrqu->retry.value >= 255) | ||
9453 | return -EINVAL; | ||
9454 | |||
9455 | mutex_lock(&priv->mutex); | ||
9456 | if (wrqu->retry.flags & IW_RETRY_SHORT) | ||
9457 | priv->short_retry_limit = (u8) wrqu->retry.value; | ||
9458 | else if (wrqu->retry.flags & IW_RETRY_LONG) | ||
9459 | priv->long_retry_limit = (u8) wrqu->retry.value; | ||
9460 | else { | ||
9461 | priv->short_retry_limit = (u8) wrqu->retry.value; | ||
9462 | priv->long_retry_limit = (u8) wrqu->retry.value; | ||
9463 | } | ||
9464 | |||
9465 | ipw_send_retry_limit(priv, priv->short_retry_limit, | ||
9466 | priv->long_retry_limit); | ||
9467 | mutex_unlock(&priv->mutex); | ||
9468 | IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n", | ||
9469 | priv->short_retry_limit, priv->long_retry_limit); | ||
9470 | return 0; | ||
9471 | } | ||
9472 | |||
9473 | static int ipw_wx_get_retry(struct net_device *dev, | ||
9474 | struct iw_request_info *info, | ||
9475 | union iwreq_data *wrqu, char *extra) | ||
9476 | { | ||
9477 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
9478 | |||
9479 | mutex_lock(&priv->mutex); | ||
9480 | wrqu->retry.disabled = 0; | ||
9481 | |||
9482 | if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) { | ||
9483 | mutex_unlock(&priv->mutex); | ||
9484 | return -EINVAL; | ||
9485 | } | ||
9486 | |||
9487 | if (wrqu->retry.flags & IW_RETRY_LONG) { | ||
9488 | wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_LONG; | ||
9489 | wrqu->retry.value = priv->long_retry_limit; | ||
9490 | } else if (wrqu->retry.flags & IW_RETRY_SHORT) { | ||
9491 | wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_SHORT; | ||
9492 | wrqu->retry.value = priv->short_retry_limit; | ||
9493 | } else { | ||
9494 | wrqu->retry.flags = IW_RETRY_LIMIT; | ||
9495 | wrqu->retry.value = priv->short_retry_limit; | ||
9496 | } | ||
9497 | mutex_unlock(&priv->mutex); | ||
9498 | |||
9499 | IPW_DEBUG_WX("GET retry -> %d \n", wrqu->retry.value); | ||
9500 | |||
9501 | return 0; | ||
9502 | } | ||
9503 | |||
9504 | static int ipw_wx_set_scan(struct net_device *dev, | ||
9505 | struct iw_request_info *info, | ||
9506 | union iwreq_data *wrqu, char *extra) | ||
9507 | { | ||
9508 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
9509 | struct iw_scan_req *req = (struct iw_scan_req *)extra; | ||
9510 | struct delayed_work *work = NULL; | ||
9511 | |||
9512 | mutex_lock(&priv->mutex); | ||
9513 | |||
9514 | priv->user_requested_scan = 1; | ||
9515 | |||
9516 | if (wrqu->data.length == sizeof(struct iw_scan_req)) { | ||
9517 | if (wrqu->data.flags & IW_SCAN_THIS_ESSID) { | ||
9518 | int len = min((int)req->essid_len, | ||
9519 | (int)sizeof(priv->direct_scan_ssid)); | ||
9520 | memcpy(priv->direct_scan_ssid, req->essid, len); | ||
9521 | priv->direct_scan_ssid_len = len; | ||
9522 | work = &priv->request_direct_scan; | ||
9523 | } else if (req->scan_type == IW_SCAN_TYPE_PASSIVE) { | ||
9524 | work = &priv->request_passive_scan; | ||
9525 | } | ||
9526 | } else { | ||
9527 | /* Normal active broadcast scan */ | ||
9528 | work = &priv->request_scan; | ||
9529 | } | ||
9530 | |||
9531 | mutex_unlock(&priv->mutex); | ||
9532 | |||
9533 | IPW_DEBUG_WX("Start scan\n"); | ||
9534 | |||
9535 | queue_delayed_work(priv->workqueue, work, 0); | ||
9536 | |||
9537 | return 0; | ||
9538 | } | ||
9539 | |||
9540 | static int ipw_wx_get_scan(struct net_device *dev, | ||
9541 | struct iw_request_info *info, | ||
9542 | union iwreq_data *wrqu, char *extra) | ||
9543 | { | ||
9544 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
9545 | return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra); | ||
9546 | } | ||
9547 | |||
9548 | static int ipw_wx_set_encode(struct net_device *dev, | ||
9549 | struct iw_request_info *info, | ||
9550 | union iwreq_data *wrqu, char *key) | ||
9551 | { | ||
9552 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
9553 | int ret; | ||
9554 | u32 cap = priv->capability; | ||
9555 | |||
9556 | mutex_lock(&priv->mutex); | ||
9557 | ret = ieee80211_wx_set_encode(priv->ieee, info, wrqu, key); | ||
9558 | |||
9559 | /* In IBSS mode, we need to notify the firmware to update | ||
9560 | * the beacon info after we changed the capability. */ | ||
9561 | if (cap != priv->capability && | ||
9562 | priv->ieee->iw_mode == IW_MODE_ADHOC && | ||
9563 | priv->status & STATUS_ASSOCIATED) | ||
9564 | ipw_disassociate(priv); | ||
9565 | |||
9566 | mutex_unlock(&priv->mutex); | ||
9567 | return ret; | ||
9568 | } | ||
9569 | |||
9570 | static int ipw_wx_get_encode(struct net_device *dev, | ||
9571 | struct iw_request_info *info, | ||
9572 | union iwreq_data *wrqu, char *key) | ||
9573 | { | ||
9574 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
9575 | return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key); | ||
9576 | } | ||
9577 | |||
9578 | static int ipw_wx_set_power(struct net_device *dev, | ||
9579 | struct iw_request_info *info, | ||
9580 | union iwreq_data *wrqu, char *extra) | ||
9581 | { | ||
9582 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
9583 | int err; | ||
9584 | mutex_lock(&priv->mutex); | ||
9585 | if (wrqu->power.disabled) { | ||
9586 | priv->power_mode = IPW_POWER_LEVEL(priv->power_mode); | ||
9587 | err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM); | ||
9588 | if (err) { | ||
9589 | IPW_DEBUG_WX("failed setting power mode.\n"); | ||
9590 | mutex_unlock(&priv->mutex); | ||
9591 | return err; | ||
9592 | } | ||
9593 | IPW_DEBUG_WX("SET Power Management Mode -> off\n"); | ||
9594 | mutex_unlock(&priv->mutex); | ||
9595 | return 0; | ||
9596 | } | ||
9597 | |||
9598 | switch (wrqu->power.flags & IW_POWER_MODE) { | ||
9599 | case IW_POWER_ON: /* If not specified */ | ||
9600 | case IW_POWER_MODE: /* If set all mask */ | ||
9601 | case IW_POWER_ALL_R: /* If explicitly state all */ | ||
9602 | break; | ||
9603 | default: /* Otherwise we don't support it */ | ||
9604 | IPW_DEBUG_WX("SET PM Mode: %X not supported.\n", | ||
9605 | wrqu->power.flags); | ||
9606 | mutex_unlock(&priv->mutex); | ||
9607 | return -EOPNOTSUPP; | ||
9608 | } | ||
9609 | |||
9610 | /* If the user hasn't specified a power management mode yet, default | ||
9611 | * to BATTERY */ | ||
9612 | if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC) | ||
9613 | priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY; | ||
9614 | else | ||
9615 | priv->power_mode = IPW_POWER_ENABLED | priv->power_mode; | ||
9616 | |||
9617 | err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode)); | ||
9618 | if (err) { | ||
9619 | IPW_DEBUG_WX("failed setting power mode.\n"); | ||
9620 | mutex_unlock(&priv->mutex); | ||
9621 | return err; | ||
9622 | } | ||
9623 | |||
9624 | IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode); | ||
9625 | mutex_unlock(&priv->mutex); | ||
9626 | return 0; | ||
9627 | } | ||
9628 | |||
9629 | static int ipw_wx_get_power(struct net_device *dev, | ||
9630 | struct iw_request_info *info, | ||
9631 | union iwreq_data *wrqu, char *extra) | ||
9632 | { | ||
9633 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
9634 | mutex_lock(&priv->mutex); | ||
9635 | if (!(priv->power_mode & IPW_POWER_ENABLED)) | ||
9636 | wrqu->power.disabled = 1; | ||
9637 | else | ||
9638 | wrqu->power.disabled = 0; | ||
9639 | |||
9640 | mutex_unlock(&priv->mutex); | ||
9641 | IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode); | ||
9642 | |||
9643 | return 0; | ||
9644 | } | ||
9645 | |||
9646 | static int ipw_wx_set_powermode(struct net_device *dev, | ||
9647 | struct iw_request_info *info, | ||
9648 | union iwreq_data *wrqu, char *extra) | ||
9649 | { | ||
9650 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
9651 | int mode = *(int *)extra; | ||
9652 | int err; | ||
9653 | |||
9654 | mutex_lock(&priv->mutex); | ||
9655 | if ((mode < 1) || (mode > IPW_POWER_LIMIT)) | ||
9656 | mode = IPW_POWER_AC; | ||
9657 | |||
9658 | if (IPW_POWER_LEVEL(priv->power_mode) != mode) { | ||
9659 | err = ipw_send_power_mode(priv, mode); | ||
9660 | if (err) { | ||
9661 | IPW_DEBUG_WX("failed setting power mode.\n"); | ||
9662 | mutex_unlock(&priv->mutex); | ||
9663 | return err; | ||
9664 | } | ||
9665 | priv->power_mode = IPW_POWER_ENABLED | mode; | ||
9666 | } | ||
9667 | mutex_unlock(&priv->mutex); | ||
9668 | return 0; | ||
9669 | } | ||
9670 | |||
9671 | #define MAX_WX_STRING 80 | ||
9672 | static int ipw_wx_get_powermode(struct net_device *dev, | ||
9673 | struct iw_request_info *info, | ||
9674 | union iwreq_data *wrqu, char *extra) | ||
9675 | { | ||
9676 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
9677 | int level = IPW_POWER_LEVEL(priv->power_mode); | ||
9678 | char *p = extra; | ||
9679 | |||
9680 | p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level); | ||
9681 | |||
9682 | switch (level) { | ||
9683 | case IPW_POWER_AC: | ||
9684 | p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)"); | ||
9685 | break; | ||
9686 | case IPW_POWER_BATTERY: | ||
9687 | p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)"); | ||
9688 | break; | ||
9689 | default: | ||
9690 | p += snprintf(p, MAX_WX_STRING - (p - extra), | ||
9691 | "(Timeout %dms, Period %dms)", | ||
9692 | timeout_duration[level - 1] / 1000, | ||
9693 | period_duration[level - 1] / 1000); | ||
9694 | } | ||
9695 | |||
9696 | if (!(priv->power_mode & IPW_POWER_ENABLED)) | ||
9697 | p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF"); | ||
9698 | |||
9699 | wrqu->data.length = p - extra + 1; | ||
9700 | |||
9701 | return 0; | ||
9702 | } | ||
9703 | |||
9704 | static int ipw_wx_set_wireless_mode(struct net_device *dev, | ||
9705 | struct iw_request_info *info, | ||
9706 | union iwreq_data *wrqu, char *extra) | ||
9707 | { | ||
9708 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
9709 | int mode = *(int *)extra; | ||
9710 | u8 band = 0, modulation = 0; | ||
9711 | |||
9712 | if (mode == 0 || mode & ~IEEE_MODE_MASK) { | ||
9713 | IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode); | ||
9714 | return -EINVAL; | ||
9715 | } | ||
9716 | mutex_lock(&priv->mutex); | ||
9717 | if (priv->adapter == IPW_2915ABG) { | ||
9718 | priv->ieee->abg_true = 1; | ||
9719 | if (mode & IEEE_A) { | ||
9720 | band |= IEEE80211_52GHZ_BAND; | ||
9721 | modulation |= IEEE80211_OFDM_MODULATION; | ||
9722 | } else | ||
9723 | priv->ieee->abg_true = 0; | ||
9724 | } else { | ||
9725 | if (mode & IEEE_A) { | ||
9726 | IPW_WARNING("Attempt to set 2200BG into " | ||
9727 | "802.11a mode\n"); | ||
9728 | mutex_unlock(&priv->mutex); | ||
9729 | return -EINVAL; | ||
9730 | } | ||
9731 | |||
9732 | priv->ieee->abg_true = 0; | ||
9733 | } | ||
9734 | |||
9735 | if (mode & IEEE_B) { | ||
9736 | band |= IEEE80211_24GHZ_BAND; | ||
9737 | modulation |= IEEE80211_CCK_MODULATION; | ||
9738 | } else | ||
9739 | priv->ieee->abg_true = 0; | ||
9740 | |||
9741 | if (mode & IEEE_G) { | ||
9742 | band |= IEEE80211_24GHZ_BAND; | ||
9743 | modulation |= IEEE80211_OFDM_MODULATION; | ||
9744 | } else | ||
9745 | priv->ieee->abg_true = 0; | ||
9746 | |||
9747 | priv->ieee->mode = mode; | ||
9748 | priv->ieee->freq_band = band; | ||
9749 | priv->ieee->modulation = modulation; | ||
9750 | init_supported_rates(priv, &priv->rates); | ||
9751 | |||
9752 | /* Network configuration changed -- force [re]association */ | ||
9753 | IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n"); | ||
9754 | if (!ipw_disassociate(priv)) { | ||
9755 | ipw_send_supported_rates(priv, &priv->rates); | ||
9756 | ipw_associate(priv); | ||
9757 | } | ||
9758 | |||
9759 | /* Update the band LEDs */ | ||
9760 | ipw_led_band_on(priv); | ||
9761 | |||
9762 | IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n", | ||
9763 | mode & IEEE_A ? 'a' : '.', | ||
9764 | mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.'); | ||
9765 | mutex_unlock(&priv->mutex); | ||
9766 | return 0; | ||
9767 | } | ||
9768 | |||
9769 | static int ipw_wx_get_wireless_mode(struct net_device *dev, | ||
9770 | struct iw_request_info *info, | ||
9771 | union iwreq_data *wrqu, char *extra) | ||
9772 | { | ||
9773 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
9774 | mutex_lock(&priv->mutex); | ||
9775 | switch (priv->ieee->mode) { | ||
9776 | case IEEE_A: | ||
9777 | strncpy(extra, "802.11a (1)", MAX_WX_STRING); | ||
9778 | break; | ||
9779 | case IEEE_B: | ||
9780 | strncpy(extra, "802.11b (2)", MAX_WX_STRING); | ||
9781 | break; | ||
9782 | case IEEE_A | IEEE_B: | ||
9783 | strncpy(extra, "802.11ab (3)", MAX_WX_STRING); | ||
9784 | break; | ||
9785 | case IEEE_G: | ||
9786 | strncpy(extra, "802.11g (4)", MAX_WX_STRING); | ||
9787 | break; | ||
9788 | case IEEE_A | IEEE_G: | ||
9789 | strncpy(extra, "802.11ag (5)", MAX_WX_STRING); | ||
9790 | break; | ||
9791 | case IEEE_B | IEEE_G: | ||
9792 | strncpy(extra, "802.11bg (6)", MAX_WX_STRING); | ||
9793 | break; | ||
9794 | case IEEE_A | IEEE_B | IEEE_G: | ||
9795 | strncpy(extra, "802.11abg (7)", MAX_WX_STRING); | ||
9796 | break; | ||
9797 | default: | ||
9798 | strncpy(extra, "unknown", MAX_WX_STRING); | ||
9799 | break; | ||
9800 | } | ||
9801 | |||
9802 | IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra); | ||
9803 | |||
9804 | wrqu->data.length = strlen(extra) + 1; | ||
9805 | mutex_unlock(&priv->mutex); | ||
9806 | |||
9807 | return 0; | ||
9808 | } | ||
9809 | |||
9810 | static int ipw_wx_set_preamble(struct net_device *dev, | ||
9811 | struct iw_request_info *info, | ||
9812 | union iwreq_data *wrqu, char *extra) | ||
9813 | { | ||
9814 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
9815 | int mode = *(int *)extra; | ||
9816 | mutex_lock(&priv->mutex); | ||
9817 | /* Switching from SHORT -> LONG requires a disassociation */ | ||
9818 | if (mode == 1) { | ||
9819 | if (!(priv->config & CFG_PREAMBLE_LONG)) { | ||
9820 | priv->config |= CFG_PREAMBLE_LONG; | ||
9821 | |||
9822 | /* Network configuration changed -- force [re]association */ | ||
9823 | IPW_DEBUG_ASSOC | ||
9824 | ("[re]association triggered due to preamble change.\n"); | ||
9825 | if (!ipw_disassociate(priv)) | ||
9826 | ipw_associate(priv); | ||
9827 | } | ||
9828 | goto done; | ||
9829 | } | ||
9830 | |||
9831 | if (mode == 0) { | ||
9832 | priv->config &= ~CFG_PREAMBLE_LONG; | ||
9833 | goto done; | ||
9834 | } | ||
9835 | mutex_unlock(&priv->mutex); | ||
9836 | return -EINVAL; | ||
9837 | |||
9838 | done: | ||
9839 | mutex_unlock(&priv->mutex); | ||
9840 | return 0; | ||
9841 | } | ||
9842 | |||
9843 | static int ipw_wx_get_preamble(struct net_device *dev, | ||
9844 | struct iw_request_info *info, | ||
9845 | union iwreq_data *wrqu, char *extra) | ||
9846 | { | ||
9847 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
9848 | mutex_lock(&priv->mutex); | ||
9849 | if (priv->config & CFG_PREAMBLE_LONG) | ||
9850 | snprintf(wrqu->name, IFNAMSIZ, "long (1)"); | ||
9851 | else | ||
9852 | snprintf(wrqu->name, IFNAMSIZ, "auto (0)"); | ||
9853 | mutex_unlock(&priv->mutex); | ||
9854 | return 0; | ||
9855 | } | ||
9856 | |||
9857 | #ifdef CONFIG_IPW2200_MONITOR | ||
9858 | static int ipw_wx_set_monitor(struct net_device *dev, | ||
9859 | struct iw_request_info *info, | ||
9860 | union iwreq_data *wrqu, char *extra) | ||
9861 | { | ||
9862 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
9863 | int *parms = (int *)extra; | ||
9864 | int enable = (parms[0] > 0); | ||
9865 | mutex_lock(&priv->mutex); | ||
9866 | IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]); | ||
9867 | if (enable) { | ||
9868 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { | ||
9869 | #ifdef CONFIG_IPW2200_RADIOTAP | ||
9870 | priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; | ||
9871 | #else | ||
9872 | priv->net_dev->type = ARPHRD_IEEE80211; | ||
9873 | #endif | ||
9874 | queue_work(priv->workqueue, &priv->adapter_restart); | ||
9875 | } | ||
9876 | |||
9877 | ipw_set_channel(priv, parms[1]); | ||
9878 | } else { | ||
9879 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { | ||
9880 | mutex_unlock(&priv->mutex); | ||
9881 | return 0; | ||
9882 | } | ||
9883 | priv->net_dev->type = ARPHRD_ETHER; | ||
9884 | queue_work(priv->workqueue, &priv->adapter_restart); | ||
9885 | } | ||
9886 | mutex_unlock(&priv->mutex); | ||
9887 | return 0; | ||
9888 | } | ||
9889 | |||
9890 | #endif /* CONFIG_IPW2200_MONITOR */ | ||
9891 | |||
9892 | static int ipw_wx_reset(struct net_device *dev, | ||
9893 | struct iw_request_info *info, | ||
9894 | union iwreq_data *wrqu, char *extra) | ||
9895 | { | ||
9896 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
9897 | IPW_DEBUG_WX("RESET\n"); | ||
9898 | queue_work(priv->workqueue, &priv->adapter_restart); | ||
9899 | return 0; | ||
9900 | } | ||
9901 | |||
9902 | static int ipw_wx_sw_reset(struct net_device *dev, | ||
9903 | struct iw_request_info *info, | ||
9904 | union iwreq_data *wrqu, char *extra) | ||
9905 | { | ||
9906 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
9907 | union iwreq_data wrqu_sec = { | ||
9908 | .encoding = { | ||
9909 | .flags = IW_ENCODE_DISABLED, | ||
9910 | }, | ||
9911 | }; | ||
9912 | int ret; | ||
9913 | |||
9914 | IPW_DEBUG_WX("SW_RESET\n"); | ||
9915 | |||
9916 | mutex_lock(&priv->mutex); | ||
9917 | |||
9918 | ret = ipw_sw_reset(priv, 2); | ||
9919 | if (!ret) { | ||
9920 | free_firmware(); | ||
9921 | ipw_adapter_restart(priv); | ||
9922 | } | ||
9923 | |||
9924 | /* The SW reset bit might have been toggled on by the 'disable' | ||
9925 | * module parameter, so take appropriate action */ | ||
9926 | ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW); | ||
9927 | |||
9928 | mutex_unlock(&priv->mutex); | ||
9929 | ieee80211_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL); | ||
9930 | mutex_lock(&priv->mutex); | ||
9931 | |||
9932 | if (!(priv->status & STATUS_RF_KILL_MASK)) { | ||
9933 | /* Configuration likely changed -- force [re]association */ | ||
9934 | IPW_DEBUG_ASSOC("[re]association triggered due to sw " | ||
9935 | "reset.\n"); | ||
9936 | if (!ipw_disassociate(priv)) | ||
9937 | ipw_associate(priv); | ||
9938 | } | ||
9939 | |||
9940 | mutex_unlock(&priv->mutex); | ||
9941 | |||
9942 | return 0; | ||
9943 | } | ||
9944 | |||
9945 | /* Rebase the WE IOCTLs to zero for the handler array */ | ||
9946 | #define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT] | ||
9947 | static iw_handler ipw_wx_handlers[] = { | ||
9948 | IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name, | ||
9949 | IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq, | ||
9950 | IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq, | ||
9951 | IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode, | ||
9952 | IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode, | ||
9953 | IW_IOCTL(SIOCSIWSENS) = ipw_wx_set_sens, | ||
9954 | IW_IOCTL(SIOCGIWSENS) = ipw_wx_get_sens, | ||
9955 | IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range, | ||
9956 | IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap, | ||
9957 | IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap, | ||
9958 | IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan, | ||
9959 | IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan, | ||
9960 | IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid, | ||
9961 | IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid, | ||
9962 | IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick, | ||
9963 | IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick, | ||
9964 | IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate, | ||
9965 | IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate, | ||
9966 | IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts, | ||
9967 | IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts, | ||
9968 | IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag, | ||
9969 | IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag, | ||
9970 | IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow, | ||
9971 | IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow, | ||
9972 | IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry, | ||
9973 | IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry, | ||
9974 | IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode, | ||
9975 | IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode, | ||
9976 | IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power, | ||
9977 | IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power, | ||
9978 | IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy, | ||
9979 | IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy, | ||
9980 | IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy, | ||
9981 | IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy, | ||
9982 | IW_IOCTL(SIOCSIWGENIE) = ipw_wx_set_genie, | ||
9983 | IW_IOCTL(SIOCGIWGENIE) = ipw_wx_get_genie, | ||
9984 | IW_IOCTL(SIOCSIWMLME) = ipw_wx_set_mlme, | ||
9985 | IW_IOCTL(SIOCSIWAUTH) = ipw_wx_set_auth, | ||
9986 | IW_IOCTL(SIOCGIWAUTH) = ipw_wx_get_auth, | ||
9987 | IW_IOCTL(SIOCSIWENCODEEXT) = ipw_wx_set_encodeext, | ||
9988 | IW_IOCTL(SIOCGIWENCODEEXT) = ipw_wx_get_encodeext, | ||
9989 | }; | ||
9990 | |||
9991 | enum { | ||
9992 | IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV, | ||
9993 | IPW_PRIV_GET_POWER, | ||
9994 | IPW_PRIV_SET_MODE, | ||
9995 | IPW_PRIV_GET_MODE, | ||
9996 | IPW_PRIV_SET_PREAMBLE, | ||
9997 | IPW_PRIV_GET_PREAMBLE, | ||
9998 | IPW_PRIV_RESET, | ||
9999 | IPW_PRIV_SW_RESET, | ||
10000 | #ifdef CONFIG_IPW2200_MONITOR | ||
10001 | IPW_PRIV_SET_MONITOR, | ||
10002 | #endif | ||
10003 | }; | ||
10004 | |||
10005 | static struct iw_priv_args ipw_priv_args[] = { | ||
10006 | { | ||
10007 | .cmd = IPW_PRIV_SET_POWER, | ||
10008 | .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | ||
10009 | .name = "set_power"}, | ||
10010 | { | ||
10011 | .cmd = IPW_PRIV_GET_POWER, | ||
10012 | .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING, | ||
10013 | .name = "get_power"}, | ||
10014 | { | ||
10015 | .cmd = IPW_PRIV_SET_MODE, | ||
10016 | .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | ||
10017 | .name = "set_mode"}, | ||
10018 | { | ||
10019 | .cmd = IPW_PRIV_GET_MODE, | ||
10020 | .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING, | ||
10021 | .name = "get_mode"}, | ||
10022 | { | ||
10023 | .cmd = IPW_PRIV_SET_PREAMBLE, | ||
10024 | .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | ||
10025 | .name = "set_preamble"}, | ||
10026 | { | ||
10027 | .cmd = IPW_PRIV_GET_PREAMBLE, | ||
10028 | .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, | ||
10029 | .name = "get_preamble"}, | ||
10030 | { | ||
10031 | IPW_PRIV_RESET, | ||
10032 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"}, | ||
10033 | { | ||
10034 | IPW_PRIV_SW_RESET, | ||
10035 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"}, | ||
10036 | #ifdef CONFIG_IPW2200_MONITOR | ||
10037 | { | ||
10038 | IPW_PRIV_SET_MONITOR, | ||
10039 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"}, | ||
10040 | #endif /* CONFIG_IPW2200_MONITOR */ | ||
10041 | }; | ||
10042 | |||
10043 | static iw_handler ipw_priv_handler[] = { | ||
10044 | ipw_wx_set_powermode, | ||
10045 | ipw_wx_get_powermode, | ||
10046 | ipw_wx_set_wireless_mode, | ||
10047 | ipw_wx_get_wireless_mode, | ||
10048 | ipw_wx_set_preamble, | ||
10049 | ipw_wx_get_preamble, | ||
10050 | ipw_wx_reset, | ||
10051 | ipw_wx_sw_reset, | ||
10052 | #ifdef CONFIG_IPW2200_MONITOR | ||
10053 | ipw_wx_set_monitor, | ||
10054 | #endif | ||
10055 | }; | ||
10056 | |||
10057 | static struct iw_handler_def ipw_wx_handler_def = { | ||
10058 | .standard = ipw_wx_handlers, | ||
10059 | .num_standard = ARRAY_SIZE(ipw_wx_handlers), | ||
10060 | .num_private = ARRAY_SIZE(ipw_priv_handler), | ||
10061 | .num_private_args = ARRAY_SIZE(ipw_priv_args), | ||
10062 | .private = ipw_priv_handler, | ||
10063 | .private_args = ipw_priv_args, | ||
10064 | .get_wireless_stats = ipw_get_wireless_stats, | ||
10065 | }; | ||
10066 | |||
10067 | /* | ||
10068 | * Get wireless statistics. | ||
10069 | * Called by /proc/net/wireless | ||
10070 | * Also called by SIOCGIWSTATS | ||
10071 | */ | ||
10072 | static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev) | ||
10073 | { | ||
10074 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
10075 | struct iw_statistics *wstats; | ||
10076 | |||
10077 | wstats = &priv->wstats; | ||
10078 | |||
10079 | /* if hw is disabled, then ipw_get_ordinal() can't be called. | ||
10080 | * netdev->get_wireless_stats seems to be called before fw is | ||
10081 | * initialized. STATUS_ASSOCIATED will only be set if the hw is up | ||
10082 | * and associated; if not associcated, the values are all meaningless | ||
10083 | * anyway, so set them all to NULL and INVALID */ | ||
10084 | if (!(priv->status & STATUS_ASSOCIATED)) { | ||
10085 | wstats->miss.beacon = 0; | ||
10086 | wstats->discard.retries = 0; | ||
10087 | wstats->qual.qual = 0; | ||
10088 | wstats->qual.level = 0; | ||
10089 | wstats->qual.noise = 0; | ||
10090 | wstats->qual.updated = 7; | ||
10091 | wstats->qual.updated |= IW_QUAL_NOISE_INVALID | | ||
10092 | IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID; | ||
10093 | return wstats; | ||
10094 | } | ||
10095 | |||
10096 | wstats->qual.qual = priv->quality; | ||
10097 | wstats->qual.level = priv->exp_avg_rssi; | ||
10098 | wstats->qual.noise = priv->exp_avg_noise; | ||
10099 | wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED | | ||
10100 | IW_QUAL_NOISE_UPDATED | IW_QUAL_DBM; | ||
10101 | |||
10102 | wstats->miss.beacon = average_value(&priv->average_missed_beacons); | ||
10103 | wstats->discard.retries = priv->last_tx_failures; | ||
10104 | wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable; | ||
10105 | |||
10106 | /* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len)) | ||
10107 | goto fail_get_ordinal; | ||
10108 | wstats->discard.retries += tx_retry; */ | ||
10109 | |||
10110 | return wstats; | ||
10111 | } | ||
10112 | |||
10113 | /* net device stuff */ | ||
10114 | |||
10115 | static void init_sys_config(struct ipw_sys_config *sys_config) | ||
10116 | { | ||
10117 | memset(sys_config, 0, sizeof(struct ipw_sys_config)); | ||
10118 | sys_config->bt_coexistence = 0; | ||
10119 | sys_config->answer_broadcast_ssid_probe = 0; | ||
10120 | sys_config->accept_all_data_frames = 0; | ||
10121 | sys_config->accept_non_directed_frames = 1; | ||
10122 | sys_config->exclude_unicast_unencrypted = 0; | ||
10123 | sys_config->disable_unicast_decryption = 1; | ||
10124 | sys_config->exclude_multicast_unencrypted = 0; | ||
10125 | sys_config->disable_multicast_decryption = 1; | ||
10126 | if (antenna < CFG_SYS_ANTENNA_BOTH || antenna > CFG_SYS_ANTENNA_B) | ||
10127 | antenna = CFG_SYS_ANTENNA_BOTH; | ||
10128 | sys_config->antenna_diversity = antenna; | ||
10129 | sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */ | ||
10130 | sys_config->dot11g_auto_detection = 0; | ||
10131 | sys_config->enable_cts_to_self = 0; | ||
10132 | sys_config->bt_coexist_collision_thr = 0; | ||
10133 | sys_config->pass_noise_stats_to_host = 1; /* 1 -- fix for 256 */ | ||
10134 | sys_config->silence_threshold = 0x1e; | ||
10135 | } | ||
10136 | |||
10137 | static int ipw_net_open(struct net_device *dev) | ||
10138 | { | ||
10139 | IPW_DEBUG_INFO("dev->open\n"); | ||
10140 | netif_start_queue(dev); | ||
10141 | return 0; | ||
10142 | } | ||
10143 | |||
10144 | static int ipw_net_stop(struct net_device *dev) | ||
10145 | { | ||
10146 | IPW_DEBUG_INFO("dev->close\n"); | ||
10147 | netif_stop_queue(dev); | ||
10148 | return 0; | ||
10149 | } | ||
10150 | |||
10151 | /* | ||
10152 | todo: | ||
10153 | |||
10154 | modify to send one tfd per fragment instead of using chunking. otherwise | ||
10155 | we need to heavily modify the ieee80211_skb_to_txb. | ||
10156 | */ | ||
10157 | |||
10158 | static int ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb, | ||
10159 | int pri) | ||
10160 | { | ||
10161 | struct ieee80211_hdr_3addrqos *hdr = (struct ieee80211_hdr_3addrqos *) | ||
10162 | txb->fragments[0]->data; | ||
10163 | int i = 0; | ||
10164 | struct tfd_frame *tfd; | ||
10165 | #ifdef CONFIG_IPW2200_QOS | ||
10166 | int tx_id = ipw_get_tx_queue_number(priv, pri); | ||
10167 | struct clx2_tx_queue *txq = &priv->txq[tx_id]; | ||
10168 | #else | ||
10169 | struct clx2_tx_queue *txq = &priv->txq[0]; | ||
10170 | #endif | ||
10171 | struct clx2_queue *q = &txq->q; | ||
10172 | u8 id, hdr_len, unicast; | ||
10173 | u16 remaining_bytes; | ||
10174 | int fc; | ||
10175 | |||
10176 | hdr_len = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl)); | ||
10177 | switch (priv->ieee->iw_mode) { | ||
10178 | case IW_MODE_ADHOC: | ||
10179 | unicast = !is_multicast_ether_addr(hdr->addr1); | ||
10180 | id = ipw_find_station(priv, hdr->addr1); | ||
10181 | if (id == IPW_INVALID_STATION) { | ||
10182 | id = ipw_add_station(priv, hdr->addr1); | ||
10183 | if (id == IPW_INVALID_STATION) { | ||
10184 | IPW_WARNING("Attempt to send data to " | ||
10185 | "invalid cell: %pM\n", | ||
10186 | hdr->addr1); | ||
10187 | goto drop; | ||
10188 | } | ||
10189 | } | ||
10190 | break; | ||
10191 | |||
10192 | case IW_MODE_INFRA: | ||
10193 | default: | ||
10194 | unicast = !is_multicast_ether_addr(hdr->addr3); | ||
10195 | id = 0; | ||
10196 | break; | ||
10197 | } | ||
10198 | |||
10199 | tfd = &txq->bd[q->first_empty]; | ||
10200 | txq->txb[q->first_empty] = txb; | ||
10201 | memset(tfd, 0, sizeof(*tfd)); | ||
10202 | tfd->u.data.station_number = id; | ||
10203 | |||
10204 | tfd->control_flags.message_type = TX_FRAME_TYPE; | ||
10205 | tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK; | ||
10206 | |||
10207 | tfd->u.data.cmd_id = DINO_CMD_TX; | ||
10208 | tfd->u.data.len = cpu_to_le16(txb->payload_size); | ||
10209 | remaining_bytes = txb->payload_size; | ||
10210 | |||
10211 | if (priv->assoc_request.ieee_mode == IPW_B_MODE) | ||
10212 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK; | ||
10213 | else | ||
10214 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM; | ||
10215 | |||
10216 | if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE) | ||
10217 | tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE; | ||
10218 | |||
10219 | fc = le16_to_cpu(hdr->frame_ctl); | ||
10220 | hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS); | ||
10221 | |||
10222 | memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len); | ||
10223 | |||
10224 | if (likely(unicast)) | ||
10225 | tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD; | ||
10226 | |||
10227 | if (txb->encrypted && !priv->ieee->host_encrypt) { | ||
10228 | switch (priv->ieee->sec.level) { | ||
10229 | case SEC_LEVEL_3: | ||
10230 | tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= | ||
10231 | cpu_to_le16(IEEE80211_FCTL_PROTECTED); | ||
10232 | /* XXX: ACK flag must be set for CCMP even if it | ||
10233 | * is a multicast/broadcast packet, because CCMP | ||
10234 | * group communication encrypted by GTK is | ||
10235 | * actually done by the AP. */ | ||
10236 | if (!unicast) | ||
10237 | tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD; | ||
10238 | |||
10239 | tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP; | ||
10240 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM; | ||
10241 | tfd->u.data.key_index = 0; | ||
10242 | tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE; | ||
10243 | break; | ||
10244 | case SEC_LEVEL_2: | ||
10245 | tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= | ||
10246 | cpu_to_le16(IEEE80211_FCTL_PROTECTED); | ||
10247 | tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP; | ||
10248 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP; | ||
10249 | tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE; | ||
10250 | break; | ||
10251 | case SEC_LEVEL_1: | ||
10252 | tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= | ||
10253 | cpu_to_le16(IEEE80211_FCTL_PROTECTED); | ||
10254 | tfd->u.data.key_index = priv->ieee->crypt_info.tx_keyidx; | ||
10255 | if (priv->ieee->sec.key_sizes[priv->ieee->crypt_info.tx_keyidx] <= | ||
10256 | 40) | ||
10257 | tfd->u.data.key_index |= DCT_WEP_KEY_64Bit; | ||
10258 | else | ||
10259 | tfd->u.data.key_index |= DCT_WEP_KEY_128Bit; | ||
10260 | break; | ||
10261 | case SEC_LEVEL_0: | ||
10262 | break; | ||
10263 | default: | ||
10264 | printk(KERN_ERR "Unknow security level %d\n", | ||
10265 | priv->ieee->sec.level); | ||
10266 | break; | ||
10267 | } | ||
10268 | } else | ||
10269 | /* No hardware encryption */ | ||
10270 | tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP; | ||
10271 | |||
10272 | #ifdef CONFIG_IPW2200_QOS | ||
10273 | if (fc & IEEE80211_STYPE_QOS_DATA) | ||
10274 | ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data)); | ||
10275 | #endif /* CONFIG_IPW2200_QOS */ | ||
10276 | |||
10277 | /* payload */ | ||
10278 | tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2), | ||
10279 | txb->nr_frags)); | ||
10280 | IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n", | ||
10281 | txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks)); | ||
10282 | for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) { | ||
10283 | IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n", | ||
10284 | i, le32_to_cpu(tfd->u.data.num_chunks), | ||
10285 | txb->fragments[i]->len - hdr_len); | ||
10286 | IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n", | ||
10287 | i, tfd->u.data.num_chunks, | ||
10288 | txb->fragments[i]->len - hdr_len); | ||
10289 | printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len, | ||
10290 | txb->fragments[i]->len - hdr_len); | ||
10291 | |||
10292 | tfd->u.data.chunk_ptr[i] = | ||
10293 | cpu_to_le32(pci_map_single | ||
10294 | (priv->pci_dev, | ||
10295 | txb->fragments[i]->data + hdr_len, | ||
10296 | txb->fragments[i]->len - hdr_len, | ||
10297 | PCI_DMA_TODEVICE)); | ||
10298 | tfd->u.data.chunk_len[i] = | ||
10299 | cpu_to_le16(txb->fragments[i]->len - hdr_len); | ||
10300 | } | ||
10301 | |||
10302 | if (i != txb->nr_frags) { | ||
10303 | struct sk_buff *skb; | ||
10304 | u16 remaining_bytes = 0; | ||
10305 | int j; | ||
10306 | |||
10307 | for (j = i; j < txb->nr_frags; j++) | ||
10308 | remaining_bytes += txb->fragments[j]->len - hdr_len; | ||
10309 | |||
10310 | printk(KERN_INFO "Trying to reallocate for %d bytes\n", | ||
10311 | remaining_bytes); | ||
10312 | skb = alloc_skb(remaining_bytes, GFP_ATOMIC); | ||
10313 | if (skb != NULL) { | ||
10314 | tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes); | ||
10315 | for (j = i; j < txb->nr_frags; j++) { | ||
10316 | int size = txb->fragments[j]->len - hdr_len; | ||
10317 | |||
10318 | printk(KERN_INFO "Adding frag %d %d...\n", | ||
10319 | j, size); | ||
10320 | memcpy(skb_put(skb, size), | ||
10321 | txb->fragments[j]->data + hdr_len, size); | ||
10322 | } | ||
10323 | dev_kfree_skb_any(txb->fragments[i]); | ||
10324 | txb->fragments[i] = skb; | ||
10325 | tfd->u.data.chunk_ptr[i] = | ||
10326 | cpu_to_le32(pci_map_single | ||
10327 | (priv->pci_dev, skb->data, | ||
10328 | remaining_bytes, | ||
10329 | PCI_DMA_TODEVICE)); | ||
10330 | |||
10331 | le32_add_cpu(&tfd->u.data.num_chunks, 1); | ||
10332 | } | ||
10333 | } | ||
10334 | |||
10335 | /* kick DMA */ | ||
10336 | q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd); | ||
10337 | ipw_write32(priv, q->reg_w, q->first_empty); | ||
10338 | |||
10339 | if (ipw_tx_queue_space(q) < q->high_mark) | ||
10340 | netif_stop_queue(priv->net_dev); | ||
10341 | |||
10342 | return NETDEV_TX_OK; | ||
10343 | |||
10344 | drop: | ||
10345 | IPW_DEBUG_DROP("Silently dropping Tx packet.\n"); | ||
10346 | ieee80211_txb_free(txb); | ||
10347 | return NETDEV_TX_OK; | ||
10348 | } | ||
10349 | |||
10350 | static int ipw_net_is_queue_full(struct net_device *dev, int pri) | ||
10351 | { | ||
10352 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
10353 | #ifdef CONFIG_IPW2200_QOS | ||
10354 | int tx_id = ipw_get_tx_queue_number(priv, pri); | ||
10355 | struct clx2_tx_queue *txq = &priv->txq[tx_id]; | ||
10356 | #else | ||
10357 | struct clx2_tx_queue *txq = &priv->txq[0]; | ||
10358 | #endif /* CONFIG_IPW2200_QOS */ | ||
10359 | |||
10360 | if (ipw_tx_queue_space(&txq->q) < txq->q.high_mark) | ||
10361 | return 1; | ||
10362 | |||
10363 | return 0; | ||
10364 | } | ||
10365 | |||
10366 | #ifdef CONFIG_IPW2200_PROMISCUOUS | ||
10367 | static void ipw_handle_promiscuous_tx(struct ipw_priv *priv, | ||
10368 | struct ieee80211_txb *txb) | ||
10369 | { | ||
10370 | struct ieee80211_rx_stats dummystats; | ||
10371 | struct ieee80211_hdr *hdr; | ||
10372 | u8 n; | ||
10373 | u16 filter = priv->prom_priv->filter; | ||
10374 | int hdr_only = 0; | ||
10375 | |||
10376 | if (filter & IPW_PROM_NO_TX) | ||
10377 | return; | ||
10378 | |||
10379 | memset(&dummystats, 0, sizeof(dummystats)); | ||
10380 | |||
10381 | /* Filtering of fragment chains is done agains the first fragment */ | ||
10382 | hdr = (void *)txb->fragments[0]->data; | ||
10383 | if (ieee80211_is_management(le16_to_cpu(hdr->frame_control))) { | ||
10384 | if (filter & IPW_PROM_NO_MGMT) | ||
10385 | return; | ||
10386 | if (filter & IPW_PROM_MGMT_HEADER_ONLY) | ||
10387 | hdr_only = 1; | ||
10388 | } else if (ieee80211_is_control(le16_to_cpu(hdr->frame_control))) { | ||
10389 | if (filter & IPW_PROM_NO_CTL) | ||
10390 | return; | ||
10391 | if (filter & IPW_PROM_CTL_HEADER_ONLY) | ||
10392 | hdr_only = 1; | ||
10393 | } else if (ieee80211_is_data(le16_to_cpu(hdr->frame_control))) { | ||
10394 | if (filter & IPW_PROM_NO_DATA) | ||
10395 | return; | ||
10396 | if (filter & IPW_PROM_DATA_HEADER_ONLY) | ||
10397 | hdr_only = 1; | ||
10398 | } | ||
10399 | |||
10400 | for(n=0; n<txb->nr_frags; ++n) { | ||
10401 | struct sk_buff *src = txb->fragments[n]; | ||
10402 | struct sk_buff *dst; | ||
10403 | struct ieee80211_radiotap_header *rt_hdr; | ||
10404 | int len; | ||
10405 | |||
10406 | if (hdr_only) { | ||
10407 | hdr = (void *)src->data; | ||
10408 | len = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_control)); | ||
10409 | } else | ||
10410 | len = src->len; | ||
10411 | |||
10412 | dst = alloc_skb( | ||
10413 | len + IEEE80211_RADIOTAP_HDRLEN, GFP_ATOMIC); | ||
10414 | if (!dst) continue; | ||
10415 | |||
10416 | rt_hdr = (void *)skb_put(dst, sizeof(*rt_hdr)); | ||
10417 | |||
10418 | rt_hdr->it_version = PKTHDR_RADIOTAP_VERSION; | ||
10419 | rt_hdr->it_pad = 0; | ||
10420 | rt_hdr->it_present = 0; /* after all, it's just an idea */ | ||
10421 | rt_hdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_CHANNEL); | ||
10422 | |||
10423 | *(__le16*)skb_put(dst, sizeof(u16)) = cpu_to_le16( | ||
10424 | ieee80211chan2mhz(priv->channel)); | ||
10425 | if (priv->channel > 14) /* 802.11a */ | ||
10426 | *(__le16*)skb_put(dst, sizeof(u16)) = | ||
10427 | cpu_to_le16(IEEE80211_CHAN_OFDM | | ||
10428 | IEEE80211_CHAN_5GHZ); | ||
10429 | else if (priv->ieee->mode == IEEE_B) /* 802.11b */ | ||
10430 | *(__le16*)skb_put(dst, sizeof(u16)) = | ||
10431 | cpu_to_le16(IEEE80211_CHAN_CCK | | ||
10432 | IEEE80211_CHAN_2GHZ); | ||
10433 | else /* 802.11g */ | ||
10434 | *(__le16*)skb_put(dst, sizeof(u16)) = | ||
10435 | cpu_to_le16(IEEE80211_CHAN_OFDM | | ||
10436 | IEEE80211_CHAN_2GHZ); | ||
10437 | |||
10438 | rt_hdr->it_len = cpu_to_le16(dst->len); | ||
10439 | |||
10440 | skb_copy_from_linear_data(src, skb_put(dst, len), len); | ||
10441 | |||
10442 | if (!ieee80211_rx(priv->prom_priv->ieee, dst, &dummystats)) | ||
10443 | dev_kfree_skb_any(dst); | ||
10444 | } | ||
10445 | } | ||
10446 | #endif | ||
10447 | |||
10448 | static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb, | ||
10449 | struct net_device *dev, int pri) | ||
10450 | { | ||
10451 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
10452 | unsigned long flags; | ||
10453 | int ret; | ||
10454 | |||
10455 | IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size); | ||
10456 | spin_lock_irqsave(&priv->lock, flags); | ||
10457 | |||
10458 | #ifdef CONFIG_IPW2200_PROMISCUOUS | ||
10459 | if (rtap_iface && netif_running(priv->prom_net_dev)) | ||
10460 | ipw_handle_promiscuous_tx(priv, txb); | ||
10461 | #endif | ||
10462 | |||
10463 | ret = ipw_tx_skb(priv, txb, pri); | ||
10464 | if (ret == NETDEV_TX_OK) | ||
10465 | __ipw_led_activity_on(priv); | ||
10466 | spin_unlock_irqrestore(&priv->lock, flags); | ||
10467 | |||
10468 | return ret; | ||
10469 | } | ||
10470 | |||
10471 | static struct net_device_stats *ipw_net_get_stats(struct net_device *dev) | ||
10472 | { | ||
10473 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
10474 | |||
10475 | priv->ieee->stats.tx_packets = priv->tx_packets; | ||
10476 | priv->ieee->stats.rx_packets = priv->rx_packets; | ||
10477 | return &priv->ieee->stats; | ||
10478 | } | ||
10479 | |||
10480 | static void ipw_net_set_multicast_list(struct net_device *dev) | ||
10481 | { | ||
10482 | |||
10483 | } | ||
10484 | |||
10485 | static int ipw_net_set_mac_address(struct net_device *dev, void *p) | ||
10486 | { | ||
10487 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
10488 | struct sockaddr *addr = p; | ||
10489 | |||
10490 | if (!is_valid_ether_addr(addr->sa_data)) | ||
10491 | return -EADDRNOTAVAIL; | ||
10492 | mutex_lock(&priv->mutex); | ||
10493 | priv->config |= CFG_CUSTOM_MAC; | ||
10494 | memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN); | ||
10495 | printk(KERN_INFO "%s: Setting MAC to %pM\n", | ||
10496 | priv->net_dev->name, priv->mac_addr); | ||
10497 | queue_work(priv->workqueue, &priv->adapter_restart); | ||
10498 | mutex_unlock(&priv->mutex); | ||
10499 | return 0; | ||
10500 | } | ||
10501 | |||
10502 | static void ipw_ethtool_get_drvinfo(struct net_device *dev, | ||
10503 | struct ethtool_drvinfo *info) | ||
10504 | { | ||
10505 | struct ipw_priv *p = ieee80211_priv(dev); | ||
10506 | char vers[64]; | ||
10507 | char date[32]; | ||
10508 | u32 len; | ||
10509 | |||
10510 | strcpy(info->driver, DRV_NAME); | ||
10511 | strcpy(info->version, DRV_VERSION); | ||
10512 | |||
10513 | len = sizeof(vers); | ||
10514 | ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len); | ||
10515 | len = sizeof(date); | ||
10516 | ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len); | ||
10517 | |||
10518 | snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)", | ||
10519 | vers, date); | ||
10520 | strcpy(info->bus_info, pci_name(p->pci_dev)); | ||
10521 | info->eedump_len = IPW_EEPROM_IMAGE_SIZE; | ||
10522 | } | ||
10523 | |||
10524 | static u32 ipw_ethtool_get_link(struct net_device *dev) | ||
10525 | { | ||
10526 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
10527 | return (priv->status & STATUS_ASSOCIATED) != 0; | ||
10528 | } | ||
10529 | |||
10530 | static int ipw_ethtool_get_eeprom_len(struct net_device *dev) | ||
10531 | { | ||
10532 | return IPW_EEPROM_IMAGE_SIZE; | ||
10533 | } | ||
10534 | |||
10535 | static int ipw_ethtool_get_eeprom(struct net_device *dev, | ||
10536 | struct ethtool_eeprom *eeprom, u8 * bytes) | ||
10537 | { | ||
10538 | struct ipw_priv *p = ieee80211_priv(dev); | ||
10539 | |||
10540 | if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE) | ||
10541 | return -EINVAL; | ||
10542 | mutex_lock(&p->mutex); | ||
10543 | memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len); | ||
10544 | mutex_unlock(&p->mutex); | ||
10545 | return 0; | ||
10546 | } | ||
10547 | |||
10548 | static int ipw_ethtool_set_eeprom(struct net_device *dev, | ||
10549 | struct ethtool_eeprom *eeprom, u8 * bytes) | ||
10550 | { | ||
10551 | struct ipw_priv *p = ieee80211_priv(dev); | ||
10552 | int i; | ||
10553 | |||
10554 | if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE) | ||
10555 | return -EINVAL; | ||
10556 | mutex_lock(&p->mutex); | ||
10557 | memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len); | ||
10558 | for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++) | ||
10559 | ipw_write8(p, i + IPW_EEPROM_DATA, p->eeprom[i]); | ||
10560 | mutex_unlock(&p->mutex); | ||
10561 | return 0; | ||
10562 | } | ||
10563 | |||
10564 | static const struct ethtool_ops ipw_ethtool_ops = { | ||
10565 | .get_link = ipw_ethtool_get_link, | ||
10566 | .get_drvinfo = ipw_ethtool_get_drvinfo, | ||
10567 | .get_eeprom_len = ipw_ethtool_get_eeprom_len, | ||
10568 | .get_eeprom = ipw_ethtool_get_eeprom, | ||
10569 | .set_eeprom = ipw_ethtool_set_eeprom, | ||
10570 | }; | ||
10571 | |||
10572 | static irqreturn_t ipw_isr(int irq, void *data) | ||
10573 | { | ||
10574 | struct ipw_priv *priv = data; | ||
10575 | u32 inta, inta_mask; | ||
10576 | |||
10577 | if (!priv) | ||
10578 | return IRQ_NONE; | ||
10579 | |||
10580 | spin_lock(&priv->irq_lock); | ||
10581 | |||
10582 | if (!(priv->status & STATUS_INT_ENABLED)) { | ||
10583 | /* IRQ is disabled */ | ||
10584 | goto none; | ||
10585 | } | ||
10586 | |||
10587 | inta = ipw_read32(priv, IPW_INTA_RW); | ||
10588 | inta_mask = ipw_read32(priv, IPW_INTA_MASK_R); | ||
10589 | |||
10590 | if (inta == 0xFFFFFFFF) { | ||
10591 | /* Hardware disappeared */ | ||
10592 | IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n"); | ||
10593 | goto none; | ||
10594 | } | ||
10595 | |||
10596 | if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) { | ||
10597 | /* Shared interrupt */ | ||
10598 | goto none; | ||
10599 | } | ||
10600 | |||
10601 | /* tell the device to stop sending interrupts */ | ||
10602 | __ipw_disable_interrupts(priv); | ||
10603 | |||
10604 | /* ack current interrupts */ | ||
10605 | inta &= (IPW_INTA_MASK_ALL & inta_mask); | ||
10606 | ipw_write32(priv, IPW_INTA_RW, inta); | ||
10607 | |||
10608 | /* Cache INTA value for our tasklet */ | ||
10609 | priv->isr_inta = inta; | ||
10610 | |||
10611 | tasklet_schedule(&priv->irq_tasklet); | ||
10612 | |||
10613 | spin_unlock(&priv->irq_lock); | ||
10614 | |||
10615 | return IRQ_HANDLED; | ||
10616 | none: | ||
10617 | spin_unlock(&priv->irq_lock); | ||
10618 | return IRQ_NONE; | ||
10619 | } | ||
10620 | |||
10621 | static void ipw_rf_kill(void *adapter) | ||
10622 | { | ||
10623 | struct ipw_priv *priv = adapter; | ||
10624 | unsigned long flags; | ||
10625 | |||
10626 | spin_lock_irqsave(&priv->lock, flags); | ||
10627 | |||
10628 | if (rf_kill_active(priv)) { | ||
10629 | IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n"); | ||
10630 | if (priv->workqueue) | ||
10631 | queue_delayed_work(priv->workqueue, | ||
10632 | &priv->rf_kill, 2 * HZ); | ||
10633 | goto exit_unlock; | ||
10634 | } | ||
10635 | |||
10636 | /* RF Kill is now disabled, so bring the device back up */ | ||
10637 | |||
10638 | if (!(priv->status & STATUS_RF_KILL_MASK)) { | ||
10639 | IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting " | ||
10640 | "device\n"); | ||
10641 | |||
10642 | /* we can not do an adapter restart while inside an irq lock */ | ||
10643 | queue_work(priv->workqueue, &priv->adapter_restart); | ||
10644 | } else | ||
10645 | IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still " | ||
10646 | "enabled\n"); | ||
10647 | |||
10648 | exit_unlock: | ||
10649 | spin_unlock_irqrestore(&priv->lock, flags); | ||
10650 | } | ||
10651 | |||
10652 | static void ipw_bg_rf_kill(struct work_struct *work) | ||
10653 | { | ||
10654 | struct ipw_priv *priv = | ||
10655 | container_of(work, struct ipw_priv, rf_kill.work); | ||
10656 | mutex_lock(&priv->mutex); | ||
10657 | ipw_rf_kill(priv); | ||
10658 | mutex_unlock(&priv->mutex); | ||
10659 | } | ||
10660 | |||
10661 | static void ipw_link_up(struct ipw_priv *priv) | ||
10662 | { | ||
10663 | priv->last_seq_num = -1; | ||
10664 | priv->last_frag_num = -1; | ||
10665 | priv->last_packet_time = 0; | ||
10666 | |||
10667 | netif_carrier_on(priv->net_dev); | ||
10668 | |||
10669 | cancel_delayed_work(&priv->request_scan); | ||
10670 | cancel_delayed_work(&priv->request_direct_scan); | ||
10671 | cancel_delayed_work(&priv->request_passive_scan); | ||
10672 | cancel_delayed_work(&priv->scan_event); | ||
10673 | ipw_reset_stats(priv); | ||
10674 | /* Ensure the rate is updated immediately */ | ||
10675 | priv->last_rate = ipw_get_current_rate(priv); | ||
10676 | ipw_gather_stats(priv); | ||
10677 | ipw_led_link_up(priv); | ||
10678 | notify_wx_assoc_event(priv); | ||
10679 | |||
10680 | if (priv->config & CFG_BACKGROUND_SCAN) | ||
10681 | queue_delayed_work(priv->workqueue, &priv->request_scan, HZ); | ||
10682 | } | ||
10683 | |||
10684 | static void ipw_bg_link_up(struct work_struct *work) | ||
10685 | { | ||
10686 | struct ipw_priv *priv = | ||
10687 | container_of(work, struct ipw_priv, link_up); | ||
10688 | mutex_lock(&priv->mutex); | ||
10689 | ipw_link_up(priv); | ||
10690 | mutex_unlock(&priv->mutex); | ||
10691 | } | ||
10692 | |||
10693 | static void ipw_link_down(struct ipw_priv *priv) | ||
10694 | { | ||
10695 | ipw_led_link_down(priv); | ||
10696 | netif_carrier_off(priv->net_dev); | ||
10697 | notify_wx_assoc_event(priv); | ||
10698 | |||
10699 | /* Cancel any queued work ... */ | ||
10700 | cancel_delayed_work(&priv->request_scan); | ||
10701 | cancel_delayed_work(&priv->request_direct_scan); | ||
10702 | cancel_delayed_work(&priv->request_passive_scan); | ||
10703 | cancel_delayed_work(&priv->adhoc_check); | ||
10704 | cancel_delayed_work(&priv->gather_stats); | ||
10705 | |||
10706 | ipw_reset_stats(priv); | ||
10707 | |||
10708 | if (!(priv->status & STATUS_EXIT_PENDING)) { | ||
10709 | /* Queue up another scan... */ | ||
10710 | queue_delayed_work(priv->workqueue, &priv->request_scan, 0); | ||
10711 | } else | ||
10712 | cancel_delayed_work(&priv->scan_event); | ||
10713 | } | ||
10714 | |||
10715 | static void ipw_bg_link_down(struct work_struct *work) | ||
10716 | { | ||
10717 | struct ipw_priv *priv = | ||
10718 | container_of(work, struct ipw_priv, link_down); | ||
10719 | mutex_lock(&priv->mutex); | ||
10720 | ipw_link_down(priv); | ||
10721 | mutex_unlock(&priv->mutex); | ||
10722 | } | ||
10723 | |||
10724 | static int __devinit ipw_setup_deferred_work(struct ipw_priv *priv) | ||
10725 | { | ||
10726 | int ret = 0; | ||
10727 | |||
10728 | priv->workqueue = create_workqueue(DRV_NAME); | ||
10729 | init_waitqueue_head(&priv->wait_command_queue); | ||
10730 | init_waitqueue_head(&priv->wait_state); | ||
10731 | |||
10732 | INIT_DELAYED_WORK(&priv->adhoc_check, ipw_bg_adhoc_check); | ||
10733 | INIT_WORK(&priv->associate, ipw_bg_associate); | ||
10734 | INIT_WORK(&priv->disassociate, ipw_bg_disassociate); | ||
10735 | INIT_WORK(&priv->system_config, ipw_system_config); | ||
10736 | INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish); | ||
10737 | INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart); | ||
10738 | INIT_DELAYED_WORK(&priv->rf_kill, ipw_bg_rf_kill); | ||
10739 | INIT_WORK(&priv->up, ipw_bg_up); | ||
10740 | INIT_WORK(&priv->down, ipw_bg_down); | ||
10741 | INIT_DELAYED_WORK(&priv->request_scan, ipw_request_scan); | ||
10742 | INIT_DELAYED_WORK(&priv->request_direct_scan, ipw_request_direct_scan); | ||
10743 | INIT_DELAYED_WORK(&priv->request_passive_scan, ipw_request_passive_scan); | ||
10744 | INIT_DELAYED_WORK(&priv->scan_event, ipw_scan_event); | ||
10745 | INIT_DELAYED_WORK(&priv->gather_stats, ipw_bg_gather_stats); | ||
10746 | INIT_WORK(&priv->abort_scan, ipw_bg_abort_scan); | ||
10747 | INIT_WORK(&priv->roam, ipw_bg_roam); | ||
10748 | INIT_DELAYED_WORK(&priv->scan_check, ipw_bg_scan_check); | ||
10749 | INIT_WORK(&priv->link_up, ipw_bg_link_up); | ||
10750 | INIT_WORK(&priv->link_down, ipw_bg_link_down); | ||
10751 | INIT_DELAYED_WORK(&priv->led_link_on, ipw_bg_led_link_on); | ||
10752 | INIT_DELAYED_WORK(&priv->led_link_off, ipw_bg_led_link_off); | ||
10753 | INIT_DELAYED_WORK(&priv->led_act_off, ipw_bg_led_activity_off); | ||
10754 | INIT_WORK(&priv->merge_networks, ipw_merge_adhoc_network); | ||
10755 | |||
10756 | #ifdef CONFIG_IPW2200_QOS | ||
10757 | INIT_WORK(&priv->qos_activate, ipw_bg_qos_activate); | ||
10758 | #endif /* CONFIG_IPW2200_QOS */ | ||
10759 | |||
10760 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) | ||
10761 | ipw_irq_tasklet, (unsigned long)priv); | ||
10762 | |||
10763 | return ret; | ||
10764 | } | ||
10765 | |||
10766 | static void shim__set_security(struct net_device *dev, | ||
10767 | struct ieee80211_security *sec) | ||
10768 | { | ||
10769 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
10770 | int i; | ||
10771 | for (i = 0; i < 4; i++) { | ||
10772 | if (sec->flags & (1 << i)) { | ||
10773 | priv->ieee->sec.encode_alg[i] = sec->encode_alg[i]; | ||
10774 | priv->ieee->sec.key_sizes[i] = sec->key_sizes[i]; | ||
10775 | if (sec->key_sizes[i] == 0) | ||
10776 | priv->ieee->sec.flags &= ~(1 << i); | ||
10777 | else { | ||
10778 | memcpy(priv->ieee->sec.keys[i], sec->keys[i], | ||
10779 | sec->key_sizes[i]); | ||
10780 | priv->ieee->sec.flags |= (1 << i); | ||
10781 | } | ||
10782 | priv->status |= STATUS_SECURITY_UPDATED; | ||
10783 | } else if (sec->level != SEC_LEVEL_1) | ||
10784 | priv->ieee->sec.flags &= ~(1 << i); | ||
10785 | } | ||
10786 | |||
10787 | if (sec->flags & SEC_ACTIVE_KEY) { | ||
10788 | if (sec->active_key <= 3) { | ||
10789 | priv->ieee->sec.active_key = sec->active_key; | ||
10790 | priv->ieee->sec.flags |= SEC_ACTIVE_KEY; | ||
10791 | } else | ||
10792 | priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY; | ||
10793 | priv->status |= STATUS_SECURITY_UPDATED; | ||
10794 | } else | ||
10795 | priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY; | ||
10796 | |||
10797 | if ((sec->flags & SEC_AUTH_MODE) && | ||
10798 | (priv->ieee->sec.auth_mode != sec->auth_mode)) { | ||
10799 | priv->ieee->sec.auth_mode = sec->auth_mode; | ||
10800 | priv->ieee->sec.flags |= SEC_AUTH_MODE; | ||
10801 | if (sec->auth_mode == WLAN_AUTH_SHARED_KEY) | ||
10802 | priv->capability |= CAP_SHARED_KEY; | ||
10803 | else | ||
10804 | priv->capability &= ~CAP_SHARED_KEY; | ||
10805 | priv->status |= STATUS_SECURITY_UPDATED; | ||
10806 | } | ||
10807 | |||
10808 | if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) { | ||
10809 | priv->ieee->sec.flags |= SEC_ENABLED; | ||
10810 | priv->ieee->sec.enabled = sec->enabled; | ||
10811 | priv->status |= STATUS_SECURITY_UPDATED; | ||
10812 | if (sec->enabled) | ||
10813 | priv->capability |= CAP_PRIVACY_ON; | ||
10814 | else | ||
10815 | priv->capability &= ~CAP_PRIVACY_ON; | ||
10816 | } | ||
10817 | |||
10818 | if (sec->flags & SEC_ENCRYPT) | ||
10819 | priv->ieee->sec.encrypt = sec->encrypt; | ||
10820 | |||
10821 | if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) { | ||
10822 | priv->ieee->sec.level = sec->level; | ||
10823 | priv->ieee->sec.flags |= SEC_LEVEL; | ||
10824 | priv->status |= STATUS_SECURITY_UPDATED; | ||
10825 | } | ||
10826 | |||
10827 | if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT)) | ||
10828 | ipw_set_hwcrypto_keys(priv); | ||
10829 | |||
10830 | /* To match current functionality of ipw2100 (which works well w/ | ||
10831 | * various supplicants, we don't force a disassociate if the | ||
10832 | * privacy capability changes ... */ | ||
10833 | #if 0 | ||
10834 | if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) && | ||
10835 | (((priv->assoc_request.capability & | ||
10836 | cpu_to_le16(WLAN_CAPABILITY_PRIVACY)) && !sec->enabled) || | ||
10837 | (!(priv->assoc_request.capability & | ||
10838 | cpu_to_le16(WLAN_CAPABILITY_PRIVACY)) && sec->enabled))) { | ||
10839 | IPW_DEBUG_ASSOC("Disassociating due to capability " | ||
10840 | "change.\n"); | ||
10841 | ipw_disassociate(priv); | ||
10842 | } | ||
10843 | #endif | ||
10844 | } | ||
10845 | |||
10846 | static int init_supported_rates(struct ipw_priv *priv, | ||
10847 | struct ipw_supported_rates *rates) | ||
10848 | { | ||
10849 | /* TODO: Mask out rates based on priv->rates_mask */ | ||
10850 | |||
10851 | memset(rates, 0, sizeof(*rates)); | ||
10852 | /* configure supported rates */ | ||
10853 | switch (priv->ieee->freq_band) { | ||
10854 | case IEEE80211_52GHZ_BAND: | ||
10855 | rates->ieee_mode = IPW_A_MODE; | ||
10856 | rates->purpose = IPW_RATE_CAPABILITIES; | ||
10857 | ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION, | ||
10858 | IEEE80211_OFDM_DEFAULT_RATES_MASK); | ||
10859 | break; | ||
10860 | |||
10861 | default: /* Mixed or 2.4Ghz */ | ||
10862 | rates->ieee_mode = IPW_G_MODE; | ||
10863 | rates->purpose = IPW_RATE_CAPABILITIES; | ||
10864 | ipw_add_cck_scan_rates(rates, IEEE80211_CCK_MODULATION, | ||
10865 | IEEE80211_CCK_DEFAULT_RATES_MASK); | ||
10866 | if (priv->ieee->modulation & IEEE80211_OFDM_MODULATION) { | ||
10867 | ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION, | ||
10868 | IEEE80211_OFDM_DEFAULT_RATES_MASK); | ||
10869 | } | ||
10870 | break; | ||
10871 | } | ||
10872 | |||
10873 | return 0; | ||
10874 | } | ||
10875 | |||
10876 | static int ipw_config(struct ipw_priv *priv) | ||
10877 | { | ||
10878 | /* This is only called from ipw_up, which resets/reloads the firmware | ||
10879 | so, we don't need to first disable the card before we configure | ||
10880 | it */ | ||
10881 | if (ipw_set_tx_power(priv)) | ||
10882 | goto error; | ||
10883 | |||
10884 | /* initialize adapter address */ | ||
10885 | if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr)) | ||
10886 | goto error; | ||
10887 | |||
10888 | /* set basic system config settings */ | ||
10889 | init_sys_config(&priv->sys_config); | ||
10890 | |||
10891 | /* Support Bluetooth if we have BT h/w on board, and user wants to. | ||
10892 | * Does not support BT priority yet (don't abort or defer our Tx) */ | ||
10893 | if (bt_coexist) { | ||
10894 | unsigned char bt_caps = priv->eeprom[EEPROM_SKU_CAPABILITY]; | ||
10895 | |||
10896 | if (bt_caps & EEPROM_SKU_CAP_BT_CHANNEL_SIG) | ||
10897 | priv->sys_config.bt_coexistence | ||
10898 | |= CFG_BT_COEXISTENCE_SIGNAL_CHNL; | ||
10899 | if (bt_caps & EEPROM_SKU_CAP_BT_OOB) | ||
10900 | priv->sys_config.bt_coexistence | ||
10901 | |= CFG_BT_COEXISTENCE_OOB; | ||
10902 | } | ||
10903 | |||
10904 | #ifdef CONFIG_IPW2200_PROMISCUOUS | ||
10905 | if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) { | ||
10906 | priv->sys_config.accept_all_data_frames = 1; | ||
10907 | priv->sys_config.accept_non_directed_frames = 1; | ||
10908 | priv->sys_config.accept_all_mgmt_bcpr = 1; | ||
10909 | priv->sys_config.accept_all_mgmt_frames = 1; | ||
10910 | } | ||
10911 | #endif | ||
10912 | |||
10913 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) | ||
10914 | priv->sys_config.answer_broadcast_ssid_probe = 1; | ||
10915 | else | ||
10916 | priv->sys_config.answer_broadcast_ssid_probe = 0; | ||
10917 | |||
10918 | if (ipw_send_system_config(priv)) | ||
10919 | goto error; | ||
10920 | |||
10921 | init_supported_rates(priv, &priv->rates); | ||
10922 | if (ipw_send_supported_rates(priv, &priv->rates)) | ||
10923 | goto error; | ||
10924 | |||
10925 | /* Set request-to-send threshold */ | ||
10926 | if (priv->rts_threshold) { | ||
10927 | if (ipw_send_rts_threshold(priv, priv->rts_threshold)) | ||
10928 | goto error; | ||
10929 | } | ||
10930 | #ifdef CONFIG_IPW2200_QOS | ||
10931 | IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n"); | ||
10932 | ipw_qos_activate(priv, NULL); | ||
10933 | #endif /* CONFIG_IPW2200_QOS */ | ||
10934 | |||
10935 | if (ipw_set_random_seed(priv)) | ||
10936 | goto error; | ||
10937 | |||
10938 | /* final state transition to the RUN state */ | ||
10939 | if (ipw_send_host_complete(priv)) | ||
10940 | goto error; | ||
10941 | |||
10942 | priv->status |= STATUS_INIT; | ||
10943 | |||
10944 | ipw_led_init(priv); | ||
10945 | ipw_led_radio_on(priv); | ||
10946 | priv->notif_missed_beacons = 0; | ||
10947 | |||
10948 | /* Set hardware WEP key if it is configured. */ | ||
10949 | if ((priv->capability & CAP_PRIVACY_ON) && | ||
10950 | (priv->ieee->sec.level == SEC_LEVEL_1) && | ||
10951 | !(priv->ieee->host_encrypt || priv->ieee->host_decrypt)) | ||
10952 | ipw_set_hwcrypto_keys(priv); | ||
10953 | |||
10954 | return 0; | ||
10955 | |||
10956 | error: | ||
10957 | return -EIO; | ||
10958 | } | ||
10959 | |||
10960 | /* | ||
10961 | * NOTE: | ||
10962 | * | ||
10963 | * These tables have been tested in conjunction with the | ||
10964 | * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters. | ||
10965 | * | ||
10966 | * Altering this values, using it on other hardware, or in geographies | ||
10967 | * not intended for resale of the above mentioned Intel adapters has | ||
10968 | * not been tested. | ||
10969 | * | ||
10970 | * Remember to update the table in README.ipw2200 when changing this | ||
10971 | * table. | ||
10972 | * | ||
10973 | */ | ||
10974 | static const struct ieee80211_geo ipw_geos[] = { | ||
10975 | { /* Restricted */ | ||
10976 | "---", | ||
10977 | .bg_channels = 11, | ||
10978 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | ||
10979 | {2427, 4}, {2432, 5}, {2437, 6}, | ||
10980 | {2442, 7}, {2447, 8}, {2452, 9}, | ||
10981 | {2457, 10}, {2462, 11}}, | ||
10982 | }, | ||
10983 | |||
10984 | { /* Custom US/Canada */ | ||
10985 | "ZZF", | ||
10986 | .bg_channels = 11, | ||
10987 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | ||
10988 | {2427, 4}, {2432, 5}, {2437, 6}, | ||
10989 | {2442, 7}, {2447, 8}, {2452, 9}, | ||
10990 | {2457, 10}, {2462, 11}}, | ||
10991 | .a_channels = 8, | ||
10992 | .a = {{5180, 36}, | ||
10993 | {5200, 40}, | ||
10994 | {5220, 44}, | ||
10995 | {5240, 48}, | ||
10996 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, | ||
10997 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, | ||
10998 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, | ||
10999 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}}, | ||
11000 | }, | ||
11001 | |||
11002 | { /* Rest of World */ | ||
11003 | "ZZD", | ||
11004 | .bg_channels = 13, | ||
11005 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | ||
11006 | {2427, 4}, {2432, 5}, {2437, 6}, | ||
11007 | {2442, 7}, {2447, 8}, {2452, 9}, | ||
11008 | {2457, 10}, {2462, 11}, {2467, 12}, | ||
11009 | {2472, 13}}, | ||
11010 | }, | ||
11011 | |||
11012 | { /* Custom USA & Europe & High */ | ||
11013 | "ZZA", | ||
11014 | .bg_channels = 11, | ||
11015 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | ||
11016 | {2427, 4}, {2432, 5}, {2437, 6}, | ||
11017 | {2442, 7}, {2447, 8}, {2452, 9}, | ||
11018 | {2457, 10}, {2462, 11}}, | ||
11019 | .a_channels = 13, | ||
11020 | .a = {{5180, 36}, | ||
11021 | {5200, 40}, | ||
11022 | {5220, 44}, | ||
11023 | {5240, 48}, | ||
11024 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, | ||
11025 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, | ||
11026 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, | ||
11027 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, | ||
11028 | {5745, 149}, | ||
11029 | {5765, 153}, | ||
11030 | {5785, 157}, | ||
11031 | {5805, 161}, | ||
11032 | {5825, 165}}, | ||
11033 | }, | ||
11034 | |||
11035 | { /* Custom NA & Europe */ | ||
11036 | "ZZB", | ||
11037 | .bg_channels = 11, | ||
11038 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | ||
11039 | {2427, 4}, {2432, 5}, {2437, 6}, | ||
11040 | {2442, 7}, {2447, 8}, {2452, 9}, | ||
11041 | {2457, 10}, {2462, 11}}, | ||
11042 | .a_channels = 13, | ||
11043 | .a = {{5180, 36}, | ||
11044 | {5200, 40}, | ||
11045 | {5220, 44}, | ||
11046 | {5240, 48}, | ||
11047 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, | ||
11048 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, | ||
11049 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, | ||
11050 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, | ||
11051 | {5745, 149, IEEE80211_CH_PASSIVE_ONLY}, | ||
11052 | {5765, 153, IEEE80211_CH_PASSIVE_ONLY}, | ||
11053 | {5785, 157, IEEE80211_CH_PASSIVE_ONLY}, | ||
11054 | {5805, 161, IEEE80211_CH_PASSIVE_ONLY}, | ||
11055 | {5825, 165, IEEE80211_CH_PASSIVE_ONLY}}, | ||
11056 | }, | ||
11057 | |||
11058 | { /* Custom Japan */ | ||
11059 | "ZZC", | ||
11060 | .bg_channels = 11, | ||
11061 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | ||
11062 | {2427, 4}, {2432, 5}, {2437, 6}, | ||
11063 | {2442, 7}, {2447, 8}, {2452, 9}, | ||
11064 | {2457, 10}, {2462, 11}}, | ||
11065 | .a_channels = 4, | ||
11066 | .a = {{5170, 34}, {5190, 38}, | ||
11067 | {5210, 42}, {5230, 46}}, | ||
11068 | }, | ||
11069 | |||
11070 | { /* Custom */ | ||
11071 | "ZZM", | ||
11072 | .bg_channels = 11, | ||
11073 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | ||
11074 | {2427, 4}, {2432, 5}, {2437, 6}, | ||
11075 | {2442, 7}, {2447, 8}, {2452, 9}, | ||
11076 | {2457, 10}, {2462, 11}}, | ||
11077 | }, | ||
11078 | |||
11079 | { /* Europe */ | ||
11080 | "ZZE", | ||
11081 | .bg_channels = 13, | ||
11082 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | ||
11083 | {2427, 4}, {2432, 5}, {2437, 6}, | ||
11084 | {2442, 7}, {2447, 8}, {2452, 9}, | ||
11085 | {2457, 10}, {2462, 11}, {2467, 12}, | ||
11086 | {2472, 13}}, | ||
11087 | .a_channels = 19, | ||
11088 | .a = {{5180, 36}, | ||
11089 | {5200, 40}, | ||
11090 | {5220, 44}, | ||
11091 | {5240, 48}, | ||
11092 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, | ||
11093 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, | ||
11094 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, | ||
11095 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, | ||
11096 | {5500, 100, IEEE80211_CH_PASSIVE_ONLY}, | ||
11097 | {5520, 104, IEEE80211_CH_PASSIVE_ONLY}, | ||
11098 | {5540, 108, IEEE80211_CH_PASSIVE_ONLY}, | ||
11099 | {5560, 112, IEEE80211_CH_PASSIVE_ONLY}, | ||
11100 | {5580, 116, IEEE80211_CH_PASSIVE_ONLY}, | ||
11101 | {5600, 120, IEEE80211_CH_PASSIVE_ONLY}, | ||
11102 | {5620, 124, IEEE80211_CH_PASSIVE_ONLY}, | ||
11103 | {5640, 128, IEEE80211_CH_PASSIVE_ONLY}, | ||
11104 | {5660, 132, IEEE80211_CH_PASSIVE_ONLY}, | ||
11105 | {5680, 136, IEEE80211_CH_PASSIVE_ONLY}, | ||
11106 | {5700, 140, IEEE80211_CH_PASSIVE_ONLY}}, | ||
11107 | }, | ||
11108 | |||
11109 | { /* Custom Japan */ | ||
11110 | "ZZJ", | ||
11111 | .bg_channels = 14, | ||
11112 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | ||
11113 | {2427, 4}, {2432, 5}, {2437, 6}, | ||
11114 | {2442, 7}, {2447, 8}, {2452, 9}, | ||
11115 | {2457, 10}, {2462, 11}, {2467, 12}, | ||
11116 | {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY}}, | ||
11117 | .a_channels = 4, | ||
11118 | .a = {{5170, 34}, {5190, 38}, | ||
11119 | {5210, 42}, {5230, 46}}, | ||
11120 | }, | ||
11121 | |||
11122 | { /* Rest of World */ | ||
11123 | "ZZR", | ||
11124 | .bg_channels = 14, | ||
11125 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | ||
11126 | {2427, 4}, {2432, 5}, {2437, 6}, | ||
11127 | {2442, 7}, {2447, 8}, {2452, 9}, | ||
11128 | {2457, 10}, {2462, 11}, {2467, 12}, | ||
11129 | {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY | | ||
11130 | IEEE80211_CH_PASSIVE_ONLY}}, | ||
11131 | }, | ||
11132 | |||
11133 | { /* High Band */ | ||
11134 | "ZZH", | ||
11135 | .bg_channels = 13, | ||
11136 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | ||
11137 | {2427, 4}, {2432, 5}, {2437, 6}, | ||
11138 | {2442, 7}, {2447, 8}, {2452, 9}, | ||
11139 | {2457, 10}, {2462, 11}, | ||
11140 | {2467, 12, IEEE80211_CH_PASSIVE_ONLY}, | ||
11141 | {2472, 13, IEEE80211_CH_PASSIVE_ONLY}}, | ||
11142 | .a_channels = 4, | ||
11143 | .a = {{5745, 149}, {5765, 153}, | ||
11144 | {5785, 157}, {5805, 161}}, | ||
11145 | }, | ||
11146 | |||
11147 | { /* Custom Europe */ | ||
11148 | "ZZG", | ||
11149 | .bg_channels = 13, | ||
11150 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | ||
11151 | {2427, 4}, {2432, 5}, {2437, 6}, | ||
11152 | {2442, 7}, {2447, 8}, {2452, 9}, | ||
11153 | {2457, 10}, {2462, 11}, | ||
11154 | {2467, 12}, {2472, 13}}, | ||
11155 | .a_channels = 4, | ||
11156 | .a = {{5180, 36}, {5200, 40}, | ||
11157 | {5220, 44}, {5240, 48}}, | ||
11158 | }, | ||
11159 | |||
11160 | { /* Europe */ | ||
11161 | "ZZK", | ||
11162 | .bg_channels = 13, | ||
11163 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | ||
11164 | {2427, 4}, {2432, 5}, {2437, 6}, | ||
11165 | {2442, 7}, {2447, 8}, {2452, 9}, | ||
11166 | {2457, 10}, {2462, 11}, | ||
11167 | {2467, 12, IEEE80211_CH_PASSIVE_ONLY}, | ||
11168 | {2472, 13, IEEE80211_CH_PASSIVE_ONLY}}, | ||
11169 | .a_channels = 24, | ||
11170 | .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY}, | ||
11171 | {5200, 40, IEEE80211_CH_PASSIVE_ONLY}, | ||
11172 | {5220, 44, IEEE80211_CH_PASSIVE_ONLY}, | ||
11173 | {5240, 48, IEEE80211_CH_PASSIVE_ONLY}, | ||
11174 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, | ||
11175 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, | ||
11176 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, | ||
11177 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, | ||
11178 | {5500, 100, IEEE80211_CH_PASSIVE_ONLY}, | ||
11179 | {5520, 104, IEEE80211_CH_PASSIVE_ONLY}, | ||
11180 | {5540, 108, IEEE80211_CH_PASSIVE_ONLY}, | ||
11181 | {5560, 112, IEEE80211_CH_PASSIVE_ONLY}, | ||
11182 | {5580, 116, IEEE80211_CH_PASSIVE_ONLY}, | ||
11183 | {5600, 120, IEEE80211_CH_PASSIVE_ONLY}, | ||
11184 | {5620, 124, IEEE80211_CH_PASSIVE_ONLY}, | ||
11185 | {5640, 128, IEEE80211_CH_PASSIVE_ONLY}, | ||
11186 | {5660, 132, IEEE80211_CH_PASSIVE_ONLY}, | ||
11187 | {5680, 136, IEEE80211_CH_PASSIVE_ONLY}, | ||
11188 | {5700, 140, IEEE80211_CH_PASSIVE_ONLY}, | ||
11189 | {5745, 149, IEEE80211_CH_PASSIVE_ONLY}, | ||
11190 | {5765, 153, IEEE80211_CH_PASSIVE_ONLY}, | ||
11191 | {5785, 157, IEEE80211_CH_PASSIVE_ONLY}, | ||
11192 | {5805, 161, IEEE80211_CH_PASSIVE_ONLY}, | ||
11193 | {5825, 165, IEEE80211_CH_PASSIVE_ONLY}}, | ||
11194 | }, | ||
11195 | |||
11196 | { /* Europe */ | ||
11197 | "ZZL", | ||
11198 | .bg_channels = 11, | ||
11199 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | ||
11200 | {2427, 4}, {2432, 5}, {2437, 6}, | ||
11201 | {2442, 7}, {2447, 8}, {2452, 9}, | ||
11202 | {2457, 10}, {2462, 11}}, | ||
11203 | .a_channels = 13, | ||
11204 | .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY}, | ||
11205 | {5200, 40, IEEE80211_CH_PASSIVE_ONLY}, | ||
11206 | {5220, 44, IEEE80211_CH_PASSIVE_ONLY}, | ||
11207 | {5240, 48, IEEE80211_CH_PASSIVE_ONLY}, | ||
11208 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, | ||
11209 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, | ||
11210 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, | ||
11211 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, | ||
11212 | {5745, 149, IEEE80211_CH_PASSIVE_ONLY}, | ||
11213 | {5765, 153, IEEE80211_CH_PASSIVE_ONLY}, | ||
11214 | {5785, 157, IEEE80211_CH_PASSIVE_ONLY}, | ||
11215 | {5805, 161, IEEE80211_CH_PASSIVE_ONLY}, | ||
11216 | {5825, 165, IEEE80211_CH_PASSIVE_ONLY}}, | ||
11217 | } | ||
11218 | }; | ||
11219 | |||
11220 | #define MAX_HW_RESTARTS 5 | ||
11221 | static int ipw_up(struct ipw_priv *priv) | ||
11222 | { | ||
11223 | int rc, i, j; | ||
11224 | |||
11225 | if (priv->status & STATUS_EXIT_PENDING) | ||
11226 | return -EIO; | ||
11227 | |||
11228 | if (cmdlog && !priv->cmdlog) { | ||
11229 | priv->cmdlog = kcalloc(cmdlog, sizeof(*priv->cmdlog), | ||
11230 | GFP_KERNEL); | ||
11231 | if (priv->cmdlog == NULL) { | ||
11232 | IPW_ERROR("Error allocating %d command log entries.\n", | ||
11233 | cmdlog); | ||
11234 | return -ENOMEM; | ||
11235 | } else { | ||
11236 | priv->cmdlog_len = cmdlog; | ||
11237 | } | ||
11238 | } | ||
11239 | |||
11240 | for (i = 0; i < MAX_HW_RESTARTS; i++) { | ||
11241 | /* Load the microcode, firmware, and eeprom. | ||
11242 | * Also start the clocks. */ | ||
11243 | rc = ipw_load(priv); | ||
11244 | if (rc) { | ||
11245 | IPW_ERROR("Unable to load firmware: %d\n", rc); | ||
11246 | return rc; | ||
11247 | } | ||
11248 | |||
11249 | ipw_init_ordinals(priv); | ||
11250 | if (!(priv->config & CFG_CUSTOM_MAC)) | ||
11251 | eeprom_parse_mac(priv, priv->mac_addr); | ||
11252 | memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN); | ||
11253 | |||
11254 | for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) { | ||
11255 | if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE], | ||
11256 | ipw_geos[j].name, 3)) | ||
11257 | break; | ||
11258 | } | ||
11259 | if (j == ARRAY_SIZE(ipw_geos)) { | ||
11260 | IPW_WARNING("SKU [%c%c%c] not recognized.\n", | ||
11261 | priv->eeprom[EEPROM_COUNTRY_CODE + 0], | ||
11262 | priv->eeprom[EEPROM_COUNTRY_CODE + 1], | ||
11263 | priv->eeprom[EEPROM_COUNTRY_CODE + 2]); | ||
11264 | j = 0; | ||
11265 | } | ||
11266 | if (ieee80211_set_geo(priv->ieee, &ipw_geos[j])) { | ||
11267 | IPW_WARNING("Could not set geography."); | ||
11268 | return 0; | ||
11269 | } | ||
11270 | |||
11271 | if (priv->status & STATUS_RF_KILL_SW) { | ||
11272 | IPW_WARNING("Radio disabled by module parameter.\n"); | ||
11273 | return 0; | ||
11274 | } else if (rf_kill_active(priv)) { | ||
11275 | IPW_WARNING("Radio Frequency Kill Switch is On:\n" | ||
11276 | "Kill switch must be turned off for " | ||
11277 | "wireless networking to work.\n"); | ||
11278 | queue_delayed_work(priv->workqueue, &priv->rf_kill, | ||
11279 | 2 * HZ); | ||
11280 | return 0; | ||
11281 | } | ||
11282 | |||
11283 | rc = ipw_config(priv); | ||
11284 | if (!rc) { | ||
11285 | IPW_DEBUG_INFO("Configured device on count %i\n", i); | ||
11286 | |||
11287 | /* If configure to try and auto-associate, kick | ||
11288 | * off a scan. */ | ||
11289 | queue_delayed_work(priv->workqueue, | ||
11290 | &priv->request_scan, 0); | ||
11291 | |||
11292 | return 0; | ||
11293 | } | ||
11294 | |||
11295 | IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc); | ||
11296 | IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n", | ||
11297 | i, MAX_HW_RESTARTS); | ||
11298 | |||
11299 | /* We had an error bringing up the hardware, so take it | ||
11300 | * all the way back down so we can try again */ | ||
11301 | ipw_down(priv); | ||
11302 | } | ||
11303 | |||
11304 | /* tried to restart and config the device for as long as our | ||
11305 | * patience could withstand */ | ||
11306 | IPW_ERROR("Unable to initialize device after %d attempts.\n", i); | ||
11307 | |||
11308 | return -EIO; | ||
11309 | } | ||
11310 | |||
11311 | static void ipw_bg_up(struct work_struct *work) | ||
11312 | { | ||
11313 | struct ipw_priv *priv = | ||
11314 | container_of(work, struct ipw_priv, up); | ||
11315 | mutex_lock(&priv->mutex); | ||
11316 | ipw_up(priv); | ||
11317 | mutex_unlock(&priv->mutex); | ||
11318 | } | ||
11319 | |||
11320 | static void ipw_deinit(struct ipw_priv *priv) | ||
11321 | { | ||
11322 | int i; | ||
11323 | |||
11324 | if (priv->status & STATUS_SCANNING) { | ||
11325 | IPW_DEBUG_INFO("Aborting scan during shutdown.\n"); | ||
11326 | ipw_abort_scan(priv); | ||
11327 | } | ||
11328 | |||
11329 | if (priv->status & STATUS_ASSOCIATED) { | ||
11330 | IPW_DEBUG_INFO("Disassociating during shutdown.\n"); | ||
11331 | ipw_disassociate(priv); | ||
11332 | } | ||
11333 | |||
11334 | ipw_led_shutdown(priv); | ||
11335 | |||
11336 | /* Wait up to 1s for status to change to not scanning and not | ||
11337 | * associated (disassociation can take a while for a ful 802.11 | ||
11338 | * exchange */ | ||
11339 | for (i = 1000; i && (priv->status & | ||
11340 | (STATUS_DISASSOCIATING | | ||
11341 | STATUS_ASSOCIATED | STATUS_SCANNING)); i--) | ||
11342 | udelay(10); | ||
11343 | |||
11344 | if (priv->status & (STATUS_DISASSOCIATING | | ||
11345 | STATUS_ASSOCIATED | STATUS_SCANNING)) | ||
11346 | IPW_DEBUG_INFO("Still associated or scanning...\n"); | ||
11347 | else | ||
11348 | IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i); | ||
11349 | |||
11350 | /* Attempt to disable the card */ | ||
11351 | ipw_send_card_disable(priv, 0); | ||
11352 | |||
11353 | priv->status &= ~STATUS_INIT; | ||
11354 | } | ||
11355 | |||
11356 | static void ipw_down(struct ipw_priv *priv) | ||
11357 | { | ||
11358 | int exit_pending = priv->status & STATUS_EXIT_PENDING; | ||
11359 | |||
11360 | priv->status |= STATUS_EXIT_PENDING; | ||
11361 | |||
11362 | if (ipw_is_init(priv)) | ||
11363 | ipw_deinit(priv); | ||
11364 | |||
11365 | /* Wipe out the EXIT_PENDING status bit if we are not actually | ||
11366 | * exiting the module */ | ||
11367 | if (!exit_pending) | ||
11368 | priv->status &= ~STATUS_EXIT_PENDING; | ||
11369 | |||
11370 | /* tell the device to stop sending interrupts */ | ||
11371 | ipw_disable_interrupts(priv); | ||
11372 | |||
11373 | /* Clear all bits but the RF Kill */ | ||
11374 | priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING; | ||
11375 | netif_carrier_off(priv->net_dev); | ||
11376 | |||
11377 | ipw_stop_nic(priv); | ||
11378 | |||
11379 | ipw_led_radio_off(priv); | ||
11380 | } | ||
11381 | |||
11382 | static void ipw_bg_down(struct work_struct *work) | ||
11383 | { | ||
11384 | struct ipw_priv *priv = | ||
11385 | container_of(work, struct ipw_priv, down); | ||
11386 | mutex_lock(&priv->mutex); | ||
11387 | ipw_down(priv); | ||
11388 | mutex_unlock(&priv->mutex); | ||
11389 | } | ||
11390 | |||
11391 | /* Called by register_netdev() */ | ||
11392 | static int ipw_net_init(struct net_device *dev) | ||
11393 | { | ||
11394 | struct ipw_priv *priv = ieee80211_priv(dev); | ||
11395 | mutex_lock(&priv->mutex); | ||
11396 | |||
11397 | if (ipw_up(priv)) { | ||
11398 | mutex_unlock(&priv->mutex); | ||
11399 | return -EIO; | ||
11400 | } | ||
11401 | |||
11402 | mutex_unlock(&priv->mutex); | ||
11403 | return 0; | ||
11404 | } | ||
11405 | |||
11406 | /* PCI driver stuff */ | ||
11407 | static struct pci_device_id card_ids[] = { | ||
11408 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0}, | ||
11409 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0}, | ||
11410 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0}, | ||
11411 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0}, | ||
11412 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0}, | ||
11413 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0}, | ||
11414 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0}, | ||
11415 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0}, | ||
11416 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0}, | ||
11417 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0}, | ||
11418 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0}, | ||
11419 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0}, | ||
11420 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0}, | ||
11421 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0}, | ||
11422 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0}, | ||
11423 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0}, | ||
11424 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0}, | ||
11425 | {PCI_VENDOR_ID_INTEL, 0x104f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, | ||
11426 | {PCI_VENDOR_ID_INTEL, 0x4220, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */ | ||
11427 | {PCI_VENDOR_ID_INTEL, 0x4221, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */ | ||
11428 | {PCI_VENDOR_ID_INTEL, 0x4223, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */ | ||
11429 | {PCI_VENDOR_ID_INTEL, 0x4224, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */ | ||
11430 | |||
11431 | /* required last entry */ | ||
11432 | {0,} | ||
11433 | }; | ||
11434 | |||
11435 | MODULE_DEVICE_TABLE(pci, card_ids); | ||
11436 | |||
11437 | static struct attribute *ipw_sysfs_entries[] = { | ||
11438 | &dev_attr_rf_kill.attr, | ||
11439 | &dev_attr_direct_dword.attr, | ||
11440 | &dev_attr_indirect_byte.attr, | ||
11441 | &dev_attr_indirect_dword.attr, | ||
11442 | &dev_attr_mem_gpio_reg.attr, | ||
11443 | &dev_attr_command_event_reg.attr, | ||
11444 | &dev_attr_nic_type.attr, | ||
11445 | &dev_attr_status.attr, | ||
11446 | &dev_attr_cfg.attr, | ||
11447 | &dev_attr_error.attr, | ||
11448 | &dev_attr_event_log.attr, | ||
11449 | &dev_attr_cmd_log.attr, | ||
11450 | &dev_attr_eeprom_delay.attr, | ||
11451 | &dev_attr_ucode_version.attr, | ||
11452 | &dev_attr_rtc.attr, | ||
11453 | &dev_attr_scan_age.attr, | ||
11454 | &dev_attr_led.attr, | ||
11455 | &dev_attr_speed_scan.attr, | ||
11456 | &dev_attr_net_stats.attr, | ||
11457 | &dev_attr_channels.attr, | ||
11458 | #ifdef CONFIG_IPW2200_PROMISCUOUS | ||
11459 | &dev_attr_rtap_iface.attr, | ||
11460 | &dev_attr_rtap_filter.attr, | ||
11461 | #endif | ||
11462 | NULL | ||
11463 | }; | ||
11464 | |||
11465 | static struct attribute_group ipw_attribute_group = { | ||
11466 | .name = NULL, /* put in device directory */ | ||
11467 | .attrs = ipw_sysfs_entries, | ||
11468 | }; | ||
11469 | |||
11470 | #ifdef CONFIG_IPW2200_PROMISCUOUS | ||
11471 | static int ipw_prom_open(struct net_device *dev) | ||
11472 | { | ||
11473 | struct ipw_prom_priv *prom_priv = ieee80211_priv(dev); | ||
11474 | struct ipw_priv *priv = prom_priv->priv; | ||
11475 | |||
11476 | IPW_DEBUG_INFO("prom dev->open\n"); | ||
11477 | netif_carrier_off(dev); | ||
11478 | |||
11479 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { | ||
11480 | priv->sys_config.accept_all_data_frames = 1; | ||
11481 | priv->sys_config.accept_non_directed_frames = 1; | ||
11482 | priv->sys_config.accept_all_mgmt_bcpr = 1; | ||
11483 | priv->sys_config.accept_all_mgmt_frames = 1; | ||
11484 | |||
11485 | ipw_send_system_config(priv); | ||
11486 | } | ||
11487 | |||
11488 | return 0; | ||
11489 | } | ||
11490 | |||
11491 | static int ipw_prom_stop(struct net_device *dev) | ||
11492 | { | ||
11493 | struct ipw_prom_priv *prom_priv = ieee80211_priv(dev); | ||
11494 | struct ipw_priv *priv = prom_priv->priv; | ||
11495 | |||
11496 | IPW_DEBUG_INFO("prom dev->stop\n"); | ||
11497 | |||
11498 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { | ||
11499 | priv->sys_config.accept_all_data_frames = 0; | ||
11500 | priv->sys_config.accept_non_directed_frames = 0; | ||
11501 | priv->sys_config.accept_all_mgmt_bcpr = 0; | ||
11502 | priv->sys_config.accept_all_mgmt_frames = 0; | ||
11503 | |||
11504 | ipw_send_system_config(priv); | ||
11505 | } | ||
11506 | |||
11507 | return 0; | ||
11508 | } | ||
11509 | |||
11510 | static int ipw_prom_hard_start_xmit(struct sk_buff *skb, struct net_device *dev) | ||
11511 | { | ||
11512 | IPW_DEBUG_INFO("prom dev->xmit\n"); | ||
11513 | return -EOPNOTSUPP; | ||
11514 | } | ||
11515 | |||
11516 | static struct net_device_stats *ipw_prom_get_stats(struct net_device *dev) | ||
11517 | { | ||
11518 | struct ipw_prom_priv *prom_priv = ieee80211_priv(dev); | ||
11519 | return &prom_priv->ieee->stats; | ||
11520 | } | ||
11521 | |||
11522 | static int ipw_prom_alloc(struct ipw_priv *priv) | ||
11523 | { | ||
11524 | int rc = 0; | ||
11525 | |||
11526 | if (priv->prom_net_dev) | ||
11527 | return -EPERM; | ||
11528 | |||
11529 | priv->prom_net_dev = alloc_ieee80211(sizeof(struct ipw_prom_priv)); | ||
11530 | if (priv->prom_net_dev == NULL) | ||
11531 | return -ENOMEM; | ||
11532 | |||
11533 | priv->prom_priv = ieee80211_priv(priv->prom_net_dev); | ||
11534 | priv->prom_priv->ieee = netdev_priv(priv->prom_net_dev); | ||
11535 | priv->prom_priv->priv = priv; | ||
11536 | |||
11537 | strcpy(priv->prom_net_dev->name, "rtap%d"); | ||
11538 | memcpy(priv->prom_net_dev->dev_addr, priv->mac_addr, ETH_ALEN); | ||
11539 | |||
11540 | priv->prom_net_dev->type = ARPHRD_IEEE80211_RADIOTAP; | ||
11541 | priv->prom_net_dev->open = ipw_prom_open; | ||
11542 | priv->prom_net_dev->stop = ipw_prom_stop; | ||
11543 | priv->prom_net_dev->get_stats = ipw_prom_get_stats; | ||
11544 | priv->prom_net_dev->hard_start_xmit = ipw_prom_hard_start_xmit; | ||
11545 | |||
11546 | priv->prom_priv->ieee->iw_mode = IW_MODE_MONITOR; | ||
11547 | SET_NETDEV_DEV(priv->prom_net_dev, &priv->pci_dev->dev); | ||
11548 | |||
11549 | rc = register_netdev(priv->prom_net_dev); | ||
11550 | if (rc) { | ||
11551 | free_ieee80211(priv->prom_net_dev); | ||
11552 | priv->prom_net_dev = NULL; | ||
11553 | return rc; | ||
11554 | } | ||
11555 | |||
11556 | return 0; | ||
11557 | } | ||
11558 | |||
11559 | static void ipw_prom_free(struct ipw_priv *priv) | ||
11560 | { | ||
11561 | if (!priv->prom_net_dev) | ||
11562 | return; | ||
11563 | |||
11564 | unregister_netdev(priv->prom_net_dev); | ||
11565 | free_ieee80211(priv->prom_net_dev); | ||
11566 | |||
11567 | priv->prom_net_dev = NULL; | ||
11568 | } | ||
11569 | |||
11570 | #endif | ||
11571 | |||
11572 | |||
11573 | static int __devinit ipw_pci_probe(struct pci_dev *pdev, | ||
11574 | const struct pci_device_id *ent) | ||
11575 | { | ||
11576 | int err = 0; | ||
11577 | struct net_device *net_dev; | ||
11578 | void __iomem *base; | ||
11579 | u32 length, val; | ||
11580 | struct ipw_priv *priv; | ||
11581 | int i; | ||
11582 | |||
11583 | net_dev = alloc_ieee80211(sizeof(struct ipw_priv)); | ||
11584 | if (net_dev == NULL) { | ||
11585 | err = -ENOMEM; | ||
11586 | goto out; | ||
11587 | } | ||
11588 | |||
11589 | priv = ieee80211_priv(net_dev); | ||
11590 | priv->ieee = netdev_priv(net_dev); | ||
11591 | |||
11592 | priv->net_dev = net_dev; | ||
11593 | priv->pci_dev = pdev; | ||
11594 | ipw_debug_level = debug; | ||
11595 | spin_lock_init(&priv->irq_lock); | ||
11596 | spin_lock_init(&priv->lock); | ||
11597 | for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) | ||
11598 | INIT_LIST_HEAD(&priv->ibss_mac_hash[i]); | ||
11599 | |||
11600 | mutex_init(&priv->mutex); | ||
11601 | if (pci_enable_device(pdev)) { | ||
11602 | err = -ENODEV; | ||
11603 | goto out_free_ieee80211; | ||
11604 | } | ||
11605 | |||
11606 | pci_set_master(pdev); | ||
11607 | |||
11608 | err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); | ||
11609 | if (!err) | ||
11610 | err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); | ||
11611 | if (err) { | ||
11612 | printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n"); | ||
11613 | goto out_pci_disable_device; | ||
11614 | } | ||
11615 | |||
11616 | pci_set_drvdata(pdev, priv); | ||
11617 | |||
11618 | err = pci_request_regions(pdev, DRV_NAME); | ||
11619 | if (err) | ||
11620 | goto out_pci_disable_device; | ||
11621 | |||
11622 | /* We disable the RETRY_TIMEOUT register (0x41) to keep | ||
11623 | * PCI Tx retries from interfering with C3 CPU state */ | ||
11624 | pci_read_config_dword(pdev, 0x40, &val); | ||
11625 | if ((val & 0x0000ff00) != 0) | ||
11626 | pci_write_config_dword(pdev, 0x40, val & 0xffff00ff); | ||
11627 | |||
11628 | length = pci_resource_len(pdev, 0); | ||
11629 | priv->hw_len = length; | ||
11630 | |||
11631 | base = pci_ioremap_bar(pdev, 0); | ||
11632 | if (!base) { | ||
11633 | err = -ENODEV; | ||
11634 | goto out_pci_release_regions; | ||
11635 | } | ||
11636 | |||
11637 | priv->hw_base = base; | ||
11638 | IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length); | ||
11639 | IPW_DEBUG_INFO("pci_resource_base = %p\n", base); | ||
11640 | |||
11641 | err = ipw_setup_deferred_work(priv); | ||
11642 | if (err) { | ||
11643 | IPW_ERROR("Unable to setup deferred work\n"); | ||
11644 | goto out_iounmap; | ||
11645 | } | ||
11646 | |||
11647 | ipw_sw_reset(priv, 1); | ||
11648 | |||
11649 | err = request_irq(pdev->irq, ipw_isr, IRQF_SHARED, DRV_NAME, priv); | ||
11650 | if (err) { | ||
11651 | IPW_ERROR("Error allocating IRQ %d\n", pdev->irq); | ||
11652 | goto out_destroy_workqueue; | ||
11653 | } | ||
11654 | |||
11655 | SET_NETDEV_DEV(net_dev, &pdev->dev); | ||
11656 | |||
11657 | mutex_lock(&priv->mutex); | ||
11658 | |||
11659 | priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit; | ||
11660 | priv->ieee->set_security = shim__set_security; | ||
11661 | priv->ieee->is_queue_full = ipw_net_is_queue_full; | ||
11662 | |||
11663 | #ifdef CONFIG_IPW2200_QOS | ||
11664 | priv->ieee->is_qos_active = ipw_is_qos_active; | ||
11665 | priv->ieee->handle_probe_response = ipw_handle_beacon; | ||
11666 | priv->ieee->handle_beacon = ipw_handle_probe_response; | ||
11667 | priv->ieee->handle_assoc_response = ipw_handle_assoc_response; | ||
11668 | #endif /* CONFIG_IPW2200_QOS */ | ||
11669 | |||
11670 | priv->ieee->perfect_rssi = -20; | ||
11671 | priv->ieee->worst_rssi = -85; | ||
11672 | |||
11673 | net_dev->open = ipw_net_open; | ||
11674 | net_dev->stop = ipw_net_stop; | ||
11675 | net_dev->init = ipw_net_init; | ||
11676 | net_dev->get_stats = ipw_net_get_stats; | ||
11677 | net_dev->set_multicast_list = ipw_net_set_multicast_list; | ||
11678 | net_dev->set_mac_address = ipw_net_set_mac_address; | ||
11679 | priv->wireless_data.spy_data = &priv->ieee->spy_data; | ||
11680 | net_dev->wireless_data = &priv->wireless_data; | ||
11681 | net_dev->wireless_handlers = &ipw_wx_handler_def; | ||
11682 | net_dev->ethtool_ops = &ipw_ethtool_ops; | ||
11683 | net_dev->irq = pdev->irq; | ||
11684 | net_dev->base_addr = (unsigned long)priv->hw_base; | ||
11685 | net_dev->mem_start = pci_resource_start(pdev, 0); | ||
11686 | net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1; | ||
11687 | |||
11688 | err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group); | ||
11689 | if (err) { | ||
11690 | IPW_ERROR("failed to create sysfs device attributes\n"); | ||
11691 | mutex_unlock(&priv->mutex); | ||
11692 | goto out_release_irq; | ||
11693 | } | ||
11694 | |||
11695 | mutex_unlock(&priv->mutex); | ||
11696 | err = register_netdev(net_dev); | ||
11697 | if (err) { | ||
11698 | IPW_ERROR("failed to register network device\n"); | ||
11699 | goto out_remove_sysfs; | ||
11700 | } | ||
11701 | |||
11702 | #ifdef CONFIG_IPW2200_PROMISCUOUS | ||
11703 | if (rtap_iface) { | ||
11704 | err = ipw_prom_alloc(priv); | ||
11705 | if (err) { | ||
11706 | IPW_ERROR("Failed to register promiscuous network " | ||
11707 | "device (error %d).\n", err); | ||
11708 | unregister_netdev(priv->net_dev); | ||
11709 | goto out_remove_sysfs; | ||
11710 | } | ||
11711 | } | ||
11712 | #endif | ||
11713 | |||
11714 | printk(KERN_INFO DRV_NAME ": Detected geography %s (%d 802.11bg " | ||
11715 | "channels, %d 802.11a channels)\n", | ||
11716 | priv->ieee->geo.name, priv->ieee->geo.bg_channels, | ||
11717 | priv->ieee->geo.a_channels); | ||
11718 | |||
11719 | return 0; | ||
11720 | |||
11721 | out_remove_sysfs: | ||
11722 | sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group); | ||
11723 | out_release_irq: | ||
11724 | free_irq(pdev->irq, priv); | ||
11725 | out_destroy_workqueue: | ||
11726 | destroy_workqueue(priv->workqueue); | ||
11727 | priv->workqueue = NULL; | ||
11728 | out_iounmap: | ||
11729 | iounmap(priv->hw_base); | ||
11730 | out_pci_release_regions: | ||
11731 | pci_release_regions(pdev); | ||
11732 | out_pci_disable_device: | ||
11733 | pci_disable_device(pdev); | ||
11734 | pci_set_drvdata(pdev, NULL); | ||
11735 | out_free_ieee80211: | ||
11736 | free_ieee80211(priv->net_dev); | ||
11737 | out: | ||
11738 | return err; | ||
11739 | } | ||
11740 | |||
11741 | static void __devexit ipw_pci_remove(struct pci_dev *pdev) | ||
11742 | { | ||
11743 | struct ipw_priv *priv = pci_get_drvdata(pdev); | ||
11744 | struct list_head *p, *q; | ||
11745 | int i; | ||
11746 | |||
11747 | if (!priv) | ||
11748 | return; | ||
11749 | |||
11750 | mutex_lock(&priv->mutex); | ||
11751 | |||
11752 | priv->status |= STATUS_EXIT_PENDING; | ||
11753 | ipw_down(priv); | ||
11754 | sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group); | ||
11755 | |||
11756 | mutex_unlock(&priv->mutex); | ||
11757 | |||
11758 | unregister_netdev(priv->net_dev); | ||
11759 | |||
11760 | if (priv->rxq) { | ||
11761 | ipw_rx_queue_free(priv, priv->rxq); | ||
11762 | priv->rxq = NULL; | ||
11763 | } | ||
11764 | ipw_tx_queue_free(priv); | ||
11765 | |||
11766 | if (priv->cmdlog) { | ||
11767 | kfree(priv->cmdlog); | ||
11768 | priv->cmdlog = NULL; | ||
11769 | } | ||
11770 | /* ipw_down will ensure that there is no more pending work | ||
11771 | * in the workqueue's, so we can safely remove them now. */ | ||
11772 | cancel_delayed_work(&priv->adhoc_check); | ||
11773 | cancel_delayed_work(&priv->gather_stats); | ||
11774 | cancel_delayed_work(&priv->request_scan); | ||
11775 | cancel_delayed_work(&priv->request_direct_scan); | ||
11776 | cancel_delayed_work(&priv->request_passive_scan); | ||
11777 | cancel_delayed_work(&priv->scan_event); | ||
11778 | cancel_delayed_work(&priv->rf_kill); | ||
11779 | cancel_delayed_work(&priv->scan_check); | ||
11780 | destroy_workqueue(priv->workqueue); | ||
11781 | priv->workqueue = NULL; | ||
11782 | |||
11783 | /* Free MAC hash list for ADHOC */ | ||
11784 | for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) { | ||
11785 | list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) { | ||
11786 | list_del(p); | ||
11787 | kfree(list_entry(p, struct ipw_ibss_seq, list)); | ||
11788 | } | ||
11789 | } | ||
11790 | |||
11791 | kfree(priv->error); | ||
11792 | priv->error = NULL; | ||
11793 | |||
11794 | #ifdef CONFIG_IPW2200_PROMISCUOUS | ||
11795 | ipw_prom_free(priv); | ||
11796 | #endif | ||
11797 | |||
11798 | free_irq(pdev->irq, priv); | ||
11799 | iounmap(priv->hw_base); | ||
11800 | pci_release_regions(pdev); | ||
11801 | pci_disable_device(pdev); | ||
11802 | pci_set_drvdata(pdev, NULL); | ||
11803 | free_ieee80211(priv->net_dev); | ||
11804 | free_firmware(); | ||
11805 | } | ||
11806 | |||
11807 | #ifdef CONFIG_PM | ||
11808 | static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state) | ||
11809 | { | ||
11810 | struct ipw_priv *priv = pci_get_drvdata(pdev); | ||
11811 | struct net_device *dev = priv->net_dev; | ||
11812 | |||
11813 | printk(KERN_INFO "%s: Going into suspend...\n", dev->name); | ||
11814 | |||
11815 | /* Take down the device; powers it off, etc. */ | ||
11816 | ipw_down(priv); | ||
11817 | |||
11818 | /* Remove the PRESENT state of the device */ | ||
11819 | netif_device_detach(dev); | ||
11820 | |||
11821 | pci_save_state(pdev); | ||
11822 | pci_disable_device(pdev); | ||
11823 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); | ||
11824 | |||
11825 | return 0; | ||
11826 | } | ||
11827 | |||
11828 | static int ipw_pci_resume(struct pci_dev *pdev) | ||
11829 | { | ||
11830 | struct ipw_priv *priv = pci_get_drvdata(pdev); | ||
11831 | struct net_device *dev = priv->net_dev; | ||
11832 | int err; | ||
11833 | u32 val; | ||
11834 | |||
11835 | printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name); | ||
11836 | |||
11837 | pci_set_power_state(pdev, PCI_D0); | ||
11838 | err = pci_enable_device(pdev); | ||
11839 | if (err) { | ||
11840 | printk(KERN_ERR "%s: pci_enable_device failed on resume\n", | ||
11841 | dev->name); | ||
11842 | return err; | ||
11843 | } | ||
11844 | pci_restore_state(pdev); | ||
11845 | |||
11846 | /* | ||
11847 | * Suspend/Resume resets the PCI configuration space, so we have to | ||
11848 | * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries | ||
11849 | * from interfering with C3 CPU state. pci_restore_state won't help | ||
11850 | * here since it only restores the first 64 bytes pci config header. | ||
11851 | */ | ||
11852 | pci_read_config_dword(pdev, 0x40, &val); | ||
11853 | if ((val & 0x0000ff00) != 0) | ||
11854 | pci_write_config_dword(pdev, 0x40, val & 0xffff00ff); | ||
11855 | |||
11856 | /* Set the device back into the PRESENT state; this will also wake | ||
11857 | * the queue of needed */ | ||
11858 | netif_device_attach(dev); | ||
11859 | |||
11860 | /* Bring the device back up */ | ||
11861 | queue_work(priv->workqueue, &priv->up); | ||
11862 | |||
11863 | return 0; | ||
11864 | } | ||
11865 | #endif | ||
11866 | |||
11867 | static void ipw_pci_shutdown(struct pci_dev *pdev) | ||
11868 | { | ||
11869 | struct ipw_priv *priv = pci_get_drvdata(pdev); | ||
11870 | |||
11871 | /* Take down the device; powers it off, etc. */ | ||
11872 | ipw_down(priv); | ||
11873 | |||
11874 | pci_disable_device(pdev); | ||
11875 | } | ||
11876 | |||
11877 | /* driver initialization stuff */ | ||
11878 | static struct pci_driver ipw_driver = { | ||
11879 | .name = DRV_NAME, | ||
11880 | .id_table = card_ids, | ||
11881 | .probe = ipw_pci_probe, | ||
11882 | .remove = __devexit_p(ipw_pci_remove), | ||
11883 | #ifdef CONFIG_PM | ||
11884 | .suspend = ipw_pci_suspend, | ||
11885 | .resume = ipw_pci_resume, | ||
11886 | #endif | ||
11887 | .shutdown = ipw_pci_shutdown, | ||
11888 | }; | ||
11889 | |||
11890 | static int __init ipw_init(void) | ||
11891 | { | ||
11892 | int ret; | ||
11893 | |||
11894 | printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n"); | ||
11895 | printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n"); | ||
11896 | |||
11897 | ret = pci_register_driver(&ipw_driver); | ||
11898 | if (ret) { | ||
11899 | IPW_ERROR("Unable to initialize PCI module\n"); | ||
11900 | return ret; | ||
11901 | } | ||
11902 | |||
11903 | ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level); | ||
11904 | if (ret) { | ||
11905 | IPW_ERROR("Unable to create driver sysfs file\n"); | ||
11906 | pci_unregister_driver(&ipw_driver); | ||
11907 | return ret; | ||
11908 | } | ||
11909 | |||
11910 | return ret; | ||
11911 | } | ||
11912 | |||
11913 | static void __exit ipw_exit(void) | ||
11914 | { | ||
11915 | driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level); | ||
11916 | pci_unregister_driver(&ipw_driver); | ||
11917 | } | ||
11918 | |||
11919 | module_param(disable, int, 0444); | ||
11920 | MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])"); | ||
11921 | |||
11922 | module_param(associate, int, 0444); | ||
11923 | MODULE_PARM_DESC(associate, "auto associate when scanning (default off)"); | ||
11924 | |||
11925 | module_param(auto_create, int, 0444); | ||
11926 | MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)"); | ||
11927 | |||
11928 | module_param(led, int, 0444); | ||
11929 | MODULE_PARM_DESC(led, "enable led control on some systems (default 0 off)"); | ||
11930 | |||
11931 | module_param(debug, int, 0444); | ||
11932 | MODULE_PARM_DESC(debug, "debug output mask"); | ||
11933 | |||
11934 | module_param(channel, int, 0444); | ||
11935 | MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])"); | ||
11936 | |||
11937 | #ifdef CONFIG_IPW2200_PROMISCUOUS | ||
11938 | module_param(rtap_iface, int, 0444); | ||
11939 | MODULE_PARM_DESC(rtap_iface, "create the rtap interface (1 - create, default 0)"); | ||
11940 | #endif | ||
11941 | |||
11942 | #ifdef CONFIG_IPW2200_QOS | ||
11943 | module_param(qos_enable, int, 0444); | ||
11944 | MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis"); | ||
11945 | |||
11946 | module_param(qos_burst_enable, int, 0444); | ||
11947 | MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode"); | ||
11948 | |||
11949 | module_param(qos_no_ack_mask, int, 0444); | ||
11950 | MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack"); | ||
11951 | |||
11952 | module_param(burst_duration_CCK, int, 0444); | ||
11953 | MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value"); | ||
11954 | |||
11955 | module_param(burst_duration_OFDM, int, 0444); | ||
11956 | MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value"); | ||
11957 | #endif /* CONFIG_IPW2200_QOS */ | ||
11958 | |||
11959 | #ifdef CONFIG_IPW2200_MONITOR | ||
11960 | module_param(mode, int, 0444); | ||
11961 | MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)"); | ||
11962 | #else | ||
11963 | module_param(mode, int, 0444); | ||
11964 | MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)"); | ||
11965 | #endif | ||
11966 | |||
11967 | module_param(bt_coexist, int, 0444); | ||
11968 | MODULE_PARM_DESC(bt_coexist, "enable bluetooth coexistence (default off)"); | ||
11969 | |||
11970 | module_param(hwcrypto, int, 0444); | ||
11971 | MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default off)"); | ||
11972 | |||
11973 | module_param(cmdlog, int, 0444); | ||
11974 | MODULE_PARM_DESC(cmdlog, | ||
11975 | "allocate a ring buffer for logging firmware commands"); | ||
11976 | |||
11977 | module_param(roaming, int, 0444); | ||
11978 | MODULE_PARM_DESC(roaming, "enable roaming support (default on)"); | ||
11979 | |||
11980 | module_param(antenna, int, 0444); | ||
11981 | MODULE_PARM_DESC(antenna, "select antenna 1=Main, 3=Aux, default 0 [both], 2=slow_diversity (choose the one with lower background noise)"); | ||
11982 | |||
11983 | module_exit(ipw_exit); | ||
11984 | module_init(ipw_init); | ||
diff --git a/drivers/net/wireless/ipw2x00/ipw2200.h b/drivers/net/wireless/ipw2x00/ipw2200.h new file mode 100644 index 000000000000..0a84d52147bd --- /dev/null +++ b/drivers/net/wireless/ipw2x00/ipw2200.h | |||
@@ -0,0 +1,2011 @@ | |||
1 | /****************************************************************************** | ||
2 | |||
3 | Copyright(c) 2003 - 2006 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., 59 | ||
16 | Temple Place - Suite 330, Boston, MA 02111-1307, 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 | James P. Ketrenos <ipw2100-admin@linux.intel.com> | ||
23 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
24 | |||
25 | ******************************************************************************/ | ||
26 | |||
27 | #ifndef __ipw2200_h__ | ||
28 | #define __ipw2200_h__ | ||
29 | |||
30 | #define WEXT_USECHANNELS 1 | ||
31 | |||
32 | #include <linux/module.h> | ||
33 | #include <linux/moduleparam.h> | ||
34 | #include <linux/init.h> | ||
35 | #include <linux/mutex.h> | ||
36 | |||
37 | #include <linux/pci.h> | ||
38 | #include <linux/netdevice.h> | ||
39 | #include <linux/ethtool.h> | ||
40 | #include <linux/skbuff.h> | ||
41 | #include <linux/etherdevice.h> | ||
42 | #include <linux/delay.h> | ||
43 | #include <linux/random.h> | ||
44 | #include <linux/dma-mapping.h> | ||
45 | |||
46 | #include <linux/firmware.h> | ||
47 | #include <linux/wireless.h> | ||
48 | #include <linux/jiffies.h> | ||
49 | #include <asm/io.h> | ||
50 | |||
51 | #include <net/lib80211.h> | ||
52 | #include <net/ieee80211.h> | ||
53 | #include <net/ieee80211_radiotap.h> | ||
54 | |||
55 | #define DRV_NAME "ipw2200" | ||
56 | |||
57 | #include <linux/workqueue.h> | ||
58 | |||
59 | /* Authentication and Association States */ | ||
60 | enum connection_manager_assoc_states { | ||
61 | CMAS_INIT = 0, | ||
62 | CMAS_TX_AUTH_SEQ_1, | ||
63 | CMAS_RX_AUTH_SEQ_2, | ||
64 | CMAS_AUTH_SEQ_1_PASS, | ||
65 | CMAS_AUTH_SEQ_1_FAIL, | ||
66 | CMAS_TX_AUTH_SEQ_3, | ||
67 | CMAS_RX_AUTH_SEQ_4, | ||
68 | CMAS_AUTH_SEQ_2_PASS, | ||
69 | CMAS_AUTH_SEQ_2_FAIL, | ||
70 | CMAS_AUTHENTICATED, | ||
71 | CMAS_TX_ASSOC, | ||
72 | CMAS_RX_ASSOC_RESP, | ||
73 | CMAS_ASSOCIATED, | ||
74 | CMAS_LAST | ||
75 | }; | ||
76 | |||
77 | #define IPW_WAIT (1<<0) | ||
78 | #define IPW_QUIET (1<<1) | ||
79 | #define IPW_ROAMING (1<<2) | ||
80 | |||
81 | #define IPW_POWER_MODE_CAM 0x00 //(always on) | ||
82 | #define IPW_POWER_INDEX_1 0x01 | ||
83 | #define IPW_POWER_INDEX_2 0x02 | ||
84 | #define IPW_POWER_INDEX_3 0x03 | ||
85 | #define IPW_POWER_INDEX_4 0x04 | ||
86 | #define IPW_POWER_INDEX_5 0x05 | ||
87 | #define IPW_POWER_AC 0x06 | ||
88 | #define IPW_POWER_BATTERY 0x07 | ||
89 | #define IPW_POWER_LIMIT 0x07 | ||
90 | #define IPW_POWER_MASK 0x0F | ||
91 | #define IPW_POWER_ENABLED 0x10 | ||
92 | #define IPW_POWER_LEVEL(x) ((x) & IPW_POWER_MASK) | ||
93 | |||
94 | #define IPW_CMD_HOST_COMPLETE 2 | ||
95 | #define IPW_CMD_POWER_DOWN 4 | ||
96 | #define IPW_CMD_SYSTEM_CONFIG 6 | ||
97 | #define IPW_CMD_MULTICAST_ADDRESS 7 | ||
98 | #define IPW_CMD_SSID 8 | ||
99 | #define IPW_CMD_ADAPTER_ADDRESS 11 | ||
100 | #define IPW_CMD_PORT_TYPE 12 | ||
101 | #define IPW_CMD_RTS_THRESHOLD 15 | ||
102 | #define IPW_CMD_FRAG_THRESHOLD 16 | ||
103 | #define IPW_CMD_POWER_MODE 17 | ||
104 | #define IPW_CMD_WEP_KEY 18 | ||
105 | #define IPW_CMD_TGI_TX_KEY 19 | ||
106 | #define IPW_CMD_SCAN_REQUEST 20 | ||
107 | #define IPW_CMD_ASSOCIATE 21 | ||
108 | #define IPW_CMD_SUPPORTED_RATES 22 | ||
109 | #define IPW_CMD_SCAN_ABORT 23 | ||
110 | #define IPW_CMD_TX_FLUSH 24 | ||
111 | #define IPW_CMD_QOS_PARAMETERS 25 | ||
112 | #define IPW_CMD_SCAN_REQUEST_EXT 26 | ||
113 | #define IPW_CMD_DINO_CONFIG 30 | ||
114 | #define IPW_CMD_RSN_CAPABILITIES 31 | ||
115 | #define IPW_CMD_RX_KEY 32 | ||
116 | #define IPW_CMD_CARD_DISABLE 33 | ||
117 | #define IPW_CMD_SEED_NUMBER 34 | ||
118 | #define IPW_CMD_TX_POWER 35 | ||
119 | #define IPW_CMD_COUNTRY_INFO 36 | ||
120 | #define IPW_CMD_AIRONET_INFO 37 | ||
121 | #define IPW_CMD_AP_TX_POWER 38 | ||
122 | #define IPW_CMD_CCKM_INFO 39 | ||
123 | #define IPW_CMD_CCX_VER_INFO 40 | ||
124 | #define IPW_CMD_SET_CALIBRATION 41 | ||
125 | #define IPW_CMD_SENSITIVITY_CALIB 42 | ||
126 | #define IPW_CMD_RETRY_LIMIT 51 | ||
127 | #define IPW_CMD_IPW_PRE_POWER_DOWN 58 | ||
128 | #define IPW_CMD_VAP_BEACON_TEMPLATE 60 | ||
129 | #define IPW_CMD_VAP_DTIM_PERIOD 61 | ||
130 | #define IPW_CMD_EXT_SUPPORTED_RATES 62 | ||
131 | #define IPW_CMD_VAP_LOCAL_TX_PWR_CONSTRAINT 63 | ||
132 | #define IPW_CMD_VAP_QUIET_INTERVALS 64 | ||
133 | #define IPW_CMD_VAP_CHANNEL_SWITCH 65 | ||
134 | #define IPW_CMD_VAP_MANDATORY_CHANNELS 66 | ||
135 | #define IPW_CMD_VAP_CELL_PWR_LIMIT 67 | ||
136 | #define IPW_CMD_VAP_CF_PARAM_SET 68 | ||
137 | #define IPW_CMD_VAP_SET_BEACONING_STATE 69 | ||
138 | #define IPW_CMD_MEASUREMENT 80 | ||
139 | #define IPW_CMD_POWER_CAPABILITY 81 | ||
140 | #define IPW_CMD_SUPPORTED_CHANNELS 82 | ||
141 | #define IPW_CMD_TPC_REPORT 83 | ||
142 | #define IPW_CMD_WME_INFO 84 | ||
143 | #define IPW_CMD_PRODUCTION_COMMAND 85 | ||
144 | #define IPW_CMD_LINKSYS_EOU_INFO 90 | ||
145 | |||
146 | #define RFD_SIZE 4 | ||
147 | #define NUM_TFD_CHUNKS 6 | ||
148 | |||
149 | #define TX_QUEUE_SIZE 32 | ||
150 | #define RX_QUEUE_SIZE 32 | ||
151 | |||
152 | #define DINO_CMD_WEP_KEY 0x08 | ||
153 | #define DINO_CMD_TX 0x0B | ||
154 | #define DCT_ANTENNA_A 0x01 | ||
155 | #define DCT_ANTENNA_B 0x02 | ||
156 | |||
157 | #define IPW_A_MODE 0 | ||
158 | #define IPW_B_MODE 1 | ||
159 | #define IPW_G_MODE 2 | ||
160 | |||
161 | /* | ||
162 | * TX Queue Flag Definitions | ||
163 | */ | ||
164 | |||
165 | /* tx wep key definition */ | ||
166 | #define DCT_WEP_KEY_NOT_IMMIDIATE 0x00 | ||
167 | #define DCT_WEP_KEY_64Bit 0x40 | ||
168 | #define DCT_WEP_KEY_128Bit 0x80 | ||
169 | #define DCT_WEP_KEY_128bitIV 0xC0 | ||
170 | #define DCT_WEP_KEY_SIZE_MASK 0xC0 | ||
171 | |||
172 | #define DCT_WEP_KEY_INDEX_MASK 0x0F | ||
173 | #define DCT_WEP_INDEX_USE_IMMEDIATE 0x20 | ||
174 | |||
175 | /* abort attempt if mgmt frame is rx'd */ | ||
176 | #define DCT_FLAG_ABORT_MGMT 0x01 | ||
177 | |||
178 | /* require CTS */ | ||
179 | #define DCT_FLAG_CTS_REQUIRED 0x02 | ||
180 | |||
181 | /* use short preamble */ | ||
182 | #define DCT_FLAG_LONG_PREAMBLE 0x00 | ||
183 | #define DCT_FLAG_SHORT_PREAMBLE 0x04 | ||
184 | |||
185 | /* RTS/CTS first */ | ||
186 | #define DCT_FLAG_RTS_REQD 0x08 | ||
187 | |||
188 | /* dont calculate duration field */ | ||
189 | #define DCT_FLAG_DUR_SET 0x10 | ||
190 | |||
191 | /* even if MAC WEP set (allows pre-encrypt) */ | ||
192 | #define DCT_FLAG_NO_WEP 0x20 | ||
193 | |||
194 | /* overwrite TSF field */ | ||
195 | #define DCT_FLAG_TSF_REQD 0x40 | ||
196 | |||
197 | /* ACK rx is expected to follow */ | ||
198 | #define DCT_FLAG_ACK_REQD 0x80 | ||
199 | |||
200 | /* TX flags extension */ | ||
201 | #define DCT_FLAG_EXT_MODE_CCK 0x01 | ||
202 | #define DCT_FLAG_EXT_MODE_OFDM 0x00 | ||
203 | |||
204 | #define DCT_FLAG_EXT_SECURITY_WEP 0x00 | ||
205 | #define DCT_FLAG_EXT_SECURITY_NO DCT_FLAG_EXT_SECURITY_WEP | ||
206 | #define DCT_FLAG_EXT_SECURITY_CKIP 0x04 | ||
207 | #define DCT_FLAG_EXT_SECURITY_CCM 0x08 | ||
208 | #define DCT_FLAG_EXT_SECURITY_TKIP 0x0C | ||
209 | #define DCT_FLAG_EXT_SECURITY_MASK 0x0C | ||
210 | |||
211 | #define DCT_FLAG_EXT_QOS_ENABLED 0x10 | ||
212 | |||
213 | #define DCT_FLAG_EXT_HC_NO_SIFS_PIFS 0x00 | ||
214 | #define DCT_FLAG_EXT_HC_SIFS 0x20 | ||
215 | #define DCT_FLAG_EXT_HC_PIFS 0x40 | ||
216 | |||
217 | #define TX_RX_TYPE_MASK 0xFF | ||
218 | #define TX_FRAME_TYPE 0x00 | ||
219 | #define TX_HOST_COMMAND_TYPE 0x01 | ||
220 | #define RX_FRAME_TYPE 0x09 | ||
221 | #define RX_HOST_NOTIFICATION_TYPE 0x03 | ||
222 | #define RX_HOST_CMD_RESPONSE_TYPE 0x04 | ||
223 | #define RX_TX_FRAME_RESPONSE_TYPE 0x05 | ||
224 | #define TFD_NEED_IRQ_MASK 0x04 | ||
225 | |||
226 | #define HOST_CMD_DINO_CONFIG 30 | ||
227 | |||
228 | #define HOST_NOTIFICATION_STATUS_ASSOCIATED 10 | ||
229 | #define HOST_NOTIFICATION_STATUS_AUTHENTICATE 11 | ||
230 | #define HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT 12 | ||
231 | #define HOST_NOTIFICATION_STATUS_SCAN_COMPLETED 13 | ||
232 | #define HOST_NOTIFICATION_STATUS_FRAG_LENGTH 14 | ||
233 | #define HOST_NOTIFICATION_STATUS_LINK_DETERIORATION 15 | ||
234 | #define HOST_NOTIFICATION_DINO_CONFIG_RESPONSE 16 | ||
235 | #define HOST_NOTIFICATION_STATUS_BEACON_STATE 17 | ||
236 | #define HOST_NOTIFICATION_STATUS_TGI_TX_KEY 18 | ||
237 | #define HOST_NOTIFICATION_TX_STATUS 19 | ||
238 | #define HOST_NOTIFICATION_CALIB_KEEP_RESULTS 20 | ||
239 | #define HOST_NOTIFICATION_MEASUREMENT_STARTED 21 | ||
240 | #define HOST_NOTIFICATION_MEASUREMENT_ENDED 22 | ||
241 | #define HOST_NOTIFICATION_CHANNEL_SWITCHED 23 | ||
242 | #define HOST_NOTIFICATION_RX_DURING_QUIET_PERIOD 24 | ||
243 | #define HOST_NOTIFICATION_NOISE_STATS 25 | ||
244 | #define HOST_NOTIFICATION_S36_MEASUREMENT_ACCEPTED 30 | ||
245 | #define HOST_NOTIFICATION_S36_MEASUREMENT_REFUSED 31 | ||
246 | |||
247 | #define HOST_NOTIFICATION_STATUS_BEACON_MISSING 1 | ||
248 | #define IPW_MB_ROAMING_THRESHOLD_MIN 1 | ||
249 | #define IPW_MB_ROAMING_THRESHOLD_DEFAULT 8 | ||
250 | #define IPW_MB_ROAMING_THRESHOLD_MAX 30 | ||
251 | #define IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT 3*IPW_MB_ROAMING_THRESHOLD_DEFAULT | ||
252 | #define IPW_REAL_RATE_RX_PACKET_THRESHOLD 300 | ||
253 | |||
254 | #define MACADRR_BYTE_LEN 6 | ||
255 | |||
256 | #define DCR_TYPE_AP 0x01 | ||
257 | #define DCR_TYPE_WLAP 0x02 | ||
258 | #define DCR_TYPE_MU_ESS 0x03 | ||
259 | #define DCR_TYPE_MU_IBSS 0x04 | ||
260 | #define DCR_TYPE_MU_PIBSS 0x05 | ||
261 | #define DCR_TYPE_SNIFFER 0x06 | ||
262 | #define DCR_TYPE_MU_BSS DCR_TYPE_MU_ESS | ||
263 | |||
264 | /* QoS definitions */ | ||
265 | |||
266 | #define CW_MIN_OFDM 15 | ||
267 | #define CW_MAX_OFDM 1023 | ||
268 | #define CW_MIN_CCK 31 | ||
269 | #define CW_MAX_CCK 1023 | ||
270 | |||
271 | #define QOS_TX0_CW_MIN_OFDM cpu_to_le16(CW_MIN_OFDM) | ||
272 | #define QOS_TX1_CW_MIN_OFDM cpu_to_le16(CW_MIN_OFDM) | ||
273 | #define QOS_TX2_CW_MIN_OFDM cpu_to_le16((CW_MIN_OFDM + 1)/2 - 1) | ||
274 | #define QOS_TX3_CW_MIN_OFDM cpu_to_le16((CW_MIN_OFDM + 1)/4 - 1) | ||
275 | |||
276 | #define QOS_TX0_CW_MIN_CCK cpu_to_le16(CW_MIN_CCK) | ||
277 | #define QOS_TX1_CW_MIN_CCK cpu_to_le16(CW_MIN_CCK) | ||
278 | #define QOS_TX2_CW_MIN_CCK cpu_to_le16((CW_MIN_CCK + 1)/2 - 1) | ||
279 | #define QOS_TX3_CW_MIN_CCK cpu_to_le16((CW_MIN_CCK + 1)/4 - 1) | ||
280 | |||
281 | #define QOS_TX0_CW_MAX_OFDM cpu_to_le16(CW_MAX_OFDM) | ||
282 | #define QOS_TX1_CW_MAX_OFDM cpu_to_le16(CW_MAX_OFDM) | ||
283 | #define QOS_TX2_CW_MAX_OFDM cpu_to_le16(CW_MIN_OFDM) | ||
284 | #define QOS_TX3_CW_MAX_OFDM cpu_to_le16((CW_MIN_OFDM + 1)/2 - 1) | ||
285 | |||
286 | #define QOS_TX0_CW_MAX_CCK cpu_to_le16(CW_MAX_CCK) | ||
287 | #define QOS_TX1_CW_MAX_CCK cpu_to_le16(CW_MAX_CCK) | ||
288 | #define QOS_TX2_CW_MAX_CCK cpu_to_le16(CW_MIN_CCK) | ||
289 | #define QOS_TX3_CW_MAX_CCK cpu_to_le16((CW_MIN_CCK + 1)/2 - 1) | ||
290 | |||
291 | #define QOS_TX0_AIFS (3 - QOS_AIFSN_MIN_VALUE) | ||
292 | #define QOS_TX1_AIFS (7 - QOS_AIFSN_MIN_VALUE) | ||
293 | #define QOS_TX2_AIFS (2 - QOS_AIFSN_MIN_VALUE) | ||
294 | #define QOS_TX3_AIFS (2 - QOS_AIFSN_MIN_VALUE) | ||
295 | |||
296 | #define QOS_TX0_ACM 0 | ||
297 | #define QOS_TX1_ACM 0 | ||
298 | #define QOS_TX2_ACM 0 | ||
299 | #define QOS_TX3_ACM 0 | ||
300 | |||
301 | #define QOS_TX0_TXOP_LIMIT_CCK 0 | ||
302 | #define QOS_TX1_TXOP_LIMIT_CCK 0 | ||
303 | #define QOS_TX2_TXOP_LIMIT_CCK cpu_to_le16(6016) | ||
304 | #define QOS_TX3_TXOP_LIMIT_CCK cpu_to_le16(3264) | ||
305 | |||
306 | #define QOS_TX0_TXOP_LIMIT_OFDM 0 | ||
307 | #define QOS_TX1_TXOP_LIMIT_OFDM 0 | ||
308 | #define QOS_TX2_TXOP_LIMIT_OFDM cpu_to_le16(3008) | ||
309 | #define QOS_TX3_TXOP_LIMIT_OFDM cpu_to_le16(1504) | ||
310 | |||
311 | #define DEF_TX0_CW_MIN_OFDM cpu_to_le16(CW_MIN_OFDM) | ||
312 | #define DEF_TX1_CW_MIN_OFDM cpu_to_le16(CW_MIN_OFDM) | ||
313 | #define DEF_TX2_CW_MIN_OFDM cpu_to_le16(CW_MIN_OFDM) | ||
314 | #define DEF_TX3_CW_MIN_OFDM cpu_to_le16(CW_MIN_OFDM) | ||
315 | |||
316 | #define DEF_TX0_CW_MIN_CCK cpu_to_le16(CW_MIN_CCK) | ||
317 | #define DEF_TX1_CW_MIN_CCK cpu_to_le16(CW_MIN_CCK) | ||
318 | #define DEF_TX2_CW_MIN_CCK cpu_to_le16(CW_MIN_CCK) | ||
319 | #define DEF_TX3_CW_MIN_CCK cpu_to_le16(CW_MIN_CCK) | ||
320 | |||
321 | #define DEF_TX0_CW_MAX_OFDM cpu_to_le16(CW_MAX_OFDM) | ||
322 | #define DEF_TX1_CW_MAX_OFDM cpu_to_le16(CW_MAX_OFDM) | ||
323 | #define DEF_TX2_CW_MAX_OFDM cpu_to_le16(CW_MAX_OFDM) | ||
324 | #define DEF_TX3_CW_MAX_OFDM cpu_to_le16(CW_MAX_OFDM) | ||
325 | |||
326 | #define DEF_TX0_CW_MAX_CCK cpu_to_le16(CW_MAX_CCK) | ||
327 | #define DEF_TX1_CW_MAX_CCK cpu_to_le16(CW_MAX_CCK) | ||
328 | #define DEF_TX2_CW_MAX_CCK cpu_to_le16(CW_MAX_CCK) | ||
329 | #define DEF_TX3_CW_MAX_CCK cpu_to_le16(CW_MAX_CCK) | ||
330 | |||
331 | #define DEF_TX0_AIFS 0 | ||
332 | #define DEF_TX1_AIFS 0 | ||
333 | #define DEF_TX2_AIFS 0 | ||
334 | #define DEF_TX3_AIFS 0 | ||
335 | |||
336 | #define DEF_TX0_ACM 0 | ||
337 | #define DEF_TX1_ACM 0 | ||
338 | #define DEF_TX2_ACM 0 | ||
339 | #define DEF_TX3_ACM 0 | ||
340 | |||
341 | #define DEF_TX0_TXOP_LIMIT_CCK 0 | ||
342 | #define DEF_TX1_TXOP_LIMIT_CCK 0 | ||
343 | #define DEF_TX2_TXOP_LIMIT_CCK 0 | ||
344 | #define DEF_TX3_TXOP_LIMIT_CCK 0 | ||
345 | |||
346 | #define DEF_TX0_TXOP_LIMIT_OFDM 0 | ||
347 | #define DEF_TX1_TXOP_LIMIT_OFDM 0 | ||
348 | #define DEF_TX2_TXOP_LIMIT_OFDM 0 | ||
349 | #define DEF_TX3_TXOP_LIMIT_OFDM 0 | ||
350 | |||
351 | #define QOS_QOS_SETS 3 | ||
352 | #define QOS_PARAM_SET_ACTIVE 0 | ||
353 | #define QOS_PARAM_SET_DEF_CCK 1 | ||
354 | #define QOS_PARAM_SET_DEF_OFDM 2 | ||
355 | |||
356 | #define CTRL_QOS_NO_ACK (0x0020) | ||
357 | |||
358 | #define IPW_TX_QUEUE_1 1 | ||
359 | #define IPW_TX_QUEUE_2 2 | ||
360 | #define IPW_TX_QUEUE_3 3 | ||
361 | #define IPW_TX_QUEUE_4 4 | ||
362 | |||
363 | /* QoS sturctures */ | ||
364 | struct ipw_qos_info { | ||
365 | int qos_enable; | ||
366 | struct ieee80211_qos_parameters *def_qos_parm_OFDM; | ||
367 | struct ieee80211_qos_parameters *def_qos_parm_CCK; | ||
368 | u32 burst_duration_CCK; | ||
369 | u32 burst_duration_OFDM; | ||
370 | u16 qos_no_ack_mask; | ||
371 | int burst_enable; | ||
372 | }; | ||
373 | |||
374 | /**************************************************************/ | ||
375 | /** | ||
376 | * Generic queue structure | ||
377 | * | ||
378 | * Contains common data for Rx and Tx queues | ||
379 | */ | ||
380 | struct clx2_queue { | ||
381 | int n_bd; /**< number of BDs in this queue */ | ||
382 | int first_empty; /**< 1-st empty entry (index) */ | ||
383 | int last_used; /**< last used entry (index) */ | ||
384 | u32 reg_w; /**< 'write' reg (queue head), addr in domain 1 */ | ||
385 | u32 reg_r; /**< 'read' reg (queue tail), addr in domain 1 */ | ||
386 | dma_addr_t dma_addr; /**< physical addr for BD's */ | ||
387 | int low_mark; /**< low watermark, resume queue if free space more than this */ | ||
388 | int high_mark; /**< high watermark, stop queue if free space less than this */ | ||
389 | } __attribute__ ((packed)); /* XXX */ | ||
390 | |||
391 | struct machdr32 { | ||
392 | __le16 frame_ctl; | ||
393 | __le16 duration; // watch out for endians! | ||
394 | u8 addr1[MACADRR_BYTE_LEN]; | ||
395 | u8 addr2[MACADRR_BYTE_LEN]; | ||
396 | u8 addr3[MACADRR_BYTE_LEN]; | ||
397 | __le16 seq_ctrl; // more endians! | ||
398 | u8 addr4[MACADRR_BYTE_LEN]; | ||
399 | __le16 qos_ctrl; | ||
400 | } __attribute__ ((packed)); | ||
401 | |||
402 | struct machdr30 { | ||
403 | __le16 frame_ctl; | ||
404 | __le16 duration; // watch out for endians! | ||
405 | u8 addr1[MACADRR_BYTE_LEN]; | ||
406 | u8 addr2[MACADRR_BYTE_LEN]; | ||
407 | u8 addr3[MACADRR_BYTE_LEN]; | ||
408 | __le16 seq_ctrl; // more endians! | ||
409 | u8 addr4[MACADRR_BYTE_LEN]; | ||
410 | } __attribute__ ((packed)); | ||
411 | |||
412 | struct machdr26 { | ||
413 | __le16 frame_ctl; | ||
414 | __le16 duration; // watch out for endians! | ||
415 | u8 addr1[MACADRR_BYTE_LEN]; | ||
416 | u8 addr2[MACADRR_BYTE_LEN]; | ||
417 | u8 addr3[MACADRR_BYTE_LEN]; | ||
418 | __le16 seq_ctrl; // more endians! | ||
419 | __le16 qos_ctrl; | ||
420 | } __attribute__ ((packed)); | ||
421 | |||
422 | struct machdr24 { | ||
423 | __le16 frame_ctl; | ||
424 | __le16 duration; // watch out for endians! | ||
425 | u8 addr1[MACADRR_BYTE_LEN]; | ||
426 | u8 addr2[MACADRR_BYTE_LEN]; | ||
427 | u8 addr3[MACADRR_BYTE_LEN]; | ||
428 | __le16 seq_ctrl; // more endians! | ||
429 | } __attribute__ ((packed)); | ||
430 | |||
431 | // TX TFD with 32 byte MAC Header | ||
432 | struct tx_tfd_32 { | ||
433 | struct machdr32 mchdr; // 32 | ||
434 | __le32 uivplaceholder[2]; // 8 | ||
435 | } __attribute__ ((packed)); | ||
436 | |||
437 | // TX TFD with 30 byte MAC Header | ||
438 | struct tx_tfd_30 { | ||
439 | struct machdr30 mchdr; // 30 | ||
440 | u8 reserved[2]; // 2 | ||
441 | __le32 uivplaceholder[2]; // 8 | ||
442 | } __attribute__ ((packed)); | ||
443 | |||
444 | // tx tfd with 26 byte mac header | ||
445 | struct tx_tfd_26 { | ||
446 | struct machdr26 mchdr; // 26 | ||
447 | u8 reserved1[2]; // 2 | ||
448 | __le32 uivplaceholder[2]; // 8 | ||
449 | u8 reserved2[4]; // 4 | ||
450 | } __attribute__ ((packed)); | ||
451 | |||
452 | // tx tfd with 24 byte mac header | ||
453 | struct tx_tfd_24 { | ||
454 | struct machdr24 mchdr; // 24 | ||
455 | __le32 uivplaceholder[2]; // 8 | ||
456 | u8 reserved[8]; // 8 | ||
457 | } __attribute__ ((packed)); | ||
458 | |||
459 | #define DCT_WEP_KEY_FIELD_LENGTH 16 | ||
460 | |||
461 | struct tfd_command { | ||
462 | u8 index; | ||
463 | u8 length; | ||
464 | __le16 reserved; | ||
465 | u8 payload[0]; | ||
466 | } __attribute__ ((packed)); | ||
467 | |||
468 | struct tfd_data { | ||
469 | /* Header */ | ||
470 | __le32 work_area_ptr; | ||
471 | u8 station_number; /* 0 for BSS */ | ||
472 | u8 reserved1; | ||
473 | __le16 reserved2; | ||
474 | |||
475 | /* Tx Parameters */ | ||
476 | u8 cmd_id; | ||
477 | u8 seq_num; | ||
478 | __le16 len; | ||
479 | u8 priority; | ||
480 | u8 tx_flags; | ||
481 | u8 tx_flags_ext; | ||
482 | u8 key_index; | ||
483 | u8 wepkey[DCT_WEP_KEY_FIELD_LENGTH]; | ||
484 | u8 rate; | ||
485 | u8 antenna; | ||
486 | __le16 next_packet_duration; | ||
487 | __le16 next_frag_len; | ||
488 | __le16 back_off_counter; //////txop; | ||
489 | u8 retrylimit; | ||
490 | __le16 cwcurrent; | ||
491 | u8 reserved3; | ||
492 | |||
493 | /* 802.11 MAC Header */ | ||
494 | union { | ||
495 | struct tx_tfd_24 tfd_24; | ||
496 | struct tx_tfd_26 tfd_26; | ||
497 | struct tx_tfd_30 tfd_30; | ||
498 | struct tx_tfd_32 tfd_32; | ||
499 | } tfd; | ||
500 | |||
501 | /* Payload DMA info */ | ||
502 | __le32 num_chunks; | ||
503 | __le32 chunk_ptr[NUM_TFD_CHUNKS]; | ||
504 | __le16 chunk_len[NUM_TFD_CHUNKS]; | ||
505 | } __attribute__ ((packed)); | ||
506 | |||
507 | struct txrx_control_flags { | ||
508 | u8 message_type; | ||
509 | u8 rx_seq_num; | ||
510 | u8 control_bits; | ||
511 | u8 reserved; | ||
512 | } __attribute__ ((packed)); | ||
513 | |||
514 | #define TFD_SIZE 128 | ||
515 | #define TFD_CMD_IMMEDIATE_PAYLOAD_LENGTH (TFD_SIZE - sizeof(struct txrx_control_flags)) | ||
516 | |||
517 | struct tfd_frame { | ||
518 | struct txrx_control_flags control_flags; | ||
519 | union { | ||
520 | struct tfd_data data; | ||
521 | struct tfd_command cmd; | ||
522 | u8 raw[TFD_CMD_IMMEDIATE_PAYLOAD_LENGTH]; | ||
523 | } u; | ||
524 | } __attribute__ ((packed)); | ||
525 | |||
526 | typedef void destructor_func(const void *); | ||
527 | |||
528 | /** | ||
529 | * Tx Queue for DMA. Queue consists of circular buffer of | ||
530 | * BD's and required locking structures. | ||
531 | */ | ||
532 | struct clx2_tx_queue { | ||
533 | struct clx2_queue q; | ||
534 | struct tfd_frame *bd; | ||
535 | struct ieee80211_txb **txb; | ||
536 | }; | ||
537 | |||
538 | /* | ||
539 | * RX related structures and functions | ||
540 | */ | ||
541 | #define RX_FREE_BUFFERS 32 | ||
542 | #define RX_LOW_WATERMARK 8 | ||
543 | |||
544 | #define SUP_RATE_11A_MAX_NUM_CHANNELS 8 | ||
545 | #define SUP_RATE_11B_MAX_NUM_CHANNELS 4 | ||
546 | #define SUP_RATE_11G_MAX_NUM_CHANNELS 12 | ||
547 | |||
548 | // Used for passing to driver number of successes and failures per rate | ||
549 | struct rate_histogram { | ||
550 | union { | ||
551 | __le32 a[SUP_RATE_11A_MAX_NUM_CHANNELS]; | ||
552 | __le32 b[SUP_RATE_11B_MAX_NUM_CHANNELS]; | ||
553 | __le32 g[SUP_RATE_11G_MAX_NUM_CHANNELS]; | ||
554 | } success; | ||
555 | union { | ||
556 | __le32 a[SUP_RATE_11A_MAX_NUM_CHANNELS]; | ||
557 | __le32 b[SUP_RATE_11B_MAX_NUM_CHANNELS]; | ||
558 | __le32 g[SUP_RATE_11G_MAX_NUM_CHANNELS]; | ||
559 | } failed; | ||
560 | } __attribute__ ((packed)); | ||
561 | |||
562 | /* statistics command response */ | ||
563 | struct ipw_cmd_stats { | ||
564 | u8 cmd_id; | ||
565 | u8 seq_num; | ||
566 | __le16 good_sfd; | ||
567 | __le16 bad_plcp; | ||
568 | __le16 wrong_bssid; | ||
569 | __le16 valid_mpdu; | ||
570 | __le16 bad_mac_header; | ||
571 | __le16 reserved_frame_types; | ||
572 | __le16 rx_ina; | ||
573 | __le16 bad_crc32; | ||
574 | __le16 invalid_cts; | ||
575 | __le16 invalid_acks; | ||
576 | __le16 long_distance_ina_fina; | ||
577 | __le16 dsp_silence_unreachable; | ||
578 | __le16 accumulated_rssi; | ||
579 | __le16 rx_ovfl_frame_tossed; | ||
580 | __le16 rssi_silence_threshold; | ||
581 | __le16 rx_ovfl_frame_supplied; | ||
582 | __le16 last_rx_frame_signal; | ||
583 | __le16 last_rx_frame_noise; | ||
584 | __le16 rx_autodetec_no_ofdm; | ||
585 | __le16 rx_autodetec_no_barker; | ||
586 | __le16 reserved; | ||
587 | } __attribute__ ((packed)); | ||
588 | |||
589 | struct notif_channel_result { | ||
590 | u8 channel_num; | ||
591 | struct ipw_cmd_stats stats; | ||
592 | u8 uReserved; | ||
593 | } __attribute__ ((packed)); | ||
594 | |||
595 | #define SCAN_COMPLETED_STATUS_COMPLETE 1 | ||
596 | #define SCAN_COMPLETED_STATUS_ABORTED 2 | ||
597 | |||
598 | struct notif_scan_complete { | ||
599 | u8 scan_type; | ||
600 | u8 num_channels; | ||
601 | u8 status; | ||
602 | u8 reserved; | ||
603 | } __attribute__ ((packed)); | ||
604 | |||
605 | struct notif_frag_length { | ||
606 | __le16 frag_length; | ||
607 | __le16 reserved; | ||
608 | } __attribute__ ((packed)); | ||
609 | |||
610 | struct notif_beacon_state { | ||
611 | __le32 state; | ||
612 | __le32 number; | ||
613 | } __attribute__ ((packed)); | ||
614 | |||
615 | struct notif_tgi_tx_key { | ||
616 | u8 key_state; | ||
617 | u8 security_type; | ||
618 | u8 station_index; | ||
619 | u8 reserved; | ||
620 | } __attribute__ ((packed)); | ||
621 | |||
622 | #define SILENCE_OVER_THRESH (1) | ||
623 | #define SILENCE_UNDER_THRESH (2) | ||
624 | |||
625 | struct notif_link_deterioration { | ||
626 | struct ipw_cmd_stats stats; | ||
627 | u8 rate; | ||
628 | u8 modulation; | ||
629 | struct rate_histogram histogram; | ||
630 | u8 silence_notification_type; /* SILENCE_OVER/UNDER_THRESH */ | ||
631 | __le16 silence_count; | ||
632 | } __attribute__ ((packed)); | ||
633 | |||
634 | struct notif_association { | ||
635 | u8 state; | ||
636 | } __attribute__ ((packed)); | ||
637 | |||
638 | struct notif_authenticate { | ||
639 | u8 state; | ||
640 | struct machdr24 addr; | ||
641 | __le16 status; | ||
642 | } __attribute__ ((packed)); | ||
643 | |||
644 | struct notif_calibration { | ||
645 | u8 data[104]; | ||
646 | } __attribute__ ((packed)); | ||
647 | |||
648 | struct notif_noise { | ||
649 | __le32 value; | ||
650 | } __attribute__ ((packed)); | ||
651 | |||
652 | struct ipw_rx_notification { | ||
653 | u8 reserved[8]; | ||
654 | u8 subtype; | ||
655 | u8 flags; | ||
656 | __le16 size; | ||
657 | union { | ||
658 | struct notif_association assoc; | ||
659 | struct notif_authenticate auth; | ||
660 | struct notif_channel_result channel_result; | ||
661 | struct notif_scan_complete scan_complete; | ||
662 | struct notif_frag_length frag_len; | ||
663 | struct notif_beacon_state beacon_state; | ||
664 | struct notif_tgi_tx_key tgi_tx_key; | ||
665 | struct notif_link_deterioration link_deterioration; | ||
666 | struct notif_calibration calibration; | ||
667 | struct notif_noise noise; | ||
668 | u8 raw[0]; | ||
669 | } u; | ||
670 | } __attribute__ ((packed)); | ||
671 | |||
672 | struct ipw_rx_frame { | ||
673 | __le32 reserved1; | ||
674 | u8 parent_tsf[4]; // fw_use[0] is boolean for OUR_TSF_IS_GREATER | ||
675 | u8 received_channel; // The channel that this frame was received on. | ||
676 | // Note that for .11b this does not have to be | ||
677 | // the same as the channel that it was sent. | ||
678 | // Filled by LMAC | ||
679 | u8 frameStatus; | ||
680 | u8 rate; | ||
681 | u8 rssi; | ||
682 | u8 agc; | ||
683 | u8 rssi_dbm; | ||
684 | __le16 signal; | ||
685 | __le16 noise; | ||
686 | u8 antennaAndPhy; | ||
687 | u8 control; // control bit should be on in bg | ||
688 | u8 rtscts_rate; // rate of rts or cts (in rts cts sequence rate | ||
689 | // is identical) | ||
690 | u8 rtscts_seen; // 0x1 RTS seen ; 0x2 CTS seen | ||
691 | __le16 length; | ||
692 | u8 data[0]; | ||
693 | } __attribute__ ((packed)); | ||
694 | |||
695 | struct ipw_rx_header { | ||
696 | u8 message_type; | ||
697 | u8 rx_seq_num; | ||
698 | u8 control_bits; | ||
699 | u8 reserved; | ||
700 | } __attribute__ ((packed)); | ||
701 | |||
702 | struct ipw_rx_packet { | ||
703 | struct ipw_rx_header header; | ||
704 | union { | ||
705 | struct ipw_rx_frame frame; | ||
706 | struct ipw_rx_notification notification; | ||
707 | } u; | ||
708 | } __attribute__ ((packed)); | ||
709 | |||
710 | #define IPW_RX_NOTIFICATION_SIZE sizeof(struct ipw_rx_header) + 12 | ||
711 | #define IPW_RX_FRAME_SIZE (unsigned int)(sizeof(struct ipw_rx_header) + \ | ||
712 | sizeof(struct ipw_rx_frame)) | ||
713 | |||
714 | struct ipw_rx_mem_buffer { | ||
715 | dma_addr_t dma_addr; | ||
716 | struct sk_buff *skb; | ||
717 | struct list_head list; | ||
718 | }; /* Not transferred over network, so not __attribute__ ((packed)) */ | ||
719 | |||
720 | struct ipw_rx_queue { | ||
721 | struct ipw_rx_mem_buffer pool[RX_QUEUE_SIZE + RX_FREE_BUFFERS]; | ||
722 | struct ipw_rx_mem_buffer *queue[RX_QUEUE_SIZE]; | ||
723 | u32 processed; /* Internal index to last handled Rx packet */ | ||
724 | u32 read; /* Shared index to newest available Rx buffer */ | ||
725 | u32 write; /* Shared index to oldest written Rx packet */ | ||
726 | u32 free_count; /* Number of pre-allocated buffers in rx_free */ | ||
727 | /* Each of these lists is used as a FIFO for ipw_rx_mem_buffers */ | ||
728 | struct list_head rx_free; /* Own an SKBs */ | ||
729 | struct list_head rx_used; /* No SKB allocated */ | ||
730 | spinlock_t lock; | ||
731 | }; /* Not transferred over network, so not __attribute__ ((packed)) */ | ||
732 | |||
733 | struct alive_command_responce { | ||
734 | u8 alive_command; | ||
735 | u8 sequence_number; | ||
736 | __le16 software_revision; | ||
737 | u8 device_identifier; | ||
738 | u8 reserved1[5]; | ||
739 | __le16 reserved2; | ||
740 | __le16 reserved3; | ||
741 | __le16 clock_settle_time; | ||
742 | __le16 powerup_settle_time; | ||
743 | __le16 reserved4; | ||
744 | u8 time_stamp[5]; /* month, day, year, hours, minutes */ | ||
745 | u8 ucode_valid; | ||
746 | } __attribute__ ((packed)); | ||
747 | |||
748 | #define IPW_MAX_RATES 12 | ||
749 | |||
750 | struct ipw_rates { | ||
751 | u8 num_rates; | ||
752 | u8 rates[IPW_MAX_RATES]; | ||
753 | } __attribute__ ((packed)); | ||
754 | |||
755 | struct command_block { | ||
756 | unsigned int control; | ||
757 | u32 source_addr; | ||
758 | u32 dest_addr; | ||
759 | unsigned int status; | ||
760 | } __attribute__ ((packed)); | ||
761 | |||
762 | #define CB_NUMBER_OF_ELEMENTS_SMALL 64 | ||
763 | struct fw_image_desc { | ||
764 | unsigned long last_cb_index; | ||
765 | unsigned long current_cb_index; | ||
766 | struct command_block cb_list[CB_NUMBER_OF_ELEMENTS_SMALL]; | ||
767 | void *v_addr; | ||
768 | unsigned long p_addr; | ||
769 | unsigned long len; | ||
770 | }; | ||
771 | |||
772 | struct ipw_sys_config { | ||
773 | u8 bt_coexistence; | ||
774 | u8 reserved1; | ||
775 | u8 answer_broadcast_ssid_probe; | ||
776 | u8 accept_all_data_frames; | ||
777 | u8 accept_non_directed_frames; | ||
778 | u8 exclude_unicast_unencrypted; | ||
779 | u8 disable_unicast_decryption; | ||
780 | u8 exclude_multicast_unencrypted; | ||
781 | u8 disable_multicast_decryption; | ||
782 | u8 antenna_diversity; | ||
783 | u8 pass_crc_to_host; | ||
784 | u8 dot11g_auto_detection; | ||
785 | u8 enable_cts_to_self; | ||
786 | u8 enable_multicast_filtering; | ||
787 | u8 bt_coexist_collision_thr; | ||
788 | u8 silence_threshold; | ||
789 | u8 accept_all_mgmt_bcpr; | ||
790 | u8 accept_all_mgmt_frames; | ||
791 | u8 pass_noise_stats_to_host; | ||
792 | u8 reserved3; | ||
793 | } __attribute__ ((packed)); | ||
794 | |||
795 | struct ipw_multicast_addr { | ||
796 | u8 num_of_multicast_addresses; | ||
797 | u8 reserved[3]; | ||
798 | u8 mac1[6]; | ||
799 | u8 mac2[6]; | ||
800 | u8 mac3[6]; | ||
801 | u8 mac4[6]; | ||
802 | } __attribute__ ((packed)); | ||
803 | |||
804 | #define DCW_WEP_KEY_INDEX_MASK 0x03 /* bits [0:1] */ | ||
805 | #define DCW_WEP_KEY_SEC_TYPE_MASK 0x30 /* bits [4:5] */ | ||
806 | |||
807 | #define DCW_WEP_KEY_SEC_TYPE_WEP 0x00 | ||
808 | #define DCW_WEP_KEY_SEC_TYPE_CCM 0x20 | ||
809 | #define DCW_WEP_KEY_SEC_TYPE_TKIP 0x30 | ||
810 | |||
811 | #define DCW_WEP_KEY_INVALID_SIZE 0x00 /* 0 = Invalid key */ | ||
812 | #define DCW_WEP_KEY64Bit_SIZE 0x05 /* 64-bit encryption */ | ||
813 | #define DCW_WEP_KEY128Bit_SIZE 0x0D /* 128-bit encryption */ | ||
814 | #define DCW_CCM_KEY128Bit_SIZE 0x10 /* 128-bit key */ | ||
815 | //#define DCW_WEP_KEY128BitIV_SIZE 0x10 /* 128-bit key and 128-bit IV */ | ||
816 | |||
817 | struct ipw_wep_key { | ||
818 | u8 cmd_id; | ||
819 | u8 seq_num; | ||
820 | u8 key_index; | ||
821 | u8 key_size; | ||
822 | u8 key[16]; | ||
823 | } __attribute__ ((packed)); | ||
824 | |||
825 | struct ipw_tgi_tx_key { | ||
826 | u8 key_id; | ||
827 | u8 security_type; | ||
828 | u8 station_index; | ||
829 | u8 flags; | ||
830 | u8 key[16]; | ||
831 | __le32 tx_counter[2]; | ||
832 | } __attribute__ ((packed)); | ||
833 | |||
834 | #define IPW_SCAN_CHANNELS 54 | ||
835 | |||
836 | struct ipw_scan_request { | ||
837 | u8 scan_type; | ||
838 | __le16 dwell_time; | ||
839 | u8 channels_list[IPW_SCAN_CHANNELS]; | ||
840 | u8 channels_reserved[3]; | ||
841 | } __attribute__ ((packed)); | ||
842 | |||
843 | enum { | ||
844 | IPW_SCAN_PASSIVE_TILL_FIRST_BEACON_SCAN = 0, | ||
845 | IPW_SCAN_PASSIVE_FULL_DWELL_SCAN, | ||
846 | IPW_SCAN_ACTIVE_DIRECT_SCAN, | ||
847 | IPW_SCAN_ACTIVE_BROADCAST_SCAN, | ||
848 | IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN, | ||
849 | IPW_SCAN_TYPES | ||
850 | }; | ||
851 | |||
852 | struct ipw_scan_request_ext { | ||
853 | __le32 full_scan_index; | ||
854 | u8 channels_list[IPW_SCAN_CHANNELS]; | ||
855 | u8 scan_type[IPW_SCAN_CHANNELS / 2]; | ||
856 | u8 reserved; | ||
857 | __le16 dwell_time[IPW_SCAN_TYPES]; | ||
858 | } __attribute__ ((packed)); | ||
859 | |||
860 | static inline u8 ipw_get_scan_type(struct ipw_scan_request_ext *scan, u8 index) | ||
861 | { | ||
862 | if (index % 2) | ||
863 | return scan->scan_type[index / 2] & 0x0F; | ||
864 | else | ||
865 | return (scan->scan_type[index / 2] & 0xF0) >> 4; | ||
866 | } | ||
867 | |||
868 | static inline void ipw_set_scan_type(struct ipw_scan_request_ext *scan, | ||
869 | u8 index, u8 scan_type) | ||
870 | { | ||
871 | if (index % 2) | ||
872 | scan->scan_type[index / 2] = | ||
873 | (scan->scan_type[index / 2] & 0xF0) | (scan_type & 0x0F); | ||
874 | else | ||
875 | scan->scan_type[index / 2] = | ||
876 | (scan->scan_type[index / 2] & 0x0F) | | ||
877 | ((scan_type & 0x0F) << 4); | ||
878 | } | ||
879 | |||
880 | struct ipw_associate { | ||
881 | u8 channel; | ||
882 | #ifdef __LITTLE_ENDIAN_BITFIELD | ||
883 | u8 auth_type:4, auth_key:4; | ||
884 | #else | ||
885 | u8 auth_key:4, auth_type:4; | ||
886 | #endif | ||
887 | u8 assoc_type; | ||
888 | u8 reserved; | ||
889 | __le16 policy_support; | ||
890 | u8 preamble_length; | ||
891 | u8 ieee_mode; | ||
892 | u8 bssid[ETH_ALEN]; | ||
893 | __le32 assoc_tsf_msw; | ||
894 | __le32 assoc_tsf_lsw; | ||
895 | __le16 capability; | ||
896 | __le16 listen_interval; | ||
897 | __le16 beacon_interval; | ||
898 | u8 dest[ETH_ALEN]; | ||
899 | __le16 atim_window; | ||
900 | u8 smr; | ||
901 | u8 reserved1; | ||
902 | __le16 reserved2; | ||
903 | } __attribute__ ((packed)); | ||
904 | |||
905 | struct ipw_supported_rates { | ||
906 | u8 ieee_mode; | ||
907 | u8 num_rates; | ||
908 | u8 purpose; | ||
909 | u8 reserved; | ||
910 | u8 supported_rates[IPW_MAX_RATES]; | ||
911 | } __attribute__ ((packed)); | ||
912 | |||
913 | struct ipw_rts_threshold { | ||
914 | __le16 rts_threshold; | ||
915 | __le16 reserved; | ||
916 | } __attribute__ ((packed)); | ||
917 | |||
918 | struct ipw_frag_threshold { | ||
919 | __le16 frag_threshold; | ||
920 | __le16 reserved; | ||
921 | } __attribute__ ((packed)); | ||
922 | |||
923 | struct ipw_retry_limit { | ||
924 | u8 short_retry_limit; | ||
925 | u8 long_retry_limit; | ||
926 | __le16 reserved; | ||
927 | } __attribute__ ((packed)); | ||
928 | |||
929 | struct ipw_dino_config { | ||
930 | __le32 dino_config_addr; | ||
931 | __le16 dino_config_size; | ||
932 | u8 dino_response; | ||
933 | u8 reserved; | ||
934 | } __attribute__ ((packed)); | ||
935 | |||
936 | struct ipw_aironet_info { | ||
937 | u8 id; | ||
938 | u8 length; | ||
939 | __le16 reserved; | ||
940 | } __attribute__ ((packed)); | ||
941 | |||
942 | struct ipw_rx_key { | ||
943 | u8 station_index; | ||
944 | u8 key_type; | ||
945 | u8 key_id; | ||
946 | u8 key_flag; | ||
947 | u8 key[16]; | ||
948 | u8 station_address[6]; | ||
949 | u8 key_index; | ||
950 | u8 reserved; | ||
951 | } __attribute__ ((packed)); | ||
952 | |||
953 | struct ipw_country_channel_info { | ||
954 | u8 first_channel; | ||
955 | u8 no_channels; | ||
956 | s8 max_tx_power; | ||
957 | } __attribute__ ((packed)); | ||
958 | |||
959 | struct ipw_country_info { | ||
960 | u8 id; | ||
961 | u8 length; | ||
962 | u8 country_str[3]; | ||
963 | struct ipw_country_channel_info groups[7]; | ||
964 | } __attribute__ ((packed)); | ||
965 | |||
966 | struct ipw_channel_tx_power { | ||
967 | u8 channel_number; | ||
968 | s8 tx_power; | ||
969 | } __attribute__ ((packed)); | ||
970 | |||
971 | #define SCAN_ASSOCIATED_INTERVAL (HZ) | ||
972 | #define SCAN_INTERVAL (HZ / 10) | ||
973 | #define MAX_A_CHANNELS 37 | ||
974 | #define MAX_B_CHANNELS 14 | ||
975 | |||
976 | struct ipw_tx_power { | ||
977 | u8 num_channels; | ||
978 | u8 ieee_mode; | ||
979 | struct ipw_channel_tx_power channels_tx_power[MAX_A_CHANNELS]; | ||
980 | } __attribute__ ((packed)); | ||
981 | |||
982 | struct ipw_rsn_capabilities { | ||
983 | u8 id; | ||
984 | u8 length; | ||
985 | __le16 version; | ||
986 | } __attribute__ ((packed)); | ||
987 | |||
988 | struct ipw_sensitivity_calib { | ||
989 | __le16 beacon_rssi_raw; | ||
990 | __le16 reserved; | ||
991 | } __attribute__ ((packed)); | ||
992 | |||
993 | /** | ||
994 | * Host command structure. | ||
995 | * | ||
996 | * On input, the following fields should be filled: | ||
997 | * - cmd | ||
998 | * - len | ||
999 | * - status_len | ||
1000 | * - param (if needed) | ||
1001 | * | ||
1002 | * On output, | ||
1003 | * - \a status contains status; | ||
1004 | * - \a param filled with status parameters. | ||
1005 | */ | ||
1006 | struct ipw_cmd { /* XXX */ | ||
1007 | u32 cmd; /**< Host command */ | ||
1008 | u32 status;/**< Status */ | ||
1009 | u32 status_len; | ||
1010 | /**< How many 32 bit parameters in the status */ | ||
1011 | u32 len; /**< incoming parameters length, bytes */ | ||
1012 | /** | ||
1013 | * command parameters. | ||
1014 | * There should be enough space for incoming and | ||
1015 | * outcoming parameters. | ||
1016 | * Incoming parameters listed 1-st, followed by outcoming params. | ||
1017 | * nParams=(len+3)/4+status_len | ||
1018 | */ | ||
1019 | u32 param[0]; | ||
1020 | } __attribute__ ((packed)); | ||
1021 | |||
1022 | #define STATUS_HCMD_ACTIVE (1<<0) /**< host command in progress */ | ||
1023 | |||
1024 | #define STATUS_INT_ENABLED (1<<1) | ||
1025 | #define STATUS_RF_KILL_HW (1<<2) | ||
1026 | #define STATUS_RF_KILL_SW (1<<3) | ||
1027 | #define STATUS_RF_KILL_MASK (STATUS_RF_KILL_HW | STATUS_RF_KILL_SW) | ||
1028 | |||
1029 | #define STATUS_INIT (1<<5) | ||
1030 | #define STATUS_AUTH (1<<6) | ||
1031 | #define STATUS_ASSOCIATED (1<<7) | ||
1032 | #define STATUS_STATE_MASK (STATUS_INIT | STATUS_AUTH | STATUS_ASSOCIATED) | ||
1033 | |||
1034 | #define STATUS_ASSOCIATING (1<<8) | ||
1035 | #define STATUS_DISASSOCIATING (1<<9) | ||
1036 | #define STATUS_ROAMING (1<<10) | ||
1037 | #define STATUS_EXIT_PENDING (1<<11) | ||
1038 | #define STATUS_DISASSOC_PENDING (1<<12) | ||
1039 | #define STATUS_STATE_PENDING (1<<13) | ||
1040 | |||
1041 | #define STATUS_DIRECT_SCAN_PENDING (1<<19) | ||
1042 | #define STATUS_SCAN_PENDING (1<<20) | ||
1043 | #define STATUS_SCANNING (1<<21) | ||
1044 | #define STATUS_SCAN_ABORTING (1<<22) | ||
1045 | #define STATUS_SCAN_FORCED (1<<23) | ||
1046 | |||
1047 | #define STATUS_LED_LINK_ON (1<<24) | ||
1048 | #define STATUS_LED_ACT_ON (1<<25) | ||
1049 | |||
1050 | #define STATUS_INDIRECT_BYTE (1<<28) /* sysfs entry configured for access */ | ||
1051 | #define STATUS_INDIRECT_DWORD (1<<29) /* sysfs entry configured for access */ | ||
1052 | #define STATUS_DIRECT_DWORD (1<<30) /* sysfs entry configured for access */ | ||
1053 | |||
1054 | #define STATUS_SECURITY_UPDATED (1<<31) /* Security sync needed */ | ||
1055 | |||
1056 | #define CFG_STATIC_CHANNEL (1<<0) /* Restrict assoc. to single channel */ | ||
1057 | #define CFG_STATIC_ESSID (1<<1) /* Restrict assoc. to single SSID */ | ||
1058 | #define CFG_STATIC_BSSID (1<<2) /* Restrict assoc. to single BSSID */ | ||
1059 | #define CFG_CUSTOM_MAC (1<<3) | ||
1060 | #define CFG_PREAMBLE_LONG (1<<4) | ||
1061 | #define CFG_ADHOC_PERSIST (1<<5) | ||
1062 | #define CFG_ASSOCIATE (1<<6) | ||
1063 | #define CFG_FIXED_RATE (1<<7) | ||
1064 | #define CFG_ADHOC_CREATE (1<<8) | ||
1065 | #define CFG_NO_LED (1<<9) | ||
1066 | #define CFG_BACKGROUND_SCAN (1<<10) | ||
1067 | #define CFG_SPEED_SCAN (1<<11) | ||
1068 | #define CFG_NET_STATS (1<<12) | ||
1069 | |||
1070 | #define CAP_SHARED_KEY (1<<0) /* Off = OPEN */ | ||
1071 | #define CAP_PRIVACY_ON (1<<1) /* Off = No privacy */ | ||
1072 | |||
1073 | #define MAX_STATIONS 32 | ||
1074 | #define IPW_INVALID_STATION (0xff) | ||
1075 | |||
1076 | struct ipw_station_entry { | ||
1077 | u8 mac_addr[ETH_ALEN]; | ||
1078 | u8 reserved; | ||
1079 | u8 support_mode; | ||
1080 | }; | ||
1081 | |||
1082 | #define AVG_ENTRIES 8 | ||
1083 | struct average { | ||
1084 | s16 entries[AVG_ENTRIES]; | ||
1085 | u8 pos; | ||
1086 | u8 init; | ||
1087 | s32 sum; | ||
1088 | }; | ||
1089 | |||
1090 | #define MAX_SPEED_SCAN 100 | ||
1091 | #define IPW_IBSS_MAC_HASH_SIZE 31 | ||
1092 | |||
1093 | struct ipw_ibss_seq { | ||
1094 | u8 mac[ETH_ALEN]; | ||
1095 | u16 seq_num; | ||
1096 | u16 frag_num; | ||
1097 | unsigned long packet_time; | ||
1098 | struct list_head list; | ||
1099 | }; | ||
1100 | |||
1101 | struct ipw_error_elem { /* XXX */ | ||
1102 | u32 desc; | ||
1103 | u32 time; | ||
1104 | u32 blink1; | ||
1105 | u32 blink2; | ||
1106 | u32 link1; | ||
1107 | u32 link2; | ||
1108 | u32 data; | ||
1109 | }; | ||
1110 | |||
1111 | struct ipw_event { /* XXX */ | ||
1112 | u32 event; | ||
1113 | u32 time; | ||
1114 | u32 data; | ||
1115 | } __attribute__ ((packed)); | ||
1116 | |||
1117 | struct ipw_fw_error { /* XXX */ | ||
1118 | unsigned long jiffies; | ||
1119 | u32 status; | ||
1120 | u32 config; | ||
1121 | u32 elem_len; | ||
1122 | u32 log_len; | ||
1123 | struct ipw_error_elem *elem; | ||
1124 | struct ipw_event *log; | ||
1125 | u8 payload[0]; | ||
1126 | } __attribute__ ((packed)); | ||
1127 | |||
1128 | #ifdef CONFIG_IPW2200_PROMISCUOUS | ||
1129 | |||
1130 | enum ipw_prom_filter { | ||
1131 | IPW_PROM_CTL_HEADER_ONLY = (1 << 0), | ||
1132 | IPW_PROM_MGMT_HEADER_ONLY = (1 << 1), | ||
1133 | IPW_PROM_DATA_HEADER_ONLY = (1 << 2), | ||
1134 | IPW_PROM_ALL_HEADER_ONLY = 0xf, /* bits 0..3 */ | ||
1135 | IPW_PROM_NO_TX = (1 << 4), | ||
1136 | IPW_PROM_NO_RX = (1 << 5), | ||
1137 | IPW_PROM_NO_CTL = (1 << 6), | ||
1138 | IPW_PROM_NO_MGMT = (1 << 7), | ||
1139 | IPW_PROM_NO_DATA = (1 << 8), | ||
1140 | }; | ||
1141 | |||
1142 | struct ipw_priv; | ||
1143 | struct ipw_prom_priv { | ||
1144 | struct ipw_priv *priv; | ||
1145 | struct ieee80211_device *ieee; | ||
1146 | enum ipw_prom_filter filter; | ||
1147 | int tx_packets; | ||
1148 | int rx_packets; | ||
1149 | }; | ||
1150 | #endif | ||
1151 | |||
1152 | #if defined(CONFIG_IPW2200_RADIOTAP) || defined(CONFIG_IPW2200_PROMISCUOUS) | ||
1153 | /* Magic struct that slots into the radiotap header -- no reason | ||
1154 | * to build this manually element by element, we can write it much | ||
1155 | * more efficiently than we can parse it. ORDER MATTERS HERE | ||
1156 | * | ||
1157 | * When sent to us via the simulated Rx interface in sysfs, the entire | ||
1158 | * structure is provided regardless of any bits unset. | ||
1159 | */ | ||
1160 | struct ipw_rt_hdr { | ||
1161 | struct ieee80211_radiotap_header rt_hdr; | ||
1162 | u64 rt_tsf; /* TSF */ /* XXX */ | ||
1163 | u8 rt_flags; /* radiotap packet flags */ | ||
1164 | u8 rt_rate; /* rate in 500kb/s */ | ||
1165 | __le16 rt_channel; /* channel in mhz */ | ||
1166 | __le16 rt_chbitmask; /* channel bitfield */ | ||
1167 | s8 rt_dbmsignal; /* signal in dbM, kluged to signed */ | ||
1168 | s8 rt_dbmnoise; | ||
1169 | u8 rt_antenna; /* antenna number */ | ||
1170 | u8 payload[0]; /* payload... */ | ||
1171 | } __attribute__ ((packed)); | ||
1172 | #endif | ||
1173 | |||
1174 | struct ipw_priv { | ||
1175 | /* ieee device used by generic ieee processing code */ | ||
1176 | struct ieee80211_device *ieee; | ||
1177 | |||
1178 | spinlock_t lock; | ||
1179 | spinlock_t irq_lock; | ||
1180 | struct mutex mutex; | ||
1181 | |||
1182 | /* basic pci-network driver stuff */ | ||
1183 | struct pci_dev *pci_dev; | ||
1184 | struct net_device *net_dev; | ||
1185 | |||
1186 | #ifdef CONFIG_IPW2200_PROMISCUOUS | ||
1187 | /* Promiscuous mode */ | ||
1188 | struct ipw_prom_priv *prom_priv; | ||
1189 | struct net_device *prom_net_dev; | ||
1190 | #endif | ||
1191 | |||
1192 | /* pci hardware address support */ | ||
1193 | void __iomem *hw_base; | ||
1194 | unsigned long hw_len; | ||
1195 | |||
1196 | struct fw_image_desc sram_desc; | ||
1197 | |||
1198 | /* result of ucode download */ | ||
1199 | struct alive_command_responce dino_alive; | ||
1200 | |||
1201 | wait_queue_head_t wait_command_queue; | ||
1202 | wait_queue_head_t wait_state; | ||
1203 | |||
1204 | /* Rx and Tx DMA processing queues */ | ||
1205 | struct ipw_rx_queue *rxq; | ||
1206 | struct clx2_tx_queue txq_cmd; | ||
1207 | struct clx2_tx_queue txq[4]; | ||
1208 | u32 status; | ||
1209 | u32 config; | ||
1210 | u32 capability; | ||
1211 | |||
1212 | struct average average_missed_beacons; | ||
1213 | s16 exp_avg_rssi; | ||
1214 | s16 exp_avg_noise; | ||
1215 | u32 port_type; | ||
1216 | int rx_bufs_min; /**< minimum number of bufs in Rx queue */ | ||
1217 | int rx_pend_max; /**< maximum pending buffers for one IRQ */ | ||
1218 | u32 hcmd_seq; /**< sequence number for hcmd */ | ||
1219 | u32 disassociate_threshold; | ||
1220 | u32 roaming_threshold; | ||
1221 | |||
1222 | struct ipw_associate assoc_request; | ||
1223 | struct ieee80211_network *assoc_network; | ||
1224 | |||
1225 | unsigned long ts_scan_abort; | ||
1226 | struct ipw_supported_rates rates; | ||
1227 | struct ipw_rates phy[3]; /**< PHY restrictions, per band */ | ||
1228 | struct ipw_rates supp; /**< software defined */ | ||
1229 | struct ipw_rates extended; /**< use for corresp. IE, AP only */ | ||
1230 | |||
1231 | struct notif_link_deterioration last_link_deterioration; /** for statistics */ | ||
1232 | struct ipw_cmd *hcmd; /**< host command currently executed */ | ||
1233 | |||
1234 | wait_queue_head_t hcmd_wq; /**< host command waits for execution */ | ||
1235 | u32 tsf_bcn[2]; /**< TSF from latest beacon */ | ||
1236 | |||
1237 | struct notif_calibration calib; /**< last calibration */ | ||
1238 | |||
1239 | /* ordinal interface with firmware */ | ||
1240 | u32 table0_addr; | ||
1241 | u32 table0_len; | ||
1242 | u32 table1_addr; | ||
1243 | u32 table1_len; | ||
1244 | u32 table2_addr; | ||
1245 | u32 table2_len; | ||
1246 | |||
1247 | /* context information */ | ||
1248 | u8 essid[IW_ESSID_MAX_SIZE]; | ||
1249 | u8 essid_len; | ||
1250 | u8 nick[IW_ESSID_MAX_SIZE]; | ||
1251 | u16 rates_mask; | ||
1252 | u8 channel; | ||
1253 | struct ipw_sys_config sys_config; | ||
1254 | u32 power_mode; | ||
1255 | u8 bssid[ETH_ALEN]; | ||
1256 | u16 rts_threshold; | ||
1257 | u8 mac_addr[ETH_ALEN]; | ||
1258 | u8 num_stations; | ||
1259 | u8 stations[MAX_STATIONS][ETH_ALEN]; | ||
1260 | u8 short_retry_limit; | ||
1261 | u8 long_retry_limit; | ||
1262 | |||
1263 | u32 notif_missed_beacons; | ||
1264 | |||
1265 | /* Statistics and counters normalized with each association */ | ||
1266 | u32 last_missed_beacons; | ||
1267 | u32 last_tx_packets; | ||
1268 | u32 last_rx_packets; | ||
1269 | u32 last_tx_failures; | ||
1270 | u32 last_rx_err; | ||
1271 | u32 last_rate; | ||
1272 | |||
1273 | u32 missed_adhoc_beacons; | ||
1274 | u32 missed_beacons; | ||
1275 | u32 rx_packets; | ||
1276 | u32 tx_packets; | ||
1277 | u32 quality; | ||
1278 | |||
1279 | u8 speed_scan[MAX_SPEED_SCAN]; | ||
1280 | u8 speed_scan_pos; | ||
1281 | |||
1282 | u16 last_seq_num; | ||
1283 | u16 last_frag_num; | ||
1284 | unsigned long last_packet_time; | ||
1285 | struct list_head ibss_mac_hash[IPW_IBSS_MAC_HASH_SIZE]; | ||
1286 | |||
1287 | /* eeprom */ | ||
1288 | u8 eeprom[0x100]; /* 256 bytes of eeprom */ | ||
1289 | u8 country[4]; | ||
1290 | int eeprom_delay; | ||
1291 | |||
1292 | struct iw_statistics wstats; | ||
1293 | |||
1294 | struct iw_public_data wireless_data; | ||
1295 | |||
1296 | int user_requested_scan; | ||
1297 | u8 direct_scan_ssid[IW_ESSID_MAX_SIZE]; | ||
1298 | u8 direct_scan_ssid_len; | ||
1299 | |||
1300 | struct workqueue_struct *workqueue; | ||
1301 | |||
1302 | struct delayed_work adhoc_check; | ||
1303 | struct work_struct associate; | ||
1304 | struct work_struct disassociate; | ||
1305 | struct work_struct system_config; | ||
1306 | struct work_struct rx_replenish; | ||
1307 | struct delayed_work request_scan; | ||
1308 | struct delayed_work request_direct_scan; | ||
1309 | struct delayed_work request_passive_scan; | ||
1310 | struct delayed_work scan_event; | ||
1311 | struct work_struct adapter_restart; | ||
1312 | struct delayed_work rf_kill; | ||
1313 | struct work_struct up; | ||
1314 | struct work_struct down; | ||
1315 | struct delayed_work gather_stats; | ||
1316 | struct work_struct abort_scan; | ||
1317 | struct work_struct roam; | ||
1318 | struct delayed_work scan_check; | ||
1319 | struct work_struct link_up; | ||
1320 | struct work_struct link_down; | ||
1321 | |||
1322 | struct tasklet_struct irq_tasklet; | ||
1323 | |||
1324 | /* LED related variables and work_struct */ | ||
1325 | u8 nic_type; | ||
1326 | u32 led_activity_on; | ||
1327 | u32 led_activity_off; | ||
1328 | u32 led_association_on; | ||
1329 | u32 led_association_off; | ||
1330 | u32 led_ofdm_on; | ||
1331 | u32 led_ofdm_off; | ||
1332 | |||
1333 | struct delayed_work led_link_on; | ||
1334 | struct delayed_work led_link_off; | ||
1335 | struct delayed_work led_act_off; | ||
1336 | struct work_struct merge_networks; | ||
1337 | |||
1338 | struct ipw_cmd_log *cmdlog; | ||
1339 | int cmdlog_len; | ||
1340 | int cmdlog_pos; | ||
1341 | |||
1342 | #define IPW_2200BG 1 | ||
1343 | #define IPW_2915ABG 2 | ||
1344 | u8 adapter; | ||
1345 | |||
1346 | s8 tx_power; | ||
1347 | |||
1348 | #ifdef CONFIG_PM | ||
1349 | u32 pm_state[16]; | ||
1350 | #endif | ||
1351 | |||
1352 | struct ipw_fw_error *error; | ||
1353 | |||
1354 | /* network state */ | ||
1355 | |||
1356 | /* Used to pass the current INTA value from ISR to Tasklet */ | ||
1357 | u32 isr_inta; | ||
1358 | |||
1359 | /* QoS */ | ||
1360 | struct ipw_qos_info qos_data; | ||
1361 | struct work_struct qos_activate; | ||
1362 | /*********************************/ | ||
1363 | |||
1364 | /* debugging info */ | ||
1365 | u32 indirect_dword; | ||
1366 | u32 direct_dword; | ||
1367 | u32 indirect_byte; | ||
1368 | }; /*ipw_priv */ | ||
1369 | |||
1370 | /* debug macros */ | ||
1371 | |||
1372 | /* Debug and printf string expansion helpers for printing bitfields */ | ||
1373 | #define BIT_FMT8 "%c%c%c%c-%c%c%c%c" | ||
1374 | #define BIT_FMT16 BIT_FMT8 ":" BIT_FMT8 | ||
1375 | #define BIT_FMT32 BIT_FMT16 " " BIT_FMT16 | ||
1376 | |||
1377 | #define BITC(x,y) (((x>>y)&1)?'1':'0') | ||
1378 | #define BIT_ARG8(x) \ | ||
1379 | BITC(x,7),BITC(x,6),BITC(x,5),BITC(x,4),\ | ||
1380 | BITC(x,3),BITC(x,2),BITC(x,1),BITC(x,0) | ||
1381 | |||
1382 | #define BIT_ARG16(x) \ | ||
1383 | BITC(x,15),BITC(x,14),BITC(x,13),BITC(x,12),\ | ||
1384 | BITC(x,11),BITC(x,10),BITC(x,9),BITC(x,8),\ | ||
1385 | BIT_ARG8(x) | ||
1386 | |||
1387 | #define BIT_ARG32(x) \ | ||
1388 | BITC(x,31),BITC(x,30),BITC(x,29),BITC(x,28),\ | ||
1389 | BITC(x,27),BITC(x,26),BITC(x,25),BITC(x,24),\ | ||
1390 | BITC(x,23),BITC(x,22),BITC(x,21),BITC(x,20),\ | ||
1391 | BITC(x,19),BITC(x,18),BITC(x,17),BITC(x,16),\ | ||
1392 | BIT_ARG16(x) | ||
1393 | |||
1394 | |||
1395 | #define IPW_DEBUG(level, fmt, args...) \ | ||
1396 | do { if (ipw_debug_level & (level)) \ | ||
1397 | printk(KERN_DEBUG DRV_NAME": %c %s " fmt, \ | ||
1398 | in_interrupt() ? 'I' : 'U', __func__ , ## args); } while (0) | ||
1399 | |||
1400 | #ifdef CONFIG_IPW2200_DEBUG | ||
1401 | #define IPW_LL_DEBUG(level, fmt, args...) \ | ||
1402 | do { if (ipw_debug_level & (level)) \ | ||
1403 | printk(KERN_DEBUG DRV_NAME": %c %s " fmt, \ | ||
1404 | in_interrupt() ? 'I' : 'U', __func__ , ## args); } while (0) | ||
1405 | #else | ||
1406 | #define IPW_LL_DEBUG(level, fmt, args...) do {} while (0) | ||
1407 | #endif /* CONFIG_IPW2200_DEBUG */ | ||
1408 | |||
1409 | /* | ||
1410 | * To use the debug system; | ||
1411 | * | ||
1412 | * If you are defining a new debug classification, simply add it to the #define | ||
1413 | * list here in the form of: | ||
1414 | * | ||
1415 | * #define IPW_DL_xxxx VALUE | ||
1416 | * | ||
1417 | * shifting value to the left one bit from the previous entry. xxxx should be | ||
1418 | * the name of the classification (for example, WEP) | ||
1419 | * | ||
1420 | * You then need to either add a IPW_xxxx_DEBUG() macro definition for your | ||
1421 | * classification, or use IPW_DEBUG(IPW_DL_xxxx, ...) whenever you want | ||
1422 | * to send output to that classification. | ||
1423 | * | ||
1424 | * To add your debug level to the list of levels seen when you perform | ||
1425 | * | ||
1426 | * % cat /proc/net/ipw/debug_level | ||
1427 | * | ||
1428 | * you simply need to add your entry to the ipw_debug_levels array. | ||
1429 | * | ||
1430 | * If you do not see debug_level in /proc/net/ipw then you do not have | ||
1431 | * CONFIG_IPW2200_DEBUG defined in your kernel configuration | ||
1432 | * | ||
1433 | */ | ||
1434 | |||
1435 | #define IPW_DL_ERROR (1<<0) | ||
1436 | #define IPW_DL_WARNING (1<<1) | ||
1437 | #define IPW_DL_INFO (1<<2) | ||
1438 | #define IPW_DL_WX (1<<3) | ||
1439 | #define IPW_DL_HOST_COMMAND (1<<5) | ||
1440 | #define IPW_DL_STATE (1<<6) | ||
1441 | |||
1442 | #define IPW_DL_NOTIF (1<<10) | ||
1443 | #define IPW_DL_SCAN (1<<11) | ||
1444 | #define IPW_DL_ASSOC (1<<12) | ||
1445 | #define IPW_DL_DROP (1<<13) | ||
1446 | #define IPW_DL_IOCTL (1<<14) | ||
1447 | |||
1448 | #define IPW_DL_MANAGE (1<<15) | ||
1449 | #define IPW_DL_FW (1<<16) | ||
1450 | #define IPW_DL_RF_KILL (1<<17) | ||
1451 | #define IPW_DL_FW_ERRORS (1<<18) | ||
1452 | |||
1453 | #define IPW_DL_LED (1<<19) | ||
1454 | |||
1455 | #define IPW_DL_ORD (1<<20) | ||
1456 | |||
1457 | #define IPW_DL_FRAG (1<<21) | ||
1458 | #define IPW_DL_WEP (1<<22) | ||
1459 | #define IPW_DL_TX (1<<23) | ||
1460 | #define IPW_DL_RX (1<<24) | ||
1461 | #define IPW_DL_ISR (1<<25) | ||
1462 | #define IPW_DL_FW_INFO (1<<26) | ||
1463 | #define IPW_DL_IO (1<<27) | ||
1464 | #define IPW_DL_TRACE (1<<28) | ||
1465 | |||
1466 | #define IPW_DL_STATS (1<<29) | ||
1467 | #define IPW_DL_MERGE (1<<30) | ||
1468 | #define IPW_DL_QOS (1<<31) | ||
1469 | |||
1470 | #define IPW_ERROR(f, a...) printk(KERN_ERR DRV_NAME ": " f, ## a) | ||
1471 | #define IPW_WARNING(f, a...) printk(KERN_WARNING DRV_NAME ": " f, ## a) | ||
1472 | #define IPW_DEBUG_INFO(f, a...) IPW_DEBUG(IPW_DL_INFO, f, ## a) | ||
1473 | |||
1474 | #define IPW_DEBUG_WX(f, a...) IPW_DEBUG(IPW_DL_WX, f, ## a) | ||
1475 | #define IPW_DEBUG_SCAN(f, a...) IPW_DEBUG(IPW_DL_SCAN, f, ## a) | ||
1476 | #define IPW_DEBUG_TRACE(f, a...) IPW_LL_DEBUG(IPW_DL_TRACE, f, ## a) | ||
1477 | #define IPW_DEBUG_RX(f, a...) IPW_LL_DEBUG(IPW_DL_RX, f, ## a) | ||
1478 | #define IPW_DEBUG_TX(f, a...) IPW_LL_DEBUG(IPW_DL_TX, f, ## a) | ||
1479 | #define IPW_DEBUG_ISR(f, a...) IPW_LL_DEBUG(IPW_DL_ISR, f, ## a) | ||
1480 | #define IPW_DEBUG_MANAGEMENT(f, a...) IPW_DEBUG(IPW_DL_MANAGE, f, ## a) | ||
1481 | #define IPW_DEBUG_LED(f, a...) IPW_LL_DEBUG(IPW_DL_LED, f, ## a) | ||
1482 | #define IPW_DEBUG_WEP(f, a...) IPW_LL_DEBUG(IPW_DL_WEP, f, ## a) | ||
1483 | #define IPW_DEBUG_HC(f, a...) IPW_LL_DEBUG(IPW_DL_HOST_COMMAND, f, ## a) | ||
1484 | #define IPW_DEBUG_FRAG(f, a...) IPW_LL_DEBUG(IPW_DL_FRAG, f, ## a) | ||
1485 | #define IPW_DEBUG_FW(f, a...) IPW_LL_DEBUG(IPW_DL_FW, f, ## a) | ||
1486 | #define IPW_DEBUG_RF_KILL(f, a...) IPW_DEBUG(IPW_DL_RF_KILL, f, ## a) | ||
1487 | #define IPW_DEBUG_DROP(f, a...) IPW_DEBUG(IPW_DL_DROP, f, ## a) | ||
1488 | #define IPW_DEBUG_IO(f, a...) IPW_LL_DEBUG(IPW_DL_IO, f, ## a) | ||
1489 | #define IPW_DEBUG_ORD(f, a...) IPW_LL_DEBUG(IPW_DL_ORD, f, ## a) | ||
1490 | #define IPW_DEBUG_FW_INFO(f, a...) IPW_LL_DEBUG(IPW_DL_FW_INFO, f, ## a) | ||
1491 | #define IPW_DEBUG_NOTIF(f, a...) IPW_DEBUG(IPW_DL_NOTIF, f, ## a) | ||
1492 | #define IPW_DEBUG_STATE(f, a...) IPW_DEBUG(IPW_DL_STATE | IPW_DL_ASSOC | IPW_DL_INFO, f, ## a) | ||
1493 | #define IPW_DEBUG_ASSOC(f, a...) IPW_DEBUG(IPW_DL_ASSOC | IPW_DL_INFO, f, ## a) | ||
1494 | #define IPW_DEBUG_STATS(f, a...) IPW_LL_DEBUG(IPW_DL_STATS, f, ## a) | ||
1495 | #define IPW_DEBUG_MERGE(f, a...) IPW_LL_DEBUG(IPW_DL_MERGE, f, ## a) | ||
1496 | #define IPW_DEBUG_QOS(f, a...) IPW_LL_DEBUG(IPW_DL_QOS, f, ## a) | ||
1497 | |||
1498 | #include <linux/ctype.h> | ||
1499 | |||
1500 | /* | ||
1501 | * Register bit definitions | ||
1502 | */ | ||
1503 | |||
1504 | #define IPW_INTA_RW 0x00000008 | ||
1505 | #define IPW_INTA_MASK_R 0x0000000C | ||
1506 | #define IPW_INDIRECT_ADDR 0x00000010 | ||
1507 | #define IPW_INDIRECT_DATA 0x00000014 | ||
1508 | #define IPW_AUTOINC_ADDR 0x00000018 | ||
1509 | #define IPW_AUTOINC_DATA 0x0000001C | ||
1510 | #define IPW_RESET_REG 0x00000020 | ||
1511 | #define IPW_GP_CNTRL_RW 0x00000024 | ||
1512 | |||
1513 | #define IPW_READ_INT_REGISTER 0xFF4 | ||
1514 | |||
1515 | #define IPW_GP_CNTRL_BIT_INIT_DONE 0x00000004 | ||
1516 | |||
1517 | #define IPW_REGISTER_DOMAIN1_END 0x00001000 | ||
1518 | #define IPW_SRAM_READ_INT_REGISTER 0x00000ff4 | ||
1519 | |||
1520 | #define IPW_SHARED_LOWER_BOUND 0x00000200 | ||
1521 | #define IPW_INTERRUPT_AREA_LOWER_BOUND 0x00000f80 | ||
1522 | |||
1523 | #define IPW_NIC_SRAM_LOWER_BOUND 0x00000000 | ||
1524 | #define IPW_NIC_SRAM_UPPER_BOUND 0x00030000 | ||
1525 | |||
1526 | #define IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER (1 << 29) | ||
1527 | #define IPW_GP_CNTRL_BIT_CLOCK_READY 0x00000001 | ||
1528 | #define IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY 0x00000002 | ||
1529 | |||
1530 | /* | ||
1531 | * RESET Register Bit Indexes | ||
1532 | */ | ||
1533 | #define CBD_RESET_REG_PRINCETON_RESET (1<<0) | ||
1534 | #define IPW_START_STANDBY (1<<2) | ||
1535 | #define IPW_ACTIVITY_LED (1<<4) | ||
1536 | #define IPW_ASSOCIATED_LED (1<<5) | ||
1537 | #define IPW_OFDM_LED (1<<6) | ||
1538 | #define IPW_RESET_REG_SW_RESET (1<<7) | ||
1539 | #define IPW_RESET_REG_MASTER_DISABLED (1<<8) | ||
1540 | #define IPW_RESET_REG_STOP_MASTER (1<<9) | ||
1541 | #define IPW_GATE_ODMA (1<<25) | ||
1542 | #define IPW_GATE_IDMA (1<<26) | ||
1543 | #define IPW_ARC_KESHET_CONFIG (1<<27) | ||
1544 | #define IPW_GATE_ADMA (1<<29) | ||
1545 | |||
1546 | #define IPW_CSR_CIS_UPPER_BOUND 0x00000200 | ||
1547 | #define IPW_DOMAIN_0_END 0x1000 | ||
1548 | #define CLX_MEM_BAR_SIZE 0x1000 | ||
1549 | |||
1550 | /* Dino/baseband control registers bits */ | ||
1551 | |||
1552 | #define DINO_ENABLE_SYSTEM 0x80 /* 1 = baseband processor on, 0 = reset */ | ||
1553 | #define DINO_ENABLE_CS 0x40 /* 1 = enable ucode load */ | ||
1554 | #define DINO_RXFIFO_DATA 0x01 /* 1 = data available */ | ||
1555 | #define IPW_BASEBAND_CONTROL_STATUS 0X00200000 | ||
1556 | #define IPW_BASEBAND_TX_FIFO_WRITE 0X00200004 | ||
1557 | #define IPW_BASEBAND_RX_FIFO_READ 0X00200004 | ||
1558 | #define IPW_BASEBAND_CONTROL_STORE 0X00200010 | ||
1559 | |||
1560 | #define IPW_INTERNAL_CMD_EVENT 0X00300004 | ||
1561 | #define IPW_BASEBAND_POWER_DOWN 0x00000001 | ||
1562 | |||
1563 | #define IPW_MEM_HALT_AND_RESET 0x003000e0 | ||
1564 | |||
1565 | /* defgroup bits_halt_reset MEM_HALT_AND_RESET register bits */ | ||
1566 | #define IPW_BIT_HALT_RESET_ON 0x80000000 | ||
1567 | #define IPW_BIT_HALT_RESET_OFF 0x00000000 | ||
1568 | |||
1569 | #define CB_LAST_VALID 0x20000000 | ||
1570 | #define CB_INT_ENABLED 0x40000000 | ||
1571 | #define CB_VALID 0x80000000 | ||
1572 | #define CB_SRC_LE 0x08000000 | ||
1573 | #define CB_DEST_LE 0x04000000 | ||
1574 | #define CB_SRC_AUTOINC 0x00800000 | ||
1575 | #define CB_SRC_IO_GATED 0x00400000 | ||
1576 | #define CB_DEST_AUTOINC 0x00080000 | ||
1577 | #define CB_SRC_SIZE_LONG 0x00200000 | ||
1578 | #define CB_DEST_SIZE_LONG 0x00020000 | ||
1579 | |||
1580 | /* DMA DEFINES */ | ||
1581 | |||
1582 | #define DMA_CONTROL_SMALL_CB_CONST_VALUE 0x00540000 | ||
1583 | #define DMA_CB_STOP_AND_ABORT 0x00000C00 | ||
1584 | #define DMA_CB_START 0x00000100 | ||
1585 | |||
1586 | #define IPW_SHARED_SRAM_SIZE 0x00030000 | ||
1587 | #define IPW_SHARED_SRAM_DMA_CONTROL 0x00027000 | ||
1588 | #define CB_MAX_LENGTH 0x1FFF | ||
1589 | |||
1590 | #define IPW_HOST_EEPROM_DATA_SRAM_SIZE 0xA18 | ||
1591 | #define IPW_EEPROM_IMAGE_SIZE 0x100 | ||
1592 | |||
1593 | /* DMA defs */ | ||
1594 | #define IPW_DMA_I_CURRENT_CB 0x003000D0 | ||
1595 | #define IPW_DMA_O_CURRENT_CB 0x003000D4 | ||
1596 | #define IPW_DMA_I_DMA_CONTROL 0x003000A4 | ||
1597 | #define IPW_DMA_I_CB_BASE 0x003000A0 | ||
1598 | |||
1599 | #define IPW_TX_CMD_QUEUE_BD_BASE 0x00000200 | ||
1600 | #define IPW_TX_CMD_QUEUE_BD_SIZE 0x00000204 | ||
1601 | #define IPW_TX_QUEUE_0_BD_BASE 0x00000208 | ||
1602 | #define IPW_TX_QUEUE_0_BD_SIZE (0x0000020C) | ||
1603 | #define IPW_TX_QUEUE_1_BD_BASE 0x00000210 | ||
1604 | #define IPW_TX_QUEUE_1_BD_SIZE 0x00000214 | ||
1605 | #define IPW_TX_QUEUE_2_BD_BASE 0x00000218 | ||
1606 | #define IPW_TX_QUEUE_2_BD_SIZE (0x0000021C) | ||
1607 | #define IPW_TX_QUEUE_3_BD_BASE 0x00000220 | ||
1608 | #define IPW_TX_QUEUE_3_BD_SIZE 0x00000224 | ||
1609 | #define IPW_RX_BD_BASE 0x00000240 | ||
1610 | #define IPW_RX_BD_SIZE 0x00000244 | ||
1611 | #define IPW_RFDS_TABLE_LOWER 0x00000500 | ||
1612 | |||
1613 | #define IPW_TX_CMD_QUEUE_READ_INDEX 0x00000280 | ||
1614 | #define IPW_TX_QUEUE_0_READ_INDEX 0x00000284 | ||
1615 | #define IPW_TX_QUEUE_1_READ_INDEX 0x00000288 | ||
1616 | #define IPW_TX_QUEUE_2_READ_INDEX (0x0000028C) | ||
1617 | #define IPW_TX_QUEUE_3_READ_INDEX 0x00000290 | ||
1618 | #define IPW_RX_READ_INDEX (0x000002A0) | ||
1619 | |||
1620 | #define IPW_TX_CMD_QUEUE_WRITE_INDEX (0x00000F80) | ||
1621 | #define IPW_TX_QUEUE_0_WRITE_INDEX (0x00000F84) | ||
1622 | #define IPW_TX_QUEUE_1_WRITE_INDEX (0x00000F88) | ||
1623 | #define IPW_TX_QUEUE_2_WRITE_INDEX (0x00000F8C) | ||
1624 | #define IPW_TX_QUEUE_3_WRITE_INDEX (0x00000F90) | ||
1625 | #define IPW_RX_WRITE_INDEX (0x00000FA0) | ||
1626 | |||
1627 | /* | ||
1628 | * EEPROM Related Definitions | ||
1629 | */ | ||
1630 | |||
1631 | #define IPW_EEPROM_DATA_SRAM_ADDRESS (IPW_SHARED_LOWER_BOUND + 0x814) | ||
1632 | #define IPW_EEPROM_DATA_SRAM_SIZE (IPW_SHARED_LOWER_BOUND + 0x818) | ||
1633 | #define IPW_EEPROM_LOAD_DISABLE (IPW_SHARED_LOWER_BOUND + 0x81C) | ||
1634 | #define IPW_EEPROM_DATA (IPW_SHARED_LOWER_BOUND + 0x820) | ||
1635 | #define IPW_EEPROM_UPPER_ADDRESS (IPW_SHARED_LOWER_BOUND + 0x9E0) | ||
1636 | |||
1637 | #define IPW_STATION_TABLE_LOWER (IPW_SHARED_LOWER_BOUND + 0xA0C) | ||
1638 | #define IPW_STATION_TABLE_UPPER (IPW_SHARED_LOWER_BOUND + 0xB0C) | ||
1639 | #define IPW_REQUEST_ATIM (IPW_SHARED_LOWER_BOUND + 0xB0C) | ||
1640 | #define IPW_ATIM_SENT (IPW_SHARED_LOWER_BOUND + 0xB10) | ||
1641 | #define IPW_WHO_IS_AWAKE (IPW_SHARED_LOWER_BOUND + 0xB14) | ||
1642 | #define IPW_DURING_ATIM_WINDOW (IPW_SHARED_LOWER_BOUND + 0xB18) | ||
1643 | |||
1644 | #define MSB 1 | ||
1645 | #define LSB 0 | ||
1646 | #define WORD_TO_BYTE(_word) ((_word) * sizeof(u16)) | ||
1647 | |||
1648 | #define GET_EEPROM_ADDR(_wordoffset,_byteoffset) \ | ||
1649 | ( WORD_TO_BYTE(_wordoffset) + (_byteoffset) ) | ||
1650 | |||
1651 | /* EEPROM access by BYTE */ | ||
1652 | #define EEPROM_PME_CAPABILITY (GET_EEPROM_ADDR(0x09,MSB)) /* 1 byte */ | ||
1653 | #define EEPROM_MAC_ADDRESS (GET_EEPROM_ADDR(0x21,LSB)) /* 6 byte */ | ||
1654 | #define EEPROM_VERSION (GET_EEPROM_ADDR(0x24,MSB)) /* 1 byte */ | ||
1655 | #define EEPROM_NIC_TYPE (GET_EEPROM_ADDR(0x25,LSB)) /* 1 byte */ | ||
1656 | #define EEPROM_SKU_CAPABILITY (GET_EEPROM_ADDR(0x25,MSB)) /* 1 byte */ | ||
1657 | #define EEPROM_COUNTRY_CODE (GET_EEPROM_ADDR(0x26,LSB)) /* 3 bytes */ | ||
1658 | #define EEPROM_IBSS_CHANNELS_BG (GET_EEPROM_ADDR(0x28,LSB)) /* 2 bytes */ | ||
1659 | #define EEPROM_IBSS_CHANNELS_A (GET_EEPROM_ADDR(0x29,MSB)) /* 5 bytes */ | ||
1660 | #define EEPROM_BSS_CHANNELS_BG (GET_EEPROM_ADDR(0x2c,LSB)) /* 2 bytes */ | ||
1661 | #define EEPROM_HW_VERSION (GET_EEPROM_ADDR(0x72,LSB)) /* 2 bytes */ | ||
1662 | |||
1663 | /* NIC type as found in the one byte EEPROM_NIC_TYPE offset */ | ||
1664 | #define EEPROM_NIC_TYPE_0 0 | ||
1665 | #define EEPROM_NIC_TYPE_1 1 | ||
1666 | #define EEPROM_NIC_TYPE_2 2 | ||
1667 | #define EEPROM_NIC_TYPE_3 3 | ||
1668 | #define EEPROM_NIC_TYPE_4 4 | ||
1669 | |||
1670 | /* Bluetooth Coexistence capabilities as found in EEPROM_SKU_CAPABILITY */ | ||
1671 | #define EEPROM_SKU_CAP_BT_CHANNEL_SIG 0x01 /* we can tell BT our channel # */ | ||
1672 | #define EEPROM_SKU_CAP_BT_PRIORITY 0x02 /* BT can take priority over us */ | ||
1673 | #define EEPROM_SKU_CAP_BT_OOB 0x04 /* we can signal BT out-of-band */ | ||
1674 | |||
1675 | #define FW_MEM_REG_LOWER_BOUND 0x00300000 | ||
1676 | #define FW_MEM_REG_EEPROM_ACCESS (FW_MEM_REG_LOWER_BOUND + 0x40) | ||
1677 | #define IPW_EVENT_REG (FW_MEM_REG_LOWER_BOUND + 0x04) | ||
1678 | #define EEPROM_BIT_SK (1<<0) | ||
1679 | #define EEPROM_BIT_CS (1<<1) | ||
1680 | #define EEPROM_BIT_DI (1<<2) | ||
1681 | #define EEPROM_BIT_DO (1<<4) | ||
1682 | |||
1683 | #define EEPROM_CMD_READ 0x2 | ||
1684 | |||
1685 | /* Interrupts masks */ | ||
1686 | #define IPW_INTA_NONE 0x00000000 | ||
1687 | |||
1688 | #define IPW_INTA_BIT_RX_TRANSFER 0x00000002 | ||
1689 | #define IPW_INTA_BIT_STATUS_CHANGE 0x00000010 | ||
1690 | #define IPW_INTA_BIT_BEACON_PERIOD_EXPIRED 0x00000020 | ||
1691 | |||
1692 | //Inta Bits for CF | ||
1693 | #define IPW_INTA_BIT_TX_CMD_QUEUE 0x00000800 | ||
1694 | #define IPW_INTA_BIT_TX_QUEUE_1 0x00001000 | ||
1695 | #define IPW_INTA_BIT_TX_QUEUE_2 0x00002000 | ||
1696 | #define IPW_INTA_BIT_TX_QUEUE_3 0x00004000 | ||
1697 | #define IPW_INTA_BIT_TX_QUEUE_4 0x00008000 | ||
1698 | |||
1699 | #define IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE 0x00010000 | ||
1700 | |||
1701 | #define IPW_INTA_BIT_PREPARE_FOR_POWER_DOWN 0x00100000 | ||
1702 | #define IPW_INTA_BIT_POWER_DOWN 0x00200000 | ||
1703 | |||
1704 | #define IPW_INTA_BIT_FW_INITIALIZATION_DONE 0x01000000 | ||
1705 | #define IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE 0x02000000 | ||
1706 | #define IPW_INTA_BIT_RF_KILL_DONE 0x04000000 | ||
1707 | #define IPW_INTA_BIT_FATAL_ERROR 0x40000000 | ||
1708 | #define IPW_INTA_BIT_PARITY_ERROR 0x80000000 | ||
1709 | |||
1710 | /* Interrupts enabled at init time. */ | ||
1711 | #define IPW_INTA_MASK_ALL \ | ||
1712 | (IPW_INTA_BIT_TX_QUEUE_1 | \ | ||
1713 | IPW_INTA_BIT_TX_QUEUE_2 | \ | ||
1714 | IPW_INTA_BIT_TX_QUEUE_3 | \ | ||
1715 | IPW_INTA_BIT_TX_QUEUE_4 | \ | ||
1716 | IPW_INTA_BIT_TX_CMD_QUEUE | \ | ||
1717 | IPW_INTA_BIT_RX_TRANSFER | \ | ||
1718 | IPW_INTA_BIT_FATAL_ERROR | \ | ||
1719 | IPW_INTA_BIT_PARITY_ERROR | \ | ||
1720 | IPW_INTA_BIT_STATUS_CHANGE | \ | ||
1721 | IPW_INTA_BIT_FW_INITIALIZATION_DONE | \ | ||
1722 | IPW_INTA_BIT_BEACON_PERIOD_EXPIRED | \ | ||
1723 | IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE | \ | ||
1724 | IPW_INTA_BIT_PREPARE_FOR_POWER_DOWN | \ | ||
1725 | IPW_INTA_BIT_POWER_DOWN | \ | ||
1726 | IPW_INTA_BIT_RF_KILL_DONE ) | ||
1727 | |||
1728 | /* FW event log definitions */ | ||
1729 | #define EVENT_ELEM_SIZE (3 * sizeof(u32)) | ||
1730 | #define EVENT_START_OFFSET (1 * sizeof(u32) + 2 * sizeof(u16)) | ||
1731 | |||
1732 | /* FW error log definitions */ | ||
1733 | #define ERROR_ELEM_SIZE (7 * sizeof(u32)) | ||
1734 | #define ERROR_START_OFFSET (1 * sizeof(u32)) | ||
1735 | |||
1736 | /* TX power level (dbm) */ | ||
1737 | #define IPW_TX_POWER_MIN -12 | ||
1738 | #define IPW_TX_POWER_MAX 20 | ||
1739 | #define IPW_TX_POWER_DEFAULT IPW_TX_POWER_MAX | ||
1740 | |||
1741 | enum { | ||
1742 | IPW_FW_ERROR_OK = 0, | ||
1743 | IPW_FW_ERROR_FAIL, | ||
1744 | IPW_FW_ERROR_MEMORY_UNDERFLOW, | ||
1745 | IPW_FW_ERROR_MEMORY_OVERFLOW, | ||
1746 | IPW_FW_ERROR_BAD_PARAM, | ||
1747 | IPW_FW_ERROR_BAD_CHECKSUM, | ||
1748 | IPW_FW_ERROR_NMI_INTERRUPT, | ||
1749 | IPW_FW_ERROR_BAD_DATABASE, | ||
1750 | IPW_FW_ERROR_ALLOC_FAIL, | ||
1751 | IPW_FW_ERROR_DMA_UNDERRUN, | ||
1752 | IPW_FW_ERROR_DMA_STATUS, | ||
1753 | IPW_FW_ERROR_DINO_ERROR, | ||
1754 | IPW_FW_ERROR_EEPROM_ERROR, | ||
1755 | IPW_FW_ERROR_SYSASSERT, | ||
1756 | IPW_FW_ERROR_FATAL_ERROR | ||
1757 | }; | ||
1758 | |||
1759 | #define AUTH_OPEN 0 | ||
1760 | #define AUTH_SHARED_KEY 1 | ||
1761 | #define AUTH_LEAP 2 | ||
1762 | #define AUTH_IGNORE 3 | ||
1763 | |||
1764 | #define HC_ASSOCIATE 0 | ||
1765 | #define HC_REASSOCIATE 1 | ||
1766 | #define HC_DISASSOCIATE 2 | ||
1767 | #define HC_IBSS_START 3 | ||
1768 | #define HC_IBSS_RECONF 4 | ||
1769 | #define HC_DISASSOC_QUIET 5 | ||
1770 | |||
1771 | #define HC_QOS_SUPPORT_ASSOC cpu_to_le16(0x01) | ||
1772 | |||
1773 | #define IPW_RATE_CAPABILITIES 1 | ||
1774 | #define IPW_RATE_CONNECT 0 | ||
1775 | |||
1776 | /* | ||
1777 | * Rate values and masks | ||
1778 | */ | ||
1779 | #define IPW_TX_RATE_1MB 0x0A | ||
1780 | #define IPW_TX_RATE_2MB 0x14 | ||
1781 | #define IPW_TX_RATE_5MB 0x37 | ||
1782 | #define IPW_TX_RATE_6MB 0x0D | ||
1783 | #define IPW_TX_RATE_9MB 0x0F | ||
1784 | #define IPW_TX_RATE_11MB 0x6E | ||
1785 | #define IPW_TX_RATE_12MB 0x05 | ||
1786 | #define IPW_TX_RATE_18MB 0x07 | ||
1787 | #define IPW_TX_RATE_24MB 0x09 | ||
1788 | #define IPW_TX_RATE_36MB 0x0B | ||
1789 | #define IPW_TX_RATE_48MB 0x01 | ||
1790 | #define IPW_TX_RATE_54MB 0x03 | ||
1791 | |||
1792 | #define IPW_ORD_TABLE_ID_MASK 0x0000FF00 | ||
1793 | #define IPW_ORD_TABLE_VALUE_MASK 0x000000FF | ||
1794 | |||
1795 | #define IPW_ORD_TABLE_0_MASK 0x0000F000 | ||
1796 | #define IPW_ORD_TABLE_1_MASK 0x0000F100 | ||
1797 | #define IPW_ORD_TABLE_2_MASK 0x0000F200 | ||
1798 | #define IPW_ORD_TABLE_3_MASK 0x0000F300 | ||
1799 | #define IPW_ORD_TABLE_4_MASK 0x0000F400 | ||
1800 | #define IPW_ORD_TABLE_5_MASK 0x0000F500 | ||
1801 | #define IPW_ORD_TABLE_6_MASK 0x0000F600 | ||
1802 | #define IPW_ORD_TABLE_7_MASK 0x0000F700 | ||
1803 | |||
1804 | /* | ||
1805 | * Table 0 Entries (all entries are 32 bits) | ||
1806 | */ | ||
1807 | enum { | ||
1808 | IPW_ORD_STAT_TX_CURR_RATE = IPW_ORD_TABLE_0_MASK + 1, | ||
1809 | IPW_ORD_STAT_FRAG_TRESHOLD, | ||
1810 | IPW_ORD_STAT_RTS_THRESHOLD, | ||
1811 | IPW_ORD_STAT_TX_HOST_REQUESTS, | ||
1812 | IPW_ORD_STAT_TX_HOST_COMPLETE, | ||
1813 | IPW_ORD_STAT_TX_DIR_DATA, | ||
1814 | IPW_ORD_STAT_TX_DIR_DATA_B_1, | ||
1815 | IPW_ORD_STAT_TX_DIR_DATA_B_2, | ||
1816 | IPW_ORD_STAT_TX_DIR_DATA_B_5_5, | ||
1817 | IPW_ORD_STAT_TX_DIR_DATA_B_11, | ||
1818 | /* Hole */ | ||
1819 | |||
1820 | IPW_ORD_STAT_TX_DIR_DATA_G_1 = IPW_ORD_TABLE_0_MASK + 19, | ||
1821 | IPW_ORD_STAT_TX_DIR_DATA_G_2, | ||
1822 | IPW_ORD_STAT_TX_DIR_DATA_G_5_5, | ||
1823 | IPW_ORD_STAT_TX_DIR_DATA_G_6, | ||
1824 | IPW_ORD_STAT_TX_DIR_DATA_G_9, | ||
1825 | IPW_ORD_STAT_TX_DIR_DATA_G_11, | ||
1826 | IPW_ORD_STAT_TX_DIR_DATA_G_12, | ||
1827 | IPW_ORD_STAT_TX_DIR_DATA_G_18, | ||
1828 | IPW_ORD_STAT_TX_DIR_DATA_G_24, | ||
1829 | IPW_ORD_STAT_TX_DIR_DATA_G_36, | ||
1830 | IPW_ORD_STAT_TX_DIR_DATA_G_48, | ||
1831 | IPW_ORD_STAT_TX_DIR_DATA_G_54, | ||
1832 | IPW_ORD_STAT_TX_NON_DIR_DATA, | ||
1833 | IPW_ORD_STAT_TX_NON_DIR_DATA_B_1, | ||
1834 | IPW_ORD_STAT_TX_NON_DIR_DATA_B_2, | ||
1835 | IPW_ORD_STAT_TX_NON_DIR_DATA_B_5_5, | ||
1836 | IPW_ORD_STAT_TX_NON_DIR_DATA_B_11, | ||
1837 | /* Hole */ | ||
1838 | |||
1839 | IPW_ORD_STAT_TX_NON_DIR_DATA_G_1 = IPW_ORD_TABLE_0_MASK + 44, | ||
1840 | IPW_ORD_STAT_TX_NON_DIR_DATA_G_2, | ||
1841 | IPW_ORD_STAT_TX_NON_DIR_DATA_G_5_5, | ||
1842 | IPW_ORD_STAT_TX_NON_DIR_DATA_G_6, | ||
1843 | IPW_ORD_STAT_TX_NON_DIR_DATA_G_9, | ||
1844 | IPW_ORD_STAT_TX_NON_DIR_DATA_G_11, | ||
1845 | IPW_ORD_STAT_TX_NON_DIR_DATA_G_12, | ||
1846 | IPW_ORD_STAT_TX_NON_DIR_DATA_G_18, | ||
1847 | IPW_ORD_STAT_TX_NON_DIR_DATA_G_24, | ||
1848 | IPW_ORD_STAT_TX_NON_DIR_DATA_G_36, | ||
1849 | IPW_ORD_STAT_TX_NON_DIR_DATA_G_48, | ||
1850 | IPW_ORD_STAT_TX_NON_DIR_DATA_G_54, | ||
1851 | IPW_ORD_STAT_TX_RETRY, | ||
1852 | IPW_ORD_STAT_TX_FAILURE, | ||
1853 | IPW_ORD_STAT_RX_ERR_CRC, | ||
1854 | IPW_ORD_STAT_RX_ERR_ICV, | ||
1855 | IPW_ORD_STAT_RX_NO_BUFFER, | ||
1856 | IPW_ORD_STAT_FULL_SCANS, | ||
1857 | IPW_ORD_STAT_PARTIAL_SCANS, | ||
1858 | IPW_ORD_STAT_TGH_ABORTED_SCANS, | ||
1859 | IPW_ORD_STAT_TX_TOTAL_BYTES, | ||
1860 | IPW_ORD_STAT_CURR_RSSI_RAW, | ||
1861 | IPW_ORD_STAT_RX_BEACON, | ||
1862 | IPW_ORD_STAT_MISSED_BEACONS, | ||
1863 | IPW_ORD_TABLE_0_LAST | ||
1864 | }; | ||
1865 | |||
1866 | #define IPW_RSSI_TO_DBM 112 | ||
1867 | |||
1868 | /* Table 1 Entries | ||
1869 | */ | ||
1870 | enum { | ||
1871 | IPW_ORD_TABLE_1_LAST = IPW_ORD_TABLE_1_MASK | 1, | ||
1872 | }; | ||
1873 | |||
1874 | /* | ||
1875 | * Table 2 Entries | ||
1876 | * | ||
1877 | * FW_VERSION: 16 byte string | ||
1878 | * FW_DATE: 16 byte string (only 14 bytes used) | ||
1879 | * UCODE_VERSION: 4 byte version code | ||
1880 | * UCODE_DATE: 5 bytes code code | ||
1881 | * ADDAPTER_MAC: 6 byte MAC address | ||
1882 | * RTC: 4 byte clock | ||
1883 | */ | ||
1884 | enum { | ||
1885 | IPW_ORD_STAT_FW_VERSION = IPW_ORD_TABLE_2_MASK | 1, | ||
1886 | IPW_ORD_STAT_FW_DATE, | ||
1887 | IPW_ORD_STAT_UCODE_VERSION, | ||
1888 | IPW_ORD_STAT_UCODE_DATE, | ||
1889 | IPW_ORD_STAT_ADAPTER_MAC, | ||
1890 | IPW_ORD_STAT_RTC, | ||
1891 | IPW_ORD_TABLE_2_LAST | ||
1892 | }; | ||
1893 | |||
1894 | /* Table 3 */ | ||
1895 | enum { | ||
1896 | IPW_ORD_STAT_TX_PACKET = IPW_ORD_TABLE_3_MASK | 0, | ||
1897 | IPW_ORD_STAT_TX_PACKET_FAILURE, | ||
1898 | IPW_ORD_STAT_TX_PACKET_SUCCESS, | ||
1899 | IPW_ORD_STAT_TX_PACKET_ABORTED, | ||
1900 | IPW_ORD_TABLE_3_LAST | ||
1901 | }; | ||
1902 | |||
1903 | /* Table 4 */ | ||
1904 | enum { | ||
1905 | IPW_ORD_TABLE_4_LAST = IPW_ORD_TABLE_4_MASK | ||
1906 | }; | ||
1907 | |||
1908 | /* Table 5 */ | ||
1909 | enum { | ||
1910 | IPW_ORD_STAT_AVAILABLE_AP_COUNT = IPW_ORD_TABLE_5_MASK, | ||
1911 | IPW_ORD_STAT_AP_ASSNS, | ||
1912 | IPW_ORD_STAT_ROAM, | ||
1913 | IPW_ORD_STAT_ROAM_CAUSE_MISSED_BEACONS, | ||
1914 | IPW_ORD_STAT_ROAM_CAUSE_UNASSOC, | ||
1915 | IPW_ORD_STAT_ROAM_CAUSE_RSSI, | ||
1916 | IPW_ORD_STAT_ROAM_CAUSE_LINK_QUALITY, | ||
1917 | IPW_ORD_STAT_ROAM_CAUSE_AP_LOAD_BALANCE, | ||
1918 | IPW_ORD_STAT_ROAM_CAUSE_AP_NO_TX, | ||
1919 | IPW_ORD_STAT_LINK_UP, | ||
1920 | IPW_ORD_STAT_LINK_DOWN, | ||
1921 | IPW_ORD_ANTENNA_DIVERSITY, | ||
1922 | IPW_ORD_CURR_FREQ, | ||
1923 | IPW_ORD_TABLE_5_LAST | ||
1924 | }; | ||
1925 | |||
1926 | /* Table 6 */ | ||
1927 | enum { | ||
1928 | IPW_ORD_COUNTRY_CODE = IPW_ORD_TABLE_6_MASK, | ||
1929 | IPW_ORD_CURR_BSSID, | ||
1930 | IPW_ORD_CURR_SSID, | ||
1931 | IPW_ORD_TABLE_6_LAST | ||
1932 | }; | ||
1933 | |||
1934 | /* Table 7 */ | ||
1935 | enum { | ||
1936 | IPW_ORD_STAT_PERCENT_MISSED_BEACONS = IPW_ORD_TABLE_7_MASK, | ||
1937 | IPW_ORD_STAT_PERCENT_TX_RETRIES, | ||
1938 | IPW_ORD_STAT_PERCENT_LINK_QUALITY, | ||
1939 | IPW_ORD_STAT_CURR_RSSI_DBM, | ||
1940 | IPW_ORD_TABLE_7_LAST | ||
1941 | }; | ||
1942 | |||
1943 | #define IPW_ERROR_LOG (IPW_SHARED_LOWER_BOUND + 0x410) | ||
1944 | #define IPW_EVENT_LOG (IPW_SHARED_LOWER_BOUND + 0x414) | ||
1945 | #define IPW_ORDINALS_TABLE_LOWER (IPW_SHARED_LOWER_BOUND + 0x500) | ||
1946 | #define IPW_ORDINALS_TABLE_0 (IPW_SHARED_LOWER_BOUND + 0x180) | ||
1947 | #define IPW_ORDINALS_TABLE_1 (IPW_SHARED_LOWER_BOUND + 0x184) | ||
1948 | #define IPW_ORDINALS_TABLE_2 (IPW_SHARED_LOWER_BOUND + 0x188) | ||
1949 | #define IPW_MEM_FIXED_OVERRIDE (IPW_SHARED_LOWER_BOUND + 0x41C) | ||
1950 | |||
1951 | struct ipw_fixed_rate { | ||
1952 | __le16 tx_rates; | ||
1953 | __le16 reserved; | ||
1954 | } __attribute__ ((packed)); | ||
1955 | |||
1956 | #define IPW_INDIRECT_ADDR_MASK (~0x3ul) | ||
1957 | |||
1958 | struct host_cmd { | ||
1959 | u8 cmd; | ||
1960 | u8 len; | ||
1961 | u16 reserved; | ||
1962 | u32 *param; | ||
1963 | } __attribute__ ((packed)); /* XXX */ | ||
1964 | |||
1965 | struct cmdlog_host_cmd { | ||
1966 | u8 cmd; | ||
1967 | u8 len; | ||
1968 | __le16 reserved; | ||
1969 | char param[124]; | ||
1970 | } __attribute__ ((packed)); | ||
1971 | |||
1972 | struct ipw_cmd_log { | ||
1973 | unsigned long jiffies; | ||
1974 | int retcode; | ||
1975 | struct cmdlog_host_cmd cmd; | ||
1976 | }; | ||
1977 | |||
1978 | /* SysConfig command parameters ... */ | ||
1979 | /* bt_coexistence param */ | ||
1980 | #define CFG_BT_COEXISTENCE_SIGNAL_CHNL 0x01 /* tell BT our chnl # */ | ||
1981 | #define CFG_BT_COEXISTENCE_DEFER 0x02 /* defer our Tx if BT traffic */ | ||
1982 | #define CFG_BT_COEXISTENCE_KILL 0x04 /* kill our Tx if BT traffic */ | ||
1983 | #define CFG_BT_COEXISTENCE_WME_OVER_BT 0x08 /* multimedia extensions */ | ||
1984 | #define CFG_BT_COEXISTENCE_OOB 0x10 /* signal BT via out-of-band */ | ||
1985 | |||
1986 | /* clear-to-send to self param */ | ||
1987 | #define CFG_CTS_TO_ITSELF_ENABLED_MIN 0x00 | ||
1988 | #define CFG_CTS_TO_ITSELF_ENABLED_MAX 0x01 | ||
1989 | #define CFG_CTS_TO_ITSELF_ENABLED_DEF CFG_CTS_TO_ITSELF_ENABLED_MIN | ||
1990 | |||
1991 | /* Antenna diversity param (h/w can select best antenna, based on signal) */ | ||
1992 | #define CFG_SYS_ANTENNA_BOTH 0x00 /* NIC selects best antenna */ | ||
1993 | #define CFG_SYS_ANTENNA_A 0x01 /* force antenna A */ | ||
1994 | #define CFG_SYS_ANTENNA_B 0x03 /* force antenna B */ | ||
1995 | #define CFG_SYS_ANTENNA_SLOW_DIV 0x02 /* consider background noise */ | ||
1996 | |||
1997 | /* | ||
1998 | * The definitions below were lifted off the ipw2100 driver, which only | ||
1999 | * supports 'b' mode, so I'm sure these are not exactly correct. | ||
2000 | * | ||
2001 | * Somebody fix these!! | ||
2002 | */ | ||
2003 | #define REG_MIN_CHANNEL 0 | ||
2004 | #define REG_MAX_CHANNEL 14 | ||
2005 | |||
2006 | #define REG_CHANNEL_MASK 0x00003FFF | ||
2007 | #define IPW_IBSS_11B_DEFAULT_MASK 0x87ff | ||
2008 | |||
2009 | #define IPW_MAX_CONFIG_RETRIES 10 | ||
2010 | |||
2011 | #endif /* __ipw2200_h__ */ | ||