1 /******************************************************************************
3 Copyright(c) 2003 - 2006 Intel Corporation. All rights reserved.
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of version 2 of the GNU General Public License as
7 published by the Free Software Foundation.
9 This program is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 You should have received a copy of the GNU General Public License along with
15 this program; if not, write to the Free Software Foundation, Inc., 59
16 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 The full GNU General Public License is included in this distribution in the
22 James P. Ketrenos <ipw2100-admin@linux.intel.com>
23 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25 Portions of this file are based on the sample_* files provided by Wireless
26 Extensions 0.26 package and copyright (c) 1997-2003 Jean Tourrilhes
29 Portions of this file are based on the Host AP project,
30 Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
32 Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
34 Portions of ipw2100_mod_firmware_load, ipw2100_do_mod_firmware_load, and
35 ipw2100_fw_load are loosely based on drivers/sound/sound_firmware.c
36 available in the 2.4.25 kernel sources, and are copyright (c) Alan Cox
38 ******************************************************************************/
41 Initial driver on which this is based was developed by Janusz Gorycki,
42 Maciej Urbaniak, and Maciej Sosnowski.
44 Promiscuous mode support added by Jacek Wysoczynski and Maciej Urbaniak.
48 Tx - Commands and Data
50 Firmware and host share a circular queue of Transmit Buffer Descriptors (TBDs)
51 Each TBD contains a pointer to the physical (dma_addr_t) address of data being
52 sent to the firmware as well as the length of the data.
54 The host writes to the TBD queue at the WRITE index. The WRITE index points
55 to the _next_ packet to be written and is advanced when after the TBD has been
58 The firmware pulls from the TBD queue at the READ index. The READ index points
59 to the currently being read entry, and is advanced once the firmware is
62 When data is sent to the firmware, the first TBD is used to indicate to the
63 firmware if a Command or Data is being sent. If it is Command, all of the
64 command information is contained within the physical address referred to by the
65 TBD. If it is Data, the first TBD indicates the type of data packet, number
66 of fragments, etc. The next TBD then referrs to the actual packet location.
68 The Tx flow cycle is as follows:
70 1) ipw2100_tx() is called by kernel with SKB to transmit
71 2) Packet is move from the tx_free_list and appended to the transmit pending
73 3) work is scheduled to move pending packets into the shared circular queue.
74 4) when placing packet in the circular queue, the incoming SKB is DMA mapped
75 to a physical address. That address is entered into a TBD. Two TBDs are
76 filled out. The first indicating a data packet, the second referring to the
78 5) the packet is removed from tx_pend_list and placed on the end of the
79 firmware pending list (fw_pend_list)
80 6) firmware is notified that the WRITE index has
81 7) Once the firmware has processed the TBD, INTA is triggered.
82 8) For each Tx interrupt received from the firmware, the READ index is checked
83 to see which TBDs are done being processed.
84 9) For each TBD that has been processed, the ISR pulls the oldest packet
85 from the fw_pend_list.
86 10)The packet structure contained in the fw_pend_list is then used
87 to unmap the DMA address and to free the SKB originally passed to the driver
89 11)The packet structure is placed onto the tx_free_list
91 The above steps are the same for commands, only the msg_free_list/msg_pend_list
92 are used instead of tx_free_list/tx_pend_list
96 Critical Sections / Locking :
98 There are two locks utilized. The first is the low level lock (priv->low_lock)
99 that protects the following:
101 - Access to the Tx/Rx queue lists via priv->low_lock. The lists are as follows:
103 tx_free_list : Holds pre-allocated Tx buffers.
104 TAIL modified in __ipw2100_tx_process()
105 HEAD modified in ipw2100_tx()
107 tx_pend_list : Holds used Tx buffers waiting to go into the TBD ring
108 TAIL modified ipw2100_tx()
109 HEAD modified by ipw2100_tx_send_data()
111 msg_free_list : Holds pre-allocated Msg (Command) buffers
112 TAIL modified in __ipw2100_tx_process()
113 HEAD modified in ipw2100_hw_send_command()
115 msg_pend_list : Holds used Msg buffers waiting to go into the TBD ring
116 TAIL modified in ipw2100_hw_send_command()
117 HEAD modified in ipw2100_tx_send_commands()
119 The flow of data on the TX side is as follows:
121 MSG_FREE_LIST + COMMAND => MSG_PEND_LIST => TBD => MSG_FREE_LIST
122 TX_FREE_LIST + DATA => TX_PEND_LIST => TBD => TX_FREE_LIST
124 The methods that work on the TBD ring are protected via priv->low_lock.
126 - The internal data state of the device itself
127 - Access to the firmware read/write indexes for the BD queues
130 All external entry functions are locked with the priv->action_lock to ensure
131 that only one external action is invoked at a time.
136 #include <linux/compiler.h>
137 #include <linux/config.h>
138 #include <linux/errno.h>
139 #include <linux/if_arp.h>
140 #include <linux/in6.h>
141 #include <linux/in.h>
142 #include <linux/ip.h>
143 #include <linux/kernel.h>
144 #include <linux/kmod.h>
145 #include <linux/module.h>
146 #include <linux/netdevice.h>
147 #include <linux/ethtool.h>
148 #include <linux/pci.h>
149 #include <linux/dma-mapping.h>
150 #include <linux/proc_fs.h>
151 #include <linux/skbuff.h>
152 #include <asm/uaccess.h>
154 #define __KERNEL_SYSCALLS__
155 #include <linux/fs.h>
156 #include <linux/mm.h>
157 #include <linux/slab.h>
158 #include <linux/unistd.h>
159 #include <linux/stringify.h>
160 #include <linux/tcp.h>
161 #include <linux/types.h>
162 #include <linux/version.h>
163 #include <linux/time.h>
164 #include <linux/firmware.h>
165 #include <linux/acpi.h>
166 #include <linux/ctype.h>
170 #define IPW2100_VERSION "git-1.1.4"
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-2006 Intel Corporation"
177 /* Debugging stuff */
178 #ifdef CONFIG_IPW2100_DEBUG
179 #define CONFIG_IPW2100_RX_DEBUG /* Reception debugging */
182 MODULE_DESCRIPTION(DRV_DESCRIPTION);
183 MODULE_VERSION(DRV_VERSION);
184 MODULE_AUTHOR(DRV_COPYRIGHT);
185 MODULE_LICENSE("GPL");
187 static int debug = 0;
189 static int channel = 0;
190 static int associate = 1;
191 static int disable = 0;
193 static struct ipw2100_fw ipw2100_firmware;
196 #include <linux/moduleparam.h>
197 #include <linux/mutex.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 static u32 ipw2100_debug_level = IPW_DL_NONE;
212 #ifdef CONFIG_IPW2100_DEBUG
213 #define IPW_DEBUG(level, message...) \
215 if (ipw2100_debug_level & (level)) { \
216 printk(KERN_DEBUG "ipw2100: %c %s ", \
217 in_interrupt() ? 'I' : 'U', __FUNCTION__); \
222 #define IPW_DEBUG(level, message...) do {} while (0)
223 #endif /* CONFIG_IPW2100_DEBUG */
225 #ifdef CONFIG_IPW2100_DEBUG
226 static const char *command_types[] = {
228 "unused", /* HOST_ATTENTION */
230 "unused", /* SLEEP */
231 "unused", /* HOST_POWER_DOWN */
234 "unused", /* SET_IMR */
237 "AUTHENTICATION_TYPE",
240 "INTERNATIONAL_MODE",
255 "CLEAR_ALL_MULTICAST",
276 "AP_OR_STATION_TABLE",
280 "unused", /* SAVE_CALIBRATION */
281 "unused", /* RESTORE_CALIBRATION */
285 "HOST_PRE_POWER_DOWN",
286 "unused", /* HOST_INTERRUPT_COALESCING */
288 "CARD_DISABLE_PHY_OFF",
289 "MSDU_TX_RATES" "undefined",
291 "SET_STATION_STAT_BITS",
292 "CLEAR_STATIONS_STAT_BITS",
294 "SET_SECURITY_INFORMATION",
295 "DISASSOCIATION_BSSID",
300 /* Pre-decl until we get the code solid and then we can clean it up */
301 static void ipw2100_tx_send_commands(struct ipw2100_priv *priv);
302 static void ipw2100_tx_send_data(struct ipw2100_priv *priv);
303 static int ipw2100_adapter_setup(struct ipw2100_priv *priv);
305 static void ipw2100_queues_initialize(struct ipw2100_priv *priv);
306 static void ipw2100_queues_free(struct ipw2100_priv *priv);
307 static int ipw2100_queues_allocate(struct ipw2100_priv *priv);
309 static int ipw2100_fw_download(struct ipw2100_priv *priv,
310 struct ipw2100_fw *fw);
311 static int ipw2100_get_firmware(struct ipw2100_priv *priv,
312 struct ipw2100_fw *fw);
313 static int ipw2100_get_fwversion(struct ipw2100_priv *priv, char *buf,
315 static int ipw2100_get_ucodeversion(struct ipw2100_priv *priv, char *buf,
317 static void ipw2100_release_firmware(struct ipw2100_priv *priv,
318 struct ipw2100_fw *fw);
319 static int ipw2100_ucode_download(struct ipw2100_priv *priv,
320 struct ipw2100_fw *fw);
321 static void ipw2100_wx_event_work(struct ipw2100_priv *priv);
322 static struct iw_statistics *ipw2100_wx_wireless_stats(struct net_device *dev);
323 static struct iw_handler_def ipw2100_wx_handler_def;
325 static inline void read_register(struct net_device *dev, u32 reg, u32 * val)
327 *val = readl((void __iomem *)(dev->base_addr + reg));
328 IPW_DEBUG_IO("r: 0x%08X => 0x%08X\n", reg, *val);
331 static inline void write_register(struct net_device *dev, u32 reg, u32 val)
333 writel(val, (void __iomem *)(dev->base_addr + reg));
334 IPW_DEBUG_IO("w: 0x%08X <= 0x%08X\n", reg, val);
337 static inline void read_register_word(struct net_device *dev, u32 reg,
340 *val = readw((void __iomem *)(dev->base_addr + reg));
341 IPW_DEBUG_IO("r: 0x%08X => %04X\n", reg, *val);
344 static inline void read_register_byte(struct net_device *dev, u32 reg, u8 * val)
346 *val = readb((void __iomem *)(dev->base_addr + reg));
347 IPW_DEBUG_IO("r: 0x%08X => %02X\n", reg, *val);
350 static inline void write_register_word(struct net_device *dev, u32 reg, u16 val)
352 writew(val, (void __iomem *)(dev->base_addr + reg));
353 IPW_DEBUG_IO("w: 0x%08X <= %04X\n", reg, val);
356 static inline void write_register_byte(struct net_device *dev, u32 reg, u8 val)
358 writeb(val, (void __iomem *)(dev->base_addr + reg));
359 IPW_DEBUG_IO("w: 0x%08X =< %02X\n", reg, val);
362 static inline void read_nic_dword(struct net_device *dev, u32 addr, u32 * val)
364 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
365 addr & IPW_REG_INDIRECT_ADDR_MASK);
366 read_register(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
369 static inline void write_nic_dword(struct net_device *dev, u32 addr, u32 val)
371 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
372 addr & IPW_REG_INDIRECT_ADDR_MASK);
373 write_register(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
376 static inline void read_nic_word(struct net_device *dev, u32 addr, u16 * val)
378 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
379 addr & IPW_REG_INDIRECT_ADDR_MASK);
380 read_register_word(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
383 static inline void write_nic_word(struct net_device *dev, u32 addr, u16 val)
385 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
386 addr & IPW_REG_INDIRECT_ADDR_MASK);
387 write_register_word(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
390 static inline void read_nic_byte(struct net_device *dev, u32 addr, u8 * val)
392 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
393 addr & IPW_REG_INDIRECT_ADDR_MASK);
394 read_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
397 static inline void write_nic_byte(struct net_device *dev, u32 addr, u8 val)
399 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
400 addr & IPW_REG_INDIRECT_ADDR_MASK);
401 write_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
404 static inline void write_nic_auto_inc_address(struct net_device *dev, u32 addr)
406 write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS,
407 addr & IPW_REG_INDIRECT_ADDR_MASK);
410 static inline void write_nic_dword_auto_inc(struct net_device *dev, u32 val)
412 write_register(dev, IPW_REG_AUTOINCREMENT_DATA, val);
415 static void write_nic_memory(struct net_device *dev, u32 addr, u32 len,
423 /* read first nibble byte by byte */
424 aligned_addr = addr & (~0x3);
425 dif_len = addr - aligned_addr;
427 /* Start reading at aligned_addr + dif_len */
428 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
430 for (i = dif_len; i < 4; i++, buf++)
431 write_register_byte(dev,
432 IPW_REG_INDIRECT_ACCESS_DATA + i,
439 /* read DWs through autoincrement registers */
440 write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS, aligned_addr);
441 aligned_len = len & (~0x3);
442 for (i = 0; i < aligned_len; i += 4, buf += 4, aligned_addr += 4)
443 write_register(dev, IPW_REG_AUTOINCREMENT_DATA, *(u32 *) buf);
445 /* copy the last nibble */
446 dif_len = len - aligned_len;
447 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, aligned_addr);
448 for (i = 0; i < dif_len; i++, buf++)
449 write_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA + i,
453 static void read_nic_memory(struct net_device *dev, u32 addr, u32 len,
461 /* read first nibble byte by byte */
462 aligned_addr = addr & (~0x3);
463 dif_len = addr - aligned_addr;
465 /* Start reading at aligned_addr + dif_len */
466 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
468 for (i = dif_len; i < 4; i++, buf++)
469 read_register_byte(dev,
470 IPW_REG_INDIRECT_ACCESS_DATA + i,
477 /* read DWs through autoincrement registers */
478 write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS, aligned_addr);
479 aligned_len = len & (~0x3);
480 for (i = 0; i < aligned_len; i += 4, buf += 4, aligned_addr += 4)
481 read_register(dev, IPW_REG_AUTOINCREMENT_DATA, (u32 *) buf);
483 /* copy the last nibble */
484 dif_len = len - aligned_len;
485 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, aligned_addr);
486 for (i = 0; i < dif_len; i++, buf++)
487 read_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA + i, buf);
490 static inline int ipw2100_hw_is_adapter_in_system(struct net_device *dev)
492 return (dev->base_addr &&
494 ((void __iomem *)(dev->base_addr +
495 IPW_REG_DOA_DEBUG_AREA_START))
496 == IPW_DATA_DOA_DEBUG_VALUE));
499 static int ipw2100_get_ordinal(struct ipw2100_priv *priv, u32 ord,
500 void *val, u32 * len)
502 struct ipw2100_ordinals *ordinals = &priv->ordinals;
509 if (ordinals->table1_addr == 0) {
510 printk(KERN_WARNING DRV_NAME ": attempt to use fw ordinals "
511 "before they have been loaded.\n");
515 if (IS_ORDINAL_TABLE_ONE(ordinals, ord)) {
516 if (*len < IPW_ORD_TAB_1_ENTRY_SIZE) {
517 *len = IPW_ORD_TAB_1_ENTRY_SIZE;
519 printk(KERN_WARNING DRV_NAME
520 ": ordinal buffer length too small, need %zd\n",
521 IPW_ORD_TAB_1_ENTRY_SIZE);
526 read_nic_dword(priv->net_dev,
527 ordinals->table1_addr + (ord << 2), &addr);
528 read_nic_dword(priv->net_dev, addr, val);
530 *len = IPW_ORD_TAB_1_ENTRY_SIZE;
535 if (IS_ORDINAL_TABLE_TWO(ordinals, ord)) {
537 ord -= IPW_START_ORD_TAB_2;
539 /* get the address of statistic */
540 read_nic_dword(priv->net_dev,
541 ordinals->table2_addr + (ord << 3), &addr);
543 /* get the second DW of statistics ;
544 * two 16-bit words - first is length, second is count */
545 read_nic_dword(priv->net_dev,
546 ordinals->table2_addr + (ord << 3) + sizeof(u32),
549 /* get each entry length */
550 field_len = *((u16 *) & field_info);
552 /* get number of entries */
553 field_count = *(((u16 *) & field_info) + 1);
555 /* abort if no enought memory */
556 total_length = field_len * field_count;
557 if (total_length > *len) {
566 /* read the ordinal data from the SRAM */
567 read_nic_memory(priv->net_dev, addr, total_length, val);
572 printk(KERN_WARNING DRV_NAME ": ordinal %d neither in table 1 nor "
573 "in table 2\n", ord);
578 static int ipw2100_set_ordinal(struct ipw2100_priv *priv, u32 ord, u32 * val,
581 struct ipw2100_ordinals *ordinals = &priv->ordinals;
584 if (IS_ORDINAL_TABLE_ONE(ordinals, ord)) {
585 if (*len != IPW_ORD_TAB_1_ENTRY_SIZE) {
586 *len = IPW_ORD_TAB_1_ENTRY_SIZE;
587 IPW_DEBUG_INFO("wrong size\n");
591 read_nic_dword(priv->net_dev,
592 ordinals->table1_addr + (ord << 2), &addr);
594 write_nic_dword(priv->net_dev, addr, *val);
596 *len = IPW_ORD_TAB_1_ENTRY_SIZE;
601 IPW_DEBUG_INFO("wrong table\n");
602 if (IS_ORDINAL_TABLE_TWO(ordinals, ord))
608 static char *snprint_line(char *buf, size_t count,
609 const u8 * data, u32 len, u32 ofs)
614 out = snprintf(buf, count, "%08X", ofs);
616 for (l = 0, i = 0; i < 2; i++) {
617 out += snprintf(buf + out, count - out, " ");
618 for (j = 0; j < 8 && l < len; j++, l++)
619 out += snprintf(buf + out, count - out, "%02X ",
622 out += snprintf(buf + out, count - out, " ");
625 out += snprintf(buf + out, count - out, " ");
626 for (l = 0, i = 0; i < 2; i++) {
627 out += snprintf(buf + out, count - out, " ");
628 for (j = 0; j < 8 && l < len; j++, l++) {
629 c = data[(i * 8 + j)];
630 if (!isascii(c) || !isprint(c))
633 out += snprintf(buf + out, count - out, "%c", c);
637 out += snprintf(buf + out, count - out, " ");
643 static void printk_buf(int level, const u8 * data, u32 len)
647 if (!(ipw2100_debug_level & level))
651 printk(KERN_DEBUG "%s\n",
652 snprint_line(line, sizeof(line), &data[ofs],
653 min(len, 16U), ofs));
655 len -= min(len, 16U);
659 #define MAX_RESET_BACKOFF 10
661 static void schedule_reset(struct ipw2100_priv *priv)
663 unsigned long now = get_seconds();
665 /* If we haven't received a reset request within the backoff period,
666 * then we can reset the backoff interval so this reset occurs
668 if (priv->reset_backoff &&
669 (now - priv->last_reset > priv->reset_backoff))
670 priv->reset_backoff = 0;
672 priv->last_reset = get_seconds();
674 if (!(priv->status & STATUS_RESET_PENDING)) {
675 IPW_DEBUG_INFO("%s: Scheduling firmware restart (%ds).\n",
676 priv->net_dev->name, priv->reset_backoff);
677 netif_carrier_off(priv->net_dev);
678 netif_stop_queue(priv->net_dev);
679 priv->status |= STATUS_RESET_PENDING;
680 if (priv->reset_backoff)
681 queue_delayed_work(priv->workqueue, &priv->reset_work,
682 priv->reset_backoff * HZ);
684 queue_work(priv->workqueue, &priv->reset_work);
686 if (priv->reset_backoff < MAX_RESET_BACKOFF)
687 priv->reset_backoff++;
689 wake_up_interruptible(&priv->wait_command_queue);
691 IPW_DEBUG_INFO("%s: Firmware restart already in progress.\n",
692 priv->net_dev->name);
696 #define HOST_COMPLETE_TIMEOUT (2 * HZ)
697 static int ipw2100_hw_send_command(struct ipw2100_priv *priv,
698 struct host_command *cmd)
700 struct list_head *element;
701 struct ipw2100_tx_packet *packet;
705 IPW_DEBUG_HC("Sending %s command (#%d), %d bytes\n",
706 command_types[cmd->host_command], cmd->host_command,
707 cmd->host_command_length);
708 printk_buf(IPW_DL_HC, (u8 *) cmd->host_command_parameters,
709 cmd->host_command_length);
711 spin_lock_irqsave(&priv->low_lock, flags);
713 if (priv->fatal_error) {
715 ("Attempt to send command while hardware in fatal error condition.\n");
720 if (!(priv->status & STATUS_RUNNING)) {
722 ("Attempt to send command while hardware is not running.\n");
727 if (priv->status & STATUS_CMD_ACTIVE) {
729 ("Attempt to send command while another command is pending.\n");
734 if (list_empty(&priv->msg_free_list)) {
735 IPW_DEBUG_INFO("no available msg buffers\n");
739 priv->status |= STATUS_CMD_ACTIVE;
740 priv->messages_sent++;
742 element = priv->msg_free_list.next;
744 packet = list_entry(element, struct ipw2100_tx_packet, list);
745 packet->jiffy_start = jiffies;
747 /* initialize the firmware command packet */
748 packet->info.c_struct.cmd->host_command_reg = cmd->host_command;
749 packet->info.c_struct.cmd->host_command_reg1 = cmd->host_command1;
750 packet->info.c_struct.cmd->host_command_len_reg =
751 cmd->host_command_length;
752 packet->info.c_struct.cmd->sequence = cmd->host_command_sequence;
754 memcpy(packet->info.c_struct.cmd->host_command_params_reg,
755 cmd->host_command_parameters,
756 sizeof(packet->info.c_struct.cmd->host_command_params_reg));
759 DEC_STAT(&priv->msg_free_stat);
761 list_add_tail(element, &priv->msg_pend_list);
762 INC_STAT(&priv->msg_pend_stat);
764 ipw2100_tx_send_commands(priv);
765 ipw2100_tx_send_data(priv);
767 spin_unlock_irqrestore(&priv->low_lock, flags);
770 * We must wait for this command to complete before another
771 * command can be sent... but if we wait more than 3 seconds
772 * then there is a problem.
776 wait_event_interruptible_timeout(priv->wait_command_queue,
778 status & STATUS_CMD_ACTIVE),
779 HOST_COMPLETE_TIMEOUT);
782 IPW_DEBUG_INFO("Command completion failed out after %dms.\n",
783 1000 * (HOST_COMPLETE_TIMEOUT / HZ));
784 priv->fatal_error = IPW2100_ERR_MSG_TIMEOUT;
785 priv->status &= ~STATUS_CMD_ACTIVE;
786 schedule_reset(priv);
790 if (priv->fatal_error) {
791 printk(KERN_WARNING DRV_NAME ": %s: firmware fatal error\n",
792 priv->net_dev->name);
796 /* !!!!! HACK TEST !!!!!
797 * When lots of debug trace statements are enabled, the driver
798 * doesn't seem to have as many firmware restart cycles...
800 * As a test, we're sticking in a 1/100s delay here */
801 schedule_timeout_uninterruptible(msecs_to_jiffies(10));
806 spin_unlock_irqrestore(&priv->low_lock, flags);
812 * Verify the values and data access of the hardware
813 * No locks needed or used. No functions called.
815 static int ipw2100_verify(struct ipw2100_priv *priv)
820 u32 val1 = 0x76543210;
821 u32 val2 = 0xFEDCBA98;
823 /* Domain 0 check - all values should be DOA_DEBUG */
824 for (address = IPW_REG_DOA_DEBUG_AREA_START;
825 address < IPW_REG_DOA_DEBUG_AREA_END; address += sizeof(u32)) {
826 read_register(priv->net_dev, address, &data1);
827 if (data1 != IPW_DATA_DOA_DEBUG_VALUE)
831 /* Domain 1 check - use arbitrary read/write compare */
832 for (address = 0; address < 5; address++) {
833 /* The memory area is not used now */
834 write_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x32,
836 write_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x36,
838 read_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x32,
840 read_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x36,
842 if (val1 == data1 && val2 == data2)
851 * Loop until the CARD_DISABLED bit is the same value as the
854 * TODO: See if it would be more efficient to do a wait/wake
855 * cycle and have the completion event trigger the wakeup
858 #define IPW_CARD_DISABLE_COMPLETE_WAIT 100 // 100 milli
859 static int ipw2100_wait_for_card_state(struct ipw2100_priv *priv, int state)
863 u32 len = sizeof(card_state);
866 for (i = 0; i <= IPW_CARD_DISABLE_COMPLETE_WAIT * 1000; i += 50) {
867 err = ipw2100_get_ordinal(priv, IPW_ORD_CARD_DISABLED,
870 IPW_DEBUG_INFO("Query of CARD_DISABLED ordinal "
875 /* We'll break out if either the HW state says it is
876 * in the state we want, or if HOST_COMPLETE command
878 if ((card_state == state) ||
879 ((priv->status & STATUS_ENABLED) ?
880 IPW_HW_STATE_ENABLED : IPW_HW_STATE_DISABLED) == state) {
881 if (state == IPW_HW_STATE_ENABLED)
882 priv->status |= STATUS_ENABLED;
884 priv->status &= ~STATUS_ENABLED;
892 IPW_DEBUG_INFO("ipw2100_wait_for_card_state to %s state timed out\n",
893 state ? "DISABLED" : "ENABLED");
897 /*********************************************************************
898 Procedure : sw_reset_and_clock
899 Purpose : Asserts s/w reset, asserts clock initialization
900 and waits for clock stabilization
901 ********************************************************************/
902 static int sw_reset_and_clock(struct ipw2100_priv *priv)
908 write_register(priv->net_dev, IPW_REG_RESET_REG,
909 IPW_AUX_HOST_RESET_REG_SW_RESET);
911 // wait for clock stabilization
912 for (i = 0; i < 1000; i++) {
913 udelay(IPW_WAIT_RESET_ARC_COMPLETE_DELAY);
915 // check clock ready bit
916 read_register(priv->net_dev, IPW_REG_RESET_REG, &r);
917 if (r & IPW_AUX_HOST_RESET_REG_PRINCETON_RESET)
922 return -EIO; // TODO: better error value
924 /* set "initialization complete" bit to move adapter to
926 write_register(priv->net_dev, IPW_REG_GP_CNTRL,
927 IPW_AUX_HOST_GP_CNTRL_BIT_INIT_DONE);
929 /* wait for clock stabilization */
930 for (i = 0; i < 10000; i++) {
931 udelay(IPW_WAIT_CLOCK_STABILIZATION_DELAY * 4);
933 /* check clock ready bit */
934 read_register(priv->net_dev, IPW_REG_GP_CNTRL, &r);
935 if (r & IPW_AUX_HOST_GP_CNTRL_BIT_CLOCK_READY)
940 return -EIO; /* TODO: better error value */
942 /* set D0 standby bit */
943 read_register(priv->net_dev, IPW_REG_GP_CNTRL, &r);
944 write_register(priv->net_dev, IPW_REG_GP_CNTRL,
945 r | IPW_AUX_HOST_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
950 /*********************************************************************
951 Procedure : ipw2100_download_firmware
952 Purpose : Initiaze adapter after power on.
954 1. assert s/w reset first!
955 2. awake clocks & wait for clock stabilization
956 3. hold ARC (don't ask me why...)
957 4. load Dino ucode and reset/clock init again
958 5. zero-out shared mem
960 *******************************************************************/
961 static int ipw2100_download_firmware(struct ipw2100_priv *priv)
967 /* Fetch the firmware and microcode */
968 struct ipw2100_fw ipw2100_firmware;
971 if (priv->fatal_error) {
972 IPW_DEBUG_ERROR("%s: ipw2100_download_firmware called after "
973 "fatal error %d. Interface must be brought down.\n",
974 priv->net_dev->name, priv->fatal_error);
978 if (!ipw2100_firmware.version) {
979 err = ipw2100_get_firmware(priv, &ipw2100_firmware);
981 IPW_DEBUG_ERROR("%s: ipw2100_get_firmware failed: %d\n",
982 priv->net_dev->name, err);
983 priv->fatal_error = IPW2100_ERR_FW_LOAD;
988 err = ipw2100_get_firmware(priv, &ipw2100_firmware);
990 IPW_DEBUG_ERROR("%s: ipw2100_get_firmware failed: %d\n",
991 priv->net_dev->name, err);
992 priv->fatal_error = IPW2100_ERR_FW_LOAD;
996 priv->firmware_version = ipw2100_firmware.version;
998 /* s/w reset and clock stabilization */
999 err = sw_reset_and_clock(priv);
1001 IPW_DEBUG_ERROR("%s: sw_reset_and_clock failed: %d\n",
1002 priv->net_dev->name, err);
1006 err = ipw2100_verify(priv);
1008 IPW_DEBUG_ERROR("%s: ipw2100_verify failed: %d\n",
1009 priv->net_dev->name, err);
1014 write_nic_dword(priv->net_dev,
1015 IPW_INTERNAL_REGISTER_HALT_AND_RESET, 0x80000000);
1017 /* allow ARC to run */
1018 write_register(priv->net_dev, IPW_REG_RESET_REG, 0);
1020 /* load microcode */
1021 err = ipw2100_ucode_download(priv, &ipw2100_firmware);
1023 printk(KERN_ERR DRV_NAME ": %s: Error loading microcode: %d\n",
1024 priv->net_dev->name, err);
1029 write_nic_dword(priv->net_dev,
1030 IPW_INTERNAL_REGISTER_HALT_AND_RESET, 0x00000000);
1032 /* s/w reset and clock stabilization (again!!!) */
1033 err = sw_reset_and_clock(priv);
1035 printk(KERN_ERR DRV_NAME
1036 ": %s: sw_reset_and_clock failed: %d\n",
1037 priv->net_dev->name, err);
1042 err = ipw2100_fw_download(priv, &ipw2100_firmware);
1044 IPW_DEBUG_ERROR("%s: Error loading firmware: %d\n",
1045 priv->net_dev->name, err);
1050 * When the .resume method of the driver is called, the other
1051 * part of the system, i.e. the ide driver could still stay in
1052 * the suspend stage. This prevents us from loading the firmware
1053 * from the disk. --YZ
1056 /* free any storage allocated for firmware image */
1057 ipw2100_release_firmware(priv, &ipw2100_firmware);
1060 /* zero out Domain 1 area indirectly (Si requirement) */
1061 for (address = IPW_HOST_FW_SHARED_AREA0;
1062 address < IPW_HOST_FW_SHARED_AREA0_END; address += 4)
1063 write_nic_dword(priv->net_dev, address, 0);
1064 for (address = IPW_HOST_FW_SHARED_AREA1;
1065 address < IPW_HOST_FW_SHARED_AREA1_END; address += 4)
1066 write_nic_dword(priv->net_dev, address, 0);
1067 for (address = IPW_HOST_FW_SHARED_AREA2;
1068 address < IPW_HOST_FW_SHARED_AREA2_END; address += 4)
1069 write_nic_dword(priv->net_dev, address, 0);
1070 for (address = IPW_HOST_FW_SHARED_AREA3;
1071 address < IPW_HOST_FW_SHARED_AREA3_END; address += 4)
1072 write_nic_dword(priv->net_dev, address, 0);
1073 for (address = IPW_HOST_FW_INTERRUPT_AREA;
1074 address < IPW_HOST_FW_INTERRUPT_AREA_END; address += 4)
1075 write_nic_dword(priv->net_dev, address, 0);
1080 ipw2100_release_firmware(priv, &ipw2100_firmware);
1084 static inline void ipw2100_enable_interrupts(struct ipw2100_priv *priv)
1086 if (priv->status & STATUS_INT_ENABLED)
1088 priv->status |= STATUS_INT_ENABLED;
1089 write_register(priv->net_dev, IPW_REG_INTA_MASK, IPW_INTERRUPT_MASK);
1092 static inline void ipw2100_disable_interrupts(struct ipw2100_priv *priv)
1094 if (!(priv->status & STATUS_INT_ENABLED))
1096 priv->status &= ~STATUS_INT_ENABLED;
1097 write_register(priv->net_dev, IPW_REG_INTA_MASK, 0x0);
1100 static void ipw2100_initialize_ordinals(struct ipw2100_priv *priv)
1102 struct ipw2100_ordinals *ord = &priv->ordinals;
1104 IPW_DEBUG_INFO("enter\n");
1106 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_ORDINALS_TABLE_1,
1109 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_ORDINALS_TABLE_2,
1112 read_nic_dword(priv->net_dev, ord->table1_addr, &ord->table1_size);
1113 read_nic_dword(priv->net_dev, ord->table2_addr, &ord->table2_size);
1115 ord->table2_size &= 0x0000FFFF;
1117 IPW_DEBUG_INFO("table 1 size: %d\n", ord->table1_size);
1118 IPW_DEBUG_INFO("table 2 size: %d\n", ord->table2_size);
1119 IPW_DEBUG_INFO("exit\n");
1122 static inline void ipw2100_hw_set_gpio(struct ipw2100_priv *priv)
1126 * Set GPIO 3 writable by FW; GPIO 1 writable
1127 * by driver and enable clock
1129 reg = (IPW_BIT_GPIO_GPIO3_MASK | IPW_BIT_GPIO_GPIO1_ENABLE |
1130 IPW_BIT_GPIO_LED_OFF);
1131 write_register(priv->net_dev, IPW_REG_GPIO, reg);
1134 static int rf_kill_active(struct ipw2100_priv *priv)
1136 #define MAX_RF_KILL_CHECKS 5
1137 #define RF_KILL_CHECK_DELAY 40
1139 unsigned short value = 0;
1143 if (!(priv->hw_features & HW_FEATURE_RFKILL)) {
1144 priv->status &= ~STATUS_RF_KILL_HW;
1148 for (i = 0; i < MAX_RF_KILL_CHECKS; i++) {
1149 udelay(RF_KILL_CHECK_DELAY);
1150 read_register(priv->net_dev, IPW_REG_GPIO, ®);
1151 value = (value << 1) | ((reg & IPW_BIT_GPIO_RF_KILL) ? 0 : 1);
1155 priv->status |= STATUS_RF_KILL_HW;
1157 priv->status &= ~STATUS_RF_KILL_HW;
1159 return (value == 0);
1162 static int ipw2100_get_hw_features(struct ipw2100_priv *priv)
1168 * EEPROM_SRAM_DB_START_ADDRESS using ordinal in ordinal table 1
1171 if (ipw2100_get_ordinal
1172 (priv, IPW_ORD_EEPROM_SRAM_DB_BLOCK_START_ADDRESS, &addr, &len)) {
1173 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
1178 IPW_DEBUG_INFO("EEPROM address: %08X\n", addr);
1181 * EEPROM version is the byte at offset 0xfd in firmware
1182 * We read 4 bytes, then shift out the byte we actually want */
1183 read_nic_dword(priv->net_dev, addr + 0xFC, &val);
1184 priv->eeprom_version = (val >> 24) & 0xFF;
1185 IPW_DEBUG_INFO("EEPROM version: %d\n", priv->eeprom_version);
1188 * HW RF Kill enable is bit 0 in byte at offset 0x21 in firmware
1190 * notice that the EEPROM bit is reverse polarity, i.e.
1191 * bit = 0 signifies HW RF kill switch is supported
1192 * bit = 1 signifies HW RF kill switch is NOT supported
1194 read_nic_dword(priv->net_dev, addr + 0x20, &val);
1195 if (!((val >> 24) & 0x01))
1196 priv->hw_features |= HW_FEATURE_RFKILL;
1198 IPW_DEBUG_INFO("HW RF Kill: %ssupported.\n",
1199 (priv->hw_features & HW_FEATURE_RFKILL) ? "" : "not ");
1205 * Start firmware execution after power on and intialization
1208 * 2. Wait for f/w initialization completes;
1210 static int ipw2100_start_adapter(struct ipw2100_priv *priv)
1213 u32 inta, inta_mask, gpio;
1215 IPW_DEBUG_INFO("enter\n");
1217 if (priv->status & STATUS_RUNNING)
1221 * Initialize the hw - drive adapter to DO state by setting
1222 * init_done bit. Wait for clk_ready bit and Download
1225 if (ipw2100_download_firmware(priv)) {
1226 printk(KERN_ERR DRV_NAME
1227 ": %s: Failed to power on the adapter.\n",
1228 priv->net_dev->name);
1232 /* Clear the Tx, Rx and Msg queues and the r/w indexes
1233 * in the firmware RBD and TBD ring queue */
1234 ipw2100_queues_initialize(priv);
1236 ipw2100_hw_set_gpio(priv);
1238 /* TODO -- Look at disabling interrupts here to make sure none
1239 * get fired during FW initialization */
1241 /* Release ARC - clear reset bit */
1242 write_register(priv->net_dev, IPW_REG_RESET_REG, 0);
1244 /* wait for f/w intialization complete */
1245 IPW_DEBUG_FW("Waiting for f/w initialization to complete...\n");
1248 schedule_timeout_uninterruptible(msecs_to_jiffies(40));
1249 /* Todo... wait for sync command ... */
1251 read_register(priv->net_dev, IPW_REG_INTA, &inta);
1253 /* check "init done" bit */
1254 if (inta & IPW2100_INTA_FW_INIT_DONE) {
1255 /* reset "init done" bit */
1256 write_register(priv->net_dev, IPW_REG_INTA,
1257 IPW2100_INTA_FW_INIT_DONE);
1261 /* check error conditions : we check these after the firmware
1262 * check so that if there is an error, the interrupt handler
1263 * will see it and the adapter will be reset */
1265 (IPW2100_INTA_FATAL_ERROR | IPW2100_INTA_PARITY_ERROR)) {
1266 /* clear error conditions */
1267 write_register(priv->net_dev, IPW_REG_INTA,
1268 IPW2100_INTA_FATAL_ERROR |
1269 IPW2100_INTA_PARITY_ERROR);
1273 /* Clear out any pending INTAs since we aren't supposed to have
1274 * interrupts enabled at this point... */
1275 read_register(priv->net_dev, IPW_REG_INTA, &inta);
1276 read_register(priv->net_dev, IPW_REG_INTA_MASK, &inta_mask);
1277 inta &= IPW_INTERRUPT_MASK;
1278 /* Clear out any pending interrupts */
1279 if (inta & inta_mask)
1280 write_register(priv->net_dev, IPW_REG_INTA, inta);
1282 IPW_DEBUG_FW("f/w initialization complete: %s\n",
1283 i ? "SUCCESS" : "FAILED");
1286 printk(KERN_WARNING DRV_NAME
1287 ": %s: Firmware did not initialize.\n",
1288 priv->net_dev->name);
1292 /* allow firmware to write to GPIO1 & GPIO3 */
1293 read_register(priv->net_dev, IPW_REG_GPIO, &gpio);
1295 gpio |= (IPW_BIT_GPIO_GPIO1_MASK | IPW_BIT_GPIO_GPIO3_MASK);
1297 write_register(priv->net_dev, IPW_REG_GPIO, gpio);
1299 /* Ready to receive commands */
1300 priv->status |= STATUS_RUNNING;
1302 /* The adapter has been reset; we are not associated */
1303 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
1305 IPW_DEBUG_INFO("exit\n");
1310 static inline void ipw2100_reset_fatalerror(struct ipw2100_priv *priv)
1312 if (!priv->fatal_error)
1315 priv->fatal_errors[priv->fatal_index++] = priv->fatal_error;
1316 priv->fatal_index %= IPW2100_ERROR_QUEUE;
1317 priv->fatal_error = 0;
1320 /* NOTE: Our interrupt is disabled when this method is called */
1321 static int ipw2100_power_cycle_adapter(struct ipw2100_priv *priv)
1326 IPW_DEBUG_INFO("Power cycling the hardware.\n");
1328 ipw2100_hw_set_gpio(priv);
1330 /* Step 1. Stop Master Assert */
1331 write_register(priv->net_dev, IPW_REG_RESET_REG,
1332 IPW_AUX_HOST_RESET_REG_STOP_MASTER);
1334 /* Step 2. Wait for stop Master Assert
1335 * (not more then 50us, otherwise ret error */
1338 udelay(IPW_WAIT_RESET_MASTER_ASSERT_COMPLETE_DELAY);
1339 read_register(priv->net_dev, IPW_REG_RESET_REG, ®);
1341 if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED)
1345 priv->status &= ~STATUS_RESET_PENDING;
1349 ("exit - waited too long for master assert stop\n");
1353 write_register(priv->net_dev, IPW_REG_RESET_REG,
1354 IPW_AUX_HOST_RESET_REG_SW_RESET);
1356 /* Reset any fatal_error conditions */
1357 ipw2100_reset_fatalerror(priv);
1359 /* At this point, the adapter is now stopped and disabled */
1360 priv->status &= ~(STATUS_RUNNING | STATUS_ASSOCIATING |
1361 STATUS_ASSOCIATED | STATUS_ENABLED);
1367 * Send the CARD_DISABLE_PHY_OFF comamnd to the card to disable it
1369 * After disabling, if the card was associated, a STATUS_ASSN_LOST will be sent.
1371 * STATUS_CARD_DISABLE_NOTIFICATION will be sent regardless of
1372 * if STATUS_ASSN_LOST is sent.
1374 static int ipw2100_hw_phy_off(struct ipw2100_priv *priv)
1377 #define HW_PHY_OFF_LOOP_DELAY (HZ / 5000)
1379 struct host_command cmd = {
1380 .host_command = CARD_DISABLE_PHY_OFF,
1381 .host_command_sequence = 0,
1382 .host_command_length = 0,
1387 IPW_DEBUG_HC("CARD_DISABLE_PHY_OFF\n");
1389 /* Turn off the radio */
1390 err = ipw2100_hw_send_command(priv, &cmd);
1394 for (i = 0; i < 2500; i++) {
1395 read_nic_dword(priv->net_dev, IPW2100_CONTROL_REG, &val1);
1396 read_nic_dword(priv->net_dev, IPW2100_COMMAND, &val2);
1398 if ((val1 & IPW2100_CONTROL_PHY_OFF) &&
1399 (val2 & IPW2100_COMMAND_PHY_OFF))
1402 schedule_timeout_uninterruptible(HW_PHY_OFF_LOOP_DELAY);
1408 static int ipw2100_enable_adapter(struct ipw2100_priv *priv)
1410 struct host_command cmd = {
1411 .host_command = HOST_COMPLETE,
1412 .host_command_sequence = 0,
1413 .host_command_length = 0
1417 IPW_DEBUG_HC("HOST_COMPLETE\n");
1419 if (priv->status & STATUS_ENABLED)
1422 mutex_lock(&priv->adapter_mutex);
1424 if (rf_kill_active(priv)) {
1425 IPW_DEBUG_HC("Command aborted due to RF kill active.\n");
1429 err = ipw2100_hw_send_command(priv, &cmd);
1431 IPW_DEBUG_INFO("Failed to send HOST_COMPLETE command\n");
1435 err = ipw2100_wait_for_card_state(priv, IPW_HW_STATE_ENABLED);
1437 IPW_DEBUG_INFO("%s: card not responding to init command.\n",
1438 priv->net_dev->name);
1442 if (priv->stop_hang_check) {
1443 priv->stop_hang_check = 0;
1444 queue_delayed_work(priv->workqueue, &priv->hang_check, HZ / 2);
1448 mutex_unlock(&priv->adapter_mutex);
1452 static int ipw2100_hw_stop_adapter(struct ipw2100_priv *priv)
1454 #define HW_POWER_DOWN_DELAY (msecs_to_jiffies(100))
1456 struct host_command cmd = {
1457 .host_command = HOST_PRE_POWER_DOWN,
1458 .host_command_sequence = 0,
1459 .host_command_length = 0,
1464 if (!(priv->status & STATUS_RUNNING))
1467 priv->status |= STATUS_STOPPING;
1469 /* We can only shut down the card if the firmware is operational. So,
1470 * if we haven't reset since a fatal_error, then we can not send the
1471 * shutdown commands. */
1472 if (!priv->fatal_error) {
1473 /* First, make sure the adapter is enabled so that the PHY_OFF
1474 * command can shut it down */
1475 ipw2100_enable_adapter(priv);
1477 err = ipw2100_hw_phy_off(priv);
1479 printk(KERN_WARNING DRV_NAME
1480 ": Error disabling radio %d\n", err);
1483 * If in D0-standby mode going directly to D3 may cause a
1484 * PCI bus violation. Therefore we must change out of the D0
1487 * Sending the PREPARE_FOR_POWER_DOWN will restrict the
1488 * hardware from going into standby mode and will transition
1489 * out of D0-standy if it is already in that state.
1491 * STATUS_PREPARE_POWER_DOWN_COMPLETE will be sent by the
1492 * driver upon completion. Once received, the driver can
1493 * proceed to the D3 state.
1495 * Prepare for power down command to fw. This command would
1496 * take HW out of D0-standby and prepare it for D3 state.
1498 * Currently FW does not support event notification for this
1499 * event. Therefore, skip waiting for it. Just wait a fixed
1502 IPW_DEBUG_HC("HOST_PRE_POWER_DOWN\n");
1504 err = ipw2100_hw_send_command(priv, &cmd);
1506 printk(KERN_WARNING DRV_NAME ": "
1507 "%s: Power down command failed: Error %d\n",
1508 priv->net_dev->name, err);
1510 schedule_timeout_uninterruptible(HW_POWER_DOWN_DELAY);
1513 priv->status &= ~STATUS_ENABLED;
1516 * Set GPIO 3 writable by FW; GPIO 1 writable
1517 * by driver and enable clock
1519 ipw2100_hw_set_gpio(priv);
1522 * Power down adapter. Sequence:
1523 * 1. Stop master assert (RESET_REG[9]=1)
1524 * 2. Wait for stop master (RESET_REG[8]==1)
1525 * 3. S/w reset assert (RESET_REG[7] = 1)
1528 /* Stop master assert */
1529 write_register(priv->net_dev, IPW_REG_RESET_REG,
1530 IPW_AUX_HOST_RESET_REG_STOP_MASTER);
1532 /* wait stop master not more than 50 usec.
1533 * Otherwise return error. */
1534 for (i = 5; i > 0; i--) {
1537 /* Check master stop bit */
1538 read_register(priv->net_dev, IPW_REG_RESET_REG, ®);
1540 if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED)
1545 printk(KERN_WARNING DRV_NAME
1546 ": %s: Could now power down adapter.\n",
1547 priv->net_dev->name);
1549 /* assert s/w reset */
1550 write_register(priv->net_dev, IPW_REG_RESET_REG,
1551 IPW_AUX_HOST_RESET_REG_SW_RESET);
1553 priv->status &= ~(STATUS_RUNNING | STATUS_STOPPING);
1558 static int ipw2100_disable_adapter(struct ipw2100_priv *priv)
1560 struct host_command cmd = {
1561 .host_command = CARD_DISABLE,
1562 .host_command_sequence = 0,
1563 .host_command_length = 0
1567 IPW_DEBUG_HC("CARD_DISABLE\n");
1569 if (!(priv->status & STATUS_ENABLED))
1572 /* Make sure we clear the associated state */
1573 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1575 if (!priv->stop_hang_check) {
1576 priv->stop_hang_check = 1;
1577 cancel_delayed_work(&priv->hang_check);
1580 mutex_lock(&priv->adapter_mutex);
1582 err = ipw2100_hw_send_command(priv, &cmd);
1584 printk(KERN_WARNING DRV_NAME
1585 ": exit - failed to send CARD_DISABLE command\n");
1589 err = ipw2100_wait_for_card_state(priv, IPW_HW_STATE_DISABLED);
1591 printk(KERN_WARNING DRV_NAME
1592 ": exit - card failed to change to DISABLED\n");
1596 IPW_DEBUG_INFO("TODO: implement scan state machine\n");
1599 mutex_unlock(&priv->adapter_mutex);
1603 static int ipw2100_set_scan_options(struct ipw2100_priv *priv)
1605 struct host_command cmd = {
1606 .host_command = SET_SCAN_OPTIONS,
1607 .host_command_sequence = 0,
1608 .host_command_length = 8
1612 IPW_DEBUG_INFO("enter\n");
1614 IPW_DEBUG_SCAN("setting scan options\n");
1616 cmd.host_command_parameters[0] = 0;
1618 if (!(priv->config & CFG_ASSOCIATE))
1619 cmd.host_command_parameters[0] |= IPW_SCAN_NOASSOCIATE;
1620 if ((priv->ieee->sec.flags & SEC_ENABLED) && priv->ieee->sec.enabled)
1621 cmd.host_command_parameters[0] |= IPW_SCAN_MIXED_CELL;
1622 if (priv->config & CFG_PASSIVE_SCAN)
1623 cmd.host_command_parameters[0] |= IPW_SCAN_PASSIVE;
1625 cmd.host_command_parameters[1] = priv->channel_mask;
1627 err = ipw2100_hw_send_command(priv, &cmd);
1629 IPW_DEBUG_HC("SET_SCAN_OPTIONS 0x%04X\n",
1630 cmd.host_command_parameters[0]);
1635 static int ipw2100_start_scan(struct ipw2100_priv *priv)
1637 struct host_command cmd = {
1638 .host_command = BROADCAST_SCAN,
1639 .host_command_sequence = 0,
1640 .host_command_length = 4
1644 IPW_DEBUG_HC("START_SCAN\n");
1646 cmd.host_command_parameters[0] = 0;
1648 /* No scanning if in monitor mode */
1649 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
1652 if (priv->status & STATUS_SCANNING) {
1653 IPW_DEBUG_SCAN("Scan requested while already in scan...\n");
1657 IPW_DEBUG_INFO("enter\n");
1659 /* Not clearing here; doing so makes iwlist always return nothing...
1661 * We should modify the table logic to use aging tables vs. clearing
1662 * the table on each scan start.
1664 IPW_DEBUG_SCAN("starting scan\n");
1666 priv->status |= STATUS_SCANNING;
1667 err = ipw2100_hw_send_command(priv, &cmd);
1669 priv->status &= ~STATUS_SCANNING;
1671 IPW_DEBUG_INFO("exit\n");
1676 static const struct ieee80211_geo ipw_geos[] = {
1680 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
1681 {2427, 4}, {2432, 5}, {2437, 6},
1682 {2442, 7}, {2447, 8}, {2452, 9},
1683 {2457, 10}, {2462, 11}, {2467, 12},
1684 {2472, 13}, {2484, 14}},
1688 static int ipw2100_up(struct ipw2100_priv *priv, int deferred)
1690 unsigned long flags;
1693 u32 ord_len = sizeof(lock);
1695 /* Quite if manually disabled. */
1696 if (priv->status & STATUS_RF_KILL_SW) {
1697 IPW_DEBUG_INFO("%s: Radio is disabled by Manual Disable "
1698 "switch\n", priv->net_dev->name);
1702 /* If the interrupt is enabled, turn it off... */
1703 spin_lock_irqsave(&priv->low_lock, flags);
1704 ipw2100_disable_interrupts(priv);
1706 /* Reset any fatal_error conditions */
1707 ipw2100_reset_fatalerror(priv);
1708 spin_unlock_irqrestore(&priv->low_lock, flags);
1710 if (priv->status & STATUS_POWERED ||
1711 (priv->status & STATUS_RESET_PENDING)) {
1712 /* Power cycle the card ... */
1713 if (ipw2100_power_cycle_adapter(priv)) {
1714 printk(KERN_WARNING DRV_NAME
1715 ": %s: Could not cycle adapter.\n",
1716 priv->net_dev->name);
1721 priv->status |= STATUS_POWERED;
1723 /* Load the firmware, start the clocks, etc. */
1724 if (ipw2100_start_adapter(priv)) {
1725 printk(KERN_ERR DRV_NAME
1726 ": %s: Failed to start the firmware.\n",
1727 priv->net_dev->name);
1732 ipw2100_initialize_ordinals(priv);
1734 /* Determine capabilities of this particular HW configuration */
1735 if (ipw2100_get_hw_features(priv)) {
1736 printk(KERN_ERR DRV_NAME
1737 ": %s: Failed to determine HW features.\n",
1738 priv->net_dev->name);
1743 /* Initialize the geo */
1744 if (ieee80211_set_geo(priv->ieee, &ipw_geos[0])) {
1745 printk(KERN_WARNING DRV_NAME "Could not set geo\n");
1748 priv->ieee->freq_band = IEEE80211_24GHZ_BAND;
1751 if (ipw2100_set_ordinal(priv, IPW_ORD_PERS_DB_LOCK, &lock, &ord_len)) {
1752 printk(KERN_ERR DRV_NAME
1753 ": %s: Failed to clear ordinal lock.\n",
1754 priv->net_dev->name);
1759 priv->status &= ~STATUS_SCANNING;
1761 if (rf_kill_active(priv)) {
1762 printk(KERN_INFO "%s: Radio is disabled by RF switch.\n",
1763 priv->net_dev->name);
1765 if (priv->stop_rf_kill) {
1766 priv->stop_rf_kill = 0;
1767 queue_delayed_work(priv->workqueue, &priv->rf_kill, HZ);
1773 /* Turn on the interrupt so that commands can be processed */
1774 ipw2100_enable_interrupts(priv);
1776 /* Send all of the commands that must be sent prior to
1778 if (ipw2100_adapter_setup(priv)) {
1779 printk(KERN_ERR DRV_NAME ": %s: Failed to start the card.\n",
1780 priv->net_dev->name);
1786 /* Enable the adapter - sends HOST_COMPLETE */
1787 if (ipw2100_enable_adapter(priv)) {
1788 printk(KERN_ERR DRV_NAME ": "
1789 "%s: failed in call to enable adapter.\n",
1790 priv->net_dev->name);
1791 ipw2100_hw_stop_adapter(priv);
1796 /* Start a scan . . . */
1797 ipw2100_set_scan_options(priv);
1798 ipw2100_start_scan(priv);
1805 /* Called by register_netdev() */
1806 static int ipw2100_net_init(struct net_device *dev)
1808 struct ipw2100_priv *priv = ieee80211_priv(dev);
1809 return ipw2100_up(priv, 1);
1812 static void ipw2100_down(struct ipw2100_priv *priv)
1814 unsigned long flags;
1815 union iwreq_data wrqu = {
1817 .sa_family = ARPHRD_ETHER}
1819 int associated = priv->status & STATUS_ASSOCIATED;
1821 /* Kill the RF switch timer */
1822 if (!priv->stop_rf_kill) {
1823 priv->stop_rf_kill = 1;
1824 cancel_delayed_work(&priv->rf_kill);
1827 /* Kill the firmare hang check timer */
1828 if (!priv->stop_hang_check) {
1829 priv->stop_hang_check = 1;
1830 cancel_delayed_work(&priv->hang_check);
1833 /* Kill any pending resets */
1834 if (priv->status & STATUS_RESET_PENDING)
1835 cancel_delayed_work(&priv->reset_work);
1837 /* Make sure the interrupt is on so that FW commands will be
1838 * processed correctly */
1839 spin_lock_irqsave(&priv->low_lock, flags);
1840 ipw2100_enable_interrupts(priv);
1841 spin_unlock_irqrestore(&priv->low_lock, flags);
1843 if (ipw2100_hw_stop_adapter(priv))
1844 printk(KERN_ERR DRV_NAME ": %s: Error stopping adapter.\n",
1845 priv->net_dev->name);
1847 /* Do not disable the interrupt until _after_ we disable
1848 * the adaptor. Otherwise the CARD_DISABLE command will never
1849 * be ack'd by the firmware */
1850 spin_lock_irqsave(&priv->low_lock, flags);
1851 ipw2100_disable_interrupts(priv);
1852 spin_unlock_irqrestore(&priv->low_lock, flags);
1854 #ifdef ACPI_CSTATE_LIMIT_DEFINED
1855 if (priv->config & CFG_C3_DISABLED) {
1856 IPW_DEBUG_INFO(": Resetting C3 transitions.\n");
1857 acpi_set_cstate_limit(priv->cstate_limit);
1858 priv->config &= ~CFG_C3_DISABLED;
1862 /* We have to signal any supplicant if we are disassociating */
1864 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1866 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1867 netif_carrier_off(priv->net_dev);
1868 netif_stop_queue(priv->net_dev);
1871 static void ipw2100_reset_adapter(struct ipw2100_priv *priv)
1873 unsigned long flags;
1874 union iwreq_data wrqu = {
1876 .sa_family = ARPHRD_ETHER}
1878 int associated = priv->status & STATUS_ASSOCIATED;
1880 spin_lock_irqsave(&priv->low_lock, flags);
1881 IPW_DEBUG_INFO(": %s: Restarting adapter.\n", priv->net_dev->name);
1883 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1884 priv->status |= STATUS_SECURITY_UPDATED;
1886 /* Force a power cycle even if interface hasn't been opened
1888 cancel_delayed_work(&priv->reset_work);
1889 priv->status |= STATUS_RESET_PENDING;
1890 spin_unlock_irqrestore(&priv->low_lock, flags);
1892 mutex_lock(&priv->action_mutex);
1893 /* stop timed checks so that they don't interfere with reset */
1894 priv->stop_hang_check = 1;
1895 cancel_delayed_work(&priv->hang_check);
1897 /* We have to signal any supplicant if we are disassociating */
1899 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1901 ipw2100_up(priv, 0);
1902 mutex_unlock(&priv->action_mutex);
1906 static void isr_indicate_associated(struct ipw2100_priv *priv, u32 status)
1909 #define MAC_ASSOCIATION_READ_DELAY (HZ)
1910 int ret, len, essid_len;
1911 char essid[IW_ESSID_MAX_SIZE];
1918 * TBD: BSSID is usually 00:00:00:00:00:00 here and not
1919 * an actual MAC of the AP. Seems like FW sets this
1920 * address too late. Read it later and expose through
1921 * /proc or schedule a later task to query and update
1924 essid_len = IW_ESSID_MAX_SIZE;
1925 ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_SSID,
1928 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
1934 ret = ipw2100_get_ordinal(priv, IPW_ORD_CURRENT_TX_RATE, &txrate, &len);
1936 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
1942 ret = ipw2100_get_ordinal(priv, IPW_ORD_OUR_FREQ, &chan, &len);
1944 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
1949 ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID, &bssid, &len);
1951 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
1955 memcpy(priv->ieee->bssid, bssid, ETH_ALEN);
1958 case TX_RATE_1_MBIT:
1959 txratename = "1Mbps";
1961 case TX_RATE_2_MBIT:
1962 txratename = "2Mbsp";
1964 case TX_RATE_5_5_MBIT:
1965 txratename = "5.5Mbps";
1967 case TX_RATE_11_MBIT:
1968 txratename = "11Mbps";
1971 IPW_DEBUG_INFO("Unknown rate: %d\n", txrate);
1972 txratename = "unknown rate";
1976 IPW_DEBUG_INFO("%s: Associated with '%s' at %s, channel %d (BSSID="
1978 priv->net_dev->name, escape_essid(essid, essid_len),
1979 txratename, chan, MAC_ARG(bssid));
1981 /* now we copy read ssid into dev */
1982 if (!(priv->config & CFG_STATIC_ESSID)) {
1983 priv->essid_len = min((u8) essid_len, (u8) IW_ESSID_MAX_SIZE);
1984 memcpy(priv->essid, essid, priv->essid_len);
1986 priv->channel = chan;
1987 memcpy(priv->bssid, bssid, ETH_ALEN);
1989 priv->status |= STATUS_ASSOCIATING;
1990 priv->connect_start = get_seconds();
1992 queue_delayed_work(priv->workqueue, &priv->wx_event_work, HZ / 10);
1995 static int ipw2100_set_essid(struct ipw2100_priv *priv, char *essid,
1996 int length, int batch_mode)
1998 int ssid_len = min(length, IW_ESSID_MAX_SIZE);
1999 struct host_command cmd = {
2000 .host_command = SSID,
2001 .host_command_sequence = 0,
2002 .host_command_length = ssid_len
2006 IPW_DEBUG_HC("SSID: '%s'\n", escape_essid(essid, ssid_len));
2009 memcpy(cmd.host_command_parameters, essid, ssid_len);
2012 err = ipw2100_disable_adapter(priv);
2017 /* Bug in FW currently doesn't honor bit 0 in SET_SCAN_OPTIONS to
2018 * disable auto association -- so we cheat by setting a bogus SSID */
2019 if (!ssid_len && !(priv->config & CFG_ASSOCIATE)) {
2021 u8 *bogus = (u8 *) cmd.host_command_parameters;
2022 for (i = 0; i < IW_ESSID_MAX_SIZE; i++)
2023 bogus[i] = 0x18 + i;
2024 cmd.host_command_length = IW_ESSID_MAX_SIZE;
2027 /* NOTE: We always send the SSID command even if the provided ESSID is
2028 * the same as what we currently think is set. */
2030 err = ipw2100_hw_send_command(priv, &cmd);
2032 memset(priv->essid + ssid_len, 0, IW_ESSID_MAX_SIZE - ssid_len);
2033 memcpy(priv->essid, essid, ssid_len);
2034 priv->essid_len = ssid_len;
2038 if (ipw2100_enable_adapter(priv))
2045 static void isr_indicate_association_lost(struct ipw2100_priv *priv, u32 status)
2047 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | IPW_DL_ASSOC,
2048 "disassociated: '%s' " MAC_FMT " \n",
2049 escape_essid(priv->essid, priv->essid_len),
2050 MAC_ARG(priv->bssid));
2052 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
2054 if (priv->status & STATUS_STOPPING) {
2055 IPW_DEBUG_INFO("Card is stopping itself, discard ASSN_LOST.\n");
2059 memset(priv->bssid, 0, ETH_ALEN);
2060 memset(priv->ieee->bssid, 0, ETH_ALEN);
2062 netif_carrier_off(priv->net_dev);
2063 netif_stop_queue(priv->net_dev);
2065 if (!(priv->status & STATUS_RUNNING))
2068 if (priv->status & STATUS_SECURITY_UPDATED)
2069 queue_work(priv->workqueue, &priv->security_work);
2071 queue_work(priv->workqueue, &priv->wx_event_work);
2074 static void isr_indicate_rf_kill(struct ipw2100_priv *priv, u32 status)
2076 IPW_DEBUG_INFO("%s: RF Kill state changed to radio OFF.\n",
2077 priv->net_dev->name);
2079 /* RF_KILL is now enabled (else we wouldn't be here) */
2080 priv->status |= STATUS_RF_KILL_HW;
2082 #ifdef ACPI_CSTATE_LIMIT_DEFINED
2083 if (priv->config & CFG_C3_DISABLED) {
2084 IPW_DEBUG_INFO(": Resetting C3 transitions.\n");
2085 acpi_set_cstate_limit(priv->cstate_limit);
2086 priv->config &= ~CFG_C3_DISABLED;
2090 /* Make sure the RF Kill check timer is running */
2091 priv->stop_rf_kill = 0;
2092 cancel_delayed_work(&priv->rf_kill);
2093 queue_delayed_work(priv->workqueue, &priv->rf_kill, HZ);
2096 static void isr_scan_complete(struct ipw2100_priv *priv, u32 status)
2098 IPW_DEBUG_SCAN("scan complete\n");
2099 /* Age the scan results... */
2100 priv->ieee->scans++;
2101 priv->status &= ~STATUS_SCANNING;
2104 #ifdef CONFIG_IPW2100_DEBUG
2105 #define IPW2100_HANDLER(v, f) { v, f, # v }
2106 struct ipw2100_status_indicator {
2108 void (*cb) (struct ipw2100_priv * priv, u32 status);
2112 #define IPW2100_HANDLER(v, f) { v, f }
2113 struct ipw2100_status_indicator {
2115 void (*cb) (struct ipw2100_priv * priv, u32 status);
2117 #endif /* CONFIG_IPW2100_DEBUG */
2119 static void isr_indicate_scanning(struct ipw2100_priv *priv, u32 status)
2121 IPW_DEBUG_SCAN("Scanning...\n");
2122 priv->status |= STATUS_SCANNING;
2125 static const struct ipw2100_status_indicator status_handlers[] = {
2126 IPW2100_HANDLER(IPW_STATE_INITIALIZED, NULL),
2127 IPW2100_HANDLER(IPW_STATE_COUNTRY_FOUND, NULL),
2128 IPW2100_HANDLER(IPW_STATE_ASSOCIATED, isr_indicate_associated),
2129 IPW2100_HANDLER(IPW_STATE_ASSN_LOST, isr_indicate_association_lost),
2130 IPW2100_HANDLER(IPW_STATE_ASSN_CHANGED, NULL),
2131 IPW2100_HANDLER(IPW_STATE_SCAN_COMPLETE, isr_scan_complete),
2132 IPW2100_HANDLER(IPW_STATE_ENTERED_PSP, NULL),
2133 IPW2100_HANDLER(IPW_STATE_LEFT_PSP, NULL),
2134 IPW2100_HANDLER(IPW_STATE_RF_KILL, isr_indicate_rf_kill),
2135 IPW2100_HANDLER(IPW_STATE_DISABLED, NULL),
2136 IPW2100_HANDLER(IPW_STATE_POWER_DOWN, NULL),
2137 IPW2100_HANDLER(IPW_STATE_SCANNING, isr_indicate_scanning),
2138 IPW2100_HANDLER(-1, NULL)
2141 static void isr_status_change(struct ipw2100_priv *priv, int status)
2145 if (status == IPW_STATE_SCANNING &&
2146 priv->status & STATUS_ASSOCIATED &&
2147 !(priv->status & STATUS_SCANNING)) {
2148 IPW_DEBUG_INFO("Scan detected while associated, with "
2149 "no scan request. Restarting firmware.\n");
2151 /* Wake up any sleeping jobs */
2152 schedule_reset(priv);
2155 for (i = 0; status_handlers[i].status != -1; i++) {
2156 if (status == status_handlers[i].status) {
2157 IPW_DEBUG_NOTIF("Status change: %s\n",
2158 status_handlers[i].name);
2159 if (status_handlers[i].cb)
2160 status_handlers[i].cb(priv, status);
2161 priv->wstats.status = status;
2166 IPW_DEBUG_NOTIF("unknown status received: %04x\n", status);
2169 static void isr_rx_complete_command(struct ipw2100_priv *priv,
2170 struct ipw2100_cmd_header *cmd)
2172 #ifdef CONFIG_IPW2100_DEBUG
2173 if (cmd->host_command_reg < ARRAY_SIZE(command_types)) {
2174 IPW_DEBUG_HC("Command completed '%s (%d)'\n",
2175 command_types[cmd->host_command_reg],
2176 cmd->host_command_reg);
2179 if (cmd->host_command_reg == HOST_COMPLETE)
2180 priv->status |= STATUS_ENABLED;
2182 if (cmd->host_command_reg == CARD_DISABLE)
2183 priv->status &= ~STATUS_ENABLED;
2185 priv->status &= ~STATUS_CMD_ACTIVE;
2187 wake_up_interruptible(&priv->wait_command_queue);
2190 #ifdef CONFIG_IPW2100_DEBUG
2191 static const char *frame_types[] = {
2192 "COMMAND_STATUS_VAL",
2193 "STATUS_CHANGE_VAL",
2196 "HOST_NOTIFICATION_VAL"
2200 static int ipw2100_alloc_skb(struct ipw2100_priv *priv,
2201 struct ipw2100_rx_packet *packet)
2203 packet->skb = dev_alloc_skb(sizeof(struct ipw2100_rx));
2207 packet->rxp = (struct ipw2100_rx *)packet->skb->data;
2208 packet->dma_addr = pci_map_single(priv->pci_dev, packet->skb->data,
2209 sizeof(struct ipw2100_rx),
2210 PCI_DMA_FROMDEVICE);
2211 /* NOTE: pci_map_single does not return an error code, and 0 is a valid
2217 #define SEARCH_ERROR 0xffffffff
2218 #define SEARCH_FAIL 0xfffffffe
2219 #define SEARCH_SUCCESS 0xfffffff0
2220 #define SEARCH_DISCARD 0
2221 #define SEARCH_SNAPSHOT 1
2223 #define SNAPSHOT_ADDR(ofs) (priv->snapshot[((ofs) >> 12) & 0xff] + ((ofs) & 0xfff))
2224 static void ipw2100_snapshot_free(struct ipw2100_priv *priv)
2227 if (!priv->snapshot[0])
2229 for (i = 0; i < 0x30; i++)
2230 kfree(priv->snapshot[i]);
2231 priv->snapshot[0] = NULL;
2234 #ifdef CONFIG_IPW2100_DEBUG_C3
2235 static int ipw2100_snapshot_alloc(struct ipw2100_priv *priv)
2238 if (priv->snapshot[0])
2240 for (i = 0; i < 0x30; i++) {
2241 priv->snapshot[i] = (u8 *) kmalloc(0x1000, GFP_ATOMIC);
2242 if (!priv->snapshot[i]) {
2243 IPW_DEBUG_INFO("%s: Error allocating snapshot "
2244 "buffer %d\n", priv->net_dev->name, i);
2246 kfree(priv->snapshot[--i]);
2247 priv->snapshot[0] = NULL;
2255 static u32 ipw2100_match_buf(struct ipw2100_priv *priv, u8 * in_buf,
2256 size_t len, int mode)
2264 if (mode == SEARCH_SNAPSHOT) {
2265 if (!ipw2100_snapshot_alloc(priv))
2266 mode = SEARCH_DISCARD;
2269 for (ret = SEARCH_FAIL, i = 0; i < 0x30000; i += 4) {
2270 read_nic_dword(priv->net_dev, i, &tmp);
2271 if (mode == SEARCH_SNAPSHOT)
2272 *(u32 *) SNAPSHOT_ADDR(i) = tmp;
2273 if (ret == SEARCH_FAIL) {
2275 for (j = 0; j < 4; j++) {
2284 if ((s - in_buf) == len)
2285 ret = (i + j) - len + 1;
2287 } else if (mode == SEARCH_DISCARD)
2297 * 0) Disconnect the SKB from the firmware (just unmap)
2298 * 1) Pack the ETH header into the SKB
2299 * 2) Pass the SKB to the network stack
2301 * When packet is provided by the firmware, it contains the following:
2304 * . ieee80211_snap_hdr
2306 * The size of the constructed ethernet
2309 #ifdef CONFIG_IPW2100_RX_DEBUG
2310 static u8 packet_data[IPW_RX_NIC_BUFFER_LENGTH];
2313 static void ipw2100_corruption_detected(struct ipw2100_priv *priv, int i)
2315 #ifdef CONFIG_IPW2100_DEBUG_C3
2316 struct ipw2100_status *status = &priv->status_queue.drv[i];
2320 #ifdef ACPI_CSTATE_LIMIT_DEFINED
2324 IPW_DEBUG_INFO(": PCI latency error detected at 0x%04zX.\n",
2325 i * sizeof(struct ipw2100_status));
2327 #ifdef ACPI_CSTATE_LIMIT_DEFINED
2328 IPW_DEBUG_INFO(": Disabling C3 transitions.\n");
2329 limit = acpi_get_cstate_limit();
2331 priv->cstate_limit = limit;
2332 acpi_set_cstate_limit(2);
2333 priv->config |= CFG_C3_DISABLED;
2337 #ifdef CONFIG_IPW2100_DEBUG_C3
2338 /* Halt the fimrware so we can get a good image */
2339 write_register(priv->net_dev, IPW_REG_RESET_REG,
2340 IPW_AUX_HOST_RESET_REG_STOP_MASTER);
2343 udelay(IPW_WAIT_RESET_MASTER_ASSERT_COMPLETE_DELAY);
2344 read_register(priv->net_dev, IPW_REG_RESET_REG, ®);
2346 if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED)
2350 match = ipw2100_match_buf(priv, (u8 *) status,
2351 sizeof(struct ipw2100_status),
2353 if (match < SEARCH_SUCCESS)
2354 IPW_DEBUG_INFO("%s: DMA status match in Firmware at "
2355 "offset 0x%06X, length %d:\n",
2356 priv->net_dev->name, match,
2357 sizeof(struct ipw2100_status));
2359 IPW_DEBUG_INFO("%s: No DMA status match in "
2360 "Firmware.\n", priv->net_dev->name);
2362 printk_buf((u8 *) priv->status_queue.drv,
2363 sizeof(struct ipw2100_status) * RX_QUEUE_LENGTH);
2366 priv->fatal_error = IPW2100_ERR_C3_CORRUPTION;
2367 priv->ieee->stats.rx_errors++;
2368 schedule_reset(priv);
2371 static void isr_rx(struct ipw2100_priv *priv, int i,
2372 struct ieee80211_rx_stats *stats)
2374 struct ipw2100_status *status = &priv->status_queue.drv[i];
2375 struct ipw2100_rx_packet *packet = &priv->rx_buffers[i];
2377 IPW_DEBUG_RX("Handler...\n");
2379 if (unlikely(status->frame_size > skb_tailroom(packet->skb))) {
2380 IPW_DEBUG_INFO("%s: frame_size (%u) > skb_tailroom (%u)!"
2382 priv->net_dev->name,
2383 status->frame_size, skb_tailroom(packet->skb));
2384 priv->ieee->stats.rx_errors++;
2388 if (unlikely(!netif_running(priv->net_dev))) {
2389 priv->ieee->stats.rx_errors++;
2390 priv->wstats.discard.misc++;
2391 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
2395 if (unlikely(priv->ieee->iw_mode != IW_MODE_MONITOR &&
2396 !(priv->status & STATUS_ASSOCIATED))) {
2397 IPW_DEBUG_DROP("Dropping packet while not associated.\n");
2398 priv->wstats.discard.misc++;
2402 pci_unmap_single(priv->pci_dev,
2404 sizeof(struct ipw2100_rx), PCI_DMA_FROMDEVICE);
2406 skb_put(packet->skb, status->frame_size);
2408 #ifdef CONFIG_IPW2100_RX_DEBUG
2409 /* Make a copy of the frame so we can dump it to the logs if
2410 * ieee80211_rx fails */
2411 memcpy(packet_data, packet->skb->data,
2412 min_t(u32, status->frame_size, IPW_RX_NIC_BUFFER_LENGTH));
2415 if (!ieee80211_rx(priv->ieee, packet->skb, stats)) {
2416 #ifdef CONFIG_IPW2100_RX_DEBUG
2417 IPW_DEBUG_DROP("%s: Non consumed packet:\n",
2418 priv->net_dev->name);
2419 printk_buf(IPW_DL_DROP, packet_data, status->frame_size);
2421 priv->ieee->stats.rx_errors++;
2423 /* ieee80211_rx failed, so it didn't free the SKB */
2424 dev_kfree_skb_any(packet->skb);
2428 /* We need to allocate a new SKB and attach it to the RDB. */
2429 if (unlikely(ipw2100_alloc_skb(priv, packet))) {
2430 printk(KERN_WARNING DRV_NAME ": "
2431 "%s: Unable to allocate SKB onto RBD ring - disabling "
2432 "adapter.\n", priv->net_dev->name);
2433 /* TODO: schedule adapter shutdown */
2434 IPW_DEBUG_INFO("TODO: Shutdown adapter...\n");
2437 /* Update the RDB entry */
2438 priv->rx_queue.drv[i].host_addr = packet->dma_addr;
2441 #ifdef CONFIG_IPW2100_MONITOR
2443 static void isr_rx_monitor(struct ipw2100_priv *priv, int i,
2444 struct ieee80211_rx_stats *stats)
2446 struct ipw2100_status *status = &priv->status_queue.drv[i];
2447 struct ipw2100_rx_packet *packet = &priv->rx_buffers[i];
2449 /* Magic struct that slots into the radiotap header -- no reason
2450 * to build this manually element by element, we can write it much
2451 * more efficiently than we can parse it. ORDER MATTERS HERE */
2453 struct ieee80211_radiotap_header rt_hdr;
2454 s8 rt_dbmsignal; /* signal in dbM, kluged to signed */
2457 IPW_DEBUG_RX("Handler...\n");
2459 if (unlikely(status->frame_size > skb_tailroom(packet->skb) -
2460 sizeof(struct ipw_rt_hdr))) {
2461 IPW_DEBUG_INFO("%s: frame_size (%u) > skb_tailroom (%u)!"
2463 priv->net_dev->name,
2465 skb_tailroom(packet->skb));
2466 priv->ieee->stats.rx_errors++;
2470 if (unlikely(!netif_running(priv->net_dev))) {
2471 priv->ieee->stats.rx_errors++;
2472 priv->wstats.discard.misc++;
2473 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
2477 if (unlikely(priv->config & CFG_CRC_CHECK &&
2478 status->flags & IPW_STATUS_FLAG_CRC_ERROR)) {
2479 IPW_DEBUG_RX("CRC error in packet. Dropping.\n");
2480 priv->ieee->stats.rx_errors++;
2484 pci_unmap_single(priv->pci_dev, packet->dma_addr,
2485 sizeof(struct ipw2100_rx), PCI_DMA_FROMDEVICE);
2486 memmove(packet->skb->data + sizeof(struct ipw_rt_hdr),
2487 packet->skb->data, status->frame_size);
2489 ipw_rt = (struct ipw_rt_hdr *) packet->skb->data;
2491 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
2492 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
2493 ipw_rt->rt_hdr.it_len = sizeof(struct ipw_rt_hdr); /* total hdr+data */
2495 ipw_rt->rt_hdr.it_present = 1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL;
2497 ipw_rt->rt_dbmsignal = status->rssi + IPW2100_RSSI_TO_DBM;
2499 skb_put(packet->skb, status->frame_size + sizeof(struct ipw_rt_hdr));
2501 if (!ieee80211_rx(priv->ieee, packet->skb, stats)) {
2502 priv->ieee->stats.rx_errors++;
2504 /* ieee80211_rx failed, so it didn't free the SKB */
2505 dev_kfree_skb_any(packet->skb);
2509 /* We need to allocate a new SKB and attach it to the RDB. */
2510 if (unlikely(ipw2100_alloc_skb(priv, packet))) {
2512 "%s: Unable to allocate SKB onto RBD ring - disabling "
2513 "adapter.\n", priv->net_dev->name);
2514 /* TODO: schedule adapter shutdown */
2515 IPW_DEBUG_INFO("TODO: Shutdown adapter...\n");
2518 /* Update the RDB entry */
2519 priv->rx_queue.drv[i].host_addr = packet->dma_addr;
2524 static int ipw2100_corruption_check(struct ipw2100_priv *priv, int i)
2526 struct ipw2100_status *status = &priv->status_queue.drv[i];
2527 struct ipw2100_rx *u = priv->rx_buffers[i].rxp;
2528 u16 frame_type = status->status_fields & STATUS_TYPE_MASK;
2530 switch (frame_type) {
2531 case COMMAND_STATUS_VAL:
2532 return (status->frame_size != sizeof(u->rx_data.command));
2533 case STATUS_CHANGE_VAL:
2534 return (status->frame_size != sizeof(u->rx_data.status));
2535 case HOST_NOTIFICATION_VAL:
2536 return (status->frame_size < sizeof(u->rx_data.notification));
2537 case P80211_DATA_VAL:
2538 case P8023_DATA_VAL:
2539 #ifdef CONFIG_IPW2100_MONITOR
2542 switch (WLAN_FC_GET_TYPE(u->rx_data.header.frame_ctl)) {
2543 case IEEE80211_FTYPE_MGMT:
2544 case IEEE80211_FTYPE_CTL:
2546 case IEEE80211_FTYPE_DATA:
2547 return (status->frame_size >
2548 IPW_MAX_802_11_PAYLOAD_LENGTH);
2557 * ipw2100 interrupts are disabled at this point, and the ISR
2558 * is the only code that calls this method. So, we do not need
2559 * to play with any locks.
2561 * RX Queue works as follows:
2563 * Read index - firmware places packet in entry identified by the
2564 * Read index and advances Read index. In this manner,
2565 * Read index will always point to the next packet to
2566 * be filled--but not yet valid.
2568 * Write index - driver fills this entry with an unused RBD entry.
2569 * This entry has not filled by the firmware yet.
2571 * In between the W and R indexes are the RBDs that have been received
2572 * but not yet processed.
2574 * The process of handling packets will start at WRITE + 1 and advance
2575 * until it reaches the READ index.
2577 * The WRITE index is cached in the variable 'priv->rx_queue.next'.
2580 static void __ipw2100_rx_process(struct ipw2100_priv *priv)
2582 struct ipw2100_bd_queue *rxq = &priv->rx_queue;
2583 struct ipw2100_status_queue *sq = &priv->status_queue;
2584 struct ipw2100_rx_packet *packet;
2587 struct ipw2100_rx *u;
2588 struct ieee80211_rx_stats stats = {
2589 .mac_time = jiffies,
2592 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_READ_INDEX, &r);
2593 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_WRITE_INDEX, &w);
2595 if (r >= rxq->entries) {
2596 IPW_DEBUG_RX("exit - bad read index\n");
2600 i = (rxq->next + 1) % rxq->entries;
2603 /* IPW_DEBUG_RX("r = %d : w = %d : processing = %d\n",
2604 r, rxq->next, i); */
2606 packet = &priv->rx_buffers[i];
2608 /* Sync the DMA for the STATUS buffer so CPU is sure to get
2609 * the correct values */
2610 pci_dma_sync_single_for_cpu(priv->pci_dev,
2612 sizeof(struct ipw2100_status) * i,
2613 sizeof(struct ipw2100_status),
2614 PCI_DMA_FROMDEVICE);
2616 /* Sync the DMA for the RX buffer so CPU is sure to get
2617 * the correct values */
2618 pci_dma_sync_single_for_cpu(priv->pci_dev, packet->dma_addr,
2619 sizeof(struct ipw2100_rx),
2620 PCI_DMA_FROMDEVICE);
2622 if (unlikely(ipw2100_corruption_check(priv, i))) {
2623 ipw2100_corruption_detected(priv, i);
2628 frame_type = sq->drv[i].status_fields & STATUS_TYPE_MASK;
2629 stats.rssi = sq->drv[i].rssi + IPW2100_RSSI_TO_DBM;
2630 stats.len = sq->drv[i].frame_size;
2633 if (stats.rssi != 0)
2634 stats.mask |= IEEE80211_STATMASK_RSSI;
2635 stats.freq = IEEE80211_24GHZ_BAND;
2637 IPW_DEBUG_RX("%s: '%s' frame type received (%d).\n",
2638 priv->net_dev->name, frame_types[frame_type],
2641 switch (frame_type) {
2642 case COMMAND_STATUS_VAL:
2643 /* Reset Rx watchdog */
2644 isr_rx_complete_command(priv, &u->rx_data.command);
2647 case STATUS_CHANGE_VAL:
2648 isr_status_change(priv, u->rx_data.status);
2651 case P80211_DATA_VAL:
2652 case P8023_DATA_VAL:
2653 #ifdef CONFIG_IPW2100_MONITOR
2654 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
2655 isr_rx_monitor(priv, i, &stats);
2659 if (stats.len < sizeof(u->rx_data.header))
2661 switch (WLAN_FC_GET_TYPE(u->rx_data.header.frame_ctl)) {
2662 case IEEE80211_FTYPE_MGMT:
2663 ieee80211_rx_mgt(priv->ieee,
2664 &u->rx_data.header, &stats);
2667 case IEEE80211_FTYPE_CTL:
2670 case IEEE80211_FTYPE_DATA:
2671 isr_rx(priv, i, &stats);
2679 /* clear status field associated with this RBD */
2680 rxq->drv[i].status.info.field = 0;
2682 i = (i + 1) % rxq->entries;
2686 /* backtrack one entry, wrapping to end if at 0 */
2687 rxq->next = (i ? i : rxq->entries) - 1;
2689 write_register(priv->net_dev,
2690 IPW_MEM_HOST_SHARED_RX_WRITE_INDEX, rxq->next);
2695 * __ipw2100_tx_process
2697 * This routine will determine whether the next packet on
2698 * the fw_pend_list has been processed by the firmware yet.
2700 * If not, then it does nothing and returns.
2702 * If so, then it removes the item from the fw_pend_list, frees
2703 * any associated storage, and places the item back on the
2704 * free list of its source (either msg_free_list or tx_free_list)
2706 * TX Queue works as follows:
2708 * Read index - points to the next TBD that the firmware will
2709 * process. The firmware will read the data, and once
2710 * done processing, it will advance the Read index.
2712 * Write index - driver fills this entry with an constructed TBD
2713 * entry. The Write index is not advanced until the
2714 * packet has been configured.
2716 * In between the W and R indexes are the TBDs that have NOT been
2717 * processed. Lagging behind the R index are packets that have
2718 * been processed but have not been freed by the driver.
2720 * In order to free old storage, an internal index will be maintained
2721 * that points to the next packet to be freed. When all used
2722 * packets have been freed, the oldest index will be the same as the
2723 * firmware's read index.
2725 * The OLDEST index is cached in the variable 'priv->tx_queue.oldest'
2727 * Because the TBD structure can not contain arbitrary data, the
2728 * driver must keep an internal queue of cached allocations such that
2729 * it can put that data back into the tx_free_list and msg_free_list
2730 * for use by future command and data packets.
2733 static int __ipw2100_tx_process(struct ipw2100_priv *priv)
2735 struct ipw2100_bd_queue *txq = &priv->tx_queue;
2736 struct ipw2100_bd *tbd;
2737 struct list_head *element;
2738 struct ipw2100_tx_packet *packet;
2739 int descriptors_used;
2741 u32 r, w, frag_num = 0;
2743 if (list_empty(&priv->fw_pend_list))
2746 element = priv->fw_pend_list.next;
2748 packet = list_entry(element, struct ipw2100_tx_packet, list);
2749 tbd = &txq->drv[packet->index];
2751 /* Determine how many TBD entries must be finished... */
2752 switch (packet->type) {
2754 /* COMMAND uses only one slot; don't advance */
2755 descriptors_used = 1;
2760 /* DATA uses two slots; advance and loop position. */
2761 descriptors_used = tbd->num_fragments;
2762 frag_num = tbd->num_fragments - 1;
2763 e = txq->oldest + frag_num;
2768 printk(KERN_WARNING DRV_NAME ": %s: Bad fw_pend_list entry!\n",
2769 priv->net_dev->name);
2773 /* if the last TBD is not done by NIC yet, then packet is
2774 * not ready to be released.
2777 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_TX_QUEUE_READ_INDEX,
2779 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX,
2782 printk(KERN_WARNING DRV_NAME ": %s: write index mismatch\n",
2783 priv->net_dev->name);
2786 * txq->next is the index of the last packet written txq->oldest is
2787 * the index of the r is the index of the next packet to be read by
2792 * Quick graphic to help you visualize the following
2793 * if / else statement
2795 * ===>| s---->|===============
2797 * | a | b | c | d | e | f | g | h | i | j | k | l
2801 * w - updated by driver
2802 * r - updated by firmware
2803 * s - start of oldest BD entry (txq->oldest)
2804 * e - end of oldest BD entry
2807 if (!((r <= w && (e < r || e >= w)) || (e < r && e >= w))) {
2808 IPW_DEBUG_TX("exit - no processed packets ready to release.\n");
2813 DEC_STAT(&priv->fw_pend_stat);
2815 #ifdef CONFIG_IPW2100_DEBUG
2817 int i = txq->oldest;
2818 IPW_DEBUG_TX("TX%d V=%p P=%04X T=%04X L=%d\n", i,
2820 (u32) (txq->nic + i * sizeof(struct ipw2100_bd)),
2821 txq->drv[i].host_addr, txq->drv[i].buf_length);
2823 if (packet->type == DATA) {
2824 i = (i + 1) % txq->entries;
2826 IPW_DEBUG_TX("TX%d V=%p P=%04X T=%04X L=%d\n", i,
2828 (u32) (txq->nic + i *
2829 sizeof(struct ipw2100_bd)),
2830 (u32) txq->drv[i].host_addr,
2831 txq->drv[i].buf_length);
2836 switch (packet->type) {
2838 if (txq->drv[txq->oldest].status.info.fields.txType != 0)
2839 printk(KERN_WARNING DRV_NAME ": %s: Queue mismatch. "
2840 "Expecting DATA TBD but pulled "
2841 "something else: ids %d=%d.\n",
2842 priv->net_dev->name, txq->oldest, packet->index);
2844 /* DATA packet; we have to unmap and free the SKB */
2845 for (i = 0; i < frag_num; i++) {
2846 tbd = &txq->drv[(packet->index + 1 + i) % txq->entries];
2848 IPW_DEBUG_TX("TX%d P=%08x L=%d\n",
2849 (packet->index + 1 + i) % txq->entries,
2850 tbd->host_addr, tbd->buf_length);
2852 pci_unmap_single(priv->pci_dev,
2854 tbd->buf_length, PCI_DMA_TODEVICE);
2857 ieee80211_txb_free(packet->info.d_struct.txb);
2858 packet->info.d_struct.txb = NULL;
2860 list_add_tail(element, &priv->tx_free_list);
2861 INC_STAT(&priv->tx_free_stat);
2863 /* We have a free slot in the Tx queue, so wake up the
2864 * transmit layer if it is stopped. */
2865 if (priv->status & STATUS_ASSOCIATED)
2866 netif_wake_queue(priv->net_dev);
2868 /* A packet was processed by the hardware, so update the
2870 priv->net_dev->trans_start = jiffies;
2875 if (txq->drv[txq->oldest].status.info.fields.txType != 1)
2876 printk(KERN_WARNING DRV_NAME ": %s: Queue mismatch. "
2877 "Expecting COMMAND TBD but pulled "
2878 "something else: ids %d=%d.\n",
2879 priv->net_dev->name, txq->oldest, packet->index);
2881 #ifdef CONFIG_IPW2100_DEBUG
2882 if (packet->info.c_struct.cmd->host_command_reg <
2883 sizeof(command_types) / sizeof(*command_types))
2884 IPW_DEBUG_TX("Command '%s (%d)' processed: %d.\n",
2885 command_types[packet->info.c_struct.cmd->
2887 packet->info.c_struct.cmd->
2889 packet->info.c_struct.cmd->cmd_status_reg);
2892 list_add_tail(element, &priv->msg_free_list);
2893 INC_STAT(&priv->msg_free_stat);
2897 /* advance oldest used TBD pointer to start of next entry */
2898 txq->oldest = (e + 1) % txq->entries;
2899 /* increase available TBDs number */
2900 txq->available += descriptors_used;
2901 SET_STAT(&priv->txq_stat, txq->available);
2903 IPW_DEBUG_TX("packet latency (send to process) %ld jiffies\n",
2904 jiffies - packet->jiffy_start);
2906 return (!list_empty(&priv->fw_pend_list));
2909 static inline void __ipw2100_tx_complete(struct ipw2100_priv *priv)
2913 while (__ipw2100_tx_process(priv) && i < 200)
2917 printk(KERN_WARNING DRV_NAME ": "
2918 "%s: Driver is running slow (%d iters).\n",
2919 priv->net_dev->name, i);
2923 static void ipw2100_tx_send_commands(struct ipw2100_priv *priv)
2925 struct list_head *element;
2926 struct ipw2100_tx_packet *packet;
2927 struct ipw2100_bd_queue *txq = &priv->tx_queue;
2928 struct ipw2100_bd *tbd;
2929 int next = txq->next;
2931 while (!list_empty(&priv->msg_pend_list)) {
2932 /* if there isn't enough space in TBD queue, then
2933 * don't stuff a new one in.
2934 * NOTE: 3 are needed as a command will take one,
2935 * and there is a minimum of 2 that must be
2936 * maintained between the r and w indexes
2938 if (txq->available <= 3) {
2939 IPW_DEBUG_TX("no room in tx_queue\n");
2943 element = priv->msg_pend_list.next;
2945 DEC_STAT(&priv->msg_pend_stat);
2947 packet = list_entry(element, struct ipw2100_tx_packet, list);
2949 IPW_DEBUG_TX("using TBD at virt=%p, phys=%p\n",
2950 &txq->drv[txq->next],
2951 (void *)(txq->nic + txq->next *
2952 sizeof(struct ipw2100_bd)));
2954 packet->index = txq->next;
2956 tbd = &txq->drv[txq->next];
2958 /* initialize TBD */
2959 tbd->host_addr = packet->info.c_struct.cmd_phys;
2960 tbd->buf_length = sizeof(struct ipw2100_cmd_header);
2961 /* not marking number of fragments causes problems
2962 * with f/w debug version */
2963 tbd->num_fragments = 1;
2964 tbd->status.info.field =
2965 IPW_BD_STATUS_TX_FRAME_COMMAND |
2966 IPW_BD_STATUS_TX_INTERRUPT_ENABLE;
2968 /* update TBD queue counters */
2970 txq->next %= txq->entries;
2972 DEC_STAT(&priv->txq_stat);
2974 list_add_tail(element, &priv->fw_pend_list);
2975 INC_STAT(&priv->fw_pend_stat);
2978 if (txq->next != next) {
2979 /* kick off the DMA by notifying firmware the
2980 * write index has moved; make sure TBD stores are sync'd */
2982 write_register(priv->net_dev,
2983 IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX,
2989 * ipw2100_tx_send_data
2992 static void ipw2100_tx_send_data(struct ipw2100_priv *priv)
2994 struct list_head *element;
2995 struct ipw2100_tx_packet *packet;
2996 struct ipw2100_bd_queue *txq = &priv->tx_queue;
2997 struct ipw2100_bd *tbd;
2998 int next = txq->next;
3000 struct ipw2100_data_header *ipw_hdr;
3001 struct ieee80211_hdr_3addr *hdr;
3003 while (!list_empty(&priv->tx_pend_list)) {
3004 /* if there isn't enough space in TBD queue, then
3005 * don't stuff a new one in.
3006 * NOTE: 4 are needed as a data will take two,
3007 * and there is a minimum of 2 that must be
3008 * maintained between the r and w indexes
3010 element = priv->tx_pend_list.next;
3011 packet = list_entry(element, struct ipw2100_tx_packet, list);
3013 if (unlikely(1 + packet->info.d_struct.txb->nr_frags >
3015 /* TODO: Support merging buffers if more than
3016 * IPW_MAX_BDS are used */
3017 IPW_DEBUG_INFO("%s: Maximum BD theshold exceeded. "
3018 "Increase fragmentation level.\n",
3019 priv->net_dev->name);
3022 if (txq->available <= 3 + packet->info.d_struct.txb->nr_frags) {
3023 IPW_DEBUG_TX("no room in tx_queue\n");
3028 DEC_STAT(&priv->tx_pend_stat);
3030 tbd = &txq->drv[txq->next];
3032 packet->index = txq->next;
3034 ipw_hdr = packet->info.d_struct.data;
3035 hdr = (struct ieee80211_hdr_3addr *)packet->info.d_struct.txb->
3038 if (priv->ieee->iw_mode == IW_MODE_INFRA) {
3039 /* To DS: Addr1 = BSSID, Addr2 = SA,
3041 memcpy(ipw_hdr->src_addr, hdr->addr2, ETH_ALEN);
3042 memcpy(ipw_hdr->dst_addr, hdr->addr3, ETH_ALEN);
3043 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
3044 /* not From/To DS: Addr1 = DA, Addr2 = SA,
3046 memcpy(ipw_hdr->src_addr, hdr->addr2, ETH_ALEN);
3047 memcpy(ipw_hdr->dst_addr, hdr->addr1, ETH_ALEN);
3050 ipw_hdr->host_command_reg = SEND;
3051 ipw_hdr->host_command_reg1 = 0;
3053 /* For now we only support host based encryption */
3054 ipw_hdr->needs_encryption = 0;
3055 ipw_hdr->encrypted = packet->info.d_struct.txb->encrypted;
3056 if (packet->info.d_struct.txb->nr_frags > 1)
3057 ipw_hdr->fragment_size =
3058 packet->info.d_struct.txb->frag_size -
3059 IEEE80211_3ADDR_LEN;
3061 ipw_hdr->fragment_size = 0;
3063 tbd->host_addr = packet->info.d_struct.data_phys;
3064 tbd->buf_length = sizeof(struct ipw2100_data_header);
3065 tbd->num_fragments = 1 + packet->info.d_struct.txb->nr_frags;
3066 tbd->status.info.field =
3067 IPW_BD_STATUS_TX_FRAME_802_3 |
3068 IPW_BD_STATUS_TX_FRAME_NOT_LAST_FRAGMENT;
3070 txq->next %= txq->entries;
3072 IPW_DEBUG_TX("data header tbd TX%d P=%08x L=%d\n",
3073 packet->index, tbd->host_addr, tbd->buf_length);
3074 #ifdef CONFIG_IPW2100_DEBUG
3075 if (packet->info.d_struct.txb->nr_frags > 1)
3076 IPW_DEBUG_FRAG("fragment Tx: %d frames\n",
3077 packet->info.d_struct.txb->nr_frags);
3080 for (i = 0; i < packet->info.d_struct.txb->nr_frags; i++) {
3081 tbd = &txq->drv[txq->next];
3082 if (i == packet->info.d_struct.txb->nr_frags - 1)
3083 tbd->status.info.field =
3084 IPW_BD_STATUS_TX_FRAME_802_3 |
3085 IPW_BD_STATUS_TX_INTERRUPT_ENABLE;
3087 tbd->status.info.field =
3088 IPW_BD_STATUS_TX_FRAME_802_3 |
3089 IPW_BD_STATUS_TX_FRAME_NOT_LAST_FRAGMENT;
3091 tbd->buf_length = packet->info.d_struct.txb->
3092 fragments[i]->len - IEEE80211_3ADDR_LEN;
3094 tbd->host_addr = pci_map_single(priv->pci_dev,
3095 packet->info.d_struct.
3098 IEEE80211_3ADDR_LEN,
3102 IPW_DEBUG_TX("data frag tbd TX%d P=%08x L=%d\n",
3103 txq->next, tbd->host_addr,
3106 pci_dma_sync_single_for_device(priv->pci_dev,
3112 txq->next %= txq->entries;
3115 txq->available -= 1 + packet->info.d_struct.txb->nr_frags;
3116 SET_STAT(&priv->txq_stat, txq->available);
3118 list_add_tail(element, &priv->fw_pend_list);
3119 INC_STAT(&priv->fw_pend_stat);
3122 if (txq->next != next) {
3123 /* kick off the DMA by notifying firmware the
3124 * write index has moved; make sure TBD stores are sync'd */
3125 write_register(priv->net_dev,
3126 IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX,
3132 static void ipw2100_irq_tasklet(struct ipw2100_priv *priv)
3134 struct net_device *dev = priv->net_dev;
3135 unsigned long flags;
3138 spin_lock_irqsave(&priv->low_lock, flags);
3139 ipw2100_disable_interrupts(priv);
3141 read_register(dev, IPW_REG_INTA, &inta);
3143 IPW_DEBUG_ISR("enter - INTA: 0x%08lX\n",
3144 (unsigned long)inta & IPW_INTERRUPT_MASK);
3149 /* We do not loop and keep polling for more interrupts as this
3150 * is frowned upon and doesn't play nicely with other potentially
3152 IPW_DEBUG_ISR("INTA: 0x%08lX\n",
3153 (unsigned long)inta & IPW_INTERRUPT_MASK);
3155 if (inta & IPW2100_INTA_FATAL_ERROR) {
3156 printk(KERN_WARNING DRV_NAME
3157 ": Fatal interrupt. Scheduling firmware restart.\n");
3159 write_register(dev, IPW_REG_INTA, IPW2100_INTA_FATAL_ERROR);
3161 read_nic_dword(dev, IPW_NIC_FATAL_ERROR, &priv->fatal_error);
3162 IPW_DEBUG_INFO("%s: Fatal error value: 0x%08X\n",
3163 priv->net_dev->name, priv->fatal_error);
3165 read_nic_dword(dev, IPW_ERROR_ADDR(priv->fatal_error), &tmp);
3166 IPW_DEBUG_INFO("%s: Fatal error address value: 0x%08X\n",
3167 priv->net_dev->name, tmp);
3169 /* Wake up any sleeping jobs */
3170 schedule_reset(priv);
3173 if (inta & IPW2100_INTA_PARITY_ERROR) {
3174 printk(KERN_ERR DRV_NAME
3175 ": ***** PARITY ERROR INTERRUPT !!!! \n");
3177 write_register(dev, IPW_REG_INTA, IPW2100_INTA_PARITY_ERROR);
3180 if (inta & IPW2100_INTA_RX_TRANSFER) {
3181 IPW_DEBUG_ISR("RX interrupt\n");
3183 priv->rx_interrupts++;
3185 write_register(dev, IPW_REG_INTA, IPW2100_INTA_RX_TRANSFER);
3187 __ipw2100_rx_process(priv);
3188 __ipw2100_tx_complete(priv);
3191 if (inta & IPW2100_INTA_TX_TRANSFER) {
3192 IPW_DEBUG_ISR("TX interrupt\n");
3194 priv->tx_interrupts++;
3196 write_register(dev, IPW_REG_INTA, IPW2100_INTA_TX_TRANSFER);
3198 __ipw2100_tx_complete(priv);
3199 ipw2100_tx_send_commands(priv);
3200 ipw2100_tx_send_data(priv);
3203 if (inta & IPW2100_INTA_TX_COMPLETE) {
3204 IPW_DEBUG_ISR("TX complete\n");
3206 write_register(dev, IPW_REG_INTA, IPW2100_INTA_TX_COMPLETE);
3208 __ipw2100_tx_complete(priv);
3211 if (inta & IPW2100_INTA_EVENT_INTERRUPT) {
3212 /* ipw2100_handle_event(dev); */
3214 write_register(dev, IPW_REG_INTA, IPW2100_INTA_EVENT_INTERRUPT);
3217 if (inta & IPW2100_INTA_FW_INIT_DONE) {
3218 IPW_DEBUG_ISR("FW init done interrupt\n");
3221 read_register(dev, IPW_REG_INTA, &tmp);
3222 if (tmp & (IPW2100_INTA_FATAL_ERROR |
3223 IPW2100_INTA_PARITY_ERROR)) {
3224 write_register(dev, IPW_REG_INTA,
3225 IPW2100_INTA_FATAL_ERROR |
3226 IPW2100_INTA_PARITY_ERROR);
3229 write_register(dev, IPW_REG_INTA, IPW2100_INTA_FW_INIT_DONE);
3232 if (inta & IPW2100_INTA_STATUS_CHANGE) {
3233 IPW_DEBUG_ISR("Status change interrupt\n");
3235 write_register(dev, IPW_REG_INTA, IPW2100_INTA_STATUS_CHANGE);
3238 if (inta & IPW2100_INTA_SLAVE_MODE_HOST_COMMAND_DONE) {
3239 IPW_DEBUG_ISR("slave host mode interrupt\n");
3241 write_register(dev, IPW_REG_INTA,
3242 IPW2100_INTA_SLAVE_MODE_HOST_COMMAND_DONE);
3246 ipw2100_enable_interrupts(priv);
3248 spin_unlock_irqrestore(&priv->low_lock, flags);
3250 IPW_DEBUG_ISR("exit\n");
3253 static irqreturn_t ipw2100_interrupt(int irq, void *data, struct pt_regs *regs)
3255 struct ipw2100_priv *priv = data;
3256 u32 inta, inta_mask;
3261 spin_lock(&priv->low_lock);
3263 /* We check to see if we should be ignoring interrupts before
3264 * we touch the hardware. During ucode load if we try and handle
3265 * an interrupt we can cause keyboard problems as well as cause
3266 * the ucode to fail to initialize */
3267 if (!(priv->status & STATUS_INT_ENABLED)) {
3272 read_register(priv->net_dev, IPW_REG_INTA_MASK, &inta_mask);
3273 read_register(priv->net_dev, IPW_REG_INTA, &inta);
3275 if (inta == 0xFFFFFFFF) {
3276 /* Hardware disappeared */
3277 printk(KERN_WARNING DRV_NAME ": IRQ INTA == 0xFFFFFFFF\n");
3281 inta &= IPW_INTERRUPT_MASK;
3283 if (!(inta & inta_mask)) {
3284 /* Shared interrupt */
3288 /* We disable the hardware interrupt here just to prevent unneeded
3289 * calls to be made. We disable this again within the actual
3290 * work tasklet, so if another part of the code re-enables the
3291 * interrupt, that is fine */
3292 ipw2100_disable_interrupts(priv);
3294 tasklet_schedule(&priv->irq_tasklet);
3295 spin_unlock(&priv->low_lock);
3299 spin_unlock(&priv->low_lock);
3303 static int ipw2100_tx(struct ieee80211_txb *txb, struct net_device *dev,
3306 struct ipw2100_priv *priv = ieee80211_priv(dev);
3307 struct list_head *element;
3308 struct ipw2100_tx_packet *packet;
3309 unsigned long flags;
3311 spin_lock_irqsave(&priv->low_lock, flags);
3313 if (!(priv->status & STATUS_ASSOCIATED)) {
3314 IPW_DEBUG_INFO("Can not transmit when not connected.\n");
3315 priv->ieee->stats.tx_carrier_errors++;
3316 netif_stop_queue(dev);
3320 if (list_empty(&priv->tx_free_list))
3323 element = priv->tx_free_list.next;
3324 packet = list_entry(element, struct ipw2100_tx_packet, list);
3326 packet->info.d_struct.txb = txb;
3328 IPW_DEBUG_TX("Sending fragment (%d bytes):\n", txb->fragments[0]->len);
3329 printk_buf(IPW_DL_TX, txb->fragments[0]->data, txb->fragments[0]->len);
3331 packet->jiffy_start = jiffies;
3334 DEC_STAT(&priv->tx_free_stat);
3336 list_add_tail(element, &priv->tx_pend_list);
3337 INC_STAT(&priv->tx_pend_stat);
3339 ipw2100_tx_send_data(priv);
3341 spin_unlock_irqrestore(&priv->low_lock, flags);
3345 netif_stop_queue(dev);
3346 spin_unlock_irqrestore(&priv->low_lock, flags);
3350 static int ipw2100_msg_allocate(struct ipw2100_priv *priv)
3352 int i, j, err = -EINVAL;
3357 (struct ipw2100_tx_packet *)kmalloc(IPW_COMMAND_POOL_SIZE *
3361 if (!priv->msg_buffers) {
3362 printk(KERN_ERR DRV_NAME ": %s: PCI alloc failed for msg "
3363 "buffers.\n", priv->net_dev->name);
3367 for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++) {
3368 v = pci_alloc_consistent(priv->pci_dev,
3369 sizeof(struct ipw2100_cmd_header), &p);
3371 printk(KERN_ERR DRV_NAME ": "
3372 "%s: PCI alloc failed for msg "
3373 "buffers.\n", priv->net_dev->name);
3378 memset(v, 0, sizeof(struct ipw2100_cmd_header));
3380 priv->msg_buffers[i].type = COMMAND;
3381 priv->msg_buffers[i].info.c_struct.cmd =
3382 (struct ipw2100_cmd_header *)v;
3383 priv->msg_buffers[i].info.c_struct.cmd_phys = p;
3386 if (i == IPW_COMMAND_POOL_SIZE)
3389 for (j = 0; j < i; j++) {
3390 pci_free_consistent(priv->pci_dev,
3391 sizeof(struct ipw2100_cmd_header),
3392 priv->msg_buffers[j].info.c_struct.cmd,
3393 priv->msg_buffers[j].info.c_struct.
3397 kfree(priv->msg_buffers);
3398 priv->msg_buffers = NULL;
3403 static int ipw2100_msg_initialize(struct ipw2100_priv *priv)
3407 INIT_LIST_HEAD(&priv->msg_free_list);
3408 INIT_LIST_HEAD(&priv->msg_pend_list);
3410 for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++)
3411 list_add_tail(&priv->msg_buffers[i].list, &priv->msg_free_list);
3412 SET_STAT(&priv->msg_free_stat, i);
3417 static void ipw2100_msg_free(struct ipw2100_priv *priv)
3421 if (!priv->msg_buffers)
3424 for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++) {
3425 pci_free_consistent(priv->pci_dev,
3426 sizeof(struct ipw2100_cmd_header),
3427 priv->msg_buffers[i].info.c_struct.cmd,
3428 priv->msg_buffers[i].info.c_struct.
3432 kfree(priv->msg_buffers);
3433 priv->msg_buffers = NULL;
3436 static ssize_t show_pci(struct device *d, struct device_attribute *attr,
3439 struct pci_dev *pci_dev = container_of(d, struct pci_dev, dev);
3444 for (i = 0; i < 16; i++) {
3445 out += sprintf(out, "[%08X] ", i * 16);
3446 for (j = 0; j < 16; j += 4) {
3447 pci_read_config_dword(pci_dev, i * 16 + j, &val);
3448 out += sprintf(out, "%08X ", val);
3450 out += sprintf(out, "\n");
3456 static DEVICE_ATTR(pci, S_IRUGO, show_pci, NULL);
3458 static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
3461 struct ipw2100_priv *p = d->driver_data;
3462 return sprintf(buf, "0x%08x\n", (int)p->config);
3465 static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
3467 static ssize_t show_status(struct device *d, struct device_attribute *attr,
3470 struct ipw2100_priv *p = d->driver_data;
3471 return sprintf(buf, "0x%08x\n", (int)p->status);
3474 static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
3476 static ssize_t show_capability(struct device *d, struct device_attribute *attr,
3479 struct ipw2100_priv *p = d->driver_data;
3480 return sprintf(buf, "0x%08x\n", (int)p->capability);
3483 static DEVICE_ATTR(capability, S_IRUGO, show_capability, NULL);
3485 #define IPW2100_REG(x) { IPW_ ##x, #x }
3486 static const struct {
3490 IPW2100_REG(REG_GP_CNTRL),
3491 IPW2100_REG(REG_GPIO),
3492 IPW2100_REG(REG_INTA),
3493 IPW2100_REG(REG_INTA_MASK), IPW2100_REG(REG_RESET_REG),};
3494 #define IPW2100_NIC(x, s) { x, #x, s }
3495 static const struct {
3500 IPW2100_NIC(IPW2100_CONTROL_REG, 2),
3501 IPW2100_NIC(0x210014, 1), IPW2100_NIC(0x210000, 1),};
3502 #define IPW2100_ORD(x, d) { IPW_ORD_ ##x, #x, d }
3503 static const struct {
3508 IPW2100_ORD(STAT_TX_HOST_REQUESTS, "requested Host Tx's (MSDU)"),
3509 IPW2100_ORD(STAT_TX_HOST_COMPLETE,
3510 "successful Host Tx's (MSDU)"),
3511 IPW2100_ORD(STAT_TX_DIR_DATA,
3512 "successful Directed Tx's (MSDU)"),
3513 IPW2100_ORD(STAT_TX_DIR_DATA1,
3514 "successful Directed Tx's (MSDU) @ 1MB"),
3515 IPW2100_ORD(STAT_TX_DIR_DATA2,
3516 "successful Directed Tx's (MSDU) @ 2MB"),
3517 IPW2100_ORD(STAT_TX_DIR_DATA5_5,
3518 "successful Directed Tx's (MSDU) @ 5_5MB"),
3519 IPW2100_ORD(STAT_TX_DIR_DATA11,
3520 "successful Directed Tx's (MSDU) @ 11MB"),
3521 IPW2100_ORD(STAT_TX_NODIR_DATA1,
3522 "successful Non_Directed Tx's (MSDU) @ 1MB"),
3523 IPW2100_ORD(STAT_TX_NODIR_DATA2,
3524 "successful Non_Directed Tx's (MSDU) @ 2MB"),
3525 IPW2100_ORD(STAT_TX_NODIR_DATA5_5,
3526 "successful Non_Directed Tx's (MSDU) @ 5.5MB"),
3527 IPW2100_ORD(STAT_TX_NODIR_DATA11,
3528 "successful Non_Directed Tx's (MSDU) @ 11MB"),
3529 IPW2100_ORD(STAT_NULL_DATA, "successful NULL data Tx's"),
3530 IPW2100_ORD(STAT_TX_RTS, "successful Tx RTS"),
3531 IPW2100_ORD(STAT_TX_CTS, "successful Tx CTS"),
3532 IPW2100_ORD(STAT_TX_ACK, "successful Tx ACK"),
3533 IPW2100_ORD(STAT_TX_ASSN, "successful Association Tx's"),
3534 IPW2100_ORD(STAT_TX_ASSN_RESP,
3535 "successful Association response Tx's"),
3536 IPW2100_ORD(STAT_TX_REASSN,
3537 "successful Reassociation Tx's"),
3538 IPW2100_ORD(STAT_TX_REASSN_RESP,
3539 "successful Reassociation response Tx's"),
3540 IPW2100_ORD(STAT_TX_PROBE,
3541 "probes successfully transmitted"),
3542 IPW2100_ORD(STAT_TX_PROBE_RESP,
3543 "probe responses successfully transmitted"),
3544 IPW2100_ORD(STAT_TX_BEACON, "tx beacon"),
3545 IPW2100_ORD(STAT_TX_ATIM, "Tx ATIM"),
3546 IPW2100_ORD(STAT_TX_DISASSN,
3547 "successful Disassociation TX"),
3548 IPW2100_ORD(STAT_TX_AUTH, "successful Authentication Tx"),
3549 IPW2100_ORD(STAT_TX_DEAUTH,
3550 "successful Deauthentication TX"),
3551 IPW2100_ORD(STAT_TX_TOTAL_BYTES,
3552 "Total successful Tx data bytes"),
3553 IPW2100_ORD(STAT_TX_RETRIES, "Tx retries"),
3554 IPW2100_ORD(STAT_TX_RETRY1, "Tx retries at 1MBPS"),
3555 IPW2100_ORD(STAT_TX_RETRY2, "Tx retries at 2MBPS"),
3556 IPW2100_ORD(STAT_TX_RETRY5_5, "Tx retries at 5.5MBPS"),
3557 IPW2100_ORD(STAT_TX_RETRY11, "Tx retries at 11MBPS"),
3558 IPW2100_ORD(STAT_TX_FAILURES, "Tx Failures"),
3559 IPW2100_ORD(STAT_TX_MAX_TRIES_IN_HOP,
3560 "times max tries in a hop failed"),
3561 IPW2100_ORD(STAT_TX_DISASSN_FAIL,
3562 "times disassociation failed"),
3563 IPW2100_ORD(STAT_TX_ERR_CTS, "missed/bad CTS frames"),
3564 IPW2100_ORD(STAT_TX_ERR_ACK, "tx err due to acks"),
3565 IPW2100_ORD(STAT_RX_HOST, "packets passed to host"),
3566 IPW2100_ORD(STAT_RX_DIR_DATA, "directed packets"),
3567 IPW2100_ORD(STAT_RX_DIR_DATA1, "directed packets at 1MB"),
3568 IPW2100_ORD(STAT_RX_DIR_DATA2, "directed packets at 2MB"),
3569 IPW2100_ORD(STAT_RX_DIR_DATA5_5,
3570 "directed packets at 5.5MB"),
3571 IPW2100_ORD(STAT_RX_DIR_DATA11, "directed packets at 11MB"),
3572 IPW2100_ORD(STAT_RX_NODIR_DATA, "nondirected packets"),
3573 IPW2100_ORD(STAT_RX_NODIR_DATA1,
3574 "nondirected packets at 1MB"),
3575 IPW2100_ORD(STAT_RX_NODIR_DATA2,
3576 "nondirected packets at 2MB"),
3577 IPW2100_ORD(STAT_RX_NODIR_DATA5_5,
3578 "nondirected packets at 5.5MB"),
3579 IPW2100_ORD(STAT_RX_NODIR_DATA11,
3580 "nondirected packets at 11MB"),
3581 IPW2100_ORD(STAT_RX_NULL_DATA, "null data rx's"),
3582 IPW2100_ORD(STAT_RX_RTS, "Rx RTS"), IPW2100_ORD(STAT_RX_CTS,
3584 IPW2100_ORD(STAT_RX_ACK, "Rx ACK"),
3585 IPW2100_ORD(STAT_RX_CFEND, "Rx CF End"),
3586 IPW2100_ORD(STAT_RX_CFEND_ACK, "Rx CF End + CF Ack"),
3587 IPW2100_ORD(STAT_RX_ASSN, "Association Rx's"),
3588 IPW2100_ORD(STAT_RX_ASSN_RESP, "Association response Rx's"),
3589 IPW2100_ORD(STAT_RX_REASSN, "Reassociation Rx's"),
3590 IPW2100_ORD(STAT_RX_REASSN_RESP,
3591 "Reassociation response Rx's"),
3592 IPW2100_ORD(STAT_RX_PROBE, "probe Rx's"),
3593 IPW2100_ORD(STAT_RX_PROBE_RESP, "probe response Rx's"),
3594 IPW2100_ORD(STAT_RX_BEACON, "Rx beacon"),
3595 IPW2100_ORD(STAT_RX_ATIM, "Rx ATIM"),
3596 IPW2100_ORD(STAT_RX_DISASSN, "disassociation Rx"),
3597 IPW2100_ORD(STAT_RX_AUTH, "authentication Rx"),
3598 IPW2100_ORD(STAT_RX_DEAUTH, "deauthentication Rx"),
3599 IPW2100_ORD(STAT_RX_TOTAL_BYTES,
3600 "Total rx data bytes received"),
3601 IPW2100_ORD(STAT_RX_ERR_CRC, "packets with Rx CRC error"),
3602 IPW2100_ORD(STAT_RX_ERR_CRC1, "Rx CRC errors at 1MB"),
3603 IPW2100_ORD(STAT_RX_ERR_CRC2, "Rx CRC errors at 2MB"),
3604 IPW2100_ORD(STAT_RX_ERR_CRC5_5, "Rx CRC errors at 5.5MB"),
3605 IPW2100_ORD(STAT_RX_ERR_CRC11, "Rx CRC errors at 11MB"),
3606 IPW2100_ORD(STAT_RX_DUPLICATE1,
3607 "duplicate rx packets at 1MB"),
3608 IPW2100_ORD(STAT_RX_DUPLICATE2,
3609 "duplicate rx packets at 2MB"),
3610 IPW2100_ORD(STAT_RX_DUPLICATE5_5,
3611 "duplicate rx packets at 5.5MB"),
3612 IPW2100_ORD(STAT_RX_DUPLICATE11,
3613 "duplicate rx packets at 11MB"),
3614 IPW2100_ORD(STAT_RX_DUPLICATE, "duplicate rx packets"),
3615 IPW2100_ORD(PERS_DB_LOCK, "locking fw permanent db"),
3616 IPW2100_ORD(PERS_DB_SIZE, "size of fw permanent db"),
3617 IPW2100_ORD(PERS_DB_ADDR, "address of fw permanent db"),
3618 IPW2100_ORD(STAT_RX_INVALID_PROTOCOL,
3619 "rx frames with invalid protocol"),
3620 IPW2100_ORD(SYS_BOOT_TIME, "Boot time"),
3621 IPW2100_ORD(STAT_RX_NO_BUFFER,
3622 "rx frames rejected due to no buffer"),
3623 IPW2100_ORD(STAT_RX_MISSING_FRAG,
3624 "rx frames dropped due to missing fragment"),
3625 IPW2100_ORD(STAT_RX_ORPHAN_FRAG,
3626 "rx frames dropped due to non-sequential fragment"),
3627 IPW2100_ORD(STAT_RX_ORPHAN_FRAME,
3628 "rx frames dropped due to unmatched 1st frame"),
3629 IPW2100_ORD(STAT_RX_FRAG_AGEOUT,
3630 "rx frames dropped due to uncompleted frame"),
3631 IPW2100_ORD(STAT_RX_ICV_ERRORS,
3632 "ICV errors during decryption"),
3633 IPW2100_ORD(STAT_PSP_SUSPENSION, "times adapter suspended"),
3634 IPW2100_ORD(STAT_PSP_BCN_TIMEOUT, "beacon timeout"),
3635 IPW2100_ORD(STAT_PSP_POLL_TIMEOUT,
3636 "poll response timeouts"),
3637 IPW2100_ORD(STAT_PSP_NONDIR_TIMEOUT,
3638 "timeouts waiting for last {broad,multi}cast pkt"),
3639 IPW2100_ORD(STAT_PSP_RX_DTIMS, "PSP DTIMs received"),
3640 IPW2100_ORD(STAT_PSP_RX_TIMS, "PSP TIMs received"),
3641 IPW2100_ORD(STAT_PSP_STATION_ID, "PSP Station ID"),
3642 IPW2100_ORD(LAST_ASSN_TIME, "RTC time of last association"),
3643 IPW2100_ORD(STAT_PERCENT_MISSED_BCNS,
3644 "current calculation of % missed beacons"),
3645 IPW2100_ORD(STAT_PERCENT_RETRIES,
3646 "current calculation of % missed tx retries"),
3647 IPW2100_ORD(ASSOCIATED_AP_PTR,
3648 "0 if not associated, else pointer to AP table entry"),
3649 IPW2100_ORD(AVAILABLE_AP_CNT,
3650 "AP's decsribed in the AP table"),
3651 IPW2100_ORD(AP_LIST_PTR, "Ptr to list of available APs"),
3652 IPW2100_ORD(STAT_AP_ASSNS, "associations"),
3653 IPW2100_ORD(STAT_ASSN_FAIL, "association failures"),
3654 IPW2100_ORD(STAT_ASSN_RESP_FAIL,
3655 "failures due to response fail"),
3656 IPW2100_ORD(STAT_FULL_SCANS, "full scans"),
3657 IPW2100_ORD(CARD_DISABLED, "Card Disabled"),
3658 IPW2100_ORD(STAT_ROAM_INHIBIT,
3659 "times roaming was inhibited due to activity"),
3660 IPW2100_ORD(RSSI_AT_ASSN,
3661 "RSSI of associated AP at time of association"),
3662 IPW2100_ORD(STAT_ASSN_CAUSE1,
3663 "reassociation: no probe response or TX on hop"),
3664 IPW2100_ORD(STAT_ASSN_CAUSE2,
3665 "reassociation: poor tx/rx quality"),
3666 IPW2100_ORD(STAT_ASSN_CAUSE3,
3667 "reassociation: tx/rx quality (excessive AP load"),
3668 IPW2100_ORD(STAT_ASSN_CAUSE4,
3669 "reassociation: AP RSSI level"),
3670 IPW2100_ORD(STAT_ASSN_CAUSE5,
3671 "reassociations due to load leveling"),
3672 IPW2100_ORD(STAT_AUTH_FAIL, "times authentication failed"),
3673 IPW2100_ORD(STAT_AUTH_RESP_FAIL,
3674 "times authentication response failed"),
3675 IPW2100_ORD(STATION_TABLE_CNT,
3676 "entries in association table"),
3677 IPW2100_ORD(RSSI_AVG_CURR, "Current avg RSSI"),
3678 IPW2100_ORD(POWER_MGMT_MODE, "Power mode - 0=CAM, 1=PSP"),
3679 IPW2100_ORD(COUNTRY_CODE,
3680 "IEEE country code as recv'd from beacon"),
3681 IPW2100_ORD(COUNTRY_CHANNELS,
3682 "channels suported by country"),
3683 IPW2100_ORD(RESET_CNT, "adapter resets (warm)"),
3684 IPW2100_ORD(BEACON_INTERVAL, "Beacon interval"),
3685 IPW2100_ORD(ANTENNA_DIVERSITY,
3686 "TRUE if antenna diversity is disabled"),
3687 IPW2100_ORD(DTIM_PERIOD, "beacon intervals between DTIMs"),
3688 IPW2100_ORD(OUR_FREQ,
3689 "current radio freq lower digits - channel ID"),
3690 IPW2100_ORD(RTC_TIME, "current RTC time"),
3691 IPW2100_ORD(PORT_TYPE, "operating mode"),
3692 IPW2100_ORD(CURRENT_TX_RATE, "current tx rate"),
3693 IPW2100_ORD(SUPPORTED_RATES, "supported tx rates"),
3694 IPW2100_ORD(ATIM_WINDOW, "current ATIM Window"),
3695 IPW2100_ORD(BASIC_RATES, "basic tx rates"),
3696 IPW2100_ORD(NIC_HIGHEST_RATE, "NIC highest tx rate"),
3697 IPW2100_ORD(AP_HIGHEST_RATE, "AP highest tx rate"),
3698 IPW2100_ORD(CAPABILITIES,
3699 "Management frame capability field"),
3700 IPW2100_ORD(AUTH_TYPE, "Type of authentication"),
3701 IPW2100_ORD(RADIO_TYPE, "Adapter card platform type"),
3702 IPW2100_ORD(RTS_THRESHOLD,
3703 "Min packet length for RTS handshaking"),
3704 IPW2100_ORD(INT_MODE, "International mode"),
3705 IPW2100_ORD(FRAGMENTATION_THRESHOLD,
3706 "protocol frag threshold"),
3707 IPW2100_ORD(EEPROM_SRAM_DB_BLOCK_START_ADDRESS,
3708 "EEPROM offset in SRAM"),
3709 IPW2100_ORD(EEPROM_SRAM_DB_BLOCK_SIZE,
3710 "EEPROM size in SRAM"),
3711 IPW2100_ORD(EEPROM_SKU_CAPABILITY, "EEPROM SKU Capability"),
3712 IPW2100_ORD(EEPROM_IBSS_11B_CHANNELS,
3713 "EEPROM IBSS 11b channel set"),
3714 IPW2100_ORD(MAC_VERSION, "MAC Version"),
3715 IPW2100_ORD(MAC_REVISION, "MAC Revision"),
3716 IPW2100_ORD(RADIO_VERSION, "Radio Version"),
3717 IPW2100_ORD(NIC_MANF_DATE_TIME, "MANF Date/Time STAMP"),
3718 IPW2100_ORD(UCODE_VERSION, "Ucode Version"),};
3720 static ssize_t show_registers(struct device *d, struct device_attribute *attr,
3724 struct ipw2100_priv *priv = dev_get_drvdata(d);
3725 struct net_device *dev = priv->net_dev;
3729 out += sprintf(out, "%30s [Address ] : Hex\n", "Register");
3731 for (i = 0; i < (sizeof(hw_data) / sizeof(*hw_data)); i++) {
3732 read_register(dev, hw_data[i].addr, &val);
3733 out += sprintf(out, "%30s [%08X] : %08X\n",
3734 hw_data[i].name, hw_data[i].addr, val);
3740 static DEVICE_ATTR(registers, S_IRUGO, show_registers, NULL);
3742 static ssize_t show_hardware(struct device *d, struct device_attribute *attr,
3745 struct ipw2100_priv *priv = dev_get_drvdata(d);
3746 struct net_device *dev = priv->net_dev;
3750 out += sprintf(out, "%30s [Address ] : Hex\n", "NIC entry");
3752 for (i = 0; i < (sizeof(nic_data) / sizeof(*nic_data)); i++) {
3757 switch (nic_data[i].size) {
3759 read_nic_byte(dev, nic_data[i].addr, &tmp8);
3760 out += sprintf(out, "%30s [%08X] : %02X\n",
3761 nic_data[i].name, nic_data[i].addr,
3765 read_nic_word(dev, nic_data[i].addr, &tmp16);
3766 out += sprintf(out, "%30s [%08X] : %04X\n",
3767 nic_data[i].name, nic_data[i].addr,
3771 read_nic_dword(dev, nic_data[i].addr, &tmp32);
3772 out += sprintf(out, "%30s [%08X] : %08X\n",
3773 nic_data[i].name, nic_data[i].addr,
3781 static DEVICE_ATTR(hardware, S_IRUGO, show_hardware, NULL);
3783 static ssize_t show_memory(struct device *d, struct device_attribute *attr,
3786 struct ipw2100_priv *priv = dev_get_drvdata(d);
3787 struct net_device *dev = priv->net_dev;
3788 static unsigned long loop = 0;
3794 if (loop >= 0x30000)
3797 /* sysfs provides us PAGE_SIZE buffer */
3798 while (len < PAGE_SIZE - 128 && loop < 0x30000) {
3800 if (priv->snapshot[0])
3801 for (i = 0; i < 4; i++)
3803 *(u32 *) SNAPSHOT_ADDR(loop + i * 4);
3805 for (i = 0; i < 4; i++)
3806 read_nic_dword(dev, loop + i * 4, &buffer[i]);
3809 len += sprintf(buf + len,
3814 ((u8 *) buffer)[0x0],
3815 ((u8 *) buffer)[0x1],
3816 ((u8 *) buffer)[0x2],
3817 ((u8 *) buffer)[0x3],
3818 ((u8 *) buffer)[0x4],
3819 ((u8 *) buffer)[0x5],
3820 ((u8 *) buffer)[0x6],
3821 ((u8 *) buffer)[0x7],
3822 ((u8 *) buffer)[0x8],
3823 ((u8 *) buffer)[0x9],
3824 ((u8 *) buffer)[0xa],
3825 ((u8 *) buffer)[0xb],
3826 ((u8 *) buffer)[0xc],
3827 ((u8 *) buffer)[0xd],
3828 ((u8 *) buffer)[0xe],
3829 ((u8 *) buffer)[0xf]);
3831 len += sprintf(buf + len, "%s\n",
3832 snprint_line(line, sizeof(line),
3833 (u8 *) buffer, 16, loop));
3840 static ssize_t store_memory(struct device *d, struct device_attribute *attr,
3841 const char *buf, size_t count)
3843 struct ipw2100_priv *priv = dev_get_drvdata(d);
3844 struct net_device *dev = priv->net_dev;
3845 const char *p = buf;
3847 (void)dev; /* kill unused-var warning for debug-only code */
3853 (count >= 2 && tolower(p[0]) == 'o' && tolower(p[1]) == 'n')) {
3854 IPW_DEBUG_INFO("%s: Setting memory dump to RAW mode.\n",
3858 } else if (p[0] == '0' || (count >= 2 && tolower(p[0]) == 'o' &&
3859 tolower(p[1]) == 'f')) {
3860 IPW_DEBUG_INFO("%s: Setting memory dump to HEX mode.\n",
3864 } else if (tolower(p[0]) == 'r') {
3865 IPW_DEBUG_INFO("%s: Resetting firmware snapshot.\n", dev->name);
3866 ipw2100_snapshot_free(priv);
3869 IPW_DEBUG_INFO("%s: Usage: 0|on = HEX, 1|off = RAW, "
3870 "reset = clear memory snapshot\n", dev->name);
3875 static DEVICE_ATTR(memory, S_IWUSR | S_IRUGO, show_memory, store_memory);
3877 static ssize_t show_ordinals(struct device *d, struct device_attribute *attr,
3880 struct ipw2100_priv *priv = dev_get_drvdata(d);
3884 static int loop = 0;
3886 if (priv->status & STATUS_RF_KILL_MASK)
3889 if (loop >= sizeof(ord_data) / sizeof(*ord_data))
3892 /* sysfs provides us PAGE_SIZE buffer */
3893 while (len < PAGE_SIZE - 128 &&
3894 loop < (sizeof(ord_data) / sizeof(*ord_data))) {
3896 val_len = sizeof(u32);
3898 if (ipw2100_get_ordinal(priv, ord_data[loop].index, &val,
3900 len += sprintf(buf + len, "[0x%02X] = ERROR %s\n",
3901 ord_data[loop].index,
3902 ord_data[loop].desc);
3904 len += sprintf(buf + len, "[0x%02X] = 0x%08X %s\n",
3905 ord_data[loop].index, val,
3906 ord_data[loop].desc);
3913 static DEVICE_ATTR(ordinals, S_IRUGO, show_ordinals, NULL);
3915 static ssize_t show_stats(struct device *d, struct device_attribute *attr,
3918 struct ipw2100_priv *priv = dev_get_drvdata(d);
3921 out += sprintf(out, "interrupts: %d {tx: %d, rx: %d, other: %d}\n",
3922 priv->interrupts, priv->tx_interrupts,
3923 priv->rx_interrupts, priv->inta_other);
3924 out += sprintf(out, "firmware resets: %d\n", priv->resets);
3925 out += sprintf(out, "firmware hangs: %d\n", priv->hangs);
3926 #ifdef CONFIG_IPW2100_DEBUG
3927 out += sprintf(out, "packet mismatch image: %s\n",
3928 priv->snapshot[0] ? "YES" : "NO");
3934 static DEVICE_ATTR(stats, S_IRUGO, show_stats, NULL);
3936 static int ipw2100_switch_mode(struct ipw2100_priv *priv, u32 mode)
3940 if (mode == priv->ieee->iw_mode)
3943 err = ipw2100_disable_adapter(priv);
3945 printk(KERN_ERR DRV_NAME ": %s: Could not disable adapter %d\n",
3946 priv->net_dev->name, err);
3952 priv->net_dev->type = ARPHRD_ETHER;
3955 priv->net_dev->type = ARPHRD_ETHER;
3957 #ifdef CONFIG_IPW2100_MONITOR
3958 case IW_MODE_MONITOR:
3959 priv->last_mode = priv->ieee->iw_mode;
3960 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
3962 #endif /* CONFIG_IPW2100_MONITOR */
3965 priv->ieee->iw_mode = mode;
3968 /* Indicate ipw2100_download_firmware download firmware
3969 * from disk instead of memory. */
3970 ipw2100_firmware.version = 0;
3973 printk(KERN_INFO "%s: Reseting on mode change.\n", priv->net_dev->name);
3974 priv->reset_backoff = 0;
3975 schedule_reset(priv);
3980 static ssize_t show_internals(struct device *d, struct device_attribute *attr,
3983 struct ipw2100_priv *priv = dev_get_drvdata(d);
3986 #define DUMP_VAR(x,y) len += sprintf(buf + len, # x ": %" y "\n", priv-> x)
3988 if (priv->status & STATUS_ASSOCIATED)
3989 len += sprintf(buf + len, "connected: %lu\n",
3990 get_seconds() - priv->connect_start);
3992 len += sprintf(buf + len, "not connected\n");
3994 DUMP_VAR(ieee->crypt[priv->ieee->tx_keyidx], "p");
3995 DUMP_VAR(status, "08lx");
3996 DUMP_VAR(config, "08lx");
3997 DUMP_VAR(capability, "08lx");
4000 sprintf(buf + len, "last_rtc: %lu\n",
4001 (unsigned long)priv->last_rtc);
4003 DUMP_VAR(fatal_error, "d");
4004 DUMP_VAR(stop_hang_check, "d");
4005 DUMP_VAR(stop_rf_kill, "d");
4006 DUMP_VAR(messages_sent, "d");
4008 DUMP_VAR(tx_pend_stat.value, "d");
4009 DUMP_VAR(tx_pend_stat.hi, "d");
4011 DUMP_VAR(tx_free_stat.value, "d");
4012 DUMP_VAR(tx_free_stat.lo, "d");
4014 DUMP_VAR(msg_free_stat.value, "d");
4015 DUMP_VAR(msg_free_stat.lo, "d");
4017 DUMP_VAR(msg_pend_stat.value, "d");
4018 DUMP_VAR(msg_pend_stat.hi, "d");
4020 DUMP_VAR(fw_pend_stat.value, "d");
4021 DUMP_VAR(fw_pend_stat.hi, "d");
4023 DUMP_VAR(txq_stat.value, "d");
4024 DUMP_VAR(txq_stat.lo, "d");
4026 DUMP_VAR(ieee->scans, "d");
4027 DUMP_VAR(reset_backoff, "d");
4032 static DEVICE_ATTR(internals, S_IRUGO, show_internals, NULL);
4034 static ssize_t show_bssinfo(struct device *d, struct device_attribute *attr,
4037 struct ipw2100_priv *priv = dev_get_drvdata(d);
4038 char essid[IW_ESSID_MAX_SIZE + 1];
4045 if (priv->status & STATUS_RF_KILL_MASK)
4048 memset(essid, 0, sizeof(essid));
4049 memset(bssid, 0, sizeof(bssid));
4051 length = IW_ESSID_MAX_SIZE;
4052 ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_SSID, essid, &length);
4054 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
4057 length = sizeof(bssid);
4058 ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID,
4061 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
4064 length = sizeof(u32);
4065 ret = ipw2100_get_ordinal(priv, IPW_ORD_OUR_FREQ, &chan, &length);
4067 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
4070 out += sprintf(out, "ESSID: %s\n", essid);
4071 out += sprintf(out, "BSSID: %02x:%02x:%02x:%02x:%02x:%02x\n",
4072 bssid[0], bssid[1], bssid[2],
4073 bssid[3], bssid[4], bssid[5]);
4074 out += sprintf(out, "Channel: %d\n", chan);
4079 static DEVICE_ATTR(bssinfo, S_IRUGO, show_bssinfo, NULL);
4081 #ifdef CONFIG_IPW2100_DEBUG
4082 static ssize_t show_debug_level(struct device_driver *d, char *buf)
4084 return sprintf(buf, "0x%08X\n", ipw2100_debug_level);
4087 static ssize_t store_debug_level(struct device_driver *d,
4088 const char *buf, size_t count)
4090 char *p = (char *)buf;
4093 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
4095 if (p[0] == 'x' || p[0] == 'X')
4097 val = simple_strtoul(p, &p, 16);
4099 val = simple_strtoul(p, &p, 10);
4101 IPW_DEBUG_INFO(": %s is not in hex or decimal form.\n", buf);
4103 ipw2100_debug_level = val;
4105 return strnlen(buf, count);
4108 static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, show_debug_level,
4110 #endif /* CONFIG_IPW2100_DEBUG */
4112 static ssize_t show_fatal_error(struct device *d,
4113 struct device_attribute *attr, char *buf)
4115 struct ipw2100_priv *priv = dev_get_drvdata(d);
4119 if (priv->fatal_error)
4120 out += sprintf(out, "0x%08X\n", priv->fatal_error);
4122 out += sprintf(out, "0\n");
4124 for (i = 1; i <= IPW2100_ERROR_QUEUE; i++) {
4125 if (!priv->fatal_errors[(priv->fatal_index - i) %
4126 IPW2100_ERROR_QUEUE])
4129 out += sprintf(out, "%d. 0x%08X\n", i,
4130 priv->fatal_errors[(priv->fatal_index - i) %
4131 IPW2100_ERROR_QUEUE]);
4137 static ssize_t store_fatal_error(struct device *d,
4138 struct device_attribute *attr, const char *buf,
4141 struct ipw2100_priv *priv = dev_get_drvdata(d);
4142 schedule_reset(priv);
4146 static DEVICE_ATTR(fatal_error, S_IWUSR | S_IRUGO, show_fatal_error,
4149 static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
4152 struct ipw2100_priv *priv = dev_get_drvdata(d);
4153 return sprintf(buf, "%d\n", priv->ieee->scan_age);
4156 static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
4157 const char *buf, size_t count)
4159 struct ipw2100_priv *priv = dev_get_drvdata(d);
4160 struct net_device *dev = priv->net_dev;
4161 char buffer[] = "00000000";
4163 (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
4167 (void)dev; /* kill unused-var warning for debug-only code */
4169 IPW_DEBUG_INFO("enter\n");
4171 strncpy(buffer, buf, len);
4174 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
4176 if (p[0] == 'x' || p[0] == 'X')
4178 val = simple_strtoul(p, &p, 16);
4180 val = simple_strtoul(p, &p, 10);
4182 IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
4184 priv->ieee->scan_age = val;
4185 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
4188 IPW_DEBUG_INFO("exit\n");
4192 static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
4194 static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
4197 /* 0 - RF kill not enabled
4198 1 - SW based RF kill active (sysfs)
4199 2 - HW based RF kill active
4200 3 - Both HW and SW baed RF kill active */
4201 struct ipw2100_priv *priv = (struct ipw2100_priv *)d->driver_data;
4202 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
4203 (rf_kill_active(priv) ? 0x2 : 0x0);
4204 return sprintf(buf, "%i\n", val);
4207 static int ipw_radio_kill_sw(struct ipw2100_priv *priv, int disable_radio)
4209 if ((disable_radio ? 1 : 0) ==
4210 (priv->status & STATUS_RF_KILL_SW ? 1 : 0))
4213 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
4214 disable_radio ? "OFF" : "ON");
4216 mutex_lock(&priv->action_mutex);
4218 if (disable_radio) {
4219 priv->status |= STATUS_RF_KILL_SW;
4222 priv->status &= ~STATUS_RF_KILL_SW;
4223 if (rf_kill_active(priv)) {
4224 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
4225 "disabled by HW switch\n");
4226 /* Make sure the RF_KILL check timer is running */
4227 priv->stop_rf_kill = 0;
4228 cancel_delayed_work(&priv->rf_kill);
4229 queue_delayed_work(priv->workqueue, &priv->rf_kill, HZ);
4231 schedule_reset(priv);
4234 mutex_unlock(&priv->action_mutex);
4238 static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
4239 const char *buf, size_t count)
4241 struct ipw2100_priv *priv = dev_get_drvdata(d);
4242 ipw_radio_kill_sw(priv, buf[0] == '1');
4246 static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
4248 static struct attribute *ipw2100_sysfs_entries[] = {
4249 &dev_attr_hardware.attr,
4250 &dev_attr_registers.attr,
4251 &dev_attr_ordinals.attr,
4253 &dev_attr_stats.attr,
4254 &dev_attr_internals.attr,
4255 &dev_attr_bssinfo.attr,
4256 &dev_attr_memory.attr,
4257 &dev_attr_scan_age.attr,
4258 &dev_attr_fatal_error.attr,
4259 &dev_attr_rf_kill.attr,
4261 &dev_attr_status.attr,
4262 &dev_attr_capability.attr,
4266 static struct attribute_group ipw2100_attribute_group = {
4267 .attrs = ipw2100_sysfs_entries,
4270 static int status_queue_allocate(struct ipw2100_priv *priv, int entries)
4272 struct ipw2100_status_queue *q = &priv->status_queue;
4274 IPW_DEBUG_INFO("enter\n");
4276 q->size = entries * sizeof(struct ipw2100_status);
4278 (struct ipw2100_status *)pci_alloc_consistent(priv->pci_dev,
4281 IPW_DEBUG_WARNING("Can not allocate status queue.\n");
4285 memset(q->drv, 0, q->size);
4287 IPW_DEBUG_INFO("exit\n");
4292 static void status_queue_free(struct ipw2100_priv *priv)
4294 IPW_DEBUG_INFO("enter\n");
4296 if (priv->status_queue.drv) {
4297 pci_free_consistent(priv->pci_dev, priv->status_queue.size,
4298 priv->status_queue.drv,
4299 priv->status_queue.nic);
4300 priv->status_queue.drv = NULL;
4303 IPW_DEBUG_INFO("exit\n");
4306 static int bd_queue_allocate(struct ipw2100_priv *priv,
4307 struct ipw2100_bd_queue *q, int entries)
4309 IPW_DEBUG_INFO("enter\n");
4311 memset(q, 0, sizeof(struct ipw2100_bd_queue));
4313 q->entries = entries;
4314 q->size = entries * sizeof(struct ipw2100_bd);
4315 q->drv = pci_alloc_consistent(priv->pci_dev, q->size, &q->nic);
4318 ("can't allocate shared memory for buffer descriptors\n");
4321 memset(q->drv, 0, q->size);
4323 IPW_DEBUG_INFO("exit\n");
4328 static void bd_queue_free(struct ipw2100_priv *priv, struct ipw2100_bd_queue *q)
4330 IPW_DEBUG_INFO("enter\n");
4336 pci_free_consistent(priv->pci_dev, q->size, q->drv, q->nic);
4340 IPW_DEBUG_INFO("exit\n");
4343 static void bd_queue_initialize(struct ipw2100_priv *priv,
4344 struct ipw2100_bd_queue *q, u32 base, u32 size,
4347 IPW_DEBUG_INFO("enter\n");
4349 IPW_DEBUG_INFO("initializing bd queue at virt=%p, phys=%08x\n", q->drv,
4352 write_register(priv->net_dev, base, q->nic);
4353 write_register(priv->net_dev, size, q->entries);
4354 write_register(priv->net_dev, r, q->oldest);
4355 write_register(priv->net_dev, w, q->next);
4357 IPW_DEBUG_INFO("exit\n");
4360 static void ipw2100_kill_workqueue(struct ipw2100_priv *priv)
4362 if (priv->workqueue) {
4363 priv->stop_rf_kill = 1;
4364 priv->stop_hang_check = 1;
4365 cancel_delayed_work(&priv->reset_work);
4366 cancel_delayed_work(&priv->security_work);
4367 cancel_delayed_work(&priv->wx_event_work);
4368 cancel_delayed_work(&priv->hang_check);
4369 cancel_delayed_work(&priv->rf_kill);
4370 destroy_workqueue(priv->workqueue);
4371 priv->workqueue = NULL;
4375 static int ipw2100_tx_allocate(struct ipw2100_priv *priv)
4377 int i, j, err = -EINVAL;
4381 IPW_DEBUG_INFO("enter\n");
4383 err = bd_queue_allocate(priv, &priv->tx_queue, TX_QUEUE_LENGTH);
4385 IPW_DEBUG_ERROR("%s: failed bd_queue_allocate\n",
4386 priv->net_dev->name);
4391 (struct ipw2100_tx_packet *)kmalloc(TX_PENDED_QUEUE_LENGTH *
4395 if (!priv->tx_buffers) {
4396 printk(KERN_ERR DRV_NAME
4397 ": %s: alloc failed form tx buffers.\n",
4398 priv->net_dev->name);
4399 bd_queue_free(priv, &priv->tx_queue);
4403 for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
4404 v = pci_alloc_consistent(priv->pci_dev,
4405 sizeof(struct ipw2100_data_header),
4408 printk(KERN_ERR DRV_NAME
4409 ": %s: PCI alloc failed for tx " "buffers.\n",
4410 priv->net_dev->name);
4415 priv->tx_buffers[i].type = DATA;
4416 priv->tx_buffers[i].info.d_struct.data =
4417 (struct ipw2100_data_header *)v;
4418 priv->tx_buffers[i].info.d_struct.data_phys = p;
4419 priv->tx_buffers[i].info.d_struct.txb = NULL;
4422 if (i == TX_PENDED_QUEUE_LENGTH)
4425 for (j = 0; j < i; j++) {
4426 pci_free_consistent(priv->pci_dev,
4427 sizeof(struct ipw2100_data_header),
4428 priv->tx_buffers[j].info.d_struct.data,
4429 priv->tx_buffers[j].info.d_struct.
4433 kfree(priv->tx_buffers);
4434 priv->tx_buffers = NULL;
4439 static void ipw2100_tx_initialize(struct ipw2100_priv *priv)
4443 IPW_DEBUG_INFO("enter\n");
4446 * reinitialize packet info lists
4448 INIT_LIST_HEAD(&priv->fw_pend_list);
4449 INIT_STAT(&priv->fw_pend_stat);
4452 * reinitialize lists
4454 INIT_LIST_HEAD(&priv->tx_pend_list);
4455 INIT_LIST_HEAD(&priv->tx_free_list);
4456 INIT_STAT(&priv->tx_pend_stat);
4457 INIT_STAT(&priv->tx_free_stat);
4459 for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
4460 /* We simply drop any SKBs that have been queued for
4462 if (priv->tx_buffers[i].info.d_struct.txb) {
4463 ieee80211_txb_free(priv->tx_buffers[i].info.d_struct.
4465 priv->tx_buffers[i].info.d_struct.txb = NULL;
4468 list_add_tail(&priv->tx_buffers[i].list, &priv->tx_free_list);
4471 SET_STAT(&priv->tx_free_stat, i);
4473 priv->tx_queue.oldest = 0;
4474 priv->tx_queue.available = priv->tx_queue.entries;
4475 priv->tx_queue.next = 0;
4476 INIT_STAT(&priv->txq_stat);
4477 SET_STAT(&priv->txq_stat, priv->tx_queue.available);
4479 bd_queue_initialize(priv, &priv->tx_queue,
4480 IPW_MEM_HOST_SHARED_TX_QUEUE_BD_BASE,
4481 IPW_MEM_HOST_SHARED_TX_QUEUE_BD_SIZE,
4482 IPW_MEM_HOST_SHARED_TX_QUEUE_READ_INDEX,
4483 IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX);
4485 IPW_DEBUG_INFO("exit\n");
4489 static void ipw2100_tx_free(struct ipw2100_priv *priv)
4493 IPW_DEBUG_INFO("enter\n");
4495 bd_queue_free(priv, &priv->tx_queue);
4497 if (!priv->tx_buffers)
4500 for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
4501 if (priv->tx_buffers[i].info.d_struct.txb) {
4502 ieee80211_txb_free(priv->tx_buffers[i].info.d_struct.
4504 priv->tx_buffers[i].info.d_struct.txb = NULL;
4506 if (priv->tx_buffers[i].info.d_struct.data)
4507 pci_free_consistent(priv->pci_dev,
4508 sizeof(struct ipw2100_data_header),
4509 priv->tx_buffers[i].info.d_struct.
4511 priv->tx_buffers[i].info.d_struct.
4515 kfree(priv->tx_buffers);
4516 priv->tx_buffers = NULL;
4518 IPW_DEBUG_INFO("exit\n");
4521 static int ipw2100_rx_allocate(struct ipw2100_priv *priv)
4523 int i, j, err = -EINVAL;
4525 IPW_DEBUG_INFO("enter\n");
4527 err = bd_queue_allocate(priv, &priv->rx_queue, RX_QUEUE_LENGTH);
4529 IPW_DEBUG_INFO("failed bd_queue_allocate\n");
4533 err = status_queue_allocate(priv, RX_QUEUE_LENGTH);
4535 IPW_DEBUG_INFO("failed status_queue_allocate\n");
4536 bd_queue_free(priv, &priv->rx_queue);
4543 priv->rx_buffers = (struct ipw2100_rx_packet *)
4544 kmalloc(RX_QUEUE_LENGTH * sizeof(struct ipw2100_rx_packet),
4546 if (!priv->rx_buffers) {
4547 IPW_DEBUG_INFO("can't allocate rx packet buffer table\n");
4549 bd_queue_free(priv, &priv->rx_queue);
4551 status_queue_free(priv);
4556 for (i = 0; i < RX_QUEUE_LENGTH; i++) {
4557 struct ipw2100_rx_packet *packet = &priv->rx_buffers[i];
4559 err = ipw2100_alloc_skb(priv, packet);
4560 if (unlikely(err)) {
4565 /* The BD holds the cache aligned address */
4566 priv->rx_queue.drv[i].host_addr = packet->dma_addr;
4567 priv->rx_queue.drv[i].buf_length = IPW_RX_NIC_BUFFER_LENGTH;
4568 priv->status_queue.drv[i].status_fields = 0;
4571 if (i == RX_QUEUE_LENGTH)
4574 for (j = 0; j < i; j++) {
4575 pci_unmap_single(priv->pci_dev, priv->rx_buffers[j].dma_addr,
4576 sizeof(struct ipw2100_rx_packet),
4577 PCI_DMA_FROMDEVICE);
4578 dev_kfree_skb(priv->rx_buffers[j].skb);
4581 kfree(priv->rx_buffers);
4582 priv->rx_buffers = NULL;
4584 bd_queue_free(priv, &priv->rx_queue);
4586 status_queue_free(priv);
4591 static void ipw2100_rx_initialize(struct ipw2100_priv *priv)
4593 IPW_DEBUG_INFO("enter\n");
4595 priv->rx_queue.oldest = 0;
4596 priv->rx_queue.available = priv->rx_queue.entries - 1;
4597 priv->rx_queue.next = priv->rx_queue.entries - 1;
4599 INIT_STAT(&priv->rxq_stat);
4600 SET_STAT(&priv->rxq_stat, priv->rx_queue.available);
4602 bd_queue_initialize(priv, &priv->rx_queue,
4603 IPW_MEM_HOST_SHARED_RX_BD_BASE,
4604 IPW_MEM_HOST_SHARED_RX_BD_SIZE,
4605 IPW_MEM_HOST_SHARED_RX_READ_INDEX,
4606 IPW_MEM_HOST_SHARED_RX_WRITE_INDEX);
4608 /* set up the status queue */
4609 write_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_STATUS_BASE,
4610 priv->status_queue.nic);
4612 IPW_DEBUG_INFO("exit\n");
4615 static void ipw2100_rx_free(struct ipw2100_priv *priv)
4619 IPW_DEBUG_INFO("enter\n");
4621 bd_queue_free(priv, &priv->rx_queue);
4622 status_queue_free(priv);
4624 if (!priv->rx_buffers)
4627 for (i = 0; i < RX_QUEUE_LENGTH; i++) {
4628 if (priv->rx_buffers[i].rxp) {
4629 pci_unmap_single(priv->pci_dev,
4630 priv->rx_buffers[i].dma_addr,
4631 sizeof(struct ipw2100_rx),
4632 PCI_DMA_FROMDEVICE);
4633 dev_kfree_skb(priv->rx_buffers[i].skb);
4637 kfree(priv->rx_buffers);
4638 priv->rx_buffers = NULL;
4640 IPW_DEBUG_INFO("exit\n");
4643 static int ipw2100_read_mac_address(struct ipw2100_priv *priv)
4645 u32 length = ETH_ALEN;
4650 err = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ADAPTER_MAC, mac, &length);
4652 IPW_DEBUG_INFO("MAC address read failed\n");
4655 IPW_DEBUG_INFO("card MAC is %02X:%02X:%02X:%02X:%02X:%02X\n",
4656 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
4658 memcpy(priv->net_dev->dev_addr, mac, ETH_ALEN);
4663 /********************************************************************
4667 ********************************************************************/
4669 static int ipw2100_set_mac_address(struct ipw2100_priv *priv, int batch_mode)
4671 struct host_command cmd = {
4672 .host_command = ADAPTER_ADDRESS,
4673 .host_command_sequence = 0,
4674 .host_command_length = ETH_ALEN
4678 IPW_DEBUG_HC("SET_MAC_ADDRESS\n");
4680 IPW_DEBUG_INFO("enter\n");
4682 if (priv->config & CFG_CUSTOM_MAC) {
4683 memcpy(cmd.host_command_parameters, priv->mac_addr, ETH_ALEN);
4684 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
4686 memcpy(cmd.host_command_parameters, priv->net_dev->dev_addr,
4689 err = ipw2100_hw_send_command(priv, &cmd);
4691 IPW_DEBUG_INFO("exit\n");
4695 static int ipw2100_set_port_type(struct ipw2100_priv *priv, u32 port_type,
4698 struct host_command cmd = {
4699 .host_command = PORT_TYPE,
4700 .host_command_sequence = 0,
4701 .host_command_length = sizeof(u32)
4705 switch (port_type) {
4707 cmd.host_command_parameters[0] = IPW_BSS;
4710 cmd.host_command_parameters[0] = IPW_IBSS;
4714 IPW_DEBUG_HC("PORT_TYPE: %s\n",
4715 port_type == IPW_IBSS ? "Ad-Hoc" : "Managed");
4718 err = ipw2100_disable_adapter(priv);
4720 printk(KERN_ERR DRV_NAME
4721 ": %s: Could not disable adapter %d\n",
4722 priv->net_dev->name, err);
4727 /* send cmd to firmware */
4728 err = ipw2100_hw_send_command(priv, &cmd);
4731 ipw2100_enable_adapter(priv);
4736 static int ipw2100_set_channel(struct ipw2100_priv *priv, u32 channel,
4739 struct host_command cmd = {
4740 .host_command = CHANNEL,
4741 .host_command_sequence = 0,
4742 .host_command_length = sizeof(u32)
4746 cmd.host_command_parameters[0] = channel;
4748 IPW_DEBUG_HC("CHANNEL: %d\n", channel);
4750 /* If BSS then we don't support channel selection */
4751 if (priv->ieee->iw_mode == IW_MODE_INFRA)
4754 if ((channel != 0) &&
4755 ((channel < REG_MIN_CHANNEL) || (channel > REG_MAX_CHANNEL)))
4759 err = ipw2100_disable_adapter(priv);
4764 err = ipw2100_hw_send_command(priv, &cmd);
4766 IPW_DEBUG_INFO("Failed to set channel to %d", channel);
4771 priv->config |= CFG_STATIC_CHANNEL;
4773 priv->config &= ~CFG_STATIC_CHANNEL;
4775 priv->channel = channel;
4778 err = ipw2100_enable_adapter(priv);
4786 static int ipw2100_system_config(struct ipw2100_priv *priv, int batch_mode)
4788 struct host_command cmd = {
4789 .host_command = SYSTEM_CONFIG,
4790 .host_command_sequence = 0,
4791 .host_command_length = 12,
4793 u32 ibss_mask, len = sizeof(u32);
4796 /* Set system configuration */
4799 err = ipw2100_disable_adapter(priv);
4804 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
4805 cmd.host_command_parameters[0] |= IPW_CFG_IBSS_AUTO_START;
4807 cmd.host_command_parameters[0] |= IPW_CFG_IBSS_MASK |
4808 IPW_CFG_BSS_MASK | IPW_CFG_802_1x_ENABLE;
4810 if (!(priv->config & CFG_LONG_PREAMBLE))
4811 cmd.host_command_parameters[0] |= IPW_CFG_PREAMBLE_AUTO;
4813 err = ipw2100_get_ordinal(priv,
4814 IPW_ORD_EEPROM_IBSS_11B_CHANNELS,
4817 ibss_mask = IPW_IBSS_11B_DEFAULT_MASK;
4819 cmd.host_command_parameters[1] = REG_CHANNEL_MASK;
4820 cmd.host_command_parameters[2] = REG_CHANNEL_MASK & ibss_mask;
4823 /*cmd.host_command_parameters[0] |= DIVERSITY_ANTENNA_A; */
4825 err = ipw2100_hw_send_command(priv, &cmd);
4829 /* If IPv6 is configured in the kernel then we don't want to filter out all
4830 * of the multicast packets as IPv6 needs some. */
4831 #if !defined(CONFIG_IPV6) && !defined(CONFIG_IPV6_MODULE)
4832 cmd.host_command = ADD_MULTICAST;
4833 cmd.host_command_sequence = 0;
4834 cmd.host_command_length = 0;
4836 ipw2100_hw_send_command(priv, &cmd);
4839 err = ipw2100_enable_adapter(priv);
4847 static int ipw2100_set_tx_rates(struct ipw2100_priv *priv, u32 rate,
4850 struct host_command cmd = {
4851 .host_command = BASIC_TX_RATES,
4852 .host_command_sequence = 0,
4853 .host_command_length = 4
4857 cmd.host_command_parameters[0] = rate & TX_RATE_MASK;
4860 err = ipw2100_disable_adapter(priv);
4865 /* Set BASIC TX Rate first */
4866 ipw2100_hw_send_command(priv, &cmd);
4869 cmd.host_command = TX_RATES;
4870 ipw2100_hw_send_command(priv, &cmd);
4872 /* Set MSDU TX Rate */
4873 cmd.host_command = MSDU_TX_RATES;
4874 ipw2100_hw_send_command(priv, &cmd);
4877 err = ipw2100_enable_adapter(priv);
4882 priv->tx_rates = rate;
4887 static int ipw2100_set_power_mode(struct ipw2100_priv *priv, int power_level)
4889 struct host_command cmd = {
4890 .host_command = POWER_MODE,
4891 .host_command_sequence = 0,
4892 .host_command_length = 4
4896 cmd.host_command_parameters[0] = power_level;
4898 err = ipw2100_hw_send_command(priv, &cmd);
4902 if (power_level == IPW_POWER_MODE_CAM)
4903 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
4905 priv->power_mode = IPW_POWER_ENABLED | power_level;
4907 #ifdef CONFIG_IPW2100_TX_POWER
4908 if (priv->port_type == IBSS && priv->adhoc_power != DFTL_IBSS_TX_POWER) {
4909 /* Set beacon interval */
4910 cmd.host_command = TX_POWER_INDEX;
4911 cmd.host_command_parameters[0] = (u32) priv->adhoc_power;
4913 err = ipw2100_hw_send_command(priv, &cmd);
4922 static int ipw2100_set_rts_threshold(struct ipw2100_priv *priv, u32 threshold)
4924 struct host_command cmd = {
4925 .host_command = RTS_THRESHOLD,
4926 .host_command_sequence = 0,
4927 .host_command_length = 4
4931 if (threshold & RTS_DISABLED)
4932 cmd.host_command_parameters[0] = MAX_RTS_THRESHOLD;
4934 cmd.host_command_parameters[0] = threshold & ~RTS_DISABLED;
4936 err = ipw2100_hw_send_command(priv, &cmd);
4940 priv->rts_threshold = threshold;
4946 int ipw2100_set_fragmentation_threshold(struct ipw2100_priv *priv,
4947 u32 threshold, int batch_mode)
4949 struct host_command cmd = {
4950 .host_command = FRAG_THRESHOLD,
4951 .host_command_sequence = 0,
4952 .host_command_length = 4,
4953 .host_command_parameters[0] = 0,
4958 err = ipw2100_disable_adapter(priv);
4964 threshold = DEFAULT_FRAG_THRESHOLD;
4966 threshold = max(threshold, MIN_FRAG_THRESHOLD);
4967 threshold = min(threshold, MAX_FRAG_THRESHOLD);
4970 cmd.host_command_parameters[0] = threshold;
4972 IPW_DEBUG_HC("FRAG_THRESHOLD: %u\n", threshold);
4974 err = ipw2100_hw_send_command(priv, &cmd);
4977 ipw2100_enable_adapter(priv);
4980 priv->frag_threshold = threshold;
4986 static int ipw2100_set_short_retry(struct ipw2100_priv *priv, u32 retry)
4988 struct host_command cmd = {
4989 .host_command = SHORT_RETRY_LIMIT,
4990 .host_command_sequence = 0,
4991 .host_command_length = 4
4995 cmd.host_command_parameters[0] = retry;
4997 err = ipw2100_hw_send_command(priv, &cmd);
5001 priv->short_retry_limit = retry;
5006 static int ipw2100_set_long_retry(struct ipw2100_priv *priv, u32 retry)
5008 struct host_command cmd = {
5009 .host_command = LONG_RETRY_LIMIT,
5010 .host_command_sequence = 0,
5011 .host_command_length = 4
5015 cmd.host_command_parameters[0] = retry;
5017 err = ipw2100_hw_send_command(priv, &cmd);
5021 priv->long_retry_limit = retry;
5026 static int ipw2100_set_mandatory_bssid(struct ipw2100_priv *priv, u8 * bssid,
5029 struct host_command cmd = {
5030 .host_command = MANDATORY_BSSID,
5031 .host_command_sequence = 0,
5032 .host_command_length = (bssid == NULL) ? 0 : ETH_ALEN
5036 #ifdef CONFIG_IPW2100_DEBUG
5038 IPW_DEBUG_HC("MANDATORY_BSSID: %02X:%02X:%02X:%02X:%02X:%02X\n",
5039 bssid[0], bssid[1], bssid[2], bssid[3], bssid[4],
5042 IPW_DEBUG_HC("MANDATORY_BSSID: <clear>\n");
5044 /* if BSSID is empty then we disable mandatory bssid mode */
5046 memcpy(cmd.host_command_parameters, bssid, ETH_ALEN);
5049 err = ipw2100_disable_adapter(priv);
5054 err = ipw2100_hw_send_command(priv, &cmd);
5057 ipw2100_enable_adapter(priv);
5062 static int ipw2100_disassociate_bssid(struct ipw2100_priv *priv)
5064 struct host_command cmd = {
5065 .host_command = DISASSOCIATION_BSSID,
5066 .host_command_sequence = 0,
5067 .host_command_length = ETH_ALEN
5072 IPW_DEBUG_HC("DISASSOCIATION_BSSID\n");
5075 /* The Firmware currently ignores the BSSID and just disassociates from
5076 * the currently associated AP -- but in the off chance that a future
5077 * firmware does use the BSSID provided here, we go ahead and try and
5078 * set it to the currently associated AP's BSSID */
5079 memcpy(cmd.host_command_parameters, priv->bssid, ETH_ALEN);
5081 err = ipw2100_hw_send_command(priv, &cmd);
5086 static int ipw2100_set_wpa_ie(struct ipw2100_priv *,
5087 struct ipw2100_wpa_assoc_frame *, int)
5088 __attribute__ ((unused));
5090 static int ipw2100_set_wpa_ie(struct ipw2100_priv *priv,
5091 struct ipw2100_wpa_assoc_frame *wpa_frame,
5094 struct host_command cmd = {
5095 .host_command = SET_WPA_IE,
5096 .host_command_sequence = 0,
5097 .host_command_length = sizeof(struct ipw2100_wpa_assoc_frame),
5101 IPW_DEBUG_HC("SET_WPA_IE\n");
5104 err = ipw2100_disable_adapter(priv);
5109 memcpy(cmd.host_command_parameters, wpa_frame,
5110 sizeof(struct ipw2100_wpa_assoc_frame));
5112 err = ipw2100_hw_send_command(priv, &cmd);
5115 if (ipw2100_enable_adapter(priv))
5122 struct security_info_params {
5123 u32 allowed_ciphers;
5126 u8 replay_counters_number;
5127 u8 unicast_using_group;
5128 } __attribute__ ((packed));
5130 static int ipw2100_set_security_information(struct ipw2100_priv *priv,
5133 int unicast_using_group,
5136 struct host_command cmd = {
5137 .host_command = SET_SECURITY_INFORMATION,
5138 .host_command_sequence = 0,
5139 .host_command_length = sizeof(struct security_info_params)
5141 struct security_info_params *security =
5142 (struct security_info_params *)&cmd.host_command_parameters;
5144 memset(security, 0, sizeof(*security));
5146 /* If shared key AP authentication is turned on, then we need to
5147 * configure the firmware to try and use it.
5149 * Actual data encryption/decryption is handled by the host. */
5150 security->auth_mode = auth_mode;
5151 security->unicast_using_group = unicast_using_group;
5153 switch (security_level) {
5156 security->allowed_ciphers = IPW_NONE_CIPHER;
5159 security->allowed_ciphers = IPW_WEP40_CIPHER |
5163 security->allowed_ciphers = IPW_WEP40_CIPHER |
5164 IPW_WEP104_CIPHER | IPW_TKIP_CIPHER;
5166 case SEC_LEVEL_2_CKIP:
5167 security->allowed_ciphers = IPW_WEP40_CIPHER |
5168 IPW_WEP104_CIPHER | IPW_CKIP_CIPHER;
5171 security->allowed_ciphers = IPW_WEP40_CIPHER |
5172 IPW_WEP104_CIPHER | IPW_TKIP_CIPHER | IPW_CCMP_CIPHER;
5177 ("SET_SECURITY_INFORMATION: auth:%d cipher:0x%02X (level %d)\n",
5178 security->auth_mode, security->allowed_ciphers, security_level);
5180 security->replay_counters_number = 0;
5183 err = ipw2100_disable_adapter(priv);
5188 err = ipw2100_hw_send_command(priv, &cmd);
5191 ipw2100_enable_adapter(priv);
5196 static int ipw2100_set_tx_power(struct ipw2100_priv *priv, u32 tx_power)
5198 struct host_command cmd = {
5199 .host_command = TX_POWER_INDEX,
5200 .host_command_sequence = 0,
5201 .host_command_length = 4
5206 if (tx_power != IPW_TX_POWER_DEFAULT)
5207 tmp = (tx_power - IPW_TX_POWER_MIN_DBM) * 16 /
5208 (IPW_TX_POWER_MAX_DBM - IPW_TX_POWER_MIN_DBM);
5210 cmd.host_command_parameters[0] = tmp;
5212 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
5213 err = ipw2100_hw_send_command(priv, &cmd);
5215 priv->tx_power = tx_power;
5220 static int ipw2100_set_ibss_beacon_interval(struct ipw2100_priv *priv,
5221 u32 interval, int batch_mode)
5223 struct host_command cmd = {
5224 .host_command = BEACON_INTERVAL,
5225 .host_command_sequence = 0,
5226 .host_command_length = 4
5230 cmd.host_command_parameters[0] = interval;
5232 IPW_DEBUG_INFO("enter\n");
5234 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
5236 err = ipw2100_disable_adapter(priv);
5241 ipw2100_hw_send_command(priv, &cmd);
5244 err = ipw2100_enable_adapter(priv);
5250 IPW_DEBUG_INFO("exit\n");
5255 void ipw2100_queues_initialize(struct ipw2100_priv *priv)
5257 ipw2100_tx_initialize(priv);
5258 ipw2100_rx_initialize(priv);
5259 ipw2100_msg_initialize(priv);
5262 void ipw2100_queues_free(struct ipw2100_priv *priv)
5264 ipw2100_tx_free(priv);
5265 ipw2100_rx_free(priv);
5266 ipw2100_msg_free(priv);
5269 int ipw2100_queues_allocate(struct ipw2100_priv *priv)
5271 if (ipw2100_tx_allocate(priv) ||
5272 ipw2100_rx_allocate(priv) || ipw2100_msg_allocate(priv))
5278 ipw2100_tx_free(priv);
5279 ipw2100_rx_free(priv);
5280 ipw2100_msg_free(priv);
5284 #define IPW_PRIVACY_CAPABLE 0x0008
5286 static int ipw2100_set_wep_flags(struct ipw2100_priv *priv, u32 flags,
5289 struct host_command cmd = {
5290 .host_command = WEP_FLAGS,
5291 .host_command_sequence = 0,
5292 .host_command_length = 4
5296 cmd.host_command_parameters[0] = flags;
5298 IPW_DEBUG_HC("WEP_FLAGS: flags = 0x%08X\n", flags);
5301 err = ipw2100_disable_adapter(priv);
5303 printk(KERN_ERR DRV_NAME
5304 ": %s: Could not disable adapter %d\n",
5305 priv->net_dev->name, err);
5310 /* send cmd to firmware */
5311 err = ipw2100_hw_send_command(priv, &cmd);
5314 ipw2100_enable_adapter(priv);
5319 struct ipw2100_wep_key {
5325 /* Macros to ease up priting WEP keys */
5326 #define WEP_FMT_64 "%02X%02X%02X%02X-%02X"
5327 #define WEP_FMT_128 "%02X%02X%02X%02X-%02X%02X%02X%02X-%02X%02X%02X"
5328 #define WEP_STR_64(x) x[0],x[1],x[2],x[3],x[4]
5329 #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]
5334 * @priv: struct to work on
5335 * @idx: index of the key we want to set
5336 * @key: ptr to the key data to set
5337 * @len: length of the buffer at @key
5338 * @batch_mode: FIXME perform the operation in batch mode, not
5339 * disabling the device.
5341 * @returns 0 if OK, < 0 errno code on error.
5343 * Fill out a command structure with the new wep key, length an
5344 * index and send it down the wire.
5346 static int ipw2100_set_key(struct ipw2100_priv *priv,
5347 int idx, char *key, int len, int batch_mode)
5349 int keylen = len ? (len <= 5 ? 5 : 13) : 0;
5350 struct host_command cmd = {
5351 .host_command = WEP_KEY_INFO,
5352 .host_command_sequence = 0,
5353 .host_command_length = sizeof(struct ipw2100_wep_key),
5355 struct ipw2100_wep_key *wep_key = (void *)cmd.host_command_parameters;
5358 IPW_DEBUG_HC("WEP_KEY_INFO: index = %d, len = %d/%d\n",
5361 /* NOTE: We don't check cached values in case the firmware was reset
5362 * or some other problem is occuring. If the user is setting the key,
5363 * then we push the change */
5366 wep_key->len = keylen;
5369 memcpy(wep_key->key, key, len);
5370 memset(wep_key->key + len, 0, keylen - len);
5373 /* Will be optimized out on debug not being configured in */
5375 IPW_DEBUG_WEP("%s: Clearing key %d\n",
5376 priv->net_dev->name, wep_key->idx);
5377 else if (keylen == 5)
5378 IPW_DEBUG_WEP("%s: idx: %d, len: %d key: " WEP_FMT_64 "\n",
5379 priv->net_dev->name, wep_key->idx, wep_key->len,
5380 WEP_STR_64(wep_key->key));
5382 IPW_DEBUG_WEP("%s: idx: %d, len: %d key: " WEP_FMT_128
5384 priv->net_dev->name, wep_key->idx, wep_key->len,
5385 WEP_STR_128(wep_key->key));
5388 err = ipw2100_disable_adapter(priv);
5389 /* FIXME: IPG: shouldn't this prink be in _disable_adapter()? */
5391 printk(KERN_ERR DRV_NAME
5392 ": %s: Could not disable adapter %d\n",
5393 priv->net_dev->name, err);
5398 /* send cmd to firmware */
5399 err = ipw2100_hw_send_command(priv, &cmd);
5402 int err2 = ipw2100_enable_adapter(priv);
5409 static int ipw2100_set_key_index(struct ipw2100_priv *priv,
5410 int idx, int batch_mode)
5412 struct host_command cmd = {
5413 .host_command = WEP_KEY_INDEX,
5414 .host_command_sequence = 0,
5415 .host_command_length = 4,
5416 .host_command_parameters = {idx},
5420 IPW_DEBUG_HC("WEP_KEY_INDEX: index = %d\n", idx);
5422 if (idx < 0 || idx > 3)
5426 err = ipw2100_disable_adapter(priv);
5428 printk(KERN_ERR DRV_NAME
5429 ": %s: Could not disable adapter %d\n",
5430 priv->net_dev->name, err);
5435 /* send cmd to firmware */
5436 err = ipw2100_hw_send_command(priv, &cmd);
5439 ipw2100_enable_adapter(priv);
5444 static int ipw2100_configure_security(struct ipw2100_priv *priv, int batch_mode)
5446 int i, err, auth_mode, sec_level, use_group;
5448 if (!(priv->status & STATUS_RUNNING))
5452 err = ipw2100_disable_adapter(priv);
5457 if (!priv->ieee->sec.enabled) {
5459 ipw2100_set_security_information(priv, IPW_AUTH_OPEN,
5462 auth_mode = IPW_AUTH_OPEN;
5463 if (priv->ieee->sec.flags & SEC_AUTH_MODE) {
5464 if (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)
5465 auth_mode = IPW_AUTH_SHARED;
5466 else if (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP)
5467 auth_mode = IPW_AUTH_LEAP_CISCO_ID;
5470 sec_level = SEC_LEVEL_0;
5471 if (priv->ieee->sec.flags & SEC_LEVEL)
5472 sec_level = priv->ieee->sec.level;
5475 if (priv->ieee->sec.flags & SEC_UNICAST_GROUP)
5476 use_group = priv->ieee->sec.unicast_uses_group;
5479 ipw2100_set_security_information(priv, auth_mode, sec_level,
5486 if (priv->ieee->sec.enabled) {
5487 for (i = 0; i < 4; i++) {
5488 if (!(priv->ieee->sec.flags & (1 << i))) {
5489 memset(priv->ieee->sec.keys[i], 0, WEP_KEY_LEN);
5490 priv->ieee->sec.key_sizes[i] = 0;
5492 err = ipw2100_set_key(priv, i,
5493 priv->ieee->sec.keys[i],
5501 ipw2100_set_key_index(priv, priv->ieee->tx_keyidx, 1);
5504 /* Always enable privacy so the Host can filter WEP packets if
5505 * encrypted data is sent up */
5507 ipw2100_set_wep_flags(priv,
5509 enabled ? IPW_PRIVACY_CAPABLE : 0, 1);
5513 priv->status &= ~STATUS_SECURITY_UPDATED;
5517 ipw2100_enable_adapter(priv);
5522 static void ipw2100_security_work(struct ipw2100_priv *priv)
5524 /* If we happen to have reconnected before we get a chance to
5525 * process this, then update the security settings--which causes
5526 * a disassociation to occur */
5527 if (!(priv->status & STATUS_ASSOCIATED) &&
5528 priv->status & STATUS_SECURITY_UPDATED)
5529 ipw2100_configure_security(priv, 0);
5532 static void shim__set_security(struct net_device *dev,
5533 struct ieee80211_security *sec)
5535 struct ipw2100_priv *priv = ieee80211_priv(dev);
5536 int i, force_update = 0;
5538 mutex_lock(&priv->action_mutex);
5539 if (!(priv->status & STATUS_INITIALIZED))
5542 for (i = 0; i < 4; i++) {
5543 if (sec->flags & (1 << i)) {
5544 priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
5545 if (sec->key_sizes[i] == 0)
5546 priv->ieee->sec.flags &= ~(1 << i);
5548 memcpy(priv->ieee->sec.keys[i], sec->keys[i],
5550 if (sec->level == SEC_LEVEL_1) {
5551 priv->ieee->sec.flags |= (1 << i);
5552 priv->status |= STATUS_SECURITY_UPDATED;
5554 priv->ieee->sec.flags &= ~(1 << i);
5558 if ((sec->flags & SEC_ACTIVE_KEY) &&
5559 priv->ieee->sec.active_key != sec->active_key) {
5560 if (sec->active_key <= 3) {
5561 priv->ieee->sec.active_key = sec->active_key;
5562 priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
5564 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
5566 priv->status |= STATUS_SECURITY_UPDATED;
5569 if ((sec->flags & SEC_AUTH_MODE) &&
5570 (priv->ieee->sec.auth_mode != sec->auth_mode)) {
5571 priv->ieee->sec.auth_mode = sec->auth_mode;
5572 priv->ieee->sec.flags |= SEC_AUTH_MODE;
5573 priv->status |= STATUS_SECURITY_UPDATED;
5576 if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
5577 priv->ieee->sec.flags |= SEC_ENABLED;
5578 priv->ieee->sec.enabled = sec->enabled;
5579 priv->status |= STATUS_SECURITY_UPDATED;
5583 if (sec->flags & SEC_ENCRYPT)
5584 priv->ieee->sec.encrypt = sec->encrypt;
5586 if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
5587 priv->ieee->sec.level = sec->level;
5588 priv->ieee->sec.flags |= SEC_LEVEL;
5589 priv->status |= STATUS_SECURITY_UPDATED;
5592 IPW_DEBUG_WEP("Security flags: %c %c%c%c%c %c%c%c%c\n",
5593 priv->ieee->sec.flags & (1 << 8) ? '1' : '0',
5594 priv->ieee->sec.flags & (1 << 7) ? '1' : '0',
5595 priv->ieee->sec.flags & (1 << 6) ? '1' : '0',
5596 priv->ieee->sec.flags & (1 << 5) ? '1' : '0',
5597 priv->ieee->sec.flags & (1 << 4) ? '1' : '0',
5598 priv->ieee->sec.flags & (1 << 3) ? '1' : '0',
5599 priv->ieee->sec.flags & (1 << 2) ? '1' : '0',
5600 priv->ieee->sec.flags & (1 << 1) ? '1' : '0',
5601 priv->ieee->sec.flags & (1 << 0) ? '1' : '0');
5603 /* As a temporary work around to enable WPA until we figure out why
5604 * wpa_supplicant toggles the security capability of the driver, which
5605 * forces a disassocation with force_update...
5607 * if (force_update || !(priv->status & STATUS_ASSOCIATED))*/
5608 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
5609 ipw2100_configure_security(priv, 0);
5611 mutex_unlock(&priv->action_mutex);
5614 static int ipw2100_adapter_setup(struct ipw2100_priv *priv)
5620 IPW_DEBUG_INFO("enter\n");
5622 err = ipw2100_disable_adapter(priv);
5625 #ifdef CONFIG_IPW2100_MONITOR
5626 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
5627 err = ipw2100_set_channel(priv, priv->channel, batch_mode);
5631 IPW_DEBUG_INFO("exit\n");
5635 #endif /* CONFIG_IPW2100_MONITOR */
5637 err = ipw2100_read_mac_address(priv);
5641 err = ipw2100_set_mac_address(priv, batch_mode);
5645 err = ipw2100_set_port_type(priv, priv->ieee->iw_mode, batch_mode);
5649 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
5650 err = ipw2100_set_channel(priv, priv->channel, batch_mode);
5655 err = ipw2100_system_config(priv, batch_mode);
5659 err = ipw2100_set_tx_rates(priv, priv->tx_rates, batch_mode);
5663 /* Default to power mode OFF */
5664 err = ipw2100_set_power_mode(priv, IPW_POWER_MODE_CAM);
5668 err = ipw2100_set_rts_threshold(priv, priv->rts_threshold);
5672 if (priv->config & CFG_STATIC_BSSID)
5673 bssid = priv->bssid;
5676 err = ipw2100_set_mandatory_bssid(priv, bssid, batch_mode);
5680 if (priv->config & CFG_STATIC_ESSID)
5681 err = ipw2100_set_essid(priv, priv->essid, priv->essid_len,
5684 err = ipw2100_set_essid(priv, NULL, 0, batch_mode);
5688 err = ipw2100_configure_security(priv, batch_mode);
5692 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
5694 ipw2100_set_ibss_beacon_interval(priv,
5695 priv->beacon_interval,
5700 err = ipw2100_set_tx_power(priv, priv->tx_power);
5706 err = ipw2100_set_fragmentation_threshold(
5707 priv, priv->frag_threshold, batch_mode);
5712 IPW_DEBUG_INFO("exit\n");
5717 /*************************************************************************
5719 * EXTERNALLY CALLED METHODS
5721 *************************************************************************/
5723 /* This method is called by the network layer -- not to be confused with
5724 * ipw2100_set_mac_address() declared above called by this driver (and this
5725 * method as well) to talk to the firmware */
5726 static int ipw2100_set_address(struct net_device *dev, void *p)
5728 struct ipw2100_priv *priv = ieee80211_priv(dev);
5729 struct sockaddr *addr = p;
5732 if (!is_valid_ether_addr(addr->sa_data))
5733 return -EADDRNOTAVAIL;
5735 mutex_lock(&priv->action_mutex);
5737 priv->config |= CFG_CUSTOM_MAC;
5738 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
5740 err = ipw2100_set_mac_address(priv, 0);
5744 priv->reset_backoff = 0;
5745 mutex_unlock(&priv->action_mutex);
5746 ipw2100_reset_adapter(priv);
5750 mutex_unlock(&priv->action_mutex);
5754 static int ipw2100_open(struct net_device *dev)
5756 struct ipw2100_priv *priv = ieee80211_priv(dev);
5757 unsigned long flags;
5758 IPW_DEBUG_INFO("dev->open\n");
5760 spin_lock_irqsave(&priv->low_lock, flags);
5761 if (priv->status & STATUS_ASSOCIATED) {
5762 netif_carrier_on(dev);
5763 netif_start_queue(dev);
5765 spin_unlock_irqrestore(&priv->low_lock, flags);
5770 static int ipw2100_close(struct net_device *dev)
5772 struct ipw2100_priv *priv = ieee80211_priv(dev);
5773 unsigned long flags;
5774 struct list_head *element;
5775 struct ipw2100_tx_packet *packet;
5777 IPW_DEBUG_INFO("enter\n");
5779 spin_lock_irqsave(&priv->low_lock, flags);
5781 if (priv->status & STATUS_ASSOCIATED)
5782 netif_carrier_off(dev);
5783 netif_stop_queue(dev);
5785 /* Flush the TX queue ... */
5786 while (!list_empty(&priv->tx_pend_list)) {
5787 element = priv->tx_pend_list.next;
5788 packet = list_entry(element, struct ipw2100_tx_packet, list);
5791 DEC_STAT(&priv->tx_pend_stat);
5793 ieee80211_txb_free(packet->info.d_struct.txb);
5794 packet->info.d_struct.txb = NULL;
5796 list_add_tail(element, &priv->tx_free_list);
5797 INC_STAT(&priv->tx_free_stat);
5799 spin_unlock_irqrestore(&priv->low_lock, flags);
5801 IPW_DEBUG_INFO("exit\n");
5807 * TODO: Fix this function... its just wrong
5809 static void ipw2100_tx_timeout(struct net_device *dev)
5811 struct ipw2100_priv *priv = ieee80211_priv(dev);
5813 priv->ieee->stats.tx_errors++;
5815 #ifdef CONFIG_IPW2100_MONITOR
5816 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
5820 IPW_DEBUG_INFO("%s: TX timed out. Scheduling firmware restart.\n",
5822 schedule_reset(priv);
5826 * TODO: reimplement it so that it reads statistics
5827 * from the adapter using ordinal tables
5828 * instead of/in addition to collecting them
5831 static struct net_device_stats *ipw2100_stats(struct net_device *dev)
5833 struct ipw2100_priv *priv = ieee80211_priv(dev);
5835 return &priv->ieee->stats;
5838 static int ipw2100_wpa_enable(struct ipw2100_priv *priv, int value)
5840 /* This is called when wpa_supplicant loads and closes the driver
5842 priv->ieee->wpa_enabled = value;
5846 static int ipw2100_wpa_set_auth_algs(struct ipw2100_priv *priv, int value)
5849 struct ieee80211_device *ieee = priv->ieee;
5850 struct ieee80211_security sec = {
5851 .flags = SEC_AUTH_MODE,
5855 if (value & IW_AUTH_ALG_SHARED_KEY) {
5856 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
5858 } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
5859 sec.auth_mode = WLAN_AUTH_OPEN;
5861 } else if (value & IW_AUTH_ALG_LEAP) {
5862 sec.auth_mode = WLAN_AUTH_LEAP;
5867 if (ieee->set_security)
5868 ieee->set_security(ieee->dev, &sec);
5875 static void ipw2100_wpa_assoc_frame(struct ipw2100_priv *priv,
5876 char *wpa_ie, int wpa_ie_len)
5879 struct ipw2100_wpa_assoc_frame frame;
5881 frame.fixed_ie_mask = 0;
5884 memcpy(frame.var_ie, wpa_ie, wpa_ie_len);
5885 frame.var_ie_len = wpa_ie_len;
5887 /* make sure WPA is enabled */
5888 ipw2100_wpa_enable(priv, 1);
5889 ipw2100_set_wpa_ie(priv, &frame, 0);
5892 static void ipw_ethtool_get_drvinfo(struct net_device *dev,
5893 struct ethtool_drvinfo *info)
5895 struct ipw2100_priv *priv = ieee80211_priv(dev);
5896 char fw_ver[64], ucode_ver[64];
5898 strcpy(info->driver, DRV_NAME);
5899 strcpy(info->version, DRV_VERSION);
5901 ipw2100_get_fwversion(priv, fw_ver, sizeof(fw_ver));
5902 ipw2100_get_ucodeversion(priv, ucode_ver, sizeof(ucode_ver));
5904 snprintf(info->fw_version, sizeof(info->fw_version), "%s:%d:%s",
5905 fw_ver, priv->eeprom_version, ucode_ver);
5907 strcpy(info->bus_info, pci_name(priv->pci_dev));
5910 static u32 ipw2100_ethtool_get_link(struct net_device *dev)
5912 struct ipw2100_priv *priv = ieee80211_priv(dev);
5913 return (priv->status & STATUS_ASSOCIATED) ? 1 : 0;
5916 static struct ethtool_ops ipw2100_ethtool_ops = {
5917 .get_link = ipw2100_ethtool_get_link,
5918 .get_drvinfo = ipw_ethtool_get_drvinfo,
5921 static void ipw2100_hang_check(void *adapter)
5923 struct ipw2100_priv *priv = adapter;
5924 unsigned long flags;
5925 u32 rtc = 0xa5a5a5a5;
5926 u32 len = sizeof(rtc);
5929 spin_lock_irqsave(&priv->low_lock, flags);
5931 if (priv->fatal_error != 0) {
5932 /* If fatal_error is set then we need to restart */
5933 IPW_DEBUG_INFO("%s: Hardware fatal error detected.\n",
5934 priv->net_dev->name);
5937 } else if (ipw2100_get_ordinal(priv, IPW_ORD_RTC_TIME, &rtc, &len) ||
5938 (rtc == priv->last_rtc)) {
5939 /* Check if firmware is hung */
5940 IPW_DEBUG_INFO("%s: Firmware RTC stalled.\n",
5941 priv->net_dev->name);
5948 priv->stop_hang_check = 1;
5951 /* Restart the NIC */
5952 schedule_reset(priv);
5955 priv->last_rtc = rtc;
5957 if (!priv->stop_hang_check)
5958 queue_delayed_work(priv->workqueue, &priv->hang_check, HZ / 2);
5960 spin_unlock_irqrestore(&priv->low_lock, flags);
5963 static void ipw2100_rf_kill(void *adapter)
5965 struct ipw2100_priv *priv = adapter;
5966 unsigned long flags;
5968 spin_lock_irqsave(&priv->low_lock, flags);
5970 if (rf_kill_active(priv)) {
5971 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
5972 if (!priv->stop_rf_kill)
5973 queue_delayed_work(priv->workqueue, &priv->rf_kill, HZ);
5977 /* RF Kill is now disabled, so bring the device back up */
5979 if (!(priv->status & STATUS_RF_KILL_MASK)) {
5980 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
5982 schedule_reset(priv);
5984 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
5988 spin_unlock_irqrestore(&priv->low_lock, flags);
5991 static void ipw2100_irq_tasklet(struct ipw2100_priv *priv);
5993 /* Look into using netdev destructor to shutdown ieee80211? */
5995 static struct net_device *ipw2100_alloc_device(struct pci_dev *pci_dev,
5996 void __iomem * base_addr,
5997 unsigned long mem_start,
5998 unsigned long mem_len)
6000 struct ipw2100_priv *priv;
6001 struct net_device *dev;
6003 dev = alloc_ieee80211(sizeof(struct ipw2100_priv));
6006 priv = ieee80211_priv(dev);
6007 priv->ieee = netdev_priv(dev);
6008 priv->pci_dev = pci_dev;
6009 priv->net_dev = dev;
6011 priv->ieee->hard_start_xmit = ipw2100_tx;
6012 priv->ieee->set_security = shim__set_security;
6014 priv->ieee->perfect_rssi = -20;
6015 priv->ieee->worst_rssi = -85;
6017 dev->open = ipw2100_open;
6018 dev->stop = ipw2100_close;
6019 dev->init = ipw2100_net_init;
6020 dev->get_stats = ipw2100_stats;
6021 dev->ethtool_ops = &ipw2100_ethtool_ops;
6022 dev->tx_timeout = ipw2100_tx_timeout;
6023 dev->wireless_handlers = &ipw2100_wx_handler_def;
6024 priv->wireless_data.ieee80211 = priv->ieee;
6025 dev->wireless_data = &priv->wireless_data;
6026 dev->set_mac_address = ipw2100_set_address;
6027 dev->watchdog_timeo = 3 * HZ;
6030 dev->base_addr = (unsigned long)base_addr;
6031 dev->mem_start = mem_start;
6032 dev->mem_end = dev->mem_start + mem_len - 1;
6034 /* NOTE: We don't use the wireless_handlers hook
6035 * in dev as the system will start throwing WX requests
6036 * to us before we're actually initialized and it just
6037 * ends up causing problems. So, we just handle
6038 * the WX extensions through the ipw2100_ioctl interface */
6040 /* memset() puts everything to 0, so we only have explicitely set
6041 * those values that need to be something else */
6043 /* If power management is turned on, default to AUTO mode */
6044 priv->power_mode = IPW_POWER_AUTO;
6046 #ifdef CONFIG_IPW2100_MONITOR
6047 priv->config |= CFG_CRC_CHECK;
6049 priv->ieee->wpa_enabled = 0;
6050 priv->ieee->drop_unencrypted = 0;
6051 priv->ieee->privacy_invoked = 0;
6052 priv->ieee->ieee802_1x = 1;
6054 /* Set module parameters */
6057 priv->ieee->iw_mode = IW_MODE_ADHOC;
6059 #ifdef CONFIG_IPW2100_MONITOR
6061 priv->ieee->iw_mode = IW_MODE_MONITOR;
6066 priv->ieee->iw_mode = IW_MODE_INFRA;
6071 priv->status |= STATUS_RF_KILL_SW;
6074 ((channel >= REG_MIN_CHANNEL) && (channel <= REG_MAX_CHANNEL))) {
6075 priv->config |= CFG_STATIC_CHANNEL;
6076 priv->channel = channel;
6080 priv->config |= CFG_ASSOCIATE;
6082 priv->beacon_interval = DEFAULT_BEACON_INTERVAL;
6083 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
6084 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
6085 priv->rts_threshold = DEFAULT_RTS_THRESHOLD | RTS_DISABLED;
6086 priv->frag_threshold = DEFAULT_FTS | FRAG_DISABLED;
6087 priv->tx_power = IPW_TX_POWER_DEFAULT;
6088 priv->tx_rates = DEFAULT_TX_RATES;
6090 strcpy(priv->nick, "ipw2100");
6092 spin_lock_init(&priv->low_lock);
6093 mutex_init(&priv->action_mutex);
6094 mutex_init(&priv->adapter_mutex);
6096 init_waitqueue_head(&priv->wait_command_queue);
6098 netif_carrier_off(dev);
6100 INIT_LIST_HEAD(&priv->msg_free_list);
6101 INIT_LIST_HEAD(&priv->msg_pend_list);
6102 INIT_STAT(&priv->msg_free_stat);
6103 INIT_STAT(&priv->msg_pend_stat);
6105 INIT_LIST_HEAD(&priv->tx_free_list);
6106 INIT_LIST_HEAD(&priv->tx_pend_list);
6107 INIT_STAT(&priv->tx_free_stat);
6108 INIT_STAT(&priv->tx_pend_stat);
6110 INIT_LIST_HEAD(&priv->fw_pend_list);
6111 INIT_STAT(&priv->fw_pend_stat);
6113 priv->workqueue = create_workqueue(DRV_NAME);
6115 INIT_WORK(&priv->reset_work,
6116 (void (*)(void *))ipw2100_reset_adapter, priv);
6117 INIT_WORK(&priv->security_work,
6118 (void (*)(void *))ipw2100_security_work, priv);
6119 INIT_WORK(&priv->wx_event_work,
6120 (void (*)(void *))ipw2100_wx_event_work, priv);
6121 INIT_WORK(&priv->hang_check, ipw2100_hang_check, priv);
6122 INIT_WORK(&priv->rf_kill, ipw2100_rf_kill, priv);
6124 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
6125 ipw2100_irq_tasklet, (unsigned long)priv);
6127 /* NOTE: We do not start the deferred work for status checks yet */
6128 priv->stop_rf_kill = 1;
6129 priv->stop_hang_check = 1;
6134 static int ipw2100_pci_init_one(struct pci_dev *pci_dev,
6135 const struct pci_device_id *ent)
6137 unsigned long mem_start, mem_len, mem_flags;
6138 void __iomem *base_addr = NULL;
6139 struct net_device *dev = NULL;
6140 struct ipw2100_priv *priv = NULL;
6145 IPW_DEBUG_INFO("enter\n");
6147 mem_start = pci_resource_start(pci_dev, 0);
6148 mem_len = pci_resource_len(pci_dev, 0);
6149 mem_flags = pci_resource_flags(pci_dev, 0);
6151 if ((mem_flags & IORESOURCE_MEM) != IORESOURCE_MEM) {
6152 IPW_DEBUG_INFO("weird - resource type is not memory\n");
6157 base_addr = ioremap_nocache(mem_start, mem_len);
6159 printk(KERN_WARNING DRV_NAME
6160 "Error calling ioremap_nocache.\n");
6165 /* allocate and initialize our net_device */
6166 dev = ipw2100_alloc_device(pci_dev, base_addr, mem_start, mem_len);
6168 printk(KERN_WARNING DRV_NAME
6169 "Error calling ipw2100_alloc_device.\n");
6174 /* set up PCI mappings for device */
6175 err = pci_enable_device(pci_dev);
6177 printk(KERN_WARNING DRV_NAME
6178 "Error calling pci_enable_device.\n");
6182 priv = ieee80211_priv(dev);
6184 pci_set_master(pci_dev);
6185 pci_set_drvdata(pci_dev, priv);
6187 err = pci_set_dma_mask(pci_dev, DMA_32BIT_MASK);
6189 printk(KERN_WARNING DRV_NAME
6190 "Error calling pci_set_dma_mask.\n");
6191 pci_disable_device(pci_dev);
6195 err = pci_request_regions(pci_dev, DRV_NAME);
6197 printk(KERN_WARNING DRV_NAME
6198 "Error calling pci_request_regions.\n");
6199 pci_disable_device(pci_dev);
6203 /* We disable the RETRY_TIMEOUT register (0x41) to keep
6204 * PCI Tx retries from interfering with C3 CPU state */
6205 pci_read_config_dword(pci_dev, 0x40, &val);
6206 if ((val & 0x0000ff00) != 0)
6207 pci_write_config_dword(pci_dev, 0x40, val & 0xffff00ff);
6209 pci_set_power_state(pci_dev, PCI_D0);
6211 if (!ipw2100_hw_is_adapter_in_system(dev)) {
6212 printk(KERN_WARNING DRV_NAME
6213 "Device not found via register read.\n");
6218 SET_NETDEV_DEV(dev, &pci_dev->dev);
6220 /* Force interrupts to be shut off on the device */
6221 priv->status |= STATUS_INT_ENABLED;
6222 ipw2100_disable_interrupts(priv);
6224 /* Allocate and initialize the Tx/Rx queues and lists */
6225 if (ipw2100_queues_allocate(priv)) {
6226 printk(KERN_WARNING DRV_NAME
6227 "Error calilng ipw2100_queues_allocate.\n");
6231 ipw2100_queues_initialize(priv);
6233 err = request_irq(pci_dev->irq,
6234 ipw2100_interrupt, SA_SHIRQ, dev->name, priv);
6236 printk(KERN_WARNING DRV_NAME
6237 "Error calling request_irq: %d.\n", pci_dev->irq);
6240 dev->irq = pci_dev->irq;
6242 IPW_DEBUG_INFO("Attempting to register device...\n");
6244 SET_MODULE_OWNER(dev);
6246 printk(KERN_INFO DRV_NAME
6247 ": Detected Intel PRO/Wireless 2100 Network Connection\n");
6249 /* Bring up the interface. Pre 0.46, after we registered the
6250 * network device we would call ipw2100_up. This introduced a race
6251 * condition with newer hotplug configurations (network was coming
6252 * up and making calls before the device was initialized).
6254 * If we called ipw2100_up before we registered the device, then the
6255 * device name wasn't registered. So, we instead use the net_dev->init
6256 * member to call a function that then just turns and calls ipw2100_up.
6257 * net_dev->init is called after name allocation but before the
6258 * notifier chain is called */
6259 mutex_lock(&priv->action_mutex);
6260 err = register_netdev(dev);
6262 printk(KERN_WARNING DRV_NAME
6263 "Error calling register_netdev.\n");
6268 IPW_DEBUG_INFO("%s: Bound to %s\n", dev->name, pci_name(pci_dev));
6270 /* perform this after register_netdev so that dev->name is set */
6271 sysfs_create_group(&pci_dev->dev.kobj, &ipw2100_attribute_group);
6273 /* If the RF Kill switch is disabled, go ahead and complete the
6274 * startup sequence */
6275 if (!(priv->status & STATUS_RF_KILL_MASK)) {
6276 /* Enable the adapter - sends HOST_COMPLETE */
6277 if (ipw2100_enable_adapter(priv)) {
6278 printk(KERN_WARNING DRV_NAME
6279 ": %s: failed in call to enable adapter.\n",
6280 priv->net_dev->name);
6281 ipw2100_hw_stop_adapter(priv);
6286 /* Start a scan . . . */
6287 ipw2100_set_scan_options(priv);
6288 ipw2100_start_scan(priv);
6291 IPW_DEBUG_INFO("exit\n");
6293 priv->status |= STATUS_INITIALIZED;
6295 mutex_unlock(&priv->action_mutex);
6300 mutex_unlock(&priv->action_mutex);
6305 unregister_netdev(dev);
6307 ipw2100_hw_stop_adapter(priv);
6309 ipw2100_disable_interrupts(priv);
6312 free_irq(dev->irq, priv);
6314 ipw2100_kill_workqueue(priv);
6316 /* These are safe to call even if they weren't allocated */
6317 ipw2100_queues_free(priv);
6318 sysfs_remove_group(&pci_dev->dev.kobj,
6319 &ipw2100_attribute_group);
6321 free_ieee80211(dev);
6322 pci_set_drvdata(pci_dev, NULL);
6328 pci_release_regions(pci_dev);
6329 pci_disable_device(pci_dev);
6334 static void __devexit ipw2100_pci_remove_one(struct pci_dev *pci_dev)
6336 struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
6337 struct net_device *dev;
6340 mutex_lock(&priv->action_mutex);
6342 priv->status &= ~STATUS_INITIALIZED;
6344 dev = priv->net_dev;
6345 sysfs_remove_group(&pci_dev->dev.kobj,
6346 &ipw2100_attribute_group);
6349 if (ipw2100_firmware.version)
6350 ipw2100_release_firmware(priv, &ipw2100_firmware);
6352 /* Take down the hardware */
6355 /* Release the mutex so that the network subsystem can
6356 * complete any needed calls into the driver... */
6357 mutex_unlock(&priv->action_mutex);
6359 /* Unregister the device first - this results in close()
6360 * being called if the device is open. If we free storage
6361 * first, then close() will crash. */
6362 unregister_netdev(dev);
6364 /* ipw2100_down will ensure that there is no more pending work
6365 * in the workqueue's, so we can safely remove them now. */
6366 ipw2100_kill_workqueue(priv);
6368 ipw2100_queues_free(priv);
6370 /* Free potential debugging firmware snapshot */
6371 ipw2100_snapshot_free(priv);
6374 free_irq(dev->irq, priv);
6377 iounmap((void __iomem *)dev->base_addr);
6379 free_ieee80211(dev);
6382 pci_release_regions(pci_dev);
6383 pci_disable_device(pci_dev);
6385 IPW_DEBUG_INFO("exit\n");
6389 static int ipw2100_suspend(struct pci_dev *pci_dev, pm_message_t state)
6391 struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
6392 struct net_device *dev = priv->net_dev;
6394 IPW_DEBUG_INFO("%s: Going into suspend...\n", dev->name);
6396 mutex_lock(&priv->action_mutex);
6397 if (priv->status & STATUS_INITIALIZED) {
6398 /* Take down the device; powers it off, etc. */
6402 /* Remove the PRESENT state of the device */
6403 netif_device_detach(dev);
6405 pci_save_state(pci_dev);
6406 pci_disable_device(pci_dev);
6407 pci_set_power_state(pci_dev, PCI_D3hot);
6409 mutex_unlock(&priv->action_mutex);
6414 static int ipw2100_resume(struct pci_dev *pci_dev)
6416 struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
6417 struct net_device *dev = priv->net_dev;
6420 if (IPW2100_PM_DISABLED)
6423 mutex_lock(&priv->action_mutex);
6425 IPW_DEBUG_INFO("%s: Coming out of suspend...\n", dev->name);
6427 pci_set_power_state(pci_dev, PCI_D0);
6428 pci_enable_device(pci_dev);
6429 pci_restore_state(pci_dev);
6432 * Suspend/Resume resets the PCI configuration space, so we have to
6433 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
6434 * from interfering with C3 CPU state. pci_restore_state won't help
6435 * here since it only restores the first 64 bytes pci config header.
6437 pci_read_config_dword(pci_dev, 0x40, &val);
6438 if ((val & 0x0000ff00) != 0)
6439 pci_write_config_dword(pci_dev, 0x40, val & 0xffff00ff);
6441 /* Set the device back into the PRESENT state; this will also wake
6442 * the queue of needed */
6443 netif_device_attach(dev);
6445 /* Bring the device back up */
6446 if (!(priv->status & STATUS_RF_KILL_SW))
6447 ipw2100_up(priv, 0);
6449 mutex_unlock(&priv->action_mutex);
6455 #define IPW2100_DEV_ID(x) { PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, x }
6457 static struct pci_device_id ipw2100_pci_id_table[] __devinitdata = {
6458 IPW2100_DEV_ID(0x2520), /* IN 2100A mPCI 3A */
6459 IPW2100_DEV_ID(0x2521), /* IN 2100A mPCI 3B */
6460 IPW2100_DEV_ID(0x2524), /* IN 2100A mPCI 3B */
6461 IPW2100_DEV_ID(0x2525), /* IN 2100A mPCI 3B */
6462 IPW2100_DEV_ID(0x2526), /* IN 2100A mPCI Gen A3 */
6463 IPW2100_DEV_ID(0x2522), /* IN 2100 mPCI 3B */
6464 IPW2100_DEV_ID(0x2523), /* IN 2100 mPCI 3A */
6465 IPW2100_DEV_ID(0x2527), /* IN 2100 mPCI 3B */
6466 IPW2100_DEV_ID(0x2528), /* IN 2100 mPCI 3B */
6467 IPW2100_DEV_ID(0x2529), /* IN 2100 mPCI 3B */
6468 IPW2100_DEV_ID(0x252B), /* IN 2100 mPCI 3A */
6469 IPW2100_DEV_ID(0x252C), /* IN 2100 mPCI 3A */
6470 IPW2100_DEV_ID(0x252D), /* IN 2100 mPCI 3A */
6472 IPW2100_DEV_ID(0x2550), /* IB 2100A mPCI 3B */
6473 IPW2100_DEV_ID(0x2551), /* IB 2100 mPCI 3B */
6474 IPW2100_DEV_ID(0x2553), /* IB 2100 mPCI 3B */
6475 IPW2100_DEV_ID(0x2554), /* IB 2100 mPCI 3B */
6476 IPW2100_DEV_ID(0x2555), /* IB 2100 mPCI 3B */
6478 IPW2100_DEV_ID(0x2560), /* DE 2100A mPCI 3A */
6479 IPW2100_DEV_ID(0x2562), /* DE 2100A mPCI 3A */
6480 IPW2100_DEV_ID(0x2563), /* DE 2100A mPCI 3A */
6481 IPW2100_DEV_ID(0x2561), /* DE 2100 mPCI 3A */
6482 IPW2100_DEV_ID(0x2565), /* DE 2100 mPCI 3A */
6483 IPW2100_DEV_ID(0x2566), /* DE 2100 mPCI 3A */
6484 IPW2100_DEV_ID(0x2567), /* DE 2100 mPCI 3A */
6486 IPW2100_DEV_ID(0x2570), /* GA 2100 mPCI 3B */
6488 IPW2100_DEV_ID(0x2580), /* TO 2100A mPCI 3B */
6489 IPW2100_DEV_ID(0x2582), /* TO 2100A mPCI 3B */
6490 IPW2100_DEV_ID(0x2583), /* TO 2100A mPCI 3B */
6491 IPW2100_DEV_ID(0x2581), /* TO 2100 mPCI 3B */
6492 IPW2100_DEV_ID(0x2585), /* TO 2100 mPCI 3B */
6493 IPW2100_DEV_ID(0x2586), /* TO 2100 mPCI 3B */
6494 IPW2100_DEV_ID(0x2587), /* TO 2100 mPCI 3B */
6496 IPW2100_DEV_ID(0x2590), /* SO 2100A mPCI 3B */
6497 IPW2100_DEV_ID(0x2592), /* SO 2100A mPCI 3B */
6498 IPW2100_DEV_ID(0x2591), /* SO 2100 mPCI 3B */
6499 IPW2100_DEV_ID(0x2593), /* SO 2100 mPCI 3B */
6500 IPW2100_DEV_ID(0x2596), /* SO 2100 mPCI 3B */
6501 IPW2100_DEV_ID(0x2598), /* SO 2100 mPCI 3B */
6503 IPW2100_DEV_ID(0x25A0), /* HP 2100 mPCI 3B */
6507 MODULE_DEVICE_TABLE(pci, ipw2100_pci_id_table);
6509 static struct pci_driver ipw2100_pci_driver = {
6511 .id_table = ipw2100_pci_id_table,
6512 .probe = ipw2100_pci_init_one,
6513 .remove = __devexit_p(ipw2100_pci_remove_one),
6515 .suspend = ipw2100_suspend,
6516 .resume = ipw2100_resume,
6521 * Initialize the ipw2100 driver/module
6523 * @returns 0 if ok, < 0 errno node con error.
6525 * Note: we cannot init the /proc stuff until the PCI driver is there,
6526 * or we risk an unlikely race condition on someone accessing
6527 * uninitialized data in the PCI dev struct through /proc.
6529 static int __init ipw2100_init(void)
6533 printk(KERN_INFO DRV_NAME ": %s, %s\n", DRV_DESCRIPTION, DRV_VERSION);
6534 printk(KERN_INFO DRV_NAME ": %s\n", DRV_COPYRIGHT);
6536 ret = pci_module_init(&ipw2100_pci_driver);
6538 #ifdef CONFIG_IPW2100_DEBUG
6539 ipw2100_debug_level = debug;
6540 driver_create_file(&ipw2100_pci_driver.driver,
6541 &driver_attr_debug_level);
6548 * Cleanup ipw2100 driver registration
6550 static void __exit ipw2100_exit(void)
6552 /* FIXME: IPG: check that we have no instances of the devices open */
6553 #ifdef CONFIG_IPW2100_DEBUG
6554 driver_remove_file(&ipw2100_pci_driver.driver,
6555 &driver_attr_debug_level);
6557 pci_unregister_driver(&ipw2100_pci_driver);
6560 module_init(ipw2100_init);
6561 module_exit(ipw2100_exit);
6563 #define WEXT_USECHANNELS 1
6565 static const long ipw2100_frequencies[] = {
6566 2412, 2417, 2422, 2427,
6567 2432, 2437, 2442, 2447,
6568 2452, 2457, 2462, 2467,
6572 #define FREQ_COUNT (sizeof(ipw2100_frequencies) / \
6573 sizeof(ipw2100_frequencies[0]))
6575 static const long ipw2100_rates_11b[] = {
6582 #define RATE_COUNT (sizeof(ipw2100_rates_11b) / sizeof(ipw2100_rates_11b[0]))
6584 static int ipw2100_wx_get_name(struct net_device *dev,
6585 struct iw_request_info *info,
6586 union iwreq_data *wrqu, char *extra)
6589 * This can be called at any time. No action lock required
6592 struct ipw2100_priv *priv = ieee80211_priv(dev);
6593 if (!(priv->status & STATUS_ASSOCIATED))
6594 strcpy(wrqu->name, "unassociated");
6596 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11b");
6598 IPW_DEBUG_WX("Name: %s\n", wrqu->name);
6602 static int ipw2100_wx_set_freq(struct net_device *dev,
6603 struct iw_request_info *info,
6604 union iwreq_data *wrqu, char *extra)
6606 struct ipw2100_priv *priv = ieee80211_priv(dev);
6607 struct iw_freq *fwrq = &wrqu->freq;
6610 if (priv->ieee->iw_mode == IW_MODE_INFRA)
6613 mutex_lock(&priv->action_mutex);
6614 if (!(priv->status & STATUS_INITIALIZED)) {
6619 /* if setting by freq convert to channel */
6621 if ((fwrq->m >= (int)2.412e8 && fwrq->m <= (int)2.487e8)) {
6622 int f = fwrq->m / 100000;
6625 while ((c < REG_MAX_CHANNEL) &&
6626 (f != ipw2100_frequencies[c]))
6629 /* hack to fall through */
6635 if (fwrq->e > 0 || fwrq->m > 1000) {
6638 } else { /* Set the channel */
6639 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
6640 err = ipw2100_set_channel(priv, fwrq->m, 0);
6644 mutex_unlock(&priv->action_mutex);
6648 static int ipw2100_wx_get_freq(struct net_device *dev,
6649 struct iw_request_info *info,
6650 union iwreq_data *wrqu, char *extra)
6653 * This can be called at any time. No action lock required
6656 struct ipw2100_priv *priv = ieee80211_priv(dev);
6660 /* If we are associated, trying to associate, or have a statically
6661 * configured CHANNEL then return that; otherwise return ANY */
6662 if (priv->config & CFG_STATIC_CHANNEL ||
6663 priv->status & STATUS_ASSOCIATED)
6664 wrqu->freq.m = priv->channel;
6668 IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
6673 static int ipw2100_wx_set_mode(struct net_device *dev,
6674 struct iw_request_info *info,
6675 union iwreq_data *wrqu, char *extra)
6677 struct ipw2100_priv *priv = ieee80211_priv(dev);
6680 IPW_DEBUG_WX("SET Mode -> %d \n", wrqu->mode);
6682 if (wrqu->mode == priv->ieee->iw_mode)
6685 mutex_lock(&priv->action_mutex);
6686 if (!(priv->status & STATUS_INITIALIZED)) {
6691 switch (wrqu->mode) {
6692 #ifdef CONFIG_IPW2100_MONITOR
6693 case IW_MODE_MONITOR:
6694 err = ipw2100_switch_mode(priv, IW_MODE_MONITOR);
6696 #endif /* CONFIG_IPW2100_MONITOR */
6698 err = ipw2100_switch_mode(priv, IW_MODE_ADHOC);
6703 err = ipw2100_switch_mode(priv, IW_MODE_INFRA);
6708 mutex_unlock(&priv->action_mutex);
6712 static int ipw2100_wx_get_mode(struct net_device *dev,
6713 struct iw_request_info *info,
6714 union iwreq_data *wrqu, char *extra)
6717 * This can be called at any time. No action lock required
6720 struct ipw2100_priv *priv = ieee80211_priv(dev);
6722 wrqu->mode = priv->ieee->iw_mode;
6723 IPW_DEBUG_WX("GET Mode -> %d\n", wrqu->mode);
6728 #define POWER_MODES 5
6730 /* Values are in microsecond */
6731 static const s32 timeout_duration[POWER_MODES] = {
6739 static const s32 period_duration[POWER_MODES] = {
6747 static int ipw2100_wx_get_range(struct net_device *dev,
6748 struct iw_request_info *info,
6749 union iwreq_data *wrqu, char *extra)
6752 * This can be called at any time. No action lock required
6755 struct ipw2100_priv *priv = ieee80211_priv(dev);
6756 struct iw_range *range = (struct iw_range *)extra;
6760 wrqu->data.length = sizeof(*range);
6761 memset(range, 0, sizeof(*range));
6763 /* Let's try to keep this struct in the same order as in
6764 * linux/include/wireless.h
6767 /* TODO: See what values we can set, and remove the ones we can't
6768 * set, or fill them with some default data.
6771 /* ~5 Mb/s real (802.11b) */
6772 range->throughput = 5 * 1000 * 1000;
6774 // range->sensitivity; /* signal level threshold range */
6776 range->max_qual.qual = 100;
6777 /* TODO: Find real max RSSI and stick here */
6778 range->max_qual.level = 0;
6779 range->max_qual.noise = 0;
6780 range->max_qual.updated = 7; /* Updated all three */
6782 range->avg_qual.qual = 70; /* > 8% missed beacons is 'bad' */
6783 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
6784 range->avg_qual.level = 20 + IPW2100_RSSI_TO_DBM;
6785 range->avg_qual.noise = 0;
6786 range->avg_qual.updated = 7; /* Updated all three */
6788 range->num_bitrates = RATE_COUNT;
6790 for (i = 0; i < RATE_COUNT && i < IW_MAX_BITRATES; i++) {
6791 range->bitrate[i] = ipw2100_rates_11b[i];
6794 range->min_rts = MIN_RTS_THRESHOLD;
6795 range->max_rts = MAX_RTS_THRESHOLD;
6796 range->min_frag = MIN_FRAG_THRESHOLD;
6797 range->max_frag = MAX_FRAG_THRESHOLD;
6799 range->min_pmp = period_duration[0]; /* Minimal PM period */
6800 range->max_pmp = period_duration[POWER_MODES - 1]; /* Maximal PM period */
6801 range->min_pmt = timeout_duration[POWER_MODES - 1]; /* Minimal PM timeout */
6802 range->max_pmt = timeout_duration[0]; /* Maximal PM timeout */
6804 /* How to decode max/min PM period */
6805 range->pmp_flags = IW_POWER_PERIOD;
6806 /* How to decode max/min PM period */
6807 range->pmt_flags = IW_POWER_TIMEOUT;
6808 /* What PM options are supported */
6809 range->pm_capa = IW_POWER_TIMEOUT | IW_POWER_PERIOD;
6811 range->encoding_size[0] = 5;
6812 range->encoding_size[1] = 13; /* Different token sizes */
6813 range->num_encoding_sizes = 2; /* Number of entry in the list */
6814 range->max_encoding_tokens = WEP_KEYS; /* Max number of tokens */
6815 // range->encoding_login_index; /* token index for login token */
6817 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
6818 range->txpower_capa = IW_TXPOW_DBM;
6819 range->num_txpower = IW_MAX_TXPOWER;
6820 for (i = 0, level = (IPW_TX_POWER_MAX_DBM * 16);
6823 ((IPW_TX_POWER_MAX_DBM -
6824 IPW_TX_POWER_MIN_DBM) * 16) / (IW_MAX_TXPOWER - 1))
6825 range->txpower[i] = level / 16;
6827 range->txpower_capa = 0;
6828 range->num_txpower = 0;
6831 /* Set the Wireless Extension versions */
6832 range->we_version_compiled = WIRELESS_EXT;
6833 range->we_version_source = 18;
6835 // range->retry_capa; /* What retry options are supported */
6836 // range->retry_flags; /* How to decode max/min retry limit */
6837 // range->r_time_flags; /* How to decode max/min retry life */
6838 // range->min_retry; /* Minimal number of retries */
6839 // range->max_retry; /* Maximal number of retries */
6840 // range->min_r_time; /* Minimal retry lifetime */
6841 // range->max_r_time; /* Maximal retry lifetime */
6843 range->num_channels = FREQ_COUNT;
6846 for (i = 0; i < FREQ_COUNT; i++) {
6847 // TODO: Include only legal frequencies for some countries
6848 // if (local->channel_mask & (1 << i)) {
6849 range->freq[val].i = i + 1;
6850 range->freq[val].m = ipw2100_frequencies[i] * 100000;
6851 range->freq[val].e = 1;
6854 if (val == IW_MAX_FREQUENCIES)
6857 range->num_frequency = val;
6859 /* Event capability (kernel + driver) */
6860 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
6861 IW_EVENT_CAPA_MASK(SIOCGIWAP));
6862 range->event_capa[1] = IW_EVENT_CAPA_K_1;
6864 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
6865 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
6867 IPW_DEBUG_WX("GET Range\n");
6872 static int ipw2100_wx_set_wap(struct net_device *dev,
6873 struct iw_request_info *info,
6874 union iwreq_data *wrqu, char *extra)
6876 struct ipw2100_priv *priv = ieee80211_priv(dev);
6879 static const unsigned char any[] = {
6880 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
6882 static const unsigned char off[] = {
6883 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
6887 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
6890 mutex_lock(&priv->action_mutex);
6891 if (!(priv->status & STATUS_INITIALIZED)) {
6896 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
6897 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
6898 /* we disable mandatory BSSID association */
6899 IPW_DEBUG_WX("exit - disable mandatory BSSID\n");
6900 priv->config &= ~CFG_STATIC_BSSID;
6901 err = ipw2100_set_mandatory_bssid(priv, NULL, 0);
6905 priv->config |= CFG_STATIC_BSSID;
6906 memcpy(priv->mandatory_bssid_mac, wrqu->ap_addr.sa_data, ETH_ALEN);
6908 err = ipw2100_set_mandatory_bssid(priv, wrqu->ap_addr.sa_data, 0);
6910 IPW_DEBUG_WX("SET BSSID -> %02X:%02X:%02X:%02X:%02X:%02X\n",
6911 wrqu->ap_addr.sa_data[0] & 0xff,
6912 wrqu->ap_addr.sa_data[1] & 0xff,
6913 wrqu->ap_addr.sa_data[2] & 0xff,
6914 wrqu->ap_addr.sa_data[3] & 0xff,
6915 wrqu->ap_addr.sa_data[4] & 0xff,
6916 wrqu->ap_addr.sa_data[5] & 0xff);
6919 mutex_unlock(&priv->action_mutex);
6923 static int ipw2100_wx_get_wap(struct net_device *dev,
6924 struct iw_request_info *info,
6925 union iwreq_data *wrqu, char *extra)
6928 * This can be called at any time. No action lock required
6931 struct ipw2100_priv *priv = ieee80211_priv(dev);
6933 /* If we are associated, trying to associate, or have a statically
6934 * configured BSSID then return that; otherwise return ANY */
6935 if (priv->config & CFG_STATIC_BSSID || priv->status & STATUS_ASSOCIATED) {
6936 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
6937 memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
6939 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
6941 IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n",
6942 MAC_ARG(wrqu->ap_addr.sa_data));
6946 static int ipw2100_wx_set_essid(struct net_device *dev,
6947 struct iw_request_info *info,
6948 union iwreq_data *wrqu, char *extra)
6950 struct ipw2100_priv *priv = ieee80211_priv(dev);
6951 char *essid = ""; /* ANY */
6955 mutex_lock(&priv->action_mutex);
6956 if (!(priv->status & STATUS_INITIALIZED)) {
6961 if (wrqu->essid.flags && wrqu->essid.length) {
6962 length = wrqu->essid.length - 1;
6967 IPW_DEBUG_WX("Setting ESSID to ANY\n");
6968 priv->config &= ~CFG_STATIC_ESSID;
6969 err = ipw2100_set_essid(priv, NULL, 0, 0);
6973 length = min(length, IW_ESSID_MAX_SIZE);
6975 priv->config |= CFG_STATIC_ESSID;
6977 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
6978 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
6983 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length),
6986 priv->essid_len = length;
6987 memcpy(priv->essid, essid, priv->essid_len);
6989 err = ipw2100_set_essid(priv, essid, length, 0);
6992 mutex_unlock(&priv->action_mutex);
6996 static int ipw2100_wx_get_essid(struct net_device *dev,
6997 struct iw_request_info *info,
6998 union iwreq_data *wrqu, char *extra)
7001 * This can be called at any time. No action lock required
7004 struct ipw2100_priv *priv = ieee80211_priv(dev);
7006 /* If we are associated, trying to associate, or have a statically
7007 * configured ESSID then return that; otherwise return ANY */
7008 if (priv->config & CFG_STATIC_ESSID || priv->status & STATUS_ASSOCIATED) {
7009 IPW_DEBUG_WX("Getting essid: '%s'\n",
7010 escape_essid(priv->essid, priv->essid_len));
7011 memcpy(extra, priv->essid, priv->essid_len);
7012 wrqu->essid.length = priv->essid_len;
7013 wrqu->essid.flags = 1; /* active */
7015 IPW_DEBUG_WX("Getting essid: ANY\n");
7016 wrqu->essid.length = 0;
7017 wrqu->essid.flags = 0; /* active */
7023 static int ipw2100_wx_set_nick(struct net_device *dev,
7024 struct iw_request_info *info,
7025 union iwreq_data *wrqu, char *extra)
7028 * This can be called at any time. No action lock required
7031 struct ipw2100_priv *priv = ieee80211_priv(dev);
7033 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
7036 wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
7037 memset(priv->nick, 0, sizeof(priv->nick));
7038 memcpy(priv->nick, extra, wrqu->data.length);
7040 IPW_DEBUG_WX("SET Nickname -> %s \n", priv->nick);
7045 static int ipw2100_wx_get_nick(struct net_device *dev,
7046 struct iw_request_info *info,
7047 union iwreq_data *wrqu, char *extra)
7050 * This can be called at any time. No action lock required
7053 struct ipw2100_priv *priv = ieee80211_priv(dev);
7055 wrqu->data.length = strlen(priv->nick) + 1;
7056 memcpy(extra, priv->nick, wrqu->data.length);
7057 wrqu->data.flags = 1; /* active */
7059 IPW_DEBUG_WX("GET Nickname -> %s \n", extra);
7064 static int ipw2100_wx_set_rate(struct net_device *dev,
7065 struct iw_request_info *info,
7066 union iwreq_data *wrqu, char *extra)
7068 struct ipw2100_priv *priv = ieee80211_priv(dev);
7069 u32 target_rate = wrqu->bitrate.value;
7073 mutex_lock(&priv->action_mutex);
7074 if (!(priv->status & STATUS_INITIALIZED)) {
7081 if (target_rate == 1000000 ||
7082 (!wrqu->bitrate.fixed && target_rate > 1000000))
7083 rate |= TX_RATE_1_MBIT;
7084 if (target_rate == 2000000 ||
7085 (!wrqu->bitrate.fixed && target_rate > 2000000))
7086 rate |= TX_RATE_2_MBIT;
7087 if (target_rate == 5500000 ||
7088 (!wrqu->bitrate.fixed && target_rate > 5500000))
7089 rate |= TX_RATE_5_5_MBIT;
7090 if (target_rate == 11000000 ||
7091 (!wrqu->bitrate.fixed && target_rate > 11000000))
7092 rate |= TX_RATE_11_MBIT;
7094 rate = DEFAULT_TX_RATES;
7096 err = ipw2100_set_tx_rates(priv, rate, 0);
7098 IPW_DEBUG_WX("SET Rate -> %04X \n", rate);
7100 mutex_unlock(&priv->action_mutex);
7104 static int ipw2100_wx_get_rate(struct net_device *dev,
7105 struct iw_request_info *info,
7106 union iwreq_data *wrqu, char *extra)
7108 struct ipw2100_priv *priv = ieee80211_priv(dev);
7110 int len = sizeof(val);
7113 if (!(priv->status & STATUS_ENABLED) ||
7114 priv->status & STATUS_RF_KILL_MASK ||
7115 !(priv->status & STATUS_ASSOCIATED)) {
7116 wrqu->bitrate.value = 0;
7120 mutex_lock(&priv->action_mutex);
7121 if (!(priv->status & STATUS_INITIALIZED)) {
7126 err = ipw2100_get_ordinal(priv, IPW_ORD_CURRENT_TX_RATE, &val, &len);
7128 IPW_DEBUG_WX("failed querying ordinals.\n");
7132 switch (val & TX_RATE_MASK) {
7133 case TX_RATE_1_MBIT:
7134 wrqu->bitrate.value = 1000000;
7136 case TX_RATE_2_MBIT:
7137 wrqu->bitrate.value = 2000000;
7139 case TX_RATE_5_5_MBIT:
7140 wrqu->bitrate.value = 5500000;
7142 case TX_RATE_11_MBIT:
7143 wrqu->bitrate.value = 11000000;
7146 wrqu->bitrate.value = 0;
7149 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
7152 mutex_unlock(&priv->action_mutex);
7156 static int ipw2100_wx_set_rts(struct net_device *dev,
7157 struct iw_request_info *info,
7158 union iwreq_data *wrqu, char *extra)
7160 struct ipw2100_priv *priv = ieee80211_priv(dev);
7163 /* Auto RTS not yet supported */
7164 if (wrqu->rts.fixed == 0)
7167 mutex_lock(&priv->action_mutex);
7168 if (!(priv->status & STATUS_INITIALIZED)) {
7173 if (wrqu->rts.disabled)
7174 value = priv->rts_threshold | RTS_DISABLED;
7176 if (wrqu->rts.value < 1 || wrqu->rts.value > 2304) {
7180 value = wrqu->rts.value;
7183 err = ipw2100_set_rts_threshold(priv, value);
7185 IPW_DEBUG_WX("SET RTS Threshold -> 0x%08X \n", value);
7187 mutex_unlock(&priv->action_mutex);
7191 static int ipw2100_wx_get_rts(struct net_device *dev,
7192 struct iw_request_info *info,
7193 union iwreq_data *wrqu, char *extra)
7196 * This can be called at any time. No action lock required
7199 struct ipw2100_priv *priv = ieee80211_priv(dev);
7201 wrqu->rts.value = priv->rts_threshold & ~RTS_DISABLED;
7202 wrqu->rts.fixed = 1; /* no auto select */
7204 /* If RTS is set to the default value, then it is disabled */
7205 wrqu->rts.disabled = (priv->rts_threshold & RTS_DISABLED) ? 1 : 0;
7207 IPW_DEBUG_WX("GET RTS Threshold -> 0x%08X \n", wrqu->rts.value);
7212 static int ipw2100_wx_set_txpow(struct net_device *dev,
7213 struct iw_request_info *info,
7214 union iwreq_data *wrqu, char *extra)
7216 struct ipw2100_priv *priv = ieee80211_priv(dev);
7219 if (ipw_radio_kill_sw(priv, wrqu->txpower.disabled))
7220 return -EINPROGRESS;
7222 if (priv->ieee->iw_mode != IW_MODE_ADHOC)
7225 if ((wrqu->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
7228 if (wrqu->txpower.fixed == 0)
7229 value = IPW_TX_POWER_DEFAULT;
7231 if (wrqu->txpower.value < IPW_TX_POWER_MIN_DBM ||
7232 wrqu->txpower.value > IPW_TX_POWER_MAX_DBM)
7235 value = wrqu->txpower.value;
7238 mutex_lock(&priv->action_mutex);
7239 if (!(priv->status & STATUS_INITIALIZED)) {
7244 err = ipw2100_set_tx_power(priv, value);
7246 IPW_DEBUG_WX("SET TX Power -> %d \n", value);
7249 mutex_unlock(&priv->action_mutex);
7253 static int ipw2100_wx_get_txpow(struct net_device *dev,
7254 struct iw_request_info *info,
7255 union iwreq_data *wrqu, char *extra)
7258 * This can be called at any time. No action lock required
7261 struct ipw2100_priv *priv = ieee80211_priv(dev);
7263 wrqu->txpower.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
7265 if (priv->tx_power == IPW_TX_POWER_DEFAULT) {
7266 wrqu->txpower.fixed = 0;
7267 wrqu->txpower.value = IPW_TX_POWER_MAX_DBM;
7269 wrqu->txpower.fixed = 1;
7270 wrqu->txpower.value = priv->tx_power;
7273 wrqu->txpower.flags = IW_TXPOW_DBM;
7275 IPW_DEBUG_WX("GET TX Power -> %d \n", wrqu->txpower.value);
7280 static int ipw2100_wx_set_frag(struct net_device *dev,
7281 struct iw_request_info *info,
7282 union iwreq_data *wrqu, char *extra)
7285 * This can be called at any time. No action lock required
7288 struct ipw2100_priv *priv = ieee80211_priv(dev);
7290 if (!wrqu->frag.fixed)
7293 if (wrqu->frag.disabled) {
7294 priv->frag_threshold |= FRAG_DISABLED;
7295 priv->ieee->fts = DEFAULT_FTS;
7297 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
7298 wrqu->frag.value > MAX_FRAG_THRESHOLD)
7301 priv->ieee->fts = wrqu->frag.value & ~0x1;
7302 priv->frag_threshold = priv->ieee->fts;
7305 IPW_DEBUG_WX("SET Frag Threshold -> %d \n", priv->ieee->fts);
7310 static int ipw2100_wx_get_frag(struct net_device *dev,
7311 struct iw_request_info *info,
7312 union iwreq_data *wrqu, char *extra)
7315 * This can be called at any time. No action lock required
7318 struct ipw2100_priv *priv = ieee80211_priv(dev);
7319 wrqu->frag.value = priv->frag_threshold & ~FRAG_DISABLED;
7320 wrqu->frag.fixed = 0; /* no auto select */
7321 wrqu->frag.disabled = (priv->frag_threshold & FRAG_DISABLED) ? 1 : 0;
7323 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
7328 static int ipw2100_wx_set_retry(struct net_device *dev,
7329 struct iw_request_info *info,
7330 union iwreq_data *wrqu, char *extra)
7332 struct ipw2100_priv *priv = ieee80211_priv(dev);
7335 if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
7338 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
7341 mutex_lock(&priv->action_mutex);
7342 if (!(priv->status & STATUS_INITIALIZED)) {
7347 if (wrqu->retry.flags & IW_RETRY_MIN) {
7348 err = ipw2100_set_short_retry(priv, wrqu->retry.value);
7349 IPW_DEBUG_WX("SET Short Retry Limit -> %d \n",
7354 if (wrqu->retry.flags & IW_RETRY_MAX) {
7355 err = ipw2100_set_long_retry(priv, wrqu->retry.value);
7356 IPW_DEBUG_WX("SET Long Retry Limit -> %d \n",
7361 err = ipw2100_set_short_retry(priv, wrqu->retry.value);
7363 err = ipw2100_set_long_retry(priv, wrqu->retry.value);
7365 IPW_DEBUG_WX("SET Both Retry Limits -> %d \n", wrqu->retry.value);
7368 mutex_unlock(&priv->action_mutex);
7372 static int ipw2100_wx_get_retry(struct net_device *dev,
7373 struct iw_request_info *info,
7374 union iwreq_data *wrqu, char *extra)
7377 * This can be called at any time. No action lock required
7380 struct ipw2100_priv *priv = ieee80211_priv(dev);
7382 wrqu->retry.disabled = 0; /* can't be disabled */
7384 if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME)
7387 if (wrqu->retry.flags & IW_RETRY_MAX) {
7388 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
7389 wrqu->retry.value = priv->long_retry_limit;
7392 (priv->short_retry_limit !=
7393 priv->long_retry_limit) ?
7394 IW_RETRY_LIMIT | IW_RETRY_MIN : IW_RETRY_LIMIT;
7396 wrqu->retry.value = priv->short_retry_limit;
7399 IPW_DEBUG_WX("GET Retry -> %d \n", wrqu->retry.value);
7404 static int ipw2100_wx_set_scan(struct net_device *dev,
7405 struct iw_request_info *info,
7406 union iwreq_data *wrqu, char *extra)
7408 struct ipw2100_priv *priv = ieee80211_priv(dev);
7411 mutex_lock(&priv->action_mutex);
7412 if (!(priv->status & STATUS_INITIALIZED)) {
7417 IPW_DEBUG_WX("Initiating scan...\n");
7418 if (ipw2100_set_scan_options(priv) || ipw2100_start_scan(priv)) {
7419 IPW_DEBUG_WX("Start scan failed.\n");
7421 /* TODO: Mark a scan as pending so when hardware initialized
7426 mutex_unlock(&priv->action_mutex);
7430 static int ipw2100_wx_get_scan(struct net_device *dev,
7431 struct iw_request_info *info,
7432 union iwreq_data *wrqu, char *extra)
7435 * This can be called at any time. No action lock required
7438 struct ipw2100_priv *priv = ieee80211_priv(dev);
7439 return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra);
7443 * Implementation based on code in hostap-driver v0.1.3 hostap_ioctl.c
7445 static int ipw2100_wx_set_encode(struct net_device *dev,
7446 struct iw_request_info *info,
7447 union iwreq_data *wrqu, char *key)
7450 * No check of STATUS_INITIALIZED required
7453 struct ipw2100_priv *priv = ieee80211_priv(dev);
7454 return ieee80211_wx_set_encode(priv->ieee, info, wrqu, key);
7457 static int ipw2100_wx_get_encode(struct net_device *dev,
7458 struct iw_request_info *info,
7459 union iwreq_data *wrqu, char *key)
7462 * This can be called at any time. No action lock required
7465 struct ipw2100_priv *priv = ieee80211_priv(dev);
7466 return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key);
7469 static int ipw2100_wx_set_power(struct net_device *dev,
7470 struct iw_request_info *info,
7471 union iwreq_data *wrqu, char *extra)
7473 struct ipw2100_priv *priv = ieee80211_priv(dev);
7476 mutex_lock(&priv->action_mutex);
7477 if (!(priv->status & STATUS_INITIALIZED)) {
7482 if (wrqu->power.disabled) {
7483 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
7484 err = ipw2100_set_power_mode(priv, IPW_POWER_MODE_CAM);
7485 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
7489 switch (wrqu->power.flags & IW_POWER_MODE) {
7490 case IW_POWER_ON: /* If not specified */
7491 case IW_POWER_MODE: /* If set all mask */
7492 case IW_POWER_ALL_R: /* If explicitely state all */
7494 default: /* Otherwise we don't support it */
7495 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
7501 /* If the user hasn't specified a power management mode yet, default
7503 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
7504 err = ipw2100_set_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
7506 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
7509 mutex_unlock(&priv->action_mutex);
7514 static int ipw2100_wx_get_power(struct net_device *dev,
7515 struct iw_request_info *info,
7516 union iwreq_data *wrqu, char *extra)
7519 * This can be called at any time. No action lock required
7522 struct ipw2100_priv *priv = ieee80211_priv(dev);
7524 if (!(priv->power_mode & IPW_POWER_ENABLED))
7525 wrqu->power.disabled = 1;
7527 wrqu->power.disabled = 0;
7528 wrqu->power.flags = 0;
7531 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
7541 static int ipw2100_wx_set_genie(struct net_device *dev,
7542 struct iw_request_info *info,
7543 union iwreq_data *wrqu, char *extra)
7546 struct ipw2100_priv *priv = ieee80211_priv(dev);
7547 struct ieee80211_device *ieee = priv->ieee;
7550 if (!ieee->wpa_enabled)
7553 if (wrqu->data.length > MAX_WPA_IE_LEN ||
7554 (wrqu->data.length && extra == NULL))
7557 if (wrqu->data.length) {
7558 buf = kmalloc(wrqu->data.length, GFP_KERNEL);
7562 memcpy(buf, extra, wrqu->data.length);
7563 kfree(ieee->wpa_ie);
7565 ieee->wpa_ie_len = wrqu->data.length;
7567 kfree(ieee->wpa_ie);
7568 ieee->wpa_ie = NULL;
7569 ieee->wpa_ie_len = 0;
7572 ipw2100_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
7578 static int ipw2100_wx_get_genie(struct net_device *dev,
7579 struct iw_request_info *info,
7580 union iwreq_data *wrqu, char *extra)
7582 struct ipw2100_priv *priv = ieee80211_priv(dev);
7583 struct ieee80211_device *ieee = priv->ieee;
7585 if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
7586 wrqu->data.length = 0;
7590 if (wrqu->data.length < ieee->wpa_ie_len)
7593 wrqu->data.length = ieee->wpa_ie_len;
7594 memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
7600 static int ipw2100_wx_set_auth(struct net_device *dev,
7601 struct iw_request_info *info,
7602 union iwreq_data *wrqu, char *extra)
7604 struct ipw2100_priv *priv = ieee80211_priv(dev);
7605 struct ieee80211_device *ieee = priv->ieee;
7606 struct iw_param *param = &wrqu->param;
7607 struct ieee80211_crypt_data *crypt;
7608 unsigned long flags;
7611 switch (param->flags & IW_AUTH_INDEX) {
7612 case IW_AUTH_WPA_VERSION:
7613 case IW_AUTH_CIPHER_PAIRWISE:
7614 case IW_AUTH_CIPHER_GROUP:
7615 case IW_AUTH_KEY_MGMT:
7617 * ipw2200 does not use these parameters
7621 case IW_AUTH_TKIP_COUNTERMEASURES:
7622 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
7623 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags)
7626 flags = crypt->ops->get_flags(crypt->priv);
7629 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
7631 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
7633 crypt->ops->set_flags(flags, crypt->priv);
7637 case IW_AUTH_DROP_UNENCRYPTED:{
7640 * wpa_supplicant calls set_wpa_enabled when the driver
7641 * is loaded and unloaded, regardless of if WPA is being
7642 * used. No other calls are made which can be used to
7643 * determine if encryption will be used or not prior to
7644 * association being expected. If encryption is not being
7645 * used, drop_unencrypted is set to false, else true -- we
7646 * can use this to determine if the CAP_PRIVACY_ON bit should
7649 struct ieee80211_security sec = {
7650 .flags = SEC_ENABLED,
7651 .enabled = param->value,
7653 priv->ieee->drop_unencrypted = param->value;
7654 /* We only change SEC_LEVEL for open mode. Others
7655 * are set by ipw_wpa_set_encryption.
7657 if (!param->value) {
7658 sec.flags |= SEC_LEVEL;
7659 sec.level = SEC_LEVEL_0;
7661 sec.flags |= SEC_LEVEL;
7662 sec.level = SEC_LEVEL_1;
7664 if (priv->ieee->set_security)
7665 priv->ieee->set_security(priv->ieee->dev, &sec);
7669 case IW_AUTH_80211_AUTH_ALG:
7670 ret = ipw2100_wpa_set_auth_algs(priv, param->value);
7673 case IW_AUTH_WPA_ENABLED:
7674 ret = ipw2100_wpa_enable(priv, param->value);
7677 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
7678 ieee->ieee802_1x = param->value;
7681 //case IW_AUTH_ROAMING_CONTROL:
7682 case IW_AUTH_PRIVACY_INVOKED:
7683 ieee->privacy_invoked = param->value;
7693 static int ipw2100_wx_get_auth(struct net_device *dev,
7694 struct iw_request_info *info,
7695 union iwreq_data *wrqu, char *extra)
7697 struct ipw2100_priv *priv = ieee80211_priv(dev);
7698 struct ieee80211_device *ieee = priv->ieee;
7699 struct ieee80211_crypt_data *crypt;
7700 struct iw_param *param = &wrqu->param;
7703 switch (param->flags & IW_AUTH_INDEX) {
7704 case IW_AUTH_WPA_VERSION:
7705 case IW_AUTH_CIPHER_PAIRWISE:
7706 case IW_AUTH_CIPHER_GROUP:
7707 case IW_AUTH_KEY_MGMT:
7709 * wpa_supplicant will control these internally
7714 case IW_AUTH_TKIP_COUNTERMEASURES:
7715 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
7716 if (!crypt || !crypt->ops->get_flags) {
7717 IPW_DEBUG_WARNING("Can't get TKIP countermeasures: "
7718 "crypt not set!\n");
7722 param->value = (crypt->ops->get_flags(crypt->priv) &
7723 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
7727 case IW_AUTH_DROP_UNENCRYPTED:
7728 param->value = ieee->drop_unencrypted;
7731 case IW_AUTH_80211_AUTH_ALG:
7732 param->value = priv->ieee->sec.auth_mode;
7735 case IW_AUTH_WPA_ENABLED:
7736 param->value = ieee->wpa_enabled;
7739 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
7740 param->value = ieee->ieee802_1x;
7743 case IW_AUTH_ROAMING_CONTROL:
7744 case IW_AUTH_PRIVACY_INVOKED:
7745 param->value = ieee->privacy_invoked;
7754 /* SIOCSIWENCODEEXT */
7755 static int ipw2100_wx_set_encodeext(struct net_device *dev,
7756 struct iw_request_info *info,
7757 union iwreq_data *wrqu, char *extra)
7759 struct ipw2100_priv *priv = ieee80211_priv(dev);
7760 return ieee80211_wx_set_encodeext(priv->ieee, info, wrqu, extra);
7763 /* SIOCGIWENCODEEXT */
7764 static int ipw2100_wx_get_encodeext(struct net_device *dev,
7765 struct iw_request_info *info,
7766 union iwreq_data *wrqu, char *extra)
7768 struct ipw2100_priv *priv = ieee80211_priv(dev);
7769 return ieee80211_wx_get_encodeext(priv->ieee, info, wrqu, extra);
7773 static int ipw2100_wx_set_mlme(struct net_device *dev,
7774 struct iw_request_info *info,
7775 union iwreq_data *wrqu, char *extra)
7777 struct ipw2100_priv *priv = ieee80211_priv(dev);
7778 struct iw_mlme *mlme = (struct iw_mlme *)extra;
7781 reason = cpu_to_le16(mlme->reason_code);
7783 switch (mlme->cmd) {
7784 case IW_MLME_DEAUTH:
7788 case IW_MLME_DISASSOC:
7789 ipw2100_disassociate_bssid(priv);
7803 #ifdef CONFIG_IPW2100_MONITOR
7804 static int ipw2100_wx_set_promisc(struct net_device *dev,
7805 struct iw_request_info *info,
7806 union iwreq_data *wrqu, char *extra)
7808 struct ipw2100_priv *priv = ieee80211_priv(dev);
7809 int *parms = (int *)extra;
7810 int enable = (parms[0] > 0);
7813 mutex_lock(&priv->action_mutex);
7814 if (!(priv->status & STATUS_INITIALIZED)) {
7820 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7821 err = ipw2100_set_channel(priv, parms[1], 0);
7824 priv->channel = parms[1];
7825 err = ipw2100_switch_mode(priv, IW_MODE_MONITOR);
7827 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
7828 err = ipw2100_switch_mode(priv, priv->last_mode);
7831 mutex_unlock(&priv->action_mutex);
7835 static int ipw2100_wx_reset(struct net_device *dev,
7836 struct iw_request_info *info,
7837 union iwreq_data *wrqu, char *extra)
7839 struct ipw2100_priv *priv = ieee80211_priv(dev);
7840 if (priv->status & STATUS_INITIALIZED)
7841 schedule_reset(priv);
7847 static int ipw2100_wx_set_powermode(struct net_device *dev,
7848 struct iw_request_info *info,
7849 union iwreq_data *wrqu, char *extra)
7851 struct ipw2100_priv *priv = ieee80211_priv(dev);
7852 int err = 0, mode = *(int *)extra;
7854 mutex_lock(&priv->action_mutex);
7855 if (!(priv->status & STATUS_INITIALIZED)) {
7860 if ((mode < 1) || (mode > POWER_MODES))
7861 mode = IPW_POWER_AUTO;
7863 if (priv->power_mode != mode)
7864 err = ipw2100_set_power_mode(priv, mode);
7866 mutex_unlock(&priv->action_mutex);
7870 #define MAX_POWER_STRING 80
7871 static int ipw2100_wx_get_powermode(struct net_device *dev,
7872 struct iw_request_info *info,
7873 union iwreq_data *wrqu, char *extra)
7876 * This can be called at any time. No action lock required
7879 struct ipw2100_priv *priv = ieee80211_priv(dev);
7880 int level = IPW_POWER_LEVEL(priv->power_mode);
7881 s32 timeout, period;
7883 if (!(priv->power_mode & IPW_POWER_ENABLED)) {
7884 snprintf(extra, MAX_POWER_STRING,
7885 "Power save level: %d (Off)", level);
7888 case IPW_POWER_MODE_CAM:
7889 snprintf(extra, MAX_POWER_STRING,
7890 "Power save level: %d (None)", level);
7892 case IPW_POWER_AUTO:
7893 snprintf(extra, MAX_POWER_STRING,
7894 "Power save level: %d (Auto)", 0);
7897 timeout = timeout_duration[level - 1] / 1000;
7898 period = period_duration[level - 1] / 1000;
7899 snprintf(extra, MAX_POWER_STRING,
7900 "Power save level: %d "
7901 "(Timeout %dms, Period %dms)",
7902 level, timeout, period);
7906 wrqu->data.length = strlen(extra) + 1;
7911 static int ipw2100_wx_set_preamble(struct net_device *dev,
7912 struct iw_request_info *info,
7913 union iwreq_data *wrqu, char *extra)
7915 struct ipw2100_priv *priv = ieee80211_priv(dev);
7916 int err, mode = *(int *)extra;
7918 mutex_lock(&priv->action_mutex);
7919 if (!(priv->status & STATUS_INITIALIZED)) {
7925 priv->config |= CFG_LONG_PREAMBLE;
7927 priv->config &= ~CFG_LONG_PREAMBLE;
7933 err = ipw2100_system_config(priv, 0);
7936 mutex_unlock(&priv->action_mutex);
7940 static int ipw2100_wx_get_preamble(struct net_device *dev,
7941 struct iw_request_info *info,
7942 union iwreq_data *wrqu, char *extra)
7945 * This can be called at any time. No action lock required
7948 struct ipw2100_priv *priv = ieee80211_priv(dev);
7950 if (priv->config & CFG_LONG_PREAMBLE)
7951 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
7953 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
7958 #ifdef CONFIG_IPW2100_MONITOR
7959 static int ipw2100_wx_set_crc_check(struct net_device *dev,
7960 struct iw_request_info *info,
7961 union iwreq_data *wrqu, char *extra)
7963 struct ipw2100_priv *priv = ieee80211_priv(dev);
7964 int err, mode = *(int *)extra;
7966 mutex_lock(&priv->action_mutex);
7967 if (!(priv->status & STATUS_INITIALIZED)) {
7973 priv->config |= CFG_CRC_CHECK;
7975 priv->config &= ~CFG_CRC_CHECK;
7983 mutex_unlock(&priv->action_mutex);
7987 static int ipw2100_wx_get_crc_check(struct net_device *dev,
7988 struct iw_request_info *info,
7989 union iwreq_data *wrqu, char *extra)
7992 * This can be called at any time. No action lock required
7995 struct ipw2100_priv *priv = ieee80211_priv(dev);
7997 if (priv->config & CFG_CRC_CHECK)
7998 snprintf(wrqu->name, IFNAMSIZ, "CRC checked (1)");
8000 snprintf(wrqu->name, IFNAMSIZ, "CRC ignored (0)");
8004 #endif /* CONFIG_IPW2100_MONITOR */
8006 static iw_handler ipw2100_wx_handlers[] = {
8007 NULL, /* SIOCSIWCOMMIT */
8008 ipw2100_wx_get_name, /* SIOCGIWNAME */
8009 NULL, /* SIOCSIWNWID */
8010 NULL, /* SIOCGIWNWID */
8011 ipw2100_wx_set_freq, /* SIOCSIWFREQ */
8012 ipw2100_wx_get_freq, /* SIOCGIWFREQ */
8013 ipw2100_wx_set_mode, /* SIOCSIWMODE */
8014 ipw2100_wx_get_mode, /* SIOCGIWMODE */
8015 NULL, /* SIOCSIWSENS */
8016 NULL, /* SIOCGIWSENS */
8017 NULL, /* SIOCSIWRANGE */
8018 ipw2100_wx_get_range, /* SIOCGIWRANGE */
8019 NULL, /* SIOCSIWPRIV */
8020 NULL, /* SIOCGIWPRIV */
8021 NULL, /* SIOCSIWSTATS */
8022 NULL, /* SIOCGIWSTATS */
8023 NULL, /* SIOCSIWSPY */
8024 NULL, /* SIOCGIWSPY */
8025 NULL, /* SIOCGIWTHRSPY */
8026 NULL, /* SIOCWIWTHRSPY */
8027 ipw2100_wx_set_wap, /* SIOCSIWAP */
8028 ipw2100_wx_get_wap, /* SIOCGIWAP */
8029 ipw2100_wx_set_mlme, /* SIOCSIWMLME */
8030 NULL, /* SIOCGIWAPLIST -- deprecated */
8031 ipw2100_wx_set_scan, /* SIOCSIWSCAN */
8032 ipw2100_wx_get_scan, /* SIOCGIWSCAN */
8033 ipw2100_wx_set_essid, /* SIOCSIWESSID */
8034 ipw2100_wx_get_essid, /* SIOCGIWESSID */
8035 ipw2100_wx_set_nick, /* SIOCSIWNICKN */
8036 ipw2100_wx_get_nick, /* SIOCGIWNICKN */
8037 NULL, /* -- hole -- */
8038 NULL, /* -- hole -- */
8039 ipw2100_wx_set_rate, /* SIOCSIWRATE */
8040 ipw2100_wx_get_rate, /* SIOCGIWRATE */
8041 ipw2100_wx_set_rts, /* SIOCSIWRTS */
8042 ipw2100_wx_get_rts, /* SIOCGIWRTS */
8043 ipw2100_wx_set_frag, /* SIOCSIWFRAG */
8044 ipw2100_wx_get_frag, /* SIOCGIWFRAG */
8045 ipw2100_wx_set_txpow, /* SIOCSIWTXPOW */
8046 ipw2100_wx_get_txpow, /* SIOCGIWTXPOW */
8047 ipw2100_wx_set_retry, /* SIOCSIWRETRY */
8048 ipw2100_wx_get_retry, /* SIOCGIWRETRY */
8049 ipw2100_wx_set_encode, /* SIOCSIWENCODE */
8050 ipw2100_wx_get_encode, /* SIOCGIWENCODE */
8051 ipw2100_wx_set_power, /* SIOCSIWPOWER */
8052 ipw2100_wx_get_power, /* SIOCGIWPOWER */
8053 NULL, /* -- hole -- */
8054 NULL, /* -- hole -- */
8055 ipw2100_wx_set_genie, /* SIOCSIWGENIE */
8056 ipw2100_wx_get_genie, /* SIOCGIWGENIE */
8057 ipw2100_wx_set_auth, /* SIOCSIWAUTH */
8058 ipw2100_wx_get_auth, /* SIOCGIWAUTH */
8059 ipw2100_wx_set_encodeext, /* SIOCSIWENCODEEXT */
8060 ipw2100_wx_get_encodeext, /* SIOCGIWENCODEEXT */
8061 NULL, /* SIOCSIWPMKSA */
8064 #define IPW2100_PRIV_SET_MONITOR SIOCIWFIRSTPRIV
8065 #define IPW2100_PRIV_RESET SIOCIWFIRSTPRIV+1
8066 #define IPW2100_PRIV_SET_POWER SIOCIWFIRSTPRIV+2
8067 #define IPW2100_PRIV_GET_POWER SIOCIWFIRSTPRIV+3
8068 #define IPW2100_PRIV_SET_LONGPREAMBLE SIOCIWFIRSTPRIV+4
8069 #define IPW2100_PRIV_GET_LONGPREAMBLE SIOCIWFIRSTPRIV+5
8070 #define IPW2100_PRIV_SET_CRC_CHECK SIOCIWFIRSTPRIV+6
8071 #define IPW2100_PRIV_GET_CRC_CHECK SIOCIWFIRSTPRIV+7
8073 static const struct iw_priv_args ipw2100_private_args[] = {
8075 #ifdef CONFIG_IPW2100_MONITOR
8077 IPW2100_PRIV_SET_MONITOR,
8078 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
8081 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
8082 #endif /* CONFIG_IPW2100_MONITOR */
8085 IPW2100_PRIV_SET_POWER,
8086 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_power"},
8088 IPW2100_PRIV_GET_POWER,
8089 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_POWER_STRING,
8092 IPW2100_PRIV_SET_LONGPREAMBLE,
8093 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_preamble"},
8095 IPW2100_PRIV_GET_LONGPREAMBLE,
8096 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, "get_preamble"},
8097 #ifdef CONFIG_IPW2100_MONITOR
8099 IPW2100_PRIV_SET_CRC_CHECK,
8100 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_crc_check"},
8102 IPW2100_PRIV_GET_CRC_CHECK,
8103 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, "get_crc_check"},
8104 #endif /* CONFIG_IPW2100_MONITOR */
8107 static iw_handler ipw2100_private_handler[] = {
8108 #ifdef CONFIG_IPW2100_MONITOR
8109 ipw2100_wx_set_promisc,
8111 #else /* CONFIG_IPW2100_MONITOR */
8114 #endif /* CONFIG_IPW2100_MONITOR */
8115 ipw2100_wx_set_powermode,
8116 ipw2100_wx_get_powermode,
8117 ipw2100_wx_set_preamble,
8118 ipw2100_wx_get_preamble,
8119 #ifdef CONFIG_IPW2100_MONITOR
8120 ipw2100_wx_set_crc_check,
8121 ipw2100_wx_get_crc_check,
8122 #else /* CONFIG_IPW2100_MONITOR */
8125 #endif /* CONFIG_IPW2100_MONITOR */
8129 * Get wireless statistics.
8130 * Called by /proc/net/wireless
8131 * Also called by SIOCGIWSTATS
8133 static struct iw_statistics *ipw2100_wx_wireless_stats(struct net_device *dev)
8147 struct ipw2100_priv *priv = ieee80211_priv(dev);
8148 struct iw_statistics *wstats;
8149 u32 rssi, quality, tx_retries, missed_beacons, tx_failures;
8150 u32 ord_len = sizeof(u32);
8153 return (struct iw_statistics *)NULL;
8155 wstats = &priv->wstats;
8157 /* if hw is disabled, then ipw2100_get_ordinal() can't be called.
8158 * ipw2100_wx_wireless_stats seems to be called before fw is
8159 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
8160 * and associated; if not associcated, the values are all meaningless
8161 * anyway, so set them all to NULL and INVALID */
8162 if (!(priv->status & STATUS_ASSOCIATED)) {
8163 wstats->miss.beacon = 0;
8164 wstats->discard.retries = 0;
8165 wstats->qual.qual = 0;
8166 wstats->qual.level = 0;
8167 wstats->qual.noise = 0;
8168 wstats->qual.updated = 7;
8169 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
8170 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
8174 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_PERCENT_MISSED_BCNS,
8175 &missed_beacons, &ord_len))
8176 goto fail_get_ordinal;
8178 /* If we don't have a connection the quality and level is 0 */
8179 if (!(priv->status & STATUS_ASSOCIATED)) {
8180 wstats->qual.qual = 0;
8181 wstats->qual.level = 0;
8183 if (ipw2100_get_ordinal(priv, IPW_ORD_RSSI_AVG_CURR,
8185 goto fail_get_ordinal;
8186 wstats->qual.level = rssi + IPW2100_RSSI_TO_DBM;
8188 rssi_qual = rssi * POOR / 10;
8190 rssi_qual = (rssi - 10) * (FAIR - POOR) / 5 + POOR;
8192 rssi_qual = (rssi - 15) * (GOOD - FAIR) / 5 + FAIR;
8194 rssi_qual = (rssi - 20) * (VERY_GOOD - GOOD) /
8197 rssi_qual = (rssi - 30) * (PERFECT - VERY_GOOD) /
8200 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_PERCENT_RETRIES,
8201 &tx_retries, &ord_len))
8202 goto fail_get_ordinal;
8204 if (tx_retries > 75)
8205 tx_qual = (90 - tx_retries) * POOR / 15;
8206 else if (tx_retries > 70)
8207 tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
8208 else if (tx_retries > 65)
8209 tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
8210 else if (tx_retries > 50)
8211 tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
8214 tx_qual = (50 - tx_retries) *
8215 (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
8217 if (missed_beacons > 50)
8218 beacon_qual = (60 - missed_beacons) * POOR / 10;
8219 else if (missed_beacons > 40)
8220 beacon_qual = (50 - missed_beacons) * (FAIR - POOR) /
8222 else if (missed_beacons > 32)
8223 beacon_qual = (40 - missed_beacons) * (GOOD - FAIR) /
8225 else if (missed_beacons > 20)
8226 beacon_qual = (32 - missed_beacons) *
8227 (VERY_GOOD - GOOD) / 20 + GOOD;
8229 beacon_qual = (20 - missed_beacons) *
8230 (PERFECT - VERY_GOOD) / 20 + VERY_GOOD;
8232 quality = min(beacon_qual, min(tx_qual, rssi_qual));
8234 #ifdef CONFIG_IPW2100_DEBUG
8235 if (beacon_qual == quality)
8236 IPW_DEBUG_WX("Quality clamped by Missed Beacons\n");
8237 else if (tx_qual == quality)
8238 IPW_DEBUG_WX("Quality clamped by Tx Retries\n");
8239 else if (quality != 100)
8240 IPW_DEBUG_WX("Quality clamped by Signal Strength\n");
8242 IPW_DEBUG_WX("Quality not clamped.\n");
8245 wstats->qual.qual = quality;
8246 wstats->qual.level = rssi + IPW2100_RSSI_TO_DBM;
8249 wstats->qual.noise = 0;
8250 wstats->qual.updated = 7;
8251 wstats->qual.updated |= IW_QUAL_NOISE_INVALID;
8253 /* FIXME: this is percent and not a # */
8254 wstats->miss.beacon = missed_beacons;
8256 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURES,
8257 &tx_failures, &ord_len))
8258 goto fail_get_ordinal;
8259 wstats->discard.retries = tx_failures;
8264 IPW_DEBUG_WX("failed querying ordinals.\n");
8266 return (struct iw_statistics *)NULL;
8269 static struct iw_handler_def ipw2100_wx_handler_def = {
8270 .standard = ipw2100_wx_handlers,
8271 .num_standard = sizeof(ipw2100_wx_handlers) / sizeof(iw_handler),
8272 .num_private = sizeof(ipw2100_private_handler) / sizeof(iw_handler),
8273 .num_private_args = sizeof(ipw2100_private_args) /
8274 sizeof(struct iw_priv_args),
8275 .private = (iw_handler *) ipw2100_private_handler,
8276 .private_args = (struct iw_priv_args *)ipw2100_private_args,
8277 .get_wireless_stats = ipw2100_wx_wireless_stats,
8280 static void ipw2100_wx_event_work(struct ipw2100_priv *priv)
8282 union iwreq_data wrqu;
8285 if (priv->status & STATUS_STOPPING)
8288 mutex_lock(&priv->action_mutex);
8290 IPW_DEBUG_WX("enter\n");
8292 mutex_unlock(&priv->action_mutex);
8294 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
8296 /* Fetch BSSID from the hardware */
8297 if (!(priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) ||
8298 priv->status & STATUS_RF_KILL_MASK ||
8299 ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID,
8300 &priv->bssid, &len)) {
8301 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
8303 /* We now have the BSSID, so can finish setting to the full
8304 * associated state */
8305 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
8306 memcpy(priv->ieee->bssid, priv->bssid, ETH_ALEN);
8307 priv->status &= ~STATUS_ASSOCIATING;
8308 priv->status |= STATUS_ASSOCIATED;
8309 netif_carrier_on(priv->net_dev);
8310 netif_wake_queue(priv->net_dev);
8313 if (!(priv->status & STATUS_ASSOCIATED)) {
8314 IPW_DEBUG_WX("Configuring ESSID\n");
8315 mutex_lock(&priv->action_mutex);
8316 /* This is a disassociation event, so kick the firmware to
8317 * look for another AP */
8318 if (priv->config & CFG_STATIC_ESSID)
8319 ipw2100_set_essid(priv, priv->essid, priv->essid_len,
8322 ipw2100_set_essid(priv, NULL, 0, 0);
8323 mutex_unlock(&priv->action_mutex);
8326 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
8329 #define IPW2100_FW_MAJOR_VERSION 1
8330 #define IPW2100_FW_MINOR_VERSION 3
8332 #define IPW2100_FW_MINOR(x) ((x & 0xff) >> 8)
8333 #define IPW2100_FW_MAJOR(x) (x & 0xff)
8335 #define IPW2100_FW_VERSION ((IPW2100_FW_MINOR_VERSION << 8) | \
8336 IPW2100_FW_MAJOR_VERSION)
8338 #define IPW2100_FW_PREFIX "ipw2100-" __stringify(IPW2100_FW_MAJOR_VERSION) \
8339 "." __stringify(IPW2100_FW_MINOR_VERSION)
8341 #define IPW2100_FW_NAME(x) IPW2100_FW_PREFIX "" x ".fw"
8345 BINARY FIRMWARE HEADER FORMAT
8349 2 2 mode == 0:BSS,1:IBSS,2:MONITOR
8352 C fw_len firmware data
8353 12 + fw_len uc_len microcode data
8357 struct ipw2100_fw_header {
8360 unsigned int fw_size;
8361 unsigned int uc_size;
8362 } __attribute__ ((packed));
8364 static int ipw2100_mod_firmware_load(struct ipw2100_fw *fw)
8366 struct ipw2100_fw_header *h =
8367 (struct ipw2100_fw_header *)fw->fw_entry->data;
8369 if (IPW2100_FW_MAJOR(h->version) != IPW2100_FW_MAJOR_VERSION) {
8370 printk(KERN_WARNING DRV_NAME ": Firmware image not compatible "
8371 "(detected version id of %u). "
8372 "See Documentation/networking/README.ipw2100\n",
8377 fw->version = h->version;
8378 fw->fw.data = fw->fw_entry->data + sizeof(struct ipw2100_fw_header);
8379 fw->fw.size = h->fw_size;
8380 fw->uc.data = fw->fw.data + h->fw_size;
8381 fw->uc.size = h->uc_size;
8386 static int ipw2100_get_firmware(struct ipw2100_priv *priv,
8387 struct ipw2100_fw *fw)
8392 IPW_DEBUG_INFO("%s: Using hotplug firmware load.\n",
8393 priv->net_dev->name);
8395 switch (priv->ieee->iw_mode) {
8397 fw_name = IPW2100_FW_NAME("-i");
8399 #ifdef CONFIG_IPW2100_MONITOR
8400 case IW_MODE_MONITOR:
8401 fw_name = IPW2100_FW_NAME("-p");
8406 fw_name = IPW2100_FW_NAME("");
8410 rc = request_firmware(&fw->fw_entry, fw_name, &priv->pci_dev->dev);
8413 printk(KERN_ERR DRV_NAME ": "
8414 "%s: Firmware '%s' not available or load failed.\n",
8415 priv->net_dev->name, fw_name);
8418 IPW_DEBUG_INFO("firmware data %p size %zd\n", fw->fw_entry->data,
8419 fw->fw_entry->size);
8421 ipw2100_mod_firmware_load(fw);
8426 static void ipw2100_release_firmware(struct ipw2100_priv *priv,
8427 struct ipw2100_fw *fw)
8431 release_firmware(fw->fw_entry);
8432 fw->fw_entry = NULL;
8435 static int ipw2100_get_fwversion(struct ipw2100_priv *priv, char *buf,
8438 char ver[MAX_FW_VERSION_LEN];
8439 u32 len = MAX_FW_VERSION_LEN;
8442 /* firmware version is an ascii string (max len of 14) */
8443 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_FW_VER_NUM, ver, &len))
8448 for (i = 0; i < len; i++)
8454 static int ipw2100_get_ucodeversion(struct ipw2100_priv *priv, char *buf,
8458 u32 len = sizeof(ver);
8459 /* microcode version is a 32 bit integer */
8460 if (ipw2100_get_ordinal(priv, IPW_ORD_UCODE_VERSION, &ver, &len))
8462 return snprintf(buf, max, "%08X", ver);
8466 * On exit, the firmware will have been freed from the fw list
8468 static int ipw2100_fw_download(struct ipw2100_priv *priv, struct ipw2100_fw *fw)
8470 /* firmware is constructed of N contiguous entries, each entry is
8474 * 0 4 address to write to
8475 * 4 2 length of data run
8481 const unsigned char *firmware_data = fw->fw.data;
8482 unsigned int firmware_data_left = fw->fw.size;
8484 while (firmware_data_left > 0) {
8485 addr = *(u32 *) (firmware_data);
8487 firmware_data_left -= 4;
8489 len = *(u16 *) (firmware_data);
8491 firmware_data_left -= 2;
8494 printk(KERN_ERR DRV_NAME ": "
8495 "Invalid firmware run-length of %d bytes\n",
8500 write_nic_memory(priv->net_dev, addr, len, firmware_data);
8501 firmware_data += len;
8502 firmware_data_left -= len;
8508 struct symbol_alive_response {
8517 u16 clock_settle_time; // 1us LSB
8518 u16 powerup_settle_time; // 1us LSB
8519 u16 hop_settle_time; // 1us LSB
8520 u8 date[3]; // month, day, year
8521 u8 time[2]; // hours, minutes
8525 static int ipw2100_ucode_download(struct ipw2100_priv *priv,
8526 struct ipw2100_fw *fw)
8528 struct net_device *dev = priv->net_dev;
8529 const unsigned char *microcode_data = fw->uc.data;
8530 unsigned int microcode_data_left = fw->uc.size;
8531 void __iomem *reg = (void __iomem *)dev->base_addr;
8533 struct symbol_alive_response response;
8537 /* Symbol control */
8538 write_nic_word(dev, IPW2100_CONTROL_REG, 0x703);
8540 write_nic_word(dev, IPW2100_CONTROL_REG, 0x707);
8544 write_nic_byte(dev, 0x210014, 0x72); /* fifo width =16 */
8546 write_nic_byte(dev, 0x210014, 0x72); /* fifo width =16 */
8549 /* EN_CS_ACCESS bit to reset control store pointer */
8550 write_nic_byte(dev, 0x210000, 0x40);
8552 write_nic_byte(dev, 0x210000, 0x0);
8554 write_nic_byte(dev, 0x210000, 0x40);
8557 /* copy microcode from buffer into Symbol */
8559 while (microcode_data_left > 0) {
8560 write_nic_byte(dev, 0x210010, *microcode_data++);
8561 write_nic_byte(dev, 0x210010, *microcode_data++);
8562 microcode_data_left -= 2;
8565 /* EN_CS_ACCESS bit to reset the control store pointer */
8566 write_nic_byte(dev, 0x210000, 0x0);
8569 /* Enable System (Reg 0)
8570 * first enable causes garbage in RX FIFO */
8571 write_nic_byte(dev, 0x210000, 0x0);
8573 write_nic_byte(dev, 0x210000, 0x80);
8576 /* Reset External Baseband Reg */
8577 write_nic_word(dev, IPW2100_CONTROL_REG, 0x703);
8579 write_nic_word(dev, IPW2100_CONTROL_REG, 0x707);
8582 /* HW Config (Reg 5) */
8583 write_nic_byte(dev, 0x210014, 0x72); // fifo width =16
8585 write_nic_byte(dev, 0x210014, 0x72); // fifo width =16
8588 /* Enable System (Reg 0)
8589 * second enable should be OK */
8590 write_nic_byte(dev, 0x210000, 0x00); // clear enable system
8592 write_nic_byte(dev, 0x210000, 0x80); // set enable system
8594 /* check Symbol is enabled - upped this from 5 as it wasn't always
8595 * catching the update */
8596 for (i = 0; i < 10; i++) {
8599 /* check Dino is enabled bit */
8600 read_nic_byte(dev, 0x210000, &data);
8606 printk(KERN_ERR DRV_NAME ": %s: Error initializing Symbol\n",
8611 /* Get Symbol alive response */
8612 for (i = 0; i < 30; i++) {
8613 /* Read alive response structure */
8615 j < (sizeof(struct symbol_alive_response) >> 1); j++)
8616 read_nic_word(dev, 0x210004, ((u16 *) & response) + j);
8618 if ((response.cmd_id == 1) && (response.ucode_valid == 0x1))
8624 printk(KERN_ERR DRV_NAME
8625 ": %s: No response from Symbol - hw not alive\n",
8627 printk_buf(IPW_DL_ERROR, (u8 *) & response, sizeof(response));