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)
3274 struct ipw2100_priv *priv = ieee80211_priv(dev);
3275 struct list_head *element;
3276 struct ipw2100_tx_packet *packet;
3277 unsigned long flags;
3279 spin_lock_irqsave(&priv->low_lock, flags);
3281 if (!(priv->status & STATUS_ASSOCIATED)) {
3282 IPW_DEBUG_INFO("Can not transmit when not connected.\n");
3283 priv->ieee->stats.tx_carrier_errors++;
3284 netif_stop_queue(dev);
3288 if (list_empty(&priv->tx_free_list))
3291 element = priv->tx_free_list.next;
3292 packet = list_entry(element, struct ipw2100_tx_packet, list);
3294 packet->info.d_struct.txb = txb;
3296 IPW_DEBUG_TX("Sending fragment (%d bytes):\n",
3297 txb->fragments[0]->len);
3298 printk_buf(IPW_DL_TX, txb->fragments[0]->data,
3299 txb->fragments[0]->len);
3301 packet->jiffy_start = jiffies;
3304 DEC_STAT(&priv->tx_free_stat);
3306 list_add_tail(element, &priv->tx_pend_list);
3307 INC_STAT(&priv->tx_pend_stat);
3309 ipw2100_tx_send_data(priv);
3311 spin_unlock_irqrestore(&priv->low_lock, flags);
3315 netif_stop_queue(dev);
3316 spin_unlock_irqrestore(&priv->low_lock, flags);
3321 static int ipw2100_msg_allocate(struct ipw2100_priv *priv)
3323 int i, j, err = -EINVAL;
3327 priv->msg_buffers = (struct ipw2100_tx_packet *)kmalloc(
3328 IPW_COMMAND_POOL_SIZE * sizeof(struct ipw2100_tx_packet),
3330 if (!priv->msg_buffers) {
3331 printk(KERN_ERR DRV_NAME ": %s: PCI alloc failed for msg "
3332 "buffers.\n", priv->net_dev->name);
3336 for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++) {
3337 v = pci_alloc_consistent(
3339 sizeof(struct ipw2100_cmd_header),
3342 printk(KERN_ERR DRV_NAME ": "
3343 "%s: PCI alloc failed for msg "
3345 priv->net_dev->name);
3350 memset(v, 0, sizeof(struct ipw2100_cmd_header));
3352 priv->msg_buffers[i].type = COMMAND;
3353 priv->msg_buffers[i].info.c_struct.cmd =
3354 (struct ipw2100_cmd_header*)v;
3355 priv->msg_buffers[i].info.c_struct.cmd_phys = p;
3358 if (i == IPW_COMMAND_POOL_SIZE)
3361 for (j = 0; j < i; j++) {
3362 pci_free_consistent(
3364 sizeof(struct ipw2100_cmd_header),
3365 priv->msg_buffers[j].info.c_struct.cmd,
3366 priv->msg_buffers[j].info.c_struct.cmd_phys);
3369 kfree(priv->msg_buffers);
3370 priv->msg_buffers = NULL;
3375 static int ipw2100_msg_initialize(struct ipw2100_priv *priv)
3379 INIT_LIST_HEAD(&priv->msg_free_list);
3380 INIT_LIST_HEAD(&priv->msg_pend_list);
3382 for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++)
3383 list_add_tail(&priv->msg_buffers[i].list, &priv->msg_free_list);
3384 SET_STAT(&priv->msg_free_stat, i);
3389 static void ipw2100_msg_free(struct ipw2100_priv *priv)
3393 if (!priv->msg_buffers)
3396 for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++) {
3397 pci_free_consistent(priv->pci_dev,
3398 sizeof(struct ipw2100_cmd_header),
3399 priv->msg_buffers[i].info.c_struct.cmd,
3400 priv->msg_buffers[i].info.c_struct.cmd_phys);
3403 kfree(priv->msg_buffers);
3404 priv->msg_buffers = NULL;
3407 static ssize_t show_pci(struct device *d, struct device_attribute *attr,
3410 struct pci_dev *pci_dev = container_of(d, struct pci_dev, dev);
3415 for (i = 0; i < 16; i++) {
3416 out += sprintf(out, "[%08X] ", i * 16);
3417 for (j = 0; j < 16; j += 4) {
3418 pci_read_config_dword(pci_dev, i * 16 + j, &val);
3419 out += sprintf(out, "%08X ", val);
3421 out += sprintf(out, "\n");
3426 static DEVICE_ATTR(pci, S_IRUGO, show_pci, NULL);
3428 static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
3431 struct ipw2100_priv *p = d->driver_data;
3432 return sprintf(buf, "0x%08x\n", (int)p->config);
3434 static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
3436 static ssize_t show_status(struct device *d, struct device_attribute *attr,
3439 struct ipw2100_priv *p = d->driver_data;
3440 return sprintf(buf, "0x%08x\n", (int)p->status);
3442 static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
3444 static ssize_t show_capability(struct device *d, struct device_attribute *attr,
3447 struct ipw2100_priv *p = d->driver_data;
3448 return sprintf(buf, "0x%08x\n", (int)p->capability);
3450 static DEVICE_ATTR(capability, S_IRUGO, show_capability, NULL);
3453 #define IPW2100_REG(x) { IPW_ ##x, #x }
3454 static const struct {
3458 IPW2100_REG(REG_GP_CNTRL),
3459 IPW2100_REG(REG_GPIO),
3460 IPW2100_REG(REG_INTA),
3461 IPW2100_REG(REG_INTA_MASK),
3462 IPW2100_REG(REG_RESET_REG),
3464 #define IPW2100_NIC(x, s) { x, #x, s }
3465 static const struct {
3470 IPW2100_NIC(IPW2100_CONTROL_REG, 2),
3471 IPW2100_NIC(0x210014, 1),
3472 IPW2100_NIC(0x210000, 1),
3474 #define IPW2100_ORD(x, d) { IPW_ORD_ ##x, #x, d }
3475 static const struct {
3480 IPW2100_ORD(STAT_TX_HOST_REQUESTS, "requested Host Tx's (MSDU)"),
3481 IPW2100_ORD(STAT_TX_HOST_COMPLETE, "successful Host Tx's (MSDU)"),
3482 IPW2100_ORD(STAT_TX_DIR_DATA, "successful Directed Tx's (MSDU)"),
3483 IPW2100_ORD(STAT_TX_DIR_DATA1, "successful Directed Tx's (MSDU) @ 1MB"),
3484 IPW2100_ORD(STAT_TX_DIR_DATA2, "successful Directed Tx's (MSDU) @ 2MB"),
3485 IPW2100_ORD(STAT_TX_DIR_DATA5_5, "successful Directed Tx's (MSDU) @ 5_5MB"),
3486 IPW2100_ORD(STAT_TX_DIR_DATA11, "successful Directed Tx's (MSDU) @ 11MB"),
3487 IPW2100_ORD(STAT_TX_NODIR_DATA1, "successful Non_Directed Tx's (MSDU) @ 1MB"),
3488 IPW2100_ORD(STAT_TX_NODIR_DATA2, "successful Non_Directed Tx's (MSDU) @ 2MB"),
3489 IPW2100_ORD(STAT_TX_NODIR_DATA5_5, "successful Non_Directed Tx's (MSDU) @ 5.5MB"),
3490 IPW2100_ORD(STAT_TX_NODIR_DATA11, "successful Non_Directed Tx's (MSDU) @ 11MB"),
3491 IPW2100_ORD(STAT_NULL_DATA, "successful NULL data Tx's"),
3492 IPW2100_ORD(STAT_TX_RTS, "successful Tx RTS"),
3493 IPW2100_ORD(STAT_TX_CTS, "successful Tx CTS"),
3494 IPW2100_ORD(STAT_TX_ACK, "successful Tx ACK"),
3495 IPW2100_ORD(STAT_TX_ASSN, "successful Association Tx's"),
3496 IPW2100_ORD(STAT_TX_ASSN_RESP, "successful Association response Tx's"),
3497 IPW2100_ORD(STAT_TX_REASSN, "successful Reassociation Tx's"),
3498 IPW2100_ORD(STAT_TX_REASSN_RESP, "successful Reassociation response Tx's"),
3499 IPW2100_ORD(STAT_TX_PROBE, "probes successfully transmitted"),
3500 IPW2100_ORD(STAT_TX_PROBE_RESP, "probe responses successfully transmitted"),
3501 IPW2100_ORD(STAT_TX_BEACON, "tx beacon"),
3502 IPW2100_ORD(STAT_TX_ATIM, "Tx ATIM"),
3503 IPW2100_ORD(STAT_TX_DISASSN, "successful Disassociation TX"),
3504 IPW2100_ORD(STAT_TX_AUTH, "successful Authentication Tx"),
3505 IPW2100_ORD(STAT_TX_DEAUTH, "successful Deauthentication TX"),
3506 IPW2100_ORD(STAT_TX_TOTAL_BYTES, "Total successful Tx data bytes"),
3507 IPW2100_ORD(STAT_TX_RETRIES, "Tx retries"),
3508 IPW2100_ORD(STAT_TX_RETRY1, "Tx retries at 1MBPS"),
3509 IPW2100_ORD(STAT_TX_RETRY2, "Tx retries at 2MBPS"),
3510 IPW2100_ORD(STAT_TX_RETRY5_5, "Tx retries at 5.5MBPS"),
3511 IPW2100_ORD(STAT_TX_RETRY11, "Tx retries at 11MBPS"),
3512 IPW2100_ORD(STAT_TX_FAILURES, "Tx Failures"),
3513 IPW2100_ORD(STAT_TX_MAX_TRIES_IN_HOP,"times max tries in a hop failed"),
3514 IPW2100_ORD(STAT_TX_DISASSN_FAIL, "times disassociation failed"),
3515 IPW2100_ORD(STAT_TX_ERR_CTS, "missed/bad CTS frames"),
3516 IPW2100_ORD(STAT_TX_ERR_ACK, "tx err due to acks"),
3517 IPW2100_ORD(STAT_RX_HOST, "packets passed to host"),
3518 IPW2100_ORD(STAT_RX_DIR_DATA, "directed packets"),
3519 IPW2100_ORD(STAT_RX_DIR_DATA1, "directed packets at 1MB"),
3520 IPW2100_ORD(STAT_RX_DIR_DATA2, "directed packets at 2MB"),
3521 IPW2100_ORD(STAT_RX_DIR_DATA5_5, "directed packets at 5.5MB"),
3522 IPW2100_ORD(STAT_RX_DIR_DATA11, "directed packets at 11MB"),
3523 IPW2100_ORD(STAT_RX_NODIR_DATA,"nondirected packets"),
3524 IPW2100_ORD(STAT_RX_NODIR_DATA1, "nondirected packets at 1MB"),
3525 IPW2100_ORD(STAT_RX_NODIR_DATA2, "nondirected packets at 2MB"),
3526 IPW2100_ORD(STAT_RX_NODIR_DATA5_5, "nondirected packets at 5.5MB"),
3527 IPW2100_ORD(STAT_RX_NODIR_DATA11, "nondirected packets at 11MB"),
3528 IPW2100_ORD(STAT_RX_NULL_DATA, "null data rx's"),
3529 IPW2100_ORD(STAT_RX_RTS, "Rx RTS"),
3530 IPW2100_ORD(STAT_RX_CTS, "Rx CTS"),
3531 IPW2100_ORD(STAT_RX_ACK, "Rx ACK"),
3532 IPW2100_ORD(STAT_RX_CFEND, "Rx CF End"),
3533 IPW2100_ORD(STAT_RX_CFEND_ACK, "Rx CF End + CF Ack"),
3534 IPW2100_ORD(STAT_RX_ASSN, "Association Rx's"),
3535 IPW2100_ORD(STAT_RX_ASSN_RESP, "Association response Rx's"),
3536 IPW2100_ORD(STAT_RX_REASSN, "Reassociation Rx's"),
3537 IPW2100_ORD(STAT_RX_REASSN_RESP, "Reassociation response Rx's"),
3538 IPW2100_ORD(STAT_RX_PROBE, "probe Rx's"),
3539 IPW2100_ORD(STAT_RX_PROBE_RESP, "probe response Rx's"),
3540 IPW2100_ORD(STAT_RX_BEACON, "Rx beacon"),
3541 IPW2100_ORD(STAT_RX_ATIM, "Rx ATIM"),
3542 IPW2100_ORD(STAT_RX_DISASSN, "disassociation Rx"),
3543 IPW2100_ORD(STAT_RX_AUTH, "authentication Rx"),
3544 IPW2100_ORD(STAT_RX_DEAUTH, "deauthentication Rx"),
3545 IPW2100_ORD(STAT_RX_TOTAL_BYTES,"Total rx data bytes received"),
3546 IPW2100_ORD(STAT_RX_ERR_CRC, "packets with Rx CRC error"),
3547 IPW2100_ORD(STAT_RX_ERR_CRC1, "Rx CRC errors at 1MB"),
3548 IPW2100_ORD(STAT_RX_ERR_CRC2, "Rx CRC errors at 2MB"),
3549 IPW2100_ORD(STAT_RX_ERR_CRC5_5, "Rx CRC errors at 5.5MB"),
3550 IPW2100_ORD(STAT_RX_ERR_CRC11, "Rx CRC errors at 11MB"),
3551 IPW2100_ORD(STAT_RX_DUPLICATE1, "duplicate rx packets at 1MB"),
3552 IPW2100_ORD(STAT_RX_DUPLICATE2, "duplicate rx packets at 2MB"),
3553 IPW2100_ORD(STAT_RX_DUPLICATE5_5, "duplicate rx packets at 5.5MB"),
3554 IPW2100_ORD(STAT_RX_DUPLICATE11, "duplicate rx packets at 11MB"),
3555 IPW2100_ORD(STAT_RX_DUPLICATE, "duplicate rx packets"),
3556 IPW2100_ORD(PERS_DB_LOCK, "locking fw permanent db"),
3557 IPW2100_ORD(PERS_DB_SIZE, "size of fw permanent db"),
3558 IPW2100_ORD(PERS_DB_ADDR, "address of fw permanent db"),
3559 IPW2100_ORD(STAT_RX_INVALID_PROTOCOL, "rx frames with invalid protocol"),
3560 IPW2100_ORD(SYS_BOOT_TIME, "Boot time"),
3561 IPW2100_ORD(STAT_RX_NO_BUFFER, "rx frames rejected due to no buffer"),
3562 IPW2100_ORD(STAT_RX_MISSING_FRAG, "rx frames dropped due to missing fragment"),
3563 IPW2100_ORD(STAT_RX_ORPHAN_FRAG, "rx frames dropped due to non-sequential fragment"),
3564 IPW2100_ORD(STAT_RX_ORPHAN_FRAME, "rx frames dropped due to unmatched 1st frame"),
3565 IPW2100_ORD(STAT_RX_FRAG_AGEOUT, "rx frames dropped due to uncompleted frame"),
3566 IPW2100_ORD(STAT_RX_ICV_ERRORS, "ICV errors during decryption"),
3567 IPW2100_ORD(STAT_PSP_SUSPENSION,"times adapter suspended"),
3568 IPW2100_ORD(STAT_PSP_BCN_TIMEOUT, "beacon timeout"),
3569 IPW2100_ORD(STAT_PSP_POLL_TIMEOUT, "poll response timeouts"),
3570 IPW2100_ORD(STAT_PSP_NONDIR_TIMEOUT, "timeouts waiting for last {broad,multi}cast pkt"),
3571 IPW2100_ORD(STAT_PSP_RX_DTIMS, "PSP DTIMs received"),
3572 IPW2100_ORD(STAT_PSP_RX_TIMS, "PSP TIMs received"),
3573 IPW2100_ORD(STAT_PSP_STATION_ID,"PSP Station ID"),
3574 IPW2100_ORD(LAST_ASSN_TIME, "RTC time of last association"),
3575 IPW2100_ORD(STAT_PERCENT_MISSED_BCNS,"current calculation of % missed beacons"),
3576 IPW2100_ORD(STAT_PERCENT_RETRIES,"current calculation of % missed tx retries"),
3577 IPW2100_ORD(ASSOCIATED_AP_PTR, "0 if not associated, else pointer to AP table entry"),
3578 IPW2100_ORD(AVAILABLE_AP_CNT, "AP's decsribed in the AP table"),
3579 IPW2100_ORD(AP_LIST_PTR, "Ptr to list of available APs"),
3580 IPW2100_ORD(STAT_AP_ASSNS, "associations"),
3581 IPW2100_ORD(STAT_ASSN_FAIL, "association failures"),
3582 IPW2100_ORD(STAT_ASSN_RESP_FAIL,"failures due to response fail"),
3583 IPW2100_ORD(STAT_FULL_SCANS, "full scans"),
3584 IPW2100_ORD(CARD_DISABLED, "Card Disabled"),
3585 IPW2100_ORD(STAT_ROAM_INHIBIT, "times roaming was inhibited due to activity"),
3586 IPW2100_ORD(RSSI_AT_ASSN, "RSSI of associated AP at time of association"),
3587 IPW2100_ORD(STAT_ASSN_CAUSE1, "reassociation: no probe response or TX on hop"),
3588 IPW2100_ORD(STAT_ASSN_CAUSE2, "reassociation: poor tx/rx quality"),
3589 IPW2100_ORD(STAT_ASSN_CAUSE3, "reassociation: tx/rx quality (excessive AP load"),
3590 IPW2100_ORD(STAT_ASSN_CAUSE4, "reassociation: AP RSSI level"),
3591 IPW2100_ORD(STAT_ASSN_CAUSE5, "reassociations due to load leveling"),
3592 IPW2100_ORD(STAT_AUTH_FAIL, "times authentication failed"),
3593 IPW2100_ORD(STAT_AUTH_RESP_FAIL,"times authentication response failed"),
3594 IPW2100_ORD(STATION_TABLE_CNT, "entries in association table"),
3595 IPW2100_ORD(RSSI_AVG_CURR, "Current avg RSSI"),
3596 IPW2100_ORD(POWER_MGMT_MODE, "Power mode - 0=CAM, 1=PSP"),
3597 IPW2100_ORD(COUNTRY_CODE, "IEEE country code as recv'd from beacon"),
3598 IPW2100_ORD(COUNTRY_CHANNELS, "channels suported by country"),
3599 IPW2100_ORD(RESET_CNT, "adapter resets (warm)"),
3600 IPW2100_ORD(BEACON_INTERVAL, "Beacon interval"),
3601 IPW2100_ORD(ANTENNA_DIVERSITY, "TRUE if antenna diversity is disabled"),
3602 IPW2100_ORD(DTIM_PERIOD, "beacon intervals between DTIMs"),
3603 IPW2100_ORD(OUR_FREQ, "current radio freq lower digits - channel ID"),
3604 IPW2100_ORD(RTC_TIME, "current RTC time"),
3605 IPW2100_ORD(PORT_TYPE, "operating mode"),
3606 IPW2100_ORD(CURRENT_TX_RATE, "current tx rate"),
3607 IPW2100_ORD(SUPPORTED_RATES, "supported tx rates"),
3608 IPW2100_ORD(ATIM_WINDOW, "current ATIM Window"),
3609 IPW2100_ORD(BASIC_RATES, "basic tx rates"),
3610 IPW2100_ORD(NIC_HIGHEST_RATE, "NIC highest tx rate"),
3611 IPW2100_ORD(AP_HIGHEST_RATE, "AP highest tx rate"),
3612 IPW2100_ORD(CAPABILITIES, "Management frame capability field"),
3613 IPW2100_ORD(AUTH_TYPE, "Type of authentication"),
3614 IPW2100_ORD(RADIO_TYPE, "Adapter card platform type"),
3615 IPW2100_ORD(RTS_THRESHOLD, "Min packet length for RTS handshaking"),
3616 IPW2100_ORD(INT_MODE, "International mode"),
3617 IPW2100_ORD(FRAGMENTATION_THRESHOLD, "protocol frag threshold"),
3618 IPW2100_ORD(EEPROM_SRAM_DB_BLOCK_START_ADDRESS, "EEPROM offset in SRAM"),
3619 IPW2100_ORD(EEPROM_SRAM_DB_BLOCK_SIZE, "EEPROM size in SRAM"),
3620 IPW2100_ORD(EEPROM_SKU_CAPABILITY, "EEPROM SKU Capability"),
3621 IPW2100_ORD(EEPROM_IBSS_11B_CHANNELS, "EEPROM IBSS 11b channel set"),
3622 IPW2100_ORD(MAC_VERSION, "MAC Version"),
3623 IPW2100_ORD(MAC_REVISION, "MAC Revision"),
3624 IPW2100_ORD(RADIO_VERSION, "Radio Version"),
3625 IPW2100_ORD(NIC_MANF_DATE_TIME, "MANF Date/Time STAMP"),
3626 IPW2100_ORD(UCODE_VERSION, "Ucode Version"),
3630 static ssize_t show_registers(struct device *d, struct device_attribute *attr,
3634 struct ipw2100_priv *priv = dev_get_drvdata(d);
3635 struct net_device *dev = priv->net_dev;
3639 out += sprintf(out, "%30s [Address ] : Hex\n", "Register");
3641 for (i = 0; i < (sizeof(hw_data) / sizeof(*hw_data)); i++) {
3642 read_register(dev, hw_data[i].addr, &val);
3643 out += sprintf(out, "%30s [%08X] : %08X\n",
3644 hw_data[i].name, hw_data[i].addr, val);
3649 static DEVICE_ATTR(registers, S_IRUGO, show_registers, NULL);
3652 static ssize_t show_hardware(struct device *d, struct device_attribute *attr,
3655 struct ipw2100_priv *priv = dev_get_drvdata(d);
3656 struct net_device *dev = priv->net_dev;
3660 out += sprintf(out, "%30s [Address ] : Hex\n", "NIC entry");
3662 for (i = 0; i < (sizeof(nic_data) / sizeof(*nic_data)); i++) {
3667 switch (nic_data[i].size) {
3669 read_nic_byte(dev, nic_data[i].addr, &tmp8);
3670 out += sprintf(out, "%30s [%08X] : %02X\n",
3671 nic_data[i].name, nic_data[i].addr,
3675 read_nic_word(dev, nic_data[i].addr, &tmp16);
3676 out += sprintf(out, "%30s [%08X] : %04X\n",
3677 nic_data[i].name, nic_data[i].addr,
3681 read_nic_dword(dev, nic_data[i].addr, &tmp32);
3682 out += sprintf(out, "%30s [%08X] : %08X\n",
3683 nic_data[i].name, nic_data[i].addr,
3690 static DEVICE_ATTR(hardware, S_IRUGO, show_hardware, NULL);
3693 static ssize_t show_memory(struct device *d, struct device_attribute *attr,
3696 struct ipw2100_priv *priv = dev_get_drvdata(d);
3697 struct net_device *dev = priv->net_dev;
3698 static unsigned long loop = 0;
3704 if (loop >= 0x30000)
3707 /* sysfs provides us PAGE_SIZE buffer */
3708 while (len < PAGE_SIZE - 128 && loop < 0x30000) {
3710 if (priv->snapshot[0]) for (i = 0; i < 4; i++)
3711 buffer[i] = *(u32 *)SNAPSHOT_ADDR(loop + i * 4);
3712 else for (i = 0; i < 4; i++)
3713 read_nic_dword(dev, loop + i * 4, &buffer[i]);
3716 len += sprintf(buf + len,
3736 ((u8*)buffer)[0xf]);
3738 len += sprintf(buf + len, "%s\n",
3739 snprint_line(line, sizeof(line),
3740 (u8*)buffer, 16, loop));
3747 static ssize_t store_memory(struct device *d, struct device_attribute *attr,
3748 const char *buf, size_t count)
3750 struct ipw2100_priv *priv = dev_get_drvdata(d);
3751 struct net_device *dev = priv->net_dev;
3752 const char *p = buf;
3758 (count >= 2 && tolower(p[0]) == 'o' && tolower(p[1]) == 'n')) {
3759 IPW_DEBUG_INFO("%s: Setting memory dump to RAW mode.\n",
3763 } else if (p[0] == '0' || (count >= 2 && tolower(p[0]) == 'o' &&
3764 tolower(p[1]) == 'f')) {
3765 IPW_DEBUG_INFO("%s: Setting memory dump to HEX mode.\n",
3769 } else if (tolower(p[0]) == 'r') {
3770 IPW_DEBUG_INFO("%s: Resetting firmware snapshot.\n",
3772 ipw2100_snapshot_free(priv);
3775 IPW_DEBUG_INFO("%s: Usage: 0|on = HEX, 1|off = RAW, "
3776 "reset = clear memory snapshot\n",
3781 static DEVICE_ATTR(memory, S_IWUSR|S_IRUGO, show_memory, store_memory);
3784 static ssize_t show_ordinals(struct device *d, struct device_attribute *attr,
3787 struct ipw2100_priv *priv = dev_get_drvdata(d);
3791 static int loop = 0;
3793 if (loop >= sizeof(ord_data) / sizeof(*ord_data))
3796 /* sysfs provides us PAGE_SIZE buffer */
3797 while (len < PAGE_SIZE - 128 &&
3798 loop < (sizeof(ord_data) / sizeof(*ord_data))) {
3800 val_len = sizeof(u32);
3802 if (ipw2100_get_ordinal(priv, ord_data[loop].index, &val,
3804 len += sprintf(buf + len, "[0x%02X] = ERROR %s\n",
3805 ord_data[loop].index,
3806 ord_data[loop].desc);
3808 len += sprintf(buf + len, "[0x%02X] = 0x%08X %s\n",
3809 ord_data[loop].index, val,
3810 ord_data[loop].desc);
3816 static DEVICE_ATTR(ordinals, S_IRUGO, show_ordinals, NULL);
3819 static ssize_t show_stats(struct device *d, struct device_attribute *attr,
3822 struct ipw2100_priv *priv = dev_get_drvdata(d);
3825 out += sprintf(out, "interrupts: %d {tx: %d, rx: %d, other: %d}\n",
3826 priv->interrupts, priv->tx_interrupts,
3827 priv->rx_interrupts, priv->inta_other);
3828 out += sprintf(out, "firmware resets: %d\n", priv->resets);
3829 out += sprintf(out, "firmware hangs: %d\n", priv->hangs);
3830 #ifdef CONFIG_IPW_DEBUG
3831 out += sprintf(out, "packet mismatch image: %s\n",
3832 priv->snapshot[0] ? "YES" : "NO");
3837 static DEVICE_ATTR(stats, S_IRUGO, show_stats, NULL);
3840 static int ipw2100_switch_mode(struct ipw2100_priv *priv, u32 mode)
3844 if (mode == priv->ieee->iw_mode)
3847 err = ipw2100_disable_adapter(priv);
3849 printk(KERN_ERR DRV_NAME ": %s: Could not disable adapter %d\n",
3850 priv->net_dev->name, err);
3856 priv->net_dev->type = ARPHRD_ETHER;
3859 priv->net_dev->type = ARPHRD_ETHER;
3861 #ifdef CONFIG_IPW2100_MONITOR
3862 case IW_MODE_MONITOR:
3863 priv->last_mode = priv->ieee->iw_mode;
3864 priv->net_dev->type = ARPHRD_IEEE80211;
3866 #endif /* CONFIG_IPW2100_MONITOR */
3869 priv->ieee->iw_mode = mode;
3872 /* Indicate ipw2100_download_firmware download firmware
3873 * from disk instead of memory. */
3874 ipw2100_firmware.version = 0;
3877 printk(KERN_INFO "%s: Reseting on mode change.\n",
3878 priv->net_dev->name);
3879 priv->reset_backoff = 0;
3880 schedule_reset(priv);
3885 static ssize_t show_internals(struct device *d, struct device_attribute *attr,
3888 struct ipw2100_priv *priv = dev_get_drvdata(d);
3891 #define DUMP_VAR(x,y) len += sprintf(buf + len, # x ": %" # y "\n", priv-> x)
3893 if (priv->status & STATUS_ASSOCIATED)
3894 len += sprintf(buf + len, "connected: %lu\n",
3895 get_seconds() - priv->connect_start);
3897 len += sprintf(buf + len, "not connected\n");
3899 DUMP_VAR(ieee->crypt[priv->ieee->tx_keyidx], p);
3900 DUMP_VAR(status, 08lx);
3901 DUMP_VAR(config, 08lx);
3902 DUMP_VAR(capability, 08lx);
3904 len += sprintf(buf + len, "last_rtc: %lu\n", (unsigned long)priv->last_rtc);
3906 DUMP_VAR(fatal_error, d);
3907 DUMP_VAR(stop_hang_check, d);
3908 DUMP_VAR(stop_rf_kill, d);
3909 DUMP_VAR(messages_sent, d);
3911 DUMP_VAR(tx_pend_stat.value, d);
3912 DUMP_VAR(tx_pend_stat.hi, d);
3914 DUMP_VAR(tx_free_stat.value, d);
3915 DUMP_VAR(tx_free_stat.lo, d);
3917 DUMP_VAR(msg_free_stat.value, d);
3918 DUMP_VAR(msg_free_stat.lo, d);
3920 DUMP_VAR(msg_pend_stat.value, d);
3921 DUMP_VAR(msg_pend_stat.hi, d);
3923 DUMP_VAR(fw_pend_stat.value, d);
3924 DUMP_VAR(fw_pend_stat.hi, d);
3926 DUMP_VAR(txq_stat.value, d);
3927 DUMP_VAR(txq_stat.lo, d);
3929 DUMP_VAR(ieee->scans, d);
3930 DUMP_VAR(reset_backoff, d);
3934 static DEVICE_ATTR(internals, S_IRUGO, show_internals, NULL);
3937 static ssize_t show_bssinfo(struct device *d, struct device_attribute *attr,
3940 struct ipw2100_priv *priv = dev_get_drvdata(d);
3941 char essid[IW_ESSID_MAX_SIZE + 1];
3948 memset(essid, 0, sizeof(essid));
3949 memset(bssid, 0, sizeof(bssid));
3951 length = IW_ESSID_MAX_SIZE;
3952 ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_SSID, essid, &length);
3954 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
3957 length = sizeof(bssid);
3958 ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID,
3961 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
3964 length = sizeof(u32);
3965 ret = ipw2100_get_ordinal(priv, IPW_ORD_OUR_FREQ, &chan, &length);
3967 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
3970 out += sprintf(out, "ESSID: %s\n", essid);
3971 out += sprintf(out, "BSSID: %02x:%02x:%02x:%02x:%02x:%02x\n",
3972 bssid[0], bssid[1], bssid[2],
3973 bssid[3], bssid[4], bssid[5]);
3974 out += sprintf(out, "Channel: %d\n", chan);
3978 static DEVICE_ATTR(bssinfo, S_IRUGO, show_bssinfo, NULL);
3981 #ifdef CONFIG_IPW_DEBUG
3982 static ssize_t show_debug_level(struct device_driver *d, char *buf)
3984 return sprintf(buf, "0x%08X\n", ipw2100_debug_level);
3987 static ssize_t store_debug_level(struct device_driver *d, const char *buf,
3990 char *p = (char *)buf;
3993 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
3995 if (p[0] == 'x' || p[0] == 'X')
3997 val = simple_strtoul(p, &p, 16);
3999 val = simple_strtoul(p, &p, 10);
4001 IPW_DEBUG_INFO(DRV_NAME
4002 ": %s is not in hex or decimal form.\n", buf);
4004 ipw2100_debug_level = val;
4006 return strnlen(buf, count);
4008 static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, show_debug_level,
4010 #endif /* CONFIG_IPW_DEBUG */
4013 static ssize_t show_fatal_error(struct device *d,
4014 struct device_attribute *attr, char *buf)
4016 struct ipw2100_priv *priv = dev_get_drvdata(d);
4020 if (priv->fatal_error)
4021 out += sprintf(out, "0x%08X\n",
4024 out += sprintf(out, "0\n");
4026 for (i = 1; i <= IPW2100_ERROR_QUEUE; i++) {
4027 if (!priv->fatal_errors[(priv->fatal_index - i) %
4028 IPW2100_ERROR_QUEUE])
4031 out += sprintf(out, "%d. 0x%08X\n", i,
4032 priv->fatal_errors[(priv->fatal_index - i) %
4033 IPW2100_ERROR_QUEUE]);
4039 static ssize_t store_fatal_error(struct device *d,
4040 struct device_attribute *attr, const char *buf, size_t count)
4042 struct ipw2100_priv *priv = dev_get_drvdata(d);
4043 schedule_reset(priv);
4046 static DEVICE_ATTR(fatal_error, S_IWUSR|S_IRUGO, show_fatal_error, store_fatal_error);
4049 static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
4052 struct ipw2100_priv *priv = dev_get_drvdata(d);
4053 return sprintf(buf, "%d\n", priv->ieee->scan_age);
4056 static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
4057 const char *buf, size_t count)
4059 struct ipw2100_priv *priv = dev_get_drvdata(d);
4060 struct net_device *dev = priv->net_dev;
4061 char buffer[] = "00000000";
4063 (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
4067 IPW_DEBUG_INFO("enter\n");
4069 strncpy(buffer, buf, len);
4072 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
4074 if (p[0] == 'x' || p[0] == 'X')
4076 val = simple_strtoul(p, &p, 16);
4078 val = simple_strtoul(p, &p, 10);
4080 IPW_DEBUG_INFO("%s: user supplied invalid value.\n",
4083 priv->ieee->scan_age = val;
4084 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
4087 IPW_DEBUG_INFO("exit\n");
4090 static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
4093 static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
4096 /* 0 - RF kill not enabled
4097 1 - SW based RF kill active (sysfs)
4098 2 - HW based RF kill active
4099 3 - Both HW and SW baed RF kill active */
4100 struct ipw2100_priv *priv = (struct ipw2100_priv *)d->driver_data;
4101 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
4102 (rf_kill_active(priv) ? 0x2 : 0x0);
4103 return sprintf(buf, "%i\n", val);
4106 static int ipw_radio_kill_sw(struct ipw2100_priv *priv, int disable_radio)
4108 if ((disable_radio ? 1 : 0) ==
4109 (priv->status & STATUS_RF_KILL_SW ? 1 : 0))
4112 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
4113 disable_radio ? "OFF" : "ON");
4115 down(&priv->action_sem);
4117 if (disable_radio) {
4118 priv->status |= STATUS_RF_KILL_SW;
4121 priv->status &= ~STATUS_RF_KILL_SW;
4122 if (rf_kill_active(priv)) {
4123 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
4124 "disabled by HW switch\n");
4125 /* Make sure the RF_KILL check timer is running */
4126 priv->stop_rf_kill = 0;
4127 cancel_delayed_work(&priv->rf_kill);
4128 queue_delayed_work(priv->workqueue, &priv->rf_kill,
4131 schedule_reset(priv);
4134 up(&priv->action_sem);
4138 static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
4139 const char *buf, size_t count)
4141 struct ipw2100_priv *priv = dev_get_drvdata(d);
4142 ipw_radio_kill_sw(priv, buf[0] == '1');
4145 static DEVICE_ATTR(rf_kill, S_IWUSR|S_IRUGO, show_rf_kill, store_rf_kill);
4148 static struct attribute *ipw2100_sysfs_entries[] = {
4149 &dev_attr_hardware.attr,
4150 &dev_attr_registers.attr,
4151 &dev_attr_ordinals.attr,
4153 &dev_attr_stats.attr,
4154 &dev_attr_internals.attr,
4155 &dev_attr_bssinfo.attr,
4156 &dev_attr_memory.attr,
4157 &dev_attr_scan_age.attr,
4158 &dev_attr_fatal_error.attr,
4159 &dev_attr_rf_kill.attr,
4161 &dev_attr_status.attr,
4162 &dev_attr_capability.attr,
4166 static struct attribute_group ipw2100_attribute_group = {
4167 .attrs = ipw2100_sysfs_entries,
4171 static int status_queue_allocate(struct ipw2100_priv *priv, int entries)
4173 struct ipw2100_status_queue *q = &priv->status_queue;
4175 IPW_DEBUG_INFO("enter\n");
4177 q->size = entries * sizeof(struct ipw2100_status);
4178 q->drv = (struct ipw2100_status *)pci_alloc_consistent(
4179 priv->pci_dev, q->size, &q->nic);
4182 "Can not allocate status queue.\n");
4186 memset(q->drv, 0, q->size);
4188 IPW_DEBUG_INFO("exit\n");
4193 static void status_queue_free(struct ipw2100_priv *priv)
4195 IPW_DEBUG_INFO("enter\n");
4197 if (priv->status_queue.drv) {
4198 pci_free_consistent(
4199 priv->pci_dev, priv->status_queue.size,
4200 priv->status_queue.drv, priv->status_queue.nic);
4201 priv->status_queue.drv = NULL;
4204 IPW_DEBUG_INFO("exit\n");
4207 static int bd_queue_allocate(struct ipw2100_priv *priv,
4208 struct ipw2100_bd_queue *q, int entries)
4210 IPW_DEBUG_INFO("enter\n");
4212 memset(q, 0, sizeof(struct ipw2100_bd_queue));
4214 q->entries = entries;
4215 q->size = entries * sizeof(struct ipw2100_bd);
4216 q->drv = pci_alloc_consistent(priv->pci_dev, q->size, &q->nic);
4218 IPW_DEBUG_INFO("can't allocate shared memory for buffer descriptors\n");
4221 memset(q->drv, 0, q->size);
4223 IPW_DEBUG_INFO("exit\n");
4228 static void bd_queue_free(struct ipw2100_priv *priv,
4229 struct ipw2100_bd_queue *q)
4231 IPW_DEBUG_INFO("enter\n");
4237 pci_free_consistent(priv->pci_dev,
4238 q->size, q->drv, q->nic);
4242 IPW_DEBUG_INFO("exit\n");
4245 static void bd_queue_initialize(
4246 struct ipw2100_priv *priv, struct ipw2100_bd_queue * q,
4247 u32 base, u32 size, u32 r, u32 w)
4249 IPW_DEBUG_INFO("enter\n");
4251 IPW_DEBUG_INFO("initializing bd queue at virt=%p, phys=%08x\n", q->drv, (u32)q->nic);
4253 write_register(priv->net_dev, base, q->nic);
4254 write_register(priv->net_dev, size, q->entries);
4255 write_register(priv->net_dev, r, q->oldest);
4256 write_register(priv->net_dev, w, q->next);
4258 IPW_DEBUG_INFO("exit\n");
4261 static void ipw2100_kill_workqueue(struct ipw2100_priv *priv)
4263 if (priv->workqueue) {
4264 priv->stop_rf_kill = 1;
4265 priv->stop_hang_check = 1;
4266 cancel_delayed_work(&priv->reset_work);
4267 cancel_delayed_work(&priv->security_work);
4268 cancel_delayed_work(&priv->wx_event_work);
4269 cancel_delayed_work(&priv->hang_check);
4270 cancel_delayed_work(&priv->rf_kill);
4271 destroy_workqueue(priv->workqueue);
4272 priv->workqueue = NULL;
4276 static int ipw2100_tx_allocate(struct ipw2100_priv *priv)
4278 int i, j, err = -EINVAL;
4282 IPW_DEBUG_INFO("enter\n");
4284 err = bd_queue_allocate(priv, &priv->tx_queue, TX_QUEUE_LENGTH);
4286 IPW_DEBUG_ERROR("%s: failed bd_queue_allocate\n",
4287 priv->net_dev->name);
4291 priv->tx_buffers = (struct ipw2100_tx_packet *)kmalloc(
4292 TX_PENDED_QUEUE_LENGTH * sizeof(struct ipw2100_tx_packet),
4294 if (!priv->tx_buffers) {
4295 printk(KERN_ERR DRV_NAME ": %s: alloc failed form tx buffers.\n",
4296 priv->net_dev->name);
4297 bd_queue_free(priv, &priv->tx_queue);
4301 for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
4302 v = pci_alloc_consistent(
4303 priv->pci_dev, sizeof(struct ipw2100_data_header), &p);
4305 printk(KERN_ERR DRV_NAME ": %s: PCI alloc failed for tx "
4306 "buffers.\n", priv->net_dev->name);
4311 priv->tx_buffers[i].type = DATA;
4312 priv->tx_buffers[i].info.d_struct.data = (struct ipw2100_data_header*)v;
4313 priv->tx_buffers[i].info.d_struct.data_phys = p;
4314 priv->tx_buffers[i].info.d_struct.txb = NULL;
4317 if (i == TX_PENDED_QUEUE_LENGTH)
4320 for (j = 0; j < i; j++) {
4321 pci_free_consistent(
4323 sizeof(struct ipw2100_data_header),
4324 priv->tx_buffers[j].info.d_struct.data,
4325 priv->tx_buffers[j].info.d_struct.data_phys);
4328 kfree(priv->tx_buffers);
4329 priv->tx_buffers = NULL;
4334 static void ipw2100_tx_initialize(struct ipw2100_priv *priv)
4338 IPW_DEBUG_INFO("enter\n");
4341 * reinitialize packet info lists
4343 INIT_LIST_HEAD(&priv->fw_pend_list);
4344 INIT_STAT(&priv->fw_pend_stat);
4347 * reinitialize lists
4349 INIT_LIST_HEAD(&priv->tx_pend_list);
4350 INIT_LIST_HEAD(&priv->tx_free_list);
4351 INIT_STAT(&priv->tx_pend_stat);
4352 INIT_STAT(&priv->tx_free_stat);
4354 for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
4355 /* We simply drop any SKBs that have been queued for
4357 if (priv->tx_buffers[i].info.d_struct.txb) {
4358 ieee80211_txb_free(priv->tx_buffers[i].info.d_struct.txb);
4359 priv->tx_buffers[i].info.d_struct.txb = NULL;
4362 list_add_tail(&priv->tx_buffers[i].list, &priv->tx_free_list);
4365 SET_STAT(&priv->tx_free_stat, i);
4367 priv->tx_queue.oldest = 0;
4368 priv->tx_queue.available = priv->tx_queue.entries;
4369 priv->tx_queue.next = 0;
4370 INIT_STAT(&priv->txq_stat);
4371 SET_STAT(&priv->txq_stat, priv->tx_queue.available);
4373 bd_queue_initialize(priv, &priv->tx_queue,
4374 IPW_MEM_HOST_SHARED_TX_QUEUE_BD_BASE,
4375 IPW_MEM_HOST_SHARED_TX_QUEUE_BD_SIZE,
4376 IPW_MEM_HOST_SHARED_TX_QUEUE_READ_INDEX,
4377 IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX);
4379 IPW_DEBUG_INFO("exit\n");
4383 static void ipw2100_tx_free(struct ipw2100_priv *priv)
4387 IPW_DEBUG_INFO("enter\n");
4389 bd_queue_free(priv, &priv->tx_queue);
4391 if (!priv->tx_buffers)
4394 for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
4395 if (priv->tx_buffers[i].info.d_struct.txb) {
4396 ieee80211_txb_free(priv->tx_buffers[i].info.d_struct.txb);
4397 priv->tx_buffers[i].info.d_struct.txb = NULL;
4399 if (priv->tx_buffers[i].info.d_struct.data)
4400 pci_free_consistent(
4402 sizeof(struct ipw2100_data_header),
4403 priv->tx_buffers[i].info.d_struct.data,
4404 priv->tx_buffers[i].info.d_struct.data_phys);
4407 kfree(priv->tx_buffers);
4408 priv->tx_buffers = NULL;
4410 IPW_DEBUG_INFO("exit\n");
4415 static int ipw2100_rx_allocate(struct ipw2100_priv *priv)
4417 int i, j, err = -EINVAL;
4419 IPW_DEBUG_INFO("enter\n");
4421 err = bd_queue_allocate(priv, &priv->rx_queue, RX_QUEUE_LENGTH);
4423 IPW_DEBUG_INFO("failed bd_queue_allocate\n");
4427 err = status_queue_allocate(priv, RX_QUEUE_LENGTH);
4429 IPW_DEBUG_INFO("failed status_queue_allocate\n");
4430 bd_queue_free(priv, &priv->rx_queue);
4437 priv->rx_buffers = (struct ipw2100_rx_packet *)
4438 kmalloc(RX_QUEUE_LENGTH * sizeof(struct ipw2100_rx_packet),
4440 if (!priv->rx_buffers) {
4441 IPW_DEBUG_INFO("can't allocate rx packet buffer table\n");
4443 bd_queue_free(priv, &priv->rx_queue);
4445 status_queue_free(priv);
4450 for (i = 0; i < RX_QUEUE_LENGTH; i++) {
4451 struct ipw2100_rx_packet *packet = &priv->rx_buffers[i];
4453 err = ipw2100_alloc_skb(priv, packet);
4454 if (unlikely(err)) {
4459 /* The BD holds the cache aligned address */
4460 priv->rx_queue.drv[i].host_addr = packet->dma_addr;
4461 priv->rx_queue.drv[i].buf_length = IPW_RX_NIC_BUFFER_LENGTH;
4462 priv->status_queue.drv[i].status_fields = 0;
4465 if (i == RX_QUEUE_LENGTH)
4468 for (j = 0; j < i; j++) {
4469 pci_unmap_single(priv->pci_dev, priv->rx_buffers[j].dma_addr,
4470 sizeof(struct ipw2100_rx_packet),
4471 PCI_DMA_FROMDEVICE);
4472 dev_kfree_skb(priv->rx_buffers[j].skb);
4475 kfree(priv->rx_buffers);
4476 priv->rx_buffers = NULL;
4478 bd_queue_free(priv, &priv->rx_queue);
4480 status_queue_free(priv);
4485 static void ipw2100_rx_initialize(struct ipw2100_priv *priv)
4487 IPW_DEBUG_INFO("enter\n");
4489 priv->rx_queue.oldest = 0;
4490 priv->rx_queue.available = priv->rx_queue.entries - 1;
4491 priv->rx_queue.next = priv->rx_queue.entries - 1;
4493 INIT_STAT(&priv->rxq_stat);
4494 SET_STAT(&priv->rxq_stat, priv->rx_queue.available);
4496 bd_queue_initialize(priv, &priv->rx_queue,
4497 IPW_MEM_HOST_SHARED_RX_BD_BASE,
4498 IPW_MEM_HOST_SHARED_RX_BD_SIZE,
4499 IPW_MEM_HOST_SHARED_RX_READ_INDEX,
4500 IPW_MEM_HOST_SHARED_RX_WRITE_INDEX);
4502 /* set up the status queue */
4503 write_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_STATUS_BASE,
4504 priv->status_queue.nic);
4506 IPW_DEBUG_INFO("exit\n");
4509 static void ipw2100_rx_free(struct ipw2100_priv *priv)
4513 IPW_DEBUG_INFO("enter\n");
4515 bd_queue_free(priv, &priv->rx_queue);
4516 status_queue_free(priv);
4518 if (!priv->rx_buffers)
4521 for (i = 0; i < RX_QUEUE_LENGTH; i++) {
4522 if (priv->rx_buffers[i].rxp) {
4523 pci_unmap_single(priv->pci_dev,
4524 priv->rx_buffers[i].dma_addr,
4525 sizeof(struct ipw2100_rx),
4526 PCI_DMA_FROMDEVICE);
4527 dev_kfree_skb(priv->rx_buffers[i].skb);
4531 kfree(priv->rx_buffers);
4532 priv->rx_buffers = NULL;
4534 IPW_DEBUG_INFO("exit\n");
4537 static int ipw2100_read_mac_address(struct ipw2100_priv *priv)
4539 u32 length = ETH_ALEN;
4544 err = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ADAPTER_MAC,
4547 IPW_DEBUG_INFO("MAC address read failed\n");
4550 IPW_DEBUG_INFO("card MAC is %02X:%02X:%02X:%02X:%02X:%02X\n",
4551 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
4553 memcpy(priv->net_dev->dev_addr, mac, ETH_ALEN);
4558 /********************************************************************
4562 ********************************************************************/
4564 static int ipw2100_set_mac_address(struct ipw2100_priv *priv, int batch_mode)
4566 struct host_command cmd = {
4567 .host_command = ADAPTER_ADDRESS,
4568 .host_command_sequence = 0,
4569 .host_command_length = ETH_ALEN
4573 IPW_DEBUG_HC("SET_MAC_ADDRESS\n");
4575 IPW_DEBUG_INFO("enter\n");
4577 if (priv->config & CFG_CUSTOM_MAC) {
4578 memcpy(cmd.host_command_parameters, priv->mac_addr,
4580 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
4582 memcpy(cmd.host_command_parameters, priv->net_dev->dev_addr,
4585 err = ipw2100_hw_send_command(priv, &cmd);
4587 IPW_DEBUG_INFO("exit\n");
4591 static int ipw2100_set_port_type(struct ipw2100_priv *priv, u32 port_type,
4594 struct host_command cmd = {
4595 .host_command = PORT_TYPE,
4596 .host_command_sequence = 0,
4597 .host_command_length = sizeof(u32)
4601 switch (port_type) {
4603 cmd.host_command_parameters[0] = IPW_BSS;
4606 cmd.host_command_parameters[0] = IPW_IBSS;
4610 IPW_DEBUG_HC("PORT_TYPE: %s\n",
4611 port_type == IPW_IBSS ? "Ad-Hoc" : "Managed");
4614 err = ipw2100_disable_adapter(priv);
4616 printk(KERN_ERR DRV_NAME ": %s: Could not disable adapter %d\n",
4617 priv->net_dev->name, err);
4622 /* send cmd to firmware */
4623 err = ipw2100_hw_send_command(priv, &cmd);
4626 ipw2100_enable_adapter(priv);
4632 static int ipw2100_set_channel(struct ipw2100_priv *priv, u32 channel,
4635 struct host_command cmd = {
4636 .host_command = CHANNEL,
4637 .host_command_sequence = 0,
4638 .host_command_length = sizeof(u32)
4642 cmd.host_command_parameters[0] = channel;
4644 IPW_DEBUG_HC("CHANNEL: %d\n", channel);
4646 /* If BSS then we don't support channel selection */
4647 if (priv->ieee->iw_mode == IW_MODE_INFRA)
4650 if ((channel != 0) &&
4651 ((channel < REG_MIN_CHANNEL) || (channel > REG_MAX_CHANNEL)))
4655 err = ipw2100_disable_adapter(priv);
4660 err = ipw2100_hw_send_command(priv, &cmd);
4662 IPW_DEBUG_INFO("Failed to set channel to %d",
4668 priv->config |= CFG_STATIC_CHANNEL;
4670 priv->config &= ~CFG_STATIC_CHANNEL;
4672 priv->channel = channel;
4675 err = ipw2100_enable_adapter(priv);
4683 static int ipw2100_system_config(struct ipw2100_priv *priv, int batch_mode)
4685 struct host_command cmd = {
4686 .host_command = SYSTEM_CONFIG,
4687 .host_command_sequence = 0,
4688 .host_command_length = 12,
4690 u32 ibss_mask, len = sizeof(u32);
4693 /* Set system configuration */
4696 err = ipw2100_disable_adapter(priv);
4701 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
4702 cmd.host_command_parameters[0] |= IPW_CFG_IBSS_AUTO_START;
4704 cmd.host_command_parameters[0] |= IPW_CFG_IBSS_MASK |
4706 IPW_CFG_802_1x_ENABLE;
4708 if (!(priv->config & CFG_LONG_PREAMBLE))
4709 cmd.host_command_parameters[0] |= IPW_CFG_PREAMBLE_AUTO;
4711 err = ipw2100_get_ordinal(priv,
4712 IPW_ORD_EEPROM_IBSS_11B_CHANNELS,
4715 ibss_mask = IPW_IBSS_11B_DEFAULT_MASK;
4717 cmd.host_command_parameters[1] = REG_CHANNEL_MASK;
4718 cmd.host_command_parameters[2] = REG_CHANNEL_MASK & ibss_mask;
4721 /*cmd.host_command_parameters[0] |= DIVERSITY_ANTENNA_A;*/
4723 err = ipw2100_hw_send_command(priv, &cmd);
4727 /* If IPv6 is configured in the kernel then we don't want to filter out all
4728 * of the multicast packets as IPv6 needs some. */
4729 #if !defined(CONFIG_IPV6) && !defined(CONFIG_IPV6_MODULE)
4730 cmd.host_command = ADD_MULTICAST;
4731 cmd.host_command_sequence = 0;
4732 cmd.host_command_length = 0;
4734 ipw2100_hw_send_command(priv, &cmd);
4737 err = ipw2100_enable_adapter(priv);
4745 static int ipw2100_set_tx_rates(struct ipw2100_priv *priv, u32 rate,
4748 struct host_command cmd = {
4749 .host_command = BASIC_TX_RATES,
4750 .host_command_sequence = 0,
4751 .host_command_length = 4
4755 cmd.host_command_parameters[0] = rate & TX_RATE_MASK;
4758 err = ipw2100_disable_adapter(priv);
4763 /* Set BASIC TX Rate first */
4764 ipw2100_hw_send_command(priv, &cmd);
4767 cmd.host_command = TX_RATES;
4768 ipw2100_hw_send_command(priv, &cmd);
4770 /* Set MSDU TX Rate */
4771 cmd.host_command = MSDU_TX_RATES;
4772 ipw2100_hw_send_command(priv, &cmd);
4775 err = ipw2100_enable_adapter(priv);
4780 priv->tx_rates = rate;
4785 static int ipw2100_set_power_mode(struct ipw2100_priv *priv,
4788 struct host_command cmd = {
4789 .host_command = POWER_MODE,
4790 .host_command_sequence = 0,
4791 .host_command_length = 4
4795 cmd.host_command_parameters[0] = power_level;
4797 err = ipw2100_hw_send_command(priv, &cmd);
4801 if (power_level == IPW_POWER_MODE_CAM)
4802 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
4804 priv->power_mode = IPW_POWER_ENABLED | power_level;
4806 #ifdef CONFIG_IPW2100_TX_POWER
4807 if (priv->port_type == IBSS &&
4808 priv->adhoc_power != DFTL_IBSS_TX_POWER) {
4809 /* Set beacon interval */
4810 cmd.host_command = TX_POWER_INDEX;
4811 cmd.host_command_parameters[0] = (u32)priv->adhoc_power;
4813 err = ipw2100_hw_send_command(priv, &cmd);
4823 static int ipw2100_set_rts_threshold(struct ipw2100_priv *priv, u32 threshold)
4825 struct host_command cmd = {
4826 .host_command = RTS_THRESHOLD,
4827 .host_command_sequence = 0,
4828 .host_command_length = 4
4832 if (threshold & RTS_DISABLED)
4833 cmd.host_command_parameters[0] = MAX_RTS_THRESHOLD;
4835 cmd.host_command_parameters[0] = threshold & ~RTS_DISABLED;
4837 err = ipw2100_hw_send_command(priv, &cmd);
4841 priv->rts_threshold = threshold;
4847 int ipw2100_set_fragmentation_threshold(struct ipw2100_priv *priv,
4848 u32 threshold, int batch_mode)
4850 struct host_command cmd = {
4851 .host_command = FRAG_THRESHOLD,
4852 .host_command_sequence = 0,
4853 .host_command_length = 4,
4854 .host_command_parameters[0] = 0,
4859 err = ipw2100_disable_adapter(priv);
4865 threshold = DEFAULT_FRAG_THRESHOLD;
4867 threshold = max(threshold, MIN_FRAG_THRESHOLD);
4868 threshold = min(threshold, MAX_FRAG_THRESHOLD);
4871 cmd.host_command_parameters[0] = threshold;
4873 IPW_DEBUG_HC("FRAG_THRESHOLD: %u\n", threshold);
4875 err = ipw2100_hw_send_command(priv, &cmd);
4878 ipw2100_enable_adapter(priv);
4881 priv->frag_threshold = threshold;
4887 static int ipw2100_set_short_retry(struct ipw2100_priv *priv, u32 retry)
4889 struct host_command cmd = {
4890 .host_command = SHORT_RETRY_LIMIT,
4891 .host_command_sequence = 0,
4892 .host_command_length = 4
4896 cmd.host_command_parameters[0] = retry;
4898 err = ipw2100_hw_send_command(priv, &cmd);
4902 priv->short_retry_limit = retry;
4907 static int ipw2100_set_long_retry(struct ipw2100_priv *priv, u32 retry)
4909 struct host_command cmd = {
4910 .host_command = LONG_RETRY_LIMIT,
4911 .host_command_sequence = 0,
4912 .host_command_length = 4
4916 cmd.host_command_parameters[0] = retry;
4918 err = ipw2100_hw_send_command(priv, &cmd);
4922 priv->long_retry_limit = retry;
4928 static int ipw2100_set_mandatory_bssid(struct ipw2100_priv *priv, u8 *bssid,
4931 struct host_command cmd = {
4932 .host_command = MANDATORY_BSSID,
4933 .host_command_sequence = 0,
4934 .host_command_length = (bssid == NULL) ? 0 : ETH_ALEN
4938 #ifdef CONFIG_IPW_DEBUG
4941 "MANDATORY_BSSID: %02X:%02X:%02X:%02X:%02X:%02X\n",
4942 bssid[0], bssid[1], bssid[2], bssid[3], bssid[4],
4945 IPW_DEBUG_HC("MANDATORY_BSSID: <clear>\n");
4947 /* if BSSID is empty then we disable mandatory bssid mode */
4949 memcpy((u8 *)cmd.host_command_parameters, bssid, ETH_ALEN);
4952 err = ipw2100_disable_adapter(priv);
4957 err = ipw2100_hw_send_command(priv, &cmd);
4960 ipw2100_enable_adapter(priv);
4965 #ifdef CONFIG_IEEE80211_WPA
4966 static int ipw2100_disassociate_bssid(struct ipw2100_priv *priv)
4968 struct host_command cmd = {
4969 .host_command = DISASSOCIATION_BSSID,
4970 .host_command_sequence = 0,
4971 .host_command_length = ETH_ALEN
4976 IPW_DEBUG_HC("DISASSOCIATION_BSSID\n");
4979 /* The Firmware currently ignores the BSSID and just disassociates from
4980 * the currently associated AP -- but in the off chance that a future
4981 * firmware does use the BSSID provided here, we go ahead and try and
4982 * set it to the currently associated AP's BSSID */
4983 memcpy(cmd.host_command_parameters, priv->bssid, ETH_ALEN);
4985 err = ipw2100_hw_send_command(priv, &cmd);
4992 * Pseudo code for setting up wpa_frame:
4995 void x(struct ieee80211_assoc_frame *wpa_assoc)
4997 struct ipw2100_wpa_assoc_frame frame;
4998 frame->fixed_ie_mask = IPW_WPA_CAPABILTIES |
4999 IPW_WPA_LISTENINTERVAL |
5001 frame->capab_info = wpa_assoc->capab_info;
5002 frame->lisen_interval = wpa_assoc->listent_interval;
5003 memcpy(frame->current_ap, wpa_assoc->current_ap, ETH_ALEN);
5005 /* UNKNOWN -- I'm not postivive about this part; don't have any WPA
5006 * setup here to test it with.
5008 * Walk the IEs in the wpa_assoc and figure out the total size of all
5009 * that data. Stick that into frame->var_ie_len. Then memcpy() all of
5010 * the IEs from wpa_frame into frame.
5012 frame->var_ie_len = calculate_ie_len(wpa_assoc);
5013 memcpy(frame->var_ie, wpa_assoc->variable, frame->var_ie_len);
5015 ipw2100_set_wpa_ie(priv, &frame, 0);
5022 static int ipw2100_set_wpa_ie(struct ipw2100_priv *,
5023 struct ipw2100_wpa_assoc_frame *, int)
5024 __attribute__ ((unused));
5026 static int ipw2100_set_wpa_ie(struct ipw2100_priv *priv,
5027 struct ipw2100_wpa_assoc_frame *wpa_frame,
5030 struct host_command cmd = {
5031 .host_command = SET_WPA_IE,
5032 .host_command_sequence = 0,
5033 .host_command_length = sizeof(struct ipw2100_wpa_assoc_frame),
5037 IPW_DEBUG_HC("SET_WPA_IE\n");
5040 err = ipw2100_disable_adapter(priv);
5045 memcpy(cmd.host_command_parameters, wpa_frame,
5046 sizeof(struct ipw2100_wpa_assoc_frame));
5048 err = ipw2100_hw_send_command(priv, &cmd);
5051 if (ipw2100_enable_adapter(priv))
5058 struct security_info_params {
5059 u32 allowed_ciphers;
5062 u8 replay_counters_number;
5063 u8 unicast_using_group;
5064 } __attribute__ ((packed));
5066 static int ipw2100_set_security_information(struct ipw2100_priv *priv,
5069 int unicast_using_group,
5072 struct host_command cmd = {
5073 .host_command = SET_SECURITY_INFORMATION,
5074 .host_command_sequence = 0,
5075 .host_command_length = sizeof(struct security_info_params)
5077 struct security_info_params *security =
5078 (struct security_info_params *)&cmd.host_command_parameters;
5080 memset(security, 0, sizeof(*security));
5082 /* If shared key AP authentication is turned on, then we need to
5083 * configure the firmware to try and use it.
5085 * Actual data encryption/decryption is handled by the host. */
5086 security->auth_mode = auth_mode;
5087 security->unicast_using_group = unicast_using_group;
5089 switch (security_level) {
5092 security->allowed_ciphers = IPW_NONE_CIPHER;
5095 security->allowed_ciphers = IPW_WEP40_CIPHER |
5099 security->allowed_ciphers = IPW_WEP40_CIPHER |
5100 IPW_WEP104_CIPHER | IPW_TKIP_CIPHER;
5102 case SEC_LEVEL_2_CKIP:
5103 security->allowed_ciphers = IPW_WEP40_CIPHER |
5104 IPW_WEP104_CIPHER | IPW_CKIP_CIPHER;
5107 security->allowed_ciphers = IPW_WEP40_CIPHER |
5108 IPW_WEP104_CIPHER | IPW_TKIP_CIPHER | IPW_CCMP_CIPHER;
5113 "SET_SECURITY_INFORMATION: auth:%d cipher:0x%02X (level %d)\n",
5114 security->auth_mode, security->allowed_ciphers, security_level);
5116 security->replay_counters_number = 0;
5119 err = ipw2100_disable_adapter(priv);
5124 err = ipw2100_hw_send_command(priv, &cmd);
5127 ipw2100_enable_adapter(priv);
5132 static int ipw2100_set_tx_power(struct ipw2100_priv *priv,
5135 struct host_command cmd = {
5136 .host_command = TX_POWER_INDEX,
5137 .host_command_sequence = 0,
5138 .host_command_length = 4
5142 cmd.host_command_parameters[0] = tx_power;
5144 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
5145 err = ipw2100_hw_send_command(priv, &cmd);
5147 priv->tx_power = tx_power;
5152 static int ipw2100_set_ibss_beacon_interval(struct ipw2100_priv *priv,
5153 u32 interval, int batch_mode)
5155 struct host_command cmd = {
5156 .host_command = BEACON_INTERVAL,
5157 .host_command_sequence = 0,
5158 .host_command_length = 4
5162 cmd.host_command_parameters[0] = interval;
5164 IPW_DEBUG_INFO("enter\n");
5166 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
5168 err = ipw2100_disable_adapter(priv);
5173 ipw2100_hw_send_command(priv, &cmd);
5176 err = ipw2100_enable_adapter(priv);
5182 IPW_DEBUG_INFO("exit\n");
5188 void ipw2100_queues_initialize(struct ipw2100_priv *priv)
5190 ipw2100_tx_initialize(priv);
5191 ipw2100_rx_initialize(priv);
5192 ipw2100_msg_initialize(priv);
5195 void ipw2100_queues_free(struct ipw2100_priv *priv)
5197 ipw2100_tx_free(priv);
5198 ipw2100_rx_free(priv);
5199 ipw2100_msg_free(priv);
5202 int ipw2100_queues_allocate(struct ipw2100_priv *priv)
5204 if (ipw2100_tx_allocate(priv) ||
5205 ipw2100_rx_allocate(priv) ||
5206 ipw2100_msg_allocate(priv))
5212 ipw2100_tx_free(priv);
5213 ipw2100_rx_free(priv);
5214 ipw2100_msg_free(priv);
5218 #define IPW_PRIVACY_CAPABLE 0x0008
5220 static int ipw2100_set_wep_flags(struct ipw2100_priv *priv, u32 flags,
5223 struct host_command cmd = {
5224 .host_command = WEP_FLAGS,
5225 .host_command_sequence = 0,
5226 .host_command_length = 4
5230 cmd.host_command_parameters[0] = flags;
5232 IPW_DEBUG_HC("WEP_FLAGS: flags = 0x%08X\n", flags);
5235 err = ipw2100_disable_adapter(priv);
5237 printk(KERN_ERR DRV_NAME ": %s: Could not disable adapter %d\n",
5238 priv->net_dev->name, err);
5243 /* send cmd to firmware */
5244 err = ipw2100_hw_send_command(priv, &cmd);
5247 ipw2100_enable_adapter(priv);
5252 struct ipw2100_wep_key {
5258 /* Macros to ease up priting WEP keys */
5259 #define WEP_FMT_64 "%02X%02X%02X%02X-%02X"
5260 #define WEP_FMT_128 "%02X%02X%02X%02X-%02X%02X%02X%02X-%02X%02X%02X"
5261 #define WEP_STR_64(x) x[0],x[1],x[2],x[3],x[4]
5262 #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]
5268 * @priv: struct to work on
5269 * @idx: index of the key we want to set
5270 * @key: ptr to the key data to set
5271 * @len: length of the buffer at @key
5272 * @batch_mode: FIXME perform the operation in batch mode, not
5273 * disabling the device.
5275 * @returns 0 if OK, < 0 errno code on error.
5277 * Fill out a command structure with the new wep key, length an
5278 * index and send it down the wire.
5280 static int ipw2100_set_key(struct ipw2100_priv *priv,
5281 int idx, char *key, int len, int batch_mode)
5283 int keylen = len ? (len <= 5 ? 5 : 13) : 0;
5284 struct host_command cmd = {
5285 .host_command = WEP_KEY_INFO,
5286 .host_command_sequence = 0,
5287 .host_command_length = sizeof(struct ipw2100_wep_key),
5289 struct ipw2100_wep_key *wep_key = (void*)cmd.host_command_parameters;
5292 IPW_DEBUG_HC("WEP_KEY_INFO: index = %d, len = %d/%d\n",
5295 /* NOTE: We don't check cached values in case the firmware was reset
5296 * or some other problem is occuring. If the user is setting the key,
5297 * then we push the change */
5300 wep_key->len = keylen;
5303 memcpy(wep_key->key, key, len);
5304 memset(wep_key->key + len, 0, keylen - len);
5307 /* Will be optimized out on debug not being configured in */
5309 IPW_DEBUG_WEP("%s: Clearing key %d\n",
5310 priv->net_dev->name, wep_key->idx);
5311 else if (keylen == 5)
5312 IPW_DEBUG_WEP("%s: idx: %d, len: %d key: " WEP_FMT_64 "\n",
5313 priv->net_dev->name, wep_key->idx, wep_key->len,
5314 WEP_STR_64(wep_key->key));
5316 IPW_DEBUG_WEP("%s: idx: %d, len: %d key: " WEP_FMT_128
5318 priv->net_dev->name, wep_key->idx, wep_key->len,
5319 WEP_STR_128(wep_key->key));
5322 err = ipw2100_disable_adapter(priv);
5323 /* FIXME: IPG: shouldn't this prink be in _disable_adapter()? */
5325 printk(KERN_ERR DRV_NAME ": %s: Could not disable adapter %d\n",
5326 priv->net_dev->name, err);
5331 /* send cmd to firmware */
5332 err = ipw2100_hw_send_command(priv, &cmd);
5335 int err2 = ipw2100_enable_adapter(priv);
5342 static int ipw2100_set_key_index(struct ipw2100_priv *priv,
5343 int idx, int batch_mode)
5345 struct host_command cmd = {
5346 .host_command = WEP_KEY_INDEX,
5347 .host_command_sequence = 0,
5348 .host_command_length = 4,
5349 .host_command_parameters = { idx },
5353 IPW_DEBUG_HC("WEP_KEY_INDEX: index = %d\n", idx);
5355 if (idx < 0 || idx > 3)
5359 err = ipw2100_disable_adapter(priv);
5361 printk(KERN_ERR DRV_NAME ": %s: Could not disable adapter %d\n",
5362 priv->net_dev->name, err);
5367 /* send cmd to firmware */
5368 err = ipw2100_hw_send_command(priv, &cmd);
5371 ipw2100_enable_adapter(priv);
5377 static int ipw2100_configure_security(struct ipw2100_priv *priv,
5380 int i, err, auth_mode, sec_level, use_group;
5382 if (!(priv->status & STATUS_RUNNING))
5386 err = ipw2100_disable_adapter(priv);
5391 if (!priv->sec.enabled) {
5392 err = ipw2100_set_security_information(
5393 priv, IPW_AUTH_OPEN, SEC_LEVEL_0, 0, 1);
5395 auth_mode = IPW_AUTH_OPEN;
5396 if ((priv->sec.flags & SEC_AUTH_MODE) &&
5397 (priv->sec.auth_mode == WLAN_AUTH_SHARED_KEY))
5398 auth_mode = IPW_AUTH_SHARED;
5400 sec_level = SEC_LEVEL_0;
5401 if (priv->sec.flags & SEC_LEVEL)
5402 sec_level = priv->sec.level;
5405 if (priv->sec.flags & SEC_UNICAST_GROUP)
5406 use_group = priv->sec.unicast_uses_group;
5408 err = ipw2100_set_security_information(
5409 priv, auth_mode, sec_level, use_group, 1);
5415 if (priv->sec.enabled) {
5416 for (i = 0; i < 4; i++) {
5417 if (!(priv->sec.flags & (1 << i))) {
5418 memset(priv->sec.keys[i], 0, WEP_KEY_LEN);
5419 priv->sec.key_sizes[i] = 0;
5421 err = ipw2100_set_key(priv, i,
5423 priv->sec.key_sizes[i],
5430 ipw2100_set_key_index(priv, priv->ieee->tx_keyidx, 1);
5433 /* Always enable privacy so the Host can filter WEP packets if
5434 * encrypted data is sent up */
5435 err = ipw2100_set_wep_flags(
5436 priv, priv->sec.enabled ? IPW_PRIVACY_CAPABLE : 0, 1);
5440 priv->status &= ~STATUS_SECURITY_UPDATED;
5444 ipw2100_enable_adapter(priv);
5449 static void ipw2100_security_work(struct ipw2100_priv *priv)
5451 /* If we happen to have reconnected before we get a chance to
5452 * process this, then update the security settings--which causes
5453 * a disassociation to occur */
5454 if (!(priv->status & STATUS_ASSOCIATED) &&
5455 priv->status & STATUS_SECURITY_UPDATED)
5456 ipw2100_configure_security(priv, 0);
5459 static void shim__set_security(struct net_device *dev,
5460 struct ieee80211_security *sec)
5462 struct ipw2100_priv *priv = ieee80211_priv(dev);
5463 int i, force_update = 0;
5465 down(&priv->action_sem);
5466 if (!(priv->status & STATUS_INITIALIZED))
5469 for (i = 0; i < 4; i++) {
5470 if (sec->flags & (1 << i)) {
5471 priv->sec.key_sizes[i] = sec->key_sizes[i];
5472 if (sec->key_sizes[i] == 0)
5473 priv->sec.flags &= ~(1 << i);
5475 memcpy(priv->sec.keys[i], sec->keys[i],
5477 priv->sec.flags |= (1 << i);
5478 priv->status |= STATUS_SECURITY_UPDATED;
5482 if ((sec->flags & SEC_ACTIVE_KEY) &&
5483 priv->sec.active_key != sec->active_key) {
5484 if (sec->active_key <= 3) {
5485 priv->sec.active_key = sec->active_key;
5486 priv->sec.flags |= SEC_ACTIVE_KEY;
5488 priv->sec.flags &= ~SEC_ACTIVE_KEY;
5490 priv->status |= STATUS_SECURITY_UPDATED;
5493 if ((sec->flags & SEC_AUTH_MODE) &&
5494 (priv->sec.auth_mode != sec->auth_mode)) {
5495 priv->sec.auth_mode = sec->auth_mode;
5496 priv->sec.flags |= SEC_AUTH_MODE;
5497 priv->status |= STATUS_SECURITY_UPDATED;
5500 if (sec->flags & SEC_ENABLED &&
5501 priv->sec.enabled != sec->enabled) {
5502 priv->sec.flags |= SEC_ENABLED;
5503 priv->sec.enabled = sec->enabled;
5504 priv->status |= STATUS_SECURITY_UPDATED;
5508 if (sec->flags & SEC_LEVEL &&
5509 priv->sec.level != sec->level) {
5510 priv->sec.level = sec->level;
5511 priv->sec.flags |= SEC_LEVEL;
5512 priv->status |= STATUS_SECURITY_UPDATED;
5515 IPW_DEBUG_WEP("Security flags: %c %c%c%c%c %c%c%c%c\n",
5516 priv->sec.flags & (1<<8) ? '1' : '0',
5517 priv->sec.flags & (1<<7) ? '1' : '0',
5518 priv->sec.flags & (1<<6) ? '1' : '0',
5519 priv->sec.flags & (1<<5) ? '1' : '0',
5520 priv->sec.flags & (1<<4) ? '1' : '0',
5521 priv->sec.flags & (1<<3) ? '1' : '0',
5522 priv->sec.flags & (1<<2) ? '1' : '0',
5523 priv->sec.flags & (1<<1) ? '1' : '0',
5524 priv->sec.flags & (1<<0) ? '1' : '0');
5526 /* As a temporary work around to enable WPA until we figure out why
5527 * wpa_supplicant toggles the security capability of the driver, which
5528 * forces a disassocation with force_update...
5530 * if (force_update || !(priv->status & STATUS_ASSOCIATED))*/
5531 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
5532 ipw2100_configure_security(priv, 0);
5534 up(&priv->action_sem);
5537 static int ipw2100_adapter_setup(struct ipw2100_priv *priv)
5543 IPW_DEBUG_INFO("enter\n");
5545 err = ipw2100_disable_adapter(priv);
5548 #ifdef CONFIG_IPW2100_MONITOR
5549 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
5550 err = ipw2100_set_channel(priv, priv->channel, batch_mode);
5554 IPW_DEBUG_INFO("exit\n");
5558 #endif /* CONFIG_IPW2100_MONITOR */
5560 err = ipw2100_read_mac_address(priv);
5564 err = ipw2100_set_mac_address(priv, batch_mode);
5568 err = ipw2100_set_port_type(priv, priv->ieee->iw_mode, batch_mode);
5572 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
5573 err = ipw2100_set_channel(priv, priv->channel, batch_mode);
5578 err = ipw2100_system_config(priv, batch_mode);
5582 err = ipw2100_set_tx_rates(priv, priv->tx_rates, batch_mode);
5586 /* Default to power mode OFF */
5587 err = ipw2100_set_power_mode(priv, IPW_POWER_MODE_CAM);
5591 err = ipw2100_set_rts_threshold(priv, priv->rts_threshold);
5595 if (priv->config & CFG_STATIC_BSSID)
5596 bssid = priv->bssid;
5599 err = ipw2100_set_mandatory_bssid(priv, bssid, batch_mode);
5603 if (priv->config & CFG_STATIC_ESSID)
5604 err = ipw2100_set_essid(priv, priv->essid, priv->essid_len,
5607 err = ipw2100_set_essid(priv, NULL, 0, batch_mode);
5611 err = ipw2100_configure_security(priv, batch_mode);
5615 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
5616 err = ipw2100_set_ibss_beacon_interval(
5617 priv, priv->beacon_interval, batch_mode);
5621 err = ipw2100_set_tx_power(priv, priv->tx_power);
5627 err = ipw2100_set_fragmentation_threshold(
5628 priv, priv->frag_threshold, batch_mode);
5633 IPW_DEBUG_INFO("exit\n");
5639 /*************************************************************************
5641 * EXTERNALLY CALLED METHODS
5643 *************************************************************************/
5645 /* This method is called by the network layer -- not to be confused with
5646 * ipw2100_set_mac_address() declared above called by this driver (and this
5647 * method as well) to talk to the firmware */
5648 static int ipw2100_set_address(struct net_device *dev, void *p)
5650 struct ipw2100_priv *priv = ieee80211_priv(dev);
5651 struct sockaddr *addr = p;
5654 if (!is_valid_ether_addr(addr->sa_data))
5655 return -EADDRNOTAVAIL;
5657 down(&priv->action_sem);
5659 priv->config |= CFG_CUSTOM_MAC;
5660 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
5662 err = ipw2100_set_mac_address(priv, 0);
5666 priv->reset_backoff = 0;
5667 up(&priv->action_sem);
5668 ipw2100_reset_adapter(priv);
5672 up(&priv->action_sem);
5676 static int ipw2100_open(struct net_device *dev)
5678 struct ipw2100_priv *priv = ieee80211_priv(dev);
5679 unsigned long flags;
5680 IPW_DEBUG_INFO("dev->open\n");
5682 spin_lock_irqsave(&priv->low_lock, flags);
5683 if (priv->status & STATUS_ASSOCIATED) {
5684 netif_carrier_on(dev);
5685 netif_start_queue(dev);
5687 spin_unlock_irqrestore(&priv->low_lock, flags);
5692 static int ipw2100_close(struct net_device *dev)
5694 struct ipw2100_priv *priv = ieee80211_priv(dev);
5695 unsigned long flags;
5696 struct list_head *element;
5697 struct ipw2100_tx_packet *packet;
5699 IPW_DEBUG_INFO("enter\n");
5701 spin_lock_irqsave(&priv->low_lock, flags);
5703 if (priv->status & STATUS_ASSOCIATED)
5704 netif_carrier_off(dev);
5705 netif_stop_queue(dev);
5707 /* Flush the TX queue ... */
5708 while (!list_empty(&priv->tx_pend_list)) {
5709 element = priv->tx_pend_list.next;
5710 packet = list_entry(element, struct ipw2100_tx_packet, list);
5713 DEC_STAT(&priv->tx_pend_stat);
5715 ieee80211_txb_free(packet->info.d_struct.txb);
5716 packet->info.d_struct.txb = NULL;
5718 list_add_tail(element, &priv->tx_free_list);
5719 INC_STAT(&priv->tx_free_stat);
5721 spin_unlock_irqrestore(&priv->low_lock, flags);
5723 IPW_DEBUG_INFO("exit\n");
5731 * TODO: Fix this function... its just wrong
5733 static void ipw2100_tx_timeout(struct net_device *dev)
5735 struct ipw2100_priv *priv = ieee80211_priv(dev);
5737 priv->ieee->stats.tx_errors++;
5739 #ifdef CONFIG_IPW2100_MONITOR
5740 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
5744 IPW_DEBUG_INFO("%s: TX timed out. Scheduling firmware restart.\n",
5746 schedule_reset(priv);
5751 * TODO: reimplement it so that it reads statistics
5752 * from the adapter using ordinal tables
5753 * instead of/in addition to collecting them
5756 static struct net_device_stats *ipw2100_stats(struct net_device *dev)
5758 struct ipw2100_priv *priv = ieee80211_priv(dev);
5760 return &priv->ieee->stats;
5763 /* Support for wpa_supplicant. Will be replaced with WEXT once
5764 * they get WPA support. */
5765 #ifdef CONFIG_IEEE80211_WPA
5767 /* following definitions must match definitions in driver_ipw2100.c */
5769 #define IPW2100_IOCTL_WPA_SUPPLICANT SIOCIWFIRSTPRIV+30
5771 #define IPW2100_CMD_SET_WPA_PARAM 1
5772 #define IPW2100_CMD_SET_WPA_IE 2
5773 #define IPW2100_CMD_SET_ENCRYPTION 3
5774 #define IPW2100_CMD_MLME 4
5776 #define IPW2100_PARAM_WPA_ENABLED 1
5777 #define IPW2100_PARAM_TKIP_COUNTERMEASURES 2
5778 #define IPW2100_PARAM_DROP_UNENCRYPTED 3
5779 #define IPW2100_PARAM_PRIVACY_INVOKED 4
5780 #define IPW2100_PARAM_AUTH_ALGS 5
5781 #define IPW2100_PARAM_IEEE_802_1X 6
5783 #define IPW2100_MLME_STA_DEAUTH 1
5784 #define IPW2100_MLME_STA_DISASSOC 2
5786 #define IPW2100_CRYPT_ERR_UNKNOWN_ALG 2
5787 #define IPW2100_CRYPT_ERR_UNKNOWN_ADDR 3
5788 #define IPW2100_CRYPT_ERR_CRYPT_INIT_FAILED 4
5789 #define IPW2100_CRYPT_ERR_KEY_SET_FAILED 5
5790 #define IPW2100_CRYPT_ERR_TX_KEY_SET_FAILED 6
5791 #define IPW2100_CRYPT_ERR_CARD_CONF_FAILED 7
5793 #define IPW2100_CRYPT_ALG_NAME_LEN 16
5795 struct ipw2100_param {
5797 u8 sta_addr[ETH_ALEN];
5812 u8 alg[IPW2100_CRYPT_ALG_NAME_LEN];
5816 u8 seq[8]; /* sequence counter (set: RX, get: TX) */
5824 /* end of driver_ipw2100.c code */
5826 static int ipw2100_wpa_enable(struct ipw2100_priv *priv, int value){
5828 struct ieee80211_device *ieee = priv->ieee;
5829 struct ieee80211_security sec = {
5830 .flags = SEC_LEVEL | SEC_ENABLED,
5834 ieee->wpa_enabled = value;
5837 sec.level = SEC_LEVEL_3;
5840 sec.level = SEC_LEVEL_0;
5844 if (ieee->set_security)
5845 ieee->set_security(ieee->dev, &sec);
5852 #define AUTH_ALG_OPEN_SYSTEM 0x1
5853 #define AUTH_ALG_SHARED_KEY 0x2
5855 static int ipw2100_wpa_set_auth_algs(struct ipw2100_priv *priv, int value){
5857 struct ieee80211_device *ieee = priv->ieee;
5858 struct ieee80211_security sec = {
5859 .flags = SEC_AUTH_MODE,
5863 if (value & AUTH_ALG_SHARED_KEY){
5864 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
5867 sec.auth_mode = WLAN_AUTH_OPEN;
5871 if (ieee->set_security)
5872 ieee->set_security(ieee->dev, &sec);
5880 static int ipw2100_wpa_set_param(struct net_device *dev, u8 name, u32 value){
5882 struct ipw2100_priv *priv = ieee80211_priv(dev);
5886 case IPW2100_PARAM_WPA_ENABLED:
5887 ret = ipw2100_wpa_enable(priv, value);
5890 case IPW2100_PARAM_TKIP_COUNTERMEASURES:
5891 priv->ieee->tkip_countermeasures=value;
5894 case IPW2100_PARAM_DROP_UNENCRYPTED:
5895 priv->ieee->drop_unencrypted=value;
5898 case IPW2100_PARAM_PRIVACY_INVOKED:
5899 priv->ieee->privacy_invoked=value;
5902 case IPW2100_PARAM_AUTH_ALGS:
5903 ret = ipw2100_wpa_set_auth_algs(priv, value);
5906 case IPW2100_PARAM_IEEE_802_1X:
5907 priv->ieee->ieee802_1x=value;
5911 printk(KERN_ERR DRV_NAME ": %s: Unknown WPA param: %d\n",
5919 static int ipw2100_wpa_mlme(struct net_device *dev, int command, int reason){
5921 struct ipw2100_priv *priv = ieee80211_priv(dev);
5925 case IPW2100_MLME_STA_DEAUTH:
5929 case IPW2100_MLME_STA_DISASSOC:
5930 ipw2100_disassociate_bssid(priv);
5934 printk(KERN_ERR DRV_NAME ": %s: Unknown MLME request: %d\n",
5935 dev->name, command);
5943 void ipw2100_wpa_assoc_frame(struct ipw2100_priv *priv,
5944 char *wpa_ie, int wpa_ie_len){
5946 struct ipw2100_wpa_assoc_frame frame;
5948 frame.fixed_ie_mask = 0;
5951 memcpy(frame.var_ie, wpa_ie, wpa_ie_len);
5952 frame.var_ie_len = wpa_ie_len;
5954 /* make sure WPA is enabled */
5955 ipw2100_wpa_enable(priv, 1);
5956 ipw2100_set_wpa_ie(priv, &frame, 0);
5960 static int ipw2100_wpa_set_wpa_ie(struct net_device *dev,
5961 struct ipw2100_param *param, int plen){
5963 struct ipw2100_priv *priv = ieee80211_priv(dev);
5964 struct ieee80211_device *ieee = priv->ieee;
5967 if (! ieee->wpa_enabled)
5970 if (param->u.wpa_ie.len > MAX_WPA_IE_LEN ||
5971 (param->u.wpa_ie.len &&
5972 param->u.wpa_ie.data==NULL))
5975 if (param->u.wpa_ie.len){
5976 buf = kmalloc(param->u.wpa_ie.len, GFP_KERNEL);
5980 memcpy(buf, param->u.wpa_ie.data, param->u.wpa_ie.len);
5982 kfree(ieee->wpa_ie);
5984 ieee->wpa_ie_len = param->u.wpa_ie.len;
5987 kfree(ieee->wpa_ie);
5988 ieee->wpa_ie = NULL;
5989 ieee->wpa_ie_len = 0;
5992 ipw2100_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
5997 /* implementation borrowed from hostap driver */
5999 static int ipw2100_wpa_set_encryption(struct net_device *dev,
6000 struct ipw2100_param *param, int param_len){
6003 struct ipw2100_priv *priv = ieee80211_priv(dev);
6004 struct ieee80211_device *ieee = priv->ieee;
6005 struct ieee80211_crypto_ops *ops;
6006 struct ieee80211_crypt_data **crypt;
6008 struct ieee80211_security sec = {
6012 param->u.crypt.err = 0;
6013 param->u.crypt.alg[IPW2100_CRYPT_ALG_NAME_LEN - 1] = '\0';
6016 (int) ((char *) param->u.crypt.key - (char *) param) +
6017 param->u.crypt.key_len){
6018 IPW_DEBUG_INFO("Len mismatch %d, %d\n", param_len, param->u.crypt.key_len);
6021 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
6022 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
6023 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
6024 if (param->u.crypt.idx >= WEP_KEYS)
6026 crypt = &ieee->crypt[param->u.crypt.idx];
6031 if (strcmp(param->u.crypt.alg, "none") == 0) {
6034 sec.level = SEC_LEVEL_0;
6035 sec.flags |= SEC_ENABLED | SEC_LEVEL;
6036 ieee80211_crypt_delayed_deinit(ieee, crypt);
6041 sec.flags |= SEC_ENABLED;
6043 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6044 if (ops == NULL && strcmp(param->u.crypt.alg, "WEP") == 0) {
6045 request_module("ieee80211_crypt_wep");
6046 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6047 } else if (ops == NULL && strcmp(param->u.crypt.alg, "TKIP") == 0) {
6048 request_module("ieee80211_crypt_tkip");
6049 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6050 } else if (ops == NULL && strcmp(param->u.crypt.alg, "CCMP") == 0) {
6051 request_module("ieee80211_crypt_ccmp");
6052 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6055 IPW_DEBUG_INFO("%s: unknown crypto alg '%s'\n",
6056 dev->name, param->u.crypt.alg);
6057 param->u.crypt.err = IPW2100_CRYPT_ERR_UNKNOWN_ALG;
6062 if (*crypt == NULL || (*crypt)->ops != ops) {
6063 struct ieee80211_crypt_data *new_crypt;
6065 ieee80211_crypt_delayed_deinit(ieee, crypt);
6067 new_crypt = (struct ieee80211_crypt_data *)
6068 kmalloc(sizeof(struct ieee80211_crypt_data), GFP_KERNEL);
6069 if (new_crypt == NULL) {
6073 memset(new_crypt, 0, sizeof(struct ieee80211_crypt_data));
6074 new_crypt->ops = ops;
6075 if (new_crypt->ops && try_module_get(new_crypt->ops->owner))
6076 new_crypt->priv = new_crypt->ops->init(param->u.crypt.idx);
6078 if (new_crypt->priv == NULL) {
6080 param->u.crypt.err =
6081 IPW2100_CRYPT_ERR_CRYPT_INIT_FAILED;
6089 if (param->u.crypt.key_len > 0 && (*crypt)->ops->set_key &&
6090 (*crypt)->ops->set_key(param->u.crypt.key,
6091 param->u.crypt.key_len, param->u.crypt.seq,
6092 (*crypt)->priv) < 0) {
6093 IPW_DEBUG_INFO("%s: key setting failed\n",
6095 param->u.crypt.err = IPW2100_CRYPT_ERR_KEY_SET_FAILED;
6100 if (param->u.crypt.set_tx){
6101 ieee->tx_keyidx = param->u.crypt.idx;
6102 sec.active_key = param->u.crypt.idx;
6103 sec.flags |= SEC_ACTIVE_KEY;
6106 if (ops->name != NULL){
6108 if (strcmp(ops->name, "WEP") == 0) {
6109 memcpy(sec.keys[param->u.crypt.idx], param->u.crypt.key, param->u.crypt.key_len);
6110 sec.key_sizes[param->u.crypt.idx] = param->u.crypt.key_len;
6111 sec.flags |= (1 << param->u.crypt.idx);
6112 sec.flags |= SEC_LEVEL;
6113 sec.level = SEC_LEVEL_1;
6114 } else if (strcmp(ops->name, "TKIP") == 0) {
6115 sec.flags |= SEC_LEVEL;
6116 sec.level = SEC_LEVEL_2;
6117 } else if (strcmp(ops->name, "CCMP") == 0) {
6118 sec.flags |= SEC_LEVEL;
6119 sec.level = SEC_LEVEL_3;
6123 if (ieee->set_security)
6124 ieee->set_security(ieee->dev, &sec);
6126 /* Do not reset port if card is in Managed mode since resetting will
6127 * generate new IEEE 802.11 authentication which may end up in looping
6128 * with IEEE 802.1X. If your hardware requires a reset after WEP
6129 * configuration (for example... Prism2), implement the reset_port in
6130 * the callbacks structures used to initialize the 802.11 stack. */
6131 if (ieee->reset_on_keychange &&
6132 ieee->iw_mode != IW_MODE_INFRA &&
6134 ieee->reset_port(dev)) {
6135 IPW_DEBUG_INFO("%s: reset_port failed\n", dev->name);
6136 param->u.crypt.err = IPW2100_CRYPT_ERR_CARD_CONF_FAILED;
6144 static int ipw2100_wpa_supplicant(struct net_device *dev, struct iw_point *p){
6146 struct ipw2100_param *param;
6149 IPW_DEBUG_IOCTL("wpa_supplicant: len=%d\n", p->length);
6151 if (p->length < sizeof(struct ipw2100_param) || !p->pointer)
6154 param = (struct ipw2100_param *)kmalloc(p->length, GFP_KERNEL);
6158 if (copy_from_user(param, p->pointer, p->length)){
6163 switch (param->cmd){
6165 case IPW2100_CMD_SET_WPA_PARAM:
6166 ret = ipw2100_wpa_set_param(dev, param->u.wpa_param.name,
6167 param->u.wpa_param.value);
6170 case IPW2100_CMD_SET_WPA_IE:
6171 ret = ipw2100_wpa_set_wpa_ie(dev, param, p->length);
6174 case IPW2100_CMD_SET_ENCRYPTION:
6175 ret = ipw2100_wpa_set_encryption(dev, param, p->length);
6178 case IPW2100_CMD_MLME:
6179 ret = ipw2100_wpa_mlme(dev, param->u.mlme.command,
6180 param->u.mlme.reason_code);
6184 printk(KERN_ERR DRV_NAME ": %s: Unknown WPA supplicant request: %d\n",
6185 dev->name, param->cmd);
6190 if (ret == 0 && copy_to_user(p->pointer, param, p->length))
6196 #endif /* CONFIG_IEEE80211_WPA */
6198 static int ipw2100_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
6200 #ifdef CONFIG_IEEE80211_WPA
6201 struct iwreq *wrq = (struct iwreq *) rq;
6204 case IPW2100_IOCTL_WPA_SUPPLICANT:
6205 ret = ipw2100_wpa_supplicant(dev, &wrq->u.data);
6212 #endif /* CONFIG_IEEE80211_WPA */
6218 static void ipw_ethtool_get_drvinfo(struct net_device *dev,
6219 struct ethtool_drvinfo *info)
6221 struct ipw2100_priv *priv = ieee80211_priv(dev);
6222 char fw_ver[64], ucode_ver[64];
6224 strcpy(info->driver, DRV_NAME);
6225 strcpy(info->version, DRV_VERSION);
6227 ipw2100_get_fwversion(priv, fw_ver, sizeof(fw_ver));
6228 ipw2100_get_ucodeversion(priv, ucode_ver, sizeof(ucode_ver));
6230 snprintf(info->fw_version, sizeof(info->fw_version), "%s:%d:%s",
6231 fw_ver, priv->eeprom_version, ucode_ver);
6233 strcpy(info->bus_info, pci_name(priv->pci_dev));
6236 static u32 ipw2100_ethtool_get_link(struct net_device *dev)
6238 struct ipw2100_priv *priv = ieee80211_priv(dev);
6239 return (priv->status & STATUS_ASSOCIATED) ? 1 : 0;
6243 static struct ethtool_ops ipw2100_ethtool_ops = {
6244 .get_link = ipw2100_ethtool_get_link,
6245 .get_drvinfo = ipw_ethtool_get_drvinfo,
6248 static void ipw2100_hang_check(void *adapter)
6250 struct ipw2100_priv *priv = adapter;
6251 unsigned long flags;
6252 u32 rtc = 0xa5a5a5a5;
6253 u32 len = sizeof(rtc);
6256 spin_lock_irqsave(&priv->low_lock, flags);
6258 if (priv->fatal_error != 0) {
6259 /* If fatal_error is set then we need to restart */
6260 IPW_DEBUG_INFO("%s: Hardware fatal error detected.\n",
6261 priv->net_dev->name);
6264 } else if (ipw2100_get_ordinal(priv, IPW_ORD_RTC_TIME, &rtc, &len) ||
6265 (rtc == priv->last_rtc)) {
6266 /* Check if firmware is hung */
6267 IPW_DEBUG_INFO("%s: Firmware RTC stalled.\n",
6268 priv->net_dev->name);
6275 priv->stop_hang_check = 1;
6278 /* Restart the NIC */
6279 schedule_reset(priv);
6282 priv->last_rtc = rtc;
6284 if (!priv->stop_hang_check)
6285 queue_delayed_work(priv->workqueue, &priv->hang_check, HZ / 2);
6287 spin_unlock_irqrestore(&priv->low_lock, flags);
6291 static void ipw2100_rf_kill(void *adapter)
6293 struct ipw2100_priv *priv = adapter;
6294 unsigned long flags;
6296 spin_lock_irqsave(&priv->low_lock, flags);
6298 if (rf_kill_active(priv)) {
6299 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
6300 if (!priv->stop_rf_kill)
6301 queue_delayed_work(priv->workqueue, &priv->rf_kill, HZ);
6305 /* RF Kill is now disabled, so bring the device back up */
6307 if (!(priv->status & STATUS_RF_KILL_MASK)) {
6308 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
6310 schedule_reset(priv);
6312 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
6316 spin_unlock_irqrestore(&priv->low_lock, flags);
6319 static void ipw2100_irq_tasklet(struct ipw2100_priv *priv);
6321 /* Look into using netdev destructor to shutdown ieee80211? */
6323 static struct net_device *ipw2100_alloc_device(
6324 struct pci_dev *pci_dev,
6325 void __iomem *base_addr,
6326 unsigned long mem_start,
6327 unsigned long mem_len)
6329 struct ipw2100_priv *priv;
6330 struct net_device *dev;
6332 dev = alloc_ieee80211(sizeof(struct ipw2100_priv));
6335 priv = ieee80211_priv(dev);
6336 priv->ieee = netdev_priv(dev);
6337 priv->pci_dev = pci_dev;
6338 priv->net_dev = dev;
6340 priv->ieee->hard_start_xmit = ipw2100_tx;
6341 priv->ieee->set_security = shim__set_security;
6343 dev->open = ipw2100_open;
6344 dev->stop = ipw2100_close;
6345 dev->init = ipw2100_net_init;
6346 dev->do_ioctl = ipw2100_ioctl;
6347 dev->get_stats = ipw2100_stats;
6348 dev->ethtool_ops = &ipw2100_ethtool_ops;
6349 dev->tx_timeout = ipw2100_tx_timeout;
6350 dev->wireless_handlers = &ipw2100_wx_handler_def;
6351 dev->get_wireless_stats = ipw2100_wx_wireless_stats;
6352 dev->set_mac_address = ipw2100_set_address;
6353 dev->watchdog_timeo = 3*HZ;
6356 dev->base_addr = (unsigned long)base_addr;
6357 dev->mem_start = mem_start;
6358 dev->mem_end = dev->mem_start + mem_len - 1;
6360 /* NOTE: We don't use the wireless_handlers hook
6361 * in dev as the system will start throwing WX requests
6362 * to us before we're actually initialized and it just
6363 * ends up causing problems. So, we just handle
6364 * the WX extensions through the ipw2100_ioctl interface */
6367 /* memset() puts everything to 0, so we only have explicitely set
6368 * those values that need to be something else */
6370 /* If power management is turned on, default to AUTO mode */
6371 priv->power_mode = IPW_POWER_AUTO;
6375 #ifdef CONFIG_IEEE80211_WPA
6376 priv->ieee->wpa_enabled = 0;
6377 priv->ieee->tkip_countermeasures = 0;
6378 priv->ieee->drop_unencrypted = 0;
6379 priv->ieee->privacy_invoked = 0;
6380 priv->ieee->ieee802_1x = 1;
6381 #endif /* CONFIG_IEEE80211_WPA */
6383 /* Set module parameters */
6386 priv->ieee->iw_mode = IW_MODE_ADHOC;
6388 #ifdef CONFIG_IPW2100_MONITOR
6390 priv->ieee->iw_mode = IW_MODE_MONITOR;
6395 priv->ieee->iw_mode = IW_MODE_INFRA;
6400 priv->status |= STATUS_RF_KILL_SW;
6403 ((channel >= REG_MIN_CHANNEL) &&
6404 (channel <= REG_MAX_CHANNEL))) {
6405 priv->config |= CFG_STATIC_CHANNEL;
6406 priv->channel = channel;
6410 priv->config |= CFG_ASSOCIATE;
6412 priv->beacon_interval = DEFAULT_BEACON_INTERVAL;
6413 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
6414 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
6415 priv->rts_threshold = DEFAULT_RTS_THRESHOLD | RTS_DISABLED;
6416 priv->frag_threshold = DEFAULT_FTS | FRAG_DISABLED;
6417 priv->tx_power = IPW_TX_POWER_DEFAULT;
6418 priv->tx_rates = DEFAULT_TX_RATES;
6420 strcpy(priv->nick, "ipw2100");
6422 spin_lock_init(&priv->low_lock);
6423 sema_init(&priv->action_sem, 1);
6424 sema_init(&priv->adapter_sem, 1);
6426 init_waitqueue_head(&priv->wait_command_queue);
6428 netif_carrier_off(dev);
6430 INIT_LIST_HEAD(&priv->msg_free_list);
6431 INIT_LIST_HEAD(&priv->msg_pend_list);
6432 INIT_STAT(&priv->msg_free_stat);
6433 INIT_STAT(&priv->msg_pend_stat);
6435 INIT_LIST_HEAD(&priv->tx_free_list);
6436 INIT_LIST_HEAD(&priv->tx_pend_list);
6437 INIT_STAT(&priv->tx_free_stat);
6438 INIT_STAT(&priv->tx_pend_stat);
6440 INIT_LIST_HEAD(&priv->fw_pend_list);
6441 INIT_STAT(&priv->fw_pend_stat);
6444 #ifdef CONFIG_SOFTWARE_SUSPEND2
6445 priv->workqueue = create_workqueue(DRV_NAME, 0);
6447 priv->workqueue = create_workqueue(DRV_NAME);
6449 INIT_WORK(&priv->reset_work,
6450 (void (*)(void *))ipw2100_reset_adapter, priv);
6451 INIT_WORK(&priv->security_work,
6452 (void (*)(void *))ipw2100_security_work, priv);
6453 INIT_WORK(&priv->wx_event_work,
6454 (void (*)(void *))ipw2100_wx_event_work, priv);
6455 INIT_WORK(&priv->hang_check, ipw2100_hang_check, priv);
6456 INIT_WORK(&priv->rf_kill, ipw2100_rf_kill, priv);
6458 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
6459 ipw2100_irq_tasklet, (unsigned long)priv);
6461 /* NOTE: We do not start the deferred work for status checks yet */
6462 priv->stop_rf_kill = 1;
6463 priv->stop_hang_check = 1;
6468 static int ipw2100_pci_init_one(struct pci_dev *pci_dev,
6469 const struct pci_device_id *ent)
6471 unsigned long mem_start, mem_len, mem_flags;
6472 void __iomem *base_addr = NULL;
6473 struct net_device *dev = NULL;
6474 struct ipw2100_priv *priv = NULL;
6479 IPW_DEBUG_INFO("enter\n");
6481 mem_start = pci_resource_start(pci_dev, 0);
6482 mem_len = pci_resource_len(pci_dev, 0);
6483 mem_flags = pci_resource_flags(pci_dev, 0);
6485 if ((mem_flags & IORESOURCE_MEM) != IORESOURCE_MEM) {
6486 IPW_DEBUG_INFO("weird - resource type is not memory\n");
6491 base_addr = ioremap_nocache(mem_start, mem_len);
6493 printk(KERN_WARNING DRV_NAME
6494 "Error calling ioremap_nocache.\n");
6499 /* allocate and initialize our net_device */
6500 dev = ipw2100_alloc_device(pci_dev, base_addr, mem_start, mem_len);
6502 printk(KERN_WARNING DRV_NAME
6503 "Error calling ipw2100_alloc_device.\n");
6508 /* set up PCI mappings for device */
6509 err = pci_enable_device(pci_dev);
6511 printk(KERN_WARNING DRV_NAME
6512 "Error calling pci_enable_device.\n");
6516 priv = ieee80211_priv(dev);
6518 pci_set_master(pci_dev);
6519 pci_set_drvdata(pci_dev, priv);
6521 err = pci_set_dma_mask(pci_dev, DMA_32BIT_MASK);
6523 printk(KERN_WARNING DRV_NAME
6524 "Error calling pci_set_dma_mask.\n");
6525 pci_disable_device(pci_dev);
6529 err = pci_request_regions(pci_dev, DRV_NAME);
6531 printk(KERN_WARNING DRV_NAME
6532 "Error calling pci_request_regions.\n");
6533 pci_disable_device(pci_dev);
6537 /* We disable the RETRY_TIMEOUT register (0x41) to keep
6538 * PCI Tx retries from interfering with C3 CPU state */
6539 pci_read_config_dword(pci_dev, 0x40, &val);
6540 if ((val & 0x0000ff00) != 0)
6541 pci_write_config_dword(pci_dev, 0x40, val & 0xffff00ff);
6543 pci_set_power_state(pci_dev, PCI_D0);
6545 if (!ipw2100_hw_is_adapter_in_system(dev)) {
6546 printk(KERN_WARNING DRV_NAME
6547 "Device not found via register read.\n");
6552 SET_NETDEV_DEV(dev, &pci_dev->dev);
6554 /* Force interrupts to be shut off on the device */
6555 priv->status |= STATUS_INT_ENABLED;
6556 ipw2100_disable_interrupts(priv);
6558 /* Allocate and initialize the Tx/Rx queues and lists */
6559 if (ipw2100_queues_allocate(priv)) {
6560 printk(KERN_WARNING DRV_NAME
6561 "Error calilng ipw2100_queues_allocate.\n");
6565 ipw2100_queues_initialize(priv);
6567 err = request_irq(pci_dev->irq,
6568 ipw2100_interrupt, SA_SHIRQ,
6571 printk(KERN_WARNING DRV_NAME
6572 "Error calling request_irq: %d.\n",
6576 dev->irq = pci_dev->irq;
6578 IPW_DEBUG_INFO("Attempting to register device...\n");
6580 SET_MODULE_OWNER(dev);
6582 printk(KERN_INFO DRV_NAME
6583 ": Detected Intel PRO/Wireless 2100 Network Connection\n");
6585 /* Bring up the interface. Pre 0.46, after we registered the
6586 * network device we would call ipw2100_up. This introduced a race
6587 * condition with newer hotplug configurations (network was coming
6588 * up and making calls before the device was initialized).
6590 * If we called ipw2100_up before we registered the device, then the
6591 * device name wasn't registered. So, we instead use the net_dev->init
6592 * member to call a function that then just turns and calls ipw2100_up.
6593 * net_dev->init is called after name allocation but before the
6594 * notifier chain is called */
6595 down(&priv->action_sem);
6596 err = register_netdev(dev);
6598 printk(KERN_WARNING DRV_NAME
6599 "Error calling register_netdev.\n");
6604 IPW_DEBUG_INFO("%s: Bound to %s\n", dev->name, pci_name(pci_dev));
6606 /* perform this after register_netdev so that dev->name is set */
6607 sysfs_create_group(&pci_dev->dev.kobj, &ipw2100_attribute_group);
6608 netif_carrier_off(dev);
6610 /* If the RF Kill switch is disabled, go ahead and complete the
6611 * startup sequence */
6612 if (!(priv->status & STATUS_RF_KILL_MASK)) {
6613 /* Enable the adapter - sends HOST_COMPLETE */
6614 if (ipw2100_enable_adapter(priv)) {
6615 printk(KERN_WARNING DRV_NAME
6616 ": %s: failed in call to enable adapter.\n",
6617 priv->net_dev->name);
6618 ipw2100_hw_stop_adapter(priv);
6623 /* Start a scan . . . */
6624 ipw2100_set_scan_options(priv);
6625 ipw2100_start_scan(priv);
6628 IPW_DEBUG_INFO("exit\n");
6630 priv->status |= STATUS_INITIALIZED;
6632 up(&priv->action_sem);
6637 up(&priv->action_sem);
6642 unregister_netdev(dev);
6644 ipw2100_hw_stop_adapter(priv);
6646 ipw2100_disable_interrupts(priv);
6649 free_irq(dev->irq, priv);
6651 ipw2100_kill_workqueue(priv);
6653 /* These are safe to call even if they weren't allocated */
6654 ipw2100_queues_free(priv);
6655 sysfs_remove_group(&pci_dev->dev.kobj, &ipw2100_attribute_group);
6657 free_ieee80211(dev);
6658 pci_set_drvdata(pci_dev, NULL);
6664 pci_release_regions(pci_dev);
6665 pci_disable_device(pci_dev);
6670 static void __devexit ipw2100_pci_remove_one(struct pci_dev *pci_dev)
6672 struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
6673 struct net_device *dev;
6676 down(&priv->action_sem);
6678 priv->status &= ~STATUS_INITIALIZED;
6680 dev = priv->net_dev;
6681 sysfs_remove_group(&pci_dev->dev.kobj, &ipw2100_attribute_group);
6684 if (ipw2100_firmware.version)
6685 ipw2100_release_firmware(priv, &ipw2100_firmware);
6687 /* Take down the hardware */
6690 /* Release the semaphore so that the network subsystem can
6691 * complete any needed calls into the driver... */
6692 up(&priv->action_sem);
6694 /* Unregister the device first - this results in close()
6695 * being called if the device is open. If we free storage
6696 * first, then close() will crash. */
6697 unregister_netdev(dev);
6699 /* ipw2100_down will ensure that there is no more pending work
6700 * in the workqueue's, so we can safely remove them now. */
6701 ipw2100_kill_workqueue(priv);
6703 ipw2100_queues_free(priv);
6705 /* Free potential debugging firmware snapshot */
6706 ipw2100_snapshot_free(priv);
6709 free_irq(dev->irq, priv);
6712 iounmap((void __iomem *)dev->base_addr);
6714 free_ieee80211(dev);
6717 pci_release_regions(pci_dev);
6718 pci_disable_device(pci_dev);
6720 IPW_DEBUG_INFO("exit\n");
6725 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11)
6726 static int ipw2100_suspend(struct pci_dev *pci_dev, u32 state)
6728 static int ipw2100_suspend(struct pci_dev *pci_dev, pm_message_t state)
6731 struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
6732 struct net_device *dev = priv->net_dev;
6734 IPW_DEBUG_INFO("%s: Going into suspend...\n",
6737 down(&priv->action_sem);
6738 if (priv->status & STATUS_INITIALIZED) {
6739 /* Take down the device; powers it off, etc. */
6743 /* Remove the PRESENT state of the device */
6744 netif_device_detach(dev);
6746 pci_save_state(pci_dev);
6747 pci_disable_device (pci_dev);
6748 pci_set_power_state(pci_dev, PCI_D3hot);
6750 up(&priv->action_sem);
6755 static int ipw2100_resume(struct pci_dev *pci_dev)
6757 struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
6758 struct net_device *dev = priv->net_dev;
6761 if (IPW2100_PM_DISABLED)
6764 down(&priv->action_sem);
6766 IPW_DEBUG_INFO("%s: Coming out of suspend...\n",
6769 pci_set_power_state(pci_dev, PCI_D0);
6770 pci_enable_device(pci_dev);
6771 pci_restore_state(pci_dev);
6774 * Suspend/Resume resets the PCI configuration space, so we have to
6775 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
6776 * from interfering with C3 CPU state. pci_restore_state won't help
6777 * here since it only restores the first 64 bytes pci config header.
6779 pci_read_config_dword(pci_dev, 0x40, &val);
6780 if ((val & 0x0000ff00) != 0)
6781 pci_write_config_dword(pci_dev, 0x40, val & 0xffff00ff);
6783 /* Set the device back into the PRESENT state; this will also wake
6784 * the queue of needed */
6785 netif_device_attach(dev);
6787 /* Bring the device back up */
6788 if (!(priv->status & STATUS_RF_KILL_SW))
6789 ipw2100_up(priv, 0);
6791 up(&priv->action_sem);
6798 #define IPW2100_DEV_ID(x) { PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, x }
6800 static struct pci_device_id ipw2100_pci_id_table[] __devinitdata = {
6801 IPW2100_DEV_ID(0x2520), /* IN 2100A mPCI 3A */
6802 IPW2100_DEV_ID(0x2521), /* IN 2100A mPCI 3B */
6803 IPW2100_DEV_ID(0x2524), /* IN 2100A mPCI 3B */
6804 IPW2100_DEV_ID(0x2525), /* IN 2100A mPCI 3B */
6805 IPW2100_DEV_ID(0x2526), /* IN 2100A mPCI Gen A3 */
6806 IPW2100_DEV_ID(0x2522), /* IN 2100 mPCI 3B */
6807 IPW2100_DEV_ID(0x2523), /* IN 2100 mPCI 3A */
6808 IPW2100_DEV_ID(0x2527), /* IN 2100 mPCI 3B */
6809 IPW2100_DEV_ID(0x2528), /* IN 2100 mPCI 3B */
6810 IPW2100_DEV_ID(0x2529), /* IN 2100 mPCI 3B */
6811 IPW2100_DEV_ID(0x252B), /* IN 2100 mPCI 3A */
6812 IPW2100_DEV_ID(0x252C), /* IN 2100 mPCI 3A */
6813 IPW2100_DEV_ID(0x252D), /* IN 2100 mPCI 3A */
6815 IPW2100_DEV_ID(0x2550), /* IB 2100A mPCI 3B */
6816 IPW2100_DEV_ID(0x2551), /* IB 2100 mPCI 3B */
6817 IPW2100_DEV_ID(0x2553), /* IB 2100 mPCI 3B */
6818 IPW2100_DEV_ID(0x2554), /* IB 2100 mPCI 3B */
6819 IPW2100_DEV_ID(0x2555), /* IB 2100 mPCI 3B */
6821 IPW2100_DEV_ID(0x2560), /* DE 2100A mPCI 3A */
6822 IPW2100_DEV_ID(0x2562), /* DE 2100A mPCI 3A */
6823 IPW2100_DEV_ID(0x2563), /* DE 2100A mPCI 3A */
6824 IPW2100_DEV_ID(0x2561), /* DE 2100 mPCI 3A */
6825 IPW2100_DEV_ID(0x2565), /* DE 2100 mPCI 3A */
6826 IPW2100_DEV_ID(0x2566), /* DE 2100 mPCI 3A */
6827 IPW2100_DEV_ID(0x2567), /* DE 2100 mPCI 3A */
6829 IPW2100_DEV_ID(0x2570), /* GA 2100 mPCI 3B */
6831 IPW2100_DEV_ID(0x2580), /* TO 2100A mPCI 3B */
6832 IPW2100_DEV_ID(0x2582), /* TO 2100A mPCI 3B */
6833 IPW2100_DEV_ID(0x2583), /* TO 2100A mPCI 3B */
6834 IPW2100_DEV_ID(0x2581), /* TO 2100 mPCI 3B */
6835 IPW2100_DEV_ID(0x2585), /* TO 2100 mPCI 3B */
6836 IPW2100_DEV_ID(0x2586), /* TO 2100 mPCI 3B */
6837 IPW2100_DEV_ID(0x2587), /* TO 2100 mPCI 3B */
6839 IPW2100_DEV_ID(0x2590), /* SO 2100A mPCI 3B */
6840 IPW2100_DEV_ID(0x2592), /* SO 2100A mPCI 3B */
6841 IPW2100_DEV_ID(0x2591), /* SO 2100 mPCI 3B */
6842 IPW2100_DEV_ID(0x2593), /* SO 2100 mPCI 3B */
6843 IPW2100_DEV_ID(0x2596), /* SO 2100 mPCI 3B */
6844 IPW2100_DEV_ID(0x2598), /* SO 2100 mPCI 3B */
6846 IPW2100_DEV_ID(0x25A0), /* HP 2100 mPCI 3B */
6850 MODULE_DEVICE_TABLE(pci, ipw2100_pci_id_table);
6852 static struct pci_driver ipw2100_pci_driver = {
6854 .id_table = ipw2100_pci_id_table,
6855 .probe = ipw2100_pci_init_one,
6856 .remove = __devexit_p(ipw2100_pci_remove_one),
6858 .suspend = ipw2100_suspend,
6859 .resume = ipw2100_resume,
6865 * Initialize the ipw2100 driver/module
6867 * @returns 0 if ok, < 0 errno node con error.
6869 * Note: we cannot init the /proc stuff until the PCI driver is there,
6870 * or we risk an unlikely race condition on someone accessing
6871 * uninitialized data in the PCI dev struct through /proc.
6873 static int __init ipw2100_init(void)
6877 printk(KERN_INFO DRV_NAME ": %s, %s\n", DRV_DESCRIPTION, DRV_VERSION);
6878 printk(KERN_INFO DRV_NAME ": %s\n", DRV_COPYRIGHT);
6880 #ifdef CONFIG_IEEE80211_NOWEP
6881 IPW_DEBUG_INFO(DRV_NAME ": Compiled with WEP disabled.\n");
6884 ret = pci_module_init(&ipw2100_pci_driver);
6886 #ifdef CONFIG_IPW_DEBUG
6887 ipw2100_debug_level = debug;
6888 driver_create_file(&ipw2100_pci_driver.driver,
6889 &driver_attr_debug_level);
6897 * Cleanup ipw2100 driver registration
6899 static void __exit ipw2100_exit(void)
6901 /* FIXME: IPG: check that we have no instances of the devices open */
6902 #ifdef CONFIG_IPW_DEBUG
6903 driver_remove_file(&ipw2100_pci_driver.driver,
6904 &driver_attr_debug_level);
6906 pci_unregister_driver(&ipw2100_pci_driver);
6909 module_init(ipw2100_init);
6910 module_exit(ipw2100_exit);
6912 #define WEXT_USECHANNELS 1
6914 static const long ipw2100_frequencies[] = {
6915 2412, 2417, 2422, 2427,
6916 2432, 2437, 2442, 2447,
6917 2452, 2457, 2462, 2467,
6921 #define FREQ_COUNT (sizeof(ipw2100_frequencies) / \
6922 sizeof(ipw2100_frequencies[0]))
6924 static const long ipw2100_rates_11b[] = {
6931 #define RATE_COUNT (sizeof(ipw2100_rates_11b) / sizeof(ipw2100_rates_11b[0]))
6933 static int ipw2100_wx_get_name(struct net_device *dev,
6934 struct iw_request_info *info,
6935 union iwreq_data *wrqu, char *extra)
6938 * This can be called at any time. No action lock required
6941 struct ipw2100_priv *priv = ieee80211_priv(dev);
6942 if (!(priv->status & STATUS_ASSOCIATED))
6943 strcpy(wrqu->name, "unassociated");
6945 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11b");
6947 IPW_DEBUG_WX("Name: %s\n", wrqu->name);
6952 static int ipw2100_wx_set_freq(struct net_device *dev,
6953 struct iw_request_info *info,
6954 union iwreq_data *wrqu, char *extra)
6956 struct ipw2100_priv *priv = ieee80211_priv(dev);
6957 struct iw_freq *fwrq = &wrqu->freq;
6960 if (priv->ieee->iw_mode == IW_MODE_INFRA)
6963 down(&priv->action_sem);
6964 if (!(priv->status & STATUS_INITIALIZED)) {
6969 /* if setting by freq convert to channel */
6971 if ((fwrq->m >= (int) 2.412e8 &&
6972 fwrq->m <= (int) 2.487e8)) {
6973 int f = fwrq->m / 100000;
6976 while ((c < REG_MAX_CHANNEL) &&
6977 (f != ipw2100_frequencies[c]))
6980 /* hack to fall through */
6986 if (fwrq->e > 0 || fwrq->m > 1000)
6988 else { /* Set the channel */
6989 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
6990 err = ipw2100_set_channel(priv, fwrq->m, 0);
6994 up(&priv->action_sem);
6999 static int ipw2100_wx_get_freq(struct net_device *dev,
7000 struct iw_request_info *info,
7001 union iwreq_data *wrqu, char *extra)
7004 * This can be called at any time. No action lock required
7007 struct ipw2100_priv *priv = ieee80211_priv(dev);
7011 /* If we are associated, trying to associate, or have a statically
7012 * configured CHANNEL then return that; otherwise return ANY */
7013 if (priv->config & CFG_STATIC_CHANNEL ||
7014 priv->status & STATUS_ASSOCIATED)
7015 wrqu->freq.m = priv->channel;
7019 IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
7024 static int ipw2100_wx_set_mode(struct net_device *dev,
7025 struct iw_request_info *info,
7026 union iwreq_data *wrqu, char *extra)
7028 struct ipw2100_priv *priv = ieee80211_priv(dev);
7031 IPW_DEBUG_WX("SET Mode -> %d \n", wrqu->mode);
7033 if (wrqu->mode == priv->ieee->iw_mode)
7036 down(&priv->action_sem);
7037 if (!(priv->status & STATUS_INITIALIZED)) {
7042 switch (wrqu->mode) {
7043 #ifdef CONFIG_IPW2100_MONITOR
7044 case IW_MODE_MONITOR:
7045 err = ipw2100_switch_mode(priv, IW_MODE_MONITOR);
7047 #endif /* CONFIG_IPW2100_MONITOR */
7049 err = ipw2100_switch_mode(priv, IW_MODE_ADHOC);
7054 err = ipw2100_switch_mode(priv, IW_MODE_INFRA);
7059 up(&priv->action_sem);
7063 static int ipw2100_wx_get_mode(struct net_device *dev,
7064 struct iw_request_info *info,
7065 union iwreq_data *wrqu, char *extra)
7068 * This can be called at any time. No action lock required
7071 struct ipw2100_priv *priv = ieee80211_priv(dev);
7073 wrqu->mode = priv->ieee->iw_mode;
7074 IPW_DEBUG_WX("GET Mode -> %d\n", wrqu->mode);
7080 #define POWER_MODES 5
7082 /* Values are in microsecond */
7083 static const s32 timeout_duration[POWER_MODES] = {
7091 static const s32 period_duration[POWER_MODES] = {
7099 static int ipw2100_wx_get_range(struct net_device *dev,
7100 struct iw_request_info *info,
7101 union iwreq_data *wrqu, char *extra)
7104 * This can be called at any time. No action lock required
7107 struct ipw2100_priv *priv = ieee80211_priv(dev);
7108 struct iw_range *range = (struct iw_range *)extra;
7112 wrqu->data.length = sizeof(*range);
7113 memset(range, 0, sizeof(*range));
7115 /* Let's try to keep this struct in the same order as in
7116 * linux/include/wireless.h
7119 /* TODO: See what values we can set, and remove the ones we can't
7120 * set, or fill them with some default data.
7123 /* ~5 Mb/s real (802.11b) */
7124 range->throughput = 5 * 1000 * 1000;
7126 // range->sensitivity; /* signal level threshold range */
7128 range->max_qual.qual = 100;
7129 /* TODO: Find real max RSSI and stick here */
7130 range->max_qual.level = 0;
7131 range->max_qual.noise = 0;
7132 range->max_qual.updated = 7; /* Updated all three */
7134 range->avg_qual.qual = 70; /* > 8% missed beacons is 'bad' */
7135 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
7136 range->avg_qual.level = 20 + IPW2100_RSSI_TO_DBM;
7137 range->avg_qual.noise = 0;
7138 range->avg_qual.updated = 7; /* Updated all three */
7140 range->num_bitrates = RATE_COUNT;
7142 for (i = 0; i < RATE_COUNT && i < IW_MAX_BITRATES; i++) {
7143 range->bitrate[i] = ipw2100_rates_11b[i];
7146 range->min_rts = MIN_RTS_THRESHOLD;
7147 range->max_rts = MAX_RTS_THRESHOLD;
7148 range->min_frag = MIN_FRAG_THRESHOLD;
7149 range->max_frag = MAX_FRAG_THRESHOLD;
7151 range->min_pmp = period_duration[0]; /* Minimal PM period */
7152 range->max_pmp = period_duration[POWER_MODES-1];/* Maximal PM period */
7153 range->min_pmt = timeout_duration[POWER_MODES-1]; /* Minimal PM timeout */
7154 range->max_pmt = timeout_duration[0];/* Maximal PM timeout */
7156 /* How to decode max/min PM period */
7157 range->pmp_flags = IW_POWER_PERIOD;
7158 /* How to decode max/min PM period */
7159 range->pmt_flags = IW_POWER_TIMEOUT;
7160 /* What PM options are supported */
7161 range->pm_capa = IW_POWER_TIMEOUT | IW_POWER_PERIOD;
7163 range->encoding_size[0] = 5;
7164 range->encoding_size[1] = 13; /* Different token sizes */
7165 range->num_encoding_sizes = 2; /* Number of entry in the list */
7166 range->max_encoding_tokens = WEP_KEYS; /* Max number of tokens */
7167 // range->encoding_login_index; /* token index for login token */
7169 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7170 range->txpower_capa = IW_TXPOW_DBM;
7171 range->num_txpower = IW_MAX_TXPOWER;
7172 for (i = 0, level = (IPW_TX_POWER_MAX_DBM * 16); i < IW_MAX_TXPOWER;
7173 i++, level -= ((IPW_TX_POWER_MAX_DBM - IPW_TX_POWER_MIN_DBM) * 16) /
7174 (IW_MAX_TXPOWER - 1))
7175 range->txpower[i] = level / 16;
7177 range->txpower_capa = 0;
7178 range->num_txpower = 0;
7182 /* Set the Wireless Extension versions */
7183 range->we_version_compiled = WIRELESS_EXT;
7184 range->we_version_source = 16;
7186 // range->retry_capa; /* What retry options are supported */
7187 // range->retry_flags; /* How to decode max/min retry limit */
7188 // range->r_time_flags; /* How to decode max/min retry life */
7189 // range->min_retry; /* Minimal number of retries */
7190 // range->max_retry; /* Maximal number of retries */
7191 // range->min_r_time; /* Minimal retry lifetime */
7192 // range->max_r_time; /* Maximal retry lifetime */
7194 range->num_channels = FREQ_COUNT;
7197 for (i = 0; i < FREQ_COUNT; i++) {
7198 // TODO: Include only legal frequencies for some countries
7199 // if (local->channel_mask & (1 << i)) {
7200 range->freq[val].i = i + 1;
7201 range->freq[val].m = ipw2100_frequencies[i] * 100000;
7202 range->freq[val].e = 1;
7205 if (val == IW_MAX_FREQUENCIES)
7208 range->num_frequency = val;
7210 IPW_DEBUG_WX("GET Range\n");
7215 static int ipw2100_wx_set_wap(struct net_device *dev,
7216 struct iw_request_info *info,
7217 union iwreq_data *wrqu, char *extra)
7219 struct ipw2100_priv *priv = ieee80211_priv(dev);
7222 static const unsigned char any[] = {
7223 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
7225 static const unsigned char off[] = {
7226 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
7230 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
7233 down(&priv->action_sem);
7234 if (!(priv->status & STATUS_INITIALIZED)) {
7239 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
7240 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
7241 /* we disable mandatory BSSID association */
7242 IPW_DEBUG_WX("exit - disable mandatory BSSID\n");
7243 priv->config &= ~CFG_STATIC_BSSID;
7244 err = ipw2100_set_mandatory_bssid(priv, NULL, 0);
7248 priv->config |= CFG_STATIC_BSSID;
7249 memcpy(priv->mandatory_bssid_mac, wrqu->ap_addr.sa_data, ETH_ALEN);
7251 err = ipw2100_set_mandatory_bssid(priv, wrqu->ap_addr.sa_data, 0);
7253 IPW_DEBUG_WX("SET BSSID -> %02X:%02X:%02X:%02X:%02X:%02X\n",
7254 wrqu->ap_addr.sa_data[0] & 0xff,
7255 wrqu->ap_addr.sa_data[1] & 0xff,
7256 wrqu->ap_addr.sa_data[2] & 0xff,
7257 wrqu->ap_addr.sa_data[3] & 0xff,
7258 wrqu->ap_addr.sa_data[4] & 0xff,
7259 wrqu->ap_addr.sa_data[5] & 0xff);
7262 up(&priv->action_sem);
7266 static int ipw2100_wx_get_wap(struct net_device *dev,
7267 struct iw_request_info *info,
7268 union iwreq_data *wrqu, char *extra)
7271 * This can be called at any time. No action lock required
7274 struct ipw2100_priv *priv = ieee80211_priv(dev);
7276 /* If we are associated, trying to associate, or have a statically
7277 * configured BSSID then return that; otherwise return ANY */
7278 if (priv->config & CFG_STATIC_BSSID ||
7279 priv->status & STATUS_ASSOCIATED) {
7280 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
7281 memcpy(wrqu->ap_addr.sa_data, &priv->bssid, ETH_ALEN);
7283 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
7285 IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n",
7286 MAC_ARG(wrqu->ap_addr.sa_data));
7290 static int ipw2100_wx_set_essid(struct net_device *dev,
7291 struct iw_request_info *info,
7292 union iwreq_data *wrqu, char *extra)
7294 struct ipw2100_priv *priv = ieee80211_priv(dev);
7295 char *essid = ""; /* ANY */
7299 down(&priv->action_sem);
7300 if (!(priv->status & STATUS_INITIALIZED)) {
7305 if (wrqu->essid.flags && wrqu->essid.length) {
7306 length = wrqu->essid.length - 1;
7311 IPW_DEBUG_WX("Setting ESSID to ANY\n");
7312 priv->config &= ~CFG_STATIC_ESSID;
7313 err = ipw2100_set_essid(priv, NULL, 0, 0);
7317 length = min(length, IW_ESSID_MAX_SIZE);
7319 priv->config |= CFG_STATIC_ESSID;
7321 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
7322 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
7327 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length),
7330 priv->essid_len = length;
7331 memcpy(priv->essid, essid, priv->essid_len);
7333 err = ipw2100_set_essid(priv, essid, length, 0);
7336 up(&priv->action_sem);
7340 static int ipw2100_wx_get_essid(struct net_device *dev,
7341 struct iw_request_info *info,
7342 union iwreq_data *wrqu, char *extra)
7345 * This can be called at any time. No action lock required
7348 struct ipw2100_priv *priv = ieee80211_priv(dev);
7350 /* If we are associated, trying to associate, or have a statically
7351 * configured ESSID then return that; otherwise return ANY */
7352 if (priv->config & CFG_STATIC_ESSID ||
7353 priv->status & STATUS_ASSOCIATED) {
7354 IPW_DEBUG_WX("Getting essid: '%s'\n",
7355 escape_essid(priv->essid, priv->essid_len));
7356 memcpy(extra, priv->essid, priv->essid_len);
7357 wrqu->essid.length = priv->essid_len;
7358 wrqu->essid.flags = 1; /* active */
7360 IPW_DEBUG_WX("Getting essid: ANY\n");
7361 wrqu->essid.length = 0;
7362 wrqu->essid.flags = 0; /* active */
7368 static int ipw2100_wx_set_nick(struct net_device *dev,
7369 struct iw_request_info *info,
7370 union iwreq_data *wrqu, char *extra)
7373 * This can be called at any time. No action lock required
7376 struct ipw2100_priv *priv = ieee80211_priv(dev);
7378 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
7381 wrqu->data.length = min((size_t)wrqu->data.length, sizeof(priv->nick));
7382 memset(priv->nick, 0, sizeof(priv->nick));
7383 memcpy(priv->nick, extra, wrqu->data.length);
7385 IPW_DEBUG_WX("SET Nickname -> %s \n", priv->nick);
7390 static int ipw2100_wx_get_nick(struct net_device *dev,
7391 struct iw_request_info *info,
7392 union iwreq_data *wrqu, char *extra)
7395 * This can be called at any time. No action lock required
7398 struct ipw2100_priv *priv = ieee80211_priv(dev);
7400 wrqu->data.length = strlen(priv->nick) + 1;
7401 memcpy(extra, priv->nick, wrqu->data.length);
7402 wrqu->data.flags = 1; /* active */
7404 IPW_DEBUG_WX("GET Nickname -> %s \n", extra);
7409 static int ipw2100_wx_set_rate(struct net_device *dev,
7410 struct iw_request_info *info,
7411 union iwreq_data *wrqu, char *extra)
7413 struct ipw2100_priv *priv = ieee80211_priv(dev);
7414 u32 target_rate = wrqu->bitrate.value;
7418 down(&priv->action_sem);
7419 if (!(priv->status & STATUS_INITIALIZED)) {
7426 if (target_rate == 1000000 ||
7427 (!wrqu->bitrate.fixed && target_rate > 1000000))
7428 rate |= TX_RATE_1_MBIT;
7429 if (target_rate == 2000000 ||
7430 (!wrqu->bitrate.fixed && target_rate > 2000000))
7431 rate |= TX_RATE_2_MBIT;
7432 if (target_rate == 5500000 ||
7433 (!wrqu->bitrate.fixed && target_rate > 5500000))
7434 rate |= TX_RATE_5_5_MBIT;
7435 if (target_rate == 11000000 ||
7436 (!wrqu->bitrate.fixed && target_rate > 11000000))
7437 rate |= TX_RATE_11_MBIT;
7439 rate = DEFAULT_TX_RATES;
7441 err = ipw2100_set_tx_rates(priv, rate, 0);
7443 IPW_DEBUG_WX("SET Rate -> %04X \n", rate);
7445 up(&priv->action_sem);
7450 static int ipw2100_wx_get_rate(struct net_device *dev,
7451 struct iw_request_info *info,
7452 union iwreq_data *wrqu, char *extra)
7454 struct ipw2100_priv *priv = ieee80211_priv(dev);
7456 int len = sizeof(val);
7459 if (!(priv->status & STATUS_ENABLED) ||
7460 priv->status & STATUS_RF_KILL_MASK ||
7461 !(priv->status & STATUS_ASSOCIATED)) {
7462 wrqu->bitrate.value = 0;
7466 down(&priv->action_sem);
7467 if (!(priv->status & STATUS_INITIALIZED)) {
7472 err = ipw2100_get_ordinal(priv, IPW_ORD_CURRENT_TX_RATE, &val, &len);
7474 IPW_DEBUG_WX("failed querying ordinals.\n");
7478 switch (val & TX_RATE_MASK) {
7479 case TX_RATE_1_MBIT:
7480 wrqu->bitrate.value = 1000000;
7482 case TX_RATE_2_MBIT:
7483 wrqu->bitrate.value = 2000000;
7485 case TX_RATE_5_5_MBIT:
7486 wrqu->bitrate.value = 5500000;
7488 case TX_RATE_11_MBIT:
7489 wrqu->bitrate.value = 11000000;
7492 wrqu->bitrate.value = 0;
7495 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
7498 up(&priv->action_sem);
7502 static int ipw2100_wx_set_rts(struct net_device *dev,
7503 struct iw_request_info *info,
7504 union iwreq_data *wrqu, char *extra)
7506 struct ipw2100_priv *priv = ieee80211_priv(dev);
7509 /* Auto RTS not yet supported */
7510 if (wrqu->rts.fixed == 0)
7513 down(&priv->action_sem);
7514 if (!(priv->status & STATUS_INITIALIZED)) {
7519 if (wrqu->rts.disabled)
7520 value = priv->rts_threshold | RTS_DISABLED;
7522 if (wrqu->rts.value < 1 ||
7523 wrqu->rts.value > 2304) {
7527 value = wrqu->rts.value;
7530 err = ipw2100_set_rts_threshold(priv, value);
7532 IPW_DEBUG_WX("SET RTS Threshold -> 0x%08X \n", value);
7534 up(&priv->action_sem);
7538 static int ipw2100_wx_get_rts(struct net_device *dev,
7539 struct iw_request_info *info,
7540 union iwreq_data *wrqu, char *extra)
7543 * This can be called at any time. No action lock required
7546 struct ipw2100_priv *priv = ieee80211_priv(dev);
7548 wrqu->rts.value = priv->rts_threshold & ~RTS_DISABLED;
7549 wrqu->rts.fixed = 1; /* no auto select */
7551 /* If RTS is set to the default value, then it is disabled */
7552 wrqu->rts.disabled = (priv->rts_threshold & RTS_DISABLED) ? 1 : 0;
7554 IPW_DEBUG_WX("GET RTS Threshold -> 0x%08X \n", wrqu->rts.value);
7559 static int ipw2100_wx_set_txpow(struct net_device *dev,
7560 struct iw_request_info *info,
7561 union iwreq_data *wrqu, char *extra)
7563 struct ipw2100_priv *priv = ieee80211_priv(dev);
7566 if (priv->ieee->iw_mode != IW_MODE_ADHOC)
7569 if (wrqu->txpower.disabled == 1 || wrqu->txpower.fixed == 0)
7570 value = IPW_TX_POWER_DEFAULT;
7572 if (wrqu->txpower.value < IPW_TX_POWER_MIN_DBM ||
7573 wrqu->txpower.value > IPW_TX_POWER_MAX_DBM)
7576 value = (wrqu->txpower.value - IPW_TX_POWER_MIN_DBM) * 16 /
7577 (IPW_TX_POWER_MAX_DBM - IPW_TX_POWER_MIN_DBM);
7580 down(&priv->action_sem);
7581 if (!(priv->status & STATUS_INITIALIZED)) {
7586 err = ipw2100_set_tx_power(priv, value);
7588 IPW_DEBUG_WX("SET TX Power -> %d \n", value);
7591 up(&priv->action_sem);
7595 static int ipw2100_wx_get_txpow(struct net_device *dev,
7596 struct iw_request_info *info,
7597 union iwreq_data *wrqu, char *extra)
7600 * This can be called at any time. No action lock required
7603 struct ipw2100_priv *priv = ieee80211_priv(dev);
7605 if (priv->ieee->iw_mode != IW_MODE_ADHOC) {
7606 wrqu->power.disabled = 1;
7610 if (priv->tx_power == IPW_TX_POWER_DEFAULT) {
7611 wrqu->power.fixed = 0;
7612 wrqu->power.value = IPW_TX_POWER_MAX_DBM;
7613 wrqu->power.disabled = 1;
7615 wrqu->power.disabled = 0;
7616 wrqu->power.fixed = 1;
7619 (IPW_TX_POWER_MAX_DBM - IPW_TX_POWER_MIN_DBM)) /
7620 (IPW_TX_POWER_MAX - IPW_TX_POWER_MIN) +
7621 IPW_TX_POWER_MIN_DBM;
7624 wrqu->power.flags = IW_TXPOW_DBM;
7626 IPW_DEBUG_WX("GET TX Power -> %d \n", wrqu->power.value);
7631 static int ipw2100_wx_set_frag(struct net_device *dev,
7632 struct iw_request_info *info,
7633 union iwreq_data *wrqu, char *extra)
7636 * This can be called at any time. No action lock required
7639 struct ipw2100_priv *priv = ieee80211_priv(dev);
7641 if (!wrqu->frag.fixed)
7644 if (wrqu->frag.disabled) {
7645 priv->frag_threshold |= FRAG_DISABLED;
7646 priv->ieee->fts = DEFAULT_FTS;
7648 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
7649 wrqu->frag.value > MAX_FRAG_THRESHOLD)
7652 priv->ieee->fts = wrqu->frag.value & ~0x1;
7653 priv->frag_threshold = priv->ieee->fts;
7656 IPW_DEBUG_WX("SET Frag Threshold -> %d \n", priv->ieee->fts);
7661 static int ipw2100_wx_get_frag(struct net_device *dev,
7662 struct iw_request_info *info,
7663 union iwreq_data *wrqu, char *extra)
7666 * This can be called at any time. No action lock required
7669 struct ipw2100_priv *priv = ieee80211_priv(dev);
7670 wrqu->frag.value = priv->frag_threshold & ~FRAG_DISABLED;
7671 wrqu->frag.fixed = 0; /* no auto select */
7672 wrqu->frag.disabled = (priv->frag_threshold & FRAG_DISABLED) ? 1 : 0;
7674 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
7679 static int ipw2100_wx_set_retry(struct net_device *dev,
7680 struct iw_request_info *info,
7681 union iwreq_data *wrqu, char *extra)
7683 struct ipw2100_priv *priv = ieee80211_priv(dev);
7686 if (wrqu->retry.flags & IW_RETRY_LIFETIME ||
7687 wrqu->retry.disabled)
7690 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
7693 down(&priv->action_sem);
7694 if (!(priv->status & STATUS_INITIALIZED)) {
7699 if (wrqu->retry.flags & IW_RETRY_MIN) {
7700 err = ipw2100_set_short_retry(priv, wrqu->retry.value);
7701 IPW_DEBUG_WX("SET Short Retry Limit -> %d \n",
7706 if (wrqu->retry.flags & IW_RETRY_MAX) {
7707 err = ipw2100_set_long_retry(priv, wrqu->retry.value);
7708 IPW_DEBUG_WX("SET Long Retry Limit -> %d \n",
7713 err = ipw2100_set_short_retry(priv, wrqu->retry.value);
7715 err = ipw2100_set_long_retry(priv, wrqu->retry.value);
7717 IPW_DEBUG_WX("SET Both Retry Limits -> %d \n", wrqu->retry.value);
7720 up(&priv->action_sem);
7724 static int ipw2100_wx_get_retry(struct net_device *dev,
7725 struct iw_request_info *info,
7726 union iwreq_data *wrqu, char *extra)
7729 * This can be called at any time. No action lock required
7732 struct ipw2100_priv *priv = ieee80211_priv(dev);
7734 wrqu->retry.disabled = 0; /* can't be disabled */
7736 if ((wrqu->retry.flags & IW_RETRY_TYPE) ==
7740 if (wrqu->retry.flags & IW_RETRY_MAX) {
7741 wrqu->retry.flags = IW_RETRY_LIMIT & IW_RETRY_MAX;
7742 wrqu->retry.value = priv->long_retry_limit;
7745 (priv->short_retry_limit !=
7746 priv->long_retry_limit) ?
7747 IW_RETRY_LIMIT & IW_RETRY_MIN : IW_RETRY_LIMIT;
7749 wrqu->retry.value = priv->short_retry_limit;
7752 IPW_DEBUG_WX("GET Retry -> %d \n", wrqu->retry.value);
7757 static int ipw2100_wx_set_scan(struct net_device *dev,
7758 struct iw_request_info *info,
7759 union iwreq_data *wrqu, char *extra)
7761 struct ipw2100_priv *priv = ieee80211_priv(dev);
7764 down(&priv->action_sem);
7765 if (!(priv->status & STATUS_INITIALIZED)) {
7770 IPW_DEBUG_WX("Initiating scan...\n");
7771 if (ipw2100_set_scan_options(priv) ||
7772 ipw2100_start_scan(priv)) {
7773 IPW_DEBUG_WX("Start scan failed.\n");
7775 /* TODO: Mark a scan as pending so when hardware initialized
7780 up(&priv->action_sem);
7784 static int ipw2100_wx_get_scan(struct net_device *dev,
7785 struct iw_request_info *info,
7786 union iwreq_data *wrqu, char *extra)
7789 * This can be called at any time. No action lock required
7792 struct ipw2100_priv *priv = ieee80211_priv(dev);
7793 return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra);
7798 * Implementation based on code in hostap-driver v0.1.3 hostap_ioctl.c
7800 static int ipw2100_wx_set_encode(struct net_device *dev,
7801 struct iw_request_info *info,
7802 union iwreq_data *wrqu, char *key)
7805 * No check of STATUS_INITIALIZED required
7808 struct ipw2100_priv *priv = ieee80211_priv(dev);
7809 return ieee80211_wx_set_encode(priv->ieee, info, wrqu, key);
7812 static int ipw2100_wx_get_encode(struct net_device *dev,
7813 struct iw_request_info *info,
7814 union iwreq_data *wrqu, char *key)
7817 * This can be called at any time. No action lock required
7820 struct ipw2100_priv *priv = ieee80211_priv(dev);
7821 return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key);
7824 static int ipw2100_wx_set_power(struct net_device *dev,
7825 struct iw_request_info *info,
7826 union iwreq_data *wrqu, char *extra)
7828 struct ipw2100_priv *priv = ieee80211_priv(dev);
7831 down(&priv->action_sem);
7832 if (!(priv->status & STATUS_INITIALIZED)) {
7837 if (wrqu->power.disabled) {
7838 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
7839 err = ipw2100_set_power_mode(priv, IPW_POWER_MODE_CAM);
7840 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
7844 switch (wrqu->power.flags & IW_POWER_MODE) {
7845 case IW_POWER_ON: /* If not specified */
7846 case IW_POWER_MODE: /* If set all mask */
7847 case IW_POWER_ALL_R: /* If explicitely state all */
7849 default: /* Otherwise we don't support it */
7850 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
7856 /* If the user hasn't specified a power management mode yet, default
7858 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
7859 err = ipw2100_set_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
7861 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n",
7865 up(&priv->action_sem);
7870 static int ipw2100_wx_get_power(struct net_device *dev,
7871 struct iw_request_info *info,
7872 union iwreq_data *wrqu, char *extra)
7875 * This can be called at any time. No action lock required
7878 struct ipw2100_priv *priv = ieee80211_priv(dev);
7880 if (!(priv->power_mode & IPW_POWER_ENABLED)) {
7881 wrqu->power.disabled = 1;
7883 wrqu->power.disabled = 0;
7884 wrqu->power.flags = 0;
7887 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
7898 #ifdef CONFIG_IPW2100_MONITOR
7899 static int ipw2100_wx_set_promisc(struct net_device *dev,
7900 struct iw_request_info *info,
7901 union iwreq_data *wrqu, char *extra)
7903 struct ipw2100_priv *priv = ieee80211_priv(dev);
7904 int *parms = (int *)extra;
7905 int enable = (parms[0] > 0);
7908 down(&priv->action_sem);
7909 if (!(priv->status & STATUS_INITIALIZED)) {
7915 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7916 err = ipw2100_set_channel(priv, parms[1], 0);
7919 priv->channel = parms[1];
7920 err = ipw2100_switch_mode(priv, IW_MODE_MONITOR);
7922 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
7923 err = ipw2100_switch_mode(priv, priv->last_mode);
7926 up(&priv->action_sem);
7930 static int ipw2100_wx_reset(struct net_device *dev,
7931 struct iw_request_info *info,
7932 union iwreq_data *wrqu, char *extra)
7934 struct ipw2100_priv *priv = ieee80211_priv(dev);
7935 if (priv->status & STATUS_INITIALIZED)
7936 schedule_reset(priv);
7942 static int ipw2100_wx_set_powermode(struct net_device *dev,
7943 struct iw_request_info *info,
7944 union iwreq_data *wrqu, char *extra)
7946 struct ipw2100_priv *priv = ieee80211_priv(dev);
7947 int err = 0, mode = *(int *)extra;
7949 down(&priv->action_sem);
7950 if (!(priv->status & STATUS_INITIALIZED)) {
7955 if ((mode < 1) || (mode > POWER_MODES))
7956 mode = IPW_POWER_AUTO;
7958 if (priv->power_mode != mode)
7959 err = ipw2100_set_power_mode(priv, mode);
7961 up(&priv->action_sem);
7965 #define MAX_POWER_STRING 80
7966 static int ipw2100_wx_get_powermode(struct net_device *dev,
7967 struct iw_request_info *info,
7968 union iwreq_data *wrqu, char *extra)
7971 * This can be called at any time. No action lock required
7974 struct ipw2100_priv *priv = ieee80211_priv(dev);
7975 int level = IPW_POWER_LEVEL(priv->power_mode);
7976 s32 timeout, period;
7978 if (!(priv->power_mode & IPW_POWER_ENABLED)) {
7979 snprintf(extra, MAX_POWER_STRING,
7980 "Power save level: %d (Off)", level);
7983 case IPW_POWER_MODE_CAM:
7984 snprintf(extra, MAX_POWER_STRING,
7985 "Power save level: %d (None)", level);
7987 case IPW_POWER_AUTO:
7988 snprintf(extra, MAX_POWER_STRING,
7989 "Power save level: %d (Auto)", 0);
7992 timeout = timeout_duration[level - 1] / 1000;
7993 period = period_duration[level - 1] / 1000;
7994 snprintf(extra, MAX_POWER_STRING,
7995 "Power save level: %d "
7996 "(Timeout %dms, Period %dms)",
7997 level, timeout, period);
8001 wrqu->data.length = strlen(extra) + 1;
8007 static int ipw2100_wx_set_preamble(struct net_device *dev,
8008 struct iw_request_info *info,
8009 union iwreq_data *wrqu, char *extra)
8011 struct ipw2100_priv *priv = ieee80211_priv(dev);
8012 int err, mode = *(int *)extra;
8014 down(&priv->action_sem);
8015 if (!(priv->status & STATUS_INITIALIZED)) {
8021 priv->config |= CFG_LONG_PREAMBLE;
8023 priv->config &= ~CFG_LONG_PREAMBLE;
8029 err = ipw2100_system_config(priv, 0);
8032 up(&priv->action_sem);
8036 static int ipw2100_wx_get_preamble(struct net_device *dev,
8037 struct iw_request_info *info,
8038 union iwreq_data *wrqu, char *extra)
8041 * This can be called at any time. No action lock required
8044 struct ipw2100_priv *priv = ieee80211_priv(dev);
8046 if (priv->config & CFG_LONG_PREAMBLE)
8047 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
8049 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
8054 static iw_handler ipw2100_wx_handlers[] =
8056 NULL, /* SIOCSIWCOMMIT */
8057 ipw2100_wx_get_name, /* SIOCGIWNAME */
8058 NULL, /* SIOCSIWNWID */
8059 NULL, /* SIOCGIWNWID */
8060 ipw2100_wx_set_freq, /* SIOCSIWFREQ */
8061 ipw2100_wx_get_freq, /* SIOCGIWFREQ */
8062 ipw2100_wx_set_mode, /* SIOCSIWMODE */
8063 ipw2100_wx_get_mode, /* SIOCGIWMODE */
8064 NULL, /* SIOCSIWSENS */
8065 NULL, /* SIOCGIWSENS */
8066 NULL, /* SIOCSIWRANGE */
8067 ipw2100_wx_get_range, /* SIOCGIWRANGE */
8068 NULL, /* SIOCSIWPRIV */
8069 NULL, /* SIOCGIWPRIV */
8070 NULL, /* SIOCSIWSTATS */
8071 NULL, /* SIOCGIWSTATS */
8072 NULL, /* SIOCSIWSPY */
8073 NULL, /* SIOCGIWSPY */
8074 NULL, /* SIOCGIWTHRSPY */
8075 NULL, /* SIOCWIWTHRSPY */
8076 ipw2100_wx_set_wap, /* SIOCSIWAP */
8077 ipw2100_wx_get_wap, /* SIOCGIWAP */
8078 NULL, /* -- hole -- */
8079 NULL, /* SIOCGIWAPLIST -- deprecated */
8080 ipw2100_wx_set_scan, /* SIOCSIWSCAN */
8081 ipw2100_wx_get_scan, /* SIOCGIWSCAN */
8082 ipw2100_wx_set_essid, /* SIOCSIWESSID */
8083 ipw2100_wx_get_essid, /* SIOCGIWESSID */
8084 ipw2100_wx_set_nick, /* SIOCSIWNICKN */
8085 ipw2100_wx_get_nick, /* SIOCGIWNICKN */
8086 NULL, /* -- hole -- */
8087 NULL, /* -- hole -- */
8088 ipw2100_wx_set_rate, /* SIOCSIWRATE */
8089 ipw2100_wx_get_rate, /* SIOCGIWRATE */
8090 ipw2100_wx_set_rts, /* SIOCSIWRTS */
8091 ipw2100_wx_get_rts, /* SIOCGIWRTS */
8092 ipw2100_wx_set_frag, /* SIOCSIWFRAG */
8093 ipw2100_wx_get_frag, /* SIOCGIWFRAG */
8094 ipw2100_wx_set_txpow, /* SIOCSIWTXPOW */
8095 ipw2100_wx_get_txpow, /* SIOCGIWTXPOW */
8096 ipw2100_wx_set_retry, /* SIOCSIWRETRY */
8097 ipw2100_wx_get_retry, /* SIOCGIWRETRY */
8098 ipw2100_wx_set_encode, /* SIOCSIWENCODE */
8099 ipw2100_wx_get_encode, /* SIOCGIWENCODE */
8100 ipw2100_wx_set_power, /* SIOCSIWPOWER */
8101 ipw2100_wx_get_power, /* SIOCGIWPOWER */
8104 #define IPW2100_PRIV_SET_MONITOR SIOCIWFIRSTPRIV
8105 #define IPW2100_PRIV_RESET SIOCIWFIRSTPRIV+1
8106 #define IPW2100_PRIV_SET_POWER SIOCIWFIRSTPRIV+2
8107 #define IPW2100_PRIV_GET_POWER SIOCIWFIRSTPRIV+3
8108 #define IPW2100_PRIV_SET_LONGPREAMBLE SIOCIWFIRSTPRIV+4
8109 #define IPW2100_PRIV_GET_LONGPREAMBLE SIOCIWFIRSTPRIV+5
8111 static const struct iw_priv_args ipw2100_private_args[] = {
8113 #ifdef CONFIG_IPW2100_MONITOR
8115 IPW2100_PRIV_SET_MONITOR,
8116 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"
8120 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"
8122 #endif /* CONFIG_IPW2100_MONITOR */
8125 IPW2100_PRIV_SET_POWER,
8126 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_power"
8129 IPW2100_PRIV_GET_POWER,
8130 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_POWER_STRING, "get_power"
8133 IPW2100_PRIV_SET_LONGPREAMBLE,
8134 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_preamble"
8137 IPW2100_PRIV_GET_LONGPREAMBLE,
8138 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, "get_preamble"
8142 static iw_handler ipw2100_private_handler[] = {
8143 #ifdef CONFIG_IPW2100_MONITOR
8144 ipw2100_wx_set_promisc,
8146 #else /* CONFIG_IPW2100_MONITOR */
8149 #endif /* CONFIG_IPW2100_MONITOR */
8150 ipw2100_wx_set_powermode,
8151 ipw2100_wx_get_powermode,
8152 ipw2100_wx_set_preamble,
8153 ipw2100_wx_get_preamble,
8156 static struct iw_handler_def ipw2100_wx_handler_def =
8158 .standard = ipw2100_wx_handlers,
8159 .num_standard = sizeof(ipw2100_wx_handlers) / sizeof(iw_handler),
8160 .num_private = sizeof(ipw2100_private_handler) / sizeof(iw_handler),
8161 .num_private_args = sizeof(ipw2100_private_args) /
8162 sizeof(struct iw_priv_args),
8163 .private = (iw_handler *)ipw2100_private_handler,
8164 .private_args = (struct iw_priv_args *)ipw2100_private_args,
8168 * Get wireless statistics.
8169 * Called by /proc/net/wireless
8170 * Also called by SIOCGIWSTATS
8172 static struct iw_statistics *ipw2100_wx_wireless_stats(struct net_device * dev)
8186 struct ipw2100_priv *priv = ieee80211_priv(dev);
8187 struct iw_statistics *wstats;
8188 u32 rssi, quality, tx_retries, missed_beacons, tx_failures;
8189 u32 ord_len = sizeof(u32);
8192 return (struct iw_statistics *) NULL;
8194 wstats = &priv->wstats;
8196 /* if hw is disabled, then ipw2100_get_ordinal() can't be called.
8197 * ipw2100_wx_wireless_stats seems to be called before fw is
8198 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
8199 * and associated; if not associcated, the values are all meaningless
8200 * anyway, so set them all to NULL and INVALID */
8201 if (!(priv->status & STATUS_ASSOCIATED)) {
8202 wstats->miss.beacon = 0;
8203 wstats->discard.retries = 0;
8204 wstats->qual.qual = 0;
8205 wstats->qual.level = 0;
8206 wstats->qual.noise = 0;
8207 wstats->qual.updated = 7;
8208 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
8209 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
8213 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_PERCENT_MISSED_BCNS,
8214 &missed_beacons, &ord_len))
8215 goto fail_get_ordinal;
8217 /* If we don't have a connection the quality and level is 0*/
8218 if (!(priv->status & STATUS_ASSOCIATED)) {
8219 wstats->qual.qual = 0;
8220 wstats->qual.level = 0;
8222 if (ipw2100_get_ordinal(priv, IPW_ORD_RSSI_AVG_CURR,
8224 goto fail_get_ordinal;
8225 wstats->qual.level = rssi + IPW2100_RSSI_TO_DBM;
8227 rssi_qual = rssi * POOR / 10;
8229 rssi_qual = (rssi - 10) * (FAIR - POOR) / 5 + POOR;
8231 rssi_qual = (rssi - 15) * (GOOD - FAIR) / 5 + FAIR;
8233 rssi_qual = (rssi - 20) * (VERY_GOOD - GOOD) /
8236 rssi_qual = (rssi - 30) * (PERFECT - VERY_GOOD) /
8239 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_PERCENT_RETRIES,
8240 &tx_retries, &ord_len))
8241 goto fail_get_ordinal;
8243 if (tx_retries > 75)
8244 tx_qual = (90 - tx_retries) * POOR / 15;
8245 else if (tx_retries > 70)
8246 tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
8247 else if (tx_retries > 65)
8248 tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
8249 else if (tx_retries > 50)
8250 tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
8253 tx_qual = (50 - tx_retries) *
8254 (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
8256 if (missed_beacons > 50)
8257 beacon_qual = (60 - missed_beacons) * POOR / 10;
8258 else if (missed_beacons > 40)
8259 beacon_qual = (50 - missed_beacons) * (FAIR - POOR) /
8261 else if (missed_beacons > 32)
8262 beacon_qual = (40 - missed_beacons) * (GOOD - FAIR) /
8264 else if (missed_beacons > 20)
8265 beacon_qual = (32 - missed_beacons) *
8266 (VERY_GOOD - GOOD) / 20 + GOOD;
8268 beacon_qual = (20 - missed_beacons) *
8269 (PERFECT - VERY_GOOD) / 20 + VERY_GOOD;
8271 quality = min(beacon_qual, min(tx_qual, rssi_qual));
8273 #ifdef CONFIG_IPW_DEBUG
8274 if (beacon_qual == quality)
8275 IPW_DEBUG_WX("Quality clamped by Missed Beacons\n");
8276 else if (tx_qual == quality)
8277 IPW_DEBUG_WX("Quality clamped by Tx Retries\n");
8278 else if (quality != 100)
8279 IPW_DEBUG_WX("Quality clamped by Signal Strength\n");
8281 IPW_DEBUG_WX("Quality not clamped.\n");
8284 wstats->qual.qual = quality;
8285 wstats->qual.level = rssi + IPW2100_RSSI_TO_DBM;
8288 wstats->qual.noise = 0;
8289 wstats->qual.updated = 7;
8290 wstats->qual.updated |= IW_QUAL_NOISE_INVALID;
8292 /* FIXME: this is percent and not a # */
8293 wstats->miss.beacon = missed_beacons;
8295 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURES,
8296 &tx_failures, &ord_len))
8297 goto fail_get_ordinal;
8298 wstats->discard.retries = tx_failures;
8303 IPW_DEBUG_WX("failed querying ordinals.\n");
8305 return (struct iw_statistics *) NULL;
8308 static void ipw2100_wx_event_work(struct ipw2100_priv *priv)
8310 union iwreq_data wrqu;
8313 if (priv->status & STATUS_STOPPING)
8316 down(&priv->action_sem);
8318 IPW_DEBUG_WX("enter\n");
8320 up(&priv->action_sem);
8322 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
8324 /* Fetch BSSID from the hardware */
8325 if (!(priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) ||
8326 priv->status & STATUS_RF_KILL_MASK ||
8327 ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID,
8328 &priv->bssid, &len)) {
8329 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
8331 /* We now have the BSSID, so can finish setting to the full
8332 * associated state */
8333 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
8334 memcpy(&priv->ieee->bssid, priv->bssid, ETH_ALEN);
8335 priv->status &= ~STATUS_ASSOCIATING;
8336 priv->status |= STATUS_ASSOCIATED;
8337 netif_carrier_on(priv->net_dev);
8338 if (netif_queue_stopped(priv->net_dev)) {
8339 IPW_DEBUG_INFO("Waking net queue.\n");
8340 netif_wake_queue(priv->net_dev);
8342 IPW_DEBUG_INFO("Starting net queue.\n");
8343 netif_start_queue(priv->net_dev);
8347 if (!(priv->status & STATUS_ASSOCIATED)) {
8348 IPW_DEBUG_WX("Configuring ESSID\n");
8349 down(&priv->action_sem);
8350 /* This is a disassociation event, so kick the firmware to
8351 * look for another AP */
8352 if (priv->config & CFG_STATIC_ESSID)
8353 ipw2100_set_essid(priv, priv->essid, priv->essid_len, 0);
8355 ipw2100_set_essid(priv, NULL, 0, 0);
8356 up(&priv->action_sem);
8359 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
8362 #define IPW2100_FW_MAJOR_VERSION 1
8363 #define IPW2100_FW_MINOR_VERSION 3
8365 #define IPW2100_FW_MINOR(x) ((x & 0xff) >> 8)
8366 #define IPW2100_FW_MAJOR(x) (x & 0xff)
8368 #define IPW2100_FW_VERSION ((IPW2100_FW_MINOR_VERSION << 8) | \
8369 IPW2100_FW_MAJOR_VERSION)
8371 #define IPW2100_FW_PREFIX "ipw2100-" __stringify(IPW2100_FW_MAJOR_VERSION) \
8372 "." __stringify(IPW2100_FW_MINOR_VERSION)
8374 #define IPW2100_FW_NAME(x) IPW2100_FW_PREFIX "" x ".fw"
8379 BINARY FIRMWARE HEADER FORMAT
8383 2 2 mode == 0:BSS,1:IBSS,2:MONITOR
8386 C fw_len firmware data
8387 12 + fw_len uc_len microcode data
8391 struct ipw2100_fw_header {
8394 unsigned int fw_size;
8395 unsigned int uc_size;
8396 } __attribute__ ((packed));
8400 static int ipw2100_mod_firmware_load(struct ipw2100_fw *fw)
8402 struct ipw2100_fw_header *h =
8403 (struct ipw2100_fw_header *)fw->fw_entry->data;
8405 if (IPW2100_FW_MAJOR(h->version) != IPW2100_FW_MAJOR_VERSION) {
8406 printk(KERN_WARNING DRV_NAME ": Firmware image not compatible "
8407 "(detected version id of %u). "
8408 "See Documentation/networking/README.ipw2100\n",
8413 fw->version = h->version;
8414 fw->fw.data = fw->fw_entry->data + sizeof(struct ipw2100_fw_header);
8415 fw->fw.size = h->fw_size;
8416 fw->uc.data = fw->fw.data + h->fw_size;
8417 fw->uc.size = h->uc_size;
8423 static int ipw2100_get_firmware(struct ipw2100_priv *priv,
8424 struct ipw2100_fw *fw)
8429 IPW_DEBUG_INFO("%s: Using hotplug firmware load.\n",
8430 priv->net_dev->name);
8432 switch (priv->ieee->iw_mode) {
8434 fw_name = IPW2100_FW_NAME("-i");
8436 #ifdef CONFIG_IPW2100_MONITOR
8437 case IW_MODE_MONITOR:
8438 fw_name = IPW2100_FW_NAME("-p");
8443 fw_name = IPW2100_FW_NAME("");
8447 rc = request_firmware(&fw->fw_entry, fw_name, &priv->pci_dev->dev);
8450 printk(KERN_ERR DRV_NAME ": "
8451 "%s: Firmware '%s' not available or load failed.\n",
8452 priv->net_dev->name, fw_name);
8455 IPW_DEBUG_INFO("firmware data %p size %zd\n", fw->fw_entry->data,
8456 fw->fw_entry->size);
8458 ipw2100_mod_firmware_load(fw);
8463 static void ipw2100_release_firmware(struct ipw2100_priv *priv,
8464 struct ipw2100_fw *fw)
8468 release_firmware(fw->fw_entry);
8469 fw->fw_entry = NULL;
8473 static int ipw2100_get_fwversion(struct ipw2100_priv *priv, char *buf,
8476 char ver[MAX_FW_VERSION_LEN];
8477 u32 len = MAX_FW_VERSION_LEN;
8480 /* firmware version is an ascii string (max len of 14) */
8481 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_FW_VER_NUM,
8487 for (i = 0; i < len; i++)
8493 static int ipw2100_get_ucodeversion(struct ipw2100_priv *priv, char *buf,
8497 u32 len = sizeof(ver);
8498 /* microcode version is a 32 bit integer */
8499 if (ipw2100_get_ordinal(priv, IPW_ORD_UCODE_VERSION,
8502 return snprintf(buf, max, "%08X", ver);
8506 * On exit, the firmware will have been freed from the fw list
8508 static int ipw2100_fw_download(struct ipw2100_priv *priv,
8509 struct ipw2100_fw *fw)
8511 /* firmware is constructed of N contiguous entries, each entry is
8515 * 0 4 address to write to
8516 * 4 2 length of data run
8522 const unsigned char *firmware_data = fw->fw.data;
8523 unsigned int firmware_data_left = fw->fw.size;
8525 while (firmware_data_left > 0) {
8526 addr = *(u32 *)(firmware_data);
8528 firmware_data_left -= 4;
8530 len = *(u16 *)(firmware_data);
8532 firmware_data_left -= 2;
8535 printk(KERN_ERR DRV_NAME ": "
8536 "Invalid firmware run-length of %d bytes\n",
8541 write_nic_memory(priv->net_dev, addr, len, firmware_data);
8542 firmware_data += len;
8543 firmware_data_left -= len;
8549 struct symbol_alive_response {
8558 u16 clock_settle_time; // 1us LSB
8559 u16 powerup_settle_time; // 1us LSB
8560 u16 hop_settle_time; // 1us LSB
8561 u8 date[3]; // month, day, year
8562 u8 time[2]; // hours, minutes
8566 static int ipw2100_ucode_download(struct ipw2100_priv *priv,
8567 struct ipw2100_fw *fw)
8569 struct net_device *dev = priv->net_dev;
8570 const unsigned char *microcode_data = fw->uc.data;
8571 unsigned int microcode_data_left = fw->uc.size;
8572 void __iomem *reg = (void __iomem *)dev->base_addr;
8574 struct symbol_alive_response response;
8578 /* Symbol control */
8579 write_nic_word(dev, IPW2100_CONTROL_REG, 0x703);
8581 write_nic_word(dev, IPW2100_CONTROL_REG, 0x707);
8585 write_nic_byte(dev, 0x210014, 0x72); /* fifo width =16 */
8587 write_nic_byte(dev, 0x210014, 0x72); /* fifo width =16 */
8590 /* EN_CS_ACCESS bit to reset control store pointer */
8591 write_nic_byte(dev, 0x210000, 0x40);
8593 write_nic_byte(dev, 0x210000, 0x0);
8595 write_nic_byte(dev, 0x210000, 0x40);
8598 /* copy microcode from buffer into Symbol */
8600 while (microcode_data_left > 0) {
8601 write_nic_byte(dev, 0x210010, *microcode_data++);
8602 write_nic_byte(dev, 0x210010, *microcode_data++);
8603 microcode_data_left -= 2;
8606 /* EN_CS_ACCESS bit to reset the control store pointer */
8607 write_nic_byte(dev, 0x210000, 0x0);
8610 /* Enable System (Reg 0)
8611 * first enable causes garbage in RX FIFO */
8612 write_nic_byte(dev, 0x210000, 0x0);
8614 write_nic_byte(dev, 0x210000, 0x80);
8617 /* Reset External Baseband Reg */
8618 write_nic_word(dev, IPW2100_CONTROL_REG, 0x703);
8620 write_nic_word(dev, IPW2100_CONTROL_REG, 0x707);
8623 /* HW Config (Reg 5) */
8624 write_nic_byte(dev, 0x210014, 0x72); // fifo width =16
8626 write_nic_byte(dev, 0x210014, 0x72); // fifo width =16
8629 /* Enable System (Reg 0)
8630 * second enable should be OK */
8631 write_nic_byte(dev, 0x210000, 0x00); // clear enable system
8633 write_nic_byte(dev, 0x210000, 0x80); // set enable system
8635 /* check Symbol is enabled - upped this from 5 as it wasn't always
8636 * catching the update */
8637 for (i = 0; i < 10; i++) {
8640 /* check Dino is enabled bit */
8641 read_nic_byte(dev, 0x210000, &data);
8647 printk(KERN_ERR DRV_NAME ": %s: Error initializing Symbol\n",
8652 /* Get Symbol alive response */
8653 for (i = 0; i < 30; i++) {
8654 /* Read alive response structure */
8656 j < (sizeof(struct symbol_alive_response) >> 1);
8658 read_nic_word(dev, 0x210004,
8659 ((u16 *)&response) + j);
8661 if ((response.cmd_id == 1) &&
8662 (response.ucode_valid == 0x1))
8668 printk(KERN_ERR DRV_NAME ": %s: No response from Symbol - hw not alive\n",
8670 printk_buf(IPW_DL_ERROR, (u8*)&response, sizeof(response));