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, GFP_KERNEL);
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 GFP_KERNEL);
3417 if (!priv->msg_buffers)
3418 return -ENOMEM;
3419
3420 for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++) {
3421 v = dma_alloc_coherent(&priv->pci_dev->dev,
3422 sizeof(struct ipw2100_cmd_header), &p,
3423 GFP_KERNEL);
3424 if (!v) {
3425 printk(KERN_ERR DRV_NAME ": "
3426 "%s: PCI alloc failed for msg "
3427 "buffers.\n", priv->net_dev->name);
3428 err = -ENOMEM;
3429 break;
3430 }
3431
3432 priv->msg_buffers[i].type = COMMAND;
3433 priv->msg_buffers[i].info.c_struct.cmd =
3434 (struct ipw2100_cmd_header *)v;
3435 priv->msg_buffers[i].info.c_struct.cmd_phys = p;
3436 }
3437
3438 if (i == IPW_COMMAND_POOL_SIZE)
3439 return 0;
3440
3441 for (j = 0; j < i; j++) {
3442 dma_free_coherent(&priv->pci_dev->dev,
3443 sizeof(struct ipw2100_cmd_header),
3444 priv->msg_buffers[j].info.c_struct.cmd,
3445 priv->msg_buffers[j].info.c_struct.cmd_phys);
3446 }
3447
3448 kfree(priv->msg_buffers);
3449 priv->msg_buffers = NULL;
3450
3451 return err;
3452 }
3453
ipw2100_msg_initialize(struct ipw2100_priv * priv)3454 static int ipw2100_msg_initialize(struct ipw2100_priv *priv)
3455 {
3456 int i;
3457
3458 INIT_LIST_HEAD(&priv->msg_free_list);
3459 INIT_LIST_HEAD(&priv->msg_pend_list);
3460
3461 for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++)
3462 list_add_tail(&priv->msg_buffers[i].list, &priv->msg_free_list);
3463 SET_STAT(&priv->msg_free_stat, i);
3464
3465 return 0;
3466 }
3467
ipw2100_msg_free(struct ipw2100_priv * priv)3468 static void ipw2100_msg_free(struct ipw2100_priv *priv)
3469 {
3470 int i;
3471
3472 if (!priv->msg_buffers)
3473 return;
3474
3475 for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++) {
3476 dma_free_coherent(&priv->pci_dev->dev,
3477 sizeof(struct ipw2100_cmd_header),
3478 priv->msg_buffers[i].info.c_struct.cmd,
3479 priv->msg_buffers[i].info.c_struct.cmd_phys);
3480 }
3481
3482 kfree(priv->msg_buffers);
3483 priv->msg_buffers = NULL;
3484 }
3485
pci_show(struct device * d,struct device_attribute * attr,char * buf)3486 static ssize_t pci_show(struct device *d, struct device_attribute *attr,
3487 char *buf)
3488 {
3489 struct pci_dev *pci_dev = to_pci_dev(d);
3490 char *out = buf;
3491 int i, j;
3492 u32 val;
3493
3494 for (i = 0; i < 16; i++) {
3495 out += sprintf(out, "[%08X] ", i * 16);
3496 for (j = 0; j < 16; j += 4) {
3497 pci_read_config_dword(pci_dev, i * 16 + j, &val);
3498 out += sprintf(out, "%08X ", val);
3499 }
3500 out += sprintf(out, "\n");
3501 }
3502
3503 return out - buf;
3504 }
3505
3506 static DEVICE_ATTR_RO(pci);
3507
cfg_show(struct device * d,struct device_attribute * attr,char * buf)3508 static ssize_t cfg_show(struct device *d, struct device_attribute *attr,
3509 char *buf)
3510 {
3511 struct ipw2100_priv *p = dev_get_drvdata(d);
3512 return sprintf(buf, "0x%08x\n", (int)p->config);
3513 }
3514
3515 static DEVICE_ATTR_RO(cfg);
3516
status_show(struct device * d,struct device_attribute * attr,char * buf)3517 static ssize_t status_show(struct device *d, struct device_attribute *attr,
3518 char *buf)
3519 {
3520 struct ipw2100_priv *p = dev_get_drvdata(d);
3521 return sprintf(buf, "0x%08x\n", (int)p->status);
3522 }
3523
3524 static DEVICE_ATTR_RO(status);
3525
capability_show(struct device * d,struct device_attribute * attr,char * buf)3526 static ssize_t capability_show(struct device *d, struct device_attribute *attr,
3527 char *buf)
3528 {
3529 struct ipw2100_priv *p = dev_get_drvdata(d);
3530 return sprintf(buf, "0x%08x\n", (int)p->capability);
3531 }
3532
3533 static DEVICE_ATTR_RO(capability);
3534
3535 #define IPW2100_REG(x) { IPW_ ##x, #x }
3536 static const struct {
3537 u32 addr;
3538 const char *name;
3539 } hw_data[] = {
3540 IPW2100_REG(REG_GP_CNTRL),
3541 IPW2100_REG(REG_GPIO),
3542 IPW2100_REG(REG_INTA),
3543 IPW2100_REG(REG_INTA_MASK), IPW2100_REG(REG_RESET_REG),};
3544 #define IPW2100_NIC(x, s) { x, #x, s }
3545 static const struct {
3546 u32 addr;
3547 const char *name;
3548 size_t size;
3549 } nic_data[] = {
3550 IPW2100_NIC(IPW2100_CONTROL_REG, 2),
3551 IPW2100_NIC(0x210014, 1), IPW2100_NIC(0x210000, 1),};
3552 #define IPW2100_ORD(x, d) { IPW_ORD_ ##x, #x, d }
3553 static const struct {
3554 u8 index;
3555 const char *name;
3556 const char *desc;
3557 } ord_data[] = {
3558 IPW2100_ORD(STAT_TX_HOST_REQUESTS, "requested Host Tx's (MSDU)"),
3559 IPW2100_ORD(STAT_TX_HOST_COMPLETE,
3560 "successful Host Tx's (MSDU)"),
3561 IPW2100_ORD(STAT_TX_DIR_DATA,
3562 "successful Directed Tx's (MSDU)"),
3563 IPW2100_ORD(STAT_TX_DIR_DATA1,
3564 "successful Directed Tx's (MSDU) @ 1MB"),
3565 IPW2100_ORD(STAT_TX_DIR_DATA2,
3566 "successful Directed Tx's (MSDU) @ 2MB"),
3567 IPW2100_ORD(STAT_TX_DIR_DATA5_5,
3568 "successful Directed Tx's (MSDU) @ 5_5MB"),
3569 IPW2100_ORD(STAT_TX_DIR_DATA11,
3570 "successful Directed Tx's (MSDU) @ 11MB"),
3571 IPW2100_ORD(STAT_TX_NODIR_DATA1,
3572 "successful Non_Directed Tx's (MSDU) @ 1MB"),
3573 IPW2100_ORD(STAT_TX_NODIR_DATA2,
3574 "successful Non_Directed Tx's (MSDU) @ 2MB"),
3575 IPW2100_ORD(STAT_TX_NODIR_DATA5_5,
3576 "successful Non_Directed Tx's (MSDU) @ 5.5MB"),
3577 IPW2100_ORD(STAT_TX_NODIR_DATA11,
3578 "successful Non_Directed Tx's (MSDU) @ 11MB"),
3579 IPW2100_ORD(STAT_NULL_DATA, "successful NULL data Tx's"),
3580 IPW2100_ORD(STAT_TX_RTS, "successful Tx RTS"),
3581 IPW2100_ORD(STAT_TX_CTS, "successful Tx CTS"),
3582 IPW2100_ORD(STAT_TX_ACK, "successful Tx ACK"),
3583 IPW2100_ORD(STAT_TX_ASSN, "successful Association Tx's"),
3584 IPW2100_ORD(STAT_TX_ASSN_RESP,
3585 "successful Association response Tx's"),
3586 IPW2100_ORD(STAT_TX_REASSN,
3587 "successful Reassociation Tx's"),
3588 IPW2100_ORD(STAT_TX_REASSN_RESP,
3589 "successful Reassociation response Tx's"),
3590 IPW2100_ORD(STAT_TX_PROBE,
3591 "probes successfully transmitted"),
3592 IPW2100_ORD(STAT_TX_PROBE_RESP,
3593 "probe responses successfully transmitted"),
3594 IPW2100_ORD(STAT_TX_BEACON, "tx beacon"),
3595 IPW2100_ORD(STAT_TX_ATIM, "Tx ATIM"),
3596 IPW2100_ORD(STAT_TX_DISASSN,
3597 "successful Disassociation TX"),
3598 IPW2100_ORD(STAT_TX_AUTH, "successful Authentication Tx"),
3599 IPW2100_ORD(STAT_TX_DEAUTH,
3600 "successful Deauthentication TX"),
3601 IPW2100_ORD(STAT_TX_TOTAL_BYTES,
3602 "Total successful Tx data bytes"),
3603 IPW2100_ORD(STAT_TX_RETRIES, "Tx retries"),
3604 IPW2100_ORD(STAT_TX_RETRY1, "Tx retries at 1MBPS"),
3605 IPW2100_ORD(STAT_TX_RETRY2, "Tx retries at 2MBPS"),
3606 IPW2100_ORD(STAT_TX_RETRY5_5, "Tx retries at 5.5MBPS"),
3607 IPW2100_ORD(STAT_TX_RETRY11, "Tx retries at 11MBPS"),
3608 IPW2100_ORD(STAT_TX_FAILURES, "Tx Failures"),
3609 IPW2100_ORD(STAT_TX_MAX_TRIES_IN_HOP,
3610 "times max tries in a hop failed"),
3611 IPW2100_ORD(STAT_TX_DISASSN_FAIL,
3612 "times disassociation failed"),
3613 IPW2100_ORD(STAT_TX_ERR_CTS, "missed/bad CTS frames"),
3614 IPW2100_ORD(STAT_TX_ERR_ACK, "tx err due to acks"),
3615 IPW2100_ORD(STAT_RX_HOST, "packets passed to host"),
3616 IPW2100_ORD(STAT_RX_DIR_DATA, "directed packets"),
3617 IPW2100_ORD(STAT_RX_DIR_DATA1, "directed packets at 1MB"),
3618 IPW2100_ORD(STAT_RX_DIR_DATA2, "directed packets at 2MB"),
3619 IPW2100_ORD(STAT_RX_DIR_DATA5_5,
3620 "directed packets at 5.5MB"),
3621 IPW2100_ORD(STAT_RX_DIR_DATA11, "directed packets at 11MB"),
3622 IPW2100_ORD(STAT_RX_NODIR_DATA, "nondirected packets"),
3623 IPW2100_ORD(STAT_RX_NODIR_DATA1,
3624 "nondirected packets at 1MB"),
3625 IPW2100_ORD(STAT_RX_NODIR_DATA2,
3626 "nondirected packets at 2MB"),
3627 IPW2100_ORD(STAT_RX_NODIR_DATA5_5,
3628 "nondirected packets at 5.5MB"),
3629 IPW2100_ORD(STAT_RX_NODIR_DATA11,
3630 "nondirected packets at 11MB"),
3631 IPW2100_ORD(STAT_RX_NULL_DATA, "null data rx's"),
3632 IPW2100_ORD(STAT_RX_RTS, "Rx RTS"), IPW2100_ORD(STAT_RX_CTS,
3633 "Rx CTS"),
3634 IPW2100_ORD(STAT_RX_ACK, "Rx ACK"),
3635 IPW2100_ORD(STAT_RX_CFEND, "Rx CF End"),
3636 IPW2100_ORD(STAT_RX_CFEND_ACK, "Rx CF End + CF Ack"),
3637 IPW2100_ORD(STAT_RX_ASSN, "Association Rx's"),
3638 IPW2100_ORD(STAT_RX_ASSN_RESP, "Association response Rx's"),
3639 IPW2100_ORD(STAT_RX_REASSN, "Reassociation Rx's"),
3640 IPW2100_ORD(STAT_RX_REASSN_RESP,
3641 "Reassociation response Rx's"),
3642 IPW2100_ORD(STAT_RX_PROBE, "probe Rx's"),
3643 IPW2100_ORD(STAT_RX_PROBE_RESP, "probe response Rx's"),
3644 IPW2100_ORD(STAT_RX_BEACON, "Rx beacon"),
3645 IPW2100_ORD(STAT_RX_ATIM, "Rx ATIM"),
3646 IPW2100_ORD(STAT_RX_DISASSN, "disassociation Rx"),
3647 IPW2100_ORD(STAT_RX_AUTH, "authentication Rx"),
3648 IPW2100_ORD(STAT_RX_DEAUTH, "deauthentication Rx"),
3649 IPW2100_ORD(STAT_RX_TOTAL_BYTES,
3650 "Total rx data bytes received"),
3651 IPW2100_ORD(STAT_RX_ERR_CRC, "packets with Rx CRC error"),
3652 IPW2100_ORD(STAT_RX_ERR_CRC1, "Rx CRC errors at 1MB"),
3653 IPW2100_ORD(STAT_RX_ERR_CRC2, "Rx CRC errors at 2MB"),
3654 IPW2100_ORD(STAT_RX_ERR_CRC5_5, "Rx CRC errors at 5.5MB"),
3655 IPW2100_ORD(STAT_RX_ERR_CRC11, "Rx CRC errors at 11MB"),
3656 IPW2100_ORD(STAT_RX_DUPLICATE1,
3657 "duplicate rx packets at 1MB"),
3658 IPW2100_ORD(STAT_RX_DUPLICATE2,
3659 "duplicate rx packets at 2MB"),
3660 IPW2100_ORD(STAT_RX_DUPLICATE5_5,
3661 "duplicate rx packets at 5.5MB"),
3662 IPW2100_ORD(STAT_RX_DUPLICATE11,
3663 "duplicate rx packets at 11MB"),
3664 IPW2100_ORD(STAT_RX_DUPLICATE, "duplicate rx packets"),
3665 IPW2100_ORD(PERS_DB_LOCK, "locking fw permanent db"),
3666 IPW2100_ORD(PERS_DB_SIZE, "size of fw permanent db"),
3667 IPW2100_ORD(PERS_DB_ADDR, "address of fw permanent db"),
3668 IPW2100_ORD(STAT_RX_INVALID_PROTOCOL,
3669 "rx frames with invalid protocol"),
3670 IPW2100_ORD(SYS_BOOT_TIME, "Boot time"),
3671 IPW2100_ORD(STAT_RX_NO_BUFFER,
3672 "rx frames rejected due to no buffer"),
3673 IPW2100_ORD(STAT_RX_MISSING_FRAG,
3674 "rx frames dropped due to missing fragment"),
3675 IPW2100_ORD(STAT_RX_ORPHAN_FRAG,
3676 "rx frames dropped due to non-sequential fragment"),
3677 IPW2100_ORD(STAT_RX_ORPHAN_FRAME,
3678 "rx frames dropped due to unmatched 1st frame"),
3679 IPW2100_ORD(STAT_RX_FRAG_AGEOUT,
3680 "rx frames dropped due to uncompleted frame"),
3681 IPW2100_ORD(STAT_RX_ICV_ERRORS,
3682 "ICV errors during decryption"),
3683 IPW2100_ORD(STAT_PSP_SUSPENSION, "times adapter suspended"),
3684 IPW2100_ORD(STAT_PSP_BCN_TIMEOUT, "beacon timeout"),
3685 IPW2100_ORD(STAT_PSP_POLL_TIMEOUT,
3686 "poll response timeouts"),
3687 IPW2100_ORD(STAT_PSP_NONDIR_TIMEOUT,
3688 "timeouts waiting for last {broad,multi}cast pkt"),
3689 IPW2100_ORD(STAT_PSP_RX_DTIMS, "PSP DTIMs received"),
3690 IPW2100_ORD(STAT_PSP_RX_TIMS, "PSP TIMs received"),
3691 IPW2100_ORD(STAT_PSP_STATION_ID, "PSP Station ID"),
3692 IPW2100_ORD(LAST_ASSN_TIME, "RTC time of last association"),
3693 IPW2100_ORD(STAT_PERCENT_MISSED_BCNS,
3694 "current calculation of % missed beacons"),
3695 IPW2100_ORD(STAT_PERCENT_RETRIES,
3696 "current calculation of % missed tx retries"),
3697 IPW2100_ORD(ASSOCIATED_AP_PTR,
3698 "0 if not associated, else pointer to AP table entry"),
3699 IPW2100_ORD(AVAILABLE_AP_CNT,
3700 "AP's described in the AP table"),
3701 IPW2100_ORD(AP_LIST_PTR, "Ptr to list of available APs"),
3702 IPW2100_ORD(STAT_AP_ASSNS, "associations"),
3703 IPW2100_ORD(STAT_ASSN_FAIL, "association failures"),
3704 IPW2100_ORD(STAT_ASSN_RESP_FAIL,
3705 "failures due to response fail"),
3706 IPW2100_ORD(STAT_FULL_SCANS, "full scans"),
3707 IPW2100_ORD(CARD_DISABLED, "Card Disabled"),
3708 IPW2100_ORD(STAT_ROAM_INHIBIT,
3709 "times roaming was inhibited due to activity"),
3710 IPW2100_ORD(RSSI_AT_ASSN,
3711 "RSSI of associated AP at time of association"),
3712 IPW2100_ORD(STAT_ASSN_CAUSE1,
3713 "reassociation: no probe response or TX on hop"),
3714 IPW2100_ORD(STAT_ASSN_CAUSE2,
3715 "reassociation: poor tx/rx quality"),
3716 IPW2100_ORD(STAT_ASSN_CAUSE3,
3717 "reassociation: tx/rx quality (excessive AP load"),
3718 IPW2100_ORD(STAT_ASSN_CAUSE4,
3719 "reassociation: AP RSSI level"),
3720 IPW2100_ORD(STAT_ASSN_CAUSE5,
3721 "reassociations due to load leveling"),
3722 IPW2100_ORD(STAT_AUTH_FAIL, "times authentication failed"),
3723 IPW2100_ORD(STAT_AUTH_RESP_FAIL,
3724 "times authentication response failed"),
3725 IPW2100_ORD(STATION_TABLE_CNT,
3726 "entries in association table"),
3727 IPW2100_ORD(RSSI_AVG_CURR, "Current avg RSSI"),
3728 IPW2100_ORD(POWER_MGMT_MODE, "Power mode - 0=CAM, 1=PSP"),
3729 IPW2100_ORD(COUNTRY_CODE,
3730 "IEEE country code as recv'd from beacon"),
3731 IPW2100_ORD(COUNTRY_CHANNELS,
3732 "channels supported by country"),
3733 IPW2100_ORD(RESET_CNT, "adapter resets (warm)"),
3734 IPW2100_ORD(BEACON_INTERVAL, "Beacon interval"),
3735 IPW2100_ORD(ANTENNA_DIVERSITY,
3736 "TRUE if antenna diversity is disabled"),
3737 IPW2100_ORD(DTIM_PERIOD, "beacon intervals between DTIMs"),
3738 IPW2100_ORD(OUR_FREQ,
3739 "current radio freq lower digits - channel ID"),
3740 IPW2100_ORD(RTC_TIME, "current RTC time"),
3741 IPW2100_ORD(PORT_TYPE, "operating mode"),
3742 IPW2100_ORD(CURRENT_TX_RATE, "current tx rate"),
3743 IPW2100_ORD(SUPPORTED_RATES, "supported tx rates"),
3744 IPW2100_ORD(ATIM_WINDOW, "current ATIM Window"),
3745 IPW2100_ORD(BASIC_RATES, "basic tx rates"),
3746 IPW2100_ORD(NIC_HIGHEST_RATE, "NIC highest tx rate"),
3747 IPW2100_ORD(AP_HIGHEST_RATE, "AP highest tx rate"),
3748 IPW2100_ORD(CAPABILITIES,
3749 "Management frame capability field"),
3750 IPW2100_ORD(AUTH_TYPE, "Type of authentication"),
3751 IPW2100_ORD(RADIO_TYPE, "Adapter card platform type"),
3752 IPW2100_ORD(RTS_THRESHOLD,
3753 "Min packet length for RTS handshaking"),
3754 IPW2100_ORD(INT_MODE, "International mode"),
3755 IPW2100_ORD(FRAGMENTATION_THRESHOLD,
3756 "protocol frag threshold"),
3757 IPW2100_ORD(EEPROM_SRAM_DB_BLOCK_START_ADDRESS,
3758 "EEPROM offset in SRAM"),
3759 IPW2100_ORD(EEPROM_SRAM_DB_BLOCK_SIZE,
3760 "EEPROM size in SRAM"),
3761 IPW2100_ORD(EEPROM_SKU_CAPABILITY, "EEPROM SKU Capability"),
3762 IPW2100_ORD(EEPROM_IBSS_11B_CHANNELS,
3763 "EEPROM IBSS 11b channel set"),
3764 IPW2100_ORD(MAC_VERSION, "MAC Version"),
3765 IPW2100_ORD(MAC_REVISION, "MAC Revision"),
3766 IPW2100_ORD(RADIO_VERSION, "Radio Version"),
3767 IPW2100_ORD(NIC_MANF_DATE_TIME, "MANF Date/Time STAMP"),
3768 IPW2100_ORD(UCODE_VERSION, "Ucode Version"),};
3769
registers_show(struct device * d,struct device_attribute * attr,char * buf)3770 static ssize_t registers_show(struct device *d, struct device_attribute *attr,
3771 char *buf)
3772 {
3773 int i;
3774 struct ipw2100_priv *priv = dev_get_drvdata(d);
3775 struct net_device *dev = priv->net_dev;
3776 char *out = buf;
3777 u32 val = 0;
3778
3779 out += sprintf(out, "%30s [Address ] : Hex\n", "Register");
3780
3781 for (i = 0; i < ARRAY_SIZE(hw_data); i++) {
3782 read_register(dev, hw_data[i].addr, &val);
3783 out += sprintf(out, "%30s [%08X] : %08X\n",
3784 hw_data[i].name, hw_data[i].addr, val);
3785 }
3786
3787 return out - buf;
3788 }
3789
3790 static DEVICE_ATTR_RO(registers);
3791
hardware_show(struct device * d,struct device_attribute * attr,char * buf)3792 static ssize_t hardware_show(struct device *d, struct device_attribute *attr,
3793 char *buf)
3794 {
3795 struct ipw2100_priv *priv = dev_get_drvdata(d);
3796 struct net_device *dev = priv->net_dev;
3797 char *out = buf;
3798 int i;
3799
3800 out += sprintf(out, "%30s [Address ] : Hex\n", "NIC entry");
3801
3802 for (i = 0; i < ARRAY_SIZE(nic_data); i++) {
3803 u8 tmp8;
3804 u16 tmp16;
3805 u32 tmp32;
3806
3807 switch (nic_data[i].size) {
3808 case 1:
3809 read_nic_byte(dev, nic_data[i].addr, &tmp8);
3810 out += sprintf(out, "%30s [%08X] : %02X\n",
3811 nic_data[i].name, nic_data[i].addr,
3812 tmp8);
3813 break;
3814 case 2:
3815 read_nic_word(dev, nic_data[i].addr, &tmp16);
3816 out += sprintf(out, "%30s [%08X] : %04X\n",
3817 nic_data[i].name, nic_data[i].addr,
3818 tmp16);
3819 break;
3820 case 4:
3821 read_nic_dword(dev, nic_data[i].addr, &tmp32);
3822 out += sprintf(out, "%30s [%08X] : %08X\n",
3823 nic_data[i].name, nic_data[i].addr,
3824 tmp32);
3825 break;
3826 }
3827 }
3828 return out - buf;
3829 }
3830
3831 static DEVICE_ATTR_RO(hardware);
3832
memory_show(struct device * d,struct device_attribute * attr,char * buf)3833 static ssize_t memory_show(struct device *d, struct device_attribute *attr,
3834 char *buf)
3835 {
3836 struct ipw2100_priv *priv = dev_get_drvdata(d);
3837 struct net_device *dev = priv->net_dev;
3838 static unsigned long loop = 0;
3839 int len = 0;
3840 u32 buffer[4];
3841 int i;
3842 char line[81];
3843
3844 if (loop >= 0x30000)
3845 loop = 0;
3846
3847 /* sysfs provides us PAGE_SIZE buffer */
3848 while (len < PAGE_SIZE - 128 && loop < 0x30000) {
3849
3850 if (priv->snapshot[0])
3851 for (i = 0; i < 4; i++)
3852 buffer[i] =
3853 *(u32 *) SNAPSHOT_ADDR(loop + i * 4);
3854 else
3855 for (i = 0; i < 4; i++)
3856 read_nic_dword(dev, loop + i * 4, &buffer[i]);
3857
3858 if (priv->dump_raw)
3859 len += sprintf(buf + len,
3860 "%c%c%c%c"
3861 "%c%c%c%c"
3862 "%c%c%c%c"
3863 "%c%c%c%c",
3864 ((u8 *) buffer)[0x0],
3865 ((u8 *) buffer)[0x1],
3866 ((u8 *) buffer)[0x2],
3867 ((u8 *) buffer)[0x3],
3868 ((u8 *) buffer)[0x4],
3869 ((u8 *) buffer)[0x5],
3870 ((u8 *) buffer)[0x6],
3871 ((u8 *) buffer)[0x7],
3872 ((u8 *) buffer)[0x8],
3873 ((u8 *) buffer)[0x9],
3874 ((u8 *) buffer)[0xa],
3875 ((u8 *) buffer)[0xb],
3876 ((u8 *) buffer)[0xc],
3877 ((u8 *) buffer)[0xd],
3878 ((u8 *) buffer)[0xe],
3879 ((u8 *) buffer)[0xf]);
3880 else
3881 len += sprintf(buf + len, "%s\n",
3882 snprint_line(line, sizeof(line),
3883 (u8 *) buffer, 16, loop));
3884 loop += 16;
3885 }
3886
3887 return len;
3888 }
3889
memory_store(struct device * d,struct device_attribute * attr,const char * buf,size_t count)3890 static ssize_t memory_store(struct device *d, struct device_attribute *attr,
3891 const char *buf, size_t count)
3892 {
3893 struct ipw2100_priv *priv = dev_get_drvdata(d);
3894 struct net_device *dev = priv->net_dev;
3895 const char *p = buf;
3896
3897 (void)dev; /* kill unused-var warning for debug-only code */
3898
3899 if (count < 1)
3900 return count;
3901
3902 if (p[0] == '1' ||
3903 (count >= 2 && tolower(p[0]) == 'o' && tolower(p[1]) == 'n')) {
3904 IPW_DEBUG_INFO("%s: Setting memory dump to RAW mode.\n",
3905 dev->name);
3906 priv->dump_raw = 1;
3907
3908 } else if (p[0] == '0' || (count >= 2 && tolower(p[0]) == 'o' &&
3909 tolower(p[1]) == 'f')) {
3910 IPW_DEBUG_INFO("%s: Setting memory dump to HEX mode.\n",
3911 dev->name);
3912 priv->dump_raw = 0;
3913
3914 } else if (tolower(p[0]) == 'r') {
3915 IPW_DEBUG_INFO("%s: Resetting firmware snapshot.\n", dev->name);
3916 ipw2100_snapshot_free(priv);
3917
3918 } else
3919 IPW_DEBUG_INFO("%s: Usage: 0|on = HEX, 1|off = RAW, "
3920 "reset = clear memory snapshot\n", dev->name);
3921
3922 return count;
3923 }
3924
3925 static DEVICE_ATTR_RW(memory);
3926
ordinals_show(struct device * d,struct device_attribute * attr,char * buf)3927 static ssize_t ordinals_show(struct device *d, struct device_attribute *attr,
3928 char *buf)
3929 {
3930 struct ipw2100_priv *priv = dev_get_drvdata(d);
3931 u32 val = 0;
3932 int len = 0;
3933 u32 val_len;
3934 static int loop = 0;
3935
3936 if (priv->status & STATUS_RF_KILL_MASK)
3937 return 0;
3938
3939 if (loop >= ARRAY_SIZE(ord_data))
3940 loop = 0;
3941
3942 /* sysfs provides us PAGE_SIZE buffer */
3943 while (len < PAGE_SIZE - 128 && loop < ARRAY_SIZE(ord_data)) {
3944 val_len = sizeof(u32);
3945
3946 if (ipw2100_get_ordinal(priv, ord_data[loop].index, &val,
3947 &val_len))
3948 len += sprintf(buf + len, "[0x%02X] = ERROR %s\n",
3949 ord_data[loop].index,
3950 ord_data[loop].desc);
3951 else
3952 len += sprintf(buf + len, "[0x%02X] = 0x%08X %s\n",
3953 ord_data[loop].index, val,
3954 ord_data[loop].desc);
3955 loop++;
3956 }
3957
3958 return len;
3959 }
3960
3961 static DEVICE_ATTR_RO(ordinals);
3962
stats_show(struct device * d,struct device_attribute * attr,char * buf)3963 static ssize_t stats_show(struct device *d, struct device_attribute *attr,
3964 char *buf)
3965 {
3966 struct ipw2100_priv *priv = dev_get_drvdata(d);
3967 char *out = buf;
3968
3969 out += sprintf(out, "interrupts: %d {tx: %d, rx: %d, other: %d}\n",
3970 priv->interrupts, priv->tx_interrupts,
3971 priv->rx_interrupts, priv->inta_other);
3972 out += sprintf(out, "firmware resets: %d\n", priv->resets);
3973 out += sprintf(out, "firmware hangs: %d\n", priv->hangs);
3974 #ifdef CONFIG_IPW2100_DEBUG
3975 out += sprintf(out, "packet mismatch image: %s\n",
3976 priv->snapshot[0] ? "YES" : "NO");
3977 #endif
3978
3979 return out - buf;
3980 }
3981
3982 static DEVICE_ATTR_RO(stats);
3983
ipw2100_switch_mode(struct ipw2100_priv * priv,u32 mode)3984 static int ipw2100_switch_mode(struct ipw2100_priv *priv, u32 mode)
3985 {
3986 int err;
3987
3988 if (mode == priv->ieee->iw_mode)
3989 return 0;
3990
3991 err = ipw2100_disable_adapter(priv);
3992 if (err) {
3993 printk(KERN_ERR DRV_NAME ": %s: Could not disable adapter %d\n",
3994 priv->net_dev->name, err);
3995 return err;
3996 }
3997
3998 switch (mode) {
3999 case IW_MODE_INFRA:
4000 priv->net_dev->type = ARPHRD_ETHER;
4001 break;
4002 case IW_MODE_ADHOC:
4003 priv->net_dev->type = ARPHRD_ETHER;
4004 break;
4005 #ifdef CONFIG_IPW2100_MONITOR
4006 case IW_MODE_MONITOR:
4007 priv->last_mode = priv->ieee->iw_mode;
4008 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
4009 break;
4010 #endif /* CONFIG_IPW2100_MONITOR */
4011 }
4012
4013 priv->ieee->iw_mode = mode;
4014
4015 #ifdef CONFIG_PM
4016 /* Indicate ipw2100_download_firmware download firmware
4017 * from disk instead of memory. */
4018 ipw2100_firmware.version = 0;
4019 #endif
4020
4021 printk(KERN_INFO "%s: Resetting on mode change.\n", priv->net_dev->name);
4022 priv->reset_backoff = 0;
4023 schedule_reset(priv);
4024
4025 return 0;
4026 }
4027
internals_show(struct device * d,struct device_attribute * attr,char * buf)4028 static ssize_t internals_show(struct device *d, struct device_attribute *attr,
4029 char *buf)
4030 {
4031 struct ipw2100_priv *priv = dev_get_drvdata(d);
4032 int len = 0;
4033
4034 #define DUMP_VAR(x,y) len += sprintf(buf + len, # x ": %" y "\n", priv-> x)
4035
4036 if (priv->status & STATUS_ASSOCIATED)
4037 len += sprintf(buf + len, "connected: %llu\n",
4038 ktime_get_boottime_seconds() - priv->connect_start);
4039 else
4040 len += sprintf(buf + len, "not connected\n");
4041
4042 DUMP_VAR(ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx], "p");
4043 DUMP_VAR(status, "08lx");
4044 DUMP_VAR(config, "08lx");
4045 DUMP_VAR(capability, "08lx");
4046
4047 len +=
4048 sprintf(buf + len, "last_rtc: %lu\n",
4049 (unsigned long)priv->last_rtc);
4050
4051 DUMP_VAR(fatal_error, "d");
4052 DUMP_VAR(stop_hang_check, "d");
4053 DUMP_VAR(stop_rf_kill, "d");
4054 DUMP_VAR(messages_sent, "d");
4055
4056 DUMP_VAR(tx_pend_stat.value, "d");
4057 DUMP_VAR(tx_pend_stat.hi, "d");
4058
4059 DUMP_VAR(tx_free_stat.value, "d");
4060 DUMP_VAR(tx_free_stat.lo, "d");
4061
4062 DUMP_VAR(msg_free_stat.value, "d");
4063 DUMP_VAR(msg_free_stat.lo, "d");
4064
4065 DUMP_VAR(msg_pend_stat.value, "d");
4066 DUMP_VAR(msg_pend_stat.hi, "d");
4067
4068 DUMP_VAR(fw_pend_stat.value, "d");
4069 DUMP_VAR(fw_pend_stat.hi, "d");
4070
4071 DUMP_VAR(txq_stat.value, "d");
4072 DUMP_VAR(txq_stat.lo, "d");
4073
4074 DUMP_VAR(ieee->scans, "d");
4075 DUMP_VAR(reset_backoff, "lld");
4076
4077 return len;
4078 }
4079
4080 static DEVICE_ATTR_RO(internals);
4081
bssinfo_show(struct device * d,struct device_attribute * attr,char * buf)4082 static ssize_t bssinfo_show(struct device *d, struct device_attribute *attr,
4083 char *buf)
4084 {
4085 struct ipw2100_priv *priv = dev_get_drvdata(d);
4086 char essid[IW_ESSID_MAX_SIZE + 1];
4087 u8 bssid[ETH_ALEN];
4088 u32 chan = 0;
4089 char *out = buf;
4090 unsigned int length;
4091 int ret;
4092
4093 if (priv->status & STATUS_RF_KILL_MASK)
4094 return 0;
4095
4096 memset(essid, 0, sizeof(essid));
4097 memset(bssid, 0, sizeof(bssid));
4098
4099 length = IW_ESSID_MAX_SIZE;
4100 ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_SSID, essid, &length);
4101 if (ret)
4102 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
4103 __LINE__);
4104
4105 length = sizeof(bssid);
4106 ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID,
4107 bssid, &length);
4108 if (ret)
4109 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
4110 __LINE__);
4111
4112 length = sizeof(u32);
4113 ret = ipw2100_get_ordinal(priv, IPW_ORD_OUR_FREQ, &chan, &length);
4114 if (ret)
4115 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
4116 __LINE__);
4117
4118 out += sprintf(out, "ESSID: %s\n", essid);
4119 out += sprintf(out, "BSSID: %pM\n", bssid);
4120 out += sprintf(out, "Channel: %d\n", chan);
4121
4122 return out - buf;
4123 }
4124
4125 static DEVICE_ATTR_RO(bssinfo);
4126
4127 #ifdef CONFIG_IPW2100_DEBUG
debug_level_show(struct device_driver * d,char * buf)4128 static ssize_t debug_level_show(struct device_driver *d, char *buf)
4129 {
4130 return sprintf(buf, "0x%08X\n", ipw2100_debug_level);
4131 }
4132
debug_level_store(struct device_driver * d,const char * buf,size_t count)4133 static ssize_t debug_level_store(struct device_driver *d,
4134 const char *buf, size_t count)
4135 {
4136 u32 val;
4137 int ret;
4138
4139 ret = kstrtou32(buf, 0, &val);
4140 if (ret)
4141 IPW_DEBUG_INFO(": %s is not in hex or decimal form.\n", buf);
4142 else
4143 ipw2100_debug_level = val;
4144
4145 return strnlen(buf, count);
4146 }
4147 static DRIVER_ATTR_RW(debug_level);
4148 #endif /* CONFIG_IPW2100_DEBUG */
4149
fatal_error_show(struct device * d,struct device_attribute * attr,char * buf)4150 static ssize_t fatal_error_show(struct device *d,
4151 struct device_attribute *attr, char *buf)
4152 {
4153 struct ipw2100_priv *priv = dev_get_drvdata(d);
4154 char *out = buf;
4155 int i;
4156
4157 if (priv->fatal_error)
4158 out += sprintf(out, "0x%08X\n", priv->fatal_error);
4159 else
4160 out += sprintf(out, "0\n");
4161
4162 for (i = 1; i <= IPW2100_ERROR_QUEUE; i++) {
4163 if (!priv->fatal_errors[(priv->fatal_index - i) %
4164 IPW2100_ERROR_QUEUE])
4165 continue;
4166
4167 out += sprintf(out, "%d. 0x%08X\n", i,
4168 priv->fatal_errors[(priv->fatal_index - i) %
4169 IPW2100_ERROR_QUEUE]);
4170 }
4171
4172 return out - buf;
4173 }
4174
fatal_error_store(struct device * d,struct device_attribute * attr,const char * buf,size_t count)4175 static ssize_t fatal_error_store(struct device *d,
4176 struct device_attribute *attr, const char *buf,
4177 size_t count)
4178 {
4179 struct ipw2100_priv *priv = dev_get_drvdata(d);
4180 schedule_reset(priv);
4181 return count;
4182 }
4183
4184 static DEVICE_ATTR_RW(fatal_error);
4185
scan_age_show(struct device * d,struct device_attribute * attr,char * buf)4186 static ssize_t scan_age_show(struct device *d, struct device_attribute *attr,
4187 char *buf)
4188 {
4189 struct ipw2100_priv *priv = dev_get_drvdata(d);
4190 return sprintf(buf, "%d\n", priv->ieee->scan_age);
4191 }
4192
scan_age_store(struct device * d,struct device_attribute * attr,const char * buf,size_t count)4193 static ssize_t scan_age_store(struct device *d, struct device_attribute *attr,
4194 const char *buf, size_t count)
4195 {
4196 struct ipw2100_priv *priv = dev_get_drvdata(d);
4197 struct net_device *dev = priv->net_dev;
4198 unsigned long val;
4199 int ret;
4200
4201 (void)dev; /* kill unused-var warning for debug-only code */
4202
4203 IPW_DEBUG_INFO("enter\n");
4204
4205 ret = kstrtoul(buf, 0, &val);
4206 if (ret) {
4207 IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
4208 } else {
4209 priv->ieee->scan_age = val;
4210 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
4211 }
4212
4213 IPW_DEBUG_INFO("exit\n");
4214 return strnlen(buf, count);
4215 }
4216
4217 static DEVICE_ATTR_RW(scan_age);
4218
rf_kill_show(struct device * d,struct device_attribute * attr,char * buf)4219 static ssize_t rf_kill_show(struct device *d, struct device_attribute *attr,
4220 char *buf)
4221 {
4222 /* 0 - RF kill not enabled
4223 1 - SW based RF kill active (sysfs)
4224 2 - HW based RF kill active
4225 3 - Both HW and SW baed RF kill active */
4226 struct ipw2100_priv *priv = dev_get_drvdata(d);
4227 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
4228 (rf_kill_active(priv) ? 0x2 : 0x0);
4229 return sprintf(buf, "%i\n", val);
4230 }
4231
ipw_radio_kill_sw(struct ipw2100_priv * priv,int disable_radio)4232 static int ipw_radio_kill_sw(struct ipw2100_priv *priv, int disable_radio)
4233 {
4234 if ((disable_radio ? 1 : 0) ==
4235 (priv->status & STATUS_RF_KILL_SW ? 1 : 0))
4236 return 0;
4237
4238 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
4239 disable_radio ? "OFF" : "ON");
4240
4241 mutex_lock(&priv->action_mutex);
4242
4243 if (disable_radio) {
4244 priv->status |= STATUS_RF_KILL_SW;
4245 ipw2100_down(priv);
4246 } else {
4247 priv->status &= ~STATUS_RF_KILL_SW;
4248 if (rf_kill_active(priv)) {
4249 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
4250 "disabled by HW switch\n");
4251 /* Make sure the RF_KILL check timer is running */
4252 priv->stop_rf_kill = 0;
4253 mod_delayed_work(system_percpu_wq, &priv->rf_kill,
4254 round_jiffies_relative(HZ));
4255 } else
4256 schedule_reset(priv);
4257 }
4258
4259 mutex_unlock(&priv->action_mutex);
4260 return 1;
4261 }
4262
rf_kill_store(struct device * d,struct device_attribute * attr,const char * buf,size_t count)4263 static ssize_t rf_kill_store(struct device *d, struct device_attribute *attr,
4264 const char *buf, size_t count)
4265 {
4266 struct ipw2100_priv *priv = dev_get_drvdata(d);
4267 ipw_radio_kill_sw(priv, buf[0] == '1');
4268 return count;
4269 }
4270
4271 static DEVICE_ATTR_RW(rf_kill);
4272
4273 static struct attribute *ipw2100_sysfs_entries[] = {
4274 &dev_attr_hardware.attr,
4275 &dev_attr_registers.attr,
4276 &dev_attr_ordinals.attr,
4277 &dev_attr_pci.attr,
4278 &dev_attr_stats.attr,
4279 &dev_attr_internals.attr,
4280 &dev_attr_bssinfo.attr,
4281 &dev_attr_memory.attr,
4282 &dev_attr_scan_age.attr,
4283 &dev_attr_fatal_error.attr,
4284 &dev_attr_rf_kill.attr,
4285 &dev_attr_cfg.attr,
4286 &dev_attr_status.attr,
4287 &dev_attr_capability.attr,
4288 NULL,
4289 };
4290
4291 static const struct attribute_group ipw2100_attribute_group = {
4292 .attrs = ipw2100_sysfs_entries,
4293 };
4294
status_queue_allocate(struct ipw2100_priv * priv,int entries)4295 static int status_queue_allocate(struct ipw2100_priv *priv, int entries)
4296 {
4297 struct ipw2100_status_queue *q = &priv->status_queue;
4298
4299 IPW_DEBUG_INFO("enter\n");
4300
4301 q->size = entries * sizeof(struct ipw2100_status);
4302 q->drv = dma_alloc_coherent(&priv->pci_dev->dev, q->size, &q->nic,
4303 GFP_KERNEL);
4304 if (!q->drv) {
4305 IPW_DEBUG_WARNING("Can not allocate status queue.\n");
4306 return -ENOMEM;
4307 }
4308
4309 IPW_DEBUG_INFO("exit\n");
4310
4311 return 0;
4312 }
4313
status_queue_free(struct ipw2100_priv * priv)4314 static void status_queue_free(struct ipw2100_priv *priv)
4315 {
4316 IPW_DEBUG_INFO("enter\n");
4317
4318 if (priv->status_queue.drv) {
4319 dma_free_coherent(&priv->pci_dev->dev,
4320 priv->status_queue.size,
4321 priv->status_queue.drv,
4322 priv->status_queue.nic);
4323 priv->status_queue.drv = NULL;
4324 }
4325
4326 IPW_DEBUG_INFO("exit\n");
4327 }
4328
bd_queue_allocate(struct ipw2100_priv * priv,struct ipw2100_bd_queue * q,int entries)4329 static int bd_queue_allocate(struct ipw2100_priv *priv,
4330 struct ipw2100_bd_queue *q, int entries)
4331 {
4332 IPW_DEBUG_INFO("enter\n");
4333
4334 memset(q, 0, sizeof(struct ipw2100_bd_queue));
4335
4336 q->entries = entries;
4337 q->size = entries * sizeof(struct ipw2100_bd);
4338 q->drv = dma_alloc_coherent(&priv->pci_dev->dev, q->size, &q->nic,
4339 GFP_KERNEL);
4340 if (!q->drv) {
4341 IPW_DEBUG_INFO
4342 ("can't allocate shared memory for buffer descriptors\n");
4343 return -ENOMEM;
4344 }
4345
4346 IPW_DEBUG_INFO("exit\n");
4347
4348 return 0;
4349 }
4350
bd_queue_free(struct ipw2100_priv * priv,struct ipw2100_bd_queue * q)4351 static void bd_queue_free(struct ipw2100_priv *priv, struct ipw2100_bd_queue *q)
4352 {
4353 IPW_DEBUG_INFO("enter\n");
4354
4355 if (!q)
4356 return;
4357
4358 if (q->drv) {
4359 dma_free_coherent(&priv->pci_dev->dev, q->size, q->drv,
4360 q->nic);
4361 q->drv = NULL;
4362 }
4363
4364 IPW_DEBUG_INFO("exit\n");
4365 }
4366
bd_queue_initialize(struct ipw2100_priv * priv,struct ipw2100_bd_queue * q,u32 base,u32 size,u32 r,u32 w)4367 static void bd_queue_initialize(struct ipw2100_priv *priv,
4368 struct ipw2100_bd_queue *q, u32 base, u32 size,
4369 u32 r, u32 w)
4370 {
4371 IPW_DEBUG_INFO("enter\n");
4372
4373 IPW_DEBUG_INFO("initializing bd queue at virt=%p, phys=%08x\n", q->drv,
4374 (u32) q->nic);
4375
4376 write_register(priv->net_dev, base, q->nic);
4377 write_register(priv->net_dev, size, q->entries);
4378 write_register(priv->net_dev, r, q->oldest);
4379 write_register(priv->net_dev, w, q->next);
4380
4381 IPW_DEBUG_INFO("exit\n");
4382 }
4383
ipw2100_kill_works(struct ipw2100_priv * priv)4384 static void ipw2100_kill_works(struct ipw2100_priv *priv)
4385 {
4386 priv->stop_rf_kill = 1;
4387 priv->stop_hang_check = 1;
4388 cancel_delayed_work_sync(&priv->reset_work);
4389 cancel_delayed_work_sync(&priv->security_work);
4390 cancel_delayed_work_sync(&priv->wx_event_work);
4391 cancel_delayed_work_sync(&priv->hang_check);
4392 cancel_delayed_work_sync(&priv->rf_kill);
4393 cancel_delayed_work_sync(&priv->scan_event);
4394 }
4395
ipw2100_tx_allocate(struct ipw2100_priv * priv)4396 static int ipw2100_tx_allocate(struct ipw2100_priv *priv)
4397 {
4398 int i, j, err;
4399 void *v;
4400 dma_addr_t p;
4401
4402 IPW_DEBUG_INFO("enter\n");
4403
4404 err = bd_queue_allocate(priv, &priv->tx_queue, TX_QUEUE_LENGTH);
4405 if (err) {
4406 IPW_DEBUG_ERROR("%s: failed bd_queue_allocate\n",
4407 priv->net_dev->name);
4408 return err;
4409 }
4410
4411 priv->tx_buffers = kmalloc_objs(struct ipw2100_tx_packet,
4412 TX_PENDED_QUEUE_LENGTH, GFP_KERNEL);
4413 if (!priv->tx_buffers) {
4414 bd_queue_free(priv, &priv->tx_queue);
4415 return -ENOMEM;
4416 }
4417
4418 for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
4419 v = dma_alloc_coherent(&priv->pci_dev->dev,
4420 sizeof(struct ipw2100_data_header), &p,
4421 GFP_KERNEL);
4422 if (!v) {
4423 printk(KERN_ERR DRV_NAME
4424 ": %s: PCI alloc failed for tx " "buffers.\n",
4425 priv->net_dev->name);
4426 err = -ENOMEM;
4427 break;
4428 }
4429
4430 priv->tx_buffers[i].type = DATA;
4431 priv->tx_buffers[i].info.d_struct.data =
4432 (struct ipw2100_data_header *)v;
4433 priv->tx_buffers[i].info.d_struct.data_phys = p;
4434 priv->tx_buffers[i].info.d_struct.txb = NULL;
4435 }
4436
4437 if (i == TX_PENDED_QUEUE_LENGTH)
4438 return 0;
4439
4440 for (j = 0; j < i; j++) {
4441 dma_free_coherent(&priv->pci_dev->dev,
4442 sizeof(struct ipw2100_data_header),
4443 priv->tx_buffers[j].info.d_struct.data,
4444 priv->tx_buffers[j].info.d_struct.data_phys);
4445 }
4446
4447 kfree(priv->tx_buffers);
4448 priv->tx_buffers = NULL;
4449
4450 return err;
4451 }
4452
ipw2100_tx_initialize(struct ipw2100_priv * priv)4453 static void ipw2100_tx_initialize(struct ipw2100_priv *priv)
4454 {
4455 int i;
4456
4457 IPW_DEBUG_INFO("enter\n");
4458
4459 /*
4460 * reinitialize packet info lists
4461 */
4462 INIT_LIST_HEAD(&priv->fw_pend_list);
4463 INIT_STAT(&priv->fw_pend_stat);
4464
4465 /*
4466 * reinitialize lists
4467 */
4468 INIT_LIST_HEAD(&priv->tx_pend_list);
4469 INIT_LIST_HEAD(&priv->tx_free_list);
4470 INIT_STAT(&priv->tx_pend_stat);
4471 INIT_STAT(&priv->tx_free_stat);
4472
4473 for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
4474 /* We simply drop any SKBs that have been queued for
4475 * transmit */
4476 if (priv->tx_buffers[i].info.d_struct.txb) {
4477 libipw_txb_free(priv->tx_buffers[i].info.d_struct.
4478 txb);
4479 priv->tx_buffers[i].info.d_struct.txb = NULL;
4480 }
4481
4482 list_add_tail(&priv->tx_buffers[i].list, &priv->tx_free_list);
4483 }
4484
4485 SET_STAT(&priv->tx_free_stat, i);
4486
4487 priv->tx_queue.oldest = 0;
4488 priv->tx_queue.available = priv->tx_queue.entries;
4489 priv->tx_queue.next = 0;
4490 INIT_STAT(&priv->txq_stat);
4491 SET_STAT(&priv->txq_stat, priv->tx_queue.available);
4492
4493 bd_queue_initialize(priv, &priv->tx_queue,
4494 IPW_MEM_HOST_SHARED_TX_QUEUE_BD_BASE,
4495 IPW_MEM_HOST_SHARED_TX_QUEUE_BD_SIZE,
4496 IPW_MEM_HOST_SHARED_TX_QUEUE_READ_INDEX,
4497 IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX);
4498
4499 IPW_DEBUG_INFO("exit\n");
4500
4501 }
4502
ipw2100_tx_free(struct ipw2100_priv * priv)4503 static void ipw2100_tx_free(struct ipw2100_priv *priv)
4504 {
4505 int i;
4506
4507 IPW_DEBUG_INFO("enter\n");
4508
4509 bd_queue_free(priv, &priv->tx_queue);
4510
4511 if (!priv->tx_buffers)
4512 return;
4513
4514 for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
4515 if (priv->tx_buffers[i].info.d_struct.txb) {
4516 libipw_txb_free(priv->tx_buffers[i].info.d_struct.
4517 txb);
4518 priv->tx_buffers[i].info.d_struct.txb = NULL;
4519 }
4520 if (priv->tx_buffers[i].info.d_struct.data)
4521 dma_free_coherent(&priv->pci_dev->dev,
4522 sizeof(struct ipw2100_data_header),
4523 priv->tx_buffers[i].info.d_struct.data,
4524 priv->tx_buffers[i].info.d_struct.data_phys);
4525 }
4526
4527 kfree(priv->tx_buffers);
4528 priv->tx_buffers = NULL;
4529
4530 IPW_DEBUG_INFO("exit\n");
4531 }
4532
ipw2100_rx_allocate(struct ipw2100_priv * priv)4533 static int ipw2100_rx_allocate(struct ipw2100_priv *priv)
4534 {
4535 int i, j, err = -EINVAL;
4536
4537 IPW_DEBUG_INFO("enter\n");
4538
4539 err = bd_queue_allocate(priv, &priv->rx_queue, RX_QUEUE_LENGTH);
4540 if (err) {
4541 IPW_DEBUG_INFO("failed bd_queue_allocate\n");
4542 return err;
4543 }
4544
4545 err = status_queue_allocate(priv, RX_QUEUE_LENGTH);
4546 if (err) {
4547 IPW_DEBUG_INFO("failed status_queue_allocate\n");
4548 bd_queue_free(priv, &priv->rx_queue);
4549 return err;
4550 }
4551
4552 /*
4553 * allocate packets
4554 */
4555 priv->rx_buffers = kmalloc_objs(struct ipw2100_rx_packet,
4556 RX_QUEUE_LENGTH, GFP_KERNEL);
4557 if (!priv->rx_buffers) {
4558 IPW_DEBUG_INFO("can't allocate rx packet buffer table\n");
4559
4560 bd_queue_free(priv, &priv->rx_queue);
4561
4562 status_queue_free(priv);
4563
4564 return -ENOMEM;
4565 }
4566
4567 for (i = 0; i < RX_QUEUE_LENGTH; i++) {
4568 struct ipw2100_rx_packet *packet = &priv->rx_buffers[i];
4569
4570 err = ipw2100_alloc_skb(priv, packet);
4571 if (unlikely(err)) {
4572 err = -ENOMEM;
4573 break;
4574 }
4575
4576 /* The BD holds the cache aligned address */
4577 priv->rx_queue.drv[i].host_addr = packet->dma_addr;
4578 priv->rx_queue.drv[i].buf_length = IPW_RX_NIC_BUFFER_LENGTH;
4579 priv->status_queue.drv[i].status_fields = 0;
4580 }
4581
4582 if (i == RX_QUEUE_LENGTH)
4583 return 0;
4584
4585 for (j = 0; j < i; j++) {
4586 dma_unmap_single(&priv->pci_dev->dev,
4587 priv->rx_buffers[j].dma_addr,
4588 sizeof(struct ipw2100_rx_packet),
4589 DMA_FROM_DEVICE);
4590 dev_kfree_skb(priv->rx_buffers[j].skb);
4591 }
4592
4593 kfree(priv->rx_buffers);
4594 priv->rx_buffers = NULL;
4595
4596 bd_queue_free(priv, &priv->rx_queue);
4597
4598 status_queue_free(priv);
4599
4600 return err;
4601 }
4602
ipw2100_rx_initialize(struct ipw2100_priv * priv)4603 static void ipw2100_rx_initialize(struct ipw2100_priv *priv)
4604 {
4605 IPW_DEBUG_INFO("enter\n");
4606
4607 priv->rx_queue.oldest = 0;
4608 priv->rx_queue.available = priv->rx_queue.entries - 1;
4609 priv->rx_queue.next = priv->rx_queue.entries - 1;
4610
4611 INIT_STAT(&priv->rxq_stat);
4612 SET_STAT(&priv->rxq_stat, priv->rx_queue.available);
4613
4614 bd_queue_initialize(priv, &priv->rx_queue,
4615 IPW_MEM_HOST_SHARED_RX_BD_BASE,
4616 IPW_MEM_HOST_SHARED_RX_BD_SIZE,
4617 IPW_MEM_HOST_SHARED_RX_READ_INDEX,
4618 IPW_MEM_HOST_SHARED_RX_WRITE_INDEX);
4619
4620 /* set up the status queue */
4621 write_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_STATUS_BASE,
4622 priv->status_queue.nic);
4623
4624 IPW_DEBUG_INFO("exit\n");
4625 }
4626
ipw2100_rx_free(struct ipw2100_priv * priv)4627 static void ipw2100_rx_free(struct ipw2100_priv *priv)
4628 {
4629 int i;
4630
4631 IPW_DEBUG_INFO("enter\n");
4632
4633 bd_queue_free(priv, &priv->rx_queue);
4634 status_queue_free(priv);
4635
4636 if (!priv->rx_buffers)
4637 return;
4638
4639 for (i = 0; i < RX_QUEUE_LENGTH; i++) {
4640 if (priv->rx_buffers[i].rxp) {
4641 dma_unmap_single(&priv->pci_dev->dev,
4642 priv->rx_buffers[i].dma_addr,
4643 sizeof(struct ipw2100_rx),
4644 DMA_FROM_DEVICE);
4645 dev_kfree_skb(priv->rx_buffers[i].skb);
4646 }
4647 }
4648
4649 kfree(priv->rx_buffers);
4650 priv->rx_buffers = NULL;
4651
4652 IPW_DEBUG_INFO("exit\n");
4653 }
4654
ipw2100_read_mac_address(struct ipw2100_priv * priv)4655 static int ipw2100_read_mac_address(struct ipw2100_priv *priv)
4656 {
4657 u32 length = ETH_ALEN;
4658 u8 addr[ETH_ALEN];
4659
4660 int err;
4661
4662 err = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ADAPTER_MAC, addr, &length);
4663 if (err) {
4664 IPW_DEBUG_INFO("MAC address read failed\n");
4665 return -EIO;
4666 }
4667
4668 eth_hw_addr_set(priv->net_dev, addr);
4669 IPW_DEBUG_INFO("card MAC is %pM\n", priv->net_dev->dev_addr);
4670
4671 return 0;
4672 }
4673
4674 /********************************************************************
4675 *
4676 * Firmware Commands
4677 *
4678 ********************************************************************/
4679
ipw2100_set_mac_address(struct ipw2100_priv * priv,int batch_mode)4680 static int ipw2100_set_mac_address(struct ipw2100_priv *priv, int batch_mode)
4681 {
4682 struct host_command cmd = {
4683 .host_command = ADAPTER_ADDRESS,
4684 .host_command_sequence = 0,
4685 .host_command_length = ETH_ALEN
4686 };
4687 int err;
4688
4689 IPW_DEBUG_HC("SET_MAC_ADDRESS\n");
4690
4691 IPW_DEBUG_INFO("enter\n");
4692
4693 if (priv->config & CFG_CUSTOM_MAC) {
4694 memcpy(cmd.host_command_parameters, priv->mac_addr, ETH_ALEN);
4695 eth_hw_addr_set(priv->net_dev, priv->mac_addr);
4696 } else
4697 memcpy(cmd.host_command_parameters, priv->net_dev->dev_addr,
4698 ETH_ALEN);
4699
4700 err = ipw2100_hw_send_command(priv, &cmd);
4701
4702 IPW_DEBUG_INFO("exit\n");
4703 return err;
4704 }
4705
ipw2100_set_port_type(struct ipw2100_priv * priv,u32 port_type,int batch_mode)4706 static int ipw2100_set_port_type(struct ipw2100_priv *priv, u32 port_type,
4707 int batch_mode)
4708 {
4709 struct host_command cmd = {
4710 .host_command = PORT_TYPE,
4711 .host_command_sequence = 0,
4712 .host_command_length = sizeof(u32)
4713 };
4714 int err;
4715
4716 switch (port_type) {
4717 case IW_MODE_INFRA:
4718 cmd.host_command_parameters[0] = IPW_BSS;
4719 break;
4720 case IW_MODE_ADHOC:
4721 cmd.host_command_parameters[0] = IPW_IBSS;
4722 break;
4723 }
4724
4725 IPW_DEBUG_HC("PORT_TYPE: %s\n",
4726 port_type == IPW_IBSS ? "Ad-Hoc" : "Managed");
4727
4728 if (!batch_mode) {
4729 err = ipw2100_disable_adapter(priv);
4730 if (err) {
4731 printk(KERN_ERR DRV_NAME
4732 ": %s: Could not disable adapter %d\n",
4733 priv->net_dev->name, err);
4734 return err;
4735 }
4736 }
4737
4738 /* send cmd to firmware */
4739 err = ipw2100_hw_send_command(priv, &cmd);
4740
4741 if (!batch_mode)
4742 ipw2100_enable_adapter(priv);
4743
4744 return err;
4745 }
4746
ipw2100_set_channel(struct ipw2100_priv * priv,u32 channel,int batch_mode)4747 static int ipw2100_set_channel(struct ipw2100_priv *priv, u32 channel,
4748 int batch_mode)
4749 {
4750 struct host_command cmd = {
4751 .host_command = CHANNEL,
4752 .host_command_sequence = 0,
4753 .host_command_length = sizeof(u32)
4754 };
4755 int err;
4756
4757 cmd.host_command_parameters[0] = channel;
4758
4759 IPW_DEBUG_HC("CHANNEL: %d\n", channel);
4760
4761 /* If BSS then we don't support channel selection */
4762 if (priv->ieee->iw_mode == IW_MODE_INFRA)
4763 return 0;
4764
4765 if ((channel != 0) &&
4766 ((channel < REG_MIN_CHANNEL) || (channel > REG_MAX_CHANNEL)))
4767 return -EINVAL;
4768
4769 if (!batch_mode) {
4770 err = ipw2100_disable_adapter(priv);
4771 if (err)
4772 return err;
4773 }
4774
4775 err = ipw2100_hw_send_command(priv, &cmd);
4776 if (err) {
4777 IPW_DEBUG_INFO("Failed to set channel to %d", channel);
4778 return err;
4779 }
4780
4781 if (channel)
4782 priv->config |= CFG_STATIC_CHANNEL;
4783 else
4784 priv->config &= ~CFG_STATIC_CHANNEL;
4785
4786 priv->channel = channel;
4787
4788 if (!batch_mode) {
4789 err = ipw2100_enable_adapter(priv);
4790 if (err)
4791 return err;
4792 }
4793
4794 return 0;
4795 }
4796
ipw2100_system_config(struct ipw2100_priv * priv,int batch_mode)4797 static int ipw2100_system_config(struct ipw2100_priv *priv, int batch_mode)
4798 {
4799 struct host_command cmd = {
4800 .host_command = SYSTEM_CONFIG,
4801 .host_command_sequence = 0,
4802 .host_command_length = 12,
4803 };
4804 u32 ibss_mask, len = sizeof(u32);
4805 int err;
4806
4807 /* Set system configuration */
4808
4809 if (!batch_mode) {
4810 err = ipw2100_disable_adapter(priv);
4811 if (err)
4812 return err;
4813 }
4814
4815 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
4816 cmd.host_command_parameters[0] |= IPW_CFG_IBSS_AUTO_START;
4817
4818 cmd.host_command_parameters[0] |= IPW_CFG_IBSS_MASK |
4819 IPW_CFG_BSS_MASK | IPW_CFG_802_1x_ENABLE;
4820
4821 if (!(priv->config & CFG_LONG_PREAMBLE))
4822 cmd.host_command_parameters[0] |= IPW_CFG_PREAMBLE_AUTO;
4823
4824 err = ipw2100_get_ordinal(priv,
4825 IPW_ORD_EEPROM_IBSS_11B_CHANNELS,
4826 &ibss_mask, &len);
4827 if (err)
4828 ibss_mask = IPW_IBSS_11B_DEFAULT_MASK;
4829
4830 cmd.host_command_parameters[1] = REG_CHANNEL_MASK;
4831 cmd.host_command_parameters[2] = REG_CHANNEL_MASK & ibss_mask;
4832
4833 /* 11b only */
4834 /*cmd.host_command_parameters[0] |= DIVERSITY_ANTENNA_A; */
4835
4836 err = ipw2100_hw_send_command(priv, &cmd);
4837 if (err)
4838 return err;
4839
4840 /* If IPv6 is configured in the kernel then we don't want to filter out all
4841 * of the multicast packets as IPv6 needs some. */
4842 #if !defined(CONFIG_IPV6) && !defined(CONFIG_IPV6_MODULE)
4843 cmd.host_command = ADD_MULTICAST;
4844 cmd.host_command_sequence = 0;
4845 cmd.host_command_length = 0;
4846
4847 ipw2100_hw_send_command(priv, &cmd);
4848 #endif
4849 if (!batch_mode) {
4850 err = ipw2100_enable_adapter(priv);
4851 if (err)
4852 return err;
4853 }
4854
4855 return 0;
4856 }
4857
ipw2100_set_tx_rates(struct ipw2100_priv * priv,u32 rate,int batch_mode)4858 static int ipw2100_set_tx_rates(struct ipw2100_priv *priv, u32 rate,
4859 int batch_mode)
4860 {
4861 struct host_command cmd = {
4862 .host_command = BASIC_TX_RATES,
4863 .host_command_sequence = 0,
4864 .host_command_length = 4
4865 };
4866 int err;
4867
4868 cmd.host_command_parameters[0] = rate & TX_RATE_MASK;
4869
4870 if (!batch_mode) {
4871 err = ipw2100_disable_adapter(priv);
4872 if (err)
4873 return err;
4874 }
4875
4876 /* Set BASIC TX Rate first */
4877 ipw2100_hw_send_command(priv, &cmd);
4878
4879 /* Set TX Rate */
4880 cmd.host_command = TX_RATES;
4881 ipw2100_hw_send_command(priv, &cmd);
4882
4883 /* Set MSDU TX Rate */
4884 cmd.host_command = MSDU_TX_RATES;
4885 ipw2100_hw_send_command(priv, &cmd);
4886
4887 if (!batch_mode) {
4888 err = ipw2100_enable_adapter(priv);
4889 if (err)
4890 return err;
4891 }
4892
4893 priv->tx_rates = rate;
4894
4895 return 0;
4896 }
4897
ipw2100_set_power_mode(struct ipw2100_priv * priv,int power_level)4898 static int ipw2100_set_power_mode(struct ipw2100_priv *priv, int power_level)
4899 {
4900 struct host_command cmd = {
4901 .host_command = POWER_MODE,
4902 .host_command_sequence = 0,
4903 .host_command_length = 4
4904 };
4905 int err;
4906
4907 cmd.host_command_parameters[0] = power_level;
4908
4909 err = ipw2100_hw_send_command(priv, &cmd);
4910 if (err)
4911 return err;
4912
4913 if (power_level == IPW_POWER_MODE_CAM)
4914 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
4915 else
4916 priv->power_mode = IPW_POWER_ENABLED | power_level;
4917
4918 #ifdef IPW2100_TX_POWER
4919 if (priv->port_type == IBSS && priv->adhoc_power != DFTL_IBSS_TX_POWER) {
4920 /* Set beacon interval */
4921 cmd.host_command = TX_POWER_INDEX;
4922 cmd.host_command_parameters[0] = (u32) priv->adhoc_power;
4923
4924 err = ipw2100_hw_send_command(priv, &cmd);
4925 if (err)
4926 return err;
4927 }
4928 #endif
4929
4930 return 0;
4931 }
4932
ipw2100_set_rts_threshold(struct ipw2100_priv * priv,u32 threshold)4933 static int ipw2100_set_rts_threshold(struct ipw2100_priv *priv, u32 threshold)
4934 {
4935 struct host_command cmd = {
4936 .host_command = RTS_THRESHOLD,
4937 .host_command_sequence = 0,
4938 .host_command_length = 4
4939 };
4940 int err;
4941
4942 if (threshold & RTS_DISABLED)
4943 cmd.host_command_parameters[0] = MAX_RTS_THRESHOLD;
4944 else
4945 cmd.host_command_parameters[0] = threshold & ~RTS_DISABLED;
4946
4947 err = ipw2100_hw_send_command(priv, &cmd);
4948 if (err)
4949 return err;
4950
4951 priv->rts_threshold = threshold;
4952
4953 return 0;
4954 }
4955
4956 #if 0
4957 int ipw2100_set_fragmentation_threshold(struct ipw2100_priv *priv,
4958 u32 threshold, int batch_mode)
4959 {
4960 struct host_command cmd = {
4961 .host_command = FRAG_THRESHOLD,
4962 .host_command_sequence = 0,
4963 .host_command_length = 4,
4964 .host_command_parameters[0] = 0,
4965 };
4966 int err;
4967
4968 if (!batch_mode) {
4969 err = ipw2100_disable_adapter(priv);
4970 if (err)
4971 return err;
4972 }
4973
4974 if (threshold == 0)
4975 threshold = DEFAULT_FRAG_THRESHOLD;
4976 else {
4977 threshold = max(threshold, MIN_FRAG_THRESHOLD);
4978 threshold = min(threshold, MAX_FRAG_THRESHOLD);
4979 }
4980
4981 cmd.host_command_parameters[0] = threshold;
4982
4983 IPW_DEBUG_HC("FRAG_THRESHOLD: %u\n", threshold);
4984
4985 err = ipw2100_hw_send_command(priv, &cmd);
4986
4987 if (!batch_mode)
4988 ipw2100_enable_adapter(priv);
4989
4990 if (!err)
4991 priv->frag_threshold = threshold;
4992
4993 return err;
4994 }
4995 #endif
4996
ipw2100_set_short_retry(struct ipw2100_priv * priv,u32 retry)4997 static int ipw2100_set_short_retry(struct ipw2100_priv *priv, u32 retry)
4998 {
4999 struct host_command cmd = {
5000 .host_command = SHORT_RETRY_LIMIT,
5001 .host_command_sequence = 0,
5002 .host_command_length = 4
5003 };
5004 int err;
5005
5006 cmd.host_command_parameters[0] = retry;
5007
5008 err = ipw2100_hw_send_command(priv, &cmd);
5009 if (err)
5010 return err;
5011
5012 priv->short_retry_limit = retry;
5013
5014 return 0;
5015 }
5016
ipw2100_set_long_retry(struct ipw2100_priv * priv,u32 retry)5017 static int ipw2100_set_long_retry(struct ipw2100_priv *priv, u32 retry)
5018 {
5019 struct host_command cmd = {
5020 .host_command = LONG_RETRY_LIMIT,
5021 .host_command_sequence = 0,
5022 .host_command_length = 4
5023 };
5024 int err;
5025
5026 cmd.host_command_parameters[0] = retry;
5027
5028 err = ipw2100_hw_send_command(priv, &cmd);
5029 if (err)
5030 return err;
5031
5032 priv->long_retry_limit = retry;
5033
5034 return 0;
5035 }
5036
ipw2100_set_mandatory_bssid(struct ipw2100_priv * priv,u8 * bssid,int batch_mode)5037 static int ipw2100_set_mandatory_bssid(struct ipw2100_priv *priv, u8 * bssid,
5038 int batch_mode)
5039 {
5040 struct host_command cmd = {
5041 .host_command = MANDATORY_BSSID,
5042 .host_command_sequence = 0,
5043 .host_command_length = (bssid == NULL) ? 0 : ETH_ALEN
5044 };
5045 int err;
5046
5047 #ifdef CONFIG_IPW2100_DEBUG
5048 if (bssid != NULL)
5049 IPW_DEBUG_HC("MANDATORY_BSSID: %pM\n", bssid);
5050 else
5051 IPW_DEBUG_HC("MANDATORY_BSSID: <clear>\n");
5052 #endif
5053 /* if BSSID is empty then we disable mandatory bssid mode */
5054 if (bssid != NULL)
5055 memcpy(cmd.host_command_parameters, bssid, ETH_ALEN);
5056
5057 if (!batch_mode) {
5058 err = ipw2100_disable_adapter(priv);
5059 if (err)
5060 return err;
5061 }
5062
5063 err = ipw2100_hw_send_command(priv, &cmd);
5064
5065 if (!batch_mode)
5066 ipw2100_enable_adapter(priv);
5067
5068 return err;
5069 }
5070
ipw2100_disassociate_bssid(struct ipw2100_priv * priv)5071 static int ipw2100_disassociate_bssid(struct ipw2100_priv *priv)
5072 {
5073 struct host_command cmd = {
5074 .host_command = DISASSOCIATION_BSSID,
5075 .host_command_sequence = 0,
5076 .host_command_length = ETH_ALEN
5077 };
5078 int err;
5079
5080 IPW_DEBUG_HC("DISASSOCIATION_BSSID\n");
5081
5082 /* The Firmware currently ignores the BSSID and just disassociates from
5083 * the currently associated AP -- but in the off chance that a future
5084 * firmware does use the BSSID provided here, we go ahead and try and
5085 * set it to the currently associated AP's BSSID */
5086 memcpy(cmd.host_command_parameters, priv->bssid, ETH_ALEN);
5087
5088 err = ipw2100_hw_send_command(priv, &cmd);
5089
5090 return err;
5091 }
5092
5093 static int ipw2100_set_wpa_ie(struct ipw2100_priv *,
5094 struct ipw2100_wpa_assoc_frame *, int)
5095 __attribute__ ((unused));
5096
ipw2100_set_wpa_ie(struct ipw2100_priv * priv,struct ipw2100_wpa_assoc_frame * wpa_frame,int batch_mode)5097 static int ipw2100_set_wpa_ie(struct ipw2100_priv *priv,
5098 struct ipw2100_wpa_assoc_frame *wpa_frame,
5099 int batch_mode)
5100 {
5101 struct host_command cmd = {
5102 .host_command = SET_WPA_IE,
5103 .host_command_sequence = 0,
5104 .host_command_length = sizeof(struct ipw2100_wpa_assoc_frame),
5105 };
5106 int err;
5107
5108 IPW_DEBUG_HC("SET_WPA_IE\n");
5109
5110 if (!batch_mode) {
5111 err = ipw2100_disable_adapter(priv);
5112 if (err)
5113 return err;
5114 }
5115
5116 memcpy(cmd.host_command_parameters, wpa_frame,
5117 sizeof(struct ipw2100_wpa_assoc_frame));
5118
5119 err = ipw2100_hw_send_command(priv, &cmd);
5120
5121 if (!batch_mode) {
5122 if (ipw2100_enable_adapter(priv))
5123 err = -EIO;
5124 }
5125
5126 return err;
5127 }
5128
5129 struct security_info_params {
5130 u32 allowed_ciphers;
5131 u16 version;
5132 u8 auth_mode;
5133 u8 replay_counters_number;
5134 u8 unicast_using_group;
5135 } __packed;
5136
ipw2100_set_security_information(struct ipw2100_priv * priv,int auth_mode,int security_level,int unicast_using_group,int batch_mode)5137 static int ipw2100_set_security_information(struct ipw2100_priv *priv,
5138 int auth_mode,
5139 int security_level,
5140 int unicast_using_group,
5141 int batch_mode)
5142 {
5143 struct host_command cmd = {
5144 .host_command = SET_SECURITY_INFORMATION,
5145 .host_command_sequence = 0,
5146 .host_command_length = sizeof(struct security_info_params)
5147 };
5148 struct security_info_params *security =
5149 (struct security_info_params *)&cmd.host_command_parameters;
5150 int err;
5151 memset(security, 0, sizeof(*security));
5152
5153 /* If shared key AP authentication is turned on, then we need to
5154 * configure the firmware to try and use it.
5155 *
5156 * Actual data encryption/decryption is handled by the host. */
5157 security->auth_mode = auth_mode;
5158 security->unicast_using_group = unicast_using_group;
5159
5160 switch (security_level) {
5161 default:
5162 case SEC_LEVEL_0:
5163 security->allowed_ciphers = IPW_NONE_CIPHER;
5164 break;
5165 case SEC_LEVEL_1:
5166 security->allowed_ciphers = IPW_WEP40_CIPHER |
5167 IPW_WEP104_CIPHER;
5168 break;
5169 case SEC_LEVEL_2:
5170 security->allowed_ciphers = IPW_WEP40_CIPHER |
5171 IPW_WEP104_CIPHER | IPW_TKIP_CIPHER;
5172 break;
5173 case SEC_LEVEL_2_CKIP:
5174 security->allowed_ciphers = IPW_WEP40_CIPHER |
5175 IPW_WEP104_CIPHER | IPW_CKIP_CIPHER;
5176 break;
5177 case SEC_LEVEL_3:
5178 security->allowed_ciphers = IPW_WEP40_CIPHER |
5179 IPW_WEP104_CIPHER | IPW_TKIP_CIPHER | IPW_CCMP_CIPHER;
5180 break;
5181 }
5182
5183 IPW_DEBUG_HC
5184 ("SET_SECURITY_INFORMATION: auth:%d cipher:0x%02X (level %d)\n",
5185 security->auth_mode, security->allowed_ciphers, security_level);
5186
5187 security->replay_counters_number = 0;
5188
5189 if (!batch_mode) {
5190 err = ipw2100_disable_adapter(priv);
5191 if (err)
5192 return err;
5193 }
5194
5195 err = ipw2100_hw_send_command(priv, &cmd);
5196
5197 if (!batch_mode)
5198 ipw2100_enable_adapter(priv);
5199
5200 return err;
5201 }
5202
ipw2100_set_tx_power(struct ipw2100_priv * priv,u32 tx_power)5203 static int ipw2100_set_tx_power(struct ipw2100_priv *priv, u32 tx_power)
5204 {
5205 struct host_command cmd = {
5206 .host_command = TX_POWER_INDEX,
5207 .host_command_sequence = 0,
5208 .host_command_length = 4
5209 };
5210 int err = 0;
5211 u32 tmp = tx_power;
5212
5213 if (tx_power != IPW_TX_POWER_DEFAULT)
5214 tmp = (tx_power - IPW_TX_POWER_MIN_DBM) * 16 /
5215 (IPW_TX_POWER_MAX_DBM - IPW_TX_POWER_MIN_DBM);
5216
5217 cmd.host_command_parameters[0] = tmp;
5218
5219 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
5220 err = ipw2100_hw_send_command(priv, &cmd);
5221 if (!err)
5222 priv->tx_power = tx_power;
5223
5224 return 0;
5225 }
5226
ipw2100_set_ibss_beacon_interval(struct ipw2100_priv * priv,u32 interval,int batch_mode)5227 static int ipw2100_set_ibss_beacon_interval(struct ipw2100_priv *priv,
5228 u32 interval, int batch_mode)
5229 {
5230 struct host_command cmd = {
5231 .host_command = BEACON_INTERVAL,
5232 .host_command_sequence = 0,
5233 .host_command_length = 4
5234 };
5235 int err;
5236
5237 cmd.host_command_parameters[0] = interval;
5238
5239 IPW_DEBUG_INFO("enter\n");
5240
5241 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
5242 if (!batch_mode) {
5243 err = ipw2100_disable_adapter(priv);
5244 if (err)
5245 return err;
5246 }
5247
5248 ipw2100_hw_send_command(priv, &cmd);
5249
5250 if (!batch_mode) {
5251 err = ipw2100_enable_adapter(priv);
5252 if (err)
5253 return err;
5254 }
5255 }
5256
5257 IPW_DEBUG_INFO("exit\n");
5258
5259 return 0;
5260 }
5261
ipw2100_queues_initialize(struct ipw2100_priv * priv)5262 static void ipw2100_queues_initialize(struct ipw2100_priv *priv)
5263 {
5264 ipw2100_tx_initialize(priv);
5265 ipw2100_rx_initialize(priv);
5266 ipw2100_msg_initialize(priv);
5267 }
5268
ipw2100_queues_free(struct ipw2100_priv * priv)5269 static void ipw2100_queues_free(struct ipw2100_priv *priv)
5270 {
5271 ipw2100_tx_free(priv);
5272 ipw2100_rx_free(priv);
5273 ipw2100_msg_free(priv);
5274 }
5275
ipw2100_queues_allocate(struct ipw2100_priv * priv)5276 static int ipw2100_queues_allocate(struct ipw2100_priv *priv)
5277 {
5278 if (ipw2100_tx_allocate(priv) ||
5279 ipw2100_rx_allocate(priv) || ipw2100_msg_allocate(priv))
5280 goto fail;
5281
5282 return 0;
5283
5284 fail:
5285 ipw2100_tx_free(priv);
5286 ipw2100_rx_free(priv);
5287 ipw2100_msg_free(priv);
5288 return -ENOMEM;
5289 }
5290
5291 #define IPW_PRIVACY_CAPABLE 0x0008
5292
ipw2100_set_wep_flags(struct ipw2100_priv * priv,u32 flags,int batch_mode)5293 static int ipw2100_set_wep_flags(struct ipw2100_priv *priv, u32 flags,
5294 int batch_mode)
5295 {
5296 struct host_command cmd = {
5297 .host_command = WEP_FLAGS,
5298 .host_command_sequence = 0,
5299 .host_command_length = 4
5300 };
5301 int err;
5302
5303 cmd.host_command_parameters[0] = flags;
5304
5305 IPW_DEBUG_HC("WEP_FLAGS: flags = 0x%08X\n", flags);
5306
5307 if (!batch_mode) {
5308 err = ipw2100_disable_adapter(priv);
5309 if (err) {
5310 printk(KERN_ERR DRV_NAME
5311 ": %s: Could not disable adapter %d\n",
5312 priv->net_dev->name, err);
5313 return err;
5314 }
5315 }
5316
5317 /* send cmd to firmware */
5318 err = ipw2100_hw_send_command(priv, &cmd);
5319
5320 if (!batch_mode)
5321 ipw2100_enable_adapter(priv);
5322
5323 return err;
5324 }
5325
5326 struct ipw2100_wep_key {
5327 u8 idx;
5328 u8 len;
5329 u8 key[13];
5330 };
5331
5332 /* Macros to ease up priting WEP keys */
5333 #define WEP_FMT_64 "%02X%02X%02X%02X-%02X"
5334 #define WEP_FMT_128 "%02X%02X%02X%02X-%02X%02X%02X%02X-%02X%02X%02X"
5335 #define WEP_STR_64(x) x[0],x[1],x[2],x[3],x[4]
5336 #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]
5337
5338 /**
5339 * ipw2100_set_key() - Set a the wep key
5340 *
5341 * @priv: struct to work on
5342 * @idx: index of the key we want to set
5343 * @key: ptr to the key data to set
5344 * @len: length of the buffer at @key
5345 * @batch_mode: FIXME perform the operation in batch mode, not
5346 * disabling the device.
5347 *
5348 * @returns 0 if OK, < 0 errno code on error.
5349 *
5350 * Fill out a command structure with the new wep key, length an
5351 * index and send it down the wire.
5352 */
ipw2100_set_key(struct ipw2100_priv * priv,int idx,char * key,int len,int batch_mode)5353 static int ipw2100_set_key(struct ipw2100_priv *priv,
5354 int idx, char *key, int len, int batch_mode)
5355 {
5356 int keylen = len ? (len <= 5 ? 5 : 13) : 0;
5357 struct host_command cmd = {
5358 .host_command = WEP_KEY_INFO,
5359 .host_command_sequence = 0,
5360 .host_command_length = sizeof(struct ipw2100_wep_key),
5361 };
5362 struct ipw2100_wep_key *wep_key = (void *)cmd.host_command_parameters;
5363 int err;
5364
5365 IPW_DEBUG_HC("WEP_KEY_INFO: index = %d, len = %d/%d\n",
5366 idx, keylen, len);
5367
5368 /* NOTE: We don't check cached values in case the firmware was reset
5369 * or some other problem is occurring. If the user is setting the key,
5370 * then we push the change */
5371
5372 wep_key->idx = idx;
5373 wep_key->len = keylen;
5374
5375 if (keylen) {
5376 memcpy(wep_key->key, key, len);
5377 memset(wep_key->key + len, 0, keylen - len);
5378 }
5379
5380 /* Will be optimized out on debug not being configured in */
5381 if (keylen == 0)
5382 IPW_DEBUG_WEP("%s: Clearing key %d\n",
5383 priv->net_dev->name, wep_key->idx);
5384 else if (keylen == 5)
5385 IPW_DEBUG_WEP("%s: idx: %d, len: %d key: " WEP_FMT_64 "\n",
5386 priv->net_dev->name, wep_key->idx, wep_key->len,
5387 WEP_STR_64(wep_key->key));
5388 else
5389 IPW_DEBUG_WEP("%s: idx: %d, len: %d key: " WEP_FMT_128
5390 "\n",
5391 priv->net_dev->name, wep_key->idx, wep_key->len,
5392 WEP_STR_128(wep_key->key));
5393
5394 if (!batch_mode) {
5395 err = ipw2100_disable_adapter(priv);
5396 /* FIXME: IPG: shouldn't this prink be in _disable_adapter()? */
5397 if (err) {
5398 printk(KERN_ERR DRV_NAME
5399 ": %s: Could not disable adapter %d\n",
5400 priv->net_dev->name, err);
5401 return err;
5402 }
5403 }
5404
5405 /* send cmd to firmware */
5406 err = ipw2100_hw_send_command(priv, &cmd);
5407
5408 if (!batch_mode) {
5409 int err2 = ipw2100_enable_adapter(priv);
5410 if (err == 0)
5411 err = err2;
5412 }
5413 return err;
5414 }
5415
ipw2100_set_key_index(struct ipw2100_priv * priv,int idx,int batch_mode)5416 static int ipw2100_set_key_index(struct ipw2100_priv *priv,
5417 int idx, int batch_mode)
5418 {
5419 struct host_command cmd = {
5420 .host_command = WEP_KEY_INDEX,
5421 .host_command_sequence = 0,
5422 .host_command_length = 4,
5423 .host_command_parameters = {idx},
5424 };
5425 int err;
5426
5427 IPW_DEBUG_HC("WEP_KEY_INDEX: index = %d\n", idx);
5428
5429 if (idx < 0 || idx > 3)
5430 return -EINVAL;
5431
5432 if (!batch_mode) {
5433 err = ipw2100_disable_adapter(priv);
5434 if (err) {
5435 printk(KERN_ERR DRV_NAME
5436 ": %s: Could not disable adapter %d\n",
5437 priv->net_dev->name, err);
5438 return err;
5439 }
5440 }
5441
5442 /* send cmd to firmware */
5443 err = ipw2100_hw_send_command(priv, &cmd);
5444
5445 if (!batch_mode)
5446 ipw2100_enable_adapter(priv);
5447
5448 return err;
5449 }
5450
ipw2100_configure_security(struct ipw2100_priv * priv,int batch_mode)5451 static int ipw2100_configure_security(struct ipw2100_priv *priv, int batch_mode)
5452 {
5453 int i, err, auth_mode, sec_level, use_group;
5454
5455 if (!(priv->status & STATUS_RUNNING))
5456 return 0;
5457
5458 if (!batch_mode) {
5459 err = ipw2100_disable_adapter(priv);
5460 if (err)
5461 return err;
5462 }
5463
5464 if (!priv->ieee->sec.enabled) {
5465 err =
5466 ipw2100_set_security_information(priv, IPW_AUTH_OPEN,
5467 SEC_LEVEL_0, 0, 1);
5468 } else {
5469 auth_mode = IPW_AUTH_OPEN;
5470 if (priv->ieee->sec.flags & SEC_AUTH_MODE) {
5471 if (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)
5472 auth_mode = IPW_AUTH_SHARED;
5473 else if (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP)
5474 auth_mode = IPW_AUTH_LEAP_CISCO_ID;
5475 }
5476
5477 sec_level = SEC_LEVEL_0;
5478 if (priv->ieee->sec.flags & SEC_LEVEL)
5479 sec_level = priv->ieee->sec.level;
5480
5481 use_group = 0;
5482 if (priv->ieee->sec.flags & SEC_UNICAST_GROUP)
5483 use_group = priv->ieee->sec.unicast_uses_group;
5484
5485 err =
5486 ipw2100_set_security_information(priv, auth_mode, sec_level,
5487 use_group, 1);
5488 }
5489
5490 if (err)
5491 goto exit;
5492
5493 if (priv->ieee->sec.enabled) {
5494 for (i = 0; i < 4; i++) {
5495 if (!(priv->ieee->sec.flags & (1 << i))) {
5496 memset(priv->ieee->sec.keys[i], 0, WEP_KEY_LEN);
5497 priv->ieee->sec.key_sizes[i] = 0;
5498 } else {
5499 err = ipw2100_set_key(priv, i,
5500 priv->ieee->sec.keys[i],
5501 priv->ieee->sec.
5502 key_sizes[i], 1);
5503 if (err)
5504 goto exit;
5505 }
5506 }
5507
5508 ipw2100_set_key_index(priv, priv->ieee->crypt_info.tx_keyidx, 1);
5509 }
5510
5511 /* Always enable privacy so the Host can filter WEP packets if
5512 * encrypted data is sent up */
5513 err =
5514 ipw2100_set_wep_flags(priv,
5515 priv->ieee->sec.
5516 enabled ? IPW_PRIVACY_CAPABLE : 0, 1);
5517 if (err)
5518 goto exit;
5519
5520 priv->status &= ~STATUS_SECURITY_UPDATED;
5521
5522 exit:
5523 if (!batch_mode)
5524 ipw2100_enable_adapter(priv);
5525
5526 return err;
5527 }
5528
ipw2100_security_work(struct work_struct * work)5529 static void ipw2100_security_work(struct work_struct *work)
5530 {
5531 struct ipw2100_priv *priv =
5532 container_of(work, struct ipw2100_priv, security_work.work);
5533
5534 /* If we happen to have reconnected before we get a chance to
5535 * process this, then update the security settings--which causes
5536 * a disassociation to occur */
5537 if (!(priv->status & STATUS_ASSOCIATED) &&
5538 priv->status & STATUS_SECURITY_UPDATED)
5539 ipw2100_configure_security(priv, 0);
5540 }
5541
shim__set_security(struct net_device * dev,struct libipw_security * sec)5542 static void shim__set_security(struct net_device *dev,
5543 struct libipw_security *sec)
5544 {
5545 struct ipw2100_priv *priv = libipw_priv(dev);
5546 int i;
5547
5548 mutex_lock(&priv->action_mutex);
5549 if (!(priv->status & STATUS_INITIALIZED))
5550 goto done;
5551
5552 for (i = 0; i < 4; i++) {
5553 if (sec->flags & (1 << i)) {
5554 priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
5555 if (sec->key_sizes[i] == 0)
5556 priv->ieee->sec.flags &= ~(1 << i);
5557 else
5558 memcpy(priv->ieee->sec.keys[i], sec->keys[i],
5559 sec->key_sizes[i]);
5560 if (sec->level == SEC_LEVEL_1) {
5561 priv->ieee->sec.flags |= (1 << i);
5562 priv->status |= STATUS_SECURITY_UPDATED;
5563 } else
5564 priv->ieee->sec.flags &= ~(1 << i);
5565 }
5566 }
5567
5568 if ((sec->flags & SEC_ACTIVE_KEY) &&
5569 priv->ieee->sec.active_key != sec->active_key) {
5570 priv->ieee->sec.active_key = sec->active_key;
5571 priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
5572 priv->status |= STATUS_SECURITY_UPDATED;
5573 }
5574
5575 if ((sec->flags & SEC_AUTH_MODE) &&
5576 (priv->ieee->sec.auth_mode != sec->auth_mode)) {
5577 priv->ieee->sec.auth_mode = sec->auth_mode;
5578 priv->ieee->sec.flags |= SEC_AUTH_MODE;
5579 priv->status |= STATUS_SECURITY_UPDATED;
5580 }
5581
5582 if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
5583 priv->ieee->sec.flags |= SEC_ENABLED;
5584 priv->ieee->sec.enabled = sec->enabled;
5585 priv->status |= STATUS_SECURITY_UPDATED;
5586 }
5587
5588 if (sec->flags & SEC_ENCRYPT)
5589 priv->ieee->sec.encrypt = sec->encrypt;
5590
5591 if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
5592 priv->ieee->sec.level = sec->level;
5593 priv->ieee->sec.flags |= SEC_LEVEL;
5594 priv->status |= STATUS_SECURITY_UPDATED;
5595 }
5596
5597 IPW_DEBUG_WEP("Security flags: %c %c%c%c%c %c%c%c%c\n",
5598 priv->ieee->sec.flags & (1 << 8) ? '1' : '0',
5599 priv->ieee->sec.flags & (1 << 7) ? '1' : '0',
5600 priv->ieee->sec.flags & (1 << 6) ? '1' : '0',
5601 priv->ieee->sec.flags & (1 << 5) ? '1' : '0',
5602 priv->ieee->sec.flags & (1 << 4) ? '1' : '0',
5603 priv->ieee->sec.flags & (1 << 3) ? '1' : '0',
5604 priv->ieee->sec.flags & (1 << 2) ? '1' : '0',
5605 priv->ieee->sec.flags & (1 << 1) ? '1' : '0',
5606 priv->ieee->sec.flags & (1 << 0) ? '1' : '0');
5607
5608 /* As a temporary work around to enable WPA until we figure out why
5609 * wpa_supplicant toggles the security capability of the driver, which
5610 * forces a disassociation with force_update...
5611 *
5612 * if (force_update || !(priv->status & STATUS_ASSOCIATED))*/
5613 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
5614 ipw2100_configure_security(priv, 0);
5615 done:
5616 mutex_unlock(&priv->action_mutex);
5617 }
5618
ipw2100_adapter_setup(struct ipw2100_priv * priv)5619 static int ipw2100_adapter_setup(struct ipw2100_priv *priv)
5620 {
5621 int err;
5622 int batch_mode = 1;
5623 u8 *bssid;
5624
5625 IPW_DEBUG_INFO("enter\n");
5626
5627 err = ipw2100_disable_adapter(priv);
5628 if (err)
5629 return err;
5630 #ifdef CONFIG_IPW2100_MONITOR
5631 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
5632 err = ipw2100_set_channel(priv, priv->channel, batch_mode);
5633 if (err)
5634 return err;
5635
5636 IPW_DEBUG_INFO("exit\n");
5637
5638 return 0;
5639 }
5640 #endif /* CONFIG_IPW2100_MONITOR */
5641
5642 err = ipw2100_read_mac_address(priv);
5643 if (err)
5644 return -EIO;
5645
5646 err = ipw2100_set_mac_address(priv, batch_mode);
5647 if (err)
5648 return err;
5649
5650 err = ipw2100_set_port_type(priv, priv->ieee->iw_mode, batch_mode);
5651 if (err)
5652 return err;
5653
5654 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
5655 err = ipw2100_set_channel(priv, priv->channel, batch_mode);
5656 if (err)
5657 return err;
5658 }
5659
5660 err = ipw2100_system_config(priv, batch_mode);
5661 if (err)
5662 return err;
5663
5664 err = ipw2100_set_tx_rates(priv, priv->tx_rates, batch_mode);
5665 if (err)
5666 return err;
5667
5668 /* Default to power mode OFF */
5669 err = ipw2100_set_power_mode(priv, IPW_POWER_MODE_CAM);
5670 if (err)
5671 return err;
5672
5673 err = ipw2100_set_rts_threshold(priv, priv->rts_threshold);
5674 if (err)
5675 return err;
5676
5677 if (priv->config & CFG_STATIC_BSSID)
5678 bssid = priv->bssid;
5679 else
5680 bssid = NULL;
5681 err = ipw2100_set_mandatory_bssid(priv, bssid, batch_mode);
5682 if (err)
5683 return err;
5684
5685 if (priv->config & CFG_STATIC_ESSID)
5686 err = ipw2100_set_essid(priv, priv->essid, priv->essid_len,
5687 batch_mode);
5688 else
5689 err = ipw2100_set_essid(priv, NULL, 0, batch_mode);
5690 if (err)
5691 return err;
5692
5693 err = ipw2100_configure_security(priv, batch_mode);
5694 if (err)
5695 return err;
5696
5697 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
5698 err =
5699 ipw2100_set_ibss_beacon_interval(priv,
5700 priv->beacon_interval,
5701 batch_mode);
5702 if (err)
5703 return err;
5704
5705 err = ipw2100_set_tx_power(priv, priv->tx_power);
5706 if (err)
5707 return err;
5708 }
5709
5710 /*
5711 err = ipw2100_set_fragmentation_threshold(
5712 priv, priv->frag_threshold, batch_mode);
5713 if (err)
5714 return err;
5715 */
5716
5717 IPW_DEBUG_INFO("exit\n");
5718
5719 return 0;
5720 }
5721
5722 /*************************************************************************
5723 *
5724 * EXTERNALLY CALLED METHODS
5725 *
5726 *************************************************************************/
5727
5728 /* This method is called by the network layer -- not to be confused with
5729 * ipw2100_set_mac_address() declared above called by this driver (and this
5730 * method as well) to talk to the firmware */
ipw2100_set_address(struct net_device * dev,void * p)5731 static int ipw2100_set_address(struct net_device *dev, void *p)
5732 {
5733 struct ipw2100_priv *priv = libipw_priv(dev);
5734 struct sockaddr *addr = p;
5735 int err = 0;
5736
5737 if (!is_valid_ether_addr(addr->sa_data))
5738 return -EADDRNOTAVAIL;
5739
5740 mutex_lock(&priv->action_mutex);
5741
5742 priv->config |= CFG_CUSTOM_MAC;
5743 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
5744
5745 err = ipw2100_set_mac_address(priv, 0);
5746 if (err)
5747 goto done;
5748
5749 priv->reset_backoff = 0;
5750 mutex_unlock(&priv->action_mutex);
5751 ipw2100_reset_adapter(&priv->reset_work.work);
5752 return 0;
5753
5754 done:
5755 mutex_unlock(&priv->action_mutex);
5756 return err;
5757 }
5758
ipw2100_open(struct net_device * dev)5759 static int ipw2100_open(struct net_device *dev)
5760 {
5761 struct ipw2100_priv *priv = libipw_priv(dev);
5762 unsigned long flags;
5763 IPW_DEBUG_INFO("dev->open\n");
5764
5765 spin_lock_irqsave(&priv->low_lock, flags);
5766 if (priv->status & STATUS_ASSOCIATED) {
5767 netif_carrier_on(dev);
5768 netif_start_queue(dev);
5769 }
5770 spin_unlock_irqrestore(&priv->low_lock, flags);
5771
5772 return 0;
5773 }
5774
ipw2100_close(struct net_device * dev)5775 static int ipw2100_close(struct net_device *dev)
5776 {
5777 struct ipw2100_priv *priv = libipw_priv(dev);
5778 unsigned long flags;
5779 struct list_head *element;
5780 struct ipw2100_tx_packet *packet;
5781
5782 IPW_DEBUG_INFO("enter\n");
5783
5784 spin_lock_irqsave(&priv->low_lock, flags);
5785
5786 if (priv->status & STATUS_ASSOCIATED)
5787 netif_carrier_off(dev);
5788 netif_stop_queue(dev);
5789
5790 /* Flush the TX queue ... */
5791 while (!list_empty(&priv->tx_pend_list)) {
5792 element = priv->tx_pend_list.next;
5793 packet = list_entry(element, struct ipw2100_tx_packet, list);
5794
5795 list_del(element);
5796 DEC_STAT(&priv->tx_pend_stat);
5797
5798 libipw_txb_free(packet->info.d_struct.txb);
5799 packet->info.d_struct.txb = NULL;
5800
5801 list_add_tail(element, &priv->tx_free_list);
5802 INC_STAT(&priv->tx_free_stat);
5803 }
5804 spin_unlock_irqrestore(&priv->low_lock, flags);
5805
5806 IPW_DEBUG_INFO("exit\n");
5807
5808 return 0;
5809 }
5810
5811 /*
5812 * TODO: Fix this function... its just wrong
5813 */
ipw2100_tx_timeout(struct net_device * dev,unsigned int txqueue)5814 static void ipw2100_tx_timeout(struct net_device *dev, unsigned int txqueue)
5815 {
5816 struct ipw2100_priv *priv = libipw_priv(dev);
5817
5818 dev->stats.tx_errors++;
5819
5820 #ifdef CONFIG_IPW2100_MONITOR
5821 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
5822 return;
5823 #endif
5824
5825 IPW_DEBUG_INFO("%s: TX timed out. Scheduling firmware restart.\n",
5826 dev->name);
5827 schedule_reset(priv);
5828 }
5829
ipw2100_wpa_enable(struct ipw2100_priv * priv,int value)5830 static int ipw2100_wpa_enable(struct ipw2100_priv *priv, int value)
5831 {
5832 /* This is called when wpa_supplicant loads and closes the driver
5833 * interface. */
5834 priv->ieee->wpa_enabled = value;
5835 return 0;
5836 }
5837
ipw2100_wpa_set_auth_algs(struct ipw2100_priv * priv,int value)5838 static int ipw2100_wpa_set_auth_algs(struct ipw2100_priv *priv, int value)
5839 {
5840
5841 struct libipw_device *ieee = priv->ieee;
5842 struct libipw_security sec = {
5843 .flags = SEC_AUTH_MODE,
5844 };
5845 int ret = 0;
5846
5847 if (value & IW_AUTH_ALG_SHARED_KEY) {
5848 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
5849 ieee->open_wep = 0;
5850 } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
5851 sec.auth_mode = WLAN_AUTH_OPEN;
5852 ieee->open_wep = 1;
5853 } else if (value & IW_AUTH_ALG_LEAP) {
5854 sec.auth_mode = WLAN_AUTH_LEAP;
5855 ieee->open_wep = 1;
5856 } else
5857 return -EINVAL;
5858
5859 if (ieee->set_security)
5860 ieee->set_security(ieee->dev, &sec);
5861 else
5862 ret = -EOPNOTSUPP;
5863
5864 return ret;
5865 }
5866
ipw2100_wpa_assoc_frame(struct ipw2100_priv * priv,char * wpa_ie,int wpa_ie_len)5867 static void ipw2100_wpa_assoc_frame(struct ipw2100_priv *priv,
5868 char *wpa_ie, int wpa_ie_len)
5869 {
5870
5871 struct ipw2100_wpa_assoc_frame frame;
5872
5873 frame.fixed_ie_mask = 0;
5874
5875 /* copy WPA IE */
5876 memcpy(frame.var_ie, wpa_ie, wpa_ie_len);
5877 frame.var_ie_len = wpa_ie_len;
5878
5879 /* make sure WPA is enabled */
5880 ipw2100_wpa_enable(priv, 1);
5881 ipw2100_set_wpa_ie(priv, &frame, 0);
5882 }
5883
ipw_ethtool_get_drvinfo(struct net_device * dev,struct ethtool_drvinfo * info)5884 static void ipw_ethtool_get_drvinfo(struct net_device *dev,
5885 struct ethtool_drvinfo *info)
5886 {
5887 struct ipw2100_priv *priv = libipw_priv(dev);
5888 char fw_ver[64];
5889
5890 strscpy(info->driver, DRV_NAME, sizeof(info->driver));
5891 strscpy(info->version, DRV_VERSION, sizeof(info->version));
5892
5893 ipw2100_get_fwversion(priv, fw_ver, sizeof(fw_ver));
5894
5895 strscpy(info->fw_version, fw_ver, sizeof(info->fw_version));
5896 strscpy(info->bus_info, pci_name(priv->pci_dev),
5897 sizeof(info->bus_info));
5898 }
5899
ipw2100_ethtool_get_link(struct net_device * dev)5900 static u32 ipw2100_ethtool_get_link(struct net_device *dev)
5901 {
5902 struct ipw2100_priv *priv = libipw_priv(dev);
5903 return (priv->status & STATUS_ASSOCIATED) ? 1 : 0;
5904 }
5905
5906 static const struct ethtool_ops ipw2100_ethtool_ops = {
5907 .get_link = ipw2100_ethtool_get_link,
5908 .get_drvinfo = ipw_ethtool_get_drvinfo,
5909 };
5910
ipw2100_hang_check(struct work_struct * work)5911 static void ipw2100_hang_check(struct work_struct *work)
5912 {
5913 struct ipw2100_priv *priv =
5914 container_of(work, struct ipw2100_priv, hang_check.work);
5915 unsigned long flags;
5916 u32 rtc = 0xa5a5a5a5;
5917 u32 len = sizeof(rtc);
5918 int restart = 0;
5919
5920 spin_lock_irqsave(&priv->low_lock, flags);
5921
5922 if (priv->fatal_error != 0) {
5923 /* If fatal_error is set then we need to restart */
5924 IPW_DEBUG_INFO("%s: Hardware fatal error detected.\n",
5925 priv->net_dev->name);
5926
5927 restart = 1;
5928 } else if (ipw2100_get_ordinal(priv, IPW_ORD_RTC_TIME, &rtc, &len) ||
5929 (rtc == priv->last_rtc)) {
5930 /* Check if firmware is hung */
5931 IPW_DEBUG_INFO("%s: Firmware RTC stalled.\n",
5932 priv->net_dev->name);
5933
5934 restart = 1;
5935 }
5936
5937 if (restart) {
5938 /* Kill timer */
5939 priv->stop_hang_check = 1;
5940 priv->hangs++;
5941
5942 /* Restart the NIC */
5943 schedule_reset(priv);
5944 }
5945
5946 priv->last_rtc = rtc;
5947
5948 if (!priv->stop_hang_check)
5949 schedule_delayed_work(&priv->hang_check, HZ / 2);
5950
5951 spin_unlock_irqrestore(&priv->low_lock, flags);
5952 }
5953
ipw2100_rf_kill(struct work_struct * work)5954 static void ipw2100_rf_kill(struct work_struct *work)
5955 {
5956 struct ipw2100_priv *priv =
5957 container_of(work, struct ipw2100_priv, rf_kill.work);
5958 unsigned long flags;
5959
5960 spin_lock_irqsave(&priv->low_lock, flags);
5961
5962 if (rf_kill_active(priv)) {
5963 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
5964 if (!priv->stop_rf_kill)
5965 schedule_delayed_work(&priv->rf_kill,
5966 round_jiffies_relative(HZ));
5967 goto exit_unlock;
5968 }
5969
5970 /* RF Kill is now disabled, so bring the device back up */
5971
5972 if (!(priv->status & STATUS_RF_KILL_MASK)) {
5973 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
5974 "device\n");
5975 schedule_reset(priv);
5976 } else
5977 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
5978 "enabled\n");
5979
5980 exit_unlock:
5981 spin_unlock_irqrestore(&priv->low_lock, flags);
5982 }
5983
5984 static void ipw2100_irq_tasklet(struct tasklet_struct *t);
5985
5986 static const struct net_device_ops ipw2100_netdev_ops = {
5987 .ndo_open = ipw2100_open,
5988 .ndo_stop = ipw2100_close,
5989 .ndo_start_xmit = libipw_xmit,
5990 .ndo_tx_timeout = ipw2100_tx_timeout,
5991 .ndo_set_mac_address = ipw2100_set_address,
5992 .ndo_validate_addr = eth_validate_addr,
5993 };
5994
5995 /* Look into using netdev destructor to shutdown libipw? */
5996
ipw2100_alloc_device(struct pci_dev * pci_dev,void __iomem * ioaddr)5997 static struct net_device *ipw2100_alloc_device(struct pci_dev *pci_dev,
5998 void __iomem * ioaddr)
5999 {
6000 struct ipw2100_priv *priv;
6001 struct net_device *dev;
6002
6003 dev = alloc_libipw(sizeof(struct ipw2100_priv), 0);
6004 if (!dev)
6005 return NULL;
6006 priv = libipw_priv(dev);
6007 priv->ieee = netdev_priv(dev);
6008 priv->pci_dev = pci_dev;
6009 priv->net_dev = dev;
6010 priv->ioaddr = ioaddr;
6011
6012 priv->ieee->hard_start_xmit = ipw2100_tx;
6013 priv->ieee->set_security = shim__set_security;
6014
6015 priv->ieee->perfect_rssi = -20;
6016 priv->ieee->worst_rssi = -85;
6017
6018 dev->netdev_ops = &ipw2100_netdev_ops;
6019 dev->ethtool_ops = &ipw2100_ethtool_ops;
6020 dev->wireless_handlers = &ipw2100_wx_handler_def;
6021 dev->watchdog_timeo = 3 * HZ;
6022 dev->irq = 0;
6023 dev->min_mtu = 68;
6024 dev->max_mtu = LIBIPW_DATA_LEN;
6025
6026 /* NOTE: We don't use the wireless_handlers hook
6027 * in dev as the system will start throwing WX requests
6028 * to us before we're actually initialized and it just
6029 * ends up causing problems. So, we just handle
6030 * the WX extensions through the ipw2100_ioctl interface */
6031
6032 /* memset() puts everything to 0, so we only have explicitly set
6033 * those values that need to be something else */
6034
6035 /* If power management is turned on, default to AUTO mode */
6036 priv->power_mode = IPW_POWER_AUTO;
6037
6038 #ifdef CONFIG_IPW2100_MONITOR
6039 priv->config |= CFG_CRC_CHECK;
6040 #endif
6041 priv->ieee->wpa_enabled = 0;
6042 priv->ieee->drop_unencrypted = 0;
6043 priv->ieee->privacy_invoked = 0;
6044 priv->ieee->ieee802_1x = 1;
6045
6046 /* Set module parameters */
6047 switch (network_mode) {
6048 case 1:
6049 priv->ieee->iw_mode = IW_MODE_ADHOC;
6050 break;
6051 #ifdef CONFIG_IPW2100_MONITOR
6052 case 2:
6053 priv->ieee->iw_mode = IW_MODE_MONITOR;
6054 break;
6055 #endif
6056 default:
6057 case 0:
6058 priv->ieee->iw_mode = IW_MODE_INFRA;
6059 break;
6060 }
6061
6062 if (disable == 1)
6063 priv->status |= STATUS_RF_KILL_SW;
6064
6065 if (channel != 0 &&
6066 ((channel >= REG_MIN_CHANNEL) && (channel <= REG_MAX_CHANNEL))) {
6067 priv->config |= CFG_STATIC_CHANNEL;
6068 priv->channel = channel;
6069 }
6070
6071 if (associate)
6072 priv->config |= CFG_ASSOCIATE;
6073
6074 priv->beacon_interval = DEFAULT_BEACON_INTERVAL;
6075 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
6076 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
6077 priv->rts_threshold = DEFAULT_RTS_THRESHOLD | RTS_DISABLED;
6078 priv->frag_threshold = DEFAULT_FTS | FRAG_DISABLED;
6079 priv->tx_power = IPW_TX_POWER_DEFAULT;
6080 priv->tx_rates = DEFAULT_TX_RATES;
6081
6082 strcpy(priv->nick, "ipw2100");
6083
6084 spin_lock_init(&priv->low_lock);
6085 mutex_init(&priv->action_mutex);
6086 mutex_init(&priv->adapter_mutex);
6087
6088 init_waitqueue_head(&priv->wait_command_queue);
6089
6090 netif_carrier_off(dev);
6091
6092 INIT_LIST_HEAD(&priv->msg_free_list);
6093 INIT_LIST_HEAD(&priv->msg_pend_list);
6094 INIT_STAT(&priv->msg_free_stat);
6095 INIT_STAT(&priv->msg_pend_stat);
6096
6097 INIT_LIST_HEAD(&priv->tx_free_list);
6098 INIT_LIST_HEAD(&priv->tx_pend_list);
6099 INIT_STAT(&priv->tx_free_stat);
6100 INIT_STAT(&priv->tx_pend_stat);
6101
6102 INIT_LIST_HEAD(&priv->fw_pend_list);
6103 INIT_STAT(&priv->fw_pend_stat);
6104
6105 INIT_DELAYED_WORK(&priv->reset_work, ipw2100_reset_adapter);
6106 INIT_DELAYED_WORK(&priv->security_work, ipw2100_security_work);
6107 INIT_DELAYED_WORK(&priv->wx_event_work, ipw2100_wx_event_work);
6108 INIT_DELAYED_WORK(&priv->hang_check, ipw2100_hang_check);
6109 INIT_DELAYED_WORK(&priv->rf_kill, ipw2100_rf_kill);
6110 INIT_DELAYED_WORK(&priv->scan_event, ipw2100_scan_event);
6111
6112 tasklet_setup(&priv->irq_tasklet, ipw2100_irq_tasklet);
6113
6114 /* NOTE: We do not start the deferred work for status checks yet */
6115 priv->stop_rf_kill = 1;
6116 priv->stop_hang_check = 1;
6117
6118 return dev;
6119 }
6120
ipw2100_pci_init_one(struct pci_dev * pci_dev,const struct pci_device_id * ent)6121 static int ipw2100_pci_init_one(struct pci_dev *pci_dev,
6122 const struct pci_device_id *ent)
6123 {
6124 void __iomem *ioaddr;
6125 struct net_device *dev = NULL;
6126 struct ipw2100_priv *priv = NULL;
6127 int err = 0;
6128 int registered = 0;
6129 u32 val;
6130
6131 IPW_DEBUG_INFO("enter\n");
6132
6133 if (!(pci_resource_flags(pci_dev, 0) & IORESOURCE_MEM)) {
6134 IPW_DEBUG_INFO("weird - resource type is not memory\n");
6135 err = -ENODEV;
6136 goto out;
6137 }
6138
6139 ioaddr = pci_iomap(pci_dev, 0, 0);
6140 if (!ioaddr) {
6141 printk(KERN_WARNING DRV_NAME
6142 "Error calling ioremap.\n");
6143 err = -EIO;
6144 goto fail;
6145 }
6146
6147 /* allocate and initialize our net_device */
6148 dev = ipw2100_alloc_device(pci_dev, ioaddr);
6149 if (!dev) {
6150 printk(KERN_WARNING DRV_NAME
6151 "Error calling ipw2100_alloc_device.\n");
6152 err = -ENOMEM;
6153 goto fail;
6154 }
6155
6156 /* set up PCI mappings for device */
6157 err = pci_enable_device(pci_dev);
6158 if (err) {
6159 printk(KERN_WARNING DRV_NAME
6160 "Error calling pci_enable_device.\n");
6161 return err;
6162 }
6163
6164 priv = libipw_priv(dev);
6165
6166 pci_set_master(pci_dev);
6167 pci_set_drvdata(pci_dev, priv);
6168
6169 err = dma_set_mask(&pci_dev->dev, DMA_BIT_MASK(32));
6170 if (err) {
6171 printk(KERN_WARNING DRV_NAME
6172 "Error calling pci_set_dma_mask.\n");
6173 pci_disable_device(pci_dev);
6174 return err;
6175 }
6176
6177 err = pci_request_regions(pci_dev, DRV_NAME);
6178 if (err) {
6179 printk(KERN_WARNING DRV_NAME
6180 "Error calling pci_request_regions.\n");
6181 pci_disable_device(pci_dev);
6182 return err;
6183 }
6184
6185 /* We disable the RETRY_TIMEOUT register (0x41) to keep
6186 * PCI Tx retries from interfering with C3 CPU state */
6187 pci_read_config_dword(pci_dev, 0x40, &val);
6188 if ((val & 0x0000ff00) != 0)
6189 pci_write_config_dword(pci_dev, 0x40, val & 0xffff00ff);
6190
6191 if (!ipw2100_hw_is_adapter_in_system(dev)) {
6192 printk(KERN_WARNING DRV_NAME
6193 "Device not found via register read.\n");
6194 err = -ENODEV;
6195 goto fail;
6196 }
6197
6198 SET_NETDEV_DEV(dev, &pci_dev->dev);
6199
6200 /* Force interrupts to be shut off on the device */
6201 priv->status |= STATUS_INT_ENABLED;
6202 ipw2100_disable_interrupts(priv);
6203
6204 /* Allocate and initialize the Tx/Rx queues and lists */
6205 if (ipw2100_queues_allocate(priv)) {
6206 printk(KERN_WARNING DRV_NAME
6207 "Error calling ipw2100_queues_allocate.\n");
6208 err = -ENOMEM;
6209 goto fail;
6210 }
6211 ipw2100_queues_initialize(priv);
6212
6213 err = request_irq(pci_dev->irq,
6214 ipw2100_interrupt, IRQF_SHARED, dev->name, priv);
6215 if (err) {
6216 printk(KERN_WARNING DRV_NAME
6217 "Error calling request_irq: %d.\n", pci_dev->irq);
6218 goto fail;
6219 }
6220 dev->irq = pci_dev->irq;
6221
6222 IPW_DEBUG_INFO("Attempting to register device...\n");
6223
6224 printk(KERN_INFO DRV_NAME
6225 ": Detected Intel PRO/Wireless 2100 Network Connection\n");
6226
6227 err = ipw2100_up(priv, 1);
6228 if (err)
6229 goto fail;
6230
6231 err = ipw2100_wdev_init(dev);
6232 if (err)
6233 goto fail;
6234 registered = 1;
6235
6236 /* Bring up the interface. Pre 0.46, after we registered the
6237 * network device we would call ipw2100_up. This introduced a race
6238 * condition with newer hotplug configurations (network was coming
6239 * up and making calls before the device was initialized).
6240 */
6241 err = register_netdev(dev);
6242 if (err) {
6243 printk(KERN_WARNING DRV_NAME
6244 "Error calling register_netdev.\n");
6245 goto fail;
6246 }
6247 registered = 2;
6248
6249 mutex_lock(&priv->action_mutex);
6250
6251 IPW_DEBUG_INFO("%s: Bound to %s\n", dev->name, pci_name(pci_dev));
6252
6253 /* perform this after register_netdev so that dev->name is set */
6254 err = sysfs_create_group(&pci_dev->dev.kobj, &ipw2100_attribute_group);
6255 if (err)
6256 goto fail_unlock;
6257
6258 /* If the RF Kill switch is disabled, go ahead and complete the
6259 * startup sequence */
6260 if (!(priv->status & STATUS_RF_KILL_MASK)) {
6261 /* Enable the adapter - sends HOST_COMPLETE */
6262 if (ipw2100_enable_adapter(priv)) {
6263 printk(KERN_WARNING DRV_NAME
6264 ": %s: failed in call to enable adapter.\n",
6265 priv->net_dev->name);
6266 ipw2100_hw_stop_adapter(priv);
6267 err = -EIO;
6268 goto fail_unlock;
6269 }
6270
6271 /* Start a scan . . . */
6272 ipw2100_set_scan_options(priv);
6273 ipw2100_start_scan(priv);
6274 }
6275
6276 IPW_DEBUG_INFO("exit\n");
6277
6278 priv->status |= STATUS_INITIALIZED;
6279
6280 mutex_unlock(&priv->action_mutex);
6281 out:
6282 return err;
6283
6284 fail_unlock:
6285 mutex_unlock(&priv->action_mutex);
6286 fail:
6287 if (dev) {
6288 if (registered >= 2)
6289 unregister_netdev(dev);
6290
6291 if (registered) {
6292 wiphy_unregister(priv->ieee->wdev.wiphy);
6293 kfree(priv->ieee->bg_band.channels);
6294 }
6295
6296 ipw2100_hw_stop_adapter(priv);
6297
6298 ipw2100_disable_interrupts(priv);
6299
6300 if (dev->irq)
6301 free_irq(dev->irq, priv);
6302
6303 ipw2100_kill_works(priv);
6304
6305 /* These are safe to call even if they weren't allocated */
6306 ipw2100_queues_free(priv);
6307 sysfs_remove_group(&pci_dev->dev.kobj,
6308 &ipw2100_attribute_group);
6309
6310 free_libipw(dev, 0);
6311 }
6312
6313 pci_iounmap(pci_dev, ioaddr);
6314
6315 pci_release_regions(pci_dev);
6316 pci_disable_device(pci_dev);
6317 goto out;
6318 }
6319
ipw2100_pci_remove_one(struct pci_dev * pci_dev)6320 static void ipw2100_pci_remove_one(struct pci_dev *pci_dev)
6321 {
6322 struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
6323 struct net_device *dev = priv->net_dev;
6324
6325 mutex_lock(&priv->action_mutex);
6326
6327 priv->status &= ~STATUS_INITIALIZED;
6328
6329 sysfs_remove_group(&pci_dev->dev.kobj, &ipw2100_attribute_group);
6330
6331 #ifdef CONFIG_PM
6332 if (ipw2100_firmware.version)
6333 ipw2100_release_firmware(priv, &ipw2100_firmware);
6334 #endif
6335 /* Take down the hardware */
6336 ipw2100_down(priv);
6337
6338 /* Release the mutex so that the network subsystem can
6339 * complete any needed calls into the driver... */
6340 mutex_unlock(&priv->action_mutex);
6341
6342 /* Unregister the device first - this results in close()
6343 * being called if the device is open. If we free storage
6344 * first, then close() will crash.
6345 * FIXME: remove the comment above. */
6346 unregister_netdev(dev);
6347
6348 ipw2100_kill_works(priv);
6349
6350 ipw2100_queues_free(priv);
6351
6352 /* Free potential debugging firmware snapshot */
6353 ipw2100_snapshot_free(priv);
6354
6355 free_irq(dev->irq, priv);
6356
6357 pci_iounmap(pci_dev, priv->ioaddr);
6358
6359 /* wiphy_unregister needs to be here, before free_libipw */
6360 wiphy_unregister(priv->ieee->wdev.wiphy);
6361 kfree(priv->ieee->bg_band.channels);
6362 free_libipw(dev, 0);
6363
6364 pci_release_regions(pci_dev);
6365 pci_disable_device(pci_dev);
6366
6367 IPW_DEBUG_INFO("exit\n");
6368 }
6369
ipw2100_suspend(struct device * dev_d)6370 static int __maybe_unused ipw2100_suspend(struct device *dev_d)
6371 {
6372 struct ipw2100_priv *priv = dev_get_drvdata(dev_d);
6373 struct net_device *dev = priv->net_dev;
6374
6375 IPW_DEBUG_INFO("%s: Going into suspend...\n", dev->name);
6376
6377 mutex_lock(&priv->action_mutex);
6378 if (priv->status & STATUS_INITIALIZED) {
6379 /* Take down the device; powers it off, etc. */
6380 ipw2100_down(priv);
6381 }
6382
6383 /* Remove the PRESENT state of the device */
6384 netif_device_detach(dev);
6385
6386 priv->suspend_at = ktime_get_boottime_seconds();
6387
6388 mutex_unlock(&priv->action_mutex);
6389
6390 return 0;
6391 }
6392
ipw2100_resume(struct device * dev_d)6393 static int __maybe_unused ipw2100_resume(struct device *dev_d)
6394 {
6395 struct pci_dev *pci_dev = to_pci_dev(dev_d);
6396 struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
6397 struct net_device *dev = priv->net_dev;
6398 u32 val;
6399
6400 if (IPW2100_PM_DISABLED)
6401 return 0;
6402
6403 mutex_lock(&priv->action_mutex);
6404
6405 IPW_DEBUG_INFO("%s: Coming out of suspend...\n", dev->name);
6406
6407 /*
6408 * Suspend/Resume resets the PCI configuration space, so we have to
6409 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
6410 * from interfering with C3 CPU state. pci_restore_state won't help
6411 * here since it only restores the first 64 bytes pci config header.
6412 */
6413 pci_read_config_dword(pci_dev, 0x40, &val);
6414 if ((val & 0x0000ff00) != 0)
6415 pci_write_config_dword(pci_dev, 0x40, val & 0xffff00ff);
6416
6417 /* Set the device back into the PRESENT state; this will also wake
6418 * the queue of needed */
6419 netif_device_attach(dev);
6420
6421 priv->suspend_time = ktime_get_boottime_seconds() - priv->suspend_at;
6422
6423 /* Bring the device back up */
6424 if (!(priv->status & STATUS_RF_KILL_SW))
6425 ipw2100_up(priv, 0);
6426
6427 mutex_unlock(&priv->action_mutex);
6428
6429 return 0;
6430 }
6431
ipw2100_shutdown(struct pci_dev * pci_dev)6432 static void ipw2100_shutdown(struct pci_dev *pci_dev)
6433 {
6434 struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
6435
6436 /* Take down the device; powers it off, etc. */
6437 ipw2100_down(priv);
6438
6439 pci_disable_device(pci_dev);
6440 }
6441
6442 #define IPW2100_DEV_ID(x) { PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, x }
6443
6444 static const struct pci_device_id ipw2100_pci_id_table[] = {
6445 IPW2100_DEV_ID(0x2520), /* IN 2100A mPCI 3A */
6446 IPW2100_DEV_ID(0x2521), /* IN 2100A mPCI 3B */
6447 IPW2100_DEV_ID(0x2524), /* IN 2100A mPCI 3B */
6448 IPW2100_DEV_ID(0x2525), /* IN 2100A mPCI 3B */
6449 IPW2100_DEV_ID(0x2526), /* IN 2100A mPCI Gen A3 */
6450 IPW2100_DEV_ID(0x2522), /* IN 2100 mPCI 3B */
6451 IPW2100_DEV_ID(0x2523), /* IN 2100 mPCI 3A */
6452 IPW2100_DEV_ID(0x2527), /* IN 2100 mPCI 3B */
6453 IPW2100_DEV_ID(0x2528), /* IN 2100 mPCI 3B */
6454 IPW2100_DEV_ID(0x2529), /* IN 2100 mPCI 3B */
6455 IPW2100_DEV_ID(0x252B), /* IN 2100 mPCI 3A */
6456 IPW2100_DEV_ID(0x252C), /* IN 2100 mPCI 3A */
6457 IPW2100_DEV_ID(0x252D), /* IN 2100 mPCI 3A */
6458
6459 IPW2100_DEV_ID(0x2550), /* IB 2100A mPCI 3B */
6460 IPW2100_DEV_ID(0x2551), /* IB 2100 mPCI 3B */
6461 IPW2100_DEV_ID(0x2553), /* IB 2100 mPCI 3B */
6462 IPW2100_DEV_ID(0x2554), /* IB 2100 mPCI 3B */
6463 IPW2100_DEV_ID(0x2555), /* IB 2100 mPCI 3B */
6464
6465 IPW2100_DEV_ID(0x2560), /* DE 2100A mPCI 3A */
6466 IPW2100_DEV_ID(0x2562), /* DE 2100A mPCI 3A */
6467 IPW2100_DEV_ID(0x2563), /* DE 2100A mPCI 3A */
6468 IPW2100_DEV_ID(0x2561), /* DE 2100 mPCI 3A */
6469 IPW2100_DEV_ID(0x2565), /* DE 2100 mPCI 3A */
6470 IPW2100_DEV_ID(0x2566), /* DE 2100 mPCI 3A */
6471 IPW2100_DEV_ID(0x2567), /* DE 2100 mPCI 3A */
6472
6473 IPW2100_DEV_ID(0x2570), /* GA 2100 mPCI 3B */
6474
6475 IPW2100_DEV_ID(0x2580), /* TO 2100A mPCI 3B */
6476 IPW2100_DEV_ID(0x2582), /* TO 2100A mPCI 3B */
6477 IPW2100_DEV_ID(0x2583), /* TO 2100A mPCI 3B */
6478 IPW2100_DEV_ID(0x2581), /* TO 2100 mPCI 3B */
6479 IPW2100_DEV_ID(0x2585), /* TO 2100 mPCI 3B */
6480 IPW2100_DEV_ID(0x2586), /* TO 2100 mPCI 3B */
6481 IPW2100_DEV_ID(0x2587), /* TO 2100 mPCI 3B */
6482
6483 IPW2100_DEV_ID(0x2590), /* SO 2100A mPCI 3B */
6484 IPW2100_DEV_ID(0x2592), /* SO 2100A mPCI 3B */
6485 IPW2100_DEV_ID(0x2591), /* SO 2100 mPCI 3B */
6486 IPW2100_DEV_ID(0x2593), /* SO 2100 mPCI 3B */
6487 IPW2100_DEV_ID(0x2596), /* SO 2100 mPCI 3B */
6488 IPW2100_DEV_ID(0x2598), /* SO 2100 mPCI 3B */
6489
6490 IPW2100_DEV_ID(0x25A0), /* HP 2100 mPCI 3B */
6491 {0,},
6492 };
6493
6494 MODULE_DEVICE_TABLE(pci, ipw2100_pci_id_table);
6495
6496 static SIMPLE_DEV_PM_OPS(ipw2100_pm_ops, ipw2100_suspend, ipw2100_resume);
6497
6498 static struct pci_driver ipw2100_pci_driver = {
6499 .name = DRV_NAME,
6500 .id_table = ipw2100_pci_id_table,
6501 .probe = ipw2100_pci_init_one,
6502 .remove = ipw2100_pci_remove_one,
6503 .driver.pm = &ipw2100_pm_ops,
6504 .shutdown = ipw2100_shutdown,
6505 };
6506
6507 /*
6508 * Initialize the ipw2100 driver/module
6509 *
6510 * @returns 0 if ok, < 0 errno node con error.
6511 *
6512 * Note: we cannot init the /proc stuff until the PCI driver is there,
6513 * or we risk an unlikely race condition on someone accessing
6514 * uninitialized data in the PCI dev struct through /proc.
6515 */
ipw2100_init(void)6516 static int __init ipw2100_init(void)
6517 {
6518 int ret;
6519
6520 printk(KERN_INFO DRV_NAME ": %s, %s\n", DRV_DESCRIPTION, DRV_VERSION);
6521 printk(KERN_INFO DRV_NAME ": %s\n", DRV_COPYRIGHT);
6522
6523 cpu_latency_qos_add_request(&ipw2100_pm_qos_req, PM_QOS_DEFAULT_VALUE);
6524
6525 ret = pci_register_driver(&ipw2100_pci_driver);
6526 if (ret)
6527 goto out;
6528
6529 #ifdef CONFIG_IPW2100_DEBUG
6530 ipw2100_debug_level = debug;
6531 ret = driver_create_file(&ipw2100_pci_driver.driver,
6532 &driver_attr_debug_level);
6533 #endif
6534
6535 out:
6536 return ret;
6537 }
6538
6539 /*
6540 * Cleanup ipw2100 driver registration
6541 */
ipw2100_exit(void)6542 static void __exit ipw2100_exit(void)
6543 {
6544 /* FIXME: IPG: check that we have no instances of the devices open */
6545 #ifdef CONFIG_IPW2100_DEBUG
6546 driver_remove_file(&ipw2100_pci_driver.driver,
6547 &driver_attr_debug_level);
6548 #endif
6549 pci_unregister_driver(&ipw2100_pci_driver);
6550 cpu_latency_qos_remove_request(&ipw2100_pm_qos_req);
6551 }
6552
6553 module_init(ipw2100_init);
6554 module_exit(ipw2100_exit);
6555
ipw2100_wx_get_name(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)6556 static int ipw2100_wx_get_name(struct net_device *dev,
6557 struct iw_request_info *info,
6558 union iwreq_data *wrqu, char *extra)
6559 {
6560 /*
6561 * This can be called at any time. No action lock required
6562 */
6563
6564 struct ipw2100_priv *priv = libipw_priv(dev);
6565 if (!(priv->status & STATUS_ASSOCIATED))
6566 strcpy(wrqu->name, "unassociated");
6567 else
6568 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11b");
6569
6570 IPW_DEBUG_WX("Name: %s\n", wrqu->name);
6571 return 0;
6572 }
6573
ipw2100_wx_set_freq(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)6574 static int ipw2100_wx_set_freq(struct net_device *dev,
6575 struct iw_request_info *info,
6576 union iwreq_data *wrqu, char *extra)
6577 {
6578 struct ipw2100_priv *priv = libipw_priv(dev);
6579 struct iw_freq *fwrq = &wrqu->freq;
6580 int err = 0;
6581
6582 if (priv->ieee->iw_mode == IW_MODE_INFRA)
6583 return -EOPNOTSUPP;
6584
6585 mutex_lock(&priv->action_mutex);
6586 if (!(priv->status & STATUS_INITIALIZED)) {
6587 err = -EIO;
6588 goto done;
6589 }
6590
6591 /* if setting by freq convert to channel */
6592 if (fwrq->e == 1) {
6593 if ((fwrq->m >= (int)2.412e8 && fwrq->m <= (int)2.487e8)) {
6594 int f = fwrq->m / 100000;
6595 int c = 0;
6596
6597 while ((c < REG_MAX_CHANNEL) &&
6598 (f != ipw2100_frequencies[c]))
6599 c++;
6600
6601 /* hack to fall through */
6602 fwrq->e = 0;
6603 fwrq->m = c + 1;
6604 }
6605 }
6606
6607 if (fwrq->e > 0 || fwrq->m > 1000) {
6608 err = -EOPNOTSUPP;
6609 goto done;
6610 } else { /* Set the channel */
6611 IPW_DEBUG_WX("SET Freq/Channel -> %d\n", fwrq->m);
6612 err = ipw2100_set_channel(priv, fwrq->m, 0);
6613 }
6614
6615 done:
6616 mutex_unlock(&priv->action_mutex);
6617 return err;
6618 }
6619
ipw2100_wx_get_freq(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)6620 static int ipw2100_wx_get_freq(struct net_device *dev,
6621 struct iw_request_info *info,
6622 union iwreq_data *wrqu, char *extra)
6623 {
6624 /*
6625 * This can be called at any time. No action lock required
6626 */
6627
6628 struct ipw2100_priv *priv = libipw_priv(dev);
6629
6630 wrqu->freq.e = 0;
6631
6632 /* If we are associated, trying to associate, or have a statically
6633 * configured CHANNEL then return that; otherwise return ANY */
6634 if (priv->config & CFG_STATIC_CHANNEL ||
6635 priv->status & STATUS_ASSOCIATED)
6636 wrqu->freq.m = priv->channel;
6637 else
6638 wrqu->freq.m = 0;
6639
6640 IPW_DEBUG_WX("GET Freq/Channel -> %d\n", priv->channel);
6641 return 0;
6642
6643 }
6644
ipw2100_wx_set_mode(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)6645 static int ipw2100_wx_set_mode(struct net_device *dev,
6646 struct iw_request_info *info,
6647 union iwreq_data *wrqu, char *extra)
6648 {
6649 struct ipw2100_priv *priv = libipw_priv(dev);
6650 int err = 0;
6651
6652 IPW_DEBUG_WX("SET Mode -> %d\n", wrqu->mode);
6653
6654 if (wrqu->mode == priv->ieee->iw_mode)
6655 return 0;
6656
6657 mutex_lock(&priv->action_mutex);
6658 if (!(priv->status & STATUS_INITIALIZED)) {
6659 err = -EIO;
6660 goto done;
6661 }
6662
6663 switch (wrqu->mode) {
6664 #ifdef CONFIG_IPW2100_MONITOR
6665 case IW_MODE_MONITOR:
6666 err = ipw2100_switch_mode(priv, IW_MODE_MONITOR);
6667 break;
6668 #endif /* CONFIG_IPW2100_MONITOR */
6669 case IW_MODE_ADHOC:
6670 err = ipw2100_switch_mode(priv, IW_MODE_ADHOC);
6671 break;
6672 case IW_MODE_INFRA:
6673 case IW_MODE_AUTO:
6674 default:
6675 err = ipw2100_switch_mode(priv, IW_MODE_INFRA);
6676 break;
6677 }
6678
6679 done:
6680 mutex_unlock(&priv->action_mutex);
6681 return err;
6682 }
6683
ipw2100_wx_get_mode(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)6684 static int ipw2100_wx_get_mode(struct net_device *dev,
6685 struct iw_request_info *info,
6686 union iwreq_data *wrqu, char *extra)
6687 {
6688 /*
6689 * This can be called at any time. No action lock required
6690 */
6691
6692 struct ipw2100_priv *priv = libipw_priv(dev);
6693
6694 wrqu->mode = priv->ieee->iw_mode;
6695 IPW_DEBUG_WX("GET Mode -> %d\n", wrqu->mode);
6696
6697 return 0;
6698 }
6699
6700 #define POWER_MODES 5
6701
6702 /* Values are in microsecond */
6703 static const s32 timeout_duration[POWER_MODES] = {
6704 350000,
6705 250000,
6706 75000,
6707 37000,
6708 25000,
6709 };
6710
6711 static const s32 period_duration[POWER_MODES] = {
6712 400000,
6713 700000,
6714 1000000,
6715 1000000,
6716 1000000
6717 };
6718
ipw2100_wx_get_range(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)6719 static int ipw2100_wx_get_range(struct net_device *dev,
6720 struct iw_request_info *info,
6721 union iwreq_data *wrqu, char *extra)
6722 {
6723 /*
6724 * This can be called at any time. No action lock required
6725 */
6726
6727 struct ipw2100_priv *priv = libipw_priv(dev);
6728 struct iw_range *range = (struct iw_range *)extra;
6729 u16 val;
6730 int i, level;
6731
6732 wrqu->data.length = sizeof(*range);
6733 memset(range, 0, sizeof(*range));
6734
6735 /* Let's try to keep this struct in the same order as in
6736 * linux/include/wireless.h
6737 */
6738
6739 /* TODO: See what values we can set, and remove the ones we can't
6740 * set, or fill them with some default data.
6741 */
6742
6743 /* ~5 Mb/s real (802.11b) */
6744 range->throughput = 5 * 1000 * 1000;
6745
6746 // range->sensitivity; /* signal level threshold range */
6747
6748 range->max_qual.qual = 100;
6749 /* TODO: Find real max RSSI and stick here */
6750 range->max_qual.level = 0;
6751 range->max_qual.noise = 0;
6752 range->max_qual.updated = 7; /* Updated all three */
6753
6754 range->avg_qual.qual = 70; /* > 8% missed beacons is 'bad' */
6755 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
6756 range->avg_qual.level = 20 + IPW2100_RSSI_TO_DBM;
6757 range->avg_qual.noise = 0;
6758 range->avg_qual.updated = 7; /* Updated all three */
6759
6760 range->num_bitrates = RATE_COUNT;
6761
6762 for (i = 0; i < RATE_COUNT && i < IW_MAX_BITRATES; i++) {
6763 range->bitrate[i] = ipw2100_bg_rates[i].bitrate * 100 * 1000;
6764 }
6765
6766 range->min_rts = MIN_RTS_THRESHOLD;
6767 range->max_rts = MAX_RTS_THRESHOLD;
6768 range->min_frag = MIN_FRAG_THRESHOLD;
6769 range->max_frag = MAX_FRAG_THRESHOLD;
6770
6771 range->min_pmp = period_duration[0]; /* Minimal PM period */
6772 range->max_pmp = period_duration[POWER_MODES - 1]; /* Maximal PM period */
6773 range->min_pmt = timeout_duration[POWER_MODES - 1]; /* Minimal PM timeout */
6774 range->max_pmt = timeout_duration[0]; /* Maximal PM timeout */
6775
6776 /* How to decode max/min PM period */
6777 range->pmp_flags = IW_POWER_PERIOD;
6778 /* How to decode max/min PM period */
6779 range->pmt_flags = IW_POWER_TIMEOUT;
6780 /* What PM options are supported */
6781 range->pm_capa = IW_POWER_TIMEOUT | IW_POWER_PERIOD;
6782
6783 range->encoding_size[0] = 5;
6784 range->encoding_size[1] = 13; /* Different token sizes */
6785 range->num_encoding_sizes = 2; /* Number of entry in the list */
6786 range->max_encoding_tokens = WEP_KEYS; /* Max number of tokens */
6787 // range->encoding_login_index; /* token index for login token */
6788
6789 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
6790 range->txpower_capa = IW_TXPOW_DBM;
6791 range->num_txpower = IW_MAX_TXPOWER;
6792 for (i = 0, level = (IPW_TX_POWER_MAX_DBM * 16);
6793 i < IW_MAX_TXPOWER;
6794 i++, level -=
6795 ((IPW_TX_POWER_MAX_DBM -
6796 IPW_TX_POWER_MIN_DBM) * 16) / (IW_MAX_TXPOWER - 1))
6797 range->txpower[i] = level / 16;
6798 } else {
6799 range->txpower_capa = 0;
6800 range->num_txpower = 0;
6801 }
6802
6803 /* Set the Wireless Extension versions */
6804 range->we_version_compiled = WIRELESS_EXT;
6805 range->we_version_source = 18;
6806
6807 // range->retry_capa; /* What retry options are supported */
6808 // range->retry_flags; /* How to decode max/min retry limit */
6809 // range->r_time_flags; /* How to decode max/min retry life */
6810 // range->min_retry; /* Minimal number of retries */
6811 // range->max_retry; /* Maximal number of retries */
6812 // range->min_r_time; /* Minimal retry lifetime */
6813 // range->max_r_time; /* Maximal retry lifetime */
6814
6815 range->num_channels = FREQ_COUNT;
6816
6817 val = 0;
6818 for (i = 0; i < FREQ_COUNT; i++) {
6819 // TODO: Include only legal frequencies for some countries
6820 // if (local->channel_mask & (1 << i)) {
6821 range->freq[val].i = i + 1;
6822 range->freq[val].m = ipw2100_frequencies[i] * 100000;
6823 range->freq[val].e = 1;
6824 val++;
6825 // }
6826 if (val == IW_MAX_FREQUENCIES)
6827 break;
6828 }
6829 range->num_frequency = val;
6830
6831 /* Event capability (kernel + driver) */
6832 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
6833 IW_EVENT_CAPA_MASK(SIOCGIWAP));
6834 range->event_capa[1] = IW_EVENT_CAPA_K_1;
6835
6836 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
6837 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
6838
6839 IPW_DEBUG_WX("GET Range\n");
6840
6841 return 0;
6842 }
6843
ipw2100_wx_set_wap(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)6844 static int ipw2100_wx_set_wap(struct net_device *dev,
6845 struct iw_request_info *info,
6846 union iwreq_data *wrqu, char *extra)
6847 {
6848 struct ipw2100_priv *priv = libipw_priv(dev);
6849 int err = 0;
6850
6851 // sanity checks
6852 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
6853 return -EINVAL;
6854
6855 mutex_lock(&priv->action_mutex);
6856 if (!(priv->status & STATUS_INITIALIZED)) {
6857 err = -EIO;
6858 goto done;
6859 }
6860
6861 if (is_broadcast_ether_addr(wrqu->ap_addr.sa_data) ||
6862 is_zero_ether_addr(wrqu->ap_addr.sa_data)) {
6863 /* we disable mandatory BSSID association */
6864 IPW_DEBUG_WX("exit - disable mandatory BSSID\n");
6865 priv->config &= ~CFG_STATIC_BSSID;
6866 err = ipw2100_set_mandatory_bssid(priv, NULL, 0);
6867 goto done;
6868 }
6869
6870 priv->config |= CFG_STATIC_BSSID;
6871 memcpy(priv->mandatory_bssid_mac, wrqu->ap_addr.sa_data, ETH_ALEN);
6872
6873 err = ipw2100_set_mandatory_bssid(priv, wrqu->ap_addr.sa_data, 0);
6874
6875 IPW_DEBUG_WX("SET BSSID -> %pM\n", wrqu->ap_addr.sa_data);
6876
6877 done:
6878 mutex_unlock(&priv->action_mutex);
6879 return err;
6880 }
6881
ipw2100_wx_get_wap(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)6882 static int ipw2100_wx_get_wap(struct net_device *dev,
6883 struct iw_request_info *info,
6884 union iwreq_data *wrqu, char *extra)
6885 {
6886 /*
6887 * This can be called at any time. No action lock required
6888 */
6889
6890 struct ipw2100_priv *priv = libipw_priv(dev);
6891
6892 /* If we are associated, trying to associate, or have a statically
6893 * configured BSSID then return that; otherwise return ANY */
6894 if (priv->config & CFG_STATIC_BSSID || priv->status & STATUS_ASSOCIATED) {
6895 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
6896 memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
6897 } else
6898 eth_zero_addr(wrqu->ap_addr.sa_data);
6899
6900 IPW_DEBUG_WX("Getting WAP BSSID: %pM\n", wrqu->ap_addr.sa_data);
6901 return 0;
6902 }
6903
ipw2100_wx_set_essid(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)6904 static int ipw2100_wx_set_essid(struct net_device *dev,
6905 struct iw_request_info *info,
6906 union iwreq_data *wrqu, char *extra)
6907 {
6908 struct ipw2100_priv *priv = libipw_priv(dev);
6909 char *essid = ""; /* ANY */
6910 int length = 0;
6911 int err = 0;
6912
6913 mutex_lock(&priv->action_mutex);
6914 if (!(priv->status & STATUS_INITIALIZED)) {
6915 err = -EIO;
6916 goto done;
6917 }
6918
6919 if (wrqu->essid.flags && wrqu->essid.length) {
6920 length = wrqu->essid.length;
6921 essid = extra;
6922 }
6923
6924 if (length == 0) {
6925 IPW_DEBUG_WX("Setting ESSID to ANY\n");
6926 priv->config &= ~CFG_STATIC_ESSID;
6927 err = ipw2100_set_essid(priv, NULL, 0, 0);
6928 goto done;
6929 }
6930
6931 length = min(length, IW_ESSID_MAX_SIZE);
6932
6933 priv->config |= CFG_STATIC_ESSID;
6934
6935 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
6936 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
6937 err = 0;
6938 goto done;
6939 }
6940
6941 IPW_DEBUG_WX("Setting ESSID: '%*pE' (%d)\n", length, essid, length);
6942
6943 priv->essid_len = length;
6944 memcpy(priv->essid, essid, priv->essid_len);
6945
6946 err = ipw2100_set_essid(priv, essid, length, 0);
6947
6948 done:
6949 mutex_unlock(&priv->action_mutex);
6950 return err;
6951 }
6952
ipw2100_wx_get_essid(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)6953 static int ipw2100_wx_get_essid(struct net_device *dev,
6954 struct iw_request_info *info,
6955 union iwreq_data *wrqu, char *extra)
6956 {
6957 /*
6958 * This can be called at any time. No action lock required
6959 */
6960
6961 struct ipw2100_priv *priv = libipw_priv(dev);
6962
6963 /* If we are associated, trying to associate, or have a statically
6964 * configured ESSID then return that; otherwise return ANY */
6965 if (priv->config & CFG_STATIC_ESSID || priv->status & STATUS_ASSOCIATED) {
6966 IPW_DEBUG_WX("Getting essid: '%*pE'\n",
6967 priv->essid_len, priv->essid);
6968 memcpy(extra, priv->essid, priv->essid_len);
6969 wrqu->essid.length = priv->essid_len;
6970 wrqu->essid.flags = 1; /* active */
6971 } else {
6972 IPW_DEBUG_WX("Getting essid: ANY\n");
6973 wrqu->essid.length = 0;
6974 wrqu->essid.flags = 0; /* active */
6975 }
6976
6977 return 0;
6978 }
6979
ipw2100_wx_set_nick(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)6980 static int ipw2100_wx_set_nick(struct net_device *dev,
6981 struct iw_request_info *info,
6982 union iwreq_data *wrqu, char *extra)
6983 {
6984 /*
6985 * This can be called at any time. No action lock required
6986 */
6987
6988 struct ipw2100_priv *priv = libipw_priv(dev);
6989
6990 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
6991 return -E2BIG;
6992
6993 wrqu->data.length = min_t(size_t, wrqu->data.length, sizeof(priv->nick));
6994 memset(priv->nick, 0, sizeof(priv->nick));
6995 memcpy(priv->nick, extra, wrqu->data.length);
6996
6997 IPW_DEBUG_WX("SET Nickname -> %s\n", priv->nick);
6998
6999 return 0;
7000 }
7001
ipw2100_wx_get_nick(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)7002 static int ipw2100_wx_get_nick(struct net_device *dev,
7003 struct iw_request_info *info,
7004 union iwreq_data *wrqu, char *extra)
7005 {
7006 /*
7007 * This can be called at any time. No action lock required
7008 */
7009
7010 struct ipw2100_priv *priv = libipw_priv(dev);
7011
7012 wrqu->data.length = strlen(priv->nick);
7013 memcpy(extra, priv->nick, wrqu->data.length);
7014 wrqu->data.flags = 1; /* active */
7015
7016 IPW_DEBUG_WX("GET Nickname -> %s\n", extra);
7017
7018 return 0;
7019 }
7020
ipw2100_wx_set_rate(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)7021 static int ipw2100_wx_set_rate(struct net_device *dev,
7022 struct iw_request_info *info,
7023 union iwreq_data *wrqu, char *extra)
7024 {
7025 struct ipw2100_priv *priv = libipw_priv(dev);
7026 u32 target_rate = wrqu->bitrate.value;
7027 u32 rate;
7028 int err = 0;
7029
7030 mutex_lock(&priv->action_mutex);
7031 if (!(priv->status & STATUS_INITIALIZED)) {
7032 err = -EIO;
7033 goto done;
7034 }
7035
7036 rate = 0;
7037
7038 if (target_rate == 1000000 ||
7039 (!wrqu->bitrate.fixed && target_rate > 1000000))
7040 rate |= TX_RATE_1_MBIT;
7041 if (target_rate == 2000000 ||
7042 (!wrqu->bitrate.fixed && target_rate > 2000000))
7043 rate |= TX_RATE_2_MBIT;
7044 if (target_rate == 5500000 ||
7045 (!wrqu->bitrate.fixed && target_rate > 5500000))
7046 rate |= TX_RATE_5_5_MBIT;
7047 if (target_rate == 11000000 ||
7048 (!wrqu->bitrate.fixed && target_rate > 11000000))
7049 rate |= TX_RATE_11_MBIT;
7050 if (rate == 0)
7051 rate = DEFAULT_TX_RATES;
7052
7053 err = ipw2100_set_tx_rates(priv, rate, 0);
7054
7055 IPW_DEBUG_WX("SET Rate -> %04X\n", rate);
7056 done:
7057 mutex_unlock(&priv->action_mutex);
7058 return err;
7059 }
7060
ipw2100_wx_get_rate(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)7061 static int ipw2100_wx_get_rate(struct net_device *dev,
7062 struct iw_request_info *info,
7063 union iwreq_data *wrqu, char *extra)
7064 {
7065 struct ipw2100_priv *priv = libipw_priv(dev);
7066 int val;
7067 unsigned int len = sizeof(val);
7068 int err = 0;
7069
7070 if (!(priv->status & STATUS_ENABLED) ||
7071 priv->status & STATUS_RF_KILL_MASK ||
7072 !(priv->status & STATUS_ASSOCIATED)) {
7073 wrqu->bitrate.value = 0;
7074 return 0;
7075 }
7076
7077 mutex_lock(&priv->action_mutex);
7078 if (!(priv->status & STATUS_INITIALIZED)) {
7079 err = -EIO;
7080 goto done;
7081 }
7082
7083 err = ipw2100_get_ordinal(priv, IPW_ORD_CURRENT_TX_RATE, &val, &len);
7084 if (err) {
7085 IPW_DEBUG_WX("failed querying ordinals.\n");
7086 goto done;
7087 }
7088
7089 switch (val & TX_RATE_MASK) {
7090 case TX_RATE_1_MBIT:
7091 wrqu->bitrate.value = 1000000;
7092 break;
7093 case TX_RATE_2_MBIT:
7094 wrqu->bitrate.value = 2000000;
7095 break;
7096 case TX_RATE_5_5_MBIT:
7097 wrqu->bitrate.value = 5500000;
7098 break;
7099 case TX_RATE_11_MBIT:
7100 wrqu->bitrate.value = 11000000;
7101 break;
7102 default:
7103 wrqu->bitrate.value = 0;
7104 }
7105
7106 IPW_DEBUG_WX("GET Rate -> %d\n", wrqu->bitrate.value);
7107
7108 done:
7109 mutex_unlock(&priv->action_mutex);
7110 return err;
7111 }
7112
ipw2100_wx_set_rts(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)7113 static int ipw2100_wx_set_rts(struct net_device *dev,
7114 struct iw_request_info *info,
7115 union iwreq_data *wrqu, char *extra)
7116 {
7117 struct ipw2100_priv *priv = libipw_priv(dev);
7118 int value, err;
7119
7120 /* Auto RTS not yet supported */
7121 if (wrqu->rts.fixed == 0)
7122 return -EINVAL;
7123
7124 mutex_lock(&priv->action_mutex);
7125 if (!(priv->status & STATUS_INITIALIZED)) {
7126 err = -EIO;
7127 goto done;
7128 }
7129
7130 if (wrqu->rts.disabled)
7131 value = priv->rts_threshold | RTS_DISABLED;
7132 else {
7133 if (wrqu->rts.value < 1 || wrqu->rts.value > 2304) {
7134 err = -EINVAL;
7135 goto done;
7136 }
7137 value = wrqu->rts.value;
7138 }
7139
7140 err = ipw2100_set_rts_threshold(priv, value);
7141
7142 IPW_DEBUG_WX("SET RTS Threshold -> 0x%08X\n", value);
7143 done:
7144 mutex_unlock(&priv->action_mutex);
7145 return err;
7146 }
7147
ipw2100_wx_get_rts(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)7148 static int ipw2100_wx_get_rts(struct net_device *dev,
7149 struct iw_request_info *info,
7150 union iwreq_data *wrqu, char *extra)
7151 {
7152 /*
7153 * This can be called at any time. No action lock required
7154 */
7155
7156 struct ipw2100_priv *priv = libipw_priv(dev);
7157
7158 wrqu->rts.value = priv->rts_threshold & ~RTS_DISABLED;
7159 wrqu->rts.fixed = 1; /* no auto select */
7160
7161 /* If RTS is set to the default value, then it is disabled */
7162 wrqu->rts.disabled = (priv->rts_threshold & RTS_DISABLED) ? 1 : 0;
7163
7164 IPW_DEBUG_WX("GET RTS Threshold -> 0x%08X\n", wrqu->rts.value);
7165
7166 return 0;
7167 }
7168
ipw2100_wx_set_txpow(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)7169 static int ipw2100_wx_set_txpow(struct net_device *dev,
7170 struct iw_request_info *info,
7171 union iwreq_data *wrqu, char *extra)
7172 {
7173 struct ipw2100_priv *priv = libipw_priv(dev);
7174 int err = 0, value;
7175
7176 if (ipw_radio_kill_sw(priv, wrqu->txpower.disabled))
7177 return -EINPROGRESS;
7178
7179 if (priv->ieee->iw_mode != IW_MODE_ADHOC)
7180 return 0;
7181
7182 if ((wrqu->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
7183 return -EINVAL;
7184
7185 if (wrqu->txpower.fixed == 0)
7186 value = IPW_TX_POWER_DEFAULT;
7187 else {
7188 if (wrqu->txpower.value < IPW_TX_POWER_MIN_DBM ||
7189 wrqu->txpower.value > IPW_TX_POWER_MAX_DBM)
7190 return -EINVAL;
7191
7192 value = wrqu->txpower.value;
7193 }
7194
7195 mutex_lock(&priv->action_mutex);
7196 if (!(priv->status & STATUS_INITIALIZED)) {
7197 err = -EIO;
7198 goto done;
7199 }
7200
7201 err = ipw2100_set_tx_power(priv, value);
7202
7203 IPW_DEBUG_WX("SET TX Power -> %d\n", value);
7204
7205 done:
7206 mutex_unlock(&priv->action_mutex);
7207 return err;
7208 }
7209
ipw2100_wx_get_txpow(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)7210 static int ipw2100_wx_get_txpow(struct net_device *dev,
7211 struct iw_request_info *info,
7212 union iwreq_data *wrqu, char *extra)
7213 {
7214 /*
7215 * This can be called at any time. No action lock required
7216 */
7217
7218 struct ipw2100_priv *priv = libipw_priv(dev);
7219
7220 wrqu->txpower.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
7221
7222 if (priv->tx_power == IPW_TX_POWER_DEFAULT) {
7223 wrqu->txpower.fixed = 0;
7224 wrqu->txpower.value = IPW_TX_POWER_MAX_DBM;
7225 } else {
7226 wrqu->txpower.fixed = 1;
7227 wrqu->txpower.value = priv->tx_power;
7228 }
7229
7230 wrqu->txpower.flags = IW_TXPOW_DBM;
7231
7232 IPW_DEBUG_WX("GET TX Power -> %d\n", wrqu->txpower.value);
7233
7234 return 0;
7235 }
7236
ipw2100_wx_set_frag(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)7237 static int ipw2100_wx_set_frag(struct net_device *dev,
7238 struct iw_request_info *info,
7239 union iwreq_data *wrqu, char *extra)
7240 {
7241 /*
7242 * This can be called at any time. No action lock required
7243 */
7244
7245 struct ipw2100_priv *priv = libipw_priv(dev);
7246
7247 if (!wrqu->frag.fixed)
7248 return -EINVAL;
7249
7250 if (wrqu->frag.disabled) {
7251 priv->frag_threshold |= FRAG_DISABLED;
7252 priv->ieee->fts = DEFAULT_FTS;
7253 } else {
7254 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
7255 wrqu->frag.value > MAX_FRAG_THRESHOLD)
7256 return -EINVAL;
7257
7258 priv->ieee->fts = wrqu->frag.value & ~0x1;
7259 priv->frag_threshold = priv->ieee->fts;
7260 }
7261
7262 IPW_DEBUG_WX("SET Frag Threshold -> %d\n", priv->ieee->fts);
7263
7264 return 0;
7265 }
7266
ipw2100_wx_get_frag(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)7267 static int ipw2100_wx_get_frag(struct net_device *dev,
7268 struct iw_request_info *info,
7269 union iwreq_data *wrqu, char *extra)
7270 {
7271 /*
7272 * This can be called at any time. No action lock required
7273 */
7274
7275 struct ipw2100_priv *priv = libipw_priv(dev);
7276 wrqu->frag.value = priv->frag_threshold & ~FRAG_DISABLED;
7277 wrqu->frag.fixed = 0; /* no auto select */
7278 wrqu->frag.disabled = (priv->frag_threshold & FRAG_DISABLED) ? 1 : 0;
7279
7280 IPW_DEBUG_WX("GET Frag Threshold -> %d\n", wrqu->frag.value);
7281
7282 return 0;
7283 }
7284
ipw2100_wx_set_retry(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)7285 static int ipw2100_wx_set_retry(struct net_device *dev,
7286 struct iw_request_info *info,
7287 union iwreq_data *wrqu, char *extra)
7288 {
7289 struct ipw2100_priv *priv = libipw_priv(dev);
7290 int err = 0;
7291
7292 if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
7293 return -EINVAL;
7294
7295 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
7296 return 0;
7297
7298 mutex_lock(&priv->action_mutex);
7299 if (!(priv->status & STATUS_INITIALIZED)) {
7300 err = -EIO;
7301 goto done;
7302 }
7303
7304 if (wrqu->retry.flags & IW_RETRY_SHORT) {
7305 err = ipw2100_set_short_retry(priv, wrqu->retry.value);
7306 IPW_DEBUG_WX("SET Short Retry Limit -> %d\n",
7307 wrqu->retry.value);
7308 goto done;
7309 }
7310
7311 if (wrqu->retry.flags & IW_RETRY_LONG) {
7312 err = ipw2100_set_long_retry(priv, wrqu->retry.value);
7313 IPW_DEBUG_WX("SET Long Retry Limit -> %d\n",
7314 wrqu->retry.value);
7315 goto done;
7316 }
7317
7318 err = ipw2100_set_short_retry(priv, wrqu->retry.value);
7319 if (!err)
7320 err = ipw2100_set_long_retry(priv, wrqu->retry.value);
7321
7322 IPW_DEBUG_WX("SET Both Retry Limits -> %d\n", wrqu->retry.value);
7323
7324 done:
7325 mutex_unlock(&priv->action_mutex);
7326 return err;
7327 }
7328
ipw2100_wx_get_retry(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)7329 static int ipw2100_wx_get_retry(struct net_device *dev,
7330 struct iw_request_info *info,
7331 union iwreq_data *wrqu, char *extra)
7332 {
7333 /*
7334 * This can be called at any time. No action lock required
7335 */
7336
7337 struct ipw2100_priv *priv = libipw_priv(dev);
7338
7339 wrqu->retry.disabled = 0; /* can't be disabled */
7340
7341 if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME)
7342 return -EINVAL;
7343
7344 if (wrqu->retry.flags & IW_RETRY_LONG) {
7345 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
7346 wrqu->retry.value = priv->long_retry_limit;
7347 } else {
7348 wrqu->retry.flags =
7349 (priv->short_retry_limit !=
7350 priv->long_retry_limit) ?
7351 IW_RETRY_LIMIT | IW_RETRY_SHORT : IW_RETRY_LIMIT;
7352
7353 wrqu->retry.value = priv->short_retry_limit;
7354 }
7355
7356 IPW_DEBUG_WX("GET Retry -> %d\n", wrqu->retry.value);
7357
7358 return 0;
7359 }
7360
ipw2100_wx_set_scan(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)7361 static int ipw2100_wx_set_scan(struct net_device *dev,
7362 struct iw_request_info *info,
7363 union iwreq_data *wrqu, char *extra)
7364 {
7365 struct ipw2100_priv *priv = libipw_priv(dev);
7366 int err = 0;
7367
7368 mutex_lock(&priv->action_mutex);
7369 if (!(priv->status & STATUS_INITIALIZED)) {
7370 err = -EIO;
7371 goto done;
7372 }
7373
7374 IPW_DEBUG_WX("Initiating scan...\n");
7375
7376 priv->user_requested_scan = 1;
7377 if (ipw2100_set_scan_options(priv) || ipw2100_start_scan(priv)) {
7378 IPW_DEBUG_WX("Start scan failed.\n");
7379
7380 /* TODO: Mark a scan as pending so when hardware initialized
7381 * a scan starts */
7382 }
7383
7384 done:
7385 mutex_unlock(&priv->action_mutex);
7386 return err;
7387 }
7388
ipw2100_wx_get_scan(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)7389 static int ipw2100_wx_get_scan(struct net_device *dev,
7390 struct iw_request_info *info,
7391 union iwreq_data *wrqu, char *extra)
7392 {
7393 /*
7394 * This can be called at any time. No action lock required
7395 */
7396
7397 struct ipw2100_priv *priv = libipw_priv(dev);
7398 return libipw_wx_get_scan(priv->ieee, info, wrqu, extra);
7399 }
7400
7401 /*
7402 * Implementation based on code in hostap-driver v0.1.3 hostap_ioctl.c
7403 */
ipw2100_wx_set_encode(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * key)7404 static int ipw2100_wx_set_encode(struct net_device *dev,
7405 struct iw_request_info *info,
7406 union iwreq_data *wrqu, char *key)
7407 {
7408 /*
7409 * No check of STATUS_INITIALIZED required
7410 */
7411
7412 struct ipw2100_priv *priv = libipw_priv(dev);
7413 return libipw_wx_set_encode(priv->ieee, info, wrqu, key);
7414 }
7415
ipw2100_wx_get_encode(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * key)7416 static int ipw2100_wx_get_encode(struct net_device *dev,
7417 struct iw_request_info *info,
7418 union iwreq_data *wrqu, char *key)
7419 {
7420 /*
7421 * This can be called at any time. No action lock required
7422 */
7423
7424 struct ipw2100_priv *priv = libipw_priv(dev);
7425 return libipw_wx_get_encode(priv->ieee, info, wrqu, key);
7426 }
7427
ipw2100_wx_set_power(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)7428 static int ipw2100_wx_set_power(struct net_device *dev,
7429 struct iw_request_info *info,
7430 union iwreq_data *wrqu, char *extra)
7431 {
7432 struct ipw2100_priv *priv = libipw_priv(dev);
7433 int err = 0;
7434
7435 mutex_lock(&priv->action_mutex);
7436 if (!(priv->status & STATUS_INITIALIZED)) {
7437 err = -EIO;
7438 goto done;
7439 }
7440
7441 if (wrqu->power.disabled) {
7442 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
7443 err = ipw2100_set_power_mode(priv, IPW_POWER_MODE_CAM);
7444 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
7445 goto done;
7446 }
7447
7448 switch (wrqu->power.flags & IW_POWER_MODE) {
7449 case IW_POWER_ON: /* If not specified */
7450 case IW_POWER_MODE: /* If set all mask */
7451 case IW_POWER_ALL_R: /* If explicitly state all */
7452 break;
7453 default: /* Otherwise we don't support it */
7454 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
7455 wrqu->power.flags);
7456 err = -EOPNOTSUPP;
7457 goto done;
7458 }
7459
7460 /* If the user hasn't specified a power management mode yet, default
7461 * to BATTERY */
7462 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
7463 err = ipw2100_set_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
7464
7465 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
7466
7467 done:
7468 mutex_unlock(&priv->action_mutex);
7469 return err;
7470
7471 }
7472
ipw2100_wx_get_power(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)7473 static int ipw2100_wx_get_power(struct net_device *dev,
7474 struct iw_request_info *info,
7475 union iwreq_data *wrqu, char *extra)
7476 {
7477 /*
7478 * This can be called at any time. No action lock required
7479 */
7480
7481 struct ipw2100_priv *priv = libipw_priv(dev);
7482
7483 if (!(priv->power_mode & IPW_POWER_ENABLED))
7484 wrqu->power.disabled = 1;
7485 else {
7486 wrqu->power.disabled = 0;
7487 wrqu->power.flags = 0;
7488 }
7489
7490 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
7491
7492 return 0;
7493 }
7494
7495 /*
7496 * WE-18 WPA support
7497 */
7498
7499 /* SIOCSIWGENIE */
ipw2100_wx_set_genie(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)7500 static int ipw2100_wx_set_genie(struct net_device *dev,
7501 struct iw_request_info *info,
7502 union iwreq_data *wrqu, char *extra)
7503 {
7504
7505 struct ipw2100_priv *priv = libipw_priv(dev);
7506 struct libipw_device *ieee = priv->ieee;
7507 u8 *buf;
7508
7509 if (!ieee->wpa_enabled)
7510 return -EOPNOTSUPP;
7511
7512 if (wrqu->data.length > MAX_WPA_IE_LEN ||
7513 (wrqu->data.length && extra == NULL))
7514 return -EINVAL;
7515
7516 if (wrqu->data.length) {
7517 buf = kmemdup(extra, wrqu->data.length, GFP_KERNEL);
7518 if (buf == NULL)
7519 return -ENOMEM;
7520
7521 kfree(ieee->wpa_ie);
7522 ieee->wpa_ie = buf;
7523 ieee->wpa_ie_len = wrqu->data.length;
7524 } else {
7525 kfree(ieee->wpa_ie);
7526 ieee->wpa_ie = NULL;
7527 ieee->wpa_ie_len = 0;
7528 }
7529
7530 ipw2100_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
7531
7532 return 0;
7533 }
7534
7535 /* SIOCGIWGENIE */
ipw2100_wx_get_genie(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)7536 static int ipw2100_wx_get_genie(struct net_device *dev,
7537 struct iw_request_info *info,
7538 union iwreq_data *wrqu, char *extra)
7539 {
7540 struct ipw2100_priv *priv = libipw_priv(dev);
7541 struct libipw_device *ieee = priv->ieee;
7542
7543 if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
7544 wrqu->data.length = 0;
7545 return 0;
7546 }
7547
7548 if (wrqu->data.length < ieee->wpa_ie_len)
7549 return -E2BIG;
7550
7551 wrqu->data.length = ieee->wpa_ie_len;
7552 memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
7553
7554 return 0;
7555 }
7556
7557 /* SIOCSIWAUTH */
ipw2100_wx_set_auth(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)7558 static int ipw2100_wx_set_auth(struct net_device *dev,
7559 struct iw_request_info *info,
7560 union iwreq_data *wrqu, char *extra)
7561 {
7562 struct ipw2100_priv *priv = libipw_priv(dev);
7563 struct libipw_device *ieee = priv->ieee;
7564 struct iw_param *param = &wrqu->param;
7565 struct libipw_crypt_data *crypt;
7566 unsigned long flags;
7567 int ret = 0;
7568
7569 switch (param->flags & IW_AUTH_INDEX) {
7570 case IW_AUTH_WPA_VERSION:
7571 case IW_AUTH_CIPHER_PAIRWISE:
7572 case IW_AUTH_CIPHER_GROUP:
7573 case IW_AUTH_KEY_MGMT:
7574 /*
7575 * ipw2200 does not use these parameters
7576 */
7577 break;
7578
7579 case IW_AUTH_TKIP_COUNTERMEASURES:
7580 crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx];
7581 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags)
7582 break;
7583
7584 flags = crypt->ops->get_flags(crypt->priv);
7585
7586 if (param->value)
7587 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
7588 else
7589 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
7590
7591 crypt->ops->set_flags(flags, crypt->priv);
7592
7593 break;
7594
7595 case IW_AUTH_DROP_UNENCRYPTED:{
7596 /* HACK:
7597 *
7598 * wpa_supplicant calls set_wpa_enabled when the driver
7599 * is loaded and unloaded, regardless of if WPA is being
7600 * used. No other calls are made which can be used to
7601 * determine if encryption will be used or not prior to
7602 * association being expected. If encryption is not being
7603 * used, drop_unencrypted is set to false, else true -- we
7604 * can use this to determine if the CAP_PRIVACY_ON bit should
7605 * be set.
7606 */
7607 struct libipw_security sec = {
7608 .flags = SEC_ENABLED,
7609 .enabled = param->value,
7610 };
7611 priv->ieee->drop_unencrypted = param->value;
7612 /* We only change SEC_LEVEL for open mode. Others
7613 * are set by ipw_wpa_set_encryption.
7614 */
7615 if (!param->value) {
7616 sec.flags |= SEC_LEVEL;
7617 sec.level = SEC_LEVEL_0;
7618 } else {
7619 sec.flags |= SEC_LEVEL;
7620 sec.level = SEC_LEVEL_1;
7621 }
7622 if (priv->ieee->set_security)
7623 priv->ieee->set_security(priv->ieee->dev, &sec);
7624 break;
7625 }
7626
7627 case IW_AUTH_80211_AUTH_ALG:
7628 ret = ipw2100_wpa_set_auth_algs(priv, param->value);
7629 break;
7630
7631 case IW_AUTH_WPA_ENABLED:
7632 ret = ipw2100_wpa_enable(priv, param->value);
7633 break;
7634
7635 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
7636 ieee->ieee802_1x = param->value;
7637 break;
7638
7639 //case IW_AUTH_ROAMING_CONTROL:
7640 case IW_AUTH_PRIVACY_INVOKED:
7641 ieee->privacy_invoked = param->value;
7642 break;
7643
7644 default:
7645 return -EOPNOTSUPP;
7646 }
7647 return ret;
7648 }
7649
7650 /* SIOCGIWAUTH */
ipw2100_wx_get_auth(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)7651 static int ipw2100_wx_get_auth(struct net_device *dev,
7652 struct iw_request_info *info,
7653 union iwreq_data *wrqu, char *extra)
7654 {
7655 struct ipw2100_priv *priv = libipw_priv(dev);
7656 struct libipw_device *ieee = priv->ieee;
7657 struct libipw_crypt_data *crypt;
7658 struct iw_param *param = &wrqu->param;
7659
7660 switch (param->flags & IW_AUTH_INDEX) {
7661 case IW_AUTH_WPA_VERSION:
7662 case IW_AUTH_CIPHER_PAIRWISE:
7663 case IW_AUTH_CIPHER_GROUP:
7664 case IW_AUTH_KEY_MGMT:
7665 /*
7666 * wpa_supplicant will control these internally
7667 */
7668 break;
7669
7670 case IW_AUTH_TKIP_COUNTERMEASURES:
7671 crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx];
7672 if (!crypt || !crypt->ops->get_flags) {
7673 IPW_DEBUG_WARNING("Can't get TKIP countermeasures: "
7674 "crypt not set!\n");
7675 break;
7676 }
7677
7678 param->value = (crypt->ops->get_flags(crypt->priv) &
7679 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
7680
7681 break;
7682
7683 case IW_AUTH_DROP_UNENCRYPTED:
7684 param->value = ieee->drop_unencrypted;
7685 break;
7686
7687 case IW_AUTH_80211_AUTH_ALG:
7688 param->value = priv->ieee->sec.auth_mode;
7689 break;
7690
7691 case IW_AUTH_WPA_ENABLED:
7692 param->value = ieee->wpa_enabled;
7693 break;
7694
7695 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
7696 param->value = ieee->ieee802_1x;
7697 break;
7698
7699 case IW_AUTH_ROAMING_CONTROL:
7700 case IW_AUTH_PRIVACY_INVOKED:
7701 param->value = ieee->privacy_invoked;
7702 break;
7703
7704 default:
7705 return -EOPNOTSUPP;
7706 }
7707 return 0;
7708 }
7709
7710 /* SIOCSIWENCODEEXT */
ipw2100_wx_set_encodeext(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)7711 static int ipw2100_wx_set_encodeext(struct net_device *dev,
7712 struct iw_request_info *info,
7713 union iwreq_data *wrqu, char *extra)
7714 {
7715 struct ipw2100_priv *priv = libipw_priv(dev);
7716 return libipw_wx_set_encodeext(priv->ieee, info, wrqu, extra);
7717 }
7718
7719 /* SIOCGIWENCODEEXT */
ipw2100_wx_get_encodeext(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)7720 static int ipw2100_wx_get_encodeext(struct net_device *dev,
7721 struct iw_request_info *info,
7722 union iwreq_data *wrqu, char *extra)
7723 {
7724 struct ipw2100_priv *priv = libipw_priv(dev);
7725 return libipw_wx_get_encodeext(priv->ieee, info, wrqu, extra);
7726 }
7727
7728 /* SIOCSIWMLME */
ipw2100_wx_set_mlme(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)7729 static int ipw2100_wx_set_mlme(struct net_device *dev,
7730 struct iw_request_info *info,
7731 union iwreq_data *wrqu, char *extra)
7732 {
7733 struct ipw2100_priv *priv = libipw_priv(dev);
7734 struct iw_mlme *mlme = (struct iw_mlme *)extra;
7735
7736 switch (mlme->cmd) {
7737 case IW_MLME_DEAUTH:
7738 // silently ignore
7739 break;
7740
7741 case IW_MLME_DISASSOC:
7742 ipw2100_disassociate_bssid(priv);
7743 break;
7744
7745 default:
7746 return -EOPNOTSUPP;
7747 }
7748 return 0;
7749 }
7750
7751 /*
7752 *
7753 * IWPRIV handlers
7754 *
7755 */
7756 #ifdef CONFIG_IPW2100_MONITOR
ipw2100_wx_set_promisc(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)7757 static int ipw2100_wx_set_promisc(struct net_device *dev,
7758 struct iw_request_info *info,
7759 union iwreq_data *wrqu, char *extra)
7760 {
7761 struct ipw2100_priv *priv = libipw_priv(dev);
7762 int *parms = (int *)extra;
7763 int enable = (parms[0] > 0);
7764 int err = 0;
7765
7766 mutex_lock(&priv->action_mutex);
7767 if (!(priv->status & STATUS_INITIALIZED)) {
7768 err = -EIO;
7769 goto done;
7770 }
7771
7772 if (enable) {
7773 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7774 err = ipw2100_set_channel(priv, parms[1], 0);
7775 goto done;
7776 }
7777 priv->channel = parms[1];
7778 err = ipw2100_switch_mode(priv, IW_MODE_MONITOR);
7779 } else {
7780 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
7781 err = ipw2100_switch_mode(priv, priv->last_mode);
7782 }
7783 done:
7784 mutex_unlock(&priv->action_mutex);
7785 return err;
7786 }
7787
ipw2100_wx_reset(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)7788 static int ipw2100_wx_reset(struct net_device *dev,
7789 struct iw_request_info *info,
7790 union iwreq_data *wrqu, char *extra)
7791 {
7792 struct ipw2100_priv *priv = libipw_priv(dev);
7793 if (priv->status & STATUS_INITIALIZED)
7794 schedule_reset(priv);
7795 return 0;
7796 }
7797
7798 #endif
7799
ipw2100_wx_set_powermode(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)7800 static int ipw2100_wx_set_powermode(struct net_device *dev,
7801 struct iw_request_info *info,
7802 union iwreq_data *wrqu, char *extra)
7803 {
7804 struct ipw2100_priv *priv = libipw_priv(dev);
7805 int err = 0, mode = *(int *)extra;
7806
7807 mutex_lock(&priv->action_mutex);
7808 if (!(priv->status & STATUS_INITIALIZED)) {
7809 err = -EIO;
7810 goto done;
7811 }
7812
7813 if ((mode < 0) || (mode > POWER_MODES))
7814 mode = IPW_POWER_AUTO;
7815
7816 if (IPW_POWER_LEVEL(priv->power_mode) != mode)
7817 err = ipw2100_set_power_mode(priv, mode);
7818 done:
7819 mutex_unlock(&priv->action_mutex);
7820 return err;
7821 }
7822
7823 #define MAX_POWER_STRING 80
ipw2100_wx_get_powermode(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)7824 static int ipw2100_wx_get_powermode(struct net_device *dev,
7825 struct iw_request_info *info,
7826 union iwreq_data *wrqu, char *extra)
7827 {
7828 /*
7829 * This can be called at any time. No action lock required
7830 */
7831
7832 struct ipw2100_priv *priv = libipw_priv(dev);
7833 int level = IPW_POWER_LEVEL(priv->power_mode);
7834 s32 timeout, period;
7835
7836 if (!(priv->power_mode & IPW_POWER_ENABLED)) {
7837 snprintf(extra, MAX_POWER_STRING,
7838 "Power save level: %d (Off)", level);
7839 } else {
7840 switch (level) {
7841 case IPW_POWER_MODE_CAM:
7842 snprintf(extra, MAX_POWER_STRING,
7843 "Power save level: %d (None)", level);
7844 break;
7845 case IPW_POWER_AUTO:
7846 snprintf(extra, MAX_POWER_STRING,
7847 "Power save level: %d (Auto)", level);
7848 break;
7849 default:
7850 timeout = timeout_duration[level - 1] / 1000;
7851 period = period_duration[level - 1] / 1000;
7852 snprintf(extra, MAX_POWER_STRING,
7853 "Power save level: %d "
7854 "(Timeout %dms, Period %dms)",
7855 level, timeout, period);
7856 }
7857 }
7858
7859 wrqu->data.length = strlen(extra) + 1;
7860
7861 return 0;
7862 }
7863
ipw2100_wx_set_preamble(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)7864 static int ipw2100_wx_set_preamble(struct net_device *dev,
7865 struct iw_request_info *info,
7866 union iwreq_data *wrqu, char *extra)
7867 {
7868 struct ipw2100_priv *priv = libipw_priv(dev);
7869 int err, mode = *(int *)extra;
7870
7871 mutex_lock(&priv->action_mutex);
7872 if (!(priv->status & STATUS_INITIALIZED)) {
7873 err = -EIO;
7874 goto done;
7875 }
7876
7877 if (mode == 1)
7878 priv->config |= CFG_LONG_PREAMBLE;
7879 else if (mode == 0)
7880 priv->config &= ~CFG_LONG_PREAMBLE;
7881 else {
7882 err = -EINVAL;
7883 goto done;
7884 }
7885
7886 err = ipw2100_system_config(priv, 0);
7887
7888 done:
7889 mutex_unlock(&priv->action_mutex);
7890 return err;
7891 }
7892
ipw2100_wx_get_preamble(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)7893 static int ipw2100_wx_get_preamble(struct net_device *dev,
7894 struct iw_request_info *info,
7895 union iwreq_data *wrqu, char *extra)
7896 {
7897 /*
7898 * This can be called at any time. No action lock required
7899 */
7900
7901 struct ipw2100_priv *priv = libipw_priv(dev);
7902
7903 if (priv->config & CFG_LONG_PREAMBLE)
7904 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
7905 else
7906 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
7907
7908 return 0;
7909 }
7910
7911 #ifdef CONFIG_IPW2100_MONITOR
ipw2100_wx_set_crc_check(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)7912 static int ipw2100_wx_set_crc_check(struct net_device *dev,
7913 struct iw_request_info *info,
7914 union iwreq_data *wrqu, char *extra)
7915 {
7916 struct ipw2100_priv *priv = libipw_priv(dev);
7917 int err, mode = *(int *)extra;
7918
7919 mutex_lock(&priv->action_mutex);
7920 if (!(priv->status & STATUS_INITIALIZED)) {
7921 err = -EIO;
7922 goto done;
7923 }
7924
7925 if (mode == 1)
7926 priv->config |= CFG_CRC_CHECK;
7927 else if (mode == 0)
7928 priv->config &= ~CFG_CRC_CHECK;
7929 else {
7930 err = -EINVAL;
7931 goto done;
7932 }
7933 err = 0;
7934
7935 done:
7936 mutex_unlock(&priv->action_mutex);
7937 return err;
7938 }
7939
ipw2100_wx_get_crc_check(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)7940 static int ipw2100_wx_get_crc_check(struct net_device *dev,
7941 struct iw_request_info *info,
7942 union iwreq_data *wrqu, char *extra)
7943 {
7944 /*
7945 * This can be called at any time. No action lock required
7946 */
7947
7948 struct ipw2100_priv *priv = libipw_priv(dev);
7949
7950 if (priv->config & CFG_CRC_CHECK)
7951 snprintf(wrqu->name, IFNAMSIZ, "CRC checked (1)");
7952 else
7953 snprintf(wrqu->name, IFNAMSIZ, "CRC ignored (0)");
7954
7955 return 0;
7956 }
7957 #endif /* CONFIG_IPW2100_MONITOR */
7958
7959 static iw_handler ipw2100_wx_handlers[] = {
7960 IW_HANDLER(SIOCGIWNAME, ipw2100_wx_get_name),
7961 IW_HANDLER(SIOCSIWFREQ, ipw2100_wx_set_freq),
7962 IW_HANDLER(SIOCGIWFREQ, ipw2100_wx_get_freq),
7963 IW_HANDLER(SIOCSIWMODE, ipw2100_wx_set_mode),
7964 IW_HANDLER(SIOCGIWMODE, ipw2100_wx_get_mode),
7965 IW_HANDLER(SIOCGIWRANGE, ipw2100_wx_get_range),
7966 IW_HANDLER(SIOCSIWAP, ipw2100_wx_set_wap),
7967 IW_HANDLER(SIOCGIWAP, ipw2100_wx_get_wap),
7968 IW_HANDLER(SIOCSIWMLME, ipw2100_wx_set_mlme),
7969 IW_HANDLER(SIOCSIWSCAN, ipw2100_wx_set_scan),
7970 IW_HANDLER(SIOCGIWSCAN, ipw2100_wx_get_scan),
7971 IW_HANDLER(SIOCSIWESSID, ipw2100_wx_set_essid),
7972 IW_HANDLER(SIOCGIWESSID, ipw2100_wx_get_essid),
7973 IW_HANDLER(SIOCSIWNICKN, ipw2100_wx_set_nick),
7974 IW_HANDLER(SIOCGIWNICKN, ipw2100_wx_get_nick),
7975 IW_HANDLER(SIOCSIWRATE, ipw2100_wx_set_rate),
7976 IW_HANDLER(SIOCGIWRATE, ipw2100_wx_get_rate),
7977 IW_HANDLER(SIOCSIWRTS, ipw2100_wx_set_rts),
7978 IW_HANDLER(SIOCGIWRTS, ipw2100_wx_get_rts),
7979 IW_HANDLER(SIOCSIWFRAG, ipw2100_wx_set_frag),
7980 IW_HANDLER(SIOCGIWFRAG, ipw2100_wx_get_frag),
7981 IW_HANDLER(SIOCSIWTXPOW, ipw2100_wx_set_txpow),
7982 IW_HANDLER(SIOCGIWTXPOW, ipw2100_wx_get_txpow),
7983 IW_HANDLER(SIOCSIWRETRY, ipw2100_wx_set_retry),
7984 IW_HANDLER(SIOCGIWRETRY, ipw2100_wx_get_retry),
7985 IW_HANDLER(SIOCSIWENCODE, ipw2100_wx_set_encode),
7986 IW_HANDLER(SIOCGIWENCODE, ipw2100_wx_get_encode),
7987 IW_HANDLER(SIOCSIWPOWER, ipw2100_wx_set_power),
7988 IW_HANDLER(SIOCGIWPOWER, ipw2100_wx_get_power),
7989 IW_HANDLER(SIOCSIWGENIE, ipw2100_wx_set_genie),
7990 IW_HANDLER(SIOCGIWGENIE, ipw2100_wx_get_genie),
7991 IW_HANDLER(SIOCSIWAUTH, ipw2100_wx_set_auth),
7992 IW_HANDLER(SIOCGIWAUTH, ipw2100_wx_get_auth),
7993 IW_HANDLER(SIOCSIWENCODEEXT, ipw2100_wx_set_encodeext),
7994 IW_HANDLER(SIOCGIWENCODEEXT, ipw2100_wx_get_encodeext),
7995 };
7996
7997 #define IPW2100_PRIV_SET_MONITOR SIOCIWFIRSTPRIV
7998 #define IPW2100_PRIV_RESET SIOCIWFIRSTPRIV+1
7999 #define IPW2100_PRIV_SET_POWER SIOCIWFIRSTPRIV+2
8000 #define IPW2100_PRIV_GET_POWER SIOCIWFIRSTPRIV+3
8001 #define IPW2100_PRIV_SET_LONGPREAMBLE SIOCIWFIRSTPRIV+4
8002 #define IPW2100_PRIV_GET_LONGPREAMBLE SIOCIWFIRSTPRIV+5
8003 #define IPW2100_PRIV_SET_CRC_CHECK SIOCIWFIRSTPRIV+6
8004 #define IPW2100_PRIV_GET_CRC_CHECK SIOCIWFIRSTPRIV+7
8005
8006 static const struct iw_priv_args ipw2100_private_args[] = {
8007
8008 #ifdef CONFIG_IPW2100_MONITOR
8009 {
8010 IPW2100_PRIV_SET_MONITOR,
8011 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
8012 {
8013 IPW2100_PRIV_RESET,
8014 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
8015 #endif /* CONFIG_IPW2100_MONITOR */
8016
8017 {
8018 IPW2100_PRIV_SET_POWER,
8019 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_power"},
8020 {
8021 IPW2100_PRIV_GET_POWER,
8022 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_POWER_STRING,
8023 "get_power"},
8024 {
8025 IPW2100_PRIV_SET_LONGPREAMBLE,
8026 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_preamble"},
8027 {
8028 IPW2100_PRIV_GET_LONGPREAMBLE,
8029 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, "get_preamble"},
8030 #ifdef CONFIG_IPW2100_MONITOR
8031 {
8032 IPW2100_PRIV_SET_CRC_CHECK,
8033 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_crc_check"},
8034 {
8035 IPW2100_PRIV_GET_CRC_CHECK,
8036 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, "get_crc_check"},
8037 #endif /* CONFIG_IPW2100_MONITOR */
8038 };
8039
8040 static iw_handler ipw2100_private_handler[] = {
8041 #ifdef CONFIG_IPW2100_MONITOR
8042 ipw2100_wx_set_promisc,
8043 ipw2100_wx_reset,
8044 #else /* CONFIG_IPW2100_MONITOR */
8045 NULL,
8046 NULL,
8047 #endif /* CONFIG_IPW2100_MONITOR */
8048 ipw2100_wx_set_powermode,
8049 ipw2100_wx_get_powermode,
8050 ipw2100_wx_set_preamble,
8051 ipw2100_wx_get_preamble,
8052 #ifdef CONFIG_IPW2100_MONITOR
8053 ipw2100_wx_set_crc_check,
8054 ipw2100_wx_get_crc_check,
8055 #else /* CONFIG_IPW2100_MONITOR */
8056 NULL,
8057 NULL,
8058 #endif /* CONFIG_IPW2100_MONITOR */
8059 };
8060
8061 /*
8062 * Get wireless statistics.
8063 * Called by /proc/net/wireless
8064 * Also called by SIOCGIWSTATS
8065 */
ipw2100_wx_wireless_stats(struct net_device * dev)8066 static struct iw_statistics *ipw2100_wx_wireless_stats(struct net_device *dev)
8067 {
8068 enum {
8069 POOR = 30,
8070 FAIR = 60,
8071 GOOD = 80,
8072 VERY_GOOD = 90,
8073 EXCELLENT = 95,
8074 PERFECT = 100
8075 };
8076 int rssi_qual;
8077 int tx_qual;
8078 int beacon_qual;
8079 int quality;
8080
8081 struct ipw2100_priv *priv = libipw_priv(dev);
8082 struct iw_statistics *wstats;
8083 u32 rssi, tx_retries, missed_beacons, tx_failures;
8084 u32 ord_len = sizeof(u32);
8085
8086 if (!priv)
8087 return (struct iw_statistics *)NULL;
8088
8089 wstats = &priv->wstats;
8090
8091 /* if hw is disabled, then ipw2100_get_ordinal() can't be called.
8092 * ipw2100_wx_wireless_stats seems to be called before fw is
8093 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
8094 * and associated; if not associcated, the values are all meaningless
8095 * anyway, so set them all to NULL and INVALID */
8096 if (!(priv->status & STATUS_ASSOCIATED)) {
8097 wstats->miss.beacon = 0;
8098 wstats->discard.retries = 0;
8099 wstats->qual.qual = 0;
8100 wstats->qual.level = 0;
8101 wstats->qual.noise = 0;
8102 wstats->qual.updated = 7;
8103 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
8104 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
8105 return wstats;
8106 }
8107
8108 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_PERCENT_MISSED_BCNS,
8109 &missed_beacons, &ord_len))
8110 goto fail_get_ordinal;
8111
8112 /* If we don't have a connection the quality and level is 0 */
8113 if (!(priv->status & STATUS_ASSOCIATED)) {
8114 wstats->qual.qual = 0;
8115 wstats->qual.level = 0;
8116 } else {
8117 if (ipw2100_get_ordinal(priv, IPW_ORD_RSSI_AVG_CURR,
8118 &rssi, &ord_len))
8119 goto fail_get_ordinal;
8120 wstats->qual.level = rssi + IPW2100_RSSI_TO_DBM;
8121 if (rssi < 10)
8122 rssi_qual = rssi * POOR / 10;
8123 else if (rssi < 15)
8124 rssi_qual = (rssi - 10) * (FAIR - POOR) / 5 + POOR;
8125 else if (rssi < 20)
8126 rssi_qual = (rssi - 15) * (GOOD - FAIR) / 5 + FAIR;
8127 else if (rssi < 30)
8128 rssi_qual = (rssi - 20) * (VERY_GOOD - GOOD) /
8129 10 + GOOD;
8130 else
8131 rssi_qual = (rssi - 30) * (PERFECT - VERY_GOOD) /
8132 10 + VERY_GOOD;
8133
8134 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_PERCENT_RETRIES,
8135 &tx_retries, &ord_len))
8136 goto fail_get_ordinal;
8137
8138 if (tx_retries > 75)
8139 tx_qual = (90 - tx_retries) * POOR / 15;
8140 else if (tx_retries > 70)
8141 tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
8142 else if (tx_retries > 65)
8143 tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
8144 else if (tx_retries > 50)
8145 tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
8146 15 + GOOD;
8147 else
8148 tx_qual = (50 - tx_retries) *
8149 (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
8150
8151 if (missed_beacons > 50)
8152 beacon_qual = (60 - missed_beacons) * POOR / 10;
8153 else if (missed_beacons > 40)
8154 beacon_qual = (50 - missed_beacons) * (FAIR - POOR) /
8155 10 + POOR;
8156 else if (missed_beacons > 32)
8157 beacon_qual = (40 - missed_beacons) * (GOOD - FAIR) /
8158 18 + FAIR;
8159 else if (missed_beacons > 20)
8160 beacon_qual = (32 - missed_beacons) *
8161 (VERY_GOOD - GOOD) / 20 + GOOD;
8162 else
8163 beacon_qual = (20 - missed_beacons) *
8164 (PERFECT - VERY_GOOD) / 20 + VERY_GOOD;
8165
8166 quality = min(tx_qual, rssi_qual);
8167 quality = min(beacon_qual, quality);
8168
8169 #ifdef CONFIG_IPW2100_DEBUG
8170 if (beacon_qual == quality)
8171 IPW_DEBUG_WX("Quality clamped by Missed Beacons\n");
8172 else if (tx_qual == quality)
8173 IPW_DEBUG_WX("Quality clamped by Tx Retries\n");
8174 else if (quality != 100)
8175 IPW_DEBUG_WX("Quality clamped by Signal Strength\n");
8176 else
8177 IPW_DEBUG_WX("Quality not clamped.\n");
8178 #endif
8179
8180 wstats->qual.qual = quality;
8181 wstats->qual.level = rssi + IPW2100_RSSI_TO_DBM;
8182 }
8183
8184 wstats->qual.noise = 0;
8185 wstats->qual.updated = 7;
8186 wstats->qual.updated |= IW_QUAL_NOISE_INVALID;
8187
8188 /* FIXME: this is percent and not a # */
8189 wstats->miss.beacon = missed_beacons;
8190
8191 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURES,
8192 &tx_failures, &ord_len))
8193 goto fail_get_ordinal;
8194 wstats->discard.retries = tx_failures;
8195
8196 return wstats;
8197
8198 fail_get_ordinal:
8199 IPW_DEBUG_WX("failed querying ordinals.\n");
8200
8201 return (struct iw_statistics *)NULL;
8202 }
8203
8204 static const struct iw_handler_def ipw2100_wx_handler_def = {
8205 .standard = ipw2100_wx_handlers,
8206 .num_standard = ARRAY_SIZE(ipw2100_wx_handlers),
8207 .num_private = ARRAY_SIZE(ipw2100_private_handler),
8208 .num_private_args = ARRAY_SIZE(ipw2100_private_args),
8209 .private = (iw_handler *) ipw2100_private_handler,
8210 .private_args = (struct iw_priv_args *)ipw2100_private_args,
8211 .get_wireless_stats = ipw2100_wx_wireless_stats,
8212 };
8213
ipw2100_wx_event_work(struct work_struct * work)8214 static void ipw2100_wx_event_work(struct work_struct *work)
8215 {
8216 struct ipw2100_priv *priv =
8217 container_of(work, struct ipw2100_priv, wx_event_work.work);
8218 union iwreq_data wrqu;
8219 unsigned int len = ETH_ALEN;
8220
8221 if (priv->status & STATUS_STOPPING)
8222 return;
8223
8224 mutex_lock(&priv->action_mutex);
8225
8226 IPW_DEBUG_WX("enter\n");
8227
8228 mutex_unlock(&priv->action_mutex);
8229
8230 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
8231
8232 /* Fetch BSSID from the hardware */
8233 if (!(priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) ||
8234 priv->status & STATUS_RF_KILL_MASK ||
8235 ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID,
8236 &priv->bssid, &len)) {
8237 eth_zero_addr(wrqu.ap_addr.sa_data);
8238 } else {
8239 /* We now have the BSSID, so can finish setting to the full
8240 * associated state */
8241 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
8242 memcpy(priv->ieee->bssid, priv->bssid, ETH_ALEN);
8243 priv->status &= ~STATUS_ASSOCIATING;
8244 priv->status |= STATUS_ASSOCIATED;
8245 netif_carrier_on(priv->net_dev);
8246 netif_wake_queue(priv->net_dev);
8247 }
8248
8249 if (!(priv->status & STATUS_ASSOCIATED)) {
8250 IPW_DEBUG_WX("Configuring ESSID\n");
8251 mutex_lock(&priv->action_mutex);
8252 /* This is a disassociation event, so kick the firmware to
8253 * look for another AP */
8254 if (priv->config & CFG_STATIC_ESSID)
8255 ipw2100_set_essid(priv, priv->essid, priv->essid_len,
8256 0);
8257 else
8258 ipw2100_set_essid(priv, NULL, 0, 0);
8259 mutex_unlock(&priv->action_mutex);
8260 }
8261
8262 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
8263 }
8264
8265 #define IPW2100_FW_MAJOR_VERSION 1
8266 #define IPW2100_FW_MINOR_VERSION 3
8267
8268 #define IPW2100_FW_MINOR(x) ((x & 0xff) >> 8)
8269 #define IPW2100_FW_MAJOR(x) (x & 0xff)
8270
8271 #define IPW2100_FW_VERSION ((IPW2100_FW_MINOR_VERSION << 8) | \
8272 IPW2100_FW_MAJOR_VERSION)
8273
8274 #define IPW2100_FW_PREFIX "ipw2100-" __stringify(IPW2100_FW_MAJOR_VERSION) \
8275 "." __stringify(IPW2100_FW_MINOR_VERSION)
8276
8277 #define IPW2100_FW_NAME(x) IPW2100_FW_PREFIX "" x ".fw"
8278
8279 /*
8280
8281 BINARY FIRMWARE HEADER FORMAT
8282
8283 offset length desc
8284 0 2 version
8285 2 2 mode == 0:BSS,1:IBSS,2:MONITOR
8286 4 4 fw_len
8287 8 4 uc_len
8288 C fw_len firmware data
8289 12 + fw_len uc_len microcode data
8290
8291 */
8292
8293 struct ipw2100_fw_header {
8294 short version;
8295 short mode;
8296 unsigned int fw_size;
8297 unsigned int uc_size;
8298 } __packed;
8299
ipw2100_mod_firmware_load(struct ipw2100_fw * fw)8300 static int ipw2100_mod_firmware_load(struct ipw2100_fw *fw)
8301 {
8302 struct ipw2100_fw_header *h =
8303 (struct ipw2100_fw_header *)fw->fw_entry->data;
8304
8305 if (IPW2100_FW_MAJOR(h->version) != IPW2100_FW_MAJOR_VERSION) {
8306 printk(KERN_WARNING DRV_NAME ": Firmware image not compatible "
8307 "(detected version id of %u). "
8308 "See Documentation/networking/device_drivers/wifi/intel/ipw2100.rst\n",
8309 h->version);
8310 return 1;
8311 }
8312
8313 fw->version = h->version;
8314 fw->fw.data = fw->fw_entry->data + sizeof(struct ipw2100_fw_header);
8315 fw->fw.size = h->fw_size;
8316 fw->uc.data = fw->fw.data + h->fw_size;
8317 fw->uc.size = h->uc_size;
8318
8319 return 0;
8320 }
8321
ipw2100_get_firmware(struct ipw2100_priv * priv,struct ipw2100_fw * fw)8322 static int ipw2100_get_firmware(struct ipw2100_priv *priv,
8323 struct ipw2100_fw *fw)
8324 {
8325 char *fw_name;
8326 int rc;
8327
8328 IPW_DEBUG_INFO("%s: Using hotplug firmware load.\n",
8329 priv->net_dev->name);
8330
8331 switch (priv->ieee->iw_mode) {
8332 case IW_MODE_ADHOC:
8333 fw_name = IPW2100_FW_NAME("-i");
8334 break;
8335 #ifdef CONFIG_IPW2100_MONITOR
8336 case IW_MODE_MONITOR:
8337 fw_name = IPW2100_FW_NAME("-p");
8338 break;
8339 #endif
8340 case IW_MODE_INFRA:
8341 default:
8342 fw_name = IPW2100_FW_NAME("");
8343 break;
8344 }
8345
8346 rc = request_firmware(&fw->fw_entry, fw_name, &priv->pci_dev->dev);
8347
8348 if (rc < 0) {
8349 printk(KERN_ERR DRV_NAME ": "
8350 "%s: Firmware '%s' not available or load failed.\n",
8351 priv->net_dev->name, fw_name);
8352 return rc;
8353 }
8354 IPW_DEBUG_INFO("firmware data %p size %zd\n", fw->fw_entry->data,
8355 fw->fw_entry->size);
8356
8357 ipw2100_mod_firmware_load(fw);
8358
8359 return 0;
8360 }
8361
8362 MODULE_FIRMWARE(IPW2100_FW_NAME("-i"));
8363 #ifdef CONFIG_IPW2100_MONITOR
8364 MODULE_FIRMWARE(IPW2100_FW_NAME("-p"));
8365 #endif
8366 MODULE_FIRMWARE(IPW2100_FW_NAME(""));
8367
ipw2100_release_firmware(struct ipw2100_priv * priv,struct ipw2100_fw * fw)8368 static void ipw2100_release_firmware(struct ipw2100_priv *priv,
8369 struct ipw2100_fw *fw)
8370 {
8371 fw->version = 0;
8372 release_firmware(fw->fw_entry);
8373 fw->fw_entry = NULL;
8374 }
8375
ipw2100_get_fwversion(struct ipw2100_priv * priv,char * buf,size_t max)8376 static int ipw2100_get_fwversion(struct ipw2100_priv *priv, char *buf,
8377 size_t max)
8378 {
8379 char ver[MAX_FW_VERSION_LEN];
8380 u32 len = MAX_FW_VERSION_LEN;
8381 u32 tmp;
8382 int i;
8383 /* firmware version is an ascii string (max len of 14) */
8384 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_FW_VER_NUM, ver, &len))
8385 return -EIO;
8386 tmp = max;
8387 if (len >= max)
8388 len = max - 1;
8389 for (i = 0; i < len; i++)
8390 buf[i] = ver[i];
8391 buf[i] = '\0';
8392 return tmp;
8393 }
8394
8395 /*
8396 * On exit, the firmware will have been freed from the fw list
8397 */
ipw2100_fw_download(struct ipw2100_priv * priv,struct ipw2100_fw * fw)8398 static int ipw2100_fw_download(struct ipw2100_priv *priv, struct ipw2100_fw *fw)
8399 {
8400 /* firmware is constructed of N contiguous entries, each entry is
8401 * structured as:
8402 *
8403 * offset sie desc
8404 * 0 4 address to write to
8405 * 4 2 length of data run
8406 * 6 length data
8407 */
8408 unsigned int addr;
8409 unsigned short len;
8410
8411 const unsigned char *firmware_data = fw->fw.data;
8412 unsigned int firmware_data_left = fw->fw.size;
8413
8414 while (firmware_data_left > 0) {
8415 addr = *(u32 *) (firmware_data);
8416 firmware_data += 4;
8417 firmware_data_left -= 4;
8418
8419 len = *(u16 *) (firmware_data);
8420 firmware_data += 2;
8421 firmware_data_left -= 2;
8422
8423 if (len > 32) {
8424 printk(KERN_ERR DRV_NAME ": "
8425 "Invalid firmware run-length of %d bytes\n",
8426 len);
8427 return -EINVAL;
8428 }
8429
8430 write_nic_memory(priv->net_dev, addr, len, firmware_data);
8431 firmware_data += len;
8432 firmware_data_left -= len;
8433 }
8434
8435 return 0;
8436 }
8437
8438 struct symbol_alive_response {
8439 u8 cmd_id;
8440 u8 seq_num;
8441 u8 ucode_rev;
8442 u8 eeprom_valid;
8443 u16 valid_flags;
8444 u8 IEEE_addr[6];
8445 u16 flags;
8446 u16 pcb_rev;
8447 u16 clock_settle_time; // 1us LSB
8448 u16 powerup_settle_time; // 1us LSB
8449 u16 hop_settle_time; // 1us LSB
8450 u8 date[3]; // month, day, year
8451 u8 time[2]; // hours, minutes
8452 u8 ucode_valid;
8453 };
8454
ipw2100_ucode_download(struct ipw2100_priv * priv,struct ipw2100_fw * fw)8455 static int ipw2100_ucode_download(struct ipw2100_priv *priv,
8456 struct ipw2100_fw *fw)
8457 {
8458 struct net_device *dev = priv->net_dev;
8459 const unsigned char *microcode_data = fw->uc.data;
8460 unsigned int microcode_data_left = fw->uc.size;
8461 void __iomem *reg = priv->ioaddr;
8462
8463 struct symbol_alive_response response;
8464 int i, j;
8465 u8 data;
8466
8467 /* Symbol control */
8468 write_nic_word(dev, IPW2100_CONTROL_REG, 0x703);
8469 readl(reg);
8470 write_nic_word(dev, IPW2100_CONTROL_REG, 0x707);
8471 readl(reg);
8472
8473 /* HW config */
8474 write_nic_byte(dev, 0x210014, 0x72); /* fifo width =16 */
8475 readl(reg);
8476 write_nic_byte(dev, 0x210014, 0x72); /* fifo width =16 */
8477 readl(reg);
8478
8479 /* EN_CS_ACCESS bit to reset control store pointer */
8480 write_nic_byte(dev, 0x210000, 0x40);
8481 readl(reg);
8482 write_nic_byte(dev, 0x210000, 0x0);
8483 readl(reg);
8484 write_nic_byte(dev, 0x210000, 0x40);
8485 readl(reg);
8486
8487 /* copy microcode from buffer into Symbol */
8488
8489 while (microcode_data_left > 0) {
8490 write_nic_byte(dev, 0x210010, *microcode_data++);
8491 write_nic_byte(dev, 0x210010, *microcode_data++);
8492 microcode_data_left -= 2;
8493 }
8494
8495 /* EN_CS_ACCESS bit to reset the control store pointer */
8496 write_nic_byte(dev, 0x210000, 0x0);
8497 readl(reg);
8498
8499 /* Enable System (Reg 0)
8500 * first enable causes garbage in RX FIFO */
8501 write_nic_byte(dev, 0x210000, 0x0);
8502 readl(reg);
8503 write_nic_byte(dev, 0x210000, 0x80);
8504 readl(reg);
8505
8506 /* Reset External Baseband Reg */
8507 write_nic_word(dev, IPW2100_CONTROL_REG, 0x703);
8508 readl(reg);
8509 write_nic_word(dev, IPW2100_CONTROL_REG, 0x707);
8510 readl(reg);
8511
8512 /* HW Config (Reg 5) */
8513 write_nic_byte(dev, 0x210014, 0x72); // fifo width =16
8514 readl(reg);
8515 write_nic_byte(dev, 0x210014, 0x72); // fifo width =16
8516 readl(reg);
8517
8518 /* Enable System (Reg 0)
8519 * second enable should be OK */
8520 write_nic_byte(dev, 0x210000, 0x00); // clear enable system
8521 readl(reg);
8522 write_nic_byte(dev, 0x210000, 0x80); // set enable system
8523
8524 /* check Symbol is enabled - upped this from 5 as it wasn't always
8525 * catching the update */
8526 for (i = 0; i < 10; i++) {
8527 udelay(10);
8528
8529 /* check Dino is enabled bit */
8530 read_nic_byte(dev, 0x210000, &data);
8531 if (data & 0x1)
8532 break;
8533 }
8534
8535 if (i == 10) {
8536 printk(KERN_ERR DRV_NAME ": %s: Error initializing Symbol\n",
8537 dev->name);
8538 return -EIO;
8539 }
8540
8541 /* Get Symbol alive response */
8542 for (i = 0; i < 30; i++) {
8543 /* Read alive response structure */
8544 for (j = 0;
8545 j < (sizeof(struct symbol_alive_response) >> 1); j++)
8546 read_nic_word(dev, 0x210004, ((u16 *) & response) + j);
8547
8548 if ((response.cmd_id == 1) && (response.ucode_valid == 0x1))
8549 break;
8550 udelay(10);
8551 }
8552
8553 if (i == 30) {
8554 printk(KERN_ERR DRV_NAME
8555 ": %s: No response from Symbol - hw not alive\n",
8556 dev->name);
8557 printk_buf(IPW_DL_ERROR, (u8 *) & response, sizeof(response));
8558 return -EIO;
8559 }
8560
8561 return 0;
8562 }
8563