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