1 // SPDX-License-Identifier: GPL-2.0-only
2 /******************************************************************************
4 Copyright(c) 2003 - 2006 Intel Corporation. All rights reserved.
8 Intel Linux Wireless <ilw@linux.intel.com>
9 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
11 Portions of this file are based on the sample_* files provided by Wireless
12 Extensions 0.26 package and copyright (c) 1997-2003 Jean Tourrilhes
15 Portions of this file are based on the Host AP project,
16 Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
18 Copyright (c) 2002-2003, Jouni Malinen <j@w1.fi>
20 Portions of ipw2100_mod_firmware_load, ipw2100_do_mod_firmware_load, and
21 ipw2100_fw_load are loosely based on drivers/sound/sound_firmware.c
22 available in the 2.4.25 kernel sources, and are copyright (c) Alan Cox
24 ******************************************************************************/
27 Initial driver on which this is based was developed by Janusz Gorycki,
28 Maciej Urbaniak, and Maciej Sosnowski.
30 Promiscuous mode support added by Jacek Wysoczynski and Maciej Urbaniak.
34 Tx - Commands and Data
36 Firmware and host share a circular queue of Transmit Buffer Descriptors (TBDs)
37 Each TBD contains a pointer to the physical (dma_addr_t) address of data being
38 sent to the firmware as well as the length of the data.
40 The host writes to the TBD queue at the WRITE index. The WRITE index points
41 to the _next_ packet to be written and is advanced when after the TBD has been
44 The firmware pulls from the TBD queue at the READ index. The READ index points
45 to the currently being read entry, and is advanced once the firmware is
48 When data is sent to the firmware, the first TBD is used to indicate to the
49 firmware if a Command or Data is being sent. If it is Command, all of the
50 command information is contained within the physical address referred to by the
51 TBD. If it is Data, the first TBD indicates the type of data packet, number
52 of fragments, etc. The next TBD then refers to the actual packet location.
54 The Tx flow cycle is as follows:
56 1) ipw2100_tx() is called by kernel with SKB to transmit
57 2) Packet is move from the tx_free_list and appended to the transmit pending
59 3) work is scheduled to move pending packets into the shared circular queue.
60 4) when placing packet in the circular queue, the incoming SKB is DMA mapped
61 to a physical address. That address is entered into a TBD. Two TBDs are
62 filled out. The first indicating a data packet, the second referring to the
64 5) the packet is removed from tx_pend_list and placed on the end of the
65 firmware pending list (fw_pend_list)
66 6) firmware is notified that the WRITE index has
67 7) Once the firmware has processed the TBD, INTA is triggered.
68 8) For each Tx interrupt received from the firmware, the READ index is checked
69 to see which TBDs are done being processed.
70 9) For each TBD that has been processed, the ISR pulls the oldest packet
71 from the fw_pend_list.
72 10)The packet structure contained in the fw_pend_list is then used
73 to unmap the DMA address and to free the SKB originally passed to the driver
75 11)The packet structure is placed onto the tx_free_list
77 The above steps are the same for commands, only the msg_free_list/msg_pend_list
78 are used instead of tx_free_list/tx_pend_list
82 Critical Sections / Locking :
84 There are two locks utilized. The first is the low level lock (priv->low_lock)
85 that protects the following:
87 - Access to the Tx/Rx queue lists via priv->low_lock. The lists are as follows:
89 tx_free_list : Holds pre-allocated Tx buffers.
90 TAIL modified in __ipw2100_tx_process()
91 HEAD modified in ipw2100_tx()
93 tx_pend_list : Holds used Tx buffers waiting to go into the TBD ring
94 TAIL modified ipw2100_tx()
95 HEAD modified by ipw2100_tx_send_data()
97 msg_free_list : Holds pre-allocated Msg (Command) buffers
98 TAIL modified in __ipw2100_tx_process()
99 HEAD modified in ipw2100_hw_send_command()
101 msg_pend_list : Holds used Msg buffers waiting to go into the TBD ring
102 TAIL modified in ipw2100_hw_send_command()
103 HEAD modified in ipw2100_tx_send_commands()
105 The flow of data on the TX side is as follows:
107 MSG_FREE_LIST + COMMAND => MSG_PEND_LIST => TBD => MSG_FREE_LIST
108 TX_FREE_LIST + DATA => TX_PEND_LIST => TBD => TX_FREE_LIST
110 The methods that work on the TBD ring are protected via priv->low_lock.
112 - The internal data state of the device itself
113 - Access to the firmware read/write indexes for the BD queues
116 All external entry functions are locked with the priv->action_lock to ensure
117 that only one external action is invoked at a time.
122 #include <linux/compiler.h>
123 #include <linux/errno.h>
124 #include <linux/if_arp.h>
125 #include <linux/in6.h>
126 #include <linux/in.h>
127 #include <linux/ip.h>
128 #include <linux/kernel.h>
129 #include <linux/kmod.h>
130 #include <linux/module.h>
131 #include <linux/netdevice.h>
132 #include <linux/ethtool.h>
133 #include <linux/pci.h>
134 #include <linux/dma-mapping.h>
135 #include <linux/proc_fs.h>
136 #include <linux/skbuff.h>
137 #include <linux/uaccess.h>
139 #include <linux/fs.h>
140 #include <linux/mm.h>
141 #include <linux/slab.h>
142 #include <linux/unistd.h>
143 #include <linux/stringify.h>
144 #include <linux/tcp.h>
145 #include <linux/types.h>
146 #include <linux/time.h>
147 #include <linux/firmware.h>
148 #include <linux/acpi.h>
149 #include <linux/ctype.h>
150 #include <linux/pm_qos.h>
152 #include <net/lib80211.h>
157 #define IPW2100_VERSION "git-1.2.2"
159 #define DRV_NAME "ipw2100"
160 #define DRV_VERSION IPW2100_VERSION
161 #define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2100 Network Driver"
162 #define DRV_COPYRIGHT "Copyright(c) 2003-2006 Intel Corporation"
164 static struct pm_qos_request ipw2100_pm_qos_req;
166 /* Debugging stuff */
167 #ifdef CONFIG_IPW2100_DEBUG
168 #define IPW2100_RX_DEBUG /* Reception debugging */
171 MODULE_DESCRIPTION(DRV_DESCRIPTION);
172 MODULE_VERSION(DRV_VERSION);
173 MODULE_AUTHOR(DRV_COPYRIGHT);
174 MODULE_LICENSE("GPL");
176 static int debug = 0;
177 static int network_mode = 0;
178 static int channel = 0;
179 static int associate = 0;
180 static int disable = 0;
182 static struct ipw2100_fw ipw2100_firmware;
185 #include <linux/moduleparam.h>
186 module_param(debug, int, 0444);
187 module_param_named(mode, network_mode, int, 0444);
188 module_param(channel, int, 0444);
189 module_param(associate, int, 0444);
190 module_param(disable, int, 0444);
192 MODULE_PARM_DESC(debug, "debug level");
193 MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
194 MODULE_PARM_DESC(channel, "channel");
195 MODULE_PARM_DESC(associate, "auto associate when scanning (default off)");
196 MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
198 static u32 ipw2100_debug_level = IPW_DL_NONE;
200 #ifdef CONFIG_IPW2100_DEBUG
201 #define IPW_DEBUG(level, message...) \
203 if (ipw2100_debug_level & (level)) { \
204 printk(KERN_DEBUG "ipw2100: %s ", __func__); \
209 #define IPW_DEBUG(level, message...) do {} while (0)
210 #endif /* CONFIG_IPW2100_DEBUG */
212 #ifdef CONFIG_IPW2100_DEBUG
213 static const char *command_types[] = {
215 "unused", /* HOST_ATTENTION */
217 "unused", /* SLEEP */
218 "unused", /* HOST_POWER_DOWN */
221 "unused", /* SET_IMR */
224 "AUTHENTICATION_TYPE",
227 "INTERNATIONAL_MODE",
242 "CLEAR_ALL_MULTICAST",
263 "AP_OR_STATION_TABLE",
267 "unused", /* SAVE_CALIBRATION */
268 "unused", /* RESTORE_CALIBRATION */
272 "HOST_PRE_POWER_DOWN",
273 "unused", /* HOST_INTERRUPT_COALESCING */
275 "CARD_DISABLE_PHY_OFF",
278 "SET_STATION_STAT_BITS",
279 "CLEAR_STATIONS_STAT_BITS",
281 "SET_SECURITY_INFORMATION",
282 "DISASSOCIATION_BSSID",
287 static const long ipw2100_frequencies[] = {
288 2412, 2417, 2422, 2427,
289 2432, 2437, 2442, 2447,
290 2452, 2457, 2462, 2467,
294 #define FREQ_COUNT ARRAY_SIZE(ipw2100_frequencies)
296 static struct ieee80211_rate ipw2100_bg_rates[] = {
298 { .bitrate = 20, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
299 { .bitrate = 55, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
300 { .bitrate = 110, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
303 #define RATE_COUNT ARRAY_SIZE(ipw2100_bg_rates)
305 /* Pre-decl until we get the code solid and then we can clean it up */
306 static void ipw2100_tx_send_commands(struct ipw2100_priv *priv);
307 static void ipw2100_tx_send_data(struct ipw2100_priv *priv);
308 static int ipw2100_adapter_setup(struct ipw2100_priv *priv);
310 static void ipw2100_queues_initialize(struct ipw2100_priv *priv);
311 static void ipw2100_queues_free(struct ipw2100_priv *priv);
312 static int ipw2100_queues_allocate(struct ipw2100_priv *priv);
314 static int ipw2100_fw_download(struct ipw2100_priv *priv,
315 struct ipw2100_fw *fw);
316 static int ipw2100_get_firmware(struct ipw2100_priv *priv,
317 struct ipw2100_fw *fw);
318 static int ipw2100_get_fwversion(struct ipw2100_priv *priv, char *buf,
320 static int ipw2100_get_ucodeversion(struct ipw2100_priv *priv, char *buf,
322 static void ipw2100_release_firmware(struct ipw2100_priv *priv,
323 struct ipw2100_fw *fw);
324 static int ipw2100_ucode_download(struct ipw2100_priv *priv,
325 struct ipw2100_fw *fw);
326 static void ipw2100_wx_event_work(struct work_struct *work);
327 static struct iw_statistics *ipw2100_wx_wireless_stats(struct net_device *dev);
328 static const struct iw_handler_def ipw2100_wx_handler_def;
330 static inline void read_register(struct net_device *dev, u32 reg, u32 * val)
332 struct ipw2100_priv *priv = libipw_priv(dev);
334 *val = ioread32(priv->ioaddr + reg);
335 IPW_DEBUG_IO("r: 0x%08X => 0x%08X\n", reg, *val);
338 static inline void write_register(struct net_device *dev, u32 reg, u32 val)
340 struct ipw2100_priv *priv = libipw_priv(dev);
342 iowrite32(val, priv->ioaddr + reg);
343 IPW_DEBUG_IO("w: 0x%08X <= 0x%08X\n", reg, val);
346 static inline void read_register_word(struct net_device *dev, u32 reg,
349 struct ipw2100_priv *priv = libipw_priv(dev);
351 *val = ioread16(priv->ioaddr + reg);
352 IPW_DEBUG_IO("r: 0x%08X => %04X\n", reg, *val);
355 static inline void read_register_byte(struct net_device *dev, u32 reg, u8 * val)
357 struct ipw2100_priv *priv = libipw_priv(dev);
359 *val = ioread8(priv->ioaddr + reg);
360 IPW_DEBUG_IO("r: 0x%08X => %02X\n", reg, *val);
363 static inline void write_register_word(struct net_device *dev, u32 reg, u16 val)
365 struct ipw2100_priv *priv = libipw_priv(dev);
367 iowrite16(val, priv->ioaddr + reg);
368 IPW_DEBUG_IO("w: 0x%08X <= %04X\n", reg, val);
371 static inline void write_register_byte(struct net_device *dev, u32 reg, u8 val)
373 struct ipw2100_priv *priv = libipw_priv(dev);
375 iowrite8(val, priv->ioaddr + reg);
376 IPW_DEBUG_IO("w: 0x%08X =< %02X\n", reg, val);
379 static inline void read_nic_dword(struct net_device *dev, u32 addr, u32 * val)
381 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
382 addr & IPW_REG_INDIRECT_ADDR_MASK);
383 read_register(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
386 static inline void write_nic_dword(struct net_device *dev, u32 addr, u32 val)
388 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
389 addr & IPW_REG_INDIRECT_ADDR_MASK);
390 write_register(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
393 static inline void read_nic_word(struct net_device *dev, u32 addr, u16 * val)
395 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
396 addr & IPW_REG_INDIRECT_ADDR_MASK);
397 read_register_word(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
400 static inline void write_nic_word(struct net_device *dev, u32 addr, u16 val)
402 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
403 addr & IPW_REG_INDIRECT_ADDR_MASK);
404 write_register_word(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
407 static inline void read_nic_byte(struct net_device *dev, u32 addr, u8 * val)
409 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
410 addr & IPW_REG_INDIRECT_ADDR_MASK);
411 read_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
414 static inline void write_nic_byte(struct net_device *dev, u32 addr, u8 val)
416 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
417 addr & IPW_REG_INDIRECT_ADDR_MASK);
418 write_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
421 static inline void write_nic_auto_inc_address(struct net_device *dev, u32 addr)
423 write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS,
424 addr & IPW_REG_INDIRECT_ADDR_MASK);
427 static inline void write_nic_dword_auto_inc(struct net_device *dev, u32 val)
429 write_register(dev, IPW_REG_AUTOINCREMENT_DATA, val);
432 static void write_nic_memory(struct net_device *dev, u32 addr, u32 len,
440 /* read first nibble byte by byte */
441 aligned_addr = addr & (~0x3);
442 dif_len = addr - aligned_addr;
444 /* Start reading at aligned_addr + dif_len */
445 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
447 for (i = dif_len; i < 4; i++, buf++)
448 write_register_byte(dev,
449 IPW_REG_INDIRECT_ACCESS_DATA + i,
456 /* read DWs through autoincrement registers */
457 write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS, aligned_addr);
458 aligned_len = len & (~0x3);
459 for (i = 0; i < aligned_len; i += 4, buf += 4, aligned_addr += 4)
460 write_register(dev, IPW_REG_AUTOINCREMENT_DATA, *(u32 *) buf);
462 /* copy the last nibble */
463 dif_len = len - aligned_len;
464 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, aligned_addr);
465 for (i = 0; i < dif_len; i++, buf++)
466 write_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA + i,
470 static void read_nic_memory(struct net_device *dev, u32 addr, u32 len,
478 /* read first nibble byte by byte */
479 aligned_addr = addr & (~0x3);
480 dif_len = addr - aligned_addr;
482 /* Start reading at aligned_addr + dif_len */
483 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
485 for (i = dif_len; i < 4; i++, buf++)
486 read_register_byte(dev,
487 IPW_REG_INDIRECT_ACCESS_DATA + i,
494 /* read DWs through autoincrement registers */
495 write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS, aligned_addr);
496 aligned_len = len & (~0x3);
497 for (i = 0; i < aligned_len; i += 4, buf += 4, aligned_addr += 4)
498 read_register(dev, IPW_REG_AUTOINCREMENT_DATA, (u32 *) buf);
500 /* copy the last nibble */
501 dif_len = len - aligned_len;
502 write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, aligned_addr);
503 for (i = 0; i < dif_len; i++, buf++)
504 read_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA + i, buf);
507 static bool ipw2100_hw_is_adapter_in_system(struct net_device *dev)
511 read_register(dev, IPW_REG_DOA_DEBUG_AREA_START, &dbg);
513 return dbg == IPW_DATA_DOA_DEBUG_VALUE;
516 static int ipw2100_get_ordinal(struct ipw2100_priv *priv, u32 ord,
517 void *val, u32 * len)
519 struct ipw2100_ordinals *ordinals = &priv->ordinals;
526 if (ordinals->table1_addr == 0) {
527 printk(KERN_WARNING DRV_NAME ": attempt to use fw ordinals "
528 "before they have been loaded.\n");
532 if (IS_ORDINAL_TABLE_ONE(ordinals, ord)) {
533 if (*len < IPW_ORD_TAB_1_ENTRY_SIZE) {
534 *len = IPW_ORD_TAB_1_ENTRY_SIZE;
536 printk(KERN_WARNING DRV_NAME
537 ": ordinal buffer length too small, need %zd\n",
538 IPW_ORD_TAB_1_ENTRY_SIZE);
543 read_nic_dword(priv->net_dev,
544 ordinals->table1_addr + (ord << 2), &addr);
545 read_nic_dword(priv->net_dev, addr, val);
547 *len = IPW_ORD_TAB_1_ENTRY_SIZE;
552 if (IS_ORDINAL_TABLE_TWO(ordinals, ord)) {
554 ord -= IPW_START_ORD_TAB_2;
556 /* get the address of statistic */
557 read_nic_dword(priv->net_dev,
558 ordinals->table2_addr + (ord << 3), &addr);
560 /* get the second DW of statistics ;
561 * two 16-bit words - first is length, second is count */
562 read_nic_dword(priv->net_dev,
563 ordinals->table2_addr + (ord << 3) + sizeof(u32),
566 /* get each entry length */
567 field_len = *((u16 *) & field_info);
569 /* get number of entries */
570 field_count = *(((u16 *) & field_info) + 1);
572 /* abort if no enough memory */
573 total_length = field_len * field_count;
574 if (total_length > *len) {
583 /* read the ordinal data from the SRAM */
584 read_nic_memory(priv->net_dev, addr, total_length, val);
589 printk(KERN_WARNING DRV_NAME ": ordinal %d neither in table 1 nor "
590 "in table 2\n", ord);
595 static int ipw2100_set_ordinal(struct ipw2100_priv *priv, u32 ord, u32 * val,
598 struct ipw2100_ordinals *ordinals = &priv->ordinals;
601 if (IS_ORDINAL_TABLE_ONE(ordinals, ord)) {
602 if (*len != IPW_ORD_TAB_1_ENTRY_SIZE) {
603 *len = IPW_ORD_TAB_1_ENTRY_SIZE;
604 IPW_DEBUG_INFO("wrong size\n");
608 read_nic_dword(priv->net_dev,
609 ordinals->table1_addr + (ord << 2), &addr);
611 write_nic_dword(priv->net_dev, addr, *val);
613 *len = IPW_ORD_TAB_1_ENTRY_SIZE;
618 IPW_DEBUG_INFO("wrong table\n");
619 if (IS_ORDINAL_TABLE_TWO(ordinals, ord))
625 static char *snprint_line(char *buf, size_t count,
626 const u8 * data, u32 len, u32 ofs)
631 out = scnprintf(buf, count, "%08X", ofs);
633 for (l = 0, i = 0; i < 2; i++) {
634 out += scnprintf(buf + out, count - out, " ");
635 for (j = 0; j < 8 && l < len; j++, l++)
636 out += scnprintf(buf + out, count - out, "%02X ",
639 out += scnprintf(buf + out, count - out, " ");
642 out += scnprintf(buf + out, count - out, " ");
643 for (l = 0, i = 0; i < 2; i++) {
644 out += scnprintf(buf + out, count - out, " ");
645 for (j = 0; j < 8 && l < len; j++, l++) {
646 c = data[(i * 8 + j)];
647 if (!isascii(c) || !isprint(c))
650 out += scnprintf(buf + out, count - out, "%c", c);
654 out += scnprintf(buf + out, count - out, " ");
660 static void printk_buf(int level, const u8 * data, u32 len)
664 if (!(ipw2100_debug_level & level))
668 printk(KERN_DEBUG "%s\n",
669 snprint_line(line, sizeof(line), &data[ofs],
670 min(len, 16U), ofs));
672 len -= min(len, 16U);
676 #define MAX_RESET_BACKOFF 10
678 static void schedule_reset(struct ipw2100_priv *priv)
680 time64_t now = ktime_get_boottime_seconds();
682 /* If we haven't received a reset request within the backoff period,
683 * then we can reset the backoff interval so this reset occurs
685 if (priv->reset_backoff &&
686 (now - priv->last_reset > priv->reset_backoff))
687 priv->reset_backoff = 0;
689 priv->last_reset = now;
691 if (!(priv->status & STATUS_RESET_PENDING)) {
692 IPW_DEBUG_INFO("%s: Scheduling firmware restart (%llds).\n",
693 priv->net_dev->name, priv->reset_backoff);
694 netif_carrier_off(priv->net_dev);
695 netif_stop_queue(priv->net_dev);
696 priv->status |= STATUS_RESET_PENDING;
697 if (priv->reset_backoff)
698 schedule_delayed_work(&priv->reset_work,
699 priv->reset_backoff * HZ);
701 schedule_delayed_work(&priv->reset_work, 0);
703 if (priv->reset_backoff < MAX_RESET_BACKOFF)
704 priv->reset_backoff++;
706 wake_up_interruptible(&priv->wait_command_queue);
708 IPW_DEBUG_INFO("%s: Firmware restart already in progress.\n",
709 priv->net_dev->name);
713 #define HOST_COMPLETE_TIMEOUT (2 * HZ)
714 static int ipw2100_hw_send_command(struct ipw2100_priv *priv,
715 struct host_command *cmd)
717 struct list_head *element;
718 struct ipw2100_tx_packet *packet;
722 IPW_DEBUG_HC("Sending %s command (#%d), %d bytes\n",
723 command_types[cmd->host_command], cmd->host_command,
724 cmd->host_command_length);
725 printk_buf(IPW_DL_HC, (u8 *) cmd->host_command_parameters,
726 cmd->host_command_length);
728 spin_lock_irqsave(&priv->low_lock, flags);
730 if (priv->fatal_error) {
732 ("Attempt to send command while hardware in fatal error condition.\n");
737 if (!(priv->status & STATUS_RUNNING)) {
739 ("Attempt to send command while hardware is not running.\n");
744 if (priv->status & STATUS_CMD_ACTIVE) {
746 ("Attempt to send command while another command is pending.\n");
751 if (list_empty(&priv->msg_free_list)) {
752 IPW_DEBUG_INFO("no available msg buffers\n");
756 priv->status |= STATUS_CMD_ACTIVE;
757 priv->messages_sent++;
759 element = priv->msg_free_list.next;
761 packet = list_entry(element, struct ipw2100_tx_packet, list);
762 packet->jiffy_start = jiffies;
764 /* initialize the firmware command packet */
765 packet->info.c_struct.cmd->host_command_reg = cmd->host_command;
766 packet->info.c_struct.cmd->host_command_reg1 = cmd->host_command1;
767 packet->info.c_struct.cmd->host_command_len_reg =
768 cmd->host_command_length;
769 packet->info.c_struct.cmd->sequence = cmd->host_command_sequence;
771 memcpy(packet->info.c_struct.cmd->host_command_params_reg,
772 cmd->host_command_parameters,
773 sizeof(packet->info.c_struct.cmd->host_command_params_reg));
776 DEC_STAT(&priv->msg_free_stat);
778 list_add_tail(element, &priv->msg_pend_list);
779 INC_STAT(&priv->msg_pend_stat);
781 ipw2100_tx_send_commands(priv);
782 ipw2100_tx_send_data(priv);
784 spin_unlock_irqrestore(&priv->low_lock, flags);
787 * We must wait for this command to complete before another
788 * command can be sent... but if we wait more than 3 seconds
789 * then there is a problem.
793 wait_event_interruptible_timeout(priv->wait_command_queue,
795 status & STATUS_CMD_ACTIVE),
796 HOST_COMPLETE_TIMEOUT);
799 IPW_DEBUG_INFO("Command completion failed out after %dms.\n",
800 1000 * (HOST_COMPLETE_TIMEOUT / HZ));
801 priv->fatal_error = IPW2100_ERR_MSG_TIMEOUT;
802 priv->status &= ~STATUS_CMD_ACTIVE;
803 schedule_reset(priv);
807 if (priv->fatal_error) {
808 printk(KERN_WARNING DRV_NAME ": %s: firmware fatal error\n",
809 priv->net_dev->name);
813 /* !!!!! HACK TEST !!!!!
814 * When lots of debug trace statements are enabled, the driver
815 * doesn't seem to have as many firmware restart cycles...
817 * As a test, we're sticking in a 1/100s delay here */
818 schedule_timeout_uninterruptible(msecs_to_jiffies(10));
823 spin_unlock_irqrestore(&priv->low_lock, flags);
829 * Verify the values and data access of the hardware
830 * No locks needed or used. No functions called.
832 static int ipw2100_verify(struct ipw2100_priv *priv)
837 u32 val1 = 0x76543210;
838 u32 val2 = 0xFEDCBA98;
840 /* Domain 0 check - all values should be DOA_DEBUG */
841 for (address = IPW_REG_DOA_DEBUG_AREA_START;
842 address < IPW_REG_DOA_DEBUG_AREA_END; address += sizeof(u32)) {
843 read_register(priv->net_dev, address, &data1);
844 if (data1 != IPW_DATA_DOA_DEBUG_VALUE)
848 /* Domain 1 check - use arbitrary read/write compare */
849 for (address = 0; address < 5; address++) {
850 /* The memory area is not used now */
851 write_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x32,
853 write_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x36,
855 read_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x32,
857 read_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x36,
859 if (val1 == data1 && val2 == data2)
868 * Loop until the CARD_DISABLED bit is the same value as the
871 * TODO: See if it would be more efficient to do a wait/wake
872 * cycle and have the completion event trigger the wakeup
875 #define IPW_CARD_DISABLE_COMPLETE_WAIT 100 // 100 milli
876 static int ipw2100_wait_for_card_state(struct ipw2100_priv *priv, int state)
880 u32 len = sizeof(card_state);
883 for (i = 0; i <= IPW_CARD_DISABLE_COMPLETE_WAIT * 1000; i += 50) {
884 err = ipw2100_get_ordinal(priv, IPW_ORD_CARD_DISABLED,
887 IPW_DEBUG_INFO("Query of CARD_DISABLED ordinal "
892 /* We'll break out if either the HW state says it is
893 * in the state we want, or if HOST_COMPLETE command
895 if ((card_state == state) ||
896 ((priv->status & STATUS_ENABLED) ?
897 IPW_HW_STATE_ENABLED : IPW_HW_STATE_DISABLED) == state) {
898 if (state == IPW_HW_STATE_ENABLED)
899 priv->status |= STATUS_ENABLED;
901 priv->status &= ~STATUS_ENABLED;
909 IPW_DEBUG_INFO("ipw2100_wait_for_card_state to %s state timed out\n",
910 state ? "DISABLED" : "ENABLED");
914 /*********************************************************************
915 Procedure : sw_reset_and_clock
916 Purpose : Asserts s/w reset, asserts clock initialization
917 and waits for clock stabilization
918 ********************************************************************/
919 static int sw_reset_and_clock(struct ipw2100_priv *priv)
925 write_register(priv->net_dev, IPW_REG_RESET_REG,
926 IPW_AUX_HOST_RESET_REG_SW_RESET);
928 // wait for clock stabilization
929 for (i = 0; i < 1000; i++) {
930 udelay(IPW_WAIT_RESET_ARC_COMPLETE_DELAY);
932 // check clock ready bit
933 read_register(priv->net_dev, IPW_REG_RESET_REG, &r);
934 if (r & IPW_AUX_HOST_RESET_REG_PRINCETON_RESET)
939 return -EIO; // TODO: better error value
941 /* set "initialization complete" bit to move adapter to
943 write_register(priv->net_dev, IPW_REG_GP_CNTRL,
944 IPW_AUX_HOST_GP_CNTRL_BIT_INIT_DONE);
946 /* wait for clock stabilization */
947 for (i = 0; i < 10000; i++) {
948 udelay(IPW_WAIT_CLOCK_STABILIZATION_DELAY * 4);
950 /* check clock ready bit */
951 read_register(priv->net_dev, IPW_REG_GP_CNTRL, &r);
952 if (r & IPW_AUX_HOST_GP_CNTRL_BIT_CLOCK_READY)
957 return -EIO; /* TODO: better error value */
959 /* set D0 standby bit */
960 read_register(priv->net_dev, IPW_REG_GP_CNTRL, &r);
961 write_register(priv->net_dev, IPW_REG_GP_CNTRL,
962 r | IPW_AUX_HOST_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
967 /*********************************************************************
968 Procedure : ipw2100_download_firmware
969 Purpose : Initiaze adapter after power on.
971 1. assert s/w reset first!
972 2. awake clocks & wait for clock stabilization
973 3. hold ARC (don't ask me why...)
974 4. load Dino ucode and reset/clock init again
975 5. zero-out shared mem
977 *******************************************************************/
978 static int ipw2100_download_firmware(struct ipw2100_priv *priv)
984 /* Fetch the firmware and microcode */
985 struct ipw2100_fw ipw2100_firmware;
988 if (priv->fatal_error) {
989 IPW_DEBUG_ERROR("%s: ipw2100_download_firmware called after "
990 "fatal error %d. Interface must be brought down.\n",
991 priv->net_dev->name, priv->fatal_error);
995 if (!ipw2100_firmware.version) {
996 err = ipw2100_get_firmware(priv, &ipw2100_firmware);
998 IPW_DEBUG_ERROR("%s: ipw2100_get_firmware failed: %d\n",
999 priv->net_dev->name, err);
1000 priv->fatal_error = IPW2100_ERR_FW_LOAD;
1005 err = ipw2100_get_firmware(priv, &ipw2100_firmware);
1007 IPW_DEBUG_ERROR("%s: ipw2100_get_firmware failed: %d\n",
1008 priv->net_dev->name, err);
1009 priv->fatal_error = IPW2100_ERR_FW_LOAD;
1013 priv->firmware_version = ipw2100_firmware.version;
1015 /* s/w reset and clock stabilization */
1016 err = sw_reset_and_clock(priv);
1018 IPW_DEBUG_ERROR("%s: sw_reset_and_clock failed: %d\n",
1019 priv->net_dev->name, err);
1023 err = ipw2100_verify(priv);
1025 IPW_DEBUG_ERROR("%s: ipw2100_verify failed: %d\n",
1026 priv->net_dev->name, err);
1031 write_nic_dword(priv->net_dev,
1032 IPW_INTERNAL_REGISTER_HALT_AND_RESET, 0x80000000);
1034 /* allow ARC to run */
1035 write_register(priv->net_dev, IPW_REG_RESET_REG, 0);
1037 /* load microcode */
1038 err = ipw2100_ucode_download(priv, &ipw2100_firmware);
1040 printk(KERN_ERR DRV_NAME ": %s: Error loading microcode: %d\n",
1041 priv->net_dev->name, err);
1046 write_nic_dword(priv->net_dev,
1047 IPW_INTERNAL_REGISTER_HALT_AND_RESET, 0x00000000);
1049 /* s/w reset and clock stabilization (again!!!) */
1050 err = sw_reset_and_clock(priv);
1052 printk(KERN_ERR DRV_NAME
1053 ": %s: sw_reset_and_clock failed: %d\n",
1054 priv->net_dev->name, err);
1059 err = ipw2100_fw_download(priv, &ipw2100_firmware);
1061 IPW_DEBUG_ERROR("%s: Error loading firmware: %d\n",
1062 priv->net_dev->name, err);
1067 * When the .resume method of the driver is called, the other
1068 * part of the system, i.e. the ide driver could still stay in
1069 * the suspend stage. This prevents us from loading the firmware
1070 * from the disk. --YZ
1073 /* free any storage allocated for firmware image */
1074 ipw2100_release_firmware(priv, &ipw2100_firmware);
1077 /* zero out Domain 1 area indirectly (Si requirement) */
1078 for (address = IPW_HOST_FW_SHARED_AREA0;
1079 address < IPW_HOST_FW_SHARED_AREA0_END; address += 4)
1080 write_nic_dword(priv->net_dev, address, 0);
1081 for (address = IPW_HOST_FW_SHARED_AREA1;
1082 address < IPW_HOST_FW_SHARED_AREA1_END; address += 4)
1083 write_nic_dword(priv->net_dev, address, 0);
1084 for (address = IPW_HOST_FW_SHARED_AREA2;
1085 address < IPW_HOST_FW_SHARED_AREA2_END; address += 4)
1086 write_nic_dword(priv->net_dev, address, 0);
1087 for (address = IPW_HOST_FW_SHARED_AREA3;
1088 address < IPW_HOST_FW_SHARED_AREA3_END; address += 4)
1089 write_nic_dword(priv->net_dev, address, 0);
1090 for (address = IPW_HOST_FW_INTERRUPT_AREA;
1091 address < IPW_HOST_FW_INTERRUPT_AREA_END; address += 4)
1092 write_nic_dword(priv->net_dev, address, 0);
1097 ipw2100_release_firmware(priv, &ipw2100_firmware);
1101 static inline void ipw2100_enable_interrupts(struct ipw2100_priv *priv)
1103 if (priv->status & STATUS_INT_ENABLED)
1105 priv->status |= STATUS_INT_ENABLED;
1106 write_register(priv->net_dev, IPW_REG_INTA_MASK, IPW_INTERRUPT_MASK);
1109 static inline void ipw2100_disable_interrupts(struct ipw2100_priv *priv)
1111 if (!(priv->status & STATUS_INT_ENABLED))
1113 priv->status &= ~STATUS_INT_ENABLED;
1114 write_register(priv->net_dev, IPW_REG_INTA_MASK, 0x0);
1117 static void ipw2100_initialize_ordinals(struct ipw2100_priv *priv)
1119 struct ipw2100_ordinals *ord = &priv->ordinals;
1121 IPW_DEBUG_INFO("enter\n");
1123 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_ORDINALS_TABLE_1,
1126 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_ORDINALS_TABLE_2,
1129 read_nic_dword(priv->net_dev, ord->table1_addr, &ord->table1_size);
1130 read_nic_dword(priv->net_dev, ord->table2_addr, &ord->table2_size);
1132 ord->table2_size &= 0x0000FFFF;
1134 IPW_DEBUG_INFO("table 1 size: %d\n", ord->table1_size);
1135 IPW_DEBUG_INFO("table 2 size: %d\n", ord->table2_size);
1136 IPW_DEBUG_INFO("exit\n");
1139 static inline void ipw2100_hw_set_gpio(struct ipw2100_priv *priv)
1143 * Set GPIO 3 writable by FW; GPIO 1 writable
1144 * by driver and enable clock
1146 reg = (IPW_BIT_GPIO_GPIO3_MASK | IPW_BIT_GPIO_GPIO1_ENABLE |
1147 IPW_BIT_GPIO_LED_OFF);
1148 write_register(priv->net_dev, IPW_REG_GPIO, reg);
1151 static int rf_kill_active(struct ipw2100_priv *priv)
1153 #define MAX_RF_KILL_CHECKS 5
1154 #define RF_KILL_CHECK_DELAY 40
1156 unsigned short value = 0;
1160 if (!(priv->hw_features & HW_FEATURE_RFKILL)) {
1161 wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, false);
1162 priv->status &= ~STATUS_RF_KILL_HW;
1166 for (i = 0; i < MAX_RF_KILL_CHECKS; i++) {
1167 udelay(RF_KILL_CHECK_DELAY);
1168 read_register(priv->net_dev, IPW_REG_GPIO, ®);
1169 value = (value << 1) | ((reg & IPW_BIT_GPIO_RF_KILL) ? 0 : 1);
1173 wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, true);
1174 priv->status |= STATUS_RF_KILL_HW;
1176 wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, false);
1177 priv->status &= ~STATUS_RF_KILL_HW;
1180 return (value == 0);
1183 static int ipw2100_get_hw_features(struct ipw2100_priv *priv)
1189 * EEPROM_SRAM_DB_START_ADDRESS using ordinal in ordinal table 1
1192 if (ipw2100_get_ordinal
1193 (priv, IPW_ORD_EEPROM_SRAM_DB_BLOCK_START_ADDRESS, &addr, &len)) {
1194 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
1199 IPW_DEBUG_INFO("EEPROM address: %08X\n", addr);
1202 * EEPROM version is the byte at offset 0xfd in firmware
1203 * We read 4 bytes, then shift out the byte we actually want */
1204 read_nic_dword(priv->net_dev, addr + 0xFC, &val);
1205 priv->eeprom_version = (val >> 24) & 0xFF;
1206 IPW_DEBUG_INFO("EEPROM version: %d\n", priv->eeprom_version);
1209 * HW RF Kill enable is bit 0 in byte at offset 0x21 in firmware
1211 * notice that the EEPROM bit is reverse polarity, i.e.
1212 * bit = 0 signifies HW RF kill switch is supported
1213 * bit = 1 signifies HW RF kill switch is NOT supported
1215 read_nic_dword(priv->net_dev, addr + 0x20, &val);
1216 if (!((val >> 24) & 0x01))
1217 priv->hw_features |= HW_FEATURE_RFKILL;
1219 IPW_DEBUG_INFO("HW RF Kill: %ssupported.\n",
1220 (priv->hw_features & HW_FEATURE_RFKILL) ? "" : "not ");
1226 * Start firmware execution after power on and initialization
1229 * 2. Wait for f/w initialization completes;
1231 static int ipw2100_start_adapter(struct ipw2100_priv *priv)
1234 u32 inta, inta_mask, gpio;
1236 IPW_DEBUG_INFO("enter\n");
1238 if (priv->status & STATUS_RUNNING)
1242 * Initialize the hw - drive adapter to DO state by setting
1243 * init_done bit. Wait for clk_ready bit and Download
1246 if (ipw2100_download_firmware(priv)) {
1247 printk(KERN_ERR DRV_NAME
1248 ": %s: Failed to power on the adapter.\n",
1249 priv->net_dev->name);
1253 /* Clear the Tx, Rx and Msg queues and the r/w indexes
1254 * in the firmware RBD and TBD ring queue */
1255 ipw2100_queues_initialize(priv);
1257 ipw2100_hw_set_gpio(priv);
1259 /* TODO -- Look at disabling interrupts here to make sure none
1260 * get fired during FW initialization */
1262 /* Release ARC - clear reset bit */
1263 write_register(priv->net_dev, IPW_REG_RESET_REG, 0);
1265 /* wait for f/w initialization complete */
1266 IPW_DEBUG_FW("Waiting for f/w initialization to complete...\n");
1269 schedule_timeout_uninterruptible(msecs_to_jiffies(40));
1270 /* Todo... wait for sync command ... */
1272 read_register(priv->net_dev, IPW_REG_INTA, &inta);
1274 /* check "init done" bit */
1275 if (inta & IPW2100_INTA_FW_INIT_DONE) {
1276 /* reset "init done" bit */
1277 write_register(priv->net_dev, IPW_REG_INTA,
1278 IPW2100_INTA_FW_INIT_DONE);
1282 /* check error conditions : we check these after the firmware
1283 * check so that if there is an error, the interrupt handler
1284 * will see it and the adapter will be reset */
1286 (IPW2100_INTA_FATAL_ERROR | IPW2100_INTA_PARITY_ERROR)) {
1287 /* clear error conditions */
1288 write_register(priv->net_dev, IPW_REG_INTA,
1289 IPW2100_INTA_FATAL_ERROR |
1290 IPW2100_INTA_PARITY_ERROR);
1294 /* Clear out any pending INTAs since we aren't supposed to have
1295 * interrupts enabled at this point... */
1296 read_register(priv->net_dev, IPW_REG_INTA, &inta);
1297 read_register(priv->net_dev, IPW_REG_INTA_MASK, &inta_mask);
1298 inta &= IPW_INTERRUPT_MASK;
1299 /* Clear out any pending interrupts */
1300 if (inta & inta_mask)
1301 write_register(priv->net_dev, IPW_REG_INTA, inta);
1303 IPW_DEBUG_FW("f/w initialization complete: %s\n",
1304 i ? "SUCCESS" : "FAILED");
1307 printk(KERN_WARNING DRV_NAME
1308 ": %s: Firmware did not initialize.\n",
1309 priv->net_dev->name);
1313 /* allow firmware to write to GPIO1 & GPIO3 */
1314 read_register(priv->net_dev, IPW_REG_GPIO, &gpio);
1316 gpio |= (IPW_BIT_GPIO_GPIO1_MASK | IPW_BIT_GPIO_GPIO3_MASK);
1318 write_register(priv->net_dev, IPW_REG_GPIO, gpio);
1320 /* Ready to receive commands */
1321 priv->status |= STATUS_RUNNING;
1323 /* The adapter has been reset; we are not associated */
1324 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
1326 IPW_DEBUG_INFO("exit\n");
1331 static inline void ipw2100_reset_fatalerror(struct ipw2100_priv *priv)
1333 if (!priv->fatal_error)
1336 priv->fatal_errors[priv->fatal_index++] = priv->fatal_error;
1337 priv->fatal_index %= IPW2100_ERROR_QUEUE;
1338 priv->fatal_error = 0;
1341 /* NOTE: Our interrupt is disabled when this method is called */
1342 static int ipw2100_power_cycle_adapter(struct ipw2100_priv *priv)
1347 IPW_DEBUG_INFO("Power cycling the hardware.\n");
1349 ipw2100_hw_set_gpio(priv);
1351 /* Step 1. Stop Master Assert */
1352 write_register(priv->net_dev, IPW_REG_RESET_REG,
1353 IPW_AUX_HOST_RESET_REG_STOP_MASTER);
1355 /* Step 2. Wait for stop Master Assert
1356 * (not more than 50us, otherwise ret error */
1359 udelay(IPW_WAIT_RESET_MASTER_ASSERT_COMPLETE_DELAY);
1360 read_register(priv->net_dev, IPW_REG_RESET_REG, ®);
1362 if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED)
1366 priv->status &= ~STATUS_RESET_PENDING;
1370 ("exit - waited too long for master assert stop\n");
1374 write_register(priv->net_dev, IPW_REG_RESET_REG,
1375 IPW_AUX_HOST_RESET_REG_SW_RESET);
1377 /* Reset any fatal_error conditions */
1378 ipw2100_reset_fatalerror(priv);
1380 /* At this point, the adapter is now stopped and disabled */
1381 priv->status &= ~(STATUS_RUNNING | STATUS_ASSOCIATING |
1382 STATUS_ASSOCIATED | STATUS_ENABLED);
1388 * Send the CARD_DISABLE_PHY_OFF command to the card to disable it
1390 * After disabling, if the card was associated, a STATUS_ASSN_LOST will be sent.
1392 * STATUS_CARD_DISABLE_NOTIFICATION will be sent regardless of
1393 * if STATUS_ASSN_LOST is sent.
1395 static int ipw2100_hw_phy_off(struct ipw2100_priv *priv)
1398 #define HW_PHY_OFF_LOOP_DELAY (msecs_to_jiffies(50))
1400 struct host_command cmd = {
1401 .host_command = CARD_DISABLE_PHY_OFF,
1402 .host_command_sequence = 0,
1403 .host_command_length = 0,
1408 IPW_DEBUG_HC("CARD_DISABLE_PHY_OFF\n");
1410 /* Turn off the radio */
1411 err = ipw2100_hw_send_command(priv, &cmd);
1415 for (i = 0; i < 2500; i++) {
1416 read_nic_dword(priv->net_dev, IPW2100_CONTROL_REG, &val1);
1417 read_nic_dword(priv->net_dev, IPW2100_COMMAND, &val2);
1419 if ((val1 & IPW2100_CONTROL_PHY_OFF) &&
1420 (val2 & IPW2100_COMMAND_PHY_OFF))
1423 schedule_timeout_uninterruptible(HW_PHY_OFF_LOOP_DELAY);
1429 static int ipw2100_enable_adapter(struct ipw2100_priv *priv)
1431 struct host_command cmd = {
1432 .host_command = HOST_COMPLETE,
1433 .host_command_sequence = 0,
1434 .host_command_length = 0
1438 IPW_DEBUG_HC("HOST_COMPLETE\n");
1440 if (priv->status & STATUS_ENABLED)
1443 mutex_lock(&priv->adapter_mutex);
1445 if (rf_kill_active(priv)) {
1446 IPW_DEBUG_HC("Command aborted due to RF kill active.\n");
1450 err = ipw2100_hw_send_command(priv, &cmd);
1452 IPW_DEBUG_INFO("Failed to send HOST_COMPLETE command\n");
1456 err = ipw2100_wait_for_card_state(priv, IPW_HW_STATE_ENABLED);
1458 IPW_DEBUG_INFO("%s: card not responding to init command.\n",
1459 priv->net_dev->name);
1463 if (priv->stop_hang_check) {
1464 priv->stop_hang_check = 0;
1465 schedule_delayed_work(&priv->hang_check, HZ / 2);
1469 mutex_unlock(&priv->adapter_mutex);
1473 static int ipw2100_hw_stop_adapter(struct ipw2100_priv *priv)
1475 #define HW_POWER_DOWN_DELAY (msecs_to_jiffies(100))
1477 struct host_command cmd = {
1478 .host_command = HOST_PRE_POWER_DOWN,
1479 .host_command_sequence = 0,
1480 .host_command_length = 0,
1485 if (!(priv->status & STATUS_RUNNING))
1488 priv->status |= STATUS_STOPPING;
1490 /* We can only shut down the card if the firmware is operational. So,
1491 * if we haven't reset since a fatal_error, then we can not send the
1492 * shutdown commands. */
1493 if (!priv->fatal_error) {
1494 /* First, make sure the adapter is enabled so that the PHY_OFF
1495 * command can shut it down */
1496 ipw2100_enable_adapter(priv);
1498 err = ipw2100_hw_phy_off(priv);
1500 printk(KERN_WARNING DRV_NAME
1501 ": Error disabling radio %d\n", err);
1504 * If in D0-standby mode going directly to D3 may cause a
1505 * PCI bus violation. Therefore we must change out of the D0
1508 * Sending the PREPARE_FOR_POWER_DOWN will restrict the
1509 * hardware from going into standby mode and will transition
1510 * out of D0-standby if it is already in that state.
1512 * STATUS_PREPARE_POWER_DOWN_COMPLETE will be sent by the
1513 * driver upon completion. Once received, the driver can
1514 * proceed to the D3 state.
1516 * Prepare for power down command to fw. This command would
1517 * take HW out of D0-standby and prepare it for D3 state.
1519 * Currently FW does not support event notification for this
1520 * event. Therefore, skip waiting for it. Just wait a fixed
1523 IPW_DEBUG_HC("HOST_PRE_POWER_DOWN\n");
1525 err = ipw2100_hw_send_command(priv, &cmd);
1527 printk(KERN_WARNING DRV_NAME ": "
1528 "%s: Power down command failed: Error %d\n",
1529 priv->net_dev->name, err);
1531 schedule_timeout_uninterruptible(HW_POWER_DOWN_DELAY);
1534 priv->status &= ~STATUS_ENABLED;
1537 * Set GPIO 3 writable by FW; GPIO 1 writable
1538 * by driver and enable clock
1540 ipw2100_hw_set_gpio(priv);
1543 * Power down adapter. Sequence:
1544 * 1. Stop master assert (RESET_REG[9]=1)
1545 * 2. Wait for stop master (RESET_REG[8]==1)
1546 * 3. S/w reset assert (RESET_REG[7] = 1)
1549 /* Stop master assert */
1550 write_register(priv->net_dev, IPW_REG_RESET_REG,
1551 IPW_AUX_HOST_RESET_REG_STOP_MASTER);
1553 /* wait stop master not more than 50 usec.
1554 * Otherwise return error. */
1555 for (i = 5; i > 0; i--) {
1558 /* Check master stop bit */
1559 read_register(priv->net_dev, IPW_REG_RESET_REG, ®);
1561 if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED)
1566 printk(KERN_WARNING DRV_NAME
1567 ": %s: Could now power down adapter.\n",
1568 priv->net_dev->name);
1570 /* assert s/w reset */
1571 write_register(priv->net_dev, IPW_REG_RESET_REG,
1572 IPW_AUX_HOST_RESET_REG_SW_RESET);
1574 priv->status &= ~(STATUS_RUNNING | STATUS_STOPPING);
1579 static int ipw2100_disable_adapter(struct ipw2100_priv *priv)
1581 struct host_command cmd = {
1582 .host_command = CARD_DISABLE,
1583 .host_command_sequence = 0,
1584 .host_command_length = 0
1588 IPW_DEBUG_HC("CARD_DISABLE\n");
1590 if (!(priv->status & STATUS_ENABLED))
1593 /* Make sure we clear the associated state */
1594 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1596 if (!priv->stop_hang_check) {
1597 priv->stop_hang_check = 1;
1598 cancel_delayed_work(&priv->hang_check);
1601 mutex_lock(&priv->adapter_mutex);
1603 err = ipw2100_hw_send_command(priv, &cmd);
1605 printk(KERN_WARNING DRV_NAME
1606 ": exit - failed to send CARD_DISABLE command\n");
1610 err = ipw2100_wait_for_card_state(priv, IPW_HW_STATE_DISABLED);
1612 printk(KERN_WARNING DRV_NAME
1613 ": exit - card failed to change to DISABLED\n");
1617 IPW_DEBUG_INFO("TODO: implement scan state machine\n");
1620 mutex_unlock(&priv->adapter_mutex);
1624 static int ipw2100_set_scan_options(struct ipw2100_priv *priv)
1626 struct host_command cmd = {
1627 .host_command = SET_SCAN_OPTIONS,
1628 .host_command_sequence = 0,
1629 .host_command_length = 8
1633 IPW_DEBUG_INFO("enter\n");
1635 IPW_DEBUG_SCAN("setting scan options\n");
1637 cmd.host_command_parameters[0] = 0;
1639 if (!(priv->config & CFG_ASSOCIATE))
1640 cmd.host_command_parameters[0] |= IPW_SCAN_NOASSOCIATE;
1641 if ((priv->ieee->sec.flags & SEC_ENABLED) && priv->ieee->sec.enabled)
1642 cmd.host_command_parameters[0] |= IPW_SCAN_MIXED_CELL;
1643 if (priv->config & CFG_PASSIVE_SCAN)
1644 cmd.host_command_parameters[0] |= IPW_SCAN_PASSIVE;
1646 cmd.host_command_parameters[1] = priv->channel_mask;
1648 err = ipw2100_hw_send_command(priv, &cmd);
1650 IPW_DEBUG_HC("SET_SCAN_OPTIONS 0x%04X\n",
1651 cmd.host_command_parameters[0]);
1656 static int ipw2100_start_scan(struct ipw2100_priv *priv)
1658 struct host_command cmd = {
1659 .host_command = BROADCAST_SCAN,
1660 .host_command_sequence = 0,
1661 .host_command_length = 4
1665 IPW_DEBUG_HC("START_SCAN\n");
1667 cmd.host_command_parameters[0] = 0;
1669 /* No scanning if in monitor mode */
1670 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
1673 if (priv->status & STATUS_SCANNING) {
1674 IPW_DEBUG_SCAN("Scan requested while already in scan...\n");
1678 IPW_DEBUG_INFO("enter\n");
1680 /* Not clearing here; doing so makes iwlist always return nothing...
1682 * We should modify the table logic to use aging tables vs. clearing
1683 * the table on each scan start.
1685 IPW_DEBUG_SCAN("starting scan\n");
1687 priv->status |= STATUS_SCANNING;
1688 err = ipw2100_hw_send_command(priv, &cmd);
1690 priv->status &= ~STATUS_SCANNING;
1692 IPW_DEBUG_INFO("exit\n");
1697 static const struct libipw_geo ipw_geos[] = {
1701 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
1702 {2427, 4}, {2432, 5}, {2437, 6},
1703 {2442, 7}, {2447, 8}, {2452, 9},
1704 {2457, 10}, {2462, 11}, {2467, 12},
1705 {2472, 13}, {2484, 14}},
1709 static int ipw2100_up(struct ipw2100_priv *priv, int deferred)
1711 unsigned long flags;
1714 u32 ord_len = sizeof(lock);
1716 /* Age scan list entries found before suspend */
1717 if (priv->suspend_time) {
1718 libipw_networks_age(priv->ieee, priv->suspend_time);
1719 priv->suspend_time = 0;
1722 /* Quiet if manually disabled. */
1723 if (priv->status & STATUS_RF_KILL_SW) {
1724 IPW_DEBUG_INFO("%s: Radio is disabled by Manual Disable "
1725 "switch\n", priv->net_dev->name);
1729 /* the ipw2100 hardware really doesn't want power management delays
1730 * longer than 175usec
1732 cpu_latency_qos_update_request(&ipw2100_pm_qos_req, 175);
1734 /* If the interrupt is enabled, turn it off... */
1735 spin_lock_irqsave(&priv->low_lock, flags);
1736 ipw2100_disable_interrupts(priv);
1738 /* Reset any fatal_error conditions */
1739 ipw2100_reset_fatalerror(priv);
1740 spin_unlock_irqrestore(&priv->low_lock, flags);
1742 if (priv->status & STATUS_POWERED ||
1743 (priv->status & STATUS_RESET_PENDING)) {
1744 /* Power cycle the card ... */
1745 err = ipw2100_power_cycle_adapter(priv);
1747 printk(KERN_WARNING DRV_NAME
1748 ": %s: Could not cycle adapter.\n",
1749 priv->net_dev->name);
1753 priv->status |= STATUS_POWERED;
1755 /* Load the firmware, start the clocks, etc. */
1756 err = ipw2100_start_adapter(priv);
1758 printk(KERN_ERR DRV_NAME
1759 ": %s: Failed to start the firmware.\n",
1760 priv->net_dev->name);
1764 ipw2100_initialize_ordinals(priv);
1766 /* Determine capabilities of this particular HW configuration */
1767 err = ipw2100_get_hw_features(priv);
1769 printk(KERN_ERR DRV_NAME
1770 ": %s: Failed to determine HW features.\n",
1771 priv->net_dev->name);
1775 /* Initialize the geo */
1776 libipw_set_geo(priv->ieee, &ipw_geos[0]);
1777 priv->ieee->freq_band = LIBIPW_24GHZ_BAND;
1780 err = ipw2100_set_ordinal(priv, IPW_ORD_PERS_DB_LOCK, &lock, &ord_len);
1782 printk(KERN_ERR DRV_NAME
1783 ": %s: Failed to clear ordinal lock.\n",
1784 priv->net_dev->name);
1788 priv->status &= ~STATUS_SCANNING;
1790 if (rf_kill_active(priv)) {
1791 printk(KERN_INFO "%s: Radio is disabled by RF switch.\n",
1792 priv->net_dev->name);
1794 if (priv->stop_rf_kill) {
1795 priv->stop_rf_kill = 0;
1796 schedule_delayed_work(&priv->rf_kill,
1797 round_jiffies_relative(HZ));
1803 /* Turn on the interrupt so that commands can be processed */
1804 ipw2100_enable_interrupts(priv);
1806 /* Send all of the commands that must be sent prior to
1808 err = ipw2100_adapter_setup(priv);
1810 printk(KERN_ERR DRV_NAME ": %s: Failed to start the card.\n",
1811 priv->net_dev->name);
1816 /* Enable the adapter - sends HOST_COMPLETE */
1817 err = ipw2100_enable_adapter(priv);
1819 printk(KERN_ERR DRV_NAME ": "
1820 "%s: failed in call to enable adapter.\n",
1821 priv->net_dev->name);
1822 ipw2100_hw_stop_adapter(priv);
1826 /* Start a scan . . . */
1827 ipw2100_set_scan_options(priv);
1828 ipw2100_start_scan(priv);
1835 static void ipw2100_down(struct ipw2100_priv *priv)
1837 unsigned long flags;
1838 union iwreq_data wrqu = {
1840 .sa_family = ARPHRD_ETHER}
1842 int associated = priv->status & STATUS_ASSOCIATED;
1844 /* Kill the RF switch timer */
1845 if (!priv->stop_rf_kill) {
1846 priv->stop_rf_kill = 1;
1847 cancel_delayed_work(&priv->rf_kill);
1850 /* Kill the firmware hang check timer */
1851 if (!priv->stop_hang_check) {
1852 priv->stop_hang_check = 1;
1853 cancel_delayed_work(&priv->hang_check);
1856 /* Kill any pending resets */
1857 if (priv->status & STATUS_RESET_PENDING)
1858 cancel_delayed_work(&priv->reset_work);
1860 /* Make sure the interrupt is on so that FW commands will be
1861 * processed correctly */
1862 spin_lock_irqsave(&priv->low_lock, flags);
1863 ipw2100_enable_interrupts(priv);
1864 spin_unlock_irqrestore(&priv->low_lock, flags);
1866 if (ipw2100_hw_stop_adapter(priv))
1867 printk(KERN_ERR DRV_NAME ": %s: Error stopping adapter.\n",
1868 priv->net_dev->name);
1870 /* Do not disable the interrupt until _after_ we disable
1871 * the adaptor. Otherwise the CARD_DISABLE command will never
1872 * be ack'd by the firmware */
1873 spin_lock_irqsave(&priv->low_lock, flags);
1874 ipw2100_disable_interrupts(priv);
1875 spin_unlock_irqrestore(&priv->low_lock, flags);
1877 cpu_latency_qos_update_request(&ipw2100_pm_qos_req,
1878 PM_QOS_DEFAULT_VALUE);
1880 /* We have to signal any supplicant if we are disassociating */
1882 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1884 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1885 netif_carrier_off(priv->net_dev);
1886 netif_stop_queue(priv->net_dev);
1889 static int ipw2100_wdev_init(struct net_device *dev)
1891 struct ipw2100_priv *priv = libipw_priv(dev);
1892 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
1893 struct wireless_dev *wdev = &priv->ieee->wdev;
1896 memcpy(wdev->wiphy->perm_addr, priv->mac_addr, ETH_ALEN);
1898 /* fill-out priv->ieee->bg_band */
1899 if (geo->bg_channels) {
1900 struct ieee80211_supported_band *bg_band = &priv->ieee->bg_band;
1902 bg_band->band = NL80211_BAND_2GHZ;
1903 bg_band->n_channels = geo->bg_channels;
1904 bg_band->channels = kcalloc(geo->bg_channels,
1905 sizeof(struct ieee80211_channel),
1907 if (!bg_band->channels) {
1911 /* translate geo->bg to bg_band.channels */
1912 for (i = 0; i < geo->bg_channels; i++) {
1913 bg_band->channels[i].band = NL80211_BAND_2GHZ;
1914 bg_band->channels[i].center_freq = geo->bg[i].freq;
1915 bg_band->channels[i].hw_value = geo->bg[i].channel;
1916 bg_band->channels[i].max_power = geo->bg[i].max_power;
1917 if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY)
1918 bg_band->channels[i].flags |=
1919 IEEE80211_CHAN_NO_IR;
1920 if (geo->bg[i].flags & LIBIPW_CH_NO_IBSS)
1921 bg_band->channels[i].flags |=
1922 IEEE80211_CHAN_NO_IR;
1923 if (geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT)
1924 bg_band->channels[i].flags |=
1925 IEEE80211_CHAN_RADAR;
1926 /* No equivalent for LIBIPW_CH_80211H_RULES,
1927 LIBIPW_CH_UNIFORM_SPREADING, or
1928 LIBIPW_CH_B_ONLY... */
1930 /* point at bitrate info */
1931 bg_band->bitrates = ipw2100_bg_rates;
1932 bg_band->n_bitrates = RATE_COUNT;
1934 wdev->wiphy->bands[NL80211_BAND_2GHZ] = bg_band;
1937 wdev->wiphy->cipher_suites = ipw_cipher_suites;
1938 wdev->wiphy->n_cipher_suites = ARRAY_SIZE(ipw_cipher_suites);
1940 set_wiphy_dev(wdev->wiphy, &priv->pci_dev->dev);
1941 if (wiphy_register(wdev->wiphy))
1946 static void ipw2100_reset_adapter(struct work_struct *work)
1948 struct ipw2100_priv *priv =
1949 container_of(work, struct ipw2100_priv, reset_work.work);
1950 unsigned long flags;
1951 union iwreq_data wrqu = {
1953 .sa_family = ARPHRD_ETHER}
1955 int associated = priv->status & STATUS_ASSOCIATED;
1957 spin_lock_irqsave(&priv->low_lock, flags);
1958 IPW_DEBUG_INFO(": %s: Restarting adapter.\n", priv->net_dev->name);
1960 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1961 priv->status |= STATUS_SECURITY_UPDATED;
1963 /* Force a power cycle even if interface hasn't been opened
1965 cancel_delayed_work(&priv->reset_work);
1966 priv->status |= STATUS_RESET_PENDING;
1967 spin_unlock_irqrestore(&priv->low_lock, flags);
1969 mutex_lock(&priv->action_mutex);
1970 /* stop timed checks so that they don't interfere with reset */
1971 priv->stop_hang_check = 1;
1972 cancel_delayed_work(&priv->hang_check);
1974 /* We have to signal any supplicant if we are disassociating */
1976 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1978 ipw2100_up(priv, 0);
1979 mutex_unlock(&priv->action_mutex);
1983 static void isr_indicate_associated(struct ipw2100_priv *priv, u32 status)
1986 #define MAC_ASSOCIATION_READ_DELAY (HZ)
1988 unsigned int len, essid_len;
1989 char essid[IW_ESSID_MAX_SIZE];
1996 * TBD: BSSID is usually 00:00:00:00:00:00 here and not
1997 * an actual MAC of the AP. Seems like FW sets this
1998 * address too late. Read it later and expose through
1999 * /proc or schedule a later task to query and update
2002 essid_len = IW_ESSID_MAX_SIZE;
2003 ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_SSID,
2006 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
2012 ret = ipw2100_get_ordinal(priv, IPW_ORD_CURRENT_TX_RATE, &txrate, &len);
2014 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
2020 ret = ipw2100_get_ordinal(priv, IPW_ORD_OUR_FREQ, &chan, &len);
2022 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
2027 ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID, bssid,
2030 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
2034 memcpy(priv->ieee->bssid, bssid, ETH_ALEN);
2037 case TX_RATE_1_MBIT:
2038 txratename = "1Mbps";
2040 case TX_RATE_2_MBIT:
2041 txratename = "2Mbsp";
2043 case TX_RATE_5_5_MBIT:
2044 txratename = "5.5Mbps";
2046 case TX_RATE_11_MBIT:
2047 txratename = "11Mbps";
2050 IPW_DEBUG_INFO("Unknown rate: %d\n", txrate);
2051 txratename = "unknown rate";
2055 IPW_DEBUG_INFO("%s: Associated with '%*pE' at %s, channel %d (BSSID=%pM)\n",
2056 priv->net_dev->name, essid_len, essid,
2057 txratename, chan, bssid);
2059 /* now we copy read ssid into dev */
2060 if (!(priv->config & CFG_STATIC_ESSID)) {
2061 priv->essid_len = min((u8) essid_len, (u8) IW_ESSID_MAX_SIZE);
2062 memcpy(priv->essid, essid, priv->essid_len);
2064 priv->channel = chan;
2065 memcpy(priv->bssid, bssid, ETH_ALEN);
2067 priv->status |= STATUS_ASSOCIATING;
2068 priv->connect_start = ktime_get_boottime_seconds();
2070 schedule_delayed_work(&priv->wx_event_work, HZ / 10);
2073 static int ipw2100_set_essid(struct ipw2100_priv *priv, char *essid,
2074 int length, int batch_mode)
2076 int ssid_len = min(length, IW_ESSID_MAX_SIZE);
2077 struct host_command cmd = {
2078 .host_command = SSID,
2079 .host_command_sequence = 0,
2080 .host_command_length = ssid_len
2084 IPW_DEBUG_HC("SSID: '%*pE'\n", ssid_len, essid);
2087 memcpy(cmd.host_command_parameters, essid, ssid_len);
2090 err = ipw2100_disable_adapter(priv);
2095 /* Bug in FW currently doesn't honor bit 0 in SET_SCAN_OPTIONS to
2096 * disable auto association -- so we cheat by setting a bogus SSID */
2097 if (!ssid_len && !(priv->config & CFG_ASSOCIATE)) {
2099 u8 *bogus = (u8 *) cmd.host_command_parameters;
2100 for (i = 0; i < IW_ESSID_MAX_SIZE; i++)
2101 bogus[i] = 0x18 + i;
2102 cmd.host_command_length = IW_ESSID_MAX_SIZE;
2105 /* NOTE: We always send the SSID command even if the provided ESSID is
2106 * the same as what we currently think is set. */
2108 err = ipw2100_hw_send_command(priv, &cmd);
2110 memset(priv->essid + ssid_len, 0, IW_ESSID_MAX_SIZE - ssid_len);
2111 memcpy(priv->essid, essid, ssid_len);
2112 priv->essid_len = ssid_len;
2116 if (ipw2100_enable_adapter(priv))
2123 static void isr_indicate_association_lost(struct ipw2100_priv *priv, u32 status)
2125 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | IPW_DL_ASSOC,
2126 "disassociated: '%*pE' %pM\n", priv->essid_len, priv->essid,
2129 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
2131 if (priv->status & STATUS_STOPPING) {
2132 IPW_DEBUG_INFO("Card is stopping itself, discard ASSN_LOST.\n");
2136 eth_zero_addr(priv->bssid);
2137 eth_zero_addr(priv->ieee->bssid);
2139 netif_carrier_off(priv->net_dev);
2140 netif_stop_queue(priv->net_dev);
2142 if (!(priv->status & STATUS_RUNNING))
2145 if (priv->status & STATUS_SECURITY_UPDATED)
2146 schedule_delayed_work(&priv->security_work, 0);
2148 schedule_delayed_work(&priv->wx_event_work, 0);
2151 static void isr_indicate_rf_kill(struct ipw2100_priv *priv, u32 status)
2153 IPW_DEBUG_INFO("%s: RF Kill state changed to radio OFF.\n",
2154 priv->net_dev->name);
2156 /* RF_KILL is now enabled (else we wouldn't be here) */
2157 wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, true);
2158 priv->status |= STATUS_RF_KILL_HW;
2160 /* Make sure the RF Kill check timer is running */
2161 priv->stop_rf_kill = 0;
2162 mod_delayed_work(system_wq, &priv->rf_kill, round_jiffies_relative(HZ));
2165 static void ipw2100_scan_event(struct work_struct *work)
2167 struct ipw2100_priv *priv = container_of(work, struct ipw2100_priv,
2169 union iwreq_data wrqu;
2171 wrqu.data.length = 0;
2172 wrqu.data.flags = 0;
2173 wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL);
2176 static void isr_scan_complete(struct ipw2100_priv *priv, u32 status)
2178 IPW_DEBUG_SCAN("scan complete\n");
2179 /* Age the scan results... */
2180 priv->ieee->scans++;
2181 priv->status &= ~STATUS_SCANNING;
2183 /* Only userspace-requested scan completion events go out immediately */
2184 if (!priv->user_requested_scan) {
2185 schedule_delayed_work(&priv->scan_event,
2186 round_jiffies_relative(msecs_to_jiffies(4000)));
2188 priv->user_requested_scan = 0;
2189 mod_delayed_work(system_wq, &priv->scan_event, 0);
2193 #ifdef CONFIG_IPW2100_DEBUG
2194 #define IPW2100_HANDLER(v, f) { v, f, # v }
2195 struct ipw2100_status_indicator {
2197 void (*cb) (struct ipw2100_priv * priv, u32 status);
2201 #define IPW2100_HANDLER(v, f) { v, f }
2202 struct ipw2100_status_indicator {
2204 void (*cb) (struct ipw2100_priv * priv, u32 status);
2206 #endif /* CONFIG_IPW2100_DEBUG */
2208 static void isr_indicate_scanning(struct ipw2100_priv *priv, u32 status)
2210 IPW_DEBUG_SCAN("Scanning...\n");
2211 priv->status |= STATUS_SCANNING;
2214 static const struct ipw2100_status_indicator status_handlers[] = {
2215 IPW2100_HANDLER(IPW_STATE_INITIALIZED, NULL),
2216 IPW2100_HANDLER(IPW_STATE_COUNTRY_FOUND, NULL),
2217 IPW2100_HANDLER(IPW_STATE_ASSOCIATED, isr_indicate_associated),
2218 IPW2100_HANDLER(IPW_STATE_ASSN_LOST, isr_indicate_association_lost),
2219 IPW2100_HANDLER(IPW_STATE_ASSN_CHANGED, NULL),
2220 IPW2100_HANDLER(IPW_STATE_SCAN_COMPLETE, isr_scan_complete),
2221 IPW2100_HANDLER(IPW_STATE_ENTERED_PSP, NULL),
2222 IPW2100_HANDLER(IPW_STATE_LEFT_PSP, NULL),
2223 IPW2100_HANDLER(IPW_STATE_RF_KILL, isr_indicate_rf_kill),
2224 IPW2100_HANDLER(IPW_STATE_DISABLED, NULL),
2225 IPW2100_HANDLER(IPW_STATE_POWER_DOWN, NULL),
2226 IPW2100_HANDLER(IPW_STATE_SCANNING, isr_indicate_scanning),
2227 IPW2100_HANDLER(-1, NULL)
2230 static void isr_status_change(struct ipw2100_priv *priv, int status)
2234 if (status == IPW_STATE_SCANNING &&
2235 priv->status & STATUS_ASSOCIATED &&
2236 !(priv->status & STATUS_SCANNING)) {
2237 IPW_DEBUG_INFO("Scan detected while associated, with "
2238 "no scan request. Restarting firmware.\n");
2240 /* Wake up any sleeping jobs */
2241 schedule_reset(priv);
2244 for (i = 0; status_handlers[i].status != -1; i++) {
2245 if (status == status_handlers[i].status) {
2246 IPW_DEBUG_NOTIF("Status change: %s\n",
2247 status_handlers[i].name);
2248 if (status_handlers[i].cb)
2249 status_handlers[i].cb(priv, status);
2250 priv->wstats.status = status;
2255 IPW_DEBUG_NOTIF("unknown status received: %04x\n", status);
2258 static void isr_rx_complete_command(struct ipw2100_priv *priv,
2259 struct ipw2100_cmd_header *cmd)
2261 #ifdef CONFIG_IPW2100_DEBUG
2262 if (cmd->host_command_reg < ARRAY_SIZE(command_types)) {
2263 IPW_DEBUG_HC("Command completed '%s (%d)'\n",
2264 command_types[cmd->host_command_reg],
2265 cmd->host_command_reg);
2268 if (cmd->host_command_reg == HOST_COMPLETE)
2269 priv->status |= STATUS_ENABLED;
2271 if (cmd->host_command_reg == CARD_DISABLE)
2272 priv->status &= ~STATUS_ENABLED;
2274 priv->status &= ~STATUS_CMD_ACTIVE;
2276 wake_up_interruptible(&priv->wait_command_queue);
2279 #ifdef CONFIG_IPW2100_DEBUG
2280 static const char *frame_types[] = {
2281 "COMMAND_STATUS_VAL",
2282 "STATUS_CHANGE_VAL",
2285 "HOST_NOTIFICATION_VAL"
2289 static int ipw2100_alloc_skb(struct ipw2100_priv *priv,
2290 struct ipw2100_rx_packet *packet)
2292 packet->skb = dev_alloc_skb(sizeof(struct ipw2100_rx));
2296 packet->rxp = (struct ipw2100_rx *)packet->skb->data;
2297 packet->dma_addr = dma_map_single(&priv->pci_dev->dev,
2299 sizeof(struct ipw2100_rx),
2301 if (dma_mapping_error(&priv->pci_dev->dev, packet->dma_addr)) {
2302 dev_kfree_skb(packet->skb);
2309 #define SEARCH_ERROR 0xffffffff
2310 #define SEARCH_FAIL 0xfffffffe
2311 #define SEARCH_SUCCESS 0xfffffff0
2312 #define SEARCH_DISCARD 0
2313 #define SEARCH_SNAPSHOT 1
2315 #define SNAPSHOT_ADDR(ofs) (priv->snapshot[((ofs) >> 12) & 0xff] + ((ofs) & 0xfff))
2316 static void ipw2100_snapshot_free(struct ipw2100_priv *priv)
2319 if (!priv->snapshot[0])
2321 for (i = 0; i < 0x30; i++)
2322 kfree(priv->snapshot[i]);
2323 priv->snapshot[0] = NULL;
2326 #ifdef IPW2100_DEBUG_C3
2327 static int ipw2100_snapshot_alloc(struct ipw2100_priv *priv)
2330 if (priv->snapshot[0])
2332 for (i = 0; i < 0x30; i++) {
2333 priv->snapshot[i] = kmalloc(0x1000, GFP_ATOMIC);
2334 if (!priv->snapshot[i]) {
2335 IPW_DEBUG_INFO("%s: Error allocating snapshot "
2336 "buffer %d\n", priv->net_dev->name, i);
2338 kfree(priv->snapshot[--i]);
2339 priv->snapshot[0] = NULL;
2347 static u32 ipw2100_match_buf(struct ipw2100_priv *priv, u8 * in_buf,
2348 size_t len, int mode)
2356 if (mode == SEARCH_SNAPSHOT) {
2357 if (!ipw2100_snapshot_alloc(priv))
2358 mode = SEARCH_DISCARD;
2361 for (ret = SEARCH_FAIL, i = 0; i < 0x30000; i += 4) {
2362 read_nic_dword(priv->net_dev, i, &tmp);
2363 if (mode == SEARCH_SNAPSHOT)
2364 *(u32 *) SNAPSHOT_ADDR(i) = tmp;
2365 if (ret == SEARCH_FAIL) {
2367 for (j = 0; j < 4; j++) {
2376 if ((s - in_buf) == len)
2377 ret = (i + j) - len + 1;
2379 } else if (mode == SEARCH_DISCARD)
2389 * 0) Disconnect the SKB from the firmware (just unmap)
2390 * 1) Pack the ETH header into the SKB
2391 * 2) Pass the SKB to the network stack
2393 * When packet is provided by the firmware, it contains the following:
2398 * The size of the constructed ethernet
2401 #ifdef IPW2100_RX_DEBUG
2402 static u8 packet_data[IPW_RX_NIC_BUFFER_LENGTH];
2405 static void ipw2100_corruption_detected(struct ipw2100_priv *priv, int i)
2407 #ifdef IPW2100_DEBUG_C3
2408 struct ipw2100_status *status = &priv->status_queue.drv[i];
2413 IPW_DEBUG_INFO(": PCI latency error detected at 0x%04zX.\n",
2414 i * sizeof(struct ipw2100_status));
2416 #ifdef IPW2100_DEBUG_C3
2417 /* Halt the firmware so we can get a good image */
2418 write_register(priv->net_dev, IPW_REG_RESET_REG,
2419 IPW_AUX_HOST_RESET_REG_STOP_MASTER);
2422 udelay(IPW_WAIT_RESET_MASTER_ASSERT_COMPLETE_DELAY);
2423 read_register(priv->net_dev, IPW_REG_RESET_REG, ®);
2425 if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED)
2429 match = ipw2100_match_buf(priv, (u8 *) status,
2430 sizeof(struct ipw2100_status),
2432 if (match < SEARCH_SUCCESS)
2433 IPW_DEBUG_INFO("%s: DMA status match in Firmware at "
2434 "offset 0x%06X, length %d:\n",
2435 priv->net_dev->name, match,
2436 sizeof(struct ipw2100_status));
2438 IPW_DEBUG_INFO("%s: No DMA status match in "
2439 "Firmware.\n", priv->net_dev->name);
2441 printk_buf((u8 *) priv->status_queue.drv,
2442 sizeof(struct ipw2100_status) * RX_QUEUE_LENGTH);
2445 priv->fatal_error = IPW2100_ERR_C3_CORRUPTION;
2446 priv->net_dev->stats.rx_errors++;
2447 schedule_reset(priv);
2450 static void isr_rx(struct ipw2100_priv *priv, int i,
2451 struct libipw_rx_stats *stats)
2453 struct net_device *dev = priv->net_dev;
2454 struct ipw2100_status *status = &priv->status_queue.drv[i];
2455 struct ipw2100_rx_packet *packet = &priv->rx_buffers[i];
2457 IPW_DEBUG_RX("Handler...\n");
2459 if (unlikely(status->frame_size > skb_tailroom(packet->skb))) {
2460 IPW_DEBUG_INFO("%s: frame_size (%u) > skb_tailroom (%u)!"
2463 status->frame_size, skb_tailroom(packet->skb));
2464 dev->stats.rx_errors++;
2468 if (unlikely(!netif_running(dev))) {
2469 dev->stats.rx_errors++;
2470 priv->wstats.discard.misc++;
2471 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
2475 if (unlikely(priv->ieee->iw_mode != IW_MODE_MONITOR &&
2476 !(priv->status & STATUS_ASSOCIATED))) {
2477 IPW_DEBUG_DROP("Dropping packet while not associated.\n");
2478 priv->wstats.discard.misc++;
2482 dma_unmap_single(&priv->pci_dev->dev, packet->dma_addr,
2483 sizeof(struct ipw2100_rx), DMA_FROM_DEVICE);
2485 skb_put(packet->skb, status->frame_size);
2487 #ifdef IPW2100_RX_DEBUG
2488 /* Make a copy of the frame so we can dump it to the logs if
2489 * libipw_rx fails */
2490 skb_copy_from_linear_data(packet->skb, packet_data,
2491 min_t(u32, status->frame_size,
2492 IPW_RX_NIC_BUFFER_LENGTH));
2495 if (!libipw_rx(priv->ieee, packet->skb, stats)) {
2496 #ifdef IPW2100_RX_DEBUG
2497 IPW_DEBUG_DROP("%s: Non consumed packet:\n",
2499 printk_buf(IPW_DL_DROP, packet_data, status->frame_size);
2501 dev->stats.rx_errors++;
2503 /* libipw_rx failed, so it didn't free the SKB */
2504 dev_kfree_skb_any(packet->skb);
2508 /* We need to allocate a new SKB and attach it to the RDB. */
2509 if (unlikely(ipw2100_alloc_skb(priv, packet))) {
2510 printk(KERN_WARNING DRV_NAME ": "
2511 "%s: Unable to allocate SKB onto RBD ring - disabling "
2512 "adapter.\n", dev->name);
2513 /* TODO: schedule adapter shutdown */
2514 IPW_DEBUG_INFO("TODO: Shutdown adapter...\n");
2517 /* Update the RDB entry */
2518 priv->rx_queue.drv[i].host_addr = packet->dma_addr;
2521 #ifdef CONFIG_IPW2100_MONITOR
2523 static void isr_rx_monitor(struct ipw2100_priv *priv, int i,
2524 struct libipw_rx_stats *stats)
2526 struct net_device *dev = priv->net_dev;
2527 struct ipw2100_status *status = &priv->status_queue.drv[i];
2528 struct ipw2100_rx_packet *packet = &priv->rx_buffers[i];
2530 /* Magic struct that slots into the radiotap header -- no reason
2531 * to build this manually element by element, we can write it much
2532 * more efficiently than we can parse it. ORDER MATTERS HERE */
2534 struct ieee80211_radiotap_header rt_hdr;
2535 s8 rt_dbmsignal; /* signal in dbM, kluged to signed */
2538 IPW_DEBUG_RX("Handler...\n");
2540 if (unlikely(status->frame_size > skb_tailroom(packet->skb) -
2541 sizeof(struct ipw_rt_hdr))) {
2542 IPW_DEBUG_INFO("%s: frame_size (%u) > skb_tailroom (%u)!"
2546 skb_tailroom(packet->skb));
2547 dev->stats.rx_errors++;
2551 if (unlikely(!netif_running(dev))) {
2552 dev->stats.rx_errors++;
2553 priv->wstats.discard.misc++;
2554 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
2558 if (unlikely(priv->config & CFG_CRC_CHECK &&
2559 status->flags & IPW_STATUS_FLAG_CRC_ERROR)) {
2560 IPW_DEBUG_RX("CRC error in packet. Dropping.\n");
2561 dev->stats.rx_errors++;
2565 dma_unmap_single(&priv->pci_dev->dev, packet->dma_addr,
2566 sizeof(struct ipw2100_rx), DMA_FROM_DEVICE);
2567 memmove(packet->skb->data + sizeof(struct ipw_rt_hdr),
2568 packet->skb->data, status->frame_size);
2570 ipw_rt = (struct ipw_rt_hdr *) packet->skb->data;
2572 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
2573 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
2574 ipw_rt->rt_hdr.it_len = cpu_to_le16(sizeof(struct ipw_rt_hdr)); /* total hdr+data */
2576 ipw_rt->rt_hdr.it_present = cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
2578 ipw_rt->rt_dbmsignal = status->rssi + IPW2100_RSSI_TO_DBM;
2580 skb_put(packet->skb, status->frame_size + sizeof(struct ipw_rt_hdr));
2582 if (!libipw_rx(priv->ieee, packet->skb, stats)) {
2583 dev->stats.rx_errors++;
2585 /* libipw_rx failed, so it didn't free the SKB */
2586 dev_kfree_skb_any(packet->skb);
2590 /* We need to allocate a new SKB and attach it to the RDB. */
2591 if (unlikely(ipw2100_alloc_skb(priv, packet))) {
2593 "%s: Unable to allocate SKB onto RBD ring - disabling "
2594 "adapter.\n", dev->name);
2595 /* TODO: schedule adapter shutdown */
2596 IPW_DEBUG_INFO("TODO: Shutdown adapter...\n");
2599 /* Update the RDB entry */
2600 priv->rx_queue.drv[i].host_addr = packet->dma_addr;
2605 static int ipw2100_corruption_check(struct ipw2100_priv *priv, int i)
2607 struct ipw2100_status *status = &priv->status_queue.drv[i];
2608 struct ipw2100_rx *u = priv->rx_buffers[i].rxp;
2609 u16 frame_type = status->status_fields & STATUS_TYPE_MASK;
2611 switch (frame_type) {
2612 case COMMAND_STATUS_VAL:
2613 return (status->frame_size != sizeof(u->rx_data.command));
2614 case STATUS_CHANGE_VAL:
2615 return (status->frame_size != sizeof(u->rx_data.status));
2616 case HOST_NOTIFICATION_VAL:
2617 return (status->frame_size < sizeof(u->rx_data.notification));
2618 case P80211_DATA_VAL:
2619 case P8023_DATA_VAL:
2620 #ifdef CONFIG_IPW2100_MONITOR
2623 switch (WLAN_FC_GET_TYPE(le16_to_cpu(u->rx_data.header.frame_ctl))) {
2624 case IEEE80211_FTYPE_MGMT:
2625 case IEEE80211_FTYPE_CTL:
2627 case IEEE80211_FTYPE_DATA:
2628 return (status->frame_size >
2629 IPW_MAX_802_11_PAYLOAD_LENGTH);
2638 * ipw2100 interrupts are disabled at this point, and the ISR
2639 * is the only code that calls this method. So, we do not need
2640 * to play with any locks.
2642 * RX Queue works as follows:
2644 * Read index - firmware places packet in entry identified by the
2645 * Read index and advances Read index. In this manner,
2646 * Read index will always point to the next packet to
2647 * be filled--but not yet valid.
2649 * Write index - driver fills this entry with an unused RBD entry.
2650 * This entry has not filled by the firmware yet.
2652 * In between the W and R indexes are the RBDs that have been received
2653 * but not yet processed.
2655 * The process of handling packets will start at WRITE + 1 and advance
2656 * until it reaches the READ index.
2658 * The WRITE index is cached in the variable 'priv->rx_queue.next'.
2661 static void __ipw2100_rx_process(struct ipw2100_priv *priv)
2663 struct ipw2100_bd_queue *rxq = &priv->rx_queue;
2664 struct ipw2100_status_queue *sq = &priv->status_queue;
2665 struct ipw2100_rx_packet *packet;
2668 struct ipw2100_rx *u;
2669 struct libipw_rx_stats stats = {
2670 .mac_time = jiffies,
2673 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_READ_INDEX, &r);
2674 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_WRITE_INDEX, &w);
2676 if (r >= rxq->entries) {
2677 IPW_DEBUG_RX("exit - bad read index\n");
2681 i = (rxq->next + 1) % rxq->entries;
2684 /* IPW_DEBUG_RX("r = %d : w = %d : processing = %d\n",
2685 r, rxq->next, i); */
2687 packet = &priv->rx_buffers[i];
2689 /* Sync the DMA for the RX buffer so CPU is sure to get
2690 * the correct values */
2691 dma_sync_single_for_cpu(&priv->pci_dev->dev, packet->dma_addr,
2692 sizeof(struct ipw2100_rx),
2695 if (unlikely(ipw2100_corruption_check(priv, i))) {
2696 ipw2100_corruption_detected(priv, i);
2701 frame_type = sq->drv[i].status_fields & STATUS_TYPE_MASK;
2702 stats.rssi = sq->drv[i].rssi + IPW2100_RSSI_TO_DBM;
2703 stats.len = sq->drv[i].frame_size;
2706 if (stats.rssi != 0)
2707 stats.mask |= LIBIPW_STATMASK_RSSI;
2708 stats.freq = LIBIPW_24GHZ_BAND;
2710 IPW_DEBUG_RX("%s: '%s' frame type received (%d).\n",
2711 priv->net_dev->name, frame_types[frame_type],
2714 switch (frame_type) {
2715 case COMMAND_STATUS_VAL:
2716 /* Reset Rx watchdog */
2717 isr_rx_complete_command(priv, &u->rx_data.command);
2720 case STATUS_CHANGE_VAL:
2721 isr_status_change(priv, u->rx_data.status);
2724 case P80211_DATA_VAL:
2725 case P8023_DATA_VAL:
2726 #ifdef CONFIG_IPW2100_MONITOR
2727 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
2728 isr_rx_monitor(priv, i, &stats);
2732 if (stats.len < sizeof(struct libipw_hdr_3addr))
2734 switch (WLAN_FC_GET_TYPE(le16_to_cpu(u->rx_data.header.frame_ctl))) {
2735 case IEEE80211_FTYPE_MGMT:
2736 libipw_rx_mgt(priv->ieee,
2737 &u->rx_data.header, &stats);
2740 case IEEE80211_FTYPE_CTL:
2743 case IEEE80211_FTYPE_DATA:
2744 isr_rx(priv, i, &stats);
2752 /* clear status field associated with this RBD */
2753 rxq->drv[i].status.info.field = 0;
2755 i = (i + 1) % rxq->entries;
2759 /* backtrack one entry, wrapping to end if at 0 */
2760 rxq->next = (i ? i : rxq->entries) - 1;
2762 write_register(priv->net_dev,
2763 IPW_MEM_HOST_SHARED_RX_WRITE_INDEX, rxq->next);
2768 * __ipw2100_tx_process
2770 * This routine will determine whether the next packet on
2771 * the fw_pend_list has been processed by the firmware yet.
2773 * If not, then it does nothing and returns.
2775 * If so, then it removes the item from the fw_pend_list, frees
2776 * any associated storage, and places the item back on the
2777 * free list of its source (either msg_free_list or tx_free_list)
2779 * TX Queue works as follows:
2781 * Read index - points to the next TBD that the firmware will
2782 * process. The firmware will read the data, and once
2783 * done processing, it will advance the Read index.
2785 * Write index - driver fills this entry with an constructed TBD
2786 * entry. The Write index is not advanced until the
2787 * packet has been configured.
2789 * In between the W and R indexes are the TBDs that have NOT been
2790 * processed. Lagging behind the R index are packets that have
2791 * been processed but have not been freed by the driver.
2793 * In order to free old storage, an internal index will be maintained
2794 * that points to the next packet to be freed. When all used
2795 * packets have been freed, the oldest index will be the same as the
2796 * firmware's read index.
2798 * The OLDEST index is cached in the variable 'priv->tx_queue.oldest'
2800 * Because the TBD structure can not contain arbitrary data, the
2801 * driver must keep an internal queue of cached allocations such that
2802 * it can put that data back into the tx_free_list and msg_free_list
2803 * for use by future command and data packets.
2806 static int __ipw2100_tx_process(struct ipw2100_priv *priv)
2808 struct ipw2100_bd_queue *txq = &priv->tx_queue;
2809 struct ipw2100_bd *tbd;
2810 struct list_head *element;
2811 struct ipw2100_tx_packet *packet;
2812 int descriptors_used;
2814 u32 r, w, frag_num = 0;
2816 if (list_empty(&priv->fw_pend_list))
2819 element = priv->fw_pend_list.next;
2821 packet = list_entry(element, struct ipw2100_tx_packet, list);
2822 tbd = &txq->drv[packet->index];
2824 /* Determine how many TBD entries must be finished... */
2825 switch (packet->type) {
2827 /* COMMAND uses only one slot; don't advance */
2828 descriptors_used = 1;
2833 /* DATA uses two slots; advance and loop position. */
2834 descriptors_used = tbd->num_fragments;
2835 frag_num = tbd->num_fragments - 1;
2836 e = txq->oldest + frag_num;
2841 printk(KERN_WARNING DRV_NAME ": %s: Bad fw_pend_list entry!\n",
2842 priv->net_dev->name);
2846 /* if the last TBD is not done by NIC yet, then packet is
2847 * not ready to be released.
2850 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_TX_QUEUE_READ_INDEX,
2852 read_register(priv->net_dev, IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX,
2855 printk(KERN_WARNING DRV_NAME ": %s: write index mismatch\n",
2856 priv->net_dev->name);
2859 * txq->next is the index of the last packet written txq->oldest is
2860 * the index of the r is the index of the next packet to be read by
2865 * Quick graphic to help you visualize the following
2866 * if / else statement
2868 * ===>| s---->|===============
2870 * | a | b | c | d | e | f | g | h | i | j | k | l
2874 * w - updated by driver
2875 * r - updated by firmware
2876 * s - start of oldest BD entry (txq->oldest)
2877 * e - end of oldest BD entry
2880 if (!((r <= w && (e < r || e >= w)) || (e < r && e >= w))) {
2881 IPW_DEBUG_TX("exit - no processed packets ready to release.\n");
2886 DEC_STAT(&priv->fw_pend_stat);
2888 #ifdef CONFIG_IPW2100_DEBUG
2891 IPW_DEBUG_TX("TX%d V=%p P=%04X T=%04X L=%d\n", i,
2893 (u32) (txq->nic + i * sizeof(struct ipw2100_bd)),
2894 txq->drv[i].host_addr, txq->drv[i].buf_length);
2896 if (packet->type == DATA) {
2897 i = (i + 1) % txq->entries;
2899 IPW_DEBUG_TX("TX%d V=%p P=%04X T=%04X L=%d\n", i,
2901 (u32) (txq->nic + i *
2902 sizeof(struct ipw2100_bd)),
2903 (u32) txq->drv[i].host_addr,
2904 txq->drv[i].buf_length);
2909 switch (packet->type) {
2911 if (txq->drv[txq->oldest].status.info.fields.txType != 0)
2912 printk(KERN_WARNING DRV_NAME ": %s: Queue mismatch. "
2913 "Expecting DATA TBD but pulled "
2914 "something else: ids %d=%d.\n",
2915 priv->net_dev->name, txq->oldest, packet->index);
2917 /* DATA packet; we have to unmap and free the SKB */
2918 for (i = 0; i < frag_num; i++) {
2919 tbd = &txq->drv[(packet->index + 1 + i) % txq->entries];
2921 IPW_DEBUG_TX("TX%d P=%08x L=%d\n",
2922 (packet->index + 1 + i) % txq->entries,
2923 tbd->host_addr, tbd->buf_length);
2925 dma_unmap_single(&priv->pci_dev->dev, tbd->host_addr,
2926 tbd->buf_length, DMA_TO_DEVICE);
2929 libipw_txb_free(packet->info.d_struct.txb);
2930 packet->info.d_struct.txb = NULL;
2932 list_add_tail(element, &priv->tx_free_list);
2933 INC_STAT(&priv->tx_free_stat);
2935 /* We have a free slot in the Tx queue, so wake up the
2936 * transmit layer if it is stopped. */
2937 if (priv->status & STATUS_ASSOCIATED)
2938 netif_wake_queue(priv->net_dev);
2940 /* A packet was processed by the hardware, so update the
2942 netif_trans_update(priv->net_dev);
2947 if (txq->drv[txq->oldest].status.info.fields.txType != 1)
2948 printk(KERN_WARNING DRV_NAME ": %s: Queue mismatch. "
2949 "Expecting COMMAND TBD but pulled "
2950 "something else: ids %d=%d.\n",
2951 priv->net_dev->name, txq->oldest, packet->index);
2953 #ifdef CONFIG_IPW2100_DEBUG
2954 if (packet->info.c_struct.cmd->host_command_reg <
2955 ARRAY_SIZE(command_types))
2956 IPW_DEBUG_TX("Command '%s (%d)' processed: %d.\n",
2957 command_types[packet->info.c_struct.cmd->
2959 packet->info.c_struct.cmd->
2961 packet->info.c_struct.cmd->cmd_status_reg);
2964 list_add_tail(element, &priv->msg_free_list);
2965 INC_STAT(&priv->msg_free_stat);
2969 /* advance oldest used TBD pointer to start of next entry */
2970 txq->oldest = (e + 1) % txq->entries;
2971 /* increase available TBDs number */
2972 txq->available += descriptors_used;
2973 SET_STAT(&priv->txq_stat, txq->available);
2975 IPW_DEBUG_TX("packet latency (send to process) %ld jiffies\n",
2976 jiffies - packet->jiffy_start);
2978 return (!list_empty(&priv->fw_pend_list));
2981 static inline void __ipw2100_tx_complete(struct ipw2100_priv *priv)
2985 while (__ipw2100_tx_process(priv) && i < 200)
2989 printk(KERN_WARNING DRV_NAME ": "
2990 "%s: Driver is running slow (%d iters).\n",
2991 priv->net_dev->name, i);
2995 static void ipw2100_tx_send_commands(struct ipw2100_priv *priv)
2997 struct list_head *element;
2998 struct ipw2100_tx_packet *packet;
2999 struct ipw2100_bd_queue *txq = &priv->tx_queue;
3000 struct ipw2100_bd *tbd;
3001 int next = txq->next;
3003 while (!list_empty(&priv->msg_pend_list)) {
3004 /* if there isn't enough space in TBD queue, then
3005 * don't stuff a new one in.
3006 * NOTE: 3 are needed as a command will take one,
3007 * and there is a minimum of 2 that must be
3008 * maintained between the r and w indexes
3010 if (txq->available <= 3) {
3011 IPW_DEBUG_TX("no room in tx_queue\n");
3015 element = priv->msg_pend_list.next;
3017 DEC_STAT(&priv->msg_pend_stat);
3019 packet = list_entry(element, struct ipw2100_tx_packet, list);
3021 IPW_DEBUG_TX("using TBD at virt=%p, phys=%04X\n",
3022 &txq->drv[txq->next],
3023 (u32) (txq->nic + txq->next *
3024 sizeof(struct ipw2100_bd)));
3026 packet->index = txq->next;
3028 tbd = &txq->drv[txq->next];
3030 /* initialize TBD */
3031 tbd->host_addr = packet->info.c_struct.cmd_phys;
3032 tbd->buf_length = sizeof(struct ipw2100_cmd_header);
3033 /* not marking number of fragments causes problems
3034 * with f/w debug version */
3035 tbd->num_fragments = 1;
3036 tbd->status.info.field =
3037 IPW_BD_STATUS_TX_FRAME_COMMAND |
3038 IPW_BD_STATUS_TX_INTERRUPT_ENABLE;
3040 /* update TBD queue counters */
3042 txq->next %= txq->entries;
3044 DEC_STAT(&priv->txq_stat);
3046 list_add_tail(element, &priv->fw_pend_list);
3047 INC_STAT(&priv->fw_pend_stat);
3050 if (txq->next != next) {
3051 /* kick off the DMA by notifying firmware the
3052 * write index has moved; make sure TBD stores are sync'd */
3054 write_register(priv->net_dev,
3055 IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX,
3061 * ipw2100_tx_send_data
3064 static void ipw2100_tx_send_data(struct ipw2100_priv *priv)
3066 struct list_head *element;
3067 struct ipw2100_tx_packet *packet;
3068 struct ipw2100_bd_queue *txq = &priv->tx_queue;
3069 struct ipw2100_bd *tbd;
3070 int next = txq->next;
3072 struct ipw2100_data_header *ipw_hdr;
3073 struct libipw_hdr_3addr *hdr;
3075 while (!list_empty(&priv->tx_pend_list)) {
3076 /* if there isn't enough space in TBD queue, then
3077 * don't stuff a new one in.
3078 * NOTE: 4 are needed as a data will take two,
3079 * and there is a minimum of 2 that must be
3080 * maintained between the r and w indexes
3082 element = priv->tx_pend_list.next;
3083 packet = list_entry(element, struct ipw2100_tx_packet, list);
3085 if (unlikely(1 + packet->info.d_struct.txb->nr_frags >
3087 /* TODO: Support merging buffers if more than
3088 * IPW_MAX_BDS are used */
3089 IPW_DEBUG_INFO("%s: Maximum BD threshold exceeded. "
3090 "Increase fragmentation level.\n",
3091 priv->net_dev->name);
3094 if (txq->available <= 3 + packet->info.d_struct.txb->nr_frags) {
3095 IPW_DEBUG_TX("no room in tx_queue\n");
3100 DEC_STAT(&priv->tx_pend_stat);
3102 tbd = &txq->drv[txq->next];
3104 packet->index = txq->next;
3106 ipw_hdr = packet->info.d_struct.data;
3107 hdr = (struct libipw_hdr_3addr *)packet->info.d_struct.txb->
3110 if (priv->ieee->iw_mode == IW_MODE_INFRA) {
3111 /* To DS: Addr1 = BSSID, Addr2 = SA,
3113 memcpy(ipw_hdr->src_addr, hdr->addr2, ETH_ALEN);
3114 memcpy(ipw_hdr->dst_addr, hdr->addr3, ETH_ALEN);
3115 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
3116 /* not From/To DS: Addr1 = DA, Addr2 = SA,
3118 memcpy(ipw_hdr->src_addr, hdr->addr2, ETH_ALEN);
3119 memcpy(ipw_hdr->dst_addr, hdr->addr1, ETH_ALEN);
3122 ipw_hdr->host_command_reg = SEND;
3123 ipw_hdr->host_command_reg1 = 0;
3125 /* For now we only support host based encryption */
3126 ipw_hdr->needs_encryption = 0;
3127 ipw_hdr->encrypted = packet->info.d_struct.txb->encrypted;
3128 if (packet->info.d_struct.txb->nr_frags > 1)
3129 ipw_hdr->fragment_size =
3130 packet->info.d_struct.txb->frag_size -
3133 ipw_hdr->fragment_size = 0;
3135 tbd->host_addr = packet->info.d_struct.data_phys;
3136 tbd->buf_length = sizeof(struct ipw2100_data_header);
3137 tbd->num_fragments = 1 + packet->info.d_struct.txb->nr_frags;
3138 tbd->status.info.field =
3139 IPW_BD_STATUS_TX_FRAME_802_3 |
3140 IPW_BD_STATUS_TX_FRAME_NOT_LAST_FRAGMENT;
3142 txq->next %= txq->entries;
3144 IPW_DEBUG_TX("data header tbd TX%d P=%08x L=%d\n",
3145 packet->index, tbd->host_addr, tbd->buf_length);
3146 #ifdef CONFIG_IPW2100_DEBUG
3147 if (packet->info.d_struct.txb->nr_frags > 1)
3148 IPW_DEBUG_FRAG("fragment Tx: %d frames\n",
3149 packet->info.d_struct.txb->nr_frags);
3152 for (i = 0; i < packet->info.d_struct.txb->nr_frags; i++) {
3153 tbd = &txq->drv[txq->next];
3154 if (i == packet->info.d_struct.txb->nr_frags - 1)
3155 tbd->status.info.field =
3156 IPW_BD_STATUS_TX_FRAME_802_3 |
3157 IPW_BD_STATUS_TX_INTERRUPT_ENABLE;
3159 tbd->status.info.field =
3160 IPW_BD_STATUS_TX_FRAME_802_3 |
3161 IPW_BD_STATUS_TX_FRAME_NOT_LAST_FRAGMENT;
3163 tbd->buf_length = packet->info.d_struct.txb->
3164 fragments[i]->len - LIBIPW_3ADDR_LEN;
3166 tbd->host_addr = dma_map_single(&priv->pci_dev->dev,
3167 packet->info.d_struct.
3168 txb->fragments[i]->data +
3172 if (dma_mapping_error(&priv->pci_dev->dev, tbd->host_addr)) {
3173 IPW_DEBUG_TX("dma mapping error\n");
3177 IPW_DEBUG_TX("data frag tbd TX%d P=%08x L=%d\n",
3178 txq->next, tbd->host_addr,
3181 dma_sync_single_for_device(&priv->pci_dev->dev,
3187 txq->next %= txq->entries;
3190 txq->available -= 1 + packet->info.d_struct.txb->nr_frags;
3191 SET_STAT(&priv->txq_stat, txq->available);
3193 list_add_tail(element, &priv->fw_pend_list);
3194 INC_STAT(&priv->fw_pend_stat);
3197 if (txq->next != next) {
3198 /* kick off the DMA by notifying firmware the
3199 * write index has moved; make sure TBD stores are sync'd */
3200 write_register(priv->net_dev,
3201 IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX,
3206 static void ipw2100_irq_tasklet(struct tasklet_struct *t)
3208 struct ipw2100_priv *priv = from_tasklet(priv, t, irq_tasklet);
3209 struct net_device *dev = priv->net_dev;
3210 unsigned long flags;
3213 spin_lock_irqsave(&priv->low_lock, flags);
3214 ipw2100_disable_interrupts(priv);
3216 read_register(dev, IPW_REG_INTA, &inta);
3218 IPW_DEBUG_ISR("enter - INTA: 0x%08lX\n",
3219 (unsigned long)inta & IPW_INTERRUPT_MASK);
3224 /* We do not loop and keep polling for more interrupts as this
3225 * is frowned upon and doesn't play nicely with other potentially
3227 IPW_DEBUG_ISR("INTA: 0x%08lX\n",
3228 (unsigned long)inta & IPW_INTERRUPT_MASK);
3230 if (inta & IPW2100_INTA_FATAL_ERROR) {
3231 printk(KERN_WARNING DRV_NAME
3232 ": Fatal interrupt. Scheduling firmware restart.\n");
3234 write_register(dev, IPW_REG_INTA, IPW2100_INTA_FATAL_ERROR);
3236 read_nic_dword(dev, IPW_NIC_FATAL_ERROR, &priv->fatal_error);
3237 IPW_DEBUG_INFO("%s: Fatal error value: 0x%08X\n",
3238 priv->net_dev->name, priv->fatal_error);
3240 read_nic_dword(dev, IPW_ERROR_ADDR(priv->fatal_error), &tmp);
3241 IPW_DEBUG_INFO("%s: Fatal error address value: 0x%08X\n",
3242 priv->net_dev->name, tmp);
3244 /* Wake up any sleeping jobs */
3245 schedule_reset(priv);
3248 if (inta & IPW2100_INTA_PARITY_ERROR) {
3249 printk(KERN_ERR DRV_NAME
3250 ": ***** PARITY ERROR INTERRUPT !!!!\n");
3252 write_register(dev, IPW_REG_INTA, IPW2100_INTA_PARITY_ERROR);
3255 if (inta & IPW2100_INTA_RX_TRANSFER) {
3256 IPW_DEBUG_ISR("RX interrupt\n");
3258 priv->rx_interrupts++;
3260 write_register(dev, IPW_REG_INTA, IPW2100_INTA_RX_TRANSFER);
3262 __ipw2100_rx_process(priv);
3263 __ipw2100_tx_complete(priv);
3266 if (inta & IPW2100_INTA_TX_TRANSFER) {
3267 IPW_DEBUG_ISR("TX interrupt\n");
3269 priv->tx_interrupts++;
3271 write_register(dev, IPW_REG_INTA, IPW2100_INTA_TX_TRANSFER);
3273 __ipw2100_tx_complete(priv);
3274 ipw2100_tx_send_commands(priv);
3275 ipw2100_tx_send_data(priv);
3278 if (inta & IPW2100_INTA_TX_COMPLETE) {
3279 IPW_DEBUG_ISR("TX complete\n");
3281 write_register(dev, IPW_REG_INTA, IPW2100_INTA_TX_COMPLETE);
3283 __ipw2100_tx_complete(priv);
3286 if (inta & IPW2100_INTA_EVENT_INTERRUPT) {
3287 /* ipw2100_handle_event(dev); */
3289 write_register(dev, IPW_REG_INTA, IPW2100_INTA_EVENT_INTERRUPT);
3292 if (inta & IPW2100_INTA_FW_INIT_DONE) {
3293 IPW_DEBUG_ISR("FW init done interrupt\n");
3296 read_register(dev, IPW_REG_INTA, &tmp);
3297 if (tmp & (IPW2100_INTA_FATAL_ERROR |
3298 IPW2100_INTA_PARITY_ERROR)) {
3299 write_register(dev, IPW_REG_INTA,
3300 IPW2100_INTA_FATAL_ERROR |
3301 IPW2100_INTA_PARITY_ERROR);
3304 write_register(dev, IPW_REG_INTA, IPW2100_INTA_FW_INIT_DONE);
3307 if (inta & IPW2100_INTA_STATUS_CHANGE) {
3308 IPW_DEBUG_ISR("Status change interrupt\n");
3310 write_register(dev, IPW_REG_INTA, IPW2100_INTA_STATUS_CHANGE);
3313 if (inta & IPW2100_INTA_SLAVE_MODE_HOST_COMMAND_DONE) {
3314 IPW_DEBUG_ISR("slave host mode interrupt\n");
3316 write_register(dev, IPW_REG_INTA,
3317 IPW2100_INTA_SLAVE_MODE_HOST_COMMAND_DONE);
3321 ipw2100_enable_interrupts(priv);
3323 spin_unlock_irqrestore(&priv->low_lock, flags);
3325 IPW_DEBUG_ISR("exit\n");
3328 static irqreturn_t ipw2100_interrupt(int irq, void *data)
3330 struct ipw2100_priv *priv = data;
3331 u32 inta, inta_mask;
3336 spin_lock(&priv->low_lock);
3338 /* We check to see if we should be ignoring interrupts before
3339 * we touch the hardware. During ucode load if we try and handle
3340 * an interrupt we can cause keyboard problems as well as cause
3341 * the ucode to fail to initialize */
3342 if (!(priv->status & STATUS_INT_ENABLED)) {
3347 read_register(priv->net_dev, IPW_REG_INTA_MASK, &inta_mask);
3348 read_register(priv->net_dev, IPW_REG_INTA, &inta);
3350 if (inta == 0xFFFFFFFF) {
3351 /* Hardware disappeared */
3352 printk(KERN_WARNING DRV_NAME ": IRQ INTA == 0xFFFFFFFF\n");
3356 inta &= IPW_INTERRUPT_MASK;
3358 if (!(inta & inta_mask)) {
3359 /* Shared interrupt */
3363 /* We disable the hardware interrupt here just to prevent unneeded
3364 * calls to be made. We disable this again within the actual
3365 * work tasklet, so if another part of the code re-enables the
3366 * interrupt, that is fine */
3367 ipw2100_disable_interrupts(priv);
3369 tasklet_schedule(&priv->irq_tasklet);
3370 spin_unlock(&priv->low_lock);
3374 spin_unlock(&priv->low_lock);
3378 static netdev_tx_t ipw2100_tx(struct libipw_txb *txb,
3379 struct net_device *dev, int pri)
3381 struct ipw2100_priv *priv = libipw_priv(dev);
3382 struct list_head *element;
3383 struct ipw2100_tx_packet *packet;
3384 unsigned long flags;
3386 spin_lock_irqsave(&priv->low_lock, flags);
3388 if (!(priv->status & STATUS_ASSOCIATED)) {
3389 IPW_DEBUG_INFO("Can not transmit when not connected.\n");
3390 priv->net_dev->stats.tx_carrier_errors++;
3391 netif_stop_queue(dev);
3395 if (list_empty(&priv->tx_free_list))
3398 element = priv->tx_free_list.next;
3399 packet = list_entry(element, struct ipw2100_tx_packet, list);
3401 packet->info.d_struct.txb = txb;
3403 IPW_DEBUG_TX("Sending fragment (%d bytes):\n", txb->fragments[0]->len);
3404 printk_buf(IPW_DL_TX, txb->fragments[0]->data, txb->fragments[0]->len);
3406 packet->jiffy_start = jiffies;
3409 DEC_STAT(&priv->tx_free_stat);
3411 list_add_tail(element, &priv->tx_pend_list);
3412 INC_STAT(&priv->tx_pend_stat);
3414 ipw2100_tx_send_data(priv);
3416 spin_unlock_irqrestore(&priv->low_lock, flags);
3417 return NETDEV_TX_OK;
3420 netif_stop_queue(dev);
3421 spin_unlock_irqrestore(&priv->low_lock, flags);
3422 return NETDEV_TX_BUSY;
3425 static int ipw2100_msg_allocate(struct ipw2100_priv *priv)
3427 int i, j, err = -EINVAL;
3432 kmalloc_array(IPW_COMMAND_POOL_SIZE,
3433 sizeof(struct ipw2100_tx_packet),
3435 if (!priv->msg_buffers)
3438 for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++) {
3439 v = dma_alloc_coherent(&priv->pci_dev->dev,
3440 sizeof(struct ipw2100_cmd_header), &p,
3443 printk(KERN_ERR DRV_NAME ": "
3444 "%s: PCI alloc failed for msg "
3445 "buffers.\n", priv->net_dev->name);
3450 priv->msg_buffers[i].type = COMMAND;
3451 priv->msg_buffers[i].info.c_struct.cmd =
3452 (struct ipw2100_cmd_header *)v;
3453 priv->msg_buffers[i].info.c_struct.cmd_phys = p;
3456 if (i == IPW_COMMAND_POOL_SIZE)
3459 for (j = 0; j < i; j++) {
3460 dma_free_coherent(&priv->pci_dev->dev,
3461 sizeof(struct ipw2100_cmd_header),
3462 priv->msg_buffers[j].info.c_struct.cmd,
3463 priv->msg_buffers[j].info.c_struct.cmd_phys);
3466 kfree(priv->msg_buffers);
3467 priv->msg_buffers = NULL;
3472 static int ipw2100_msg_initialize(struct ipw2100_priv *priv)
3476 INIT_LIST_HEAD(&priv->msg_free_list);
3477 INIT_LIST_HEAD(&priv->msg_pend_list);
3479 for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++)
3480 list_add_tail(&priv->msg_buffers[i].list, &priv->msg_free_list);
3481 SET_STAT(&priv->msg_free_stat, i);
3486 static void ipw2100_msg_free(struct ipw2100_priv *priv)
3490 if (!priv->msg_buffers)
3493 for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++) {
3494 dma_free_coherent(&priv->pci_dev->dev,
3495 sizeof(struct ipw2100_cmd_header),
3496 priv->msg_buffers[i].info.c_struct.cmd,
3497 priv->msg_buffers[i].info.c_struct.cmd_phys);
3500 kfree(priv->msg_buffers);
3501 priv->msg_buffers = NULL;
3504 static ssize_t show_pci(struct device *d, struct device_attribute *attr,
3507 struct pci_dev *pci_dev = to_pci_dev(d);
3512 for (i = 0; i < 16; i++) {
3513 out += sprintf(out, "[%08X] ", i * 16);
3514 for (j = 0; j < 16; j += 4) {
3515 pci_read_config_dword(pci_dev, i * 16 + j, &val);
3516 out += sprintf(out, "%08X ", val);
3518 out += sprintf(out, "\n");
3524 static DEVICE_ATTR(pci, 0444, show_pci, NULL);
3526 static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
3529 struct ipw2100_priv *p = dev_get_drvdata(d);
3530 return sprintf(buf, "0x%08x\n", (int)p->config);
3533 static DEVICE_ATTR(cfg, 0444, show_cfg, NULL);
3535 static ssize_t show_status(struct device *d, struct device_attribute *attr,
3538 struct ipw2100_priv *p = dev_get_drvdata(d);
3539 return sprintf(buf, "0x%08x\n", (int)p->status);
3542 static DEVICE_ATTR(status, 0444, show_status, NULL);
3544 static ssize_t show_capability(struct device *d, struct device_attribute *attr,
3547 struct ipw2100_priv *p = dev_get_drvdata(d);
3548 return sprintf(buf, "0x%08x\n", (int)p->capability);
3551 static DEVICE_ATTR(capability, 0444, show_capability, NULL);
3553 #define IPW2100_REG(x) { IPW_ ##x, #x }
3554 static const struct {
3558 IPW2100_REG(REG_GP_CNTRL),
3559 IPW2100_REG(REG_GPIO),
3560 IPW2100_REG(REG_INTA),
3561 IPW2100_REG(REG_INTA_MASK), IPW2100_REG(REG_RESET_REG),};
3562 #define IPW2100_NIC(x, s) { x, #x, s }
3563 static const struct {
3568 IPW2100_NIC(IPW2100_CONTROL_REG, 2),
3569 IPW2100_NIC(0x210014, 1), IPW2100_NIC(0x210000, 1),};
3570 #define IPW2100_ORD(x, d) { IPW_ORD_ ##x, #x, d }
3571 static const struct {
3576 IPW2100_ORD(STAT_TX_HOST_REQUESTS, "requested Host Tx's (MSDU)"),
3577 IPW2100_ORD(STAT_TX_HOST_COMPLETE,
3578 "successful Host Tx's (MSDU)"),
3579 IPW2100_ORD(STAT_TX_DIR_DATA,
3580 "successful Directed Tx's (MSDU)"),
3581 IPW2100_ORD(STAT_TX_DIR_DATA1,
3582 "successful Directed Tx's (MSDU) @ 1MB"),
3583 IPW2100_ORD(STAT_TX_DIR_DATA2,
3584 "successful Directed Tx's (MSDU) @ 2MB"),
3585 IPW2100_ORD(STAT_TX_DIR_DATA5_5,
3586 "successful Directed Tx's (MSDU) @ 5_5MB"),
3587 IPW2100_ORD(STAT_TX_DIR_DATA11,
3588 "successful Directed Tx's (MSDU) @ 11MB"),
3589 IPW2100_ORD(STAT_TX_NODIR_DATA1,
3590 "successful Non_Directed Tx's (MSDU) @ 1MB"),
3591 IPW2100_ORD(STAT_TX_NODIR_DATA2,
3592 "successful Non_Directed Tx's (MSDU) @ 2MB"),
3593 IPW2100_ORD(STAT_TX_NODIR_DATA5_5,
3594 "successful Non_Directed Tx's (MSDU) @ 5.5MB"),
3595 IPW2100_ORD(STAT_TX_NODIR_DATA11,
3596 "successful Non_Directed Tx's (MSDU) @ 11MB"),
3597 IPW2100_ORD(STAT_NULL_DATA, "successful NULL data Tx's"),
3598 IPW2100_ORD(STAT_TX_RTS, "successful Tx RTS"),
3599 IPW2100_ORD(STAT_TX_CTS, "successful Tx CTS"),
3600 IPW2100_ORD(STAT_TX_ACK, "successful Tx ACK"),
3601 IPW2100_ORD(STAT_TX_ASSN, "successful Association Tx's"),
3602 IPW2100_ORD(STAT_TX_ASSN_RESP,
3603 "successful Association response Tx's"),
3604 IPW2100_ORD(STAT_TX_REASSN,
3605 "successful Reassociation Tx's"),
3606 IPW2100_ORD(STAT_TX_REASSN_RESP,
3607 "successful Reassociation response Tx's"),
3608 IPW2100_ORD(STAT_TX_PROBE,
3609 "probes successfully transmitted"),
3610 IPW2100_ORD(STAT_TX_PROBE_RESP,
3611 "probe responses successfully transmitted"),
3612 IPW2100_ORD(STAT_TX_BEACON, "tx beacon"),
3613 IPW2100_ORD(STAT_TX_ATIM, "Tx ATIM"),
3614 IPW2100_ORD(STAT_TX_DISASSN,
3615 "successful Disassociation TX"),
3616 IPW2100_ORD(STAT_TX_AUTH, "successful Authentication Tx"),
3617 IPW2100_ORD(STAT_TX_DEAUTH,
3618 "successful Deauthentication TX"),
3619 IPW2100_ORD(STAT_TX_TOTAL_BYTES,
3620 "Total successful Tx data bytes"),
3621 IPW2100_ORD(STAT_TX_RETRIES, "Tx retries"),
3622 IPW2100_ORD(STAT_TX_RETRY1, "Tx retries at 1MBPS"),
3623 IPW2100_ORD(STAT_TX_RETRY2, "Tx retries at 2MBPS"),
3624 IPW2100_ORD(STAT_TX_RETRY5_5, "Tx retries at 5.5MBPS"),
3625 IPW2100_ORD(STAT_TX_RETRY11, "Tx retries at 11MBPS"),
3626 IPW2100_ORD(STAT_TX_FAILURES, "Tx Failures"),
3627 IPW2100_ORD(STAT_TX_MAX_TRIES_IN_HOP,
3628 "times max tries in a hop failed"),
3629 IPW2100_ORD(STAT_TX_DISASSN_FAIL,
3630 "times disassociation failed"),
3631 IPW2100_ORD(STAT_TX_ERR_CTS, "missed/bad CTS frames"),
3632 IPW2100_ORD(STAT_TX_ERR_ACK, "tx err due to acks"),
3633 IPW2100_ORD(STAT_RX_HOST, "packets passed to host"),
3634 IPW2100_ORD(STAT_RX_DIR_DATA, "directed packets"),
3635 IPW2100_ORD(STAT_RX_DIR_DATA1, "directed packets at 1MB"),
3636 IPW2100_ORD(STAT_RX_DIR_DATA2, "directed packets at 2MB"),
3637 IPW2100_ORD(STAT_RX_DIR_DATA5_5,
3638 "directed packets at 5.5MB"),
3639 IPW2100_ORD(STAT_RX_DIR_DATA11, "directed packets at 11MB"),
3640 IPW2100_ORD(STAT_RX_NODIR_DATA, "nondirected packets"),
3641 IPW2100_ORD(STAT_RX_NODIR_DATA1,
3642 "nondirected packets at 1MB"),
3643 IPW2100_ORD(STAT_RX_NODIR_DATA2,
3644 "nondirected packets at 2MB"),
3645 IPW2100_ORD(STAT_RX_NODIR_DATA5_5,
3646 "nondirected packets at 5.5MB"),
3647 IPW2100_ORD(STAT_RX_NODIR_DATA11,
3648 "nondirected packets at 11MB"),
3649 IPW2100_ORD(STAT_RX_NULL_DATA, "null data rx's"),
3650 IPW2100_ORD(STAT_RX_RTS, "Rx RTS"), IPW2100_ORD(STAT_RX_CTS,
3652 IPW2100_ORD(STAT_RX_ACK, "Rx ACK"),
3653 IPW2100_ORD(STAT_RX_CFEND, "Rx CF End"),
3654 IPW2100_ORD(STAT_RX_CFEND_ACK, "Rx CF End + CF Ack"),
3655 IPW2100_ORD(STAT_RX_ASSN, "Association Rx's"),
3656 IPW2100_ORD(STAT_RX_ASSN_RESP, "Association response Rx's"),
3657 IPW2100_ORD(STAT_RX_REASSN, "Reassociation Rx's"),
3658 IPW2100_ORD(STAT_RX_REASSN_RESP,
3659 "Reassociation response Rx's"),
3660 IPW2100_ORD(STAT_RX_PROBE, "probe Rx's"),
3661 IPW2100_ORD(STAT_RX_PROBE_RESP, "probe response Rx's"),
3662 IPW2100_ORD(STAT_RX_BEACON, "Rx beacon"),
3663 IPW2100_ORD(STAT_RX_ATIM, "Rx ATIM"),
3664 IPW2100_ORD(STAT_RX_DISASSN, "disassociation Rx"),
3665 IPW2100_ORD(STAT_RX_AUTH, "authentication Rx"),
3666 IPW2100_ORD(STAT_RX_DEAUTH, "deauthentication Rx"),
3667 IPW2100_ORD(STAT_RX_TOTAL_BYTES,
3668 "Total rx data bytes received"),
3669 IPW2100_ORD(STAT_RX_ERR_CRC, "packets with Rx CRC error"),
3670 IPW2100_ORD(STAT_RX_ERR_CRC1, "Rx CRC errors at 1MB"),
3671 IPW2100_ORD(STAT_RX_ERR_CRC2, "Rx CRC errors at 2MB"),
3672 IPW2100_ORD(STAT_RX_ERR_CRC5_5, "Rx CRC errors at 5.5MB"),
3673 IPW2100_ORD(STAT_RX_ERR_CRC11, "Rx CRC errors at 11MB"),
3674 IPW2100_ORD(STAT_RX_DUPLICATE1,
3675 "duplicate rx packets at 1MB"),
3676 IPW2100_ORD(STAT_RX_DUPLICATE2,
3677 "duplicate rx packets at 2MB"),
3678 IPW2100_ORD(STAT_RX_DUPLICATE5_5,
3679 "duplicate rx packets at 5.5MB"),
3680 IPW2100_ORD(STAT_RX_DUPLICATE11,
3681 "duplicate rx packets at 11MB"),
3682 IPW2100_ORD(STAT_RX_DUPLICATE, "duplicate rx packets"),
3683 IPW2100_ORD(PERS_DB_LOCK, "locking fw permanent db"),
3684 IPW2100_ORD(PERS_DB_SIZE, "size of fw permanent db"),
3685 IPW2100_ORD(PERS_DB_ADDR, "address of fw permanent db"),
3686 IPW2100_ORD(STAT_RX_INVALID_PROTOCOL,
3687 "rx frames with invalid protocol"),
3688 IPW2100_ORD(SYS_BOOT_TIME, "Boot time"),
3689 IPW2100_ORD(STAT_RX_NO_BUFFER,
3690 "rx frames rejected due to no buffer"),
3691 IPW2100_ORD(STAT_RX_MISSING_FRAG,
3692 "rx frames dropped due to missing fragment"),
3693 IPW2100_ORD(STAT_RX_ORPHAN_FRAG,
3694 "rx frames dropped due to non-sequential fragment"),
3695 IPW2100_ORD(STAT_RX_ORPHAN_FRAME,
3696 "rx frames dropped due to unmatched 1st frame"),
3697 IPW2100_ORD(STAT_RX_FRAG_AGEOUT,
3698 "rx frames dropped due to uncompleted frame"),
3699 IPW2100_ORD(STAT_RX_ICV_ERRORS,
3700 "ICV errors during decryption"),
3701 IPW2100_ORD(STAT_PSP_SUSPENSION, "times adapter suspended"),
3702 IPW2100_ORD(STAT_PSP_BCN_TIMEOUT, "beacon timeout"),
3703 IPW2100_ORD(STAT_PSP_POLL_TIMEOUT,
3704 "poll response timeouts"),
3705 IPW2100_ORD(STAT_PSP_NONDIR_TIMEOUT,
3706 "timeouts waiting for last {broad,multi}cast pkt"),
3707 IPW2100_ORD(STAT_PSP_RX_DTIMS, "PSP DTIMs received"),
3708 IPW2100_ORD(STAT_PSP_RX_TIMS, "PSP TIMs received"),
3709 IPW2100_ORD(STAT_PSP_STATION_ID, "PSP Station ID"),
3710 IPW2100_ORD(LAST_ASSN_TIME, "RTC time of last association"),
3711 IPW2100_ORD(STAT_PERCENT_MISSED_BCNS,
3712 "current calculation of % missed beacons"),
3713 IPW2100_ORD(STAT_PERCENT_RETRIES,
3714 "current calculation of % missed tx retries"),
3715 IPW2100_ORD(ASSOCIATED_AP_PTR,
3716 "0 if not associated, else pointer to AP table entry"),
3717 IPW2100_ORD(AVAILABLE_AP_CNT,
3718 "AP's described in the AP table"),
3719 IPW2100_ORD(AP_LIST_PTR, "Ptr to list of available APs"),
3720 IPW2100_ORD(STAT_AP_ASSNS, "associations"),
3721 IPW2100_ORD(STAT_ASSN_FAIL, "association failures"),
3722 IPW2100_ORD(STAT_ASSN_RESP_FAIL,
3723 "failures due to response fail"),
3724 IPW2100_ORD(STAT_FULL_SCANS, "full scans"),
3725 IPW2100_ORD(CARD_DISABLED, "Card Disabled"),
3726 IPW2100_ORD(STAT_ROAM_INHIBIT,
3727 "times roaming was inhibited due to activity"),
3728 IPW2100_ORD(RSSI_AT_ASSN,
3729 "RSSI of associated AP at time of association"),
3730 IPW2100_ORD(STAT_ASSN_CAUSE1,
3731 "reassociation: no probe response or TX on hop"),
3732 IPW2100_ORD(STAT_ASSN_CAUSE2,
3733 "reassociation: poor tx/rx quality"),
3734 IPW2100_ORD(STAT_ASSN_CAUSE3,
3735 "reassociation: tx/rx quality (excessive AP load"),
3736 IPW2100_ORD(STAT_ASSN_CAUSE4,
3737 "reassociation: AP RSSI level"),
3738 IPW2100_ORD(STAT_ASSN_CAUSE5,
3739 "reassociations due to load leveling"),
3740 IPW2100_ORD(STAT_AUTH_FAIL, "times authentication failed"),
3741 IPW2100_ORD(STAT_AUTH_RESP_FAIL,
3742 "times authentication response failed"),
3743 IPW2100_ORD(STATION_TABLE_CNT,
3744 "entries in association table"),
3745 IPW2100_ORD(RSSI_AVG_CURR, "Current avg RSSI"),
3746 IPW2100_ORD(POWER_MGMT_MODE, "Power mode - 0=CAM, 1=PSP"),
3747 IPW2100_ORD(COUNTRY_CODE,
3748 "IEEE country code as recv'd from beacon"),
3749 IPW2100_ORD(COUNTRY_CHANNELS,
3750 "channels supported by country"),
3751 IPW2100_ORD(RESET_CNT, "adapter resets (warm)"),
3752 IPW2100_ORD(BEACON_INTERVAL, "Beacon interval"),
3753 IPW2100_ORD(ANTENNA_DIVERSITY,
3754 "TRUE if antenna diversity is disabled"),
3755 IPW2100_ORD(DTIM_PERIOD, "beacon intervals between DTIMs"),
3756 IPW2100_ORD(OUR_FREQ,
3757 "current radio freq lower digits - channel ID"),
3758 IPW2100_ORD(RTC_TIME, "current RTC time"),
3759 IPW2100_ORD(PORT_TYPE, "operating mode"),
3760 IPW2100_ORD(CURRENT_TX_RATE, "current tx rate"),
3761 IPW2100_ORD(SUPPORTED_RATES, "supported tx rates"),
3762 IPW2100_ORD(ATIM_WINDOW, "current ATIM Window"),
3763 IPW2100_ORD(BASIC_RATES, "basic tx rates"),
3764 IPW2100_ORD(NIC_HIGHEST_RATE, "NIC highest tx rate"),
3765 IPW2100_ORD(AP_HIGHEST_RATE, "AP highest tx rate"),
3766 IPW2100_ORD(CAPABILITIES,
3767 "Management frame capability field"),
3768 IPW2100_ORD(AUTH_TYPE, "Type of authentication"),
3769 IPW2100_ORD(RADIO_TYPE, "Adapter card platform type"),
3770 IPW2100_ORD(RTS_THRESHOLD,
3771 "Min packet length for RTS handshaking"),
3772 IPW2100_ORD(INT_MODE, "International mode"),
3773 IPW2100_ORD(FRAGMENTATION_THRESHOLD,
3774 "protocol frag threshold"),
3775 IPW2100_ORD(EEPROM_SRAM_DB_BLOCK_START_ADDRESS,
3776 "EEPROM offset in SRAM"),
3777 IPW2100_ORD(EEPROM_SRAM_DB_BLOCK_SIZE,
3778 "EEPROM size in SRAM"),
3779 IPW2100_ORD(EEPROM_SKU_CAPABILITY, "EEPROM SKU Capability"),
3780 IPW2100_ORD(EEPROM_IBSS_11B_CHANNELS,
3781 "EEPROM IBSS 11b channel set"),
3782 IPW2100_ORD(MAC_VERSION, "MAC Version"),
3783 IPW2100_ORD(MAC_REVISION, "MAC Revision"),
3784 IPW2100_ORD(RADIO_VERSION, "Radio Version"),
3785 IPW2100_ORD(NIC_MANF_DATE_TIME, "MANF Date/Time STAMP"),
3786 IPW2100_ORD(UCODE_VERSION, "Ucode Version"),};
3788 static ssize_t show_registers(struct device *d, struct device_attribute *attr,
3792 struct ipw2100_priv *priv = dev_get_drvdata(d);
3793 struct net_device *dev = priv->net_dev;
3797 out += sprintf(out, "%30s [Address ] : Hex\n", "Register");
3799 for (i = 0; i < ARRAY_SIZE(hw_data); i++) {
3800 read_register(dev, hw_data[i].addr, &val);
3801 out += sprintf(out, "%30s [%08X] : %08X\n",
3802 hw_data[i].name, hw_data[i].addr, val);
3808 static DEVICE_ATTR(registers, 0444, show_registers, NULL);
3810 static ssize_t show_hardware(struct device *d, struct device_attribute *attr,
3813 struct ipw2100_priv *priv = dev_get_drvdata(d);
3814 struct net_device *dev = priv->net_dev;
3818 out += sprintf(out, "%30s [Address ] : Hex\n", "NIC entry");
3820 for (i = 0; i < ARRAY_SIZE(nic_data); i++) {
3825 switch (nic_data[i].size) {
3827 read_nic_byte(dev, nic_data[i].addr, &tmp8);
3828 out += sprintf(out, "%30s [%08X] : %02X\n",
3829 nic_data[i].name, nic_data[i].addr,
3833 read_nic_word(dev, nic_data[i].addr, &tmp16);
3834 out += sprintf(out, "%30s [%08X] : %04X\n",
3835 nic_data[i].name, nic_data[i].addr,
3839 read_nic_dword(dev, nic_data[i].addr, &tmp32);
3840 out += sprintf(out, "%30s [%08X] : %08X\n",
3841 nic_data[i].name, nic_data[i].addr,
3849 static DEVICE_ATTR(hardware, 0444, show_hardware, NULL);
3851 static ssize_t show_memory(struct device *d, struct device_attribute *attr,
3854 struct ipw2100_priv *priv = dev_get_drvdata(d);
3855 struct net_device *dev = priv->net_dev;
3856 static unsigned long loop = 0;
3862 if (loop >= 0x30000)
3865 /* sysfs provides us PAGE_SIZE buffer */
3866 while (len < PAGE_SIZE - 128 && loop < 0x30000) {
3868 if (priv->snapshot[0])
3869 for (i = 0; i < 4; i++)
3871 *(u32 *) SNAPSHOT_ADDR(loop + i * 4);
3873 for (i = 0; i < 4; i++)
3874 read_nic_dword(dev, loop + i * 4, &buffer[i]);
3877 len += sprintf(buf + len,
3882 ((u8 *) buffer)[0x0],
3883 ((u8 *) buffer)[0x1],
3884 ((u8 *) buffer)[0x2],
3885 ((u8 *) buffer)[0x3],
3886 ((u8 *) buffer)[0x4],
3887 ((u8 *) buffer)[0x5],
3888 ((u8 *) buffer)[0x6],
3889 ((u8 *) buffer)[0x7],
3890 ((u8 *) buffer)[0x8],
3891 ((u8 *) buffer)[0x9],
3892 ((u8 *) buffer)[0xa],
3893 ((u8 *) buffer)[0xb],
3894 ((u8 *) buffer)[0xc],
3895 ((u8 *) buffer)[0xd],
3896 ((u8 *) buffer)[0xe],
3897 ((u8 *) buffer)[0xf]);
3899 len += sprintf(buf + len, "%s\n",
3900 snprint_line(line, sizeof(line),
3901 (u8 *) buffer, 16, loop));
3908 static ssize_t store_memory(struct device *d, struct device_attribute *attr,
3909 const char *buf, size_t count)
3911 struct ipw2100_priv *priv = dev_get_drvdata(d);
3912 struct net_device *dev = priv->net_dev;
3913 const char *p = buf;
3915 (void)dev; /* kill unused-var warning for debug-only code */
3921 (count >= 2 && tolower(p[0]) == 'o' && tolower(p[1]) == 'n')) {
3922 IPW_DEBUG_INFO("%s: Setting memory dump to RAW mode.\n",
3926 } else if (p[0] == '0' || (count >= 2 && tolower(p[0]) == 'o' &&
3927 tolower(p[1]) == 'f')) {
3928 IPW_DEBUG_INFO("%s: Setting memory dump to HEX mode.\n",
3932 } else if (tolower(p[0]) == 'r') {
3933 IPW_DEBUG_INFO("%s: Resetting firmware snapshot.\n", dev->name);
3934 ipw2100_snapshot_free(priv);
3937 IPW_DEBUG_INFO("%s: Usage: 0|on = HEX, 1|off = RAW, "
3938 "reset = clear memory snapshot\n", dev->name);
3943 static DEVICE_ATTR(memory, 0644, show_memory, store_memory);
3945 static ssize_t show_ordinals(struct device *d, struct device_attribute *attr,
3948 struct ipw2100_priv *priv = dev_get_drvdata(d);
3952 static int loop = 0;
3954 if (priv->status & STATUS_RF_KILL_MASK)
3957 if (loop >= ARRAY_SIZE(ord_data))
3960 /* sysfs provides us PAGE_SIZE buffer */
3961 while (len < PAGE_SIZE - 128 && loop < ARRAY_SIZE(ord_data)) {
3962 val_len = sizeof(u32);
3964 if (ipw2100_get_ordinal(priv, ord_data[loop].index, &val,
3966 len += sprintf(buf + len, "[0x%02X] = ERROR %s\n",
3967 ord_data[loop].index,
3968 ord_data[loop].desc);
3970 len += sprintf(buf + len, "[0x%02X] = 0x%08X %s\n",
3971 ord_data[loop].index, val,
3972 ord_data[loop].desc);
3979 static DEVICE_ATTR(ordinals, 0444, show_ordinals, NULL);
3981 static ssize_t show_stats(struct device *d, struct device_attribute *attr,
3984 struct ipw2100_priv *priv = dev_get_drvdata(d);
3987 out += sprintf(out, "interrupts: %d {tx: %d, rx: %d, other: %d}\n",
3988 priv->interrupts, priv->tx_interrupts,
3989 priv->rx_interrupts, priv->inta_other);
3990 out += sprintf(out, "firmware resets: %d\n", priv->resets);
3991 out += sprintf(out, "firmware hangs: %d\n", priv->hangs);
3992 #ifdef CONFIG_IPW2100_DEBUG
3993 out += sprintf(out, "packet mismatch image: %s\n",
3994 priv->snapshot[0] ? "YES" : "NO");
4000 static DEVICE_ATTR(stats, 0444, show_stats, NULL);
4002 static int ipw2100_switch_mode(struct ipw2100_priv *priv, u32 mode)
4006 if (mode == priv->ieee->iw_mode)
4009 err = ipw2100_disable_adapter(priv);
4011 printk(KERN_ERR DRV_NAME ": %s: Could not disable adapter %d\n",
4012 priv->net_dev->name, err);
4018 priv->net_dev->type = ARPHRD_ETHER;
4021 priv->net_dev->type = ARPHRD_ETHER;
4023 #ifdef CONFIG_IPW2100_MONITOR
4024 case IW_MODE_MONITOR:
4025 priv->last_mode = priv->ieee->iw_mode;
4026 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
4028 #endif /* CONFIG_IPW2100_MONITOR */
4031 priv->ieee->iw_mode = mode;
4034 /* Indicate ipw2100_download_firmware download firmware
4035 * from disk instead of memory. */
4036 ipw2100_firmware.version = 0;
4039 printk(KERN_INFO "%s: Resetting on mode change.\n", priv->net_dev->name);
4040 priv->reset_backoff = 0;
4041 schedule_reset(priv);
4046 static ssize_t show_internals(struct device *d, struct device_attribute *attr,
4049 struct ipw2100_priv *priv = dev_get_drvdata(d);
4052 #define DUMP_VAR(x,y) len += sprintf(buf + len, # x ": %" y "\n", priv-> x)
4054 if (priv->status & STATUS_ASSOCIATED)
4055 len += sprintf(buf + len, "connected: %llu\n",
4056 ktime_get_boottime_seconds() - priv->connect_start);
4058 len += sprintf(buf + len, "not connected\n");
4060 DUMP_VAR(ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx], "p");
4061 DUMP_VAR(status, "08lx");
4062 DUMP_VAR(config, "08lx");
4063 DUMP_VAR(capability, "08lx");
4066 sprintf(buf + len, "last_rtc: %lu\n",
4067 (unsigned long)priv->last_rtc);
4069 DUMP_VAR(fatal_error, "d");
4070 DUMP_VAR(stop_hang_check, "d");
4071 DUMP_VAR(stop_rf_kill, "d");
4072 DUMP_VAR(messages_sent, "d");
4074 DUMP_VAR(tx_pend_stat.value, "d");
4075 DUMP_VAR(tx_pend_stat.hi, "d");
4077 DUMP_VAR(tx_free_stat.value, "d");
4078 DUMP_VAR(tx_free_stat.lo, "d");
4080 DUMP_VAR(msg_free_stat.value, "d");
4081 DUMP_VAR(msg_free_stat.lo, "d");
4083 DUMP_VAR(msg_pend_stat.value, "d");
4084 DUMP_VAR(msg_pend_stat.hi, "d");
4086 DUMP_VAR(fw_pend_stat.value, "d");
4087 DUMP_VAR(fw_pend_stat.hi, "d");
4089 DUMP_VAR(txq_stat.value, "d");
4090 DUMP_VAR(txq_stat.lo, "d");
4092 DUMP_VAR(ieee->scans, "d");
4093 DUMP_VAR(reset_backoff, "lld");
4098 static DEVICE_ATTR(internals, 0444, show_internals, NULL);
4100 static ssize_t show_bssinfo(struct device *d, struct device_attribute *attr,
4103 struct ipw2100_priv *priv = dev_get_drvdata(d);
4104 char essid[IW_ESSID_MAX_SIZE + 1];
4108 unsigned int length;
4111 if (priv->status & STATUS_RF_KILL_MASK)
4114 memset(essid, 0, sizeof(essid));
4115 memset(bssid, 0, sizeof(bssid));
4117 length = IW_ESSID_MAX_SIZE;
4118 ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_SSID, essid, &length);
4120 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
4123 length = sizeof(bssid);
4124 ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID,
4127 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
4130 length = sizeof(u32);
4131 ret = ipw2100_get_ordinal(priv, IPW_ORD_OUR_FREQ, &chan, &length);
4133 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
4136 out += sprintf(out, "ESSID: %s\n", essid);
4137 out += sprintf(out, "BSSID: %pM\n", bssid);
4138 out += sprintf(out, "Channel: %d\n", chan);
4143 static DEVICE_ATTR(bssinfo, 0444, show_bssinfo, NULL);
4145 #ifdef CONFIG_IPW2100_DEBUG
4146 static ssize_t debug_level_show(struct device_driver *d, char *buf)
4148 return sprintf(buf, "0x%08X\n", ipw2100_debug_level);
4151 static ssize_t debug_level_store(struct device_driver *d,
4152 const char *buf, size_t count)
4157 ret = kstrtou32(buf, 0, &val);
4159 IPW_DEBUG_INFO(": %s is not in hex or decimal form.\n", buf);
4161 ipw2100_debug_level = val;
4163 return strnlen(buf, count);
4165 static DRIVER_ATTR_RW(debug_level);
4166 #endif /* CONFIG_IPW2100_DEBUG */
4168 static ssize_t show_fatal_error(struct device *d,
4169 struct device_attribute *attr, char *buf)
4171 struct ipw2100_priv *priv = dev_get_drvdata(d);
4175 if (priv->fatal_error)
4176 out += sprintf(out, "0x%08X\n", priv->fatal_error);
4178 out += sprintf(out, "0\n");
4180 for (i = 1; i <= IPW2100_ERROR_QUEUE; i++) {
4181 if (!priv->fatal_errors[(priv->fatal_index - i) %
4182 IPW2100_ERROR_QUEUE])
4185 out += sprintf(out, "%d. 0x%08X\n", i,
4186 priv->fatal_errors[(priv->fatal_index - i) %
4187 IPW2100_ERROR_QUEUE]);
4193 static ssize_t store_fatal_error(struct device *d,
4194 struct device_attribute *attr, const char *buf,
4197 struct ipw2100_priv *priv = dev_get_drvdata(d);
4198 schedule_reset(priv);
4202 static DEVICE_ATTR(fatal_error, 0644, show_fatal_error, store_fatal_error);
4204 static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
4207 struct ipw2100_priv *priv = dev_get_drvdata(d);
4208 return sprintf(buf, "%d\n", priv->ieee->scan_age);
4211 static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
4212 const char *buf, size_t count)
4214 struct ipw2100_priv *priv = dev_get_drvdata(d);
4215 struct net_device *dev = priv->net_dev;
4219 (void)dev; /* kill unused-var warning for debug-only code */
4221 IPW_DEBUG_INFO("enter\n");
4223 ret = kstrtoul(buf, 0, &val);
4225 IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
4227 priv->ieee->scan_age = val;
4228 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
4231 IPW_DEBUG_INFO("exit\n");
4232 return strnlen(buf, count);
4235 static DEVICE_ATTR(scan_age, 0644, show_scan_age, store_scan_age);
4237 static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
4240 /* 0 - RF kill not enabled
4241 1 - SW based RF kill active (sysfs)
4242 2 - HW based RF kill active
4243 3 - Both HW and SW baed RF kill active */
4244 struct ipw2100_priv *priv = dev_get_drvdata(d);
4245 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
4246 (rf_kill_active(priv) ? 0x2 : 0x0);
4247 return sprintf(buf, "%i\n", val);
4250 static int ipw_radio_kill_sw(struct ipw2100_priv *priv, int disable_radio)
4252 if ((disable_radio ? 1 : 0) ==
4253 (priv->status & STATUS_RF_KILL_SW ? 1 : 0))
4256 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
4257 disable_radio ? "OFF" : "ON");
4259 mutex_lock(&priv->action_mutex);
4261 if (disable_radio) {
4262 priv->status |= STATUS_RF_KILL_SW;
4265 priv->status &= ~STATUS_RF_KILL_SW;
4266 if (rf_kill_active(priv)) {
4267 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
4268 "disabled by HW switch\n");
4269 /* Make sure the RF_KILL check timer is running */
4270 priv->stop_rf_kill = 0;
4271 mod_delayed_work(system_wq, &priv->rf_kill,
4272 round_jiffies_relative(HZ));
4274 schedule_reset(priv);
4277 mutex_unlock(&priv->action_mutex);
4281 static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
4282 const char *buf, size_t count)
4284 struct ipw2100_priv *priv = dev_get_drvdata(d);
4285 ipw_radio_kill_sw(priv, buf[0] == '1');
4289 static DEVICE_ATTR(rf_kill, 0644, show_rf_kill, store_rf_kill);
4291 static struct attribute *ipw2100_sysfs_entries[] = {
4292 &dev_attr_hardware.attr,
4293 &dev_attr_registers.attr,
4294 &dev_attr_ordinals.attr,
4296 &dev_attr_stats.attr,
4297 &dev_attr_internals.attr,
4298 &dev_attr_bssinfo.attr,
4299 &dev_attr_memory.attr,
4300 &dev_attr_scan_age.attr,
4301 &dev_attr_fatal_error.attr,
4302 &dev_attr_rf_kill.attr,
4304 &dev_attr_status.attr,
4305 &dev_attr_capability.attr,
4309 static const struct attribute_group ipw2100_attribute_group = {
4310 .attrs = ipw2100_sysfs_entries,
4313 static int status_queue_allocate(struct ipw2100_priv *priv, int entries)
4315 struct ipw2100_status_queue *q = &priv->status_queue;
4317 IPW_DEBUG_INFO("enter\n");
4319 q->size = entries * sizeof(struct ipw2100_status);
4320 q->drv = dma_alloc_coherent(&priv->pci_dev->dev, q->size, &q->nic,
4323 IPW_DEBUG_WARNING("Can not allocate status queue.\n");
4327 IPW_DEBUG_INFO("exit\n");
4332 static void status_queue_free(struct ipw2100_priv *priv)
4334 IPW_DEBUG_INFO("enter\n");
4336 if (priv->status_queue.drv) {
4337 dma_free_coherent(&priv->pci_dev->dev,
4338 priv->status_queue.size,
4339 priv->status_queue.drv,
4340 priv->status_queue.nic);
4341 priv->status_queue.drv = NULL;
4344 IPW_DEBUG_INFO("exit\n");
4347 static int bd_queue_allocate(struct ipw2100_priv *priv,
4348 struct ipw2100_bd_queue *q, int entries)
4350 IPW_DEBUG_INFO("enter\n");
4352 memset(q, 0, sizeof(struct ipw2100_bd_queue));
4354 q->entries = entries;
4355 q->size = entries * sizeof(struct ipw2100_bd);
4356 q->drv = dma_alloc_coherent(&priv->pci_dev->dev, q->size, &q->nic,
4360 ("can't allocate shared memory for buffer descriptors\n");
4364 IPW_DEBUG_INFO("exit\n");
4369 static void bd_queue_free(struct ipw2100_priv *priv, struct ipw2100_bd_queue *q)
4371 IPW_DEBUG_INFO("enter\n");
4377 dma_free_coherent(&priv->pci_dev->dev, q->size, q->drv,
4382 IPW_DEBUG_INFO("exit\n");
4385 static void bd_queue_initialize(struct ipw2100_priv *priv,
4386 struct ipw2100_bd_queue *q, u32 base, u32 size,
4389 IPW_DEBUG_INFO("enter\n");
4391 IPW_DEBUG_INFO("initializing bd queue at virt=%p, phys=%08x\n", q->drv,
4394 write_register(priv->net_dev, base, q->nic);
4395 write_register(priv->net_dev, size, q->entries);
4396 write_register(priv->net_dev, r, q->oldest);
4397 write_register(priv->net_dev, w, q->next);
4399 IPW_DEBUG_INFO("exit\n");
4402 static void ipw2100_kill_works(struct ipw2100_priv *priv)
4404 priv->stop_rf_kill = 1;
4405 priv->stop_hang_check = 1;
4406 cancel_delayed_work_sync(&priv->reset_work);
4407 cancel_delayed_work_sync(&priv->security_work);
4408 cancel_delayed_work_sync(&priv->wx_event_work);
4409 cancel_delayed_work_sync(&priv->hang_check);
4410 cancel_delayed_work_sync(&priv->rf_kill);
4411 cancel_delayed_work_sync(&priv->scan_event);
4414 static int ipw2100_tx_allocate(struct ipw2100_priv *priv)
4420 IPW_DEBUG_INFO("enter\n");
4422 err = bd_queue_allocate(priv, &priv->tx_queue, TX_QUEUE_LENGTH);
4424 IPW_DEBUG_ERROR("%s: failed bd_queue_allocate\n",
4425 priv->net_dev->name);
4429 priv->tx_buffers = kmalloc_array(TX_PENDED_QUEUE_LENGTH,
4430 sizeof(struct ipw2100_tx_packet),
4432 if (!priv->tx_buffers) {
4433 bd_queue_free(priv, &priv->tx_queue);
4437 for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
4438 v = dma_alloc_coherent(&priv->pci_dev->dev,
4439 sizeof(struct ipw2100_data_header), &p,
4442 printk(KERN_ERR DRV_NAME
4443 ": %s: PCI alloc failed for tx " "buffers.\n",
4444 priv->net_dev->name);
4449 priv->tx_buffers[i].type = DATA;
4450 priv->tx_buffers[i].info.d_struct.data =
4451 (struct ipw2100_data_header *)v;
4452 priv->tx_buffers[i].info.d_struct.data_phys = p;
4453 priv->tx_buffers[i].info.d_struct.txb = NULL;
4456 if (i == TX_PENDED_QUEUE_LENGTH)
4459 for (j = 0; j < i; j++) {
4460 dma_free_coherent(&priv->pci_dev->dev,
4461 sizeof(struct ipw2100_data_header),
4462 priv->tx_buffers[j].info.d_struct.data,
4463 priv->tx_buffers[j].info.d_struct.data_phys);
4466 kfree(priv->tx_buffers);
4467 priv->tx_buffers = NULL;
4472 static void ipw2100_tx_initialize(struct ipw2100_priv *priv)
4476 IPW_DEBUG_INFO("enter\n");
4479 * reinitialize packet info lists
4481 INIT_LIST_HEAD(&priv->fw_pend_list);
4482 INIT_STAT(&priv->fw_pend_stat);
4485 * reinitialize lists
4487 INIT_LIST_HEAD(&priv->tx_pend_list);
4488 INIT_LIST_HEAD(&priv->tx_free_list);
4489 INIT_STAT(&priv->tx_pend_stat);
4490 INIT_STAT(&priv->tx_free_stat);
4492 for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
4493 /* We simply drop any SKBs that have been queued for
4495 if (priv->tx_buffers[i].info.d_struct.txb) {
4496 libipw_txb_free(priv->tx_buffers[i].info.d_struct.
4498 priv->tx_buffers[i].info.d_struct.txb = NULL;
4501 list_add_tail(&priv->tx_buffers[i].list, &priv->tx_free_list);
4504 SET_STAT(&priv->tx_free_stat, i);
4506 priv->tx_queue.oldest = 0;
4507 priv->tx_queue.available = priv->tx_queue.entries;
4508 priv->tx_queue.next = 0;
4509 INIT_STAT(&priv->txq_stat);
4510 SET_STAT(&priv->txq_stat, priv->tx_queue.available);
4512 bd_queue_initialize(priv, &priv->tx_queue,
4513 IPW_MEM_HOST_SHARED_TX_QUEUE_BD_BASE,
4514 IPW_MEM_HOST_SHARED_TX_QUEUE_BD_SIZE,
4515 IPW_MEM_HOST_SHARED_TX_QUEUE_READ_INDEX,
4516 IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX);
4518 IPW_DEBUG_INFO("exit\n");
4522 static void ipw2100_tx_free(struct ipw2100_priv *priv)
4526 IPW_DEBUG_INFO("enter\n");
4528 bd_queue_free(priv, &priv->tx_queue);
4530 if (!priv->tx_buffers)
4533 for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
4534 if (priv->tx_buffers[i].info.d_struct.txb) {
4535 libipw_txb_free(priv->tx_buffers[i].info.d_struct.
4537 priv->tx_buffers[i].info.d_struct.txb = NULL;
4539 if (priv->tx_buffers[i].info.d_struct.data)
4540 dma_free_coherent(&priv->pci_dev->dev,
4541 sizeof(struct ipw2100_data_header),
4542 priv->tx_buffers[i].info.d_struct.data,
4543 priv->tx_buffers[i].info.d_struct.data_phys);
4546 kfree(priv->tx_buffers);
4547 priv->tx_buffers = NULL;
4549 IPW_DEBUG_INFO("exit\n");
4552 static int ipw2100_rx_allocate(struct ipw2100_priv *priv)
4554 int i, j, err = -EINVAL;
4556 IPW_DEBUG_INFO("enter\n");
4558 err = bd_queue_allocate(priv, &priv->rx_queue, RX_QUEUE_LENGTH);
4560 IPW_DEBUG_INFO("failed bd_queue_allocate\n");
4564 err = status_queue_allocate(priv, RX_QUEUE_LENGTH);
4566 IPW_DEBUG_INFO("failed status_queue_allocate\n");
4567 bd_queue_free(priv, &priv->rx_queue);
4574 priv->rx_buffers = kmalloc_array(RX_QUEUE_LENGTH,
4575 sizeof(struct ipw2100_rx_packet),
4577 if (!priv->rx_buffers) {
4578 IPW_DEBUG_INFO("can't allocate rx packet buffer table\n");
4580 bd_queue_free(priv, &priv->rx_queue);
4582 status_queue_free(priv);
4587 for (i = 0; i < RX_QUEUE_LENGTH; i++) {
4588 struct ipw2100_rx_packet *packet = &priv->rx_buffers[i];
4590 err = ipw2100_alloc_skb(priv, packet);
4591 if (unlikely(err)) {
4596 /* The BD holds the cache aligned address */
4597 priv->rx_queue.drv[i].host_addr = packet->dma_addr;
4598 priv->rx_queue.drv[i].buf_length = IPW_RX_NIC_BUFFER_LENGTH;
4599 priv->status_queue.drv[i].status_fields = 0;
4602 if (i == RX_QUEUE_LENGTH)
4605 for (j = 0; j < i; j++) {
4606 dma_unmap_single(&priv->pci_dev->dev,
4607 priv->rx_buffers[j].dma_addr,
4608 sizeof(struct ipw2100_rx_packet),
4610 dev_kfree_skb(priv->rx_buffers[j].skb);
4613 kfree(priv->rx_buffers);
4614 priv->rx_buffers = NULL;
4616 bd_queue_free(priv, &priv->rx_queue);
4618 status_queue_free(priv);
4623 static void ipw2100_rx_initialize(struct ipw2100_priv *priv)
4625 IPW_DEBUG_INFO("enter\n");
4627 priv->rx_queue.oldest = 0;
4628 priv->rx_queue.available = priv->rx_queue.entries - 1;
4629 priv->rx_queue.next = priv->rx_queue.entries - 1;
4631 INIT_STAT(&priv->rxq_stat);
4632 SET_STAT(&priv->rxq_stat, priv->rx_queue.available);
4634 bd_queue_initialize(priv, &priv->rx_queue,
4635 IPW_MEM_HOST_SHARED_RX_BD_BASE,
4636 IPW_MEM_HOST_SHARED_RX_BD_SIZE,
4637 IPW_MEM_HOST_SHARED_RX_READ_INDEX,
4638 IPW_MEM_HOST_SHARED_RX_WRITE_INDEX);
4640 /* set up the status queue */
4641 write_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_STATUS_BASE,
4642 priv->status_queue.nic);
4644 IPW_DEBUG_INFO("exit\n");
4647 static void ipw2100_rx_free(struct ipw2100_priv *priv)
4651 IPW_DEBUG_INFO("enter\n");
4653 bd_queue_free(priv, &priv->rx_queue);
4654 status_queue_free(priv);
4656 if (!priv->rx_buffers)
4659 for (i = 0; i < RX_QUEUE_LENGTH; i++) {
4660 if (priv->rx_buffers[i].rxp) {
4661 dma_unmap_single(&priv->pci_dev->dev,
4662 priv->rx_buffers[i].dma_addr,
4663 sizeof(struct ipw2100_rx),
4665 dev_kfree_skb(priv->rx_buffers[i].skb);
4669 kfree(priv->rx_buffers);
4670 priv->rx_buffers = NULL;
4672 IPW_DEBUG_INFO("exit\n");
4675 static int ipw2100_read_mac_address(struct ipw2100_priv *priv)
4677 u32 length = ETH_ALEN;
4682 err = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ADAPTER_MAC, addr, &length);
4684 IPW_DEBUG_INFO("MAC address read failed\n");
4688 memcpy(priv->net_dev->dev_addr, addr, ETH_ALEN);
4689 IPW_DEBUG_INFO("card MAC is %pM\n", priv->net_dev->dev_addr);
4694 /********************************************************************
4698 ********************************************************************/
4700 static int ipw2100_set_mac_address(struct ipw2100_priv *priv, int batch_mode)
4702 struct host_command cmd = {
4703 .host_command = ADAPTER_ADDRESS,
4704 .host_command_sequence = 0,
4705 .host_command_length = ETH_ALEN
4709 IPW_DEBUG_HC("SET_MAC_ADDRESS\n");
4711 IPW_DEBUG_INFO("enter\n");
4713 if (priv->config & CFG_CUSTOM_MAC) {
4714 memcpy(cmd.host_command_parameters, priv->mac_addr, ETH_ALEN);
4715 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
4717 memcpy(cmd.host_command_parameters, priv->net_dev->dev_addr,
4720 err = ipw2100_hw_send_command(priv, &cmd);
4722 IPW_DEBUG_INFO("exit\n");
4726 static int ipw2100_set_port_type(struct ipw2100_priv *priv, u32 port_type,
4729 struct host_command cmd = {
4730 .host_command = PORT_TYPE,
4731 .host_command_sequence = 0,
4732 .host_command_length = sizeof(u32)
4736 switch (port_type) {
4738 cmd.host_command_parameters[0] = IPW_BSS;
4741 cmd.host_command_parameters[0] = IPW_IBSS;
4745 IPW_DEBUG_HC("PORT_TYPE: %s\n",
4746 port_type == IPW_IBSS ? "Ad-Hoc" : "Managed");
4749 err = ipw2100_disable_adapter(priv);
4751 printk(KERN_ERR DRV_NAME
4752 ": %s: Could not disable adapter %d\n",
4753 priv->net_dev->name, err);
4758 /* send cmd to firmware */
4759 err = ipw2100_hw_send_command(priv, &cmd);
4762 ipw2100_enable_adapter(priv);
4767 static int ipw2100_set_channel(struct ipw2100_priv *priv, u32 channel,
4770 struct host_command cmd = {
4771 .host_command = CHANNEL,
4772 .host_command_sequence = 0,
4773 .host_command_length = sizeof(u32)
4777 cmd.host_command_parameters[0] = channel;
4779 IPW_DEBUG_HC("CHANNEL: %d\n", channel);
4781 /* If BSS then we don't support channel selection */
4782 if (priv->ieee->iw_mode == IW_MODE_INFRA)
4785 if ((channel != 0) &&
4786 ((channel < REG_MIN_CHANNEL) || (channel > REG_MAX_CHANNEL)))
4790 err = ipw2100_disable_adapter(priv);
4795 err = ipw2100_hw_send_command(priv, &cmd);
4797 IPW_DEBUG_INFO("Failed to set channel to %d", channel);
4802 priv->config |= CFG_STATIC_CHANNEL;
4804 priv->config &= ~CFG_STATIC_CHANNEL;
4806 priv->channel = channel;
4809 err = ipw2100_enable_adapter(priv);
4817 static int ipw2100_system_config(struct ipw2100_priv *priv, int batch_mode)
4819 struct host_command cmd = {
4820 .host_command = SYSTEM_CONFIG,
4821 .host_command_sequence = 0,
4822 .host_command_length = 12,
4824 u32 ibss_mask, len = sizeof(u32);
4827 /* Set system configuration */
4830 err = ipw2100_disable_adapter(priv);
4835 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
4836 cmd.host_command_parameters[0] |= IPW_CFG_IBSS_AUTO_START;
4838 cmd.host_command_parameters[0] |= IPW_CFG_IBSS_MASK |
4839 IPW_CFG_BSS_MASK | IPW_CFG_802_1x_ENABLE;
4841 if (!(priv->config & CFG_LONG_PREAMBLE))
4842 cmd.host_command_parameters[0] |= IPW_CFG_PREAMBLE_AUTO;
4844 err = ipw2100_get_ordinal(priv,
4845 IPW_ORD_EEPROM_IBSS_11B_CHANNELS,
4848 ibss_mask = IPW_IBSS_11B_DEFAULT_MASK;
4850 cmd.host_command_parameters[1] = REG_CHANNEL_MASK;
4851 cmd.host_command_parameters[2] = REG_CHANNEL_MASK & ibss_mask;
4854 /*cmd.host_command_parameters[0] |= DIVERSITY_ANTENNA_A; */
4856 err = ipw2100_hw_send_command(priv, &cmd);
4860 /* If IPv6 is configured in the kernel then we don't want to filter out all
4861 * of the multicast packets as IPv6 needs some. */
4862 #if !defined(CONFIG_IPV6) && !defined(CONFIG_IPV6_MODULE)
4863 cmd.host_command = ADD_MULTICAST;
4864 cmd.host_command_sequence = 0;
4865 cmd.host_command_length = 0;
4867 ipw2100_hw_send_command(priv, &cmd);
4870 err = ipw2100_enable_adapter(priv);
4878 static int ipw2100_set_tx_rates(struct ipw2100_priv *priv, u32 rate,
4881 struct host_command cmd = {
4882 .host_command = BASIC_TX_RATES,
4883 .host_command_sequence = 0,
4884 .host_command_length = 4
4888 cmd.host_command_parameters[0] = rate & TX_RATE_MASK;
4891 err = ipw2100_disable_adapter(priv);
4896 /* Set BASIC TX Rate first */
4897 ipw2100_hw_send_command(priv, &cmd);
4900 cmd.host_command = TX_RATES;
4901 ipw2100_hw_send_command(priv, &cmd);
4903 /* Set MSDU TX Rate */
4904 cmd.host_command = MSDU_TX_RATES;
4905 ipw2100_hw_send_command(priv, &cmd);
4908 err = ipw2100_enable_adapter(priv);
4913 priv->tx_rates = rate;
4918 static int ipw2100_set_power_mode(struct ipw2100_priv *priv, int power_level)
4920 struct host_command cmd = {
4921 .host_command = POWER_MODE,
4922 .host_command_sequence = 0,
4923 .host_command_length = 4
4927 cmd.host_command_parameters[0] = power_level;
4929 err = ipw2100_hw_send_command(priv, &cmd);
4933 if (power_level == IPW_POWER_MODE_CAM)
4934 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
4936 priv->power_mode = IPW_POWER_ENABLED | power_level;
4938 #ifdef IPW2100_TX_POWER
4939 if (priv->port_type == IBSS && priv->adhoc_power != DFTL_IBSS_TX_POWER) {
4940 /* Set beacon interval */
4941 cmd.host_command = TX_POWER_INDEX;
4942 cmd.host_command_parameters[0] = (u32) priv->adhoc_power;
4944 err = ipw2100_hw_send_command(priv, &cmd);
4953 static int ipw2100_set_rts_threshold(struct ipw2100_priv *priv, u32 threshold)
4955 struct host_command cmd = {
4956 .host_command = RTS_THRESHOLD,
4957 .host_command_sequence = 0,
4958 .host_command_length = 4
4962 if (threshold & RTS_DISABLED)
4963 cmd.host_command_parameters[0] = MAX_RTS_THRESHOLD;
4965 cmd.host_command_parameters[0] = threshold & ~RTS_DISABLED;
4967 err = ipw2100_hw_send_command(priv, &cmd);
4971 priv->rts_threshold = threshold;
4977 int ipw2100_set_fragmentation_threshold(struct ipw2100_priv *priv,
4978 u32 threshold, int batch_mode)
4980 struct host_command cmd = {
4981 .host_command = FRAG_THRESHOLD,
4982 .host_command_sequence = 0,
4983 .host_command_length = 4,
4984 .host_command_parameters[0] = 0,
4989 err = ipw2100_disable_adapter(priv);
4995 threshold = DEFAULT_FRAG_THRESHOLD;
4997 threshold = max(threshold, MIN_FRAG_THRESHOLD);
4998 threshold = min(threshold, MAX_FRAG_THRESHOLD);
5001 cmd.host_command_parameters[0] = threshold;
5003 IPW_DEBUG_HC("FRAG_THRESHOLD: %u\n", threshold);
5005 err = ipw2100_hw_send_command(priv, &cmd);
5008 ipw2100_enable_adapter(priv);
5011 priv->frag_threshold = threshold;
5017 static int ipw2100_set_short_retry(struct ipw2100_priv *priv, u32 retry)
5019 struct host_command cmd = {
5020 .host_command = SHORT_RETRY_LIMIT,
5021 .host_command_sequence = 0,
5022 .host_command_length = 4
5026 cmd.host_command_parameters[0] = retry;
5028 err = ipw2100_hw_send_command(priv, &cmd);
5032 priv->short_retry_limit = retry;
5037 static int ipw2100_set_long_retry(struct ipw2100_priv *priv, u32 retry)
5039 struct host_command cmd = {
5040 .host_command = LONG_RETRY_LIMIT,
5041 .host_command_sequence = 0,
5042 .host_command_length = 4
5046 cmd.host_command_parameters[0] = retry;
5048 err = ipw2100_hw_send_command(priv, &cmd);
5052 priv->long_retry_limit = retry;
5057 static int ipw2100_set_mandatory_bssid(struct ipw2100_priv *priv, u8 * bssid,
5060 struct host_command cmd = {
5061 .host_command = MANDATORY_BSSID,
5062 .host_command_sequence = 0,
5063 .host_command_length = (bssid == NULL) ? 0 : ETH_ALEN
5067 #ifdef CONFIG_IPW2100_DEBUG
5069 IPW_DEBUG_HC("MANDATORY_BSSID: %pM\n", bssid);
5071 IPW_DEBUG_HC("MANDATORY_BSSID: <clear>\n");
5073 /* if BSSID is empty then we disable mandatory bssid mode */
5075 memcpy(cmd.host_command_parameters, bssid, ETH_ALEN);
5078 err = ipw2100_disable_adapter(priv);
5083 err = ipw2100_hw_send_command(priv, &cmd);
5086 ipw2100_enable_adapter(priv);
5091 static int ipw2100_disassociate_bssid(struct ipw2100_priv *priv)
5093 struct host_command cmd = {
5094 .host_command = DISASSOCIATION_BSSID,
5095 .host_command_sequence = 0,
5096 .host_command_length = ETH_ALEN
5100 IPW_DEBUG_HC("DISASSOCIATION_BSSID\n");
5102 /* The Firmware currently ignores the BSSID and just disassociates from
5103 * the currently associated AP -- but in the off chance that a future
5104 * firmware does use the BSSID provided here, we go ahead and try and
5105 * set it to the currently associated AP's BSSID */
5106 memcpy(cmd.host_command_parameters, priv->bssid, ETH_ALEN);
5108 err = ipw2100_hw_send_command(priv, &cmd);
5113 static int ipw2100_set_wpa_ie(struct ipw2100_priv *,
5114 struct ipw2100_wpa_assoc_frame *, int)
5115 __attribute__ ((unused));
5117 static int ipw2100_set_wpa_ie(struct ipw2100_priv *priv,
5118 struct ipw2100_wpa_assoc_frame *wpa_frame,
5121 struct host_command cmd = {
5122 .host_command = SET_WPA_IE,
5123 .host_command_sequence = 0,
5124 .host_command_length = sizeof(struct ipw2100_wpa_assoc_frame),
5128 IPW_DEBUG_HC("SET_WPA_IE\n");
5131 err = ipw2100_disable_adapter(priv);
5136 memcpy(cmd.host_command_parameters, wpa_frame,
5137 sizeof(struct ipw2100_wpa_assoc_frame));
5139 err = ipw2100_hw_send_command(priv, &cmd);
5142 if (ipw2100_enable_adapter(priv))
5149 struct security_info_params {
5150 u32 allowed_ciphers;
5153 u8 replay_counters_number;
5154 u8 unicast_using_group;
5157 static int ipw2100_set_security_information(struct ipw2100_priv *priv,
5160 int unicast_using_group,
5163 struct host_command cmd = {
5164 .host_command = SET_SECURITY_INFORMATION,
5165 .host_command_sequence = 0,
5166 .host_command_length = sizeof(struct security_info_params)
5168 struct security_info_params *security =
5169 (struct security_info_params *)&cmd.host_command_parameters;
5171 memset(security, 0, sizeof(*security));
5173 /* If shared key AP authentication is turned on, then we need to
5174 * configure the firmware to try and use it.
5176 * Actual data encryption/decryption is handled by the host. */
5177 security->auth_mode = auth_mode;
5178 security->unicast_using_group = unicast_using_group;
5180 switch (security_level) {
5183 security->allowed_ciphers = IPW_NONE_CIPHER;
5186 security->allowed_ciphers = IPW_WEP40_CIPHER |
5190 security->allowed_ciphers = IPW_WEP40_CIPHER |
5191 IPW_WEP104_CIPHER | IPW_TKIP_CIPHER;
5193 case SEC_LEVEL_2_CKIP:
5194 security->allowed_ciphers = IPW_WEP40_CIPHER |
5195 IPW_WEP104_CIPHER | IPW_CKIP_CIPHER;
5198 security->allowed_ciphers = IPW_WEP40_CIPHER |
5199 IPW_WEP104_CIPHER | IPW_TKIP_CIPHER | IPW_CCMP_CIPHER;
5204 ("SET_SECURITY_INFORMATION: auth:%d cipher:0x%02X (level %d)\n",
5205 security->auth_mode, security->allowed_ciphers, security_level);
5207 security->replay_counters_number = 0;
5210 err = ipw2100_disable_adapter(priv);
5215 err = ipw2100_hw_send_command(priv, &cmd);
5218 ipw2100_enable_adapter(priv);
5223 static int ipw2100_set_tx_power(struct ipw2100_priv *priv, u32 tx_power)
5225 struct host_command cmd = {
5226 .host_command = TX_POWER_INDEX,
5227 .host_command_sequence = 0,
5228 .host_command_length = 4
5233 if (tx_power != IPW_TX_POWER_DEFAULT)
5234 tmp = (tx_power - IPW_TX_POWER_MIN_DBM) * 16 /
5235 (IPW_TX_POWER_MAX_DBM - IPW_TX_POWER_MIN_DBM);
5237 cmd.host_command_parameters[0] = tmp;
5239 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
5240 err = ipw2100_hw_send_command(priv, &cmd);
5242 priv->tx_power = tx_power;
5247 static int ipw2100_set_ibss_beacon_interval(struct ipw2100_priv *priv,
5248 u32 interval, int batch_mode)
5250 struct host_command cmd = {
5251 .host_command = BEACON_INTERVAL,
5252 .host_command_sequence = 0,
5253 .host_command_length = 4
5257 cmd.host_command_parameters[0] = interval;
5259 IPW_DEBUG_INFO("enter\n");
5261 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
5263 err = ipw2100_disable_adapter(priv);
5268 ipw2100_hw_send_command(priv, &cmd);
5271 err = ipw2100_enable_adapter(priv);
5277 IPW_DEBUG_INFO("exit\n");
5282 static void ipw2100_queues_initialize(struct ipw2100_priv *priv)
5284 ipw2100_tx_initialize(priv);
5285 ipw2100_rx_initialize(priv);
5286 ipw2100_msg_initialize(priv);
5289 static void ipw2100_queues_free(struct ipw2100_priv *priv)
5291 ipw2100_tx_free(priv);
5292 ipw2100_rx_free(priv);
5293 ipw2100_msg_free(priv);
5296 static int ipw2100_queues_allocate(struct ipw2100_priv *priv)
5298 if (ipw2100_tx_allocate(priv) ||
5299 ipw2100_rx_allocate(priv) || ipw2100_msg_allocate(priv))
5305 ipw2100_tx_free(priv);
5306 ipw2100_rx_free(priv);
5307 ipw2100_msg_free(priv);
5311 #define IPW_PRIVACY_CAPABLE 0x0008
5313 static int ipw2100_set_wep_flags(struct ipw2100_priv *priv, u32 flags,
5316 struct host_command cmd = {
5317 .host_command = WEP_FLAGS,
5318 .host_command_sequence = 0,
5319 .host_command_length = 4
5323 cmd.host_command_parameters[0] = flags;
5325 IPW_DEBUG_HC("WEP_FLAGS: flags = 0x%08X\n", flags);
5328 err = ipw2100_disable_adapter(priv);
5330 printk(KERN_ERR DRV_NAME
5331 ": %s: Could not disable adapter %d\n",
5332 priv->net_dev->name, err);
5337 /* send cmd to firmware */
5338 err = ipw2100_hw_send_command(priv, &cmd);
5341 ipw2100_enable_adapter(priv);
5346 struct ipw2100_wep_key {
5352 /* Macros to ease up priting WEP keys */
5353 #define WEP_FMT_64 "%02X%02X%02X%02X-%02X"
5354 #define WEP_FMT_128 "%02X%02X%02X%02X-%02X%02X%02X%02X-%02X%02X%02X"
5355 #define WEP_STR_64(x) x[0],x[1],x[2],x[3],x[4]
5356 #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]
5359 * ipw2100_set_key() - Set a the wep key
5361 * @priv: struct to work on
5362 * @idx: index of the key we want to set
5363 * @key: ptr to the key data to set
5364 * @len: length of the buffer at @key
5365 * @batch_mode: FIXME perform the operation in batch mode, not
5366 * disabling the device.
5368 * @returns 0 if OK, < 0 errno code on error.
5370 * Fill out a command structure with the new wep key, length an
5371 * index and send it down the wire.
5373 static int ipw2100_set_key(struct ipw2100_priv *priv,
5374 int idx, char *key, int len, int batch_mode)
5376 int keylen = len ? (len <= 5 ? 5 : 13) : 0;
5377 struct host_command cmd = {
5378 .host_command = WEP_KEY_INFO,
5379 .host_command_sequence = 0,
5380 .host_command_length = sizeof(struct ipw2100_wep_key),
5382 struct ipw2100_wep_key *wep_key = (void *)cmd.host_command_parameters;
5385 IPW_DEBUG_HC("WEP_KEY_INFO: index = %d, len = %d/%d\n",
5388 /* NOTE: We don't check cached values in case the firmware was reset
5389 * or some other problem is occurring. If the user is setting the key,
5390 * then we push the change */
5393 wep_key->len = keylen;
5396 memcpy(wep_key->key, key, len);
5397 memset(wep_key->key + len, 0, keylen - len);
5400 /* Will be optimized out on debug not being configured in */
5402 IPW_DEBUG_WEP("%s: Clearing key %d\n",
5403 priv->net_dev->name, wep_key->idx);
5404 else if (keylen == 5)
5405 IPW_DEBUG_WEP("%s: idx: %d, len: %d key: " WEP_FMT_64 "\n",
5406 priv->net_dev->name, wep_key->idx, wep_key->len,
5407 WEP_STR_64(wep_key->key));
5409 IPW_DEBUG_WEP("%s: idx: %d, len: %d key: " WEP_FMT_128
5411 priv->net_dev->name, wep_key->idx, wep_key->len,
5412 WEP_STR_128(wep_key->key));
5415 err = ipw2100_disable_adapter(priv);
5416 /* FIXME: IPG: shouldn't this prink be in _disable_adapter()? */
5418 printk(KERN_ERR DRV_NAME
5419 ": %s: Could not disable adapter %d\n",
5420 priv->net_dev->name, err);
5425 /* send cmd to firmware */
5426 err = ipw2100_hw_send_command(priv, &cmd);
5429 int err2 = ipw2100_enable_adapter(priv);
5436 static int ipw2100_set_key_index(struct ipw2100_priv *priv,
5437 int idx, int batch_mode)
5439 struct host_command cmd = {
5440 .host_command = WEP_KEY_INDEX,
5441 .host_command_sequence = 0,
5442 .host_command_length = 4,
5443 .host_command_parameters = {idx},
5447 IPW_DEBUG_HC("WEP_KEY_INDEX: index = %d\n", idx);
5449 if (idx < 0 || idx > 3)
5453 err = ipw2100_disable_adapter(priv);
5455 printk(KERN_ERR DRV_NAME
5456 ": %s: Could not disable adapter %d\n",
5457 priv->net_dev->name, err);
5462 /* send cmd to firmware */
5463 err = ipw2100_hw_send_command(priv, &cmd);
5466 ipw2100_enable_adapter(priv);
5471 static int ipw2100_configure_security(struct ipw2100_priv *priv, int batch_mode)
5473 int i, err, auth_mode, sec_level, use_group;
5475 if (!(priv->status & STATUS_RUNNING))
5479 err = ipw2100_disable_adapter(priv);
5484 if (!priv->ieee->sec.enabled) {
5486 ipw2100_set_security_information(priv, IPW_AUTH_OPEN,
5489 auth_mode = IPW_AUTH_OPEN;
5490 if (priv->ieee->sec.flags & SEC_AUTH_MODE) {
5491 if (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)
5492 auth_mode = IPW_AUTH_SHARED;
5493 else if (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP)
5494 auth_mode = IPW_AUTH_LEAP_CISCO_ID;
5497 sec_level = SEC_LEVEL_0;
5498 if (priv->ieee->sec.flags & SEC_LEVEL)
5499 sec_level = priv->ieee->sec.level;
5502 if (priv->ieee->sec.flags & SEC_UNICAST_GROUP)
5503 use_group = priv->ieee->sec.unicast_uses_group;
5506 ipw2100_set_security_information(priv, auth_mode, sec_level,
5513 if (priv->ieee->sec.enabled) {
5514 for (i = 0; i < 4; i++) {
5515 if (!(priv->ieee->sec.flags & (1 << i))) {
5516 memset(priv->ieee->sec.keys[i], 0, WEP_KEY_LEN);
5517 priv->ieee->sec.key_sizes[i] = 0;
5519 err = ipw2100_set_key(priv, i,
5520 priv->ieee->sec.keys[i],
5528 ipw2100_set_key_index(priv, priv->ieee->crypt_info.tx_keyidx, 1);
5531 /* Always enable privacy so the Host can filter WEP packets if
5532 * encrypted data is sent up */
5534 ipw2100_set_wep_flags(priv,
5536 enabled ? IPW_PRIVACY_CAPABLE : 0, 1);
5540 priv->status &= ~STATUS_SECURITY_UPDATED;
5544 ipw2100_enable_adapter(priv);
5549 static void ipw2100_security_work(struct work_struct *work)
5551 struct ipw2100_priv *priv =
5552 container_of(work, struct ipw2100_priv, security_work.work);
5554 /* If we happen to have reconnected before we get a chance to
5555 * process this, then update the security settings--which causes
5556 * a disassociation to occur */
5557 if (!(priv->status & STATUS_ASSOCIATED) &&
5558 priv->status & STATUS_SECURITY_UPDATED)
5559 ipw2100_configure_security(priv, 0);
5562 static void shim__set_security(struct net_device *dev,
5563 struct libipw_security *sec)
5565 struct ipw2100_priv *priv = libipw_priv(dev);
5568 mutex_lock(&priv->action_mutex);
5569 if (!(priv->status & STATUS_INITIALIZED))
5572 for (i = 0; i < 4; i++) {
5573 if (sec->flags & (1 << i)) {
5574 priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
5575 if (sec->key_sizes[i] == 0)
5576 priv->ieee->sec.flags &= ~(1 << i);
5578 memcpy(priv->ieee->sec.keys[i], sec->keys[i],
5580 if (sec->level == SEC_LEVEL_1) {
5581 priv->ieee->sec.flags |= (1 << i);
5582 priv->status |= STATUS_SECURITY_UPDATED;
5584 priv->ieee->sec.flags &= ~(1 << i);
5588 if ((sec->flags & SEC_ACTIVE_KEY) &&
5589 priv->ieee->sec.active_key != sec->active_key) {
5590 priv->ieee->sec.active_key = sec->active_key;
5591 priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
5592 priv->status |= STATUS_SECURITY_UPDATED;
5595 if ((sec->flags & SEC_AUTH_MODE) &&
5596 (priv->ieee->sec.auth_mode != sec->auth_mode)) {
5597 priv->ieee->sec.auth_mode = sec->auth_mode;
5598 priv->ieee->sec.flags |= SEC_AUTH_MODE;
5599 priv->status |= STATUS_SECURITY_UPDATED;
5602 if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
5603 priv->ieee->sec.flags |= SEC_ENABLED;
5604 priv->ieee->sec.enabled = sec->enabled;
5605 priv->status |= STATUS_SECURITY_UPDATED;
5608 if (sec->flags & SEC_ENCRYPT)
5609 priv->ieee->sec.encrypt = sec->encrypt;
5611 if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
5612 priv->ieee->sec.level = sec->level;
5613 priv->ieee->sec.flags |= SEC_LEVEL;
5614 priv->status |= STATUS_SECURITY_UPDATED;
5617 IPW_DEBUG_WEP("Security flags: %c %c%c%c%c %c%c%c%c\n",
5618 priv->ieee->sec.flags & (1 << 8) ? '1' : '0',
5619 priv->ieee->sec.flags & (1 << 7) ? '1' : '0',
5620 priv->ieee->sec.flags & (1 << 6) ? '1' : '0',
5621 priv->ieee->sec.flags & (1 << 5) ? '1' : '0',
5622 priv->ieee->sec.flags & (1 << 4) ? '1' : '0',
5623 priv->ieee->sec.flags & (1 << 3) ? '1' : '0',
5624 priv->ieee->sec.flags & (1 << 2) ? '1' : '0',
5625 priv->ieee->sec.flags & (1 << 1) ? '1' : '0',
5626 priv->ieee->sec.flags & (1 << 0) ? '1' : '0');
5628 /* As a temporary work around to enable WPA until we figure out why
5629 * wpa_supplicant toggles the security capability of the driver, which
5630 * forces a disassociation with force_update...
5632 * if (force_update || !(priv->status & STATUS_ASSOCIATED))*/
5633 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
5634 ipw2100_configure_security(priv, 0);
5636 mutex_unlock(&priv->action_mutex);
5639 static int ipw2100_adapter_setup(struct ipw2100_priv *priv)
5645 IPW_DEBUG_INFO("enter\n");
5647 err = ipw2100_disable_adapter(priv);
5650 #ifdef CONFIG_IPW2100_MONITOR
5651 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
5652 err = ipw2100_set_channel(priv, priv->channel, batch_mode);
5656 IPW_DEBUG_INFO("exit\n");
5660 #endif /* CONFIG_IPW2100_MONITOR */
5662 err = ipw2100_read_mac_address(priv);
5666 err = ipw2100_set_mac_address(priv, batch_mode);
5670 err = ipw2100_set_port_type(priv, priv->ieee->iw_mode, batch_mode);
5674 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
5675 err = ipw2100_set_channel(priv, priv->channel, batch_mode);
5680 err = ipw2100_system_config(priv, batch_mode);
5684 err = ipw2100_set_tx_rates(priv, priv->tx_rates, batch_mode);
5688 /* Default to power mode OFF */
5689 err = ipw2100_set_power_mode(priv, IPW_POWER_MODE_CAM);
5693 err = ipw2100_set_rts_threshold(priv, priv->rts_threshold);
5697 if (priv->config & CFG_STATIC_BSSID)
5698 bssid = priv->bssid;
5701 err = ipw2100_set_mandatory_bssid(priv, bssid, batch_mode);
5705 if (priv->config & CFG_STATIC_ESSID)
5706 err = ipw2100_set_essid(priv, priv->essid, priv->essid_len,
5709 err = ipw2100_set_essid(priv, NULL, 0, batch_mode);
5713 err = ipw2100_configure_security(priv, batch_mode);
5717 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
5719 ipw2100_set_ibss_beacon_interval(priv,
5720 priv->beacon_interval,
5725 err = ipw2100_set_tx_power(priv, priv->tx_power);
5731 err = ipw2100_set_fragmentation_threshold(
5732 priv, priv->frag_threshold, batch_mode);
5737 IPW_DEBUG_INFO("exit\n");
5742 /*************************************************************************
5744 * EXTERNALLY CALLED METHODS
5746 *************************************************************************/
5748 /* This method is called by the network layer -- not to be confused with
5749 * ipw2100_set_mac_address() declared above called by this driver (and this
5750 * method as well) to talk to the firmware */
5751 static int ipw2100_set_address(struct net_device *dev, void *p)
5753 struct ipw2100_priv *priv = libipw_priv(dev);
5754 struct sockaddr *addr = p;
5757 if (!is_valid_ether_addr(addr->sa_data))
5758 return -EADDRNOTAVAIL;
5760 mutex_lock(&priv->action_mutex);
5762 priv->config |= CFG_CUSTOM_MAC;
5763 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
5765 err = ipw2100_set_mac_address(priv, 0);
5769 priv->reset_backoff = 0;
5770 mutex_unlock(&priv->action_mutex);
5771 ipw2100_reset_adapter(&priv->reset_work.work);
5775 mutex_unlock(&priv->action_mutex);
5779 static int ipw2100_open(struct net_device *dev)
5781 struct ipw2100_priv *priv = libipw_priv(dev);
5782 unsigned long flags;
5783 IPW_DEBUG_INFO("dev->open\n");
5785 spin_lock_irqsave(&priv->low_lock, flags);
5786 if (priv->status & STATUS_ASSOCIATED) {
5787 netif_carrier_on(dev);
5788 netif_start_queue(dev);
5790 spin_unlock_irqrestore(&priv->low_lock, flags);
5795 static int ipw2100_close(struct net_device *dev)
5797 struct ipw2100_priv *priv = libipw_priv(dev);
5798 unsigned long flags;
5799 struct list_head *element;
5800 struct ipw2100_tx_packet *packet;
5802 IPW_DEBUG_INFO("enter\n");
5804 spin_lock_irqsave(&priv->low_lock, flags);
5806 if (priv->status & STATUS_ASSOCIATED)
5807 netif_carrier_off(dev);
5808 netif_stop_queue(dev);
5810 /* Flush the TX queue ... */
5811 while (!list_empty(&priv->tx_pend_list)) {
5812 element = priv->tx_pend_list.next;
5813 packet = list_entry(element, struct ipw2100_tx_packet, list);
5816 DEC_STAT(&priv->tx_pend_stat);
5818 libipw_txb_free(packet->info.d_struct.txb);
5819 packet->info.d_struct.txb = NULL;
5821 list_add_tail(element, &priv->tx_free_list);
5822 INC_STAT(&priv->tx_free_stat);
5824 spin_unlock_irqrestore(&priv->low_lock, flags);
5826 IPW_DEBUG_INFO("exit\n");
5832 * TODO: Fix this function... its just wrong
5834 static void ipw2100_tx_timeout(struct net_device *dev, unsigned int txqueue)
5836 struct ipw2100_priv *priv = libipw_priv(dev);
5838 dev->stats.tx_errors++;
5840 #ifdef CONFIG_IPW2100_MONITOR
5841 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
5845 IPW_DEBUG_INFO("%s: TX timed out. Scheduling firmware restart.\n",
5847 schedule_reset(priv);
5850 static int ipw2100_wpa_enable(struct ipw2100_priv *priv, int value)
5852 /* This is called when wpa_supplicant loads and closes the driver
5854 priv->ieee->wpa_enabled = value;
5858 static int ipw2100_wpa_set_auth_algs(struct ipw2100_priv *priv, int value)
5861 struct libipw_device *ieee = priv->ieee;
5862 struct libipw_security sec = {
5863 .flags = SEC_AUTH_MODE,
5867 if (value & IW_AUTH_ALG_SHARED_KEY) {
5868 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
5870 } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
5871 sec.auth_mode = WLAN_AUTH_OPEN;
5873 } else if (value & IW_AUTH_ALG_LEAP) {
5874 sec.auth_mode = WLAN_AUTH_LEAP;
5879 if (ieee->set_security)
5880 ieee->set_security(ieee->dev, &sec);
5887 static void ipw2100_wpa_assoc_frame(struct ipw2100_priv *priv,
5888 char *wpa_ie, int wpa_ie_len)
5891 struct ipw2100_wpa_assoc_frame frame;
5893 frame.fixed_ie_mask = 0;
5896 memcpy(frame.var_ie, wpa_ie, wpa_ie_len);
5897 frame.var_ie_len = wpa_ie_len;
5899 /* make sure WPA is enabled */
5900 ipw2100_wpa_enable(priv, 1);
5901 ipw2100_set_wpa_ie(priv, &frame, 0);
5904 static void ipw_ethtool_get_drvinfo(struct net_device *dev,
5905 struct ethtool_drvinfo *info)
5907 struct ipw2100_priv *priv = libipw_priv(dev);
5908 char fw_ver[64], ucode_ver[64];
5910 strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
5911 strlcpy(info->version, DRV_VERSION, sizeof(info->version));
5913 ipw2100_get_fwversion(priv, fw_ver, sizeof(fw_ver));
5914 ipw2100_get_ucodeversion(priv, ucode_ver, sizeof(ucode_ver));
5916 snprintf(info->fw_version, sizeof(info->fw_version), "%s:%d:%s",
5917 fw_ver, priv->eeprom_version, ucode_ver);
5919 strlcpy(info->bus_info, pci_name(priv->pci_dev),
5920 sizeof(info->bus_info));
5923 static u32 ipw2100_ethtool_get_link(struct net_device *dev)
5925 struct ipw2100_priv *priv = libipw_priv(dev);
5926 return (priv->status & STATUS_ASSOCIATED) ? 1 : 0;
5929 static const struct ethtool_ops ipw2100_ethtool_ops = {
5930 .get_link = ipw2100_ethtool_get_link,
5931 .get_drvinfo = ipw_ethtool_get_drvinfo,
5934 static void ipw2100_hang_check(struct work_struct *work)
5936 struct ipw2100_priv *priv =
5937 container_of(work, struct ipw2100_priv, hang_check.work);
5938 unsigned long flags;
5939 u32 rtc = 0xa5a5a5a5;
5940 u32 len = sizeof(rtc);
5943 spin_lock_irqsave(&priv->low_lock, flags);
5945 if (priv->fatal_error != 0) {
5946 /* If fatal_error is set then we need to restart */
5947 IPW_DEBUG_INFO("%s: Hardware fatal error detected.\n",
5948 priv->net_dev->name);
5951 } else if (ipw2100_get_ordinal(priv, IPW_ORD_RTC_TIME, &rtc, &len) ||
5952 (rtc == priv->last_rtc)) {
5953 /* Check if firmware is hung */
5954 IPW_DEBUG_INFO("%s: Firmware RTC stalled.\n",
5955 priv->net_dev->name);
5962 priv->stop_hang_check = 1;
5965 /* Restart the NIC */
5966 schedule_reset(priv);
5969 priv->last_rtc = rtc;
5971 if (!priv->stop_hang_check)
5972 schedule_delayed_work(&priv->hang_check, HZ / 2);
5974 spin_unlock_irqrestore(&priv->low_lock, flags);
5977 static void ipw2100_rf_kill(struct work_struct *work)
5979 struct ipw2100_priv *priv =
5980 container_of(work, struct ipw2100_priv, rf_kill.work);
5981 unsigned long flags;
5983 spin_lock_irqsave(&priv->low_lock, flags);
5985 if (rf_kill_active(priv)) {
5986 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
5987 if (!priv->stop_rf_kill)
5988 schedule_delayed_work(&priv->rf_kill,
5989 round_jiffies_relative(HZ));
5993 /* RF Kill is now disabled, so bring the device back up */
5995 if (!(priv->status & STATUS_RF_KILL_MASK)) {
5996 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
5998 schedule_reset(priv);
6000 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
6004 spin_unlock_irqrestore(&priv->low_lock, flags);
6007 static void ipw2100_irq_tasklet(struct tasklet_struct *t);
6009 static const struct net_device_ops ipw2100_netdev_ops = {
6010 .ndo_open = ipw2100_open,
6011 .ndo_stop = ipw2100_close,
6012 .ndo_start_xmit = libipw_xmit,
6013 .ndo_tx_timeout = ipw2100_tx_timeout,
6014 .ndo_set_mac_address = ipw2100_set_address,
6015 .ndo_validate_addr = eth_validate_addr,
6018 /* Look into using netdev destructor to shutdown libipw? */
6020 static struct net_device *ipw2100_alloc_device(struct pci_dev *pci_dev,
6021 void __iomem * ioaddr)
6023 struct ipw2100_priv *priv;
6024 struct net_device *dev;
6026 dev = alloc_libipw(sizeof(struct ipw2100_priv), 0);
6029 priv = libipw_priv(dev);
6030 priv->ieee = netdev_priv(dev);
6031 priv->pci_dev = pci_dev;
6032 priv->net_dev = dev;
6033 priv->ioaddr = ioaddr;
6035 priv->ieee->hard_start_xmit = ipw2100_tx;
6036 priv->ieee->set_security = shim__set_security;
6038 priv->ieee->perfect_rssi = -20;
6039 priv->ieee->worst_rssi = -85;
6041 dev->netdev_ops = &ipw2100_netdev_ops;
6042 dev->ethtool_ops = &ipw2100_ethtool_ops;
6043 dev->wireless_handlers = &ipw2100_wx_handler_def;
6044 priv->wireless_data.libipw = priv->ieee;
6045 dev->wireless_data = &priv->wireless_data;
6046 dev->watchdog_timeo = 3 * HZ;
6049 dev->max_mtu = LIBIPW_DATA_LEN;
6051 /* NOTE: We don't use the wireless_handlers hook
6052 * in dev as the system will start throwing WX requests
6053 * to us before we're actually initialized and it just
6054 * ends up causing problems. So, we just handle
6055 * the WX extensions through the ipw2100_ioctl interface */
6057 /* memset() puts everything to 0, so we only have explicitly set
6058 * those values that need to be something else */
6060 /* If power management is turned on, default to AUTO mode */
6061 priv->power_mode = IPW_POWER_AUTO;
6063 #ifdef CONFIG_IPW2100_MONITOR
6064 priv->config |= CFG_CRC_CHECK;
6066 priv->ieee->wpa_enabled = 0;
6067 priv->ieee->drop_unencrypted = 0;
6068 priv->ieee->privacy_invoked = 0;
6069 priv->ieee->ieee802_1x = 1;
6071 /* Set module parameters */
6072 switch (network_mode) {
6074 priv->ieee->iw_mode = IW_MODE_ADHOC;
6076 #ifdef CONFIG_IPW2100_MONITOR
6078 priv->ieee->iw_mode = IW_MODE_MONITOR;
6083 priv->ieee->iw_mode = IW_MODE_INFRA;
6088 priv->status |= STATUS_RF_KILL_SW;
6091 ((channel >= REG_MIN_CHANNEL) && (channel <= REG_MAX_CHANNEL))) {
6092 priv->config |= CFG_STATIC_CHANNEL;
6093 priv->channel = channel;
6097 priv->config |= CFG_ASSOCIATE;
6099 priv->beacon_interval = DEFAULT_BEACON_INTERVAL;
6100 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
6101 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
6102 priv->rts_threshold = DEFAULT_RTS_THRESHOLD | RTS_DISABLED;
6103 priv->frag_threshold = DEFAULT_FTS | FRAG_DISABLED;
6104 priv->tx_power = IPW_TX_POWER_DEFAULT;
6105 priv->tx_rates = DEFAULT_TX_RATES;
6107 strcpy(priv->nick, "ipw2100");
6109 spin_lock_init(&priv->low_lock);
6110 mutex_init(&priv->action_mutex);
6111 mutex_init(&priv->adapter_mutex);
6113 init_waitqueue_head(&priv->wait_command_queue);
6115 netif_carrier_off(dev);
6117 INIT_LIST_HEAD(&priv->msg_free_list);
6118 INIT_LIST_HEAD(&priv->msg_pend_list);
6119 INIT_STAT(&priv->msg_free_stat);
6120 INIT_STAT(&priv->msg_pend_stat);
6122 INIT_LIST_HEAD(&priv->tx_free_list);
6123 INIT_LIST_HEAD(&priv->tx_pend_list);
6124 INIT_STAT(&priv->tx_free_stat);
6125 INIT_STAT(&priv->tx_pend_stat);
6127 INIT_LIST_HEAD(&priv->fw_pend_list);
6128 INIT_STAT(&priv->fw_pend_stat);
6130 INIT_DELAYED_WORK(&priv->reset_work, ipw2100_reset_adapter);
6131 INIT_DELAYED_WORK(&priv->security_work, ipw2100_security_work);
6132 INIT_DELAYED_WORK(&priv->wx_event_work, ipw2100_wx_event_work);
6133 INIT_DELAYED_WORK(&priv->hang_check, ipw2100_hang_check);
6134 INIT_DELAYED_WORK(&priv->rf_kill, ipw2100_rf_kill);
6135 INIT_DELAYED_WORK(&priv->scan_event, ipw2100_scan_event);
6137 tasklet_setup(&priv->irq_tasklet, ipw2100_irq_tasklet);
6139 /* NOTE: We do not start the deferred work for status checks yet */
6140 priv->stop_rf_kill = 1;
6141 priv->stop_hang_check = 1;
6146 static int ipw2100_pci_init_one(struct pci_dev *pci_dev,
6147 const struct pci_device_id *ent)
6149 void __iomem *ioaddr;
6150 struct net_device *dev = NULL;
6151 struct ipw2100_priv *priv = NULL;
6156 IPW_DEBUG_INFO("enter\n");
6158 if (!(pci_resource_flags(pci_dev, 0) & IORESOURCE_MEM)) {
6159 IPW_DEBUG_INFO("weird - resource type is not memory\n");
6164 ioaddr = pci_iomap(pci_dev, 0, 0);
6166 printk(KERN_WARNING DRV_NAME
6167 "Error calling ioremap.\n");
6172 /* allocate and initialize our net_device */
6173 dev = ipw2100_alloc_device(pci_dev, ioaddr);
6175 printk(KERN_WARNING DRV_NAME
6176 "Error calling ipw2100_alloc_device.\n");
6181 /* set up PCI mappings for device */
6182 err = pci_enable_device(pci_dev);
6184 printk(KERN_WARNING DRV_NAME
6185 "Error calling pci_enable_device.\n");
6189 priv = libipw_priv(dev);
6191 pci_set_master(pci_dev);
6192 pci_set_drvdata(pci_dev, priv);
6194 err = dma_set_mask(&pci_dev->dev, DMA_BIT_MASK(32));
6196 printk(KERN_WARNING DRV_NAME
6197 "Error calling pci_set_dma_mask.\n");
6198 pci_disable_device(pci_dev);
6202 err = pci_request_regions(pci_dev, DRV_NAME);
6204 printk(KERN_WARNING DRV_NAME
6205 "Error calling pci_request_regions.\n");
6206 pci_disable_device(pci_dev);
6210 /* We disable the RETRY_TIMEOUT register (0x41) to keep
6211 * PCI Tx retries from interfering with C3 CPU state */
6212 pci_read_config_dword(pci_dev, 0x40, &val);
6213 if ((val & 0x0000ff00) != 0)
6214 pci_write_config_dword(pci_dev, 0x40, val & 0xffff00ff);
6216 if (!ipw2100_hw_is_adapter_in_system(dev)) {
6217 printk(KERN_WARNING DRV_NAME
6218 "Device not found via register read.\n");
6223 SET_NETDEV_DEV(dev, &pci_dev->dev);
6225 /* Force interrupts to be shut off on the device */
6226 priv->status |= STATUS_INT_ENABLED;
6227 ipw2100_disable_interrupts(priv);
6229 /* Allocate and initialize the Tx/Rx queues and lists */
6230 if (ipw2100_queues_allocate(priv)) {
6231 printk(KERN_WARNING DRV_NAME
6232 "Error calling ipw2100_queues_allocate.\n");
6236 ipw2100_queues_initialize(priv);
6238 err = request_irq(pci_dev->irq,
6239 ipw2100_interrupt, IRQF_SHARED, dev->name, priv);
6241 printk(KERN_WARNING DRV_NAME
6242 "Error calling request_irq: %d.\n", pci_dev->irq);
6245 dev->irq = pci_dev->irq;
6247 IPW_DEBUG_INFO("Attempting to register device...\n");
6249 printk(KERN_INFO DRV_NAME
6250 ": Detected Intel PRO/Wireless 2100 Network Connection\n");
6252 err = ipw2100_up(priv, 1);
6256 err = ipw2100_wdev_init(dev);
6261 /* Bring up the interface. Pre 0.46, after we registered the
6262 * network device we would call ipw2100_up. This introduced a race
6263 * condition with newer hotplug configurations (network was coming
6264 * up and making calls before the device was initialized).
6266 err = register_netdev(dev);
6268 printk(KERN_WARNING DRV_NAME
6269 "Error calling register_netdev.\n");
6274 mutex_lock(&priv->action_mutex);
6276 IPW_DEBUG_INFO("%s: Bound to %s\n", dev->name, pci_name(pci_dev));
6278 /* perform this after register_netdev so that dev->name is set */
6279 err = sysfs_create_group(&pci_dev->dev.kobj, &ipw2100_attribute_group);
6283 /* If the RF Kill switch is disabled, go ahead and complete the
6284 * startup sequence */
6285 if (!(priv->status & STATUS_RF_KILL_MASK)) {
6286 /* Enable the adapter - sends HOST_COMPLETE */
6287 if (ipw2100_enable_adapter(priv)) {
6288 printk(KERN_WARNING DRV_NAME
6289 ": %s: failed in call to enable adapter.\n",
6290 priv->net_dev->name);
6291 ipw2100_hw_stop_adapter(priv);
6296 /* Start a scan . . . */
6297 ipw2100_set_scan_options(priv);
6298 ipw2100_start_scan(priv);
6301 IPW_DEBUG_INFO("exit\n");
6303 priv->status |= STATUS_INITIALIZED;
6305 mutex_unlock(&priv->action_mutex);
6310 mutex_unlock(&priv->action_mutex);
6313 if (registered >= 2)
6314 unregister_netdev(dev);
6317 wiphy_unregister(priv->ieee->wdev.wiphy);
6318 kfree(priv->ieee->bg_band.channels);
6321 ipw2100_hw_stop_adapter(priv);
6323 ipw2100_disable_interrupts(priv);
6326 free_irq(dev->irq, priv);
6328 ipw2100_kill_works(priv);
6330 /* These are safe to call even if they weren't allocated */
6331 ipw2100_queues_free(priv);
6332 sysfs_remove_group(&pci_dev->dev.kobj,
6333 &ipw2100_attribute_group);
6335 free_libipw(dev, 0);
6338 pci_iounmap(pci_dev, ioaddr);
6340 pci_release_regions(pci_dev);
6341 pci_disable_device(pci_dev);
6345 static void ipw2100_pci_remove_one(struct pci_dev *pci_dev)
6347 struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
6348 struct net_device *dev = priv->net_dev;
6350 mutex_lock(&priv->action_mutex);
6352 priv->status &= ~STATUS_INITIALIZED;
6354 sysfs_remove_group(&pci_dev->dev.kobj, &ipw2100_attribute_group);
6357 if (ipw2100_firmware.version)
6358 ipw2100_release_firmware(priv, &ipw2100_firmware);
6360 /* Take down the hardware */
6363 /* Release the mutex so that the network subsystem can
6364 * complete any needed calls into the driver... */
6365 mutex_unlock(&priv->action_mutex);
6367 /* Unregister the device first - this results in close()
6368 * being called if the device is open. If we free storage
6369 * first, then close() will crash.
6370 * FIXME: remove the comment above. */
6371 unregister_netdev(dev);
6373 ipw2100_kill_works(priv);
6375 ipw2100_queues_free(priv);
6377 /* Free potential debugging firmware snapshot */
6378 ipw2100_snapshot_free(priv);
6380 free_irq(dev->irq, priv);
6382 pci_iounmap(pci_dev, priv->ioaddr);
6384 /* wiphy_unregister needs to be here, before free_libipw */
6385 wiphy_unregister(priv->ieee->wdev.wiphy);
6386 kfree(priv->ieee->bg_band.channels);
6387 free_libipw(dev, 0);
6389 pci_release_regions(pci_dev);
6390 pci_disable_device(pci_dev);
6392 IPW_DEBUG_INFO("exit\n");
6395 static int __maybe_unused ipw2100_suspend(struct device *dev_d)
6397 struct ipw2100_priv *priv = dev_get_drvdata(dev_d);
6398 struct net_device *dev = priv->net_dev;
6400 IPW_DEBUG_INFO("%s: Going into suspend...\n", dev->name);
6402 mutex_lock(&priv->action_mutex);
6403 if (priv->status & STATUS_INITIALIZED) {
6404 /* Take down the device; powers it off, etc. */
6408 /* Remove the PRESENT state of the device */
6409 netif_device_detach(dev);
6411 priv->suspend_at = ktime_get_boottime_seconds();
6413 mutex_unlock(&priv->action_mutex);
6418 static int __maybe_unused ipw2100_resume(struct device *dev_d)
6420 struct pci_dev *pci_dev = to_pci_dev(dev_d);
6421 struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
6422 struct net_device *dev = priv->net_dev;
6425 if (IPW2100_PM_DISABLED)
6428 mutex_lock(&priv->action_mutex);
6430 IPW_DEBUG_INFO("%s: Coming out of suspend...\n", dev->name);
6433 * Suspend/Resume resets the PCI configuration space, so we have to
6434 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
6435 * from interfering with C3 CPU state. pci_restore_state won't help
6436 * here since it only restores the first 64 bytes pci config header.
6438 pci_read_config_dword(pci_dev, 0x40, &val);
6439 if ((val & 0x0000ff00) != 0)
6440 pci_write_config_dword(pci_dev, 0x40, val & 0xffff00ff);
6442 /* Set the device back into the PRESENT state; this will also wake
6443 * the queue of needed */
6444 netif_device_attach(dev);
6446 priv->suspend_time = ktime_get_boottime_seconds() - priv->suspend_at;
6448 /* Bring the device back up */
6449 if (!(priv->status & STATUS_RF_KILL_SW))
6450 ipw2100_up(priv, 0);
6452 mutex_unlock(&priv->action_mutex);
6457 static void ipw2100_shutdown(struct pci_dev *pci_dev)
6459 struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
6461 /* Take down the device; powers it off, etc. */
6464 pci_disable_device(pci_dev);
6467 #define IPW2100_DEV_ID(x) { PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, x }
6469 static const struct pci_device_id ipw2100_pci_id_table[] = {
6470 IPW2100_DEV_ID(0x2520), /* IN 2100A mPCI 3A */
6471 IPW2100_DEV_ID(0x2521), /* IN 2100A mPCI 3B */
6472 IPW2100_DEV_ID(0x2524), /* IN 2100A mPCI 3B */
6473 IPW2100_DEV_ID(0x2525), /* IN 2100A mPCI 3B */
6474 IPW2100_DEV_ID(0x2526), /* IN 2100A mPCI Gen A3 */
6475 IPW2100_DEV_ID(0x2522), /* IN 2100 mPCI 3B */
6476 IPW2100_DEV_ID(0x2523), /* IN 2100 mPCI 3A */
6477 IPW2100_DEV_ID(0x2527), /* IN 2100 mPCI 3B */
6478 IPW2100_DEV_ID(0x2528), /* IN 2100 mPCI 3B */
6479 IPW2100_DEV_ID(0x2529), /* IN 2100 mPCI 3B */
6480 IPW2100_DEV_ID(0x252B), /* IN 2100 mPCI 3A */
6481 IPW2100_DEV_ID(0x252C), /* IN 2100 mPCI 3A */
6482 IPW2100_DEV_ID(0x252D), /* IN 2100 mPCI 3A */
6484 IPW2100_DEV_ID(0x2550), /* IB 2100A mPCI 3B */
6485 IPW2100_DEV_ID(0x2551), /* IB 2100 mPCI 3B */
6486 IPW2100_DEV_ID(0x2553), /* IB 2100 mPCI 3B */
6487 IPW2100_DEV_ID(0x2554), /* IB 2100 mPCI 3B */
6488 IPW2100_DEV_ID(0x2555), /* IB 2100 mPCI 3B */
6490 IPW2100_DEV_ID(0x2560), /* DE 2100A mPCI 3A */
6491 IPW2100_DEV_ID(0x2562), /* DE 2100A mPCI 3A */
6492 IPW2100_DEV_ID(0x2563), /* DE 2100A mPCI 3A */
6493 IPW2100_DEV_ID(0x2561), /* DE 2100 mPCI 3A */
6494 IPW2100_DEV_ID(0x2565), /* DE 2100 mPCI 3A */
6495 IPW2100_DEV_ID(0x2566), /* DE 2100 mPCI 3A */
6496 IPW2100_DEV_ID(0x2567), /* DE 2100 mPCI 3A */
6498 IPW2100_DEV_ID(0x2570), /* GA 2100 mPCI 3B */
6500 IPW2100_DEV_ID(0x2580), /* TO 2100A mPCI 3B */
6501 IPW2100_DEV_ID(0x2582), /* TO 2100A mPCI 3B */
6502 IPW2100_DEV_ID(0x2583), /* TO 2100A mPCI 3B */
6503 IPW2100_DEV_ID(0x2581), /* TO 2100 mPCI 3B */
6504 IPW2100_DEV_ID(0x2585), /* TO 2100 mPCI 3B */
6505 IPW2100_DEV_ID(0x2586), /* TO 2100 mPCI 3B */
6506 IPW2100_DEV_ID(0x2587), /* TO 2100 mPCI 3B */
6508 IPW2100_DEV_ID(0x2590), /* SO 2100A mPCI 3B */
6509 IPW2100_DEV_ID(0x2592), /* SO 2100A mPCI 3B */
6510 IPW2100_DEV_ID(0x2591), /* SO 2100 mPCI 3B */
6511 IPW2100_DEV_ID(0x2593), /* SO 2100 mPCI 3B */
6512 IPW2100_DEV_ID(0x2596), /* SO 2100 mPCI 3B */
6513 IPW2100_DEV_ID(0x2598), /* SO 2100 mPCI 3B */
6515 IPW2100_DEV_ID(0x25A0), /* HP 2100 mPCI 3B */
6519 MODULE_DEVICE_TABLE(pci, ipw2100_pci_id_table);
6521 static SIMPLE_DEV_PM_OPS(ipw2100_pm_ops, ipw2100_suspend, ipw2100_resume);
6523 static struct pci_driver ipw2100_pci_driver = {
6525 .id_table = ipw2100_pci_id_table,
6526 .probe = ipw2100_pci_init_one,
6527 .remove = ipw2100_pci_remove_one,
6528 .driver.pm = &ipw2100_pm_ops,
6529 .shutdown = ipw2100_shutdown,
6533 * Initialize the ipw2100 driver/module
6535 * @returns 0 if ok, < 0 errno node con error.
6537 * Note: we cannot init the /proc stuff until the PCI driver is there,
6538 * or we risk an unlikely race condition on someone accessing
6539 * uninitialized data in the PCI dev struct through /proc.
6541 static int __init ipw2100_init(void)
6545 printk(KERN_INFO DRV_NAME ": %s, %s\n", DRV_DESCRIPTION, DRV_VERSION);
6546 printk(KERN_INFO DRV_NAME ": %s\n", DRV_COPYRIGHT);
6548 cpu_latency_qos_add_request(&ipw2100_pm_qos_req, PM_QOS_DEFAULT_VALUE);
6550 ret = pci_register_driver(&ipw2100_pci_driver);
6554 #ifdef CONFIG_IPW2100_DEBUG
6555 ipw2100_debug_level = debug;
6556 ret = driver_create_file(&ipw2100_pci_driver.driver,
6557 &driver_attr_debug_level);
6565 * Cleanup ipw2100 driver registration
6567 static void __exit ipw2100_exit(void)
6569 /* FIXME: IPG: check that we have no instances of the devices open */
6570 #ifdef CONFIG_IPW2100_DEBUG
6571 driver_remove_file(&ipw2100_pci_driver.driver,
6572 &driver_attr_debug_level);
6574 pci_unregister_driver(&ipw2100_pci_driver);
6575 cpu_latency_qos_remove_request(&ipw2100_pm_qos_req);
6578 module_init(ipw2100_init);
6579 module_exit(ipw2100_exit);
6581 static int ipw2100_wx_get_name(struct net_device *dev,
6582 struct iw_request_info *info,
6583 union iwreq_data *wrqu, char *extra)
6586 * This can be called at any time. No action lock required
6589 struct ipw2100_priv *priv = libipw_priv(dev);
6590 if (!(priv->status & STATUS_ASSOCIATED))
6591 strcpy(wrqu->name, "unassociated");
6593 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11b");
6595 IPW_DEBUG_WX("Name: %s\n", wrqu->name);
6599 static int ipw2100_wx_set_freq(struct net_device *dev,
6600 struct iw_request_info *info,
6601 union iwreq_data *wrqu, char *extra)
6603 struct ipw2100_priv *priv = libipw_priv(dev);
6604 struct iw_freq *fwrq = &wrqu->freq;
6607 if (priv->ieee->iw_mode == IW_MODE_INFRA)
6610 mutex_lock(&priv->action_mutex);
6611 if (!(priv->status & STATUS_INITIALIZED)) {
6616 /* if setting by freq convert to channel */
6618 if ((fwrq->m >= (int)2.412e8 && fwrq->m <= (int)2.487e8)) {
6619 int f = fwrq->m / 100000;
6622 while ((c < REG_MAX_CHANNEL) &&
6623 (f != ipw2100_frequencies[c]))
6626 /* hack to fall through */
6632 if (fwrq->e > 0 || fwrq->m > 1000) {
6635 } else { /* Set the channel */
6636 IPW_DEBUG_WX("SET Freq/Channel -> %d\n", fwrq->m);
6637 err = ipw2100_set_channel(priv, fwrq->m, 0);
6641 mutex_unlock(&priv->action_mutex);
6645 static int ipw2100_wx_get_freq(struct net_device *dev,
6646 struct iw_request_info *info,
6647 union iwreq_data *wrqu, char *extra)
6650 * This can be called at any time. No action lock required
6653 struct ipw2100_priv *priv = libipw_priv(dev);
6657 /* If we are associated, trying to associate, or have a statically
6658 * configured CHANNEL then return that; otherwise return ANY */
6659 if (priv->config & CFG_STATIC_CHANNEL ||
6660 priv->status & STATUS_ASSOCIATED)
6661 wrqu->freq.m = priv->channel;
6665 IPW_DEBUG_WX("GET Freq/Channel -> %d\n", priv->channel);
6670 static int ipw2100_wx_set_mode(struct net_device *dev,
6671 struct iw_request_info *info,
6672 union iwreq_data *wrqu, char *extra)
6674 struct ipw2100_priv *priv = libipw_priv(dev);
6677 IPW_DEBUG_WX("SET Mode -> %d\n", wrqu->mode);
6679 if (wrqu->mode == priv->ieee->iw_mode)
6682 mutex_lock(&priv->action_mutex);
6683 if (!(priv->status & STATUS_INITIALIZED)) {
6688 switch (wrqu->mode) {
6689 #ifdef CONFIG_IPW2100_MONITOR
6690 case IW_MODE_MONITOR:
6691 err = ipw2100_switch_mode(priv, IW_MODE_MONITOR);
6693 #endif /* CONFIG_IPW2100_MONITOR */
6695 err = ipw2100_switch_mode(priv, IW_MODE_ADHOC);
6700 err = ipw2100_switch_mode(priv, IW_MODE_INFRA);
6705 mutex_unlock(&priv->action_mutex);
6709 static int ipw2100_wx_get_mode(struct net_device *dev,
6710 struct iw_request_info *info,
6711 union iwreq_data *wrqu, char *extra)
6714 * This can be called at any time. No action lock required
6717 struct ipw2100_priv *priv = libipw_priv(dev);
6719 wrqu->mode = priv->ieee->iw_mode;
6720 IPW_DEBUG_WX("GET Mode -> %d\n", wrqu->mode);
6725 #define POWER_MODES 5
6727 /* Values are in microsecond */
6728 static const s32 timeout_duration[POWER_MODES] = {
6736 static const s32 period_duration[POWER_MODES] = {
6744 static int ipw2100_wx_get_range(struct net_device *dev,
6745 struct iw_request_info *info,
6746 union iwreq_data *wrqu, char *extra)
6749 * This can be called at any time. No action lock required
6752 struct ipw2100_priv *priv = libipw_priv(dev);
6753 struct iw_range *range = (struct iw_range *)extra;
6757 wrqu->data.length = sizeof(*range);
6758 memset(range, 0, sizeof(*range));
6760 /* Let's try to keep this struct in the same order as in
6761 * linux/include/wireless.h
6764 /* TODO: See what values we can set, and remove the ones we can't
6765 * set, or fill them with some default data.
6768 /* ~5 Mb/s real (802.11b) */
6769 range->throughput = 5 * 1000 * 1000;
6771 // range->sensitivity; /* signal level threshold range */
6773 range->max_qual.qual = 100;
6774 /* TODO: Find real max RSSI and stick here */
6775 range->max_qual.level = 0;
6776 range->max_qual.noise = 0;
6777 range->max_qual.updated = 7; /* Updated all three */
6779 range->avg_qual.qual = 70; /* > 8% missed beacons is 'bad' */
6780 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
6781 range->avg_qual.level = 20 + IPW2100_RSSI_TO_DBM;
6782 range->avg_qual.noise = 0;
6783 range->avg_qual.updated = 7; /* Updated all three */
6785 range->num_bitrates = RATE_COUNT;
6787 for (i = 0; i < RATE_COUNT && i < IW_MAX_BITRATES; i++) {
6788 range->bitrate[i] = ipw2100_bg_rates[i].bitrate * 100 * 1000;
6791 range->min_rts = MIN_RTS_THRESHOLD;
6792 range->max_rts = MAX_RTS_THRESHOLD;
6793 range->min_frag = MIN_FRAG_THRESHOLD;
6794 range->max_frag = MAX_FRAG_THRESHOLD;
6796 range->min_pmp = period_duration[0]; /* Minimal PM period */
6797 range->max_pmp = period_duration[POWER_MODES - 1]; /* Maximal PM period */
6798 range->min_pmt = timeout_duration[POWER_MODES - 1]; /* Minimal PM timeout */
6799 range->max_pmt = timeout_duration[0]; /* Maximal PM timeout */
6801 /* How to decode max/min PM period */
6802 range->pmp_flags = IW_POWER_PERIOD;
6803 /* How to decode max/min PM period */
6804 range->pmt_flags = IW_POWER_TIMEOUT;
6805 /* What PM options are supported */
6806 range->pm_capa = IW_POWER_TIMEOUT | IW_POWER_PERIOD;
6808 range->encoding_size[0] = 5;
6809 range->encoding_size[1] = 13; /* Different token sizes */
6810 range->num_encoding_sizes = 2; /* Number of entry in the list */
6811 range->max_encoding_tokens = WEP_KEYS; /* Max number of tokens */
6812 // range->encoding_login_index; /* token index for login token */
6814 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
6815 range->txpower_capa = IW_TXPOW_DBM;
6816 range->num_txpower = IW_MAX_TXPOWER;
6817 for (i = 0, level = (IPW_TX_POWER_MAX_DBM * 16);
6820 ((IPW_TX_POWER_MAX_DBM -
6821 IPW_TX_POWER_MIN_DBM) * 16) / (IW_MAX_TXPOWER - 1))
6822 range->txpower[i] = level / 16;
6824 range->txpower_capa = 0;
6825 range->num_txpower = 0;
6828 /* Set the Wireless Extension versions */
6829 range->we_version_compiled = WIRELESS_EXT;
6830 range->we_version_source = 18;
6832 // range->retry_capa; /* What retry options are supported */
6833 // range->retry_flags; /* How to decode max/min retry limit */
6834 // range->r_time_flags; /* How to decode max/min retry life */
6835 // range->min_retry; /* Minimal number of retries */
6836 // range->max_retry; /* Maximal number of retries */
6837 // range->min_r_time; /* Minimal retry lifetime */
6838 // range->max_r_time; /* Maximal retry lifetime */
6840 range->num_channels = FREQ_COUNT;
6843 for (i = 0; i < FREQ_COUNT; i++) {
6844 // TODO: Include only legal frequencies for some countries
6845 // if (local->channel_mask & (1 << i)) {
6846 range->freq[val].i = i + 1;
6847 range->freq[val].m = ipw2100_frequencies[i] * 100000;
6848 range->freq[val].e = 1;
6851 if (val == IW_MAX_FREQUENCIES)
6854 range->num_frequency = val;
6856 /* Event capability (kernel + driver) */
6857 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
6858 IW_EVENT_CAPA_MASK(SIOCGIWAP));
6859 range->event_capa[1] = IW_EVENT_CAPA_K_1;
6861 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
6862 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
6864 IPW_DEBUG_WX("GET Range\n");
6869 static int ipw2100_wx_set_wap(struct net_device *dev,
6870 struct iw_request_info *info,
6871 union iwreq_data *wrqu, char *extra)
6873 struct ipw2100_priv *priv = libipw_priv(dev);
6877 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
6880 mutex_lock(&priv->action_mutex);
6881 if (!(priv->status & STATUS_INITIALIZED)) {
6886 if (is_broadcast_ether_addr(wrqu->ap_addr.sa_data) ||
6887 is_zero_ether_addr(wrqu->ap_addr.sa_data)) {
6888 /* we disable mandatory BSSID association */
6889 IPW_DEBUG_WX("exit - disable mandatory BSSID\n");
6890 priv->config &= ~CFG_STATIC_BSSID;
6891 err = ipw2100_set_mandatory_bssid(priv, NULL, 0);
6895 priv->config |= CFG_STATIC_BSSID;
6896 memcpy(priv->mandatory_bssid_mac, wrqu->ap_addr.sa_data, ETH_ALEN);
6898 err = ipw2100_set_mandatory_bssid(priv, wrqu->ap_addr.sa_data, 0);
6900 IPW_DEBUG_WX("SET BSSID -> %pM\n", wrqu->ap_addr.sa_data);
6903 mutex_unlock(&priv->action_mutex);
6907 static int ipw2100_wx_get_wap(struct net_device *dev,
6908 struct iw_request_info *info,
6909 union iwreq_data *wrqu, char *extra)
6912 * This can be called at any time. No action lock required
6915 struct ipw2100_priv *priv = libipw_priv(dev);
6917 /* If we are associated, trying to associate, or have a statically
6918 * configured BSSID then return that; otherwise return ANY */
6919 if (priv->config & CFG_STATIC_BSSID || priv->status & STATUS_ASSOCIATED) {
6920 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
6921 memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
6923 eth_zero_addr(wrqu->ap_addr.sa_data);
6925 IPW_DEBUG_WX("Getting WAP BSSID: %pM\n", wrqu->ap_addr.sa_data);
6929 static int ipw2100_wx_set_essid(struct net_device *dev,
6930 struct iw_request_info *info,
6931 union iwreq_data *wrqu, char *extra)
6933 struct ipw2100_priv *priv = libipw_priv(dev);
6934 char *essid = ""; /* ANY */
6938 mutex_lock(&priv->action_mutex);
6939 if (!(priv->status & STATUS_INITIALIZED)) {
6944 if (wrqu->essid.flags && wrqu->essid.length) {
6945 length = wrqu->essid.length;
6950 IPW_DEBUG_WX("Setting ESSID to ANY\n");
6951 priv->config &= ~CFG_STATIC_ESSID;
6952 err = ipw2100_set_essid(priv, NULL, 0, 0);
6956 length = min(length, IW_ESSID_MAX_SIZE);
6958 priv->config |= CFG_STATIC_ESSID;
6960 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
6961 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
6966 IPW_DEBUG_WX("Setting ESSID: '%*pE' (%d)\n", length, essid, length);
6968 priv->essid_len = length;
6969 memcpy(priv->essid, essid, priv->essid_len);
6971 err = ipw2100_set_essid(priv, essid, length, 0);
6974 mutex_unlock(&priv->action_mutex);
6978 static int ipw2100_wx_get_essid(struct net_device *dev,
6979 struct iw_request_info *info,
6980 union iwreq_data *wrqu, char *extra)
6983 * This can be called at any time. No action lock required
6986 struct ipw2100_priv *priv = libipw_priv(dev);
6988 /* If we are associated, trying to associate, or have a statically
6989 * configured ESSID then return that; otherwise return ANY */
6990 if (priv->config & CFG_STATIC_ESSID || priv->status & STATUS_ASSOCIATED) {
6991 IPW_DEBUG_WX("Getting essid: '%*pE'\n",
6992 priv->essid_len, priv->essid);
6993 memcpy(extra, priv->essid, priv->essid_len);
6994 wrqu->essid.length = priv->essid_len;
6995 wrqu->essid.flags = 1; /* active */
6997 IPW_DEBUG_WX("Getting essid: ANY\n");
6998 wrqu->essid.length = 0;
6999 wrqu->essid.flags = 0; /* active */
7005 static int ipw2100_wx_set_nick(struct net_device *dev,
7006 struct iw_request_info *info,
7007 union iwreq_data *wrqu, char *extra)
7010 * This can be called at any time. No action lock required
7013 struct ipw2100_priv *priv = libipw_priv(dev);
7015 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
7018 wrqu->data.length = min_t(size_t, wrqu->data.length, sizeof(priv->nick));
7019 memset(priv->nick, 0, sizeof(priv->nick));
7020 memcpy(priv->nick, extra, wrqu->data.length);
7022 IPW_DEBUG_WX("SET Nickname -> %s\n", priv->nick);
7027 static int ipw2100_wx_get_nick(struct net_device *dev,
7028 struct iw_request_info *info,
7029 union iwreq_data *wrqu, char *extra)
7032 * This can be called at any time. No action lock required
7035 struct ipw2100_priv *priv = libipw_priv(dev);
7037 wrqu->data.length = strlen(priv->nick);
7038 memcpy(extra, priv->nick, wrqu->data.length);
7039 wrqu->data.flags = 1; /* active */
7041 IPW_DEBUG_WX("GET Nickname -> %s\n", extra);
7046 static int ipw2100_wx_set_rate(struct net_device *dev,
7047 struct iw_request_info *info,
7048 union iwreq_data *wrqu, char *extra)
7050 struct ipw2100_priv *priv = libipw_priv(dev);
7051 u32 target_rate = wrqu->bitrate.value;
7055 mutex_lock(&priv->action_mutex);
7056 if (!(priv->status & STATUS_INITIALIZED)) {
7063 if (target_rate == 1000000 ||
7064 (!wrqu->bitrate.fixed && target_rate > 1000000))
7065 rate |= TX_RATE_1_MBIT;
7066 if (target_rate == 2000000 ||
7067 (!wrqu->bitrate.fixed && target_rate > 2000000))
7068 rate |= TX_RATE_2_MBIT;
7069 if (target_rate == 5500000 ||
7070 (!wrqu->bitrate.fixed && target_rate > 5500000))
7071 rate |= TX_RATE_5_5_MBIT;
7072 if (target_rate == 11000000 ||
7073 (!wrqu->bitrate.fixed && target_rate > 11000000))
7074 rate |= TX_RATE_11_MBIT;
7076 rate = DEFAULT_TX_RATES;
7078 err = ipw2100_set_tx_rates(priv, rate, 0);
7080 IPW_DEBUG_WX("SET Rate -> %04X\n", rate);
7082 mutex_unlock(&priv->action_mutex);
7086 static int ipw2100_wx_get_rate(struct net_device *dev,
7087 struct iw_request_info *info,
7088 union iwreq_data *wrqu, char *extra)
7090 struct ipw2100_priv *priv = libipw_priv(dev);
7092 unsigned int len = sizeof(val);
7095 if (!(priv->status & STATUS_ENABLED) ||
7096 priv->status & STATUS_RF_KILL_MASK ||
7097 !(priv->status & STATUS_ASSOCIATED)) {
7098 wrqu->bitrate.value = 0;
7102 mutex_lock(&priv->action_mutex);
7103 if (!(priv->status & STATUS_INITIALIZED)) {
7108 err = ipw2100_get_ordinal(priv, IPW_ORD_CURRENT_TX_RATE, &val, &len);
7110 IPW_DEBUG_WX("failed querying ordinals.\n");
7114 switch (val & TX_RATE_MASK) {
7115 case TX_RATE_1_MBIT:
7116 wrqu->bitrate.value = 1000000;
7118 case TX_RATE_2_MBIT:
7119 wrqu->bitrate.value = 2000000;
7121 case TX_RATE_5_5_MBIT:
7122 wrqu->bitrate.value = 5500000;
7124 case TX_RATE_11_MBIT:
7125 wrqu->bitrate.value = 11000000;
7128 wrqu->bitrate.value = 0;
7131 IPW_DEBUG_WX("GET Rate -> %d\n", wrqu->bitrate.value);
7134 mutex_unlock(&priv->action_mutex);
7138 static int ipw2100_wx_set_rts(struct net_device *dev,
7139 struct iw_request_info *info,
7140 union iwreq_data *wrqu, char *extra)
7142 struct ipw2100_priv *priv = libipw_priv(dev);
7145 /* Auto RTS not yet supported */
7146 if (wrqu->rts.fixed == 0)
7149 mutex_lock(&priv->action_mutex);
7150 if (!(priv->status & STATUS_INITIALIZED)) {
7155 if (wrqu->rts.disabled)
7156 value = priv->rts_threshold | RTS_DISABLED;
7158 if (wrqu->rts.value < 1 || wrqu->rts.value > 2304) {
7162 value = wrqu->rts.value;
7165 err = ipw2100_set_rts_threshold(priv, value);
7167 IPW_DEBUG_WX("SET RTS Threshold -> 0x%08X\n", value);
7169 mutex_unlock(&priv->action_mutex);
7173 static int ipw2100_wx_get_rts(struct net_device *dev,
7174 struct iw_request_info *info,
7175 union iwreq_data *wrqu, char *extra)
7178 * This can be called at any time. No action lock required
7181 struct ipw2100_priv *priv = libipw_priv(dev);
7183 wrqu->rts.value = priv->rts_threshold & ~RTS_DISABLED;
7184 wrqu->rts.fixed = 1; /* no auto select */
7186 /* If RTS is set to the default value, then it is disabled */
7187 wrqu->rts.disabled = (priv->rts_threshold & RTS_DISABLED) ? 1 : 0;
7189 IPW_DEBUG_WX("GET RTS Threshold -> 0x%08X\n", wrqu->rts.value);
7194 static int ipw2100_wx_set_txpow(struct net_device *dev,
7195 struct iw_request_info *info,
7196 union iwreq_data *wrqu, char *extra)
7198 struct ipw2100_priv *priv = libipw_priv(dev);
7201 if (ipw_radio_kill_sw(priv, wrqu->txpower.disabled))
7202 return -EINPROGRESS;
7204 if (priv->ieee->iw_mode != IW_MODE_ADHOC)
7207 if ((wrqu->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
7210 if (wrqu->txpower.fixed == 0)
7211 value = IPW_TX_POWER_DEFAULT;
7213 if (wrqu->txpower.value < IPW_TX_POWER_MIN_DBM ||
7214 wrqu->txpower.value > IPW_TX_POWER_MAX_DBM)
7217 value = wrqu->txpower.value;
7220 mutex_lock(&priv->action_mutex);
7221 if (!(priv->status & STATUS_INITIALIZED)) {
7226 err = ipw2100_set_tx_power(priv, value);
7228 IPW_DEBUG_WX("SET TX Power -> %d\n", value);
7231 mutex_unlock(&priv->action_mutex);
7235 static int ipw2100_wx_get_txpow(struct net_device *dev,
7236 struct iw_request_info *info,
7237 union iwreq_data *wrqu, char *extra)
7240 * This can be called at any time. No action lock required
7243 struct ipw2100_priv *priv = libipw_priv(dev);
7245 wrqu->txpower.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
7247 if (priv->tx_power == IPW_TX_POWER_DEFAULT) {
7248 wrqu->txpower.fixed = 0;
7249 wrqu->txpower.value = IPW_TX_POWER_MAX_DBM;
7251 wrqu->txpower.fixed = 1;
7252 wrqu->txpower.value = priv->tx_power;
7255 wrqu->txpower.flags = IW_TXPOW_DBM;
7257 IPW_DEBUG_WX("GET TX Power -> %d\n", wrqu->txpower.value);
7262 static int ipw2100_wx_set_frag(struct net_device *dev,
7263 struct iw_request_info *info,
7264 union iwreq_data *wrqu, char *extra)
7267 * This can be called at any time. No action lock required
7270 struct ipw2100_priv *priv = libipw_priv(dev);
7272 if (!wrqu->frag.fixed)
7275 if (wrqu->frag.disabled) {
7276 priv->frag_threshold |= FRAG_DISABLED;
7277 priv->ieee->fts = DEFAULT_FTS;
7279 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
7280 wrqu->frag.value > MAX_FRAG_THRESHOLD)
7283 priv->ieee->fts = wrqu->frag.value & ~0x1;
7284 priv->frag_threshold = priv->ieee->fts;
7287 IPW_DEBUG_WX("SET Frag Threshold -> %d\n", priv->ieee->fts);
7292 static int ipw2100_wx_get_frag(struct net_device *dev,
7293 struct iw_request_info *info,
7294 union iwreq_data *wrqu, char *extra)
7297 * This can be called at any time. No action lock required
7300 struct ipw2100_priv *priv = libipw_priv(dev);
7301 wrqu->frag.value = priv->frag_threshold & ~FRAG_DISABLED;
7302 wrqu->frag.fixed = 0; /* no auto select */
7303 wrqu->frag.disabled = (priv->frag_threshold & FRAG_DISABLED) ? 1 : 0;
7305 IPW_DEBUG_WX("GET Frag Threshold -> %d\n", wrqu->frag.value);
7310 static int ipw2100_wx_set_retry(struct net_device *dev,
7311 struct iw_request_info *info,
7312 union iwreq_data *wrqu, char *extra)
7314 struct ipw2100_priv *priv = libipw_priv(dev);
7317 if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
7320 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
7323 mutex_lock(&priv->action_mutex);
7324 if (!(priv->status & STATUS_INITIALIZED)) {
7329 if (wrqu->retry.flags & IW_RETRY_SHORT) {
7330 err = ipw2100_set_short_retry(priv, wrqu->retry.value);
7331 IPW_DEBUG_WX("SET Short Retry Limit -> %d\n",
7336 if (wrqu->retry.flags & IW_RETRY_LONG) {
7337 err = ipw2100_set_long_retry(priv, wrqu->retry.value);
7338 IPW_DEBUG_WX("SET Long Retry Limit -> %d\n",
7343 err = ipw2100_set_short_retry(priv, wrqu->retry.value);
7345 err = ipw2100_set_long_retry(priv, wrqu->retry.value);
7347 IPW_DEBUG_WX("SET Both Retry Limits -> %d\n", wrqu->retry.value);
7350 mutex_unlock(&priv->action_mutex);
7354 static int ipw2100_wx_get_retry(struct net_device *dev,
7355 struct iw_request_info *info,
7356 union iwreq_data *wrqu, char *extra)
7359 * This can be called at any time. No action lock required
7362 struct ipw2100_priv *priv = libipw_priv(dev);
7364 wrqu->retry.disabled = 0; /* can't be disabled */
7366 if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME)
7369 if (wrqu->retry.flags & IW_RETRY_LONG) {
7370 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
7371 wrqu->retry.value = priv->long_retry_limit;
7374 (priv->short_retry_limit !=
7375 priv->long_retry_limit) ?
7376 IW_RETRY_LIMIT | IW_RETRY_SHORT : IW_RETRY_LIMIT;
7378 wrqu->retry.value = priv->short_retry_limit;
7381 IPW_DEBUG_WX("GET Retry -> %d\n", wrqu->retry.value);
7386 static int ipw2100_wx_set_scan(struct net_device *dev,
7387 struct iw_request_info *info,
7388 union iwreq_data *wrqu, char *extra)
7390 struct ipw2100_priv *priv = libipw_priv(dev);
7393 mutex_lock(&priv->action_mutex);
7394 if (!(priv->status & STATUS_INITIALIZED)) {
7399 IPW_DEBUG_WX("Initiating scan...\n");
7401 priv->user_requested_scan = 1;
7402 if (ipw2100_set_scan_options(priv) || ipw2100_start_scan(priv)) {
7403 IPW_DEBUG_WX("Start scan failed.\n");
7405 /* TODO: Mark a scan as pending so when hardware initialized
7410 mutex_unlock(&priv->action_mutex);
7414 static int ipw2100_wx_get_scan(struct net_device *dev,
7415 struct iw_request_info *info,
7416 union iwreq_data *wrqu, char *extra)
7419 * This can be called at any time. No action lock required
7422 struct ipw2100_priv *priv = libipw_priv(dev);
7423 return libipw_wx_get_scan(priv->ieee, info, wrqu, extra);
7427 * Implementation based on code in hostap-driver v0.1.3 hostap_ioctl.c
7429 static int ipw2100_wx_set_encode(struct net_device *dev,
7430 struct iw_request_info *info,
7431 union iwreq_data *wrqu, char *key)
7434 * No check of STATUS_INITIALIZED required
7437 struct ipw2100_priv *priv = libipw_priv(dev);
7438 return libipw_wx_set_encode(priv->ieee, info, wrqu, key);
7441 static int ipw2100_wx_get_encode(struct net_device *dev,
7442 struct iw_request_info *info,
7443 union iwreq_data *wrqu, char *key)
7446 * This can be called at any time. No action lock required
7449 struct ipw2100_priv *priv = libipw_priv(dev);
7450 return libipw_wx_get_encode(priv->ieee, info, wrqu, key);
7453 static int ipw2100_wx_set_power(struct net_device *dev,
7454 struct iw_request_info *info,
7455 union iwreq_data *wrqu, char *extra)
7457 struct ipw2100_priv *priv = libipw_priv(dev);
7460 mutex_lock(&priv->action_mutex);
7461 if (!(priv->status & STATUS_INITIALIZED)) {
7466 if (wrqu->power.disabled) {
7467 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
7468 err = ipw2100_set_power_mode(priv, IPW_POWER_MODE_CAM);
7469 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
7473 switch (wrqu->power.flags & IW_POWER_MODE) {
7474 case IW_POWER_ON: /* If not specified */
7475 case IW_POWER_MODE: /* If set all mask */
7476 case IW_POWER_ALL_R: /* If explicitly state all */
7478 default: /* Otherwise we don't support it */
7479 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
7485 /* If the user hasn't specified a power management mode yet, default
7487 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
7488 err = ipw2100_set_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
7490 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
7493 mutex_unlock(&priv->action_mutex);
7498 static int ipw2100_wx_get_power(struct net_device *dev,
7499 struct iw_request_info *info,
7500 union iwreq_data *wrqu, char *extra)
7503 * This can be called at any time. No action lock required
7506 struct ipw2100_priv *priv = libipw_priv(dev);
7508 if (!(priv->power_mode & IPW_POWER_ENABLED))
7509 wrqu->power.disabled = 1;
7511 wrqu->power.disabled = 0;
7512 wrqu->power.flags = 0;
7515 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
7525 static int ipw2100_wx_set_genie(struct net_device *dev,
7526 struct iw_request_info *info,
7527 union iwreq_data *wrqu, char *extra)
7530 struct ipw2100_priv *priv = libipw_priv(dev);
7531 struct libipw_device *ieee = priv->ieee;
7534 if (!ieee->wpa_enabled)
7537 if (wrqu->data.length > MAX_WPA_IE_LEN ||
7538 (wrqu->data.length && extra == NULL))
7541 if (wrqu->data.length) {
7542 buf = kmemdup(extra, wrqu->data.length, GFP_KERNEL);
7546 kfree(ieee->wpa_ie);
7548 ieee->wpa_ie_len = wrqu->data.length;
7550 kfree(ieee->wpa_ie);
7551 ieee->wpa_ie = NULL;
7552 ieee->wpa_ie_len = 0;
7555 ipw2100_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
7561 static int ipw2100_wx_get_genie(struct net_device *dev,
7562 struct iw_request_info *info,
7563 union iwreq_data *wrqu, char *extra)
7565 struct ipw2100_priv *priv = libipw_priv(dev);
7566 struct libipw_device *ieee = priv->ieee;
7568 if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
7569 wrqu->data.length = 0;
7573 if (wrqu->data.length < ieee->wpa_ie_len)
7576 wrqu->data.length = ieee->wpa_ie_len;
7577 memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
7583 static int ipw2100_wx_set_auth(struct net_device *dev,
7584 struct iw_request_info *info,
7585 union iwreq_data *wrqu, char *extra)
7587 struct ipw2100_priv *priv = libipw_priv(dev);
7588 struct libipw_device *ieee = priv->ieee;
7589 struct iw_param *param = &wrqu->param;
7590 struct lib80211_crypt_data *crypt;
7591 unsigned long flags;
7594 switch (param->flags & IW_AUTH_INDEX) {
7595 case IW_AUTH_WPA_VERSION:
7596 case IW_AUTH_CIPHER_PAIRWISE:
7597 case IW_AUTH_CIPHER_GROUP:
7598 case IW_AUTH_KEY_MGMT:
7600 * ipw2200 does not use these parameters
7604 case IW_AUTH_TKIP_COUNTERMEASURES:
7605 crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx];
7606 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags)
7609 flags = crypt->ops->get_flags(crypt->priv);
7612 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
7614 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
7616 crypt->ops->set_flags(flags, crypt->priv);
7620 case IW_AUTH_DROP_UNENCRYPTED:{
7623 * wpa_supplicant calls set_wpa_enabled when the driver
7624 * is loaded and unloaded, regardless of if WPA is being
7625 * used. No other calls are made which can be used to
7626 * determine if encryption will be used or not prior to
7627 * association being expected. If encryption is not being
7628 * used, drop_unencrypted is set to false, else true -- we
7629 * can use this to determine if the CAP_PRIVACY_ON bit should
7632 struct libipw_security sec = {
7633 .flags = SEC_ENABLED,
7634 .enabled = param->value,
7636 priv->ieee->drop_unencrypted = param->value;
7637 /* We only change SEC_LEVEL for open mode. Others
7638 * are set by ipw_wpa_set_encryption.
7640 if (!param->value) {
7641 sec.flags |= SEC_LEVEL;
7642 sec.level = SEC_LEVEL_0;
7644 sec.flags |= SEC_LEVEL;
7645 sec.level = SEC_LEVEL_1;
7647 if (priv->ieee->set_security)
7648 priv->ieee->set_security(priv->ieee->dev, &sec);
7652 case IW_AUTH_80211_AUTH_ALG:
7653 ret = ipw2100_wpa_set_auth_algs(priv, param->value);
7656 case IW_AUTH_WPA_ENABLED:
7657 ret = ipw2100_wpa_enable(priv, param->value);
7660 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
7661 ieee->ieee802_1x = param->value;
7664 //case IW_AUTH_ROAMING_CONTROL:
7665 case IW_AUTH_PRIVACY_INVOKED:
7666 ieee->privacy_invoked = param->value;
7676 static int ipw2100_wx_get_auth(struct net_device *dev,
7677 struct iw_request_info *info,
7678 union iwreq_data *wrqu, char *extra)
7680 struct ipw2100_priv *priv = libipw_priv(dev);
7681 struct libipw_device *ieee = priv->ieee;
7682 struct lib80211_crypt_data *crypt;
7683 struct iw_param *param = &wrqu->param;
7685 switch (param->flags & IW_AUTH_INDEX) {
7686 case IW_AUTH_WPA_VERSION:
7687 case IW_AUTH_CIPHER_PAIRWISE:
7688 case IW_AUTH_CIPHER_GROUP:
7689 case IW_AUTH_KEY_MGMT:
7691 * wpa_supplicant will control these internally
7695 case IW_AUTH_TKIP_COUNTERMEASURES:
7696 crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx];
7697 if (!crypt || !crypt->ops->get_flags) {
7698 IPW_DEBUG_WARNING("Can't get TKIP countermeasures: "
7699 "crypt not set!\n");
7703 param->value = (crypt->ops->get_flags(crypt->priv) &
7704 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
7708 case IW_AUTH_DROP_UNENCRYPTED:
7709 param->value = ieee->drop_unencrypted;
7712 case IW_AUTH_80211_AUTH_ALG:
7713 param->value = priv->ieee->sec.auth_mode;
7716 case IW_AUTH_WPA_ENABLED:
7717 param->value = ieee->wpa_enabled;
7720 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
7721 param->value = ieee->ieee802_1x;
7724 case IW_AUTH_ROAMING_CONTROL:
7725 case IW_AUTH_PRIVACY_INVOKED:
7726 param->value = ieee->privacy_invoked;
7735 /* SIOCSIWENCODEEXT */
7736 static int ipw2100_wx_set_encodeext(struct net_device *dev,
7737 struct iw_request_info *info,
7738 union iwreq_data *wrqu, char *extra)
7740 struct ipw2100_priv *priv = libipw_priv(dev);
7741 return libipw_wx_set_encodeext(priv->ieee, info, wrqu, extra);
7744 /* SIOCGIWENCODEEXT */
7745 static int ipw2100_wx_get_encodeext(struct net_device *dev,
7746 struct iw_request_info *info,
7747 union iwreq_data *wrqu, char *extra)
7749 struct ipw2100_priv *priv = libipw_priv(dev);
7750 return libipw_wx_get_encodeext(priv->ieee, info, wrqu, extra);
7754 static int ipw2100_wx_set_mlme(struct net_device *dev,
7755 struct iw_request_info *info,
7756 union iwreq_data *wrqu, char *extra)
7758 struct ipw2100_priv *priv = libipw_priv(dev);
7759 struct iw_mlme *mlme = (struct iw_mlme *)extra;
7761 switch (mlme->cmd) {
7762 case IW_MLME_DEAUTH:
7766 case IW_MLME_DISASSOC:
7767 ipw2100_disassociate_bssid(priv);
7781 #ifdef CONFIG_IPW2100_MONITOR
7782 static int ipw2100_wx_set_promisc(struct net_device *dev,
7783 struct iw_request_info *info,
7784 union iwreq_data *wrqu, char *extra)
7786 struct ipw2100_priv *priv = libipw_priv(dev);
7787 int *parms = (int *)extra;
7788 int enable = (parms[0] > 0);
7791 mutex_lock(&priv->action_mutex);
7792 if (!(priv->status & STATUS_INITIALIZED)) {
7798 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7799 err = ipw2100_set_channel(priv, parms[1], 0);
7802 priv->channel = parms[1];
7803 err = ipw2100_switch_mode(priv, IW_MODE_MONITOR);
7805 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
7806 err = ipw2100_switch_mode(priv, priv->last_mode);
7809 mutex_unlock(&priv->action_mutex);
7813 static int ipw2100_wx_reset(struct net_device *dev,
7814 struct iw_request_info *info,
7815 union iwreq_data *wrqu, char *extra)
7817 struct ipw2100_priv *priv = libipw_priv(dev);
7818 if (priv->status & STATUS_INITIALIZED)
7819 schedule_reset(priv);
7825 static int ipw2100_wx_set_powermode(struct net_device *dev,
7826 struct iw_request_info *info,
7827 union iwreq_data *wrqu, char *extra)
7829 struct ipw2100_priv *priv = libipw_priv(dev);
7830 int err = 0, mode = *(int *)extra;
7832 mutex_lock(&priv->action_mutex);
7833 if (!(priv->status & STATUS_INITIALIZED)) {
7838 if ((mode < 0) || (mode > POWER_MODES))
7839 mode = IPW_POWER_AUTO;
7841 if (IPW_POWER_LEVEL(priv->power_mode) != mode)
7842 err = ipw2100_set_power_mode(priv, mode);
7844 mutex_unlock(&priv->action_mutex);
7848 #define MAX_POWER_STRING 80
7849 static int ipw2100_wx_get_powermode(struct net_device *dev,
7850 struct iw_request_info *info,
7851 union iwreq_data *wrqu, char *extra)
7854 * This can be called at any time. No action lock required
7857 struct ipw2100_priv *priv = libipw_priv(dev);
7858 int level = IPW_POWER_LEVEL(priv->power_mode);
7859 s32 timeout, period;
7861 if (!(priv->power_mode & IPW_POWER_ENABLED)) {
7862 snprintf(extra, MAX_POWER_STRING,
7863 "Power save level: %d (Off)", level);
7866 case IPW_POWER_MODE_CAM:
7867 snprintf(extra, MAX_POWER_STRING,
7868 "Power save level: %d (None)", level);
7870 case IPW_POWER_AUTO:
7871 snprintf(extra, MAX_POWER_STRING,
7872 "Power save level: %d (Auto)", level);
7875 timeout = timeout_duration[level - 1] / 1000;
7876 period = period_duration[level - 1] / 1000;
7877 snprintf(extra, MAX_POWER_STRING,
7878 "Power save level: %d "
7879 "(Timeout %dms, Period %dms)",
7880 level, timeout, period);
7884 wrqu->data.length = strlen(extra) + 1;
7889 static int ipw2100_wx_set_preamble(struct net_device *dev,
7890 struct iw_request_info *info,
7891 union iwreq_data *wrqu, char *extra)
7893 struct ipw2100_priv *priv = libipw_priv(dev);
7894 int err, mode = *(int *)extra;
7896 mutex_lock(&priv->action_mutex);
7897 if (!(priv->status & STATUS_INITIALIZED)) {
7903 priv->config |= CFG_LONG_PREAMBLE;
7905 priv->config &= ~CFG_LONG_PREAMBLE;
7911 err = ipw2100_system_config(priv, 0);
7914 mutex_unlock(&priv->action_mutex);
7918 static int ipw2100_wx_get_preamble(struct net_device *dev,
7919 struct iw_request_info *info,
7920 union iwreq_data *wrqu, char *extra)
7923 * This can be called at any time. No action lock required
7926 struct ipw2100_priv *priv = libipw_priv(dev);
7928 if (priv->config & CFG_LONG_PREAMBLE)
7929 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
7931 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
7936 #ifdef CONFIG_IPW2100_MONITOR
7937 static int ipw2100_wx_set_crc_check(struct net_device *dev,
7938 struct iw_request_info *info,
7939 union iwreq_data *wrqu, char *extra)
7941 struct ipw2100_priv *priv = libipw_priv(dev);
7942 int err, mode = *(int *)extra;
7944 mutex_lock(&priv->action_mutex);
7945 if (!(priv->status & STATUS_INITIALIZED)) {
7951 priv->config |= CFG_CRC_CHECK;
7953 priv->config &= ~CFG_CRC_CHECK;
7961 mutex_unlock(&priv->action_mutex);
7965 static int ipw2100_wx_get_crc_check(struct net_device *dev,
7966 struct iw_request_info *info,
7967 union iwreq_data *wrqu, char *extra)
7970 * This can be called at any time. No action lock required
7973 struct ipw2100_priv *priv = libipw_priv(dev);
7975 if (priv->config & CFG_CRC_CHECK)
7976 snprintf(wrqu->name, IFNAMSIZ, "CRC checked (1)");
7978 snprintf(wrqu->name, IFNAMSIZ, "CRC ignored (0)");
7982 #endif /* CONFIG_IPW2100_MONITOR */
7984 static iw_handler ipw2100_wx_handlers[] = {
7985 IW_HANDLER(SIOCGIWNAME, ipw2100_wx_get_name),
7986 IW_HANDLER(SIOCSIWFREQ, ipw2100_wx_set_freq),
7987 IW_HANDLER(SIOCGIWFREQ, ipw2100_wx_get_freq),
7988 IW_HANDLER(SIOCSIWMODE, ipw2100_wx_set_mode),
7989 IW_HANDLER(SIOCGIWMODE, ipw2100_wx_get_mode),
7990 IW_HANDLER(SIOCGIWRANGE, ipw2100_wx_get_range),
7991 IW_HANDLER(SIOCSIWAP, ipw2100_wx_set_wap),
7992 IW_HANDLER(SIOCGIWAP, ipw2100_wx_get_wap),
7993 IW_HANDLER(SIOCSIWMLME, ipw2100_wx_set_mlme),
7994 IW_HANDLER(SIOCSIWSCAN, ipw2100_wx_set_scan),
7995 IW_HANDLER(SIOCGIWSCAN, ipw2100_wx_get_scan),
7996 IW_HANDLER(SIOCSIWESSID, ipw2100_wx_set_essid),
7997 IW_HANDLER(SIOCGIWESSID, ipw2100_wx_get_essid),
7998 IW_HANDLER(SIOCSIWNICKN, ipw2100_wx_set_nick),
7999 IW_HANDLER(SIOCGIWNICKN, ipw2100_wx_get_nick),
8000 IW_HANDLER(SIOCSIWRATE, ipw2100_wx_set_rate),
8001 IW_HANDLER(SIOCGIWRATE, ipw2100_wx_get_rate),
8002 IW_HANDLER(SIOCSIWRTS, ipw2100_wx_set_rts),
8003 IW_HANDLER(SIOCGIWRTS, ipw2100_wx_get_rts),
8004 IW_HANDLER(SIOCSIWFRAG, ipw2100_wx_set_frag),
8005 IW_HANDLER(SIOCGIWFRAG, ipw2100_wx_get_frag),
8006 IW_HANDLER(SIOCSIWTXPOW, ipw2100_wx_set_txpow),
8007 IW_HANDLER(SIOCGIWTXPOW, ipw2100_wx_get_txpow),
8008 IW_HANDLER(SIOCSIWRETRY, ipw2100_wx_set_retry),
8009 IW_HANDLER(SIOCGIWRETRY, ipw2100_wx_get_retry),
8010 IW_HANDLER(SIOCSIWENCODE, ipw2100_wx_set_encode),
8011 IW_HANDLER(SIOCGIWENCODE, ipw2100_wx_get_encode),
8012 IW_HANDLER(SIOCSIWPOWER, ipw2100_wx_set_power),
8013 IW_HANDLER(SIOCGIWPOWER, ipw2100_wx_get_power),
8014 IW_HANDLER(SIOCSIWGENIE, ipw2100_wx_set_genie),
8015 IW_HANDLER(SIOCGIWGENIE, ipw2100_wx_get_genie),
8016 IW_HANDLER(SIOCSIWAUTH, ipw2100_wx_set_auth),
8017 IW_HANDLER(SIOCGIWAUTH, ipw2100_wx_get_auth),
8018 IW_HANDLER(SIOCSIWENCODEEXT, ipw2100_wx_set_encodeext),
8019 IW_HANDLER(SIOCGIWENCODEEXT, ipw2100_wx_get_encodeext),
8022 #define IPW2100_PRIV_SET_MONITOR SIOCIWFIRSTPRIV
8023 #define IPW2100_PRIV_RESET SIOCIWFIRSTPRIV+1
8024 #define IPW2100_PRIV_SET_POWER SIOCIWFIRSTPRIV+2
8025 #define IPW2100_PRIV_GET_POWER SIOCIWFIRSTPRIV+3
8026 #define IPW2100_PRIV_SET_LONGPREAMBLE SIOCIWFIRSTPRIV+4
8027 #define IPW2100_PRIV_GET_LONGPREAMBLE SIOCIWFIRSTPRIV+5
8028 #define IPW2100_PRIV_SET_CRC_CHECK SIOCIWFIRSTPRIV+6
8029 #define IPW2100_PRIV_GET_CRC_CHECK SIOCIWFIRSTPRIV+7
8031 static const struct iw_priv_args ipw2100_private_args[] = {
8033 #ifdef CONFIG_IPW2100_MONITOR
8035 IPW2100_PRIV_SET_MONITOR,
8036 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
8039 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
8040 #endif /* CONFIG_IPW2100_MONITOR */
8043 IPW2100_PRIV_SET_POWER,
8044 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_power"},
8046 IPW2100_PRIV_GET_POWER,
8047 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_POWER_STRING,
8050 IPW2100_PRIV_SET_LONGPREAMBLE,
8051 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_preamble"},
8053 IPW2100_PRIV_GET_LONGPREAMBLE,
8054 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, "get_preamble"},
8055 #ifdef CONFIG_IPW2100_MONITOR
8057 IPW2100_PRIV_SET_CRC_CHECK,
8058 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_crc_check"},
8060 IPW2100_PRIV_GET_CRC_CHECK,
8061 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, "get_crc_check"},
8062 #endif /* CONFIG_IPW2100_MONITOR */
8065 static iw_handler ipw2100_private_handler[] = {
8066 #ifdef CONFIG_IPW2100_MONITOR
8067 ipw2100_wx_set_promisc,
8069 #else /* CONFIG_IPW2100_MONITOR */
8072 #endif /* CONFIG_IPW2100_MONITOR */
8073 ipw2100_wx_set_powermode,
8074 ipw2100_wx_get_powermode,
8075 ipw2100_wx_set_preamble,
8076 ipw2100_wx_get_preamble,
8077 #ifdef CONFIG_IPW2100_MONITOR
8078 ipw2100_wx_set_crc_check,
8079 ipw2100_wx_get_crc_check,
8080 #else /* CONFIG_IPW2100_MONITOR */
8083 #endif /* CONFIG_IPW2100_MONITOR */
8087 * Get wireless statistics.
8088 * Called by /proc/net/wireless
8089 * Also called by SIOCGIWSTATS
8091 static struct iw_statistics *ipw2100_wx_wireless_stats(struct net_device *dev)
8106 struct ipw2100_priv *priv = libipw_priv(dev);
8107 struct iw_statistics *wstats;
8108 u32 rssi, tx_retries, missed_beacons, tx_failures;
8109 u32 ord_len = sizeof(u32);
8112 return (struct iw_statistics *)NULL;
8114 wstats = &priv->wstats;
8116 /* if hw is disabled, then ipw2100_get_ordinal() can't be called.
8117 * ipw2100_wx_wireless_stats seems to be called before fw is
8118 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
8119 * and associated; if not associcated, the values are all meaningless
8120 * anyway, so set them all to NULL and INVALID */
8121 if (!(priv->status & STATUS_ASSOCIATED)) {
8122 wstats->miss.beacon = 0;
8123 wstats->discard.retries = 0;
8124 wstats->qual.qual = 0;
8125 wstats->qual.level = 0;
8126 wstats->qual.noise = 0;
8127 wstats->qual.updated = 7;
8128 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
8129 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
8133 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_PERCENT_MISSED_BCNS,
8134 &missed_beacons, &ord_len))
8135 goto fail_get_ordinal;
8137 /* If we don't have a connection the quality and level is 0 */
8138 if (!(priv->status & STATUS_ASSOCIATED)) {
8139 wstats->qual.qual = 0;
8140 wstats->qual.level = 0;
8142 if (ipw2100_get_ordinal(priv, IPW_ORD_RSSI_AVG_CURR,
8144 goto fail_get_ordinal;
8145 wstats->qual.level = rssi + IPW2100_RSSI_TO_DBM;
8147 rssi_qual = rssi * POOR / 10;
8149 rssi_qual = (rssi - 10) * (FAIR - POOR) / 5 + POOR;
8151 rssi_qual = (rssi - 15) * (GOOD - FAIR) / 5 + FAIR;
8153 rssi_qual = (rssi - 20) * (VERY_GOOD - GOOD) /
8156 rssi_qual = (rssi - 30) * (PERFECT - VERY_GOOD) /
8159 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_PERCENT_RETRIES,
8160 &tx_retries, &ord_len))
8161 goto fail_get_ordinal;
8163 if (tx_retries > 75)
8164 tx_qual = (90 - tx_retries) * POOR / 15;
8165 else if (tx_retries > 70)
8166 tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
8167 else if (tx_retries > 65)
8168 tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
8169 else if (tx_retries > 50)
8170 tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
8173 tx_qual = (50 - tx_retries) *
8174 (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
8176 if (missed_beacons > 50)
8177 beacon_qual = (60 - missed_beacons) * POOR / 10;
8178 else if (missed_beacons > 40)
8179 beacon_qual = (50 - missed_beacons) * (FAIR - POOR) /
8181 else if (missed_beacons > 32)
8182 beacon_qual = (40 - missed_beacons) * (GOOD - FAIR) /
8184 else if (missed_beacons > 20)
8185 beacon_qual = (32 - missed_beacons) *
8186 (VERY_GOOD - GOOD) / 20 + GOOD;
8188 beacon_qual = (20 - missed_beacons) *
8189 (PERFECT - VERY_GOOD) / 20 + VERY_GOOD;
8191 quality = min(tx_qual, rssi_qual);
8192 quality = min(beacon_qual, quality);
8194 #ifdef CONFIG_IPW2100_DEBUG
8195 if (beacon_qual == quality)
8196 IPW_DEBUG_WX("Quality clamped by Missed Beacons\n");
8197 else if (tx_qual == quality)
8198 IPW_DEBUG_WX("Quality clamped by Tx Retries\n");
8199 else if (quality != 100)
8200 IPW_DEBUG_WX("Quality clamped by Signal Strength\n");
8202 IPW_DEBUG_WX("Quality not clamped.\n");
8205 wstats->qual.qual = quality;
8206 wstats->qual.level = rssi + IPW2100_RSSI_TO_DBM;
8209 wstats->qual.noise = 0;
8210 wstats->qual.updated = 7;
8211 wstats->qual.updated |= IW_QUAL_NOISE_INVALID;
8213 /* FIXME: this is percent and not a # */
8214 wstats->miss.beacon = missed_beacons;
8216 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURES,
8217 &tx_failures, &ord_len))
8218 goto fail_get_ordinal;
8219 wstats->discard.retries = tx_failures;
8224 IPW_DEBUG_WX("failed querying ordinals.\n");
8226 return (struct iw_statistics *)NULL;
8229 static const struct iw_handler_def ipw2100_wx_handler_def = {
8230 .standard = ipw2100_wx_handlers,
8231 .num_standard = ARRAY_SIZE(ipw2100_wx_handlers),
8232 .num_private = ARRAY_SIZE(ipw2100_private_handler),
8233 .num_private_args = ARRAY_SIZE(ipw2100_private_args),
8234 .private = (iw_handler *) ipw2100_private_handler,
8235 .private_args = (struct iw_priv_args *)ipw2100_private_args,
8236 .get_wireless_stats = ipw2100_wx_wireless_stats,
8239 static void ipw2100_wx_event_work(struct work_struct *work)
8241 struct ipw2100_priv *priv =
8242 container_of(work, struct ipw2100_priv, wx_event_work.work);
8243 union iwreq_data wrqu;
8244 unsigned int len = ETH_ALEN;
8246 if (priv->status & STATUS_STOPPING)
8249 mutex_lock(&priv->action_mutex);
8251 IPW_DEBUG_WX("enter\n");
8253 mutex_unlock(&priv->action_mutex);
8255 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
8257 /* Fetch BSSID from the hardware */
8258 if (!(priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) ||
8259 priv->status & STATUS_RF_KILL_MASK ||
8260 ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID,
8261 &priv->bssid, &len)) {
8262 eth_zero_addr(wrqu.ap_addr.sa_data);
8264 /* We now have the BSSID, so can finish setting to the full
8265 * associated state */
8266 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
8267 memcpy(priv->ieee->bssid, priv->bssid, ETH_ALEN);
8268 priv->status &= ~STATUS_ASSOCIATING;
8269 priv->status |= STATUS_ASSOCIATED;
8270 netif_carrier_on(priv->net_dev);
8271 netif_wake_queue(priv->net_dev);
8274 if (!(priv->status & STATUS_ASSOCIATED)) {
8275 IPW_DEBUG_WX("Configuring ESSID\n");
8276 mutex_lock(&priv->action_mutex);
8277 /* This is a disassociation event, so kick the firmware to
8278 * look for another AP */
8279 if (priv->config & CFG_STATIC_ESSID)
8280 ipw2100_set_essid(priv, priv->essid, priv->essid_len,
8283 ipw2100_set_essid(priv, NULL, 0, 0);
8284 mutex_unlock(&priv->action_mutex);
8287 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
8290 #define IPW2100_FW_MAJOR_VERSION 1
8291 #define IPW2100_FW_MINOR_VERSION 3
8293 #define IPW2100_FW_MINOR(x) ((x & 0xff) >> 8)
8294 #define IPW2100_FW_MAJOR(x) (x & 0xff)
8296 #define IPW2100_FW_VERSION ((IPW2100_FW_MINOR_VERSION << 8) | \
8297 IPW2100_FW_MAJOR_VERSION)
8299 #define IPW2100_FW_PREFIX "ipw2100-" __stringify(IPW2100_FW_MAJOR_VERSION) \
8300 "." __stringify(IPW2100_FW_MINOR_VERSION)
8302 #define IPW2100_FW_NAME(x) IPW2100_FW_PREFIX "" x ".fw"
8306 BINARY FIRMWARE HEADER FORMAT
8310 2 2 mode == 0:BSS,1:IBSS,2:MONITOR
8313 C fw_len firmware data
8314 12 + fw_len uc_len microcode data
8318 struct ipw2100_fw_header {
8321 unsigned int fw_size;
8322 unsigned int uc_size;
8325 static int ipw2100_mod_firmware_load(struct ipw2100_fw *fw)
8327 struct ipw2100_fw_header *h =
8328 (struct ipw2100_fw_header *)fw->fw_entry->data;
8330 if (IPW2100_FW_MAJOR(h->version) != IPW2100_FW_MAJOR_VERSION) {
8331 printk(KERN_WARNING DRV_NAME ": Firmware image not compatible "
8332 "(detected version id of %u). "
8333 "See Documentation/networking/device_drivers/wifi/intel/ipw2100.rst\n",
8338 fw->version = h->version;
8339 fw->fw.data = fw->fw_entry->data + sizeof(struct ipw2100_fw_header);
8340 fw->fw.size = h->fw_size;
8341 fw->uc.data = fw->fw.data + h->fw_size;
8342 fw->uc.size = h->uc_size;
8347 static int ipw2100_get_firmware(struct ipw2100_priv *priv,
8348 struct ipw2100_fw *fw)
8353 IPW_DEBUG_INFO("%s: Using hotplug firmware load.\n",
8354 priv->net_dev->name);
8356 switch (priv->ieee->iw_mode) {
8358 fw_name = IPW2100_FW_NAME("-i");
8360 #ifdef CONFIG_IPW2100_MONITOR
8361 case IW_MODE_MONITOR:
8362 fw_name = IPW2100_FW_NAME("-p");
8367 fw_name = IPW2100_FW_NAME("");
8371 rc = request_firmware(&fw->fw_entry, fw_name, &priv->pci_dev->dev);
8374 printk(KERN_ERR DRV_NAME ": "
8375 "%s: Firmware '%s' not available or load failed.\n",
8376 priv->net_dev->name, fw_name);
8379 IPW_DEBUG_INFO("firmware data %p size %zd\n", fw->fw_entry->data,
8380 fw->fw_entry->size);
8382 ipw2100_mod_firmware_load(fw);
8387 MODULE_FIRMWARE(IPW2100_FW_NAME("-i"));
8388 #ifdef CONFIG_IPW2100_MONITOR
8389 MODULE_FIRMWARE(IPW2100_FW_NAME("-p"));
8391 MODULE_FIRMWARE(IPW2100_FW_NAME(""));
8393 static void ipw2100_release_firmware(struct ipw2100_priv *priv,
8394 struct ipw2100_fw *fw)
8397 release_firmware(fw->fw_entry);
8398 fw->fw_entry = NULL;
8401 static int ipw2100_get_fwversion(struct ipw2100_priv *priv, char *buf,
8404 char ver[MAX_FW_VERSION_LEN];
8405 u32 len = MAX_FW_VERSION_LEN;
8408 /* firmware version is an ascii string (max len of 14) */
8409 if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_FW_VER_NUM, ver, &len))
8414 for (i = 0; i < len; i++)
8420 static int ipw2100_get_ucodeversion(struct ipw2100_priv *priv, char *buf,
8424 u32 len = sizeof(ver);
8425 /* microcode version is a 32 bit integer */
8426 if (ipw2100_get_ordinal(priv, IPW_ORD_UCODE_VERSION, &ver, &len))
8428 return snprintf(buf, max, "%08X", ver);
8432 * On exit, the firmware will have been freed from the fw list
8434 static int ipw2100_fw_download(struct ipw2100_priv *priv, struct ipw2100_fw *fw)
8436 /* firmware is constructed of N contiguous entries, each entry is
8440 * 0 4 address to write to
8441 * 4 2 length of data run
8447 const unsigned char *firmware_data = fw->fw.data;
8448 unsigned int firmware_data_left = fw->fw.size;
8450 while (firmware_data_left > 0) {
8451 addr = *(u32 *) (firmware_data);
8453 firmware_data_left -= 4;
8455 len = *(u16 *) (firmware_data);
8457 firmware_data_left -= 2;
8460 printk(KERN_ERR DRV_NAME ": "
8461 "Invalid firmware run-length of %d bytes\n",
8466 write_nic_memory(priv->net_dev, addr, len, firmware_data);
8467 firmware_data += len;
8468 firmware_data_left -= len;
8474 struct symbol_alive_response {
8483 u16 clock_settle_time; // 1us LSB
8484 u16 powerup_settle_time; // 1us LSB
8485 u16 hop_settle_time; // 1us LSB
8486 u8 date[3]; // month, day, year
8487 u8 time[2]; // hours, minutes
8491 static int ipw2100_ucode_download(struct ipw2100_priv *priv,
8492 struct ipw2100_fw *fw)
8494 struct net_device *dev = priv->net_dev;
8495 const unsigned char *microcode_data = fw->uc.data;
8496 unsigned int microcode_data_left = fw->uc.size;
8497 void __iomem *reg = priv->ioaddr;
8499 struct symbol_alive_response response;
8503 /* Symbol control */
8504 write_nic_word(dev, IPW2100_CONTROL_REG, 0x703);
8506 write_nic_word(dev, IPW2100_CONTROL_REG, 0x707);
8510 write_nic_byte(dev, 0x210014, 0x72); /* fifo width =16 */
8512 write_nic_byte(dev, 0x210014, 0x72); /* fifo width =16 */
8515 /* EN_CS_ACCESS bit to reset control store pointer */
8516 write_nic_byte(dev, 0x210000, 0x40);
8518 write_nic_byte(dev, 0x210000, 0x0);
8520 write_nic_byte(dev, 0x210000, 0x40);
8523 /* copy microcode from buffer into Symbol */
8525 while (microcode_data_left > 0) {
8526 write_nic_byte(dev, 0x210010, *microcode_data++);
8527 write_nic_byte(dev, 0x210010, *microcode_data++);
8528 microcode_data_left -= 2;
8531 /* EN_CS_ACCESS bit to reset the control store pointer */
8532 write_nic_byte(dev, 0x210000, 0x0);
8535 /* Enable System (Reg 0)
8536 * first enable causes garbage in RX FIFO */
8537 write_nic_byte(dev, 0x210000, 0x0);
8539 write_nic_byte(dev, 0x210000, 0x80);
8542 /* Reset External Baseband Reg */
8543 write_nic_word(dev, IPW2100_CONTROL_REG, 0x703);
8545 write_nic_word(dev, IPW2100_CONTROL_REG, 0x707);
8548 /* HW Config (Reg 5) */
8549 write_nic_byte(dev, 0x210014, 0x72); // fifo width =16
8551 write_nic_byte(dev, 0x210014, 0x72); // fifo width =16
8554 /* Enable System (Reg 0)
8555 * second enable should be OK */
8556 write_nic_byte(dev, 0x210000, 0x00); // clear enable system
8558 write_nic_byte(dev, 0x210000, 0x80); // set enable system
8560 /* check Symbol is enabled - upped this from 5 as it wasn't always
8561 * catching the update */
8562 for (i = 0; i < 10; i++) {
8565 /* check Dino is enabled bit */
8566 read_nic_byte(dev, 0x210000, &data);
8572 printk(KERN_ERR DRV_NAME ": %s: Error initializing Symbol\n",
8577 /* Get Symbol alive response */
8578 for (i = 0; i < 30; i++) {
8579 /* Read alive response structure */
8581 j < (sizeof(struct symbol_alive_response) >> 1); j++)
8582 read_nic_word(dev, 0x210004, ((u16 *) & response) + j);
8584 if ((response.cmd_id == 1) && (response.ucode_valid == 0x1))
8590 printk(KERN_ERR DRV_NAME
8591 ": %s: No response from Symbol - hw not alive\n",
8593 printk_buf(IPW_DL_ERROR, (u8 *) & response, sizeof(response));