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/dma-mapping.h>
150 #include <linux/proc_fs.h>
151 #include <linux/skbuff.h>
152 #include <asm/uaccess.h>
154 #define __KERNEL_SYSCALLS__
155 #include <linux/fs.h>
156 #include <linux/mm.h>
157 #include <linux/slab.h>
158 #include <linux/unistd.h>
159 #include <linux/stringify.h>
160 #include <linux/tcp.h>
161 #include <linux/types.h>
162 #include <linux/version.h>
163 #include <linux/time.h>
164 #include <linux/firmware.h>
165 #include <linux/acpi.h>
166 #include <linux/ctype.h>
170 #define IPW2100_VERSION "1.1.0"
172 #define DRV_NAME "ipw2100"
173 #define DRV_VERSION IPW2100_VERSION
174 #define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2100 Network Driver"
175 #define DRV_COPYRIGHT "Copyright(c) 2003-2004 Intel Corporation"
178 /* Debugging stuff */
179 #ifdef CONFIG_IPW_DEBUG
180 #define CONFIG_IPW2100_RX_DEBUG /* Reception debugging */
183 MODULE_DESCRIPTION(DRV_DESCRIPTION);
184 MODULE_VERSION(DRV_VERSION);
185 MODULE_AUTHOR(DRV_COPYRIGHT);
186 MODULE_LICENSE("GPL");
188 static int debug = 0;
190 static int channel = 0;
191 static int associate = 1;
192 static int disable = 0;
194 static struct ipw2100_fw ipw2100_firmware;
197 #include <linux/moduleparam.h>
198 module_param(debug, int, 0444);
199 module_param(mode, int, 0444);
200 module_param(channel, int, 0444);
201 module_param(associate, int, 0444);
202 module_param(disable, int, 0444);
204 MODULE_PARM_DESC(debug, "debug level");
205 MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
206 MODULE_PARM_DESC(channel, "channel");
207 MODULE_PARM_DESC(associate, "auto associate when scanning (default on)");
208 MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
210 u32 ipw2100_debug_level = IPW_DL_NONE;
212 #ifdef CONFIG_IPW_DEBUG
213 static const char *command_types[] = {
215 "unused", /* HOST_ATTENTION */
217 "unused", /* SLEEP */
218 "unused", /* HOST_POWER_DOWN */
221 "unused", /* SET_IMR */
224 "AUTHENTICATION_TYPE",
227 "INTERNATIONAL_MODE",
242 "CLEAR_ALL_MULTICAST",
263 "AP_OR_STATION_TABLE",
267 "unused", /* SAVE_CALIBRATION */
268 "unused", /* RESTORE_CALIBRATION */
272 "HOST_PRE_POWER_DOWN",
273 "unused", /* HOST_INTERRUPT_COALESCING */
275 "CARD_DISABLE_PHY_OFF",
279 "SET_STATION_STAT_BITS",
280 "CLEAR_STATIONS_STAT_BITS",
282 "SET_SECURITY_INFORMATION",
283 "DISASSOCIATION_BSSID",
289 /* Pre-decl until we get the code solid and then we can clean it up */
290 static void X__ipw2100_tx_send_commands(struct ipw2100_priv *priv);
291 static void X__ipw2100_tx_send_data(struct ipw2100_priv *priv);
292 static int ipw2100_adapter_setup(struct ipw2100_priv *priv);
294 static void ipw2100_queues_initialize(struct ipw2100_priv *priv);
295 static void ipw2100_queues_free(struct ipw2100_priv *priv);
296 static int ipw2100_queues_allocate(struct ipw2100_priv *priv);
299 static inline void read_register(struct net_device *dev, u32 reg, u32 *val)
301 *val = readl((void *)(dev->base_addr + reg));
302 IPW_DEBUG_IO("r: 0x%08X => 0x%08X\n", reg, *val);
305 static inline void write_register(struct net_device *dev, u32 reg, u32 val)
307 writel(val, (void *)(dev->base_addr + reg));
308 IPW_DEBUG_IO("w: 0x%08X <= 0x%08X\n", reg, val);
311 static inline void read_register_word(struct net_device *dev, u32 reg, u16 *val)
313 *val = readw((void *)(dev->base_addr + reg));
314 IPW_DEBUG_IO("r: 0x%08X => %04X\n", reg, *val);
317 static inline void read_register_byte(struct net_device *dev, u32 reg, u8 *val)
319 *val = readb((void *)(dev->base_addr + reg));
320 IPW_DEBUG_IO("r: 0x%08X => %02X\n", reg, *val);
323 static inline void write_register_word(struct net_device *dev, u32 reg, u16 val)
325 writew(val, (void *)(dev->base_addr + reg));
326 IPW_DEBUG_IO("w: 0x%08X <= %04X\n", reg, val);
330 static inline void write_register_byte(struct net_device *dev, u32 reg, u8 val)
332 writeb(val, (void *)(dev->base_addr + reg));
333 IPW_DEBUG_IO("w: 0x%08X =< %02X\n", reg, val);
336 static inline void read_nic_dword(struct net_device *dev, u32 addr, u32 *val)
338 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
339 addr & IPW_REG_INDIRECT_ADDR_MASK);
340 read_register(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
343 static inline void write_nic_dword(struct net_device *dev, u32 addr, u32 val)
345 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
346 addr & IPW_REG_INDIRECT_ADDR_MASK);
347 write_register(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
350 static inline void read_nic_word(struct net_device *dev, u32 addr, u16 *val)
352 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
353 addr & IPW_REG_INDIRECT_ADDR_MASK);
354 read_register_word(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
357 static inline void write_nic_word(struct net_device *dev, u32 addr, u16 val)
359 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
360 addr & IPW_REG_INDIRECT_ADDR_MASK);
361 write_register_word(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
364 static inline void read_nic_byte(struct net_device *dev, u32 addr, u8 *val)
366 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
367 addr & IPW_REG_INDIRECT_ADDR_MASK);
368 read_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
371 static inline void write_nic_byte(struct net_device *dev, u32 addr, u8 val)
373 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
374 addr & IPW_REG_INDIRECT_ADDR_MASK);
375 write_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
378 static inline void write_nic_auto_inc_address(struct net_device *dev, u32 addr)
380 write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS,
381 addr & IPW_REG_INDIRECT_ADDR_MASK);
384 static inline void write_nic_dword_auto_inc(struct net_device *dev, u32 val)
386 write_register(dev, IPW_REG_AUTOINCREMENT_DATA, val);
389 static inline void write_nic_memory(struct net_device *dev, u32 addr, u32 len,
397 /* read first nibble byte by byte */
398 aligned_addr = addr & (~0x3);
399 dif_len = addr - aligned_addr;
401 /* Start reading at aligned_addr + dif_len */
402 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
404 for (i = dif_len; i < 4; i++, buf++)
406 dev, IPW_REG_INDIRECT_ACCESS_DATA + i,
413 /* read DWs through autoincrement registers */
414 write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS,
416 aligned_len = len & (~0x3);
417 for (i = 0; i < aligned_len; i += 4, buf += 4, aligned_addr += 4)
419 dev, IPW_REG_AUTOINCREMENT_DATA, *(u32 *)buf);
421 /* copy the last nibble */
422 dif_len = len - aligned_len;
423 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, aligned_addr);
424 for (i = 0; i < dif_len; i++, buf++)
426 dev, IPW_REG_INDIRECT_ACCESS_DATA + i, *buf);
429 static inline void read_nic_memory(struct net_device *dev, u32 addr, u32 len,
437 /* read first nibble byte by byte */
438 aligned_addr = addr & (~0x3);
439 dif_len = addr - aligned_addr;
441 /* Start reading at aligned_addr + dif_len */
442 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
444 for (i = dif_len; i < 4; i++, buf++)
446 dev, IPW_REG_INDIRECT_ACCESS_DATA + i, buf);
452 /* read DWs through autoincrement registers */
453 write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS,
455 aligned_len = len & (~0x3);
456 for (i = 0; i < aligned_len; i += 4, buf += 4, aligned_addr += 4)
457 read_register(dev, IPW_REG_AUTOINCREMENT_DATA,
460 /* copy the last nibble */
461 dif_len = len - aligned_len;
462 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
464 for (i = 0; i < dif_len; i++, buf++)
465 read_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA +
469 static inline int ipw2100_hw_is_adapter_in_system(struct net_device *dev)
471 return (dev->base_addr &&
472 (readl((void *)(dev->base_addr + IPW_REG_DOA_DEBUG_AREA_START))
473 == IPW_DATA_DOA_DEBUG_VALUE));
476 int ipw2100_get_ordinal(struct ipw2100_priv *priv, u32 ord,
479 struct ipw2100_ordinals *ordinals = &priv->ordinals;
486 if (ordinals->table1_addr == 0) {
487 IPW_DEBUG_WARNING(DRV_NAME ": attempt to use fw ordinals "
488 "before they have been loaded.\n");
492 if (IS_ORDINAL_TABLE_ONE(ordinals, ord)) {
493 if (*len < IPW_ORD_TAB_1_ENTRY_SIZE) {
494 *len = IPW_ORD_TAB_1_ENTRY_SIZE;
496 IPW_DEBUG_WARNING(DRV_NAME
497 ": ordinal buffer length too small, need %zd\n",
498 IPW_ORD_TAB_1_ENTRY_SIZE);
503 read_nic_dword(priv->net_dev, ordinals->table1_addr + (ord << 2),
505 read_nic_dword(priv->net_dev, addr, val);
507 *len = IPW_ORD_TAB_1_ENTRY_SIZE;
512 if (IS_ORDINAL_TABLE_TWO(ordinals, ord)) {
514 ord -= IPW_START_ORD_TAB_2;
516 /* get the address of statistic */
517 read_nic_dword(priv->net_dev, ordinals->table2_addr + (ord << 3),
520 /* get the second DW of statistics ;
521 * two 16-bit words - first is length, second is count */
522 read_nic_dword(priv->net_dev,
523 ordinals->table2_addr + (ord << 3) + sizeof(u32),
526 /* get each entry length */
527 field_len = *((u16 *)&field_info);
529 /* get number of entries */
530 field_count = *(((u16 *)&field_info) + 1);
532 /* abort if no enought memory */
533 total_length = field_len * field_count;
534 if (total_length > *len) {
543 /* read the ordinal data from the SRAM */
544 read_nic_memory(priv->net_dev, addr, total_length, val);
549 IPW_DEBUG_WARNING(DRV_NAME ": ordinal %d neither in table 1 nor "
550 "in table 2\n", ord);
555 static int ipw2100_set_ordinal(struct ipw2100_priv *priv, u32 ord, u32 *val,
558 struct ipw2100_ordinals *ordinals = &priv->ordinals;
561 if (IS_ORDINAL_TABLE_ONE(ordinals, ord)) {
562 if (*len != IPW_ORD_TAB_1_ENTRY_SIZE) {
563 *len = IPW_ORD_TAB_1_ENTRY_SIZE;
564 IPW_DEBUG_INFO("wrong size\n");
568 read_nic_dword(priv->net_dev, ordinals->table1_addr + (ord << 2),
571 write_nic_dword(priv->net_dev, addr, *val);
573 *len = IPW_ORD_TAB_1_ENTRY_SIZE;
578 IPW_DEBUG_INFO("wrong table\n");
579 if (IS_ORDINAL_TABLE_TWO(ordinals, ord))
585 static char *snprint_line(char *buf, size_t count,
586 const u8 *data, u32 len, u32 ofs)
591 out = snprintf(buf, count, "%08X", ofs);
593 for (l = 0, i = 0; i < 2; i++) {
594 out += snprintf(buf + out, count - out, " ");
595 for (j = 0; j < 8 && l < len; j++, l++)
596 out += snprintf(buf + out, count - out, "%02X ",
599 out += snprintf(buf + out, count - out, " ");
602 out += snprintf(buf + out, count - out, " ");
603 for (l = 0, i = 0; i < 2; i++) {
604 out += snprintf(buf + out, count - out, " ");
605 for (j = 0; j < 8 && l < len; j++, l++) {
606 c = data[(i * 8 + j)];
607 if (!isascii(c) || !isprint(c))
610 out += snprintf(buf + out, count - out, "%c", c);
614 out += snprintf(buf + out, count - out, " ");
620 static void printk_buf(int level, const u8 *data, u32 len)
624 if (!(ipw2100_debug_level & level))
628 printk(KERN_DEBUG "%s\n",
629 snprint_line(line, sizeof(line), &data[ofs],
630 min(len, 16U), ofs));
632 len -= min(len, 16U);
638 #define MAX_RESET_BACKOFF 10
640 static inline void schedule_reset(struct ipw2100_priv *priv)
642 unsigned long now = get_seconds();
644 /* If we haven't received a reset request within the backoff period,
645 * then we can reset the backoff interval so this reset occurs
647 if (priv->reset_backoff &&
648 (now - priv->last_reset > priv->reset_backoff))
649 priv->reset_backoff = 0;
651 priv->last_reset = get_seconds();
653 if (!(priv->status & STATUS_RESET_PENDING)) {
654 IPW_DEBUG_INFO("%s: Scheduling firmware restart (%ds).\n",
655 priv->net_dev->name, priv->reset_backoff);
656 netif_carrier_off(priv->net_dev);
657 netif_stop_queue(priv->net_dev);
658 priv->status |= STATUS_RESET_PENDING;
659 if (priv->reset_backoff)
660 queue_delayed_work(priv->workqueue, &priv->reset_work,
661 priv->reset_backoff * HZ);
663 queue_work(priv->workqueue, &priv->reset_work);
665 if (priv->reset_backoff < MAX_RESET_BACKOFF)
666 priv->reset_backoff++;
668 wake_up_interruptible(&priv->wait_command_queue);
670 IPW_DEBUG_INFO("%s: Firmware restart already in progress.\n",
671 priv->net_dev->name);
675 #define HOST_COMPLETE_TIMEOUT (2 * HZ)
676 static int ipw2100_hw_send_command(struct ipw2100_priv *priv,
677 struct host_command * cmd)
679 struct list_head *element;
680 struct ipw2100_tx_packet *packet;
684 IPW_DEBUG_HC("Sending %s command (#%d), %d bytes\n",
685 command_types[cmd->host_command], cmd->host_command,
686 cmd->host_command_length);
687 printk_buf(IPW_DL_HC, (u8*)cmd->host_command_parameters,
688 cmd->host_command_length);
690 spin_lock_irqsave(&priv->low_lock, flags);
692 if (priv->fatal_error) {
693 IPW_DEBUG_INFO("Attempt to send command while hardware in fatal error condition.\n");
698 if (!(priv->status & STATUS_RUNNING)) {
699 IPW_DEBUG_INFO("Attempt to send command while hardware is not running.\n");
704 if (priv->status & STATUS_CMD_ACTIVE) {
705 IPW_DEBUG_INFO("Attempt to send command while another command is pending.\n");
710 if (list_empty(&priv->msg_free_list)) {
711 IPW_DEBUG_INFO("no available msg buffers\n");
715 priv->status |= STATUS_CMD_ACTIVE;
716 priv->messages_sent++;
718 element = priv->msg_free_list.next;
720 packet = list_entry(element, struct ipw2100_tx_packet, list);
721 packet->jiffy_start = jiffies;
723 /* initialize the firmware command packet */
724 packet->info.c_struct.cmd->host_command_reg = cmd->host_command;
725 packet->info.c_struct.cmd->host_command_reg1 = cmd->host_command1;
726 packet->info.c_struct.cmd->host_command_len_reg = cmd->host_command_length;
727 packet->info.c_struct.cmd->sequence = cmd->host_command_sequence;
729 memcpy(packet->info.c_struct.cmd->host_command_params_reg,
730 cmd->host_command_parameters,
731 sizeof(packet->info.c_struct.cmd->host_command_params_reg));
734 DEC_STAT(&priv->msg_free_stat);
736 list_add_tail(element, &priv->msg_pend_list);
737 INC_STAT(&priv->msg_pend_stat);
739 X__ipw2100_tx_send_commands(priv);
740 X__ipw2100_tx_send_data(priv);
742 spin_unlock_irqrestore(&priv->low_lock, flags);
745 * We must wait for this command to complete before another
746 * command can be sent... but if we wait more than 3 seconds
747 * then there is a problem.
750 err = wait_event_interruptible_timeout(
751 priv->wait_command_queue, !(priv->status & STATUS_CMD_ACTIVE),
752 HOST_COMPLETE_TIMEOUT);
755 IPW_DEBUG_INFO("Command completion failed out after %dms.\n",
756 HOST_COMPLETE_TIMEOUT / (HZ / 100));
757 priv->fatal_error = IPW2100_ERR_MSG_TIMEOUT;
758 priv->status &= ~STATUS_CMD_ACTIVE;
759 schedule_reset(priv);
763 if (priv->fatal_error) {
764 IPW_DEBUG_WARNING("%s: firmware fatal error\n",
765 priv->net_dev->name);
769 /* !!!!! HACK TEST !!!!!
770 * When lots of debug trace statements are enabled, the driver
771 * doesn't seem to have as many firmware restart cycles...
773 * As a test, we're sticking in a 1/100s delay here */
774 set_current_state(TASK_UNINTERRUPTIBLE);
775 schedule_timeout(HZ / 100);
780 spin_unlock_irqrestore(&priv->low_lock, flags);
787 * Verify the values and data access of the hardware
788 * No locks needed or used. No functions called.
790 static int ipw2100_verify(struct ipw2100_priv *priv)
795 u32 val1 = 0x76543210;
796 u32 val2 = 0xFEDCBA98;
798 /* Domain 0 check - all values should be DOA_DEBUG */
799 for (address = IPW_REG_DOA_DEBUG_AREA_START;
800 address < IPW_REG_DOA_DEBUG_AREA_END;
801 address += sizeof(u32)) {
802 read_register(priv->net_dev, address, &data1);
803 if (data1 != IPW_DATA_DOA_DEBUG_VALUE)
807 /* Domain 1 check - use arbitrary read/write compare */
808 for (address = 0; address < 5; address++) {
809 /* The memory area is not used now */
810 write_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x32,
812 write_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x36,
814 read_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x32,
816 read_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x36,
818 if (val1 == data1 && val2 == data2)
827 * Loop until the CARD_DISABLED bit is the same value as the
830 * TODO: See if it would be more efficient to do a wait/wake
831 * cycle and have the completion event trigger the wakeup
834 #define IPW_CARD_DISABLE_COMPLETE_WAIT 100 // 100 milli
835 static int ipw2100_wait_for_card_state(struct ipw2100_priv *priv, int state)
839 u32 len = sizeof(card_state);
842 for (i = 0; i <= IPW_CARD_DISABLE_COMPLETE_WAIT * 1000; i += 50) {
843 err = ipw2100_get_ordinal(priv, IPW_ORD_CARD_DISABLED,
846 IPW_DEBUG_INFO("Query of CARD_DISABLED ordinal "
851 /* We'll break out if either the HW state says it is
852 * in the state we want, or if HOST_COMPLETE command
854 if ((card_state == state) ||
855 ((priv->status & STATUS_ENABLED) ?
856 IPW_HW_STATE_ENABLED : IPW_HW_STATE_DISABLED) == state) {
857 if (state == IPW_HW_STATE_ENABLED)
858 priv->status |= STATUS_ENABLED;
860 priv->status &= ~STATUS_ENABLED;
868 IPW_DEBUG_INFO("ipw2100_wait_for_card_state to %s state timed out\n",
869 state ? "DISABLED" : "ENABLED");
874 /*********************************************************************
875 Procedure : sw_reset_and_clock
876 Purpose : Asserts s/w reset, asserts clock initialization
877 and waits for clock stabilization
878 ********************************************************************/
879 static int sw_reset_and_clock(struct ipw2100_priv *priv)
885 write_register(priv->net_dev, IPW_REG_RESET_REG,
886 IPW_AUX_HOST_RESET_REG_SW_RESET);
888 // wait for clock stabilization
889 for (i = 0; i < 1000; i++) {
890 udelay(IPW_WAIT_RESET_ARC_COMPLETE_DELAY);
892 // check clock ready bit
893 read_register(priv->net_dev, IPW_REG_RESET_REG, &r);
894 if (r & IPW_AUX_HOST_RESET_REG_PRINCETON_RESET)
899 return -EIO; // TODO: better error value
901 /* set "initialization complete" bit to move adapter to
903 write_register(priv->net_dev, IPW_REG_GP_CNTRL,
904 IPW_AUX_HOST_GP_CNTRL_BIT_INIT_DONE);
906 /* wait for clock stabilization */
907 for (i = 0; i < 10000; i++) {
908 udelay(IPW_WAIT_CLOCK_STABILIZATION_DELAY * 4);
910 /* check clock ready bit */
911 read_register(priv->net_dev, IPW_REG_GP_CNTRL, &r);
912 if (r & IPW_AUX_HOST_GP_CNTRL_BIT_CLOCK_READY)
917 return -EIO; /* TODO: better error value */
919 /* set D0 standby bit */
920 read_register(priv->net_dev, IPW_REG_GP_CNTRL, &r);
921 write_register(priv->net_dev, IPW_REG_GP_CNTRL,
922 r | IPW_AUX_HOST_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
927 /*********************************************************************
928 Procedure : ipw2100_ipw2100_download_firmware
929 Purpose : Initiaze adapter after power on.
931 1. assert s/w reset first!
932 2. awake clocks & wait for clock stabilization
933 3. hold ARC (don't ask me why...)
934 4. load Dino ucode and reset/clock init again
935 5. zero-out shared mem
937 *******************************************************************/
938 static int ipw2100_download_firmware(struct ipw2100_priv *priv)
944 /* Fetch the firmware and microcode */
945 struct ipw2100_fw ipw2100_firmware;
948 if (priv->fatal_error) {
949 IPW_DEBUG_ERROR("%s: ipw2100_download_firmware called after "
950 "fatal error %d. Interface must be brought down.\n",
951 priv->net_dev->name, priv->fatal_error);
956 if (!ipw2100_firmware.version) {
957 err = ipw2100_get_firmware(priv, &ipw2100_firmware);
959 IPW_DEBUG_ERROR("%s: ipw2100_get_firmware failed: %d\n",
960 priv->net_dev->name, err);
961 priv->fatal_error = IPW2100_ERR_FW_LOAD;
966 err = ipw2100_get_firmware(priv, &ipw2100_firmware);
968 IPW_DEBUG_ERROR("%s: ipw2100_get_firmware failed: %d\n",
969 priv->net_dev->name, err);
970 priv->fatal_error = IPW2100_ERR_FW_LOAD;
974 priv->firmware_version = ipw2100_firmware.version;
976 /* s/w reset and clock stabilization */
977 err = sw_reset_and_clock(priv);
979 IPW_DEBUG_ERROR("%s: sw_reset_and_clock failed: %d\n",
980 priv->net_dev->name, err);
984 err = ipw2100_verify(priv);
986 IPW_DEBUG_ERROR("%s: ipw2100_verify failed: %d\n",
987 priv->net_dev->name, err);
992 write_nic_dword(priv->net_dev,
993 IPW_INTERNAL_REGISTER_HALT_AND_RESET,
996 /* allow ARC to run */
997 write_register(priv->net_dev, IPW_REG_RESET_REG, 0);
1000 err = ipw2100_ucode_download(priv, &ipw2100_firmware);
1002 IPW_DEBUG_ERROR("%s: Error loading microcode: %d\n",
1003 priv->net_dev->name, err);
1008 write_nic_dword(priv->net_dev,
1009 IPW_INTERNAL_REGISTER_HALT_AND_RESET,
1012 /* s/w reset and clock stabilization (again!!!) */
1013 err = sw_reset_and_clock(priv);
1015 IPW_DEBUG_ERROR("%s: sw_reset_and_clock failed: %d\n",
1016 priv->net_dev->name, err);
1021 err = ipw2100_fw_download(priv, &ipw2100_firmware);
1023 IPW_DEBUG_ERROR("%s: Error loading firmware: %d\n",
1024 priv->net_dev->name, err);
1030 * When the .resume method of the driver is called, the other
1031 * part of the system, i.e. the ide driver could still stay in
1032 * the suspend stage. This prevents us from loading the firmware
1033 * from the disk. --YZ
1036 /* free any storage allocated for firmware image */
1037 ipw2100_release_firmware(priv, &ipw2100_firmware);
1040 /* zero out Domain 1 area indirectly (Si requirement) */
1041 for (address = IPW_HOST_FW_SHARED_AREA0;
1042 address < IPW_HOST_FW_SHARED_AREA0_END; address += 4)
1043 write_nic_dword(priv->net_dev, address, 0);
1044 for (address = IPW_HOST_FW_SHARED_AREA1;
1045 address < IPW_HOST_FW_SHARED_AREA1_END; address += 4)
1046 write_nic_dword(priv->net_dev, address, 0);
1047 for (address = IPW_HOST_FW_SHARED_AREA2;
1048 address < IPW_HOST_FW_SHARED_AREA2_END; address += 4)
1049 write_nic_dword(priv->net_dev, address, 0);
1050 for (address = IPW_HOST_FW_SHARED_AREA3;
1051 address < IPW_HOST_FW_SHARED_AREA3_END; address += 4)
1052 write_nic_dword(priv->net_dev, address, 0);
1053 for (address = IPW_HOST_FW_INTERRUPT_AREA;
1054 address < IPW_HOST_FW_INTERRUPT_AREA_END; address += 4)
1055 write_nic_dword(priv->net_dev, address, 0);
1060 ipw2100_release_firmware(priv, &ipw2100_firmware);
1064 static inline void ipw2100_enable_interrupts(struct ipw2100_priv *priv)
1066 if (priv->status & STATUS_INT_ENABLED)
1068 priv->status |= STATUS_INT_ENABLED;
1069 write_register(priv->net_dev, IPW_REG_INTA_MASK, IPW_INTERRUPT_MASK);
1072 static inline void ipw2100_disable_interrupts(struct ipw2100_priv *priv)
1074 if (!(priv->status & STATUS_INT_ENABLED))
1076 priv->status &= ~STATUS_INT_ENABLED;
1077 write_register(priv->net_dev, IPW_REG_INTA_MASK, 0x0);
1081 static void ipw2100_initialize_ordinals(struct ipw2100_priv *priv)
1083 struct ipw2100_ordinals *ord = &priv->ordinals;
1085 IPW_DEBUG_INFO("enter\n");
1087 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_ORDINALS_TABLE_1,
1090 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_ORDINALS_TABLE_2,
1093 read_nic_dword(priv->net_dev, ord->table1_addr, &ord->table1_size);
1094 read_nic_dword(priv->net_dev, ord->table2_addr, &ord->table2_size);
1096 ord->table2_size &= 0x0000FFFF;
1098 IPW_DEBUG_INFO("table 1 size: %d\n", ord->table1_size);
1099 IPW_DEBUG_INFO("table 2 size: %d\n", ord->table2_size);
1100 IPW_DEBUG_INFO("exit\n");
1103 static inline void ipw2100_hw_set_gpio(struct ipw2100_priv *priv)
1107 * Set GPIO 3 writable by FW; GPIO 1 writable
1108 * by driver and enable clock
1110 reg = (IPW_BIT_GPIO_GPIO3_MASK | IPW_BIT_GPIO_GPIO1_ENABLE |
1111 IPW_BIT_GPIO_LED_OFF);
1112 write_register(priv->net_dev, IPW_REG_GPIO, reg);
1115 static inline int rf_kill_active(struct ipw2100_priv *priv)
1117 #define MAX_RF_KILL_CHECKS 5
1118 #define RF_KILL_CHECK_DELAY 40
1119 #define RF_KILL_CHECK_THRESHOLD 3
1121 unsigned short value = 0;
1125 if (!(priv->hw_features & HW_FEATURE_RFKILL)) {
1126 priv->status &= ~STATUS_RF_KILL_HW;
1130 for (i = 0; i < MAX_RF_KILL_CHECKS; i++) {
1131 udelay(RF_KILL_CHECK_DELAY);
1132 read_register(priv->net_dev, IPW_REG_GPIO, ®);
1133 value = (value << 1) | ((reg & IPW_BIT_GPIO_RF_KILL) ? 0 : 1);
1137 priv->status |= STATUS_RF_KILL_HW;
1139 priv->status &= ~STATUS_RF_KILL_HW;
1141 return (value == 0);
1144 static int ipw2100_get_hw_features(struct ipw2100_priv *priv)
1150 * EEPROM_SRAM_DB_START_ADDRESS using ordinal in ordinal table 1
1153 if (ipw2100_get_ordinal(
1154 priv, IPW_ORD_EEPROM_SRAM_DB_BLOCK_START_ADDRESS,
1156 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
1161 IPW_DEBUG_INFO("EEPROM address: %08X\n", addr);
1164 * EEPROM version is the byte at offset 0xfd in firmware
1165 * We read 4 bytes, then shift out the byte we actually want */
1166 read_nic_dword(priv->net_dev, addr + 0xFC, &val);
1167 priv->eeprom_version = (val >> 24) & 0xFF;
1168 IPW_DEBUG_INFO("EEPROM version: %d\n", priv->eeprom_version);
1171 * HW RF Kill enable is bit 0 in byte at offset 0x21 in firmware
1173 * notice that the EEPROM bit is reverse polarity, i.e.
1174 * bit = 0 signifies HW RF kill switch is supported
1175 * bit = 1 signifies HW RF kill switch is NOT supported
1177 read_nic_dword(priv->net_dev, addr + 0x20, &val);
1178 if (!((val >> 24) & 0x01))
1179 priv->hw_features |= HW_FEATURE_RFKILL;
1181 IPW_DEBUG_INFO("HW RF Kill: %ssupported.\n",
1182 (priv->hw_features & HW_FEATURE_RFKILL) ?
1189 * Start firmware execution after power on and intialization
1192 * 2. Wait for f/w initialization completes;
1194 static int ipw2100_start_adapter(struct ipw2100_priv *priv)
1196 #define IPW_WAIT_FW_INIT_COMPLETE_DELAY (40 * HZ / 1000)
1198 u32 inta, inta_mask, gpio;
1200 IPW_DEBUG_INFO("enter\n");
1202 if (priv->status & STATUS_RUNNING)
1206 * Initialize the hw - drive adapter to DO state by setting
1207 * init_done bit. Wait for clk_ready bit and Download
1210 if (ipw2100_download_firmware(priv)) {
1211 IPW_DEBUG_ERROR("%s: Failed to power on the adapter.\n",
1212 priv->net_dev->name);
1216 /* Clear the Tx, Rx and Msg queues and the r/w indexes
1217 * in the firmware RBD and TBD ring queue */
1218 ipw2100_queues_initialize(priv);
1220 ipw2100_hw_set_gpio(priv);
1222 /* TODO -- Look at disabling interrupts here to make sure none
1223 * get fired during FW initialization */
1225 /* Release ARC - clear reset bit */
1226 write_register(priv->net_dev, IPW_REG_RESET_REG, 0);
1228 /* wait for f/w intialization complete */
1229 IPW_DEBUG_FW("Waiting for f/w initialization to complete...\n");
1232 set_current_state(TASK_UNINTERRUPTIBLE);
1233 schedule_timeout(IPW_WAIT_FW_INIT_COMPLETE_DELAY);
1234 /* Todo... wait for sync command ... */
1236 read_register(priv->net_dev, IPW_REG_INTA, &inta);
1238 /* check "init done" bit */
1239 if (inta & IPW2100_INTA_FW_INIT_DONE) {
1240 /* reset "init done" bit */
1241 write_register(priv->net_dev, IPW_REG_INTA,
1242 IPW2100_INTA_FW_INIT_DONE);
1246 /* check error conditions : we check these after the firmware
1247 * check so that if there is an error, the interrupt handler
1248 * will see it and the adapter will be reset */
1250 (IPW2100_INTA_FATAL_ERROR | IPW2100_INTA_PARITY_ERROR)) {
1251 /* clear error conditions */
1252 write_register(priv->net_dev, IPW_REG_INTA,
1253 IPW2100_INTA_FATAL_ERROR |
1254 IPW2100_INTA_PARITY_ERROR);
1258 /* Clear out any pending INTAs since we aren't supposed to have
1259 * interrupts enabled at this point... */
1260 read_register(priv->net_dev, IPW_REG_INTA, &inta);
1261 read_register(priv->net_dev, IPW_REG_INTA_MASK, &inta_mask);
1262 inta &= IPW_INTERRUPT_MASK;
1263 /* Clear out any pending interrupts */
1264 if (inta & inta_mask)
1265 write_register(priv->net_dev, IPW_REG_INTA, inta);
1267 IPW_DEBUG_FW("f/w initialization complete: %s\n",
1268 i ? "SUCCESS" : "FAILED");
1271 IPW_DEBUG_WARNING("%s: Firmware did not initialize.\n",
1272 priv->net_dev->name);
1276 /* allow firmware to write to GPIO1 & GPIO3 */
1277 read_register(priv->net_dev, IPW_REG_GPIO, &gpio);
1279 gpio |= (IPW_BIT_GPIO_GPIO1_MASK | IPW_BIT_GPIO_GPIO3_MASK);
1281 write_register(priv->net_dev, IPW_REG_GPIO, gpio);
1283 /* Ready to receive commands */
1284 priv->status |= STATUS_RUNNING;
1286 /* The adapter has been reset; we are not associated */
1287 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
1289 IPW_DEBUG_INFO("exit\n");
1294 static inline void ipw2100_reset_fatalerror(struct ipw2100_priv *priv)
1296 if (!priv->fatal_error)
1299 priv->fatal_errors[priv->fatal_index++] = priv->fatal_error;
1300 priv->fatal_index %= IPW2100_ERROR_QUEUE;
1301 priv->fatal_error = 0;
1305 /* NOTE: Our interrupt is disabled when this method is called */
1306 static int ipw2100_power_cycle_adapter(struct ipw2100_priv *priv)
1311 IPW_DEBUG_INFO("Power cycling the hardware.\n");
1313 ipw2100_hw_set_gpio(priv);
1315 /* Step 1. Stop Master Assert */
1316 write_register(priv->net_dev, IPW_REG_RESET_REG,
1317 IPW_AUX_HOST_RESET_REG_STOP_MASTER);
1319 /* Step 2. Wait for stop Master Assert
1320 * (not more then 50us, otherwise ret error */
1323 udelay(IPW_WAIT_RESET_MASTER_ASSERT_COMPLETE_DELAY);
1324 read_register(priv->net_dev, IPW_REG_RESET_REG, ®);
1326 if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED)
1330 priv->status &= ~STATUS_RESET_PENDING;
1333 IPW_DEBUG_INFO("exit - waited too long for master assert stop\n");
1337 write_register(priv->net_dev, IPW_REG_RESET_REG,
1338 IPW_AUX_HOST_RESET_REG_SW_RESET);
1341 /* Reset any fatal_error conditions */
1342 ipw2100_reset_fatalerror(priv);
1344 /* At this point, the adapter is now stopped and disabled */
1345 priv->status &= ~(STATUS_RUNNING | STATUS_ASSOCIATING |
1346 STATUS_ASSOCIATED | STATUS_ENABLED);
1352 * Send the CARD_DISABLE_PHY_OFF comamnd to the card to disable it
1354 * After disabling, if the card was associated, a STATUS_ASSN_LOST will be sent.
1356 * STATUS_CARD_DISABLE_NOTIFICATION will be sent regardless of
1357 * if STATUS_ASSN_LOST is sent.
1359 static int ipw2100_hw_phy_off(struct ipw2100_priv *priv)
1362 #define HW_PHY_OFF_LOOP_DELAY (HZ / 5000)
1364 struct host_command cmd = {
1365 .host_command = CARD_DISABLE_PHY_OFF,
1366 .host_command_sequence = 0,
1367 .host_command_length = 0,
1372 IPW_DEBUG_HC("CARD_DISABLE_PHY_OFF\n");
1374 /* Turn off the radio */
1375 err = ipw2100_hw_send_command(priv, &cmd);
1379 for (i = 0; i < 2500; i++) {
1380 read_nic_dword(priv->net_dev, IPW2100_CONTROL_REG, &val1);
1381 read_nic_dword(priv->net_dev, IPW2100_COMMAND, &val2);
1383 if ((val1 & IPW2100_CONTROL_PHY_OFF) &&
1384 (val2 & IPW2100_COMMAND_PHY_OFF))
1387 set_current_state(TASK_UNINTERRUPTIBLE);
1388 schedule_timeout(HW_PHY_OFF_LOOP_DELAY);
1395 static int ipw2100_enable_adapter(struct ipw2100_priv *priv)
1397 struct host_command cmd = {
1398 .host_command = HOST_COMPLETE,
1399 .host_command_sequence = 0,
1400 .host_command_length = 0
1404 IPW_DEBUG_HC("HOST_COMPLETE\n");
1406 if (priv->status & STATUS_ENABLED)
1409 down(&priv->adapter_sem);
1411 if (rf_kill_active(priv)) {
1412 IPW_DEBUG_HC("Command aborted due to RF kill active.\n");
1416 err = ipw2100_hw_send_command(priv, &cmd);
1418 IPW_DEBUG_INFO("Failed to send HOST_COMPLETE command\n");
1422 err = ipw2100_wait_for_card_state(priv, IPW_HW_STATE_ENABLED);
1425 "%s: card not responding to init command.\n",
1426 priv->net_dev->name);
1430 if (priv->stop_hang_check) {
1431 priv->stop_hang_check = 0;
1432 queue_delayed_work(priv->workqueue, &priv->hang_check, HZ / 2);
1436 up(&priv->adapter_sem);
1440 static int ipw2100_hw_stop_adapter(struct ipw2100_priv *priv)
1442 #define HW_POWER_DOWN_DELAY (HZ / 10)
1444 struct host_command cmd = {
1445 .host_command = HOST_PRE_POWER_DOWN,
1446 .host_command_sequence = 0,
1447 .host_command_length = 0,
1452 if (!(priv->status & STATUS_RUNNING))
1455 priv->status |= STATUS_STOPPING;
1457 /* We can only shut down the card if the firmware is operational. So,
1458 * if we haven't reset since a fatal_error, then we can not send the
1459 * shutdown commands. */
1460 if (!priv->fatal_error) {
1461 /* First, make sure the adapter is enabled so that the PHY_OFF
1462 * command can shut it down */
1463 ipw2100_enable_adapter(priv);
1465 err = ipw2100_hw_phy_off(priv);
1467 IPW_DEBUG_WARNING("Error disabling radio %d\n", err);
1470 * If in D0-standby mode going directly to D3 may cause a
1471 * PCI bus violation. Therefore we must change out of the D0
1474 * Sending the PREPARE_FOR_POWER_DOWN will restrict the
1475 * hardware from going into standby mode and will transition
1476 * out of D0-standy if it is already in that state.
1478 * STATUS_PREPARE_POWER_DOWN_COMPLETE will be sent by the
1479 * driver upon completion. Once received, the driver can
1480 * proceed to the D3 state.
1482 * Prepare for power down command to fw. This command would
1483 * take HW out of D0-standby and prepare it for D3 state.
1485 * Currently FW does not support event notification for this
1486 * event. Therefore, skip waiting for it. Just wait a fixed
1489 IPW_DEBUG_HC("HOST_PRE_POWER_DOWN\n");
1491 err = ipw2100_hw_send_command(priv, &cmd);
1494 "%s: Power down command failed: Error %d\n",
1495 priv->net_dev->name, err);
1497 set_current_state(TASK_UNINTERRUPTIBLE);
1498 schedule_timeout(HW_POWER_DOWN_DELAY);
1502 priv->status &= ~STATUS_ENABLED;
1505 * Set GPIO 3 writable by FW; GPIO 1 writable
1506 * by driver and enable clock
1508 ipw2100_hw_set_gpio(priv);
1511 * Power down adapter. Sequence:
1512 * 1. Stop master assert (RESET_REG[9]=1)
1513 * 2. Wait for stop master (RESET_REG[8]==1)
1514 * 3. S/w reset assert (RESET_REG[7] = 1)
1517 /* Stop master assert */
1518 write_register(priv->net_dev, IPW_REG_RESET_REG,
1519 IPW_AUX_HOST_RESET_REG_STOP_MASTER);
1521 /* wait stop master not more than 50 usec.
1522 * Otherwise return error. */
1523 for (i = 5; i > 0; i--) {
1526 /* Check master stop bit */
1527 read_register(priv->net_dev, IPW_REG_RESET_REG, ®);
1529 if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED)
1534 IPW_DEBUG_WARNING(DRV_NAME
1535 ": %s: Could now power down adapter.\n",
1536 priv->net_dev->name);
1538 /* assert s/w reset */
1539 write_register(priv->net_dev, IPW_REG_RESET_REG,
1540 IPW_AUX_HOST_RESET_REG_SW_RESET);
1542 priv->status &= ~(STATUS_RUNNING | STATUS_STOPPING);
1548 static int ipw2100_disable_adapter(struct ipw2100_priv *priv)
1550 struct host_command cmd = {
1551 .host_command = CARD_DISABLE,
1552 .host_command_sequence = 0,
1553 .host_command_length = 0
1557 IPW_DEBUG_HC("CARD_DISABLE\n");
1559 if (!(priv->status & STATUS_ENABLED))
1562 /* Make sure we clear the associated state */
1563 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1565 if (!priv->stop_hang_check) {
1566 priv->stop_hang_check = 1;
1567 cancel_delayed_work(&priv->hang_check);
1570 down(&priv->adapter_sem);
1572 err = ipw2100_hw_send_command(priv, &cmd);
1574 IPW_DEBUG_WARNING("exit - failed to send CARD_DISABLE command\n");
1578 err = ipw2100_wait_for_card_state(priv, IPW_HW_STATE_DISABLED);
1580 IPW_DEBUG_WARNING("exit - card failed to change to DISABLED\n");
1584 IPW_DEBUG_INFO("TODO: implement scan state machine\n");
1587 up(&priv->adapter_sem);
1591 int ipw2100_set_scan_options(struct ipw2100_priv *priv)
1593 struct host_command cmd = {
1594 .host_command = SET_SCAN_OPTIONS,
1595 .host_command_sequence = 0,
1596 .host_command_length = 8
1600 IPW_DEBUG_INFO("enter\n");
1602 IPW_DEBUG_SCAN("setting scan options\n");
1604 cmd.host_command_parameters[0] = 0;
1606 if (!(priv->config & CFG_ASSOCIATE))
1607 cmd.host_command_parameters[0] |= IPW_SCAN_NOASSOCIATE;
1608 if ((priv->sec.flags & SEC_ENABLED) && priv->sec.enabled)
1609 cmd.host_command_parameters[0] |= IPW_SCAN_MIXED_CELL;
1610 if (priv->config & CFG_PASSIVE_SCAN)
1611 cmd.host_command_parameters[0] |= IPW_SCAN_PASSIVE;
1613 cmd.host_command_parameters[1] = priv->channel_mask;
1615 err = ipw2100_hw_send_command(priv, &cmd);
1617 IPW_DEBUG_HC("SET_SCAN_OPTIONS 0x%04X\n",
1618 cmd.host_command_parameters[0]);
1623 int ipw2100_start_scan(struct ipw2100_priv *priv)
1625 struct host_command cmd = {
1626 .host_command = BROADCAST_SCAN,
1627 .host_command_sequence = 0,
1628 .host_command_length = 4
1632 IPW_DEBUG_HC("START_SCAN\n");
1634 cmd.host_command_parameters[0] = 0;
1636 /* No scanning if in monitor mode */
1637 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
1640 if (priv->status & STATUS_SCANNING) {
1641 IPW_DEBUG_SCAN("Scan requested while already in scan...\n");
1645 IPW_DEBUG_INFO("enter\n");
1647 /* Not clearing here; doing so makes iwlist always return nothing...
1649 * We should modify the table logic to use aging tables vs. clearing
1650 * the table on each scan start.
1652 IPW_DEBUG_SCAN("starting scan\n");
1654 priv->status |= STATUS_SCANNING;
1655 err = ipw2100_hw_send_command(priv, &cmd);
1657 priv->status &= ~STATUS_SCANNING;
1659 IPW_DEBUG_INFO("exit\n");
1664 static int ipw2100_up(struct ipw2100_priv *priv, int deferred)
1666 unsigned long flags;
1669 u32 ord_len = sizeof(lock);
1671 /* Quite if manually disabled. */
1672 if (priv->status & STATUS_RF_KILL_SW) {
1673 IPW_DEBUG_INFO("%s: Radio is disabled by Manual Disable "
1674 "switch\n", priv->net_dev->name);
1678 /* If the interrupt is enabled, turn it off... */
1679 spin_lock_irqsave(&priv->low_lock, flags);
1680 ipw2100_disable_interrupts(priv);
1682 /* Reset any fatal_error conditions */
1683 ipw2100_reset_fatalerror(priv);
1684 spin_unlock_irqrestore(&priv->low_lock, flags);
1686 if (priv->status & STATUS_POWERED ||
1687 (priv->status & STATUS_RESET_PENDING)) {
1688 /* Power cycle the card ... */
1689 if (ipw2100_power_cycle_adapter(priv)) {
1690 IPW_DEBUG_WARNING("%s: Could not cycle adapter.\n",
1691 priv->net_dev->name);
1696 priv->status |= STATUS_POWERED;
1698 /* Load the firmeware, start the clocks, etc. */
1699 if (ipw2100_start_adapter(priv)) {
1700 IPW_DEBUG_ERROR("%s: Failed to start the firmware.\n",
1701 priv->net_dev->name);
1706 ipw2100_initialize_ordinals(priv);
1708 /* Determine capabilities of this particular HW configuration */
1709 if (ipw2100_get_hw_features(priv)) {
1710 IPW_DEBUG_ERROR("%s: Failed to determine HW features.\n",
1711 priv->net_dev->name);
1717 if (ipw2100_set_ordinal(priv, IPW_ORD_PERS_DB_LOCK, &lock, &ord_len)) {
1718 IPW_DEBUG_ERROR("%s: Failed to clear ordinal lock.\n",
1719 priv->net_dev->name);
1724 priv->status &= ~STATUS_SCANNING;
1726 if (rf_kill_active(priv)) {
1727 printk(KERN_INFO "%s: Radio is disabled by RF switch.\n",
1728 priv->net_dev->name);
1730 if (priv->stop_rf_kill) {
1731 priv->stop_rf_kill = 0;
1732 queue_delayed_work(priv->workqueue, &priv->rf_kill, HZ);
1738 /* Turn on the interrupt so that commands can be processed */
1739 ipw2100_enable_interrupts(priv);
1741 /* Send all of the commands that must be sent prior to
1743 if (ipw2100_adapter_setup(priv)) {
1744 IPW_DEBUG_ERROR("%s: Failed to start the card.\n",
1745 priv->net_dev->name);
1751 /* Enable the adapter - sends HOST_COMPLETE */
1752 if (ipw2100_enable_adapter(priv)) {
1754 "%s: failed in call to enable adapter.\n",
1755 priv->net_dev->name);
1756 ipw2100_hw_stop_adapter(priv);
1762 /* Start a scan . . . */
1763 ipw2100_set_scan_options(priv);
1764 ipw2100_start_scan(priv);
1771 /* Called by register_netdev() */
1772 static int ipw2100_net_init(struct net_device *dev)
1774 struct ipw2100_priv *priv = ieee80211_priv(dev);
1775 return ipw2100_up(priv, 1);
1778 static void ipw2100_down(struct ipw2100_priv *priv)
1780 unsigned long flags;
1781 union iwreq_data wrqu = {
1783 .sa_family = ARPHRD_ETHER
1786 int associated = priv->status & STATUS_ASSOCIATED;
1788 /* Kill the RF switch timer */
1789 if (!priv->stop_rf_kill) {
1790 priv->stop_rf_kill = 1;
1791 cancel_delayed_work(&priv->rf_kill);
1794 /* Kill the firmare hang check timer */
1795 if (!priv->stop_hang_check) {
1796 priv->stop_hang_check = 1;
1797 cancel_delayed_work(&priv->hang_check);
1800 /* Kill any pending resets */
1801 if (priv->status & STATUS_RESET_PENDING)
1802 cancel_delayed_work(&priv->reset_work);
1804 /* Make sure the interrupt is on so that FW commands will be
1805 * processed correctly */
1806 spin_lock_irqsave(&priv->low_lock, flags);
1807 ipw2100_enable_interrupts(priv);
1808 spin_unlock_irqrestore(&priv->low_lock, flags);
1810 if (ipw2100_hw_stop_adapter(priv))
1811 IPW_DEBUG_ERROR("%s: Error stopping adapter.\n",
1812 priv->net_dev->name);
1814 /* Do not disable the interrupt until _after_ we disable
1815 * the adaptor. Otherwise the CARD_DISABLE command will never
1816 * be ack'd by the firmware */
1817 spin_lock_irqsave(&priv->low_lock, flags);
1818 ipw2100_disable_interrupts(priv);
1819 spin_unlock_irqrestore(&priv->low_lock, flags);
1821 #ifdef ACPI_CSTATE_LIMIT_DEFINED
1822 if (priv->config & CFG_C3_DISABLED) {
1823 IPW_DEBUG_INFO(DRV_NAME ": Resetting C3 transitions.\n");
1824 acpi_set_cstate_limit(priv->cstate_limit);
1825 priv->config &= ~CFG_C3_DISABLED;
1829 /* We have to signal any supplicant if we are disassociating */
1831 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1833 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1834 netif_carrier_off(priv->net_dev);
1835 netif_stop_queue(priv->net_dev);
1838 void ipw2100_reset_adapter(struct ipw2100_priv *priv)
1840 unsigned long flags;
1841 union iwreq_data wrqu = {
1843 .sa_family = ARPHRD_ETHER
1846 int associated = priv->status & STATUS_ASSOCIATED;
1848 spin_lock_irqsave(&priv->low_lock, flags);
1849 IPW_DEBUG_INFO(DRV_NAME ": %s: Restarting adapter.\n",
1850 priv->net_dev->name);
1852 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1853 priv->status |= STATUS_SECURITY_UPDATED;
1855 /* Force a power cycle even if interface hasn't been opened
1857 cancel_delayed_work(&priv->reset_work);
1858 priv->status |= STATUS_RESET_PENDING;
1859 spin_unlock_irqrestore(&priv->low_lock, flags);
1861 down(&priv->action_sem);
1862 /* stop timed checks so that they don't interfere with reset */
1863 priv->stop_hang_check = 1;
1864 cancel_delayed_work(&priv->hang_check);
1866 /* We have to signal any supplicant if we are disassociating */
1868 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1870 ipw2100_up(priv, 0);
1871 up(&priv->action_sem);
1876 static void isr_indicate_associated(struct ipw2100_priv *priv, u32 status)
1879 #define MAC_ASSOCIATION_READ_DELAY (HZ)
1880 int ret, len, essid_len;
1881 char essid[IW_ESSID_MAX_SIZE];
1888 * TBD: BSSID is usually 00:00:00:00:00:00 here and not
1889 * an actual MAC of the AP. Seems like FW sets this
1890 * address too late. Read it later and expose through
1891 * /proc or schedule a later task to query and update
1894 essid_len = IW_ESSID_MAX_SIZE;
1895 ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_SSID,
1898 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
1904 ret = ipw2100_get_ordinal(priv, IPW_ORD_CURRENT_TX_RATE,
1907 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
1913 ret = ipw2100_get_ordinal(priv, IPW_ORD_OUR_FREQ, &chan, &len);
1915 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
1920 ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID, &bssid, &len);
1922 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
1926 memcpy(priv->ieee->bssid, bssid, ETH_ALEN);
1930 case TX_RATE_1_MBIT:
1931 txratename = "1Mbps";
1933 case TX_RATE_2_MBIT:
1934 txratename = "2Mbsp";
1936 case TX_RATE_5_5_MBIT:
1937 txratename = "5.5Mbps";
1939 case TX_RATE_11_MBIT:
1940 txratename = "11Mbps";
1943 IPW_DEBUG_INFO("Unknown rate: %d\n", txrate);
1944 txratename = "unknown rate";
1948 IPW_DEBUG_INFO("%s: Associated with '%s' at %s, channel %d (BSSID="
1950 priv->net_dev->name, escape_essid(essid, essid_len),
1951 txratename, chan, MAC_ARG(bssid));
1953 /* now we copy read ssid into dev */
1954 if (!(priv->config & CFG_STATIC_ESSID)) {
1955 priv->essid_len = min((u8)essid_len, (u8)IW_ESSID_MAX_SIZE);
1956 memcpy(priv->essid, essid, priv->essid_len);
1958 priv->channel = chan;
1959 memcpy(priv->bssid, bssid, ETH_ALEN);
1961 priv->status |= STATUS_ASSOCIATING;
1962 priv->connect_start = get_seconds();
1964 queue_delayed_work(priv->workqueue, &priv->wx_event_work, HZ / 10);
1968 int ipw2100_set_essid(struct ipw2100_priv *priv, char *essid,
1969 int length, int batch_mode)
1971 int ssid_len = min(length, IW_ESSID_MAX_SIZE);
1972 struct host_command cmd = {
1973 .host_command = SSID,
1974 .host_command_sequence = 0,
1975 .host_command_length = ssid_len
1979 IPW_DEBUG_HC("SSID: '%s'\n", escape_essid(essid, ssid_len));
1982 memcpy((char*)cmd.host_command_parameters,
1986 err = ipw2100_disable_adapter(priv);
1991 /* Bug in FW currently doesn't honor bit 0 in SET_SCAN_OPTIONS to
1992 * disable auto association -- so we cheat by setting a bogus SSID */
1993 if (!ssid_len && !(priv->config & CFG_ASSOCIATE)) {
1995 u8 *bogus = (u8*)cmd.host_command_parameters;
1996 for (i = 0; i < IW_ESSID_MAX_SIZE; i++)
1997 bogus[i] = 0x18 + i;
1998 cmd.host_command_length = IW_ESSID_MAX_SIZE;
2001 /* NOTE: We always send the SSID command even if the provided ESSID is
2002 * the same as what we currently think is set. */
2004 err = ipw2100_hw_send_command(priv, &cmd);
2006 memset(priv->essid + ssid_len, 0,
2007 IW_ESSID_MAX_SIZE - ssid_len);
2008 memcpy(priv->essid, essid, ssid_len);
2009 priv->essid_len = ssid_len;
2013 if (ipw2100_enable_adapter(priv))
2020 static void isr_indicate_association_lost(struct ipw2100_priv *priv, u32 status)
2022 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | IPW_DL_ASSOC,
2023 "disassociated: '%s' " MAC_FMT " \n",
2024 escape_essid(priv->essid, priv->essid_len),
2025 MAC_ARG(priv->bssid));
2027 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
2029 if (priv->status & STATUS_STOPPING) {
2030 IPW_DEBUG_INFO("Card is stopping itself, discard ASSN_LOST.\n");
2034 memset(priv->bssid, 0, ETH_ALEN);
2035 memset(priv->ieee->bssid, 0, ETH_ALEN);
2037 netif_carrier_off(priv->net_dev);
2038 netif_stop_queue(priv->net_dev);
2040 if (!(priv->status & STATUS_RUNNING))
2043 if (priv->status & STATUS_SECURITY_UPDATED)
2044 queue_work(priv->workqueue, &priv->security_work);
2046 queue_work(priv->workqueue, &priv->wx_event_work);
2049 static void isr_indicate_rf_kill(struct ipw2100_priv *priv, u32 status)
2051 IPW_DEBUG_INFO("%s: RF Kill state changed to radio OFF.\n",
2052 priv->net_dev->name);
2054 /* RF_KILL is now enabled (else we wouldn't be here) */
2055 priv->status |= STATUS_RF_KILL_HW;
2057 #ifdef ACPI_CSTATE_LIMIT_DEFINED
2058 if (priv->config & CFG_C3_DISABLED) {
2059 IPW_DEBUG_INFO(DRV_NAME ": Resetting C3 transitions.\n");
2060 acpi_set_cstate_limit(priv->cstate_limit);
2061 priv->config &= ~CFG_C3_DISABLED;
2065 /* Make sure the RF Kill check timer is running */
2066 priv->stop_rf_kill = 0;
2067 cancel_delayed_work(&priv->rf_kill);
2068 queue_delayed_work(priv->workqueue, &priv->rf_kill, HZ);
2071 static void isr_scan_complete(struct ipw2100_priv *priv, u32 status)
2073 IPW_DEBUG_SCAN("scan complete\n");
2074 /* Age the scan results... */
2075 priv->ieee->scans++;
2076 priv->status &= ~STATUS_SCANNING;
2079 #ifdef CONFIG_IPW_DEBUG
2080 #define IPW2100_HANDLER(v, f) { v, f, # v }
2081 struct ipw2100_status_indicator {
2083 void (*cb)(struct ipw2100_priv *priv, u32 status);
2087 #define IPW2100_HANDLER(v, f) { v, f }
2088 struct ipw2100_status_indicator {
2090 void (*cb)(struct ipw2100_priv *priv, u32 status);
2092 #endif /* CONFIG_IPW_DEBUG */
2094 static void isr_indicate_scanning(struct ipw2100_priv *priv, u32 status)
2096 IPW_DEBUG_SCAN("Scanning...\n");
2097 priv->status |= STATUS_SCANNING;
2100 const struct ipw2100_status_indicator status_handlers[] = {
2101 IPW2100_HANDLER(IPW_STATE_INITIALIZED, 0),
2102 IPW2100_HANDLER(IPW_STATE_COUNTRY_FOUND, 0),
2103 IPW2100_HANDLER(IPW_STATE_ASSOCIATED, isr_indicate_associated),
2104 IPW2100_HANDLER(IPW_STATE_ASSN_LOST, isr_indicate_association_lost),
2105 IPW2100_HANDLER(IPW_STATE_ASSN_CHANGED, 0),
2106 IPW2100_HANDLER(IPW_STATE_SCAN_COMPLETE, isr_scan_complete),
2107 IPW2100_HANDLER(IPW_STATE_ENTERED_PSP, 0),
2108 IPW2100_HANDLER(IPW_STATE_LEFT_PSP, 0),
2109 IPW2100_HANDLER(IPW_STATE_RF_KILL, isr_indicate_rf_kill),
2110 IPW2100_HANDLER(IPW_STATE_DISABLED, 0),
2111 IPW2100_HANDLER(IPW_STATE_POWER_DOWN, 0),
2112 IPW2100_HANDLER(IPW_STATE_SCANNING, isr_indicate_scanning),
2113 IPW2100_HANDLER(-1, 0)
2117 static void isr_status_change(struct ipw2100_priv *priv, int status)
2121 if (status == IPW_STATE_SCANNING &&
2122 priv->status & STATUS_ASSOCIATED &&
2123 !(priv->status & STATUS_SCANNING)) {
2124 IPW_DEBUG_INFO("Scan detected while associated, with "
2125 "no scan request. Restarting firmware.\n");
2127 /* Wake up any sleeping jobs */
2128 schedule_reset(priv);
2131 for (i = 0; status_handlers[i].status != -1; i++) {
2132 if (status == status_handlers[i].status) {
2133 IPW_DEBUG_NOTIF("Status change: %s\n",
2134 status_handlers[i].name);
2135 if (status_handlers[i].cb)
2136 status_handlers[i].cb(priv, status);
2137 priv->wstats.status = status;
2142 IPW_DEBUG_NOTIF("unknown status received: %04x\n", status);
2145 static void isr_rx_complete_command(
2146 struct ipw2100_priv *priv,
2147 struct ipw2100_cmd_header *cmd)
2149 #ifdef CONFIG_IPW_DEBUG
2150 if (cmd->host_command_reg < ARRAY_SIZE(command_types)) {
2151 IPW_DEBUG_HC("Command completed '%s (%d)'\n",
2152 command_types[cmd->host_command_reg],
2153 cmd->host_command_reg);
2156 if (cmd->host_command_reg == HOST_COMPLETE)
2157 priv->status |= STATUS_ENABLED;
2159 if (cmd->host_command_reg == CARD_DISABLE)
2160 priv->status &= ~STATUS_ENABLED;
2162 priv->status &= ~STATUS_CMD_ACTIVE;
2164 wake_up_interruptible(&priv->wait_command_queue);
2167 #ifdef CONFIG_IPW_DEBUG
2168 const char *frame_types[] = {
2169 "COMMAND_STATUS_VAL",
2170 "STATUS_CHANGE_VAL",
2173 "HOST_NOTIFICATION_VAL"
2178 static inline int ipw2100_alloc_skb(
2179 struct ipw2100_priv *priv,
2180 struct ipw2100_rx_packet *packet)
2182 packet->skb = dev_alloc_skb(sizeof(struct ipw2100_rx));
2186 packet->rxp = (struct ipw2100_rx *)packet->skb->data;
2187 packet->dma_addr = pci_map_single(priv->pci_dev, packet->skb->data,
2188 sizeof(struct ipw2100_rx),
2189 PCI_DMA_FROMDEVICE);
2190 /* NOTE: pci_map_single does not return an error code, and 0 is a valid
2197 #define SEARCH_ERROR 0xffffffff
2198 #define SEARCH_FAIL 0xfffffffe
2199 #define SEARCH_SUCCESS 0xfffffff0
2200 #define SEARCH_DISCARD 0
2201 #define SEARCH_SNAPSHOT 1
2203 #define SNAPSHOT_ADDR(ofs) (priv->snapshot[((ofs) >> 12) & 0xff] + ((ofs) & 0xfff))
2204 static inline int ipw2100_snapshot_alloc(struct ipw2100_priv *priv)
2207 if (priv->snapshot[0])
2209 for (i = 0; i < 0x30; i++) {
2210 priv->snapshot[i] = (u8*)kmalloc(0x1000, GFP_ATOMIC);
2211 if (!priv->snapshot[i]) {
2212 IPW_DEBUG_INFO("%s: Error allocating snapshot "
2213 "buffer %d\n", priv->net_dev->name, i);
2215 kfree(priv->snapshot[--i]);
2216 priv->snapshot[0] = NULL;
2224 static inline void ipw2100_snapshot_free(struct ipw2100_priv *priv)
2227 if (!priv->snapshot[0])
2229 for (i = 0; i < 0x30; i++)
2230 kfree(priv->snapshot[i]);
2231 priv->snapshot[0] = NULL;
2234 static inline u32 ipw2100_match_buf(struct ipw2100_priv *priv, u8 *in_buf,
2235 size_t len, int mode)
2243 if (mode == SEARCH_SNAPSHOT) {
2244 if (!ipw2100_snapshot_alloc(priv))
2245 mode = SEARCH_DISCARD;
2248 for (ret = SEARCH_FAIL, i = 0; i < 0x30000; i += 4) {
2249 read_nic_dword(priv->net_dev, i, &tmp);
2250 if (mode == SEARCH_SNAPSHOT)
2251 *(u32 *)SNAPSHOT_ADDR(i) = tmp;
2252 if (ret == SEARCH_FAIL) {
2254 for (j = 0; j < 4; j++) {
2263 if ((s - in_buf) == len)
2264 ret = (i + j) - len + 1;
2266 } else if (mode == SEARCH_DISCARD)
2275 * 0) Disconnect the SKB from the firmware (just unmap)
2276 * 1) Pack the ETH header into the SKB
2277 * 2) Pass the SKB to the network stack
2279 * When packet is provided by the firmware, it contains the following:
2282 * . ieee80211_snap_hdr
2284 * The size of the constructed ethernet
2287 #ifdef CONFIG_IPW2100_RX_DEBUG
2288 u8 packet_data[IPW_RX_NIC_BUFFER_LENGTH];
2291 static inline void ipw2100_corruption_detected(struct ipw2100_priv *priv,
2294 #ifdef CONFIG_IPW_DEBUG_C3
2295 struct ipw2100_status *status = &priv->status_queue.drv[i];
2299 #ifdef ACPI_CSTATE_LIMIT_DEFINED
2303 IPW_DEBUG_INFO(DRV_NAME ": PCI latency error detected at "
2304 "0x%04zX.\n", i * sizeof(struct ipw2100_status));
2306 #ifdef ACPI_CSTATE_LIMIT_DEFINED
2307 IPW_DEBUG_INFO(DRV_NAME ": Disabling C3 transitions.\n");
2308 limit = acpi_get_cstate_limit();
2310 priv->cstate_limit = limit;
2311 acpi_set_cstate_limit(2);
2312 priv->config |= CFG_C3_DISABLED;
2316 #ifdef CONFIG_IPW_DEBUG_C3
2317 /* Halt the fimrware so we can get a good image */
2318 write_register(priv->net_dev, IPW_REG_RESET_REG,
2319 IPW_AUX_HOST_RESET_REG_STOP_MASTER);
2322 udelay(IPW_WAIT_RESET_MASTER_ASSERT_COMPLETE_DELAY);
2323 read_register(priv->net_dev, IPW_REG_RESET_REG, ®);
2325 if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED)
2329 match = ipw2100_match_buf(priv, (u8*)status,
2330 sizeof(struct ipw2100_status),
2332 if (match < SEARCH_SUCCESS)
2333 IPW_DEBUG_INFO("%s: DMA status match in Firmware at "
2334 "offset 0x%06X, length %d:\n",
2335 priv->net_dev->name, match,
2336 sizeof(struct ipw2100_status));
2338 IPW_DEBUG_INFO("%s: No DMA status match in "
2339 "Firmware.\n", priv->net_dev->name);
2341 printk_buf((u8*)priv->status_queue.drv,
2342 sizeof(struct ipw2100_status) * RX_QUEUE_LENGTH);
2345 priv->fatal_error = IPW2100_ERR_C3_CORRUPTION;
2346 priv->ieee->stats.rx_errors++;
2347 schedule_reset(priv);
2350 static inline void isr_rx(struct ipw2100_priv *priv, int i,
2351 struct ieee80211_rx_stats *stats)
2353 struct ipw2100_status *status = &priv->status_queue.drv[i];
2354 struct ipw2100_rx_packet *packet = &priv->rx_buffers[i];
2356 IPW_DEBUG_RX("Handler...\n");
2358 if (unlikely(status->frame_size > skb_tailroom(packet->skb))) {
2359 IPW_DEBUG_INFO("%s: frame_size (%u) > skb_tailroom (%u)!"
2361 priv->net_dev->name,
2362 status->frame_size, skb_tailroom(packet->skb));
2363 priv->ieee->stats.rx_errors++;
2367 if (unlikely(!netif_running(priv->net_dev))) {
2368 priv->ieee->stats.rx_errors++;
2369 priv->wstats.discard.misc++;
2370 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
2374 if (unlikely(priv->ieee->iw_mode == IW_MODE_MONITOR &&
2375 status->flags & IPW_STATUS_FLAG_CRC_ERROR)) {
2376 IPW_DEBUG_RX("CRC error in packet. Dropping.\n");
2377 priv->ieee->stats.rx_errors++;
2381 if (unlikely(priv->ieee->iw_mode != IW_MODE_MONITOR &&
2382 !(priv->status & STATUS_ASSOCIATED))) {
2383 IPW_DEBUG_DROP("Dropping packet while not associated.\n");
2384 priv->wstats.discard.misc++;
2389 pci_unmap_single(priv->pci_dev,
2391 sizeof(struct ipw2100_rx),
2392 PCI_DMA_FROMDEVICE);
2394 skb_put(packet->skb, status->frame_size);
2396 #ifdef CONFIG_IPW2100_RX_DEBUG
2397 /* Make a copy of the frame so we can dump it to the logs if
2398 * ieee80211_rx fails */
2399 memcpy(packet_data, packet->skb->data,
2400 min_t(u32, status->frame_size, IPW_RX_NIC_BUFFER_LENGTH));
2403 if (!ieee80211_rx(priv->ieee, packet->skb, stats)) {
2404 #ifdef CONFIG_IPW2100_RX_DEBUG
2405 IPW_DEBUG_DROP("%s: Non consumed packet:\n",
2406 priv->net_dev->name);
2407 printk_buf(IPW_DL_DROP, packet_data, status->frame_size);
2409 priv->ieee->stats.rx_errors++;
2411 /* ieee80211_rx failed, so it didn't free the SKB */
2412 dev_kfree_skb_any(packet->skb);
2416 /* We need to allocate a new SKB and attach it to the RDB. */
2417 if (unlikely(ipw2100_alloc_skb(priv, packet))) {
2419 "%s: Unable to allocate SKB onto RBD ring - disabling "
2420 "adapter.\n", priv->net_dev->name);
2421 /* TODO: schedule adapter shutdown */
2422 IPW_DEBUG_INFO("TODO: Shutdown adapter...\n");
2425 /* Update the RDB entry */
2426 priv->rx_queue.drv[i].host_addr = packet->dma_addr;
2429 static inline int ipw2100_corruption_check(struct ipw2100_priv *priv, int i)
2431 struct ipw2100_status *status = &priv->status_queue.drv[i];
2432 struct ipw2100_rx *u = priv->rx_buffers[i].rxp;
2433 u16 frame_type = status->status_fields & STATUS_TYPE_MASK;
2435 switch (frame_type) {
2436 case COMMAND_STATUS_VAL:
2437 return (status->frame_size != sizeof(u->rx_data.command));
2438 case STATUS_CHANGE_VAL:
2439 return (status->frame_size != sizeof(u->rx_data.status));
2440 case HOST_NOTIFICATION_VAL:
2441 return (status->frame_size < sizeof(u->rx_data.notification));
2442 case P80211_DATA_VAL:
2443 case P8023_DATA_VAL:
2444 #ifdef CONFIG_IPW2100_MONITOR
2447 switch (WLAN_FC_GET_TYPE(u->rx_data.header.frame_ctl)) {
2448 case IEEE80211_FTYPE_MGMT:
2449 case IEEE80211_FTYPE_CTL:
2451 case IEEE80211_FTYPE_DATA:
2452 return (status->frame_size >
2453 IPW_MAX_802_11_PAYLOAD_LENGTH);
2462 * ipw2100 interrupts are disabled at this point, and the ISR
2463 * is the only code that calls this method. So, we do not need
2464 * to play with any locks.
2466 * RX Queue works as follows:
2468 * Read index - firmware places packet in entry identified by the
2469 * Read index and advances Read index. In this manner,
2470 * Read index will always point to the next packet to
2471 * be filled--but not yet valid.
2473 * Write index - driver fills this entry with an unused RBD entry.
2474 * This entry has not filled by the firmware yet.
2476 * In between the W and R indexes are the RBDs that have been received
2477 * but not yet processed.
2479 * The process of handling packets will start at WRITE + 1 and advance
2480 * until it reaches the READ index.
2482 * The WRITE index is cached in the variable 'priv->rx_queue.next'.
2485 static inline void __ipw2100_rx_process(struct ipw2100_priv *priv)
2487 struct ipw2100_bd_queue *rxq = &priv->rx_queue;
2488 struct ipw2100_status_queue *sq = &priv->status_queue;
2489 struct ipw2100_rx_packet *packet;
2492 struct ipw2100_rx *u;
2493 struct ieee80211_rx_stats stats = {
2494 .mac_time = jiffies,
2497 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_READ_INDEX, &r);
2498 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_WRITE_INDEX, &w);
2500 if (r >= rxq->entries) {
2501 IPW_DEBUG_RX("exit - bad read index\n");
2505 i = (rxq->next + 1) % rxq->entries;
2508 /* IPW_DEBUG_RX("r = %d : w = %d : processing = %d\n",
2509 r, rxq->next, i); */
2511 packet = &priv->rx_buffers[i];
2513 /* Sync the DMA for the STATUS buffer so CPU is sure to get
2514 * the correct values */
2515 pci_dma_sync_single_for_cpu(
2517 sq->nic + sizeof(struct ipw2100_status) * i,
2518 sizeof(struct ipw2100_status),
2519 PCI_DMA_FROMDEVICE);
2521 /* Sync the DMA for the RX buffer so CPU is sure to get
2522 * the correct values */
2523 pci_dma_sync_single_for_cpu(priv->pci_dev, packet->dma_addr,
2524 sizeof(struct ipw2100_rx),
2525 PCI_DMA_FROMDEVICE);
2527 if (unlikely(ipw2100_corruption_check(priv, i))) {
2528 ipw2100_corruption_detected(priv, i);
2533 frame_type = sq->drv[i].status_fields &
2535 stats.rssi = sq->drv[i].rssi + IPW2100_RSSI_TO_DBM;
2536 stats.len = sq->drv[i].frame_size;
2539 if (stats.rssi != 0)
2540 stats.mask |= IEEE80211_STATMASK_RSSI;
2541 stats.freq = IEEE80211_24GHZ_BAND;
2544 "%s: '%s' frame type received (%d).\n",
2545 priv->net_dev->name, frame_types[frame_type],
2548 switch (frame_type) {
2549 case COMMAND_STATUS_VAL:
2550 /* Reset Rx watchdog */
2551 isr_rx_complete_command(
2552 priv, &u->rx_data.command);
2555 case STATUS_CHANGE_VAL:
2556 isr_status_change(priv, u->rx_data.status);
2559 case P80211_DATA_VAL:
2560 case P8023_DATA_VAL:
2561 #ifdef CONFIG_IPW2100_MONITOR
2562 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
2563 isr_rx(priv, i, &stats);
2567 if (stats.len < sizeof(u->rx_data.header))
2569 switch (WLAN_FC_GET_TYPE(u->rx_data.header.
2571 case IEEE80211_FTYPE_MGMT:
2572 ieee80211_rx_mgt(priv->ieee,
2577 case IEEE80211_FTYPE_CTL:
2580 case IEEE80211_FTYPE_DATA:
2581 isr_rx(priv, i, &stats);
2589 /* clear status field associated with this RBD */
2590 rxq->drv[i].status.info.field = 0;
2592 i = (i + 1) % rxq->entries;
2596 /* backtrack one entry, wrapping to end if at 0 */
2597 rxq->next = (i ? i : rxq->entries) - 1;
2599 write_register(priv->net_dev,
2600 IPW_MEM_HOST_SHARED_RX_WRITE_INDEX,
2607 * __ipw2100_tx_process
2609 * This routine will determine whether the next packet on
2610 * the fw_pend_list has been processed by the firmware yet.
2612 * If not, then it does nothing and returns.
2614 * If so, then it removes the item from the fw_pend_list, frees
2615 * any associated storage, and places the item back on the
2616 * free list of its source (either msg_free_list or tx_free_list)
2618 * TX Queue works as follows:
2620 * Read index - points to the next TBD that the firmware will
2621 * process. The firmware will read the data, and once
2622 * done processing, it will advance the Read index.
2624 * Write index - driver fills this entry with an constructed TBD
2625 * entry. The Write index is not advanced until the
2626 * packet has been configured.
2628 * In between the W and R indexes are the TBDs that have NOT been
2629 * processed. Lagging behind the R index are packets that have
2630 * been processed but have not been freed by the driver.
2632 * In order to free old storage, an internal index will be maintained
2633 * that points to the next packet to be freed. When all used
2634 * packets have been freed, the oldest index will be the same as the
2635 * firmware's read index.
2637 * The OLDEST index is cached in the variable 'priv->tx_queue.oldest'
2639 * Because the TBD structure can not contain arbitrary data, the
2640 * driver must keep an internal queue of cached allocations such that
2641 * it can put that data back into the tx_free_list and msg_free_list
2642 * for use by future command and data packets.
2645 static inline int __ipw2100_tx_process(struct ipw2100_priv *priv)
2647 struct ipw2100_bd_queue *txq = &priv->tx_queue;
2648 struct ipw2100_bd *tbd;
2649 struct list_head *element;
2650 struct ipw2100_tx_packet *packet;
2651 int descriptors_used;
2653 u32 r, w, frag_num = 0;
2655 if (list_empty(&priv->fw_pend_list))
2658 element = priv->fw_pend_list.next;
2660 packet = list_entry(element, struct ipw2100_tx_packet, list);
2661 tbd = &txq->drv[packet->index];
2663 /* Determine how many TBD entries must be finished... */
2664 switch (packet->type) {
2666 /* COMMAND uses only one slot; don't advance */
2667 descriptors_used = 1;
2672 /* DATA uses two slots; advance and loop position. */
2673 descriptors_used = tbd->num_fragments;
2674 frag_num = tbd->num_fragments - 1;
2675 e = txq->oldest + frag_num;
2680 IPW_DEBUG_WARNING("%s: Bad fw_pend_list entry!\n",
2681 priv->net_dev->name);
2685 /* if the last TBD is not done by NIC yet, then packet is
2686 * not ready to be released.
2689 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_TX_QUEUE_READ_INDEX,
2691 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX,
2694 IPW_DEBUG_WARNING("%s: write index mismatch\n",
2695 priv->net_dev->name);
2698 * txq->next is the index of the last packet written txq->oldest is
2699 * the index of the r is the index of the next packet to be read by
2705 * Quick graphic to help you visualize the following
2706 * if / else statement
2708 * ===>| s---->|===============
2710 * | a | b | c | d | e | f | g | h | i | j | k | l
2714 * w - updated by driver
2715 * r - updated by firmware
2716 * s - start of oldest BD entry (txq->oldest)
2717 * e - end of oldest BD entry
2720 if (!((r <= w && (e < r || e >= w)) || (e < r && e >= w))) {
2721 IPW_DEBUG_TX("exit - no processed packets ready to release.\n");
2726 DEC_STAT(&priv->fw_pend_stat);
2728 #ifdef CONFIG_IPW_DEBUG
2730 int i = txq->oldest;
2732 "TX%d V=%p P=%04X T=%04X L=%d\n", i,
2734 (u32)(txq->nic + i * sizeof(struct ipw2100_bd)),
2735 txq->drv[i].host_addr,
2736 txq->drv[i].buf_length);
2738 if (packet->type == DATA) {
2739 i = (i + 1) % txq->entries;
2742 "TX%d V=%p P=%04X T=%04X L=%d\n", i,
2744 (u32)(txq->nic + i *
2745 sizeof(struct ipw2100_bd)),
2746 (u32)txq->drv[i].host_addr,
2747 txq->drv[i].buf_length);
2752 switch (packet->type) {
2754 if (txq->drv[txq->oldest].status.info.fields.txType != 0)
2755 IPW_DEBUG_WARNING("%s: Queue mismatch. "
2756 "Expecting DATA TBD but pulled "
2757 "something else: ids %d=%d.\n",
2758 priv->net_dev->name, txq->oldest, packet->index);
2760 /* DATA packet; we have to unmap and free the SKB */
2761 priv->ieee->stats.tx_packets++;
2762 for (i = 0; i < frag_num; i++) {
2763 tbd = &txq->drv[(packet->index + 1 + i) %
2767 "TX%d P=%08x L=%d\n",
2768 (packet->index + 1 + i) % txq->entries,
2769 tbd->host_addr, tbd->buf_length);
2771 pci_unmap_single(priv->pci_dev,
2777 priv->ieee->stats.tx_bytes += packet->info.d_struct.txb->payload_size;
2778 ieee80211_txb_free(packet->info.d_struct.txb);
2779 packet->info.d_struct.txb = NULL;
2781 list_add_tail(element, &priv->tx_free_list);
2782 INC_STAT(&priv->tx_free_stat);
2784 /* We have a free slot in the Tx queue, so wake up the
2785 * transmit layer if it is stopped. */
2786 if (priv->status & STATUS_ASSOCIATED &&
2787 netif_queue_stopped(priv->net_dev)) {
2788 IPW_DEBUG_INFO(KERN_INFO
2789 "%s: Waking net queue.\n",
2790 priv->net_dev->name);
2791 netif_wake_queue(priv->net_dev);
2794 /* A packet was processed by the hardware, so update the
2796 priv->net_dev->trans_start = jiffies;
2801 if (txq->drv[txq->oldest].status.info.fields.txType != 1)
2802 IPW_DEBUG_WARNING("%s: Queue mismatch. "
2803 "Expecting COMMAND TBD but pulled "
2804 "something else: ids %d=%d.\n",
2805 priv->net_dev->name, txq->oldest, packet->index);
2807 #ifdef CONFIG_IPW_DEBUG
2808 if (packet->info.c_struct.cmd->host_command_reg <
2809 sizeof(command_types) / sizeof(*command_types))
2811 "Command '%s (%d)' processed: %d.\n",
2812 command_types[packet->info.c_struct.cmd->host_command_reg],
2813 packet->info.c_struct.cmd->host_command_reg,
2814 packet->info.c_struct.cmd->cmd_status_reg);
2817 list_add_tail(element, &priv->msg_free_list);
2818 INC_STAT(&priv->msg_free_stat);
2822 /* advance oldest used TBD pointer to start of next entry */
2823 txq->oldest = (e + 1) % txq->entries;
2824 /* increase available TBDs number */
2825 txq->available += descriptors_used;
2826 SET_STAT(&priv->txq_stat, txq->available);
2828 IPW_DEBUG_TX("packet latency (send to process) %ld jiffies\n",
2829 jiffies - packet->jiffy_start);
2831 return (!list_empty(&priv->fw_pend_list));
2835 static inline void __ipw2100_tx_complete(struct ipw2100_priv *priv)
2839 while (__ipw2100_tx_process(priv) && i < 200) i++;
2843 "%s: Driver is running slow (%d iters).\n",
2844 priv->net_dev->name, i);
2849 static void X__ipw2100_tx_send_commands(struct ipw2100_priv *priv)
2851 struct list_head *element;
2852 struct ipw2100_tx_packet *packet;
2853 struct ipw2100_bd_queue *txq = &priv->tx_queue;
2854 struct ipw2100_bd *tbd;
2855 int next = txq->next;
2857 while (!list_empty(&priv->msg_pend_list)) {
2858 /* if there isn't enough space in TBD queue, then
2859 * don't stuff a new one in.
2860 * NOTE: 3 are needed as a command will take one,
2861 * and there is a minimum of 2 that must be
2862 * maintained between the r and w indexes
2864 if (txq->available <= 3) {
2865 IPW_DEBUG_TX("no room in tx_queue\n");
2869 element = priv->msg_pend_list.next;
2871 DEC_STAT(&priv->msg_pend_stat);
2873 packet = list_entry(element,
2874 struct ipw2100_tx_packet, list);
2876 IPW_DEBUG_TX("using TBD at virt=%p, phys=%p\n",
2877 &txq->drv[txq->next],
2878 (void*)(txq->nic + txq->next *
2879 sizeof(struct ipw2100_bd)));
2881 packet->index = txq->next;
2883 tbd = &txq->drv[txq->next];
2885 /* initialize TBD */
2886 tbd->host_addr = packet->info.c_struct.cmd_phys;
2887 tbd->buf_length = sizeof(struct ipw2100_cmd_header);
2888 /* not marking number of fragments causes problems
2889 * with f/w debug version */
2890 tbd->num_fragments = 1;
2891 tbd->status.info.field =
2892 IPW_BD_STATUS_TX_FRAME_COMMAND |
2893 IPW_BD_STATUS_TX_INTERRUPT_ENABLE;
2895 /* update TBD queue counters */
2897 txq->next %= txq->entries;
2899 DEC_STAT(&priv->txq_stat);
2901 list_add_tail(element, &priv->fw_pend_list);
2902 INC_STAT(&priv->fw_pend_stat);
2905 if (txq->next != next) {
2906 /* kick off the DMA by notifying firmware the
2907 * write index has moved; make sure TBD stores are sync'd */
2909 write_register(priv->net_dev,
2910 IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX,
2917 * X__ipw2100_tx_send_data
2920 static void X__ipw2100_tx_send_data(struct ipw2100_priv *priv)
2922 struct list_head *element;
2923 struct ipw2100_tx_packet *packet;
2924 struct ipw2100_bd_queue *txq = &priv->tx_queue;
2925 struct ipw2100_bd *tbd;
2926 int next = txq->next;
2928 struct ipw2100_data_header *ipw_hdr;
2929 struct ieee80211_hdr *hdr;
2931 while (!list_empty(&priv->tx_pend_list)) {
2932 /* if there isn't enough space in TBD queue, then
2933 * don't stuff a new one in.
2934 * NOTE: 4 are needed as a data will take two,
2935 * and there is a minimum of 2 that must be
2936 * maintained between the r and w indexes
2938 element = priv->tx_pend_list.next;
2939 packet = list_entry(element, struct ipw2100_tx_packet, list);
2941 if (unlikely(1 + packet->info.d_struct.txb->nr_frags >
2943 /* TODO: Support merging buffers if more than
2944 * IPW_MAX_BDS are used */
2946 "%s: Maximum BD theshold exceeded. "
2947 "Increase fragmentation level.\n",
2948 priv->net_dev->name);
2951 if (txq->available <= 3 +
2952 packet->info.d_struct.txb->nr_frags) {
2953 IPW_DEBUG_TX("no room in tx_queue\n");
2958 DEC_STAT(&priv->tx_pend_stat);
2960 tbd = &txq->drv[txq->next];
2962 packet->index = txq->next;
2964 ipw_hdr = packet->info.d_struct.data;
2965 hdr = (struct ieee80211_hdr *)packet->info.d_struct.txb->
2968 if (priv->ieee->iw_mode == IW_MODE_INFRA) {
2969 /* To DS: Addr1 = BSSID, Addr2 = SA,
2971 memcpy(ipw_hdr->src_addr, hdr->addr2, ETH_ALEN);
2972 memcpy(ipw_hdr->dst_addr, hdr->addr3, ETH_ALEN);
2973 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
2974 /* not From/To DS: Addr1 = DA, Addr2 = SA,
2976 memcpy(ipw_hdr->src_addr, hdr->addr2, ETH_ALEN);
2977 memcpy(ipw_hdr->dst_addr, hdr->addr1, ETH_ALEN);
2980 ipw_hdr->host_command_reg = SEND;
2981 ipw_hdr->host_command_reg1 = 0;
2983 /* For now we only support host based encryption */
2984 ipw_hdr->needs_encryption = 0;
2985 ipw_hdr->encrypted = packet->info.d_struct.txb->encrypted;
2986 if (packet->info.d_struct.txb->nr_frags > 1)
2987 ipw_hdr->fragment_size =
2988 packet->info.d_struct.txb->frag_size - IEEE80211_3ADDR_LEN;
2990 ipw_hdr->fragment_size = 0;
2992 tbd->host_addr = packet->info.d_struct.data_phys;
2993 tbd->buf_length = sizeof(struct ipw2100_data_header);
2994 tbd->num_fragments = 1 + packet->info.d_struct.txb->nr_frags;
2995 tbd->status.info.field =
2996 IPW_BD_STATUS_TX_FRAME_802_3 |
2997 IPW_BD_STATUS_TX_FRAME_NOT_LAST_FRAGMENT;
2999 txq->next %= txq->entries;
3002 "data header tbd TX%d P=%08x L=%d\n",
3003 packet->index, tbd->host_addr,
3005 #ifdef CONFIG_IPW_DEBUG
3006 if (packet->info.d_struct.txb->nr_frags > 1)
3007 IPW_DEBUG_FRAG("fragment Tx: %d frames\n",
3008 packet->info.d_struct.txb->nr_frags);
3011 for (i = 0; i < packet->info.d_struct.txb->nr_frags; i++) {
3012 tbd = &txq->drv[txq->next];
3013 if (i == packet->info.d_struct.txb->nr_frags - 1)
3014 tbd->status.info.field =
3015 IPW_BD_STATUS_TX_FRAME_802_3 |
3016 IPW_BD_STATUS_TX_INTERRUPT_ENABLE;
3018 tbd->status.info.field =
3019 IPW_BD_STATUS_TX_FRAME_802_3 |
3020 IPW_BD_STATUS_TX_FRAME_NOT_LAST_FRAGMENT;
3022 tbd->buf_length = packet->info.d_struct.txb->
3023 fragments[i]->len - IEEE80211_3ADDR_LEN;
3025 tbd->host_addr = pci_map_single(
3027 packet->info.d_struct.txb->fragments[i]->data +
3028 IEEE80211_3ADDR_LEN,
3033 "data frag tbd TX%d P=%08x L=%d\n",
3034 txq->next, tbd->host_addr, tbd->buf_length);
3036 pci_dma_sync_single_for_device(
3037 priv->pci_dev, tbd->host_addr,
3042 txq->next %= txq->entries;
3045 txq->available -= 1 + packet->info.d_struct.txb->nr_frags;
3046 SET_STAT(&priv->txq_stat, txq->available);
3048 list_add_tail(element, &priv->fw_pend_list);
3049 INC_STAT(&priv->fw_pend_stat);
3052 if (txq->next != next) {
3053 /* kick off the DMA by notifying firmware the
3054 * write index has moved; make sure TBD stores are sync'd */
3055 write_register(priv->net_dev,
3056 IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX,
3062 static void ipw2100_irq_tasklet(struct ipw2100_priv *priv)
3064 struct net_device *dev = priv->net_dev;
3065 unsigned long flags;
3068 spin_lock_irqsave(&priv->low_lock, flags);
3069 ipw2100_disable_interrupts(priv);
3071 read_register(dev, IPW_REG_INTA, &inta);
3073 IPW_DEBUG_ISR("enter - INTA: 0x%08lX\n",
3074 (unsigned long)inta & IPW_INTERRUPT_MASK);
3079 /* We do not loop and keep polling for more interrupts as this
3080 * is frowned upon and doesn't play nicely with other potentially
3082 IPW_DEBUG_ISR("INTA: 0x%08lX\n",
3083 (unsigned long)inta & IPW_INTERRUPT_MASK);
3085 if (inta & IPW2100_INTA_FATAL_ERROR) {
3086 IPW_DEBUG_WARNING(DRV_NAME
3087 ": Fatal interrupt. Scheduling firmware restart.\n");
3091 IPW2100_INTA_FATAL_ERROR);
3093 read_nic_dword(dev, IPW_NIC_FATAL_ERROR, &priv->fatal_error);
3094 IPW_DEBUG_INFO("%s: Fatal error value: 0x%08X\n",
3095 priv->net_dev->name, priv->fatal_error);
3097 read_nic_dword(dev, IPW_ERROR_ADDR(priv->fatal_error), &tmp);
3098 IPW_DEBUG_INFO("%s: Fatal error address value: 0x%08X\n",
3099 priv->net_dev->name, tmp);
3101 /* Wake up any sleeping jobs */
3102 schedule_reset(priv);
3105 if (inta & IPW2100_INTA_PARITY_ERROR) {
3106 IPW_DEBUG_ERROR("***** PARITY ERROR INTERRUPT !!!! \n");
3110 IPW2100_INTA_PARITY_ERROR);
3113 if (inta & IPW2100_INTA_RX_TRANSFER) {
3114 IPW_DEBUG_ISR("RX interrupt\n");
3116 priv->rx_interrupts++;
3120 IPW2100_INTA_RX_TRANSFER);
3122 __ipw2100_rx_process(priv);
3123 __ipw2100_tx_complete(priv);
3126 if (inta & IPW2100_INTA_TX_TRANSFER) {
3127 IPW_DEBUG_ISR("TX interrupt\n");
3129 priv->tx_interrupts++;
3131 write_register(dev, IPW_REG_INTA,
3132 IPW2100_INTA_TX_TRANSFER);
3134 __ipw2100_tx_complete(priv);
3135 X__ipw2100_tx_send_commands(priv);
3136 X__ipw2100_tx_send_data(priv);
3139 if (inta & IPW2100_INTA_TX_COMPLETE) {
3140 IPW_DEBUG_ISR("TX complete\n");
3144 IPW2100_INTA_TX_COMPLETE);
3146 __ipw2100_tx_complete(priv);
3149 if (inta & IPW2100_INTA_EVENT_INTERRUPT) {
3150 /* ipw2100_handle_event(dev); */
3154 IPW2100_INTA_EVENT_INTERRUPT);
3157 if (inta & IPW2100_INTA_FW_INIT_DONE) {
3158 IPW_DEBUG_ISR("FW init done interrupt\n");
3161 read_register(dev, IPW_REG_INTA, &tmp);
3162 if (tmp & (IPW2100_INTA_FATAL_ERROR |
3163 IPW2100_INTA_PARITY_ERROR)) {
3166 IPW2100_INTA_FATAL_ERROR |
3167 IPW2100_INTA_PARITY_ERROR);
3170 write_register(dev, IPW_REG_INTA,
3171 IPW2100_INTA_FW_INIT_DONE);
3174 if (inta & IPW2100_INTA_STATUS_CHANGE) {
3175 IPW_DEBUG_ISR("Status change interrupt\n");
3179 IPW2100_INTA_STATUS_CHANGE);
3182 if (inta & IPW2100_INTA_SLAVE_MODE_HOST_COMMAND_DONE) {
3183 IPW_DEBUG_ISR("slave host mode interrupt\n");
3187 IPW2100_INTA_SLAVE_MODE_HOST_COMMAND_DONE);
3191 ipw2100_enable_interrupts(priv);
3193 spin_unlock_irqrestore(&priv->low_lock, flags);
3195 IPW_DEBUG_ISR("exit\n");
3199 static irqreturn_t ipw2100_interrupt(int irq, void *data,
3200 struct pt_regs *regs)
3202 struct ipw2100_priv *priv = data;
3203 u32 inta, inta_mask;
3208 spin_lock(&priv->low_lock);
3210 /* We check to see if we should be ignoring interrupts before
3211 * we touch the hardware. During ucode load if we try and handle
3212 * an interrupt we can cause keyboard problems as well as cause
3213 * the ucode to fail to initialize */
3214 if (!(priv->status & STATUS_INT_ENABLED)) {
3219 read_register(priv->net_dev, IPW_REG_INTA_MASK, &inta_mask);
3220 read_register(priv->net_dev, IPW_REG_INTA, &inta);
3222 if (inta == 0xFFFFFFFF) {
3223 /* Hardware disappeared */
3224 IPW_DEBUG_WARNING("IRQ INTA == 0xFFFFFFFF\n");
3228 inta &= IPW_INTERRUPT_MASK;
3230 if (!(inta & inta_mask)) {
3231 /* Shared interrupt */
3235 /* We disable the hardware interrupt here just to prevent unneeded
3236 * calls to be made. We disable this again within the actual
3237 * work tasklet, so if another part of the code re-enables the
3238 * interrupt, that is fine */
3239 ipw2100_disable_interrupts(priv);
3241 tasklet_schedule(&priv->irq_tasklet);
3242 spin_unlock(&priv->low_lock);
3246 spin_unlock(&priv->low_lock);
3250 static int ipw2100_tx(struct ieee80211_txb *txb, struct net_device *dev)
3252 struct ipw2100_priv *priv = ieee80211_priv(dev);
3253 struct list_head *element;
3254 struct ipw2100_tx_packet *packet;
3255 unsigned long flags;
3257 spin_lock_irqsave(&priv->low_lock, flags);
3259 if (!(priv->status & STATUS_ASSOCIATED)) {
3260 IPW_DEBUG_INFO("Can not transmit when not connected.\n");
3261 priv->ieee->stats.tx_carrier_errors++;
3262 netif_stop_queue(dev);
3266 if (list_empty(&priv->tx_free_list))
3269 element = priv->tx_free_list.next;
3270 packet = list_entry(element, struct ipw2100_tx_packet, list);
3272 packet->info.d_struct.txb = txb;
3274 IPW_DEBUG_TX("Sending fragment (%d bytes):\n",
3275 txb->fragments[0]->len);
3276 printk_buf(IPW_DL_TX, txb->fragments[0]->data,
3277 txb->fragments[0]->len);
3279 packet->jiffy_start = jiffies;
3282 DEC_STAT(&priv->tx_free_stat);
3284 list_add_tail(element, &priv->tx_pend_list);
3285 INC_STAT(&priv->tx_pend_stat);
3287 X__ipw2100_tx_send_data(priv);
3289 spin_unlock_irqrestore(&priv->low_lock, flags);
3293 netif_stop_queue(dev);
3294 spin_unlock_irqrestore(&priv->low_lock, flags);
3299 static int ipw2100_msg_allocate(struct ipw2100_priv *priv)
3301 int i, j, err = -EINVAL;
3305 priv->msg_buffers = (struct ipw2100_tx_packet *)kmalloc(
3306 IPW_COMMAND_POOL_SIZE * sizeof(struct ipw2100_tx_packet),
3308 if (!priv->msg_buffers) {
3309 IPW_DEBUG_ERROR("%s: PCI alloc failed for msg "
3310 "buffers.\n", priv->net_dev->name);
3314 for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++) {
3315 v = pci_alloc_consistent(
3317 sizeof(struct ipw2100_cmd_header),
3321 "%s: PCI alloc failed for msg "
3323 priv->net_dev->name);
3328 memset(v, 0, sizeof(struct ipw2100_cmd_header));
3330 priv->msg_buffers[i].type = COMMAND;
3331 priv->msg_buffers[i].info.c_struct.cmd =
3332 (struct ipw2100_cmd_header*)v;
3333 priv->msg_buffers[i].info.c_struct.cmd_phys = p;
3336 if (i == IPW_COMMAND_POOL_SIZE)
3339 for (j = 0; j < i; j++) {
3340 pci_free_consistent(
3342 sizeof(struct ipw2100_cmd_header),
3343 priv->msg_buffers[j].info.c_struct.cmd,
3344 priv->msg_buffers[j].info.c_struct.cmd_phys);
3347 kfree(priv->msg_buffers);
3348 priv->msg_buffers = NULL;
3353 static int ipw2100_msg_initialize(struct ipw2100_priv *priv)
3357 INIT_LIST_HEAD(&priv->msg_free_list);
3358 INIT_LIST_HEAD(&priv->msg_pend_list);
3360 for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++)
3361 list_add_tail(&priv->msg_buffers[i].list, &priv->msg_free_list);
3362 SET_STAT(&priv->msg_free_stat, i);
3367 static void ipw2100_msg_free(struct ipw2100_priv *priv)
3371 if (!priv->msg_buffers)
3374 for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++) {
3375 pci_free_consistent(priv->pci_dev,
3376 sizeof(struct ipw2100_cmd_header),
3377 priv->msg_buffers[i].info.c_struct.cmd,
3378 priv->msg_buffers[i].info.c_struct.cmd_phys);
3381 kfree(priv->msg_buffers);
3382 priv->msg_buffers = NULL;
3385 static ssize_t show_pci(struct device *d, char *buf)
3387 struct pci_dev *pci_dev = container_of(d, struct pci_dev, dev);
3392 for (i = 0; i < 16; i++) {
3393 out += sprintf(out, "[%08X] ", i * 16);
3394 for (j = 0; j < 16; j += 4) {
3395 pci_read_config_dword(pci_dev, i * 16 + j, &val);
3396 out += sprintf(out, "%08X ", val);
3398 out += sprintf(out, "\n");
3403 static DEVICE_ATTR(pci, S_IRUGO, show_pci, NULL);
3405 static ssize_t show_cfg(struct device *d, char *buf)
3407 struct ipw2100_priv *p = (struct ipw2100_priv *)d->driver_data;
3408 return sprintf(buf, "0x%08x\n", (int)p->config);
3410 static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
3412 static ssize_t show_status(struct device *d, char *buf)
3414 struct ipw2100_priv *p = (struct ipw2100_priv *)d->driver_data;
3415 return sprintf(buf, "0x%08x\n", (int)p->status);
3417 static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
3419 static ssize_t show_capability(struct device *d, char *buf)
3421 struct ipw2100_priv *p = (struct ipw2100_priv *)d->driver_data;
3422 return sprintf(buf, "0x%08x\n", (int)p->capability);
3424 static DEVICE_ATTR(capability, S_IRUGO, show_capability, NULL);
3427 #define IPW2100_REG(x) { IPW_ ##x, #x }
3432 IPW2100_REG(REG_GP_CNTRL),
3433 IPW2100_REG(REG_GPIO),
3434 IPW2100_REG(REG_INTA),
3435 IPW2100_REG(REG_INTA_MASK),
3436 IPW2100_REG(REG_RESET_REG),
3438 #define IPW2100_NIC(x, s) { x, #x, s }
3444 IPW2100_NIC(IPW2100_CONTROL_REG, 2),
3445 IPW2100_NIC(0x210014, 1),
3446 IPW2100_NIC(0x210000, 1),
3448 #define IPW2100_ORD(x, d) { IPW_ORD_ ##x, #x, d }
3454 IPW2100_ORD(STAT_TX_HOST_REQUESTS, "requested Host Tx's (MSDU)"),
3455 IPW2100_ORD(STAT_TX_HOST_COMPLETE, "successful Host Tx's (MSDU)"),
3456 IPW2100_ORD(STAT_TX_DIR_DATA, "successful Directed Tx's (MSDU)"),
3457 IPW2100_ORD(STAT_TX_DIR_DATA1, "successful Directed Tx's (MSDU) @ 1MB"),
3458 IPW2100_ORD(STAT_TX_DIR_DATA2, "successful Directed Tx's (MSDU) @ 2MB"),
3459 IPW2100_ORD(STAT_TX_DIR_DATA5_5, "successful Directed Tx's (MSDU) @ 5_5MB"),
3460 IPW2100_ORD(STAT_TX_DIR_DATA11, "successful Directed Tx's (MSDU) @ 11MB"),
3461 IPW2100_ORD(STAT_TX_NODIR_DATA1, "successful Non_Directed Tx's (MSDU) @ 1MB"),
3462 IPW2100_ORD(STAT_TX_NODIR_DATA2, "successful Non_Directed Tx's (MSDU) @ 2MB"),
3463 IPW2100_ORD(STAT_TX_NODIR_DATA5_5, "successful Non_Directed Tx's (MSDU) @ 5.5MB"),
3464 IPW2100_ORD(STAT_TX_NODIR_DATA11, "successful Non_Directed Tx's (MSDU) @ 11MB"),
3465 IPW2100_ORD(STAT_NULL_DATA, "successful NULL data Tx's"),
3466 IPW2100_ORD(STAT_TX_RTS, "successful Tx RTS"),
3467 IPW2100_ORD(STAT_TX_CTS, "successful Tx CTS"),
3468 IPW2100_ORD(STAT_TX_ACK, "successful Tx ACK"),
3469 IPW2100_ORD(STAT_TX_ASSN, "successful Association Tx's"),
3470 IPW2100_ORD(STAT_TX_ASSN_RESP, "successful Association response Tx's"),
3471 IPW2100_ORD(STAT_TX_REASSN, "successful Reassociation Tx's"),
3472 IPW2100_ORD(STAT_TX_REASSN_RESP, "successful Reassociation response Tx's"),
3473 IPW2100_ORD(STAT_TX_PROBE, "probes successfully transmitted"),
3474 IPW2100_ORD(STAT_TX_PROBE_RESP, "probe responses successfully transmitted"),
3475 IPW2100_ORD(STAT_TX_BEACON, "tx beacon"),
3476 IPW2100_ORD(STAT_TX_ATIM, "Tx ATIM"),
3477 IPW2100_ORD(STAT_TX_DISASSN, "successful Disassociation TX"),
3478 IPW2100_ORD(STAT_TX_AUTH, "successful Authentication Tx"),
3479 IPW2100_ORD(STAT_TX_DEAUTH, "successful Deauthentication TX"),
3480 IPW2100_ORD(STAT_TX_TOTAL_BYTES, "Total successful Tx data bytes"),
3481 IPW2100_ORD(STAT_TX_RETRIES, "Tx retries"),
3482 IPW2100_ORD(STAT_TX_RETRY1, "Tx retries at 1MBPS"),
3483 IPW2100_ORD(STAT_TX_RETRY2, "Tx retries at 2MBPS"),
3484 IPW2100_ORD(STAT_TX_RETRY5_5, "Tx retries at 5.5MBPS"),
3485 IPW2100_ORD(STAT_TX_RETRY11, "Tx retries at 11MBPS"),
3486 IPW2100_ORD(STAT_TX_FAILURES, "Tx Failures"),
3487 IPW2100_ORD(STAT_TX_MAX_TRIES_IN_HOP,"times max tries in a hop failed"),
3488 IPW2100_ORD(STAT_TX_DISASSN_FAIL, "times disassociation failed"),
3489 IPW2100_ORD(STAT_TX_ERR_CTS, "missed/bad CTS frames"),
3490 IPW2100_ORD(STAT_TX_ERR_ACK, "tx err due to acks"),
3491 IPW2100_ORD(STAT_RX_HOST, "packets passed to host"),
3492 IPW2100_ORD(STAT_RX_DIR_DATA, "directed packets"),
3493 IPW2100_ORD(STAT_RX_DIR_DATA1, "directed packets at 1MB"),
3494 IPW2100_ORD(STAT_RX_DIR_DATA2, "directed packets at 2MB"),
3495 IPW2100_ORD(STAT_RX_DIR_DATA5_5, "directed packets at 5.5MB"),
3496 IPW2100_ORD(STAT_RX_DIR_DATA11, "directed packets at 11MB"),
3497 IPW2100_ORD(STAT_RX_NODIR_DATA,"nondirected packets"),
3498 IPW2100_ORD(STAT_RX_NODIR_DATA1, "nondirected packets at 1MB"),
3499 IPW2100_ORD(STAT_RX_NODIR_DATA2, "nondirected packets at 2MB"),
3500 IPW2100_ORD(STAT_RX_NODIR_DATA5_5, "nondirected packets at 5.5MB"),
3501 IPW2100_ORD(STAT_RX_NODIR_DATA11, "nondirected packets at 11MB"),
3502 IPW2100_ORD(STAT_RX_NULL_DATA, "null data rx's"),
3503 IPW2100_ORD(STAT_RX_RTS, "Rx RTS"),
3504 IPW2100_ORD(STAT_RX_CTS, "Rx CTS"),
3505 IPW2100_ORD(STAT_RX_ACK, "Rx ACK"),
3506 IPW2100_ORD(STAT_RX_CFEND, "Rx CF End"),
3507 IPW2100_ORD(STAT_RX_CFEND_ACK, "Rx CF End + CF Ack"),
3508 IPW2100_ORD(STAT_RX_ASSN, "Association Rx's"),
3509 IPW2100_ORD(STAT_RX_ASSN_RESP, "Association response Rx's"),
3510 IPW2100_ORD(STAT_RX_REASSN, "Reassociation Rx's"),
3511 IPW2100_ORD(STAT_RX_REASSN_RESP, "Reassociation response Rx's"),
3512 IPW2100_ORD(STAT_RX_PROBE, "probe Rx's"),
3513 IPW2100_ORD(STAT_RX_PROBE_RESP, "probe response Rx's"),
3514 IPW2100_ORD(STAT_RX_BEACON, "Rx beacon"),
3515 IPW2100_ORD(STAT_RX_ATIM, "Rx ATIM"),
3516 IPW2100_ORD(STAT_RX_DISASSN, "disassociation Rx"),
3517 IPW2100_ORD(STAT_RX_AUTH, "authentication Rx"),
3518 IPW2100_ORD(STAT_RX_DEAUTH, "deauthentication Rx"),
3519 IPW2100_ORD(STAT_RX_TOTAL_BYTES,"Total rx data bytes received"),
3520 IPW2100_ORD(STAT_RX_ERR_CRC, "packets with Rx CRC error"),
3521 IPW2100_ORD(STAT_RX_ERR_CRC1, "Rx CRC errors at 1MB"),
3522 IPW2100_ORD(STAT_RX_ERR_CRC2, "Rx CRC errors at 2MB"),
3523 IPW2100_ORD(STAT_RX_ERR_CRC5_5, "Rx CRC errors at 5.5MB"),
3524 IPW2100_ORD(STAT_RX_ERR_CRC11, "Rx CRC errors at 11MB"),
3525 IPW2100_ORD(STAT_RX_DUPLICATE1, "duplicate rx packets at 1MB"),
3526 IPW2100_ORD(STAT_RX_DUPLICATE2, "duplicate rx packets at 2MB"),
3527 IPW2100_ORD(STAT_RX_DUPLICATE5_5, "duplicate rx packets at 5.5MB"),
3528 IPW2100_ORD(STAT_RX_DUPLICATE11, "duplicate rx packets at 11MB"),
3529 IPW2100_ORD(STAT_RX_DUPLICATE, "duplicate rx packets"),
3530 IPW2100_ORD(PERS_DB_LOCK, "locking fw permanent db"),
3531 IPW2100_ORD(PERS_DB_SIZE, "size of fw permanent db"),
3532 IPW2100_ORD(PERS_DB_ADDR, "address of fw permanent db"),
3533 IPW2100_ORD(STAT_RX_INVALID_PROTOCOL, "rx frames with invalid protocol"),
3534 IPW2100_ORD(SYS_BOOT_TIME, "Boot time"),
3535 IPW2100_ORD(STAT_RX_NO_BUFFER, "rx frames rejected due to no buffer"),
3536 IPW2100_ORD(STAT_RX_MISSING_FRAG, "rx frames dropped due to missing fragment"),
3537 IPW2100_ORD(STAT_RX_ORPHAN_FRAG, "rx frames dropped due to non-sequential fragment"),
3538 IPW2100_ORD(STAT_RX_ORPHAN_FRAME, "rx frames dropped due to unmatched 1st frame"),
3539 IPW2100_ORD(STAT_RX_FRAG_AGEOUT, "rx frames dropped due to uncompleted frame"),
3540 IPW2100_ORD(STAT_RX_ICV_ERRORS, "ICV errors during decryption"),
3541 IPW2100_ORD(STAT_PSP_SUSPENSION,"times adapter suspended"),
3542 IPW2100_ORD(STAT_PSP_BCN_TIMEOUT, "beacon timeout"),
3543 IPW2100_ORD(STAT_PSP_POLL_TIMEOUT, "poll response timeouts"),
3544 IPW2100_ORD(STAT_PSP_NONDIR_TIMEOUT, "timeouts waiting for last {broad,multi}cast pkt"),
3545 IPW2100_ORD(STAT_PSP_RX_DTIMS, "PSP DTIMs received"),
3546 IPW2100_ORD(STAT_PSP_RX_TIMS, "PSP TIMs received"),
3547 IPW2100_ORD(STAT_PSP_STATION_ID,"PSP Station ID"),
3548 IPW2100_ORD(LAST_ASSN_TIME, "RTC time of last association"),
3549 IPW2100_ORD(STAT_PERCENT_MISSED_BCNS,"current calculation of % missed beacons"),
3550 IPW2100_ORD(STAT_PERCENT_RETRIES,"current calculation of % missed tx retries"),
3551 IPW2100_ORD(ASSOCIATED_AP_PTR, "0 if not associated, else pointer to AP table entry"),
3552 IPW2100_ORD(AVAILABLE_AP_CNT, "AP's decsribed in the AP table"),
3553 IPW2100_ORD(AP_LIST_PTR, "Ptr to list of available APs"),
3554 IPW2100_ORD(STAT_AP_ASSNS, "associations"),
3555 IPW2100_ORD(STAT_ASSN_FAIL, "association failures"),
3556 IPW2100_ORD(STAT_ASSN_RESP_FAIL,"failures due to response fail"),
3557 IPW2100_ORD(STAT_FULL_SCANS, "full scans"),
3558 IPW2100_ORD(CARD_DISABLED, "Card Disabled"),
3559 IPW2100_ORD(STAT_ROAM_INHIBIT, "times roaming was inhibited due to activity"),
3560 IPW2100_ORD(RSSI_AT_ASSN, "RSSI of associated AP at time of association"),
3561 IPW2100_ORD(STAT_ASSN_CAUSE1, "reassociation: no probe response or TX on hop"),
3562 IPW2100_ORD(STAT_ASSN_CAUSE2, "reassociation: poor tx/rx quality"),
3563 IPW2100_ORD(STAT_ASSN_CAUSE3, "reassociation: tx/rx quality (excessive AP load"),
3564 IPW2100_ORD(STAT_ASSN_CAUSE4, "reassociation: AP RSSI level"),
3565 IPW2100_ORD(STAT_ASSN_CAUSE5, "reassociations due to load leveling"),
3566 IPW2100_ORD(STAT_AUTH_FAIL, "times authentication failed"),
3567 IPW2100_ORD(STAT_AUTH_RESP_FAIL,"times authentication response failed"),
3568 IPW2100_ORD(STATION_TABLE_CNT, "entries in association table"),
3569 IPW2100_ORD(RSSI_AVG_CURR, "Current avg RSSI"),
3570 IPW2100_ORD(POWER_MGMT_MODE, "Power mode - 0=CAM, 1=PSP"),
3571 IPW2100_ORD(COUNTRY_CODE, "IEEE country code as recv'd from beacon"),
3572 IPW2100_ORD(COUNTRY_CHANNELS, "channels suported by country"),
3573 IPW2100_ORD(RESET_CNT, "adapter resets (warm)"),
3574 IPW2100_ORD(BEACON_INTERVAL, "Beacon interval"),
3575 IPW2100_ORD(ANTENNA_DIVERSITY, "TRUE if antenna diversity is disabled"),
3576 IPW2100_ORD(DTIM_PERIOD, "beacon intervals between DTIMs"),
3577 IPW2100_ORD(OUR_FREQ, "current radio freq lower digits - channel ID"),
3578 IPW2100_ORD(RTC_TIME, "current RTC time"),
3579 IPW2100_ORD(PORT_TYPE, "operating mode"),
3580 IPW2100_ORD(CURRENT_TX_RATE, "current tx rate"),
3581 IPW2100_ORD(SUPPORTED_RATES, "supported tx rates"),
3582 IPW2100_ORD(ATIM_WINDOW, "current ATIM Window"),
3583 IPW2100_ORD(BASIC_RATES, "basic tx rates"),
3584 IPW2100_ORD(NIC_HIGHEST_RATE, "NIC highest tx rate"),
3585 IPW2100_ORD(AP_HIGHEST_RATE, "AP highest tx rate"),
3586 IPW2100_ORD(CAPABILITIES, "Management frame capability field"),
3587 IPW2100_ORD(AUTH_TYPE, "Type of authentication"),
3588 IPW2100_ORD(RADIO_TYPE, "Adapter card platform type"),
3589 IPW2100_ORD(RTS_THRESHOLD, "Min packet length for RTS handshaking"),
3590 IPW2100_ORD(INT_MODE, "International mode"),
3591 IPW2100_ORD(FRAGMENTATION_THRESHOLD, "protocol frag threshold"),
3592 IPW2100_ORD(EEPROM_SRAM_DB_BLOCK_START_ADDRESS, "EEPROM offset in SRAM"),
3593 IPW2100_ORD(EEPROM_SRAM_DB_BLOCK_SIZE, "EEPROM size in SRAM"),
3594 IPW2100_ORD(EEPROM_SKU_CAPABILITY, "EEPROM SKU Capability"),
3595 IPW2100_ORD(EEPROM_IBSS_11B_CHANNELS, "EEPROM IBSS 11b channel set"),
3596 IPW2100_ORD(MAC_VERSION, "MAC Version"),
3597 IPW2100_ORD(MAC_REVISION, "MAC Revision"),
3598 IPW2100_ORD(RADIO_VERSION, "Radio Version"),
3599 IPW2100_ORD(NIC_MANF_DATE_TIME, "MANF Date/Time STAMP"),
3600 IPW2100_ORD(UCODE_VERSION, "Ucode Version"),
3604 static ssize_t show_registers(struct device *d, char *buf)
3607 struct ipw2100_priv *priv = dev_get_drvdata(d);
3608 struct net_device *dev = priv->net_dev;
3612 out += sprintf(out, "%30s [Address ] : Hex\n", "Register");
3614 for (i = 0; i < (sizeof(hw_data) / sizeof(*hw_data)); i++) {
3615 read_register(dev, hw_data[i].addr, &val);
3616 out += sprintf(out, "%30s [%08X] : %08X\n",
3617 hw_data[i].name, hw_data[i].addr, val);
3622 static DEVICE_ATTR(registers, S_IRUGO, show_registers, NULL);
3625 static ssize_t show_hardware(struct device *d, char *buf)
3627 struct ipw2100_priv *priv = dev_get_drvdata(d);
3628 struct net_device *dev = priv->net_dev;
3632 out += sprintf(out, "%30s [Address ] : Hex\n", "NIC entry");
3634 for (i = 0; i < (sizeof(nic_data) / sizeof(*nic_data)); i++) {
3639 switch (nic_data[i].size) {
3641 read_nic_byte(dev, nic_data[i].addr, &tmp8);
3642 out += sprintf(out, "%30s [%08X] : %02X\n",
3643 nic_data[i].name, nic_data[i].addr,
3647 read_nic_word(dev, nic_data[i].addr, &tmp16);
3648 out += sprintf(out, "%30s [%08X] : %04X\n",
3649 nic_data[i].name, nic_data[i].addr,
3653 read_nic_dword(dev, nic_data[i].addr, &tmp32);
3654 out += sprintf(out, "%30s [%08X] : %08X\n",
3655 nic_data[i].name, nic_data[i].addr,
3662 static DEVICE_ATTR(hardware, S_IRUGO, show_hardware, NULL);
3665 static ssize_t show_memory(struct device *d, char *buf)
3667 struct ipw2100_priv *priv = dev_get_drvdata(d);
3668 struct net_device *dev = priv->net_dev;
3669 static unsigned long loop = 0;
3675 if (loop >= 0x30000)
3678 /* sysfs provides us PAGE_SIZE buffer */
3679 while (len < PAGE_SIZE - 128 && loop < 0x30000) {
3681 if (priv->snapshot[0]) for (i = 0; i < 4; i++)
3682 buffer[i] = *(u32 *)SNAPSHOT_ADDR(loop + i * 4);
3683 else for (i = 0; i < 4; i++)
3684 read_nic_dword(dev, loop + i * 4, &buffer[i]);
3687 len += sprintf(buf + len,
3707 ((u8*)buffer)[0xf]);
3709 len += sprintf(buf + len, "%s\n",
3710 snprint_line(line, sizeof(line),
3711 (u8*)buffer, 16, loop));
3718 static ssize_t store_memory(struct device *d, const char *buf, size_t count)
3720 struct ipw2100_priv *priv = dev_get_drvdata(d);
3721 struct net_device *dev = priv->net_dev;
3722 const char *p = buf;
3728 (count >= 2 && tolower(p[0]) == 'o' && tolower(p[1]) == 'n')) {
3729 IPW_DEBUG_INFO("%s: Setting memory dump to RAW mode.\n",
3733 } else if (p[0] == '0' || (count >= 2 && tolower(p[0]) == 'o' &&
3734 tolower(p[1]) == 'f')) {
3735 IPW_DEBUG_INFO("%s: Setting memory dump to HEX mode.\n",
3739 } else if (tolower(p[0]) == 'r') {
3740 IPW_DEBUG_INFO("%s: Resetting firmware snapshot.\n",
3742 ipw2100_snapshot_free(priv);
3745 IPW_DEBUG_INFO("%s: Usage: 0|on = HEX, 1|off = RAW, "
3746 "reset = clear memory snapshot\n",
3751 static DEVICE_ATTR(memory, S_IWUSR|S_IRUGO, show_memory, store_memory);
3754 static ssize_t show_ordinals(struct device *d, char *buf)
3756 struct ipw2100_priv *priv = dev_get_drvdata(d);
3760 static int loop = 0;
3762 if (loop >= sizeof(ord_data) / sizeof(*ord_data))
3765 /* sysfs provides us PAGE_SIZE buffer */
3766 while (len < PAGE_SIZE - 128 &&
3767 loop < (sizeof(ord_data) / sizeof(*ord_data))) {
3769 val_len = sizeof(u32);
3771 if (ipw2100_get_ordinal(priv, ord_data[loop].index, &val,
3773 len += sprintf(buf + len, "[0x%02X] = ERROR %s\n",
3774 ord_data[loop].index,
3775 ord_data[loop].desc);
3777 len += sprintf(buf + len, "[0x%02X] = 0x%08X %s\n",
3778 ord_data[loop].index, val,
3779 ord_data[loop].desc);
3785 static DEVICE_ATTR(ordinals, S_IRUGO, show_ordinals, NULL);
3788 static ssize_t show_stats(struct device *d, char *buf)
3790 struct ipw2100_priv *priv = dev_get_drvdata(d);
3793 out += sprintf(out, "interrupts: %d {tx: %d, rx: %d, other: %d}\n",
3794 priv->interrupts, priv->tx_interrupts,
3795 priv->rx_interrupts, priv->inta_other);
3796 out += sprintf(out, "firmware resets: %d\n", priv->resets);
3797 out += sprintf(out, "firmware hangs: %d\n", priv->hangs);
3798 #ifdef CONFIG_IPW_DEBUG
3799 out += sprintf(out, "packet mismatch image: %s\n",
3800 priv->snapshot[0] ? "YES" : "NO");
3805 static DEVICE_ATTR(stats, S_IRUGO, show_stats, NULL);
3808 int ipw2100_switch_mode(struct ipw2100_priv *priv, u32 mode)
3812 if (mode == priv->ieee->iw_mode)
3815 err = ipw2100_disable_adapter(priv);
3817 IPW_DEBUG_ERROR("%s: Could not disable adapter %d\n",
3818 priv->net_dev->name, err);
3824 priv->net_dev->type = ARPHRD_ETHER;
3827 priv->net_dev->type = ARPHRD_ETHER;
3829 #ifdef CONFIG_IPW2100_MONITOR
3830 case IW_MODE_MONITOR:
3831 priv->last_mode = priv->ieee->iw_mode;
3832 priv->net_dev->type = ARPHRD_IEEE80211;
3834 #endif /* CONFIG_IPW2100_MONITOR */
3837 priv->ieee->iw_mode = mode;
3840 /* Indicate ipw2100_download_firmware download firmware
3841 * from disk instead of memory. */
3842 ipw2100_firmware.version = 0;
3845 printk(KERN_INFO "%s: Reseting on mode change.\n",
3846 priv->net_dev->name);
3847 priv->reset_backoff = 0;
3848 schedule_reset(priv);
3853 static ssize_t show_internals(struct device *d, char *buf)
3855 struct ipw2100_priv *priv = dev_get_drvdata(d);
3858 #define DUMP_VAR(x,y) len += sprintf(buf + len, # x ": %" # y "\n", priv-> x)
3860 if (priv->status & STATUS_ASSOCIATED)
3861 len += sprintf(buf + len, "connected: %lu\n",
3862 get_seconds() - priv->connect_start);
3864 len += sprintf(buf + len, "not connected\n");
3866 DUMP_VAR(ieee->crypt[priv->ieee->tx_keyidx], p);
3867 DUMP_VAR(status, 08lx);
3868 DUMP_VAR(config, 08lx);
3869 DUMP_VAR(capability, 08lx);
3871 len += sprintf(buf + len, "last_rtc: %lu\n", (unsigned long)priv->last_rtc);
3873 DUMP_VAR(fatal_error, d);
3874 DUMP_VAR(stop_hang_check, d);
3875 DUMP_VAR(stop_rf_kill, d);
3876 DUMP_VAR(messages_sent, d);
3878 DUMP_VAR(tx_pend_stat.value, d);
3879 DUMP_VAR(tx_pend_stat.hi, d);
3881 DUMP_VAR(tx_free_stat.value, d);
3882 DUMP_VAR(tx_free_stat.lo, d);
3884 DUMP_VAR(msg_free_stat.value, d);
3885 DUMP_VAR(msg_free_stat.lo, d);
3887 DUMP_VAR(msg_pend_stat.value, d);
3888 DUMP_VAR(msg_pend_stat.hi, d);
3890 DUMP_VAR(fw_pend_stat.value, d);
3891 DUMP_VAR(fw_pend_stat.hi, d);
3893 DUMP_VAR(txq_stat.value, d);
3894 DUMP_VAR(txq_stat.lo, d);
3896 DUMP_VAR(ieee->scans, d);
3897 DUMP_VAR(reset_backoff, d);
3901 static DEVICE_ATTR(internals, S_IRUGO, show_internals, NULL);
3904 static ssize_t show_bssinfo(struct device *d, char *buf)
3906 struct ipw2100_priv *priv = dev_get_drvdata(d);
3907 char essid[IW_ESSID_MAX_SIZE + 1];
3914 memset(essid, 0, sizeof(essid));
3915 memset(bssid, 0, sizeof(bssid));
3917 length = IW_ESSID_MAX_SIZE;
3918 ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_SSID, essid, &length);
3920 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
3923 length = sizeof(bssid);
3924 ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID,
3927 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
3930 length = sizeof(u32);
3931 ret = ipw2100_get_ordinal(priv, IPW_ORD_OUR_FREQ, &chan, &length);
3933 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
3936 out += sprintf(out, "ESSID: %s\n", essid);
3937 out += sprintf(out, "BSSID: %02x:%02x:%02x:%02x:%02x:%02x\n",
3938 bssid[0], bssid[1], bssid[2],
3939 bssid[3], bssid[4], bssid[5]);
3940 out += sprintf(out, "Channel: %d\n", chan);
3944 static DEVICE_ATTR(bssinfo, S_IRUGO, show_bssinfo, NULL);
3949 #ifdef CONFIG_IPW_DEBUG
3950 static ssize_t show_debug_level(struct device_driver *d, char *buf)
3952 return sprintf(buf, "0x%08X\n", ipw2100_debug_level);
3955 static ssize_t store_debug_level(struct device_driver *d, const char *buf,
3958 char *p = (char *)buf;
3961 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
3963 if (p[0] == 'x' || p[0] == 'X')
3965 val = simple_strtoul(p, &p, 16);
3967 val = simple_strtoul(p, &p, 10);
3969 IPW_DEBUG_INFO(DRV_NAME
3970 ": %s is not in hex or decimal form.\n", buf);
3972 ipw2100_debug_level = val;
3974 return strnlen(buf, count);
3976 static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, show_debug_level,
3978 #endif /* CONFIG_IPW_DEBUG */
3981 static ssize_t show_fatal_error(struct device *d, char *buf)
3983 struct ipw2100_priv *priv = dev_get_drvdata(d);
3987 if (priv->fatal_error)
3988 out += sprintf(out, "0x%08X\n",
3991 out += sprintf(out, "0\n");
3993 for (i = 1; i <= IPW2100_ERROR_QUEUE; i++) {
3994 if (!priv->fatal_errors[(priv->fatal_index - i) %
3995 IPW2100_ERROR_QUEUE])
3998 out += sprintf(out, "%d. 0x%08X\n", i,
3999 priv->fatal_errors[(priv->fatal_index - i) %
4000 IPW2100_ERROR_QUEUE]);
4006 static ssize_t store_fatal_error(struct device *d, const char *buf,
4009 struct ipw2100_priv *priv = dev_get_drvdata(d);
4010 schedule_reset(priv);
4013 static DEVICE_ATTR(fatal_error, S_IWUSR|S_IRUGO, show_fatal_error, store_fatal_error);
4016 static ssize_t show_scan_age(struct device *d, char *buf)
4018 struct ipw2100_priv *priv = dev_get_drvdata(d);
4019 return sprintf(buf, "%d\n", priv->ieee->scan_age);
4022 static ssize_t store_scan_age(struct device *d, const char *buf, size_t count)
4024 struct ipw2100_priv *priv = dev_get_drvdata(d);
4025 struct net_device *dev = priv->net_dev;
4026 char buffer[] = "00000000";
4028 (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
4032 IPW_DEBUG_INFO("enter\n");
4034 strncpy(buffer, buf, len);
4037 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
4039 if (p[0] == 'x' || p[0] == 'X')
4041 val = simple_strtoul(p, &p, 16);
4043 val = simple_strtoul(p, &p, 10);
4045 IPW_DEBUG_INFO("%s: user supplied invalid value.\n",
4048 priv->ieee->scan_age = val;
4049 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
4052 IPW_DEBUG_INFO("exit\n");
4055 static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
4058 static ssize_t show_rf_kill(struct device *d, char *buf)
4060 /* 0 - RF kill not enabled
4061 1 - SW based RF kill active (sysfs)
4062 2 - HW based RF kill active
4063 3 - Both HW and SW baed RF kill active */
4064 struct ipw2100_priv *priv = (struct ipw2100_priv *)d->driver_data;
4065 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
4066 (rf_kill_active(priv) ? 0x2 : 0x0);
4067 return sprintf(buf, "%i\n", val);
4070 static int ipw_radio_kill_sw(struct ipw2100_priv *priv, int disable_radio)
4072 if ((disable_radio ? 1 : 0) ==
4073 (priv->status & STATUS_RF_KILL_SW ? 1 : 0))
4076 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
4077 disable_radio ? "OFF" : "ON");
4079 down(&priv->action_sem);
4081 if (disable_radio) {
4082 priv->status |= STATUS_RF_KILL_SW;
4085 priv->status &= ~STATUS_RF_KILL_SW;
4086 if (rf_kill_active(priv)) {
4087 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
4088 "disabled by HW switch\n");
4089 /* Make sure the RF_KILL check timer is running */
4090 priv->stop_rf_kill = 0;
4091 cancel_delayed_work(&priv->rf_kill);
4092 queue_delayed_work(priv->workqueue, &priv->rf_kill,
4095 schedule_reset(priv);
4098 up(&priv->action_sem);
4102 static ssize_t store_rf_kill(struct device *d, const char *buf, size_t count)
4104 struct ipw2100_priv *priv = dev_get_drvdata(d);
4105 ipw_radio_kill_sw(priv, buf[0] == '1');
4108 static DEVICE_ATTR(rf_kill, S_IWUSR|S_IRUGO, show_rf_kill, store_rf_kill);
4111 static struct attribute *ipw2100_sysfs_entries[] = {
4112 &dev_attr_hardware.attr,
4113 &dev_attr_registers.attr,
4114 &dev_attr_ordinals.attr,
4116 &dev_attr_stats.attr,
4117 &dev_attr_internals.attr,
4118 &dev_attr_bssinfo.attr,
4119 &dev_attr_memory.attr,
4120 &dev_attr_scan_age.attr,
4121 &dev_attr_fatal_error.attr,
4122 &dev_attr_rf_kill.attr,
4124 &dev_attr_status.attr,
4125 &dev_attr_capability.attr,
4129 static struct attribute_group ipw2100_attribute_group = {
4130 .attrs = ipw2100_sysfs_entries,
4134 static int status_queue_allocate(struct ipw2100_priv *priv, int entries)
4136 struct ipw2100_status_queue *q = &priv->status_queue;
4138 IPW_DEBUG_INFO("enter\n");
4140 q->size = entries * sizeof(struct ipw2100_status);
4141 q->drv = (struct ipw2100_status *)pci_alloc_consistent(
4142 priv->pci_dev, q->size, &q->nic);
4145 "Can not allocate status queue.\n");
4149 memset(q->drv, 0, q->size);
4151 IPW_DEBUG_INFO("exit\n");
4156 static void status_queue_free(struct ipw2100_priv *priv)
4158 IPW_DEBUG_INFO("enter\n");
4160 if (priv->status_queue.drv) {
4161 pci_free_consistent(
4162 priv->pci_dev, priv->status_queue.size,
4163 priv->status_queue.drv, priv->status_queue.nic);
4164 priv->status_queue.drv = NULL;
4167 IPW_DEBUG_INFO("exit\n");
4170 static int bd_queue_allocate(struct ipw2100_priv *priv,
4171 struct ipw2100_bd_queue *q, int entries)
4173 IPW_DEBUG_INFO("enter\n");
4175 memset(q, 0, sizeof(struct ipw2100_bd_queue));
4177 q->entries = entries;
4178 q->size = entries * sizeof(struct ipw2100_bd);
4179 q->drv = pci_alloc_consistent(priv->pci_dev, q->size, &q->nic);
4181 IPW_DEBUG_INFO("can't allocate shared memory for buffer descriptors\n");
4184 memset(q->drv, 0, q->size);
4186 IPW_DEBUG_INFO("exit\n");
4191 static void bd_queue_free(struct ipw2100_priv *priv,
4192 struct ipw2100_bd_queue *q)
4194 IPW_DEBUG_INFO("enter\n");
4200 pci_free_consistent(priv->pci_dev,
4201 q->size, q->drv, q->nic);
4205 IPW_DEBUG_INFO("exit\n");
4208 static void bd_queue_initialize(
4209 struct ipw2100_priv *priv, struct ipw2100_bd_queue * q,
4210 u32 base, u32 size, u32 r, u32 w)
4212 IPW_DEBUG_INFO("enter\n");
4214 IPW_DEBUG_INFO("initializing bd queue at virt=%p, phys=%08x\n", q->drv, (u32)q->nic);
4216 write_register(priv->net_dev, base, q->nic);
4217 write_register(priv->net_dev, size, q->entries);
4218 write_register(priv->net_dev, r, q->oldest);
4219 write_register(priv->net_dev, w, q->next);
4221 IPW_DEBUG_INFO("exit\n");
4224 static void ipw2100_kill_workqueue(struct ipw2100_priv *priv)
4226 if (priv->workqueue) {
4227 priv->stop_rf_kill = 1;
4228 priv->stop_hang_check = 1;
4229 cancel_delayed_work(&priv->reset_work);
4230 cancel_delayed_work(&priv->security_work);
4231 cancel_delayed_work(&priv->wx_event_work);
4232 cancel_delayed_work(&priv->hang_check);
4233 cancel_delayed_work(&priv->rf_kill);
4234 destroy_workqueue(priv->workqueue);
4235 priv->workqueue = NULL;
4239 static int ipw2100_tx_allocate(struct ipw2100_priv *priv)
4241 int i, j, err = -EINVAL;
4245 IPW_DEBUG_INFO("enter\n");
4247 err = bd_queue_allocate(priv, &priv->tx_queue, TX_QUEUE_LENGTH);
4249 IPW_DEBUG_ERROR("%s: failed bd_queue_allocate\n",
4250 priv->net_dev->name);
4254 priv->tx_buffers = (struct ipw2100_tx_packet *)kmalloc(
4255 TX_PENDED_QUEUE_LENGTH * sizeof(struct ipw2100_tx_packet),
4257 if (!priv->tx_buffers) {
4258 IPW_DEBUG_ERROR("%s: alloc failed form tx buffers.\n",
4259 priv->net_dev->name);
4260 bd_queue_free(priv, &priv->tx_queue);
4264 for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
4265 v = pci_alloc_consistent(
4266 priv->pci_dev, sizeof(struct ipw2100_data_header), &p);
4268 IPW_DEBUG_ERROR("%s: PCI alloc failed for tx "
4269 "buffers.\n", priv->net_dev->name);
4274 priv->tx_buffers[i].type = DATA;
4275 priv->tx_buffers[i].info.d_struct.data = (struct ipw2100_data_header*)v;
4276 priv->tx_buffers[i].info.d_struct.data_phys = p;
4277 priv->tx_buffers[i].info.d_struct.txb = NULL;
4280 if (i == TX_PENDED_QUEUE_LENGTH)
4283 for (j = 0; j < i; j++) {
4284 pci_free_consistent(
4286 sizeof(struct ipw2100_data_header),
4287 priv->tx_buffers[j].info.d_struct.data,
4288 priv->tx_buffers[j].info.d_struct.data_phys);
4291 kfree(priv->tx_buffers);
4292 priv->tx_buffers = NULL;
4297 static void ipw2100_tx_initialize(struct ipw2100_priv *priv)
4301 IPW_DEBUG_INFO("enter\n");
4304 * reinitialize packet info lists
4306 INIT_LIST_HEAD(&priv->fw_pend_list);
4307 INIT_STAT(&priv->fw_pend_stat);
4310 * reinitialize lists
4312 INIT_LIST_HEAD(&priv->tx_pend_list);
4313 INIT_LIST_HEAD(&priv->tx_free_list);
4314 INIT_STAT(&priv->tx_pend_stat);
4315 INIT_STAT(&priv->tx_free_stat);
4317 for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
4318 /* We simply drop any SKBs that have been queued for
4320 if (priv->tx_buffers[i].info.d_struct.txb) {
4321 ieee80211_txb_free(priv->tx_buffers[i].info.d_struct.txb);
4322 priv->tx_buffers[i].info.d_struct.txb = NULL;
4325 list_add_tail(&priv->tx_buffers[i].list, &priv->tx_free_list);
4328 SET_STAT(&priv->tx_free_stat, i);
4330 priv->tx_queue.oldest = 0;
4331 priv->tx_queue.available = priv->tx_queue.entries;
4332 priv->tx_queue.next = 0;
4333 INIT_STAT(&priv->txq_stat);
4334 SET_STAT(&priv->txq_stat, priv->tx_queue.available);
4336 bd_queue_initialize(priv, &priv->tx_queue,
4337 IPW_MEM_HOST_SHARED_TX_QUEUE_BD_BASE,
4338 IPW_MEM_HOST_SHARED_TX_QUEUE_BD_SIZE,
4339 IPW_MEM_HOST_SHARED_TX_QUEUE_READ_INDEX,
4340 IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX);
4342 IPW_DEBUG_INFO("exit\n");
4346 static void ipw2100_tx_free(struct ipw2100_priv *priv)
4350 IPW_DEBUG_INFO("enter\n");
4352 bd_queue_free(priv, &priv->tx_queue);
4354 if (!priv->tx_buffers)
4357 for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
4358 if (priv->tx_buffers[i].info.d_struct.txb) {
4359 ieee80211_txb_free(priv->tx_buffers[i].info.d_struct.txb);
4360 priv->tx_buffers[i].info.d_struct.txb = NULL;
4362 if (priv->tx_buffers[i].info.d_struct.data)
4363 pci_free_consistent(
4365 sizeof(struct ipw2100_data_header),
4366 priv->tx_buffers[i].info.d_struct.data,
4367 priv->tx_buffers[i].info.d_struct.data_phys);
4370 kfree(priv->tx_buffers);
4371 priv->tx_buffers = NULL;
4373 IPW_DEBUG_INFO("exit\n");
4378 static int ipw2100_rx_allocate(struct ipw2100_priv *priv)
4380 int i, j, err = -EINVAL;
4382 IPW_DEBUG_INFO("enter\n");
4384 err = bd_queue_allocate(priv, &priv->rx_queue, RX_QUEUE_LENGTH);
4386 IPW_DEBUG_INFO("failed bd_queue_allocate\n");
4390 err = status_queue_allocate(priv, RX_QUEUE_LENGTH);
4392 IPW_DEBUG_INFO("failed status_queue_allocate\n");
4393 bd_queue_free(priv, &priv->rx_queue);
4400 priv->rx_buffers = (struct ipw2100_rx_packet *)
4401 kmalloc(RX_QUEUE_LENGTH * sizeof(struct ipw2100_rx_packet),
4403 if (!priv->rx_buffers) {
4404 IPW_DEBUG_INFO("can't allocate rx packet buffer table\n");
4406 bd_queue_free(priv, &priv->rx_queue);
4408 status_queue_free(priv);
4413 for (i = 0; i < RX_QUEUE_LENGTH; i++) {
4414 struct ipw2100_rx_packet *packet = &priv->rx_buffers[i];
4416 err = ipw2100_alloc_skb(priv, packet);
4417 if (unlikely(err)) {
4422 /* The BD holds the cache aligned address */
4423 priv->rx_queue.drv[i].host_addr = packet->dma_addr;
4424 priv->rx_queue.drv[i].buf_length = IPW_RX_NIC_BUFFER_LENGTH;
4425 priv->status_queue.drv[i].status_fields = 0;
4428 if (i == RX_QUEUE_LENGTH)
4431 for (j = 0; j < i; j++) {
4432 pci_unmap_single(priv->pci_dev, priv->rx_buffers[j].dma_addr,
4433 sizeof(struct ipw2100_rx_packet),
4434 PCI_DMA_FROMDEVICE);
4435 dev_kfree_skb(priv->rx_buffers[j].skb);
4438 kfree(priv->rx_buffers);
4439 priv->rx_buffers = NULL;
4441 bd_queue_free(priv, &priv->rx_queue);
4443 status_queue_free(priv);
4448 static void ipw2100_rx_initialize(struct ipw2100_priv *priv)
4450 IPW_DEBUG_INFO("enter\n");
4452 priv->rx_queue.oldest = 0;
4453 priv->rx_queue.available = priv->rx_queue.entries - 1;
4454 priv->rx_queue.next = priv->rx_queue.entries - 1;
4456 INIT_STAT(&priv->rxq_stat);
4457 SET_STAT(&priv->rxq_stat, priv->rx_queue.available);
4459 bd_queue_initialize(priv, &priv->rx_queue,
4460 IPW_MEM_HOST_SHARED_RX_BD_BASE,
4461 IPW_MEM_HOST_SHARED_RX_BD_SIZE,
4462 IPW_MEM_HOST_SHARED_RX_READ_INDEX,
4463 IPW_MEM_HOST_SHARED_RX_WRITE_INDEX);
4465 /* set up the status queue */
4466 write_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_STATUS_BASE,
4467 priv->status_queue.nic);
4469 IPW_DEBUG_INFO("exit\n");
4472 static void ipw2100_rx_free(struct ipw2100_priv *priv)
4476 IPW_DEBUG_INFO("enter\n");
4478 bd_queue_free(priv, &priv->rx_queue);
4479 status_queue_free(priv);
4481 if (!priv->rx_buffers)
4484 for (i = 0; i < RX_QUEUE_LENGTH; i++) {
4485 if (priv->rx_buffers[i].rxp) {
4486 pci_unmap_single(priv->pci_dev,
4487 priv->rx_buffers[i].dma_addr,
4488 sizeof(struct ipw2100_rx),
4489 PCI_DMA_FROMDEVICE);
4490 dev_kfree_skb(priv->rx_buffers[i].skb);
4494 kfree(priv->rx_buffers);
4495 priv->rx_buffers = NULL;
4497 IPW_DEBUG_INFO("exit\n");
4500 static int ipw2100_read_mac_address(struct ipw2100_priv *priv)
4502 u32 length = ETH_ALEN;
4507 err = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ADAPTER_MAC,
4510 IPW_DEBUG_INFO("MAC address read failed\n");
4513 IPW_DEBUG_INFO("card MAC is %02X:%02X:%02X:%02X:%02X:%02X\n",
4514 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
4516 memcpy(priv->net_dev->dev_addr, mac, ETH_ALEN);
4521 /********************************************************************
4525 ********************************************************************/
4527 int ipw2100_set_mac_address(struct ipw2100_priv *priv, int batch_mode)
4529 struct host_command cmd = {
4530 .host_command = ADAPTER_ADDRESS,
4531 .host_command_sequence = 0,
4532 .host_command_length = ETH_ALEN
4536 IPW_DEBUG_HC("SET_MAC_ADDRESS\n");
4538 IPW_DEBUG_INFO("enter\n");
4540 if (priv->config & CFG_CUSTOM_MAC) {
4541 memcpy(cmd.host_command_parameters, priv->mac_addr,
4543 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
4545 memcpy(cmd.host_command_parameters, priv->net_dev->dev_addr,
4548 err = ipw2100_hw_send_command(priv, &cmd);
4550 IPW_DEBUG_INFO("exit\n");
4554 int ipw2100_set_port_type(struct ipw2100_priv *priv, u32 port_type,
4557 struct host_command cmd = {
4558 .host_command = PORT_TYPE,
4559 .host_command_sequence = 0,
4560 .host_command_length = sizeof(u32)
4564 switch (port_type) {
4566 cmd.host_command_parameters[0] = IPW_BSS;
4569 cmd.host_command_parameters[0] = IPW_IBSS;
4573 IPW_DEBUG_HC("PORT_TYPE: %s\n",
4574 port_type == IPW_IBSS ? "Ad-Hoc" : "Managed");
4577 err = ipw2100_disable_adapter(priv);
4579 IPW_DEBUG_ERROR("%s: Could not disable adapter %d\n",
4580 priv->net_dev->name, err);
4585 /* send cmd to firmware */
4586 err = ipw2100_hw_send_command(priv, &cmd);
4589 ipw2100_enable_adapter(priv);
4595 int ipw2100_set_channel(struct ipw2100_priv *priv, u32 channel, int batch_mode)
4597 struct host_command cmd = {
4598 .host_command = CHANNEL,
4599 .host_command_sequence = 0,
4600 .host_command_length = sizeof(u32)
4604 cmd.host_command_parameters[0] = channel;
4606 IPW_DEBUG_HC("CHANNEL: %d\n", channel);
4608 /* If BSS then we don't support channel selection */
4609 if (priv->ieee->iw_mode == IW_MODE_INFRA)
4612 if ((channel != 0) &&
4613 ((channel < REG_MIN_CHANNEL) || (channel > REG_MAX_CHANNEL)))
4617 err = ipw2100_disable_adapter(priv);
4622 err = ipw2100_hw_send_command(priv, &cmd);
4624 IPW_DEBUG_INFO("Failed to set channel to %d",
4630 priv->config |= CFG_STATIC_CHANNEL;
4632 priv->config &= ~CFG_STATIC_CHANNEL;
4634 priv->channel = channel;
4637 err = ipw2100_enable_adapter(priv);
4645 int ipw2100_system_config(struct ipw2100_priv *priv, int batch_mode)
4647 struct host_command cmd = {
4648 .host_command = SYSTEM_CONFIG,
4649 .host_command_sequence = 0,
4650 .host_command_length = 12,
4652 u32 ibss_mask, len = sizeof(u32);
4655 /* Set system configuration */
4658 err = ipw2100_disable_adapter(priv);
4663 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
4664 cmd.host_command_parameters[0] |= IPW_CFG_IBSS_AUTO_START;
4666 cmd.host_command_parameters[0] |= IPW_CFG_IBSS_MASK |
4668 IPW_CFG_802_1x_ENABLE;
4670 if (!(priv->config & CFG_LONG_PREAMBLE))
4671 cmd.host_command_parameters[0] |= IPW_CFG_PREAMBLE_AUTO;
4673 err = ipw2100_get_ordinal(priv,
4674 IPW_ORD_EEPROM_IBSS_11B_CHANNELS,
4677 ibss_mask = IPW_IBSS_11B_DEFAULT_MASK;
4679 cmd.host_command_parameters[1] = REG_CHANNEL_MASK;
4680 cmd.host_command_parameters[2] = REG_CHANNEL_MASK & ibss_mask;
4683 /*cmd.host_command_parameters[0] |= DIVERSITY_ANTENNA_A;*/
4685 err = ipw2100_hw_send_command(priv, &cmd);
4689 /* If IPv6 is configured in the kernel then we don't want to filter out all
4690 * of the multicast packets as IPv6 needs some. */
4691 #if !defined(CONFIG_IPV6) && !defined(CONFIG_IPV6_MODULE)
4692 cmd.host_command = ADD_MULTICAST;
4693 cmd.host_command_sequence = 0;
4694 cmd.host_command_length = 0;
4696 ipw2100_hw_send_command(priv, &cmd);
4699 err = ipw2100_enable_adapter(priv);
4707 int ipw2100_set_tx_rates(struct ipw2100_priv *priv, u32 rate, int batch_mode)
4709 struct host_command cmd = {
4710 .host_command = BASIC_TX_RATES,
4711 .host_command_sequence = 0,
4712 .host_command_length = 4
4716 cmd.host_command_parameters[0] = rate & TX_RATE_MASK;
4719 err = ipw2100_disable_adapter(priv);
4724 /* Set BASIC TX Rate first */
4725 ipw2100_hw_send_command(priv, &cmd);
4728 cmd.host_command = TX_RATES;
4729 ipw2100_hw_send_command(priv, &cmd);
4731 /* Set MSDU TX Rate */
4732 cmd.host_command = MSDU_TX_RATES;
4733 ipw2100_hw_send_command(priv, &cmd);
4736 err = ipw2100_enable_adapter(priv);
4741 priv->tx_rates = rate;
4746 int ipw2100_set_power_mode(struct ipw2100_priv *priv,
4749 struct host_command cmd = {
4750 .host_command = POWER_MODE,
4751 .host_command_sequence = 0,
4752 .host_command_length = 4
4756 cmd.host_command_parameters[0] = power_level;
4758 err = ipw2100_hw_send_command(priv, &cmd);
4762 if (power_level == IPW_POWER_MODE_CAM)
4763 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
4765 priv->power_mode = IPW_POWER_ENABLED | power_level;
4767 #ifdef CONFIG_IPW2100_TX_POWER
4768 if (priv->port_type == IBSS &&
4769 priv->adhoc_power != DFTL_IBSS_TX_POWER) {
4770 /* Set beacon interval */
4771 cmd.host_command = TX_POWER_INDEX;
4772 cmd.host_command_parameters[0] = (u32)priv->adhoc_power;
4774 err = ipw2100_hw_send_command(priv, &cmd);
4784 int ipw2100_set_rts_threshold(struct ipw2100_priv *priv, u32 threshold)
4786 struct host_command cmd = {
4787 .host_command = RTS_THRESHOLD,
4788 .host_command_sequence = 0,
4789 .host_command_length = 4
4793 if (threshold & RTS_DISABLED)
4794 cmd.host_command_parameters[0] = MAX_RTS_THRESHOLD;
4796 cmd.host_command_parameters[0] = threshold & ~RTS_DISABLED;
4798 err = ipw2100_hw_send_command(priv, &cmd);
4802 priv->rts_threshold = threshold;
4808 int ipw2100_set_fragmentation_threshold(struct ipw2100_priv *priv,
4809 u32 threshold, int batch_mode)
4811 struct host_command cmd = {
4812 .host_command = FRAG_THRESHOLD,
4813 .host_command_sequence = 0,
4814 .host_command_length = 4,
4815 .host_command_parameters[0] = 0,
4820 err = ipw2100_disable_adapter(priv);
4826 threshold = DEFAULT_FRAG_THRESHOLD;
4828 threshold = max(threshold, MIN_FRAG_THRESHOLD);
4829 threshold = min(threshold, MAX_FRAG_THRESHOLD);
4832 cmd.host_command_parameters[0] = threshold;
4834 IPW_DEBUG_HC("FRAG_THRESHOLD: %u\n", threshold);
4836 err = ipw2100_hw_send_command(priv, &cmd);
4839 ipw2100_enable_adapter(priv);
4842 priv->frag_threshold = threshold;
4848 int ipw2100_set_short_retry(struct ipw2100_priv *priv, u32 retry)
4850 struct host_command cmd = {
4851 .host_command = SHORT_RETRY_LIMIT,
4852 .host_command_sequence = 0,
4853 .host_command_length = 4
4857 cmd.host_command_parameters[0] = retry;
4859 err = ipw2100_hw_send_command(priv, &cmd);
4863 priv->short_retry_limit = retry;
4868 int ipw2100_set_long_retry(struct ipw2100_priv *priv, u32 retry)
4870 struct host_command cmd = {
4871 .host_command = LONG_RETRY_LIMIT,
4872 .host_command_sequence = 0,
4873 .host_command_length = 4
4877 cmd.host_command_parameters[0] = retry;
4879 err = ipw2100_hw_send_command(priv, &cmd);
4883 priv->long_retry_limit = retry;
4889 int ipw2100_set_mandatory_bssid(struct ipw2100_priv *priv, u8 *bssid,
4892 struct host_command cmd = {
4893 .host_command = MANDATORY_BSSID,
4894 .host_command_sequence = 0,
4895 .host_command_length = (bssid == NULL) ? 0 : ETH_ALEN
4899 #ifdef CONFIG_IPW_DEBUG
4902 "MANDATORY_BSSID: %02X:%02X:%02X:%02X:%02X:%02X\n",
4903 bssid[0], bssid[1], bssid[2], bssid[3], bssid[4],
4906 IPW_DEBUG_HC("MANDATORY_BSSID: <clear>\n");
4908 /* if BSSID is empty then we disable mandatory bssid mode */
4910 memcpy((u8 *)cmd.host_command_parameters, bssid, ETH_ALEN);
4913 err = ipw2100_disable_adapter(priv);
4918 err = ipw2100_hw_send_command(priv, &cmd);
4921 ipw2100_enable_adapter(priv);
4926 #ifdef CONFIG_IEEE80211_WPA
4927 static int ipw2100_disassociate_bssid(struct ipw2100_priv *priv)
4929 struct host_command cmd = {
4930 .host_command = DISASSOCIATION_BSSID,
4931 .host_command_sequence = 0,
4932 .host_command_length = ETH_ALEN
4937 IPW_DEBUG_HC("DISASSOCIATION_BSSID\n");
4940 /* The Firmware currently ignores the BSSID and just disassociates from
4941 * the currently associated AP -- but in the off chance that a future
4942 * firmware does use the BSSID provided here, we go ahead and try and
4943 * set it to the currently associated AP's BSSID */
4944 memcpy(cmd.host_command_parameters, priv->bssid, ETH_ALEN);
4946 err = ipw2100_hw_send_command(priv, &cmd);
4953 * Pseudo code for setting up wpa_frame:
4956 void x(struct ieee80211_assoc_frame *wpa_assoc)
4958 struct ipw2100_wpa_assoc_frame frame;
4959 frame->fixed_ie_mask = IPW_WPA_CAPABILTIES |
4960 IPW_WPA_LISTENINTERVAL |
4962 frame->capab_info = wpa_assoc->capab_info;
4963 frame->lisen_interval = wpa_assoc->listent_interval;
4964 memcpy(frame->current_ap, wpa_assoc->current_ap, ETH_ALEN);
4966 /* UNKNOWN -- I'm not postivive about this part; don't have any WPA
4967 * setup here to test it with.
4969 * Walk the IEs in the wpa_assoc and figure out the total size of all
4970 * that data. Stick that into frame->var_ie_len. Then memcpy() all of
4971 * the IEs from wpa_frame into frame.
4973 frame->var_ie_len = calculate_ie_len(wpa_assoc);
4974 memcpy(frame->var_ie, wpa_assoc->variable, frame->var_ie_len);
4976 ipw2100_set_wpa_ie(priv, &frame, 0);
4983 static int ipw2100_set_wpa_ie(struct ipw2100_priv *,
4984 struct ipw2100_wpa_assoc_frame *, int)
4985 __attribute__ ((unused));
4987 static int ipw2100_set_wpa_ie(struct ipw2100_priv *priv,
4988 struct ipw2100_wpa_assoc_frame *wpa_frame,
4991 struct host_command cmd = {
4992 .host_command = SET_WPA_IE,
4993 .host_command_sequence = 0,
4994 .host_command_length = sizeof(struct ipw2100_wpa_assoc_frame),
4998 IPW_DEBUG_HC("SET_WPA_IE\n");
5001 err = ipw2100_disable_adapter(priv);
5006 memcpy(cmd.host_command_parameters, wpa_frame,
5007 sizeof(struct ipw2100_wpa_assoc_frame));
5009 err = ipw2100_hw_send_command(priv, &cmd);
5012 if (ipw2100_enable_adapter(priv))
5019 struct security_info_params {
5020 u32 allowed_ciphers;
5023 u8 replay_counters_number;
5024 u8 unicast_using_group;
5025 } __attribute__ ((packed));
5027 int ipw2100_set_security_information(struct ipw2100_priv *priv,
5030 int unicast_using_group,
5033 struct host_command cmd = {
5034 .host_command = SET_SECURITY_INFORMATION,
5035 .host_command_sequence = 0,
5036 .host_command_length = sizeof(struct security_info_params)
5038 struct security_info_params *security =
5039 (struct security_info_params *)&cmd.host_command_parameters;
5041 memset(security, 0, sizeof(*security));
5043 /* If shared key AP authentication is turned on, then we need to
5044 * configure the firmware to try and use it.
5046 * Actual data encryption/decryption is handled by the host. */
5047 security->auth_mode = auth_mode;
5048 security->unicast_using_group = unicast_using_group;
5050 switch (security_level) {
5053 security->allowed_ciphers = IPW_NONE_CIPHER;
5056 security->allowed_ciphers = IPW_WEP40_CIPHER |
5060 security->allowed_ciphers = IPW_WEP40_CIPHER |
5061 IPW_WEP104_CIPHER | IPW_TKIP_CIPHER;
5063 case SEC_LEVEL_2_CKIP:
5064 security->allowed_ciphers = IPW_WEP40_CIPHER |
5065 IPW_WEP104_CIPHER | IPW_CKIP_CIPHER;
5068 security->allowed_ciphers = IPW_WEP40_CIPHER |
5069 IPW_WEP104_CIPHER | IPW_TKIP_CIPHER | IPW_CCMP_CIPHER;
5074 "SET_SECURITY_INFORMATION: auth:%d cipher:0x%02X (level %d)\n",
5075 security->auth_mode, security->allowed_ciphers, security_level);
5077 security->replay_counters_number = 0;
5080 err = ipw2100_disable_adapter(priv);
5085 err = ipw2100_hw_send_command(priv, &cmd);
5088 ipw2100_enable_adapter(priv);
5093 int ipw2100_set_tx_power(struct ipw2100_priv *priv,
5096 struct host_command cmd = {
5097 .host_command = TX_POWER_INDEX,
5098 .host_command_sequence = 0,
5099 .host_command_length = 4
5103 cmd.host_command_parameters[0] = tx_power;
5105 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
5106 err = ipw2100_hw_send_command(priv, &cmd);
5108 priv->tx_power = tx_power;
5113 int ipw2100_set_ibss_beacon_interval(struct ipw2100_priv *priv,
5114 u32 interval, int batch_mode)
5116 struct host_command cmd = {
5117 .host_command = BEACON_INTERVAL,
5118 .host_command_sequence = 0,
5119 .host_command_length = 4
5123 cmd.host_command_parameters[0] = interval;
5125 IPW_DEBUG_INFO("enter\n");
5127 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
5129 err = ipw2100_disable_adapter(priv);
5134 ipw2100_hw_send_command(priv, &cmd);
5137 err = ipw2100_enable_adapter(priv);
5143 IPW_DEBUG_INFO("exit\n");
5149 void ipw2100_queues_initialize(struct ipw2100_priv *priv)
5151 ipw2100_tx_initialize(priv);
5152 ipw2100_rx_initialize(priv);
5153 ipw2100_msg_initialize(priv);
5156 void ipw2100_queues_free(struct ipw2100_priv *priv)
5158 ipw2100_tx_free(priv);
5159 ipw2100_rx_free(priv);
5160 ipw2100_msg_free(priv);
5163 int ipw2100_queues_allocate(struct ipw2100_priv *priv)
5165 if (ipw2100_tx_allocate(priv) ||
5166 ipw2100_rx_allocate(priv) ||
5167 ipw2100_msg_allocate(priv))
5173 ipw2100_tx_free(priv);
5174 ipw2100_rx_free(priv);
5175 ipw2100_msg_free(priv);
5179 #define IPW_PRIVACY_CAPABLE 0x0008
5181 static int ipw2100_set_wep_flags(struct ipw2100_priv *priv, u32 flags,
5184 struct host_command cmd = {
5185 .host_command = WEP_FLAGS,
5186 .host_command_sequence = 0,
5187 .host_command_length = 4
5191 cmd.host_command_parameters[0] = flags;
5193 IPW_DEBUG_HC("WEP_FLAGS: flags = 0x%08X\n", flags);
5196 err = ipw2100_disable_adapter(priv);
5198 IPW_DEBUG_ERROR("%s: Could not disable adapter %d\n",
5199 priv->net_dev->name, err);
5204 /* send cmd to firmware */
5205 err = ipw2100_hw_send_command(priv, &cmd);
5208 ipw2100_enable_adapter(priv);
5213 struct ipw2100_wep_key {
5219 /* Macros to ease up priting WEP keys */
5220 #define WEP_FMT_64 "%02X%02X%02X%02X-%02X"
5221 #define WEP_FMT_128 "%02X%02X%02X%02X-%02X%02X%02X%02X-%02X%02X%02X"
5222 #define WEP_STR_64(x) x[0],x[1],x[2],x[3],x[4]
5223 #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]
5229 * @priv: struct to work on
5230 * @idx: index of the key we want to set
5231 * @key: ptr to the key data to set
5232 * @len: length of the buffer at @key
5233 * @batch_mode: FIXME perform the operation in batch mode, not
5234 * disabling the device.
5236 * @returns 0 if OK, < 0 errno code on error.
5238 * Fill out a command structure with the new wep key, length an
5239 * index and send it down the wire.
5241 static int ipw2100_set_key(struct ipw2100_priv *priv,
5242 int idx, char *key, int len, int batch_mode)
5244 int keylen = len ? (len <= 5 ? 5 : 13) : 0;
5245 struct host_command cmd = {
5246 .host_command = WEP_KEY_INFO,
5247 .host_command_sequence = 0,
5248 .host_command_length = sizeof(struct ipw2100_wep_key),
5250 struct ipw2100_wep_key *wep_key = (void*)cmd.host_command_parameters;
5253 IPW_DEBUG_HC("WEP_KEY_INFO: index = %d, len = %d/%d\n",
5256 /* NOTE: We don't check cached values in case the firmware was reset
5257 * or some other problem is occuring. If the user is setting the key,
5258 * then we push the change */
5261 wep_key->len = keylen;
5264 memcpy(wep_key->key, key, len);
5265 memset(wep_key->key + len, 0, keylen - len);
5268 /* Will be optimized out on debug not being configured in */
5270 IPW_DEBUG_WEP("%s: Clearing key %d\n",
5271 priv->net_dev->name, wep_key->idx);
5272 else if (keylen == 5)
5273 IPW_DEBUG_WEP("%s: idx: %d, len: %d key: " WEP_FMT_64 "\n",
5274 priv->net_dev->name, wep_key->idx, wep_key->len,
5275 WEP_STR_64(wep_key->key));
5277 IPW_DEBUG_WEP("%s: idx: %d, len: %d key: " WEP_FMT_128
5279 priv->net_dev->name, wep_key->idx, wep_key->len,
5280 WEP_STR_128(wep_key->key));
5283 err = ipw2100_disable_adapter(priv);
5284 /* FIXME: IPG: shouldn't this prink be in _disable_adapter()? */
5286 IPW_DEBUG_ERROR("%s: Could not disable adapter %d\n",
5287 priv->net_dev->name, err);
5292 /* send cmd to firmware */
5293 err = ipw2100_hw_send_command(priv, &cmd);
5296 int err2 = ipw2100_enable_adapter(priv);
5303 static int ipw2100_set_key_index(struct ipw2100_priv *priv,
5304 int idx, int batch_mode)
5306 struct host_command cmd = {
5307 .host_command = WEP_KEY_INDEX,
5308 .host_command_sequence = 0,
5309 .host_command_length = 4,
5310 .host_command_parameters[0] = idx,
5314 IPW_DEBUG_HC("WEP_KEY_INDEX: index = %d\n", idx);
5316 if (idx < 0 || idx > 3)
5320 err = ipw2100_disable_adapter(priv);
5322 IPW_DEBUG_ERROR("%s: Could not disable adapter %d\n",
5323 priv->net_dev->name, err);
5328 /* send cmd to firmware */
5329 err = ipw2100_hw_send_command(priv, &cmd);
5332 ipw2100_enable_adapter(priv);
5338 static int ipw2100_configure_security(struct ipw2100_priv *priv,
5341 int i, err, auth_mode, sec_level, use_group;
5343 if (!(priv->status & STATUS_RUNNING))
5347 err = ipw2100_disable_adapter(priv);
5352 if (!priv->sec.enabled) {
5353 err = ipw2100_set_security_information(
5354 priv, IPW_AUTH_OPEN, SEC_LEVEL_0, 0, 1);
5356 auth_mode = IPW_AUTH_OPEN;
5357 if ((priv->sec.flags & SEC_AUTH_MODE) &&
5358 (priv->sec.auth_mode == WLAN_AUTH_SHARED_KEY))
5359 auth_mode = IPW_AUTH_SHARED;
5361 sec_level = SEC_LEVEL_0;
5362 if (priv->sec.flags & SEC_LEVEL)
5363 sec_level = priv->sec.level;
5366 if (priv->sec.flags & SEC_UNICAST_GROUP)
5367 use_group = priv->sec.unicast_uses_group;
5369 err = ipw2100_set_security_information(
5370 priv, auth_mode, sec_level, use_group, 1);
5376 if (priv->sec.enabled) {
5377 for (i = 0; i < 4; i++) {
5378 if (!(priv->sec.flags & (1 << i))) {
5379 memset(priv->sec.keys[i], 0, WEP_KEY_LEN);
5380 priv->sec.key_sizes[i] = 0;
5382 err = ipw2100_set_key(priv, i,
5384 priv->sec.key_sizes[i],
5391 ipw2100_set_key_index(priv, priv->ieee->tx_keyidx, 1);
5394 /* Always enable privacy so the Host can filter WEP packets if
5395 * encrypted data is sent up */
5396 err = ipw2100_set_wep_flags(
5397 priv, priv->sec.enabled ? IPW_PRIVACY_CAPABLE : 0, 1);
5401 priv->status &= ~STATUS_SECURITY_UPDATED;
5405 ipw2100_enable_adapter(priv);
5410 static void ipw2100_security_work(struct ipw2100_priv *priv)
5412 /* If we happen to have reconnected before we get a chance to
5413 * process this, then update the security settings--which causes
5414 * a disassociation to occur */
5415 if (!(priv->status & STATUS_ASSOCIATED) &&
5416 priv->status & STATUS_SECURITY_UPDATED)
5417 ipw2100_configure_security(priv, 0);
5420 static void shim__set_security(struct net_device *dev,
5421 struct ieee80211_security *sec)
5423 struct ipw2100_priv *priv = ieee80211_priv(dev);
5424 int i, force_update = 0;
5426 down(&priv->action_sem);
5427 if (!(priv->status & STATUS_INITIALIZED))
5430 for (i = 0; i < 4; i++) {
5431 if (sec->flags & (1 << i)) {
5432 priv->sec.key_sizes[i] = sec->key_sizes[i];
5433 if (sec->key_sizes[i] == 0)
5434 priv->sec.flags &= ~(1 << i);
5436 memcpy(priv->sec.keys[i], sec->keys[i],
5438 priv->sec.flags |= (1 << i);
5439 priv->status |= STATUS_SECURITY_UPDATED;
5443 if ((sec->flags & SEC_ACTIVE_KEY) &&
5444 priv->sec.active_key != sec->active_key) {
5445 if (sec->active_key <= 3) {
5446 priv->sec.active_key = sec->active_key;
5447 priv->sec.flags |= SEC_ACTIVE_KEY;
5449 priv->sec.flags &= ~SEC_ACTIVE_KEY;
5451 priv->status |= STATUS_SECURITY_UPDATED;
5454 if ((sec->flags & SEC_AUTH_MODE) &&
5455 (priv->sec.auth_mode != sec->auth_mode)) {
5456 priv->sec.auth_mode = sec->auth_mode;
5457 priv->sec.flags |= SEC_AUTH_MODE;
5458 priv->status |= STATUS_SECURITY_UPDATED;
5461 if (sec->flags & SEC_ENABLED &&
5462 priv->sec.enabled != sec->enabled) {
5463 priv->sec.flags |= SEC_ENABLED;
5464 priv->sec.enabled = sec->enabled;
5465 priv->status |= STATUS_SECURITY_UPDATED;
5469 if (sec->flags & SEC_LEVEL &&
5470 priv->sec.level != sec->level) {
5471 priv->sec.level = sec->level;
5472 priv->sec.flags |= SEC_LEVEL;
5473 priv->status |= STATUS_SECURITY_UPDATED;
5476 IPW_DEBUG_WEP("Security flags: %c %c%c%c%c %c%c%c%c\n",
5477 priv->sec.flags & (1<<8) ? '1' : '0',
5478 priv->sec.flags & (1<<7) ? '1' : '0',
5479 priv->sec.flags & (1<<6) ? '1' : '0',
5480 priv->sec.flags & (1<<5) ? '1' : '0',
5481 priv->sec.flags & (1<<4) ? '1' : '0',
5482 priv->sec.flags & (1<<3) ? '1' : '0',
5483 priv->sec.flags & (1<<2) ? '1' : '0',
5484 priv->sec.flags & (1<<1) ? '1' : '0',
5485 priv->sec.flags & (1<<0) ? '1' : '0');
5487 /* As a temporary work around to enable WPA until we figure out why
5488 * wpa_supplicant toggles the security capability of the driver, which
5489 * forces a disassocation with force_update...
5491 * if (force_update || !(priv->status & STATUS_ASSOCIATED))*/
5492 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
5493 ipw2100_configure_security(priv, 0);
5495 up(&priv->action_sem);
5498 static int ipw2100_adapter_setup(struct ipw2100_priv *priv)
5504 IPW_DEBUG_INFO("enter\n");
5506 err = ipw2100_disable_adapter(priv);
5509 #ifdef CONFIG_IPW2100_MONITOR
5510 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
5511 err = ipw2100_set_channel(priv, priv->channel, batch_mode);
5515 IPW_DEBUG_INFO("exit\n");
5519 #endif /* CONFIG_IPW2100_MONITOR */
5521 err = ipw2100_read_mac_address(priv);
5525 err = ipw2100_set_mac_address(priv, batch_mode);
5529 err = ipw2100_set_port_type(priv, priv->ieee->iw_mode, batch_mode);
5533 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
5534 err = ipw2100_set_channel(priv, priv->channel, batch_mode);
5539 err = ipw2100_system_config(priv, batch_mode);
5543 err = ipw2100_set_tx_rates(priv, priv->tx_rates, batch_mode);
5547 /* Default to power mode OFF */
5548 err = ipw2100_set_power_mode(priv, IPW_POWER_MODE_CAM);
5552 err = ipw2100_set_rts_threshold(priv, priv->rts_threshold);
5556 if (priv->config & CFG_STATIC_BSSID)
5557 bssid = priv->bssid;
5560 err = ipw2100_set_mandatory_bssid(priv, bssid, batch_mode);
5564 if (priv->config & CFG_STATIC_ESSID)
5565 err = ipw2100_set_essid(priv, priv->essid, priv->essid_len,
5568 err = ipw2100_set_essid(priv, NULL, 0, batch_mode);
5572 err = ipw2100_configure_security(priv, batch_mode);
5576 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
5577 err = ipw2100_set_ibss_beacon_interval(
5578 priv, priv->beacon_interval, batch_mode);
5582 err = ipw2100_set_tx_power(priv, priv->tx_power);
5588 err = ipw2100_set_fragmentation_threshold(
5589 priv, priv->frag_threshold, batch_mode);
5594 IPW_DEBUG_INFO("exit\n");
5600 /*************************************************************************
5602 * EXTERNALLY CALLED METHODS
5604 *************************************************************************/
5606 /* This method is called by the network layer -- not to be confused with
5607 * ipw2100_set_mac_address() declared above called by this driver (and this
5608 * method as well) to talk to the firmware */
5609 static int ipw2100_set_address(struct net_device *dev, void *p)
5611 struct ipw2100_priv *priv = ieee80211_priv(dev);
5612 struct sockaddr *addr = p;
5615 if (!is_valid_ether_addr(addr->sa_data))
5616 return -EADDRNOTAVAIL;
5618 down(&priv->action_sem);
5620 priv->config |= CFG_CUSTOM_MAC;
5621 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
5623 err = ipw2100_set_mac_address(priv, 0);
5627 priv->reset_backoff = 0;
5628 up(&priv->action_sem);
5629 ipw2100_reset_adapter(priv);
5633 up(&priv->action_sem);
5637 static int ipw2100_open(struct net_device *dev)
5639 struct ipw2100_priv *priv = ieee80211_priv(dev);
5640 unsigned long flags;
5641 IPW_DEBUG_INFO("dev->open\n");
5643 spin_lock_irqsave(&priv->low_lock, flags);
5644 if (priv->status & STATUS_ASSOCIATED)
5645 netif_start_queue(dev);
5646 spin_unlock_irqrestore(&priv->low_lock, flags);
5651 static int ipw2100_close(struct net_device *dev)
5653 struct ipw2100_priv *priv = ieee80211_priv(dev);
5654 unsigned long flags;
5655 struct list_head *element;
5656 struct ipw2100_tx_packet *packet;
5658 IPW_DEBUG_INFO("enter\n");
5660 spin_lock_irqsave(&priv->low_lock, flags);
5662 if (priv->status & STATUS_ASSOCIATED)
5663 netif_carrier_off(dev);
5664 netif_stop_queue(dev);
5666 /* Flush the TX queue ... */
5667 while (!list_empty(&priv->tx_pend_list)) {
5668 element = priv->tx_pend_list.next;
5669 packet = list_entry(element, struct ipw2100_tx_packet, list);
5672 DEC_STAT(&priv->tx_pend_stat);
5674 ieee80211_txb_free(packet->info.d_struct.txb);
5675 packet->info.d_struct.txb = NULL;
5677 list_add_tail(element, &priv->tx_free_list);
5678 INC_STAT(&priv->tx_free_stat);
5680 spin_unlock_irqrestore(&priv->low_lock, flags);
5682 IPW_DEBUG_INFO("exit\n");
5690 * TODO: Fix this function... its just wrong
5692 static void ipw2100_tx_timeout(struct net_device *dev)
5694 struct ipw2100_priv *priv = ieee80211_priv(dev);
5696 priv->ieee->stats.tx_errors++;
5698 #ifdef CONFIG_IPW2100_MONITOR
5699 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
5703 IPW_DEBUG_INFO("%s: TX timed out. Scheduling firmware restart.\n",
5705 schedule_reset(priv);
5710 * TODO: reimplement it so that it reads statistics
5711 * from the adapter using ordinal tables
5712 * instead of/in addition to collecting them
5715 static struct net_device_stats *ipw2100_stats(struct net_device *dev)
5717 struct ipw2100_priv *priv = ieee80211_priv(dev);
5719 return &priv->ieee->stats;
5722 /* Support for wpa_supplicant. Will be replaced with WEXT once
5723 * they get WPA support. */
5724 #ifdef CONFIG_IEEE80211_WPA
5726 /* following definitions must match definitions in driver_ipw2100.c */
5728 #define IPW2100_IOCTL_WPA_SUPPLICANT SIOCIWFIRSTPRIV+30
5730 #define IPW2100_CMD_SET_WPA_PARAM 1
5731 #define IPW2100_CMD_SET_WPA_IE 2
5732 #define IPW2100_CMD_SET_ENCRYPTION 3
5733 #define IPW2100_CMD_MLME 4
5735 #define IPW2100_PARAM_WPA_ENABLED 1
5736 #define IPW2100_PARAM_TKIP_COUNTERMEASURES 2
5737 #define IPW2100_PARAM_DROP_UNENCRYPTED 3
5738 #define IPW2100_PARAM_PRIVACY_INVOKED 4
5739 #define IPW2100_PARAM_AUTH_ALGS 5
5740 #define IPW2100_PARAM_IEEE_802_1X 6
5742 #define IPW2100_MLME_STA_DEAUTH 1
5743 #define IPW2100_MLME_STA_DISASSOC 2
5745 #define IPW2100_CRYPT_ERR_UNKNOWN_ALG 2
5746 #define IPW2100_CRYPT_ERR_UNKNOWN_ADDR 3
5747 #define IPW2100_CRYPT_ERR_CRYPT_INIT_FAILED 4
5748 #define IPW2100_CRYPT_ERR_KEY_SET_FAILED 5
5749 #define IPW2100_CRYPT_ERR_TX_KEY_SET_FAILED 6
5750 #define IPW2100_CRYPT_ERR_CARD_CONF_FAILED 7
5752 #define IPW2100_CRYPT_ALG_NAME_LEN 16
5754 struct ipw2100_param {
5756 u8 sta_addr[ETH_ALEN];
5771 u8 alg[IPW2100_CRYPT_ALG_NAME_LEN];
5775 u8 seq[8]; /* sequence counter (set: RX, get: TX) */
5783 /* end of driver_ipw2100.c code */
5785 static int ipw2100_wpa_enable(struct ipw2100_priv *priv, int value){
5787 struct ieee80211_device *ieee = priv->ieee;
5788 struct ieee80211_security sec = {
5789 .flags = SEC_LEVEL | SEC_ENABLED,
5793 ieee->wpa_enabled = value;
5796 sec.level = SEC_LEVEL_3;
5799 sec.level = SEC_LEVEL_0;
5803 if (ieee->set_security)
5804 ieee->set_security(ieee->dev, &sec);
5811 #define AUTH_ALG_OPEN_SYSTEM 0x1
5812 #define AUTH_ALG_SHARED_KEY 0x2
5814 static int ipw2100_wpa_set_auth_algs(struct ipw2100_priv *priv, int value){
5816 struct ieee80211_device *ieee = priv->ieee;
5817 struct ieee80211_security sec = {
5818 .flags = SEC_AUTH_MODE,
5822 if (value & AUTH_ALG_SHARED_KEY){
5823 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
5826 sec.auth_mode = WLAN_AUTH_OPEN;
5830 if (ieee->set_security)
5831 ieee->set_security(ieee->dev, &sec);
5839 static int ipw2100_wpa_set_param(struct net_device *dev, u8 name, u32 value){
5841 struct ipw2100_priv *priv = ieee80211_priv(dev);
5845 case IPW2100_PARAM_WPA_ENABLED:
5846 ret = ipw2100_wpa_enable(priv, value);
5849 case IPW2100_PARAM_TKIP_COUNTERMEASURES:
5850 priv->ieee->tkip_countermeasures=value;
5853 case IPW2100_PARAM_DROP_UNENCRYPTED:
5854 priv->ieee->drop_unencrypted=value;
5857 case IPW2100_PARAM_PRIVACY_INVOKED:
5858 priv->ieee->privacy_invoked=value;
5861 case IPW2100_PARAM_AUTH_ALGS:
5862 ret = ipw2100_wpa_set_auth_algs(priv, value);
5865 case IPW2100_PARAM_IEEE_802_1X:
5866 priv->ieee->ieee802_1x=value;
5870 IPW_DEBUG_ERROR("%s: Unknown WPA param: %d\n",
5878 static int ipw2100_wpa_mlme(struct net_device *dev, int command, int reason){
5880 struct ipw2100_priv *priv = ieee80211_priv(dev);
5884 case IPW2100_MLME_STA_DEAUTH:
5888 case IPW2100_MLME_STA_DISASSOC:
5889 ipw2100_disassociate_bssid(priv);
5893 IPW_DEBUG_ERROR("%s: Unknown MLME request: %d\n",
5894 dev->name, command);
5902 void ipw2100_wpa_assoc_frame(struct ipw2100_priv *priv,
5903 char *wpa_ie, int wpa_ie_len){
5905 struct ipw2100_wpa_assoc_frame frame;
5907 frame.fixed_ie_mask = 0;
5910 memcpy(frame.var_ie, wpa_ie, wpa_ie_len);
5911 frame.var_ie_len = wpa_ie_len;
5913 /* make sure WPA is enabled */
5914 ipw2100_wpa_enable(priv, 1);
5915 ipw2100_set_wpa_ie(priv, &frame, 0);
5919 static int ipw2100_wpa_set_wpa_ie(struct net_device *dev,
5920 struct ipw2100_param *param, int plen){
5922 struct ipw2100_priv *priv = ieee80211_priv(dev);
5923 struct ieee80211_device *ieee = priv->ieee;
5926 if (! ieee->wpa_enabled)
5929 if (param->u.wpa_ie.len > MAX_WPA_IE_LEN ||
5930 (param->u.wpa_ie.len &&
5931 param->u.wpa_ie.data==NULL))
5934 if (param->u.wpa_ie.len){
5935 buf = kmalloc(param->u.wpa_ie.len, GFP_KERNEL);
5939 memcpy(buf, param->u.wpa_ie.data, param->u.wpa_ie.len);
5941 kfree(ieee->wpa_ie);
5943 ieee->wpa_ie_len = param->u.wpa_ie.len;
5946 kfree(ieee->wpa_ie);
5947 ieee->wpa_ie = NULL;
5948 ieee->wpa_ie_len = 0;
5951 ipw2100_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
5956 /* implementation borrowed from hostap driver */
5958 static int ipw2100_wpa_set_encryption(struct net_device *dev,
5959 struct ipw2100_param *param, int param_len){
5962 struct ipw2100_priv *priv = ieee80211_priv(dev);
5963 struct ieee80211_device *ieee = priv->ieee;
5964 struct ieee80211_crypto_ops *ops;
5965 struct ieee80211_crypt_data **crypt;
5967 struct ieee80211_security sec = {
5971 param->u.crypt.err = 0;
5972 param->u.crypt.alg[IPW2100_CRYPT_ALG_NAME_LEN - 1] = '\0';
5975 (int) ((char *) param->u.crypt.key - (char *) param) +
5976 param->u.crypt.key_len){
5977 IPW_DEBUG_INFO("Len mismatch %d, %d\n", param_len, param->u.crypt.key_len);
5980 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
5981 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
5982 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
5983 if (param->u.crypt.idx >= WEP_KEYS)
5985 crypt = &ieee->crypt[param->u.crypt.idx];
5990 if (strcmp(param->u.crypt.alg, "none") == 0) {
5993 sec.level = SEC_LEVEL_0;
5994 sec.flags |= SEC_ENABLED | SEC_LEVEL;
5995 ieee80211_crypt_delayed_deinit(ieee, crypt);
6000 sec.flags |= SEC_ENABLED;
6002 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6003 if (ops == NULL && strcmp(param->u.crypt.alg, "WEP") == 0) {
6004 request_module("ieee80211_crypt_wep");
6005 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6006 } else if (ops == NULL && strcmp(param->u.crypt.alg, "TKIP") == 0) {
6007 request_module("ieee80211_crypt_tkip");
6008 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6009 } else if (ops == NULL && strcmp(param->u.crypt.alg, "CCMP") == 0) {
6010 request_module("ieee80211_crypt_ccmp");
6011 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6014 IPW_DEBUG_INFO("%s: unknown crypto alg '%s'\n",
6015 dev->name, param->u.crypt.alg);
6016 param->u.crypt.err = IPW2100_CRYPT_ERR_UNKNOWN_ALG;
6021 if (*crypt == NULL || (*crypt)->ops != ops) {
6022 struct ieee80211_crypt_data *new_crypt;
6024 ieee80211_crypt_delayed_deinit(ieee, crypt);
6026 new_crypt = (struct ieee80211_crypt_data *)
6027 kmalloc(sizeof(struct ieee80211_crypt_data), GFP_KERNEL);
6028 if (new_crypt == NULL) {
6032 memset(new_crypt, 0, sizeof(struct ieee80211_crypt_data));
6033 new_crypt->ops = ops;
6034 if (new_crypt->ops && try_module_get(new_crypt->ops->owner))
6035 new_crypt->priv = new_crypt->ops->init(param->u.crypt.idx);
6037 if (new_crypt->priv == NULL) {
6039 param->u.crypt.err =
6040 IPW2100_CRYPT_ERR_CRYPT_INIT_FAILED;
6048 if (param->u.crypt.key_len > 0 && (*crypt)->ops->set_key &&
6049 (*crypt)->ops->set_key(param->u.crypt.key,
6050 param->u.crypt.key_len, param->u.crypt.seq,
6051 (*crypt)->priv) < 0) {
6052 IPW_DEBUG_INFO("%s: key setting failed\n",
6054 param->u.crypt.err = IPW2100_CRYPT_ERR_KEY_SET_FAILED;
6059 if (param->u.crypt.set_tx){
6060 ieee->tx_keyidx = param->u.crypt.idx;
6061 sec.active_key = param->u.crypt.idx;
6062 sec.flags |= SEC_ACTIVE_KEY;
6065 if (ops->name != NULL){
6067 if (strcmp(ops->name, "WEP") == 0) {
6068 memcpy(sec.keys[param->u.crypt.idx], param->u.crypt.key, param->u.crypt.key_len);
6069 sec.key_sizes[param->u.crypt.idx] = param->u.crypt.key_len;
6070 sec.flags |= (1 << param->u.crypt.idx);
6071 sec.flags |= SEC_LEVEL;
6072 sec.level = SEC_LEVEL_1;
6073 } else if (strcmp(ops->name, "TKIP") == 0) {
6074 sec.flags |= SEC_LEVEL;
6075 sec.level = SEC_LEVEL_2;
6076 } else if (strcmp(ops->name, "CCMP") == 0) {
6077 sec.flags |= SEC_LEVEL;
6078 sec.level = SEC_LEVEL_3;
6082 if (ieee->set_security)
6083 ieee->set_security(ieee->dev, &sec);
6085 /* Do not reset port if card is in Managed mode since resetting will
6086 * generate new IEEE 802.11 authentication which may end up in looping
6087 * with IEEE 802.1X. If your hardware requires a reset after WEP
6088 * configuration (for example... Prism2), implement the reset_port in
6089 * the callbacks structures used to initialize the 802.11 stack. */
6090 if (ieee->reset_on_keychange &&
6091 ieee->iw_mode != IW_MODE_INFRA &&
6093 ieee->reset_port(dev)) {
6094 IPW_DEBUG_INFO("%s: reset_port failed\n", dev->name);
6095 param->u.crypt.err = IPW2100_CRYPT_ERR_CARD_CONF_FAILED;
6103 static int ipw2100_wpa_supplicant(struct net_device *dev, struct iw_point *p){
6105 struct ipw2100_param *param;
6108 IPW_DEBUG_IOCTL("wpa_supplicant: len=%d\n", p->length);
6110 if (p->length < sizeof(struct ipw2100_param) || !p->pointer)
6113 param = (struct ipw2100_param *)kmalloc(p->length, GFP_KERNEL);
6117 if (copy_from_user(param, p->pointer, p->length)){
6122 switch (param->cmd){
6124 case IPW2100_CMD_SET_WPA_PARAM:
6125 ret = ipw2100_wpa_set_param(dev, param->u.wpa_param.name,
6126 param->u.wpa_param.value);
6129 case IPW2100_CMD_SET_WPA_IE:
6130 ret = ipw2100_wpa_set_wpa_ie(dev, param, p->length);
6133 case IPW2100_CMD_SET_ENCRYPTION:
6134 ret = ipw2100_wpa_set_encryption(dev, param, p->length);
6137 case IPW2100_CMD_MLME:
6138 ret = ipw2100_wpa_mlme(dev, param->u.mlme.command,
6139 param->u.mlme.reason_code);
6143 IPW_DEBUG_ERROR("%s: Unknown WPA supplicant request: %d\n",
6144 dev->name, param->cmd);
6149 if (ret == 0 && copy_to_user(p->pointer, param, p->length))
6155 #endif /* CONFIG_IEEE80211_WPA */
6157 static int ipw2100_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
6159 #ifdef CONFIG_IEEE80211_WPA
6160 struct iwreq *wrq = (struct iwreq *) rq;
6163 case IPW2100_IOCTL_WPA_SUPPLICANT:
6164 ret = ipw2100_wpa_supplicant(dev, &wrq->u.data);
6171 #endif /* CONFIG_IEEE80211_WPA */
6177 static void ipw_ethtool_get_drvinfo(struct net_device *dev,
6178 struct ethtool_drvinfo *info)
6180 struct ipw2100_priv *priv = ieee80211_priv(dev);
6181 char fw_ver[64], ucode_ver[64];
6183 strcpy(info->driver, DRV_NAME);
6184 strcpy(info->version, DRV_VERSION);
6186 ipw2100_get_fwversion(priv, fw_ver, sizeof(fw_ver));
6187 ipw2100_get_ucodeversion(priv, ucode_ver, sizeof(ucode_ver));
6189 snprintf(info->fw_version, sizeof(info->fw_version), "%s:%d:%s",
6190 fw_ver, priv->eeprom_version, ucode_ver);
6192 strcpy(info->bus_info, pci_name(priv->pci_dev));
6195 static u32 ipw2100_ethtool_get_link(struct net_device *dev)
6197 struct ipw2100_priv *priv = ieee80211_priv(dev);
6198 return (priv->status & STATUS_ASSOCIATED) ? 1 : 0;
6202 static struct ethtool_ops ipw2100_ethtool_ops = {
6203 .get_link = ipw2100_ethtool_get_link,
6204 .get_drvinfo = ipw_ethtool_get_drvinfo,
6207 static void ipw2100_hang_check(void *adapter)
6209 struct ipw2100_priv *priv = adapter;
6210 unsigned long flags;
6211 u32 rtc = 0xa5a5a5a5;
6212 u32 len = sizeof(rtc);
6215 spin_lock_irqsave(&priv->low_lock, flags);
6217 if (priv->fatal_error != 0) {
6218 /* If fatal_error is set then we need to restart */
6219 IPW_DEBUG_INFO("%s: Hardware fatal error detected.\n",
6220 priv->net_dev->name);
6223 } else if (ipw2100_get_ordinal(priv, IPW_ORD_RTC_TIME, &rtc, &len) ||
6224 (rtc == priv->last_rtc)) {
6225 /* Check if firmware is hung */
6226 IPW_DEBUG_INFO("%s: Firmware RTC stalled.\n",
6227 priv->net_dev->name);
6234 priv->stop_hang_check = 1;
6237 /* Restart the NIC */
6238 schedule_reset(priv);
6241 priv->last_rtc = rtc;
6243 if (!priv->stop_hang_check)
6244 queue_delayed_work(priv->workqueue, &priv->hang_check, HZ / 2);
6246 spin_unlock_irqrestore(&priv->low_lock, flags);
6250 static void ipw2100_rf_kill(void *adapter)
6252 struct ipw2100_priv *priv = adapter;
6253 unsigned long flags;
6255 spin_lock_irqsave(&priv->low_lock, flags);
6257 if (rf_kill_active(priv)) {
6258 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
6259 if (!priv->stop_rf_kill)
6260 queue_delayed_work(priv->workqueue, &priv->rf_kill, HZ);
6264 /* RF Kill is now disabled, so bring the device back up */
6266 if (!(priv->status & STATUS_RF_KILL_MASK)) {
6267 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
6269 schedule_reset(priv);
6271 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
6275 spin_unlock_irqrestore(&priv->low_lock, flags);
6278 static void ipw2100_irq_tasklet(struct ipw2100_priv *priv);
6280 /* Look into using netdev destructor to shutdown ieee80211? */
6282 static struct net_device *ipw2100_alloc_device(
6283 struct pci_dev *pci_dev,
6285 unsigned long mem_start,
6286 unsigned long mem_len)
6288 struct ipw2100_priv *priv;
6289 struct net_device *dev;
6291 dev = alloc_ieee80211(sizeof(struct ipw2100_priv));
6294 priv = ieee80211_priv(dev);
6295 priv->ieee = netdev_priv(dev);
6296 priv->pci_dev = pci_dev;
6297 priv->net_dev = dev;
6299 priv->ieee->hard_start_xmit = ipw2100_tx;
6300 priv->ieee->set_security = shim__set_security;
6302 dev->open = ipw2100_open;
6303 dev->stop = ipw2100_close;
6304 dev->init = ipw2100_net_init;
6305 dev->do_ioctl = ipw2100_ioctl;
6306 dev->get_stats = ipw2100_stats;
6307 dev->ethtool_ops = &ipw2100_ethtool_ops;
6308 dev->tx_timeout = ipw2100_tx_timeout;
6309 dev->wireless_handlers = &ipw2100_wx_handler_def;
6310 dev->get_wireless_stats = ipw2100_wx_wireless_stats;
6311 dev->set_mac_address = ipw2100_set_address;
6312 dev->watchdog_timeo = 3*HZ;
6315 dev->base_addr = (unsigned long)base_addr;
6316 dev->mem_start = mem_start;
6317 dev->mem_end = dev->mem_start + mem_len - 1;
6319 /* NOTE: We don't use the wireless_handlers hook
6320 * in dev as the system will start throwing WX requests
6321 * to us before we're actually initialized and it just
6322 * ends up causing problems. So, we just handle
6323 * the WX extensions through the ipw2100_ioctl interface */
6326 /* memset() puts everything to 0, so we only have explicitely set
6327 * those values that need to be something else */
6329 /* If power management is turned on, default to AUTO mode */
6330 priv->power_mode = IPW_POWER_AUTO;
6334 #ifdef CONFIG_IEEE80211_WPA
6335 priv->ieee->wpa_enabled = 0;
6336 priv->ieee->tkip_countermeasures = 0;
6337 priv->ieee->drop_unencrypted = 0;
6338 priv->ieee->privacy_invoked = 0;
6339 priv->ieee->ieee802_1x = 1;
6340 #endif /* CONFIG_IEEE80211_WPA */
6342 /* Set module parameters */
6345 priv->ieee->iw_mode = IW_MODE_ADHOC;
6347 #ifdef CONFIG_IPW2100_MONITOR
6349 priv->ieee->iw_mode = IW_MODE_MONITOR;
6354 priv->ieee->iw_mode = IW_MODE_INFRA;
6359 priv->status |= STATUS_RF_KILL_SW;
6362 ((channel >= REG_MIN_CHANNEL) &&
6363 (channel <= REG_MAX_CHANNEL))) {
6364 priv->config |= CFG_STATIC_CHANNEL;
6365 priv->channel = channel;
6369 priv->config |= CFG_ASSOCIATE;
6371 priv->beacon_interval = DEFAULT_BEACON_INTERVAL;
6372 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
6373 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
6374 priv->rts_threshold = DEFAULT_RTS_THRESHOLD | RTS_DISABLED;
6375 priv->frag_threshold = DEFAULT_FTS | FRAG_DISABLED;
6376 priv->tx_power = IPW_TX_POWER_DEFAULT;
6377 priv->tx_rates = DEFAULT_TX_RATES;
6379 strcpy(priv->nick, "ipw2100");
6381 spin_lock_init(&priv->low_lock);
6382 sema_init(&priv->action_sem, 1);
6383 sema_init(&priv->adapter_sem, 1);
6385 init_waitqueue_head(&priv->wait_command_queue);
6387 netif_carrier_off(dev);
6389 INIT_LIST_HEAD(&priv->msg_free_list);
6390 INIT_LIST_HEAD(&priv->msg_pend_list);
6391 INIT_STAT(&priv->msg_free_stat);
6392 INIT_STAT(&priv->msg_pend_stat);
6394 INIT_LIST_HEAD(&priv->tx_free_list);
6395 INIT_LIST_HEAD(&priv->tx_pend_list);
6396 INIT_STAT(&priv->tx_free_stat);
6397 INIT_STAT(&priv->tx_pend_stat);
6399 INIT_LIST_HEAD(&priv->fw_pend_list);
6400 INIT_STAT(&priv->fw_pend_stat);
6403 #ifdef CONFIG_SOFTWARE_SUSPEND2
6404 priv->workqueue = create_workqueue(DRV_NAME, 0);
6406 priv->workqueue = create_workqueue(DRV_NAME);
6408 INIT_WORK(&priv->reset_work,
6409 (void (*)(void *))ipw2100_reset_adapter, priv);
6410 INIT_WORK(&priv->security_work,
6411 (void (*)(void *))ipw2100_security_work, priv);
6412 INIT_WORK(&priv->wx_event_work,
6413 (void (*)(void *))ipw2100_wx_event_work, priv);
6414 INIT_WORK(&priv->hang_check, ipw2100_hang_check, priv);
6415 INIT_WORK(&priv->rf_kill, ipw2100_rf_kill, priv);
6417 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
6418 ipw2100_irq_tasklet, (unsigned long)priv);
6420 /* NOTE: We do not start the deferred work for status checks yet */
6421 priv->stop_rf_kill = 1;
6422 priv->stop_hang_check = 1;
6427 static int ipw2100_pci_init_one(struct pci_dev *pci_dev,
6428 const struct pci_device_id *ent)
6430 unsigned long mem_start, mem_len, mem_flags;
6431 char *base_addr = NULL;
6432 struct net_device *dev = NULL;
6433 struct ipw2100_priv *priv = NULL;
6438 IPW_DEBUG_INFO("enter\n");
6440 mem_start = pci_resource_start(pci_dev, 0);
6441 mem_len = pci_resource_len(pci_dev, 0);
6442 mem_flags = pci_resource_flags(pci_dev, 0);
6444 if ((mem_flags & IORESOURCE_MEM) != IORESOURCE_MEM) {
6445 IPW_DEBUG_INFO("weird - resource type is not memory\n");
6450 base_addr = ioremap_nocache(mem_start, mem_len);
6452 printk(KERN_WARNING DRV_NAME
6453 "Error calling ioremap_nocache.\n");
6458 /* allocate and initialize our net_device */
6459 dev = ipw2100_alloc_device(pci_dev, base_addr, mem_start, mem_len);
6461 printk(KERN_WARNING DRV_NAME
6462 "Error calling ipw2100_alloc_device.\n");
6467 /* set up PCI mappings for device */
6468 err = pci_enable_device(pci_dev);
6470 printk(KERN_WARNING DRV_NAME
6471 "Error calling pci_enable_device.\n");
6475 priv = ieee80211_priv(dev);
6477 pci_set_master(pci_dev);
6478 pci_set_drvdata(pci_dev, priv);
6480 err = pci_set_dma_mask(pci_dev, DMA_32BIT_MASK);
6482 printk(KERN_WARNING DRV_NAME
6483 "Error calling pci_set_dma_mask.\n");
6484 pci_disable_device(pci_dev);
6488 err = pci_request_regions(pci_dev, DRV_NAME);
6490 printk(KERN_WARNING DRV_NAME
6491 "Error calling pci_request_regions.\n");
6492 pci_disable_device(pci_dev);
6496 /* We disable the RETRY_TIMEOUT register (0x41) to keep
6497 * PCI Tx retries from interfering with C3 CPU state */
6498 pci_read_config_dword(pci_dev, 0x40, &val);
6499 if ((val & 0x0000ff00) != 0)
6500 pci_write_config_dword(pci_dev, 0x40, val & 0xffff00ff);
6502 pci_set_power_state(pci_dev, 0);
6504 if (!ipw2100_hw_is_adapter_in_system(dev)) {
6505 printk(KERN_WARNING DRV_NAME
6506 "Device not found via register read.\n");
6511 SET_NETDEV_DEV(dev, &pci_dev->dev);
6513 /* Force interrupts to be shut off on the device */
6514 priv->status |= STATUS_INT_ENABLED;
6515 ipw2100_disable_interrupts(priv);
6517 /* Allocate and initialize the Tx/Rx queues and lists */
6518 if (ipw2100_queues_allocate(priv)) {
6519 printk(KERN_WARNING DRV_NAME
6520 "Error calilng ipw2100_queues_allocate.\n");
6524 ipw2100_queues_initialize(priv);
6526 err = request_irq(pci_dev->irq,
6527 ipw2100_interrupt, SA_SHIRQ,
6530 printk(KERN_WARNING DRV_NAME
6531 "Error calling request_irq: %d.\n",
6535 dev->irq = pci_dev->irq;
6537 IPW_DEBUG_INFO("Attempting to register device...\n");
6539 SET_MODULE_OWNER(dev);
6541 printk(KERN_INFO DRV_NAME
6542 ": Detected Intel PRO/Wireless 2100 Network Connection\n");
6544 /* Bring up the interface. Pre 0.46, after we registered the
6545 * network device we would call ipw2100_up. This introduced a race
6546 * condition with newer hotplug configurations (network was coming
6547 * up and making calls before the device was initialized).
6549 * If we called ipw2100_up before we registered the device, then the
6550 * device name wasn't registered. So, we instead use the net_dev->init
6551 * member to call a function that then just turns and calls ipw2100_up.
6552 * net_dev->init is called after name allocation but before the
6553 * notifier chain is called */
6554 down(&priv->action_sem);
6555 err = register_netdev(dev);
6557 printk(KERN_WARNING DRV_NAME
6558 "Error calling register_netdev.\n");
6563 IPW_DEBUG_INFO("%s: Bound to %s\n", dev->name, pci_name(pci_dev));
6565 /* perform this after register_netdev so that dev->name is set */
6566 sysfs_create_group(&pci_dev->dev.kobj, &ipw2100_attribute_group);
6567 netif_carrier_off(dev);
6569 /* If the RF Kill switch is disabled, go ahead and complete the
6570 * startup sequence */
6571 if (!(priv->status & STATUS_RF_KILL_MASK)) {
6572 /* Enable the adapter - sends HOST_COMPLETE */
6573 if (ipw2100_enable_adapter(priv)) {
6574 printk(KERN_WARNING DRV_NAME
6575 ": %s: failed in call to enable adapter.\n",
6576 priv->net_dev->name);
6577 ipw2100_hw_stop_adapter(priv);
6582 /* Start a scan . . . */
6583 ipw2100_set_scan_options(priv);
6584 ipw2100_start_scan(priv);
6587 IPW_DEBUG_INFO("exit\n");
6589 priv->status |= STATUS_INITIALIZED;
6591 up(&priv->action_sem);
6596 up(&priv->action_sem);
6601 unregister_netdev(dev);
6603 ipw2100_hw_stop_adapter(priv);
6605 ipw2100_disable_interrupts(priv);
6608 free_irq(dev->irq, priv);
6610 ipw2100_kill_workqueue(priv);
6612 /* These are safe to call even if they weren't allocated */
6613 ipw2100_queues_free(priv);
6614 sysfs_remove_group(&pci_dev->dev.kobj, &ipw2100_attribute_group);
6616 free_ieee80211(dev);
6617 pci_set_drvdata(pci_dev, NULL);
6621 iounmap((char*)base_addr);
6623 pci_release_regions(pci_dev);
6624 pci_disable_device(pci_dev);
6629 static void __devexit ipw2100_pci_remove_one(struct pci_dev *pci_dev)
6631 struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
6632 struct net_device *dev;
6635 down(&priv->action_sem);
6637 priv->status &= ~STATUS_INITIALIZED;
6639 dev = priv->net_dev;
6640 sysfs_remove_group(&pci_dev->dev.kobj, &ipw2100_attribute_group);
6643 if (ipw2100_firmware.version)
6644 ipw2100_release_firmware(priv, &ipw2100_firmware);
6646 /* Take down the hardware */
6649 /* Release the semaphore so that the network subsystem can
6650 * complete any needed calls into the driver... */
6651 up(&priv->action_sem);
6653 /* Unregister the device first - this results in close()
6654 * being called if the device is open. If we free storage
6655 * first, then close() will crash. */
6656 unregister_netdev(dev);
6658 /* ipw2100_down will ensure that there is no more pending work
6659 * in the workqueue's, so we can safely remove them now. */
6660 ipw2100_kill_workqueue(priv);
6662 ipw2100_queues_free(priv);
6664 /* Free potential debugging firmware snapshot */
6665 ipw2100_snapshot_free(priv);
6668 free_irq(dev->irq, priv);
6671 iounmap((unsigned char *)dev->base_addr);
6673 free_ieee80211(dev);
6676 pci_release_regions(pci_dev);
6677 pci_disable_device(pci_dev);
6679 IPW_DEBUG_INFO("exit\n");
6684 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11)
6685 static int ipw2100_suspend(struct pci_dev *pci_dev, u32 state)
6687 static int ipw2100_suspend(struct pci_dev *pci_dev, pm_message_t state)
6690 struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
6691 struct net_device *dev = priv->net_dev;
6693 IPW_DEBUG_INFO("%s: Going into suspend...\n",
6696 down(&priv->action_sem);
6697 if (priv->status & STATUS_INITIALIZED) {
6698 /* Take down the device; powers it off, etc. */
6702 /* Remove the PRESENT state of the device */
6703 netif_device_detach(dev);
6705 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)
6706 pci_save_state(pci_dev, priv->pm_state);
6708 pci_save_state(pci_dev);
6710 pci_disable_device (pci_dev);
6711 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11)
6712 pci_set_power_state(pci_dev, state);
6714 pci_set_power_state(pci_dev, PCI_D3hot);
6717 up(&priv->action_sem);
6722 static int ipw2100_resume(struct pci_dev *pci_dev)
6724 struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
6725 struct net_device *dev = priv->net_dev;
6728 if (IPW2100_PM_DISABLED)
6731 down(&priv->action_sem);
6733 IPW_DEBUG_INFO("%s: Coming out of suspend...\n",
6736 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11)
6737 pci_set_power_state(pci_dev, 0);
6739 pci_set_power_state(pci_dev, PCI_D0);
6741 pci_enable_device(pci_dev);
6742 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)
6743 pci_restore_state(pci_dev, priv->pm_state);
6745 pci_restore_state(pci_dev);
6749 * Suspend/Resume resets the PCI configuration space, so we have to
6750 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
6751 * from interfering with C3 CPU state. pci_restore_state won't help
6752 * here since it only restores the first 64 bytes pci config header.
6754 pci_read_config_dword(pci_dev, 0x40, &val);
6755 if ((val & 0x0000ff00) != 0)
6756 pci_write_config_dword(pci_dev, 0x40, val & 0xffff00ff);
6758 /* Set the device back into the PRESENT state; this will also wake
6759 * the queue of needed */
6760 netif_device_attach(dev);
6762 /* Bring the device back up */
6763 if (!(priv->status & STATUS_RF_KILL_SW))
6764 ipw2100_up(priv, 0);
6766 up(&priv->action_sem);
6773 #define IPW2100_DEV_ID(x) { PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, x }
6775 static struct pci_device_id ipw2100_pci_id_table[] __devinitdata = {
6776 IPW2100_DEV_ID(0x2520), /* IN 2100A mPCI 3A */
6777 IPW2100_DEV_ID(0x2521), /* IN 2100A mPCI 3B */
6778 IPW2100_DEV_ID(0x2524), /* IN 2100A mPCI 3B */
6779 IPW2100_DEV_ID(0x2525), /* IN 2100A mPCI 3B */
6780 IPW2100_DEV_ID(0x2526), /* IN 2100A mPCI Gen A3 */
6781 IPW2100_DEV_ID(0x2522), /* IN 2100 mPCI 3B */
6782 IPW2100_DEV_ID(0x2523), /* IN 2100 mPCI 3A */
6783 IPW2100_DEV_ID(0x2527), /* IN 2100 mPCI 3B */
6784 IPW2100_DEV_ID(0x2528), /* IN 2100 mPCI 3B */
6785 IPW2100_DEV_ID(0x2529), /* IN 2100 mPCI 3B */
6786 IPW2100_DEV_ID(0x252B), /* IN 2100 mPCI 3A */
6787 IPW2100_DEV_ID(0x252C), /* IN 2100 mPCI 3A */
6788 IPW2100_DEV_ID(0x252D), /* IN 2100 mPCI 3A */
6790 IPW2100_DEV_ID(0x2550), /* IB 2100A mPCI 3B */
6791 IPW2100_DEV_ID(0x2551), /* IB 2100 mPCI 3B */
6792 IPW2100_DEV_ID(0x2553), /* IB 2100 mPCI 3B */
6793 IPW2100_DEV_ID(0x2554), /* IB 2100 mPCI 3B */
6794 IPW2100_DEV_ID(0x2555), /* IB 2100 mPCI 3B */
6796 IPW2100_DEV_ID(0x2560), /* DE 2100A mPCI 3A */
6797 IPW2100_DEV_ID(0x2562), /* DE 2100A mPCI 3A */
6798 IPW2100_DEV_ID(0x2563), /* DE 2100A mPCI 3A */
6799 IPW2100_DEV_ID(0x2561), /* DE 2100 mPCI 3A */
6800 IPW2100_DEV_ID(0x2565), /* DE 2100 mPCI 3A */
6801 IPW2100_DEV_ID(0x2566), /* DE 2100 mPCI 3A */
6802 IPW2100_DEV_ID(0x2567), /* DE 2100 mPCI 3A */
6804 IPW2100_DEV_ID(0x2570), /* GA 2100 mPCI 3B */
6806 IPW2100_DEV_ID(0x2580), /* TO 2100A mPCI 3B */
6807 IPW2100_DEV_ID(0x2582), /* TO 2100A mPCI 3B */
6808 IPW2100_DEV_ID(0x2583), /* TO 2100A mPCI 3B */
6809 IPW2100_DEV_ID(0x2581), /* TO 2100 mPCI 3B */
6810 IPW2100_DEV_ID(0x2585), /* TO 2100 mPCI 3B */
6811 IPW2100_DEV_ID(0x2586), /* TO 2100 mPCI 3B */
6812 IPW2100_DEV_ID(0x2587), /* TO 2100 mPCI 3B */
6814 IPW2100_DEV_ID(0x2590), /* SO 2100A mPCI 3B */
6815 IPW2100_DEV_ID(0x2592), /* SO 2100A mPCI 3B */
6816 IPW2100_DEV_ID(0x2591), /* SO 2100 mPCI 3B */
6817 IPW2100_DEV_ID(0x2593), /* SO 2100 mPCI 3B */
6818 IPW2100_DEV_ID(0x2596), /* SO 2100 mPCI 3B */
6819 IPW2100_DEV_ID(0x2598), /* SO 2100 mPCI 3B */
6821 IPW2100_DEV_ID(0x25A0), /* HP 2100 mPCI 3B */
6825 MODULE_DEVICE_TABLE(pci, ipw2100_pci_id_table);
6827 static struct pci_driver ipw2100_pci_driver = {
6829 .id_table = ipw2100_pci_id_table,
6830 .probe = ipw2100_pci_init_one,
6831 .remove = __devexit_p(ipw2100_pci_remove_one),
6833 .suspend = ipw2100_suspend,
6834 .resume = ipw2100_resume,
6840 * Initialize the ipw2100 driver/module
6842 * @returns 0 if ok, < 0 errno node con error.
6844 * Note: we cannot init the /proc stuff until the PCI driver is there,
6845 * or we risk an unlikely race condition on someone accessing
6846 * uninitialized data in the PCI dev struct through /proc.
6848 static int __init ipw2100_init(void)
6852 printk(KERN_INFO DRV_NAME ": %s, %s\n", DRV_DESCRIPTION, DRV_VERSION);
6853 printk(KERN_INFO DRV_NAME ": %s\n", DRV_COPYRIGHT);
6855 #ifdef CONFIG_IEEE80211_NOWEP
6856 IPW_DEBUG_INFO(DRV_NAME ": Compiled with WEP disabled.\n");
6859 ret = pci_module_init(&ipw2100_pci_driver);
6861 #ifdef CONFIG_IPW_DEBUG
6862 ipw2100_debug_level = debug;
6863 driver_create_file(&ipw2100_pci_driver.driver,
6864 &driver_attr_debug_level);
6872 * Cleanup ipw2100 driver registration
6874 static void __exit ipw2100_exit(void)
6876 /* FIXME: IPG: check that we have no instances of the devices open */
6877 #ifdef CONFIG_IPW_DEBUG
6878 driver_remove_file(&ipw2100_pci_driver.driver,
6879 &driver_attr_debug_level);
6881 pci_unregister_driver(&ipw2100_pci_driver);
6884 module_init(ipw2100_init);
6885 module_exit(ipw2100_exit);
6887 #define WEXT_USECHANNELS 1
6889 const long ipw2100_frequencies[] = {
6890 2412, 2417, 2422, 2427,
6891 2432, 2437, 2442, 2447,
6892 2452, 2457, 2462, 2467,
6896 #define FREQ_COUNT (sizeof(ipw2100_frequencies) / \
6897 sizeof(ipw2100_frequencies[0]))
6899 const long ipw2100_rates_11b[] = {
6906 #define RATE_COUNT (sizeof(ipw2100_rates_11b) / sizeof(ipw2100_rates_11b[0]))
6908 static int ipw2100_wx_get_name(struct net_device *dev,
6909 struct iw_request_info *info,
6910 union iwreq_data *wrqu, char *extra)
6913 * This can be called at any time. No action lock required
6916 struct ipw2100_priv *priv = ieee80211_priv(dev);
6917 if (!(priv->status & STATUS_ASSOCIATED))
6918 strcpy(wrqu->name, "unassociated");
6920 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11b");
6922 IPW_DEBUG_WX("Name: %s\n", wrqu->name);
6927 static int ipw2100_wx_set_freq(struct net_device *dev,
6928 struct iw_request_info *info,
6929 union iwreq_data *wrqu, char *extra)
6931 struct ipw2100_priv *priv = ieee80211_priv(dev);
6932 struct iw_freq *fwrq = &wrqu->freq;
6935 if (priv->ieee->iw_mode == IW_MODE_INFRA)
6938 down(&priv->action_sem);
6939 if (!(priv->status & STATUS_INITIALIZED)) {
6944 /* if setting by freq convert to channel */
6946 if ((fwrq->m >= (int) 2.412e8 &&
6947 fwrq->m <= (int) 2.487e8)) {
6948 int f = fwrq->m / 100000;
6951 while ((c < REG_MAX_CHANNEL) &&
6952 (f != ipw2100_frequencies[c]))
6955 /* hack to fall through */
6961 if (fwrq->e > 0 || fwrq->m > 1000)
6963 else { /* Set the channel */
6964 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
6965 err = ipw2100_set_channel(priv, fwrq->m, 0);
6969 up(&priv->action_sem);
6974 static int ipw2100_wx_get_freq(struct net_device *dev,
6975 struct iw_request_info *info,
6976 union iwreq_data *wrqu, char *extra)
6979 * This can be called at any time. No action lock required
6982 struct ipw2100_priv *priv = ieee80211_priv(dev);
6986 /* If we are associated, trying to associate, or have a statically
6987 * configured CHANNEL then return that; otherwise return ANY */
6988 if (priv->config & CFG_STATIC_CHANNEL ||
6989 priv->status & STATUS_ASSOCIATED)
6990 wrqu->freq.m = priv->channel;
6994 IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
6999 static int ipw2100_wx_set_mode(struct net_device *dev,
7000 struct iw_request_info *info,
7001 union iwreq_data *wrqu, char *extra)
7003 struct ipw2100_priv *priv = ieee80211_priv(dev);
7006 IPW_DEBUG_WX("SET Mode -> %d \n", wrqu->mode);
7008 if (wrqu->mode == priv->ieee->iw_mode)
7011 down(&priv->action_sem);
7012 if (!(priv->status & STATUS_INITIALIZED)) {
7017 switch (wrqu->mode) {
7018 #ifdef CONFIG_IPW2100_MONITOR
7019 case IW_MODE_MONITOR:
7020 err = ipw2100_switch_mode(priv, IW_MODE_MONITOR);
7022 #endif /* CONFIG_IPW2100_MONITOR */
7024 err = ipw2100_switch_mode(priv, IW_MODE_ADHOC);
7029 err = ipw2100_switch_mode(priv, IW_MODE_INFRA);
7034 up(&priv->action_sem);
7038 static int ipw2100_wx_get_mode(struct net_device *dev,
7039 struct iw_request_info *info,
7040 union iwreq_data *wrqu, char *extra)
7043 * This can be called at any time. No action lock required
7046 struct ipw2100_priv *priv = ieee80211_priv(dev);
7048 wrqu->mode = priv->ieee->iw_mode;
7049 IPW_DEBUG_WX("GET Mode -> %d\n", wrqu->mode);
7055 #define POWER_MODES 5
7057 /* Values are in microsecond */
7058 const s32 timeout_duration[POWER_MODES] = {
7066 const s32 period_duration[POWER_MODES] = {
7074 static int ipw2100_wx_get_range(struct net_device *dev,
7075 struct iw_request_info *info,
7076 union iwreq_data *wrqu, char *extra)
7079 * This can be called at any time. No action lock required
7082 struct ipw2100_priv *priv = ieee80211_priv(dev);
7083 struct iw_range *range = (struct iw_range *)extra;
7087 wrqu->data.length = sizeof(*range);
7088 memset(range, 0, sizeof(*range));
7090 /* Let's try to keep this struct in the same order as in
7091 * linux/include/wireless.h
7094 /* TODO: See what values we can set, and remove the ones we can't
7095 * set, or fill them with some default data.
7098 /* ~5 Mb/s real (802.11b) */
7099 range->throughput = 5 * 1000 * 1000;
7101 // range->sensitivity; /* signal level threshold range */
7103 range->max_qual.qual = 100;
7104 /* TODO: Find real max RSSI and stick here */
7105 range->max_qual.level = 0;
7106 range->max_qual.noise = 0;
7107 range->max_qual.updated = 7; /* Updated all three */
7109 range->avg_qual.qual = 70; /* > 8% missed beacons is 'bad' */
7110 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
7111 range->avg_qual.level = 20 + IPW2100_RSSI_TO_DBM;
7112 range->avg_qual.noise = 0;
7113 range->avg_qual.updated = 7; /* Updated all three */
7115 range->num_bitrates = RATE_COUNT;
7117 for (i = 0; i < RATE_COUNT && i < IW_MAX_BITRATES; i++) {
7118 range->bitrate[i] = ipw2100_rates_11b[i];
7121 range->min_rts = MIN_RTS_THRESHOLD;
7122 range->max_rts = MAX_RTS_THRESHOLD;
7123 range->min_frag = MIN_FRAG_THRESHOLD;
7124 range->max_frag = MAX_FRAG_THRESHOLD;
7126 range->min_pmp = period_duration[0]; /* Minimal PM period */
7127 range->max_pmp = period_duration[POWER_MODES-1];/* Maximal PM period */
7128 range->min_pmt = timeout_duration[POWER_MODES-1]; /* Minimal PM timeout */
7129 range->max_pmt = timeout_duration[0];/* Maximal PM timeout */
7131 /* How to decode max/min PM period */
7132 range->pmp_flags = IW_POWER_PERIOD;
7133 /* How to decode max/min PM period */
7134 range->pmt_flags = IW_POWER_TIMEOUT;
7135 /* What PM options are supported */
7136 range->pm_capa = IW_POWER_TIMEOUT | IW_POWER_PERIOD;
7138 range->encoding_size[0] = 5;
7139 range->encoding_size[1] = 13; /* Different token sizes */
7140 range->num_encoding_sizes = 2; /* Number of entry in the list */
7141 range->max_encoding_tokens = WEP_KEYS; /* Max number of tokens */
7142 // range->encoding_login_index; /* token index for login token */
7144 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7145 range->txpower_capa = IW_TXPOW_DBM;
7146 range->num_txpower = IW_MAX_TXPOWER;
7147 for (i = 0, level = (IPW_TX_POWER_MAX_DBM * 16); i < IW_MAX_TXPOWER;
7148 i++, level -= ((IPW_TX_POWER_MAX_DBM - IPW_TX_POWER_MIN_DBM) * 16) /
7149 (IW_MAX_TXPOWER - 1))
7150 range->txpower[i] = level / 16;
7152 range->txpower_capa = 0;
7153 range->num_txpower = 0;
7157 /* Set the Wireless Extension versions */
7158 range->we_version_compiled = WIRELESS_EXT;
7159 range->we_version_source = 16;
7161 // range->retry_capa; /* What retry options are supported */
7162 // range->retry_flags; /* How to decode max/min retry limit */
7163 // range->r_time_flags; /* How to decode max/min retry life */
7164 // range->min_retry; /* Minimal number of retries */
7165 // range->max_retry; /* Maximal number of retries */
7166 // range->min_r_time; /* Minimal retry lifetime */
7167 // range->max_r_time; /* Maximal retry lifetime */
7169 range->num_channels = FREQ_COUNT;
7172 for (i = 0; i < FREQ_COUNT; i++) {
7173 // TODO: Include only legal frequencies for some countries
7174 // if (local->channel_mask & (1 << i)) {
7175 range->freq[val].i = i + 1;
7176 range->freq[val].m = ipw2100_frequencies[i] * 100000;
7177 range->freq[val].e = 1;
7180 if (val == IW_MAX_FREQUENCIES)
7183 range->num_frequency = val;
7185 IPW_DEBUG_WX("GET Range\n");
7190 static int ipw2100_wx_set_wap(struct net_device *dev,
7191 struct iw_request_info *info,
7192 union iwreq_data *wrqu, char *extra)
7194 struct ipw2100_priv *priv = ieee80211_priv(dev);
7197 static const unsigned char any[] = {
7198 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
7200 static const unsigned char off[] = {
7201 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
7205 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
7208 down(&priv->action_sem);
7209 if (!(priv->status & STATUS_INITIALIZED)) {
7214 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
7215 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
7216 /* we disable mandatory BSSID association */
7217 IPW_DEBUG_WX("exit - disable mandatory BSSID\n");
7218 priv->config &= ~CFG_STATIC_BSSID;
7219 err = ipw2100_set_mandatory_bssid(priv, NULL, 0);
7223 priv->config |= CFG_STATIC_BSSID;
7224 memcpy(priv->mandatory_bssid_mac, wrqu->ap_addr.sa_data, ETH_ALEN);
7226 err = ipw2100_set_mandatory_bssid(priv, wrqu->ap_addr.sa_data, 0);
7228 IPW_DEBUG_WX("SET BSSID -> %02X:%02X:%02X:%02X:%02X:%02X\n",
7229 wrqu->ap_addr.sa_data[0] & 0xff,
7230 wrqu->ap_addr.sa_data[1] & 0xff,
7231 wrqu->ap_addr.sa_data[2] & 0xff,
7232 wrqu->ap_addr.sa_data[3] & 0xff,
7233 wrqu->ap_addr.sa_data[4] & 0xff,
7234 wrqu->ap_addr.sa_data[5] & 0xff);
7237 up(&priv->action_sem);
7241 static int ipw2100_wx_get_wap(struct net_device *dev,
7242 struct iw_request_info *info,
7243 union iwreq_data *wrqu, char *extra)
7246 * This can be called at any time. No action lock required
7249 struct ipw2100_priv *priv = ieee80211_priv(dev);
7251 /* If we are associated, trying to associate, or have a statically
7252 * configured BSSID then return that; otherwise return ANY */
7253 if (priv->config & CFG_STATIC_BSSID ||
7254 priv->status & STATUS_ASSOCIATED) {
7255 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
7256 memcpy(wrqu->ap_addr.sa_data, &priv->bssid, ETH_ALEN);
7258 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
7260 IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n",
7261 MAC_ARG(wrqu->ap_addr.sa_data));
7265 static int ipw2100_wx_set_essid(struct net_device *dev,
7266 struct iw_request_info *info,
7267 union iwreq_data *wrqu, char *extra)
7269 struct ipw2100_priv *priv = ieee80211_priv(dev);
7270 char *essid = ""; /* ANY */
7274 down(&priv->action_sem);
7275 if (!(priv->status & STATUS_INITIALIZED)) {
7280 if (wrqu->essid.flags && wrqu->essid.length) {
7281 length = wrqu->essid.length - 1;
7286 IPW_DEBUG_WX("Setting ESSID to ANY\n");
7287 priv->config &= ~CFG_STATIC_ESSID;
7288 err = ipw2100_set_essid(priv, NULL, 0, 0);
7292 length = min(length, IW_ESSID_MAX_SIZE);
7294 priv->config |= CFG_STATIC_ESSID;
7296 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
7297 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
7302 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length),
7305 priv->essid_len = length;
7306 memcpy(priv->essid, essid, priv->essid_len);
7308 err = ipw2100_set_essid(priv, essid, length, 0);
7311 up(&priv->action_sem);
7315 static int ipw2100_wx_get_essid(struct net_device *dev,
7316 struct iw_request_info *info,
7317 union iwreq_data *wrqu, char *extra)
7320 * This can be called at any time. No action lock required
7323 struct ipw2100_priv *priv = ieee80211_priv(dev);
7325 /* If we are associated, trying to associate, or have a statically
7326 * configured ESSID then return that; otherwise return ANY */
7327 if (priv->config & CFG_STATIC_ESSID ||
7328 priv->status & STATUS_ASSOCIATED) {
7329 IPW_DEBUG_WX("Getting essid: '%s'\n",
7330 escape_essid(priv->essid, priv->essid_len));
7331 memcpy(extra, priv->essid, priv->essid_len);
7332 wrqu->essid.length = priv->essid_len;
7333 wrqu->essid.flags = 1; /* active */
7335 IPW_DEBUG_WX("Getting essid: ANY\n");
7336 wrqu->essid.length = 0;
7337 wrqu->essid.flags = 0; /* active */
7343 static int ipw2100_wx_set_nick(struct net_device *dev,
7344 struct iw_request_info *info,
7345 union iwreq_data *wrqu, char *extra)
7348 * This can be called at any time. No action lock required
7351 struct ipw2100_priv *priv = ieee80211_priv(dev);
7353 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
7356 wrqu->data.length = min((size_t)wrqu->data.length, sizeof(priv->nick));
7357 memset(priv->nick, 0, sizeof(priv->nick));
7358 memcpy(priv->nick, extra, wrqu->data.length);
7360 IPW_DEBUG_WX("SET Nickname -> %s \n", priv->nick);
7365 static int ipw2100_wx_get_nick(struct net_device *dev,
7366 struct iw_request_info *info,
7367 union iwreq_data *wrqu, char *extra)
7370 * This can be called at any time. No action lock required
7373 struct ipw2100_priv *priv = ieee80211_priv(dev);
7375 wrqu->data.length = strlen(priv->nick) + 1;
7376 memcpy(extra, priv->nick, wrqu->data.length);
7377 wrqu->data.flags = 1; /* active */
7379 IPW_DEBUG_WX("GET Nickname -> %s \n", extra);
7384 static int ipw2100_wx_set_rate(struct net_device *dev,
7385 struct iw_request_info *info,
7386 union iwreq_data *wrqu, char *extra)
7388 struct ipw2100_priv *priv = ieee80211_priv(dev);
7389 u32 target_rate = wrqu->bitrate.value;
7393 down(&priv->action_sem);
7394 if (!(priv->status & STATUS_INITIALIZED)) {
7401 if (target_rate == 1000000 ||
7402 (!wrqu->bitrate.fixed && target_rate > 1000000))
7403 rate |= TX_RATE_1_MBIT;
7404 if (target_rate == 2000000 ||
7405 (!wrqu->bitrate.fixed && target_rate > 2000000))
7406 rate |= TX_RATE_2_MBIT;
7407 if (target_rate == 5500000 ||
7408 (!wrqu->bitrate.fixed && target_rate > 5500000))
7409 rate |= TX_RATE_5_5_MBIT;
7410 if (target_rate == 11000000 ||
7411 (!wrqu->bitrate.fixed && target_rate > 11000000))
7412 rate |= TX_RATE_11_MBIT;
7414 rate = DEFAULT_TX_RATES;
7416 err = ipw2100_set_tx_rates(priv, rate, 0);
7418 IPW_DEBUG_WX("SET Rate -> %04X \n", rate);
7420 up(&priv->action_sem);
7425 static int ipw2100_wx_get_rate(struct net_device *dev,
7426 struct iw_request_info *info,
7427 union iwreq_data *wrqu, char *extra)
7429 struct ipw2100_priv *priv = ieee80211_priv(dev);
7431 int len = sizeof(val);
7434 if (!(priv->status & STATUS_ENABLED) ||
7435 priv->status & STATUS_RF_KILL_MASK ||
7436 !(priv->status & STATUS_ASSOCIATED)) {
7437 wrqu->bitrate.value = 0;
7441 down(&priv->action_sem);
7442 if (!(priv->status & STATUS_INITIALIZED)) {
7447 err = ipw2100_get_ordinal(priv, IPW_ORD_CURRENT_TX_RATE, &val, &len);
7449 IPW_DEBUG_WX("failed querying ordinals.\n");
7453 switch (val & TX_RATE_MASK) {
7454 case TX_RATE_1_MBIT:
7455 wrqu->bitrate.value = 1000000;
7457 case TX_RATE_2_MBIT:
7458 wrqu->bitrate.value = 2000000;
7460 case TX_RATE_5_5_MBIT:
7461 wrqu->bitrate.value = 5500000;
7463 case TX_RATE_11_MBIT:
7464 wrqu->bitrate.value = 11000000;
7467 wrqu->bitrate.value = 0;
7470 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
7473 up(&priv->action_sem);
7477 static int ipw2100_wx_set_rts(struct net_device *dev,
7478 struct iw_request_info *info,
7479 union iwreq_data *wrqu, char *extra)
7481 struct ipw2100_priv *priv = ieee80211_priv(dev);
7484 /* Auto RTS not yet supported */
7485 if (wrqu->rts.fixed == 0)
7488 down(&priv->action_sem);
7489 if (!(priv->status & STATUS_INITIALIZED)) {
7494 if (wrqu->rts.disabled)
7495 value = priv->rts_threshold | RTS_DISABLED;
7497 if (wrqu->rts.value < 1 ||
7498 wrqu->rts.value > 2304) {
7502 value = wrqu->rts.value;
7505 err = ipw2100_set_rts_threshold(priv, value);
7507 IPW_DEBUG_WX("SET RTS Threshold -> 0x%08X \n", value);
7509 up(&priv->action_sem);
7513 static int ipw2100_wx_get_rts(struct net_device *dev,
7514 struct iw_request_info *info,
7515 union iwreq_data *wrqu, char *extra)
7518 * This can be called at any time. No action lock required
7521 struct ipw2100_priv *priv = ieee80211_priv(dev);
7523 wrqu->rts.value = priv->rts_threshold & ~RTS_DISABLED;
7524 wrqu->rts.fixed = 1; /* no auto select */
7526 /* If RTS is set to the default value, then it is disabled */
7527 wrqu->rts.disabled = (priv->rts_threshold & RTS_DISABLED) ? 1 : 0;
7529 IPW_DEBUG_WX("GET RTS Threshold -> 0x%08X \n", wrqu->rts.value);
7534 static int ipw2100_wx_set_txpow(struct net_device *dev,
7535 struct iw_request_info *info,
7536 union iwreq_data *wrqu, char *extra)
7538 struct ipw2100_priv *priv = ieee80211_priv(dev);
7541 if (priv->ieee->iw_mode != IW_MODE_ADHOC)
7544 if (wrqu->txpower.disabled == 1 || wrqu->txpower.fixed == 0)
7545 value = IPW_TX_POWER_DEFAULT;
7547 if (wrqu->txpower.value < IPW_TX_POWER_MIN_DBM ||
7548 wrqu->txpower.value > IPW_TX_POWER_MAX_DBM)
7551 value = (wrqu->txpower.value - IPW_TX_POWER_MIN_DBM) * 16 /
7552 (IPW_TX_POWER_MAX_DBM - IPW_TX_POWER_MIN_DBM);
7555 down(&priv->action_sem);
7556 if (!(priv->status & STATUS_INITIALIZED)) {
7561 err = ipw2100_set_tx_power(priv, value);
7563 IPW_DEBUG_WX("SET TX Power -> %d \n", value);
7566 up(&priv->action_sem);
7570 static int ipw2100_wx_get_txpow(struct net_device *dev,
7571 struct iw_request_info *info,
7572 union iwreq_data *wrqu, char *extra)
7575 * This can be called at any time. No action lock required
7578 struct ipw2100_priv *priv = ieee80211_priv(dev);
7580 if (priv->ieee->iw_mode != IW_MODE_ADHOC) {
7581 wrqu->power.disabled = 1;
7585 if (priv->tx_power == IPW_TX_POWER_DEFAULT) {
7586 wrqu->power.fixed = 0;
7587 wrqu->power.value = IPW_TX_POWER_MAX_DBM;
7588 wrqu->power.disabled = 1;
7590 wrqu->power.disabled = 0;
7591 wrqu->power.fixed = 1;
7594 (IPW_TX_POWER_MAX_DBM - IPW_TX_POWER_MIN_DBM)) /
7595 (IPW_TX_POWER_MAX - IPW_TX_POWER_MIN) +
7596 IPW_TX_POWER_MIN_DBM;
7599 wrqu->power.flags = IW_TXPOW_DBM;
7601 IPW_DEBUG_WX("GET TX Power -> %d \n", wrqu->power.value);
7606 static int ipw2100_wx_set_frag(struct net_device *dev,
7607 struct iw_request_info *info,
7608 union iwreq_data *wrqu, char *extra)
7611 * This can be called at any time. No action lock required
7614 struct ipw2100_priv *priv = ieee80211_priv(dev);
7616 if (!wrqu->frag.fixed)
7619 if (wrqu->frag.disabled) {
7620 priv->frag_threshold |= FRAG_DISABLED;
7621 priv->ieee->fts = DEFAULT_FTS;
7623 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
7624 wrqu->frag.value > MAX_FRAG_THRESHOLD)
7627 priv->ieee->fts = wrqu->frag.value & ~0x1;
7628 priv->frag_threshold = priv->ieee->fts;
7631 IPW_DEBUG_WX("SET Frag Threshold -> %d \n", priv->ieee->fts);
7636 static int ipw2100_wx_get_frag(struct net_device *dev,
7637 struct iw_request_info *info,
7638 union iwreq_data *wrqu, char *extra)
7641 * This can be called at any time. No action lock required
7644 struct ipw2100_priv *priv = ieee80211_priv(dev);
7645 wrqu->frag.value = priv->frag_threshold & ~FRAG_DISABLED;
7646 wrqu->frag.fixed = 0; /* no auto select */
7647 wrqu->frag.disabled = (priv->frag_threshold & FRAG_DISABLED) ? 1 : 0;
7649 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
7654 static int ipw2100_wx_set_retry(struct net_device *dev,
7655 struct iw_request_info *info,
7656 union iwreq_data *wrqu, char *extra)
7658 struct ipw2100_priv *priv = ieee80211_priv(dev);
7661 if (wrqu->retry.flags & IW_RETRY_LIFETIME ||
7662 wrqu->retry.disabled)
7665 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
7668 down(&priv->action_sem);
7669 if (!(priv->status & STATUS_INITIALIZED)) {
7674 if (wrqu->retry.flags & IW_RETRY_MIN) {
7675 err = ipw2100_set_short_retry(priv, wrqu->retry.value);
7676 IPW_DEBUG_WX("SET Short Retry Limit -> %d \n",
7681 if (wrqu->retry.flags & IW_RETRY_MAX) {
7682 err = ipw2100_set_long_retry(priv, wrqu->retry.value);
7683 IPW_DEBUG_WX("SET Long Retry Limit -> %d \n",
7688 err = ipw2100_set_short_retry(priv, wrqu->retry.value);
7690 err = ipw2100_set_long_retry(priv, wrqu->retry.value);
7692 IPW_DEBUG_WX("SET Both Retry Limits -> %d \n", wrqu->retry.value);
7695 up(&priv->action_sem);
7699 static int ipw2100_wx_get_retry(struct net_device *dev,
7700 struct iw_request_info *info,
7701 union iwreq_data *wrqu, char *extra)
7704 * This can be called at any time. No action lock required
7707 struct ipw2100_priv *priv = ieee80211_priv(dev);
7709 wrqu->retry.disabled = 0; /* can't be disabled */
7711 if ((wrqu->retry.flags & IW_RETRY_TYPE) ==
7715 if (wrqu->retry.flags & IW_RETRY_MAX) {
7716 wrqu->retry.flags = IW_RETRY_LIMIT & IW_RETRY_MAX;
7717 wrqu->retry.value = priv->long_retry_limit;
7720 (priv->short_retry_limit !=
7721 priv->long_retry_limit) ?
7722 IW_RETRY_LIMIT & IW_RETRY_MIN : IW_RETRY_LIMIT;
7724 wrqu->retry.value = priv->short_retry_limit;
7727 IPW_DEBUG_WX("GET Retry -> %d \n", wrqu->retry.value);
7732 static int ipw2100_wx_set_scan(struct net_device *dev,
7733 struct iw_request_info *info,
7734 union iwreq_data *wrqu, char *extra)
7736 struct ipw2100_priv *priv = ieee80211_priv(dev);
7739 down(&priv->action_sem);
7740 if (!(priv->status & STATUS_INITIALIZED)) {
7745 IPW_DEBUG_WX("Initiating scan...\n");
7746 if (ipw2100_set_scan_options(priv) ||
7747 ipw2100_start_scan(priv)) {
7748 IPW_DEBUG_WX("Start scan failed.\n");
7750 /* TODO: Mark a scan as pending so when hardware initialized
7755 up(&priv->action_sem);
7759 static int ipw2100_wx_get_scan(struct net_device *dev,
7760 struct iw_request_info *info,
7761 union iwreq_data *wrqu, char *extra)
7764 * This can be called at any time. No action lock required
7767 struct ipw2100_priv *priv = ieee80211_priv(dev);
7768 return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra);
7773 * Implementation based on code in hostap-driver v0.1.3 hostap_ioctl.c
7775 static int ipw2100_wx_set_encode(struct net_device *dev,
7776 struct iw_request_info *info,
7777 union iwreq_data *wrqu, char *key)
7780 * No check of STATUS_INITIALIZED required
7783 struct ipw2100_priv *priv = ieee80211_priv(dev);
7784 return ieee80211_wx_set_encode(priv->ieee, info, wrqu, key);
7787 static int ipw2100_wx_get_encode(struct net_device *dev,
7788 struct iw_request_info *info,
7789 union iwreq_data *wrqu, char *key)
7792 * This can be called at any time. No action lock required
7795 struct ipw2100_priv *priv = ieee80211_priv(dev);
7796 return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key);
7799 static int ipw2100_wx_set_power(struct net_device *dev,
7800 struct iw_request_info *info,
7801 union iwreq_data *wrqu, char *extra)
7803 struct ipw2100_priv *priv = ieee80211_priv(dev);
7806 down(&priv->action_sem);
7807 if (!(priv->status & STATUS_INITIALIZED)) {
7812 if (wrqu->power.disabled) {
7813 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
7814 err = ipw2100_set_power_mode(priv, IPW_POWER_MODE_CAM);
7815 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
7819 switch (wrqu->power.flags & IW_POWER_MODE) {
7820 case IW_POWER_ON: /* If not specified */
7821 case IW_POWER_MODE: /* If set all mask */
7822 case IW_POWER_ALL_R: /* If explicitely state all */
7824 default: /* Otherwise we don't support it */
7825 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
7831 /* If the user hasn't specified a power management mode yet, default
7833 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
7834 err = ipw2100_set_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
7836 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n",
7840 up(&priv->action_sem);
7845 static int ipw2100_wx_get_power(struct net_device *dev,
7846 struct iw_request_info *info,
7847 union iwreq_data *wrqu, char *extra)
7850 * This can be called at any time. No action lock required
7853 struct ipw2100_priv *priv = ieee80211_priv(dev);
7855 if (!(priv->power_mode & IPW_POWER_ENABLED)) {
7856 wrqu->power.disabled = 1;
7858 wrqu->power.disabled = 0;
7859 wrqu->power.flags = 0;
7862 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
7873 #ifdef CONFIG_IPW2100_MONITOR
7874 static int ipw2100_wx_set_promisc(struct net_device *dev,
7875 struct iw_request_info *info,
7876 union iwreq_data *wrqu, char *extra)
7878 struct ipw2100_priv *priv = ieee80211_priv(dev);
7879 int *parms = (int *)extra;
7880 int enable = (parms[0] > 0);
7883 down(&priv->action_sem);
7884 if (!(priv->status & STATUS_INITIALIZED)) {
7890 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7891 err = ipw2100_set_channel(priv, parms[1], 0);
7894 priv->channel = parms[1];
7895 err = ipw2100_switch_mode(priv, IW_MODE_MONITOR);
7897 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
7898 err = ipw2100_switch_mode(priv, priv->last_mode);
7901 up(&priv->action_sem);
7905 static int ipw2100_wx_reset(struct net_device *dev,
7906 struct iw_request_info *info,
7907 union iwreq_data *wrqu, char *extra)
7909 struct ipw2100_priv *priv = ieee80211_priv(dev);
7910 if (priv->status & STATUS_INITIALIZED)
7911 schedule_reset(priv);
7917 static int ipw2100_wx_set_powermode(struct net_device *dev,
7918 struct iw_request_info *info,
7919 union iwreq_data *wrqu, char *extra)
7921 struct ipw2100_priv *priv = ieee80211_priv(dev);
7922 int err = 0, mode = *(int *)extra;
7924 down(&priv->action_sem);
7925 if (!(priv->status & STATUS_INITIALIZED)) {
7930 if ((mode < 1) || (mode > POWER_MODES))
7931 mode = IPW_POWER_AUTO;
7933 if (priv->power_mode != mode)
7934 err = ipw2100_set_power_mode(priv, mode);
7936 up(&priv->action_sem);
7940 #define MAX_POWER_STRING 80
7941 static int ipw2100_wx_get_powermode(struct net_device *dev,
7942 struct iw_request_info *info,
7943 union iwreq_data *wrqu, char *extra)
7946 * This can be called at any time. No action lock required
7949 struct ipw2100_priv *priv = ieee80211_priv(dev);
7950 int level = IPW_POWER_LEVEL(priv->power_mode);
7951 s32 timeout, period;
7953 if (!(priv->power_mode & IPW_POWER_ENABLED)) {
7954 snprintf(extra, MAX_POWER_STRING,
7955 "Power save level: %d (Off)", level);
7958 case IPW_POWER_MODE_CAM:
7959 snprintf(extra, MAX_POWER_STRING,
7960 "Power save level: %d (None)", level);
7962 case IPW_POWER_AUTO:
7963 snprintf(extra, MAX_POWER_STRING,
7964 "Power save level: %d (Auto)", 0);
7967 timeout = timeout_duration[level - 1] / 1000;
7968 period = period_duration[level - 1] / 1000;
7969 snprintf(extra, MAX_POWER_STRING,
7970 "Power save level: %d "
7971 "(Timeout %dms, Period %dms)",
7972 level, timeout, period);
7976 wrqu->data.length = strlen(extra) + 1;
7982 static int ipw2100_wx_set_preamble(struct net_device *dev,
7983 struct iw_request_info *info,
7984 union iwreq_data *wrqu, char *extra)
7986 struct ipw2100_priv *priv = ieee80211_priv(dev);
7987 int err, mode = *(int *)extra;
7989 down(&priv->action_sem);
7990 if (!(priv->status & STATUS_INITIALIZED)) {
7996 priv->config |= CFG_LONG_PREAMBLE;
7998 priv->config &= ~CFG_LONG_PREAMBLE;
8004 err = ipw2100_system_config(priv, 0);
8007 up(&priv->action_sem);
8011 static int ipw2100_wx_get_preamble(struct net_device *dev,
8012 struct iw_request_info *info,
8013 union iwreq_data *wrqu, char *extra)
8016 * This can be called at any time. No action lock required
8019 struct ipw2100_priv *priv = ieee80211_priv(dev);
8021 if (priv->config & CFG_LONG_PREAMBLE)
8022 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
8024 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
8029 static iw_handler ipw2100_wx_handlers[] =
8031 NULL, /* SIOCSIWCOMMIT */
8032 ipw2100_wx_get_name, /* SIOCGIWNAME */
8033 NULL, /* SIOCSIWNWID */
8034 NULL, /* SIOCGIWNWID */
8035 ipw2100_wx_set_freq, /* SIOCSIWFREQ */
8036 ipw2100_wx_get_freq, /* SIOCGIWFREQ */
8037 ipw2100_wx_set_mode, /* SIOCSIWMODE */
8038 ipw2100_wx_get_mode, /* SIOCGIWMODE */
8039 NULL, /* SIOCSIWSENS */
8040 NULL, /* SIOCGIWSENS */
8041 NULL, /* SIOCSIWRANGE */
8042 ipw2100_wx_get_range, /* SIOCGIWRANGE */
8043 NULL, /* SIOCSIWPRIV */
8044 NULL, /* SIOCGIWPRIV */
8045 NULL, /* SIOCSIWSTATS */
8046 NULL, /* SIOCGIWSTATS */
8047 NULL, /* SIOCSIWSPY */
8048 NULL, /* SIOCGIWSPY */
8049 NULL, /* SIOCGIWTHRSPY */
8050 NULL, /* SIOCWIWTHRSPY */
8051 ipw2100_wx_set_wap, /* SIOCSIWAP */
8052 ipw2100_wx_get_wap, /* SIOCGIWAP */
8053 NULL, /* -- hole -- */
8054 NULL, /* SIOCGIWAPLIST -- depricated */
8055 ipw2100_wx_set_scan, /* SIOCSIWSCAN */
8056 ipw2100_wx_get_scan, /* SIOCGIWSCAN */
8057 ipw2100_wx_set_essid, /* SIOCSIWESSID */
8058 ipw2100_wx_get_essid, /* SIOCGIWESSID */
8059 ipw2100_wx_set_nick, /* SIOCSIWNICKN */
8060 ipw2100_wx_get_nick, /* SIOCGIWNICKN */
8061 NULL, /* -- hole -- */
8062 NULL, /* -- hole -- */
8063 ipw2100_wx_set_rate, /* SIOCSIWRATE */
8064 ipw2100_wx_get_rate, /* SIOCGIWRATE */
8065 ipw2100_wx_set_rts, /* SIOCSIWRTS */
8066 ipw2100_wx_get_rts, /* SIOCGIWRTS */
8067 ipw2100_wx_set_frag, /* SIOCSIWFRAG */
8068 ipw2100_wx_get_frag, /* SIOCGIWFRAG */
8069 ipw2100_wx_set_txpow, /* SIOCSIWTXPOW */
8070 ipw2100_wx_get_txpow, /* SIOCGIWTXPOW */
8071 ipw2100_wx_set_retry, /* SIOCSIWRETRY */
8072 ipw2100_wx_get_retry, /* SIOCGIWRETRY */
8073 ipw2100_wx_set_encode, /* SIOCSIWENCODE */
8074 ipw2100_wx_get_encode, /* SIOCGIWENCODE */
8075 ipw2100_wx_set_power, /* SIOCSIWPOWER */
8076 ipw2100_wx_get_power, /* SIOCGIWPOWER */
8079 #define IPW2100_PRIV_SET_MONITOR SIOCIWFIRSTPRIV
8080 #define IPW2100_PRIV_RESET SIOCIWFIRSTPRIV+1
8081 #define IPW2100_PRIV_SET_POWER SIOCIWFIRSTPRIV+2
8082 #define IPW2100_PRIV_GET_POWER SIOCIWFIRSTPRIV+3
8083 #define IPW2100_PRIV_SET_LONGPREAMBLE SIOCIWFIRSTPRIV+4
8084 #define IPW2100_PRIV_GET_LONGPREAMBLE SIOCIWFIRSTPRIV+5
8086 static const struct iw_priv_args ipw2100_private_args[] = {
8088 #ifdef CONFIG_IPW2100_MONITOR
8090 IPW2100_PRIV_SET_MONITOR,
8091 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"
8095 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"
8097 #endif /* CONFIG_IPW2100_MONITOR */
8100 IPW2100_PRIV_SET_POWER,
8101 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_power"
8104 IPW2100_PRIV_GET_POWER,
8105 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_POWER_STRING, "get_power"
8108 IPW2100_PRIV_SET_LONGPREAMBLE,
8109 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_preamble"
8112 IPW2100_PRIV_GET_LONGPREAMBLE,
8113 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, "get_preamble"
8117 static iw_handler ipw2100_private_handler[] = {
8118 #ifdef CONFIG_IPW2100_MONITOR
8119 ipw2100_wx_set_promisc,
8121 #else /* CONFIG_IPW2100_MONITOR */
8124 #endif /* CONFIG_IPW2100_MONITOR */
8125 ipw2100_wx_set_powermode,
8126 ipw2100_wx_get_powermode,
8127 ipw2100_wx_set_preamble,
8128 ipw2100_wx_get_preamble,
8131 struct iw_handler_def ipw2100_wx_handler_def =
8133 .standard = ipw2100_wx_handlers,
8134 .num_standard = sizeof(ipw2100_wx_handlers) / sizeof(iw_handler),
8135 .num_private = sizeof(ipw2100_private_handler) / sizeof(iw_handler),
8136 .num_private_args = sizeof(ipw2100_private_args) /
8137 sizeof(struct iw_priv_args),
8138 .private = (iw_handler *)ipw2100_private_handler,
8139 .private_args = (struct iw_priv_args *)ipw2100_private_args,
8143 * Get wireless statistics.
8144 * Called by /proc/net/wireless
8145 * Also called by SIOCGIWSTATS
8147 struct iw_statistics *ipw2100_wx_wireless_stats(struct net_device * dev)
8161 struct ipw2100_priv *priv = ieee80211_priv(dev);
8162 struct iw_statistics *wstats;
8163 u32 rssi, quality, tx_retries, missed_beacons, tx_failures;
8164 u32 ord_len = sizeof(u32);
8167 return (struct iw_statistics *) NULL;
8169 wstats = &priv->wstats;
8171 /* if hw is disabled, then ipw2100_get_ordinal() can't be called.
8172 * ipw2100_wx_wireless_stats seems to be called before fw is
8173 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
8174 * and associated; if not associcated, the values are all meaningless
8175 * anyway, so set them all to NULL and INVALID */
8176 if (!(priv->status & STATUS_ASSOCIATED)) {
8177 wstats->miss.beacon = 0;
8178 wstats->discard.retries = 0;
8179 wstats->qual.qual = 0;
8180 wstats->qual.level = 0;
8181 wstats->qual.noise = 0;
8182 wstats->qual.updated = 7;
8183 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
8184 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
8188 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_PERCENT_MISSED_BCNS,
8189 &missed_beacons, &ord_len))
8190 goto fail_get_ordinal;
8192 /* If we don't have a connection the quality and level is 0*/
8193 if (!(priv->status & STATUS_ASSOCIATED)) {
8194 wstats->qual.qual = 0;
8195 wstats->qual.level = 0;
8197 if (ipw2100_get_ordinal(priv, IPW_ORD_RSSI_AVG_CURR,
8199 goto fail_get_ordinal;
8200 wstats->qual.level = rssi + IPW2100_RSSI_TO_DBM;
8202 rssi_qual = rssi * POOR / 10;
8204 rssi_qual = (rssi - 10) * (FAIR - POOR) / 5 + POOR;
8206 rssi_qual = (rssi - 15) * (GOOD - FAIR) / 5 + FAIR;
8208 rssi_qual = (rssi - 20) * (VERY_GOOD - GOOD) /
8211 rssi_qual = (rssi - 30) * (PERFECT - VERY_GOOD) /
8214 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_PERCENT_RETRIES,
8215 &tx_retries, &ord_len))
8216 goto fail_get_ordinal;
8218 if (tx_retries > 75)
8219 tx_qual = (90 - tx_retries) * POOR / 15;
8220 else if (tx_retries > 70)
8221 tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
8222 else if (tx_retries > 65)
8223 tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
8224 else if (tx_retries > 50)
8225 tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
8228 tx_qual = (50 - tx_retries) *
8229 (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
8231 if (missed_beacons > 50)
8232 beacon_qual = (60 - missed_beacons) * POOR / 10;
8233 else if (missed_beacons > 40)
8234 beacon_qual = (50 - missed_beacons) * (FAIR - POOR) /
8236 else if (missed_beacons > 32)
8237 beacon_qual = (40 - missed_beacons) * (GOOD - FAIR) /
8239 else if (missed_beacons > 20)
8240 beacon_qual = (32 - missed_beacons) *
8241 (VERY_GOOD - GOOD) / 20 + GOOD;
8243 beacon_qual = (20 - missed_beacons) *
8244 (PERFECT - VERY_GOOD) / 20 + VERY_GOOD;
8246 quality = min(beacon_qual, min(tx_qual, rssi_qual));
8248 #ifdef CONFIG_IPW_DEBUG
8249 if (beacon_qual == quality)
8250 IPW_DEBUG_WX("Quality clamped by Missed Beacons\n");
8251 else if (tx_qual == quality)
8252 IPW_DEBUG_WX("Quality clamped by Tx Retries\n");
8253 else if (quality != 100)
8254 IPW_DEBUG_WX("Quality clamped by Signal Strength\n");
8256 IPW_DEBUG_WX("Quality not clamped.\n");
8259 wstats->qual.qual = quality;
8260 wstats->qual.level = rssi + IPW2100_RSSI_TO_DBM;
8263 wstats->qual.noise = 0;
8264 wstats->qual.updated = 7;
8265 wstats->qual.updated |= IW_QUAL_NOISE_INVALID;
8267 /* FIXME: this is percent and not a # */
8268 wstats->miss.beacon = missed_beacons;
8270 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURES,
8271 &tx_failures, &ord_len))
8272 goto fail_get_ordinal;
8273 wstats->discard.retries = tx_failures;
8278 IPW_DEBUG_WX("failed querying ordinals.\n");
8280 return (struct iw_statistics *) NULL;
8283 void ipw2100_wx_event_work(struct ipw2100_priv *priv)
8285 union iwreq_data wrqu;
8288 if (priv->status & STATUS_STOPPING)
8291 down(&priv->action_sem);
8293 IPW_DEBUG_WX("enter\n");
8295 up(&priv->action_sem);
8297 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
8299 /* Fetch BSSID from the hardware */
8300 if (!(priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) ||
8301 priv->status & STATUS_RF_KILL_MASK ||
8302 ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID,
8303 &priv->bssid, &len)) {
8304 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
8306 /* We now have the BSSID, so can finish setting to the full
8307 * associated state */
8308 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
8309 memcpy(&priv->ieee->bssid, priv->bssid, ETH_ALEN);
8310 priv->status &= ~STATUS_ASSOCIATING;
8311 priv->status |= STATUS_ASSOCIATED;
8312 netif_carrier_on(priv->net_dev);
8313 if (netif_queue_stopped(priv->net_dev)) {
8314 IPW_DEBUG_INFO("Waking net queue.\n");
8315 netif_wake_queue(priv->net_dev);
8317 IPW_DEBUG_INFO("Starting net queue.\n");
8318 netif_start_queue(priv->net_dev);
8322 if (!(priv->status & STATUS_ASSOCIATED)) {
8323 IPW_DEBUG_WX("Configuring ESSID\n");
8324 down(&priv->action_sem);
8325 /* This is a disassociation event, so kick the firmware to
8326 * look for another AP */
8327 if (priv->config & CFG_STATIC_ESSID)
8328 ipw2100_set_essid(priv, priv->essid, priv->essid_len, 0);
8330 ipw2100_set_essid(priv, NULL, 0, 0);
8331 up(&priv->action_sem);
8334 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
8337 #define IPW2100_FW_MAJOR_VERSION 1
8338 #define IPW2100_FW_MINOR_VERSION 3
8340 #define IPW2100_FW_MINOR(x) ((x & 0xff) >> 8)
8341 #define IPW2100_FW_MAJOR(x) (x & 0xff)
8343 #define IPW2100_FW_VERSION ((IPW2100_FW_MINOR_VERSION << 8) | \
8344 IPW2100_FW_MAJOR_VERSION)
8346 #define IPW2100_FW_PREFIX "ipw2100-" __stringify(IPW2100_FW_MAJOR_VERSION) \
8347 "." __stringify(IPW2100_FW_MINOR_VERSION)
8349 #define IPW2100_FW_NAME(x) IPW2100_FW_PREFIX "" x ".fw"
8354 BINARY FIRMWARE HEADER FORMAT
8358 2 2 mode == 0:BSS,1:IBSS,2:MONITOR
8361 C fw_len firmware data
8362 12 + fw_len uc_len microcode data
8366 struct ipw2100_fw_header {
8369 unsigned int fw_size;
8370 unsigned int uc_size;
8371 } __attribute__ ((packed));
8375 static int ipw2100_mod_firmware_load(struct ipw2100_fw *fw)
8377 struct ipw2100_fw_header *h =
8378 (struct ipw2100_fw_header *)fw->fw_entry->data;
8380 if (IPW2100_FW_MAJOR(h->version) != IPW2100_FW_MAJOR_VERSION) {
8381 IPW_DEBUG_WARNING("Firmware image not compatible "
8382 "(detected version id of %u). "
8383 "See Documentation/networking/README.ipw2100\n",
8388 fw->version = h->version;
8389 fw->fw.data = fw->fw_entry->data + sizeof(struct ipw2100_fw_header);
8390 fw->fw.size = h->fw_size;
8391 fw->uc.data = fw->fw.data + h->fw_size;
8392 fw->uc.size = h->uc_size;
8398 int ipw2100_get_firmware(struct ipw2100_priv *priv, struct ipw2100_fw *fw)
8403 IPW_DEBUG_INFO("%s: Using hotplug firmware load.\n",
8404 priv->net_dev->name);
8406 switch (priv->ieee->iw_mode) {
8408 fw_name = IPW2100_FW_NAME("-i");
8410 #ifdef CONFIG_IPW2100_MONITOR
8411 case IW_MODE_MONITOR:
8412 fw_name = IPW2100_FW_NAME("-p");
8417 fw_name = IPW2100_FW_NAME("");
8421 rc = request_firmware(&fw->fw_entry, fw_name, &priv->pci_dev->dev);
8425 "%s: Firmware '%s' not available or load failed.\n",
8426 priv->net_dev->name, fw_name);
8429 IPW_DEBUG_INFO("firmware data %p size %zd\n", fw->fw_entry->data,
8430 fw->fw_entry->size);
8432 ipw2100_mod_firmware_load(fw);
8437 void ipw2100_release_firmware(struct ipw2100_priv *priv,
8438 struct ipw2100_fw *fw)
8442 release_firmware(fw->fw_entry);
8443 fw->fw_entry = NULL;
8447 int ipw2100_get_fwversion(struct ipw2100_priv *priv, char *buf, size_t max)
8449 char ver[MAX_FW_VERSION_LEN];
8450 u32 len = MAX_FW_VERSION_LEN;
8453 /* firmware version is an ascii string (max len of 14) */
8454 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_FW_VER_NUM,
8460 for (i = 0; i < len; i++)
8466 int ipw2100_get_ucodeversion(struct ipw2100_priv *priv, char *buf, size_t max)
8469 u32 len = sizeof(ver);
8470 /* microcode version is a 32 bit integer */
8471 if (ipw2100_get_ordinal(priv, IPW_ORD_UCODE_VERSION,
8474 return snprintf(buf, max, "%08X", ver);
8478 * On exit, the firmware will have been freed from the fw list
8480 int ipw2100_fw_download(struct ipw2100_priv *priv, struct ipw2100_fw *fw)
8482 /* firmware is constructed of N contiguous entries, each entry is
8486 * 0 4 address to write to
8487 * 4 2 length of data run
8493 const unsigned char *firmware_data = fw->fw.data;
8494 unsigned int firmware_data_left = fw->fw.size;
8496 while (firmware_data_left > 0) {
8497 addr = *(u32 *)(firmware_data);
8499 firmware_data_left -= 4;
8501 len = *(u16 *)(firmware_data);
8503 firmware_data_left -= 2;
8507 "Invalid firmware run-length of %d bytes\n",
8512 write_nic_memory(priv->net_dev, addr, len, firmware_data);
8513 firmware_data += len;
8514 firmware_data_left -= len;
8520 struct symbol_alive_response {
8529 u16 clock_settle_time; // 1us LSB
8530 u16 powerup_settle_time; // 1us LSB
8531 u16 hop_settle_time; // 1us LSB
8532 u8 date[3]; // month, day, year
8533 u8 time[2]; // hours, minutes
8537 int ipw2100_ucode_download(struct ipw2100_priv *priv, struct ipw2100_fw *fw)
8539 struct net_device *dev = priv->net_dev;
8540 const unsigned char *microcode_data = fw->uc.data;
8541 unsigned int microcode_data_left = fw->uc.size;
8543 struct symbol_alive_response response;
8547 /* Symbol control */
8548 write_nic_word(dev, IPW2100_CONTROL_REG, 0x703);
8549 readl((void *)(dev->base_addr));
8550 write_nic_word(dev, IPW2100_CONTROL_REG, 0x707);
8551 readl((void *)(dev->base_addr));
8554 write_nic_byte(dev, 0x210014, 0x72); /* fifo width =16 */
8555 readl((void *)(dev->base_addr));
8556 write_nic_byte(dev, 0x210014, 0x72); /* fifo width =16 */
8557 readl((void *)(dev->base_addr));
8559 /* EN_CS_ACCESS bit to reset control store pointer */
8560 write_nic_byte(dev, 0x210000, 0x40);
8561 readl((void *)(dev->base_addr));
8562 write_nic_byte(dev, 0x210000, 0x0);
8563 readl((void *)(dev->base_addr));
8564 write_nic_byte(dev, 0x210000, 0x40);
8565 readl((void *)(dev->base_addr));
8567 /* copy microcode from buffer into Symbol */
8569 while (microcode_data_left > 0) {
8570 write_nic_byte(dev, 0x210010, *microcode_data++);
8571 write_nic_byte(dev, 0x210010, *microcode_data++);
8572 microcode_data_left -= 2;
8575 /* EN_CS_ACCESS bit to reset the control store pointer */
8576 write_nic_byte(dev, 0x210000, 0x0);
8577 readl((void *)(dev->base_addr));
8579 /* Enable System (Reg 0)
8580 * first enable causes garbage in RX FIFO */
8581 write_nic_byte(dev, 0x210000, 0x0);
8582 readl((void *)(dev->base_addr));
8583 write_nic_byte(dev, 0x210000, 0x80);
8584 readl((void *)(dev->base_addr));
8586 /* Reset External Baseband Reg */
8587 write_nic_word(dev, IPW2100_CONTROL_REG, 0x703);
8588 readl((void *)(dev->base_addr));
8589 write_nic_word(dev, IPW2100_CONTROL_REG, 0x707);
8590 readl((void *)(dev->base_addr));
8592 /* HW Config (Reg 5) */
8593 write_nic_byte(dev, 0x210014, 0x72); // fifo width =16
8594 readl((void *)(dev->base_addr));
8595 write_nic_byte(dev, 0x210014, 0x72); // fifo width =16
8596 readl((void *)(dev->base_addr));
8598 /* Enable System (Reg 0)
8599 * second enable should be OK */
8600 write_nic_byte(dev, 0x210000, 0x00); // clear enable system
8601 readl((void *)(dev->base_addr));
8602 write_nic_byte(dev, 0x210000, 0x80); // set enable system
8604 /* check Symbol is enabled - upped this from 5 as it wasn't always
8605 * catching the update */
8606 for (i = 0; i < 10; i++) {
8609 /* check Dino is enabled bit */
8610 read_nic_byte(dev, 0x210000, &data);
8616 IPW_DEBUG_ERROR("%s: Error initializing Symbol\n",
8621 /* Get Symbol alive response */
8622 for (i = 0; i < 30; i++) {
8623 /* Read alive response structure */
8625 j < (sizeof(struct symbol_alive_response) >> 1);
8627 read_nic_word(dev, 0x210004,
8628 ((u16 *)&response) + j);
8630 if ((response.cmd_id == 1) &&
8631 (response.ucode_valid == 0x1))
8637 IPW_DEBUG_ERROR("%s: No response from Symbol - hw not alive\n",
8639 printk_buf(IPW_DL_ERROR, (u8*)&response, sizeof(response));