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 %zd\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 /* set D0 standby bit */
919 read_register(priv->net_dev, IPW_REG_GP_CNTRL, &r);
920 write_register(priv->net_dev, IPW_REG_GP_CNTRL,
921 r | IPW_AUX_HOST_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
926 /*********************************************************************
927 Procedure : ipw2100_ipw2100_download_firmware
928 Purpose : Initiaze adapter after power on.
930 1. assert s/w reset first!
931 2. awake clocks & wait for clock stabilization
932 3. hold ARC (don't ask me why...)
933 4. load Dino ucode and reset/clock init again
934 5. zero-out shared mem
936 *******************************************************************/
937 static int ipw2100_download_firmware(struct ipw2100_priv *priv)
943 /* Fetch the firmware and microcode */
944 struct ipw2100_fw ipw2100_firmware;
947 if (priv->fatal_error) {
948 IPW_DEBUG_ERROR("%s: ipw2100_download_firmware called after "
949 "fatal error %d. Interface must be brought down.\n",
950 priv->net_dev->name, priv->fatal_error);
955 if (!ipw2100_firmware.version) {
956 err = ipw2100_get_firmware(priv, &ipw2100_firmware);
958 IPW_DEBUG_ERROR("%s: ipw2100_get_firmware failed: %d\n",
959 priv->net_dev->name, err);
960 priv->fatal_error = IPW2100_ERR_FW_LOAD;
965 err = ipw2100_get_firmware(priv, &ipw2100_firmware);
967 IPW_DEBUG_ERROR("%s: ipw2100_get_firmware failed: %d\n",
968 priv->net_dev->name, err);
969 priv->fatal_error = IPW2100_ERR_FW_LOAD;
973 priv->firmware_version = ipw2100_firmware.version;
975 /* s/w reset and clock stabilization */
976 err = sw_reset_and_clock(priv);
978 IPW_DEBUG_ERROR("%s: sw_reset_and_clock failed: %d\n",
979 priv->net_dev->name, err);
983 err = ipw2100_verify(priv);
985 IPW_DEBUG_ERROR("%s: ipw2100_verify failed: %d\n",
986 priv->net_dev->name, err);
991 write_nic_dword(priv->net_dev,
992 IPW_INTERNAL_REGISTER_HALT_AND_RESET,
995 /* allow ARC to run */
996 write_register(priv->net_dev, IPW_REG_RESET_REG, 0);
999 err = ipw2100_ucode_download(priv, &ipw2100_firmware);
1001 IPW_DEBUG_ERROR("%s: Error loading microcode: %d\n",
1002 priv->net_dev->name, err);
1007 write_nic_dword(priv->net_dev,
1008 IPW_INTERNAL_REGISTER_HALT_AND_RESET,
1011 /* s/w reset and clock stabilization (again!!!) */
1012 err = sw_reset_and_clock(priv);
1014 IPW_DEBUG_ERROR("%s: sw_reset_and_clock failed: %d\n",
1015 priv->net_dev->name, err);
1020 err = ipw2100_fw_download(priv, &ipw2100_firmware);
1022 IPW_DEBUG_ERROR("%s: Error loading firmware: %d\n",
1023 priv->net_dev->name, err);
1029 * When the .resume method of the driver is called, the other
1030 * part of the system, i.e. the ide driver could still stay in
1031 * the suspend stage. This prevents us from loading the firmware
1032 * from the disk. --YZ
1035 /* free any storage allocated for firmware image */
1036 ipw2100_release_firmware(priv, &ipw2100_firmware);
1039 /* zero out Domain 1 area indirectly (Si requirement) */
1040 for (address = IPW_HOST_FW_SHARED_AREA0;
1041 address < IPW_HOST_FW_SHARED_AREA0_END; address += 4)
1042 write_nic_dword(priv->net_dev, address, 0);
1043 for (address = IPW_HOST_FW_SHARED_AREA1;
1044 address < IPW_HOST_FW_SHARED_AREA1_END; address += 4)
1045 write_nic_dword(priv->net_dev, address, 0);
1046 for (address = IPW_HOST_FW_SHARED_AREA2;
1047 address < IPW_HOST_FW_SHARED_AREA2_END; address += 4)
1048 write_nic_dword(priv->net_dev, address, 0);
1049 for (address = IPW_HOST_FW_SHARED_AREA3;
1050 address < IPW_HOST_FW_SHARED_AREA3_END; address += 4)
1051 write_nic_dword(priv->net_dev, address, 0);
1052 for (address = IPW_HOST_FW_INTERRUPT_AREA;
1053 address < IPW_HOST_FW_INTERRUPT_AREA_END; address += 4)
1054 write_nic_dword(priv->net_dev, address, 0);
1059 ipw2100_release_firmware(priv, &ipw2100_firmware);
1063 static inline void ipw2100_enable_interrupts(struct ipw2100_priv *priv)
1065 if (priv->status & STATUS_INT_ENABLED)
1067 priv->status |= STATUS_INT_ENABLED;
1068 write_register(priv->net_dev, IPW_REG_INTA_MASK, IPW_INTERRUPT_MASK);
1071 static inline void ipw2100_disable_interrupts(struct ipw2100_priv *priv)
1073 if (!(priv->status & STATUS_INT_ENABLED))
1075 priv->status &= ~STATUS_INT_ENABLED;
1076 write_register(priv->net_dev, IPW_REG_INTA_MASK, 0x0);
1080 static void ipw2100_initialize_ordinals(struct ipw2100_priv *priv)
1082 struct ipw2100_ordinals *ord = &priv->ordinals;
1084 IPW_DEBUG_INFO("enter\n");
1086 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_ORDINALS_TABLE_1,
1089 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_ORDINALS_TABLE_2,
1092 read_nic_dword(priv->net_dev, ord->table1_addr, &ord->table1_size);
1093 read_nic_dword(priv->net_dev, ord->table2_addr, &ord->table2_size);
1095 ord->table2_size &= 0x0000FFFF;
1097 IPW_DEBUG_INFO("table 1 size: %d\n", ord->table1_size);
1098 IPW_DEBUG_INFO("table 2 size: %d\n", ord->table2_size);
1099 IPW_DEBUG_INFO("exit\n");
1102 static inline void ipw2100_hw_set_gpio(struct ipw2100_priv *priv)
1106 * Set GPIO 3 writable by FW; GPIO 1 writable
1107 * by driver and enable clock
1109 reg = (IPW_BIT_GPIO_GPIO3_MASK | IPW_BIT_GPIO_GPIO1_ENABLE |
1110 IPW_BIT_GPIO_LED_OFF);
1111 write_register(priv->net_dev, IPW_REG_GPIO, reg);
1114 static inline int rf_kill_active(struct ipw2100_priv *priv)
1116 #define MAX_RF_KILL_CHECKS 5
1117 #define RF_KILL_CHECK_DELAY 40
1118 #define RF_KILL_CHECK_THRESHOLD 3
1120 unsigned short value = 0;
1124 if (!(priv->hw_features & HW_FEATURE_RFKILL)) {
1125 priv->status &= ~STATUS_RF_KILL_HW;
1129 for (i = 0; i < MAX_RF_KILL_CHECKS; i++) {
1130 udelay(RF_KILL_CHECK_DELAY);
1131 read_register(priv->net_dev, IPW_REG_GPIO, ®);
1132 value = (value << 1) | ((reg & IPW_BIT_GPIO_RF_KILL) ? 0 : 1);
1136 priv->status |= STATUS_RF_KILL_HW;
1138 priv->status &= ~STATUS_RF_KILL_HW;
1140 return (value == 0);
1143 static int ipw2100_get_hw_features(struct ipw2100_priv *priv)
1149 * EEPROM_SRAM_DB_START_ADDRESS using ordinal in ordinal table 1
1152 if (ipw2100_get_ordinal(
1153 priv, IPW_ORD_EEPROM_SRAM_DB_BLOCK_START_ADDRESS,
1155 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
1160 IPW_DEBUG_INFO("EEPROM address: %08X\n", addr);
1163 * EEPROM version is the byte at offset 0xfd in firmware
1164 * We read 4 bytes, then shift out the byte we actually want */
1165 read_nic_dword(priv->net_dev, addr + 0xFC, &val);
1166 priv->eeprom_version = (val >> 24) & 0xFF;
1167 IPW_DEBUG_INFO("EEPROM version: %d\n", priv->eeprom_version);
1170 * HW RF Kill enable is bit 0 in byte at offset 0x21 in firmware
1172 * notice that the EEPROM bit is reverse polarity, i.e.
1173 * bit = 0 signifies HW RF kill switch is supported
1174 * bit = 1 signifies HW RF kill switch is NOT supported
1176 read_nic_dword(priv->net_dev, addr + 0x20, &val);
1177 if (!((val >> 24) & 0x01))
1178 priv->hw_features |= HW_FEATURE_RFKILL;
1180 IPW_DEBUG_INFO("HW RF Kill: %ssupported.\n",
1181 (priv->hw_features & HW_FEATURE_RFKILL) ?
1188 * Start firmware execution after power on and intialization
1191 * 2. Wait for f/w initialization completes;
1193 static int ipw2100_start_adapter(struct ipw2100_priv *priv)
1195 #define IPW_WAIT_FW_INIT_COMPLETE_DELAY (40 * HZ / 1000)
1197 u32 inta, inta_mask, gpio;
1199 IPW_DEBUG_INFO("enter\n");
1201 if (priv->status & STATUS_RUNNING)
1205 * Initialize the hw - drive adapter to DO state by setting
1206 * init_done bit. Wait for clk_ready bit and Download
1209 if (ipw2100_download_firmware(priv)) {
1210 IPW_DEBUG_ERROR("%s: Failed to power on the adapter.\n",
1211 priv->net_dev->name);
1215 /* Clear the Tx, Rx and Msg queues and the r/w indexes
1216 * in the firmware RBD and TBD ring queue */
1217 ipw2100_queues_initialize(priv);
1219 ipw2100_hw_set_gpio(priv);
1221 /* TODO -- Look at disabling interrupts here to make sure none
1222 * get fired during FW initialization */
1224 /* Release ARC - clear reset bit */
1225 write_register(priv->net_dev, IPW_REG_RESET_REG, 0);
1227 /* wait for f/w intialization complete */
1228 IPW_DEBUG_FW("Waiting for f/w initialization to complete...\n");
1231 set_current_state(TASK_UNINTERRUPTIBLE);
1232 schedule_timeout(IPW_WAIT_FW_INIT_COMPLETE_DELAY);
1233 /* Todo... wait for sync command ... */
1235 read_register(priv->net_dev, IPW_REG_INTA, &inta);
1237 /* check "init done" bit */
1238 if (inta & IPW2100_INTA_FW_INIT_DONE) {
1239 /* reset "init done" bit */
1240 write_register(priv->net_dev, IPW_REG_INTA,
1241 IPW2100_INTA_FW_INIT_DONE);
1245 /* check error conditions : we check these after the firmware
1246 * check so that if there is an error, the interrupt handler
1247 * will see it and the adapter will be reset */
1249 (IPW2100_INTA_FATAL_ERROR | IPW2100_INTA_PARITY_ERROR)) {
1250 /* clear error conditions */
1251 write_register(priv->net_dev, IPW_REG_INTA,
1252 IPW2100_INTA_FATAL_ERROR |
1253 IPW2100_INTA_PARITY_ERROR);
1257 /* Clear out any pending INTAs since we aren't supposed to have
1258 * interrupts enabled at this point... */
1259 read_register(priv->net_dev, IPW_REG_INTA, &inta);
1260 read_register(priv->net_dev, IPW_REG_INTA_MASK, &inta_mask);
1261 inta &= IPW_INTERRUPT_MASK;
1262 /* Clear out any pending interrupts */
1263 if (inta & inta_mask)
1264 write_register(priv->net_dev, IPW_REG_INTA, inta);
1266 IPW_DEBUG_FW("f/w initialization complete: %s\n",
1267 i ? "SUCCESS" : "FAILED");
1270 IPW_DEBUG_WARNING("%s: Firmware did not initialize.\n",
1271 priv->net_dev->name);
1275 /* allow firmware to write to GPIO1 & GPIO3 */
1276 read_register(priv->net_dev, IPW_REG_GPIO, &gpio);
1278 gpio |= (IPW_BIT_GPIO_GPIO1_MASK | IPW_BIT_GPIO_GPIO3_MASK);
1280 write_register(priv->net_dev, IPW_REG_GPIO, gpio);
1282 /* Ready to receive commands */
1283 priv->status |= STATUS_RUNNING;
1285 /* The adapter has been reset; we are not associated */
1286 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
1288 IPW_DEBUG_INFO("exit\n");
1293 static inline void ipw2100_reset_fatalerror(struct ipw2100_priv *priv)
1295 if (!priv->fatal_error)
1298 priv->fatal_errors[priv->fatal_index++] = priv->fatal_error;
1299 priv->fatal_index %= IPW2100_ERROR_QUEUE;
1300 priv->fatal_error = 0;
1304 /* NOTE: Our interrupt is disabled when this method is called */
1305 static int ipw2100_power_cycle_adapter(struct ipw2100_priv *priv)
1310 IPW_DEBUG_INFO("Power cycling the hardware.\n");
1312 ipw2100_hw_set_gpio(priv);
1314 /* Step 1. Stop Master Assert */
1315 write_register(priv->net_dev, IPW_REG_RESET_REG,
1316 IPW_AUX_HOST_RESET_REG_STOP_MASTER);
1318 /* Step 2. Wait for stop Master Assert
1319 * (not more then 50us, otherwise ret error */
1322 udelay(IPW_WAIT_RESET_MASTER_ASSERT_COMPLETE_DELAY);
1323 read_register(priv->net_dev, IPW_REG_RESET_REG, ®);
1325 if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED)
1329 priv->status &= ~STATUS_RESET_PENDING;
1332 IPW_DEBUG_INFO("exit - waited too long for master assert stop\n");
1336 write_register(priv->net_dev, IPW_REG_RESET_REG,
1337 IPW_AUX_HOST_RESET_REG_SW_RESET);
1340 /* Reset any fatal_error conditions */
1341 ipw2100_reset_fatalerror(priv);
1343 /* At this point, the adapter is now stopped and disabled */
1344 priv->status &= ~(STATUS_RUNNING | STATUS_ASSOCIATING |
1345 STATUS_ASSOCIATED | STATUS_ENABLED);
1351 * Send the CARD_DISABLE_PHY_OFF comamnd to the card to disable it
1353 * After disabling, if the card was associated, a STATUS_ASSN_LOST will be sent.
1355 * STATUS_CARD_DISABLE_NOTIFICATION will be sent regardless of
1356 * if STATUS_ASSN_LOST is sent.
1358 static int ipw2100_hw_phy_off(struct ipw2100_priv *priv)
1361 #define HW_PHY_OFF_LOOP_DELAY (HZ / 5000)
1363 struct host_command cmd = {
1364 .host_command = CARD_DISABLE_PHY_OFF,
1365 .host_command_sequence = 0,
1366 .host_command_length = 0,
1371 IPW_DEBUG_HC("CARD_DISABLE_PHY_OFF\n");
1373 /* Turn off the radio */
1374 err = ipw2100_hw_send_command(priv, &cmd);
1378 for (i = 0; i < 2500; i++) {
1379 read_nic_dword(priv->net_dev, IPW2100_CONTROL_REG, &val1);
1380 read_nic_dword(priv->net_dev, IPW2100_COMMAND, &val2);
1382 if ((val1 & IPW2100_CONTROL_PHY_OFF) &&
1383 (val2 & IPW2100_COMMAND_PHY_OFF))
1386 set_current_state(TASK_UNINTERRUPTIBLE);
1387 schedule_timeout(HW_PHY_OFF_LOOP_DELAY);
1394 static int ipw2100_enable_adapter(struct ipw2100_priv *priv)
1396 struct host_command cmd = {
1397 .host_command = HOST_COMPLETE,
1398 .host_command_sequence = 0,
1399 .host_command_length = 0
1403 IPW_DEBUG_HC("HOST_COMPLETE\n");
1405 if (priv->status & STATUS_ENABLED)
1408 down(&priv->adapter_sem);
1410 if (rf_kill_active(priv)) {
1411 IPW_DEBUG_HC("Command aborted due to RF kill active.\n");
1415 err = ipw2100_hw_send_command(priv, &cmd);
1417 IPW_DEBUG_INFO("Failed to send HOST_COMPLETE command\n");
1421 err = ipw2100_wait_for_card_state(priv, IPW_HW_STATE_ENABLED);
1424 "%s: card not responding to init command.\n",
1425 priv->net_dev->name);
1429 if (priv->stop_hang_check) {
1430 priv->stop_hang_check = 0;
1431 queue_delayed_work(priv->workqueue, &priv->hang_check, HZ / 2);
1435 up(&priv->adapter_sem);
1439 static int ipw2100_hw_stop_adapter(struct ipw2100_priv *priv)
1441 #define HW_POWER_DOWN_DELAY (HZ / 10)
1443 struct host_command cmd = {
1444 .host_command = HOST_PRE_POWER_DOWN,
1445 .host_command_sequence = 0,
1446 .host_command_length = 0,
1451 if (!(priv->status & STATUS_RUNNING))
1454 priv->status |= STATUS_STOPPING;
1456 /* We can only shut down the card if the firmware is operational. So,
1457 * if we haven't reset since a fatal_error, then we can not send the
1458 * shutdown commands. */
1459 if (!priv->fatal_error) {
1460 /* First, make sure the adapter is enabled so that the PHY_OFF
1461 * command can shut it down */
1462 ipw2100_enable_adapter(priv);
1464 err = ipw2100_hw_phy_off(priv);
1466 IPW_DEBUG_WARNING("Error disabling radio %d\n", err);
1469 * If in D0-standby mode going directly to D3 may cause a
1470 * PCI bus violation. Therefore we must change out of the D0
1473 * Sending the PREPARE_FOR_POWER_DOWN will restrict the
1474 * hardware from going into standby mode and will transition
1475 * out of D0-standy if it is already in that state.
1477 * STATUS_PREPARE_POWER_DOWN_COMPLETE will be sent by the
1478 * driver upon completion. Once received, the driver can
1479 * proceed to the D3 state.
1481 * Prepare for power down command to fw. This command would
1482 * take HW out of D0-standby and prepare it for D3 state.
1484 * Currently FW does not support event notification for this
1485 * event. Therefore, skip waiting for it. Just wait a fixed
1488 IPW_DEBUG_HC("HOST_PRE_POWER_DOWN\n");
1490 err = ipw2100_hw_send_command(priv, &cmd);
1493 "%s: Power down command failed: Error %d\n",
1494 priv->net_dev->name, err);
1496 set_current_state(TASK_UNINTERRUPTIBLE);
1497 schedule_timeout(HW_POWER_DOWN_DELAY);
1501 priv->status &= ~STATUS_ENABLED;
1504 * Set GPIO 3 writable by FW; GPIO 1 writable
1505 * by driver and enable clock
1507 ipw2100_hw_set_gpio(priv);
1510 * Power down adapter. Sequence:
1511 * 1. Stop master assert (RESET_REG[9]=1)
1512 * 2. Wait for stop master (RESET_REG[8]==1)
1513 * 3. S/w reset assert (RESET_REG[7] = 1)
1516 /* Stop master assert */
1517 write_register(priv->net_dev, IPW_REG_RESET_REG,
1518 IPW_AUX_HOST_RESET_REG_STOP_MASTER);
1520 /* wait stop master not more than 50 usec.
1521 * Otherwise return error. */
1522 for (i = 5; i > 0; i--) {
1525 /* Check master stop bit */
1526 read_register(priv->net_dev, IPW_REG_RESET_REG, ®);
1528 if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED)
1533 IPW_DEBUG_WARNING(DRV_NAME
1534 ": %s: Could now power down adapter.\n",
1535 priv->net_dev->name);
1537 /* assert s/w reset */
1538 write_register(priv->net_dev, IPW_REG_RESET_REG,
1539 IPW_AUX_HOST_RESET_REG_SW_RESET);
1541 priv->status &= ~(STATUS_RUNNING | STATUS_STOPPING);
1547 static int ipw2100_disable_adapter(struct ipw2100_priv *priv)
1549 struct host_command cmd = {
1550 .host_command = CARD_DISABLE,
1551 .host_command_sequence = 0,
1552 .host_command_length = 0
1556 IPW_DEBUG_HC("CARD_DISABLE\n");
1558 if (!(priv->status & STATUS_ENABLED))
1561 /* Make sure we clear the associated state */
1562 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1564 if (!priv->stop_hang_check) {
1565 priv->stop_hang_check = 1;
1566 cancel_delayed_work(&priv->hang_check);
1569 down(&priv->adapter_sem);
1571 err = ipw2100_hw_send_command(priv, &cmd);
1573 IPW_DEBUG_WARNING("exit - failed to send CARD_DISABLE command\n");
1577 err = ipw2100_wait_for_card_state(priv, IPW_HW_STATE_DISABLED);
1579 IPW_DEBUG_WARNING("exit - card failed to change to DISABLED\n");
1583 IPW_DEBUG_INFO("TODO: implement scan state machine\n");
1586 up(&priv->adapter_sem);
1590 int ipw2100_set_scan_options(struct ipw2100_priv *priv)
1592 struct host_command cmd = {
1593 .host_command = SET_SCAN_OPTIONS,
1594 .host_command_sequence = 0,
1595 .host_command_length = 8
1599 IPW_DEBUG_INFO("enter\n");
1601 IPW_DEBUG_SCAN("setting scan options\n");
1603 cmd.host_command_parameters[0] = 0;
1605 if (!(priv->config & CFG_ASSOCIATE))
1606 cmd.host_command_parameters[0] |= IPW_SCAN_NOASSOCIATE;
1607 if ((priv->sec.flags & SEC_ENABLED) && priv->sec.enabled)
1608 cmd.host_command_parameters[0] |= IPW_SCAN_MIXED_CELL;
1609 if (priv->config & CFG_PASSIVE_SCAN)
1610 cmd.host_command_parameters[0] |= IPW_SCAN_PASSIVE;
1612 cmd.host_command_parameters[1] = priv->channel_mask;
1614 err = ipw2100_hw_send_command(priv, &cmd);
1616 IPW_DEBUG_HC("SET_SCAN_OPTIONS 0x%04X\n",
1617 cmd.host_command_parameters[0]);
1622 int ipw2100_start_scan(struct ipw2100_priv *priv)
1624 struct host_command cmd = {
1625 .host_command = BROADCAST_SCAN,
1626 .host_command_sequence = 0,
1627 .host_command_length = 4
1631 IPW_DEBUG_HC("START_SCAN\n");
1633 cmd.host_command_parameters[0] = 0;
1635 /* No scanning if in monitor mode */
1636 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
1639 if (priv->status & STATUS_SCANNING) {
1640 IPW_DEBUG_SCAN("Scan requested while already in scan...\n");
1644 IPW_DEBUG_INFO("enter\n");
1646 /* Not clearing here; doing so makes iwlist always return nothing...
1648 * We should modify the table logic to use aging tables vs. clearing
1649 * the table on each scan start.
1651 IPW_DEBUG_SCAN("starting scan\n");
1653 priv->status |= STATUS_SCANNING;
1654 err = ipw2100_hw_send_command(priv, &cmd);
1656 priv->status &= ~STATUS_SCANNING;
1658 IPW_DEBUG_INFO("exit\n");
1663 static int ipw2100_up(struct ipw2100_priv *priv, int deferred)
1665 unsigned long flags;
1668 u32 ord_len = sizeof(lock);
1670 /* Quite if manually disabled. */
1671 if (priv->status & STATUS_RF_KILL_SW) {
1672 IPW_DEBUG_INFO("%s: Radio is disabled by Manual Disable "
1673 "switch\n", priv->net_dev->name);
1677 /* If the interrupt is enabled, turn it off... */
1678 spin_lock_irqsave(&priv->low_lock, flags);
1679 ipw2100_disable_interrupts(priv);
1681 /* Reset any fatal_error conditions */
1682 ipw2100_reset_fatalerror(priv);
1683 spin_unlock_irqrestore(&priv->low_lock, flags);
1685 if (priv->status & STATUS_POWERED ||
1686 (priv->status & STATUS_RESET_PENDING)) {
1687 /* Power cycle the card ... */
1688 if (ipw2100_power_cycle_adapter(priv)) {
1689 IPW_DEBUG_WARNING("%s: Could not cycle adapter.\n",
1690 priv->net_dev->name);
1695 priv->status |= STATUS_POWERED;
1697 /* Load the firmeware, start the clocks, etc. */
1698 if (ipw2100_start_adapter(priv)) {
1699 IPW_DEBUG_ERROR("%s: Failed to start the firmware.\n",
1700 priv->net_dev->name);
1705 ipw2100_initialize_ordinals(priv);
1707 /* Determine capabilities of this particular HW configuration */
1708 if (ipw2100_get_hw_features(priv)) {
1709 IPW_DEBUG_ERROR("%s: Failed to determine HW features.\n",
1710 priv->net_dev->name);
1716 if (ipw2100_set_ordinal(priv, IPW_ORD_PERS_DB_LOCK, &lock, &ord_len)) {
1717 IPW_DEBUG_ERROR("%s: Failed to clear ordinal lock.\n",
1718 priv->net_dev->name);
1723 priv->status &= ~STATUS_SCANNING;
1725 if (rf_kill_active(priv)) {
1726 printk(KERN_INFO "%s: Radio is disabled by RF switch.\n",
1727 priv->net_dev->name);
1729 if (priv->stop_rf_kill) {
1730 priv->stop_rf_kill = 0;
1731 queue_delayed_work(priv->workqueue, &priv->rf_kill, HZ);
1737 /* Turn on the interrupt so that commands can be processed */
1738 ipw2100_enable_interrupts(priv);
1740 /* Send all of the commands that must be sent prior to
1742 if (ipw2100_adapter_setup(priv)) {
1743 IPW_DEBUG_ERROR("%s: Failed to start the card.\n",
1744 priv->net_dev->name);
1750 /* Enable the adapter - sends HOST_COMPLETE */
1751 if (ipw2100_enable_adapter(priv)) {
1753 "%s: failed in call to enable adapter.\n",
1754 priv->net_dev->name);
1755 ipw2100_hw_stop_adapter(priv);
1761 /* Start a scan . . . */
1762 ipw2100_set_scan_options(priv);
1763 ipw2100_start_scan(priv);
1770 /* Called by register_netdev() */
1771 static int ipw2100_net_init(struct net_device *dev)
1773 struct ipw2100_priv *priv = ieee80211_priv(dev);
1774 return ipw2100_up(priv, 1);
1777 static void ipw2100_down(struct ipw2100_priv *priv)
1779 unsigned long flags;
1780 union iwreq_data wrqu = {
1782 .sa_family = ARPHRD_ETHER
1785 int associated = priv->status & STATUS_ASSOCIATED;
1787 /* Kill the RF switch timer */
1788 if (!priv->stop_rf_kill) {
1789 priv->stop_rf_kill = 1;
1790 cancel_delayed_work(&priv->rf_kill);
1793 /* Kill the firmare hang check timer */
1794 if (!priv->stop_hang_check) {
1795 priv->stop_hang_check = 1;
1796 cancel_delayed_work(&priv->hang_check);
1799 /* Kill any pending resets */
1800 if (priv->status & STATUS_RESET_PENDING)
1801 cancel_delayed_work(&priv->reset_work);
1803 /* Make sure the interrupt is on so that FW commands will be
1804 * processed correctly */
1805 spin_lock_irqsave(&priv->low_lock, flags);
1806 ipw2100_enable_interrupts(priv);
1807 spin_unlock_irqrestore(&priv->low_lock, flags);
1809 if (ipw2100_hw_stop_adapter(priv))
1810 IPW_DEBUG_ERROR("%s: Error stopping adapter.\n",
1811 priv->net_dev->name);
1813 /* Do not disable the interrupt until _after_ we disable
1814 * the adaptor. Otherwise the CARD_DISABLE command will never
1815 * be ack'd by the firmware */
1816 spin_lock_irqsave(&priv->low_lock, flags);
1817 ipw2100_disable_interrupts(priv);
1818 spin_unlock_irqrestore(&priv->low_lock, flags);
1820 #ifdef ACPI_CSTATE_LIMIT_DEFINED
1821 if (priv->config & CFG_C3_DISABLED) {
1822 IPW_DEBUG_INFO(DRV_NAME ": Resetting C3 transitions.\n");
1823 acpi_set_cstate_limit(priv->cstate_limit);
1824 priv->config &= ~CFG_C3_DISABLED;
1828 /* We have to signal any supplicant if we are disassociating */
1830 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1832 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1833 netif_carrier_off(priv->net_dev);
1834 netif_stop_queue(priv->net_dev);
1837 void ipw2100_reset_adapter(struct ipw2100_priv *priv)
1839 unsigned long flags;
1840 union iwreq_data wrqu = {
1842 .sa_family = ARPHRD_ETHER
1845 int associated = priv->status & STATUS_ASSOCIATED;
1847 spin_lock_irqsave(&priv->low_lock, flags);
1848 IPW_DEBUG_INFO(DRV_NAME ": %s: Restarting adapter.\n",
1849 priv->net_dev->name);
1851 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1852 priv->status |= STATUS_SECURITY_UPDATED;
1854 /* Force a power cycle even if interface hasn't been opened
1856 cancel_delayed_work(&priv->reset_work);
1857 priv->status |= STATUS_RESET_PENDING;
1858 spin_unlock_irqrestore(&priv->low_lock, flags);
1860 down(&priv->action_sem);
1861 /* stop timed checks so that they don't interfere with reset */
1862 priv->stop_hang_check = 1;
1863 cancel_delayed_work(&priv->hang_check);
1865 /* We have to signal any supplicant if we are disassociating */
1867 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1869 ipw2100_up(priv, 0);
1870 up(&priv->action_sem);
1875 static void isr_indicate_associated(struct ipw2100_priv *priv, u32 status)
1878 #define MAC_ASSOCIATION_READ_DELAY (HZ)
1879 int ret, len, essid_len;
1880 char essid[IW_ESSID_MAX_SIZE];
1887 * TBD: BSSID is usually 00:00:00:00:00:00 here and not
1888 * an actual MAC of the AP. Seems like FW sets this
1889 * address too late. Read it later and expose through
1890 * /proc or schedule a later task to query and update
1893 essid_len = IW_ESSID_MAX_SIZE;
1894 ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_SSID,
1897 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
1903 ret = ipw2100_get_ordinal(priv, IPW_ORD_CURRENT_TX_RATE,
1906 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
1912 ret = ipw2100_get_ordinal(priv, IPW_ORD_OUR_FREQ, &chan, &len);
1914 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
1919 ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID, &bssid, &len);
1921 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
1925 memcpy(priv->ieee->bssid, bssid, ETH_ALEN);
1929 case TX_RATE_1_MBIT:
1930 txratename = "1Mbps";
1932 case TX_RATE_2_MBIT:
1933 txratename = "2Mbsp";
1935 case TX_RATE_5_5_MBIT:
1936 txratename = "5.5Mbps";
1938 case TX_RATE_11_MBIT:
1939 txratename = "11Mbps";
1942 IPW_DEBUG_INFO("Unknown rate: %d\n", txrate);
1943 txratename = "unknown rate";
1947 IPW_DEBUG_INFO("%s: Associated with '%s' at %s, channel %d (BSSID="
1949 priv->net_dev->name, escape_essid(essid, essid_len),
1950 txratename, chan, MAC_ARG(bssid));
1952 /* now we copy read ssid into dev */
1953 if (!(priv->config & CFG_STATIC_ESSID)) {
1954 priv->essid_len = min((u8)essid_len, (u8)IW_ESSID_MAX_SIZE);
1955 memcpy(priv->essid, essid, priv->essid_len);
1957 priv->channel = chan;
1958 memcpy(priv->bssid, bssid, ETH_ALEN);
1960 priv->status |= STATUS_ASSOCIATING;
1961 priv->connect_start = get_seconds();
1963 queue_delayed_work(priv->workqueue, &priv->wx_event_work, HZ / 10);
1967 int ipw2100_set_essid(struct ipw2100_priv *priv, char *essid,
1968 int length, int batch_mode)
1970 int ssid_len = min(length, IW_ESSID_MAX_SIZE);
1971 struct host_command cmd = {
1972 .host_command = SSID,
1973 .host_command_sequence = 0,
1974 .host_command_length = ssid_len
1978 IPW_DEBUG_HC("SSID: '%s'\n", escape_essid(essid, ssid_len));
1981 memcpy((char*)cmd.host_command_parameters,
1985 err = ipw2100_disable_adapter(priv);
1990 /* Bug in FW currently doesn't honor bit 0 in SET_SCAN_OPTIONS to
1991 * disable auto association -- so we cheat by setting a bogus SSID */
1992 if (!ssid_len && !(priv->config & CFG_ASSOCIATE)) {
1994 u8 *bogus = (u8*)cmd.host_command_parameters;
1995 for (i = 0; i < IW_ESSID_MAX_SIZE; i++)
1996 bogus[i] = 0x18 + i;
1997 cmd.host_command_length = IW_ESSID_MAX_SIZE;
2000 /* NOTE: We always send the SSID command even if the provided ESSID is
2001 * the same as what we currently think is set. */
2003 err = ipw2100_hw_send_command(priv, &cmd);
2005 memset(priv->essid + ssid_len, 0,
2006 IW_ESSID_MAX_SIZE - ssid_len);
2007 memcpy(priv->essid, essid, ssid_len);
2008 priv->essid_len = ssid_len;
2012 if (ipw2100_enable_adapter(priv))
2019 static void isr_indicate_association_lost(struct ipw2100_priv *priv, u32 status)
2021 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | IPW_DL_ASSOC,
2022 "disassociated: '%s' " MAC_FMT " \n",
2023 escape_essid(priv->essid, priv->essid_len),
2024 MAC_ARG(priv->bssid));
2026 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
2028 if (priv->status & STATUS_STOPPING) {
2029 IPW_DEBUG_INFO("Card is stopping itself, discard ASSN_LOST.\n");
2033 memset(priv->bssid, 0, ETH_ALEN);
2034 memset(priv->ieee->bssid, 0, ETH_ALEN);
2036 netif_carrier_off(priv->net_dev);
2037 netif_stop_queue(priv->net_dev);
2039 if (!(priv->status & STATUS_RUNNING))
2042 if (priv->status & STATUS_SECURITY_UPDATED)
2043 queue_work(priv->workqueue, &priv->security_work);
2045 queue_work(priv->workqueue, &priv->wx_event_work);
2048 static void isr_indicate_rf_kill(struct ipw2100_priv *priv, u32 status)
2050 IPW_DEBUG_INFO("%s: RF Kill state changed to radio OFF.\n",
2051 priv->net_dev->name);
2053 /* RF_KILL is now enabled (else we wouldn't be here) */
2054 priv->status |= STATUS_RF_KILL_HW;
2056 #ifdef ACPI_CSTATE_LIMIT_DEFINED
2057 if (priv->config & CFG_C3_DISABLED) {
2058 IPW_DEBUG_INFO(DRV_NAME ": Resetting C3 transitions.\n");
2059 acpi_set_cstate_limit(priv->cstate_limit);
2060 priv->config &= ~CFG_C3_DISABLED;
2064 /* Make sure the RF Kill check timer is running */
2065 priv->stop_rf_kill = 0;
2066 cancel_delayed_work(&priv->rf_kill);
2067 queue_delayed_work(priv->workqueue, &priv->rf_kill, HZ);
2070 static void isr_scan_complete(struct ipw2100_priv *priv, u32 status)
2072 IPW_DEBUG_SCAN("scan complete\n");
2073 /* Age the scan results... */
2074 priv->ieee->scans++;
2075 priv->status &= ~STATUS_SCANNING;
2078 #ifdef CONFIG_IPW_DEBUG
2079 #define IPW2100_HANDLER(v, f) { v, f, # v }
2080 struct ipw2100_status_indicator {
2082 void (*cb)(struct ipw2100_priv *priv, u32 status);
2086 #define IPW2100_HANDLER(v, f) { v, f }
2087 struct ipw2100_status_indicator {
2089 void (*cb)(struct ipw2100_priv *priv, u32 status);
2091 #endif /* CONFIG_IPW_DEBUG */
2093 static void isr_indicate_scanning(struct ipw2100_priv *priv, u32 status)
2095 IPW_DEBUG_SCAN("Scanning...\n");
2096 priv->status |= STATUS_SCANNING;
2099 const struct ipw2100_status_indicator status_handlers[] = {
2100 IPW2100_HANDLER(IPW_STATE_INITIALIZED, 0),
2101 IPW2100_HANDLER(IPW_STATE_COUNTRY_FOUND, 0),
2102 IPW2100_HANDLER(IPW_STATE_ASSOCIATED, isr_indicate_associated),
2103 IPW2100_HANDLER(IPW_STATE_ASSN_LOST, isr_indicate_association_lost),
2104 IPW2100_HANDLER(IPW_STATE_ASSN_CHANGED, 0),
2105 IPW2100_HANDLER(IPW_STATE_SCAN_COMPLETE, isr_scan_complete),
2106 IPW2100_HANDLER(IPW_STATE_ENTERED_PSP, 0),
2107 IPW2100_HANDLER(IPW_STATE_LEFT_PSP, 0),
2108 IPW2100_HANDLER(IPW_STATE_RF_KILL, isr_indicate_rf_kill),
2109 IPW2100_HANDLER(IPW_STATE_DISABLED, 0),
2110 IPW2100_HANDLER(IPW_STATE_POWER_DOWN, 0),
2111 IPW2100_HANDLER(IPW_STATE_SCANNING, isr_indicate_scanning),
2112 IPW2100_HANDLER(-1, 0)
2116 static void isr_status_change(struct ipw2100_priv *priv, int status)
2120 if (status == IPW_STATE_SCANNING &&
2121 priv->status & STATUS_ASSOCIATED &&
2122 !(priv->status & STATUS_SCANNING)) {
2123 IPW_DEBUG_INFO("Scan detected while associated, with "
2124 "no scan request. Restarting firmware.\n");
2126 /* Wake up any sleeping jobs */
2127 schedule_reset(priv);
2130 for (i = 0; status_handlers[i].status != -1; i++) {
2131 if (status == status_handlers[i].status) {
2132 IPW_DEBUG_NOTIF("Status change: %s\n",
2133 status_handlers[i].name);
2134 if (status_handlers[i].cb)
2135 status_handlers[i].cb(priv, status);
2136 priv->wstats.status = status;
2141 IPW_DEBUG_NOTIF("unknown status received: %04x\n", status);
2144 static void isr_rx_complete_command(
2145 struct ipw2100_priv *priv,
2146 struct ipw2100_cmd_header *cmd)
2148 #ifdef CONFIG_IPW_DEBUG
2149 if (cmd->host_command_reg < ARRAY_SIZE(command_types)) {
2150 IPW_DEBUG_HC("Command completed '%s (%d)'\n",
2151 command_types[cmd->host_command_reg],
2152 cmd->host_command_reg);
2155 if (cmd->host_command_reg == HOST_COMPLETE)
2156 priv->status |= STATUS_ENABLED;
2158 if (cmd->host_command_reg == CARD_DISABLE)
2159 priv->status &= ~STATUS_ENABLED;
2161 priv->status &= ~STATUS_CMD_ACTIVE;
2163 wake_up_interruptible(&priv->wait_command_queue);
2166 #ifdef CONFIG_IPW_DEBUG
2167 const char *frame_types[] = {
2168 "COMMAND_STATUS_VAL",
2169 "STATUS_CHANGE_VAL",
2172 "HOST_NOTIFICATION_VAL"
2177 static inline int ipw2100_alloc_skb(
2178 struct ipw2100_priv *priv,
2179 struct ipw2100_rx_packet *packet)
2181 packet->skb = dev_alloc_skb(sizeof(struct ipw2100_rx));
2185 packet->rxp = (struct ipw2100_rx *)packet->skb->data;
2186 packet->dma_addr = pci_map_single(priv->pci_dev, packet->skb->data,
2187 sizeof(struct ipw2100_rx),
2188 PCI_DMA_FROMDEVICE);
2189 /* NOTE: pci_map_single does not return an error code, and 0 is a valid
2196 #define SEARCH_ERROR 0xffffffff
2197 #define SEARCH_FAIL 0xfffffffe
2198 #define SEARCH_SUCCESS 0xfffffff0
2199 #define SEARCH_DISCARD 0
2200 #define SEARCH_SNAPSHOT 1
2202 #define SNAPSHOT_ADDR(ofs) (priv->snapshot[((ofs) >> 12) & 0xff] + ((ofs) & 0xfff))
2203 static inline int ipw2100_snapshot_alloc(struct ipw2100_priv *priv)
2206 if (priv->snapshot[0])
2208 for (i = 0; i < 0x30; i++) {
2209 priv->snapshot[i] = (u8*)kmalloc(0x1000, GFP_ATOMIC);
2210 if (!priv->snapshot[i]) {
2211 IPW_DEBUG_INFO("%s: Error allocating snapshot "
2212 "buffer %d\n", priv->net_dev->name, i);
2214 kfree(priv->snapshot[--i]);
2215 priv->snapshot[0] = NULL;
2223 static inline void ipw2100_snapshot_free(struct ipw2100_priv *priv)
2226 if (!priv->snapshot[0])
2228 for (i = 0; i < 0x30; i++)
2229 kfree(priv->snapshot[i]);
2230 priv->snapshot[0] = NULL;
2233 static inline u32 ipw2100_match_buf(struct ipw2100_priv *priv, u8 *in_buf,
2234 size_t len, int mode)
2242 if (mode == SEARCH_SNAPSHOT) {
2243 if (!ipw2100_snapshot_alloc(priv))
2244 mode = SEARCH_DISCARD;
2247 for (ret = SEARCH_FAIL, i = 0; i < 0x30000; i += 4) {
2248 read_nic_dword(priv->net_dev, i, &tmp);
2249 if (mode == SEARCH_SNAPSHOT)
2250 *(u32 *)SNAPSHOT_ADDR(i) = tmp;
2251 if (ret == SEARCH_FAIL) {
2253 for (j = 0; j < 4; j++) {
2262 if ((s - in_buf) == len)
2263 ret = (i + j) - len + 1;
2265 } else if (mode == SEARCH_DISCARD)
2274 * 0) Disconnect the SKB from the firmware (just unmap)
2275 * 1) Pack the ETH header into the SKB
2276 * 2) Pass the SKB to the network stack
2278 * When packet is provided by the firmware, it contains the following:
2281 * . ieee80211_snap_hdr
2283 * The size of the constructed ethernet
2286 #ifdef CONFIG_IPW2100_RX_DEBUG
2287 u8 packet_data[IPW_RX_NIC_BUFFER_LENGTH];
2290 static inline void ipw2100_corruption_detected(struct ipw2100_priv *priv,
2293 #ifdef CONFIG_IPW_DEBUG_C3
2294 struct ipw2100_status *status = &priv->status_queue.drv[i];
2298 #ifdef ACPI_CSTATE_LIMIT_DEFINED
2302 IPW_DEBUG_INFO(DRV_NAME ": PCI latency error detected at "
2303 "0x%04zX.\n", i * sizeof(struct ipw2100_status));
2305 #ifdef ACPI_CSTATE_LIMIT_DEFINED
2306 IPW_DEBUG_INFO(DRV_NAME ": Disabling C3 transitions.\n");
2307 limit = acpi_get_cstate_limit();
2309 priv->cstate_limit = limit;
2310 acpi_set_cstate_limit(2);
2311 priv->config |= CFG_C3_DISABLED;
2315 #ifdef CONFIG_IPW_DEBUG_C3
2316 /* Halt the fimrware so we can get a good image */
2317 write_register(priv->net_dev, IPW_REG_RESET_REG,
2318 IPW_AUX_HOST_RESET_REG_STOP_MASTER);
2321 udelay(IPW_WAIT_RESET_MASTER_ASSERT_COMPLETE_DELAY);
2322 read_register(priv->net_dev, IPW_REG_RESET_REG, ®);
2324 if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED)
2328 match = ipw2100_match_buf(priv, (u8*)status,
2329 sizeof(struct ipw2100_status),
2331 if (match < SEARCH_SUCCESS)
2332 IPW_DEBUG_INFO("%s: DMA status match in Firmware at "
2333 "offset 0x%06X, length %d:\n",
2334 priv->net_dev->name, match,
2335 sizeof(struct ipw2100_status));
2337 IPW_DEBUG_INFO("%s: No DMA status match in "
2338 "Firmware.\n", priv->net_dev->name);
2340 printk_buf((u8*)priv->status_queue.drv,
2341 sizeof(struct ipw2100_status) * RX_QUEUE_LENGTH);
2344 priv->fatal_error = IPW2100_ERR_C3_CORRUPTION;
2345 priv->ieee->stats.rx_errors++;
2346 schedule_reset(priv);
2349 static inline void isr_rx(struct ipw2100_priv *priv, int i,
2350 struct ieee80211_rx_stats *stats)
2352 struct ipw2100_status *status = &priv->status_queue.drv[i];
2353 struct ipw2100_rx_packet *packet = &priv->rx_buffers[i];
2355 IPW_DEBUG_RX("Handler...\n");
2357 if (unlikely(status->frame_size > skb_tailroom(packet->skb))) {
2358 IPW_DEBUG_INFO("%s: frame_size (%u) > skb_tailroom (%u)!"
2360 priv->net_dev->name,
2361 status->frame_size, skb_tailroom(packet->skb));
2362 priv->ieee->stats.rx_errors++;
2366 if (unlikely(!netif_running(priv->net_dev))) {
2367 priv->ieee->stats.rx_errors++;
2368 priv->wstats.discard.misc++;
2369 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
2373 if (unlikely(priv->ieee->iw_mode == IW_MODE_MONITOR &&
2374 status->flags & IPW_STATUS_FLAG_CRC_ERROR)) {
2375 IPW_DEBUG_RX("CRC error in packet. Dropping.\n");
2376 priv->ieee->stats.rx_errors++;
2380 if (unlikely(priv->ieee->iw_mode != IW_MODE_MONITOR &&
2381 !(priv->status & STATUS_ASSOCIATED))) {
2382 IPW_DEBUG_DROP("Dropping packet while not associated.\n");
2383 priv->wstats.discard.misc++;
2388 pci_unmap_single(priv->pci_dev,
2390 sizeof(struct ipw2100_rx),
2391 PCI_DMA_FROMDEVICE);
2393 skb_put(packet->skb, status->frame_size);
2395 #ifdef CONFIG_IPW2100_RX_DEBUG
2396 /* Make a copy of the frame so we can dump it to the logs if
2397 * ieee80211_rx fails */
2398 memcpy(packet_data, packet->skb->data,
2399 min_t(u32, status->frame_size, IPW_RX_NIC_BUFFER_LENGTH));
2402 if (!ieee80211_rx(priv->ieee, packet->skb, stats)) {
2403 #ifdef CONFIG_IPW2100_RX_DEBUG
2404 IPW_DEBUG_DROP("%s: Non consumed packet:\n",
2405 priv->net_dev->name);
2406 printk_buf(IPW_DL_DROP, packet_data, status->frame_size);
2408 priv->ieee->stats.rx_errors++;
2410 /* ieee80211_rx failed, so it didn't free the SKB */
2411 dev_kfree_skb_any(packet->skb);
2415 /* We need to allocate a new SKB and attach it to the RDB. */
2416 if (unlikely(ipw2100_alloc_skb(priv, packet))) {
2418 "%s: Unable to allocate SKB onto RBD ring - disabling "
2419 "adapter.\n", priv->net_dev->name);
2420 /* TODO: schedule adapter shutdown */
2421 IPW_DEBUG_INFO("TODO: Shutdown adapter...\n");
2424 /* Update the RDB entry */
2425 priv->rx_queue.drv[i].host_addr = packet->dma_addr;
2428 static inline int ipw2100_corruption_check(struct ipw2100_priv *priv, int i)
2430 struct ipw2100_status *status = &priv->status_queue.drv[i];
2431 struct ipw2100_rx *u = priv->rx_buffers[i].rxp;
2432 u16 frame_type = status->status_fields & STATUS_TYPE_MASK;
2434 switch (frame_type) {
2435 case COMMAND_STATUS_VAL:
2436 return (status->frame_size != sizeof(u->rx_data.command));
2437 case STATUS_CHANGE_VAL:
2438 return (status->frame_size != sizeof(u->rx_data.status));
2439 case HOST_NOTIFICATION_VAL:
2440 return (status->frame_size < sizeof(u->rx_data.notification));
2441 case P80211_DATA_VAL:
2442 case P8023_DATA_VAL:
2443 #ifdef CONFIG_IPW2100_MONITOR
2446 switch (WLAN_FC_GET_TYPE(u->rx_data.header.frame_ctl)) {
2447 case IEEE80211_FTYPE_MGMT:
2448 case IEEE80211_FTYPE_CTL:
2450 case IEEE80211_FTYPE_DATA:
2451 return (status->frame_size >
2452 IPW_MAX_802_11_PAYLOAD_LENGTH);
2461 * ipw2100 interrupts are disabled at this point, and the ISR
2462 * is the only code that calls this method. So, we do not need
2463 * to play with any locks.
2465 * RX Queue works as follows:
2467 * Read index - firmware places packet in entry identified by the
2468 * Read index and advances Read index. In this manner,
2469 * Read index will always point to the next packet to
2470 * be filled--but not yet valid.
2472 * Write index - driver fills this entry with an unused RBD entry.
2473 * This entry has not filled by the firmware yet.
2475 * In between the W and R indexes are the RBDs that have been received
2476 * but not yet processed.
2478 * The process of handling packets will start at WRITE + 1 and advance
2479 * until it reaches the READ index.
2481 * The WRITE index is cached in the variable 'priv->rx_queue.next'.
2484 static inline void __ipw2100_rx_process(struct ipw2100_priv *priv)
2486 struct ipw2100_bd_queue *rxq = &priv->rx_queue;
2487 struct ipw2100_status_queue *sq = &priv->status_queue;
2488 struct ipw2100_rx_packet *packet;
2491 struct ipw2100_rx *u;
2492 struct ieee80211_rx_stats stats = {
2493 .mac_time = jiffies,
2496 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_READ_INDEX, &r);
2497 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_WRITE_INDEX, &w);
2499 if (r >= rxq->entries) {
2500 IPW_DEBUG_RX("exit - bad read index\n");
2504 i = (rxq->next + 1) % rxq->entries;
2507 /* IPW_DEBUG_RX("r = %d : w = %d : processing = %d\n",
2508 r, rxq->next, i); */
2510 packet = &priv->rx_buffers[i];
2512 /* Sync the DMA for the STATUS buffer so CPU is sure to get
2513 * the correct values */
2514 pci_dma_sync_single_for_cpu(
2516 sq->nic + sizeof(struct ipw2100_status) * i,
2517 sizeof(struct ipw2100_status),
2518 PCI_DMA_FROMDEVICE);
2520 /* Sync the DMA for the RX buffer so CPU is sure to get
2521 * the correct values */
2522 pci_dma_sync_single_for_cpu(priv->pci_dev, packet->dma_addr,
2523 sizeof(struct ipw2100_rx),
2524 PCI_DMA_FROMDEVICE);
2526 if (unlikely(ipw2100_corruption_check(priv, i))) {
2527 ipw2100_corruption_detected(priv, i);
2532 frame_type = sq->drv[i].status_fields &
2534 stats.rssi = sq->drv[i].rssi + IPW2100_RSSI_TO_DBM;
2535 stats.len = sq->drv[i].frame_size;
2538 if (stats.rssi != 0)
2539 stats.mask |= IEEE80211_STATMASK_RSSI;
2540 stats.freq = IEEE80211_24GHZ_BAND;
2543 "%s: '%s' frame type received (%d).\n",
2544 priv->net_dev->name, frame_types[frame_type],
2547 switch (frame_type) {
2548 case COMMAND_STATUS_VAL:
2549 /* Reset Rx watchdog */
2550 isr_rx_complete_command(
2551 priv, &u->rx_data.command);
2554 case STATUS_CHANGE_VAL:
2555 isr_status_change(priv, u->rx_data.status);
2558 case P80211_DATA_VAL:
2559 case P8023_DATA_VAL:
2560 #ifdef CONFIG_IPW2100_MONITOR
2561 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
2562 isr_rx(priv, i, &stats);
2566 if (stats.len < sizeof(u->rx_data.header))
2568 switch (WLAN_FC_GET_TYPE(u->rx_data.header.
2570 case IEEE80211_FTYPE_MGMT:
2571 ieee80211_rx_mgt(priv->ieee,
2576 case IEEE80211_FTYPE_CTL:
2579 case IEEE80211_FTYPE_DATA:
2580 isr_rx(priv, i, &stats);
2588 /* clear status field associated with this RBD */
2589 rxq->drv[i].status.info.field = 0;
2591 i = (i + 1) % rxq->entries;
2595 /* backtrack one entry, wrapping to end if at 0 */
2596 rxq->next = (i ? i : rxq->entries) - 1;
2598 write_register(priv->net_dev,
2599 IPW_MEM_HOST_SHARED_RX_WRITE_INDEX,
2606 * __ipw2100_tx_process
2608 * This routine will determine whether the next packet on
2609 * the fw_pend_list has been processed by the firmware yet.
2611 * If not, then it does nothing and returns.
2613 * If so, then it removes the item from the fw_pend_list, frees
2614 * any associated storage, and places the item back on the
2615 * free list of its source (either msg_free_list or tx_free_list)
2617 * TX Queue works as follows:
2619 * Read index - points to the next TBD that the firmware will
2620 * process. The firmware will read the data, and once
2621 * done processing, it will advance the Read index.
2623 * Write index - driver fills this entry with an constructed TBD
2624 * entry. The Write index is not advanced until the
2625 * packet has been configured.
2627 * In between the W and R indexes are the TBDs that have NOT been
2628 * processed. Lagging behind the R index are packets that have
2629 * been processed but have not been freed by the driver.
2631 * In order to free old storage, an internal index will be maintained
2632 * that points to the next packet to be freed. When all used
2633 * packets have been freed, the oldest index will be the same as the
2634 * firmware's read index.
2636 * The OLDEST index is cached in the variable 'priv->tx_queue.oldest'
2638 * Because the TBD structure can not contain arbitrary data, the
2639 * driver must keep an internal queue of cached allocations such that
2640 * it can put that data back into the tx_free_list and msg_free_list
2641 * for use by future command and data packets.
2644 static inline int __ipw2100_tx_process(struct ipw2100_priv *priv)
2646 struct ipw2100_bd_queue *txq = &priv->tx_queue;
2647 struct ipw2100_bd *tbd;
2648 struct list_head *element;
2649 struct ipw2100_tx_packet *packet;
2650 int descriptors_used;
2652 u32 r, w, frag_num = 0;
2654 if (list_empty(&priv->fw_pend_list))
2657 element = priv->fw_pend_list.next;
2659 packet = list_entry(element, struct ipw2100_tx_packet, list);
2660 tbd = &txq->drv[packet->index];
2662 /* Determine how many TBD entries must be finished... */
2663 switch (packet->type) {
2665 /* COMMAND uses only one slot; don't advance */
2666 descriptors_used = 1;
2671 /* DATA uses two slots; advance and loop position. */
2672 descriptors_used = tbd->num_fragments;
2673 frag_num = tbd->num_fragments - 1;
2674 e = txq->oldest + frag_num;
2679 IPW_DEBUG_WARNING("%s: Bad fw_pend_list entry!\n",
2680 priv->net_dev->name);
2684 /* if the last TBD is not done by NIC yet, then packet is
2685 * not ready to be released.
2688 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_TX_QUEUE_READ_INDEX,
2690 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX,
2693 IPW_DEBUG_WARNING("%s: write index mismatch\n",
2694 priv->net_dev->name);
2697 * txq->next is the index of the last packet written txq->oldest is
2698 * the index of the r is the index of the next packet to be read by
2704 * Quick graphic to help you visualize the following
2705 * if / else statement
2707 * ===>| s---->|===============
2709 * | a | b | c | d | e | f | g | h | i | j | k | l
2713 * w - updated by driver
2714 * r - updated by firmware
2715 * s - start of oldest BD entry (txq->oldest)
2716 * e - end of oldest BD entry
2719 if (!((r <= w && (e < r || e >= w)) || (e < r && e >= w))) {
2720 IPW_DEBUG_TX("exit - no processed packets ready to release.\n");
2725 DEC_STAT(&priv->fw_pend_stat);
2727 #ifdef CONFIG_IPW_DEBUG
2729 int i = txq->oldest;
2731 "TX%d V=%p P=%04X T=%04X L=%d\n", i,
2733 (u32)(txq->nic + i * sizeof(struct ipw2100_bd)),
2734 txq->drv[i].host_addr,
2735 txq->drv[i].buf_length);
2737 if (packet->type == DATA) {
2738 i = (i + 1) % txq->entries;
2741 "TX%d V=%p P=%04X T=%04X L=%d\n", i,
2743 (u32)(txq->nic + i *
2744 sizeof(struct ipw2100_bd)),
2745 (u32)txq->drv[i].host_addr,
2746 txq->drv[i].buf_length);
2751 switch (packet->type) {
2753 if (txq->drv[txq->oldest].status.info.fields.txType != 0)
2754 IPW_DEBUG_WARNING("%s: Queue mismatch. "
2755 "Expecting DATA TBD but pulled "
2756 "something else: ids %d=%d.\n",
2757 priv->net_dev->name, txq->oldest, packet->index);
2759 /* DATA packet; we have to unmap and free the SKB */
2760 priv->ieee->stats.tx_packets++;
2761 for (i = 0; i < frag_num; i++) {
2762 tbd = &txq->drv[(packet->index + 1 + i) %
2766 "TX%d P=%08x L=%d\n",
2767 (packet->index + 1 + i) % txq->entries,
2768 tbd->host_addr, tbd->buf_length);
2770 pci_unmap_single(priv->pci_dev,
2776 priv->ieee->stats.tx_bytes += packet->info.d_struct.txb->payload_size;
2777 ieee80211_txb_free(packet->info.d_struct.txb);
2778 packet->info.d_struct.txb = NULL;
2780 list_add_tail(element, &priv->tx_free_list);
2781 INC_STAT(&priv->tx_free_stat);
2783 /* We have a free slot in the Tx queue, so wake up the
2784 * transmit layer if it is stopped. */
2785 if (priv->status & STATUS_ASSOCIATED &&
2786 netif_queue_stopped(priv->net_dev)) {
2787 IPW_DEBUG_INFO(KERN_INFO
2788 "%s: Waking net queue.\n",
2789 priv->net_dev->name);
2790 netif_wake_queue(priv->net_dev);
2793 /* A packet was processed by the hardware, so update the
2795 priv->net_dev->trans_start = jiffies;
2800 if (txq->drv[txq->oldest].status.info.fields.txType != 1)
2801 IPW_DEBUG_WARNING("%s: Queue mismatch. "
2802 "Expecting COMMAND TBD but pulled "
2803 "something else: ids %d=%d.\n",
2804 priv->net_dev->name, txq->oldest, packet->index);
2806 #ifdef CONFIG_IPW_DEBUG
2807 if (packet->info.c_struct.cmd->host_command_reg <
2808 sizeof(command_types) / sizeof(*command_types))
2810 "Command '%s (%d)' processed: %d.\n",
2811 command_types[packet->info.c_struct.cmd->host_command_reg],
2812 packet->info.c_struct.cmd->host_command_reg,
2813 packet->info.c_struct.cmd->cmd_status_reg);
2816 list_add_tail(element, &priv->msg_free_list);
2817 INC_STAT(&priv->msg_free_stat);
2821 /* advance oldest used TBD pointer to start of next entry */
2822 txq->oldest = (e + 1) % txq->entries;
2823 /* increase available TBDs number */
2824 txq->available += descriptors_used;
2825 SET_STAT(&priv->txq_stat, txq->available);
2827 IPW_DEBUG_TX("packet latency (send to process) %ld jiffies\n",
2828 jiffies - packet->jiffy_start);
2830 return (!list_empty(&priv->fw_pend_list));
2834 static inline void __ipw2100_tx_complete(struct ipw2100_priv *priv)
2838 while (__ipw2100_tx_process(priv) && i < 200) i++;
2842 "%s: Driver is running slow (%d iters).\n",
2843 priv->net_dev->name, i);
2848 static void X__ipw2100_tx_send_commands(struct ipw2100_priv *priv)
2850 struct list_head *element;
2851 struct ipw2100_tx_packet *packet;
2852 struct ipw2100_bd_queue *txq = &priv->tx_queue;
2853 struct ipw2100_bd *tbd;
2854 int next = txq->next;
2856 while (!list_empty(&priv->msg_pend_list)) {
2857 /* if there isn't enough space in TBD queue, then
2858 * don't stuff a new one in.
2859 * NOTE: 3 are needed as a command will take one,
2860 * and there is a minimum of 2 that must be
2861 * maintained between the r and w indexes
2863 if (txq->available <= 3) {
2864 IPW_DEBUG_TX("no room in tx_queue\n");
2868 element = priv->msg_pend_list.next;
2870 DEC_STAT(&priv->msg_pend_stat);
2872 packet = list_entry(element,
2873 struct ipw2100_tx_packet, list);
2875 IPW_DEBUG_TX("using TBD at virt=%p, phys=%p\n",
2876 &txq->drv[txq->next],
2877 (void*)(txq->nic + txq->next *
2878 sizeof(struct ipw2100_bd)));
2880 packet->index = txq->next;
2882 tbd = &txq->drv[txq->next];
2884 /* initialize TBD */
2885 tbd->host_addr = packet->info.c_struct.cmd_phys;
2886 tbd->buf_length = sizeof(struct ipw2100_cmd_header);
2887 /* not marking number of fragments causes problems
2888 * with f/w debug version */
2889 tbd->num_fragments = 1;
2890 tbd->status.info.field =
2891 IPW_BD_STATUS_TX_FRAME_COMMAND |
2892 IPW_BD_STATUS_TX_INTERRUPT_ENABLE;
2894 /* update TBD queue counters */
2896 txq->next %= txq->entries;
2898 DEC_STAT(&priv->txq_stat);
2900 list_add_tail(element, &priv->fw_pend_list);
2901 INC_STAT(&priv->fw_pend_stat);
2904 if (txq->next != next) {
2905 /* kick off the DMA by notifying firmware the
2906 * write index has moved; make sure TBD stores are sync'd */
2908 write_register(priv->net_dev,
2909 IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX,
2916 * X__ipw2100_tx_send_data
2919 static void X__ipw2100_tx_send_data(struct ipw2100_priv *priv)
2921 struct list_head *element;
2922 struct ipw2100_tx_packet *packet;
2923 struct ipw2100_bd_queue *txq = &priv->tx_queue;
2924 struct ipw2100_bd *tbd;
2925 int next = txq->next;
2927 struct ipw2100_data_header *ipw_hdr;
2928 struct ieee80211_hdr *hdr;
2930 while (!list_empty(&priv->tx_pend_list)) {
2931 /* if there isn't enough space in TBD queue, then
2932 * don't stuff a new one in.
2933 * NOTE: 4 are needed as a data will take two,
2934 * and there is a minimum of 2 that must be
2935 * maintained between the r and w indexes
2937 element = priv->tx_pend_list.next;
2938 packet = list_entry(element, struct ipw2100_tx_packet, list);
2940 if (unlikely(1 + packet->info.d_struct.txb->nr_frags >
2942 /* TODO: Support merging buffers if more than
2943 * IPW_MAX_BDS are used */
2945 "%s: Maximum BD theshold exceeded. "
2946 "Increase fragmentation level.\n",
2947 priv->net_dev->name);
2950 if (txq->available <= 3 +
2951 packet->info.d_struct.txb->nr_frags) {
2952 IPW_DEBUG_TX("no room in tx_queue\n");
2957 DEC_STAT(&priv->tx_pend_stat);
2959 tbd = &txq->drv[txq->next];
2961 packet->index = txq->next;
2963 ipw_hdr = packet->info.d_struct.data;
2964 hdr = (struct ieee80211_hdr *)packet->info.d_struct.txb->
2967 if (priv->ieee->iw_mode == IW_MODE_INFRA) {
2968 /* To DS: Addr1 = BSSID, Addr2 = SA,
2970 memcpy(ipw_hdr->src_addr, hdr->addr2, ETH_ALEN);
2971 memcpy(ipw_hdr->dst_addr, hdr->addr3, ETH_ALEN);
2972 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
2973 /* not From/To DS: Addr1 = DA, Addr2 = SA,
2975 memcpy(ipw_hdr->src_addr, hdr->addr2, ETH_ALEN);
2976 memcpy(ipw_hdr->dst_addr, hdr->addr1, ETH_ALEN);
2979 ipw_hdr->host_command_reg = SEND;
2980 ipw_hdr->host_command_reg1 = 0;
2982 /* For now we only support host based encryption */
2983 ipw_hdr->needs_encryption = 0;
2984 ipw_hdr->encrypted = packet->info.d_struct.txb->encrypted;
2985 if (packet->info.d_struct.txb->nr_frags > 1)
2986 ipw_hdr->fragment_size =
2987 packet->info.d_struct.txb->frag_size - IEEE80211_3ADDR_LEN;
2989 ipw_hdr->fragment_size = 0;
2991 tbd->host_addr = packet->info.d_struct.data_phys;
2992 tbd->buf_length = sizeof(struct ipw2100_data_header);
2993 tbd->num_fragments = 1 + packet->info.d_struct.txb->nr_frags;
2994 tbd->status.info.field =
2995 IPW_BD_STATUS_TX_FRAME_802_3 |
2996 IPW_BD_STATUS_TX_FRAME_NOT_LAST_FRAGMENT;
2998 txq->next %= txq->entries;
3001 "data header tbd TX%d P=%08x L=%d\n",
3002 packet->index, tbd->host_addr,
3004 #ifdef CONFIG_IPW_DEBUG
3005 if (packet->info.d_struct.txb->nr_frags > 1)
3006 IPW_DEBUG_FRAG("fragment Tx: %d frames\n",
3007 packet->info.d_struct.txb->nr_frags);
3010 for (i = 0; i < packet->info.d_struct.txb->nr_frags; i++) {
3011 tbd = &txq->drv[txq->next];
3012 if (i == packet->info.d_struct.txb->nr_frags - 1)
3013 tbd->status.info.field =
3014 IPW_BD_STATUS_TX_FRAME_802_3 |
3015 IPW_BD_STATUS_TX_INTERRUPT_ENABLE;
3017 tbd->status.info.field =
3018 IPW_BD_STATUS_TX_FRAME_802_3 |
3019 IPW_BD_STATUS_TX_FRAME_NOT_LAST_FRAGMENT;
3021 tbd->buf_length = packet->info.d_struct.txb->
3022 fragments[i]->len - IEEE80211_3ADDR_LEN;
3024 tbd->host_addr = pci_map_single(
3026 packet->info.d_struct.txb->fragments[i]->data +
3027 IEEE80211_3ADDR_LEN,
3032 "data frag tbd TX%d P=%08x L=%d\n",
3033 txq->next, tbd->host_addr, tbd->buf_length);
3035 pci_dma_sync_single_for_device(
3036 priv->pci_dev, tbd->host_addr,
3041 txq->next %= txq->entries;
3044 txq->available -= 1 + packet->info.d_struct.txb->nr_frags;
3045 SET_STAT(&priv->txq_stat, txq->available);
3047 list_add_tail(element, &priv->fw_pend_list);
3048 INC_STAT(&priv->fw_pend_stat);
3051 if (txq->next != next) {
3052 /* kick off the DMA by notifying firmware the
3053 * write index has moved; make sure TBD stores are sync'd */
3054 write_register(priv->net_dev,
3055 IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX,
3061 static void ipw2100_irq_tasklet(struct ipw2100_priv *priv)
3063 struct net_device *dev = priv->net_dev;
3064 unsigned long flags;
3067 spin_lock_irqsave(&priv->low_lock, flags);
3068 ipw2100_disable_interrupts(priv);
3070 read_register(dev, IPW_REG_INTA, &inta);
3072 IPW_DEBUG_ISR("enter - INTA: 0x%08lX\n",
3073 (unsigned long)inta & IPW_INTERRUPT_MASK);
3078 /* We do not loop and keep polling for more interrupts as this
3079 * is frowned upon and doesn't play nicely with other potentially
3081 IPW_DEBUG_ISR("INTA: 0x%08lX\n",
3082 (unsigned long)inta & IPW_INTERRUPT_MASK);
3084 if (inta & IPW2100_INTA_FATAL_ERROR) {
3085 IPW_DEBUG_WARNING(DRV_NAME
3086 ": Fatal interrupt. Scheduling firmware restart.\n");
3090 IPW2100_INTA_FATAL_ERROR);
3092 read_nic_dword(dev, IPW_NIC_FATAL_ERROR, &priv->fatal_error);
3093 IPW_DEBUG_INFO("%s: Fatal error value: 0x%08X\n",
3094 priv->net_dev->name, priv->fatal_error);
3096 read_nic_dword(dev, IPW_ERROR_ADDR(priv->fatal_error), &tmp);
3097 IPW_DEBUG_INFO("%s: Fatal error address value: 0x%08X\n",
3098 priv->net_dev->name, tmp);
3100 /* Wake up any sleeping jobs */
3101 schedule_reset(priv);
3104 if (inta & IPW2100_INTA_PARITY_ERROR) {
3105 IPW_DEBUG_ERROR("***** PARITY ERROR INTERRUPT !!!! \n");
3109 IPW2100_INTA_PARITY_ERROR);
3112 if (inta & IPW2100_INTA_RX_TRANSFER) {
3113 IPW_DEBUG_ISR("RX interrupt\n");
3115 priv->rx_interrupts++;
3119 IPW2100_INTA_RX_TRANSFER);
3121 __ipw2100_rx_process(priv);
3122 __ipw2100_tx_complete(priv);
3125 if (inta & IPW2100_INTA_TX_TRANSFER) {
3126 IPW_DEBUG_ISR("TX interrupt\n");
3128 priv->tx_interrupts++;
3130 write_register(dev, IPW_REG_INTA,
3131 IPW2100_INTA_TX_TRANSFER);
3133 __ipw2100_tx_complete(priv);
3134 X__ipw2100_tx_send_commands(priv);
3135 X__ipw2100_tx_send_data(priv);
3138 if (inta & IPW2100_INTA_TX_COMPLETE) {
3139 IPW_DEBUG_ISR("TX complete\n");
3143 IPW2100_INTA_TX_COMPLETE);
3145 __ipw2100_tx_complete(priv);
3148 if (inta & IPW2100_INTA_EVENT_INTERRUPT) {
3149 /* ipw2100_handle_event(dev); */
3153 IPW2100_INTA_EVENT_INTERRUPT);
3156 if (inta & IPW2100_INTA_FW_INIT_DONE) {
3157 IPW_DEBUG_ISR("FW init done interrupt\n");
3160 read_register(dev, IPW_REG_INTA, &tmp);
3161 if (tmp & (IPW2100_INTA_FATAL_ERROR |
3162 IPW2100_INTA_PARITY_ERROR)) {
3165 IPW2100_INTA_FATAL_ERROR |
3166 IPW2100_INTA_PARITY_ERROR);
3169 write_register(dev, IPW_REG_INTA,
3170 IPW2100_INTA_FW_INIT_DONE);
3173 if (inta & IPW2100_INTA_STATUS_CHANGE) {
3174 IPW_DEBUG_ISR("Status change interrupt\n");
3178 IPW2100_INTA_STATUS_CHANGE);
3181 if (inta & IPW2100_INTA_SLAVE_MODE_HOST_COMMAND_DONE) {
3182 IPW_DEBUG_ISR("slave host mode interrupt\n");
3186 IPW2100_INTA_SLAVE_MODE_HOST_COMMAND_DONE);
3190 ipw2100_enable_interrupts(priv);
3192 spin_unlock_irqrestore(&priv->low_lock, flags);
3194 IPW_DEBUG_ISR("exit\n");
3198 static irqreturn_t ipw2100_interrupt(int irq, void *data,
3199 struct pt_regs *regs)
3201 struct ipw2100_priv *priv = data;
3202 u32 inta, inta_mask;
3207 spin_lock(&priv->low_lock);
3209 /* We check to see if we should be ignoring interrupts before
3210 * we touch the hardware. During ucode load if we try and handle
3211 * an interrupt we can cause keyboard problems as well as cause
3212 * the ucode to fail to initialize */
3213 if (!(priv->status & STATUS_INT_ENABLED)) {
3218 read_register(priv->net_dev, IPW_REG_INTA_MASK, &inta_mask);
3219 read_register(priv->net_dev, IPW_REG_INTA, &inta);
3221 if (inta == 0xFFFFFFFF) {
3222 /* Hardware disappeared */
3223 IPW_DEBUG_WARNING("IRQ INTA == 0xFFFFFFFF\n");
3227 inta &= IPW_INTERRUPT_MASK;
3229 if (!(inta & inta_mask)) {
3230 /* Shared interrupt */
3234 /* We disable the hardware interrupt here just to prevent unneeded
3235 * calls to be made. We disable this again within the actual
3236 * work tasklet, so if another part of the code re-enables the
3237 * interrupt, that is fine */
3238 ipw2100_disable_interrupts(priv);
3240 tasklet_schedule(&priv->irq_tasklet);
3241 spin_unlock(&priv->low_lock);
3245 spin_unlock(&priv->low_lock);
3249 static int ipw2100_tx(struct ieee80211_txb *txb, struct net_device *dev)
3251 struct ipw2100_priv *priv = ieee80211_priv(dev);
3252 struct list_head *element;
3253 struct ipw2100_tx_packet *packet;
3254 unsigned long flags;
3256 spin_lock_irqsave(&priv->low_lock, flags);
3258 if (!(priv->status & STATUS_ASSOCIATED)) {
3259 IPW_DEBUG_INFO("Can not transmit when not connected.\n");
3260 priv->ieee->stats.tx_carrier_errors++;
3261 netif_stop_queue(dev);
3265 if (list_empty(&priv->tx_free_list))
3268 element = priv->tx_free_list.next;
3269 packet = list_entry(element, struct ipw2100_tx_packet, list);
3271 packet->info.d_struct.txb = txb;
3273 IPW_DEBUG_TX("Sending fragment (%d bytes):\n",
3274 txb->fragments[0]->len);
3275 printk_buf(IPW_DL_TX, txb->fragments[0]->data,
3276 txb->fragments[0]->len);
3278 packet->jiffy_start = jiffies;
3281 DEC_STAT(&priv->tx_free_stat);
3283 list_add_tail(element, &priv->tx_pend_list);
3284 INC_STAT(&priv->tx_pend_stat);
3286 X__ipw2100_tx_send_data(priv);
3288 spin_unlock_irqrestore(&priv->low_lock, flags);
3292 netif_stop_queue(dev);
3293 spin_unlock_irqrestore(&priv->low_lock, flags);
3298 static int ipw2100_msg_allocate(struct ipw2100_priv *priv)
3300 int i, j, err = -EINVAL;
3304 priv->msg_buffers = (struct ipw2100_tx_packet *)kmalloc(
3305 IPW_COMMAND_POOL_SIZE * sizeof(struct ipw2100_tx_packet),
3307 if (!priv->msg_buffers) {
3308 IPW_DEBUG_ERROR("%s: PCI alloc failed for msg "
3309 "buffers.\n", priv->net_dev->name);
3313 for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++) {
3314 v = pci_alloc_consistent(
3316 sizeof(struct ipw2100_cmd_header),
3320 "%s: PCI alloc failed for msg "
3322 priv->net_dev->name);
3327 memset(v, 0, sizeof(struct ipw2100_cmd_header));
3329 priv->msg_buffers[i].type = COMMAND;
3330 priv->msg_buffers[i].info.c_struct.cmd =
3331 (struct ipw2100_cmd_header*)v;
3332 priv->msg_buffers[i].info.c_struct.cmd_phys = p;
3335 if (i == IPW_COMMAND_POOL_SIZE)
3338 for (j = 0; j < i; j++) {
3339 pci_free_consistent(
3341 sizeof(struct ipw2100_cmd_header),
3342 priv->msg_buffers[j].info.c_struct.cmd,
3343 priv->msg_buffers[j].info.c_struct.cmd_phys);
3346 kfree(priv->msg_buffers);
3347 priv->msg_buffers = NULL;
3352 static int ipw2100_msg_initialize(struct ipw2100_priv *priv)
3356 INIT_LIST_HEAD(&priv->msg_free_list);
3357 INIT_LIST_HEAD(&priv->msg_pend_list);
3359 for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++)
3360 list_add_tail(&priv->msg_buffers[i].list, &priv->msg_free_list);
3361 SET_STAT(&priv->msg_free_stat, i);
3366 static void ipw2100_msg_free(struct ipw2100_priv *priv)
3370 if (!priv->msg_buffers)
3373 for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++) {
3374 pci_free_consistent(priv->pci_dev,
3375 sizeof(struct ipw2100_cmd_header),
3376 priv->msg_buffers[i].info.c_struct.cmd,
3377 priv->msg_buffers[i].info.c_struct.cmd_phys);
3380 kfree(priv->msg_buffers);
3381 priv->msg_buffers = NULL;
3384 static ssize_t show_pci(struct device *d, char *buf)
3386 struct pci_dev *pci_dev = container_of(d, struct pci_dev, dev);
3391 for (i = 0; i < 16; i++) {
3392 out += sprintf(out, "[%08X] ", i * 16);
3393 for (j = 0; j < 16; j += 4) {
3394 pci_read_config_dword(pci_dev, i * 16 + j, &val);
3395 out += sprintf(out, "%08X ", val);
3397 out += sprintf(out, "\n");
3402 static DEVICE_ATTR(pci, S_IRUGO, show_pci, NULL);
3404 static ssize_t show_cfg(struct device *d, char *buf)
3406 struct ipw2100_priv *p = (struct ipw2100_priv *)d->driver_data;
3407 return sprintf(buf, "0x%08x\n", (int)p->config);
3409 static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
3411 static ssize_t show_status(struct device *d, char *buf)
3413 struct ipw2100_priv *p = (struct ipw2100_priv *)d->driver_data;
3414 return sprintf(buf, "0x%08x\n", (int)p->status);
3416 static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
3418 static ssize_t show_capability(struct device *d, char *buf)
3420 struct ipw2100_priv *p = (struct ipw2100_priv *)d->driver_data;
3421 return sprintf(buf, "0x%08x\n", (int)p->capability);
3423 static DEVICE_ATTR(capability, S_IRUGO, show_capability, NULL);
3426 #define IPW2100_REG(x) { IPW_ ##x, #x }
3431 IPW2100_REG(REG_GP_CNTRL),
3432 IPW2100_REG(REG_GPIO),
3433 IPW2100_REG(REG_INTA),
3434 IPW2100_REG(REG_INTA_MASK),
3435 IPW2100_REG(REG_RESET_REG),
3437 #define IPW2100_NIC(x, s) { x, #x, s }
3443 IPW2100_NIC(IPW2100_CONTROL_REG, 2),
3444 IPW2100_NIC(0x210014, 1),
3445 IPW2100_NIC(0x210000, 1),
3447 #define IPW2100_ORD(x, d) { IPW_ORD_ ##x, #x, d }
3453 IPW2100_ORD(STAT_TX_HOST_REQUESTS, "requested Host Tx's (MSDU)"),
3454 IPW2100_ORD(STAT_TX_HOST_COMPLETE, "successful Host Tx's (MSDU)"),
3455 IPW2100_ORD(STAT_TX_DIR_DATA, "successful Directed Tx's (MSDU)"),
3456 IPW2100_ORD(STAT_TX_DIR_DATA1, "successful Directed Tx's (MSDU) @ 1MB"),
3457 IPW2100_ORD(STAT_TX_DIR_DATA2, "successful Directed Tx's (MSDU) @ 2MB"),
3458 IPW2100_ORD(STAT_TX_DIR_DATA5_5, "successful Directed Tx's (MSDU) @ 5_5MB"),
3459 IPW2100_ORD(STAT_TX_DIR_DATA11, "successful Directed Tx's (MSDU) @ 11MB"),
3460 IPW2100_ORD(STAT_TX_NODIR_DATA1, "successful Non_Directed Tx's (MSDU) @ 1MB"),
3461 IPW2100_ORD(STAT_TX_NODIR_DATA2, "successful Non_Directed Tx's (MSDU) @ 2MB"),
3462 IPW2100_ORD(STAT_TX_NODIR_DATA5_5, "successful Non_Directed Tx's (MSDU) @ 5.5MB"),
3463 IPW2100_ORD(STAT_TX_NODIR_DATA11, "successful Non_Directed Tx's (MSDU) @ 11MB"),
3464 IPW2100_ORD(STAT_NULL_DATA, "successful NULL data Tx's"),
3465 IPW2100_ORD(STAT_TX_RTS, "successful Tx RTS"),
3466 IPW2100_ORD(STAT_TX_CTS, "successful Tx CTS"),
3467 IPW2100_ORD(STAT_TX_ACK, "successful Tx ACK"),
3468 IPW2100_ORD(STAT_TX_ASSN, "successful Association Tx's"),
3469 IPW2100_ORD(STAT_TX_ASSN_RESP, "successful Association response Tx's"),
3470 IPW2100_ORD(STAT_TX_REASSN, "successful Reassociation Tx's"),
3471 IPW2100_ORD(STAT_TX_REASSN_RESP, "successful Reassociation response Tx's"),
3472 IPW2100_ORD(STAT_TX_PROBE, "probes successfully transmitted"),
3473 IPW2100_ORD(STAT_TX_PROBE_RESP, "probe responses successfully transmitted"),
3474 IPW2100_ORD(STAT_TX_BEACON, "tx beacon"),
3475 IPW2100_ORD(STAT_TX_ATIM, "Tx ATIM"),
3476 IPW2100_ORD(STAT_TX_DISASSN, "successful Disassociation TX"),
3477 IPW2100_ORD(STAT_TX_AUTH, "successful Authentication Tx"),
3478 IPW2100_ORD(STAT_TX_DEAUTH, "successful Deauthentication TX"),
3479 IPW2100_ORD(STAT_TX_TOTAL_BYTES, "Total successful Tx data bytes"),
3480 IPW2100_ORD(STAT_TX_RETRIES, "Tx retries"),
3481 IPW2100_ORD(STAT_TX_RETRY1, "Tx retries at 1MBPS"),
3482 IPW2100_ORD(STAT_TX_RETRY2, "Tx retries at 2MBPS"),
3483 IPW2100_ORD(STAT_TX_RETRY5_5, "Tx retries at 5.5MBPS"),
3484 IPW2100_ORD(STAT_TX_RETRY11, "Tx retries at 11MBPS"),
3485 IPW2100_ORD(STAT_TX_FAILURES, "Tx Failures"),
3486 IPW2100_ORD(STAT_TX_MAX_TRIES_IN_HOP,"times max tries in a hop failed"),
3487 IPW2100_ORD(STAT_TX_DISASSN_FAIL, "times disassociation failed"),
3488 IPW2100_ORD(STAT_TX_ERR_CTS, "missed/bad CTS frames"),
3489 IPW2100_ORD(STAT_TX_ERR_ACK, "tx err due to acks"),
3490 IPW2100_ORD(STAT_RX_HOST, "packets passed to host"),
3491 IPW2100_ORD(STAT_RX_DIR_DATA, "directed packets"),
3492 IPW2100_ORD(STAT_RX_DIR_DATA1, "directed packets at 1MB"),
3493 IPW2100_ORD(STAT_RX_DIR_DATA2, "directed packets at 2MB"),
3494 IPW2100_ORD(STAT_RX_DIR_DATA5_5, "directed packets at 5.5MB"),
3495 IPW2100_ORD(STAT_RX_DIR_DATA11, "directed packets at 11MB"),
3496 IPW2100_ORD(STAT_RX_NODIR_DATA,"nondirected packets"),
3497 IPW2100_ORD(STAT_RX_NODIR_DATA1, "nondirected packets at 1MB"),
3498 IPW2100_ORD(STAT_RX_NODIR_DATA2, "nondirected packets at 2MB"),
3499 IPW2100_ORD(STAT_RX_NODIR_DATA5_5, "nondirected packets at 5.5MB"),
3500 IPW2100_ORD(STAT_RX_NODIR_DATA11, "nondirected packets at 11MB"),
3501 IPW2100_ORD(STAT_RX_NULL_DATA, "null data rx's"),
3502 IPW2100_ORD(STAT_RX_RTS, "Rx RTS"),
3503 IPW2100_ORD(STAT_RX_CTS, "Rx CTS"),
3504 IPW2100_ORD(STAT_RX_ACK, "Rx ACK"),
3505 IPW2100_ORD(STAT_RX_CFEND, "Rx CF End"),
3506 IPW2100_ORD(STAT_RX_CFEND_ACK, "Rx CF End + CF Ack"),
3507 IPW2100_ORD(STAT_RX_ASSN, "Association Rx's"),
3508 IPW2100_ORD(STAT_RX_ASSN_RESP, "Association response Rx's"),
3509 IPW2100_ORD(STAT_RX_REASSN, "Reassociation Rx's"),
3510 IPW2100_ORD(STAT_RX_REASSN_RESP, "Reassociation response Rx's"),
3511 IPW2100_ORD(STAT_RX_PROBE, "probe Rx's"),
3512 IPW2100_ORD(STAT_RX_PROBE_RESP, "probe response Rx's"),
3513 IPW2100_ORD(STAT_RX_BEACON, "Rx beacon"),
3514 IPW2100_ORD(STAT_RX_ATIM, "Rx ATIM"),
3515 IPW2100_ORD(STAT_RX_DISASSN, "disassociation Rx"),
3516 IPW2100_ORD(STAT_RX_AUTH, "authentication Rx"),
3517 IPW2100_ORD(STAT_RX_DEAUTH, "deauthentication Rx"),
3518 IPW2100_ORD(STAT_RX_TOTAL_BYTES,"Total rx data bytes received"),
3519 IPW2100_ORD(STAT_RX_ERR_CRC, "packets with Rx CRC error"),
3520 IPW2100_ORD(STAT_RX_ERR_CRC1, "Rx CRC errors at 1MB"),
3521 IPW2100_ORD(STAT_RX_ERR_CRC2, "Rx CRC errors at 2MB"),
3522 IPW2100_ORD(STAT_RX_ERR_CRC5_5, "Rx CRC errors at 5.5MB"),
3523 IPW2100_ORD(STAT_RX_ERR_CRC11, "Rx CRC errors at 11MB"),
3524 IPW2100_ORD(STAT_RX_DUPLICATE1, "duplicate rx packets at 1MB"),
3525 IPW2100_ORD(STAT_RX_DUPLICATE2, "duplicate rx packets at 2MB"),
3526 IPW2100_ORD(STAT_RX_DUPLICATE5_5, "duplicate rx packets at 5.5MB"),
3527 IPW2100_ORD(STAT_RX_DUPLICATE11, "duplicate rx packets at 11MB"),
3528 IPW2100_ORD(STAT_RX_DUPLICATE, "duplicate rx packets"),
3529 IPW2100_ORD(PERS_DB_LOCK, "locking fw permanent db"),
3530 IPW2100_ORD(PERS_DB_SIZE, "size of fw permanent db"),
3531 IPW2100_ORD(PERS_DB_ADDR, "address of fw permanent db"),
3532 IPW2100_ORD(STAT_RX_INVALID_PROTOCOL, "rx frames with invalid protocol"),
3533 IPW2100_ORD(SYS_BOOT_TIME, "Boot time"),
3534 IPW2100_ORD(STAT_RX_NO_BUFFER, "rx frames rejected due to no buffer"),
3535 IPW2100_ORD(STAT_RX_MISSING_FRAG, "rx frames dropped due to missing fragment"),
3536 IPW2100_ORD(STAT_RX_ORPHAN_FRAG, "rx frames dropped due to non-sequential fragment"),
3537 IPW2100_ORD(STAT_RX_ORPHAN_FRAME, "rx frames dropped due to unmatched 1st frame"),
3538 IPW2100_ORD(STAT_RX_FRAG_AGEOUT, "rx frames dropped due to uncompleted frame"),
3539 IPW2100_ORD(STAT_RX_ICV_ERRORS, "ICV errors during decryption"),
3540 IPW2100_ORD(STAT_PSP_SUSPENSION,"times adapter suspended"),
3541 IPW2100_ORD(STAT_PSP_BCN_TIMEOUT, "beacon timeout"),
3542 IPW2100_ORD(STAT_PSP_POLL_TIMEOUT, "poll response timeouts"),
3543 IPW2100_ORD(STAT_PSP_NONDIR_TIMEOUT, "timeouts waiting for last {broad,multi}cast pkt"),
3544 IPW2100_ORD(STAT_PSP_RX_DTIMS, "PSP DTIMs received"),
3545 IPW2100_ORD(STAT_PSP_RX_TIMS, "PSP TIMs received"),
3546 IPW2100_ORD(STAT_PSP_STATION_ID,"PSP Station ID"),
3547 IPW2100_ORD(LAST_ASSN_TIME, "RTC time of last association"),
3548 IPW2100_ORD(STAT_PERCENT_MISSED_BCNS,"current calculation of % missed beacons"),
3549 IPW2100_ORD(STAT_PERCENT_RETRIES,"current calculation of % missed tx retries"),
3550 IPW2100_ORD(ASSOCIATED_AP_PTR, "0 if not associated, else pointer to AP table entry"),
3551 IPW2100_ORD(AVAILABLE_AP_CNT, "AP's decsribed in the AP table"),
3552 IPW2100_ORD(AP_LIST_PTR, "Ptr to list of available APs"),
3553 IPW2100_ORD(STAT_AP_ASSNS, "associations"),
3554 IPW2100_ORD(STAT_ASSN_FAIL, "association failures"),
3555 IPW2100_ORD(STAT_ASSN_RESP_FAIL,"failures due to response fail"),
3556 IPW2100_ORD(STAT_FULL_SCANS, "full scans"),
3557 IPW2100_ORD(CARD_DISABLED, "Card Disabled"),
3558 IPW2100_ORD(STAT_ROAM_INHIBIT, "times roaming was inhibited due to activity"),
3559 IPW2100_ORD(RSSI_AT_ASSN, "RSSI of associated AP at time of association"),
3560 IPW2100_ORD(STAT_ASSN_CAUSE1, "reassociation: no probe response or TX on hop"),
3561 IPW2100_ORD(STAT_ASSN_CAUSE2, "reassociation: poor tx/rx quality"),
3562 IPW2100_ORD(STAT_ASSN_CAUSE3, "reassociation: tx/rx quality (excessive AP load"),
3563 IPW2100_ORD(STAT_ASSN_CAUSE4, "reassociation: AP RSSI level"),
3564 IPW2100_ORD(STAT_ASSN_CAUSE5, "reassociations due to load leveling"),
3565 IPW2100_ORD(STAT_AUTH_FAIL, "times authentication failed"),
3566 IPW2100_ORD(STAT_AUTH_RESP_FAIL,"times authentication response failed"),
3567 IPW2100_ORD(STATION_TABLE_CNT, "entries in association table"),
3568 IPW2100_ORD(RSSI_AVG_CURR, "Current avg RSSI"),
3569 IPW2100_ORD(POWER_MGMT_MODE, "Power mode - 0=CAM, 1=PSP"),
3570 IPW2100_ORD(COUNTRY_CODE, "IEEE country code as recv'd from beacon"),
3571 IPW2100_ORD(COUNTRY_CHANNELS, "channels suported by country"),
3572 IPW2100_ORD(RESET_CNT, "adapter resets (warm)"),
3573 IPW2100_ORD(BEACON_INTERVAL, "Beacon interval"),
3574 IPW2100_ORD(ANTENNA_DIVERSITY, "TRUE if antenna diversity is disabled"),
3575 IPW2100_ORD(DTIM_PERIOD, "beacon intervals between DTIMs"),
3576 IPW2100_ORD(OUR_FREQ, "current radio freq lower digits - channel ID"),
3577 IPW2100_ORD(RTC_TIME, "current RTC time"),
3578 IPW2100_ORD(PORT_TYPE, "operating mode"),
3579 IPW2100_ORD(CURRENT_TX_RATE, "current tx rate"),
3580 IPW2100_ORD(SUPPORTED_RATES, "supported tx rates"),
3581 IPW2100_ORD(ATIM_WINDOW, "current ATIM Window"),
3582 IPW2100_ORD(BASIC_RATES, "basic tx rates"),
3583 IPW2100_ORD(NIC_HIGHEST_RATE, "NIC highest tx rate"),
3584 IPW2100_ORD(AP_HIGHEST_RATE, "AP highest tx rate"),
3585 IPW2100_ORD(CAPABILITIES, "Management frame capability field"),
3586 IPW2100_ORD(AUTH_TYPE, "Type of authentication"),
3587 IPW2100_ORD(RADIO_TYPE, "Adapter card platform type"),
3588 IPW2100_ORD(RTS_THRESHOLD, "Min packet length for RTS handshaking"),
3589 IPW2100_ORD(INT_MODE, "International mode"),
3590 IPW2100_ORD(FRAGMENTATION_THRESHOLD, "protocol frag threshold"),
3591 IPW2100_ORD(EEPROM_SRAM_DB_BLOCK_START_ADDRESS, "EEPROM offset in SRAM"),
3592 IPW2100_ORD(EEPROM_SRAM_DB_BLOCK_SIZE, "EEPROM size in SRAM"),
3593 IPW2100_ORD(EEPROM_SKU_CAPABILITY, "EEPROM SKU Capability"),
3594 IPW2100_ORD(EEPROM_IBSS_11B_CHANNELS, "EEPROM IBSS 11b channel set"),
3595 IPW2100_ORD(MAC_VERSION, "MAC Version"),
3596 IPW2100_ORD(MAC_REVISION, "MAC Revision"),
3597 IPW2100_ORD(RADIO_VERSION, "Radio Version"),
3598 IPW2100_ORD(NIC_MANF_DATE_TIME, "MANF Date/Time STAMP"),
3599 IPW2100_ORD(UCODE_VERSION, "Ucode Version"),
3603 static ssize_t show_registers(struct device *d, char *buf)
3606 struct ipw2100_priv *priv = dev_get_drvdata(d);
3607 struct net_device *dev = priv->net_dev;
3611 out += sprintf(out, "%30s [Address ] : Hex\n", "Register");
3613 for (i = 0; i < (sizeof(hw_data) / sizeof(*hw_data)); i++) {
3614 read_register(dev, hw_data[i].addr, &val);
3615 out += sprintf(out, "%30s [%08X] : %08X\n",
3616 hw_data[i].name, hw_data[i].addr, val);
3621 static DEVICE_ATTR(registers, S_IRUGO, show_registers, NULL);
3624 static ssize_t show_hardware(struct device *d, char *buf)
3626 struct ipw2100_priv *priv = dev_get_drvdata(d);
3627 struct net_device *dev = priv->net_dev;
3631 out += sprintf(out, "%30s [Address ] : Hex\n", "NIC entry");
3633 for (i = 0; i < (sizeof(nic_data) / sizeof(*nic_data)); i++) {
3638 switch (nic_data[i].size) {
3640 read_nic_byte(dev, nic_data[i].addr, &tmp8);
3641 out += sprintf(out, "%30s [%08X] : %02X\n",
3642 nic_data[i].name, nic_data[i].addr,
3646 read_nic_word(dev, nic_data[i].addr, &tmp16);
3647 out += sprintf(out, "%30s [%08X] : %04X\n",
3648 nic_data[i].name, nic_data[i].addr,
3652 read_nic_dword(dev, nic_data[i].addr, &tmp32);
3653 out += sprintf(out, "%30s [%08X] : %08X\n",
3654 nic_data[i].name, nic_data[i].addr,
3661 static DEVICE_ATTR(hardware, S_IRUGO, show_hardware, NULL);
3664 static ssize_t show_memory(struct device *d, char *buf)
3666 struct ipw2100_priv *priv = dev_get_drvdata(d);
3667 struct net_device *dev = priv->net_dev;
3668 static unsigned long loop = 0;
3674 if (loop >= 0x30000)
3677 /* sysfs provides us PAGE_SIZE buffer */
3678 while (len < PAGE_SIZE - 128 && loop < 0x30000) {
3680 if (priv->snapshot[0]) for (i = 0; i < 4; i++)
3681 buffer[i] = *(u32 *)SNAPSHOT_ADDR(loop + i * 4);
3682 else for (i = 0; i < 4; i++)
3683 read_nic_dword(dev, loop + i * 4, &buffer[i]);
3686 len += sprintf(buf + len,
3706 ((u8*)buffer)[0xf]);
3708 len += sprintf(buf + len, "%s\n",
3709 snprint_line(line, sizeof(line),
3710 (u8*)buffer, 16, loop));
3717 static ssize_t store_memory(struct device *d, const char *buf, size_t count)
3719 struct ipw2100_priv *priv = dev_get_drvdata(d);
3720 struct net_device *dev = priv->net_dev;
3721 const char *p = buf;
3727 (count >= 2 && tolower(p[0]) == 'o' && tolower(p[1]) == 'n')) {
3728 IPW_DEBUG_INFO("%s: Setting memory dump to RAW mode.\n",
3732 } else if (p[0] == '0' || (count >= 2 && tolower(p[0]) == 'o' &&
3733 tolower(p[1]) == 'f')) {
3734 IPW_DEBUG_INFO("%s: Setting memory dump to HEX mode.\n",
3738 } else if (tolower(p[0]) == 'r') {
3739 IPW_DEBUG_INFO("%s: Resetting firmware snapshot.\n",
3741 ipw2100_snapshot_free(priv);
3744 IPW_DEBUG_INFO("%s: Usage: 0|on = HEX, 1|off = RAW, "
3745 "reset = clear memory snapshot\n",
3750 static DEVICE_ATTR(memory, S_IWUSR|S_IRUGO, show_memory, store_memory);
3753 static ssize_t show_ordinals(struct device *d, char *buf)
3755 struct ipw2100_priv *priv = dev_get_drvdata(d);
3759 static int loop = 0;
3761 if (loop >= sizeof(ord_data) / sizeof(*ord_data))
3764 /* sysfs provides us PAGE_SIZE buffer */
3765 while (len < PAGE_SIZE - 128 &&
3766 loop < (sizeof(ord_data) / sizeof(*ord_data))) {
3768 val_len = sizeof(u32);
3770 if (ipw2100_get_ordinal(priv, ord_data[loop].index, &val,
3772 len += sprintf(buf + len, "[0x%02X] = ERROR %s\n",
3773 ord_data[loop].index,
3774 ord_data[loop].desc);
3776 len += sprintf(buf + len, "[0x%02X] = 0x%08X %s\n",
3777 ord_data[loop].index, val,
3778 ord_data[loop].desc);
3784 static DEVICE_ATTR(ordinals, S_IRUGO, show_ordinals, NULL);
3787 static ssize_t show_stats(struct device *d, char *buf)
3789 struct ipw2100_priv *priv = dev_get_drvdata(d);
3792 out += sprintf(out, "interrupts: %d {tx: %d, rx: %d, other: %d}\n",
3793 priv->interrupts, priv->tx_interrupts,
3794 priv->rx_interrupts, priv->inta_other);
3795 out += sprintf(out, "firmware resets: %d\n", priv->resets);
3796 out += sprintf(out, "firmware hangs: %d\n", priv->hangs);
3797 #ifdef CONFIG_IPW_DEBUG
3798 out += sprintf(out, "packet mismatch image: %s\n",
3799 priv->snapshot[0] ? "YES" : "NO");
3804 static DEVICE_ATTR(stats, S_IRUGO, show_stats, NULL);
3807 int ipw2100_switch_mode(struct ipw2100_priv *priv, u32 mode)
3811 if (mode == priv->ieee->iw_mode)
3814 err = ipw2100_disable_adapter(priv);
3816 IPW_DEBUG_ERROR("%s: Could not disable adapter %d\n",
3817 priv->net_dev->name, err);
3823 priv->net_dev->type = ARPHRD_ETHER;
3826 priv->net_dev->type = ARPHRD_ETHER;
3828 #ifdef CONFIG_IPW2100_MONITOR
3829 case IW_MODE_MONITOR:
3830 priv->last_mode = priv->ieee->iw_mode;
3831 priv->net_dev->type = ARPHRD_IEEE80211;
3833 #endif /* CONFIG_IPW2100_MONITOR */
3836 priv->ieee->iw_mode = mode;
3839 /* Indicate ipw2100_download_firmware download firmware
3840 * from disk instead of memory. */
3841 ipw2100_firmware.version = 0;
3844 printk(KERN_INFO "%s: Reseting on mode change.\n",
3845 priv->net_dev->name);
3846 priv->reset_backoff = 0;
3847 schedule_reset(priv);
3852 static ssize_t show_internals(struct device *d, char *buf)
3854 struct ipw2100_priv *priv = dev_get_drvdata(d);
3857 #define DUMP_VAR(x,y) len += sprintf(buf + len, # x ": %" # y "\n", priv-> x)
3859 if (priv->status & STATUS_ASSOCIATED)
3860 len += sprintf(buf + len, "connected: %lu\n",
3861 get_seconds() - priv->connect_start);
3863 len += sprintf(buf + len, "not connected\n");
3865 DUMP_VAR(ieee->crypt[priv->ieee->tx_keyidx], p);
3866 DUMP_VAR(status, 08lx);
3867 DUMP_VAR(config, 08lx);
3868 DUMP_VAR(capability, 08lx);
3870 len += sprintf(buf + len, "last_rtc: %lu\n", (unsigned long)priv->last_rtc);
3872 DUMP_VAR(fatal_error, d);
3873 DUMP_VAR(stop_hang_check, d);
3874 DUMP_VAR(stop_rf_kill, d);
3875 DUMP_VAR(messages_sent, d);
3877 DUMP_VAR(tx_pend_stat.value, d);
3878 DUMP_VAR(tx_pend_stat.hi, d);
3880 DUMP_VAR(tx_free_stat.value, d);
3881 DUMP_VAR(tx_free_stat.lo, d);
3883 DUMP_VAR(msg_free_stat.value, d);
3884 DUMP_VAR(msg_free_stat.lo, d);
3886 DUMP_VAR(msg_pend_stat.value, d);
3887 DUMP_VAR(msg_pend_stat.hi, d);
3889 DUMP_VAR(fw_pend_stat.value, d);
3890 DUMP_VAR(fw_pend_stat.hi, d);
3892 DUMP_VAR(txq_stat.value, d);
3893 DUMP_VAR(txq_stat.lo, d);
3895 DUMP_VAR(ieee->scans, d);
3896 DUMP_VAR(reset_backoff, d);
3900 static DEVICE_ATTR(internals, S_IRUGO, show_internals, NULL);
3903 static ssize_t show_bssinfo(struct device *d, char *buf)
3905 struct ipw2100_priv *priv = dev_get_drvdata(d);
3906 char essid[IW_ESSID_MAX_SIZE + 1];
3913 memset(essid, 0, sizeof(essid));
3914 memset(bssid, 0, sizeof(bssid));
3916 length = IW_ESSID_MAX_SIZE;
3917 ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_SSID, essid, &length);
3919 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
3922 length = sizeof(bssid);
3923 ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID,
3926 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
3929 length = sizeof(u32);
3930 ret = ipw2100_get_ordinal(priv, IPW_ORD_OUR_FREQ, &chan, &length);
3932 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
3935 out += sprintf(out, "ESSID: %s\n", essid);
3936 out += sprintf(out, "BSSID: %02x:%02x:%02x:%02x:%02x:%02x\n",
3937 bssid[0], bssid[1], bssid[2],
3938 bssid[3], bssid[4], bssid[5]);
3939 out += sprintf(out, "Channel: %d\n", chan);
3943 static DEVICE_ATTR(bssinfo, S_IRUGO, show_bssinfo, NULL);
3948 #ifdef CONFIG_IPW_DEBUG
3949 static ssize_t show_debug_level(struct device_driver *d, char *buf)
3951 return sprintf(buf, "0x%08X\n", ipw2100_debug_level);
3954 static ssize_t store_debug_level(struct device_driver *d, const char *buf,
3957 char *p = (char *)buf;
3960 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
3962 if (p[0] == 'x' || p[0] == 'X')
3964 val = simple_strtoul(p, &p, 16);
3966 val = simple_strtoul(p, &p, 10);
3968 IPW_DEBUG_INFO(DRV_NAME
3969 ": %s is not in hex or decimal form.\n", buf);
3971 ipw2100_debug_level = val;
3973 return strnlen(buf, count);
3975 static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, show_debug_level,
3977 #endif /* CONFIG_IPW_DEBUG */
3980 static ssize_t show_fatal_error(struct device *d, char *buf)
3982 struct ipw2100_priv *priv = dev_get_drvdata(d);
3986 if (priv->fatal_error)
3987 out += sprintf(out, "0x%08X\n",
3990 out += sprintf(out, "0\n");
3992 for (i = 1; i <= IPW2100_ERROR_QUEUE; i++) {
3993 if (!priv->fatal_errors[(priv->fatal_index - i) %
3994 IPW2100_ERROR_QUEUE])
3997 out += sprintf(out, "%d. 0x%08X\n", i,
3998 priv->fatal_errors[(priv->fatal_index - i) %
3999 IPW2100_ERROR_QUEUE]);
4005 static ssize_t store_fatal_error(struct device *d, const char *buf,
4008 struct ipw2100_priv *priv = dev_get_drvdata(d);
4009 schedule_reset(priv);
4012 static DEVICE_ATTR(fatal_error, S_IWUSR|S_IRUGO, show_fatal_error, store_fatal_error);
4015 static ssize_t show_scan_age(struct device *d, char *buf)
4017 struct ipw2100_priv *priv = dev_get_drvdata(d);
4018 return sprintf(buf, "%d\n", priv->ieee->scan_age);
4021 static ssize_t store_scan_age(struct device *d, const char *buf, size_t count)
4023 struct ipw2100_priv *priv = dev_get_drvdata(d);
4024 struct net_device *dev = priv->net_dev;
4025 char buffer[] = "00000000";
4027 (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
4031 IPW_DEBUG_INFO("enter\n");
4033 strncpy(buffer, buf, len);
4036 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
4038 if (p[0] == 'x' || p[0] == 'X')
4040 val = simple_strtoul(p, &p, 16);
4042 val = simple_strtoul(p, &p, 10);
4044 IPW_DEBUG_INFO("%s: user supplied invalid value.\n",
4047 priv->ieee->scan_age = val;
4048 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
4051 IPW_DEBUG_INFO("exit\n");
4054 static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
4057 static ssize_t show_rf_kill(struct device *d, char *buf)
4059 /* 0 - RF kill not enabled
4060 1 - SW based RF kill active (sysfs)
4061 2 - HW based RF kill active
4062 3 - Both HW and SW baed RF kill active */
4063 struct ipw2100_priv *priv = (struct ipw2100_priv *)d->driver_data;
4064 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
4065 (rf_kill_active(priv) ? 0x2 : 0x0);
4066 return sprintf(buf, "%i\n", val);
4069 static int ipw_radio_kill_sw(struct ipw2100_priv *priv, int disable_radio)
4071 if ((disable_radio ? 1 : 0) ==
4072 (priv->status & STATUS_RF_KILL_SW ? 1 : 0))
4075 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
4076 disable_radio ? "OFF" : "ON");
4078 down(&priv->action_sem);
4080 if (disable_radio) {
4081 priv->status |= STATUS_RF_KILL_SW;
4084 priv->status &= ~STATUS_RF_KILL_SW;
4085 if (rf_kill_active(priv)) {
4086 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
4087 "disabled by HW switch\n");
4088 /* Make sure the RF_KILL check timer is running */
4089 priv->stop_rf_kill = 0;
4090 cancel_delayed_work(&priv->rf_kill);
4091 queue_delayed_work(priv->workqueue, &priv->rf_kill,
4094 schedule_reset(priv);
4097 up(&priv->action_sem);
4101 static ssize_t store_rf_kill(struct device *d, const char *buf, size_t count)
4103 struct ipw2100_priv *priv = dev_get_drvdata(d);
4104 ipw_radio_kill_sw(priv, buf[0] == '1');
4107 static DEVICE_ATTR(rf_kill, S_IWUSR|S_IRUGO, show_rf_kill, store_rf_kill);
4110 static struct attribute *ipw2100_sysfs_entries[] = {
4111 &dev_attr_hardware.attr,
4112 &dev_attr_registers.attr,
4113 &dev_attr_ordinals.attr,
4115 &dev_attr_stats.attr,
4116 &dev_attr_internals.attr,
4117 &dev_attr_bssinfo.attr,
4118 &dev_attr_memory.attr,
4119 &dev_attr_scan_age.attr,
4120 &dev_attr_fatal_error.attr,
4121 &dev_attr_rf_kill.attr,
4123 &dev_attr_status.attr,
4124 &dev_attr_capability.attr,
4128 static struct attribute_group ipw2100_attribute_group = {
4129 .attrs = ipw2100_sysfs_entries,
4133 static int status_queue_allocate(struct ipw2100_priv *priv, int entries)
4135 struct ipw2100_status_queue *q = &priv->status_queue;
4137 IPW_DEBUG_INFO("enter\n");
4139 q->size = entries * sizeof(struct ipw2100_status);
4140 q->drv = (struct ipw2100_status *)pci_alloc_consistent(
4141 priv->pci_dev, q->size, &q->nic);
4144 "Can not allocate status queue.\n");
4148 memset(q->drv, 0, q->size);
4150 IPW_DEBUG_INFO("exit\n");
4155 static void status_queue_free(struct ipw2100_priv *priv)
4157 IPW_DEBUG_INFO("enter\n");
4159 if (priv->status_queue.drv) {
4160 pci_free_consistent(
4161 priv->pci_dev, priv->status_queue.size,
4162 priv->status_queue.drv, priv->status_queue.nic);
4163 priv->status_queue.drv = NULL;
4166 IPW_DEBUG_INFO("exit\n");
4169 static int bd_queue_allocate(struct ipw2100_priv *priv,
4170 struct ipw2100_bd_queue *q, int entries)
4172 IPW_DEBUG_INFO("enter\n");
4174 memset(q, 0, sizeof(struct ipw2100_bd_queue));
4176 q->entries = entries;
4177 q->size = entries * sizeof(struct ipw2100_bd);
4178 q->drv = pci_alloc_consistent(priv->pci_dev, q->size, &q->nic);
4180 IPW_DEBUG_INFO("can't allocate shared memory for buffer descriptors\n");
4183 memset(q->drv, 0, q->size);
4185 IPW_DEBUG_INFO("exit\n");
4190 static void bd_queue_free(struct ipw2100_priv *priv,
4191 struct ipw2100_bd_queue *q)
4193 IPW_DEBUG_INFO("enter\n");
4199 pci_free_consistent(priv->pci_dev,
4200 q->size, q->drv, q->nic);
4204 IPW_DEBUG_INFO("exit\n");
4207 static void bd_queue_initialize(
4208 struct ipw2100_priv *priv, struct ipw2100_bd_queue * q,
4209 u32 base, u32 size, u32 r, u32 w)
4211 IPW_DEBUG_INFO("enter\n");
4213 IPW_DEBUG_INFO("initializing bd queue at virt=%p, phys=%08x\n", q->drv, (u32)q->nic);
4215 write_register(priv->net_dev, base, q->nic);
4216 write_register(priv->net_dev, size, q->entries);
4217 write_register(priv->net_dev, r, q->oldest);
4218 write_register(priv->net_dev, w, q->next);
4220 IPW_DEBUG_INFO("exit\n");
4223 static void ipw2100_kill_workqueue(struct ipw2100_priv *priv)
4225 if (priv->workqueue) {
4226 priv->stop_rf_kill = 1;
4227 priv->stop_hang_check = 1;
4228 cancel_delayed_work(&priv->reset_work);
4229 cancel_delayed_work(&priv->security_work);
4230 cancel_delayed_work(&priv->wx_event_work);
4231 cancel_delayed_work(&priv->hang_check);
4232 cancel_delayed_work(&priv->rf_kill);
4233 destroy_workqueue(priv->workqueue);
4234 priv->workqueue = NULL;
4238 static int ipw2100_tx_allocate(struct ipw2100_priv *priv)
4240 int i, j, err = -EINVAL;
4244 IPW_DEBUG_INFO("enter\n");
4246 err = bd_queue_allocate(priv, &priv->tx_queue, TX_QUEUE_LENGTH);
4248 IPW_DEBUG_ERROR("%s: failed bd_queue_allocate\n",
4249 priv->net_dev->name);
4253 priv->tx_buffers = (struct ipw2100_tx_packet *)kmalloc(
4254 TX_PENDED_QUEUE_LENGTH * sizeof(struct ipw2100_tx_packet),
4256 if (!priv->tx_buffers) {
4257 IPW_DEBUG_ERROR("%s: alloc failed form tx buffers.\n",
4258 priv->net_dev->name);
4259 bd_queue_free(priv, &priv->tx_queue);
4263 for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
4264 v = pci_alloc_consistent(
4265 priv->pci_dev, sizeof(struct ipw2100_data_header), &p);
4267 IPW_DEBUG_ERROR("%s: PCI alloc failed for tx "
4268 "buffers.\n", priv->net_dev->name);
4273 priv->tx_buffers[i].type = DATA;
4274 priv->tx_buffers[i].info.d_struct.data = (struct ipw2100_data_header*)v;
4275 priv->tx_buffers[i].info.d_struct.data_phys = p;
4276 priv->tx_buffers[i].info.d_struct.txb = NULL;
4279 if (i == TX_PENDED_QUEUE_LENGTH)
4282 for (j = 0; j < i; j++) {
4283 pci_free_consistent(
4285 sizeof(struct ipw2100_data_header),
4286 priv->tx_buffers[j].info.d_struct.data,
4287 priv->tx_buffers[j].info.d_struct.data_phys);
4290 kfree(priv->tx_buffers);
4291 priv->tx_buffers = NULL;
4296 static void ipw2100_tx_initialize(struct ipw2100_priv *priv)
4300 IPW_DEBUG_INFO("enter\n");
4303 * reinitialize packet info lists
4305 INIT_LIST_HEAD(&priv->fw_pend_list);
4306 INIT_STAT(&priv->fw_pend_stat);
4309 * reinitialize lists
4311 INIT_LIST_HEAD(&priv->tx_pend_list);
4312 INIT_LIST_HEAD(&priv->tx_free_list);
4313 INIT_STAT(&priv->tx_pend_stat);
4314 INIT_STAT(&priv->tx_free_stat);
4316 for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
4317 /* We simply drop any SKBs that have been queued for
4319 if (priv->tx_buffers[i].info.d_struct.txb) {
4320 ieee80211_txb_free(priv->tx_buffers[i].info.d_struct.txb);
4321 priv->tx_buffers[i].info.d_struct.txb = NULL;
4324 list_add_tail(&priv->tx_buffers[i].list, &priv->tx_free_list);
4327 SET_STAT(&priv->tx_free_stat, i);
4329 priv->tx_queue.oldest = 0;
4330 priv->tx_queue.available = priv->tx_queue.entries;
4331 priv->tx_queue.next = 0;
4332 INIT_STAT(&priv->txq_stat);
4333 SET_STAT(&priv->txq_stat, priv->tx_queue.available);
4335 bd_queue_initialize(priv, &priv->tx_queue,
4336 IPW_MEM_HOST_SHARED_TX_QUEUE_BD_BASE,
4337 IPW_MEM_HOST_SHARED_TX_QUEUE_BD_SIZE,
4338 IPW_MEM_HOST_SHARED_TX_QUEUE_READ_INDEX,
4339 IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX);
4341 IPW_DEBUG_INFO("exit\n");
4345 static void ipw2100_tx_free(struct ipw2100_priv *priv)
4349 IPW_DEBUG_INFO("enter\n");
4351 bd_queue_free(priv, &priv->tx_queue);
4353 if (!priv->tx_buffers)
4356 for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
4357 if (priv->tx_buffers[i].info.d_struct.txb) {
4358 ieee80211_txb_free(priv->tx_buffers[i].info.d_struct.txb);
4359 priv->tx_buffers[i].info.d_struct.txb = NULL;
4361 if (priv->tx_buffers[i].info.d_struct.data)
4362 pci_free_consistent(
4364 sizeof(struct ipw2100_data_header),
4365 priv->tx_buffers[i].info.d_struct.data,
4366 priv->tx_buffers[i].info.d_struct.data_phys);
4369 kfree(priv->tx_buffers);
4370 priv->tx_buffers = NULL;
4372 IPW_DEBUG_INFO("exit\n");
4377 static int ipw2100_rx_allocate(struct ipw2100_priv *priv)
4379 int i, j, err = -EINVAL;
4381 IPW_DEBUG_INFO("enter\n");
4383 err = bd_queue_allocate(priv, &priv->rx_queue, RX_QUEUE_LENGTH);
4385 IPW_DEBUG_INFO("failed bd_queue_allocate\n");
4389 err = status_queue_allocate(priv, RX_QUEUE_LENGTH);
4391 IPW_DEBUG_INFO("failed status_queue_allocate\n");
4392 bd_queue_free(priv, &priv->rx_queue);
4399 priv->rx_buffers = (struct ipw2100_rx_packet *)
4400 kmalloc(RX_QUEUE_LENGTH * sizeof(struct ipw2100_rx_packet),
4402 if (!priv->rx_buffers) {
4403 IPW_DEBUG_INFO("can't allocate rx packet buffer table\n");
4405 bd_queue_free(priv, &priv->rx_queue);
4407 status_queue_free(priv);
4412 for (i = 0; i < RX_QUEUE_LENGTH; i++) {
4413 struct ipw2100_rx_packet *packet = &priv->rx_buffers[i];
4415 err = ipw2100_alloc_skb(priv, packet);
4416 if (unlikely(err)) {
4421 /* The BD holds the cache aligned address */
4422 priv->rx_queue.drv[i].host_addr = packet->dma_addr;
4423 priv->rx_queue.drv[i].buf_length = IPW_RX_NIC_BUFFER_LENGTH;
4424 priv->status_queue.drv[i].status_fields = 0;
4427 if (i == RX_QUEUE_LENGTH)
4430 for (j = 0; j < i; j++) {
4431 pci_unmap_single(priv->pci_dev, priv->rx_buffers[j].dma_addr,
4432 sizeof(struct ipw2100_rx_packet),
4433 PCI_DMA_FROMDEVICE);
4434 dev_kfree_skb(priv->rx_buffers[j].skb);
4437 kfree(priv->rx_buffers);
4438 priv->rx_buffers = NULL;
4440 bd_queue_free(priv, &priv->rx_queue);
4442 status_queue_free(priv);
4447 static void ipw2100_rx_initialize(struct ipw2100_priv *priv)
4449 IPW_DEBUG_INFO("enter\n");
4451 priv->rx_queue.oldest = 0;
4452 priv->rx_queue.available = priv->rx_queue.entries - 1;
4453 priv->rx_queue.next = priv->rx_queue.entries - 1;
4455 INIT_STAT(&priv->rxq_stat);
4456 SET_STAT(&priv->rxq_stat, priv->rx_queue.available);
4458 bd_queue_initialize(priv, &priv->rx_queue,
4459 IPW_MEM_HOST_SHARED_RX_BD_BASE,
4460 IPW_MEM_HOST_SHARED_RX_BD_SIZE,
4461 IPW_MEM_HOST_SHARED_RX_READ_INDEX,
4462 IPW_MEM_HOST_SHARED_RX_WRITE_INDEX);
4464 /* set up the status queue */
4465 write_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_STATUS_BASE,
4466 priv->status_queue.nic);
4468 IPW_DEBUG_INFO("exit\n");
4471 static void ipw2100_rx_free(struct ipw2100_priv *priv)
4475 IPW_DEBUG_INFO("enter\n");
4477 bd_queue_free(priv, &priv->rx_queue);
4478 status_queue_free(priv);
4480 if (!priv->rx_buffers)
4483 for (i = 0; i < RX_QUEUE_LENGTH; i++) {
4484 if (priv->rx_buffers[i].rxp) {
4485 pci_unmap_single(priv->pci_dev,
4486 priv->rx_buffers[i].dma_addr,
4487 sizeof(struct ipw2100_rx),
4488 PCI_DMA_FROMDEVICE);
4489 dev_kfree_skb(priv->rx_buffers[i].skb);
4493 kfree(priv->rx_buffers);
4494 priv->rx_buffers = NULL;
4496 IPW_DEBUG_INFO("exit\n");
4499 static int ipw2100_read_mac_address(struct ipw2100_priv *priv)
4501 u32 length = ETH_ALEN;
4506 err = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ADAPTER_MAC,
4509 IPW_DEBUG_INFO("MAC address read failed\n");
4512 IPW_DEBUG_INFO("card MAC is %02X:%02X:%02X:%02X:%02X:%02X\n",
4513 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
4515 memcpy(priv->net_dev->dev_addr, mac, ETH_ALEN);
4520 /********************************************************************
4524 ********************************************************************/
4526 int ipw2100_set_mac_address(struct ipw2100_priv *priv, int batch_mode)
4528 struct host_command cmd = {
4529 .host_command = ADAPTER_ADDRESS,
4530 .host_command_sequence = 0,
4531 .host_command_length = ETH_ALEN
4535 IPW_DEBUG_HC("SET_MAC_ADDRESS\n");
4537 IPW_DEBUG_INFO("enter\n");
4539 if (priv->config & CFG_CUSTOM_MAC) {
4540 memcpy(cmd.host_command_parameters, priv->mac_addr,
4542 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
4544 memcpy(cmd.host_command_parameters, priv->net_dev->dev_addr,
4547 err = ipw2100_hw_send_command(priv, &cmd);
4549 IPW_DEBUG_INFO("exit\n");
4553 int ipw2100_set_port_type(struct ipw2100_priv *priv, u32 port_type,
4556 struct host_command cmd = {
4557 .host_command = PORT_TYPE,
4558 .host_command_sequence = 0,
4559 .host_command_length = sizeof(u32)
4563 switch (port_type) {
4565 cmd.host_command_parameters[0] = IPW_BSS;
4568 cmd.host_command_parameters[0] = IPW_IBSS;
4572 IPW_DEBUG_HC("PORT_TYPE: %s\n",
4573 port_type == IPW_IBSS ? "Ad-Hoc" : "Managed");
4576 err = ipw2100_disable_adapter(priv);
4578 IPW_DEBUG_ERROR("%s: Could not disable adapter %d\n",
4579 priv->net_dev->name, err);
4584 /* send cmd to firmware */
4585 err = ipw2100_hw_send_command(priv, &cmd);
4588 ipw2100_enable_adapter(priv);
4594 int ipw2100_set_channel(struct ipw2100_priv *priv, u32 channel, int batch_mode)
4596 struct host_command cmd = {
4597 .host_command = CHANNEL,
4598 .host_command_sequence = 0,
4599 .host_command_length = sizeof(u32)
4603 cmd.host_command_parameters[0] = channel;
4605 IPW_DEBUG_HC("CHANNEL: %d\n", channel);
4607 /* If BSS then we don't support channel selection */
4608 if (priv->ieee->iw_mode == IW_MODE_INFRA)
4611 if ((channel != 0) &&
4612 ((channel < REG_MIN_CHANNEL) || (channel > REG_MAX_CHANNEL)))
4616 err = ipw2100_disable_adapter(priv);
4621 err = ipw2100_hw_send_command(priv, &cmd);
4623 IPW_DEBUG_INFO("Failed to set channel to %d",
4629 priv->config |= CFG_STATIC_CHANNEL;
4631 priv->config &= ~CFG_STATIC_CHANNEL;
4633 priv->channel = channel;
4636 err = ipw2100_enable_adapter(priv);
4644 int ipw2100_system_config(struct ipw2100_priv *priv, int batch_mode)
4646 struct host_command cmd = {
4647 .host_command = SYSTEM_CONFIG,
4648 .host_command_sequence = 0,
4649 .host_command_length = 12,
4651 u32 ibss_mask, len = sizeof(u32);
4654 /* Set system configuration */
4657 err = ipw2100_disable_adapter(priv);
4662 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
4663 cmd.host_command_parameters[0] |= IPW_CFG_IBSS_AUTO_START;
4665 cmd.host_command_parameters[0] |= IPW_CFG_IBSS_MASK |
4667 IPW_CFG_802_1x_ENABLE;
4669 if (!(priv->config & CFG_LONG_PREAMBLE))
4670 cmd.host_command_parameters[0] |= IPW_CFG_PREAMBLE_AUTO;
4672 err = ipw2100_get_ordinal(priv,
4673 IPW_ORD_EEPROM_IBSS_11B_CHANNELS,
4676 ibss_mask = IPW_IBSS_11B_DEFAULT_MASK;
4678 cmd.host_command_parameters[1] = REG_CHANNEL_MASK;
4679 cmd.host_command_parameters[2] = REG_CHANNEL_MASK & ibss_mask;
4682 /*cmd.host_command_parameters[0] |= DIVERSITY_ANTENNA_A;*/
4684 err = ipw2100_hw_send_command(priv, &cmd);
4688 /* If IPv6 is configured in the kernel then we don't want to filter out all
4689 * of the multicast packets as IPv6 needs some. */
4690 #if !defined(CONFIG_IPV6) && !defined(CONFIG_IPV6_MODULE)
4691 cmd.host_command = ADD_MULTICAST;
4692 cmd.host_command_sequence = 0;
4693 cmd.host_command_length = 0;
4695 ipw2100_hw_send_command(priv, &cmd);
4698 err = ipw2100_enable_adapter(priv);
4706 int ipw2100_set_tx_rates(struct ipw2100_priv *priv, u32 rate, int batch_mode)
4708 struct host_command cmd = {
4709 .host_command = BASIC_TX_RATES,
4710 .host_command_sequence = 0,
4711 .host_command_length = 4
4715 cmd.host_command_parameters[0] = rate & TX_RATE_MASK;
4718 err = ipw2100_disable_adapter(priv);
4723 /* Set BASIC TX Rate first */
4724 ipw2100_hw_send_command(priv, &cmd);
4727 cmd.host_command = TX_RATES;
4728 ipw2100_hw_send_command(priv, &cmd);
4730 /* Set MSDU TX Rate */
4731 cmd.host_command = MSDU_TX_RATES;
4732 ipw2100_hw_send_command(priv, &cmd);
4735 err = ipw2100_enable_adapter(priv);
4740 priv->tx_rates = rate;
4745 int ipw2100_set_power_mode(struct ipw2100_priv *priv,
4748 struct host_command cmd = {
4749 .host_command = POWER_MODE,
4750 .host_command_sequence = 0,
4751 .host_command_length = 4
4755 cmd.host_command_parameters[0] = power_level;
4757 err = ipw2100_hw_send_command(priv, &cmd);
4761 if (power_level == IPW_POWER_MODE_CAM)
4762 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
4764 priv->power_mode = IPW_POWER_ENABLED | power_level;
4766 #ifdef CONFIG_IPW2100_TX_POWER
4767 if (priv->port_type == IBSS &&
4768 priv->adhoc_power != DFTL_IBSS_TX_POWER) {
4769 /* Set beacon interval */
4770 cmd.host_command = TX_POWER_INDEX;
4771 cmd.host_command_parameters[0] = (u32)priv->adhoc_power;
4773 err = ipw2100_hw_send_command(priv, &cmd);
4783 int ipw2100_set_rts_threshold(struct ipw2100_priv *priv, u32 threshold)
4785 struct host_command cmd = {
4786 .host_command = RTS_THRESHOLD,
4787 .host_command_sequence = 0,
4788 .host_command_length = 4
4792 if (threshold & RTS_DISABLED)
4793 cmd.host_command_parameters[0] = MAX_RTS_THRESHOLD;
4795 cmd.host_command_parameters[0] = threshold & ~RTS_DISABLED;
4797 err = ipw2100_hw_send_command(priv, &cmd);
4801 priv->rts_threshold = threshold;
4807 int ipw2100_set_fragmentation_threshold(struct ipw2100_priv *priv,
4808 u32 threshold, int batch_mode)
4810 struct host_command cmd = {
4811 .host_command = FRAG_THRESHOLD,
4812 .host_command_sequence = 0,
4813 .host_command_length = 4,
4814 .host_command_parameters[0] = 0,
4819 err = ipw2100_disable_adapter(priv);
4825 threshold = DEFAULT_FRAG_THRESHOLD;
4827 threshold = max(threshold, MIN_FRAG_THRESHOLD);
4828 threshold = min(threshold, MAX_FRAG_THRESHOLD);
4831 cmd.host_command_parameters[0] = threshold;
4833 IPW_DEBUG_HC("FRAG_THRESHOLD: %u\n", threshold);
4835 err = ipw2100_hw_send_command(priv, &cmd);
4838 ipw2100_enable_adapter(priv);
4841 priv->frag_threshold = threshold;
4847 int ipw2100_set_short_retry(struct ipw2100_priv *priv, u32 retry)
4849 struct host_command cmd = {
4850 .host_command = SHORT_RETRY_LIMIT,
4851 .host_command_sequence = 0,
4852 .host_command_length = 4
4856 cmd.host_command_parameters[0] = retry;
4858 err = ipw2100_hw_send_command(priv, &cmd);
4862 priv->short_retry_limit = retry;
4867 int ipw2100_set_long_retry(struct ipw2100_priv *priv, u32 retry)
4869 struct host_command cmd = {
4870 .host_command = LONG_RETRY_LIMIT,
4871 .host_command_sequence = 0,
4872 .host_command_length = 4
4876 cmd.host_command_parameters[0] = retry;
4878 err = ipw2100_hw_send_command(priv, &cmd);
4882 priv->long_retry_limit = retry;
4888 int ipw2100_set_mandatory_bssid(struct ipw2100_priv *priv, u8 *bssid,
4891 struct host_command cmd = {
4892 .host_command = MANDATORY_BSSID,
4893 .host_command_sequence = 0,
4894 .host_command_length = (bssid == NULL) ? 0 : ETH_ALEN
4898 #ifdef CONFIG_IPW_DEBUG
4901 "MANDATORY_BSSID: %02X:%02X:%02X:%02X:%02X:%02X\n",
4902 bssid[0], bssid[1], bssid[2], bssid[3], bssid[4],
4905 IPW_DEBUG_HC("MANDATORY_BSSID: <clear>\n");
4907 /* if BSSID is empty then we disable mandatory bssid mode */
4909 memcpy((u8 *)cmd.host_command_parameters, bssid, ETH_ALEN);
4912 err = ipw2100_disable_adapter(priv);
4917 err = ipw2100_hw_send_command(priv, &cmd);
4920 ipw2100_enable_adapter(priv);
4925 #ifdef CONFIG_IEEE80211_WPA
4926 static int ipw2100_disassociate_bssid(struct ipw2100_priv *priv)
4928 struct host_command cmd = {
4929 .host_command = DISASSOCIATION_BSSID,
4930 .host_command_sequence = 0,
4931 .host_command_length = ETH_ALEN
4936 IPW_DEBUG_HC("DISASSOCIATION_BSSID\n");
4939 /* The Firmware currently ignores the BSSID and just disassociates from
4940 * the currently associated AP -- but in the off chance that a future
4941 * firmware does use the BSSID provided here, we go ahead and try and
4942 * set it to the currently associated AP's BSSID */
4943 memcpy(cmd.host_command_parameters, priv->bssid, ETH_ALEN);
4945 err = ipw2100_hw_send_command(priv, &cmd);
4952 * Pseudo code for setting up wpa_frame:
4955 void x(struct ieee80211_assoc_frame *wpa_assoc)
4957 struct ipw2100_wpa_assoc_frame frame;
4958 frame->fixed_ie_mask = IPW_WPA_CAPABILTIES |
4959 IPW_WPA_LISTENINTERVAL |
4961 frame->capab_info = wpa_assoc->capab_info;
4962 frame->lisen_interval = wpa_assoc->listent_interval;
4963 memcpy(frame->current_ap, wpa_assoc->current_ap, ETH_ALEN);
4965 /* UNKNOWN -- I'm not postivive about this part; don't have any WPA
4966 * setup here to test it with.
4968 * Walk the IEs in the wpa_assoc and figure out the total size of all
4969 * that data. Stick that into frame->var_ie_len. Then memcpy() all of
4970 * the IEs from wpa_frame into frame.
4972 frame->var_ie_len = calculate_ie_len(wpa_assoc);
4973 memcpy(frame->var_ie, wpa_assoc->variable, frame->var_ie_len);
4975 ipw2100_set_wpa_ie(priv, &frame, 0);
4982 static int ipw2100_set_wpa_ie(struct ipw2100_priv *,
4983 struct ipw2100_wpa_assoc_frame *, int)
4984 __attribute__ ((unused));
4986 static int ipw2100_set_wpa_ie(struct ipw2100_priv *priv,
4987 struct ipw2100_wpa_assoc_frame *wpa_frame,
4990 struct host_command cmd = {
4991 .host_command = SET_WPA_IE,
4992 .host_command_sequence = 0,
4993 .host_command_length = sizeof(struct ipw2100_wpa_assoc_frame),
4997 IPW_DEBUG_HC("SET_WPA_IE\n");
5000 err = ipw2100_disable_adapter(priv);
5005 memcpy(cmd.host_command_parameters, wpa_frame,
5006 sizeof(struct ipw2100_wpa_assoc_frame));
5008 err = ipw2100_hw_send_command(priv, &cmd);
5011 if (ipw2100_enable_adapter(priv))
5018 struct security_info_params {
5019 u32 allowed_ciphers;
5022 u8 replay_counters_number;
5023 u8 unicast_using_group;
5024 } __attribute__ ((packed));
5026 int ipw2100_set_security_information(struct ipw2100_priv *priv,
5029 int unicast_using_group,
5032 struct host_command cmd = {
5033 .host_command = SET_SECURITY_INFORMATION,
5034 .host_command_sequence = 0,
5035 .host_command_length = sizeof(struct security_info_params)
5037 struct security_info_params *security =
5038 (struct security_info_params *)&cmd.host_command_parameters;
5040 memset(security, 0, sizeof(*security));
5042 /* If shared key AP authentication is turned on, then we need to
5043 * configure the firmware to try and use it.
5045 * Actual data encryption/decryption is handled by the host. */
5046 security->auth_mode = auth_mode;
5047 security->unicast_using_group = unicast_using_group;
5049 switch (security_level) {
5052 security->allowed_ciphers = IPW_NONE_CIPHER;
5055 security->allowed_ciphers = IPW_WEP40_CIPHER |
5059 security->allowed_ciphers = IPW_WEP40_CIPHER |
5060 IPW_WEP104_CIPHER | IPW_TKIP_CIPHER;
5062 case SEC_LEVEL_2_CKIP:
5063 security->allowed_ciphers = IPW_WEP40_CIPHER |
5064 IPW_WEP104_CIPHER | IPW_CKIP_CIPHER;
5067 security->allowed_ciphers = IPW_WEP40_CIPHER |
5068 IPW_WEP104_CIPHER | IPW_TKIP_CIPHER | IPW_CCMP_CIPHER;
5073 "SET_SECURITY_INFORMATION: auth:%d cipher:0x%02X (level %d)\n",
5074 security->auth_mode, security->allowed_ciphers, security_level);
5076 security->replay_counters_number = 0;
5079 err = ipw2100_disable_adapter(priv);
5084 err = ipw2100_hw_send_command(priv, &cmd);
5087 ipw2100_enable_adapter(priv);
5092 int ipw2100_set_tx_power(struct ipw2100_priv *priv,
5095 struct host_command cmd = {
5096 .host_command = TX_POWER_INDEX,
5097 .host_command_sequence = 0,
5098 .host_command_length = 4
5102 cmd.host_command_parameters[0] = tx_power;
5104 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
5105 err = ipw2100_hw_send_command(priv, &cmd);
5107 priv->tx_power = tx_power;
5112 int ipw2100_set_ibss_beacon_interval(struct ipw2100_priv *priv,
5113 u32 interval, int batch_mode)
5115 struct host_command cmd = {
5116 .host_command = BEACON_INTERVAL,
5117 .host_command_sequence = 0,
5118 .host_command_length = 4
5122 cmd.host_command_parameters[0] = interval;
5124 IPW_DEBUG_INFO("enter\n");
5126 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
5128 err = ipw2100_disable_adapter(priv);
5133 ipw2100_hw_send_command(priv, &cmd);
5136 err = ipw2100_enable_adapter(priv);
5142 IPW_DEBUG_INFO("exit\n");
5148 void ipw2100_queues_initialize(struct ipw2100_priv *priv)
5150 ipw2100_tx_initialize(priv);
5151 ipw2100_rx_initialize(priv);
5152 ipw2100_msg_initialize(priv);
5155 void ipw2100_queues_free(struct ipw2100_priv *priv)
5157 ipw2100_tx_free(priv);
5158 ipw2100_rx_free(priv);
5159 ipw2100_msg_free(priv);
5162 int ipw2100_queues_allocate(struct ipw2100_priv *priv)
5164 if (ipw2100_tx_allocate(priv) ||
5165 ipw2100_rx_allocate(priv) ||
5166 ipw2100_msg_allocate(priv))
5172 ipw2100_tx_free(priv);
5173 ipw2100_rx_free(priv);
5174 ipw2100_msg_free(priv);
5178 #define IPW_PRIVACY_CAPABLE 0x0008
5180 static int ipw2100_set_wep_flags(struct ipw2100_priv *priv, u32 flags,
5183 struct host_command cmd = {
5184 .host_command = WEP_FLAGS,
5185 .host_command_sequence = 0,
5186 .host_command_length = 4
5190 cmd.host_command_parameters[0] = flags;
5192 IPW_DEBUG_HC("WEP_FLAGS: flags = 0x%08X\n", flags);
5195 err = ipw2100_disable_adapter(priv);
5197 IPW_DEBUG_ERROR("%s: Could not disable adapter %d\n",
5198 priv->net_dev->name, err);
5203 /* send cmd to firmware */
5204 err = ipw2100_hw_send_command(priv, &cmd);
5207 ipw2100_enable_adapter(priv);
5212 struct ipw2100_wep_key {
5218 /* Macros to ease up priting WEP keys */
5219 #define WEP_FMT_64 "%02X%02X%02X%02X-%02X"
5220 #define WEP_FMT_128 "%02X%02X%02X%02X-%02X%02X%02X%02X-%02X%02X%02X"
5221 #define WEP_STR_64(x) x[0],x[1],x[2],x[3],x[4]
5222 #define WEP_STR_128(x) x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],x[8],x[9],x[10]
5228 * @priv: struct to work on
5229 * @idx: index of the key we want to set
5230 * @key: ptr to the key data to set
5231 * @len: length of the buffer at @key
5232 * @batch_mode: FIXME perform the operation in batch mode, not
5233 * disabling the device.
5235 * @returns 0 if OK, < 0 errno code on error.
5237 * Fill out a command structure with the new wep key, length an
5238 * index and send it down the wire.
5240 static int ipw2100_set_key(struct ipw2100_priv *priv,
5241 int idx, char *key, int len, int batch_mode)
5243 int keylen = len ? (len <= 5 ? 5 : 13) : 0;
5244 struct host_command cmd = {
5245 .host_command = WEP_KEY_INFO,
5246 .host_command_sequence = 0,
5247 .host_command_length = sizeof(struct ipw2100_wep_key),
5249 struct ipw2100_wep_key *wep_key = (void*)cmd.host_command_parameters;
5252 IPW_DEBUG_HC("WEP_KEY_INFO: index = %d, len = %d/%d\n",
5255 /* NOTE: We don't check cached values in case the firmware was reset
5256 * or some other problem is occuring. If the user is setting the key,
5257 * then we push the change */
5260 wep_key->len = keylen;
5263 memcpy(wep_key->key, key, len);
5264 memset(wep_key->key + len, 0, keylen - len);
5267 /* Will be optimized out on debug not being configured in */
5269 IPW_DEBUG_WEP("%s: Clearing key %d\n",
5270 priv->net_dev->name, wep_key->idx);
5271 else if (keylen == 5)
5272 IPW_DEBUG_WEP("%s: idx: %d, len: %d key: " WEP_FMT_64 "\n",
5273 priv->net_dev->name, wep_key->idx, wep_key->len,
5274 WEP_STR_64(wep_key->key));
5276 IPW_DEBUG_WEP("%s: idx: %d, len: %d key: " WEP_FMT_128
5278 priv->net_dev->name, wep_key->idx, wep_key->len,
5279 WEP_STR_128(wep_key->key));
5282 err = ipw2100_disable_adapter(priv);
5283 /* FIXME: IPG: shouldn't this prink be in _disable_adapter()? */
5285 IPW_DEBUG_ERROR("%s: Could not disable adapter %d\n",
5286 priv->net_dev->name, err);
5291 /* send cmd to firmware */
5292 err = ipw2100_hw_send_command(priv, &cmd);
5295 int err2 = ipw2100_enable_adapter(priv);
5302 static int ipw2100_set_key_index(struct ipw2100_priv *priv,
5303 int idx, int batch_mode)
5305 struct host_command cmd = {
5306 .host_command = WEP_KEY_INDEX,
5307 .host_command_sequence = 0,
5308 .host_command_length = 4,
5309 .host_command_parameters[0] = idx,
5313 IPW_DEBUG_HC("WEP_KEY_INDEX: index = %d\n", idx);
5315 if (idx < 0 || idx > 3)
5319 err = ipw2100_disable_adapter(priv);
5321 IPW_DEBUG_ERROR("%s: Could not disable adapter %d\n",
5322 priv->net_dev->name, err);
5327 /* send cmd to firmware */
5328 err = ipw2100_hw_send_command(priv, &cmd);
5331 ipw2100_enable_adapter(priv);
5337 static int ipw2100_configure_security(struct ipw2100_priv *priv,
5340 int i, err, auth_mode, sec_level, use_group;
5342 if (!(priv->status & STATUS_RUNNING))
5346 err = ipw2100_disable_adapter(priv);
5351 if (!priv->sec.enabled) {
5352 err = ipw2100_set_security_information(
5353 priv, IPW_AUTH_OPEN, SEC_LEVEL_0, 0, 1);
5355 auth_mode = IPW_AUTH_OPEN;
5356 if ((priv->sec.flags & SEC_AUTH_MODE) &&
5357 (priv->sec.auth_mode == WLAN_AUTH_SHARED_KEY))
5358 auth_mode = IPW_AUTH_SHARED;
5360 sec_level = SEC_LEVEL_0;
5361 if (priv->sec.flags & SEC_LEVEL)
5362 sec_level = priv->sec.level;
5365 if (priv->sec.flags & SEC_UNICAST_GROUP)
5366 use_group = priv->sec.unicast_uses_group;
5368 err = ipw2100_set_security_information(
5369 priv, auth_mode, sec_level, use_group, 1);
5375 if (priv->sec.enabled) {
5376 for (i = 0; i < 4; i++) {
5377 if (!(priv->sec.flags & (1 << i))) {
5378 memset(priv->sec.keys[i], 0, WEP_KEY_LEN);
5379 priv->sec.key_sizes[i] = 0;
5381 err = ipw2100_set_key(priv, i,
5383 priv->sec.key_sizes[i],
5390 ipw2100_set_key_index(priv, priv->ieee->tx_keyidx, 1);
5393 /* Always enable privacy so the Host can filter WEP packets if
5394 * encrypted data is sent up */
5395 err = ipw2100_set_wep_flags(
5396 priv, priv->sec.enabled ? IPW_PRIVACY_CAPABLE : 0, 1);
5400 priv->status &= ~STATUS_SECURITY_UPDATED;
5404 ipw2100_enable_adapter(priv);
5409 static void ipw2100_security_work(struct ipw2100_priv *priv)
5411 /* If we happen to have reconnected before we get a chance to
5412 * process this, then update the security settings--which causes
5413 * a disassociation to occur */
5414 if (!(priv->status & STATUS_ASSOCIATED) &&
5415 priv->status & STATUS_SECURITY_UPDATED)
5416 ipw2100_configure_security(priv, 0);
5419 static void shim__set_security(struct net_device *dev,
5420 struct ieee80211_security *sec)
5422 struct ipw2100_priv *priv = ieee80211_priv(dev);
5423 int i, force_update = 0;
5425 down(&priv->action_sem);
5426 if (!(priv->status & STATUS_INITIALIZED))
5429 for (i = 0; i < 4; i++) {
5430 if (sec->flags & (1 << i)) {
5431 priv->sec.key_sizes[i] = sec->key_sizes[i];
5432 if (sec->key_sizes[i] == 0)
5433 priv->sec.flags &= ~(1 << i);
5435 memcpy(priv->sec.keys[i], sec->keys[i],
5437 priv->sec.flags |= (1 << i);
5438 priv->status |= STATUS_SECURITY_UPDATED;
5442 if ((sec->flags & SEC_ACTIVE_KEY) &&
5443 priv->sec.active_key != sec->active_key) {
5444 if (sec->active_key <= 3) {
5445 priv->sec.active_key = sec->active_key;
5446 priv->sec.flags |= SEC_ACTIVE_KEY;
5448 priv->sec.flags &= ~SEC_ACTIVE_KEY;
5450 priv->status |= STATUS_SECURITY_UPDATED;
5453 if ((sec->flags & SEC_AUTH_MODE) &&
5454 (priv->sec.auth_mode != sec->auth_mode)) {
5455 priv->sec.auth_mode = sec->auth_mode;
5456 priv->sec.flags |= SEC_AUTH_MODE;
5457 priv->status |= STATUS_SECURITY_UPDATED;
5460 if (sec->flags & SEC_ENABLED &&
5461 priv->sec.enabled != sec->enabled) {
5462 priv->sec.flags |= SEC_ENABLED;
5463 priv->sec.enabled = sec->enabled;
5464 priv->status |= STATUS_SECURITY_UPDATED;
5468 if (sec->flags & SEC_LEVEL &&
5469 priv->sec.level != sec->level) {
5470 priv->sec.level = sec->level;
5471 priv->sec.flags |= SEC_LEVEL;
5472 priv->status |= STATUS_SECURITY_UPDATED;
5475 IPW_DEBUG_WEP("Security flags: %c %c%c%c%c %c%c%c%c\n",
5476 priv->sec.flags & (1<<8) ? '1' : '0',
5477 priv->sec.flags & (1<<7) ? '1' : '0',
5478 priv->sec.flags & (1<<6) ? '1' : '0',
5479 priv->sec.flags & (1<<5) ? '1' : '0',
5480 priv->sec.flags & (1<<4) ? '1' : '0',
5481 priv->sec.flags & (1<<3) ? '1' : '0',
5482 priv->sec.flags & (1<<2) ? '1' : '0',
5483 priv->sec.flags & (1<<1) ? '1' : '0',
5484 priv->sec.flags & (1<<0) ? '1' : '0');
5486 /* As a temporary work around to enable WPA until we figure out why
5487 * wpa_supplicant toggles the security capability of the driver, which
5488 * forces a disassocation with force_update...
5490 * if (force_update || !(priv->status & STATUS_ASSOCIATED))*/
5491 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
5492 ipw2100_configure_security(priv, 0);
5494 up(&priv->action_sem);
5497 static int ipw2100_adapter_setup(struct ipw2100_priv *priv)
5503 IPW_DEBUG_INFO("enter\n");
5505 err = ipw2100_disable_adapter(priv);
5508 #ifdef CONFIG_IPW2100_MONITOR
5509 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
5510 err = ipw2100_set_channel(priv, priv->channel, batch_mode);
5514 IPW_DEBUG_INFO("exit\n");
5518 #endif /* CONFIG_IPW2100_MONITOR */
5520 err = ipw2100_read_mac_address(priv);
5524 err = ipw2100_set_mac_address(priv, batch_mode);
5528 err = ipw2100_set_port_type(priv, priv->ieee->iw_mode, batch_mode);
5532 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
5533 err = ipw2100_set_channel(priv, priv->channel, batch_mode);
5538 err = ipw2100_system_config(priv, batch_mode);
5542 err = ipw2100_set_tx_rates(priv, priv->tx_rates, batch_mode);
5546 /* Default to power mode OFF */
5547 err = ipw2100_set_power_mode(priv, IPW_POWER_MODE_CAM);
5551 err = ipw2100_set_rts_threshold(priv, priv->rts_threshold);
5555 if (priv->config & CFG_STATIC_BSSID)
5556 bssid = priv->bssid;
5559 err = ipw2100_set_mandatory_bssid(priv, bssid, batch_mode);
5563 if (priv->config & CFG_STATIC_ESSID)
5564 err = ipw2100_set_essid(priv, priv->essid, priv->essid_len,
5567 err = ipw2100_set_essid(priv, NULL, 0, batch_mode);
5571 err = ipw2100_configure_security(priv, batch_mode);
5575 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
5576 err = ipw2100_set_ibss_beacon_interval(
5577 priv, priv->beacon_interval, batch_mode);
5581 err = ipw2100_set_tx_power(priv, priv->tx_power);
5587 err = ipw2100_set_fragmentation_threshold(
5588 priv, priv->frag_threshold, batch_mode);
5593 IPW_DEBUG_INFO("exit\n");
5599 /*************************************************************************
5601 * EXTERNALLY CALLED METHODS
5603 *************************************************************************/
5605 /* This method is called by the network layer -- not to be confused with
5606 * ipw2100_set_mac_address() declared above called by this driver (and this
5607 * method as well) to talk to the firmware */
5608 static int ipw2100_set_address(struct net_device *dev, void *p)
5610 struct ipw2100_priv *priv = ieee80211_priv(dev);
5611 struct sockaddr *addr = p;
5614 if (!is_valid_ether_addr(addr->sa_data))
5615 return -EADDRNOTAVAIL;
5617 down(&priv->action_sem);
5619 priv->config |= CFG_CUSTOM_MAC;
5620 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
5622 err = ipw2100_set_mac_address(priv, 0);
5626 priv->reset_backoff = 0;
5627 up(&priv->action_sem);
5628 ipw2100_reset_adapter(priv);
5632 up(&priv->action_sem);
5636 static int ipw2100_open(struct net_device *dev)
5638 struct ipw2100_priv *priv = ieee80211_priv(dev);
5639 unsigned long flags;
5640 IPW_DEBUG_INFO("dev->open\n");
5642 spin_lock_irqsave(&priv->low_lock, flags);
5643 if (priv->status & STATUS_ASSOCIATED)
5644 netif_start_queue(dev);
5645 spin_unlock_irqrestore(&priv->low_lock, flags);
5650 static int ipw2100_close(struct net_device *dev)
5652 struct ipw2100_priv *priv = ieee80211_priv(dev);
5653 unsigned long flags;
5654 struct list_head *element;
5655 struct ipw2100_tx_packet *packet;
5657 IPW_DEBUG_INFO("enter\n");
5659 spin_lock_irqsave(&priv->low_lock, flags);
5661 if (priv->status & STATUS_ASSOCIATED)
5662 netif_carrier_off(dev);
5663 netif_stop_queue(dev);
5665 /* Flush the TX queue ... */
5666 while (!list_empty(&priv->tx_pend_list)) {
5667 element = priv->tx_pend_list.next;
5668 packet = list_entry(element, struct ipw2100_tx_packet, list);
5671 DEC_STAT(&priv->tx_pend_stat);
5673 ieee80211_txb_free(packet->info.d_struct.txb);
5674 packet->info.d_struct.txb = NULL;
5676 list_add_tail(element, &priv->tx_free_list);
5677 INC_STAT(&priv->tx_free_stat);
5679 spin_unlock_irqrestore(&priv->low_lock, flags);
5681 IPW_DEBUG_INFO("exit\n");
5689 * TODO: Fix this function... its just wrong
5691 static void ipw2100_tx_timeout(struct net_device *dev)
5693 struct ipw2100_priv *priv = ieee80211_priv(dev);
5695 priv->ieee->stats.tx_errors++;
5697 #ifdef CONFIG_IPW2100_MONITOR
5698 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
5702 IPW_DEBUG_INFO("%s: TX timed out. Scheduling firmware restart.\n",
5704 schedule_reset(priv);
5709 * TODO: reimplement it so that it reads statistics
5710 * from the adapter using ordinal tables
5711 * instead of/in addition to collecting them
5714 static struct net_device_stats *ipw2100_stats(struct net_device *dev)
5716 struct ipw2100_priv *priv = ieee80211_priv(dev);
5718 return &priv->ieee->stats;
5721 /* Support for wpa_supplicant. Will be replaced with WEXT once
5722 * they get WPA support. */
5723 #ifdef CONFIG_IEEE80211_WPA
5725 /* following definitions must match definitions in driver_ipw2100.c */
5727 #define IPW2100_IOCTL_WPA_SUPPLICANT SIOCIWFIRSTPRIV+30
5729 #define IPW2100_CMD_SET_WPA_PARAM 1
5730 #define IPW2100_CMD_SET_WPA_IE 2
5731 #define IPW2100_CMD_SET_ENCRYPTION 3
5732 #define IPW2100_CMD_MLME 4
5734 #define IPW2100_PARAM_WPA_ENABLED 1
5735 #define IPW2100_PARAM_TKIP_COUNTERMEASURES 2
5736 #define IPW2100_PARAM_DROP_UNENCRYPTED 3
5737 #define IPW2100_PARAM_PRIVACY_INVOKED 4
5738 #define IPW2100_PARAM_AUTH_ALGS 5
5739 #define IPW2100_PARAM_IEEE_802_1X 6
5741 #define IPW2100_MLME_STA_DEAUTH 1
5742 #define IPW2100_MLME_STA_DISASSOC 2
5744 #define IPW2100_CRYPT_ERR_UNKNOWN_ALG 2
5745 #define IPW2100_CRYPT_ERR_UNKNOWN_ADDR 3
5746 #define IPW2100_CRYPT_ERR_CRYPT_INIT_FAILED 4
5747 #define IPW2100_CRYPT_ERR_KEY_SET_FAILED 5
5748 #define IPW2100_CRYPT_ERR_TX_KEY_SET_FAILED 6
5749 #define IPW2100_CRYPT_ERR_CARD_CONF_FAILED 7
5751 #define IPW2100_CRYPT_ALG_NAME_LEN 16
5753 struct ipw2100_param {
5755 u8 sta_addr[ETH_ALEN];
5770 u8 alg[IPW2100_CRYPT_ALG_NAME_LEN];
5774 u8 seq[8]; /* sequence counter (set: RX, get: TX) */
5782 /* end of driver_ipw2100.c code */
5784 static int ipw2100_wpa_enable(struct ipw2100_priv *priv, int value){
5786 struct ieee80211_device *ieee = priv->ieee;
5787 struct ieee80211_security sec = {
5788 .flags = SEC_LEVEL | SEC_ENABLED,
5792 ieee->wpa_enabled = value;
5795 sec.level = SEC_LEVEL_3;
5798 sec.level = SEC_LEVEL_0;
5802 if (ieee->set_security)
5803 ieee->set_security(ieee->dev, &sec);
5810 #define AUTH_ALG_OPEN_SYSTEM 0x1
5811 #define AUTH_ALG_SHARED_KEY 0x2
5813 static int ipw2100_wpa_set_auth_algs(struct ipw2100_priv *priv, int value){
5815 struct ieee80211_device *ieee = priv->ieee;
5816 struct ieee80211_security sec = {
5817 .flags = SEC_AUTH_MODE,
5821 if (value & AUTH_ALG_SHARED_KEY){
5822 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
5825 sec.auth_mode = WLAN_AUTH_OPEN;
5829 if (ieee->set_security)
5830 ieee->set_security(ieee->dev, &sec);
5838 static int ipw2100_wpa_set_param(struct net_device *dev, u8 name, u32 value){
5840 struct ipw2100_priv *priv = ieee80211_priv(dev);
5844 case IPW2100_PARAM_WPA_ENABLED:
5845 ret = ipw2100_wpa_enable(priv, value);
5848 case IPW2100_PARAM_TKIP_COUNTERMEASURES:
5849 priv->ieee->tkip_countermeasures=value;
5852 case IPW2100_PARAM_DROP_UNENCRYPTED:
5853 priv->ieee->drop_unencrypted=value;
5856 case IPW2100_PARAM_PRIVACY_INVOKED:
5857 priv->ieee->privacy_invoked=value;
5860 case IPW2100_PARAM_AUTH_ALGS:
5861 ret = ipw2100_wpa_set_auth_algs(priv, value);
5864 case IPW2100_PARAM_IEEE_802_1X:
5865 priv->ieee->ieee802_1x=value;
5869 IPW_DEBUG_ERROR("%s: Unknown WPA param: %d\n",
5877 static int ipw2100_wpa_mlme(struct net_device *dev, int command, int reason){
5879 struct ipw2100_priv *priv = ieee80211_priv(dev);
5883 case IPW2100_MLME_STA_DEAUTH:
5887 case IPW2100_MLME_STA_DISASSOC:
5888 ipw2100_disassociate_bssid(priv);
5892 IPW_DEBUG_ERROR("%s: Unknown MLME request: %d\n",
5893 dev->name, command);
5901 void ipw2100_wpa_assoc_frame(struct ipw2100_priv *priv,
5902 char *wpa_ie, int wpa_ie_len){
5904 struct ipw2100_wpa_assoc_frame frame;
5906 frame.fixed_ie_mask = 0;
5909 memcpy(frame.var_ie, wpa_ie, wpa_ie_len);
5910 frame.var_ie_len = wpa_ie_len;
5912 /* make sure WPA is enabled */
5913 ipw2100_wpa_enable(priv, 1);
5914 ipw2100_set_wpa_ie(priv, &frame, 0);
5918 static int ipw2100_wpa_set_wpa_ie(struct net_device *dev,
5919 struct ipw2100_param *param, int plen){
5921 struct ipw2100_priv *priv = ieee80211_priv(dev);
5922 struct ieee80211_device *ieee = priv->ieee;
5925 if (! ieee->wpa_enabled)
5928 if (param->u.wpa_ie.len > MAX_WPA_IE_LEN ||
5929 (param->u.wpa_ie.len &&
5930 param->u.wpa_ie.data==NULL))
5933 if (param->u.wpa_ie.len){
5934 buf = kmalloc(param->u.wpa_ie.len, GFP_KERNEL);
5938 memcpy(buf, param->u.wpa_ie.data, param->u.wpa_ie.len);
5940 kfree(ieee->wpa_ie);
5942 ieee->wpa_ie_len = param->u.wpa_ie.len;
5945 kfree(ieee->wpa_ie);
5946 ieee->wpa_ie = NULL;
5947 ieee->wpa_ie_len = 0;
5950 ipw2100_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
5955 /* implementation borrowed from hostap driver */
5957 static int ipw2100_wpa_set_encryption(struct net_device *dev,
5958 struct ipw2100_param *param, int param_len){
5961 struct ipw2100_priv *priv = ieee80211_priv(dev);
5962 struct ieee80211_device *ieee = priv->ieee;
5963 struct ieee80211_crypto_ops *ops;
5964 struct ieee80211_crypt_data **crypt;
5966 struct ieee80211_security sec = {
5970 param->u.crypt.err = 0;
5971 param->u.crypt.alg[IPW2100_CRYPT_ALG_NAME_LEN - 1] = '\0';
5974 (int) ((char *) param->u.crypt.key - (char *) param) +
5975 param->u.crypt.key_len){
5976 IPW_DEBUG_INFO("Len mismatch %d, %d\n", param_len, param->u.crypt.key_len);
5979 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
5980 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
5981 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
5982 if (param->u.crypt.idx >= WEP_KEYS)
5984 crypt = &ieee->crypt[param->u.crypt.idx];
5989 if (strcmp(param->u.crypt.alg, "none") == 0) {
5992 sec.level = SEC_LEVEL_0;
5993 sec.flags |= SEC_ENABLED | SEC_LEVEL;
5994 ieee80211_crypt_delayed_deinit(ieee, crypt);
5999 sec.flags |= SEC_ENABLED;
6001 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6002 if (ops == NULL && strcmp(param->u.crypt.alg, "WEP") == 0) {
6003 request_module("ieee80211_crypt_wep");
6004 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6005 } else if (ops == NULL && strcmp(param->u.crypt.alg, "TKIP") == 0) {
6006 request_module("ieee80211_crypt_tkip");
6007 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6008 } else if (ops == NULL && strcmp(param->u.crypt.alg, "CCMP") == 0) {
6009 request_module("ieee80211_crypt_ccmp");
6010 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6013 IPW_DEBUG_INFO("%s: unknown crypto alg '%s'\n",
6014 dev->name, param->u.crypt.alg);
6015 param->u.crypt.err = IPW2100_CRYPT_ERR_UNKNOWN_ALG;
6020 if (*crypt == NULL || (*crypt)->ops != ops) {
6021 struct ieee80211_crypt_data *new_crypt;
6023 ieee80211_crypt_delayed_deinit(ieee, crypt);
6025 new_crypt = (struct ieee80211_crypt_data *)
6026 kmalloc(sizeof(struct ieee80211_crypt_data), GFP_KERNEL);
6027 if (new_crypt == NULL) {
6031 memset(new_crypt, 0, sizeof(struct ieee80211_crypt_data));
6032 new_crypt->ops = ops;
6033 if (new_crypt->ops && try_module_get(new_crypt->ops->owner))
6034 new_crypt->priv = new_crypt->ops->init(param->u.crypt.idx);
6036 if (new_crypt->priv == NULL) {
6038 param->u.crypt.err =
6039 IPW2100_CRYPT_ERR_CRYPT_INIT_FAILED;
6047 if (param->u.crypt.key_len > 0 && (*crypt)->ops->set_key &&
6048 (*crypt)->ops->set_key(param->u.crypt.key,
6049 param->u.crypt.key_len, param->u.crypt.seq,
6050 (*crypt)->priv) < 0) {
6051 IPW_DEBUG_INFO("%s: key setting failed\n",
6053 param->u.crypt.err = IPW2100_CRYPT_ERR_KEY_SET_FAILED;
6058 if (param->u.crypt.set_tx){
6059 ieee->tx_keyidx = param->u.crypt.idx;
6060 sec.active_key = param->u.crypt.idx;
6061 sec.flags |= SEC_ACTIVE_KEY;
6064 if (ops->name != NULL){
6066 if (strcmp(ops->name, "WEP") == 0) {
6067 memcpy(sec.keys[param->u.crypt.idx], param->u.crypt.key, param->u.crypt.key_len);
6068 sec.key_sizes[param->u.crypt.idx] = param->u.crypt.key_len;
6069 sec.flags |= (1 << param->u.crypt.idx);
6070 sec.flags |= SEC_LEVEL;
6071 sec.level = SEC_LEVEL_1;
6072 } else if (strcmp(ops->name, "TKIP") == 0) {
6073 sec.flags |= SEC_LEVEL;
6074 sec.level = SEC_LEVEL_2;
6075 } else if (strcmp(ops->name, "CCMP") == 0) {
6076 sec.flags |= SEC_LEVEL;
6077 sec.level = SEC_LEVEL_3;
6081 if (ieee->set_security)
6082 ieee->set_security(ieee->dev, &sec);
6084 /* Do not reset port if card is in Managed mode since resetting will
6085 * generate new IEEE 802.11 authentication which may end up in looping
6086 * with IEEE 802.1X. If your hardware requires a reset after WEP
6087 * configuration (for example... Prism2), implement the reset_port in
6088 * the callbacks structures used to initialize the 802.11 stack. */
6089 if (ieee->reset_on_keychange &&
6090 ieee->iw_mode != IW_MODE_INFRA &&
6092 ieee->reset_port(dev)) {
6093 IPW_DEBUG_INFO("%s: reset_port failed\n", dev->name);
6094 param->u.crypt.err = IPW2100_CRYPT_ERR_CARD_CONF_FAILED;
6102 static int ipw2100_wpa_supplicant(struct net_device *dev, struct iw_point *p){
6104 struct ipw2100_param *param;
6107 IPW_DEBUG_IOCTL("wpa_supplicant: len=%d\n", p->length);
6109 if (p->length < sizeof(struct ipw2100_param) || !p->pointer)
6112 param = (struct ipw2100_param *)kmalloc(p->length, GFP_KERNEL);
6116 if (copy_from_user(param, p->pointer, p->length)){
6121 switch (param->cmd){
6123 case IPW2100_CMD_SET_WPA_PARAM:
6124 ret = ipw2100_wpa_set_param(dev, param->u.wpa_param.name,
6125 param->u.wpa_param.value);
6128 case IPW2100_CMD_SET_WPA_IE:
6129 ret = ipw2100_wpa_set_wpa_ie(dev, param, p->length);
6132 case IPW2100_CMD_SET_ENCRYPTION:
6133 ret = ipw2100_wpa_set_encryption(dev, param, p->length);
6136 case IPW2100_CMD_MLME:
6137 ret = ipw2100_wpa_mlme(dev, param->u.mlme.command,
6138 param->u.mlme.reason_code);
6142 IPW_DEBUG_ERROR("%s: Unknown WPA supplicant request: %d\n",
6143 dev->name, param->cmd);
6148 if (ret == 0 && copy_to_user(p->pointer, param, p->length))
6154 #endif /* CONFIG_IEEE80211_WPA */
6156 static int ipw2100_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
6158 #ifdef CONFIG_IEEE80211_WPA
6159 struct iwreq *wrq = (struct iwreq *) rq;
6162 case IPW2100_IOCTL_WPA_SUPPLICANT:
6163 ret = ipw2100_wpa_supplicant(dev, &wrq->u.data);
6170 #endif /* CONFIG_IEEE80211_WPA */
6176 static void ipw_ethtool_get_drvinfo(struct net_device *dev,
6177 struct ethtool_drvinfo *info)
6179 struct ipw2100_priv *priv = ieee80211_priv(dev);
6180 char fw_ver[64], ucode_ver[64];
6182 strcpy(info->driver, DRV_NAME);
6183 strcpy(info->version, DRV_VERSION);
6185 ipw2100_get_fwversion(priv, fw_ver, sizeof(fw_ver));
6186 ipw2100_get_ucodeversion(priv, ucode_ver, sizeof(ucode_ver));
6188 snprintf(info->fw_version, sizeof(info->fw_version), "%s:%d:%s",
6189 fw_ver, priv->eeprom_version, ucode_ver);
6191 strcpy(info->bus_info, pci_name(priv->pci_dev));
6194 static u32 ipw2100_ethtool_get_link(struct net_device *dev)
6196 struct ipw2100_priv *priv = ieee80211_priv(dev);
6197 return (priv->status & STATUS_ASSOCIATED) ? 1 : 0;
6201 static struct ethtool_ops ipw2100_ethtool_ops = {
6202 .get_link = ipw2100_ethtool_get_link,
6203 .get_drvinfo = ipw_ethtool_get_drvinfo,
6206 static void ipw2100_hang_check(void *adapter)
6208 struct ipw2100_priv *priv = adapter;
6209 unsigned long flags;
6210 u32 rtc = 0xa5a5a5a5;
6211 u32 len = sizeof(rtc);
6214 spin_lock_irqsave(&priv->low_lock, flags);
6216 if (priv->fatal_error != 0) {
6217 /* If fatal_error is set then we need to restart */
6218 IPW_DEBUG_INFO("%s: Hardware fatal error detected.\n",
6219 priv->net_dev->name);
6222 } else if (ipw2100_get_ordinal(priv, IPW_ORD_RTC_TIME, &rtc, &len) ||
6223 (rtc == priv->last_rtc)) {
6224 /* Check if firmware is hung */
6225 IPW_DEBUG_INFO("%s: Firmware RTC stalled.\n",
6226 priv->net_dev->name);
6233 priv->stop_hang_check = 1;
6236 /* Restart the NIC */
6237 schedule_reset(priv);
6240 priv->last_rtc = rtc;
6242 if (!priv->stop_hang_check)
6243 queue_delayed_work(priv->workqueue, &priv->hang_check, HZ / 2);
6245 spin_unlock_irqrestore(&priv->low_lock, flags);
6249 static void ipw2100_rf_kill(void *adapter)
6251 struct ipw2100_priv *priv = adapter;
6252 unsigned long flags;
6254 spin_lock_irqsave(&priv->low_lock, flags);
6256 if (rf_kill_active(priv)) {
6257 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
6258 if (!priv->stop_rf_kill)
6259 queue_delayed_work(priv->workqueue, &priv->rf_kill, HZ);
6263 /* RF Kill is now disabled, so bring the device back up */
6265 if (!(priv->status & STATUS_RF_KILL_MASK)) {
6266 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
6268 schedule_reset(priv);
6270 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
6274 spin_unlock_irqrestore(&priv->low_lock, flags);
6277 static void ipw2100_irq_tasklet(struct ipw2100_priv *priv);
6279 /* Look into using netdev destructor to shutdown ieee80211? */
6281 static struct net_device *ipw2100_alloc_device(
6282 struct pci_dev *pci_dev,
6284 unsigned long mem_start,
6285 unsigned long mem_len)
6287 struct ipw2100_priv *priv;
6288 struct net_device *dev;
6290 dev = alloc_ieee80211(sizeof(struct ipw2100_priv));
6293 priv = ieee80211_priv(dev);
6294 priv->ieee = netdev_priv(dev);
6295 priv->pci_dev = pci_dev;
6296 priv->net_dev = dev;
6298 priv->ieee->hard_start_xmit = ipw2100_tx;
6299 priv->ieee->set_security = shim__set_security;
6301 dev->open = ipw2100_open;
6302 dev->stop = ipw2100_close;
6303 dev->init = ipw2100_net_init;
6304 dev->do_ioctl = ipw2100_ioctl;
6305 dev->get_stats = ipw2100_stats;
6306 dev->ethtool_ops = &ipw2100_ethtool_ops;
6307 dev->tx_timeout = ipw2100_tx_timeout;
6308 dev->wireless_handlers = &ipw2100_wx_handler_def;
6309 dev->get_wireless_stats = ipw2100_wx_wireless_stats;
6310 dev->set_mac_address = ipw2100_set_address;
6311 dev->watchdog_timeo = 3*HZ;
6314 dev->base_addr = (unsigned long)base_addr;
6315 dev->mem_start = mem_start;
6316 dev->mem_end = dev->mem_start + mem_len - 1;
6318 /* NOTE: We don't use the wireless_handlers hook
6319 * in dev as the system will start throwing WX requests
6320 * to us before we're actually initialized and it just
6321 * ends up causing problems. So, we just handle
6322 * the WX extensions through the ipw2100_ioctl interface */
6325 /* memset() puts everything to 0, so we only have explicitely set
6326 * those values that need to be something else */
6328 /* If power management is turned on, default to AUTO mode */
6329 priv->power_mode = IPW_POWER_AUTO;
6333 #ifdef CONFIG_IEEE80211_WPA
6334 priv->ieee->wpa_enabled = 0;
6335 priv->ieee->tkip_countermeasures = 0;
6336 priv->ieee->drop_unencrypted = 0;
6337 priv->ieee->privacy_invoked = 0;
6338 priv->ieee->ieee802_1x = 1;
6339 #endif /* CONFIG_IEEE80211_WPA */
6341 /* Set module parameters */
6344 priv->ieee->iw_mode = IW_MODE_ADHOC;
6346 #ifdef CONFIG_IPW2100_MONITOR
6348 priv->ieee->iw_mode = IW_MODE_MONITOR;
6353 priv->ieee->iw_mode = IW_MODE_INFRA;
6358 priv->status |= STATUS_RF_KILL_SW;
6361 ((channel >= REG_MIN_CHANNEL) &&
6362 (channel <= REG_MAX_CHANNEL))) {
6363 priv->config |= CFG_STATIC_CHANNEL;
6364 priv->channel = channel;
6368 priv->config |= CFG_ASSOCIATE;
6370 priv->beacon_interval = DEFAULT_BEACON_INTERVAL;
6371 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
6372 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
6373 priv->rts_threshold = DEFAULT_RTS_THRESHOLD | RTS_DISABLED;
6374 priv->frag_threshold = DEFAULT_FTS | FRAG_DISABLED;
6375 priv->tx_power = IPW_TX_POWER_DEFAULT;
6376 priv->tx_rates = DEFAULT_TX_RATES;
6378 strcpy(priv->nick, "ipw2100");
6380 spin_lock_init(&priv->low_lock);
6381 sema_init(&priv->action_sem, 1);
6382 sema_init(&priv->adapter_sem, 1);
6384 init_waitqueue_head(&priv->wait_command_queue);
6386 netif_carrier_off(dev);
6388 INIT_LIST_HEAD(&priv->msg_free_list);
6389 INIT_LIST_HEAD(&priv->msg_pend_list);
6390 INIT_STAT(&priv->msg_free_stat);
6391 INIT_STAT(&priv->msg_pend_stat);
6393 INIT_LIST_HEAD(&priv->tx_free_list);
6394 INIT_LIST_HEAD(&priv->tx_pend_list);
6395 INIT_STAT(&priv->tx_free_stat);
6396 INIT_STAT(&priv->tx_pend_stat);
6398 INIT_LIST_HEAD(&priv->fw_pend_list);
6399 INIT_STAT(&priv->fw_pend_stat);
6402 #ifdef CONFIG_SOFTWARE_SUSPEND2
6403 priv->workqueue = create_workqueue(DRV_NAME, 0);
6405 priv->workqueue = create_workqueue(DRV_NAME);
6407 INIT_WORK(&priv->reset_work,
6408 (void (*)(void *))ipw2100_reset_adapter, priv);
6409 INIT_WORK(&priv->security_work,
6410 (void (*)(void *))ipw2100_security_work, priv);
6411 INIT_WORK(&priv->wx_event_work,
6412 (void (*)(void *))ipw2100_wx_event_work, priv);
6413 INIT_WORK(&priv->hang_check, ipw2100_hang_check, priv);
6414 INIT_WORK(&priv->rf_kill, ipw2100_rf_kill, priv);
6416 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
6417 ipw2100_irq_tasklet, (unsigned long)priv);
6419 /* NOTE: We do not start the deferred work for status checks yet */
6420 priv->stop_rf_kill = 1;
6421 priv->stop_hang_check = 1;
6428 #define PCI_DMA_32BIT 0x00000000ffffffffULL
6430 static int ipw2100_pci_init_one(struct pci_dev *pci_dev,
6431 const struct pci_device_id *ent)
6433 unsigned long mem_start, mem_len, mem_flags;
6434 char *base_addr = NULL;
6435 struct net_device *dev = NULL;
6436 struct ipw2100_priv *priv = NULL;
6441 IPW_DEBUG_INFO("enter\n");
6443 mem_start = pci_resource_start(pci_dev, 0);
6444 mem_len = pci_resource_len(pci_dev, 0);
6445 mem_flags = pci_resource_flags(pci_dev, 0);
6447 if ((mem_flags & IORESOURCE_MEM) != IORESOURCE_MEM) {
6448 IPW_DEBUG_INFO("weird - resource type is not memory\n");
6453 base_addr = ioremap_nocache(mem_start, mem_len);
6455 printk(KERN_WARNING DRV_NAME
6456 "Error calling ioremap_nocache.\n");
6461 /* allocate and initialize our net_device */
6462 dev = ipw2100_alloc_device(pci_dev, base_addr, mem_start, mem_len);
6464 printk(KERN_WARNING DRV_NAME
6465 "Error calling ipw2100_alloc_device.\n");
6470 /* set up PCI mappings for device */
6471 err = pci_enable_device(pci_dev);
6473 printk(KERN_WARNING DRV_NAME
6474 "Error calling pci_enable_device.\n");
6478 priv = ieee80211_priv(dev);
6480 pci_set_master(pci_dev);
6481 pci_set_drvdata(pci_dev, priv);
6483 err = pci_set_dma_mask(pci_dev, PCI_DMA_32BIT);
6485 printk(KERN_WARNING DRV_NAME
6486 "Error calling pci_set_dma_mask.\n");
6487 pci_disable_device(pci_dev);
6491 err = pci_request_regions(pci_dev, DRV_NAME);
6493 printk(KERN_WARNING DRV_NAME
6494 "Error calling pci_request_regions.\n");
6495 pci_disable_device(pci_dev);
6499 /* We disable the RETRY_TIMEOUT register (0x41) to keep
6500 * PCI Tx retries from interfering with C3 CPU state */
6501 pci_read_config_dword(pci_dev, 0x40, &val);
6502 if ((val & 0x0000ff00) != 0)
6503 pci_write_config_dword(pci_dev, 0x40, val & 0xffff00ff);
6505 pci_set_power_state(pci_dev, 0);
6507 if (!ipw2100_hw_is_adapter_in_system(dev)) {
6508 printk(KERN_WARNING DRV_NAME
6509 "Device not found via register read.\n");
6514 SET_NETDEV_DEV(dev, &pci_dev->dev);
6516 /* Force interrupts to be shut off on the device */
6517 priv->status |= STATUS_INT_ENABLED;
6518 ipw2100_disable_interrupts(priv);
6520 /* Allocate and initialize the Tx/Rx queues and lists */
6521 if (ipw2100_queues_allocate(priv)) {
6522 printk(KERN_WARNING DRV_NAME
6523 "Error calilng ipw2100_queues_allocate.\n");
6527 ipw2100_queues_initialize(priv);
6529 err = request_irq(pci_dev->irq,
6530 ipw2100_interrupt, SA_SHIRQ,
6533 printk(KERN_WARNING DRV_NAME
6534 "Error calling request_irq: %d.\n",
6538 dev->irq = pci_dev->irq;
6540 IPW_DEBUG_INFO("Attempting to register device...\n");
6542 SET_MODULE_OWNER(dev);
6544 printk(KERN_INFO DRV_NAME
6545 ": Detected Intel PRO/Wireless 2100 Network Connection\n");
6547 /* Bring up the interface. Pre 0.46, after we registered the
6548 * network device we would call ipw2100_up. This introduced a race
6549 * condition with newer hotplug configurations (network was coming
6550 * up and making calls before the device was initialized).
6552 * If we called ipw2100_up before we registered the device, then the
6553 * device name wasn't registered. So, we instead use the net_dev->init
6554 * member to call a function that then just turns and calls ipw2100_up.
6555 * net_dev->init is called after name allocation but before the
6556 * notifier chain is called */
6557 down(&priv->action_sem);
6558 err = register_netdev(dev);
6560 printk(KERN_WARNING DRV_NAME
6561 "Error calling register_netdev.\n");
6566 IPW_DEBUG_INFO("%s: Bound to %s\n", dev->name, pci_name(pci_dev));
6568 /* perform this after register_netdev so that dev->name is set */
6569 sysfs_create_group(&pci_dev->dev.kobj, &ipw2100_attribute_group);
6570 netif_carrier_off(dev);
6572 /* If the RF Kill switch is disabled, go ahead and complete the
6573 * startup sequence */
6574 if (!(priv->status & STATUS_RF_KILL_MASK)) {
6575 /* Enable the adapter - sends HOST_COMPLETE */
6576 if (ipw2100_enable_adapter(priv)) {
6577 printk(KERN_WARNING DRV_NAME
6578 ": %s: failed in call to enable adapter.\n",
6579 priv->net_dev->name);
6580 ipw2100_hw_stop_adapter(priv);
6585 /* Start a scan . . . */
6586 ipw2100_set_scan_options(priv);
6587 ipw2100_start_scan(priv);
6590 IPW_DEBUG_INFO("exit\n");
6592 priv->status |= STATUS_INITIALIZED;
6594 up(&priv->action_sem);
6599 up(&priv->action_sem);
6604 unregister_netdev(dev);
6606 ipw2100_hw_stop_adapter(priv);
6608 ipw2100_disable_interrupts(priv);
6611 free_irq(dev->irq, priv);
6613 ipw2100_kill_workqueue(priv);
6615 /* These are safe to call even if they weren't allocated */
6616 ipw2100_queues_free(priv);
6617 sysfs_remove_group(&pci_dev->dev.kobj, &ipw2100_attribute_group);
6619 free_ieee80211(dev);
6620 pci_set_drvdata(pci_dev, NULL);
6624 iounmap((char*)base_addr);
6626 pci_release_regions(pci_dev);
6627 pci_disable_device(pci_dev);
6632 static void __devexit ipw2100_pci_remove_one(struct pci_dev *pci_dev)
6634 struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
6635 struct net_device *dev;
6638 down(&priv->action_sem);
6640 priv->status &= ~STATUS_INITIALIZED;
6642 dev = priv->net_dev;
6643 sysfs_remove_group(&pci_dev->dev.kobj, &ipw2100_attribute_group);
6646 if (ipw2100_firmware.version)
6647 ipw2100_release_firmware(priv, &ipw2100_firmware);
6649 /* Take down the hardware */
6652 /* Release the semaphore so that the network subsystem can
6653 * complete any needed calls into the driver... */
6654 up(&priv->action_sem);
6656 /* Unregister the device first - this results in close()
6657 * being called if the device is open. If we free storage
6658 * first, then close() will crash. */
6659 unregister_netdev(dev);
6661 /* ipw2100_down will ensure that there is no more pending work
6662 * in the workqueue's, so we can safely remove them now. */
6663 ipw2100_kill_workqueue(priv);
6665 ipw2100_queues_free(priv);
6667 /* Free potential debugging firmware snapshot */
6668 ipw2100_snapshot_free(priv);
6671 free_irq(dev->irq, priv);
6674 iounmap((unsigned char *)dev->base_addr);
6676 free_ieee80211(dev);
6679 pci_release_regions(pci_dev);
6680 pci_disable_device(pci_dev);
6682 IPW_DEBUG_INFO("exit\n");
6687 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11)
6688 static int ipw2100_suspend(struct pci_dev *pci_dev, u32 state)
6690 static int ipw2100_suspend(struct pci_dev *pci_dev, pm_message_t state)
6693 struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
6694 struct net_device *dev = priv->net_dev;
6696 IPW_DEBUG_INFO("%s: Going into suspend...\n",
6699 down(&priv->action_sem);
6700 if (priv->status & STATUS_INITIALIZED) {
6701 /* Take down the device; powers it off, etc. */
6705 /* Remove the PRESENT state of the device */
6706 netif_device_detach(dev);
6708 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)
6709 pci_save_state(pci_dev, priv->pm_state);
6711 pci_save_state(pci_dev);
6713 pci_disable_device (pci_dev);
6714 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11)
6715 pci_set_power_state(pci_dev, state);
6717 pci_set_power_state(pci_dev, PCI_D3hot);
6720 up(&priv->action_sem);
6725 static int ipw2100_resume(struct pci_dev *pci_dev)
6727 struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
6728 struct net_device *dev = priv->net_dev;
6731 if (IPW2100_PM_DISABLED)
6734 down(&priv->action_sem);
6736 IPW_DEBUG_INFO("%s: Coming out of suspend...\n",
6739 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11)
6740 pci_set_power_state(pci_dev, 0);
6742 pci_set_power_state(pci_dev, PCI_D0);
6744 pci_enable_device(pci_dev);
6745 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)
6746 pci_restore_state(pci_dev, priv->pm_state);
6748 pci_restore_state(pci_dev);
6752 * Suspend/Resume resets the PCI configuration space, so we have to
6753 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
6754 * from interfering with C3 CPU state. pci_restore_state won't help
6755 * here since it only restores the first 64 bytes pci config header.
6757 pci_read_config_dword(pci_dev, 0x40, &val);
6758 if ((val & 0x0000ff00) != 0)
6759 pci_write_config_dword(pci_dev, 0x40, val & 0xffff00ff);
6761 /* Set the device back into the PRESENT state; this will also wake
6762 * the queue of needed */
6763 netif_device_attach(dev);
6765 /* Bring the device back up */
6766 if (!(priv->status & STATUS_RF_KILL_SW))
6767 ipw2100_up(priv, 0);
6769 up(&priv->action_sem);
6776 #define IPW2100_DEV_ID(x) { PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, x }
6778 static struct pci_device_id ipw2100_pci_id_table[] __devinitdata = {
6779 IPW2100_DEV_ID(0x2520), /* IN 2100A mPCI 3A */
6780 IPW2100_DEV_ID(0x2521), /* IN 2100A mPCI 3B */
6781 IPW2100_DEV_ID(0x2524), /* IN 2100A mPCI 3B */
6782 IPW2100_DEV_ID(0x2525), /* IN 2100A mPCI 3B */
6783 IPW2100_DEV_ID(0x2526), /* IN 2100A mPCI Gen A3 */
6784 IPW2100_DEV_ID(0x2522), /* IN 2100 mPCI 3B */
6785 IPW2100_DEV_ID(0x2523), /* IN 2100 mPCI 3A */
6786 IPW2100_DEV_ID(0x2527), /* IN 2100 mPCI 3B */
6787 IPW2100_DEV_ID(0x2528), /* IN 2100 mPCI 3B */
6788 IPW2100_DEV_ID(0x2529), /* IN 2100 mPCI 3B */
6789 IPW2100_DEV_ID(0x252B), /* IN 2100 mPCI 3A */
6790 IPW2100_DEV_ID(0x252C), /* IN 2100 mPCI 3A */
6791 IPW2100_DEV_ID(0x252D), /* IN 2100 mPCI 3A */
6793 IPW2100_DEV_ID(0x2550), /* IB 2100A mPCI 3B */
6794 IPW2100_DEV_ID(0x2551), /* IB 2100 mPCI 3B */
6795 IPW2100_DEV_ID(0x2553), /* IB 2100 mPCI 3B */
6796 IPW2100_DEV_ID(0x2554), /* IB 2100 mPCI 3B */
6797 IPW2100_DEV_ID(0x2555), /* IB 2100 mPCI 3B */
6799 IPW2100_DEV_ID(0x2560), /* DE 2100A mPCI 3A */
6800 IPW2100_DEV_ID(0x2562), /* DE 2100A mPCI 3A */
6801 IPW2100_DEV_ID(0x2563), /* DE 2100A mPCI 3A */
6802 IPW2100_DEV_ID(0x2561), /* DE 2100 mPCI 3A */
6803 IPW2100_DEV_ID(0x2565), /* DE 2100 mPCI 3A */
6804 IPW2100_DEV_ID(0x2566), /* DE 2100 mPCI 3A */
6805 IPW2100_DEV_ID(0x2567), /* DE 2100 mPCI 3A */
6807 IPW2100_DEV_ID(0x2570), /* GA 2100 mPCI 3B */
6809 IPW2100_DEV_ID(0x2580), /* TO 2100A mPCI 3B */
6810 IPW2100_DEV_ID(0x2582), /* TO 2100A mPCI 3B */
6811 IPW2100_DEV_ID(0x2583), /* TO 2100A mPCI 3B */
6812 IPW2100_DEV_ID(0x2581), /* TO 2100 mPCI 3B */
6813 IPW2100_DEV_ID(0x2585), /* TO 2100 mPCI 3B */
6814 IPW2100_DEV_ID(0x2586), /* TO 2100 mPCI 3B */
6815 IPW2100_DEV_ID(0x2587), /* TO 2100 mPCI 3B */
6817 IPW2100_DEV_ID(0x2590), /* SO 2100A mPCI 3B */
6818 IPW2100_DEV_ID(0x2592), /* SO 2100A mPCI 3B */
6819 IPW2100_DEV_ID(0x2591), /* SO 2100 mPCI 3B */
6820 IPW2100_DEV_ID(0x2593), /* SO 2100 mPCI 3B */
6821 IPW2100_DEV_ID(0x2596), /* SO 2100 mPCI 3B */
6822 IPW2100_DEV_ID(0x2598), /* SO 2100 mPCI 3B */
6824 IPW2100_DEV_ID(0x25A0), /* HP 2100 mPCI 3B */
6828 MODULE_DEVICE_TABLE(pci, ipw2100_pci_id_table);
6830 static struct pci_driver ipw2100_pci_driver = {
6832 .id_table = ipw2100_pci_id_table,
6833 .probe = ipw2100_pci_init_one,
6834 .remove = __devexit_p(ipw2100_pci_remove_one),
6836 .suspend = ipw2100_suspend,
6837 .resume = ipw2100_resume,
6843 * Initialize the ipw2100 driver/module
6845 * @returns 0 if ok, < 0 errno node con error.
6847 * Note: we cannot init the /proc stuff until the PCI driver is there,
6848 * or we risk an unlikely race condition on someone accessing
6849 * uninitialized data in the PCI dev struct through /proc.
6851 static int __init ipw2100_init(void)
6855 printk(KERN_INFO DRV_NAME ": %s, %s\n", DRV_DESCRIPTION, DRV_VERSION);
6856 printk(KERN_INFO DRV_NAME ": %s\n", DRV_COPYRIGHT);
6858 #ifdef CONFIG_IEEE80211_NOWEP
6859 IPW_DEBUG_INFO(DRV_NAME ": Compiled with WEP disabled.\n");
6862 ret = pci_module_init(&ipw2100_pci_driver);
6864 #ifdef CONFIG_IPW_DEBUG
6865 ipw2100_debug_level = debug;
6866 driver_create_file(&ipw2100_pci_driver.driver,
6867 &driver_attr_debug_level);
6875 * Cleanup ipw2100 driver registration
6877 static void __exit ipw2100_exit(void)
6879 /* FIXME: IPG: check that we have no instances of the devices open */
6880 #ifdef CONFIG_IPW_DEBUG
6881 driver_remove_file(&ipw2100_pci_driver.driver,
6882 &driver_attr_debug_level);
6884 pci_unregister_driver(&ipw2100_pci_driver);
6887 module_init(ipw2100_init);
6888 module_exit(ipw2100_exit);
6890 #define WEXT_USECHANNELS 1
6892 const long ipw2100_frequencies[] = {
6893 2412, 2417, 2422, 2427,
6894 2432, 2437, 2442, 2447,
6895 2452, 2457, 2462, 2467,
6899 #define FREQ_COUNT (sizeof(ipw2100_frequencies) / \
6900 sizeof(ipw2100_frequencies[0]))
6902 const long ipw2100_rates_11b[] = {
6909 #define RATE_COUNT (sizeof(ipw2100_rates_11b) / sizeof(ipw2100_rates_11b[0]))
6911 static int ipw2100_wx_get_name(struct net_device *dev,
6912 struct iw_request_info *info,
6913 union iwreq_data *wrqu, char *extra)
6916 * This can be called at any time. No action lock required
6919 struct ipw2100_priv *priv = ieee80211_priv(dev);
6920 if (!(priv->status & STATUS_ASSOCIATED))
6921 strcpy(wrqu->name, "unassociated");
6923 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11b");
6925 IPW_DEBUG_WX("Name: %s\n", wrqu->name);
6930 static int ipw2100_wx_set_freq(struct net_device *dev,
6931 struct iw_request_info *info,
6932 union iwreq_data *wrqu, char *extra)
6934 struct ipw2100_priv *priv = ieee80211_priv(dev);
6935 struct iw_freq *fwrq = &wrqu->freq;
6938 if (priv->ieee->iw_mode == IW_MODE_INFRA)
6941 down(&priv->action_sem);
6942 if (!(priv->status & STATUS_INITIALIZED)) {
6947 /* if setting by freq convert to channel */
6949 if ((fwrq->m >= (int) 2.412e8 &&
6950 fwrq->m <= (int) 2.487e8)) {
6951 int f = fwrq->m / 100000;
6954 while ((c < REG_MAX_CHANNEL) &&
6955 (f != ipw2100_frequencies[c]))
6958 /* hack to fall through */
6964 if (fwrq->e > 0 || fwrq->m > 1000)
6966 else { /* Set the channel */
6967 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
6968 err = ipw2100_set_channel(priv, fwrq->m, 0);
6972 up(&priv->action_sem);
6977 static int ipw2100_wx_get_freq(struct net_device *dev,
6978 struct iw_request_info *info,
6979 union iwreq_data *wrqu, char *extra)
6982 * This can be called at any time. No action lock required
6985 struct ipw2100_priv *priv = ieee80211_priv(dev);
6989 /* If we are associated, trying to associate, or have a statically
6990 * configured CHANNEL then return that; otherwise return ANY */
6991 if (priv->config & CFG_STATIC_CHANNEL ||
6992 priv->status & STATUS_ASSOCIATED)
6993 wrqu->freq.m = priv->channel;
6997 IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
7002 static int ipw2100_wx_set_mode(struct net_device *dev,
7003 struct iw_request_info *info,
7004 union iwreq_data *wrqu, char *extra)
7006 struct ipw2100_priv *priv = ieee80211_priv(dev);
7009 IPW_DEBUG_WX("SET Mode -> %d \n", wrqu->mode);
7011 if (wrqu->mode == priv->ieee->iw_mode)
7014 down(&priv->action_sem);
7015 if (!(priv->status & STATUS_INITIALIZED)) {
7020 switch (wrqu->mode) {
7021 #ifdef CONFIG_IPW2100_MONITOR
7022 case IW_MODE_MONITOR:
7023 err = ipw2100_switch_mode(priv, IW_MODE_MONITOR);
7025 #endif /* CONFIG_IPW2100_MONITOR */
7027 err = ipw2100_switch_mode(priv, IW_MODE_ADHOC);
7032 err = ipw2100_switch_mode(priv, IW_MODE_INFRA);
7037 up(&priv->action_sem);
7041 static int ipw2100_wx_get_mode(struct net_device *dev,
7042 struct iw_request_info *info,
7043 union iwreq_data *wrqu, char *extra)
7046 * This can be called at any time. No action lock required
7049 struct ipw2100_priv *priv = ieee80211_priv(dev);
7051 wrqu->mode = priv->ieee->iw_mode;
7052 IPW_DEBUG_WX("GET Mode -> %d\n", wrqu->mode);
7058 #define POWER_MODES 5
7060 /* Values are in microsecond */
7061 const s32 timeout_duration[POWER_MODES] = {
7069 const s32 period_duration[POWER_MODES] = {
7077 static int ipw2100_wx_get_range(struct net_device *dev,
7078 struct iw_request_info *info,
7079 union iwreq_data *wrqu, char *extra)
7082 * This can be called at any time. No action lock required
7085 struct ipw2100_priv *priv = ieee80211_priv(dev);
7086 struct iw_range *range = (struct iw_range *)extra;
7090 wrqu->data.length = sizeof(*range);
7091 memset(range, 0, sizeof(*range));
7093 /* Let's try to keep this struct in the same order as in
7094 * linux/include/wireless.h
7097 /* TODO: See what values we can set, and remove the ones we can't
7098 * set, or fill them with some default data.
7101 /* ~5 Mb/s real (802.11b) */
7102 range->throughput = 5 * 1000 * 1000;
7104 // range->sensitivity; /* signal level threshold range */
7106 range->max_qual.qual = 100;
7107 /* TODO: Find real max RSSI and stick here */
7108 range->max_qual.level = 0;
7109 range->max_qual.noise = 0;
7110 range->max_qual.updated = 7; /* Updated all three */
7112 range->avg_qual.qual = 70; /* > 8% missed beacons is 'bad' */
7113 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
7114 range->avg_qual.level = 20 + IPW2100_RSSI_TO_DBM;
7115 range->avg_qual.noise = 0;
7116 range->avg_qual.updated = 7; /* Updated all three */
7118 range->num_bitrates = RATE_COUNT;
7120 for (i = 0; i < RATE_COUNT && i < IW_MAX_BITRATES; i++) {
7121 range->bitrate[i] = ipw2100_rates_11b[i];
7124 range->min_rts = MIN_RTS_THRESHOLD;
7125 range->max_rts = MAX_RTS_THRESHOLD;
7126 range->min_frag = MIN_FRAG_THRESHOLD;
7127 range->max_frag = MAX_FRAG_THRESHOLD;
7129 range->min_pmp = period_duration[0]; /* Minimal PM period */
7130 range->max_pmp = period_duration[POWER_MODES-1];/* Maximal PM period */
7131 range->min_pmt = timeout_duration[POWER_MODES-1]; /* Minimal PM timeout */
7132 range->max_pmt = timeout_duration[0];/* Maximal PM timeout */
7134 /* How to decode max/min PM period */
7135 range->pmp_flags = IW_POWER_PERIOD;
7136 /* How to decode max/min PM period */
7137 range->pmt_flags = IW_POWER_TIMEOUT;
7138 /* What PM options are supported */
7139 range->pm_capa = IW_POWER_TIMEOUT | IW_POWER_PERIOD;
7141 range->encoding_size[0] = 5;
7142 range->encoding_size[1] = 13; /* Different token sizes */
7143 range->num_encoding_sizes = 2; /* Number of entry in the list */
7144 range->max_encoding_tokens = WEP_KEYS; /* Max number of tokens */
7145 // range->encoding_login_index; /* token index for login token */
7147 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7148 range->txpower_capa = IW_TXPOW_DBM;
7149 range->num_txpower = IW_MAX_TXPOWER;
7150 for (i = 0, level = (IPW_TX_POWER_MAX_DBM * 16); i < IW_MAX_TXPOWER;
7151 i++, level -= ((IPW_TX_POWER_MAX_DBM - IPW_TX_POWER_MIN_DBM) * 16) /
7152 (IW_MAX_TXPOWER - 1))
7153 range->txpower[i] = level / 16;
7155 range->txpower_capa = 0;
7156 range->num_txpower = 0;
7160 /* Set the Wireless Extension versions */
7161 range->we_version_compiled = WIRELESS_EXT;
7162 range->we_version_source = 16;
7164 // range->retry_capa; /* What retry options are supported */
7165 // range->retry_flags; /* How to decode max/min retry limit */
7166 // range->r_time_flags; /* How to decode max/min retry life */
7167 // range->min_retry; /* Minimal number of retries */
7168 // range->max_retry; /* Maximal number of retries */
7169 // range->min_r_time; /* Minimal retry lifetime */
7170 // range->max_r_time; /* Maximal retry lifetime */
7172 range->num_channels = FREQ_COUNT;
7175 for (i = 0; i < FREQ_COUNT; i++) {
7176 // TODO: Include only legal frequencies for some countries
7177 // if (local->channel_mask & (1 << i)) {
7178 range->freq[val].i = i + 1;
7179 range->freq[val].m = ipw2100_frequencies[i] * 100000;
7180 range->freq[val].e = 1;
7183 if (val == IW_MAX_FREQUENCIES)
7186 range->num_frequency = val;
7188 IPW_DEBUG_WX("GET Range\n");
7193 static int ipw2100_wx_set_wap(struct net_device *dev,
7194 struct iw_request_info *info,
7195 union iwreq_data *wrqu, char *extra)
7197 struct ipw2100_priv *priv = ieee80211_priv(dev);
7200 static const unsigned char any[] = {
7201 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
7203 static const unsigned char off[] = {
7204 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
7208 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
7211 down(&priv->action_sem);
7212 if (!(priv->status & STATUS_INITIALIZED)) {
7217 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
7218 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
7219 /* we disable mandatory BSSID association */
7220 IPW_DEBUG_WX("exit - disable mandatory BSSID\n");
7221 priv->config &= ~CFG_STATIC_BSSID;
7222 err = ipw2100_set_mandatory_bssid(priv, NULL, 0);
7226 priv->config |= CFG_STATIC_BSSID;
7227 memcpy(priv->mandatory_bssid_mac, wrqu->ap_addr.sa_data, ETH_ALEN);
7229 err = ipw2100_set_mandatory_bssid(priv, wrqu->ap_addr.sa_data, 0);
7231 IPW_DEBUG_WX("SET BSSID -> %02X:%02X:%02X:%02X:%02X:%02X\n",
7232 wrqu->ap_addr.sa_data[0] & 0xff,
7233 wrqu->ap_addr.sa_data[1] & 0xff,
7234 wrqu->ap_addr.sa_data[2] & 0xff,
7235 wrqu->ap_addr.sa_data[3] & 0xff,
7236 wrqu->ap_addr.sa_data[4] & 0xff,
7237 wrqu->ap_addr.sa_data[5] & 0xff);
7240 up(&priv->action_sem);
7244 static int ipw2100_wx_get_wap(struct net_device *dev,
7245 struct iw_request_info *info,
7246 union iwreq_data *wrqu, char *extra)
7249 * This can be called at any time. No action lock required
7252 struct ipw2100_priv *priv = ieee80211_priv(dev);
7254 /* If we are associated, trying to associate, or have a statically
7255 * configured BSSID then return that; otherwise return ANY */
7256 if (priv->config & CFG_STATIC_BSSID ||
7257 priv->status & STATUS_ASSOCIATED) {
7258 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
7259 memcpy(wrqu->ap_addr.sa_data, &priv->bssid, ETH_ALEN);
7261 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
7263 IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n",
7264 MAC_ARG(wrqu->ap_addr.sa_data));
7268 static int ipw2100_wx_set_essid(struct net_device *dev,
7269 struct iw_request_info *info,
7270 union iwreq_data *wrqu, char *extra)
7272 struct ipw2100_priv *priv = ieee80211_priv(dev);
7273 char *essid = ""; /* ANY */
7277 down(&priv->action_sem);
7278 if (!(priv->status & STATUS_INITIALIZED)) {
7283 if (wrqu->essid.flags && wrqu->essid.length) {
7284 length = wrqu->essid.length - 1;
7289 IPW_DEBUG_WX("Setting ESSID to ANY\n");
7290 priv->config &= ~CFG_STATIC_ESSID;
7291 err = ipw2100_set_essid(priv, NULL, 0, 0);
7295 length = min(length, IW_ESSID_MAX_SIZE);
7297 priv->config |= CFG_STATIC_ESSID;
7299 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
7300 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
7305 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length),
7308 priv->essid_len = length;
7309 memcpy(priv->essid, essid, priv->essid_len);
7311 err = ipw2100_set_essid(priv, essid, length, 0);
7314 up(&priv->action_sem);
7318 static int ipw2100_wx_get_essid(struct net_device *dev,
7319 struct iw_request_info *info,
7320 union iwreq_data *wrqu, char *extra)
7323 * This can be called at any time. No action lock required
7326 struct ipw2100_priv *priv = ieee80211_priv(dev);
7328 /* If we are associated, trying to associate, or have a statically
7329 * configured ESSID then return that; otherwise return ANY */
7330 if (priv->config & CFG_STATIC_ESSID ||
7331 priv->status & STATUS_ASSOCIATED) {
7332 IPW_DEBUG_WX("Getting essid: '%s'\n",
7333 escape_essid(priv->essid, priv->essid_len));
7334 memcpy(extra, priv->essid, priv->essid_len);
7335 wrqu->essid.length = priv->essid_len;
7336 wrqu->essid.flags = 1; /* active */
7338 IPW_DEBUG_WX("Getting essid: ANY\n");
7339 wrqu->essid.length = 0;
7340 wrqu->essid.flags = 0; /* active */
7346 static int ipw2100_wx_set_nick(struct net_device *dev,
7347 struct iw_request_info *info,
7348 union iwreq_data *wrqu, char *extra)
7351 * This can be called at any time. No action lock required
7354 struct ipw2100_priv *priv = ieee80211_priv(dev);
7356 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
7359 wrqu->data.length = min((size_t)wrqu->data.length, sizeof(priv->nick));
7360 memset(priv->nick, 0, sizeof(priv->nick));
7361 memcpy(priv->nick, extra, wrqu->data.length);
7363 IPW_DEBUG_WX("SET Nickname -> %s \n", priv->nick);
7368 static int ipw2100_wx_get_nick(struct net_device *dev,
7369 struct iw_request_info *info,
7370 union iwreq_data *wrqu, char *extra)
7373 * This can be called at any time. No action lock required
7376 struct ipw2100_priv *priv = ieee80211_priv(dev);
7378 wrqu->data.length = strlen(priv->nick) + 1;
7379 memcpy(extra, priv->nick, wrqu->data.length);
7380 wrqu->data.flags = 1; /* active */
7382 IPW_DEBUG_WX("GET Nickname -> %s \n", extra);
7387 static int ipw2100_wx_set_rate(struct net_device *dev,
7388 struct iw_request_info *info,
7389 union iwreq_data *wrqu, char *extra)
7391 struct ipw2100_priv *priv = ieee80211_priv(dev);
7392 u32 target_rate = wrqu->bitrate.value;
7396 down(&priv->action_sem);
7397 if (!(priv->status & STATUS_INITIALIZED)) {
7404 if (target_rate == 1000000 ||
7405 (!wrqu->bitrate.fixed && target_rate > 1000000))
7406 rate |= TX_RATE_1_MBIT;
7407 if (target_rate == 2000000 ||
7408 (!wrqu->bitrate.fixed && target_rate > 2000000))
7409 rate |= TX_RATE_2_MBIT;
7410 if (target_rate == 5500000 ||
7411 (!wrqu->bitrate.fixed && target_rate > 5500000))
7412 rate |= TX_RATE_5_5_MBIT;
7413 if (target_rate == 11000000 ||
7414 (!wrqu->bitrate.fixed && target_rate > 11000000))
7415 rate |= TX_RATE_11_MBIT;
7417 rate = DEFAULT_TX_RATES;
7419 err = ipw2100_set_tx_rates(priv, rate, 0);
7421 IPW_DEBUG_WX("SET Rate -> %04X \n", rate);
7423 up(&priv->action_sem);
7428 static int ipw2100_wx_get_rate(struct net_device *dev,
7429 struct iw_request_info *info,
7430 union iwreq_data *wrqu, char *extra)
7432 struct ipw2100_priv *priv = ieee80211_priv(dev);
7434 int len = sizeof(val);
7437 if (!(priv->status & STATUS_ENABLED) ||
7438 priv->status & STATUS_RF_KILL_MASK ||
7439 !(priv->status & STATUS_ASSOCIATED)) {
7440 wrqu->bitrate.value = 0;
7444 down(&priv->action_sem);
7445 if (!(priv->status & STATUS_INITIALIZED)) {
7450 err = ipw2100_get_ordinal(priv, IPW_ORD_CURRENT_TX_RATE, &val, &len);
7452 IPW_DEBUG_WX("failed querying ordinals.\n");
7456 switch (val & TX_RATE_MASK) {
7457 case TX_RATE_1_MBIT:
7458 wrqu->bitrate.value = 1000000;
7460 case TX_RATE_2_MBIT:
7461 wrqu->bitrate.value = 2000000;
7463 case TX_RATE_5_5_MBIT:
7464 wrqu->bitrate.value = 5500000;
7466 case TX_RATE_11_MBIT:
7467 wrqu->bitrate.value = 11000000;
7470 wrqu->bitrate.value = 0;
7473 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
7476 up(&priv->action_sem);
7480 static int ipw2100_wx_set_rts(struct net_device *dev,
7481 struct iw_request_info *info,
7482 union iwreq_data *wrqu, char *extra)
7484 struct ipw2100_priv *priv = ieee80211_priv(dev);
7487 /* Auto RTS not yet supported */
7488 if (wrqu->rts.fixed == 0)
7491 down(&priv->action_sem);
7492 if (!(priv->status & STATUS_INITIALIZED)) {
7497 if (wrqu->rts.disabled)
7498 value = priv->rts_threshold | RTS_DISABLED;
7500 if (wrqu->rts.value < 1 ||
7501 wrqu->rts.value > 2304) {
7505 value = wrqu->rts.value;
7508 err = ipw2100_set_rts_threshold(priv, value);
7510 IPW_DEBUG_WX("SET RTS Threshold -> 0x%08X \n", value);
7512 up(&priv->action_sem);
7516 static int ipw2100_wx_get_rts(struct net_device *dev,
7517 struct iw_request_info *info,
7518 union iwreq_data *wrqu, char *extra)
7521 * This can be called at any time. No action lock required
7524 struct ipw2100_priv *priv = ieee80211_priv(dev);
7526 wrqu->rts.value = priv->rts_threshold & ~RTS_DISABLED;
7527 wrqu->rts.fixed = 1; /* no auto select */
7529 /* If RTS is set to the default value, then it is disabled */
7530 wrqu->rts.disabled = (priv->rts_threshold & RTS_DISABLED) ? 1 : 0;
7532 IPW_DEBUG_WX("GET RTS Threshold -> 0x%08X \n", wrqu->rts.value);
7537 static int ipw2100_wx_set_txpow(struct net_device *dev,
7538 struct iw_request_info *info,
7539 union iwreq_data *wrqu, char *extra)
7541 struct ipw2100_priv *priv = ieee80211_priv(dev);
7544 if (priv->ieee->iw_mode != IW_MODE_ADHOC)
7547 if (wrqu->txpower.disabled == 1 || wrqu->txpower.fixed == 0)
7548 value = IPW_TX_POWER_DEFAULT;
7550 if (wrqu->txpower.value < IPW_TX_POWER_MIN_DBM ||
7551 wrqu->txpower.value > IPW_TX_POWER_MAX_DBM)
7554 value = (wrqu->txpower.value - IPW_TX_POWER_MIN_DBM) * 16 /
7555 (IPW_TX_POWER_MAX_DBM - IPW_TX_POWER_MIN_DBM);
7558 down(&priv->action_sem);
7559 if (!(priv->status & STATUS_INITIALIZED)) {
7564 err = ipw2100_set_tx_power(priv, value);
7566 IPW_DEBUG_WX("SET TX Power -> %d \n", value);
7569 up(&priv->action_sem);
7573 static int ipw2100_wx_get_txpow(struct net_device *dev,
7574 struct iw_request_info *info,
7575 union iwreq_data *wrqu, char *extra)
7578 * This can be called at any time. No action lock required
7581 struct ipw2100_priv *priv = ieee80211_priv(dev);
7583 if (priv->ieee->iw_mode != IW_MODE_ADHOC) {
7584 wrqu->power.disabled = 1;
7588 if (priv->tx_power == IPW_TX_POWER_DEFAULT) {
7589 wrqu->power.fixed = 0;
7590 wrqu->power.value = IPW_TX_POWER_MAX_DBM;
7591 wrqu->power.disabled = 1;
7593 wrqu->power.disabled = 0;
7594 wrqu->power.fixed = 1;
7597 (IPW_TX_POWER_MAX_DBM - IPW_TX_POWER_MIN_DBM)) /
7598 (IPW_TX_POWER_MAX - IPW_TX_POWER_MIN) +
7599 IPW_TX_POWER_MIN_DBM;
7602 wrqu->power.flags = IW_TXPOW_DBM;
7604 IPW_DEBUG_WX("GET TX Power -> %d \n", wrqu->power.value);
7609 static int ipw2100_wx_set_frag(struct net_device *dev,
7610 struct iw_request_info *info,
7611 union iwreq_data *wrqu, char *extra)
7614 * This can be called at any time. No action lock required
7617 struct ipw2100_priv *priv = ieee80211_priv(dev);
7619 if (!wrqu->frag.fixed)
7622 if (wrqu->frag.disabled) {
7623 priv->frag_threshold |= FRAG_DISABLED;
7624 priv->ieee->fts = DEFAULT_FTS;
7626 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
7627 wrqu->frag.value > MAX_FRAG_THRESHOLD)
7630 priv->ieee->fts = wrqu->frag.value & ~0x1;
7631 priv->frag_threshold = priv->ieee->fts;
7634 IPW_DEBUG_WX("SET Frag Threshold -> %d \n", priv->ieee->fts);
7639 static int ipw2100_wx_get_frag(struct net_device *dev,
7640 struct iw_request_info *info,
7641 union iwreq_data *wrqu, char *extra)
7644 * This can be called at any time. No action lock required
7647 struct ipw2100_priv *priv = ieee80211_priv(dev);
7648 wrqu->frag.value = priv->frag_threshold & ~FRAG_DISABLED;
7649 wrqu->frag.fixed = 0; /* no auto select */
7650 wrqu->frag.disabled = (priv->frag_threshold & FRAG_DISABLED) ? 1 : 0;
7652 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
7657 static int ipw2100_wx_set_retry(struct net_device *dev,
7658 struct iw_request_info *info,
7659 union iwreq_data *wrqu, char *extra)
7661 struct ipw2100_priv *priv = ieee80211_priv(dev);
7664 if (wrqu->retry.flags & IW_RETRY_LIFETIME ||
7665 wrqu->retry.disabled)
7668 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
7671 down(&priv->action_sem);
7672 if (!(priv->status & STATUS_INITIALIZED)) {
7677 if (wrqu->retry.flags & IW_RETRY_MIN) {
7678 err = ipw2100_set_short_retry(priv, wrqu->retry.value);
7679 IPW_DEBUG_WX("SET Short Retry Limit -> %d \n",
7684 if (wrqu->retry.flags & IW_RETRY_MAX) {
7685 err = ipw2100_set_long_retry(priv, wrqu->retry.value);
7686 IPW_DEBUG_WX("SET Long Retry Limit -> %d \n",
7691 err = ipw2100_set_short_retry(priv, wrqu->retry.value);
7693 err = ipw2100_set_long_retry(priv, wrqu->retry.value);
7695 IPW_DEBUG_WX("SET Both Retry Limits -> %d \n", wrqu->retry.value);
7698 up(&priv->action_sem);
7702 static int ipw2100_wx_get_retry(struct net_device *dev,
7703 struct iw_request_info *info,
7704 union iwreq_data *wrqu, char *extra)
7707 * This can be called at any time. No action lock required
7710 struct ipw2100_priv *priv = ieee80211_priv(dev);
7712 wrqu->retry.disabled = 0; /* can't be disabled */
7714 if ((wrqu->retry.flags & IW_RETRY_TYPE) ==
7718 if (wrqu->retry.flags & IW_RETRY_MAX) {
7719 wrqu->retry.flags = IW_RETRY_LIMIT & IW_RETRY_MAX;
7720 wrqu->retry.value = priv->long_retry_limit;
7723 (priv->short_retry_limit !=
7724 priv->long_retry_limit) ?
7725 IW_RETRY_LIMIT & IW_RETRY_MIN : IW_RETRY_LIMIT;
7727 wrqu->retry.value = priv->short_retry_limit;
7730 IPW_DEBUG_WX("GET Retry -> %d \n", wrqu->retry.value);
7735 static int ipw2100_wx_set_scan(struct net_device *dev,
7736 struct iw_request_info *info,
7737 union iwreq_data *wrqu, char *extra)
7739 struct ipw2100_priv *priv = ieee80211_priv(dev);
7742 down(&priv->action_sem);
7743 if (!(priv->status & STATUS_INITIALIZED)) {
7748 IPW_DEBUG_WX("Initiating scan...\n");
7749 if (ipw2100_set_scan_options(priv) ||
7750 ipw2100_start_scan(priv)) {
7751 IPW_DEBUG_WX("Start scan failed.\n");
7753 /* TODO: Mark a scan as pending so when hardware initialized
7758 up(&priv->action_sem);
7762 static int ipw2100_wx_get_scan(struct net_device *dev,
7763 struct iw_request_info *info,
7764 union iwreq_data *wrqu, char *extra)
7767 * This can be called at any time. No action lock required
7770 struct ipw2100_priv *priv = ieee80211_priv(dev);
7771 return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra);
7776 * Implementation based on code in hostap-driver v0.1.3 hostap_ioctl.c
7778 static int ipw2100_wx_set_encode(struct net_device *dev,
7779 struct iw_request_info *info,
7780 union iwreq_data *wrqu, char *key)
7783 * No check of STATUS_INITIALIZED required
7786 struct ipw2100_priv *priv = ieee80211_priv(dev);
7787 return ieee80211_wx_set_encode(priv->ieee, info, wrqu, key);
7790 static int ipw2100_wx_get_encode(struct net_device *dev,
7791 struct iw_request_info *info,
7792 union iwreq_data *wrqu, char *key)
7795 * This can be called at any time. No action lock required
7798 struct ipw2100_priv *priv = ieee80211_priv(dev);
7799 return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key);
7802 static int ipw2100_wx_set_power(struct net_device *dev,
7803 struct iw_request_info *info,
7804 union iwreq_data *wrqu, char *extra)
7806 struct ipw2100_priv *priv = ieee80211_priv(dev);
7809 down(&priv->action_sem);
7810 if (!(priv->status & STATUS_INITIALIZED)) {
7815 if (wrqu->power.disabled) {
7816 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
7817 err = ipw2100_set_power_mode(priv, IPW_POWER_MODE_CAM);
7818 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
7822 switch (wrqu->power.flags & IW_POWER_MODE) {
7823 case IW_POWER_ON: /* If not specified */
7824 case IW_POWER_MODE: /* If set all mask */
7825 case IW_POWER_ALL_R: /* If explicitely state all */
7827 default: /* Otherwise we don't support it */
7828 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
7834 /* If the user hasn't specified a power management mode yet, default
7836 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
7837 err = ipw2100_set_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
7839 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n",
7843 up(&priv->action_sem);
7848 static int ipw2100_wx_get_power(struct net_device *dev,
7849 struct iw_request_info *info,
7850 union iwreq_data *wrqu, char *extra)
7853 * This can be called at any time. No action lock required
7856 struct ipw2100_priv *priv = ieee80211_priv(dev);
7858 if (!(priv->power_mode & IPW_POWER_ENABLED)) {
7859 wrqu->power.disabled = 1;
7861 wrqu->power.disabled = 0;
7862 wrqu->power.flags = 0;
7865 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
7876 #ifdef CONFIG_IPW2100_MONITOR
7877 static int ipw2100_wx_set_promisc(struct net_device *dev,
7878 struct iw_request_info *info,
7879 union iwreq_data *wrqu, char *extra)
7881 struct ipw2100_priv *priv = ieee80211_priv(dev);
7882 int *parms = (int *)extra;
7883 int enable = (parms[0] > 0);
7886 down(&priv->action_sem);
7887 if (!(priv->status & STATUS_INITIALIZED)) {
7893 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7894 err = ipw2100_set_channel(priv, parms[1], 0);
7897 priv->channel = parms[1];
7898 err = ipw2100_switch_mode(priv, IW_MODE_MONITOR);
7900 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
7901 err = ipw2100_switch_mode(priv, priv->last_mode);
7904 up(&priv->action_sem);
7908 static int ipw2100_wx_reset(struct net_device *dev,
7909 struct iw_request_info *info,
7910 union iwreq_data *wrqu, char *extra)
7912 struct ipw2100_priv *priv = ieee80211_priv(dev);
7913 if (priv->status & STATUS_INITIALIZED)
7914 schedule_reset(priv);
7920 static int ipw2100_wx_set_powermode(struct net_device *dev,
7921 struct iw_request_info *info,
7922 union iwreq_data *wrqu, char *extra)
7924 struct ipw2100_priv *priv = ieee80211_priv(dev);
7925 int err = 0, mode = *(int *)extra;
7927 down(&priv->action_sem);
7928 if (!(priv->status & STATUS_INITIALIZED)) {
7933 if ((mode < 1) || (mode > POWER_MODES))
7934 mode = IPW_POWER_AUTO;
7936 if (priv->power_mode != mode)
7937 err = ipw2100_set_power_mode(priv, mode);
7939 up(&priv->action_sem);
7943 #define MAX_POWER_STRING 80
7944 static int ipw2100_wx_get_powermode(struct net_device *dev,
7945 struct iw_request_info *info,
7946 union iwreq_data *wrqu, char *extra)
7949 * This can be called at any time. No action lock required
7952 struct ipw2100_priv *priv = ieee80211_priv(dev);
7953 int level = IPW_POWER_LEVEL(priv->power_mode);
7954 s32 timeout, period;
7956 if (!(priv->power_mode & IPW_POWER_ENABLED)) {
7957 snprintf(extra, MAX_POWER_STRING,
7958 "Power save level: %d (Off)", level);
7961 case IPW_POWER_MODE_CAM:
7962 snprintf(extra, MAX_POWER_STRING,
7963 "Power save level: %d (None)", level);
7965 case IPW_POWER_AUTO:
7966 snprintf(extra, MAX_POWER_STRING,
7967 "Power save level: %d (Auto)", 0);
7970 timeout = timeout_duration[level - 1] / 1000;
7971 period = period_duration[level - 1] / 1000;
7972 snprintf(extra, MAX_POWER_STRING,
7973 "Power save level: %d "
7974 "(Timeout %dms, Period %dms)",
7975 level, timeout, period);
7979 wrqu->data.length = strlen(extra) + 1;
7985 static int ipw2100_wx_set_preamble(struct net_device *dev,
7986 struct iw_request_info *info,
7987 union iwreq_data *wrqu, char *extra)
7989 struct ipw2100_priv *priv = ieee80211_priv(dev);
7990 int err, mode = *(int *)extra;
7992 down(&priv->action_sem);
7993 if (!(priv->status & STATUS_INITIALIZED)) {
7999 priv->config |= CFG_LONG_PREAMBLE;
8001 priv->config &= ~CFG_LONG_PREAMBLE;
8007 err = ipw2100_system_config(priv, 0);
8010 up(&priv->action_sem);
8014 static int ipw2100_wx_get_preamble(struct net_device *dev,
8015 struct iw_request_info *info,
8016 union iwreq_data *wrqu, char *extra)
8019 * This can be called at any time. No action lock required
8022 struct ipw2100_priv *priv = ieee80211_priv(dev);
8024 if (priv->config & CFG_LONG_PREAMBLE)
8025 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
8027 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
8032 static iw_handler ipw2100_wx_handlers[] =
8034 NULL, /* SIOCSIWCOMMIT */
8035 ipw2100_wx_get_name, /* SIOCGIWNAME */
8036 NULL, /* SIOCSIWNWID */
8037 NULL, /* SIOCGIWNWID */
8038 ipw2100_wx_set_freq, /* SIOCSIWFREQ */
8039 ipw2100_wx_get_freq, /* SIOCGIWFREQ */
8040 ipw2100_wx_set_mode, /* SIOCSIWMODE */
8041 ipw2100_wx_get_mode, /* SIOCGIWMODE */
8042 NULL, /* SIOCSIWSENS */
8043 NULL, /* SIOCGIWSENS */
8044 NULL, /* SIOCSIWRANGE */
8045 ipw2100_wx_get_range, /* SIOCGIWRANGE */
8046 NULL, /* SIOCSIWPRIV */
8047 NULL, /* SIOCGIWPRIV */
8048 NULL, /* SIOCSIWSTATS */
8049 NULL, /* SIOCGIWSTATS */
8050 NULL, /* SIOCSIWSPY */
8051 NULL, /* SIOCGIWSPY */
8052 NULL, /* SIOCGIWTHRSPY */
8053 NULL, /* SIOCWIWTHRSPY */
8054 ipw2100_wx_set_wap, /* SIOCSIWAP */
8055 ipw2100_wx_get_wap, /* SIOCGIWAP */
8056 NULL, /* -- hole -- */
8057 NULL, /* SIOCGIWAPLIST -- depricated */
8058 ipw2100_wx_set_scan, /* SIOCSIWSCAN */
8059 ipw2100_wx_get_scan, /* SIOCGIWSCAN */
8060 ipw2100_wx_set_essid, /* SIOCSIWESSID */
8061 ipw2100_wx_get_essid, /* SIOCGIWESSID */
8062 ipw2100_wx_set_nick, /* SIOCSIWNICKN */
8063 ipw2100_wx_get_nick, /* SIOCGIWNICKN */
8064 NULL, /* -- hole -- */
8065 NULL, /* -- hole -- */
8066 ipw2100_wx_set_rate, /* SIOCSIWRATE */
8067 ipw2100_wx_get_rate, /* SIOCGIWRATE */
8068 ipw2100_wx_set_rts, /* SIOCSIWRTS */
8069 ipw2100_wx_get_rts, /* SIOCGIWRTS */
8070 ipw2100_wx_set_frag, /* SIOCSIWFRAG */
8071 ipw2100_wx_get_frag, /* SIOCGIWFRAG */
8072 ipw2100_wx_set_txpow, /* SIOCSIWTXPOW */
8073 ipw2100_wx_get_txpow, /* SIOCGIWTXPOW */
8074 ipw2100_wx_set_retry, /* SIOCSIWRETRY */
8075 ipw2100_wx_get_retry, /* SIOCGIWRETRY */
8076 ipw2100_wx_set_encode, /* SIOCSIWENCODE */
8077 ipw2100_wx_get_encode, /* SIOCGIWENCODE */
8078 ipw2100_wx_set_power, /* SIOCSIWPOWER */
8079 ipw2100_wx_get_power, /* SIOCGIWPOWER */
8082 #define IPW2100_PRIV_SET_MONITOR SIOCIWFIRSTPRIV
8083 #define IPW2100_PRIV_RESET SIOCIWFIRSTPRIV+1
8084 #define IPW2100_PRIV_SET_POWER SIOCIWFIRSTPRIV+2
8085 #define IPW2100_PRIV_GET_POWER SIOCIWFIRSTPRIV+3
8086 #define IPW2100_PRIV_SET_LONGPREAMBLE SIOCIWFIRSTPRIV+4
8087 #define IPW2100_PRIV_GET_LONGPREAMBLE SIOCIWFIRSTPRIV+5
8089 static const struct iw_priv_args ipw2100_private_args[] = {
8091 #ifdef CONFIG_IPW2100_MONITOR
8093 IPW2100_PRIV_SET_MONITOR,
8094 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"
8098 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"
8100 #endif /* CONFIG_IPW2100_MONITOR */
8103 IPW2100_PRIV_SET_POWER,
8104 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_power"
8107 IPW2100_PRIV_GET_POWER,
8108 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_POWER_STRING, "get_power"
8111 IPW2100_PRIV_SET_LONGPREAMBLE,
8112 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_preamble"
8115 IPW2100_PRIV_GET_LONGPREAMBLE,
8116 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, "get_preamble"
8120 static iw_handler ipw2100_private_handler[] = {
8121 #ifdef CONFIG_IPW2100_MONITOR
8122 ipw2100_wx_set_promisc,
8124 #else /* CONFIG_IPW2100_MONITOR */
8127 #endif /* CONFIG_IPW2100_MONITOR */
8128 ipw2100_wx_set_powermode,
8129 ipw2100_wx_get_powermode,
8130 ipw2100_wx_set_preamble,
8131 ipw2100_wx_get_preamble,
8134 struct iw_handler_def ipw2100_wx_handler_def =
8136 .standard = ipw2100_wx_handlers,
8137 .num_standard = sizeof(ipw2100_wx_handlers) / sizeof(iw_handler),
8138 .num_private = sizeof(ipw2100_private_handler) / sizeof(iw_handler),
8139 .num_private_args = sizeof(ipw2100_private_args) /
8140 sizeof(struct iw_priv_args),
8141 .private = (iw_handler *)ipw2100_private_handler,
8142 .private_args = (struct iw_priv_args *)ipw2100_private_args,
8146 * Get wireless statistics.
8147 * Called by /proc/net/wireless
8148 * Also called by SIOCGIWSTATS
8150 struct iw_statistics *ipw2100_wx_wireless_stats(struct net_device * dev)
8164 struct ipw2100_priv *priv = ieee80211_priv(dev);
8165 struct iw_statistics *wstats;
8166 u32 rssi, quality, tx_retries, missed_beacons, tx_failures;
8167 u32 ord_len = sizeof(u32);
8170 return (struct iw_statistics *) NULL;
8172 wstats = &priv->wstats;
8174 /* if hw is disabled, then ipw2100_get_ordinal() can't be called.
8175 * ipw2100_wx_wireless_stats seems to be called before fw is
8176 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
8177 * and associated; if not associcated, the values are all meaningless
8178 * anyway, so set them all to NULL and INVALID */
8179 if (!(priv->status & STATUS_ASSOCIATED)) {
8180 wstats->miss.beacon = 0;
8181 wstats->discard.retries = 0;
8182 wstats->qual.qual = 0;
8183 wstats->qual.level = 0;
8184 wstats->qual.noise = 0;
8185 wstats->qual.updated = 7;
8186 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
8187 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
8191 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_PERCENT_MISSED_BCNS,
8192 &missed_beacons, &ord_len))
8193 goto fail_get_ordinal;
8195 /* If we don't have a connection the quality and level is 0*/
8196 if (!(priv->status & STATUS_ASSOCIATED)) {
8197 wstats->qual.qual = 0;
8198 wstats->qual.level = 0;
8200 if (ipw2100_get_ordinal(priv, IPW_ORD_RSSI_AVG_CURR,
8202 goto fail_get_ordinal;
8203 wstats->qual.level = rssi + IPW2100_RSSI_TO_DBM;
8205 rssi_qual = rssi * POOR / 10;
8207 rssi_qual = (rssi - 10) * (FAIR - POOR) / 5 + POOR;
8209 rssi_qual = (rssi - 15) * (GOOD - FAIR) / 5 + FAIR;
8211 rssi_qual = (rssi - 20) * (VERY_GOOD - GOOD) /
8214 rssi_qual = (rssi - 30) * (PERFECT - VERY_GOOD) /
8217 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_PERCENT_RETRIES,
8218 &tx_retries, &ord_len))
8219 goto fail_get_ordinal;
8221 if (tx_retries > 75)
8222 tx_qual = (90 - tx_retries) * POOR / 15;
8223 else if (tx_retries > 70)
8224 tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
8225 else if (tx_retries > 65)
8226 tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
8227 else if (tx_retries > 50)
8228 tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
8231 tx_qual = (50 - tx_retries) *
8232 (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
8234 if (missed_beacons > 50)
8235 beacon_qual = (60 - missed_beacons) * POOR / 10;
8236 else if (missed_beacons > 40)
8237 beacon_qual = (50 - missed_beacons) * (FAIR - POOR) /
8239 else if (missed_beacons > 32)
8240 beacon_qual = (40 - missed_beacons) * (GOOD - FAIR) /
8242 else if (missed_beacons > 20)
8243 beacon_qual = (32 - missed_beacons) *
8244 (VERY_GOOD - GOOD) / 20 + GOOD;
8246 beacon_qual = (20 - missed_beacons) *
8247 (PERFECT - VERY_GOOD) / 20 + VERY_GOOD;
8249 quality = min(beacon_qual, min(tx_qual, rssi_qual));
8251 #ifdef CONFIG_IPW_DEBUG
8252 if (beacon_qual == quality)
8253 IPW_DEBUG_WX("Quality clamped by Missed Beacons\n");
8254 else if (tx_qual == quality)
8255 IPW_DEBUG_WX("Quality clamped by Tx Retries\n");
8256 else if (quality != 100)
8257 IPW_DEBUG_WX("Quality clamped by Signal Strength\n");
8259 IPW_DEBUG_WX("Quality not clamped.\n");
8262 wstats->qual.qual = quality;
8263 wstats->qual.level = rssi + IPW2100_RSSI_TO_DBM;
8266 wstats->qual.noise = 0;
8267 wstats->qual.updated = 7;
8268 wstats->qual.updated |= IW_QUAL_NOISE_INVALID;
8270 /* FIXME: this is percent and not a # */
8271 wstats->miss.beacon = missed_beacons;
8273 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURES,
8274 &tx_failures, &ord_len))
8275 goto fail_get_ordinal;
8276 wstats->discard.retries = tx_failures;
8281 IPW_DEBUG_WX("failed querying ordinals.\n");
8283 return (struct iw_statistics *) NULL;
8286 void ipw2100_wx_event_work(struct ipw2100_priv *priv)
8288 union iwreq_data wrqu;
8291 if (priv->status & STATUS_STOPPING)
8294 down(&priv->action_sem);
8296 IPW_DEBUG_WX("enter\n");
8298 up(&priv->action_sem);
8300 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
8302 /* Fetch BSSID from the hardware */
8303 if (!(priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) ||
8304 priv->status & STATUS_RF_KILL_MASK ||
8305 ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID,
8306 &priv->bssid, &len)) {
8307 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
8309 /* We now have the BSSID, so can finish setting to the full
8310 * associated state */
8311 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
8312 memcpy(&priv->ieee->bssid, priv->bssid, ETH_ALEN);
8313 priv->status &= ~STATUS_ASSOCIATING;
8314 priv->status |= STATUS_ASSOCIATED;
8315 netif_carrier_on(priv->net_dev);
8316 if (netif_queue_stopped(priv->net_dev)) {
8317 IPW_DEBUG_INFO("Waking net queue.\n");
8318 netif_wake_queue(priv->net_dev);
8320 IPW_DEBUG_INFO("Starting net queue.\n");
8321 netif_start_queue(priv->net_dev);
8325 if (!(priv->status & STATUS_ASSOCIATED)) {
8326 IPW_DEBUG_WX("Configuring ESSID\n");
8327 down(&priv->action_sem);
8328 /* This is a disassociation event, so kick the firmware to
8329 * look for another AP */
8330 if (priv->config & CFG_STATIC_ESSID)
8331 ipw2100_set_essid(priv, priv->essid, priv->essid_len, 0);
8333 ipw2100_set_essid(priv, NULL, 0, 0);
8334 up(&priv->action_sem);
8337 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
8340 #define IPW2100_FW_MAJOR_VERSION 1
8341 #define IPW2100_FW_MINOR_VERSION 3
8343 #define IPW2100_FW_MINOR(x) ((x & 0xff) >> 8)
8344 #define IPW2100_FW_MAJOR(x) (x & 0xff)
8346 #define IPW2100_FW_VERSION ((IPW2100_FW_MINOR_VERSION << 8) | \
8347 IPW2100_FW_MAJOR_VERSION)
8349 #define IPW2100_FW_PREFIX "ipw2100-" __stringify(IPW2100_FW_MAJOR_VERSION) \
8350 "." __stringify(IPW2100_FW_MINOR_VERSION)
8352 #define IPW2100_FW_NAME(x) IPW2100_FW_PREFIX "" x ".fw"
8357 BINARY FIRMWARE HEADER FORMAT
8361 2 2 mode == 0:BSS,1:IBSS,2:MONITOR
8364 C fw_len firmware data
8365 12 + fw_len uc_len microcode data
8369 struct ipw2100_fw_header {
8372 unsigned int fw_size;
8373 unsigned int uc_size;
8374 } __attribute__ ((packed));
8378 static int ipw2100_mod_firmware_load(struct ipw2100_fw *fw)
8380 struct ipw2100_fw_header *h =
8381 (struct ipw2100_fw_header *)fw->fw_entry->data;
8383 if (IPW2100_FW_MAJOR(h->version) != IPW2100_FW_MAJOR_VERSION) {
8384 IPW_DEBUG_WARNING("Firmware image not compatible "
8385 "(detected version id of %u). "
8386 "See Documentation/networking/README.ipw2100\n",
8391 fw->version = h->version;
8392 fw->fw.data = fw->fw_entry->data + sizeof(struct ipw2100_fw_header);
8393 fw->fw.size = h->fw_size;
8394 fw->uc.data = fw->fw.data + h->fw_size;
8395 fw->uc.size = h->uc_size;
8401 int ipw2100_get_firmware(struct ipw2100_priv *priv, struct ipw2100_fw *fw)
8406 IPW_DEBUG_INFO("%s: Using hotplug firmware load.\n",
8407 priv->net_dev->name);
8409 switch (priv->ieee->iw_mode) {
8411 fw_name = IPW2100_FW_NAME("-i");
8413 #ifdef CONFIG_IPW2100_MONITOR
8414 case IW_MODE_MONITOR:
8415 fw_name = IPW2100_FW_NAME("-p");
8420 fw_name = IPW2100_FW_NAME("");
8424 rc = request_firmware(&fw->fw_entry, fw_name, &priv->pci_dev->dev);
8428 "%s: Firmware '%s' not available or load failed.\n",
8429 priv->net_dev->name, fw_name);
8432 IPW_DEBUG_INFO("firmware data %p size %zd\n", fw->fw_entry->data,
8433 fw->fw_entry->size);
8435 ipw2100_mod_firmware_load(fw);
8440 void ipw2100_release_firmware(struct ipw2100_priv *priv,
8441 struct ipw2100_fw *fw)
8445 release_firmware(fw->fw_entry);
8446 fw->fw_entry = NULL;
8450 int ipw2100_get_fwversion(struct ipw2100_priv *priv, char *buf, size_t max)
8452 char ver[MAX_FW_VERSION_LEN];
8453 u32 len = MAX_FW_VERSION_LEN;
8456 /* firmware version is an ascii string (max len of 14) */
8457 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_FW_VER_NUM,
8463 for (i = 0; i < len; i++)
8469 int ipw2100_get_ucodeversion(struct ipw2100_priv *priv, char *buf, size_t max)
8472 u32 len = sizeof(ver);
8473 /* microcode version is a 32 bit integer */
8474 if (ipw2100_get_ordinal(priv, IPW_ORD_UCODE_VERSION,
8477 return snprintf(buf, max, "%08X", ver);
8481 * On exit, the firmware will have been freed from the fw list
8483 int ipw2100_fw_download(struct ipw2100_priv *priv, struct ipw2100_fw *fw)
8485 /* firmware is constructed of N contiguous entries, each entry is
8489 * 0 4 address to write to
8490 * 4 2 length of data run
8496 const unsigned char *firmware_data = fw->fw.data;
8497 unsigned int firmware_data_left = fw->fw.size;
8499 while (firmware_data_left > 0) {
8500 addr = *(u32 *)(firmware_data);
8502 firmware_data_left -= 4;
8504 len = *(u16 *)(firmware_data);
8506 firmware_data_left -= 2;
8510 "Invalid firmware run-length of %d bytes\n",
8515 write_nic_memory(priv->net_dev, addr, len, firmware_data);
8516 firmware_data += len;
8517 firmware_data_left -= len;
8523 struct symbol_alive_response {
8532 u16 clock_settle_time; // 1us LSB
8533 u16 powerup_settle_time; // 1us LSB
8534 u16 hop_settle_time; // 1us LSB
8535 u8 date[3]; // month, day, year
8536 u8 time[2]; // hours, minutes
8540 int ipw2100_ucode_download(struct ipw2100_priv *priv, struct ipw2100_fw *fw)
8542 struct net_device *dev = priv->net_dev;
8543 const unsigned char *microcode_data = fw->uc.data;
8544 unsigned int microcode_data_left = fw->uc.size;
8546 struct symbol_alive_response response;
8550 /* Symbol control */
8551 write_nic_word(dev, IPW2100_CONTROL_REG, 0x703);
8552 readl((void *)(dev->base_addr));
8553 write_nic_word(dev, IPW2100_CONTROL_REG, 0x707);
8554 readl((void *)(dev->base_addr));
8557 write_nic_byte(dev, 0x210014, 0x72); /* fifo width =16 */
8558 readl((void *)(dev->base_addr));
8559 write_nic_byte(dev, 0x210014, 0x72); /* fifo width =16 */
8560 readl((void *)(dev->base_addr));
8562 /* EN_CS_ACCESS bit to reset control store pointer */
8563 write_nic_byte(dev, 0x210000, 0x40);
8564 readl((void *)(dev->base_addr));
8565 write_nic_byte(dev, 0x210000, 0x0);
8566 readl((void *)(dev->base_addr));
8567 write_nic_byte(dev, 0x210000, 0x40);
8568 readl((void *)(dev->base_addr));
8570 /* copy microcode from buffer into Symbol */
8572 while (microcode_data_left > 0) {
8573 write_nic_byte(dev, 0x210010, *microcode_data++);
8574 write_nic_byte(dev, 0x210010, *microcode_data++);
8575 microcode_data_left -= 2;
8578 /* EN_CS_ACCESS bit to reset the control store pointer */
8579 write_nic_byte(dev, 0x210000, 0x0);
8580 readl((void *)(dev->base_addr));
8582 /* Enable System (Reg 0)
8583 * first enable causes garbage in RX FIFO */
8584 write_nic_byte(dev, 0x210000, 0x0);
8585 readl((void *)(dev->base_addr));
8586 write_nic_byte(dev, 0x210000, 0x80);
8587 readl((void *)(dev->base_addr));
8589 /* Reset External Baseband Reg */
8590 write_nic_word(dev, IPW2100_CONTROL_REG, 0x703);
8591 readl((void *)(dev->base_addr));
8592 write_nic_word(dev, IPW2100_CONTROL_REG, 0x707);
8593 readl((void *)(dev->base_addr));
8595 /* HW Config (Reg 5) */
8596 write_nic_byte(dev, 0x210014, 0x72); // fifo width =16
8597 readl((void *)(dev->base_addr));
8598 write_nic_byte(dev, 0x210014, 0x72); // fifo width =16
8599 readl((void *)(dev->base_addr));
8601 /* Enable System (Reg 0)
8602 * second enable should be OK */
8603 write_nic_byte(dev, 0x210000, 0x00); // clear enable system
8604 readl((void *)(dev->base_addr));
8605 write_nic_byte(dev, 0x210000, 0x80); // set enable system
8607 /* check Symbol is enabled - upped this from 5 as it wasn't always
8608 * catching the update */
8609 for (i = 0; i < 10; i++) {
8612 /* check Dino is enabled bit */
8613 read_nic_byte(dev, 0x210000, &data);
8619 IPW_DEBUG_ERROR("%s: Error initializing Symbol\n",
8624 /* Get Symbol alive response */
8625 for (i = 0; i < 30; i++) {
8626 /* Read alive response structure */
8628 j < (sizeof(struct symbol_alive_response) >> 1);
8630 read_nic_word(dev, 0x210004,
8631 ((u16 *)&response) + j);
8633 if ((response.cmd_id == 1) &&
8634 (response.ucode_valid == 0x1))
8640 IPW_DEBUG_ERROR("%s: No response from Symbol - hw not alive\n",
8642 printk_buf(IPW_DL_ERROR, (u8*)&response, sizeof(response));