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 X__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 X__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/proc_fs.h>
150 #include <linux/skbuff.h>
151 #include <asm/uaccess.h>
153 #define __KERNEL_SYSCALLS__
154 #include <linux/fs.h>
155 #include <linux/mm.h>
156 #include <linux/slab.h>
157 #include <linux/unistd.h>
158 #include <linux/stringify.h>
159 #include <linux/tcp.h>
160 #include <linux/types.h>
161 #include <linux/version.h>
162 #include <linux/time.h>
163 #include <linux/firmware.h>
164 #include <linux/acpi.h>
165 #include <linux/ctype.h>
169 #define IPW2100_VERSION "1.1.0"
171 #define DRV_NAME "ipw2100"
172 #define DRV_VERSION IPW2100_VERSION
173 #define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2100 Network Driver"
174 #define DRV_COPYRIGHT "Copyright(c) 2003-2004 Intel Corporation"
177 /* Debugging stuff */
178 #ifdef CONFIG_IPW_DEBUG
179 #define CONFIG_IPW2100_RX_DEBUG /* Reception debugging */
182 MODULE_DESCRIPTION(DRV_DESCRIPTION);
183 MODULE_VERSION(DRV_VERSION);
184 MODULE_AUTHOR(DRV_COPYRIGHT);
185 MODULE_LICENSE("GPL");
187 static int debug = 0;
189 static int channel = 0;
190 static int associate = 1;
191 static int disable = 0;
193 static struct ipw2100_fw ipw2100_firmware;
196 #include <linux/moduleparam.h>
197 module_param(debug, int, 0444);
198 module_param(mode, int, 0444);
199 module_param(channel, int, 0444);
200 module_param(associate, int, 0444);
201 module_param(disable, int, 0444);
203 MODULE_PARM_DESC(debug, "debug level");
204 MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
205 MODULE_PARM_DESC(channel, "channel");
206 MODULE_PARM_DESC(associate, "auto associate when scanning (default on)");
207 MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
209 u32 ipw2100_debug_level = IPW_DL_NONE;
211 #ifdef CONFIG_IPW_DEBUG
212 static const char *command_types[] = {
214 "unused", /* HOST_ATTENTION */
216 "unused", /* SLEEP */
217 "unused", /* HOST_POWER_DOWN */
220 "unused", /* SET_IMR */
223 "AUTHENTICATION_TYPE",
226 "INTERNATIONAL_MODE",
241 "CLEAR_ALL_MULTICAST",
262 "AP_OR_STATION_TABLE",
266 "unused", /* SAVE_CALIBRATION */
267 "unused", /* RESTORE_CALIBRATION */
271 "HOST_PRE_POWER_DOWN",
272 "unused", /* HOST_INTERRUPT_COALESCING */
274 "CARD_DISABLE_PHY_OFF",
278 "SET_STATION_STAT_BITS",
279 "CLEAR_STATIONS_STAT_BITS",
281 "SET_SECURITY_INFORMATION",
282 "DISASSOCIATION_BSSID",
288 /* Pre-decl until we get the code solid and then we can clean it up */
289 static void X__ipw2100_tx_send_commands(struct ipw2100_priv *priv);
290 static void X__ipw2100_tx_send_data(struct ipw2100_priv *priv);
291 static int ipw2100_adapter_setup(struct ipw2100_priv *priv);
293 static void ipw2100_queues_initialize(struct ipw2100_priv *priv);
294 static void ipw2100_queues_free(struct ipw2100_priv *priv);
295 static int ipw2100_queues_allocate(struct ipw2100_priv *priv);
298 static inline void read_register(struct net_device *dev, u32 reg, u32 *val)
300 *val = readl((void *)(dev->base_addr + reg));
301 IPW_DEBUG_IO("r: 0x%08X => 0x%08X\n", reg, *val);
304 static inline void write_register(struct net_device *dev, u32 reg, u32 val)
306 writel(val, (void *)(dev->base_addr + reg));
307 IPW_DEBUG_IO("w: 0x%08X <= 0x%08X\n", reg, val);
310 static inline void read_register_word(struct net_device *dev, u32 reg, u16 *val)
312 *val = readw((void *)(dev->base_addr + reg));
313 IPW_DEBUG_IO("r: 0x%08X => %04X\n", reg, *val);
316 static inline void read_register_byte(struct net_device *dev, u32 reg, u8 *val)
318 *val = readb((void *)(dev->base_addr + reg));
319 IPW_DEBUG_IO("r: 0x%08X => %02X\n", reg, *val);
322 static inline void write_register_word(struct net_device *dev, u32 reg, u16 val)
324 writew(val, (void *)(dev->base_addr + reg));
325 IPW_DEBUG_IO("w: 0x%08X <= %04X\n", reg, val);
329 static inline void write_register_byte(struct net_device *dev, u32 reg, u8 val)
331 writeb(val, (void *)(dev->base_addr + reg));
332 IPW_DEBUG_IO("w: 0x%08X =< %02X\n", reg, val);
335 static inline void read_nic_dword(struct net_device *dev, u32 addr, u32 *val)
337 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
338 addr & IPW_REG_INDIRECT_ADDR_MASK);
339 read_register(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
342 static inline void write_nic_dword(struct net_device *dev, u32 addr, u32 val)
344 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
345 addr & IPW_REG_INDIRECT_ADDR_MASK);
346 write_register(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
349 static inline void read_nic_word(struct net_device *dev, u32 addr, u16 *val)
351 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
352 addr & IPW_REG_INDIRECT_ADDR_MASK);
353 read_register_word(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
356 static inline void write_nic_word(struct net_device *dev, u32 addr, u16 val)
358 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
359 addr & IPW_REG_INDIRECT_ADDR_MASK);
360 write_register_word(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
363 static inline void read_nic_byte(struct net_device *dev, u32 addr, u8 *val)
365 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
366 addr & IPW_REG_INDIRECT_ADDR_MASK);
367 read_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
370 static inline void write_nic_byte(struct net_device *dev, u32 addr, u8 val)
372 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
373 addr & IPW_REG_INDIRECT_ADDR_MASK);
374 write_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
377 static inline void write_nic_auto_inc_address(struct net_device *dev, u32 addr)
379 write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS,
380 addr & IPW_REG_INDIRECT_ADDR_MASK);
383 static inline void write_nic_dword_auto_inc(struct net_device *dev, u32 val)
385 write_register(dev, IPW_REG_AUTOINCREMENT_DATA, val);
388 static inline void write_nic_memory(struct net_device *dev, u32 addr, u32 len,
396 /* read first nibble byte by byte */
397 aligned_addr = addr & (~0x3);
398 dif_len = addr - aligned_addr;
400 /* Start reading at aligned_addr + dif_len */
401 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
403 for (i = dif_len; i < 4; i++, buf++)
405 dev, IPW_REG_INDIRECT_ACCESS_DATA + i,
412 /* read DWs through autoincrement registers */
413 write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS,
415 aligned_len = len & (~0x3);
416 for (i = 0; i < aligned_len; i += 4, buf += 4, aligned_addr += 4)
418 dev, IPW_REG_AUTOINCREMENT_DATA, *(u32 *)buf);
420 /* copy the last nibble */
421 dif_len = len - aligned_len;
422 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, aligned_addr);
423 for (i = 0; i < dif_len; i++, buf++)
425 dev, IPW_REG_INDIRECT_ACCESS_DATA + i, *buf);
428 static inline void read_nic_memory(struct net_device *dev, u32 addr, u32 len,
436 /* read first nibble byte by byte */
437 aligned_addr = addr & (~0x3);
438 dif_len = addr - aligned_addr;
440 /* Start reading at aligned_addr + dif_len */
441 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
443 for (i = dif_len; i < 4; i++, buf++)
445 dev, IPW_REG_INDIRECT_ACCESS_DATA + i, buf);
451 /* read DWs through autoincrement registers */
452 write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS,
454 aligned_len = len & (~0x3);
455 for (i = 0; i < aligned_len; i += 4, buf += 4, aligned_addr += 4)
456 read_register(dev, IPW_REG_AUTOINCREMENT_DATA,
459 /* copy the last nibble */
460 dif_len = len - aligned_len;
461 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
463 for (i = 0; i < dif_len; i++, buf++)
464 read_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA +
468 static inline int ipw2100_hw_is_adapter_in_system(struct net_device *dev)
470 return (dev->base_addr &&
471 (readl((void *)(dev->base_addr + IPW_REG_DOA_DEBUG_AREA_START))
472 == IPW_DATA_DOA_DEBUG_VALUE));
475 int ipw2100_get_ordinal(struct ipw2100_priv *priv, u32 ord,
478 struct ipw2100_ordinals *ordinals = &priv->ordinals;
485 if (ordinals->table1_addr == 0) {
486 IPW_DEBUG_WARNING(DRV_NAME ": attempt to use fw ordinals "
487 "before they have been loaded.\n");
491 if (IS_ORDINAL_TABLE_ONE(ordinals, ord)) {
492 if (*len < IPW_ORD_TAB_1_ENTRY_SIZE) {
493 *len = IPW_ORD_TAB_1_ENTRY_SIZE;
495 IPW_DEBUG_WARNING(DRV_NAME
496 ": ordinal buffer length too small, need %d\n",
497 IPW_ORD_TAB_1_ENTRY_SIZE);
502 read_nic_dword(priv->net_dev, ordinals->table1_addr + (ord << 2),
504 read_nic_dword(priv->net_dev, addr, val);
506 *len = IPW_ORD_TAB_1_ENTRY_SIZE;
511 if (IS_ORDINAL_TABLE_TWO(ordinals, ord)) {
513 ord -= IPW_START_ORD_TAB_2;
515 /* get the address of statistic */
516 read_nic_dword(priv->net_dev, ordinals->table2_addr + (ord << 3),
519 /* get the second DW of statistics ;
520 * two 16-bit words - first is length, second is count */
521 read_nic_dword(priv->net_dev,
522 ordinals->table2_addr + (ord << 3) + sizeof(u32),
525 /* get each entry length */
526 field_len = *((u16 *)&field_info);
528 /* get number of entries */
529 field_count = *(((u16 *)&field_info) + 1);
531 /* abort if no enought memory */
532 total_length = field_len * field_count;
533 if (total_length > *len) {
542 /* read the ordinal data from the SRAM */
543 read_nic_memory(priv->net_dev, addr, total_length, val);
548 IPW_DEBUG_WARNING(DRV_NAME ": ordinal %d neither in table 1 nor "
549 "in table 2\n", ord);
554 static int ipw2100_set_ordinal(struct ipw2100_priv *priv, u32 ord, u32 *val,
557 struct ipw2100_ordinals *ordinals = &priv->ordinals;
560 if (IS_ORDINAL_TABLE_ONE(ordinals, ord)) {
561 if (*len != IPW_ORD_TAB_1_ENTRY_SIZE) {
562 *len = IPW_ORD_TAB_1_ENTRY_SIZE;
563 IPW_DEBUG_INFO("wrong size\n");
567 read_nic_dword(priv->net_dev, ordinals->table1_addr + (ord << 2),
570 write_nic_dword(priv->net_dev, addr, *val);
572 *len = IPW_ORD_TAB_1_ENTRY_SIZE;
577 IPW_DEBUG_INFO("wrong table\n");
578 if (IS_ORDINAL_TABLE_TWO(ordinals, ord))
584 static char *snprint_line(char *buf, size_t count,
585 const u8 *data, u32 len, u32 ofs)
590 out = snprintf(buf, count, "%08X", ofs);
592 for (l = 0, i = 0; i < 2; i++) {
593 out += snprintf(buf + out, count - out, " ");
594 for (j = 0; j < 8 && l < len; j++, l++)
595 out += snprintf(buf + out, count - out, "%02X ",
598 out += snprintf(buf + out, count - out, " ");
601 out += snprintf(buf + out, count - out, " ");
602 for (l = 0, i = 0; i < 2; i++) {
603 out += snprintf(buf + out, count - out, " ");
604 for (j = 0; j < 8 && l < len; j++, l++) {
605 c = data[(i * 8 + j)];
606 if (!isascii(c) || !isprint(c))
609 out += snprintf(buf + out, count - out, "%c", c);
613 out += snprintf(buf + out, count - out, " ");
619 static void printk_buf(int level, const u8 *data, u32 len)
623 if (!(ipw2100_debug_level & level))
627 printk(KERN_DEBUG "%s\n",
628 snprint_line(line, sizeof(line), &data[ofs],
629 min(len, 16U), ofs));
631 len -= min(len, 16U);
637 #define MAX_RESET_BACKOFF 10
639 static inline void schedule_reset(struct ipw2100_priv *priv)
641 unsigned long now = get_seconds();
643 /* If we haven't received a reset request within the backoff period,
644 * then we can reset the backoff interval so this reset occurs
646 if (priv->reset_backoff &&
647 (now - priv->last_reset > priv->reset_backoff))
648 priv->reset_backoff = 0;
650 priv->last_reset = get_seconds();
652 if (!(priv->status & STATUS_RESET_PENDING)) {
653 IPW_DEBUG_INFO("%s: Scheduling firmware restart (%ds).\n",
654 priv->net_dev->name, priv->reset_backoff);
655 netif_carrier_off(priv->net_dev);
656 netif_stop_queue(priv->net_dev);
657 priv->status |= STATUS_RESET_PENDING;
658 if (priv->reset_backoff)
659 queue_delayed_work(priv->workqueue, &priv->reset_work,
660 priv->reset_backoff * HZ);
662 queue_work(priv->workqueue, &priv->reset_work);
664 if (priv->reset_backoff < MAX_RESET_BACKOFF)
665 priv->reset_backoff++;
667 wake_up_interruptible(&priv->wait_command_queue);
669 IPW_DEBUG_INFO("%s: Firmware restart already in progress.\n",
670 priv->net_dev->name);
674 #define HOST_COMPLETE_TIMEOUT (2 * HZ)
675 static int ipw2100_hw_send_command(struct ipw2100_priv *priv,
676 struct host_command * cmd)
678 struct list_head *element;
679 struct ipw2100_tx_packet *packet;
683 IPW_DEBUG_HC("Sending %s command (#%d), %d bytes\n",
684 command_types[cmd->host_command], cmd->host_command,
685 cmd->host_command_length);
686 printk_buf(IPW_DL_HC, (u8*)cmd->host_command_parameters,
687 cmd->host_command_length);
689 spin_lock_irqsave(&priv->low_lock, flags);
691 if (priv->fatal_error) {
692 IPW_DEBUG_INFO("Attempt to send command while hardware in fatal error condition.\n");
697 if (!(priv->status & STATUS_RUNNING)) {
698 IPW_DEBUG_INFO("Attempt to send command while hardware is not running.\n");
703 if (priv->status & STATUS_CMD_ACTIVE) {
704 IPW_DEBUG_INFO("Attempt to send command while another command is pending.\n");
709 if (list_empty(&priv->msg_free_list)) {
710 IPW_DEBUG_INFO("no available msg buffers\n");
714 priv->status |= STATUS_CMD_ACTIVE;
715 priv->messages_sent++;
717 element = priv->msg_free_list.next;
719 packet = list_entry(element, struct ipw2100_tx_packet, list);
720 packet->jiffy_start = jiffies;
722 /* initialize the firmware command packet */
723 packet->info.c_struct.cmd->host_command_reg = cmd->host_command;
724 packet->info.c_struct.cmd->host_command_reg1 = cmd->host_command1;
725 packet->info.c_struct.cmd->host_command_len_reg = cmd->host_command_length;
726 packet->info.c_struct.cmd->sequence = cmd->host_command_sequence;
728 memcpy(packet->info.c_struct.cmd->host_command_params_reg,
729 cmd->host_command_parameters,
730 sizeof(packet->info.c_struct.cmd->host_command_params_reg));
733 DEC_STAT(&priv->msg_free_stat);
735 list_add_tail(element, &priv->msg_pend_list);
736 INC_STAT(&priv->msg_pend_stat);
738 X__ipw2100_tx_send_commands(priv);
739 X__ipw2100_tx_send_data(priv);
741 spin_unlock_irqrestore(&priv->low_lock, flags);
744 * We must wait for this command to complete before another
745 * command can be sent... but if we wait more than 3 seconds
746 * then there is a problem.
749 err = wait_event_interruptible_timeout(
750 priv->wait_command_queue, !(priv->status & STATUS_CMD_ACTIVE),
751 HOST_COMPLETE_TIMEOUT);
754 IPW_DEBUG_INFO("Command completion failed out after %dms.\n",
755 HOST_COMPLETE_TIMEOUT / (HZ / 100));
756 priv->fatal_error = IPW2100_ERR_MSG_TIMEOUT;
757 priv->status &= ~STATUS_CMD_ACTIVE;
758 schedule_reset(priv);
762 if (priv->fatal_error) {
763 IPW_DEBUG_WARNING("%s: firmware fatal error\n",
764 priv->net_dev->name);
768 /* !!!!! HACK TEST !!!!!
769 * When lots of debug trace statements are enabled, the driver
770 * doesn't seem to have as many firmware restart cycles...
772 * As a test, we're sticking in a 1/100s delay here */
773 set_current_state(TASK_UNINTERRUPTIBLE);
774 schedule_timeout(HZ / 100);
779 spin_unlock_irqrestore(&priv->low_lock, flags);
786 * Verify the values and data access of the hardware
787 * No locks needed or used. No functions called.
789 static int ipw2100_verify(struct ipw2100_priv *priv)
794 u32 val1 = 0x76543210;
795 u32 val2 = 0xFEDCBA98;
797 /* Domain 0 check - all values should be DOA_DEBUG */
798 for (address = IPW_REG_DOA_DEBUG_AREA_START;
799 address < IPW_REG_DOA_DEBUG_AREA_END;
800 address += sizeof(u32)) {
801 read_register(priv->net_dev, address, &data1);
802 if (data1 != IPW_DATA_DOA_DEBUG_VALUE)
806 /* Domain 1 check - use arbitrary read/write compare */
807 for (address = 0; address < 5; address++) {
808 /* The memory area is not used now */
809 write_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x32,
811 write_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x36,
813 read_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x32,
815 read_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x36,
817 if (val1 == data1 && val2 == data2)
826 * Loop until the CARD_DISABLED bit is the same value as the
829 * TODO: See if it would be more efficient to do a wait/wake
830 * cycle and have the completion event trigger the wakeup
833 #define IPW_CARD_DISABLE_COMPLETE_WAIT 100 // 100 milli
834 static int ipw2100_wait_for_card_state(struct ipw2100_priv *priv, int state)
838 u32 len = sizeof(card_state);
841 for (i = 0; i <= IPW_CARD_DISABLE_COMPLETE_WAIT * 1000; i += 50) {
842 err = ipw2100_get_ordinal(priv, IPW_ORD_CARD_DISABLED,
845 IPW_DEBUG_INFO("Query of CARD_DISABLED ordinal "
850 /* We'll break out if either the HW state says it is
851 * in the state we want, or if HOST_COMPLETE command
853 if ((card_state == state) ||
854 ((priv->status & STATUS_ENABLED) ?
855 IPW_HW_STATE_ENABLED : IPW_HW_STATE_DISABLED) == state) {
856 if (state == IPW_HW_STATE_ENABLED)
857 priv->status |= STATUS_ENABLED;
859 priv->status &= ~STATUS_ENABLED;
867 IPW_DEBUG_INFO("ipw2100_wait_for_card_state to %s state timed out\n",
868 state ? "DISABLED" : "ENABLED");
873 /*********************************************************************
874 Procedure : sw_reset_and_clock
875 Purpose : Asserts s/w reset, asserts clock initialization
876 and waits for clock stabilization
877 ********************************************************************/
878 static int sw_reset_and_clock(struct ipw2100_priv *priv)
884 write_register(priv->net_dev, IPW_REG_RESET_REG,
885 IPW_AUX_HOST_RESET_REG_SW_RESET);
887 // wait for clock stabilization
888 for (i = 0; i < 1000; i++) {
889 udelay(IPW_WAIT_RESET_ARC_COMPLETE_DELAY);
891 // check clock ready bit
892 read_register(priv->net_dev, IPW_REG_RESET_REG, &r);
893 if (r & IPW_AUX_HOST_RESET_REG_PRINCETON_RESET)
898 return -EIO; // TODO: better error value
900 /* set "initialization complete" bit to move adapter to
902 write_register(priv->net_dev, IPW_REG_GP_CNTRL,
903 IPW_AUX_HOST_GP_CNTRL_BIT_INIT_DONE);
905 /* wait for clock stabilization */
906 for (i = 0; i < 10000; i++) {
907 udelay(IPW_WAIT_CLOCK_STABILIZATION_DELAY * 4);
909 /* check clock ready bit */
910 read_register(priv->net_dev, IPW_REG_GP_CNTRL, &r);
911 if (r & IPW_AUX_HOST_GP_CNTRL_BIT_CLOCK_READY)
916 return -EIO; /* TODO: better error value */
918 //#if CONFIG_IPW2100_D0ENABLED
919 /* set D0 standby bit */
920 read_register(priv->net_dev, IPW_REG_GP_CNTRL, &r);
921 write_register(priv->net_dev, IPW_REG_GP_CNTRL,
922 r | IPW_AUX_HOST_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
928 /*********************************************************************
929 Procedure : ipw2100_ipw2100_download_firmware
930 Purpose : Initiaze adapter after power on.
932 1. assert s/w reset first!
933 2. awake clocks & wait for clock stabilization
934 3. hold ARC (don't ask me why...)
935 4. load Dino ucode and reset/clock init again
936 5. zero-out shared mem
938 *******************************************************************/
939 static int ipw2100_download_firmware(struct ipw2100_priv *priv)
945 /* Fetch the firmware and microcode */
946 struct ipw2100_fw ipw2100_firmware;
949 if (priv->fatal_error) {
950 IPW_DEBUG_ERROR("%s: ipw2100_download_firmware called after "
951 "fatal error %d. Interface must be brought down.\n",
952 priv->net_dev->name, priv->fatal_error);
957 if (!ipw2100_firmware.version) {
958 err = ipw2100_get_firmware(priv, &ipw2100_firmware);
960 IPW_DEBUG_ERROR("%s: ipw2100_get_firmware failed: %d\n",
961 priv->net_dev->name, err);
962 priv->fatal_error = IPW2100_ERR_FW_LOAD;
967 err = ipw2100_get_firmware(priv, &ipw2100_firmware);
969 IPW_DEBUG_ERROR("%s: ipw2100_get_firmware failed: %d\n",
970 priv->net_dev->name, err);
971 priv->fatal_error = IPW2100_ERR_FW_LOAD;
975 priv->firmware_version = ipw2100_firmware.version;
977 /* s/w reset and clock stabilization */
978 err = sw_reset_and_clock(priv);
980 IPW_DEBUG_ERROR("%s: sw_reset_and_clock failed: %d\n",
981 priv->net_dev->name, err);
985 err = ipw2100_verify(priv);
987 IPW_DEBUG_ERROR("%s: ipw2100_verify failed: %d\n",
988 priv->net_dev->name, err);
993 write_nic_dword(priv->net_dev,
994 IPW_INTERNAL_REGISTER_HALT_AND_RESET,
997 /* allow ARC to run */
998 write_register(priv->net_dev, IPW_REG_RESET_REG, 0);
1000 /* load microcode */
1001 err = ipw2100_ucode_download(priv, &ipw2100_firmware);
1003 IPW_DEBUG_ERROR("%s: Error loading microcode: %d\n",
1004 priv->net_dev->name, err);
1009 write_nic_dword(priv->net_dev,
1010 IPW_INTERNAL_REGISTER_HALT_AND_RESET,
1013 /* s/w reset and clock stabilization (again!!!) */
1014 err = sw_reset_and_clock(priv);
1016 IPW_DEBUG_ERROR("%s: sw_reset_and_clock failed: %d\n",
1017 priv->net_dev->name, err);
1022 err = ipw2100_fw_download(priv, &ipw2100_firmware);
1024 IPW_DEBUG_ERROR("%s: Error loading firmware: %d\n",
1025 priv->net_dev->name, err);
1031 * When the .resume method of the driver is called, the other
1032 * part of the system, i.e. the ide driver could still stay in
1033 * the suspend stage. This prevents us from loading the firmware
1034 * from the disk. --YZ
1037 /* free any storage allocated for firmware image */
1038 ipw2100_release_firmware(priv, &ipw2100_firmware);
1041 /* zero out Domain 1 area indirectly (Si requirement) */
1042 for (address = IPW_HOST_FW_SHARED_AREA0;
1043 address < IPW_HOST_FW_SHARED_AREA0_END; address += 4)
1044 write_nic_dword(priv->net_dev, address, 0);
1045 for (address = IPW_HOST_FW_SHARED_AREA1;
1046 address < IPW_HOST_FW_SHARED_AREA1_END; address += 4)
1047 write_nic_dword(priv->net_dev, address, 0);
1048 for (address = IPW_HOST_FW_SHARED_AREA2;
1049 address < IPW_HOST_FW_SHARED_AREA2_END; address += 4)
1050 write_nic_dword(priv->net_dev, address, 0);
1051 for (address = IPW_HOST_FW_SHARED_AREA3;
1052 address < IPW_HOST_FW_SHARED_AREA3_END; address += 4)
1053 write_nic_dword(priv->net_dev, address, 0);
1054 for (address = IPW_HOST_FW_INTERRUPT_AREA;
1055 address < IPW_HOST_FW_INTERRUPT_AREA_END; address += 4)
1056 write_nic_dword(priv->net_dev, address, 0);
1061 ipw2100_release_firmware(priv, &ipw2100_firmware);
1065 static inline void ipw2100_enable_interrupts(struct ipw2100_priv *priv)
1067 if (priv->status & STATUS_INT_ENABLED)
1069 priv->status |= STATUS_INT_ENABLED;
1070 write_register(priv->net_dev, IPW_REG_INTA_MASK, IPW_INTERRUPT_MASK);
1073 static inline void ipw2100_disable_interrupts(struct ipw2100_priv *priv)
1075 if (!(priv->status & STATUS_INT_ENABLED))
1077 priv->status &= ~STATUS_INT_ENABLED;
1078 write_register(priv->net_dev, IPW_REG_INTA_MASK, 0x0);
1082 static void ipw2100_initialize_ordinals(struct ipw2100_priv *priv)
1084 struct ipw2100_ordinals *ord = &priv->ordinals;
1086 IPW_DEBUG_INFO("enter\n");
1088 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_ORDINALS_TABLE_1,
1091 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_ORDINALS_TABLE_2,
1094 read_nic_dword(priv->net_dev, ord->table1_addr, &ord->table1_size);
1095 read_nic_dword(priv->net_dev, ord->table2_addr, &ord->table2_size);
1097 ord->table2_size &= 0x0000FFFF;
1099 IPW_DEBUG_INFO("table 1 size: %d\n", ord->table1_size);
1100 IPW_DEBUG_INFO("table 2 size: %d\n", ord->table2_size);
1101 IPW_DEBUG_INFO("exit\n");
1104 static inline void ipw2100_hw_set_gpio(struct ipw2100_priv *priv)
1108 * Set GPIO 3 writable by FW; GPIO 1 writable
1109 * by driver and enable clock
1111 reg = (IPW_BIT_GPIO_GPIO3_MASK | IPW_BIT_GPIO_GPIO1_ENABLE |
1112 IPW_BIT_GPIO_LED_OFF);
1113 write_register(priv->net_dev, IPW_REG_GPIO, reg);
1116 static inline int rf_kill_active(struct ipw2100_priv *priv)
1118 #define MAX_RF_KILL_CHECKS 5
1119 #define RF_KILL_CHECK_DELAY 40
1120 #define RF_KILL_CHECK_THRESHOLD 3
1122 unsigned short value = 0;
1126 if (!(priv->hw_features & HW_FEATURE_RFKILL)) {
1127 priv->status &= ~STATUS_RF_KILL_HW;
1131 for (i = 0; i < MAX_RF_KILL_CHECKS; i++) {
1132 udelay(RF_KILL_CHECK_DELAY);
1133 read_register(priv->net_dev, IPW_REG_GPIO, ®);
1134 value = (value << 1) | ((reg & IPW_BIT_GPIO_RF_KILL) ? 0 : 1);
1138 priv->status |= STATUS_RF_KILL_HW;
1140 priv->status &= ~STATUS_RF_KILL_HW;
1142 return (value == 0);
1145 static int ipw2100_get_hw_features(struct ipw2100_priv *priv)
1151 * EEPROM_SRAM_DB_START_ADDRESS using ordinal in ordinal table 1
1154 if (ipw2100_get_ordinal(
1155 priv, IPW_ORD_EEPROM_SRAM_DB_BLOCK_START_ADDRESS,
1157 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
1162 IPW_DEBUG_INFO("EEPROM address: %08X\n", addr);
1165 * EEPROM version is the byte at offset 0xfd in firmware
1166 * We read 4 bytes, then shift out the byte we actually want */
1167 read_nic_dword(priv->net_dev, addr + 0xFC, &val);
1168 priv->eeprom_version = (val >> 24) & 0xFF;
1169 IPW_DEBUG_INFO("EEPROM version: %d\n", priv->eeprom_version);
1172 * HW RF Kill enable is bit 0 in byte at offset 0x21 in firmware
1174 * notice that the EEPROM bit is reverse polarity, i.e.
1175 * bit = 0 signifies HW RF kill switch is supported
1176 * bit = 1 signifies HW RF kill switch is NOT supported
1178 read_nic_dword(priv->net_dev, addr + 0x20, &val);
1179 if (!((val >> 24) & 0x01))
1180 priv->hw_features |= HW_FEATURE_RFKILL;
1182 IPW_DEBUG_INFO("HW RF Kill: %ssupported.\n",
1183 (priv->hw_features & HW_FEATURE_RFKILL) ?
1190 * Start firmware execution after power on and intialization
1193 * 2. Wait for f/w initialization completes;
1195 static int ipw2100_start_adapter(struct ipw2100_priv *priv)
1197 #define IPW_WAIT_FW_INIT_COMPLETE_DELAY (40 * HZ / 1000)
1199 u32 inta, inta_mask, gpio;
1201 IPW_DEBUG_INFO("enter\n");
1203 if (priv->status & STATUS_RUNNING)
1207 * Initialize the hw - drive adapter to DO state by setting
1208 * init_done bit. Wait for clk_ready bit and Download
1211 if (ipw2100_download_firmware(priv)) {
1212 IPW_DEBUG_ERROR("%s: Failed to power on the adapter.\n",
1213 priv->net_dev->name);
1217 /* Clear the Tx, Rx and Msg queues and the r/w indexes
1218 * in the firmware RBD and TBD ring queue */
1219 ipw2100_queues_initialize(priv);
1221 ipw2100_hw_set_gpio(priv);
1223 /* TODO -- Look at disabling interrupts here to make sure none
1224 * get fired during FW initialization */
1226 /* Release ARC - clear reset bit */
1227 write_register(priv->net_dev, IPW_REG_RESET_REG, 0);
1229 /* wait for f/w intialization complete */
1230 IPW_DEBUG_FW("Waiting for f/w initialization to complete...\n");
1233 set_current_state(TASK_UNINTERRUPTIBLE);
1234 schedule_timeout(IPW_WAIT_FW_INIT_COMPLETE_DELAY);
1235 /* Todo... wait for sync command ... */
1237 read_register(priv->net_dev, IPW_REG_INTA, &inta);
1239 /* check "init done" bit */
1240 if (inta & IPW2100_INTA_FW_INIT_DONE) {
1241 /* reset "init done" bit */
1242 write_register(priv->net_dev, IPW_REG_INTA,
1243 IPW2100_INTA_FW_INIT_DONE);
1247 /* check error conditions : we check these after the firmware
1248 * check so that if there is an error, the interrupt handler
1249 * will see it and the adapter will be reset */
1251 (IPW2100_INTA_FATAL_ERROR | IPW2100_INTA_PARITY_ERROR)) {
1252 /* clear error conditions */
1253 write_register(priv->net_dev, IPW_REG_INTA,
1254 IPW2100_INTA_FATAL_ERROR |
1255 IPW2100_INTA_PARITY_ERROR);
1259 /* Clear out any pending INTAs since we aren't supposed to have
1260 * interrupts enabled at this point... */
1261 read_register(priv->net_dev, IPW_REG_INTA, &inta);
1262 read_register(priv->net_dev, IPW_REG_INTA_MASK, &inta_mask);
1263 inta &= IPW_INTERRUPT_MASK;
1264 /* Clear out any pending interrupts */
1265 if (inta & inta_mask)
1266 write_register(priv->net_dev, IPW_REG_INTA, inta);
1268 IPW_DEBUG_FW("f/w initialization complete: %s\n",
1269 i ? "SUCCESS" : "FAILED");
1272 IPW_DEBUG_WARNING("%s: Firmware did not initialize.\n",
1273 priv->net_dev->name);
1277 /* allow firmware to write to GPIO1 & GPIO3 */
1278 read_register(priv->net_dev, IPW_REG_GPIO, &gpio);
1280 gpio |= (IPW_BIT_GPIO_GPIO1_MASK | IPW_BIT_GPIO_GPIO3_MASK);
1282 write_register(priv->net_dev, IPW_REG_GPIO, gpio);
1284 /* Ready to receive commands */
1285 priv->status |= STATUS_RUNNING;
1287 /* The adapter has been reset; we are not associated */
1288 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
1290 IPW_DEBUG_INFO("exit\n");
1295 static inline void ipw2100_reset_fatalerror(struct ipw2100_priv *priv)
1297 if (!priv->fatal_error)
1300 priv->fatal_errors[priv->fatal_index++] = priv->fatal_error;
1301 priv->fatal_index %= IPW2100_ERROR_QUEUE;
1302 priv->fatal_error = 0;
1306 /* NOTE: Our interrupt is disabled when this method is called */
1307 static int ipw2100_power_cycle_adapter(struct ipw2100_priv *priv)
1312 IPW_DEBUG_INFO("Power cycling the hardware.\n");
1314 ipw2100_hw_set_gpio(priv);
1316 /* Step 1. Stop Master Assert */
1317 write_register(priv->net_dev, IPW_REG_RESET_REG,
1318 IPW_AUX_HOST_RESET_REG_STOP_MASTER);
1320 /* Step 2. Wait for stop Master Assert
1321 * (not more then 50us, otherwise ret error */
1324 udelay(IPW_WAIT_RESET_MASTER_ASSERT_COMPLETE_DELAY);
1325 read_register(priv->net_dev, IPW_REG_RESET_REG, ®);
1327 if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED)
1331 priv->status &= ~STATUS_RESET_PENDING;
1334 IPW_DEBUG_INFO("exit - waited too long for master assert stop\n");
1338 write_register(priv->net_dev, IPW_REG_RESET_REG,
1339 IPW_AUX_HOST_RESET_REG_SW_RESET);
1342 /* Reset any fatal_error conditions */
1343 ipw2100_reset_fatalerror(priv);
1345 /* At this point, the adapter is now stopped and disabled */
1346 priv->status &= ~(STATUS_RUNNING | STATUS_ASSOCIATING |
1347 STATUS_ASSOCIATED | STATUS_ENABLED);
1353 * Send the CARD_DISABLE_PHY_OFF comamnd to the card to disable it
1355 * After disabling, if the card was associated, a STATUS_ASSN_LOST will be sent.
1357 * STATUS_CARD_DISABLE_NOTIFICATION will be sent regardless of
1358 * if STATUS_ASSN_LOST is sent.
1360 static int ipw2100_hw_phy_off(struct ipw2100_priv *priv)
1363 #define HW_PHY_OFF_LOOP_DELAY (HZ / 5000)
1365 struct host_command cmd = {
1366 .host_command = CARD_DISABLE_PHY_OFF,
1367 .host_command_sequence = 0,
1368 .host_command_length = 0,
1373 IPW_DEBUG_HC("CARD_DISABLE_PHY_OFF\n");
1375 /* Turn off the radio */
1376 err = ipw2100_hw_send_command(priv, &cmd);
1380 for (i = 0; i < 2500; i++) {
1381 read_nic_dword(priv->net_dev, IPW2100_CONTROL_REG, &val1);
1382 read_nic_dword(priv->net_dev, IPW2100_COMMAND, &val2);
1384 if ((val1 & IPW2100_CONTROL_PHY_OFF) &&
1385 (val2 & IPW2100_COMMAND_PHY_OFF))
1388 set_current_state(TASK_UNINTERRUPTIBLE);
1389 schedule_timeout(HW_PHY_OFF_LOOP_DELAY);
1396 static int ipw2100_enable_adapter(struct ipw2100_priv *priv)
1398 struct host_command cmd = {
1399 .host_command = HOST_COMPLETE,
1400 .host_command_sequence = 0,
1401 .host_command_length = 0
1405 IPW_DEBUG_HC("HOST_COMPLETE\n");
1407 if (priv->status & STATUS_ENABLED)
1410 down(&priv->adapter_sem);
1412 if (rf_kill_active(priv)) {
1413 IPW_DEBUG_HC("Command aborted due to RF kill active.\n");
1417 err = ipw2100_hw_send_command(priv, &cmd);
1419 IPW_DEBUG_INFO("Failed to send HOST_COMPLETE command\n");
1423 err = ipw2100_wait_for_card_state(priv, IPW_HW_STATE_ENABLED);
1426 "%s: card not responding to init command.\n",
1427 priv->net_dev->name);
1431 if (priv->stop_hang_check) {
1432 priv->stop_hang_check = 0;
1433 queue_delayed_work(priv->workqueue, &priv->hang_check, HZ / 2);
1437 up(&priv->adapter_sem);
1441 static int ipw2100_hw_stop_adapter(struct ipw2100_priv *priv)
1443 #define HW_POWER_DOWN_DELAY (HZ / 10)
1445 struct host_command cmd = {
1446 .host_command = HOST_PRE_POWER_DOWN,
1447 .host_command_sequence = 0,
1448 .host_command_length = 0,
1453 if (!(priv->status & STATUS_RUNNING))
1456 priv->status |= STATUS_STOPPING;
1458 /* We can only shut down the card if the firmware is operational. So,
1459 * if we haven't reset since a fatal_error, then we can not send the
1460 * shutdown commands. */
1461 if (!priv->fatal_error) {
1462 /* First, make sure the adapter is enabled so that the PHY_OFF
1463 * command can shut it down */
1464 ipw2100_enable_adapter(priv);
1466 err = ipw2100_hw_phy_off(priv);
1468 IPW_DEBUG_WARNING("Error disabling radio %d\n", err);
1471 * If in D0-standby mode going directly to D3 may cause a
1472 * PCI bus violation. Therefore we must change out of the D0
1475 * Sending the PREPARE_FOR_POWER_DOWN will restrict the
1476 * hardware from going into standby mode and will transition
1477 * out of D0-standy if it is already in that state.
1479 * STATUS_PREPARE_POWER_DOWN_COMPLETE will be sent by the
1480 * driver upon completion. Once received, the driver can
1481 * proceed to the D3 state.
1483 * Prepare for power down command to fw. This command would
1484 * take HW out of D0-standby and prepare it for D3 state.
1486 * Currently FW does not support event notification for this
1487 * event. Therefore, skip waiting for it. Just wait a fixed
1490 IPW_DEBUG_HC("HOST_PRE_POWER_DOWN\n");
1492 err = ipw2100_hw_send_command(priv, &cmd);
1495 "%s: Power down command failed: Error %d\n",
1496 priv->net_dev->name, err);
1498 set_current_state(TASK_UNINTERRUPTIBLE);
1499 schedule_timeout(HW_POWER_DOWN_DELAY);
1503 priv->status &= ~STATUS_ENABLED;
1506 * Set GPIO 3 writable by FW; GPIO 1 writable
1507 * by driver and enable clock
1509 ipw2100_hw_set_gpio(priv);
1512 * Power down adapter. Sequence:
1513 * 1. Stop master assert (RESET_REG[9]=1)
1514 * 2. Wait for stop master (RESET_REG[8]==1)
1515 * 3. S/w reset assert (RESET_REG[7] = 1)
1518 /* Stop master assert */
1519 write_register(priv->net_dev, IPW_REG_RESET_REG,
1520 IPW_AUX_HOST_RESET_REG_STOP_MASTER);
1522 /* wait stop master not more than 50 usec.
1523 * Otherwise return error. */
1524 for (i = 5; i > 0; i--) {
1527 /* Check master stop bit */
1528 read_register(priv->net_dev, IPW_REG_RESET_REG, ®);
1530 if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED)
1535 IPW_DEBUG_WARNING(DRV_NAME
1536 ": %s: Could now power down adapter.\n",
1537 priv->net_dev->name);
1539 /* assert s/w reset */
1540 write_register(priv->net_dev, IPW_REG_RESET_REG,
1541 IPW_AUX_HOST_RESET_REG_SW_RESET);
1543 priv->status &= ~(STATUS_RUNNING | STATUS_STOPPING);
1549 static int ipw2100_disable_adapter(struct ipw2100_priv *priv)
1551 struct host_command cmd = {
1552 .host_command = CARD_DISABLE,
1553 .host_command_sequence = 0,
1554 .host_command_length = 0
1558 IPW_DEBUG_HC("CARD_DISABLE\n");
1560 if (!(priv->status & STATUS_ENABLED))
1563 /* Make sure we clear the associated state */
1564 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1566 if (!priv->stop_hang_check) {
1567 priv->stop_hang_check = 1;
1568 cancel_delayed_work(&priv->hang_check);
1571 down(&priv->adapter_sem);
1573 err = ipw2100_hw_send_command(priv, &cmd);
1575 IPW_DEBUG_WARNING("exit - failed to send CARD_DISABLE command\n");
1579 err = ipw2100_wait_for_card_state(priv, IPW_HW_STATE_DISABLED);
1581 IPW_DEBUG_WARNING("exit - card failed to change to DISABLED\n");
1585 IPW_DEBUG_INFO("TODO: implement scan state machine\n");
1588 up(&priv->adapter_sem);
1592 int ipw2100_set_scan_options(struct ipw2100_priv *priv)
1594 struct host_command cmd = {
1595 .host_command = SET_SCAN_OPTIONS,
1596 .host_command_sequence = 0,
1597 .host_command_length = 8
1601 IPW_DEBUG_INFO("enter\n");
1603 IPW_DEBUG_SCAN("setting scan options\n");
1605 cmd.host_command_parameters[0] = 0;
1607 if (!(priv->config & CFG_ASSOCIATE))
1608 cmd.host_command_parameters[0] |= IPW_SCAN_NOASSOCIATE;
1609 if ((priv->sec.flags & SEC_ENABLED) && priv->sec.enabled)
1610 cmd.host_command_parameters[0] |= IPW_SCAN_MIXED_CELL;
1611 if (priv->config & CFG_PASSIVE_SCAN)
1612 cmd.host_command_parameters[0] |= IPW_SCAN_PASSIVE;
1614 cmd.host_command_parameters[1] = priv->channel_mask;
1616 err = ipw2100_hw_send_command(priv, &cmd);
1618 IPW_DEBUG_HC("SET_SCAN_OPTIONS 0x%04X\n",
1619 cmd.host_command_parameters[0]);
1624 int ipw2100_start_scan(struct ipw2100_priv *priv)
1626 struct host_command cmd = {
1627 .host_command = BROADCAST_SCAN,
1628 .host_command_sequence = 0,
1629 .host_command_length = 4
1633 IPW_DEBUG_HC("START_SCAN\n");
1635 cmd.host_command_parameters[0] = 0;
1637 /* No scanning if in monitor mode */
1638 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
1641 if (priv->status & STATUS_SCANNING) {
1642 IPW_DEBUG_SCAN("Scan requested while already in scan...\n");
1646 IPW_DEBUG_INFO("enter\n");
1648 /* Not clearing here; doing so makes iwlist always return nothing...
1650 * We should modify the table logic to use aging tables vs. clearing
1651 * the table on each scan start.
1653 IPW_DEBUG_SCAN("starting scan\n");
1655 priv->status |= STATUS_SCANNING;
1656 err = ipw2100_hw_send_command(priv, &cmd);
1658 priv->status &= ~STATUS_SCANNING;
1660 IPW_DEBUG_INFO("exit\n");
1665 static int ipw2100_up(struct ipw2100_priv *priv, int deferred)
1667 unsigned long flags;
1670 u32 ord_len = sizeof(lock);
1672 /* Quite if manually disabled. */
1673 if (priv->status & STATUS_RF_KILL_SW) {
1674 IPW_DEBUG_INFO("%s: Radio is disabled by Manual Disable "
1675 "switch\n", priv->net_dev->name);
1679 /* If the interrupt is enabled, turn it off... */
1680 spin_lock_irqsave(&priv->low_lock, flags);
1681 ipw2100_disable_interrupts(priv);
1683 /* Reset any fatal_error conditions */
1684 ipw2100_reset_fatalerror(priv);
1685 spin_unlock_irqrestore(&priv->low_lock, flags);
1687 if (priv->status & STATUS_POWERED ||
1688 (priv->status & STATUS_RESET_PENDING)) {
1689 /* Power cycle the card ... */
1690 if (ipw2100_power_cycle_adapter(priv)) {
1691 IPW_DEBUG_WARNING("%s: Could not cycle adapter.\n",
1692 priv->net_dev->name);
1697 priv->status |= STATUS_POWERED;
1699 /* Load the firmeware, start the clocks, etc. */
1700 if (ipw2100_start_adapter(priv)) {
1701 IPW_DEBUG_ERROR("%s: Failed to start the firmware.\n",
1702 priv->net_dev->name);
1707 ipw2100_initialize_ordinals(priv);
1709 /* Determine capabilities of this particular HW configuration */
1710 if (ipw2100_get_hw_features(priv)) {
1711 IPW_DEBUG_ERROR("%s: Failed to determine HW features.\n",
1712 priv->net_dev->name);
1718 if (ipw2100_set_ordinal(priv, IPW_ORD_PERS_DB_LOCK, &lock, &ord_len)) {
1719 IPW_DEBUG_ERROR("%s: Failed to clear ordinal lock.\n",
1720 priv->net_dev->name);
1725 priv->status &= ~STATUS_SCANNING;
1727 if (rf_kill_active(priv)) {
1728 printk(KERN_INFO "%s: Radio is disabled by RF switch.\n",
1729 priv->net_dev->name);
1731 if (priv->stop_rf_kill) {
1732 priv->stop_rf_kill = 0;
1733 queue_delayed_work(priv->workqueue, &priv->rf_kill, HZ);
1739 /* Turn on the interrupt so that commands can be processed */
1740 ipw2100_enable_interrupts(priv);
1742 /* Send all of the commands that must be sent prior to
1744 if (ipw2100_adapter_setup(priv)) {
1745 IPW_DEBUG_ERROR("%s: Failed to start the card.\n",
1746 priv->net_dev->name);
1752 /* Enable the adapter - sends HOST_COMPLETE */
1753 if (ipw2100_enable_adapter(priv)) {
1755 "%s: failed in call to enable adapter.\n",
1756 priv->net_dev->name);
1757 ipw2100_hw_stop_adapter(priv);
1763 /* Start a scan . . . */
1764 ipw2100_set_scan_options(priv);
1765 ipw2100_start_scan(priv);
1772 /* Called by register_netdev() */
1773 static int ipw2100_net_init(struct net_device *dev)
1775 struct ipw2100_priv *priv = ieee80211_priv(dev);
1776 return ipw2100_up(priv, 1);
1779 static void ipw2100_down(struct ipw2100_priv *priv)
1781 unsigned long flags;
1782 union iwreq_data wrqu = {
1784 .sa_family = ARPHRD_ETHER
1787 int associated = priv->status & STATUS_ASSOCIATED;
1789 /* Kill the RF switch timer */
1790 if (!priv->stop_rf_kill) {
1791 priv->stop_rf_kill = 1;
1792 cancel_delayed_work(&priv->rf_kill);
1795 /* Kill the firmare hang check timer */
1796 if (!priv->stop_hang_check) {
1797 priv->stop_hang_check = 1;
1798 cancel_delayed_work(&priv->hang_check);
1801 /* Kill any pending resets */
1802 if (priv->status & STATUS_RESET_PENDING)
1803 cancel_delayed_work(&priv->reset_work);
1805 /* Make sure the interrupt is on so that FW commands will be
1806 * processed correctly */
1807 spin_lock_irqsave(&priv->low_lock, flags);
1808 ipw2100_enable_interrupts(priv);
1809 spin_unlock_irqrestore(&priv->low_lock, flags);
1811 if (ipw2100_hw_stop_adapter(priv))
1812 IPW_DEBUG_ERROR("%s: Error stopping adapter.\n",
1813 priv->net_dev->name);
1815 /* Do not disable the interrupt until _after_ we disable
1816 * the adaptor. Otherwise the CARD_DISABLE command will never
1817 * be ack'd by the firmware */
1818 spin_lock_irqsave(&priv->low_lock, flags);
1819 ipw2100_disable_interrupts(priv);
1820 spin_unlock_irqrestore(&priv->low_lock, flags);
1822 #ifdef ACPI_CSTATE_LIMIT_DEFINED
1823 if (priv->config & CFG_C3_DISABLED) {
1824 IPW_DEBUG_INFO(DRV_NAME ": Resetting C3 transitions.\n");
1825 acpi_set_cstate_limit(priv->cstate_limit);
1826 priv->config &= ~CFG_C3_DISABLED;
1830 /* We have to signal any supplicant if we are disassociating */
1832 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1834 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1835 netif_carrier_off(priv->net_dev);
1836 netif_stop_queue(priv->net_dev);
1839 void ipw2100_reset_adapter(struct ipw2100_priv *priv)
1841 unsigned long flags;
1842 union iwreq_data wrqu = {
1844 .sa_family = ARPHRD_ETHER
1847 int associated = priv->status & STATUS_ASSOCIATED;
1849 spin_lock_irqsave(&priv->low_lock, flags);
1850 IPW_DEBUG_INFO(DRV_NAME ": %s: Restarting adapter.\n",
1851 priv->net_dev->name);
1853 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1854 priv->status |= STATUS_SECURITY_UPDATED;
1856 /* Force a power cycle even if interface hasn't been opened
1858 cancel_delayed_work(&priv->reset_work);
1859 priv->status |= STATUS_RESET_PENDING;
1860 spin_unlock_irqrestore(&priv->low_lock, flags);
1862 down(&priv->action_sem);
1863 /* stop timed checks so that they don't interfere with reset */
1864 priv->stop_hang_check = 1;
1865 cancel_delayed_work(&priv->hang_check);
1867 /* We have to signal any supplicant if we are disassociating */
1869 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1871 ipw2100_up(priv, 0);
1872 up(&priv->action_sem);
1877 static void isr_indicate_associated(struct ipw2100_priv *priv, u32 status)
1880 #define MAC_ASSOCIATION_READ_DELAY (HZ)
1881 int ret, len, essid_len;
1882 char essid[IW_ESSID_MAX_SIZE];
1889 * TBD: BSSID is usually 00:00:00:00:00:00 here and not
1890 * an actual MAC of the AP. Seems like FW sets this
1891 * address too late. Read it later and expose through
1892 * /proc or schedule a later task to query and update
1895 essid_len = IW_ESSID_MAX_SIZE;
1896 ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_SSID,
1899 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
1905 ret = ipw2100_get_ordinal(priv, IPW_ORD_CURRENT_TX_RATE,
1908 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
1914 ret = ipw2100_get_ordinal(priv, IPW_ORD_OUR_FREQ, &chan, &len);
1916 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
1921 ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID, &bssid, &len);
1923 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
1927 memcpy(priv->ieee->bssid, bssid, ETH_ALEN);
1931 case TX_RATE_1_MBIT:
1932 txratename = "1Mbps";
1934 case TX_RATE_2_MBIT:
1935 txratename = "2Mbsp";
1937 case TX_RATE_5_5_MBIT:
1938 txratename = "5.5Mbps";
1940 case TX_RATE_11_MBIT:
1941 txratename = "11Mbps";
1944 IPW_DEBUG_INFO("Unknown rate: %d\n", txrate);
1945 txratename = "unknown rate";
1949 IPW_DEBUG_INFO("%s: Associated with '%s' at %s, channel %d (BSSID="
1951 priv->net_dev->name, escape_essid(essid, essid_len),
1952 txratename, chan, MAC_ARG(bssid));
1954 /* now we copy read ssid into dev */
1955 if (!(priv->config & CFG_STATIC_ESSID)) {
1956 priv->essid_len = min((u8)essid_len, (u8)IW_ESSID_MAX_SIZE);
1957 memcpy(priv->essid, essid, priv->essid_len);
1959 priv->channel = chan;
1960 memcpy(priv->bssid, bssid, ETH_ALEN);
1962 priv->status |= STATUS_ASSOCIATING;
1963 priv->connect_start = get_seconds();
1965 queue_delayed_work(priv->workqueue, &priv->wx_event_work, HZ / 10);
1969 int ipw2100_set_essid(struct ipw2100_priv *priv, char *essid,
1970 int length, int batch_mode)
1972 int ssid_len = min(length, IW_ESSID_MAX_SIZE);
1973 struct host_command cmd = {
1974 .host_command = SSID,
1975 .host_command_sequence = 0,
1976 .host_command_length = ssid_len
1980 IPW_DEBUG_HC("SSID: '%s'\n", escape_essid(essid, ssid_len));
1983 memcpy((char*)cmd.host_command_parameters,
1987 err = ipw2100_disable_adapter(priv);
1992 /* Bug in FW currently doesn't honor bit 0 in SET_SCAN_OPTIONS to
1993 * disable auto association -- so we cheat by setting a bogus SSID */
1994 if (!ssid_len && !(priv->config & CFG_ASSOCIATE)) {
1996 u8 *bogus = (u8*)cmd.host_command_parameters;
1997 for (i = 0; i < IW_ESSID_MAX_SIZE; i++)
1998 bogus[i] = 0x18 + i;
1999 cmd.host_command_length = IW_ESSID_MAX_SIZE;
2002 /* NOTE: We always send the SSID command even if the provided ESSID is
2003 * the same as what we currently think is set. */
2005 err = ipw2100_hw_send_command(priv, &cmd);
2007 memset(priv->essid + ssid_len, 0,
2008 IW_ESSID_MAX_SIZE - ssid_len);
2009 memcpy(priv->essid, essid, ssid_len);
2010 priv->essid_len = ssid_len;
2014 if (ipw2100_enable_adapter(priv))
2021 static void isr_indicate_association_lost(struct ipw2100_priv *priv, u32 status)
2023 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | IPW_DL_ASSOC,
2024 "disassociated: '%s' " MAC_FMT " \n",
2025 escape_essid(priv->essid, priv->essid_len),
2026 MAC_ARG(priv->bssid));
2028 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
2030 if (priv->status & STATUS_STOPPING) {
2031 IPW_DEBUG_INFO("Card is stopping itself, discard ASSN_LOST.\n");
2035 memset(priv->bssid, 0, ETH_ALEN);
2036 memset(priv->ieee->bssid, 0, ETH_ALEN);
2038 netif_carrier_off(priv->net_dev);
2039 netif_stop_queue(priv->net_dev);
2041 if (!(priv->status & STATUS_RUNNING))
2044 if (priv->status & STATUS_SECURITY_UPDATED)
2045 queue_work(priv->workqueue, &priv->security_work);
2047 queue_work(priv->workqueue, &priv->wx_event_work);
2050 static void isr_indicate_rf_kill(struct ipw2100_priv *priv, u32 status)
2052 IPW_DEBUG_INFO("%s: RF Kill state changed to radio OFF.\n",
2053 priv->net_dev->name);
2055 /* RF_KILL is now enabled (else we wouldn't be here) */
2056 priv->status |= STATUS_RF_KILL_HW;
2058 #ifdef ACPI_CSTATE_LIMIT_DEFINED
2059 if (priv->config & CFG_C3_DISABLED) {
2060 IPW_DEBUG_INFO(DRV_NAME ": Resetting C3 transitions.\n");
2061 acpi_set_cstate_limit(priv->cstate_limit);
2062 priv->config &= ~CFG_C3_DISABLED;
2066 /* Make sure the RF Kill check timer is running */
2067 priv->stop_rf_kill = 0;
2068 cancel_delayed_work(&priv->rf_kill);
2069 queue_delayed_work(priv->workqueue, &priv->rf_kill, HZ);
2072 static void isr_scan_complete(struct ipw2100_priv *priv, u32 status)
2074 IPW_DEBUG_SCAN("scan complete\n");
2075 /* Age the scan results... */
2076 priv->ieee->scans++;
2077 priv->status &= ~STATUS_SCANNING;
2080 #ifdef CONFIG_IPW_DEBUG
2081 #define IPW2100_HANDLER(v, f) { v, f, # v }
2082 struct ipw2100_status_indicator {
2084 void (*cb)(struct ipw2100_priv *priv, u32 status);
2088 #define IPW2100_HANDLER(v, f) { v, f }
2089 struct ipw2100_status_indicator {
2091 void (*cb)(struct ipw2100_priv *priv, u32 status);
2093 #endif /* CONFIG_IPW_DEBUG */
2095 static void isr_indicate_scanning(struct ipw2100_priv *priv, u32 status)
2097 IPW_DEBUG_SCAN("Scanning...\n");
2098 priv->status |= STATUS_SCANNING;
2101 const struct ipw2100_status_indicator status_handlers[] = {
2102 IPW2100_HANDLER(IPW_STATE_INITIALIZED, 0),
2103 IPW2100_HANDLER(IPW_STATE_COUNTRY_FOUND, 0),
2104 IPW2100_HANDLER(IPW_STATE_ASSOCIATED, isr_indicate_associated),
2105 IPW2100_HANDLER(IPW_STATE_ASSN_LOST, isr_indicate_association_lost),
2106 IPW2100_HANDLER(IPW_STATE_ASSN_CHANGED, 0),
2107 IPW2100_HANDLER(IPW_STATE_SCAN_COMPLETE, isr_scan_complete),
2108 IPW2100_HANDLER(IPW_STATE_ENTERED_PSP, 0),
2109 IPW2100_HANDLER(IPW_STATE_LEFT_PSP, 0),
2110 IPW2100_HANDLER(IPW_STATE_RF_KILL, isr_indicate_rf_kill),
2111 IPW2100_HANDLER(IPW_STATE_DISABLED, 0),
2112 IPW2100_HANDLER(IPW_STATE_POWER_DOWN, 0),
2113 IPW2100_HANDLER(IPW_STATE_SCANNING, isr_indicate_scanning),
2114 IPW2100_HANDLER(-1, 0)
2118 static void isr_status_change(struct ipw2100_priv *priv, int status)
2122 if (status == IPW_STATE_SCANNING &&
2123 priv->status & STATUS_ASSOCIATED &&
2124 !(priv->status & STATUS_SCANNING)) {
2125 IPW_DEBUG_INFO("Scan detected while associated, with "
2126 "no scan request. Restarting firmware.\n");
2128 /* Wake up any sleeping jobs */
2129 schedule_reset(priv);
2132 for (i = 0; status_handlers[i].status != -1; i++) {
2133 if (status == status_handlers[i].status) {
2134 IPW_DEBUG_NOTIF("Status change: %s\n",
2135 status_handlers[i].name);
2136 if (status_handlers[i].cb)
2137 status_handlers[i].cb(priv, status);
2138 priv->wstats.status = status;
2143 IPW_DEBUG_NOTIF("unknown status received: %04x\n", status);
2146 static void isr_rx_complete_command(
2147 struct ipw2100_priv *priv,
2148 struct ipw2100_cmd_header *cmd)
2150 #ifdef CONFIG_IPW_DEBUG
2151 if (cmd->host_command_reg < ARRAY_SIZE(command_types)) {
2152 IPW_DEBUG_HC("Command completed '%s (%d)'\n",
2153 command_types[cmd->host_command_reg],
2154 cmd->host_command_reg);
2157 if (cmd->host_command_reg == HOST_COMPLETE)
2158 priv->status |= STATUS_ENABLED;
2160 if (cmd->host_command_reg == CARD_DISABLE)
2161 priv->status &= ~STATUS_ENABLED;
2163 priv->status &= ~STATUS_CMD_ACTIVE;
2165 wake_up_interruptible(&priv->wait_command_queue);
2168 #ifdef CONFIG_IPW_DEBUG
2169 const char *frame_types[] = {
2170 "COMMAND_STATUS_VAL",
2171 "STATUS_CHANGE_VAL",
2174 "HOST_NOTIFICATION_VAL"
2179 static inline int ipw2100_alloc_skb(
2180 struct ipw2100_priv *priv,
2181 struct ipw2100_rx_packet *packet)
2183 packet->skb = dev_alloc_skb(sizeof(struct ipw2100_rx));
2187 packet->rxp = (struct ipw2100_rx *)packet->skb->data;
2188 packet->dma_addr = pci_map_single(priv->pci_dev, packet->skb->data,
2189 sizeof(struct ipw2100_rx),
2190 PCI_DMA_FROMDEVICE);
2191 /* NOTE: pci_map_single does not return an error code, and 0 is a valid
2198 #define SEARCH_ERROR 0xffffffff
2199 #define SEARCH_FAIL 0xfffffffe
2200 #define SEARCH_SUCCESS 0xfffffff0
2201 #define SEARCH_DISCARD 0
2202 #define SEARCH_SNAPSHOT 1
2204 #define SNAPSHOT_ADDR(ofs) (priv->snapshot[((ofs) >> 12) & 0xff] + ((ofs) & 0xfff))
2205 static inline int ipw2100_snapshot_alloc(struct ipw2100_priv *priv)
2208 if (priv->snapshot[0])
2210 for (i = 0; i < 0x30; i++) {
2211 priv->snapshot[i] = (u8*)kmalloc(0x1000, GFP_ATOMIC);
2212 if (!priv->snapshot[i]) {
2213 IPW_DEBUG_INFO("%s: Error allocating snapshot "
2214 "buffer %d\n", priv->net_dev->name, i);
2216 kfree(priv->snapshot[--i]);
2217 priv->snapshot[0] = NULL;
2225 static inline void ipw2100_snapshot_free(struct ipw2100_priv *priv)
2228 if (!priv->snapshot[0])
2230 for (i = 0; i < 0x30; i++)
2231 kfree(priv->snapshot[i]);
2232 priv->snapshot[0] = NULL;
2235 static inline u32 ipw2100_match_buf(struct ipw2100_priv *priv, u8 *in_buf,
2236 size_t len, int mode)
2244 if (mode == SEARCH_SNAPSHOT) {
2245 if (!ipw2100_snapshot_alloc(priv))
2246 mode = SEARCH_DISCARD;
2249 for (ret = SEARCH_FAIL, i = 0; i < 0x30000; i += 4) {
2250 read_nic_dword(priv->net_dev, i, &tmp);
2251 if (mode == SEARCH_SNAPSHOT)
2252 *(u32 *)SNAPSHOT_ADDR(i) = tmp;
2253 if (ret == SEARCH_FAIL) {
2255 for (j = 0; j < 4; j++) {
2264 if ((s - in_buf) == len)
2265 ret = (i + j) - len + 1;
2267 } else if (mode == SEARCH_DISCARD)
2276 * 0) Disconnect the SKB from the firmware (just unmap)
2277 * 1) Pack the ETH header into the SKB
2278 * 2) Pass the SKB to the network stack
2280 * When packet is provided by the firmware, it contains the following:
2283 * . ieee80211_snap_hdr
2285 * The size of the constructed ethernet
2288 #ifdef CONFIG_IPW2100_RX_DEBUG
2289 u8 packet_data[IPW_RX_NIC_BUFFER_LENGTH];
2292 static inline void ipw2100_corruption_detected(struct ipw2100_priv *priv,
2295 #ifdef CONFIG_IPW_DEBUG_C3
2296 struct ipw2100_status *status = &priv->status_queue.drv[i];
2300 #ifdef ACPI_CSTATE_LIMIT_DEFINED
2304 IPW_DEBUG_INFO(DRV_NAME ": PCI latency error detected at "
2305 "0x%04X.\n", i * sizeof(struct ipw2100_status));
2307 #ifdef ACPI_CSTATE_LIMIT_DEFINED
2308 IPW_DEBUG_INFO(DRV_NAME ": Disabling C3 transitions.\n");
2309 limit = acpi_get_cstate_limit();
2311 priv->cstate_limit = limit;
2312 acpi_set_cstate_limit(2);
2313 priv->config |= CFG_C3_DISABLED;
2317 #ifdef CONFIG_IPW_DEBUG_C3
2318 /* Halt the fimrware so we can get a good image */
2319 write_register(priv->net_dev, IPW_REG_RESET_REG,
2320 IPW_AUX_HOST_RESET_REG_STOP_MASTER);
2323 udelay(IPW_WAIT_RESET_MASTER_ASSERT_COMPLETE_DELAY);
2324 read_register(priv->net_dev, IPW_REG_RESET_REG, ®);
2326 if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED)
2330 match = ipw2100_match_buf(priv, (u8*)status,
2331 sizeof(struct ipw2100_status),
2333 if (match < SEARCH_SUCCESS)
2334 IPW_DEBUG_INFO("%s: DMA status match in Firmware at "
2335 "offset 0x%06X, length %d:\n",
2336 priv->net_dev->name, match,
2337 sizeof(struct ipw2100_status));
2339 IPW_DEBUG_INFO("%s: No DMA status match in "
2340 "Firmware.\n", priv->net_dev->name);
2342 printk_buf((u8*)priv->status_queue.drv,
2343 sizeof(struct ipw2100_status) * RX_QUEUE_LENGTH);
2346 priv->fatal_error = IPW2100_ERR_C3_CORRUPTION;
2347 priv->ieee->stats.rx_errors++;
2348 schedule_reset(priv);
2351 static inline void isr_rx(struct ipw2100_priv *priv, int i,
2352 struct ieee80211_rx_stats *stats)
2354 struct ipw2100_status *status = &priv->status_queue.drv[i];
2355 struct ipw2100_rx_packet *packet = &priv->rx_buffers[i];
2357 IPW_DEBUG_RX("Handler...\n");
2359 if (unlikely(status->frame_size > skb_tailroom(packet->skb))) {
2360 IPW_DEBUG_INFO("%s: frame_size (%u) > skb_tailroom (%u)!"
2362 priv->net_dev->name,
2363 status->frame_size, skb_tailroom(packet->skb));
2364 priv->ieee->stats.rx_errors++;
2368 if (unlikely(!netif_running(priv->net_dev))) {
2369 priv->ieee->stats.rx_errors++;
2370 priv->wstats.discard.misc++;
2371 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
2375 if (unlikely(priv->ieee->iw_mode == IW_MODE_MONITOR &&
2376 status->flags & IPW_STATUS_FLAG_CRC_ERROR)) {
2377 IPW_DEBUG_RX("CRC error in packet. Dropping.\n");
2378 priv->ieee->stats.rx_errors++;
2382 if (unlikely(priv->ieee->iw_mode != IW_MODE_MONITOR &&
2383 !(priv->status & STATUS_ASSOCIATED))) {
2384 IPW_DEBUG_DROP("Dropping packet while not associated.\n");
2385 priv->wstats.discard.misc++;
2390 pci_unmap_single(priv->pci_dev,
2392 sizeof(struct ipw2100_rx),
2393 PCI_DMA_FROMDEVICE);
2395 skb_put(packet->skb, status->frame_size);
2397 #ifdef CONFIG_IPW2100_RX_DEBUG
2398 /* Make a copy of the frame so we can dump it to the logs if
2399 * ieee80211_rx fails */
2400 memcpy(packet_data, packet->skb->data,
2401 min(status->frame_size, IPW_RX_NIC_BUFFER_LENGTH));
2404 if (!ieee80211_rx(priv->ieee, packet->skb, stats)) {
2405 #ifdef CONFIG_IPW2100_RX_DEBUG
2406 IPW_DEBUG_DROP("%s: Non consumed packet:\n",
2407 priv->net_dev->name);
2408 printk_buf(IPW_DL_DROP, packet_data, status->frame_size);
2410 priv->ieee->stats.rx_errors++;
2412 /* ieee80211_rx failed, so it didn't free the SKB */
2413 dev_kfree_skb_any(packet->skb);
2417 /* We need to allocate a new SKB and attach it to the RDB. */
2418 if (unlikely(ipw2100_alloc_skb(priv, packet))) {
2420 "%s: Unable to allocate SKB onto RBD ring - disabling "
2421 "adapter.\n", priv->net_dev->name);
2422 /* TODO: schedule adapter shutdown */
2423 IPW_DEBUG_INFO("TODO: Shutdown adapter...\n");
2426 /* Update the RDB entry */
2427 priv->rx_queue.drv[i].host_addr = packet->dma_addr;
2430 static inline int ipw2100_corruption_check(struct ipw2100_priv *priv, int i)
2432 struct ipw2100_status *status = &priv->status_queue.drv[i];
2433 struct ipw2100_rx *u = priv->rx_buffers[i].rxp;
2434 u16 frame_type = status->status_fields & STATUS_TYPE_MASK;
2436 switch (frame_type) {
2437 case COMMAND_STATUS_VAL:
2438 return (status->frame_size != sizeof(u->rx_data.command));
2439 case STATUS_CHANGE_VAL:
2440 return (status->frame_size != sizeof(u->rx_data.status));
2441 case HOST_NOTIFICATION_VAL:
2442 return (status->frame_size < sizeof(u->rx_data.notification));
2443 case P80211_DATA_VAL:
2444 case P8023_DATA_VAL:
2445 #ifdef CONFIG_IPW2100_MONITOR
2448 switch (WLAN_FC_GET_TYPE(u->rx_data.header.frame_ctl)) {
2449 case IEEE80211_FTYPE_MGMT:
2450 case IEEE80211_FTYPE_CTL:
2452 case IEEE80211_FTYPE_DATA:
2453 return (status->frame_size >
2454 IPW_MAX_802_11_PAYLOAD_LENGTH);
2463 * ipw2100 interrupts are disabled at this point, and the ISR
2464 * is the only code that calls this method. So, we do not need
2465 * to play with any locks.
2467 * RX Queue works as follows:
2469 * Read index - firmware places packet in entry identified by the
2470 * Read index and advances Read index. In this manner,
2471 * Read index will always point to the next packet to
2472 * be filled--but not yet valid.
2474 * Write index - driver fills this entry with an unused RBD entry.
2475 * This entry has not filled by the firmware yet.
2477 * In between the W and R indexes are the RBDs that have been received
2478 * but not yet processed.
2480 * The process of handling packets will start at WRITE + 1 and advance
2481 * until it reaches the READ index.
2483 * The WRITE index is cached in the variable 'priv->rx_queue.next'.
2486 static inline void __ipw2100_rx_process(struct ipw2100_priv *priv)
2488 struct ipw2100_bd_queue *rxq = &priv->rx_queue;
2489 struct ipw2100_status_queue *sq = &priv->status_queue;
2490 struct ipw2100_rx_packet *packet;
2493 struct ipw2100_rx *u;
2494 struct ieee80211_rx_stats stats = {
2495 .mac_time = jiffies,
2498 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_READ_INDEX, &r);
2499 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_WRITE_INDEX, &w);
2501 if (r >= rxq->entries) {
2502 IPW_DEBUG_RX("exit - bad read index\n");
2506 i = (rxq->next + 1) % rxq->entries;
2509 /* IPW_DEBUG_RX("r = %d : w = %d : processing = %d\n",
2510 r, rxq->next, i); */
2512 packet = &priv->rx_buffers[i];
2514 /* Sync the DMA for the STATUS buffer so CPU is sure to get
2515 * the correct values */
2516 pci_dma_sync_single_for_cpu(
2518 sq->nic + sizeof(struct ipw2100_status) * i,
2519 sizeof(struct ipw2100_status),
2520 PCI_DMA_FROMDEVICE);
2522 /* Sync the DMA for the RX buffer so CPU is sure to get
2523 * the correct values */
2524 pci_dma_sync_single_for_cpu(priv->pci_dev, packet->dma_addr,
2525 sizeof(struct ipw2100_rx),
2526 PCI_DMA_FROMDEVICE);
2528 if (unlikely(ipw2100_corruption_check(priv, i))) {
2529 ipw2100_corruption_detected(priv, i);
2534 frame_type = sq->drv[i].status_fields &
2536 stats.rssi = sq->drv[i].rssi + IPW2100_RSSI_TO_DBM;
2537 stats.len = sq->drv[i].frame_size;
2540 if (stats.rssi != 0)
2541 stats.mask |= IEEE80211_STATMASK_RSSI;
2542 stats.freq = IEEE80211_24GHZ_BAND;
2545 "%s: '%s' frame type received (%d).\n",
2546 priv->net_dev->name, frame_types[frame_type],
2549 switch (frame_type) {
2550 case COMMAND_STATUS_VAL:
2551 /* Reset Rx watchdog */
2552 isr_rx_complete_command(
2553 priv, &u->rx_data.command);
2556 case STATUS_CHANGE_VAL:
2557 isr_status_change(priv, u->rx_data.status);
2560 case P80211_DATA_VAL:
2561 case P8023_DATA_VAL:
2562 #ifdef CONFIG_IPW2100_MONITOR
2563 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
2564 isr_rx(priv, i, &stats);
2568 if (stats.len < sizeof(u->rx_data.header))
2570 switch (WLAN_FC_GET_TYPE(u->rx_data.header.
2572 case IEEE80211_FTYPE_MGMT:
2573 ieee80211_rx_mgt(priv->ieee,
2578 case IEEE80211_FTYPE_CTL:
2581 case IEEE80211_FTYPE_DATA:
2582 isr_rx(priv, i, &stats);
2590 /* clear status field associated with this RBD */
2591 rxq->drv[i].status.info.field = 0;
2593 i = (i + 1) % rxq->entries;
2597 /* backtrack one entry, wrapping to end if at 0 */
2598 rxq->next = (i ? i : rxq->entries) - 1;
2600 write_register(priv->net_dev,
2601 IPW_MEM_HOST_SHARED_RX_WRITE_INDEX,
2608 * __ipw2100_tx_process
2610 * This routine will determine whether the next packet on
2611 * the fw_pend_list has been processed by the firmware yet.
2613 * If not, then it does nothing and returns.
2615 * If so, then it removes the item from the fw_pend_list, frees
2616 * any associated storage, and places the item back on the
2617 * free list of its source (either msg_free_list or tx_free_list)
2619 * TX Queue works as follows:
2621 * Read index - points to the next TBD that the firmware will
2622 * process. The firmware will read the data, and once
2623 * done processing, it will advance the Read index.
2625 * Write index - driver fills this entry with an constructed TBD
2626 * entry. The Write index is not advanced until the
2627 * packet has been configured.
2629 * In between the W and R indexes are the TBDs that have NOT been
2630 * processed. Lagging behind the R index are packets that have
2631 * been processed but have not been freed by the driver.
2633 * In order to free old storage, an internal index will be maintained
2634 * that points to the next packet to be freed. When all used
2635 * packets have been freed, the oldest index will be the same as the
2636 * firmware's read index.
2638 * The OLDEST index is cached in the variable 'priv->tx_queue.oldest'
2640 * Because the TBD structure can not contain arbitrary data, the
2641 * driver must keep an internal queue of cached allocations such that
2642 * it can put that data back into the tx_free_list and msg_free_list
2643 * for use by future command and data packets.
2646 static inline int __ipw2100_tx_process(struct ipw2100_priv *priv)
2648 struct ipw2100_bd_queue *txq = &priv->tx_queue;
2649 struct ipw2100_bd *tbd;
2650 struct list_head *element;
2651 struct ipw2100_tx_packet *packet;
2652 int descriptors_used;
2654 u32 r, w, frag_num = 0;
2656 if (list_empty(&priv->fw_pend_list))
2659 element = priv->fw_pend_list.next;
2661 packet = list_entry(element, struct ipw2100_tx_packet, list);
2662 tbd = &txq->drv[packet->index];
2664 /* Determine how many TBD entries must be finished... */
2665 switch (packet->type) {
2667 /* COMMAND uses only one slot; don't advance */
2668 descriptors_used = 1;
2673 /* DATA uses two slots; advance and loop position. */
2674 descriptors_used = tbd->num_fragments;
2675 frag_num = tbd->num_fragments - 1;
2676 e = txq->oldest + frag_num;
2681 IPW_DEBUG_WARNING("%s: Bad fw_pend_list entry!\n",
2682 priv->net_dev->name);
2686 /* if the last TBD is not done by NIC yet, then packet is
2687 * not ready to be released.
2690 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_TX_QUEUE_READ_INDEX,
2692 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX,
2695 IPW_DEBUG_WARNING("%s: write index mismatch\n",
2696 priv->net_dev->name);
2699 * txq->next is the index of the last packet written txq->oldest is
2700 * the index of the r is the index of the next packet to be read by
2706 * Quick graphic to help you visualize the following
2707 * if / else statement
2709 * ===>| s---->|===============
2711 * | a | b | c | d | e | f | g | h | i | j | k | l
2715 * w - updated by driver
2716 * r - updated by firmware
2717 * s - start of oldest BD entry (txq->oldest)
2718 * e - end of oldest BD entry
2721 if (!((r <= w && (e < r || e >= w)) || (e < r && e >= w))) {
2722 IPW_DEBUG_TX("exit - no processed packets ready to release.\n");
2727 DEC_STAT(&priv->fw_pend_stat);
2729 #ifdef CONFIG_IPW_DEBUG
2731 int i = txq->oldest;
2733 "TX%d V=%p P=%p T=%p L=%d\n", i,
2735 (void*)txq->nic + i * sizeof(struct ipw2100_bd),
2736 (void*)txq->drv[i].host_addr,
2737 txq->drv[i].buf_length);
2739 if (packet->type == DATA) {
2740 i = (i + 1) % txq->entries;
2743 "TX%d V=%p P=%p T=%p L=%d\n", i,
2745 (void*)txq->nic + i *
2746 sizeof(struct ipw2100_bd),
2747 (void*)txq->drv[i].host_addr,
2748 txq->drv[i].buf_length);
2753 switch (packet->type) {
2755 if (txq->drv[txq->oldest].status.info.fields.txType != 0)
2756 IPW_DEBUG_WARNING("%s: Queue mismatch. "
2757 "Expecting DATA TBD but pulled "
2758 "something else: ids %d=%d.\n",
2759 priv->net_dev->name, txq->oldest, packet->index);
2761 /* DATA packet; we have to unmap and free the SKB */
2762 priv->ieee->stats.tx_packets++;
2763 for (i = 0; i < frag_num; i++) {
2764 tbd = &txq->drv[(packet->index + 1 + i) %
2768 "TX%d P=%08x L=%d\n",
2769 (packet->index + 1 + i) % txq->entries,
2770 tbd->host_addr, tbd->buf_length);
2772 pci_unmap_single(priv->pci_dev,
2778 priv->ieee->stats.tx_bytes += packet->info.d_struct.txb->payload_size;
2779 ieee80211_txb_free(packet->info.d_struct.txb);
2780 packet->info.d_struct.txb = NULL;
2782 list_add_tail(element, &priv->tx_free_list);
2783 INC_STAT(&priv->tx_free_stat);
2785 /* We have a free slot in the Tx queue, so wake up the
2786 * transmit layer if it is stopped. */
2787 if (priv->status & STATUS_ASSOCIATED &&
2788 netif_queue_stopped(priv->net_dev)) {
2789 IPW_DEBUG_INFO(KERN_INFO
2790 "%s: Waking net queue.\n",
2791 priv->net_dev->name);
2792 netif_wake_queue(priv->net_dev);
2795 /* A packet was processed by the hardware, so update the
2797 priv->net_dev->trans_start = jiffies;
2802 if (txq->drv[txq->oldest].status.info.fields.txType != 1)
2803 IPW_DEBUG_WARNING("%s: Queue mismatch. "
2804 "Expecting COMMAND TBD but pulled "
2805 "something else: ids %d=%d.\n",
2806 priv->net_dev->name, txq->oldest, packet->index);
2808 #ifdef CONFIG_IPW_DEBUG
2809 if (packet->info.c_struct.cmd->host_command_reg <
2810 sizeof(command_types) / sizeof(*command_types))
2812 "Command '%s (%d)' processed: %d.\n",
2813 command_types[packet->info.c_struct.cmd->host_command_reg],
2814 packet->info.c_struct.cmd->host_command_reg,
2815 packet->info.c_struct.cmd->cmd_status_reg);
2818 list_add_tail(element, &priv->msg_free_list);
2819 INC_STAT(&priv->msg_free_stat);
2823 /* advance oldest used TBD pointer to start of next entry */
2824 txq->oldest = (e + 1) % txq->entries;
2825 /* increase available TBDs number */
2826 txq->available += descriptors_used;
2827 SET_STAT(&priv->txq_stat, txq->available);
2829 IPW_DEBUG_TX("packet latency (send to process) %ld jiffies\n",
2830 jiffies - packet->jiffy_start);
2832 return (!list_empty(&priv->fw_pend_list));
2836 static inline void __ipw2100_tx_complete(struct ipw2100_priv *priv)
2840 while (__ipw2100_tx_process(priv) && i < 200) i++;
2844 "%s: Driver is running slow (%d iters).\n",
2845 priv->net_dev->name, i);
2850 static void X__ipw2100_tx_send_commands(struct ipw2100_priv *priv)
2852 struct list_head *element;
2853 struct ipw2100_tx_packet *packet;
2854 struct ipw2100_bd_queue *txq = &priv->tx_queue;
2855 struct ipw2100_bd *tbd;
2856 int next = txq->next;
2858 while (!list_empty(&priv->msg_pend_list)) {
2859 /* if there isn't enough space in TBD queue, then
2860 * don't stuff a new one in.
2861 * NOTE: 3 are needed as a command will take one,
2862 * and there is a minimum of 2 that must be
2863 * maintained between the r and w indexes
2865 if (txq->available <= 3) {
2866 IPW_DEBUG_TX("no room in tx_queue\n");
2870 element = priv->msg_pend_list.next;
2872 DEC_STAT(&priv->msg_pend_stat);
2874 packet = list_entry(element,
2875 struct ipw2100_tx_packet, list);
2877 IPW_DEBUG_TX("using TBD at virt=%p, phys=%p\n",
2878 &txq->drv[txq->next],
2879 (void*)(txq->nic + txq->next *
2880 sizeof(struct ipw2100_bd)));
2882 packet->index = txq->next;
2884 tbd = &txq->drv[txq->next];
2886 /* initialize TBD */
2887 tbd->host_addr = packet->info.c_struct.cmd_phys;
2888 tbd->buf_length = sizeof(struct ipw2100_cmd_header);
2889 /* not marking number of fragments causes problems
2890 * with f/w debug version */
2891 tbd->num_fragments = 1;
2892 tbd->status.info.field =
2893 IPW_BD_STATUS_TX_FRAME_COMMAND |
2894 IPW_BD_STATUS_TX_INTERRUPT_ENABLE;
2896 /* update TBD queue counters */
2898 txq->next %= txq->entries;
2900 DEC_STAT(&priv->txq_stat);
2902 list_add_tail(element, &priv->fw_pend_list);
2903 INC_STAT(&priv->fw_pend_stat);
2906 if (txq->next != next) {
2907 /* kick off the DMA by notifying firmware the
2908 * write index has moved; make sure TBD stores are sync'd */
2910 write_register(priv->net_dev,
2911 IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX,
2918 * X__ipw2100_tx_send_data
2921 static void X__ipw2100_tx_send_data(struct ipw2100_priv *priv)
2923 struct list_head *element;
2924 struct ipw2100_tx_packet *packet;
2925 struct ipw2100_bd_queue *txq = &priv->tx_queue;
2926 struct ipw2100_bd *tbd;
2927 int next = txq->next;
2929 struct ipw2100_data_header *ipw_hdr;
2930 struct ieee80211_hdr *hdr;
2932 while (!list_empty(&priv->tx_pend_list)) {
2933 /* if there isn't enough space in TBD queue, then
2934 * don't stuff a new one in.
2935 * NOTE: 4 are needed as a data will take two,
2936 * and there is a minimum of 2 that must be
2937 * maintained between the r and w indexes
2939 element = priv->tx_pend_list.next;
2940 packet = list_entry(element, struct ipw2100_tx_packet, list);
2942 if (unlikely(1 + packet->info.d_struct.txb->nr_frags >
2944 /* TODO: Support merging buffers if more than
2945 * IPW_MAX_BDS are used */
2947 "%s: Maximum BD theshold exceeded. "
2948 "Increase fragmentation level.\n",
2949 priv->net_dev->name);
2952 if (txq->available <= 3 +
2953 packet->info.d_struct.txb->nr_frags) {
2954 IPW_DEBUG_TX("no room in tx_queue\n");
2959 DEC_STAT(&priv->tx_pend_stat);
2961 tbd = &txq->drv[txq->next];
2963 packet->index = txq->next;
2965 ipw_hdr = packet->info.d_struct.data;
2966 hdr = (struct ieee80211_hdr *)packet->info.d_struct.txb->
2969 if (priv->ieee->iw_mode == IW_MODE_INFRA) {
2970 /* To DS: Addr1 = BSSID, Addr2 = SA,
2972 memcpy(ipw_hdr->src_addr, hdr->addr2, ETH_ALEN);
2973 memcpy(ipw_hdr->dst_addr, hdr->addr3, ETH_ALEN);
2974 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
2975 /* not From/To DS: Addr1 = DA, Addr2 = SA,
2977 memcpy(ipw_hdr->src_addr, hdr->addr2, ETH_ALEN);
2978 memcpy(ipw_hdr->dst_addr, hdr->addr1, ETH_ALEN);
2981 ipw_hdr->host_command_reg = SEND;
2982 ipw_hdr->host_command_reg1 = 0;
2984 /* For now we only support host based encryption */
2985 ipw_hdr->needs_encryption = 0;
2986 ipw_hdr->encrypted = packet->info.d_struct.txb->encrypted;
2987 if (packet->info.d_struct.txb->nr_frags > 1)
2988 ipw_hdr->fragment_size =
2989 packet->info.d_struct.txb->frag_size - IEEE80211_3ADDR_LEN;
2991 ipw_hdr->fragment_size = 0;
2993 tbd->host_addr = packet->info.d_struct.data_phys;
2994 tbd->buf_length = sizeof(struct ipw2100_data_header);
2995 tbd->num_fragments = 1 + packet->info.d_struct.txb->nr_frags;
2996 tbd->status.info.field =
2997 IPW_BD_STATUS_TX_FRAME_802_3 |
2998 IPW_BD_STATUS_TX_FRAME_NOT_LAST_FRAGMENT;
3000 txq->next %= txq->entries;
3003 "data header tbd TX%d P=%08x L=%d\n",
3004 packet->index, tbd->host_addr,
3006 #ifdef CONFIG_IPW_DEBUG
3007 if (packet->info.d_struct.txb->nr_frags > 1)
3008 IPW_DEBUG_FRAG("fragment Tx: %d frames\n",
3009 packet->info.d_struct.txb->nr_frags);
3012 for (i = 0; i < packet->info.d_struct.txb->nr_frags; i++) {
3013 tbd = &txq->drv[txq->next];
3014 if (i == packet->info.d_struct.txb->nr_frags - 1)
3015 tbd->status.info.field =
3016 IPW_BD_STATUS_TX_FRAME_802_3 |
3017 IPW_BD_STATUS_TX_INTERRUPT_ENABLE;
3019 tbd->status.info.field =
3020 IPW_BD_STATUS_TX_FRAME_802_3 |
3021 IPW_BD_STATUS_TX_FRAME_NOT_LAST_FRAGMENT;
3023 tbd->buf_length = packet->info.d_struct.txb->
3024 fragments[i]->len - IEEE80211_3ADDR_LEN;
3026 tbd->host_addr = pci_map_single(
3028 packet->info.d_struct.txb->fragments[i]->data +
3029 IEEE80211_3ADDR_LEN,
3034 "data frag tbd TX%d P=%08x L=%d\n",
3035 txq->next, tbd->host_addr, tbd->buf_length);
3037 pci_dma_sync_single_for_device(
3038 priv->pci_dev, tbd->host_addr,
3043 txq->next %= txq->entries;
3046 txq->available -= 1 + packet->info.d_struct.txb->nr_frags;
3047 SET_STAT(&priv->txq_stat, txq->available);
3049 list_add_tail(element, &priv->fw_pend_list);
3050 INC_STAT(&priv->fw_pend_stat);
3053 if (txq->next != next) {
3054 /* kick off the DMA by notifying firmware the
3055 * write index has moved; make sure TBD stores are sync'd */
3056 write_register(priv->net_dev,
3057 IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX,
3063 static void ipw2100_irq_tasklet(struct ipw2100_priv *priv)
3065 struct net_device *dev = priv->net_dev;
3066 unsigned long flags;
3069 spin_lock_irqsave(&priv->low_lock, flags);
3070 ipw2100_disable_interrupts(priv);
3072 read_register(dev, IPW_REG_INTA, &inta);
3074 IPW_DEBUG_ISR("enter - INTA: 0x%08lX\n",
3075 (unsigned long)inta & IPW_INTERRUPT_MASK);
3080 /* We do not loop and keep polling for more interrupts as this
3081 * is frowned upon and doesn't play nicely with other potentially
3083 IPW_DEBUG_ISR("INTA: 0x%08lX\n",
3084 (unsigned long)inta & IPW_INTERRUPT_MASK);
3086 if (inta & IPW2100_INTA_FATAL_ERROR) {
3087 IPW_DEBUG_WARNING(DRV_NAME
3088 ": Fatal interrupt. Scheduling firmware restart.\n");
3092 IPW2100_INTA_FATAL_ERROR);
3094 read_nic_dword(dev, IPW_NIC_FATAL_ERROR, &priv->fatal_error);
3095 IPW_DEBUG_INFO("%s: Fatal error value: 0x%08X\n",
3096 priv->net_dev->name, priv->fatal_error);
3098 read_nic_dword(dev, IPW_ERROR_ADDR(priv->fatal_error), &tmp);
3099 IPW_DEBUG_INFO("%s: Fatal error address value: 0x%08X\n",
3100 priv->net_dev->name, tmp);
3102 /* Wake up any sleeping jobs */
3103 schedule_reset(priv);
3106 if (inta & IPW2100_INTA_PARITY_ERROR) {
3107 IPW_DEBUG_ERROR("***** PARITY ERROR INTERRUPT !!!! \n");
3111 IPW2100_INTA_PARITY_ERROR);
3114 if (inta & IPW2100_INTA_RX_TRANSFER) {
3115 IPW_DEBUG_ISR("RX interrupt\n");
3117 priv->rx_interrupts++;
3121 IPW2100_INTA_RX_TRANSFER);
3123 __ipw2100_rx_process(priv);
3124 __ipw2100_tx_complete(priv);
3127 if (inta & IPW2100_INTA_TX_TRANSFER) {
3128 IPW_DEBUG_ISR("TX interrupt\n");
3130 priv->tx_interrupts++;
3132 write_register(dev, IPW_REG_INTA,
3133 IPW2100_INTA_TX_TRANSFER);
3135 __ipw2100_tx_complete(priv);
3136 X__ipw2100_tx_send_commands(priv);
3137 X__ipw2100_tx_send_data(priv);
3140 if (inta & IPW2100_INTA_TX_COMPLETE) {
3141 IPW_DEBUG_ISR("TX complete\n");
3145 IPW2100_INTA_TX_COMPLETE);
3147 __ipw2100_tx_complete(priv);
3150 if (inta & IPW2100_INTA_EVENT_INTERRUPT) {
3151 /* ipw2100_handle_event(dev); */
3155 IPW2100_INTA_EVENT_INTERRUPT);
3158 if (inta & IPW2100_INTA_FW_INIT_DONE) {
3159 IPW_DEBUG_ISR("FW init done interrupt\n");
3162 read_register(dev, IPW_REG_INTA, &tmp);
3163 if (tmp & (IPW2100_INTA_FATAL_ERROR |
3164 IPW2100_INTA_PARITY_ERROR)) {
3167 IPW2100_INTA_FATAL_ERROR |
3168 IPW2100_INTA_PARITY_ERROR);
3171 write_register(dev, IPW_REG_INTA,
3172 IPW2100_INTA_FW_INIT_DONE);
3175 if (inta & IPW2100_INTA_STATUS_CHANGE) {
3176 IPW_DEBUG_ISR("Status change interrupt\n");
3180 IPW2100_INTA_STATUS_CHANGE);
3183 if (inta & IPW2100_INTA_SLAVE_MODE_HOST_COMMAND_DONE) {
3184 IPW_DEBUG_ISR("slave host mode interrupt\n");
3188 IPW2100_INTA_SLAVE_MODE_HOST_COMMAND_DONE);
3192 ipw2100_enable_interrupts(priv);
3194 spin_unlock_irqrestore(&priv->low_lock, flags);
3196 IPW_DEBUG_ISR("exit\n");
3200 static irqreturn_t ipw2100_interrupt(int irq, void *data,
3201 struct pt_regs *regs)
3203 struct ipw2100_priv *priv = data;
3204 u32 inta, inta_mask;
3209 spin_lock(&priv->low_lock);
3211 /* We check to see if we should be ignoring interrupts before
3212 * we touch the hardware. During ucode load if we try and handle
3213 * an interrupt we can cause keyboard problems as well as cause
3214 * the ucode to fail to initialize */
3215 if (!(priv->status & STATUS_INT_ENABLED)) {
3220 read_register(priv->net_dev, IPW_REG_INTA_MASK, &inta_mask);
3221 read_register(priv->net_dev, IPW_REG_INTA, &inta);
3223 if (inta == 0xFFFFFFFF) {
3224 /* Hardware disappeared */
3225 IPW_DEBUG_WARNING("IRQ INTA == 0xFFFFFFFF\n");
3229 inta &= IPW_INTERRUPT_MASK;
3231 if (!(inta & inta_mask)) {
3232 /* Shared interrupt */
3236 /* We disable the hardware interrupt here just to prevent unneeded
3237 * calls to be made. We disable this again within the actual
3238 * work tasklet, so if another part of the code re-enables the
3239 * interrupt, that is fine */
3240 ipw2100_disable_interrupts(priv);
3242 tasklet_schedule(&priv->irq_tasklet);
3243 spin_unlock(&priv->low_lock);
3247 spin_unlock(&priv->low_lock);
3251 static int ipw2100_tx(struct ieee80211_txb *txb, struct net_device *dev)
3253 struct ipw2100_priv *priv = ieee80211_priv(dev);
3254 struct list_head *element;
3255 struct ipw2100_tx_packet *packet;
3256 unsigned long flags;
3258 spin_lock_irqsave(&priv->low_lock, flags);
3260 if (!(priv->status & STATUS_ASSOCIATED)) {
3261 IPW_DEBUG_INFO("Can not transmit when not connected.\n");
3262 priv->ieee->stats.tx_carrier_errors++;
3263 netif_stop_queue(dev);
3267 if (list_empty(&priv->tx_free_list))
3270 element = priv->tx_free_list.next;
3271 packet = list_entry(element, struct ipw2100_tx_packet, list);
3273 packet->info.d_struct.txb = txb;
3275 IPW_DEBUG_TX("Sending fragment (%d bytes):\n",
3276 txb->fragments[0]->len);
3277 printk_buf(IPW_DL_TX, txb->fragments[0]->data,
3278 txb->fragments[0]->len);
3280 packet->jiffy_start = jiffies;
3283 DEC_STAT(&priv->tx_free_stat);
3285 list_add_tail(element, &priv->tx_pend_list);
3286 INC_STAT(&priv->tx_pend_stat);
3288 X__ipw2100_tx_send_data(priv);
3290 spin_unlock_irqrestore(&priv->low_lock, flags);
3294 netif_stop_queue(dev);
3295 spin_unlock_irqrestore(&priv->low_lock, flags);
3300 static int ipw2100_msg_allocate(struct ipw2100_priv *priv)
3302 int i, j, err = -EINVAL;
3306 priv->msg_buffers = (struct ipw2100_tx_packet *)kmalloc(
3307 IPW_COMMAND_POOL_SIZE * sizeof(struct ipw2100_tx_packet),
3309 if (!priv->msg_buffers) {
3310 IPW_DEBUG_ERROR("%s: PCI alloc failed for msg "
3311 "buffers.\n", priv->net_dev->name);
3315 for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++) {
3316 v = pci_alloc_consistent(
3318 sizeof(struct ipw2100_cmd_header),
3322 "%s: PCI alloc failed for msg "
3324 priv->net_dev->name);
3329 memset(v, 0, sizeof(struct ipw2100_cmd_header));
3331 priv->msg_buffers[i].type = COMMAND;
3332 priv->msg_buffers[i].info.c_struct.cmd =
3333 (struct ipw2100_cmd_header*)v;
3334 priv->msg_buffers[i].info.c_struct.cmd_phys = p;
3337 if (i == IPW_COMMAND_POOL_SIZE)
3340 for (j = 0; j < i; j++) {
3341 pci_free_consistent(
3343 sizeof(struct ipw2100_cmd_header),
3344 priv->msg_buffers[j].info.c_struct.cmd,
3345 priv->msg_buffers[j].info.c_struct.cmd_phys);
3348 kfree(priv->msg_buffers);
3349 priv->msg_buffers = NULL;
3354 static int ipw2100_msg_initialize(struct ipw2100_priv *priv)
3358 INIT_LIST_HEAD(&priv->msg_free_list);
3359 INIT_LIST_HEAD(&priv->msg_pend_list);
3361 for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++)
3362 list_add_tail(&priv->msg_buffers[i].list, &priv->msg_free_list);
3363 SET_STAT(&priv->msg_free_stat, i);
3368 static void ipw2100_msg_free(struct ipw2100_priv *priv)
3372 if (!priv->msg_buffers)
3375 for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++) {
3376 pci_free_consistent(priv->pci_dev,
3377 sizeof(struct ipw2100_cmd_header),
3378 priv->msg_buffers[i].info.c_struct.cmd,
3379 priv->msg_buffers[i].info.c_struct.cmd_phys);
3382 kfree(priv->msg_buffers);
3383 priv->msg_buffers = NULL;
3386 static ssize_t show_pci(struct device *d, char *buf)
3388 struct pci_dev *pci_dev = container_of(d, struct pci_dev, dev);
3393 for (i = 0; i < 16; i++) {
3394 out += sprintf(out, "[%08X] ", i * 16);
3395 for (j = 0; j < 16; j += 4) {
3396 pci_read_config_dword(pci_dev, i * 16 + j, &val);
3397 out += sprintf(out, "%08X ", val);
3399 out += sprintf(out, "\n");
3404 static DEVICE_ATTR(pci, S_IRUGO, show_pci, NULL);
3406 static ssize_t show_cfg(struct device *d, char *buf)
3408 struct ipw2100_priv *p = (struct ipw2100_priv *)d->driver_data;
3409 return sprintf(buf, "0x%08x\n", (int)p->config);
3411 static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
3413 static ssize_t show_status(struct device *d, char *buf)
3415 struct ipw2100_priv *p = (struct ipw2100_priv *)d->driver_data;
3416 return sprintf(buf, "0x%08x\n", (int)p->status);
3418 static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
3420 static ssize_t show_capability(struct device *d, char *buf)
3422 struct ipw2100_priv *p = (struct ipw2100_priv *)d->driver_data;
3423 return sprintf(buf, "0x%08x\n", (int)p->capability);
3425 static DEVICE_ATTR(capability, S_IRUGO, show_capability, NULL);
3428 #define IPW2100_REG(x) { IPW_ ##x, #x }
3433 IPW2100_REG(REG_GP_CNTRL),
3434 IPW2100_REG(REG_GPIO),
3435 IPW2100_REG(REG_INTA),
3436 IPW2100_REG(REG_INTA_MASK),
3437 IPW2100_REG(REG_RESET_REG),
3439 #define IPW2100_NIC(x, s) { x, #x, s }
3445 IPW2100_NIC(IPW2100_CONTROL_REG, 2),
3446 IPW2100_NIC(0x210014, 1),
3447 IPW2100_NIC(0x210000, 1),
3449 #define IPW2100_ORD(x, d) { IPW_ORD_ ##x, #x, d }
3455 IPW2100_ORD(STAT_TX_HOST_REQUESTS, "requested Host Tx's (MSDU)"),
3456 IPW2100_ORD(STAT_TX_HOST_COMPLETE, "successful Host Tx's (MSDU)"),
3457 IPW2100_ORD(STAT_TX_DIR_DATA, "successful Directed Tx's (MSDU)"),
3458 IPW2100_ORD(STAT_TX_DIR_DATA1, "successful Directed Tx's (MSDU) @ 1MB"),
3459 IPW2100_ORD(STAT_TX_DIR_DATA2, "successful Directed Tx's (MSDU) @ 2MB"),
3460 IPW2100_ORD(STAT_TX_DIR_DATA5_5, "successful Directed Tx's (MSDU) @ 5_5MB"),
3461 IPW2100_ORD(STAT_TX_DIR_DATA11, "successful Directed Tx's (MSDU) @ 11MB"),
3462 IPW2100_ORD(STAT_TX_NODIR_DATA1, "successful Non_Directed Tx's (MSDU) @ 1MB"),
3463 IPW2100_ORD(STAT_TX_NODIR_DATA2, "successful Non_Directed Tx's (MSDU) @ 2MB"),
3464 IPW2100_ORD(STAT_TX_NODIR_DATA5_5, "successful Non_Directed Tx's (MSDU) @ 5.5MB"),
3465 IPW2100_ORD(STAT_TX_NODIR_DATA11, "successful Non_Directed Tx's (MSDU) @ 11MB"),
3466 IPW2100_ORD(STAT_NULL_DATA, "successful NULL data Tx's"),
3467 IPW2100_ORD(STAT_TX_RTS, "successful Tx RTS"),
3468 IPW2100_ORD(STAT_TX_CTS, "successful Tx CTS"),
3469 IPW2100_ORD(STAT_TX_ACK, "successful Tx ACK"),
3470 IPW2100_ORD(STAT_TX_ASSN, "successful Association Tx's"),
3471 IPW2100_ORD(STAT_TX_ASSN_RESP, "successful Association response Tx's"),
3472 IPW2100_ORD(STAT_TX_REASSN, "successful Reassociation Tx's"),
3473 IPW2100_ORD(STAT_TX_REASSN_RESP, "successful Reassociation response Tx's"),
3474 IPW2100_ORD(STAT_TX_PROBE, "probes successfully transmitted"),
3475 IPW2100_ORD(STAT_TX_PROBE_RESP, "probe responses successfully transmitted"),
3476 IPW2100_ORD(STAT_TX_BEACON, "tx beacon"),
3477 IPW2100_ORD(STAT_TX_ATIM, "Tx ATIM"),
3478 IPW2100_ORD(STAT_TX_DISASSN, "successful Disassociation TX"),
3479 IPW2100_ORD(STAT_TX_AUTH, "successful Authentication Tx"),
3480 IPW2100_ORD(STAT_TX_DEAUTH, "successful Deauthentication TX"),
3481 IPW2100_ORD(STAT_TX_TOTAL_BYTES, "Total successful Tx data bytes"),
3482 IPW2100_ORD(STAT_TX_RETRIES, "Tx retries"),
3483 IPW2100_ORD(STAT_TX_RETRY1, "Tx retries at 1MBPS"),
3484 IPW2100_ORD(STAT_TX_RETRY2, "Tx retries at 2MBPS"),
3485 IPW2100_ORD(STAT_TX_RETRY5_5, "Tx retries at 5.5MBPS"),
3486 IPW2100_ORD(STAT_TX_RETRY11, "Tx retries at 11MBPS"),
3487 IPW2100_ORD(STAT_TX_FAILURES, "Tx Failures"),
3488 IPW2100_ORD(STAT_TX_MAX_TRIES_IN_HOP,"times max tries in a hop failed"),
3489 IPW2100_ORD(STAT_TX_DISASSN_FAIL, "times disassociation failed"),
3490 IPW2100_ORD(STAT_TX_ERR_CTS, "missed/bad CTS frames"),
3491 IPW2100_ORD(STAT_TX_ERR_ACK, "tx err due to acks"),
3492 IPW2100_ORD(STAT_RX_HOST, "packets passed to host"),
3493 IPW2100_ORD(STAT_RX_DIR_DATA, "directed packets"),
3494 IPW2100_ORD(STAT_RX_DIR_DATA1, "directed packets at 1MB"),
3495 IPW2100_ORD(STAT_RX_DIR_DATA2, "directed packets at 2MB"),
3496 IPW2100_ORD(STAT_RX_DIR_DATA5_5, "directed packets at 5.5MB"),
3497 IPW2100_ORD(STAT_RX_DIR_DATA11, "directed packets at 11MB"),
3498 IPW2100_ORD(STAT_RX_NODIR_DATA,"nondirected packets"),
3499 IPW2100_ORD(STAT_RX_NODIR_DATA1, "nondirected packets at 1MB"),
3500 IPW2100_ORD(STAT_RX_NODIR_DATA2, "nondirected packets at 2MB"),
3501 IPW2100_ORD(STAT_RX_NODIR_DATA5_5, "nondirected packets at 5.5MB"),
3502 IPW2100_ORD(STAT_RX_NODIR_DATA11, "nondirected packets at 11MB"),
3503 IPW2100_ORD(STAT_RX_NULL_DATA, "null data rx's"),
3504 IPW2100_ORD(STAT_RX_RTS, "Rx RTS"),
3505 IPW2100_ORD(STAT_RX_CTS, "Rx CTS"),
3506 IPW2100_ORD(STAT_RX_ACK, "Rx ACK"),
3507 IPW2100_ORD(STAT_RX_CFEND, "Rx CF End"),
3508 IPW2100_ORD(STAT_RX_CFEND_ACK, "Rx CF End + CF Ack"),
3509 IPW2100_ORD(STAT_RX_ASSN, "Association Rx's"),
3510 IPW2100_ORD(STAT_RX_ASSN_RESP, "Association response Rx's"),
3511 IPW2100_ORD(STAT_RX_REASSN, "Reassociation Rx's"),
3512 IPW2100_ORD(STAT_RX_REASSN_RESP, "Reassociation response Rx's"),
3513 IPW2100_ORD(STAT_RX_PROBE, "probe Rx's"),
3514 IPW2100_ORD(STAT_RX_PROBE_RESP, "probe response Rx's"),
3515 IPW2100_ORD(STAT_RX_BEACON, "Rx beacon"),
3516 IPW2100_ORD(STAT_RX_ATIM, "Rx ATIM"),
3517 IPW2100_ORD(STAT_RX_DISASSN, "disassociation Rx"),
3518 IPW2100_ORD(STAT_RX_AUTH, "authentication Rx"),
3519 IPW2100_ORD(STAT_RX_DEAUTH, "deauthentication Rx"),
3520 IPW2100_ORD(STAT_RX_TOTAL_BYTES,"Total rx data bytes received"),
3521 IPW2100_ORD(STAT_RX_ERR_CRC, "packets with Rx CRC error"),
3522 IPW2100_ORD(STAT_RX_ERR_CRC1, "Rx CRC errors at 1MB"),
3523 IPW2100_ORD(STAT_RX_ERR_CRC2, "Rx CRC errors at 2MB"),
3524 IPW2100_ORD(STAT_RX_ERR_CRC5_5, "Rx CRC errors at 5.5MB"),
3525 IPW2100_ORD(STAT_RX_ERR_CRC11, "Rx CRC errors at 11MB"),
3526 IPW2100_ORD(STAT_RX_DUPLICATE1, "duplicate rx packets at 1MB"),
3527 IPW2100_ORD(STAT_RX_DUPLICATE2, "duplicate rx packets at 2MB"),
3528 IPW2100_ORD(STAT_RX_DUPLICATE5_5, "duplicate rx packets at 5.5MB"),
3529 IPW2100_ORD(STAT_RX_DUPLICATE11, "duplicate rx packets at 11MB"),
3530 IPW2100_ORD(STAT_RX_DUPLICATE, "duplicate rx packets"),
3531 IPW2100_ORD(PERS_DB_LOCK, "locking fw permanent db"),
3532 IPW2100_ORD(PERS_DB_SIZE, "size of fw permanent db"),
3533 IPW2100_ORD(PERS_DB_ADDR, "address of fw permanent db"),
3534 IPW2100_ORD(STAT_RX_INVALID_PROTOCOL, "rx frames with invalid protocol"),
3535 IPW2100_ORD(SYS_BOOT_TIME, "Boot time"),
3536 IPW2100_ORD(STAT_RX_NO_BUFFER, "rx frames rejected due to no buffer"),
3537 IPW2100_ORD(STAT_RX_MISSING_FRAG, "rx frames dropped due to missing fragment"),
3538 IPW2100_ORD(STAT_RX_ORPHAN_FRAG, "rx frames dropped due to non-sequential fragment"),
3539 IPW2100_ORD(STAT_RX_ORPHAN_FRAME, "rx frames dropped due to unmatched 1st frame"),
3540 IPW2100_ORD(STAT_RX_FRAG_AGEOUT, "rx frames dropped due to uncompleted frame"),
3541 IPW2100_ORD(STAT_RX_ICV_ERRORS, "ICV errors during decryption"),
3542 IPW2100_ORD(STAT_PSP_SUSPENSION,"times adapter suspended"),
3543 IPW2100_ORD(STAT_PSP_BCN_TIMEOUT, "beacon timeout"),
3544 IPW2100_ORD(STAT_PSP_POLL_TIMEOUT, "poll response timeouts"),
3545 IPW2100_ORD(STAT_PSP_NONDIR_TIMEOUT, "timeouts waiting for last {broad,multi}cast pkt"),
3546 IPW2100_ORD(STAT_PSP_RX_DTIMS, "PSP DTIMs received"),
3547 IPW2100_ORD(STAT_PSP_RX_TIMS, "PSP TIMs received"),
3548 IPW2100_ORD(STAT_PSP_STATION_ID,"PSP Station ID"),
3549 IPW2100_ORD(LAST_ASSN_TIME, "RTC time of last association"),
3550 IPW2100_ORD(STAT_PERCENT_MISSED_BCNS,"current calculation of % missed beacons"),
3551 IPW2100_ORD(STAT_PERCENT_RETRIES,"current calculation of % missed tx retries"),
3552 IPW2100_ORD(ASSOCIATED_AP_PTR, "0 if not associated, else pointer to AP table entry"),
3553 IPW2100_ORD(AVAILABLE_AP_CNT, "AP's decsribed in the AP table"),
3554 IPW2100_ORD(AP_LIST_PTR, "Ptr to list of available APs"),
3555 IPW2100_ORD(STAT_AP_ASSNS, "associations"),
3556 IPW2100_ORD(STAT_ASSN_FAIL, "association failures"),
3557 IPW2100_ORD(STAT_ASSN_RESP_FAIL,"failures due to response fail"),
3558 IPW2100_ORD(STAT_FULL_SCANS, "full scans"),
3559 IPW2100_ORD(CARD_DISABLED, "Card Disabled"),
3560 IPW2100_ORD(STAT_ROAM_INHIBIT, "times roaming was inhibited due to activity"),
3561 IPW2100_ORD(RSSI_AT_ASSN, "RSSI of associated AP at time of association"),
3562 IPW2100_ORD(STAT_ASSN_CAUSE1, "reassociation: no probe response or TX on hop"),
3563 IPW2100_ORD(STAT_ASSN_CAUSE2, "reassociation: poor tx/rx quality"),
3564 IPW2100_ORD(STAT_ASSN_CAUSE3, "reassociation: tx/rx quality (excessive AP load"),
3565 IPW2100_ORD(STAT_ASSN_CAUSE4, "reassociation: AP RSSI level"),
3566 IPW2100_ORD(STAT_ASSN_CAUSE5, "reassociations due to load leveling"),
3567 IPW2100_ORD(STAT_AUTH_FAIL, "times authentication failed"),
3568 IPW2100_ORD(STAT_AUTH_RESP_FAIL,"times authentication response failed"),
3569 IPW2100_ORD(STATION_TABLE_CNT, "entries in association table"),
3570 IPW2100_ORD(RSSI_AVG_CURR, "Current avg RSSI"),
3571 IPW2100_ORD(POWER_MGMT_MODE, "Power mode - 0=CAM, 1=PSP"),
3572 IPW2100_ORD(COUNTRY_CODE, "IEEE country code as recv'd from beacon"),
3573 IPW2100_ORD(COUNTRY_CHANNELS, "channels suported by country"),
3574 IPW2100_ORD(RESET_CNT, "adapter resets (warm)"),
3575 IPW2100_ORD(BEACON_INTERVAL, "Beacon interval"),
3576 IPW2100_ORD(ANTENNA_DIVERSITY, "TRUE if antenna diversity is disabled"),
3577 IPW2100_ORD(DTIM_PERIOD, "beacon intervals between DTIMs"),
3578 IPW2100_ORD(OUR_FREQ, "current radio freq lower digits - channel ID"),
3579 IPW2100_ORD(RTC_TIME, "current RTC time"),
3580 IPW2100_ORD(PORT_TYPE, "operating mode"),
3581 IPW2100_ORD(CURRENT_TX_RATE, "current tx rate"),
3582 IPW2100_ORD(SUPPORTED_RATES, "supported tx rates"),
3583 IPW2100_ORD(ATIM_WINDOW, "current ATIM Window"),
3584 IPW2100_ORD(BASIC_RATES, "basic tx rates"),
3585 IPW2100_ORD(NIC_HIGHEST_RATE, "NIC highest tx rate"),
3586 IPW2100_ORD(AP_HIGHEST_RATE, "AP highest tx rate"),
3587 IPW2100_ORD(CAPABILITIES, "Management frame capability field"),
3588 IPW2100_ORD(AUTH_TYPE, "Type of authentication"),
3589 IPW2100_ORD(RADIO_TYPE, "Adapter card platform type"),
3590 IPW2100_ORD(RTS_THRESHOLD, "Min packet length for RTS handshaking"),
3591 IPW2100_ORD(INT_MODE, "International mode"),
3592 IPW2100_ORD(FRAGMENTATION_THRESHOLD, "protocol frag threshold"),
3593 IPW2100_ORD(EEPROM_SRAM_DB_BLOCK_START_ADDRESS, "EEPROM offset in SRAM"),
3594 IPW2100_ORD(EEPROM_SRAM_DB_BLOCK_SIZE, "EEPROM size in SRAM"),
3595 IPW2100_ORD(EEPROM_SKU_CAPABILITY, "EEPROM SKU Capability"),
3596 IPW2100_ORD(EEPROM_IBSS_11B_CHANNELS, "EEPROM IBSS 11b channel set"),
3597 IPW2100_ORD(MAC_VERSION, "MAC Version"),
3598 IPW2100_ORD(MAC_REVISION, "MAC Revision"),
3599 IPW2100_ORD(RADIO_VERSION, "Radio Version"),
3600 IPW2100_ORD(NIC_MANF_DATE_TIME, "MANF Date/Time STAMP"),
3601 IPW2100_ORD(UCODE_VERSION, "Ucode Version"),
3605 static ssize_t show_registers(struct device *d, char *buf)
3608 struct ipw2100_priv *priv = dev_get_drvdata(d);
3609 struct net_device *dev = priv->net_dev;
3613 out += sprintf(out, "%30s [Address ] : Hex\n", "Register");
3615 for (i = 0; i < (sizeof(hw_data) / sizeof(*hw_data)); i++) {
3616 read_register(dev, hw_data[i].addr, &val);
3617 out += sprintf(out, "%30s [%08X] : %08X\n",
3618 hw_data[i].name, hw_data[i].addr, val);
3623 static DEVICE_ATTR(registers, S_IRUGO, show_registers, NULL);
3626 static ssize_t show_hardware(struct device *d, char *buf)
3628 struct ipw2100_priv *priv = dev_get_drvdata(d);
3629 struct net_device *dev = priv->net_dev;
3633 out += sprintf(out, "%30s [Address ] : Hex\n", "NIC entry");
3635 for (i = 0; i < (sizeof(nic_data) / sizeof(*nic_data)); i++) {
3640 switch (nic_data[i].size) {
3642 read_nic_byte(dev, nic_data[i].addr, &tmp8);
3643 out += sprintf(out, "%30s [%08X] : %02X\n",
3644 nic_data[i].name, nic_data[i].addr,
3648 read_nic_word(dev, nic_data[i].addr, &tmp16);
3649 out += sprintf(out, "%30s [%08X] : %04X\n",
3650 nic_data[i].name, nic_data[i].addr,
3654 read_nic_dword(dev, nic_data[i].addr, &tmp32);
3655 out += sprintf(out, "%30s [%08X] : %08X\n",
3656 nic_data[i].name, nic_data[i].addr,
3663 static DEVICE_ATTR(hardware, S_IRUGO, show_hardware, NULL);
3666 static ssize_t show_memory(struct device *d, char *buf)
3668 struct ipw2100_priv *priv = dev_get_drvdata(d);
3669 struct net_device *dev = priv->net_dev;
3670 static unsigned long loop = 0;
3676 if (loop >= 0x30000)
3679 /* sysfs provides us PAGE_SIZE buffer */
3680 while (len < PAGE_SIZE - 128 && loop < 0x30000) {
3682 if (priv->snapshot[0]) for (i = 0; i < 4; i++)
3683 buffer[i] = *(u32 *)SNAPSHOT_ADDR(loop + i * 4);
3684 else for (i = 0; i < 4; i++)
3685 read_nic_dword(dev, loop + i * 4, &buffer[i]);
3688 len += sprintf(buf + len,
3708 ((u8*)buffer)[0xf]);
3710 len += sprintf(buf + len, "%s\n",
3711 snprint_line(line, sizeof(line),
3712 (u8*)buffer, 16, loop));
3719 static ssize_t store_memory(struct device *d, const char *buf, size_t count)
3721 struct ipw2100_priv *priv = dev_get_drvdata(d);
3722 struct net_device *dev = priv->net_dev;
3723 const char *p = buf;
3729 (count >= 2 && tolower(p[0]) == 'o' && tolower(p[1]) == 'n')) {
3730 IPW_DEBUG_INFO("%s: Setting memory dump to RAW mode.\n",
3734 } else if (p[0] == '0' || (count >= 2 && tolower(p[0]) == 'o' &&
3735 tolower(p[1]) == 'f')) {
3736 IPW_DEBUG_INFO("%s: Setting memory dump to HEX mode.\n",
3740 } else if (tolower(p[0]) == 'r') {
3741 IPW_DEBUG_INFO("%s: Resetting firmware snapshot.\n",
3743 ipw2100_snapshot_free(priv);
3746 IPW_DEBUG_INFO("%s: Usage: 0|on = HEX, 1|off = RAW, "
3747 "reset = clear memory snapshot\n",
3752 static DEVICE_ATTR(memory, S_IWUSR|S_IRUGO, show_memory, store_memory);
3755 static ssize_t show_ordinals(struct device *d, char *buf)
3757 struct ipw2100_priv *priv = dev_get_drvdata(d);
3761 static int loop = 0;
3763 if (loop >= sizeof(ord_data) / sizeof(*ord_data))
3766 /* sysfs provides us PAGE_SIZE buffer */
3767 while (len < PAGE_SIZE - 128 &&
3768 loop < (sizeof(ord_data) / sizeof(*ord_data))) {
3770 val_len = sizeof(u32);
3772 if (ipw2100_get_ordinal(priv, ord_data[loop].index, &val,
3774 len += sprintf(buf + len, "[0x%02X] = ERROR %s\n",
3775 ord_data[loop].index,
3776 ord_data[loop].desc);
3778 len += sprintf(buf + len, "[0x%02X] = 0x%08X %s\n",
3779 ord_data[loop].index, val,
3780 ord_data[loop].desc);
3786 static DEVICE_ATTR(ordinals, S_IRUGO, show_ordinals, NULL);
3789 static ssize_t show_stats(struct device *d, char *buf)
3791 struct ipw2100_priv *priv = dev_get_drvdata(d);
3794 out += sprintf(out, "interrupts: %d {tx: %d, rx: %d, other: %d}\n",
3795 priv->interrupts, priv->tx_interrupts,
3796 priv->rx_interrupts, priv->inta_other);
3797 out += sprintf(out, "firmware resets: %d\n", priv->resets);
3798 out += sprintf(out, "firmware hangs: %d\n", priv->hangs);
3799 #ifdef CONFIG_IPW_DEBUG
3800 out += sprintf(out, "packet mismatch image: %s\n",
3801 priv->snapshot[0] ? "YES" : "NO");
3806 static DEVICE_ATTR(stats, S_IRUGO, show_stats, NULL);
3809 int ipw2100_switch_mode(struct ipw2100_priv *priv, u32 mode)
3813 if (mode == priv->ieee->iw_mode)
3816 err = ipw2100_disable_adapter(priv);
3818 IPW_DEBUG_ERROR("%s: Could not disable adapter %d\n",
3819 priv->net_dev->name, err);
3825 priv->net_dev->type = ARPHRD_ETHER;
3828 priv->net_dev->type = ARPHRD_ETHER;
3830 #ifdef CONFIG_IPW2100_MONITOR
3831 case IW_MODE_MONITOR:
3832 priv->last_mode = priv->ieee->iw_mode;
3833 priv->net_dev->type = ARPHRD_IEEE80211;
3835 #endif /* CONFIG_IPW2100_MONITOR */
3838 priv->ieee->iw_mode = mode;
3841 /* Indicate ipw2100_download_firmware download firmware
3842 * from disk instead of memory. */
3843 ipw2100_firmware.version = 0;
3846 printk(KERN_INFO "%s: Reseting on mode change.\n",
3847 priv->net_dev->name);
3848 priv->reset_backoff = 0;
3849 schedule_reset(priv);
3854 static ssize_t show_internals(struct device *d, char *buf)
3856 struct ipw2100_priv *priv = dev_get_drvdata(d);
3859 #define DUMP_VAR(x,y) len += sprintf(buf + len, # x ": %" # y "\n", priv-> x)
3861 if (priv->status & STATUS_ASSOCIATED)
3862 len += sprintf(buf + len, "connected: %lu\n",
3863 get_seconds() - priv->connect_start);
3865 len += sprintf(buf + len, "not connected\n");
3867 DUMP_VAR(ieee->crypt[priv->ieee->tx_keyidx], p);
3868 DUMP_VAR(status, 08lx);
3869 DUMP_VAR(config, 08lx);
3870 DUMP_VAR(capability, 08lx);
3872 len += sprintf(buf + len, "last_rtc: %lu\n", (unsigned long)priv->last_rtc);
3874 DUMP_VAR(fatal_error, d);
3875 DUMP_VAR(stop_hang_check, d);
3876 DUMP_VAR(stop_rf_kill, d);
3877 DUMP_VAR(messages_sent, d);
3879 DUMP_VAR(tx_pend_stat.value, d);
3880 DUMP_VAR(tx_pend_stat.hi, d);
3882 DUMP_VAR(tx_free_stat.value, d);
3883 DUMP_VAR(tx_free_stat.lo, d);
3885 DUMP_VAR(msg_free_stat.value, d);
3886 DUMP_VAR(msg_free_stat.lo, d);
3888 DUMP_VAR(msg_pend_stat.value, d);
3889 DUMP_VAR(msg_pend_stat.hi, d);
3891 DUMP_VAR(fw_pend_stat.value, d);
3892 DUMP_VAR(fw_pend_stat.hi, d);
3894 DUMP_VAR(txq_stat.value, d);
3895 DUMP_VAR(txq_stat.lo, d);
3897 DUMP_VAR(ieee->scans, d);
3898 DUMP_VAR(reset_backoff, d);
3902 static DEVICE_ATTR(internals, S_IRUGO, show_internals, NULL);
3905 static ssize_t show_bssinfo(struct device *d, char *buf)
3907 struct ipw2100_priv *priv = dev_get_drvdata(d);
3908 char essid[IW_ESSID_MAX_SIZE + 1];
3915 memset(essid, 0, sizeof(essid));
3916 memset(bssid, 0, sizeof(bssid));
3918 length = IW_ESSID_MAX_SIZE;
3919 ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_SSID, essid, &length);
3921 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
3924 length = sizeof(bssid);
3925 ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID,
3928 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
3931 length = sizeof(u32);
3932 ret = ipw2100_get_ordinal(priv, IPW_ORD_OUR_FREQ, &chan, &length);
3934 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
3937 out += sprintf(out, "ESSID: %s\n", essid);
3938 out += sprintf(out, "BSSID: %02x:%02x:%02x:%02x:%02x:%02x\n",
3939 bssid[0], bssid[1], bssid[2],
3940 bssid[3], bssid[4], bssid[5]);
3941 out += sprintf(out, "Channel: %d\n", chan);
3945 static DEVICE_ATTR(bssinfo, S_IRUGO, show_bssinfo, NULL);
3950 #ifdef CONFIG_IPW_DEBUG
3951 static ssize_t show_debug_level(struct device_driver *d, char *buf)
3953 return sprintf(buf, "0x%08X\n", ipw2100_debug_level);
3956 static ssize_t store_debug_level(struct device_driver *d, const char *buf,
3959 char *p = (char *)buf;
3962 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
3964 if (p[0] == 'x' || p[0] == 'X')
3966 val = simple_strtoul(p, &p, 16);
3968 val = simple_strtoul(p, &p, 10);
3970 IPW_DEBUG_INFO(DRV_NAME
3971 ": %s is not in hex or decimal form.\n", buf);
3973 ipw2100_debug_level = val;
3975 return strnlen(buf, count);
3977 static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, show_debug_level,
3979 #endif /* CONFIG_IPW_DEBUG */
3982 static ssize_t show_fatal_error(struct device *d, char *buf)
3984 struct ipw2100_priv *priv = dev_get_drvdata(d);
3988 if (priv->fatal_error)
3989 out += sprintf(out, "0x%08X\n",
3992 out += sprintf(out, "0\n");
3994 for (i = 1; i <= IPW2100_ERROR_QUEUE; i++) {
3995 if (!priv->fatal_errors[(priv->fatal_index - i) %
3996 IPW2100_ERROR_QUEUE])
3999 out += sprintf(out, "%d. 0x%08X\n", i,
4000 priv->fatal_errors[(priv->fatal_index - i) %
4001 IPW2100_ERROR_QUEUE]);
4007 static ssize_t store_fatal_error(struct device *d, const char *buf,
4010 struct ipw2100_priv *priv = dev_get_drvdata(d);
4011 schedule_reset(priv);
4014 static DEVICE_ATTR(fatal_error, S_IWUSR|S_IRUGO, show_fatal_error, store_fatal_error);
4017 static ssize_t show_scan_age(struct device *d, char *buf)
4019 struct ipw2100_priv *priv = dev_get_drvdata(d);
4020 return sprintf(buf, "%d\n", priv->ieee->scan_age);
4023 static ssize_t store_scan_age(struct device *d, const char *buf, size_t count)
4025 struct ipw2100_priv *priv = dev_get_drvdata(d);
4026 struct net_device *dev = priv->net_dev;
4027 char buffer[] = "00000000";
4029 (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
4033 IPW_DEBUG_INFO("enter\n");
4035 strncpy(buffer, buf, len);
4038 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
4040 if (p[0] == 'x' || p[0] == 'X')
4042 val = simple_strtoul(p, &p, 16);
4044 val = simple_strtoul(p, &p, 10);
4046 IPW_DEBUG_INFO("%s: user supplied invalid value.\n",
4049 priv->ieee->scan_age = val;
4050 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
4053 IPW_DEBUG_INFO("exit\n");
4056 static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
4059 static ssize_t show_rf_kill(struct device *d, char *buf)
4061 /* 0 - RF kill not enabled
4062 1 - SW based RF kill active (sysfs)
4063 2 - HW based RF kill active
4064 3 - Both HW and SW baed RF kill active */
4065 struct ipw2100_priv *priv = (struct ipw2100_priv *)d->driver_data;
4066 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
4067 (rf_kill_active(priv) ? 0x2 : 0x0);
4068 return sprintf(buf, "%i\n", val);
4071 static int ipw_radio_kill_sw(struct ipw2100_priv *priv, int disable_radio)
4073 if ((disable_radio ? 1 : 0) ==
4074 (priv->status & STATUS_RF_KILL_SW ? 1 : 0))
4077 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
4078 disable_radio ? "OFF" : "ON");
4080 down(&priv->action_sem);
4082 if (disable_radio) {
4083 priv->status |= STATUS_RF_KILL_SW;
4086 priv->status &= ~STATUS_RF_KILL_SW;
4087 if (rf_kill_active(priv)) {
4088 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
4089 "disabled by HW switch\n");
4090 /* Make sure the RF_KILL check timer is running */
4091 priv->stop_rf_kill = 0;
4092 cancel_delayed_work(&priv->rf_kill);
4093 queue_delayed_work(priv->workqueue, &priv->rf_kill,
4096 schedule_reset(priv);
4099 up(&priv->action_sem);
4103 static ssize_t store_rf_kill(struct device *d, const char *buf, size_t count)
4105 struct ipw2100_priv *priv = dev_get_drvdata(d);
4106 ipw_radio_kill_sw(priv, buf[0] == '1');
4109 static DEVICE_ATTR(rf_kill, S_IWUSR|S_IRUGO, show_rf_kill, store_rf_kill);
4112 static struct attribute *ipw2100_sysfs_entries[] = {
4113 &dev_attr_hardware.attr,
4114 &dev_attr_registers.attr,
4115 &dev_attr_ordinals.attr,
4117 &dev_attr_stats.attr,
4118 &dev_attr_internals.attr,
4119 &dev_attr_bssinfo.attr,
4120 &dev_attr_memory.attr,
4121 &dev_attr_scan_age.attr,
4122 &dev_attr_fatal_error.attr,
4123 &dev_attr_rf_kill.attr,
4125 &dev_attr_status.attr,
4126 &dev_attr_capability.attr,
4130 static struct attribute_group ipw2100_attribute_group = {
4131 .attrs = ipw2100_sysfs_entries,
4135 static int status_queue_allocate(struct ipw2100_priv *priv, int entries)
4137 struct ipw2100_status_queue *q = &priv->status_queue;
4139 IPW_DEBUG_INFO("enter\n");
4141 q->size = entries * sizeof(struct ipw2100_status);
4142 q->drv = (struct ipw2100_status *)pci_alloc_consistent(
4143 priv->pci_dev, q->size, &q->nic);
4146 "Can not allocate status queue.\n");
4150 memset(q->drv, 0, q->size);
4152 IPW_DEBUG_INFO("exit\n");
4157 static void status_queue_free(struct ipw2100_priv *priv)
4159 IPW_DEBUG_INFO("enter\n");
4161 if (priv->status_queue.drv) {
4162 pci_free_consistent(
4163 priv->pci_dev, priv->status_queue.size,
4164 priv->status_queue.drv, priv->status_queue.nic);
4165 priv->status_queue.drv = NULL;
4168 IPW_DEBUG_INFO("exit\n");
4171 static int bd_queue_allocate(struct ipw2100_priv *priv,
4172 struct ipw2100_bd_queue *q, int entries)
4174 IPW_DEBUG_INFO("enter\n");
4176 memset(q, 0, sizeof(struct ipw2100_bd_queue));
4178 q->entries = entries;
4179 q->size = entries * sizeof(struct ipw2100_bd);
4180 q->drv = pci_alloc_consistent(priv->pci_dev, q->size, &q->nic);
4182 IPW_DEBUG_INFO("can't allocate shared memory for buffer descriptors\n");
4185 memset(q->drv, 0, q->size);
4187 IPW_DEBUG_INFO("exit\n");
4192 static void bd_queue_free(struct ipw2100_priv *priv,
4193 struct ipw2100_bd_queue *q)
4195 IPW_DEBUG_INFO("enter\n");
4201 pci_free_consistent(priv->pci_dev,
4202 q->size, q->drv, q->nic);
4206 IPW_DEBUG_INFO("exit\n");
4209 static void bd_queue_initialize(
4210 struct ipw2100_priv *priv, struct ipw2100_bd_queue * q,
4211 u32 base, u32 size, u32 r, u32 w)
4213 IPW_DEBUG_INFO("enter\n");
4215 IPW_DEBUG_INFO("initializing bd queue at virt=%p, phys=%08x\n", q->drv, q->nic);
4217 write_register(priv->net_dev, base, q->nic);
4218 write_register(priv->net_dev, size, q->entries);
4219 write_register(priv->net_dev, r, q->oldest);
4220 write_register(priv->net_dev, w, q->next);
4222 IPW_DEBUG_INFO("exit\n");
4225 static void ipw2100_kill_workqueue(struct ipw2100_priv *priv)
4227 if (priv->workqueue) {
4228 priv->stop_rf_kill = 1;
4229 priv->stop_hang_check = 1;
4230 cancel_delayed_work(&priv->reset_work);
4231 cancel_delayed_work(&priv->security_work);
4232 cancel_delayed_work(&priv->wx_event_work);
4233 cancel_delayed_work(&priv->hang_check);
4234 cancel_delayed_work(&priv->rf_kill);
4235 destroy_workqueue(priv->workqueue);
4236 priv->workqueue = NULL;
4240 static int ipw2100_tx_allocate(struct ipw2100_priv *priv)
4242 int i, j, err = -EINVAL;
4246 IPW_DEBUG_INFO("enter\n");
4248 err = bd_queue_allocate(priv, &priv->tx_queue, TX_QUEUE_LENGTH);
4250 IPW_DEBUG_ERROR("%s: failed bd_queue_allocate\n",
4251 priv->net_dev->name);
4255 priv->tx_buffers = (struct ipw2100_tx_packet *)kmalloc(
4256 TX_PENDED_QUEUE_LENGTH * sizeof(struct ipw2100_tx_packet),
4258 if (!priv->tx_buffers) {
4259 IPW_DEBUG_ERROR("%s: alloc failed form tx buffers.\n",
4260 priv->net_dev->name);
4261 bd_queue_free(priv, &priv->tx_queue);
4265 for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
4266 v = pci_alloc_consistent(
4267 priv->pci_dev, sizeof(struct ipw2100_data_header), &p);
4269 IPW_DEBUG_ERROR("%s: PCI alloc failed for tx "
4270 "buffers.\n", priv->net_dev->name);
4275 priv->tx_buffers[i].type = DATA;
4276 priv->tx_buffers[i].info.d_struct.data = (struct ipw2100_data_header*)v;
4277 priv->tx_buffers[i].info.d_struct.data_phys = p;
4278 priv->tx_buffers[i].info.d_struct.txb = NULL;
4281 if (i == TX_PENDED_QUEUE_LENGTH)
4284 for (j = 0; j < i; j++) {
4285 pci_free_consistent(
4287 sizeof(struct ipw2100_data_header),
4288 priv->tx_buffers[j].info.d_struct.data,
4289 priv->tx_buffers[j].info.d_struct.data_phys);
4292 kfree(priv->tx_buffers);
4293 priv->tx_buffers = NULL;
4298 static void ipw2100_tx_initialize(struct ipw2100_priv *priv)
4302 IPW_DEBUG_INFO("enter\n");
4305 * reinitialize packet info lists
4307 INIT_LIST_HEAD(&priv->fw_pend_list);
4308 INIT_STAT(&priv->fw_pend_stat);
4311 * reinitialize lists
4313 INIT_LIST_HEAD(&priv->tx_pend_list);
4314 INIT_LIST_HEAD(&priv->tx_free_list);
4315 INIT_STAT(&priv->tx_pend_stat);
4316 INIT_STAT(&priv->tx_free_stat);
4318 for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
4319 /* We simply drop any SKBs that have been queued for
4321 if (priv->tx_buffers[i].info.d_struct.txb) {
4322 ieee80211_txb_free(priv->tx_buffers[i].info.d_struct.txb);
4323 priv->tx_buffers[i].info.d_struct.txb = NULL;
4326 list_add_tail(&priv->tx_buffers[i].list, &priv->tx_free_list);
4329 SET_STAT(&priv->tx_free_stat, i);
4331 priv->tx_queue.oldest = 0;
4332 priv->tx_queue.available = priv->tx_queue.entries;
4333 priv->tx_queue.next = 0;
4334 INIT_STAT(&priv->txq_stat);
4335 SET_STAT(&priv->txq_stat, priv->tx_queue.available);
4337 bd_queue_initialize(priv, &priv->tx_queue,
4338 IPW_MEM_HOST_SHARED_TX_QUEUE_BD_BASE,
4339 IPW_MEM_HOST_SHARED_TX_QUEUE_BD_SIZE,
4340 IPW_MEM_HOST_SHARED_TX_QUEUE_READ_INDEX,
4341 IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX);
4343 IPW_DEBUG_INFO("exit\n");
4347 static void ipw2100_tx_free(struct ipw2100_priv *priv)
4351 IPW_DEBUG_INFO("enter\n");
4353 bd_queue_free(priv, &priv->tx_queue);
4355 if (!priv->tx_buffers)
4358 for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
4359 if (priv->tx_buffers[i].info.d_struct.txb) {
4360 ieee80211_txb_free(priv->tx_buffers[i].info.d_struct.txb);
4361 priv->tx_buffers[i].info.d_struct.txb = NULL;
4363 if (priv->tx_buffers[i].info.d_struct.data)
4364 pci_free_consistent(
4366 sizeof(struct ipw2100_data_header),
4367 priv->tx_buffers[i].info.d_struct.data,
4368 priv->tx_buffers[i].info.d_struct.data_phys);
4371 kfree(priv->tx_buffers);
4372 priv->tx_buffers = NULL;
4374 IPW_DEBUG_INFO("exit\n");
4379 static int ipw2100_rx_allocate(struct ipw2100_priv *priv)
4381 int i, j, err = -EINVAL;
4383 IPW_DEBUG_INFO("enter\n");
4385 err = bd_queue_allocate(priv, &priv->rx_queue, RX_QUEUE_LENGTH);
4387 IPW_DEBUG_INFO("failed bd_queue_allocate\n");
4391 err = status_queue_allocate(priv, RX_QUEUE_LENGTH);
4393 IPW_DEBUG_INFO("failed status_queue_allocate\n");
4394 bd_queue_free(priv, &priv->rx_queue);
4401 priv->rx_buffers = (struct ipw2100_rx_packet *)
4402 kmalloc(RX_QUEUE_LENGTH * sizeof(struct ipw2100_rx_packet),
4404 if (!priv->rx_buffers) {
4405 IPW_DEBUG_INFO("can't allocate rx packet buffer table\n");
4407 bd_queue_free(priv, &priv->rx_queue);
4409 status_queue_free(priv);
4414 for (i = 0; i < RX_QUEUE_LENGTH; i++) {
4415 struct ipw2100_rx_packet *packet = &priv->rx_buffers[i];
4417 err = ipw2100_alloc_skb(priv, packet);
4418 if (unlikely(err)) {
4423 /* The BD holds the cache aligned address */
4424 priv->rx_queue.drv[i].host_addr = packet->dma_addr;
4425 priv->rx_queue.drv[i].buf_length = IPW_RX_NIC_BUFFER_LENGTH;
4426 priv->status_queue.drv[i].status_fields = 0;
4429 if (i == RX_QUEUE_LENGTH)
4432 for (j = 0; j < i; j++) {
4433 pci_unmap_single(priv->pci_dev, priv->rx_buffers[j].dma_addr,
4434 sizeof(struct ipw2100_rx_packet),
4435 PCI_DMA_FROMDEVICE);
4436 dev_kfree_skb(priv->rx_buffers[j].skb);
4439 kfree(priv->rx_buffers);
4440 priv->rx_buffers = NULL;
4442 bd_queue_free(priv, &priv->rx_queue);
4444 status_queue_free(priv);
4449 static void ipw2100_rx_initialize(struct ipw2100_priv *priv)
4451 IPW_DEBUG_INFO("enter\n");
4453 priv->rx_queue.oldest = 0;
4454 priv->rx_queue.available = priv->rx_queue.entries - 1;
4455 priv->rx_queue.next = priv->rx_queue.entries - 1;
4457 INIT_STAT(&priv->rxq_stat);
4458 SET_STAT(&priv->rxq_stat, priv->rx_queue.available);
4460 bd_queue_initialize(priv, &priv->rx_queue,
4461 IPW_MEM_HOST_SHARED_RX_BD_BASE,
4462 IPW_MEM_HOST_SHARED_RX_BD_SIZE,
4463 IPW_MEM_HOST_SHARED_RX_READ_INDEX,
4464 IPW_MEM_HOST_SHARED_RX_WRITE_INDEX);
4466 /* set up the status queue */
4467 write_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_STATUS_BASE,
4468 priv->status_queue.nic);
4470 IPW_DEBUG_INFO("exit\n");
4473 static void ipw2100_rx_free(struct ipw2100_priv *priv)
4477 IPW_DEBUG_INFO("enter\n");
4479 bd_queue_free(priv, &priv->rx_queue);
4480 status_queue_free(priv);
4482 if (!priv->rx_buffers)
4485 for (i = 0; i < RX_QUEUE_LENGTH; i++) {
4486 if (priv->rx_buffers[i].rxp) {
4487 pci_unmap_single(priv->pci_dev,
4488 priv->rx_buffers[i].dma_addr,
4489 sizeof(struct ipw2100_rx),
4490 PCI_DMA_FROMDEVICE);
4491 dev_kfree_skb(priv->rx_buffers[i].skb);
4495 kfree(priv->rx_buffers);
4496 priv->rx_buffers = NULL;
4498 IPW_DEBUG_INFO("exit\n");
4501 static int ipw2100_read_mac_address(struct ipw2100_priv *priv)
4503 u32 length = ETH_ALEN;
4508 err = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ADAPTER_MAC,
4511 IPW_DEBUG_INFO("MAC address read failed\n");
4514 IPW_DEBUG_INFO("card MAC is %02X:%02X:%02X:%02X:%02X:%02X\n",
4515 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
4517 memcpy(priv->net_dev->dev_addr, mac, ETH_ALEN);
4522 /********************************************************************
4526 ********************************************************************/
4528 int ipw2100_set_mac_address(struct ipw2100_priv *priv, int batch_mode)
4530 struct host_command cmd = {
4531 .host_command = ADAPTER_ADDRESS,
4532 .host_command_sequence = 0,
4533 .host_command_length = ETH_ALEN
4537 IPW_DEBUG_HC("SET_MAC_ADDRESS\n");
4539 IPW_DEBUG_INFO("enter\n");
4541 if (priv->config & CFG_CUSTOM_MAC) {
4542 memcpy(cmd.host_command_parameters, priv->mac_addr,
4544 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
4546 memcpy(cmd.host_command_parameters, priv->net_dev->dev_addr,
4549 err = ipw2100_hw_send_command(priv, &cmd);
4551 IPW_DEBUG_INFO("exit\n");
4555 int ipw2100_set_port_type(struct ipw2100_priv *priv, u32 port_type,
4558 struct host_command cmd = {
4559 .host_command = PORT_TYPE,
4560 .host_command_sequence = 0,
4561 .host_command_length = sizeof(u32)
4565 switch (port_type) {
4567 cmd.host_command_parameters[0] = IPW_BSS;
4570 cmd.host_command_parameters[0] = IPW_IBSS;
4574 IPW_DEBUG_HC("PORT_TYPE: %s\n",
4575 port_type == IPW_IBSS ? "Ad-Hoc" : "Managed");
4578 err = ipw2100_disable_adapter(priv);
4580 IPW_DEBUG_ERROR("%s: Could not disable adapter %d\n",
4581 priv->net_dev->name, err);
4586 /* send cmd to firmware */
4587 err = ipw2100_hw_send_command(priv, &cmd);
4590 ipw2100_enable_adapter(priv);
4596 int ipw2100_set_channel(struct ipw2100_priv *priv, u32 channel, int batch_mode)
4598 struct host_command cmd = {
4599 .host_command = CHANNEL,
4600 .host_command_sequence = 0,
4601 .host_command_length = sizeof(u32)
4605 cmd.host_command_parameters[0] = channel;
4607 IPW_DEBUG_HC("CHANNEL: %d\n", channel);
4609 /* If BSS then we don't support channel selection */
4610 if (priv->ieee->iw_mode == IW_MODE_INFRA)
4613 if ((channel != 0) &&
4614 ((channel < REG_MIN_CHANNEL) || (channel > REG_MAX_CHANNEL)))
4618 err = ipw2100_disable_adapter(priv);
4623 err = ipw2100_hw_send_command(priv, &cmd);
4625 IPW_DEBUG_INFO("Failed to set channel to %d",
4631 priv->config |= CFG_STATIC_CHANNEL;
4633 priv->config &= ~CFG_STATIC_CHANNEL;
4635 priv->channel = channel;
4638 err = ipw2100_enable_adapter(priv);
4646 int ipw2100_system_config(struct ipw2100_priv *priv, int batch_mode)
4648 struct host_command cmd = {
4649 .host_command = SYSTEM_CONFIG,
4650 .host_command_sequence = 0,
4651 .host_command_length = 12,
4653 u32 ibss_mask, len = sizeof(u32);
4656 /* Set system configuration */
4659 err = ipw2100_disable_adapter(priv);
4664 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
4665 cmd.host_command_parameters[0] |= IPW_CFG_IBSS_AUTO_START;
4667 cmd.host_command_parameters[0] |= IPW_CFG_IBSS_MASK |
4669 IPW_CFG_802_1x_ENABLE;
4671 if (!(priv->config & CFG_LONG_PREAMBLE))
4672 cmd.host_command_parameters[0] |= IPW_CFG_PREAMBLE_AUTO;
4674 err = ipw2100_get_ordinal(priv,
4675 IPW_ORD_EEPROM_IBSS_11B_CHANNELS,
4678 ibss_mask = IPW_IBSS_11B_DEFAULT_MASK;
4680 cmd.host_command_parameters[1] = REG_CHANNEL_MASK;
4681 cmd.host_command_parameters[2] = REG_CHANNEL_MASK & ibss_mask;
4684 /*cmd.host_command_parameters[0] |= DIVERSITY_ANTENNA_A;*/
4686 err = ipw2100_hw_send_command(priv, &cmd);
4690 /* If IPv6 is configured in the kernel then we don't want to filter out all
4691 * of the multicast packets as IPv6 needs some. */
4692 #if !defined(CONFIG_IPV6) && !defined(CONFIG_IPV6_MODULE)
4693 cmd.host_command = ADD_MULTICAST;
4694 cmd.host_command_sequence = 0;
4695 cmd.host_command_length = 0;
4697 ipw2100_hw_send_command(priv, &cmd);
4700 err = ipw2100_enable_adapter(priv);
4708 int ipw2100_set_tx_rates(struct ipw2100_priv *priv, u32 rate, int batch_mode)
4710 struct host_command cmd = {
4711 .host_command = BASIC_TX_RATES,
4712 .host_command_sequence = 0,
4713 .host_command_length = 4
4717 cmd.host_command_parameters[0] = rate & TX_RATE_MASK;
4720 err = ipw2100_disable_adapter(priv);
4725 /* Set BASIC TX Rate first */
4726 ipw2100_hw_send_command(priv, &cmd);
4729 cmd.host_command = TX_RATES;
4730 ipw2100_hw_send_command(priv, &cmd);
4732 /* Set MSDU TX Rate */
4733 cmd.host_command = MSDU_TX_RATES;
4734 ipw2100_hw_send_command(priv, &cmd);
4737 err = ipw2100_enable_adapter(priv);
4742 priv->tx_rates = rate;
4747 int ipw2100_set_power_mode(struct ipw2100_priv *priv,
4750 struct host_command cmd = {
4751 .host_command = POWER_MODE,
4752 .host_command_sequence = 0,
4753 .host_command_length = 4
4757 cmd.host_command_parameters[0] = power_level;
4759 err = ipw2100_hw_send_command(priv, &cmd);
4763 if (power_level == IPW_POWER_MODE_CAM)
4764 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
4766 priv->power_mode = IPW_POWER_ENABLED | power_level;
4768 #ifdef CONFIG_IPW2100_TX_POWER
4769 if (priv->port_type == IBSS &&
4770 priv->adhoc_power != DFTL_IBSS_TX_POWER) {
4771 /* Set beacon interval */
4772 cmd.host_command = TX_POWER_INDEX;
4773 cmd.host_command_parameters[0] = (u32)priv->adhoc_power;
4775 err = ipw2100_hw_send_command(priv, &cmd);
4785 int ipw2100_set_rts_threshold(struct ipw2100_priv *priv, u32 threshold)
4787 struct host_command cmd = {
4788 .host_command = RTS_THRESHOLD,
4789 .host_command_sequence = 0,
4790 .host_command_length = 4
4794 if (threshold & RTS_DISABLED)
4795 cmd.host_command_parameters[0] = MAX_RTS_THRESHOLD;
4797 cmd.host_command_parameters[0] = threshold & ~RTS_DISABLED;
4799 err = ipw2100_hw_send_command(priv, &cmd);
4803 priv->rts_threshold = threshold;
4809 int ipw2100_set_fragmentation_threshold(struct ipw2100_priv *priv,
4810 u32 threshold, int batch_mode)
4812 struct host_command cmd = {
4813 .host_command = FRAG_THRESHOLD,
4814 .host_command_sequence = 0,
4815 .host_command_length = 4,
4816 .host_command_parameters[0] = 0,
4821 err = ipw2100_disable_adapter(priv);
4827 threshold = DEFAULT_FRAG_THRESHOLD;
4829 threshold = max(threshold, MIN_FRAG_THRESHOLD);
4830 threshold = min(threshold, MAX_FRAG_THRESHOLD);
4833 cmd.host_command_parameters[0] = threshold;
4835 IPW_DEBUG_HC("FRAG_THRESHOLD: %u\n", threshold);
4837 err = ipw2100_hw_send_command(priv, &cmd);
4840 ipw2100_enable_adapter(priv);
4843 priv->frag_threshold = threshold;
4849 int ipw2100_set_short_retry(struct ipw2100_priv *priv, u32 retry)
4851 struct host_command cmd = {
4852 .host_command = SHORT_RETRY_LIMIT,
4853 .host_command_sequence = 0,
4854 .host_command_length = 4
4858 cmd.host_command_parameters[0] = retry;
4860 err = ipw2100_hw_send_command(priv, &cmd);
4864 priv->short_retry_limit = retry;
4869 int ipw2100_set_long_retry(struct ipw2100_priv *priv, u32 retry)
4871 struct host_command cmd = {
4872 .host_command = LONG_RETRY_LIMIT,
4873 .host_command_sequence = 0,
4874 .host_command_length = 4
4878 cmd.host_command_parameters[0] = retry;
4880 err = ipw2100_hw_send_command(priv, &cmd);
4884 priv->long_retry_limit = retry;
4890 int ipw2100_set_mandatory_bssid(struct ipw2100_priv *priv, u8 *bssid,
4893 struct host_command cmd = {
4894 .host_command = MANDATORY_BSSID,
4895 .host_command_sequence = 0,
4896 .host_command_length = (bssid == NULL) ? 0 : ETH_ALEN
4900 #ifdef CONFIG_IPW_DEBUG
4903 "MANDATORY_BSSID: %02X:%02X:%02X:%02X:%02X:%02X\n",
4904 bssid[0], bssid[1], bssid[2], bssid[3], bssid[4],
4907 IPW_DEBUG_HC("MANDATORY_BSSID: <clear>\n");
4909 /* if BSSID is empty then we disable mandatory bssid mode */
4911 memcpy((u8 *)cmd.host_command_parameters, bssid, ETH_ALEN);
4914 err = ipw2100_disable_adapter(priv);
4919 err = ipw2100_hw_send_command(priv, &cmd);
4922 ipw2100_enable_adapter(priv);
4927 #ifdef CONFIG_IEEE80211_WPA
4928 static int ipw2100_disassociate_bssid(struct ipw2100_priv *priv)
4930 struct host_command cmd = {
4931 .host_command = DISASSOCIATION_BSSID,
4932 .host_command_sequence = 0,
4933 .host_command_length = ETH_ALEN
4938 IPW_DEBUG_HC("DISASSOCIATION_BSSID\n");
4941 /* The Firmware currently ignores the BSSID and just disassociates from
4942 * the currently associated AP -- but in the off chance that a future
4943 * firmware does use the BSSID provided here, we go ahead and try and
4944 * set it to the currently associated AP's BSSID */
4945 memcpy(cmd.host_command_parameters, priv->bssid, ETH_ALEN);
4947 err = ipw2100_hw_send_command(priv, &cmd);
4954 * Pseudo code for setting up wpa_frame:
4957 void x(struct ieee80211_assoc_frame *wpa_assoc)
4959 struct ipw2100_wpa_assoc_frame frame;
4960 frame->fixed_ie_mask = IPW_WPA_CAPABILTIES |
4961 IPW_WPA_LISTENINTERVAL |
4963 frame->capab_info = wpa_assoc->capab_info;
4964 frame->lisen_interval = wpa_assoc->listent_interval;
4965 memcpy(frame->current_ap, wpa_assoc->current_ap, ETH_ALEN);
4967 /* UNKNOWN -- I'm not postivive about this part; don't have any WPA
4968 * setup here to test it with.
4970 * Walk the IEs in the wpa_assoc and figure out the total size of all
4971 * that data. Stick that into frame->var_ie_len. Then memcpy() all of
4972 * the IEs from wpa_frame into frame.
4974 frame->var_ie_len = calculate_ie_len(wpa_assoc);
4975 memcpy(frame->var_ie, wpa_assoc->variable, frame->var_ie_len);
4977 ipw2100_set_wpa_ie(priv, &frame, 0);
4984 static int ipw2100_set_wpa_ie(struct ipw2100_priv *,
4985 struct ipw2100_wpa_assoc_frame *, int)
4986 __attribute__ ((unused));
4988 static int ipw2100_set_wpa_ie(struct ipw2100_priv *priv,
4989 struct ipw2100_wpa_assoc_frame *wpa_frame,
4992 struct host_command cmd = {
4993 .host_command = SET_WPA_IE,
4994 .host_command_sequence = 0,
4995 .host_command_length = sizeof(struct ipw2100_wpa_assoc_frame),
4999 IPW_DEBUG_HC("SET_WPA_IE\n");
5002 err = ipw2100_disable_adapter(priv);
5007 memcpy(cmd.host_command_parameters, wpa_frame,
5008 sizeof(struct ipw2100_wpa_assoc_frame));
5010 err = ipw2100_hw_send_command(priv, &cmd);
5013 if (ipw2100_enable_adapter(priv))
5020 struct security_info_params {
5021 u32 allowed_ciphers;
5024 u8 replay_counters_number;
5025 u8 unicast_using_group;
5026 } __attribute__ ((packed));
5028 int ipw2100_set_security_information(struct ipw2100_priv *priv,
5031 int unicast_using_group,
5034 struct host_command cmd = {
5035 .host_command = SET_SECURITY_INFORMATION,
5036 .host_command_sequence = 0,
5037 .host_command_length = sizeof(struct security_info_params)
5039 struct security_info_params *security =
5040 (struct security_info_params *)&cmd.host_command_parameters;
5042 memset(security, 0, sizeof(*security));
5044 /* If shared key AP authentication is turned on, then we need to
5045 * configure the firmware to try and use it.
5047 * Actual data encryption/decryption is handled by the host. */
5048 security->auth_mode = auth_mode;
5049 security->unicast_using_group = unicast_using_group;
5051 switch (security_level) {
5054 security->allowed_ciphers = IPW_NONE_CIPHER;
5057 security->allowed_ciphers = IPW_WEP40_CIPHER |
5061 security->allowed_ciphers = IPW_WEP40_CIPHER |
5062 IPW_WEP104_CIPHER | IPW_TKIP_CIPHER;
5064 case SEC_LEVEL_2_CKIP:
5065 security->allowed_ciphers = IPW_WEP40_CIPHER |
5066 IPW_WEP104_CIPHER | IPW_CKIP_CIPHER;
5069 security->allowed_ciphers = IPW_WEP40_CIPHER |
5070 IPW_WEP104_CIPHER | IPW_TKIP_CIPHER | IPW_CCMP_CIPHER;
5075 "SET_SECURITY_INFORMATION: auth:%d cipher:0x%02X (level %d)\n",
5076 security->auth_mode, security->allowed_ciphers, security_level);
5078 security->replay_counters_number = 0;
5081 err = ipw2100_disable_adapter(priv);
5086 err = ipw2100_hw_send_command(priv, &cmd);
5089 ipw2100_enable_adapter(priv);
5094 int ipw2100_set_tx_power(struct ipw2100_priv *priv,
5097 struct host_command cmd = {
5098 .host_command = TX_POWER_INDEX,
5099 .host_command_sequence = 0,
5100 .host_command_length = 4
5104 cmd.host_command_parameters[0] = tx_power;
5106 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
5107 err = ipw2100_hw_send_command(priv, &cmd);
5109 priv->tx_power = tx_power;
5114 int ipw2100_set_ibss_beacon_interval(struct ipw2100_priv *priv,
5115 u32 interval, int batch_mode)
5117 struct host_command cmd = {
5118 .host_command = BEACON_INTERVAL,
5119 .host_command_sequence = 0,
5120 .host_command_length = 4
5124 cmd.host_command_parameters[0] = interval;
5126 IPW_DEBUG_INFO("enter\n");
5128 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
5130 err = ipw2100_disable_adapter(priv);
5135 ipw2100_hw_send_command(priv, &cmd);
5138 err = ipw2100_enable_adapter(priv);
5144 IPW_DEBUG_INFO("exit\n");
5150 void ipw2100_queues_initialize(struct ipw2100_priv *priv)
5152 ipw2100_tx_initialize(priv);
5153 ipw2100_rx_initialize(priv);
5154 ipw2100_msg_initialize(priv);
5157 void ipw2100_queues_free(struct ipw2100_priv *priv)
5159 ipw2100_tx_free(priv);
5160 ipw2100_rx_free(priv);
5161 ipw2100_msg_free(priv);
5164 int ipw2100_queues_allocate(struct ipw2100_priv *priv)
5166 if (ipw2100_tx_allocate(priv) ||
5167 ipw2100_rx_allocate(priv) ||
5168 ipw2100_msg_allocate(priv))
5174 ipw2100_tx_free(priv);
5175 ipw2100_rx_free(priv);
5176 ipw2100_msg_free(priv);
5180 #define IPW_PRIVACY_CAPABLE 0x0008
5182 static int ipw2100_set_wep_flags(struct ipw2100_priv *priv, u32 flags,
5185 struct host_command cmd = {
5186 .host_command = WEP_FLAGS,
5187 .host_command_sequence = 0,
5188 .host_command_length = 4
5192 cmd.host_command_parameters[0] = flags;
5194 IPW_DEBUG_HC("WEP_FLAGS: flags = 0x%08X\n", flags);
5197 err = ipw2100_disable_adapter(priv);
5199 IPW_DEBUG_ERROR("%s: Could not disable adapter %d\n",
5200 priv->net_dev->name, err);
5205 /* send cmd to firmware */
5206 err = ipw2100_hw_send_command(priv, &cmd);
5209 ipw2100_enable_adapter(priv);
5214 struct ipw2100_wep_key {
5220 /* Macros to ease up priting WEP keys */
5221 #define WEP_FMT_64 "%02X%02X%02X%02X-%02X"
5222 #define WEP_FMT_128 "%02X%02X%02X%02X-%02X%02X%02X%02X-%02X%02X%02X"
5223 #define WEP_STR_64(x) x[0],x[1],x[2],x[3],x[4]
5224 #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]
5230 * @priv: struct to work on
5231 * @idx: index of the key we want to set
5232 * @key: ptr to the key data to set
5233 * @len: length of the buffer at @key
5234 * @batch_mode: FIXME perform the operation in batch mode, not
5235 * disabling the device.
5237 * @returns 0 if OK, < 0 errno code on error.
5239 * Fill out a command structure with the new wep key, length an
5240 * index and send it down the wire.
5242 static int ipw2100_set_key(struct ipw2100_priv *priv,
5243 int idx, char *key, int len, int batch_mode)
5245 int keylen = len ? (len <= 5 ? 5 : 13) : 0;
5246 struct host_command cmd = {
5247 .host_command = WEP_KEY_INFO,
5248 .host_command_sequence = 0,
5249 .host_command_length = sizeof(struct ipw2100_wep_key),
5251 struct ipw2100_wep_key *wep_key = (void*)cmd.host_command_parameters;
5254 IPW_DEBUG_HC("WEP_KEY_INFO: index = %d, len = %d/%d\n",
5257 /* NOTE: We don't check cached values in case the firmware was reset
5258 * or some other problem is occuring. If the user is setting the key,
5259 * then we push the change */
5262 wep_key->len = keylen;
5265 memcpy(wep_key->key, key, len);
5266 memset(wep_key->key + len, 0, keylen - len);
5269 /* Will be optimized out on debug not being configured in */
5271 IPW_DEBUG_WEP("%s: Clearing key %d\n",
5272 priv->net_dev->name, wep_key->idx);
5273 else if (keylen == 5)
5274 IPW_DEBUG_WEP("%s: idx: %d, len: %d key: " WEP_FMT_64 "\n",
5275 priv->net_dev->name, wep_key->idx, wep_key->len,
5276 WEP_STR_64(wep_key->key));
5278 IPW_DEBUG_WEP("%s: idx: %d, len: %d key: " WEP_FMT_128
5280 priv->net_dev->name, wep_key->idx, wep_key->len,
5281 WEP_STR_128(wep_key->key));
5284 err = ipw2100_disable_adapter(priv);
5285 /* FIXME: IPG: shouldn't this prink be in _disable_adapter()? */
5287 IPW_DEBUG_ERROR("%s: Could not disable adapter %d\n",
5288 priv->net_dev->name, err);
5293 /* send cmd to firmware */
5294 err = ipw2100_hw_send_command(priv, &cmd);
5297 int err2 = ipw2100_enable_adapter(priv);
5304 static int ipw2100_set_key_index(struct ipw2100_priv *priv,
5305 int idx, int batch_mode)
5307 struct host_command cmd = {
5308 .host_command = WEP_KEY_INDEX,
5309 .host_command_sequence = 0,
5310 .host_command_length = 4,
5311 .host_command_parameters[0] = idx,
5315 IPW_DEBUG_HC("WEP_KEY_INDEX: index = %d\n", idx);
5317 if (idx < 0 || idx > 3)
5321 err = ipw2100_disable_adapter(priv);
5323 IPW_DEBUG_ERROR("%s: Could not disable adapter %d\n",
5324 priv->net_dev->name, err);
5329 /* send cmd to firmware */
5330 err = ipw2100_hw_send_command(priv, &cmd);
5333 ipw2100_enable_adapter(priv);
5339 static int ipw2100_configure_security(struct ipw2100_priv *priv,
5342 int i, err, auth_mode, sec_level, use_group;
5344 if (!(priv->status & STATUS_RUNNING))
5348 err = ipw2100_disable_adapter(priv);
5353 if (!priv->sec.enabled) {
5354 err = ipw2100_set_security_information(
5355 priv, IPW_AUTH_OPEN, SEC_LEVEL_0, 0, 1);
5357 auth_mode = IPW_AUTH_OPEN;
5358 if ((priv->sec.flags & SEC_AUTH_MODE) &&
5359 (priv->sec.auth_mode == WLAN_AUTH_SHARED_KEY))
5360 auth_mode = IPW_AUTH_SHARED;
5362 sec_level = SEC_LEVEL_0;
5363 if (priv->sec.flags & SEC_LEVEL)
5364 sec_level = priv->sec.level;
5367 if (priv->sec.flags & SEC_UNICAST_GROUP)
5368 use_group = priv->sec.unicast_uses_group;
5370 err = ipw2100_set_security_information(
5371 priv, auth_mode, sec_level, use_group, 1);
5377 if (priv->sec.enabled) {
5378 for (i = 0; i < 4; i++) {
5379 if (!(priv->sec.flags & (1 << i))) {
5380 memset(priv->sec.keys[i], 0, WEP_KEY_LEN);
5381 priv->sec.key_sizes[i] = 0;
5383 err = ipw2100_set_key(priv, i,
5385 priv->sec.key_sizes[i],
5392 ipw2100_set_key_index(priv, priv->ieee->tx_keyidx, 1);
5395 /* Always enable privacy so the Host can filter WEP packets if
5396 * encrypted data is sent up */
5397 err = ipw2100_set_wep_flags(
5398 priv, priv->sec.enabled ? IPW_PRIVACY_CAPABLE : 0, 1);
5402 priv->status &= ~STATUS_SECURITY_UPDATED;
5406 ipw2100_enable_adapter(priv);
5411 static void ipw2100_security_work(struct ipw2100_priv *priv)
5413 /* If we happen to have reconnected before we get a chance to
5414 * process this, then update the security settings--which causes
5415 * a disassociation to occur */
5416 if (!(priv->status & STATUS_ASSOCIATED) &&
5417 priv->status & STATUS_SECURITY_UPDATED)
5418 ipw2100_configure_security(priv, 0);
5421 static void shim__set_security(struct net_device *dev,
5422 struct ieee80211_security *sec)
5424 struct ipw2100_priv *priv = ieee80211_priv(dev);
5425 int i, force_update = 0;
5427 down(&priv->action_sem);
5428 if (!(priv->status & STATUS_INITIALIZED))
5431 for (i = 0; i < 4; i++) {
5432 if (sec->flags & (1 << i)) {
5433 priv->sec.key_sizes[i] = sec->key_sizes[i];
5434 if (sec->key_sizes[i] == 0)
5435 priv->sec.flags &= ~(1 << i);
5437 memcpy(priv->sec.keys[i], sec->keys[i],
5439 priv->sec.flags |= (1 << i);
5440 priv->status |= STATUS_SECURITY_UPDATED;
5444 if ((sec->flags & SEC_ACTIVE_KEY) &&
5445 priv->sec.active_key != sec->active_key) {
5446 if (sec->active_key <= 3) {
5447 priv->sec.active_key = sec->active_key;
5448 priv->sec.flags |= SEC_ACTIVE_KEY;
5450 priv->sec.flags &= ~SEC_ACTIVE_KEY;
5452 priv->status |= STATUS_SECURITY_UPDATED;
5455 if ((sec->flags & SEC_AUTH_MODE) &&
5456 (priv->sec.auth_mode != sec->auth_mode)) {
5457 priv->sec.auth_mode = sec->auth_mode;
5458 priv->sec.flags |= SEC_AUTH_MODE;
5459 priv->status |= STATUS_SECURITY_UPDATED;
5462 if (sec->flags & SEC_ENABLED &&
5463 priv->sec.enabled != sec->enabled) {
5464 priv->sec.flags |= SEC_ENABLED;
5465 priv->sec.enabled = sec->enabled;
5466 priv->status |= STATUS_SECURITY_UPDATED;
5470 if (sec->flags & SEC_LEVEL &&
5471 priv->sec.level != sec->level) {
5472 priv->sec.level = sec->level;
5473 priv->sec.flags |= SEC_LEVEL;
5474 priv->status |= STATUS_SECURITY_UPDATED;
5477 IPW_DEBUG_WEP("Security flags: %c %c%c%c%c %c%c%c%c\n",
5478 priv->sec.flags & (1<<8) ? '1' : '0',
5479 priv->sec.flags & (1<<7) ? '1' : '0',
5480 priv->sec.flags & (1<<6) ? '1' : '0',
5481 priv->sec.flags & (1<<5) ? '1' : '0',
5482 priv->sec.flags & (1<<4) ? '1' : '0',
5483 priv->sec.flags & (1<<3) ? '1' : '0',
5484 priv->sec.flags & (1<<2) ? '1' : '0',
5485 priv->sec.flags & (1<<1) ? '1' : '0',
5486 priv->sec.flags & (1<<0) ? '1' : '0');
5488 /* As a temporary work around to enable WPA until we figure out why
5489 * wpa_supplicant toggles the security capability of the driver, which
5490 * forces a disassocation with force_update...
5492 * if (force_update || !(priv->status & STATUS_ASSOCIATED))*/
5493 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
5494 ipw2100_configure_security(priv, 0);
5496 up(&priv->action_sem);
5499 static int ipw2100_adapter_setup(struct ipw2100_priv *priv)
5505 IPW_DEBUG_INFO("enter\n");
5507 err = ipw2100_disable_adapter(priv);
5510 #ifdef CONFIG_IPW2100_MONITOR
5511 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
5512 err = ipw2100_set_channel(priv, priv->channel, batch_mode);
5516 IPW_DEBUG_INFO("exit\n");
5520 #endif /* CONFIG_IPW2100_MONITOR */
5522 err = ipw2100_read_mac_address(priv);
5526 err = ipw2100_set_mac_address(priv, batch_mode);
5530 err = ipw2100_set_port_type(priv, priv->ieee->iw_mode, batch_mode);
5534 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
5535 err = ipw2100_set_channel(priv, priv->channel, batch_mode);
5540 err = ipw2100_system_config(priv, batch_mode);
5544 err = ipw2100_set_tx_rates(priv, priv->tx_rates, batch_mode);
5548 /* Default to power mode OFF */
5549 err = ipw2100_set_power_mode(priv, IPW_POWER_MODE_CAM);
5553 err = ipw2100_set_rts_threshold(priv, priv->rts_threshold);
5557 if (priv->config & CFG_STATIC_BSSID)
5558 bssid = priv->bssid;
5561 err = ipw2100_set_mandatory_bssid(priv, bssid, batch_mode);
5565 if (priv->config & CFG_STATIC_ESSID)
5566 err = ipw2100_set_essid(priv, priv->essid, priv->essid_len,
5569 err = ipw2100_set_essid(priv, NULL, 0, batch_mode);
5573 err = ipw2100_configure_security(priv, batch_mode);
5577 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
5578 err = ipw2100_set_ibss_beacon_interval(
5579 priv, priv->beacon_interval, batch_mode);
5583 err = ipw2100_set_tx_power(priv, priv->tx_power);
5589 err = ipw2100_set_fragmentation_threshold(
5590 priv, priv->frag_threshold, batch_mode);
5595 IPW_DEBUG_INFO("exit\n");
5601 /*************************************************************************
5603 * EXTERNALLY CALLED METHODS
5605 *************************************************************************/
5607 /* This method is called by the network layer -- not to be confused with
5608 * ipw2100_set_mac_address() declared above called by this driver (and this
5609 * method as well) to talk to the firmware */
5610 static int ipw2100_set_address(struct net_device *dev, void *p)
5612 struct ipw2100_priv *priv = ieee80211_priv(dev);
5613 struct sockaddr *addr = p;
5616 if (!is_valid_ether_addr(addr->sa_data))
5617 return -EADDRNOTAVAIL;
5619 down(&priv->action_sem);
5621 priv->config |= CFG_CUSTOM_MAC;
5622 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
5624 err = ipw2100_set_mac_address(priv, 0);
5628 priv->reset_backoff = 0;
5629 up(&priv->action_sem);
5630 ipw2100_reset_adapter(priv);
5634 up(&priv->action_sem);
5638 static int ipw2100_open(struct net_device *dev)
5640 struct ipw2100_priv *priv = ieee80211_priv(dev);
5641 unsigned long flags;
5642 IPW_DEBUG_INFO("dev->open\n");
5644 spin_lock_irqsave(&priv->low_lock, flags);
5645 if (priv->status & STATUS_ASSOCIATED)
5646 netif_start_queue(dev);
5647 spin_unlock_irqrestore(&priv->low_lock, flags);
5652 static int ipw2100_close(struct net_device *dev)
5654 struct ipw2100_priv *priv = ieee80211_priv(dev);
5655 unsigned long flags;
5656 struct list_head *element;
5657 struct ipw2100_tx_packet *packet;
5659 IPW_DEBUG_INFO("enter\n");
5661 spin_lock_irqsave(&priv->low_lock, flags);
5663 if (priv->status & STATUS_ASSOCIATED)
5664 netif_carrier_off(dev);
5665 netif_stop_queue(dev);
5667 /* Flush the TX queue ... */
5668 while (!list_empty(&priv->tx_pend_list)) {
5669 element = priv->tx_pend_list.next;
5670 packet = list_entry(element, struct ipw2100_tx_packet, list);
5673 DEC_STAT(&priv->tx_pend_stat);
5675 ieee80211_txb_free(packet->info.d_struct.txb);
5676 packet->info.d_struct.txb = NULL;
5678 list_add_tail(element, &priv->tx_free_list);
5679 INC_STAT(&priv->tx_free_stat);
5681 spin_unlock_irqrestore(&priv->low_lock, flags);
5683 IPW_DEBUG_INFO("exit\n");
5691 * TODO: Fix this function... its just wrong
5693 static void ipw2100_tx_timeout(struct net_device *dev)
5695 struct ipw2100_priv *priv = ieee80211_priv(dev);
5697 priv->ieee->stats.tx_errors++;
5699 #ifdef CONFIG_IPW2100_MONITOR
5700 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
5704 IPW_DEBUG_INFO("%s: TX timed out. Scheduling firmware restart.\n",
5706 schedule_reset(priv);
5711 * TODO: reimplement it so that it reads statistics
5712 * from the adapter using ordinal tables
5713 * instead of/in addition to collecting them
5716 static struct net_device_stats *ipw2100_stats(struct net_device *dev)
5718 struct ipw2100_priv *priv = ieee80211_priv(dev);
5720 return &priv->ieee->stats;
5723 /* Support for wpa_supplicant. Will be replaced with WEXT once
5724 * they get WPA support. */
5725 #ifdef CONFIG_IEEE80211_WPA
5727 /* following definitions must match definitions in driver_ipw2100.c */
5729 #define IPW2100_IOCTL_WPA_SUPPLICANT SIOCIWFIRSTPRIV+30
5731 #define IPW2100_CMD_SET_WPA_PARAM 1
5732 #define IPW2100_CMD_SET_WPA_IE 2
5733 #define IPW2100_CMD_SET_ENCRYPTION 3
5734 #define IPW2100_CMD_MLME 4
5736 #define IPW2100_PARAM_WPA_ENABLED 1
5737 #define IPW2100_PARAM_TKIP_COUNTERMEASURES 2
5738 #define IPW2100_PARAM_DROP_UNENCRYPTED 3
5739 #define IPW2100_PARAM_PRIVACY_INVOKED 4
5740 #define IPW2100_PARAM_AUTH_ALGS 5
5741 #define IPW2100_PARAM_IEEE_802_1X 6
5743 #define IPW2100_MLME_STA_DEAUTH 1
5744 #define IPW2100_MLME_STA_DISASSOC 2
5746 #define IPW2100_CRYPT_ERR_UNKNOWN_ALG 2
5747 #define IPW2100_CRYPT_ERR_UNKNOWN_ADDR 3
5748 #define IPW2100_CRYPT_ERR_CRYPT_INIT_FAILED 4
5749 #define IPW2100_CRYPT_ERR_KEY_SET_FAILED 5
5750 #define IPW2100_CRYPT_ERR_TX_KEY_SET_FAILED 6
5751 #define IPW2100_CRYPT_ERR_CARD_CONF_FAILED 7
5753 #define IPW2100_CRYPT_ALG_NAME_LEN 16
5755 struct ipw2100_param {
5757 u8 sta_addr[ETH_ALEN];
5772 u8 alg[IPW2100_CRYPT_ALG_NAME_LEN];
5776 u8 seq[8]; /* sequence counter (set: RX, get: TX) */
5784 /* end of driver_ipw2100.c code */
5786 static int ipw2100_wpa_enable(struct ipw2100_priv *priv, int value){
5788 struct ieee80211_device *ieee = priv->ieee;
5789 struct ieee80211_security sec = {
5790 .flags = SEC_LEVEL | SEC_ENABLED,
5794 ieee->wpa_enabled = value;
5797 sec.level = SEC_LEVEL_3;
5800 sec.level = SEC_LEVEL_0;
5804 if (ieee->set_security)
5805 ieee->set_security(ieee->dev, &sec);
5812 #define AUTH_ALG_OPEN_SYSTEM 0x1
5813 #define AUTH_ALG_SHARED_KEY 0x2
5815 static int ipw2100_wpa_set_auth_algs(struct ipw2100_priv *priv, int value){
5817 struct ieee80211_device *ieee = priv->ieee;
5818 struct ieee80211_security sec = {
5819 .flags = SEC_AUTH_MODE,
5823 if (value & AUTH_ALG_SHARED_KEY){
5824 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
5827 sec.auth_mode = WLAN_AUTH_OPEN;
5831 if (ieee->set_security)
5832 ieee->set_security(ieee->dev, &sec);
5840 static int ipw2100_wpa_set_param(struct net_device *dev, u8 name, u32 value){
5842 struct ipw2100_priv *priv = ieee80211_priv(dev);
5846 case IPW2100_PARAM_WPA_ENABLED:
5847 ret = ipw2100_wpa_enable(priv, value);
5850 case IPW2100_PARAM_TKIP_COUNTERMEASURES:
5851 priv->ieee->tkip_countermeasures=value;
5854 case IPW2100_PARAM_DROP_UNENCRYPTED:
5855 priv->ieee->drop_unencrypted=value;
5858 case IPW2100_PARAM_PRIVACY_INVOKED:
5859 priv->ieee->privacy_invoked=value;
5862 case IPW2100_PARAM_AUTH_ALGS:
5863 ret = ipw2100_wpa_set_auth_algs(priv, value);
5866 case IPW2100_PARAM_IEEE_802_1X:
5867 priv->ieee->ieee802_1x=value;
5871 IPW_DEBUG_ERROR("%s: Unknown WPA param: %d\n",
5879 static int ipw2100_wpa_mlme(struct net_device *dev, int command, int reason){
5881 struct ipw2100_priv *priv = ieee80211_priv(dev);
5885 case IPW2100_MLME_STA_DEAUTH:
5889 case IPW2100_MLME_STA_DISASSOC:
5890 ipw2100_disassociate_bssid(priv);
5894 IPW_DEBUG_ERROR("%s: Unknown MLME request: %d\n",
5895 dev->name, command);
5903 void ipw2100_wpa_assoc_frame(struct ipw2100_priv *priv,
5904 char *wpa_ie, int wpa_ie_len){
5906 struct ipw2100_wpa_assoc_frame frame;
5908 frame.fixed_ie_mask = 0;
5911 memcpy(frame.var_ie, wpa_ie, wpa_ie_len);
5912 frame.var_ie_len = wpa_ie_len;
5914 /* make sure WPA is enabled */
5915 ipw2100_wpa_enable(priv, 1);
5916 ipw2100_set_wpa_ie(priv, &frame, 0);
5920 static int ipw2100_wpa_set_wpa_ie(struct net_device *dev,
5921 struct ipw2100_param *param, int plen){
5923 struct ipw2100_priv *priv = ieee80211_priv(dev);
5924 struct ieee80211_device *ieee = priv->ieee;
5927 if (! ieee->wpa_enabled)
5930 if (param->u.wpa_ie.len > MAX_WPA_IE_LEN ||
5931 (param->u.wpa_ie.len &&
5932 param->u.wpa_ie.data==NULL))
5935 if (param->u.wpa_ie.len){
5936 buf = kmalloc(param->u.wpa_ie.len, GFP_KERNEL);
5940 memcpy(buf, param->u.wpa_ie.data, param->u.wpa_ie.len);
5942 kfree(ieee->wpa_ie);
5944 ieee->wpa_ie_len = param->u.wpa_ie.len;
5947 kfree(ieee->wpa_ie);
5948 ieee->wpa_ie = NULL;
5949 ieee->wpa_ie_len = 0;
5952 ipw2100_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
5957 /* implementation borrowed from hostap driver */
5959 static int ipw2100_wpa_set_encryption(struct net_device *dev,
5960 struct ipw2100_param *param, int param_len){
5963 struct ipw2100_priv *priv = ieee80211_priv(dev);
5964 struct ieee80211_device *ieee = priv->ieee;
5965 struct ieee80211_crypto_ops *ops;
5966 struct ieee80211_crypt_data **crypt;
5968 struct ieee80211_security sec = {
5972 param->u.crypt.err = 0;
5973 param->u.crypt.alg[IPW2100_CRYPT_ALG_NAME_LEN - 1] = '\0';
5976 (int) ((char *) param->u.crypt.key - (char *) param) +
5977 param->u.crypt.key_len){
5978 IPW_DEBUG_INFO("Len mismatch %d, %d\n", param_len, param->u.crypt.key_len);
5981 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
5982 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
5983 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
5984 if (param->u.crypt.idx >= WEP_KEYS)
5986 crypt = &ieee->crypt[param->u.crypt.idx];
5991 if (strcmp(param->u.crypt.alg, "none") == 0) {
5994 sec.level = SEC_LEVEL_0;
5995 sec.flags |= SEC_ENABLED | SEC_LEVEL;
5996 ieee80211_crypt_delayed_deinit(ieee, crypt);
6001 sec.flags |= SEC_ENABLED;
6003 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6004 if (ops == NULL && strcmp(param->u.crypt.alg, "WEP") == 0) {
6005 request_module("ieee80211_crypt_wep");
6006 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6007 } else if (ops == NULL && strcmp(param->u.crypt.alg, "TKIP") == 0) {
6008 request_module("ieee80211_crypt_tkip");
6009 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6010 } else if (ops == NULL && strcmp(param->u.crypt.alg, "CCMP") == 0) {
6011 request_module("ieee80211_crypt_ccmp");
6012 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6015 IPW_DEBUG_INFO("%s: unknown crypto alg '%s'\n",
6016 dev->name, param->u.crypt.alg);
6017 param->u.crypt.err = IPW2100_CRYPT_ERR_UNKNOWN_ALG;
6022 if (*crypt == NULL || (*crypt)->ops != ops) {
6023 struct ieee80211_crypt_data *new_crypt;
6025 ieee80211_crypt_delayed_deinit(ieee, crypt);
6027 new_crypt = (struct ieee80211_crypt_data *)
6028 kmalloc(sizeof(struct ieee80211_crypt_data), GFP_KERNEL);
6029 if (new_crypt == NULL) {
6033 memset(new_crypt, 0, sizeof(struct ieee80211_crypt_data));
6034 new_crypt->ops = ops;
6035 if (new_crypt->ops && try_module_get(new_crypt->ops->owner))
6036 new_crypt->priv = new_crypt->ops->init(param->u.crypt.idx);
6038 if (new_crypt->priv == NULL) {
6040 param->u.crypt.err =
6041 IPW2100_CRYPT_ERR_CRYPT_INIT_FAILED;
6049 if (param->u.crypt.key_len > 0 && (*crypt)->ops->set_key &&
6050 (*crypt)->ops->set_key(param->u.crypt.key,
6051 param->u.crypt.key_len, param->u.crypt.seq,
6052 (*crypt)->priv) < 0) {
6053 IPW_DEBUG_INFO("%s: key setting failed\n",
6055 param->u.crypt.err = IPW2100_CRYPT_ERR_KEY_SET_FAILED;
6060 if (param->u.crypt.set_tx){
6061 ieee->tx_keyidx = param->u.crypt.idx;
6062 sec.active_key = param->u.crypt.idx;
6063 sec.flags |= SEC_ACTIVE_KEY;
6066 if (ops->name != NULL){
6068 if (strcmp(ops->name, "WEP") == 0) {
6069 memcpy(sec.keys[param->u.crypt.idx], param->u.crypt.key, param->u.crypt.key_len);
6070 sec.key_sizes[param->u.crypt.idx] = param->u.crypt.key_len;
6071 sec.flags |= (1 << param->u.crypt.idx);
6072 sec.flags |= SEC_LEVEL;
6073 sec.level = SEC_LEVEL_1;
6074 } else if (strcmp(ops->name, "TKIP") == 0) {
6075 sec.flags |= SEC_LEVEL;
6076 sec.level = SEC_LEVEL_2;
6077 } else if (strcmp(ops->name, "CCMP") == 0) {
6078 sec.flags |= SEC_LEVEL;
6079 sec.level = SEC_LEVEL_3;
6083 if (ieee->set_security)
6084 ieee->set_security(ieee->dev, &sec);
6086 /* Do not reset port if card is in Managed mode since resetting will
6087 * generate new IEEE 802.11 authentication which may end up in looping
6088 * with IEEE 802.1X. If your hardware requires a reset after WEP
6089 * configuration (for example... Prism2), implement the reset_port in
6090 * the callbacks structures used to initialize the 802.11 stack. */
6091 if (ieee->reset_on_keychange &&
6092 ieee->iw_mode != IW_MODE_INFRA &&
6094 ieee->reset_port(dev)) {
6095 IPW_DEBUG_INFO("%s: reset_port failed\n", dev->name);
6096 param->u.crypt.err = IPW2100_CRYPT_ERR_CARD_CONF_FAILED;
6104 static int ipw2100_wpa_supplicant(struct net_device *dev, struct iw_point *p){
6106 struct ipw2100_param *param;
6109 IPW_DEBUG_IOCTL("wpa_supplicant: len=%d\n", p->length);
6111 if (p->length < sizeof(struct ipw2100_param) || !p->pointer)
6114 param = (struct ipw2100_param *)kmalloc(p->length, GFP_KERNEL);
6118 if (copy_from_user(param, p->pointer, p->length)){
6123 switch (param->cmd){
6125 case IPW2100_CMD_SET_WPA_PARAM:
6126 ret = ipw2100_wpa_set_param(dev, param->u.wpa_param.name,
6127 param->u.wpa_param.value);
6130 case IPW2100_CMD_SET_WPA_IE:
6131 ret = ipw2100_wpa_set_wpa_ie(dev, param, p->length);
6134 case IPW2100_CMD_SET_ENCRYPTION:
6135 ret = ipw2100_wpa_set_encryption(dev, param, p->length);
6138 case IPW2100_CMD_MLME:
6139 ret = ipw2100_wpa_mlme(dev, param->u.mlme.command,
6140 param->u.mlme.reason_code);
6144 IPW_DEBUG_ERROR("%s: Unknown WPA supplicant request: %d\n",
6145 dev->name, param->cmd);
6150 if (ret == 0 && copy_to_user(p->pointer, param, p->length))
6156 #endif /* CONFIG_IEEE80211_WPA */
6158 static int ipw2100_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
6160 #ifdef CONFIG_IEEE80211_WPA
6161 struct iwreq *wrq = (struct iwreq *) rq;
6164 case IPW2100_IOCTL_WPA_SUPPLICANT:
6165 ret = ipw2100_wpa_supplicant(dev, &wrq->u.data);
6172 #endif /* CONFIG_IEEE80211_WPA */
6178 static void ipw_ethtool_get_drvinfo(struct net_device *dev,
6179 struct ethtool_drvinfo *info)
6181 struct ipw2100_priv *priv = ieee80211_priv(dev);
6182 char fw_ver[64], ucode_ver[64];
6184 strcpy(info->driver, DRV_NAME);
6185 strcpy(info->version, DRV_VERSION);
6187 ipw2100_get_fwversion(priv, fw_ver, sizeof(fw_ver));
6188 ipw2100_get_ucodeversion(priv, ucode_ver, sizeof(ucode_ver));
6190 snprintf(info->fw_version, sizeof(info->fw_version), "%s:%d:%s",
6191 fw_ver, priv->eeprom_version, ucode_ver);
6193 strcpy(info->bus_info, pci_name(priv->pci_dev));
6196 static u32 ipw2100_ethtool_get_link(struct net_device *dev)
6198 struct ipw2100_priv *priv = ieee80211_priv(dev);
6199 return (priv->status & STATUS_ASSOCIATED) ? 1 : 0;
6203 static struct ethtool_ops ipw2100_ethtool_ops = {
6204 .get_link = ipw2100_ethtool_get_link,
6205 .get_drvinfo = ipw_ethtool_get_drvinfo,
6208 static void ipw2100_hang_check(void *adapter)
6210 struct ipw2100_priv *priv = adapter;
6211 unsigned long flags;
6212 u32 rtc = 0xa5a5a5a5;
6213 u32 len = sizeof(rtc);
6216 spin_lock_irqsave(&priv->low_lock, flags);
6218 if (priv->fatal_error != 0) {
6219 /* If fatal_error is set then we need to restart */
6220 IPW_DEBUG_INFO("%s: Hardware fatal error detected.\n",
6221 priv->net_dev->name);
6224 } else if (ipw2100_get_ordinal(priv, IPW_ORD_RTC_TIME, &rtc, &len) ||
6225 (rtc == priv->last_rtc)) {
6226 /* Check if firmware is hung */
6227 IPW_DEBUG_INFO("%s: Firmware RTC stalled.\n",
6228 priv->net_dev->name);
6235 priv->stop_hang_check = 1;
6238 /* Restart the NIC */
6239 schedule_reset(priv);
6242 priv->last_rtc = rtc;
6244 if (!priv->stop_hang_check)
6245 queue_delayed_work(priv->workqueue, &priv->hang_check, HZ / 2);
6247 spin_unlock_irqrestore(&priv->low_lock, flags);
6251 static void ipw2100_rf_kill(void *adapter)
6253 struct ipw2100_priv *priv = adapter;
6254 unsigned long flags;
6256 spin_lock_irqsave(&priv->low_lock, flags);
6258 if (rf_kill_active(priv)) {
6259 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
6260 if (!priv->stop_rf_kill)
6261 queue_delayed_work(priv->workqueue, &priv->rf_kill, HZ);
6265 /* RF Kill is now disabled, so bring the device back up */
6267 if (!(priv->status & STATUS_RF_KILL_MASK)) {
6268 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
6270 schedule_reset(priv);
6272 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
6276 spin_unlock_irqrestore(&priv->low_lock, flags);
6279 static void ipw2100_irq_tasklet(struct ipw2100_priv *priv);
6281 /* Look into using netdev destructor to shutdown ieee80211? */
6283 static struct net_device *ipw2100_alloc_device(
6284 struct pci_dev *pci_dev,
6286 unsigned long mem_start,
6287 unsigned long mem_len)
6289 struct ipw2100_priv *priv;
6290 struct net_device *dev;
6292 dev = alloc_ieee80211(sizeof(struct ipw2100_priv));
6295 priv = ieee80211_priv(dev);
6296 priv->ieee = netdev_priv(dev);
6297 priv->pci_dev = pci_dev;
6298 priv->net_dev = dev;
6300 priv->ieee->hard_start_xmit = ipw2100_tx;
6301 priv->ieee->set_security = shim__set_security;
6303 dev->open = ipw2100_open;
6304 dev->stop = ipw2100_close;
6305 dev->init = ipw2100_net_init;
6306 dev->do_ioctl = ipw2100_ioctl;
6307 dev->get_stats = ipw2100_stats;
6308 dev->ethtool_ops = &ipw2100_ethtool_ops;
6309 dev->tx_timeout = ipw2100_tx_timeout;
6310 dev->wireless_handlers = &ipw2100_wx_handler_def;
6311 dev->get_wireless_stats = ipw2100_wx_wireless_stats;
6312 dev->set_mac_address = ipw2100_set_address;
6313 dev->watchdog_timeo = 3*HZ;
6316 dev->base_addr = (unsigned long)base_addr;
6317 dev->mem_start = mem_start;
6318 dev->mem_end = dev->mem_start + mem_len - 1;
6320 /* NOTE: We don't use the wireless_handlers hook
6321 * in dev as the system will start throwing WX requests
6322 * to us before we're actually initialized and it just
6323 * ends up causing problems. So, we just handle
6324 * the WX extensions through the ipw2100_ioctl interface */
6327 /* memset() puts everything to 0, so we only have explicitely set
6328 * those values that need to be something else */
6330 /* If power management is turned on, default to AUTO mode */
6331 priv->power_mode = IPW_POWER_AUTO;
6335 #ifdef CONFIG_IEEE80211_WPA
6336 priv->ieee->wpa_enabled = 0;
6337 priv->ieee->tkip_countermeasures = 0;
6338 priv->ieee->drop_unencrypted = 0;
6339 priv->ieee->privacy_invoked = 0;
6340 priv->ieee->ieee802_1x = 1;
6341 #endif /* CONFIG_IEEE80211_WPA */
6343 /* Set module parameters */
6346 priv->ieee->iw_mode = IW_MODE_ADHOC;
6348 #ifdef CONFIG_IPW2100_MONITOR
6350 priv->ieee->iw_mode = IW_MODE_MONITOR;
6355 priv->ieee->iw_mode = IW_MODE_INFRA;
6360 priv->status |= STATUS_RF_KILL_SW;
6363 ((channel >= REG_MIN_CHANNEL) &&
6364 (channel <= REG_MAX_CHANNEL))) {
6365 priv->config |= CFG_STATIC_CHANNEL;
6366 priv->channel = channel;
6370 priv->config |= CFG_ASSOCIATE;
6372 priv->beacon_interval = DEFAULT_BEACON_INTERVAL;
6373 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
6374 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
6375 priv->rts_threshold = DEFAULT_RTS_THRESHOLD | RTS_DISABLED;
6376 priv->frag_threshold = DEFAULT_FTS | FRAG_DISABLED;
6377 priv->tx_power = IPW_TX_POWER_DEFAULT;
6378 priv->tx_rates = DEFAULT_TX_RATES;
6380 strcpy(priv->nick, "ipw2100");
6382 spin_lock_init(&priv->low_lock);
6383 sema_init(&priv->action_sem, 1);
6384 sema_init(&priv->adapter_sem, 1);
6386 init_waitqueue_head(&priv->wait_command_queue);
6388 netif_carrier_off(dev);
6390 INIT_LIST_HEAD(&priv->msg_free_list);
6391 INIT_LIST_HEAD(&priv->msg_pend_list);
6392 INIT_STAT(&priv->msg_free_stat);
6393 INIT_STAT(&priv->msg_pend_stat);
6395 INIT_LIST_HEAD(&priv->tx_free_list);
6396 INIT_LIST_HEAD(&priv->tx_pend_list);
6397 INIT_STAT(&priv->tx_free_stat);
6398 INIT_STAT(&priv->tx_pend_stat);
6400 INIT_LIST_HEAD(&priv->fw_pend_list);
6401 INIT_STAT(&priv->fw_pend_stat);
6404 #ifdef CONFIG_SOFTWARE_SUSPEND2
6405 priv->workqueue = create_workqueue(DRV_NAME, 0);
6407 priv->workqueue = create_workqueue(DRV_NAME);
6409 INIT_WORK(&priv->reset_work,
6410 (void (*)(void *))ipw2100_reset_adapter, priv);
6411 INIT_WORK(&priv->security_work,
6412 (void (*)(void *))ipw2100_security_work, priv);
6413 INIT_WORK(&priv->wx_event_work,
6414 (void (*)(void *))ipw2100_wx_event_work, priv);
6415 INIT_WORK(&priv->hang_check, ipw2100_hang_check, priv);
6416 INIT_WORK(&priv->rf_kill, ipw2100_rf_kill, priv);
6418 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
6419 ipw2100_irq_tasklet, (unsigned long)priv);
6421 /* NOTE: We do not start the deferred work for status checks yet */
6422 priv->stop_rf_kill = 1;
6423 priv->stop_hang_check = 1;
6430 #define PCI_DMA_32BIT 0x00000000ffffffffULL
6432 static int ipw2100_pci_init_one(struct pci_dev *pci_dev,
6433 const struct pci_device_id *ent)
6435 unsigned long mem_start, mem_len, mem_flags;
6436 char *base_addr = NULL;
6437 struct net_device *dev = NULL;
6438 struct ipw2100_priv *priv = NULL;
6443 IPW_DEBUG_INFO("enter\n");
6445 mem_start = pci_resource_start(pci_dev, 0);
6446 mem_len = pci_resource_len(pci_dev, 0);
6447 mem_flags = pci_resource_flags(pci_dev, 0);
6449 if ((mem_flags & IORESOURCE_MEM) != IORESOURCE_MEM) {
6450 IPW_DEBUG_INFO("weird - resource type is not memory\n");
6455 base_addr = ioremap_nocache(mem_start, mem_len);
6457 printk(KERN_WARNING DRV_NAME
6458 "Error calling ioremap_nocache.\n");
6463 /* allocate and initialize our net_device */
6464 dev = ipw2100_alloc_device(pci_dev, base_addr, mem_start, mem_len);
6466 printk(KERN_WARNING DRV_NAME
6467 "Error calling ipw2100_alloc_device.\n");
6472 /* set up PCI mappings for device */
6473 err = pci_enable_device(pci_dev);
6475 printk(KERN_WARNING DRV_NAME
6476 "Error calling pci_enable_device.\n");
6480 priv = ieee80211_priv(dev);
6482 pci_set_master(pci_dev);
6483 pci_set_drvdata(pci_dev, priv);
6485 err = pci_set_dma_mask(pci_dev, PCI_DMA_32BIT);
6487 printk(KERN_WARNING DRV_NAME
6488 "Error calling pci_set_dma_mask.\n");
6489 pci_disable_device(pci_dev);
6493 err = pci_request_regions(pci_dev, DRV_NAME);
6495 printk(KERN_WARNING DRV_NAME
6496 "Error calling pci_request_regions.\n");
6497 pci_disable_device(pci_dev);
6501 /* We disable the RETRY_TIMEOUT register (0x41) to keep
6502 * PCI Tx retries from interfering with C3 CPU state */
6503 pci_read_config_dword(pci_dev, 0x40, &val);
6504 if ((val & 0x0000ff00) != 0)
6505 pci_write_config_dword(pci_dev, 0x40, val & 0xffff00ff);
6507 pci_set_power_state(pci_dev, 0);
6509 if (!ipw2100_hw_is_adapter_in_system(dev)) {
6510 printk(KERN_WARNING DRV_NAME
6511 "Device not found via register read.\n");
6516 SET_NETDEV_DEV(dev, &pci_dev->dev);
6518 /* Force interrupts to be shut off on the device */
6519 priv->status |= STATUS_INT_ENABLED;
6520 ipw2100_disable_interrupts(priv);
6522 /* Allocate and initialize the Tx/Rx queues and lists */
6523 if (ipw2100_queues_allocate(priv)) {
6524 printk(KERN_WARNING DRV_NAME
6525 "Error calilng ipw2100_queues_allocate.\n");
6529 ipw2100_queues_initialize(priv);
6531 err = request_irq(pci_dev->irq,
6532 ipw2100_interrupt, SA_SHIRQ,
6535 printk(KERN_WARNING DRV_NAME
6536 "Error calling request_irq: %d.\n",
6540 dev->irq = pci_dev->irq;
6542 IPW_DEBUG_INFO("Attempting to register device...\n");
6544 SET_MODULE_OWNER(dev);
6546 printk(KERN_INFO DRV_NAME
6547 ": Detected Intel PRO/Wireless 2100 Network Connection\n");
6549 /* Bring up the interface. Pre 0.46, after we registered the
6550 * network device we would call ipw2100_up. This introduced a race
6551 * condition with newer hotplug configurations (network was coming
6552 * up and making calls before the device was initialized).
6554 * If we called ipw2100_up before we registered the device, then the
6555 * device name wasn't registered. So, we instead use the net_dev->init
6556 * member to call a function that then just turns and calls ipw2100_up.
6557 * net_dev->init is called after name allocation but before the
6558 * notifier chain is called */
6559 down(&priv->action_sem);
6560 err = register_netdev(dev);
6562 printk(KERN_WARNING DRV_NAME
6563 "Error calling register_netdev.\n");
6568 IPW_DEBUG_INFO("%s: Bound to %s\n", dev->name, pci_name(pci_dev));
6570 /* perform this after register_netdev so that dev->name is set */
6571 sysfs_create_group(&pci_dev->dev.kobj, &ipw2100_attribute_group);
6572 netif_carrier_off(dev);
6574 /* If the RF Kill switch is disabled, go ahead and complete the
6575 * startup sequence */
6576 if (!(priv->status & STATUS_RF_KILL_MASK)) {
6577 /* Enable the adapter - sends HOST_COMPLETE */
6578 if (ipw2100_enable_adapter(priv)) {
6579 printk(KERN_WARNING DRV_NAME
6580 ": %s: failed in call to enable adapter.\n",
6581 priv->net_dev->name);
6582 ipw2100_hw_stop_adapter(priv);
6587 /* Start a scan . . . */
6588 ipw2100_set_scan_options(priv);
6589 ipw2100_start_scan(priv);
6592 IPW_DEBUG_INFO("exit\n");
6594 priv->status |= STATUS_INITIALIZED;
6596 up(&priv->action_sem);
6601 up(&priv->action_sem);
6606 unregister_netdev(dev);
6608 ipw2100_hw_stop_adapter(priv);
6610 ipw2100_disable_interrupts(priv);
6613 free_irq(dev->irq, priv);
6615 ipw2100_kill_workqueue(priv);
6617 /* These are safe to call even if they weren't allocated */
6618 ipw2100_queues_free(priv);
6619 sysfs_remove_group(&pci_dev->dev.kobj, &ipw2100_attribute_group);
6621 free_ieee80211(dev);
6622 pci_set_drvdata(pci_dev, NULL);
6626 iounmap((char*)base_addr);
6628 pci_release_regions(pci_dev);
6629 pci_disable_device(pci_dev);
6634 static void __devexit ipw2100_pci_remove_one(struct pci_dev *pci_dev)
6636 struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
6637 struct net_device *dev;
6640 down(&priv->action_sem);
6642 priv->status &= ~STATUS_INITIALIZED;
6644 dev = priv->net_dev;
6645 sysfs_remove_group(&pci_dev->dev.kobj, &ipw2100_attribute_group);
6648 if (ipw2100_firmware.version)
6649 ipw2100_release_firmware(priv, &ipw2100_firmware);
6651 /* Take down the hardware */
6654 /* Release the semaphore so that the network subsystem can
6655 * complete any needed calls into the driver... */
6656 up(&priv->action_sem);
6658 /* Unregister the device first - this results in close()
6659 * being called if the device is open. If we free storage
6660 * first, then close() will crash. */
6661 unregister_netdev(dev);
6663 /* ipw2100_down will ensure that there is no more pending work
6664 * in the workqueue's, so we can safely remove them now. */
6665 ipw2100_kill_workqueue(priv);
6667 ipw2100_queues_free(priv);
6669 /* Free potential debugging firmware snapshot */
6670 ipw2100_snapshot_free(priv);
6673 free_irq(dev->irq, priv);
6676 iounmap((unsigned char *)dev->base_addr);
6678 free_ieee80211(dev);
6681 pci_release_regions(pci_dev);
6682 pci_disable_device(pci_dev);
6684 IPW_DEBUG_INFO("exit\n");
6689 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11)
6690 static int ipw2100_suspend(struct pci_dev *pci_dev, u32 state)
6692 static int ipw2100_suspend(struct pci_dev *pci_dev, pm_message_t state)
6695 struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
6696 struct net_device *dev = priv->net_dev;
6698 IPW_DEBUG_INFO("%s: Going into suspend...\n",
6701 down(&priv->action_sem);
6702 if (priv->status & STATUS_INITIALIZED) {
6703 /* Take down the device; powers it off, etc. */
6707 /* Remove the PRESENT state of the device */
6708 netif_device_detach(dev);
6710 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)
6711 pci_save_state(pci_dev, priv->pm_state);
6713 pci_save_state(pci_dev);
6715 pci_disable_device (pci_dev);
6716 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11)
6717 pci_set_power_state(pci_dev, state);
6719 pci_set_power_state(pci_dev, PCI_D3hot);
6722 up(&priv->action_sem);
6727 static int ipw2100_resume(struct pci_dev *pci_dev)
6729 struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
6730 struct net_device *dev = priv->net_dev;
6733 if (IPW2100_PM_DISABLED)
6736 down(&priv->action_sem);
6738 IPW_DEBUG_INFO("%s: Coming out of suspend...\n",
6741 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11)
6742 pci_set_power_state(pci_dev, 0);
6744 pci_set_power_state(pci_dev, PCI_D0);
6746 pci_enable_device(pci_dev);
6747 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)
6748 pci_restore_state(pci_dev, priv->pm_state);
6750 pci_restore_state(pci_dev);
6754 * Suspend/Resume resets the PCI configuration space, so we have to
6755 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
6756 * from interfering with C3 CPU state. pci_restore_state won't help
6757 * here since it only restores the first 64 bytes pci config header.
6759 pci_read_config_dword(pci_dev, 0x40, &val);
6760 if ((val & 0x0000ff00) != 0)
6761 pci_write_config_dword(pci_dev, 0x40, val & 0xffff00ff);
6763 /* Set the device back into the PRESENT state; this will also wake
6764 * the queue of needed */
6765 netif_device_attach(dev);
6767 /* Bring the device back up */
6768 if (!(priv->status & STATUS_RF_KILL_SW))
6769 ipw2100_up(priv, 0);
6771 up(&priv->action_sem);
6778 #define IPW2100_DEV_ID(x) { PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, x }
6780 static struct pci_device_id ipw2100_pci_id_table[] __devinitdata = {
6781 IPW2100_DEV_ID(0x2520), /* IN 2100A mPCI 3A */
6782 IPW2100_DEV_ID(0x2521), /* IN 2100A mPCI 3B */
6783 IPW2100_DEV_ID(0x2524), /* IN 2100A mPCI 3B */
6784 IPW2100_DEV_ID(0x2525), /* IN 2100A mPCI 3B */
6785 IPW2100_DEV_ID(0x2526), /* IN 2100A mPCI Gen A3 */
6786 IPW2100_DEV_ID(0x2522), /* IN 2100 mPCI 3B */
6787 IPW2100_DEV_ID(0x2523), /* IN 2100 mPCI 3A */
6788 IPW2100_DEV_ID(0x2527), /* IN 2100 mPCI 3B */
6789 IPW2100_DEV_ID(0x2528), /* IN 2100 mPCI 3B */
6790 IPW2100_DEV_ID(0x2529), /* IN 2100 mPCI 3B */
6791 IPW2100_DEV_ID(0x252B), /* IN 2100 mPCI 3A */
6792 IPW2100_DEV_ID(0x252C), /* IN 2100 mPCI 3A */
6793 IPW2100_DEV_ID(0x252D), /* IN 2100 mPCI 3A */
6795 IPW2100_DEV_ID(0x2550), /* IB 2100A mPCI 3B */
6796 IPW2100_DEV_ID(0x2551), /* IB 2100 mPCI 3B */
6797 IPW2100_DEV_ID(0x2553), /* IB 2100 mPCI 3B */
6798 IPW2100_DEV_ID(0x2554), /* IB 2100 mPCI 3B */
6799 IPW2100_DEV_ID(0x2555), /* IB 2100 mPCI 3B */
6801 IPW2100_DEV_ID(0x2560), /* DE 2100A mPCI 3A */
6802 IPW2100_DEV_ID(0x2562), /* DE 2100A mPCI 3A */
6803 IPW2100_DEV_ID(0x2563), /* DE 2100A mPCI 3A */
6804 IPW2100_DEV_ID(0x2561), /* DE 2100 mPCI 3A */
6805 IPW2100_DEV_ID(0x2565), /* DE 2100 mPCI 3A */
6806 IPW2100_DEV_ID(0x2566), /* DE 2100 mPCI 3A */
6807 IPW2100_DEV_ID(0x2567), /* DE 2100 mPCI 3A */
6809 IPW2100_DEV_ID(0x2570), /* GA 2100 mPCI 3B */
6811 IPW2100_DEV_ID(0x2580), /* TO 2100A mPCI 3B */
6812 IPW2100_DEV_ID(0x2582), /* TO 2100A mPCI 3B */
6813 IPW2100_DEV_ID(0x2583), /* TO 2100A mPCI 3B */
6814 IPW2100_DEV_ID(0x2581), /* TO 2100 mPCI 3B */
6815 IPW2100_DEV_ID(0x2585), /* TO 2100 mPCI 3B */
6816 IPW2100_DEV_ID(0x2586), /* TO 2100 mPCI 3B */
6817 IPW2100_DEV_ID(0x2587), /* TO 2100 mPCI 3B */
6819 IPW2100_DEV_ID(0x2590), /* SO 2100A mPCI 3B */
6820 IPW2100_DEV_ID(0x2592), /* SO 2100A mPCI 3B */
6821 IPW2100_DEV_ID(0x2591), /* SO 2100 mPCI 3B */
6822 IPW2100_DEV_ID(0x2593), /* SO 2100 mPCI 3B */
6823 IPW2100_DEV_ID(0x2596), /* SO 2100 mPCI 3B */
6824 IPW2100_DEV_ID(0x2598), /* SO 2100 mPCI 3B */
6826 IPW2100_DEV_ID(0x25A0), /* HP 2100 mPCI 3B */
6830 MODULE_DEVICE_TABLE(pci, ipw2100_pci_id_table);
6832 static struct pci_driver ipw2100_pci_driver = {
6834 .id_table = ipw2100_pci_id_table,
6835 .probe = ipw2100_pci_init_one,
6836 .remove = __devexit_p(ipw2100_pci_remove_one),
6838 .suspend = ipw2100_suspend,
6839 .resume = ipw2100_resume,
6845 * Initialize the ipw2100 driver/module
6847 * @returns 0 if ok, < 0 errno node con error.
6849 * Note: we cannot init the /proc stuff until the PCI driver is there,
6850 * or we risk an unlikely race condition on someone accessing
6851 * uninitialized data in the PCI dev struct through /proc.
6853 static int __init ipw2100_init(void)
6857 printk(KERN_INFO DRV_NAME ": %s, %s\n", DRV_DESCRIPTION, DRV_VERSION);
6858 printk(KERN_INFO DRV_NAME ": %s\n", DRV_COPYRIGHT);
6860 #ifdef CONFIG_IEEE80211_NOWEP
6861 IPW_DEBUG_INFO(DRV_NAME ": Compiled with WEP disabled.\n");
6864 ret = pci_module_init(&ipw2100_pci_driver);
6866 #ifdef CONFIG_IPW_DEBUG
6867 ipw2100_debug_level = debug;
6868 driver_create_file(&ipw2100_pci_driver.driver,
6869 &driver_attr_debug_level);
6877 * Cleanup ipw2100 driver registration
6879 static void __exit ipw2100_exit(void)
6881 /* FIXME: IPG: check that we have no instances of the devices open */
6882 #ifdef CONFIG_IPW_DEBUG
6883 driver_remove_file(&ipw2100_pci_driver.driver,
6884 &driver_attr_debug_level);
6886 pci_unregister_driver(&ipw2100_pci_driver);
6889 module_init(ipw2100_init);
6890 module_exit(ipw2100_exit);
6892 #define WEXT_USECHANNELS 1
6894 const long ipw2100_frequencies[] = {
6895 2412, 2417, 2422, 2427,
6896 2432, 2437, 2442, 2447,
6897 2452, 2457, 2462, 2467,
6901 #define FREQ_COUNT (sizeof(ipw2100_frequencies) / \
6902 sizeof(ipw2100_frequencies[0]))
6904 const long ipw2100_rates_11b[] = {
6911 #define RATE_COUNT (sizeof(ipw2100_rates_11b) / sizeof(ipw2100_rates_11b[0]))
6913 static int ipw2100_wx_get_name(struct net_device *dev,
6914 struct iw_request_info *info,
6915 union iwreq_data *wrqu, char *extra)
6918 * This can be called at any time. No action lock required
6921 struct ipw2100_priv *priv = ieee80211_priv(dev);
6922 if (!(priv->status & STATUS_ASSOCIATED))
6923 strcpy(wrqu->name, "unassociated");
6925 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11b");
6927 IPW_DEBUG_WX("Name: %s\n", wrqu->name);
6932 static int ipw2100_wx_set_freq(struct net_device *dev,
6933 struct iw_request_info *info,
6934 union iwreq_data *wrqu, char *extra)
6936 struct ipw2100_priv *priv = ieee80211_priv(dev);
6937 struct iw_freq *fwrq = &wrqu->freq;
6940 if (priv->ieee->iw_mode == IW_MODE_INFRA)
6943 down(&priv->action_sem);
6944 if (!(priv->status & STATUS_INITIALIZED)) {
6949 /* if setting by freq convert to channel */
6951 if ((fwrq->m >= (int) 2.412e8 &&
6952 fwrq->m <= (int) 2.487e8)) {
6953 int f = fwrq->m / 100000;
6956 while ((c < REG_MAX_CHANNEL) &&
6957 (f != ipw2100_frequencies[c]))
6960 /* hack to fall through */
6966 if (fwrq->e > 0 || fwrq->m > 1000)
6968 else { /* Set the channel */
6969 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
6970 err = ipw2100_set_channel(priv, fwrq->m, 0);
6974 up(&priv->action_sem);
6979 static int ipw2100_wx_get_freq(struct net_device *dev,
6980 struct iw_request_info *info,
6981 union iwreq_data *wrqu, char *extra)
6984 * This can be called at any time. No action lock required
6987 struct ipw2100_priv *priv = ieee80211_priv(dev);
6991 /* If we are associated, trying to associate, or have a statically
6992 * configured CHANNEL then return that; otherwise return ANY */
6993 if (priv->config & CFG_STATIC_CHANNEL ||
6994 priv->status & STATUS_ASSOCIATED)
6995 wrqu->freq.m = priv->channel;
6999 IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
7004 static int ipw2100_wx_set_mode(struct net_device *dev,
7005 struct iw_request_info *info,
7006 union iwreq_data *wrqu, char *extra)
7008 struct ipw2100_priv *priv = ieee80211_priv(dev);
7011 IPW_DEBUG_WX("SET Mode -> %d \n", wrqu->mode);
7013 if (wrqu->mode == priv->ieee->iw_mode)
7016 down(&priv->action_sem);
7017 if (!(priv->status & STATUS_INITIALIZED)) {
7022 switch (wrqu->mode) {
7023 #ifdef CONFIG_IPW2100_MONITOR
7024 case IW_MODE_MONITOR:
7025 err = ipw2100_switch_mode(priv, IW_MODE_MONITOR);
7027 #endif /* CONFIG_IPW2100_MONITOR */
7029 err = ipw2100_switch_mode(priv, IW_MODE_ADHOC);
7034 err = ipw2100_switch_mode(priv, IW_MODE_INFRA);
7039 up(&priv->action_sem);
7043 static int ipw2100_wx_get_mode(struct net_device *dev,
7044 struct iw_request_info *info,
7045 union iwreq_data *wrqu, char *extra)
7048 * This can be called at any time. No action lock required
7051 struct ipw2100_priv *priv = ieee80211_priv(dev);
7053 wrqu->mode = priv->ieee->iw_mode;
7054 IPW_DEBUG_WX("GET Mode -> %d\n", wrqu->mode);
7060 #define POWER_MODES 5
7062 /* Values are in microsecond */
7063 const s32 timeout_duration[POWER_MODES] = {
7071 const s32 period_duration[POWER_MODES] = {
7079 static int ipw2100_wx_get_range(struct net_device *dev,
7080 struct iw_request_info *info,
7081 union iwreq_data *wrqu, char *extra)
7084 * This can be called at any time. No action lock required
7087 struct ipw2100_priv *priv = ieee80211_priv(dev);
7088 struct iw_range *range = (struct iw_range *)extra;
7092 wrqu->data.length = sizeof(*range);
7093 memset(range, 0, sizeof(*range));
7095 /* Let's try to keep this struct in the same order as in
7096 * linux/include/wireless.h
7099 /* TODO: See what values we can set, and remove the ones we can't
7100 * set, or fill them with some default data.
7103 /* ~5 Mb/s real (802.11b) */
7104 range->throughput = 5 * 1000 * 1000;
7106 // range->sensitivity; /* signal level threshold range */
7108 range->max_qual.qual = 100;
7109 /* TODO: Find real max RSSI and stick here */
7110 range->max_qual.level = 0;
7111 range->max_qual.noise = 0;
7112 range->max_qual.updated = 7; /* Updated all three */
7114 range->avg_qual.qual = 70; /* > 8% missed beacons is 'bad' */
7115 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
7116 range->avg_qual.level = 20 + IPW2100_RSSI_TO_DBM;
7117 range->avg_qual.noise = 0;
7118 range->avg_qual.updated = 7; /* Updated all three */
7120 range->num_bitrates = RATE_COUNT;
7122 for (i = 0; i < RATE_COUNT && i < IW_MAX_BITRATES; i++) {
7123 range->bitrate[i] = ipw2100_rates_11b[i];
7126 range->min_rts = MIN_RTS_THRESHOLD;
7127 range->max_rts = MAX_RTS_THRESHOLD;
7128 range->min_frag = MIN_FRAG_THRESHOLD;
7129 range->max_frag = MAX_FRAG_THRESHOLD;
7131 range->min_pmp = period_duration[0]; /* Minimal PM period */
7132 range->max_pmp = period_duration[POWER_MODES-1];/* Maximal PM period */
7133 range->min_pmt = timeout_duration[POWER_MODES-1]; /* Minimal PM timeout */
7134 range->max_pmt = timeout_duration[0];/* Maximal PM timeout */
7136 /* How to decode max/min PM period */
7137 range->pmp_flags = IW_POWER_PERIOD;
7138 /* How to decode max/min PM period */
7139 range->pmt_flags = IW_POWER_TIMEOUT;
7140 /* What PM options are supported */
7141 range->pm_capa = IW_POWER_TIMEOUT | IW_POWER_PERIOD;
7143 range->encoding_size[0] = 5;
7144 range->encoding_size[1] = 13; /* Different token sizes */
7145 range->num_encoding_sizes = 2; /* Number of entry in the list */
7146 range->max_encoding_tokens = WEP_KEYS; /* Max number of tokens */
7147 // range->encoding_login_index; /* token index for login token */
7149 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7150 range->txpower_capa = IW_TXPOW_DBM;
7151 range->num_txpower = IW_MAX_TXPOWER;
7152 for (i = 0, level = (IPW_TX_POWER_MAX_DBM * 16); i < IW_MAX_TXPOWER;
7153 i++, level -= ((IPW_TX_POWER_MAX_DBM - IPW_TX_POWER_MIN_DBM) * 16) /
7154 (IW_MAX_TXPOWER - 1))
7155 range->txpower[i] = level / 16;
7157 range->txpower_capa = 0;
7158 range->num_txpower = 0;
7162 /* Set the Wireless Extension versions */
7163 range->we_version_compiled = WIRELESS_EXT;
7164 range->we_version_source = 16;
7166 // range->retry_capa; /* What retry options are supported */
7167 // range->retry_flags; /* How to decode max/min retry limit */
7168 // range->r_time_flags; /* How to decode max/min retry life */
7169 // range->min_retry; /* Minimal number of retries */
7170 // range->max_retry; /* Maximal number of retries */
7171 // range->min_r_time; /* Minimal retry lifetime */
7172 // range->max_r_time; /* Maximal retry lifetime */
7174 range->num_channels = FREQ_COUNT;
7177 for (i = 0; i < FREQ_COUNT; i++) {
7178 // TODO: Include only legal frequencies for some countries
7179 // if (local->channel_mask & (1 << i)) {
7180 range->freq[val].i = i + 1;
7181 range->freq[val].m = ipw2100_frequencies[i] * 100000;
7182 range->freq[val].e = 1;
7185 if (val == IW_MAX_FREQUENCIES)
7188 range->num_frequency = val;
7190 IPW_DEBUG_WX("GET Range\n");
7195 static int ipw2100_wx_set_wap(struct net_device *dev,
7196 struct iw_request_info *info,
7197 union iwreq_data *wrqu, char *extra)
7199 struct ipw2100_priv *priv = ieee80211_priv(dev);
7202 static const unsigned char any[] = {
7203 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
7205 static const unsigned char off[] = {
7206 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
7210 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
7213 down(&priv->action_sem);
7214 if (!(priv->status & STATUS_INITIALIZED)) {
7219 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
7220 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
7221 /* we disable mandatory BSSID association */
7222 IPW_DEBUG_WX("exit - disable mandatory BSSID\n");
7223 priv->config &= ~CFG_STATIC_BSSID;
7224 err = ipw2100_set_mandatory_bssid(priv, NULL, 0);
7228 priv->config |= CFG_STATIC_BSSID;
7229 memcpy(priv->mandatory_bssid_mac, wrqu->ap_addr.sa_data, ETH_ALEN);
7231 err = ipw2100_set_mandatory_bssid(priv, wrqu->ap_addr.sa_data, 0);
7233 IPW_DEBUG_WX("SET BSSID -> %02X:%02X:%02X:%02X:%02X:%02X\n",
7234 wrqu->ap_addr.sa_data[0] & 0xff,
7235 wrqu->ap_addr.sa_data[1] & 0xff,
7236 wrqu->ap_addr.sa_data[2] & 0xff,
7237 wrqu->ap_addr.sa_data[3] & 0xff,
7238 wrqu->ap_addr.sa_data[4] & 0xff,
7239 wrqu->ap_addr.sa_data[5] & 0xff);
7242 up(&priv->action_sem);
7246 static int ipw2100_wx_get_wap(struct net_device *dev,
7247 struct iw_request_info *info,
7248 union iwreq_data *wrqu, char *extra)
7251 * This can be called at any time. No action lock required
7254 struct ipw2100_priv *priv = ieee80211_priv(dev);
7256 /* If we are associated, trying to associate, or have a statically
7257 * configured BSSID then return that; otherwise return ANY */
7258 if (priv->config & CFG_STATIC_BSSID ||
7259 priv->status & STATUS_ASSOCIATED) {
7260 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
7261 memcpy(wrqu->ap_addr.sa_data, &priv->bssid, ETH_ALEN);
7263 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
7265 IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n",
7266 MAC_ARG(wrqu->ap_addr.sa_data));
7270 static int ipw2100_wx_set_essid(struct net_device *dev,
7271 struct iw_request_info *info,
7272 union iwreq_data *wrqu, char *extra)
7274 struct ipw2100_priv *priv = ieee80211_priv(dev);
7275 char *essid = ""; /* ANY */
7279 down(&priv->action_sem);
7280 if (!(priv->status & STATUS_INITIALIZED)) {
7285 if (wrqu->essid.flags && wrqu->essid.length) {
7286 length = wrqu->essid.length - 1;
7291 IPW_DEBUG_WX("Setting ESSID to ANY\n");
7292 priv->config &= ~CFG_STATIC_ESSID;
7293 err = ipw2100_set_essid(priv, NULL, 0, 0);
7297 length = min(length, IW_ESSID_MAX_SIZE);
7299 priv->config |= CFG_STATIC_ESSID;
7301 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
7302 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
7307 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length),
7310 priv->essid_len = length;
7311 memcpy(priv->essid, essid, priv->essid_len);
7313 err = ipw2100_set_essid(priv, essid, length, 0);
7316 up(&priv->action_sem);
7320 static int ipw2100_wx_get_essid(struct net_device *dev,
7321 struct iw_request_info *info,
7322 union iwreq_data *wrqu, char *extra)
7325 * This can be called at any time. No action lock required
7328 struct ipw2100_priv *priv = ieee80211_priv(dev);
7330 /* If we are associated, trying to associate, or have a statically
7331 * configured ESSID then return that; otherwise return ANY */
7332 if (priv->config & CFG_STATIC_ESSID ||
7333 priv->status & STATUS_ASSOCIATED) {
7334 IPW_DEBUG_WX("Getting essid: '%s'\n",
7335 escape_essid(priv->essid, priv->essid_len));
7336 memcpy(extra, priv->essid, priv->essid_len);
7337 wrqu->essid.length = priv->essid_len;
7338 wrqu->essid.flags = 1; /* active */
7340 IPW_DEBUG_WX("Getting essid: ANY\n");
7341 wrqu->essid.length = 0;
7342 wrqu->essid.flags = 0; /* active */
7348 static int ipw2100_wx_set_nick(struct net_device *dev,
7349 struct iw_request_info *info,
7350 union iwreq_data *wrqu, char *extra)
7353 * This can be called at any time. No action lock required
7356 struct ipw2100_priv *priv = ieee80211_priv(dev);
7358 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
7361 wrqu->data.length = min((size_t)wrqu->data.length, sizeof(priv->nick));
7362 memset(priv->nick, 0, sizeof(priv->nick));
7363 memcpy(priv->nick, extra, wrqu->data.length);
7365 IPW_DEBUG_WX("SET Nickname -> %s \n", priv->nick);
7370 static int ipw2100_wx_get_nick(struct net_device *dev,
7371 struct iw_request_info *info,
7372 union iwreq_data *wrqu, char *extra)
7375 * This can be called at any time. No action lock required
7378 struct ipw2100_priv *priv = ieee80211_priv(dev);
7380 wrqu->data.length = strlen(priv->nick) + 1;
7381 memcpy(extra, priv->nick, wrqu->data.length);
7382 wrqu->data.flags = 1; /* active */
7384 IPW_DEBUG_WX("GET Nickname -> %s \n", extra);
7389 static int ipw2100_wx_set_rate(struct net_device *dev,
7390 struct iw_request_info *info,
7391 union iwreq_data *wrqu, char *extra)
7393 struct ipw2100_priv *priv = ieee80211_priv(dev);
7394 u32 target_rate = wrqu->bitrate.value;
7398 down(&priv->action_sem);
7399 if (!(priv->status & STATUS_INITIALIZED)) {
7406 if (target_rate == 1000000 ||
7407 (!wrqu->bitrate.fixed && target_rate > 1000000))
7408 rate |= TX_RATE_1_MBIT;
7409 if (target_rate == 2000000 ||
7410 (!wrqu->bitrate.fixed && target_rate > 2000000))
7411 rate |= TX_RATE_2_MBIT;
7412 if (target_rate == 5500000 ||
7413 (!wrqu->bitrate.fixed && target_rate > 5500000))
7414 rate |= TX_RATE_5_5_MBIT;
7415 if (target_rate == 11000000 ||
7416 (!wrqu->bitrate.fixed && target_rate > 11000000))
7417 rate |= TX_RATE_11_MBIT;
7419 rate = DEFAULT_TX_RATES;
7421 err = ipw2100_set_tx_rates(priv, rate, 0);
7423 IPW_DEBUG_WX("SET Rate -> %04X \n", rate);
7425 up(&priv->action_sem);
7430 static int ipw2100_wx_get_rate(struct net_device *dev,
7431 struct iw_request_info *info,
7432 union iwreq_data *wrqu, char *extra)
7434 struct ipw2100_priv *priv = ieee80211_priv(dev);
7436 int len = sizeof(val);
7439 if (!(priv->status & STATUS_ENABLED) ||
7440 priv->status & STATUS_RF_KILL_MASK ||
7441 !(priv->status & STATUS_ASSOCIATED)) {
7442 wrqu->bitrate.value = 0;
7446 down(&priv->action_sem);
7447 if (!(priv->status & STATUS_INITIALIZED)) {
7452 err = ipw2100_get_ordinal(priv, IPW_ORD_CURRENT_TX_RATE, &val, &len);
7454 IPW_DEBUG_WX("failed querying ordinals.\n");
7458 switch (val & TX_RATE_MASK) {
7459 case TX_RATE_1_MBIT:
7460 wrqu->bitrate.value = 1000000;
7462 case TX_RATE_2_MBIT:
7463 wrqu->bitrate.value = 2000000;
7465 case TX_RATE_5_5_MBIT:
7466 wrqu->bitrate.value = 5500000;
7468 case TX_RATE_11_MBIT:
7469 wrqu->bitrate.value = 11000000;
7472 wrqu->bitrate.value = 0;
7475 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
7478 up(&priv->action_sem);
7482 static int ipw2100_wx_set_rts(struct net_device *dev,
7483 struct iw_request_info *info,
7484 union iwreq_data *wrqu, char *extra)
7486 struct ipw2100_priv *priv = ieee80211_priv(dev);
7489 /* Auto RTS not yet supported */
7490 if (wrqu->rts.fixed == 0)
7493 down(&priv->action_sem);
7494 if (!(priv->status & STATUS_INITIALIZED)) {
7499 if (wrqu->rts.disabled)
7500 value = priv->rts_threshold | RTS_DISABLED;
7502 if (wrqu->rts.value < 1 ||
7503 wrqu->rts.value > 2304) {
7507 value = wrqu->rts.value;
7510 err = ipw2100_set_rts_threshold(priv, value);
7512 IPW_DEBUG_WX("SET RTS Threshold -> 0x%08X \n", value);
7514 up(&priv->action_sem);
7518 static int ipw2100_wx_get_rts(struct net_device *dev,
7519 struct iw_request_info *info,
7520 union iwreq_data *wrqu, char *extra)
7523 * This can be called at any time. No action lock required
7526 struct ipw2100_priv *priv = ieee80211_priv(dev);
7528 wrqu->rts.value = priv->rts_threshold & ~RTS_DISABLED;
7529 wrqu->rts.fixed = 1; /* no auto select */
7531 /* If RTS is set to the default value, then it is disabled */
7532 wrqu->rts.disabled = (priv->rts_threshold & RTS_DISABLED) ? 1 : 0;
7534 IPW_DEBUG_WX("GET RTS Threshold -> 0x%08X \n", wrqu->rts.value);
7539 static int ipw2100_wx_set_txpow(struct net_device *dev,
7540 struct iw_request_info *info,
7541 union iwreq_data *wrqu, char *extra)
7543 struct ipw2100_priv *priv = ieee80211_priv(dev);
7546 if (priv->ieee->iw_mode != IW_MODE_ADHOC)
7549 if (wrqu->txpower.disabled == 1 || wrqu->txpower.fixed == 0)
7550 value = IPW_TX_POWER_DEFAULT;
7552 if (wrqu->txpower.value < IPW_TX_POWER_MIN_DBM ||
7553 wrqu->txpower.value > IPW_TX_POWER_MAX_DBM)
7556 value = (wrqu->txpower.value - IPW_TX_POWER_MIN_DBM) * 16 /
7557 (IPW_TX_POWER_MAX_DBM - IPW_TX_POWER_MIN_DBM);
7560 down(&priv->action_sem);
7561 if (!(priv->status & STATUS_INITIALIZED)) {
7566 err = ipw2100_set_tx_power(priv, value);
7568 IPW_DEBUG_WX("SET TX Power -> %d \n", value);
7571 up(&priv->action_sem);
7575 static int ipw2100_wx_get_txpow(struct net_device *dev,
7576 struct iw_request_info *info,
7577 union iwreq_data *wrqu, char *extra)
7580 * This can be called at any time. No action lock required
7583 struct ipw2100_priv *priv = ieee80211_priv(dev);
7585 if (priv->ieee->iw_mode != IW_MODE_ADHOC) {
7586 wrqu->power.disabled = 1;
7590 if (priv->tx_power == IPW_TX_POWER_DEFAULT) {
7591 wrqu->power.fixed = 0;
7592 wrqu->power.value = IPW_TX_POWER_MAX_DBM;
7593 wrqu->power.disabled = 1;
7595 wrqu->power.disabled = 0;
7596 wrqu->power.fixed = 1;
7599 (IPW_TX_POWER_MAX_DBM - IPW_TX_POWER_MIN_DBM)) /
7600 (IPW_TX_POWER_MAX - IPW_TX_POWER_MIN) +
7601 IPW_TX_POWER_MIN_DBM;
7604 wrqu->power.flags = IW_TXPOW_DBM;
7606 IPW_DEBUG_WX("GET TX Power -> %d \n", wrqu->power.value);
7611 static int ipw2100_wx_set_frag(struct net_device *dev,
7612 struct iw_request_info *info,
7613 union iwreq_data *wrqu, char *extra)
7616 * This can be called at any time. No action lock required
7619 struct ipw2100_priv *priv = ieee80211_priv(dev);
7621 if (!wrqu->frag.fixed)
7624 if (wrqu->frag.disabled) {
7625 priv->frag_threshold |= FRAG_DISABLED;
7626 priv->ieee->fts = DEFAULT_FTS;
7628 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
7629 wrqu->frag.value > MAX_FRAG_THRESHOLD)
7632 priv->ieee->fts = wrqu->frag.value & ~0x1;
7633 priv->frag_threshold = priv->ieee->fts;
7636 IPW_DEBUG_WX("SET Frag Threshold -> %d \n", priv->ieee->fts);
7641 static int ipw2100_wx_get_frag(struct net_device *dev,
7642 struct iw_request_info *info,
7643 union iwreq_data *wrqu, char *extra)
7646 * This can be called at any time. No action lock required
7649 struct ipw2100_priv *priv = ieee80211_priv(dev);
7650 wrqu->frag.value = priv->frag_threshold & ~FRAG_DISABLED;
7651 wrqu->frag.fixed = 0; /* no auto select */
7652 wrqu->frag.disabled = (priv->frag_threshold & FRAG_DISABLED) ? 1 : 0;
7654 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
7659 static int ipw2100_wx_set_retry(struct net_device *dev,
7660 struct iw_request_info *info,
7661 union iwreq_data *wrqu, char *extra)
7663 struct ipw2100_priv *priv = ieee80211_priv(dev);
7666 if (wrqu->retry.flags & IW_RETRY_LIFETIME ||
7667 wrqu->retry.disabled)
7670 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
7673 down(&priv->action_sem);
7674 if (!(priv->status & STATUS_INITIALIZED)) {
7679 if (wrqu->retry.flags & IW_RETRY_MIN) {
7680 err = ipw2100_set_short_retry(priv, wrqu->retry.value);
7681 IPW_DEBUG_WX("SET Short Retry Limit -> %d \n",
7686 if (wrqu->retry.flags & IW_RETRY_MAX) {
7687 err = ipw2100_set_long_retry(priv, wrqu->retry.value);
7688 IPW_DEBUG_WX("SET Long Retry Limit -> %d \n",
7693 err = ipw2100_set_short_retry(priv, wrqu->retry.value);
7695 err = ipw2100_set_long_retry(priv, wrqu->retry.value);
7697 IPW_DEBUG_WX("SET Both Retry Limits -> %d \n", wrqu->retry.value);
7700 up(&priv->action_sem);
7704 static int ipw2100_wx_get_retry(struct net_device *dev,
7705 struct iw_request_info *info,
7706 union iwreq_data *wrqu, char *extra)
7709 * This can be called at any time. No action lock required
7712 struct ipw2100_priv *priv = ieee80211_priv(dev);
7714 wrqu->retry.disabled = 0; /* can't be disabled */
7716 if ((wrqu->retry.flags & IW_RETRY_TYPE) ==
7720 if (wrqu->retry.flags & IW_RETRY_MAX) {
7721 wrqu->retry.flags = IW_RETRY_LIMIT & IW_RETRY_MAX;
7722 wrqu->retry.value = priv->long_retry_limit;
7725 (priv->short_retry_limit !=
7726 priv->long_retry_limit) ?
7727 IW_RETRY_LIMIT & IW_RETRY_MIN : IW_RETRY_LIMIT;
7729 wrqu->retry.value = priv->short_retry_limit;
7732 IPW_DEBUG_WX("GET Retry -> %d \n", wrqu->retry.value);
7737 static int ipw2100_wx_set_scan(struct net_device *dev,
7738 struct iw_request_info *info,
7739 union iwreq_data *wrqu, char *extra)
7741 struct ipw2100_priv *priv = ieee80211_priv(dev);
7744 down(&priv->action_sem);
7745 if (!(priv->status & STATUS_INITIALIZED)) {
7750 IPW_DEBUG_WX("Initiating scan...\n");
7751 if (ipw2100_set_scan_options(priv) ||
7752 ipw2100_start_scan(priv)) {
7753 IPW_DEBUG_WX("Start scan failed.\n");
7755 /* TODO: Mark a scan as pending so when hardware initialized
7760 up(&priv->action_sem);
7764 static int ipw2100_wx_get_scan(struct net_device *dev,
7765 struct iw_request_info *info,
7766 union iwreq_data *wrqu, char *extra)
7769 * This can be called at any time. No action lock required
7772 struct ipw2100_priv *priv = ieee80211_priv(dev);
7773 return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra);
7778 * Implementation based on code in hostap-driver v0.1.3 hostap_ioctl.c
7780 static int ipw2100_wx_set_encode(struct net_device *dev,
7781 struct iw_request_info *info,
7782 union iwreq_data *wrqu, char *key)
7785 * No check of STATUS_INITIALIZED required
7788 struct ipw2100_priv *priv = ieee80211_priv(dev);
7789 return ieee80211_wx_set_encode(priv->ieee, info, wrqu, key);
7792 static int ipw2100_wx_get_encode(struct net_device *dev,
7793 struct iw_request_info *info,
7794 union iwreq_data *wrqu, char *key)
7797 * This can be called at any time. No action lock required
7800 struct ipw2100_priv *priv = ieee80211_priv(dev);
7801 return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key);
7804 static int ipw2100_wx_set_power(struct net_device *dev,
7805 struct iw_request_info *info,
7806 union iwreq_data *wrqu, char *extra)
7808 struct ipw2100_priv *priv = ieee80211_priv(dev);
7811 down(&priv->action_sem);
7812 if (!(priv->status & STATUS_INITIALIZED)) {
7817 if (wrqu->power.disabled) {
7818 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
7819 err = ipw2100_set_power_mode(priv, IPW_POWER_MODE_CAM);
7820 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
7824 switch (wrqu->power.flags & IW_POWER_MODE) {
7825 case IW_POWER_ON: /* If not specified */
7826 case IW_POWER_MODE: /* If set all mask */
7827 case IW_POWER_ALL_R: /* If explicitely state all */
7829 default: /* Otherwise we don't support it */
7830 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
7836 /* If the user hasn't specified a power management mode yet, default
7838 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
7839 err = ipw2100_set_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
7841 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n",
7845 up(&priv->action_sem);
7850 static int ipw2100_wx_get_power(struct net_device *dev,
7851 struct iw_request_info *info,
7852 union iwreq_data *wrqu, char *extra)
7855 * This can be called at any time. No action lock required
7858 struct ipw2100_priv *priv = ieee80211_priv(dev);
7860 if (!(priv->power_mode & IPW_POWER_ENABLED)) {
7861 wrqu->power.disabled = 1;
7863 wrqu->power.disabled = 0;
7864 wrqu->power.flags = 0;
7867 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
7878 #ifdef CONFIG_IPW2100_MONITOR
7879 static int ipw2100_wx_set_promisc(struct net_device *dev,
7880 struct iw_request_info *info,
7881 union iwreq_data *wrqu, char *extra)
7883 struct ipw2100_priv *priv = ieee80211_priv(dev);
7884 int *parms = (int *)extra;
7885 int enable = (parms[0] > 0);
7888 down(&priv->action_sem);
7889 if (!(priv->status & STATUS_INITIALIZED)) {
7895 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7896 err = ipw2100_set_channel(priv, parms[1], 0);
7899 priv->channel = parms[1];
7900 err = ipw2100_switch_mode(priv, IW_MODE_MONITOR);
7902 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
7903 err = ipw2100_switch_mode(priv, priv->last_mode);
7906 up(&priv->action_sem);
7910 static int ipw2100_wx_reset(struct net_device *dev,
7911 struct iw_request_info *info,
7912 union iwreq_data *wrqu, char *extra)
7914 struct ipw2100_priv *priv = ieee80211_priv(dev);
7915 if (priv->status & STATUS_INITIALIZED)
7916 schedule_reset(priv);
7922 static int ipw2100_wx_set_powermode(struct net_device *dev,
7923 struct iw_request_info *info,
7924 union iwreq_data *wrqu, char *extra)
7926 struct ipw2100_priv *priv = ieee80211_priv(dev);
7927 int err = 0, mode = *(int *)extra;
7929 down(&priv->action_sem);
7930 if (!(priv->status & STATUS_INITIALIZED)) {
7935 if ((mode < 1) || (mode > POWER_MODES))
7936 mode = IPW_POWER_AUTO;
7938 if (priv->power_mode != mode)
7939 err = ipw2100_set_power_mode(priv, mode);
7941 up(&priv->action_sem);
7945 #define MAX_POWER_STRING 80
7946 static int ipw2100_wx_get_powermode(struct net_device *dev,
7947 struct iw_request_info *info,
7948 union iwreq_data *wrqu, char *extra)
7951 * This can be called at any time. No action lock required
7954 struct ipw2100_priv *priv = ieee80211_priv(dev);
7955 int level = IPW_POWER_LEVEL(priv->power_mode);
7956 s32 timeout, period;
7958 if (!(priv->power_mode & IPW_POWER_ENABLED)) {
7959 snprintf(extra, MAX_POWER_STRING,
7960 "Power save level: %d (Off)", level);
7963 case IPW_POWER_MODE_CAM:
7964 snprintf(extra, MAX_POWER_STRING,
7965 "Power save level: %d (None)", level);
7967 case IPW_POWER_AUTO:
7968 snprintf(extra, MAX_POWER_STRING,
7969 "Power save level: %d (Auto)", 0);
7972 timeout = timeout_duration[level - 1] / 1000;
7973 period = period_duration[level - 1] / 1000;
7974 snprintf(extra, MAX_POWER_STRING,
7975 "Power save level: %d "
7976 "(Timeout %dms, Period %dms)",
7977 level, timeout, period);
7981 wrqu->data.length = strlen(extra) + 1;
7987 static int ipw2100_wx_set_preamble(struct net_device *dev,
7988 struct iw_request_info *info,
7989 union iwreq_data *wrqu, char *extra)
7991 struct ipw2100_priv *priv = ieee80211_priv(dev);
7992 int err, mode = *(int *)extra;
7994 down(&priv->action_sem);
7995 if (!(priv->status & STATUS_INITIALIZED)) {
8001 priv->config |= CFG_LONG_PREAMBLE;
8003 priv->config &= ~CFG_LONG_PREAMBLE;
8009 err = ipw2100_system_config(priv, 0);
8012 up(&priv->action_sem);
8016 static int ipw2100_wx_get_preamble(struct net_device *dev,
8017 struct iw_request_info *info,
8018 union iwreq_data *wrqu, char *extra)
8021 * This can be called at any time. No action lock required
8024 struct ipw2100_priv *priv = ieee80211_priv(dev);
8026 if (priv->config & CFG_LONG_PREAMBLE)
8027 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
8029 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
8034 static iw_handler ipw2100_wx_handlers[] =
8036 NULL, /* SIOCSIWCOMMIT */
8037 ipw2100_wx_get_name, /* SIOCGIWNAME */
8038 NULL, /* SIOCSIWNWID */
8039 NULL, /* SIOCGIWNWID */
8040 ipw2100_wx_set_freq, /* SIOCSIWFREQ */
8041 ipw2100_wx_get_freq, /* SIOCGIWFREQ */
8042 ipw2100_wx_set_mode, /* SIOCSIWMODE */
8043 ipw2100_wx_get_mode, /* SIOCGIWMODE */
8044 NULL, /* SIOCSIWSENS */
8045 NULL, /* SIOCGIWSENS */
8046 NULL, /* SIOCSIWRANGE */
8047 ipw2100_wx_get_range, /* SIOCGIWRANGE */
8048 NULL, /* SIOCSIWPRIV */
8049 NULL, /* SIOCGIWPRIV */
8050 NULL, /* SIOCSIWSTATS */
8051 NULL, /* SIOCGIWSTATS */
8052 NULL, /* SIOCSIWSPY */
8053 NULL, /* SIOCGIWSPY */
8054 NULL, /* SIOCGIWTHRSPY */
8055 NULL, /* SIOCWIWTHRSPY */
8056 ipw2100_wx_set_wap, /* SIOCSIWAP */
8057 ipw2100_wx_get_wap, /* SIOCGIWAP */
8058 NULL, /* -- hole -- */
8059 NULL, /* SIOCGIWAPLIST -- depricated */
8060 ipw2100_wx_set_scan, /* SIOCSIWSCAN */
8061 ipw2100_wx_get_scan, /* SIOCGIWSCAN */
8062 ipw2100_wx_set_essid, /* SIOCSIWESSID */
8063 ipw2100_wx_get_essid, /* SIOCGIWESSID */
8064 ipw2100_wx_set_nick, /* SIOCSIWNICKN */
8065 ipw2100_wx_get_nick, /* SIOCGIWNICKN */
8066 NULL, /* -- hole -- */
8067 NULL, /* -- hole -- */
8068 ipw2100_wx_set_rate, /* SIOCSIWRATE */
8069 ipw2100_wx_get_rate, /* SIOCGIWRATE */
8070 ipw2100_wx_set_rts, /* SIOCSIWRTS */
8071 ipw2100_wx_get_rts, /* SIOCGIWRTS */
8072 ipw2100_wx_set_frag, /* SIOCSIWFRAG */
8073 ipw2100_wx_get_frag, /* SIOCGIWFRAG */
8074 ipw2100_wx_set_txpow, /* SIOCSIWTXPOW */
8075 ipw2100_wx_get_txpow, /* SIOCGIWTXPOW */
8076 ipw2100_wx_set_retry, /* SIOCSIWRETRY */
8077 ipw2100_wx_get_retry, /* SIOCGIWRETRY */
8078 ipw2100_wx_set_encode, /* SIOCSIWENCODE */
8079 ipw2100_wx_get_encode, /* SIOCGIWENCODE */
8080 ipw2100_wx_set_power, /* SIOCSIWPOWER */
8081 ipw2100_wx_get_power, /* SIOCGIWPOWER */
8084 #define IPW2100_PRIV_SET_MONITOR SIOCIWFIRSTPRIV
8085 #define IPW2100_PRIV_RESET SIOCIWFIRSTPRIV+1
8086 #define IPW2100_PRIV_SET_POWER SIOCIWFIRSTPRIV+2
8087 #define IPW2100_PRIV_GET_POWER SIOCIWFIRSTPRIV+3
8088 #define IPW2100_PRIV_SET_LONGPREAMBLE SIOCIWFIRSTPRIV+4
8089 #define IPW2100_PRIV_GET_LONGPREAMBLE SIOCIWFIRSTPRIV+5
8091 static const struct iw_priv_args ipw2100_private_args[] = {
8093 #ifdef CONFIG_IPW2100_MONITOR
8095 IPW2100_PRIV_SET_MONITOR,
8096 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"
8100 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"
8102 #endif /* CONFIG_IPW2100_MONITOR */
8105 IPW2100_PRIV_SET_POWER,
8106 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_power"
8109 IPW2100_PRIV_GET_POWER,
8110 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_POWER_STRING, "get_power"
8113 IPW2100_PRIV_SET_LONGPREAMBLE,
8114 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_preamble"
8117 IPW2100_PRIV_GET_LONGPREAMBLE,
8118 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, "get_preamble"
8122 static iw_handler ipw2100_private_handler[] = {
8123 #ifdef CONFIG_IPW2100_MONITOR
8124 ipw2100_wx_set_promisc,
8126 #else /* CONFIG_IPW2100_MONITOR */
8129 #endif /* CONFIG_IPW2100_MONITOR */
8130 ipw2100_wx_set_powermode,
8131 ipw2100_wx_get_powermode,
8132 ipw2100_wx_set_preamble,
8133 ipw2100_wx_get_preamble,
8136 struct iw_handler_def ipw2100_wx_handler_def =
8138 .standard = ipw2100_wx_handlers,
8139 .num_standard = sizeof(ipw2100_wx_handlers) / sizeof(iw_handler),
8140 .num_private = sizeof(ipw2100_private_handler) / sizeof(iw_handler),
8141 .num_private_args = sizeof(ipw2100_private_args) /
8142 sizeof(struct iw_priv_args),
8143 .private = (iw_handler *)ipw2100_private_handler,
8144 .private_args = (struct iw_priv_args *)ipw2100_private_args,
8148 * Get wireless statistics.
8149 * Called by /proc/net/wireless
8150 * Also called by SIOCGIWSTATS
8152 struct iw_statistics *ipw2100_wx_wireless_stats(struct net_device * dev)
8166 struct ipw2100_priv *priv = ieee80211_priv(dev);
8167 struct iw_statistics *wstats;
8168 u32 rssi, quality, tx_retries, missed_beacons, tx_failures;
8169 u32 ord_len = sizeof(u32);
8172 return (struct iw_statistics *) NULL;
8174 wstats = &priv->wstats;
8176 /* if hw is disabled, then ipw2100_get_ordinal() can't be called.
8177 * ipw2100_wx_wireless_stats seems to be called before fw is
8178 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
8179 * and associated; if not associcated, the values are all meaningless
8180 * anyway, so set them all to NULL and INVALID */
8181 if (!(priv->status & STATUS_ASSOCIATED)) {
8182 wstats->miss.beacon = 0;
8183 wstats->discard.retries = 0;
8184 wstats->qual.qual = 0;
8185 wstats->qual.level = 0;
8186 wstats->qual.noise = 0;
8187 wstats->qual.updated = 7;
8188 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
8189 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
8193 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_PERCENT_MISSED_BCNS,
8194 &missed_beacons, &ord_len))
8195 goto fail_get_ordinal;
8197 /* If we don't have a connection the quality and level is 0*/
8198 if (!(priv->status & STATUS_ASSOCIATED)) {
8199 wstats->qual.qual = 0;
8200 wstats->qual.level = 0;
8202 if (ipw2100_get_ordinal(priv, IPW_ORD_RSSI_AVG_CURR,
8204 goto fail_get_ordinal;
8205 wstats->qual.level = rssi + IPW2100_RSSI_TO_DBM;
8207 rssi_qual = rssi * POOR / 10;
8209 rssi_qual = (rssi - 10) * (FAIR - POOR) / 5 + POOR;
8211 rssi_qual = (rssi - 15) * (GOOD - FAIR) / 5 + FAIR;
8213 rssi_qual = (rssi - 20) * (VERY_GOOD - GOOD) /
8216 rssi_qual = (rssi - 30) * (PERFECT - VERY_GOOD) /
8219 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_PERCENT_RETRIES,
8220 &tx_retries, &ord_len))
8221 goto fail_get_ordinal;
8223 if (tx_retries > 75)
8224 tx_qual = (90 - tx_retries) * POOR / 15;
8225 else if (tx_retries > 70)
8226 tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
8227 else if (tx_retries > 65)
8228 tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
8229 else if (tx_retries > 50)
8230 tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
8233 tx_qual = (50 - tx_retries) *
8234 (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
8236 if (missed_beacons > 50)
8237 beacon_qual = (60 - missed_beacons) * POOR / 10;
8238 else if (missed_beacons > 40)
8239 beacon_qual = (50 - missed_beacons) * (FAIR - POOR) /
8241 else if (missed_beacons > 32)
8242 beacon_qual = (40 - missed_beacons) * (GOOD - FAIR) /
8244 else if (missed_beacons > 20)
8245 beacon_qual = (32 - missed_beacons) *
8246 (VERY_GOOD - GOOD) / 20 + GOOD;
8248 beacon_qual = (20 - missed_beacons) *
8249 (PERFECT - VERY_GOOD) / 20 + VERY_GOOD;
8251 quality = min(beacon_qual, min(tx_qual, rssi_qual));
8253 #ifdef CONFIG_IPW_DEBUG
8254 if (beacon_qual == quality)
8255 IPW_DEBUG_WX("Quality clamped by Missed Beacons\n");
8256 else if (tx_qual == quality)
8257 IPW_DEBUG_WX("Quality clamped by Tx Retries\n");
8258 else if (quality != 100)
8259 IPW_DEBUG_WX("Quality clamped by Signal Strength\n");
8261 IPW_DEBUG_WX("Quality not clamped.\n");
8264 wstats->qual.qual = quality;
8265 wstats->qual.level = rssi + IPW2100_RSSI_TO_DBM;
8268 wstats->qual.noise = 0;
8269 wstats->qual.updated = 7;
8270 wstats->qual.updated |= IW_QUAL_NOISE_INVALID;
8272 /* FIXME: this is percent and not a # */
8273 wstats->miss.beacon = missed_beacons;
8275 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURES,
8276 &tx_failures, &ord_len))
8277 goto fail_get_ordinal;
8278 wstats->discard.retries = tx_failures;
8283 IPW_DEBUG_WX("failed querying ordinals.\n");
8285 return (struct iw_statistics *) NULL;
8288 void ipw2100_wx_event_work(struct ipw2100_priv *priv)
8290 union iwreq_data wrqu;
8293 if (priv->status & STATUS_STOPPING)
8296 down(&priv->action_sem);
8298 IPW_DEBUG_WX("enter\n");
8300 up(&priv->action_sem);
8302 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
8304 /* Fetch BSSID from the hardware */
8305 if (!(priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) ||
8306 priv->status & STATUS_RF_KILL_MASK ||
8307 ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID,
8308 &priv->bssid, &len)) {
8309 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
8311 /* We now have the BSSID, so can finish setting to the full
8312 * associated state */
8313 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
8314 memcpy(&priv->ieee->bssid, priv->bssid, ETH_ALEN);
8315 priv->status &= ~STATUS_ASSOCIATING;
8316 priv->status |= STATUS_ASSOCIATED;
8317 netif_carrier_on(priv->net_dev);
8318 if (netif_queue_stopped(priv->net_dev)) {
8319 IPW_DEBUG_INFO("Waking net queue.\n");
8320 netif_wake_queue(priv->net_dev);
8322 IPW_DEBUG_INFO("Starting net queue.\n");
8323 netif_start_queue(priv->net_dev);
8327 if (!(priv->status & STATUS_ASSOCIATED)) {
8328 IPW_DEBUG_WX("Configuring ESSID\n");
8329 down(&priv->action_sem);
8330 /* This is a disassociation event, so kick the firmware to
8331 * look for another AP */
8332 if (priv->config & CFG_STATIC_ESSID)
8333 ipw2100_set_essid(priv, priv->essid, priv->essid_len, 0);
8335 ipw2100_set_essid(priv, NULL, 0, 0);
8336 up(&priv->action_sem);
8339 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
8342 #define IPW2100_FW_MAJOR_VERSION 1
8343 #define IPW2100_FW_MINOR_VERSION 3
8345 #define IPW2100_FW_MINOR(x) ((x & 0xff) >> 8)
8346 #define IPW2100_FW_MAJOR(x) (x & 0xff)
8348 #define IPW2100_FW_VERSION ((IPW2100_FW_MINOR_VERSION << 8) | \
8349 IPW2100_FW_MAJOR_VERSION)
8351 #define IPW2100_FW_PREFIX "ipw2100-" __stringify(IPW2100_FW_MAJOR_VERSION) \
8352 "." __stringify(IPW2100_FW_MINOR_VERSION)
8354 #define IPW2100_FW_NAME(x) IPW2100_FW_PREFIX "" x ".fw"
8359 BINARY FIRMWARE HEADER FORMAT
8363 2 2 mode == 0:BSS,1:IBSS,2:MONITOR
8366 C fw_len firmware data
8367 12 + fw_len uc_len microcode data
8371 struct ipw2100_fw_header {
8374 unsigned int fw_size;
8375 unsigned int uc_size;
8376 } __attribute__ ((packed));
8380 static int ipw2100_mod_firmware_load(struct ipw2100_fw *fw)
8382 struct ipw2100_fw_header *h =
8383 (struct ipw2100_fw_header *)fw->fw_entry->data;
8385 if (IPW2100_FW_MAJOR(h->version) != IPW2100_FW_MAJOR_VERSION) {
8386 IPW_DEBUG_WARNING("Firmware image not compatible "
8387 "(detected version id of %u). "
8388 "See Documentation/networking/README.ipw2100\n",
8393 fw->version = h->version;
8394 fw->fw.data = fw->fw_entry->data + sizeof(struct ipw2100_fw_header);
8395 fw->fw.size = h->fw_size;
8396 fw->uc.data = fw->fw.data + h->fw_size;
8397 fw->uc.size = h->uc_size;
8403 int ipw2100_get_firmware(struct ipw2100_priv *priv, struct ipw2100_fw *fw)
8408 IPW_DEBUG_INFO("%s: Using hotplug firmware load.\n",
8409 priv->net_dev->name);
8411 switch (priv->ieee->iw_mode) {
8413 fw_name = IPW2100_FW_NAME("-i");
8415 #ifdef CONFIG_IPW2100_MONITOR
8416 case IW_MODE_MONITOR:
8417 fw_name = IPW2100_FW_NAME("-p");
8422 fw_name = IPW2100_FW_NAME("");
8426 rc = request_firmware(&fw->fw_entry, fw_name, &priv->pci_dev->dev);
8430 "%s: Firmware '%s' not available or load failed.\n",
8431 priv->net_dev->name, fw_name);
8434 IPW_DEBUG_INFO("firmware data %p size %d\n", fw->fw_entry->data,
8435 fw->fw_entry->size);
8437 ipw2100_mod_firmware_load(fw);
8442 void ipw2100_release_firmware(struct ipw2100_priv *priv,
8443 struct ipw2100_fw *fw)
8447 release_firmware(fw->fw_entry);
8448 fw->fw_entry = NULL;
8452 int ipw2100_get_fwversion(struct ipw2100_priv *priv, char *buf, size_t max)
8454 char ver[MAX_FW_VERSION_LEN];
8455 u32 len = MAX_FW_VERSION_LEN;
8458 /* firmware version is an ascii string (max len of 14) */
8459 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_FW_VER_NUM,
8465 for (i = 0; i < len; i++)
8471 int ipw2100_get_ucodeversion(struct ipw2100_priv *priv, char *buf, size_t max)
8474 u32 len = sizeof(ver);
8475 /* microcode version is a 32 bit integer */
8476 if (ipw2100_get_ordinal(priv, IPW_ORD_UCODE_VERSION,
8479 return snprintf(buf, max, "%08X", ver);
8483 * On exit, the firmware will have been freed from the fw list
8485 int ipw2100_fw_download(struct ipw2100_priv *priv, struct ipw2100_fw *fw)
8487 /* firmware is constructed of N contiguous entries, each entry is
8491 * 0 4 address to write to
8492 * 4 2 length of data run
8498 const unsigned char *firmware_data = fw->fw.data;
8499 unsigned int firmware_data_left = fw->fw.size;
8501 while (firmware_data_left > 0) {
8502 addr = *(u32 *)(firmware_data);
8504 firmware_data_left -= 4;
8506 len = *(u16 *)(firmware_data);
8508 firmware_data_left -= 2;
8512 "Invalid firmware run-length of %d bytes\n",
8517 write_nic_memory(priv->net_dev, addr, len, firmware_data);
8518 firmware_data += len;
8519 firmware_data_left -= len;
8525 struct symbol_alive_response {
8534 u16 clock_settle_time; // 1us LSB
8535 u16 powerup_settle_time; // 1us LSB
8536 u16 hop_settle_time; // 1us LSB
8537 u8 date[3]; // month, day, year
8538 u8 time[2]; // hours, minutes
8542 int ipw2100_ucode_download(struct ipw2100_priv *priv, struct ipw2100_fw *fw)
8544 struct net_device *dev = priv->net_dev;
8545 const unsigned char *microcode_data = fw->uc.data;
8546 unsigned int microcode_data_left = fw->uc.size;
8548 struct symbol_alive_response response;
8552 /* Symbol control */
8553 write_nic_word(dev, IPW2100_CONTROL_REG, 0x703);
8554 readl((void *)(dev->base_addr));
8555 write_nic_word(dev, IPW2100_CONTROL_REG, 0x707);
8556 readl((void *)(dev->base_addr));
8559 write_nic_byte(dev, 0x210014, 0x72); /* fifo width =16 */
8560 readl((void *)(dev->base_addr));
8561 write_nic_byte(dev, 0x210014, 0x72); /* fifo width =16 */
8562 readl((void *)(dev->base_addr));
8564 /* EN_CS_ACCESS bit to reset control store pointer */
8565 write_nic_byte(dev, 0x210000, 0x40);
8566 readl((void *)(dev->base_addr));
8567 write_nic_byte(dev, 0x210000, 0x0);
8568 readl((void *)(dev->base_addr));
8569 write_nic_byte(dev, 0x210000, 0x40);
8570 readl((void *)(dev->base_addr));
8572 /* copy microcode from buffer into Symbol */
8574 while (microcode_data_left > 0) {
8575 write_nic_byte(dev, 0x210010, *microcode_data++);
8576 write_nic_byte(dev, 0x210010, *microcode_data++);
8577 microcode_data_left -= 2;
8580 /* EN_CS_ACCESS bit to reset the control store pointer */
8581 write_nic_byte(dev, 0x210000, 0x0);
8582 readl((void *)(dev->base_addr));
8584 /* Enable System (Reg 0)
8585 * first enable causes garbage in RX FIFO */
8586 write_nic_byte(dev, 0x210000, 0x0);
8587 readl((void *)(dev->base_addr));
8588 write_nic_byte(dev, 0x210000, 0x80);
8589 readl((void *)(dev->base_addr));
8591 /* Reset External Baseband Reg */
8592 write_nic_word(dev, IPW2100_CONTROL_REG, 0x703);
8593 readl((void *)(dev->base_addr));
8594 write_nic_word(dev, IPW2100_CONTROL_REG, 0x707);
8595 readl((void *)(dev->base_addr));
8597 /* HW Config (Reg 5) */
8598 write_nic_byte(dev, 0x210014, 0x72); // fifo width =16
8599 readl((void *)(dev->base_addr));
8600 write_nic_byte(dev, 0x210014, 0x72); // fifo width =16
8601 readl((void *)(dev->base_addr));
8603 /* Enable System (Reg 0)
8604 * second enable should be OK */
8605 write_nic_byte(dev, 0x210000, 0x00); // clear enable system
8606 readl((void *)(dev->base_addr));
8607 write_nic_byte(dev, 0x210000, 0x80); // set enable system
8609 /* check Symbol is enabled - upped this from 5 as it wasn't always
8610 * catching the update */
8611 for (i = 0; i < 10; i++) {
8614 /* check Dino is enabled bit */
8615 read_nic_byte(dev, 0x210000, &data);
8621 IPW_DEBUG_ERROR("%s: Error initializing Symbol\n",
8626 /* Get Symbol alive response */
8627 for (i = 0; i < 30; i++) {
8628 /* Read alive response structure */
8630 j < (sizeof(struct symbol_alive_response) >> 1);
8632 read_nic_word(dev, 0x210004,
8633 ((u16 *)&response) + j);
8635 if ((response.cmd_id == 1) &&
8636 (response.ucode_valid == 0x1))
8642 IPW_DEBUG_ERROR("%s: No response from Symbol - hw not alive\n",
8644 printk_buf(IPW_DL_ERROR, (u8*)&response, sizeof(response));