1 /******************************************************************************
3 Copyright(c) 2003 - 2005 Intel Corporation. All rights reserved.
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of version 2 of the GNU General Public License as
7 published by the Free Software Foundation.
9 This program is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 You should have received a copy of the GNU General Public License along with
15 this program; if not, write to the Free Software Foundation, Inc., 59
16 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 The full GNU General Public License is included in this distribution in the
22 James P. Ketrenos <ipw2100-admin@linux.intel.com>
23 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25 Portions of this file are based on the sample_* files provided by Wireless
26 Extensions 0.26 package and copyright (c) 1997-2003 Jean Tourrilhes
29 Portions of this file are based on the Host AP project,
30 Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
32 Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
34 Portions of ipw2100_mod_firmware_load, ipw2100_do_mod_firmware_load, and
35 ipw2100_fw_load are loosely based on drivers/sound/sound_firmware.c
36 available in the 2.4.25 kernel sources, and are copyright (c) Alan Cox
38 ******************************************************************************/
41 Initial driver on which this is based was developed by Janusz Gorycki,
42 Maciej Urbaniak, and Maciej Sosnowski.
44 Promiscuous mode support added by Jacek Wysoczynski and Maciej Urbaniak.
48 Tx - Commands and Data
50 Firmware and host share a circular queue of Transmit Buffer Descriptors (TBDs)
51 Each TBD contains a pointer to the physical (dma_addr_t) address of data being
52 sent to the firmware as well as the length of the data.
54 The host writes to the TBD queue at the WRITE index. The WRITE index points
55 to the _next_ packet to be written and is advanced when after the TBD has been
58 The firmware pulls from the TBD queue at the READ index. The READ index points
59 to the currently being read entry, and is advanced once the firmware is
62 When data is sent to the firmware, the first TBD is used to indicate to the
63 firmware if a Command or Data is being sent. If it is Command, all of the
64 command information is contained within the physical address referred to by the
65 TBD. If it is Data, the first TBD indicates the type of data packet, number
66 of fragments, etc. The next TBD then referrs to the actual packet location.
68 The Tx flow cycle is as follows:
70 1) ipw2100_tx() is called by kernel with SKB to transmit
71 2) Packet is move from the tx_free_list and appended to the transmit pending
73 3) work is scheduled to move pending packets into the shared circular queue.
74 4) when placing packet in the circular queue, the incoming SKB is DMA mapped
75 to a physical address. That address is entered into a TBD. Two TBDs are
76 filled out. The first indicating a data packet, the second referring to the
78 5) the packet is removed from tx_pend_list and placed on the end of the
79 firmware pending list (fw_pend_list)
80 6) firmware is notified that the WRITE index has
81 7) Once the firmware has processed the TBD, INTA is triggered.
82 8) For each Tx interrupt received from the firmware, the READ index is checked
83 to see which TBDs are done being processed.
84 9) For each TBD that has been processed, the ISR pulls the oldest packet
85 from the fw_pend_list.
86 10)The packet structure contained in the fw_pend_list is then used
87 to unmap the DMA address and to free the SKB originally passed to the driver
89 11)The packet structure is placed onto the tx_free_list
91 The above steps are the same for commands, only the msg_free_list/msg_pend_list
92 are used instead of tx_free_list/tx_pend_list
96 Critical Sections / Locking :
98 There are two locks utilized. The first is the low level lock (priv->low_lock)
99 that protects the following:
101 - Access to the Tx/Rx queue lists via priv->low_lock. The lists are as follows:
103 tx_free_list : Holds pre-allocated Tx buffers.
104 TAIL modified in __ipw2100_tx_process()
105 HEAD modified in ipw2100_tx()
107 tx_pend_list : Holds used Tx buffers waiting to go into the TBD ring
108 TAIL modified ipw2100_tx()
109 HEAD modified by X__ipw2100_tx_send_data()
111 msg_free_list : Holds pre-allocated Msg (Command) buffers
112 TAIL modified in __ipw2100_tx_process()
113 HEAD modified in ipw2100_hw_send_command()
115 msg_pend_list : Holds used Msg buffers waiting to go into the TBD ring
116 TAIL modified in ipw2100_hw_send_command()
117 HEAD modified in X__ipw2100_tx_send_commands()
119 The flow of data on the TX side is as follows:
121 MSG_FREE_LIST + COMMAND => MSG_PEND_LIST => TBD => MSG_FREE_LIST
122 TX_FREE_LIST + DATA => TX_PEND_LIST => TBD => TX_FREE_LIST
124 The methods that work on the TBD ring are protected via priv->low_lock.
126 - The internal data state of the device itself
127 - Access to the firmware read/write indexes for the BD queues
130 All external entry functions are locked with the priv->action_lock to ensure
131 that only one external action is invoked at a time.
136 #include <linux/compiler.h>
137 #include <linux/config.h>
138 #include <linux/errno.h>
139 #include <linux/if_arp.h>
140 #include <linux/in6.h>
141 #include <linux/in.h>
142 #include <linux/ip.h>
143 #include <linux/kernel.h>
144 #include <linux/kmod.h>
145 #include <linux/module.h>
146 #include <linux/netdevice.h>
147 #include <linux/ethtool.h>
148 #include <linux/pci.h>
149 #include <linux/dma-mapping.h>
150 #include <linux/proc_fs.h>
151 #include <linux/skbuff.h>
152 #include <asm/uaccess.h>
154 #define __KERNEL_SYSCALLS__
155 #include <linux/fs.h>
156 #include <linux/mm.h>
157 #include <linux/slab.h>
158 #include <linux/unistd.h>
159 #include <linux/stringify.h>
160 #include <linux/tcp.h>
161 #include <linux/types.h>
162 #include <linux/version.h>
163 #include <linux/time.h>
164 #include <linux/firmware.h>
165 #include <linux/acpi.h>
166 #include <linux/ctype.h>
170 #define IPW2100_VERSION "1.1.0"
172 #define DRV_NAME "ipw2100"
173 #define DRV_VERSION IPW2100_VERSION
174 #define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2100 Network Driver"
175 #define DRV_COPYRIGHT "Copyright(c) 2003-2004 Intel Corporation"
178 /* Debugging stuff */
179 #ifdef CONFIG_IPW_DEBUG
180 #define CONFIG_IPW2100_RX_DEBUG /* Reception debugging */
183 MODULE_DESCRIPTION(DRV_DESCRIPTION);
184 MODULE_VERSION(DRV_VERSION);
185 MODULE_AUTHOR(DRV_COPYRIGHT);
186 MODULE_LICENSE("GPL");
188 static int debug = 0;
190 static int channel = 0;
191 static int associate = 1;
192 static int disable = 0;
194 static struct ipw2100_fw ipw2100_firmware;
197 #include <linux/moduleparam.h>
198 module_param(debug, int, 0444);
199 module_param(mode, int, 0444);
200 module_param(channel, int, 0444);
201 module_param(associate, int, 0444);
202 module_param(disable, int, 0444);
204 MODULE_PARM_DESC(debug, "debug level");
205 MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
206 MODULE_PARM_DESC(channel, "channel");
207 MODULE_PARM_DESC(associate, "auto associate when scanning (default on)");
208 MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
210 u32 ipw2100_debug_level = IPW_DL_NONE;
212 #ifdef CONFIG_IPW_DEBUG
213 static const char *command_types[] = {
215 "unused", /* HOST_ATTENTION */
217 "unused", /* SLEEP */
218 "unused", /* HOST_POWER_DOWN */
221 "unused", /* SET_IMR */
224 "AUTHENTICATION_TYPE",
227 "INTERNATIONAL_MODE",
242 "CLEAR_ALL_MULTICAST",
263 "AP_OR_STATION_TABLE",
267 "unused", /* SAVE_CALIBRATION */
268 "unused", /* RESTORE_CALIBRATION */
272 "HOST_PRE_POWER_DOWN",
273 "unused", /* HOST_INTERRUPT_COALESCING */
275 "CARD_DISABLE_PHY_OFF",
279 "SET_STATION_STAT_BITS",
280 "CLEAR_STATIONS_STAT_BITS",
282 "SET_SECURITY_INFORMATION",
283 "DISASSOCIATION_BSSID",
289 /* Pre-decl until we get the code solid and then we can clean it up */
290 static void X__ipw2100_tx_send_commands(struct ipw2100_priv *priv);
291 static void X__ipw2100_tx_send_data(struct ipw2100_priv *priv);
292 static int ipw2100_adapter_setup(struct ipw2100_priv *priv);
294 static void ipw2100_queues_initialize(struct ipw2100_priv *priv);
295 static void ipw2100_queues_free(struct ipw2100_priv *priv);
296 static int ipw2100_queues_allocate(struct ipw2100_priv *priv);
299 static inline void read_register(struct net_device *dev, u32 reg, u32 *val)
301 *val = readl((void *)(dev->base_addr + reg));
302 IPW_DEBUG_IO("r: 0x%08X => 0x%08X\n", reg, *val);
305 static inline void write_register(struct net_device *dev, u32 reg, u32 val)
307 writel(val, (void *)(dev->base_addr + reg));
308 IPW_DEBUG_IO("w: 0x%08X <= 0x%08X\n", reg, val);
311 static inline void read_register_word(struct net_device *dev, u32 reg, u16 *val)
313 *val = readw((void *)(dev->base_addr + reg));
314 IPW_DEBUG_IO("r: 0x%08X => %04X\n", reg, *val);
317 static inline void read_register_byte(struct net_device *dev, u32 reg, u8 *val)
319 *val = readb((void *)(dev->base_addr + reg));
320 IPW_DEBUG_IO("r: 0x%08X => %02X\n", reg, *val);
323 static inline void write_register_word(struct net_device *dev, u32 reg, u16 val)
325 writew(val, (void *)(dev->base_addr + reg));
326 IPW_DEBUG_IO("w: 0x%08X <= %04X\n", reg, val);
330 static inline void write_register_byte(struct net_device *dev, u32 reg, u8 val)
332 writeb(val, (void *)(dev->base_addr + reg));
333 IPW_DEBUG_IO("w: 0x%08X =< %02X\n", reg, val);
336 static inline void read_nic_dword(struct net_device *dev, u32 addr, u32 *val)
338 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
339 addr & IPW_REG_INDIRECT_ADDR_MASK);
340 read_register(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
343 static inline void write_nic_dword(struct net_device *dev, u32 addr, u32 val)
345 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
346 addr & IPW_REG_INDIRECT_ADDR_MASK);
347 write_register(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
350 static inline void read_nic_word(struct net_device *dev, u32 addr, u16 *val)
352 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
353 addr & IPW_REG_INDIRECT_ADDR_MASK);
354 read_register_word(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
357 static inline void write_nic_word(struct net_device *dev, u32 addr, u16 val)
359 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
360 addr & IPW_REG_INDIRECT_ADDR_MASK);
361 write_register_word(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
364 static inline void read_nic_byte(struct net_device *dev, u32 addr, u8 *val)
366 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
367 addr & IPW_REG_INDIRECT_ADDR_MASK);
368 read_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
371 static inline void write_nic_byte(struct net_device *dev, u32 addr, u8 val)
373 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
374 addr & IPW_REG_INDIRECT_ADDR_MASK);
375 write_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
378 static inline void write_nic_auto_inc_address(struct net_device *dev, u32 addr)
380 write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS,
381 addr & IPW_REG_INDIRECT_ADDR_MASK);
384 static inline void write_nic_dword_auto_inc(struct net_device *dev, u32 val)
386 write_register(dev, IPW_REG_AUTOINCREMENT_DATA, val);
389 static inline void write_nic_memory(struct net_device *dev, u32 addr, u32 len,
397 /* read first nibble byte by byte */
398 aligned_addr = addr & (~0x3);
399 dif_len = addr - aligned_addr;
401 /* Start reading at aligned_addr + dif_len */
402 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
404 for (i = dif_len; i < 4; i++, buf++)
406 dev, IPW_REG_INDIRECT_ACCESS_DATA + i,
413 /* read DWs through autoincrement registers */
414 write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS,
416 aligned_len = len & (~0x3);
417 for (i = 0; i < aligned_len; i += 4, buf += 4, aligned_addr += 4)
419 dev, IPW_REG_AUTOINCREMENT_DATA, *(u32 *)buf);
421 /* copy the last nibble */
422 dif_len = len - aligned_len;
423 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, aligned_addr);
424 for (i = 0; i < dif_len; i++, buf++)
426 dev, IPW_REG_INDIRECT_ACCESS_DATA + i, *buf);
429 static inline void read_nic_memory(struct net_device *dev, u32 addr, u32 len,
437 /* read first nibble byte by byte */
438 aligned_addr = addr & (~0x3);
439 dif_len = addr - aligned_addr;
441 /* Start reading at aligned_addr + dif_len */
442 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
444 for (i = dif_len; i < 4; i++, buf++)
446 dev, IPW_REG_INDIRECT_ACCESS_DATA + i, buf);
452 /* read DWs through autoincrement registers */
453 write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS,
455 aligned_len = len & (~0x3);
456 for (i = 0; i < aligned_len; i += 4, buf += 4, aligned_addr += 4)
457 read_register(dev, IPW_REG_AUTOINCREMENT_DATA,
460 /* copy the last nibble */
461 dif_len = len - aligned_len;
462 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
464 for (i = 0; i < dif_len; i++, buf++)
465 read_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA +
469 static inline int ipw2100_hw_is_adapter_in_system(struct net_device *dev)
471 return (dev->base_addr &&
472 (readl((void *)(dev->base_addr + IPW_REG_DOA_DEBUG_AREA_START))
473 == IPW_DATA_DOA_DEBUG_VALUE));
476 int ipw2100_get_ordinal(struct ipw2100_priv *priv, u32 ord,
479 struct ipw2100_ordinals *ordinals = &priv->ordinals;
486 if (ordinals->table1_addr == 0) {
487 IPW_DEBUG_WARNING(DRV_NAME ": attempt to use fw ordinals "
488 "before they have been loaded.\n");
492 if (IS_ORDINAL_TABLE_ONE(ordinals, ord)) {
493 if (*len < IPW_ORD_TAB_1_ENTRY_SIZE) {
494 *len = IPW_ORD_TAB_1_ENTRY_SIZE;
496 IPW_DEBUG_WARNING(DRV_NAME
497 ": ordinal buffer length too small, need %zd\n",
498 IPW_ORD_TAB_1_ENTRY_SIZE);
503 read_nic_dword(priv->net_dev, ordinals->table1_addr + (ord << 2),
505 read_nic_dword(priv->net_dev, addr, val);
507 *len = IPW_ORD_TAB_1_ENTRY_SIZE;
512 if (IS_ORDINAL_TABLE_TWO(ordinals, ord)) {
514 ord -= IPW_START_ORD_TAB_2;
516 /* get the address of statistic */
517 read_nic_dword(priv->net_dev, ordinals->table2_addr + (ord << 3),
520 /* get the second DW of statistics ;
521 * two 16-bit words - first is length, second is count */
522 read_nic_dword(priv->net_dev,
523 ordinals->table2_addr + (ord << 3) + sizeof(u32),
526 /* get each entry length */
527 field_len = *((u16 *)&field_info);
529 /* get number of entries */
530 field_count = *(((u16 *)&field_info) + 1);
532 /* abort if no enought memory */
533 total_length = field_len * field_count;
534 if (total_length > *len) {
543 /* read the ordinal data from the SRAM */
544 read_nic_memory(priv->net_dev, addr, total_length, val);
549 IPW_DEBUG_WARNING(DRV_NAME ": ordinal %d neither in table 1 nor "
550 "in table 2\n", ord);
555 static int ipw2100_set_ordinal(struct ipw2100_priv *priv, u32 ord, u32 *val,
558 struct ipw2100_ordinals *ordinals = &priv->ordinals;
561 if (IS_ORDINAL_TABLE_ONE(ordinals, ord)) {
562 if (*len != IPW_ORD_TAB_1_ENTRY_SIZE) {
563 *len = IPW_ORD_TAB_1_ENTRY_SIZE;
564 IPW_DEBUG_INFO("wrong size\n");
568 read_nic_dword(priv->net_dev, ordinals->table1_addr + (ord << 2),
571 write_nic_dword(priv->net_dev, addr, *val);
573 *len = IPW_ORD_TAB_1_ENTRY_SIZE;
578 IPW_DEBUG_INFO("wrong table\n");
579 if (IS_ORDINAL_TABLE_TWO(ordinals, ord))
585 static char *snprint_line(char *buf, size_t count,
586 const u8 *data, u32 len, u32 ofs)
591 out = snprintf(buf, count, "%08X", ofs);
593 for (l = 0, i = 0; i < 2; i++) {
594 out += snprintf(buf + out, count - out, " ");
595 for (j = 0; j < 8 && l < len; j++, l++)
596 out += snprintf(buf + out, count - out, "%02X ",
599 out += snprintf(buf + out, count - out, " ");
602 out += snprintf(buf + out, count - out, " ");
603 for (l = 0, i = 0; i < 2; i++) {
604 out += snprintf(buf + out, count - out, " ");
605 for (j = 0; j < 8 && l < len; j++, l++) {
606 c = data[(i * 8 + j)];
607 if (!isascii(c) || !isprint(c))
610 out += snprintf(buf + out, count - out, "%c", c);
614 out += snprintf(buf + out, count - out, " ");
620 static void printk_buf(int level, const u8 *data, u32 len)
624 if (!(ipw2100_debug_level & level))
628 printk(KERN_DEBUG "%s\n",
629 snprint_line(line, sizeof(line), &data[ofs],
630 min(len, 16U), ofs));
632 len -= min(len, 16U);
638 #define MAX_RESET_BACKOFF 10
640 static inline void schedule_reset(struct ipw2100_priv *priv)
642 unsigned long now = get_seconds();
644 /* If we haven't received a reset request within the backoff period,
645 * then we can reset the backoff interval so this reset occurs
647 if (priv->reset_backoff &&
648 (now - priv->last_reset > priv->reset_backoff))
649 priv->reset_backoff = 0;
651 priv->last_reset = get_seconds();
653 if (!(priv->status & STATUS_RESET_PENDING)) {
654 IPW_DEBUG_INFO("%s: Scheduling firmware restart (%ds).\n",
655 priv->net_dev->name, priv->reset_backoff);
656 netif_carrier_off(priv->net_dev);
657 netif_stop_queue(priv->net_dev);
658 priv->status |= STATUS_RESET_PENDING;
659 if (priv->reset_backoff)
660 queue_delayed_work(priv->workqueue, &priv->reset_work,
661 priv->reset_backoff * HZ);
663 queue_work(priv->workqueue, &priv->reset_work);
665 if (priv->reset_backoff < MAX_RESET_BACKOFF)
666 priv->reset_backoff++;
668 wake_up_interruptible(&priv->wait_command_queue);
670 IPW_DEBUG_INFO("%s: Firmware restart already in progress.\n",
671 priv->net_dev->name);
675 #define HOST_COMPLETE_TIMEOUT (2 * HZ)
676 static int ipw2100_hw_send_command(struct ipw2100_priv *priv,
677 struct host_command * cmd)
679 struct list_head *element;
680 struct ipw2100_tx_packet *packet;
684 IPW_DEBUG_HC("Sending %s command (#%d), %d bytes\n",
685 command_types[cmd->host_command], cmd->host_command,
686 cmd->host_command_length);
687 printk_buf(IPW_DL_HC, (u8*)cmd->host_command_parameters,
688 cmd->host_command_length);
690 spin_lock_irqsave(&priv->low_lock, flags);
692 if (priv->fatal_error) {
693 IPW_DEBUG_INFO("Attempt to send command while hardware in fatal error condition.\n");
698 if (!(priv->status & STATUS_RUNNING)) {
699 IPW_DEBUG_INFO("Attempt to send command while hardware is not running.\n");
704 if (priv->status & STATUS_CMD_ACTIVE) {
705 IPW_DEBUG_INFO("Attempt to send command while another command is pending.\n");
710 if (list_empty(&priv->msg_free_list)) {
711 IPW_DEBUG_INFO("no available msg buffers\n");
715 priv->status |= STATUS_CMD_ACTIVE;
716 priv->messages_sent++;
718 element = priv->msg_free_list.next;
720 packet = list_entry(element, struct ipw2100_tx_packet, list);
721 packet->jiffy_start = jiffies;
723 /* initialize the firmware command packet */
724 packet->info.c_struct.cmd->host_command_reg = cmd->host_command;
725 packet->info.c_struct.cmd->host_command_reg1 = cmd->host_command1;
726 packet->info.c_struct.cmd->host_command_len_reg = cmd->host_command_length;
727 packet->info.c_struct.cmd->sequence = cmd->host_command_sequence;
729 memcpy(packet->info.c_struct.cmd->host_command_params_reg,
730 cmd->host_command_parameters,
731 sizeof(packet->info.c_struct.cmd->host_command_params_reg));
734 DEC_STAT(&priv->msg_free_stat);
736 list_add_tail(element, &priv->msg_pend_list);
737 INC_STAT(&priv->msg_pend_stat);
739 X__ipw2100_tx_send_commands(priv);
740 X__ipw2100_tx_send_data(priv);
742 spin_unlock_irqrestore(&priv->low_lock, flags);
745 * We must wait for this command to complete before another
746 * command can be sent... but if we wait more than 3 seconds
747 * then there is a problem.
750 err = wait_event_interruptible_timeout(
751 priv->wait_command_queue, !(priv->status & STATUS_CMD_ACTIVE),
752 HOST_COMPLETE_TIMEOUT);
755 IPW_DEBUG_INFO("Command completion failed out after %dms.\n",
756 HOST_COMPLETE_TIMEOUT / (HZ / 100));
757 priv->fatal_error = IPW2100_ERR_MSG_TIMEOUT;
758 priv->status &= ~STATUS_CMD_ACTIVE;
759 schedule_reset(priv);
763 if (priv->fatal_error) {
764 IPW_DEBUG_WARNING("%s: firmware fatal error\n",
765 priv->net_dev->name);
769 /* !!!!! HACK TEST !!!!!
770 * When lots of debug trace statements are enabled, the driver
771 * doesn't seem to have as many firmware restart cycles...
773 * As a test, we're sticking in a 1/100s delay here */
774 set_current_state(TASK_UNINTERRUPTIBLE);
775 schedule_timeout(HZ / 100);
780 spin_unlock_irqrestore(&priv->low_lock, flags);
787 * Verify the values and data access of the hardware
788 * No locks needed or used. No functions called.
790 static int ipw2100_verify(struct ipw2100_priv *priv)
795 u32 val1 = 0x76543210;
796 u32 val2 = 0xFEDCBA98;
798 /* Domain 0 check - all values should be DOA_DEBUG */
799 for (address = IPW_REG_DOA_DEBUG_AREA_START;
800 address < IPW_REG_DOA_DEBUG_AREA_END;
801 address += sizeof(u32)) {
802 read_register(priv->net_dev, address, &data1);
803 if (data1 != IPW_DATA_DOA_DEBUG_VALUE)
807 /* Domain 1 check - use arbitrary read/write compare */
808 for (address = 0; address < 5; address++) {
809 /* The memory area is not used now */
810 write_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x32,
812 write_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x36,
814 read_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x32,
816 read_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x36,
818 if (val1 == data1 && val2 == data2)
827 * Loop until the CARD_DISABLED bit is the same value as the
830 * TODO: See if it would be more efficient to do a wait/wake
831 * cycle and have the completion event trigger the wakeup
834 #define IPW_CARD_DISABLE_COMPLETE_WAIT 100 // 100 milli
835 static int ipw2100_wait_for_card_state(struct ipw2100_priv *priv, int state)
839 u32 len = sizeof(card_state);
842 for (i = 0; i <= IPW_CARD_DISABLE_COMPLETE_WAIT * 1000; i += 50) {
843 err = ipw2100_get_ordinal(priv, IPW_ORD_CARD_DISABLED,
846 IPW_DEBUG_INFO("Query of CARD_DISABLED ordinal "
851 /* We'll break out if either the HW state says it is
852 * in the state we want, or if HOST_COMPLETE command
854 if ((card_state == state) ||
855 ((priv->status & STATUS_ENABLED) ?
856 IPW_HW_STATE_ENABLED : IPW_HW_STATE_DISABLED) == state) {
857 if (state == IPW_HW_STATE_ENABLED)
858 priv->status |= STATUS_ENABLED;
860 priv->status &= ~STATUS_ENABLED;
868 IPW_DEBUG_INFO("ipw2100_wait_for_card_state to %s state timed out\n",
869 state ? "DISABLED" : "ENABLED");
874 /*********************************************************************
875 Procedure : sw_reset_and_clock
876 Purpose : Asserts s/w reset, asserts clock initialization
877 and waits for clock stabilization
878 ********************************************************************/
879 static int sw_reset_and_clock(struct ipw2100_priv *priv)
885 write_register(priv->net_dev, IPW_REG_RESET_REG,
886 IPW_AUX_HOST_RESET_REG_SW_RESET);
888 // wait for clock stabilization
889 for (i = 0; i < 1000; i++) {
890 udelay(IPW_WAIT_RESET_ARC_COMPLETE_DELAY);
892 // check clock ready bit
893 read_register(priv->net_dev, IPW_REG_RESET_REG, &r);
894 if (r & IPW_AUX_HOST_RESET_REG_PRINCETON_RESET)
899 return -EIO; // TODO: better error value
901 /* set "initialization complete" bit to move adapter to
903 write_register(priv->net_dev, IPW_REG_GP_CNTRL,
904 IPW_AUX_HOST_GP_CNTRL_BIT_INIT_DONE);
906 /* wait for clock stabilization */
907 for (i = 0; i < 10000; i++) {
908 udelay(IPW_WAIT_CLOCK_STABILIZATION_DELAY * 4);
910 /* check clock ready bit */
911 read_register(priv->net_dev, IPW_REG_GP_CNTRL, &r);
912 if (r & IPW_AUX_HOST_GP_CNTRL_BIT_CLOCK_READY)
917 return -EIO; /* TODO: better error value */
919 /* set D0 standby bit */
920 read_register(priv->net_dev, IPW_REG_GP_CNTRL, &r);
921 write_register(priv->net_dev, IPW_REG_GP_CNTRL,
922 r | IPW_AUX_HOST_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
927 /*********************************************************************
928 Procedure : ipw2100_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++;
2841 "%s: Driver is running slow (%d iters).\n",
2842 priv->net_dev->name, i);
2847 static void X__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 * X__ipw2100_tx_send_data
2918 static void X__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 X__ipw2100_tx_send_commands(priv);
3134 X__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 X__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, char *buf)
3385 struct pci_dev *pci_dev = container_of(d, struct pci_dev, dev);
3390 for (i = 0; i < 16; i++) {
3391 out += sprintf(out, "[%08X] ", i * 16);
3392 for (j = 0; j < 16; j += 4) {
3393 pci_read_config_dword(pci_dev, i * 16 + j, &val);
3394 out += sprintf(out, "%08X ", val);
3396 out += sprintf(out, "\n");
3401 static DEVICE_ATTR(pci, S_IRUGO, show_pci, NULL);
3403 static ssize_t show_cfg(struct device *d, char *buf)
3405 struct ipw2100_priv *p = (struct ipw2100_priv *)d->driver_data;
3406 return sprintf(buf, "0x%08x\n", (int)p->config);
3408 static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
3410 static ssize_t show_status(struct device *d, char *buf)
3412 struct ipw2100_priv *p = (struct ipw2100_priv *)d->driver_data;
3413 return sprintf(buf, "0x%08x\n", (int)p->status);
3415 static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
3417 static ssize_t show_capability(struct device *d, char *buf)
3419 struct ipw2100_priv *p = (struct ipw2100_priv *)d->driver_data;
3420 return sprintf(buf, "0x%08x\n", (int)p->capability);
3422 static DEVICE_ATTR(capability, S_IRUGO, show_capability, NULL);
3425 #define IPW2100_REG(x) { IPW_ ##x, #x }
3430 IPW2100_REG(REG_GP_CNTRL),
3431 IPW2100_REG(REG_GPIO),
3432 IPW2100_REG(REG_INTA),
3433 IPW2100_REG(REG_INTA_MASK),
3434 IPW2100_REG(REG_RESET_REG),
3436 #define IPW2100_NIC(x, s) { x, #x, s }
3442 IPW2100_NIC(IPW2100_CONTROL_REG, 2),
3443 IPW2100_NIC(0x210014, 1),
3444 IPW2100_NIC(0x210000, 1),
3446 #define IPW2100_ORD(x, d) { IPW_ORD_ ##x, #x, d }
3452 IPW2100_ORD(STAT_TX_HOST_REQUESTS, "requested Host Tx's (MSDU)"),
3453 IPW2100_ORD(STAT_TX_HOST_COMPLETE, "successful Host Tx's (MSDU)"),
3454 IPW2100_ORD(STAT_TX_DIR_DATA, "successful Directed Tx's (MSDU)"),
3455 IPW2100_ORD(STAT_TX_DIR_DATA1, "successful Directed Tx's (MSDU) @ 1MB"),
3456 IPW2100_ORD(STAT_TX_DIR_DATA2, "successful Directed Tx's (MSDU) @ 2MB"),
3457 IPW2100_ORD(STAT_TX_DIR_DATA5_5, "successful Directed Tx's (MSDU) @ 5_5MB"),
3458 IPW2100_ORD(STAT_TX_DIR_DATA11, "successful Directed Tx's (MSDU) @ 11MB"),
3459 IPW2100_ORD(STAT_TX_NODIR_DATA1, "successful Non_Directed Tx's (MSDU) @ 1MB"),
3460 IPW2100_ORD(STAT_TX_NODIR_DATA2, "successful Non_Directed Tx's (MSDU) @ 2MB"),
3461 IPW2100_ORD(STAT_TX_NODIR_DATA5_5, "successful Non_Directed Tx's (MSDU) @ 5.5MB"),
3462 IPW2100_ORD(STAT_TX_NODIR_DATA11, "successful Non_Directed Tx's (MSDU) @ 11MB"),
3463 IPW2100_ORD(STAT_NULL_DATA, "successful NULL data Tx's"),
3464 IPW2100_ORD(STAT_TX_RTS, "successful Tx RTS"),
3465 IPW2100_ORD(STAT_TX_CTS, "successful Tx CTS"),
3466 IPW2100_ORD(STAT_TX_ACK, "successful Tx ACK"),
3467 IPW2100_ORD(STAT_TX_ASSN, "successful Association Tx's"),
3468 IPW2100_ORD(STAT_TX_ASSN_RESP, "successful Association response Tx's"),
3469 IPW2100_ORD(STAT_TX_REASSN, "successful Reassociation Tx's"),
3470 IPW2100_ORD(STAT_TX_REASSN_RESP, "successful Reassociation response Tx's"),
3471 IPW2100_ORD(STAT_TX_PROBE, "probes successfully transmitted"),
3472 IPW2100_ORD(STAT_TX_PROBE_RESP, "probe responses successfully transmitted"),
3473 IPW2100_ORD(STAT_TX_BEACON, "tx beacon"),
3474 IPW2100_ORD(STAT_TX_ATIM, "Tx ATIM"),
3475 IPW2100_ORD(STAT_TX_DISASSN, "successful Disassociation TX"),
3476 IPW2100_ORD(STAT_TX_AUTH, "successful Authentication Tx"),
3477 IPW2100_ORD(STAT_TX_DEAUTH, "successful Deauthentication TX"),
3478 IPW2100_ORD(STAT_TX_TOTAL_BYTES, "Total successful Tx data bytes"),
3479 IPW2100_ORD(STAT_TX_RETRIES, "Tx retries"),
3480 IPW2100_ORD(STAT_TX_RETRY1, "Tx retries at 1MBPS"),
3481 IPW2100_ORD(STAT_TX_RETRY2, "Tx retries at 2MBPS"),
3482 IPW2100_ORD(STAT_TX_RETRY5_5, "Tx retries at 5.5MBPS"),
3483 IPW2100_ORD(STAT_TX_RETRY11, "Tx retries at 11MBPS"),
3484 IPW2100_ORD(STAT_TX_FAILURES, "Tx Failures"),
3485 IPW2100_ORD(STAT_TX_MAX_TRIES_IN_HOP,"times max tries in a hop failed"),
3486 IPW2100_ORD(STAT_TX_DISASSN_FAIL, "times disassociation failed"),
3487 IPW2100_ORD(STAT_TX_ERR_CTS, "missed/bad CTS frames"),
3488 IPW2100_ORD(STAT_TX_ERR_ACK, "tx err due to acks"),
3489 IPW2100_ORD(STAT_RX_HOST, "packets passed to host"),
3490 IPW2100_ORD(STAT_RX_DIR_DATA, "directed packets"),
3491 IPW2100_ORD(STAT_RX_DIR_DATA1, "directed packets at 1MB"),
3492 IPW2100_ORD(STAT_RX_DIR_DATA2, "directed packets at 2MB"),
3493 IPW2100_ORD(STAT_RX_DIR_DATA5_5, "directed packets at 5.5MB"),
3494 IPW2100_ORD(STAT_RX_DIR_DATA11, "directed packets at 11MB"),
3495 IPW2100_ORD(STAT_RX_NODIR_DATA,"nondirected packets"),
3496 IPW2100_ORD(STAT_RX_NODIR_DATA1, "nondirected packets at 1MB"),
3497 IPW2100_ORD(STAT_RX_NODIR_DATA2, "nondirected packets at 2MB"),
3498 IPW2100_ORD(STAT_RX_NODIR_DATA5_5, "nondirected packets at 5.5MB"),
3499 IPW2100_ORD(STAT_RX_NODIR_DATA11, "nondirected packets at 11MB"),
3500 IPW2100_ORD(STAT_RX_NULL_DATA, "null data rx's"),
3501 IPW2100_ORD(STAT_RX_RTS, "Rx RTS"),
3502 IPW2100_ORD(STAT_RX_CTS, "Rx CTS"),
3503 IPW2100_ORD(STAT_RX_ACK, "Rx ACK"),
3504 IPW2100_ORD(STAT_RX_CFEND, "Rx CF End"),
3505 IPW2100_ORD(STAT_RX_CFEND_ACK, "Rx CF End + CF Ack"),
3506 IPW2100_ORD(STAT_RX_ASSN, "Association Rx's"),
3507 IPW2100_ORD(STAT_RX_ASSN_RESP, "Association response Rx's"),
3508 IPW2100_ORD(STAT_RX_REASSN, "Reassociation Rx's"),
3509 IPW2100_ORD(STAT_RX_REASSN_RESP, "Reassociation response Rx's"),
3510 IPW2100_ORD(STAT_RX_PROBE, "probe Rx's"),
3511 IPW2100_ORD(STAT_RX_PROBE_RESP, "probe response Rx's"),
3512 IPW2100_ORD(STAT_RX_BEACON, "Rx beacon"),
3513 IPW2100_ORD(STAT_RX_ATIM, "Rx ATIM"),
3514 IPW2100_ORD(STAT_RX_DISASSN, "disassociation Rx"),
3515 IPW2100_ORD(STAT_RX_AUTH, "authentication Rx"),
3516 IPW2100_ORD(STAT_RX_DEAUTH, "deauthentication Rx"),
3517 IPW2100_ORD(STAT_RX_TOTAL_BYTES,"Total rx data bytes received"),
3518 IPW2100_ORD(STAT_RX_ERR_CRC, "packets with Rx CRC error"),
3519 IPW2100_ORD(STAT_RX_ERR_CRC1, "Rx CRC errors at 1MB"),
3520 IPW2100_ORD(STAT_RX_ERR_CRC2, "Rx CRC errors at 2MB"),
3521 IPW2100_ORD(STAT_RX_ERR_CRC5_5, "Rx CRC errors at 5.5MB"),
3522 IPW2100_ORD(STAT_RX_ERR_CRC11, "Rx CRC errors at 11MB"),
3523 IPW2100_ORD(STAT_RX_DUPLICATE1, "duplicate rx packets at 1MB"),
3524 IPW2100_ORD(STAT_RX_DUPLICATE2, "duplicate rx packets at 2MB"),
3525 IPW2100_ORD(STAT_RX_DUPLICATE5_5, "duplicate rx packets at 5.5MB"),
3526 IPW2100_ORD(STAT_RX_DUPLICATE11, "duplicate rx packets at 11MB"),
3527 IPW2100_ORD(STAT_RX_DUPLICATE, "duplicate rx packets"),
3528 IPW2100_ORD(PERS_DB_LOCK, "locking fw permanent db"),
3529 IPW2100_ORD(PERS_DB_SIZE, "size of fw permanent db"),
3530 IPW2100_ORD(PERS_DB_ADDR, "address of fw permanent db"),
3531 IPW2100_ORD(STAT_RX_INVALID_PROTOCOL, "rx frames with invalid protocol"),
3532 IPW2100_ORD(SYS_BOOT_TIME, "Boot time"),
3533 IPW2100_ORD(STAT_RX_NO_BUFFER, "rx frames rejected due to no buffer"),
3534 IPW2100_ORD(STAT_RX_MISSING_FRAG, "rx frames dropped due to missing fragment"),
3535 IPW2100_ORD(STAT_RX_ORPHAN_FRAG, "rx frames dropped due to non-sequential fragment"),
3536 IPW2100_ORD(STAT_RX_ORPHAN_FRAME, "rx frames dropped due to unmatched 1st frame"),
3537 IPW2100_ORD(STAT_RX_FRAG_AGEOUT, "rx frames dropped due to uncompleted frame"),
3538 IPW2100_ORD(STAT_RX_ICV_ERRORS, "ICV errors during decryption"),
3539 IPW2100_ORD(STAT_PSP_SUSPENSION,"times adapter suspended"),
3540 IPW2100_ORD(STAT_PSP_BCN_TIMEOUT, "beacon timeout"),
3541 IPW2100_ORD(STAT_PSP_POLL_TIMEOUT, "poll response timeouts"),
3542 IPW2100_ORD(STAT_PSP_NONDIR_TIMEOUT, "timeouts waiting for last {broad,multi}cast pkt"),
3543 IPW2100_ORD(STAT_PSP_RX_DTIMS, "PSP DTIMs received"),
3544 IPW2100_ORD(STAT_PSP_RX_TIMS, "PSP TIMs received"),
3545 IPW2100_ORD(STAT_PSP_STATION_ID,"PSP Station ID"),
3546 IPW2100_ORD(LAST_ASSN_TIME, "RTC time of last association"),
3547 IPW2100_ORD(STAT_PERCENT_MISSED_BCNS,"current calculation of % missed beacons"),
3548 IPW2100_ORD(STAT_PERCENT_RETRIES,"current calculation of % missed tx retries"),
3549 IPW2100_ORD(ASSOCIATED_AP_PTR, "0 if not associated, else pointer to AP table entry"),
3550 IPW2100_ORD(AVAILABLE_AP_CNT, "AP's decsribed in the AP table"),
3551 IPW2100_ORD(AP_LIST_PTR, "Ptr to list of available APs"),
3552 IPW2100_ORD(STAT_AP_ASSNS, "associations"),
3553 IPW2100_ORD(STAT_ASSN_FAIL, "association failures"),
3554 IPW2100_ORD(STAT_ASSN_RESP_FAIL,"failures due to response fail"),
3555 IPW2100_ORD(STAT_FULL_SCANS, "full scans"),
3556 IPW2100_ORD(CARD_DISABLED, "Card Disabled"),
3557 IPW2100_ORD(STAT_ROAM_INHIBIT, "times roaming was inhibited due to activity"),
3558 IPW2100_ORD(RSSI_AT_ASSN, "RSSI of associated AP at time of association"),
3559 IPW2100_ORD(STAT_ASSN_CAUSE1, "reassociation: no probe response or TX on hop"),
3560 IPW2100_ORD(STAT_ASSN_CAUSE2, "reassociation: poor tx/rx quality"),
3561 IPW2100_ORD(STAT_ASSN_CAUSE3, "reassociation: tx/rx quality (excessive AP load"),
3562 IPW2100_ORD(STAT_ASSN_CAUSE4, "reassociation: AP RSSI level"),
3563 IPW2100_ORD(STAT_ASSN_CAUSE5, "reassociations due to load leveling"),
3564 IPW2100_ORD(STAT_AUTH_FAIL, "times authentication failed"),
3565 IPW2100_ORD(STAT_AUTH_RESP_FAIL,"times authentication response failed"),
3566 IPW2100_ORD(STATION_TABLE_CNT, "entries in association table"),
3567 IPW2100_ORD(RSSI_AVG_CURR, "Current avg RSSI"),
3568 IPW2100_ORD(POWER_MGMT_MODE, "Power mode - 0=CAM, 1=PSP"),
3569 IPW2100_ORD(COUNTRY_CODE, "IEEE country code as recv'd from beacon"),
3570 IPW2100_ORD(COUNTRY_CHANNELS, "channels suported by country"),
3571 IPW2100_ORD(RESET_CNT, "adapter resets (warm)"),
3572 IPW2100_ORD(BEACON_INTERVAL, "Beacon interval"),
3573 IPW2100_ORD(ANTENNA_DIVERSITY, "TRUE if antenna diversity is disabled"),
3574 IPW2100_ORD(DTIM_PERIOD, "beacon intervals between DTIMs"),
3575 IPW2100_ORD(OUR_FREQ, "current radio freq lower digits - channel ID"),
3576 IPW2100_ORD(RTC_TIME, "current RTC time"),
3577 IPW2100_ORD(PORT_TYPE, "operating mode"),
3578 IPW2100_ORD(CURRENT_TX_RATE, "current tx rate"),
3579 IPW2100_ORD(SUPPORTED_RATES, "supported tx rates"),
3580 IPW2100_ORD(ATIM_WINDOW, "current ATIM Window"),
3581 IPW2100_ORD(BASIC_RATES, "basic tx rates"),
3582 IPW2100_ORD(NIC_HIGHEST_RATE, "NIC highest tx rate"),
3583 IPW2100_ORD(AP_HIGHEST_RATE, "AP highest tx rate"),
3584 IPW2100_ORD(CAPABILITIES, "Management frame capability field"),
3585 IPW2100_ORD(AUTH_TYPE, "Type of authentication"),
3586 IPW2100_ORD(RADIO_TYPE, "Adapter card platform type"),
3587 IPW2100_ORD(RTS_THRESHOLD, "Min packet length for RTS handshaking"),
3588 IPW2100_ORD(INT_MODE, "International mode"),
3589 IPW2100_ORD(FRAGMENTATION_THRESHOLD, "protocol frag threshold"),
3590 IPW2100_ORD(EEPROM_SRAM_DB_BLOCK_START_ADDRESS, "EEPROM offset in SRAM"),
3591 IPW2100_ORD(EEPROM_SRAM_DB_BLOCK_SIZE, "EEPROM size in SRAM"),
3592 IPW2100_ORD(EEPROM_SKU_CAPABILITY, "EEPROM SKU Capability"),
3593 IPW2100_ORD(EEPROM_IBSS_11B_CHANNELS, "EEPROM IBSS 11b channel set"),
3594 IPW2100_ORD(MAC_VERSION, "MAC Version"),
3595 IPW2100_ORD(MAC_REVISION, "MAC Revision"),
3596 IPW2100_ORD(RADIO_VERSION, "Radio Version"),
3597 IPW2100_ORD(NIC_MANF_DATE_TIME, "MANF Date/Time STAMP"),
3598 IPW2100_ORD(UCODE_VERSION, "Ucode Version"),
3602 static ssize_t show_registers(struct device *d, char *buf)
3605 struct ipw2100_priv *priv = dev_get_drvdata(d);
3606 struct net_device *dev = priv->net_dev;
3610 out += sprintf(out, "%30s [Address ] : Hex\n", "Register");
3612 for (i = 0; i < (sizeof(hw_data) / sizeof(*hw_data)); i++) {
3613 read_register(dev, hw_data[i].addr, &val);
3614 out += sprintf(out, "%30s [%08X] : %08X\n",
3615 hw_data[i].name, hw_data[i].addr, val);
3620 static DEVICE_ATTR(registers, S_IRUGO, show_registers, NULL);
3623 static ssize_t show_hardware(struct device *d, char *buf)
3625 struct ipw2100_priv *priv = dev_get_drvdata(d);
3626 struct net_device *dev = priv->net_dev;
3630 out += sprintf(out, "%30s [Address ] : Hex\n", "NIC entry");
3632 for (i = 0; i < (sizeof(nic_data) / sizeof(*nic_data)); i++) {
3637 switch (nic_data[i].size) {
3639 read_nic_byte(dev, nic_data[i].addr, &tmp8);
3640 out += sprintf(out, "%30s [%08X] : %02X\n",
3641 nic_data[i].name, nic_data[i].addr,
3645 read_nic_word(dev, nic_data[i].addr, &tmp16);
3646 out += sprintf(out, "%30s [%08X] : %04X\n",
3647 nic_data[i].name, nic_data[i].addr,
3651 read_nic_dword(dev, nic_data[i].addr, &tmp32);
3652 out += sprintf(out, "%30s [%08X] : %08X\n",
3653 nic_data[i].name, nic_data[i].addr,
3660 static DEVICE_ATTR(hardware, S_IRUGO, show_hardware, NULL);
3663 static ssize_t show_memory(struct device *d, char *buf)
3665 struct ipw2100_priv *priv = dev_get_drvdata(d);
3666 struct net_device *dev = priv->net_dev;
3667 static unsigned long loop = 0;
3673 if (loop >= 0x30000)
3676 /* sysfs provides us PAGE_SIZE buffer */
3677 while (len < PAGE_SIZE - 128 && loop < 0x30000) {
3679 if (priv->snapshot[0]) for (i = 0; i < 4; i++)
3680 buffer[i] = *(u32 *)SNAPSHOT_ADDR(loop + i * 4);
3681 else for (i = 0; i < 4; i++)
3682 read_nic_dword(dev, loop + i * 4, &buffer[i]);
3685 len += sprintf(buf + len,
3705 ((u8*)buffer)[0xf]);
3707 len += sprintf(buf + len, "%s\n",
3708 snprint_line(line, sizeof(line),
3709 (u8*)buffer, 16, loop));
3716 static ssize_t store_memory(struct device *d, const char *buf, size_t count)
3718 struct ipw2100_priv *priv = dev_get_drvdata(d);
3719 struct net_device *dev = priv->net_dev;
3720 const char *p = buf;
3726 (count >= 2 && tolower(p[0]) == 'o' && tolower(p[1]) == 'n')) {
3727 IPW_DEBUG_INFO("%s: Setting memory dump to RAW mode.\n",
3731 } else if (p[0] == '0' || (count >= 2 && tolower(p[0]) == 'o' &&
3732 tolower(p[1]) == 'f')) {
3733 IPW_DEBUG_INFO("%s: Setting memory dump to HEX mode.\n",
3737 } else if (tolower(p[0]) == 'r') {
3738 IPW_DEBUG_INFO("%s: Resetting firmware snapshot.\n",
3740 ipw2100_snapshot_free(priv);
3743 IPW_DEBUG_INFO("%s: Usage: 0|on = HEX, 1|off = RAW, "
3744 "reset = clear memory snapshot\n",
3749 static DEVICE_ATTR(memory, S_IWUSR|S_IRUGO, show_memory, store_memory);
3752 static ssize_t show_ordinals(struct device *d, char *buf)
3754 struct ipw2100_priv *priv = dev_get_drvdata(d);
3758 static int loop = 0;
3760 if (loop >= sizeof(ord_data) / sizeof(*ord_data))
3763 /* sysfs provides us PAGE_SIZE buffer */
3764 while (len < PAGE_SIZE - 128 &&
3765 loop < (sizeof(ord_data) / sizeof(*ord_data))) {
3767 val_len = sizeof(u32);
3769 if (ipw2100_get_ordinal(priv, ord_data[loop].index, &val,
3771 len += sprintf(buf + len, "[0x%02X] = ERROR %s\n",
3772 ord_data[loop].index,
3773 ord_data[loop].desc);
3775 len += sprintf(buf + len, "[0x%02X] = 0x%08X %s\n",
3776 ord_data[loop].index, val,
3777 ord_data[loop].desc);
3783 static DEVICE_ATTR(ordinals, S_IRUGO, show_ordinals, NULL);
3786 static ssize_t show_stats(struct device *d, char *buf)
3788 struct ipw2100_priv *priv = dev_get_drvdata(d);
3791 out += sprintf(out, "interrupts: %d {tx: %d, rx: %d, other: %d}\n",
3792 priv->interrupts, priv->tx_interrupts,
3793 priv->rx_interrupts, priv->inta_other);
3794 out += sprintf(out, "firmware resets: %d\n", priv->resets);
3795 out += sprintf(out, "firmware hangs: %d\n", priv->hangs);
3796 #ifdef CONFIG_IPW_DEBUG
3797 out += sprintf(out, "packet mismatch image: %s\n",
3798 priv->snapshot[0] ? "YES" : "NO");
3803 static DEVICE_ATTR(stats, S_IRUGO, show_stats, NULL);
3806 int ipw2100_switch_mode(struct ipw2100_priv *priv, u32 mode)
3810 if (mode == priv->ieee->iw_mode)
3813 err = ipw2100_disable_adapter(priv);
3815 IPW_DEBUG_ERROR("%s: Could not disable adapter %d\n",
3816 priv->net_dev->name, err);
3822 priv->net_dev->type = ARPHRD_ETHER;
3825 priv->net_dev->type = ARPHRD_ETHER;
3827 #ifdef CONFIG_IPW2100_MONITOR
3828 case IW_MODE_MONITOR:
3829 priv->last_mode = priv->ieee->iw_mode;
3830 priv->net_dev->type = ARPHRD_IEEE80211;
3832 #endif /* CONFIG_IPW2100_MONITOR */
3835 priv->ieee->iw_mode = mode;
3838 /* Indicate ipw2100_download_firmware download firmware
3839 * from disk instead of memory. */
3840 ipw2100_firmware.version = 0;
3843 printk(KERN_INFO "%s: Reseting on mode change.\n",
3844 priv->net_dev->name);
3845 priv->reset_backoff = 0;
3846 schedule_reset(priv);
3851 static ssize_t show_internals(struct device *d, char *buf)
3853 struct ipw2100_priv *priv = dev_get_drvdata(d);
3856 #define DUMP_VAR(x,y) len += sprintf(buf + len, # x ": %" # y "\n", priv-> x)
3858 if (priv->status & STATUS_ASSOCIATED)
3859 len += sprintf(buf + len, "connected: %lu\n",
3860 get_seconds() - priv->connect_start);
3862 len += sprintf(buf + len, "not connected\n");
3864 DUMP_VAR(ieee->crypt[priv->ieee->tx_keyidx], p);
3865 DUMP_VAR(status, 08lx);
3866 DUMP_VAR(config, 08lx);
3867 DUMP_VAR(capability, 08lx);
3869 len += sprintf(buf + len, "last_rtc: %lu\n", (unsigned long)priv->last_rtc);
3871 DUMP_VAR(fatal_error, d);
3872 DUMP_VAR(stop_hang_check, d);
3873 DUMP_VAR(stop_rf_kill, d);
3874 DUMP_VAR(messages_sent, d);
3876 DUMP_VAR(tx_pend_stat.value, d);
3877 DUMP_VAR(tx_pend_stat.hi, d);
3879 DUMP_VAR(tx_free_stat.value, d);
3880 DUMP_VAR(tx_free_stat.lo, d);
3882 DUMP_VAR(msg_free_stat.value, d);
3883 DUMP_VAR(msg_free_stat.lo, d);
3885 DUMP_VAR(msg_pend_stat.value, d);
3886 DUMP_VAR(msg_pend_stat.hi, d);
3888 DUMP_VAR(fw_pend_stat.value, d);
3889 DUMP_VAR(fw_pend_stat.hi, d);
3891 DUMP_VAR(txq_stat.value, d);
3892 DUMP_VAR(txq_stat.lo, d);
3894 DUMP_VAR(ieee->scans, d);
3895 DUMP_VAR(reset_backoff, d);
3899 static DEVICE_ATTR(internals, S_IRUGO, show_internals, NULL);
3902 static ssize_t show_bssinfo(struct device *d, char *buf)
3904 struct ipw2100_priv *priv = dev_get_drvdata(d);
3905 char essid[IW_ESSID_MAX_SIZE + 1];
3912 memset(essid, 0, sizeof(essid));
3913 memset(bssid, 0, sizeof(bssid));
3915 length = IW_ESSID_MAX_SIZE;
3916 ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_SSID, essid, &length);
3918 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
3921 length = sizeof(bssid);
3922 ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID,
3925 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
3928 length = sizeof(u32);
3929 ret = ipw2100_get_ordinal(priv, IPW_ORD_OUR_FREQ, &chan, &length);
3931 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
3934 out += sprintf(out, "ESSID: %s\n", essid);
3935 out += sprintf(out, "BSSID: %02x:%02x:%02x:%02x:%02x:%02x\n",
3936 bssid[0], bssid[1], bssid[2],
3937 bssid[3], bssid[4], bssid[5]);
3938 out += sprintf(out, "Channel: %d\n", chan);
3942 static DEVICE_ATTR(bssinfo, S_IRUGO, show_bssinfo, NULL);
3947 #ifdef CONFIG_IPW_DEBUG
3948 static ssize_t show_debug_level(struct device_driver *d, char *buf)
3950 return sprintf(buf, "0x%08X\n", ipw2100_debug_level);
3953 static ssize_t store_debug_level(struct device_driver *d, const char *buf,
3956 char *p = (char *)buf;
3959 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
3961 if (p[0] == 'x' || p[0] == 'X')
3963 val = simple_strtoul(p, &p, 16);
3965 val = simple_strtoul(p, &p, 10);
3967 IPW_DEBUG_INFO(DRV_NAME
3968 ": %s is not in hex or decimal form.\n", buf);
3970 ipw2100_debug_level = val;
3972 return strnlen(buf, count);
3974 static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, show_debug_level,
3976 #endif /* CONFIG_IPW_DEBUG */
3979 static ssize_t show_fatal_error(struct device *d, char *buf)
3981 struct ipw2100_priv *priv = dev_get_drvdata(d);
3985 if (priv->fatal_error)
3986 out += sprintf(out, "0x%08X\n",
3989 out += sprintf(out, "0\n");
3991 for (i = 1; i <= IPW2100_ERROR_QUEUE; i++) {
3992 if (!priv->fatal_errors[(priv->fatal_index - i) %
3993 IPW2100_ERROR_QUEUE])
3996 out += sprintf(out, "%d. 0x%08X\n", i,
3997 priv->fatal_errors[(priv->fatal_index - i) %
3998 IPW2100_ERROR_QUEUE]);
4004 static ssize_t store_fatal_error(struct device *d, const char *buf,
4007 struct ipw2100_priv *priv = dev_get_drvdata(d);
4008 schedule_reset(priv);
4011 static DEVICE_ATTR(fatal_error, S_IWUSR|S_IRUGO, show_fatal_error, store_fatal_error);
4014 static ssize_t show_scan_age(struct device *d, char *buf)
4016 struct ipw2100_priv *priv = dev_get_drvdata(d);
4017 return sprintf(buf, "%d\n", priv->ieee->scan_age);
4020 static ssize_t store_scan_age(struct device *d, const char *buf, size_t count)
4022 struct ipw2100_priv *priv = dev_get_drvdata(d);
4023 struct net_device *dev = priv->net_dev;
4024 char buffer[] = "00000000";
4026 (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
4030 IPW_DEBUG_INFO("enter\n");
4032 strncpy(buffer, buf, len);
4035 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
4037 if (p[0] == 'x' || p[0] == 'X')
4039 val = simple_strtoul(p, &p, 16);
4041 val = simple_strtoul(p, &p, 10);
4043 IPW_DEBUG_INFO("%s: user supplied invalid value.\n",
4046 priv->ieee->scan_age = val;
4047 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
4050 IPW_DEBUG_INFO("exit\n");
4053 static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
4056 static ssize_t show_rf_kill(struct device *d, char *buf)
4058 /* 0 - RF kill not enabled
4059 1 - SW based RF kill active (sysfs)
4060 2 - HW based RF kill active
4061 3 - Both HW and SW baed RF kill active */
4062 struct ipw2100_priv *priv = (struct ipw2100_priv *)d->driver_data;
4063 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
4064 (rf_kill_active(priv) ? 0x2 : 0x0);
4065 return sprintf(buf, "%i\n", val);
4068 static int ipw_radio_kill_sw(struct ipw2100_priv *priv, int disable_radio)
4070 if ((disable_radio ? 1 : 0) ==
4071 (priv->status & STATUS_RF_KILL_SW ? 1 : 0))
4074 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
4075 disable_radio ? "OFF" : "ON");
4077 down(&priv->action_sem);
4079 if (disable_radio) {
4080 priv->status |= STATUS_RF_KILL_SW;
4083 priv->status &= ~STATUS_RF_KILL_SW;
4084 if (rf_kill_active(priv)) {
4085 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
4086 "disabled by HW switch\n");
4087 /* Make sure the RF_KILL check timer is running */
4088 priv->stop_rf_kill = 0;
4089 cancel_delayed_work(&priv->rf_kill);
4090 queue_delayed_work(priv->workqueue, &priv->rf_kill,
4093 schedule_reset(priv);
4096 up(&priv->action_sem);
4100 static ssize_t store_rf_kill(struct device *d, const char *buf, size_t count)
4102 struct ipw2100_priv *priv = dev_get_drvdata(d);
4103 ipw_radio_kill_sw(priv, buf[0] == '1');
4106 static DEVICE_ATTR(rf_kill, S_IWUSR|S_IRUGO, show_rf_kill, store_rf_kill);
4109 static struct attribute *ipw2100_sysfs_entries[] = {
4110 &dev_attr_hardware.attr,
4111 &dev_attr_registers.attr,
4112 &dev_attr_ordinals.attr,
4114 &dev_attr_stats.attr,
4115 &dev_attr_internals.attr,
4116 &dev_attr_bssinfo.attr,
4117 &dev_attr_memory.attr,
4118 &dev_attr_scan_age.attr,
4119 &dev_attr_fatal_error.attr,
4120 &dev_attr_rf_kill.attr,
4122 &dev_attr_status.attr,
4123 &dev_attr_capability.attr,
4127 static struct attribute_group ipw2100_attribute_group = {
4128 .attrs = ipw2100_sysfs_entries,
4132 static int status_queue_allocate(struct ipw2100_priv *priv, int entries)
4134 struct ipw2100_status_queue *q = &priv->status_queue;
4136 IPW_DEBUG_INFO("enter\n");
4138 q->size = entries * sizeof(struct ipw2100_status);
4139 q->drv = (struct ipw2100_status *)pci_alloc_consistent(
4140 priv->pci_dev, q->size, &q->nic);
4143 "Can not allocate status queue.\n");
4147 memset(q->drv, 0, q->size);
4149 IPW_DEBUG_INFO("exit\n");
4154 static void status_queue_free(struct ipw2100_priv *priv)
4156 IPW_DEBUG_INFO("enter\n");
4158 if (priv->status_queue.drv) {
4159 pci_free_consistent(
4160 priv->pci_dev, priv->status_queue.size,
4161 priv->status_queue.drv, priv->status_queue.nic);
4162 priv->status_queue.drv = NULL;
4165 IPW_DEBUG_INFO("exit\n");
4168 static int bd_queue_allocate(struct ipw2100_priv *priv,
4169 struct ipw2100_bd_queue *q, int entries)
4171 IPW_DEBUG_INFO("enter\n");
4173 memset(q, 0, sizeof(struct ipw2100_bd_queue));
4175 q->entries = entries;
4176 q->size = entries * sizeof(struct ipw2100_bd);
4177 q->drv = pci_alloc_consistent(priv->pci_dev, q->size, &q->nic);
4179 IPW_DEBUG_INFO("can't allocate shared memory for buffer descriptors\n");
4182 memset(q->drv, 0, q->size);
4184 IPW_DEBUG_INFO("exit\n");
4189 static void bd_queue_free(struct ipw2100_priv *priv,
4190 struct ipw2100_bd_queue *q)
4192 IPW_DEBUG_INFO("enter\n");
4198 pci_free_consistent(priv->pci_dev,
4199 q->size, q->drv, q->nic);
4203 IPW_DEBUG_INFO("exit\n");
4206 static void bd_queue_initialize(
4207 struct ipw2100_priv *priv, struct ipw2100_bd_queue * q,
4208 u32 base, u32 size, u32 r, u32 w)
4210 IPW_DEBUG_INFO("enter\n");
4212 IPW_DEBUG_INFO("initializing bd queue at virt=%p, phys=%08x\n", q->drv, (u32)q->nic);
4214 write_register(priv->net_dev, base, q->nic);
4215 write_register(priv->net_dev, size, q->entries);
4216 write_register(priv->net_dev, r, q->oldest);
4217 write_register(priv->net_dev, w, q->next);
4219 IPW_DEBUG_INFO("exit\n");
4222 static void ipw2100_kill_workqueue(struct ipw2100_priv *priv)
4224 if (priv->workqueue) {
4225 priv->stop_rf_kill = 1;
4226 priv->stop_hang_check = 1;
4227 cancel_delayed_work(&priv->reset_work);
4228 cancel_delayed_work(&priv->security_work);
4229 cancel_delayed_work(&priv->wx_event_work);
4230 cancel_delayed_work(&priv->hang_check);
4231 cancel_delayed_work(&priv->rf_kill);
4232 destroy_workqueue(priv->workqueue);
4233 priv->workqueue = NULL;
4237 static int ipw2100_tx_allocate(struct ipw2100_priv *priv)
4239 int i, j, err = -EINVAL;
4243 IPW_DEBUG_INFO("enter\n");
4245 err = bd_queue_allocate(priv, &priv->tx_queue, TX_QUEUE_LENGTH);
4247 IPW_DEBUG_ERROR("%s: failed bd_queue_allocate\n",
4248 priv->net_dev->name);
4252 priv->tx_buffers = (struct ipw2100_tx_packet *)kmalloc(
4253 TX_PENDED_QUEUE_LENGTH * sizeof(struct ipw2100_tx_packet),
4255 if (!priv->tx_buffers) {
4256 IPW_DEBUG_ERROR("%s: alloc failed form tx buffers.\n",
4257 priv->net_dev->name);
4258 bd_queue_free(priv, &priv->tx_queue);
4262 for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
4263 v = pci_alloc_consistent(
4264 priv->pci_dev, sizeof(struct ipw2100_data_header), &p);
4266 IPW_DEBUG_ERROR("%s: PCI alloc failed for tx "
4267 "buffers.\n", priv->net_dev->name);
4272 priv->tx_buffers[i].type = DATA;
4273 priv->tx_buffers[i].info.d_struct.data = (struct ipw2100_data_header*)v;
4274 priv->tx_buffers[i].info.d_struct.data_phys = p;
4275 priv->tx_buffers[i].info.d_struct.txb = NULL;
4278 if (i == TX_PENDED_QUEUE_LENGTH)
4281 for (j = 0; j < i; j++) {
4282 pci_free_consistent(
4284 sizeof(struct ipw2100_data_header),
4285 priv->tx_buffers[j].info.d_struct.data,
4286 priv->tx_buffers[j].info.d_struct.data_phys);
4289 kfree(priv->tx_buffers);
4290 priv->tx_buffers = NULL;
4295 static void ipw2100_tx_initialize(struct ipw2100_priv *priv)
4299 IPW_DEBUG_INFO("enter\n");
4302 * reinitialize packet info lists
4304 INIT_LIST_HEAD(&priv->fw_pend_list);
4305 INIT_STAT(&priv->fw_pend_stat);
4308 * reinitialize lists
4310 INIT_LIST_HEAD(&priv->tx_pend_list);
4311 INIT_LIST_HEAD(&priv->tx_free_list);
4312 INIT_STAT(&priv->tx_pend_stat);
4313 INIT_STAT(&priv->tx_free_stat);
4315 for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
4316 /* We simply drop any SKBs that have been queued for
4318 if (priv->tx_buffers[i].info.d_struct.txb) {
4319 ieee80211_txb_free(priv->tx_buffers[i].info.d_struct.txb);
4320 priv->tx_buffers[i].info.d_struct.txb = NULL;
4323 list_add_tail(&priv->tx_buffers[i].list, &priv->tx_free_list);
4326 SET_STAT(&priv->tx_free_stat, i);
4328 priv->tx_queue.oldest = 0;
4329 priv->tx_queue.available = priv->tx_queue.entries;
4330 priv->tx_queue.next = 0;
4331 INIT_STAT(&priv->txq_stat);
4332 SET_STAT(&priv->txq_stat, priv->tx_queue.available);
4334 bd_queue_initialize(priv, &priv->tx_queue,
4335 IPW_MEM_HOST_SHARED_TX_QUEUE_BD_BASE,
4336 IPW_MEM_HOST_SHARED_TX_QUEUE_BD_SIZE,
4337 IPW_MEM_HOST_SHARED_TX_QUEUE_READ_INDEX,
4338 IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX);
4340 IPW_DEBUG_INFO("exit\n");
4344 static void ipw2100_tx_free(struct ipw2100_priv *priv)
4348 IPW_DEBUG_INFO("enter\n");
4350 bd_queue_free(priv, &priv->tx_queue);
4352 if (!priv->tx_buffers)
4355 for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
4356 if (priv->tx_buffers[i].info.d_struct.txb) {
4357 ieee80211_txb_free(priv->tx_buffers[i].info.d_struct.txb);
4358 priv->tx_buffers[i].info.d_struct.txb = NULL;
4360 if (priv->tx_buffers[i].info.d_struct.data)
4361 pci_free_consistent(
4363 sizeof(struct ipw2100_data_header),
4364 priv->tx_buffers[i].info.d_struct.data,
4365 priv->tx_buffers[i].info.d_struct.data_phys);
4368 kfree(priv->tx_buffers);
4369 priv->tx_buffers = NULL;
4371 IPW_DEBUG_INFO("exit\n");
4376 static int ipw2100_rx_allocate(struct ipw2100_priv *priv)
4378 int i, j, err = -EINVAL;
4380 IPW_DEBUG_INFO("enter\n");
4382 err = bd_queue_allocate(priv, &priv->rx_queue, RX_QUEUE_LENGTH);
4384 IPW_DEBUG_INFO("failed bd_queue_allocate\n");
4388 err = status_queue_allocate(priv, RX_QUEUE_LENGTH);
4390 IPW_DEBUG_INFO("failed status_queue_allocate\n");
4391 bd_queue_free(priv, &priv->rx_queue);
4398 priv->rx_buffers = (struct ipw2100_rx_packet *)
4399 kmalloc(RX_QUEUE_LENGTH * sizeof(struct ipw2100_rx_packet),
4401 if (!priv->rx_buffers) {
4402 IPW_DEBUG_INFO("can't allocate rx packet buffer table\n");
4404 bd_queue_free(priv, &priv->rx_queue);
4406 status_queue_free(priv);
4411 for (i = 0; i < RX_QUEUE_LENGTH; i++) {
4412 struct ipw2100_rx_packet *packet = &priv->rx_buffers[i];
4414 err = ipw2100_alloc_skb(priv, packet);
4415 if (unlikely(err)) {
4420 /* The BD holds the cache aligned address */
4421 priv->rx_queue.drv[i].host_addr = packet->dma_addr;
4422 priv->rx_queue.drv[i].buf_length = IPW_RX_NIC_BUFFER_LENGTH;
4423 priv->status_queue.drv[i].status_fields = 0;
4426 if (i == RX_QUEUE_LENGTH)
4429 for (j = 0; j < i; j++) {
4430 pci_unmap_single(priv->pci_dev, priv->rx_buffers[j].dma_addr,
4431 sizeof(struct ipw2100_rx_packet),
4432 PCI_DMA_FROMDEVICE);
4433 dev_kfree_skb(priv->rx_buffers[j].skb);
4436 kfree(priv->rx_buffers);
4437 priv->rx_buffers = NULL;
4439 bd_queue_free(priv, &priv->rx_queue);
4441 status_queue_free(priv);
4446 static void ipw2100_rx_initialize(struct ipw2100_priv *priv)
4448 IPW_DEBUG_INFO("enter\n");
4450 priv->rx_queue.oldest = 0;
4451 priv->rx_queue.available = priv->rx_queue.entries - 1;
4452 priv->rx_queue.next = priv->rx_queue.entries - 1;
4454 INIT_STAT(&priv->rxq_stat);
4455 SET_STAT(&priv->rxq_stat, priv->rx_queue.available);
4457 bd_queue_initialize(priv, &priv->rx_queue,
4458 IPW_MEM_HOST_SHARED_RX_BD_BASE,
4459 IPW_MEM_HOST_SHARED_RX_BD_SIZE,
4460 IPW_MEM_HOST_SHARED_RX_READ_INDEX,
4461 IPW_MEM_HOST_SHARED_RX_WRITE_INDEX);
4463 /* set up the status queue */
4464 write_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_STATUS_BASE,
4465 priv->status_queue.nic);
4467 IPW_DEBUG_INFO("exit\n");
4470 static void ipw2100_rx_free(struct ipw2100_priv *priv)
4474 IPW_DEBUG_INFO("enter\n");
4476 bd_queue_free(priv, &priv->rx_queue);
4477 status_queue_free(priv);
4479 if (!priv->rx_buffers)
4482 for (i = 0; i < RX_QUEUE_LENGTH; i++) {
4483 if (priv->rx_buffers[i].rxp) {
4484 pci_unmap_single(priv->pci_dev,
4485 priv->rx_buffers[i].dma_addr,
4486 sizeof(struct ipw2100_rx),
4487 PCI_DMA_FROMDEVICE);
4488 dev_kfree_skb(priv->rx_buffers[i].skb);
4492 kfree(priv->rx_buffers);
4493 priv->rx_buffers = NULL;
4495 IPW_DEBUG_INFO("exit\n");
4498 static int ipw2100_read_mac_address(struct ipw2100_priv *priv)
4500 u32 length = ETH_ALEN;
4505 err = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ADAPTER_MAC,
4508 IPW_DEBUG_INFO("MAC address read failed\n");
4511 IPW_DEBUG_INFO("card MAC is %02X:%02X:%02X:%02X:%02X:%02X\n",
4512 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
4514 memcpy(priv->net_dev->dev_addr, mac, ETH_ALEN);
4519 /********************************************************************
4523 ********************************************************************/
4525 int ipw2100_set_mac_address(struct ipw2100_priv *priv, int batch_mode)
4527 struct host_command cmd = {
4528 .host_command = ADAPTER_ADDRESS,
4529 .host_command_sequence = 0,
4530 .host_command_length = ETH_ALEN
4534 IPW_DEBUG_HC("SET_MAC_ADDRESS\n");
4536 IPW_DEBUG_INFO("enter\n");
4538 if (priv->config & CFG_CUSTOM_MAC) {
4539 memcpy(cmd.host_command_parameters, priv->mac_addr,
4541 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
4543 memcpy(cmd.host_command_parameters, priv->net_dev->dev_addr,
4546 err = ipw2100_hw_send_command(priv, &cmd);
4548 IPW_DEBUG_INFO("exit\n");
4552 int ipw2100_set_port_type(struct ipw2100_priv *priv, u32 port_type,
4555 struct host_command cmd = {
4556 .host_command = PORT_TYPE,
4557 .host_command_sequence = 0,
4558 .host_command_length = sizeof(u32)
4562 switch (port_type) {
4564 cmd.host_command_parameters[0] = IPW_BSS;
4567 cmd.host_command_parameters[0] = IPW_IBSS;
4571 IPW_DEBUG_HC("PORT_TYPE: %s\n",
4572 port_type == IPW_IBSS ? "Ad-Hoc" : "Managed");
4575 err = ipw2100_disable_adapter(priv);
4577 IPW_DEBUG_ERROR("%s: Could not disable adapter %d\n",
4578 priv->net_dev->name, err);
4583 /* send cmd to firmware */
4584 err = ipw2100_hw_send_command(priv, &cmd);
4587 ipw2100_enable_adapter(priv);
4593 int ipw2100_set_channel(struct ipw2100_priv *priv, u32 channel, int batch_mode)
4595 struct host_command cmd = {
4596 .host_command = CHANNEL,
4597 .host_command_sequence = 0,
4598 .host_command_length = sizeof(u32)
4602 cmd.host_command_parameters[0] = channel;
4604 IPW_DEBUG_HC("CHANNEL: %d\n", channel);
4606 /* If BSS then we don't support channel selection */
4607 if (priv->ieee->iw_mode == IW_MODE_INFRA)
4610 if ((channel != 0) &&
4611 ((channel < REG_MIN_CHANNEL) || (channel > REG_MAX_CHANNEL)))
4615 err = ipw2100_disable_adapter(priv);
4620 err = ipw2100_hw_send_command(priv, &cmd);
4622 IPW_DEBUG_INFO("Failed to set channel to %d",
4628 priv->config |= CFG_STATIC_CHANNEL;
4630 priv->config &= ~CFG_STATIC_CHANNEL;
4632 priv->channel = channel;
4635 err = ipw2100_enable_adapter(priv);
4643 int ipw2100_system_config(struct ipw2100_priv *priv, int batch_mode)
4645 struct host_command cmd = {
4646 .host_command = SYSTEM_CONFIG,
4647 .host_command_sequence = 0,
4648 .host_command_length = 12,
4650 u32 ibss_mask, len = sizeof(u32);
4653 /* Set system configuration */
4656 err = ipw2100_disable_adapter(priv);
4661 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
4662 cmd.host_command_parameters[0] |= IPW_CFG_IBSS_AUTO_START;
4664 cmd.host_command_parameters[0] |= IPW_CFG_IBSS_MASK |
4666 IPW_CFG_802_1x_ENABLE;
4668 if (!(priv->config & CFG_LONG_PREAMBLE))
4669 cmd.host_command_parameters[0] |= IPW_CFG_PREAMBLE_AUTO;
4671 err = ipw2100_get_ordinal(priv,
4672 IPW_ORD_EEPROM_IBSS_11B_CHANNELS,
4675 ibss_mask = IPW_IBSS_11B_DEFAULT_MASK;
4677 cmd.host_command_parameters[1] = REG_CHANNEL_MASK;
4678 cmd.host_command_parameters[2] = REG_CHANNEL_MASK & ibss_mask;
4681 /*cmd.host_command_parameters[0] |= DIVERSITY_ANTENNA_A;*/
4683 err = ipw2100_hw_send_command(priv, &cmd);
4687 /* If IPv6 is configured in the kernel then we don't want to filter out all
4688 * of the multicast packets as IPv6 needs some. */
4689 #if !defined(CONFIG_IPV6) && !defined(CONFIG_IPV6_MODULE)
4690 cmd.host_command = ADD_MULTICAST;
4691 cmd.host_command_sequence = 0;
4692 cmd.host_command_length = 0;
4694 ipw2100_hw_send_command(priv, &cmd);
4697 err = ipw2100_enable_adapter(priv);
4705 int ipw2100_set_tx_rates(struct ipw2100_priv *priv, u32 rate, int batch_mode)
4707 struct host_command cmd = {
4708 .host_command = BASIC_TX_RATES,
4709 .host_command_sequence = 0,
4710 .host_command_length = 4
4714 cmd.host_command_parameters[0] = rate & TX_RATE_MASK;
4717 err = ipw2100_disable_adapter(priv);
4722 /* Set BASIC TX Rate first */
4723 ipw2100_hw_send_command(priv, &cmd);
4726 cmd.host_command = TX_RATES;
4727 ipw2100_hw_send_command(priv, &cmd);
4729 /* Set MSDU TX Rate */
4730 cmd.host_command = MSDU_TX_RATES;
4731 ipw2100_hw_send_command(priv, &cmd);
4734 err = ipw2100_enable_adapter(priv);
4739 priv->tx_rates = rate;
4744 int ipw2100_set_power_mode(struct ipw2100_priv *priv,
4747 struct host_command cmd = {
4748 .host_command = POWER_MODE,
4749 .host_command_sequence = 0,
4750 .host_command_length = 4
4754 cmd.host_command_parameters[0] = power_level;
4756 err = ipw2100_hw_send_command(priv, &cmd);
4760 if (power_level == IPW_POWER_MODE_CAM)
4761 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
4763 priv->power_mode = IPW_POWER_ENABLED | power_level;
4765 #ifdef CONFIG_IPW2100_TX_POWER
4766 if (priv->port_type == IBSS &&
4767 priv->adhoc_power != DFTL_IBSS_TX_POWER) {
4768 /* Set beacon interval */
4769 cmd.host_command = TX_POWER_INDEX;
4770 cmd.host_command_parameters[0] = (u32)priv->adhoc_power;
4772 err = ipw2100_hw_send_command(priv, &cmd);
4782 int ipw2100_set_rts_threshold(struct ipw2100_priv *priv, u32 threshold)
4784 struct host_command cmd = {
4785 .host_command = RTS_THRESHOLD,
4786 .host_command_sequence = 0,
4787 .host_command_length = 4
4791 if (threshold & RTS_DISABLED)
4792 cmd.host_command_parameters[0] = MAX_RTS_THRESHOLD;
4794 cmd.host_command_parameters[0] = threshold & ~RTS_DISABLED;
4796 err = ipw2100_hw_send_command(priv, &cmd);
4800 priv->rts_threshold = threshold;
4806 int ipw2100_set_fragmentation_threshold(struct ipw2100_priv *priv,
4807 u32 threshold, int batch_mode)
4809 struct host_command cmd = {
4810 .host_command = FRAG_THRESHOLD,
4811 .host_command_sequence = 0,
4812 .host_command_length = 4,
4813 .host_command_parameters[0] = 0,
4818 err = ipw2100_disable_adapter(priv);
4824 threshold = DEFAULT_FRAG_THRESHOLD;
4826 threshold = max(threshold, MIN_FRAG_THRESHOLD);
4827 threshold = min(threshold, MAX_FRAG_THRESHOLD);
4830 cmd.host_command_parameters[0] = threshold;
4832 IPW_DEBUG_HC("FRAG_THRESHOLD: %u\n", threshold);
4834 err = ipw2100_hw_send_command(priv, &cmd);
4837 ipw2100_enable_adapter(priv);
4840 priv->frag_threshold = threshold;
4846 int ipw2100_set_short_retry(struct ipw2100_priv *priv, u32 retry)
4848 struct host_command cmd = {
4849 .host_command = SHORT_RETRY_LIMIT,
4850 .host_command_sequence = 0,
4851 .host_command_length = 4
4855 cmd.host_command_parameters[0] = retry;
4857 err = ipw2100_hw_send_command(priv, &cmd);
4861 priv->short_retry_limit = retry;
4866 int ipw2100_set_long_retry(struct ipw2100_priv *priv, u32 retry)
4868 struct host_command cmd = {
4869 .host_command = LONG_RETRY_LIMIT,
4870 .host_command_sequence = 0,
4871 .host_command_length = 4
4875 cmd.host_command_parameters[0] = retry;
4877 err = ipw2100_hw_send_command(priv, &cmd);
4881 priv->long_retry_limit = retry;
4887 int ipw2100_set_mandatory_bssid(struct ipw2100_priv *priv, u8 *bssid,
4890 struct host_command cmd = {
4891 .host_command = MANDATORY_BSSID,
4892 .host_command_sequence = 0,
4893 .host_command_length = (bssid == NULL) ? 0 : ETH_ALEN
4897 #ifdef CONFIG_IPW_DEBUG
4900 "MANDATORY_BSSID: %02X:%02X:%02X:%02X:%02X:%02X\n",
4901 bssid[0], bssid[1], bssid[2], bssid[3], bssid[4],
4904 IPW_DEBUG_HC("MANDATORY_BSSID: <clear>\n");
4906 /* if BSSID is empty then we disable mandatory bssid mode */
4908 memcpy((u8 *)cmd.host_command_parameters, bssid, ETH_ALEN);
4911 err = ipw2100_disable_adapter(priv);
4916 err = ipw2100_hw_send_command(priv, &cmd);
4919 ipw2100_enable_adapter(priv);
4924 #ifdef CONFIG_IEEE80211_WPA
4925 static int ipw2100_disassociate_bssid(struct ipw2100_priv *priv)
4927 struct host_command cmd = {
4928 .host_command = DISASSOCIATION_BSSID,
4929 .host_command_sequence = 0,
4930 .host_command_length = ETH_ALEN
4935 IPW_DEBUG_HC("DISASSOCIATION_BSSID\n");
4938 /* The Firmware currently ignores the BSSID and just disassociates from
4939 * the currently associated AP -- but in the off chance that a future
4940 * firmware does use the BSSID provided here, we go ahead and try and
4941 * set it to the currently associated AP's BSSID */
4942 memcpy(cmd.host_command_parameters, priv->bssid, ETH_ALEN);
4944 err = ipw2100_hw_send_command(priv, &cmd);
4951 * Pseudo code for setting up wpa_frame:
4954 void x(struct ieee80211_assoc_frame *wpa_assoc)
4956 struct ipw2100_wpa_assoc_frame frame;
4957 frame->fixed_ie_mask = IPW_WPA_CAPABILTIES |
4958 IPW_WPA_LISTENINTERVAL |
4960 frame->capab_info = wpa_assoc->capab_info;
4961 frame->lisen_interval = wpa_assoc->listent_interval;
4962 memcpy(frame->current_ap, wpa_assoc->current_ap, ETH_ALEN);
4964 /* UNKNOWN -- I'm not postivive about this part; don't have any WPA
4965 * setup here to test it with.
4967 * Walk the IEs in the wpa_assoc and figure out the total size of all
4968 * that data. Stick that into frame->var_ie_len. Then memcpy() all of
4969 * the IEs from wpa_frame into frame.
4971 frame->var_ie_len = calculate_ie_len(wpa_assoc);
4972 memcpy(frame->var_ie, wpa_assoc->variable, frame->var_ie_len);
4974 ipw2100_set_wpa_ie(priv, &frame, 0);
4981 static int ipw2100_set_wpa_ie(struct ipw2100_priv *,
4982 struct ipw2100_wpa_assoc_frame *, int)
4983 __attribute__ ((unused));
4985 static int ipw2100_set_wpa_ie(struct ipw2100_priv *priv,
4986 struct ipw2100_wpa_assoc_frame *wpa_frame,
4989 struct host_command cmd = {
4990 .host_command = SET_WPA_IE,
4991 .host_command_sequence = 0,
4992 .host_command_length = sizeof(struct ipw2100_wpa_assoc_frame),
4996 IPW_DEBUG_HC("SET_WPA_IE\n");
4999 err = ipw2100_disable_adapter(priv);
5004 memcpy(cmd.host_command_parameters, wpa_frame,
5005 sizeof(struct ipw2100_wpa_assoc_frame));
5007 err = ipw2100_hw_send_command(priv, &cmd);
5010 if (ipw2100_enable_adapter(priv))
5017 struct security_info_params {
5018 u32 allowed_ciphers;
5021 u8 replay_counters_number;
5022 u8 unicast_using_group;
5023 } __attribute__ ((packed));
5025 int ipw2100_set_security_information(struct ipw2100_priv *priv,
5028 int unicast_using_group,
5031 struct host_command cmd = {
5032 .host_command = SET_SECURITY_INFORMATION,
5033 .host_command_sequence = 0,
5034 .host_command_length = sizeof(struct security_info_params)
5036 struct security_info_params *security =
5037 (struct security_info_params *)&cmd.host_command_parameters;
5039 memset(security, 0, sizeof(*security));
5041 /* If shared key AP authentication is turned on, then we need to
5042 * configure the firmware to try and use it.
5044 * Actual data encryption/decryption is handled by the host. */
5045 security->auth_mode = auth_mode;
5046 security->unicast_using_group = unicast_using_group;
5048 switch (security_level) {
5051 security->allowed_ciphers = IPW_NONE_CIPHER;
5054 security->allowed_ciphers = IPW_WEP40_CIPHER |
5058 security->allowed_ciphers = IPW_WEP40_CIPHER |
5059 IPW_WEP104_CIPHER | IPW_TKIP_CIPHER;
5061 case SEC_LEVEL_2_CKIP:
5062 security->allowed_ciphers = IPW_WEP40_CIPHER |
5063 IPW_WEP104_CIPHER | IPW_CKIP_CIPHER;
5066 security->allowed_ciphers = IPW_WEP40_CIPHER |
5067 IPW_WEP104_CIPHER | IPW_TKIP_CIPHER | IPW_CCMP_CIPHER;
5072 "SET_SECURITY_INFORMATION: auth:%d cipher:0x%02X (level %d)\n",
5073 security->auth_mode, security->allowed_ciphers, security_level);
5075 security->replay_counters_number = 0;
5078 err = ipw2100_disable_adapter(priv);
5083 err = ipw2100_hw_send_command(priv, &cmd);
5086 ipw2100_enable_adapter(priv);
5091 int ipw2100_set_tx_power(struct ipw2100_priv *priv,
5094 struct host_command cmd = {
5095 .host_command = TX_POWER_INDEX,
5096 .host_command_sequence = 0,
5097 .host_command_length = 4
5101 cmd.host_command_parameters[0] = tx_power;
5103 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
5104 err = ipw2100_hw_send_command(priv, &cmd);
5106 priv->tx_power = tx_power;
5111 int ipw2100_set_ibss_beacon_interval(struct ipw2100_priv *priv,
5112 u32 interval, int batch_mode)
5114 struct host_command cmd = {
5115 .host_command = BEACON_INTERVAL,
5116 .host_command_sequence = 0,
5117 .host_command_length = 4
5121 cmd.host_command_parameters[0] = interval;
5123 IPW_DEBUG_INFO("enter\n");
5125 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
5127 err = ipw2100_disable_adapter(priv);
5132 ipw2100_hw_send_command(priv, &cmd);
5135 err = ipw2100_enable_adapter(priv);
5141 IPW_DEBUG_INFO("exit\n");
5147 void ipw2100_queues_initialize(struct ipw2100_priv *priv)
5149 ipw2100_tx_initialize(priv);
5150 ipw2100_rx_initialize(priv);
5151 ipw2100_msg_initialize(priv);
5154 void ipw2100_queues_free(struct ipw2100_priv *priv)
5156 ipw2100_tx_free(priv);
5157 ipw2100_rx_free(priv);
5158 ipw2100_msg_free(priv);
5161 int ipw2100_queues_allocate(struct ipw2100_priv *priv)
5163 if (ipw2100_tx_allocate(priv) ||
5164 ipw2100_rx_allocate(priv) ||
5165 ipw2100_msg_allocate(priv))
5171 ipw2100_tx_free(priv);
5172 ipw2100_rx_free(priv);
5173 ipw2100_msg_free(priv);
5177 #define IPW_PRIVACY_CAPABLE 0x0008
5179 static int ipw2100_set_wep_flags(struct ipw2100_priv *priv, u32 flags,
5182 struct host_command cmd = {
5183 .host_command = WEP_FLAGS,
5184 .host_command_sequence = 0,
5185 .host_command_length = 4
5189 cmd.host_command_parameters[0] = flags;
5191 IPW_DEBUG_HC("WEP_FLAGS: flags = 0x%08X\n", flags);
5194 err = ipw2100_disable_adapter(priv);
5196 IPW_DEBUG_ERROR("%s: Could not disable adapter %d\n",
5197 priv->net_dev->name, err);
5202 /* send cmd to firmware */
5203 err = ipw2100_hw_send_command(priv, &cmd);
5206 ipw2100_enable_adapter(priv);
5211 struct ipw2100_wep_key {
5217 /* Macros to ease up priting WEP keys */
5218 #define WEP_FMT_64 "%02X%02X%02X%02X-%02X"
5219 #define WEP_FMT_128 "%02X%02X%02X%02X-%02X%02X%02X%02X-%02X%02X%02X"
5220 #define WEP_STR_64(x) x[0],x[1],x[2],x[3],x[4]
5221 #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]
5227 * @priv: struct to work on
5228 * @idx: index of the key we want to set
5229 * @key: ptr to the key data to set
5230 * @len: length of the buffer at @key
5231 * @batch_mode: FIXME perform the operation in batch mode, not
5232 * disabling the device.
5234 * @returns 0 if OK, < 0 errno code on error.
5236 * Fill out a command structure with the new wep key, length an
5237 * index and send it down the wire.
5239 static int ipw2100_set_key(struct ipw2100_priv *priv,
5240 int idx, char *key, int len, int batch_mode)
5242 int keylen = len ? (len <= 5 ? 5 : 13) : 0;
5243 struct host_command cmd = {
5244 .host_command = WEP_KEY_INFO,
5245 .host_command_sequence = 0,
5246 .host_command_length = sizeof(struct ipw2100_wep_key),
5248 struct ipw2100_wep_key *wep_key = (void*)cmd.host_command_parameters;
5251 IPW_DEBUG_HC("WEP_KEY_INFO: index = %d, len = %d/%d\n",
5254 /* NOTE: We don't check cached values in case the firmware was reset
5255 * or some other problem is occuring. If the user is setting the key,
5256 * then we push the change */
5259 wep_key->len = keylen;
5262 memcpy(wep_key->key, key, len);
5263 memset(wep_key->key + len, 0, keylen - len);
5266 /* Will be optimized out on debug not being configured in */
5268 IPW_DEBUG_WEP("%s: Clearing key %d\n",
5269 priv->net_dev->name, wep_key->idx);
5270 else if (keylen == 5)
5271 IPW_DEBUG_WEP("%s: idx: %d, len: %d key: " WEP_FMT_64 "\n",
5272 priv->net_dev->name, wep_key->idx, wep_key->len,
5273 WEP_STR_64(wep_key->key));
5275 IPW_DEBUG_WEP("%s: idx: %d, len: %d key: " WEP_FMT_128
5277 priv->net_dev->name, wep_key->idx, wep_key->len,
5278 WEP_STR_128(wep_key->key));
5281 err = ipw2100_disable_adapter(priv);
5282 /* FIXME: IPG: shouldn't this prink be in _disable_adapter()? */
5284 IPW_DEBUG_ERROR("%s: Could not disable adapter %d\n",
5285 priv->net_dev->name, err);
5290 /* send cmd to firmware */
5291 err = ipw2100_hw_send_command(priv, &cmd);
5294 int err2 = ipw2100_enable_adapter(priv);
5301 static int ipw2100_set_key_index(struct ipw2100_priv *priv,
5302 int idx, int batch_mode)
5304 struct host_command cmd = {
5305 .host_command = WEP_KEY_INDEX,
5306 .host_command_sequence = 0,
5307 .host_command_length = 4,
5308 .host_command_parameters[0] = idx,
5312 IPW_DEBUG_HC("WEP_KEY_INDEX: index = %d\n", idx);
5314 if (idx < 0 || idx > 3)
5318 err = ipw2100_disable_adapter(priv);
5320 IPW_DEBUG_ERROR("%s: Could not disable adapter %d\n",
5321 priv->net_dev->name, err);
5326 /* send cmd to firmware */
5327 err = ipw2100_hw_send_command(priv, &cmd);
5330 ipw2100_enable_adapter(priv);
5336 static int ipw2100_configure_security(struct ipw2100_priv *priv,
5339 int i, err, auth_mode, sec_level, use_group;
5341 if (!(priv->status & STATUS_RUNNING))
5345 err = ipw2100_disable_adapter(priv);
5350 if (!priv->sec.enabled) {
5351 err = ipw2100_set_security_information(
5352 priv, IPW_AUTH_OPEN, SEC_LEVEL_0, 0, 1);
5354 auth_mode = IPW_AUTH_OPEN;
5355 if ((priv->sec.flags & SEC_AUTH_MODE) &&
5356 (priv->sec.auth_mode == WLAN_AUTH_SHARED_KEY))
5357 auth_mode = IPW_AUTH_SHARED;
5359 sec_level = SEC_LEVEL_0;
5360 if (priv->sec.flags & SEC_LEVEL)
5361 sec_level = priv->sec.level;
5364 if (priv->sec.flags & SEC_UNICAST_GROUP)
5365 use_group = priv->sec.unicast_uses_group;
5367 err = ipw2100_set_security_information(
5368 priv, auth_mode, sec_level, use_group, 1);
5374 if (priv->sec.enabled) {
5375 for (i = 0; i < 4; i++) {
5376 if (!(priv->sec.flags & (1 << i))) {
5377 memset(priv->sec.keys[i], 0, WEP_KEY_LEN);
5378 priv->sec.key_sizes[i] = 0;
5380 err = ipw2100_set_key(priv, i,
5382 priv->sec.key_sizes[i],
5389 ipw2100_set_key_index(priv, priv->ieee->tx_keyidx, 1);
5392 /* Always enable privacy so the Host can filter WEP packets if
5393 * encrypted data is sent up */
5394 err = ipw2100_set_wep_flags(
5395 priv, priv->sec.enabled ? IPW_PRIVACY_CAPABLE : 0, 1);
5399 priv->status &= ~STATUS_SECURITY_UPDATED;
5403 ipw2100_enable_adapter(priv);
5408 static void ipw2100_security_work(struct ipw2100_priv *priv)
5410 /* If we happen to have reconnected before we get a chance to
5411 * process this, then update the security settings--which causes
5412 * a disassociation to occur */
5413 if (!(priv->status & STATUS_ASSOCIATED) &&
5414 priv->status & STATUS_SECURITY_UPDATED)
5415 ipw2100_configure_security(priv, 0);
5418 static void shim__set_security(struct net_device *dev,
5419 struct ieee80211_security *sec)
5421 struct ipw2100_priv *priv = ieee80211_priv(dev);
5422 int i, force_update = 0;
5424 down(&priv->action_sem);
5425 if (!(priv->status & STATUS_INITIALIZED))
5428 for (i = 0; i < 4; i++) {
5429 if (sec->flags & (1 << i)) {
5430 priv->sec.key_sizes[i] = sec->key_sizes[i];
5431 if (sec->key_sizes[i] == 0)
5432 priv->sec.flags &= ~(1 << i);
5434 memcpy(priv->sec.keys[i], sec->keys[i],
5436 priv->sec.flags |= (1 << i);
5437 priv->status |= STATUS_SECURITY_UPDATED;
5441 if ((sec->flags & SEC_ACTIVE_KEY) &&
5442 priv->sec.active_key != sec->active_key) {
5443 if (sec->active_key <= 3) {
5444 priv->sec.active_key = sec->active_key;
5445 priv->sec.flags |= SEC_ACTIVE_KEY;
5447 priv->sec.flags &= ~SEC_ACTIVE_KEY;
5449 priv->status |= STATUS_SECURITY_UPDATED;
5452 if ((sec->flags & SEC_AUTH_MODE) &&
5453 (priv->sec.auth_mode != sec->auth_mode)) {
5454 priv->sec.auth_mode = sec->auth_mode;
5455 priv->sec.flags |= SEC_AUTH_MODE;
5456 priv->status |= STATUS_SECURITY_UPDATED;
5459 if (sec->flags & SEC_ENABLED &&
5460 priv->sec.enabled != sec->enabled) {
5461 priv->sec.flags |= SEC_ENABLED;
5462 priv->sec.enabled = sec->enabled;
5463 priv->status |= STATUS_SECURITY_UPDATED;
5467 if (sec->flags & SEC_LEVEL &&
5468 priv->sec.level != sec->level) {
5469 priv->sec.level = sec->level;
5470 priv->sec.flags |= SEC_LEVEL;
5471 priv->status |= STATUS_SECURITY_UPDATED;
5474 IPW_DEBUG_WEP("Security flags: %c %c%c%c%c %c%c%c%c\n",
5475 priv->sec.flags & (1<<8) ? '1' : '0',
5476 priv->sec.flags & (1<<7) ? '1' : '0',
5477 priv->sec.flags & (1<<6) ? '1' : '0',
5478 priv->sec.flags & (1<<5) ? '1' : '0',
5479 priv->sec.flags & (1<<4) ? '1' : '0',
5480 priv->sec.flags & (1<<3) ? '1' : '0',
5481 priv->sec.flags & (1<<2) ? '1' : '0',
5482 priv->sec.flags & (1<<1) ? '1' : '0',
5483 priv->sec.flags & (1<<0) ? '1' : '0');
5485 /* As a temporary work around to enable WPA until we figure out why
5486 * wpa_supplicant toggles the security capability of the driver, which
5487 * forces a disassocation with force_update...
5489 * if (force_update || !(priv->status & STATUS_ASSOCIATED))*/
5490 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
5491 ipw2100_configure_security(priv, 0);
5493 up(&priv->action_sem);
5496 static int ipw2100_adapter_setup(struct ipw2100_priv *priv)
5502 IPW_DEBUG_INFO("enter\n");
5504 err = ipw2100_disable_adapter(priv);
5507 #ifdef CONFIG_IPW2100_MONITOR
5508 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
5509 err = ipw2100_set_channel(priv, priv->channel, batch_mode);
5513 IPW_DEBUG_INFO("exit\n");
5517 #endif /* CONFIG_IPW2100_MONITOR */
5519 err = ipw2100_read_mac_address(priv);
5523 err = ipw2100_set_mac_address(priv, batch_mode);
5527 err = ipw2100_set_port_type(priv, priv->ieee->iw_mode, batch_mode);
5531 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
5532 err = ipw2100_set_channel(priv, priv->channel, batch_mode);
5537 err = ipw2100_system_config(priv, batch_mode);
5541 err = ipw2100_set_tx_rates(priv, priv->tx_rates, batch_mode);
5545 /* Default to power mode OFF */
5546 err = ipw2100_set_power_mode(priv, IPW_POWER_MODE_CAM);
5550 err = ipw2100_set_rts_threshold(priv, priv->rts_threshold);
5554 if (priv->config & CFG_STATIC_BSSID)
5555 bssid = priv->bssid;
5558 err = ipw2100_set_mandatory_bssid(priv, bssid, batch_mode);
5562 if (priv->config & CFG_STATIC_ESSID)
5563 err = ipw2100_set_essid(priv, priv->essid, priv->essid_len,
5566 err = ipw2100_set_essid(priv, NULL, 0, batch_mode);
5570 err = ipw2100_configure_security(priv, batch_mode);
5574 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
5575 err = ipw2100_set_ibss_beacon_interval(
5576 priv, priv->beacon_interval, batch_mode);
5580 err = ipw2100_set_tx_power(priv, priv->tx_power);
5586 err = ipw2100_set_fragmentation_threshold(
5587 priv, priv->frag_threshold, batch_mode);
5592 IPW_DEBUG_INFO("exit\n");
5598 /*************************************************************************
5600 * EXTERNALLY CALLED METHODS
5602 *************************************************************************/
5604 /* This method is called by the network layer -- not to be confused with
5605 * ipw2100_set_mac_address() declared above called by this driver (and this
5606 * method as well) to talk to the firmware */
5607 static int ipw2100_set_address(struct net_device *dev, void *p)
5609 struct ipw2100_priv *priv = ieee80211_priv(dev);
5610 struct sockaddr *addr = p;
5613 if (!is_valid_ether_addr(addr->sa_data))
5614 return -EADDRNOTAVAIL;
5616 down(&priv->action_sem);
5618 priv->config |= CFG_CUSTOM_MAC;
5619 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
5621 err = ipw2100_set_mac_address(priv, 0);
5625 priv->reset_backoff = 0;
5626 up(&priv->action_sem);
5627 ipw2100_reset_adapter(priv);
5631 up(&priv->action_sem);
5635 static int ipw2100_open(struct net_device *dev)
5637 struct ipw2100_priv *priv = ieee80211_priv(dev);
5638 unsigned long flags;
5639 IPW_DEBUG_INFO("dev->open\n");
5641 spin_lock_irqsave(&priv->low_lock, flags);
5642 if (priv->status & STATUS_ASSOCIATED)
5643 netif_start_queue(dev);
5644 spin_unlock_irqrestore(&priv->low_lock, flags);
5649 static int ipw2100_close(struct net_device *dev)
5651 struct ipw2100_priv *priv = ieee80211_priv(dev);
5652 unsigned long flags;
5653 struct list_head *element;
5654 struct ipw2100_tx_packet *packet;
5656 IPW_DEBUG_INFO("enter\n");
5658 spin_lock_irqsave(&priv->low_lock, flags);
5660 if (priv->status & STATUS_ASSOCIATED)
5661 netif_carrier_off(dev);
5662 netif_stop_queue(dev);
5664 /* Flush the TX queue ... */
5665 while (!list_empty(&priv->tx_pend_list)) {
5666 element = priv->tx_pend_list.next;
5667 packet = list_entry(element, struct ipw2100_tx_packet, list);
5670 DEC_STAT(&priv->tx_pend_stat);
5672 ieee80211_txb_free(packet->info.d_struct.txb);
5673 packet->info.d_struct.txb = NULL;
5675 list_add_tail(element, &priv->tx_free_list);
5676 INC_STAT(&priv->tx_free_stat);
5678 spin_unlock_irqrestore(&priv->low_lock, flags);
5680 IPW_DEBUG_INFO("exit\n");
5688 * TODO: Fix this function... its just wrong
5690 static void ipw2100_tx_timeout(struct net_device *dev)
5692 struct ipw2100_priv *priv = ieee80211_priv(dev);
5694 priv->ieee->stats.tx_errors++;
5696 #ifdef CONFIG_IPW2100_MONITOR
5697 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
5701 IPW_DEBUG_INFO("%s: TX timed out. Scheduling firmware restart.\n",
5703 schedule_reset(priv);
5708 * TODO: reimplement it so that it reads statistics
5709 * from the adapter using ordinal tables
5710 * instead of/in addition to collecting them
5713 static struct net_device_stats *ipw2100_stats(struct net_device *dev)
5715 struct ipw2100_priv *priv = ieee80211_priv(dev);
5717 return &priv->ieee->stats;
5720 /* Support for wpa_supplicant. Will be replaced with WEXT once
5721 * they get WPA support. */
5722 #ifdef CONFIG_IEEE80211_WPA
5724 /* following definitions must match definitions in driver_ipw2100.c */
5726 #define IPW2100_IOCTL_WPA_SUPPLICANT SIOCIWFIRSTPRIV+30
5728 #define IPW2100_CMD_SET_WPA_PARAM 1
5729 #define IPW2100_CMD_SET_WPA_IE 2
5730 #define IPW2100_CMD_SET_ENCRYPTION 3
5731 #define IPW2100_CMD_MLME 4
5733 #define IPW2100_PARAM_WPA_ENABLED 1
5734 #define IPW2100_PARAM_TKIP_COUNTERMEASURES 2
5735 #define IPW2100_PARAM_DROP_UNENCRYPTED 3
5736 #define IPW2100_PARAM_PRIVACY_INVOKED 4
5737 #define IPW2100_PARAM_AUTH_ALGS 5
5738 #define IPW2100_PARAM_IEEE_802_1X 6
5740 #define IPW2100_MLME_STA_DEAUTH 1
5741 #define IPW2100_MLME_STA_DISASSOC 2
5743 #define IPW2100_CRYPT_ERR_UNKNOWN_ALG 2
5744 #define IPW2100_CRYPT_ERR_UNKNOWN_ADDR 3
5745 #define IPW2100_CRYPT_ERR_CRYPT_INIT_FAILED 4
5746 #define IPW2100_CRYPT_ERR_KEY_SET_FAILED 5
5747 #define IPW2100_CRYPT_ERR_TX_KEY_SET_FAILED 6
5748 #define IPW2100_CRYPT_ERR_CARD_CONF_FAILED 7
5750 #define IPW2100_CRYPT_ALG_NAME_LEN 16
5752 struct ipw2100_param {
5754 u8 sta_addr[ETH_ALEN];
5769 u8 alg[IPW2100_CRYPT_ALG_NAME_LEN];
5773 u8 seq[8]; /* sequence counter (set: RX, get: TX) */
5781 /* end of driver_ipw2100.c code */
5783 static int ipw2100_wpa_enable(struct ipw2100_priv *priv, int value){
5785 struct ieee80211_device *ieee = priv->ieee;
5786 struct ieee80211_security sec = {
5787 .flags = SEC_LEVEL | SEC_ENABLED,
5791 ieee->wpa_enabled = value;
5794 sec.level = SEC_LEVEL_3;
5797 sec.level = SEC_LEVEL_0;
5801 if (ieee->set_security)
5802 ieee->set_security(ieee->dev, &sec);
5809 #define AUTH_ALG_OPEN_SYSTEM 0x1
5810 #define AUTH_ALG_SHARED_KEY 0x2
5812 static int ipw2100_wpa_set_auth_algs(struct ipw2100_priv *priv, int value){
5814 struct ieee80211_device *ieee = priv->ieee;
5815 struct ieee80211_security sec = {
5816 .flags = SEC_AUTH_MODE,
5820 if (value & AUTH_ALG_SHARED_KEY){
5821 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
5824 sec.auth_mode = WLAN_AUTH_OPEN;
5828 if (ieee->set_security)
5829 ieee->set_security(ieee->dev, &sec);
5837 static int ipw2100_wpa_set_param(struct net_device *dev, u8 name, u32 value){
5839 struct ipw2100_priv *priv = ieee80211_priv(dev);
5843 case IPW2100_PARAM_WPA_ENABLED:
5844 ret = ipw2100_wpa_enable(priv, value);
5847 case IPW2100_PARAM_TKIP_COUNTERMEASURES:
5848 priv->ieee->tkip_countermeasures=value;
5851 case IPW2100_PARAM_DROP_UNENCRYPTED:
5852 priv->ieee->drop_unencrypted=value;
5855 case IPW2100_PARAM_PRIVACY_INVOKED:
5856 priv->ieee->privacy_invoked=value;
5859 case IPW2100_PARAM_AUTH_ALGS:
5860 ret = ipw2100_wpa_set_auth_algs(priv, value);
5863 case IPW2100_PARAM_IEEE_802_1X:
5864 priv->ieee->ieee802_1x=value;
5868 IPW_DEBUG_ERROR("%s: Unknown WPA param: %d\n",
5876 static int ipw2100_wpa_mlme(struct net_device *dev, int command, int reason){
5878 struct ipw2100_priv *priv = ieee80211_priv(dev);
5882 case IPW2100_MLME_STA_DEAUTH:
5886 case IPW2100_MLME_STA_DISASSOC:
5887 ipw2100_disassociate_bssid(priv);
5891 IPW_DEBUG_ERROR("%s: Unknown MLME request: %d\n",
5892 dev->name, command);
5900 void ipw2100_wpa_assoc_frame(struct ipw2100_priv *priv,
5901 char *wpa_ie, int wpa_ie_len){
5903 struct ipw2100_wpa_assoc_frame frame;
5905 frame.fixed_ie_mask = 0;
5908 memcpy(frame.var_ie, wpa_ie, wpa_ie_len);
5909 frame.var_ie_len = wpa_ie_len;
5911 /* make sure WPA is enabled */
5912 ipw2100_wpa_enable(priv, 1);
5913 ipw2100_set_wpa_ie(priv, &frame, 0);
5917 static int ipw2100_wpa_set_wpa_ie(struct net_device *dev,
5918 struct ipw2100_param *param, int plen){
5920 struct ipw2100_priv *priv = ieee80211_priv(dev);
5921 struct ieee80211_device *ieee = priv->ieee;
5924 if (! ieee->wpa_enabled)
5927 if (param->u.wpa_ie.len > MAX_WPA_IE_LEN ||
5928 (param->u.wpa_ie.len &&
5929 param->u.wpa_ie.data==NULL))
5932 if (param->u.wpa_ie.len){
5933 buf = kmalloc(param->u.wpa_ie.len, GFP_KERNEL);
5937 memcpy(buf, param->u.wpa_ie.data, param->u.wpa_ie.len);
5939 kfree(ieee->wpa_ie);
5941 ieee->wpa_ie_len = param->u.wpa_ie.len;
5944 kfree(ieee->wpa_ie);
5945 ieee->wpa_ie = NULL;
5946 ieee->wpa_ie_len = 0;
5949 ipw2100_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
5954 /* implementation borrowed from hostap driver */
5956 static int ipw2100_wpa_set_encryption(struct net_device *dev,
5957 struct ipw2100_param *param, int param_len){
5960 struct ipw2100_priv *priv = ieee80211_priv(dev);
5961 struct ieee80211_device *ieee = priv->ieee;
5962 struct ieee80211_crypto_ops *ops;
5963 struct ieee80211_crypt_data **crypt;
5965 struct ieee80211_security sec = {
5969 param->u.crypt.err = 0;
5970 param->u.crypt.alg[IPW2100_CRYPT_ALG_NAME_LEN - 1] = '\0';
5973 (int) ((char *) param->u.crypt.key - (char *) param) +
5974 param->u.crypt.key_len){
5975 IPW_DEBUG_INFO("Len mismatch %d, %d\n", param_len, param->u.crypt.key_len);
5978 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
5979 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
5980 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
5981 if (param->u.crypt.idx >= WEP_KEYS)
5983 crypt = &ieee->crypt[param->u.crypt.idx];
5988 if (strcmp(param->u.crypt.alg, "none") == 0) {
5991 sec.level = SEC_LEVEL_0;
5992 sec.flags |= SEC_ENABLED | SEC_LEVEL;
5993 ieee80211_crypt_delayed_deinit(ieee, crypt);
5998 sec.flags |= SEC_ENABLED;
6000 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6001 if (ops == NULL && strcmp(param->u.crypt.alg, "WEP") == 0) {
6002 request_module("ieee80211_crypt_wep");
6003 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6004 } else if (ops == NULL && strcmp(param->u.crypt.alg, "TKIP") == 0) {
6005 request_module("ieee80211_crypt_tkip");
6006 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6007 } else if (ops == NULL && strcmp(param->u.crypt.alg, "CCMP") == 0) {
6008 request_module("ieee80211_crypt_ccmp");
6009 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6012 IPW_DEBUG_INFO("%s: unknown crypto alg '%s'\n",
6013 dev->name, param->u.crypt.alg);
6014 param->u.crypt.err = IPW2100_CRYPT_ERR_UNKNOWN_ALG;
6019 if (*crypt == NULL || (*crypt)->ops != ops) {
6020 struct ieee80211_crypt_data *new_crypt;
6022 ieee80211_crypt_delayed_deinit(ieee, crypt);
6024 new_crypt = (struct ieee80211_crypt_data *)
6025 kmalloc(sizeof(struct ieee80211_crypt_data), GFP_KERNEL);
6026 if (new_crypt == NULL) {
6030 memset(new_crypt, 0, sizeof(struct ieee80211_crypt_data));
6031 new_crypt->ops = ops;
6032 if (new_crypt->ops && try_module_get(new_crypt->ops->owner))
6033 new_crypt->priv = new_crypt->ops->init(param->u.crypt.idx);
6035 if (new_crypt->priv == NULL) {
6037 param->u.crypt.err =
6038 IPW2100_CRYPT_ERR_CRYPT_INIT_FAILED;
6046 if (param->u.crypt.key_len > 0 && (*crypt)->ops->set_key &&
6047 (*crypt)->ops->set_key(param->u.crypt.key,
6048 param->u.crypt.key_len, param->u.crypt.seq,
6049 (*crypt)->priv) < 0) {
6050 IPW_DEBUG_INFO("%s: key setting failed\n",
6052 param->u.crypt.err = IPW2100_CRYPT_ERR_KEY_SET_FAILED;
6057 if (param->u.crypt.set_tx){
6058 ieee->tx_keyidx = param->u.crypt.idx;
6059 sec.active_key = param->u.crypt.idx;
6060 sec.flags |= SEC_ACTIVE_KEY;
6063 if (ops->name != NULL){
6065 if (strcmp(ops->name, "WEP") == 0) {
6066 memcpy(sec.keys[param->u.crypt.idx], param->u.crypt.key, param->u.crypt.key_len);
6067 sec.key_sizes[param->u.crypt.idx] = param->u.crypt.key_len;
6068 sec.flags |= (1 << param->u.crypt.idx);
6069 sec.flags |= SEC_LEVEL;
6070 sec.level = SEC_LEVEL_1;
6071 } else if (strcmp(ops->name, "TKIP") == 0) {
6072 sec.flags |= SEC_LEVEL;
6073 sec.level = SEC_LEVEL_2;
6074 } else if (strcmp(ops->name, "CCMP") == 0) {
6075 sec.flags |= SEC_LEVEL;
6076 sec.level = SEC_LEVEL_3;
6080 if (ieee->set_security)
6081 ieee->set_security(ieee->dev, &sec);
6083 /* Do not reset port if card is in Managed mode since resetting will
6084 * generate new IEEE 802.11 authentication which may end up in looping
6085 * with IEEE 802.1X. If your hardware requires a reset after WEP
6086 * configuration (for example... Prism2), implement the reset_port in
6087 * the callbacks structures used to initialize the 802.11 stack. */
6088 if (ieee->reset_on_keychange &&
6089 ieee->iw_mode != IW_MODE_INFRA &&
6091 ieee->reset_port(dev)) {
6092 IPW_DEBUG_INFO("%s: reset_port failed\n", dev->name);
6093 param->u.crypt.err = IPW2100_CRYPT_ERR_CARD_CONF_FAILED;
6101 static int ipw2100_wpa_supplicant(struct net_device *dev, struct iw_point *p){
6103 struct ipw2100_param *param;
6106 IPW_DEBUG_IOCTL("wpa_supplicant: len=%d\n", p->length);
6108 if (p->length < sizeof(struct ipw2100_param) || !p->pointer)
6111 param = (struct ipw2100_param *)kmalloc(p->length, GFP_KERNEL);
6115 if (copy_from_user(param, p->pointer, p->length)){
6120 switch (param->cmd){
6122 case IPW2100_CMD_SET_WPA_PARAM:
6123 ret = ipw2100_wpa_set_param(dev, param->u.wpa_param.name,
6124 param->u.wpa_param.value);
6127 case IPW2100_CMD_SET_WPA_IE:
6128 ret = ipw2100_wpa_set_wpa_ie(dev, param, p->length);
6131 case IPW2100_CMD_SET_ENCRYPTION:
6132 ret = ipw2100_wpa_set_encryption(dev, param, p->length);
6135 case IPW2100_CMD_MLME:
6136 ret = ipw2100_wpa_mlme(dev, param->u.mlme.command,
6137 param->u.mlme.reason_code);
6141 IPW_DEBUG_ERROR("%s: Unknown WPA supplicant request: %d\n",
6142 dev->name, param->cmd);
6147 if (ret == 0 && copy_to_user(p->pointer, param, p->length))
6153 #endif /* CONFIG_IEEE80211_WPA */
6155 static int ipw2100_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
6157 #ifdef CONFIG_IEEE80211_WPA
6158 struct iwreq *wrq = (struct iwreq *) rq;
6161 case IPW2100_IOCTL_WPA_SUPPLICANT:
6162 ret = ipw2100_wpa_supplicant(dev, &wrq->u.data);
6169 #endif /* CONFIG_IEEE80211_WPA */
6175 static void ipw_ethtool_get_drvinfo(struct net_device *dev,
6176 struct ethtool_drvinfo *info)
6178 struct ipw2100_priv *priv = ieee80211_priv(dev);
6179 char fw_ver[64], ucode_ver[64];
6181 strcpy(info->driver, DRV_NAME);
6182 strcpy(info->version, DRV_VERSION);
6184 ipw2100_get_fwversion(priv, fw_ver, sizeof(fw_ver));
6185 ipw2100_get_ucodeversion(priv, ucode_ver, sizeof(ucode_ver));
6187 snprintf(info->fw_version, sizeof(info->fw_version), "%s:%d:%s",
6188 fw_ver, priv->eeprom_version, ucode_ver);
6190 strcpy(info->bus_info, pci_name(priv->pci_dev));
6193 static u32 ipw2100_ethtool_get_link(struct net_device *dev)
6195 struct ipw2100_priv *priv = ieee80211_priv(dev);
6196 return (priv->status & STATUS_ASSOCIATED) ? 1 : 0;
6200 static struct ethtool_ops ipw2100_ethtool_ops = {
6201 .get_link = ipw2100_ethtool_get_link,
6202 .get_drvinfo = ipw_ethtool_get_drvinfo,
6205 static void ipw2100_hang_check(void *adapter)
6207 struct ipw2100_priv *priv = adapter;
6208 unsigned long flags;
6209 u32 rtc = 0xa5a5a5a5;
6210 u32 len = sizeof(rtc);
6213 spin_lock_irqsave(&priv->low_lock, flags);
6215 if (priv->fatal_error != 0) {
6216 /* If fatal_error is set then we need to restart */
6217 IPW_DEBUG_INFO("%s: Hardware fatal error detected.\n",
6218 priv->net_dev->name);
6221 } else if (ipw2100_get_ordinal(priv, IPW_ORD_RTC_TIME, &rtc, &len) ||
6222 (rtc == priv->last_rtc)) {
6223 /* Check if firmware is hung */
6224 IPW_DEBUG_INFO("%s: Firmware RTC stalled.\n",
6225 priv->net_dev->name);
6232 priv->stop_hang_check = 1;
6235 /* Restart the NIC */
6236 schedule_reset(priv);
6239 priv->last_rtc = rtc;
6241 if (!priv->stop_hang_check)
6242 queue_delayed_work(priv->workqueue, &priv->hang_check, HZ / 2);
6244 spin_unlock_irqrestore(&priv->low_lock, flags);
6248 static void ipw2100_rf_kill(void *adapter)
6250 struct ipw2100_priv *priv = adapter;
6251 unsigned long flags;
6253 spin_lock_irqsave(&priv->low_lock, flags);
6255 if (rf_kill_active(priv)) {
6256 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
6257 if (!priv->stop_rf_kill)
6258 queue_delayed_work(priv->workqueue, &priv->rf_kill, HZ);
6262 /* RF Kill is now disabled, so bring the device back up */
6264 if (!(priv->status & STATUS_RF_KILL_MASK)) {
6265 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
6267 schedule_reset(priv);
6269 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
6273 spin_unlock_irqrestore(&priv->low_lock, flags);
6276 static void ipw2100_irq_tasklet(struct ipw2100_priv *priv);
6278 /* Look into using netdev destructor to shutdown ieee80211? */
6280 static struct net_device *ipw2100_alloc_device(
6281 struct pci_dev *pci_dev,
6283 unsigned long mem_start,
6284 unsigned long mem_len)
6286 struct ipw2100_priv *priv;
6287 struct net_device *dev;
6289 dev = alloc_ieee80211(sizeof(struct ipw2100_priv));
6292 priv = ieee80211_priv(dev);
6293 priv->ieee = netdev_priv(dev);
6294 priv->pci_dev = pci_dev;
6295 priv->net_dev = dev;
6297 priv->ieee->hard_start_xmit = ipw2100_tx;
6298 priv->ieee->set_security = shim__set_security;
6300 dev->open = ipw2100_open;
6301 dev->stop = ipw2100_close;
6302 dev->init = ipw2100_net_init;
6303 dev->do_ioctl = ipw2100_ioctl;
6304 dev->get_stats = ipw2100_stats;
6305 dev->ethtool_ops = &ipw2100_ethtool_ops;
6306 dev->tx_timeout = ipw2100_tx_timeout;
6307 dev->wireless_handlers = &ipw2100_wx_handler_def;
6308 dev->get_wireless_stats = ipw2100_wx_wireless_stats;
6309 dev->set_mac_address = ipw2100_set_address;
6310 dev->watchdog_timeo = 3*HZ;
6313 dev->base_addr = (unsigned long)base_addr;
6314 dev->mem_start = mem_start;
6315 dev->mem_end = dev->mem_start + mem_len - 1;
6317 /* NOTE: We don't use the wireless_handlers hook
6318 * in dev as the system will start throwing WX requests
6319 * to us before we're actually initialized and it just
6320 * ends up causing problems. So, we just handle
6321 * the WX extensions through the ipw2100_ioctl interface */
6324 /* memset() puts everything to 0, so we only have explicitely set
6325 * those values that need to be something else */
6327 /* If power management is turned on, default to AUTO mode */
6328 priv->power_mode = IPW_POWER_AUTO;
6332 #ifdef CONFIG_IEEE80211_WPA
6333 priv->ieee->wpa_enabled = 0;
6334 priv->ieee->tkip_countermeasures = 0;
6335 priv->ieee->drop_unencrypted = 0;
6336 priv->ieee->privacy_invoked = 0;
6337 priv->ieee->ieee802_1x = 1;
6338 #endif /* CONFIG_IEEE80211_WPA */
6340 /* Set module parameters */
6343 priv->ieee->iw_mode = IW_MODE_ADHOC;
6345 #ifdef CONFIG_IPW2100_MONITOR
6347 priv->ieee->iw_mode = IW_MODE_MONITOR;
6352 priv->ieee->iw_mode = IW_MODE_INFRA;
6357 priv->status |= STATUS_RF_KILL_SW;
6360 ((channel >= REG_MIN_CHANNEL) &&
6361 (channel <= REG_MAX_CHANNEL))) {
6362 priv->config |= CFG_STATIC_CHANNEL;
6363 priv->channel = channel;
6367 priv->config |= CFG_ASSOCIATE;
6369 priv->beacon_interval = DEFAULT_BEACON_INTERVAL;
6370 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
6371 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
6372 priv->rts_threshold = DEFAULT_RTS_THRESHOLD | RTS_DISABLED;
6373 priv->frag_threshold = DEFAULT_FTS | FRAG_DISABLED;
6374 priv->tx_power = IPW_TX_POWER_DEFAULT;
6375 priv->tx_rates = DEFAULT_TX_RATES;
6377 strcpy(priv->nick, "ipw2100");
6379 spin_lock_init(&priv->low_lock);
6380 sema_init(&priv->action_sem, 1);
6381 sema_init(&priv->adapter_sem, 1);
6383 init_waitqueue_head(&priv->wait_command_queue);
6385 netif_carrier_off(dev);
6387 INIT_LIST_HEAD(&priv->msg_free_list);
6388 INIT_LIST_HEAD(&priv->msg_pend_list);
6389 INIT_STAT(&priv->msg_free_stat);
6390 INIT_STAT(&priv->msg_pend_stat);
6392 INIT_LIST_HEAD(&priv->tx_free_list);
6393 INIT_LIST_HEAD(&priv->tx_pend_list);
6394 INIT_STAT(&priv->tx_free_stat);
6395 INIT_STAT(&priv->tx_pend_stat);
6397 INIT_LIST_HEAD(&priv->fw_pend_list);
6398 INIT_STAT(&priv->fw_pend_stat);
6401 #ifdef CONFIG_SOFTWARE_SUSPEND2
6402 priv->workqueue = create_workqueue(DRV_NAME, 0);
6404 priv->workqueue = create_workqueue(DRV_NAME);
6406 INIT_WORK(&priv->reset_work,
6407 (void (*)(void *))ipw2100_reset_adapter, priv);
6408 INIT_WORK(&priv->security_work,
6409 (void (*)(void *))ipw2100_security_work, priv);
6410 INIT_WORK(&priv->wx_event_work,
6411 (void (*)(void *))ipw2100_wx_event_work, priv);
6412 INIT_WORK(&priv->hang_check, ipw2100_hang_check, priv);
6413 INIT_WORK(&priv->rf_kill, ipw2100_rf_kill, priv);
6415 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
6416 ipw2100_irq_tasklet, (unsigned long)priv);
6418 /* NOTE: We do not start the deferred work for status checks yet */
6419 priv->stop_rf_kill = 1;
6420 priv->stop_hang_check = 1;
6425 static int ipw2100_pci_init_one(struct pci_dev *pci_dev,
6426 const struct pci_device_id *ent)
6428 unsigned long mem_start, mem_len, mem_flags;
6429 char *base_addr = NULL;
6430 struct net_device *dev = NULL;
6431 struct ipw2100_priv *priv = NULL;
6436 IPW_DEBUG_INFO("enter\n");
6438 mem_start = pci_resource_start(pci_dev, 0);
6439 mem_len = pci_resource_len(pci_dev, 0);
6440 mem_flags = pci_resource_flags(pci_dev, 0);
6442 if ((mem_flags & IORESOURCE_MEM) != IORESOURCE_MEM) {
6443 IPW_DEBUG_INFO("weird - resource type is not memory\n");
6448 base_addr = ioremap_nocache(mem_start, mem_len);
6450 printk(KERN_WARNING DRV_NAME
6451 "Error calling ioremap_nocache.\n");
6456 /* allocate and initialize our net_device */
6457 dev = ipw2100_alloc_device(pci_dev, base_addr, mem_start, mem_len);
6459 printk(KERN_WARNING DRV_NAME
6460 "Error calling ipw2100_alloc_device.\n");
6465 /* set up PCI mappings for device */
6466 err = pci_enable_device(pci_dev);
6468 printk(KERN_WARNING DRV_NAME
6469 "Error calling pci_enable_device.\n");
6473 priv = ieee80211_priv(dev);
6475 pci_set_master(pci_dev);
6476 pci_set_drvdata(pci_dev, priv);
6478 err = pci_set_dma_mask(pci_dev, DMA_32BIT_MASK);
6480 printk(KERN_WARNING DRV_NAME
6481 "Error calling pci_set_dma_mask.\n");
6482 pci_disable_device(pci_dev);
6486 err = pci_request_regions(pci_dev, DRV_NAME);
6488 printk(KERN_WARNING DRV_NAME
6489 "Error calling pci_request_regions.\n");
6490 pci_disable_device(pci_dev);
6494 /* We disable the RETRY_TIMEOUT register (0x41) to keep
6495 * PCI Tx retries from interfering with C3 CPU state */
6496 pci_read_config_dword(pci_dev, 0x40, &val);
6497 if ((val & 0x0000ff00) != 0)
6498 pci_write_config_dword(pci_dev, 0x40, val & 0xffff00ff);
6500 pci_set_power_state(pci_dev, PCI_D0);
6502 if (!ipw2100_hw_is_adapter_in_system(dev)) {
6503 printk(KERN_WARNING DRV_NAME
6504 "Device not found via register read.\n");
6509 SET_NETDEV_DEV(dev, &pci_dev->dev);
6511 /* Force interrupts to be shut off on the device */
6512 priv->status |= STATUS_INT_ENABLED;
6513 ipw2100_disable_interrupts(priv);
6515 /* Allocate and initialize the Tx/Rx queues and lists */
6516 if (ipw2100_queues_allocate(priv)) {
6517 printk(KERN_WARNING DRV_NAME
6518 "Error calilng ipw2100_queues_allocate.\n");
6522 ipw2100_queues_initialize(priv);
6524 err = request_irq(pci_dev->irq,
6525 ipw2100_interrupt, SA_SHIRQ,
6528 printk(KERN_WARNING DRV_NAME
6529 "Error calling request_irq: %d.\n",
6533 dev->irq = pci_dev->irq;
6535 IPW_DEBUG_INFO("Attempting to register device...\n");
6537 SET_MODULE_OWNER(dev);
6539 printk(KERN_INFO DRV_NAME
6540 ": Detected Intel PRO/Wireless 2100 Network Connection\n");
6542 /* Bring up the interface. Pre 0.46, after we registered the
6543 * network device we would call ipw2100_up. This introduced a race
6544 * condition with newer hotplug configurations (network was coming
6545 * up and making calls before the device was initialized).
6547 * If we called ipw2100_up before we registered the device, then the
6548 * device name wasn't registered. So, we instead use the net_dev->init
6549 * member to call a function that then just turns and calls ipw2100_up.
6550 * net_dev->init is called after name allocation but before the
6551 * notifier chain is called */
6552 down(&priv->action_sem);
6553 err = register_netdev(dev);
6555 printk(KERN_WARNING DRV_NAME
6556 "Error calling register_netdev.\n");
6561 IPW_DEBUG_INFO("%s: Bound to %s\n", dev->name, pci_name(pci_dev));
6563 /* perform this after register_netdev so that dev->name is set */
6564 sysfs_create_group(&pci_dev->dev.kobj, &ipw2100_attribute_group);
6565 netif_carrier_off(dev);
6567 /* If the RF Kill switch is disabled, go ahead and complete the
6568 * startup sequence */
6569 if (!(priv->status & STATUS_RF_KILL_MASK)) {
6570 /* Enable the adapter - sends HOST_COMPLETE */
6571 if (ipw2100_enable_adapter(priv)) {
6572 printk(KERN_WARNING DRV_NAME
6573 ": %s: failed in call to enable adapter.\n",
6574 priv->net_dev->name);
6575 ipw2100_hw_stop_adapter(priv);
6580 /* Start a scan . . . */
6581 ipw2100_set_scan_options(priv);
6582 ipw2100_start_scan(priv);
6585 IPW_DEBUG_INFO("exit\n");
6587 priv->status |= STATUS_INITIALIZED;
6589 up(&priv->action_sem);
6594 up(&priv->action_sem);
6599 unregister_netdev(dev);
6601 ipw2100_hw_stop_adapter(priv);
6603 ipw2100_disable_interrupts(priv);
6606 free_irq(dev->irq, priv);
6608 ipw2100_kill_workqueue(priv);
6610 /* These are safe to call even if they weren't allocated */
6611 ipw2100_queues_free(priv);
6612 sysfs_remove_group(&pci_dev->dev.kobj, &ipw2100_attribute_group);
6614 free_ieee80211(dev);
6615 pci_set_drvdata(pci_dev, NULL);
6619 iounmap((char*)base_addr);
6621 pci_release_regions(pci_dev);
6622 pci_disable_device(pci_dev);
6627 static void __devexit ipw2100_pci_remove_one(struct pci_dev *pci_dev)
6629 struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
6630 struct net_device *dev;
6633 down(&priv->action_sem);
6635 priv->status &= ~STATUS_INITIALIZED;
6637 dev = priv->net_dev;
6638 sysfs_remove_group(&pci_dev->dev.kobj, &ipw2100_attribute_group);
6641 if (ipw2100_firmware.version)
6642 ipw2100_release_firmware(priv, &ipw2100_firmware);
6644 /* Take down the hardware */
6647 /* Release the semaphore so that the network subsystem can
6648 * complete any needed calls into the driver... */
6649 up(&priv->action_sem);
6651 /* Unregister the device first - this results in close()
6652 * being called if the device is open. If we free storage
6653 * first, then close() will crash. */
6654 unregister_netdev(dev);
6656 /* ipw2100_down will ensure that there is no more pending work
6657 * in the workqueue's, so we can safely remove them now. */
6658 ipw2100_kill_workqueue(priv);
6660 ipw2100_queues_free(priv);
6662 /* Free potential debugging firmware snapshot */
6663 ipw2100_snapshot_free(priv);
6666 free_irq(dev->irq, priv);
6669 iounmap((unsigned char *)dev->base_addr);
6671 free_ieee80211(dev);
6674 pci_release_regions(pci_dev);
6675 pci_disable_device(pci_dev);
6677 IPW_DEBUG_INFO("exit\n");
6682 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11)
6683 static int ipw2100_suspend(struct pci_dev *pci_dev, u32 state)
6685 static int ipw2100_suspend(struct pci_dev *pci_dev, pm_message_t state)
6688 struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
6689 struct net_device *dev = priv->net_dev;
6691 IPW_DEBUG_INFO("%s: Going into suspend...\n",
6694 down(&priv->action_sem);
6695 if (priv->status & STATUS_INITIALIZED) {
6696 /* Take down the device; powers it off, etc. */
6700 /* Remove the PRESENT state of the device */
6701 netif_device_detach(dev);
6703 pci_save_state(pci_dev);
6704 pci_disable_device (pci_dev);
6705 pci_set_power_state(pci_dev, PCI_D3hot);
6707 up(&priv->action_sem);
6712 static int ipw2100_resume(struct pci_dev *pci_dev)
6714 struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
6715 struct net_device *dev = priv->net_dev;
6718 if (IPW2100_PM_DISABLED)
6721 down(&priv->action_sem);
6723 IPW_DEBUG_INFO("%s: Coming out of suspend...\n",
6726 pci_set_power_state(pci_dev, PCI_D0);
6727 pci_enable_device(pci_dev);
6728 pci_restore_state(pci_dev);
6731 * Suspend/Resume resets the PCI configuration space, so we have to
6732 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
6733 * from interfering with C3 CPU state. pci_restore_state won't help
6734 * here since it only restores the first 64 bytes pci config header.
6736 pci_read_config_dword(pci_dev, 0x40, &val);
6737 if ((val & 0x0000ff00) != 0)
6738 pci_write_config_dword(pci_dev, 0x40, val & 0xffff00ff);
6740 /* Set the device back into the PRESENT state; this will also wake
6741 * the queue of needed */
6742 netif_device_attach(dev);
6744 /* Bring the device back up */
6745 if (!(priv->status & STATUS_RF_KILL_SW))
6746 ipw2100_up(priv, 0);
6748 up(&priv->action_sem);
6755 #define IPW2100_DEV_ID(x) { PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, x }
6757 static struct pci_device_id ipw2100_pci_id_table[] __devinitdata = {
6758 IPW2100_DEV_ID(0x2520), /* IN 2100A mPCI 3A */
6759 IPW2100_DEV_ID(0x2521), /* IN 2100A mPCI 3B */
6760 IPW2100_DEV_ID(0x2524), /* IN 2100A mPCI 3B */
6761 IPW2100_DEV_ID(0x2525), /* IN 2100A mPCI 3B */
6762 IPW2100_DEV_ID(0x2526), /* IN 2100A mPCI Gen A3 */
6763 IPW2100_DEV_ID(0x2522), /* IN 2100 mPCI 3B */
6764 IPW2100_DEV_ID(0x2523), /* IN 2100 mPCI 3A */
6765 IPW2100_DEV_ID(0x2527), /* IN 2100 mPCI 3B */
6766 IPW2100_DEV_ID(0x2528), /* IN 2100 mPCI 3B */
6767 IPW2100_DEV_ID(0x2529), /* IN 2100 mPCI 3B */
6768 IPW2100_DEV_ID(0x252B), /* IN 2100 mPCI 3A */
6769 IPW2100_DEV_ID(0x252C), /* IN 2100 mPCI 3A */
6770 IPW2100_DEV_ID(0x252D), /* IN 2100 mPCI 3A */
6772 IPW2100_DEV_ID(0x2550), /* IB 2100A mPCI 3B */
6773 IPW2100_DEV_ID(0x2551), /* IB 2100 mPCI 3B */
6774 IPW2100_DEV_ID(0x2553), /* IB 2100 mPCI 3B */
6775 IPW2100_DEV_ID(0x2554), /* IB 2100 mPCI 3B */
6776 IPW2100_DEV_ID(0x2555), /* IB 2100 mPCI 3B */
6778 IPW2100_DEV_ID(0x2560), /* DE 2100A mPCI 3A */
6779 IPW2100_DEV_ID(0x2562), /* DE 2100A mPCI 3A */
6780 IPW2100_DEV_ID(0x2563), /* DE 2100A mPCI 3A */
6781 IPW2100_DEV_ID(0x2561), /* DE 2100 mPCI 3A */
6782 IPW2100_DEV_ID(0x2565), /* DE 2100 mPCI 3A */
6783 IPW2100_DEV_ID(0x2566), /* DE 2100 mPCI 3A */
6784 IPW2100_DEV_ID(0x2567), /* DE 2100 mPCI 3A */
6786 IPW2100_DEV_ID(0x2570), /* GA 2100 mPCI 3B */
6788 IPW2100_DEV_ID(0x2580), /* TO 2100A mPCI 3B */
6789 IPW2100_DEV_ID(0x2582), /* TO 2100A mPCI 3B */
6790 IPW2100_DEV_ID(0x2583), /* TO 2100A mPCI 3B */
6791 IPW2100_DEV_ID(0x2581), /* TO 2100 mPCI 3B */
6792 IPW2100_DEV_ID(0x2585), /* TO 2100 mPCI 3B */
6793 IPW2100_DEV_ID(0x2586), /* TO 2100 mPCI 3B */
6794 IPW2100_DEV_ID(0x2587), /* TO 2100 mPCI 3B */
6796 IPW2100_DEV_ID(0x2590), /* SO 2100A mPCI 3B */
6797 IPW2100_DEV_ID(0x2592), /* SO 2100A mPCI 3B */
6798 IPW2100_DEV_ID(0x2591), /* SO 2100 mPCI 3B */
6799 IPW2100_DEV_ID(0x2593), /* SO 2100 mPCI 3B */
6800 IPW2100_DEV_ID(0x2596), /* SO 2100 mPCI 3B */
6801 IPW2100_DEV_ID(0x2598), /* SO 2100 mPCI 3B */
6803 IPW2100_DEV_ID(0x25A0), /* HP 2100 mPCI 3B */
6807 MODULE_DEVICE_TABLE(pci, ipw2100_pci_id_table);
6809 static struct pci_driver ipw2100_pci_driver = {
6811 .id_table = ipw2100_pci_id_table,
6812 .probe = ipw2100_pci_init_one,
6813 .remove = __devexit_p(ipw2100_pci_remove_one),
6815 .suspend = ipw2100_suspend,
6816 .resume = ipw2100_resume,
6822 * Initialize the ipw2100 driver/module
6824 * @returns 0 if ok, < 0 errno node con error.
6826 * Note: we cannot init the /proc stuff until the PCI driver is there,
6827 * or we risk an unlikely race condition on someone accessing
6828 * uninitialized data in the PCI dev struct through /proc.
6830 static int __init ipw2100_init(void)
6834 printk(KERN_INFO DRV_NAME ": %s, %s\n", DRV_DESCRIPTION, DRV_VERSION);
6835 printk(KERN_INFO DRV_NAME ": %s\n", DRV_COPYRIGHT);
6837 #ifdef CONFIG_IEEE80211_NOWEP
6838 IPW_DEBUG_INFO(DRV_NAME ": Compiled with WEP disabled.\n");
6841 ret = pci_module_init(&ipw2100_pci_driver);
6843 #ifdef CONFIG_IPW_DEBUG
6844 ipw2100_debug_level = debug;
6845 driver_create_file(&ipw2100_pci_driver.driver,
6846 &driver_attr_debug_level);
6854 * Cleanup ipw2100 driver registration
6856 static void __exit ipw2100_exit(void)
6858 /* FIXME: IPG: check that we have no instances of the devices open */
6859 #ifdef CONFIG_IPW_DEBUG
6860 driver_remove_file(&ipw2100_pci_driver.driver,
6861 &driver_attr_debug_level);
6863 pci_unregister_driver(&ipw2100_pci_driver);
6866 module_init(ipw2100_init);
6867 module_exit(ipw2100_exit);
6869 #define WEXT_USECHANNELS 1
6871 const long ipw2100_frequencies[] = {
6872 2412, 2417, 2422, 2427,
6873 2432, 2437, 2442, 2447,
6874 2452, 2457, 2462, 2467,
6878 #define FREQ_COUNT (sizeof(ipw2100_frequencies) / \
6879 sizeof(ipw2100_frequencies[0]))
6881 const long ipw2100_rates_11b[] = {
6888 #define RATE_COUNT (sizeof(ipw2100_rates_11b) / sizeof(ipw2100_rates_11b[0]))
6890 static int ipw2100_wx_get_name(struct net_device *dev,
6891 struct iw_request_info *info,
6892 union iwreq_data *wrqu, char *extra)
6895 * This can be called at any time. No action lock required
6898 struct ipw2100_priv *priv = ieee80211_priv(dev);
6899 if (!(priv->status & STATUS_ASSOCIATED))
6900 strcpy(wrqu->name, "unassociated");
6902 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11b");
6904 IPW_DEBUG_WX("Name: %s\n", wrqu->name);
6909 static int ipw2100_wx_set_freq(struct net_device *dev,
6910 struct iw_request_info *info,
6911 union iwreq_data *wrqu, char *extra)
6913 struct ipw2100_priv *priv = ieee80211_priv(dev);
6914 struct iw_freq *fwrq = &wrqu->freq;
6917 if (priv->ieee->iw_mode == IW_MODE_INFRA)
6920 down(&priv->action_sem);
6921 if (!(priv->status & STATUS_INITIALIZED)) {
6926 /* if setting by freq convert to channel */
6928 if ((fwrq->m >= (int) 2.412e8 &&
6929 fwrq->m <= (int) 2.487e8)) {
6930 int f = fwrq->m / 100000;
6933 while ((c < REG_MAX_CHANNEL) &&
6934 (f != ipw2100_frequencies[c]))
6937 /* hack to fall through */
6943 if (fwrq->e > 0 || fwrq->m > 1000)
6945 else { /* Set the channel */
6946 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
6947 err = ipw2100_set_channel(priv, fwrq->m, 0);
6951 up(&priv->action_sem);
6956 static int ipw2100_wx_get_freq(struct net_device *dev,
6957 struct iw_request_info *info,
6958 union iwreq_data *wrqu, char *extra)
6961 * This can be called at any time. No action lock required
6964 struct ipw2100_priv *priv = ieee80211_priv(dev);
6968 /* If we are associated, trying to associate, or have a statically
6969 * configured CHANNEL then return that; otherwise return ANY */
6970 if (priv->config & CFG_STATIC_CHANNEL ||
6971 priv->status & STATUS_ASSOCIATED)
6972 wrqu->freq.m = priv->channel;
6976 IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
6981 static int ipw2100_wx_set_mode(struct net_device *dev,
6982 struct iw_request_info *info,
6983 union iwreq_data *wrqu, char *extra)
6985 struct ipw2100_priv *priv = ieee80211_priv(dev);
6988 IPW_DEBUG_WX("SET Mode -> %d \n", wrqu->mode);
6990 if (wrqu->mode == priv->ieee->iw_mode)
6993 down(&priv->action_sem);
6994 if (!(priv->status & STATUS_INITIALIZED)) {
6999 switch (wrqu->mode) {
7000 #ifdef CONFIG_IPW2100_MONITOR
7001 case IW_MODE_MONITOR:
7002 err = ipw2100_switch_mode(priv, IW_MODE_MONITOR);
7004 #endif /* CONFIG_IPW2100_MONITOR */
7006 err = ipw2100_switch_mode(priv, IW_MODE_ADHOC);
7011 err = ipw2100_switch_mode(priv, IW_MODE_INFRA);
7016 up(&priv->action_sem);
7020 static int ipw2100_wx_get_mode(struct net_device *dev,
7021 struct iw_request_info *info,
7022 union iwreq_data *wrqu, char *extra)
7025 * This can be called at any time. No action lock required
7028 struct ipw2100_priv *priv = ieee80211_priv(dev);
7030 wrqu->mode = priv->ieee->iw_mode;
7031 IPW_DEBUG_WX("GET Mode -> %d\n", wrqu->mode);
7037 #define POWER_MODES 5
7039 /* Values are in microsecond */
7040 const s32 timeout_duration[POWER_MODES] = {
7048 const s32 period_duration[POWER_MODES] = {
7056 static int ipw2100_wx_get_range(struct net_device *dev,
7057 struct iw_request_info *info,
7058 union iwreq_data *wrqu, char *extra)
7061 * This can be called at any time. No action lock required
7064 struct ipw2100_priv *priv = ieee80211_priv(dev);
7065 struct iw_range *range = (struct iw_range *)extra;
7069 wrqu->data.length = sizeof(*range);
7070 memset(range, 0, sizeof(*range));
7072 /* Let's try to keep this struct in the same order as in
7073 * linux/include/wireless.h
7076 /* TODO: See what values we can set, and remove the ones we can't
7077 * set, or fill them with some default data.
7080 /* ~5 Mb/s real (802.11b) */
7081 range->throughput = 5 * 1000 * 1000;
7083 // range->sensitivity; /* signal level threshold range */
7085 range->max_qual.qual = 100;
7086 /* TODO: Find real max RSSI and stick here */
7087 range->max_qual.level = 0;
7088 range->max_qual.noise = 0;
7089 range->max_qual.updated = 7; /* Updated all three */
7091 range->avg_qual.qual = 70; /* > 8% missed beacons is 'bad' */
7092 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
7093 range->avg_qual.level = 20 + IPW2100_RSSI_TO_DBM;
7094 range->avg_qual.noise = 0;
7095 range->avg_qual.updated = 7; /* Updated all three */
7097 range->num_bitrates = RATE_COUNT;
7099 for (i = 0; i < RATE_COUNT && i < IW_MAX_BITRATES; i++) {
7100 range->bitrate[i] = ipw2100_rates_11b[i];
7103 range->min_rts = MIN_RTS_THRESHOLD;
7104 range->max_rts = MAX_RTS_THRESHOLD;
7105 range->min_frag = MIN_FRAG_THRESHOLD;
7106 range->max_frag = MAX_FRAG_THRESHOLD;
7108 range->min_pmp = period_duration[0]; /* Minimal PM period */
7109 range->max_pmp = period_duration[POWER_MODES-1];/* Maximal PM period */
7110 range->min_pmt = timeout_duration[POWER_MODES-1]; /* Minimal PM timeout */
7111 range->max_pmt = timeout_duration[0];/* Maximal PM timeout */
7113 /* How to decode max/min PM period */
7114 range->pmp_flags = IW_POWER_PERIOD;
7115 /* How to decode max/min PM period */
7116 range->pmt_flags = IW_POWER_TIMEOUT;
7117 /* What PM options are supported */
7118 range->pm_capa = IW_POWER_TIMEOUT | IW_POWER_PERIOD;
7120 range->encoding_size[0] = 5;
7121 range->encoding_size[1] = 13; /* Different token sizes */
7122 range->num_encoding_sizes = 2; /* Number of entry in the list */
7123 range->max_encoding_tokens = WEP_KEYS; /* Max number of tokens */
7124 // range->encoding_login_index; /* token index for login token */
7126 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7127 range->txpower_capa = IW_TXPOW_DBM;
7128 range->num_txpower = IW_MAX_TXPOWER;
7129 for (i = 0, level = (IPW_TX_POWER_MAX_DBM * 16); i < IW_MAX_TXPOWER;
7130 i++, level -= ((IPW_TX_POWER_MAX_DBM - IPW_TX_POWER_MIN_DBM) * 16) /
7131 (IW_MAX_TXPOWER - 1))
7132 range->txpower[i] = level / 16;
7134 range->txpower_capa = 0;
7135 range->num_txpower = 0;
7139 /* Set the Wireless Extension versions */
7140 range->we_version_compiled = WIRELESS_EXT;
7141 range->we_version_source = 16;
7143 // range->retry_capa; /* What retry options are supported */
7144 // range->retry_flags; /* How to decode max/min retry limit */
7145 // range->r_time_flags; /* How to decode max/min retry life */
7146 // range->min_retry; /* Minimal number of retries */
7147 // range->max_retry; /* Maximal number of retries */
7148 // range->min_r_time; /* Minimal retry lifetime */
7149 // range->max_r_time; /* Maximal retry lifetime */
7151 range->num_channels = FREQ_COUNT;
7154 for (i = 0; i < FREQ_COUNT; i++) {
7155 // TODO: Include only legal frequencies for some countries
7156 // if (local->channel_mask & (1 << i)) {
7157 range->freq[val].i = i + 1;
7158 range->freq[val].m = ipw2100_frequencies[i] * 100000;
7159 range->freq[val].e = 1;
7162 if (val == IW_MAX_FREQUENCIES)
7165 range->num_frequency = val;
7167 IPW_DEBUG_WX("GET Range\n");
7172 static int ipw2100_wx_set_wap(struct net_device *dev,
7173 struct iw_request_info *info,
7174 union iwreq_data *wrqu, char *extra)
7176 struct ipw2100_priv *priv = ieee80211_priv(dev);
7179 static const unsigned char any[] = {
7180 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
7182 static const unsigned char off[] = {
7183 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
7187 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
7190 down(&priv->action_sem);
7191 if (!(priv->status & STATUS_INITIALIZED)) {
7196 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
7197 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
7198 /* we disable mandatory BSSID association */
7199 IPW_DEBUG_WX("exit - disable mandatory BSSID\n");
7200 priv->config &= ~CFG_STATIC_BSSID;
7201 err = ipw2100_set_mandatory_bssid(priv, NULL, 0);
7205 priv->config |= CFG_STATIC_BSSID;
7206 memcpy(priv->mandatory_bssid_mac, wrqu->ap_addr.sa_data, ETH_ALEN);
7208 err = ipw2100_set_mandatory_bssid(priv, wrqu->ap_addr.sa_data, 0);
7210 IPW_DEBUG_WX("SET BSSID -> %02X:%02X:%02X:%02X:%02X:%02X\n",
7211 wrqu->ap_addr.sa_data[0] & 0xff,
7212 wrqu->ap_addr.sa_data[1] & 0xff,
7213 wrqu->ap_addr.sa_data[2] & 0xff,
7214 wrqu->ap_addr.sa_data[3] & 0xff,
7215 wrqu->ap_addr.sa_data[4] & 0xff,
7216 wrqu->ap_addr.sa_data[5] & 0xff);
7219 up(&priv->action_sem);
7223 static int ipw2100_wx_get_wap(struct net_device *dev,
7224 struct iw_request_info *info,
7225 union iwreq_data *wrqu, char *extra)
7228 * This can be called at any time. No action lock required
7231 struct ipw2100_priv *priv = ieee80211_priv(dev);
7233 /* If we are associated, trying to associate, or have a statically
7234 * configured BSSID then return that; otherwise return ANY */
7235 if (priv->config & CFG_STATIC_BSSID ||
7236 priv->status & STATUS_ASSOCIATED) {
7237 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
7238 memcpy(wrqu->ap_addr.sa_data, &priv->bssid, ETH_ALEN);
7240 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
7242 IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n",
7243 MAC_ARG(wrqu->ap_addr.sa_data));
7247 static int ipw2100_wx_set_essid(struct net_device *dev,
7248 struct iw_request_info *info,
7249 union iwreq_data *wrqu, char *extra)
7251 struct ipw2100_priv *priv = ieee80211_priv(dev);
7252 char *essid = ""; /* ANY */
7256 down(&priv->action_sem);
7257 if (!(priv->status & STATUS_INITIALIZED)) {
7262 if (wrqu->essid.flags && wrqu->essid.length) {
7263 length = wrqu->essid.length - 1;
7268 IPW_DEBUG_WX("Setting ESSID to ANY\n");
7269 priv->config &= ~CFG_STATIC_ESSID;
7270 err = ipw2100_set_essid(priv, NULL, 0, 0);
7274 length = min(length, IW_ESSID_MAX_SIZE);
7276 priv->config |= CFG_STATIC_ESSID;
7278 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
7279 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
7284 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length),
7287 priv->essid_len = length;
7288 memcpy(priv->essid, essid, priv->essid_len);
7290 err = ipw2100_set_essid(priv, essid, length, 0);
7293 up(&priv->action_sem);
7297 static int ipw2100_wx_get_essid(struct net_device *dev,
7298 struct iw_request_info *info,
7299 union iwreq_data *wrqu, char *extra)
7302 * This can be called at any time. No action lock required
7305 struct ipw2100_priv *priv = ieee80211_priv(dev);
7307 /* If we are associated, trying to associate, or have a statically
7308 * configured ESSID then return that; otherwise return ANY */
7309 if (priv->config & CFG_STATIC_ESSID ||
7310 priv->status & STATUS_ASSOCIATED) {
7311 IPW_DEBUG_WX("Getting essid: '%s'\n",
7312 escape_essid(priv->essid, priv->essid_len));
7313 memcpy(extra, priv->essid, priv->essid_len);
7314 wrqu->essid.length = priv->essid_len;
7315 wrqu->essid.flags = 1; /* active */
7317 IPW_DEBUG_WX("Getting essid: ANY\n");
7318 wrqu->essid.length = 0;
7319 wrqu->essid.flags = 0; /* active */
7325 static int ipw2100_wx_set_nick(struct net_device *dev,
7326 struct iw_request_info *info,
7327 union iwreq_data *wrqu, char *extra)
7330 * This can be called at any time. No action lock required
7333 struct ipw2100_priv *priv = ieee80211_priv(dev);
7335 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
7338 wrqu->data.length = min((size_t)wrqu->data.length, sizeof(priv->nick));
7339 memset(priv->nick, 0, sizeof(priv->nick));
7340 memcpy(priv->nick, extra, wrqu->data.length);
7342 IPW_DEBUG_WX("SET Nickname -> %s \n", priv->nick);
7347 static int ipw2100_wx_get_nick(struct net_device *dev,
7348 struct iw_request_info *info,
7349 union iwreq_data *wrqu, char *extra)
7352 * This can be called at any time. No action lock required
7355 struct ipw2100_priv *priv = ieee80211_priv(dev);
7357 wrqu->data.length = strlen(priv->nick) + 1;
7358 memcpy(extra, priv->nick, wrqu->data.length);
7359 wrqu->data.flags = 1; /* active */
7361 IPW_DEBUG_WX("GET Nickname -> %s \n", extra);
7366 static int ipw2100_wx_set_rate(struct net_device *dev,
7367 struct iw_request_info *info,
7368 union iwreq_data *wrqu, char *extra)
7370 struct ipw2100_priv *priv = ieee80211_priv(dev);
7371 u32 target_rate = wrqu->bitrate.value;
7375 down(&priv->action_sem);
7376 if (!(priv->status & STATUS_INITIALIZED)) {
7383 if (target_rate == 1000000 ||
7384 (!wrqu->bitrate.fixed && target_rate > 1000000))
7385 rate |= TX_RATE_1_MBIT;
7386 if (target_rate == 2000000 ||
7387 (!wrqu->bitrate.fixed && target_rate > 2000000))
7388 rate |= TX_RATE_2_MBIT;
7389 if (target_rate == 5500000 ||
7390 (!wrqu->bitrate.fixed && target_rate > 5500000))
7391 rate |= TX_RATE_5_5_MBIT;
7392 if (target_rate == 11000000 ||
7393 (!wrqu->bitrate.fixed && target_rate > 11000000))
7394 rate |= TX_RATE_11_MBIT;
7396 rate = DEFAULT_TX_RATES;
7398 err = ipw2100_set_tx_rates(priv, rate, 0);
7400 IPW_DEBUG_WX("SET Rate -> %04X \n", rate);
7402 up(&priv->action_sem);
7407 static int ipw2100_wx_get_rate(struct net_device *dev,
7408 struct iw_request_info *info,
7409 union iwreq_data *wrqu, char *extra)
7411 struct ipw2100_priv *priv = ieee80211_priv(dev);
7413 int len = sizeof(val);
7416 if (!(priv->status & STATUS_ENABLED) ||
7417 priv->status & STATUS_RF_KILL_MASK ||
7418 !(priv->status & STATUS_ASSOCIATED)) {
7419 wrqu->bitrate.value = 0;
7423 down(&priv->action_sem);
7424 if (!(priv->status & STATUS_INITIALIZED)) {
7429 err = ipw2100_get_ordinal(priv, IPW_ORD_CURRENT_TX_RATE, &val, &len);
7431 IPW_DEBUG_WX("failed querying ordinals.\n");
7435 switch (val & TX_RATE_MASK) {
7436 case TX_RATE_1_MBIT:
7437 wrqu->bitrate.value = 1000000;
7439 case TX_RATE_2_MBIT:
7440 wrqu->bitrate.value = 2000000;
7442 case TX_RATE_5_5_MBIT:
7443 wrqu->bitrate.value = 5500000;
7445 case TX_RATE_11_MBIT:
7446 wrqu->bitrate.value = 11000000;
7449 wrqu->bitrate.value = 0;
7452 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
7455 up(&priv->action_sem);
7459 static int ipw2100_wx_set_rts(struct net_device *dev,
7460 struct iw_request_info *info,
7461 union iwreq_data *wrqu, char *extra)
7463 struct ipw2100_priv *priv = ieee80211_priv(dev);
7466 /* Auto RTS not yet supported */
7467 if (wrqu->rts.fixed == 0)
7470 down(&priv->action_sem);
7471 if (!(priv->status & STATUS_INITIALIZED)) {
7476 if (wrqu->rts.disabled)
7477 value = priv->rts_threshold | RTS_DISABLED;
7479 if (wrqu->rts.value < 1 ||
7480 wrqu->rts.value > 2304) {
7484 value = wrqu->rts.value;
7487 err = ipw2100_set_rts_threshold(priv, value);
7489 IPW_DEBUG_WX("SET RTS Threshold -> 0x%08X \n", value);
7491 up(&priv->action_sem);
7495 static int ipw2100_wx_get_rts(struct net_device *dev,
7496 struct iw_request_info *info,
7497 union iwreq_data *wrqu, char *extra)
7500 * This can be called at any time. No action lock required
7503 struct ipw2100_priv *priv = ieee80211_priv(dev);
7505 wrqu->rts.value = priv->rts_threshold & ~RTS_DISABLED;
7506 wrqu->rts.fixed = 1; /* no auto select */
7508 /* If RTS is set to the default value, then it is disabled */
7509 wrqu->rts.disabled = (priv->rts_threshold & RTS_DISABLED) ? 1 : 0;
7511 IPW_DEBUG_WX("GET RTS Threshold -> 0x%08X \n", wrqu->rts.value);
7516 static int ipw2100_wx_set_txpow(struct net_device *dev,
7517 struct iw_request_info *info,
7518 union iwreq_data *wrqu, char *extra)
7520 struct ipw2100_priv *priv = ieee80211_priv(dev);
7523 if (priv->ieee->iw_mode != IW_MODE_ADHOC)
7526 if (wrqu->txpower.disabled == 1 || wrqu->txpower.fixed == 0)
7527 value = IPW_TX_POWER_DEFAULT;
7529 if (wrqu->txpower.value < IPW_TX_POWER_MIN_DBM ||
7530 wrqu->txpower.value > IPW_TX_POWER_MAX_DBM)
7533 value = (wrqu->txpower.value - IPW_TX_POWER_MIN_DBM) * 16 /
7534 (IPW_TX_POWER_MAX_DBM - IPW_TX_POWER_MIN_DBM);
7537 down(&priv->action_sem);
7538 if (!(priv->status & STATUS_INITIALIZED)) {
7543 err = ipw2100_set_tx_power(priv, value);
7545 IPW_DEBUG_WX("SET TX Power -> %d \n", value);
7548 up(&priv->action_sem);
7552 static int ipw2100_wx_get_txpow(struct net_device *dev,
7553 struct iw_request_info *info,
7554 union iwreq_data *wrqu, char *extra)
7557 * This can be called at any time. No action lock required
7560 struct ipw2100_priv *priv = ieee80211_priv(dev);
7562 if (priv->ieee->iw_mode != IW_MODE_ADHOC) {
7563 wrqu->power.disabled = 1;
7567 if (priv->tx_power == IPW_TX_POWER_DEFAULT) {
7568 wrqu->power.fixed = 0;
7569 wrqu->power.value = IPW_TX_POWER_MAX_DBM;
7570 wrqu->power.disabled = 1;
7572 wrqu->power.disabled = 0;
7573 wrqu->power.fixed = 1;
7576 (IPW_TX_POWER_MAX_DBM - IPW_TX_POWER_MIN_DBM)) /
7577 (IPW_TX_POWER_MAX - IPW_TX_POWER_MIN) +
7578 IPW_TX_POWER_MIN_DBM;
7581 wrqu->power.flags = IW_TXPOW_DBM;
7583 IPW_DEBUG_WX("GET TX Power -> %d \n", wrqu->power.value);
7588 static int ipw2100_wx_set_frag(struct net_device *dev,
7589 struct iw_request_info *info,
7590 union iwreq_data *wrqu, char *extra)
7593 * This can be called at any time. No action lock required
7596 struct ipw2100_priv *priv = ieee80211_priv(dev);
7598 if (!wrqu->frag.fixed)
7601 if (wrqu->frag.disabled) {
7602 priv->frag_threshold |= FRAG_DISABLED;
7603 priv->ieee->fts = DEFAULT_FTS;
7605 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
7606 wrqu->frag.value > MAX_FRAG_THRESHOLD)
7609 priv->ieee->fts = wrqu->frag.value & ~0x1;
7610 priv->frag_threshold = priv->ieee->fts;
7613 IPW_DEBUG_WX("SET Frag Threshold -> %d \n", priv->ieee->fts);
7618 static int ipw2100_wx_get_frag(struct net_device *dev,
7619 struct iw_request_info *info,
7620 union iwreq_data *wrqu, char *extra)
7623 * This can be called at any time. No action lock required
7626 struct ipw2100_priv *priv = ieee80211_priv(dev);
7627 wrqu->frag.value = priv->frag_threshold & ~FRAG_DISABLED;
7628 wrqu->frag.fixed = 0; /* no auto select */
7629 wrqu->frag.disabled = (priv->frag_threshold & FRAG_DISABLED) ? 1 : 0;
7631 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
7636 static int ipw2100_wx_set_retry(struct net_device *dev,
7637 struct iw_request_info *info,
7638 union iwreq_data *wrqu, char *extra)
7640 struct ipw2100_priv *priv = ieee80211_priv(dev);
7643 if (wrqu->retry.flags & IW_RETRY_LIFETIME ||
7644 wrqu->retry.disabled)
7647 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
7650 down(&priv->action_sem);
7651 if (!(priv->status & STATUS_INITIALIZED)) {
7656 if (wrqu->retry.flags & IW_RETRY_MIN) {
7657 err = ipw2100_set_short_retry(priv, wrqu->retry.value);
7658 IPW_DEBUG_WX("SET Short Retry Limit -> %d \n",
7663 if (wrqu->retry.flags & IW_RETRY_MAX) {
7664 err = ipw2100_set_long_retry(priv, wrqu->retry.value);
7665 IPW_DEBUG_WX("SET Long Retry Limit -> %d \n",
7670 err = ipw2100_set_short_retry(priv, wrqu->retry.value);
7672 err = ipw2100_set_long_retry(priv, wrqu->retry.value);
7674 IPW_DEBUG_WX("SET Both Retry Limits -> %d \n", wrqu->retry.value);
7677 up(&priv->action_sem);
7681 static int ipw2100_wx_get_retry(struct net_device *dev,
7682 struct iw_request_info *info,
7683 union iwreq_data *wrqu, char *extra)
7686 * This can be called at any time. No action lock required
7689 struct ipw2100_priv *priv = ieee80211_priv(dev);
7691 wrqu->retry.disabled = 0; /* can't be disabled */
7693 if ((wrqu->retry.flags & IW_RETRY_TYPE) ==
7697 if (wrqu->retry.flags & IW_RETRY_MAX) {
7698 wrqu->retry.flags = IW_RETRY_LIMIT & IW_RETRY_MAX;
7699 wrqu->retry.value = priv->long_retry_limit;
7702 (priv->short_retry_limit !=
7703 priv->long_retry_limit) ?
7704 IW_RETRY_LIMIT & IW_RETRY_MIN : IW_RETRY_LIMIT;
7706 wrqu->retry.value = priv->short_retry_limit;
7709 IPW_DEBUG_WX("GET Retry -> %d \n", wrqu->retry.value);
7714 static int ipw2100_wx_set_scan(struct net_device *dev,
7715 struct iw_request_info *info,
7716 union iwreq_data *wrqu, char *extra)
7718 struct ipw2100_priv *priv = ieee80211_priv(dev);
7721 down(&priv->action_sem);
7722 if (!(priv->status & STATUS_INITIALIZED)) {
7727 IPW_DEBUG_WX("Initiating scan...\n");
7728 if (ipw2100_set_scan_options(priv) ||
7729 ipw2100_start_scan(priv)) {
7730 IPW_DEBUG_WX("Start scan failed.\n");
7732 /* TODO: Mark a scan as pending so when hardware initialized
7737 up(&priv->action_sem);
7741 static int ipw2100_wx_get_scan(struct net_device *dev,
7742 struct iw_request_info *info,
7743 union iwreq_data *wrqu, char *extra)
7746 * This can be called at any time. No action lock required
7749 struct ipw2100_priv *priv = ieee80211_priv(dev);
7750 return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra);
7755 * Implementation based on code in hostap-driver v0.1.3 hostap_ioctl.c
7757 static int ipw2100_wx_set_encode(struct net_device *dev,
7758 struct iw_request_info *info,
7759 union iwreq_data *wrqu, char *key)
7762 * No check of STATUS_INITIALIZED required
7765 struct ipw2100_priv *priv = ieee80211_priv(dev);
7766 return ieee80211_wx_set_encode(priv->ieee, info, wrqu, key);
7769 static int ipw2100_wx_get_encode(struct net_device *dev,
7770 struct iw_request_info *info,
7771 union iwreq_data *wrqu, char *key)
7774 * This can be called at any time. No action lock required
7777 struct ipw2100_priv *priv = ieee80211_priv(dev);
7778 return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key);
7781 static int ipw2100_wx_set_power(struct net_device *dev,
7782 struct iw_request_info *info,
7783 union iwreq_data *wrqu, char *extra)
7785 struct ipw2100_priv *priv = ieee80211_priv(dev);
7788 down(&priv->action_sem);
7789 if (!(priv->status & STATUS_INITIALIZED)) {
7794 if (wrqu->power.disabled) {
7795 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
7796 err = ipw2100_set_power_mode(priv, IPW_POWER_MODE_CAM);
7797 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
7801 switch (wrqu->power.flags & IW_POWER_MODE) {
7802 case IW_POWER_ON: /* If not specified */
7803 case IW_POWER_MODE: /* If set all mask */
7804 case IW_POWER_ALL_R: /* If explicitely state all */
7806 default: /* Otherwise we don't support it */
7807 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
7813 /* If the user hasn't specified a power management mode yet, default
7815 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
7816 err = ipw2100_set_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
7818 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n",
7822 up(&priv->action_sem);
7827 static int ipw2100_wx_get_power(struct net_device *dev,
7828 struct iw_request_info *info,
7829 union iwreq_data *wrqu, char *extra)
7832 * This can be called at any time. No action lock required
7835 struct ipw2100_priv *priv = ieee80211_priv(dev);
7837 if (!(priv->power_mode & IPW_POWER_ENABLED)) {
7838 wrqu->power.disabled = 1;
7840 wrqu->power.disabled = 0;
7841 wrqu->power.flags = 0;
7844 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
7855 #ifdef CONFIG_IPW2100_MONITOR
7856 static int ipw2100_wx_set_promisc(struct net_device *dev,
7857 struct iw_request_info *info,
7858 union iwreq_data *wrqu, char *extra)
7860 struct ipw2100_priv *priv = ieee80211_priv(dev);
7861 int *parms = (int *)extra;
7862 int enable = (parms[0] > 0);
7865 down(&priv->action_sem);
7866 if (!(priv->status & STATUS_INITIALIZED)) {
7872 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7873 err = ipw2100_set_channel(priv, parms[1], 0);
7876 priv->channel = parms[1];
7877 err = ipw2100_switch_mode(priv, IW_MODE_MONITOR);
7879 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
7880 err = ipw2100_switch_mode(priv, priv->last_mode);
7883 up(&priv->action_sem);
7887 static int ipw2100_wx_reset(struct net_device *dev,
7888 struct iw_request_info *info,
7889 union iwreq_data *wrqu, char *extra)
7891 struct ipw2100_priv *priv = ieee80211_priv(dev);
7892 if (priv->status & STATUS_INITIALIZED)
7893 schedule_reset(priv);
7899 static int ipw2100_wx_set_powermode(struct net_device *dev,
7900 struct iw_request_info *info,
7901 union iwreq_data *wrqu, char *extra)
7903 struct ipw2100_priv *priv = ieee80211_priv(dev);
7904 int err = 0, mode = *(int *)extra;
7906 down(&priv->action_sem);
7907 if (!(priv->status & STATUS_INITIALIZED)) {
7912 if ((mode < 1) || (mode > POWER_MODES))
7913 mode = IPW_POWER_AUTO;
7915 if (priv->power_mode != mode)
7916 err = ipw2100_set_power_mode(priv, mode);
7918 up(&priv->action_sem);
7922 #define MAX_POWER_STRING 80
7923 static int ipw2100_wx_get_powermode(struct net_device *dev,
7924 struct iw_request_info *info,
7925 union iwreq_data *wrqu, char *extra)
7928 * This can be called at any time. No action lock required
7931 struct ipw2100_priv *priv = ieee80211_priv(dev);
7932 int level = IPW_POWER_LEVEL(priv->power_mode);
7933 s32 timeout, period;
7935 if (!(priv->power_mode & IPW_POWER_ENABLED)) {
7936 snprintf(extra, MAX_POWER_STRING,
7937 "Power save level: %d (Off)", level);
7940 case IPW_POWER_MODE_CAM:
7941 snprintf(extra, MAX_POWER_STRING,
7942 "Power save level: %d (None)", level);
7944 case IPW_POWER_AUTO:
7945 snprintf(extra, MAX_POWER_STRING,
7946 "Power save level: %d (Auto)", 0);
7949 timeout = timeout_duration[level - 1] / 1000;
7950 period = period_duration[level - 1] / 1000;
7951 snprintf(extra, MAX_POWER_STRING,
7952 "Power save level: %d "
7953 "(Timeout %dms, Period %dms)",
7954 level, timeout, period);
7958 wrqu->data.length = strlen(extra) + 1;
7964 static int ipw2100_wx_set_preamble(struct net_device *dev,
7965 struct iw_request_info *info,
7966 union iwreq_data *wrqu, char *extra)
7968 struct ipw2100_priv *priv = ieee80211_priv(dev);
7969 int err, mode = *(int *)extra;
7971 down(&priv->action_sem);
7972 if (!(priv->status & STATUS_INITIALIZED)) {
7978 priv->config |= CFG_LONG_PREAMBLE;
7980 priv->config &= ~CFG_LONG_PREAMBLE;
7986 err = ipw2100_system_config(priv, 0);
7989 up(&priv->action_sem);
7993 static int ipw2100_wx_get_preamble(struct net_device *dev,
7994 struct iw_request_info *info,
7995 union iwreq_data *wrqu, char *extra)
7998 * This can be called at any time. No action lock required
8001 struct ipw2100_priv *priv = ieee80211_priv(dev);
8003 if (priv->config & CFG_LONG_PREAMBLE)
8004 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
8006 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
8011 static iw_handler ipw2100_wx_handlers[] =
8013 NULL, /* SIOCSIWCOMMIT */
8014 ipw2100_wx_get_name, /* SIOCGIWNAME */
8015 NULL, /* SIOCSIWNWID */
8016 NULL, /* SIOCGIWNWID */
8017 ipw2100_wx_set_freq, /* SIOCSIWFREQ */
8018 ipw2100_wx_get_freq, /* SIOCGIWFREQ */
8019 ipw2100_wx_set_mode, /* SIOCSIWMODE */
8020 ipw2100_wx_get_mode, /* SIOCGIWMODE */
8021 NULL, /* SIOCSIWSENS */
8022 NULL, /* SIOCGIWSENS */
8023 NULL, /* SIOCSIWRANGE */
8024 ipw2100_wx_get_range, /* SIOCGIWRANGE */
8025 NULL, /* SIOCSIWPRIV */
8026 NULL, /* SIOCGIWPRIV */
8027 NULL, /* SIOCSIWSTATS */
8028 NULL, /* SIOCGIWSTATS */
8029 NULL, /* SIOCSIWSPY */
8030 NULL, /* SIOCGIWSPY */
8031 NULL, /* SIOCGIWTHRSPY */
8032 NULL, /* SIOCWIWTHRSPY */
8033 ipw2100_wx_set_wap, /* SIOCSIWAP */
8034 ipw2100_wx_get_wap, /* SIOCGIWAP */
8035 NULL, /* -- hole -- */
8036 NULL, /* SIOCGIWAPLIST -- deprecated */
8037 ipw2100_wx_set_scan, /* SIOCSIWSCAN */
8038 ipw2100_wx_get_scan, /* SIOCGIWSCAN */
8039 ipw2100_wx_set_essid, /* SIOCSIWESSID */
8040 ipw2100_wx_get_essid, /* SIOCGIWESSID */
8041 ipw2100_wx_set_nick, /* SIOCSIWNICKN */
8042 ipw2100_wx_get_nick, /* SIOCGIWNICKN */
8043 NULL, /* -- hole -- */
8044 NULL, /* -- hole -- */
8045 ipw2100_wx_set_rate, /* SIOCSIWRATE */
8046 ipw2100_wx_get_rate, /* SIOCGIWRATE */
8047 ipw2100_wx_set_rts, /* SIOCSIWRTS */
8048 ipw2100_wx_get_rts, /* SIOCGIWRTS */
8049 ipw2100_wx_set_frag, /* SIOCSIWFRAG */
8050 ipw2100_wx_get_frag, /* SIOCGIWFRAG */
8051 ipw2100_wx_set_txpow, /* SIOCSIWTXPOW */
8052 ipw2100_wx_get_txpow, /* SIOCGIWTXPOW */
8053 ipw2100_wx_set_retry, /* SIOCSIWRETRY */
8054 ipw2100_wx_get_retry, /* SIOCGIWRETRY */
8055 ipw2100_wx_set_encode, /* SIOCSIWENCODE */
8056 ipw2100_wx_get_encode, /* SIOCGIWENCODE */
8057 ipw2100_wx_set_power, /* SIOCSIWPOWER */
8058 ipw2100_wx_get_power, /* SIOCGIWPOWER */
8061 #define IPW2100_PRIV_SET_MONITOR SIOCIWFIRSTPRIV
8062 #define IPW2100_PRIV_RESET SIOCIWFIRSTPRIV+1
8063 #define IPW2100_PRIV_SET_POWER SIOCIWFIRSTPRIV+2
8064 #define IPW2100_PRIV_GET_POWER SIOCIWFIRSTPRIV+3
8065 #define IPW2100_PRIV_SET_LONGPREAMBLE SIOCIWFIRSTPRIV+4
8066 #define IPW2100_PRIV_GET_LONGPREAMBLE SIOCIWFIRSTPRIV+5
8068 static const struct iw_priv_args ipw2100_private_args[] = {
8070 #ifdef CONFIG_IPW2100_MONITOR
8072 IPW2100_PRIV_SET_MONITOR,
8073 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"
8077 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"
8079 #endif /* CONFIG_IPW2100_MONITOR */
8082 IPW2100_PRIV_SET_POWER,
8083 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_power"
8086 IPW2100_PRIV_GET_POWER,
8087 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_POWER_STRING, "get_power"
8090 IPW2100_PRIV_SET_LONGPREAMBLE,
8091 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_preamble"
8094 IPW2100_PRIV_GET_LONGPREAMBLE,
8095 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, "get_preamble"
8099 static iw_handler ipw2100_private_handler[] = {
8100 #ifdef CONFIG_IPW2100_MONITOR
8101 ipw2100_wx_set_promisc,
8103 #else /* CONFIG_IPW2100_MONITOR */
8106 #endif /* CONFIG_IPW2100_MONITOR */
8107 ipw2100_wx_set_powermode,
8108 ipw2100_wx_get_powermode,
8109 ipw2100_wx_set_preamble,
8110 ipw2100_wx_get_preamble,
8113 struct iw_handler_def ipw2100_wx_handler_def =
8115 .standard = ipw2100_wx_handlers,
8116 .num_standard = sizeof(ipw2100_wx_handlers) / sizeof(iw_handler),
8117 .num_private = sizeof(ipw2100_private_handler) / sizeof(iw_handler),
8118 .num_private_args = sizeof(ipw2100_private_args) /
8119 sizeof(struct iw_priv_args),
8120 .private = (iw_handler *)ipw2100_private_handler,
8121 .private_args = (struct iw_priv_args *)ipw2100_private_args,
8125 * Get wireless statistics.
8126 * Called by /proc/net/wireless
8127 * Also called by SIOCGIWSTATS
8129 struct iw_statistics *ipw2100_wx_wireless_stats(struct net_device * dev)
8143 struct ipw2100_priv *priv = ieee80211_priv(dev);
8144 struct iw_statistics *wstats;
8145 u32 rssi, quality, tx_retries, missed_beacons, tx_failures;
8146 u32 ord_len = sizeof(u32);
8149 return (struct iw_statistics *) NULL;
8151 wstats = &priv->wstats;
8153 /* if hw is disabled, then ipw2100_get_ordinal() can't be called.
8154 * ipw2100_wx_wireless_stats seems to be called before fw is
8155 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
8156 * and associated; if not associcated, the values are all meaningless
8157 * anyway, so set them all to NULL and INVALID */
8158 if (!(priv->status & STATUS_ASSOCIATED)) {
8159 wstats->miss.beacon = 0;
8160 wstats->discard.retries = 0;
8161 wstats->qual.qual = 0;
8162 wstats->qual.level = 0;
8163 wstats->qual.noise = 0;
8164 wstats->qual.updated = 7;
8165 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
8166 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
8170 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_PERCENT_MISSED_BCNS,
8171 &missed_beacons, &ord_len))
8172 goto fail_get_ordinal;
8174 /* If we don't have a connection the quality and level is 0*/
8175 if (!(priv->status & STATUS_ASSOCIATED)) {
8176 wstats->qual.qual = 0;
8177 wstats->qual.level = 0;
8179 if (ipw2100_get_ordinal(priv, IPW_ORD_RSSI_AVG_CURR,
8181 goto fail_get_ordinal;
8182 wstats->qual.level = rssi + IPW2100_RSSI_TO_DBM;
8184 rssi_qual = rssi * POOR / 10;
8186 rssi_qual = (rssi - 10) * (FAIR - POOR) / 5 + POOR;
8188 rssi_qual = (rssi - 15) * (GOOD - FAIR) / 5 + FAIR;
8190 rssi_qual = (rssi - 20) * (VERY_GOOD - GOOD) /
8193 rssi_qual = (rssi - 30) * (PERFECT - VERY_GOOD) /
8196 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_PERCENT_RETRIES,
8197 &tx_retries, &ord_len))
8198 goto fail_get_ordinal;
8200 if (tx_retries > 75)
8201 tx_qual = (90 - tx_retries) * POOR / 15;
8202 else if (tx_retries > 70)
8203 tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
8204 else if (tx_retries > 65)
8205 tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
8206 else if (tx_retries > 50)
8207 tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
8210 tx_qual = (50 - tx_retries) *
8211 (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
8213 if (missed_beacons > 50)
8214 beacon_qual = (60 - missed_beacons) * POOR / 10;
8215 else if (missed_beacons > 40)
8216 beacon_qual = (50 - missed_beacons) * (FAIR - POOR) /
8218 else if (missed_beacons > 32)
8219 beacon_qual = (40 - missed_beacons) * (GOOD - FAIR) /
8221 else if (missed_beacons > 20)
8222 beacon_qual = (32 - missed_beacons) *
8223 (VERY_GOOD - GOOD) / 20 + GOOD;
8225 beacon_qual = (20 - missed_beacons) *
8226 (PERFECT - VERY_GOOD) / 20 + VERY_GOOD;
8228 quality = min(beacon_qual, min(tx_qual, rssi_qual));
8230 #ifdef CONFIG_IPW_DEBUG
8231 if (beacon_qual == quality)
8232 IPW_DEBUG_WX("Quality clamped by Missed Beacons\n");
8233 else if (tx_qual == quality)
8234 IPW_DEBUG_WX("Quality clamped by Tx Retries\n");
8235 else if (quality != 100)
8236 IPW_DEBUG_WX("Quality clamped by Signal Strength\n");
8238 IPW_DEBUG_WX("Quality not clamped.\n");
8241 wstats->qual.qual = quality;
8242 wstats->qual.level = rssi + IPW2100_RSSI_TO_DBM;
8245 wstats->qual.noise = 0;
8246 wstats->qual.updated = 7;
8247 wstats->qual.updated |= IW_QUAL_NOISE_INVALID;
8249 /* FIXME: this is percent and not a # */
8250 wstats->miss.beacon = missed_beacons;
8252 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURES,
8253 &tx_failures, &ord_len))
8254 goto fail_get_ordinal;
8255 wstats->discard.retries = tx_failures;
8260 IPW_DEBUG_WX("failed querying ordinals.\n");
8262 return (struct iw_statistics *) NULL;
8265 void ipw2100_wx_event_work(struct ipw2100_priv *priv)
8267 union iwreq_data wrqu;
8270 if (priv->status & STATUS_STOPPING)
8273 down(&priv->action_sem);
8275 IPW_DEBUG_WX("enter\n");
8277 up(&priv->action_sem);
8279 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
8281 /* Fetch BSSID from the hardware */
8282 if (!(priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) ||
8283 priv->status & STATUS_RF_KILL_MASK ||
8284 ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID,
8285 &priv->bssid, &len)) {
8286 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
8288 /* We now have the BSSID, so can finish setting to the full
8289 * associated state */
8290 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
8291 memcpy(&priv->ieee->bssid, priv->bssid, ETH_ALEN);
8292 priv->status &= ~STATUS_ASSOCIATING;
8293 priv->status |= STATUS_ASSOCIATED;
8294 netif_carrier_on(priv->net_dev);
8295 if (netif_queue_stopped(priv->net_dev)) {
8296 IPW_DEBUG_INFO("Waking net queue.\n");
8297 netif_wake_queue(priv->net_dev);
8299 IPW_DEBUG_INFO("Starting net queue.\n");
8300 netif_start_queue(priv->net_dev);
8304 if (!(priv->status & STATUS_ASSOCIATED)) {
8305 IPW_DEBUG_WX("Configuring ESSID\n");
8306 down(&priv->action_sem);
8307 /* This is a disassociation event, so kick the firmware to
8308 * look for another AP */
8309 if (priv->config & CFG_STATIC_ESSID)
8310 ipw2100_set_essid(priv, priv->essid, priv->essid_len, 0);
8312 ipw2100_set_essid(priv, NULL, 0, 0);
8313 up(&priv->action_sem);
8316 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
8319 #define IPW2100_FW_MAJOR_VERSION 1
8320 #define IPW2100_FW_MINOR_VERSION 3
8322 #define IPW2100_FW_MINOR(x) ((x & 0xff) >> 8)
8323 #define IPW2100_FW_MAJOR(x) (x & 0xff)
8325 #define IPW2100_FW_VERSION ((IPW2100_FW_MINOR_VERSION << 8) | \
8326 IPW2100_FW_MAJOR_VERSION)
8328 #define IPW2100_FW_PREFIX "ipw2100-" __stringify(IPW2100_FW_MAJOR_VERSION) \
8329 "." __stringify(IPW2100_FW_MINOR_VERSION)
8331 #define IPW2100_FW_NAME(x) IPW2100_FW_PREFIX "" x ".fw"
8336 BINARY FIRMWARE HEADER FORMAT
8340 2 2 mode == 0:BSS,1:IBSS,2:MONITOR
8343 C fw_len firmware data
8344 12 + fw_len uc_len microcode data
8348 struct ipw2100_fw_header {
8351 unsigned int fw_size;
8352 unsigned int uc_size;
8353 } __attribute__ ((packed));
8357 static int ipw2100_mod_firmware_load(struct ipw2100_fw *fw)
8359 struct ipw2100_fw_header *h =
8360 (struct ipw2100_fw_header *)fw->fw_entry->data;
8362 if (IPW2100_FW_MAJOR(h->version) != IPW2100_FW_MAJOR_VERSION) {
8363 IPW_DEBUG_WARNING("Firmware image not compatible "
8364 "(detected version id of %u). "
8365 "See Documentation/networking/README.ipw2100\n",
8370 fw->version = h->version;
8371 fw->fw.data = fw->fw_entry->data + sizeof(struct ipw2100_fw_header);
8372 fw->fw.size = h->fw_size;
8373 fw->uc.data = fw->fw.data + h->fw_size;
8374 fw->uc.size = h->uc_size;
8380 int ipw2100_get_firmware(struct ipw2100_priv *priv, struct ipw2100_fw *fw)
8385 IPW_DEBUG_INFO("%s: Using hotplug firmware load.\n",
8386 priv->net_dev->name);
8388 switch (priv->ieee->iw_mode) {
8390 fw_name = IPW2100_FW_NAME("-i");
8392 #ifdef CONFIG_IPW2100_MONITOR
8393 case IW_MODE_MONITOR:
8394 fw_name = IPW2100_FW_NAME("-p");
8399 fw_name = IPW2100_FW_NAME("");
8403 rc = request_firmware(&fw->fw_entry, fw_name, &priv->pci_dev->dev);
8407 "%s: Firmware '%s' not available or load failed.\n",
8408 priv->net_dev->name, fw_name);
8411 IPW_DEBUG_INFO("firmware data %p size %zd\n", fw->fw_entry->data,
8412 fw->fw_entry->size);
8414 ipw2100_mod_firmware_load(fw);
8419 void ipw2100_release_firmware(struct ipw2100_priv *priv,
8420 struct ipw2100_fw *fw)
8424 release_firmware(fw->fw_entry);
8425 fw->fw_entry = NULL;
8429 int ipw2100_get_fwversion(struct ipw2100_priv *priv, char *buf, size_t max)
8431 char ver[MAX_FW_VERSION_LEN];
8432 u32 len = MAX_FW_VERSION_LEN;
8435 /* firmware version is an ascii string (max len of 14) */
8436 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_FW_VER_NUM,
8442 for (i = 0; i < len; i++)
8448 int ipw2100_get_ucodeversion(struct ipw2100_priv *priv, char *buf, size_t max)
8451 u32 len = sizeof(ver);
8452 /* microcode version is a 32 bit integer */
8453 if (ipw2100_get_ordinal(priv, IPW_ORD_UCODE_VERSION,
8456 return snprintf(buf, max, "%08X", ver);
8460 * On exit, the firmware will have been freed from the fw list
8462 int ipw2100_fw_download(struct ipw2100_priv *priv, struct ipw2100_fw *fw)
8464 /* firmware is constructed of N contiguous entries, each entry is
8468 * 0 4 address to write to
8469 * 4 2 length of data run
8475 const unsigned char *firmware_data = fw->fw.data;
8476 unsigned int firmware_data_left = fw->fw.size;
8478 while (firmware_data_left > 0) {
8479 addr = *(u32 *)(firmware_data);
8481 firmware_data_left -= 4;
8483 len = *(u16 *)(firmware_data);
8485 firmware_data_left -= 2;
8489 "Invalid firmware run-length of %d bytes\n",
8494 write_nic_memory(priv->net_dev, addr, len, firmware_data);
8495 firmware_data += len;
8496 firmware_data_left -= len;
8502 struct symbol_alive_response {
8511 u16 clock_settle_time; // 1us LSB
8512 u16 powerup_settle_time; // 1us LSB
8513 u16 hop_settle_time; // 1us LSB
8514 u8 date[3]; // month, day, year
8515 u8 time[2]; // hours, minutes
8519 int ipw2100_ucode_download(struct ipw2100_priv *priv, struct ipw2100_fw *fw)
8521 struct net_device *dev = priv->net_dev;
8522 const unsigned char *microcode_data = fw->uc.data;
8523 unsigned int microcode_data_left = fw->uc.size;
8525 struct symbol_alive_response response;
8529 /* Symbol control */
8530 write_nic_word(dev, IPW2100_CONTROL_REG, 0x703);
8531 readl((void *)(dev->base_addr));
8532 write_nic_word(dev, IPW2100_CONTROL_REG, 0x707);
8533 readl((void *)(dev->base_addr));
8536 write_nic_byte(dev, 0x210014, 0x72); /* fifo width =16 */
8537 readl((void *)(dev->base_addr));
8538 write_nic_byte(dev, 0x210014, 0x72); /* fifo width =16 */
8539 readl((void *)(dev->base_addr));
8541 /* EN_CS_ACCESS bit to reset control store pointer */
8542 write_nic_byte(dev, 0x210000, 0x40);
8543 readl((void *)(dev->base_addr));
8544 write_nic_byte(dev, 0x210000, 0x0);
8545 readl((void *)(dev->base_addr));
8546 write_nic_byte(dev, 0x210000, 0x40);
8547 readl((void *)(dev->base_addr));
8549 /* copy microcode from buffer into Symbol */
8551 while (microcode_data_left > 0) {
8552 write_nic_byte(dev, 0x210010, *microcode_data++);
8553 write_nic_byte(dev, 0x210010, *microcode_data++);
8554 microcode_data_left -= 2;
8557 /* EN_CS_ACCESS bit to reset the control store pointer */
8558 write_nic_byte(dev, 0x210000, 0x0);
8559 readl((void *)(dev->base_addr));
8561 /* Enable System (Reg 0)
8562 * first enable causes garbage in RX FIFO */
8563 write_nic_byte(dev, 0x210000, 0x0);
8564 readl((void *)(dev->base_addr));
8565 write_nic_byte(dev, 0x210000, 0x80);
8566 readl((void *)(dev->base_addr));
8568 /* Reset External Baseband Reg */
8569 write_nic_word(dev, IPW2100_CONTROL_REG, 0x703);
8570 readl((void *)(dev->base_addr));
8571 write_nic_word(dev, IPW2100_CONTROL_REG, 0x707);
8572 readl((void *)(dev->base_addr));
8574 /* HW Config (Reg 5) */
8575 write_nic_byte(dev, 0x210014, 0x72); // fifo width =16
8576 readl((void *)(dev->base_addr));
8577 write_nic_byte(dev, 0x210014, 0x72); // fifo width =16
8578 readl((void *)(dev->base_addr));
8580 /* Enable System (Reg 0)
8581 * second enable should be OK */
8582 write_nic_byte(dev, 0x210000, 0x00); // clear enable system
8583 readl((void *)(dev->base_addr));
8584 write_nic_byte(dev, 0x210000, 0x80); // set enable system
8586 /* check Symbol is enabled - upped this from 5 as it wasn't always
8587 * catching the update */
8588 for (i = 0; i < 10; i++) {
8591 /* check Dino is enabled bit */
8592 read_nic_byte(dev, 0x210000, &data);
8598 IPW_DEBUG_ERROR("%s: Error initializing Symbol\n",
8603 /* Get Symbol alive response */
8604 for (i = 0; i < 30; i++) {
8605 /* Read alive response structure */
8607 j < (sizeof(struct symbol_alive_response) >> 1);
8609 read_nic_word(dev, 0x210004,
8610 ((u16 *)&response) + j);
8612 if ((response.cmd_id == 1) &&
8613 (response.ucode_valid == 0x1))
8619 IPW_DEBUG_ERROR("%s: No response from Symbol - hw not alive\n",
8621 printk_buf(IPW_DL_ERROR, (u8*)&response, sizeof(response));