]>
Commit | Line | Data |
---|---|---|
2c86c275 JK |
1 | /****************************************************************************** |
2 | ||
3 | Copyright(c) 2003 - 2005 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 | <jkmaline@cc.hut.fi> | |
32 | Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.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() | |
19f7f742 | 109 | HEAD modified by ipw2100_tx_send_data() |
2c86c275 JK |
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() | |
19f7f742 | 117 | HEAD modified in ipw2100_tx_send_commands() |
2c86c275 JK |
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/config.h> | |
138 | #include <linux/errno.h> | |
139 | #include <linux/if_arp.h> | |
140 | #include <linux/in6.h> | |
141 | #include <linux/in.h> | |
142 | #include <linux/ip.h> | |
143 | #include <linux/kernel.h> | |
144 | #include <linux/kmod.h> | |
145 | #include <linux/module.h> | |
146 | #include <linux/netdevice.h> | |
147 | #include <linux/ethtool.h> | |
148 | #include <linux/pci.h> | |
05743d16 | 149 | #include <linux/dma-mapping.h> |
2c86c275 JK |
150 | #include <linux/proc_fs.h> |
151 | #include <linux/skbuff.h> | |
152 | #include <asm/uaccess.h> | |
153 | #include <asm/io.h> | |
154 | #define __KERNEL_SYSCALLS__ | |
155 | #include <linux/fs.h> | |
156 | #include <linux/mm.h> | |
157 | #include <linux/slab.h> | |
158 | #include <linux/unistd.h> | |
159 | #include <linux/stringify.h> | |
160 | #include <linux/tcp.h> | |
161 | #include <linux/types.h> | |
162 | #include <linux/version.h> | |
163 | #include <linux/time.h> | |
164 | #include <linux/firmware.h> | |
165 | #include <linux/acpi.h> | |
166 | #include <linux/ctype.h> | |
167 | ||
168 | #include "ipw2100.h" | |
169 | ||
170 | #define IPW2100_VERSION "1.1.0" | |
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-2004 Intel Corporation" | |
176 | ||
177 | ||
178 | /* Debugging stuff */ | |
179 | #ifdef CONFIG_IPW_DEBUG | |
180 | #define CONFIG_IPW2100_RX_DEBUG /* Reception debugging */ | |
181 | #endif | |
182 | ||
183 | MODULE_DESCRIPTION(DRV_DESCRIPTION); | |
184 | MODULE_VERSION(DRV_VERSION); | |
185 | MODULE_AUTHOR(DRV_COPYRIGHT); | |
186 | MODULE_LICENSE("GPL"); | |
187 | ||
188 | static int debug = 0; | |
189 | static int mode = 0; | |
190 | static int channel = 0; | |
191 | static int associate = 1; | |
192 | static int disable = 0; | |
193 | #ifdef CONFIG_PM | |
194 | static struct ipw2100_fw ipw2100_firmware; | |
195 | #endif | |
196 | ||
197 | #include <linux/moduleparam.h> | |
198 | module_param(debug, int, 0444); | |
199 | module_param(mode, int, 0444); | |
200 | module_param(channel, int, 0444); | |
201 | module_param(associate, int, 0444); | |
202 | module_param(disable, int, 0444); | |
203 | ||
204 | MODULE_PARM_DESC(debug, "debug level"); | |
205 | MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)"); | |
206 | MODULE_PARM_DESC(channel, "channel"); | |
207 | MODULE_PARM_DESC(associate, "auto associate when scanning (default on)"); | |
208 | MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])"); | |
209 | ||
c4aee8c2 JB |
210 | static u32 ipw2100_debug_level = IPW_DL_NONE; |
211 | ||
212 | #ifdef CONFIG_IPW_DEBUG | |
213 | #define IPW_DEBUG(level, message...) \ | |
214 | do { \ | |
215 | if (ipw2100_debug_level & (level)) { \ | |
216 | printk(KERN_DEBUG "ipw2100: %c %s ", \ | |
217 | in_interrupt() ? 'I' : 'U', __FUNCTION__); \ | |
218 | printk(message); \ | |
219 | } \ | |
220 | } while (0) | |
221 | #else | |
222 | #define IPW_DEBUG(level, message...) do {} while (0) | |
223 | #endif /* CONFIG_IPW_DEBUG */ | |
2c86c275 JK |
224 | |
225 | #ifdef CONFIG_IPW_DEBUG | |
226 | static const char *command_types[] = { | |
227 | "undefined", | |
228 | "unused", /* HOST_ATTENTION */ | |
229 | "HOST_COMPLETE", | |
230 | "unused", /* SLEEP */ | |
231 | "unused", /* HOST_POWER_DOWN */ | |
232 | "unused", | |
233 | "SYSTEM_CONFIG", | |
234 | "unused", /* SET_IMR */ | |
235 | "SSID", | |
236 | "MANDATORY_BSSID", | |
237 | "AUTHENTICATION_TYPE", | |
238 | "ADAPTER_ADDRESS", | |
239 | "PORT_TYPE", | |
240 | "INTERNATIONAL_MODE", | |
241 | "CHANNEL", | |
242 | "RTS_THRESHOLD", | |
243 | "FRAG_THRESHOLD", | |
244 | "POWER_MODE", | |
245 | "TX_RATES", | |
246 | "BASIC_TX_RATES", | |
247 | "WEP_KEY_INFO", | |
248 | "unused", | |
249 | "unused", | |
250 | "unused", | |
251 | "unused", | |
252 | "WEP_KEY_INDEX", | |
253 | "WEP_FLAGS", | |
254 | "ADD_MULTICAST", | |
255 | "CLEAR_ALL_MULTICAST", | |
256 | "BEACON_INTERVAL", | |
257 | "ATIM_WINDOW", | |
258 | "CLEAR_STATISTICS", | |
259 | "undefined", | |
260 | "undefined", | |
261 | "undefined", | |
262 | "undefined", | |
263 | "TX_POWER_INDEX", | |
264 | "undefined", | |
265 | "undefined", | |
266 | "undefined", | |
267 | "undefined", | |
268 | "undefined", | |
269 | "undefined", | |
270 | "BROADCAST_SCAN", | |
271 | "CARD_DISABLE", | |
272 | "PREFERRED_BSSID", | |
273 | "SET_SCAN_OPTIONS", | |
274 | "SCAN_DWELL_TIME", | |
275 | "SWEEP_TABLE", | |
276 | "AP_OR_STATION_TABLE", | |
277 | "GROUP_ORDINALS", | |
278 | "SHORT_RETRY_LIMIT", | |
279 | "LONG_RETRY_LIMIT", | |
280 | "unused", /* SAVE_CALIBRATION */ | |
281 | "unused", /* RESTORE_CALIBRATION */ | |
282 | "undefined", | |
283 | "undefined", | |
284 | "undefined", | |
285 | "HOST_PRE_POWER_DOWN", | |
286 | "unused", /* HOST_INTERRUPT_COALESCING */ | |
287 | "undefined", | |
288 | "CARD_DISABLE_PHY_OFF", | |
289 | "MSDU_TX_RATES" | |
290 | "undefined", | |
291 | "undefined", | |
292 | "SET_STATION_STAT_BITS", | |
293 | "CLEAR_STATIONS_STAT_BITS", | |
294 | "LEAP_ROGUE_MODE", | |
295 | "SET_SECURITY_INFORMATION", | |
296 | "DISASSOCIATION_BSSID", | |
297 | "SET_WPA_ASS_IE" | |
298 | }; | |
299 | #endif | |
300 | ||
301 | ||
302 | /* Pre-decl until we get the code solid and then we can clean it up */ | |
19f7f742 JB |
303 | static void ipw2100_tx_send_commands(struct ipw2100_priv *priv); |
304 | static void ipw2100_tx_send_data(struct ipw2100_priv *priv); | |
2c86c275 JK |
305 | static int ipw2100_adapter_setup(struct ipw2100_priv *priv); |
306 | ||
307 | static void ipw2100_queues_initialize(struct ipw2100_priv *priv); | |
308 | static void ipw2100_queues_free(struct ipw2100_priv *priv); | |
309 | static int ipw2100_queues_allocate(struct ipw2100_priv *priv); | |
310 | ||
c4aee8c2 JB |
311 | static int ipw2100_fw_download(struct ipw2100_priv *priv, |
312 | struct ipw2100_fw *fw); | |
313 | static int ipw2100_get_firmware(struct ipw2100_priv *priv, | |
314 | struct ipw2100_fw *fw); | |
315 | static int ipw2100_get_fwversion(struct ipw2100_priv *priv, char *buf, | |
316 | size_t max); | |
317 | static int ipw2100_get_ucodeversion(struct ipw2100_priv *priv, char *buf, | |
318 | size_t max); | |
319 | static void ipw2100_release_firmware(struct ipw2100_priv *priv, | |
320 | struct ipw2100_fw *fw); | |
321 | static int ipw2100_ucode_download(struct ipw2100_priv *priv, | |
322 | struct ipw2100_fw *fw); | |
323 | static void ipw2100_wx_event_work(struct ipw2100_priv *priv); | |
324 | static struct iw_statistics *ipw2100_wx_wireless_stats(struct net_device * dev); | |
325 | static struct iw_handler_def ipw2100_wx_handler_def; | |
326 | ||
2c86c275 JK |
327 | |
328 | static inline void read_register(struct net_device *dev, u32 reg, u32 *val) | |
329 | { | |
330 | *val = readl((void *)(dev->base_addr + reg)); | |
331 | IPW_DEBUG_IO("r: 0x%08X => 0x%08X\n", reg, *val); | |
332 | } | |
333 | ||
334 | static inline void write_register(struct net_device *dev, u32 reg, u32 val) | |
335 | { | |
336 | writel(val, (void *)(dev->base_addr + reg)); | |
337 | IPW_DEBUG_IO("w: 0x%08X <= 0x%08X\n", reg, val); | |
338 | } | |
339 | ||
340 | static inline void read_register_word(struct net_device *dev, u32 reg, u16 *val) | |
341 | { | |
342 | *val = readw((void *)(dev->base_addr + reg)); | |
343 | IPW_DEBUG_IO("r: 0x%08X => %04X\n", reg, *val); | |
344 | } | |
345 | ||
346 | static inline void read_register_byte(struct net_device *dev, u32 reg, u8 *val) | |
347 | { | |
348 | *val = readb((void *)(dev->base_addr + reg)); | |
349 | IPW_DEBUG_IO("r: 0x%08X => %02X\n", reg, *val); | |
350 | } | |
351 | ||
352 | static inline void write_register_word(struct net_device *dev, u32 reg, u16 val) | |
353 | { | |
354 | writew(val, (void *)(dev->base_addr + reg)); | |
355 | IPW_DEBUG_IO("w: 0x%08X <= %04X\n", reg, val); | |
356 | } | |
357 | ||
358 | ||
359 | static inline void write_register_byte(struct net_device *dev, u32 reg, u8 val) | |
360 | { | |
361 | writeb(val, (void *)(dev->base_addr + reg)); | |
362 | IPW_DEBUG_IO("w: 0x%08X =< %02X\n", reg, val); | |
363 | } | |
364 | ||
365 | static inline void read_nic_dword(struct net_device *dev, u32 addr, u32 *val) | |
366 | { | |
367 | write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, | |
368 | addr & IPW_REG_INDIRECT_ADDR_MASK); | |
369 | read_register(dev, IPW_REG_INDIRECT_ACCESS_DATA, val); | |
370 | } | |
371 | ||
372 | static inline void write_nic_dword(struct net_device *dev, u32 addr, u32 val) | |
373 | { | |
374 | write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, | |
375 | addr & IPW_REG_INDIRECT_ADDR_MASK); | |
376 | write_register(dev, IPW_REG_INDIRECT_ACCESS_DATA, val); | |
377 | } | |
378 | ||
379 | static inline void read_nic_word(struct net_device *dev, u32 addr, u16 *val) | |
380 | { | |
381 | write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, | |
382 | addr & IPW_REG_INDIRECT_ADDR_MASK); | |
383 | read_register_word(dev, IPW_REG_INDIRECT_ACCESS_DATA, val); | |
384 | } | |
385 | ||
386 | static inline void write_nic_word(struct net_device *dev, u32 addr, u16 val) | |
387 | { | |
388 | write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, | |
389 | addr & IPW_REG_INDIRECT_ADDR_MASK); | |
390 | write_register_word(dev, IPW_REG_INDIRECT_ACCESS_DATA, val); | |
391 | } | |
392 | ||
393 | static inline void read_nic_byte(struct net_device *dev, u32 addr, u8 *val) | |
394 | { | |
395 | write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, | |
396 | addr & IPW_REG_INDIRECT_ADDR_MASK); | |
397 | read_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA, val); | |
398 | } | |
399 | ||
400 | static inline void write_nic_byte(struct net_device *dev, u32 addr, u8 val) | |
401 | { | |
402 | write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, | |
403 | addr & IPW_REG_INDIRECT_ADDR_MASK); | |
404 | write_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA, val); | |
405 | } | |
406 | ||
407 | static inline void write_nic_auto_inc_address(struct net_device *dev, u32 addr) | |
408 | { | |
409 | write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS, | |
410 | addr & IPW_REG_INDIRECT_ADDR_MASK); | |
411 | } | |
412 | ||
413 | static inline void write_nic_dword_auto_inc(struct net_device *dev, u32 val) | |
414 | { | |
415 | write_register(dev, IPW_REG_AUTOINCREMENT_DATA, val); | |
416 | } | |
417 | ||
418 | static inline void write_nic_memory(struct net_device *dev, u32 addr, u32 len, | |
419 | const u8 *buf) | |
420 | { | |
421 | u32 aligned_addr; | |
422 | u32 aligned_len; | |
423 | u32 dif_len; | |
424 | u32 i; | |
425 | ||
426 | /* read first nibble byte by byte */ | |
427 | aligned_addr = addr & (~0x3); | |
428 | dif_len = addr - aligned_addr; | |
429 | if (dif_len) { | |
430 | /* Start reading at aligned_addr + dif_len */ | |
431 | write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, | |
432 | aligned_addr); | |
433 | for (i = dif_len; i < 4; i++, buf++) | |
434 | write_register_byte( | |
435 | dev, IPW_REG_INDIRECT_ACCESS_DATA + i, | |
436 | *buf); | |
437 | ||
438 | len -= dif_len; | |
439 | aligned_addr += 4; | |
440 | } | |
441 | ||
442 | /* read DWs through autoincrement registers */ | |
443 | write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS, | |
444 | aligned_addr); | |
445 | aligned_len = len & (~0x3); | |
446 | for (i = 0; i < aligned_len; i += 4, buf += 4, aligned_addr += 4) | |
447 | write_register( | |
448 | dev, IPW_REG_AUTOINCREMENT_DATA, *(u32 *)buf); | |
449 | ||
450 | /* copy the last nibble */ | |
451 | dif_len = len - aligned_len; | |
452 | write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, aligned_addr); | |
453 | for (i = 0; i < dif_len; i++, buf++) | |
454 | write_register_byte( | |
455 | dev, IPW_REG_INDIRECT_ACCESS_DATA + i, *buf); | |
456 | } | |
457 | ||
458 | static inline void read_nic_memory(struct net_device *dev, u32 addr, u32 len, | |
459 | u8 *buf) | |
460 | { | |
461 | u32 aligned_addr; | |
462 | u32 aligned_len; | |
463 | u32 dif_len; | |
464 | u32 i; | |
465 | ||
466 | /* read first nibble byte by byte */ | |
467 | aligned_addr = addr & (~0x3); | |
468 | dif_len = addr - aligned_addr; | |
469 | if (dif_len) { | |
470 | /* Start reading at aligned_addr + dif_len */ | |
471 | write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, | |
472 | aligned_addr); | |
473 | for (i = dif_len; i < 4; i++, buf++) | |
474 | read_register_byte( | |
475 | dev, IPW_REG_INDIRECT_ACCESS_DATA + i, buf); | |
476 | ||
477 | len -= dif_len; | |
478 | aligned_addr += 4; | |
479 | } | |
480 | ||
481 | /* read DWs through autoincrement registers */ | |
482 | write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS, | |
483 | aligned_addr); | |
484 | aligned_len = len & (~0x3); | |
485 | for (i = 0; i < aligned_len; i += 4, buf += 4, aligned_addr += 4) | |
486 | read_register(dev, IPW_REG_AUTOINCREMENT_DATA, | |
487 | (u32 *)buf); | |
488 | ||
489 | /* copy the last nibble */ | |
490 | dif_len = len - aligned_len; | |
491 | write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, | |
492 | aligned_addr); | |
493 | for (i = 0; i < dif_len; i++, buf++) | |
494 | read_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA + | |
495 | i, buf); | |
496 | } | |
497 | ||
498 | static inline int ipw2100_hw_is_adapter_in_system(struct net_device *dev) | |
499 | { | |
500 | return (dev->base_addr && | |
501 | (readl((void *)(dev->base_addr + IPW_REG_DOA_DEBUG_AREA_START)) | |
502 | == IPW_DATA_DOA_DEBUG_VALUE)); | |
503 | } | |
504 | ||
c4aee8c2 JB |
505 | static int ipw2100_get_ordinal(struct ipw2100_priv *priv, u32 ord, |
506 | void *val, u32 *len) | |
2c86c275 JK |
507 | { |
508 | struct ipw2100_ordinals *ordinals = &priv->ordinals; | |
509 | u32 addr; | |
510 | u32 field_info; | |
511 | u16 field_len; | |
512 | u16 field_count; | |
513 | u32 total_length; | |
514 | ||
515 | if (ordinals->table1_addr == 0) { | |
797b4f76 | 516 | printk(KERN_WARNING DRV_NAME ": attempt to use fw ordinals " |
2c86c275 JK |
517 | "before they have been loaded.\n"); |
518 | return -EINVAL; | |
519 | } | |
520 | ||
521 | if (IS_ORDINAL_TABLE_ONE(ordinals, ord)) { | |
522 | if (*len < IPW_ORD_TAB_1_ENTRY_SIZE) { | |
523 | *len = IPW_ORD_TAB_1_ENTRY_SIZE; | |
524 | ||
797b4f76 | 525 | printk(KERN_WARNING DRV_NAME |
aaa4d308 | 526 | ": ordinal buffer length too small, need %zd\n", |
2c86c275 JK |
527 | IPW_ORD_TAB_1_ENTRY_SIZE); |
528 | ||
529 | return -EINVAL; | |
530 | } | |
531 | ||
532 | read_nic_dword(priv->net_dev, ordinals->table1_addr + (ord << 2), | |
533 | &addr); | |
534 | read_nic_dword(priv->net_dev, addr, val); | |
535 | ||
536 | *len = IPW_ORD_TAB_1_ENTRY_SIZE; | |
537 | ||
538 | return 0; | |
539 | } | |
540 | ||
541 | if (IS_ORDINAL_TABLE_TWO(ordinals, ord)) { | |
542 | ||
543 | ord -= IPW_START_ORD_TAB_2; | |
544 | ||
545 | /* get the address of statistic */ | |
546 | read_nic_dword(priv->net_dev, ordinals->table2_addr + (ord << 3), | |
547 | &addr); | |
548 | ||
549 | /* get the second DW of statistics ; | |
550 | * two 16-bit words - first is length, second is count */ | |
551 | read_nic_dword(priv->net_dev, | |
552 | ordinals->table2_addr + (ord << 3) + sizeof(u32), | |
553 | &field_info); | |
554 | ||
555 | /* get each entry length */ | |
556 | field_len = *((u16 *)&field_info); | |
557 | ||
558 | /* get number of entries */ | |
559 | field_count = *(((u16 *)&field_info) + 1); | |
560 | ||
561 | /* abort if no enought memory */ | |
562 | total_length = field_len * field_count; | |
563 | if (total_length > *len) { | |
564 | *len = total_length; | |
565 | return -EINVAL; | |
566 | } | |
567 | ||
568 | *len = total_length; | |
569 | if (!total_length) | |
570 | return 0; | |
571 | ||
572 | /* read the ordinal data from the SRAM */ | |
573 | read_nic_memory(priv->net_dev, addr, total_length, val); | |
574 | ||
575 | return 0; | |
576 | } | |
577 | ||
797b4f76 | 578 | printk(KERN_WARNING DRV_NAME ": ordinal %d neither in table 1 nor " |
2c86c275 JK |
579 | "in table 2\n", ord); |
580 | ||
581 | return -EINVAL; | |
582 | } | |
583 | ||
584 | static int ipw2100_set_ordinal(struct ipw2100_priv *priv, u32 ord, u32 *val, | |
585 | u32 *len) | |
586 | { | |
587 | struct ipw2100_ordinals *ordinals = &priv->ordinals; | |
588 | u32 addr; | |
589 | ||
590 | if (IS_ORDINAL_TABLE_ONE(ordinals, ord)) { | |
591 | if (*len != IPW_ORD_TAB_1_ENTRY_SIZE) { | |
592 | *len = IPW_ORD_TAB_1_ENTRY_SIZE; | |
593 | IPW_DEBUG_INFO("wrong size\n"); | |
594 | return -EINVAL; | |
595 | } | |
596 | ||
597 | read_nic_dword(priv->net_dev, ordinals->table1_addr + (ord << 2), | |
598 | &addr); | |
599 | ||
600 | write_nic_dword(priv->net_dev, addr, *val); | |
601 | ||
602 | *len = IPW_ORD_TAB_1_ENTRY_SIZE; | |
603 | ||
604 | return 0; | |
605 | } | |
606 | ||
607 | IPW_DEBUG_INFO("wrong table\n"); | |
608 | if (IS_ORDINAL_TABLE_TWO(ordinals, ord)) | |
609 | return -EINVAL; | |
610 | ||
611 | return -EINVAL; | |
612 | } | |
613 | ||
614 | static char *snprint_line(char *buf, size_t count, | |
615 | const u8 *data, u32 len, u32 ofs) | |
616 | { | |
617 | int out, i, j, l; | |
618 | char c; | |
619 | ||
620 | out = snprintf(buf, count, "%08X", ofs); | |
621 | ||
622 | for (l = 0, i = 0; i < 2; i++) { | |
623 | out += snprintf(buf + out, count - out, " "); | |
624 | for (j = 0; j < 8 && l < len; j++, l++) | |
625 | out += snprintf(buf + out, count - out, "%02X ", | |
626 | data[(i * 8 + j)]); | |
627 | for (; j < 8; j++) | |
628 | out += snprintf(buf + out, count - out, " "); | |
629 | } | |
630 | ||
631 | out += snprintf(buf + out, count - out, " "); | |
632 | for (l = 0, i = 0; i < 2; i++) { | |
633 | out += snprintf(buf + out, count - out, " "); | |
634 | for (j = 0; j < 8 && l < len; j++, l++) { | |
635 | c = data[(i * 8 + j)]; | |
636 | if (!isascii(c) || !isprint(c)) | |
637 | c = '.'; | |
638 | ||
639 | out += snprintf(buf + out, count - out, "%c", c); | |
640 | } | |
641 | ||
642 | for (; j < 8; j++) | |
643 | out += snprintf(buf + out, count - out, " "); | |
644 | } | |
645 | ||
646 | return buf; | |
647 | } | |
648 | ||
649 | static void printk_buf(int level, const u8 *data, u32 len) | |
650 | { | |
651 | char line[81]; | |
652 | u32 ofs = 0; | |
653 | if (!(ipw2100_debug_level & level)) | |
654 | return; | |
655 | ||
656 | while (len) { | |
657 | printk(KERN_DEBUG "%s\n", | |
658 | snprint_line(line, sizeof(line), &data[ofs], | |
659 | min(len, 16U), ofs)); | |
660 | ofs += 16; | |
661 | len -= min(len, 16U); | |
662 | } | |
663 | } | |
664 | ||
665 | ||
666 | ||
667 | #define MAX_RESET_BACKOFF 10 | |
668 | ||
669 | static inline void schedule_reset(struct ipw2100_priv *priv) | |
670 | { | |
671 | unsigned long now = get_seconds(); | |
672 | ||
673 | /* If we haven't received a reset request within the backoff period, | |
674 | * then we can reset the backoff interval so this reset occurs | |
675 | * immediately */ | |
676 | if (priv->reset_backoff && | |
677 | (now - priv->last_reset > priv->reset_backoff)) | |
678 | priv->reset_backoff = 0; | |
679 | ||
680 | priv->last_reset = get_seconds(); | |
681 | ||
682 | if (!(priv->status & STATUS_RESET_PENDING)) { | |
683 | IPW_DEBUG_INFO("%s: Scheduling firmware restart (%ds).\n", | |
684 | priv->net_dev->name, priv->reset_backoff); | |
685 | netif_carrier_off(priv->net_dev); | |
686 | netif_stop_queue(priv->net_dev); | |
687 | priv->status |= STATUS_RESET_PENDING; | |
688 | if (priv->reset_backoff) | |
689 | queue_delayed_work(priv->workqueue, &priv->reset_work, | |
690 | priv->reset_backoff * HZ); | |
691 | else | |
692 | queue_work(priv->workqueue, &priv->reset_work); | |
693 | ||
694 | if (priv->reset_backoff < MAX_RESET_BACKOFF) | |
695 | priv->reset_backoff++; | |
696 | ||
697 | wake_up_interruptible(&priv->wait_command_queue); | |
698 | } else | |
699 | IPW_DEBUG_INFO("%s: Firmware restart already in progress.\n", | |
700 | priv->net_dev->name); | |
701 | ||
702 | } | |
703 | ||
704 | #define HOST_COMPLETE_TIMEOUT (2 * HZ) | |
705 | static int ipw2100_hw_send_command(struct ipw2100_priv *priv, | |
706 | struct host_command * cmd) | |
707 | { | |
708 | struct list_head *element; | |
709 | struct ipw2100_tx_packet *packet; | |
710 | unsigned long flags; | |
711 | int err = 0; | |
712 | ||
713 | IPW_DEBUG_HC("Sending %s command (#%d), %d bytes\n", | |
714 | command_types[cmd->host_command], cmd->host_command, | |
715 | cmd->host_command_length); | |
716 | printk_buf(IPW_DL_HC, (u8*)cmd->host_command_parameters, | |
717 | cmd->host_command_length); | |
718 | ||
719 | spin_lock_irqsave(&priv->low_lock, flags); | |
720 | ||
721 | if (priv->fatal_error) { | |
722 | IPW_DEBUG_INFO("Attempt to send command while hardware in fatal error condition.\n"); | |
723 | err = -EIO; | |
724 | goto fail_unlock; | |
725 | } | |
726 | ||
727 | if (!(priv->status & STATUS_RUNNING)) { | |
728 | IPW_DEBUG_INFO("Attempt to send command while hardware is not running.\n"); | |
729 | err = -EIO; | |
730 | goto fail_unlock; | |
731 | } | |
732 | ||
733 | if (priv->status & STATUS_CMD_ACTIVE) { | |
734 | IPW_DEBUG_INFO("Attempt to send command while another command is pending.\n"); | |
735 | err = -EBUSY; | |
736 | goto fail_unlock; | |
737 | } | |
738 | ||
739 | if (list_empty(&priv->msg_free_list)) { | |
740 | IPW_DEBUG_INFO("no available msg buffers\n"); | |
741 | goto fail_unlock; | |
742 | } | |
743 | ||
744 | priv->status |= STATUS_CMD_ACTIVE; | |
745 | priv->messages_sent++; | |
746 | ||
747 | element = priv->msg_free_list.next; | |
748 | ||
749 | packet = list_entry(element, struct ipw2100_tx_packet, list); | |
750 | packet->jiffy_start = jiffies; | |
751 | ||
752 | /* initialize the firmware command packet */ | |
753 | packet->info.c_struct.cmd->host_command_reg = cmd->host_command; | |
754 | packet->info.c_struct.cmd->host_command_reg1 = cmd->host_command1; | |
755 | packet->info.c_struct.cmd->host_command_len_reg = cmd->host_command_length; | |
756 | packet->info.c_struct.cmd->sequence = cmd->host_command_sequence; | |
757 | ||
758 | memcpy(packet->info.c_struct.cmd->host_command_params_reg, | |
759 | cmd->host_command_parameters, | |
760 | sizeof(packet->info.c_struct.cmd->host_command_params_reg)); | |
761 | ||
762 | list_del(element); | |
763 | DEC_STAT(&priv->msg_free_stat); | |
764 | ||
765 | list_add_tail(element, &priv->msg_pend_list); | |
766 | INC_STAT(&priv->msg_pend_stat); | |
767 | ||
19f7f742 JB |
768 | ipw2100_tx_send_commands(priv); |
769 | ipw2100_tx_send_data(priv); | |
2c86c275 JK |
770 | |
771 | spin_unlock_irqrestore(&priv->low_lock, flags); | |
772 | ||
773 | /* | |
774 | * We must wait for this command to complete before another | |
775 | * command can be sent... but if we wait more than 3 seconds | |
776 | * then there is a problem. | |
777 | */ | |
778 | ||
779 | err = wait_event_interruptible_timeout( | |
780 | priv->wait_command_queue, !(priv->status & STATUS_CMD_ACTIVE), | |
781 | HOST_COMPLETE_TIMEOUT); | |
782 | ||
783 | if (err == 0) { | |
784 | IPW_DEBUG_INFO("Command completion failed out after %dms.\n", | |
785 | HOST_COMPLETE_TIMEOUT / (HZ / 100)); | |
786 | priv->fatal_error = IPW2100_ERR_MSG_TIMEOUT; | |
787 | priv->status &= ~STATUS_CMD_ACTIVE; | |
788 | schedule_reset(priv); | |
789 | return -EIO; | |
790 | } | |
791 | ||
792 | if (priv->fatal_error) { | |
797b4f76 | 793 | printk(KERN_WARNING DRV_NAME ": %s: firmware fatal error\n", |
2c86c275 JK |
794 | priv->net_dev->name); |
795 | return -EIO; | |
796 | } | |
797 | ||
798 | /* !!!!! HACK TEST !!!!! | |
799 | * When lots of debug trace statements are enabled, the driver | |
800 | * doesn't seem to have as many firmware restart cycles... | |
801 | * | |
802 | * As a test, we're sticking in a 1/100s delay here */ | |
803 | set_current_state(TASK_UNINTERRUPTIBLE); | |
804 | schedule_timeout(HZ / 100); | |
805 | ||
806 | return 0; | |
807 | ||
808 | fail_unlock: | |
809 | spin_unlock_irqrestore(&priv->low_lock, flags); | |
810 | ||
811 | return err; | |
812 | } | |
813 | ||
814 | ||
815 | /* | |
816 | * Verify the values and data access of the hardware | |
817 | * No locks needed or used. No functions called. | |
818 | */ | |
819 | static int ipw2100_verify(struct ipw2100_priv *priv) | |
820 | { | |
821 | u32 data1, data2; | |
822 | u32 address; | |
823 | ||
824 | u32 val1 = 0x76543210; | |
825 | u32 val2 = 0xFEDCBA98; | |
826 | ||
827 | /* Domain 0 check - all values should be DOA_DEBUG */ | |
828 | for (address = IPW_REG_DOA_DEBUG_AREA_START; | |
829 | address < IPW_REG_DOA_DEBUG_AREA_END; | |
830 | address += sizeof(u32)) { | |
831 | read_register(priv->net_dev, address, &data1); | |
832 | if (data1 != IPW_DATA_DOA_DEBUG_VALUE) | |
833 | return -EIO; | |
834 | } | |
835 | ||
836 | /* Domain 1 check - use arbitrary read/write compare */ | |
837 | for (address = 0; address < 5; address++) { | |
838 | /* The memory area is not used now */ | |
839 | write_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x32, | |
840 | val1); | |
841 | write_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x36, | |
842 | val2); | |
843 | read_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x32, | |
844 | &data1); | |
845 | read_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x36, | |
846 | &data2); | |
847 | if (val1 == data1 && val2 == data2) | |
848 | return 0; | |
849 | } | |
850 | ||
851 | return -EIO; | |
852 | } | |
853 | ||
854 | /* | |
855 | * | |
856 | * Loop until the CARD_DISABLED bit is the same value as the | |
857 | * supplied parameter | |
858 | * | |
859 | * TODO: See if it would be more efficient to do a wait/wake | |
860 | * cycle and have the completion event trigger the wakeup | |
861 | * | |
862 | */ | |
863 | #define IPW_CARD_DISABLE_COMPLETE_WAIT 100 // 100 milli | |
864 | static int ipw2100_wait_for_card_state(struct ipw2100_priv *priv, int state) | |
865 | { | |
866 | int i; | |
867 | u32 card_state; | |
868 | u32 len = sizeof(card_state); | |
869 | int err; | |
870 | ||
871 | for (i = 0; i <= IPW_CARD_DISABLE_COMPLETE_WAIT * 1000; i += 50) { | |
872 | err = ipw2100_get_ordinal(priv, IPW_ORD_CARD_DISABLED, | |
873 | &card_state, &len); | |
874 | if (err) { | |
875 | IPW_DEBUG_INFO("Query of CARD_DISABLED ordinal " | |
876 | "failed.\n"); | |
877 | return 0; | |
878 | } | |
879 | ||
880 | /* We'll break out if either the HW state says it is | |
881 | * in the state we want, or if HOST_COMPLETE command | |
882 | * finishes */ | |
883 | if ((card_state == state) || | |
884 | ((priv->status & STATUS_ENABLED) ? | |
885 | IPW_HW_STATE_ENABLED : IPW_HW_STATE_DISABLED) == state) { | |
886 | if (state == IPW_HW_STATE_ENABLED) | |
887 | priv->status |= STATUS_ENABLED; | |
888 | else | |
889 | priv->status &= ~STATUS_ENABLED; | |
890 | ||
891 | return 0; | |
892 | } | |
893 | ||
894 | udelay(50); | |
895 | } | |
896 | ||
897 | IPW_DEBUG_INFO("ipw2100_wait_for_card_state to %s state timed out\n", | |
898 | state ? "DISABLED" : "ENABLED"); | |
899 | return -EIO; | |
900 | } | |
901 | ||
902 | ||
903 | /********************************************************************* | |
904 | Procedure : sw_reset_and_clock | |
905 | Purpose : Asserts s/w reset, asserts clock initialization | |
906 | and waits for clock stabilization | |
907 | ********************************************************************/ | |
908 | static int sw_reset_and_clock(struct ipw2100_priv *priv) | |
909 | { | |
910 | int i; | |
911 | u32 r; | |
912 | ||
913 | // assert s/w reset | |
914 | write_register(priv->net_dev, IPW_REG_RESET_REG, | |
915 | IPW_AUX_HOST_RESET_REG_SW_RESET); | |
916 | ||
917 | // wait for clock stabilization | |
918 | for (i = 0; i < 1000; i++) { | |
919 | udelay(IPW_WAIT_RESET_ARC_COMPLETE_DELAY); | |
920 | ||
921 | // check clock ready bit | |
922 | read_register(priv->net_dev, IPW_REG_RESET_REG, &r); | |
923 | if (r & IPW_AUX_HOST_RESET_REG_PRINCETON_RESET) | |
924 | break; | |
925 | } | |
926 | ||
927 | if (i == 1000) | |
928 | return -EIO; // TODO: better error value | |
929 | ||
930 | /* set "initialization complete" bit to move adapter to | |
931 | * D0 state */ | |
932 | write_register(priv->net_dev, IPW_REG_GP_CNTRL, | |
933 | IPW_AUX_HOST_GP_CNTRL_BIT_INIT_DONE); | |
934 | ||
935 | /* wait for clock stabilization */ | |
936 | for (i = 0; i < 10000; i++) { | |
937 | udelay(IPW_WAIT_CLOCK_STABILIZATION_DELAY * 4); | |
938 | ||
939 | /* check clock ready bit */ | |
940 | read_register(priv->net_dev, IPW_REG_GP_CNTRL, &r); | |
941 | if (r & IPW_AUX_HOST_GP_CNTRL_BIT_CLOCK_READY) | |
942 | break; | |
943 | } | |
944 | ||
945 | if (i == 10000) | |
946 | return -EIO; /* TODO: better error value */ | |
947 | ||
2c86c275 JK |
948 | /* set D0 standby bit */ |
949 | read_register(priv->net_dev, IPW_REG_GP_CNTRL, &r); | |
950 | write_register(priv->net_dev, IPW_REG_GP_CNTRL, | |
951 | r | IPW_AUX_HOST_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY); | |
2c86c275 JK |
952 | |
953 | return 0; | |
954 | } | |
955 | ||
956 | /********************************************************************* | |
8724a118 | 957 | Procedure : ipw2100_download_firmware |
2c86c275 JK |
958 | Purpose : Initiaze adapter after power on. |
959 | The sequence is: | |
960 | 1. assert s/w reset first! | |
961 | 2. awake clocks & wait for clock stabilization | |
962 | 3. hold ARC (don't ask me why...) | |
963 | 4. load Dino ucode and reset/clock init again | |
964 | 5. zero-out shared mem | |
965 | 6. download f/w | |
966 | *******************************************************************/ | |
967 | static int ipw2100_download_firmware(struct ipw2100_priv *priv) | |
968 | { | |
969 | u32 address; | |
970 | int err; | |
971 | ||
972 | #ifndef CONFIG_PM | |
973 | /* Fetch the firmware and microcode */ | |
974 | struct ipw2100_fw ipw2100_firmware; | |
975 | #endif | |
976 | ||
977 | if (priv->fatal_error) { | |
978 | IPW_DEBUG_ERROR("%s: ipw2100_download_firmware called after " | |
979 | "fatal error %d. Interface must be brought down.\n", | |
980 | priv->net_dev->name, priv->fatal_error); | |
981 | return -EINVAL; | |
982 | } | |
983 | ||
984 | #ifdef CONFIG_PM | |
985 | if (!ipw2100_firmware.version) { | |
986 | err = ipw2100_get_firmware(priv, &ipw2100_firmware); | |
987 | if (err) { | |
988 | IPW_DEBUG_ERROR("%s: ipw2100_get_firmware failed: %d\n", | |
989 | priv->net_dev->name, err); | |
990 | priv->fatal_error = IPW2100_ERR_FW_LOAD; | |
991 | goto fail; | |
992 | } | |
993 | } | |
994 | #else | |
995 | err = ipw2100_get_firmware(priv, &ipw2100_firmware); | |
996 | if (err) { | |
997 | IPW_DEBUG_ERROR("%s: ipw2100_get_firmware failed: %d\n", | |
998 | priv->net_dev->name, err); | |
999 | priv->fatal_error = IPW2100_ERR_FW_LOAD; | |
1000 | goto fail; | |
1001 | } | |
1002 | #endif | |
1003 | priv->firmware_version = ipw2100_firmware.version; | |
1004 | ||
1005 | /* s/w reset and clock stabilization */ | |
1006 | err = sw_reset_and_clock(priv); | |
1007 | if (err) { | |
1008 | IPW_DEBUG_ERROR("%s: sw_reset_and_clock failed: %d\n", | |
1009 | priv->net_dev->name, err); | |
1010 | goto fail; | |
1011 | } | |
1012 | ||
1013 | err = ipw2100_verify(priv); | |
1014 | if (err) { | |
1015 | IPW_DEBUG_ERROR("%s: ipw2100_verify failed: %d\n", | |
1016 | priv->net_dev->name, err); | |
1017 | goto fail; | |
1018 | } | |
1019 | ||
1020 | /* Hold ARC */ | |
1021 | write_nic_dword(priv->net_dev, | |
1022 | IPW_INTERNAL_REGISTER_HALT_AND_RESET, | |
1023 | 0x80000000); | |
1024 | ||
1025 | /* allow ARC to run */ | |
1026 | write_register(priv->net_dev, IPW_REG_RESET_REG, 0); | |
1027 | ||
1028 | /* load microcode */ | |
1029 | err = ipw2100_ucode_download(priv, &ipw2100_firmware); | |
1030 | if (err) { | |
797b4f76 | 1031 | printk(KERN_ERR DRV_NAME ": %s: Error loading microcode: %d\n", |
2c86c275 JK |
1032 | priv->net_dev->name, err); |
1033 | goto fail; | |
1034 | } | |
1035 | ||
1036 | /* release ARC */ | |
1037 | write_nic_dword(priv->net_dev, | |
1038 | IPW_INTERNAL_REGISTER_HALT_AND_RESET, | |
1039 | 0x00000000); | |
1040 | ||
1041 | /* s/w reset and clock stabilization (again!!!) */ | |
1042 | err = sw_reset_and_clock(priv); | |
1043 | if (err) { | |
797b4f76 | 1044 | printk(KERN_ERR DRV_NAME ": %s: sw_reset_and_clock failed: %d\n", |
2c86c275 JK |
1045 | priv->net_dev->name, err); |
1046 | goto fail; | |
1047 | } | |
1048 | ||
1049 | /* load f/w */ | |
1050 | err = ipw2100_fw_download(priv, &ipw2100_firmware); | |
1051 | if (err) { | |
1052 | IPW_DEBUG_ERROR("%s: Error loading firmware: %d\n", | |
1053 | priv->net_dev->name, err); | |
1054 | goto fail; | |
1055 | } | |
1056 | ||
1057 | #ifndef CONFIG_PM | |
1058 | /* | |
1059 | * When the .resume method of the driver is called, the other | |
1060 | * part of the system, i.e. the ide driver could still stay in | |
1061 | * the suspend stage. This prevents us from loading the firmware | |
1062 | * from the disk. --YZ | |
1063 | */ | |
1064 | ||
1065 | /* free any storage allocated for firmware image */ | |
1066 | ipw2100_release_firmware(priv, &ipw2100_firmware); | |
1067 | #endif | |
1068 | ||
1069 | /* zero out Domain 1 area indirectly (Si requirement) */ | |
1070 | for (address = IPW_HOST_FW_SHARED_AREA0; | |
1071 | address < IPW_HOST_FW_SHARED_AREA0_END; address += 4) | |
1072 | write_nic_dword(priv->net_dev, address, 0); | |
1073 | for (address = IPW_HOST_FW_SHARED_AREA1; | |
1074 | address < IPW_HOST_FW_SHARED_AREA1_END; address += 4) | |
1075 | write_nic_dword(priv->net_dev, address, 0); | |
1076 | for (address = IPW_HOST_FW_SHARED_AREA2; | |
1077 | address < IPW_HOST_FW_SHARED_AREA2_END; address += 4) | |
1078 | write_nic_dword(priv->net_dev, address, 0); | |
1079 | for (address = IPW_HOST_FW_SHARED_AREA3; | |
1080 | address < IPW_HOST_FW_SHARED_AREA3_END; address += 4) | |
1081 | write_nic_dword(priv->net_dev, address, 0); | |
1082 | for (address = IPW_HOST_FW_INTERRUPT_AREA; | |
1083 | address < IPW_HOST_FW_INTERRUPT_AREA_END; address += 4) | |
1084 | write_nic_dword(priv->net_dev, address, 0); | |
1085 | ||
1086 | return 0; | |
1087 | ||
1088 | fail: | |
1089 | ipw2100_release_firmware(priv, &ipw2100_firmware); | |
1090 | return err; | |
1091 | } | |
1092 | ||
1093 | static inline void ipw2100_enable_interrupts(struct ipw2100_priv *priv) | |
1094 | { | |
1095 | if (priv->status & STATUS_INT_ENABLED) | |
1096 | return; | |
1097 | priv->status |= STATUS_INT_ENABLED; | |
1098 | write_register(priv->net_dev, IPW_REG_INTA_MASK, IPW_INTERRUPT_MASK); | |
1099 | } | |
1100 | ||
1101 | static inline void ipw2100_disable_interrupts(struct ipw2100_priv *priv) | |
1102 | { | |
1103 | if (!(priv->status & STATUS_INT_ENABLED)) | |
1104 | return; | |
1105 | priv->status &= ~STATUS_INT_ENABLED; | |
1106 | write_register(priv->net_dev, IPW_REG_INTA_MASK, 0x0); | |
1107 | } | |
1108 | ||
1109 | ||
1110 | static void ipw2100_initialize_ordinals(struct ipw2100_priv *priv) | |
1111 | { | |
1112 | struct ipw2100_ordinals *ord = &priv->ordinals; | |
1113 | ||
1114 | IPW_DEBUG_INFO("enter\n"); | |
1115 | ||
1116 | read_register(priv->net_dev, IPW_MEM_HOST_SHARED_ORDINALS_TABLE_1, | |
1117 | &ord->table1_addr); | |
1118 | ||
1119 | read_register(priv->net_dev, IPW_MEM_HOST_SHARED_ORDINALS_TABLE_2, | |
1120 | &ord->table2_addr); | |
1121 | ||
1122 | read_nic_dword(priv->net_dev, ord->table1_addr, &ord->table1_size); | |
1123 | read_nic_dword(priv->net_dev, ord->table2_addr, &ord->table2_size); | |
1124 | ||
1125 | ord->table2_size &= 0x0000FFFF; | |
1126 | ||
1127 | IPW_DEBUG_INFO("table 1 size: %d\n", ord->table1_size); | |
1128 | IPW_DEBUG_INFO("table 2 size: %d\n", ord->table2_size); | |
1129 | IPW_DEBUG_INFO("exit\n"); | |
1130 | } | |
1131 | ||
1132 | static inline void ipw2100_hw_set_gpio(struct ipw2100_priv *priv) | |
1133 | { | |
1134 | u32 reg = 0; | |
1135 | /* | |
1136 | * Set GPIO 3 writable by FW; GPIO 1 writable | |
1137 | * by driver and enable clock | |
1138 | */ | |
1139 | reg = (IPW_BIT_GPIO_GPIO3_MASK | IPW_BIT_GPIO_GPIO1_ENABLE | | |
1140 | IPW_BIT_GPIO_LED_OFF); | |
1141 | write_register(priv->net_dev, IPW_REG_GPIO, reg); | |
1142 | } | |
1143 | ||
1144 | static inline int rf_kill_active(struct ipw2100_priv *priv) | |
1145 | { | |
1146 | #define MAX_RF_KILL_CHECKS 5 | |
1147 | #define RF_KILL_CHECK_DELAY 40 | |
2c86c275 JK |
1148 | |
1149 | unsigned short value = 0; | |
1150 | u32 reg = 0; | |
1151 | int i; | |
1152 | ||
1153 | if (!(priv->hw_features & HW_FEATURE_RFKILL)) { | |
1154 | priv->status &= ~STATUS_RF_KILL_HW; | |
1155 | return 0; | |
1156 | } | |
1157 | ||
1158 | for (i = 0; i < MAX_RF_KILL_CHECKS; i++) { | |
1159 | udelay(RF_KILL_CHECK_DELAY); | |
1160 | read_register(priv->net_dev, IPW_REG_GPIO, ®); | |
1161 | value = (value << 1) | ((reg & IPW_BIT_GPIO_RF_KILL) ? 0 : 1); | |
1162 | } | |
1163 | ||
1164 | if (value == 0) | |
1165 | priv->status |= STATUS_RF_KILL_HW; | |
1166 | else | |
1167 | priv->status &= ~STATUS_RF_KILL_HW; | |
1168 | ||
1169 | return (value == 0); | |
1170 | } | |
1171 | ||
1172 | static int ipw2100_get_hw_features(struct ipw2100_priv *priv) | |
1173 | { | |
1174 | u32 addr, len; | |
1175 | u32 val; | |
1176 | ||
1177 | /* | |
1178 | * EEPROM_SRAM_DB_START_ADDRESS using ordinal in ordinal table 1 | |
1179 | */ | |
1180 | len = sizeof(addr); | |
1181 | if (ipw2100_get_ordinal( | |
1182 | priv, IPW_ORD_EEPROM_SRAM_DB_BLOCK_START_ADDRESS, | |
1183 | &addr, &len)) { | |
1184 | IPW_DEBUG_INFO("failed querying ordinals at line %d\n", | |
1185 | __LINE__); | |
1186 | return -EIO; | |
1187 | } | |
1188 | ||
1189 | IPW_DEBUG_INFO("EEPROM address: %08X\n", addr); | |
1190 | ||
1191 | /* | |
1192 | * EEPROM version is the byte at offset 0xfd in firmware | |
1193 | * We read 4 bytes, then shift out the byte we actually want */ | |
1194 | read_nic_dword(priv->net_dev, addr + 0xFC, &val); | |
1195 | priv->eeprom_version = (val >> 24) & 0xFF; | |
1196 | IPW_DEBUG_INFO("EEPROM version: %d\n", priv->eeprom_version); | |
1197 | ||
1198 | /* | |
1199 | * HW RF Kill enable is bit 0 in byte at offset 0x21 in firmware | |
1200 | * | |
1201 | * notice that the EEPROM bit is reverse polarity, i.e. | |
1202 | * bit = 0 signifies HW RF kill switch is supported | |
1203 | * bit = 1 signifies HW RF kill switch is NOT supported | |
1204 | */ | |
1205 | read_nic_dword(priv->net_dev, addr + 0x20, &val); | |
1206 | if (!((val >> 24) & 0x01)) | |
1207 | priv->hw_features |= HW_FEATURE_RFKILL; | |
1208 | ||
1209 | IPW_DEBUG_INFO("HW RF Kill: %ssupported.\n", | |
1210 | (priv->hw_features & HW_FEATURE_RFKILL) ? | |
1211 | "" : "not "); | |
1212 | ||
1213 | return 0; | |
1214 | } | |
1215 | ||
1216 | /* | |
1217 | * Start firmware execution after power on and intialization | |
1218 | * The sequence is: | |
1219 | * 1. Release ARC | |
1220 | * 2. Wait for f/w initialization completes; | |
1221 | */ | |
1222 | static int ipw2100_start_adapter(struct ipw2100_priv *priv) | |
1223 | { | |
2c86c275 JK |
1224 | int i; |
1225 | u32 inta, inta_mask, gpio; | |
1226 | ||
1227 | IPW_DEBUG_INFO("enter\n"); | |
1228 | ||
1229 | if (priv->status & STATUS_RUNNING) | |
1230 | return 0; | |
1231 | ||
1232 | /* | |
1233 | * Initialize the hw - drive adapter to DO state by setting | |
1234 | * init_done bit. Wait for clk_ready bit and Download | |
1235 | * fw & dino ucode | |
1236 | */ | |
1237 | if (ipw2100_download_firmware(priv)) { | |
797b4f76 | 1238 | printk(KERN_ERR DRV_NAME ": %s: Failed to power on the adapter.\n", |
2c86c275 JK |
1239 | priv->net_dev->name); |
1240 | return -EIO; | |
1241 | } | |
1242 | ||
1243 | /* Clear the Tx, Rx and Msg queues and the r/w indexes | |
1244 | * in the firmware RBD and TBD ring queue */ | |
1245 | ipw2100_queues_initialize(priv); | |
1246 | ||
1247 | ipw2100_hw_set_gpio(priv); | |
1248 | ||
1249 | /* TODO -- Look at disabling interrupts here to make sure none | |
1250 | * get fired during FW initialization */ | |
1251 | ||
1252 | /* Release ARC - clear reset bit */ | |
1253 | write_register(priv->net_dev, IPW_REG_RESET_REG, 0); | |
1254 | ||
1255 | /* wait for f/w intialization complete */ | |
1256 | IPW_DEBUG_FW("Waiting for f/w initialization to complete...\n"); | |
1257 | i = 5000; | |
1258 | do { | |
1259 | set_current_state(TASK_UNINTERRUPTIBLE); | |
8724a118 | 1260 | schedule_timeout(40 * HZ / 1000); |
2c86c275 JK |
1261 | /* Todo... wait for sync command ... */ |
1262 | ||
1263 | read_register(priv->net_dev, IPW_REG_INTA, &inta); | |
1264 | ||
1265 | /* check "init done" bit */ | |
1266 | if (inta & IPW2100_INTA_FW_INIT_DONE) { | |
1267 | /* reset "init done" bit */ | |
1268 | write_register(priv->net_dev, IPW_REG_INTA, | |
1269 | IPW2100_INTA_FW_INIT_DONE); | |
1270 | break; | |
1271 | } | |
1272 | ||
1273 | /* check error conditions : we check these after the firmware | |
1274 | * check so that if there is an error, the interrupt handler | |
1275 | * will see it and the adapter will be reset */ | |
1276 | if (inta & | |
1277 | (IPW2100_INTA_FATAL_ERROR | IPW2100_INTA_PARITY_ERROR)) { | |
1278 | /* clear error conditions */ | |
1279 | write_register(priv->net_dev, IPW_REG_INTA, | |
1280 | IPW2100_INTA_FATAL_ERROR | | |
1281 | IPW2100_INTA_PARITY_ERROR); | |
1282 | } | |
1283 | } while (i--); | |
1284 | ||
1285 | /* Clear out any pending INTAs since we aren't supposed to have | |
1286 | * interrupts enabled at this point... */ | |
1287 | read_register(priv->net_dev, IPW_REG_INTA, &inta); | |
1288 | read_register(priv->net_dev, IPW_REG_INTA_MASK, &inta_mask); | |
1289 | inta &= IPW_INTERRUPT_MASK; | |
1290 | /* Clear out any pending interrupts */ | |
1291 | if (inta & inta_mask) | |
1292 | write_register(priv->net_dev, IPW_REG_INTA, inta); | |
1293 | ||
1294 | IPW_DEBUG_FW("f/w initialization complete: %s\n", | |
1295 | i ? "SUCCESS" : "FAILED"); | |
1296 | ||
1297 | if (!i) { | |
797b4f76 | 1298 | printk(KERN_WARNING DRV_NAME ": %s: Firmware did not initialize.\n", |
2c86c275 JK |
1299 | priv->net_dev->name); |
1300 | return -EIO; | |
1301 | } | |
1302 | ||
1303 | /* allow firmware to write to GPIO1 & GPIO3 */ | |
1304 | read_register(priv->net_dev, IPW_REG_GPIO, &gpio); | |
1305 | ||
1306 | gpio |= (IPW_BIT_GPIO_GPIO1_MASK | IPW_BIT_GPIO_GPIO3_MASK); | |
1307 | ||
1308 | write_register(priv->net_dev, IPW_REG_GPIO, gpio); | |
1309 | ||
1310 | /* Ready to receive commands */ | |
1311 | priv->status |= STATUS_RUNNING; | |
1312 | ||
1313 | /* The adapter has been reset; we are not associated */ | |
1314 | priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED); | |
1315 | ||
1316 | IPW_DEBUG_INFO("exit\n"); | |
1317 | ||
1318 | return 0; | |
1319 | } | |
1320 | ||
1321 | static inline void ipw2100_reset_fatalerror(struct ipw2100_priv *priv) | |
1322 | { | |
1323 | if (!priv->fatal_error) | |
1324 | return; | |
1325 | ||
1326 | priv->fatal_errors[priv->fatal_index++] = priv->fatal_error; | |
1327 | priv->fatal_index %= IPW2100_ERROR_QUEUE; | |
1328 | priv->fatal_error = 0; | |
1329 | } | |
1330 | ||
1331 | ||
1332 | /* NOTE: Our interrupt is disabled when this method is called */ | |
1333 | static int ipw2100_power_cycle_adapter(struct ipw2100_priv *priv) | |
1334 | { | |
1335 | u32 reg; | |
1336 | int i; | |
1337 | ||
1338 | IPW_DEBUG_INFO("Power cycling the hardware.\n"); | |
1339 | ||
1340 | ipw2100_hw_set_gpio(priv); | |
1341 | ||
1342 | /* Step 1. Stop Master Assert */ | |
1343 | write_register(priv->net_dev, IPW_REG_RESET_REG, | |
1344 | IPW_AUX_HOST_RESET_REG_STOP_MASTER); | |
1345 | ||
1346 | /* Step 2. Wait for stop Master Assert | |
1347 | * (not more then 50us, otherwise ret error */ | |
1348 | i = 5; | |
1349 | do { | |
1350 | udelay(IPW_WAIT_RESET_MASTER_ASSERT_COMPLETE_DELAY); | |
1351 | read_register(priv->net_dev, IPW_REG_RESET_REG, ®); | |
1352 | ||
1353 | if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED) | |
1354 | break; | |
1355 | } while(i--); | |
1356 | ||
1357 | priv->status &= ~STATUS_RESET_PENDING; | |
1358 | ||
1359 | if (!i) { | |
1360 | IPW_DEBUG_INFO("exit - waited too long for master assert stop\n"); | |
1361 | return -EIO; | |
1362 | } | |
1363 | ||
1364 | write_register(priv->net_dev, IPW_REG_RESET_REG, | |
1365 | IPW_AUX_HOST_RESET_REG_SW_RESET); | |
1366 | ||
1367 | ||
1368 | /* Reset any fatal_error conditions */ | |
1369 | ipw2100_reset_fatalerror(priv); | |
1370 | ||
1371 | /* At this point, the adapter is now stopped and disabled */ | |
1372 | priv->status &= ~(STATUS_RUNNING | STATUS_ASSOCIATING | | |
1373 | STATUS_ASSOCIATED | STATUS_ENABLED); | |
1374 | ||
1375 | return 0; | |
1376 | } | |
1377 | ||
1378 | /* | |
1379 | * Send the CARD_DISABLE_PHY_OFF comamnd to the card to disable it | |
1380 | * | |
1381 | * After disabling, if the card was associated, a STATUS_ASSN_LOST will be sent. | |
1382 | * | |
1383 | * STATUS_CARD_DISABLE_NOTIFICATION will be sent regardless of | |
1384 | * if STATUS_ASSN_LOST is sent. | |
1385 | */ | |
1386 | static int ipw2100_hw_phy_off(struct ipw2100_priv *priv) | |
1387 | { | |
1388 | ||
1389 | #define HW_PHY_OFF_LOOP_DELAY (HZ / 5000) | |
1390 | ||
1391 | struct host_command cmd = { | |
1392 | .host_command = CARD_DISABLE_PHY_OFF, | |
1393 | .host_command_sequence = 0, | |
1394 | .host_command_length = 0, | |
1395 | }; | |
1396 | int err, i; | |
1397 | u32 val1, val2; | |
1398 | ||
1399 | IPW_DEBUG_HC("CARD_DISABLE_PHY_OFF\n"); | |
1400 | ||
1401 | /* Turn off the radio */ | |
1402 | err = ipw2100_hw_send_command(priv, &cmd); | |
1403 | if (err) | |
1404 | return err; | |
1405 | ||
1406 | for (i = 0; i < 2500; i++) { | |
1407 | read_nic_dword(priv->net_dev, IPW2100_CONTROL_REG, &val1); | |
1408 | read_nic_dword(priv->net_dev, IPW2100_COMMAND, &val2); | |
1409 | ||
1410 | if ((val1 & IPW2100_CONTROL_PHY_OFF) && | |
1411 | (val2 & IPW2100_COMMAND_PHY_OFF)) | |
1412 | return 0; | |
1413 | ||
1414 | set_current_state(TASK_UNINTERRUPTIBLE); | |
1415 | schedule_timeout(HW_PHY_OFF_LOOP_DELAY); | |
1416 | } | |
1417 | ||
1418 | return -EIO; | |
1419 | } | |
1420 | ||
1421 | ||
1422 | static int ipw2100_enable_adapter(struct ipw2100_priv *priv) | |
1423 | { | |
1424 | struct host_command cmd = { | |
1425 | .host_command = HOST_COMPLETE, | |
1426 | .host_command_sequence = 0, | |
1427 | .host_command_length = 0 | |
1428 | }; | |
1429 | int err = 0; | |
1430 | ||
1431 | IPW_DEBUG_HC("HOST_COMPLETE\n"); | |
1432 | ||
1433 | if (priv->status & STATUS_ENABLED) | |
1434 | return 0; | |
1435 | ||
1436 | down(&priv->adapter_sem); | |
1437 | ||
1438 | if (rf_kill_active(priv)) { | |
1439 | IPW_DEBUG_HC("Command aborted due to RF kill active.\n"); | |
1440 | goto fail_up; | |
1441 | } | |
1442 | ||
1443 | err = ipw2100_hw_send_command(priv, &cmd); | |
1444 | if (err) { | |
1445 | IPW_DEBUG_INFO("Failed to send HOST_COMPLETE command\n"); | |
1446 | goto fail_up; | |
1447 | } | |
1448 | ||
1449 | err = ipw2100_wait_for_card_state(priv, IPW_HW_STATE_ENABLED); | |
1450 | if (err) { | |
1451 | IPW_DEBUG_INFO( | |
1452 | "%s: card not responding to init command.\n", | |
1453 | priv->net_dev->name); | |
1454 | goto fail_up; | |
1455 | } | |
1456 | ||
1457 | if (priv->stop_hang_check) { | |
1458 | priv->stop_hang_check = 0; | |
1459 | queue_delayed_work(priv->workqueue, &priv->hang_check, HZ / 2); | |
1460 | } | |
1461 | ||
1462 | fail_up: | |
1463 | up(&priv->adapter_sem); | |
1464 | return err; | |
1465 | } | |
1466 | ||
1467 | static int ipw2100_hw_stop_adapter(struct ipw2100_priv *priv) | |
1468 | { | |
1469 | #define HW_POWER_DOWN_DELAY (HZ / 10) | |
1470 | ||
1471 | struct host_command cmd = { | |
1472 | .host_command = HOST_PRE_POWER_DOWN, | |
1473 | .host_command_sequence = 0, | |
1474 | .host_command_length = 0, | |
1475 | }; | |
1476 | int err, i; | |
1477 | u32 reg; | |
1478 | ||
1479 | if (!(priv->status & STATUS_RUNNING)) | |
1480 | return 0; | |
1481 | ||
1482 | priv->status |= STATUS_STOPPING; | |
1483 | ||
1484 | /* We can only shut down the card if the firmware is operational. So, | |
1485 | * if we haven't reset since a fatal_error, then we can not send the | |
1486 | * shutdown commands. */ | |
1487 | if (!priv->fatal_error) { | |
1488 | /* First, make sure the adapter is enabled so that the PHY_OFF | |
1489 | * command can shut it down */ | |
1490 | ipw2100_enable_adapter(priv); | |
1491 | ||
1492 | err = ipw2100_hw_phy_off(priv); | |
1493 | if (err) | |
797b4f76 | 1494 | printk(KERN_WARNING DRV_NAME ": Error disabling radio %d\n", err); |
2c86c275 JK |
1495 | |
1496 | /* | |
1497 | * If in D0-standby mode going directly to D3 may cause a | |
1498 | * PCI bus violation. Therefore we must change out of the D0 | |
1499 | * state. | |
1500 | * | |
1501 | * Sending the PREPARE_FOR_POWER_DOWN will restrict the | |
1502 | * hardware from going into standby mode and will transition | |
1503 | * out of D0-standy if it is already in that state. | |
1504 | * | |
1505 | * STATUS_PREPARE_POWER_DOWN_COMPLETE will be sent by the | |
1506 | * driver upon completion. Once received, the driver can | |
1507 | * proceed to the D3 state. | |
1508 | * | |
1509 | * Prepare for power down command to fw. This command would | |
1510 | * take HW out of D0-standby and prepare it for D3 state. | |
1511 | * | |
1512 | * Currently FW does not support event notification for this | |
1513 | * event. Therefore, skip waiting for it. Just wait a fixed | |
1514 | * 100ms | |
1515 | */ | |
1516 | IPW_DEBUG_HC("HOST_PRE_POWER_DOWN\n"); | |
1517 | ||
1518 | err = ipw2100_hw_send_command(priv, &cmd); | |
1519 | if (err) | |
797b4f76 | 1520 | printk(KERN_WARNING DRV_NAME ": " |
2c86c275 JK |
1521 | "%s: Power down command failed: Error %d\n", |
1522 | priv->net_dev->name, err); | |
1523 | else { | |
1524 | set_current_state(TASK_UNINTERRUPTIBLE); | |
1525 | schedule_timeout(HW_POWER_DOWN_DELAY); | |
1526 | } | |
1527 | } | |
1528 | ||
1529 | priv->status &= ~STATUS_ENABLED; | |
1530 | ||
1531 | /* | |
1532 | * Set GPIO 3 writable by FW; GPIO 1 writable | |
1533 | * by driver and enable clock | |
1534 | */ | |
1535 | ipw2100_hw_set_gpio(priv); | |
1536 | ||
1537 | /* | |
1538 | * Power down adapter. Sequence: | |
1539 | * 1. Stop master assert (RESET_REG[9]=1) | |
1540 | * 2. Wait for stop master (RESET_REG[8]==1) | |
1541 | * 3. S/w reset assert (RESET_REG[7] = 1) | |
1542 | */ | |
1543 | ||
1544 | /* Stop master assert */ | |
1545 | write_register(priv->net_dev, IPW_REG_RESET_REG, | |
1546 | IPW_AUX_HOST_RESET_REG_STOP_MASTER); | |
1547 | ||
1548 | /* wait stop master not more than 50 usec. | |
1549 | * Otherwise return error. */ | |
1550 | for (i = 5; i > 0; i--) { | |
1551 | udelay(10); | |
1552 | ||
1553 | /* Check master stop bit */ | |
1554 | read_register(priv->net_dev, IPW_REG_RESET_REG, ®); | |
1555 | ||
1556 | if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED) | |
1557 | break; | |
1558 | } | |
1559 | ||
1560 | if (i == 0) | |
797b4f76 | 1561 | printk(KERN_WARNING DRV_NAME |
2c86c275 JK |
1562 | ": %s: Could now power down adapter.\n", |
1563 | priv->net_dev->name); | |
1564 | ||
1565 | /* assert s/w reset */ | |
1566 | write_register(priv->net_dev, IPW_REG_RESET_REG, | |
1567 | IPW_AUX_HOST_RESET_REG_SW_RESET); | |
1568 | ||
1569 | priv->status &= ~(STATUS_RUNNING | STATUS_STOPPING); | |
1570 | ||
1571 | return 0; | |
1572 | } | |
1573 | ||
1574 | ||
1575 | static int ipw2100_disable_adapter(struct ipw2100_priv *priv) | |
1576 | { | |
1577 | struct host_command cmd = { | |
1578 | .host_command = CARD_DISABLE, | |
1579 | .host_command_sequence = 0, | |
1580 | .host_command_length = 0 | |
1581 | }; | |
1582 | int err = 0; | |
1583 | ||
1584 | IPW_DEBUG_HC("CARD_DISABLE\n"); | |
1585 | ||
1586 | if (!(priv->status & STATUS_ENABLED)) | |
1587 | return 0; | |
1588 | ||
1589 | /* Make sure we clear the associated state */ | |
1590 | priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING); | |
1591 | ||
1592 | if (!priv->stop_hang_check) { | |
1593 | priv->stop_hang_check = 1; | |
1594 | cancel_delayed_work(&priv->hang_check); | |
1595 | } | |
1596 | ||
1597 | down(&priv->adapter_sem); | |
1598 | ||
1599 | err = ipw2100_hw_send_command(priv, &cmd); | |
1600 | if (err) { | |
797b4f76 | 1601 | printk(KERN_WARNING DRV_NAME ": exit - failed to send CARD_DISABLE command\n"); |
2c86c275 JK |
1602 | goto fail_up; |
1603 | } | |
1604 | ||
1605 | err = ipw2100_wait_for_card_state(priv, IPW_HW_STATE_DISABLED); | |
1606 | if (err) { | |
797b4f76 | 1607 | printk(KERN_WARNING DRV_NAME ": exit - card failed to change to DISABLED\n"); |
2c86c275 JK |
1608 | goto fail_up; |
1609 | } | |
1610 | ||
1611 | IPW_DEBUG_INFO("TODO: implement scan state machine\n"); | |
1612 | ||
1613 | fail_up: | |
1614 | up(&priv->adapter_sem); | |
1615 | return err; | |
1616 | } | |
1617 | ||
c4aee8c2 | 1618 | static int ipw2100_set_scan_options(struct ipw2100_priv *priv) |
2c86c275 JK |
1619 | { |
1620 | struct host_command cmd = { | |
1621 | .host_command = SET_SCAN_OPTIONS, | |
1622 | .host_command_sequence = 0, | |
1623 | .host_command_length = 8 | |
1624 | }; | |
1625 | int err; | |
1626 | ||
1627 | IPW_DEBUG_INFO("enter\n"); | |
1628 | ||
1629 | IPW_DEBUG_SCAN("setting scan options\n"); | |
1630 | ||
1631 | cmd.host_command_parameters[0] = 0; | |
1632 | ||
1633 | if (!(priv->config & CFG_ASSOCIATE)) | |
1634 | cmd.host_command_parameters[0] |= IPW_SCAN_NOASSOCIATE; | |
1635 | if ((priv->sec.flags & SEC_ENABLED) && priv->sec.enabled) | |
1636 | cmd.host_command_parameters[0] |= IPW_SCAN_MIXED_CELL; | |
1637 | if (priv->config & CFG_PASSIVE_SCAN) | |
1638 | cmd.host_command_parameters[0] |= IPW_SCAN_PASSIVE; | |
1639 | ||
1640 | cmd.host_command_parameters[1] = priv->channel_mask; | |
1641 | ||
1642 | err = ipw2100_hw_send_command(priv, &cmd); | |
1643 | ||
1644 | IPW_DEBUG_HC("SET_SCAN_OPTIONS 0x%04X\n", | |
1645 | cmd.host_command_parameters[0]); | |
1646 | ||
1647 | return err; | |
1648 | } | |
1649 | ||
c4aee8c2 | 1650 | static int ipw2100_start_scan(struct ipw2100_priv *priv) |
2c86c275 JK |
1651 | { |
1652 | struct host_command cmd = { | |
1653 | .host_command = BROADCAST_SCAN, | |
1654 | .host_command_sequence = 0, | |
1655 | .host_command_length = 4 | |
1656 | }; | |
1657 | int err; | |
1658 | ||
1659 | IPW_DEBUG_HC("START_SCAN\n"); | |
1660 | ||
1661 | cmd.host_command_parameters[0] = 0; | |
1662 | ||
1663 | /* No scanning if in monitor mode */ | |
1664 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) | |
1665 | return 1; | |
1666 | ||
1667 | if (priv->status & STATUS_SCANNING) { | |
1668 | IPW_DEBUG_SCAN("Scan requested while already in scan...\n"); | |
1669 | return 0; | |
1670 | } | |
1671 | ||
1672 | IPW_DEBUG_INFO("enter\n"); | |
1673 | ||
1674 | /* Not clearing here; doing so makes iwlist always return nothing... | |
1675 | * | |
1676 | * We should modify the table logic to use aging tables vs. clearing | |
1677 | * the table on each scan start. | |
1678 | */ | |
1679 | IPW_DEBUG_SCAN("starting scan\n"); | |
1680 | ||
1681 | priv->status |= STATUS_SCANNING; | |
1682 | err = ipw2100_hw_send_command(priv, &cmd); | |
1683 | if (err) | |
1684 | priv->status &= ~STATUS_SCANNING; | |
1685 | ||
1686 | IPW_DEBUG_INFO("exit\n"); | |
1687 | ||
1688 | return err; | |
1689 | } | |
1690 | ||
1691 | static int ipw2100_up(struct ipw2100_priv *priv, int deferred) | |
1692 | { | |
1693 | unsigned long flags; | |
1694 | int rc = 0; | |
1695 | u32 lock; | |
1696 | u32 ord_len = sizeof(lock); | |
1697 | ||
1698 | /* Quite if manually disabled. */ | |
1699 | if (priv->status & STATUS_RF_KILL_SW) { | |
1700 | IPW_DEBUG_INFO("%s: Radio is disabled by Manual Disable " | |
1701 | "switch\n", priv->net_dev->name); | |
1702 | return 0; | |
1703 | } | |
1704 | ||
1705 | /* If the interrupt is enabled, turn it off... */ | |
1706 | spin_lock_irqsave(&priv->low_lock, flags); | |
1707 | ipw2100_disable_interrupts(priv); | |
1708 | ||
1709 | /* Reset any fatal_error conditions */ | |
1710 | ipw2100_reset_fatalerror(priv); | |
1711 | spin_unlock_irqrestore(&priv->low_lock, flags); | |
1712 | ||
1713 | if (priv->status & STATUS_POWERED || | |
1714 | (priv->status & STATUS_RESET_PENDING)) { | |
1715 | /* Power cycle the card ... */ | |
1716 | if (ipw2100_power_cycle_adapter(priv)) { | |
797b4f76 | 1717 | printk(KERN_WARNING DRV_NAME ": %s: Could not cycle adapter.\n", |
2c86c275 JK |
1718 | priv->net_dev->name); |
1719 | rc = 1; | |
1720 | goto exit; | |
1721 | } | |
1722 | } else | |
1723 | priv->status |= STATUS_POWERED; | |
1724 | ||
8724a118 | 1725 | /* Load the firmware, start the clocks, etc. */ |
2c86c275 | 1726 | if (ipw2100_start_adapter(priv)) { |
797b4f76 | 1727 | printk(KERN_ERR DRV_NAME ": %s: Failed to start the firmware.\n", |
2c86c275 JK |
1728 | priv->net_dev->name); |
1729 | rc = 1; | |
1730 | goto exit; | |
1731 | } | |
1732 | ||
1733 | ipw2100_initialize_ordinals(priv); | |
1734 | ||
1735 | /* Determine capabilities of this particular HW configuration */ | |
1736 | if (ipw2100_get_hw_features(priv)) { | |
797b4f76 | 1737 | printk(KERN_ERR DRV_NAME ": %s: Failed to determine HW features.\n", |
2c86c275 JK |
1738 | priv->net_dev->name); |
1739 | rc = 1; | |
1740 | goto exit; | |
1741 | } | |
1742 | ||
1743 | lock = LOCK_NONE; | |
1744 | if (ipw2100_set_ordinal(priv, IPW_ORD_PERS_DB_LOCK, &lock, &ord_len)) { | |
797b4f76 | 1745 | printk(KERN_ERR DRV_NAME ": %s: Failed to clear ordinal lock.\n", |
2c86c275 JK |
1746 | priv->net_dev->name); |
1747 | rc = 1; | |
1748 | goto exit; | |
1749 | } | |
1750 | ||
1751 | priv->status &= ~STATUS_SCANNING; | |
1752 | ||
1753 | if (rf_kill_active(priv)) { | |
1754 | printk(KERN_INFO "%s: Radio is disabled by RF switch.\n", | |
1755 | priv->net_dev->name); | |
1756 | ||
1757 | if (priv->stop_rf_kill) { | |
1758 | priv->stop_rf_kill = 0; | |
1759 | queue_delayed_work(priv->workqueue, &priv->rf_kill, HZ); | |
1760 | } | |
1761 | ||
1762 | deferred = 1; | |
1763 | } | |
1764 | ||
1765 | /* Turn on the interrupt so that commands can be processed */ | |
1766 | ipw2100_enable_interrupts(priv); | |
1767 | ||
1768 | /* Send all of the commands that must be sent prior to | |
1769 | * HOST_COMPLETE */ | |
1770 | if (ipw2100_adapter_setup(priv)) { | |
797b4f76 | 1771 | printk(KERN_ERR DRV_NAME ": %s: Failed to start the card.\n", |
2c86c275 JK |
1772 | priv->net_dev->name); |
1773 | rc = 1; | |
1774 | goto exit; | |
1775 | } | |
1776 | ||
1777 | if (!deferred) { | |
1778 | /* Enable the adapter - sends HOST_COMPLETE */ | |
1779 | if (ipw2100_enable_adapter(priv)) { | |
797b4f76 | 1780 | printk(KERN_ERR DRV_NAME ": " |
2c86c275 JK |
1781 | "%s: failed in call to enable adapter.\n", |
1782 | priv->net_dev->name); | |
1783 | ipw2100_hw_stop_adapter(priv); | |
1784 | rc = 1; | |
1785 | goto exit; | |
1786 | } | |
1787 | ||
1788 | ||
1789 | /* Start a scan . . . */ | |
1790 | ipw2100_set_scan_options(priv); | |
1791 | ipw2100_start_scan(priv); | |
1792 | } | |
1793 | ||
1794 | exit: | |
1795 | return rc; | |
1796 | } | |
1797 | ||
1798 | /* Called by register_netdev() */ | |
1799 | static int ipw2100_net_init(struct net_device *dev) | |
1800 | { | |
1801 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
1802 | return ipw2100_up(priv, 1); | |
1803 | } | |
1804 | ||
1805 | static void ipw2100_down(struct ipw2100_priv *priv) | |
1806 | { | |
1807 | unsigned long flags; | |
1808 | union iwreq_data wrqu = { | |
1809 | .ap_addr = { | |
1810 | .sa_family = ARPHRD_ETHER | |
1811 | } | |
1812 | }; | |
1813 | int associated = priv->status & STATUS_ASSOCIATED; | |
1814 | ||
1815 | /* Kill the RF switch timer */ | |
1816 | if (!priv->stop_rf_kill) { | |
1817 | priv->stop_rf_kill = 1; | |
1818 | cancel_delayed_work(&priv->rf_kill); | |
1819 | } | |
1820 | ||
1821 | /* Kill the firmare hang check timer */ | |
1822 | if (!priv->stop_hang_check) { | |
1823 | priv->stop_hang_check = 1; | |
1824 | cancel_delayed_work(&priv->hang_check); | |
1825 | } | |
1826 | ||
1827 | /* Kill any pending resets */ | |
1828 | if (priv->status & STATUS_RESET_PENDING) | |
1829 | cancel_delayed_work(&priv->reset_work); | |
1830 | ||
1831 | /* Make sure the interrupt is on so that FW commands will be | |
1832 | * processed correctly */ | |
1833 | spin_lock_irqsave(&priv->low_lock, flags); | |
1834 | ipw2100_enable_interrupts(priv); | |
1835 | spin_unlock_irqrestore(&priv->low_lock, flags); | |
1836 | ||
1837 | if (ipw2100_hw_stop_adapter(priv)) | |
797b4f76 | 1838 | printk(KERN_ERR DRV_NAME ": %s: Error stopping adapter.\n", |
2c86c275 JK |
1839 | priv->net_dev->name); |
1840 | ||
1841 | /* Do not disable the interrupt until _after_ we disable | |
1842 | * the adaptor. Otherwise the CARD_DISABLE command will never | |
1843 | * be ack'd by the firmware */ | |
1844 | spin_lock_irqsave(&priv->low_lock, flags); | |
1845 | ipw2100_disable_interrupts(priv); | |
1846 | spin_unlock_irqrestore(&priv->low_lock, flags); | |
1847 | ||
1848 | #ifdef ACPI_CSTATE_LIMIT_DEFINED | |
1849 | if (priv->config & CFG_C3_DISABLED) { | |
1850 | IPW_DEBUG_INFO(DRV_NAME ": Resetting C3 transitions.\n"); | |
1851 | acpi_set_cstate_limit(priv->cstate_limit); | |
1852 | priv->config &= ~CFG_C3_DISABLED; | |
1853 | } | |
1854 | #endif | |
1855 | ||
1856 | /* We have to signal any supplicant if we are disassociating */ | |
1857 | if (associated) | |
1858 | wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL); | |
1859 | ||
1860 | priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING); | |
1861 | netif_carrier_off(priv->net_dev); | |
1862 | netif_stop_queue(priv->net_dev); | |
1863 | } | |
1864 | ||
c4aee8c2 | 1865 | static void ipw2100_reset_adapter(struct ipw2100_priv *priv) |
2c86c275 JK |
1866 | { |
1867 | unsigned long flags; | |
1868 | union iwreq_data wrqu = { | |
1869 | .ap_addr = { | |
1870 | .sa_family = ARPHRD_ETHER | |
1871 | } | |
1872 | }; | |
1873 | int associated = priv->status & STATUS_ASSOCIATED; | |
1874 | ||
1875 | spin_lock_irqsave(&priv->low_lock, flags); | |
1876 | IPW_DEBUG_INFO(DRV_NAME ": %s: Restarting adapter.\n", | |
1877 | priv->net_dev->name); | |
1878 | priv->resets++; | |
1879 | priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING); | |
1880 | priv->status |= STATUS_SECURITY_UPDATED; | |
1881 | ||
1882 | /* Force a power cycle even if interface hasn't been opened | |
1883 | * yet */ | |
1884 | cancel_delayed_work(&priv->reset_work); | |
1885 | priv->status |= STATUS_RESET_PENDING; | |
1886 | spin_unlock_irqrestore(&priv->low_lock, flags); | |
1887 | ||
1888 | down(&priv->action_sem); | |
1889 | /* stop timed checks so that they don't interfere with reset */ | |
1890 | priv->stop_hang_check = 1; | |
1891 | cancel_delayed_work(&priv->hang_check); | |
1892 | ||
1893 | /* We have to signal any supplicant if we are disassociating */ | |
1894 | if (associated) | |
1895 | wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL); | |
1896 | ||
1897 | ipw2100_up(priv, 0); | |
1898 | up(&priv->action_sem); | |
1899 | ||
1900 | } | |
1901 | ||
1902 | ||
1903 | static void isr_indicate_associated(struct ipw2100_priv *priv, u32 status) | |
1904 | { | |
1905 | ||
1906 | #define MAC_ASSOCIATION_READ_DELAY (HZ) | |
1907 | int ret, len, essid_len; | |
1908 | char essid[IW_ESSID_MAX_SIZE]; | |
1909 | u32 txrate; | |
1910 | u32 chan; | |
1911 | char *txratename; | |
1912 | u8 bssid[ETH_ALEN]; | |
1913 | ||
1914 | /* | |
1915 | * TBD: BSSID is usually 00:00:00:00:00:00 here and not | |
1916 | * an actual MAC of the AP. Seems like FW sets this | |
1917 | * address too late. Read it later and expose through | |
1918 | * /proc or schedule a later task to query and update | |
1919 | */ | |
1920 | ||
1921 | essid_len = IW_ESSID_MAX_SIZE; | |
1922 | ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_SSID, | |
1923 | essid, &essid_len); | |
1924 | if (ret) { | |
1925 | IPW_DEBUG_INFO("failed querying ordinals at line %d\n", | |
1926 | __LINE__); | |
1927 | return; | |
1928 | } | |
1929 | ||
1930 | len = sizeof(u32); | |
1931 | ret = ipw2100_get_ordinal(priv, IPW_ORD_CURRENT_TX_RATE, | |
1932 | &txrate, &len); | |
1933 | if (ret) { | |
1934 | IPW_DEBUG_INFO("failed querying ordinals at line %d\n", | |
1935 | __LINE__); | |
1936 | return; | |
1937 | } | |
1938 | ||
1939 | len = sizeof(u32); | |
1940 | ret = ipw2100_get_ordinal(priv, IPW_ORD_OUR_FREQ, &chan, &len); | |
1941 | if (ret) { | |
1942 | IPW_DEBUG_INFO("failed querying ordinals at line %d\n", | |
1943 | __LINE__); | |
1944 | return; | |
1945 | } | |
1946 | len = ETH_ALEN; | |
1947 | ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID, &bssid, &len); | |
1948 | if (ret) { | |
1949 | IPW_DEBUG_INFO("failed querying ordinals at line %d\n", | |
1950 | __LINE__); | |
1951 | return; | |
1952 | } | |
1953 | memcpy(priv->ieee->bssid, bssid, ETH_ALEN); | |
1954 | ||
1955 | ||
1956 | switch (txrate) { | |
1957 | case TX_RATE_1_MBIT: | |
1958 | txratename = "1Mbps"; | |
1959 | break; | |
1960 | case TX_RATE_2_MBIT: | |
1961 | txratename = "2Mbsp"; | |
1962 | break; | |
1963 | case TX_RATE_5_5_MBIT: | |
1964 | txratename = "5.5Mbps"; | |
1965 | break; | |
1966 | case TX_RATE_11_MBIT: | |
1967 | txratename = "11Mbps"; | |
1968 | break; | |
1969 | default: | |
1970 | IPW_DEBUG_INFO("Unknown rate: %d\n", txrate); | |
1971 | txratename = "unknown rate"; | |
1972 | break; | |
1973 | } | |
1974 | ||
1975 | IPW_DEBUG_INFO("%s: Associated with '%s' at %s, channel %d (BSSID=" | |
1976 | MAC_FMT ")\n", | |
1977 | priv->net_dev->name, escape_essid(essid, essid_len), | |
1978 | txratename, chan, MAC_ARG(bssid)); | |
1979 | ||
1980 | /* now we copy read ssid into dev */ | |
1981 | if (!(priv->config & CFG_STATIC_ESSID)) { | |
1982 | priv->essid_len = min((u8)essid_len, (u8)IW_ESSID_MAX_SIZE); | |
1983 | memcpy(priv->essid, essid, priv->essid_len); | |
1984 | } | |
1985 | priv->channel = chan; | |
1986 | memcpy(priv->bssid, bssid, ETH_ALEN); | |
1987 | ||
1988 | priv->status |= STATUS_ASSOCIATING; | |
1989 | priv->connect_start = get_seconds(); | |
1990 | ||
1991 | queue_delayed_work(priv->workqueue, &priv->wx_event_work, HZ / 10); | |
1992 | } | |
1993 | ||
1994 | ||
c4aee8c2 JB |
1995 | static int ipw2100_set_essid(struct ipw2100_priv *priv, char *essid, |
1996 | int length, int batch_mode) | |
2c86c275 JK |
1997 | { |
1998 | int ssid_len = min(length, IW_ESSID_MAX_SIZE); | |
1999 | struct host_command cmd = { | |
2000 | .host_command = SSID, | |
2001 | .host_command_sequence = 0, | |
2002 | .host_command_length = ssid_len | |
2003 | }; | |
2004 | int err; | |
2005 | ||
2006 | IPW_DEBUG_HC("SSID: '%s'\n", escape_essid(essid, ssid_len)); | |
2007 | ||
2008 | if (ssid_len) | |
2009 | memcpy((char*)cmd.host_command_parameters, | |
2010 | essid, ssid_len); | |
2011 | ||
2012 | if (!batch_mode) { | |
2013 | err = ipw2100_disable_adapter(priv); | |
2014 | if (err) | |
2015 | return err; | |
2016 | } | |
2017 | ||
2018 | /* Bug in FW currently doesn't honor bit 0 in SET_SCAN_OPTIONS to | |
2019 | * disable auto association -- so we cheat by setting a bogus SSID */ | |
2020 | if (!ssid_len && !(priv->config & CFG_ASSOCIATE)) { | |
2021 | int i; | |
2022 | u8 *bogus = (u8*)cmd.host_command_parameters; | |
2023 | for (i = 0; i < IW_ESSID_MAX_SIZE; i++) | |
2024 | bogus[i] = 0x18 + i; | |
2025 | cmd.host_command_length = IW_ESSID_MAX_SIZE; | |
2026 | } | |
2027 | ||
2028 | /* NOTE: We always send the SSID command even if the provided ESSID is | |
2029 | * the same as what we currently think is set. */ | |
2030 | ||
2031 | err = ipw2100_hw_send_command(priv, &cmd); | |
2032 | if (!err) { | |
2033 | memset(priv->essid + ssid_len, 0, | |
2034 | IW_ESSID_MAX_SIZE - ssid_len); | |
2035 | memcpy(priv->essid, essid, ssid_len); | |
2036 | priv->essid_len = ssid_len; | |
2037 | } | |
2038 | ||
2039 | if (!batch_mode) { | |
2040 | if (ipw2100_enable_adapter(priv)) | |
2041 | err = -EIO; | |
2042 | } | |
2043 | ||
2044 | return err; | |
2045 | } | |
2046 | ||
2047 | static void isr_indicate_association_lost(struct ipw2100_priv *priv, u32 status) | |
2048 | { | |
2049 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | IPW_DL_ASSOC, | |
2050 | "disassociated: '%s' " MAC_FMT " \n", | |
2051 | escape_essid(priv->essid, priv->essid_len), | |
2052 | MAC_ARG(priv->bssid)); | |
2053 | ||
2054 | priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING); | |
2055 | ||
2056 | if (priv->status & STATUS_STOPPING) { | |
2057 | IPW_DEBUG_INFO("Card is stopping itself, discard ASSN_LOST.\n"); | |
2058 | return; | |
2059 | } | |
2060 | ||
2061 | memset(priv->bssid, 0, ETH_ALEN); | |
2062 | memset(priv->ieee->bssid, 0, ETH_ALEN); | |
2063 | ||
2064 | netif_carrier_off(priv->net_dev); | |
2065 | netif_stop_queue(priv->net_dev); | |
2066 | ||
2067 | if (!(priv->status & STATUS_RUNNING)) | |
2068 | return; | |
2069 | ||
2070 | if (priv->status & STATUS_SECURITY_UPDATED) | |
2071 | queue_work(priv->workqueue, &priv->security_work); | |
2072 | ||
2073 | queue_work(priv->workqueue, &priv->wx_event_work); | |
2074 | } | |
2075 | ||
2076 | static void isr_indicate_rf_kill(struct ipw2100_priv *priv, u32 status) | |
2077 | { | |
2078 | IPW_DEBUG_INFO("%s: RF Kill state changed to radio OFF.\n", | |
2079 | priv->net_dev->name); | |
2080 | ||
2081 | /* RF_KILL is now enabled (else we wouldn't be here) */ | |
2082 | priv->status |= STATUS_RF_KILL_HW; | |
2083 | ||
2084 | #ifdef ACPI_CSTATE_LIMIT_DEFINED | |
2085 | if (priv->config & CFG_C3_DISABLED) { | |
2086 | IPW_DEBUG_INFO(DRV_NAME ": Resetting C3 transitions.\n"); | |
2087 | acpi_set_cstate_limit(priv->cstate_limit); | |
2088 | priv->config &= ~CFG_C3_DISABLED; | |
2089 | } | |
2090 | #endif | |
2091 | ||
2092 | /* Make sure the RF Kill check timer is running */ | |
2093 | priv->stop_rf_kill = 0; | |
2094 | cancel_delayed_work(&priv->rf_kill); | |
2095 | queue_delayed_work(priv->workqueue, &priv->rf_kill, HZ); | |
2096 | } | |
2097 | ||
2098 | static void isr_scan_complete(struct ipw2100_priv *priv, u32 status) | |
2099 | { | |
2100 | IPW_DEBUG_SCAN("scan complete\n"); | |
2101 | /* Age the scan results... */ | |
2102 | priv->ieee->scans++; | |
2103 | priv->status &= ~STATUS_SCANNING; | |
2104 | } | |
2105 | ||
2106 | #ifdef CONFIG_IPW_DEBUG | |
2107 | #define IPW2100_HANDLER(v, f) { v, f, # v } | |
2108 | struct ipw2100_status_indicator { | |
2109 | int status; | |
2110 | void (*cb)(struct ipw2100_priv *priv, u32 status); | |
2111 | char *name; | |
2112 | }; | |
2113 | #else | |
2114 | #define IPW2100_HANDLER(v, f) { v, f } | |
2115 | struct ipw2100_status_indicator { | |
2116 | int status; | |
2117 | void (*cb)(struct ipw2100_priv *priv, u32 status); | |
2118 | }; | |
2119 | #endif /* CONFIG_IPW_DEBUG */ | |
2120 | ||
2121 | static void isr_indicate_scanning(struct ipw2100_priv *priv, u32 status) | |
2122 | { | |
2123 | IPW_DEBUG_SCAN("Scanning...\n"); | |
2124 | priv->status |= STATUS_SCANNING; | |
2125 | } | |
2126 | ||
c4aee8c2 | 2127 | static const struct ipw2100_status_indicator status_handlers[] = { |
2c86c275 JK |
2128 | IPW2100_HANDLER(IPW_STATE_INITIALIZED, 0), |
2129 | IPW2100_HANDLER(IPW_STATE_COUNTRY_FOUND, 0), | |
2130 | IPW2100_HANDLER(IPW_STATE_ASSOCIATED, isr_indicate_associated), | |
2131 | IPW2100_HANDLER(IPW_STATE_ASSN_LOST, isr_indicate_association_lost), | |
2132 | IPW2100_HANDLER(IPW_STATE_ASSN_CHANGED, 0), | |
2133 | IPW2100_HANDLER(IPW_STATE_SCAN_COMPLETE, isr_scan_complete), | |
2134 | IPW2100_HANDLER(IPW_STATE_ENTERED_PSP, 0), | |
2135 | IPW2100_HANDLER(IPW_STATE_LEFT_PSP, 0), | |
2136 | IPW2100_HANDLER(IPW_STATE_RF_KILL, isr_indicate_rf_kill), | |
2137 | IPW2100_HANDLER(IPW_STATE_DISABLED, 0), | |
2138 | IPW2100_HANDLER(IPW_STATE_POWER_DOWN, 0), | |
2139 | IPW2100_HANDLER(IPW_STATE_SCANNING, isr_indicate_scanning), | |
2140 | IPW2100_HANDLER(-1, 0) | |
2141 | }; | |
2142 | ||
2143 | ||
2144 | static void isr_status_change(struct ipw2100_priv *priv, int status) | |
2145 | { | |
2146 | int i; | |
2147 | ||
2148 | if (status == IPW_STATE_SCANNING && | |
2149 | priv->status & STATUS_ASSOCIATED && | |
2150 | !(priv->status & STATUS_SCANNING)) { | |
2151 | IPW_DEBUG_INFO("Scan detected while associated, with " | |
2152 | "no scan request. Restarting firmware.\n"); | |
2153 | ||
2154 | /* Wake up any sleeping jobs */ | |
2155 | schedule_reset(priv); | |
2156 | } | |
2157 | ||
2158 | for (i = 0; status_handlers[i].status != -1; i++) { | |
2159 | if (status == status_handlers[i].status) { | |
2160 | IPW_DEBUG_NOTIF("Status change: %s\n", | |
2161 | status_handlers[i].name); | |
2162 | if (status_handlers[i].cb) | |
2163 | status_handlers[i].cb(priv, status); | |
2164 | priv->wstats.status = status; | |
2165 | return; | |
2166 | } | |
2167 | } | |
2168 | ||
2169 | IPW_DEBUG_NOTIF("unknown status received: %04x\n", status); | |
2170 | } | |
2171 | ||
2172 | static void isr_rx_complete_command( | |
2173 | struct ipw2100_priv *priv, | |
2174 | struct ipw2100_cmd_header *cmd) | |
2175 | { | |
2176 | #ifdef CONFIG_IPW_DEBUG | |
2177 | if (cmd->host_command_reg < ARRAY_SIZE(command_types)) { | |
2178 | IPW_DEBUG_HC("Command completed '%s (%d)'\n", | |
2179 | command_types[cmd->host_command_reg], | |
2180 | cmd->host_command_reg); | |
2181 | } | |
2182 | #endif | |
2183 | if (cmd->host_command_reg == HOST_COMPLETE) | |
2184 | priv->status |= STATUS_ENABLED; | |
2185 | ||
2186 | if (cmd->host_command_reg == CARD_DISABLE) | |
2187 | priv->status &= ~STATUS_ENABLED; | |
2188 | ||
2189 | priv->status &= ~STATUS_CMD_ACTIVE; | |
2190 | ||
2191 | wake_up_interruptible(&priv->wait_command_queue); | |
2192 | } | |
2193 | ||
2194 | #ifdef CONFIG_IPW_DEBUG | |
c4aee8c2 | 2195 | static const char *frame_types[] = { |
2c86c275 JK |
2196 | "COMMAND_STATUS_VAL", |
2197 | "STATUS_CHANGE_VAL", | |
2198 | "P80211_DATA_VAL", | |
2199 | "P8023_DATA_VAL", | |
2200 | "HOST_NOTIFICATION_VAL" | |
2201 | }; | |
2202 | #endif | |
2203 | ||
2204 | ||
2205 | static inline int ipw2100_alloc_skb( | |
2206 | struct ipw2100_priv *priv, | |
2207 | struct ipw2100_rx_packet *packet) | |
2208 | { | |
2209 | packet->skb = dev_alloc_skb(sizeof(struct ipw2100_rx)); | |
2210 | if (!packet->skb) | |
2211 | return -ENOMEM; | |
2212 | ||
2213 | packet->rxp = (struct ipw2100_rx *)packet->skb->data; | |
2214 | packet->dma_addr = pci_map_single(priv->pci_dev, packet->skb->data, | |
2215 | sizeof(struct ipw2100_rx), | |
2216 | PCI_DMA_FROMDEVICE); | |
2217 | /* NOTE: pci_map_single does not return an error code, and 0 is a valid | |
2218 | * dma_addr */ | |
2219 | ||
2220 | return 0; | |
2221 | } | |
2222 | ||
2223 | ||
2224 | #define SEARCH_ERROR 0xffffffff | |
2225 | #define SEARCH_FAIL 0xfffffffe | |
2226 | #define SEARCH_SUCCESS 0xfffffff0 | |
2227 | #define SEARCH_DISCARD 0 | |
2228 | #define SEARCH_SNAPSHOT 1 | |
2229 | ||
2230 | #define SNAPSHOT_ADDR(ofs) (priv->snapshot[((ofs) >> 12) & 0xff] + ((ofs) & 0xfff)) | |
2231 | static inline int ipw2100_snapshot_alloc(struct ipw2100_priv *priv) | |
2232 | { | |
2233 | int i; | |
2234 | if (priv->snapshot[0]) | |
2235 | return 1; | |
2236 | for (i = 0; i < 0x30; i++) { | |
2237 | priv->snapshot[i] = (u8*)kmalloc(0x1000, GFP_ATOMIC); | |
2238 | if (!priv->snapshot[i]) { | |
2239 | IPW_DEBUG_INFO("%s: Error allocating snapshot " | |
2240 | "buffer %d\n", priv->net_dev->name, i); | |
2241 | while (i > 0) | |
2242 | kfree(priv->snapshot[--i]); | |
2243 | priv->snapshot[0] = NULL; | |
2244 | return 0; | |
2245 | } | |
2246 | } | |
2247 | ||
2248 | return 1; | |
2249 | } | |
2250 | ||
2251 | static inline void ipw2100_snapshot_free(struct ipw2100_priv *priv) | |
2252 | { | |
2253 | int i; | |
2254 | if (!priv->snapshot[0]) | |
2255 | return; | |
2256 | for (i = 0; i < 0x30; i++) | |
2257 | kfree(priv->snapshot[i]); | |
2258 | priv->snapshot[0] = NULL; | |
2259 | } | |
2260 | ||
2261 | static inline u32 ipw2100_match_buf(struct ipw2100_priv *priv, u8 *in_buf, | |
2262 | size_t len, int mode) | |
2263 | { | |
2264 | u32 i, j; | |
2265 | u32 tmp; | |
2266 | u8 *s, *d; | |
2267 | u32 ret; | |
2268 | ||
2269 | s = in_buf; | |
2270 | if (mode == SEARCH_SNAPSHOT) { | |
2271 | if (!ipw2100_snapshot_alloc(priv)) | |
2272 | mode = SEARCH_DISCARD; | |
2273 | } | |
2274 | ||
2275 | for (ret = SEARCH_FAIL, i = 0; i < 0x30000; i += 4) { | |
2276 | read_nic_dword(priv->net_dev, i, &tmp); | |
2277 | if (mode == SEARCH_SNAPSHOT) | |
2278 | *(u32 *)SNAPSHOT_ADDR(i) = tmp; | |
2279 | if (ret == SEARCH_FAIL) { | |
2280 | d = (u8*)&tmp; | |
2281 | for (j = 0; j < 4; j++) { | |
2282 | if (*s != *d) { | |
2283 | s = in_buf; | |
2284 | continue; | |
2285 | } | |
2286 | ||
2287 | s++; | |
2288 | d++; | |
2289 | ||
2290 | if ((s - in_buf) == len) | |
2291 | ret = (i + j) - len + 1; | |
2292 | } | |
2293 | } else if (mode == SEARCH_DISCARD) | |
2294 | return ret; | |
2295 | } | |
2296 | ||
2297 | return ret; | |
2298 | } | |
2299 | ||
2300 | /* | |
2301 | * | |
2302 | * 0) Disconnect the SKB from the firmware (just unmap) | |
2303 | * 1) Pack the ETH header into the SKB | |
2304 | * 2) Pass the SKB to the network stack | |
2305 | * | |
2306 | * When packet is provided by the firmware, it contains the following: | |
2307 | * | |
2308 | * . ieee80211_hdr | |
2309 | * . ieee80211_snap_hdr | |
2310 | * | |
2311 | * The size of the constructed ethernet | |
2312 | * | |
2313 | */ | |
2314 | #ifdef CONFIG_IPW2100_RX_DEBUG | |
c4aee8c2 | 2315 | static u8 packet_data[IPW_RX_NIC_BUFFER_LENGTH]; |
2c86c275 JK |
2316 | #endif |
2317 | ||
2318 | static inline void ipw2100_corruption_detected(struct ipw2100_priv *priv, | |
2319 | int i) | |
2320 | { | |
2321 | #ifdef CONFIG_IPW_DEBUG_C3 | |
2322 | struct ipw2100_status *status = &priv->status_queue.drv[i]; | |
2323 | u32 match, reg; | |
2324 | int j; | |
2325 | #endif | |
2326 | #ifdef ACPI_CSTATE_LIMIT_DEFINED | |
2327 | int limit; | |
2328 | #endif | |
2329 | ||
2330 | IPW_DEBUG_INFO(DRV_NAME ": PCI latency error detected at " | |
aaa4d308 | 2331 | "0x%04zX.\n", i * sizeof(struct ipw2100_status)); |
2c86c275 JK |
2332 | |
2333 | #ifdef ACPI_CSTATE_LIMIT_DEFINED | |
2334 | IPW_DEBUG_INFO(DRV_NAME ": Disabling C3 transitions.\n"); | |
2335 | limit = acpi_get_cstate_limit(); | |
2336 | if (limit > 2) { | |
2337 | priv->cstate_limit = limit; | |
2338 | acpi_set_cstate_limit(2); | |
2339 | priv->config |= CFG_C3_DISABLED; | |
2340 | } | |
2341 | #endif | |
2342 | ||
2343 | #ifdef CONFIG_IPW_DEBUG_C3 | |
2344 | /* Halt the fimrware so we can get a good image */ | |
2345 | write_register(priv->net_dev, IPW_REG_RESET_REG, | |
2346 | IPW_AUX_HOST_RESET_REG_STOP_MASTER); | |
2347 | j = 5; | |
2348 | do { | |
2349 | udelay(IPW_WAIT_RESET_MASTER_ASSERT_COMPLETE_DELAY); | |
2350 | read_register(priv->net_dev, IPW_REG_RESET_REG, ®); | |
2351 | ||
2352 | if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED) | |
2353 | break; | |
2354 | } while (j--); | |
2355 | ||
2356 | match = ipw2100_match_buf(priv, (u8*)status, | |
2357 | sizeof(struct ipw2100_status), | |
2358 | SEARCH_SNAPSHOT); | |
2359 | if (match < SEARCH_SUCCESS) | |
2360 | IPW_DEBUG_INFO("%s: DMA status match in Firmware at " | |
2361 | "offset 0x%06X, length %d:\n", | |
2362 | priv->net_dev->name, match, | |
2363 | sizeof(struct ipw2100_status)); | |
2364 | else | |
2365 | IPW_DEBUG_INFO("%s: No DMA status match in " | |
2366 | "Firmware.\n", priv->net_dev->name); | |
2367 | ||
2368 | printk_buf((u8*)priv->status_queue.drv, | |
2369 | sizeof(struct ipw2100_status) * RX_QUEUE_LENGTH); | |
2370 | #endif | |
2371 | ||
2372 | priv->fatal_error = IPW2100_ERR_C3_CORRUPTION; | |
2373 | priv->ieee->stats.rx_errors++; | |
2374 | schedule_reset(priv); | |
2375 | } | |
2376 | ||
2377 | static inline void isr_rx(struct ipw2100_priv *priv, int i, | |
2378 | struct ieee80211_rx_stats *stats) | |
2379 | { | |
2380 | struct ipw2100_status *status = &priv->status_queue.drv[i]; | |
2381 | struct ipw2100_rx_packet *packet = &priv->rx_buffers[i]; | |
2382 | ||
2383 | IPW_DEBUG_RX("Handler...\n"); | |
2384 | ||
2385 | if (unlikely(status->frame_size > skb_tailroom(packet->skb))) { | |
2386 | IPW_DEBUG_INFO("%s: frame_size (%u) > skb_tailroom (%u)!" | |
2387 | " Dropping.\n", | |
2388 | priv->net_dev->name, | |
2389 | status->frame_size, skb_tailroom(packet->skb)); | |
2390 | priv->ieee->stats.rx_errors++; | |
2391 | return; | |
2392 | } | |
2393 | ||
2394 | if (unlikely(!netif_running(priv->net_dev))) { | |
2395 | priv->ieee->stats.rx_errors++; | |
2396 | priv->wstats.discard.misc++; | |
2397 | IPW_DEBUG_DROP("Dropping packet while interface is not up.\n"); | |
2398 | return; | |
2399 | } | |
2400 | ||
2401 | if (unlikely(priv->ieee->iw_mode == IW_MODE_MONITOR && | |
2402 | status->flags & IPW_STATUS_FLAG_CRC_ERROR)) { | |
2403 | IPW_DEBUG_RX("CRC error in packet. Dropping.\n"); | |
2404 | priv->ieee->stats.rx_errors++; | |
2405 | return; | |
2406 | } | |
2407 | ||
2408 | if (unlikely(priv->ieee->iw_mode != IW_MODE_MONITOR && | |
2409 | !(priv->status & STATUS_ASSOCIATED))) { | |
2410 | IPW_DEBUG_DROP("Dropping packet while not associated.\n"); | |
2411 | priv->wstats.discard.misc++; | |
2412 | return; | |
2413 | } | |
2414 | ||
2415 | ||
2416 | pci_unmap_single(priv->pci_dev, | |
2417 | packet->dma_addr, | |
2418 | sizeof(struct ipw2100_rx), | |
2419 | PCI_DMA_FROMDEVICE); | |
2420 | ||
2421 | skb_put(packet->skb, status->frame_size); | |
2422 | ||
2423 | #ifdef CONFIG_IPW2100_RX_DEBUG | |
2424 | /* Make a copy of the frame so we can dump it to the logs if | |
2425 | * ieee80211_rx fails */ | |
2426 | memcpy(packet_data, packet->skb->data, | |
aaa4d308 | 2427 | min_t(u32, status->frame_size, IPW_RX_NIC_BUFFER_LENGTH)); |
2c86c275 JK |
2428 | #endif |
2429 | ||
2430 | if (!ieee80211_rx(priv->ieee, packet->skb, stats)) { | |
2431 | #ifdef CONFIG_IPW2100_RX_DEBUG | |
2432 | IPW_DEBUG_DROP("%s: Non consumed packet:\n", | |
2433 | priv->net_dev->name); | |
2434 | printk_buf(IPW_DL_DROP, packet_data, status->frame_size); | |
2435 | #endif | |
2436 | priv->ieee->stats.rx_errors++; | |
2437 | ||
2438 | /* ieee80211_rx failed, so it didn't free the SKB */ | |
2439 | dev_kfree_skb_any(packet->skb); | |
2440 | packet->skb = NULL; | |
2441 | } | |
2442 | ||
2443 | /* We need to allocate a new SKB and attach it to the RDB. */ | |
2444 | if (unlikely(ipw2100_alloc_skb(priv, packet))) { | |
797b4f76 | 2445 | printk(KERN_WARNING DRV_NAME ": " |
2c86c275 JK |
2446 | "%s: Unable to allocate SKB onto RBD ring - disabling " |
2447 | "adapter.\n", priv->net_dev->name); | |
2448 | /* TODO: schedule adapter shutdown */ | |
2449 | IPW_DEBUG_INFO("TODO: Shutdown adapter...\n"); | |
2450 | } | |
2451 | ||
2452 | /* Update the RDB entry */ | |
2453 | priv->rx_queue.drv[i].host_addr = packet->dma_addr; | |
2454 | } | |
2455 | ||
2456 | static inline int ipw2100_corruption_check(struct ipw2100_priv *priv, int i) | |
2457 | { | |
2458 | struct ipw2100_status *status = &priv->status_queue.drv[i]; | |
2459 | struct ipw2100_rx *u = priv->rx_buffers[i].rxp; | |
2460 | u16 frame_type = status->status_fields & STATUS_TYPE_MASK; | |
2461 | ||
2462 | switch (frame_type) { | |
2463 | case COMMAND_STATUS_VAL: | |
2464 | return (status->frame_size != sizeof(u->rx_data.command)); | |
2465 | case STATUS_CHANGE_VAL: | |
2466 | return (status->frame_size != sizeof(u->rx_data.status)); | |
2467 | case HOST_NOTIFICATION_VAL: | |
2468 | return (status->frame_size < sizeof(u->rx_data.notification)); | |
2469 | case P80211_DATA_VAL: | |
2470 | case P8023_DATA_VAL: | |
2471 | #ifdef CONFIG_IPW2100_MONITOR | |
2472 | return 0; | |
2473 | #else | |
2474 | switch (WLAN_FC_GET_TYPE(u->rx_data.header.frame_ctl)) { | |
2475 | case IEEE80211_FTYPE_MGMT: | |
2476 | case IEEE80211_FTYPE_CTL: | |
2477 | return 0; | |
2478 | case IEEE80211_FTYPE_DATA: | |
2479 | return (status->frame_size > | |
2480 | IPW_MAX_802_11_PAYLOAD_LENGTH); | |
2481 | } | |
2482 | #endif | |
2483 | } | |
2484 | ||
2485 | return 1; | |
2486 | } | |
2487 | ||
2488 | /* | |
2489 | * ipw2100 interrupts are disabled at this point, and the ISR | |
2490 | * is the only code that calls this method. So, we do not need | |
2491 | * to play with any locks. | |
2492 | * | |
2493 | * RX Queue works as follows: | |
2494 | * | |
2495 | * Read index - firmware places packet in entry identified by the | |
2496 | * Read index and advances Read index. In this manner, | |
2497 | * Read index will always point to the next packet to | |
2498 | * be filled--but not yet valid. | |
2499 | * | |
2500 | * Write index - driver fills this entry with an unused RBD entry. | |
2501 | * This entry has not filled by the firmware yet. | |
2502 | * | |
2503 | * In between the W and R indexes are the RBDs that have been received | |
2504 | * but not yet processed. | |
2505 | * | |
2506 | * The process of handling packets will start at WRITE + 1 and advance | |
2507 | * until it reaches the READ index. | |
2508 | * | |
2509 | * The WRITE index is cached in the variable 'priv->rx_queue.next'. | |
2510 | * | |
2511 | */ | |
2512 | static inline void __ipw2100_rx_process(struct ipw2100_priv *priv) | |
2513 | { | |
2514 | struct ipw2100_bd_queue *rxq = &priv->rx_queue; | |
2515 | struct ipw2100_status_queue *sq = &priv->status_queue; | |
2516 | struct ipw2100_rx_packet *packet; | |
2517 | u16 frame_type; | |
2518 | u32 r, w, i, s; | |
2519 | struct ipw2100_rx *u; | |
2520 | struct ieee80211_rx_stats stats = { | |
2521 | .mac_time = jiffies, | |
2522 | }; | |
2523 | ||
2524 | read_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_READ_INDEX, &r); | |
2525 | read_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_WRITE_INDEX, &w); | |
2526 | ||
2527 | if (r >= rxq->entries) { | |
2528 | IPW_DEBUG_RX("exit - bad read index\n"); | |
2529 | return; | |
2530 | } | |
2531 | ||
2532 | i = (rxq->next + 1) % rxq->entries; | |
2533 | s = i; | |
2534 | while (i != r) { | |
2535 | /* IPW_DEBUG_RX("r = %d : w = %d : processing = %d\n", | |
2536 | r, rxq->next, i); */ | |
2537 | ||
2538 | packet = &priv->rx_buffers[i]; | |
2539 | ||
2540 | /* Sync the DMA for the STATUS buffer so CPU is sure to get | |
2541 | * the correct values */ | |
2542 | pci_dma_sync_single_for_cpu( | |
2543 | priv->pci_dev, | |
2544 | sq->nic + sizeof(struct ipw2100_status) * i, | |
2545 | sizeof(struct ipw2100_status), | |
2546 | PCI_DMA_FROMDEVICE); | |
2547 | ||
2548 | /* Sync the DMA for the RX buffer so CPU is sure to get | |
2549 | * the correct values */ | |
2550 | pci_dma_sync_single_for_cpu(priv->pci_dev, packet->dma_addr, | |
2551 | sizeof(struct ipw2100_rx), | |
2552 | PCI_DMA_FROMDEVICE); | |
2553 | ||
2554 | if (unlikely(ipw2100_corruption_check(priv, i))) { | |
2555 | ipw2100_corruption_detected(priv, i); | |
2556 | goto increment; | |
2557 | } | |
2558 | ||
2559 | u = packet->rxp; | |
2560 | frame_type = sq->drv[i].status_fields & | |
2561 | STATUS_TYPE_MASK; | |
2562 | stats.rssi = sq->drv[i].rssi + IPW2100_RSSI_TO_DBM; | |
2563 | stats.len = sq->drv[i].frame_size; | |
2564 | ||
2565 | stats.mask = 0; | |
2566 | if (stats.rssi != 0) | |
2567 | stats.mask |= IEEE80211_STATMASK_RSSI; | |
2568 | stats.freq = IEEE80211_24GHZ_BAND; | |
2569 | ||
2570 | IPW_DEBUG_RX( | |
2571 | "%s: '%s' frame type received (%d).\n", | |
2572 | priv->net_dev->name, frame_types[frame_type], | |
2573 | stats.len); | |
2574 | ||
2575 | switch (frame_type) { | |
2576 | case COMMAND_STATUS_VAL: | |
2577 | /* Reset Rx watchdog */ | |
2578 | isr_rx_complete_command( | |
2579 | priv, &u->rx_data.command); | |
2580 | break; | |
2581 | ||
2582 | case STATUS_CHANGE_VAL: | |
2583 | isr_status_change(priv, u->rx_data.status); | |
2584 | break; | |
2585 | ||
2586 | case P80211_DATA_VAL: | |
2587 | case P8023_DATA_VAL: | |
2588 | #ifdef CONFIG_IPW2100_MONITOR | |
2589 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { | |
2590 | isr_rx(priv, i, &stats); | |
2591 | break; | |
2592 | } | |
2593 | #endif | |
2594 | if (stats.len < sizeof(u->rx_data.header)) | |
2595 | break; | |
2596 | switch (WLAN_FC_GET_TYPE(u->rx_data.header. | |
2597 | frame_ctl)) { | |
2598 | case IEEE80211_FTYPE_MGMT: | |
2599 | ieee80211_rx_mgt(priv->ieee, | |
2600 | &u->rx_data.header, | |
2601 | &stats); | |
2602 | break; | |
2603 | ||
2604 | case IEEE80211_FTYPE_CTL: | |
2605 | break; | |
2606 | ||
2607 | case IEEE80211_FTYPE_DATA: | |
2608 | isr_rx(priv, i, &stats); | |
2609 | break; | |
2610 | ||
2611 | } | |
2612 | break; | |
2613 | } | |
2614 | ||
2615 | increment: | |
2616 | /* clear status field associated with this RBD */ | |
2617 | rxq->drv[i].status.info.field = 0; | |
2618 | ||
2619 | i = (i + 1) % rxq->entries; | |
2620 | } | |
2621 | ||
2622 | if (i != s) { | |
2623 | /* backtrack one entry, wrapping to end if at 0 */ | |
2624 | rxq->next = (i ? i : rxq->entries) - 1; | |
2625 | ||
2626 | write_register(priv->net_dev, | |
2627 | IPW_MEM_HOST_SHARED_RX_WRITE_INDEX, | |
2628 | rxq->next); | |
2629 | } | |
2630 | } | |
2631 | ||
2632 | ||
2633 | /* | |
2634 | * __ipw2100_tx_process | |
2635 | * | |
2636 | * This routine will determine whether the next packet on | |
2637 | * the fw_pend_list has been processed by the firmware yet. | |
2638 | * | |
2639 | * If not, then it does nothing and returns. | |
2640 | * | |
2641 | * If so, then it removes the item from the fw_pend_list, frees | |
2642 | * any associated storage, and places the item back on the | |
2643 | * free list of its source (either msg_free_list or tx_free_list) | |
2644 | * | |
2645 | * TX Queue works as follows: | |
2646 | * | |
2647 | * Read index - points to the next TBD that the firmware will | |
2648 | * process. The firmware will read the data, and once | |
2649 | * done processing, it will advance the Read index. | |
2650 | * | |
2651 | * Write index - driver fills this entry with an constructed TBD | |
2652 | * entry. The Write index is not advanced until the | |
2653 | * packet has been configured. | |
2654 | * | |
2655 | * In between the W and R indexes are the TBDs that have NOT been | |
2656 | * processed. Lagging behind the R index are packets that have | |
2657 | * been processed but have not been freed by the driver. | |
2658 | * | |
2659 | * In order to free old storage, an internal index will be maintained | |
2660 | * that points to the next packet to be freed. When all used | |
2661 | * packets have been freed, the oldest index will be the same as the | |
2662 | * firmware's read index. | |
2663 | * | |
2664 | * The OLDEST index is cached in the variable 'priv->tx_queue.oldest' | |
2665 | * | |
2666 | * Because the TBD structure can not contain arbitrary data, the | |
2667 | * driver must keep an internal queue of cached allocations such that | |
2668 | * it can put that data back into the tx_free_list and msg_free_list | |
2669 | * for use by future command and data packets. | |
2670 | * | |
2671 | */ | |
2672 | static inline int __ipw2100_tx_process(struct ipw2100_priv *priv) | |
2673 | { | |
2674 | struct ipw2100_bd_queue *txq = &priv->tx_queue; | |
2675 | struct ipw2100_bd *tbd; | |
2676 | struct list_head *element; | |
2677 | struct ipw2100_tx_packet *packet; | |
2678 | int descriptors_used; | |
2679 | int e, i; | |
2680 | u32 r, w, frag_num = 0; | |
2681 | ||
2682 | if (list_empty(&priv->fw_pend_list)) | |
2683 | return 0; | |
2684 | ||
2685 | element = priv->fw_pend_list.next; | |
2686 | ||
2687 | packet = list_entry(element, struct ipw2100_tx_packet, list); | |
2688 | tbd = &txq->drv[packet->index]; | |
2689 | ||
2690 | /* Determine how many TBD entries must be finished... */ | |
2691 | switch (packet->type) { | |
2692 | case COMMAND: | |
2693 | /* COMMAND uses only one slot; don't advance */ | |
2694 | descriptors_used = 1; | |
2695 | e = txq->oldest; | |
2696 | break; | |
2697 | ||
2698 | case DATA: | |
2699 | /* DATA uses two slots; advance and loop position. */ | |
2700 | descriptors_used = tbd->num_fragments; | |
2701 | frag_num = tbd->num_fragments - 1; | |
2702 | e = txq->oldest + frag_num; | |
2703 | e %= txq->entries; | |
2704 | break; | |
2705 | ||
2706 | default: | |
797b4f76 | 2707 | printk(KERN_WARNING DRV_NAME ": %s: Bad fw_pend_list entry!\n", |
2c86c275 JK |
2708 | priv->net_dev->name); |
2709 | return 0; | |
2710 | } | |
2711 | ||
2712 | /* if the last TBD is not done by NIC yet, then packet is | |
2713 | * not ready to be released. | |
2714 | * | |
2715 | */ | |
2716 | read_register(priv->net_dev, IPW_MEM_HOST_SHARED_TX_QUEUE_READ_INDEX, | |
2717 | &r); | |
2718 | read_register(priv->net_dev, IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX, | |
2719 | &w); | |
2720 | if (w != txq->next) | |
797b4f76 | 2721 | printk(KERN_WARNING DRV_NAME ": %s: write index mismatch\n", |
2c86c275 JK |
2722 | priv->net_dev->name); |
2723 | ||
2724 | /* | |
2725 | * txq->next is the index of the last packet written txq->oldest is | |
2726 | * the index of the r is the index of the next packet to be read by | |
2727 | * firmware | |
2728 | */ | |
2729 | ||
2730 | ||
2731 | /* | |
2732 | * Quick graphic to help you visualize the following | |
2733 | * if / else statement | |
2734 | * | |
2735 | * ===>| s---->|=============== | |
2736 | * e>| | |
2737 | * | a | b | c | d | e | f | g | h | i | j | k | l | |
2738 | * r---->| | |
2739 | * w | |
2740 | * | |
2741 | * w - updated by driver | |
2742 | * r - updated by firmware | |
2743 | * s - start of oldest BD entry (txq->oldest) | |
2744 | * e - end of oldest BD entry | |
2745 | * | |
2746 | */ | |
2747 | if (!((r <= w && (e < r || e >= w)) || (e < r && e >= w))) { | |
2748 | IPW_DEBUG_TX("exit - no processed packets ready to release.\n"); | |
2749 | return 0; | |
2750 | } | |
2751 | ||
2752 | list_del(element); | |
2753 | DEC_STAT(&priv->fw_pend_stat); | |
2754 | ||
2755 | #ifdef CONFIG_IPW_DEBUG | |
2756 | { | |
2757 | int i = txq->oldest; | |
2758 | IPW_DEBUG_TX( | |
aaa4d308 | 2759 | "TX%d V=%p P=%04X T=%04X L=%d\n", i, |
2c86c275 | 2760 | &txq->drv[i], |
aaa4d308 JB |
2761 | (u32)(txq->nic + i * sizeof(struct ipw2100_bd)), |
2762 | txq->drv[i].host_addr, | |
2c86c275 JK |
2763 | txq->drv[i].buf_length); |
2764 | ||
2765 | if (packet->type == DATA) { | |
2766 | i = (i + 1) % txq->entries; | |
2767 | ||
2768 | IPW_DEBUG_TX( | |
aaa4d308 | 2769 | "TX%d V=%p P=%04X T=%04X L=%d\n", i, |
2c86c275 | 2770 | &txq->drv[i], |
aaa4d308 JB |
2771 | (u32)(txq->nic + i * |
2772 | sizeof(struct ipw2100_bd)), | |
2773 | (u32)txq->drv[i].host_addr, | |
2c86c275 JK |
2774 | txq->drv[i].buf_length); |
2775 | } | |
2776 | } | |
2777 | #endif | |
2778 | ||
2779 | switch (packet->type) { | |
2780 | case DATA: | |
2781 | if (txq->drv[txq->oldest].status.info.fields.txType != 0) | |
797b4f76 | 2782 | printk(KERN_WARNING DRV_NAME ": %s: Queue mismatch. " |
2c86c275 JK |
2783 | "Expecting DATA TBD but pulled " |
2784 | "something else: ids %d=%d.\n", | |
2785 | priv->net_dev->name, txq->oldest, packet->index); | |
2786 | ||
2787 | /* DATA packet; we have to unmap and free the SKB */ | |
2788 | priv->ieee->stats.tx_packets++; | |
2789 | for (i = 0; i < frag_num; i++) { | |
2790 | tbd = &txq->drv[(packet->index + 1 + i) % | |
2791 | txq->entries]; | |
2792 | ||
2793 | IPW_DEBUG_TX( | |
2794 | "TX%d P=%08x L=%d\n", | |
2795 | (packet->index + 1 + i) % txq->entries, | |
2796 | tbd->host_addr, tbd->buf_length); | |
2797 | ||
2798 | pci_unmap_single(priv->pci_dev, | |
2799 | tbd->host_addr, | |
2800 | tbd->buf_length, | |
2801 | PCI_DMA_TODEVICE); | |
2802 | } | |
2803 | ||
2804 | priv->ieee->stats.tx_bytes += packet->info.d_struct.txb->payload_size; | |
2805 | ieee80211_txb_free(packet->info.d_struct.txb); | |
2806 | packet->info.d_struct.txb = NULL; | |
2807 | ||
2808 | list_add_tail(element, &priv->tx_free_list); | |
2809 | INC_STAT(&priv->tx_free_stat); | |
2810 | ||
2811 | /* We have a free slot in the Tx queue, so wake up the | |
2812 | * transmit layer if it is stopped. */ | |
2813 | if (priv->status & STATUS_ASSOCIATED && | |
2814 | netif_queue_stopped(priv->net_dev)) { | |
2815 | IPW_DEBUG_INFO(KERN_INFO | |
2816 | "%s: Waking net queue.\n", | |
2817 | priv->net_dev->name); | |
2818 | netif_wake_queue(priv->net_dev); | |
2819 | } | |
2820 | ||
2821 | /* A packet was processed by the hardware, so update the | |
2822 | * watchdog */ | |
2823 | priv->net_dev->trans_start = jiffies; | |
2824 | ||
2825 | break; | |
2826 | ||
2827 | case COMMAND: | |
2828 | if (txq->drv[txq->oldest].status.info.fields.txType != 1) | |
797b4f76 | 2829 | printk(KERN_WARNING DRV_NAME ": %s: Queue mismatch. " |
2c86c275 JK |
2830 | "Expecting COMMAND TBD but pulled " |
2831 | "something else: ids %d=%d.\n", | |
2832 | priv->net_dev->name, txq->oldest, packet->index); | |
2833 | ||
2834 | #ifdef CONFIG_IPW_DEBUG | |
2835 | if (packet->info.c_struct.cmd->host_command_reg < | |
2836 | sizeof(command_types) / sizeof(*command_types)) | |
2837 | IPW_DEBUG_TX( | |
2838 | "Command '%s (%d)' processed: %d.\n", | |
2839 | command_types[packet->info.c_struct.cmd->host_command_reg], | |
2840 | packet->info.c_struct.cmd->host_command_reg, | |
2841 | packet->info.c_struct.cmd->cmd_status_reg); | |
2842 | #endif | |
2843 | ||
2844 | list_add_tail(element, &priv->msg_free_list); | |
2845 | INC_STAT(&priv->msg_free_stat); | |
2846 | break; | |
2847 | } | |
2848 | ||
2849 | /* advance oldest used TBD pointer to start of next entry */ | |
2850 | txq->oldest = (e + 1) % txq->entries; | |
2851 | /* increase available TBDs number */ | |
2852 | txq->available += descriptors_used; | |
2853 | SET_STAT(&priv->txq_stat, txq->available); | |
2854 | ||
2855 | IPW_DEBUG_TX("packet latency (send to process) %ld jiffies\n", | |
2856 | jiffies - packet->jiffy_start); | |
2857 | ||
2858 | return (!list_empty(&priv->fw_pend_list)); | |
2859 | } | |
2860 | ||
2861 | ||
2862 | static inline void __ipw2100_tx_complete(struct ipw2100_priv *priv) | |
2863 | { | |
2864 | int i = 0; | |
2865 | ||
2866 | while (__ipw2100_tx_process(priv) && i < 200) i++; | |
2867 | ||
2868 | if (i == 200) { | |
19f7f742 | 2869 | printk(KERN_WARNING DRV_NAME ": " |
2c86c275 JK |
2870 | "%s: Driver is running slow (%d iters).\n", |
2871 | priv->net_dev->name, i); | |
2872 | } | |
2873 | } | |
2874 | ||
2875 | ||
19f7f742 | 2876 | static void ipw2100_tx_send_commands(struct ipw2100_priv *priv) |
2c86c275 JK |
2877 | { |
2878 | struct list_head *element; | |
2879 | struct ipw2100_tx_packet *packet; | |
2880 | struct ipw2100_bd_queue *txq = &priv->tx_queue; | |
2881 | struct ipw2100_bd *tbd; | |
2882 | int next = txq->next; | |
2883 | ||
2884 | while (!list_empty(&priv->msg_pend_list)) { | |
2885 | /* if there isn't enough space in TBD queue, then | |
2886 | * don't stuff a new one in. | |
2887 | * NOTE: 3 are needed as a command will take one, | |
2888 | * and there is a minimum of 2 that must be | |
2889 | * maintained between the r and w indexes | |
2890 | */ | |
2891 | if (txq->available <= 3) { | |
2892 | IPW_DEBUG_TX("no room in tx_queue\n"); | |
2893 | break; | |
2894 | } | |
2895 | ||
2896 | element = priv->msg_pend_list.next; | |
2897 | list_del(element); | |
2898 | DEC_STAT(&priv->msg_pend_stat); | |
2899 | ||
2900 | packet = list_entry(element, | |
2901 | struct ipw2100_tx_packet, list); | |
2902 | ||
2903 | IPW_DEBUG_TX("using TBD at virt=%p, phys=%p\n", | |
2904 | &txq->drv[txq->next], | |
2905 | (void*)(txq->nic + txq->next * | |
2906 | sizeof(struct ipw2100_bd))); | |
2907 | ||
2908 | packet->index = txq->next; | |
2909 | ||
2910 | tbd = &txq->drv[txq->next]; | |
2911 | ||
2912 | /* initialize TBD */ | |
2913 | tbd->host_addr = packet->info.c_struct.cmd_phys; | |
2914 | tbd->buf_length = sizeof(struct ipw2100_cmd_header); | |
2915 | /* not marking number of fragments causes problems | |
2916 | * with f/w debug version */ | |
2917 | tbd->num_fragments = 1; | |
2918 | tbd->status.info.field = | |
2919 | IPW_BD_STATUS_TX_FRAME_COMMAND | | |
2920 | IPW_BD_STATUS_TX_INTERRUPT_ENABLE; | |
2921 | ||
2922 | /* update TBD queue counters */ | |
2923 | txq->next++; | |
2924 | txq->next %= txq->entries; | |
2925 | txq->available--; | |
2926 | DEC_STAT(&priv->txq_stat); | |
2927 | ||
2928 | list_add_tail(element, &priv->fw_pend_list); | |
2929 | INC_STAT(&priv->fw_pend_stat); | |
2930 | } | |
2931 | ||
2932 | if (txq->next != next) { | |
2933 | /* kick off the DMA by notifying firmware the | |
2934 | * write index has moved; make sure TBD stores are sync'd */ | |
2935 | wmb(); | |
2936 | write_register(priv->net_dev, | |
2937 | IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX, | |
2938 | txq->next); | |
2939 | } | |
2940 | } | |
2941 | ||
2942 | ||
2943 | /* | |
19f7f742 | 2944 | * ipw2100_tx_send_data |
2c86c275 JK |
2945 | * |
2946 | */ | |
19f7f742 | 2947 | static void ipw2100_tx_send_data(struct ipw2100_priv *priv) |
2c86c275 JK |
2948 | { |
2949 | struct list_head *element; | |
2950 | struct ipw2100_tx_packet *packet; | |
2951 | struct ipw2100_bd_queue *txq = &priv->tx_queue; | |
2952 | struct ipw2100_bd *tbd; | |
2953 | int next = txq->next; | |
2954 | int i = 0; | |
2955 | struct ipw2100_data_header *ipw_hdr; | |
2956 | struct ieee80211_hdr *hdr; | |
2957 | ||
2958 | while (!list_empty(&priv->tx_pend_list)) { | |
2959 | /* if there isn't enough space in TBD queue, then | |
2960 | * don't stuff a new one in. | |
2961 | * NOTE: 4 are needed as a data will take two, | |
2962 | * and there is a minimum of 2 that must be | |
2963 | * maintained between the r and w indexes | |
2964 | */ | |
2965 | element = priv->tx_pend_list.next; | |
2966 | packet = list_entry(element, struct ipw2100_tx_packet, list); | |
2967 | ||
2968 | if (unlikely(1 + packet->info.d_struct.txb->nr_frags > | |
2969 | IPW_MAX_BDS)) { | |
2970 | /* TODO: Support merging buffers if more than | |
2971 | * IPW_MAX_BDS are used */ | |
2972 | IPW_DEBUG_INFO( | |
2973 | "%s: Maximum BD theshold exceeded. " | |
2974 | "Increase fragmentation level.\n", | |
2975 | priv->net_dev->name); | |
2976 | } | |
2977 | ||
2978 | if (txq->available <= 3 + | |
2979 | packet->info.d_struct.txb->nr_frags) { | |
2980 | IPW_DEBUG_TX("no room in tx_queue\n"); | |
2981 | break; | |
2982 | } | |
2983 | ||
2984 | list_del(element); | |
2985 | DEC_STAT(&priv->tx_pend_stat); | |
2986 | ||
2987 | tbd = &txq->drv[txq->next]; | |
2988 | ||
2989 | packet->index = txq->next; | |
2990 | ||
2991 | ipw_hdr = packet->info.d_struct.data; | |
2992 | hdr = (struct ieee80211_hdr *)packet->info.d_struct.txb-> | |
2993 | fragments[0]->data; | |
2994 | ||
2995 | if (priv->ieee->iw_mode == IW_MODE_INFRA) { | |
2996 | /* To DS: Addr1 = BSSID, Addr2 = SA, | |
2997 | Addr3 = DA */ | |
2998 | memcpy(ipw_hdr->src_addr, hdr->addr2, ETH_ALEN); | |
2999 | memcpy(ipw_hdr->dst_addr, hdr->addr3, ETH_ALEN); | |
3000 | } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) { | |
3001 | /* not From/To DS: Addr1 = DA, Addr2 = SA, | |
3002 | Addr3 = BSSID */ | |
3003 | memcpy(ipw_hdr->src_addr, hdr->addr2, ETH_ALEN); | |
3004 | memcpy(ipw_hdr->dst_addr, hdr->addr1, ETH_ALEN); | |
3005 | } | |
3006 | ||
3007 | ipw_hdr->host_command_reg = SEND; | |
3008 | ipw_hdr->host_command_reg1 = 0; | |
3009 | ||
3010 | /* For now we only support host based encryption */ | |
3011 | ipw_hdr->needs_encryption = 0; | |
3012 | ipw_hdr->encrypted = packet->info.d_struct.txb->encrypted; | |
3013 | if (packet->info.d_struct.txb->nr_frags > 1) | |
3014 | ipw_hdr->fragment_size = | |
3015 | packet->info.d_struct.txb->frag_size - IEEE80211_3ADDR_LEN; | |
3016 | else | |
3017 | ipw_hdr->fragment_size = 0; | |
3018 | ||
3019 | tbd->host_addr = packet->info.d_struct.data_phys; | |
3020 | tbd->buf_length = sizeof(struct ipw2100_data_header); | |
3021 | tbd->num_fragments = 1 + packet->info.d_struct.txb->nr_frags; | |
3022 | tbd->status.info.field = | |
3023 | IPW_BD_STATUS_TX_FRAME_802_3 | | |
3024 | IPW_BD_STATUS_TX_FRAME_NOT_LAST_FRAGMENT; | |
3025 | txq->next++; | |
3026 | txq->next %= txq->entries; | |
3027 | ||
3028 | IPW_DEBUG_TX( | |
3029 | "data header tbd TX%d P=%08x L=%d\n", | |
3030 | packet->index, tbd->host_addr, | |
3031 | tbd->buf_length); | |
3032 | #ifdef CONFIG_IPW_DEBUG | |
3033 | if (packet->info.d_struct.txb->nr_frags > 1) | |
3034 | IPW_DEBUG_FRAG("fragment Tx: %d frames\n", | |
3035 | packet->info.d_struct.txb->nr_frags); | |
3036 | #endif | |
3037 | ||
3038 | for (i = 0; i < packet->info.d_struct.txb->nr_frags; i++) { | |
3039 | tbd = &txq->drv[txq->next]; | |
3040 | if (i == packet->info.d_struct.txb->nr_frags - 1) | |
3041 | tbd->status.info.field = | |
3042 | IPW_BD_STATUS_TX_FRAME_802_3 | | |
3043 | IPW_BD_STATUS_TX_INTERRUPT_ENABLE; | |
3044 | else | |
3045 | tbd->status.info.field = | |
3046 | IPW_BD_STATUS_TX_FRAME_802_3 | | |
3047 | IPW_BD_STATUS_TX_FRAME_NOT_LAST_FRAGMENT; | |
3048 | ||
3049 | tbd->buf_length = packet->info.d_struct.txb-> | |
3050 | fragments[i]->len - IEEE80211_3ADDR_LEN; | |
3051 | ||
3052 | tbd->host_addr = pci_map_single( | |
3053 | priv->pci_dev, | |
3054 | packet->info.d_struct.txb->fragments[i]->data + | |
3055 | IEEE80211_3ADDR_LEN, | |
3056 | tbd->buf_length, | |
3057 | PCI_DMA_TODEVICE); | |
3058 | ||
3059 | IPW_DEBUG_TX( | |
3060 | "data frag tbd TX%d P=%08x L=%d\n", | |
3061 | txq->next, tbd->host_addr, tbd->buf_length); | |
3062 | ||
3063 | pci_dma_sync_single_for_device( | |
3064 | priv->pci_dev, tbd->host_addr, | |
3065 | tbd->buf_length, | |
3066 | PCI_DMA_TODEVICE); | |
3067 | ||
3068 | txq->next++; | |
3069 | txq->next %= txq->entries; | |
3070 | } | |
3071 | ||
3072 | txq->available -= 1 + packet->info.d_struct.txb->nr_frags; | |
3073 | SET_STAT(&priv->txq_stat, txq->available); | |
3074 | ||
3075 | list_add_tail(element, &priv->fw_pend_list); | |
3076 | INC_STAT(&priv->fw_pend_stat); | |
3077 | } | |
3078 | ||
3079 | if (txq->next != next) { | |
3080 | /* kick off the DMA by notifying firmware the | |
3081 | * write index has moved; make sure TBD stores are sync'd */ | |
3082 | write_register(priv->net_dev, | |
3083 | IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX, | |
3084 | txq->next); | |
3085 | } | |
3086 | return; | |
3087 | } | |
3088 | ||
3089 | static void ipw2100_irq_tasklet(struct ipw2100_priv *priv) | |
3090 | { | |
3091 | struct net_device *dev = priv->net_dev; | |
3092 | unsigned long flags; | |
3093 | u32 inta, tmp; | |
3094 | ||
3095 | spin_lock_irqsave(&priv->low_lock, flags); | |
3096 | ipw2100_disable_interrupts(priv); | |
3097 | ||
3098 | read_register(dev, IPW_REG_INTA, &inta); | |
3099 | ||
3100 | IPW_DEBUG_ISR("enter - INTA: 0x%08lX\n", | |
3101 | (unsigned long)inta & IPW_INTERRUPT_MASK); | |
3102 | ||
3103 | priv->in_isr++; | |
3104 | priv->interrupts++; | |
3105 | ||
3106 | /* We do not loop and keep polling for more interrupts as this | |
3107 | * is frowned upon and doesn't play nicely with other potentially | |
3108 | * chained IRQs */ | |
3109 | IPW_DEBUG_ISR("INTA: 0x%08lX\n", | |
3110 | (unsigned long)inta & IPW_INTERRUPT_MASK); | |
3111 | ||
3112 | if (inta & IPW2100_INTA_FATAL_ERROR) { | |
797b4f76 | 3113 | printk(KERN_WARNING DRV_NAME |
2c86c275 JK |
3114 | ": Fatal interrupt. Scheduling firmware restart.\n"); |
3115 | priv->inta_other++; | |
3116 | write_register( | |
3117 | dev, IPW_REG_INTA, | |
3118 | IPW2100_INTA_FATAL_ERROR); | |
3119 | ||
3120 | read_nic_dword(dev, IPW_NIC_FATAL_ERROR, &priv->fatal_error); | |
3121 | IPW_DEBUG_INFO("%s: Fatal error value: 0x%08X\n", | |
3122 | priv->net_dev->name, priv->fatal_error); | |
3123 | ||
3124 | read_nic_dword(dev, IPW_ERROR_ADDR(priv->fatal_error), &tmp); | |
3125 | IPW_DEBUG_INFO("%s: Fatal error address value: 0x%08X\n", | |
3126 | priv->net_dev->name, tmp); | |
3127 | ||
3128 | /* Wake up any sleeping jobs */ | |
3129 | schedule_reset(priv); | |
3130 | } | |
3131 | ||
3132 | if (inta & IPW2100_INTA_PARITY_ERROR) { | |
797b4f76 | 3133 | printk(KERN_ERR DRV_NAME ": ***** PARITY ERROR INTERRUPT !!!! \n"); |
2c86c275 JK |
3134 | priv->inta_other++; |
3135 | write_register( | |
3136 | dev, IPW_REG_INTA, | |
3137 | IPW2100_INTA_PARITY_ERROR); | |
3138 | } | |
3139 | ||
3140 | if (inta & IPW2100_INTA_RX_TRANSFER) { | |
3141 | IPW_DEBUG_ISR("RX interrupt\n"); | |
3142 | ||
3143 | priv->rx_interrupts++; | |
3144 | ||
3145 | write_register( | |
3146 | dev, IPW_REG_INTA, | |
3147 | IPW2100_INTA_RX_TRANSFER); | |
3148 | ||
3149 | __ipw2100_rx_process(priv); | |
3150 | __ipw2100_tx_complete(priv); | |
3151 | } | |
3152 | ||
3153 | if (inta & IPW2100_INTA_TX_TRANSFER) { | |
3154 | IPW_DEBUG_ISR("TX interrupt\n"); | |
3155 | ||
3156 | priv->tx_interrupts++; | |
3157 | ||
3158 | write_register(dev, IPW_REG_INTA, | |
3159 | IPW2100_INTA_TX_TRANSFER); | |
3160 | ||
3161 | __ipw2100_tx_complete(priv); | |
19f7f742 JB |
3162 | ipw2100_tx_send_commands(priv); |
3163 | ipw2100_tx_send_data(priv); | |
2c86c275 JK |
3164 | } |
3165 | ||
3166 | if (inta & IPW2100_INTA_TX_COMPLETE) { | |
3167 | IPW_DEBUG_ISR("TX complete\n"); | |
3168 | priv->inta_other++; | |
3169 | write_register( | |
3170 | dev, IPW_REG_INTA, | |
3171 | IPW2100_INTA_TX_COMPLETE); | |
3172 | ||
3173 | __ipw2100_tx_complete(priv); | |
3174 | } | |
3175 | ||
3176 | if (inta & IPW2100_INTA_EVENT_INTERRUPT) { | |
3177 | /* ipw2100_handle_event(dev); */ | |
3178 | priv->inta_other++; | |
3179 | write_register( | |
3180 | dev, IPW_REG_INTA, | |
3181 | IPW2100_INTA_EVENT_INTERRUPT); | |
3182 | } | |
3183 | ||
3184 | if (inta & IPW2100_INTA_FW_INIT_DONE) { | |
3185 | IPW_DEBUG_ISR("FW init done interrupt\n"); | |
3186 | priv->inta_other++; | |
3187 | ||
3188 | read_register(dev, IPW_REG_INTA, &tmp); | |
3189 | if (tmp & (IPW2100_INTA_FATAL_ERROR | | |
3190 | IPW2100_INTA_PARITY_ERROR)) { | |
3191 | write_register( | |
3192 | dev, IPW_REG_INTA, | |
3193 | IPW2100_INTA_FATAL_ERROR | | |
3194 | IPW2100_INTA_PARITY_ERROR); | |
3195 | } | |
3196 | ||
3197 | write_register(dev, IPW_REG_INTA, | |
3198 | IPW2100_INTA_FW_INIT_DONE); | |
3199 | } | |
3200 | ||
3201 | if (inta & IPW2100_INTA_STATUS_CHANGE) { | |
3202 | IPW_DEBUG_ISR("Status change interrupt\n"); | |
3203 | priv->inta_other++; | |
3204 | write_register( | |
3205 | dev, IPW_REG_INTA, | |
3206 | IPW2100_INTA_STATUS_CHANGE); | |
3207 | } | |
3208 | ||
3209 | if (inta & IPW2100_INTA_SLAVE_MODE_HOST_COMMAND_DONE) { | |
3210 | IPW_DEBUG_ISR("slave host mode interrupt\n"); | |
3211 | priv->inta_other++; | |
3212 | write_register( | |
3213 | dev, IPW_REG_INTA, | |
3214 | IPW2100_INTA_SLAVE_MODE_HOST_COMMAND_DONE); | |
3215 | } | |
3216 | ||
3217 | priv->in_isr--; | |
3218 | ipw2100_enable_interrupts(priv); | |
3219 | ||
3220 | spin_unlock_irqrestore(&priv->low_lock, flags); | |
3221 | ||
3222 | IPW_DEBUG_ISR("exit\n"); | |
3223 | } | |
3224 | ||
3225 | ||
3226 | static irqreturn_t ipw2100_interrupt(int irq, void *data, | |
3227 | struct pt_regs *regs) | |
3228 | { | |
3229 | struct ipw2100_priv *priv = data; | |
3230 | u32 inta, inta_mask; | |
3231 | ||
3232 | if (!data) | |
3233 | return IRQ_NONE; | |
3234 | ||
3235 | spin_lock(&priv->low_lock); | |
3236 | ||
3237 | /* We check to see if we should be ignoring interrupts before | |
3238 | * we touch the hardware. During ucode load if we try and handle | |
3239 | * an interrupt we can cause keyboard problems as well as cause | |
3240 | * the ucode to fail to initialize */ | |
3241 | if (!(priv->status & STATUS_INT_ENABLED)) { | |
3242 | /* Shared IRQ */ | |
3243 | goto none; | |
3244 | } | |
3245 | ||
3246 | read_register(priv->net_dev, IPW_REG_INTA_MASK, &inta_mask); | |
3247 | read_register(priv->net_dev, IPW_REG_INTA, &inta); | |
3248 | ||
3249 | if (inta == 0xFFFFFFFF) { | |
3250 | /* Hardware disappeared */ | |
797b4f76 | 3251 | printk(KERN_WARNING DRV_NAME ": IRQ INTA == 0xFFFFFFFF\n"); |
2c86c275 JK |
3252 | goto none; |
3253 | } | |
3254 | ||
3255 | inta &= IPW_INTERRUPT_MASK; | |
3256 | ||
3257 | if (!(inta & inta_mask)) { | |
3258 | /* Shared interrupt */ | |
3259 | goto none; | |
3260 | } | |
3261 | ||
3262 | /* We disable the hardware interrupt here just to prevent unneeded | |
3263 | * calls to be made. We disable this again within the actual | |
3264 | * work tasklet, so if another part of the code re-enables the | |
3265 | * interrupt, that is fine */ | |
3266 | ipw2100_disable_interrupts(priv); | |
3267 | ||
3268 | tasklet_schedule(&priv->irq_tasklet); | |
3269 | spin_unlock(&priv->low_lock); | |
3270 | ||
3271 | return IRQ_HANDLED; | |
3272 | none: | |
3273 | spin_unlock(&priv->low_lock); | |
3274 | return IRQ_NONE; | |
3275 | } | |
3276 | ||
3277 | static int ipw2100_tx(struct ieee80211_txb *txb, struct net_device *dev) | |
3278 | { | |
3279 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
3280 | struct list_head *element; | |
3281 | struct ipw2100_tx_packet *packet; | |
3282 | unsigned long flags; | |
3283 | ||
3284 | spin_lock_irqsave(&priv->low_lock, flags); | |
3285 | ||
3286 | if (!(priv->status & STATUS_ASSOCIATED)) { | |
3287 | IPW_DEBUG_INFO("Can not transmit when not connected.\n"); | |
3288 | priv->ieee->stats.tx_carrier_errors++; | |
3289 | netif_stop_queue(dev); | |
3290 | goto fail_unlock; | |
3291 | } | |
3292 | ||
3293 | if (list_empty(&priv->tx_free_list)) | |
3294 | goto fail_unlock; | |
3295 | ||
3296 | element = priv->tx_free_list.next; | |
3297 | packet = list_entry(element, struct ipw2100_tx_packet, list); | |
3298 | ||
3299 | packet->info.d_struct.txb = txb; | |
3300 | ||
3301 | IPW_DEBUG_TX("Sending fragment (%d bytes):\n", | |
3302 | txb->fragments[0]->len); | |
3303 | printk_buf(IPW_DL_TX, txb->fragments[0]->data, | |
3304 | txb->fragments[0]->len); | |
3305 | ||
3306 | packet->jiffy_start = jiffies; | |
3307 | ||
3308 | list_del(element); | |
3309 | DEC_STAT(&priv->tx_free_stat); | |
3310 | ||
3311 | list_add_tail(element, &priv->tx_pend_list); | |
3312 | INC_STAT(&priv->tx_pend_stat); | |
3313 | ||
19f7f742 | 3314 | ipw2100_tx_send_data(priv); |
2c86c275 JK |
3315 | |
3316 | spin_unlock_irqrestore(&priv->low_lock, flags); | |
3317 | return 0; | |
3318 | ||
3319 | fail_unlock: | |
3320 | netif_stop_queue(dev); | |
3321 | spin_unlock_irqrestore(&priv->low_lock, flags); | |
3322 | return 1; | |
3323 | } | |
3324 | ||
3325 | ||
3326 | static int ipw2100_msg_allocate(struct ipw2100_priv *priv) | |
3327 | { | |
3328 | int i, j, err = -EINVAL; | |
3329 | void *v; | |
3330 | dma_addr_t p; | |
3331 | ||
3332 | priv->msg_buffers = (struct ipw2100_tx_packet *)kmalloc( | |
3333 | IPW_COMMAND_POOL_SIZE * sizeof(struct ipw2100_tx_packet), | |
3334 | GFP_KERNEL); | |
3335 | if (!priv->msg_buffers) { | |
797b4f76 | 3336 | printk(KERN_ERR DRV_NAME ": %s: PCI alloc failed for msg " |
2c86c275 JK |
3337 | "buffers.\n", priv->net_dev->name); |
3338 | return -ENOMEM; | |
3339 | } | |
3340 | ||
3341 | for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++) { | |
3342 | v = pci_alloc_consistent( | |
3343 | priv->pci_dev, | |
3344 | sizeof(struct ipw2100_cmd_header), | |
3345 | &p); | |
3346 | if (!v) { | |
797b4f76 | 3347 | printk(KERN_ERR DRV_NAME ": " |
2c86c275 JK |
3348 | "%s: PCI alloc failed for msg " |
3349 | "buffers.\n", | |
3350 | priv->net_dev->name); | |
3351 | err = -ENOMEM; | |
3352 | break; | |
3353 | } | |
3354 | ||
3355 | memset(v, 0, sizeof(struct ipw2100_cmd_header)); | |
3356 | ||
3357 | priv->msg_buffers[i].type = COMMAND; | |
3358 | priv->msg_buffers[i].info.c_struct.cmd = | |
3359 | (struct ipw2100_cmd_header*)v; | |
3360 | priv->msg_buffers[i].info.c_struct.cmd_phys = p; | |
3361 | } | |
3362 | ||
3363 | if (i == IPW_COMMAND_POOL_SIZE) | |
3364 | return 0; | |
3365 | ||
3366 | for (j = 0; j < i; j++) { | |
3367 | pci_free_consistent( | |
3368 | priv->pci_dev, | |
3369 | sizeof(struct ipw2100_cmd_header), | |
3370 | priv->msg_buffers[j].info.c_struct.cmd, | |
3371 | priv->msg_buffers[j].info.c_struct.cmd_phys); | |
3372 | } | |
3373 | ||
3374 | kfree(priv->msg_buffers); | |
3375 | priv->msg_buffers = NULL; | |
3376 | ||
3377 | return err; | |
3378 | } | |
3379 | ||
3380 | static int ipw2100_msg_initialize(struct ipw2100_priv *priv) | |
3381 | { | |
3382 | int i; | |
3383 | ||
3384 | INIT_LIST_HEAD(&priv->msg_free_list); | |
3385 | INIT_LIST_HEAD(&priv->msg_pend_list); | |
3386 | ||
3387 | for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++) | |
3388 | list_add_tail(&priv->msg_buffers[i].list, &priv->msg_free_list); | |
3389 | SET_STAT(&priv->msg_free_stat, i); | |
3390 | ||
3391 | return 0; | |
3392 | } | |
3393 | ||
3394 | static void ipw2100_msg_free(struct ipw2100_priv *priv) | |
3395 | { | |
3396 | int i; | |
3397 | ||
3398 | if (!priv->msg_buffers) | |
3399 | return; | |
3400 | ||
3401 | for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++) { | |
3402 | pci_free_consistent(priv->pci_dev, | |
3403 | sizeof(struct ipw2100_cmd_header), | |
3404 | priv->msg_buffers[i].info.c_struct.cmd, | |
3405 | priv->msg_buffers[i].info.c_struct.cmd_phys); | |
3406 | } | |
3407 | ||
3408 | kfree(priv->msg_buffers); | |
3409 | priv->msg_buffers = NULL; | |
3410 | } | |
3411 | ||
edfc43f2 AM |
3412 | static ssize_t show_pci(struct device *d, struct device_attribute *attr, |
3413 | char *buf) | |
2c86c275 JK |
3414 | { |
3415 | struct pci_dev *pci_dev = container_of(d, struct pci_dev, dev); | |
3416 | char *out = buf; | |
3417 | int i, j; | |
3418 | u32 val; | |
3419 | ||
3420 | for (i = 0; i < 16; i++) { | |
3421 | out += sprintf(out, "[%08X] ", i * 16); | |
3422 | for (j = 0; j < 16; j += 4) { | |
3423 | pci_read_config_dword(pci_dev, i * 16 + j, &val); | |
3424 | out += sprintf(out, "%08X ", val); | |
3425 | } | |
3426 | out += sprintf(out, "\n"); | |
3427 | } | |
3428 | ||
3429 | return out - buf; | |
3430 | } | |
3431 | static DEVICE_ATTR(pci, S_IRUGO, show_pci, NULL); | |
3432 | ||
edfc43f2 AM |
3433 | static ssize_t show_cfg(struct device *d, struct device_attribute *attr, |
3434 | char *buf) | |
2c86c275 | 3435 | { |
edfc43f2 | 3436 | struct ipw2100_priv *p = d->driver_data; |
2c86c275 JK |
3437 | return sprintf(buf, "0x%08x\n", (int)p->config); |
3438 | } | |
3439 | static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL); | |
3440 | ||
edfc43f2 AM |
3441 | static ssize_t show_status(struct device *d, struct device_attribute *attr, |
3442 | char *buf) | |
2c86c275 | 3443 | { |
edfc43f2 | 3444 | struct ipw2100_priv *p = d->driver_data; |
2c86c275 JK |
3445 | return sprintf(buf, "0x%08x\n", (int)p->status); |
3446 | } | |
3447 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); | |
3448 | ||
edfc43f2 AM |
3449 | static ssize_t show_capability(struct device *d, struct device_attribute *attr, |
3450 | char *buf) | |
2c86c275 | 3451 | { |
edfc43f2 | 3452 | struct ipw2100_priv *p = d->driver_data; |
2c86c275 JK |
3453 | return sprintf(buf, "0x%08x\n", (int)p->capability); |
3454 | } | |
3455 | static DEVICE_ATTR(capability, S_IRUGO, show_capability, NULL); | |
3456 | ||
3457 | ||
3458 | #define IPW2100_REG(x) { IPW_ ##x, #x } | |
c4aee8c2 | 3459 | static const struct { |
2c86c275 JK |
3460 | u32 addr; |
3461 | const char *name; | |
3462 | } hw_data[] = { | |
3463 | IPW2100_REG(REG_GP_CNTRL), | |
3464 | IPW2100_REG(REG_GPIO), | |
3465 | IPW2100_REG(REG_INTA), | |
3466 | IPW2100_REG(REG_INTA_MASK), | |
3467 | IPW2100_REG(REG_RESET_REG), | |
3468 | }; | |
3469 | #define IPW2100_NIC(x, s) { x, #x, s } | |
c4aee8c2 | 3470 | static const struct { |
2c86c275 JK |
3471 | u32 addr; |
3472 | const char *name; | |
3473 | size_t size; | |
3474 | } nic_data[] = { | |
3475 | IPW2100_NIC(IPW2100_CONTROL_REG, 2), | |
3476 | IPW2100_NIC(0x210014, 1), | |
3477 | IPW2100_NIC(0x210000, 1), | |
3478 | }; | |
3479 | #define IPW2100_ORD(x, d) { IPW_ORD_ ##x, #x, d } | |
c4aee8c2 | 3480 | static const struct { |
2c86c275 JK |
3481 | u8 index; |
3482 | const char *name; | |
3483 | const char *desc; | |
3484 | } ord_data[] = { | |
3485 | IPW2100_ORD(STAT_TX_HOST_REQUESTS, "requested Host Tx's (MSDU)"), | |
3486 | IPW2100_ORD(STAT_TX_HOST_COMPLETE, "successful Host Tx's (MSDU)"), | |
3487 | IPW2100_ORD(STAT_TX_DIR_DATA, "successful Directed Tx's (MSDU)"), | |
3488 | IPW2100_ORD(STAT_TX_DIR_DATA1, "successful Directed Tx's (MSDU) @ 1MB"), | |
3489 | IPW2100_ORD(STAT_TX_DIR_DATA2, "successful Directed Tx's (MSDU) @ 2MB"), | |
3490 | IPW2100_ORD(STAT_TX_DIR_DATA5_5, "successful Directed Tx's (MSDU) @ 5_5MB"), | |
3491 | IPW2100_ORD(STAT_TX_DIR_DATA11, "successful Directed Tx's (MSDU) @ 11MB"), | |
3492 | IPW2100_ORD(STAT_TX_NODIR_DATA1, "successful Non_Directed Tx's (MSDU) @ 1MB"), | |
3493 | IPW2100_ORD(STAT_TX_NODIR_DATA2, "successful Non_Directed Tx's (MSDU) @ 2MB"), | |
3494 | IPW2100_ORD(STAT_TX_NODIR_DATA5_5, "successful Non_Directed Tx's (MSDU) @ 5.5MB"), | |
3495 | IPW2100_ORD(STAT_TX_NODIR_DATA11, "successful Non_Directed Tx's (MSDU) @ 11MB"), | |
3496 | IPW2100_ORD(STAT_NULL_DATA, "successful NULL data Tx's"), | |
3497 | IPW2100_ORD(STAT_TX_RTS, "successful Tx RTS"), | |
3498 | IPW2100_ORD(STAT_TX_CTS, "successful Tx CTS"), | |
3499 | IPW2100_ORD(STAT_TX_ACK, "successful Tx ACK"), | |
3500 | IPW2100_ORD(STAT_TX_ASSN, "successful Association Tx's"), | |
3501 | IPW2100_ORD(STAT_TX_ASSN_RESP, "successful Association response Tx's"), | |
3502 | IPW2100_ORD(STAT_TX_REASSN, "successful Reassociation Tx's"), | |
3503 | IPW2100_ORD(STAT_TX_REASSN_RESP, "successful Reassociation response Tx's"), | |
3504 | IPW2100_ORD(STAT_TX_PROBE, "probes successfully transmitted"), | |
3505 | IPW2100_ORD(STAT_TX_PROBE_RESP, "probe responses successfully transmitted"), | |
3506 | IPW2100_ORD(STAT_TX_BEACON, "tx beacon"), | |
3507 | IPW2100_ORD(STAT_TX_ATIM, "Tx ATIM"), | |
3508 | IPW2100_ORD(STAT_TX_DISASSN, "successful Disassociation TX"), | |
3509 | IPW2100_ORD(STAT_TX_AUTH, "successful Authentication Tx"), | |
3510 | IPW2100_ORD(STAT_TX_DEAUTH, "successful Deauthentication TX"), | |
3511 | IPW2100_ORD(STAT_TX_TOTAL_BYTES, "Total successful Tx data bytes"), | |
3512 | IPW2100_ORD(STAT_TX_RETRIES, "Tx retries"), | |
3513 | IPW2100_ORD(STAT_TX_RETRY1, "Tx retries at 1MBPS"), | |
3514 | IPW2100_ORD(STAT_TX_RETRY2, "Tx retries at 2MBPS"), | |
3515 | IPW2100_ORD(STAT_TX_RETRY5_5, "Tx retries at 5.5MBPS"), | |
3516 | IPW2100_ORD(STAT_TX_RETRY11, "Tx retries at 11MBPS"), | |
3517 | IPW2100_ORD(STAT_TX_FAILURES, "Tx Failures"), | |
3518 | IPW2100_ORD(STAT_TX_MAX_TRIES_IN_HOP,"times max tries in a hop failed"), | |
3519 | IPW2100_ORD(STAT_TX_DISASSN_FAIL, "times disassociation failed"), | |
3520 | IPW2100_ORD(STAT_TX_ERR_CTS, "missed/bad CTS frames"), | |
3521 | IPW2100_ORD(STAT_TX_ERR_ACK, "tx err due to acks"), | |
3522 | IPW2100_ORD(STAT_RX_HOST, "packets passed to host"), | |
3523 | IPW2100_ORD(STAT_RX_DIR_DATA, "directed packets"), | |
3524 | IPW2100_ORD(STAT_RX_DIR_DATA1, "directed packets at 1MB"), | |
3525 | IPW2100_ORD(STAT_RX_DIR_DATA2, "directed packets at 2MB"), | |
3526 | IPW2100_ORD(STAT_RX_DIR_DATA5_5, "directed packets at 5.5MB"), | |
3527 | IPW2100_ORD(STAT_RX_DIR_DATA11, "directed packets at 11MB"), | |
3528 | IPW2100_ORD(STAT_RX_NODIR_DATA,"nondirected packets"), | |
3529 | IPW2100_ORD(STAT_RX_NODIR_DATA1, "nondirected packets at 1MB"), | |
3530 | IPW2100_ORD(STAT_RX_NODIR_DATA2, "nondirected packets at 2MB"), | |
3531 | IPW2100_ORD(STAT_RX_NODIR_DATA5_5, "nondirected packets at 5.5MB"), | |
3532 | IPW2100_ORD(STAT_RX_NODIR_DATA11, "nondirected packets at 11MB"), | |
3533 | IPW2100_ORD(STAT_RX_NULL_DATA, "null data rx's"), | |
3534 | IPW2100_ORD(STAT_RX_RTS, "Rx RTS"), | |
3535 | IPW2100_ORD(STAT_RX_CTS, "Rx CTS"), | |
3536 | IPW2100_ORD(STAT_RX_ACK, "Rx ACK"), | |
3537 | IPW2100_ORD(STAT_RX_CFEND, "Rx CF End"), | |
3538 | IPW2100_ORD(STAT_RX_CFEND_ACK, "Rx CF End + CF Ack"), | |
3539 | IPW2100_ORD(STAT_RX_ASSN, "Association Rx's"), | |
3540 | IPW2100_ORD(STAT_RX_ASSN_RESP, "Association response Rx's"), | |
3541 | IPW2100_ORD(STAT_RX_REASSN, "Reassociation Rx's"), | |
3542 | IPW2100_ORD(STAT_RX_REASSN_RESP, "Reassociation response Rx's"), | |
3543 | IPW2100_ORD(STAT_RX_PROBE, "probe Rx's"), | |
3544 | IPW2100_ORD(STAT_RX_PROBE_RESP, "probe response Rx's"), | |
3545 | IPW2100_ORD(STAT_RX_BEACON, "Rx beacon"), | |
3546 | IPW2100_ORD(STAT_RX_ATIM, "Rx ATIM"), | |
3547 | IPW2100_ORD(STAT_RX_DISASSN, "disassociation Rx"), | |
3548 | IPW2100_ORD(STAT_RX_AUTH, "authentication Rx"), | |
3549 | IPW2100_ORD(STAT_RX_DEAUTH, "deauthentication Rx"), | |
3550 | IPW2100_ORD(STAT_RX_TOTAL_BYTES,"Total rx data bytes received"), | |
3551 | IPW2100_ORD(STAT_RX_ERR_CRC, "packets with Rx CRC error"), | |
3552 | IPW2100_ORD(STAT_RX_ERR_CRC1, "Rx CRC errors at 1MB"), | |
3553 | IPW2100_ORD(STAT_RX_ERR_CRC2, "Rx CRC errors at 2MB"), | |
3554 | IPW2100_ORD(STAT_RX_ERR_CRC5_5, "Rx CRC errors at 5.5MB"), | |
3555 | IPW2100_ORD(STAT_RX_ERR_CRC11, "Rx CRC errors at 11MB"), | |
3556 | IPW2100_ORD(STAT_RX_DUPLICATE1, "duplicate rx packets at 1MB"), | |
3557 | IPW2100_ORD(STAT_RX_DUPLICATE2, "duplicate rx packets at 2MB"), | |
3558 | IPW2100_ORD(STAT_RX_DUPLICATE5_5, "duplicate rx packets at 5.5MB"), | |
3559 | IPW2100_ORD(STAT_RX_DUPLICATE11, "duplicate rx packets at 11MB"), | |
3560 | IPW2100_ORD(STAT_RX_DUPLICATE, "duplicate rx packets"), | |
3561 | IPW2100_ORD(PERS_DB_LOCK, "locking fw permanent db"), | |
3562 | IPW2100_ORD(PERS_DB_SIZE, "size of fw permanent db"), | |
3563 | IPW2100_ORD(PERS_DB_ADDR, "address of fw permanent db"), | |
3564 | IPW2100_ORD(STAT_RX_INVALID_PROTOCOL, "rx frames with invalid protocol"), | |
3565 | IPW2100_ORD(SYS_BOOT_TIME, "Boot time"), | |
3566 | IPW2100_ORD(STAT_RX_NO_BUFFER, "rx frames rejected due to no buffer"), | |
3567 | IPW2100_ORD(STAT_RX_MISSING_FRAG, "rx frames dropped due to missing fragment"), | |
3568 | IPW2100_ORD(STAT_RX_ORPHAN_FRAG, "rx frames dropped due to non-sequential fragment"), | |
3569 | IPW2100_ORD(STAT_RX_ORPHAN_FRAME, "rx frames dropped due to unmatched 1st frame"), | |
3570 | IPW2100_ORD(STAT_RX_FRAG_AGEOUT, "rx frames dropped due to uncompleted frame"), | |
3571 | IPW2100_ORD(STAT_RX_ICV_ERRORS, "ICV errors during decryption"), | |
3572 | IPW2100_ORD(STAT_PSP_SUSPENSION,"times adapter suspended"), | |
3573 | IPW2100_ORD(STAT_PSP_BCN_TIMEOUT, "beacon timeout"), | |
3574 | IPW2100_ORD(STAT_PSP_POLL_TIMEOUT, "poll response timeouts"), | |
3575 | IPW2100_ORD(STAT_PSP_NONDIR_TIMEOUT, "timeouts waiting for last {broad,multi}cast pkt"), | |
3576 | IPW2100_ORD(STAT_PSP_RX_DTIMS, "PSP DTIMs received"), | |
3577 | IPW2100_ORD(STAT_PSP_RX_TIMS, "PSP TIMs received"), | |
3578 | IPW2100_ORD(STAT_PSP_STATION_ID,"PSP Station ID"), | |
3579 | IPW2100_ORD(LAST_ASSN_TIME, "RTC time of last association"), | |
3580 | IPW2100_ORD(STAT_PERCENT_MISSED_BCNS,"current calculation of % missed beacons"), | |
3581 | IPW2100_ORD(STAT_PERCENT_RETRIES,"current calculation of % missed tx retries"), | |
3582 | IPW2100_ORD(ASSOCIATED_AP_PTR, "0 if not associated, else pointer to AP table entry"), | |
3583 | IPW2100_ORD(AVAILABLE_AP_CNT, "AP's decsribed in the AP table"), | |
3584 | IPW2100_ORD(AP_LIST_PTR, "Ptr to list of available APs"), | |
3585 | IPW2100_ORD(STAT_AP_ASSNS, "associations"), | |
3586 | IPW2100_ORD(STAT_ASSN_FAIL, "association failures"), | |
3587 | IPW2100_ORD(STAT_ASSN_RESP_FAIL,"failures due to response fail"), | |
3588 | IPW2100_ORD(STAT_FULL_SCANS, "full scans"), | |
3589 | IPW2100_ORD(CARD_DISABLED, "Card Disabled"), | |
3590 | IPW2100_ORD(STAT_ROAM_INHIBIT, "times roaming was inhibited due to activity"), | |
3591 | IPW2100_ORD(RSSI_AT_ASSN, "RSSI of associated AP at time of association"), | |
3592 | IPW2100_ORD(STAT_ASSN_CAUSE1, "reassociation: no probe response or TX on hop"), | |
3593 | IPW2100_ORD(STAT_ASSN_CAUSE2, "reassociation: poor tx/rx quality"), | |
3594 | IPW2100_ORD(STAT_ASSN_CAUSE3, "reassociation: tx/rx quality (excessive AP load"), | |
3595 | IPW2100_ORD(STAT_ASSN_CAUSE4, "reassociation: AP RSSI level"), | |
3596 | IPW2100_ORD(STAT_ASSN_CAUSE5, "reassociations due to load leveling"), | |
3597 | IPW2100_ORD(STAT_AUTH_FAIL, "times authentication failed"), | |
3598 | IPW2100_ORD(STAT_AUTH_RESP_FAIL,"times authentication response failed"), | |
3599 | IPW2100_ORD(STATION_TABLE_CNT, "entries in association table"), | |
3600 | IPW2100_ORD(RSSI_AVG_CURR, "Current avg RSSI"), | |
3601 | IPW2100_ORD(POWER_MGMT_MODE, "Power mode - 0=CAM, 1=PSP"), | |
3602 | IPW2100_ORD(COUNTRY_CODE, "IEEE country code as recv'd from beacon"), | |
3603 | IPW2100_ORD(COUNTRY_CHANNELS, "channels suported by country"), | |
3604 | IPW2100_ORD(RESET_CNT, "adapter resets (warm)"), | |
3605 | IPW2100_ORD(BEACON_INTERVAL, "Beacon interval"), | |
3606 | IPW2100_ORD(ANTENNA_DIVERSITY, "TRUE if antenna diversity is disabled"), | |
3607 | IPW2100_ORD(DTIM_PERIOD, "beacon intervals between DTIMs"), | |
3608 | IPW2100_ORD(OUR_FREQ, "current radio freq lower digits - channel ID"), | |
3609 | IPW2100_ORD(RTC_TIME, "current RTC time"), | |
3610 | IPW2100_ORD(PORT_TYPE, "operating mode"), | |
3611 | IPW2100_ORD(CURRENT_TX_RATE, "current tx rate"), | |
3612 | IPW2100_ORD(SUPPORTED_RATES, "supported tx rates"), | |
3613 | IPW2100_ORD(ATIM_WINDOW, "current ATIM Window"), | |
3614 | IPW2100_ORD(BASIC_RATES, "basic tx rates"), | |
3615 | IPW2100_ORD(NIC_HIGHEST_RATE, "NIC highest tx rate"), | |
3616 | IPW2100_ORD(AP_HIGHEST_RATE, "AP highest tx rate"), | |
3617 | IPW2100_ORD(CAPABILITIES, "Management frame capability field"), | |
3618 | IPW2100_ORD(AUTH_TYPE, "Type of authentication"), | |
3619 | IPW2100_ORD(RADIO_TYPE, "Adapter card platform type"), | |
3620 | IPW2100_ORD(RTS_THRESHOLD, "Min packet length for RTS handshaking"), | |
3621 | IPW2100_ORD(INT_MODE, "International mode"), | |
3622 | IPW2100_ORD(FRAGMENTATION_THRESHOLD, "protocol frag threshold"), | |
3623 | IPW2100_ORD(EEPROM_SRAM_DB_BLOCK_START_ADDRESS, "EEPROM offset in SRAM"), | |
3624 | IPW2100_ORD(EEPROM_SRAM_DB_BLOCK_SIZE, "EEPROM size in SRAM"), | |
3625 | IPW2100_ORD(EEPROM_SKU_CAPABILITY, "EEPROM SKU Capability"), | |
3626 | IPW2100_ORD(EEPROM_IBSS_11B_CHANNELS, "EEPROM IBSS 11b channel set"), | |
3627 | IPW2100_ORD(MAC_VERSION, "MAC Version"), | |
3628 | IPW2100_ORD(MAC_REVISION, "MAC Revision"), | |
3629 | IPW2100_ORD(RADIO_VERSION, "Radio Version"), | |
3630 | IPW2100_ORD(NIC_MANF_DATE_TIME, "MANF Date/Time STAMP"), | |
3631 | IPW2100_ORD(UCODE_VERSION, "Ucode Version"), | |
3632 | }; | |
3633 | ||
3634 | ||
edfc43f2 AM |
3635 | static ssize_t show_registers(struct device *d, struct device_attribute *attr, |
3636 | char *buf) | |
2c86c275 JK |
3637 | { |
3638 | int i; | |
3639 | struct ipw2100_priv *priv = dev_get_drvdata(d); | |
3640 | struct net_device *dev = priv->net_dev; | |
3641 | char * out = buf; | |
3642 | u32 val = 0; | |
3643 | ||
3644 | out += sprintf(out, "%30s [Address ] : Hex\n", "Register"); | |
3645 | ||
3646 | for (i = 0; i < (sizeof(hw_data) / sizeof(*hw_data)); i++) { | |
3647 | read_register(dev, hw_data[i].addr, &val); | |
3648 | out += sprintf(out, "%30s [%08X] : %08X\n", | |
3649 | hw_data[i].name, hw_data[i].addr, val); | |
3650 | } | |
3651 | ||
3652 | return out - buf; | |
3653 | } | |
3654 | static DEVICE_ATTR(registers, S_IRUGO, show_registers, NULL); | |
3655 | ||
3656 | ||
edfc43f2 AM |
3657 | static ssize_t show_hardware(struct device *d, struct device_attribute *attr, |
3658 | char *buf) | |
2c86c275 JK |
3659 | { |
3660 | struct ipw2100_priv *priv = dev_get_drvdata(d); | |
3661 | struct net_device *dev = priv->net_dev; | |
3662 | char * out = buf; | |
3663 | int i; | |
3664 | ||
3665 | out += sprintf(out, "%30s [Address ] : Hex\n", "NIC entry"); | |
3666 | ||
3667 | for (i = 0; i < (sizeof(nic_data) / sizeof(*nic_data)); i++) { | |
3668 | u8 tmp8; | |
3669 | u16 tmp16; | |
3670 | u32 tmp32; | |
3671 | ||
3672 | switch (nic_data[i].size) { | |
3673 | case 1: | |
3674 | read_nic_byte(dev, nic_data[i].addr, &tmp8); | |
3675 | out += sprintf(out, "%30s [%08X] : %02X\n", | |
3676 | nic_data[i].name, nic_data[i].addr, | |
3677 | tmp8); | |
3678 | break; | |
3679 | case 2: | |
3680 | read_nic_word(dev, nic_data[i].addr, &tmp16); | |
3681 | out += sprintf(out, "%30s [%08X] : %04X\n", | |
3682 | nic_data[i].name, nic_data[i].addr, | |
3683 | tmp16); | |
3684 | break; | |
3685 | case 4: | |
3686 | read_nic_dword(dev, nic_data[i].addr, &tmp32); | |
3687 | out += sprintf(out, "%30s [%08X] : %08X\n", | |
3688 | nic_data[i].name, nic_data[i].addr, | |
3689 | tmp32); | |
3690 | break; | |
3691 | } | |
3692 | } | |
3693 | return out - buf; | |
3694 | } | |
3695 | static DEVICE_ATTR(hardware, S_IRUGO, show_hardware, NULL); | |
3696 | ||
3697 | ||
edfc43f2 AM |
3698 | static ssize_t show_memory(struct device *d, struct device_attribute *attr, |
3699 | char *buf) | |
2c86c275 JK |
3700 | { |
3701 | struct ipw2100_priv *priv = dev_get_drvdata(d); | |
3702 | struct net_device *dev = priv->net_dev; | |
3703 | static unsigned long loop = 0; | |
3704 | int len = 0; | |
3705 | u32 buffer[4]; | |
3706 | int i; | |
3707 | char line[81]; | |
3708 | ||
3709 | if (loop >= 0x30000) | |
3710 | loop = 0; | |
3711 | ||
3712 | /* sysfs provides us PAGE_SIZE buffer */ | |
3713 | while (len < PAGE_SIZE - 128 && loop < 0x30000) { | |
3714 | ||
3715 | if (priv->snapshot[0]) for (i = 0; i < 4; i++) | |
3716 | buffer[i] = *(u32 *)SNAPSHOT_ADDR(loop + i * 4); | |
3717 | else for (i = 0; i < 4; i++) | |
3718 | read_nic_dword(dev, loop + i * 4, &buffer[i]); | |
3719 | ||
3720 | if (priv->dump_raw) | |
3721 | len += sprintf(buf + len, | |
3722 | "%c%c%c%c" | |
3723 | "%c%c%c%c" | |
3724 | "%c%c%c%c" | |
3725 | "%c%c%c%c", | |
3726 | ((u8*)buffer)[0x0], | |
3727 | ((u8*)buffer)[0x1], | |
3728 | ((u8*)buffer)[0x2], | |
3729 | ((u8*)buffer)[0x3], | |
3730 | ((u8*)buffer)[0x4], | |
3731 | ((u8*)buffer)[0x5], | |
3732 | ((u8*)buffer)[0x6], | |
3733 | ((u8*)buffer)[0x7], | |
3734 | ((u8*)buffer)[0x8], | |
3735 | ((u8*)buffer)[0x9], | |
3736 | ((u8*)buffer)[0xa], | |
3737 | ((u8*)buffer)[0xb], | |
3738 | ((u8*)buffer)[0xc], | |
3739 | ((u8*)buffer)[0xd], | |
3740 | ((u8*)buffer)[0xe], | |
3741 | ((u8*)buffer)[0xf]); | |
3742 | else | |
3743 | len += sprintf(buf + len, "%s\n", | |
3744 | snprint_line(line, sizeof(line), | |
3745 | (u8*)buffer, 16, loop)); | |
3746 | loop += 16; | |
3747 | } | |
3748 | ||
3749 | return len; | |
3750 | } | |
3751 | ||
edfc43f2 AM |
3752 | static ssize_t store_memory(struct device *d, struct device_attribute *attr, |
3753 | const char *buf, size_t count) | |
2c86c275 JK |
3754 | { |
3755 | struct ipw2100_priv *priv = dev_get_drvdata(d); | |
3756 | struct net_device *dev = priv->net_dev; | |
3757 | const char *p = buf; | |
3758 | ||
3759 | if (count < 1) | |
3760 | return count; | |
3761 | ||
3762 | if (p[0] == '1' || | |
3763 | (count >= 2 && tolower(p[0]) == 'o' && tolower(p[1]) == 'n')) { | |
3764 | IPW_DEBUG_INFO("%s: Setting memory dump to RAW mode.\n", | |
3765 | dev->name); | |
3766 | priv->dump_raw = 1; | |
3767 | ||
3768 | } else if (p[0] == '0' || (count >= 2 && tolower(p[0]) == 'o' && | |
3769 | tolower(p[1]) == 'f')) { | |
3770 | IPW_DEBUG_INFO("%s: Setting memory dump to HEX mode.\n", | |
3771 | dev->name); | |
3772 | priv->dump_raw = 0; | |
3773 | ||
3774 | } else if (tolower(p[0]) == 'r') { | |
3775 | IPW_DEBUG_INFO("%s: Resetting firmware snapshot.\n", | |
3776 | dev->name); | |
3777 | ipw2100_snapshot_free(priv); | |
3778 | ||
3779 | } else | |
3780 | IPW_DEBUG_INFO("%s: Usage: 0|on = HEX, 1|off = RAW, " | |
3781 | "reset = clear memory snapshot\n", | |
3782 | dev->name); | |
3783 | ||
3784 | return count; | |
3785 | } | |
3786 | static DEVICE_ATTR(memory, S_IWUSR|S_IRUGO, show_memory, store_memory); | |
3787 | ||
3788 | ||
edfc43f2 AM |
3789 | static ssize_t show_ordinals(struct device *d, struct device_attribute *attr, |
3790 | char *buf) | |
2c86c275 JK |
3791 | { |
3792 | struct ipw2100_priv *priv = dev_get_drvdata(d); | |
3793 | u32 val = 0; | |
3794 | int len = 0; | |
3795 | u32 val_len; | |
3796 | static int loop = 0; | |
3797 | ||
3798 | if (loop >= sizeof(ord_data) / sizeof(*ord_data)) | |
3799 | loop = 0; | |
3800 | ||
3801 | /* sysfs provides us PAGE_SIZE buffer */ | |
3802 | while (len < PAGE_SIZE - 128 && | |
3803 | loop < (sizeof(ord_data) / sizeof(*ord_data))) { | |
3804 | ||
3805 | val_len = sizeof(u32); | |
3806 | ||
3807 | if (ipw2100_get_ordinal(priv, ord_data[loop].index, &val, | |
3808 | &val_len)) | |
3809 | len += sprintf(buf + len, "[0x%02X] = ERROR %s\n", | |
3810 | ord_data[loop].index, | |
3811 | ord_data[loop].desc); | |
3812 | else | |
3813 | len += sprintf(buf + len, "[0x%02X] = 0x%08X %s\n", | |
3814 | ord_data[loop].index, val, | |
3815 | ord_data[loop].desc); | |
3816 | loop++; | |
3817 | } | |
3818 | ||
3819 | return len; | |
3820 | } | |
3821 | static DEVICE_ATTR(ordinals, S_IRUGO, show_ordinals, NULL); | |
3822 | ||
3823 | ||
edfc43f2 AM |
3824 | static ssize_t show_stats(struct device *d, struct device_attribute *attr, |
3825 | char *buf) | |
2c86c275 JK |
3826 | { |
3827 | struct ipw2100_priv *priv = dev_get_drvdata(d); | |
3828 | char * out = buf; | |
3829 | ||
3830 | out += sprintf(out, "interrupts: %d {tx: %d, rx: %d, other: %d}\n", | |
3831 | priv->interrupts, priv->tx_interrupts, | |
3832 | priv->rx_interrupts, priv->inta_other); | |
3833 | out += sprintf(out, "firmware resets: %d\n", priv->resets); | |
3834 | out += sprintf(out, "firmware hangs: %d\n", priv->hangs); | |
3835 | #ifdef CONFIG_IPW_DEBUG | |
3836 | out += sprintf(out, "packet mismatch image: %s\n", | |
3837 | priv->snapshot[0] ? "YES" : "NO"); | |
3838 | #endif | |
3839 | ||
3840 | return out - buf; | |
3841 | } | |
3842 | static DEVICE_ATTR(stats, S_IRUGO, show_stats, NULL); | |
3843 | ||
3844 | ||
c4aee8c2 | 3845 | static int ipw2100_switch_mode(struct ipw2100_priv *priv, u32 mode) |
2c86c275 JK |
3846 | { |
3847 | int err; | |
3848 | ||
3849 | if (mode == priv->ieee->iw_mode) | |
3850 | return 0; | |
3851 | ||
3852 | err = ipw2100_disable_adapter(priv); | |
3853 | if (err) { | |
797b4f76 | 3854 | printk(KERN_ERR DRV_NAME ": %s: Could not disable adapter %d\n", |
2c86c275 JK |
3855 | priv->net_dev->name, err); |
3856 | return err; | |
3857 | } | |
3858 | ||
3859 | switch (mode) { | |
3860 | case IW_MODE_INFRA: | |
3861 | priv->net_dev->type = ARPHRD_ETHER; | |
3862 | break; | |
3863 | case IW_MODE_ADHOC: | |
3864 | priv->net_dev->type = ARPHRD_ETHER; | |
3865 | break; | |
3866 | #ifdef CONFIG_IPW2100_MONITOR | |
3867 | case IW_MODE_MONITOR: | |
3868 | priv->last_mode = priv->ieee->iw_mode; | |
3869 | priv->net_dev->type = ARPHRD_IEEE80211; | |
3870 | break; | |
3871 | #endif /* CONFIG_IPW2100_MONITOR */ | |
3872 | } | |
3873 | ||
3874 | priv->ieee->iw_mode = mode; | |
3875 | ||
3876 | #ifdef CONFIG_PM | |
3877 | /* Indicate ipw2100_download_firmware download firmware | |
3878 | * from disk instead of memory. */ | |
3879 | ipw2100_firmware.version = 0; | |
3880 | #endif | |
3881 | ||
3882 | printk(KERN_INFO "%s: Reseting on mode change.\n", | |
3883 | priv->net_dev->name); | |
3884 | priv->reset_backoff = 0; | |
3885 | schedule_reset(priv); | |
3886 | ||
3887 | return 0; | |
3888 | } | |
3889 | ||
edfc43f2 AM |
3890 | static ssize_t show_internals(struct device *d, struct device_attribute *attr, |
3891 | char *buf) | |
2c86c275 JK |
3892 | { |
3893 | struct ipw2100_priv *priv = dev_get_drvdata(d); | |
3894 | int len = 0; | |
3895 | ||
3896 | #define DUMP_VAR(x,y) len += sprintf(buf + len, # x ": %" # y "\n", priv-> x) | |
3897 | ||
3898 | if (priv->status & STATUS_ASSOCIATED) | |
3899 | len += sprintf(buf + len, "connected: %lu\n", | |
3900 | get_seconds() - priv->connect_start); | |
3901 | else | |
3902 | len += sprintf(buf + len, "not connected\n"); | |
3903 | ||
3904 | DUMP_VAR(ieee->crypt[priv->ieee->tx_keyidx], p); | |
3905 | DUMP_VAR(status, 08lx); | |
3906 | DUMP_VAR(config, 08lx); | |
3907 | DUMP_VAR(capability, 08lx); | |
3908 | ||
3909 | len += sprintf(buf + len, "last_rtc: %lu\n", (unsigned long)priv->last_rtc); | |
3910 | ||
3911 | DUMP_VAR(fatal_error, d); | |
3912 | DUMP_VAR(stop_hang_check, d); | |
3913 | DUMP_VAR(stop_rf_kill, d); | |
3914 | DUMP_VAR(messages_sent, d); | |
3915 | ||
3916 | DUMP_VAR(tx_pend_stat.value, d); | |
3917 | DUMP_VAR(tx_pend_stat.hi, d); | |
3918 | ||
3919 | DUMP_VAR(tx_free_stat.value, d); | |
3920 | DUMP_VAR(tx_free_stat.lo, d); | |
3921 | ||
3922 | DUMP_VAR(msg_free_stat.value, d); | |
3923 | DUMP_VAR(msg_free_stat.lo, d); | |
3924 | ||
3925 | DUMP_VAR(msg_pend_stat.value, d); | |
3926 | DUMP_VAR(msg_pend_stat.hi, d); | |
3927 | ||
3928 | DUMP_VAR(fw_pend_stat.value, d); | |
3929 | DUMP_VAR(fw_pend_stat.hi, d); | |
3930 | ||
3931 | DUMP_VAR(txq_stat.value, d); | |
3932 | DUMP_VAR(txq_stat.lo, d); | |
3933 | ||
3934 | DUMP_VAR(ieee->scans, d); | |
3935 | DUMP_VAR(reset_backoff, d); | |
3936 | ||
3937 | return len; | |
3938 | } | |
3939 | static DEVICE_ATTR(internals, S_IRUGO, show_internals, NULL); | |
3940 | ||
3941 | ||
edfc43f2 AM |
3942 | static ssize_t show_bssinfo(struct device *d, struct device_attribute *attr, |
3943 | char *buf) | |
2c86c275 JK |
3944 | { |
3945 | struct ipw2100_priv *priv = dev_get_drvdata(d); | |
3946 | char essid[IW_ESSID_MAX_SIZE + 1]; | |
3947 | u8 bssid[ETH_ALEN]; | |
3948 | u32 chan = 0; | |
3949 | char * out = buf; | |
3950 | int length; | |
3951 | int ret; | |
3952 | ||
3953 | memset(essid, 0, sizeof(essid)); | |
3954 | memset(bssid, 0, sizeof(bssid)); | |
3955 | ||
3956 | length = IW_ESSID_MAX_SIZE; | |
3957 | ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_SSID, essid, &length); | |
3958 | if (ret) | |
3959 | IPW_DEBUG_INFO("failed querying ordinals at line %d\n", | |
3960 | __LINE__); | |
3961 | ||
3962 | length = sizeof(bssid); | |
3963 | ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID, | |
3964 | bssid, &length); | |
3965 | if (ret) | |
3966 | IPW_DEBUG_INFO("failed querying ordinals at line %d\n", | |
3967 | __LINE__); | |
3968 | ||
3969 | length = sizeof(u32); | |
3970 | ret = ipw2100_get_ordinal(priv, IPW_ORD_OUR_FREQ, &chan, &length); | |
3971 | if (ret) | |
3972 | IPW_DEBUG_INFO("failed querying ordinals at line %d\n", | |
3973 | __LINE__); | |
3974 | ||
3975 | out += sprintf(out, "ESSID: %s\n", essid); | |
3976 | out += sprintf(out, "BSSID: %02x:%02x:%02x:%02x:%02x:%02x\n", | |
3977 | bssid[0], bssid[1], bssid[2], | |
3978 | bssid[3], bssid[4], bssid[5]); | |
3979 | out += sprintf(out, "Channel: %d\n", chan); | |
3980 | ||
3981 | return out - buf; | |
3982 | } | |
3983 | static DEVICE_ATTR(bssinfo, S_IRUGO, show_bssinfo, NULL); | |
3984 | ||
3985 | ||
2c86c275 JK |
3986 | #ifdef CONFIG_IPW_DEBUG |
3987 | static ssize_t show_debug_level(struct device_driver *d, char *buf) | |
3988 | { | |
3989 | return sprintf(buf, "0x%08X\n", ipw2100_debug_level); | |
3990 | } | |
3991 | ||
3992 | static ssize_t store_debug_level(struct device_driver *d, const char *buf, | |
3993 | size_t count) | |
3994 | { | |
3995 | char *p = (char *)buf; | |
3996 | u32 val; | |
3997 | ||
3998 | if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') { | |
3999 | p++; | |
4000 | if (p[0] == 'x' || p[0] == 'X') | |
4001 | p++; | |
4002 | val = simple_strtoul(p, &p, 16); | |
4003 | } else | |
4004 | val = simple_strtoul(p, &p, 10); | |
4005 | if (p == buf) | |
4006 | IPW_DEBUG_INFO(DRV_NAME | |
4007 | ": %s is not in hex or decimal form.\n", buf); | |
4008 | else | |
4009 | ipw2100_debug_level = val; | |
4010 | ||
4011 | return strnlen(buf, count); | |
4012 | } | |
4013 | static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, show_debug_level, | |
4014 | store_debug_level); | |
4015 | #endif /* CONFIG_IPW_DEBUG */ | |
4016 | ||
4017 | ||
edfc43f2 AM |
4018 | static ssize_t show_fatal_error(struct device *d, |
4019 | struct device_attribute *attr, char *buf) | |
2c86c275 JK |
4020 | { |
4021 | struct ipw2100_priv *priv = dev_get_drvdata(d); | |
4022 | char *out = buf; | |
4023 | int i; | |
4024 | ||
4025 | if (priv->fatal_error) | |
4026 | out += sprintf(out, "0x%08X\n", | |
4027 | priv->fatal_error); | |
4028 | else | |
4029 | out += sprintf(out, "0\n"); | |
4030 | ||
4031 | for (i = 1; i <= IPW2100_ERROR_QUEUE; i++) { | |
4032 | if (!priv->fatal_errors[(priv->fatal_index - i) % | |
4033 | IPW2100_ERROR_QUEUE]) | |
4034 | continue; | |
4035 | ||
4036 | out += sprintf(out, "%d. 0x%08X\n", i, | |
4037 | priv->fatal_errors[(priv->fatal_index - i) % | |
4038 | IPW2100_ERROR_QUEUE]); | |
4039 | } | |
4040 | ||
4041 | return out - buf; | |
4042 | } | |
4043 | ||
edfc43f2 AM |
4044 | static ssize_t store_fatal_error(struct device *d, |
4045 | struct device_attribute *attr, const char *buf, size_t count) | |
2c86c275 JK |
4046 | { |
4047 | struct ipw2100_priv *priv = dev_get_drvdata(d); | |
4048 | schedule_reset(priv); | |
4049 | return count; | |
4050 | } | |
4051 | static DEVICE_ATTR(fatal_error, S_IWUSR|S_IRUGO, show_fatal_error, store_fatal_error); | |
4052 | ||
4053 | ||
edfc43f2 AM |
4054 | static ssize_t show_scan_age(struct device *d, struct device_attribute *attr, |
4055 | char *buf) | |
2c86c275 JK |
4056 | { |
4057 | struct ipw2100_priv *priv = dev_get_drvdata(d); | |
4058 | return sprintf(buf, "%d\n", priv->ieee->scan_age); | |
4059 | } | |
4060 | ||
edfc43f2 AM |
4061 | static ssize_t store_scan_age(struct device *d, struct device_attribute *attr, |
4062 | const char *buf, size_t count) | |
2c86c275 JK |
4063 | { |
4064 | struct ipw2100_priv *priv = dev_get_drvdata(d); | |
4065 | struct net_device *dev = priv->net_dev; | |
4066 | char buffer[] = "00000000"; | |
4067 | unsigned long len = | |
4068 | (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1; | |
4069 | unsigned long val; | |
4070 | char *p = buffer; | |
4071 | ||
4072 | IPW_DEBUG_INFO("enter\n"); | |
4073 | ||
4074 | strncpy(buffer, buf, len); | |
4075 | buffer[len] = 0; | |
4076 | ||
4077 | if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') { | |
4078 | p++; | |
4079 | if (p[0] == 'x' || p[0] == 'X') | |
4080 | p++; | |
4081 | val = simple_strtoul(p, &p, 16); | |
4082 | } else | |
4083 | val = simple_strtoul(p, &p, 10); | |
4084 | if (p == buffer) { | |
4085 | IPW_DEBUG_INFO("%s: user supplied invalid value.\n", | |
4086 | dev->name); | |
4087 | } else { | |
4088 | priv->ieee->scan_age = val; | |
4089 | IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age); | |
4090 | } | |
4091 | ||
4092 | IPW_DEBUG_INFO("exit\n"); | |
4093 | return len; | |
4094 | } | |
4095 | static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age); | |
4096 | ||
4097 | ||
edfc43f2 AM |
4098 | static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr, |
4099 | char *buf) | |
2c86c275 JK |
4100 | { |
4101 | /* 0 - RF kill not enabled | |
4102 | 1 - SW based RF kill active (sysfs) | |
4103 | 2 - HW based RF kill active | |
4104 | 3 - Both HW and SW baed RF kill active */ | |
4105 | struct ipw2100_priv *priv = (struct ipw2100_priv *)d->driver_data; | |
4106 | int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) | | |
4107 | (rf_kill_active(priv) ? 0x2 : 0x0); | |
4108 | return sprintf(buf, "%i\n", val); | |
4109 | } | |
4110 | ||
4111 | static int ipw_radio_kill_sw(struct ipw2100_priv *priv, int disable_radio) | |
4112 | { | |
4113 | if ((disable_radio ? 1 : 0) == | |
4114 | (priv->status & STATUS_RF_KILL_SW ? 1 : 0)) | |
4115 | return 0 ; | |
4116 | ||
4117 | IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n", | |
4118 | disable_radio ? "OFF" : "ON"); | |
4119 | ||
4120 | down(&priv->action_sem); | |
4121 | ||
4122 | if (disable_radio) { | |
4123 | priv->status |= STATUS_RF_KILL_SW; | |
4124 | ipw2100_down(priv); | |
4125 | } else { | |
4126 | priv->status &= ~STATUS_RF_KILL_SW; | |
4127 | if (rf_kill_active(priv)) { | |
4128 | IPW_DEBUG_RF_KILL("Can not turn radio back on - " | |
4129 | "disabled by HW switch\n"); | |
4130 | /* Make sure the RF_KILL check timer is running */ | |
4131 | priv->stop_rf_kill = 0; | |
4132 | cancel_delayed_work(&priv->rf_kill); | |
4133 | queue_delayed_work(priv->workqueue, &priv->rf_kill, | |
4134 | HZ); | |
4135 | } else | |
4136 | schedule_reset(priv); | |
4137 | } | |
4138 | ||
4139 | up(&priv->action_sem); | |
4140 | return 1; | |
4141 | } | |
4142 | ||
edfc43f2 AM |
4143 | static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr, |
4144 | const char *buf, size_t count) | |
2c86c275 JK |
4145 | { |
4146 | struct ipw2100_priv *priv = dev_get_drvdata(d); | |
4147 | ipw_radio_kill_sw(priv, buf[0] == '1'); | |
4148 | return count; | |
4149 | } | |
4150 | static DEVICE_ATTR(rf_kill, S_IWUSR|S_IRUGO, show_rf_kill, store_rf_kill); | |
4151 | ||
4152 | ||
4153 | static struct attribute *ipw2100_sysfs_entries[] = { | |
4154 | &dev_attr_hardware.attr, | |
4155 | &dev_attr_registers.attr, | |
4156 | &dev_attr_ordinals.attr, | |
4157 | &dev_attr_pci.attr, | |
4158 | &dev_attr_stats.attr, | |
4159 | &dev_attr_internals.attr, | |
4160 | &dev_attr_bssinfo.attr, | |
4161 | &dev_attr_memory.attr, | |
4162 | &dev_attr_scan_age.attr, | |
4163 | &dev_attr_fatal_error.attr, | |
4164 | &dev_attr_rf_kill.attr, | |
4165 | &dev_attr_cfg.attr, | |
4166 | &dev_attr_status.attr, | |
4167 | &dev_attr_capability.attr, | |
4168 | NULL, | |
4169 | }; | |
4170 | ||
4171 | static struct attribute_group ipw2100_attribute_group = { | |
4172 | .attrs = ipw2100_sysfs_entries, | |
4173 | }; | |
4174 | ||
4175 | ||
4176 | static int status_queue_allocate(struct ipw2100_priv *priv, int entries) | |
4177 | { | |
4178 | struct ipw2100_status_queue *q = &priv->status_queue; | |
4179 | ||
4180 | IPW_DEBUG_INFO("enter\n"); | |
4181 | ||
4182 | q->size = entries * sizeof(struct ipw2100_status); | |
4183 | q->drv = (struct ipw2100_status *)pci_alloc_consistent( | |
4184 | priv->pci_dev, q->size, &q->nic); | |
4185 | if (!q->drv) { | |
4186 | IPW_DEBUG_WARNING( | |
4187 | "Can not allocate status queue.\n"); | |
4188 | return -ENOMEM; | |
4189 | } | |
4190 | ||
4191 | memset(q->drv, 0, q->size); | |
4192 | ||
4193 | IPW_DEBUG_INFO("exit\n"); | |
4194 | ||
4195 | return 0; | |
4196 | } | |
4197 | ||
4198 | static void status_queue_free(struct ipw2100_priv *priv) | |
4199 | { | |
4200 | IPW_DEBUG_INFO("enter\n"); | |
4201 | ||
4202 | if (priv->status_queue.drv) { | |
4203 | pci_free_consistent( | |
4204 | priv->pci_dev, priv->status_queue.size, | |
4205 | priv->status_queue.drv, priv->status_queue.nic); | |
4206 | priv->status_queue.drv = NULL; | |
4207 | } | |
4208 | ||
4209 | IPW_DEBUG_INFO("exit\n"); | |
4210 | } | |
4211 | ||
4212 | static int bd_queue_allocate(struct ipw2100_priv *priv, | |
4213 | struct ipw2100_bd_queue *q, int entries) | |
4214 | { | |
4215 | IPW_DEBUG_INFO("enter\n"); | |
4216 | ||
4217 | memset(q, 0, sizeof(struct ipw2100_bd_queue)); | |
4218 | ||
4219 | q->entries = entries; | |
4220 | q->size = entries * sizeof(struct ipw2100_bd); | |
4221 | q->drv = pci_alloc_consistent(priv->pci_dev, q->size, &q->nic); | |
4222 | if (!q->drv) { | |
4223 | IPW_DEBUG_INFO("can't allocate shared memory for buffer descriptors\n"); | |
4224 | return -ENOMEM; | |
4225 | } | |
4226 | memset(q->drv, 0, q->size); | |
4227 | ||
4228 | IPW_DEBUG_INFO("exit\n"); | |
4229 | ||
4230 | return 0; | |
4231 | } | |
4232 | ||
4233 | static void bd_queue_free(struct ipw2100_priv *priv, | |
4234 | struct ipw2100_bd_queue *q) | |
4235 | { | |
4236 | IPW_DEBUG_INFO("enter\n"); | |
4237 | ||
4238 | if (!q) | |
4239 | return; | |
4240 | ||
4241 | if (q->drv) { | |
4242 | pci_free_consistent(priv->pci_dev, | |
4243 | q->size, q->drv, q->nic); | |
4244 | q->drv = NULL; | |
4245 | } | |
4246 | ||
4247 | IPW_DEBUG_INFO("exit\n"); | |
4248 | } | |
4249 | ||
4250 | static void bd_queue_initialize( | |
4251 | struct ipw2100_priv *priv, struct ipw2100_bd_queue * q, | |
4252 | u32 base, u32 size, u32 r, u32 w) | |
4253 | { | |
4254 | IPW_DEBUG_INFO("enter\n"); | |
4255 | ||
aaa4d308 | 4256 | IPW_DEBUG_INFO("initializing bd queue at virt=%p, phys=%08x\n", q->drv, (u32)q->nic); |
2c86c275 JK |
4257 | |
4258 | write_register(priv->net_dev, base, q->nic); | |
4259 | write_register(priv->net_dev, size, q->entries); | |
4260 | write_register(priv->net_dev, r, q->oldest); | |
4261 | write_register(priv->net_dev, w, q->next); | |
4262 | ||
4263 | IPW_DEBUG_INFO("exit\n"); | |
4264 | } | |
4265 | ||
4266 | static void ipw2100_kill_workqueue(struct ipw2100_priv *priv) | |
4267 | { | |
4268 | if (priv->workqueue) { | |
4269 | priv->stop_rf_kill = 1; | |
4270 | priv->stop_hang_check = 1; | |
4271 | cancel_delayed_work(&priv->reset_work); | |
4272 | cancel_delayed_work(&priv->security_work); | |
4273 | cancel_delayed_work(&priv->wx_event_work); | |
4274 | cancel_delayed_work(&priv->hang_check); | |
4275 | cancel_delayed_work(&priv->rf_kill); | |
4276 | destroy_workqueue(priv->workqueue); | |
4277 | priv->workqueue = NULL; | |
4278 | } | |
4279 | } | |
4280 | ||
4281 | static int ipw2100_tx_allocate(struct ipw2100_priv *priv) | |
4282 | { | |
4283 | int i, j, err = -EINVAL; | |
4284 | void *v; | |
4285 | dma_addr_t p; | |
4286 | ||
4287 | IPW_DEBUG_INFO("enter\n"); | |
4288 | ||
4289 | err = bd_queue_allocate(priv, &priv->tx_queue, TX_QUEUE_LENGTH); | |
4290 | if (err) { | |
4291 | IPW_DEBUG_ERROR("%s: failed bd_queue_allocate\n", | |
4292 | priv->net_dev->name); | |
4293 | return err; | |
4294 | } | |
4295 | ||
4296 | priv->tx_buffers = (struct ipw2100_tx_packet *)kmalloc( | |
4297 | TX_PENDED_QUEUE_LENGTH * sizeof(struct ipw2100_tx_packet), | |
4298 | GFP_ATOMIC); | |
4299 | if (!priv->tx_buffers) { | |
797b4f76 | 4300 | printk(KERN_ERR DRV_NAME ": %s: alloc failed form tx buffers.\n", |
2c86c275 JK |
4301 | priv->net_dev->name); |
4302 | bd_queue_free(priv, &priv->tx_queue); | |
4303 | return -ENOMEM; | |
4304 | } | |
4305 | ||
4306 | for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) { | |
4307 | v = pci_alloc_consistent( | |
4308 | priv->pci_dev, sizeof(struct ipw2100_data_header), &p); | |
4309 | if (!v) { | |
797b4f76 | 4310 | printk(KERN_ERR DRV_NAME ": %s: PCI alloc failed for tx " |
2c86c275 JK |
4311 | "buffers.\n", priv->net_dev->name); |
4312 | err = -ENOMEM; | |
4313 | break; | |
4314 | } | |
4315 | ||
4316 | priv->tx_buffers[i].type = DATA; | |
4317 | priv->tx_buffers[i].info.d_struct.data = (struct ipw2100_data_header*)v; | |
4318 | priv->tx_buffers[i].info.d_struct.data_phys = p; | |
4319 | priv->tx_buffers[i].info.d_struct.txb = NULL; | |
4320 | } | |
4321 | ||
4322 | if (i == TX_PENDED_QUEUE_LENGTH) | |
4323 | return 0; | |
4324 | ||
4325 | for (j = 0; j < i; j++) { | |
4326 | pci_free_consistent( | |
4327 | priv->pci_dev, | |
4328 | sizeof(struct ipw2100_data_header), | |
4329 | priv->tx_buffers[j].info.d_struct.data, | |
4330 | priv->tx_buffers[j].info.d_struct.data_phys); | |
4331 | } | |
4332 | ||
4333 | kfree(priv->tx_buffers); | |
4334 | priv->tx_buffers = NULL; | |
4335 | ||
4336 | return err; | |
4337 | } | |
4338 | ||
4339 | static void ipw2100_tx_initialize(struct ipw2100_priv *priv) | |
4340 | { | |
4341 | int i; | |
4342 | ||
4343 | IPW_DEBUG_INFO("enter\n"); | |
4344 | ||
4345 | /* | |
4346 | * reinitialize packet info lists | |
4347 | */ | |
4348 | INIT_LIST_HEAD(&priv->fw_pend_list); | |
4349 | INIT_STAT(&priv->fw_pend_stat); | |
4350 | ||
4351 | /* | |
4352 | * reinitialize lists | |
4353 | */ | |
4354 | INIT_LIST_HEAD(&priv->tx_pend_list); | |
4355 | INIT_LIST_HEAD(&priv->tx_free_list); | |
4356 | INIT_STAT(&priv->tx_pend_stat); | |
4357 | INIT_STAT(&priv->tx_free_stat); | |
4358 | ||
4359 | for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) { | |
4360 | /* We simply drop any SKBs that have been queued for | |
4361 | * transmit */ | |
4362 | if (priv->tx_buffers[i].info.d_struct.txb) { | |
4363 | ieee80211_txb_free(priv->tx_buffers[i].info.d_struct.txb); | |
4364 | priv->tx_buffers[i].info.d_struct.txb = NULL; | |
4365 | } | |
4366 | ||
4367 | list_add_tail(&priv->tx_buffers[i].list, &priv->tx_free_list); | |
4368 | } | |
4369 | ||
4370 | SET_STAT(&priv->tx_free_stat, i); | |
4371 | ||
4372 | priv->tx_queue.oldest = 0; | |
4373 | priv->tx_queue.available = priv->tx_queue.entries; | |
4374 | priv->tx_queue.next = 0; | |
4375 | INIT_STAT(&priv->txq_stat); | |
4376 | SET_STAT(&priv->txq_stat, priv->tx_queue.available); | |
4377 | ||
4378 | bd_queue_initialize(priv, &priv->tx_queue, | |
4379 | IPW_MEM_HOST_SHARED_TX_QUEUE_BD_BASE, | |
4380 | IPW_MEM_HOST_SHARED_TX_QUEUE_BD_SIZE, | |
4381 | IPW_MEM_HOST_SHARED_TX_QUEUE_READ_INDEX, | |
4382 | IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX); | |
4383 | ||
4384 | IPW_DEBUG_INFO("exit\n"); | |
4385 | ||
4386 | } | |
4387 | ||
4388 | static void ipw2100_tx_free(struct ipw2100_priv *priv) | |
4389 | { | |
4390 | int i; | |
4391 | ||
4392 | IPW_DEBUG_INFO("enter\n"); | |
4393 | ||
4394 | bd_queue_free(priv, &priv->tx_queue); | |
4395 | ||
4396 | if (!priv->tx_buffers) | |
4397 | return; | |
4398 | ||
4399 | for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) { | |
4400 | if (priv->tx_buffers[i].info.d_struct.txb) { | |
4401 | ieee80211_txb_free(priv->tx_buffers[i].info.d_struct.txb); | |
4402 | priv->tx_buffers[i].info.d_struct.txb = NULL; | |
4403 | } | |
4404 | if (priv->tx_buffers[i].info.d_struct.data) | |
4405 | pci_free_consistent( | |
4406 | priv->pci_dev, | |
4407 | sizeof(struct ipw2100_data_header), | |
4408 | priv->tx_buffers[i].info.d_struct.data, | |
4409 | priv->tx_buffers[i].info.d_struct.data_phys); | |
4410 | } | |
4411 | ||
4412 | kfree(priv->tx_buffers); | |
4413 | priv->tx_buffers = NULL; | |
4414 | ||
4415 | IPW_DEBUG_INFO("exit\n"); | |
4416 | } | |
4417 | ||
4418 | ||
4419 | ||
4420 | static int ipw2100_rx_allocate(struct ipw2100_priv *priv) | |
4421 | { | |
4422 | int i, j, err = -EINVAL; | |
4423 | ||
4424 | IPW_DEBUG_INFO("enter\n"); | |
4425 | ||
4426 | err = bd_queue_allocate(priv, &priv->rx_queue, RX_QUEUE_LENGTH); | |
4427 | if (err) { | |
4428 | IPW_DEBUG_INFO("failed bd_queue_allocate\n"); | |
4429 | return err; | |
4430 | } | |
4431 | ||
4432 | err = status_queue_allocate(priv, RX_QUEUE_LENGTH); | |
4433 | if (err) { | |
4434 | IPW_DEBUG_INFO("failed status_queue_allocate\n"); | |
4435 | bd_queue_free(priv, &priv->rx_queue); | |
4436 | return err; | |
4437 | } | |
4438 | ||
4439 | /* | |
4440 | * allocate packets | |
4441 | */ | |
4442 | priv->rx_buffers = (struct ipw2100_rx_packet *) | |
4443 | kmalloc(RX_QUEUE_LENGTH * sizeof(struct ipw2100_rx_packet), | |
4444 | GFP_KERNEL); | |
4445 | if (!priv->rx_buffers) { | |
4446 | IPW_DEBUG_INFO("can't allocate rx packet buffer table\n"); | |
4447 | ||
4448 | bd_queue_free(priv, &priv->rx_queue); | |
4449 | ||
4450 | status_queue_free(priv); | |
4451 | ||
4452 | return -ENOMEM; | |
4453 | } | |
4454 | ||
4455 | for (i = 0; i < RX_QUEUE_LENGTH; i++) { | |
4456 | struct ipw2100_rx_packet *packet = &priv->rx_buffers[i]; | |
4457 | ||
4458 | err = ipw2100_alloc_skb(priv, packet); | |
4459 | if (unlikely(err)) { | |
4460 | err = -ENOMEM; | |
4461 | break; | |
4462 | } | |
4463 | ||
4464 | /* The BD holds the cache aligned address */ | |
4465 | priv->rx_queue.drv[i].host_addr = packet->dma_addr; | |
4466 | priv->rx_queue.drv[i].buf_length = IPW_RX_NIC_BUFFER_LENGTH; | |
4467 | priv->status_queue.drv[i].status_fields = 0; | |
4468 | } | |
4469 | ||
4470 | if (i == RX_QUEUE_LENGTH) | |
4471 | return 0; | |
4472 | ||
4473 | for (j = 0; j < i; j++) { | |
4474 | pci_unmap_single(priv->pci_dev, priv->rx_buffers[j].dma_addr, | |
4475 | sizeof(struct ipw2100_rx_packet), | |
4476 | PCI_DMA_FROMDEVICE); | |
4477 | dev_kfree_skb(priv->rx_buffers[j].skb); | |
4478 | } | |
4479 | ||
4480 | kfree(priv->rx_buffers); | |
4481 | priv->rx_buffers = NULL; | |
4482 | ||
4483 | bd_queue_free(priv, &priv->rx_queue); | |
4484 | ||
4485 | status_queue_free(priv); | |
4486 | ||
4487 | return err; | |
4488 | } | |
4489 | ||
4490 | static void ipw2100_rx_initialize(struct ipw2100_priv *priv) | |
4491 | { | |
4492 | IPW_DEBUG_INFO("enter\n"); | |
4493 | ||
4494 | priv->rx_queue.oldest = 0; | |
4495 | priv->rx_queue.available = priv->rx_queue.entries - 1; | |
4496 | priv->rx_queue.next = priv->rx_queue.entries - 1; | |
4497 | ||
4498 | INIT_STAT(&priv->rxq_stat); | |
4499 | SET_STAT(&priv->rxq_stat, priv->rx_queue.available); | |
4500 | ||
4501 | bd_queue_initialize(priv, &priv->rx_queue, | |
4502 | IPW_MEM_HOST_SHARED_RX_BD_BASE, | |
4503 | IPW_MEM_HOST_SHARED_RX_BD_SIZE, | |
4504 | IPW_MEM_HOST_SHARED_RX_READ_INDEX, | |
4505 | IPW_MEM_HOST_SHARED_RX_WRITE_INDEX); | |
4506 | ||
4507 | /* set up the status queue */ | |
4508 | write_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_STATUS_BASE, | |
4509 | priv->status_queue.nic); | |
4510 | ||
4511 | IPW_DEBUG_INFO("exit\n"); | |
4512 | } | |
4513 | ||
4514 | static void ipw2100_rx_free(struct ipw2100_priv *priv) | |
4515 | { | |
4516 | int i; | |
4517 | ||
4518 | IPW_DEBUG_INFO("enter\n"); | |
4519 | ||
4520 | bd_queue_free(priv, &priv->rx_queue); | |
4521 | status_queue_free(priv); | |
4522 | ||
4523 | if (!priv->rx_buffers) | |
4524 | return; | |
4525 | ||
4526 | for (i = 0; i < RX_QUEUE_LENGTH; i++) { | |
4527 | if (priv->rx_buffers[i].rxp) { | |
4528 | pci_unmap_single(priv->pci_dev, | |
4529 | priv->rx_buffers[i].dma_addr, | |
4530 | sizeof(struct ipw2100_rx), | |
4531 | PCI_DMA_FROMDEVICE); | |
4532 | dev_kfree_skb(priv->rx_buffers[i].skb); | |
4533 | } | |
4534 | } | |
4535 | ||
4536 | kfree(priv->rx_buffers); | |
4537 | priv->rx_buffers = NULL; | |
4538 | ||
4539 | IPW_DEBUG_INFO("exit\n"); | |
4540 | } | |
4541 | ||
4542 | static int ipw2100_read_mac_address(struct ipw2100_priv *priv) | |
4543 | { | |
4544 | u32 length = ETH_ALEN; | |
4545 | u8 mac[ETH_ALEN]; | |
4546 | ||
4547 | int err; | |
4548 | ||
4549 | err = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ADAPTER_MAC, | |
4550 | mac, &length); | |
4551 | if (err) { | |
4552 | IPW_DEBUG_INFO("MAC address read failed\n"); | |
4553 | return -EIO; | |
4554 | } | |
4555 | IPW_DEBUG_INFO("card MAC is %02X:%02X:%02X:%02X:%02X:%02X\n", | |
4556 | mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); | |
4557 | ||
4558 | memcpy(priv->net_dev->dev_addr, mac, ETH_ALEN); | |
4559 | ||
4560 | return 0; | |
4561 | } | |
4562 | ||
4563 | /******************************************************************** | |
4564 | * | |
4565 | * Firmware Commands | |
4566 | * | |
4567 | ********************************************************************/ | |
4568 | ||
c4aee8c2 | 4569 | static int ipw2100_set_mac_address(struct ipw2100_priv *priv, int batch_mode) |
2c86c275 JK |
4570 | { |
4571 | struct host_command cmd = { | |
4572 | .host_command = ADAPTER_ADDRESS, | |
4573 | .host_command_sequence = 0, | |
4574 | .host_command_length = ETH_ALEN | |
4575 | }; | |
4576 | int err; | |
4577 | ||
4578 | IPW_DEBUG_HC("SET_MAC_ADDRESS\n"); | |
4579 | ||
4580 | IPW_DEBUG_INFO("enter\n"); | |
4581 | ||
4582 | if (priv->config & CFG_CUSTOM_MAC) { | |
4583 | memcpy(cmd.host_command_parameters, priv->mac_addr, | |
4584 | ETH_ALEN); | |
4585 | memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN); | |
4586 | } else | |
4587 | memcpy(cmd.host_command_parameters, priv->net_dev->dev_addr, | |
4588 | ETH_ALEN); | |
4589 | ||
4590 | err = ipw2100_hw_send_command(priv, &cmd); | |
4591 | ||
4592 | IPW_DEBUG_INFO("exit\n"); | |
4593 | return err; | |
4594 | } | |
4595 | ||
c4aee8c2 | 4596 | static int ipw2100_set_port_type(struct ipw2100_priv *priv, u32 port_type, |
2c86c275 JK |
4597 | int batch_mode) |
4598 | { | |
4599 | struct host_command cmd = { | |
4600 | .host_command = PORT_TYPE, | |
4601 | .host_command_sequence = 0, | |
4602 | .host_command_length = sizeof(u32) | |
4603 | }; | |
4604 | int err; | |
4605 | ||
4606 | switch (port_type) { | |
4607 | case IW_MODE_INFRA: | |
4608 | cmd.host_command_parameters[0] = IPW_BSS; | |
4609 | break; | |
4610 | case IW_MODE_ADHOC: | |
4611 | cmd.host_command_parameters[0] = IPW_IBSS; | |
4612 | break; | |
4613 | } | |
4614 | ||
4615 | IPW_DEBUG_HC("PORT_TYPE: %s\n", | |
4616 | port_type == IPW_IBSS ? "Ad-Hoc" : "Managed"); | |
4617 | ||
4618 | if (!batch_mode) { | |
4619 | err = ipw2100_disable_adapter(priv); | |
4620 | if (err) { | |
797b4f76 | 4621 | printk(KERN_ERR DRV_NAME ": %s: Could not disable adapter %d\n", |
2c86c275 JK |
4622 | priv->net_dev->name, err); |
4623 | return err; | |
4624 | } | |
4625 | } | |
4626 | ||
4627 | /* send cmd to firmware */ | |
4628 | err = ipw2100_hw_send_command(priv, &cmd); | |
4629 | ||
4630 | if (!batch_mode) | |
4631 | ipw2100_enable_adapter(priv); | |
4632 | ||
4633 | return err; | |
4634 | } | |
4635 | ||
4636 | ||
c4aee8c2 JB |
4637 | static int ipw2100_set_channel(struct ipw2100_priv *priv, u32 channel, |
4638 | int batch_mode) | |
2c86c275 JK |
4639 | { |
4640 | struct host_command cmd = { | |
4641 | .host_command = CHANNEL, | |
4642 | .host_command_sequence = 0, | |
4643 | .host_command_length = sizeof(u32) | |
4644 | }; | |
4645 | int err; | |
4646 | ||
4647 | cmd.host_command_parameters[0] = channel; | |
4648 | ||
4649 | IPW_DEBUG_HC("CHANNEL: %d\n", channel); | |
4650 | ||
4651 | /* If BSS then we don't support channel selection */ | |
4652 | if (priv->ieee->iw_mode == IW_MODE_INFRA) | |
4653 | return 0; | |
4654 | ||
4655 | if ((channel != 0) && | |
4656 | ((channel < REG_MIN_CHANNEL) || (channel > REG_MAX_CHANNEL))) | |
4657 | return -EINVAL; | |
4658 | ||
4659 | if (!batch_mode) { | |
4660 | err = ipw2100_disable_adapter(priv); | |
4661 | if (err) | |
4662 | return err; | |
4663 | } | |
4664 | ||
4665 | err = ipw2100_hw_send_command(priv, &cmd); | |
4666 | if (err) { | |
4667 | IPW_DEBUG_INFO("Failed to set channel to %d", | |
4668 | channel); | |
4669 | return err; | |
4670 | } | |
4671 | ||
4672 | if (channel) | |
4673 | priv->config |= CFG_STATIC_CHANNEL; | |
4674 | else | |
4675 | priv->config &= ~CFG_STATIC_CHANNEL; | |
4676 | ||
4677 | priv->channel = channel; | |
4678 | ||
4679 | if (!batch_mode) { | |
4680 | err = ipw2100_enable_adapter(priv); | |
4681 | if (err) | |
4682 | return err; | |
4683 | } | |
4684 | ||
4685 | return 0; | |
4686 | } | |
4687 | ||
c4aee8c2 | 4688 | static int ipw2100_system_config(struct ipw2100_priv *priv, int batch_mode) |
2c86c275 JK |
4689 | { |
4690 | struct host_command cmd = { | |
4691 | .host_command = SYSTEM_CONFIG, | |
4692 | .host_command_sequence = 0, | |
4693 | .host_command_length = 12, | |
4694 | }; | |
4695 | u32 ibss_mask, len = sizeof(u32); | |
4696 | int err; | |
4697 | ||
4698 | /* Set system configuration */ | |
4699 | ||
4700 | if (!batch_mode) { | |
4701 | err = ipw2100_disable_adapter(priv); | |
4702 | if (err) | |
4703 | return err; | |
4704 | } | |
4705 | ||
4706 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) | |
4707 | cmd.host_command_parameters[0] |= IPW_CFG_IBSS_AUTO_START; | |
4708 | ||
4709 | cmd.host_command_parameters[0] |= IPW_CFG_IBSS_MASK | | |
4710 | IPW_CFG_BSS_MASK | | |
4711 | IPW_CFG_802_1x_ENABLE; | |
4712 | ||
4713 | if (!(priv->config & CFG_LONG_PREAMBLE)) | |
4714 | cmd.host_command_parameters[0] |= IPW_CFG_PREAMBLE_AUTO; | |
4715 | ||
4716 | err = ipw2100_get_ordinal(priv, | |
4717 | IPW_ORD_EEPROM_IBSS_11B_CHANNELS, | |
4718 | &ibss_mask, &len); | |
4719 | if (err) | |
4720 | ibss_mask = IPW_IBSS_11B_DEFAULT_MASK; | |
4721 | ||
4722 | cmd.host_command_parameters[1] = REG_CHANNEL_MASK; | |
4723 | cmd.host_command_parameters[2] = REG_CHANNEL_MASK & ibss_mask; | |
4724 | ||
4725 | /* 11b only */ | |
4726 | /*cmd.host_command_parameters[0] |= DIVERSITY_ANTENNA_A;*/ | |
4727 | ||
4728 | err = ipw2100_hw_send_command(priv, &cmd); | |
4729 | if (err) | |
4730 | return err; | |
4731 | ||
4732 | /* If IPv6 is configured in the kernel then we don't want to filter out all | |
4733 | * of the multicast packets as IPv6 needs some. */ | |
4734 | #if !defined(CONFIG_IPV6) && !defined(CONFIG_IPV6_MODULE) | |
4735 | cmd.host_command = ADD_MULTICAST; | |
4736 | cmd.host_command_sequence = 0; | |
4737 | cmd.host_command_length = 0; | |
4738 | ||
4739 | ipw2100_hw_send_command(priv, &cmd); | |
4740 | #endif | |
4741 | if (!batch_mode) { | |
4742 | err = ipw2100_enable_adapter(priv); | |
4743 | if (err) | |
4744 | return err; | |
4745 | } | |
4746 | ||
4747 | return 0; | |
4748 | } | |
4749 | ||
c4aee8c2 JB |
4750 | static int ipw2100_set_tx_rates(struct ipw2100_priv *priv, u32 rate, |
4751 | int batch_mode) | |
2c86c275 JK |
4752 | { |
4753 | struct host_command cmd = { | |
4754 | .host_command = BASIC_TX_RATES, | |
4755 | .host_command_sequence = 0, | |
4756 | .host_command_length = 4 | |
4757 | }; | |
4758 | int err; | |
4759 | ||
4760 | cmd.host_command_parameters[0] = rate & TX_RATE_MASK; | |
4761 | ||
4762 | if (!batch_mode) { | |
4763 | err = ipw2100_disable_adapter(priv); | |
4764 | if (err) | |
4765 | return err; | |
4766 | } | |
4767 | ||
4768 | /* Set BASIC TX Rate first */ | |
4769 | ipw2100_hw_send_command(priv, &cmd); | |
4770 | ||
4771 | /* Set TX Rate */ | |
4772 | cmd.host_command = TX_RATES; | |
4773 | ipw2100_hw_send_command(priv, &cmd); | |
4774 | ||
4775 | /* Set MSDU TX Rate */ | |
4776 | cmd.host_command = MSDU_TX_RATES; | |
4777 | ipw2100_hw_send_command(priv, &cmd); | |
4778 | ||
4779 | if (!batch_mode) { | |
4780 | err = ipw2100_enable_adapter(priv); | |
4781 | if (err) | |
4782 | return err; | |
4783 | } | |
4784 | ||
4785 | priv->tx_rates = rate; | |
4786 | ||
4787 | return 0; | |
4788 | } | |
4789 | ||
c4aee8c2 JB |
4790 | static int ipw2100_set_power_mode(struct ipw2100_priv *priv, |
4791 | int power_level) | |
2c86c275 JK |
4792 | { |
4793 | struct host_command cmd = { | |
4794 | .host_command = POWER_MODE, | |
4795 | .host_command_sequence = 0, | |
4796 | .host_command_length = 4 | |
4797 | }; | |
4798 | int err; | |
4799 | ||
4800 | cmd.host_command_parameters[0] = power_level; | |
4801 | ||
4802 | err = ipw2100_hw_send_command(priv, &cmd); | |
4803 | if (err) | |
4804 | return err; | |
4805 | ||
4806 | if (power_level == IPW_POWER_MODE_CAM) | |
4807 | priv->power_mode = IPW_POWER_LEVEL(priv->power_mode); | |
4808 | else | |
4809 | priv->power_mode = IPW_POWER_ENABLED | power_level; | |
4810 | ||
4811 | #ifdef CONFIG_IPW2100_TX_POWER | |
4812 | if (priv->port_type == IBSS && | |
4813 | priv->adhoc_power != DFTL_IBSS_TX_POWER) { | |
4814 | /* Set beacon interval */ | |
4815 | cmd.host_command = TX_POWER_INDEX; | |
4816 | cmd.host_command_parameters[0] = (u32)priv->adhoc_power; | |
4817 | ||
4818 | err = ipw2100_hw_send_command(priv, &cmd); | |
4819 | if (err) | |
4820 | return err; | |
4821 | } | |
4822 | #endif | |
4823 | ||
4824 | return 0; | |
4825 | } | |
4826 | ||
4827 | ||
c4aee8c2 | 4828 | static int ipw2100_set_rts_threshold(struct ipw2100_priv *priv, u32 threshold) |
2c86c275 JK |
4829 | { |
4830 | struct host_command cmd = { | |
4831 | .host_command = RTS_THRESHOLD, | |
4832 | .host_command_sequence = 0, | |
4833 | .host_command_length = 4 | |
4834 | }; | |
4835 | int err; | |
4836 | ||
4837 | if (threshold & RTS_DISABLED) | |
4838 | cmd.host_command_parameters[0] = MAX_RTS_THRESHOLD; | |
4839 | else | |
4840 | cmd.host_command_parameters[0] = threshold & ~RTS_DISABLED; | |
4841 | ||
4842 | err = ipw2100_hw_send_command(priv, &cmd); | |
4843 | if (err) | |
4844 | return err; | |
4845 | ||
4846 | priv->rts_threshold = threshold; | |
4847 | ||
4848 | return 0; | |
4849 | } | |
4850 | ||
4851 | #if 0 | |
4852 | int ipw2100_set_fragmentation_threshold(struct ipw2100_priv *priv, | |
4853 | u32 threshold, int batch_mode) | |
4854 | { | |
4855 | struct host_command cmd = { | |
4856 | .host_command = FRAG_THRESHOLD, | |
4857 | .host_command_sequence = 0, | |
4858 | .host_command_length = 4, | |
4859 | .host_command_parameters[0] = 0, | |
4860 | }; | |
4861 | int err; | |
4862 | ||
4863 | if (!batch_mode) { | |
4864 | err = ipw2100_disable_adapter(priv); | |
4865 | if (err) | |
4866 | return err; | |
4867 | } | |
4868 | ||
4869 | if (threshold == 0) | |
4870 | threshold = DEFAULT_FRAG_THRESHOLD; | |
4871 | else { | |
4872 | threshold = max(threshold, MIN_FRAG_THRESHOLD); | |
4873 | threshold = min(threshold, MAX_FRAG_THRESHOLD); | |
4874 | } | |
4875 | ||
4876 | cmd.host_command_parameters[0] = threshold; | |
4877 | ||
4878 | IPW_DEBUG_HC("FRAG_THRESHOLD: %u\n", threshold); | |
4879 | ||
4880 | err = ipw2100_hw_send_command(priv, &cmd); | |
4881 | ||
4882 | if (!batch_mode) | |
4883 | ipw2100_enable_adapter(priv); | |
4884 | ||
4885 | if (!err) | |
4886 | priv->frag_threshold = threshold; | |
4887 | ||
4888 | return err; | |
4889 | } | |
4890 | #endif | |
4891 | ||
c4aee8c2 | 4892 | static int ipw2100_set_short_retry(struct ipw2100_priv *priv, u32 retry) |
2c86c275 JK |
4893 | { |
4894 | struct host_command cmd = { | |
4895 | .host_command = SHORT_RETRY_LIMIT, | |
4896 | .host_command_sequence = 0, | |
4897 | .host_command_length = 4 | |
4898 | }; | |
4899 | int err; | |
4900 | ||
4901 | cmd.host_command_parameters[0] = retry; | |
4902 | ||
4903 | err = ipw2100_hw_send_command(priv, &cmd); | |
4904 | if (err) | |
4905 | return err; | |
4906 | ||
4907 | priv->short_retry_limit = retry; | |
4908 | ||
4909 | return 0; | |
4910 | } | |
4911 | ||
c4aee8c2 | 4912 | static int ipw2100_set_long_retry(struct ipw2100_priv *priv, u32 retry) |
2c86c275 JK |
4913 | { |
4914 | struct host_command cmd = { | |
4915 | .host_command = LONG_RETRY_LIMIT, | |
4916 | .host_command_sequence = 0, | |
4917 | .host_command_length = 4 | |
4918 | }; | |
4919 | int err; | |
4920 | ||
4921 | cmd.host_command_parameters[0] = retry; | |
4922 | ||
4923 | err = ipw2100_hw_send_command(priv, &cmd); | |
4924 | if (err) | |
4925 | return err; | |
4926 | ||
4927 | priv->long_retry_limit = retry; | |
4928 | ||
4929 | return 0; | |
4930 | } | |
4931 | ||
4932 | ||
c4aee8c2 JB |
4933 | static int ipw2100_set_mandatory_bssid(struct ipw2100_priv *priv, u8 *bssid, |
4934 | int batch_mode) | |
2c86c275 JK |
4935 | { |
4936 | struct host_command cmd = { | |
4937 | .host_command = MANDATORY_BSSID, | |
4938 | .host_command_sequence = 0, | |
4939 | .host_command_length = (bssid == NULL) ? 0 : ETH_ALEN | |
4940 | }; | |
4941 | int err; | |
4942 | ||
4943 | #ifdef CONFIG_IPW_DEBUG | |
4944 | if (bssid != NULL) | |
4945 | IPW_DEBUG_HC( | |
4946 | "MANDATORY_BSSID: %02X:%02X:%02X:%02X:%02X:%02X\n", | |
4947 | bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], | |
4948 | bssid[5]); | |
4949 | else | |
4950 | IPW_DEBUG_HC("MANDATORY_BSSID: <clear>\n"); | |
4951 | #endif | |
4952 | /* if BSSID is empty then we disable mandatory bssid mode */ | |
4953 | if (bssid != NULL) | |
4954 | memcpy((u8 *)cmd.host_command_parameters, bssid, ETH_ALEN); | |
4955 | ||
4956 | if (!batch_mode) { | |
4957 | err = ipw2100_disable_adapter(priv); | |
4958 | if (err) | |
4959 | return err; | |
4960 | } | |
4961 | ||
4962 | err = ipw2100_hw_send_command(priv, &cmd); | |
4963 | ||
4964 | if (!batch_mode) | |
4965 | ipw2100_enable_adapter(priv); | |
4966 | ||
4967 | return err; | |
4968 | } | |
4969 | ||
4970 | #ifdef CONFIG_IEEE80211_WPA | |
4971 | static int ipw2100_disassociate_bssid(struct ipw2100_priv *priv) | |
4972 | { | |
4973 | struct host_command cmd = { | |
4974 | .host_command = DISASSOCIATION_BSSID, | |
4975 | .host_command_sequence = 0, | |
4976 | .host_command_length = ETH_ALEN | |
4977 | }; | |
4978 | int err; | |
4979 | int len; | |
4980 | ||
4981 | IPW_DEBUG_HC("DISASSOCIATION_BSSID\n"); | |
4982 | ||
4983 | len = ETH_ALEN; | |
4984 | /* The Firmware currently ignores the BSSID and just disassociates from | |
4985 | * the currently associated AP -- but in the off chance that a future | |
4986 | * firmware does use the BSSID provided here, we go ahead and try and | |
4987 | * set it to the currently associated AP's BSSID */ | |
4988 | memcpy(cmd.host_command_parameters, priv->bssid, ETH_ALEN); | |
4989 | ||
4990 | err = ipw2100_hw_send_command(priv, &cmd); | |
4991 | ||
4992 | return err; | |
4993 | } | |
4994 | #endif | |
4995 | ||
4996 | /* | |
4997 | * Pseudo code for setting up wpa_frame: | |
4998 | */ | |
4999 | #if 0 | |
5000 | void x(struct ieee80211_assoc_frame *wpa_assoc) | |
5001 | { | |
5002 | struct ipw2100_wpa_assoc_frame frame; | |
5003 | frame->fixed_ie_mask = IPW_WPA_CAPABILTIES | | |
5004 | IPW_WPA_LISTENINTERVAL | | |
5005 | IPW_WPA_AP_ADDRESS; | |
5006 | frame->capab_info = wpa_assoc->capab_info; | |
5007 | frame->lisen_interval = wpa_assoc->listent_interval; | |
5008 | memcpy(frame->current_ap, wpa_assoc->current_ap, ETH_ALEN); | |
5009 | ||
5010 | /* UNKNOWN -- I'm not postivive about this part; don't have any WPA | |
5011 | * setup here to test it with. | |
5012 | * | |
5013 | * Walk the IEs in the wpa_assoc and figure out the total size of all | |
5014 | * that data. Stick that into frame->var_ie_len. Then memcpy() all of | |
5015 | * the IEs from wpa_frame into frame. | |
5016 | */ | |
5017 | frame->var_ie_len = calculate_ie_len(wpa_assoc); | |
5018 | memcpy(frame->var_ie, wpa_assoc->variable, frame->var_ie_len); | |
5019 | ||
5020 | ipw2100_set_wpa_ie(priv, &frame, 0); | |
5021 | } | |
5022 | #endif | |
5023 | ||
5024 | ||
5025 | ||
5026 | ||
5027 | static int ipw2100_set_wpa_ie(struct ipw2100_priv *, | |
5028 | struct ipw2100_wpa_assoc_frame *, int) | |
5029 | __attribute__ ((unused)); | |
5030 | ||
5031 | static int ipw2100_set_wpa_ie(struct ipw2100_priv *priv, | |
5032 | struct ipw2100_wpa_assoc_frame *wpa_frame, | |
5033 | int batch_mode) | |
5034 | { | |
5035 | struct host_command cmd = { | |
5036 | .host_command = SET_WPA_IE, | |
5037 | .host_command_sequence = 0, | |
5038 | .host_command_length = sizeof(struct ipw2100_wpa_assoc_frame), | |
5039 | }; | |
5040 | int err; | |
5041 | ||
5042 | IPW_DEBUG_HC("SET_WPA_IE\n"); | |
5043 | ||
5044 | if (!batch_mode) { | |
5045 | err = ipw2100_disable_adapter(priv); | |
5046 | if (err) | |
5047 | return err; | |
5048 | } | |
5049 | ||
5050 | memcpy(cmd.host_command_parameters, wpa_frame, | |
5051 | sizeof(struct ipw2100_wpa_assoc_frame)); | |
5052 | ||
5053 | err = ipw2100_hw_send_command(priv, &cmd); | |
5054 | ||
5055 | if (!batch_mode) { | |
5056 | if (ipw2100_enable_adapter(priv)) | |
5057 | err = -EIO; | |
5058 | } | |
5059 | ||
5060 | return err; | |
5061 | } | |
5062 | ||
5063 | struct security_info_params { | |
5064 | u32 allowed_ciphers; | |
5065 | u16 version; | |
5066 | u8 auth_mode; | |
5067 | u8 replay_counters_number; | |
5068 | u8 unicast_using_group; | |
5069 | } __attribute__ ((packed)); | |
5070 | ||
c4aee8c2 JB |
5071 | static int ipw2100_set_security_information(struct ipw2100_priv *priv, |
5072 | int auth_mode, | |
5073 | int security_level, | |
5074 | int unicast_using_group, | |
5075 | int batch_mode) | |
2c86c275 JK |
5076 | { |
5077 | struct host_command cmd = { | |
5078 | .host_command = SET_SECURITY_INFORMATION, | |
5079 | .host_command_sequence = 0, | |
5080 | .host_command_length = sizeof(struct security_info_params) | |
5081 | }; | |
5082 | struct security_info_params *security = | |
5083 | (struct security_info_params *)&cmd.host_command_parameters; | |
5084 | int err; | |
5085 | memset(security, 0, sizeof(*security)); | |
5086 | ||
5087 | /* If shared key AP authentication is turned on, then we need to | |
5088 | * configure the firmware to try and use it. | |
5089 | * | |
5090 | * Actual data encryption/decryption is handled by the host. */ | |
5091 | security->auth_mode = auth_mode; | |
5092 | security->unicast_using_group = unicast_using_group; | |
5093 | ||
5094 | switch (security_level) { | |
5095 | default: | |
5096 | case SEC_LEVEL_0: | |
5097 | security->allowed_ciphers = IPW_NONE_CIPHER; | |
5098 | break; | |
5099 | case SEC_LEVEL_1: | |
5100 | security->allowed_ciphers = IPW_WEP40_CIPHER | | |
5101 | IPW_WEP104_CIPHER; | |
5102 | break; | |
5103 | case SEC_LEVEL_2: | |
5104 | security->allowed_ciphers = IPW_WEP40_CIPHER | | |
5105 | IPW_WEP104_CIPHER | IPW_TKIP_CIPHER; | |
5106 | break; | |
5107 | case SEC_LEVEL_2_CKIP: | |
5108 | security->allowed_ciphers = IPW_WEP40_CIPHER | | |
5109 | IPW_WEP104_CIPHER | IPW_CKIP_CIPHER; | |
5110 | break; | |
5111 | case SEC_LEVEL_3: | |
5112 | security->allowed_ciphers = IPW_WEP40_CIPHER | | |
5113 | IPW_WEP104_CIPHER | IPW_TKIP_CIPHER | IPW_CCMP_CIPHER; | |
5114 | break; | |
5115 | } | |
5116 | ||
5117 | IPW_DEBUG_HC( | |
5118 | "SET_SECURITY_INFORMATION: auth:%d cipher:0x%02X (level %d)\n", | |
5119 | security->auth_mode, security->allowed_ciphers, security_level); | |
5120 | ||
5121 | security->replay_counters_number = 0; | |
5122 | ||
5123 | if (!batch_mode) { | |
5124 | err = ipw2100_disable_adapter(priv); | |
5125 | if (err) | |
5126 | return err; | |
5127 | } | |
5128 | ||
5129 | err = ipw2100_hw_send_command(priv, &cmd); | |
5130 | ||
5131 | if (!batch_mode) | |
5132 | ipw2100_enable_adapter(priv); | |
5133 | ||
5134 | return err; | |
5135 | } | |
5136 | ||
c4aee8c2 JB |
5137 | static int ipw2100_set_tx_power(struct ipw2100_priv *priv, |
5138 | u32 tx_power) | |
2c86c275 JK |
5139 | { |
5140 | struct host_command cmd = { | |
5141 | .host_command = TX_POWER_INDEX, | |
5142 | .host_command_sequence = 0, | |
5143 | .host_command_length = 4 | |
5144 | }; | |
5145 | int err = 0; | |
5146 | ||
5147 | cmd.host_command_parameters[0] = tx_power; | |
5148 | ||
5149 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) | |
5150 | err = ipw2100_hw_send_command(priv, &cmd); | |
5151 | if (!err) | |
5152 | priv->tx_power = tx_power; | |
5153 | ||
5154 | return 0; | |
5155 | } | |
5156 | ||
c4aee8c2 JB |
5157 | static int ipw2100_set_ibss_beacon_interval(struct ipw2100_priv *priv, |
5158 | u32 interval, int batch_mode) | |
2c86c275 JK |
5159 | { |
5160 | struct host_command cmd = { | |
5161 | .host_command = BEACON_INTERVAL, | |
5162 | .host_command_sequence = 0, | |
5163 | .host_command_length = 4 | |
5164 | }; | |
5165 | int err; | |
5166 | ||
5167 | cmd.host_command_parameters[0] = interval; | |
5168 | ||
5169 | IPW_DEBUG_INFO("enter\n"); | |
5170 | ||
5171 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { | |
5172 | if (!batch_mode) { | |
5173 | err = ipw2100_disable_adapter(priv); | |
5174 | if (err) | |
5175 | return err; | |
5176 | } | |
5177 | ||
5178 | ipw2100_hw_send_command(priv, &cmd); | |
5179 | ||
5180 | if (!batch_mode) { | |
5181 | err = ipw2100_enable_adapter(priv); | |
5182 | if (err) | |
5183 | return err; | |
5184 | } | |
5185 | } | |
5186 | ||
5187 | IPW_DEBUG_INFO("exit\n"); | |
5188 | ||
5189 | return 0; | |
5190 | } | |
5191 | ||
5192 | ||
5193 | void ipw2100_queues_initialize(struct ipw2100_priv *priv) | |
5194 | { | |
5195 | ipw2100_tx_initialize(priv); | |
5196 | ipw2100_rx_initialize(priv); | |
5197 | ipw2100_msg_initialize(priv); | |
5198 | } | |
5199 | ||
5200 | void ipw2100_queues_free(struct ipw2100_priv *priv) | |
5201 | { | |
5202 | ipw2100_tx_free(priv); | |
5203 | ipw2100_rx_free(priv); | |
5204 | ipw2100_msg_free(priv); | |
5205 | } | |
5206 | ||
5207 | int ipw2100_queues_allocate(struct ipw2100_priv *priv) | |
5208 | { | |
5209 | if (ipw2100_tx_allocate(priv) || | |
5210 | ipw2100_rx_allocate(priv) || | |
5211 | ipw2100_msg_allocate(priv)) | |
5212 | goto fail; | |
5213 | ||
5214 | return 0; | |
5215 | ||
5216 | fail: | |
5217 | ipw2100_tx_free(priv); | |
5218 | ipw2100_rx_free(priv); | |
5219 | ipw2100_msg_free(priv); | |
5220 | return -ENOMEM; | |
5221 | } | |
5222 | ||
5223 | #define IPW_PRIVACY_CAPABLE 0x0008 | |
5224 | ||
5225 | static int ipw2100_set_wep_flags(struct ipw2100_priv *priv, u32 flags, | |
5226 | int batch_mode) | |
5227 | { | |
5228 | struct host_command cmd = { | |
5229 | .host_command = WEP_FLAGS, | |
5230 | .host_command_sequence = 0, | |
5231 | .host_command_length = 4 | |
5232 | }; | |
5233 | int err; | |
5234 | ||
5235 | cmd.host_command_parameters[0] = flags; | |
5236 | ||
5237 | IPW_DEBUG_HC("WEP_FLAGS: flags = 0x%08X\n", flags); | |
5238 | ||
5239 | if (!batch_mode) { | |
5240 | err = ipw2100_disable_adapter(priv); | |
5241 | if (err) { | |
797b4f76 | 5242 | printk(KERN_ERR DRV_NAME ": %s: Could not disable adapter %d\n", |
2c86c275 JK |
5243 | priv->net_dev->name, err); |
5244 | return err; | |
5245 | } | |
5246 | } | |
5247 | ||
5248 | /* send cmd to firmware */ | |
5249 | err = ipw2100_hw_send_command(priv, &cmd); | |
5250 | ||
5251 | if (!batch_mode) | |
5252 | ipw2100_enable_adapter(priv); | |
5253 | ||
5254 | return err; | |
5255 | } | |
5256 | ||
5257 | struct ipw2100_wep_key { | |
5258 | u8 idx; | |
5259 | u8 len; | |
5260 | u8 key[13]; | |
5261 | }; | |
5262 | ||
5263 | /* Macros to ease up priting WEP keys */ | |
5264 | #define WEP_FMT_64 "%02X%02X%02X%02X-%02X" | |
5265 | #define WEP_FMT_128 "%02X%02X%02X%02X-%02X%02X%02X%02X-%02X%02X%02X" | |
5266 | #define WEP_STR_64(x) x[0],x[1],x[2],x[3],x[4] | |
5267 | #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] | |
5268 | ||
5269 | ||
5270 | /** | |
5271 | * Set a the wep key | |
5272 | * | |
5273 | * @priv: struct to work on | |
5274 | * @idx: index of the key we want to set | |
5275 | * @key: ptr to the key data to set | |
5276 | * @len: length of the buffer at @key | |
5277 | * @batch_mode: FIXME perform the operation in batch mode, not | |
5278 | * disabling the device. | |
5279 | * | |
5280 | * @returns 0 if OK, < 0 errno code on error. | |
5281 | * | |
5282 | * Fill out a command structure with the new wep key, length an | |
5283 | * index and send it down the wire. | |
5284 | */ | |
5285 | static int ipw2100_set_key(struct ipw2100_priv *priv, | |
5286 | int idx, char *key, int len, int batch_mode) | |
5287 | { | |
5288 | int keylen = len ? (len <= 5 ? 5 : 13) : 0; | |
5289 | struct host_command cmd = { | |
5290 | .host_command = WEP_KEY_INFO, | |
5291 | .host_command_sequence = 0, | |
5292 | .host_command_length = sizeof(struct ipw2100_wep_key), | |
5293 | }; | |
5294 | struct ipw2100_wep_key *wep_key = (void*)cmd.host_command_parameters; | |
5295 | int err; | |
5296 | ||
5297 | IPW_DEBUG_HC("WEP_KEY_INFO: index = %d, len = %d/%d\n", | |
5298 | idx, keylen, len); | |
5299 | ||
5300 | /* NOTE: We don't check cached values in case the firmware was reset | |
5301 | * or some other problem is occuring. If the user is setting the key, | |
5302 | * then we push the change */ | |
5303 | ||
5304 | wep_key->idx = idx; | |
5305 | wep_key->len = keylen; | |
5306 | ||
5307 | if (keylen) { | |
5308 | memcpy(wep_key->key, key, len); | |
5309 | memset(wep_key->key + len, 0, keylen - len); | |
5310 | } | |
5311 | ||
5312 | /* Will be optimized out on debug not being configured in */ | |
5313 | if (keylen == 0) | |
5314 | IPW_DEBUG_WEP("%s: Clearing key %d\n", | |
5315 | priv->net_dev->name, wep_key->idx); | |
5316 | else if (keylen == 5) | |
5317 | IPW_DEBUG_WEP("%s: idx: %d, len: %d key: " WEP_FMT_64 "\n", | |
5318 | priv->net_dev->name, wep_key->idx, wep_key->len, | |
5319 | WEP_STR_64(wep_key->key)); | |
5320 | else | |
5321 | IPW_DEBUG_WEP("%s: idx: %d, len: %d key: " WEP_FMT_128 | |
5322 | "\n", | |
5323 | priv->net_dev->name, wep_key->idx, wep_key->len, | |
5324 | WEP_STR_128(wep_key->key)); | |
5325 | ||
5326 | if (!batch_mode) { | |
5327 | err = ipw2100_disable_adapter(priv); | |
5328 | /* FIXME: IPG: shouldn't this prink be in _disable_adapter()? */ | |
5329 | if (err) { | |
797b4f76 | 5330 | printk(KERN_ERR DRV_NAME ": %s: Could not disable adapter %d\n", |
2c86c275 JK |
5331 | priv->net_dev->name, err); |
5332 | return err; | |
5333 | } | |
5334 | } | |
5335 | ||
5336 | /* send cmd to firmware */ | |
5337 | err = ipw2100_hw_send_command(priv, &cmd); | |
5338 | ||
5339 | if (!batch_mode) { | |
5340 | int err2 = ipw2100_enable_adapter(priv); | |
5341 | if (err == 0) | |
5342 | err = err2; | |
5343 | } | |
5344 | return err; | |
5345 | } | |
5346 | ||
5347 | static int ipw2100_set_key_index(struct ipw2100_priv *priv, | |
5348 | int idx, int batch_mode) | |
5349 | { | |
5350 | struct host_command cmd = { | |
5351 | .host_command = WEP_KEY_INDEX, | |
5352 | .host_command_sequence = 0, | |
5353 | .host_command_length = 4, | |
011fe95a | 5354 | .host_command_parameters = { idx }, |
2c86c275 JK |
5355 | }; |
5356 | int err; | |
5357 | ||
5358 | IPW_DEBUG_HC("WEP_KEY_INDEX: index = %d\n", idx); | |
5359 | ||
5360 | if (idx < 0 || idx > 3) | |
5361 | return -EINVAL; | |
5362 | ||
5363 | if (!batch_mode) { | |
5364 | err = ipw2100_disable_adapter(priv); | |
5365 | if (err) { | |
797b4f76 | 5366 | printk(KERN_ERR DRV_NAME ": %s: Could not disable adapter %d\n", |
2c86c275 JK |
5367 | priv->net_dev->name, err); |
5368 | return err; | |
5369 | } | |
5370 | } | |
5371 | ||
5372 | /* send cmd to firmware */ | |
5373 | err = ipw2100_hw_send_command(priv, &cmd); | |
5374 | ||
5375 | if (!batch_mode) | |
5376 | ipw2100_enable_adapter(priv); | |
5377 | ||
5378 | return err; | |
5379 | } | |
5380 | ||
5381 | ||
5382 | static int ipw2100_configure_security(struct ipw2100_priv *priv, | |
5383 | int batch_mode) | |
5384 | { | |
5385 | int i, err, auth_mode, sec_level, use_group; | |
5386 | ||
5387 | if (!(priv->status & STATUS_RUNNING)) | |
5388 | return 0; | |
5389 | ||
5390 | if (!batch_mode) { | |
5391 | err = ipw2100_disable_adapter(priv); | |
5392 | if (err) | |
5393 | return err; | |
5394 | } | |
5395 | ||
5396 | if (!priv->sec.enabled) { | |
5397 | err = ipw2100_set_security_information( | |
5398 | priv, IPW_AUTH_OPEN, SEC_LEVEL_0, 0, 1); | |
5399 | } else { | |
5400 | auth_mode = IPW_AUTH_OPEN; | |
5401 | if ((priv->sec.flags & SEC_AUTH_MODE) && | |
5402 | (priv->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) | |
5403 | auth_mode = IPW_AUTH_SHARED; | |
5404 | ||
5405 | sec_level = SEC_LEVEL_0; | |
5406 | if (priv->sec.flags & SEC_LEVEL) | |
5407 | sec_level = priv->sec.level; | |
5408 | ||
5409 | use_group = 0; | |
5410 | if (priv->sec.flags & SEC_UNICAST_GROUP) | |
5411 | use_group = priv->sec.unicast_uses_group; | |
5412 | ||
5413 | err = ipw2100_set_security_information( | |
5414 | priv, auth_mode, sec_level, use_group, 1); | |
5415 | } | |
5416 | ||
5417 | if (err) | |
5418 | goto exit; | |
5419 | ||
5420 | if (priv->sec.enabled) { | |
5421 | for (i = 0; i < 4; i++) { | |
5422 | if (!(priv->sec.flags & (1 << i))) { | |
5423 | memset(priv->sec.keys[i], 0, WEP_KEY_LEN); | |
5424 | priv->sec.key_sizes[i] = 0; | |
5425 | } else { | |
5426 | err = ipw2100_set_key(priv, i, | |
5427 | priv->sec.keys[i], | |
5428 | priv->sec.key_sizes[i], | |
5429 | 1); | |
5430 | if (err) | |
5431 | goto exit; | |
5432 | } | |
5433 | } | |
5434 | ||
5435 | ipw2100_set_key_index(priv, priv->ieee->tx_keyidx, 1); | |
5436 | } | |
5437 | ||
5438 | /* Always enable privacy so the Host can filter WEP packets if | |
5439 | * encrypted data is sent up */ | |
5440 | err = ipw2100_set_wep_flags( | |
5441 | priv, priv->sec.enabled ? IPW_PRIVACY_CAPABLE : 0, 1); | |
5442 | if (err) | |
5443 | goto exit; | |
5444 | ||
5445 | priv->status &= ~STATUS_SECURITY_UPDATED; | |
5446 | ||
5447 | exit: | |
5448 | if (!batch_mode) | |
5449 | ipw2100_enable_adapter(priv); | |
5450 | ||
5451 | return err; | |
5452 | } | |
5453 | ||
5454 | static void ipw2100_security_work(struct ipw2100_priv *priv) | |
5455 | { | |
5456 | /* If we happen to have reconnected before we get a chance to | |
5457 | * process this, then update the security settings--which causes | |
5458 | * a disassociation to occur */ | |
5459 | if (!(priv->status & STATUS_ASSOCIATED) && | |
5460 | priv->status & STATUS_SECURITY_UPDATED) | |
5461 | ipw2100_configure_security(priv, 0); | |
5462 | } | |
5463 | ||
5464 | static void shim__set_security(struct net_device *dev, | |
5465 | struct ieee80211_security *sec) | |
5466 | { | |
5467 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
5468 | int i, force_update = 0; | |
5469 | ||
5470 | down(&priv->action_sem); | |
5471 | if (!(priv->status & STATUS_INITIALIZED)) | |
5472 | goto done; | |
5473 | ||
5474 | for (i = 0; i < 4; i++) { | |
5475 | if (sec->flags & (1 << i)) { | |
5476 | priv->sec.key_sizes[i] = sec->key_sizes[i]; | |
5477 | if (sec->key_sizes[i] == 0) | |
5478 | priv->sec.flags &= ~(1 << i); | |
5479 | else | |
5480 | memcpy(priv->sec.keys[i], sec->keys[i], | |
5481 | sec->key_sizes[i]); | |
5482 | priv->sec.flags |= (1 << i); | |
5483 | priv->status |= STATUS_SECURITY_UPDATED; | |
5484 | } | |
5485 | } | |
5486 | ||
5487 | if ((sec->flags & SEC_ACTIVE_KEY) && | |
5488 | priv->sec.active_key != sec->active_key) { | |
5489 | if (sec->active_key <= 3) { | |
5490 | priv->sec.active_key = sec->active_key; | |
5491 | priv->sec.flags |= SEC_ACTIVE_KEY; | |
5492 | } else | |
5493 | priv->sec.flags &= ~SEC_ACTIVE_KEY; | |
5494 | ||
5495 | priv->status |= STATUS_SECURITY_UPDATED; | |
5496 | } | |
5497 | ||
5498 | if ((sec->flags & SEC_AUTH_MODE) && | |
5499 | (priv->sec.auth_mode != sec->auth_mode)) { | |
5500 | priv->sec.auth_mode = sec->auth_mode; | |
5501 | priv->sec.flags |= SEC_AUTH_MODE; | |
5502 | priv->status |= STATUS_SECURITY_UPDATED; | |
5503 | } | |
5504 | ||
5505 | if (sec->flags & SEC_ENABLED && | |
5506 | priv->sec.enabled != sec->enabled) { | |
5507 | priv->sec.flags |= SEC_ENABLED; | |
5508 | priv->sec.enabled = sec->enabled; | |
5509 | priv->status |= STATUS_SECURITY_UPDATED; | |
5510 | force_update = 1; | |
5511 | } | |
5512 | ||
5513 | if (sec->flags & SEC_LEVEL && | |
5514 | priv->sec.level != sec->level) { | |
5515 | priv->sec.level = sec->level; | |
5516 | priv->sec.flags |= SEC_LEVEL; | |
5517 | priv->status |= STATUS_SECURITY_UPDATED; | |
5518 | } | |
5519 | ||
5520 | IPW_DEBUG_WEP("Security flags: %c %c%c%c%c %c%c%c%c\n", | |
5521 | priv->sec.flags & (1<<8) ? '1' : '0', | |
5522 | priv->sec.flags & (1<<7) ? '1' : '0', | |
5523 | priv->sec.flags & (1<<6) ? '1' : '0', | |
5524 | priv->sec.flags & (1<<5) ? '1' : '0', | |
5525 | priv->sec.flags & (1<<4) ? '1' : '0', | |
5526 | priv->sec.flags & (1<<3) ? '1' : '0', | |
5527 | priv->sec.flags & (1<<2) ? '1' : '0', | |
5528 | priv->sec.flags & (1<<1) ? '1' : '0', | |
5529 | priv->sec.flags & (1<<0) ? '1' : '0'); | |
5530 | ||
5531 | /* As a temporary work around to enable WPA until we figure out why | |
5532 | * wpa_supplicant toggles the security capability of the driver, which | |
5533 | * forces a disassocation with force_update... | |
5534 | * | |
5535 | * if (force_update || !(priv->status & STATUS_ASSOCIATED))*/ | |
5536 | if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) | |
5537 | ipw2100_configure_security(priv, 0); | |
5538 | done: | |
5539 | up(&priv->action_sem); | |
5540 | } | |
5541 | ||
5542 | static int ipw2100_adapter_setup(struct ipw2100_priv *priv) | |
5543 | { | |
5544 | int err; | |
5545 | int batch_mode = 1; | |
5546 | u8 *bssid; | |
5547 | ||
5548 | IPW_DEBUG_INFO("enter\n"); | |
5549 | ||
5550 | err = ipw2100_disable_adapter(priv); | |
5551 | if (err) | |
5552 | return err; | |
5553 | #ifdef CONFIG_IPW2100_MONITOR | |
5554 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { | |
5555 | err = ipw2100_set_channel(priv, priv->channel, batch_mode); | |
5556 | if (err) | |
5557 | return err; | |
5558 | ||
5559 | IPW_DEBUG_INFO("exit\n"); | |
5560 | ||
5561 | return 0; | |
5562 | } | |
5563 | #endif /* CONFIG_IPW2100_MONITOR */ | |
5564 | ||
5565 | err = ipw2100_read_mac_address(priv); | |
5566 | if (err) | |
5567 | return -EIO; | |
5568 | ||
5569 | err = ipw2100_set_mac_address(priv, batch_mode); | |
5570 | if (err) | |
5571 | return err; | |
5572 | ||
5573 | err = ipw2100_set_port_type(priv, priv->ieee->iw_mode, batch_mode); | |
5574 | if (err) | |
5575 | return err; | |
5576 | ||
5577 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { | |
5578 | err = ipw2100_set_channel(priv, priv->channel, batch_mode); | |
5579 | if (err) | |
5580 | return err; | |
5581 | } | |
5582 | ||
5583 | err = ipw2100_system_config(priv, batch_mode); | |
5584 | if (err) | |
5585 | return err; | |
5586 | ||
5587 | err = ipw2100_set_tx_rates(priv, priv->tx_rates, batch_mode); | |
5588 | if (err) | |
5589 | return err; | |
5590 | ||
5591 | /* Default to power mode OFF */ | |
5592 | err = ipw2100_set_power_mode(priv, IPW_POWER_MODE_CAM); | |
5593 | if (err) | |
5594 | return err; | |
5595 | ||
5596 | err = ipw2100_set_rts_threshold(priv, priv->rts_threshold); | |
5597 | if (err) | |
5598 | return err; | |
5599 | ||
5600 | if (priv->config & CFG_STATIC_BSSID) | |
5601 | bssid = priv->bssid; | |
5602 | else | |
5603 | bssid = NULL; | |
5604 | err = ipw2100_set_mandatory_bssid(priv, bssid, batch_mode); | |
5605 | if (err) | |
5606 | return err; | |
5607 | ||
5608 | if (priv->config & CFG_STATIC_ESSID) | |
5609 | err = ipw2100_set_essid(priv, priv->essid, priv->essid_len, | |
5610 | batch_mode); | |
5611 | else | |
5612 | err = ipw2100_set_essid(priv, NULL, 0, batch_mode); | |
5613 | if (err) | |
5614 | return err; | |
5615 | ||
5616 | err = ipw2100_configure_security(priv, batch_mode); | |
5617 | if (err) | |
5618 | return err; | |
5619 | ||
5620 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { | |
5621 | err = ipw2100_set_ibss_beacon_interval( | |
5622 | priv, priv->beacon_interval, batch_mode); | |
5623 | if (err) | |
5624 | return err; | |
5625 | ||
5626 | err = ipw2100_set_tx_power(priv, priv->tx_power); | |
5627 | if (err) | |
5628 | return err; | |
5629 | } | |
5630 | ||
5631 | /* | |
5632 | err = ipw2100_set_fragmentation_threshold( | |
5633 | priv, priv->frag_threshold, batch_mode); | |
5634 | if (err) | |
5635 | return err; | |
5636 | */ | |
5637 | ||
5638 | IPW_DEBUG_INFO("exit\n"); | |
5639 | ||
5640 | return 0; | |
5641 | } | |
5642 | ||
5643 | ||
5644 | /************************************************************************* | |
5645 | * | |
5646 | * EXTERNALLY CALLED METHODS | |
5647 | * | |
5648 | *************************************************************************/ | |
5649 | ||
5650 | /* This method is called by the network layer -- not to be confused with | |
5651 | * ipw2100_set_mac_address() declared above called by this driver (and this | |
5652 | * method as well) to talk to the firmware */ | |
5653 | static int ipw2100_set_address(struct net_device *dev, void *p) | |
5654 | { | |
5655 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
5656 | struct sockaddr *addr = p; | |
5657 | int err = 0; | |
5658 | ||
5659 | if (!is_valid_ether_addr(addr->sa_data)) | |
5660 | return -EADDRNOTAVAIL; | |
5661 | ||
5662 | down(&priv->action_sem); | |
5663 | ||
5664 | priv->config |= CFG_CUSTOM_MAC; | |
5665 | memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN); | |
5666 | ||
5667 | err = ipw2100_set_mac_address(priv, 0); | |
5668 | if (err) | |
5669 | goto done; | |
5670 | ||
5671 | priv->reset_backoff = 0; | |
5672 | up(&priv->action_sem); | |
5673 | ipw2100_reset_adapter(priv); | |
5674 | return 0; | |
5675 | ||
5676 | done: | |
5677 | up(&priv->action_sem); | |
5678 | return err; | |
5679 | } | |
5680 | ||
5681 | static int ipw2100_open(struct net_device *dev) | |
5682 | { | |
5683 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
5684 | unsigned long flags; | |
5685 | IPW_DEBUG_INFO("dev->open\n"); | |
5686 | ||
5687 | spin_lock_irqsave(&priv->low_lock, flags); | |
5688 | if (priv->status & STATUS_ASSOCIATED) | |
5689 | netif_start_queue(dev); | |
5690 | spin_unlock_irqrestore(&priv->low_lock, flags); | |
5691 | ||
5692 | return 0; | |
5693 | } | |
5694 | ||
5695 | static int ipw2100_close(struct net_device *dev) | |
5696 | { | |
5697 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
5698 | unsigned long flags; | |
5699 | struct list_head *element; | |
5700 | struct ipw2100_tx_packet *packet; | |
5701 | ||
5702 | IPW_DEBUG_INFO("enter\n"); | |
5703 | ||
5704 | spin_lock_irqsave(&priv->low_lock, flags); | |
5705 | ||
5706 | if (priv->status & STATUS_ASSOCIATED) | |
5707 | netif_carrier_off(dev); | |
5708 | netif_stop_queue(dev); | |
5709 | ||
5710 | /* Flush the TX queue ... */ | |
5711 | while (!list_empty(&priv->tx_pend_list)) { | |
5712 | element = priv->tx_pend_list.next; | |
5713 | packet = list_entry(element, struct ipw2100_tx_packet, list); | |
5714 | ||
5715 | list_del(element); | |
5716 | DEC_STAT(&priv->tx_pend_stat); | |
5717 | ||
5718 | ieee80211_txb_free(packet->info.d_struct.txb); | |
5719 | packet->info.d_struct.txb = NULL; | |
5720 | ||
5721 | list_add_tail(element, &priv->tx_free_list); | |
5722 | INC_STAT(&priv->tx_free_stat); | |
5723 | } | |
5724 | spin_unlock_irqrestore(&priv->low_lock, flags); | |
5725 | ||
5726 | IPW_DEBUG_INFO("exit\n"); | |
5727 | ||
5728 | return 0; | |
5729 | } | |
5730 | ||
5731 | ||
5732 | ||
5733 | /* | |
5734 | * TODO: Fix this function... its just wrong | |
5735 | */ | |
5736 | static void ipw2100_tx_timeout(struct net_device *dev) | |
5737 | { | |
5738 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
5739 | ||
5740 | priv->ieee->stats.tx_errors++; | |
5741 | ||
5742 | #ifdef CONFIG_IPW2100_MONITOR | |
5743 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) | |
5744 | return; | |
5745 | #endif | |
5746 | ||
5747 | IPW_DEBUG_INFO("%s: TX timed out. Scheduling firmware restart.\n", | |
5748 | dev->name); | |
5749 | schedule_reset(priv); | |
5750 | } | |
5751 | ||
5752 | ||
5753 | /* | |
5754 | * TODO: reimplement it so that it reads statistics | |
5755 | * from the adapter using ordinal tables | |
5756 | * instead of/in addition to collecting them | |
5757 | * in the driver | |
5758 | */ | |
5759 | static struct net_device_stats *ipw2100_stats(struct net_device *dev) | |
5760 | { | |
5761 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
5762 | ||
5763 | return &priv->ieee->stats; | |
5764 | } | |
5765 | ||
5766 | /* Support for wpa_supplicant. Will be replaced with WEXT once | |
5767 | * they get WPA support. */ | |
5768 | #ifdef CONFIG_IEEE80211_WPA | |
5769 | ||
5770 | /* following definitions must match definitions in driver_ipw2100.c */ | |
5771 | ||
5772 | #define IPW2100_IOCTL_WPA_SUPPLICANT SIOCIWFIRSTPRIV+30 | |
5773 | ||
5774 | #define IPW2100_CMD_SET_WPA_PARAM 1 | |
5775 | #define IPW2100_CMD_SET_WPA_IE 2 | |
5776 | #define IPW2100_CMD_SET_ENCRYPTION 3 | |
5777 | #define IPW2100_CMD_MLME 4 | |
5778 | ||
5779 | #define IPW2100_PARAM_WPA_ENABLED 1 | |
5780 | #define IPW2100_PARAM_TKIP_COUNTERMEASURES 2 | |
5781 | #define IPW2100_PARAM_DROP_UNENCRYPTED 3 | |
5782 | #define IPW2100_PARAM_PRIVACY_INVOKED 4 | |
5783 | #define IPW2100_PARAM_AUTH_ALGS 5 | |
5784 | #define IPW2100_PARAM_IEEE_802_1X 6 | |
5785 | ||
5786 | #define IPW2100_MLME_STA_DEAUTH 1 | |
5787 | #define IPW2100_MLME_STA_DISASSOC 2 | |
5788 | ||
5789 | #define IPW2100_CRYPT_ERR_UNKNOWN_ALG 2 | |
5790 | #define IPW2100_CRYPT_ERR_UNKNOWN_ADDR 3 | |
5791 | #define IPW2100_CRYPT_ERR_CRYPT_INIT_FAILED 4 | |
5792 | #define IPW2100_CRYPT_ERR_KEY_SET_FAILED 5 | |
5793 | #define IPW2100_CRYPT_ERR_TX_KEY_SET_FAILED 6 | |
5794 | #define IPW2100_CRYPT_ERR_CARD_CONF_FAILED 7 | |
5795 | ||
5796 | #define IPW2100_CRYPT_ALG_NAME_LEN 16 | |
5797 | ||
5798 | struct ipw2100_param { | |
5799 | u32 cmd; | |
5800 | u8 sta_addr[ETH_ALEN]; | |
5801 | union { | |
5802 | struct { | |
5803 | u8 name; | |
5804 | u32 value; | |
5805 | } wpa_param; | |
5806 | struct { | |
5807 | u32 len; | |
5808 | u8 *data; | |
5809 | } wpa_ie; | |
5810 | struct{ | |
5811 | int command; | |
5812 | int reason_code; | |
5813 | } mlme; | |
5814 | struct { | |
5815 | u8 alg[IPW2100_CRYPT_ALG_NAME_LEN]; | |
5816 | u8 set_tx; | |
5817 | u32 err; | |
5818 | u8 idx; | |
5819 | u8 seq[8]; /* sequence counter (set: RX, get: TX) */ | |
5820 | u16 key_len; | |
5821 | u8 key[0]; | |
5822 | } crypt; | |
5823 | ||
5824 | } u; | |
5825 | }; | |
5826 | ||
5827 | /* end of driver_ipw2100.c code */ | |
5828 | ||
5829 | static int ipw2100_wpa_enable(struct ipw2100_priv *priv, int value){ | |
5830 | ||
5831 | struct ieee80211_device *ieee = priv->ieee; | |
5832 | struct ieee80211_security sec = { | |
5833 | .flags = SEC_LEVEL | SEC_ENABLED, | |
5834 | }; | |
5835 | int ret = 0; | |
5836 | ||
5837 | ieee->wpa_enabled = value; | |
5838 | ||
5839 | if (value){ | |
5840 | sec.level = SEC_LEVEL_3; | |
5841 | sec.enabled = 1; | |
5842 | } else { | |
5843 | sec.level = SEC_LEVEL_0; | |
5844 | sec.enabled = 0; | |
5845 | } | |
5846 | ||
5847 | if (ieee->set_security) | |
5848 | ieee->set_security(ieee->dev, &sec); | |
5849 | else | |
5850 | ret = -EOPNOTSUPP; | |
5851 | ||
5852 | return ret; | |
5853 | } | |
5854 | ||
5855 | #define AUTH_ALG_OPEN_SYSTEM 0x1 | |
5856 | #define AUTH_ALG_SHARED_KEY 0x2 | |
5857 | ||
5858 | static int ipw2100_wpa_set_auth_algs(struct ipw2100_priv *priv, int value){ | |
5859 | ||
5860 | struct ieee80211_device *ieee = priv->ieee; | |
5861 | struct ieee80211_security sec = { | |
5862 | .flags = SEC_AUTH_MODE, | |
5863 | }; | |
5864 | int ret = 0; | |
5865 | ||
5866 | if (value & AUTH_ALG_SHARED_KEY){ | |
5867 | sec.auth_mode = WLAN_AUTH_SHARED_KEY; | |
5868 | ieee->open_wep = 0; | |
5869 | } else { | |
5870 | sec.auth_mode = WLAN_AUTH_OPEN; | |
5871 | ieee->open_wep = 1; | |
5872 | } | |
5873 | ||
5874 | if (ieee->set_security) | |
5875 | ieee->set_security(ieee->dev, &sec); | |
5876 | else | |
5877 | ret = -EOPNOTSUPP; | |
5878 | ||
5879 | return ret; | |
5880 | } | |
5881 | ||
5882 | ||
5883 | static int ipw2100_wpa_set_param(struct net_device *dev, u8 name, u32 value){ | |
5884 | ||
5885 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
5886 | int ret=0; | |
5887 | ||
5888 | switch(name){ | |
5889 | case IPW2100_PARAM_WPA_ENABLED: | |
5890 | ret = ipw2100_wpa_enable(priv, value); | |
5891 | break; | |
5892 | ||
5893 | case IPW2100_PARAM_TKIP_COUNTERMEASURES: | |
5894 | priv->ieee->tkip_countermeasures=value; | |
5895 | break; | |
5896 | ||
5897 | case IPW2100_PARAM_DROP_UNENCRYPTED: | |
5898 | priv->ieee->drop_unencrypted=value; | |
5899 | break; | |
5900 | ||
5901 | case IPW2100_PARAM_PRIVACY_INVOKED: | |
5902 | priv->ieee->privacy_invoked=value; | |
5903 | break; | |
5904 | ||
5905 | case IPW2100_PARAM_AUTH_ALGS: | |
5906 | ret = ipw2100_wpa_set_auth_algs(priv, value); | |
5907 | break; | |
5908 | ||
5909 | case IPW2100_PARAM_IEEE_802_1X: | |
5910 | priv->ieee->ieee802_1x=value; | |
5911 | break; | |
5912 | ||
5913 | default: | |
797b4f76 | 5914 | printk(KERN_ERR DRV_NAME ": %s: Unknown WPA param: %d\n", |
2c86c275 JK |
5915 | dev->name, name); |
5916 | ret = -EOPNOTSUPP; | |
5917 | } | |
5918 | ||
5919 | return ret; | |
5920 | } | |
5921 | ||
5922 | static int ipw2100_wpa_mlme(struct net_device *dev, int command, int reason){ | |
5923 | ||
5924 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
5925 | int ret=0; | |
5926 | ||
5927 | switch(command){ | |
5928 | case IPW2100_MLME_STA_DEAUTH: | |
5929 | // silently ignore | |
5930 | break; | |
5931 | ||
5932 | case IPW2100_MLME_STA_DISASSOC: | |
5933 | ipw2100_disassociate_bssid(priv); | |
5934 | break; | |
5935 | ||
5936 | default: | |
797b4f76 | 5937 | printk(KERN_ERR DRV_NAME ": %s: Unknown MLME request: %d\n", |
2c86c275 JK |
5938 | dev->name, command); |
5939 | ret = -EOPNOTSUPP; | |
5940 | } | |
5941 | ||
5942 | return ret; | |
5943 | } | |
5944 | ||
5945 | ||
5946 | void ipw2100_wpa_assoc_frame(struct ipw2100_priv *priv, | |
5947 | char *wpa_ie, int wpa_ie_len){ | |
5948 | ||
5949 | struct ipw2100_wpa_assoc_frame frame; | |
5950 | ||
5951 | frame.fixed_ie_mask = 0; | |
5952 | ||
5953 | /* copy WPA IE */ | |
5954 | memcpy(frame.var_ie, wpa_ie, wpa_ie_len); | |
5955 | frame.var_ie_len = wpa_ie_len; | |
5956 | ||
5957 | /* make sure WPA is enabled */ | |
5958 | ipw2100_wpa_enable(priv, 1); | |
5959 | ipw2100_set_wpa_ie(priv, &frame, 0); | |
5960 | } | |
5961 | ||
5962 | ||
5963 | static int ipw2100_wpa_set_wpa_ie(struct net_device *dev, | |
5964 | struct ipw2100_param *param, int plen){ | |
5965 | ||
5966 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
5967 | struct ieee80211_device *ieee = priv->ieee; | |
5968 | u8 *buf; | |
5969 | ||
5970 | if (! ieee->wpa_enabled) | |
5971 | return -EOPNOTSUPP; | |
5972 | ||
5973 | if (param->u.wpa_ie.len > MAX_WPA_IE_LEN || | |
5974 | (param->u.wpa_ie.len && | |
5975 | param->u.wpa_ie.data==NULL)) | |
5976 | return -EINVAL; | |
5977 | ||
5978 | if (param->u.wpa_ie.len){ | |
5979 | buf = kmalloc(param->u.wpa_ie.len, GFP_KERNEL); | |
5980 | if (buf == NULL) | |
5981 | return -ENOMEM; | |
5982 | ||
5983 | memcpy(buf, param->u.wpa_ie.data, param->u.wpa_ie.len); | |
5984 | ||
5985 | kfree(ieee->wpa_ie); | |
5986 | ieee->wpa_ie = buf; | |
5987 | ieee->wpa_ie_len = param->u.wpa_ie.len; | |
5988 | ||
5989 | } else { | |
5990 | kfree(ieee->wpa_ie); | |
5991 | ieee->wpa_ie = NULL; | |
5992 | ieee->wpa_ie_len = 0; | |
5993 | } | |
5994 | ||
5995 | ipw2100_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len); | |
5996 | ||
5997 | return 0; | |
5998 | } | |
5999 | ||
6000 | /* implementation borrowed from hostap driver */ | |
6001 | ||
6002 | static int ipw2100_wpa_set_encryption(struct net_device *dev, | |
6003 | struct ipw2100_param *param, int param_len){ | |
6004 | ||
6005 | int ret = 0; | |
6006 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
6007 | struct ieee80211_device *ieee = priv->ieee; | |
6008 | struct ieee80211_crypto_ops *ops; | |
6009 | struct ieee80211_crypt_data **crypt; | |
6010 | ||
6011 | struct ieee80211_security sec = { | |
6012 | .flags = 0, | |
6013 | }; | |
6014 | ||
6015 | param->u.crypt.err = 0; | |
6016 | param->u.crypt.alg[IPW2100_CRYPT_ALG_NAME_LEN - 1] = '\0'; | |
6017 | ||
6018 | if (param_len != | |
6019 | (int) ((char *) param->u.crypt.key - (char *) param) + | |
6020 | param->u.crypt.key_len){ | |
6021 | IPW_DEBUG_INFO("Len mismatch %d, %d\n", param_len, param->u.crypt.key_len); | |
6022 | return -EINVAL; | |
6023 | } | |
6024 | if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff && | |
6025 | param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff && | |
6026 | param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) { | |
6027 | if (param->u.crypt.idx >= WEP_KEYS) | |
6028 | return -EINVAL; | |
6029 | crypt = &ieee->crypt[param->u.crypt.idx]; | |
6030 | } else { | |
6031 | return -EINVAL; | |
6032 | } | |
6033 | ||
6034 | if (strcmp(param->u.crypt.alg, "none") == 0) { | |
6035 | if (crypt){ | |
6036 | sec.enabled = 0; | |
6037 | sec.level = SEC_LEVEL_0; | |
6038 | sec.flags |= SEC_ENABLED | SEC_LEVEL; | |
6039 | ieee80211_crypt_delayed_deinit(ieee, crypt); | |
6040 | } | |
6041 | goto done; | |
6042 | } | |
6043 | sec.enabled = 1; | |
6044 | sec.flags |= SEC_ENABLED; | |
6045 | ||
6046 | ops = ieee80211_get_crypto_ops(param->u.crypt.alg); | |
6047 | if (ops == NULL && strcmp(param->u.crypt.alg, "WEP") == 0) { | |
6048 | request_module("ieee80211_crypt_wep"); | |
6049 | ops = ieee80211_get_crypto_ops(param->u.crypt.alg); | |
6050 | } else if (ops == NULL && strcmp(param->u.crypt.alg, "TKIP") == 0) { | |
6051 | request_module("ieee80211_crypt_tkip"); | |
6052 | ops = ieee80211_get_crypto_ops(param->u.crypt.alg); | |
6053 | } else if (ops == NULL && strcmp(param->u.crypt.alg, "CCMP") == 0) { | |
6054 | request_module("ieee80211_crypt_ccmp"); | |
6055 | ops = ieee80211_get_crypto_ops(param->u.crypt.alg); | |
6056 | } | |
6057 | if (ops == NULL) { | |
6058 | IPW_DEBUG_INFO("%s: unknown crypto alg '%s'\n", | |
6059 | dev->name, param->u.crypt.alg); | |
6060 | param->u.crypt.err = IPW2100_CRYPT_ERR_UNKNOWN_ALG; | |
6061 | ret = -EINVAL; | |
6062 | goto done; | |
6063 | } | |
6064 | ||
6065 | if (*crypt == NULL || (*crypt)->ops != ops) { | |
6066 | struct ieee80211_crypt_data *new_crypt; | |
6067 | ||
6068 | ieee80211_crypt_delayed_deinit(ieee, crypt); | |
6069 | ||
6070 | new_crypt = (struct ieee80211_crypt_data *) | |
6071 | kmalloc(sizeof(struct ieee80211_crypt_data), GFP_KERNEL); | |
6072 | if (new_crypt == NULL) { | |
6073 | ret = -ENOMEM; | |
6074 | goto done; | |
6075 | } | |
6076 | memset(new_crypt, 0, sizeof(struct ieee80211_crypt_data)); | |
6077 | new_crypt->ops = ops; | |
6078 | if (new_crypt->ops && try_module_get(new_crypt->ops->owner)) | |
6079 | new_crypt->priv = new_crypt->ops->init(param->u.crypt.idx); | |
6080 | ||
6081 | if (new_crypt->priv == NULL) { | |
6082 | kfree(new_crypt); | |
6083 | param->u.crypt.err = | |
6084 | IPW2100_CRYPT_ERR_CRYPT_INIT_FAILED; | |
6085 | ret = -EINVAL; | |
6086 | goto done; | |
6087 | } | |
6088 | ||
6089 | *crypt = new_crypt; | |
6090 | } | |
6091 | ||
6092 | if (param->u.crypt.key_len > 0 && (*crypt)->ops->set_key && | |
6093 | (*crypt)->ops->set_key(param->u.crypt.key, | |
6094 | param->u.crypt.key_len, param->u.crypt.seq, | |
6095 | (*crypt)->priv) < 0) { | |
6096 | IPW_DEBUG_INFO("%s: key setting failed\n", | |
6097 | dev->name); | |
6098 | param->u.crypt.err = IPW2100_CRYPT_ERR_KEY_SET_FAILED; | |
6099 | ret = -EINVAL; | |
6100 | goto done; | |
6101 | } | |
6102 | ||
6103 | if (param->u.crypt.set_tx){ | |
6104 | ieee->tx_keyidx = param->u.crypt.idx; | |
6105 | sec.active_key = param->u.crypt.idx; | |
6106 | sec.flags |= SEC_ACTIVE_KEY; | |
6107 | } | |
6108 | ||
6109 | if (ops->name != NULL){ | |
6110 | ||
6111 | if (strcmp(ops->name, "WEP") == 0) { | |
6112 | memcpy(sec.keys[param->u.crypt.idx], param->u.crypt.key, param->u.crypt.key_len); | |
6113 | sec.key_sizes[param->u.crypt.idx] = param->u.crypt.key_len; | |
6114 | sec.flags |= (1 << param->u.crypt.idx); | |
6115 | sec.flags |= SEC_LEVEL; | |
6116 | sec.level = SEC_LEVEL_1; | |
6117 | } else if (strcmp(ops->name, "TKIP") == 0) { | |
6118 | sec.flags |= SEC_LEVEL; | |
6119 | sec.level = SEC_LEVEL_2; | |
6120 | } else if (strcmp(ops->name, "CCMP") == 0) { | |
6121 | sec.flags |= SEC_LEVEL; | |
6122 | sec.level = SEC_LEVEL_3; | |
6123 | } | |
6124 | } | |
6125 | done: | |
6126 | if (ieee->set_security) | |
6127 | ieee->set_security(ieee->dev, &sec); | |
6128 | ||
6129 | /* Do not reset port if card is in Managed mode since resetting will | |
6130 | * generate new IEEE 802.11 authentication which may end up in looping | |
6131 | * with IEEE 802.1X. If your hardware requires a reset after WEP | |
6132 | * configuration (for example... Prism2), implement the reset_port in | |
6133 | * the callbacks structures used to initialize the 802.11 stack. */ | |
6134 | if (ieee->reset_on_keychange && | |
6135 | ieee->iw_mode != IW_MODE_INFRA && | |
6136 | ieee->reset_port && | |
6137 | ieee->reset_port(dev)) { | |
6138 | IPW_DEBUG_INFO("%s: reset_port failed\n", dev->name); | |
6139 | param->u.crypt.err = IPW2100_CRYPT_ERR_CARD_CONF_FAILED; | |
6140 | return -EINVAL; | |
6141 | } | |
6142 | ||
6143 | return ret; | |
6144 | } | |
6145 | ||
6146 | ||
6147 | static int ipw2100_wpa_supplicant(struct net_device *dev, struct iw_point *p){ | |
6148 | ||
6149 | struct ipw2100_param *param; | |
6150 | int ret=0; | |
6151 | ||
6152 | IPW_DEBUG_IOCTL("wpa_supplicant: len=%d\n", p->length); | |
6153 | ||
6154 | if (p->length < sizeof(struct ipw2100_param) || !p->pointer) | |
6155 | return -EINVAL; | |
6156 | ||
6157 | param = (struct ipw2100_param *)kmalloc(p->length, GFP_KERNEL); | |
6158 | if (param == NULL) | |
6159 | return -ENOMEM; | |
6160 | ||
6161 | if (copy_from_user(param, p->pointer, p->length)){ | |
6162 | kfree(param); | |
6163 | return -EFAULT; | |
6164 | } | |
6165 | ||
6166 | switch (param->cmd){ | |
6167 | ||
6168 | case IPW2100_CMD_SET_WPA_PARAM: | |
6169 | ret = ipw2100_wpa_set_param(dev, param->u.wpa_param.name, | |
6170 | param->u.wpa_param.value); | |
6171 | break; | |
6172 | ||
6173 | case IPW2100_CMD_SET_WPA_IE: | |
6174 | ret = ipw2100_wpa_set_wpa_ie(dev, param, p->length); | |
6175 | break; | |
6176 | ||
6177 | case IPW2100_CMD_SET_ENCRYPTION: | |
6178 | ret = ipw2100_wpa_set_encryption(dev, param, p->length); | |
6179 | break; | |
6180 | ||
6181 | case IPW2100_CMD_MLME: | |
6182 | ret = ipw2100_wpa_mlme(dev, param->u.mlme.command, | |
6183 | param->u.mlme.reason_code); | |
6184 | break; | |
6185 | ||
6186 | default: | |
797b4f76 | 6187 | printk(KERN_ERR DRV_NAME ": %s: Unknown WPA supplicant request: %d\n", |
2c86c275 JK |
6188 | dev->name, param->cmd); |
6189 | ret = -EOPNOTSUPP; | |
6190 | ||
6191 | } | |
6192 | ||
6193 | if (ret == 0 && copy_to_user(p->pointer, param, p->length)) | |
6194 | ret = -EFAULT; | |
6195 | ||
6196 | kfree(param); | |
6197 | return ret; | |
6198 | } | |
6199 | #endif /* CONFIG_IEEE80211_WPA */ | |
6200 | ||
6201 | static int ipw2100_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) | |
6202 | { | |
6203 | #ifdef CONFIG_IEEE80211_WPA | |
6204 | struct iwreq *wrq = (struct iwreq *) rq; | |
6205 | int ret=-1; | |
6206 | switch (cmd){ | |
6207 | case IPW2100_IOCTL_WPA_SUPPLICANT: | |
6208 | ret = ipw2100_wpa_supplicant(dev, &wrq->u.data); | |
6209 | return ret; | |
6210 | ||
6211 | default: | |
6212 | return -EOPNOTSUPP; | |
6213 | } | |
6214 | ||
6215 | #endif /* CONFIG_IEEE80211_WPA */ | |
6216 | ||
6217 | return -EOPNOTSUPP; | |
6218 | } | |
6219 | ||
6220 | ||
6221 | static void ipw_ethtool_get_drvinfo(struct net_device *dev, | |
6222 | struct ethtool_drvinfo *info) | |
6223 | { | |
6224 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
6225 | char fw_ver[64], ucode_ver[64]; | |
6226 | ||
6227 | strcpy(info->driver, DRV_NAME); | |
6228 | strcpy(info->version, DRV_VERSION); | |
6229 | ||
6230 | ipw2100_get_fwversion(priv, fw_ver, sizeof(fw_ver)); | |
6231 | ipw2100_get_ucodeversion(priv, ucode_ver, sizeof(ucode_ver)); | |
6232 | ||
6233 | snprintf(info->fw_version, sizeof(info->fw_version), "%s:%d:%s", | |
6234 | fw_ver, priv->eeprom_version, ucode_ver); | |
6235 | ||
6236 | strcpy(info->bus_info, pci_name(priv->pci_dev)); | |
6237 | } | |
6238 | ||
6239 | static u32 ipw2100_ethtool_get_link(struct net_device *dev) | |
6240 | { | |
6241 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
6242 | return (priv->status & STATUS_ASSOCIATED) ? 1 : 0; | |
6243 | } | |
6244 | ||
6245 | ||
6246 | static struct ethtool_ops ipw2100_ethtool_ops = { | |
6247 | .get_link = ipw2100_ethtool_get_link, | |
6248 | .get_drvinfo = ipw_ethtool_get_drvinfo, | |
6249 | }; | |
6250 | ||
6251 | static void ipw2100_hang_check(void *adapter) | |
6252 | { | |
6253 | struct ipw2100_priv *priv = adapter; | |
6254 | unsigned long flags; | |
6255 | u32 rtc = 0xa5a5a5a5; | |
6256 | u32 len = sizeof(rtc); | |
6257 | int restart = 0; | |
6258 | ||
6259 | spin_lock_irqsave(&priv->low_lock, flags); | |
6260 | ||
6261 | if (priv->fatal_error != 0) { | |
6262 | /* If fatal_error is set then we need to restart */ | |
6263 | IPW_DEBUG_INFO("%s: Hardware fatal error detected.\n", | |
6264 | priv->net_dev->name); | |
6265 | ||
6266 | restart = 1; | |
6267 | } else if (ipw2100_get_ordinal(priv, IPW_ORD_RTC_TIME, &rtc, &len) || | |
6268 | (rtc == priv->last_rtc)) { | |
6269 | /* Check if firmware is hung */ | |
6270 | IPW_DEBUG_INFO("%s: Firmware RTC stalled.\n", | |
6271 | priv->net_dev->name); | |
6272 | ||
6273 | restart = 1; | |
6274 | } | |
6275 | ||
6276 | if (restart) { | |
6277 | /* Kill timer */ | |
6278 | priv->stop_hang_check = 1; | |
6279 | priv->hangs++; | |
6280 | ||
6281 | /* Restart the NIC */ | |
6282 | schedule_reset(priv); | |
6283 | } | |
6284 | ||
6285 | priv->last_rtc = rtc; | |
6286 | ||
6287 | if (!priv->stop_hang_check) | |
6288 | queue_delayed_work(priv->workqueue, &priv->hang_check, HZ / 2); | |
6289 | ||
6290 | spin_unlock_irqrestore(&priv->low_lock, flags); | |
6291 | } | |
6292 | ||
6293 | ||
6294 | static void ipw2100_rf_kill(void *adapter) | |
6295 | { | |
6296 | struct ipw2100_priv *priv = adapter; | |
6297 | unsigned long flags; | |
6298 | ||
6299 | spin_lock_irqsave(&priv->low_lock, flags); | |
6300 | ||
6301 | if (rf_kill_active(priv)) { | |
6302 | IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n"); | |
6303 | if (!priv->stop_rf_kill) | |
6304 | queue_delayed_work(priv->workqueue, &priv->rf_kill, HZ); | |
6305 | goto exit_unlock; | |
6306 | } | |
6307 | ||
6308 | /* RF Kill is now disabled, so bring the device back up */ | |
6309 | ||
6310 | if (!(priv->status & STATUS_RF_KILL_MASK)) { | |
6311 | IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting " | |
6312 | "device\n"); | |
6313 | schedule_reset(priv); | |
6314 | } else | |
6315 | IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still " | |
6316 | "enabled\n"); | |
6317 | ||
6318 | exit_unlock: | |
6319 | spin_unlock_irqrestore(&priv->low_lock, flags); | |
6320 | } | |
6321 | ||
6322 | static void ipw2100_irq_tasklet(struct ipw2100_priv *priv); | |
6323 | ||
6324 | /* Look into using netdev destructor to shutdown ieee80211? */ | |
6325 | ||
6326 | static struct net_device *ipw2100_alloc_device( | |
6327 | struct pci_dev *pci_dev, | |
6328 | char *base_addr, | |
6329 | unsigned long mem_start, | |
6330 | unsigned long mem_len) | |
6331 | { | |
6332 | struct ipw2100_priv *priv; | |
6333 | struct net_device *dev; | |
6334 | ||
6335 | dev = alloc_ieee80211(sizeof(struct ipw2100_priv)); | |
6336 | if (!dev) | |
6337 | return NULL; | |
6338 | priv = ieee80211_priv(dev); | |
6339 | priv->ieee = netdev_priv(dev); | |
6340 | priv->pci_dev = pci_dev; | |
6341 | priv->net_dev = dev; | |
6342 | ||
6343 | priv->ieee->hard_start_xmit = ipw2100_tx; | |
6344 | priv->ieee->set_security = shim__set_security; | |
6345 | ||
6346 | dev->open = ipw2100_open; | |
6347 | dev->stop = ipw2100_close; | |
6348 | dev->init = ipw2100_net_init; | |
6349 | dev->do_ioctl = ipw2100_ioctl; | |
6350 | dev->get_stats = ipw2100_stats; | |
6351 | dev->ethtool_ops = &ipw2100_ethtool_ops; | |
6352 | dev->tx_timeout = ipw2100_tx_timeout; | |
6353 | dev->wireless_handlers = &ipw2100_wx_handler_def; | |
6354 | dev->get_wireless_stats = ipw2100_wx_wireless_stats; | |
6355 | dev->set_mac_address = ipw2100_set_address; | |
6356 | dev->watchdog_timeo = 3*HZ; | |
6357 | dev->irq = 0; | |
6358 | ||
6359 | dev->base_addr = (unsigned long)base_addr; | |
6360 | dev->mem_start = mem_start; | |
6361 | dev->mem_end = dev->mem_start + mem_len - 1; | |
6362 | ||
6363 | /* NOTE: We don't use the wireless_handlers hook | |
6364 | * in dev as the system will start throwing WX requests | |
6365 | * to us before we're actually initialized and it just | |
6366 | * ends up causing problems. So, we just handle | |
6367 | * the WX extensions through the ipw2100_ioctl interface */ | |
6368 | ||
6369 | ||
6370 | /* memset() puts everything to 0, so we only have explicitely set | |
6371 | * those values that need to be something else */ | |
6372 | ||
6373 | /* If power management is turned on, default to AUTO mode */ | |
6374 | priv->power_mode = IPW_POWER_AUTO; | |
6375 | ||
6376 | ||
6377 | ||
6378 | #ifdef CONFIG_IEEE80211_WPA | |
6379 | priv->ieee->wpa_enabled = 0; | |
6380 | priv->ieee->tkip_countermeasures = 0; | |
6381 | priv->ieee->drop_unencrypted = 0; | |
6382 | priv->ieee->privacy_invoked = 0; | |
6383 | priv->ieee->ieee802_1x = 1; | |
6384 | #endif /* CONFIG_IEEE80211_WPA */ | |
6385 | ||
6386 | /* Set module parameters */ | |
6387 | switch (mode) { | |
6388 | case 1: | |
6389 | priv->ieee->iw_mode = IW_MODE_ADHOC; | |
6390 | break; | |
6391 | #ifdef CONFIG_IPW2100_MONITOR | |
6392 | case 2: | |
6393 | priv->ieee->iw_mode = IW_MODE_MONITOR; | |
6394 | break; | |
6395 | #endif | |
6396 | default: | |
6397 | case 0: | |
6398 | priv->ieee->iw_mode = IW_MODE_INFRA; | |
6399 | break; | |
6400 | } | |
6401 | ||
6402 | if (disable == 1) | |
6403 | priv->status |= STATUS_RF_KILL_SW; | |
6404 | ||
6405 | if (channel != 0 && | |
6406 | ((channel >= REG_MIN_CHANNEL) && | |
6407 | (channel <= REG_MAX_CHANNEL))) { | |
6408 | priv->config |= CFG_STATIC_CHANNEL; | |
6409 | priv->channel = channel; | |
6410 | } | |
6411 | ||
6412 | if (associate) | |
6413 | priv->config |= CFG_ASSOCIATE; | |
6414 | ||
6415 | priv->beacon_interval = DEFAULT_BEACON_INTERVAL; | |
6416 | priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT; | |
6417 | priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT; | |
6418 | priv->rts_threshold = DEFAULT_RTS_THRESHOLD | RTS_DISABLED; | |
6419 | priv->frag_threshold = DEFAULT_FTS | FRAG_DISABLED; | |
6420 | priv->tx_power = IPW_TX_POWER_DEFAULT; | |
6421 | priv->tx_rates = DEFAULT_TX_RATES; | |
6422 | ||
6423 | strcpy(priv->nick, "ipw2100"); | |
6424 | ||
6425 | spin_lock_init(&priv->low_lock); | |
6426 | sema_init(&priv->action_sem, 1); | |
6427 | sema_init(&priv->adapter_sem, 1); | |
6428 | ||
6429 | init_waitqueue_head(&priv->wait_command_queue); | |
6430 | ||
6431 | netif_carrier_off(dev); | |
6432 | ||
6433 | INIT_LIST_HEAD(&priv->msg_free_list); | |
6434 | INIT_LIST_HEAD(&priv->msg_pend_list); | |
6435 | INIT_STAT(&priv->msg_free_stat); | |
6436 | INIT_STAT(&priv->msg_pend_stat); | |
6437 | ||
6438 | INIT_LIST_HEAD(&priv->tx_free_list); | |
6439 | INIT_LIST_HEAD(&priv->tx_pend_list); | |
6440 | INIT_STAT(&priv->tx_free_stat); | |
6441 | INIT_STAT(&priv->tx_pend_stat); | |
6442 | ||
6443 | INIT_LIST_HEAD(&priv->fw_pend_list); | |
6444 | INIT_STAT(&priv->fw_pend_stat); | |
6445 | ||
6446 | ||
6447 | #ifdef CONFIG_SOFTWARE_SUSPEND2 | |
6448 | priv->workqueue = create_workqueue(DRV_NAME, 0); | |
6449 | #else | |
6450 | priv->workqueue = create_workqueue(DRV_NAME); | |
6451 | #endif | |
6452 | INIT_WORK(&priv->reset_work, | |
6453 | (void (*)(void *))ipw2100_reset_adapter, priv); | |
6454 | INIT_WORK(&priv->security_work, | |
6455 | (void (*)(void *))ipw2100_security_work, priv); | |
6456 | INIT_WORK(&priv->wx_event_work, | |
6457 | (void (*)(void *))ipw2100_wx_event_work, priv); | |
6458 | INIT_WORK(&priv->hang_check, ipw2100_hang_check, priv); | |
6459 | INIT_WORK(&priv->rf_kill, ipw2100_rf_kill, priv); | |
6460 | ||
6461 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) | |
6462 | ipw2100_irq_tasklet, (unsigned long)priv); | |
6463 | ||
6464 | /* NOTE: We do not start the deferred work for status checks yet */ | |
6465 | priv->stop_rf_kill = 1; | |
6466 | priv->stop_hang_check = 1; | |
6467 | ||
6468 | return dev; | |
6469 | } | |
6470 | ||
2c86c275 JK |
6471 | static int ipw2100_pci_init_one(struct pci_dev *pci_dev, |
6472 | const struct pci_device_id *ent) | |
6473 | { | |
6474 | unsigned long mem_start, mem_len, mem_flags; | |
6475 | char *base_addr = NULL; | |
6476 | struct net_device *dev = NULL; | |
6477 | struct ipw2100_priv *priv = NULL; | |
6478 | int err = 0; | |
6479 | int registered = 0; | |
6480 | u32 val; | |
6481 | ||
6482 | IPW_DEBUG_INFO("enter\n"); | |
6483 | ||
6484 | mem_start = pci_resource_start(pci_dev, 0); | |
6485 | mem_len = pci_resource_len(pci_dev, 0); | |
6486 | mem_flags = pci_resource_flags(pci_dev, 0); | |
6487 | ||
6488 | if ((mem_flags & IORESOURCE_MEM) != IORESOURCE_MEM) { | |
6489 | IPW_DEBUG_INFO("weird - resource type is not memory\n"); | |
6490 | err = -ENODEV; | |
6491 | goto fail; | |
6492 | } | |
6493 | ||
6494 | base_addr = ioremap_nocache(mem_start, mem_len); | |
6495 | if (!base_addr) { | |
6496 | printk(KERN_WARNING DRV_NAME | |
6497 | "Error calling ioremap_nocache.\n"); | |
6498 | err = -EIO; | |
6499 | goto fail; | |
6500 | } | |
6501 | ||
6502 | /* allocate and initialize our net_device */ | |
6503 | dev = ipw2100_alloc_device(pci_dev, base_addr, mem_start, mem_len); | |
6504 | if (!dev) { | |
6505 | printk(KERN_WARNING DRV_NAME | |
6506 | "Error calling ipw2100_alloc_device.\n"); | |
6507 | err = -ENOMEM; | |
6508 | goto fail; | |
6509 | } | |
6510 | ||
6511 | /* set up PCI mappings for device */ | |
6512 | err = pci_enable_device(pci_dev); | |
6513 | if (err) { | |
6514 | printk(KERN_WARNING DRV_NAME | |
6515 | "Error calling pci_enable_device.\n"); | |
6516 | return err; | |
6517 | } | |
6518 | ||
6519 | priv = ieee80211_priv(dev); | |
6520 | ||
6521 | pci_set_master(pci_dev); | |
6522 | pci_set_drvdata(pci_dev, priv); | |
6523 | ||
05743d16 | 6524 | err = pci_set_dma_mask(pci_dev, DMA_32BIT_MASK); |
2c86c275 JK |
6525 | if (err) { |
6526 | printk(KERN_WARNING DRV_NAME | |
6527 | "Error calling pci_set_dma_mask.\n"); | |
6528 | pci_disable_device(pci_dev); | |
6529 | return err; | |
6530 | } | |
6531 | ||
6532 | err = pci_request_regions(pci_dev, DRV_NAME); | |
6533 | if (err) { | |
6534 | printk(KERN_WARNING DRV_NAME | |
6535 | "Error calling pci_request_regions.\n"); | |
6536 | pci_disable_device(pci_dev); | |
6537 | return err; | |
6538 | } | |
6539 | ||
6540 | /* We disable the RETRY_TIMEOUT register (0x41) to keep | |
6541 | * PCI Tx retries from interfering with C3 CPU state */ | |
6542 | pci_read_config_dword(pci_dev, 0x40, &val); | |
6543 | if ((val & 0x0000ff00) != 0) | |
6544 | pci_write_config_dword(pci_dev, 0x40, val & 0xffff00ff); | |
6545 | ||
8724a118 | 6546 | pci_set_power_state(pci_dev, PCI_D0); |
2c86c275 JK |
6547 | |
6548 | if (!ipw2100_hw_is_adapter_in_system(dev)) { | |
6549 | printk(KERN_WARNING DRV_NAME | |
6550 | "Device not found via register read.\n"); | |
6551 | err = -ENODEV; | |
6552 | goto fail; | |
6553 | } | |
6554 | ||
6555 | SET_NETDEV_DEV(dev, &pci_dev->dev); | |
6556 | ||
6557 | /* Force interrupts to be shut off on the device */ | |
6558 | priv->status |= STATUS_INT_ENABLED; | |
6559 | ipw2100_disable_interrupts(priv); | |
6560 | ||
6561 | /* Allocate and initialize the Tx/Rx queues and lists */ | |
6562 | if (ipw2100_queues_allocate(priv)) { | |
6563 | printk(KERN_WARNING DRV_NAME | |
6564 | "Error calilng ipw2100_queues_allocate.\n"); | |
6565 | err = -ENOMEM; | |
6566 | goto fail; | |
6567 | } | |
6568 | ipw2100_queues_initialize(priv); | |
6569 | ||
6570 | err = request_irq(pci_dev->irq, | |
6571 | ipw2100_interrupt, SA_SHIRQ, | |
6572 | dev->name, priv); | |
6573 | if (err) { | |
6574 | printk(KERN_WARNING DRV_NAME | |
6575 | "Error calling request_irq: %d.\n", | |
6576 | pci_dev->irq); | |
6577 | goto fail; | |
6578 | } | |
6579 | dev->irq = pci_dev->irq; | |
6580 | ||
6581 | IPW_DEBUG_INFO("Attempting to register device...\n"); | |
6582 | ||
6583 | SET_MODULE_OWNER(dev); | |
6584 | ||
6585 | printk(KERN_INFO DRV_NAME | |
6586 | ": Detected Intel PRO/Wireless 2100 Network Connection\n"); | |
6587 | ||
6588 | /* Bring up the interface. Pre 0.46, after we registered the | |
6589 | * network device we would call ipw2100_up. This introduced a race | |
6590 | * condition with newer hotplug configurations (network was coming | |
6591 | * up and making calls before the device was initialized). | |
6592 | * | |
6593 | * If we called ipw2100_up before we registered the device, then the | |
6594 | * device name wasn't registered. So, we instead use the net_dev->init | |
6595 | * member to call a function that then just turns and calls ipw2100_up. | |
6596 | * net_dev->init is called after name allocation but before the | |
6597 | * notifier chain is called */ | |
6598 | down(&priv->action_sem); | |
6599 | err = register_netdev(dev); | |
6600 | if (err) { | |
6601 | printk(KERN_WARNING DRV_NAME | |
6602 | "Error calling register_netdev.\n"); | |
6603 | goto fail_unlock; | |
6604 | } | |
6605 | registered = 1; | |
6606 | ||
6607 | IPW_DEBUG_INFO("%s: Bound to %s\n", dev->name, pci_name(pci_dev)); | |
6608 | ||
6609 | /* perform this after register_netdev so that dev->name is set */ | |
6610 | sysfs_create_group(&pci_dev->dev.kobj, &ipw2100_attribute_group); | |
6611 | netif_carrier_off(dev); | |
6612 | ||
6613 | /* If the RF Kill switch is disabled, go ahead and complete the | |
6614 | * startup sequence */ | |
6615 | if (!(priv->status & STATUS_RF_KILL_MASK)) { | |
6616 | /* Enable the adapter - sends HOST_COMPLETE */ | |
6617 | if (ipw2100_enable_adapter(priv)) { | |
6618 | printk(KERN_WARNING DRV_NAME | |
6619 | ": %s: failed in call to enable adapter.\n", | |
6620 | priv->net_dev->name); | |
6621 | ipw2100_hw_stop_adapter(priv); | |
6622 | err = -EIO; | |
6623 | goto fail_unlock; | |
6624 | } | |
6625 | ||
6626 | /* Start a scan . . . */ | |
6627 | ipw2100_set_scan_options(priv); | |
6628 | ipw2100_start_scan(priv); | |
6629 | } | |
6630 | ||
6631 | IPW_DEBUG_INFO("exit\n"); | |
6632 | ||
6633 | priv->status |= STATUS_INITIALIZED; | |
6634 | ||
6635 | up(&priv->action_sem); | |
6636 | ||
6637 | return 0; | |
6638 | ||
6639 | fail_unlock: | |
6640 | up(&priv->action_sem); | |
6641 | ||
6642 | fail: | |
6643 | if (dev) { | |
6644 | if (registered) | |
6645 | unregister_netdev(dev); | |
6646 | ||
6647 | ipw2100_hw_stop_adapter(priv); | |
6648 | ||
6649 | ipw2100_disable_interrupts(priv); | |
6650 | ||
6651 | if (dev->irq) | |
6652 | free_irq(dev->irq, priv); | |
6653 | ||
6654 | ipw2100_kill_workqueue(priv); | |
6655 | ||
6656 | /* These are safe to call even if they weren't allocated */ | |
6657 | ipw2100_queues_free(priv); | |
6658 | sysfs_remove_group(&pci_dev->dev.kobj, &ipw2100_attribute_group); | |
6659 | ||
6660 | free_ieee80211(dev); | |
6661 | pci_set_drvdata(pci_dev, NULL); | |
6662 | } | |
6663 | ||
6664 | if (base_addr) | |
6665 | iounmap((char*)base_addr); | |
6666 | ||
6667 | pci_release_regions(pci_dev); | |
6668 | pci_disable_device(pci_dev); | |
6669 | ||
6670 | return err; | |
6671 | } | |
6672 | ||
6673 | static void __devexit ipw2100_pci_remove_one(struct pci_dev *pci_dev) | |
6674 | { | |
6675 | struct ipw2100_priv *priv = pci_get_drvdata(pci_dev); | |
6676 | struct net_device *dev; | |
6677 | ||
6678 | if (priv) { | |
6679 | down(&priv->action_sem); | |
6680 | ||
6681 | priv->status &= ~STATUS_INITIALIZED; | |
6682 | ||
6683 | dev = priv->net_dev; | |
6684 | sysfs_remove_group(&pci_dev->dev.kobj, &ipw2100_attribute_group); | |
6685 | ||
6686 | #ifdef CONFIG_PM | |
6687 | if (ipw2100_firmware.version) | |
6688 | ipw2100_release_firmware(priv, &ipw2100_firmware); | |
6689 | #endif | |
6690 | /* Take down the hardware */ | |
6691 | ipw2100_down(priv); | |
6692 | ||
6693 | /* Release the semaphore so that the network subsystem can | |
6694 | * complete any needed calls into the driver... */ | |
6695 | up(&priv->action_sem); | |
6696 | ||
6697 | /* Unregister the device first - this results in close() | |
6698 | * being called if the device is open. If we free storage | |
6699 | * first, then close() will crash. */ | |
6700 | unregister_netdev(dev); | |
6701 | ||
6702 | /* ipw2100_down will ensure that there is no more pending work | |
6703 | * in the workqueue's, so we can safely remove them now. */ | |
6704 | ipw2100_kill_workqueue(priv); | |
6705 | ||
6706 | ipw2100_queues_free(priv); | |
6707 | ||
6708 | /* Free potential debugging firmware snapshot */ | |
6709 | ipw2100_snapshot_free(priv); | |
6710 | ||
6711 | if (dev->irq) | |
6712 | free_irq(dev->irq, priv); | |
6713 | ||
6714 | if (dev->base_addr) | |
6715 | iounmap((unsigned char *)dev->base_addr); | |
6716 | ||
6717 | free_ieee80211(dev); | |
6718 | } | |
6719 | ||
6720 | pci_release_regions(pci_dev); | |
6721 | pci_disable_device(pci_dev); | |
6722 | ||
6723 | IPW_DEBUG_INFO("exit\n"); | |
6724 | } | |
6725 | ||
6726 | ||
6727 | #ifdef CONFIG_PM | |
6728 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11) | |
6729 | static int ipw2100_suspend(struct pci_dev *pci_dev, u32 state) | |
6730 | #else | |
6731 | static int ipw2100_suspend(struct pci_dev *pci_dev, pm_message_t state) | |
6732 | #endif | |
6733 | { | |
6734 | struct ipw2100_priv *priv = pci_get_drvdata(pci_dev); | |
6735 | struct net_device *dev = priv->net_dev; | |
6736 | ||
6737 | IPW_DEBUG_INFO("%s: Going into suspend...\n", | |
6738 | dev->name); | |
6739 | ||
6740 | down(&priv->action_sem); | |
6741 | if (priv->status & STATUS_INITIALIZED) { | |
6742 | /* Take down the device; powers it off, etc. */ | |
6743 | ipw2100_down(priv); | |
6744 | } | |
6745 | ||
6746 | /* Remove the PRESENT state of the device */ | |
6747 | netif_device_detach(dev); | |
6748 | ||
2c86c275 | 6749 | pci_save_state(pci_dev); |
2c86c275 | 6750 | pci_disable_device (pci_dev); |
2c86c275 | 6751 | pci_set_power_state(pci_dev, PCI_D3hot); |
2c86c275 JK |
6752 | |
6753 | up(&priv->action_sem); | |
6754 | ||
6755 | return 0; | |
6756 | } | |
6757 | ||
6758 | static int ipw2100_resume(struct pci_dev *pci_dev) | |
6759 | { | |
6760 | struct ipw2100_priv *priv = pci_get_drvdata(pci_dev); | |
6761 | struct net_device *dev = priv->net_dev; | |
6762 | u32 val; | |
6763 | ||
6764 | if (IPW2100_PM_DISABLED) | |
6765 | return 0; | |
6766 | ||
6767 | down(&priv->action_sem); | |
6768 | ||
6769 | IPW_DEBUG_INFO("%s: Coming out of suspend...\n", | |
6770 | dev->name); | |
6771 | ||
2c86c275 | 6772 | pci_set_power_state(pci_dev, PCI_D0); |
2c86c275 | 6773 | pci_enable_device(pci_dev); |
2c86c275 | 6774 | pci_restore_state(pci_dev); |
2c86c275 JK |
6775 | |
6776 | /* | |
6777 | * Suspend/Resume resets the PCI configuration space, so we have to | |
6778 | * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries | |
6779 | * from interfering with C3 CPU state. pci_restore_state won't help | |
6780 | * here since it only restores the first 64 bytes pci config header. | |
6781 | */ | |
6782 | pci_read_config_dword(pci_dev, 0x40, &val); | |
6783 | if ((val & 0x0000ff00) != 0) | |
6784 | pci_write_config_dword(pci_dev, 0x40, val & 0xffff00ff); | |
6785 | ||
6786 | /* Set the device back into the PRESENT state; this will also wake | |
6787 | * the queue of needed */ | |
6788 | netif_device_attach(dev); | |
6789 | ||
6790 | /* Bring the device back up */ | |
6791 | if (!(priv->status & STATUS_RF_KILL_SW)) | |
6792 | ipw2100_up(priv, 0); | |
6793 | ||
6794 | up(&priv->action_sem); | |
6795 | ||
6796 | return 0; | |
6797 | } | |
6798 | #endif | |
6799 | ||
6800 | ||
6801 | #define IPW2100_DEV_ID(x) { PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, x } | |
6802 | ||
6803 | static struct pci_device_id ipw2100_pci_id_table[] __devinitdata = { | |
6804 | IPW2100_DEV_ID(0x2520), /* IN 2100A mPCI 3A */ | |
6805 | IPW2100_DEV_ID(0x2521), /* IN 2100A mPCI 3B */ | |
6806 | IPW2100_DEV_ID(0x2524), /* IN 2100A mPCI 3B */ | |
6807 | IPW2100_DEV_ID(0x2525), /* IN 2100A mPCI 3B */ | |
6808 | IPW2100_DEV_ID(0x2526), /* IN 2100A mPCI Gen A3 */ | |
6809 | IPW2100_DEV_ID(0x2522), /* IN 2100 mPCI 3B */ | |
6810 | IPW2100_DEV_ID(0x2523), /* IN 2100 mPCI 3A */ | |
6811 | IPW2100_DEV_ID(0x2527), /* IN 2100 mPCI 3B */ | |
6812 | IPW2100_DEV_ID(0x2528), /* IN 2100 mPCI 3B */ | |
6813 | IPW2100_DEV_ID(0x2529), /* IN 2100 mPCI 3B */ | |
6814 | IPW2100_DEV_ID(0x252B), /* IN 2100 mPCI 3A */ | |
6815 | IPW2100_DEV_ID(0x252C), /* IN 2100 mPCI 3A */ | |
6816 | IPW2100_DEV_ID(0x252D), /* IN 2100 mPCI 3A */ | |
6817 | ||
6818 | IPW2100_DEV_ID(0x2550), /* IB 2100A mPCI 3B */ | |
6819 | IPW2100_DEV_ID(0x2551), /* IB 2100 mPCI 3B */ | |
6820 | IPW2100_DEV_ID(0x2553), /* IB 2100 mPCI 3B */ | |
6821 | IPW2100_DEV_ID(0x2554), /* IB 2100 mPCI 3B */ | |
6822 | IPW2100_DEV_ID(0x2555), /* IB 2100 mPCI 3B */ | |
6823 | ||
6824 | IPW2100_DEV_ID(0x2560), /* DE 2100A mPCI 3A */ | |
6825 | IPW2100_DEV_ID(0x2562), /* DE 2100A mPCI 3A */ | |
6826 | IPW2100_DEV_ID(0x2563), /* DE 2100A mPCI 3A */ | |
6827 | IPW2100_DEV_ID(0x2561), /* DE 2100 mPCI 3A */ | |
6828 | IPW2100_DEV_ID(0x2565), /* DE 2100 mPCI 3A */ | |
6829 | IPW2100_DEV_ID(0x2566), /* DE 2100 mPCI 3A */ | |
6830 | IPW2100_DEV_ID(0x2567), /* DE 2100 mPCI 3A */ | |
6831 | ||
6832 | IPW2100_DEV_ID(0x2570), /* GA 2100 mPCI 3B */ | |
6833 | ||
6834 | IPW2100_DEV_ID(0x2580), /* TO 2100A mPCI 3B */ | |
6835 | IPW2100_DEV_ID(0x2582), /* TO 2100A mPCI 3B */ | |
6836 | IPW2100_DEV_ID(0x2583), /* TO 2100A mPCI 3B */ | |
6837 | IPW2100_DEV_ID(0x2581), /* TO 2100 mPCI 3B */ | |
6838 | IPW2100_DEV_ID(0x2585), /* TO 2100 mPCI 3B */ | |
6839 | IPW2100_DEV_ID(0x2586), /* TO 2100 mPCI 3B */ | |
6840 | IPW2100_DEV_ID(0x2587), /* TO 2100 mPCI 3B */ | |
6841 | ||
6842 | IPW2100_DEV_ID(0x2590), /* SO 2100A mPCI 3B */ | |
6843 | IPW2100_DEV_ID(0x2592), /* SO 2100A mPCI 3B */ | |
6844 | IPW2100_DEV_ID(0x2591), /* SO 2100 mPCI 3B */ | |
6845 | IPW2100_DEV_ID(0x2593), /* SO 2100 mPCI 3B */ | |
6846 | IPW2100_DEV_ID(0x2596), /* SO 2100 mPCI 3B */ | |
6847 | IPW2100_DEV_ID(0x2598), /* SO 2100 mPCI 3B */ | |
6848 | ||
6849 | IPW2100_DEV_ID(0x25A0), /* HP 2100 mPCI 3B */ | |
6850 | {0,}, | |
6851 | }; | |
6852 | ||
6853 | MODULE_DEVICE_TABLE(pci, ipw2100_pci_id_table); | |
6854 | ||
6855 | static struct pci_driver ipw2100_pci_driver = { | |
6856 | .name = DRV_NAME, | |
6857 | .id_table = ipw2100_pci_id_table, | |
6858 | .probe = ipw2100_pci_init_one, | |
6859 | .remove = __devexit_p(ipw2100_pci_remove_one), | |
6860 | #ifdef CONFIG_PM | |
6861 | .suspend = ipw2100_suspend, | |
6862 | .resume = ipw2100_resume, | |
6863 | #endif | |
6864 | }; | |
6865 | ||
6866 | ||
6867 | /** | |
6868 | * Initialize the ipw2100 driver/module | |
6869 | * | |
6870 | * @returns 0 if ok, < 0 errno node con error. | |
6871 | * | |
6872 | * Note: we cannot init the /proc stuff until the PCI driver is there, | |
6873 | * or we risk an unlikely race condition on someone accessing | |
6874 | * uninitialized data in the PCI dev struct through /proc. | |
6875 | */ | |
6876 | static int __init ipw2100_init(void) | |
6877 | { | |
6878 | int ret; | |
6879 | ||
6880 | printk(KERN_INFO DRV_NAME ": %s, %s\n", DRV_DESCRIPTION, DRV_VERSION); | |
6881 | printk(KERN_INFO DRV_NAME ": %s\n", DRV_COPYRIGHT); | |
6882 | ||
6883 | #ifdef CONFIG_IEEE80211_NOWEP | |
6884 | IPW_DEBUG_INFO(DRV_NAME ": Compiled with WEP disabled.\n"); | |
6885 | #endif | |
6886 | ||
6887 | ret = pci_module_init(&ipw2100_pci_driver); | |
6888 | ||
6889 | #ifdef CONFIG_IPW_DEBUG | |
6890 | ipw2100_debug_level = debug; | |
6891 | driver_create_file(&ipw2100_pci_driver.driver, | |
6892 | &driver_attr_debug_level); | |
6893 | #endif | |
6894 | ||
6895 | return ret; | |
6896 | } | |
6897 | ||
6898 | ||
6899 | /** | |
6900 | * Cleanup ipw2100 driver registration | |
6901 | */ | |
6902 | static void __exit ipw2100_exit(void) | |
6903 | { | |
6904 | /* FIXME: IPG: check that we have no instances of the devices open */ | |
6905 | #ifdef CONFIG_IPW_DEBUG | |
6906 | driver_remove_file(&ipw2100_pci_driver.driver, | |
6907 | &driver_attr_debug_level); | |
6908 | #endif | |
6909 | pci_unregister_driver(&ipw2100_pci_driver); | |
6910 | } | |
6911 | ||
6912 | module_init(ipw2100_init); | |
6913 | module_exit(ipw2100_exit); | |
6914 | ||
6915 | #define WEXT_USECHANNELS 1 | |
6916 | ||
c4aee8c2 | 6917 | static const long ipw2100_frequencies[] = { |
2c86c275 JK |
6918 | 2412, 2417, 2422, 2427, |
6919 | 2432, 2437, 2442, 2447, | |
6920 | 2452, 2457, 2462, 2467, | |
6921 | 2472, 2484 | |
6922 | }; | |
6923 | ||
6924 | #define FREQ_COUNT (sizeof(ipw2100_frequencies) / \ | |
6925 | sizeof(ipw2100_frequencies[0])) | |
6926 | ||
c4aee8c2 | 6927 | static const long ipw2100_rates_11b[] = { |
2c86c275 JK |
6928 | 1000000, |
6929 | 2000000, | |
6930 | 5500000, | |
6931 | 11000000 | |
6932 | }; | |
6933 | ||
6934 | #define RATE_COUNT (sizeof(ipw2100_rates_11b) / sizeof(ipw2100_rates_11b[0])) | |
6935 | ||
6936 | static int ipw2100_wx_get_name(struct net_device *dev, | |
6937 | struct iw_request_info *info, | |
6938 | union iwreq_data *wrqu, char *extra) | |
6939 | { | |
6940 | /* | |
6941 | * This can be called at any time. No action lock required | |
6942 | */ | |
6943 | ||
6944 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
6945 | if (!(priv->status & STATUS_ASSOCIATED)) | |
6946 | strcpy(wrqu->name, "unassociated"); | |
6947 | else | |
6948 | snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11b"); | |
6949 | ||
6950 | IPW_DEBUG_WX("Name: %s\n", wrqu->name); | |
6951 | return 0; | |
6952 | } | |
6953 | ||
6954 | ||
6955 | static int ipw2100_wx_set_freq(struct net_device *dev, | |
6956 | struct iw_request_info *info, | |
6957 | union iwreq_data *wrqu, char *extra) | |
6958 | { | |
6959 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
6960 | struct iw_freq *fwrq = &wrqu->freq; | |
6961 | int err = 0; | |
6962 | ||
6963 | if (priv->ieee->iw_mode == IW_MODE_INFRA) | |
6964 | return -EOPNOTSUPP; | |
6965 | ||
6966 | down(&priv->action_sem); | |
6967 | if (!(priv->status & STATUS_INITIALIZED)) { | |
6968 | err = -EIO; | |
6969 | goto done; | |
6970 | } | |
6971 | ||
6972 | /* if setting by freq convert to channel */ | |
6973 | if (fwrq->e == 1) { | |
6974 | if ((fwrq->m >= (int) 2.412e8 && | |
6975 | fwrq->m <= (int) 2.487e8)) { | |
6976 | int f = fwrq->m / 100000; | |
6977 | int c = 0; | |
6978 | ||
6979 | while ((c < REG_MAX_CHANNEL) && | |
6980 | (f != ipw2100_frequencies[c])) | |
6981 | c++; | |
6982 | ||
6983 | /* hack to fall through */ | |
6984 | fwrq->e = 0; | |
6985 | fwrq->m = c + 1; | |
6986 | } | |
6987 | } | |
6988 | ||
6989 | if (fwrq->e > 0 || fwrq->m > 1000) | |
6990 | return -EOPNOTSUPP; | |
6991 | else { /* Set the channel */ | |
6992 | IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m); | |
6993 | err = ipw2100_set_channel(priv, fwrq->m, 0); | |
6994 | } | |
6995 | ||
6996 | done: | |
6997 | up(&priv->action_sem); | |
6998 | return err; | |
6999 | } | |
7000 | ||
7001 | ||
7002 | static int ipw2100_wx_get_freq(struct net_device *dev, | |
7003 | struct iw_request_info *info, | |
7004 | union iwreq_data *wrqu, char *extra) | |
7005 | { | |
7006 | /* | |
7007 | * This can be called at any time. No action lock required | |
7008 | */ | |
7009 | ||
7010 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
7011 | ||
7012 | wrqu->freq.e = 0; | |
7013 | ||
7014 | /* If we are associated, trying to associate, or have a statically | |
7015 | * configured CHANNEL then return that; otherwise return ANY */ | |
7016 | if (priv->config & CFG_STATIC_CHANNEL || | |
7017 | priv->status & STATUS_ASSOCIATED) | |
7018 | wrqu->freq.m = priv->channel; | |
7019 | else | |
7020 | wrqu->freq.m = 0; | |
7021 | ||
7022 | IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel); | |
7023 | return 0; | |
7024 | ||
7025 | } | |
7026 | ||
7027 | static int ipw2100_wx_set_mode(struct net_device *dev, | |
7028 | struct iw_request_info *info, | |
7029 | union iwreq_data *wrqu, char *extra) | |
7030 | { | |
7031 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
7032 | int err = 0; | |
7033 | ||
7034 | IPW_DEBUG_WX("SET Mode -> %d \n", wrqu->mode); | |
7035 | ||
7036 | if (wrqu->mode == priv->ieee->iw_mode) | |
7037 | return 0; | |
7038 | ||
7039 | down(&priv->action_sem); | |
7040 | if (!(priv->status & STATUS_INITIALIZED)) { | |
7041 | err = -EIO; | |
7042 | goto done; | |
7043 | } | |
7044 | ||
7045 | switch (wrqu->mode) { | |
7046 | #ifdef CONFIG_IPW2100_MONITOR | |
7047 | case IW_MODE_MONITOR: | |
7048 | err = ipw2100_switch_mode(priv, IW_MODE_MONITOR); | |
7049 | break; | |
7050 | #endif /* CONFIG_IPW2100_MONITOR */ | |
7051 | case IW_MODE_ADHOC: | |
7052 | err = ipw2100_switch_mode(priv, IW_MODE_ADHOC); | |
7053 | break; | |
7054 | case IW_MODE_INFRA: | |
7055 | case IW_MODE_AUTO: | |
7056 | default: | |
7057 | err = ipw2100_switch_mode(priv, IW_MODE_INFRA); | |
7058 | break; | |
7059 | } | |
7060 | ||
7061 | done: | |
7062 | up(&priv->action_sem); | |
7063 | return err; | |
7064 | } | |
7065 | ||
7066 | static int ipw2100_wx_get_mode(struct net_device *dev, | |
7067 | struct iw_request_info *info, | |
7068 | union iwreq_data *wrqu, char *extra) | |
7069 | { | |
7070 | /* | |
7071 | * This can be called at any time. No action lock required | |
7072 | */ | |
7073 | ||
7074 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
7075 | ||
7076 | wrqu->mode = priv->ieee->iw_mode; | |
7077 | IPW_DEBUG_WX("GET Mode -> %d\n", wrqu->mode); | |
7078 | ||
7079 | return 0; | |
7080 | } | |
7081 | ||
7082 | ||
7083 | #define POWER_MODES 5 | |
7084 | ||
7085 | /* Values are in microsecond */ | |
c4aee8c2 | 7086 | static const s32 timeout_duration[POWER_MODES] = { |
2c86c275 JK |
7087 | 350000, |
7088 | 250000, | |
7089 | 75000, | |
7090 | 37000, | |
7091 | 25000, | |
7092 | }; | |
7093 | ||
c4aee8c2 | 7094 | static const s32 period_duration[POWER_MODES] = { |
2c86c275 JK |
7095 | 400000, |
7096 | 700000, | |
7097 | 1000000, | |
7098 | 1000000, | |
7099 | 1000000 | |
7100 | }; | |
7101 | ||
7102 | static int ipw2100_wx_get_range(struct net_device *dev, | |
7103 | struct iw_request_info *info, | |
7104 | union iwreq_data *wrqu, char *extra) | |
7105 | { | |
7106 | /* | |
7107 | * This can be called at any time. No action lock required | |
7108 | */ | |
7109 | ||
7110 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
7111 | struct iw_range *range = (struct iw_range *)extra; | |
7112 | u16 val; | |
7113 | int i, level; | |
7114 | ||
7115 | wrqu->data.length = sizeof(*range); | |
7116 | memset(range, 0, sizeof(*range)); | |
7117 | ||
7118 | /* Let's try to keep this struct in the same order as in | |
7119 | * linux/include/wireless.h | |
7120 | */ | |
7121 | ||
7122 | /* TODO: See what values we can set, and remove the ones we can't | |
7123 | * set, or fill them with some default data. | |
7124 | */ | |
7125 | ||
7126 | /* ~5 Mb/s real (802.11b) */ | |
7127 | range->throughput = 5 * 1000 * 1000; | |
7128 | ||
7129 | // range->sensitivity; /* signal level threshold range */ | |
7130 | ||
7131 | range->max_qual.qual = 100; | |
7132 | /* TODO: Find real max RSSI and stick here */ | |
7133 | range->max_qual.level = 0; | |
7134 | range->max_qual.noise = 0; | |
7135 | range->max_qual.updated = 7; /* Updated all three */ | |
7136 | ||
7137 | range->avg_qual.qual = 70; /* > 8% missed beacons is 'bad' */ | |
7138 | /* TODO: Find real 'good' to 'bad' threshol value for RSSI */ | |
7139 | range->avg_qual.level = 20 + IPW2100_RSSI_TO_DBM; | |
7140 | range->avg_qual.noise = 0; | |
7141 | range->avg_qual.updated = 7; /* Updated all three */ | |
7142 | ||
7143 | range->num_bitrates = RATE_COUNT; | |
7144 | ||
7145 | for (i = 0; i < RATE_COUNT && i < IW_MAX_BITRATES; i++) { | |
7146 | range->bitrate[i] = ipw2100_rates_11b[i]; | |
7147 | } | |
7148 | ||
7149 | range->min_rts = MIN_RTS_THRESHOLD; | |
7150 | range->max_rts = MAX_RTS_THRESHOLD; | |
7151 | range->min_frag = MIN_FRAG_THRESHOLD; | |
7152 | range->max_frag = MAX_FRAG_THRESHOLD; | |
7153 | ||
7154 | range->min_pmp = period_duration[0]; /* Minimal PM period */ | |
7155 | range->max_pmp = period_duration[POWER_MODES-1];/* Maximal PM period */ | |
7156 | range->min_pmt = timeout_duration[POWER_MODES-1]; /* Minimal PM timeout */ | |
7157 | range->max_pmt = timeout_duration[0];/* Maximal PM timeout */ | |
7158 | ||
7159 | /* How to decode max/min PM period */ | |
7160 | range->pmp_flags = IW_POWER_PERIOD; | |
7161 | /* How to decode max/min PM period */ | |
7162 | range->pmt_flags = IW_POWER_TIMEOUT; | |
7163 | /* What PM options are supported */ | |
7164 | range->pm_capa = IW_POWER_TIMEOUT | IW_POWER_PERIOD; | |
7165 | ||
7166 | range->encoding_size[0] = 5; | |
7167 | range->encoding_size[1] = 13; /* Different token sizes */ | |
7168 | range->num_encoding_sizes = 2; /* Number of entry in the list */ | |
7169 | range->max_encoding_tokens = WEP_KEYS; /* Max number of tokens */ | |
7170 | // range->encoding_login_index; /* token index for login token */ | |
7171 | ||
7172 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { | |
7173 | range->txpower_capa = IW_TXPOW_DBM; | |
7174 | range->num_txpower = IW_MAX_TXPOWER; | |
7175 | for (i = 0, level = (IPW_TX_POWER_MAX_DBM * 16); i < IW_MAX_TXPOWER; | |
7176 | i++, level -= ((IPW_TX_POWER_MAX_DBM - IPW_TX_POWER_MIN_DBM) * 16) / | |
7177 | (IW_MAX_TXPOWER - 1)) | |
7178 | range->txpower[i] = level / 16; | |
7179 | } else { | |
7180 | range->txpower_capa = 0; | |
7181 | range->num_txpower = 0; | |
7182 | } | |
7183 | ||
7184 | ||
7185 | /* Set the Wireless Extension versions */ | |
7186 | range->we_version_compiled = WIRELESS_EXT; | |
7187 | range->we_version_source = 16; | |
7188 | ||
7189 | // range->retry_capa; /* What retry options are supported */ | |
7190 | // range->retry_flags; /* How to decode max/min retry limit */ | |
7191 | // range->r_time_flags; /* How to decode max/min retry life */ | |
7192 | // range->min_retry; /* Minimal number of retries */ | |
7193 | // range->max_retry; /* Maximal number of retries */ | |
7194 | // range->min_r_time; /* Minimal retry lifetime */ | |
7195 | // range->max_r_time; /* Maximal retry lifetime */ | |
7196 | ||
7197 | range->num_channels = FREQ_COUNT; | |
7198 | ||
7199 | val = 0; | |
7200 | for (i = 0; i < FREQ_COUNT; i++) { | |
7201 | // TODO: Include only legal frequencies for some countries | |
7202 | // if (local->channel_mask & (1 << i)) { | |
7203 | range->freq[val].i = i + 1; | |
7204 | range->freq[val].m = ipw2100_frequencies[i] * 100000; | |
7205 | range->freq[val].e = 1; | |
7206 | val++; | |
7207 | // } | |
7208 | if (val == IW_MAX_FREQUENCIES) | |
7209 | break; | |
7210 | } | |
7211 | range->num_frequency = val; | |
7212 | ||
7213 | IPW_DEBUG_WX("GET Range\n"); | |
7214 | ||
7215 | return 0; | |
7216 | } | |
7217 | ||
7218 | static int ipw2100_wx_set_wap(struct net_device *dev, | |
7219 | struct iw_request_info *info, | |
7220 | union iwreq_data *wrqu, char *extra) | |
7221 | { | |
7222 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
7223 | int err = 0; | |
7224 | ||
7225 | static const unsigned char any[] = { | |
7226 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff | |
7227 | }; | |
7228 | static const unsigned char off[] = { | |
7229 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | |
7230 | }; | |
7231 | ||
7232 | // sanity checks | |
7233 | if (wrqu->ap_addr.sa_family != ARPHRD_ETHER) | |
7234 | return -EINVAL; | |
7235 | ||
7236 | down(&priv->action_sem); | |
7237 | if (!(priv->status & STATUS_INITIALIZED)) { | |
7238 | err = -EIO; | |
7239 | goto done; | |
7240 | } | |
7241 | ||
7242 | if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) || | |
7243 | !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) { | |
7244 | /* we disable mandatory BSSID association */ | |
7245 | IPW_DEBUG_WX("exit - disable mandatory BSSID\n"); | |
7246 | priv->config &= ~CFG_STATIC_BSSID; | |
7247 | err = ipw2100_set_mandatory_bssid(priv, NULL, 0); | |
7248 | goto done; | |
7249 | } | |
7250 | ||
7251 | priv->config |= CFG_STATIC_BSSID; | |
7252 | memcpy(priv->mandatory_bssid_mac, wrqu->ap_addr.sa_data, ETH_ALEN); | |
7253 | ||
7254 | err = ipw2100_set_mandatory_bssid(priv, wrqu->ap_addr.sa_data, 0); | |
7255 | ||
7256 | IPW_DEBUG_WX("SET BSSID -> %02X:%02X:%02X:%02X:%02X:%02X\n", | |
7257 | wrqu->ap_addr.sa_data[0] & 0xff, | |
7258 | wrqu->ap_addr.sa_data[1] & 0xff, | |
7259 | wrqu->ap_addr.sa_data[2] & 0xff, | |
7260 | wrqu->ap_addr.sa_data[3] & 0xff, | |
7261 | wrqu->ap_addr.sa_data[4] & 0xff, | |
7262 | wrqu->ap_addr.sa_data[5] & 0xff); | |
7263 | ||
7264 | done: | |
7265 | up(&priv->action_sem); | |
7266 | return err; | |
7267 | } | |
7268 | ||
7269 | static int ipw2100_wx_get_wap(struct net_device *dev, | |
7270 | struct iw_request_info *info, | |
7271 | union iwreq_data *wrqu, char *extra) | |
7272 | { | |
7273 | /* | |
7274 | * This can be called at any time. No action lock required | |
7275 | */ | |
7276 | ||
7277 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
7278 | ||
7279 | /* If we are associated, trying to associate, or have a statically | |
7280 | * configured BSSID then return that; otherwise return ANY */ | |
7281 | if (priv->config & CFG_STATIC_BSSID || | |
7282 | priv->status & STATUS_ASSOCIATED) { | |
7283 | wrqu->ap_addr.sa_family = ARPHRD_ETHER; | |
7284 | memcpy(wrqu->ap_addr.sa_data, &priv->bssid, ETH_ALEN); | |
7285 | } else | |
7286 | memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN); | |
7287 | ||
7288 | IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n", | |
7289 | MAC_ARG(wrqu->ap_addr.sa_data)); | |
7290 | return 0; | |
7291 | } | |
7292 | ||
7293 | static int ipw2100_wx_set_essid(struct net_device *dev, | |
7294 | struct iw_request_info *info, | |
7295 | union iwreq_data *wrqu, char *extra) | |
7296 | { | |
7297 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
7298 | char *essid = ""; /* ANY */ | |
7299 | int length = 0; | |
7300 | int err = 0; | |
7301 | ||
7302 | down(&priv->action_sem); | |
7303 | if (!(priv->status & STATUS_INITIALIZED)) { | |
7304 | err = -EIO; | |
7305 | goto done; | |
7306 | } | |
7307 | ||
7308 | if (wrqu->essid.flags && wrqu->essid.length) { | |
7309 | length = wrqu->essid.length - 1; | |
7310 | essid = extra; | |
7311 | } | |
7312 | ||
7313 | if (length == 0) { | |
7314 | IPW_DEBUG_WX("Setting ESSID to ANY\n"); | |
7315 | priv->config &= ~CFG_STATIC_ESSID; | |
7316 | err = ipw2100_set_essid(priv, NULL, 0, 0); | |
7317 | goto done; | |
7318 | } | |
7319 | ||
7320 | length = min(length, IW_ESSID_MAX_SIZE); | |
7321 | ||
7322 | priv->config |= CFG_STATIC_ESSID; | |
7323 | ||
7324 | if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) { | |
7325 | IPW_DEBUG_WX("ESSID set to current ESSID.\n"); | |
7326 | err = 0; | |
7327 | goto done; | |
7328 | } | |
7329 | ||
7330 | IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length), | |
7331 | length); | |
7332 | ||
7333 | priv->essid_len = length; | |
7334 | memcpy(priv->essid, essid, priv->essid_len); | |
7335 | ||
7336 | err = ipw2100_set_essid(priv, essid, length, 0); | |
7337 | ||
7338 | done: | |
7339 | up(&priv->action_sem); | |
7340 | return err; | |
7341 | } | |
7342 | ||
7343 | static int ipw2100_wx_get_essid(struct net_device *dev, | |
7344 | struct iw_request_info *info, | |
7345 | union iwreq_data *wrqu, char *extra) | |
7346 | { | |
7347 | /* | |
7348 | * This can be called at any time. No action lock required | |
7349 | */ | |
7350 | ||
7351 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
7352 | ||
7353 | /* If we are associated, trying to associate, or have a statically | |
7354 | * configured ESSID then return that; otherwise return ANY */ | |
7355 | if (priv->config & CFG_STATIC_ESSID || | |
7356 | priv->status & STATUS_ASSOCIATED) { | |
7357 | IPW_DEBUG_WX("Getting essid: '%s'\n", | |
7358 | escape_essid(priv->essid, priv->essid_len)); | |
7359 | memcpy(extra, priv->essid, priv->essid_len); | |
7360 | wrqu->essid.length = priv->essid_len; | |
7361 | wrqu->essid.flags = 1; /* active */ | |
7362 | } else { | |
7363 | IPW_DEBUG_WX("Getting essid: ANY\n"); | |
7364 | wrqu->essid.length = 0; | |
7365 | wrqu->essid.flags = 0; /* active */ | |
7366 | } | |
7367 | ||
7368 | return 0; | |
7369 | } | |
7370 | ||
7371 | static int ipw2100_wx_set_nick(struct net_device *dev, | |
7372 | struct iw_request_info *info, | |
7373 | union iwreq_data *wrqu, char *extra) | |
7374 | { | |
7375 | /* | |
7376 | * This can be called at any time. No action lock required | |
7377 | */ | |
7378 | ||
7379 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
7380 | ||
7381 | if (wrqu->data.length > IW_ESSID_MAX_SIZE) | |
7382 | return -E2BIG; | |
7383 | ||
7384 | wrqu->data.length = min((size_t)wrqu->data.length, sizeof(priv->nick)); | |
7385 | memset(priv->nick, 0, sizeof(priv->nick)); | |
7386 | memcpy(priv->nick, extra, wrqu->data.length); | |
7387 | ||
7388 | IPW_DEBUG_WX("SET Nickname -> %s \n", priv->nick); | |
7389 | ||
7390 | return 0; | |
7391 | } | |
7392 | ||
7393 | static int ipw2100_wx_get_nick(struct net_device *dev, | |
7394 | struct iw_request_info *info, | |
7395 | union iwreq_data *wrqu, char *extra) | |
7396 | { | |
7397 | /* | |
7398 | * This can be called at any time. No action lock required | |
7399 | */ | |
7400 | ||
7401 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
7402 | ||
7403 | wrqu->data.length = strlen(priv->nick) + 1; | |
7404 | memcpy(extra, priv->nick, wrqu->data.length); | |
7405 | wrqu->data.flags = 1; /* active */ | |
7406 | ||
7407 | IPW_DEBUG_WX("GET Nickname -> %s \n", extra); | |
7408 | ||
7409 | return 0; | |
7410 | } | |
7411 | ||
7412 | static int ipw2100_wx_set_rate(struct net_device *dev, | |
7413 | struct iw_request_info *info, | |
7414 | union iwreq_data *wrqu, char *extra) | |
7415 | { | |
7416 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
7417 | u32 target_rate = wrqu->bitrate.value; | |
7418 | u32 rate; | |
7419 | int err = 0; | |
7420 | ||
7421 | down(&priv->action_sem); | |
7422 | if (!(priv->status & STATUS_INITIALIZED)) { | |
7423 | err = -EIO; | |
7424 | goto done; | |
7425 | } | |
7426 | ||
7427 | rate = 0; | |
7428 | ||
7429 | if (target_rate == 1000000 || | |
7430 | (!wrqu->bitrate.fixed && target_rate > 1000000)) | |
7431 | rate |= TX_RATE_1_MBIT; | |
7432 | if (target_rate == 2000000 || | |
7433 | (!wrqu->bitrate.fixed && target_rate > 2000000)) | |
7434 | rate |= TX_RATE_2_MBIT; | |
7435 | if (target_rate == 5500000 || | |
7436 | (!wrqu->bitrate.fixed && target_rate > 5500000)) | |
7437 | rate |= TX_RATE_5_5_MBIT; | |
7438 | if (target_rate == 11000000 || | |
7439 | (!wrqu->bitrate.fixed && target_rate > 11000000)) | |
7440 | rate |= TX_RATE_11_MBIT; | |
7441 | if (rate == 0) | |
7442 | rate = DEFAULT_TX_RATES; | |
7443 | ||
7444 | err = ipw2100_set_tx_rates(priv, rate, 0); | |
7445 | ||
7446 | IPW_DEBUG_WX("SET Rate -> %04X \n", rate); | |
7447 | done: | |
7448 | up(&priv->action_sem); | |
7449 | return err; | |
7450 | } | |
7451 | ||
7452 | ||
7453 | static int ipw2100_wx_get_rate(struct net_device *dev, | |
7454 | struct iw_request_info *info, | |
7455 | union iwreq_data *wrqu, char *extra) | |
7456 | { | |
7457 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
7458 | int val; | |
7459 | int len = sizeof(val); | |
7460 | int err = 0; | |
7461 | ||
7462 | if (!(priv->status & STATUS_ENABLED) || | |
7463 | priv->status & STATUS_RF_KILL_MASK || | |
7464 | !(priv->status & STATUS_ASSOCIATED)) { | |
7465 | wrqu->bitrate.value = 0; | |
7466 | return 0; | |
7467 | } | |
7468 | ||
7469 | down(&priv->action_sem); | |
7470 | if (!(priv->status & STATUS_INITIALIZED)) { | |
7471 | err = -EIO; | |
7472 | goto done; | |
7473 | } | |
7474 | ||
7475 | err = ipw2100_get_ordinal(priv, IPW_ORD_CURRENT_TX_RATE, &val, &len); | |
7476 | if (err) { | |
7477 | IPW_DEBUG_WX("failed querying ordinals.\n"); | |
7478 | return err; | |
7479 | } | |
7480 | ||
7481 | switch (val & TX_RATE_MASK) { | |
7482 | case TX_RATE_1_MBIT: | |
7483 | wrqu->bitrate.value = 1000000; | |
7484 | break; | |
7485 | case TX_RATE_2_MBIT: | |
7486 | wrqu->bitrate.value = 2000000; | |
7487 | break; | |
7488 | case TX_RATE_5_5_MBIT: | |
7489 | wrqu->bitrate.value = 5500000; | |
7490 | break; | |
7491 | case TX_RATE_11_MBIT: | |
7492 | wrqu->bitrate.value = 11000000; | |
7493 | break; | |
7494 | default: | |
7495 | wrqu->bitrate.value = 0; | |
7496 | } | |
7497 | ||
7498 | IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value); | |
7499 | ||
7500 | done: | |
7501 | up(&priv->action_sem); | |
7502 | return err; | |
7503 | } | |
7504 | ||
7505 | static int ipw2100_wx_set_rts(struct net_device *dev, | |
7506 | struct iw_request_info *info, | |
7507 | union iwreq_data *wrqu, char *extra) | |
7508 | { | |
7509 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
7510 | int value, err; | |
7511 | ||
7512 | /* Auto RTS not yet supported */ | |
7513 | if (wrqu->rts.fixed == 0) | |
7514 | return -EINVAL; | |
7515 | ||
7516 | down(&priv->action_sem); | |
7517 | if (!(priv->status & STATUS_INITIALIZED)) { | |
7518 | err = -EIO; | |
7519 | goto done; | |
7520 | } | |
7521 | ||
7522 | if (wrqu->rts.disabled) | |
7523 | value = priv->rts_threshold | RTS_DISABLED; | |
7524 | else { | |
7525 | if (wrqu->rts.value < 1 || | |
7526 | wrqu->rts.value > 2304) { | |
7527 | err = -EINVAL; | |
7528 | goto done; | |
7529 | } | |
7530 | value = wrqu->rts.value; | |
7531 | } | |
7532 | ||
7533 | err = ipw2100_set_rts_threshold(priv, value); | |
7534 | ||
7535 | IPW_DEBUG_WX("SET RTS Threshold -> 0x%08X \n", value); | |
7536 | done: | |
7537 | up(&priv->action_sem); | |
7538 | return err; | |
7539 | } | |
7540 | ||
7541 | static int ipw2100_wx_get_rts(struct net_device *dev, | |
7542 | struct iw_request_info *info, | |
7543 | union iwreq_data *wrqu, char *extra) | |
7544 | { | |
7545 | /* | |
7546 | * This can be called at any time. No action lock required | |
7547 | */ | |
7548 | ||
7549 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
7550 | ||
7551 | wrqu->rts.value = priv->rts_threshold & ~RTS_DISABLED; | |
7552 | wrqu->rts.fixed = 1; /* no auto select */ | |
7553 | ||
7554 | /* If RTS is set to the default value, then it is disabled */ | |
7555 | wrqu->rts.disabled = (priv->rts_threshold & RTS_DISABLED) ? 1 : 0; | |
7556 | ||
7557 | IPW_DEBUG_WX("GET RTS Threshold -> 0x%08X \n", wrqu->rts.value); | |
7558 | ||
7559 | return 0; | |
7560 | } | |
7561 | ||
7562 | static int ipw2100_wx_set_txpow(struct net_device *dev, | |
7563 | struct iw_request_info *info, | |
7564 | union iwreq_data *wrqu, char *extra) | |
7565 | { | |
7566 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
7567 | int err = 0, value; | |
7568 | ||
7569 | if (priv->ieee->iw_mode != IW_MODE_ADHOC) | |
7570 | return -EINVAL; | |
7571 | ||
7572 | if (wrqu->txpower.disabled == 1 || wrqu->txpower.fixed == 0) | |
7573 | value = IPW_TX_POWER_DEFAULT; | |
7574 | else { | |
7575 | if (wrqu->txpower.value < IPW_TX_POWER_MIN_DBM || | |
7576 | wrqu->txpower.value > IPW_TX_POWER_MAX_DBM) | |
7577 | return -EINVAL; | |
7578 | ||
7579 | value = (wrqu->txpower.value - IPW_TX_POWER_MIN_DBM) * 16 / | |
7580 | (IPW_TX_POWER_MAX_DBM - IPW_TX_POWER_MIN_DBM); | |
7581 | } | |
7582 | ||
7583 | down(&priv->action_sem); | |
7584 | if (!(priv->status & STATUS_INITIALIZED)) { | |
7585 | err = -EIO; | |
7586 | goto done; | |
7587 | } | |
7588 | ||
7589 | err = ipw2100_set_tx_power(priv, value); | |
7590 | ||
7591 | IPW_DEBUG_WX("SET TX Power -> %d \n", value); | |
7592 | ||
7593 | done: | |
7594 | up(&priv->action_sem); | |
7595 | return err; | |
7596 | } | |
7597 | ||
7598 | static int ipw2100_wx_get_txpow(struct net_device *dev, | |
7599 | struct iw_request_info *info, | |
7600 | union iwreq_data *wrqu, char *extra) | |
7601 | { | |
7602 | /* | |
7603 | * This can be called at any time. No action lock required | |
7604 | */ | |
7605 | ||
7606 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
7607 | ||
7608 | if (priv->ieee->iw_mode != IW_MODE_ADHOC) { | |
7609 | wrqu->power.disabled = 1; | |
7610 | return 0; | |
7611 | } | |
7612 | ||
7613 | if (priv->tx_power == IPW_TX_POWER_DEFAULT) { | |
7614 | wrqu->power.fixed = 0; | |
7615 | wrqu->power.value = IPW_TX_POWER_MAX_DBM; | |
7616 | wrqu->power.disabled = 1; | |
7617 | } else { | |
7618 | wrqu->power.disabled = 0; | |
7619 | wrqu->power.fixed = 1; | |
7620 | wrqu->power.value = | |
7621 | (priv->tx_power * | |
7622 | (IPW_TX_POWER_MAX_DBM - IPW_TX_POWER_MIN_DBM)) / | |
7623 | (IPW_TX_POWER_MAX - IPW_TX_POWER_MIN) + | |
7624 | IPW_TX_POWER_MIN_DBM; | |
7625 | } | |
7626 | ||
7627 | wrqu->power.flags = IW_TXPOW_DBM; | |
7628 | ||
7629 | IPW_DEBUG_WX("GET TX Power -> %d \n", wrqu->power.value); | |
7630 | ||
7631 | return 0; | |
7632 | } | |
7633 | ||
7634 | static int ipw2100_wx_set_frag(struct net_device *dev, | |
7635 | struct iw_request_info *info, | |
7636 | union iwreq_data *wrqu, char *extra) | |
7637 | { | |
7638 | /* | |
7639 | * This can be called at any time. No action lock required | |
7640 | */ | |
7641 | ||
7642 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
7643 | ||
7644 | if (!wrqu->frag.fixed) | |
7645 | return -EINVAL; | |
7646 | ||
7647 | if (wrqu->frag.disabled) { | |
7648 | priv->frag_threshold |= FRAG_DISABLED; | |
7649 | priv->ieee->fts = DEFAULT_FTS; | |
7650 | } else { | |
7651 | if (wrqu->frag.value < MIN_FRAG_THRESHOLD || | |
7652 | wrqu->frag.value > MAX_FRAG_THRESHOLD) | |
7653 | return -EINVAL; | |
7654 | ||
7655 | priv->ieee->fts = wrqu->frag.value & ~0x1; | |
7656 | priv->frag_threshold = priv->ieee->fts; | |
7657 | } | |
7658 | ||
7659 | IPW_DEBUG_WX("SET Frag Threshold -> %d \n", priv->ieee->fts); | |
7660 | ||
7661 | return 0; | |
7662 | } | |
7663 | ||
7664 | static int ipw2100_wx_get_frag(struct net_device *dev, | |
7665 | struct iw_request_info *info, | |
7666 | union iwreq_data *wrqu, char *extra) | |
7667 | { | |
7668 | /* | |
7669 | * This can be called at any time. No action lock required | |
7670 | */ | |
7671 | ||
7672 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
7673 | wrqu->frag.value = priv->frag_threshold & ~FRAG_DISABLED; | |
7674 | wrqu->frag.fixed = 0; /* no auto select */ | |
7675 | wrqu->frag.disabled = (priv->frag_threshold & FRAG_DISABLED) ? 1 : 0; | |
7676 | ||
7677 | IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value); | |
7678 | ||
7679 | return 0; | |
7680 | } | |
7681 | ||
7682 | static int ipw2100_wx_set_retry(struct net_device *dev, | |
7683 | struct iw_request_info *info, | |
7684 | union iwreq_data *wrqu, char *extra) | |
7685 | { | |
7686 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
7687 | int err = 0; | |
7688 | ||
7689 | if (wrqu->retry.flags & IW_RETRY_LIFETIME || | |
7690 | wrqu->retry.disabled) | |
7691 | return -EINVAL; | |
7692 | ||
7693 | if (!(wrqu->retry.flags & IW_RETRY_LIMIT)) | |
7694 | return 0; | |
7695 | ||
7696 | down(&priv->action_sem); | |
7697 | if (!(priv->status & STATUS_INITIALIZED)) { | |
7698 | err = -EIO; | |
7699 | goto done; | |
7700 | } | |
7701 | ||
7702 | if (wrqu->retry.flags & IW_RETRY_MIN) { | |
7703 | err = ipw2100_set_short_retry(priv, wrqu->retry.value); | |
7704 | IPW_DEBUG_WX("SET Short Retry Limit -> %d \n", | |
7705 | wrqu->retry.value); | |
7706 | goto done; | |
7707 | } | |
7708 | ||
7709 | if (wrqu->retry.flags & IW_RETRY_MAX) { | |
7710 | err = ipw2100_set_long_retry(priv, wrqu->retry.value); | |
7711 | IPW_DEBUG_WX("SET Long Retry Limit -> %d \n", | |
7712 | wrqu->retry.value); | |
7713 | goto done; | |
7714 | } | |
7715 | ||
7716 | err = ipw2100_set_short_retry(priv, wrqu->retry.value); | |
7717 | if (!err) | |
7718 | err = ipw2100_set_long_retry(priv, wrqu->retry.value); | |
7719 | ||
7720 | IPW_DEBUG_WX("SET Both Retry Limits -> %d \n", wrqu->retry.value); | |
7721 | ||
7722 | done: | |
7723 | up(&priv->action_sem); | |
7724 | return err; | |
7725 | } | |
7726 | ||
7727 | static int ipw2100_wx_get_retry(struct net_device *dev, | |
7728 | struct iw_request_info *info, | |
7729 | union iwreq_data *wrqu, char *extra) | |
7730 | { | |
7731 | /* | |
7732 | * This can be called at any time. No action lock required | |
7733 | */ | |
7734 | ||
7735 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
7736 | ||
7737 | wrqu->retry.disabled = 0; /* can't be disabled */ | |
7738 | ||
7739 | if ((wrqu->retry.flags & IW_RETRY_TYPE) == | |
7740 | IW_RETRY_LIFETIME) | |
7741 | return -EINVAL; | |
7742 | ||
7743 | if (wrqu->retry.flags & IW_RETRY_MAX) { | |
7744 | wrqu->retry.flags = IW_RETRY_LIMIT & IW_RETRY_MAX; | |
7745 | wrqu->retry.value = priv->long_retry_limit; | |
7746 | } else { | |
7747 | wrqu->retry.flags = | |
7748 | (priv->short_retry_limit != | |
7749 | priv->long_retry_limit) ? | |
7750 | IW_RETRY_LIMIT & IW_RETRY_MIN : IW_RETRY_LIMIT; | |
7751 | ||
7752 | wrqu->retry.value = priv->short_retry_limit; | |
7753 | } | |
7754 | ||
7755 | IPW_DEBUG_WX("GET Retry -> %d \n", wrqu->retry.value); | |
7756 | ||
7757 | return 0; | |
7758 | } | |
7759 | ||
7760 | static int ipw2100_wx_set_scan(struct net_device *dev, | |
7761 | struct iw_request_info *info, | |
7762 | union iwreq_data *wrqu, char *extra) | |
7763 | { | |
7764 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
7765 | int err = 0; | |
7766 | ||
7767 | down(&priv->action_sem); | |
7768 | if (!(priv->status & STATUS_INITIALIZED)) { | |
7769 | err = -EIO; | |
7770 | goto done; | |
7771 | } | |
7772 | ||
7773 | IPW_DEBUG_WX("Initiating scan...\n"); | |
7774 | if (ipw2100_set_scan_options(priv) || | |
7775 | ipw2100_start_scan(priv)) { | |
7776 | IPW_DEBUG_WX("Start scan failed.\n"); | |
7777 | ||
7778 | /* TODO: Mark a scan as pending so when hardware initialized | |
7779 | * a scan starts */ | |
7780 | } | |
7781 | ||
7782 | done: | |
7783 | up(&priv->action_sem); | |
7784 | return err; | |
7785 | } | |
7786 | ||
7787 | static int ipw2100_wx_get_scan(struct net_device *dev, | |
7788 | struct iw_request_info *info, | |
7789 | union iwreq_data *wrqu, char *extra) | |
7790 | { | |
7791 | /* | |
7792 | * This can be called at any time. No action lock required | |
7793 | */ | |
7794 | ||
7795 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
7796 | return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra); | |
7797 | } | |
7798 | ||
7799 | ||
7800 | /* | |
7801 | * Implementation based on code in hostap-driver v0.1.3 hostap_ioctl.c | |
7802 | */ | |
7803 | static int ipw2100_wx_set_encode(struct net_device *dev, | |
7804 | struct iw_request_info *info, | |
7805 | union iwreq_data *wrqu, char *key) | |
7806 | { | |
7807 | /* | |
7808 | * No check of STATUS_INITIALIZED required | |
7809 | */ | |
7810 | ||
7811 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
7812 | return ieee80211_wx_set_encode(priv->ieee, info, wrqu, key); | |
7813 | } | |
7814 | ||
7815 | static int ipw2100_wx_get_encode(struct net_device *dev, | |
7816 | struct iw_request_info *info, | |
7817 | union iwreq_data *wrqu, char *key) | |
7818 | { | |
7819 | /* | |
7820 | * This can be called at any time. No action lock required | |
7821 | */ | |
7822 | ||
7823 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
7824 | return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key); | |
7825 | } | |
7826 | ||
7827 | static int ipw2100_wx_set_power(struct net_device *dev, | |
7828 | struct iw_request_info *info, | |
7829 | union iwreq_data *wrqu, char *extra) | |
7830 | { | |
7831 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
7832 | int err = 0; | |
7833 | ||
7834 | down(&priv->action_sem); | |
7835 | if (!(priv->status & STATUS_INITIALIZED)) { | |
7836 | err = -EIO; | |
7837 | goto done; | |
7838 | } | |
7839 | ||
7840 | if (wrqu->power.disabled) { | |
7841 | priv->power_mode = IPW_POWER_LEVEL(priv->power_mode); | |
7842 | err = ipw2100_set_power_mode(priv, IPW_POWER_MODE_CAM); | |
7843 | IPW_DEBUG_WX("SET Power Management Mode -> off\n"); | |
7844 | goto done; | |
7845 | } | |
7846 | ||
7847 | switch (wrqu->power.flags & IW_POWER_MODE) { | |
7848 | case IW_POWER_ON: /* If not specified */ | |
7849 | case IW_POWER_MODE: /* If set all mask */ | |
7850 | case IW_POWER_ALL_R: /* If explicitely state all */ | |
7851 | break; | |
7852 | default: /* Otherwise we don't support it */ | |
7853 | IPW_DEBUG_WX("SET PM Mode: %X not supported.\n", | |
7854 | wrqu->power.flags); | |
7855 | err = -EOPNOTSUPP; | |
7856 | goto done; | |
7857 | } | |
7858 | ||
7859 | /* If the user hasn't specified a power management mode yet, default | |
7860 | * to BATTERY */ | |
7861 | priv->power_mode = IPW_POWER_ENABLED | priv->power_mode; | |
7862 | err = ipw2100_set_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode)); | |
7863 | ||
7864 | IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", | |
7865 | priv->power_mode); | |
7866 | ||
7867 | done: | |
7868 | up(&priv->action_sem); | |
7869 | return err; | |
7870 | ||
7871 | } | |
7872 | ||
7873 | static int ipw2100_wx_get_power(struct net_device *dev, | |
7874 | struct iw_request_info *info, | |
7875 | union iwreq_data *wrqu, char *extra) | |
7876 | { | |
7877 | /* | |
7878 | * This can be called at any time. No action lock required | |
7879 | */ | |
7880 | ||
7881 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
7882 | ||
7883 | if (!(priv->power_mode & IPW_POWER_ENABLED)) { | |
7884 | wrqu->power.disabled = 1; | |
7885 | } else { | |
7886 | wrqu->power.disabled = 0; | |
7887 | wrqu->power.flags = 0; | |
7888 | } | |
7889 | ||
7890 | IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode); | |
7891 | ||
7892 | return 0; | |
7893 | } | |
7894 | ||
7895 | ||
7896 | /* | |
7897 | * | |
7898 | * IWPRIV handlers | |
7899 | * | |
7900 | */ | |
7901 | #ifdef CONFIG_IPW2100_MONITOR | |
7902 | static int ipw2100_wx_set_promisc(struct net_device *dev, | |
7903 | struct iw_request_info *info, | |
7904 | union iwreq_data *wrqu, char *extra) | |
7905 | { | |
7906 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
7907 | int *parms = (int *)extra; | |
7908 | int enable = (parms[0] > 0); | |
7909 | int err = 0; | |
7910 | ||
7911 | down(&priv->action_sem); | |
7912 | if (!(priv->status & STATUS_INITIALIZED)) { | |
7913 | err = -EIO; | |
7914 | goto done; | |
7915 | } | |
7916 | ||
7917 | if (enable) { | |
7918 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { | |
7919 | err = ipw2100_set_channel(priv, parms[1], 0); | |
7920 | goto done; | |
7921 | } | |
7922 | priv->channel = parms[1]; | |
7923 | err = ipw2100_switch_mode(priv, IW_MODE_MONITOR); | |
7924 | } else { | |
7925 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) | |
7926 | err = ipw2100_switch_mode(priv, priv->last_mode); | |
7927 | } | |
7928 | done: | |
7929 | up(&priv->action_sem); | |
7930 | return err; | |
7931 | } | |
7932 | ||
7933 | static int ipw2100_wx_reset(struct net_device *dev, | |
7934 | struct iw_request_info *info, | |
7935 | union iwreq_data *wrqu, char *extra) | |
7936 | { | |
7937 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
7938 | if (priv->status & STATUS_INITIALIZED) | |
7939 | schedule_reset(priv); | |
7940 | return 0; | |
7941 | } | |
7942 | ||
7943 | #endif | |
7944 | ||
7945 | static int ipw2100_wx_set_powermode(struct net_device *dev, | |
7946 | struct iw_request_info *info, | |
7947 | union iwreq_data *wrqu, char *extra) | |
7948 | { | |
7949 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
7950 | int err = 0, mode = *(int *)extra; | |
7951 | ||
7952 | down(&priv->action_sem); | |
7953 | if (!(priv->status & STATUS_INITIALIZED)) { | |
7954 | err = -EIO; | |
7955 | goto done; | |
7956 | } | |
7957 | ||
7958 | if ((mode < 1) || (mode > POWER_MODES)) | |
7959 | mode = IPW_POWER_AUTO; | |
7960 | ||
7961 | if (priv->power_mode != mode) | |
7962 | err = ipw2100_set_power_mode(priv, mode); | |
7963 | done: | |
7964 | up(&priv->action_sem); | |
7965 | return err; | |
7966 | } | |
7967 | ||
7968 | #define MAX_POWER_STRING 80 | |
7969 | static int ipw2100_wx_get_powermode(struct net_device *dev, | |
7970 | struct iw_request_info *info, | |
7971 | union iwreq_data *wrqu, char *extra) | |
7972 | { | |
7973 | /* | |
7974 | * This can be called at any time. No action lock required | |
7975 | */ | |
7976 | ||
7977 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
7978 | int level = IPW_POWER_LEVEL(priv->power_mode); | |
7979 | s32 timeout, period; | |
7980 | ||
7981 | if (!(priv->power_mode & IPW_POWER_ENABLED)) { | |
7982 | snprintf(extra, MAX_POWER_STRING, | |
7983 | "Power save level: %d (Off)", level); | |
7984 | } else { | |
7985 | switch (level) { | |
7986 | case IPW_POWER_MODE_CAM: | |
7987 | snprintf(extra, MAX_POWER_STRING, | |
7988 | "Power save level: %d (None)", level); | |
7989 | break; | |
7990 | case IPW_POWER_AUTO: | |
7991 | snprintf(extra, MAX_POWER_STRING, | |
7992 | "Power save level: %d (Auto)", 0); | |
7993 | break; | |
7994 | default: | |
7995 | timeout = timeout_duration[level - 1] / 1000; | |
7996 | period = period_duration[level - 1] / 1000; | |
7997 | snprintf(extra, MAX_POWER_STRING, | |
7998 | "Power save level: %d " | |
7999 | "(Timeout %dms, Period %dms)", | |
8000 | level, timeout, period); | |
8001 | } | |
8002 | } | |
8003 | ||
8004 | wrqu->data.length = strlen(extra) + 1; | |
8005 | ||
8006 | return 0; | |
8007 | } | |
8008 | ||
8009 | ||
8010 | static int ipw2100_wx_set_preamble(struct net_device *dev, | |
8011 | struct iw_request_info *info, | |
8012 | union iwreq_data *wrqu, char *extra) | |
8013 | { | |
8014 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
8015 | int err, mode = *(int *)extra; | |
8016 | ||
8017 | down(&priv->action_sem); | |
8018 | if (!(priv->status & STATUS_INITIALIZED)) { | |
8019 | err = -EIO; | |
8020 | goto done; | |
8021 | } | |
8022 | ||
8023 | if (mode == 1) | |
8024 | priv->config |= CFG_LONG_PREAMBLE; | |
8025 | else if (mode == 0) | |
8026 | priv->config &= ~CFG_LONG_PREAMBLE; | |
8027 | else { | |
8028 | err = -EINVAL; | |
8029 | goto done; | |
8030 | } | |
8031 | ||
8032 | err = ipw2100_system_config(priv, 0); | |
8033 | ||
8034 | done: | |
8035 | up(&priv->action_sem); | |
8036 | return err; | |
8037 | } | |
8038 | ||
8039 | static int ipw2100_wx_get_preamble(struct net_device *dev, | |
8040 | struct iw_request_info *info, | |
8041 | union iwreq_data *wrqu, char *extra) | |
8042 | { | |
8043 | /* | |
8044 | * This can be called at any time. No action lock required | |
8045 | */ | |
8046 | ||
8047 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
8048 | ||
8049 | if (priv->config & CFG_LONG_PREAMBLE) | |
8050 | snprintf(wrqu->name, IFNAMSIZ, "long (1)"); | |
8051 | else | |
8052 | snprintf(wrqu->name, IFNAMSIZ, "auto (0)"); | |
8053 | ||
8054 | return 0; | |
8055 | } | |
8056 | ||
8057 | static iw_handler ipw2100_wx_handlers[] = | |
8058 | { | |
8059 | NULL, /* SIOCSIWCOMMIT */ | |
8060 | ipw2100_wx_get_name, /* SIOCGIWNAME */ | |
8061 | NULL, /* SIOCSIWNWID */ | |
8062 | NULL, /* SIOCGIWNWID */ | |
8063 | ipw2100_wx_set_freq, /* SIOCSIWFREQ */ | |
8064 | ipw2100_wx_get_freq, /* SIOCGIWFREQ */ | |
8065 | ipw2100_wx_set_mode, /* SIOCSIWMODE */ | |
8066 | ipw2100_wx_get_mode, /* SIOCGIWMODE */ | |
8067 | NULL, /* SIOCSIWSENS */ | |
8068 | NULL, /* SIOCGIWSENS */ | |
8069 | NULL, /* SIOCSIWRANGE */ | |
8070 | ipw2100_wx_get_range, /* SIOCGIWRANGE */ | |
8071 | NULL, /* SIOCSIWPRIV */ | |
8072 | NULL, /* SIOCGIWPRIV */ | |
8073 | NULL, /* SIOCSIWSTATS */ | |
8074 | NULL, /* SIOCGIWSTATS */ | |
8075 | NULL, /* SIOCSIWSPY */ | |
8076 | NULL, /* SIOCGIWSPY */ | |
8077 | NULL, /* SIOCGIWTHRSPY */ | |
8078 | NULL, /* SIOCWIWTHRSPY */ | |
8079 | ipw2100_wx_set_wap, /* SIOCSIWAP */ | |
8080 | ipw2100_wx_get_wap, /* SIOCGIWAP */ | |
8081 | NULL, /* -- hole -- */ | |
8724a118 | 8082 | NULL, /* SIOCGIWAPLIST -- deprecated */ |
2c86c275 JK |
8083 | ipw2100_wx_set_scan, /* SIOCSIWSCAN */ |
8084 | ipw2100_wx_get_scan, /* SIOCGIWSCAN */ | |
8085 | ipw2100_wx_set_essid, /* SIOCSIWESSID */ | |
8086 | ipw2100_wx_get_essid, /* SIOCGIWESSID */ | |
8087 | ipw2100_wx_set_nick, /* SIOCSIWNICKN */ | |
8088 | ipw2100_wx_get_nick, /* SIOCGIWNICKN */ | |
8089 | NULL, /* -- hole -- */ | |
8090 | NULL, /* -- hole -- */ | |
8091 | ipw2100_wx_set_rate, /* SIOCSIWRATE */ | |
8092 | ipw2100_wx_get_rate, /* SIOCGIWRATE */ | |
8093 | ipw2100_wx_set_rts, /* SIOCSIWRTS */ | |
8094 | ipw2100_wx_get_rts, /* SIOCGIWRTS */ | |
8095 | ipw2100_wx_set_frag, /* SIOCSIWFRAG */ | |
8096 | ipw2100_wx_get_frag, /* SIOCGIWFRAG */ | |
8097 | ipw2100_wx_set_txpow, /* SIOCSIWTXPOW */ | |
8098 | ipw2100_wx_get_txpow, /* SIOCGIWTXPOW */ | |
8099 | ipw2100_wx_set_retry, /* SIOCSIWRETRY */ | |
8100 | ipw2100_wx_get_retry, /* SIOCGIWRETRY */ | |
8101 | ipw2100_wx_set_encode, /* SIOCSIWENCODE */ | |
8102 | ipw2100_wx_get_encode, /* SIOCGIWENCODE */ | |
8103 | ipw2100_wx_set_power, /* SIOCSIWPOWER */ | |
8104 | ipw2100_wx_get_power, /* SIOCGIWPOWER */ | |
8105 | }; | |
8106 | ||
8107 | #define IPW2100_PRIV_SET_MONITOR SIOCIWFIRSTPRIV | |
8108 | #define IPW2100_PRIV_RESET SIOCIWFIRSTPRIV+1 | |
8109 | #define IPW2100_PRIV_SET_POWER SIOCIWFIRSTPRIV+2 | |
8110 | #define IPW2100_PRIV_GET_POWER SIOCIWFIRSTPRIV+3 | |
8111 | #define IPW2100_PRIV_SET_LONGPREAMBLE SIOCIWFIRSTPRIV+4 | |
8112 | #define IPW2100_PRIV_GET_LONGPREAMBLE SIOCIWFIRSTPRIV+5 | |
8113 | ||
8114 | static const struct iw_priv_args ipw2100_private_args[] = { | |
8115 | ||
8116 | #ifdef CONFIG_IPW2100_MONITOR | |
8117 | { | |
8118 | IPW2100_PRIV_SET_MONITOR, | |
8119 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor" | |
8120 | }, | |
8121 | { | |
8122 | IPW2100_PRIV_RESET, | |
8123 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset" | |
8124 | }, | |
8125 | #endif /* CONFIG_IPW2100_MONITOR */ | |
8126 | ||
8127 | { | |
8128 | IPW2100_PRIV_SET_POWER, | |
8129 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_power" | |
8130 | }, | |
8131 | { | |
8132 | IPW2100_PRIV_GET_POWER, | |
8133 | 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_POWER_STRING, "get_power" | |
8134 | }, | |
8135 | { | |
8136 | IPW2100_PRIV_SET_LONGPREAMBLE, | |
8137 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_preamble" | |
8138 | }, | |
8139 | { | |
8140 | IPW2100_PRIV_GET_LONGPREAMBLE, | |
8141 | 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, "get_preamble" | |
8142 | }, | |
8143 | }; | |
8144 | ||
8145 | static iw_handler ipw2100_private_handler[] = { | |
8146 | #ifdef CONFIG_IPW2100_MONITOR | |
8147 | ipw2100_wx_set_promisc, | |
8148 | ipw2100_wx_reset, | |
8149 | #else /* CONFIG_IPW2100_MONITOR */ | |
8150 | NULL, | |
8151 | NULL, | |
8152 | #endif /* CONFIG_IPW2100_MONITOR */ | |
8153 | ipw2100_wx_set_powermode, | |
8154 | ipw2100_wx_get_powermode, | |
8155 | ipw2100_wx_set_preamble, | |
8156 | ipw2100_wx_get_preamble, | |
8157 | }; | |
8158 | ||
c4aee8c2 | 8159 | static struct iw_handler_def ipw2100_wx_handler_def = |
2c86c275 JK |
8160 | { |
8161 | .standard = ipw2100_wx_handlers, | |
8162 | .num_standard = sizeof(ipw2100_wx_handlers) / sizeof(iw_handler), | |
8163 | .num_private = sizeof(ipw2100_private_handler) / sizeof(iw_handler), | |
8164 | .num_private_args = sizeof(ipw2100_private_args) / | |
8165 | sizeof(struct iw_priv_args), | |
8166 | .private = (iw_handler *)ipw2100_private_handler, | |
8167 | .private_args = (struct iw_priv_args *)ipw2100_private_args, | |
8168 | }; | |
8169 | ||
8170 | /* | |
8171 | * Get wireless statistics. | |
8172 | * Called by /proc/net/wireless | |
8173 | * Also called by SIOCGIWSTATS | |
8174 | */ | |
c4aee8c2 | 8175 | static struct iw_statistics *ipw2100_wx_wireless_stats(struct net_device * dev) |
2c86c275 JK |
8176 | { |
8177 | enum { | |
8178 | POOR = 30, | |
8179 | FAIR = 60, | |
8180 | GOOD = 80, | |
8181 | VERY_GOOD = 90, | |
8182 | EXCELLENT = 95, | |
8183 | PERFECT = 100 | |
8184 | }; | |
8185 | int rssi_qual; | |
8186 | int tx_qual; | |
8187 | int beacon_qual; | |
8188 | ||
8189 | struct ipw2100_priv *priv = ieee80211_priv(dev); | |
8190 | struct iw_statistics *wstats; | |
8191 | u32 rssi, quality, tx_retries, missed_beacons, tx_failures; | |
8192 | u32 ord_len = sizeof(u32); | |
8193 | ||
8194 | if (!priv) | |
8195 | return (struct iw_statistics *) NULL; | |
8196 | ||
8197 | wstats = &priv->wstats; | |
8198 | ||
8199 | /* if hw is disabled, then ipw2100_get_ordinal() can't be called. | |
8200 | * ipw2100_wx_wireless_stats seems to be called before fw is | |
8201 | * initialized. STATUS_ASSOCIATED will only be set if the hw is up | |
8202 | * and associated; if not associcated, the values are all meaningless | |
8203 | * anyway, so set them all to NULL and INVALID */ | |
8204 | if (!(priv->status & STATUS_ASSOCIATED)) { | |
8205 | wstats->miss.beacon = 0; | |
8206 | wstats->discard.retries = 0; | |
8207 | wstats->qual.qual = 0; | |
8208 | wstats->qual.level = 0; | |
8209 | wstats->qual.noise = 0; | |
8210 | wstats->qual.updated = 7; | |
8211 | wstats->qual.updated |= IW_QUAL_NOISE_INVALID | | |
8212 | IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID; | |
8213 | return wstats; | |
8214 | } | |
8215 | ||
8216 | if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_PERCENT_MISSED_BCNS, | |
8217 | &missed_beacons, &ord_len)) | |
8218 | goto fail_get_ordinal; | |
8219 | ||
8220 | /* If we don't have a connection the quality and level is 0*/ | |
8221 | if (!(priv->status & STATUS_ASSOCIATED)) { | |
8222 | wstats->qual.qual = 0; | |
8223 | wstats->qual.level = 0; | |
8224 | } else { | |
8225 | if (ipw2100_get_ordinal(priv, IPW_ORD_RSSI_AVG_CURR, | |
8226 | &rssi, &ord_len)) | |
8227 | goto fail_get_ordinal; | |
8228 | wstats->qual.level = rssi + IPW2100_RSSI_TO_DBM; | |
8229 | if (rssi < 10) | |
8230 | rssi_qual = rssi * POOR / 10; | |
8231 | else if (rssi < 15) | |
8232 | rssi_qual = (rssi - 10) * (FAIR - POOR) / 5 + POOR; | |
8233 | else if (rssi < 20) | |
8234 | rssi_qual = (rssi - 15) * (GOOD - FAIR) / 5 + FAIR; | |
8235 | else if (rssi < 30) | |
8236 | rssi_qual = (rssi - 20) * (VERY_GOOD - GOOD) / | |
8237 | 10 + GOOD; | |
8238 | else | |
8239 | rssi_qual = (rssi - 30) * (PERFECT - VERY_GOOD) / | |
8240 | 10 + VERY_GOOD; | |
8241 | ||
8242 | if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_PERCENT_RETRIES, | |
8243 | &tx_retries, &ord_len)) | |
8244 | goto fail_get_ordinal; | |
8245 | ||
8246 | if (tx_retries > 75) | |
8247 | tx_qual = (90 - tx_retries) * POOR / 15; | |
8248 | else if (tx_retries > 70) | |
8249 | tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR; | |
8250 | else if (tx_retries > 65) | |
8251 | tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR; | |
8252 | else if (tx_retries > 50) | |
8253 | tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) / | |
8254 | 15 + GOOD; | |
8255 | else | |
8256 | tx_qual = (50 - tx_retries) * | |
8257 | (PERFECT - VERY_GOOD) / 50 + VERY_GOOD; | |
8258 | ||
8259 | if (missed_beacons > 50) | |
8260 | beacon_qual = (60 - missed_beacons) * POOR / 10; | |
8261 | else if (missed_beacons > 40) | |
8262 | beacon_qual = (50 - missed_beacons) * (FAIR - POOR) / | |
8263 | 10 + POOR; | |
8264 | else if (missed_beacons > 32) | |
8265 | beacon_qual = (40 - missed_beacons) * (GOOD - FAIR) / | |
8266 | 18 + FAIR; | |
8267 | else if (missed_beacons > 20) | |
8268 | beacon_qual = (32 - missed_beacons) * | |
8269 | (VERY_GOOD - GOOD) / 20 + GOOD; | |
8270 | else | |
8271 | beacon_qual = (20 - missed_beacons) * | |
8272 | (PERFECT - VERY_GOOD) / 20 + VERY_GOOD; | |
8273 | ||
8274 | quality = min(beacon_qual, min(tx_qual, rssi_qual)); | |
8275 | ||
8276 | #ifdef CONFIG_IPW_DEBUG | |
8277 | if (beacon_qual == quality) | |
8278 | IPW_DEBUG_WX("Quality clamped by Missed Beacons\n"); | |
8279 | else if (tx_qual == quality) | |
8280 | IPW_DEBUG_WX("Quality clamped by Tx Retries\n"); | |
8281 | else if (quality != 100) | |
8282 | IPW_DEBUG_WX("Quality clamped by Signal Strength\n"); | |
8283 | else | |
8284 | IPW_DEBUG_WX("Quality not clamped.\n"); | |
8285 | #endif | |
8286 | ||
8287 | wstats->qual.qual = quality; | |
8288 | wstats->qual.level = rssi + IPW2100_RSSI_TO_DBM; | |
8289 | } | |
8290 | ||
8291 | wstats->qual.noise = 0; | |
8292 | wstats->qual.updated = 7; | |
8293 | wstats->qual.updated |= IW_QUAL_NOISE_INVALID; | |
8294 | ||
8295 | /* FIXME: this is percent and not a # */ | |
8296 | wstats->miss.beacon = missed_beacons; | |
8297 | ||
8298 | if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURES, | |
8299 | &tx_failures, &ord_len)) | |
8300 | goto fail_get_ordinal; | |
8301 | wstats->discard.retries = tx_failures; | |
8302 | ||
8303 | return wstats; | |
8304 | ||
8305 | fail_get_ordinal: | |
8306 | IPW_DEBUG_WX("failed querying ordinals.\n"); | |
8307 | ||
8308 | return (struct iw_statistics *) NULL; | |
8309 | } | |
8310 | ||
c4aee8c2 | 8311 | static void ipw2100_wx_event_work(struct ipw2100_priv *priv) |
2c86c275 JK |
8312 | { |
8313 | union iwreq_data wrqu; | |
8314 | int len = ETH_ALEN; | |
8315 | ||
8316 | if (priv->status & STATUS_STOPPING) | |
8317 | return; | |
8318 | ||
8319 | down(&priv->action_sem); | |
8320 | ||
8321 | IPW_DEBUG_WX("enter\n"); | |
8322 | ||
8323 | up(&priv->action_sem); | |
8324 | ||
8325 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; | |
8326 | ||
8327 | /* Fetch BSSID from the hardware */ | |
8328 | if (!(priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) || | |
8329 | priv->status & STATUS_RF_KILL_MASK || | |
8330 | ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID, | |
8331 | &priv->bssid, &len)) { | |
8332 | memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN); | |
8333 | } else { | |
8334 | /* We now have the BSSID, so can finish setting to the full | |
8335 | * associated state */ | |
8336 | memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN); | |
8337 | memcpy(&priv->ieee->bssid, priv->bssid, ETH_ALEN); | |
8338 | priv->status &= ~STATUS_ASSOCIATING; | |
8339 | priv->status |= STATUS_ASSOCIATED; | |
8340 | netif_carrier_on(priv->net_dev); | |
8341 | if (netif_queue_stopped(priv->net_dev)) { | |
8342 | IPW_DEBUG_INFO("Waking net queue.\n"); | |
8343 | netif_wake_queue(priv->net_dev); | |
8344 | } else { | |
8345 | IPW_DEBUG_INFO("Starting net queue.\n"); | |
8346 | netif_start_queue(priv->net_dev); | |
8347 | } | |
8348 | } | |
8349 | ||
8350 | if (!(priv->status & STATUS_ASSOCIATED)) { | |
8351 | IPW_DEBUG_WX("Configuring ESSID\n"); | |
8352 | down(&priv->action_sem); | |
8353 | /* This is a disassociation event, so kick the firmware to | |
8354 | * look for another AP */ | |
8355 | if (priv->config & CFG_STATIC_ESSID) | |
8356 | ipw2100_set_essid(priv, priv->essid, priv->essid_len, 0); | |
8357 | else | |
8358 | ipw2100_set_essid(priv, NULL, 0, 0); | |
8359 | up(&priv->action_sem); | |
8360 | } | |
8361 | ||
8362 | wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL); | |
8363 | } | |
8364 | ||
8365 | #define IPW2100_FW_MAJOR_VERSION 1 | |
8366 | #define IPW2100_FW_MINOR_VERSION 3 | |
8367 | ||
8368 | #define IPW2100_FW_MINOR(x) ((x & 0xff) >> 8) | |
8369 | #define IPW2100_FW_MAJOR(x) (x & 0xff) | |
8370 | ||
8371 | #define IPW2100_FW_VERSION ((IPW2100_FW_MINOR_VERSION << 8) | \ | |
8372 | IPW2100_FW_MAJOR_VERSION) | |
8373 | ||
8374 | #define IPW2100_FW_PREFIX "ipw2100-" __stringify(IPW2100_FW_MAJOR_VERSION) \ | |
8375 | "." __stringify(IPW2100_FW_MINOR_VERSION) | |
8376 | ||
8377 | #define IPW2100_FW_NAME(x) IPW2100_FW_PREFIX "" x ".fw" | |
8378 | ||
8379 | ||
8380 | /* | |
8381 | ||
8382 | BINARY FIRMWARE HEADER FORMAT | |
8383 | ||
8384 | offset length desc | |
8385 | 0 2 version | |
8386 | 2 2 mode == 0:BSS,1:IBSS,2:MONITOR | |
8387 | 4 4 fw_len | |
8388 | 8 4 uc_len | |
8389 | C fw_len firmware data | |
8390 | 12 + fw_len uc_len microcode data | |
8391 | ||
8392 | */ | |
8393 | ||
8394 | struct ipw2100_fw_header { | |
8395 | short version; | |
8396 | short mode; | |
8397 | unsigned int fw_size; | |
8398 | unsigned int uc_size; | |
8399 | } __attribute__ ((packed)); | |
8400 | ||
8401 | ||
8402 | ||
8403 | static int ipw2100_mod_firmware_load(struct ipw2100_fw *fw) | |
8404 | { | |
8405 | struct ipw2100_fw_header *h = | |
8406 | (struct ipw2100_fw_header *)fw->fw_entry->data; | |
8407 | ||
8408 | if (IPW2100_FW_MAJOR(h->version) != IPW2100_FW_MAJOR_VERSION) { | |
797b4f76 | 8409 | printk(KERN_WARNING DRV_NAME ": Firmware image not compatible " |
2c86c275 JK |
8410 | "(detected version id of %u). " |
8411 | "See Documentation/networking/README.ipw2100\n", | |
8412 | h->version); | |
8413 | return 1; | |
8414 | } | |
8415 | ||
8416 | fw->version = h->version; | |
8417 | fw->fw.data = fw->fw_entry->data + sizeof(struct ipw2100_fw_header); | |
8418 | fw->fw.size = h->fw_size; | |
8419 | fw->uc.data = fw->fw.data + h->fw_size; | |
8420 | fw->uc.size = h->uc_size; | |
8421 | ||
8422 | return 0; | |
8423 | } | |
8424 | ||
8425 | ||
c4aee8c2 JB |
8426 | static int ipw2100_get_firmware(struct ipw2100_priv *priv, |
8427 | struct ipw2100_fw *fw) | |
2c86c275 JK |
8428 | { |
8429 | char *fw_name; | |
8430 | int rc; | |
8431 | ||
8432 | IPW_DEBUG_INFO("%s: Using hotplug firmware load.\n", | |
8433 | priv->net_dev->name); | |
8434 | ||
8435 | switch (priv->ieee->iw_mode) { | |
8436 | case IW_MODE_ADHOC: | |
8437 | fw_name = IPW2100_FW_NAME("-i"); | |
8438 | break; | |
8439 | #ifdef CONFIG_IPW2100_MONITOR | |
8440 | case IW_MODE_MONITOR: | |
8441 | fw_name = IPW2100_FW_NAME("-p"); | |
8442 | break; | |
8443 | #endif | |
8444 | case IW_MODE_INFRA: | |
8445 | default: | |
8446 | fw_name = IPW2100_FW_NAME(""); | |
8447 | break; | |
8448 | } | |
8449 | ||
8450 | rc = request_firmware(&fw->fw_entry, fw_name, &priv->pci_dev->dev); | |
8451 | ||
8452 | if (rc < 0) { | |
797b4f76 | 8453 | printk(KERN_ERR DRV_NAME ": " |
2c86c275 JK |
8454 | "%s: Firmware '%s' not available or load failed.\n", |
8455 | priv->net_dev->name, fw_name); | |
8456 | return rc; | |
8457 | } | |
aaa4d308 | 8458 | IPW_DEBUG_INFO("firmware data %p size %zd\n", fw->fw_entry->data, |
2c86c275 JK |
8459 | fw->fw_entry->size); |
8460 | ||
8461 | ipw2100_mod_firmware_load(fw); | |
8462 | ||
8463 | return 0; | |
8464 | } | |
8465 | ||
c4aee8c2 JB |
8466 | static void ipw2100_release_firmware(struct ipw2100_priv *priv, |
8467 | struct ipw2100_fw *fw) | |
2c86c275 JK |
8468 | { |
8469 | fw->version = 0; | |
8470 | if (fw->fw_entry) | |
8471 | release_firmware(fw->fw_entry); | |
8472 | fw->fw_entry = NULL; | |
8473 | } | |
8474 | ||
8475 | ||
c4aee8c2 JB |
8476 | static int ipw2100_get_fwversion(struct ipw2100_priv *priv, char *buf, |
8477 | size_t max) | |
2c86c275 JK |
8478 | { |
8479 | char ver[MAX_FW_VERSION_LEN]; | |
8480 | u32 len = MAX_FW_VERSION_LEN; | |
8481 | u32 tmp; | |
8482 | int i; | |
8483 | /* firmware version is an ascii string (max len of 14) */ | |
8484 | if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_FW_VER_NUM, | |
8485 | ver, &len)) | |
8486 | return -EIO; | |
8487 | tmp = max; | |
8488 | if (len >= max) | |
8489 | len = max - 1; | |
8490 | for (i = 0; i < len; i++) | |
8491 | buf[i] = ver[i]; | |
8492 | buf[i] = '\0'; | |
8493 | return tmp; | |
8494 | } | |
8495 | ||
c4aee8c2 JB |
8496 | static int ipw2100_get_ucodeversion(struct ipw2100_priv *priv, char *buf, |
8497 | size_t max) | |
2c86c275 JK |
8498 | { |
8499 | u32 ver; | |
8500 | u32 len = sizeof(ver); | |
8501 | /* microcode version is a 32 bit integer */ | |
8502 | if (ipw2100_get_ordinal(priv, IPW_ORD_UCODE_VERSION, | |
8503 | &ver, &len)) | |
8504 | return -EIO; | |
8505 | return snprintf(buf, max, "%08X", ver); | |
8506 | } | |
8507 | ||
8508 | /* | |
8509 | * On exit, the firmware will have been freed from the fw list | |
8510 | */ | |
c4aee8c2 JB |
8511 | static int ipw2100_fw_download(struct ipw2100_priv *priv, |
8512 | struct ipw2100_fw *fw) | |
2c86c275 JK |
8513 | { |
8514 | /* firmware is constructed of N contiguous entries, each entry is | |
8515 | * structured as: | |
8516 | * | |
8517 | * offset sie desc | |
8518 | * 0 4 address to write to | |
8519 | * 4 2 length of data run | |
8520 | * 6 length data | |
8521 | */ | |
8522 | unsigned int addr; | |
8523 | unsigned short len; | |
8524 | ||
8525 | const unsigned char *firmware_data = fw->fw.data; | |
8526 | unsigned int firmware_data_left = fw->fw.size; | |
8527 | ||
8528 | while (firmware_data_left > 0) { | |
8529 | addr = *(u32 *)(firmware_data); | |
8530 | firmware_data += 4; | |
8531 | firmware_data_left -= 4; | |
8532 | ||
8533 | len = *(u16 *)(firmware_data); | |
8534 | firmware_data += 2; | |
8535 | firmware_data_left -= 2; | |
8536 | ||
8537 | if (len > 32) { | |
797b4f76 | 8538 | printk(KERN_ERR DRV_NAME ": " |
2c86c275 JK |
8539 | "Invalid firmware run-length of %d bytes\n", |
8540 | len); | |
8541 | return -EINVAL; | |
8542 | } | |
8543 | ||
8544 | write_nic_memory(priv->net_dev, addr, len, firmware_data); | |
8545 | firmware_data += len; | |
8546 | firmware_data_left -= len; | |
8547 | } | |
8548 | ||
8549 | return 0; | |
8550 | } | |
8551 | ||
8552 | struct symbol_alive_response { | |
8553 | u8 cmd_id; | |
8554 | u8 seq_num; | |
8555 | u8 ucode_rev; | |
8556 | u8 eeprom_valid; | |
8557 | u16 valid_flags; | |
8558 | u8 IEEE_addr[6]; | |
8559 | u16 flags; | |
8560 | u16 pcb_rev; | |
8561 | u16 clock_settle_time; // 1us LSB | |
8562 | u16 powerup_settle_time; // 1us LSB | |
8563 | u16 hop_settle_time; // 1us LSB | |
8564 | u8 date[3]; // month, day, year | |
8565 | u8 time[2]; // hours, minutes | |
8566 | u8 ucode_valid; | |
8567 | }; | |
8568 | ||
c4aee8c2 JB |
8569 | static int ipw2100_ucode_download(struct ipw2100_priv *priv, |
8570 | struct ipw2100_fw *fw) | |
2c86c275 JK |
8571 | { |
8572 | struct net_device *dev = priv->net_dev; | |
8573 | const unsigned char *microcode_data = fw->uc.data; | |
8574 | unsigned int microcode_data_left = fw->uc.size; | |
8575 | ||
8576 | struct symbol_alive_response response; | |
8577 | int i, j; | |
8578 | u8 data; | |
8579 | ||
8580 | /* Symbol control */ | |
8581 | write_nic_word(dev, IPW2100_CONTROL_REG, 0x703); | |
8582 | readl((void *)(dev->base_addr)); | |
8583 | write_nic_word(dev, IPW2100_CONTROL_REG, 0x707); | |
8584 | readl((void *)(dev->base_addr)); | |
8585 | ||
8586 | /* HW config */ | |
8587 | write_nic_byte(dev, 0x210014, 0x72); /* fifo width =16 */ | |
8588 | readl((void *)(dev->base_addr)); | |
8589 | write_nic_byte(dev, 0x210014, 0x72); /* fifo width =16 */ | |
8590 | readl((void *)(dev->base_addr)); | |
8591 | ||
8592 | /* EN_CS_ACCESS bit to reset control store pointer */ | |
8593 | write_nic_byte(dev, 0x210000, 0x40); | |
8594 | readl((void *)(dev->base_addr)); | |
8595 | write_nic_byte(dev, 0x210000, 0x0); | |
8596 | readl((void *)(dev->base_addr)); | |
8597 | write_nic_byte(dev, 0x210000, 0x40); | |
8598 | readl((void *)(dev->base_addr)); | |
8599 | ||
8600 | /* copy microcode from buffer into Symbol */ | |
8601 | ||
8602 | while (microcode_data_left > 0) { | |
8603 | write_nic_byte(dev, 0x210010, *microcode_data++); | |
8604 | write_nic_byte(dev, 0x210010, *microcode_data++); | |
8605 | microcode_data_left -= 2; | |
8606 | } | |
8607 | ||
8608 | /* EN_CS_ACCESS bit to reset the control store pointer */ | |
8609 | write_nic_byte(dev, 0x210000, 0x0); | |
8610 | readl((void *)(dev->base_addr)); | |
8611 | ||
8612 | /* Enable System (Reg 0) | |
8613 | * first enable causes garbage in RX FIFO */ | |
8614 | write_nic_byte(dev, 0x210000, 0x0); | |
8615 | readl((void *)(dev->base_addr)); | |
8616 | write_nic_byte(dev, 0x210000, 0x80); | |
8617 | readl((void *)(dev->base_addr)); | |
8618 | ||
8619 | /* Reset External Baseband Reg */ | |
8620 | write_nic_word(dev, IPW2100_CONTROL_REG, 0x703); | |
8621 | readl((void *)(dev->base_addr)); | |
8622 | write_nic_word(dev, IPW2100_CONTROL_REG, 0x707); | |
8623 | readl((void *)(dev->base_addr)); | |
8624 | ||
8625 | /* HW Config (Reg 5) */ | |
8626 | write_nic_byte(dev, 0x210014, 0x72); // fifo width =16 | |
8627 | readl((void *)(dev->base_addr)); | |
8628 | write_nic_byte(dev, 0x210014, 0x72); // fifo width =16 | |
8629 | readl((void *)(dev->base_addr)); | |
8630 | ||
8631 | /* Enable System (Reg 0) | |
8632 | * second enable should be OK */ | |
8633 | write_nic_byte(dev, 0x210000, 0x00); // clear enable system | |
8634 | readl((void *)(dev->base_addr)); | |
8635 | write_nic_byte(dev, 0x210000, 0x80); // set enable system | |
8636 | ||
8637 | /* check Symbol is enabled - upped this from 5 as it wasn't always | |
8638 | * catching the update */ | |
8639 | for (i = 0; i < 10; i++) { | |
8640 | udelay(10); | |
8641 | ||
8642 | /* check Dino is enabled bit */ | |
8643 | read_nic_byte(dev, 0x210000, &data); | |
8644 | if (data & 0x1) | |
8645 | break; | |
8646 | } | |
8647 | ||
8648 | if (i == 10) { | |
797b4f76 | 8649 | printk(KERN_ERR DRV_NAME ": %s: Error initializing Symbol\n", |
2c86c275 JK |
8650 | dev->name); |
8651 | return -EIO; | |
8652 | } | |
8653 | ||
8654 | /* Get Symbol alive response */ | |
8655 | for (i = 0; i < 30; i++) { | |
8656 | /* Read alive response structure */ | |
8657 | for (j = 0; | |
8658 | j < (sizeof(struct symbol_alive_response) >> 1); | |
8659 | j++) | |
8660 | read_nic_word(dev, 0x210004, | |
8661 | ((u16 *)&response) + j); | |
8662 | ||
8663 | if ((response.cmd_id == 1) && | |
8664 | (response.ucode_valid == 0x1)) | |
8665 | break; | |
8666 | udelay(10); | |
8667 | } | |
8668 | ||
8669 | if (i == 30) { | |
797b4f76 | 8670 | printk(KERN_ERR DRV_NAME ": %s: No response from Symbol - hw not alive\n", |
2c86c275 JK |
8671 | dev->name); |
8672 | printk_buf(IPW_DL_ERROR, (u8*)&response, sizeof(response)); | |
8673 | return -EIO; | |
8674 | } | |
8675 | ||
8676 | return 0; | |
8677 | } |