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