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