1 /******************************************************************************
3 Copyright(c) 2003 - 2005 Intel Corporation. All rights reserved.
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of version 2 of the GNU General Public License as
7 published by the Free Software Foundation.
9 This program is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 You should have received a copy of the GNU General Public License along with
15 this program; if not, write to the Free Software Foundation, Inc., 59
16 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 The full GNU General Public License is included in this distribution in the
22 James P. Ketrenos <ipw2100-admin@linux.intel.com>
23 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25 Portions of this file are based on the sample_* files provided by Wireless
26 Extensions 0.26 package and copyright (c) 1997-2003 Jean Tourrilhes
29 Portions of this file are based on the Host AP project,
30 Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
32 Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
34 Portions of ipw2100_mod_firmware_load, ipw2100_do_mod_firmware_load, and
35 ipw2100_fw_load are loosely based on drivers/sound/sound_firmware.c
36 available in the 2.4.25 kernel sources, and are copyright (c) Alan Cox
38 ******************************************************************************/
41 Initial driver on which this is based was developed by Janusz Gorycki,
42 Maciej Urbaniak, and Maciej Sosnowski.
44 Promiscuous mode support added by Jacek Wysoczynski and Maciej Urbaniak.
48 Tx - Commands and Data
50 Firmware and host share a circular queue of Transmit Buffer Descriptors (TBDs)
51 Each TBD contains a pointer to the physical (dma_addr_t) address of data being
52 sent to the firmware as well as the length of the data.
54 The host writes to the TBD queue at the WRITE index. The WRITE index points
55 to the _next_ packet to be written and is advanced when after the TBD has been
58 The firmware pulls from the TBD queue at the READ index. The READ index points
59 to the currently being read entry, and is advanced once the firmware is
62 When data is sent to the firmware, the first TBD is used to indicate to the
63 firmware if a Command or Data is being sent. If it is Command, all of the
64 command information is contained within the physical address referred to by the
65 TBD. If it is Data, the first TBD indicates the type of data packet, number
66 of fragments, etc. The next TBD then referrs to the actual packet location.
68 The Tx flow cycle is as follows:
70 1) ipw2100_tx() is called by kernel with SKB to transmit
71 2) Packet is move from the tx_free_list and appended to the transmit pending
73 3) work is scheduled to move pending packets into the shared circular queue.
74 4) when placing packet in the circular queue, the incoming SKB is DMA mapped
75 to a physical address. That address is entered into a TBD. Two TBDs are
76 filled out. The first indicating a data packet, the second referring to the
78 5) the packet is removed from tx_pend_list and placed on the end of the
79 firmware pending list (fw_pend_list)
80 6) firmware is notified that the WRITE index has
81 7) Once the firmware has processed the TBD, INTA is triggered.
82 8) For each Tx interrupt received from the firmware, the READ index is checked
83 to see which TBDs are done being processed.
84 9) For each TBD that has been processed, the ISR pulls the oldest packet
85 from the fw_pend_list.
86 10)The packet structure contained in the fw_pend_list is then used
87 to unmap the DMA address and to free the SKB originally passed to the driver
89 11)The packet structure is placed onto the tx_free_list
91 The above steps are the same for commands, only the msg_free_list/msg_pend_list
92 are used instead of tx_free_list/tx_pend_list
96 Critical Sections / Locking :
98 There are two locks utilized. The first is the low level lock (priv->low_lock)
99 that protects the following:
101 - Access to the Tx/Rx queue lists via priv->low_lock. The lists are as follows:
103 tx_free_list : Holds pre-allocated Tx buffers.
104 TAIL modified in __ipw2100_tx_process()
105 HEAD modified in ipw2100_tx()
107 tx_pend_list : Holds used Tx buffers waiting to go into the TBD ring
108 TAIL modified ipw2100_tx()
109 HEAD modified by ipw2100_tx_send_data()
111 msg_free_list : Holds pre-allocated Msg (Command) buffers
112 TAIL modified in __ipw2100_tx_process()
113 HEAD modified in ipw2100_hw_send_command()
115 msg_pend_list : Holds used Msg buffers waiting to go into the TBD ring
116 TAIL modified in ipw2100_hw_send_command()
117 HEAD modified in ipw2100_tx_send_commands()
119 The flow of data on the TX side is as follows:
121 MSG_FREE_LIST + COMMAND => MSG_PEND_LIST => TBD => MSG_FREE_LIST
122 TX_FREE_LIST + DATA => TX_PEND_LIST => TBD => TX_FREE_LIST
124 The methods that work on the TBD ring are protected via priv->low_lock.
126 - The internal data state of the device itself
127 - Access to the firmware read/write indexes for the BD queues
130 All external entry functions are locked with the priv->action_lock to ensure
131 that only one external action is invoked at a time.
136 #include <linux/compiler.h>
137 #include <linux/config.h>
138 #include <linux/errno.h>
139 #include <linux/if_arp.h>
140 #include <linux/in6.h>
141 #include <linux/in.h>
142 #include <linux/ip.h>
143 #include <linux/kernel.h>
144 #include <linux/kmod.h>
145 #include <linux/module.h>
146 #include <linux/netdevice.h>
147 #include <linux/ethtool.h>
148 #include <linux/pci.h>
149 #include <linux/dma-mapping.h>
150 #include <linux/proc_fs.h>
151 #include <linux/skbuff.h>
152 #include <asm/uaccess.h>
154 #define __KERNEL_SYSCALLS__
155 #include <linux/fs.h>
156 #include <linux/mm.h>
157 #include <linux/slab.h>
158 #include <linux/unistd.h>
159 #include <linux/stringify.h>
160 #include <linux/tcp.h>
161 #include <linux/types.h>
162 #include <linux/version.h>
163 #include <linux/time.h>
164 #include <linux/firmware.h>
165 #include <linux/acpi.h>
166 #include <linux/ctype.h>
170 #define IPW2100_VERSION "1.1.0"
172 #define DRV_NAME "ipw2100"
173 #define DRV_VERSION IPW2100_VERSION
174 #define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2100 Network Driver"
175 #define DRV_COPYRIGHT "Copyright(c) 2003-2004 Intel Corporation"
178 /* Debugging stuff */
179 #ifdef CONFIG_IPW_DEBUG
180 #define CONFIG_IPW2100_RX_DEBUG /* Reception debugging */
183 MODULE_DESCRIPTION(DRV_DESCRIPTION);
184 MODULE_VERSION(DRV_VERSION);
185 MODULE_AUTHOR(DRV_COPYRIGHT);
186 MODULE_LICENSE("GPL");
188 static int debug = 0;
190 static int channel = 0;
191 static int associate = 1;
192 static int disable = 0;
194 static struct ipw2100_fw ipw2100_firmware;
197 #include <linux/moduleparam.h>
198 module_param(debug, int, 0444);
199 module_param(mode, int, 0444);
200 module_param(channel, int, 0444);
201 module_param(associate, int, 0444);
202 module_param(disable, int, 0444);
204 MODULE_PARM_DESC(debug, "debug level");
205 MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
206 MODULE_PARM_DESC(channel, "channel");
207 MODULE_PARM_DESC(associate, "auto associate when scanning (default on)");
208 MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
210 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 ipw2100_tx_send_commands(struct ipw2100_priv *priv);
291 static void 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 ipw2100_tx_send_commands(priv);
740 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_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
1120 unsigned short value = 0;
1124 if (!(priv->hw_features & HW_FEATURE_RFKILL)) {
1125 priv->status &= ~STATUS_RF_KILL_HW;
1129 for (i = 0; i < MAX_RF_KILL_CHECKS; i++) {
1130 udelay(RF_KILL_CHECK_DELAY);
1131 read_register(priv->net_dev, IPW_REG_GPIO, ®);
1132 value = (value << 1) | ((reg & IPW_BIT_GPIO_RF_KILL) ? 0 : 1);
1136 priv->status |= STATUS_RF_KILL_HW;
1138 priv->status &= ~STATUS_RF_KILL_HW;
1140 return (value == 0);
1143 static int ipw2100_get_hw_features(struct ipw2100_priv *priv)
1149 * EEPROM_SRAM_DB_START_ADDRESS using ordinal in ordinal table 1
1152 if (ipw2100_get_ordinal(
1153 priv, IPW_ORD_EEPROM_SRAM_DB_BLOCK_START_ADDRESS,
1155 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
1160 IPW_DEBUG_INFO("EEPROM address: %08X\n", addr);
1163 * EEPROM version is the byte at offset 0xfd in firmware
1164 * We read 4 bytes, then shift out the byte we actually want */
1165 read_nic_dword(priv->net_dev, addr + 0xFC, &val);
1166 priv->eeprom_version = (val >> 24) & 0xFF;
1167 IPW_DEBUG_INFO("EEPROM version: %d\n", priv->eeprom_version);
1170 * HW RF Kill enable is bit 0 in byte at offset 0x21 in firmware
1172 * notice that the EEPROM bit is reverse polarity, i.e.
1173 * bit = 0 signifies HW RF kill switch is supported
1174 * bit = 1 signifies HW RF kill switch is NOT supported
1176 read_nic_dword(priv->net_dev, addr + 0x20, &val);
1177 if (!((val >> 24) & 0x01))
1178 priv->hw_features |= HW_FEATURE_RFKILL;
1180 IPW_DEBUG_INFO("HW RF Kill: %ssupported.\n",
1181 (priv->hw_features & HW_FEATURE_RFKILL) ?
1188 * Start firmware execution after power on and intialization
1191 * 2. Wait for f/w initialization completes;
1193 static int ipw2100_start_adapter(struct ipw2100_priv *priv)
1196 u32 inta, inta_mask, gpio;
1198 IPW_DEBUG_INFO("enter\n");
1200 if (priv->status & STATUS_RUNNING)
1204 * Initialize the hw - drive adapter to DO state by setting
1205 * init_done bit. Wait for clk_ready bit and Download
1208 if (ipw2100_download_firmware(priv)) {
1209 IPW_DEBUG_ERROR("%s: Failed to power on the adapter.\n",
1210 priv->net_dev->name);
1214 /* Clear the Tx, Rx and Msg queues and the r/w indexes
1215 * in the firmware RBD and TBD ring queue */
1216 ipw2100_queues_initialize(priv);
1218 ipw2100_hw_set_gpio(priv);
1220 /* TODO -- Look at disabling interrupts here to make sure none
1221 * get fired during FW initialization */
1223 /* Release ARC - clear reset bit */
1224 write_register(priv->net_dev, IPW_REG_RESET_REG, 0);
1226 /* wait for f/w intialization complete */
1227 IPW_DEBUG_FW("Waiting for f/w initialization to complete...\n");
1230 set_current_state(TASK_UNINTERRUPTIBLE);
1231 schedule_timeout(40 * HZ / 1000);
1232 /* Todo... wait for sync command ... */
1234 read_register(priv->net_dev, IPW_REG_INTA, &inta);
1236 /* check "init done" bit */
1237 if (inta & IPW2100_INTA_FW_INIT_DONE) {
1238 /* reset "init done" bit */
1239 write_register(priv->net_dev, IPW_REG_INTA,
1240 IPW2100_INTA_FW_INIT_DONE);
1244 /* check error conditions : we check these after the firmware
1245 * check so that if there is an error, the interrupt handler
1246 * will see it and the adapter will be reset */
1248 (IPW2100_INTA_FATAL_ERROR | IPW2100_INTA_PARITY_ERROR)) {
1249 /* clear error conditions */
1250 write_register(priv->net_dev, IPW_REG_INTA,
1251 IPW2100_INTA_FATAL_ERROR |
1252 IPW2100_INTA_PARITY_ERROR);
1256 /* Clear out any pending INTAs since we aren't supposed to have
1257 * interrupts enabled at this point... */
1258 read_register(priv->net_dev, IPW_REG_INTA, &inta);
1259 read_register(priv->net_dev, IPW_REG_INTA_MASK, &inta_mask);
1260 inta &= IPW_INTERRUPT_MASK;
1261 /* Clear out any pending interrupts */
1262 if (inta & inta_mask)
1263 write_register(priv->net_dev, IPW_REG_INTA, inta);
1265 IPW_DEBUG_FW("f/w initialization complete: %s\n",
1266 i ? "SUCCESS" : "FAILED");
1269 IPW_DEBUG_WARNING("%s: Firmware did not initialize.\n",
1270 priv->net_dev->name);
1274 /* allow firmware to write to GPIO1 & GPIO3 */
1275 read_register(priv->net_dev, IPW_REG_GPIO, &gpio);
1277 gpio |= (IPW_BIT_GPIO_GPIO1_MASK | IPW_BIT_GPIO_GPIO3_MASK);
1279 write_register(priv->net_dev, IPW_REG_GPIO, gpio);
1281 /* Ready to receive commands */
1282 priv->status |= STATUS_RUNNING;
1284 /* The adapter has been reset; we are not associated */
1285 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
1287 IPW_DEBUG_INFO("exit\n");
1292 static inline void ipw2100_reset_fatalerror(struct ipw2100_priv *priv)
1294 if (!priv->fatal_error)
1297 priv->fatal_errors[priv->fatal_index++] = priv->fatal_error;
1298 priv->fatal_index %= IPW2100_ERROR_QUEUE;
1299 priv->fatal_error = 0;
1303 /* NOTE: Our interrupt is disabled when this method is called */
1304 static int ipw2100_power_cycle_adapter(struct ipw2100_priv *priv)
1309 IPW_DEBUG_INFO("Power cycling the hardware.\n");
1311 ipw2100_hw_set_gpio(priv);
1313 /* Step 1. Stop Master Assert */
1314 write_register(priv->net_dev, IPW_REG_RESET_REG,
1315 IPW_AUX_HOST_RESET_REG_STOP_MASTER);
1317 /* Step 2. Wait for stop Master Assert
1318 * (not more then 50us, otherwise ret error */
1321 udelay(IPW_WAIT_RESET_MASTER_ASSERT_COMPLETE_DELAY);
1322 read_register(priv->net_dev, IPW_REG_RESET_REG, ®);
1324 if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED)
1328 priv->status &= ~STATUS_RESET_PENDING;
1331 IPW_DEBUG_INFO("exit - waited too long for master assert stop\n");
1335 write_register(priv->net_dev, IPW_REG_RESET_REG,
1336 IPW_AUX_HOST_RESET_REG_SW_RESET);
1339 /* Reset any fatal_error conditions */
1340 ipw2100_reset_fatalerror(priv);
1342 /* At this point, the adapter is now stopped and disabled */
1343 priv->status &= ~(STATUS_RUNNING | STATUS_ASSOCIATING |
1344 STATUS_ASSOCIATED | STATUS_ENABLED);
1350 * Send the CARD_DISABLE_PHY_OFF comamnd to the card to disable it
1352 * After disabling, if the card was associated, a STATUS_ASSN_LOST will be sent.
1354 * STATUS_CARD_DISABLE_NOTIFICATION will be sent regardless of
1355 * if STATUS_ASSN_LOST is sent.
1357 static int ipw2100_hw_phy_off(struct ipw2100_priv *priv)
1360 #define HW_PHY_OFF_LOOP_DELAY (HZ / 5000)
1362 struct host_command cmd = {
1363 .host_command = CARD_DISABLE_PHY_OFF,
1364 .host_command_sequence = 0,
1365 .host_command_length = 0,
1370 IPW_DEBUG_HC("CARD_DISABLE_PHY_OFF\n");
1372 /* Turn off the radio */
1373 err = ipw2100_hw_send_command(priv, &cmd);
1377 for (i = 0; i < 2500; i++) {
1378 read_nic_dword(priv->net_dev, IPW2100_CONTROL_REG, &val1);
1379 read_nic_dword(priv->net_dev, IPW2100_COMMAND, &val2);
1381 if ((val1 & IPW2100_CONTROL_PHY_OFF) &&
1382 (val2 & IPW2100_COMMAND_PHY_OFF))
1385 set_current_state(TASK_UNINTERRUPTIBLE);
1386 schedule_timeout(HW_PHY_OFF_LOOP_DELAY);
1393 static int ipw2100_enable_adapter(struct ipw2100_priv *priv)
1395 struct host_command cmd = {
1396 .host_command = HOST_COMPLETE,
1397 .host_command_sequence = 0,
1398 .host_command_length = 0
1402 IPW_DEBUG_HC("HOST_COMPLETE\n");
1404 if (priv->status & STATUS_ENABLED)
1407 down(&priv->adapter_sem);
1409 if (rf_kill_active(priv)) {
1410 IPW_DEBUG_HC("Command aborted due to RF kill active.\n");
1414 err = ipw2100_hw_send_command(priv, &cmd);
1416 IPW_DEBUG_INFO("Failed to send HOST_COMPLETE command\n");
1420 err = ipw2100_wait_for_card_state(priv, IPW_HW_STATE_ENABLED);
1423 "%s: card not responding to init command.\n",
1424 priv->net_dev->name);
1428 if (priv->stop_hang_check) {
1429 priv->stop_hang_check = 0;
1430 queue_delayed_work(priv->workqueue, &priv->hang_check, HZ / 2);
1434 up(&priv->adapter_sem);
1438 static int ipw2100_hw_stop_adapter(struct ipw2100_priv *priv)
1440 #define HW_POWER_DOWN_DELAY (HZ / 10)
1442 struct host_command cmd = {
1443 .host_command = HOST_PRE_POWER_DOWN,
1444 .host_command_sequence = 0,
1445 .host_command_length = 0,
1450 if (!(priv->status & STATUS_RUNNING))
1453 priv->status |= STATUS_STOPPING;
1455 /* We can only shut down the card if the firmware is operational. So,
1456 * if we haven't reset since a fatal_error, then we can not send the
1457 * shutdown commands. */
1458 if (!priv->fatal_error) {
1459 /* First, make sure the adapter is enabled so that the PHY_OFF
1460 * command can shut it down */
1461 ipw2100_enable_adapter(priv);
1463 err = ipw2100_hw_phy_off(priv);
1465 IPW_DEBUG_WARNING("Error disabling radio %d\n", err);
1468 * If in D0-standby mode going directly to D3 may cause a
1469 * PCI bus violation. Therefore we must change out of the D0
1472 * Sending the PREPARE_FOR_POWER_DOWN will restrict the
1473 * hardware from going into standby mode and will transition
1474 * out of D0-standy if it is already in that state.
1476 * STATUS_PREPARE_POWER_DOWN_COMPLETE will be sent by the
1477 * driver upon completion. Once received, the driver can
1478 * proceed to the D3 state.
1480 * Prepare for power down command to fw. This command would
1481 * take HW out of D0-standby and prepare it for D3 state.
1483 * Currently FW does not support event notification for this
1484 * event. Therefore, skip waiting for it. Just wait a fixed
1487 IPW_DEBUG_HC("HOST_PRE_POWER_DOWN\n");
1489 err = ipw2100_hw_send_command(priv, &cmd);
1492 "%s: Power down command failed: Error %d\n",
1493 priv->net_dev->name, err);
1495 set_current_state(TASK_UNINTERRUPTIBLE);
1496 schedule_timeout(HW_POWER_DOWN_DELAY);
1500 priv->status &= ~STATUS_ENABLED;
1503 * Set GPIO 3 writable by FW; GPIO 1 writable
1504 * by driver and enable clock
1506 ipw2100_hw_set_gpio(priv);
1509 * Power down adapter. Sequence:
1510 * 1. Stop master assert (RESET_REG[9]=1)
1511 * 2. Wait for stop master (RESET_REG[8]==1)
1512 * 3. S/w reset assert (RESET_REG[7] = 1)
1515 /* Stop master assert */
1516 write_register(priv->net_dev, IPW_REG_RESET_REG,
1517 IPW_AUX_HOST_RESET_REG_STOP_MASTER);
1519 /* wait stop master not more than 50 usec.
1520 * Otherwise return error. */
1521 for (i = 5; i > 0; i--) {
1524 /* Check master stop bit */
1525 read_register(priv->net_dev, IPW_REG_RESET_REG, ®);
1527 if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED)
1532 IPW_DEBUG_WARNING(DRV_NAME
1533 ": %s: Could now power down adapter.\n",
1534 priv->net_dev->name);
1536 /* assert s/w reset */
1537 write_register(priv->net_dev, IPW_REG_RESET_REG,
1538 IPW_AUX_HOST_RESET_REG_SW_RESET);
1540 priv->status &= ~(STATUS_RUNNING | STATUS_STOPPING);
1546 static int ipw2100_disable_adapter(struct ipw2100_priv *priv)
1548 struct host_command cmd = {
1549 .host_command = CARD_DISABLE,
1550 .host_command_sequence = 0,
1551 .host_command_length = 0
1555 IPW_DEBUG_HC("CARD_DISABLE\n");
1557 if (!(priv->status & STATUS_ENABLED))
1560 /* Make sure we clear the associated state */
1561 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1563 if (!priv->stop_hang_check) {
1564 priv->stop_hang_check = 1;
1565 cancel_delayed_work(&priv->hang_check);
1568 down(&priv->adapter_sem);
1570 err = ipw2100_hw_send_command(priv, &cmd);
1572 IPW_DEBUG_WARNING("exit - failed to send CARD_DISABLE command\n");
1576 err = ipw2100_wait_for_card_state(priv, IPW_HW_STATE_DISABLED);
1578 IPW_DEBUG_WARNING("exit - card failed to change to DISABLED\n");
1582 IPW_DEBUG_INFO("TODO: implement scan state machine\n");
1585 up(&priv->adapter_sem);
1589 int ipw2100_set_scan_options(struct ipw2100_priv *priv)
1591 struct host_command cmd = {
1592 .host_command = SET_SCAN_OPTIONS,
1593 .host_command_sequence = 0,
1594 .host_command_length = 8
1598 IPW_DEBUG_INFO("enter\n");
1600 IPW_DEBUG_SCAN("setting scan options\n");
1602 cmd.host_command_parameters[0] = 0;
1604 if (!(priv->config & CFG_ASSOCIATE))
1605 cmd.host_command_parameters[0] |= IPW_SCAN_NOASSOCIATE;
1606 if ((priv->sec.flags & SEC_ENABLED) && priv->sec.enabled)
1607 cmd.host_command_parameters[0] |= IPW_SCAN_MIXED_CELL;
1608 if (priv->config & CFG_PASSIVE_SCAN)
1609 cmd.host_command_parameters[0] |= IPW_SCAN_PASSIVE;
1611 cmd.host_command_parameters[1] = priv->channel_mask;
1613 err = ipw2100_hw_send_command(priv, &cmd);
1615 IPW_DEBUG_HC("SET_SCAN_OPTIONS 0x%04X\n",
1616 cmd.host_command_parameters[0]);
1621 int ipw2100_start_scan(struct ipw2100_priv *priv)
1623 struct host_command cmd = {
1624 .host_command = BROADCAST_SCAN,
1625 .host_command_sequence = 0,
1626 .host_command_length = 4
1630 IPW_DEBUG_HC("START_SCAN\n");
1632 cmd.host_command_parameters[0] = 0;
1634 /* No scanning if in monitor mode */
1635 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
1638 if (priv->status & STATUS_SCANNING) {
1639 IPW_DEBUG_SCAN("Scan requested while already in scan...\n");
1643 IPW_DEBUG_INFO("enter\n");
1645 /* Not clearing here; doing so makes iwlist always return nothing...
1647 * We should modify the table logic to use aging tables vs. clearing
1648 * the table on each scan start.
1650 IPW_DEBUG_SCAN("starting scan\n");
1652 priv->status |= STATUS_SCANNING;
1653 err = ipw2100_hw_send_command(priv, &cmd);
1655 priv->status &= ~STATUS_SCANNING;
1657 IPW_DEBUG_INFO("exit\n");
1662 static int ipw2100_up(struct ipw2100_priv *priv, int deferred)
1664 unsigned long flags;
1667 u32 ord_len = sizeof(lock);
1669 /* Quite if manually disabled. */
1670 if (priv->status & STATUS_RF_KILL_SW) {
1671 IPW_DEBUG_INFO("%s: Radio is disabled by Manual Disable "
1672 "switch\n", priv->net_dev->name);
1676 /* If the interrupt is enabled, turn it off... */
1677 spin_lock_irqsave(&priv->low_lock, flags);
1678 ipw2100_disable_interrupts(priv);
1680 /* Reset any fatal_error conditions */
1681 ipw2100_reset_fatalerror(priv);
1682 spin_unlock_irqrestore(&priv->low_lock, flags);
1684 if (priv->status & STATUS_POWERED ||
1685 (priv->status & STATUS_RESET_PENDING)) {
1686 /* Power cycle the card ... */
1687 if (ipw2100_power_cycle_adapter(priv)) {
1688 IPW_DEBUG_WARNING("%s: Could not cycle adapter.\n",
1689 priv->net_dev->name);
1694 priv->status |= STATUS_POWERED;
1696 /* Load the firmware, start the clocks, etc. */
1697 if (ipw2100_start_adapter(priv)) {
1698 IPW_DEBUG_ERROR("%s: Failed to start the firmware.\n",
1699 priv->net_dev->name);
1704 ipw2100_initialize_ordinals(priv);
1706 /* Determine capabilities of this particular HW configuration */
1707 if (ipw2100_get_hw_features(priv)) {
1708 IPW_DEBUG_ERROR("%s: Failed to determine HW features.\n",
1709 priv->net_dev->name);
1715 if (ipw2100_set_ordinal(priv, IPW_ORD_PERS_DB_LOCK, &lock, &ord_len)) {
1716 IPW_DEBUG_ERROR("%s: Failed to clear ordinal lock.\n",
1717 priv->net_dev->name);
1722 priv->status &= ~STATUS_SCANNING;
1724 if (rf_kill_active(priv)) {
1725 printk(KERN_INFO "%s: Radio is disabled by RF switch.\n",
1726 priv->net_dev->name);
1728 if (priv->stop_rf_kill) {
1729 priv->stop_rf_kill = 0;
1730 queue_delayed_work(priv->workqueue, &priv->rf_kill, HZ);
1736 /* Turn on the interrupt so that commands can be processed */
1737 ipw2100_enable_interrupts(priv);
1739 /* Send all of the commands that must be sent prior to
1741 if (ipw2100_adapter_setup(priv)) {
1742 IPW_DEBUG_ERROR("%s: Failed to start the card.\n",
1743 priv->net_dev->name);
1749 /* Enable the adapter - sends HOST_COMPLETE */
1750 if (ipw2100_enable_adapter(priv)) {
1752 "%s: failed in call to enable adapter.\n",
1753 priv->net_dev->name);
1754 ipw2100_hw_stop_adapter(priv);
1760 /* Start a scan . . . */
1761 ipw2100_set_scan_options(priv);
1762 ipw2100_start_scan(priv);
1769 /* Called by register_netdev() */
1770 static int ipw2100_net_init(struct net_device *dev)
1772 struct ipw2100_priv *priv = ieee80211_priv(dev);
1773 return ipw2100_up(priv, 1);
1776 static void ipw2100_down(struct ipw2100_priv *priv)
1778 unsigned long flags;
1779 union iwreq_data wrqu = {
1781 .sa_family = ARPHRD_ETHER
1784 int associated = priv->status & STATUS_ASSOCIATED;
1786 /* Kill the RF switch timer */
1787 if (!priv->stop_rf_kill) {
1788 priv->stop_rf_kill = 1;
1789 cancel_delayed_work(&priv->rf_kill);
1792 /* Kill the firmare hang check timer */
1793 if (!priv->stop_hang_check) {
1794 priv->stop_hang_check = 1;
1795 cancel_delayed_work(&priv->hang_check);
1798 /* Kill any pending resets */
1799 if (priv->status & STATUS_RESET_PENDING)
1800 cancel_delayed_work(&priv->reset_work);
1802 /* Make sure the interrupt is on so that FW commands will be
1803 * processed correctly */
1804 spin_lock_irqsave(&priv->low_lock, flags);
1805 ipw2100_enable_interrupts(priv);
1806 spin_unlock_irqrestore(&priv->low_lock, flags);
1808 if (ipw2100_hw_stop_adapter(priv))
1809 IPW_DEBUG_ERROR("%s: Error stopping adapter.\n",
1810 priv->net_dev->name);
1812 /* Do not disable the interrupt until _after_ we disable
1813 * the adaptor. Otherwise the CARD_DISABLE command will never
1814 * be ack'd by the firmware */
1815 spin_lock_irqsave(&priv->low_lock, flags);
1816 ipw2100_disable_interrupts(priv);
1817 spin_unlock_irqrestore(&priv->low_lock, flags);
1819 #ifdef ACPI_CSTATE_LIMIT_DEFINED
1820 if (priv->config & CFG_C3_DISABLED) {
1821 IPW_DEBUG_INFO(DRV_NAME ": Resetting C3 transitions.\n");
1822 acpi_set_cstate_limit(priv->cstate_limit);
1823 priv->config &= ~CFG_C3_DISABLED;
1827 /* We have to signal any supplicant if we are disassociating */
1829 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1831 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1832 netif_carrier_off(priv->net_dev);
1833 netif_stop_queue(priv->net_dev);
1836 void ipw2100_reset_adapter(struct ipw2100_priv *priv)
1838 unsigned long flags;
1839 union iwreq_data wrqu = {
1841 .sa_family = ARPHRD_ETHER
1844 int associated = priv->status & STATUS_ASSOCIATED;
1846 spin_lock_irqsave(&priv->low_lock, flags);
1847 IPW_DEBUG_INFO(DRV_NAME ": %s: Restarting adapter.\n",
1848 priv->net_dev->name);
1850 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1851 priv->status |= STATUS_SECURITY_UPDATED;
1853 /* Force a power cycle even if interface hasn't been opened
1855 cancel_delayed_work(&priv->reset_work);
1856 priv->status |= STATUS_RESET_PENDING;
1857 spin_unlock_irqrestore(&priv->low_lock, flags);
1859 down(&priv->action_sem);
1860 /* stop timed checks so that they don't interfere with reset */
1861 priv->stop_hang_check = 1;
1862 cancel_delayed_work(&priv->hang_check);
1864 /* We have to signal any supplicant if we are disassociating */
1866 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1868 ipw2100_up(priv, 0);
1869 up(&priv->action_sem);
1874 static void isr_indicate_associated(struct ipw2100_priv *priv, u32 status)
1877 #define MAC_ASSOCIATION_READ_DELAY (HZ)
1878 int ret, len, essid_len;
1879 char essid[IW_ESSID_MAX_SIZE];
1886 * TBD: BSSID is usually 00:00:00:00:00:00 here and not
1887 * an actual MAC of the AP. Seems like FW sets this
1888 * address too late. Read it later and expose through
1889 * /proc or schedule a later task to query and update
1892 essid_len = IW_ESSID_MAX_SIZE;
1893 ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_SSID,
1896 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
1902 ret = ipw2100_get_ordinal(priv, IPW_ORD_CURRENT_TX_RATE,
1905 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
1911 ret = ipw2100_get_ordinal(priv, IPW_ORD_OUR_FREQ, &chan, &len);
1913 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
1918 ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID, &bssid, &len);
1920 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
1924 memcpy(priv->ieee->bssid, bssid, ETH_ALEN);
1928 case TX_RATE_1_MBIT:
1929 txratename = "1Mbps";
1931 case TX_RATE_2_MBIT:
1932 txratename = "2Mbsp";
1934 case TX_RATE_5_5_MBIT:
1935 txratename = "5.5Mbps";
1937 case TX_RATE_11_MBIT:
1938 txratename = "11Mbps";
1941 IPW_DEBUG_INFO("Unknown rate: %d\n", txrate);
1942 txratename = "unknown rate";
1946 IPW_DEBUG_INFO("%s: Associated with '%s' at %s, channel %d (BSSID="
1948 priv->net_dev->name, escape_essid(essid, essid_len),
1949 txratename, chan, MAC_ARG(bssid));
1951 /* now we copy read ssid into dev */
1952 if (!(priv->config & CFG_STATIC_ESSID)) {
1953 priv->essid_len = min((u8)essid_len, (u8)IW_ESSID_MAX_SIZE);
1954 memcpy(priv->essid, essid, priv->essid_len);
1956 priv->channel = chan;
1957 memcpy(priv->bssid, bssid, ETH_ALEN);
1959 priv->status |= STATUS_ASSOCIATING;
1960 priv->connect_start = get_seconds();
1962 queue_delayed_work(priv->workqueue, &priv->wx_event_work, HZ / 10);
1966 int ipw2100_set_essid(struct ipw2100_priv *priv, char *essid,
1967 int length, int batch_mode)
1969 int ssid_len = min(length, IW_ESSID_MAX_SIZE);
1970 struct host_command cmd = {
1971 .host_command = SSID,
1972 .host_command_sequence = 0,
1973 .host_command_length = ssid_len
1977 IPW_DEBUG_HC("SSID: '%s'\n", escape_essid(essid, ssid_len));
1980 memcpy((char*)cmd.host_command_parameters,
1984 err = ipw2100_disable_adapter(priv);
1989 /* Bug in FW currently doesn't honor bit 0 in SET_SCAN_OPTIONS to
1990 * disable auto association -- so we cheat by setting a bogus SSID */
1991 if (!ssid_len && !(priv->config & CFG_ASSOCIATE)) {
1993 u8 *bogus = (u8*)cmd.host_command_parameters;
1994 for (i = 0; i < IW_ESSID_MAX_SIZE; i++)
1995 bogus[i] = 0x18 + i;
1996 cmd.host_command_length = IW_ESSID_MAX_SIZE;
1999 /* NOTE: We always send the SSID command even if the provided ESSID is
2000 * the same as what we currently think is set. */
2002 err = ipw2100_hw_send_command(priv, &cmd);
2004 memset(priv->essid + ssid_len, 0,
2005 IW_ESSID_MAX_SIZE - ssid_len);
2006 memcpy(priv->essid, essid, ssid_len);
2007 priv->essid_len = ssid_len;
2011 if (ipw2100_enable_adapter(priv))
2018 static void isr_indicate_association_lost(struct ipw2100_priv *priv, u32 status)
2020 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | IPW_DL_ASSOC,
2021 "disassociated: '%s' " MAC_FMT " \n",
2022 escape_essid(priv->essid, priv->essid_len),
2023 MAC_ARG(priv->bssid));
2025 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
2027 if (priv->status & STATUS_STOPPING) {
2028 IPW_DEBUG_INFO("Card is stopping itself, discard ASSN_LOST.\n");
2032 memset(priv->bssid, 0, ETH_ALEN);
2033 memset(priv->ieee->bssid, 0, ETH_ALEN);
2035 netif_carrier_off(priv->net_dev);
2036 netif_stop_queue(priv->net_dev);
2038 if (!(priv->status & STATUS_RUNNING))
2041 if (priv->status & STATUS_SECURITY_UPDATED)
2042 queue_work(priv->workqueue, &priv->security_work);
2044 queue_work(priv->workqueue, &priv->wx_event_work);
2047 static void isr_indicate_rf_kill(struct ipw2100_priv *priv, u32 status)
2049 IPW_DEBUG_INFO("%s: RF Kill state changed to radio OFF.\n",
2050 priv->net_dev->name);
2052 /* RF_KILL is now enabled (else we wouldn't be here) */
2053 priv->status |= STATUS_RF_KILL_HW;
2055 #ifdef ACPI_CSTATE_LIMIT_DEFINED
2056 if (priv->config & CFG_C3_DISABLED) {
2057 IPW_DEBUG_INFO(DRV_NAME ": Resetting C3 transitions.\n");
2058 acpi_set_cstate_limit(priv->cstate_limit);
2059 priv->config &= ~CFG_C3_DISABLED;
2063 /* Make sure the RF Kill check timer is running */
2064 priv->stop_rf_kill = 0;
2065 cancel_delayed_work(&priv->rf_kill);
2066 queue_delayed_work(priv->workqueue, &priv->rf_kill, HZ);
2069 static void isr_scan_complete(struct ipw2100_priv *priv, u32 status)
2071 IPW_DEBUG_SCAN("scan complete\n");
2072 /* Age the scan results... */
2073 priv->ieee->scans++;
2074 priv->status &= ~STATUS_SCANNING;
2077 #ifdef CONFIG_IPW_DEBUG
2078 #define IPW2100_HANDLER(v, f) { v, f, # v }
2079 struct ipw2100_status_indicator {
2081 void (*cb)(struct ipw2100_priv *priv, u32 status);
2085 #define IPW2100_HANDLER(v, f) { v, f }
2086 struct ipw2100_status_indicator {
2088 void (*cb)(struct ipw2100_priv *priv, u32 status);
2090 #endif /* CONFIG_IPW_DEBUG */
2092 static void isr_indicate_scanning(struct ipw2100_priv *priv, u32 status)
2094 IPW_DEBUG_SCAN("Scanning...\n");
2095 priv->status |= STATUS_SCANNING;
2098 const struct ipw2100_status_indicator status_handlers[] = {
2099 IPW2100_HANDLER(IPW_STATE_INITIALIZED, 0),
2100 IPW2100_HANDLER(IPW_STATE_COUNTRY_FOUND, 0),
2101 IPW2100_HANDLER(IPW_STATE_ASSOCIATED, isr_indicate_associated),
2102 IPW2100_HANDLER(IPW_STATE_ASSN_LOST, isr_indicate_association_lost),
2103 IPW2100_HANDLER(IPW_STATE_ASSN_CHANGED, 0),
2104 IPW2100_HANDLER(IPW_STATE_SCAN_COMPLETE, isr_scan_complete),
2105 IPW2100_HANDLER(IPW_STATE_ENTERED_PSP, 0),
2106 IPW2100_HANDLER(IPW_STATE_LEFT_PSP, 0),
2107 IPW2100_HANDLER(IPW_STATE_RF_KILL, isr_indicate_rf_kill),
2108 IPW2100_HANDLER(IPW_STATE_DISABLED, 0),
2109 IPW2100_HANDLER(IPW_STATE_POWER_DOWN, 0),
2110 IPW2100_HANDLER(IPW_STATE_SCANNING, isr_indicate_scanning),
2111 IPW2100_HANDLER(-1, 0)
2115 static void isr_status_change(struct ipw2100_priv *priv, int status)
2119 if (status == IPW_STATE_SCANNING &&
2120 priv->status & STATUS_ASSOCIATED &&
2121 !(priv->status & STATUS_SCANNING)) {
2122 IPW_DEBUG_INFO("Scan detected while associated, with "
2123 "no scan request. Restarting firmware.\n");
2125 /* Wake up any sleeping jobs */
2126 schedule_reset(priv);
2129 for (i = 0; status_handlers[i].status != -1; i++) {
2130 if (status == status_handlers[i].status) {
2131 IPW_DEBUG_NOTIF("Status change: %s\n",
2132 status_handlers[i].name);
2133 if (status_handlers[i].cb)
2134 status_handlers[i].cb(priv, status);
2135 priv->wstats.status = status;
2140 IPW_DEBUG_NOTIF("unknown status received: %04x\n", status);
2143 static void isr_rx_complete_command(
2144 struct ipw2100_priv *priv,
2145 struct ipw2100_cmd_header *cmd)
2147 #ifdef CONFIG_IPW_DEBUG
2148 if (cmd->host_command_reg < ARRAY_SIZE(command_types)) {
2149 IPW_DEBUG_HC("Command completed '%s (%d)'\n",
2150 command_types[cmd->host_command_reg],
2151 cmd->host_command_reg);
2154 if (cmd->host_command_reg == HOST_COMPLETE)
2155 priv->status |= STATUS_ENABLED;
2157 if (cmd->host_command_reg == CARD_DISABLE)
2158 priv->status &= ~STATUS_ENABLED;
2160 priv->status &= ~STATUS_CMD_ACTIVE;
2162 wake_up_interruptible(&priv->wait_command_queue);
2165 #ifdef CONFIG_IPW_DEBUG
2166 const char *frame_types[] = {
2167 "COMMAND_STATUS_VAL",
2168 "STATUS_CHANGE_VAL",
2171 "HOST_NOTIFICATION_VAL"
2176 static inline int ipw2100_alloc_skb(
2177 struct ipw2100_priv *priv,
2178 struct ipw2100_rx_packet *packet)
2180 packet->skb = dev_alloc_skb(sizeof(struct ipw2100_rx));
2184 packet->rxp = (struct ipw2100_rx *)packet->skb->data;
2185 packet->dma_addr = pci_map_single(priv->pci_dev, packet->skb->data,
2186 sizeof(struct ipw2100_rx),
2187 PCI_DMA_FROMDEVICE);
2188 /* NOTE: pci_map_single does not return an error code, and 0 is a valid
2195 #define SEARCH_ERROR 0xffffffff
2196 #define SEARCH_FAIL 0xfffffffe
2197 #define SEARCH_SUCCESS 0xfffffff0
2198 #define SEARCH_DISCARD 0
2199 #define SEARCH_SNAPSHOT 1
2201 #define SNAPSHOT_ADDR(ofs) (priv->snapshot[((ofs) >> 12) & 0xff] + ((ofs) & 0xfff))
2202 static inline int ipw2100_snapshot_alloc(struct ipw2100_priv *priv)
2205 if (priv->snapshot[0])
2207 for (i = 0; i < 0x30; i++) {
2208 priv->snapshot[i] = (u8*)kmalloc(0x1000, GFP_ATOMIC);
2209 if (!priv->snapshot[i]) {
2210 IPW_DEBUG_INFO("%s: Error allocating snapshot "
2211 "buffer %d\n", priv->net_dev->name, i);
2213 kfree(priv->snapshot[--i]);
2214 priv->snapshot[0] = NULL;
2222 static inline void ipw2100_snapshot_free(struct ipw2100_priv *priv)
2225 if (!priv->snapshot[0])
2227 for (i = 0; i < 0x30; i++)
2228 kfree(priv->snapshot[i]);
2229 priv->snapshot[0] = NULL;
2232 static inline u32 ipw2100_match_buf(struct ipw2100_priv *priv, u8 *in_buf,
2233 size_t len, int mode)
2241 if (mode == SEARCH_SNAPSHOT) {
2242 if (!ipw2100_snapshot_alloc(priv))
2243 mode = SEARCH_DISCARD;
2246 for (ret = SEARCH_FAIL, i = 0; i < 0x30000; i += 4) {
2247 read_nic_dword(priv->net_dev, i, &tmp);
2248 if (mode == SEARCH_SNAPSHOT)
2249 *(u32 *)SNAPSHOT_ADDR(i) = tmp;
2250 if (ret == SEARCH_FAIL) {
2252 for (j = 0; j < 4; j++) {
2261 if ((s - in_buf) == len)
2262 ret = (i + j) - len + 1;
2264 } else if (mode == SEARCH_DISCARD)
2273 * 0) Disconnect the SKB from the firmware (just unmap)
2274 * 1) Pack the ETH header into the SKB
2275 * 2) Pass the SKB to the network stack
2277 * When packet is provided by the firmware, it contains the following:
2280 * . ieee80211_snap_hdr
2282 * The size of the constructed ethernet
2285 #ifdef CONFIG_IPW2100_RX_DEBUG
2286 u8 packet_data[IPW_RX_NIC_BUFFER_LENGTH];
2289 static inline void ipw2100_corruption_detected(struct ipw2100_priv *priv,
2292 #ifdef CONFIG_IPW_DEBUG_C3
2293 struct ipw2100_status *status = &priv->status_queue.drv[i];
2297 #ifdef ACPI_CSTATE_LIMIT_DEFINED
2301 IPW_DEBUG_INFO(DRV_NAME ": PCI latency error detected at "
2302 "0x%04zX.\n", i * sizeof(struct ipw2100_status));
2304 #ifdef ACPI_CSTATE_LIMIT_DEFINED
2305 IPW_DEBUG_INFO(DRV_NAME ": Disabling C3 transitions.\n");
2306 limit = acpi_get_cstate_limit();
2308 priv->cstate_limit = limit;
2309 acpi_set_cstate_limit(2);
2310 priv->config |= CFG_C3_DISABLED;
2314 #ifdef CONFIG_IPW_DEBUG_C3
2315 /* Halt the fimrware so we can get a good image */
2316 write_register(priv->net_dev, IPW_REG_RESET_REG,
2317 IPW_AUX_HOST_RESET_REG_STOP_MASTER);
2320 udelay(IPW_WAIT_RESET_MASTER_ASSERT_COMPLETE_DELAY);
2321 read_register(priv->net_dev, IPW_REG_RESET_REG, ®);
2323 if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED)
2327 match = ipw2100_match_buf(priv, (u8*)status,
2328 sizeof(struct ipw2100_status),
2330 if (match < SEARCH_SUCCESS)
2331 IPW_DEBUG_INFO("%s: DMA status match in Firmware at "
2332 "offset 0x%06X, length %d:\n",
2333 priv->net_dev->name, match,
2334 sizeof(struct ipw2100_status));
2336 IPW_DEBUG_INFO("%s: No DMA status match in "
2337 "Firmware.\n", priv->net_dev->name);
2339 printk_buf((u8*)priv->status_queue.drv,
2340 sizeof(struct ipw2100_status) * RX_QUEUE_LENGTH);
2343 priv->fatal_error = IPW2100_ERR_C3_CORRUPTION;
2344 priv->ieee->stats.rx_errors++;
2345 schedule_reset(priv);
2348 static inline void isr_rx(struct ipw2100_priv *priv, int i,
2349 struct ieee80211_rx_stats *stats)
2351 struct ipw2100_status *status = &priv->status_queue.drv[i];
2352 struct ipw2100_rx_packet *packet = &priv->rx_buffers[i];
2354 IPW_DEBUG_RX("Handler...\n");
2356 if (unlikely(status->frame_size > skb_tailroom(packet->skb))) {
2357 IPW_DEBUG_INFO("%s: frame_size (%u) > skb_tailroom (%u)!"
2359 priv->net_dev->name,
2360 status->frame_size, skb_tailroom(packet->skb));
2361 priv->ieee->stats.rx_errors++;
2365 if (unlikely(!netif_running(priv->net_dev))) {
2366 priv->ieee->stats.rx_errors++;
2367 priv->wstats.discard.misc++;
2368 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
2372 if (unlikely(priv->ieee->iw_mode == IW_MODE_MONITOR &&
2373 status->flags & IPW_STATUS_FLAG_CRC_ERROR)) {
2374 IPW_DEBUG_RX("CRC error in packet. Dropping.\n");
2375 priv->ieee->stats.rx_errors++;
2379 if (unlikely(priv->ieee->iw_mode != IW_MODE_MONITOR &&
2380 !(priv->status & STATUS_ASSOCIATED))) {
2381 IPW_DEBUG_DROP("Dropping packet while not associated.\n");
2382 priv->wstats.discard.misc++;
2387 pci_unmap_single(priv->pci_dev,
2389 sizeof(struct ipw2100_rx),
2390 PCI_DMA_FROMDEVICE);
2392 skb_put(packet->skb, status->frame_size);
2394 #ifdef CONFIG_IPW2100_RX_DEBUG
2395 /* Make a copy of the frame so we can dump it to the logs if
2396 * ieee80211_rx fails */
2397 memcpy(packet_data, packet->skb->data,
2398 min_t(u32, status->frame_size, IPW_RX_NIC_BUFFER_LENGTH));
2401 if (!ieee80211_rx(priv->ieee, packet->skb, stats)) {
2402 #ifdef CONFIG_IPW2100_RX_DEBUG
2403 IPW_DEBUG_DROP("%s: Non consumed packet:\n",
2404 priv->net_dev->name);
2405 printk_buf(IPW_DL_DROP, packet_data, status->frame_size);
2407 priv->ieee->stats.rx_errors++;
2409 /* ieee80211_rx failed, so it didn't free the SKB */
2410 dev_kfree_skb_any(packet->skb);
2414 /* We need to allocate a new SKB and attach it to the RDB. */
2415 if (unlikely(ipw2100_alloc_skb(priv, packet))) {
2417 "%s: Unable to allocate SKB onto RBD ring - disabling "
2418 "adapter.\n", priv->net_dev->name);
2419 /* TODO: schedule adapter shutdown */
2420 IPW_DEBUG_INFO("TODO: Shutdown adapter...\n");
2423 /* Update the RDB entry */
2424 priv->rx_queue.drv[i].host_addr = packet->dma_addr;
2427 static inline int ipw2100_corruption_check(struct ipw2100_priv *priv, int i)
2429 struct ipw2100_status *status = &priv->status_queue.drv[i];
2430 struct ipw2100_rx *u = priv->rx_buffers[i].rxp;
2431 u16 frame_type = status->status_fields & STATUS_TYPE_MASK;
2433 switch (frame_type) {
2434 case COMMAND_STATUS_VAL:
2435 return (status->frame_size != sizeof(u->rx_data.command));
2436 case STATUS_CHANGE_VAL:
2437 return (status->frame_size != sizeof(u->rx_data.status));
2438 case HOST_NOTIFICATION_VAL:
2439 return (status->frame_size < sizeof(u->rx_data.notification));
2440 case P80211_DATA_VAL:
2441 case P8023_DATA_VAL:
2442 #ifdef CONFIG_IPW2100_MONITOR
2445 switch (WLAN_FC_GET_TYPE(u->rx_data.header.frame_ctl)) {
2446 case IEEE80211_FTYPE_MGMT:
2447 case IEEE80211_FTYPE_CTL:
2449 case IEEE80211_FTYPE_DATA:
2450 return (status->frame_size >
2451 IPW_MAX_802_11_PAYLOAD_LENGTH);
2460 * ipw2100 interrupts are disabled at this point, and the ISR
2461 * is the only code that calls this method. So, we do not need
2462 * to play with any locks.
2464 * RX Queue works as follows:
2466 * Read index - firmware places packet in entry identified by the
2467 * Read index and advances Read index. In this manner,
2468 * Read index will always point to the next packet to
2469 * be filled--but not yet valid.
2471 * Write index - driver fills this entry with an unused RBD entry.
2472 * This entry has not filled by the firmware yet.
2474 * In between the W and R indexes are the RBDs that have been received
2475 * but not yet processed.
2477 * The process of handling packets will start at WRITE + 1 and advance
2478 * until it reaches the READ index.
2480 * The WRITE index is cached in the variable 'priv->rx_queue.next'.
2483 static inline void __ipw2100_rx_process(struct ipw2100_priv *priv)
2485 struct ipw2100_bd_queue *rxq = &priv->rx_queue;
2486 struct ipw2100_status_queue *sq = &priv->status_queue;
2487 struct ipw2100_rx_packet *packet;
2490 struct ipw2100_rx *u;
2491 struct ieee80211_rx_stats stats = {
2492 .mac_time = jiffies,
2495 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_READ_INDEX, &r);
2496 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_WRITE_INDEX, &w);
2498 if (r >= rxq->entries) {
2499 IPW_DEBUG_RX("exit - bad read index\n");
2503 i = (rxq->next + 1) % rxq->entries;
2506 /* IPW_DEBUG_RX("r = %d : w = %d : processing = %d\n",
2507 r, rxq->next, i); */
2509 packet = &priv->rx_buffers[i];
2511 /* Sync the DMA for the STATUS buffer so CPU is sure to get
2512 * the correct values */
2513 pci_dma_sync_single_for_cpu(
2515 sq->nic + sizeof(struct ipw2100_status) * i,
2516 sizeof(struct ipw2100_status),
2517 PCI_DMA_FROMDEVICE);
2519 /* Sync the DMA for the RX buffer so CPU is sure to get
2520 * the correct values */
2521 pci_dma_sync_single_for_cpu(priv->pci_dev, packet->dma_addr,
2522 sizeof(struct ipw2100_rx),
2523 PCI_DMA_FROMDEVICE);
2525 if (unlikely(ipw2100_corruption_check(priv, i))) {
2526 ipw2100_corruption_detected(priv, i);
2531 frame_type = sq->drv[i].status_fields &
2533 stats.rssi = sq->drv[i].rssi + IPW2100_RSSI_TO_DBM;
2534 stats.len = sq->drv[i].frame_size;
2537 if (stats.rssi != 0)
2538 stats.mask |= IEEE80211_STATMASK_RSSI;
2539 stats.freq = IEEE80211_24GHZ_BAND;
2542 "%s: '%s' frame type received (%d).\n",
2543 priv->net_dev->name, frame_types[frame_type],
2546 switch (frame_type) {
2547 case COMMAND_STATUS_VAL:
2548 /* Reset Rx watchdog */
2549 isr_rx_complete_command(
2550 priv, &u->rx_data.command);
2553 case STATUS_CHANGE_VAL:
2554 isr_status_change(priv, u->rx_data.status);
2557 case P80211_DATA_VAL:
2558 case P8023_DATA_VAL:
2559 #ifdef CONFIG_IPW2100_MONITOR
2560 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
2561 isr_rx(priv, i, &stats);
2565 if (stats.len < sizeof(u->rx_data.header))
2567 switch (WLAN_FC_GET_TYPE(u->rx_data.header.
2569 case IEEE80211_FTYPE_MGMT:
2570 ieee80211_rx_mgt(priv->ieee,
2575 case IEEE80211_FTYPE_CTL:
2578 case IEEE80211_FTYPE_DATA:
2579 isr_rx(priv, i, &stats);
2587 /* clear status field associated with this RBD */
2588 rxq->drv[i].status.info.field = 0;
2590 i = (i + 1) % rxq->entries;
2594 /* backtrack one entry, wrapping to end if at 0 */
2595 rxq->next = (i ? i : rxq->entries) - 1;
2597 write_register(priv->net_dev,
2598 IPW_MEM_HOST_SHARED_RX_WRITE_INDEX,
2605 * __ipw2100_tx_process
2607 * This routine will determine whether the next packet on
2608 * the fw_pend_list has been processed by the firmware yet.
2610 * If not, then it does nothing and returns.
2612 * If so, then it removes the item from the fw_pend_list, frees
2613 * any associated storage, and places the item back on the
2614 * free list of its source (either msg_free_list or tx_free_list)
2616 * TX Queue works as follows:
2618 * Read index - points to the next TBD that the firmware will
2619 * process. The firmware will read the data, and once
2620 * done processing, it will advance the Read index.
2622 * Write index - driver fills this entry with an constructed TBD
2623 * entry. The Write index is not advanced until the
2624 * packet has been configured.
2626 * In between the W and R indexes are the TBDs that have NOT been
2627 * processed. Lagging behind the R index are packets that have
2628 * been processed but have not been freed by the driver.
2630 * In order to free old storage, an internal index will be maintained
2631 * that points to the next packet to be freed. When all used
2632 * packets have been freed, the oldest index will be the same as the
2633 * firmware's read index.
2635 * The OLDEST index is cached in the variable 'priv->tx_queue.oldest'
2637 * Because the TBD structure can not contain arbitrary data, the
2638 * driver must keep an internal queue of cached allocations such that
2639 * it can put that data back into the tx_free_list and msg_free_list
2640 * for use by future command and data packets.
2643 static inline int __ipw2100_tx_process(struct ipw2100_priv *priv)
2645 struct ipw2100_bd_queue *txq = &priv->tx_queue;
2646 struct ipw2100_bd *tbd;
2647 struct list_head *element;
2648 struct ipw2100_tx_packet *packet;
2649 int descriptors_used;
2651 u32 r, w, frag_num = 0;
2653 if (list_empty(&priv->fw_pend_list))
2656 element = priv->fw_pend_list.next;
2658 packet = list_entry(element, struct ipw2100_tx_packet, list);
2659 tbd = &txq->drv[packet->index];
2661 /* Determine how many TBD entries must be finished... */
2662 switch (packet->type) {
2664 /* COMMAND uses only one slot; don't advance */
2665 descriptors_used = 1;
2670 /* DATA uses two slots; advance and loop position. */
2671 descriptors_used = tbd->num_fragments;
2672 frag_num = tbd->num_fragments - 1;
2673 e = txq->oldest + frag_num;
2678 IPW_DEBUG_WARNING("%s: Bad fw_pend_list entry!\n",
2679 priv->net_dev->name);
2683 /* if the last TBD is not done by NIC yet, then packet is
2684 * not ready to be released.
2687 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_TX_QUEUE_READ_INDEX,
2689 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX,
2692 IPW_DEBUG_WARNING("%s: write index mismatch\n",
2693 priv->net_dev->name);
2696 * txq->next is the index of the last packet written txq->oldest is
2697 * the index of the r is the index of the next packet to be read by
2703 * Quick graphic to help you visualize the following
2704 * if / else statement
2706 * ===>| s---->|===============
2708 * | a | b | c | d | e | f | g | h | i | j | k | l
2712 * w - updated by driver
2713 * r - updated by firmware
2714 * s - start of oldest BD entry (txq->oldest)
2715 * e - end of oldest BD entry
2718 if (!((r <= w && (e < r || e >= w)) || (e < r && e >= w))) {
2719 IPW_DEBUG_TX("exit - no processed packets ready to release.\n");
2724 DEC_STAT(&priv->fw_pend_stat);
2726 #ifdef CONFIG_IPW_DEBUG
2728 int i = txq->oldest;
2730 "TX%d V=%p P=%04X T=%04X L=%d\n", i,
2732 (u32)(txq->nic + i * sizeof(struct ipw2100_bd)),
2733 txq->drv[i].host_addr,
2734 txq->drv[i].buf_length);
2736 if (packet->type == DATA) {
2737 i = (i + 1) % txq->entries;
2740 "TX%d V=%p P=%04X T=%04X L=%d\n", i,
2742 (u32)(txq->nic + i *
2743 sizeof(struct ipw2100_bd)),
2744 (u32)txq->drv[i].host_addr,
2745 txq->drv[i].buf_length);
2750 switch (packet->type) {
2752 if (txq->drv[txq->oldest].status.info.fields.txType != 0)
2753 IPW_DEBUG_WARNING("%s: Queue mismatch. "
2754 "Expecting DATA TBD but pulled "
2755 "something else: ids %d=%d.\n",
2756 priv->net_dev->name, txq->oldest, packet->index);
2758 /* DATA packet; we have to unmap and free the SKB */
2759 priv->ieee->stats.tx_packets++;
2760 for (i = 0; i < frag_num; i++) {
2761 tbd = &txq->drv[(packet->index + 1 + i) %
2765 "TX%d P=%08x L=%d\n",
2766 (packet->index + 1 + i) % txq->entries,
2767 tbd->host_addr, tbd->buf_length);
2769 pci_unmap_single(priv->pci_dev,
2775 priv->ieee->stats.tx_bytes += packet->info.d_struct.txb->payload_size;
2776 ieee80211_txb_free(packet->info.d_struct.txb);
2777 packet->info.d_struct.txb = NULL;
2779 list_add_tail(element, &priv->tx_free_list);
2780 INC_STAT(&priv->tx_free_stat);
2782 /* We have a free slot in the Tx queue, so wake up the
2783 * transmit layer if it is stopped. */
2784 if (priv->status & STATUS_ASSOCIATED &&
2785 netif_queue_stopped(priv->net_dev)) {
2786 IPW_DEBUG_INFO(KERN_INFO
2787 "%s: Waking net queue.\n",
2788 priv->net_dev->name);
2789 netif_wake_queue(priv->net_dev);
2792 /* A packet was processed by the hardware, so update the
2794 priv->net_dev->trans_start = jiffies;
2799 if (txq->drv[txq->oldest].status.info.fields.txType != 1)
2800 IPW_DEBUG_WARNING("%s: Queue mismatch. "
2801 "Expecting COMMAND TBD but pulled "
2802 "something else: ids %d=%d.\n",
2803 priv->net_dev->name, txq->oldest, packet->index);
2805 #ifdef CONFIG_IPW_DEBUG
2806 if (packet->info.c_struct.cmd->host_command_reg <
2807 sizeof(command_types) / sizeof(*command_types))
2809 "Command '%s (%d)' processed: %d.\n",
2810 command_types[packet->info.c_struct.cmd->host_command_reg],
2811 packet->info.c_struct.cmd->host_command_reg,
2812 packet->info.c_struct.cmd->cmd_status_reg);
2815 list_add_tail(element, &priv->msg_free_list);
2816 INC_STAT(&priv->msg_free_stat);
2820 /* advance oldest used TBD pointer to start of next entry */
2821 txq->oldest = (e + 1) % txq->entries;
2822 /* increase available TBDs number */
2823 txq->available += descriptors_used;
2824 SET_STAT(&priv->txq_stat, txq->available);
2826 IPW_DEBUG_TX("packet latency (send to process) %ld jiffies\n",
2827 jiffies - packet->jiffy_start);
2829 return (!list_empty(&priv->fw_pend_list));
2833 static inline void __ipw2100_tx_complete(struct ipw2100_priv *priv)
2837 while (__ipw2100_tx_process(priv) && i < 200) i++;
2840 printk(KERN_WARNING DRV_NAME ": "
2841 "%s: Driver is running slow (%d iters).\n",
2842 priv->net_dev->name, i);
2847 static void ipw2100_tx_send_commands(struct ipw2100_priv *priv)
2849 struct list_head *element;
2850 struct ipw2100_tx_packet *packet;
2851 struct ipw2100_bd_queue *txq = &priv->tx_queue;
2852 struct ipw2100_bd *tbd;
2853 int next = txq->next;
2855 while (!list_empty(&priv->msg_pend_list)) {
2856 /* if there isn't enough space in TBD queue, then
2857 * don't stuff a new one in.
2858 * NOTE: 3 are needed as a command will take one,
2859 * and there is a minimum of 2 that must be
2860 * maintained between the r and w indexes
2862 if (txq->available <= 3) {
2863 IPW_DEBUG_TX("no room in tx_queue\n");
2867 element = priv->msg_pend_list.next;
2869 DEC_STAT(&priv->msg_pend_stat);
2871 packet = list_entry(element,
2872 struct ipw2100_tx_packet, list);
2874 IPW_DEBUG_TX("using TBD at virt=%p, phys=%p\n",
2875 &txq->drv[txq->next],
2876 (void*)(txq->nic + txq->next *
2877 sizeof(struct ipw2100_bd)));
2879 packet->index = txq->next;
2881 tbd = &txq->drv[txq->next];
2883 /* initialize TBD */
2884 tbd->host_addr = packet->info.c_struct.cmd_phys;
2885 tbd->buf_length = sizeof(struct ipw2100_cmd_header);
2886 /* not marking number of fragments causes problems
2887 * with f/w debug version */
2888 tbd->num_fragments = 1;
2889 tbd->status.info.field =
2890 IPW_BD_STATUS_TX_FRAME_COMMAND |
2891 IPW_BD_STATUS_TX_INTERRUPT_ENABLE;
2893 /* update TBD queue counters */
2895 txq->next %= txq->entries;
2897 DEC_STAT(&priv->txq_stat);
2899 list_add_tail(element, &priv->fw_pend_list);
2900 INC_STAT(&priv->fw_pend_stat);
2903 if (txq->next != next) {
2904 /* kick off the DMA by notifying firmware the
2905 * write index has moved; make sure TBD stores are sync'd */
2907 write_register(priv->net_dev,
2908 IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX,
2915 * ipw2100_tx_send_data
2918 static void ipw2100_tx_send_data(struct ipw2100_priv *priv)
2920 struct list_head *element;
2921 struct ipw2100_tx_packet *packet;
2922 struct ipw2100_bd_queue *txq = &priv->tx_queue;
2923 struct ipw2100_bd *tbd;
2924 int next = txq->next;
2926 struct ipw2100_data_header *ipw_hdr;
2927 struct ieee80211_hdr *hdr;
2929 while (!list_empty(&priv->tx_pend_list)) {
2930 /* if there isn't enough space in TBD queue, then
2931 * don't stuff a new one in.
2932 * NOTE: 4 are needed as a data will take two,
2933 * and there is a minimum of 2 that must be
2934 * maintained between the r and w indexes
2936 element = priv->tx_pend_list.next;
2937 packet = list_entry(element, struct ipw2100_tx_packet, list);
2939 if (unlikely(1 + packet->info.d_struct.txb->nr_frags >
2941 /* TODO: Support merging buffers if more than
2942 * IPW_MAX_BDS are used */
2944 "%s: Maximum BD theshold exceeded. "
2945 "Increase fragmentation level.\n",
2946 priv->net_dev->name);
2949 if (txq->available <= 3 +
2950 packet->info.d_struct.txb->nr_frags) {
2951 IPW_DEBUG_TX("no room in tx_queue\n");
2956 DEC_STAT(&priv->tx_pend_stat);
2958 tbd = &txq->drv[txq->next];
2960 packet->index = txq->next;
2962 ipw_hdr = packet->info.d_struct.data;
2963 hdr = (struct ieee80211_hdr *)packet->info.d_struct.txb->
2966 if (priv->ieee->iw_mode == IW_MODE_INFRA) {
2967 /* To DS: Addr1 = BSSID, Addr2 = SA,
2969 memcpy(ipw_hdr->src_addr, hdr->addr2, ETH_ALEN);
2970 memcpy(ipw_hdr->dst_addr, hdr->addr3, ETH_ALEN);
2971 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
2972 /* not From/To DS: Addr1 = DA, Addr2 = SA,
2974 memcpy(ipw_hdr->src_addr, hdr->addr2, ETH_ALEN);
2975 memcpy(ipw_hdr->dst_addr, hdr->addr1, ETH_ALEN);
2978 ipw_hdr->host_command_reg = SEND;
2979 ipw_hdr->host_command_reg1 = 0;
2981 /* For now we only support host based encryption */
2982 ipw_hdr->needs_encryption = 0;
2983 ipw_hdr->encrypted = packet->info.d_struct.txb->encrypted;
2984 if (packet->info.d_struct.txb->nr_frags > 1)
2985 ipw_hdr->fragment_size =
2986 packet->info.d_struct.txb->frag_size - IEEE80211_3ADDR_LEN;
2988 ipw_hdr->fragment_size = 0;
2990 tbd->host_addr = packet->info.d_struct.data_phys;
2991 tbd->buf_length = sizeof(struct ipw2100_data_header);
2992 tbd->num_fragments = 1 + packet->info.d_struct.txb->nr_frags;
2993 tbd->status.info.field =
2994 IPW_BD_STATUS_TX_FRAME_802_3 |
2995 IPW_BD_STATUS_TX_FRAME_NOT_LAST_FRAGMENT;
2997 txq->next %= txq->entries;
3000 "data header tbd TX%d P=%08x L=%d\n",
3001 packet->index, tbd->host_addr,
3003 #ifdef CONFIG_IPW_DEBUG
3004 if (packet->info.d_struct.txb->nr_frags > 1)
3005 IPW_DEBUG_FRAG("fragment Tx: %d frames\n",
3006 packet->info.d_struct.txb->nr_frags);
3009 for (i = 0; i < packet->info.d_struct.txb->nr_frags; i++) {
3010 tbd = &txq->drv[txq->next];
3011 if (i == packet->info.d_struct.txb->nr_frags - 1)
3012 tbd->status.info.field =
3013 IPW_BD_STATUS_TX_FRAME_802_3 |
3014 IPW_BD_STATUS_TX_INTERRUPT_ENABLE;
3016 tbd->status.info.field =
3017 IPW_BD_STATUS_TX_FRAME_802_3 |
3018 IPW_BD_STATUS_TX_FRAME_NOT_LAST_FRAGMENT;
3020 tbd->buf_length = packet->info.d_struct.txb->
3021 fragments[i]->len - IEEE80211_3ADDR_LEN;
3023 tbd->host_addr = pci_map_single(
3025 packet->info.d_struct.txb->fragments[i]->data +
3026 IEEE80211_3ADDR_LEN,
3031 "data frag tbd TX%d P=%08x L=%d\n",
3032 txq->next, tbd->host_addr, tbd->buf_length);
3034 pci_dma_sync_single_for_device(
3035 priv->pci_dev, tbd->host_addr,
3040 txq->next %= txq->entries;
3043 txq->available -= 1 + packet->info.d_struct.txb->nr_frags;
3044 SET_STAT(&priv->txq_stat, txq->available);
3046 list_add_tail(element, &priv->fw_pend_list);
3047 INC_STAT(&priv->fw_pend_stat);
3050 if (txq->next != next) {
3051 /* kick off the DMA by notifying firmware the
3052 * write index has moved; make sure TBD stores are sync'd */
3053 write_register(priv->net_dev,
3054 IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX,
3060 static void ipw2100_irq_tasklet(struct ipw2100_priv *priv)
3062 struct net_device *dev = priv->net_dev;
3063 unsigned long flags;
3066 spin_lock_irqsave(&priv->low_lock, flags);
3067 ipw2100_disable_interrupts(priv);
3069 read_register(dev, IPW_REG_INTA, &inta);
3071 IPW_DEBUG_ISR("enter - INTA: 0x%08lX\n",
3072 (unsigned long)inta & IPW_INTERRUPT_MASK);
3077 /* We do not loop and keep polling for more interrupts as this
3078 * is frowned upon and doesn't play nicely with other potentially
3080 IPW_DEBUG_ISR("INTA: 0x%08lX\n",
3081 (unsigned long)inta & IPW_INTERRUPT_MASK);
3083 if (inta & IPW2100_INTA_FATAL_ERROR) {
3084 IPW_DEBUG_WARNING(DRV_NAME
3085 ": Fatal interrupt. Scheduling firmware restart.\n");
3089 IPW2100_INTA_FATAL_ERROR);
3091 read_nic_dword(dev, IPW_NIC_FATAL_ERROR, &priv->fatal_error);
3092 IPW_DEBUG_INFO("%s: Fatal error value: 0x%08X\n",
3093 priv->net_dev->name, priv->fatal_error);
3095 read_nic_dword(dev, IPW_ERROR_ADDR(priv->fatal_error), &tmp);
3096 IPW_DEBUG_INFO("%s: Fatal error address value: 0x%08X\n",
3097 priv->net_dev->name, tmp);
3099 /* Wake up any sleeping jobs */
3100 schedule_reset(priv);
3103 if (inta & IPW2100_INTA_PARITY_ERROR) {
3104 IPW_DEBUG_ERROR("***** PARITY ERROR INTERRUPT !!!! \n");
3108 IPW2100_INTA_PARITY_ERROR);
3111 if (inta & IPW2100_INTA_RX_TRANSFER) {
3112 IPW_DEBUG_ISR("RX interrupt\n");
3114 priv->rx_interrupts++;
3118 IPW2100_INTA_RX_TRANSFER);
3120 __ipw2100_rx_process(priv);
3121 __ipw2100_tx_complete(priv);
3124 if (inta & IPW2100_INTA_TX_TRANSFER) {
3125 IPW_DEBUG_ISR("TX interrupt\n");
3127 priv->tx_interrupts++;
3129 write_register(dev, IPW_REG_INTA,
3130 IPW2100_INTA_TX_TRANSFER);
3132 __ipw2100_tx_complete(priv);
3133 ipw2100_tx_send_commands(priv);
3134 ipw2100_tx_send_data(priv);
3137 if (inta & IPW2100_INTA_TX_COMPLETE) {
3138 IPW_DEBUG_ISR("TX complete\n");
3142 IPW2100_INTA_TX_COMPLETE);
3144 __ipw2100_tx_complete(priv);
3147 if (inta & IPW2100_INTA_EVENT_INTERRUPT) {
3148 /* ipw2100_handle_event(dev); */
3152 IPW2100_INTA_EVENT_INTERRUPT);
3155 if (inta & IPW2100_INTA_FW_INIT_DONE) {
3156 IPW_DEBUG_ISR("FW init done interrupt\n");
3159 read_register(dev, IPW_REG_INTA, &tmp);
3160 if (tmp & (IPW2100_INTA_FATAL_ERROR |
3161 IPW2100_INTA_PARITY_ERROR)) {
3164 IPW2100_INTA_FATAL_ERROR |
3165 IPW2100_INTA_PARITY_ERROR);
3168 write_register(dev, IPW_REG_INTA,
3169 IPW2100_INTA_FW_INIT_DONE);
3172 if (inta & IPW2100_INTA_STATUS_CHANGE) {
3173 IPW_DEBUG_ISR("Status change interrupt\n");
3177 IPW2100_INTA_STATUS_CHANGE);
3180 if (inta & IPW2100_INTA_SLAVE_MODE_HOST_COMMAND_DONE) {
3181 IPW_DEBUG_ISR("slave host mode interrupt\n");
3185 IPW2100_INTA_SLAVE_MODE_HOST_COMMAND_DONE);
3189 ipw2100_enable_interrupts(priv);
3191 spin_unlock_irqrestore(&priv->low_lock, flags);
3193 IPW_DEBUG_ISR("exit\n");
3197 static irqreturn_t ipw2100_interrupt(int irq, void *data,
3198 struct pt_regs *regs)
3200 struct ipw2100_priv *priv = data;
3201 u32 inta, inta_mask;
3206 spin_lock(&priv->low_lock);
3208 /* We check to see if we should be ignoring interrupts before
3209 * we touch the hardware. During ucode load if we try and handle
3210 * an interrupt we can cause keyboard problems as well as cause
3211 * the ucode to fail to initialize */
3212 if (!(priv->status & STATUS_INT_ENABLED)) {
3217 read_register(priv->net_dev, IPW_REG_INTA_MASK, &inta_mask);
3218 read_register(priv->net_dev, IPW_REG_INTA, &inta);
3220 if (inta == 0xFFFFFFFF) {
3221 /* Hardware disappeared */
3222 IPW_DEBUG_WARNING("IRQ INTA == 0xFFFFFFFF\n");
3226 inta &= IPW_INTERRUPT_MASK;
3228 if (!(inta & inta_mask)) {
3229 /* Shared interrupt */
3233 /* We disable the hardware interrupt here just to prevent unneeded
3234 * calls to be made. We disable this again within the actual
3235 * work tasklet, so if another part of the code re-enables the
3236 * interrupt, that is fine */
3237 ipw2100_disable_interrupts(priv);
3239 tasklet_schedule(&priv->irq_tasklet);
3240 spin_unlock(&priv->low_lock);
3244 spin_unlock(&priv->low_lock);
3248 static int ipw2100_tx(struct ieee80211_txb *txb, struct net_device *dev)
3250 struct ipw2100_priv *priv = ieee80211_priv(dev);
3251 struct list_head *element;
3252 struct ipw2100_tx_packet *packet;
3253 unsigned long flags;
3255 spin_lock_irqsave(&priv->low_lock, flags);
3257 if (!(priv->status & STATUS_ASSOCIATED)) {
3258 IPW_DEBUG_INFO("Can not transmit when not connected.\n");
3259 priv->ieee->stats.tx_carrier_errors++;
3260 netif_stop_queue(dev);
3264 if (list_empty(&priv->tx_free_list))
3267 element = priv->tx_free_list.next;
3268 packet = list_entry(element, struct ipw2100_tx_packet, list);
3270 packet->info.d_struct.txb = txb;
3272 IPW_DEBUG_TX("Sending fragment (%d bytes):\n",
3273 txb->fragments[0]->len);
3274 printk_buf(IPW_DL_TX, txb->fragments[0]->data,
3275 txb->fragments[0]->len);
3277 packet->jiffy_start = jiffies;
3280 DEC_STAT(&priv->tx_free_stat);
3282 list_add_tail(element, &priv->tx_pend_list);
3283 INC_STAT(&priv->tx_pend_stat);
3285 ipw2100_tx_send_data(priv);
3287 spin_unlock_irqrestore(&priv->low_lock, flags);
3291 netif_stop_queue(dev);
3292 spin_unlock_irqrestore(&priv->low_lock, flags);
3297 static int ipw2100_msg_allocate(struct ipw2100_priv *priv)
3299 int i, j, err = -EINVAL;
3303 priv->msg_buffers = (struct ipw2100_tx_packet *)kmalloc(
3304 IPW_COMMAND_POOL_SIZE * sizeof(struct ipw2100_tx_packet),
3306 if (!priv->msg_buffers) {
3307 IPW_DEBUG_ERROR("%s: PCI alloc failed for msg "
3308 "buffers.\n", priv->net_dev->name);
3312 for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++) {
3313 v = pci_alloc_consistent(
3315 sizeof(struct ipw2100_cmd_header),
3319 "%s: PCI alloc failed for msg "
3321 priv->net_dev->name);
3326 memset(v, 0, sizeof(struct ipw2100_cmd_header));
3328 priv->msg_buffers[i].type = COMMAND;
3329 priv->msg_buffers[i].info.c_struct.cmd =
3330 (struct ipw2100_cmd_header*)v;
3331 priv->msg_buffers[i].info.c_struct.cmd_phys = p;
3334 if (i == IPW_COMMAND_POOL_SIZE)
3337 for (j = 0; j < i; j++) {
3338 pci_free_consistent(
3340 sizeof(struct ipw2100_cmd_header),
3341 priv->msg_buffers[j].info.c_struct.cmd,
3342 priv->msg_buffers[j].info.c_struct.cmd_phys);
3345 kfree(priv->msg_buffers);
3346 priv->msg_buffers = NULL;
3351 static int ipw2100_msg_initialize(struct ipw2100_priv *priv)
3355 INIT_LIST_HEAD(&priv->msg_free_list);
3356 INIT_LIST_HEAD(&priv->msg_pend_list);
3358 for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++)
3359 list_add_tail(&priv->msg_buffers[i].list, &priv->msg_free_list);
3360 SET_STAT(&priv->msg_free_stat, i);
3365 static void ipw2100_msg_free(struct ipw2100_priv *priv)
3369 if (!priv->msg_buffers)
3372 for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++) {
3373 pci_free_consistent(priv->pci_dev,
3374 sizeof(struct ipw2100_cmd_header),
3375 priv->msg_buffers[i].info.c_struct.cmd,
3376 priv->msg_buffers[i].info.c_struct.cmd_phys);
3379 kfree(priv->msg_buffers);
3380 priv->msg_buffers = NULL;
3383 static ssize_t show_pci(struct device *d, struct device_attribute *attr,
3386 struct pci_dev *pci_dev = container_of(d, struct pci_dev, dev);
3391 for (i = 0; i < 16; i++) {
3392 out += sprintf(out, "[%08X] ", i * 16);
3393 for (j = 0; j < 16; j += 4) {
3394 pci_read_config_dword(pci_dev, i * 16 + j, &val);
3395 out += sprintf(out, "%08X ", val);
3397 out += sprintf(out, "\n");
3402 static DEVICE_ATTR(pci, S_IRUGO, show_pci, NULL);
3404 static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
3407 struct ipw2100_priv *p = 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, struct device_attribute *attr,
3415 struct ipw2100_priv *p = d->driver_data;
3416 return sprintf(buf, "0x%08x\n", (int)p->status);
3418 static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
3420 static ssize_t show_capability(struct device *d, struct device_attribute *attr,
3423 struct ipw2100_priv *p = d->driver_data;
3424 return sprintf(buf, "0x%08x\n", (int)p->capability);
3426 static DEVICE_ATTR(capability, S_IRUGO, show_capability, NULL);
3429 #define IPW2100_REG(x) { IPW_ ##x, #x }
3434 IPW2100_REG(REG_GP_CNTRL),
3435 IPW2100_REG(REG_GPIO),
3436 IPW2100_REG(REG_INTA),
3437 IPW2100_REG(REG_INTA_MASK),
3438 IPW2100_REG(REG_RESET_REG),
3440 #define IPW2100_NIC(x, s) { x, #x, s }
3446 IPW2100_NIC(IPW2100_CONTROL_REG, 2),
3447 IPW2100_NIC(0x210014, 1),
3448 IPW2100_NIC(0x210000, 1),
3450 #define IPW2100_ORD(x, d) { IPW_ORD_ ##x, #x, d }
3456 IPW2100_ORD(STAT_TX_HOST_REQUESTS, "requested Host Tx's (MSDU)"),
3457 IPW2100_ORD(STAT_TX_HOST_COMPLETE, "successful Host Tx's (MSDU)"),
3458 IPW2100_ORD(STAT_TX_DIR_DATA, "successful Directed Tx's (MSDU)"),
3459 IPW2100_ORD(STAT_TX_DIR_DATA1, "successful Directed Tx's (MSDU) @ 1MB"),
3460 IPW2100_ORD(STAT_TX_DIR_DATA2, "successful Directed Tx's (MSDU) @ 2MB"),
3461 IPW2100_ORD(STAT_TX_DIR_DATA5_5, "successful Directed Tx's (MSDU) @ 5_5MB"),
3462 IPW2100_ORD(STAT_TX_DIR_DATA11, "successful Directed Tx's (MSDU) @ 11MB"),
3463 IPW2100_ORD(STAT_TX_NODIR_DATA1, "successful Non_Directed Tx's (MSDU) @ 1MB"),
3464 IPW2100_ORD(STAT_TX_NODIR_DATA2, "successful Non_Directed Tx's (MSDU) @ 2MB"),
3465 IPW2100_ORD(STAT_TX_NODIR_DATA5_5, "successful Non_Directed Tx's (MSDU) @ 5.5MB"),
3466 IPW2100_ORD(STAT_TX_NODIR_DATA11, "successful Non_Directed Tx's (MSDU) @ 11MB"),
3467 IPW2100_ORD(STAT_NULL_DATA, "successful NULL data Tx's"),
3468 IPW2100_ORD(STAT_TX_RTS, "successful Tx RTS"),
3469 IPW2100_ORD(STAT_TX_CTS, "successful Tx CTS"),
3470 IPW2100_ORD(STAT_TX_ACK, "successful Tx ACK"),
3471 IPW2100_ORD(STAT_TX_ASSN, "successful Association Tx's"),
3472 IPW2100_ORD(STAT_TX_ASSN_RESP, "successful Association response Tx's"),
3473 IPW2100_ORD(STAT_TX_REASSN, "successful Reassociation Tx's"),
3474 IPW2100_ORD(STAT_TX_REASSN_RESP, "successful Reassociation response Tx's"),
3475 IPW2100_ORD(STAT_TX_PROBE, "probes successfully transmitted"),
3476 IPW2100_ORD(STAT_TX_PROBE_RESP, "probe responses successfully transmitted"),
3477 IPW2100_ORD(STAT_TX_BEACON, "tx beacon"),
3478 IPW2100_ORD(STAT_TX_ATIM, "Tx ATIM"),
3479 IPW2100_ORD(STAT_TX_DISASSN, "successful Disassociation TX"),
3480 IPW2100_ORD(STAT_TX_AUTH, "successful Authentication Tx"),
3481 IPW2100_ORD(STAT_TX_DEAUTH, "successful Deauthentication TX"),
3482 IPW2100_ORD(STAT_TX_TOTAL_BYTES, "Total successful Tx data bytes"),
3483 IPW2100_ORD(STAT_TX_RETRIES, "Tx retries"),
3484 IPW2100_ORD(STAT_TX_RETRY1, "Tx retries at 1MBPS"),
3485 IPW2100_ORD(STAT_TX_RETRY2, "Tx retries at 2MBPS"),
3486 IPW2100_ORD(STAT_TX_RETRY5_5, "Tx retries at 5.5MBPS"),
3487 IPW2100_ORD(STAT_TX_RETRY11, "Tx retries at 11MBPS"),
3488 IPW2100_ORD(STAT_TX_FAILURES, "Tx Failures"),
3489 IPW2100_ORD(STAT_TX_MAX_TRIES_IN_HOP,"times max tries in a hop failed"),
3490 IPW2100_ORD(STAT_TX_DISASSN_FAIL, "times disassociation failed"),
3491 IPW2100_ORD(STAT_TX_ERR_CTS, "missed/bad CTS frames"),
3492 IPW2100_ORD(STAT_TX_ERR_ACK, "tx err due to acks"),
3493 IPW2100_ORD(STAT_RX_HOST, "packets passed to host"),
3494 IPW2100_ORD(STAT_RX_DIR_DATA, "directed packets"),
3495 IPW2100_ORD(STAT_RX_DIR_DATA1, "directed packets at 1MB"),
3496 IPW2100_ORD(STAT_RX_DIR_DATA2, "directed packets at 2MB"),
3497 IPW2100_ORD(STAT_RX_DIR_DATA5_5, "directed packets at 5.5MB"),
3498 IPW2100_ORD(STAT_RX_DIR_DATA11, "directed packets at 11MB"),
3499 IPW2100_ORD(STAT_RX_NODIR_DATA,"nondirected packets"),
3500 IPW2100_ORD(STAT_RX_NODIR_DATA1, "nondirected packets at 1MB"),
3501 IPW2100_ORD(STAT_RX_NODIR_DATA2, "nondirected packets at 2MB"),
3502 IPW2100_ORD(STAT_RX_NODIR_DATA5_5, "nondirected packets at 5.5MB"),
3503 IPW2100_ORD(STAT_RX_NODIR_DATA11, "nondirected packets at 11MB"),
3504 IPW2100_ORD(STAT_RX_NULL_DATA, "null data rx's"),
3505 IPW2100_ORD(STAT_RX_RTS, "Rx RTS"),
3506 IPW2100_ORD(STAT_RX_CTS, "Rx CTS"),
3507 IPW2100_ORD(STAT_RX_ACK, "Rx ACK"),
3508 IPW2100_ORD(STAT_RX_CFEND, "Rx CF End"),
3509 IPW2100_ORD(STAT_RX_CFEND_ACK, "Rx CF End + CF Ack"),
3510 IPW2100_ORD(STAT_RX_ASSN, "Association Rx's"),
3511 IPW2100_ORD(STAT_RX_ASSN_RESP, "Association response Rx's"),
3512 IPW2100_ORD(STAT_RX_REASSN, "Reassociation Rx's"),
3513 IPW2100_ORD(STAT_RX_REASSN_RESP, "Reassociation response Rx's"),
3514 IPW2100_ORD(STAT_RX_PROBE, "probe Rx's"),
3515 IPW2100_ORD(STAT_RX_PROBE_RESP, "probe response Rx's"),
3516 IPW2100_ORD(STAT_RX_BEACON, "Rx beacon"),
3517 IPW2100_ORD(STAT_RX_ATIM, "Rx ATIM"),
3518 IPW2100_ORD(STAT_RX_DISASSN, "disassociation Rx"),
3519 IPW2100_ORD(STAT_RX_AUTH, "authentication Rx"),
3520 IPW2100_ORD(STAT_RX_DEAUTH, "deauthentication Rx"),
3521 IPW2100_ORD(STAT_RX_TOTAL_BYTES,"Total rx data bytes received"),
3522 IPW2100_ORD(STAT_RX_ERR_CRC, "packets with Rx CRC error"),
3523 IPW2100_ORD(STAT_RX_ERR_CRC1, "Rx CRC errors at 1MB"),
3524 IPW2100_ORD(STAT_RX_ERR_CRC2, "Rx CRC errors at 2MB"),
3525 IPW2100_ORD(STAT_RX_ERR_CRC5_5, "Rx CRC errors at 5.5MB"),
3526 IPW2100_ORD(STAT_RX_ERR_CRC11, "Rx CRC errors at 11MB"),
3527 IPW2100_ORD(STAT_RX_DUPLICATE1, "duplicate rx packets at 1MB"),
3528 IPW2100_ORD(STAT_RX_DUPLICATE2, "duplicate rx packets at 2MB"),
3529 IPW2100_ORD(STAT_RX_DUPLICATE5_5, "duplicate rx packets at 5.5MB"),
3530 IPW2100_ORD(STAT_RX_DUPLICATE11, "duplicate rx packets at 11MB"),
3531 IPW2100_ORD(STAT_RX_DUPLICATE, "duplicate rx packets"),
3532 IPW2100_ORD(PERS_DB_LOCK, "locking fw permanent db"),
3533 IPW2100_ORD(PERS_DB_SIZE, "size of fw permanent db"),
3534 IPW2100_ORD(PERS_DB_ADDR, "address of fw permanent db"),
3535 IPW2100_ORD(STAT_RX_INVALID_PROTOCOL, "rx frames with invalid protocol"),
3536 IPW2100_ORD(SYS_BOOT_TIME, "Boot time"),
3537 IPW2100_ORD(STAT_RX_NO_BUFFER, "rx frames rejected due to no buffer"),
3538 IPW2100_ORD(STAT_RX_MISSING_FRAG, "rx frames dropped due to missing fragment"),
3539 IPW2100_ORD(STAT_RX_ORPHAN_FRAG, "rx frames dropped due to non-sequential fragment"),
3540 IPW2100_ORD(STAT_RX_ORPHAN_FRAME, "rx frames dropped due to unmatched 1st frame"),
3541 IPW2100_ORD(STAT_RX_FRAG_AGEOUT, "rx frames dropped due to uncompleted frame"),
3542 IPW2100_ORD(STAT_RX_ICV_ERRORS, "ICV errors during decryption"),
3543 IPW2100_ORD(STAT_PSP_SUSPENSION,"times adapter suspended"),
3544 IPW2100_ORD(STAT_PSP_BCN_TIMEOUT, "beacon timeout"),
3545 IPW2100_ORD(STAT_PSP_POLL_TIMEOUT, "poll response timeouts"),
3546 IPW2100_ORD(STAT_PSP_NONDIR_TIMEOUT, "timeouts waiting for last {broad,multi}cast pkt"),
3547 IPW2100_ORD(STAT_PSP_RX_DTIMS, "PSP DTIMs received"),
3548 IPW2100_ORD(STAT_PSP_RX_TIMS, "PSP TIMs received"),
3549 IPW2100_ORD(STAT_PSP_STATION_ID,"PSP Station ID"),
3550 IPW2100_ORD(LAST_ASSN_TIME, "RTC time of last association"),
3551 IPW2100_ORD(STAT_PERCENT_MISSED_BCNS,"current calculation of % missed beacons"),
3552 IPW2100_ORD(STAT_PERCENT_RETRIES,"current calculation of % missed tx retries"),
3553 IPW2100_ORD(ASSOCIATED_AP_PTR, "0 if not associated, else pointer to AP table entry"),
3554 IPW2100_ORD(AVAILABLE_AP_CNT, "AP's decsribed in the AP table"),
3555 IPW2100_ORD(AP_LIST_PTR, "Ptr to list of available APs"),
3556 IPW2100_ORD(STAT_AP_ASSNS, "associations"),
3557 IPW2100_ORD(STAT_ASSN_FAIL, "association failures"),
3558 IPW2100_ORD(STAT_ASSN_RESP_FAIL,"failures due to response fail"),
3559 IPW2100_ORD(STAT_FULL_SCANS, "full scans"),
3560 IPW2100_ORD(CARD_DISABLED, "Card Disabled"),
3561 IPW2100_ORD(STAT_ROAM_INHIBIT, "times roaming was inhibited due to activity"),
3562 IPW2100_ORD(RSSI_AT_ASSN, "RSSI of associated AP at time of association"),
3563 IPW2100_ORD(STAT_ASSN_CAUSE1, "reassociation: no probe response or TX on hop"),
3564 IPW2100_ORD(STAT_ASSN_CAUSE2, "reassociation: poor tx/rx quality"),
3565 IPW2100_ORD(STAT_ASSN_CAUSE3, "reassociation: tx/rx quality (excessive AP load"),
3566 IPW2100_ORD(STAT_ASSN_CAUSE4, "reassociation: AP RSSI level"),
3567 IPW2100_ORD(STAT_ASSN_CAUSE5, "reassociations due to load leveling"),
3568 IPW2100_ORD(STAT_AUTH_FAIL, "times authentication failed"),
3569 IPW2100_ORD(STAT_AUTH_RESP_FAIL,"times authentication response failed"),
3570 IPW2100_ORD(STATION_TABLE_CNT, "entries in association table"),
3571 IPW2100_ORD(RSSI_AVG_CURR, "Current avg RSSI"),
3572 IPW2100_ORD(POWER_MGMT_MODE, "Power mode - 0=CAM, 1=PSP"),
3573 IPW2100_ORD(COUNTRY_CODE, "IEEE country code as recv'd from beacon"),
3574 IPW2100_ORD(COUNTRY_CHANNELS, "channels suported by country"),
3575 IPW2100_ORD(RESET_CNT, "adapter resets (warm)"),
3576 IPW2100_ORD(BEACON_INTERVAL, "Beacon interval"),
3577 IPW2100_ORD(ANTENNA_DIVERSITY, "TRUE if antenna diversity is disabled"),
3578 IPW2100_ORD(DTIM_PERIOD, "beacon intervals between DTIMs"),
3579 IPW2100_ORD(OUR_FREQ, "current radio freq lower digits - channel ID"),
3580 IPW2100_ORD(RTC_TIME, "current RTC time"),
3581 IPW2100_ORD(PORT_TYPE, "operating mode"),
3582 IPW2100_ORD(CURRENT_TX_RATE, "current tx rate"),
3583 IPW2100_ORD(SUPPORTED_RATES, "supported tx rates"),
3584 IPW2100_ORD(ATIM_WINDOW, "current ATIM Window"),
3585 IPW2100_ORD(BASIC_RATES, "basic tx rates"),
3586 IPW2100_ORD(NIC_HIGHEST_RATE, "NIC highest tx rate"),
3587 IPW2100_ORD(AP_HIGHEST_RATE, "AP highest tx rate"),
3588 IPW2100_ORD(CAPABILITIES, "Management frame capability field"),
3589 IPW2100_ORD(AUTH_TYPE, "Type of authentication"),
3590 IPW2100_ORD(RADIO_TYPE, "Adapter card platform type"),
3591 IPW2100_ORD(RTS_THRESHOLD, "Min packet length for RTS handshaking"),
3592 IPW2100_ORD(INT_MODE, "International mode"),
3593 IPW2100_ORD(FRAGMENTATION_THRESHOLD, "protocol frag threshold"),
3594 IPW2100_ORD(EEPROM_SRAM_DB_BLOCK_START_ADDRESS, "EEPROM offset in SRAM"),
3595 IPW2100_ORD(EEPROM_SRAM_DB_BLOCK_SIZE, "EEPROM size in SRAM"),
3596 IPW2100_ORD(EEPROM_SKU_CAPABILITY, "EEPROM SKU Capability"),
3597 IPW2100_ORD(EEPROM_IBSS_11B_CHANNELS, "EEPROM IBSS 11b channel set"),
3598 IPW2100_ORD(MAC_VERSION, "MAC Version"),
3599 IPW2100_ORD(MAC_REVISION, "MAC Revision"),
3600 IPW2100_ORD(RADIO_VERSION, "Radio Version"),
3601 IPW2100_ORD(NIC_MANF_DATE_TIME, "MANF Date/Time STAMP"),
3602 IPW2100_ORD(UCODE_VERSION, "Ucode Version"),
3606 static ssize_t show_registers(struct device *d, struct device_attribute *attr,
3610 struct ipw2100_priv *priv = dev_get_drvdata(d);
3611 struct net_device *dev = priv->net_dev;
3615 out += sprintf(out, "%30s [Address ] : Hex\n", "Register");
3617 for (i = 0; i < (sizeof(hw_data) / sizeof(*hw_data)); i++) {
3618 read_register(dev, hw_data[i].addr, &val);
3619 out += sprintf(out, "%30s [%08X] : %08X\n",
3620 hw_data[i].name, hw_data[i].addr, val);
3625 static DEVICE_ATTR(registers, S_IRUGO, show_registers, NULL);
3628 static ssize_t show_hardware(struct device *d, struct device_attribute *attr,
3631 struct ipw2100_priv *priv = dev_get_drvdata(d);
3632 struct net_device *dev = priv->net_dev;
3636 out += sprintf(out, "%30s [Address ] : Hex\n", "NIC entry");
3638 for (i = 0; i < (sizeof(nic_data) / sizeof(*nic_data)); i++) {
3643 switch (nic_data[i].size) {
3645 read_nic_byte(dev, nic_data[i].addr, &tmp8);
3646 out += sprintf(out, "%30s [%08X] : %02X\n",
3647 nic_data[i].name, nic_data[i].addr,
3651 read_nic_word(dev, nic_data[i].addr, &tmp16);
3652 out += sprintf(out, "%30s [%08X] : %04X\n",
3653 nic_data[i].name, nic_data[i].addr,
3657 read_nic_dword(dev, nic_data[i].addr, &tmp32);
3658 out += sprintf(out, "%30s [%08X] : %08X\n",
3659 nic_data[i].name, nic_data[i].addr,
3666 static DEVICE_ATTR(hardware, S_IRUGO, show_hardware, NULL);
3669 static ssize_t show_memory(struct device *d, struct device_attribute *attr,
3672 struct ipw2100_priv *priv = dev_get_drvdata(d);
3673 struct net_device *dev = priv->net_dev;
3674 static unsigned long loop = 0;
3680 if (loop >= 0x30000)
3683 /* sysfs provides us PAGE_SIZE buffer */
3684 while (len < PAGE_SIZE - 128 && loop < 0x30000) {
3686 if (priv->snapshot[0]) for (i = 0; i < 4; i++)
3687 buffer[i] = *(u32 *)SNAPSHOT_ADDR(loop + i * 4);
3688 else for (i = 0; i < 4; i++)
3689 read_nic_dword(dev, loop + i * 4, &buffer[i]);
3692 len += sprintf(buf + len,
3712 ((u8*)buffer)[0xf]);
3714 len += sprintf(buf + len, "%s\n",
3715 snprint_line(line, sizeof(line),
3716 (u8*)buffer, 16, loop));
3723 static ssize_t store_memory(struct device *d, struct device_attribute *attr,
3724 const char *buf, size_t count)
3726 struct ipw2100_priv *priv = dev_get_drvdata(d);
3727 struct net_device *dev = priv->net_dev;
3728 const char *p = buf;
3734 (count >= 2 && tolower(p[0]) == 'o' && tolower(p[1]) == 'n')) {
3735 IPW_DEBUG_INFO("%s: Setting memory dump to RAW mode.\n",
3739 } else if (p[0] == '0' || (count >= 2 && tolower(p[0]) == 'o' &&
3740 tolower(p[1]) == 'f')) {
3741 IPW_DEBUG_INFO("%s: Setting memory dump to HEX mode.\n",
3745 } else if (tolower(p[0]) == 'r') {
3746 IPW_DEBUG_INFO("%s: Resetting firmware snapshot.\n",
3748 ipw2100_snapshot_free(priv);
3751 IPW_DEBUG_INFO("%s: Usage: 0|on = HEX, 1|off = RAW, "
3752 "reset = clear memory snapshot\n",
3757 static DEVICE_ATTR(memory, S_IWUSR|S_IRUGO, show_memory, store_memory);
3760 static ssize_t show_ordinals(struct device *d, struct device_attribute *attr,
3763 struct ipw2100_priv *priv = dev_get_drvdata(d);
3767 static int loop = 0;
3769 if (loop >= sizeof(ord_data) / sizeof(*ord_data))
3772 /* sysfs provides us PAGE_SIZE buffer */
3773 while (len < PAGE_SIZE - 128 &&
3774 loop < (sizeof(ord_data) / sizeof(*ord_data))) {
3776 val_len = sizeof(u32);
3778 if (ipw2100_get_ordinal(priv, ord_data[loop].index, &val,
3780 len += sprintf(buf + len, "[0x%02X] = ERROR %s\n",
3781 ord_data[loop].index,
3782 ord_data[loop].desc);
3784 len += sprintf(buf + len, "[0x%02X] = 0x%08X %s\n",
3785 ord_data[loop].index, val,
3786 ord_data[loop].desc);
3792 static DEVICE_ATTR(ordinals, S_IRUGO, show_ordinals, NULL);
3795 static ssize_t show_stats(struct device *d, struct device_attribute *attr,
3798 struct ipw2100_priv *priv = dev_get_drvdata(d);
3801 out += sprintf(out, "interrupts: %d {tx: %d, rx: %d, other: %d}\n",
3802 priv->interrupts, priv->tx_interrupts,
3803 priv->rx_interrupts, priv->inta_other);
3804 out += sprintf(out, "firmware resets: %d\n", priv->resets);
3805 out += sprintf(out, "firmware hangs: %d\n", priv->hangs);
3806 #ifdef CONFIG_IPW_DEBUG
3807 out += sprintf(out, "packet mismatch image: %s\n",
3808 priv->snapshot[0] ? "YES" : "NO");
3813 static DEVICE_ATTR(stats, S_IRUGO, show_stats, NULL);
3816 int ipw2100_switch_mode(struct ipw2100_priv *priv, u32 mode)
3820 if (mode == priv->ieee->iw_mode)
3823 err = ipw2100_disable_adapter(priv);
3825 IPW_DEBUG_ERROR("%s: Could not disable adapter %d\n",
3826 priv->net_dev->name, err);
3832 priv->net_dev->type = ARPHRD_ETHER;
3835 priv->net_dev->type = ARPHRD_ETHER;
3837 #ifdef CONFIG_IPW2100_MONITOR
3838 case IW_MODE_MONITOR:
3839 priv->last_mode = priv->ieee->iw_mode;
3840 priv->net_dev->type = ARPHRD_IEEE80211;
3842 #endif /* CONFIG_IPW2100_MONITOR */
3845 priv->ieee->iw_mode = mode;
3848 /* Indicate ipw2100_download_firmware download firmware
3849 * from disk instead of memory. */
3850 ipw2100_firmware.version = 0;
3853 printk(KERN_INFO "%s: Reseting on mode change.\n",
3854 priv->net_dev->name);
3855 priv->reset_backoff = 0;
3856 schedule_reset(priv);
3861 static ssize_t show_internals(struct device *d, struct device_attribute *attr,
3864 struct ipw2100_priv *priv = dev_get_drvdata(d);
3867 #define DUMP_VAR(x,y) len += sprintf(buf + len, # x ": %" # y "\n", priv-> x)
3869 if (priv->status & STATUS_ASSOCIATED)
3870 len += sprintf(buf + len, "connected: %lu\n",
3871 get_seconds() - priv->connect_start);
3873 len += sprintf(buf + len, "not connected\n");
3875 DUMP_VAR(ieee->crypt[priv->ieee->tx_keyidx], p);
3876 DUMP_VAR(status, 08lx);
3877 DUMP_VAR(config, 08lx);
3878 DUMP_VAR(capability, 08lx);
3880 len += sprintf(buf + len, "last_rtc: %lu\n", (unsigned long)priv->last_rtc);
3882 DUMP_VAR(fatal_error, d);
3883 DUMP_VAR(stop_hang_check, d);
3884 DUMP_VAR(stop_rf_kill, d);
3885 DUMP_VAR(messages_sent, d);
3887 DUMP_VAR(tx_pend_stat.value, d);
3888 DUMP_VAR(tx_pend_stat.hi, d);
3890 DUMP_VAR(tx_free_stat.value, d);
3891 DUMP_VAR(tx_free_stat.lo, d);
3893 DUMP_VAR(msg_free_stat.value, d);
3894 DUMP_VAR(msg_free_stat.lo, d);
3896 DUMP_VAR(msg_pend_stat.value, d);
3897 DUMP_VAR(msg_pend_stat.hi, d);
3899 DUMP_VAR(fw_pend_stat.value, d);
3900 DUMP_VAR(fw_pend_stat.hi, d);
3902 DUMP_VAR(txq_stat.value, d);
3903 DUMP_VAR(txq_stat.lo, d);
3905 DUMP_VAR(ieee->scans, d);
3906 DUMP_VAR(reset_backoff, d);
3910 static DEVICE_ATTR(internals, S_IRUGO, show_internals, NULL);
3913 static ssize_t show_bssinfo(struct device *d, struct device_attribute *attr,
3916 struct ipw2100_priv *priv = dev_get_drvdata(d);
3917 char essid[IW_ESSID_MAX_SIZE + 1];
3924 memset(essid, 0, sizeof(essid));
3925 memset(bssid, 0, sizeof(bssid));
3927 length = IW_ESSID_MAX_SIZE;
3928 ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_SSID, essid, &length);
3930 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
3933 length = sizeof(bssid);
3934 ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID,
3937 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
3940 length = sizeof(u32);
3941 ret = ipw2100_get_ordinal(priv, IPW_ORD_OUR_FREQ, &chan, &length);
3943 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
3946 out += sprintf(out, "ESSID: %s\n", essid);
3947 out += sprintf(out, "BSSID: %02x:%02x:%02x:%02x:%02x:%02x\n",
3948 bssid[0], bssid[1], bssid[2],
3949 bssid[3], bssid[4], bssid[5]);
3950 out += sprintf(out, "Channel: %d\n", chan);
3954 static DEVICE_ATTR(bssinfo, S_IRUGO, show_bssinfo, NULL);
3957 #ifdef CONFIG_IPW_DEBUG
3958 static ssize_t show_debug_level(struct device_driver *d, char *buf)
3960 return sprintf(buf, "0x%08X\n", ipw2100_debug_level);
3963 static ssize_t store_debug_level(struct device_driver *d, const char *buf,
3966 char *p = (char *)buf;
3969 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
3971 if (p[0] == 'x' || p[0] == 'X')
3973 val = simple_strtoul(p, &p, 16);
3975 val = simple_strtoul(p, &p, 10);
3977 IPW_DEBUG_INFO(DRV_NAME
3978 ": %s is not in hex or decimal form.\n", buf);
3980 ipw2100_debug_level = val;
3982 return strnlen(buf, count);
3984 static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, show_debug_level,
3986 #endif /* CONFIG_IPW_DEBUG */
3989 static ssize_t show_fatal_error(struct device *d,
3990 struct device_attribute *attr, char *buf)
3992 struct ipw2100_priv *priv = dev_get_drvdata(d);
3996 if (priv->fatal_error)
3997 out += sprintf(out, "0x%08X\n",
4000 out += sprintf(out, "0\n");
4002 for (i = 1; i <= IPW2100_ERROR_QUEUE; i++) {
4003 if (!priv->fatal_errors[(priv->fatal_index - i) %
4004 IPW2100_ERROR_QUEUE])
4007 out += sprintf(out, "%d. 0x%08X\n", i,
4008 priv->fatal_errors[(priv->fatal_index - i) %
4009 IPW2100_ERROR_QUEUE]);
4015 static ssize_t store_fatal_error(struct device *d,
4016 struct device_attribute *attr, const char *buf, size_t count)
4018 struct ipw2100_priv *priv = dev_get_drvdata(d);
4019 schedule_reset(priv);
4022 static DEVICE_ATTR(fatal_error, S_IWUSR|S_IRUGO, show_fatal_error, store_fatal_error);
4025 static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
4028 struct ipw2100_priv *priv = dev_get_drvdata(d);
4029 return sprintf(buf, "%d\n", priv->ieee->scan_age);
4032 static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
4033 const char *buf, size_t count)
4035 struct ipw2100_priv *priv = dev_get_drvdata(d);
4036 struct net_device *dev = priv->net_dev;
4037 char buffer[] = "00000000";
4039 (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
4043 IPW_DEBUG_INFO("enter\n");
4045 strncpy(buffer, buf, len);
4048 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
4050 if (p[0] == 'x' || p[0] == 'X')
4052 val = simple_strtoul(p, &p, 16);
4054 val = simple_strtoul(p, &p, 10);
4056 IPW_DEBUG_INFO("%s: user supplied invalid value.\n",
4059 priv->ieee->scan_age = val;
4060 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
4063 IPW_DEBUG_INFO("exit\n");
4066 static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
4069 static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
4072 /* 0 - RF kill not enabled
4073 1 - SW based RF kill active (sysfs)
4074 2 - HW based RF kill active
4075 3 - Both HW and SW baed RF kill active */
4076 struct ipw2100_priv *priv = (struct ipw2100_priv *)d->driver_data;
4077 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
4078 (rf_kill_active(priv) ? 0x2 : 0x0);
4079 return sprintf(buf, "%i\n", val);
4082 static int ipw_radio_kill_sw(struct ipw2100_priv *priv, int disable_radio)
4084 if ((disable_radio ? 1 : 0) ==
4085 (priv->status & STATUS_RF_KILL_SW ? 1 : 0))
4088 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
4089 disable_radio ? "OFF" : "ON");
4091 down(&priv->action_sem);
4093 if (disable_radio) {
4094 priv->status |= STATUS_RF_KILL_SW;
4097 priv->status &= ~STATUS_RF_KILL_SW;
4098 if (rf_kill_active(priv)) {
4099 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
4100 "disabled by HW switch\n");
4101 /* Make sure the RF_KILL check timer is running */
4102 priv->stop_rf_kill = 0;
4103 cancel_delayed_work(&priv->rf_kill);
4104 queue_delayed_work(priv->workqueue, &priv->rf_kill,
4107 schedule_reset(priv);
4110 up(&priv->action_sem);
4114 static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
4115 const char *buf, size_t count)
4117 struct ipw2100_priv *priv = dev_get_drvdata(d);
4118 ipw_radio_kill_sw(priv, buf[0] == '1');
4121 static DEVICE_ATTR(rf_kill, S_IWUSR|S_IRUGO, show_rf_kill, store_rf_kill);
4124 static struct attribute *ipw2100_sysfs_entries[] = {
4125 &dev_attr_hardware.attr,
4126 &dev_attr_registers.attr,
4127 &dev_attr_ordinals.attr,
4129 &dev_attr_stats.attr,
4130 &dev_attr_internals.attr,
4131 &dev_attr_bssinfo.attr,
4132 &dev_attr_memory.attr,
4133 &dev_attr_scan_age.attr,
4134 &dev_attr_fatal_error.attr,
4135 &dev_attr_rf_kill.attr,
4137 &dev_attr_status.attr,
4138 &dev_attr_capability.attr,
4142 static struct attribute_group ipw2100_attribute_group = {
4143 .attrs = ipw2100_sysfs_entries,
4147 static int status_queue_allocate(struct ipw2100_priv *priv, int entries)
4149 struct ipw2100_status_queue *q = &priv->status_queue;
4151 IPW_DEBUG_INFO("enter\n");
4153 q->size = entries * sizeof(struct ipw2100_status);
4154 q->drv = (struct ipw2100_status *)pci_alloc_consistent(
4155 priv->pci_dev, q->size, &q->nic);
4158 "Can not allocate status queue.\n");
4162 memset(q->drv, 0, q->size);
4164 IPW_DEBUG_INFO("exit\n");
4169 static void status_queue_free(struct ipw2100_priv *priv)
4171 IPW_DEBUG_INFO("enter\n");
4173 if (priv->status_queue.drv) {
4174 pci_free_consistent(
4175 priv->pci_dev, priv->status_queue.size,
4176 priv->status_queue.drv, priv->status_queue.nic);
4177 priv->status_queue.drv = NULL;
4180 IPW_DEBUG_INFO("exit\n");
4183 static int bd_queue_allocate(struct ipw2100_priv *priv,
4184 struct ipw2100_bd_queue *q, int entries)
4186 IPW_DEBUG_INFO("enter\n");
4188 memset(q, 0, sizeof(struct ipw2100_bd_queue));
4190 q->entries = entries;
4191 q->size = entries * sizeof(struct ipw2100_bd);
4192 q->drv = pci_alloc_consistent(priv->pci_dev, q->size, &q->nic);
4194 IPW_DEBUG_INFO("can't allocate shared memory for buffer descriptors\n");
4197 memset(q->drv, 0, q->size);
4199 IPW_DEBUG_INFO("exit\n");
4204 static void bd_queue_free(struct ipw2100_priv *priv,
4205 struct ipw2100_bd_queue *q)
4207 IPW_DEBUG_INFO("enter\n");
4213 pci_free_consistent(priv->pci_dev,
4214 q->size, q->drv, q->nic);
4218 IPW_DEBUG_INFO("exit\n");
4221 static void bd_queue_initialize(
4222 struct ipw2100_priv *priv, struct ipw2100_bd_queue * q,
4223 u32 base, u32 size, u32 r, u32 w)
4225 IPW_DEBUG_INFO("enter\n");
4227 IPW_DEBUG_INFO("initializing bd queue at virt=%p, phys=%08x\n", q->drv, (u32)q->nic);
4229 write_register(priv->net_dev, base, q->nic);
4230 write_register(priv->net_dev, size, q->entries);
4231 write_register(priv->net_dev, r, q->oldest);
4232 write_register(priv->net_dev, w, q->next);
4234 IPW_DEBUG_INFO("exit\n");
4237 static void ipw2100_kill_workqueue(struct ipw2100_priv *priv)
4239 if (priv->workqueue) {
4240 priv->stop_rf_kill = 1;
4241 priv->stop_hang_check = 1;
4242 cancel_delayed_work(&priv->reset_work);
4243 cancel_delayed_work(&priv->security_work);
4244 cancel_delayed_work(&priv->wx_event_work);
4245 cancel_delayed_work(&priv->hang_check);
4246 cancel_delayed_work(&priv->rf_kill);
4247 destroy_workqueue(priv->workqueue);
4248 priv->workqueue = NULL;
4252 static int ipw2100_tx_allocate(struct ipw2100_priv *priv)
4254 int i, j, err = -EINVAL;
4258 IPW_DEBUG_INFO("enter\n");
4260 err = bd_queue_allocate(priv, &priv->tx_queue, TX_QUEUE_LENGTH);
4262 IPW_DEBUG_ERROR("%s: failed bd_queue_allocate\n",
4263 priv->net_dev->name);
4267 priv->tx_buffers = (struct ipw2100_tx_packet *)kmalloc(
4268 TX_PENDED_QUEUE_LENGTH * sizeof(struct ipw2100_tx_packet),
4270 if (!priv->tx_buffers) {
4271 IPW_DEBUG_ERROR("%s: alloc failed form tx buffers.\n",
4272 priv->net_dev->name);
4273 bd_queue_free(priv, &priv->tx_queue);
4277 for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
4278 v = pci_alloc_consistent(
4279 priv->pci_dev, sizeof(struct ipw2100_data_header), &p);
4281 IPW_DEBUG_ERROR("%s: PCI alloc failed for tx "
4282 "buffers.\n", priv->net_dev->name);
4287 priv->tx_buffers[i].type = DATA;
4288 priv->tx_buffers[i].info.d_struct.data = (struct ipw2100_data_header*)v;
4289 priv->tx_buffers[i].info.d_struct.data_phys = p;
4290 priv->tx_buffers[i].info.d_struct.txb = NULL;
4293 if (i == TX_PENDED_QUEUE_LENGTH)
4296 for (j = 0; j < i; j++) {
4297 pci_free_consistent(
4299 sizeof(struct ipw2100_data_header),
4300 priv->tx_buffers[j].info.d_struct.data,
4301 priv->tx_buffers[j].info.d_struct.data_phys);
4304 kfree(priv->tx_buffers);
4305 priv->tx_buffers = NULL;
4310 static void ipw2100_tx_initialize(struct ipw2100_priv *priv)
4314 IPW_DEBUG_INFO("enter\n");
4317 * reinitialize packet info lists
4319 INIT_LIST_HEAD(&priv->fw_pend_list);
4320 INIT_STAT(&priv->fw_pend_stat);
4323 * reinitialize lists
4325 INIT_LIST_HEAD(&priv->tx_pend_list);
4326 INIT_LIST_HEAD(&priv->tx_free_list);
4327 INIT_STAT(&priv->tx_pend_stat);
4328 INIT_STAT(&priv->tx_free_stat);
4330 for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
4331 /* We simply drop any SKBs that have been queued for
4333 if (priv->tx_buffers[i].info.d_struct.txb) {
4334 ieee80211_txb_free(priv->tx_buffers[i].info.d_struct.txb);
4335 priv->tx_buffers[i].info.d_struct.txb = NULL;
4338 list_add_tail(&priv->tx_buffers[i].list, &priv->tx_free_list);
4341 SET_STAT(&priv->tx_free_stat, i);
4343 priv->tx_queue.oldest = 0;
4344 priv->tx_queue.available = priv->tx_queue.entries;
4345 priv->tx_queue.next = 0;
4346 INIT_STAT(&priv->txq_stat);
4347 SET_STAT(&priv->txq_stat, priv->tx_queue.available);
4349 bd_queue_initialize(priv, &priv->tx_queue,
4350 IPW_MEM_HOST_SHARED_TX_QUEUE_BD_BASE,
4351 IPW_MEM_HOST_SHARED_TX_QUEUE_BD_SIZE,
4352 IPW_MEM_HOST_SHARED_TX_QUEUE_READ_INDEX,
4353 IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX);
4355 IPW_DEBUG_INFO("exit\n");
4359 static void ipw2100_tx_free(struct ipw2100_priv *priv)
4363 IPW_DEBUG_INFO("enter\n");
4365 bd_queue_free(priv, &priv->tx_queue);
4367 if (!priv->tx_buffers)
4370 for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
4371 if (priv->tx_buffers[i].info.d_struct.txb) {
4372 ieee80211_txb_free(priv->tx_buffers[i].info.d_struct.txb);
4373 priv->tx_buffers[i].info.d_struct.txb = NULL;
4375 if (priv->tx_buffers[i].info.d_struct.data)
4376 pci_free_consistent(
4378 sizeof(struct ipw2100_data_header),
4379 priv->tx_buffers[i].info.d_struct.data,
4380 priv->tx_buffers[i].info.d_struct.data_phys);
4383 kfree(priv->tx_buffers);
4384 priv->tx_buffers = NULL;
4386 IPW_DEBUG_INFO("exit\n");
4391 static int ipw2100_rx_allocate(struct ipw2100_priv *priv)
4393 int i, j, err = -EINVAL;
4395 IPW_DEBUG_INFO("enter\n");
4397 err = bd_queue_allocate(priv, &priv->rx_queue, RX_QUEUE_LENGTH);
4399 IPW_DEBUG_INFO("failed bd_queue_allocate\n");
4403 err = status_queue_allocate(priv, RX_QUEUE_LENGTH);
4405 IPW_DEBUG_INFO("failed status_queue_allocate\n");
4406 bd_queue_free(priv, &priv->rx_queue);
4413 priv->rx_buffers = (struct ipw2100_rx_packet *)
4414 kmalloc(RX_QUEUE_LENGTH * sizeof(struct ipw2100_rx_packet),
4416 if (!priv->rx_buffers) {
4417 IPW_DEBUG_INFO("can't allocate rx packet buffer table\n");
4419 bd_queue_free(priv, &priv->rx_queue);
4421 status_queue_free(priv);
4426 for (i = 0; i < RX_QUEUE_LENGTH; i++) {
4427 struct ipw2100_rx_packet *packet = &priv->rx_buffers[i];
4429 err = ipw2100_alloc_skb(priv, packet);
4430 if (unlikely(err)) {
4435 /* The BD holds the cache aligned address */
4436 priv->rx_queue.drv[i].host_addr = packet->dma_addr;
4437 priv->rx_queue.drv[i].buf_length = IPW_RX_NIC_BUFFER_LENGTH;
4438 priv->status_queue.drv[i].status_fields = 0;
4441 if (i == RX_QUEUE_LENGTH)
4444 for (j = 0; j < i; j++) {
4445 pci_unmap_single(priv->pci_dev, priv->rx_buffers[j].dma_addr,
4446 sizeof(struct ipw2100_rx_packet),
4447 PCI_DMA_FROMDEVICE);
4448 dev_kfree_skb(priv->rx_buffers[j].skb);
4451 kfree(priv->rx_buffers);
4452 priv->rx_buffers = NULL;
4454 bd_queue_free(priv, &priv->rx_queue);
4456 status_queue_free(priv);
4461 static void ipw2100_rx_initialize(struct ipw2100_priv *priv)
4463 IPW_DEBUG_INFO("enter\n");
4465 priv->rx_queue.oldest = 0;
4466 priv->rx_queue.available = priv->rx_queue.entries - 1;
4467 priv->rx_queue.next = priv->rx_queue.entries - 1;
4469 INIT_STAT(&priv->rxq_stat);
4470 SET_STAT(&priv->rxq_stat, priv->rx_queue.available);
4472 bd_queue_initialize(priv, &priv->rx_queue,
4473 IPW_MEM_HOST_SHARED_RX_BD_BASE,
4474 IPW_MEM_HOST_SHARED_RX_BD_SIZE,
4475 IPW_MEM_HOST_SHARED_RX_READ_INDEX,
4476 IPW_MEM_HOST_SHARED_RX_WRITE_INDEX);
4478 /* set up the status queue */
4479 write_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_STATUS_BASE,
4480 priv->status_queue.nic);
4482 IPW_DEBUG_INFO("exit\n");
4485 static void ipw2100_rx_free(struct ipw2100_priv *priv)
4489 IPW_DEBUG_INFO("enter\n");
4491 bd_queue_free(priv, &priv->rx_queue);
4492 status_queue_free(priv);
4494 if (!priv->rx_buffers)
4497 for (i = 0; i < RX_QUEUE_LENGTH; i++) {
4498 if (priv->rx_buffers[i].rxp) {
4499 pci_unmap_single(priv->pci_dev,
4500 priv->rx_buffers[i].dma_addr,
4501 sizeof(struct ipw2100_rx),
4502 PCI_DMA_FROMDEVICE);
4503 dev_kfree_skb(priv->rx_buffers[i].skb);
4507 kfree(priv->rx_buffers);
4508 priv->rx_buffers = NULL;
4510 IPW_DEBUG_INFO("exit\n");
4513 static int ipw2100_read_mac_address(struct ipw2100_priv *priv)
4515 u32 length = ETH_ALEN;
4520 err = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ADAPTER_MAC,
4523 IPW_DEBUG_INFO("MAC address read failed\n");
4526 IPW_DEBUG_INFO("card MAC is %02X:%02X:%02X:%02X:%02X:%02X\n",
4527 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
4529 memcpy(priv->net_dev->dev_addr, mac, ETH_ALEN);
4534 /********************************************************************
4538 ********************************************************************/
4540 int ipw2100_set_mac_address(struct ipw2100_priv *priv, int batch_mode)
4542 struct host_command cmd = {
4543 .host_command = ADAPTER_ADDRESS,
4544 .host_command_sequence = 0,
4545 .host_command_length = ETH_ALEN
4549 IPW_DEBUG_HC("SET_MAC_ADDRESS\n");
4551 IPW_DEBUG_INFO("enter\n");
4553 if (priv->config & CFG_CUSTOM_MAC) {
4554 memcpy(cmd.host_command_parameters, priv->mac_addr,
4556 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
4558 memcpy(cmd.host_command_parameters, priv->net_dev->dev_addr,
4561 err = ipw2100_hw_send_command(priv, &cmd);
4563 IPW_DEBUG_INFO("exit\n");
4567 int ipw2100_set_port_type(struct ipw2100_priv *priv, u32 port_type,
4570 struct host_command cmd = {
4571 .host_command = PORT_TYPE,
4572 .host_command_sequence = 0,
4573 .host_command_length = sizeof(u32)
4577 switch (port_type) {
4579 cmd.host_command_parameters[0] = IPW_BSS;
4582 cmd.host_command_parameters[0] = IPW_IBSS;
4586 IPW_DEBUG_HC("PORT_TYPE: %s\n",
4587 port_type == IPW_IBSS ? "Ad-Hoc" : "Managed");
4590 err = ipw2100_disable_adapter(priv);
4592 IPW_DEBUG_ERROR("%s: Could not disable adapter %d\n",
4593 priv->net_dev->name, err);
4598 /* send cmd to firmware */
4599 err = ipw2100_hw_send_command(priv, &cmd);
4602 ipw2100_enable_adapter(priv);
4608 int ipw2100_set_channel(struct ipw2100_priv *priv, u32 channel, int batch_mode)
4610 struct host_command cmd = {
4611 .host_command = CHANNEL,
4612 .host_command_sequence = 0,
4613 .host_command_length = sizeof(u32)
4617 cmd.host_command_parameters[0] = channel;
4619 IPW_DEBUG_HC("CHANNEL: %d\n", channel);
4621 /* If BSS then we don't support channel selection */
4622 if (priv->ieee->iw_mode == IW_MODE_INFRA)
4625 if ((channel != 0) &&
4626 ((channel < REG_MIN_CHANNEL) || (channel > REG_MAX_CHANNEL)))
4630 err = ipw2100_disable_adapter(priv);
4635 err = ipw2100_hw_send_command(priv, &cmd);
4637 IPW_DEBUG_INFO("Failed to set channel to %d",
4643 priv->config |= CFG_STATIC_CHANNEL;
4645 priv->config &= ~CFG_STATIC_CHANNEL;
4647 priv->channel = channel;
4650 err = ipw2100_enable_adapter(priv);
4658 int ipw2100_system_config(struct ipw2100_priv *priv, int batch_mode)
4660 struct host_command cmd = {
4661 .host_command = SYSTEM_CONFIG,
4662 .host_command_sequence = 0,
4663 .host_command_length = 12,
4665 u32 ibss_mask, len = sizeof(u32);
4668 /* Set system configuration */
4671 err = ipw2100_disable_adapter(priv);
4676 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
4677 cmd.host_command_parameters[0] |= IPW_CFG_IBSS_AUTO_START;
4679 cmd.host_command_parameters[0] |= IPW_CFG_IBSS_MASK |
4681 IPW_CFG_802_1x_ENABLE;
4683 if (!(priv->config & CFG_LONG_PREAMBLE))
4684 cmd.host_command_parameters[0] |= IPW_CFG_PREAMBLE_AUTO;
4686 err = ipw2100_get_ordinal(priv,
4687 IPW_ORD_EEPROM_IBSS_11B_CHANNELS,
4690 ibss_mask = IPW_IBSS_11B_DEFAULT_MASK;
4692 cmd.host_command_parameters[1] = REG_CHANNEL_MASK;
4693 cmd.host_command_parameters[2] = REG_CHANNEL_MASK & ibss_mask;
4696 /*cmd.host_command_parameters[0] |= DIVERSITY_ANTENNA_A;*/
4698 err = ipw2100_hw_send_command(priv, &cmd);
4702 /* If IPv6 is configured in the kernel then we don't want to filter out all
4703 * of the multicast packets as IPv6 needs some. */
4704 #if !defined(CONFIG_IPV6) && !defined(CONFIG_IPV6_MODULE)
4705 cmd.host_command = ADD_MULTICAST;
4706 cmd.host_command_sequence = 0;
4707 cmd.host_command_length = 0;
4709 ipw2100_hw_send_command(priv, &cmd);
4712 err = ipw2100_enable_adapter(priv);
4720 int ipw2100_set_tx_rates(struct ipw2100_priv *priv, u32 rate, int batch_mode)
4722 struct host_command cmd = {
4723 .host_command = BASIC_TX_RATES,
4724 .host_command_sequence = 0,
4725 .host_command_length = 4
4729 cmd.host_command_parameters[0] = rate & TX_RATE_MASK;
4732 err = ipw2100_disable_adapter(priv);
4737 /* Set BASIC TX Rate first */
4738 ipw2100_hw_send_command(priv, &cmd);
4741 cmd.host_command = TX_RATES;
4742 ipw2100_hw_send_command(priv, &cmd);
4744 /* Set MSDU TX Rate */
4745 cmd.host_command = MSDU_TX_RATES;
4746 ipw2100_hw_send_command(priv, &cmd);
4749 err = ipw2100_enable_adapter(priv);
4754 priv->tx_rates = rate;
4759 int ipw2100_set_power_mode(struct ipw2100_priv *priv,
4762 struct host_command cmd = {
4763 .host_command = POWER_MODE,
4764 .host_command_sequence = 0,
4765 .host_command_length = 4
4769 cmd.host_command_parameters[0] = power_level;
4771 err = ipw2100_hw_send_command(priv, &cmd);
4775 if (power_level == IPW_POWER_MODE_CAM)
4776 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
4778 priv->power_mode = IPW_POWER_ENABLED | power_level;
4780 #ifdef CONFIG_IPW2100_TX_POWER
4781 if (priv->port_type == IBSS &&
4782 priv->adhoc_power != DFTL_IBSS_TX_POWER) {
4783 /* Set beacon interval */
4784 cmd.host_command = TX_POWER_INDEX;
4785 cmd.host_command_parameters[0] = (u32)priv->adhoc_power;
4787 err = ipw2100_hw_send_command(priv, &cmd);
4797 int ipw2100_set_rts_threshold(struct ipw2100_priv *priv, u32 threshold)
4799 struct host_command cmd = {
4800 .host_command = RTS_THRESHOLD,
4801 .host_command_sequence = 0,
4802 .host_command_length = 4
4806 if (threshold & RTS_DISABLED)
4807 cmd.host_command_parameters[0] = MAX_RTS_THRESHOLD;
4809 cmd.host_command_parameters[0] = threshold & ~RTS_DISABLED;
4811 err = ipw2100_hw_send_command(priv, &cmd);
4815 priv->rts_threshold = threshold;
4821 int ipw2100_set_fragmentation_threshold(struct ipw2100_priv *priv,
4822 u32 threshold, int batch_mode)
4824 struct host_command cmd = {
4825 .host_command = FRAG_THRESHOLD,
4826 .host_command_sequence = 0,
4827 .host_command_length = 4,
4828 .host_command_parameters[0] = 0,
4833 err = ipw2100_disable_adapter(priv);
4839 threshold = DEFAULT_FRAG_THRESHOLD;
4841 threshold = max(threshold, MIN_FRAG_THRESHOLD);
4842 threshold = min(threshold, MAX_FRAG_THRESHOLD);
4845 cmd.host_command_parameters[0] = threshold;
4847 IPW_DEBUG_HC("FRAG_THRESHOLD: %u\n", threshold);
4849 err = ipw2100_hw_send_command(priv, &cmd);
4852 ipw2100_enable_adapter(priv);
4855 priv->frag_threshold = threshold;
4861 int ipw2100_set_short_retry(struct ipw2100_priv *priv, u32 retry)
4863 struct host_command cmd = {
4864 .host_command = SHORT_RETRY_LIMIT,
4865 .host_command_sequence = 0,
4866 .host_command_length = 4
4870 cmd.host_command_parameters[0] = retry;
4872 err = ipw2100_hw_send_command(priv, &cmd);
4876 priv->short_retry_limit = retry;
4881 int ipw2100_set_long_retry(struct ipw2100_priv *priv, u32 retry)
4883 struct host_command cmd = {
4884 .host_command = LONG_RETRY_LIMIT,
4885 .host_command_sequence = 0,
4886 .host_command_length = 4
4890 cmd.host_command_parameters[0] = retry;
4892 err = ipw2100_hw_send_command(priv, &cmd);
4896 priv->long_retry_limit = retry;
4902 int ipw2100_set_mandatory_bssid(struct ipw2100_priv *priv, u8 *bssid,
4905 struct host_command cmd = {
4906 .host_command = MANDATORY_BSSID,
4907 .host_command_sequence = 0,
4908 .host_command_length = (bssid == NULL) ? 0 : ETH_ALEN
4912 #ifdef CONFIG_IPW_DEBUG
4915 "MANDATORY_BSSID: %02X:%02X:%02X:%02X:%02X:%02X\n",
4916 bssid[0], bssid[1], bssid[2], bssid[3], bssid[4],
4919 IPW_DEBUG_HC("MANDATORY_BSSID: <clear>\n");
4921 /* if BSSID is empty then we disable mandatory bssid mode */
4923 memcpy((u8 *)cmd.host_command_parameters, bssid, ETH_ALEN);
4926 err = ipw2100_disable_adapter(priv);
4931 err = ipw2100_hw_send_command(priv, &cmd);
4934 ipw2100_enable_adapter(priv);
4939 #ifdef CONFIG_IEEE80211_WPA
4940 static int ipw2100_disassociate_bssid(struct ipw2100_priv *priv)
4942 struct host_command cmd = {
4943 .host_command = DISASSOCIATION_BSSID,
4944 .host_command_sequence = 0,
4945 .host_command_length = ETH_ALEN
4950 IPW_DEBUG_HC("DISASSOCIATION_BSSID\n");
4953 /* The Firmware currently ignores the BSSID and just disassociates from
4954 * the currently associated AP -- but in the off chance that a future
4955 * firmware does use the BSSID provided here, we go ahead and try and
4956 * set it to the currently associated AP's BSSID */
4957 memcpy(cmd.host_command_parameters, priv->bssid, ETH_ALEN);
4959 err = ipw2100_hw_send_command(priv, &cmd);
4966 * Pseudo code for setting up wpa_frame:
4969 void x(struct ieee80211_assoc_frame *wpa_assoc)
4971 struct ipw2100_wpa_assoc_frame frame;
4972 frame->fixed_ie_mask = IPW_WPA_CAPABILTIES |
4973 IPW_WPA_LISTENINTERVAL |
4975 frame->capab_info = wpa_assoc->capab_info;
4976 frame->lisen_interval = wpa_assoc->listent_interval;
4977 memcpy(frame->current_ap, wpa_assoc->current_ap, ETH_ALEN);
4979 /* UNKNOWN -- I'm not postivive about this part; don't have any WPA
4980 * setup here to test it with.
4982 * Walk the IEs in the wpa_assoc and figure out the total size of all
4983 * that data. Stick that into frame->var_ie_len. Then memcpy() all of
4984 * the IEs from wpa_frame into frame.
4986 frame->var_ie_len = calculate_ie_len(wpa_assoc);
4987 memcpy(frame->var_ie, wpa_assoc->variable, frame->var_ie_len);
4989 ipw2100_set_wpa_ie(priv, &frame, 0);
4996 static int ipw2100_set_wpa_ie(struct ipw2100_priv *,
4997 struct ipw2100_wpa_assoc_frame *, int)
4998 __attribute__ ((unused));
5000 static int ipw2100_set_wpa_ie(struct ipw2100_priv *priv,
5001 struct ipw2100_wpa_assoc_frame *wpa_frame,
5004 struct host_command cmd = {
5005 .host_command = SET_WPA_IE,
5006 .host_command_sequence = 0,
5007 .host_command_length = sizeof(struct ipw2100_wpa_assoc_frame),
5011 IPW_DEBUG_HC("SET_WPA_IE\n");
5014 err = ipw2100_disable_adapter(priv);
5019 memcpy(cmd.host_command_parameters, wpa_frame,
5020 sizeof(struct ipw2100_wpa_assoc_frame));
5022 err = ipw2100_hw_send_command(priv, &cmd);
5025 if (ipw2100_enable_adapter(priv))
5032 struct security_info_params {
5033 u32 allowed_ciphers;
5036 u8 replay_counters_number;
5037 u8 unicast_using_group;
5038 } __attribute__ ((packed));
5040 int ipw2100_set_security_information(struct ipw2100_priv *priv,
5043 int unicast_using_group,
5046 struct host_command cmd = {
5047 .host_command = SET_SECURITY_INFORMATION,
5048 .host_command_sequence = 0,
5049 .host_command_length = sizeof(struct security_info_params)
5051 struct security_info_params *security =
5052 (struct security_info_params *)&cmd.host_command_parameters;
5054 memset(security, 0, sizeof(*security));
5056 /* If shared key AP authentication is turned on, then we need to
5057 * configure the firmware to try and use it.
5059 * Actual data encryption/decryption is handled by the host. */
5060 security->auth_mode = auth_mode;
5061 security->unicast_using_group = unicast_using_group;
5063 switch (security_level) {
5066 security->allowed_ciphers = IPW_NONE_CIPHER;
5069 security->allowed_ciphers = IPW_WEP40_CIPHER |
5073 security->allowed_ciphers = IPW_WEP40_CIPHER |
5074 IPW_WEP104_CIPHER | IPW_TKIP_CIPHER;
5076 case SEC_LEVEL_2_CKIP:
5077 security->allowed_ciphers = IPW_WEP40_CIPHER |
5078 IPW_WEP104_CIPHER | IPW_CKIP_CIPHER;
5081 security->allowed_ciphers = IPW_WEP40_CIPHER |
5082 IPW_WEP104_CIPHER | IPW_TKIP_CIPHER | IPW_CCMP_CIPHER;
5087 "SET_SECURITY_INFORMATION: auth:%d cipher:0x%02X (level %d)\n",
5088 security->auth_mode, security->allowed_ciphers, security_level);
5090 security->replay_counters_number = 0;
5093 err = ipw2100_disable_adapter(priv);
5098 err = ipw2100_hw_send_command(priv, &cmd);
5101 ipw2100_enable_adapter(priv);
5106 int ipw2100_set_tx_power(struct ipw2100_priv *priv,
5109 struct host_command cmd = {
5110 .host_command = TX_POWER_INDEX,
5111 .host_command_sequence = 0,
5112 .host_command_length = 4
5116 cmd.host_command_parameters[0] = tx_power;
5118 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
5119 err = ipw2100_hw_send_command(priv, &cmd);
5121 priv->tx_power = tx_power;
5126 int ipw2100_set_ibss_beacon_interval(struct ipw2100_priv *priv,
5127 u32 interval, int batch_mode)
5129 struct host_command cmd = {
5130 .host_command = BEACON_INTERVAL,
5131 .host_command_sequence = 0,
5132 .host_command_length = 4
5136 cmd.host_command_parameters[0] = interval;
5138 IPW_DEBUG_INFO("enter\n");
5140 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
5142 err = ipw2100_disable_adapter(priv);
5147 ipw2100_hw_send_command(priv, &cmd);
5150 err = ipw2100_enable_adapter(priv);
5156 IPW_DEBUG_INFO("exit\n");
5162 void ipw2100_queues_initialize(struct ipw2100_priv *priv)
5164 ipw2100_tx_initialize(priv);
5165 ipw2100_rx_initialize(priv);
5166 ipw2100_msg_initialize(priv);
5169 void ipw2100_queues_free(struct ipw2100_priv *priv)
5171 ipw2100_tx_free(priv);
5172 ipw2100_rx_free(priv);
5173 ipw2100_msg_free(priv);
5176 int ipw2100_queues_allocate(struct ipw2100_priv *priv)
5178 if (ipw2100_tx_allocate(priv) ||
5179 ipw2100_rx_allocate(priv) ||
5180 ipw2100_msg_allocate(priv))
5186 ipw2100_tx_free(priv);
5187 ipw2100_rx_free(priv);
5188 ipw2100_msg_free(priv);
5192 #define IPW_PRIVACY_CAPABLE 0x0008
5194 static int ipw2100_set_wep_flags(struct ipw2100_priv *priv, u32 flags,
5197 struct host_command cmd = {
5198 .host_command = WEP_FLAGS,
5199 .host_command_sequence = 0,
5200 .host_command_length = 4
5204 cmd.host_command_parameters[0] = flags;
5206 IPW_DEBUG_HC("WEP_FLAGS: flags = 0x%08X\n", flags);
5209 err = ipw2100_disable_adapter(priv);
5211 IPW_DEBUG_ERROR("%s: Could not disable adapter %d\n",
5212 priv->net_dev->name, err);
5217 /* send cmd to firmware */
5218 err = ipw2100_hw_send_command(priv, &cmd);
5221 ipw2100_enable_adapter(priv);
5226 struct ipw2100_wep_key {
5232 /* Macros to ease up priting WEP keys */
5233 #define WEP_FMT_64 "%02X%02X%02X%02X-%02X"
5234 #define WEP_FMT_128 "%02X%02X%02X%02X-%02X%02X%02X%02X-%02X%02X%02X"
5235 #define WEP_STR_64(x) x[0],x[1],x[2],x[3],x[4]
5236 #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]
5242 * @priv: struct to work on
5243 * @idx: index of the key we want to set
5244 * @key: ptr to the key data to set
5245 * @len: length of the buffer at @key
5246 * @batch_mode: FIXME perform the operation in batch mode, not
5247 * disabling the device.
5249 * @returns 0 if OK, < 0 errno code on error.
5251 * Fill out a command structure with the new wep key, length an
5252 * index and send it down the wire.
5254 static int ipw2100_set_key(struct ipw2100_priv *priv,
5255 int idx, char *key, int len, int batch_mode)
5257 int keylen = len ? (len <= 5 ? 5 : 13) : 0;
5258 struct host_command cmd = {
5259 .host_command = WEP_KEY_INFO,
5260 .host_command_sequence = 0,
5261 .host_command_length = sizeof(struct ipw2100_wep_key),
5263 struct ipw2100_wep_key *wep_key = (void*)cmd.host_command_parameters;
5266 IPW_DEBUG_HC("WEP_KEY_INFO: index = %d, len = %d/%d\n",
5269 /* NOTE: We don't check cached values in case the firmware was reset
5270 * or some other problem is occuring. If the user is setting the key,
5271 * then we push the change */
5274 wep_key->len = keylen;
5277 memcpy(wep_key->key, key, len);
5278 memset(wep_key->key + len, 0, keylen - len);
5281 /* Will be optimized out on debug not being configured in */
5283 IPW_DEBUG_WEP("%s: Clearing key %d\n",
5284 priv->net_dev->name, wep_key->idx);
5285 else if (keylen == 5)
5286 IPW_DEBUG_WEP("%s: idx: %d, len: %d key: " WEP_FMT_64 "\n",
5287 priv->net_dev->name, wep_key->idx, wep_key->len,
5288 WEP_STR_64(wep_key->key));
5290 IPW_DEBUG_WEP("%s: idx: %d, len: %d key: " WEP_FMT_128
5292 priv->net_dev->name, wep_key->idx, wep_key->len,
5293 WEP_STR_128(wep_key->key));
5296 err = ipw2100_disable_adapter(priv);
5297 /* FIXME: IPG: shouldn't this prink be in _disable_adapter()? */
5299 IPW_DEBUG_ERROR("%s: Could not disable adapter %d\n",
5300 priv->net_dev->name, err);
5305 /* send cmd to firmware */
5306 err = ipw2100_hw_send_command(priv, &cmd);
5309 int err2 = ipw2100_enable_adapter(priv);
5316 static int ipw2100_set_key_index(struct ipw2100_priv *priv,
5317 int idx, int batch_mode)
5319 struct host_command cmd = {
5320 .host_command = WEP_KEY_INDEX,
5321 .host_command_sequence = 0,
5322 .host_command_length = 4,
5323 .host_command_parameters = { idx },
5327 IPW_DEBUG_HC("WEP_KEY_INDEX: index = %d\n", idx);
5329 if (idx < 0 || idx > 3)
5333 err = ipw2100_disable_adapter(priv);
5335 IPW_DEBUG_ERROR("%s: Could not disable adapter %d\n",
5336 priv->net_dev->name, err);
5341 /* send cmd to firmware */
5342 err = ipw2100_hw_send_command(priv, &cmd);
5345 ipw2100_enable_adapter(priv);
5351 static int ipw2100_configure_security(struct ipw2100_priv *priv,
5354 int i, err, auth_mode, sec_level, use_group;
5356 if (!(priv->status & STATUS_RUNNING))
5360 err = ipw2100_disable_adapter(priv);
5365 if (!priv->sec.enabled) {
5366 err = ipw2100_set_security_information(
5367 priv, IPW_AUTH_OPEN, SEC_LEVEL_0, 0, 1);
5369 auth_mode = IPW_AUTH_OPEN;
5370 if ((priv->sec.flags & SEC_AUTH_MODE) &&
5371 (priv->sec.auth_mode == WLAN_AUTH_SHARED_KEY))
5372 auth_mode = IPW_AUTH_SHARED;
5374 sec_level = SEC_LEVEL_0;
5375 if (priv->sec.flags & SEC_LEVEL)
5376 sec_level = priv->sec.level;
5379 if (priv->sec.flags & SEC_UNICAST_GROUP)
5380 use_group = priv->sec.unicast_uses_group;
5382 err = ipw2100_set_security_information(
5383 priv, auth_mode, sec_level, use_group, 1);
5389 if (priv->sec.enabled) {
5390 for (i = 0; i < 4; i++) {
5391 if (!(priv->sec.flags & (1 << i))) {
5392 memset(priv->sec.keys[i], 0, WEP_KEY_LEN);
5393 priv->sec.key_sizes[i] = 0;
5395 err = ipw2100_set_key(priv, i,
5397 priv->sec.key_sizes[i],
5404 ipw2100_set_key_index(priv, priv->ieee->tx_keyidx, 1);
5407 /* Always enable privacy so the Host can filter WEP packets if
5408 * encrypted data is sent up */
5409 err = ipw2100_set_wep_flags(
5410 priv, priv->sec.enabled ? IPW_PRIVACY_CAPABLE : 0, 1);
5414 priv->status &= ~STATUS_SECURITY_UPDATED;
5418 ipw2100_enable_adapter(priv);
5423 static void ipw2100_security_work(struct ipw2100_priv *priv)
5425 /* If we happen to have reconnected before we get a chance to
5426 * process this, then update the security settings--which causes
5427 * a disassociation to occur */
5428 if (!(priv->status & STATUS_ASSOCIATED) &&
5429 priv->status & STATUS_SECURITY_UPDATED)
5430 ipw2100_configure_security(priv, 0);
5433 static void shim__set_security(struct net_device *dev,
5434 struct ieee80211_security *sec)
5436 struct ipw2100_priv *priv = ieee80211_priv(dev);
5437 int i, force_update = 0;
5439 down(&priv->action_sem);
5440 if (!(priv->status & STATUS_INITIALIZED))
5443 for (i = 0; i < 4; i++) {
5444 if (sec->flags & (1 << i)) {
5445 priv->sec.key_sizes[i] = sec->key_sizes[i];
5446 if (sec->key_sizes[i] == 0)
5447 priv->sec.flags &= ~(1 << i);
5449 memcpy(priv->sec.keys[i], sec->keys[i],
5451 priv->sec.flags |= (1 << i);
5452 priv->status |= STATUS_SECURITY_UPDATED;
5456 if ((sec->flags & SEC_ACTIVE_KEY) &&
5457 priv->sec.active_key != sec->active_key) {
5458 if (sec->active_key <= 3) {
5459 priv->sec.active_key = sec->active_key;
5460 priv->sec.flags |= SEC_ACTIVE_KEY;
5462 priv->sec.flags &= ~SEC_ACTIVE_KEY;
5464 priv->status |= STATUS_SECURITY_UPDATED;
5467 if ((sec->flags & SEC_AUTH_MODE) &&
5468 (priv->sec.auth_mode != sec->auth_mode)) {
5469 priv->sec.auth_mode = sec->auth_mode;
5470 priv->sec.flags |= SEC_AUTH_MODE;
5471 priv->status |= STATUS_SECURITY_UPDATED;
5474 if (sec->flags & SEC_ENABLED &&
5475 priv->sec.enabled != sec->enabled) {
5476 priv->sec.flags |= SEC_ENABLED;
5477 priv->sec.enabled = sec->enabled;
5478 priv->status |= STATUS_SECURITY_UPDATED;
5482 if (sec->flags & SEC_LEVEL &&
5483 priv->sec.level != sec->level) {
5484 priv->sec.level = sec->level;
5485 priv->sec.flags |= SEC_LEVEL;
5486 priv->status |= STATUS_SECURITY_UPDATED;
5489 IPW_DEBUG_WEP("Security flags: %c %c%c%c%c %c%c%c%c\n",
5490 priv->sec.flags & (1<<8) ? '1' : '0',
5491 priv->sec.flags & (1<<7) ? '1' : '0',
5492 priv->sec.flags & (1<<6) ? '1' : '0',
5493 priv->sec.flags & (1<<5) ? '1' : '0',
5494 priv->sec.flags & (1<<4) ? '1' : '0',
5495 priv->sec.flags & (1<<3) ? '1' : '0',
5496 priv->sec.flags & (1<<2) ? '1' : '0',
5497 priv->sec.flags & (1<<1) ? '1' : '0',
5498 priv->sec.flags & (1<<0) ? '1' : '0');
5500 /* As a temporary work around to enable WPA until we figure out why
5501 * wpa_supplicant toggles the security capability of the driver, which
5502 * forces a disassocation with force_update...
5504 * if (force_update || !(priv->status & STATUS_ASSOCIATED))*/
5505 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
5506 ipw2100_configure_security(priv, 0);
5508 up(&priv->action_sem);
5511 static int ipw2100_adapter_setup(struct ipw2100_priv *priv)
5517 IPW_DEBUG_INFO("enter\n");
5519 err = ipw2100_disable_adapter(priv);
5522 #ifdef CONFIG_IPW2100_MONITOR
5523 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
5524 err = ipw2100_set_channel(priv, priv->channel, batch_mode);
5528 IPW_DEBUG_INFO("exit\n");
5532 #endif /* CONFIG_IPW2100_MONITOR */
5534 err = ipw2100_read_mac_address(priv);
5538 err = ipw2100_set_mac_address(priv, batch_mode);
5542 err = ipw2100_set_port_type(priv, priv->ieee->iw_mode, batch_mode);
5546 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
5547 err = ipw2100_set_channel(priv, priv->channel, batch_mode);
5552 err = ipw2100_system_config(priv, batch_mode);
5556 err = ipw2100_set_tx_rates(priv, priv->tx_rates, batch_mode);
5560 /* Default to power mode OFF */
5561 err = ipw2100_set_power_mode(priv, IPW_POWER_MODE_CAM);
5565 err = ipw2100_set_rts_threshold(priv, priv->rts_threshold);
5569 if (priv->config & CFG_STATIC_BSSID)
5570 bssid = priv->bssid;
5573 err = ipw2100_set_mandatory_bssid(priv, bssid, batch_mode);
5577 if (priv->config & CFG_STATIC_ESSID)
5578 err = ipw2100_set_essid(priv, priv->essid, priv->essid_len,
5581 err = ipw2100_set_essid(priv, NULL, 0, batch_mode);
5585 err = ipw2100_configure_security(priv, batch_mode);
5589 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
5590 err = ipw2100_set_ibss_beacon_interval(
5591 priv, priv->beacon_interval, batch_mode);
5595 err = ipw2100_set_tx_power(priv, priv->tx_power);
5601 err = ipw2100_set_fragmentation_threshold(
5602 priv, priv->frag_threshold, batch_mode);
5607 IPW_DEBUG_INFO("exit\n");
5613 /*************************************************************************
5615 * EXTERNALLY CALLED METHODS
5617 *************************************************************************/
5619 /* This method is called by the network layer -- not to be confused with
5620 * ipw2100_set_mac_address() declared above called by this driver (and this
5621 * method as well) to talk to the firmware */
5622 static int ipw2100_set_address(struct net_device *dev, void *p)
5624 struct ipw2100_priv *priv = ieee80211_priv(dev);
5625 struct sockaddr *addr = p;
5628 if (!is_valid_ether_addr(addr->sa_data))
5629 return -EADDRNOTAVAIL;
5631 down(&priv->action_sem);
5633 priv->config |= CFG_CUSTOM_MAC;
5634 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
5636 err = ipw2100_set_mac_address(priv, 0);
5640 priv->reset_backoff = 0;
5641 up(&priv->action_sem);
5642 ipw2100_reset_adapter(priv);
5646 up(&priv->action_sem);
5650 static int ipw2100_open(struct net_device *dev)
5652 struct ipw2100_priv *priv = ieee80211_priv(dev);
5653 unsigned long flags;
5654 IPW_DEBUG_INFO("dev->open\n");
5656 spin_lock_irqsave(&priv->low_lock, flags);
5657 if (priv->status & STATUS_ASSOCIATED)
5658 netif_start_queue(dev);
5659 spin_unlock_irqrestore(&priv->low_lock, flags);
5664 static int ipw2100_close(struct net_device *dev)
5666 struct ipw2100_priv *priv = ieee80211_priv(dev);
5667 unsigned long flags;
5668 struct list_head *element;
5669 struct ipw2100_tx_packet *packet;
5671 IPW_DEBUG_INFO("enter\n");
5673 spin_lock_irqsave(&priv->low_lock, flags);
5675 if (priv->status & STATUS_ASSOCIATED)
5676 netif_carrier_off(dev);
5677 netif_stop_queue(dev);
5679 /* Flush the TX queue ... */
5680 while (!list_empty(&priv->tx_pend_list)) {
5681 element = priv->tx_pend_list.next;
5682 packet = list_entry(element, struct ipw2100_tx_packet, list);
5685 DEC_STAT(&priv->tx_pend_stat);
5687 ieee80211_txb_free(packet->info.d_struct.txb);
5688 packet->info.d_struct.txb = NULL;
5690 list_add_tail(element, &priv->tx_free_list);
5691 INC_STAT(&priv->tx_free_stat);
5693 spin_unlock_irqrestore(&priv->low_lock, flags);
5695 IPW_DEBUG_INFO("exit\n");
5703 * TODO: Fix this function... its just wrong
5705 static void ipw2100_tx_timeout(struct net_device *dev)
5707 struct ipw2100_priv *priv = ieee80211_priv(dev);
5709 priv->ieee->stats.tx_errors++;
5711 #ifdef CONFIG_IPW2100_MONITOR
5712 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
5716 IPW_DEBUG_INFO("%s: TX timed out. Scheduling firmware restart.\n",
5718 schedule_reset(priv);
5723 * TODO: reimplement it so that it reads statistics
5724 * from the adapter using ordinal tables
5725 * instead of/in addition to collecting them
5728 static struct net_device_stats *ipw2100_stats(struct net_device *dev)
5730 struct ipw2100_priv *priv = ieee80211_priv(dev);
5732 return &priv->ieee->stats;
5735 /* Support for wpa_supplicant. Will be replaced with WEXT once
5736 * they get WPA support. */
5737 #ifdef CONFIG_IEEE80211_WPA
5739 /* following definitions must match definitions in driver_ipw2100.c */
5741 #define IPW2100_IOCTL_WPA_SUPPLICANT SIOCIWFIRSTPRIV+30
5743 #define IPW2100_CMD_SET_WPA_PARAM 1
5744 #define IPW2100_CMD_SET_WPA_IE 2
5745 #define IPW2100_CMD_SET_ENCRYPTION 3
5746 #define IPW2100_CMD_MLME 4
5748 #define IPW2100_PARAM_WPA_ENABLED 1
5749 #define IPW2100_PARAM_TKIP_COUNTERMEASURES 2
5750 #define IPW2100_PARAM_DROP_UNENCRYPTED 3
5751 #define IPW2100_PARAM_PRIVACY_INVOKED 4
5752 #define IPW2100_PARAM_AUTH_ALGS 5
5753 #define IPW2100_PARAM_IEEE_802_1X 6
5755 #define IPW2100_MLME_STA_DEAUTH 1
5756 #define IPW2100_MLME_STA_DISASSOC 2
5758 #define IPW2100_CRYPT_ERR_UNKNOWN_ALG 2
5759 #define IPW2100_CRYPT_ERR_UNKNOWN_ADDR 3
5760 #define IPW2100_CRYPT_ERR_CRYPT_INIT_FAILED 4
5761 #define IPW2100_CRYPT_ERR_KEY_SET_FAILED 5
5762 #define IPW2100_CRYPT_ERR_TX_KEY_SET_FAILED 6
5763 #define IPW2100_CRYPT_ERR_CARD_CONF_FAILED 7
5765 #define IPW2100_CRYPT_ALG_NAME_LEN 16
5767 struct ipw2100_param {
5769 u8 sta_addr[ETH_ALEN];
5784 u8 alg[IPW2100_CRYPT_ALG_NAME_LEN];
5788 u8 seq[8]; /* sequence counter (set: RX, get: TX) */
5796 /* end of driver_ipw2100.c code */
5798 static int ipw2100_wpa_enable(struct ipw2100_priv *priv, int value){
5800 struct ieee80211_device *ieee = priv->ieee;
5801 struct ieee80211_security sec = {
5802 .flags = SEC_LEVEL | SEC_ENABLED,
5806 ieee->wpa_enabled = value;
5809 sec.level = SEC_LEVEL_3;
5812 sec.level = SEC_LEVEL_0;
5816 if (ieee->set_security)
5817 ieee->set_security(ieee->dev, &sec);
5824 #define AUTH_ALG_OPEN_SYSTEM 0x1
5825 #define AUTH_ALG_SHARED_KEY 0x2
5827 static int ipw2100_wpa_set_auth_algs(struct ipw2100_priv *priv, int value){
5829 struct ieee80211_device *ieee = priv->ieee;
5830 struct ieee80211_security sec = {
5831 .flags = SEC_AUTH_MODE,
5835 if (value & AUTH_ALG_SHARED_KEY){
5836 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
5839 sec.auth_mode = WLAN_AUTH_OPEN;
5843 if (ieee->set_security)
5844 ieee->set_security(ieee->dev, &sec);
5852 static int ipw2100_wpa_set_param(struct net_device *dev, u8 name, u32 value){
5854 struct ipw2100_priv *priv = ieee80211_priv(dev);
5858 case IPW2100_PARAM_WPA_ENABLED:
5859 ret = ipw2100_wpa_enable(priv, value);
5862 case IPW2100_PARAM_TKIP_COUNTERMEASURES:
5863 priv->ieee->tkip_countermeasures=value;
5866 case IPW2100_PARAM_DROP_UNENCRYPTED:
5867 priv->ieee->drop_unencrypted=value;
5870 case IPW2100_PARAM_PRIVACY_INVOKED:
5871 priv->ieee->privacy_invoked=value;
5874 case IPW2100_PARAM_AUTH_ALGS:
5875 ret = ipw2100_wpa_set_auth_algs(priv, value);
5878 case IPW2100_PARAM_IEEE_802_1X:
5879 priv->ieee->ieee802_1x=value;
5883 IPW_DEBUG_ERROR("%s: Unknown WPA param: %d\n",
5891 static int ipw2100_wpa_mlme(struct net_device *dev, int command, int reason){
5893 struct ipw2100_priv *priv = ieee80211_priv(dev);
5897 case IPW2100_MLME_STA_DEAUTH:
5901 case IPW2100_MLME_STA_DISASSOC:
5902 ipw2100_disassociate_bssid(priv);
5906 IPW_DEBUG_ERROR("%s: Unknown MLME request: %d\n",
5907 dev->name, command);
5915 void ipw2100_wpa_assoc_frame(struct ipw2100_priv *priv,
5916 char *wpa_ie, int wpa_ie_len){
5918 struct ipw2100_wpa_assoc_frame frame;
5920 frame.fixed_ie_mask = 0;
5923 memcpy(frame.var_ie, wpa_ie, wpa_ie_len);
5924 frame.var_ie_len = wpa_ie_len;
5926 /* make sure WPA is enabled */
5927 ipw2100_wpa_enable(priv, 1);
5928 ipw2100_set_wpa_ie(priv, &frame, 0);
5932 static int ipw2100_wpa_set_wpa_ie(struct net_device *dev,
5933 struct ipw2100_param *param, int plen){
5935 struct ipw2100_priv *priv = ieee80211_priv(dev);
5936 struct ieee80211_device *ieee = priv->ieee;
5939 if (! ieee->wpa_enabled)
5942 if (param->u.wpa_ie.len > MAX_WPA_IE_LEN ||
5943 (param->u.wpa_ie.len &&
5944 param->u.wpa_ie.data==NULL))
5947 if (param->u.wpa_ie.len){
5948 buf = kmalloc(param->u.wpa_ie.len, GFP_KERNEL);
5952 memcpy(buf, param->u.wpa_ie.data, param->u.wpa_ie.len);
5954 kfree(ieee->wpa_ie);
5956 ieee->wpa_ie_len = param->u.wpa_ie.len;
5959 kfree(ieee->wpa_ie);
5960 ieee->wpa_ie = NULL;
5961 ieee->wpa_ie_len = 0;
5964 ipw2100_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
5969 /* implementation borrowed from hostap driver */
5971 static int ipw2100_wpa_set_encryption(struct net_device *dev,
5972 struct ipw2100_param *param, int param_len){
5975 struct ipw2100_priv *priv = ieee80211_priv(dev);
5976 struct ieee80211_device *ieee = priv->ieee;
5977 struct ieee80211_crypto_ops *ops;
5978 struct ieee80211_crypt_data **crypt;
5980 struct ieee80211_security sec = {
5984 param->u.crypt.err = 0;
5985 param->u.crypt.alg[IPW2100_CRYPT_ALG_NAME_LEN - 1] = '\0';
5988 (int) ((char *) param->u.crypt.key - (char *) param) +
5989 param->u.crypt.key_len){
5990 IPW_DEBUG_INFO("Len mismatch %d, %d\n", param_len, param->u.crypt.key_len);
5993 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
5994 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
5995 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
5996 if (param->u.crypt.idx >= WEP_KEYS)
5998 crypt = &ieee->crypt[param->u.crypt.idx];
6003 if (strcmp(param->u.crypt.alg, "none") == 0) {
6006 sec.level = SEC_LEVEL_0;
6007 sec.flags |= SEC_ENABLED | SEC_LEVEL;
6008 ieee80211_crypt_delayed_deinit(ieee, crypt);
6013 sec.flags |= SEC_ENABLED;
6015 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6016 if (ops == NULL && strcmp(param->u.crypt.alg, "WEP") == 0) {
6017 request_module("ieee80211_crypt_wep");
6018 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6019 } else if (ops == NULL && strcmp(param->u.crypt.alg, "TKIP") == 0) {
6020 request_module("ieee80211_crypt_tkip");
6021 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6022 } else if (ops == NULL && strcmp(param->u.crypt.alg, "CCMP") == 0) {
6023 request_module("ieee80211_crypt_ccmp");
6024 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6027 IPW_DEBUG_INFO("%s: unknown crypto alg '%s'\n",
6028 dev->name, param->u.crypt.alg);
6029 param->u.crypt.err = IPW2100_CRYPT_ERR_UNKNOWN_ALG;
6034 if (*crypt == NULL || (*crypt)->ops != ops) {
6035 struct ieee80211_crypt_data *new_crypt;
6037 ieee80211_crypt_delayed_deinit(ieee, crypt);
6039 new_crypt = (struct ieee80211_crypt_data *)
6040 kmalloc(sizeof(struct ieee80211_crypt_data), GFP_KERNEL);
6041 if (new_crypt == NULL) {
6045 memset(new_crypt, 0, sizeof(struct ieee80211_crypt_data));
6046 new_crypt->ops = ops;
6047 if (new_crypt->ops && try_module_get(new_crypt->ops->owner))
6048 new_crypt->priv = new_crypt->ops->init(param->u.crypt.idx);
6050 if (new_crypt->priv == NULL) {
6052 param->u.crypt.err =
6053 IPW2100_CRYPT_ERR_CRYPT_INIT_FAILED;
6061 if (param->u.crypt.key_len > 0 && (*crypt)->ops->set_key &&
6062 (*crypt)->ops->set_key(param->u.crypt.key,
6063 param->u.crypt.key_len, param->u.crypt.seq,
6064 (*crypt)->priv) < 0) {
6065 IPW_DEBUG_INFO("%s: key setting failed\n",
6067 param->u.crypt.err = IPW2100_CRYPT_ERR_KEY_SET_FAILED;
6072 if (param->u.crypt.set_tx){
6073 ieee->tx_keyidx = param->u.crypt.idx;
6074 sec.active_key = param->u.crypt.idx;
6075 sec.flags |= SEC_ACTIVE_KEY;
6078 if (ops->name != NULL){
6080 if (strcmp(ops->name, "WEP") == 0) {
6081 memcpy(sec.keys[param->u.crypt.idx], param->u.crypt.key, param->u.crypt.key_len);
6082 sec.key_sizes[param->u.crypt.idx] = param->u.crypt.key_len;
6083 sec.flags |= (1 << param->u.crypt.idx);
6084 sec.flags |= SEC_LEVEL;
6085 sec.level = SEC_LEVEL_1;
6086 } else if (strcmp(ops->name, "TKIP") == 0) {
6087 sec.flags |= SEC_LEVEL;
6088 sec.level = SEC_LEVEL_2;
6089 } else if (strcmp(ops->name, "CCMP") == 0) {
6090 sec.flags |= SEC_LEVEL;
6091 sec.level = SEC_LEVEL_3;
6095 if (ieee->set_security)
6096 ieee->set_security(ieee->dev, &sec);
6098 /* Do not reset port if card is in Managed mode since resetting will
6099 * generate new IEEE 802.11 authentication which may end up in looping
6100 * with IEEE 802.1X. If your hardware requires a reset after WEP
6101 * configuration (for example... Prism2), implement the reset_port in
6102 * the callbacks structures used to initialize the 802.11 stack. */
6103 if (ieee->reset_on_keychange &&
6104 ieee->iw_mode != IW_MODE_INFRA &&
6106 ieee->reset_port(dev)) {
6107 IPW_DEBUG_INFO("%s: reset_port failed\n", dev->name);
6108 param->u.crypt.err = IPW2100_CRYPT_ERR_CARD_CONF_FAILED;
6116 static int ipw2100_wpa_supplicant(struct net_device *dev, struct iw_point *p){
6118 struct ipw2100_param *param;
6121 IPW_DEBUG_IOCTL("wpa_supplicant: len=%d\n", p->length);
6123 if (p->length < sizeof(struct ipw2100_param) || !p->pointer)
6126 param = (struct ipw2100_param *)kmalloc(p->length, GFP_KERNEL);
6130 if (copy_from_user(param, p->pointer, p->length)){
6135 switch (param->cmd){
6137 case IPW2100_CMD_SET_WPA_PARAM:
6138 ret = ipw2100_wpa_set_param(dev, param->u.wpa_param.name,
6139 param->u.wpa_param.value);
6142 case IPW2100_CMD_SET_WPA_IE:
6143 ret = ipw2100_wpa_set_wpa_ie(dev, param, p->length);
6146 case IPW2100_CMD_SET_ENCRYPTION:
6147 ret = ipw2100_wpa_set_encryption(dev, param, p->length);
6150 case IPW2100_CMD_MLME:
6151 ret = ipw2100_wpa_mlme(dev, param->u.mlme.command,
6152 param->u.mlme.reason_code);
6156 IPW_DEBUG_ERROR("%s: Unknown WPA supplicant request: %d\n",
6157 dev->name, param->cmd);
6162 if (ret == 0 && copy_to_user(p->pointer, param, p->length))
6168 #endif /* CONFIG_IEEE80211_WPA */
6170 static int ipw2100_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
6172 #ifdef CONFIG_IEEE80211_WPA
6173 struct iwreq *wrq = (struct iwreq *) rq;
6176 case IPW2100_IOCTL_WPA_SUPPLICANT:
6177 ret = ipw2100_wpa_supplicant(dev, &wrq->u.data);
6184 #endif /* CONFIG_IEEE80211_WPA */
6190 static void ipw_ethtool_get_drvinfo(struct net_device *dev,
6191 struct ethtool_drvinfo *info)
6193 struct ipw2100_priv *priv = ieee80211_priv(dev);
6194 char fw_ver[64], ucode_ver[64];
6196 strcpy(info->driver, DRV_NAME);
6197 strcpy(info->version, DRV_VERSION);
6199 ipw2100_get_fwversion(priv, fw_ver, sizeof(fw_ver));
6200 ipw2100_get_ucodeversion(priv, ucode_ver, sizeof(ucode_ver));
6202 snprintf(info->fw_version, sizeof(info->fw_version), "%s:%d:%s",
6203 fw_ver, priv->eeprom_version, ucode_ver);
6205 strcpy(info->bus_info, pci_name(priv->pci_dev));
6208 static u32 ipw2100_ethtool_get_link(struct net_device *dev)
6210 struct ipw2100_priv *priv = ieee80211_priv(dev);
6211 return (priv->status & STATUS_ASSOCIATED) ? 1 : 0;
6215 static struct ethtool_ops ipw2100_ethtool_ops = {
6216 .get_link = ipw2100_ethtool_get_link,
6217 .get_drvinfo = ipw_ethtool_get_drvinfo,
6220 static void ipw2100_hang_check(void *adapter)
6222 struct ipw2100_priv *priv = adapter;
6223 unsigned long flags;
6224 u32 rtc = 0xa5a5a5a5;
6225 u32 len = sizeof(rtc);
6228 spin_lock_irqsave(&priv->low_lock, flags);
6230 if (priv->fatal_error != 0) {
6231 /* If fatal_error is set then we need to restart */
6232 IPW_DEBUG_INFO("%s: Hardware fatal error detected.\n",
6233 priv->net_dev->name);
6236 } else if (ipw2100_get_ordinal(priv, IPW_ORD_RTC_TIME, &rtc, &len) ||
6237 (rtc == priv->last_rtc)) {
6238 /* Check if firmware is hung */
6239 IPW_DEBUG_INFO("%s: Firmware RTC stalled.\n",
6240 priv->net_dev->name);
6247 priv->stop_hang_check = 1;
6250 /* Restart the NIC */
6251 schedule_reset(priv);
6254 priv->last_rtc = rtc;
6256 if (!priv->stop_hang_check)
6257 queue_delayed_work(priv->workqueue, &priv->hang_check, HZ / 2);
6259 spin_unlock_irqrestore(&priv->low_lock, flags);
6263 static void ipw2100_rf_kill(void *adapter)
6265 struct ipw2100_priv *priv = adapter;
6266 unsigned long flags;
6268 spin_lock_irqsave(&priv->low_lock, flags);
6270 if (rf_kill_active(priv)) {
6271 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
6272 if (!priv->stop_rf_kill)
6273 queue_delayed_work(priv->workqueue, &priv->rf_kill, HZ);
6277 /* RF Kill is now disabled, so bring the device back up */
6279 if (!(priv->status & STATUS_RF_KILL_MASK)) {
6280 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
6282 schedule_reset(priv);
6284 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
6288 spin_unlock_irqrestore(&priv->low_lock, flags);
6291 static void ipw2100_irq_tasklet(struct ipw2100_priv *priv);
6293 /* Look into using netdev destructor to shutdown ieee80211? */
6295 static struct net_device *ipw2100_alloc_device(
6296 struct pci_dev *pci_dev,
6298 unsigned long mem_start,
6299 unsigned long mem_len)
6301 struct ipw2100_priv *priv;
6302 struct net_device *dev;
6304 dev = alloc_ieee80211(sizeof(struct ipw2100_priv));
6307 priv = ieee80211_priv(dev);
6308 priv->ieee = netdev_priv(dev);
6309 priv->pci_dev = pci_dev;
6310 priv->net_dev = dev;
6312 priv->ieee->hard_start_xmit = ipw2100_tx;
6313 priv->ieee->set_security = shim__set_security;
6315 dev->open = ipw2100_open;
6316 dev->stop = ipw2100_close;
6317 dev->init = ipw2100_net_init;
6318 dev->do_ioctl = ipw2100_ioctl;
6319 dev->get_stats = ipw2100_stats;
6320 dev->ethtool_ops = &ipw2100_ethtool_ops;
6321 dev->tx_timeout = ipw2100_tx_timeout;
6322 dev->wireless_handlers = &ipw2100_wx_handler_def;
6323 dev->get_wireless_stats = ipw2100_wx_wireless_stats;
6324 dev->set_mac_address = ipw2100_set_address;
6325 dev->watchdog_timeo = 3*HZ;
6328 dev->base_addr = (unsigned long)base_addr;
6329 dev->mem_start = mem_start;
6330 dev->mem_end = dev->mem_start + mem_len - 1;
6332 /* NOTE: We don't use the wireless_handlers hook
6333 * in dev as the system will start throwing WX requests
6334 * to us before we're actually initialized and it just
6335 * ends up causing problems. So, we just handle
6336 * the WX extensions through the ipw2100_ioctl interface */
6339 /* memset() puts everything to 0, so we only have explicitely set
6340 * those values that need to be something else */
6342 /* If power management is turned on, default to AUTO mode */
6343 priv->power_mode = IPW_POWER_AUTO;
6347 #ifdef CONFIG_IEEE80211_WPA
6348 priv->ieee->wpa_enabled = 0;
6349 priv->ieee->tkip_countermeasures = 0;
6350 priv->ieee->drop_unencrypted = 0;
6351 priv->ieee->privacy_invoked = 0;
6352 priv->ieee->ieee802_1x = 1;
6353 #endif /* CONFIG_IEEE80211_WPA */
6355 /* Set module parameters */
6358 priv->ieee->iw_mode = IW_MODE_ADHOC;
6360 #ifdef CONFIG_IPW2100_MONITOR
6362 priv->ieee->iw_mode = IW_MODE_MONITOR;
6367 priv->ieee->iw_mode = IW_MODE_INFRA;
6372 priv->status |= STATUS_RF_KILL_SW;
6375 ((channel >= REG_MIN_CHANNEL) &&
6376 (channel <= REG_MAX_CHANNEL))) {
6377 priv->config |= CFG_STATIC_CHANNEL;
6378 priv->channel = channel;
6382 priv->config |= CFG_ASSOCIATE;
6384 priv->beacon_interval = DEFAULT_BEACON_INTERVAL;
6385 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
6386 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
6387 priv->rts_threshold = DEFAULT_RTS_THRESHOLD | RTS_DISABLED;
6388 priv->frag_threshold = DEFAULT_FTS | FRAG_DISABLED;
6389 priv->tx_power = IPW_TX_POWER_DEFAULT;
6390 priv->tx_rates = DEFAULT_TX_RATES;
6392 strcpy(priv->nick, "ipw2100");
6394 spin_lock_init(&priv->low_lock);
6395 sema_init(&priv->action_sem, 1);
6396 sema_init(&priv->adapter_sem, 1);
6398 init_waitqueue_head(&priv->wait_command_queue);
6400 netif_carrier_off(dev);
6402 INIT_LIST_HEAD(&priv->msg_free_list);
6403 INIT_LIST_HEAD(&priv->msg_pend_list);
6404 INIT_STAT(&priv->msg_free_stat);
6405 INIT_STAT(&priv->msg_pend_stat);
6407 INIT_LIST_HEAD(&priv->tx_free_list);
6408 INIT_LIST_HEAD(&priv->tx_pend_list);
6409 INIT_STAT(&priv->tx_free_stat);
6410 INIT_STAT(&priv->tx_pend_stat);
6412 INIT_LIST_HEAD(&priv->fw_pend_list);
6413 INIT_STAT(&priv->fw_pend_stat);
6416 #ifdef CONFIG_SOFTWARE_SUSPEND2
6417 priv->workqueue = create_workqueue(DRV_NAME, 0);
6419 priv->workqueue = create_workqueue(DRV_NAME);
6421 INIT_WORK(&priv->reset_work,
6422 (void (*)(void *))ipw2100_reset_adapter, priv);
6423 INIT_WORK(&priv->security_work,
6424 (void (*)(void *))ipw2100_security_work, priv);
6425 INIT_WORK(&priv->wx_event_work,
6426 (void (*)(void *))ipw2100_wx_event_work, priv);
6427 INIT_WORK(&priv->hang_check, ipw2100_hang_check, priv);
6428 INIT_WORK(&priv->rf_kill, ipw2100_rf_kill, priv);
6430 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
6431 ipw2100_irq_tasklet, (unsigned long)priv);
6433 /* NOTE: We do not start the deferred work for status checks yet */
6434 priv->stop_rf_kill = 1;
6435 priv->stop_hang_check = 1;
6440 static int ipw2100_pci_init_one(struct pci_dev *pci_dev,
6441 const struct pci_device_id *ent)
6443 unsigned long mem_start, mem_len, mem_flags;
6444 char *base_addr = NULL;
6445 struct net_device *dev = NULL;
6446 struct ipw2100_priv *priv = NULL;
6451 IPW_DEBUG_INFO("enter\n");
6453 mem_start = pci_resource_start(pci_dev, 0);
6454 mem_len = pci_resource_len(pci_dev, 0);
6455 mem_flags = pci_resource_flags(pci_dev, 0);
6457 if ((mem_flags & IORESOURCE_MEM) != IORESOURCE_MEM) {
6458 IPW_DEBUG_INFO("weird - resource type is not memory\n");
6463 base_addr = ioremap_nocache(mem_start, mem_len);
6465 printk(KERN_WARNING DRV_NAME
6466 "Error calling ioremap_nocache.\n");
6471 /* allocate and initialize our net_device */
6472 dev = ipw2100_alloc_device(pci_dev, base_addr, mem_start, mem_len);
6474 printk(KERN_WARNING DRV_NAME
6475 "Error calling ipw2100_alloc_device.\n");
6480 /* set up PCI mappings for device */
6481 err = pci_enable_device(pci_dev);
6483 printk(KERN_WARNING DRV_NAME
6484 "Error calling pci_enable_device.\n");
6488 priv = ieee80211_priv(dev);
6490 pci_set_master(pci_dev);
6491 pci_set_drvdata(pci_dev, priv);
6493 err = pci_set_dma_mask(pci_dev, DMA_32BIT_MASK);
6495 printk(KERN_WARNING DRV_NAME
6496 "Error calling pci_set_dma_mask.\n");
6497 pci_disable_device(pci_dev);
6501 err = pci_request_regions(pci_dev, DRV_NAME);
6503 printk(KERN_WARNING DRV_NAME
6504 "Error calling pci_request_regions.\n");
6505 pci_disable_device(pci_dev);
6509 /* We disable the RETRY_TIMEOUT register (0x41) to keep
6510 * PCI Tx retries from interfering with C3 CPU state */
6511 pci_read_config_dword(pci_dev, 0x40, &val);
6512 if ((val & 0x0000ff00) != 0)
6513 pci_write_config_dword(pci_dev, 0x40, val & 0xffff00ff);
6515 pci_set_power_state(pci_dev, PCI_D0);
6517 if (!ipw2100_hw_is_adapter_in_system(dev)) {
6518 printk(KERN_WARNING DRV_NAME
6519 "Device not found via register read.\n");
6524 SET_NETDEV_DEV(dev, &pci_dev->dev);
6526 /* Force interrupts to be shut off on the device */
6527 priv->status |= STATUS_INT_ENABLED;
6528 ipw2100_disable_interrupts(priv);
6530 /* Allocate and initialize the Tx/Rx queues and lists */
6531 if (ipw2100_queues_allocate(priv)) {
6532 printk(KERN_WARNING DRV_NAME
6533 "Error calilng ipw2100_queues_allocate.\n");
6537 ipw2100_queues_initialize(priv);
6539 err = request_irq(pci_dev->irq,
6540 ipw2100_interrupt, SA_SHIRQ,
6543 printk(KERN_WARNING DRV_NAME
6544 "Error calling request_irq: %d.\n",
6548 dev->irq = pci_dev->irq;
6550 IPW_DEBUG_INFO("Attempting to register device...\n");
6552 SET_MODULE_OWNER(dev);
6554 printk(KERN_INFO DRV_NAME
6555 ": Detected Intel PRO/Wireless 2100 Network Connection\n");
6557 /* Bring up the interface. Pre 0.46, after we registered the
6558 * network device we would call ipw2100_up. This introduced a race
6559 * condition with newer hotplug configurations (network was coming
6560 * up and making calls before the device was initialized).
6562 * If we called ipw2100_up before we registered the device, then the
6563 * device name wasn't registered. So, we instead use the net_dev->init
6564 * member to call a function that then just turns and calls ipw2100_up.
6565 * net_dev->init is called after name allocation but before the
6566 * notifier chain is called */
6567 down(&priv->action_sem);
6568 err = register_netdev(dev);
6570 printk(KERN_WARNING DRV_NAME
6571 "Error calling register_netdev.\n");
6576 IPW_DEBUG_INFO("%s: Bound to %s\n", dev->name, pci_name(pci_dev));
6578 /* perform this after register_netdev so that dev->name is set */
6579 sysfs_create_group(&pci_dev->dev.kobj, &ipw2100_attribute_group);
6580 netif_carrier_off(dev);
6582 /* If the RF Kill switch is disabled, go ahead and complete the
6583 * startup sequence */
6584 if (!(priv->status & STATUS_RF_KILL_MASK)) {
6585 /* Enable the adapter - sends HOST_COMPLETE */
6586 if (ipw2100_enable_adapter(priv)) {
6587 printk(KERN_WARNING DRV_NAME
6588 ": %s: failed in call to enable adapter.\n",
6589 priv->net_dev->name);
6590 ipw2100_hw_stop_adapter(priv);
6595 /* Start a scan . . . */
6596 ipw2100_set_scan_options(priv);
6597 ipw2100_start_scan(priv);
6600 IPW_DEBUG_INFO("exit\n");
6602 priv->status |= STATUS_INITIALIZED;
6604 up(&priv->action_sem);
6609 up(&priv->action_sem);
6614 unregister_netdev(dev);
6616 ipw2100_hw_stop_adapter(priv);
6618 ipw2100_disable_interrupts(priv);
6621 free_irq(dev->irq, priv);
6623 ipw2100_kill_workqueue(priv);
6625 /* These are safe to call even if they weren't allocated */
6626 ipw2100_queues_free(priv);
6627 sysfs_remove_group(&pci_dev->dev.kobj, &ipw2100_attribute_group);
6629 free_ieee80211(dev);
6630 pci_set_drvdata(pci_dev, NULL);
6634 iounmap((char*)base_addr);
6636 pci_release_regions(pci_dev);
6637 pci_disable_device(pci_dev);
6642 static void __devexit ipw2100_pci_remove_one(struct pci_dev *pci_dev)
6644 struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
6645 struct net_device *dev;
6648 down(&priv->action_sem);
6650 priv->status &= ~STATUS_INITIALIZED;
6652 dev = priv->net_dev;
6653 sysfs_remove_group(&pci_dev->dev.kobj, &ipw2100_attribute_group);
6656 if (ipw2100_firmware.version)
6657 ipw2100_release_firmware(priv, &ipw2100_firmware);
6659 /* Take down the hardware */
6662 /* Release the semaphore so that the network subsystem can
6663 * complete any needed calls into the driver... */
6664 up(&priv->action_sem);
6666 /* Unregister the device first - this results in close()
6667 * being called if the device is open. If we free storage
6668 * first, then close() will crash. */
6669 unregister_netdev(dev);
6671 /* ipw2100_down will ensure that there is no more pending work
6672 * in the workqueue's, so we can safely remove them now. */
6673 ipw2100_kill_workqueue(priv);
6675 ipw2100_queues_free(priv);
6677 /* Free potential debugging firmware snapshot */
6678 ipw2100_snapshot_free(priv);
6681 free_irq(dev->irq, priv);
6684 iounmap((unsigned char *)dev->base_addr);
6686 free_ieee80211(dev);
6689 pci_release_regions(pci_dev);
6690 pci_disable_device(pci_dev);
6692 IPW_DEBUG_INFO("exit\n");
6697 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11)
6698 static int ipw2100_suspend(struct pci_dev *pci_dev, u32 state)
6700 static int ipw2100_suspend(struct pci_dev *pci_dev, pm_message_t state)
6703 struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
6704 struct net_device *dev = priv->net_dev;
6706 IPW_DEBUG_INFO("%s: Going into suspend...\n",
6709 down(&priv->action_sem);
6710 if (priv->status & STATUS_INITIALIZED) {
6711 /* Take down the device; powers it off, etc. */
6715 /* Remove the PRESENT state of the device */
6716 netif_device_detach(dev);
6718 pci_save_state(pci_dev);
6719 pci_disable_device (pci_dev);
6720 pci_set_power_state(pci_dev, PCI_D3hot);
6722 up(&priv->action_sem);
6727 static int ipw2100_resume(struct pci_dev *pci_dev)
6729 struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
6730 struct net_device *dev = priv->net_dev;
6733 if (IPW2100_PM_DISABLED)
6736 down(&priv->action_sem);
6738 IPW_DEBUG_INFO("%s: Coming out of suspend...\n",
6741 pci_set_power_state(pci_dev, PCI_D0);
6742 pci_enable_device(pci_dev);
6743 pci_restore_state(pci_dev);
6746 * Suspend/Resume resets the PCI configuration space, so we have to
6747 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
6748 * from interfering with C3 CPU state. pci_restore_state won't help
6749 * here since it only restores the first 64 bytes pci config header.
6751 pci_read_config_dword(pci_dev, 0x40, &val);
6752 if ((val & 0x0000ff00) != 0)
6753 pci_write_config_dword(pci_dev, 0x40, val & 0xffff00ff);
6755 /* Set the device back into the PRESENT state; this will also wake
6756 * the queue of needed */
6757 netif_device_attach(dev);
6759 /* Bring the device back up */
6760 if (!(priv->status & STATUS_RF_KILL_SW))
6761 ipw2100_up(priv, 0);
6763 up(&priv->action_sem);
6770 #define IPW2100_DEV_ID(x) { PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, x }
6772 static struct pci_device_id ipw2100_pci_id_table[] __devinitdata = {
6773 IPW2100_DEV_ID(0x2520), /* IN 2100A mPCI 3A */
6774 IPW2100_DEV_ID(0x2521), /* IN 2100A mPCI 3B */
6775 IPW2100_DEV_ID(0x2524), /* IN 2100A mPCI 3B */
6776 IPW2100_DEV_ID(0x2525), /* IN 2100A mPCI 3B */
6777 IPW2100_DEV_ID(0x2526), /* IN 2100A mPCI Gen A3 */
6778 IPW2100_DEV_ID(0x2522), /* IN 2100 mPCI 3B */
6779 IPW2100_DEV_ID(0x2523), /* IN 2100 mPCI 3A */
6780 IPW2100_DEV_ID(0x2527), /* IN 2100 mPCI 3B */
6781 IPW2100_DEV_ID(0x2528), /* IN 2100 mPCI 3B */
6782 IPW2100_DEV_ID(0x2529), /* IN 2100 mPCI 3B */
6783 IPW2100_DEV_ID(0x252B), /* IN 2100 mPCI 3A */
6784 IPW2100_DEV_ID(0x252C), /* IN 2100 mPCI 3A */
6785 IPW2100_DEV_ID(0x252D), /* IN 2100 mPCI 3A */
6787 IPW2100_DEV_ID(0x2550), /* IB 2100A mPCI 3B */
6788 IPW2100_DEV_ID(0x2551), /* IB 2100 mPCI 3B */
6789 IPW2100_DEV_ID(0x2553), /* IB 2100 mPCI 3B */
6790 IPW2100_DEV_ID(0x2554), /* IB 2100 mPCI 3B */
6791 IPW2100_DEV_ID(0x2555), /* IB 2100 mPCI 3B */
6793 IPW2100_DEV_ID(0x2560), /* DE 2100A mPCI 3A */
6794 IPW2100_DEV_ID(0x2562), /* DE 2100A mPCI 3A */
6795 IPW2100_DEV_ID(0x2563), /* DE 2100A mPCI 3A */
6796 IPW2100_DEV_ID(0x2561), /* DE 2100 mPCI 3A */
6797 IPW2100_DEV_ID(0x2565), /* DE 2100 mPCI 3A */
6798 IPW2100_DEV_ID(0x2566), /* DE 2100 mPCI 3A */
6799 IPW2100_DEV_ID(0x2567), /* DE 2100 mPCI 3A */
6801 IPW2100_DEV_ID(0x2570), /* GA 2100 mPCI 3B */
6803 IPW2100_DEV_ID(0x2580), /* TO 2100A mPCI 3B */
6804 IPW2100_DEV_ID(0x2582), /* TO 2100A mPCI 3B */
6805 IPW2100_DEV_ID(0x2583), /* TO 2100A mPCI 3B */
6806 IPW2100_DEV_ID(0x2581), /* TO 2100 mPCI 3B */
6807 IPW2100_DEV_ID(0x2585), /* TO 2100 mPCI 3B */
6808 IPW2100_DEV_ID(0x2586), /* TO 2100 mPCI 3B */
6809 IPW2100_DEV_ID(0x2587), /* TO 2100 mPCI 3B */
6811 IPW2100_DEV_ID(0x2590), /* SO 2100A mPCI 3B */
6812 IPW2100_DEV_ID(0x2592), /* SO 2100A mPCI 3B */
6813 IPW2100_DEV_ID(0x2591), /* SO 2100 mPCI 3B */
6814 IPW2100_DEV_ID(0x2593), /* SO 2100 mPCI 3B */
6815 IPW2100_DEV_ID(0x2596), /* SO 2100 mPCI 3B */
6816 IPW2100_DEV_ID(0x2598), /* SO 2100 mPCI 3B */
6818 IPW2100_DEV_ID(0x25A0), /* HP 2100 mPCI 3B */
6822 MODULE_DEVICE_TABLE(pci, ipw2100_pci_id_table);
6824 static struct pci_driver ipw2100_pci_driver = {
6826 .id_table = ipw2100_pci_id_table,
6827 .probe = ipw2100_pci_init_one,
6828 .remove = __devexit_p(ipw2100_pci_remove_one),
6830 .suspend = ipw2100_suspend,
6831 .resume = ipw2100_resume,
6837 * Initialize the ipw2100 driver/module
6839 * @returns 0 if ok, < 0 errno node con error.
6841 * Note: we cannot init the /proc stuff until the PCI driver is there,
6842 * or we risk an unlikely race condition on someone accessing
6843 * uninitialized data in the PCI dev struct through /proc.
6845 static int __init ipw2100_init(void)
6849 printk(KERN_INFO DRV_NAME ": %s, %s\n", DRV_DESCRIPTION, DRV_VERSION);
6850 printk(KERN_INFO DRV_NAME ": %s\n", DRV_COPYRIGHT);
6852 #ifdef CONFIG_IEEE80211_NOWEP
6853 IPW_DEBUG_INFO(DRV_NAME ": Compiled with WEP disabled.\n");
6856 ret = pci_module_init(&ipw2100_pci_driver);
6858 #ifdef CONFIG_IPW_DEBUG
6859 ipw2100_debug_level = debug;
6860 driver_create_file(&ipw2100_pci_driver.driver,
6861 &driver_attr_debug_level);
6869 * Cleanup ipw2100 driver registration
6871 static void __exit ipw2100_exit(void)
6873 /* FIXME: IPG: check that we have no instances of the devices open */
6874 #ifdef CONFIG_IPW_DEBUG
6875 driver_remove_file(&ipw2100_pci_driver.driver,
6876 &driver_attr_debug_level);
6878 pci_unregister_driver(&ipw2100_pci_driver);
6881 module_init(ipw2100_init);
6882 module_exit(ipw2100_exit);
6884 #define WEXT_USECHANNELS 1
6886 const long ipw2100_frequencies[] = {
6887 2412, 2417, 2422, 2427,
6888 2432, 2437, 2442, 2447,
6889 2452, 2457, 2462, 2467,
6893 #define FREQ_COUNT (sizeof(ipw2100_frequencies) / \
6894 sizeof(ipw2100_frequencies[0]))
6896 const long ipw2100_rates_11b[] = {
6903 #define RATE_COUNT (sizeof(ipw2100_rates_11b) / sizeof(ipw2100_rates_11b[0]))
6905 static int ipw2100_wx_get_name(struct net_device *dev,
6906 struct iw_request_info *info,
6907 union iwreq_data *wrqu, char *extra)
6910 * This can be called at any time. No action lock required
6913 struct ipw2100_priv *priv = ieee80211_priv(dev);
6914 if (!(priv->status & STATUS_ASSOCIATED))
6915 strcpy(wrqu->name, "unassociated");
6917 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11b");
6919 IPW_DEBUG_WX("Name: %s\n", wrqu->name);
6924 static int ipw2100_wx_set_freq(struct net_device *dev,
6925 struct iw_request_info *info,
6926 union iwreq_data *wrqu, char *extra)
6928 struct ipw2100_priv *priv = ieee80211_priv(dev);
6929 struct iw_freq *fwrq = &wrqu->freq;
6932 if (priv->ieee->iw_mode == IW_MODE_INFRA)
6935 down(&priv->action_sem);
6936 if (!(priv->status & STATUS_INITIALIZED)) {
6941 /* if setting by freq convert to channel */
6943 if ((fwrq->m >= (int) 2.412e8 &&
6944 fwrq->m <= (int) 2.487e8)) {
6945 int f = fwrq->m / 100000;
6948 while ((c < REG_MAX_CHANNEL) &&
6949 (f != ipw2100_frequencies[c]))
6952 /* hack to fall through */
6958 if (fwrq->e > 0 || fwrq->m > 1000)
6960 else { /* Set the channel */
6961 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
6962 err = ipw2100_set_channel(priv, fwrq->m, 0);
6966 up(&priv->action_sem);
6971 static int ipw2100_wx_get_freq(struct net_device *dev,
6972 struct iw_request_info *info,
6973 union iwreq_data *wrqu, char *extra)
6976 * This can be called at any time. No action lock required
6979 struct ipw2100_priv *priv = ieee80211_priv(dev);
6983 /* If we are associated, trying to associate, or have a statically
6984 * configured CHANNEL then return that; otherwise return ANY */
6985 if (priv->config & CFG_STATIC_CHANNEL ||
6986 priv->status & STATUS_ASSOCIATED)
6987 wrqu->freq.m = priv->channel;
6991 IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
6996 static int ipw2100_wx_set_mode(struct net_device *dev,
6997 struct iw_request_info *info,
6998 union iwreq_data *wrqu, char *extra)
7000 struct ipw2100_priv *priv = ieee80211_priv(dev);
7003 IPW_DEBUG_WX("SET Mode -> %d \n", wrqu->mode);
7005 if (wrqu->mode == priv->ieee->iw_mode)
7008 down(&priv->action_sem);
7009 if (!(priv->status & STATUS_INITIALIZED)) {
7014 switch (wrqu->mode) {
7015 #ifdef CONFIG_IPW2100_MONITOR
7016 case IW_MODE_MONITOR:
7017 err = ipw2100_switch_mode(priv, IW_MODE_MONITOR);
7019 #endif /* CONFIG_IPW2100_MONITOR */
7021 err = ipw2100_switch_mode(priv, IW_MODE_ADHOC);
7026 err = ipw2100_switch_mode(priv, IW_MODE_INFRA);
7031 up(&priv->action_sem);
7035 static int ipw2100_wx_get_mode(struct net_device *dev,
7036 struct iw_request_info *info,
7037 union iwreq_data *wrqu, char *extra)
7040 * This can be called at any time. No action lock required
7043 struct ipw2100_priv *priv = ieee80211_priv(dev);
7045 wrqu->mode = priv->ieee->iw_mode;
7046 IPW_DEBUG_WX("GET Mode -> %d\n", wrqu->mode);
7052 #define POWER_MODES 5
7054 /* Values are in microsecond */
7055 const s32 timeout_duration[POWER_MODES] = {
7063 const s32 period_duration[POWER_MODES] = {
7071 static int ipw2100_wx_get_range(struct net_device *dev,
7072 struct iw_request_info *info,
7073 union iwreq_data *wrqu, char *extra)
7076 * This can be called at any time. No action lock required
7079 struct ipw2100_priv *priv = ieee80211_priv(dev);
7080 struct iw_range *range = (struct iw_range *)extra;
7084 wrqu->data.length = sizeof(*range);
7085 memset(range, 0, sizeof(*range));
7087 /* Let's try to keep this struct in the same order as in
7088 * linux/include/wireless.h
7091 /* TODO: See what values we can set, and remove the ones we can't
7092 * set, or fill them with some default data.
7095 /* ~5 Mb/s real (802.11b) */
7096 range->throughput = 5 * 1000 * 1000;
7098 // range->sensitivity; /* signal level threshold range */
7100 range->max_qual.qual = 100;
7101 /* TODO: Find real max RSSI and stick here */
7102 range->max_qual.level = 0;
7103 range->max_qual.noise = 0;
7104 range->max_qual.updated = 7; /* Updated all three */
7106 range->avg_qual.qual = 70; /* > 8% missed beacons is 'bad' */
7107 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
7108 range->avg_qual.level = 20 + IPW2100_RSSI_TO_DBM;
7109 range->avg_qual.noise = 0;
7110 range->avg_qual.updated = 7; /* Updated all three */
7112 range->num_bitrates = RATE_COUNT;
7114 for (i = 0; i < RATE_COUNT && i < IW_MAX_BITRATES; i++) {
7115 range->bitrate[i] = ipw2100_rates_11b[i];
7118 range->min_rts = MIN_RTS_THRESHOLD;
7119 range->max_rts = MAX_RTS_THRESHOLD;
7120 range->min_frag = MIN_FRAG_THRESHOLD;
7121 range->max_frag = MAX_FRAG_THRESHOLD;
7123 range->min_pmp = period_duration[0]; /* Minimal PM period */
7124 range->max_pmp = period_duration[POWER_MODES-1];/* Maximal PM period */
7125 range->min_pmt = timeout_duration[POWER_MODES-1]; /* Minimal PM timeout */
7126 range->max_pmt = timeout_duration[0];/* Maximal PM timeout */
7128 /* How to decode max/min PM period */
7129 range->pmp_flags = IW_POWER_PERIOD;
7130 /* How to decode max/min PM period */
7131 range->pmt_flags = IW_POWER_TIMEOUT;
7132 /* What PM options are supported */
7133 range->pm_capa = IW_POWER_TIMEOUT | IW_POWER_PERIOD;
7135 range->encoding_size[0] = 5;
7136 range->encoding_size[1] = 13; /* Different token sizes */
7137 range->num_encoding_sizes = 2; /* Number of entry in the list */
7138 range->max_encoding_tokens = WEP_KEYS; /* Max number of tokens */
7139 // range->encoding_login_index; /* token index for login token */
7141 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7142 range->txpower_capa = IW_TXPOW_DBM;
7143 range->num_txpower = IW_MAX_TXPOWER;
7144 for (i = 0, level = (IPW_TX_POWER_MAX_DBM * 16); i < IW_MAX_TXPOWER;
7145 i++, level -= ((IPW_TX_POWER_MAX_DBM - IPW_TX_POWER_MIN_DBM) * 16) /
7146 (IW_MAX_TXPOWER - 1))
7147 range->txpower[i] = level / 16;
7149 range->txpower_capa = 0;
7150 range->num_txpower = 0;
7154 /* Set the Wireless Extension versions */
7155 range->we_version_compiled = WIRELESS_EXT;
7156 range->we_version_source = 16;
7158 // range->retry_capa; /* What retry options are supported */
7159 // range->retry_flags; /* How to decode max/min retry limit */
7160 // range->r_time_flags; /* How to decode max/min retry life */
7161 // range->min_retry; /* Minimal number of retries */
7162 // range->max_retry; /* Maximal number of retries */
7163 // range->min_r_time; /* Minimal retry lifetime */
7164 // range->max_r_time; /* Maximal retry lifetime */
7166 range->num_channels = FREQ_COUNT;
7169 for (i = 0; i < FREQ_COUNT; i++) {
7170 // TODO: Include only legal frequencies for some countries
7171 // if (local->channel_mask & (1 << i)) {
7172 range->freq[val].i = i + 1;
7173 range->freq[val].m = ipw2100_frequencies[i] * 100000;
7174 range->freq[val].e = 1;
7177 if (val == IW_MAX_FREQUENCIES)
7180 range->num_frequency = val;
7182 IPW_DEBUG_WX("GET Range\n");
7187 static int ipw2100_wx_set_wap(struct net_device *dev,
7188 struct iw_request_info *info,
7189 union iwreq_data *wrqu, char *extra)
7191 struct ipw2100_priv *priv = ieee80211_priv(dev);
7194 static const unsigned char any[] = {
7195 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
7197 static const unsigned char off[] = {
7198 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
7202 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
7205 down(&priv->action_sem);
7206 if (!(priv->status & STATUS_INITIALIZED)) {
7211 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
7212 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
7213 /* we disable mandatory BSSID association */
7214 IPW_DEBUG_WX("exit - disable mandatory BSSID\n");
7215 priv->config &= ~CFG_STATIC_BSSID;
7216 err = ipw2100_set_mandatory_bssid(priv, NULL, 0);
7220 priv->config |= CFG_STATIC_BSSID;
7221 memcpy(priv->mandatory_bssid_mac, wrqu->ap_addr.sa_data, ETH_ALEN);
7223 err = ipw2100_set_mandatory_bssid(priv, wrqu->ap_addr.sa_data, 0);
7225 IPW_DEBUG_WX("SET BSSID -> %02X:%02X:%02X:%02X:%02X:%02X\n",
7226 wrqu->ap_addr.sa_data[0] & 0xff,
7227 wrqu->ap_addr.sa_data[1] & 0xff,
7228 wrqu->ap_addr.sa_data[2] & 0xff,
7229 wrqu->ap_addr.sa_data[3] & 0xff,
7230 wrqu->ap_addr.sa_data[4] & 0xff,
7231 wrqu->ap_addr.sa_data[5] & 0xff);
7234 up(&priv->action_sem);
7238 static int ipw2100_wx_get_wap(struct net_device *dev,
7239 struct iw_request_info *info,
7240 union iwreq_data *wrqu, char *extra)
7243 * This can be called at any time. No action lock required
7246 struct ipw2100_priv *priv = ieee80211_priv(dev);
7248 /* If we are associated, trying to associate, or have a statically
7249 * configured BSSID then return that; otherwise return ANY */
7250 if (priv->config & CFG_STATIC_BSSID ||
7251 priv->status & STATUS_ASSOCIATED) {
7252 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
7253 memcpy(wrqu->ap_addr.sa_data, &priv->bssid, ETH_ALEN);
7255 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
7257 IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n",
7258 MAC_ARG(wrqu->ap_addr.sa_data));
7262 static int ipw2100_wx_set_essid(struct net_device *dev,
7263 struct iw_request_info *info,
7264 union iwreq_data *wrqu, char *extra)
7266 struct ipw2100_priv *priv = ieee80211_priv(dev);
7267 char *essid = ""; /* ANY */
7271 down(&priv->action_sem);
7272 if (!(priv->status & STATUS_INITIALIZED)) {
7277 if (wrqu->essid.flags && wrqu->essid.length) {
7278 length = wrqu->essid.length - 1;
7283 IPW_DEBUG_WX("Setting ESSID to ANY\n");
7284 priv->config &= ~CFG_STATIC_ESSID;
7285 err = ipw2100_set_essid(priv, NULL, 0, 0);
7289 length = min(length, IW_ESSID_MAX_SIZE);
7291 priv->config |= CFG_STATIC_ESSID;
7293 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
7294 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
7299 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length),
7302 priv->essid_len = length;
7303 memcpy(priv->essid, essid, priv->essid_len);
7305 err = ipw2100_set_essid(priv, essid, length, 0);
7308 up(&priv->action_sem);
7312 static int ipw2100_wx_get_essid(struct net_device *dev,
7313 struct iw_request_info *info,
7314 union iwreq_data *wrqu, char *extra)
7317 * This can be called at any time. No action lock required
7320 struct ipw2100_priv *priv = ieee80211_priv(dev);
7322 /* If we are associated, trying to associate, or have a statically
7323 * configured ESSID then return that; otherwise return ANY */
7324 if (priv->config & CFG_STATIC_ESSID ||
7325 priv->status & STATUS_ASSOCIATED) {
7326 IPW_DEBUG_WX("Getting essid: '%s'\n",
7327 escape_essid(priv->essid, priv->essid_len));
7328 memcpy(extra, priv->essid, priv->essid_len);
7329 wrqu->essid.length = priv->essid_len;
7330 wrqu->essid.flags = 1; /* active */
7332 IPW_DEBUG_WX("Getting essid: ANY\n");
7333 wrqu->essid.length = 0;
7334 wrqu->essid.flags = 0; /* active */
7340 static int ipw2100_wx_set_nick(struct net_device *dev,
7341 struct iw_request_info *info,
7342 union iwreq_data *wrqu, char *extra)
7345 * This can be called at any time. No action lock required
7348 struct ipw2100_priv *priv = ieee80211_priv(dev);
7350 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
7353 wrqu->data.length = min((size_t)wrqu->data.length, sizeof(priv->nick));
7354 memset(priv->nick, 0, sizeof(priv->nick));
7355 memcpy(priv->nick, extra, wrqu->data.length);
7357 IPW_DEBUG_WX("SET Nickname -> %s \n", priv->nick);
7362 static int ipw2100_wx_get_nick(struct net_device *dev,
7363 struct iw_request_info *info,
7364 union iwreq_data *wrqu, char *extra)
7367 * This can be called at any time. No action lock required
7370 struct ipw2100_priv *priv = ieee80211_priv(dev);
7372 wrqu->data.length = strlen(priv->nick) + 1;
7373 memcpy(extra, priv->nick, wrqu->data.length);
7374 wrqu->data.flags = 1; /* active */
7376 IPW_DEBUG_WX("GET Nickname -> %s \n", extra);
7381 static int ipw2100_wx_set_rate(struct net_device *dev,
7382 struct iw_request_info *info,
7383 union iwreq_data *wrqu, char *extra)
7385 struct ipw2100_priv *priv = ieee80211_priv(dev);
7386 u32 target_rate = wrqu->bitrate.value;
7390 down(&priv->action_sem);
7391 if (!(priv->status & STATUS_INITIALIZED)) {
7398 if (target_rate == 1000000 ||
7399 (!wrqu->bitrate.fixed && target_rate > 1000000))
7400 rate |= TX_RATE_1_MBIT;
7401 if (target_rate == 2000000 ||
7402 (!wrqu->bitrate.fixed && target_rate > 2000000))
7403 rate |= TX_RATE_2_MBIT;
7404 if (target_rate == 5500000 ||
7405 (!wrqu->bitrate.fixed && target_rate > 5500000))
7406 rate |= TX_RATE_5_5_MBIT;
7407 if (target_rate == 11000000 ||
7408 (!wrqu->bitrate.fixed && target_rate > 11000000))
7409 rate |= TX_RATE_11_MBIT;
7411 rate = DEFAULT_TX_RATES;
7413 err = ipw2100_set_tx_rates(priv, rate, 0);
7415 IPW_DEBUG_WX("SET Rate -> %04X \n", rate);
7417 up(&priv->action_sem);
7422 static int ipw2100_wx_get_rate(struct net_device *dev,
7423 struct iw_request_info *info,
7424 union iwreq_data *wrqu, char *extra)
7426 struct ipw2100_priv *priv = ieee80211_priv(dev);
7428 int len = sizeof(val);
7431 if (!(priv->status & STATUS_ENABLED) ||
7432 priv->status & STATUS_RF_KILL_MASK ||
7433 !(priv->status & STATUS_ASSOCIATED)) {
7434 wrqu->bitrate.value = 0;
7438 down(&priv->action_sem);
7439 if (!(priv->status & STATUS_INITIALIZED)) {
7444 err = ipw2100_get_ordinal(priv, IPW_ORD_CURRENT_TX_RATE, &val, &len);
7446 IPW_DEBUG_WX("failed querying ordinals.\n");
7450 switch (val & TX_RATE_MASK) {
7451 case TX_RATE_1_MBIT:
7452 wrqu->bitrate.value = 1000000;
7454 case TX_RATE_2_MBIT:
7455 wrqu->bitrate.value = 2000000;
7457 case TX_RATE_5_5_MBIT:
7458 wrqu->bitrate.value = 5500000;
7460 case TX_RATE_11_MBIT:
7461 wrqu->bitrate.value = 11000000;
7464 wrqu->bitrate.value = 0;
7467 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
7470 up(&priv->action_sem);
7474 static int ipw2100_wx_set_rts(struct net_device *dev,
7475 struct iw_request_info *info,
7476 union iwreq_data *wrqu, char *extra)
7478 struct ipw2100_priv *priv = ieee80211_priv(dev);
7481 /* Auto RTS not yet supported */
7482 if (wrqu->rts.fixed == 0)
7485 down(&priv->action_sem);
7486 if (!(priv->status & STATUS_INITIALIZED)) {
7491 if (wrqu->rts.disabled)
7492 value = priv->rts_threshold | RTS_DISABLED;
7494 if (wrqu->rts.value < 1 ||
7495 wrqu->rts.value > 2304) {
7499 value = wrqu->rts.value;
7502 err = ipw2100_set_rts_threshold(priv, value);
7504 IPW_DEBUG_WX("SET RTS Threshold -> 0x%08X \n", value);
7506 up(&priv->action_sem);
7510 static int ipw2100_wx_get_rts(struct net_device *dev,
7511 struct iw_request_info *info,
7512 union iwreq_data *wrqu, char *extra)
7515 * This can be called at any time. No action lock required
7518 struct ipw2100_priv *priv = ieee80211_priv(dev);
7520 wrqu->rts.value = priv->rts_threshold & ~RTS_DISABLED;
7521 wrqu->rts.fixed = 1; /* no auto select */
7523 /* If RTS is set to the default value, then it is disabled */
7524 wrqu->rts.disabled = (priv->rts_threshold & RTS_DISABLED) ? 1 : 0;
7526 IPW_DEBUG_WX("GET RTS Threshold -> 0x%08X \n", wrqu->rts.value);
7531 static int ipw2100_wx_set_txpow(struct net_device *dev,
7532 struct iw_request_info *info,
7533 union iwreq_data *wrqu, char *extra)
7535 struct ipw2100_priv *priv = ieee80211_priv(dev);
7538 if (priv->ieee->iw_mode != IW_MODE_ADHOC)
7541 if (wrqu->txpower.disabled == 1 || wrqu->txpower.fixed == 0)
7542 value = IPW_TX_POWER_DEFAULT;
7544 if (wrqu->txpower.value < IPW_TX_POWER_MIN_DBM ||
7545 wrqu->txpower.value > IPW_TX_POWER_MAX_DBM)
7548 value = (wrqu->txpower.value - IPW_TX_POWER_MIN_DBM) * 16 /
7549 (IPW_TX_POWER_MAX_DBM - IPW_TX_POWER_MIN_DBM);
7552 down(&priv->action_sem);
7553 if (!(priv->status & STATUS_INITIALIZED)) {
7558 err = ipw2100_set_tx_power(priv, value);
7560 IPW_DEBUG_WX("SET TX Power -> %d \n", value);
7563 up(&priv->action_sem);
7567 static int ipw2100_wx_get_txpow(struct net_device *dev,
7568 struct iw_request_info *info,
7569 union iwreq_data *wrqu, char *extra)
7572 * This can be called at any time. No action lock required
7575 struct ipw2100_priv *priv = ieee80211_priv(dev);
7577 if (priv->ieee->iw_mode != IW_MODE_ADHOC) {
7578 wrqu->power.disabled = 1;
7582 if (priv->tx_power == IPW_TX_POWER_DEFAULT) {
7583 wrqu->power.fixed = 0;
7584 wrqu->power.value = IPW_TX_POWER_MAX_DBM;
7585 wrqu->power.disabled = 1;
7587 wrqu->power.disabled = 0;
7588 wrqu->power.fixed = 1;
7591 (IPW_TX_POWER_MAX_DBM - IPW_TX_POWER_MIN_DBM)) /
7592 (IPW_TX_POWER_MAX - IPW_TX_POWER_MIN) +
7593 IPW_TX_POWER_MIN_DBM;
7596 wrqu->power.flags = IW_TXPOW_DBM;
7598 IPW_DEBUG_WX("GET TX Power -> %d \n", wrqu->power.value);
7603 static int ipw2100_wx_set_frag(struct net_device *dev,
7604 struct iw_request_info *info,
7605 union iwreq_data *wrqu, char *extra)
7608 * This can be called at any time. No action lock required
7611 struct ipw2100_priv *priv = ieee80211_priv(dev);
7613 if (!wrqu->frag.fixed)
7616 if (wrqu->frag.disabled) {
7617 priv->frag_threshold |= FRAG_DISABLED;
7618 priv->ieee->fts = DEFAULT_FTS;
7620 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
7621 wrqu->frag.value > MAX_FRAG_THRESHOLD)
7624 priv->ieee->fts = wrqu->frag.value & ~0x1;
7625 priv->frag_threshold = priv->ieee->fts;
7628 IPW_DEBUG_WX("SET Frag Threshold -> %d \n", priv->ieee->fts);
7633 static int ipw2100_wx_get_frag(struct net_device *dev,
7634 struct iw_request_info *info,
7635 union iwreq_data *wrqu, char *extra)
7638 * This can be called at any time. No action lock required
7641 struct ipw2100_priv *priv = ieee80211_priv(dev);
7642 wrqu->frag.value = priv->frag_threshold & ~FRAG_DISABLED;
7643 wrqu->frag.fixed = 0; /* no auto select */
7644 wrqu->frag.disabled = (priv->frag_threshold & FRAG_DISABLED) ? 1 : 0;
7646 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
7651 static int ipw2100_wx_set_retry(struct net_device *dev,
7652 struct iw_request_info *info,
7653 union iwreq_data *wrqu, char *extra)
7655 struct ipw2100_priv *priv = ieee80211_priv(dev);
7658 if (wrqu->retry.flags & IW_RETRY_LIFETIME ||
7659 wrqu->retry.disabled)
7662 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
7665 down(&priv->action_sem);
7666 if (!(priv->status & STATUS_INITIALIZED)) {
7671 if (wrqu->retry.flags & IW_RETRY_MIN) {
7672 err = ipw2100_set_short_retry(priv, wrqu->retry.value);
7673 IPW_DEBUG_WX("SET Short Retry Limit -> %d \n",
7678 if (wrqu->retry.flags & IW_RETRY_MAX) {
7679 err = ipw2100_set_long_retry(priv, wrqu->retry.value);
7680 IPW_DEBUG_WX("SET Long Retry Limit -> %d \n",
7685 err = ipw2100_set_short_retry(priv, wrqu->retry.value);
7687 err = ipw2100_set_long_retry(priv, wrqu->retry.value);
7689 IPW_DEBUG_WX("SET Both Retry Limits -> %d \n", wrqu->retry.value);
7692 up(&priv->action_sem);
7696 static int ipw2100_wx_get_retry(struct net_device *dev,
7697 struct iw_request_info *info,
7698 union iwreq_data *wrqu, char *extra)
7701 * This can be called at any time. No action lock required
7704 struct ipw2100_priv *priv = ieee80211_priv(dev);
7706 wrqu->retry.disabled = 0; /* can't be disabled */
7708 if ((wrqu->retry.flags & IW_RETRY_TYPE) ==
7712 if (wrqu->retry.flags & IW_RETRY_MAX) {
7713 wrqu->retry.flags = IW_RETRY_LIMIT & IW_RETRY_MAX;
7714 wrqu->retry.value = priv->long_retry_limit;
7717 (priv->short_retry_limit !=
7718 priv->long_retry_limit) ?
7719 IW_RETRY_LIMIT & IW_RETRY_MIN : IW_RETRY_LIMIT;
7721 wrqu->retry.value = priv->short_retry_limit;
7724 IPW_DEBUG_WX("GET Retry -> %d \n", wrqu->retry.value);
7729 static int ipw2100_wx_set_scan(struct net_device *dev,
7730 struct iw_request_info *info,
7731 union iwreq_data *wrqu, char *extra)
7733 struct ipw2100_priv *priv = ieee80211_priv(dev);
7736 down(&priv->action_sem);
7737 if (!(priv->status & STATUS_INITIALIZED)) {
7742 IPW_DEBUG_WX("Initiating scan...\n");
7743 if (ipw2100_set_scan_options(priv) ||
7744 ipw2100_start_scan(priv)) {
7745 IPW_DEBUG_WX("Start scan failed.\n");
7747 /* TODO: Mark a scan as pending so when hardware initialized
7752 up(&priv->action_sem);
7756 static int ipw2100_wx_get_scan(struct net_device *dev,
7757 struct iw_request_info *info,
7758 union iwreq_data *wrqu, char *extra)
7761 * This can be called at any time. No action lock required
7764 struct ipw2100_priv *priv = ieee80211_priv(dev);
7765 return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra);
7770 * Implementation based on code in hostap-driver v0.1.3 hostap_ioctl.c
7772 static int ipw2100_wx_set_encode(struct net_device *dev,
7773 struct iw_request_info *info,
7774 union iwreq_data *wrqu, char *key)
7777 * No check of STATUS_INITIALIZED required
7780 struct ipw2100_priv *priv = ieee80211_priv(dev);
7781 return ieee80211_wx_set_encode(priv->ieee, info, wrqu, key);
7784 static int ipw2100_wx_get_encode(struct net_device *dev,
7785 struct iw_request_info *info,
7786 union iwreq_data *wrqu, char *key)
7789 * This can be called at any time. No action lock required
7792 struct ipw2100_priv *priv = ieee80211_priv(dev);
7793 return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key);
7796 static int ipw2100_wx_set_power(struct net_device *dev,
7797 struct iw_request_info *info,
7798 union iwreq_data *wrqu, char *extra)
7800 struct ipw2100_priv *priv = ieee80211_priv(dev);
7803 down(&priv->action_sem);
7804 if (!(priv->status & STATUS_INITIALIZED)) {
7809 if (wrqu->power.disabled) {
7810 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
7811 err = ipw2100_set_power_mode(priv, IPW_POWER_MODE_CAM);
7812 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
7816 switch (wrqu->power.flags & IW_POWER_MODE) {
7817 case IW_POWER_ON: /* If not specified */
7818 case IW_POWER_MODE: /* If set all mask */
7819 case IW_POWER_ALL_R: /* If explicitely state all */
7821 default: /* Otherwise we don't support it */
7822 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
7828 /* If the user hasn't specified a power management mode yet, default
7830 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
7831 err = ipw2100_set_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
7833 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n",
7837 up(&priv->action_sem);
7842 static int ipw2100_wx_get_power(struct net_device *dev,
7843 struct iw_request_info *info,
7844 union iwreq_data *wrqu, char *extra)
7847 * This can be called at any time. No action lock required
7850 struct ipw2100_priv *priv = ieee80211_priv(dev);
7852 if (!(priv->power_mode & IPW_POWER_ENABLED)) {
7853 wrqu->power.disabled = 1;
7855 wrqu->power.disabled = 0;
7856 wrqu->power.flags = 0;
7859 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
7870 #ifdef CONFIG_IPW2100_MONITOR
7871 static int ipw2100_wx_set_promisc(struct net_device *dev,
7872 struct iw_request_info *info,
7873 union iwreq_data *wrqu, char *extra)
7875 struct ipw2100_priv *priv = ieee80211_priv(dev);
7876 int *parms = (int *)extra;
7877 int enable = (parms[0] > 0);
7880 down(&priv->action_sem);
7881 if (!(priv->status & STATUS_INITIALIZED)) {
7887 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7888 err = ipw2100_set_channel(priv, parms[1], 0);
7891 priv->channel = parms[1];
7892 err = ipw2100_switch_mode(priv, IW_MODE_MONITOR);
7894 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
7895 err = ipw2100_switch_mode(priv, priv->last_mode);
7898 up(&priv->action_sem);
7902 static int ipw2100_wx_reset(struct net_device *dev,
7903 struct iw_request_info *info,
7904 union iwreq_data *wrqu, char *extra)
7906 struct ipw2100_priv *priv = ieee80211_priv(dev);
7907 if (priv->status & STATUS_INITIALIZED)
7908 schedule_reset(priv);
7914 static int ipw2100_wx_set_powermode(struct net_device *dev,
7915 struct iw_request_info *info,
7916 union iwreq_data *wrqu, char *extra)
7918 struct ipw2100_priv *priv = ieee80211_priv(dev);
7919 int err = 0, mode = *(int *)extra;
7921 down(&priv->action_sem);
7922 if (!(priv->status & STATUS_INITIALIZED)) {
7927 if ((mode < 1) || (mode > POWER_MODES))
7928 mode = IPW_POWER_AUTO;
7930 if (priv->power_mode != mode)
7931 err = ipw2100_set_power_mode(priv, mode);
7933 up(&priv->action_sem);
7937 #define MAX_POWER_STRING 80
7938 static int ipw2100_wx_get_powermode(struct net_device *dev,
7939 struct iw_request_info *info,
7940 union iwreq_data *wrqu, char *extra)
7943 * This can be called at any time. No action lock required
7946 struct ipw2100_priv *priv = ieee80211_priv(dev);
7947 int level = IPW_POWER_LEVEL(priv->power_mode);
7948 s32 timeout, period;
7950 if (!(priv->power_mode & IPW_POWER_ENABLED)) {
7951 snprintf(extra, MAX_POWER_STRING,
7952 "Power save level: %d (Off)", level);
7955 case IPW_POWER_MODE_CAM:
7956 snprintf(extra, MAX_POWER_STRING,
7957 "Power save level: %d (None)", level);
7959 case IPW_POWER_AUTO:
7960 snprintf(extra, MAX_POWER_STRING,
7961 "Power save level: %d (Auto)", 0);
7964 timeout = timeout_duration[level - 1] / 1000;
7965 period = period_duration[level - 1] / 1000;
7966 snprintf(extra, MAX_POWER_STRING,
7967 "Power save level: %d "
7968 "(Timeout %dms, Period %dms)",
7969 level, timeout, period);
7973 wrqu->data.length = strlen(extra) + 1;
7979 static int ipw2100_wx_set_preamble(struct net_device *dev,
7980 struct iw_request_info *info,
7981 union iwreq_data *wrqu, char *extra)
7983 struct ipw2100_priv *priv = ieee80211_priv(dev);
7984 int err, mode = *(int *)extra;
7986 down(&priv->action_sem);
7987 if (!(priv->status & STATUS_INITIALIZED)) {
7993 priv->config |= CFG_LONG_PREAMBLE;
7995 priv->config &= ~CFG_LONG_PREAMBLE;
8001 err = ipw2100_system_config(priv, 0);
8004 up(&priv->action_sem);
8008 static int ipw2100_wx_get_preamble(struct net_device *dev,
8009 struct iw_request_info *info,
8010 union iwreq_data *wrqu, char *extra)
8013 * This can be called at any time. No action lock required
8016 struct ipw2100_priv *priv = ieee80211_priv(dev);
8018 if (priv->config & CFG_LONG_PREAMBLE)
8019 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
8021 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
8026 static iw_handler ipw2100_wx_handlers[] =
8028 NULL, /* SIOCSIWCOMMIT */
8029 ipw2100_wx_get_name, /* SIOCGIWNAME */
8030 NULL, /* SIOCSIWNWID */
8031 NULL, /* SIOCGIWNWID */
8032 ipw2100_wx_set_freq, /* SIOCSIWFREQ */
8033 ipw2100_wx_get_freq, /* SIOCGIWFREQ */
8034 ipw2100_wx_set_mode, /* SIOCSIWMODE */
8035 ipw2100_wx_get_mode, /* SIOCGIWMODE */
8036 NULL, /* SIOCSIWSENS */
8037 NULL, /* SIOCGIWSENS */
8038 NULL, /* SIOCSIWRANGE */
8039 ipw2100_wx_get_range, /* SIOCGIWRANGE */
8040 NULL, /* SIOCSIWPRIV */
8041 NULL, /* SIOCGIWPRIV */
8042 NULL, /* SIOCSIWSTATS */
8043 NULL, /* SIOCGIWSTATS */
8044 NULL, /* SIOCSIWSPY */
8045 NULL, /* SIOCGIWSPY */
8046 NULL, /* SIOCGIWTHRSPY */
8047 NULL, /* SIOCWIWTHRSPY */
8048 ipw2100_wx_set_wap, /* SIOCSIWAP */
8049 ipw2100_wx_get_wap, /* SIOCGIWAP */
8050 NULL, /* -- hole -- */
8051 NULL, /* SIOCGIWAPLIST -- deprecated */
8052 ipw2100_wx_set_scan, /* SIOCSIWSCAN */
8053 ipw2100_wx_get_scan, /* SIOCGIWSCAN */
8054 ipw2100_wx_set_essid, /* SIOCSIWESSID */
8055 ipw2100_wx_get_essid, /* SIOCGIWESSID */
8056 ipw2100_wx_set_nick, /* SIOCSIWNICKN */
8057 ipw2100_wx_get_nick, /* SIOCGIWNICKN */
8058 NULL, /* -- hole -- */
8059 NULL, /* -- hole -- */
8060 ipw2100_wx_set_rate, /* SIOCSIWRATE */
8061 ipw2100_wx_get_rate, /* SIOCGIWRATE */
8062 ipw2100_wx_set_rts, /* SIOCSIWRTS */
8063 ipw2100_wx_get_rts, /* SIOCGIWRTS */
8064 ipw2100_wx_set_frag, /* SIOCSIWFRAG */
8065 ipw2100_wx_get_frag, /* SIOCGIWFRAG */
8066 ipw2100_wx_set_txpow, /* SIOCSIWTXPOW */
8067 ipw2100_wx_get_txpow, /* SIOCGIWTXPOW */
8068 ipw2100_wx_set_retry, /* SIOCSIWRETRY */
8069 ipw2100_wx_get_retry, /* SIOCGIWRETRY */
8070 ipw2100_wx_set_encode, /* SIOCSIWENCODE */
8071 ipw2100_wx_get_encode, /* SIOCGIWENCODE */
8072 ipw2100_wx_set_power, /* SIOCSIWPOWER */
8073 ipw2100_wx_get_power, /* SIOCGIWPOWER */
8076 #define IPW2100_PRIV_SET_MONITOR SIOCIWFIRSTPRIV
8077 #define IPW2100_PRIV_RESET SIOCIWFIRSTPRIV+1
8078 #define IPW2100_PRIV_SET_POWER SIOCIWFIRSTPRIV+2
8079 #define IPW2100_PRIV_GET_POWER SIOCIWFIRSTPRIV+3
8080 #define IPW2100_PRIV_SET_LONGPREAMBLE SIOCIWFIRSTPRIV+4
8081 #define IPW2100_PRIV_GET_LONGPREAMBLE SIOCIWFIRSTPRIV+5
8083 static const struct iw_priv_args ipw2100_private_args[] = {
8085 #ifdef CONFIG_IPW2100_MONITOR
8087 IPW2100_PRIV_SET_MONITOR,
8088 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"
8092 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"
8094 #endif /* CONFIG_IPW2100_MONITOR */
8097 IPW2100_PRIV_SET_POWER,
8098 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_power"
8101 IPW2100_PRIV_GET_POWER,
8102 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_POWER_STRING, "get_power"
8105 IPW2100_PRIV_SET_LONGPREAMBLE,
8106 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_preamble"
8109 IPW2100_PRIV_GET_LONGPREAMBLE,
8110 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, "get_preamble"
8114 static iw_handler ipw2100_private_handler[] = {
8115 #ifdef CONFIG_IPW2100_MONITOR
8116 ipw2100_wx_set_promisc,
8118 #else /* CONFIG_IPW2100_MONITOR */
8121 #endif /* CONFIG_IPW2100_MONITOR */
8122 ipw2100_wx_set_powermode,
8123 ipw2100_wx_get_powermode,
8124 ipw2100_wx_set_preamble,
8125 ipw2100_wx_get_preamble,
8128 struct iw_handler_def ipw2100_wx_handler_def =
8130 .standard = ipw2100_wx_handlers,
8131 .num_standard = sizeof(ipw2100_wx_handlers) / sizeof(iw_handler),
8132 .num_private = sizeof(ipw2100_private_handler) / sizeof(iw_handler),
8133 .num_private_args = sizeof(ipw2100_private_args) /
8134 sizeof(struct iw_priv_args),
8135 .private = (iw_handler *)ipw2100_private_handler,
8136 .private_args = (struct iw_priv_args *)ipw2100_private_args,
8140 * Get wireless statistics.
8141 * Called by /proc/net/wireless
8142 * Also called by SIOCGIWSTATS
8144 struct iw_statistics *ipw2100_wx_wireless_stats(struct net_device * dev)
8158 struct ipw2100_priv *priv = ieee80211_priv(dev);
8159 struct iw_statistics *wstats;
8160 u32 rssi, quality, tx_retries, missed_beacons, tx_failures;
8161 u32 ord_len = sizeof(u32);
8164 return (struct iw_statistics *) NULL;
8166 wstats = &priv->wstats;
8168 /* if hw is disabled, then ipw2100_get_ordinal() can't be called.
8169 * ipw2100_wx_wireless_stats seems to be called before fw is
8170 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
8171 * and associated; if not associcated, the values are all meaningless
8172 * anyway, so set them all to NULL and INVALID */
8173 if (!(priv->status & STATUS_ASSOCIATED)) {
8174 wstats->miss.beacon = 0;
8175 wstats->discard.retries = 0;
8176 wstats->qual.qual = 0;
8177 wstats->qual.level = 0;
8178 wstats->qual.noise = 0;
8179 wstats->qual.updated = 7;
8180 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
8181 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
8185 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_PERCENT_MISSED_BCNS,
8186 &missed_beacons, &ord_len))
8187 goto fail_get_ordinal;
8189 /* If we don't have a connection the quality and level is 0*/
8190 if (!(priv->status & STATUS_ASSOCIATED)) {
8191 wstats->qual.qual = 0;
8192 wstats->qual.level = 0;
8194 if (ipw2100_get_ordinal(priv, IPW_ORD_RSSI_AVG_CURR,
8196 goto fail_get_ordinal;
8197 wstats->qual.level = rssi + IPW2100_RSSI_TO_DBM;
8199 rssi_qual = rssi * POOR / 10;
8201 rssi_qual = (rssi - 10) * (FAIR - POOR) / 5 + POOR;
8203 rssi_qual = (rssi - 15) * (GOOD - FAIR) / 5 + FAIR;
8205 rssi_qual = (rssi - 20) * (VERY_GOOD - GOOD) /
8208 rssi_qual = (rssi - 30) * (PERFECT - VERY_GOOD) /
8211 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_PERCENT_RETRIES,
8212 &tx_retries, &ord_len))
8213 goto fail_get_ordinal;
8215 if (tx_retries > 75)
8216 tx_qual = (90 - tx_retries) * POOR / 15;
8217 else if (tx_retries > 70)
8218 tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
8219 else if (tx_retries > 65)
8220 tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
8221 else if (tx_retries > 50)
8222 tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
8225 tx_qual = (50 - tx_retries) *
8226 (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
8228 if (missed_beacons > 50)
8229 beacon_qual = (60 - missed_beacons) * POOR / 10;
8230 else if (missed_beacons > 40)
8231 beacon_qual = (50 - missed_beacons) * (FAIR - POOR) /
8233 else if (missed_beacons > 32)
8234 beacon_qual = (40 - missed_beacons) * (GOOD - FAIR) /
8236 else if (missed_beacons > 20)
8237 beacon_qual = (32 - missed_beacons) *
8238 (VERY_GOOD - GOOD) / 20 + GOOD;
8240 beacon_qual = (20 - missed_beacons) *
8241 (PERFECT - VERY_GOOD) / 20 + VERY_GOOD;
8243 quality = min(beacon_qual, min(tx_qual, rssi_qual));
8245 #ifdef CONFIG_IPW_DEBUG
8246 if (beacon_qual == quality)
8247 IPW_DEBUG_WX("Quality clamped by Missed Beacons\n");
8248 else if (tx_qual == quality)
8249 IPW_DEBUG_WX("Quality clamped by Tx Retries\n");
8250 else if (quality != 100)
8251 IPW_DEBUG_WX("Quality clamped by Signal Strength\n");
8253 IPW_DEBUG_WX("Quality not clamped.\n");
8256 wstats->qual.qual = quality;
8257 wstats->qual.level = rssi + IPW2100_RSSI_TO_DBM;
8260 wstats->qual.noise = 0;
8261 wstats->qual.updated = 7;
8262 wstats->qual.updated |= IW_QUAL_NOISE_INVALID;
8264 /* FIXME: this is percent and not a # */
8265 wstats->miss.beacon = missed_beacons;
8267 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURES,
8268 &tx_failures, &ord_len))
8269 goto fail_get_ordinal;
8270 wstats->discard.retries = tx_failures;
8275 IPW_DEBUG_WX("failed querying ordinals.\n");
8277 return (struct iw_statistics *) NULL;
8280 void ipw2100_wx_event_work(struct ipw2100_priv *priv)
8282 union iwreq_data wrqu;
8285 if (priv->status & STATUS_STOPPING)
8288 down(&priv->action_sem);
8290 IPW_DEBUG_WX("enter\n");
8292 up(&priv->action_sem);
8294 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
8296 /* Fetch BSSID from the hardware */
8297 if (!(priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) ||
8298 priv->status & STATUS_RF_KILL_MASK ||
8299 ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID,
8300 &priv->bssid, &len)) {
8301 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
8303 /* We now have the BSSID, so can finish setting to the full
8304 * associated state */
8305 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
8306 memcpy(&priv->ieee->bssid, priv->bssid, ETH_ALEN);
8307 priv->status &= ~STATUS_ASSOCIATING;
8308 priv->status |= STATUS_ASSOCIATED;
8309 netif_carrier_on(priv->net_dev);
8310 if (netif_queue_stopped(priv->net_dev)) {
8311 IPW_DEBUG_INFO("Waking net queue.\n");
8312 netif_wake_queue(priv->net_dev);
8314 IPW_DEBUG_INFO("Starting net queue.\n");
8315 netif_start_queue(priv->net_dev);
8319 if (!(priv->status & STATUS_ASSOCIATED)) {
8320 IPW_DEBUG_WX("Configuring ESSID\n");
8321 down(&priv->action_sem);
8322 /* This is a disassociation event, so kick the firmware to
8323 * look for another AP */
8324 if (priv->config & CFG_STATIC_ESSID)
8325 ipw2100_set_essid(priv, priv->essid, priv->essid_len, 0);
8327 ipw2100_set_essid(priv, NULL, 0, 0);
8328 up(&priv->action_sem);
8331 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
8334 #define IPW2100_FW_MAJOR_VERSION 1
8335 #define IPW2100_FW_MINOR_VERSION 3
8337 #define IPW2100_FW_MINOR(x) ((x & 0xff) >> 8)
8338 #define IPW2100_FW_MAJOR(x) (x & 0xff)
8340 #define IPW2100_FW_VERSION ((IPW2100_FW_MINOR_VERSION << 8) | \
8341 IPW2100_FW_MAJOR_VERSION)
8343 #define IPW2100_FW_PREFIX "ipw2100-" __stringify(IPW2100_FW_MAJOR_VERSION) \
8344 "." __stringify(IPW2100_FW_MINOR_VERSION)
8346 #define IPW2100_FW_NAME(x) IPW2100_FW_PREFIX "" x ".fw"
8351 BINARY FIRMWARE HEADER FORMAT
8355 2 2 mode == 0:BSS,1:IBSS,2:MONITOR
8358 C fw_len firmware data
8359 12 + fw_len uc_len microcode data
8363 struct ipw2100_fw_header {
8366 unsigned int fw_size;
8367 unsigned int uc_size;
8368 } __attribute__ ((packed));
8372 static int ipw2100_mod_firmware_load(struct ipw2100_fw *fw)
8374 struct ipw2100_fw_header *h =
8375 (struct ipw2100_fw_header *)fw->fw_entry->data;
8377 if (IPW2100_FW_MAJOR(h->version) != IPW2100_FW_MAJOR_VERSION) {
8378 IPW_DEBUG_WARNING("Firmware image not compatible "
8379 "(detected version id of %u). "
8380 "See Documentation/networking/README.ipw2100\n",
8385 fw->version = h->version;
8386 fw->fw.data = fw->fw_entry->data + sizeof(struct ipw2100_fw_header);
8387 fw->fw.size = h->fw_size;
8388 fw->uc.data = fw->fw.data + h->fw_size;
8389 fw->uc.size = h->uc_size;
8395 int ipw2100_get_firmware(struct ipw2100_priv *priv, struct ipw2100_fw *fw)
8400 IPW_DEBUG_INFO("%s: Using hotplug firmware load.\n",
8401 priv->net_dev->name);
8403 switch (priv->ieee->iw_mode) {
8405 fw_name = IPW2100_FW_NAME("-i");
8407 #ifdef CONFIG_IPW2100_MONITOR
8408 case IW_MODE_MONITOR:
8409 fw_name = IPW2100_FW_NAME("-p");
8414 fw_name = IPW2100_FW_NAME("");
8418 rc = request_firmware(&fw->fw_entry, fw_name, &priv->pci_dev->dev);
8422 "%s: Firmware '%s' not available or load failed.\n",
8423 priv->net_dev->name, fw_name);
8426 IPW_DEBUG_INFO("firmware data %p size %zd\n", fw->fw_entry->data,
8427 fw->fw_entry->size);
8429 ipw2100_mod_firmware_load(fw);
8434 void ipw2100_release_firmware(struct ipw2100_priv *priv,
8435 struct ipw2100_fw *fw)
8439 release_firmware(fw->fw_entry);
8440 fw->fw_entry = NULL;
8444 int ipw2100_get_fwversion(struct ipw2100_priv *priv, char *buf, size_t max)
8446 char ver[MAX_FW_VERSION_LEN];
8447 u32 len = MAX_FW_VERSION_LEN;
8450 /* firmware version is an ascii string (max len of 14) */
8451 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_FW_VER_NUM,
8457 for (i = 0; i < len; i++)
8463 int ipw2100_get_ucodeversion(struct ipw2100_priv *priv, char *buf, size_t max)
8466 u32 len = sizeof(ver);
8467 /* microcode version is a 32 bit integer */
8468 if (ipw2100_get_ordinal(priv, IPW_ORD_UCODE_VERSION,
8471 return snprintf(buf, max, "%08X", ver);
8475 * On exit, the firmware will have been freed from the fw list
8477 int ipw2100_fw_download(struct ipw2100_priv *priv, struct ipw2100_fw *fw)
8479 /* firmware is constructed of N contiguous entries, each entry is
8483 * 0 4 address to write to
8484 * 4 2 length of data run
8490 const unsigned char *firmware_data = fw->fw.data;
8491 unsigned int firmware_data_left = fw->fw.size;
8493 while (firmware_data_left > 0) {
8494 addr = *(u32 *)(firmware_data);
8496 firmware_data_left -= 4;
8498 len = *(u16 *)(firmware_data);
8500 firmware_data_left -= 2;
8504 "Invalid firmware run-length of %d bytes\n",
8509 write_nic_memory(priv->net_dev, addr, len, firmware_data);
8510 firmware_data += len;
8511 firmware_data_left -= len;
8517 struct symbol_alive_response {
8526 u16 clock_settle_time; // 1us LSB
8527 u16 powerup_settle_time; // 1us LSB
8528 u16 hop_settle_time; // 1us LSB
8529 u8 date[3]; // month, day, year
8530 u8 time[2]; // hours, minutes
8534 int ipw2100_ucode_download(struct ipw2100_priv *priv, struct ipw2100_fw *fw)
8536 struct net_device *dev = priv->net_dev;
8537 const unsigned char *microcode_data = fw->uc.data;
8538 unsigned int microcode_data_left = fw->uc.size;
8540 struct symbol_alive_response response;
8544 /* Symbol control */
8545 write_nic_word(dev, IPW2100_CONTROL_REG, 0x703);
8546 readl((void *)(dev->base_addr));
8547 write_nic_word(dev, IPW2100_CONTROL_REG, 0x707);
8548 readl((void *)(dev->base_addr));
8551 write_nic_byte(dev, 0x210014, 0x72); /* fifo width =16 */
8552 readl((void *)(dev->base_addr));
8553 write_nic_byte(dev, 0x210014, 0x72); /* fifo width =16 */
8554 readl((void *)(dev->base_addr));
8556 /* EN_CS_ACCESS bit to reset control store pointer */
8557 write_nic_byte(dev, 0x210000, 0x40);
8558 readl((void *)(dev->base_addr));
8559 write_nic_byte(dev, 0x210000, 0x0);
8560 readl((void *)(dev->base_addr));
8561 write_nic_byte(dev, 0x210000, 0x40);
8562 readl((void *)(dev->base_addr));
8564 /* copy microcode from buffer into Symbol */
8566 while (microcode_data_left > 0) {
8567 write_nic_byte(dev, 0x210010, *microcode_data++);
8568 write_nic_byte(dev, 0x210010, *microcode_data++);
8569 microcode_data_left -= 2;
8572 /* EN_CS_ACCESS bit to reset the control store pointer */
8573 write_nic_byte(dev, 0x210000, 0x0);
8574 readl((void *)(dev->base_addr));
8576 /* Enable System (Reg 0)
8577 * first enable causes garbage in RX FIFO */
8578 write_nic_byte(dev, 0x210000, 0x0);
8579 readl((void *)(dev->base_addr));
8580 write_nic_byte(dev, 0x210000, 0x80);
8581 readl((void *)(dev->base_addr));
8583 /* Reset External Baseband Reg */
8584 write_nic_word(dev, IPW2100_CONTROL_REG, 0x703);
8585 readl((void *)(dev->base_addr));
8586 write_nic_word(dev, IPW2100_CONTROL_REG, 0x707);
8587 readl((void *)(dev->base_addr));
8589 /* HW Config (Reg 5) */
8590 write_nic_byte(dev, 0x210014, 0x72); // fifo width =16
8591 readl((void *)(dev->base_addr));
8592 write_nic_byte(dev, 0x210014, 0x72); // fifo width =16
8593 readl((void *)(dev->base_addr));
8595 /* Enable System (Reg 0)
8596 * second enable should be OK */
8597 write_nic_byte(dev, 0x210000, 0x00); // clear enable system
8598 readl((void *)(dev->base_addr));
8599 write_nic_byte(dev, 0x210000, 0x80); // set enable system
8601 /* check Symbol is enabled - upped this from 5 as it wasn't always
8602 * catching the update */
8603 for (i = 0; i < 10; i++) {
8606 /* check Dino is enabled bit */
8607 read_nic_byte(dev, 0x210000, &data);
8613 IPW_DEBUG_ERROR("%s: Error initializing Symbol\n",
8618 /* Get Symbol alive response */
8619 for (i = 0; i < 30; i++) {
8620 /* Read alive response structure */
8622 j < (sizeof(struct symbol_alive_response) >> 1);
8624 read_nic_word(dev, 0x210004,
8625 ((u16 *)&response) + j);
8627 if ((response.cmd_id == 1) &&
8628 (response.ucode_valid == 0x1))
8634 IPW_DEBUG_ERROR("%s: No response from Symbol - hw not alive\n",
8636 printk_buf(IPW_DL_ERROR, (u8*)&response, sizeof(response));