1 /******************************************************************************
3 Copyright(c) 2003 - 2005 Intel Corporation. All rights reserved.
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.
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
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.
18 The full GNU General Public License is included in this distribution in the
22 James P. Ketrenos <ipw2100-admin@linux.intel.com>
23 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
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
29 Portions of this file are based on the Host AP project,
30 Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
32 Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
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
38 ******************************************************************************/
41 Initial driver on which this is based was developed by Janusz Gorycki,
42 Maciej Urbaniak, and Maciej Sosnowski.
44 Promiscuous mode support added by Jacek Wysoczynski and Maciej Urbaniak.
48 Tx - Commands and Data
50 Firmware and host share a circular queue of Transmit Buffer Descriptors (TBDs)
51 Each TBD contains a pointer to the physical (dma_addr_t) address of data being
52 sent to the firmware as well as the length of the data.
54 The host writes to the TBD queue at the WRITE index. The WRITE index points
55 to the _next_ packet to be written and is advanced when after the TBD has been
58 The firmware pulls from the TBD queue at the READ index. The READ index points
59 to the currently being read entry, and is advanced once the firmware is
62 When data is sent to the firmware, the first TBD is used to indicate to the
63 firmware if a Command or Data is being sent. If it is Command, all of the
64 command information is contained within the physical address referred to by the
65 TBD. If it is Data, the first TBD indicates the type of data packet, number
66 of fragments, etc. The next TBD then referrs to the actual packet location.
68 The Tx flow cycle is as follows:
70 1) ipw2100_tx() is called by kernel with SKB to transmit
71 2) Packet is move from the tx_free_list and appended to the transmit pending
73 3) work is scheduled to move pending packets into the shared circular queue.
74 4) when placing packet in the circular queue, the incoming SKB is DMA mapped
75 to a physical address. That address is entered into a TBD. Two TBDs are
76 filled out. The first indicating a data packet, the second referring to the
78 5) the packet is removed from tx_pend_list and placed on the end of the
79 firmware pending list (fw_pend_list)
80 6) firmware is notified that the WRITE index has
81 7) Once the firmware has processed the TBD, INTA is triggered.
82 8) For each Tx interrupt received from the firmware, the READ index is checked
83 to see which TBDs are done being processed.
84 9) For each TBD that has been processed, the ISR pulls the oldest packet
85 from the fw_pend_list.
86 10)The packet structure contained in the fw_pend_list is then used
87 to unmap the DMA address and to free the SKB originally passed to the driver
89 11)The packet structure is placed onto the tx_free_list
91 The above steps are the same for commands, only the msg_free_list/msg_pend_list
92 are used instead of tx_free_list/tx_pend_list
96 Critical Sections / Locking :
98 There are two locks utilized. The first is the low level lock (priv->low_lock)
99 that protects the following:
101 - Access to the Tx/Rx queue lists via priv->low_lock. The lists are as follows:
103 tx_free_list : Holds pre-allocated Tx buffers.
104 TAIL modified in __ipw2100_tx_process()
105 HEAD modified in ipw2100_tx()
107 tx_pend_list : Holds used Tx buffers waiting to go into the TBD ring
108 TAIL modified ipw2100_tx()
109 HEAD modified by ipw2100_tx_send_data()
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()
115 msg_pend_list : Holds used Msg buffers waiting to go into the TBD ring
116 TAIL modified in ipw2100_hw_send_command()
117 HEAD modified in ipw2100_tx_send_commands()
119 The flow of data on the TX side is as follows:
121 MSG_FREE_LIST + COMMAND => MSG_PEND_LIST => TBD => MSG_FREE_LIST
122 TX_FREE_LIST + DATA => TX_PEND_LIST => TBD => TX_FREE_LIST
124 The methods that work on the TBD ring are protected via priv->low_lock.
126 - The internal data state of the device itself
127 - Access to the firmware read/write indexes for the BD queues
130 All external entry functions are locked with the priv->action_lock to ensure
131 that only one external action is invoked at a time.
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>
149 #include <linux/dma-mapping.h>
150 #include <linux/proc_fs.h>
151 #include <linux/skbuff.h>
152 #include <asm/uaccess.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>
170 #define IPW2100_VERSION "1.1.0"
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"
178 /* Debugging stuff */
179 #ifdef CONFIG_IPW_DEBUG
180 #define CONFIG_IPW2100_RX_DEBUG /* Reception debugging */
183 MODULE_DESCRIPTION(DRV_DESCRIPTION);
184 MODULE_VERSION(DRV_VERSION);
185 MODULE_AUTHOR(DRV_COPYRIGHT);
186 MODULE_LICENSE("GPL");
188 static int debug = 0;
190 static int channel = 0;
191 static int associate = 1;
192 static int disable = 0;
194 static struct ipw2100_fw ipw2100_firmware;
197 #include <linux/moduleparam.h>
198 module_param(debug, int, 0444);
199 module_param(mode, int, 0444);
200 module_param(channel, int, 0444);
201 module_param(associate, int, 0444);
202 module_param(disable, int, 0444);
204 MODULE_PARM_DESC(debug, "debug level");
205 MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
206 MODULE_PARM_DESC(channel, "channel");
207 MODULE_PARM_DESC(associate, "auto associate when scanning (default on)");
208 MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
210 static u32 ipw2100_debug_level = IPW_DL_NONE;
212 #ifdef CONFIG_IPW_DEBUG
213 #define IPW_DEBUG(level, message...) \
215 if (ipw2100_debug_level & (level)) { \
216 printk(KERN_DEBUG "ipw2100: %c %s ", \
217 in_interrupt() ? 'I' : 'U', __FUNCTION__); \
222 #define IPW_DEBUG(level, message...) do {} while (0)
223 #endif /* CONFIG_IPW_DEBUG */
225 #ifdef CONFIG_IPW_DEBUG
226 static const char *command_types[] = {
228 "unused", /* HOST_ATTENTION */
230 "unused", /* SLEEP */
231 "unused", /* HOST_POWER_DOWN */
234 "unused", /* SET_IMR */
237 "AUTHENTICATION_TYPE",
240 "INTERNATIONAL_MODE",
255 "CLEAR_ALL_MULTICAST",
276 "AP_OR_STATION_TABLE",
280 "unused", /* SAVE_CALIBRATION */
281 "unused", /* RESTORE_CALIBRATION */
285 "HOST_PRE_POWER_DOWN",
286 "unused", /* HOST_INTERRUPT_COALESCING */
288 "CARD_DISABLE_PHY_OFF",
292 "SET_STATION_STAT_BITS",
293 "CLEAR_STATIONS_STAT_BITS",
295 "SET_SECURITY_INFORMATION",
296 "DISASSOCIATION_BSSID",
302 /* Pre-decl until we get the code solid and then we can clean it up */
303 static void ipw2100_tx_send_commands(struct ipw2100_priv *priv);
304 static void ipw2100_tx_send_data(struct ipw2100_priv *priv);
305 static int ipw2100_adapter_setup(struct ipw2100_priv *priv);
307 static void ipw2100_queues_initialize(struct ipw2100_priv *priv);
308 static void ipw2100_queues_free(struct ipw2100_priv *priv);
309 static int ipw2100_queues_allocate(struct ipw2100_priv *priv);
311 static int ipw2100_fw_download(struct ipw2100_priv *priv,
312 struct ipw2100_fw *fw);
313 static int ipw2100_get_firmware(struct ipw2100_priv *priv,
314 struct ipw2100_fw *fw);
315 static int ipw2100_get_fwversion(struct ipw2100_priv *priv, char *buf,
317 static int ipw2100_get_ucodeversion(struct ipw2100_priv *priv, char *buf,
319 static void ipw2100_release_firmware(struct ipw2100_priv *priv,
320 struct ipw2100_fw *fw);
321 static int ipw2100_ucode_download(struct ipw2100_priv *priv,
322 struct ipw2100_fw *fw);
323 static void ipw2100_wx_event_work(struct ipw2100_priv *priv);
324 static struct iw_statistics *ipw2100_wx_wireless_stats(struct net_device * dev);
325 static struct iw_handler_def ipw2100_wx_handler_def;
328 static inline void read_register(struct net_device *dev, u32 reg, u32 *val)
330 *val = readl((void __iomem *)(dev->base_addr + reg));
331 IPW_DEBUG_IO("r: 0x%08X => 0x%08X\n", reg, *val);
334 static inline void write_register(struct net_device *dev, u32 reg, u32 val)
336 writel(val, (void __iomem *)(dev->base_addr + reg));
337 IPW_DEBUG_IO("w: 0x%08X <= 0x%08X\n", reg, val);
340 static inline void read_register_word(struct net_device *dev, u32 reg, u16 *val)
342 *val = readw((void __iomem *)(dev->base_addr + reg));
343 IPW_DEBUG_IO("r: 0x%08X => %04X\n", reg, *val);
346 static inline void read_register_byte(struct net_device *dev, u32 reg, u8 *val)
348 *val = readb((void __iomem *)(dev->base_addr + reg));
349 IPW_DEBUG_IO("r: 0x%08X => %02X\n", reg, *val);
352 static inline void write_register_word(struct net_device *dev, u32 reg, u16 val)
354 writew(val, (void __iomem *)(dev->base_addr + reg));
355 IPW_DEBUG_IO("w: 0x%08X <= %04X\n", reg, val);
359 static inline void write_register_byte(struct net_device *dev, u32 reg, u8 val)
361 writeb(val, (void __iomem *)(dev->base_addr + reg));
362 IPW_DEBUG_IO("w: 0x%08X =< %02X\n", reg, val);
365 static inline void read_nic_dword(struct net_device *dev, u32 addr, u32 *val)
367 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
368 addr & IPW_REG_INDIRECT_ADDR_MASK);
369 read_register(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
372 static inline void write_nic_dword(struct net_device *dev, u32 addr, u32 val)
374 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
375 addr & IPW_REG_INDIRECT_ADDR_MASK);
376 write_register(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
379 static inline void read_nic_word(struct net_device *dev, u32 addr, u16 *val)
381 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
382 addr & IPW_REG_INDIRECT_ADDR_MASK);
383 read_register_word(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
386 static inline void write_nic_word(struct net_device *dev, u32 addr, u16 val)
388 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
389 addr & IPW_REG_INDIRECT_ADDR_MASK);
390 write_register_word(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
393 static inline void read_nic_byte(struct net_device *dev, u32 addr, u8 *val)
395 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
396 addr & IPW_REG_INDIRECT_ADDR_MASK);
397 read_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
400 static inline void write_nic_byte(struct net_device *dev, u32 addr, u8 val)
402 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
403 addr & IPW_REG_INDIRECT_ADDR_MASK);
404 write_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
407 static inline void write_nic_auto_inc_address(struct net_device *dev, u32 addr)
409 write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS,
410 addr & IPW_REG_INDIRECT_ADDR_MASK);
413 static inline void write_nic_dword_auto_inc(struct net_device *dev, u32 val)
415 write_register(dev, IPW_REG_AUTOINCREMENT_DATA, val);
418 static inline void write_nic_memory(struct net_device *dev, u32 addr, u32 len,
426 /* read first nibble byte by byte */
427 aligned_addr = addr & (~0x3);
428 dif_len = addr - aligned_addr;
430 /* Start reading at aligned_addr + dif_len */
431 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
433 for (i = dif_len; i < 4; i++, buf++)
435 dev, IPW_REG_INDIRECT_ACCESS_DATA + i,
442 /* read DWs through autoincrement registers */
443 write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS,
445 aligned_len = len & (~0x3);
446 for (i = 0; i < aligned_len; i += 4, buf += 4, aligned_addr += 4)
448 dev, IPW_REG_AUTOINCREMENT_DATA, *(u32 *)buf);
450 /* copy the last nibble */
451 dif_len = len - aligned_len;
452 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, aligned_addr);
453 for (i = 0; i < dif_len; i++, buf++)
455 dev, IPW_REG_INDIRECT_ACCESS_DATA + i, *buf);
458 static inline void read_nic_memory(struct net_device *dev, u32 addr, u32 len,
466 /* read first nibble byte by byte */
467 aligned_addr = addr & (~0x3);
468 dif_len = addr - aligned_addr;
470 /* Start reading at aligned_addr + dif_len */
471 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
473 for (i = dif_len; i < 4; i++, buf++)
475 dev, IPW_REG_INDIRECT_ACCESS_DATA + i, buf);
481 /* read DWs through autoincrement registers */
482 write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS,
484 aligned_len = len & (~0x3);
485 for (i = 0; i < aligned_len; i += 4, buf += 4, aligned_addr += 4)
486 read_register(dev, IPW_REG_AUTOINCREMENT_DATA,
489 /* copy the last nibble */
490 dif_len = len - aligned_len;
491 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
493 for (i = 0; i < dif_len; i++, buf++)
494 read_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA +
498 static inline int ipw2100_hw_is_adapter_in_system(struct net_device *dev)
500 return (dev->base_addr &&
501 (readl((void __iomem *)(dev->base_addr + IPW_REG_DOA_DEBUG_AREA_START))
502 == IPW_DATA_DOA_DEBUG_VALUE));
505 static int ipw2100_get_ordinal(struct ipw2100_priv *priv, u32 ord,
508 struct ipw2100_ordinals *ordinals = &priv->ordinals;
515 if (ordinals->table1_addr == 0) {
516 printk(KERN_WARNING DRV_NAME ": attempt to use fw ordinals "
517 "before they have been loaded.\n");
521 if (IS_ORDINAL_TABLE_ONE(ordinals, ord)) {
522 if (*len < IPW_ORD_TAB_1_ENTRY_SIZE) {
523 *len = IPW_ORD_TAB_1_ENTRY_SIZE;
525 printk(KERN_WARNING DRV_NAME
526 ": ordinal buffer length too small, need %zd\n",
527 IPW_ORD_TAB_1_ENTRY_SIZE);
532 read_nic_dword(priv->net_dev, ordinals->table1_addr + (ord << 2),
534 read_nic_dword(priv->net_dev, addr, val);
536 *len = IPW_ORD_TAB_1_ENTRY_SIZE;
541 if (IS_ORDINAL_TABLE_TWO(ordinals, ord)) {
543 ord -= IPW_START_ORD_TAB_2;
545 /* get the address of statistic */
546 read_nic_dword(priv->net_dev, ordinals->table2_addr + (ord << 3),
549 /* get the second DW of statistics ;
550 * two 16-bit words - first is length, second is count */
551 read_nic_dword(priv->net_dev,
552 ordinals->table2_addr + (ord << 3) + sizeof(u32),
555 /* get each entry length */
556 field_len = *((u16 *)&field_info);
558 /* get number of entries */
559 field_count = *(((u16 *)&field_info) + 1);
561 /* abort if no enought memory */
562 total_length = field_len * field_count;
563 if (total_length > *len) {
572 /* read the ordinal data from the SRAM */
573 read_nic_memory(priv->net_dev, addr, total_length, val);
578 printk(KERN_WARNING DRV_NAME ": ordinal %d neither in table 1 nor "
579 "in table 2\n", ord);
584 static int ipw2100_set_ordinal(struct ipw2100_priv *priv, u32 ord, u32 *val,
587 struct ipw2100_ordinals *ordinals = &priv->ordinals;
590 if (IS_ORDINAL_TABLE_ONE(ordinals, ord)) {
591 if (*len != IPW_ORD_TAB_1_ENTRY_SIZE) {
592 *len = IPW_ORD_TAB_1_ENTRY_SIZE;
593 IPW_DEBUG_INFO("wrong size\n");
597 read_nic_dword(priv->net_dev, ordinals->table1_addr + (ord << 2),
600 write_nic_dword(priv->net_dev, addr, *val);
602 *len = IPW_ORD_TAB_1_ENTRY_SIZE;
607 IPW_DEBUG_INFO("wrong table\n");
608 if (IS_ORDINAL_TABLE_TWO(ordinals, ord))
614 static char *snprint_line(char *buf, size_t count,
615 const u8 *data, u32 len, u32 ofs)
620 out = snprintf(buf, count, "%08X", ofs);
622 for (l = 0, i = 0; i < 2; i++) {
623 out += snprintf(buf + out, count - out, " ");
624 for (j = 0; j < 8 && l < len; j++, l++)
625 out += snprintf(buf + out, count - out, "%02X ",
628 out += snprintf(buf + out, count - out, " ");
631 out += snprintf(buf + out, count - out, " ");
632 for (l = 0, i = 0; i < 2; i++) {
633 out += snprintf(buf + out, count - out, " ");
634 for (j = 0; j < 8 && l < len; j++, l++) {
635 c = data[(i * 8 + j)];
636 if (!isascii(c) || !isprint(c))
639 out += snprintf(buf + out, count - out, "%c", c);
643 out += snprintf(buf + out, count - out, " ");
649 static void printk_buf(int level, const u8 *data, u32 len)
653 if (!(ipw2100_debug_level & level))
657 printk(KERN_DEBUG "%s\n",
658 snprint_line(line, sizeof(line), &data[ofs],
659 min(len, 16U), ofs));
661 len -= min(len, 16U);
667 #define MAX_RESET_BACKOFF 10
669 static inline void schedule_reset(struct ipw2100_priv *priv)
671 unsigned long now = get_seconds();
673 /* If we haven't received a reset request within the backoff period,
674 * then we can reset the backoff interval so this reset occurs
676 if (priv->reset_backoff &&
677 (now - priv->last_reset > priv->reset_backoff))
678 priv->reset_backoff = 0;
680 priv->last_reset = get_seconds();
682 if (!(priv->status & STATUS_RESET_PENDING)) {
683 IPW_DEBUG_INFO("%s: Scheduling firmware restart (%ds).\n",
684 priv->net_dev->name, priv->reset_backoff);
685 netif_carrier_off(priv->net_dev);
686 netif_stop_queue(priv->net_dev);
687 priv->status |= STATUS_RESET_PENDING;
688 if (priv->reset_backoff)
689 queue_delayed_work(priv->workqueue, &priv->reset_work,
690 priv->reset_backoff * HZ);
692 queue_work(priv->workqueue, &priv->reset_work);
694 if (priv->reset_backoff < MAX_RESET_BACKOFF)
695 priv->reset_backoff++;
697 wake_up_interruptible(&priv->wait_command_queue);
699 IPW_DEBUG_INFO("%s: Firmware restart already in progress.\n",
700 priv->net_dev->name);
704 #define HOST_COMPLETE_TIMEOUT (2 * HZ)
705 static int ipw2100_hw_send_command(struct ipw2100_priv *priv,
706 struct host_command * cmd)
708 struct list_head *element;
709 struct ipw2100_tx_packet *packet;
713 IPW_DEBUG_HC("Sending %s command (#%d), %d bytes\n",
714 command_types[cmd->host_command], cmd->host_command,
715 cmd->host_command_length);
716 printk_buf(IPW_DL_HC, (u8*)cmd->host_command_parameters,
717 cmd->host_command_length);
719 spin_lock_irqsave(&priv->low_lock, flags);
721 if (priv->fatal_error) {
722 IPW_DEBUG_INFO("Attempt to send command while hardware in fatal error condition.\n");
727 if (!(priv->status & STATUS_RUNNING)) {
728 IPW_DEBUG_INFO("Attempt to send command while hardware is not running.\n");
733 if (priv->status & STATUS_CMD_ACTIVE) {
734 IPW_DEBUG_INFO("Attempt to send command while another command is pending.\n");
739 if (list_empty(&priv->msg_free_list)) {
740 IPW_DEBUG_INFO("no available msg buffers\n");
744 priv->status |= STATUS_CMD_ACTIVE;
745 priv->messages_sent++;
747 element = priv->msg_free_list.next;
749 packet = list_entry(element, struct ipw2100_tx_packet, list);
750 packet->jiffy_start = jiffies;
752 /* initialize the firmware command packet */
753 packet->info.c_struct.cmd->host_command_reg = cmd->host_command;
754 packet->info.c_struct.cmd->host_command_reg1 = cmd->host_command1;
755 packet->info.c_struct.cmd->host_command_len_reg = cmd->host_command_length;
756 packet->info.c_struct.cmd->sequence = cmd->host_command_sequence;
758 memcpy(packet->info.c_struct.cmd->host_command_params_reg,
759 cmd->host_command_parameters,
760 sizeof(packet->info.c_struct.cmd->host_command_params_reg));
763 DEC_STAT(&priv->msg_free_stat);
765 list_add_tail(element, &priv->msg_pend_list);
766 INC_STAT(&priv->msg_pend_stat);
768 ipw2100_tx_send_commands(priv);
769 ipw2100_tx_send_data(priv);
771 spin_unlock_irqrestore(&priv->low_lock, flags);
774 * We must wait for this command to complete before another
775 * command can be sent... but if we wait more than 3 seconds
776 * then there is a problem.
779 err = wait_event_interruptible_timeout(
780 priv->wait_command_queue, !(priv->status & STATUS_CMD_ACTIVE),
781 HOST_COMPLETE_TIMEOUT);
784 IPW_DEBUG_INFO("Command completion failed out after %dms.\n",
785 HOST_COMPLETE_TIMEOUT / (HZ / 100));
786 priv->fatal_error = IPW2100_ERR_MSG_TIMEOUT;
787 priv->status &= ~STATUS_CMD_ACTIVE;
788 schedule_reset(priv);
792 if (priv->fatal_error) {
793 printk(KERN_WARNING DRV_NAME ": %s: firmware fatal error\n",
794 priv->net_dev->name);
798 /* !!!!! HACK TEST !!!!!
799 * When lots of debug trace statements are enabled, the driver
800 * doesn't seem to have as many firmware restart cycles...
802 * As a test, we're sticking in a 1/100s delay here */
803 schedule_timeout_uninterruptible(msecs_to_jiffies(10));
808 spin_unlock_irqrestore(&priv->low_lock, flags);
815 * Verify the values and data access of the hardware
816 * No locks needed or used. No functions called.
818 static int ipw2100_verify(struct ipw2100_priv *priv)
823 u32 val1 = 0x76543210;
824 u32 val2 = 0xFEDCBA98;
826 /* Domain 0 check - all values should be DOA_DEBUG */
827 for (address = IPW_REG_DOA_DEBUG_AREA_START;
828 address < IPW_REG_DOA_DEBUG_AREA_END;
829 address += sizeof(u32)) {
830 read_register(priv->net_dev, address, &data1);
831 if (data1 != IPW_DATA_DOA_DEBUG_VALUE)
835 /* Domain 1 check - use arbitrary read/write compare */
836 for (address = 0; address < 5; address++) {
837 /* The memory area is not used now */
838 write_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x32,
840 write_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x36,
842 read_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x32,
844 read_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x36,
846 if (val1 == data1 && val2 == data2)
855 * Loop until the CARD_DISABLED bit is the same value as the
858 * TODO: See if it would be more efficient to do a wait/wake
859 * cycle and have the completion event trigger the wakeup
862 #define IPW_CARD_DISABLE_COMPLETE_WAIT 100 // 100 milli
863 static int ipw2100_wait_for_card_state(struct ipw2100_priv *priv, int state)
867 u32 len = sizeof(card_state);
870 for (i = 0; i <= IPW_CARD_DISABLE_COMPLETE_WAIT * 1000; i += 50) {
871 err = ipw2100_get_ordinal(priv, IPW_ORD_CARD_DISABLED,
874 IPW_DEBUG_INFO("Query of CARD_DISABLED ordinal "
879 /* We'll break out if either the HW state says it is
880 * in the state we want, or if HOST_COMPLETE command
882 if ((card_state == state) ||
883 ((priv->status & STATUS_ENABLED) ?
884 IPW_HW_STATE_ENABLED : IPW_HW_STATE_DISABLED) == state) {
885 if (state == IPW_HW_STATE_ENABLED)
886 priv->status |= STATUS_ENABLED;
888 priv->status &= ~STATUS_ENABLED;
896 IPW_DEBUG_INFO("ipw2100_wait_for_card_state to %s state timed out\n",
897 state ? "DISABLED" : "ENABLED");
902 /*********************************************************************
903 Procedure : sw_reset_and_clock
904 Purpose : Asserts s/w reset, asserts clock initialization
905 and waits for clock stabilization
906 ********************************************************************/
907 static int sw_reset_and_clock(struct ipw2100_priv *priv)
913 write_register(priv->net_dev, IPW_REG_RESET_REG,
914 IPW_AUX_HOST_RESET_REG_SW_RESET);
916 // wait for clock stabilization
917 for (i = 0; i < 1000; i++) {
918 udelay(IPW_WAIT_RESET_ARC_COMPLETE_DELAY);
920 // check clock ready bit
921 read_register(priv->net_dev, IPW_REG_RESET_REG, &r);
922 if (r & IPW_AUX_HOST_RESET_REG_PRINCETON_RESET)
927 return -EIO; // TODO: better error value
929 /* set "initialization complete" bit to move adapter to
931 write_register(priv->net_dev, IPW_REG_GP_CNTRL,
932 IPW_AUX_HOST_GP_CNTRL_BIT_INIT_DONE);
934 /* wait for clock stabilization */
935 for (i = 0; i < 10000; i++) {
936 udelay(IPW_WAIT_CLOCK_STABILIZATION_DELAY * 4);
938 /* check clock ready bit */
939 read_register(priv->net_dev, IPW_REG_GP_CNTRL, &r);
940 if (r & IPW_AUX_HOST_GP_CNTRL_BIT_CLOCK_READY)
945 return -EIO; /* TODO: better error value */
947 /* set D0 standby bit */
948 read_register(priv->net_dev, IPW_REG_GP_CNTRL, &r);
949 write_register(priv->net_dev, IPW_REG_GP_CNTRL,
950 r | IPW_AUX_HOST_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
955 /*********************************************************************
956 Procedure : ipw2100_download_firmware
957 Purpose : Initiaze adapter after power on.
959 1. assert s/w reset first!
960 2. awake clocks & wait for clock stabilization
961 3. hold ARC (don't ask me why...)
962 4. load Dino ucode and reset/clock init again
963 5. zero-out shared mem
965 *******************************************************************/
966 static int ipw2100_download_firmware(struct ipw2100_priv *priv)
972 /* Fetch the firmware and microcode */
973 struct ipw2100_fw ipw2100_firmware;
976 if (priv->fatal_error) {
977 IPW_DEBUG_ERROR("%s: ipw2100_download_firmware called after "
978 "fatal error %d. Interface must be brought down.\n",
979 priv->net_dev->name, priv->fatal_error);
984 if (!ipw2100_firmware.version) {
985 err = ipw2100_get_firmware(priv, &ipw2100_firmware);
987 IPW_DEBUG_ERROR("%s: ipw2100_get_firmware failed: %d\n",
988 priv->net_dev->name, err);
989 priv->fatal_error = IPW2100_ERR_FW_LOAD;
994 err = ipw2100_get_firmware(priv, &ipw2100_firmware);
996 IPW_DEBUG_ERROR("%s: ipw2100_get_firmware failed: %d\n",
997 priv->net_dev->name, err);
998 priv->fatal_error = IPW2100_ERR_FW_LOAD;
1002 priv->firmware_version = ipw2100_firmware.version;
1004 /* s/w reset and clock stabilization */
1005 err = sw_reset_and_clock(priv);
1007 IPW_DEBUG_ERROR("%s: sw_reset_and_clock failed: %d\n",
1008 priv->net_dev->name, err);
1012 err = ipw2100_verify(priv);
1014 IPW_DEBUG_ERROR("%s: ipw2100_verify failed: %d\n",
1015 priv->net_dev->name, err);
1020 write_nic_dword(priv->net_dev,
1021 IPW_INTERNAL_REGISTER_HALT_AND_RESET,
1024 /* allow ARC to run */
1025 write_register(priv->net_dev, IPW_REG_RESET_REG, 0);
1027 /* load microcode */
1028 err = ipw2100_ucode_download(priv, &ipw2100_firmware);
1030 printk(KERN_ERR DRV_NAME ": %s: Error loading microcode: %d\n",
1031 priv->net_dev->name, err);
1036 write_nic_dword(priv->net_dev,
1037 IPW_INTERNAL_REGISTER_HALT_AND_RESET,
1040 /* s/w reset and clock stabilization (again!!!) */
1041 err = sw_reset_and_clock(priv);
1043 printk(KERN_ERR DRV_NAME ": %s: sw_reset_and_clock failed: %d\n",
1044 priv->net_dev->name, err);
1049 err = ipw2100_fw_download(priv, &ipw2100_firmware);
1051 IPW_DEBUG_ERROR("%s: Error loading firmware: %d\n",
1052 priv->net_dev->name, err);
1058 * When the .resume method of the driver is called, the other
1059 * part of the system, i.e. the ide driver could still stay in
1060 * the suspend stage. This prevents us from loading the firmware
1061 * from the disk. --YZ
1064 /* free any storage allocated for firmware image */
1065 ipw2100_release_firmware(priv, &ipw2100_firmware);
1068 /* zero out Domain 1 area indirectly (Si requirement) */
1069 for (address = IPW_HOST_FW_SHARED_AREA0;
1070 address < IPW_HOST_FW_SHARED_AREA0_END; address += 4)
1071 write_nic_dword(priv->net_dev, address, 0);
1072 for (address = IPW_HOST_FW_SHARED_AREA1;
1073 address < IPW_HOST_FW_SHARED_AREA1_END; address += 4)
1074 write_nic_dword(priv->net_dev, address, 0);
1075 for (address = IPW_HOST_FW_SHARED_AREA2;
1076 address < IPW_HOST_FW_SHARED_AREA2_END; address += 4)
1077 write_nic_dword(priv->net_dev, address, 0);
1078 for (address = IPW_HOST_FW_SHARED_AREA3;
1079 address < IPW_HOST_FW_SHARED_AREA3_END; address += 4)
1080 write_nic_dword(priv->net_dev, address, 0);
1081 for (address = IPW_HOST_FW_INTERRUPT_AREA;
1082 address < IPW_HOST_FW_INTERRUPT_AREA_END; address += 4)
1083 write_nic_dword(priv->net_dev, address, 0);
1088 ipw2100_release_firmware(priv, &ipw2100_firmware);
1092 static inline void ipw2100_enable_interrupts(struct ipw2100_priv *priv)
1094 if (priv->status & STATUS_INT_ENABLED)
1096 priv->status |= STATUS_INT_ENABLED;
1097 write_register(priv->net_dev, IPW_REG_INTA_MASK, IPW_INTERRUPT_MASK);
1100 static inline void ipw2100_disable_interrupts(struct ipw2100_priv *priv)
1102 if (!(priv->status & STATUS_INT_ENABLED))
1104 priv->status &= ~STATUS_INT_ENABLED;
1105 write_register(priv->net_dev, IPW_REG_INTA_MASK, 0x0);
1109 static void ipw2100_initialize_ordinals(struct ipw2100_priv *priv)
1111 struct ipw2100_ordinals *ord = &priv->ordinals;
1113 IPW_DEBUG_INFO("enter\n");
1115 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_ORDINALS_TABLE_1,
1118 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_ORDINALS_TABLE_2,
1121 read_nic_dword(priv->net_dev, ord->table1_addr, &ord->table1_size);
1122 read_nic_dword(priv->net_dev, ord->table2_addr, &ord->table2_size);
1124 ord->table2_size &= 0x0000FFFF;
1126 IPW_DEBUG_INFO("table 1 size: %d\n", ord->table1_size);
1127 IPW_DEBUG_INFO("table 2 size: %d\n", ord->table2_size);
1128 IPW_DEBUG_INFO("exit\n");
1131 static inline void ipw2100_hw_set_gpio(struct ipw2100_priv *priv)
1135 * Set GPIO 3 writable by FW; GPIO 1 writable
1136 * by driver and enable clock
1138 reg = (IPW_BIT_GPIO_GPIO3_MASK | IPW_BIT_GPIO_GPIO1_ENABLE |
1139 IPW_BIT_GPIO_LED_OFF);
1140 write_register(priv->net_dev, IPW_REG_GPIO, reg);
1143 static inline int rf_kill_active(struct ipw2100_priv *priv)
1145 #define MAX_RF_KILL_CHECKS 5
1146 #define RF_KILL_CHECK_DELAY 40
1148 unsigned short value = 0;
1152 if (!(priv->hw_features & HW_FEATURE_RFKILL)) {
1153 priv->status &= ~STATUS_RF_KILL_HW;
1157 for (i = 0; i < MAX_RF_KILL_CHECKS; i++) {
1158 udelay(RF_KILL_CHECK_DELAY);
1159 read_register(priv->net_dev, IPW_REG_GPIO, ®);
1160 value = (value << 1) | ((reg & IPW_BIT_GPIO_RF_KILL) ? 0 : 1);
1164 priv->status |= STATUS_RF_KILL_HW;
1166 priv->status &= ~STATUS_RF_KILL_HW;
1168 return (value == 0);
1171 static int ipw2100_get_hw_features(struct ipw2100_priv *priv)
1177 * EEPROM_SRAM_DB_START_ADDRESS using ordinal in ordinal table 1
1180 if (ipw2100_get_ordinal(
1181 priv, IPW_ORD_EEPROM_SRAM_DB_BLOCK_START_ADDRESS,
1183 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
1188 IPW_DEBUG_INFO("EEPROM address: %08X\n", addr);
1191 * EEPROM version is the byte at offset 0xfd in firmware
1192 * We read 4 bytes, then shift out the byte we actually want */
1193 read_nic_dword(priv->net_dev, addr + 0xFC, &val);
1194 priv->eeprom_version = (val >> 24) & 0xFF;
1195 IPW_DEBUG_INFO("EEPROM version: %d\n", priv->eeprom_version);
1198 * HW RF Kill enable is bit 0 in byte at offset 0x21 in firmware
1200 * notice that the EEPROM bit is reverse polarity, i.e.
1201 * bit = 0 signifies HW RF kill switch is supported
1202 * bit = 1 signifies HW RF kill switch is NOT supported
1204 read_nic_dword(priv->net_dev, addr + 0x20, &val);
1205 if (!((val >> 24) & 0x01))
1206 priv->hw_features |= HW_FEATURE_RFKILL;
1208 IPW_DEBUG_INFO("HW RF Kill: %ssupported.\n",
1209 (priv->hw_features & HW_FEATURE_RFKILL) ?
1216 * Start firmware execution after power on and intialization
1219 * 2. Wait for f/w initialization completes;
1221 static int ipw2100_start_adapter(struct ipw2100_priv *priv)
1224 u32 inta, inta_mask, gpio;
1226 IPW_DEBUG_INFO("enter\n");
1228 if (priv->status & STATUS_RUNNING)
1232 * Initialize the hw - drive adapter to DO state by setting
1233 * init_done bit. Wait for clk_ready bit and Download
1236 if (ipw2100_download_firmware(priv)) {
1237 printk(KERN_ERR DRV_NAME ": %s: Failed to power on the adapter.\n",
1238 priv->net_dev->name);
1242 /* Clear the Tx, Rx and Msg queues and the r/w indexes
1243 * in the firmware RBD and TBD ring queue */
1244 ipw2100_queues_initialize(priv);
1246 ipw2100_hw_set_gpio(priv);
1248 /* TODO -- Look at disabling interrupts here to make sure none
1249 * get fired during FW initialization */
1251 /* Release ARC - clear reset bit */
1252 write_register(priv->net_dev, IPW_REG_RESET_REG, 0);
1254 /* wait for f/w intialization complete */
1255 IPW_DEBUG_FW("Waiting for f/w initialization to complete...\n");
1258 schedule_timeout_uninterruptible(msecs_to_jiffies(40));
1259 /* Todo... wait for sync command ... */
1261 read_register(priv->net_dev, IPW_REG_INTA, &inta);
1263 /* check "init done" bit */
1264 if (inta & IPW2100_INTA_FW_INIT_DONE) {
1265 /* reset "init done" bit */
1266 write_register(priv->net_dev, IPW_REG_INTA,
1267 IPW2100_INTA_FW_INIT_DONE);
1271 /* check error conditions : we check these after the firmware
1272 * check so that if there is an error, the interrupt handler
1273 * will see it and the adapter will be reset */
1275 (IPW2100_INTA_FATAL_ERROR | IPW2100_INTA_PARITY_ERROR)) {
1276 /* clear error conditions */
1277 write_register(priv->net_dev, IPW_REG_INTA,
1278 IPW2100_INTA_FATAL_ERROR |
1279 IPW2100_INTA_PARITY_ERROR);
1283 /* Clear out any pending INTAs since we aren't supposed to have
1284 * interrupts enabled at this point... */
1285 read_register(priv->net_dev, IPW_REG_INTA, &inta);
1286 read_register(priv->net_dev, IPW_REG_INTA_MASK, &inta_mask);
1287 inta &= IPW_INTERRUPT_MASK;
1288 /* Clear out any pending interrupts */
1289 if (inta & inta_mask)
1290 write_register(priv->net_dev, IPW_REG_INTA, inta);
1292 IPW_DEBUG_FW("f/w initialization complete: %s\n",
1293 i ? "SUCCESS" : "FAILED");
1296 printk(KERN_WARNING DRV_NAME ": %s: Firmware did not initialize.\n",
1297 priv->net_dev->name);
1301 /* allow firmware to write to GPIO1 & GPIO3 */
1302 read_register(priv->net_dev, IPW_REG_GPIO, &gpio);
1304 gpio |= (IPW_BIT_GPIO_GPIO1_MASK | IPW_BIT_GPIO_GPIO3_MASK);
1306 write_register(priv->net_dev, IPW_REG_GPIO, gpio);
1308 /* Ready to receive commands */
1309 priv->status |= STATUS_RUNNING;
1311 /* The adapter has been reset; we are not associated */
1312 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
1314 IPW_DEBUG_INFO("exit\n");
1319 static inline void ipw2100_reset_fatalerror(struct ipw2100_priv *priv)
1321 if (!priv->fatal_error)
1324 priv->fatal_errors[priv->fatal_index++] = priv->fatal_error;
1325 priv->fatal_index %= IPW2100_ERROR_QUEUE;
1326 priv->fatal_error = 0;
1330 /* NOTE: Our interrupt is disabled when this method is called */
1331 static int ipw2100_power_cycle_adapter(struct ipw2100_priv *priv)
1336 IPW_DEBUG_INFO("Power cycling the hardware.\n");
1338 ipw2100_hw_set_gpio(priv);
1340 /* Step 1. Stop Master Assert */
1341 write_register(priv->net_dev, IPW_REG_RESET_REG,
1342 IPW_AUX_HOST_RESET_REG_STOP_MASTER);
1344 /* Step 2. Wait for stop Master Assert
1345 * (not more then 50us, otherwise ret error */
1348 udelay(IPW_WAIT_RESET_MASTER_ASSERT_COMPLETE_DELAY);
1349 read_register(priv->net_dev, IPW_REG_RESET_REG, ®);
1351 if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED)
1355 priv->status &= ~STATUS_RESET_PENDING;
1358 IPW_DEBUG_INFO("exit - waited too long for master assert stop\n");
1362 write_register(priv->net_dev, IPW_REG_RESET_REG,
1363 IPW_AUX_HOST_RESET_REG_SW_RESET);
1366 /* Reset any fatal_error conditions */
1367 ipw2100_reset_fatalerror(priv);
1369 /* At this point, the adapter is now stopped and disabled */
1370 priv->status &= ~(STATUS_RUNNING | STATUS_ASSOCIATING |
1371 STATUS_ASSOCIATED | STATUS_ENABLED);
1377 * Send the CARD_DISABLE_PHY_OFF comamnd to the card to disable it
1379 * After disabling, if the card was associated, a STATUS_ASSN_LOST will be sent.
1381 * STATUS_CARD_DISABLE_NOTIFICATION will be sent regardless of
1382 * if STATUS_ASSN_LOST is sent.
1384 static int ipw2100_hw_phy_off(struct ipw2100_priv *priv)
1387 #define HW_PHY_OFF_LOOP_DELAY (HZ / 5000)
1389 struct host_command cmd = {
1390 .host_command = CARD_DISABLE_PHY_OFF,
1391 .host_command_sequence = 0,
1392 .host_command_length = 0,
1397 IPW_DEBUG_HC("CARD_DISABLE_PHY_OFF\n");
1399 /* Turn off the radio */
1400 err = ipw2100_hw_send_command(priv, &cmd);
1404 for (i = 0; i < 2500; i++) {
1405 read_nic_dword(priv->net_dev, IPW2100_CONTROL_REG, &val1);
1406 read_nic_dword(priv->net_dev, IPW2100_COMMAND, &val2);
1408 if ((val1 & IPW2100_CONTROL_PHY_OFF) &&
1409 (val2 & IPW2100_COMMAND_PHY_OFF))
1412 schedule_timeout_uninterruptible(HW_PHY_OFF_LOOP_DELAY);
1419 static int ipw2100_enable_adapter(struct ipw2100_priv *priv)
1421 struct host_command cmd = {
1422 .host_command = HOST_COMPLETE,
1423 .host_command_sequence = 0,
1424 .host_command_length = 0
1428 IPW_DEBUG_HC("HOST_COMPLETE\n");
1430 if (priv->status & STATUS_ENABLED)
1433 down(&priv->adapter_sem);
1435 if (rf_kill_active(priv)) {
1436 IPW_DEBUG_HC("Command aborted due to RF kill active.\n");
1440 err = ipw2100_hw_send_command(priv, &cmd);
1442 IPW_DEBUG_INFO("Failed to send HOST_COMPLETE command\n");
1446 err = ipw2100_wait_for_card_state(priv, IPW_HW_STATE_ENABLED);
1449 "%s: card not responding to init command.\n",
1450 priv->net_dev->name);
1454 if (priv->stop_hang_check) {
1455 priv->stop_hang_check = 0;
1456 queue_delayed_work(priv->workqueue, &priv->hang_check, HZ / 2);
1460 up(&priv->adapter_sem);
1464 static int ipw2100_hw_stop_adapter(struct ipw2100_priv *priv)
1466 #define HW_POWER_DOWN_DELAY (msecs_to_jiffies(100))
1468 struct host_command cmd = {
1469 .host_command = HOST_PRE_POWER_DOWN,
1470 .host_command_sequence = 0,
1471 .host_command_length = 0,
1476 if (!(priv->status & STATUS_RUNNING))
1479 priv->status |= STATUS_STOPPING;
1481 /* We can only shut down the card if the firmware is operational. So,
1482 * if we haven't reset since a fatal_error, then we can not send the
1483 * shutdown commands. */
1484 if (!priv->fatal_error) {
1485 /* First, make sure the adapter is enabled so that the PHY_OFF
1486 * command can shut it down */
1487 ipw2100_enable_adapter(priv);
1489 err = ipw2100_hw_phy_off(priv);
1491 printk(KERN_WARNING DRV_NAME ": Error disabling radio %d\n", err);
1494 * If in D0-standby mode going directly to D3 may cause a
1495 * PCI bus violation. Therefore we must change out of the D0
1498 * Sending the PREPARE_FOR_POWER_DOWN will restrict the
1499 * hardware from going into standby mode and will transition
1500 * out of D0-standy if it is already in that state.
1502 * STATUS_PREPARE_POWER_DOWN_COMPLETE will be sent by the
1503 * driver upon completion. Once received, the driver can
1504 * proceed to the D3 state.
1506 * Prepare for power down command to fw. This command would
1507 * take HW out of D0-standby and prepare it for D3 state.
1509 * Currently FW does not support event notification for this
1510 * event. Therefore, skip waiting for it. Just wait a fixed
1513 IPW_DEBUG_HC("HOST_PRE_POWER_DOWN\n");
1515 err = ipw2100_hw_send_command(priv, &cmd);
1517 printk(KERN_WARNING DRV_NAME ": "
1518 "%s: Power down command failed: Error %d\n",
1519 priv->net_dev->name, err);
1521 schedule_timeout_uninterruptible(HW_POWER_DOWN_DELAY);
1524 priv->status &= ~STATUS_ENABLED;
1527 * Set GPIO 3 writable by FW; GPIO 1 writable
1528 * by driver and enable clock
1530 ipw2100_hw_set_gpio(priv);
1533 * Power down adapter. Sequence:
1534 * 1. Stop master assert (RESET_REG[9]=1)
1535 * 2. Wait for stop master (RESET_REG[8]==1)
1536 * 3. S/w reset assert (RESET_REG[7] = 1)
1539 /* Stop master assert */
1540 write_register(priv->net_dev, IPW_REG_RESET_REG,
1541 IPW_AUX_HOST_RESET_REG_STOP_MASTER);
1543 /* wait stop master not more than 50 usec.
1544 * Otherwise return error. */
1545 for (i = 5; i > 0; i--) {
1548 /* Check master stop bit */
1549 read_register(priv->net_dev, IPW_REG_RESET_REG, ®);
1551 if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED)
1556 printk(KERN_WARNING DRV_NAME
1557 ": %s: Could now power down adapter.\n",
1558 priv->net_dev->name);
1560 /* assert s/w reset */
1561 write_register(priv->net_dev, IPW_REG_RESET_REG,
1562 IPW_AUX_HOST_RESET_REG_SW_RESET);
1564 priv->status &= ~(STATUS_RUNNING | STATUS_STOPPING);
1570 static int ipw2100_disable_adapter(struct ipw2100_priv *priv)
1572 struct host_command cmd = {
1573 .host_command = CARD_DISABLE,
1574 .host_command_sequence = 0,
1575 .host_command_length = 0
1579 IPW_DEBUG_HC("CARD_DISABLE\n");
1581 if (!(priv->status & STATUS_ENABLED))
1584 /* Make sure we clear the associated state */
1585 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1587 if (!priv->stop_hang_check) {
1588 priv->stop_hang_check = 1;
1589 cancel_delayed_work(&priv->hang_check);
1592 down(&priv->adapter_sem);
1594 err = ipw2100_hw_send_command(priv, &cmd);
1596 printk(KERN_WARNING DRV_NAME ": exit - failed to send CARD_DISABLE command\n");
1600 err = ipw2100_wait_for_card_state(priv, IPW_HW_STATE_DISABLED);
1602 printk(KERN_WARNING DRV_NAME ": exit - card failed to change to DISABLED\n");
1606 IPW_DEBUG_INFO("TODO: implement scan state machine\n");
1609 up(&priv->adapter_sem);
1613 static int ipw2100_set_scan_options(struct ipw2100_priv *priv)
1615 struct host_command cmd = {
1616 .host_command = SET_SCAN_OPTIONS,
1617 .host_command_sequence = 0,
1618 .host_command_length = 8
1622 IPW_DEBUG_INFO("enter\n");
1624 IPW_DEBUG_SCAN("setting scan options\n");
1626 cmd.host_command_parameters[0] = 0;
1628 if (!(priv->config & CFG_ASSOCIATE))
1629 cmd.host_command_parameters[0] |= IPW_SCAN_NOASSOCIATE;
1630 if ((priv->sec.flags & SEC_ENABLED) && priv->sec.enabled)
1631 cmd.host_command_parameters[0] |= IPW_SCAN_MIXED_CELL;
1632 if (priv->config & CFG_PASSIVE_SCAN)
1633 cmd.host_command_parameters[0] |= IPW_SCAN_PASSIVE;
1635 cmd.host_command_parameters[1] = priv->channel_mask;
1637 err = ipw2100_hw_send_command(priv, &cmd);
1639 IPW_DEBUG_HC("SET_SCAN_OPTIONS 0x%04X\n",
1640 cmd.host_command_parameters[0]);
1645 static int ipw2100_start_scan(struct ipw2100_priv *priv)
1647 struct host_command cmd = {
1648 .host_command = BROADCAST_SCAN,
1649 .host_command_sequence = 0,
1650 .host_command_length = 4
1654 IPW_DEBUG_HC("START_SCAN\n");
1656 cmd.host_command_parameters[0] = 0;
1658 /* No scanning if in monitor mode */
1659 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
1662 if (priv->status & STATUS_SCANNING) {
1663 IPW_DEBUG_SCAN("Scan requested while already in scan...\n");
1667 IPW_DEBUG_INFO("enter\n");
1669 /* Not clearing here; doing so makes iwlist always return nothing...
1671 * We should modify the table logic to use aging tables vs. clearing
1672 * the table on each scan start.
1674 IPW_DEBUG_SCAN("starting scan\n");
1676 priv->status |= STATUS_SCANNING;
1677 err = ipw2100_hw_send_command(priv, &cmd);
1679 priv->status &= ~STATUS_SCANNING;
1681 IPW_DEBUG_INFO("exit\n");
1686 static int ipw2100_up(struct ipw2100_priv *priv, int deferred)
1688 unsigned long flags;
1691 u32 ord_len = sizeof(lock);
1693 /* Quite if manually disabled. */
1694 if (priv->status & STATUS_RF_KILL_SW) {
1695 IPW_DEBUG_INFO("%s: Radio is disabled by Manual Disable "
1696 "switch\n", priv->net_dev->name);
1700 /* If the interrupt is enabled, turn it off... */
1701 spin_lock_irqsave(&priv->low_lock, flags);
1702 ipw2100_disable_interrupts(priv);
1704 /* Reset any fatal_error conditions */
1705 ipw2100_reset_fatalerror(priv);
1706 spin_unlock_irqrestore(&priv->low_lock, flags);
1708 if (priv->status & STATUS_POWERED ||
1709 (priv->status & STATUS_RESET_PENDING)) {
1710 /* Power cycle the card ... */
1711 if (ipw2100_power_cycle_adapter(priv)) {
1712 printk(KERN_WARNING DRV_NAME ": %s: Could not cycle adapter.\n",
1713 priv->net_dev->name);
1718 priv->status |= STATUS_POWERED;
1720 /* Load the firmware, start the clocks, etc. */
1721 if (ipw2100_start_adapter(priv)) {
1722 printk(KERN_ERR DRV_NAME ": %s: Failed to start the firmware.\n",
1723 priv->net_dev->name);
1728 ipw2100_initialize_ordinals(priv);
1730 /* Determine capabilities of this particular HW configuration */
1731 if (ipw2100_get_hw_features(priv)) {
1732 printk(KERN_ERR DRV_NAME ": %s: Failed to determine HW features.\n",
1733 priv->net_dev->name);
1739 if (ipw2100_set_ordinal(priv, IPW_ORD_PERS_DB_LOCK, &lock, &ord_len)) {
1740 printk(KERN_ERR DRV_NAME ": %s: Failed to clear ordinal lock.\n",
1741 priv->net_dev->name);
1746 priv->status &= ~STATUS_SCANNING;
1748 if (rf_kill_active(priv)) {
1749 printk(KERN_INFO "%s: Radio is disabled by RF switch.\n",
1750 priv->net_dev->name);
1752 if (priv->stop_rf_kill) {
1753 priv->stop_rf_kill = 0;
1754 queue_delayed_work(priv->workqueue, &priv->rf_kill, HZ);
1760 /* Turn on the interrupt so that commands can be processed */
1761 ipw2100_enable_interrupts(priv);
1763 /* Send all of the commands that must be sent prior to
1765 if (ipw2100_adapter_setup(priv)) {
1766 printk(KERN_ERR DRV_NAME ": %s: Failed to start the card.\n",
1767 priv->net_dev->name);
1773 /* Enable the adapter - sends HOST_COMPLETE */
1774 if (ipw2100_enable_adapter(priv)) {
1775 printk(KERN_ERR DRV_NAME ": "
1776 "%s: failed in call to enable adapter.\n",
1777 priv->net_dev->name);
1778 ipw2100_hw_stop_adapter(priv);
1784 /* Start a scan . . . */
1785 ipw2100_set_scan_options(priv);
1786 ipw2100_start_scan(priv);
1793 /* Called by register_netdev() */
1794 static int ipw2100_net_init(struct net_device *dev)
1796 struct ipw2100_priv *priv = ieee80211_priv(dev);
1797 return ipw2100_up(priv, 1);
1800 static void ipw2100_down(struct ipw2100_priv *priv)
1802 unsigned long flags;
1803 union iwreq_data wrqu = {
1805 .sa_family = ARPHRD_ETHER
1808 int associated = priv->status & STATUS_ASSOCIATED;
1810 /* Kill the RF switch timer */
1811 if (!priv->stop_rf_kill) {
1812 priv->stop_rf_kill = 1;
1813 cancel_delayed_work(&priv->rf_kill);
1816 /* Kill the firmare hang check timer */
1817 if (!priv->stop_hang_check) {
1818 priv->stop_hang_check = 1;
1819 cancel_delayed_work(&priv->hang_check);
1822 /* Kill any pending resets */
1823 if (priv->status & STATUS_RESET_PENDING)
1824 cancel_delayed_work(&priv->reset_work);
1826 /* Make sure the interrupt is on so that FW commands will be
1827 * processed correctly */
1828 spin_lock_irqsave(&priv->low_lock, flags);
1829 ipw2100_enable_interrupts(priv);
1830 spin_unlock_irqrestore(&priv->low_lock, flags);
1832 if (ipw2100_hw_stop_adapter(priv))
1833 printk(KERN_ERR DRV_NAME ": %s: Error stopping adapter.\n",
1834 priv->net_dev->name);
1836 /* Do not disable the interrupt until _after_ we disable
1837 * the adaptor. Otherwise the CARD_DISABLE command will never
1838 * be ack'd by the firmware */
1839 spin_lock_irqsave(&priv->low_lock, flags);
1840 ipw2100_disable_interrupts(priv);
1841 spin_unlock_irqrestore(&priv->low_lock, flags);
1843 #ifdef ACPI_CSTATE_LIMIT_DEFINED
1844 if (priv->config & CFG_C3_DISABLED) {
1845 IPW_DEBUG_INFO(DRV_NAME ": Resetting C3 transitions.\n");
1846 acpi_set_cstate_limit(priv->cstate_limit);
1847 priv->config &= ~CFG_C3_DISABLED;
1851 /* We have to signal any supplicant if we are disassociating */
1853 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1855 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1856 netif_carrier_off(priv->net_dev);
1857 netif_stop_queue(priv->net_dev);
1860 static void ipw2100_reset_adapter(struct ipw2100_priv *priv)
1862 unsigned long flags;
1863 union iwreq_data wrqu = {
1865 .sa_family = ARPHRD_ETHER
1868 int associated = priv->status & STATUS_ASSOCIATED;
1870 spin_lock_irqsave(&priv->low_lock, flags);
1871 IPW_DEBUG_INFO(DRV_NAME ": %s: Restarting adapter.\n",
1872 priv->net_dev->name);
1874 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1875 priv->status |= STATUS_SECURITY_UPDATED;
1877 /* Force a power cycle even if interface hasn't been opened
1879 cancel_delayed_work(&priv->reset_work);
1880 priv->status |= STATUS_RESET_PENDING;
1881 spin_unlock_irqrestore(&priv->low_lock, flags);
1883 down(&priv->action_sem);
1884 /* stop timed checks so that they don't interfere with reset */
1885 priv->stop_hang_check = 1;
1886 cancel_delayed_work(&priv->hang_check);
1888 /* We have to signal any supplicant if we are disassociating */
1890 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1892 ipw2100_up(priv, 0);
1893 up(&priv->action_sem);
1898 static void isr_indicate_associated(struct ipw2100_priv *priv, u32 status)
1901 #define MAC_ASSOCIATION_READ_DELAY (HZ)
1902 int ret, len, essid_len;
1903 char essid[IW_ESSID_MAX_SIZE];
1910 * TBD: BSSID is usually 00:00:00:00:00:00 here and not
1911 * an actual MAC of the AP. Seems like FW sets this
1912 * address too late. Read it later and expose through
1913 * /proc or schedule a later task to query and update
1916 essid_len = IW_ESSID_MAX_SIZE;
1917 ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_SSID,
1920 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
1926 ret = ipw2100_get_ordinal(priv, IPW_ORD_CURRENT_TX_RATE,
1929 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
1935 ret = ipw2100_get_ordinal(priv, IPW_ORD_OUR_FREQ, &chan, &len);
1937 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
1942 ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID, &bssid, &len);
1944 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
1948 memcpy(priv->ieee->bssid, bssid, ETH_ALEN);
1952 case TX_RATE_1_MBIT:
1953 txratename = "1Mbps";
1955 case TX_RATE_2_MBIT:
1956 txratename = "2Mbsp";
1958 case TX_RATE_5_5_MBIT:
1959 txratename = "5.5Mbps";
1961 case TX_RATE_11_MBIT:
1962 txratename = "11Mbps";
1965 IPW_DEBUG_INFO("Unknown rate: %d\n", txrate);
1966 txratename = "unknown rate";
1970 IPW_DEBUG_INFO("%s: Associated with '%s' at %s, channel %d (BSSID="
1972 priv->net_dev->name, escape_essid(essid, essid_len),
1973 txratename, chan, MAC_ARG(bssid));
1975 /* now we copy read ssid into dev */
1976 if (!(priv->config & CFG_STATIC_ESSID)) {
1977 priv->essid_len = min((u8)essid_len, (u8)IW_ESSID_MAX_SIZE);
1978 memcpy(priv->essid, essid, priv->essid_len);
1980 priv->channel = chan;
1981 memcpy(priv->bssid, bssid, ETH_ALEN);
1983 priv->status |= STATUS_ASSOCIATING;
1984 priv->connect_start = get_seconds();
1986 queue_delayed_work(priv->workqueue, &priv->wx_event_work, HZ / 10);
1990 static int ipw2100_set_essid(struct ipw2100_priv *priv, char *essid,
1991 int length, int batch_mode)
1993 int ssid_len = min(length, IW_ESSID_MAX_SIZE);
1994 struct host_command cmd = {
1995 .host_command = SSID,
1996 .host_command_sequence = 0,
1997 .host_command_length = ssid_len
2001 IPW_DEBUG_HC("SSID: '%s'\n", escape_essid(essid, ssid_len));
2004 memcpy((char*)cmd.host_command_parameters,
2008 err = ipw2100_disable_adapter(priv);
2013 /* Bug in FW currently doesn't honor bit 0 in SET_SCAN_OPTIONS to
2014 * disable auto association -- so we cheat by setting a bogus SSID */
2015 if (!ssid_len && !(priv->config & CFG_ASSOCIATE)) {
2017 u8 *bogus = (u8*)cmd.host_command_parameters;
2018 for (i = 0; i < IW_ESSID_MAX_SIZE; i++)
2019 bogus[i] = 0x18 + i;
2020 cmd.host_command_length = IW_ESSID_MAX_SIZE;
2023 /* NOTE: We always send the SSID command even if the provided ESSID is
2024 * the same as what we currently think is set. */
2026 err = ipw2100_hw_send_command(priv, &cmd);
2028 memset(priv->essid + ssid_len, 0,
2029 IW_ESSID_MAX_SIZE - ssid_len);
2030 memcpy(priv->essid, essid, ssid_len);
2031 priv->essid_len = ssid_len;
2035 if (ipw2100_enable_adapter(priv))
2042 static void isr_indicate_association_lost(struct ipw2100_priv *priv, u32 status)
2044 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | IPW_DL_ASSOC,
2045 "disassociated: '%s' " MAC_FMT " \n",
2046 escape_essid(priv->essid, priv->essid_len),
2047 MAC_ARG(priv->bssid));
2049 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
2051 if (priv->status & STATUS_STOPPING) {
2052 IPW_DEBUG_INFO("Card is stopping itself, discard ASSN_LOST.\n");
2056 memset(priv->bssid, 0, ETH_ALEN);
2057 memset(priv->ieee->bssid, 0, ETH_ALEN);
2059 netif_carrier_off(priv->net_dev);
2060 netif_stop_queue(priv->net_dev);
2062 if (!(priv->status & STATUS_RUNNING))
2065 if (priv->status & STATUS_SECURITY_UPDATED)
2066 queue_work(priv->workqueue, &priv->security_work);
2068 queue_work(priv->workqueue, &priv->wx_event_work);
2071 static void isr_indicate_rf_kill(struct ipw2100_priv *priv, u32 status)
2073 IPW_DEBUG_INFO("%s: RF Kill state changed to radio OFF.\n",
2074 priv->net_dev->name);
2076 /* RF_KILL is now enabled (else we wouldn't be here) */
2077 priv->status |= STATUS_RF_KILL_HW;
2079 #ifdef ACPI_CSTATE_LIMIT_DEFINED
2080 if (priv->config & CFG_C3_DISABLED) {
2081 IPW_DEBUG_INFO(DRV_NAME ": Resetting C3 transitions.\n");
2082 acpi_set_cstate_limit(priv->cstate_limit);
2083 priv->config &= ~CFG_C3_DISABLED;
2087 /* Make sure the RF Kill check timer is running */
2088 priv->stop_rf_kill = 0;
2089 cancel_delayed_work(&priv->rf_kill);
2090 queue_delayed_work(priv->workqueue, &priv->rf_kill, HZ);
2093 static void isr_scan_complete(struct ipw2100_priv *priv, u32 status)
2095 IPW_DEBUG_SCAN("scan complete\n");
2096 /* Age the scan results... */
2097 priv->ieee->scans++;
2098 priv->status &= ~STATUS_SCANNING;
2101 #ifdef CONFIG_IPW_DEBUG
2102 #define IPW2100_HANDLER(v, f) { v, f, # v }
2103 struct ipw2100_status_indicator {
2105 void (*cb)(struct ipw2100_priv *priv, u32 status);
2109 #define IPW2100_HANDLER(v, f) { v, f }
2110 struct ipw2100_status_indicator {
2112 void (*cb)(struct ipw2100_priv *priv, u32 status);
2114 #endif /* CONFIG_IPW_DEBUG */
2116 static void isr_indicate_scanning(struct ipw2100_priv *priv, u32 status)
2118 IPW_DEBUG_SCAN("Scanning...\n");
2119 priv->status |= STATUS_SCANNING;
2122 static const struct ipw2100_status_indicator status_handlers[] = {
2123 IPW2100_HANDLER(IPW_STATE_INITIALIZED, NULL),
2124 IPW2100_HANDLER(IPW_STATE_COUNTRY_FOUND, NULL),
2125 IPW2100_HANDLER(IPW_STATE_ASSOCIATED, isr_indicate_associated),
2126 IPW2100_HANDLER(IPW_STATE_ASSN_LOST, isr_indicate_association_lost),
2127 IPW2100_HANDLER(IPW_STATE_ASSN_CHANGED, NULL),
2128 IPW2100_HANDLER(IPW_STATE_SCAN_COMPLETE, isr_scan_complete),
2129 IPW2100_HANDLER(IPW_STATE_ENTERED_PSP, NULL),
2130 IPW2100_HANDLER(IPW_STATE_LEFT_PSP, NULL),
2131 IPW2100_HANDLER(IPW_STATE_RF_KILL, isr_indicate_rf_kill),
2132 IPW2100_HANDLER(IPW_STATE_DISABLED, NULL),
2133 IPW2100_HANDLER(IPW_STATE_POWER_DOWN, NULL),
2134 IPW2100_HANDLER(IPW_STATE_SCANNING, isr_indicate_scanning),
2135 IPW2100_HANDLER(-1, NULL)
2139 static void isr_status_change(struct ipw2100_priv *priv, int status)
2143 if (status == IPW_STATE_SCANNING &&
2144 priv->status & STATUS_ASSOCIATED &&
2145 !(priv->status & STATUS_SCANNING)) {
2146 IPW_DEBUG_INFO("Scan detected while associated, with "
2147 "no scan request. Restarting firmware.\n");
2149 /* Wake up any sleeping jobs */
2150 schedule_reset(priv);
2153 for (i = 0; status_handlers[i].status != -1; i++) {
2154 if (status == status_handlers[i].status) {
2155 IPW_DEBUG_NOTIF("Status change: %s\n",
2156 status_handlers[i].name);
2157 if (status_handlers[i].cb)
2158 status_handlers[i].cb(priv, status);
2159 priv->wstats.status = status;
2164 IPW_DEBUG_NOTIF("unknown status received: %04x\n", status);
2167 static void isr_rx_complete_command(
2168 struct ipw2100_priv *priv,
2169 struct ipw2100_cmd_header *cmd)
2171 #ifdef CONFIG_IPW_DEBUG
2172 if (cmd->host_command_reg < ARRAY_SIZE(command_types)) {
2173 IPW_DEBUG_HC("Command completed '%s (%d)'\n",
2174 command_types[cmd->host_command_reg],
2175 cmd->host_command_reg);
2178 if (cmd->host_command_reg == HOST_COMPLETE)
2179 priv->status |= STATUS_ENABLED;
2181 if (cmd->host_command_reg == CARD_DISABLE)
2182 priv->status &= ~STATUS_ENABLED;
2184 priv->status &= ~STATUS_CMD_ACTIVE;
2186 wake_up_interruptible(&priv->wait_command_queue);
2189 #ifdef CONFIG_IPW_DEBUG
2190 static const char *frame_types[] = {
2191 "COMMAND_STATUS_VAL",
2192 "STATUS_CHANGE_VAL",
2195 "HOST_NOTIFICATION_VAL"
2200 static inline int ipw2100_alloc_skb(
2201 struct ipw2100_priv *priv,
2202 struct ipw2100_rx_packet *packet)
2204 packet->skb = dev_alloc_skb(sizeof(struct ipw2100_rx));
2208 packet->rxp = (struct ipw2100_rx *)packet->skb->data;
2209 packet->dma_addr = pci_map_single(priv->pci_dev, packet->skb->data,
2210 sizeof(struct ipw2100_rx),
2211 PCI_DMA_FROMDEVICE);
2212 /* NOTE: pci_map_single does not return an error code, and 0 is a valid
2219 #define SEARCH_ERROR 0xffffffff
2220 #define SEARCH_FAIL 0xfffffffe
2221 #define SEARCH_SUCCESS 0xfffffff0
2222 #define SEARCH_DISCARD 0
2223 #define SEARCH_SNAPSHOT 1
2225 #define SNAPSHOT_ADDR(ofs) (priv->snapshot[((ofs) >> 12) & 0xff] + ((ofs) & 0xfff))
2226 static inline int ipw2100_snapshot_alloc(struct ipw2100_priv *priv)
2229 if (priv->snapshot[0])
2231 for (i = 0; i < 0x30; i++) {
2232 priv->snapshot[i] = (u8*)kmalloc(0x1000, GFP_ATOMIC);
2233 if (!priv->snapshot[i]) {
2234 IPW_DEBUG_INFO("%s: Error allocating snapshot "
2235 "buffer %d\n", priv->net_dev->name, i);
2237 kfree(priv->snapshot[--i]);
2238 priv->snapshot[0] = NULL;
2246 static inline void ipw2100_snapshot_free(struct ipw2100_priv *priv)
2249 if (!priv->snapshot[0])
2251 for (i = 0; i < 0x30; i++)
2252 kfree(priv->snapshot[i]);
2253 priv->snapshot[0] = NULL;
2256 static inline u32 ipw2100_match_buf(struct ipw2100_priv *priv, u8 *in_buf,
2257 size_t len, int mode)
2265 if (mode == SEARCH_SNAPSHOT) {
2266 if (!ipw2100_snapshot_alloc(priv))
2267 mode = SEARCH_DISCARD;
2270 for (ret = SEARCH_FAIL, i = 0; i < 0x30000; i += 4) {
2271 read_nic_dword(priv->net_dev, i, &tmp);
2272 if (mode == SEARCH_SNAPSHOT)
2273 *(u32 *)SNAPSHOT_ADDR(i) = tmp;
2274 if (ret == SEARCH_FAIL) {
2276 for (j = 0; j < 4; j++) {
2285 if ((s - in_buf) == len)
2286 ret = (i + j) - len + 1;
2288 } else if (mode == SEARCH_DISCARD)
2297 * 0) Disconnect the SKB from the firmware (just unmap)
2298 * 1) Pack the ETH header into the SKB
2299 * 2) Pass the SKB to the network stack
2301 * When packet is provided by the firmware, it contains the following:
2304 * . ieee80211_snap_hdr
2306 * The size of the constructed ethernet
2309 #ifdef CONFIG_IPW2100_RX_DEBUG
2310 static u8 packet_data[IPW_RX_NIC_BUFFER_LENGTH];
2313 static inline void ipw2100_corruption_detected(struct ipw2100_priv *priv,
2316 #ifdef CONFIG_IPW_DEBUG_C3
2317 struct ipw2100_status *status = &priv->status_queue.drv[i];
2321 #ifdef ACPI_CSTATE_LIMIT_DEFINED
2325 IPW_DEBUG_INFO(DRV_NAME ": PCI latency error detected at "
2326 "0x%04zX.\n", i * sizeof(struct ipw2100_status));
2328 #ifdef ACPI_CSTATE_LIMIT_DEFINED
2329 IPW_DEBUG_INFO(DRV_NAME ": Disabling C3 transitions.\n");
2330 limit = acpi_get_cstate_limit();
2332 priv->cstate_limit = limit;
2333 acpi_set_cstate_limit(2);
2334 priv->config |= CFG_C3_DISABLED;
2338 #ifdef CONFIG_IPW_DEBUG_C3
2339 /* Halt the fimrware so we can get a good image */
2340 write_register(priv->net_dev, IPW_REG_RESET_REG,
2341 IPW_AUX_HOST_RESET_REG_STOP_MASTER);
2344 udelay(IPW_WAIT_RESET_MASTER_ASSERT_COMPLETE_DELAY);
2345 read_register(priv->net_dev, IPW_REG_RESET_REG, ®);
2347 if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED)
2351 match = ipw2100_match_buf(priv, (u8*)status,
2352 sizeof(struct ipw2100_status),
2354 if (match < SEARCH_SUCCESS)
2355 IPW_DEBUG_INFO("%s: DMA status match in Firmware at "
2356 "offset 0x%06X, length %d:\n",
2357 priv->net_dev->name, match,
2358 sizeof(struct ipw2100_status));
2360 IPW_DEBUG_INFO("%s: No DMA status match in "
2361 "Firmware.\n", priv->net_dev->name);
2363 printk_buf((u8*)priv->status_queue.drv,
2364 sizeof(struct ipw2100_status) * RX_QUEUE_LENGTH);
2367 priv->fatal_error = IPW2100_ERR_C3_CORRUPTION;
2368 priv->ieee->stats.rx_errors++;
2369 schedule_reset(priv);
2372 static inline void isr_rx(struct ipw2100_priv *priv, int i,
2373 struct ieee80211_rx_stats *stats)
2375 struct ipw2100_status *status = &priv->status_queue.drv[i];
2376 struct ipw2100_rx_packet *packet = &priv->rx_buffers[i];
2378 IPW_DEBUG_RX("Handler...\n");
2380 if (unlikely(status->frame_size > skb_tailroom(packet->skb))) {
2381 IPW_DEBUG_INFO("%s: frame_size (%u) > skb_tailroom (%u)!"
2383 priv->net_dev->name,
2384 status->frame_size, skb_tailroom(packet->skb));
2385 priv->ieee->stats.rx_errors++;
2389 if (unlikely(!netif_running(priv->net_dev))) {
2390 priv->ieee->stats.rx_errors++;
2391 priv->wstats.discard.misc++;
2392 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
2396 if (unlikely(priv->ieee->iw_mode == IW_MODE_MONITOR &&
2397 status->flags & IPW_STATUS_FLAG_CRC_ERROR)) {
2398 IPW_DEBUG_RX("CRC error in packet. Dropping.\n");
2399 priv->ieee->stats.rx_errors++;
2403 if (unlikely(priv->ieee->iw_mode != IW_MODE_MONITOR &&
2404 !(priv->status & STATUS_ASSOCIATED))) {
2405 IPW_DEBUG_DROP("Dropping packet while not associated.\n");
2406 priv->wstats.discard.misc++;
2411 pci_unmap_single(priv->pci_dev,
2413 sizeof(struct ipw2100_rx),
2414 PCI_DMA_FROMDEVICE);
2416 skb_put(packet->skb, status->frame_size);
2418 #ifdef CONFIG_IPW2100_RX_DEBUG
2419 /* Make a copy of the frame so we can dump it to the logs if
2420 * ieee80211_rx fails */
2421 memcpy(packet_data, packet->skb->data,
2422 min_t(u32, status->frame_size, IPW_RX_NIC_BUFFER_LENGTH));
2425 if (!ieee80211_rx(priv->ieee, packet->skb, stats)) {
2426 #ifdef CONFIG_IPW2100_RX_DEBUG
2427 IPW_DEBUG_DROP("%s: Non consumed packet:\n",
2428 priv->net_dev->name);
2429 printk_buf(IPW_DL_DROP, packet_data, status->frame_size);
2431 priv->ieee->stats.rx_errors++;
2433 /* ieee80211_rx failed, so it didn't free the SKB */
2434 dev_kfree_skb_any(packet->skb);
2438 /* We need to allocate a new SKB and attach it to the RDB. */
2439 if (unlikely(ipw2100_alloc_skb(priv, packet))) {
2440 printk(KERN_WARNING DRV_NAME ": "
2441 "%s: Unable to allocate SKB onto RBD ring - disabling "
2442 "adapter.\n", priv->net_dev->name);
2443 /* TODO: schedule adapter shutdown */
2444 IPW_DEBUG_INFO("TODO: Shutdown adapter...\n");
2447 /* Update the RDB entry */
2448 priv->rx_queue.drv[i].host_addr = packet->dma_addr;
2451 static inline int ipw2100_corruption_check(struct ipw2100_priv *priv, int i)
2453 struct ipw2100_status *status = &priv->status_queue.drv[i];
2454 struct ipw2100_rx *u = priv->rx_buffers[i].rxp;
2455 u16 frame_type = status->status_fields & STATUS_TYPE_MASK;
2457 switch (frame_type) {
2458 case COMMAND_STATUS_VAL:
2459 return (status->frame_size != sizeof(u->rx_data.command));
2460 case STATUS_CHANGE_VAL:
2461 return (status->frame_size != sizeof(u->rx_data.status));
2462 case HOST_NOTIFICATION_VAL:
2463 return (status->frame_size < sizeof(u->rx_data.notification));
2464 case P80211_DATA_VAL:
2465 case P8023_DATA_VAL:
2466 #ifdef CONFIG_IPW2100_MONITOR
2469 switch (WLAN_FC_GET_TYPE(u->rx_data.header.frame_ctl)) {
2470 case IEEE80211_FTYPE_MGMT:
2471 case IEEE80211_FTYPE_CTL:
2473 case IEEE80211_FTYPE_DATA:
2474 return (status->frame_size >
2475 IPW_MAX_802_11_PAYLOAD_LENGTH);
2484 * ipw2100 interrupts are disabled at this point, and the ISR
2485 * is the only code that calls this method. So, we do not need
2486 * to play with any locks.
2488 * RX Queue works as follows:
2490 * Read index - firmware places packet in entry identified by the
2491 * Read index and advances Read index. In this manner,
2492 * Read index will always point to the next packet to
2493 * be filled--but not yet valid.
2495 * Write index - driver fills this entry with an unused RBD entry.
2496 * This entry has not filled by the firmware yet.
2498 * In between the W and R indexes are the RBDs that have been received
2499 * but not yet processed.
2501 * The process of handling packets will start at WRITE + 1 and advance
2502 * until it reaches the READ index.
2504 * The WRITE index is cached in the variable 'priv->rx_queue.next'.
2507 static inline void __ipw2100_rx_process(struct ipw2100_priv *priv)
2509 struct ipw2100_bd_queue *rxq = &priv->rx_queue;
2510 struct ipw2100_status_queue *sq = &priv->status_queue;
2511 struct ipw2100_rx_packet *packet;
2514 struct ipw2100_rx *u;
2515 struct ieee80211_rx_stats stats = {
2516 .mac_time = jiffies,
2519 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_READ_INDEX, &r);
2520 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_WRITE_INDEX, &w);
2522 if (r >= rxq->entries) {
2523 IPW_DEBUG_RX("exit - bad read index\n");
2527 i = (rxq->next + 1) % rxq->entries;
2530 /* IPW_DEBUG_RX("r = %d : w = %d : processing = %d\n",
2531 r, rxq->next, i); */
2533 packet = &priv->rx_buffers[i];
2535 /* Sync the DMA for the STATUS buffer so CPU is sure to get
2536 * the correct values */
2537 pci_dma_sync_single_for_cpu(
2539 sq->nic + sizeof(struct ipw2100_status) * i,
2540 sizeof(struct ipw2100_status),
2541 PCI_DMA_FROMDEVICE);
2543 /* Sync the DMA for the RX buffer so CPU is sure to get
2544 * the correct values */
2545 pci_dma_sync_single_for_cpu(priv->pci_dev, packet->dma_addr,
2546 sizeof(struct ipw2100_rx),
2547 PCI_DMA_FROMDEVICE);
2549 if (unlikely(ipw2100_corruption_check(priv, i))) {
2550 ipw2100_corruption_detected(priv, i);
2555 frame_type = sq->drv[i].status_fields &
2557 stats.rssi = sq->drv[i].rssi + IPW2100_RSSI_TO_DBM;
2558 stats.len = sq->drv[i].frame_size;
2561 if (stats.rssi != 0)
2562 stats.mask |= IEEE80211_STATMASK_RSSI;
2563 stats.freq = IEEE80211_24GHZ_BAND;
2566 "%s: '%s' frame type received (%d).\n",
2567 priv->net_dev->name, frame_types[frame_type],
2570 switch (frame_type) {
2571 case COMMAND_STATUS_VAL:
2572 /* Reset Rx watchdog */
2573 isr_rx_complete_command(
2574 priv, &u->rx_data.command);
2577 case STATUS_CHANGE_VAL:
2578 isr_status_change(priv, u->rx_data.status);
2581 case P80211_DATA_VAL:
2582 case P8023_DATA_VAL:
2583 #ifdef CONFIG_IPW2100_MONITOR
2584 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
2585 isr_rx(priv, i, &stats);
2589 if (stats.len < sizeof(u->rx_data.header))
2591 switch (WLAN_FC_GET_TYPE(u->rx_data.header.
2593 case IEEE80211_FTYPE_MGMT:
2594 ieee80211_rx_mgt(priv->ieee,
2599 case IEEE80211_FTYPE_CTL:
2602 case IEEE80211_FTYPE_DATA:
2603 isr_rx(priv, i, &stats);
2611 /* clear status field associated with this RBD */
2612 rxq->drv[i].status.info.field = 0;
2614 i = (i + 1) % rxq->entries;
2618 /* backtrack one entry, wrapping to end if at 0 */
2619 rxq->next = (i ? i : rxq->entries) - 1;
2621 write_register(priv->net_dev,
2622 IPW_MEM_HOST_SHARED_RX_WRITE_INDEX,
2629 * __ipw2100_tx_process
2631 * This routine will determine whether the next packet on
2632 * the fw_pend_list has been processed by the firmware yet.
2634 * If not, then it does nothing and returns.
2636 * If so, then it removes the item from the fw_pend_list, frees
2637 * any associated storage, and places the item back on the
2638 * free list of its source (either msg_free_list or tx_free_list)
2640 * TX Queue works as follows:
2642 * Read index - points to the next TBD that the firmware will
2643 * process. The firmware will read the data, and once
2644 * done processing, it will advance the Read index.
2646 * Write index - driver fills this entry with an constructed TBD
2647 * entry. The Write index is not advanced until the
2648 * packet has been configured.
2650 * In between the W and R indexes are the TBDs that have NOT been
2651 * processed. Lagging behind the R index are packets that have
2652 * been processed but have not been freed by the driver.
2654 * In order to free old storage, an internal index will be maintained
2655 * that points to the next packet to be freed. When all used
2656 * packets have been freed, the oldest index will be the same as the
2657 * firmware's read index.
2659 * The OLDEST index is cached in the variable 'priv->tx_queue.oldest'
2661 * Because the TBD structure can not contain arbitrary data, the
2662 * driver must keep an internal queue of cached allocations such that
2663 * it can put that data back into the tx_free_list and msg_free_list
2664 * for use by future command and data packets.
2667 static inline int __ipw2100_tx_process(struct ipw2100_priv *priv)
2669 struct ipw2100_bd_queue *txq = &priv->tx_queue;
2670 struct ipw2100_bd *tbd;
2671 struct list_head *element;
2672 struct ipw2100_tx_packet *packet;
2673 int descriptors_used;
2675 u32 r, w, frag_num = 0;
2677 if (list_empty(&priv->fw_pend_list))
2680 element = priv->fw_pend_list.next;
2682 packet = list_entry(element, struct ipw2100_tx_packet, list);
2683 tbd = &txq->drv[packet->index];
2685 /* Determine how many TBD entries must be finished... */
2686 switch (packet->type) {
2688 /* COMMAND uses only one slot; don't advance */
2689 descriptors_used = 1;
2694 /* DATA uses two slots; advance and loop position. */
2695 descriptors_used = tbd->num_fragments;
2696 frag_num = tbd->num_fragments - 1;
2697 e = txq->oldest + frag_num;
2702 printk(KERN_WARNING DRV_NAME ": %s: Bad fw_pend_list entry!\n",
2703 priv->net_dev->name);
2707 /* if the last TBD is not done by NIC yet, then packet is
2708 * not ready to be released.
2711 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_TX_QUEUE_READ_INDEX,
2713 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX,
2716 printk(KERN_WARNING DRV_NAME ": %s: write index mismatch\n",
2717 priv->net_dev->name);
2720 * txq->next is the index of the last packet written txq->oldest is
2721 * the index of the r is the index of the next packet to be read by
2727 * Quick graphic to help you visualize the following
2728 * if / else statement
2730 * ===>| s---->|===============
2732 * | a | b | c | d | e | f | g | h | i | j | k | l
2736 * w - updated by driver
2737 * r - updated by firmware
2738 * s - start of oldest BD entry (txq->oldest)
2739 * e - end of oldest BD entry
2742 if (!((r <= w && (e < r || e >= w)) || (e < r && e >= w))) {
2743 IPW_DEBUG_TX("exit - no processed packets ready to release.\n");
2748 DEC_STAT(&priv->fw_pend_stat);
2750 #ifdef CONFIG_IPW_DEBUG
2752 int i = txq->oldest;
2754 "TX%d V=%p P=%04X T=%04X L=%d\n", i,
2756 (u32)(txq->nic + i * sizeof(struct ipw2100_bd)),
2757 txq->drv[i].host_addr,
2758 txq->drv[i].buf_length);
2760 if (packet->type == DATA) {
2761 i = (i + 1) % txq->entries;
2764 "TX%d V=%p P=%04X T=%04X L=%d\n", i,
2766 (u32)(txq->nic + i *
2767 sizeof(struct ipw2100_bd)),
2768 (u32)txq->drv[i].host_addr,
2769 txq->drv[i].buf_length);
2774 switch (packet->type) {
2776 if (txq->drv[txq->oldest].status.info.fields.txType != 0)
2777 printk(KERN_WARNING DRV_NAME ": %s: Queue mismatch. "
2778 "Expecting DATA TBD but pulled "
2779 "something else: ids %d=%d.\n",
2780 priv->net_dev->name, txq->oldest, packet->index);
2782 /* DATA packet; we have to unmap and free the SKB */
2783 priv->ieee->stats.tx_packets++;
2784 for (i = 0; i < frag_num; i++) {
2785 tbd = &txq->drv[(packet->index + 1 + i) %
2789 "TX%d P=%08x L=%d\n",
2790 (packet->index + 1 + i) % txq->entries,
2791 tbd->host_addr, tbd->buf_length);
2793 pci_unmap_single(priv->pci_dev,
2799 priv->ieee->stats.tx_bytes += packet->info.d_struct.txb->payload_size;
2800 ieee80211_txb_free(packet->info.d_struct.txb);
2801 packet->info.d_struct.txb = NULL;
2803 list_add_tail(element, &priv->tx_free_list);
2804 INC_STAT(&priv->tx_free_stat);
2806 /* We have a free slot in the Tx queue, so wake up the
2807 * transmit layer if it is stopped. */
2808 if (priv->status & STATUS_ASSOCIATED &&
2809 netif_queue_stopped(priv->net_dev)) {
2810 IPW_DEBUG_INFO(KERN_INFO
2811 "%s: Waking net queue.\n",
2812 priv->net_dev->name);
2813 netif_wake_queue(priv->net_dev);
2816 /* A packet was processed by the hardware, so update the
2818 priv->net_dev->trans_start = jiffies;
2823 if (txq->drv[txq->oldest].status.info.fields.txType != 1)
2824 printk(KERN_WARNING DRV_NAME ": %s: Queue mismatch. "
2825 "Expecting COMMAND TBD but pulled "
2826 "something else: ids %d=%d.\n",
2827 priv->net_dev->name, txq->oldest, packet->index);
2829 #ifdef CONFIG_IPW_DEBUG
2830 if (packet->info.c_struct.cmd->host_command_reg <
2831 sizeof(command_types) / sizeof(*command_types))
2833 "Command '%s (%d)' processed: %d.\n",
2834 command_types[packet->info.c_struct.cmd->host_command_reg],
2835 packet->info.c_struct.cmd->host_command_reg,
2836 packet->info.c_struct.cmd->cmd_status_reg);
2839 list_add_tail(element, &priv->msg_free_list);
2840 INC_STAT(&priv->msg_free_stat);
2844 /* advance oldest used TBD pointer to start of next entry */
2845 txq->oldest = (e + 1) % txq->entries;
2846 /* increase available TBDs number */
2847 txq->available += descriptors_used;
2848 SET_STAT(&priv->txq_stat, txq->available);
2850 IPW_DEBUG_TX("packet latency (send to process) %ld jiffies\n",
2851 jiffies - packet->jiffy_start);
2853 return (!list_empty(&priv->fw_pend_list));
2857 static inline void __ipw2100_tx_complete(struct ipw2100_priv *priv)
2861 while (__ipw2100_tx_process(priv) && i < 200) i++;
2864 printk(KERN_WARNING DRV_NAME ": "
2865 "%s: Driver is running slow (%d iters).\n",
2866 priv->net_dev->name, i);
2871 static void ipw2100_tx_send_commands(struct ipw2100_priv *priv)
2873 struct list_head *element;
2874 struct ipw2100_tx_packet *packet;
2875 struct ipw2100_bd_queue *txq = &priv->tx_queue;
2876 struct ipw2100_bd *tbd;
2877 int next = txq->next;
2879 while (!list_empty(&priv->msg_pend_list)) {
2880 /* if there isn't enough space in TBD queue, then
2881 * don't stuff a new one in.
2882 * NOTE: 3 are needed as a command will take one,
2883 * and there is a minimum of 2 that must be
2884 * maintained between the r and w indexes
2886 if (txq->available <= 3) {
2887 IPW_DEBUG_TX("no room in tx_queue\n");
2891 element = priv->msg_pend_list.next;
2893 DEC_STAT(&priv->msg_pend_stat);
2895 packet = list_entry(element,
2896 struct ipw2100_tx_packet, list);
2898 IPW_DEBUG_TX("using TBD at virt=%p, phys=%p\n",
2899 &txq->drv[txq->next],
2900 (void*)(txq->nic + txq->next *
2901 sizeof(struct ipw2100_bd)));
2903 packet->index = txq->next;
2905 tbd = &txq->drv[txq->next];
2907 /* initialize TBD */
2908 tbd->host_addr = packet->info.c_struct.cmd_phys;
2909 tbd->buf_length = sizeof(struct ipw2100_cmd_header);
2910 /* not marking number of fragments causes problems
2911 * with f/w debug version */
2912 tbd->num_fragments = 1;
2913 tbd->status.info.field =
2914 IPW_BD_STATUS_TX_FRAME_COMMAND |
2915 IPW_BD_STATUS_TX_INTERRUPT_ENABLE;
2917 /* update TBD queue counters */
2919 txq->next %= txq->entries;
2921 DEC_STAT(&priv->txq_stat);
2923 list_add_tail(element, &priv->fw_pend_list);
2924 INC_STAT(&priv->fw_pend_stat);
2927 if (txq->next != next) {
2928 /* kick off the DMA by notifying firmware the
2929 * write index has moved; make sure TBD stores are sync'd */
2931 write_register(priv->net_dev,
2932 IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX,
2939 * ipw2100_tx_send_data
2942 static void ipw2100_tx_send_data(struct ipw2100_priv *priv)
2944 struct list_head *element;
2945 struct ipw2100_tx_packet *packet;
2946 struct ipw2100_bd_queue *txq = &priv->tx_queue;
2947 struct ipw2100_bd *tbd;
2948 int next = txq->next;
2950 struct ipw2100_data_header *ipw_hdr;
2951 struct ieee80211_hdr_3addr *hdr;
2953 while (!list_empty(&priv->tx_pend_list)) {
2954 /* if there isn't enough space in TBD queue, then
2955 * don't stuff a new one in.
2956 * NOTE: 4 are needed as a data will take two,
2957 * and there is a minimum of 2 that must be
2958 * maintained between the r and w indexes
2960 element = priv->tx_pend_list.next;
2961 packet = list_entry(element, struct ipw2100_tx_packet, list);
2963 if (unlikely(1 + packet->info.d_struct.txb->nr_frags >
2965 /* TODO: Support merging buffers if more than
2966 * IPW_MAX_BDS are used */
2968 "%s: Maximum BD theshold exceeded. "
2969 "Increase fragmentation level.\n",
2970 priv->net_dev->name);
2973 if (txq->available <= 3 +
2974 packet->info.d_struct.txb->nr_frags) {
2975 IPW_DEBUG_TX("no room in tx_queue\n");
2980 DEC_STAT(&priv->tx_pend_stat);
2982 tbd = &txq->drv[txq->next];
2984 packet->index = txq->next;
2986 ipw_hdr = packet->info.d_struct.data;
2987 hdr = (struct ieee80211_hdr_3addr *)packet->info.d_struct.txb->
2990 if (priv->ieee->iw_mode == IW_MODE_INFRA) {
2991 /* To DS: Addr1 = BSSID, Addr2 = SA,
2993 memcpy(ipw_hdr->src_addr, hdr->addr2, ETH_ALEN);
2994 memcpy(ipw_hdr->dst_addr, hdr->addr3, ETH_ALEN);
2995 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
2996 /* not From/To DS: Addr1 = DA, Addr2 = SA,
2998 memcpy(ipw_hdr->src_addr, hdr->addr2, ETH_ALEN);
2999 memcpy(ipw_hdr->dst_addr, hdr->addr1, ETH_ALEN);
3002 ipw_hdr->host_command_reg = SEND;
3003 ipw_hdr->host_command_reg1 = 0;
3005 /* For now we only support host based encryption */
3006 ipw_hdr->needs_encryption = 0;
3007 ipw_hdr->encrypted = packet->info.d_struct.txb->encrypted;
3008 if (packet->info.d_struct.txb->nr_frags > 1)
3009 ipw_hdr->fragment_size =
3010 packet->info.d_struct.txb->frag_size - IEEE80211_3ADDR_LEN;
3012 ipw_hdr->fragment_size = 0;
3014 tbd->host_addr = packet->info.d_struct.data_phys;
3015 tbd->buf_length = sizeof(struct ipw2100_data_header);
3016 tbd->num_fragments = 1 + packet->info.d_struct.txb->nr_frags;
3017 tbd->status.info.field =
3018 IPW_BD_STATUS_TX_FRAME_802_3 |
3019 IPW_BD_STATUS_TX_FRAME_NOT_LAST_FRAGMENT;
3021 txq->next %= txq->entries;
3024 "data header tbd TX%d P=%08x L=%d\n",
3025 packet->index, tbd->host_addr,
3027 #ifdef CONFIG_IPW_DEBUG
3028 if (packet->info.d_struct.txb->nr_frags > 1)
3029 IPW_DEBUG_FRAG("fragment Tx: %d frames\n",
3030 packet->info.d_struct.txb->nr_frags);
3033 for (i = 0; i < packet->info.d_struct.txb->nr_frags; i++) {
3034 tbd = &txq->drv[txq->next];
3035 if (i == packet->info.d_struct.txb->nr_frags - 1)
3036 tbd->status.info.field =
3037 IPW_BD_STATUS_TX_FRAME_802_3 |
3038 IPW_BD_STATUS_TX_INTERRUPT_ENABLE;
3040 tbd->status.info.field =
3041 IPW_BD_STATUS_TX_FRAME_802_3 |
3042 IPW_BD_STATUS_TX_FRAME_NOT_LAST_FRAGMENT;
3044 tbd->buf_length = packet->info.d_struct.txb->
3045 fragments[i]->len - IEEE80211_3ADDR_LEN;
3047 tbd->host_addr = pci_map_single(
3049 packet->info.d_struct.txb->fragments[i]->data +
3050 IEEE80211_3ADDR_LEN,
3055 "data frag tbd TX%d P=%08x L=%d\n",
3056 txq->next, tbd->host_addr, tbd->buf_length);
3058 pci_dma_sync_single_for_device(
3059 priv->pci_dev, tbd->host_addr,
3064 txq->next %= txq->entries;
3067 txq->available -= 1 + packet->info.d_struct.txb->nr_frags;
3068 SET_STAT(&priv->txq_stat, txq->available);
3070 list_add_tail(element, &priv->fw_pend_list);
3071 INC_STAT(&priv->fw_pend_stat);
3074 if (txq->next != next) {
3075 /* kick off the DMA by notifying firmware the
3076 * write index has moved; make sure TBD stores are sync'd */
3077 write_register(priv->net_dev,
3078 IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX,
3084 static void ipw2100_irq_tasklet(struct ipw2100_priv *priv)
3086 struct net_device *dev = priv->net_dev;
3087 unsigned long flags;
3090 spin_lock_irqsave(&priv->low_lock, flags);
3091 ipw2100_disable_interrupts(priv);
3093 read_register(dev, IPW_REG_INTA, &inta);
3095 IPW_DEBUG_ISR("enter - INTA: 0x%08lX\n",
3096 (unsigned long)inta & IPW_INTERRUPT_MASK);
3101 /* We do not loop and keep polling for more interrupts as this
3102 * is frowned upon and doesn't play nicely with other potentially
3104 IPW_DEBUG_ISR("INTA: 0x%08lX\n",
3105 (unsigned long)inta & IPW_INTERRUPT_MASK);
3107 if (inta & IPW2100_INTA_FATAL_ERROR) {
3108 printk(KERN_WARNING DRV_NAME
3109 ": Fatal interrupt. Scheduling firmware restart.\n");
3113 IPW2100_INTA_FATAL_ERROR);
3115 read_nic_dword(dev, IPW_NIC_FATAL_ERROR, &priv->fatal_error);
3116 IPW_DEBUG_INFO("%s: Fatal error value: 0x%08X\n",
3117 priv->net_dev->name, priv->fatal_error);
3119 read_nic_dword(dev, IPW_ERROR_ADDR(priv->fatal_error), &tmp);
3120 IPW_DEBUG_INFO("%s: Fatal error address value: 0x%08X\n",
3121 priv->net_dev->name, tmp);
3123 /* Wake up any sleeping jobs */
3124 schedule_reset(priv);
3127 if (inta & IPW2100_INTA_PARITY_ERROR) {
3128 printk(KERN_ERR DRV_NAME ": ***** PARITY ERROR INTERRUPT !!!! \n");
3132 IPW2100_INTA_PARITY_ERROR);
3135 if (inta & IPW2100_INTA_RX_TRANSFER) {
3136 IPW_DEBUG_ISR("RX interrupt\n");
3138 priv->rx_interrupts++;
3142 IPW2100_INTA_RX_TRANSFER);
3144 __ipw2100_rx_process(priv);
3145 __ipw2100_tx_complete(priv);
3148 if (inta & IPW2100_INTA_TX_TRANSFER) {
3149 IPW_DEBUG_ISR("TX interrupt\n");
3151 priv->tx_interrupts++;
3153 write_register(dev, IPW_REG_INTA,
3154 IPW2100_INTA_TX_TRANSFER);
3156 __ipw2100_tx_complete(priv);
3157 ipw2100_tx_send_commands(priv);
3158 ipw2100_tx_send_data(priv);
3161 if (inta & IPW2100_INTA_TX_COMPLETE) {
3162 IPW_DEBUG_ISR("TX complete\n");
3166 IPW2100_INTA_TX_COMPLETE);
3168 __ipw2100_tx_complete(priv);
3171 if (inta & IPW2100_INTA_EVENT_INTERRUPT) {
3172 /* ipw2100_handle_event(dev); */
3176 IPW2100_INTA_EVENT_INTERRUPT);
3179 if (inta & IPW2100_INTA_FW_INIT_DONE) {
3180 IPW_DEBUG_ISR("FW init done interrupt\n");
3183 read_register(dev, IPW_REG_INTA, &tmp);
3184 if (tmp & (IPW2100_INTA_FATAL_ERROR |
3185 IPW2100_INTA_PARITY_ERROR)) {
3188 IPW2100_INTA_FATAL_ERROR |
3189 IPW2100_INTA_PARITY_ERROR);
3192 write_register(dev, IPW_REG_INTA,
3193 IPW2100_INTA_FW_INIT_DONE);
3196 if (inta & IPW2100_INTA_STATUS_CHANGE) {
3197 IPW_DEBUG_ISR("Status change interrupt\n");
3201 IPW2100_INTA_STATUS_CHANGE);
3204 if (inta & IPW2100_INTA_SLAVE_MODE_HOST_COMMAND_DONE) {
3205 IPW_DEBUG_ISR("slave host mode interrupt\n");
3209 IPW2100_INTA_SLAVE_MODE_HOST_COMMAND_DONE);
3213 ipw2100_enable_interrupts(priv);
3215 spin_unlock_irqrestore(&priv->low_lock, flags);
3217 IPW_DEBUG_ISR("exit\n");
3221 static irqreturn_t ipw2100_interrupt(int irq, void *data,
3222 struct pt_regs *regs)
3224 struct ipw2100_priv *priv = data;
3225 u32 inta, inta_mask;
3230 spin_lock(&priv->low_lock);
3232 /* We check to see if we should be ignoring interrupts before
3233 * we touch the hardware. During ucode load if we try and handle
3234 * an interrupt we can cause keyboard problems as well as cause
3235 * the ucode to fail to initialize */
3236 if (!(priv->status & STATUS_INT_ENABLED)) {
3241 read_register(priv->net_dev, IPW_REG_INTA_MASK, &inta_mask);
3242 read_register(priv->net_dev, IPW_REG_INTA, &inta);
3244 if (inta == 0xFFFFFFFF) {
3245 /* Hardware disappeared */
3246 printk(KERN_WARNING DRV_NAME ": IRQ INTA == 0xFFFFFFFF\n");
3250 inta &= IPW_INTERRUPT_MASK;
3252 if (!(inta & inta_mask)) {
3253 /* Shared interrupt */
3257 /* We disable the hardware interrupt here just to prevent unneeded
3258 * calls to be made. We disable this again within the actual
3259 * work tasklet, so if another part of the code re-enables the
3260 * interrupt, that is fine */
3261 ipw2100_disable_interrupts(priv);
3263 tasklet_schedule(&priv->irq_tasklet);
3264 spin_unlock(&priv->low_lock);
3268 spin_unlock(&priv->low_lock);
3272 static int ipw2100_tx(struct ieee80211_txb *txb, struct net_device *dev,
3275 struct ipw2100_priv *priv = ieee80211_priv(dev);
3276 struct list_head *element;
3277 struct ipw2100_tx_packet *packet;
3278 unsigned long flags;
3280 spin_lock_irqsave(&priv->low_lock, flags);
3282 if (!(priv->status & STATUS_ASSOCIATED)) {
3283 IPW_DEBUG_INFO("Can not transmit when not connected.\n");
3284 priv->ieee->stats.tx_carrier_errors++;
3285 netif_stop_queue(dev);
3289 if (list_empty(&priv->tx_free_list))
3292 element = priv->tx_free_list.next;
3293 packet = list_entry(element, struct ipw2100_tx_packet, list);
3295 packet->info.d_struct.txb = txb;
3297 IPW_DEBUG_TX("Sending fragment (%d bytes):\n",
3298 txb->fragments[0]->len);
3299 printk_buf(IPW_DL_TX, txb->fragments[0]->data,
3300 txb->fragments[0]->len);
3302 packet->jiffy_start = jiffies;
3305 DEC_STAT(&priv->tx_free_stat);
3307 list_add_tail(element, &priv->tx_pend_list);
3308 INC_STAT(&priv->tx_pend_stat);
3310 ipw2100_tx_send_data(priv);
3312 spin_unlock_irqrestore(&priv->low_lock, flags);
3316 netif_stop_queue(dev);
3317 spin_unlock_irqrestore(&priv->low_lock, flags);
3322 static int ipw2100_msg_allocate(struct ipw2100_priv *priv)
3324 int i, j, err = -EINVAL;
3328 priv->msg_buffers = (struct ipw2100_tx_packet *)kmalloc(
3329 IPW_COMMAND_POOL_SIZE * sizeof(struct ipw2100_tx_packet),
3331 if (!priv->msg_buffers) {
3332 printk(KERN_ERR DRV_NAME ": %s: PCI alloc failed for msg "
3333 "buffers.\n", priv->net_dev->name);
3337 for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++) {
3338 v = pci_alloc_consistent(
3340 sizeof(struct ipw2100_cmd_header),
3343 printk(KERN_ERR DRV_NAME ": "
3344 "%s: PCI alloc failed for msg "
3346 priv->net_dev->name);
3351 memset(v, 0, sizeof(struct ipw2100_cmd_header));
3353 priv->msg_buffers[i].type = COMMAND;
3354 priv->msg_buffers[i].info.c_struct.cmd =
3355 (struct ipw2100_cmd_header*)v;
3356 priv->msg_buffers[i].info.c_struct.cmd_phys = p;
3359 if (i == IPW_COMMAND_POOL_SIZE)
3362 for (j = 0; j < i; j++) {
3363 pci_free_consistent(
3365 sizeof(struct ipw2100_cmd_header),
3366 priv->msg_buffers[j].info.c_struct.cmd,
3367 priv->msg_buffers[j].info.c_struct.cmd_phys);
3370 kfree(priv->msg_buffers);
3371 priv->msg_buffers = NULL;
3376 static int ipw2100_msg_initialize(struct ipw2100_priv *priv)
3380 INIT_LIST_HEAD(&priv->msg_free_list);
3381 INIT_LIST_HEAD(&priv->msg_pend_list);
3383 for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++)
3384 list_add_tail(&priv->msg_buffers[i].list, &priv->msg_free_list);
3385 SET_STAT(&priv->msg_free_stat, i);
3390 static void ipw2100_msg_free(struct ipw2100_priv *priv)
3394 if (!priv->msg_buffers)
3397 for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++) {
3398 pci_free_consistent(priv->pci_dev,
3399 sizeof(struct ipw2100_cmd_header),
3400 priv->msg_buffers[i].info.c_struct.cmd,
3401 priv->msg_buffers[i].info.c_struct.cmd_phys);
3404 kfree(priv->msg_buffers);
3405 priv->msg_buffers = NULL;
3408 static ssize_t show_pci(struct device *d, struct device_attribute *attr,
3411 struct pci_dev *pci_dev = container_of(d, struct pci_dev, dev);
3416 for (i = 0; i < 16; i++) {
3417 out += sprintf(out, "[%08X] ", i * 16);
3418 for (j = 0; j < 16; j += 4) {
3419 pci_read_config_dword(pci_dev, i * 16 + j, &val);
3420 out += sprintf(out, "%08X ", val);
3422 out += sprintf(out, "\n");
3427 static DEVICE_ATTR(pci, S_IRUGO, show_pci, NULL);
3429 static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
3432 struct ipw2100_priv *p = d->driver_data;
3433 return sprintf(buf, "0x%08x\n", (int)p->config);
3435 static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
3437 static ssize_t show_status(struct device *d, struct device_attribute *attr,
3440 struct ipw2100_priv *p = d->driver_data;
3441 return sprintf(buf, "0x%08x\n", (int)p->status);
3443 static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
3445 static ssize_t show_capability(struct device *d, struct device_attribute *attr,
3448 struct ipw2100_priv *p = d->driver_data;
3449 return sprintf(buf, "0x%08x\n", (int)p->capability);
3451 static DEVICE_ATTR(capability, S_IRUGO, show_capability, NULL);
3454 #define IPW2100_REG(x) { IPW_ ##x, #x }
3455 static const struct {
3459 IPW2100_REG(REG_GP_CNTRL),
3460 IPW2100_REG(REG_GPIO),
3461 IPW2100_REG(REG_INTA),
3462 IPW2100_REG(REG_INTA_MASK),
3463 IPW2100_REG(REG_RESET_REG),
3465 #define IPW2100_NIC(x, s) { x, #x, s }
3466 static const struct {
3471 IPW2100_NIC(IPW2100_CONTROL_REG, 2),
3472 IPW2100_NIC(0x210014, 1),
3473 IPW2100_NIC(0x210000, 1),
3475 #define IPW2100_ORD(x, d) { IPW_ORD_ ##x, #x, d }
3476 static const struct {
3481 IPW2100_ORD(STAT_TX_HOST_REQUESTS, "requested Host Tx's (MSDU)"),
3482 IPW2100_ORD(STAT_TX_HOST_COMPLETE, "successful Host Tx's (MSDU)"),
3483 IPW2100_ORD(STAT_TX_DIR_DATA, "successful Directed Tx's (MSDU)"),
3484 IPW2100_ORD(STAT_TX_DIR_DATA1, "successful Directed Tx's (MSDU) @ 1MB"),
3485 IPW2100_ORD(STAT_TX_DIR_DATA2, "successful Directed Tx's (MSDU) @ 2MB"),
3486 IPW2100_ORD(STAT_TX_DIR_DATA5_5, "successful Directed Tx's (MSDU) @ 5_5MB"),
3487 IPW2100_ORD(STAT_TX_DIR_DATA11, "successful Directed Tx's (MSDU) @ 11MB"),
3488 IPW2100_ORD(STAT_TX_NODIR_DATA1, "successful Non_Directed Tx's (MSDU) @ 1MB"),
3489 IPW2100_ORD(STAT_TX_NODIR_DATA2, "successful Non_Directed Tx's (MSDU) @ 2MB"),
3490 IPW2100_ORD(STAT_TX_NODIR_DATA5_5, "successful Non_Directed Tx's (MSDU) @ 5.5MB"),
3491 IPW2100_ORD(STAT_TX_NODIR_DATA11, "successful Non_Directed Tx's (MSDU) @ 11MB"),
3492 IPW2100_ORD(STAT_NULL_DATA, "successful NULL data Tx's"),
3493 IPW2100_ORD(STAT_TX_RTS, "successful Tx RTS"),
3494 IPW2100_ORD(STAT_TX_CTS, "successful Tx CTS"),
3495 IPW2100_ORD(STAT_TX_ACK, "successful Tx ACK"),
3496 IPW2100_ORD(STAT_TX_ASSN, "successful Association Tx's"),
3497 IPW2100_ORD(STAT_TX_ASSN_RESP, "successful Association response Tx's"),
3498 IPW2100_ORD(STAT_TX_REASSN, "successful Reassociation Tx's"),
3499 IPW2100_ORD(STAT_TX_REASSN_RESP, "successful Reassociation response Tx's"),
3500 IPW2100_ORD(STAT_TX_PROBE, "probes successfully transmitted"),
3501 IPW2100_ORD(STAT_TX_PROBE_RESP, "probe responses successfully transmitted"),
3502 IPW2100_ORD(STAT_TX_BEACON, "tx beacon"),
3503 IPW2100_ORD(STAT_TX_ATIM, "Tx ATIM"),
3504 IPW2100_ORD(STAT_TX_DISASSN, "successful Disassociation TX"),
3505 IPW2100_ORD(STAT_TX_AUTH, "successful Authentication Tx"),
3506 IPW2100_ORD(STAT_TX_DEAUTH, "successful Deauthentication TX"),
3507 IPW2100_ORD(STAT_TX_TOTAL_BYTES, "Total successful Tx data bytes"),
3508 IPW2100_ORD(STAT_TX_RETRIES, "Tx retries"),
3509 IPW2100_ORD(STAT_TX_RETRY1, "Tx retries at 1MBPS"),
3510 IPW2100_ORD(STAT_TX_RETRY2, "Tx retries at 2MBPS"),
3511 IPW2100_ORD(STAT_TX_RETRY5_5, "Tx retries at 5.5MBPS"),
3512 IPW2100_ORD(STAT_TX_RETRY11, "Tx retries at 11MBPS"),
3513 IPW2100_ORD(STAT_TX_FAILURES, "Tx Failures"),
3514 IPW2100_ORD(STAT_TX_MAX_TRIES_IN_HOP,"times max tries in a hop failed"),
3515 IPW2100_ORD(STAT_TX_DISASSN_FAIL, "times disassociation failed"),
3516 IPW2100_ORD(STAT_TX_ERR_CTS, "missed/bad CTS frames"),
3517 IPW2100_ORD(STAT_TX_ERR_ACK, "tx err due to acks"),
3518 IPW2100_ORD(STAT_RX_HOST, "packets passed to host"),
3519 IPW2100_ORD(STAT_RX_DIR_DATA, "directed packets"),
3520 IPW2100_ORD(STAT_RX_DIR_DATA1, "directed packets at 1MB"),
3521 IPW2100_ORD(STAT_RX_DIR_DATA2, "directed packets at 2MB"),
3522 IPW2100_ORD(STAT_RX_DIR_DATA5_5, "directed packets at 5.5MB"),
3523 IPW2100_ORD(STAT_RX_DIR_DATA11, "directed packets at 11MB"),
3524 IPW2100_ORD(STAT_RX_NODIR_DATA,"nondirected packets"),
3525 IPW2100_ORD(STAT_RX_NODIR_DATA1, "nondirected packets at 1MB"),
3526 IPW2100_ORD(STAT_RX_NODIR_DATA2, "nondirected packets at 2MB"),
3527 IPW2100_ORD(STAT_RX_NODIR_DATA5_5, "nondirected packets at 5.5MB"),
3528 IPW2100_ORD(STAT_RX_NODIR_DATA11, "nondirected packets at 11MB"),
3529 IPW2100_ORD(STAT_RX_NULL_DATA, "null data rx's"),
3530 IPW2100_ORD(STAT_RX_RTS, "Rx RTS"),
3531 IPW2100_ORD(STAT_RX_CTS, "Rx CTS"),
3532 IPW2100_ORD(STAT_RX_ACK, "Rx ACK"),
3533 IPW2100_ORD(STAT_RX_CFEND, "Rx CF End"),
3534 IPW2100_ORD(STAT_RX_CFEND_ACK, "Rx CF End + CF Ack"),
3535 IPW2100_ORD(STAT_RX_ASSN, "Association Rx's"),
3536 IPW2100_ORD(STAT_RX_ASSN_RESP, "Association response Rx's"),
3537 IPW2100_ORD(STAT_RX_REASSN, "Reassociation Rx's"),
3538 IPW2100_ORD(STAT_RX_REASSN_RESP, "Reassociation response Rx's"),
3539 IPW2100_ORD(STAT_RX_PROBE, "probe Rx's"),
3540 IPW2100_ORD(STAT_RX_PROBE_RESP, "probe response Rx's"),
3541 IPW2100_ORD(STAT_RX_BEACON, "Rx beacon"),
3542 IPW2100_ORD(STAT_RX_ATIM, "Rx ATIM"),
3543 IPW2100_ORD(STAT_RX_DISASSN, "disassociation Rx"),
3544 IPW2100_ORD(STAT_RX_AUTH, "authentication Rx"),
3545 IPW2100_ORD(STAT_RX_DEAUTH, "deauthentication Rx"),
3546 IPW2100_ORD(STAT_RX_TOTAL_BYTES,"Total rx data bytes received"),
3547 IPW2100_ORD(STAT_RX_ERR_CRC, "packets with Rx CRC error"),
3548 IPW2100_ORD(STAT_RX_ERR_CRC1, "Rx CRC errors at 1MB"),
3549 IPW2100_ORD(STAT_RX_ERR_CRC2, "Rx CRC errors at 2MB"),
3550 IPW2100_ORD(STAT_RX_ERR_CRC5_5, "Rx CRC errors at 5.5MB"),
3551 IPW2100_ORD(STAT_RX_ERR_CRC11, "Rx CRC errors at 11MB"),
3552 IPW2100_ORD(STAT_RX_DUPLICATE1, "duplicate rx packets at 1MB"),
3553 IPW2100_ORD(STAT_RX_DUPLICATE2, "duplicate rx packets at 2MB"),
3554 IPW2100_ORD(STAT_RX_DUPLICATE5_5, "duplicate rx packets at 5.5MB"),
3555 IPW2100_ORD(STAT_RX_DUPLICATE11, "duplicate rx packets at 11MB"),
3556 IPW2100_ORD(STAT_RX_DUPLICATE, "duplicate rx packets"),
3557 IPW2100_ORD(PERS_DB_LOCK, "locking fw permanent db"),
3558 IPW2100_ORD(PERS_DB_SIZE, "size of fw permanent db"),
3559 IPW2100_ORD(PERS_DB_ADDR, "address of fw permanent db"),
3560 IPW2100_ORD(STAT_RX_INVALID_PROTOCOL, "rx frames with invalid protocol"),
3561 IPW2100_ORD(SYS_BOOT_TIME, "Boot time"),
3562 IPW2100_ORD(STAT_RX_NO_BUFFER, "rx frames rejected due to no buffer"),
3563 IPW2100_ORD(STAT_RX_MISSING_FRAG, "rx frames dropped due to missing fragment"),
3564 IPW2100_ORD(STAT_RX_ORPHAN_FRAG, "rx frames dropped due to non-sequential fragment"),
3565 IPW2100_ORD(STAT_RX_ORPHAN_FRAME, "rx frames dropped due to unmatched 1st frame"),
3566 IPW2100_ORD(STAT_RX_FRAG_AGEOUT, "rx frames dropped due to uncompleted frame"),
3567 IPW2100_ORD(STAT_RX_ICV_ERRORS, "ICV errors during decryption"),
3568 IPW2100_ORD(STAT_PSP_SUSPENSION,"times adapter suspended"),
3569 IPW2100_ORD(STAT_PSP_BCN_TIMEOUT, "beacon timeout"),
3570 IPW2100_ORD(STAT_PSP_POLL_TIMEOUT, "poll response timeouts"),
3571 IPW2100_ORD(STAT_PSP_NONDIR_TIMEOUT, "timeouts waiting for last {broad,multi}cast pkt"),
3572 IPW2100_ORD(STAT_PSP_RX_DTIMS, "PSP DTIMs received"),
3573 IPW2100_ORD(STAT_PSP_RX_TIMS, "PSP TIMs received"),
3574 IPW2100_ORD(STAT_PSP_STATION_ID,"PSP Station ID"),
3575 IPW2100_ORD(LAST_ASSN_TIME, "RTC time of last association"),
3576 IPW2100_ORD(STAT_PERCENT_MISSED_BCNS,"current calculation of % missed beacons"),
3577 IPW2100_ORD(STAT_PERCENT_RETRIES,"current calculation of % missed tx retries"),
3578 IPW2100_ORD(ASSOCIATED_AP_PTR, "0 if not associated, else pointer to AP table entry"),
3579 IPW2100_ORD(AVAILABLE_AP_CNT, "AP's decsribed in the AP table"),
3580 IPW2100_ORD(AP_LIST_PTR, "Ptr to list of available APs"),
3581 IPW2100_ORD(STAT_AP_ASSNS, "associations"),
3582 IPW2100_ORD(STAT_ASSN_FAIL, "association failures"),
3583 IPW2100_ORD(STAT_ASSN_RESP_FAIL,"failures due to response fail"),
3584 IPW2100_ORD(STAT_FULL_SCANS, "full scans"),
3585 IPW2100_ORD(CARD_DISABLED, "Card Disabled"),
3586 IPW2100_ORD(STAT_ROAM_INHIBIT, "times roaming was inhibited due to activity"),
3587 IPW2100_ORD(RSSI_AT_ASSN, "RSSI of associated AP at time of association"),
3588 IPW2100_ORD(STAT_ASSN_CAUSE1, "reassociation: no probe response or TX on hop"),
3589 IPW2100_ORD(STAT_ASSN_CAUSE2, "reassociation: poor tx/rx quality"),
3590 IPW2100_ORD(STAT_ASSN_CAUSE3, "reassociation: tx/rx quality (excessive AP load"),
3591 IPW2100_ORD(STAT_ASSN_CAUSE4, "reassociation: AP RSSI level"),
3592 IPW2100_ORD(STAT_ASSN_CAUSE5, "reassociations due to load leveling"),
3593 IPW2100_ORD(STAT_AUTH_FAIL, "times authentication failed"),
3594 IPW2100_ORD(STAT_AUTH_RESP_FAIL,"times authentication response failed"),
3595 IPW2100_ORD(STATION_TABLE_CNT, "entries in association table"),
3596 IPW2100_ORD(RSSI_AVG_CURR, "Current avg RSSI"),
3597 IPW2100_ORD(POWER_MGMT_MODE, "Power mode - 0=CAM, 1=PSP"),
3598 IPW2100_ORD(COUNTRY_CODE, "IEEE country code as recv'd from beacon"),
3599 IPW2100_ORD(COUNTRY_CHANNELS, "channels suported by country"),
3600 IPW2100_ORD(RESET_CNT, "adapter resets (warm)"),
3601 IPW2100_ORD(BEACON_INTERVAL, "Beacon interval"),
3602 IPW2100_ORD(ANTENNA_DIVERSITY, "TRUE if antenna diversity is disabled"),
3603 IPW2100_ORD(DTIM_PERIOD, "beacon intervals between DTIMs"),
3604 IPW2100_ORD(OUR_FREQ, "current radio freq lower digits - channel ID"),
3605 IPW2100_ORD(RTC_TIME, "current RTC time"),
3606 IPW2100_ORD(PORT_TYPE, "operating mode"),
3607 IPW2100_ORD(CURRENT_TX_RATE, "current tx rate"),
3608 IPW2100_ORD(SUPPORTED_RATES, "supported tx rates"),
3609 IPW2100_ORD(ATIM_WINDOW, "current ATIM Window"),
3610 IPW2100_ORD(BASIC_RATES, "basic tx rates"),
3611 IPW2100_ORD(NIC_HIGHEST_RATE, "NIC highest tx rate"),
3612 IPW2100_ORD(AP_HIGHEST_RATE, "AP highest tx rate"),
3613 IPW2100_ORD(CAPABILITIES, "Management frame capability field"),
3614 IPW2100_ORD(AUTH_TYPE, "Type of authentication"),
3615 IPW2100_ORD(RADIO_TYPE, "Adapter card platform type"),
3616 IPW2100_ORD(RTS_THRESHOLD, "Min packet length for RTS handshaking"),
3617 IPW2100_ORD(INT_MODE, "International mode"),
3618 IPW2100_ORD(FRAGMENTATION_THRESHOLD, "protocol frag threshold"),
3619 IPW2100_ORD(EEPROM_SRAM_DB_BLOCK_START_ADDRESS, "EEPROM offset in SRAM"),
3620 IPW2100_ORD(EEPROM_SRAM_DB_BLOCK_SIZE, "EEPROM size in SRAM"),
3621 IPW2100_ORD(EEPROM_SKU_CAPABILITY, "EEPROM SKU Capability"),
3622 IPW2100_ORD(EEPROM_IBSS_11B_CHANNELS, "EEPROM IBSS 11b channel set"),
3623 IPW2100_ORD(MAC_VERSION, "MAC Version"),
3624 IPW2100_ORD(MAC_REVISION, "MAC Revision"),
3625 IPW2100_ORD(RADIO_VERSION, "Radio Version"),
3626 IPW2100_ORD(NIC_MANF_DATE_TIME, "MANF Date/Time STAMP"),
3627 IPW2100_ORD(UCODE_VERSION, "Ucode Version"),
3631 static ssize_t show_registers(struct device *d, struct device_attribute *attr,
3635 struct ipw2100_priv *priv = dev_get_drvdata(d);
3636 struct net_device *dev = priv->net_dev;
3640 out += sprintf(out, "%30s [Address ] : Hex\n", "Register");
3642 for (i = 0; i < (sizeof(hw_data) / sizeof(*hw_data)); i++) {
3643 read_register(dev, hw_data[i].addr, &val);
3644 out += sprintf(out, "%30s [%08X] : %08X\n",
3645 hw_data[i].name, hw_data[i].addr, val);
3650 static DEVICE_ATTR(registers, S_IRUGO, show_registers, NULL);
3653 static ssize_t show_hardware(struct device *d, struct device_attribute *attr,
3656 struct ipw2100_priv *priv = dev_get_drvdata(d);
3657 struct net_device *dev = priv->net_dev;
3661 out += sprintf(out, "%30s [Address ] : Hex\n", "NIC entry");
3663 for (i = 0; i < (sizeof(nic_data) / sizeof(*nic_data)); i++) {
3668 switch (nic_data[i].size) {
3670 read_nic_byte(dev, nic_data[i].addr, &tmp8);
3671 out += sprintf(out, "%30s [%08X] : %02X\n",
3672 nic_data[i].name, nic_data[i].addr,
3676 read_nic_word(dev, nic_data[i].addr, &tmp16);
3677 out += sprintf(out, "%30s [%08X] : %04X\n",
3678 nic_data[i].name, nic_data[i].addr,
3682 read_nic_dword(dev, nic_data[i].addr, &tmp32);
3683 out += sprintf(out, "%30s [%08X] : %08X\n",
3684 nic_data[i].name, nic_data[i].addr,
3691 static DEVICE_ATTR(hardware, S_IRUGO, show_hardware, NULL);
3694 static ssize_t show_memory(struct device *d, struct device_attribute *attr,
3697 struct ipw2100_priv *priv = dev_get_drvdata(d);
3698 struct net_device *dev = priv->net_dev;
3699 static unsigned long loop = 0;
3705 if (loop >= 0x30000)
3708 /* sysfs provides us PAGE_SIZE buffer */
3709 while (len < PAGE_SIZE - 128 && loop < 0x30000) {
3711 if (priv->snapshot[0]) for (i = 0; i < 4; i++)
3712 buffer[i] = *(u32 *)SNAPSHOT_ADDR(loop + i * 4);
3713 else for (i = 0; i < 4; i++)
3714 read_nic_dword(dev, loop + i * 4, &buffer[i]);
3717 len += sprintf(buf + len,
3737 ((u8*)buffer)[0xf]);
3739 len += sprintf(buf + len, "%s\n",
3740 snprint_line(line, sizeof(line),
3741 (u8*)buffer, 16, loop));
3748 static ssize_t store_memory(struct device *d, struct device_attribute *attr,
3749 const char *buf, size_t count)
3751 struct ipw2100_priv *priv = dev_get_drvdata(d);
3752 struct net_device *dev = priv->net_dev;
3753 const char *p = buf;
3759 (count >= 2 && tolower(p[0]) == 'o' && tolower(p[1]) == 'n')) {
3760 IPW_DEBUG_INFO("%s: Setting memory dump to RAW mode.\n",
3764 } else if (p[0] == '0' || (count >= 2 && tolower(p[0]) == 'o' &&
3765 tolower(p[1]) == 'f')) {
3766 IPW_DEBUG_INFO("%s: Setting memory dump to HEX mode.\n",
3770 } else if (tolower(p[0]) == 'r') {
3771 IPW_DEBUG_INFO("%s: Resetting firmware snapshot.\n",
3773 ipw2100_snapshot_free(priv);
3776 IPW_DEBUG_INFO("%s: Usage: 0|on = HEX, 1|off = RAW, "
3777 "reset = clear memory snapshot\n",
3782 static DEVICE_ATTR(memory, S_IWUSR|S_IRUGO, show_memory, store_memory);
3785 static ssize_t show_ordinals(struct device *d, struct device_attribute *attr,
3788 struct ipw2100_priv *priv = dev_get_drvdata(d);
3792 static int loop = 0;
3794 if (loop >= sizeof(ord_data) / sizeof(*ord_data))
3797 /* sysfs provides us PAGE_SIZE buffer */
3798 while (len < PAGE_SIZE - 128 &&
3799 loop < (sizeof(ord_data) / sizeof(*ord_data))) {
3801 val_len = sizeof(u32);
3803 if (ipw2100_get_ordinal(priv, ord_data[loop].index, &val,
3805 len += sprintf(buf + len, "[0x%02X] = ERROR %s\n",
3806 ord_data[loop].index,
3807 ord_data[loop].desc);
3809 len += sprintf(buf + len, "[0x%02X] = 0x%08X %s\n",
3810 ord_data[loop].index, val,
3811 ord_data[loop].desc);
3817 static DEVICE_ATTR(ordinals, S_IRUGO, show_ordinals, NULL);
3820 static ssize_t show_stats(struct device *d, struct device_attribute *attr,
3823 struct ipw2100_priv *priv = dev_get_drvdata(d);
3826 out += sprintf(out, "interrupts: %d {tx: %d, rx: %d, other: %d}\n",
3827 priv->interrupts, priv->tx_interrupts,
3828 priv->rx_interrupts, priv->inta_other);
3829 out += sprintf(out, "firmware resets: %d\n", priv->resets);
3830 out += sprintf(out, "firmware hangs: %d\n", priv->hangs);
3831 #ifdef CONFIG_IPW_DEBUG
3832 out += sprintf(out, "packet mismatch image: %s\n",
3833 priv->snapshot[0] ? "YES" : "NO");
3838 static DEVICE_ATTR(stats, S_IRUGO, show_stats, NULL);
3841 static int ipw2100_switch_mode(struct ipw2100_priv *priv, u32 mode)
3845 if (mode == priv->ieee->iw_mode)
3848 err = ipw2100_disable_adapter(priv);
3850 printk(KERN_ERR DRV_NAME ": %s: Could not disable adapter %d\n",
3851 priv->net_dev->name, err);
3857 priv->net_dev->type = ARPHRD_ETHER;
3860 priv->net_dev->type = ARPHRD_ETHER;
3862 #ifdef CONFIG_IPW2100_MONITOR
3863 case IW_MODE_MONITOR:
3864 priv->last_mode = priv->ieee->iw_mode;
3865 priv->net_dev->type = ARPHRD_IEEE80211;
3867 #endif /* CONFIG_IPW2100_MONITOR */
3870 priv->ieee->iw_mode = mode;
3873 /* Indicate ipw2100_download_firmware download firmware
3874 * from disk instead of memory. */
3875 ipw2100_firmware.version = 0;
3878 printk(KERN_INFO "%s: Reseting on mode change.\n",
3879 priv->net_dev->name);
3880 priv->reset_backoff = 0;
3881 schedule_reset(priv);
3886 static ssize_t show_internals(struct device *d, struct device_attribute *attr,
3889 struct ipw2100_priv *priv = dev_get_drvdata(d);
3892 #define DUMP_VAR(x,y) len += sprintf(buf + len, # x ": %" # y "\n", priv-> x)
3894 if (priv->status & STATUS_ASSOCIATED)
3895 len += sprintf(buf + len, "connected: %lu\n",
3896 get_seconds() - priv->connect_start);
3898 len += sprintf(buf + len, "not connected\n");
3900 DUMP_VAR(ieee->crypt[priv->ieee->tx_keyidx], p);
3901 DUMP_VAR(status, 08lx);
3902 DUMP_VAR(config, 08lx);
3903 DUMP_VAR(capability, 08lx);
3905 len += sprintf(buf + len, "last_rtc: %lu\n", (unsigned long)priv->last_rtc);
3907 DUMP_VAR(fatal_error, d);
3908 DUMP_VAR(stop_hang_check, d);
3909 DUMP_VAR(stop_rf_kill, d);
3910 DUMP_VAR(messages_sent, d);
3912 DUMP_VAR(tx_pend_stat.value, d);
3913 DUMP_VAR(tx_pend_stat.hi, d);
3915 DUMP_VAR(tx_free_stat.value, d);
3916 DUMP_VAR(tx_free_stat.lo, d);
3918 DUMP_VAR(msg_free_stat.value, d);
3919 DUMP_VAR(msg_free_stat.lo, d);
3921 DUMP_VAR(msg_pend_stat.value, d);
3922 DUMP_VAR(msg_pend_stat.hi, d);
3924 DUMP_VAR(fw_pend_stat.value, d);
3925 DUMP_VAR(fw_pend_stat.hi, d);
3927 DUMP_VAR(txq_stat.value, d);
3928 DUMP_VAR(txq_stat.lo, d);
3930 DUMP_VAR(ieee->scans, d);
3931 DUMP_VAR(reset_backoff, d);
3935 static DEVICE_ATTR(internals, S_IRUGO, show_internals, NULL);
3938 static ssize_t show_bssinfo(struct device *d, struct device_attribute *attr,
3941 struct ipw2100_priv *priv = dev_get_drvdata(d);
3942 char essid[IW_ESSID_MAX_SIZE + 1];
3949 memset(essid, 0, sizeof(essid));
3950 memset(bssid, 0, sizeof(bssid));
3952 length = IW_ESSID_MAX_SIZE;
3953 ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_SSID, essid, &length);
3955 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
3958 length = sizeof(bssid);
3959 ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID,
3962 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
3965 length = sizeof(u32);
3966 ret = ipw2100_get_ordinal(priv, IPW_ORD_OUR_FREQ, &chan, &length);
3968 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
3971 out += sprintf(out, "ESSID: %s\n", essid);
3972 out += sprintf(out, "BSSID: %02x:%02x:%02x:%02x:%02x:%02x\n",
3973 bssid[0], bssid[1], bssid[2],
3974 bssid[3], bssid[4], bssid[5]);
3975 out += sprintf(out, "Channel: %d\n", chan);
3979 static DEVICE_ATTR(bssinfo, S_IRUGO, show_bssinfo, NULL);
3982 #ifdef CONFIG_IPW_DEBUG
3983 static ssize_t show_debug_level(struct device_driver *d, char *buf)
3985 return sprintf(buf, "0x%08X\n", ipw2100_debug_level);
3988 static ssize_t store_debug_level(struct device_driver *d, const char *buf,
3991 char *p = (char *)buf;
3994 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
3996 if (p[0] == 'x' || p[0] == 'X')
3998 val = simple_strtoul(p, &p, 16);
4000 val = simple_strtoul(p, &p, 10);
4002 IPW_DEBUG_INFO(DRV_NAME
4003 ": %s is not in hex or decimal form.\n", buf);
4005 ipw2100_debug_level = val;
4007 return strnlen(buf, count);
4009 static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, show_debug_level,
4011 #endif /* CONFIG_IPW_DEBUG */
4014 static ssize_t show_fatal_error(struct device *d,
4015 struct device_attribute *attr, char *buf)
4017 struct ipw2100_priv *priv = dev_get_drvdata(d);
4021 if (priv->fatal_error)
4022 out += sprintf(out, "0x%08X\n",
4025 out += sprintf(out, "0\n");
4027 for (i = 1; i <= IPW2100_ERROR_QUEUE; i++) {
4028 if (!priv->fatal_errors[(priv->fatal_index - i) %
4029 IPW2100_ERROR_QUEUE])
4032 out += sprintf(out, "%d. 0x%08X\n", i,
4033 priv->fatal_errors[(priv->fatal_index - i) %
4034 IPW2100_ERROR_QUEUE]);
4040 static ssize_t store_fatal_error(struct device *d,
4041 struct device_attribute *attr, const char *buf, size_t count)
4043 struct ipw2100_priv *priv = dev_get_drvdata(d);
4044 schedule_reset(priv);
4047 static DEVICE_ATTR(fatal_error, S_IWUSR|S_IRUGO, show_fatal_error, store_fatal_error);
4050 static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
4053 struct ipw2100_priv *priv = dev_get_drvdata(d);
4054 return sprintf(buf, "%d\n", priv->ieee->scan_age);
4057 static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
4058 const char *buf, size_t count)
4060 struct ipw2100_priv *priv = dev_get_drvdata(d);
4061 struct net_device *dev = priv->net_dev;
4062 char buffer[] = "00000000";
4064 (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
4068 IPW_DEBUG_INFO("enter\n");
4070 strncpy(buffer, buf, len);
4073 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
4075 if (p[0] == 'x' || p[0] == 'X')
4077 val = simple_strtoul(p, &p, 16);
4079 val = simple_strtoul(p, &p, 10);
4081 IPW_DEBUG_INFO("%s: user supplied invalid value.\n",
4084 priv->ieee->scan_age = val;
4085 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
4088 IPW_DEBUG_INFO("exit\n");
4091 static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
4094 static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
4097 /* 0 - RF kill not enabled
4098 1 - SW based RF kill active (sysfs)
4099 2 - HW based RF kill active
4100 3 - Both HW and SW baed RF kill active */
4101 struct ipw2100_priv *priv = (struct ipw2100_priv *)d->driver_data;
4102 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
4103 (rf_kill_active(priv) ? 0x2 : 0x0);
4104 return sprintf(buf, "%i\n", val);
4107 static int ipw_radio_kill_sw(struct ipw2100_priv *priv, int disable_radio)
4109 if ((disable_radio ? 1 : 0) ==
4110 (priv->status & STATUS_RF_KILL_SW ? 1 : 0))
4113 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
4114 disable_radio ? "OFF" : "ON");
4116 down(&priv->action_sem);
4118 if (disable_radio) {
4119 priv->status |= STATUS_RF_KILL_SW;
4122 priv->status &= ~STATUS_RF_KILL_SW;
4123 if (rf_kill_active(priv)) {
4124 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
4125 "disabled by HW switch\n");
4126 /* Make sure the RF_KILL check timer is running */
4127 priv->stop_rf_kill = 0;
4128 cancel_delayed_work(&priv->rf_kill);
4129 queue_delayed_work(priv->workqueue, &priv->rf_kill,
4132 schedule_reset(priv);
4135 up(&priv->action_sem);
4139 static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
4140 const char *buf, size_t count)
4142 struct ipw2100_priv *priv = dev_get_drvdata(d);
4143 ipw_radio_kill_sw(priv, buf[0] == '1');
4146 static DEVICE_ATTR(rf_kill, S_IWUSR|S_IRUGO, show_rf_kill, store_rf_kill);
4149 static struct attribute *ipw2100_sysfs_entries[] = {
4150 &dev_attr_hardware.attr,
4151 &dev_attr_registers.attr,
4152 &dev_attr_ordinals.attr,
4154 &dev_attr_stats.attr,
4155 &dev_attr_internals.attr,
4156 &dev_attr_bssinfo.attr,
4157 &dev_attr_memory.attr,
4158 &dev_attr_scan_age.attr,
4159 &dev_attr_fatal_error.attr,
4160 &dev_attr_rf_kill.attr,
4162 &dev_attr_status.attr,
4163 &dev_attr_capability.attr,
4167 static struct attribute_group ipw2100_attribute_group = {
4168 .attrs = ipw2100_sysfs_entries,
4172 static int status_queue_allocate(struct ipw2100_priv *priv, int entries)
4174 struct ipw2100_status_queue *q = &priv->status_queue;
4176 IPW_DEBUG_INFO("enter\n");
4178 q->size = entries * sizeof(struct ipw2100_status);
4179 q->drv = (struct ipw2100_status *)pci_alloc_consistent(
4180 priv->pci_dev, q->size, &q->nic);
4183 "Can not allocate status queue.\n");
4187 memset(q->drv, 0, q->size);
4189 IPW_DEBUG_INFO("exit\n");
4194 static void status_queue_free(struct ipw2100_priv *priv)
4196 IPW_DEBUG_INFO("enter\n");
4198 if (priv->status_queue.drv) {
4199 pci_free_consistent(
4200 priv->pci_dev, priv->status_queue.size,
4201 priv->status_queue.drv, priv->status_queue.nic);
4202 priv->status_queue.drv = NULL;
4205 IPW_DEBUG_INFO("exit\n");
4208 static int bd_queue_allocate(struct ipw2100_priv *priv,
4209 struct ipw2100_bd_queue *q, int entries)
4211 IPW_DEBUG_INFO("enter\n");
4213 memset(q, 0, sizeof(struct ipw2100_bd_queue));
4215 q->entries = entries;
4216 q->size = entries * sizeof(struct ipw2100_bd);
4217 q->drv = pci_alloc_consistent(priv->pci_dev, q->size, &q->nic);
4219 IPW_DEBUG_INFO("can't allocate shared memory for buffer descriptors\n");
4222 memset(q->drv, 0, q->size);
4224 IPW_DEBUG_INFO("exit\n");
4229 static void bd_queue_free(struct ipw2100_priv *priv,
4230 struct ipw2100_bd_queue *q)
4232 IPW_DEBUG_INFO("enter\n");
4238 pci_free_consistent(priv->pci_dev,
4239 q->size, q->drv, q->nic);
4243 IPW_DEBUG_INFO("exit\n");
4246 static void bd_queue_initialize(
4247 struct ipw2100_priv *priv, struct ipw2100_bd_queue * q,
4248 u32 base, u32 size, u32 r, u32 w)
4250 IPW_DEBUG_INFO("enter\n");
4252 IPW_DEBUG_INFO("initializing bd queue at virt=%p, phys=%08x\n", q->drv, (u32)q->nic);
4254 write_register(priv->net_dev, base, q->nic);
4255 write_register(priv->net_dev, size, q->entries);
4256 write_register(priv->net_dev, r, q->oldest);
4257 write_register(priv->net_dev, w, q->next);
4259 IPW_DEBUG_INFO("exit\n");
4262 static void ipw2100_kill_workqueue(struct ipw2100_priv *priv)
4264 if (priv->workqueue) {
4265 priv->stop_rf_kill = 1;
4266 priv->stop_hang_check = 1;
4267 cancel_delayed_work(&priv->reset_work);
4268 cancel_delayed_work(&priv->security_work);
4269 cancel_delayed_work(&priv->wx_event_work);
4270 cancel_delayed_work(&priv->hang_check);
4271 cancel_delayed_work(&priv->rf_kill);
4272 destroy_workqueue(priv->workqueue);
4273 priv->workqueue = NULL;
4277 static int ipw2100_tx_allocate(struct ipw2100_priv *priv)
4279 int i, j, err = -EINVAL;
4283 IPW_DEBUG_INFO("enter\n");
4285 err = bd_queue_allocate(priv, &priv->tx_queue, TX_QUEUE_LENGTH);
4287 IPW_DEBUG_ERROR("%s: failed bd_queue_allocate\n",
4288 priv->net_dev->name);
4292 priv->tx_buffers = (struct ipw2100_tx_packet *)kmalloc(
4293 TX_PENDED_QUEUE_LENGTH * sizeof(struct ipw2100_tx_packet),
4295 if (!priv->tx_buffers) {
4296 printk(KERN_ERR DRV_NAME ": %s: alloc failed form tx buffers.\n",
4297 priv->net_dev->name);
4298 bd_queue_free(priv, &priv->tx_queue);
4302 for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
4303 v = pci_alloc_consistent(
4304 priv->pci_dev, sizeof(struct ipw2100_data_header), &p);
4306 printk(KERN_ERR DRV_NAME ": %s: PCI alloc failed for tx "
4307 "buffers.\n", priv->net_dev->name);
4312 priv->tx_buffers[i].type = DATA;
4313 priv->tx_buffers[i].info.d_struct.data = (struct ipw2100_data_header*)v;
4314 priv->tx_buffers[i].info.d_struct.data_phys = p;
4315 priv->tx_buffers[i].info.d_struct.txb = NULL;
4318 if (i == TX_PENDED_QUEUE_LENGTH)
4321 for (j = 0; j < i; j++) {
4322 pci_free_consistent(
4324 sizeof(struct ipw2100_data_header),
4325 priv->tx_buffers[j].info.d_struct.data,
4326 priv->tx_buffers[j].info.d_struct.data_phys);
4329 kfree(priv->tx_buffers);
4330 priv->tx_buffers = NULL;
4335 static void ipw2100_tx_initialize(struct ipw2100_priv *priv)
4339 IPW_DEBUG_INFO("enter\n");
4342 * reinitialize packet info lists
4344 INIT_LIST_HEAD(&priv->fw_pend_list);
4345 INIT_STAT(&priv->fw_pend_stat);
4348 * reinitialize lists
4350 INIT_LIST_HEAD(&priv->tx_pend_list);
4351 INIT_LIST_HEAD(&priv->tx_free_list);
4352 INIT_STAT(&priv->tx_pend_stat);
4353 INIT_STAT(&priv->tx_free_stat);
4355 for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
4356 /* We simply drop any SKBs that have been queued for
4358 if (priv->tx_buffers[i].info.d_struct.txb) {
4359 ieee80211_txb_free(priv->tx_buffers[i].info.d_struct.txb);
4360 priv->tx_buffers[i].info.d_struct.txb = NULL;
4363 list_add_tail(&priv->tx_buffers[i].list, &priv->tx_free_list);
4366 SET_STAT(&priv->tx_free_stat, i);
4368 priv->tx_queue.oldest = 0;
4369 priv->tx_queue.available = priv->tx_queue.entries;
4370 priv->tx_queue.next = 0;
4371 INIT_STAT(&priv->txq_stat);
4372 SET_STAT(&priv->txq_stat, priv->tx_queue.available);
4374 bd_queue_initialize(priv, &priv->tx_queue,
4375 IPW_MEM_HOST_SHARED_TX_QUEUE_BD_BASE,
4376 IPW_MEM_HOST_SHARED_TX_QUEUE_BD_SIZE,
4377 IPW_MEM_HOST_SHARED_TX_QUEUE_READ_INDEX,
4378 IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX);
4380 IPW_DEBUG_INFO("exit\n");
4384 static void ipw2100_tx_free(struct ipw2100_priv *priv)
4388 IPW_DEBUG_INFO("enter\n");
4390 bd_queue_free(priv, &priv->tx_queue);
4392 if (!priv->tx_buffers)
4395 for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
4396 if (priv->tx_buffers[i].info.d_struct.txb) {
4397 ieee80211_txb_free(priv->tx_buffers[i].info.d_struct.txb);
4398 priv->tx_buffers[i].info.d_struct.txb = NULL;
4400 if (priv->tx_buffers[i].info.d_struct.data)
4401 pci_free_consistent(
4403 sizeof(struct ipw2100_data_header),
4404 priv->tx_buffers[i].info.d_struct.data,
4405 priv->tx_buffers[i].info.d_struct.data_phys);
4408 kfree(priv->tx_buffers);
4409 priv->tx_buffers = NULL;
4411 IPW_DEBUG_INFO("exit\n");
4416 static int ipw2100_rx_allocate(struct ipw2100_priv *priv)
4418 int i, j, err = -EINVAL;
4420 IPW_DEBUG_INFO("enter\n");
4422 err = bd_queue_allocate(priv, &priv->rx_queue, RX_QUEUE_LENGTH);
4424 IPW_DEBUG_INFO("failed bd_queue_allocate\n");
4428 err = status_queue_allocate(priv, RX_QUEUE_LENGTH);
4430 IPW_DEBUG_INFO("failed status_queue_allocate\n");
4431 bd_queue_free(priv, &priv->rx_queue);
4438 priv->rx_buffers = (struct ipw2100_rx_packet *)
4439 kmalloc(RX_QUEUE_LENGTH * sizeof(struct ipw2100_rx_packet),
4441 if (!priv->rx_buffers) {
4442 IPW_DEBUG_INFO("can't allocate rx packet buffer table\n");
4444 bd_queue_free(priv, &priv->rx_queue);
4446 status_queue_free(priv);
4451 for (i = 0; i < RX_QUEUE_LENGTH; i++) {
4452 struct ipw2100_rx_packet *packet = &priv->rx_buffers[i];
4454 err = ipw2100_alloc_skb(priv, packet);
4455 if (unlikely(err)) {
4460 /* The BD holds the cache aligned address */
4461 priv->rx_queue.drv[i].host_addr = packet->dma_addr;
4462 priv->rx_queue.drv[i].buf_length = IPW_RX_NIC_BUFFER_LENGTH;
4463 priv->status_queue.drv[i].status_fields = 0;
4466 if (i == RX_QUEUE_LENGTH)
4469 for (j = 0; j < i; j++) {
4470 pci_unmap_single(priv->pci_dev, priv->rx_buffers[j].dma_addr,
4471 sizeof(struct ipw2100_rx_packet),
4472 PCI_DMA_FROMDEVICE);
4473 dev_kfree_skb(priv->rx_buffers[j].skb);
4476 kfree(priv->rx_buffers);
4477 priv->rx_buffers = NULL;
4479 bd_queue_free(priv, &priv->rx_queue);
4481 status_queue_free(priv);
4486 static void ipw2100_rx_initialize(struct ipw2100_priv *priv)
4488 IPW_DEBUG_INFO("enter\n");
4490 priv->rx_queue.oldest = 0;
4491 priv->rx_queue.available = priv->rx_queue.entries - 1;
4492 priv->rx_queue.next = priv->rx_queue.entries - 1;
4494 INIT_STAT(&priv->rxq_stat);
4495 SET_STAT(&priv->rxq_stat, priv->rx_queue.available);
4497 bd_queue_initialize(priv, &priv->rx_queue,
4498 IPW_MEM_HOST_SHARED_RX_BD_BASE,
4499 IPW_MEM_HOST_SHARED_RX_BD_SIZE,
4500 IPW_MEM_HOST_SHARED_RX_READ_INDEX,
4501 IPW_MEM_HOST_SHARED_RX_WRITE_INDEX);
4503 /* set up the status queue */
4504 write_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_STATUS_BASE,
4505 priv->status_queue.nic);
4507 IPW_DEBUG_INFO("exit\n");
4510 static void ipw2100_rx_free(struct ipw2100_priv *priv)
4514 IPW_DEBUG_INFO("enter\n");
4516 bd_queue_free(priv, &priv->rx_queue);
4517 status_queue_free(priv);
4519 if (!priv->rx_buffers)
4522 for (i = 0; i < RX_QUEUE_LENGTH; i++) {
4523 if (priv->rx_buffers[i].rxp) {
4524 pci_unmap_single(priv->pci_dev,
4525 priv->rx_buffers[i].dma_addr,
4526 sizeof(struct ipw2100_rx),
4527 PCI_DMA_FROMDEVICE);
4528 dev_kfree_skb(priv->rx_buffers[i].skb);
4532 kfree(priv->rx_buffers);
4533 priv->rx_buffers = NULL;
4535 IPW_DEBUG_INFO("exit\n");
4538 static int ipw2100_read_mac_address(struct ipw2100_priv *priv)
4540 u32 length = ETH_ALEN;
4545 err = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ADAPTER_MAC,
4548 IPW_DEBUG_INFO("MAC address read failed\n");
4551 IPW_DEBUG_INFO("card MAC is %02X:%02X:%02X:%02X:%02X:%02X\n",
4552 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
4554 memcpy(priv->net_dev->dev_addr, mac, ETH_ALEN);
4559 /********************************************************************
4563 ********************************************************************/
4565 static int ipw2100_set_mac_address(struct ipw2100_priv *priv, int batch_mode)
4567 struct host_command cmd = {
4568 .host_command = ADAPTER_ADDRESS,
4569 .host_command_sequence = 0,
4570 .host_command_length = ETH_ALEN
4574 IPW_DEBUG_HC("SET_MAC_ADDRESS\n");
4576 IPW_DEBUG_INFO("enter\n");
4578 if (priv->config & CFG_CUSTOM_MAC) {
4579 memcpy(cmd.host_command_parameters, priv->mac_addr,
4581 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
4583 memcpy(cmd.host_command_parameters, priv->net_dev->dev_addr,
4586 err = ipw2100_hw_send_command(priv, &cmd);
4588 IPW_DEBUG_INFO("exit\n");
4592 static int ipw2100_set_port_type(struct ipw2100_priv *priv, u32 port_type,
4595 struct host_command cmd = {
4596 .host_command = PORT_TYPE,
4597 .host_command_sequence = 0,
4598 .host_command_length = sizeof(u32)
4602 switch (port_type) {
4604 cmd.host_command_parameters[0] = IPW_BSS;
4607 cmd.host_command_parameters[0] = IPW_IBSS;
4611 IPW_DEBUG_HC("PORT_TYPE: %s\n",
4612 port_type == IPW_IBSS ? "Ad-Hoc" : "Managed");
4615 err = ipw2100_disable_adapter(priv);
4617 printk(KERN_ERR DRV_NAME ": %s: Could not disable adapter %d\n",
4618 priv->net_dev->name, err);
4623 /* send cmd to firmware */
4624 err = ipw2100_hw_send_command(priv, &cmd);
4627 ipw2100_enable_adapter(priv);
4633 static int ipw2100_set_channel(struct ipw2100_priv *priv, u32 channel,
4636 struct host_command cmd = {
4637 .host_command = CHANNEL,
4638 .host_command_sequence = 0,
4639 .host_command_length = sizeof(u32)
4643 cmd.host_command_parameters[0] = channel;
4645 IPW_DEBUG_HC("CHANNEL: %d\n", channel);
4647 /* If BSS then we don't support channel selection */
4648 if (priv->ieee->iw_mode == IW_MODE_INFRA)
4651 if ((channel != 0) &&
4652 ((channel < REG_MIN_CHANNEL) || (channel > REG_MAX_CHANNEL)))
4656 err = ipw2100_disable_adapter(priv);
4661 err = ipw2100_hw_send_command(priv, &cmd);
4663 IPW_DEBUG_INFO("Failed to set channel to %d",
4669 priv->config |= CFG_STATIC_CHANNEL;
4671 priv->config &= ~CFG_STATIC_CHANNEL;
4673 priv->channel = channel;
4676 err = ipw2100_enable_adapter(priv);
4684 static int ipw2100_system_config(struct ipw2100_priv *priv, int batch_mode)
4686 struct host_command cmd = {
4687 .host_command = SYSTEM_CONFIG,
4688 .host_command_sequence = 0,
4689 .host_command_length = 12,
4691 u32 ibss_mask, len = sizeof(u32);
4694 /* Set system configuration */
4697 err = ipw2100_disable_adapter(priv);
4702 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
4703 cmd.host_command_parameters[0] |= IPW_CFG_IBSS_AUTO_START;
4705 cmd.host_command_parameters[0] |= IPW_CFG_IBSS_MASK |
4707 IPW_CFG_802_1x_ENABLE;
4709 if (!(priv->config & CFG_LONG_PREAMBLE))
4710 cmd.host_command_parameters[0] |= IPW_CFG_PREAMBLE_AUTO;
4712 err = ipw2100_get_ordinal(priv,
4713 IPW_ORD_EEPROM_IBSS_11B_CHANNELS,
4716 ibss_mask = IPW_IBSS_11B_DEFAULT_MASK;
4718 cmd.host_command_parameters[1] = REG_CHANNEL_MASK;
4719 cmd.host_command_parameters[2] = REG_CHANNEL_MASK & ibss_mask;
4722 /*cmd.host_command_parameters[0] |= DIVERSITY_ANTENNA_A;*/
4724 err = ipw2100_hw_send_command(priv, &cmd);
4728 /* If IPv6 is configured in the kernel then we don't want to filter out all
4729 * of the multicast packets as IPv6 needs some. */
4730 #if !defined(CONFIG_IPV6) && !defined(CONFIG_IPV6_MODULE)
4731 cmd.host_command = ADD_MULTICAST;
4732 cmd.host_command_sequence = 0;
4733 cmd.host_command_length = 0;
4735 ipw2100_hw_send_command(priv, &cmd);
4738 err = ipw2100_enable_adapter(priv);
4746 static int ipw2100_set_tx_rates(struct ipw2100_priv *priv, u32 rate,
4749 struct host_command cmd = {
4750 .host_command = BASIC_TX_RATES,
4751 .host_command_sequence = 0,
4752 .host_command_length = 4
4756 cmd.host_command_parameters[0] = rate & TX_RATE_MASK;
4759 err = ipw2100_disable_adapter(priv);
4764 /* Set BASIC TX Rate first */
4765 ipw2100_hw_send_command(priv, &cmd);
4768 cmd.host_command = TX_RATES;
4769 ipw2100_hw_send_command(priv, &cmd);
4771 /* Set MSDU TX Rate */
4772 cmd.host_command = MSDU_TX_RATES;
4773 ipw2100_hw_send_command(priv, &cmd);
4776 err = ipw2100_enable_adapter(priv);
4781 priv->tx_rates = rate;
4786 static int ipw2100_set_power_mode(struct ipw2100_priv *priv,
4789 struct host_command cmd = {
4790 .host_command = POWER_MODE,
4791 .host_command_sequence = 0,
4792 .host_command_length = 4
4796 cmd.host_command_parameters[0] = power_level;
4798 err = ipw2100_hw_send_command(priv, &cmd);
4802 if (power_level == IPW_POWER_MODE_CAM)
4803 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
4805 priv->power_mode = IPW_POWER_ENABLED | power_level;
4807 #ifdef CONFIG_IPW2100_TX_POWER
4808 if (priv->port_type == IBSS &&
4809 priv->adhoc_power != DFTL_IBSS_TX_POWER) {
4810 /* Set beacon interval */
4811 cmd.host_command = TX_POWER_INDEX;
4812 cmd.host_command_parameters[0] = (u32)priv->adhoc_power;
4814 err = ipw2100_hw_send_command(priv, &cmd);
4824 static int ipw2100_set_rts_threshold(struct ipw2100_priv *priv, u32 threshold)
4826 struct host_command cmd = {
4827 .host_command = RTS_THRESHOLD,
4828 .host_command_sequence = 0,
4829 .host_command_length = 4
4833 if (threshold & RTS_DISABLED)
4834 cmd.host_command_parameters[0] = MAX_RTS_THRESHOLD;
4836 cmd.host_command_parameters[0] = threshold & ~RTS_DISABLED;
4838 err = ipw2100_hw_send_command(priv, &cmd);
4842 priv->rts_threshold = threshold;
4848 int ipw2100_set_fragmentation_threshold(struct ipw2100_priv *priv,
4849 u32 threshold, int batch_mode)
4851 struct host_command cmd = {
4852 .host_command = FRAG_THRESHOLD,
4853 .host_command_sequence = 0,
4854 .host_command_length = 4,
4855 .host_command_parameters[0] = 0,
4860 err = ipw2100_disable_adapter(priv);
4866 threshold = DEFAULT_FRAG_THRESHOLD;
4868 threshold = max(threshold, MIN_FRAG_THRESHOLD);
4869 threshold = min(threshold, MAX_FRAG_THRESHOLD);
4872 cmd.host_command_parameters[0] = threshold;
4874 IPW_DEBUG_HC("FRAG_THRESHOLD: %u\n", threshold);
4876 err = ipw2100_hw_send_command(priv, &cmd);
4879 ipw2100_enable_adapter(priv);
4882 priv->frag_threshold = threshold;
4888 static int ipw2100_set_short_retry(struct ipw2100_priv *priv, u32 retry)
4890 struct host_command cmd = {
4891 .host_command = SHORT_RETRY_LIMIT,
4892 .host_command_sequence = 0,
4893 .host_command_length = 4
4897 cmd.host_command_parameters[0] = retry;
4899 err = ipw2100_hw_send_command(priv, &cmd);
4903 priv->short_retry_limit = retry;
4908 static int ipw2100_set_long_retry(struct ipw2100_priv *priv, u32 retry)
4910 struct host_command cmd = {
4911 .host_command = LONG_RETRY_LIMIT,
4912 .host_command_sequence = 0,
4913 .host_command_length = 4
4917 cmd.host_command_parameters[0] = retry;
4919 err = ipw2100_hw_send_command(priv, &cmd);
4923 priv->long_retry_limit = retry;
4929 static int ipw2100_set_mandatory_bssid(struct ipw2100_priv *priv, u8 *bssid,
4932 struct host_command cmd = {
4933 .host_command = MANDATORY_BSSID,
4934 .host_command_sequence = 0,
4935 .host_command_length = (bssid == NULL) ? 0 : ETH_ALEN
4939 #ifdef CONFIG_IPW_DEBUG
4942 "MANDATORY_BSSID: %02X:%02X:%02X:%02X:%02X:%02X\n",
4943 bssid[0], bssid[1], bssid[2], bssid[3], bssid[4],
4946 IPW_DEBUG_HC("MANDATORY_BSSID: <clear>\n");
4948 /* if BSSID is empty then we disable mandatory bssid mode */
4950 memcpy((u8 *)cmd.host_command_parameters, bssid, ETH_ALEN);
4953 err = ipw2100_disable_adapter(priv);
4958 err = ipw2100_hw_send_command(priv, &cmd);
4961 ipw2100_enable_adapter(priv);
4966 #ifdef CONFIG_IEEE80211_WPA
4967 static int ipw2100_disassociate_bssid(struct ipw2100_priv *priv)
4969 struct host_command cmd = {
4970 .host_command = DISASSOCIATION_BSSID,
4971 .host_command_sequence = 0,
4972 .host_command_length = ETH_ALEN
4977 IPW_DEBUG_HC("DISASSOCIATION_BSSID\n");
4980 /* The Firmware currently ignores the BSSID and just disassociates from
4981 * the currently associated AP -- but in the off chance that a future
4982 * firmware does use the BSSID provided here, we go ahead and try and
4983 * set it to the currently associated AP's BSSID */
4984 memcpy(cmd.host_command_parameters, priv->bssid, ETH_ALEN);
4986 err = ipw2100_hw_send_command(priv, &cmd);
4993 * Pseudo code for setting up wpa_frame:
4996 void x(struct ieee80211_assoc_frame *wpa_assoc)
4998 struct ipw2100_wpa_assoc_frame frame;
4999 frame->fixed_ie_mask = IPW_WPA_CAPABILTIES |
5000 IPW_WPA_LISTENINTERVAL |
5002 frame->capab_info = wpa_assoc->capab_info;
5003 frame->lisen_interval = wpa_assoc->listent_interval;
5004 memcpy(frame->current_ap, wpa_assoc->current_ap, ETH_ALEN);
5006 /* UNKNOWN -- I'm not postivive about this part; don't have any WPA
5007 * setup here to test it with.
5009 * Walk the IEs in the wpa_assoc and figure out the total size of all
5010 * that data. Stick that into frame->var_ie_len. Then memcpy() all of
5011 * the IEs from wpa_frame into frame.
5013 frame->var_ie_len = calculate_ie_len(wpa_assoc);
5014 memcpy(frame->var_ie, wpa_assoc->variable, frame->var_ie_len);
5016 ipw2100_set_wpa_ie(priv, &frame, 0);
5023 static int ipw2100_set_wpa_ie(struct ipw2100_priv *,
5024 struct ipw2100_wpa_assoc_frame *, int)
5025 __attribute__ ((unused));
5027 static int ipw2100_set_wpa_ie(struct ipw2100_priv *priv,
5028 struct ipw2100_wpa_assoc_frame *wpa_frame,
5031 struct host_command cmd = {
5032 .host_command = SET_WPA_IE,
5033 .host_command_sequence = 0,
5034 .host_command_length = sizeof(struct ipw2100_wpa_assoc_frame),
5038 IPW_DEBUG_HC("SET_WPA_IE\n");
5041 err = ipw2100_disable_adapter(priv);
5046 memcpy(cmd.host_command_parameters, wpa_frame,
5047 sizeof(struct ipw2100_wpa_assoc_frame));
5049 err = ipw2100_hw_send_command(priv, &cmd);
5052 if (ipw2100_enable_adapter(priv))
5059 struct security_info_params {
5060 u32 allowed_ciphers;
5063 u8 replay_counters_number;
5064 u8 unicast_using_group;
5065 } __attribute__ ((packed));
5067 static int ipw2100_set_security_information(struct ipw2100_priv *priv,
5070 int unicast_using_group,
5073 struct host_command cmd = {
5074 .host_command = SET_SECURITY_INFORMATION,
5075 .host_command_sequence = 0,
5076 .host_command_length = sizeof(struct security_info_params)
5078 struct security_info_params *security =
5079 (struct security_info_params *)&cmd.host_command_parameters;
5081 memset(security, 0, sizeof(*security));
5083 /* If shared key AP authentication is turned on, then we need to
5084 * configure the firmware to try and use it.
5086 * Actual data encryption/decryption is handled by the host. */
5087 security->auth_mode = auth_mode;
5088 security->unicast_using_group = unicast_using_group;
5090 switch (security_level) {
5093 security->allowed_ciphers = IPW_NONE_CIPHER;
5096 security->allowed_ciphers = IPW_WEP40_CIPHER |
5100 security->allowed_ciphers = IPW_WEP40_CIPHER |
5101 IPW_WEP104_CIPHER | IPW_TKIP_CIPHER;
5103 case SEC_LEVEL_2_CKIP:
5104 security->allowed_ciphers = IPW_WEP40_CIPHER |
5105 IPW_WEP104_CIPHER | IPW_CKIP_CIPHER;
5108 security->allowed_ciphers = IPW_WEP40_CIPHER |
5109 IPW_WEP104_CIPHER | IPW_TKIP_CIPHER | IPW_CCMP_CIPHER;
5114 "SET_SECURITY_INFORMATION: auth:%d cipher:0x%02X (level %d)\n",
5115 security->auth_mode, security->allowed_ciphers, security_level);
5117 security->replay_counters_number = 0;
5120 err = ipw2100_disable_adapter(priv);
5125 err = ipw2100_hw_send_command(priv, &cmd);
5128 ipw2100_enable_adapter(priv);
5133 static int ipw2100_set_tx_power(struct ipw2100_priv *priv,
5136 struct host_command cmd = {
5137 .host_command = TX_POWER_INDEX,
5138 .host_command_sequence = 0,
5139 .host_command_length = 4
5143 cmd.host_command_parameters[0] = tx_power;
5145 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
5146 err = ipw2100_hw_send_command(priv, &cmd);
5148 priv->tx_power = tx_power;
5153 static int ipw2100_set_ibss_beacon_interval(struct ipw2100_priv *priv,
5154 u32 interval, int batch_mode)
5156 struct host_command cmd = {
5157 .host_command = BEACON_INTERVAL,
5158 .host_command_sequence = 0,
5159 .host_command_length = 4
5163 cmd.host_command_parameters[0] = interval;
5165 IPW_DEBUG_INFO("enter\n");
5167 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
5169 err = ipw2100_disable_adapter(priv);
5174 ipw2100_hw_send_command(priv, &cmd);
5177 err = ipw2100_enable_adapter(priv);
5183 IPW_DEBUG_INFO("exit\n");
5189 void ipw2100_queues_initialize(struct ipw2100_priv *priv)
5191 ipw2100_tx_initialize(priv);
5192 ipw2100_rx_initialize(priv);
5193 ipw2100_msg_initialize(priv);
5196 void ipw2100_queues_free(struct ipw2100_priv *priv)
5198 ipw2100_tx_free(priv);
5199 ipw2100_rx_free(priv);
5200 ipw2100_msg_free(priv);
5203 int ipw2100_queues_allocate(struct ipw2100_priv *priv)
5205 if (ipw2100_tx_allocate(priv) ||
5206 ipw2100_rx_allocate(priv) ||
5207 ipw2100_msg_allocate(priv))
5213 ipw2100_tx_free(priv);
5214 ipw2100_rx_free(priv);
5215 ipw2100_msg_free(priv);
5219 #define IPW_PRIVACY_CAPABLE 0x0008
5221 static int ipw2100_set_wep_flags(struct ipw2100_priv *priv, u32 flags,
5224 struct host_command cmd = {
5225 .host_command = WEP_FLAGS,
5226 .host_command_sequence = 0,
5227 .host_command_length = 4
5231 cmd.host_command_parameters[0] = flags;
5233 IPW_DEBUG_HC("WEP_FLAGS: flags = 0x%08X\n", flags);
5236 err = ipw2100_disable_adapter(priv);
5238 printk(KERN_ERR DRV_NAME ": %s: Could not disable adapter %d\n",
5239 priv->net_dev->name, err);
5244 /* send cmd to firmware */
5245 err = ipw2100_hw_send_command(priv, &cmd);
5248 ipw2100_enable_adapter(priv);
5253 struct ipw2100_wep_key {
5259 /* Macros to ease up priting WEP keys */
5260 #define WEP_FMT_64 "%02X%02X%02X%02X-%02X"
5261 #define WEP_FMT_128 "%02X%02X%02X%02X-%02X%02X%02X%02X-%02X%02X%02X"
5262 #define WEP_STR_64(x) x[0],x[1],x[2],x[3],x[4]
5263 #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]
5269 * @priv: struct to work on
5270 * @idx: index of the key we want to set
5271 * @key: ptr to the key data to set
5272 * @len: length of the buffer at @key
5273 * @batch_mode: FIXME perform the operation in batch mode, not
5274 * disabling the device.
5276 * @returns 0 if OK, < 0 errno code on error.
5278 * Fill out a command structure with the new wep key, length an
5279 * index and send it down the wire.
5281 static int ipw2100_set_key(struct ipw2100_priv *priv,
5282 int idx, char *key, int len, int batch_mode)
5284 int keylen = len ? (len <= 5 ? 5 : 13) : 0;
5285 struct host_command cmd = {
5286 .host_command = WEP_KEY_INFO,
5287 .host_command_sequence = 0,
5288 .host_command_length = sizeof(struct ipw2100_wep_key),
5290 struct ipw2100_wep_key *wep_key = (void*)cmd.host_command_parameters;
5293 IPW_DEBUG_HC("WEP_KEY_INFO: index = %d, len = %d/%d\n",
5296 /* NOTE: We don't check cached values in case the firmware was reset
5297 * or some other problem is occuring. If the user is setting the key,
5298 * then we push the change */
5301 wep_key->len = keylen;
5304 memcpy(wep_key->key, key, len);
5305 memset(wep_key->key + len, 0, keylen - len);
5308 /* Will be optimized out on debug not being configured in */
5310 IPW_DEBUG_WEP("%s: Clearing key %d\n",
5311 priv->net_dev->name, wep_key->idx);
5312 else if (keylen == 5)
5313 IPW_DEBUG_WEP("%s: idx: %d, len: %d key: " WEP_FMT_64 "\n",
5314 priv->net_dev->name, wep_key->idx, wep_key->len,
5315 WEP_STR_64(wep_key->key));
5317 IPW_DEBUG_WEP("%s: idx: %d, len: %d key: " WEP_FMT_128
5319 priv->net_dev->name, wep_key->idx, wep_key->len,
5320 WEP_STR_128(wep_key->key));
5323 err = ipw2100_disable_adapter(priv);
5324 /* FIXME: IPG: shouldn't this prink be in _disable_adapter()? */
5326 printk(KERN_ERR DRV_NAME ": %s: Could not disable adapter %d\n",
5327 priv->net_dev->name, err);
5332 /* send cmd to firmware */
5333 err = ipw2100_hw_send_command(priv, &cmd);
5336 int err2 = ipw2100_enable_adapter(priv);
5343 static int ipw2100_set_key_index(struct ipw2100_priv *priv,
5344 int idx, int batch_mode)
5346 struct host_command cmd = {
5347 .host_command = WEP_KEY_INDEX,
5348 .host_command_sequence = 0,
5349 .host_command_length = 4,
5350 .host_command_parameters = { idx },
5354 IPW_DEBUG_HC("WEP_KEY_INDEX: index = %d\n", idx);
5356 if (idx < 0 || idx > 3)
5360 err = ipw2100_disable_adapter(priv);
5362 printk(KERN_ERR DRV_NAME ": %s: Could not disable adapter %d\n",
5363 priv->net_dev->name, err);
5368 /* send cmd to firmware */
5369 err = ipw2100_hw_send_command(priv, &cmd);
5372 ipw2100_enable_adapter(priv);
5378 static int ipw2100_configure_security(struct ipw2100_priv *priv,
5381 int i, err, auth_mode, sec_level, use_group;
5383 if (!(priv->status & STATUS_RUNNING))
5387 err = ipw2100_disable_adapter(priv);
5392 if (!priv->sec.enabled) {
5393 err = ipw2100_set_security_information(
5394 priv, IPW_AUTH_OPEN, SEC_LEVEL_0, 0, 1);
5396 auth_mode = IPW_AUTH_OPEN;
5397 if ((priv->sec.flags & SEC_AUTH_MODE) &&
5398 (priv->sec.auth_mode == WLAN_AUTH_SHARED_KEY))
5399 auth_mode = IPW_AUTH_SHARED;
5401 sec_level = SEC_LEVEL_0;
5402 if (priv->sec.flags & SEC_LEVEL)
5403 sec_level = priv->sec.level;
5406 if (priv->sec.flags & SEC_UNICAST_GROUP)
5407 use_group = priv->sec.unicast_uses_group;
5409 err = ipw2100_set_security_information(
5410 priv, auth_mode, sec_level, use_group, 1);
5416 if (priv->sec.enabled) {
5417 for (i = 0; i < 4; i++) {
5418 if (!(priv->sec.flags & (1 << i))) {
5419 memset(priv->sec.keys[i], 0, WEP_KEY_LEN);
5420 priv->sec.key_sizes[i] = 0;
5422 err = ipw2100_set_key(priv, i,
5424 priv->sec.key_sizes[i],
5431 ipw2100_set_key_index(priv, priv->ieee->tx_keyidx, 1);
5434 /* Always enable privacy so the Host can filter WEP packets if
5435 * encrypted data is sent up */
5436 err = ipw2100_set_wep_flags(
5437 priv, priv->sec.enabled ? IPW_PRIVACY_CAPABLE : 0, 1);
5441 priv->status &= ~STATUS_SECURITY_UPDATED;
5445 ipw2100_enable_adapter(priv);
5450 static void ipw2100_security_work(struct ipw2100_priv *priv)
5452 /* If we happen to have reconnected before we get a chance to
5453 * process this, then update the security settings--which causes
5454 * a disassociation to occur */
5455 if (!(priv->status & STATUS_ASSOCIATED) &&
5456 priv->status & STATUS_SECURITY_UPDATED)
5457 ipw2100_configure_security(priv, 0);
5460 static void shim__set_security(struct net_device *dev,
5461 struct ieee80211_security *sec)
5463 struct ipw2100_priv *priv = ieee80211_priv(dev);
5464 int i, force_update = 0;
5466 down(&priv->action_sem);
5467 if (!(priv->status & STATUS_INITIALIZED))
5470 for (i = 0; i < 4; i++) {
5471 if (sec->flags & (1 << i)) {
5472 priv->sec.key_sizes[i] = sec->key_sizes[i];
5473 if (sec->key_sizes[i] == 0)
5474 priv->sec.flags &= ~(1 << i);
5476 memcpy(priv->sec.keys[i], sec->keys[i],
5478 priv->sec.flags |= (1 << i);
5479 priv->status |= STATUS_SECURITY_UPDATED;
5483 if ((sec->flags & SEC_ACTIVE_KEY) &&
5484 priv->sec.active_key != sec->active_key) {
5485 if (sec->active_key <= 3) {
5486 priv->sec.active_key = sec->active_key;
5487 priv->sec.flags |= SEC_ACTIVE_KEY;
5489 priv->sec.flags &= ~SEC_ACTIVE_KEY;
5491 priv->status |= STATUS_SECURITY_UPDATED;
5494 if ((sec->flags & SEC_AUTH_MODE) &&
5495 (priv->sec.auth_mode != sec->auth_mode)) {
5496 priv->sec.auth_mode = sec->auth_mode;
5497 priv->sec.flags |= SEC_AUTH_MODE;
5498 priv->status |= STATUS_SECURITY_UPDATED;
5501 if (sec->flags & SEC_ENABLED &&
5502 priv->sec.enabled != sec->enabled) {
5503 priv->sec.flags |= SEC_ENABLED;
5504 priv->sec.enabled = sec->enabled;
5505 priv->status |= STATUS_SECURITY_UPDATED;
5509 if (sec->flags & SEC_LEVEL &&
5510 priv->sec.level != sec->level) {
5511 priv->sec.level = sec->level;
5512 priv->sec.flags |= SEC_LEVEL;
5513 priv->status |= STATUS_SECURITY_UPDATED;
5516 IPW_DEBUG_WEP("Security flags: %c %c%c%c%c %c%c%c%c\n",
5517 priv->sec.flags & (1<<8) ? '1' : '0',
5518 priv->sec.flags & (1<<7) ? '1' : '0',
5519 priv->sec.flags & (1<<6) ? '1' : '0',
5520 priv->sec.flags & (1<<5) ? '1' : '0',
5521 priv->sec.flags & (1<<4) ? '1' : '0',
5522 priv->sec.flags & (1<<3) ? '1' : '0',
5523 priv->sec.flags & (1<<2) ? '1' : '0',
5524 priv->sec.flags & (1<<1) ? '1' : '0',
5525 priv->sec.flags & (1<<0) ? '1' : '0');
5527 /* As a temporary work around to enable WPA until we figure out why
5528 * wpa_supplicant toggles the security capability of the driver, which
5529 * forces a disassocation with force_update...
5531 * if (force_update || !(priv->status & STATUS_ASSOCIATED))*/
5532 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
5533 ipw2100_configure_security(priv, 0);
5535 up(&priv->action_sem);
5538 static int ipw2100_adapter_setup(struct ipw2100_priv *priv)
5544 IPW_DEBUG_INFO("enter\n");
5546 err = ipw2100_disable_adapter(priv);
5549 #ifdef CONFIG_IPW2100_MONITOR
5550 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
5551 err = ipw2100_set_channel(priv, priv->channel, batch_mode);
5555 IPW_DEBUG_INFO("exit\n");
5559 #endif /* CONFIG_IPW2100_MONITOR */
5561 err = ipw2100_read_mac_address(priv);
5565 err = ipw2100_set_mac_address(priv, batch_mode);
5569 err = ipw2100_set_port_type(priv, priv->ieee->iw_mode, batch_mode);
5573 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
5574 err = ipw2100_set_channel(priv, priv->channel, batch_mode);
5579 err = ipw2100_system_config(priv, batch_mode);
5583 err = ipw2100_set_tx_rates(priv, priv->tx_rates, batch_mode);
5587 /* Default to power mode OFF */
5588 err = ipw2100_set_power_mode(priv, IPW_POWER_MODE_CAM);
5592 err = ipw2100_set_rts_threshold(priv, priv->rts_threshold);
5596 if (priv->config & CFG_STATIC_BSSID)
5597 bssid = priv->bssid;
5600 err = ipw2100_set_mandatory_bssid(priv, bssid, batch_mode);
5604 if (priv->config & CFG_STATIC_ESSID)
5605 err = ipw2100_set_essid(priv, priv->essid, priv->essid_len,
5608 err = ipw2100_set_essid(priv, NULL, 0, batch_mode);
5612 err = ipw2100_configure_security(priv, batch_mode);
5616 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
5617 err = ipw2100_set_ibss_beacon_interval(
5618 priv, priv->beacon_interval, batch_mode);
5622 err = ipw2100_set_tx_power(priv, priv->tx_power);
5628 err = ipw2100_set_fragmentation_threshold(
5629 priv, priv->frag_threshold, batch_mode);
5634 IPW_DEBUG_INFO("exit\n");
5640 /*************************************************************************
5642 * EXTERNALLY CALLED METHODS
5644 *************************************************************************/
5646 /* This method is called by the network layer -- not to be confused with
5647 * ipw2100_set_mac_address() declared above called by this driver (and this
5648 * method as well) to talk to the firmware */
5649 static int ipw2100_set_address(struct net_device *dev, void *p)
5651 struct ipw2100_priv *priv = ieee80211_priv(dev);
5652 struct sockaddr *addr = p;
5655 if (!is_valid_ether_addr(addr->sa_data))
5656 return -EADDRNOTAVAIL;
5658 down(&priv->action_sem);
5660 priv->config |= CFG_CUSTOM_MAC;
5661 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
5663 err = ipw2100_set_mac_address(priv, 0);
5667 priv->reset_backoff = 0;
5668 up(&priv->action_sem);
5669 ipw2100_reset_adapter(priv);
5673 up(&priv->action_sem);
5677 static int ipw2100_open(struct net_device *dev)
5679 struct ipw2100_priv *priv = ieee80211_priv(dev);
5680 unsigned long flags;
5681 IPW_DEBUG_INFO("dev->open\n");
5683 spin_lock_irqsave(&priv->low_lock, flags);
5684 if (priv->status & STATUS_ASSOCIATED) {
5685 netif_carrier_on(dev);
5686 netif_start_queue(dev);
5688 spin_unlock_irqrestore(&priv->low_lock, flags);
5693 static int ipw2100_close(struct net_device *dev)
5695 struct ipw2100_priv *priv = ieee80211_priv(dev);
5696 unsigned long flags;
5697 struct list_head *element;
5698 struct ipw2100_tx_packet *packet;
5700 IPW_DEBUG_INFO("enter\n");
5702 spin_lock_irqsave(&priv->low_lock, flags);
5704 if (priv->status & STATUS_ASSOCIATED)
5705 netif_carrier_off(dev);
5706 netif_stop_queue(dev);
5708 /* Flush the TX queue ... */
5709 while (!list_empty(&priv->tx_pend_list)) {
5710 element = priv->tx_pend_list.next;
5711 packet = list_entry(element, struct ipw2100_tx_packet, list);
5714 DEC_STAT(&priv->tx_pend_stat);
5716 ieee80211_txb_free(packet->info.d_struct.txb);
5717 packet->info.d_struct.txb = NULL;
5719 list_add_tail(element, &priv->tx_free_list);
5720 INC_STAT(&priv->tx_free_stat);
5722 spin_unlock_irqrestore(&priv->low_lock, flags);
5724 IPW_DEBUG_INFO("exit\n");
5732 * TODO: Fix this function... its just wrong
5734 static void ipw2100_tx_timeout(struct net_device *dev)
5736 struct ipw2100_priv *priv = ieee80211_priv(dev);
5738 priv->ieee->stats.tx_errors++;
5740 #ifdef CONFIG_IPW2100_MONITOR
5741 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
5745 IPW_DEBUG_INFO("%s: TX timed out. Scheduling firmware restart.\n",
5747 schedule_reset(priv);
5752 * TODO: reimplement it so that it reads statistics
5753 * from the adapter using ordinal tables
5754 * instead of/in addition to collecting them
5757 static struct net_device_stats *ipw2100_stats(struct net_device *dev)
5759 struct ipw2100_priv *priv = ieee80211_priv(dev);
5761 return &priv->ieee->stats;
5764 /* Support for wpa_supplicant. Will be replaced with WEXT once
5765 * they get WPA support. */
5766 #ifdef CONFIG_IEEE80211_WPA
5768 /* following definitions must match definitions in driver_ipw2100.c */
5770 #define IPW2100_IOCTL_WPA_SUPPLICANT SIOCIWFIRSTPRIV+30
5772 #define IPW2100_CMD_SET_WPA_PARAM 1
5773 #define IPW2100_CMD_SET_WPA_IE 2
5774 #define IPW2100_CMD_SET_ENCRYPTION 3
5775 #define IPW2100_CMD_MLME 4
5777 #define IPW2100_PARAM_WPA_ENABLED 1
5778 #define IPW2100_PARAM_TKIP_COUNTERMEASURES 2
5779 #define IPW2100_PARAM_DROP_UNENCRYPTED 3
5780 #define IPW2100_PARAM_PRIVACY_INVOKED 4
5781 #define IPW2100_PARAM_AUTH_ALGS 5
5782 #define IPW2100_PARAM_IEEE_802_1X 6
5784 #define IPW2100_MLME_STA_DEAUTH 1
5785 #define IPW2100_MLME_STA_DISASSOC 2
5787 #define IPW2100_CRYPT_ERR_UNKNOWN_ALG 2
5788 #define IPW2100_CRYPT_ERR_UNKNOWN_ADDR 3
5789 #define IPW2100_CRYPT_ERR_CRYPT_INIT_FAILED 4
5790 #define IPW2100_CRYPT_ERR_KEY_SET_FAILED 5
5791 #define IPW2100_CRYPT_ERR_TX_KEY_SET_FAILED 6
5792 #define IPW2100_CRYPT_ERR_CARD_CONF_FAILED 7
5794 #define IPW2100_CRYPT_ALG_NAME_LEN 16
5796 struct ipw2100_param {
5798 u8 sta_addr[ETH_ALEN];
5813 u8 alg[IPW2100_CRYPT_ALG_NAME_LEN];
5817 u8 seq[8]; /* sequence counter (set: RX, get: TX) */
5825 /* end of driver_ipw2100.c code */
5827 static int ipw2100_wpa_enable(struct ipw2100_priv *priv, int value){
5829 struct ieee80211_device *ieee = priv->ieee;
5830 struct ieee80211_security sec = {
5831 .flags = SEC_LEVEL | SEC_ENABLED,
5835 ieee->wpa_enabled = value;
5838 sec.level = SEC_LEVEL_3;
5841 sec.level = SEC_LEVEL_0;
5845 if (ieee->set_security)
5846 ieee->set_security(ieee->dev, &sec);
5853 #define AUTH_ALG_OPEN_SYSTEM 0x1
5854 #define AUTH_ALG_SHARED_KEY 0x2
5856 static int ipw2100_wpa_set_auth_algs(struct ipw2100_priv *priv, int value){
5858 struct ieee80211_device *ieee = priv->ieee;
5859 struct ieee80211_security sec = {
5860 .flags = SEC_AUTH_MODE,
5864 if (value & AUTH_ALG_SHARED_KEY){
5865 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
5868 sec.auth_mode = WLAN_AUTH_OPEN;
5872 if (ieee->set_security)
5873 ieee->set_security(ieee->dev, &sec);
5881 static int ipw2100_wpa_set_param(struct net_device *dev, u8 name, u32 value){
5883 struct ipw2100_priv *priv = ieee80211_priv(dev);
5887 case IPW2100_PARAM_WPA_ENABLED:
5888 ret = ipw2100_wpa_enable(priv, value);
5891 case IPW2100_PARAM_TKIP_COUNTERMEASURES:
5892 priv->ieee->tkip_countermeasures=value;
5895 case IPW2100_PARAM_DROP_UNENCRYPTED:
5896 priv->ieee->drop_unencrypted=value;
5899 case IPW2100_PARAM_PRIVACY_INVOKED:
5900 priv->ieee->privacy_invoked=value;
5903 case IPW2100_PARAM_AUTH_ALGS:
5904 ret = ipw2100_wpa_set_auth_algs(priv, value);
5907 case IPW2100_PARAM_IEEE_802_1X:
5908 priv->ieee->ieee802_1x=value;
5912 printk(KERN_ERR DRV_NAME ": %s: Unknown WPA param: %d\n",
5920 static int ipw2100_wpa_mlme(struct net_device *dev, int command, int reason){
5922 struct ipw2100_priv *priv = ieee80211_priv(dev);
5926 case IPW2100_MLME_STA_DEAUTH:
5930 case IPW2100_MLME_STA_DISASSOC:
5931 ipw2100_disassociate_bssid(priv);
5935 printk(KERN_ERR DRV_NAME ": %s: Unknown MLME request: %d\n",
5936 dev->name, command);
5944 void ipw2100_wpa_assoc_frame(struct ipw2100_priv *priv,
5945 char *wpa_ie, int wpa_ie_len){
5947 struct ipw2100_wpa_assoc_frame frame;
5949 frame.fixed_ie_mask = 0;
5952 memcpy(frame.var_ie, wpa_ie, wpa_ie_len);
5953 frame.var_ie_len = wpa_ie_len;
5955 /* make sure WPA is enabled */
5956 ipw2100_wpa_enable(priv, 1);
5957 ipw2100_set_wpa_ie(priv, &frame, 0);
5961 static int ipw2100_wpa_set_wpa_ie(struct net_device *dev,
5962 struct ipw2100_param *param, int plen){
5964 struct ipw2100_priv *priv = ieee80211_priv(dev);
5965 struct ieee80211_device *ieee = priv->ieee;
5968 if (! ieee->wpa_enabled)
5971 if (param->u.wpa_ie.len > MAX_WPA_IE_LEN ||
5972 (param->u.wpa_ie.len &&
5973 param->u.wpa_ie.data==NULL))
5976 if (param->u.wpa_ie.len){
5977 buf = kmalloc(param->u.wpa_ie.len, GFP_KERNEL);
5981 memcpy(buf, param->u.wpa_ie.data, param->u.wpa_ie.len);
5983 kfree(ieee->wpa_ie);
5985 ieee->wpa_ie_len = param->u.wpa_ie.len;
5988 kfree(ieee->wpa_ie);
5989 ieee->wpa_ie = NULL;
5990 ieee->wpa_ie_len = 0;
5993 ipw2100_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
5998 /* implementation borrowed from hostap driver */
6000 static int ipw2100_wpa_set_encryption(struct net_device *dev,
6001 struct ipw2100_param *param, int param_len){
6004 struct ipw2100_priv *priv = ieee80211_priv(dev);
6005 struct ieee80211_device *ieee = priv->ieee;
6006 struct ieee80211_crypto_ops *ops;
6007 struct ieee80211_crypt_data **crypt;
6009 struct ieee80211_security sec = {
6013 param->u.crypt.err = 0;
6014 param->u.crypt.alg[IPW2100_CRYPT_ALG_NAME_LEN - 1] = '\0';
6017 (int) ((char *) param->u.crypt.key - (char *) param) +
6018 param->u.crypt.key_len){
6019 IPW_DEBUG_INFO("Len mismatch %d, %d\n", param_len, param->u.crypt.key_len);
6022 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
6023 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
6024 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
6025 if (param->u.crypt.idx >= WEP_KEYS)
6027 crypt = &ieee->crypt[param->u.crypt.idx];
6032 if (strcmp(param->u.crypt.alg, "none") == 0) {
6035 sec.level = SEC_LEVEL_0;
6036 sec.flags |= SEC_ENABLED | SEC_LEVEL;
6037 ieee80211_crypt_delayed_deinit(ieee, crypt);
6042 sec.flags |= SEC_ENABLED;
6044 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6045 if (ops == NULL && strcmp(param->u.crypt.alg, "WEP") == 0) {
6046 request_module("ieee80211_crypt_wep");
6047 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6048 } else if (ops == NULL && strcmp(param->u.crypt.alg, "TKIP") == 0) {
6049 request_module("ieee80211_crypt_tkip");
6050 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6051 } else if (ops == NULL && strcmp(param->u.crypt.alg, "CCMP") == 0) {
6052 request_module("ieee80211_crypt_ccmp");
6053 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6056 IPW_DEBUG_INFO("%s: unknown crypto alg '%s'\n",
6057 dev->name, param->u.crypt.alg);
6058 param->u.crypt.err = IPW2100_CRYPT_ERR_UNKNOWN_ALG;
6063 if (*crypt == NULL || (*crypt)->ops != ops) {
6064 struct ieee80211_crypt_data *new_crypt;
6066 ieee80211_crypt_delayed_deinit(ieee, crypt);
6068 new_crypt = (struct ieee80211_crypt_data *)
6069 kmalloc(sizeof(struct ieee80211_crypt_data), GFP_KERNEL);
6070 if (new_crypt == NULL) {
6074 memset(new_crypt, 0, sizeof(struct ieee80211_crypt_data));
6075 new_crypt->ops = ops;
6076 if (new_crypt->ops && try_module_get(new_crypt->ops->owner))
6077 new_crypt->priv = new_crypt->ops->init(param->u.crypt.idx);
6079 if (new_crypt->priv == NULL) {
6081 param->u.crypt.err =
6082 IPW2100_CRYPT_ERR_CRYPT_INIT_FAILED;
6090 if (param->u.crypt.key_len > 0 && (*crypt)->ops->set_key &&
6091 (*crypt)->ops->set_key(param->u.crypt.key,
6092 param->u.crypt.key_len, param->u.crypt.seq,
6093 (*crypt)->priv) < 0) {
6094 IPW_DEBUG_INFO("%s: key setting failed\n",
6096 param->u.crypt.err = IPW2100_CRYPT_ERR_KEY_SET_FAILED;
6101 if (param->u.crypt.set_tx){
6102 ieee->tx_keyidx = param->u.crypt.idx;
6103 sec.active_key = param->u.crypt.idx;
6104 sec.flags |= SEC_ACTIVE_KEY;
6107 if (ops->name != NULL){
6109 if (strcmp(ops->name, "WEP") == 0) {
6110 memcpy(sec.keys[param->u.crypt.idx], param->u.crypt.key, param->u.crypt.key_len);
6111 sec.key_sizes[param->u.crypt.idx] = param->u.crypt.key_len;
6112 sec.flags |= (1 << param->u.crypt.idx);
6113 sec.flags |= SEC_LEVEL;
6114 sec.level = SEC_LEVEL_1;
6115 } else if (strcmp(ops->name, "TKIP") == 0) {
6116 sec.flags |= SEC_LEVEL;
6117 sec.level = SEC_LEVEL_2;
6118 } else if (strcmp(ops->name, "CCMP") == 0) {
6119 sec.flags |= SEC_LEVEL;
6120 sec.level = SEC_LEVEL_3;
6124 if (ieee->set_security)
6125 ieee->set_security(ieee->dev, &sec);
6127 /* Do not reset port if card is in Managed mode since resetting will
6128 * generate new IEEE 802.11 authentication which may end up in looping
6129 * with IEEE 802.1X. If your hardware requires a reset after WEP
6130 * configuration (for example... Prism2), implement the reset_port in
6131 * the callbacks structures used to initialize the 802.11 stack. */
6132 if (ieee->reset_on_keychange &&
6133 ieee->iw_mode != IW_MODE_INFRA &&
6135 ieee->reset_port(dev)) {
6136 IPW_DEBUG_INFO("%s: reset_port failed\n", dev->name);
6137 param->u.crypt.err = IPW2100_CRYPT_ERR_CARD_CONF_FAILED;
6145 static int ipw2100_wpa_supplicant(struct net_device *dev, struct iw_point *p){
6147 struct ipw2100_param *param;
6150 IPW_DEBUG_IOCTL("wpa_supplicant: len=%d\n", p->length);
6152 if (p->length < sizeof(struct ipw2100_param) || !p->pointer)
6155 param = (struct ipw2100_param *)kmalloc(p->length, GFP_KERNEL);
6159 if (copy_from_user(param, p->pointer, p->length)){
6164 switch (param->cmd){
6166 case IPW2100_CMD_SET_WPA_PARAM:
6167 ret = ipw2100_wpa_set_param(dev, param->u.wpa_param.name,
6168 param->u.wpa_param.value);
6171 case IPW2100_CMD_SET_WPA_IE:
6172 ret = ipw2100_wpa_set_wpa_ie(dev, param, p->length);
6175 case IPW2100_CMD_SET_ENCRYPTION:
6176 ret = ipw2100_wpa_set_encryption(dev, param, p->length);
6179 case IPW2100_CMD_MLME:
6180 ret = ipw2100_wpa_mlme(dev, param->u.mlme.command,
6181 param->u.mlme.reason_code);
6185 printk(KERN_ERR DRV_NAME ": %s: Unknown WPA supplicant request: %d\n",
6186 dev->name, param->cmd);
6191 if (ret == 0 && copy_to_user(p->pointer, param, p->length))
6197 #endif /* CONFIG_IEEE80211_WPA */
6199 static int ipw2100_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
6201 #ifdef CONFIG_IEEE80211_WPA
6202 struct iwreq *wrq = (struct iwreq *) rq;
6205 case IPW2100_IOCTL_WPA_SUPPLICANT:
6206 ret = ipw2100_wpa_supplicant(dev, &wrq->u.data);
6213 #endif /* CONFIG_IEEE80211_WPA */
6219 static void ipw_ethtool_get_drvinfo(struct net_device *dev,
6220 struct ethtool_drvinfo *info)
6222 struct ipw2100_priv *priv = ieee80211_priv(dev);
6223 char fw_ver[64], ucode_ver[64];
6225 strcpy(info->driver, DRV_NAME);
6226 strcpy(info->version, DRV_VERSION);
6228 ipw2100_get_fwversion(priv, fw_ver, sizeof(fw_ver));
6229 ipw2100_get_ucodeversion(priv, ucode_ver, sizeof(ucode_ver));
6231 snprintf(info->fw_version, sizeof(info->fw_version), "%s:%d:%s",
6232 fw_ver, priv->eeprom_version, ucode_ver);
6234 strcpy(info->bus_info, pci_name(priv->pci_dev));
6237 static u32 ipw2100_ethtool_get_link(struct net_device *dev)
6239 struct ipw2100_priv *priv = ieee80211_priv(dev);
6240 return (priv->status & STATUS_ASSOCIATED) ? 1 : 0;
6244 static struct ethtool_ops ipw2100_ethtool_ops = {
6245 .get_link = ipw2100_ethtool_get_link,
6246 .get_drvinfo = ipw_ethtool_get_drvinfo,
6249 static void ipw2100_hang_check(void *adapter)
6251 struct ipw2100_priv *priv = adapter;
6252 unsigned long flags;
6253 u32 rtc = 0xa5a5a5a5;
6254 u32 len = sizeof(rtc);
6257 spin_lock_irqsave(&priv->low_lock, flags);
6259 if (priv->fatal_error != 0) {
6260 /* If fatal_error is set then we need to restart */
6261 IPW_DEBUG_INFO("%s: Hardware fatal error detected.\n",
6262 priv->net_dev->name);
6265 } else if (ipw2100_get_ordinal(priv, IPW_ORD_RTC_TIME, &rtc, &len) ||
6266 (rtc == priv->last_rtc)) {
6267 /* Check if firmware is hung */
6268 IPW_DEBUG_INFO("%s: Firmware RTC stalled.\n",
6269 priv->net_dev->name);
6276 priv->stop_hang_check = 1;
6279 /* Restart the NIC */
6280 schedule_reset(priv);
6283 priv->last_rtc = rtc;
6285 if (!priv->stop_hang_check)
6286 queue_delayed_work(priv->workqueue, &priv->hang_check, HZ / 2);
6288 spin_unlock_irqrestore(&priv->low_lock, flags);
6292 static void ipw2100_rf_kill(void *adapter)
6294 struct ipw2100_priv *priv = adapter;
6295 unsigned long flags;
6297 spin_lock_irqsave(&priv->low_lock, flags);
6299 if (rf_kill_active(priv)) {
6300 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
6301 if (!priv->stop_rf_kill)
6302 queue_delayed_work(priv->workqueue, &priv->rf_kill, HZ);
6306 /* RF Kill is now disabled, so bring the device back up */
6308 if (!(priv->status & STATUS_RF_KILL_MASK)) {
6309 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
6311 schedule_reset(priv);
6313 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
6317 spin_unlock_irqrestore(&priv->low_lock, flags);
6320 static void ipw2100_irq_tasklet(struct ipw2100_priv *priv);
6322 /* Look into using netdev destructor to shutdown ieee80211? */
6324 static struct net_device *ipw2100_alloc_device(
6325 struct pci_dev *pci_dev,
6326 void __iomem *base_addr,
6327 unsigned long mem_start,
6328 unsigned long mem_len)
6330 struct ipw2100_priv *priv;
6331 struct net_device *dev;
6333 dev = alloc_ieee80211(sizeof(struct ipw2100_priv));
6336 priv = ieee80211_priv(dev);
6337 priv->ieee = netdev_priv(dev);
6338 priv->pci_dev = pci_dev;
6339 priv->net_dev = dev;
6341 priv->ieee->hard_start_xmit = ipw2100_tx;
6342 priv->ieee->set_security = shim__set_security;
6344 dev->open = ipw2100_open;
6345 dev->stop = ipw2100_close;
6346 dev->init = ipw2100_net_init;
6347 dev->do_ioctl = ipw2100_ioctl;
6348 dev->get_stats = ipw2100_stats;
6349 dev->ethtool_ops = &ipw2100_ethtool_ops;
6350 dev->tx_timeout = ipw2100_tx_timeout;
6351 dev->wireless_handlers = &ipw2100_wx_handler_def;
6352 dev->get_wireless_stats = ipw2100_wx_wireless_stats;
6353 dev->set_mac_address = ipw2100_set_address;
6354 dev->watchdog_timeo = 3*HZ;
6357 dev->base_addr = (unsigned long)base_addr;
6358 dev->mem_start = mem_start;
6359 dev->mem_end = dev->mem_start + mem_len - 1;
6361 /* NOTE: We don't use the wireless_handlers hook
6362 * in dev as the system will start throwing WX requests
6363 * to us before we're actually initialized and it just
6364 * ends up causing problems. So, we just handle
6365 * the WX extensions through the ipw2100_ioctl interface */
6368 /* memset() puts everything to 0, so we only have explicitely set
6369 * those values that need to be something else */
6371 /* If power management is turned on, default to AUTO mode */
6372 priv->power_mode = IPW_POWER_AUTO;
6376 #ifdef CONFIG_IEEE80211_WPA
6377 priv->ieee->wpa_enabled = 0;
6378 priv->ieee->tkip_countermeasures = 0;
6379 priv->ieee->drop_unencrypted = 0;
6380 priv->ieee->privacy_invoked = 0;
6381 priv->ieee->ieee802_1x = 1;
6382 #endif /* CONFIG_IEEE80211_WPA */
6384 /* Set module parameters */
6387 priv->ieee->iw_mode = IW_MODE_ADHOC;
6389 #ifdef CONFIG_IPW2100_MONITOR
6391 priv->ieee->iw_mode = IW_MODE_MONITOR;
6396 priv->ieee->iw_mode = IW_MODE_INFRA;
6401 priv->status |= STATUS_RF_KILL_SW;
6404 ((channel >= REG_MIN_CHANNEL) &&
6405 (channel <= REG_MAX_CHANNEL))) {
6406 priv->config |= CFG_STATIC_CHANNEL;
6407 priv->channel = channel;
6411 priv->config |= CFG_ASSOCIATE;
6413 priv->beacon_interval = DEFAULT_BEACON_INTERVAL;
6414 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
6415 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
6416 priv->rts_threshold = DEFAULT_RTS_THRESHOLD | RTS_DISABLED;
6417 priv->frag_threshold = DEFAULT_FTS | FRAG_DISABLED;
6418 priv->tx_power = IPW_TX_POWER_DEFAULT;
6419 priv->tx_rates = DEFAULT_TX_RATES;
6421 strcpy(priv->nick, "ipw2100");
6423 spin_lock_init(&priv->low_lock);
6424 sema_init(&priv->action_sem, 1);
6425 sema_init(&priv->adapter_sem, 1);
6427 init_waitqueue_head(&priv->wait_command_queue);
6429 netif_carrier_off(dev);
6431 INIT_LIST_HEAD(&priv->msg_free_list);
6432 INIT_LIST_HEAD(&priv->msg_pend_list);
6433 INIT_STAT(&priv->msg_free_stat);
6434 INIT_STAT(&priv->msg_pend_stat);
6436 INIT_LIST_HEAD(&priv->tx_free_list);
6437 INIT_LIST_HEAD(&priv->tx_pend_list);
6438 INIT_STAT(&priv->tx_free_stat);
6439 INIT_STAT(&priv->tx_pend_stat);
6441 INIT_LIST_HEAD(&priv->fw_pend_list);
6442 INIT_STAT(&priv->fw_pend_stat);
6445 #ifdef CONFIG_SOFTWARE_SUSPEND2
6446 priv->workqueue = create_workqueue(DRV_NAME, 0);
6448 priv->workqueue = create_workqueue(DRV_NAME);
6450 INIT_WORK(&priv->reset_work,
6451 (void (*)(void *))ipw2100_reset_adapter, priv);
6452 INIT_WORK(&priv->security_work,
6453 (void (*)(void *))ipw2100_security_work, priv);
6454 INIT_WORK(&priv->wx_event_work,
6455 (void (*)(void *))ipw2100_wx_event_work, priv);
6456 INIT_WORK(&priv->hang_check, ipw2100_hang_check, priv);
6457 INIT_WORK(&priv->rf_kill, ipw2100_rf_kill, priv);
6459 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
6460 ipw2100_irq_tasklet, (unsigned long)priv);
6462 /* NOTE: We do not start the deferred work for status checks yet */
6463 priv->stop_rf_kill = 1;
6464 priv->stop_hang_check = 1;
6469 static int ipw2100_pci_init_one(struct pci_dev *pci_dev,
6470 const struct pci_device_id *ent)
6472 unsigned long mem_start, mem_len, mem_flags;
6473 void __iomem *base_addr = NULL;
6474 struct net_device *dev = NULL;
6475 struct ipw2100_priv *priv = NULL;
6480 IPW_DEBUG_INFO("enter\n");
6482 mem_start = pci_resource_start(pci_dev, 0);
6483 mem_len = pci_resource_len(pci_dev, 0);
6484 mem_flags = pci_resource_flags(pci_dev, 0);
6486 if ((mem_flags & IORESOURCE_MEM) != IORESOURCE_MEM) {
6487 IPW_DEBUG_INFO("weird - resource type is not memory\n");
6492 base_addr = ioremap_nocache(mem_start, mem_len);
6494 printk(KERN_WARNING DRV_NAME
6495 "Error calling ioremap_nocache.\n");
6500 /* allocate and initialize our net_device */
6501 dev = ipw2100_alloc_device(pci_dev, base_addr, mem_start, mem_len);
6503 printk(KERN_WARNING DRV_NAME
6504 "Error calling ipw2100_alloc_device.\n");
6509 /* set up PCI mappings for device */
6510 err = pci_enable_device(pci_dev);
6512 printk(KERN_WARNING DRV_NAME
6513 "Error calling pci_enable_device.\n");
6517 priv = ieee80211_priv(dev);
6519 pci_set_master(pci_dev);
6520 pci_set_drvdata(pci_dev, priv);
6522 err = pci_set_dma_mask(pci_dev, DMA_32BIT_MASK);
6524 printk(KERN_WARNING DRV_NAME
6525 "Error calling pci_set_dma_mask.\n");
6526 pci_disable_device(pci_dev);
6530 err = pci_request_regions(pci_dev, DRV_NAME);
6532 printk(KERN_WARNING DRV_NAME
6533 "Error calling pci_request_regions.\n");
6534 pci_disable_device(pci_dev);
6538 /* We disable the RETRY_TIMEOUT register (0x41) to keep
6539 * PCI Tx retries from interfering with C3 CPU state */
6540 pci_read_config_dword(pci_dev, 0x40, &val);
6541 if ((val & 0x0000ff00) != 0)
6542 pci_write_config_dword(pci_dev, 0x40, val & 0xffff00ff);
6544 pci_set_power_state(pci_dev, PCI_D0);
6546 if (!ipw2100_hw_is_adapter_in_system(dev)) {
6547 printk(KERN_WARNING DRV_NAME
6548 "Device not found via register read.\n");
6553 SET_NETDEV_DEV(dev, &pci_dev->dev);
6555 /* Force interrupts to be shut off on the device */
6556 priv->status |= STATUS_INT_ENABLED;
6557 ipw2100_disable_interrupts(priv);
6559 /* Allocate and initialize the Tx/Rx queues and lists */
6560 if (ipw2100_queues_allocate(priv)) {
6561 printk(KERN_WARNING DRV_NAME
6562 "Error calilng ipw2100_queues_allocate.\n");
6566 ipw2100_queues_initialize(priv);
6568 err = request_irq(pci_dev->irq,
6569 ipw2100_interrupt, SA_SHIRQ,
6572 printk(KERN_WARNING DRV_NAME
6573 "Error calling request_irq: %d.\n",
6577 dev->irq = pci_dev->irq;
6579 IPW_DEBUG_INFO("Attempting to register device...\n");
6581 SET_MODULE_OWNER(dev);
6583 printk(KERN_INFO DRV_NAME
6584 ": Detected Intel PRO/Wireless 2100 Network Connection\n");
6586 /* Bring up the interface. Pre 0.46, after we registered the
6587 * network device we would call ipw2100_up. This introduced a race
6588 * condition with newer hotplug configurations (network was coming
6589 * up and making calls before the device was initialized).
6591 * If we called ipw2100_up before we registered the device, then the
6592 * device name wasn't registered. So, we instead use the net_dev->init
6593 * member to call a function that then just turns and calls ipw2100_up.
6594 * net_dev->init is called after name allocation but before the
6595 * notifier chain is called */
6596 down(&priv->action_sem);
6597 err = register_netdev(dev);
6599 printk(KERN_WARNING DRV_NAME
6600 "Error calling register_netdev.\n");
6605 IPW_DEBUG_INFO("%s: Bound to %s\n", dev->name, pci_name(pci_dev));
6607 /* perform this after register_netdev so that dev->name is set */
6608 sysfs_create_group(&pci_dev->dev.kobj, &ipw2100_attribute_group);
6609 netif_carrier_off(dev);
6611 /* If the RF Kill switch is disabled, go ahead and complete the
6612 * startup sequence */
6613 if (!(priv->status & STATUS_RF_KILL_MASK)) {
6614 /* Enable the adapter - sends HOST_COMPLETE */
6615 if (ipw2100_enable_adapter(priv)) {
6616 printk(KERN_WARNING DRV_NAME
6617 ": %s: failed in call to enable adapter.\n",
6618 priv->net_dev->name);
6619 ipw2100_hw_stop_adapter(priv);
6624 /* Start a scan . . . */
6625 ipw2100_set_scan_options(priv);
6626 ipw2100_start_scan(priv);
6629 IPW_DEBUG_INFO("exit\n");
6631 priv->status |= STATUS_INITIALIZED;
6633 up(&priv->action_sem);
6638 up(&priv->action_sem);
6643 unregister_netdev(dev);
6645 ipw2100_hw_stop_adapter(priv);
6647 ipw2100_disable_interrupts(priv);
6650 free_irq(dev->irq, priv);
6652 ipw2100_kill_workqueue(priv);
6654 /* These are safe to call even if they weren't allocated */
6655 ipw2100_queues_free(priv);
6656 sysfs_remove_group(&pci_dev->dev.kobj, &ipw2100_attribute_group);
6658 free_ieee80211(dev);
6659 pci_set_drvdata(pci_dev, NULL);
6665 pci_release_regions(pci_dev);
6666 pci_disable_device(pci_dev);
6671 static void __devexit ipw2100_pci_remove_one(struct pci_dev *pci_dev)
6673 struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
6674 struct net_device *dev;
6677 down(&priv->action_sem);
6679 priv->status &= ~STATUS_INITIALIZED;
6681 dev = priv->net_dev;
6682 sysfs_remove_group(&pci_dev->dev.kobj, &ipw2100_attribute_group);
6685 if (ipw2100_firmware.version)
6686 ipw2100_release_firmware(priv, &ipw2100_firmware);
6688 /* Take down the hardware */
6691 /* Release the semaphore so that the network subsystem can
6692 * complete any needed calls into the driver... */
6693 up(&priv->action_sem);
6695 /* Unregister the device first - this results in close()
6696 * being called if the device is open. If we free storage
6697 * first, then close() will crash. */
6698 unregister_netdev(dev);
6700 /* ipw2100_down will ensure that there is no more pending work
6701 * in the workqueue's, so we can safely remove them now. */
6702 ipw2100_kill_workqueue(priv);
6704 ipw2100_queues_free(priv);
6706 /* Free potential debugging firmware snapshot */
6707 ipw2100_snapshot_free(priv);
6710 free_irq(dev->irq, priv);
6713 iounmap((void __iomem *)dev->base_addr);
6715 free_ieee80211(dev);
6718 pci_release_regions(pci_dev);
6719 pci_disable_device(pci_dev);
6721 IPW_DEBUG_INFO("exit\n");
6726 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11)
6727 static int ipw2100_suspend(struct pci_dev *pci_dev, u32 state)
6729 static int ipw2100_suspend(struct pci_dev *pci_dev, pm_message_t state)
6732 struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
6733 struct net_device *dev = priv->net_dev;
6735 IPW_DEBUG_INFO("%s: Going into suspend...\n",
6738 down(&priv->action_sem);
6739 if (priv->status & STATUS_INITIALIZED) {
6740 /* Take down the device; powers it off, etc. */
6744 /* Remove the PRESENT state of the device */
6745 netif_device_detach(dev);
6747 pci_save_state(pci_dev);
6748 pci_disable_device (pci_dev);
6749 pci_set_power_state(pci_dev, PCI_D3hot);
6751 up(&priv->action_sem);
6756 static int ipw2100_resume(struct pci_dev *pci_dev)
6758 struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
6759 struct net_device *dev = priv->net_dev;
6762 if (IPW2100_PM_DISABLED)
6765 down(&priv->action_sem);
6767 IPW_DEBUG_INFO("%s: Coming out of suspend...\n",
6770 pci_set_power_state(pci_dev, PCI_D0);
6771 pci_enable_device(pci_dev);
6772 pci_restore_state(pci_dev);
6775 * Suspend/Resume resets the PCI configuration space, so we have to
6776 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
6777 * from interfering with C3 CPU state. pci_restore_state won't help
6778 * here since it only restores the first 64 bytes pci config header.
6780 pci_read_config_dword(pci_dev, 0x40, &val);
6781 if ((val & 0x0000ff00) != 0)
6782 pci_write_config_dword(pci_dev, 0x40, val & 0xffff00ff);
6784 /* Set the device back into the PRESENT state; this will also wake
6785 * the queue of needed */
6786 netif_device_attach(dev);
6788 /* Bring the device back up */
6789 if (!(priv->status & STATUS_RF_KILL_SW))
6790 ipw2100_up(priv, 0);
6792 up(&priv->action_sem);
6799 #define IPW2100_DEV_ID(x) { PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, x }
6801 static struct pci_device_id ipw2100_pci_id_table[] __devinitdata = {
6802 IPW2100_DEV_ID(0x2520), /* IN 2100A mPCI 3A */
6803 IPW2100_DEV_ID(0x2521), /* IN 2100A mPCI 3B */
6804 IPW2100_DEV_ID(0x2524), /* IN 2100A mPCI 3B */
6805 IPW2100_DEV_ID(0x2525), /* IN 2100A mPCI 3B */
6806 IPW2100_DEV_ID(0x2526), /* IN 2100A mPCI Gen A3 */
6807 IPW2100_DEV_ID(0x2522), /* IN 2100 mPCI 3B */
6808 IPW2100_DEV_ID(0x2523), /* IN 2100 mPCI 3A */
6809 IPW2100_DEV_ID(0x2527), /* IN 2100 mPCI 3B */
6810 IPW2100_DEV_ID(0x2528), /* IN 2100 mPCI 3B */
6811 IPW2100_DEV_ID(0x2529), /* IN 2100 mPCI 3B */
6812 IPW2100_DEV_ID(0x252B), /* IN 2100 mPCI 3A */
6813 IPW2100_DEV_ID(0x252C), /* IN 2100 mPCI 3A */
6814 IPW2100_DEV_ID(0x252D), /* IN 2100 mPCI 3A */
6816 IPW2100_DEV_ID(0x2550), /* IB 2100A mPCI 3B */
6817 IPW2100_DEV_ID(0x2551), /* IB 2100 mPCI 3B */
6818 IPW2100_DEV_ID(0x2553), /* IB 2100 mPCI 3B */
6819 IPW2100_DEV_ID(0x2554), /* IB 2100 mPCI 3B */
6820 IPW2100_DEV_ID(0x2555), /* IB 2100 mPCI 3B */
6822 IPW2100_DEV_ID(0x2560), /* DE 2100A mPCI 3A */
6823 IPW2100_DEV_ID(0x2562), /* DE 2100A mPCI 3A */
6824 IPW2100_DEV_ID(0x2563), /* DE 2100A mPCI 3A */
6825 IPW2100_DEV_ID(0x2561), /* DE 2100 mPCI 3A */
6826 IPW2100_DEV_ID(0x2565), /* DE 2100 mPCI 3A */
6827 IPW2100_DEV_ID(0x2566), /* DE 2100 mPCI 3A */
6828 IPW2100_DEV_ID(0x2567), /* DE 2100 mPCI 3A */
6830 IPW2100_DEV_ID(0x2570), /* GA 2100 mPCI 3B */
6832 IPW2100_DEV_ID(0x2580), /* TO 2100A mPCI 3B */
6833 IPW2100_DEV_ID(0x2582), /* TO 2100A mPCI 3B */
6834 IPW2100_DEV_ID(0x2583), /* TO 2100A mPCI 3B */
6835 IPW2100_DEV_ID(0x2581), /* TO 2100 mPCI 3B */
6836 IPW2100_DEV_ID(0x2585), /* TO 2100 mPCI 3B */
6837 IPW2100_DEV_ID(0x2586), /* TO 2100 mPCI 3B */
6838 IPW2100_DEV_ID(0x2587), /* TO 2100 mPCI 3B */
6840 IPW2100_DEV_ID(0x2590), /* SO 2100A mPCI 3B */
6841 IPW2100_DEV_ID(0x2592), /* SO 2100A mPCI 3B */
6842 IPW2100_DEV_ID(0x2591), /* SO 2100 mPCI 3B */
6843 IPW2100_DEV_ID(0x2593), /* SO 2100 mPCI 3B */
6844 IPW2100_DEV_ID(0x2596), /* SO 2100 mPCI 3B */
6845 IPW2100_DEV_ID(0x2598), /* SO 2100 mPCI 3B */
6847 IPW2100_DEV_ID(0x25A0), /* HP 2100 mPCI 3B */
6851 MODULE_DEVICE_TABLE(pci, ipw2100_pci_id_table);
6853 static struct pci_driver ipw2100_pci_driver = {
6855 .id_table = ipw2100_pci_id_table,
6856 .probe = ipw2100_pci_init_one,
6857 .remove = __devexit_p(ipw2100_pci_remove_one),
6859 .suspend = ipw2100_suspend,
6860 .resume = ipw2100_resume,
6866 * Initialize the ipw2100 driver/module
6868 * @returns 0 if ok, < 0 errno node con error.
6870 * Note: we cannot init the /proc stuff until the PCI driver is there,
6871 * or we risk an unlikely race condition on someone accessing
6872 * uninitialized data in the PCI dev struct through /proc.
6874 static int __init ipw2100_init(void)
6878 printk(KERN_INFO DRV_NAME ": %s, %s\n", DRV_DESCRIPTION, DRV_VERSION);
6879 printk(KERN_INFO DRV_NAME ": %s\n", DRV_COPYRIGHT);
6881 #ifdef CONFIG_IEEE80211_NOWEP
6882 IPW_DEBUG_INFO(DRV_NAME ": Compiled with WEP disabled.\n");
6885 ret = pci_module_init(&ipw2100_pci_driver);
6887 #ifdef CONFIG_IPW_DEBUG
6888 ipw2100_debug_level = debug;
6889 driver_create_file(&ipw2100_pci_driver.driver,
6890 &driver_attr_debug_level);
6898 * Cleanup ipw2100 driver registration
6900 static void __exit ipw2100_exit(void)
6902 /* FIXME: IPG: check that we have no instances of the devices open */
6903 #ifdef CONFIG_IPW_DEBUG
6904 driver_remove_file(&ipw2100_pci_driver.driver,
6905 &driver_attr_debug_level);
6907 pci_unregister_driver(&ipw2100_pci_driver);
6910 module_init(ipw2100_init);
6911 module_exit(ipw2100_exit);
6913 #define WEXT_USECHANNELS 1
6915 static const long ipw2100_frequencies[] = {
6916 2412, 2417, 2422, 2427,
6917 2432, 2437, 2442, 2447,
6918 2452, 2457, 2462, 2467,
6922 #define FREQ_COUNT (sizeof(ipw2100_frequencies) / \
6923 sizeof(ipw2100_frequencies[0]))
6925 static const long ipw2100_rates_11b[] = {
6932 #define RATE_COUNT (sizeof(ipw2100_rates_11b) / sizeof(ipw2100_rates_11b[0]))
6934 static int ipw2100_wx_get_name(struct net_device *dev,
6935 struct iw_request_info *info,
6936 union iwreq_data *wrqu, char *extra)
6939 * This can be called at any time. No action lock required
6942 struct ipw2100_priv *priv = ieee80211_priv(dev);
6943 if (!(priv->status & STATUS_ASSOCIATED))
6944 strcpy(wrqu->name, "unassociated");
6946 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11b");
6948 IPW_DEBUG_WX("Name: %s\n", wrqu->name);
6953 static int ipw2100_wx_set_freq(struct net_device *dev,
6954 struct iw_request_info *info,
6955 union iwreq_data *wrqu, char *extra)
6957 struct ipw2100_priv *priv = ieee80211_priv(dev);
6958 struct iw_freq *fwrq = &wrqu->freq;
6961 if (priv->ieee->iw_mode == IW_MODE_INFRA)
6964 down(&priv->action_sem);
6965 if (!(priv->status & STATUS_INITIALIZED)) {
6970 /* if setting by freq convert to channel */
6972 if ((fwrq->m >= (int) 2.412e8 &&
6973 fwrq->m <= (int) 2.487e8)) {
6974 int f = fwrq->m / 100000;
6977 while ((c < REG_MAX_CHANNEL) &&
6978 (f != ipw2100_frequencies[c]))
6981 /* hack to fall through */
6987 if (fwrq->e > 0 || fwrq->m > 1000)
6989 else { /* Set the channel */
6990 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
6991 err = ipw2100_set_channel(priv, fwrq->m, 0);
6995 up(&priv->action_sem);
7000 static int ipw2100_wx_get_freq(struct net_device *dev,
7001 struct iw_request_info *info,
7002 union iwreq_data *wrqu, char *extra)
7005 * This can be called at any time. No action lock required
7008 struct ipw2100_priv *priv = ieee80211_priv(dev);
7012 /* If we are associated, trying to associate, or have a statically
7013 * configured CHANNEL then return that; otherwise return ANY */
7014 if (priv->config & CFG_STATIC_CHANNEL ||
7015 priv->status & STATUS_ASSOCIATED)
7016 wrqu->freq.m = priv->channel;
7020 IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
7025 static int ipw2100_wx_set_mode(struct net_device *dev,
7026 struct iw_request_info *info,
7027 union iwreq_data *wrqu, char *extra)
7029 struct ipw2100_priv *priv = ieee80211_priv(dev);
7032 IPW_DEBUG_WX("SET Mode -> %d \n", wrqu->mode);
7034 if (wrqu->mode == priv->ieee->iw_mode)
7037 down(&priv->action_sem);
7038 if (!(priv->status & STATUS_INITIALIZED)) {
7043 switch (wrqu->mode) {
7044 #ifdef CONFIG_IPW2100_MONITOR
7045 case IW_MODE_MONITOR:
7046 err = ipw2100_switch_mode(priv, IW_MODE_MONITOR);
7048 #endif /* CONFIG_IPW2100_MONITOR */
7050 err = ipw2100_switch_mode(priv, IW_MODE_ADHOC);
7055 err = ipw2100_switch_mode(priv, IW_MODE_INFRA);
7060 up(&priv->action_sem);
7064 static int ipw2100_wx_get_mode(struct net_device *dev,
7065 struct iw_request_info *info,
7066 union iwreq_data *wrqu, char *extra)
7069 * This can be called at any time. No action lock required
7072 struct ipw2100_priv *priv = ieee80211_priv(dev);
7074 wrqu->mode = priv->ieee->iw_mode;
7075 IPW_DEBUG_WX("GET Mode -> %d\n", wrqu->mode);
7081 #define POWER_MODES 5
7083 /* Values are in microsecond */
7084 static const s32 timeout_duration[POWER_MODES] = {
7092 static const s32 period_duration[POWER_MODES] = {
7100 static int ipw2100_wx_get_range(struct net_device *dev,
7101 struct iw_request_info *info,
7102 union iwreq_data *wrqu, char *extra)
7105 * This can be called at any time. No action lock required
7108 struct ipw2100_priv *priv = ieee80211_priv(dev);
7109 struct iw_range *range = (struct iw_range *)extra;
7113 wrqu->data.length = sizeof(*range);
7114 memset(range, 0, sizeof(*range));
7116 /* Let's try to keep this struct in the same order as in
7117 * linux/include/wireless.h
7120 /* TODO: See what values we can set, and remove the ones we can't
7121 * set, or fill them with some default data.
7124 /* ~5 Mb/s real (802.11b) */
7125 range->throughput = 5 * 1000 * 1000;
7127 // range->sensitivity; /* signal level threshold range */
7129 range->max_qual.qual = 100;
7130 /* TODO: Find real max RSSI and stick here */
7131 range->max_qual.level = 0;
7132 range->max_qual.noise = 0;
7133 range->max_qual.updated = 7; /* Updated all three */
7135 range->avg_qual.qual = 70; /* > 8% missed beacons is 'bad' */
7136 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
7137 range->avg_qual.level = 20 + IPW2100_RSSI_TO_DBM;
7138 range->avg_qual.noise = 0;
7139 range->avg_qual.updated = 7; /* Updated all three */
7141 range->num_bitrates = RATE_COUNT;
7143 for (i = 0; i < RATE_COUNT && i < IW_MAX_BITRATES; i++) {
7144 range->bitrate[i] = ipw2100_rates_11b[i];
7147 range->min_rts = MIN_RTS_THRESHOLD;
7148 range->max_rts = MAX_RTS_THRESHOLD;
7149 range->min_frag = MIN_FRAG_THRESHOLD;
7150 range->max_frag = MAX_FRAG_THRESHOLD;
7152 range->min_pmp = period_duration[0]; /* Minimal PM period */
7153 range->max_pmp = period_duration[POWER_MODES-1];/* Maximal PM period */
7154 range->min_pmt = timeout_duration[POWER_MODES-1]; /* Minimal PM timeout */
7155 range->max_pmt = timeout_duration[0];/* Maximal PM timeout */
7157 /* How to decode max/min PM period */
7158 range->pmp_flags = IW_POWER_PERIOD;
7159 /* How to decode max/min PM period */
7160 range->pmt_flags = IW_POWER_TIMEOUT;
7161 /* What PM options are supported */
7162 range->pm_capa = IW_POWER_TIMEOUT | IW_POWER_PERIOD;
7164 range->encoding_size[0] = 5;
7165 range->encoding_size[1] = 13; /* Different token sizes */
7166 range->num_encoding_sizes = 2; /* Number of entry in the list */
7167 range->max_encoding_tokens = WEP_KEYS; /* Max number of tokens */
7168 // range->encoding_login_index; /* token index for login token */
7170 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7171 range->txpower_capa = IW_TXPOW_DBM;
7172 range->num_txpower = IW_MAX_TXPOWER;
7173 for (i = 0, level = (IPW_TX_POWER_MAX_DBM * 16); i < IW_MAX_TXPOWER;
7174 i++, level -= ((IPW_TX_POWER_MAX_DBM - IPW_TX_POWER_MIN_DBM) * 16) /
7175 (IW_MAX_TXPOWER - 1))
7176 range->txpower[i] = level / 16;
7178 range->txpower_capa = 0;
7179 range->num_txpower = 0;
7183 /* Set the Wireless Extension versions */
7184 range->we_version_compiled = WIRELESS_EXT;
7185 range->we_version_source = 16;
7187 // range->retry_capa; /* What retry options are supported */
7188 // range->retry_flags; /* How to decode max/min retry limit */
7189 // range->r_time_flags; /* How to decode max/min retry life */
7190 // range->min_retry; /* Minimal number of retries */
7191 // range->max_retry; /* Maximal number of retries */
7192 // range->min_r_time; /* Minimal retry lifetime */
7193 // range->max_r_time; /* Maximal retry lifetime */
7195 range->num_channels = FREQ_COUNT;
7198 for (i = 0; i < FREQ_COUNT; i++) {
7199 // TODO: Include only legal frequencies for some countries
7200 // if (local->channel_mask & (1 << i)) {
7201 range->freq[val].i = i + 1;
7202 range->freq[val].m = ipw2100_frequencies[i] * 100000;
7203 range->freq[val].e = 1;
7206 if (val == IW_MAX_FREQUENCIES)
7209 range->num_frequency = val;
7211 IPW_DEBUG_WX("GET Range\n");
7216 static int ipw2100_wx_set_wap(struct net_device *dev,
7217 struct iw_request_info *info,
7218 union iwreq_data *wrqu, char *extra)
7220 struct ipw2100_priv *priv = ieee80211_priv(dev);
7223 static const unsigned char any[] = {
7224 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
7226 static const unsigned char off[] = {
7227 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
7231 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
7234 down(&priv->action_sem);
7235 if (!(priv->status & STATUS_INITIALIZED)) {
7240 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
7241 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
7242 /* we disable mandatory BSSID association */
7243 IPW_DEBUG_WX("exit - disable mandatory BSSID\n");
7244 priv->config &= ~CFG_STATIC_BSSID;
7245 err = ipw2100_set_mandatory_bssid(priv, NULL, 0);
7249 priv->config |= CFG_STATIC_BSSID;
7250 memcpy(priv->mandatory_bssid_mac, wrqu->ap_addr.sa_data, ETH_ALEN);
7252 err = ipw2100_set_mandatory_bssid(priv, wrqu->ap_addr.sa_data, 0);
7254 IPW_DEBUG_WX("SET BSSID -> %02X:%02X:%02X:%02X:%02X:%02X\n",
7255 wrqu->ap_addr.sa_data[0] & 0xff,
7256 wrqu->ap_addr.sa_data[1] & 0xff,
7257 wrqu->ap_addr.sa_data[2] & 0xff,
7258 wrqu->ap_addr.sa_data[3] & 0xff,
7259 wrqu->ap_addr.sa_data[4] & 0xff,
7260 wrqu->ap_addr.sa_data[5] & 0xff);
7263 up(&priv->action_sem);
7267 static int ipw2100_wx_get_wap(struct net_device *dev,
7268 struct iw_request_info *info,
7269 union iwreq_data *wrqu, char *extra)
7272 * This can be called at any time. No action lock required
7275 struct ipw2100_priv *priv = ieee80211_priv(dev);
7277 /* If we are associated, trying to associate, or have a statically
7278 * configured BSSID then return that; otherwise return ANY */
7279 if (priv->config & CFG_STATIC_BSSID ||
7280 priv->status & STATUS_ASSOCIATED) {
7281 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
7282 memcpy(wrqu->ap_addr.sa_data, &priv->bssid, ETH_ALEN);
7284 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
7286 IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n",
7287 MAC_ARG(wrqu->ap_addr.sa_data));
7291 static int ipw2100_wx_set_essid(struct net_device *dev,
7292 struct iw_request_info *info,
7293 union iwreq_data *wrqu, char *extra)
7295 struct ipw2100_priv *priv = ieee80211_priv(dev);
7296 char *essid = ""; /* ANY */
7300 down(&priv->action_sem);
7301 if (!(priv->status & STATUS_INITIALIZED)) {
7306 if (wrqu->essid.flags && wrqu->essid.length) {
7307 length = wrqu->essid.length - 1;
7312 IPW_DEBUG_WX("Setting ESSID to ANY\n");
7313 priv->config &= ~CFG_STATIC_ESSID;
7314 err = ipw2100_set_essid(priv, NULL, 0, 0);
7318 length = min(length, IW_ESSID_MAX_SIZE);
7320 priv->config |= CFG_STATIC_ESSID;
7322 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
7323 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
7328 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length),
7331 priv->essid_len = length;
7332 memcpy(priv->essid, essid, priv->essid_len);
7334 err = ipw2100_set_essid(priv, essid, length, 0);
7337 up(&priv->action_sem);
7341 static int ipw2100_wx_get_essid(struct net_device *dev,
7342 struct iw_request_info *info,
7343 union iwreq_data *wrqu, char *extra)
7346 * This can be called at any time. No action lock required
7349 struct ipw2100_priv *priv = ieee80211_priv(dev);
7351 /* If we are associated, trying to associate, or have a statically
7352 * configured ESSID then return that; otherwise return ANY */
7353 if (priv->config & CFG_STATIC_ESSID ||
7354 priv->status & STATUS_ASSOCIATED) {
7355 IPW_DEBUG_WX("Getting essid: '%s'\n",
7356 escape_essid(priv->essid, priv->essid_len));
7357 memcpy(extra, priv->essid, priv->essid_len);
7358 wrqu->essid.length = priv->essid_len;
7359 wrqu->essid.flags = 1; /* active */
7361 IPW_DEBUG_WX("Getting essid: ANY\n");
7362 wrqu->essid.length = 0;
7363 wrqu->essid.flags = 0; /* active */
7369 static int ipw2100_wx_set_nick(struct net_device *dev,
7370 struct iw_request_info *info,
7371 union iwreq_data *wrqu, char *extra)
7374 * This can be called at any time. No action lock required
7377 struct ipw2100_priv *priv = ieee80211_priv(dev);
7379 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
7382 wrqu->data.length = min((size_t)wrqu->data.length, sizeof(priv->nick));
7383 memset(priv->nick, 0, sizeof(priv->nick));
7384 memcpy(priv->nick, extra, wrqu->data.length);
7386 IPW_DEBUG_WX("SET Nickname -> %s \n", priv->nick);
7391 static int ipw2100_wx_get_nick(struct net_device *dev,
7392 struct iw_request_info *info,
7393 union iwreq_data *wrqu, char *extra)
7396 * This can be called at any time. No action lock required
7399 struct ipw2100_priv *priv = ieee80211_priv(dev);
7401 wrqu->data.length = strlen(priv->nick) + 1;
7402 memcpy(extra, priv->nick, wrqu->data.length);
7403 wrqu->data.flags = 1; /* active */
7405 IPW_DEBUG_WX("GET Nickname -> %s \n", extra);
7410 static int ipw2100_wx_set_rate(struct net_device *dev,
7411 struct iw_request_info *info,
7412 union iwreq_data *wrqu, char *extra)
7414 struct ipw2100_priv *priv = ieee80211_priv(dev);
7415 u32 target_rate = wrqu->bitrate.value;
7419 down(&priv->action_sem);
7420 if (!(priv->status & STATUS_INITIALIZED)) {
7427 if (target_rate == 1000000 ||
7428 (!wrqu->bitrate.fixed && target_rate > 1000000))
7429 rate |= TX_RATE_1_MBIT;
7430 if (target_rate == 2000000 ||
7431 (!wrqu->bitrate.fixed && target_rate > 2000000))
7432 rate |= TX_RATE_2_MBIT;
7433 if (target_rate == 5500000 ||
7434 (!wrqu->bitrate.fixed && target_rate > 5500000))
7435 rate |= TX_RATE_5_5_MBIT;
7436 if (target_rate == 11000000 ||
7437 (!wrqu->bitrate.fixed && target_rate > 11000000))
7438 rate |= TX_RATE_11_MBIT;
7440 rate = DEFAULT_TX_RATES;
7442 err = ipw2100_set_tx_rates(priv, rate, 0);
7444 IPW_DEBUG_WX("SET Rate -> %04X \n", rate);
7446 up(&priv->action_sem);
7451 static int ipw2100_wx_get_rate(struct net_device *dev,
7452 struct iw_request_info *info,
7453 union iwreq_data *wrqu, char *extra)
7455 struct ipw2100_priv *priv = ieee80211_priv(dev);
7457 int len = sizeof(val);
7460 if (!(priv->status & STATUS_ENABLED) ||
7461 priv->status & STATUS_RF_KILL_MASK ||
7462 !(priv->status & STATUS_ASSOCIATED)) {
7463 wrqu->bitrate.value = 0;
7467 down(&priv->action_sem);
7468 if (!(priv->status & STATUS_INITIALIZED)) {
7473 err = ipw2100_get_ordinal(priv, IPW_ORD_CURRENT_TX_RATE, &val, &len);
7475 IPW_DEBUG_WX("failed querying ordinals.\n");
7479 switch (val & TX_RATE_MASK) {
7480 case TX_RATE_1_MBIT:
7481 wrqu->bitrate.value = 1000000;
7483 case TX_RATE_2_MBIT:
7484 wrqu->bitrate.value = 2000000;
7486 case TX_RATE_5_5_MBIT:
7487 wrqu->bitrate.value = 5500000;
7489 case TX_RATE_11_MBIT:
7490 wrqu->bitrate.value = 11000000;
7493 wrqu->bitrate.value = 0;
7496 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
7499 up(&priv->action_sem);
7503 static int ipw2100_wx_set_rts(struct net_device *dev,
7504 struct iw_request_info *info,
7505 union iwreq_data *wrqu, char *extra)
7507 struct ipw2100_priv *priv = ieee80211_priv(dev);
7510 /* Auto RTS not yet supported */
7511 if (wrqu->rts.fixed == 0)
7514 down(&priv->action_sem);
7515 if (!(priv->status & STATUS_INITIALIZED)) {
7520 if (wrqu->rts.disabled)
7521 value = priv->rts_threshold | RTS_DISABLED;
7523 if (wrqu->rts.value < 1 ||
7524 wrqu->rts.value > 2304) {
7528 value = wrqu->rts.value;
7531 err = ipw2100_set_rts_threshold(priv, value);
7533 IPW_DEBUG_WX("SET RTS Threshold -> 0x%08X \n", value);
7535 up(&priv->action_sem);
7539 static int ipw2100_wx_get_rts(struct net_device *dev,
7540 struct iw_request_info *info,
7541 union iwreq_data *wrqu, char *extra)
7544 * This can be called at any time. No action lock required
7547 struct ipw2100_priv *priv = ieee80211_priv(dev);
7549 wrqu->rts.value = priv->rts_threshold & ~RTS_DISABLED;
7550 wrqu->rts.fixed = 1; /* no auto select */
7552 /* If RTS is set to the default value, then it is disabled */
7553 wrqu->rts.disabled = (priv->rts_threshold & RTS_DISABLED) ? 1 : 0;
7555 IPW_DEBUG_WX("GET RTS Threshold -> 0x%08X \n", wrqu->rts.value);
7560 static int ipw2100_wx_set_txpow(struct net_device *dev,
7561 struct iw_request_info *info,
7562 union iwreq_data *wrqu, char *extra)
7564 struct ipw2100_priv *priv = ieee80211_priv(dev);
7567 if (priv->ieee->iw_mode != IW_MODE_ADHOC)
7570 if (wrqu->txpower.disabled == 1 || wrqu->txpower.fixed == 0)
7571 value = IPW_TX_POWER_DEFAULT;
7573 if (wrqu->txpower.value < IPW_TX_POWER_MIN_DBM ||
7574 wrqu->txpower.value > IPW_TX_POWER_MAX_DBM)
7577 value = (wrqu->txpower.value - IPW_TX_POWER_MIN_DBM) * 16 /
7578 (IPW_TX_POWER_MAX_DBM - IPW_TX_POWER_MIN_DBM);
7581 down(&priv->action_sem);
7582 if (!(priv->status & STATUS_INITIALIZED)) {
7587 err = ipw2100_set_tx_power(priv, value);
7589 IPW_DEBUG_WX("SET TX Power -> %d \n", value);
7592 up(&priv->action_sem);
7596 static int ipw2100_wx_get_txpow(struct net_device *dev,
7597 struct iw_request_info *info,
7598 union iwreq_data *wrqu, char *extra)
7601 * This can be called at any time. No action lock required
7604 struct ipw2100_priv *priv = ieee80211_priv(dev);
7606 if (priv->ieee->iw_mode != IW_MODE_ADHOC) {
7607 wrqu->power.disabled = 1;
7611 if (priv->tx_power == IPW_TX_POWER_DEFAULT) {
7612 wrqu->power.fixed = 0;
7613 wrqu->power.value = IPW_TX_POWER_MAX_DBM;
7614 wrqu->power.disabled = 1;
7616 wrqu->power.disabled = 0;
7617 wrqu->power.fixed = 1;
7620 (IPW_TX_POWER_MAX_DBM - IPW_TX_POWER_MIN_DBM)) /
7621 (IPW_TX_POWER_MAX - IPW_TX_POWER_MIN) +
7622 IPW_TX_POWER_MIN_DBM;
7625 wrqu->power.flags = IW_TXPOW_DBM;
7627 IPW_DEBUG_WX("GET TX Power -> %d \n", wrqu->power.value);
7632 static int ipw2100_wx_set_frag(struct net_device *dev,
7633 struct iw_request_info *info,
7634 union iwreq_data *wrqu, char *extra)
7637 * This can be called at any time. No action lock required
7640 struct ipw2100_priv *priv = ieee80211_priv(dev);
7642 if (!wrqu->frag.fixed)
7645 if (wrqu->frag.disabled) {
7646 priv->frag_threshold |= FRAG_DISABLED;
7647 priv->ieee->fts = DEFAULT_FTS;
7649 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
7650 wrqu->frag.value > MAX_FRAG_THRESHOLD)
7653 priv->ieee->fts = wrqu->frag.value & ~0x1;
7654 priv->frag_threshold = priv->ieee->fts;
7657 IPW_DEBUG_WX("SET Frag Threshold -> %d \n", priv->ieee->fts);
7662 static int ipw2100_wx_get_frag(struct net_device *dev,
7663 struct iw_request_info *info,
7664 union iwreq_data *wrqu, char *extra)
7667 * This can be called at any time. No action lock required
7670 struct ipw2100_priv *priv = ieee80211_priv(dev);
7671 wrqu->frag.value = priv->frag_threshold & ~FRAG_DISABLED;
7672 wrqu->frag.fixed = 0; /* no auto select */
7673 wrqu->frag.disabled = (priv->frag_threshold & FRAG_DISABLED) ? 1 : 0;
7675 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
7680 static int ipw2100_wx_set_retry(struct net_device *dev,
7681 struct iw_request_info *info,
7682 union iwreq_data *wrqu, char *extra)
7684 struct ipw2100_priv *priv = ieee80211_priv(dev);
7687 if (wrqu->retry.flags & IW_RETRY_LIFETIME ||
7688 wrqu->retry.disabled)
7691 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
7694 down(&priv->action_sem);
7695 if (!(priv->status & STATUS_INITIALIZED)) {
7700 if (wrqu->retry.flags & IW_RETRY_MIN) {
7701 err = ipw2100_set_short_retry(priv, wrqu->retry.value);
7702 IPW_DEBUG_WX("SET Short Retry Limit -> %d \n",
7707 if (wrqu->retry.flags & IW_RETRY_MAX) {
7708 err = ipw2100_set_long_retry(priv, wrqu->retry.value);
7709 IPW_DEBUG_WX("SET Long Retry Limit -> %d \n",
7714 err = ipw2100_set_short_retry(priv, wrqu->retry.value);
7716 err = ipw2100_set_long_retry(priv, wrqu->retry.value);
7718 IPW_DEBUG_WX("SET Both Retry Limits -> %d \n", wrqu->retry.value);
7721 up(&priv->action_sem);
7725 static int ipw2100_wx_get_retry(struct net_device *dev,
7726 struct iw_request_info *info,
7727 union iwreq_data *wrqu, char *extra)
7730 * This can be called at any time. No action lock required
7733 struct ipw2100_priv *priv = ieee80211_priv(dev);
7735 wrqu->retry.disabled = 0; /* can't be disabled */
7737 if ((wrqu->retry.flags & IW_RETRY_TYPE) ==
7741 if (wrqu->retry.flags & IW_RETRY_MAX) {
7742 wrqu->retry.flags = IW_RETRY_LIMIT & IW_RETRY_MAX;
7743 wrqu->retry.value = priv->long_retry_limit;
7746 (priv->short_retry_limit !=
7747 priv->long_retry_limit) ?
7748 IW_RETRY_LIMIT & IW_RETRY_MIN : IW_RETRY_LIMIT;
7750 wrqu->retry.value = priv->short_retry_limit;
7753 IPW_DEBUG_WX("GET Retry -> %d \n", wrqu->retry.value);
7758 static int ipw2100_wx_set_scan(struct net_device *dev,
7759 struct iw_request_info *info,
7760 union iwreq_data *wrqu, char *extra)
7762 struct ipw2100_priv *priv = ieee80211_priv(dev);
7765 down(&priv->action_sem);
7766 if (!(priv->status & STATUS_INITIALIZED)) {
7771 IPW_DEBUG_WX("Initiating scan...\n");
7772 if (ipw2100_set_scan_options(priv) ||
7773 ipw2100_start_scan(priv)) {
7774 IPW_DEBUG_WX("Start scan failed.\n");
7776 /* TODO: Mark a scan as pending so when hardware initialized
7781 up(&priv->action_sem);
7785 static int ipw2100_wx_get_scan(struct net_device *dev,
7786 struct iw_request_info *info,
7787 union iwreq_data *wrqu, char *extra)
7790 * This can be called at any time. No action lock required
7793 struct ipw2100_priv *priv = ieee80211_priv(dev);
7794 return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra);
7799 * Implementation based on code in hostap-driver v0.1.3 hostap_ioctl.c
7801 static int ipw2100_wx_set_encode(struct net_device *dev,
7802 struct iw_request_info *info,
7803 union iwreq_data *wrqu, char *key)
7806 * No check of STATUS_INITIALIZED required
7809 struct ipw2100_priv *priv = ieee80211_priv(dev);
7810 return ieee80211_wx_set_encode(priv->ieee, info, wrqu, key);
7813 static int ipw2100_wx_get_encode(struct net_device *dev,
7814 struct iw_request_info *info,
7815 union iwreq_data *wrqu, char *key)
7818 * This can be called at any time. No action lock required
7821 struct ipw2100_priv *priv = ieee80211_priv(dev);
7822 return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key);
7825 static int ipw2100_wx_set_power(struct net_device *dev,
7826 struct iw_request_info *info,
7827 union iwreq_data *wrqu, char *extra)
7829 struct ipw2100_priv *priv = ieee80211_priv(dev);
7832 down(&priv->action_sem);
7833 if (!(priv->status & STATUS_INITIALIZED)) {
7838 if (wrqu->power.disabled) {
7839 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
7840 err = ipw2100_set_power_mode(priv, IPW_POWER_MODE_CAM);
7841 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
7845 switch (wrqu->power.flags & IW_POWER_MODE) {
7846 case IW_POWER_ON: /* If not specified */
7847 case IW_POWER_MODE: /* If set all mask */
7848 case IW_POWER_ALL_R: /* If explicitely state all */
7850 default: /* Otherwise we don't support it */
7851 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
7857 /* If the user hasn't specified a power management mode yet, default
7859 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
7860 err = ipw2100_set_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
7862 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n",
7866 up(&priv->action_sem);
7871 static int ipw2100_wx_get_power(struct net_device *dev,
7872 struct iw_request_info *info,
7873 union iwreq_data *wrqu, char *extra)
7876 * This can be called at any time. No action lock required
7879 struct ipw2100_priv *priv = ieee80211_priv(dev);
7881 if (!(priv->power_mode & IPW_POWER_ENABLED)) {
7882 wrqu->power.disabled = 1;
7884 wrqu->power.disabled = 0;
7885 wrqu->power.flags = 0;
7888 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
7899 #ifdef CONFIG_IPW2100_MONITOR
7900 static int ipw2100_wx_set_promisc(struct net_device *dev,
7901 struct iw_request_info *info,
7902 union iwreq_data *wrqu, char *extra)
7904 struct ipw2100_priv *priv = ieee80211_priv(dev);
7905 int *parms = (int *)extra;
7906 int enable = (parms[0] > 0);
7909 down(&priv->action_sem);
7910 if (!(priv->status & STATUS_INITIALIZED)) {
7916 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7917 err = ipw2100_set_channel(priv, parms[1], 0);
7920 priv->channel = parms[1];
7921 err = ipw2100_switch_mode(priv, IW_MODE_MONITOR);
7923 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
7924 err = ipw2100_switch_mode(priv, priv->last_mode);
7927 up(&priv->action_sem);
7931 static int ipw2100_wx_reset(struct net_device *dev,
7932 struct iw_request_info *info,
7933 union iwreq_data *wrqu, char *extra)
7935 struct ipw2100_priv *priv = ieee80211_priv(dev);
7936 if (priv->status & STATUS_INITIALIZED)
7937 schedule_reset(priv);
7943 static int ipw2100_wx_set_powermode(struct net_device *dev,
7944 struct iw_request_info *info,
7945 union iwreq_data *wrqu, char *extra)
7947 struct ipw2100_priv *priv = ieee80211_priv(dev);
7948 int err = 0, mode = *(int *)extra;
7950 down(&priv->action_sem);
7951 if (!(priv->status & STATUS_INITIALIZED)) {
7956 if ((mode < 1) || (mode > POWER_MODES))
7957 mode = IPW_POWER_AUTO;
7959 if (priv->power_mode != mode)
7960 err = ipw2100_set_power_mode(priv, mode);
7962 up(&priv->action_sem);
7966 #define MAX_POWER_STRING 80
7967 static int ipw2100_wx_get_powermode(struct net_device *dev,
7968 struct iw_request_info *info,
7969 union iwreq_data *wrqu, char *extra)
7972 * This can be called at any time. No action lock required
7975 struct ipw2100_priv *priv = ieee80211_priv(dev);
7976 int level = IPW_POWER_LEVEL(priv->power_mode);
7977 s32 timeout, period;
7979 if (!(priv->power_mode & IPW_POWER_ENABLED)) {
7980 snprintf(extra, MAX_POWER_STRING,
7981 "Power save level: %d (Off)", level);
7984 case IPW_POWER_MODE_CAM:
7985 snprintf(extra, MAX_POWER_STRING,
7986 "Power save level: %d (None)", level);
7988 case IPW_POWER_AUTO:
7989 snprintf(extra, MAX_POWER_STRING,
7990 "Power save level: %d (Auto)", 0);
7993 timeout = timeout_duration[level - 1] / 1000;
7994 period = period_duration[level - 1] / 1000;
7995 snprintf(extra, MAX_POWER_STRING,
7996 "Power save level: %d "
7997 "(Timeout %dms, Period %dms)",
7998 level, timeout, period);
8002 wrqu->data.length = strlen(extra) + 1;
8008 static int ipw2100_wx_set_preamble(struct net_device *dev,
8009 struct iw_request_info *info,
8010 union iwreq_data *wrqu, char *extra)
8012 struct ipw2100_priv *priv = ieee80211_priv(dev);
8013 int err, mode = *(int *)extra;
8015 down(&priv->action_sem);
8016 if (!(priv->status & STATUS_INITIALIZED)) {
8022 priv->config |= CFG_LONG_PREAMBLE;
8024 priv->config &= ~CFG_LONG_PREAMBLE;
8030 err = ipw2100_system_config(priv, 0);
8033 up(&priv->action_sem);
8037 static int ipw2100_wx_get_preamble(struct net_device *dev,
8038 struct iw_request_info *info,
8039 union iwreq_data *wrqu, char *extra)
8042 * This can be called at any time. No action lock required
8045 struct ipw2100_priv *priv = ieee80211_priv(dev);
8047 if (priv->config & CFG_LONG_PREAMBLE)
8048 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
8050 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
8055 static iw_handler ipw2100_wx_handlers[] =
8057 NULL, /* SIOCSIWCOMMIT */
8058 ipw2100_wx_get_name, /* SIOCGIWNAME */
8059 NULL, /* SIOCSIWNWID */
8060 NULL, /* SIOCGIWNWID */
8061 ipw2100_wx_set_freq, /* SIOCSIWFREQ */
8062 ipw2100_wx_get_freq, /* SIOCGIWFREQ */
8063 ipw2100_wx_set_mode, /* SIOCSIWMODE */
8064 ipw2100_wx_get_mode, /* SIOCGIWMODE */
8065 NULL, /* SIOCSIWSENS */
8066 NULL, /* SIOCGIWSENS */
8067 NULL, /* SIOCSIWRANGE */
8068 ipw2100_wx_get_range, /* SIOCGIWRANGE */
8069 NULL, /* SIOCSIWPRIV */
8070 NULL, /* SIOCGIWPRIV */
8071 NULL, /* SIOCSIWSTATS */
8072 NULL, /* SIOCGIWSTATS */
8073 NULL, /* SIOCSIWSPY */
8074 NULL, /* SIOCGIWSPY */
8075 NULL, /* SIOCGIWTHRSPY */
8076 NULL, /* SIOCWIWTHRSPY */
8077 ipw2100_wx_set_wap, /* SIOCSIWAP */
8078 ipw2100_wx_get_wap, /* SIOCGIWAP */
8079 NULL, /* -- hole -- */
8080 NULL, /* SIOCGIWAPLIST -- deprecated */
8081 ipw2100_wx_set_scan, /* SIOCSIWSCAN */
8082 ipw2100_wx_get_scan, /* SIOCGIWSCAN */
8083 ipw2100_wx_set_essid, /* SIOCSIWESSID */
8084 ipw2100_wx_get_essid, /* SIOCGIWESSID */
8085 ipw2100_wx_set_nick, /* SIOCSIWNICKN */
8086 ipw2100_wx_get_nick, /* SIOCGIWNICKN */
8087 NULL, /* -- hole -- */
8088 NULL, /* -- hole -- */
8089 ipw2100_wx_set_rate, /* SIOCSIWRATE */
8090 ipw2100_wx_get_rate, /* SIOCGIWRATE */
8091 ipw2100_wx_set_rts, /* SIOCSIWRTS */
8092 ipw2100_wx_get_rts, /* SIOCGIWRTS */
8093 ipw2100_wx_set_frag, /* SIOCSIWFRAG */
8094 ipw2100_wx_get_frag, /* SIOCGIWFRAG */
8095 ipw2100_wx_set_txpow, /* SIOCSIWTXPOW */
8096 ipw2100_wx_get_txpow, /* SIOCGIWTXPOW */
8097 ipw2100_wx_set_retry, /* SIOCSIWRETRY */
8098 ipw2100_wx_get_retry, /* SIOCGIWRETRY */
8099 ipw2100_wx_set_encode, /* SIOCSIWENCODE */
8100 ipw2100_wx_get_encode, /* SIOCGIWENCODE */
8101 ipw2100_wx_set_power, /* SIOCSIWPOWER */
8102 ipw2100_wx_get_power, /* SIOCGIWPOWER */
8105 #define IPW2100_PRIV_SET_MONITOR SIOCIWFIRSTPRIV
8106 #define IPW2100_PRIV_RESET SIOCIWFIRSTPRIV+1
8107 #define IPW2100_PRIV_SET_POWER SIOCIWFIRSTPRIV+2
8108 #define IPW2100_PRIV_GET_POWER SIOCIWFIRSTPRIV+3
8109 #define IPW2100_PRIV_SET_LONGPREAMBLE SIOCIWFIRSTPRIV+4
8110 #define IPW2100_PRIV_GET_LONGPREAMBLE SIOCIWFIRSTPRIV+5
8112 static const struct iw_priv_args ipw2100_private_args[] = {
8114 #ifdef CONFIG_IPW2100_MONITOR
8116 IPW2100_PRIV_SET_MONITOR,
8117 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"
8121 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"
8123 #endif /* CONFIG_IPW2100_MONITOR */
8126 IPW2100_PRIV_SET_POWER,
8127 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_power"
8130 IPW2100_PRIV_GET_POWER,
8131 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_POWER_STRING, "get_power"
8134 IPW2100_PRIV_SET_LONGPREAMBLE,
8135 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_preamble"
8138 IPW2100_PRIV_GET_LONGPREAMBLE,
8139 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, "get_preamble"
8143 static iw_handler ipw2100_private_handler[] = {
8144 #ifdef CONFIG_IPW2100_MONITOR
8145 ipw2100_wx_set_promisc,
8147 #else /* CONFIG_IPW2100_MONITOR */
8150 #endif /* CONFIG_IPW2100_MONITOR */
8151 ipw2100_wx_set_powermode,
8152 ipw2100_wx_get_powermode,
8153 ipw2100_wx_set_preamble,
8154 ipw2100_wx_get_preamble,
8157 static struct iw_handler_def ipw2100_wx_handler_def =
8159 .standard = ipw2100_wx_handlers,
8160 .num_standard = sizeof(ipw2100_wx_handlers) / sizeof(iw_handler),
8161 .num_private = sizeof(ipw2100_private_handler) / sizeof(iw_handler),
8162 .num_private_args = sizeof(ipw2100_private_args) /
8163 sizeof(struct iw_priv_args),
8164 .private = (iw_handler *)ipw2100_private_handler,
8165 .private_args = (struct iw_priv_args *)ipw2100_private_args,
8169 * Get wireless statistics.
8170 * Called by /proc/net/wireless
8171 * Also called by SIOCGIWSTATS
8173 static struct iw_statistics *ipw2100_wx_wireless_stats(struct net_device * dev)
8187 struct ipw2100_priv *priv = ieee80211_priv(dev);
8188 struct iw_statistics *wstats;
8189 u32 rssi, quality, tx_retries, missed_beacons, tx_failures;
8190 u32 ord_len = sizeof(u32);
8193 return (struct iw_statistics *) NULL;
8195 wstats = &priv->wstats;
8197 /* if hw is disabled, then ipw2100_get_ordinal() can't be called.
8198 * ipw2100_wx_wireless_stats seems to be called before fw is
8199 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
8200 * and associated; if not associcated, the values are all meaningless
8201 * anyway, so set them all to NULL and INVALID */
8202 if (!(priv->status & STATUS_ASSOCIATED)) {
8203 wstats->miss.beacon = 0;
8204 wstats->discard.retries = 0;
8205 wstats->qual.qual = 0;
8206 wstats->qual.level = 0;
8207 wstats->qual.noise = 0;
8208 wstats->qual.updated = 7;
8209 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
8210 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
8214 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_PERCENT_MISSED_BCNS,
8215 &missed_beacons, &ord_len))
8216 goto fail_get_ordinal;
8218 /* If we don't have a connection the quality and level is 0*/
8219 if (!(priv->status & STATUS_ASSOCIATED)) {
8220 wstats->qual.qual = 0;
8221 wstats->qual.level = 0;
8223 if (ipw2100_get_ordinal(priv, IPW_ORD_RSSI_AVG_CURR,
8225 goto fail_get_ordinal;
8226 wstats->qual.level = rssi + IPW2100_RSSI_TO_DBM;
8228 rssi_qual = rssi * POOR / 10;
8230 rssi_qual = (rssi - 10) * (FAIR - POOR) / 5 + POOR;
8232 rssi_qual = (rssi - 15) * (GOOD - FAIR) / 5 + FAIR;
8234 rssi_qual = (rssi - 20) * (VERY_GOOD - GOOD) /
8237 rssi_qual = (rssi - 30) * (PERFECT - VERY_GOOD) /
8240 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_PERCENT_RETRIES,
8241 &tx_retries, &ord_len))
8242 goto fail_get_ordinal;
8244 if (tx_retries > 75)
8245 tx_qual = (90 - tx_retries) * POOR / 15;
8246 else if (tx_retries > 70)
8247 tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
8248 else if (tx_retries > 65)
8249 tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
8250 else if (tx_retries > 50)
8251 tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
8254 tx_qual = (50 - tx_retries) *
8255 (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
8257 if (missed_beacons > 50)
8258 beacon_qual = (60 - missed_beacons) * POOR / 10;
8259 else if (missed_beacons > 40)
8260 beacon_qual = (50 - missed_beacons) * (FAIR - POOR) /
8262 else if (missed_beacons > 32)
8263 beacon_qual = (40 - missed_beacons) * (GOOD - FAIR) /
8265 else if (missed_beacons > 20)
8266 beacon_qual = (32 - missed_beacons) *
8267 (VERY_GOOD - GOOD) / 20 + GOOD;
8269 beacon_qual = (20 - missed_beacons) *
8270 (PERFECT - VERY_GOOD) / 20 + VERY_GOOD;
8272 quality = min(beacon_qual, min(tx_qual, rssi_qual));
8274 #ifdef CONFIG_IPW_DEBUG
8275 if (beacon_qual == quality)
8276 IPW_DEBUG_WX("Quality clamped by Missed Beacons\n");
8277 else if (tx_qual == quality)
8278 IPW_DEBUG_WX("Quality clamped by Tx Retries\n");
8279 else if (quality != 100)
8280 IPW_DEBUG_WX("Quality clamped by Signal Strength\n");
8282 IPW_DEBUG_WX("Quality not clamped.\n");
8285 wstats->qual.qual = quality;
8286 wstats->qual.level = rssi + IPW2100_RSSI_TO_DBM;
8289 wstats->qual.noise = 0;
8290 wstats->qual.updated = 7;
8291 wstats->qual.updated |= IW_QUAL_NOISE_INVALID;
8293 /* FIXME: this is percent and not a # */
8294 wstats->miss.beacon = missed_beacons;
8296 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURES,
8297 &tx_failures, &ord_len))
8298 goto fail_get_ordinal;
8299 wstats->discard.retries = tx_failures;
8304 IPW_DEBUG_WX("failed querying ordinals.\n");
8306 return (struct iw_statistics *) NULL;
8309 static void ipw2100_wx_event_work(struct ipw2100_priv *priv)
8311 union iwreq_data wrqu;
8314 if (priv->status & STATUS_STOPPING)
8317 down(&priv->action_sem);
8319 IPW_DEBUG_WX("enter\n");
8321 up(&priv->action_sem);
8323 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
8325 /* Fetch BSSID from the hardware */
8326 if (!(priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) ||
8327 priv->status & STATUS_RF_KILL_MASK ||
8328 ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID,
8329 &priv->bssid, &len)) {
8330 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
8332 /* We now have the BSSID, so can finish setting to the full
8333 * associated state */
8334 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
8335 memcpy(&priv->ieee->bssid, priv->bssid, ETH_ALEN);
8336 priv->status &= ~STATUS_ASSOCIATING;
8337 priv->status |= STATUS_ASSOCIATED;
8338 netif_carrier_on(priv->net_dev);
8339 if (netif_queue_stopped(priv->net_dev)) {
8340 IPW_DEBUG_INFO("Waking net queue.\n");
8341 netif_wake_queue(priv->net_dev);
8343 IPW_DEBUG_INFO("Starting net queue.\n");
8344 netif_start_queue(priv->net_dev);
8348 if (!(priv->status & STATUS_ASSOCIATED)) {
8349 IPW_DEBUG_WX("Configuring ESSID\n");
8350 down(&priv->action_sem);
8351 /* This is a disassociation event, so kick the firmware to
8352 * look for another AP */
8353 if (priv->config & CFG_STATIC_ESSID)
8354 ipw2100_set_essid(priv, priv->essid, priv->essid_len, 0);
8356 ipw2100_set_essid(priv, NULL, 0, 0);
8357 up(&priv->action_sem);
8360 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
8363 #define IPW2100_FW_MAJOR_VERSION 1
8364 #define IPW2100_FW_MINOR_VERSION 3
8366 #define IPW2100_FW_MINOR(x) ((x & 0xff) >> 8)
8367 #define IPW2100_FW_MAJOR(x) (x & 0xff)
8369 #define IPW2100_FW_VERSION ((IPW2100_FW_MINOR_VERSION << 8) | \
8370 IPW2100_FW_MAJOR_VERSION)
8372 #define IPW2100_FW_PREFIX "ipw2100-" __stringify(IPW2100_FW_MAJOR_VERSION) \
8373 "." __stringify(IPW2100_FW_MINOR_VERSION)
8375 #define IPW2100_FW_NAME(x) IPW2100_FW_PREFIX "" x ".fw"
8380 BINARY FIRMWARE HEADER FORMAT
8384 2 2 mode == 0:BSS,1:IBSS,2:MONITOR
8387 C fw_len firmware data
8388 12 + fw_len uc_len microcode data
8392 struct ipw2100_fw_header {
8395 unsigned int fw_size;
8396 unsigned int uc_size;
8397 } __attribute__ ((packed));
8401 static int ipw2100_mod_firmware_load(struct ipw2100_fw *fw)
8403 struct ipw2100_fw_header *h =
8404 (struct ipw2100_fw_header *)fw->fw_entry->data;
8406 if (IPW2100_FW_MAJOR(h->version) != IPW2100_FW_MAJOR_VERSION) {
8407 printk(KERN_WARNING DRV_NAME ": Firmware image not compatible "
8408 "(detected version id of %u). "
8409 "See Documentation/networking/README.ipw2100\n",
8414 fw->version = h->version;
8415 fw->fw.data = fw->fw_entry->data + sizeof(struct ipw2100_fw_header);
8416 fw->fw.size = h->fw_size;
8417 fw->uc.data = fw->fw.data + h->fw_size;
8418 fw->uc.size = h->uc_size;
8424 static int ipw2100_get_firmware(struct ipw2100_priv *priv,
8425 struct ipw2100_fw *fw)
8430 IPW_DEBUG_INFO("%s: Using hotplug firmware load.\n",
8431 priv->net_dev->name);
8433 switch (priv->ieee->iw_mode) {
8435 fw_name = IPW2100_FW_NAME("-i");
8437 #ifdef CONFIG_IPW2100_MONITOR
8438 case IW_MODE_MONITOR:
8439 fw_name = IPW2100_FW_NAME("-p");
8444 fw_name = IPW2100_FW_NAME("");
8448 rc = request_firmware(&fw->fw_entry, fw_name, &priv->pci_dev->dev);
8451 printk(KERN_ERR DRV_NAME ": "
8452 "%s: Firmware '%s' not available or load failed.\n",
8453 priv->net_dev->name, fw_name);
8456 IPW_DEBUG_INFO("firmware data %p size %zd\n", fw->fw_entry->data,
8457 fw->fw_entry->size);
8459 ipw2100_mod_firmware_load(fw);
8464 static void ipw2100_release_firmware(struct ipw2100_priv *priv,
8465 struct ipw2100_fw *fw)
8469 release_firmware(fw->fw_entry);
8470 fw->fw_entry = NULL;
8474 static int ipw2100_get_fwversion(struct ipw2100_priv *priv, char *buf,
8477 char ver[MAX_FW_VERSION_LEN];
8478 u32 len = MAX_FW_VERSION_LEN;
8481 /* firmware version is an ascii string (max len of 14) */
8482 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_FW_VER_NUM,
8488 for (i = 0; i < len; i++)
8494 static int ipw2100_get_ucodeversion(struct ipw2100_priv *priv, char *buf,
8498 u32 len = sizeof(ver);
8499 /* microcode version is a 32 bit integer */
8500 if (ipw2100_get_ordinal(priv, IPW_ORD_UCODE_VERSION,
8503 return snprintf(buf, max, "%08X", ver);
8507 * On exit, the firmware will have been freed from the fw list
8509 static int ipw2100_fw_download(struct ipw2100_priv *priv,
8510 struct ipw2100_fw *fw)
8512 /* firmware is constructed of N contiguous entries, each entry is
8516 * 0 4 address to write to
8517 * 4 2 length of data run
8523 const unsigned char *firmware_data = fw->fw.data;
8524 unsigned int firmware_data_left = fw->fw.size;
8526 while (firmware_data_left > 0) {
8527 addr = *(u32 *)(firmware_data);
8529 firmware_data_left -= 4;
8531 len = *(u16 *)(firmware_data);
8533 firmware_data_left -= 2;
8536 printk(KERN_ERR DRV_NAME ": "
8537 "Invalid firmware run-length of %d bytes\n",
8542 write_nic_memory(priv->net_dev, addr, len, firmware_data);
8543 firmware_data += len;
8544 firmware_data_left -= len;
8550 struct symbol_alive_response {
8559 u16 clock_settle_time; // 1us LSB
8560 u16 powerup_settle_time; // 1us LSB
8561 u16 hop_settle_time; // 1us LSB
8562 u8 date[3]; // month, day, year
8563 u8 time[2]; // hours, minutes
8567 static int ipw2100_ucode_download(struct ipw2100_priv *priv,
8568 struct ipw2100_fw *fw)
8570 struct net_device *dev = priv->net_dev;
8571 const unsigned char *microcode_data = fw->uc.data;
8572 unsigned int microcode_data_left = fw->uc.size;
8573 void __iomem *reg = (void __iomem *)dev->base_addr;
8575 struct symbol_alive_response response;
8579 /* Symbol control */
8580 write_nic_word(dev, IPW2100_CONTROL_REG, 0x703);
8582 write_nic_word(dev, IPW2100_CONTROL_REG, 0x707);
8586 write_nic_byte(dev, 0x210014, 0x72); /* fifo width =16 */
8588 write_nic_byte(dev, 0x210014, 0x72); /* fifo width =16 */
8591 /* EN_CS_ACCESS bit to reset control store pointer */
8592 write_nic_byte(dev, 0x210000, 0x40);
8594 write_nic_byte(dev, 0x210000, 0x0);
8596 write_nic_byte(dev, 0x210000, 0x40);
8599 /* copy microcode from buffer into Symbol */
8601 while (microcode_data_left > 0) {
8602 write_nic_byte(dev, 0x210010, *microcode_data++);
8603 write_nic_byte(dev, 0x210010, *microcode_data++);
8604 microcode_data_left -= 2;
8607 /* EN_CS_ACCESS bit to reset the control store pointer */
8608 write_nic_byte(dev, 0x210000, 0x0);
8611 /* Enable System (Reg 0)
8612 * first enable causes garbage in RX FIFO */
8613 write_nic_byte(dev, 0x210000, 0x0);
8615 write_nic_byte(dev, 0x210000, 0x80);
8618 /* Reset External Baseband Reg */
8619 write_nic_word(dev, IPW2100_CONTROL_REG, 0x703);
8621 write_nic_word(dev, IPW2100_CONTROL_REG, 0x707);
8624 /* HW Config (Reg 5) */
8625 write_nic_byte(dev, 0x210014, 0x72); // fifo width =16
8627 write_nic_byte(dev, 0x210014, 0x72); // fifo width =16
8630 /* Enable System (Reg 0)
8631 * second enable should be OK */
8632 write_nic_byte(dev, 0x210000, 0x00); // clear enable system
8634 write_nic_byte(dev, 0x210000, 0x80); // set enable system
8636 /* check Symbol is enabled - upped this from 5 as it wasn't always
8637 * catching the update */
8638 for (i = 0; i < 10; i++) {
8641 /* check Dino is enabled bit */
8642 read_nic_byte(dev, 0x210000, &data);
8648 printk(KERN_ERR DRV_NAME ": %s: Error initializing Symbol\n",
8653 /* Get Symbol alive response */
8654 for (i = 0; i < 30; i++) {
8655 /* Read alive response structure */
8657 j < (sizeof(struct symbol_alive_response) >> 1);
8659 read_nic_word(dev, 0x210004,
8660 ((u16 *)&response) + j);
8662 if ((response.cmd_id == 1) &&
8663 (response.ucode_valid == 0x1))
8669 printk(KERN_ERR DRV_NAME ": %s: No response from Symbol - hw not alive\n",
8671 printk_buf(IPW_DL_ERROR, (u8*)&response, sizeof(response));