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>
154 #define IPW2100_VERSION "git-1.2.2"
156 #define DRV_NAME "ipw2100"
157 #define DRV_VERSION IPW2100_VERSION
158 #define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2100 Network Driver"
159 #define DRV_COPYRIGHT "Copyright(c) 2003-2006 Intel Corporation"
161 static struct pm_qos_request ipw2100_pm_qos_req
;
163 /* Debugging stuff */
164 #ifdef CONFIG_IPW2100_DEBUG
165 #define IPW2100_RX_DEBUG /* Reception debugging */
168 MODULE_DESCRIPTION(DRV_DESCRIPTION
);
169 MODULE_VERSION(DRV_VERSION
);
170 MODULE_AUTHOR(DRV_COPYRIGHT
);
171 MODULE_LICENSE("GPL");
173 static int debug
= 0;
174 static int network_mode
= 0;
175 static int channel
= 0;
176 static int associate
= 0;
177 static int disable
= 0;
179 static struct ipw2100_fw ipw2100_firmware
;
182 #include <linux/moduleparam.h>
183 module_param(debug
, int, 0444);
184 module_param_named(mode
, network_mode
, int, 0444);
185 module_param(channel
, int, 0444);
186 module_param(associate
, int, 0444);
187 module_param(disable
, int, 0444);
189 MODULE_PARM_DESC(debug
, "debug level");
190 MODULE_PARM_DESC(mode
, "network mode (0=BSS,1=IBSS,2=Monitor)");
191 MODULE_PARM_DESC(channel
, "channel");
192 MODULE_PARM_DESC(associate
, "auto associate when scanning (default off)");
193 MODULE_PARM_DESC(disable
, "manually disable the radio (default 0 [radio on])");
195 static u32 ipw2100_debug_level
= IPW_DL_NONE
;
197 #ifdef CONFIG_IPW2100_DEBUG
198 #define IPW_DEBUG(level, message...) \
200 if (ipw2100_debug_level & (level)) { \
201 printk(KERN_DEBUG "ipw2100: %s ", __func__); \
206 #define IPW_DEBUG(level, message...) do {} while (0)
207 #endif /* CONFIG_IPW2100_DEBUG */
209 #ifdef CONFIG_IPW2100_DEBUG
210 static const char *command_types
[] = {
212 "unused", /* HOST_ATTENTION */
214 "unused", /* SLEEP */
215 "unused", /* HOST_POWER_DOWN */
218 "unused", /* SET_IMR */
221 "AUTHENTICATION_TYPE",
224 "INTERNATIONAL_MODE",
239 "CLEAR_ALL_MULTICAST",
260 "AP_OR_STATION_TABLE",
264 "unused", /* SAVE_CALIBRATION */
265 "unused", /* RESTORE_CALIBRATION */
269 "HOST_PRE_POWER_DOWN",
270 "unused", /* HOST_INTERRUPT_COALESCING */
272 "CARD_DISABLE_PHY_OFF",
275 "SET_STATION_STAT_BITS",
276 "CLEAR_STATIONS_STAT_BITS",
278 "SET_SECURITY_INFORMATION",
279 "DISASSOCIATION_BSSID",
284 static const long ipw2100_frequencies
[] = {
285 2412, 2417, 2422, 2427,
286 2432, 2437, 2442, 2447,
287 2452, 2457, 2462, 2467,
291 #define FREQ_COUNT ARRAY_SIZE(ipw2100_frequencies)
293 static struct ieee80211_rate ipw2100_bg_rates
[] = {
295 { .bitrate
= 20, .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
296 { .bitrate
= 55, .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
297 { .bitrate
= 110, .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
300 #define RATE_COUNT ARRAY_SIZE(ipw2100_bg_rates)
302 /* Pre-decl until we get the code solid and then we can clean it up */
303 static void ipw2100_tx_send_commands(struct ipw2100_priv
*priv
);
304 static void ipw2100_tx_send_data(struct ipw2100_priv
*priv
);
305 static int ipw2100_adapter_setup(struct ipw2100_priv
*priv
);
307 static void ipw2100_queues_initialize(struct ipw2100_priv
*priv
);
308 static void ipw2100_queues_free(struct ipw2100_priv
*priv
);
309 static int ipw2100_queues_allocate(struct ipw2100_priv
*priv
);
311 static int ipw2100_fw_download(struct ipw2100_priv
*priv
,
312 struct ipw2100_fw
*fw
);
313 static int ipw2100_get_firmware(struct ipw2100_priv
*priv
,
314 struct ipw2100_fw
*fw
);
315 static int ipw2100_get_fwversion(struct ipw2100_priv
*priv
, char *buf
,
317 static void ipw2100_release_firmware(struct ipw2100_priv
*priv
,
318 struct ipw2100_fw
*fw
);
319 static int ipw2100_ucode_download(struct ipw2100_priv
*priv
,
320 struct ipw2100_fw
*fw
);
321 static void ipw2100_wx_event_work(struct work_struct
*work
);
322 static struct iw_statistics
*ipw2100_wx_wireless_stats(struct net_device
*dev
);
323 static const struct iw_handler_def ipw2100_wx_handler_def
;
325 static inline void read_register(struct net_device
*dev
, u32 reg
, u32
* val
)
327 struct ipw2100_priv
*priv
= libipw_priv(dev
);
329 *val
= ioread32(priv
->ioaddr
+ reg
);
330 IPW_DEBUG_IO("r: 0x%08X => 0x%08X\n", reg
, *val
);
333 static inline void write_register(struct net_device
*dev
, u32 reg
, u32 val
)
335 struct ipw2100_priv
*priv
= libipw_priv(dev
);
337 iowrite32(val
, priv
->ioaddr
+ reg
);
338 IPW_DEBUG_IO("w: 0x%08X <= 0x%08X\n", reg
, val
);
341 static inline void read_register_word(struct net_device
*dev
, u32 reg
,
344 struct ipw2100_priv
*priv
= libipw_priv(dev
);
346 *val
= ioread16(priv
->ioaddr
+ reg
);
347 IPW_DEBUG_IO("r: 0x%08X => %04X\n", reg
, *val
);
350 static inline void read_register_byte(struct net_device
*dev
, u32 reg
, u8
* val
)
352 struct ipw2100_priv
*priv
= libipw_priv(dev
);
354 *val
= ioread8(priv
->ioaddr
+ reg
);
355 IPW_DEBUG_IO("r: 0x%08X => %02X\n", reg
, *val
);
358 static inline void write_register_word(struct net_device
*dev
, u32 reg
, u16 val
)
360 struct ipw2100_priv
*priv
= libipw_priv(dev
);
362 iowrite16(val
, priv
->ioaddr
+ reg
);
363 IPW_DEBUG_IO("w: 0x%08X <= %04X\n", reg
, val
);
366 static inline void write_register_byte(struct net_device
*dev
, u32 reg
, u8 val
)
368 struct ipw2100_priv
*priv
= libipw_priv(dev
);
370 iowrite8(val
, priv
->ioaddr
+ reg
);
371 IPW_DEBUG_IO("w: 0x%08X =< %02X\n", reg
, val
);
374 static inline void read_nic_dword(struct net_device
*dev
, u32 addr
, u32
* val
)
376 write_register(dev
, IPW_REG_INDIRECT_ACCESS_ADDRESS
,
377 addr
& IPW_REG_INDIRECT_ADDR_MASK
);
378 read_register(dev
, IPW_REG_INDIRECT_ACCESS_DATA
, val
);
381 static inline void write_nic_dword(struct net_device
*dev
, u32 addr
, u32 val
)
383 write_register(dev
, IPW_REG_INDIRECT_ACCESS_ADDRESS
,
384 addr
& IPW_REG_INDIRECT_ADDR_MASK
);
385 write_register(dev
, IPW_REG_INDIRECT_ACCESS_DATA
, val
);
388 static inline void read_nic_word(struct net_device
*dev
, u32 addr
, u16
* val
)
390 write_register(dev
, IPW_REG_INDIRECT_ACCESS_ADDRESS
,
391 addr
& IPW_REG_INDIRECT_ADDR_MASK
);
392 read_register_word(dev
, IPW_REG_INDIRECT_ACCESS_DATA
, val
);
395 static inline void write_nic_word(struct net_device
*dev
, u32 addr
, u16 val
)
397 write_register(dev
, IPW_REG_INDIRECT_ACCESS_ADDRESS
,
398 addr
& IPW_REG_INDIRECT_ADDR_MASK
);
399 write_register_word(dev
, IPW_REG_INDIRECT_ACCESS_DATA
, val
);
402 static inline void read_nic_byte(struct net_device
*dev
, u32 addr
, u8
* val
)
404 write_register(dev
, IPW_REG_INDIRECT_ACCESS_ADDRESS
,
405 addr
& IPW_REG_INDIRECT_ADDR_MASK
);
406 read_register_byte(dev
, IPW_REG_INDIRECT_ACCESS_DATA
, val
);
409 static inline void write_nic_byte(struct net_device
*dev
, u32 addr
, u8 val
)
411 write_register(dev
, IPW_REG_INDIRECT_ACCESS_ADDRESS
,
412 addr
& IPW_REG_INDIRECT_ADDR_MASK
);
413 write_register_byte(dev
, IPW_REG_INDIRECT_ACCESS_DATA
, val
);
416 static void write_nic_memory(struct net_device
*dev
, u32 addr
, u32 len
,
424 /* read first nibble byte by byte */
425 aligned_addr
= addr
& (~0x3);
426 dif_len
= addr
- aligned_addr
;
428 /* Start reading at aligned_addr + dif_len */
429 write_register(dev
, IPW_REG_INDIRECT_ACCESS_ADDRESS
,
431 for (i
= dif_len
; i
< 4; i
++, buf
++)
432 write_register_byte(dev
,
433 IPW_REG_INDIRECT_ACCESS_DATA
+ i
,
440 /* read DWs through autoincrement registers */
441 write_register(dev
, IPW_REG_AUTOINCREMENT_ADDRESS
, aligned_addr
);
442 aligned_len
= len
& (~0x3);
443 for (i
= 0; i
< aligned_len
; i
+= 4, buf
+= 4, aligned_addr
+= 4)
444 write_register(dev
, IPW_REG_AUTOINCREMENT_DATA
, *(u32
*) buf
);
446 /* copy the last nibble */
447 dif_len
= len
- aligned_len
;
448 write_register(dev
, IPW_REG_INDIRECT_ACCESS_ADDRESS
, aligned_addr
);
449 for (i
= 0; i
< dif_len
; i
++, buf
++)
450 write_register_byte(dev
, IPW_REG_INDIRECT_ACCESS_DATA
+ i
,
454 static void read_nic_memory(struct net_device
*dev
, u32 addr
, u32 len
,
462 /* read first nibble byte by byte */
463 aligned_addr
= addr
& (~0x3);
464 dif_len
= addr
- aligned_addr
;
466 /* Start reading at aligned_addr + dif_len */
467 write_register(dev
, IPW_REG_INDIRECT_ACCESS_ADDRESS
,
469 for (i
= dif_len
; i
< 4; i
++, buf
++)
470 read_register_byte(dev
,
471 IPW_REG_INDIRECT_ACCESS_DATA
+ i
,
478 /* read DWs through autoincrement registers */
479 write_register(dev
, IPW_REG_AUTOINCREMENT_ADDRESS
, aligned_addr
);
480 aligned_len
= len
& (~0x3);
481 for (i
= 0; i
< aligned_len
; i
+= 4, buf
+= 4, aligned_addr
+= 4)
482 read_register(dev
, IPW_REG_AUTOINCREMENT_DATA
, (u32
*) buf
);
484 /* copy the last nibble */
485 dif_len
= len
- aligned_len
;
486 write_register(dev
, IPW_REG_INDIRECT_ACCESS_ADDRESS
, aligned_addr
);
487 for (i
= 0; i
< dif_len
; i
++, buf
++)
488 read_register_byte(dev
, IPW_REG_INDIRECT_ACCESS_DATA
+ i
, buf
);
491 static bool ipw2100_hw_is_adapter_in_system(struct net_device
*dev
)
495 read_register(dev
, IPW_REG_DOA_DEBUG_AREA_START
, &dbg
);
497 return dbg
== IPW_DATA_DOA_DEBUG_VALUE
;
500 static int ipw2100_get_ordinal(struct ipw2100_priv
*priv
, u32 ord
,
501 void *val
, u32
* len
)
503 struct ipw2100_ordinals
*ordinals
= &priv
->ordinals
;
510 if (ordinals
->table1_addr
== 0) {
511 printk(KERN_WARNING DRV_NAME
": attempt to use fw ordinals "
512 "before they have been loaded.\n");
516 if (IS_ORDINAL_TABLE_ONE(ordinals
, ord
)) {
517 if (*len
< IPW_ORD_TAB_1_ENTRY_SIZE
) {
518 *len
= IPW_ORD_TAB_1_ENTRY_SIZE
;
520 printk(KERN_WARNING DRV_NAME
521 ": ordinal buffer length too small, need %zd\n",
522 IPW_ORD_TAB_1_ENTRY_SIZE
);
527 read_nic_dword(priv
->net_dev
,
528 ordinals
->table1_addr
+ (ord
<< 2), &addr
);
529 read_nic_dword(priv
->net_dev
, addr
, val
);
531 *len
= IPW_ORD_TAB_1_ENTRY_SIZE
;
536 if (IS_ORDINAL_TABLE_TWO(ordinals
, ord
)) {
538 ord
-= IPW_START_ORD_TAB_2
;
540 /* get the address of statistic */
541 read_nic_dword(priv
->net_dev
,
542 ordinals
->table2_addr
+ (ord
<< 3), &addr
);
544 /* get the second DW of statistics ;
545 * two 16-bit words - first is length, second is count */
546 read_nic_dword(priv
->net_dev
,
547 ordinals
->table2_addr
+ (ord
<< 3) + sizeof(u32
),
550 /* get each entry length */
551 field_len
= *((u16
*) & field_info
);
553 /* get number of entries */
554 field_count
= *(((u16
*) & field_info
) + 1);
556 /* abort if no enough memory */
557 total_length
= field_len
* field_count
;
558 if (total_length
> *len
) {
567 /* read the ordinal data from the SRAM */
568 read_nic_memory(priv
->net_dev
, addr
, total_length
, val
);
573 printk(KERN_WARNING DRV_NAME
": ordinal %d neither in table 1 nor "
574 "in table 2\n", ord
);
579 static int ipw2100_set_ordinal(struct ipw2100_priv
*priv
, u32 ord
, u32
* val
,
582 struct ipw2100_ordinals
*ordinals
= &priv
->ordinals
;
585 if (IS_ORDINAL_TABLE_ONE(ordinals
, ord
)) {
586 if (*len
!= IPW_ORD_TAB_1_ENTRY_SIZE
) {
587 *len
= IPW_ORD_TAB_1_ENTRY_SIZE
;
588 IPW_DEBUG_INFO("wrong size\n");
592 read_nic_dword(priv
->net_dev
,
593 ordinals
->table1_addr
+ (ord
<< 2), &addr
);
595 write_nic_dword(priv
->net_dev
, addr
, *val
);
597 *len
= IPW_ORD_TAB_1_ENTRY_SIZE
;
602 IPW_DEBUG_INFO("wrong table\n");
603 if (IS_ORDINAL_TABLE_TWO(ordinals
, ord
))
609 static char *snprint_line(char *buf
, size_t count
,
610 const u8
* data
, u32 len
, u32 ofs
)
615 out
= scnprintf(buf
, count
, "%08X", ofs
);
617 for (l
= 0, i
= 0; i
< 2; i
++) {
618 out
+= scnprintf(buf
+ out
, count
- out
, " ");
619 for (j
= 0; j
< 8 && l
< len
; j
++, l
++)
620 out
+= scnprintf(buf
+ out
, count
- out
, "%02X ",
623 out
+= scnprintf(buf
+ out
, count
- out
, " ");
626 out
+= scnprintf(buf
+ out
, count
- out
, " ");
627 for (l
= 0, i
= 0; i
< 2; i
++) {
628 out
+= scnprintf(buf
+ out
, count
- out
, " ");
629 for (j
= 0; j
< 8 && l
< len
; j
++, l
++) {
630 c
= data
[(i
* 8 + j
)];
631 if (!isascii(c
) || !isprint(c
))
634 out
+= scnprintf(buf
+ out
, count
- out
, "%c", c
);
638 out
+= scnprintf(buf
+ out
, count
- out
, " ");
644 static void printk_buf(int level
, const u8
* data
, u32 len
)
648 if (!(ipw2100_debug_level
& level
))
652 printk(KERN_DEBUG
"%s\n",
653 snprint_line(line
, sizeof(line
), &data
[ofs
],
654 min(len
, 16U), ofs
));
656 len
-= min(len
, 16U);
660 #define MAX_RESET_BACKOFF 10
662 static void schedule_reset(struct ipw2100_priv
*priv
)
664 time64_t now
= ktime_get_boottime_seconds();
666 /* If we haven't received a reset request within the backoff period,
667 * then we can reset the backoff interval so this reset occurs
669 if (priv
->reset_backoff
&&
670 (now
- priv
->last_reset
> priv
->reset_backoff
))
671 priv
->reset_backoff
= 0;
673 priv
->last_reset
= now
;
675 if (!(priv
->status
& STATUS_RESET_PENDING
)) {
676 IPW_DEBUG_INFO("%s: Scheduling firmware restart (%llds).\n",
677 priv
->net_dev
->name
, priv
->reset_backoff
);
678 netif_carrier_off(priv
->net_dev
);
679 netif_stop_queue(priv
->net_dev
);
680 priv
->status
|= STATUS_RESET_PENDING
;
681 if (priv
->reset_backoff
)
682 schedule_delayed_work(&priv
->reset_work
,
683 priv
->reset_backoff
* HZ
);
685 schedule_delayed_work(&priv
->reset_work
, 0);
687 if (priv
->reset_backoff
< MAX_RESET_BACKOFF
)
688 priv
->reset_backoff
++;
690 wake_up_interruptible(&priv
->wait_command_queue
);
692 IPW_DEBUG_INFO("%s: Firmware restart already in progress.\n",
693 priv
->net_dev
->name
);
697 #define HOST_COMPLETE_TIMEOUT (2 * HZ)
698 static int ipw2100_hw_send_command(struct ipw2100_priv
*priv
,
699 struct host_command
*cmd
)
701 struct list_head
*element
;
702 struct ipw2100_tx_packet
*packet
;
706 IPW_DEBUG_HC("Sending %s command (#%d), %d bytes\n",
707 command_types
[cmd
->host_command
], cmd
->host_command
,
708 cmd
->host_command_length
);
709 printk_buf(IPW_DL_HC
, (u8
*) cmd
->host_command_parameters
,
710 cmd
->host_command_length
);
712 spin_lock_irqsave(&priv
->low_lock
, flags
);
714 if (priv
->fatal_error
) {
716 ("Attempt to send command while hardware in fatal error condition.\n");
721 if (!(priv
->status
& STATUS_RUNNING
)) {
723 ("Attempt to send command while hardware is not running.\n");
728 if (priv
->status
& STATUS_CMD_ACTIVE
) {
730 ("Attempt to send command while another command is pending.\n");
735 if (list_empty(&priv
->msg_free_list
)) {
736 IPW_DEBUG_INFO("no available msg buffers\n");
740 priv
->status
|= STATUS_CMD_ACTIVE
;
741 priv
->messages_sent
++;
743 element
= priv
->msg_free_list
.next
;
745 packet
= list_entry(element
, struct ipw2100_tx_packet
, list
);
746 packet
->jiffy_start
= jiffies
;
748 /* initialize the firmware command packet */
749 packet
->info
.c_struct
.cmd
->host_command_reg
= cmd
->host_command
;
750 packet
->info
.c_struct
.cmd
->host_command_reg1
= cmd
->host_command1
;
751 packet
->info
.c_struct
.cmd
->host_command_len_reg
=
752 cmd
->host_command_length
;
753 packet
->info
.c_struct
.cmd
->sequence
= cmd
->host_command_sequence
;
755 memcpy(packet
->info
.c_struct
.cmd
->host_command_params_reg
,
756 cmd
->host_command_parameters
,
757 sizeof(packet
->info
.c_struct
.cmd
->host_command_params_reg
));
760 DEC_STAT(&priv
->msg_free_stat
);
762 list_add_tail(element
, &priv
->msg_pend_list
);
763 INC_STAT(&priv
->msg_pend_stat
);
765 ipw2100_tx_send_commands(priv
);
766 ipw2100_tx_send_data(priv
);
768 spin_unlock_irqrestore(&priv
->low_lock
, flags
);
771 * We must wait for this command to complete before another
772 * command can be sent... but if we wait more than 3 seconds
773 * then there is a problem.
777 wait_event_interruptible_timeout(priv
->wait_command_queue
,
779 status
& STATUS_CMD_ACTIVE
),
780 HOST_COMPLETE_TIMEOUT
);
783 IPW_DEBUG_INFO("Command completion failed out after %dms.\n",
784 1000 * (HOST_COMPLETE_TIMEOUT
/ HZ
));
785 priv
->fatal_error
= IPW2100_ERR_MSG_TIMEOUT
;
786 priv
->status
&= ~STATUS_CMD_ACTIVE
;
787 schedule_reset(priv
);
791 if (priv
->fatal_error
) {
792 printk(KERN_WARNING DRV_NAME
": %s: firmware fatal error\n",
793 priv
->net_dev
->name
);
797 /* !!!!! HACK TEST !!!!!
798 * When lots of debug trace statements are enabled, the driver
799 * doesn't seem to have as many firmware restart cycles...
801 * As a test, we're sticking in a 1/100s delay here */
802 schedule_timeout_uninterruptible(msecs_to_jiffies(10));
807 spin_unlock_irqrestore(&priv
->low_lock
, flags
);
813 * Verify the values and data access of the hardware
814 * No locks needed or used. No functions called.
816 static int ipw2100_verify(struct ipw2100_priv
*priv
)
821 u32 val1
= 0x76543210;
822 u32 val2
= 0xFEDCBA98;
824 /* Domain 0 check - all values should be DOA_DEBUG */
825 for (address
= IPW_REG_DOA_DEBUG_AREA_START
;
826 address
< IPW_REG_DOA_DEBUG_AREA_END
; address
+= sizeof(u32
)) {
827 read_register(priv
->net_dev
, address
, &data1
);
828 if (data1
!= IPW_DATA_DOA_DEBUG_VALUE
)
832 /* Domain 1 check - use arbitrary read/write compare */
833 for (address
= 0; address
< 5; address
++) {
834 /* The memory area is not used now */
835 write_register(priv
->net_dev
, IPW_REG_DOMAIN_1_OFFSET
+ 0x32,
837 write_register(priv
->net_dev
, IPW_REG_DOMAIN_1_OFFSET
+ 0x36,
839 read_register(priv
->net_dev
, IPW_REG_DOMAIN_1_OFFSET
+ 0x32,
841 read_register(priv
->net_dev
, IPW_REG_DOMAIN_1_OFFSET
+ 0x36,
843 if (val1
== data1
&& val2
== data2
)
852 * Loop until the CARD_DISABLED bit is the same value as the
855 * TODO: See if it would be more efficient to do a wait/wake
856 * cycle and have the completion event trigger the wakeup
859 #define IPW_CARD_DISABLE_COMPLETE_WAIT 100 // 100 milli
860 static int ipw2100_wait_for_card_state(struct ipw2100_priv
*priv
, int state
)
864 u32 len
= sizeof(card_state
);
867 for (i
= 0; i
<= IPW_CARD_DISABLE_COMPLETE_WAIT
* 1000; i
+= 50) {
868 err
= ipw2100_get_ordinal(priv
, IPW_ORD_CARD_DISABLED
,
871 IPW_DEBUG_INFO("Query of CARD_DISABLED ordinal "
876 /* We'll break out if either the HW state says it is
877 * in the state we want, or if HOST_COMPLETE command
879 if ((card_state
== state
) ||
880 ((priv
->status
& STATUS_ENABLED
) ?
881 IPW_HW_STATE_ENABLED
: IPW_HW_STATE_DISABLED
) == state
) {
882 if (state
== IPW_HW_STATE_ENABLED
)
883 priv
->status
|= STATUS_ENABLED
;
885 priv
->status
&= ~STATUS_ENABLED
;
893 IPW_DEBUG_INFO("ipw2100_wait_for_card_state to %s state timed out\n",
894 state
? "DISABLED" : "ENABLED");
898 /*********************************************************************
899 Procedure : sw_reset_and_clock
900 Purpose : Asserts s/w reset, asserts clock initialization
901 and waits for clock stabilization
902 ********************************************************************/
903 static int sw_reset_and_clock(struct ipw2100_priv
*priv
)
909 write_register(priv
->net_dev
, IPW_REG_RESET_REG
,
910 IPW_AUX_HOST_RESET_REG_SW_RESET
);
912 // wait for clock stabilization
913 for (i
= 0; i
< 1000; i
++) {
914 udelay(IPW_WAIT_RESET_ARC_COMPLETE_DELAY
);
916 // check clock ready bit
917 read_register(priv
->net_dev
, IPW_REG_RESET_REG
, &r
);
918 if (r
& IPW_AUX_HOST_RESET_REG_PRINCETON_RESET
)
923 return -EIO
; // TODO: better error value
925 /* set "initialization complete" bit to move adapter to
927 write_register(priv
->net_dev
, IPW_REG_GP_CNTRL
,
928 IPW_AUX_HOST_GP_CNTRL_BIT_INIT_DONE
);
930 /* wait for clock stabilization */
931 for (i
= 0; i
< 10000; i
++) {
932 udelay(IPW_WAIT_CLOCK_STABILIZATION_DELAY
* 4);
934 /* check clock ready bit */
935 read_register(priv
->net_dev
, IPW_REG_GP_CNTRL
, &r
);
936 if (r
& IPW_AUX_HOST_GP_CNTRL_BIT_CLOCK_READY
)
941 return -EIO
; /* TODO: better error value */
943 /* set D0 standby bit */
944 read_register(priv
->net_dev
, IPW_REG_GP_CNTRL
, &r
);
945 write_register(priv
->net_dev
, IPW_REG_GP_CNTRL
,
946 r
| IPW_AUX_HOST_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY
);
951 /*********************************************************************
952 Procedure : ipw2100_download_firmware
953 Purpose : Initiaze adapter after power on.
955 1. assert s/w reset first!
956 2. awake clocks & wait for clock stabilization
957 3. hold ARC (don't ask me why...)
958 4. load Dino ucode and reset/clock init again
959 5. zero-out shared mem
961 *******************************************************************/
962 static int ipw2100_download_firmware(struct ipw2100_priv
*priv
)
968 /* Fetch the firmware and microcode */
969 struct ipw2100_fw ipw2100_firmware
;
972 if (priv
->fatal_error
) {
973 IPW_DEBUG_ERROR("%s: ipw2100_download_firmware called after "
974 "fatal error %d. Interface must be brought down.\n",
975 priv
->net_dev
->name
, priv
->fatal_error
);
979 if (!ipw2100_firmware
.version
) {
980 err
= ipw2100_get_firmware(priv
, &ipw2100_firmware
);
982 IPW_DEBUG_ERROR("%s: ipw2100_get_firmware failed: %d\n",
983 priv
->net_dev
->name
, err
);
984 priv
->fatal_error
= IPW2100_ERR_FW_LOAD
;
989 err
= ipw2100_get_firmware(priv
, &ipw2100_firmware
);
991 IPW_DEBUG_ERROR("%s: ipw2100_get_firmware failed: %d\n",
992 priv
->net_dev
->name
, err
);
993 priv
->fatal_error
= IPW2100_ERR_FW_LOAD
;
997 priv
->firmware_version
= ipw2100_firmware
.version
;
999 /* s/w reset and clock stabilization */
1000 err
= sw_reset_and_clock(priv
);
1002 IPW_DEBUG_ERROR("%s: sw_reset_and_clock failed: %d\n",
1003 priv
->net_dev
->name
, err
);
1007 err
= ipw2100_verify(priv
);
1009 IPW_DEBUG_ERROR("%s: ipw2100_verify failed: %d\n",
1010 priv
->net_dev
->name
, err
);
1015 write_nic_dword(priv
->net_dev
,
1016 IPW_INTERNAL_REGISTER_HALT_AND_RESET
, 0x80000000);
1018 /* allow ARC to run */
1019 write_register(priv
->net_dev
, IPW_REG_RESET_REG
, 0);
1021 /* load microcode */
1022 err
= ipw2100_ucode_download(priv
, &ipw2100_firmware
);
1024 printk(KERN_ERR DRV_NAME
": %s: Error loading microcode: %d\n",
1025 priv
->net_dev
->name
, err
);
1030 write_nic_dword(priv
->net_dev
,
1031 IPW_INTERNAL_REGISTER_HALT_AND_RESET
, 0x00000000);
1033 /* s/w reset and clock stabilization (again!!!) */
1034 err
= sw_reset_and_clock(priv
);
1036 printk(KERN_ERR DRV_NAME
1037 ": %s: sw_reset_and_clock failed: %d\n",
1038 priv
->net_dev
->name
, err
);
1043 err
= ipw2100_fw_download(priv
, &ipw2100_firmware
);
1045 IPW_DEBUG_ERROR("%s: Error loading firmware: %d\n",
1046 priv
->net_dev
->name
, err
);
1051 * When the .resume method of the driver is called, the other
1052 * part of the system, i.e. the ide driver could still stay in
1053 * the suspend stage. This prevents us from loading the firmware
1054 * from the disk. --YZ
1057 /* free any storage allocated for firmware image */
1058 ipw2100_release_firmware(priv
, &ipw2100_firmware
);
1061 /* zero out Domain 1 area indirectly (Si requirement) */
1062 for (address
= IPW_HOST_FW_SHARED_AREA0
;
1063 address
< IPW_HOST_FW_SHARED_AREA0_END
; address
+= 4)
1064 write_nic_dword(priv
->net_dev
, address
, 0);
1065 for (address
= IPW_HOST_FW_SHARED_AREA1
;
1066 address
< IPW_HOST_FW_SHARED_AREA1_END
; address
+= 4)
1067 write_nic_dword(priv
->net_dev
, address
, 0);
1068 for (address
= IPW_HOST_FW_SHARED_AREA2
;
1069 address
< IPW_HOST_FW_SHARED_AREA2_END
; address
+= 4)
1070 write_nic_dword(priv
->net_dev
, address
, 0);
1071 for (address
= IPW_HOST_FW_SHARED_AREA3
;
1072 address
< IPW_HOST_FW_SHARED_AREA3_END
; address
+= 4)
1073 write_nic_dword(priv
->net_dev
, address
, 0);
1074 for (address
= IPW_HOST_FW_INTERRUPT_AREA
;
1075 address
< IPW_HOST_FW_INTERRUPT_AREA_END
; address
+= 4)
1076 write_nic_dword(priv
->net_dev
, address
, 0);
1081 ipw2100_release_firmware(priv
, &ipw2100_firmware
);
1085 static inline void ipw2100_enable_interrupts(struct ipw2100_priv
*priv
)
1087 if (priv
->status
& STATUS_INT_ENABLED
)
1089 priv
->status
|= STATUS_INT_ENABLED
;
1090 write_register(priv
->net_dev
, IPW_REG_INTA_MASK
, IPW_INTERRUPT_MASK
);
1093 static inline void ipw2100_disable_interrupts(struct ipw2100_priv
*priv
)
1095 if (!(priv
->status
& STATUS_INT_ENABLED
))
1097 priv
->status
&= ~STATUS_INT_ENABLED
;
1098 write_register(priv
->net_dev
, IPW_REG_INTA_MASK
, 0x0);
1101 static void ipw2100_initialize_ordinals(struct ipw2100_priv
*priv
)
1103 struct ipw2100_ordinals
*ord
= &priv
->ordinals
;
1105 IPW_DEBUG_INFO("enter\n");
1107 read_register(priv
->net_dev
, IPW_MEM_HOST_SHARED_ORDINALS_TABLE_1
,
1110 read_register(priv
->net_dev
, IPW_MEM_HOST_SHARED_ORDINALS_TABLE_2
,
1113 read_nic_dword(priv
->net_dev
, ord
->table1_addr
, &ord
->table1_size
);
1114 read_nic_dword(priv
->net_dev
, ord
->table2_addr
, &ord
->table2_size
);
1116 ord
->table2_size
&= 0x0000FFFF;
1118 IPW_DEBUG_INFO("table 1 size: %d\n", ord
->table1_size
);
1119 IPW_DEBUG_INFO("table 2 size: %d\n", ord
->table2_size
);
1120 IPW_DEBUG_INFO("exit\n");
1123 static inline void ipw2100_hw_set_gpio(struct ipw2100_priv
*priv
)
1127 * Set GPIO 3 writable by FW; GPIO 1 writable
1128 * by driver and enable clock
1130 reg
= (IPW_BIT_GPIO_GPIO3_MASK
| IPW_BIT_GPIO_GPIO1_ENABLE
|
1131 IPW_BIT_GPIO_LED_OFF
);
1132 write_register(priv
->net_dev
, IPW_REG_GPIO
, reg
);
1135 static int rf_kill_active(struct ipw2100_priv
*priv
)
1137 #define MAX_RF_KILL_CHECKS 5
1138 #define RF_KILL_CHECK_DELAY 40
1140 unsigned short value
= 0;
1144 if (!(priv
->hw_features
& HW_FEATURE_RFKILL
)) {
1145 wiphy_rfkill_set_hw_state(priv
->ieee
->wdev
.wiphy
, false);
1146 priv
->status
&= ~STATUS_RF_KILL_HW
;
1150 for (i
= 0; i
< MAX_RF_KILL_CHECKS
; i
++) {
1151 udelay(RF_KILL_CHECK_DELAY
);
1152 read_register(priv
->net_dev
, IPW_REG_GPIO
, ®
);
1153 value
= (value
<< 1) | ((reg
& IPW_BIT_GPIO_RF_KILL
) ? 0 : 1);
1157 wiphy_rfkill_set_hw_state(priv
->ieee
->wdev
.wiphy
, true);
1158 priv
->status
|= STATUS_RF_KILL_HW
;
1160 wiphy_rfkill_set_hw_state(priv
->ieee
->wdev
.wiphy
, false);
1161 priv
->status
&= ~STATUS_RF_KILL_HW
;
1164 return (value
== 0);
1167 static int ipw2100_get_hw_features(struct ipw2100_priv
*priv
)
1173 * EEPROM_SRAM_DB_START_ADDRESS using ordinal in ordinal table 1
1176 if (ipw2100_get_ordinal
1177 (priv
, IPW_ORD_EEPROM_SRAM_DB_BLOCK_START_ADDRESS
, &addr
, &len
)) {
1178 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
1183 IPW_DEBUG_INFO("EEPROM address: %08X\n", addr
);
1186 * EEPROM version is the byte at offset 0xfd in firmware
1187 * We read 4 bytes, then shift out the byte we actually want */
1188 read_nic_dword(priv
->net_dev
, addr
+ 0xFC, &val
);
1189 priv
->eeprom_version
= (val
>> 24) & 0xFF;
1190 IPW_DEBUG_INFO("EEPROM version: %d\n", priv
->eeprom_version
);
1193 * HW RF Kill enable is bit 0 in byte at offset 0x21 in firmware
1195 * notice that the EEPROM bit is reverse polarity, i.e.
1196 * bit = 0 signifies HW RF kill switch is supported
1197 * bit = 1 signifies HW RF kill switch is NOT supported
1199 read_nic_dword(priv
->net_dev
, addr
+ 0x20, &val
);
1200 if (!((val
>> 24) & 0x01))
1201 priv
->hw_features
|= HW_FEATURE_RFKILL
;
1203 IPW_DEBUG_INFO("HW RF Kill: %ssupported.\n",
1204 (priv
->hw_features
& HW_FEATURE_RFKILL
) ? "" : "not ");
1210 * Start firmware execution after power on and initialization
1213 * 2. Wait for f/w initialization completes;
1215 static int ipw2100_start_adapter(struct ipw2100_priv
*priv
)
1218 u32 inta
, inta_mask
, gpio
;
1220 IPW_DEBUG_INFO("enter\n");
1222 if (priv
->status
& STATUS_RUNNING
)
1226 * Initialize the hw - drive adapter to DO state by setting
1227 * init_done bit. Wait for clk_ready bit and Download
1230 if (ipw2100_download_firmware(priv
)) {
1231 printk(KERN_ERR DRV_NAME
1232 ": %s: Failed to power on the adapter.\n",
1233 priv
->net_dev
->name
);
1237 /* Clear the Tx, Rx and Msg queues and the r/w indexes
1238 * in the firmware RBD and TBD ring queue */
1239 ipw2100_queues_initialize(priv
);
1241 ipw2100_hw_set_gpio(priv
);
1243 /* TODO -- Look at disabling interrupts here to make sure none
1244 * get fired during FW initialization */
1246 /* Release ARC - clear reset bit */
1247 write_register(priv
->net_dev
, IPW_REG_RESET_REG
, 0);
1249 /* wait for f/w initialization complete */
1250 IPW_DEBUG_FW("Waiting for f/w initialization to complete...\n");
1253 schedule_timeout_uninterruptible(msecs_to_jiffies(40));
1254 /* Todo... wait for sync command ... */
1256 read_register(priv
->net_dev
, IPW_REG_INTA
, &inta
);
1258 /* check "init done" bit */
1259 if (inta
& IPW2100_INTA_FW_INIT_DONE
) {
1260 /* reset "init done" bit */
1261 write_register(priv
->net_dev
, IPW_REG_INTA
,
1262 IPW2100_INTA_FW_INIT_DONE
);
1266 /* check error conditions : we check these after the firmware
1267 * check so that if there is an error, the interrupt handler
1268 * will see it and the adapter will be reset */
1270 (IPW2100_INTA_FATAL_ERROR
| IPW2100_INTA_PARITY_ERROR
)) {
1271 /* clear error conditions */
1272 write_register(priv
->net_dev
, IPW_REG_INTA
,
1273 IPW2100_INTA_FATAL_ERROR
|
1274 IPW2100_INTA_PARITY_ERROR
);
1278 /* Clear out any pending INTAs since we aren't supposed to have
1279 * interrupts enabled at this point... */
1280 read_register(priv
->net_dev
, IPW_REG_INTA
, &inta
);
1281 read_register(priv
->net_dev
, IPW_REG_INTA_MASK
, &inta_mask
);
1282 inta
&= IPW_INTERRUPT_MASK
;
1283 /* Clear out any pending interrupts */
1284 if (inta
& inta_mask
)
1285 write_register(priv
->net_dev
, IPW_REG_INTA
, inta
);
1287 IPW_DEBUG_FW("f/w initialization complete: %s\n",
1288 i
? "SUCCESS" : "FAILED");
1291 printk(KERN_WARNING DRV_NAME
1292 ": %s: Firmware did not initialize.\n",
1293 priv
->net_dev
->name
);
1297 /* allow firmware to write to GPIO1 & GPIO3 */
1298 read_register(priv
->net_dev
, IPW_REG_GPIO
, &gpio
);
1300 gpio
|= (IPW_BIT_GPIO_GPIO1_MASK
| IPW_BIT_GPIO_GPIO3_MASK
);
1302 write_register(priv
->net_dev
, IPW_REG_GPIO
, gpio
);
1304 /* Ready to receive commands */
1305 priv
->status
|= STATUS_RUNNING
;
1307 /* The adapter has been reset; we are not associated */
1308 priv
->status
&= ~(STATUS_ASSOCIATING
| STATUS_ASSOCIATED
);
1310 IPW_DEBUG_INFO("exit\n");
1315 static inline void ipw2100_reset_fatalerror(struct ipw2100_priv
*priv
)
1317 if (!priv
->fatal_error
)
1320 priv
->fatal_errors
[priv
->fatal_index
++] = priv
->fatal_error
;
1321 priv
->fatal_index
%= IPW2100_ERROR_QUEUE
;
1322 priv
->fatal_error
= 0;
1325 /* NOTE: Our interrupt is disabled when this method is called */
1326 static int ipw2100_power_cycle_adapter(struct ipw2100_priv
*priv
)
1331 IPW_DEBUG_INFO("Power cycling the hardware.\n");
1333 ipw2100_hw_set_gpio(priv
);
1335 /* Step 1. Stop Master Assert */
1336 write_register(priv
->net_dev
, IPW_REG_RESET_REG
,
1337 IPW_AUX_HOST_RESET_REG_STOP_MASTER
);
1339 /* Step 2. Wait for stop Master Assert
1340 * (not more than 50us, otherwise ret error */
1343 udelay(IPW_WAIT_RESET_MASTER_ASSERT_COMPLETE_DELAY
);
1344 read_register(priv
->net_dev
, IPW_REG_RESET_REG
, ®
);
1346 if (reg
& IPW_AUX_HOST_RESET_REG_MASTER_DISABLED
)
1350 priv
->status
&= ~STATUS_RESET_PENDING
;
1354 ("exit - waited too long for master assert stop\n");
1358 write_register(priv
->net_dev
, IPW_REG_RESET_REG
,
1359 IPW_AUX_HOST_RESET_REG_SW_RESET
);
1361 /* Reset any fatal_error conditions */
1362 ipw2100_reset_fatalerror(priv
);
1364 /* At this point, the adapter is now stopped and disabled */
1365 priv
->status
&= ~(STATUS_RUNNING
| STATUS_ASSOCIATING
|
1366 STATUS_ASSOCIATED
| STATUS_ENABLED
);
1372 * Send the CARD_DISABLE_PHY_OFF command to the card to disable it
1374 * After disabling, if the card was associated, a STATUS_ASSN_LOST will be sent.
1376 * STATUS_CARD_DISABLE_NOTIFICATION will be sent regardless of
1377 * if STATUS_ASSN_LOST is sent.
1379 static int ipw2100_hw_phy_off(struct ipw2100_priv
*priv
)
1382 #define HW_PHY_OFF_LOOP_DELAY (msecs_to_jiffies(50))
1384 struct host_command cmd
= {
1385 .host_command
= CARD_DISABLE_PHY_OFF
,
1386 .host_command_sequence
= 0,
1387 .host_command_length
= 0,
1392 IPW_DEBUG_HC("CARD_DISABLE_PHY_OFF\n");
1394 /* Turn off the radio */
1395 err
= ipw2100_hw_send_command(priv
, &cmd
);
1399 for (i
= 0; i
< 2500; i
++) {
1400 read_nic_dword(priv
->net_dev
, IPW2100_CONTROL_REG
, &val1
);
1401 read_nic_dword(priv
->net_dev
, IPW2100_COMMAND
, &val2
);
1403 if ((val1
& IPW2100_CONTROL_PHY_OFF
) &&
1404 (val2
& IPW2100_COMMAND_PHY_OFF
))
1407 schedule_timeout_uninterruptible(HW_PHY_OFF_LOOP_DELAY
);
1413 static int ipw2100_enable_adapter(struct ipw2100_priv
*priv
)
1415 struct host_command cmd
= {
1416 .host_command
= HOST_COMPLETE
,
1417 .host_command_sequence
= 0,
1418 .host_command_length
= 0
1422 IPW_DEBUG_HC("HOST_COMPLETE\n");
1424 if (priv
->status
& STATUS_ENABLED
)
1427 mutex_lock(&priv
->adapter_mutex
);
1429 if (rf_kill_active(priv
)) {
1430 IPW_DEBUG_HC("Command aborted due to RF kill active.\n");
1434 err
= ipw2100_hw_send_command(priv
, &cmd
);
1436 IPW_DEBUG_INFO("Failed to send HOST_COMPLETE command\n");
1440 err
= ipw2100_wait_for_card_state(priv
, IPW_HW_STATE_ENABLED
);
1442 IPW_DEBUG_INFO("%s: card not responding to init command.\n",
1443 priv
->net_dev
->name
);
1447 if (priv
->stop_hang_check
) {
1448 priv
->stop_hang_check
= 0;
1449 schedule_delayed_work(&priv
->hang_check
, HZ
/ 2);
1453 mutex_unlock(&priv
->adapter_mutex
);
1457 static int ipw2100_hw_stop_adapter(struct ipw2100_priv
*priv
)
1459 #define HW_POWER_DOWN_DELAY (msecs_to_jiffies(100))
1461 struct host_command cmd
= {
1462 .host_command
= HOST_PRE_POWER_DOWN
,
1463 .host_command_sequence
= 0,
1464 .host_command_length
= 0,
1469 if (!(priv
->status
& STATUS_RUNNING
))
1472 priv
->status
|= STATUS_STOPPING
;
1474 /* We can only shut down the card if the firmware is operational. So,
1475 * if we haven't reset since a fatal_error, then we can not send the
1476 * shutdown commands. */
1477 if (!priv
->fatal_error
) {
1478 /* First, make sure the adapter is enabled so that the PHY_OFF
1479 * command can shut it down */
1480 ipw2100_enable_adapter(priv
);
1482 err
= ipw2100_hw_phy_off(priv
);
1484 printk(KERN_WARNING DRV_NAME
1485 ": Error disabling radio %d\n", err
);
1488 * If in D0-standby mode going directly to D3 may cause a
1489 * PCI bus violation. Therefore we must change out of the D0
1492 * Sending the PREPARE_FOR_POWER_DOWN will restrict the
1493 * hardware from going into standby mode and will transition
1494 * out of D0-standby if it is already in that state.
1496 * STATUS_PREPARE_POWER_DOWN_COMPLETE will be sent by the
1497 * driver upon completion. Once received, the driver can
1498 * proceed to the D3 state.
1500 * Prepare for power down command to fw. This command would
1501 * take HW out of D0-standby and prepare it for D3 state.
1503 * Currently FW does not support event notification for this
1504 * event. Therefore, skip waiting for it. Just wait a fixed
1507 IPW_DEBUG_HC("HOST_PRE_POWER_DOWN\n");
1509 err
= ipw2100_hw_send_command(priv
, &cmd
);
1511 printk(KERN_WARNING DRV_NAME
": "
1512 "%s: Power down command failed: Error %d\n",
1513 priv
->net_dev
->name
, err
);
1515 schedule_timeout_uninterruptible(HW_POWER_DOWN_DELAY
);
1518 priv
->status
&= ~STATUS_ENABLED
;
1521 * Set GPIO 3 writable by FW; GPIO 1 writable
1522 * by driver and enable clock
1524 ipw2100_hw_set_gpio(priv
);
1527 * Power down adapter. Sequence:
1528 * 1. Stop master assert (RESET_REG[9]=1)
1529 * 2. Wait for stop master (RESET_REG[8]==1)
1530 * 3. S/w reset assert (RESET_REG[7] = 1)
1533 /* Stop master assert */
1534 write_register(priv
->net_dev
, IPW_REG_RESET_REG
,
1535 IPW_AUX_HOST_RESET_REG_STOP_MASTER
);
1537 /* wait stop master not more than 50 usec.
1538 * Otherwise return error. */
1539 for (i
= 5; i
> 0; i
--) {
1542 /* Check master stop bit */
1543 read_register(priv
->net_dev
, IPW_REG_RESET_REG
, ®
);
1545 if (reg
& IPW_AUX_HOST_RESET_REG_MASTER_DISABLED
)
1550 printk(KERN_WARNING DRV_NAME
1551 ": %s: Could now power down adapter.\n",
1552 priv
->net_dev
->name
);
1554 /* assert s/w reset */
1555 write_register(priv
->net_dev
, IPW_REG_RESET_REG
,
1556 IPW_AUX_HOST_RESET_REG_SW_RESET
);
1558 priv
->status
&= ~(STATUS_RUNNING
| STATUS_STOPPING
);
1563 static int ipw2100_disable_adapter(struct ipw2100_priv
*priv
)
1565 struct host_command cmd
= {
1566 .host_command
= CARD_DISABLE
,
1567 .host_command_sequence
= 0,
1568 .host_command_length
= 0
1572 IPW_DEBUG_HC("CARD_DISABLE\n");
1574 if (!(priv
->status
& STATUS_ENABLED
))
1577 /* Make sure we clear the associated state */
1578 priv
->status
&= ~(STATUS_ASSOCIATED
| STATUS_ASSOCIATING
);
1580 if (!priv
->stop_hang_check
) {
1581 priv
->stop_hang_check
= 1;
1582 cancel_delayed_work(&priv
->hang_check
);
1585 mutex_lock(&priv
->adapter_mutex
);
1587 err
= ipw2100_hw_send_command(priv
, &cmd
);
1589 printk(KERN_WARNING DRV_NAME
1590 ": exit - failed to send CARD_DISABLE command\n");
1594 err
= ipw2100_wait_for_card_state(priv
, IPW_HW_STATE_DISABLED
);
1596 printk(KERN_WARNING DRV_NAME
1597 ": exit - card failed to change to DISABLED\n");
1601 IPW_DEBUG_INFO("TODO: implement scan state machine\n");
1604 mutex_unlock(&priv
->adapter_mutex
);
1608 static int ipw2100_set_scan_options(struct ipw2100_priv
*priv
)
1610 struct host_command cmd
= {
1611 .host_command
= SET_SCAN_OPTIONS
,
1612 .host_command_sequence
= 0,
1613 .host_command_length
= 8
1617 IPW_DEBUG_INFO("enter\n");
1619 IPW_DEBUG_SCAN("setting scan options\n");
1621 cmd
.host_command_parameters
[0] = 0;
1623 if (!(priv
->config
& CFG_ASSOCIATE
))
1624 cmd
.host_command_parameters
[0] |= IPW_SCAN_NOASSOCIATE
;
1625 if ((priv
->ieee
->sec
.flags
& SEC_ENABLED
) && priv
->ieee
->sec
.enabled
)
1626 cmd
.host_command_parameters
[0] |= IPW_SCAN_MIXED_CELL
;
1627 if (priv
->config
& CFG_PASSIVE_SCAN
)
1628 cmd
.host_command_parameters
[0] |= IPW_SCAN_PASSIVE
;
1630 cmd
.host_command_parameters
[1] = priv
->channel_mask
;
1632 err
= ipw2100_hw_send_command(priv
, &cmd
);
1634 IPW_DEBUG_HC("SET_SCAN_OPTIONS 0x%04X\n",
1635 cmd
.host_command_parameters
[0]);
1640 static int ipw2100_start_scan(struct ipw2100_priv
*priv
)
1642 struct host_command cmd
= {
1643 .host_command
= BROADCAST_SCAN
,
1644 .host_command_sequence
= 0,
1645 .host_command_length
= 4
1649 IPW_DEBUG_HC("START_SCAN\n");
1651 cmd
.host_command_parameters
[0] = 0;
1653 /* No scanning if in monitor mode */
1654 if (priv
->ieee
->iw_mode
== IW_MODE_MONITOR
)
1657 if (priv
->status
& STATUS_SCANNING
) {
1658 IPW_DEBUG_SCAN("Scan requested while already in scan...\n");
1662 IPW_DEBUG_INFO("enter\n");
1664 /* Not clearing here; doing so makes iwlist always return nothing...
1666 * We should modify the table logic to use aging tables vs. clearing
1667 * the table on each scan start.
1669 IPW_DEBUG_SCAN("starting scan\n");
1671 priv
->status
|= STATUS_SCANNING
;
1672 err
= ipw2100_hw_send_command(priv
, &cmd
);
1674 priv
->status
&= ~STATUS_SCANNING
;
1676 IPW_DEBUG_INFO("exit\n");
1681 static const struct libipw_geo ipw_geos
[] = {
1685 .bg
= {{2412, 1}, {2417, 2}, {2422, 3},
1686 {2427, 4}, {2432, 5}, {2437, 6},
1687 {2442, 7}, {2447, 8}, {2452, 9},
1688 {2457, 10}, {2462, 11}, {2467, 12},
1689 {2472, 13}, {2484, 14}},
1693 static int ipw2100_up(struct ipw2100_priv
*priv
, int deferred
)
1695 unsigned long flags
;
1698 u32 ord_len
= sizeof(lock
);
1700 /* Age scan list entries found before suspend */
1701 if (priv
->suspend_time
) {
1702 libipw_networks_age(priv
->ieee
, priv
->suspend_time
);
1703 priv
->suspend_time
= 0;
1706 /* Quiet if manually disabled. */
1707 if (priv
->status
& STATUS_RF_KILL_SW
) {
1708 IPW_DEBUG_INFO("%s: Radio is disabled by Manual Disable "
1709 "switch\n", priv
->net_dev
->name
);
1713 /* the ipw2100 hardware really doesn't want power management delays
1714 * longer than 175usec
1716 cpu_latency_qos_update_request(&ipw2100_pm_qos_req
, 175);
1718 /* If the interrupt is enabled, turn it off... */
1719 spin_lock_irqsave(&priv
->low_lock
, flags
);
1720 ipw2100_disable_interrupts(priv
);
1722 /* Reset any fatal_error conditions */
1723 ipw2100_reset_fatalerror(priv
);
1724 spin_unlock_irqrestore(&priv
->low_lock
, flags
);
1726 if (priv
->status
& STATUS_POWERED
||
1727 (priv
->status
& STATUS_RESET_PENDING
)) {
1728 /* Power cycle the card ... */
1729 err
= ipw2100_power_cycle_adapter(priv
);
1731 printk(KERN_WARNING DRV_NAME
1732 ": %s: Could not cycle adapter.\n",
1733 priv
->net_dev
->name
);
1737 priv
->status
|= STATUS_POWERED
;
1739 /* Load the firmware, start the clocks, etc. */
1740 err
= ipw2100_start_adapter(priv
);
1742 printk(KERN_ERR DRV_NAME
1743 ": %s: Failed to start the firmware.\n",
1744 priv
->net_dev
->name
);
1748 ipw2100_initialize_ordinals(priv
);
1750 /* Determine capabilities of this particular HW configuration */
1751 err
= ipw2100_get_hw_features(priv
);
1753 printk(KERN_ERR DRV_NAME
1754 ": %s: Failed to determine HW features.\n",
1755 priv
->net_dev
->name
);
1759 /* Initialize the geo */
1760 libipw_set_geo(priv
->ieee
, &ipw_geos
[0]);
1761 priv
->ieee
->freq_band
= LIBIPW_24GHZ_BAND
;
1764 err
= ipw2100_set_ordinal(priv
, IPW_ORD_PERS_DB_LOCK
, &lock
, &ord_len
);
1766 printk(KERN_ERR DRV_NAME
1767 ": %s: Failed to clear ordinal lock.\n",
1768 priv
->net_dev
->name
);
1772 priv
->status
&= ~STATUS_SCANNING
;
1774 if (rf_kill_active(priv
)) {
1775 printk(KERN_INFO
"%s: Radio is disabled by RF switch.\n",
1776 priv
->net_dev
->name
);
1778 if (priv
->stop_rf_kill
) {
1779 priv
->stop_rf_kill
= 0;
1780 schedule_delayed_work(&priv
->rf_kill
,
1781 round_jiffies_relative(HZ
));
1787 /* Turn on the interrupt so that commands can be processed */
1788 ipw2100_enable_interrupts(priv
);
1790 /* Send all of the commands that must be sent prior to
1792 err
= ipw2100_adapter_setup(priv
);
1794 printk(KERN_ERR DRV_NAME
": %s: Failed to start the card.\n",
1795 priv
->net_dev
->name
);
1800 /* Enable the adapter - sends HOST_COMPLETE */
1801 err
= ipw2100_enable_adapter(priv
);
1803 printk(KERN_ERR DRV_NAME
": "
1804 "%s: failed in call to enable adapter.\n",
1805 priv
->net_dev
->name
);
1806 ipw2100_hw_stop_adapter(priv
);
1810 /* Start a scan . . . */
1811 ipw2100_set_scan_options(priv
);
1812 ipw2100_start_scan(priv
);
1819 static void ipw2100_down(struct ipw2100_priv
*priv
)
1821 unsigned long flags
;
1822 union iwreq_data wrqu
= {
1824 .sa_family
= ARPHRD_ETHER
}
1826 int associated
= priv
->status
& STATUS_ASSOCIATED
;
1828 /* Kill the RF switch timer */
1829 if (!priv
->stop_rf_kill
) {
1830 priv
->stop_rf_kill
= 1;
1831 cancel_delayed_work(&priv
->rf_kill
);
1834 /* Kill the firmware hang check timer */
1835 if (!priv
->stop_hang_check
) {
1836 priv
->stop_hang_check
= 1;
1837 cancel_delayed_work(&priv
->hang_check
);
1840 /* Kill any pending resets */
1841 if (priv
->status
& STATUS_RESET_PENDING
)
1842 cancel_delayed_work(&priv
->reset_work
);
1844 /* Make sure the interrupt is on so that FW commands will be
1845 * processed correctly */
1846 spin_lock_irqsave(&priv
->low_lock
, flags
);
1847 ipw2100_enable_interrupts(priv
);
1848 spin_unlock_irqrestore(&priv
->low_lock
, flags
);
1850 if (ipw2100_hw_stop_adapter(priv
))
1851 printk(KERN_ERR DRV_NAME
": %s: Error stopping adapter.\n",
1852 priv
->net_dev
->name
);
1854 /* Do not disable the interrupt until _after_ we disable
1855 * the adaptor. Otherwise the CARD_DISABLE command will never
1856 * be ack'd by the firmware */
1857 spin_lock_irqsave(&priv
->low_lock
, flags
);
1858 ipw2100_disable_interrupts(priv
);
1859 spin_unlock_irqrestore(&priv
->low_lock
, flags
);
1861 cpu_latency_qos_update_request(&ipw2100_pm_qos_req
,
1862 PM_QOS_DEFAULT_VALUE
);
1864 /* We have to signal any supplicant if we are disassociating */
1866 wireless_send_event(priv
->net_dev
, SIOCGIWAP
, &wrqu
, NULL
);
1868 priv
->status
&= ~(STATUS_ASSOCIATED
| STATUS_ASSOCIATING
);
1869 netif_carrier_off(priv
->net_dev
);
1870 netif_stop_queue(priv
->net_dev
);
1873 static int ipw2100_wdev_init(struct net_device
*dev
)
1875 struct ipw2100_priv
*priv
= libipw_priv(dev
);
1876 const struct libipw_geo
*geo
= libipw_get_geo(priv
->ieee
);
1877 struct wireless_dev
*wdev
= &priv
->ieee
->wdev
;
1880 memcpy(wdev
->wiphy
->perm_addr
, priv
->mac_addr
, ETH_ALEN
);
1882 /* fill-out priv->ieee->bg_band */
1883 if (geo
->bg_channels
) {
1884 struct ieee80211_supported_band
*bg_band
= &priv
->ieee
->bg_band
;
1886 bg_band
->band
= NL80211_BAND_2GHZ
;
1887 bg_band
->n_channels
= geo
->bg_channels
;
1888 bg_band
->channels
= kcalloc(geo
->bg_channels
,
1889 sizeof(struct ieee80211_channel
),
1891 if (!bg_band
->channels
) {
1895 /* translate geo->bg to bg_band.channels */
1896 for (i
= 0; i
< geo
->bg_channels
; i
++) {
1897 bg_band
->channels
[i
].band
= NL80211_BAND_2GHZ
;
1898 bg_band
->channels
[i
].center_freq
= geo
->bg
[i
].freq
;
1899 bg_band
->channels
[i
].hw_value
= geo
->bg
[i
].channel
;
1900 bg_band
->channels
[i
].max_power
= geo
->bg
[i
].max_power
;
1901 if (geo
->bg
[i
].flags
& LIBIPW_CH_PASSIVE_ONLY
)
1902 bg_band
->channels
[i
].flags
|=
1903 IEEE80211_CHAN_NO_IR
;
1904 if (geo
->bg
[i
].flags
& LIBIPW_CH_NO_IBSS
)
1905 bg_band
->channels
[i
].flags
|=
1906 IEEE80211_CHAN_NO_IR
;
1907 if (geo
->bg
[i
].flags
& LIBIPW_CH_RADAR_DETECT
)
1908 bg_band
->channels
[i
].flags
|=
1909 IEEE80211_CHAN_RADAR
;
1910 /* No equivalent for LIBIPW_CH_80211H_RULES,
1911 LIBIPW_CH_UNIFORM_SPREADING, or
1912 LIBIPW_CH_B_ONLY... */
1914 /* point at bitrate info */
1915 bg_band
->bitrates
= ipw2100_bg_rates
;
1916 bg_band
->n_bitrates
= RATE_COUNT
;
1918 wdev
->wiphy
->bands
[NL80211_BAND_2GHZ
] = bg_band
;
1921 wdev
->wiphy
->cipher_suites
= ipw_cipher_suites
;
1922 wdev
->wiphy
->n_cipher_suites
= ARRAY_SIZE(ipw_cipher_suites
);
1924 set_wiphy_dev(wdev
->wiphy
, &priv
->pci_dev
->dev
);
1925 if (wiphy_register(wdev
->wiphy
))
1930 static void ipw2100_reset_adapter(struct work_struct
*work
)
1932 struct ipw2100_priv
*priv
=
1933 container_of(work
, struct ipw2100_priv
, reset_work
.work
);
1934 unsigned long flags
;
1935 union iwreq_data wrqu
= {
1937 .sa_family
= ARPHRD_ETHER
}
1939 int associated
= priv
->status
& STATUS_ASSOCIATED
;
1941 spin_lock_irqsave(&priv
->low_lock
, flags
);
1942 IPW_DEBUG_INFO(": %s: Restarting adapter.\n", priv
->net_dev
->name
);
1944 priv
->status
&= ~(STATUS_ASSOCIATED
| STATUS_ASSOCIATING
);
1945 priv
->status
|= STATUS_SECURITY_UPDATED
;
1947 /* Force a power cycle even if interface hasn't been opened
1949 cancel_delayed_work(&priv
->reset_work
);
1950 priv
->status
|= STATUS_RESET_PENDING
;
1951 spin_unlock_irqrestore(&priv
->low_lock
, flags
);
1953 mutex_lock(&priv
->action_mutex
);
1954 /* stop timed checks so that they don't interfere with reset */
1955 priv
->stop_hang_check
= 1;
1956 cancel_delayed_work(&priv
->hang_check
);
1958 /* We have to signal any supplicant if we are disassociating */
1960 wireless_send_event(priv
->net_dev
, SIOCGIWAP
, &wrqu
, NULL
);
1962 ipw2100_up(priv
, 0);
1963 mutex_unlock(&priv
->action_mutex
);
1967 static void isr_indicate_associated(struct ipw2100_priv
*priv
, u32 status
)
1970 #define MAC_ASSOCIATION_READ_DELAY (HZ)
1972 unsigned int len
, essid_len
;
1973 char essid
[IW_ESSID_MAX_SIZE
];
1980 * TBD: BSSID is usually 00:00:00:00:00:00 here and not
1981 * an actual MAC of the AP. Seems like FW sets this
1982 * address too late. Read it later and expose through
1983 * /proc or schedule a later task to query and update
1986 essid_len
= IW_ESSID_MAX_SIZE
;
1987 ret
= ipw2100_get_ordinal(priv
, IPW_ORD_STAT_ASSN_SSID
,
1990 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
1996 ret
= ipw2100_get_ordinal(priv
, IPW_ORD_CURRENT_TX_RATE
, &txrate
, &len
);
1998 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
2004 ret
= ipw2100_get_ordinal(priv
, IPW_ORD_OUR_FREQ
, &chan
, &len
);
2006 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
2011 ret
= ipw2100_get_ordinal(priv
, IPW_ORD_STAT_ASSN_AP_BSSID
, bssid
,
2014 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
2018 memcpy(priv
->ieee
->bssid
, bssid
, ETH_ALEN
);
2021 case TX_RATE_1_MBIT
:
2022 txratename
= "1Mbps";
2024 case TX_RATE_2_MBIT
:
2025 txratename
= "2Mbsp";
2027 case TX_RATE_5_5_MBIT
:
2028 txratename
= "5.5Mbps";
2030 case TX_RATE_11_MBIT
:
2031 txratename
= "11Mbps";
2034 IPW_DEBUG_INFO("Unknown rate: %d\n", txrate
);
2035 txratename
= "unknown rate";
2039 IPW_DEBUG_INFO("%s: Associated with '%*pE' at %s, channel %d (BSSID=%pM)\n",
2040 priv
->net_dev
->name
, essid_len
, essid
,
2041 txratename
, chan
, bssid
);
2043 /* now we copy read ssid into dev */
2044 if (!(priv
->config
& CFG_STATIC_ESSID
)) {
2045 priv
->essid_len
= min((u8
) essid_len
, (u8
) IW_ESSID_MAX_SIZE
);
2046 memcpy(priv
->essid
, essid
, priv
->essid_len
);
2048 priv
->channel
= chan
;
2049 memcpy(priv
->bssid
, bssid
, ETH_ALEN
);
2051 priv
->status
|= STATUS_ASSOCIATING
;
2052 priv
->connect_start
= ktime_get_boottime_seconds();
2054 schedule_delayed_work(&priv
->wx_event_work
, HZ
/ 10);
2057 static int ipw2100_set_essid(struct ipw2100_priv
*priv
, char *essid
,
2058 int length
, int batch_mode
)
2060 int ssid_len
= min(length
, IW_ESSID_MAX_SIZE
);
2061 struct host_command cmd
= {
2062 .host_command
= SSID
,
2063 .host_command_sequence
= 0,
2064 .host_command_length
= ssid_len
2068 IPW_DEBUG_HC("SSID: '%*pE'\n", ssid_len
, essid
);
2071 memcpy(cmd
.host_command_parameters
, essid
, ssid_len
);
2074 err
= ipw2100_disable_adapter(priv
);
2079 /* Bug in FW currently doesn't honor bit 0 in SET_SCAN_OPTIONS to
2080 * disable auto association -- so we cheat by setting a bogus SSID */
2081 if (!ssid_len
&& !(priv
->config
& CFG_ASSOCIATE
)) {
2083 u8
*bogus
= (u8
*) cmd
.host_command_parameters
;
2084 for (i
= 0; i
< IW_ESSID_MAX_SIZE
; i
++)
2085 bogus
[i
] = 0x18 + i
;
2086 cmd
.host_command_length
= IW_ESSID_MAX_SIZE
;
2089 /* NOTE: We always send the SSID command even if the provided ESSID is
2090 * the same as what we currently think is set. */
2092 err
= ipw2100_hw_send_command(priv
, &cmd
);
2094 memset(priv
->essid
+ ssid_len
, 0, IW_ESSID_MAX_SIZE
- ssid_len
);
2095 memcpy(priv
->essid
, essid
, ssid_len
);
2096 priv
->essid_len
= ssid_len
;
2100 if (ipw2100_enable_adapter(priv
))
2107 static void isr_indicate_association_lost(struct ipw2100_priv
*priv
, u32 status
)
2109 IPW_DEBUG(IPW_DL_NOTIF
| IPW_DL_STATE
| IPW_DL_ASSOC
,
2110 "disassociated: '%*pE' %pM\n", priv
->essid_len
, priv
->essid
,
2113 priv
->status
&= ~(STATUS_ASSOCIATED
| STATUS_ASSOCIATING
);
2115 if (priv
->status
& STATUS_STOPPING
) {
2116 IPW_DEBUG_INFO("Card is stopping itself, discard ASSN_LOST.\n");
2120 eth_zero_addr(priv
->bssid
);
2121 eth_zero_addr(priv
->ieee
->bssid
);
2123 netif_carrier_off(priv
->net_dev
);
2124 netif_stop_queue(priv
->net_dev
);
2126 if (!(priv
->status
& STATUS_RUNNING
))
2129 if (priv
->status
& STATUS_SECURITY_UPDATED
)
2130 schedule_delayed_work(&priv
->security_work
, 0);
2132 schedule_delayed_work(&priv
->wx_event_work
, 0);
2135 static void isr_indicate_rf_kill(struct ipw2100_priv
*priv
, u32 status
)
2137 IPW_DEBUG_INFO("%s: RF Kill state changed to radio OFF.\n",
2138 priv
->net_dev
->name
);
2140 /* RF_KILL is now enabled (else we wouldn't be here) */
2141 wiphy_rfkill_set_hw_state(priv
->ieee
->wdev
.wiphy
, true);
2142 priv
->status
|= STATUS_RF_KILL_HW
;
2144 /* Make sure the RF Kill check timer is running */
2145 priv
->stop_rf_kill
= 0;
2146 mod_delayed_work(system_wq
, &priv
->rf_kill
, round_jiffies_relative(HZ
));
2149 static void ipw2100_scan_event(struct work_struct
*work
)
2151 struct ipw2100_priv
*priv
= container_of(work
, struct ipw2100_priv
,
2153 union iwreq_data wrqu
;
2155 wrqu
.data
.length
= 0;
2156 wrqu
.data
.flags
= 0;
2157 wireless_send_event(priv
->net_dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
2160 static void isr_scan_complete(struct ipw2100_priv
*priv
, u32 status
)
2162 IPW_DEBUG_SCAN("scan complete\n");
2163 /* Age the scan results... */
2164 priv
->ieee
->scans
++;
2165 priv
->status
&= ~STATUS_SCANNING
;
2167 /* Only userspace-requested scan completion events go out immediately */
2168 if (!priv
->user_requested_scan
) {
2169 schedule_delayed_work(&priv
->scan_event
,
2170 round_jiffies_relative(msecs_to_jiffies(4000)));
2172 priv
->user_requested_scan
= 0;
2173 mod_delayed_work(system_wq
, &priv
->scan_event
, 0);
2177 #ifdef CONFIG_IPW2100_DEBUG
2178 #define IPW2100_HANDLER(v, f) { v, f, # v }
2179 struct ipw2100_status_indicator
{
2181 void (*cb
) (struct ipw2100_priv
* priv
, u32 status
);
2185 #define IPW2100_HANDLER(v, f) { v, f }
2186 struct ipw2100_status_indicator
{
2188 void (*cb
) (struct ipw2100_priv
* priv
, u32 status
);
2190 #endif /* CONFIG_IPW2100_DEBUG */
2192 static void isr_indicate_scanning(struct ipw2100_priv
*priv
, u32 status
)
2194 IPW_DEBUG_SCAN("Scanning...\n");
2195 priv
->status
|= STATUS_SCANNING
;
2198 static const struct ipw2100_status_indicator status_handlers
[] = {
2199 IPW2100_HANDLER(IPW_STATE_INITIALIZED
, NULL
),
2200 IPW2100_HANDLER(IPW_STATE_COUNTRY_FOUND
, NULL
),
2201 IPW2100_HANDLER(IPW_STATE_ASSOCIATED
, isr_indicate_associated
),
2202 IPW2100_HANDLER(IPW_STATE_ASSN_LOST
, isr_indicate_association_lost
),
2203 IPW2100_HANDLER(IPW_STATE_ASSN_CHANGED
, NULL
),
2204 IPW2100_HANDLER(IPW_STATE_SCAN_COMPLETE
, isr_scan_complete
),
2205 IPW2100_HANDLER(IPW_STATE_ENTERED_PSP
, NULL
),
2206 IPW2100_HANDLER(IPW_STATE_LEFT_PSP
, NULL
),
2207 IPW2100_HANDLER(IPW_STATE_RF_KILL
, isr_indicate_rf_kill
),
2208 IPW2100_HANDLER(IPW_STATE_DISABLED
, NULL
),
2209 IPW2100_HANDLER(IPW_STATE_POWER_DOWN
, NULL
),
2210 IPW2100_HANDLER(IPW_STATE_SCANNING
, isr_indicate_scanning
),
2211 IPW2100_HANDLER(-1, NULL
)
2214 static void isr_status_change(struct ipw2100_priv
*priv
, int status
)
2218 if (status
== IPW_STATE_SCANNING
&&
2219 priv
->status
& STATUS_ASSOCIATED
&&
2220 !(priv
->status
& STATUS_SCANNING
)) {
2221 IPW_DEBUG_INFO("Scan detected while associated, with "
2222 "no scan request. Restarting firmware.\n");
2224 /* Wake up any sleeping jobs */
2225 schedule_reset(priv
);
2228 for (i
= 0; status_handlers
[i
].status
!= -1; i
++) {
2229 if (status
== status_handlers
[i
].status
) {
2230 IPW_DEBUG_NOTIF("Status change: %s\n",
2231 status_handlers
[i
].name
);
2232 if (status_handlers
[i
].cb
)
2233 status_handlers
[i
].cb(priv
, status
);
2234 priv
->wstats
.status
= status
;
2239 IPW_DEBUG_NOTIF("unknown status received: %04x\n", status
);
2242 static void isr_rx_complete_command(struct ipw2100_priv
*priv
,
2243 struct ipw2100_cmd_header
*cmd
)
2245 #ifdef CONFIG_IPW2100_DEBUG
2246 if (cmd
->host_command_reg
< ARRAY_SIZE(command_types
)) {
2247 IPW_DEBUG_HC("Command completed '%s (%d)'\n",
2248 command_types
[cmd
->host_command_reg
],
2249 cmd
->host_command_reg
);
2252 if (cmd
->host_command_reg
== HOST_COMPLETE
)
2253 priv
->status
|= STATUS_ENABLED
;
2255 if (cmd
->host_command_reg
== CARD_DISABLE
)
2256 priv
->status
&= ~STATUS_ENABLED
;
2258 priv
->status
&= ~STATUS_CMD_ACTIVE
;
2260 wake_up_interruptible(&priv
->wait_command_queue
);
2263 #ifdef CONFIG_IPW2100_DEBUG
2264 static const char *frame_types
[] = {
2265 "COMMAND_STATUS_VAL",
2266 "STATUS_CHANGE_VAL",
2269 "HOST_NOTIFICATION_VAL"
2273 static int ipw2100_alloc_skb(struct ipw2100_priv
*priv
,
2274 struct ipw2100_rx_packet
*packet
)
2276 packet
->skb
= dev_alloc_skb(sizeof(struct ipw2100_rx
));
2280 packet
->rxp
= (struct ipw2100_rx
*)packet
->skb
->data
;
2281 packet
->dma_addr
= dma_map_single(&priv
->pci_dev
->dev
,
2283 sizeof(struct ipw2100_rx
),
2285 if (dma_mapping_error(&priv
->pci_dev
->dev
, packet
->dma_addr
)) {
2286 dev_kfree_skb(packet
->skb
);
2293 #define SEARCH_ERROR 0xffffffff
2294 #define SEARCH_FAIL 0xfffffffe
2295 #define SEARCH_SUCCESS 0xfffffff0
2296 #define SEARCH_DISCARD 0
2297 #define SEARCH_SNAPSHOT 1
2299 #define SNAPSHOT_ADDR(ofs) (priv->snapshot[((ofs) >> 12) & 0xff] + ((ofs) & 0xfff))
2300 static void ipw2100_snapshot_free(struct ipw2100_priv
*priv
)
2303 if (!priv
->snapshot
[0])
2305 for (i
= 0; i
< 0x30; i
++)
2306 kfree(priv
->snapshot
[i
]);
2307 priv
->snapshot
[0] = NULL
;
2310 #ifdef IPW2100_DEBUG_C3
2311 static int ipw2100_snapshot_alloc(struct ipw2100_priv
*priv
)
2314 if (priv
->snapshot
[0])
2316 for (i
= 0; i
< 0x30; i
++) {
2317 priv
->snapshot
[i
] = kmalloc(0x1000, GFP_ATOMIC
);
2318 if (!priv
->snapshot
[i
]) {
2319 IPW_DEBUG_INFO("%s: Error allocating snapshot "
2320 "buffer %d\n", priv
->net_dev
->name
, i
);
2322 kfree(priv
->snapshot
[--i
]);
2323 priv
->snapshot
[0] = NULL
;
2331 static u32
ipw2100_match_buf(struct ipw2100_priv
*priv
, u8
* in_buf
,
2332 size_t len
, int mode
)
2340 if (mode
== SEARCH_SNAPSHOT
) {
2341 if (!ipw2100_snapshot_alloc(priv
))
2342 mode
= SEARCH_DISCARD
;
2345 for (ret
= SEARCH_FAIL
, i
= 0; i
< 0x30000; i
+= 4) {
2346 read_nic_dword(priv
->net_dev
, i
, &tmp
);
2347 if (mode
== SEARCH_SNAPSHOT
)
2348 *(u32
*) SNAPSHOT_ADDR(i
) = tmp
;
2349 if (ret
== SEARCH_FAIL
) {
2351 for (j
= 0; j
< 4; j
++) {
2360 if ((s
- in_buf
) == len
)
2361 ret
= (i
+ j
) - len
+ 1;
2363 } else if (mode
== SEARCH_DISCARD
)
2373 * 0) Disconnect the SKB from the firmware (just unmap)
2374 * 1) Pack the ETH header into the SKB
2375 * 2) Pass the SKB to the network stack
2377 * When packet is provided by the firmware, it contains the following:
2382 * The size of the constructed ethernet
2385 #ifdef IPW2100_RX_DEBUG
2386 static u8 packet_data
[IPW_RX_NIC_BUFFER_LENGTH
];
2389 static void ipw2100_corruption_detected(struct ipw2100_priv
*priv
, int i
)
2391 #ifdef IPW2100_DEBUG_C3
2392 struct ipw2100_status
*status
= &priv
->status_queue
.drv
[i
];
2397 IPW_DEBUG_INFO(": PCI latency error detected at 0x%04zX.\n",
2398 i
* sizeof(struct ipw2100_status
));
2400 #ifdef IPW2100_DEBUG_C3
2401 /* Halt the firmware so we can get a good image */
2402 write_register(priv
->net_dev
, IPW_REG_RESET_REG
,
2403 IPW_AUX_HOST_RESET_REG_STOP_MASTER
);
2406 udelay(IPW_WAIT_RESET_MASTER_ASSERT_COMPLETE_DELAY
);
2407 read_register(priv
->net_dev
, IPW_REG_RESET_REG
, ®
);
2409 if (reg
& IPW_AUX_HOST_RESET_REG_MASTER_DISABLED
)
2413 match
= ipw2100_match_buf(priv
, (u8
*) status
,
2414 sizeof(struct ipw2100_status
),
2416 if (match
< SEARCH_SUCCESS
)
2417 IPW_DEBUG_INFO("%s: DMA status match in Firmware at "
2418 "offset 0x%06X, length %d:\n",
2419 priv
->net_dev
->name
, match
,
2420 sizeof(struct ipw2100_status
));
2422 IPW_DEBUG_INFO("%s: No DMA status match in "
2423 "Firmware.\n", priv
->net_dev
->name
);
2425 printk_buf((u8
*) priv
->status_queue
.drv
,
2426 sizeof(struct ipw2100_status
) * RX_QUEUE_LENGTH
);
2429 priv
->fatal_error
= IPW2100_ERR_C3_CORRUPTION
;
2430 priv
->net_dev
->stats
.rx_errors
++;
2431 schedule_reset(priv
);
2434 static void isr_rx(struct ipw2100_priv
*priv
, int i
,
2435 struct libipw_rx_stats
*stats
)
2437 struct net_device
*dev
= priv
->net_dev
;
2438 struct ipw2100_status
*status
= &priv
->status_queue
.drv
[i
];
2439 struct ipw2100_rx_packet
*packet
= &priv
->rx_buffers
[i
];
2441 IPW_DEBUG_RX("Handler...\n");
2443 if (unlikely(status
->frame_size
> skb_tailroom(packet
->skb
))) {
2444 IPW_DEBUG_INFO("%s: frame_size (%u) > skb_tailroom (%u)!"
2447 status
->frame_size
, skb_tailroom(packet
->skb
));
2448 dev
->stats
.rx_errors
++;
2452 if (unlikely(!netif_running(dev
))) {
2453 dev
->stats
.rx_errors
++;
2454 priv
->wstats
.discard
.misc
++;
2455 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
2459 if (unlikely(priv
->ieee
->iw_mode
!= IW_MODE_MONITOR
&&
2460 !(priv
->status
& STATUS_ASSOCIATED
))) {
2461 IPW_DEBUG_DROP("Dropping packet while not associated.\n");
2462 priv
->wstats
.discard
.misc
++;
2466 dma_unmap_single(&priv
->pci_dev
->dev
, packet
->dma_addr
,
2467 sizeof(struct ipw2100_rx
), DMA_FROM_DEVICE
);
2469 skb_put(packet
->skb
, status
->frame_size
);
2471 #ifdef IPW2100_RX_DEBUG
2472 /* Make a copy of the frame so we can dump it to the logs if
2473 * libipw_rx fails */
2474 skb_copy_from_linear_data(packet
->skb
, packet_data
,
2475 min_t(u32
, status
->frame_size
,
2476 IPW_RX_NIC_BUFFER_LENGTH
));
2479 if (!libipw_rx(priv
->ieee
, packet
->skb
, stats
)) {
2480 #ifdef IPW2100_RX_DEBUG
2481 IPW_DEBUG_DROP("%s: Non consumed packet:\n",
2483 printk_buf(IPW_DL_DROP
, packet_data
, status
->frame_size
);
2485 dev
->stats
.rx_errors
++;
2487 /* libipw_rx failed, so it didn't free the SKB */
2488 dev_kfree_skb_any(packet
->skb
);
2492 /* We need to allocate a new SKB and attach it to the RDB. */
2493 if (unlikely(ipw2100_alloc_skb(priv
, packet
))) {
2494 printk(KERN_WARNING DRV_NAME
": "
2495 "%s: Unable to allocate SKB onto RBD ring - disabling "
2496 "adapter.\n", dev
->name
);
2497 /* TODO: schedule adapter shutdown */
2498 IPW_DEBUG_INFO("TODO: Shutdown adapter...\n");
2501 /* Update the RDB entry */
2502 priv
->rx_queue
.drv
[i
].host_addr
= packet
->dma_addr
;
2505 #ifdef CONFIG_IPW2100_MONITOR
2507 static void isr_rx_monitor(struct ipw2100_priv
*priv
, int i
,
2508 struct libipw_rx_stats
*stats
)
2510 struct net_device
*dev
= priv
->net_dev
;
2511 struct ipw2100_status
*status
= &priv
->status_queue
.drv
[i
];
2512 struct ipw2100_rx_packet
*packet
= &priv
->rx_buffers
[i
];
2514 /* Magic struct that slots into the radiotap header -- no reason
2515 * to build this manually element by element, we can write it much
2516 * more efficiently than we can parse it. ORDER MATTERS HERE */
2518 struct ieee80211_radiotap_header_fixed rt_hdr
;
2519 s8 rt_dbmsignal
; /* signal in dbM, kluged to signed */
2522 IPW_DEBUG_RX("Handler...\n");
2524 if (unlikely(status
->frame_size
> skb_tailroom(packet
->skb
) -
2525 sizeof(struct ipw_rt_hdr
))) {
2526 IPW_DEBUG_INFO("%s: frame_size (%u) > skb_tailroom (%u)!"
2530 skb_tailroom(packet
->skb
));
2531 dev
->stats
.rx_errors
++;
2535 if (unlikely(!netif_running(dev
))) {
2536 dev
->stats
.rx_errors
++;
2537 priv
->wstats
.discard
.misc
++;
2538 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
2542 if (unlikely(priv
->config
& CFG_CRC_CHECK
&&
2543 status
->flags
& IPW_STATUS_FLAG_CRC_ERROR
)) {
2544 IPW_DEBUG_RX("CRC error in packet. Dropping.\n");
2545 dev
->stats
.rx_errors
++;
2549 dma_unmap_single(&priv
->pci_dev
->dev
, packet
->dma_addr
,
2550 sizeof(struct ipw2100_rx
), DMA_FROM_DEVICE
);
2551 memmove(packet
->skb
->data
+ sizeof(struct ipw_rt_hdr
),
2552 packet
->skb
->data
, status
->frame_size
);
2554 ipw_rt
= (struct ipw_rt_hdr
*) packet
->skb
->data
;
2556 ipw_rt
->rt_hdr
.it_version
= PKTHDR_RADIOTAP_VERSION
;
2557 ipw_rt
->rt_hdr
.it_pad
= 0; /* always good to zero */
2558 ipw_rt
->rt_hdr
.it_len
= cpu_to_le16(sizeof(struct ipw_rt_hdr
)); /* total hdr+data */
2560 ipw_rt
->rt_hdr
.it_present
= cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL
);
2562 ipw_rt
->rt_dbmsignal
= status
->rssi
+ IPW2100_RSSI_TO_DBM
;
2564 skb_put(packet
->skb
, status
->frame_size
+ sizeof(struct ipw_rt_hdr
));
2566 if (!libipw_rx(priv
->ieee
, packet
->skb
, stats
)) {
2567 dev
->stats
.rx_errors
++;
2569 /* libipw_rx failed, so it didn't free the SKB */
2570 dev_kfree_skb_any(packet
->skb
);
2574 /* We need to allocate a new SKB and attach it to the RDB. */
2575 if (unlikely(ipw2100_alloc_skb(priv
, packet
))) {
2577 "%s: Unable to allocate SKB onto RBD ring - disabling "
2578 "adapter.\n", dev
->name
);
2579 /* TODO: schedule adapter shutdown */
2580 IPW_DEBUG_INFO("TODO: Shutdown adapter...\n");
2583 /* Update the RDB entry */
2584 priv
->rx_queue
.drv
[i
].host_addr
= packet
->dma_addr
;
2589 static int ipw2100_corruption_check(struct ipw2100_priv
*priv
, int i
)
2591 struct ipw2100_status
*status
= &priv
->status_queue
.drv
[i
];
2592 struct ipw2100_rx
*u
= priv
->rx_buffers
[i
].rxp
;
2593 u16 frame_type
= status
->status_fields
& STATUS_TYPE_MASK
;
2595 switch (frame_type
) {
2596 case COMMAND_STATUS_VAL
:
2597 return (status
->frame_size
!= sizeof(u
->rx_data
.command
));
2598 case STATUS_CHANGE_VAL
:
2599 return (status
->frame_size
!= sizeof(u
->rx_data
.status
));
2600 case HOST_NOTIFICATION_VAL
:
2601 return (status
->frame_size
< sizeof(u
->rx_data
.notification
));
2602 case P80211_DATA_VAL
:
2603 case P8023_DATA_VAL
:
2604 #ifdef CONFIG_IPW2100_MONITOR
2607 switch (WLAN_FC_GET_TYPE(le16_to_cpu(u
->rx_data
.header
.frame_ctl
))) {
2608 case IEEE80211_FTYPE_MGMT
:
2609 case IEEE80211_FTYPE_CTL
:
2611 case IEEE80211_FTYPE_DATA
:
2612 return (status
->frame_size
>
2613 IPW_MAX_802_11_PAYLOAD_LENGTH
);
2622 * ipw2100 interrupts are disabled at this point, and the ISR
2623 * is the only code that calls this method. So, we do not need
2624 * to play with any locks.
2626 * RX Queue works as follows:
2628 * Read index - firmware places packet in entry identified by the
2629 * Read index and advances Read index. In this manner,
2630 * Read index will always point to the next packet to
2631 * be filled--but not yet valid.
2633 * Write index - driver fills this entry with an unused RBD entry.
2634 * This entry has not filled by the firmware yet.
2636 * In between the W and R indexes are the RBDs that have been received
2637 * but not yet processed.
2639 * The process of handling packets will start at WRITE + 1 and advance
2640 * until it reaches the READ index.
2642 * The WRITE index is cached in the variable 'priv->rx_queue.next'.
2645 static void __ipw2100_rx_process(struct ipw2100_priv
*priv
)
2647 struct ipw2100_bd_queue
*rxq
= &priv
->rx_queue
;
2648 struct ipw2100_status_queue
*sq
= &priv
->status_queue
;
2649 struct ipw2100_rx_packet
*packet
;
2652 struct ipw2100_rx
*u
;
2653 struct libipw_rx_stats stats
= {
2654 .mac_time
= jiffies
,
2657 read_register(priv
->net_dev
, IPW_MEM_HOST_SHARED_RX_READ_INDEX
, &r
);
2658 read_register(priv
->net_dev
, IPW_MEM_HOST_SHARED_RX_WRITE_INDEX
, &w
);
2660 if (r
>= rxq
->entries
) {
2661 IPW_DEBUG_RX("exit - bad read index\n");
2665 i
= (rxq
->next
+ 1) % rxq
->entries
;
2668 /* IPW_DEBUG_RX("r = %d : w = %d : processing = %d\n",
2669 r, rxq->next, i); */
2671 packet
= &priv
->rx_buffers
[i
];
2673 /* Sync the DMA for the RX buffer so CPU is sure to get
2674 * the correct values */
2675 dma_sync_single_for_cpu(&priv
->pci_dev
->dev
, packet
->dma_addr
,
2676 sizeof(struct ipw2100_rx
),
2679 if (unlikely(ipw2100_corruption_check(priv
, i
))) {
2680 ipw2100_corruption_detected(priv
, i
);
2685 frame_type
= sq
->drv
[i
].status_fields
& STATUS_TYPE_MASK
;
2686 stats
.rssi
= sq
->drv
[i
].rssi
+ IPW2100_RSSI_TO_DBM
;
2687 stats
.len
= sq
->drv
[i
].frame_size
;
2690 if (stats
.rssi
!= 0)
2691 stats
.mask
|= LIBIPW_STATMASK_RSSI
;
2692 stats
.freq
= LIBIPW_24GHZ_BAND
;
2694 IPW_DEBUG_RX("%s: '%s' frame type received (%d).\n",
2695 priv
->net_dev
->name
, frame_types
[frame_type
],
2698 switch (frame_type
) {
2699 case COMMAND_STATUS_VAL
:
2700 /* Reset Rx watchdog */
2701 isr_rx_complete_command(priv
, &u
->rx_data
.command
);
2704 case STATUS_CHANGE_VAL
:
2705 isr_status_change(priv
, u
->rx_data
.status
);
2708 case P80211_DATA_VAL
:
2709 case P8023_DATA_VAL
:
2710 #ifdef CONFIG_IPW2100_MONITOR
2711 if (priv
->ieee
->iw_mode
== IW_MODE_MONITOR
) {
2712 isr_rx_monitor(priv
, i
, &stats
);
2716 if (stats
.len
< sizeof(struct libipw_hdr_3addr
))
2718 switch (WLAN_FC_GET_TYPE(le16_to_cpu(u
->rx_data
.header
.frame_ctl
))) {
2719 case IEEE80211_FTYPE_MGMT
:
2720 libipw_rx_mgt(priv
->ieee
,
2721 &u
->rx_data
.header
, &stats
);
2724 case IEEE80211_FTYPE_CTL
:
2727 case IEEE80211_FTYPE_DATA
:
2728 isr_rx(priv
, i
, &stats
);
2736 /* clear status field associated with this RBD */
2737 rxq
->drv
[i
].status
.info
.field
= 0;
2739 i
= (i
+ 1) % rxq
->entries
;
2743 /* backtrack one entry, wrapping to end if at 0 */
2744 rxq
->next
= (i
? i
: rxq
->entries
) - 1;
2746 write_register(priv
->net_dev
,
2747 IPW_MEM_HOST_SHARED_RX_WRITE_INDEX
, rxq
->next
);
2752 * __ipw2100_tx_process
2754 * This routine will determine whether the next packet on
2755 * the fw_pend_list has been processed by the firmware yet.
2757 * If not, then it does nothing and returns.
2759 * If so, then it removes the item from the fw_pend_list, frees
2760 * any associated storage, and places the item back on the
2761 * free list of its source (either msg_free_list or tx_free_list)
2763 * TX Queue works as follows:
2765 * Read index - points to the next TBD that the firmware will
2766 * process. The firmware will read the data, and once
2767 * done processing, it will advance the Read index.
2769 * Write index - driver fills this entry with an constructed TBD
2770 * entry. The Write index is not advanced until the
2771 * packet has been configured.
2773 * In between the W and R indexes are the TBDs that have NOT been
2774 * processed. Lagging behind the R index are packets that have
2775 * been processed but have not been freed by the driver.
2777 * In order to free old storage, an internal index will be maintained
2778 * that points to the next packet to be freed. When all used
2779 * packets have been freed, the oldest index will be the same as the
2780 * firmware's read index.
2782 * The OLDEST index is cached in the variable 'priv->tx_queue.oldest'
2784 * Because the TBD structure can not contain arbitrary data, the
2785 * driver must keep an internal queue of cached allocations such that
2786 * it can put that data back into the tx_free_list and msg_free_list
2787 * for use by future command and data packets.
2790 static int __ipw2100_tx_process(struct ipw2100_priv
*priv
)
2792 struct ipw2100_bd_queue
*txq
= &priv
->tx_queue
;
2793 struct ipw2100_bd
*tbd
;
2794 struct list_head
*element
;
2795 struct ipw2100_tx_packet
*packet
;
2796 int descriptors_used
;
2798 u32 r
, w
, frag_num
= 0;
2800 if (list_empty(&priv
->fw_pend_list
))
2803 element
= priv
->fw_pend_list
.next
;
2805 packet
= list_entry(element
, struct ipw2100_tx_packet
, list
);
2806 tbd
= &txq
->drv
[packet
->index
];
2808 /* Determine how many TBD entries must be finished... */
2809 switch (packet
->type
) {
2811 /* COMMAND uses only one slot; don't advance */
2812 descriptors_used
= 1;
2817 /* DATA uses two slots; advance and loop position. */
2818 descriptors_used
= tbd
->num_fragments
;
2819 frag_num
= tbd
->num_fragments
- 1;
2820 e
= txq
->oldest
+ frag_num
;
2825 printk(KERN_WARNING DRV_NAME
": %s: Bad fw_pend_list entry!\n",
2826 priv
->net_dev
->name
);
2830 /* if the last TBD is not done by NIC yet, then packet is
2831 * not ready to be released.
2834 read_register(priv
->net_dev
, IPW_MEM_HOST_SHARED_TX_QUEUE_READ_INDEX
,
2836 read_register(priv
->net_dev
, IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX
,
2839 printk(KERN_WARNING DRV_NAME
": %s: write index mismatch\n",
2840 priv
->net_dev
->name
);
2843 * txq->next is the index of the last packet written txq->oldest is
2844 * the index of the r is the index of the next packet to be read by
2849 * Quick graphic to help you visualize the following
2850 * if / else statement
2852 * ===>| s---->|===============
2854 * | a | b | c | d | e | f | g | h | i | j | k | l
2858 * w - updated by driver
2859 * r - updated by firmware
2860 * s - start of oldest BD entry (txq->oldest)
2861 * e - end of oldest BD entry
2864 if (!((r
<= w
&& (e
< r
|| e
>= w
)) || (e
< r
&& e
>= w
))) {
2865 IPW_DEBUG_TX("exit - no processed packets ready to release.\n");
2870 DEC_STAT(&priv
->fw_pend_stat
);
2872 #ifdef CONFIG_IPW2100_DEBUG
2875 IPW_DEBUG_TX("TX%d V=%p P=%04X T=%04X L=%d\n", i
,
2877 (u32
) (txq
->nic
+ i
* sizeof(struct ipw2100_bd
)),
2878 txq
->drv
[i
].host_addr
, txq
->drv
[i
].buf_length
);
2880 if (packet
->type
== DATA
) {
2881 i
= (i
+ 1) % txq
->entries
;
2883 IPW_DEBUG_TX("TX%d V=%p P=%04X T=%04X L=%d\n", i
,
2885 (u32
) (txq
->nic
+ i
*
2886 sizeof(struct ipw2100_bd
)),
2887 (u32
) txq
->drv
[i
].host_addr
,
2888 txq
->drv
[i
].buf_length
);
2893 switch (packet
->type
) {
2895 if (txq
->drv
[txq
->oldest
].status
.info
.fields
.txType
!= 0)
2896 printk(KERN_WARNING DRV_NAME
": %s: Queue mismatch. "
2897 "Expecting DATA TBD but pulled "
2898 "something else: ids %d=%d.\n",
2899 priv
->net_dev
->name
, txq
->oldest
, packet
->index
);
2901 /* DATA packet; we have to unmap and free the SKB */
2902 for (i
= 0; i
< frag_num
; i
++) {
2903 tbd
= &txq
->drv
[(packet
->index
+ 1 + i
) % txq
->entries
];
2905 IPW_DEBUG_TX("TX%d P=%08x L=%d\n",
2906 (packet
->index
+ 1 + i
) % txq
->entries
,
2907 tbd
->host_addr
, tbd
->buf_length
);
2909 dma_unmap_single(&priv
->pci_dev
->dev
, tbd
->host_addr
,
2910 tbd
->buf_length
, DMA_TO_DEVICE
);
2913 libipw_txb_free(packet
->info
.d_struct
.txb
);
2914 packet
->info
.d_struct
.txb
= NULL
;
2916 list_add_tail(element
, &priv
->tx_free_list
);
2917 INC_STAT(&priv
->tx_free_stat
);
2919 /* We have a free slot in the Tx queue, so wake up the
2920 * transmit layer if it is stopped. */
2921 if (priv
->status
& STATUS_ASSOCIATED
)
2922 netif_wake_queue(priv
->net_dev
);
2924 /* A packet was processed by the hardware, so update the
2926 netif_trans_update(priv
->net_dev
);
2931 if (txq
->drv
[txq
->oldest
].status
.info
.fields
.txType
!= 1)
2932 printk(KERN_WARNING DRV_NAME
": %s: Queue mismatch. "
2933 "Expecting COMMAND TBD but pulled "
2934 "something else: ids %d=%d.\n",
2935 priv
->net_dev
->name
, txq
->oldest
, packet
->index
);
2937 #ifdef CONFIG_IPW2100_DEBUG
2938 if (packet
->info
.c_struct
.cmd
->host_command_reg
<
2939 ARRAY_SIZE(command_types
))
2940 IPW_DEBUG_TX("Command '%s (%d)' processed: %d.\n",
2941 command_types
[packet
->info
.c_struct
.cmd
->
2943 packet
->info
.c_struct
.cmd
->
2945 packet
->info
.c_struct
.cmd
->cmd_status_reg
);
2948 list_add_tail(element
, &priv
->msg_free_list
);
2949 INC_STAT(&priv
->msg_free_stat
);
2953 /* advance oldest used TBD pointer to start of next entry */
2954 txq
->oldest
= (e
+ 1) % txq
->entries
;
2955 /* increase available TBDs number */
2956 txq
->available
+= descriptors_used
;
2957 SET_STAT(&priv
->txq_stat
, txq
->available
);
2959 IPW_DEBUG_TX("packet latency (send to process) %ld jiffies\n",
2960 jiffies
- packet
->jiffy_start
);
2962 return (!list_empty(&priv
->fw_pend_list
));
2965 static inline void __ipw2100_tx_complete(struct ipw2100_priv
*priv
)
2969 while (__ipw2100_tx_process(priv
) && i
< 200)
2973 printk(KERN_WARNING DRV_NAME
": "
2974 "%s: Driver is running slow (%d iters).\n",
2975 priv
->net_dev
->name
, i
);
2979 static void ipw2100_tx_send_commands(struct ipw2100_priv
*priv
)
2981 struct list_head
*element
;
2982 struct ipw2100_tx_packet
*packet
;
2983 struct ipw2100_bd_queue
*txq
= &priv
->tx_queue
;
2984 struct ipw2100_bd
*tbd
;
2985 int next
= txq
->next
;
2987 while (!list_empty(&priv
->msg_pend_list
)) {
2988 /* if there isn't enough space in TBD queue, then
2989 * don't stuff a new one in.
2990 * NOTE: 3 are needed as a command will take one,
2991 * and there is a minimum of 2 that must be
2992 * maintained between the r and w indexes
2994 if (txq
->available
<= 3) {
2995 IPW_DEBUG_TX("no room in tx_queue\n");
2999 element
= priv
->msg_pend_list
.next
;
3001 DEC_STAT(&priv
->msg_pend_stat
);
3003 packet
= list_entry(element
, struct ipw2100_tx_packet
, list
);
3005 IPW_DEBUG_TX("using TBD at virt=%p, phys=%04X\n",
3006 &txq
->drv
[txq
->next
],
3007 (u32
) (txq
->nic
+ txq
->next
*
3008 sizeof(struct ipw2100_bd
)));
3010 packet
->index
= txq
->next
;
3012 tbd
= &txq
->drv
[txq
->next
];
3014 /* initialize TBD */
3015 tbd
->host_addr
= packet
->info
.c_struct
.cmd_phys
;
3016 tbd
->buf_length
= sizeof(struct ipw2100_cmd_header
);
3017 /* not marking number of fragments causes problems
3018 * with f/w debug version */
3019 tbd
->num_fragments
= 1;
3020 tbd
->status
.info
.field
=
3021 IPW_BD_STATUS_TX_FRAME_COMMAND
|
3022 IPW_BD_STATUS_TX_INTERRUPT_ENABLE
;
3024 /* update TBD queue counters */
3026 txq
->next
%= txq
->entries
;
3028 DEC_STAT(&priv
->txq_stat
);
3030 list_add_tail(element
, &priv
->fw_pend_list
);
3031 INC_STAT(&priv
->fw_pend_stat
);
3034 if (txq
->next
!= next
) {
3035 /* kick off the DMA by notifying firmware the
3036 * write index has moved; make sure TBD stores are sync'd */
3038 write_register(priv
->net_dev
,
3039 IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX
,
3045 * ipw2100_tx_send_data
3048 static void ipw2100_tx_send_data(struct ipw2100_priv
*priv
)
3050 struct list_head
*element
;
3051 struct ipw2100_tx_packet
*packet
;
3052 struct ipw2100_bd_queue
*txq
= &priv
->tx_queue
;
3053 struct ipw2100_bd
*tbd
;
3054 int next
= txq
->next
;
3056 struct ipw2100_data_header
*ipw_hdr
;
3057 struct libipw_hdr_3addr
*hdr
;
3059 while (!list_empty(&priv
->tx_pend_list
)) {
3060 /* if there isn't enough space in TBD queue, then
3061 * don't stuff a new one in.
3062 * NOTE: 4 are needed as a data will take two,
3063 * and there is a minimum of 2 that must be
3064 * maintained between the r and w indexes
3066 element
= priv
->tx_pend_list
.next
;
3067 packet
= list_entry(element
, struct ipw2100_tx_packet
, list
);
3069 if (unlikely(1 + packet
->info
.d_struct
.txb
->nr_frags
>
3071 /* TODO: Support merging buffers if more than
3072 * IPW_MAX_BDS are used */
3073 IPW_DEBUG_INFO("%s: Maximum BD threshold exceeded. "
3074 "Increase fragmentation level.\n",
3075 priv
->net_dev
->name
);
3078 if (txq
->available
<= 3 + packet
->info
.d_struct
.txb
->nr_frags
) {
3079 IPW_DEBUG_TX("no room in tx_queue\n");
3084 DEC_STAT(&priv
->tx_pend_stat
);
3086 tbd
= &txq
->drv
[txq
->next
];
3088 packet
->index
= txq
->next
;
3090 ipw_hdr
= packet
->info
.d_struct
.data
;
3091 hdr
= (struct libipw_hdr_3addr
*)packet
->info
.d_struct
.txb
->
3094 if (priv
->ieee
->iw_mode
== IW_MODE_INFRA
) {
3095 /* To DS: Addr1 = BSSID, Addr2 = SA,
3097 memcpy(ipw_hdr
->src_addr
, hdr
->addr2
, ETH_ALEN
);
3098 memcpy(ipw_hdr
->dst_addr
, hdr
->addr3
, ETH_ALEN
);
3099 } else if (priv
->ieee
->iw_mode
== IW_MODE_ADHOC
) {
3100 /* not From/To DS: Addr1 = DA, Addr2 = SA,
3102 memcpy(ipw_hdr
->src_addr
, hdr
->addr2
, ETH_ALEN
);
3103 memcpy(ipw_hdr
->dst_addr
, hdr
->addr1
, ETH_ALEN
);
3106 ipw_hdr
->host_command_reg
= SEND
;
3107 ipw_hdr
->host_command_reg1
= 0;
3109 /* For now we only support host based encryption */
3110 ipw_hdr
->needs_encryption
= 0;
3111 ipw_hdr
->encrypted
= packet
->info
.d_struct
.txb
->encrypted
;
3112 if (packet
->info
.d_struct
.txb
->nr_frags
> 1)
3113 ipw_hdr
->fragment_size
=
3114 packet
->info
.d_struct
.txb
->frag_size
-
3117 ipw_hdr
->fragment_size
= 0;
3119 tbd
->host_addr
= packet
->info
.d_struct
.data_phys
;
3120 tbd
->buf_length
= sizeof(struct ipw2100_data_header
);
3121 tbd
->num_fragments
= 1 + packet
->info
.d_struct
.txb
->nr_frags
;
3122 tbd
->status
.info
.field
=
3123 IPW_BD_STATUS_TX_FRAME_802_3
|
3124 IPW_BD_STATUS_TX_FRAME_NOT_LAST_FRAGMENT
;
3126 txq
->next
%= txq
->entries
;
3128 IPW_DEBUG_TX("data header tbd TX%d P=%08x L=%d\n",
3129 packet
->index
, tbd
->host_addr
, tbd
->buf_length
);
3130 #ifdef CONFIG_IPW2100_DEBUG
3131 if (packet
->info
.d_struct
.txb
->nr_frags
> 1)
3132 IPW_DEBUG_FRAG("fragment Tx: %d frames\n",
3133 packet
->info
.d_struct
.txb
->nr_frags
);
3136 for (i
= 0; i
< packet
->info
.d_struct
.txb
->nr_frags
; i
++) {
3137 tbd
= &txq
->drv
[txq
->next
];
3138 if (i
== packet
->info
.d_struct
.txb
->nr_frags
- 1)
3139 tbd
->status
.info
.field
=
3140 IPW_BD_STATUS_TX_FRAME_802_3
|
3141 IPW_BD_STATUS_TX_INTERRUPT_ENABLE
;
3143 tbd
->status
.info
.field
=
3144 IPW_BD_STATUS_TX_FRAME_802_3
|
3145 IPW_BD_STATUS_TX_FRAME_NOT_LAST_FRAGMENT
;
3147 tbd
->buf_length
= packet
->info
.d_struct
.txb
->
3148 fragments
[i
]->len
- LIBIPW_3ADDR_LEN
;
3150 tbd
->host_addr
= dma_map_single(&priv
->pci_dev
->dev
,
3151 packet
->info
.d_struct
.
3152 txb
->fragments
[i
]->data
+
3156 if (dma_mapping_error(&priv
->pci_dev
->dev
, tbd
->host_addr
)) {
3157 IPW_DEBUG_TX("dma mapping error\n");
3161 IPW_DEBUG_TX("data frag tbd TX%d P=%08x L=%d\n",
3162 txq
->next
, tbd
->host_addr
,
3165 dma_sync_single_for_device(&priv
->pci_dev
->dev
,
3171 txq
->next
%= txq
->entries
;
3174 txq
->available
-= 1 + packet
->info
.d_struct
.txb
->nr_frags
;
3175 SET_STAT(&priv
->txq_stat
, txq
->available
);
3177 list_add_tail(element
, &priv
->fw_pend_list
);
3178 INC_STAT(&priv
->fw_pend_stat
);
3181 if (txq
->next
!= next
) {
3182 /* kick off the DMA by notifying firmware the
3183 * write index has moved; make sure TBD stores are sync'd */
3184 write_register(priv
->net_dev
,
3185 IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX
,
3190 static void ipw2100_irq_tasklet(struct tasklet_struct
*t
)
3192 struct ipw2100_priv
*priv
= from_tasklet(priv
, t
, irq_tasklet
);
3193 struct net_device
*dev
= priv
->net_dev
;
3194 unsigned long flags
;
3197 spin_lock_irqsave(&priv
->low_lock
, flags
);
3198 ipw2100_disable_interrupts(priv
);
3200 read_register(dev
, IPW_REG_INTA
, &inta
);
3202 IPW_DEBUG_ISR("enter - INTA: 0x%08lX\n",
3203 (unsigned long)inta
& IPW_INTERRUPT_MASK
);
3208 /* We do not loop and keep polling for more interrupts as this
3209 * is frowned upon and doesn't play nicely with other potentially
3211 IPW_DEBUG_ISR("INTA: 0x%08lX\n",
3212 (unsigned long)inta
& IPW_INTERRUPT_MASK
);
3214 if (inta
& IPW2100_INTA_FATAL_ERROR
) {
3215 printk(KERN_WARNING DRV_NAME
3216 ": Fatal interrupt. Scheduling firmware restart.\n");
3218 write_register(dev
, IPW_REG_INTA
, IPW2100_INTA_FATAL_ERROR
);
3220 read_nic_dword(dev
, IPW_NIC_FATAL_ERROR
, &priv
->fatal_error
);
3221 IPW_DEBUG_INFO("%s: Fatal error value: 0x%08X\n",
3222 priv
->net_dev
->name
, priv
->fatal_error
);
3224 read_nic_dword(dev
, IPW_ERROR_ADDR(priv
->fatal_error
), &tmp
);
3225 IPW_DEBUG_INFO("%s: Fatal error address value: 0x%08X\n",
3226 priv
->net_dev
->name
, tmp
);
3228 /* Wake up any sleeping jobs */
3229 schedule_reset(priv
);
3232 if (inta
& IPW2100_INTA_PARITY_ERROR
) {
3233 printk(KERN_ERR DRV_NAME
3234 ": ***** PARITY ERROR INTERRUPT !!!!\n");
3236 write_register(dev
, IPW_REG_INTA
, IPW2100_INTA_PARITY_ERROR
);
3239 if (inta
& IPW2100_INTA_RX_TRANSFER
) {
3240 IPW_DEBUG_ISR("RX interrupt\n");
3242 priv
->rx_interrupts
++;
3244 write_register(dev
, IPW_REG_INTA
, IPW2100_INTA_RX_TRANSFER
);
3246 __ipw2100_rx_process(priv
);
3247 __ipw2100_tx_complete(priv
);
3250 if (inta
& IPW2100_INTA_TX_TRANSFER
) {
3251 IPW_DEBUG_ISR("TX interrupt\n");
3253 priv
->tx_interrupts
++;
3255 write_register(dev
, IPW_REG_INTA
, IPW2100_INTA_TX_TRANSFER
);
3257 __ipw2100_tx_complete(priv
);
3258 ipw2100_tx_send_commands(priv
);
3259 ipw2100_tx_send_data(priv
);
3262 if (inta
& IPW2100_INTA_TX_COMPLETE
) {
3263 IPW_DEBUG_ISR("TX complete\n");
3265 write_register(dev
, IPW_REG_INTA
, IPW2100_INTA_TX_COMPLETE
);
3267 __ipw2100_tx_complete(priv
);
3270 if (inta
& IPW2100_INTA_EVENT_INTERRUPT
) {
3271 /* ipw2100_handle_event(dev); */
3273 write_register(dev
, IPW_REG_INTA
, IPW2100_INTA_EVENT_INTERRUPT
);
3276 if (inta
& IPW2100_INTA_FW_INIT_DONE
) {
3277 IPW_DEBUG_ISR("FW init done interrupt\n");
3280 read_register(dev
, IPW_REG_INTA
, &tmp
);
3281 if (tmp
& (IPW2100_INTA_FATAL_ERROR
|
3282 IPW2100_INTA_PARITY_ERROR
)) {
3283 write_register(dev
, IPW_REG_INTA
,
3284 IPW2100_INTA_FATAL_ERROR
|
3285 IPW2100_INTA_PARITY_ERROR
);
3288 write_register(dev
, IPW_REG_INTA
, IPW2100_INTA_FW_INIT_DONE
);
3291 if (inta
& IPW2100_INTA_STATUS_CHANGE
) {
3292 IPW_DEBUG_ISR("Status change interrupt\n");
3294 write_register(dev
, IPW_REG_INTA
, IPW2100_INTA_STATUS_CHANGE
);
3297 if (inta
& IPW2100_INTA_SLAVE_MODE_HOST_COMMAND_DONE
) {
3298 IPW_DEBUG_ISR("slave host mode interrupt\n");
3300 write_register(dev
, IPW_REG_INTA
,
3301 IPW2100_INTA_SLAVE_MODE_HOST_COMMAND_DONE
);
3305 ipw2100_enable_interrupts(priv
);
3307 spin_unlock_irqrestore(&priv
->low_lock
, flags
);
3309 IPW_DEBUG_ISR("exit\n");
3312 static irqreturn_t
ipw2100_interrupt(int irq
, void *data
)
3314 struct ipw2100_priv
*priv
= data
;
3315 u32 inta
, inta_mask
;
3320 spin_lock(&priv
->low_lock
);
3322 /* We check to see if we should be ignoring interrupts before
3323 * we touch the hardware. During ucode load if we try and handle
3324 * an interrupt we can cause keyboard problems as well as cause
3325 * the ucode to fail to initialize */
3326 if (!(priv
->status
& STATUS_INT_ENABLED
)) {
3331 read_register(priv
->net_dev
, IPW_REG_INTA_MASK
, &inta_mask
);
3332 read_register(priv
->net_dev
, IPW_REG_INTA
, &inta
);
3334 if (inta
== 0xFFFFFFFF) {
3335 /* Hardware disappeared */
3336 printk(KERN_WARNING DRV_NAME
": IRQ INTA == 0xFFFFFFFF\n");
3340 inta
&= IPW_INTERRUPT_MASK
;
3342 if (!(inta
& inta_mask
)) {
3343 /* Shared interrupt */
3347 /* We disable the hardware interrupt here just to prevent unneeded
3348 * calls to be made. We disable this again within the actual
3349 * work tasklet, so if another part of the code re-enables the
3350 * interrupt, that is fine */
3351 ipw2100_disable_interrupts(priv
);
3353 tasklet_schedule(&priv
->irq_tasklet
);
3354 spin_unlock(&priv
->low_lock
);
3358 spin_unlock(&priv
->low_lock
);
3362 static netdev_tx_t
ipw2100_tx(struct libipw_txb
*txb
,
3363 struct net_device
*dev
, int pri
)
3365 struct ipw2100_priv
*priv
= libipw_priv(dev
);
3366 struct list_head
*element
;
3367 struct ipw2100_tx_packet
*packet
;
3368 unsigned long flags
;
3370 spin_lock_irqsave(&priv
->low_lock
, flags
);
3372 if (!(priv
->status
& STATUS_ASSOCIATED
)) {
3373 IPW_DEBUG_INFO("Can not transmit when not connected.\n");
3374 priv
->net_dev
->stats
.tx_carrier_errors
++;
3375 netif_stop_queue(dev
);
3379 if (list_empty(&priv
->tx_free_list
))
3382 element
= priv
->tx_free_list
.next
;
3383 packet
= list_entry(element
, struct ipw2100_tx_packet
, list
);
3385 packet
->info
.d_struct
.txb
= txb
;
3387 IPW_DEBUG_TX("Sending fragment (%d bytes):\n", txb
->fragments
[0]->len
);
3388 printk_buf(IPW_DL_TX
, txb
->fragments
[0]->data
, txb
->fragments
[0]->len
);
3390 packet
->jiffy_start
= jiffies
;
3393 DEC_STAT(&priv
->tx_free_stat
);
3395 list_add_tail(element
, &priv
->tx_pend_list
);
3396 INC_STAT(&priv
->tx_pend_stat
);
3398 ipw2100_tx_send_data(priv
);
3400 spin_unlock_irqrestore(&priv
->low_lock
, flags
);
3401 return NETDEV_TX_OK
;
3404 netif_stop_queue(dev
);
3405 spin_unlock_irqrestore(&priv
->low_lock
, flags
);
3406 return NETDEV_TX_BUSY
;
3409 static int ipw2100_msg_allocate(struct ipw2100_priv
*priv
)
3411 int i
, j
, err
= -EINVAL
;
3416 kmalloc_array(IPW_COMMAND_POOL_SIZE
,
3417 sizeof(struct ipw2100_tx_packet
),
3419 if (!priv
->msg_buffers
)
3422 for (i
= 0; i
< IPW_COMMAND_POOL_SIZE
; i
++) {
3423 v
= dma_alloc_coherent(&priv
->pci_dev
->dev
,
3424 sizeof(struct ipw2100_cmd_header
), &p
,
3427 printk(KERN_ERR DRV_NAME
": "
3428 "%s: PCI alloc failed for msg "
3429 "buffers.\n", priv
->net_dev
->name
);
3434 priv
->msg_buffers
[i
].type
= COMMAND
;
3435 priv
->msg_buffers
[i
].info
.c_struct
.cmd
=
3436 (struct ipw2100_cmd_header
*)v
;
3437 priv
->msg_buffers
[i
].info
.c_struct
.cmd_phys
= p
;
3440 if (i
== IPW_COMMAND_POOL_SIZE
)
3443 for (j
= 0; j
< i
; j
++) {
3444 dma_free_coherent(&priv
->pci_dev
->dev
,
3445 sizeof(struct ipw2100_cmd_header
),
3446 priv
->msg_buffers
[j
].info
.c_struct
.cmd
,
3447 priv
->msg_buffers
[j
].info
.c_struct
.cmd_phys
);
3450 kfree(priv
->msg_buffers
);
3451 priv
->msg_buffers
= NULL
;
3456 static int ipw2100_msg_initialize(struct ipw2100_priv
*priv
)
3460 INIT_LIST_HEAD(&priv
->msg_free_list
);
3461 INIT_LIST_HEAD(&priv
->msg_pend_list
);
3463 for (i
= 0; i
< IPW_COMMAND_POOL_SIZE
; i
++)
3464 list_add_tail(&priv
->msg_buffers
[i
].list
, &priv
->msg_free_list
);
3465 SET_STAT(&priv
->msg_free_stat
, i
);
3470 static void ipw2100_msg_free(struct ipw2100_priv
*priv
)
3474 if (!priv
->msg_buffers
)
3477 for (i
= 0; i
< IPW_COMMAND_POOL_SIZE
; i
++) {
3478 dma_free_coherent(&priv
->pci_dev
->dev
,
3479 sizeof(struct ipw2100_cmd_header
),
3480 priv
->msg_buffers
[i
].info
.c_struct
.cmd
,
3481 priv
->msg_buffers
[i
].info
.c_struct
.cmd_phys
);
3484 kfree(priv
->msg_buffers
);
3485 priv
->msg_buffers
= NULL
;
3488 static ssize_t
pci_show(struct device
*d
, struct device_attribute
*attr
,
3491 struct pci_dev
*pci_dev
= to_pci_dev(d
);
3496 for (i
= 0; i
< 16; i
++) {
3497 out
+= sprintf(out
, "[%08X] ", i
* 16);
3498 for (j
= 0; j
< 16; j
+= 4) {
3499 pci_read_config_dword(pci_dev
, i
* 16 + j
, &val
);
3500 out
+= sprintf(out
, "%08X ", val
);
3502 out
+= sprintf(out
, "\n");
3508 static DEVICE_ATTR_RO(pci
);
3510 static ssize_t
cfg_show(struct device
*d
, struct device_attribute
*attr
,
3513 struct ipw2100_priv
*p
= dev_get_drvdata(d
);
3514 return sprintf(buf
, "0x%08x\n", (int)p
->config
);
3517 static DEVICE_ATTR_RO(cfg
);
3519 static ssize_t
status_show(struct device
*d
, struct device_attribute
*attr
,
3522 struct ipw2100_priv
*p
= dev_get_drvdata(d
);
3523 return sprintf(buf
, "0x%08x\n", (int)p
->status
);
3526 static DEVICE_ATTR_RO(status
);
3528 static ssize_t
capability_show(struct device
*d
, struct device_attribute
*attr
,
3531 struct ipw2100_priv
*p
= dev_get_drvdata(d
);
3532 return sprintf(buf
, "0x%08x\n", (int)p
->capability
);
3535 static DEVICE_ATTR_RO(capability
);
3537 #define IPW2100_REG(x) { IPW_ ##x, #x }
3538 static const struct {
3542 IPW2100_REG(REG_GP_CNTRL
),
3543 IPW2100_REG(REG_GPIO
),
3544 IPW2100_REG(REG_INTA
),
3545 IPW2100_REG(REG_INTA_MASK
), IPW2100_REG(REG_RESET_REG
),};
3546 #define IPW2100_NIC(x, s) { x, #x, s }
3547 static const struct {
3552 IPW2100_NIC(IPW2100_CONTROL_REG
, 2),
3553 IPW2100_NIC(0x210014, 1), IPW2100_NIC(0x210000, 1),};
3554 #define IPW2100_ORD(x, d) { IPW_ORD_ ##x, #x, d }
3555 static const struct {
3560 IPW2100_ORD(STAT_TX_HOST_REQUESTS
, "requested Host Tx's (MSDU)"),
3561 IPW2100_ORD(STAT_TX_HOST_COMPLETE
,
3562 "successful Host Tx's (MSDU)"),
3563 IPW2100_ORD(STAT_TX_DIR_DATA
,
3564 "successful Directed Tx's (MSDU)"),
3565 IPW2100_ORD(STAT_TX_DIR_DATA1
,
3566 "successful Directed Tx's (MSDU) @ 1MB"),
3567 IPW2100_ORD(STAT_TX_DIR_DATA2
,
3568 "successful Directed Tx's (MSDU) @ 2MB"),
3569 IPW2100_ORD(STAT_TX_DIR_DATA5_5
,
3570 "successful Directed Tx's (MSDU) @ 5_5MB"),
3571 IPW2100_ORD(STAT_TX_DIR_DATA11
,
3572 "successful Directed Tx's (MSDU) @ 11MB"),
3573 IPW2100_ORD(STAT_TX_NODIR_DATA1
,
3574 "successful Non_Directed Tx's (MSDU) @ 1MB"),
3575 IPW2100_ORD(STAT_TX_NODIR_DATA2
,
3576 "successful Non_Directed Tx's (MSDU) @ 2MB"),
3577 IPW2100_ORD(STAT_TX_NODIR_DATA5_5
,
3578 "successful Non_Directed Tx's (MSDU) @ 5.5MB"),
3579 IPW2100_ORD(STAT_TX_NODIR_DATA11
,
3580 "successful Non_Directed Tx's (MSDU) @ 11MB"),
3581 IPW2100_ORD(STAT_NULL_DATA
, "successful NULL data Tx's"),
3582 IPW2100_ORD(STAT_TX_RTS
, "successful Tx RTS"),
3583 IPW2100_ORD(STAT_TX_CTS
, "successful Tx CTS"),
3584 IPW2100_ORD(STAT_TX_ACK
, "successful Tx ACK"),
3585 IPW2100_ORD(STAT_TX_ASSN
, "successful Association Tx's"),
3586 IPW2100_ORD(STAT_TX_ASSN_RESP
,
3587 "successful Association response Tx's"),
3588 IPW2100_ORD(STAT_TX_REASSN
,
3589 "successful Reassociation Tx's"),
3590 IPW2100_ORD(STAT_TX_REASSN_RESP
,
3591 "successful Reassociation response Tx's"),
3592 IPW2100_ORD(STAT_TX_PROBE
,
3593 "probes successfully transmitted"),
3594 IPW2100_ORD(STAT_TX_PROBE_RESP
,
3595 "probe responses successfully transmitted"),
3596 IPW2100_ORD(STAT_TX_BEACON
, "tx beacon"),
3597 IPW2100_ORD(STAT_TX_ATIM
, "Tx ATIM"),
3598 IPW2100_ORD(STAT_TX_DISASSN
,
3599 "successful Disassociation TX"),
3600 IPW2100_ORD(STAT_TX_AUTH
, "successful Authentication Tx"),
3601 IPW2100_ORD(STAT_TX_DEAUTH
,
3602 "successful Deauthentication TX"),
3603 IPW2100_ORD(STAT_TX_TOTAL_BYTES
,
3604 "Total successful Tx data bytes"),
3605 IPW2100_ORD(STAT_TX_RETRIES
, "Tx retries"),
3606 IPW2100_ORD(STAT_TX_RETRY1
, "Tx retries at 1MBPS"),
3607 IPW2100_ORD(STAT_TX_RETRY2
, "Tx retries at 2MBPS"),
3608 IPW2100_ORD(STAT_TX_RETRY5_5
, "Tx retries at 5.5MBPS"),
3609 IPW2100_ORD(STAT_TX_RETRY11
, "Tx retries at 11MBPS"),
3610 IPW2100_ORD(STAT_TX_FAILURES
, "Tx Failures"),
3611 IPW2100_ORD(STAT_TX_MAX_TRIES_IN_HOP
,
3612 "times max tries in a hop failed"),
3613 IPW2100_ORD(STAT_TX_DISASSN_FAIL
,
3614 "times disassociation failed"),
3615 IPW2100_ORD(STAT_TX_ERR_CTS
, "missed/bad CTS frames"),
3616 IPW2100_ORD(STAT_TX_ERR_ACK
, "tx err due to acks"),
3617 IPW2100_ORD(STAT_RX_HOST
, "packets passed to host"),
3618 IPW2100_ORD(STAT_RX_DIR_DATA
, "directed packets"),
3619 IPW2100_ORD(STAT_RX_DIR_DATA1
, "directed packets at 1MB"),
3620 IPW2100_ORD(STAT_RX_DIR_DATA2
, "directed packets at 2MB"),
3621 IPW2100_ORD(STAT_RX_DIR_DATA5_5
,
3622 "directed packets at 5.5MB"),
3623 IPW2100_ORD(STAT_RX_DIR_DATA11
, "directed packets at 11MB"),
3624 IPW2100_ORD(STAT_RX_NODIR_DATA
, "nondirected packets"),
3625 IPW2100_ORD(STAT_RX_NODIR_DATA1
,
3626 "nondirected packets at 1MB"),
3627 IPW2100_ORD(STAT_RX_NODIR_DATA2
,
3628 "nondirected packets at 2MB"),
3629 IPW2100_ORD(STAT_RX_NODIR_DATA5_5
,
3630 "nondirected packets at 5.5MB"),
3631 IPW2100_ORD(STAT_RX_NODIR_DATA11
,
3632 "nondirected packets at 11MB"),
3633 IPW2100_ORD(STAT_RX_NULL_DATA
, "null data rx's"),
3634 IPW2100_ORD(STAT_RX_RTS
, "Rx RTS"), IPW2100_ORD(STAT_RX_CTS
,
3636 IPW2100_ORD(STAT_RX_ACK
, "Rx ACK"),
3637 IPW2100_ORD(STAT_RX_CFEND
, "Rx CF End"),
3638 IPW2100_ORD(STAT_RX_CFEND_ACK
, "Rx CF End + CF Ack"),
3639 IPW2100_ORD(STAT_RX_ASSN
, "Association Rx's"),
3640 IPW2100_ORD(STAT_RX_ASSN_RESP
, "Association response Rx's"),
3641 IPW2100_ORD(STAT_RX_REASSN
, "Reassociation Rx's"),
3642 IPW2100_ORD(STAT_RX_REASSN_RESP
,
3643 "Reassociation response Rx's"),
3644 IPW2100_ORD(STAT_RX_PROBE
, "probe Rx's"),
3645 IPW2100_ORD(STAT_RX_PROBE_RESP
, "probe response Rx's"),
3646 IPW2100_ORD(STAT_RX_BEACON
, "Rx beacon"),
3647 IPW2100_ORD(STAT_RX_ATIM
, "Rx ATIM"),
3648 IPW2100_ORD(STAT_RX_DISASSN
, "disassociation Rx"),
3649 IPW2100_ORD(STAT_RX_AUTH
, "authentication Rx"),
3650 IPW2100_ORD(STAT_RX_DEAUTH
, "deauthentication Rx"),
3651 IPW2100_ORD(STAT_RX_TOTAL_BYTES
,
3652 "Total rx data bytes received"),
3653 IPW2100_ORD(STAT_RX_ERR_CRC
, "packets with Rx CRC error"),
3654 IPW2100_ORD(STAT_RX_ERR_CRC1
, "Rx CRC errors at 1MB"),
3655 IPW2100_ORD(STAT_RX_ERR_CRC2
, "Rx CRC errors at 2MB"),
3656 IPW2100_ORD(STAT_RX_ERR_CRC5_5
, "Rx CRC errors at 5.5MB"),
3657 IPW2100_ORD(STAT_RX_ERR_CRC11
, "Rx CRC errors at 11MB"),
3658 IPW2100_ORD(STAT_RX_DUPLICATE1
,
3659 "duplicate rx packets at 1MB"),
3660 IPW2100_ORD(STAT_RX_DUPLICATE2
,
3661 "duplicate rx packets at 2MB"),
3662 IPW2100_ORD(STAT_RX_DUPLICATE5_5
,
3663 "duplicate rx packets at 5.5MB"),
3664 IPW2100_ORD(STAT_RX_DUPLICATE11
,
3665 "duplicate rx packets at 11MB"),
3666 IPW2100_ORD(STAT_RX_DUPLICATE
, "duplicate rx packets"),
3667 IPW2100_ORD(PERS_DB_LOCK
, "locking fw permanent db"),
3668 IPW2100_ORD(PERS_DB_SIZE
, "size of fw permanent db"),
3669 IPW2100_ORD(PERS_DB_ADDR
, "address of fw permanent db"),
3670 IPW2100_ORD(STAT_RX_INVALID_PROTOCOL
,
3671 "rx frames with invalid protocol"),
3672 IPW2100_ORD(SYS_BOOT_TIME
, "Boot time"),
3673 IPW2100_ORD(STAT_RX_NO_BUFFER
,
3674 "rx frames rejected due to no buffer"),
3675 IPW2100_ORD(STAT_RX_MISSING_FRAG
,
3676 "rx frames dropped due to missing fragment"),
3677 IPW2100_ORD(STAT_RX_ORPHAN_FRAG
,
3678 "rx frames dropped due to non-sequential fragment"),
3679 IPW2100_ORD(STAT_RX_ORPHAN_FRAME
,
3680 "rx frames dropped due to unmatched 1st frame"),
3681 IPW2100_ORD(STAT_RX_FRAG_AGEOUT
,
3682 "rx frames dropped due to uncompleted frame"),
3683 IPW2100_ORD(STAT_RX_ICV_ERRORS
,
3684 "ICV errors during decryption"),
3685 IPW2100_ORD(STAT_PSP_SUSPENSION
, "times adapter suspended"),
3686 IPW2100_ORD(STAT_PSP_BCN_TIMEOUT
, "beacon timeout"),
3687 IPW2100_ORD(STAT_PSP_POLL_TIMEOUT
,
3688 "poll response timeouts"),
3689 IPW2100_ORD(STAT_PSP_NONDIR_TIMEOUT
,
3690 "timeouts waiting for last {broad,multi}cast pkt"),
3691 IPW2100_ORD(STAT_PSP_RX_DTIMS
, "PSP DTIMs received"),
3692 IPW2100_ORD(STAT_PSP_RX_TIMS
, "PSP TIMs received"),
3693 IPW2100_ORD(STAT_PSP_STATION_ID
, "PSP Station ID"),
3694 IPW2100_ORD(LAST_ASSN_TIME
, "RTC time of last association"),
3695 IPW2100_ORD(STAT_PERCENT_MISSED_BCNS
,
3696 "current calculation of % missed beacons"),
3697 IPW2100_ORD(STAT_PERCENT_RETRIES
,
3698 "current calculation of % missed tx retries"),
3699 IPW2100_ORD(ASSOCIATED_AP_PTR
,
3700 "0 if not associated, else pointer to AP table entry"),
3701 IPW2100_ORD(AVAILABLE_AP_CNT
,
3702 "AP's described in the AP table"),
3703 IPW2100_ORD(AP_LIST_PTR
, "Ptr to list of available APs"),
3704 IPW2100_ORD(STAT_AP_ASSNS
, "associations"),
3705 IPW2100_ORD(STAT_ASSN_FAIL
, "association failures"),
3706 IPW2100_ORD(STAT_ASSN_RESP_FAIL
,
3707 "failures due to response fail"),
3708 IPW2100_ORD(STAT_FULL_SCANS
, "full scans"),
3709 IPW2100_ORD(CARD_DISABLED
, "Card Disabled"),
3710 IPW2100_ORD(STAT_ROAM_INHIBIT
,
3711 "times roaming was inhibited due to activity"),
3712 IPW2100_ORD(RSSI_AT_ASSN
,
3713 "RSSI of associated AP at time of association"),
3714 IPW2100_ORD(STAT_ASSN_CAUSE1
,
3715 "reassociation: no probe response or TX on hop"),
3716 IPW2100_ORD(STAT_ASSN_CAUSE2
,
3717 "reassociation: poor tx/rx quality"),
3718 IPW2100_ORD(STAT_ASSN_CAUSE3
,
3719 "reassociation: tx/rx quality (excessive AP load"),
3720 IPW2100_ORD(STAT_ASSN_CAUSE4
,
3721 "reassociation: AP RSSI level"),
3722 IPW2100_ORD(STAT_ASSN_CAUSE5
,
3723 "reassociations due to load leveling"),
3724 IPW2100_ORD(STAT_AUTH_FAIL
, "times authentication failed"),
3725 IPW2100_ORD(STAT_AUTH_RESP_FAIL
,
3726 "times authentication response failed"),
3727 IPW2100_ORD(STATION_TABLE_CNT
,
3728 "entries in association table"),
3729 IPW2100_ORD(RSSI_AVG_CURR
, "Current avg RSSI"),
3730 IPW2100_ORD(POWER_MGMT_MODE
, "Power mode - 0=CAM, 1=PSP"),
3731 IPW2100_ORD(COUNTRY_CODE
,
3732 "IEEE country code as recv'd from beacon"),
3733 IPW2100_ORD(COUNTRY_CHANNELS
,
3734 "channels supported by country"),
3735 IPW2100_ORD(RESET_CNT
, "adapter resets (warm)"),
3736 IPW2100_ORD(BEACON_INTERVAL
, "Beacon interval"),
3737 IPW2100_ORD(ANTENNA_DIVERSITY
,
3738 "TRUE if antenna diversity is disabled"),
3739 IPW2100_ORD(DTIM_PERIOD
, "beacon intervals between DTIMs"),
3740 IPW2100_ORD(OUR_FREQ
,
3741 "current radio freq lower digits - channel ID"),
3742 IPW2100_ORD(RTC_TIME
, "current RTC time"),
3743 IPW2100_ORD(PORT_TYPE
, "operating mode"),
3744 IPW2100_ORD(CURRENT_TX_RATE
, "current tx rate"),
3745 IPW2100_ORD(SUPPORTED_RATES
, "supported tx rates"),
3746 IPW2100_ORD(ATIM_WINDOW
, "current ATIM Window"),
3747 IPW2100_ORD(BASIC_RATES
, "basic tx rates"),
3748 IPW2100_ORD(NIC_HIGHEST_RATE
, "NIC highest tx rate"),
3749 IPW2100_ORD(AP_HIGHEST_RATE
, "AP highest tx rate"),
3750 IPW2100_ORD(CAPABILITIES
,
3751 "Management frame capability field"),
3752 IPW2100_ORD(AUTH_TYPE
, "Type of authentication"),
3753 IPW2100_ORD(RADIO_TYPE
, "Adapter card platform type"),
3754 IPW2100_ORD(RTS_THRESHOLD
,
3755 "Min packet length for RTS handshaking"),
3756 IPW2100_ORD(INT_MODE
, "International mode"),
3757 IPW2100_ORD(FRAGMENTATION_THRESHOLD
,
3758 "protocol frag threshold"),
3759 IPW2100_ORD(EEPROM_SRAM_DB_BLOCK_START_ADDRESS
,
3760 "EEPROM offset in SRAM"),
3761 IPW2100_ORD(EEPROM_SRAM_DB_BLOCK_SIZE
,
3762 "EEPROM size in SRAM"),
3763 IPW2100_ORD(EEPROM_SKU_CAPABILITY
, "EEPROM SKU Capability"),
3764 IPW2100_ORD(EEPROM_IBSS_11B_CHANNELS
,
3765 "EEPROM IBSS 11b channel set"),
3766 IPW2100_ORD(MAC_VERSION
, "MAC Version"),
3767 IPW2100_ORD(MAC_REVISION
, "MAC Revision"),
3768 IPW2100_ORD(RADIO_VERSION
, "Radio Version"),
3769 IPW2100_ORD(NIC_MANF_DATE_TIME
, "MANF Date/Time STAMP"),
3770 IPW2100_ORD(UCODE_VERSION
, "Ucode Version"),};
3772 static ssize_t
registers_show(struct device
*d
, struct device_attribute
*attr
,
3776 struct ipw2100_priv
*priv
= dev_get_drvdata(d
);
3777 struct net_device
*dev
= priv
->net_dev
;
3781 out
+= sprintf(out
, "%30s [Address ] : Hex\n", "Register");
3783 for (i
= 0; i
< ARRAY_SIZE(hw_data
); i
++) {
3784 read_register(dev
, hw_data
[i
].addr
, &val
);
3785 out
+= sprintf(out
, "%30s [%08X] : %08X\n",
3786 hw_data
[i
].name
, hw_data
[i
].addr
, val
);
3792 static DEVICE_ATTR_RO(registers
);
3794 static ssize_t
hardware_show(struct device
*d
, struct device_attribute
*attr
,
3797 struct ipw2100_priv
*priv
= dev_get_drvdata(d
);
3798 struct net_device
*dev
= priv
->net_dev
;
3802 out
+= sprintf(out
, "%30s [Address ] : Hex\n", "NIC entry");
3804 for (i
= 0; i
< ARRAY_SIZE(nic_data
); i
++) {
3809 switch (nic_data
[i
].size
) {
3811 read_nic_byte(dev
, nic_data
[i
].addr
, &tmp8
);
3812 out
+= sprintf(out
, "%30s [%08X] : %02X\n",
3813 nic_data
[i
].name
, nic_data
[i
].addr
,
3817 read_nic_word(dev
, nic_data
[i
].addr
, &tmp16
);
3818 out
+= sprintf(out
, "%30s [%08X] : %04X\n",
3819 nic_data
[i
].name
, nic_data
[i
].addr
,
3823 read_nic_dword(dev
, nic_data
[i
].addr
, &tmp32
);
3824 out
+= sprintf(out
, "%30s [%08X] : %08X\n",
3825 nic_data
[i
].name
, nic_data
[i
].addr
,
3833 static DEVICE_ATTR_RO(hardware
);
3835 static ssize_t
memory_show(struct device
*d
, struct device_attribute
*attr
,
3838 struct ipw2100_priv
*priv
= dev_get_drvdata(d
);
3839 struct net_device
*dev
= priv
->net_dev
;
3840 static unsigned long loop
= 0;
3846 if (loop
>= 0x30000)
3849 /* sysfs provides us PAGE_SIZE buffer */
3850 while (len
< PAGE_SIZE
- 128 && loop
< 0x30000) {
3852 if (priv
->snapshot
[0])
3853 for (i
= 0; i
< 4; i
++)
3855 *(u32
*) SNAPSHOT_ADDR(loop
+ i
* 4);
3857 for (i
= 0; i
< 4; i
++)
3858 read_nic_dword(dev
, loop
+ i
* 4, &buffer
[i
]);
3861 len
+= sprintf(buf
+ len
,
3866 ((u8
*) buffer
)[0x0],
3867 ((u8
*) buffer
)[0x1],
3868 ((u8
*) buffer
)[0x2],
3869 ((u8
*) buffer
)[0x3],
3870 ((u8
*) buffer
)[0x4],
3871 ((u8
*) buffer
)[0x5],
3872 ((u8
*) buffer
)[0x6],
3873 ((u8
*) buffer
)[0x7],
3874 ((u8
*) buffer
)[0x8],
3875 ((u8
*) buffer
)[0x9],
3876 ((u8
*) buffer
)[0xa],
3877 ((u8
*) buffer
)[0xb],
3878 ((u8
*) buffer
)[0xc],
3879 ((u8
*) buffer
)[0xd],
3880 ((u8
*) buffer
)[0xe],
3881 ((u8
*) buffer
)[0xf]);
3883 len
+= sprintf(buf
+ len
, "%s\n",
3884 snprint_line(line
, sizeof(line
),
3885 (u8
*) buffer
, 16, loop
));
3892 static ssize_t
memory_store(struct device
*d
, struct device_attribute
*attr
,
3893 const char *buf
, size_t count
)
3895 struct ipw2100_priv
*priv
= dev_get_drvdata(d
);
3896 struct net_device
*dev
= priv
->net_dev
;
3897 const char *p
= buf
;
3899 (void)dev
; /* kill unused-var warning for debug-only code */
3905 (count
>= 2 && tolower(p
[0]) == 'o' && tolower(p
[1]) == 'n')) {
3906 IPW_DEBUG_INFO("%s: Setting memory dump to RAW mode.\n",
3910 } else if (p
[0] == '0' || (count
>= 2 && tolower(p
[0]) == 'o' &&
3911 tolower(p
[1]) == 'f')) {
3912 IPW_DEBUG_INFO("%s: Setting memory dump to HEX mode.\n",
3916 } else if (tolower(p
[0]) == 'r') {
3917 IPW_DEBUG_INFO("%s: Resetting firmware snapshot.\n", dev
->name
);
3918 ipw2100_snapshot_free(priv
);
3921 IPW_DEBUG_INFO("%s: Usage: 0|on = HEX, 1|off = RAW, "
3922 "reset = clear memory snapshot\n", dev
->name
);
3927 static DEVICE_ATTR_RW(memory
);
3929 static ssize_t
ordinals_show(struct device
*d
, struct device_attribute
*attr
,
3932 struct ipw2100_priv
*priv
= dev_get_drvdata(d
);
3936 static int loop
= 0;
3938 if (priv
->status
& STATUS_RF_KILL_MASK
)
3941 if (loop
>= ARRAY_SIZE(ord_data
))
3944 /* sysfs provides us PAGE_SIZE buffer */
3945 while (len
< PAGE_SIZE
- 128 && loop
< ARRAY_SIZE(ord_data
)) {
3946 val_len
= sizeof(u32
);
3948 if (ipw2100_get_ordinal(priv
, ord_data
[loop
].index
, &val
,
3950 len
+= sprintf(buf
+ len
, "[0x%02X] = ERROR %s\n",
3951 ord_data
[loop
].index
,
3952 ord_data
[loop
].desc
);
3954 len
+= sprintf(buf
+ len
, "[0x%02X] = 0x%08X %s\n",
3955 ord_data
[loop
].index
, val
,
3956 ord_data
[loop
].desc
);
3963 static DEVICE_ATTR_RO(ordinals
);
3965 static ssize_t
stats_show(struct device
*d
, struct device_attribute
*attr
,
3968 struct ipw2100_priv
*priv
= dev_get_drvdata(d
);
3971 out
+= sprintf(out
, "interrupts: %d {tx: %d, rx: %d, other: %d}\n",
3972 priv
->interrupts
, priv
->tx_interrupts
,
3973 priv
->rx_interrupts
, priv
->inta_other
);
3974 out
+= sprintf(out
, "firmware resets: %d\n", priv
->resets
);
3975 out
+= sprintf(out
, "firmware hangs: %d\n", priv
->hangs
);
3976 #ifdef CONFIG_IPW2100_DEBUG
3977 out
+= sprintf(out
, "packet mismatch image: %s\n",
3978 priv
->snapshot
[0] ? "YES" : "NO");
3984 static DEVICE_ATTR_RO(stats
);
3986 static int ipw2100_switch_mode(struct ipw2100_priv
*priv
, u32 mode
)
3990 if (mode
== priv
->ieee
->iw_mode
)
3993 err
= ipw2100_disable_adapter(priv
);
3995 printk(KERN_ERR DRV_NAME
": %s: Could not disable adapter %d\n",
3996 priv
->net_dev
->name
, err
);
4002 priv
->net_dev
->type
= ARPHRD_ETHER
;
4005 priv
->net_dev
->type
= ARPHRD_ETHER
;
4007 #ifdef CONFIG_IPW2100_MONITOR
4008 case IW_MODE_MONITOR
:
4009 priv
->last_mode
= priv
->ieee
->iw_mode
;
4010 priv
->net_dev
->type
= ARPHRD_IEEE80211_RADIOTAP
;
4012 #endif /* CONFIG_IPW2100_MONITOR */
4015 priv
->ieee
->iw_mode
= mode
;
4018 /* Indicate ipw2100_download_firmware download firmware
4019 * from disk instead of memory. */
4020 ipw2100_firmware
.version
= 0;
4023 printk(KERN_INFO
"%s: Resetting on mode change.\n", priv
->net_dev
->name
);
4024 priv
->reset_backoff
= 0;
4025 schedule_reset(priv
);
4030 static ssize_t
internals_show(struct device
*d
, struct device_attribute
*attr
,
4033 struct ipw2100_priv
*priv
= dev_get_drvdata(d
);
4036 #define DUMP_VAR(x,y) len += sprintf(buf + len, # x ": %" y "\n", priv-> x)
4038 if (priv
->status
& STATUS_ASSOCIATED
)
4039 len
+= sprintf(buf
+ len
, "connected: %llu\n",
4040 ktime_get_boottime_seconds() - priv
->connect_start
);
4042 len
+= sprintf(buf
+ len
, "not connected\n");
4044 DUMP_VAR(ieee
->crypt_info
.crypt
[priv
->ieee
->crypt_info
.tx_keyidx
], "p");
4045 DUMP_VAR(status
, "08lx");
4046 DUMP_VAR(config
, "08lx");
4047 DUMP_VAR(capability
, "08lx");
4050 sprintf(buf
+ len
, "last_rtc: %lu\n",
4051 (unsigned long)priv
->last_rtc
);
4053 DUMP_VAR(fatal_error
, "d");
4054 DUMP_VAR(stop_hang_check
, "d");
4055 DUMP_VAR(stop_rf_kill
, "d");
4056 DUMP_VAR(messages_sent
, "d");
4058 DUMP_VAR(tx_pend_stat
.value
, "d");
4059 DUMP_VAR(tx_pend_stat
.hi
, "d");
4061 DUMP_VAR(tx_free_stat
.value
, "d");
4062 DUMP_VAR(tx_free_stat
.lo
, "d");
4064 DUMP_VAR(msg_free_stat
.value
, "d");
4065 DUMP_VAR(msg_free_stat
.lo
, "d");
4067 DUMP_VAR(msg_pend_stat
.value
, "d");
4068 DUMP_VAR(msg_pend_stat
.hi
, "d");
4070 DUMP_VAR(fw_pend_stat
.value
, "d");
4071 DUMP_VAR(fw_pend_stat
.hi
, "d");
4073 DUMP_VAR(txq_stat
.value
, "d");
4074 DUMP_VAR(txq_stat
.lo
, "d");
4076 DUMP_VAR(ieee
->scans
, "d");
4077 DUMP_VAR(reset_backoff
, "lld");
4082 static DEVICE_ATTR_RO(internals
);
4084 static ssize_t
bssinfo_show(struct device
*d
, struct device_attribute
*attr
,
4087 struct ipw2100_priv
*priv
= dev_get_drvdata(d
);
4088 char essid
[IW_ESSID_MAX_SIZE
+ 1];
4092 unsigned int length
;
4095 if (priv
->status
& STATUS_RF_KILL_MASK
)
4098 memset(essid
, 0, sizeof(essid
));
4099 memset(bssid
, 0, sizeof(bssid
));
4101 length
= IW_ESSID_MAX_SIZE
;
4102 ret
= ipw2100_get_ordinal(priv
, IPW_ORD_STAT_ASSN_SSID
, essid
, &length
);
4104 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
4107 length
= sizeof(bssid
);
4108 ret
= ipw2100_get_ordinal(priv
, IPW_ORD_STAT_ASSN_AP_BSSID
,
4111 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
4114 length
= sizeof(u32
);
4115 ret
= ipw2100_get_ordinal(priv
, IPW_ORD_OUR_FREQ
, &chan
, &length
);
4117 IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
4120 out
+= sprintf(out
, "ESSID: %s\n", essid
);
4121 out
+= sprintf(out
, "BSSID: %pM\n", bssid
);
4122 out
+= sprintf(out
, "Channel: %d\n", chan
);
4127 static DEVICE_ATTR_RO(bssinfo
);
4129 #ifdef CONFIG_IPW2100_DEBUG
4130 static ssize_t
debug_level_show(struct device_driver
*d
, char *buf
)
4132 return sprintf(buf
, "0x%08X\n", ipw2100_debug_level
);
4135 static ssize_t
debug_level_store(struct device_driver
*d
,
4136 const char *buf
, size_t count
)
4141 ret
= kstrtou32(buf
, 0, &val
);
4143 IPW_DEBUG_INFO(": %s is not in hex or decimal form.\n", buf
);
4145 ipw2100_debug_level
= val
;
4147 return strnlen(buf
, count
);
4149 static DRIVER_ATTR_RW(debug_level
);
4150 #endif /* CONFIG_IPW2100_DEBUG */
4152 static ssize_t
fatal_error_show(struct device
*d
,
4153 struct device_attribute
*attr
, char *buf
)
4155 struct ipw2100_priv
*priv
= dev_get_drvdata(d
);
4159 if (priv
->fatal_error
)
4160 out
+= sprintf(out
, "0x%08X\n", priv
->fatal_error
);
4162 out
+= sprintf(out
, "0\n");
4164 for (i
= 1; i
<= IPW2100_ERROR_QUEUE
; i
++) {
4165 if (!priv
->fatal_errors
[(priv
->fatal_index
- i
) %
4166 IPW2100_ERROR_QUEUE
])
4169 out
+= sprintf(out
, "%d. 0x%08X\n", i
,
4170 priv
->fatal_errors
[(priv
->fatal_index
- i
) %
4171 IPW2100_ERROR_QUEUE
]);
4177 static ssize_t
fatal_error_store(struct device
*d
,
4178 struct device_attribute
*attr
, const char *buf
,
4181 struct ipw2100_priv
*priv
= dev_get_drvdata(d
);
4182 schedule_reset(priv
);
4186 static DEVICE_ATTR_RW(fatal_error
);
4188 static ssize_t
scan_age_show(struct device
*d
, struct device_attribute
*attr
,
4191 struct ipw2100_priv
*priv
= dev_get_drvdata(d
);
4192 return sprintf(buf
, "%d\n", priv
->ieee
->scan_age
);
4195 static ssize_t
scan_age_store(struct device
*d
, struct device_attribute
*attr
,
4196 const char *buf
, size_t count
)
4198 struct ipw2100_priv
*priv
= dev_get_drvdata(d
);
4199 struct net_device
*dev
= priv
->net_dev
;
4203 (void)dev
; /* kill unused-var warning for debug-only code */
4205 IPW_DEBUG_INFO("enter\n");
4207 ret
= kstrtoul(buf
, 0, &val
);
4209 IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev
->name
);
4211 priv
->ieee
->scan_age
= val
;
4212 IPW_DEBUG_INFO("set scan_age = %u\n", priv
->ieee
->scan_age
);
4215 IPW_DEBUG_INFO("exit\n");
4216 return strnlen(buf
, count
);
4219 static DEVICE_ATTR_RW(scan_age
);
4221 static ssize_t
rf_kill_show(struct device
*d
, struct device_attribute
*attr
,
4224 /* 0 - RF kill not enabled
4225 1 - SW based RF kill active (sysfs)
4226 2 - HW based RF kill active
4227 3 - Both HW and SW baed RF kill active */
4228 struct ipw2100_priv
*priv
= dev_get_drvdata(d
);
4229 int val
= ((priv
->status
& STATUS_RF_KILL_SW
) ? 0x1 : 0x0) |
4230 (rf_kill_active(priv
) ? 0x2 : 0x0);
4231 return sprintf(buf
, "%i\n", val
);
4234 static int ipw_radio_kill_sw(struct ipw2100_priv
*priv
, int disable_radio
)
4236 if ((disable_radio
? 1 : 0) ==
4237 (priv
->status
& STATUS_RF_KILL_SW
? 1 : 0))
4240 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
4241 disable_radio
? "OFF" : "ON");
4243 mutex_lock(&priv
->action_mutex
);
4245 if (disable_radio
) {
4246 priv
->status
|= STATUS_RF_KILL_SW
;
4249 priv
->status
&= ~STATUS_RF_KILL_SW
;
4250 if (rf_kill_active(priv
)) {
4251 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
4252 "disabled by HW switch\n");
4253 /* Make sure the RF_KILL check timer is running */
4254 priv
->stop_rf_kill
= 0;
4255 mod_delayed_work(system_wq
, &priv
->rf_kill
,
4256 round_jiffies_relative(HZ
));
4258 schedule_reset(priv
);
4261 mutex_unlock(&priv
->action_mutex
);
4265 static ssize_t
rf_kill_store(struct device
*d
, struct device_attribute
*attr
,
4266 const char *buf
, size_t count
)
4268 struct ipw2100_priv
*priv
= dev_get_drvdata(d
);
4269 ipw_radio_kill_sw(priv
, buf
[0] == '1');
4273 static DEVICE_ATTR_RW(rf_kill
);
4275 static struct attribute
*ipw2100_sysfs_entries
[] = {
4276 &dev_attr_hardware
.attr
,
4277 &dev_attr_registers
.attr
,
4278 &dev_attr_ordinals
.attr
,
4280 &dev_attr_stats
.attr
,
4281 &dev_attr_internals
.attr
,
4282 &dev_attr_bssinfo
.attr
,
4283 &dev_attr_memory
.attr
,
4284 &dev_attr_scan_age
.attr
,
4285 &dev_attr_fatal_error
.attr
,
4286 &dev_attr_rf_kill
.attr
,
4288 &dev_attr_status
.attr
,
4289 &dev_attr_capability
.attr
,
4293 static const struct attribute_group ipw2100_attribute_group
= {
4294 .attrs
= ipw2100_sysfs_entries
,
4297 static int status_queue_allocate(struct ipw2100_priv
*priv
, int entries
)
4299 struct ipw2100_status_queue
*q
= &priv
->status_queue
;
4301 IPW_DEBUG_INFO("enter\n");
4303 q
->size
= entries
* sizeof(struct ipw2100_status
);
4304 q
->drv
= dma_alloc_coherent(&priv
->pci_dev
->dev
, q
->size
, &q
->nic
,
4307 IPW_DEBUG_WARNING("Can not allocate status queue.\n");
4311 IPW_DEBUG_INFO("exit\n");
4316 static void status_queue_free(struct ipw2100_priv
*priv
)
4318 IPW_DEBUG_INFO("enter\n");
4320 if (priv
->status_queue
.drv
) {
4321 dma_free_coherent(&priv
->pci_dev
->dev
,
4322 priv
->status_queue
.size
,
4323 priv
->status_queue
.drv
,
4324 priv
->status_queue
.nic
);
4325 priv
->status_queue
.drv
= NULL
;
4328 IPW_DEBUG_INFO("exit\n");
4331 static int bd_queue_allocate(struct ipw2100_priv
*priv
,
4332 struct ipw2100_bd_queue
*q
, int entries
)
4334 IPW_DEBUG_INFO("enter\n");
4336 memset(q
, 0, sizeof(struct ipw2100_bd_queue
));
4338 q
->entries
= entries
;
4339 q
->size
= entries
* sizeof(struct ipw2100_bd
);
4340 q
->drv
= dma_alloc_coherent(&priv
->pci_dev
->dev
, q
->size
, &q
->nic
,
4344 ("can't allocate shared memory for buffer descriptors\n");
4348 IPW_DEBUG_INFO("exit\n");
4353 static void bd_queue_free(struct ipw2100_priv
*priv
, struct ipw2100_bd_queue
*q
)
4355 IPW_DEBUG_INFO("enter\n");
4361 dma_free_coherent(&priv
->pci_dev
->dev
, q
->size
, q
->drv
,
4366 IPW_DEBUG_INFO("exit\n");
4369 static void bd_queue_initialize(struct ipw2100_priv
*priv
,
4370 struct ipw2100_bd_queue
*q
, u32 base
, u32 size
,
4373 IPW_DEBUG_INFO("enter\n");
4375 IPW_DEBUG_INFO("initializing bd queue at virt=%p, phys=%08x\n", q
->drv
,
4378 write_register(priv
->net_dev
, base
, q
->nic
);
4379 write_register(priv
->net_dev
, size
, q
->entries
);
4380 write_register(priv
->net_dev
, r
, q
->oldest
);
4381 write_register(priv
->net_dev
, w
, q
->next
);
4383 IPW_DEBUG_INFO("exit\n");
4386 static void ipw2100_kill_works(struct ipw2100_priv
*priv
)
4388 priv
->stop_rf_kill
= 1;
4389 priv
->stop_hang_check
= 1;
4390 cancel_delayed_work_sync(&priv
->reset_work
);
4391 cancel_delayed_work_sync(&priv
->security_work
);
4392 cancel_delayed_work_sync(&priv
->wx_event_work
);
4393 cancel_delayed_work_sync(&priv
->hang_check
);
4394 cancel_delayed_work_sync(&priv
->rf_kill
);
4395 cancel_delayed_work_sync(&priv
->scan_event
);
4398 static int ipw2100_tx_allocate(struct ipw2100_priv
*priv
)
4404 IPW_DEBUG_INFO("enter\n");
4406 err
= bd_queue_allocate(priv
, &priv
->tx_queue
, TX_QUEUE_LENGTH
);
4408 IPW_DEBUG_ERROR("%s: failed bd_queue_allocate\n",
4409 priv
->net_dev
->name
);
4413 priv
->tx_buffers
= kmalloc_array(TX_PENDED_QUEUE_LENGTH
,
4414 sizeof(struct ipw2100_tx_packet
),
4416 if (!priv
->tx_buffers
) {
4417 bd_queue_free(priv
, &priv
->tx_queue
);
4421 for (i
= 0; i
< TX_PENDED_QUEUE_LENGTH
; i
++) {
4422 v
= dma_alloc_coherent(&priv
->pci_dev
->dev
,
4423 sizeof(struct ipw2100_data_header
), &p
,
4426 printk(KERN_ERR DRV_NAME
4427 ": %s: PCI alloc failed for tx " "buffers.\n",
4428 priv
->net_dev
->name
);
4433 priv
->tx_buffers
[i
].type
= DATA
;
4434 priv
->tx_buffers
[i
].info
.d_struct
.data
=
4435 (struct ipw2100_data_header
*)v
;
4436 priv
->tx_buffers
[i
].info
.d_struct
.data_phys
= p
;
4437 priv
->tx_buffers
[i
].info
.d_struct
.txb
= NULL
;
4440 if (i
== TX_PENDED_QUEUE_LENGTH
)
4443 for (j
= 0; j
< i
; j
++) {
4444 dma_free_coherent(&priv
->pci_dev
->dev
,
4445 sizeof(struct ipw2100_data_header
),
4446 priv
->tx_buffers
[j
].info
.d_struct
.data
,
4447 priv
->tx_buffers
[j
].info
.d_struct
.data_phys
);
4450 kfree(priv
->tx_buffers
);
4451 priv
->tx_buffers
= NULL
;
4456 static void ipw2100_tx_initialize(struct ipw2100_priv
*priv
)
4460 IPW_DEBUG_INFO("enter\n");
4463 * reinitialize packet info lists
4465 INIT_LIST_HEAD(&priv
->fw_pend_list
);
4466 INIT_STAT(&priv
->fw_pend_stat
);
4469 * reinitialize lists
4471 INIT_LIST_HEAD(&priv
->tx_pend_list
);
4472 INIT_LIST_HEAD(&priv
->tx_free_list
);
4473 INIT_STAT(&priv
->tx_pend_stat
);
4474 INIT_STAT(&priv
->tx_free_stat
);
4476 for (i
= 0; i
< TX_PENDED_QUEUE_LENGTH
; i
++) {
4477 /* We simply drop any SKBs that have been queued for
4479 if (priv
->tx_buffers
[i
].info
.d_struct
.txb
) {
4480 libipw_txb_free(priv
->tx_buffers
[i
].info
.d_struct
.
4482 priv
->tx_buffers
[i
].info
.d_struct
.txb
= NULL
;
4485 list_add_tail(&priv
->tx_buffers
[i
].list
, &priv
->tx_free_list
);
4488 SET_STAT(&priv
->tx_free_stat
, i
);
4490 priv
->tx_queue
.oldest
= 0;
4491 priv
->tx_queue
.available
= priv
->tx_queue
.entries
;
4492 priv
->tx_queue
.next
= 0;
4493 INIT_STAT(&priv
->txq_stat
);
4494 SET_STAT(&priv
->txq_stat
, priv
->tx_queue
.available
);
4496 bd_queue_initialize(priv
, &priv
->tx_queue
,
4497 IPW_MEM_HOST_SHARED_TX_QUEUE_BD_BASE
,
4498 IPW_MEM_HOST_SHARED_TX_QUEUE_BD_SIZE
,
4499 IPW_MEM_HOST_SHARED_TX_QUEUE_READ_INDEX
,
4500 IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX
);
4502 IPW_DEBUG_INFO("exit\n");
4506 static void ipw2100_tx_free(struct ipw2100_priv
*priv
)
4510 IPW_DEBUG_INFO("enter\n");
4512 bd_queue_free(priv
, &priv
->tx_queue
);
4514 if (!priv
->tx_buffers
)
4517 for (i
= 0; i
< TX_PENDED_QUEUE_LENGTH
; i
++) {
4518 if (priv
->tx_buffers
[i
].info
.d_struct
.txb
) {
4519 libipw_txb_free(priv
->tx_buffers
[i
].info
.d_struct
.
4521 priv
->tx_buffers
[i
].info
.d_struct
.txb
= NULL
;
4523 if (priv
->tx_buffers
[i
].info
.d_struct
.data
)
4524 dma_free_coherent(&priv
->pci_dev
->dev
,
4525 sizeof(struct ipw2100_data_header
),
4526 priv
->tx_buffers
[i
].info
.d_struct
.data
,
4527 priv
->tx_buffers
[i
].info
.d_struct
.data_phys
);
4530 kfree(priv
->tx_buffers
);
4531 priv
->tx_buffers
= NULL
;
4533 IPW_DEBUG_INFO("exit\n");
4536 static int ipw2100_rx_allocate(struct ipw2100_priv
*priv
)
4538 int i
, j
, err
= -EINVAL
;
4540 IPW_DEBUG_INFO("enter\n");
4542 err
= bd_queue_allocate(priv
, &priv
->rx_queue
, RX_QUEUE_LENGTH
);
4544 IPW_DEBUG_INFO("failed bd_queue_allocate\n");
4548 err
= status_queue_allocate(priv
, RX_QUEUE_LENGTH
);
4550 IPW_DEBUG_INFO("failed status_queue_allocate\n");
4551 bd_queue_free(priv
, &priv
->rx_queue
);
4558 priv
->rx_buffers
= kmalloc_array(RX_QUEUE_LENGTH
,
4559 sizeof(struct ipw2100_rx_packet
),
4561 if (!priv
->rx_buffers
) {
4562 IPW_DEBUG_INFO("can't allocate rx packet buffer table\n");
4564 bd_queue_free(priv
, &priv
->rx_queue
);
4566 status_queue_free(priv
);
4571 for (i
= 0; i
< RX_QUEUE_LENGTH
; i
++) {
4572 struct ipw2100_rx_packet
*packet
= &priv
->rx_buffers
[i
];
4574 err
= ipw2100_alloc_skb(priv
, packet
);
4575 if (unlikely(err
)) {
4580 /* The BD holds the cache aligned address */
4581 priv
->rx_queue
.drv
[i
].host_addr
= packet
->dma_addr
;
4582 priv
->rx_queue
.drv
[i
].buf_length
= IPW_RX_NIC_BUFFER_LENGTH
;
4583 priv
->status_queue
.drv
[i
].status_fields
= 0;
4586 if (i
== RX_QUEUE_LENGTH
)
4589 for (j
= 0; j
< i
; j
++) {
4590 dma_unmap_single(&priv
->pci_dev
->dev
,
4591 priv
->rx_buffers
[j
].dma_addr
,
4592 sizeof(struct ipw2100_rx_packet
),
4594 dev_kfree_skb(priv
->rx_buffers
[j
].skb
);
4597 kfree(priv
->rx_buffers
);
4598 priv
->rx_buffers
= NULL
;
4600 bd_queue_free(priv
, &priv
->rx_queue
);
4602 status_queue_free(priv
);
4607 static void ipw2100_rx_initialize(struct ipw2100_priv
*priv
)
4609 IPW_DEBUG_INFO("enter\n");
4611 priv
->rx_queue
.oldest
= 0;
4612 priv
->rx_queue
.available
= priv
->rx_queue
.entries
- 1;
4613 priv
->rx_queue
.next
= priv
->rx_queue
.entries
- 1;
4615 INIT_STAT(&priv
->rxq_stat
);
4616 SET_STAT(&priv
->rxq_stat
, priv
->rx_queue
.available
);
4618 bd_queue_initialize(priv
, &priv
->rx_queue
,
4619 IPW_MEM_HOST_SHARED_RX_BD_BASE
,
4620 IPW_MEM_HOST_SHARED_RX_BD_SIZE
,
4621 IPW_MEM_HOST_SHARED_RX_READ_INDEX
,
4622 IPW_MEM_HOST_SHARED_RX_WRITE_INDEX
);
4624 /* set up the status queue */
4625 write_register(priv
->net_dev
, IPW_MEM_HOST_SHARED_RX_STATUS_BASE
,
4626 priv
->status_queue
.nic
);
4628 IPW_DEBUG_INFO("exit\n");
4631 static void ipw2100_rx_free(struct ipw2100_priv
*priv
)
4635 IPW_DEBUG_INFO("enter\n");
4637 bd_queue_free(priv
, &priv
->rx_queue
);
4638 status_queue_free(priv
);
4640 if (!priv
->rx_buffers
)
4643 for (i
= 0; i
< RX_QUEUE_LENGTH
; i
++) {
4644 if (priv
->rx_buffers
[i
].rxp
) {
4645 dma_unmap_single(&priv
->pci_dev
->dev
,
4646 priv
->rx_buffers
[i
].dma_addr
,
4647 sizeof(struct ipw2100_rx
),
4649 dev_kfree_skb(priv
->rx_buffers
[i
].skb
);
4653 kfree(priv
->rx_buffers
);
4654 priv
->rx_buffers
= NULL
;
4656 IPW_DEBUG_INFO("exit\n");
4659 static int ipw2100_read_mac_address(struct ipw2100_priv
*priv
)
4661 u32 length
= ETH_ALEN
;
4666 err
= ipw2100_get_ordinal(priv
, IPW_ORD_STAT_ADAPTER_MAC
, addr
, &length
);
4668 IPW_DEBUG_INFO("MAC address read failed\n");
4672 eth_hw_addr_set(priv
->net_dev
, addr
);
4673 IPW_DEBUG_INFO("card MAC is %pM\n", priv
->net_dev
->dev_addr
);
4678 /********************************************************************
4682 ********************************************************************/
4684 static int ipw2100_set_mac_address(struct ipw2100_priv
*priv
, int batch_mode
)
4686 struct host_command cmd
= {
4687 .host_command
= ADAPTER_ADDRESS
,
4688 .host_command_sequence
= 0,
4689 .host_command_length
= ETH_ALEN
4693 IPW_DEBUG_HC("SET_MAC_ADDRESS\n");
4695 IPW_DEBUG_INFO("enter\n");
4697 if (priv
->config
& CFG_CUSTOM_MAC
) {
4698 memcpy(cmd
.host_command_parameters
, priv
->mac_addr
, ETH_ALEN
);
4699 eth_hw_addr_set(priv
->net_dev
, priv
->mac_addr
);
4701 memcpy(cmd
.host_command_parameters
, priv
->net_dev
->dev_addr
,
4704 err
= ipw2100_hw_send_command(priv
, &cmd
);
4706 IPW_DEBUG_INFO("exit\n");
4710 static int ipw2100_set_port_type(struct ipw2100_priv
*priv
, u32 port_type
,
4713 struct host_command cmd
= {
4714 .host_command
= PORT_TYPE
,
4715 .host_command_sequence
= 0,
4716 .host_command_length
= sizeof(u32
)
4720 switch (port_type
) {
4722 cmd
.host_command_parameters
[0] = IPW_BSS
;
4725 cmd
.host_command_parameters
[0] = IPW_IBSS
;
4729 IPW_DEBUG_HC("PORT_TYPE: %s\n",
4730 port_type
== IPW_IBSS
? "Ad-Hoc" : "Managed");
4733 err
= ipw2100_disable_adapter(priv
);
4735 printk(KERN_ERR DRV_NAME
4736 ": %s: Could not disable adapter %d\n",
4737 priv
->net_dev
->name
, err
);
4742 /* send cmd to firmware */
4743 err
= ipw2100_hw_send_command(priv
, &cmd
);
4746 ipw2100_enable_adapter(priv
);
4751 static int ipw2100_set_channel(struct ipw2100_priv
*priv
, u32 channel
,
4754 struct host_command cmd
= {
4755 .host_command
= CHANNEL
,
4756 .host_command_sequence
= 0,
4757 .host_command_length
= sizeof(u32
)
4761 cmd
.host_command_parameters
[0] = channel
;
4763 IPW_DEBUG_HC("CHANNEL: %d\n", channel
);
4765 /* If BSS then we don't support channel selection */
4766 if (priv
->ieee
->iw_mode
== IW_MODE_INFRA
)
4769 if ((channel
!= 0) &&
4770 ((channel
< REG_MIN_CHANNEL
) || (channel
> REG_MAX_CHANNEL
)))
4774 err
= ipw2100_disable_adapter(priv
);
4779 err
= ipw2100_hw_send_command(priv
, &cmd
);
4781 IPW_DEBUG_INFO("Failed to set channel to %d", channel
);
4786 priv
->config
|= CFG_STATIC_CHANNEL
;
4788 priv
->config
&= ~CFG_STATIC_CHANNEL
;
4790 priv
->channel
= channel
;
4793 err
= ipw2100_enable_adapter(priv
);
4801 static int ipw2100_system_config(struct ipw2100_priv
*priv
, int batch_mode
)
4803 struct host_command cmd
= {
4804 .host_command
= SYSTEM_CONFIG
,
4805 .host_command_sequence
= 0,
4806 .host_command_length
= 12,
4808 u32 ibss_mask
, len
= sizeof(u32
);
4811 /* Set system configuration */
4814 err
= ipw2100_disable_adapter(priv
);
4819 if (priv
->ieee
->iw_mode
== IW_MODE_ADHOC
)
4820 cmd
.host_command_parameters
[0] |= IPW_CFG_IBSS_AUTO_START
;
4822 cmd
.host_command_parameters
[0] |= IPW_CFG_IBSS_MASK
|
4823 IPW_CFG_BSS_MASK
| IPW_CFG_802_1x_ENABLE
;
4825 if (!(priv
->config
& CFG_LONG_PREAMBLE
))
4826 cmd
.host_command_parameters
[0] |= IPW_CFG_PREAMBLE_AUTO
;
4828 err
= ipw2100_get_ordinal(priv
,
4829 IPW_ORD_EEPROM_IBSS_11B_CHANNELS
,
4832 ibss_mask
= IPW_IBSS_11B_DEFAULT_MASK
;
4834 cmd
.host_command_parameters
[1] = REG_CHANNEL_MASK
;
4835 cmd
.host_command_parameters
[2] = REG_CHANNEL_MASK
& ibss_mask
;
4838 /*cmd.host_command_parameters[0] |= DIVERSITY_ANTENNA_A; */
4840 err
= ipw2100_hw_send_command(priv
, &cmd
);
4844 /* If IPv6 is configured in the kernel then we don't want to filter out all
4845 * of the multicast packets as IPv6 needs some. */
4846 #if !defined(CONFIG_IPV6) && !defined(CONFIG_IPV6_MODULE)
4847 cmd
.host_command
= ADD_MULTICAST
;
4848 cmd
.host_command_sequence
= 0;
4849 cmd
.host_command_length
= 0;
4851 ipw2100_hw_send_command(priv
, &cmd
);
4854 err
= ipw2100_enable_adapter(priv
);
4862 static int ipw2100_set_tx_rates(struct ipw2100_priv
*priv
, u32 rate
,
4865 struct host_command cmd
= {
4866 .host_command
= BASIC_TX_RATES
,
4867 .host_command_sequence
= 0,
4868 .host_command_length
= 4
4872 cmd
.host_command_parameters
[0] = rate
& TX_RATE_MASK
;
4875 err
= ipw2100_disable_adapter(priv
);
4880 /* Set BASIC TX Rate first */
4881 ipw2100_hw_send_command(priv
, &cmd
);
4884 cmd
.host_command
= TX_RATES
;
4885 ipw2100_hw_send_command(priv
, &cmd
);
4887 /* Set MSDU TX Rate */
4888 cmd
.host_command
= MSDU_TX_RATES
;
4889 ipw2100_hw_send_command(priv
, &cmd
);
4892 err
= ipw2100_enable_adapter(priv
);
4897 priv
->tx_rates
= rate
;
4902 static int ipw2100_set_power_mode(struct ipw2100_priv
*priv
, int power_level
)
4904 struct host_command cmd
= {
4905 .host_command
= POWER_MODE
,
4906 .host_command_sequence
= 0,
4907 .host_command_length
= 4
4911 cmd
.host_command_parameters
[0] = power_level
;
4913 err
= ipw2100_hw_send_command(priv
, &cmd
);
4917 if (power_level
== IPW_POWER_MODE_CAM
)
4918 priv
->power_mode
= IPW_POWER_LEVEL(priv
->power_mode
);
4920 priv
->power_mode
= IPW_POWER_ENABLED
| power_level
;
4922 #ifdef IPW2100_TX_POWER
4923 if (priv
->port_type
== IBSS
&& priv
->adhoc_power
!= DFTL_IBSS_TX_POWER
) {
4924 /* Set beacon interval */
4925 cmd
.host_command
= TX_POWER_INDEX
;
4926 cmd
.host_command_parameters
[0] = (u32
) priv
->adhoc_power
;
4928 err
= ipw2100_hw_send_command(priv
, &cmd
);
4937 static int ipw2100_set_rts_threshold(struct ipw2100_priv
*priv
, u32 threshold
)
4939 struct host_command cmd
= {
4940 .host_command
= RTS_THRESHOLD
,
4941 .host_command_sequence
= 0,
4942 .host_command_length
= 4
4946 if (threshold
& RTS_DISABLED
)
4947 cmd
.host_command_parameters
[0] = MAX_RTS_THRESHOLD
;
4949 cmd
.host_command_parameters
[0] = threshold
& ~RTS_DISABLED
;
4951 err
= ipw2100_hw_send_command(priv
, &cmd
);
4955 priv
->rts_threshold
= threshold
;
4961 int ipw2100_set_fragmentation_threshold(struct ipw2100_priv
*priv
,
4962 u32 threshold
, int batch_mode
)
4964 struct host_command cmd
= {
4965 .host_command
= FRAG_THRESHOLD
,
4966 .host_command_sequence
= 0,
4967 .host_command_length
= 4,
4968 .host_command_parameters
[0] = 0,
4973 err
= ipw2100_disable_adapter(priv
);
4979 threshold
= DEFAULT_FRAG_THRESHOLD
;
4981 threshold
= max(threshold
, MIN_FRAG_THRESHOLD
);
4982 threshold
= min(threshold
, MAX_FRAG_THRESHOLD
);
4985 cmd
.host_command_parameters
[0] = threshold
;
4987 IPW_DEBUG_HC("FRAG_THRESHOLD: %u\n", threshold
);
4989 err
= ipw2100_hw_send_command(priv
, &cmd
);
4992 ipw2100_enable_adapter(priv
);
4995 priv
->frag_threshold
= threshold
;
5001 static int ipw2100_set_short_retry(struct ipw2100_priv
*priv
, u32 retry
)
5003 struct host_command cmd
= {
5004 .host_command
= SHORT_RETRY_LIMIT
,
5005 .host_command_sequence
= 0,
5006 .host_command_length
= 4
5010 cmd
.host_command_parameters
[0] = retry
;
5012 err
= ipw2100_hw_send_command(priv
, &cmd
);
5016 priv
->short_retry_limit
= retry
;
5021 static int ipw2100_set_long_retry(struct ipw2100_priv
*priv
, u32 retry
)
5023 struct host_command cmd
= {
5024 .host_command
= LONG_RETRY_LIMIT
,
5025 .host_command_sequence
= 0,
5026 .host_command_length
= 4
5030 cmd
.host_command_parameters
[0] = retry
;
5032 err
= ipw2100_hw_send_command(priv
, &cmd
);
5036 priv
->long_retry_limit
= retry
;
5041 static int ipw2100_set_mandatory_bssid(struct ipw2100_priv
*priv
, u8
* bssid
,
5044 struct host_command cmd
= {
5045 .host_command
= MANDATORY_BSSID
,
5046 .host_command_sequence
= 0,
5047 .host_command_length
= (bssid
== NULL
) ? 0 : ETH_ALEN
5051 #ifdef CONFIG_IPW2100_DEBUG
5053 IPW_DEBUG_HC("MANDATORY_BSSID: %pM\n", bssid
);
5055 IPW_DEBUG_HC("MANDATORY_BSSID: <clear>\n");
5057 /* if BSSID is empty then we disable mandatory bssid mode */
5059 memcpy(cmd
.host_command_parameters
, bssid
, ETH_ALEN
);
5062 err
= ipw2100_disable_adapter(priv
);
5067 err
= ipw2100_hw_send_command(priv
, &cmd
);
5070 ipw2100_enable_adapter(priv
);
5075 static int ipw2100_disassociate_bssid(struct ipw2100_priv
*priv
)
5077 struct host_command cmd
= {
5078 .host_command
= DISASSOCIATION_BSSID
,
5079 .host_command_sequence
= 0,
5080 .host_command_length
= ETH_ALEN
5084 IPW_DEBUG_HC("DISASSOCIATION_BSSID\n");
5086 /* The Firmware currently ignores the BSSID and just disassociates from
5087 * the currently associated AP -- but in the off chance that a future
5088 * firmware does use the BSSID provided here, we go ahead and try and
5089 * set it to the currently associated AP's BSSID */
5090 memcpy(cmd
.host_command_parameters
, priv
->bssid
, ETH_ALEN
);
5092 err
= ipw2100_hw_send_command(priv
, &cmd
);
5097 static int ipw2100_set_wpa_ie(struct ipw2100_priv
*,
5098 struct ipw2100_wpa_assoc_frame
*, int)
5099 __attribute__ ((unused
));
5101 static int ipw2100_set_wpa_ie(struct ipw2100_priv
*priv
,
5102 struct ipw2100_wpa_assoc_frame
*wpa_frame
,
5105 struct host_command cmd
= {
5106 .host_command
= SET_WPA_IE
,
5107 .host_command_sequence
= 0,
5108 .host_command_length
= sizeof(struct ipw2100_wpa_assoc_frame
),
5112 IPW_DEBUG_HC("SET_WPA_IE\n");
5115 err
= ipw2100_disable_adapter(priv
);
5120 memcpy(cmd
.host_command_parameters
, wpa_frame
,
5121 sizeof(struct ipw2100_wpa_assoc_frame
));
5123 err
= ipw2100_hw_send_command(priv
, &cmd
);
5126 if (ipw2100_enable_adapter(priv
))
5133 struct security_info_params
{
5134 u32 allowed_ciphers
;
5137 u8 replay_counters_number
;
5138 u8 unicast_using_group
;
5141 static int ipw2100_set_security_information(struct ipw2100_priv
*priv
,
5144 int unicast_using_group
,
5147 struct host_command cmd
= {
5148 .host_command
= SET_SECURITY_INFORMATION
,
5149 .host_command_sequence
= 0,
5150 .host_command_length
= sizeof(struct security_info_params
)
5152 struct security_info_params
*security
=
5153 (struct security_info_params
*)&cmd
.host_command_parameters
;
5155 memset(security
, 0, sizeof(*security
));
5157 /* If shared key AP authentication is turned on, then we need to
5158 * configure the firmware to try and use it.
5160 * Actual data encryption/decryption is handled by the host. */
5161 security
->auth_mode
= auth_mode
;
5162 security
->unicast_using_group
= unicast_using_group
;
5164 switch (security_level
) {
5167 security
->allowed_ciphers
= IPW_NONE_CIPHER
;
5170 security
->allowed_ciphers
= IPW_WEP40_CIPHER
|
5174 security
->allowed_ciphers
= IPW_WEP40_CIPHER
|
5175 IPW_WEP104_CIPHER
| IPW_TKIP_CIPHER
;
5177 case SEC_LEVEL_2_CKIP
:
5178 security
->allowed_ciphers
= IPW_WEP40_CIPHER
|
5179 IPW_WEP104_CIPHER
| IPW_CKIP_CIPHER
;
5182 security
->allowed_ciphers
= IPW_WEP40_CIPHER
|
5183 IPW_WEP104_CIPHER
| IPW_TKIP_CIPHER
| IPW_CCMP_CIPHER
;
5188 ("SET_SECURITY_INFORMATION: auth:%d cipher:0x%02X (level %d)\n",
5189 security
->auth_mode
, security
->allowed_ciphers
, security_level
);
5191 security
->replay_counters_number
= 0;
5194 err
= ipw2100_disable_adapter(priv
);
5199 err
= ipw2100_hw_send_command(priv
, &cmd
);
5202 ipw2100_enable_adapter(priv
);
5207 static int ipw2100_set_tx_power(struct ipw2100_priv
*priv
, u32 tx_power
)
5209 struct host_command cmd
= {
5210 .host_command
= TX_POWER_INDEX
,
5211 .host_command_sequence
= 0,
5212 .host_command_length
= 4
5217 if (tx_power
!= IPW_TX_POWER_DEFAULT
)
5218 tmp
= (tx_power
- IPW_TX_POWER_MIN_DBM
) * 16 /
5219 (IPW_TX_POWER_MAX_DBM
- IPW_TX_POWER_MIN_DBM
);
5221 cmd
.host_command_parameters
[0] = tmp
;
5223 if (priv
->ieee
->iw_mode
== IW_MODE_ADHOC
)
5224 err
= ipw2100_hw_send_command(priv
, &cmd
);
5226 priv
->tx_power
= tx_power
;
5231 static int ipw2100_set_ibss_beacon_interval(struct ipw2100_priv
*priv
,
5232 u32 interval
, int batch_mode
)
5234 struct host_command cmd
= {
5235 .host_command
= BEACON_INTERVAL
,
5236 .host_command_sequence
= 0,
5237 .host_command_length
= 4
5241 cmd
.host_command_parameters
[0] = interval
;
5243 IPW_DEBUG_INFO("enter\n");
5245 if (priv
->ieee
->iw_mode
== IW_MODE_ADHOC
) {
5247 err
= ipw2100_disable_adapter(priv
);
5252 ipw2100_hw_send_command(priv
, &cmd
);
5255 err
= ipw2100_enable_adapter(priv
);
5261 IPW_DEBUG_INFO("exit\n");
5266 static void ipw2100_queues_initialize(struct ipw2100_priv
*priv
)
5268 ipw2100_tx_initialize(priv
);
5269 ipw2100_rx_initialize(priv
);
5270 ipw2100_msg_initialize(priv
);
5273 static void ipw2100_queues_free(struct ipw2100_priv
*priv
)
5275 ipw2100_tx_free(priv
);
5276 ipw2100_rx_free(priv
);
5277 ipw2100_msg_free(priv
);
5280 static int ipw2100_queues_allocate(struct ipw2100_priv
*priv
)
5282 if (ipw2100_tx_allocate(priv
) ||
5283 ipw2100_rx_allocate(priv
) || ipw2100_msg_allocate(priv
))
5289 ipw2100_tx_free(priv
);
5290 ipw2100_rx_free(priv
);
5291 ipw2100_msg_free(priv
);
5295 #define IPW_PRIVACY_CAPABLE 0x0008
5297 static int ipw2100_set_wep_flags(struct ipw2100_priv
*priv
, u32 flags
,
5300 struct host_command cmd
= {
5301 .host_command
= WEP_FLAGS
,
5302 .host_command_sequence
= 0,
5303 .host_command_length
= 4
5307 cmd
.host_command_parameters
[0] = flags
;
5309 IPW_DEBUG_HC("WEP_FLAGS: flags = 0x%08X\n", flags
);
5312 err
= ipw2100_disable_adapter(priv
);
5314 printk(KERN_ERR DRV_NAME
5315 ": %s: Could not disable adapter %d\n",
5316 priv
->net_dev
->name
, err
);
5321 /* send cmd to firmware */
5322 err
= ipw2100_hw_send_command(priv
, &cmd
);
5325 ipw2100_enable_adapter(priv
);
5330 struct ipw2100_wep_key
{
5336 /* Macros to ease up priting WEP keys */
5337 #define WEP_FMT_64 "%02X%02X%02X%02X-%02X"
5338 #define WEP_FMT_128 "%02X%02X%02X%02X-%02X%02X%02X%02X-%02X%02X%02X"
5339 #define WEP_STR_64(x) x[0],x[1],x[2],x[3],x[4]
5340 #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]
5343 * ipw2100_set_key() - Set a the wep key
5345 * @priv: struct to work on
5346 * @idx: index of the key we want to set
5347 * @key: ptr to the key data to set
5348 * @len: length of the buffer at @key
5349 * @batch_mode: FIXME perform the operation in batch mode, not
5350 * disabling the device.
5352 * @returns 0 if OK, < 0 errno code on error.
5354 * Fill out a command structure with the new wep key, length an
5355 * index and send it down the wire.
5357 static int ipw2100_set_key(struct ipw2100_priv
*priv
,
5358 int idx
, char *key
, int len
, int batch_mode
)
5360 int keylen
= len
? (len
<= 5 ? 5 : 13) : 0;
5361 struct host_command cmd
= {
5362 .host_command
= WEP_KEY_INFO
,
5363 .host_command_sequence
= 0,
5364 .host_command_length
= sizeof(struct ipw2100_wep_key
),
5366 struct ipw2100_wep_key
*wep_key
= (void *)cmd
.host_command_parameters
;
5369 IPW_DEBUG_HC("WEP_KEY_INFO: index = %d, len = %d/%d\n",
5372 /* NOTE: We don't check cached values in case the firmware was reset
5373 * or some other problem is occurring. If the user is setting the key,
5374 * then we push the change */
5377 wep_key
->len
= keylen
;
5380 memcpy(wep_key
->key
, key
, len
);
5381 memset(wep_key
->key
+ len
, 0, keylen
- len
);
5384 /* Will be optimized out on debug not being configured in */
5386 IPW_DEBUG_WEP("%s: Clearing key %d\n",
5387 priv
->net_dev
->name
, wep_key
->idx
);
5388 else if (keylen
== 5)
5389 IPW_DEBUG_WEP("%s: idx: %d, len: %d key: " WEP_FMT_64
"\n",
5390 priv
->net_dev
->name
, wep_key
->idx
, wep_key
->len
,
5391 WEP_STR_64(wep_key
->key
));
5393 IPW_DEBUG_WEP("%s: idx: %d, len: %d key: " WEP_FMT_128
5395 priv
->net_dev
->name
, wep_key
->idx
, wep_key
->len
,
5396 WEP_STR_128(wep_key
->key
));
5399 err
= ipw2100_disable_adapter(priv
);
5400 /* FIXME: IPG: shouldn't this prink be in _disable_adapter()? */
5402 printk(KERN_ERR DRV_NAME
5403 ": %s: Could not disable adapter %d\n",
5404 priv
->net_dev
->name
, err
);
5409 /* send cmd to firmware */
5410 err
= ipw2100_hw_send_command(priv
, &cmd
);
5413 int err2
= ipw2100_enable_adapter(priv
);
5420 static int ipw2100_set_key_index(struct ipw2100_priv
*priv
,
5421 int idx
, int batch_mode
)
5423 struct host_command cmd
= {
5424 .host_command
= WEP_KEY_INDEX
,
5425 .host_command_sequence
= 0,
5426 .host_command_length
= 4,
5427 .host_command_parameters
= {idx
},
5431 IPW_DEBUG_HC("WEP_KEY_INDEX: index = %d\n", idx
);
5433 if (idx
< 0 || idx
> 3)
5437 err
= ipw2100_disable_adapter(priv
);
5439 printk(KERN_ERR DRV_NAME
5440 ": %s: Could not disable adapter %d\n",
5441 priv
->net_dev
->name
, err
);
5446 /* send cmd to firmware */
5447 err
= ipw2100_hw_send_command(priv
, &cmd
);
5450 ipw2100_enable_adapter(priv
);
5455 static int ipw2100_configure_security(struct ipw2100_priv
*priv
, int batch_mode
)
5457 int i
, err
, auth_mode
, sec_level
, use_group
;
5459 if (!(priv
->status
& STATUS_RUNNING
))
5463 err
= ipw2100_disable_adapter(priv
);
5468 if (!priv
->ieee
->sec
.enabled
) {
5470 ipw2100_set_security_information(priv
, IPW_AUTH_OPEN
,
5473 auth_mode
= IPW_AUTH_OPEN
;
5474 if (priv
->ieee
->sec
.flags
& SEC_AUTH_MODE
) {
5475 if (priv
->ieee
->sec
.auth_mode
== WLAN_AUTH_SHARED_KEY
)
5476 auth_mode
= IPW_AUTH_SHARED
;
5477 else if (priv
->ieee
->sec
.auth_mode
== WLAN_AUTH_LEAP
)
5478 auth_mode
= IPW_AUTH_LEAP_CISCO_ID
;
5481 sec_level
= SEC_LEVEL_0
;
5482 if (priv
->ieee
->sec
.flags
& SEC_LEVEL
)
5483 sec_level
= priv
->ieee
->sec
.level
;
5486 if (priv
->ieee
->sec
.flags
& SEC_UNICAST_GROUP
)
5487 use_group
= priv
->ieee
->sec
.unicast_uses_group
;
5490 ipw2100_set_security_information(priv
, auth_mode
, sec_level
,
5497 if (priv
->ieee
->sec
.enabled
) {
5498 for (i
= 0; i
< 4; i
++) {
5499 if (!(priv
->ieee
->sec
.flags
& (1 << i
))) {
5500 memset(priv
->ieee
->sec
.keys
[i
], 0, WEP_KEY_LEN
);
5501 priv
->ieee
->sec
.key_sizes
[i
] = 0;
5503 err
= ipw2100_set_key(priv
, i
,
5504 priv
->ieee
->sec
.keys
[i
],
5512 ipw2100_set_key_index(priv
, priv
->ieee
->crypt_info
.tx_keyidx
, 1);
5515 /* Always enable privacy so the Host can filter WEP packets if
5516 * encrypted data is sent up */
5518 ipw2100_set_wep_flags(priv
,
5520 enabled
? IPW_PRIVACY_CAPABLE
: 0, 1);
5524 priv
->status
&= ~STATUS_SECURITY_UPDATED
;
5528 ipw2100_enable_adapter(priv
);
5533 static void ipw2100_security_work(struct work_struct
*work
)
5535 struct ipw2100_priv
*priv
=
5536 container_of(work
, struct ipw2100_priv
, security_work
.work
);
5538 /* If we happen to have reconnected before we get a chance to
5539 * process this, then update the security settings--which causes
5540 * a disassociation to occur */
5541 if (!(priv
->status
& STATUS_ASSOCIATED
) &&
5542 priv
->status
& STATUS_SECURITY_UPDATED
)
5543 ipw2100_configure_security(priv
, 0);
5546 static void shim__set_security(struct net_device
*dev
,
5547 struct libipw_security
*sec
)
5549 struct ipw2100_priv
*priv
= libipw_priv(dev
);
5552 mutex_lock(&priv
->action_mutex
);
5553 if (!(priv
->status
& STATUS_INITIALIZED
))
5556 for (i
= 0; i
< 4; i
++) {
5557 if (sec
->flags
& (1 << i
)) {
5558 priv
->ieee
->sec
.key_sizes
[i
] = sec
->key_sizes
[i
];
5559 if (sec
->key_sizes
[i
] == 0)
5560 priv
->ieee
->sec
.flags
&= ~(1 << i
);
5562 memcpy(priv
->ieee
->sec
.keys
[i
], sec
->keys
[i
],
5564 if (sec
->level
== SEC_LEVEL_1
) {
5565 priv
->ieee
->sec
.flags
|= (1 << i
);
5566 priv
->status
|= STATUS_SECURITY_UPDATED
;
5568 priv
->ieee
->sec
.flags
&= ~(1 << i
);
5572 if ((sec
->flags
& SEC_ACTIVE_KEY
) &&
5573 priv
->ieee
->sec
.active_key
!= sec
->active_key
) {
5574 priv
->ieee
->sec
.active_key
= sec
->active_key
;
5575 priv
->ieee
->sec
.flags
|= SEC_ACTIVE_KEY
;
5576 priv
->status
|= STATUS_SECURITY_UPDATED
;
5579 if ((sec
->flags
& SEC_AUTH_MODE
) &&
5580 (priv
->ieee
->sec
.auth_mode
!= sec
->auth_mode
)) {
5581 priv
->ieee
->sec
.auth_mode
= sec
->auth_mode
;
5582 priv
->ieee
->sec
.flags
|= SEC_AUTH_MODE
;
5583 priv
->status
|= STATUS_SECURITY_UPDATED
;
5586 if (sec
->flags
& SEC_ENABLED
&& priv
->ieee
->sec
.enabled
!= sec
->enabled
) {
5587 priv
->ieee
->sec
.flags
|= SEC_ENABLED
;
5588 priv
->ieee
->sec
.enabled
= sec
->enabled
;
5589 priv
->status
|= STATUS_SECURITY_UPDATED
;
5592 if (sec
->flags
& SEC_ENCRYPT
)
5593 priv
->ieee
->sec
.encrypt
= sec
->encrypt
;
5595 if (sec
->flags
& SEC_LEVEL
&& priv
->ieee
->sec
.level
!= sec
->level
) {
5596 priv
->ieee
->sec
.level
= sec
->level
;
5597 priv
->ieee
->sec
.flags
|= SEC_LEVEL
;
5598 priv
->status
|= STATUS_SECURITY_UPDATED
;
5601 IPW_DEBUG_WEP("Security flags: %c %c%c%c%c %c%c%c%c\n",
5602 priv
->ieee
->sec
.flags
& (1 << 8) ? '1' : '0',
5603 priv
->ieee
->sec
.flags
& (1 << 7) ? '1' : '0',
5604 priv
->ieee
->sec
.flags
& (1 << 6) ? '1' : '0',
5605 priv
->ieee
->sec
.flags
& (1 << 5) ? '1' : '0',
5606 priv
->ieee
->sec
.flags
& (1 << 4) ? '1' : '0',
5607 priv
->ieee
->sec
.flags
& (1 << 3) ? '1' : '0',
5608 priv
->ieee
->sec
.flags
& (1 << 2) ? '1' : '0',
5609 priv
->ieee
->sec
.flags
& (1 << 1) ? '1' : '0',
5610 priv
->ieee
->sec
.flags
& (1 << 0) ? '1' : '0');
5612 /* As a temporary work around to enable WPA until we figure out why
5613 * wpa_supplicant toggles the security capability of the driver, which
5614 * forces a disassociation with force_update...
5616 * if (force_update || !(priv->status & STATUS_ASSOCIATED))*/
5617 if (!(priv
->status
& (STATUS_ASSOCIATED
| STATUS_ASSOCIATING
)))
5618 ipw2100_configure_security(priv
, 0);
5620 mutex_unlock(&priv
->action_mutex
);
5623 static int ipw2100_adapter_setup(struct ipw2100_priv
*priv
)
5629 IPW_DEBUG_INFO("enter\n");
5631 err
= ipw2100_disable_adapter(priv
);
5634 #ifdef CONFIG_IPW2100_MONITOR
5635 if (priv
->ieee
->iw_mode
== IW_MODE_MONITOR
) {
5636 err
= ipw2100_set_channel(priv
, priv
->channel
, batch_mode
);
5640 IPW_DEBUG_INFO("exit\n");
5644 #endif /* CONFIG_IPW2100_MONITOR */
5646 err
= ipw2100_read_mac_address(priv
);
5650 err
= ipw2100_set_mac_address(priv
, batch_mode
);
5654 err
= ipw2100_set_port_type(priv
, priv
->ieee
->iw_mode
, batch_mode
);
5658 if (priv
->ieee
->iw_mode
== IW_MODE_ADHOC
) {
5659 err
= ipw2100_set_channel(priv
, priv
->channel
, batch_mode
);
5664 err
= ipw2100_system_config(priv
, batch_mode
);
5668 err
= ipw2100_set_tx_rates(priv
, priv
->tx_rates
, batch_mode
);
5672 /* Default to power mode OFF */
5673 err
= ipw2100_set_power_mode(priv
, IPW_POWER_MODE_CAM
);
5677 err
= ipw2100_set_rts_threshold(priv
, priv
->rts_threshold
);
5681 if (priv
->config
& CFG_STATIC_BSSID
)
5682 bssid
= priv
->bssid
;
5685 err
= ipw2100_set_mandatory_bssid(priv
, bssid
, batch_mode
);
5689 if (priv
->config
& CFG_STATIC_ESSID
)
5690 err
= ipw2100_set_essid(priv
, priv
->essid
, priv
->essid_len
,
5693 err
= ipw2100_set_essid(priv
, NULL
, 0, batch_mode
);
5697 err
= ipw2100_configure_security(priv
, batch_mode
);
5701 if (priv
->ieee
->iw_mode
== IW_MODE_ADHOC
) {
5703 ipw2100_set_ibss_beacon_interval(priv
,
5704 priv
->beacon_interval
,
5709 err
= ipw2100_set_tx_power(priv
, priv
->tx_power
);
5715 err = ipw2100_set_fragmentation_threshold(
5716 priv, priv->frag_threshold, batch_mode);
5721 IPW_DEBUG_INFO("exit\n");
5726 /*************************************************************************
5728 * EXTERNALLY CALLED METHODS
5730 *************************************************************************/
5732 /* This method is called by the network layer -- not to be confused with
5733 * ipw2100_set_mac_address() declared above called by this driver (and this
5734 * method as well) to talk to the firmware */
5735 static int ipw2100_set_address(struct net_device
*dev
, void *p
)
5737 struct ipw2100_priv
*priv
= libipw_priv(dev
);
5738 struct sockaddr
*addr
= p
;
5741 if (!is_valid_ether_addr(addr
->sa_data
))
5742 return -EADDRNOTAVAIL
;
5744 mutex_lock(&priv
->action_mutex
);
5746 priv
->config
|= CFG_CUSTOM_MAC
;
5747 memcpy(priv
->mac_addr
, addr
->sa_data
, ETH_ALEN
);
5749 err
= ipw2100_set_mac_address(priv
, 0);
5753 priv
->reset_backoff
= 0;
5754 mutex_unlock(&priv
->action_mutex
);
5755 ipw2100_reset_adapter(&priv
->reset_work
.work
);
5759 mutex_unlock(&priv
->action_mutex
);
5763 static int ipw2100_open(struct net_device
*dev
)
5765 struct ipw2100_priv
*priv
= libipw_priv(dev
);
5766 unsigned long flags
;
5767 IPW_DEBUG_INFO("dev->open\n");
5769 spin_lock_irqsave(&priv
->low_lock
, flags
);
5770 if (priv
->status
& STATUS_ASSOCIATED
) {
5771 netif_carrier_on(dev
);
5772 netif_start_queue(dev
);
5774 spin_unlock_irqrestore(&priv
->low_lock
, flags
);
5779 static int ipw2100_close(struct net_device
*dev
)
5781 struct ipw2100_priv
*priv
= libipw_priv(dev
);
5782 unsigned long flags
;
5783 struct list_head
*element
;
5784 struct ipw2100_tx_packet
*packet
;
5786 IPW_DEBUG_INFO("enter\n");
5788 spin_lock_irqsave(&priv
->low_lock
, flags
);
5790 if (priv
->status
& STATUS_ASSOCIATED
)
5791 netif_carrier_off(dev
);
5792 netif_stop_queue(dev
);
5794 /* Flush the TX queue ... */
5795 while (!list_empty(&priv
->tx_pend_list
)) {
5796 element
= priv
->tx_pend_list
.next
;
5797 packet
= list_entry(element
, struct ipw2100_tx_packet
, list
);
5800 DEC_STAT(&priv
->tx_pend_stat
);
5802 libipw_txb_free(packet
->info
.d_struct
.txb
);
5803 packet
->info
.d_struct
.txb
= NULL
;
5805 list_add_tail(element
, &priv
->tx_free_list
);
5806 INC_STAT(&priv
->tx_free_stat
);
5808 spin_unlock_irqrestore(&priv
->low_lock
, flags
);
5810 IPW_DEBUG_INFO("exit\n");
5816 * TODO: Fix this function... its just wrong
5818 static void ipw2100_tx_timeout(struct net_device
*dev
, unsigned int txqueue
)
5820 struct ipw2100_priv
*priv
= libipw_priv(dev
);
5822 dev
->stats
.tx_errors
++;
5824 #ifdef CONFIG_IPW2100_MONITOR
5825 if (priv
->ieee
->iw_mode
== IW_MODE_MONITOR
)
5829 IPW_DEBUG_INFO("%s: TX timed out. Scheduling firmware restart.\n",
5831 schedule_reset(priv
);
5834 static int ipw2100_wpa_enable(struct ipw2100_priv
*priv
, int value
)
5836 /* This is called when wpa_supplicant loads and closes the driver
5838 priv
->ieee
->wpa_enabled
= value
;
5842 static int ipw2100_wpa_set_auth_algs(struct ipw2100_priv
*priv
, int value
)
5845 struct libipw_device
*ieee
= priv
->ieee
;
5846 struct libipw_security sec
= {
5847 .flags
= SEC_AUTH_MODE
,
5851 if (value
& IW_AUTH_ALG_SHARED_KEY
) {
5852 sec
.auth_mode
= WLAN_AUTH_SHARED_KEY
;
5854 } else if (value
& IW_AUTH_ALG_OPEN_SYSTEM
) {
5855 sec
.auth_mode
= WLAN_AUTH_OPEN
;
5857 } else if (value
& IW_AUTH_ALG_LEAP
) {
5858 sec
.auth_mode
= WLAN_AUTH_LEAP
;
5863 if (ieee
->set_security
)
5864 ieee
->set_security(ieee
->dev
, &sec
);
5871 static void ipw2100_wpa_assoc_frame(struct ipw2100_priv
*priv
,
5872 char *wpa_ie
, int wpa_ie_len
)
5875 struct ipw2100_wpa_assoc_frame frame
;
5877 frame
.fixed_ie_mask
= 0;
5880 memcpy(frame
.var_ie
, wpa_ie
, wpa_ie_len
);
5881 frame
.var_ie_len
= wpa_ie_len
;
5883 /* make sure WPA is enabled */
5884 ipw2100_wpa_enable(priv
, 1);
5885 ipw2100_set_wpa_ie(priv
, &frame
, 0);
5888 static void ipw_ethtool_get_drvinfo(struct net_device
*dev
,
5889 struct ethtool_drvinfo
*info
)
5891 struct ipw2100_priv
*priv
= libipw_priv(dev
);
5894 strscpy(info
->driver
, DRV_NAME
, sizeof(info
->driver
));
5895 strscpy(info
->version
, DRV_VERSION
, sizeof(info
->version
));
5897 ipw2100_get_fwversion(priv
, fw_ver
, sizeof(fw_ver
));
5899 strscpy(info
->fw_version
, fw_ver
, sizeof(info
->fw_version
));
5900 strscpy(info
->bus_info
, pci_name(priv
->pci_dev
),
5901 sizeof(info
->bus_info
));
5904 static u32
ipw2100_ethtool_get_link(struct net_device
*dev
)
5906 struct ipw2100_priv
*priv
= libipw_priv(dev
);
5907 return (priv
->status
& STATUS_ASSOCIATED
) ? 1 : 0;
5910 static const struct ethtool_ops ipw2100_ethtool_ops
= {
5911 .get_link
= ipw2100_ethtool_get_link
,
5912 .get_drvinfo
= ipw_ethtool_get_drvinfo
,
5915 static void ipw2100_hang_check(struct work_struct
*work
)
5917 struct ipw2100_priv
*priv
=
5918 container_of(work
, struct ipw2100_priv
, hang_check
.work
);
5919 unsigned long flags
;
5920 u32 rtc
= 0xa5a5a5a5;
5921 u32 len
= sizeof(rtc
);
5924 spin_lock_irqsave(&priv
->low_lock
, flags
);
5926 if (priv
->fatal_error
!= 0) {
5927 /* If fatal_error is set then we need to restart */
5928 IPW_DEBUG_INFO("%s: Hardware fatal error detected.\n",
5929 priv
->net_dev
->name
);
5932 } else if (ipw2100_get_ordinal(priv
, IPW_ORD_RTC_TIME
, &rtc
, &len
) ||
5933 (rtc
== priv
->last_rtc
)) {
5934 /* Check if firmware is hung */
5935 IPW_DEBUG_INFO("%s: Firmware RTC stalled.\n",
5936 priv
->net_dev
->name
);
5943 priv
->stop_hang_check
= 1;
5946 /* Restart the NIC */
5947 schedule_reset(priv
);
5950 priv
->last_rtc
= rtc
;
5952 if (!priv
->stop_hang_check
)
5953 schedule_delayed_work(&priv
->hang_check
, HZ
/ 2);
5955 spin_unlock_irqrestore(&priv
->low_lock
, flags
);
5958 static void ipw2100_rf_kill(struct work_struct
*work
)
5960 struct ipw2100_priv
*priv
=
5961 container_of(work
, struct ipw2100_priv
, rf_kill
.work
);
5962 unsigned long flags
;
5964 spin_lock_irqsave(&priv
->low_lock
, flags
);
5966 if (rf_kill_active(priv
)) {
5967 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
5968 if (!priv
->stop_rf_kill
)
5969 schedule_delayed_work(&priv
->rf_kill
,
5970 round_jiffies_relative(HZ
));
5974 /* RF Kill is now disabled, so bring the device back up */
5976 if (!(priv
->status
& STATUS_RF_KILL_MASK
)) {
5977 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
5979 schedule_reset(priv
);
5981 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
5985 spin_unlock_irqrestore(&priv
->low_lock
, flags
);
5988 static void ipw2100_irq_tasklet(struct tasklet_struct
*t
);
5990 static const struct net_device_ops ipw2100_netdev_ops
= {
5991 .ndo_open
= ipw2100_open
,
5992 .ndo_stop
= ipw2100_close
,
5993 .ndo_start_xmit
= libipw_xmit
,
5994 .ndo_tx_timeout
= ipw2100_tx_timeout
,
5995 .ndo_set_mac_address
= ipw2100_set_address
,
5996 .ndo_validate_addr
= eth_validate_addr
,
5999 /* Look into using netdev destructor to shutdown libipw? */
6001 static struct net_device
*ipw2100_alloc_device(struct pci_dev
*pci_dev
,
6002 void __iomem
* ioaddr
)
6004 struct ipw2100_priv
*priv
;
6005 struct net_device
*dev
;
6007 dev
= alloc_libipw(sizeof(struct ipw2100_priv
), 0);
6010 priv
= libipw_priv(dev
);
6011 priv
->ieee
= netdev_priv(dev
);
6012 priv
->pci_dev
= pci_dev
;
6013 priv
->net_dev
= dev
;
6014 priv
->ioaddr
= ioaddr
;
6016 priv
->ieee
->hard_start_xmit
= ipw2100_tx
;
6017 priv
->ieee
->set_security
= shim__set_security
;
6019 priv
->ieee
->perfect_rssi
= -20;
6020 priv
->ieee
->worst_rssi
= -85;
6022 dev
->netdev_ops
= &ipw2100_netdev_ops
;
6023 dev
->ethtool_ops
= &ipw2100_ethtool_ops
;
6024 dev
->wireless_handlers
= &ipw2100_wx_handler_def
;
6025 dev
->watchdog_timeo
= 3 * HZ
;
6028 dev
->max_mtu
= LIBIPW_DATA_LEN
;
6030 /* NOTE: We don't use the wireless_handlers hook
6031 * in dev as the system will start throwing WX requests
6032 * to us before we're actually initialized and it just
6033 * ends up causing problems. So, we just handle
6034 * the WX extensions through the ipw2100_ioctl interface */
6036 /* memset() puts everything to 0, so we only have explicitly set
6037 * those values that need to be something else */
6039 /* If power management is turned on, default to AUTO mode */
6040 priv
->power_mode
= IPW_POWER_AUTO
;
6042 #ifdef CONFIG_IPW2100_MONITOR
6043 priv
->config
|= CFG_CRC_CHECK
;
6045 priv
->ieee
->wpa_enabled
= 0;
6046 priv
->ieee
->drop_unencrypted
= 0;
6047 priv
->ieee
->privacy_invoked
= 0;
6048 priv
->ieee
->ieee802_1x
= 1;
6050 /* Set module parameters */
6051 switch (network_mode
) {
6053 priv
->ieee
->iw_mode
= IW_MODE_ADHOC
;
6055 #ifdef CONFIG_IPW2100_MONITOR
6057 priv
->ieee
->iw_mode
= IW_MODE_MONITOR
;
6062 priv
->ieee
->iw_mode
= IW_MODE_INFRA
;
6067 priv
->status
|= STATUS_RF_KILL_SW
;
6070 ((channel
>= REG_MIN_CHANNEL
) && (channel
<= REG_MAX_CHANNEL
))) {
6071 priv
->config
|= CFG_STATIC_CHANNEL
;
6072 priv
->channel
= channel
;
6076 priv
->config
|= CFG_ASSOCIATE
;
6078 priv
->beacon_interval
= DEFAULT_BEACON_INTERVAL
;
6079 priv
->short_retry_limit
= DEFAULT_SHORT_RETRY_LIMIT
;
6080 priv
->long_retry_limit
= DEFAULT_LONG_RETRY_LIMIT
;
6081 priv
->rts_threshold
= DEFAULT_RTS_THRESHOLD
| RTS_DISABLED
;
6082 priv
->frag_threshold
= DEFAULT_FTS
| FRAG_DISABLED
;
6083 priv
->tx_power
= IPW_TX_POWER_DEFAULT
;
6084 priv
->tx_rates
= DEFAULT_TX_RATES
;
6086 strcpy(priv
->nick
, "ipw2100");
6088 spin_lock_init(&priv
->low_lock
);
6089 mutex_init(&priv
->action_mutex
);
6090 mutex_init(&priv
->adapter_mutex
);
6092 init_waitqueue_head(&priv
->wait_command_queue
);
6094 netif_carrier_off(dev
);
6096 INIT_LIST_HEAD(&priv
->msg_free_list
);
6097 INIT_LIST_HEAD(&priv
->msg_pend_list
);
6098 INIT_STAT(&priv
->msg_free_stat
);
6099 INIT_STAT(&priv
->msg_pend_stat
);
6101 INIT_LIST_HEAD(&priv
->tx_free_list
);
6102 INIT_LIST_HEAD(&priv
->tx_pend_list
);
6103 INIT_STAT(&priv
->tx_free_stat
);
6104 INIT_STAT(&priv
->tx_pend_stat
);
6106 INIT_LIST_HEAD(&priv
->fw_pend_list
);
6107 INIT_STAT(&priv
->fw_pend_stat
);
6109 INIT_DELAYED_WORK(&priv
->reset_work
, ipw2100_reset_adapter
);
6110 INIT_DELAYED_WORK(&priv
->security_work
, ipw2100_security_work
);
6111 INIT_DELAYED_WORK(&priv
->wx_event_work
, ipw2100_wx_event_work
);
6112 INIT_DELAYED_WORK(&priv
->hang_check
, ipw2100_hang_check
);
6113 INIT_DELAYED_WORK(&priv
->rf_kill
, ipw2100_rf_kill
);
6114 INIT_DELAYED_WORK(&priv
->scan_event
, ipw2100_scan_event
);
6116 tasklet_setup(&priv
->irq_tasklet
, ipw2100_irq_tasklet
);
6118 /* NOTE: We do not start the deferred work for status checks yet */
6119 priv
->stop_rf_kill
= 1;
6120 priv
->stop_hang_check
= 1;
6125 static int ipw2100_pci_init_one(struct pci_dev
*pci_dev
,
6126 const struct pci_device_id
*ent
)
6128 void __iomem
*ioaddr
;
6129 struct net_device
*dev
= NULL
;
6130 struct ipw2100_priv
*priv
= NULL
;
6135 IPW_DEBUG_INFO("enter\n");
6137 if (!(pci_resource_flags(pci_dev
, 0) & IORESOURCE_MEM
)) {
6138 IPW_DEBUG_INFO("weird - resource type is not memory\n");
6143 ioaddr
= pci_iomap(pci_dev
, 0, 0);
6145 printk(KERN_WARNING DRV_NAME
6146 "Error calling ioremap.\n");
6151 /* allocate and initialize our net_device */
6152 dev
= ipw2100_alloc_device(pci_dev
, ioaddr
);
6154 printk(KERN_WARNING DRV_NAME
6155 "Error calling ipw2100_alloc_device.\n");
6160 /* set up PCI mappings for device */
6161 err
= pci_enable_device(pci_dev
);
6163 printk(KERN_WARNING DRV_NAME
6164 "Error calling pci_enable_device.\n");
6168 priv
= libipw_priv(dev
);
6170 pci_set_master(pci_dev
);
6171 pci_set_drvdata(pci_dev
, priv
);
6173 err
= dma_set_mask(&pci_dev
->dev
, DMA_BIT_MASK(32));
6175 printk(KERN_WARNING DRV_NAME
6176 "Error calling pci_set_dma_mask.\n");
6177 pci_disable_device(pci_dev
);
6181 err
= pci_request_regions(pci_dev
, DRV_NAME
);
6183 printk(KERN_WARNING DRV_NAME
6184 "Error calling pci_request_regions.\n");
6185 pci_disable_device(pci_dev
);
6189 /* We disable the RETRY_TIMEOUT register (0x41) to keep
6190 * PCI Tx retries from interfering with C3 CPU state */
6191 pci_read_config_dword(pci_dev
, 0x40, &val
);
6192 if ((val
& 0x0000ff00) != 0)
6193 pci_write_config_dword(pci_dev
, 0x40, val
& 0xffff00ff);
6195 if (!ipw2100_hw_is_adapter_in_system(dev
)) {
6196 printk(KERN_WARNING DRV_NAME
6197 "Device not found via register read.\n");
6202 SET_NETDEV_DEV(dev
, &pci_dev
->dev
);
6204 /* Force interrupts to be shut off on the device */
6205 priv
->status
|= STATUS_INT_ENABLED
;
6206 ipw2100_disable_interrupts(priv
);
6208 /* Allocate and initialize the Tx/Rx queues and lists */
6209 if (ipw2100_queues_allocate(priv
)) {
6210 printk(KERN_WARNING DRV_NAME
6211 "Error calling ipw2100_queues_allocate.\n");
6215 ipw2100_queues_initialize(priv
);
6217 err
= request_irq(pci_dev
->irq
,
6218 ipw2100_interrupt
, IRQF_SHARED
, dev
->name
, priv
);
6220 printk(KERN_WARNING DRV_NAME
6221 "Error calling request_irq: %d.\n", pci_dev
->irq
);
6224 dev
->irq
= pci_dev
->irq
;
6226 IPW_DEBUG_INFO("Attempting to register device...\n");
6228 printk(KERN_INFO DRV_NAME
6229 ": Detected Intel PRO/Wireless 2100 Network Connection\n");
6231 err
= ipw2100_up(priv
, 1);
6235 err
= ipw2100_wdev_init(dev
);
6240 /* Bring up the interface. Pre 0.46, after we registered the
6241 * network device we would call ipw2100_up. This introduced a race
6242 * condition with newer hotplug configurations (network was coming
6243 * up and making calls before the device was initialized).
6245 err
= register_netdev(dev
);
6247 printk(KERN_WARNING DRV_NAME
6248 "Error calling register_netdev.\n");
6253 mutex_lock(&priv
->action_mutex
);
6255 IPW_DEBUG_INFO("%s: Bound to %s\n", dev
->name
, pci_name(pci_dev
));
6257 /* perform this after register_netdev so that dev->name is set */
6258 err
= sysfs_create_group(&pci_dev
->dev
.kobj
, &ipw2100_attribute_group
);
6262 /* If the RF Kill switch is disabled, go ahead and complete the
6263 * startup sequence */
6264 if (!(priv
->status
& STATUS_RF_KILL_MASK
)) {
6265 /* Enable the adapter - sends HOST_COMPLETE */
6266 if (ipw2100_enable_adapter(priv
)) {
6267 printk(KERN_WARNING DRV_NAME
6268 ": %s: failed in call to enable adapter.\n",
6269 priv
->net_dev
->name
);
6270 ipw2100_hw_stop_adapter(priv
);
6275 /* Start a scan . . . */
6276 ipw2100_set_scan_options(priv
);
6277 ipw2100_start_scan(priv
);
6280 IPW_DEBUG_INFO("exit\n");
6282 priv
->status
|= STATUS_INITIALIZED
;
6284 mutex_unlock(&priv
->action_mutex
);
6289 mutex_unlock(&priv
->action_mutex
);
6292 if (registered
>= 2)
6293 unregister_netdev(dev
);
6296 wiphy_unregister(priv
->ieee
->wdev
.wiphy
);
6297 kfree(priv
->ieee
->bg_band
.channels
);
6300 ipw2100_hw_stop_adapter(priv
);
6302 ipw2100_disable_interrupts(priv
);
6305 free_irq(dev
->irq
, priv
);
6307 ipw2100_kill_works(priv
);
6309 /* These are safe to call even if they weren't allocated */
6310 ipw2100_queues_free(priv
);
6311 sysfs_remove_group(&pci_dev
->dev
.kobj
,
6312 &ipw2100_attribute_group
);
6314 free_libipw(dev
, 0);
6317 pci_iounmap(pci_dev
, ioaddr
);
6319 pci_release_regions(pci_dev
);
6320 pci_disable_device(pci_dev
);
6324 static void ipw2100_pci_remove_one(struct pci_dev
*pci_dev
)
6326 struct ipw2100_priv
*priv
= pci_get_drvdata(pci_dev
);
6327 struct net_device
*dev
= priv
->net_dev
;
6329 mutex_lock(&priv
->action_mutex
);
6331 priv
->status
&= ~STATUS_INITIALIZED
;
6333 sysfs_remove_group(&pci_dev
->dev
.kobj
, &ipw2100_attribute_group
);
6336 if (ipw2100_firmware
.version
)
6337 ipw2100_release_firmware(priv
, &ipw2100_firmware
);
6339 /* Take down the hardware */
6342 /* Release the mutex so that the network subsystem can
6343 * complete any needed calls into the driver... */
6344 mutex_unlock(&priv
->action_mutex
);
6346 /* Unregister the device first - this results in close()
6347 * being called if the device is open. If we free storage
6348 * first, then close() will crash.
6349 * FIXME: remove the comment above. */
6350 unregister_netdev(dev
);
6352 ipw2100_kill_works(priv
);
6354 ipw2100_queues_free(priv
);
6356 /* Free potential debugging firmware snapshot */
6357 ipw2100_snapshot_free(priv
);
6359 free_irq(dev
->irq
, priv
);
6361 pci_iounmap(pci_dev
, priv
->ioaddr
);
6363 /* wiphy_unregister needs to be here, before free_libipw */
6364 wiphy_unregister(priv
->ieee
->wdev
.wiphy
);
6365 kfree(priv
->ieee
->bg_band
.channels
);
6366 free_libipw(dev
, 0);
6368 pci_release_regions(pci_dev
);
6369 pci_disable_device(pci_dev
);
6371 IPW_DEBUG_INFO("exit\n");
6374 static int __maybe_unused
ipw2100_suspend(struct device
*dev_d
)
6376 struct ipw2100_priv
*priv
= dev_get_drvdata(dev_d
);
6377 struct net_device
*dev
= priv
->net_dev
;
6379 IPW_DEBUG_INFO("%s: Going into suspend...\n", dev
->name
);
6381 mutex_lock(&priv
->action_mutex
);
6382 if (priv
->status
& STATUS_INITIALIZED
) {
6383 /* Take down the device; powers it off, etc. */
6387 /* Remove the PRESENT state of the device */
6388 netif_device_detach(dev
);
6390 priv
->suspend_at
= ktime_get_boottime_seconds();
6392 mutex_unlock(&priv
->action_mutex
);
6397 static int __maybe_unused
ipw2100_resume(struct device
*dev_d
)
6399 struct pci_dev
*pci_dev
= to_pci_dev(dev_d
);
6400 struct ipw2100_priv
*priv
= pci_get_drvdata(pci_dev
);
6401 struct net_device
*dev
= priv
->net_dev
;
6404 if (IPW2100_PM_DISABLED
)
6407 mutex_lock(&priv
->action_mutex
);
6409 IPW_DEBUG_INFO("%s: Coming out of suspend...\n", dev
->name
);
6412 * Suspend/Resume resets the PCI configuration space, so we have to
6413 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
6414 * from interfering with C3 CPU state. pci_restore_state won't help
6415 * here since it only restores the first 64 bytes pci config header.
6417 pci_read_config_dword(pci_dev
, 0x40, &val
);
6418 if ((val
& 0x0000ff00) != 0)
6419 pci_write_config_dword(pci_dev
, 0x40, val
& 0xffff00ff);
6421 /* Set the device back into the PRESENT state; this will also wake
6422 * the queue of needed */
6423 netif_device_attach(dev
);
6425 priv
->suspend_time
= ktime_get_boottime_seconds() - priv
->suspend_at
;
6427 /* Bring the device back up */
6428 if (!(priv
->status
& STATUS_RF_KILL_SW
))
6429 ipw2100_up(priv
, 0);
6431 mutex_unlock(&priv
->action_mutex
);
6436 static void ipw2100_shutdown(struct pci_dev
*pci_dev
)
6438 struct ipw2100_priv
*priv
= pci_get_drvdata(pci_dev
);
6440 /* Take down the device; powers it off, etc. */
6443 pci_disable_device(pci_dev
);
6446 #define IPW2100_DEV_ID(x) { PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, x }
6448 static const struct pci_device_id ipw2100_pci_id_table
[] = {
6449 IPW2100_DEV_ID(0x2520), /* IN 2100A mPCI 3A */
6450 IPW2100_DEV_ID(0x2521), /* IN 2100A mPCI 3B */
6451 IPW2100_DEV_ID(0x2524), /* IN 2100A mPCI 3B */
6452 IPW2100_DEV_ID(0x2525), /* IN 2100A mPCI 3B */
6453 IPW2100_DEV_ID(0x2526), /* IN 2100A mPCI Gen A3 */
6454 IPW2100_DEV_ID(0x2522), /* IN 2100 mPCI 3B */
6455 IPW2100_DEV_ID(0x2523), /* IN 2100 mPCI 3A */
6456 IPW2100_DEV_ID(0x2527), /* IN 2100 mPCI 3B */
6457 IPW2100_DEV_ID(0x2528), /* IN 2100 mPCI 3B */
6458 IPW2100_DEV_ID(0x2529), /* IN 2100 mPCI 3B */
6459 IPW2100_DEV_ID(0x252B), /* IN 2100 mPCI 3A */
6460 IPW2100_DEV_ID(0x252C), /* IN 2100 mPCI 3A */
6461 IPW2100_DEV_ID(0x252D), /* IN 2100 mPCI 3A */
6463 IPW2100_DEV_ID(0x2550), /* IB 2100A mPCI 3B */
6464 IPW2100_DEV_ID(0x2551), /* IB 2100 mPCI 3B */
6465 IPW2100_DEV_ID(0x2553), /* IB 2100 mPCI 3B */
6466 IPW2100_DEV_ID(0x2554), /* IB 2100 mPCI 3B */
6467 IPW2100_DEV_ID(0x2555), /* IB 2100 mPCI 3B */
6469 IPW2100_DEV_ID(0x2560), /* DE 2100A mPCI 3A */
6470 IPW2100_DEV_ID(0x2562), /* DE 2100A mPCI 3A */
6471 IPW2100_DEV_ID(0x2563), /* DE 2100A mPCI 3A */
6472 IPW2100_DEV_ID(0x2561), /* DE 2100 mPCI 3A */
6473 IPW2100_DEV_ID(0x2565), /* DE 2100 mPCI 3A */
6474 IPW2100_DEV_ID(0x2566), /* DE 2100 mPCI 3A */
6475 IPW2100_DEV_ID(0x2567), /* DE 2100 mPCI 3A */
6477 IPW2100_DEV_ID(0x2570), /* GA 2100 mPCI 3B */
6479 IPW2100_DEV_ID(0x2580), /* TO 2100A mPCI 3B */
6480 IPW2100_DEV_ID(0x2582), /* TO 2100A mPCI 3B */
6481 IPW2100_DEV_ID(0x2583), /* TO 2100A mPCI 3B */
6482 IPW2100_DEV_ID(0x2581), /* TO 2100 mPCI 3B */
6483 IPW2100_DEV_ID(0x2585), /* TO 2100 mPCI 3B */
6484 IPW2100_DEV_ID(0x2586), /* TO 2100 mPCI 3B */
6485 IPW2100_DEV_ID(0x2587), /* TO 2100 mPCI 3B */
6487 IPW2100_DEV_ID(0x2590), /* SO 2100A mPCI 3B */
6488 IPW2100_DEV_ID(0x2592), /* SO 2100A mPCI 3B */
6489 IPW2100_DEV_ID(0x2591), /* SO 2100 mPCI 3B */
6490 IPW2100_DEV_ID(0x2593), /* SO 2100 mPCI 3B */
6491 IPW2100_DEV_ID(0x2596), /* SO 2100 mPCI 3B */
6492 IPW2100_DEV_ID(0x2598), /* SO 2100 mPCI 3B */
6494 IPW2100_DEV_ID(0x25A0), /* HP 2100 mPCI 3B */
6498 MODULE_DEVICE_TABLE(pci
, ipw2100_pci_id_table
);
6500 static SIMPLE_DEV_PM_OPS(ipw2100_pm_ops
, ipw2100_suspend
, ipw2100_resume
);
6502 static struct pci_driver ipw2100_pci_driver
= {
6504 .id_table
= ipw2100_pci_id_table
,
6505 .probe
= ipw2100_pci_init_one
,
6506 .remove
= ipw2100_pci_remove_one
,
6507 .driver
.pm
= &ipw2100_pm_ops
,
6508 .shutdown
= ipw2100_shutdown
,
6512 * Initialize the ipw2100 driver/module
6514 * @returns 0 if ok, < 0 errno node con error.
6516 * Note: we cannot init the /proc stuff until the PCI driver is there,
6517 * or we risk an unlikely race condition on someone accessing
6518 * uninitialized data in the PCI dev struct through /proc.
6520 static int __init
ipw2100_init(void)
6524 printk(KERN_INFO DRV_NAME
": %s, %s\n", DRV_DESCRIPTION
, DRV_VERSION
);
6525 printk(KERN_INFO DRV_NAME
": %s\n", DRV_COPYRIGHT
);
6527 cpu_latency_qos_add_request(&ipw2100_pm_qos_req
, PM_QOS_DEFAULT_VALUE
);
6529 ret
= pci_register_driver(&ipw2100_pci_driver
);
6533 #ifdef CONFIG_IPW2100_DEBUG
6534 ipw2100_debug_level
= debug
;
6535 ret
= driver_create_file(&ipw2100_pci_driver
.driver
,
6536 &driver_attr_debug_level
);
6544 * Cleanup ipw2100 driver registration
6546 static void __exit
ipw2100_exit(void)
6548 /* FIXME: IPG: check that we have no instances of the devices open */
6549 #ifdef CONFIG_IPW2100_DEBUG
6550 driver_remove_file(&ipw2100_pci_driver
.driver
,
6551 &driver_attr_debug_level
);
6553 pci_unregister_driver(&ipw2100_pci_driver
);
6554 cpu_latency_qos_remove_request(&ipw2100_pm_qos_req
);
6557 module_init(ipw2100_init
);
6558 module_exit(ipw2100_exit
);
6560 static int ipw2100_wx_get_name(struct net_device
*dev
,
6561 struct iw_request_info
*info
,
6562 union iwreq_data
*wrqu
, char *extra
)
6565 * This can be called at any time. No action lock required
6568 struct ipw2100_priv
*priv
= libipw_priv(dev
);
6569 if (!(priv
->status
& STATUS_ASSOCIATED
))
6570 strcpy(wrqu
->name
, "unassociated");
6572 snprintf(wrqu
->name
, IFNAMSIZ
, "IEEE 802.11b");
6574 IPW_DEBUG_WX("Name: %s\n", wrqu
->name
);
6578 static int ipw2100_wx_set_freq(struct net_device
*dev
,
6579 struct iw_request_info
*info
,
6580 union iwreq_data
*wrqu
, char *extra
)
6582 struct ipw2100_priv
*priv
= libipw_priv(dev
);
6583 struct iw_freq
*fwrq
= &wrqu
->freq
;
6586 if (priv
->ieee
->iw_mode
== IW_MODE_INFRA
)
6589 mutex_lock(&priv
->action_mutex
);
6590 if (!(priv
->status
& STATUS_INITIALIZED
)) {
6595 /* if setting by freq convert to channel */
6597 if ((fwrq
->m
>= (int)2.412e8
&& fwrq
->m
<= (int)2.487e8
)) {
6598 int f
= fwrq
->m
/ 100000;
6601 while ((c
< REG_MAX_CHANNEL
) &&
6602 (f
!= ipw2100_frequencies
[c
]))
6605 /* hack to fall through */
6611 if (fwrq
->e
> 0 || fwrq
->m
> 1000) {
6614 } else { /* Set the channel */
6615 IPW_DEBUG_WX("SET Freq/Channel -> %d\n", fwrq
->m
);
6616 err
= ipw2100_set_channel(priv
, fwrq
->m
, 0);
6620 mutex_unlock(&priv
->action_mutex
);
6624 static int ipw2100_wx_get_freq(struct net_device
*dev
,
6625 struct iw_request_info
*info
,
6626 union iwreq_data
*wrqu
, char *extra
)
6629 * This can be called at any time. No action lock required
6632 struct ipw2100_priv
*priv
= libipw_priv(dev
);
6636 /* If we are associated, trying to associate, or have a statically
6637 * configured CHANNEL then return that; otherwise return ANY */
6638 if (priv
->config
& CFG_STATIC_CHANNEL
||
6639 priv
->status
& STATUS_ASSOCIATED
)
6640 wrqu
->freq
.m
= priv
->channel
;
6644 IPW_DEBUG_WX("GET Freq/Channel -> %d\n", priv
->channel
);
6649 static int ipw2100_wx_set_mode(struct net_device
*dev
,
6650 struct iw_request_info
*info
,
6651 union iwreq_data
*wrqu
, char *extra
)
6653 struct ipw2100_priv
*priv
= libipw_priv(dev
);
6656 IPW_DEBUG_WX("SET Mode -> %d\n", wrqu
->mode
);
6658 if (wrqu
->mode
== priv
->ieee
->iw_mode
)
6661 mutex_lock(&priv
->action_mutex
);
6662 if (!(priv
->status
& STATUS_INITIALIZED
)) {
6667 switch (wrqu
->mode
) {
6668 #ifdef CONFIG_IPW2100_MONITOR
6669 case IW_MODE_MONITOR
:
6670 err
= ipw2100_switch_mode(priv
, IW_MODE_MONITOR
);
6672 #endif /* CONFIG_IPW2100_MONITOR */
6674 err
= ipw2100_switch_mode(priv
, IW_MODE_ADHOC
);
6679 err
= ipw2100_switch_mode(priv
, IW_MODE_INFRA
);
6684 mutex_unlock(&priv
->action_mutex
);
6688 static int ipw2100_wx_get_mode(struct net_device
*dev
,
6689 struct iw_request_info
*info
,
6690 union iwreq_data
*wrqu
, char *extra
)
6693 * This can be called at any time. No action lock required
6696 struct ipw2100_priv
*priv
= libipw_priv(dev
);
6698 wrqu
->mode
= priv
->ieee
->iw_mode
;
6699 IPW_DEBUG_WX("GET Mode -> %d\n", wrqu
->mode
);
6704 #define POWER_MODES 5
6706 /* Values are in microsecond */
6707 static const s32 timeout_duration
[POWER_MODES
] = {
6715 static const s32 period_duration
[POWER_MODES
] = {
6723 static int ipw2100_wx_get_range(struct net_device
*dev
,
6724 struct iw_request_info
*info
,
6725 union iwreq_data
*wrqu
, char *extra
)
6728 * This can be called at any time. No action lock required
6731 struct ipw2100_priv
*priv
= libipw_priv(dev
);
6732 struct iw_range
*range
= (struct iw_range
*)extra
;
6736 wrqu
->data
.length
= sizeof(*range
);
6737 memset(range
, 0, sizeof(*range
));
6739 /* Let's try to keep this struct in the same order as in
6740 * linux/include/wireless.h
6743 /* TODO: See what values we can set, and remove the ones we can't
6744 * set, or fill them with some default data.
6747 /* ~5 Mb/s real (802.11b) */
6748 range
->throughput
= 5 * 1000 * 1000;
6750 // range->sensitivity; /* signal level threshold range */
6752 range
->max_qual
.qual
= 100;
6753 /* TODO: Find real max RSSI and stick here */
6754 range
->max_qual
.level
= 0;
6755 range
->max_qual
.noise
= 0;
6756 range
->max_qual
.updated
= 7; /* Updated all three */
6758 range
->avg_qual
.qual
= 70; /* > 8% missed beacons is 'bad' */
6759 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
6760 range
->avg_qual
.level
= 20 + IPW2100_RSSI_TO_DBM
;
6761 range
->avg_qual
.noise
= 0;
6762 range
->avg_qual
.updated
= 7; /* Updated all three */
6764 range
->num_bitrates
= RATE_COUNT
;
6766 for (i
= 0; i
< RATE_COUNT
&& i
< IW_MAX_BITRATES
; i
++) {
6767 range
->bitrate
[i
] = ipw2100_bg_rates
[i
].bitrate
* 100 * 1000;
6770 range
->min_rts
= MIN_RTS_THRESHOLD
;
6771 range
->max_rts
= MAX_RTS_THRESHOLD
;
6772 range
->min_frag
= MIN_FRAG_THRESHOLD
;
6773 range
->max_frag
= MAX_FRAG_THRESHOLD
;
6775 range
->min_pmp
= period_duration
[0]; /* Minimal PM period */
6776 range
->max_pmp
= period_duration
[POWER_MODES
- 1]; /* Maximal PM period */
6777 range
->min_pmt
= timeout_duration
[POWER_MODES
- 1]; /* Minimal PM timeout */
6778 range
->max_pmt
= timeout_duration
[0]; /* Maximal PM timeout */
6780 /* How to decode max/min PM period */
6781 range
->pmp_flags
= IW_POWER_PERIOD
;
6782 /* How to decode max/min PM period */
6783 range
->pmt_flags
= IW_POWER_TIMEOUT
;
6784 /* What PM options are supported */
6785 range
->pm_capa
= IW_POWER_TIMEOUT
| IW_POWER_PERIOD
;
6787 range
->encoding_size
[0] = 5;
6788 range
->encoding_size
[1] = 13; /* Different token sizes */
6789 range
->num_encoding_sizes
= 2; /* Number of entry in the list */
6790 range
->max_encoding_tokens
= WEP_KEYS
; /* Max number of tokens */
6791 // range->encoding_login_index; /* token index for login token */
6793 if (priv
->ieee
->iw_mode
== IW_MODE_ADHOC
) {
6794 range
->txpower_capa
= IW_TXPOW_DBM
;
6795 range
->num_txpower
= IW_MAX_TXPOWER
;
6796 for (i
= 0, level
= (IPW_TX_POWER_MAX_DBM
* 16);
6799 ((IPW_TX_POWER_MAX_DBM
-
6800 IPW_TX_POWER_MIN_DBM
) * 16) / (IW_MAX_TXPOWER
- 1))
6801 range
->txpower
[i
] = level
/ 16;
6803 range
->txpower_capa
= 0;
6804 range
->num_txpower
= 0;
6807 /* Set the Wireless Extension versions */
6808 range
->we_version_compiled
= WIRELESS_EXT
;
6809 range
->we_version_source
= 18;
6811 // range->retry_capa; /* What retry options are supported */
6812 // range->retry_flags; /* How to decode max/min retry limit */
6813 // range->r_time_flags; /* How to decode max/min retry life */
6814 // range->min_retry; /* Minimal number of retries */
6815 // range->max_retry; /* Maximal number of retries */
6816 // range->min_r_time; /* Minimal retry lifetime */
6817 // range->max_r_time; /* Maximal retry lifetime */
6819 range
->num_channels
= FREQ_COUNT
;
6822 for (i
= 0; i
< FREQ_COUNT
; i
++) {
6823 // TODO: Include only legal frequencies for some countries
6824 // if (local->channel_mask & (1 << i)) {
6825 range
->freq
[val
].i
= i
+ 1;
6826 range
->freq
[val
].m
= ipw2100_frequencies
[i
] * 100000;
6827 range
->freq
[val
].e
= 1;
6830 if (val
== IW_MAX_FREQUENCIES
)
6833 range
->num_frequency
= val
;
6835 /* Event capability (kernel + driver) */
6836 range
->event_capa
[0] = (IW_EVENT_CAPA_K_0
|
6837 IW_EVENT_CAPA_MASK(SIOCGIWAP
));
6838 range
->event_capa
[1] = IW_EVENT_CAPA_K_1
;
6840 range
->enc_capa
= IW_ENC_CAPA_WPA
| IW_ENC_CAPA_WPA2
|
6841 IW_ENC_CAPA_CIPHER_TKIP
| IW_ENC_CAPA_CIPHER_CCMP
;
6843 IPW_DEBUG_WX("GET Range\n");
6848 static int ipw2100_wx_set_wap(struct net_device
*dev
,
6849 struct iw_request_info
*info
,
6850 union iwreq_data
*wrqu
, char *extra
)
6852 struct ipw2100_priv
*priv
= libipw_priv(dev
);
6856 if (wrqu
->ap_addr
.sa_family
!= ARPHRD_ETHER
)
6859 mutex_lock(&priv
->action_mutex
);
6860 if (!(priv
->status
& STATUS_INITIALIZED
)) {
6865 if (is_broadcast_ether_addr(wrqu
->ap_addr
.sa_data
) ||
6866 is_zero_ether_addr(wrqu
->ap_addr
.sa_data
)) {
6867 /* we disable mandatory BSSID association */
6868 IPW_DEBUG_WX("exit - disable mandatory BSSID\n");
6869 priv
->config
&= ~CFG_STATIC_BSSID
;
6870 err
= ipw2100_set_mandatory_bssid(priv
, NULL
, 0);
6874 priv
->config
|= CFG_STATIC_BSSID
;
6875 memcpy(priv
->mandatory_bssid_mac
, wrqu
->ap_addr
.sa_data
, ETH_ALEN
);
6877 err
= ipw2100_set_mandatory_bssid(priv
, wrqu
->ap_addr
.sa_data
, 0);
6879 IPW_DEBUG_WX("SET BSSID -> %pM\n", wrqu
->ap_addr
.sa_data
);
6882 mutex_unlock(&priv
->action_mutex
);
6886 static int ipw2100_wx_get_wap(struct net_device
*dev
,
6887 struct iw_request_info
*info
,
6888 union iwreq_data
*wrqu
, char *extra
)
6891 * This can be called at any time. No action lock required
6894 struct ipw2100_priv
*priv
= libipw_priv(dev
);
6896 /* If we are associated, trying to associate, or have a statically
6897 * configured BSSID then return that; otherwise return ANY */
6898 if (priv
->config
& CFG_STATIC_BSSID
|| priv
->status
& STATUS_ASSOCIATED
) {
6899 wrqu
->ap_addr
.sa_family
= ARPHRD_ETHER
;
6900 memcpy(wrqu
->ap_addr
.sa_data
, priv
->bssid
, ETH_ALEN
);
6902 eth_zero_addr(wrqu
->ap_addr
.sa_data
);
6904 IPW_DEBUG_WX("Getting WAP BSSID: %pM\n", wrqu
->ap_addr
.sa_data
);
6908 static int ipw2100_wx_set_essid(struct net_device
*dev
,
6909 struct iw_request_info
*info
,
6910 union iwreq_data
*wrqu
, char *extra
)
6912 struct ipw2100_priv
*priv
= libipw_priv(dev
);
6913 char *essid
= ""; /* ANY */
6917 mutex_lock(&priv
->action_mutex
);
6918 if (!(priv
->status
& STATUS_INITIALIZED
)) {
6923 if (wrqu
->essid
.flags
&& wrqu
->essid
.length
) {
6924 length
= wrqu
->essid
.length
;
6929 IPW_DEBUG_WX("Setting ESSID to ANY\n");
6930 priv
->config
&= ~CFG_STATIC_ESSID
;
6931 err
= ipw2100_set_essid(priv
, NULL
, 0, 0);
6935 length
= min(length
, IW_ESSID_MAX_SIZE
);
6937 priv
->config
|= CFG_STATIC_ESSID
;
6939 if (priv
->essid_len
== length
&& !memcmp(priv
->essid
, extra
, length
)) {
6940 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
6945 IPW_DEBUG_WX("Setting ESSID: '%*pE' (%d)\n", length
, essid
, length
);
6947 priv
->essid_len
= length
;
6948 memcpy(priv
->essid
, essid
, priv
->essid_len
);
6950 err
= ipw2100_set_essid(priv
, essid
, length
, 0);
6953 mutex_unlock(&priv
->action_mutex
);
6957 static int ipw2100_wx_get_essid(struct net_device
*dev
,
6958 struct iw_request_info
*info
,
6959 union iwreq_data
*wrqu
, char *extra
)
6962 * This can be called at any time. No action lock required
6965 struct ipw2100_priv
*priv
= libipw_priv(dev
);
6967 /* If we are associated, trying to associate, or have a statically
6968 * configured ESSID then return that; otherwise return ANY */
6969 if (priv
->config
& CFG_STATIC_ESSID
|| priv
->status
& STATUS_ASSOCIATED
) {
6970 IPW_DEBUG_WX("Getting essid: '%*pE'\n",
6971 priv
->essid_len
, priv
->essid
);
6972 memcpy(extra
, priv
->essid
, priv
->essid_len
);
6973 wrqu
->essid
.length
= priv
->essid_len
;
6974 wrqu
->essid
.flags
= 1; /* active */
6976 IPW_DEBUG_WX("Getting essid: ANY\n");
6977 wrqu
->essid
.length
= 0;
6978 wrqu
->essid
.flags
= 0; /* active */
6984 static int ipw2100_wx_set_nick(struct net_device
*dev
,
6985 struct iw_request_info
*info
,
6986 union iwreq_data
*wrqu
, char *extra
)
6989 * This can be called at any time. No action lock required
6992 struct ipw2100_priv
*priv
= libipw_priv(dev
);
6994 if (wrqu
->data
.length
> IW_ESSID_MAX_SIZE
)
6997 wrqu
->data
.length
= min_t(size_t, wrqu
->data
.length
, sizeof(priv
->nick
));
6998 memset(priv
->nick
, 0, sizeof(priv
->nick
));
6999 memcpy(priv
->nick
, extra
, wrqu
->data
.length
);
7001 IPW_DEBUG_WX("SET Nickname -> %s\n", priv
->nick
);
7006 static int ipw2100_wx_get_nick(struct net_device
*dev
,
7007 struct iw_request_info
*info
,
7008 union iwreq_data
*wrqu
, char *extra
)
7011 * This can be called at any time. No action lock required
7014 struct ipw2100_priv
*priv
= libipw_priv(dev
);
7016 wrqu
->data
.length
= strlen(priv
->nick
);
7017 memcpy(extra
, priv
->nick
, wrqu
->data
.length
);
7018 wrqu
->data
.flags
= 1; /* active */
7020 IPW_DEBUG_WX("GET Nickname -> %s\n", extra
);
7025 static int ipw2100_wx_set_rate(struct net_device
*dev
,
7026 struct iw_request_info
*info
,
7027 union iwreq_data
*wrqu
, char *extra
)
7029 struct ipw2100_priv
*priv
= libipw_priv(dev
);
7030 u32 target_rate
= wrqu
->bitrate
.value
;
7034 mutex_lock(&priv
->action_mutex
);
7035 if (!(priv
->status
& STATUS_INITIALIZED
)) {
7042 if (target_rate
== 1000000 ||
7043 (!wrqu
->bitrate
.fixed
&& target_rate
> 1000000))
7044 rate
|= TX_RATE_1_MBIT
;
7045 if (target_rate
== 2000000 ||
7046 (!wrqu
->bitrate
.fixed
&& target_rate
> 2000000))
7047 rate
|= TX_RATE_2_MBIT
;
7048 if (target_rate
== 5500000 ||
7049 (!wrqu
->bitrate
.fixed
&& target_rate
> 5500000))
7050 rate
|= TX_RATE_5_5_MBIT
;
7051 if (target_rate
== 11000000 ||
7052 (!wrqu
->bitrate
.fixed
&& target_rate
> 11000000))
7053 rate
|= TX_RATE_11_MBIT
;
7055 rate
= DEFAULT_TX_RATES
;
7057 err
= ipw2100_set_tx_rates(priv
, rate
, 0);
7059 IPW_DEBUG_WX("SET Rate -> %04X\n", rate
);
7061 mutex_unlock(&priv
->action_mutex
);
7065 static int ipw2100_wx_get_rate(struct net_device
*dev
,
7066 struct iw_request_info
*info
,
7067 union iwreq_data
*wrqu
, char *extra
)
7069 struct ipw2100_priv
*priv
= libipw_priv(dev
);
7071 unsigned int len
= sizeof(val
);
7074 if (!(priv
->status
& STATUS_ENABLED
) ||
7075 priv
->status
& STATUS_RF_KILL_MASK
||
7076 !(priv
->status
& STATUS_ASSOCIATED
)) {
7077 wrqu
->bitrate
.value
= 0;
7081 mutex_lock(&priv
->action_mutex
);
7082 if (!(priv
->status
& STATUS_INITIALIZED
)) {
7087 err
= ipw2100_get_ordinal(priv
, IPW_ORD_CURRENT_TX_RATE
, &val
, &len
);
7089 IPW_DEBUG_WX("failed querying ordinals.\n");
7093 switch (val
& TX_RATE_MASK
) {
7094 case TX_RATE_1_MBIT
:
7095 wrqu
->bitrate
.value
= 1000000;
7097 case TX_RATE_2_MBIT
:
7098 wrqu
->bitrate
.value
= 2000000;
7100 case TX_RATE_5_5_MBIT
:
7101 wrqu
->bitrate
.value
= 5500000;
7103 case TX_RATE_11_MBIT
:
7104 wrqu
->bitrate
.value
= 11000000;
7107 wrqu
->bitrate
.value
= 0;
7110 IPW_DEBUG_WX("GET Rate -> %d\n", wrqu
->bitrate
.value
);
7113 mutex_unlock(&priv
->action_mutex
);
7117 static int ipw2100_wx_set_rts(struct net_device
*dev
,
7118 struct iw_request_info
*info
,
7119 union iwreq_data
*wrqu
, char *extra
)
7121 struct ipw2100_priv
*priv
= libipw_priv(dev
);
7124 /* Auto RTS not yet supported */
7125 if (wrqu
->rts
.fixed
== 0)
7128 mutex_lock(&priv
->action_mutex
);
7129 if (!(priv
->status
& STATUS_INITIALIZED
)) {
7134 if (wrqu
->rts
.disabled
)
7135 value
= priv
->rts_threshold
| RTS_DISABLED
;
7137 if (wrqu
->rts
.value
< 1 || wrqu
->rts
.value
> 2304) {
7141 value
= wrqu
->rts
.value
;
7144 err
= ipw2100_set_rts_threshold(priv
, value
);
7146 IPW_DEBUG_WX("SET RTS Threshold -> 0x%08X\n", value
);
7148 mutex_unlock(&priv
->action_mutex
);
7152 static int ipw2100_wx_get_rts(struct net_device
*dev
,
7153 struct iw_request_info
*info
,
7154 union iwreq_data
*wrqu
, char *extra
)
7157 * This can be called at any time. No action lock required
7160 struct ipw2100_priv
*priv
= libipw_priv(dev
);
7162 wrqu
->rts
.value
= priv
->rts_threshold
& ~RTS_DISABLED
;
7163 wrqu
->rts
.fixed
= 1; /* no auto select */
7165 /* If RTS is set to the default value, then it is disabled */
7166 wrqu
->rts
.disabled
= (priv
->rts_threshold
& RTS_DISABLED
) ? 1 : 0;
7168 IPW_DEBUG_WX("GET RTS Threshold -> 0x%08X\n", wrqu
->rts
.value
);
7173 static int ipw2100_wx_set_txpow(struct net_device
*dev
,
7174 struct iw_request_info
*info
,
7175 union iwreq_data
*wrqu
, char *extra
)
7177 struct ipw2100_priv
*priv
= libipw_priv(dev
);
7180 if (ipw_radio_kill_sw(priv
, wrqu
->txpower
.disabled
))
7181 return -EINPROGRESS
;
7183 if (priv
->ieee
->iw_mode
!= IW_MODE_ADHOC
)
7186 if ((wrqu
->txpower
.flags
& IW_TXPOW_TYPE
) != IW_TXPOW_DBM
)
7189 if (wrqu
->txpower
.fixed
== 0)
7190 value
= IPW_TX_POWER_DEFAULT
;
7192 if (wrqu
->txpower
.value
< IPW_TX_POWER_MIN_DBM
||
7193 wrqu
->txpower
.value
> IPW_TX_POWER_MAX_DBM
)
7196 value
= wrqu
->txpower
.value
;
7199 mutex_lock(&priv
->action_mutex
);
7200 if (!(priv
->status
& STATUS_INITIALIZED
)) {
7205 err
= ipw2100_set_tx_power(priv
, value
);
7207 IPW_DEBUG_WX("SET TX Power -> %d\n", value
);
7210 mutex_unlock(&priv
->action_mutex
);
7214 static int ipw2100_wx_get_txpow(struct net_device
*dev
,
7215 struct iw_request_info
*info
,
7216 union iwreq_data
*wrqu
, char *extra
)
7219 * This can be called at any time. No action lock required
7222 struct ipw2100_priv
*priv
= libipw_priv(dev
);
7224 wrqu
->txpower
.disabled
= (priv
->status
& STATUS_RF_KILL_MASK
) ? 1 : 0;
7226 if (priv
->tx_power
== IPW_TX_POWER_DEFAULT
) {
7227 wrqu
->txpower
.fixed
= 0;
7228 wrqu
->txpower
.value
= IPW_TX_POWER_MAX_DBM
;
7230 wrqu
->txpower
.fixed
= 1;
7231 wrqu
->txpower
.value
= priv
->tx_power
;
7234 wrqu
->txpower
.flags
= IW_TXPOW_DBM
;
7236 IPW_DEBUG_WX("GET TX Power -> %d\n", wrqu
->txpower
.value
);
7241 static int ipw2100_wx_set_frag(struct net_device
*dev
,
7242 struct iw_request_info
*info
,
7243 union iwreq_data
*wrqu
, char *extra
)
7246 * This can be called at any time. No action lock required
7249 struct ipw2100_priv
*priv
= libipw_priv(dev
);
7251 if (!wrqu
->frag
.fixed
)
7254 if (wrqu
->frag
.disabled
) {
7255 priv
->frag_threshold
|= FRAG_DISABLED
;
7256 priv
->ieee
->fts
= DEFAULT_FTS
;
7258 if (wrqu
->frag
.value
< MIN_FRAG_THRESHOLD
||
7259 wrqu
->frag
.value
> MAX_FRAG_THRESHOLD
)
7262 priv
->ieee
->fts
= wrqu
->frag
.value
& ~0x1;
7263 priv
->frag_threshold
= priv
->ieee
->fts
;
7266 IPW_DEBUG_WX("SET Frag Threshold -> %d\n", priv
->ieee
->fts
);
7271 static int ipw2100_wx_get_frag(struct net_device
*dev
,
7272 struct iw_request_info
*info
,
7273 union iwreq_data
*wrqu
, char *extra
)
7276 * This can be called at any time. No action lock required
7279 struct ipw2100_priv
*priv
= libipw_priv(dev
);
7280 wrqu
->frag
.value
= priv
->frag_threshold
& ~FRAG_DISABLED
;
7281 wrqu
->frag
.fixed
= 0; /* no auto select */
7282 wrqu
->frag
.disabled
= (priv
->frag_threshold
& FRAG_DISABLED
) ? 1 : 0;
7284 IPW_DEBUG_WX("GET Frag Threshold -> %d\n", wrqu
->frag
.value
);
7289 static int ipw2100_wx_set_retry(struct net_device
*dev
,
7290 struct iw_request_info
*info
,
7291 union iwreq_data
*wrqu
, char *extra
)
7293 struct ipw2100_priv
*priv
= libipw_priv(dev
);
7296 if (wrqu
->retry
.flags
& IW_RETRY_LIFETIME
|| wrqu
->retry
.disabled
)
7299 if (!(wrqu
->retry
.flags
& IW_RETRY_LIMIT
))
7302 mutex_lock(&priv
->action_mutex
);
7303 if (!(priv
->status
& STATUS_INITIALIZED
)) {
7308 if (wrqu
->retry
.flags
& IW_RETRY_SHORT
) {
7309 err
= ipw2100_set_short_retry(priv
, wrqu
->retry
.value
);
7310 IPW_DEBUG_WX("SET Short Retry Limit -> %d\n",
7315 if (wrqu
->retry
.flags
& IW_RETRY_LONG
) {
7316 err
= ipw2100_set_long_retry(priv
, wrqu
->retry
.value
);
7317 IPW_DEBUG_WX("SET Long Retry Limit -> %d\n",
7322 err
= ipw2100_set_short_retry(priv
, wrqu
->retry
.value
);
7324 err
= ipw2100_set_long_retry(priv
, wrqu
->retry
.value
);
7326 IPW_DEBUG_WX("SET Both Retry Limits -> %d\n", wrqu
->retry
.value
);
7329 mutex_unlock(&priv
->action_mutex
);
7333 static int ipw2100_wx_get_retry(struct net_device
*dev
,
7334 struct iw_request_info
*info
,
7335 union iwreq_data
*wrqu
, char *extra
)
7338 * This can be called at any time. No action lock required
7341 struct ipw2100_priv
*priv
= libipw_priv(dev
);
7343 wrqu
->retry
.disabled
= 0; /* can't be disabled */
7345 if ((wrqu
->retry
.flags
& IW_RETRY_TYPE
) == IW_RETRY_LIFETIME
)
7348 if (wrqu
->retry
.flags
& IW_RETRY_LONG
) {
7349 wrqu
->retry
.flags
= IW_RETRY_LIMIT
| IW_RETRY_LONG
;
7350 wrqu
->retry
.value
= priv
->long_retry_limit
;
7353 (priv
->short_retry_limit
!=
7354 priv
->long_retry_limit
) ?
7355 IW_RETRY_LIMIT
| IW_RETRY_SHORT
: IW_RETRY_LIMIT
;
7357 wrqu
->retry
.value
= priv
->short_retry_limit
;
7360 IPW_DEBUG_WX("GET Retry -> %d\n", wrqu
->retry
.value
);
7365 static int ipw2100_wx_set_scan(struct net_device
*dev
,
7366 struct iw_request_info
*info
,
7367 union iwreq_data
*wrqu
, char *extra
)
7369 struct ipw2100_priv
*priv
= libipw_priv(dev
);
7372 mutex_lock(&priv
->action_mutex
);
7373 if (!(priv
->status
& STATUS_INITIALIZED
)) {
7378 IPW_DEBUG_WX("Initiating scan...\n");
7380 priv
->user_requested_scan
= 1;
7381 if (ipw2100_set_scan_options(priv
) || ipw2100_start_scan(priv
)) {
7382 IPW_DEBUG_WX("Start scan failed.\n");
7384 /* TODO: Mark a scan as pending so when hardware initialized
7389 mutex_unlock(&priv
->action_mutex
);
7393 static int ipw2100_wx_get_scan(struct net_device
*dev
,
7394 struct iw_request_info
*info
,
7395 union iwreq_data
*wrqu
, char *extra
)
7398 * This can be called at any time. No action lock required
7401 struct ipw2100_priv
*priv
= libipw_priv(dev
);
7402 return libipw_wx_get_scan(priv
->ieee
, info
, wrqu
, extra
);
7406 * Implementation based on code in hostap-driver v0.1.3 hostap_ioctl.c
7408 static int ipw2100_wx_set_encode(struct net_device
*dev
,
7409 struct iw_request_info
*info
,
7410 union iwreq_data
*wrqu
, char *key
)
7413 * No check of STATUS_INITIALIZED required
7416 struct ipw2100_priv
*priv
= libipw_priv(dev
);
7417 return libipw_wx_set_encode(priv
->ieee
, info
, wrqu
, key
);
7420 static int ipw2100_wx_get_encode(struct net_device
*dev
,
7421 struct iw_request_info
*info
,
7422 union iwreq_data
*wrqu
, char *key
)
7425 * This can be called at any time. No action lock required
7428 struct ipw2100_priv
*priv
= libipw_priv(dev
);
7429 return libipw_wx_get_encode(priv
->ieee
, info
, wrqu
, key
);
7432 static int ipw2100_wx_set_power(struct net_device
*dev
,
7433 struct iw_request_info
*info
,
7434 union iwreq_data
*wrqu
, char *extra
)
7436 struct ipw2100_priv
*priv
= libipw_priv(dev
);
7439 mutex_lock(&priv
->action_mutex
);
7440 if (!(priv
->status
& STATUS_INITIALIZED
)) {
7445 if (wrqu
->power
.disabled
) {
7446 priv
->power_mode
= IPW_POWER_LEVEL(priv
->power_mode
);
7447 err
= ipw2100_set_power_mode(priv
, IPW_POWER_MODE_CAM
);
7448 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
7452 switch (wrqu
->power
.flags
& IW_POWER_MODE
) {
7453 case IW_POWER_ON
: /* If not specified */
7454 case IW_POWER_MODE
: /* If set all mask */
7455 case IW_POWER_ALL_R
: /* If explicitly state all */
7457 default: /* Otherwise we don't support it */
7458 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
7464 /* If the user hasn't specified a power management mode yet, default
7466 priv
->power_mode
= IPW_POWER_ENABLED
| priv
->power_mode
;
7467 err
= ipw2100_set_power_mode(priv
, IPW_POWER_LEVEL(priv
->power_mode
));
7469 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv
->power_mode
);
7472 mutex_unlock(&priv
->action_mutex
);
7477 static int ipw2100_wx_get_power(struct net_device
*dev
,
7478 struct iw_request_info
*info
,
7479 union iwreq_data
*wrqu
, char *extra
)
7482 * This can be called at any time. No action lock required
7485 struct ipw2100_priv
*priv
= libipw_priv(dev
);
7487 if (!(priv
->power_mode
& IPW_POWER_ENABLED
))
7488 wrqu
->power
.disabled
= 1;
7490 wrqu
->power
.disabled
= 0;
7491 wrqu
->power
.flags
= 0;
7494 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv
->power_mode
);
7504 static int ipw2100_wx_set_genie(struct net_device
*dev
,
7505 struct iw_request_info
*info
,
7506 union iwreq_data
*wrqu
, char *extra
)
7509 struct ipw2100_priv
*priv
= libipw_priv(dev
);
7510 struct libipw_device
*ieee
= priv
->ieee
;
7513 if (!ieee
->wpa_enabled
)
7516 if (wrqu
->data
.length
> MAX_WPA_IE_LEN
||
7517 (wrqu
->data
.length
&& extra
== NULL
))
7520 if (wrqu
->data
.length
) {
7521 buf
= kmemdup(extra
, wrqu
->data
.length
, GFP_KERNEL
);
7525 kfree(ieee
->wpa_ie
);
7527 ieee
->wpa_ie_len
= wrqu
->data
.length
;
7529 kfree(ieee
->wpa_ie
);
7530 ieee
->wpa_ie
= NULL
;
7531 ieee
->wpa_ie_len
= 0;
7534 ipw2100_wpa_assoc_frame(priv
, ieee
->wpa_ie
, ieee
->wpa_ie_len
);
7540 static int ipw2100_wx_get_genie(struct net_device
*dev
,
7541 struct iw_request_info
*info
,
7542 union iwreq_data
*wrqu
, char *extra
)
7544 struct ipw2100_priv
*priv
= libipw_priv(dev
);
7545 struct libipw_device
*ieee
= priv
->ieee
;
7547 if (ieee
->wpa_ie_len
== 0 || ieee
->wpa_ie
== NULL
) {
7548 wrqu
->data
.length
= 0;
7552 if (wrqu
->data
.length
< ieee
->wpa_ie_len
)
7555 wrqu
->data
.length
= ieee
->wpa_ie_len
;
7556 memcpy(extra
, ieee
->wpa_ie
, ieee
->wpa_ie_len
);
7562 static int ipw2100_wx_set_auth(struct net_device
*dev
,
7563 struct iw_request_info
*info
,
7564 union iwreq_data
*wrqu
, char *extra
)
7566 struct ipw2100_priv
*priv
= libipw_priv(dev
);
7567 struct libipw_device
*ieee
= priv
->ieee
;
7568 struct iw_param
*param
= &wrqu
->param
;
7569 struct libipw_crypt_data
*crypt
;
7570 unsigned long flags
;
7573 switch (param
->flags
& IW_AUTH_INDEX
) {
7574 case IW_AUTH_WPA_VERSION
:
7575 case IW_AUTH_CIPHER_PAIRWISE
:
7576 case IW_AUTH_CIPHER_GROUP
:
7577 case IW_AUTH_KEY_MGMT
:
7579 * ipw2200 does not use these parameters
7583 case IW_AUTH_TKIP_COUNTERMEASURES
:
7584 crypt
= priv
->ieee
->crypt_info
.crypt
[priv
->ieee
->crypt_info
.tx_keyidx
];
7585 if (!crypt
|| !crypt
->ops
->set_flags
|| !crypt
->ops
->get_flags
)
7588 flags
= crypt
->ops
->get_flags(crypt
->priv
);
7591 flags
|= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES
;
7593 flags
&= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES
;
7595 crypt
->ops
->set_flags(flags
, crypt
->priv
);
7599 case IW_AUTH_DROP_UNENCRYPTED
:{
7602 * wpa_supplicant calls set_wpa_enabled when the driver
7603 * is loaded and unloaded, regardless of if WPA is being
7604 * used. No other calls are made which can be used to
7605 * determine if encryption will be used or not prior to
7606 * association being expected. If encryption is not being
7607 * used, drop_unencrypted is set to false, else true -- we
7608 * can use this to determine if the CAP_PRIVACY_ON bit should
7611 struct libipw_security sec
= {
7612 .flags
= SEC_ENABLED
,
7613 .enabled
= param
->value
,
7615 priv
->ieee
->drop_unencrypted
= param
->value
;
7616 /* We only change SEC_LEVEL for open mode. Others
7617 * are set by ipw_wpa_set_encryption.
7619 if (!param
->value
) {
7620 sec
.flags
|= SEC_LEVEL
;
7621 sec
.level
= SEC_LEVEL_0
;
7623 sec
.flags
|= SEC_LEVEL
;
7624 sec
.level
= SEC_LEVEL_1
;
7626 if (priv
->ieee
->set_security
)
7627 priv
->ieee
->set_security(priv
->ieee
->dev
, &sec
);
7631 case IW_AUTH_80211_AUTH_ALG
:
7632 ret
= ipw2100_wpa_set_auth_algs(priv
, param
->value
);
7635 case IW_AUTH_WPA_ENABLED
:
7636 ret
= ipw2100_wpa_enable(priv
, param
->value
);
7639 case IW_AUTH_RX_UNENCRYPTED_EAPOL
:
7640 ieee
->ieee802_1x
= param
->value
;
7643 //case IW_AUTH_ROAMING_CONTROL:
7644 case IW_AUTH_PRIVACY_INVOKED
:
7645 ieee
->privacy_invoked
= param
->value
;
7655 static int ipw2100_wx_get_auth(struct net_device
*dev
,
7656 struct iw_request_info
*info
,
7657 union iwreq_data
*wrqu
, char *extra
)
7659 struct ipw2100_priv
*priv
= libipw_priv(dev
);
7660 struct libipw_device
*ieee
= priv
->ieee
;
7661 struct libipw_crypt_data
*crypt
;
7662 struct iw_param
*param
= &wrqu
->param
;
7664 switch (param
->flags
& IW_AUTH_INDEX
) {
7665 case IW_AUTH_WPA_VERSION
:
7666 case IW_AUTH_CIPHER_PAIRWISE
:
7667 case IW_AUTH_CIPHER_GROUP
:
7668 case IW_AUTH_KEY_MGMT
:
7670 * wpa_supplicant will control these internally
7674 case IW_AUTH_TKIP_COUNTERMEASURES
:
7675 crypt
= priv
->ieee
->crypt_info
.crypt
[priv
->ieee
->crypt_info
.tx_keyidx
];
7676 if (!crypt
|| !crypt
->ops
->get_flags
) {
7677 IPW_DEBUG_WARNING("Can't get TKIP countermeasures: "
7678 "crypt not set!\n");
7682 param
->value
= (crypt
->ops
->get_flags(crypt
->priv
) &
7683 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES
) ? 1 : 0;
7687 case IW_AUTH_DROP_UNENCRYPTED
:
7688 param
->value
= ieee
->drop_unencrypted
;
7691 case IW_AUTH_80211_AUTH_ALG
:
7692 param
->value
= priv
->ieee
->sec
.auth_mode
;
7695 case IW_AUTH_WPA_ENABLED
:
7696 param
->value
= ieee
->wpa_enabled
;
7699 case IW_AUTH_RX_UNENCRYPTED_EAPOL
:
7700 param
->value
= ieee
->ieee802_1x
;
7703 case IW_AUTH_ROAMING_CONTROL
:
7704 case IW_AUTH_PRIVACY_INVOKED
:
7705 param
->value
= ieee
->privacy_invoked
;
7714 /* SIOCSIWENCODEEXT */
7715 static int ipw2100_wx_set_encodeext(struct net_device
*dev
,
7716 struct iw_request_info
*info
,
7717 union iwreq_data
*wrqu
, char *extra
)
7719 struct ipw2100_priv
*priv
= libipw_priv(dev
);
7720 return libipw_wx_set_encodeext(priv
->ieee
, info
, wrqu
, extra
);
7723 /* SIOCGIWENCODEEXT */
7724 static int ipw2100_wx_get_encodeext(struct net_device
*dev
,
7725 struct iw_request_info
*info
,
7726 union iwreq_data
*wrqu
, char *extra
)
7728 struct ipw2100_priv
*priv
= libipw_priv(dev
);
7729 return libipw_wx_get_encodeext(priv
->ieee
, info
, wrqu
, extra
);
7733 static int ipw2100_wx_set_mlme(struct net_device
*dev
,
7734 struct iw_request_info
*info
,
7735 union iwreq_data
*wrqu
, char *extra
)
7737 struct ipw2100_priv
*priv
= libipw_priv(dev
);
7738 struct iw_mlme
*mlme
= (struct iw_mlme
*)extra
;
7740 switch (mlme
->cmd
) {
7741 case IW_MLME_DEAUTH
:
7745 case IW_MLME_DISASSOC
:
7746 ipw2100_disassociate_bssid(priv
);
7760 #ifdef CONFIG_IPW2100_MONITOR
7761 static int ipw2100_wx_set_promisc(struct net_device
*dev
,
7762 struct iw_request_info
*info
,
7763 union iwreq_data
*wrqu
, char *extra
)
7765 struct ipw2100_priv
*priv
= libipw_priv(dev
);
7766 int *parms
= (int *)extra
;
7767 int enable
= (parms
[0] > 0);
7770 mutex_lock(&priv
->action_mutex
);
7771 if (!(priv
->status
& STATUS_INITIALIZED
)) {
7777 if (priv
->ieee
->iw_mode
== IW_MODE_MONITOR
) {
7778 err
= ipw2100_set_channel(priv
, parms
[1], 0);
7781 priv
->channel
= parms
[1];
7782 err
= ipw2100_switch_mode(priv
, IW_MODE_MONITOR
);
7784 if (priv
->ieee
->iw_mode
== IW_MODE_MONITOR
)
7785 err
= ipw2100_switch_mode(priv
, priv
->last_mode
);
7788 mutex_unlock(&priv
->action_mutex
);
7792 static int ipw2100_wx_reset(struct net_device
*dev
,
7793 struct iw_request_info
*info
,
7794 union iwreq_data
*wrqu
, char *extra
)
7796 struct ipw2100_priv
*priv
= libipw_priv(dev
);
7797 if (priv
->status
& STATUS_INITIALIZED
)
7798 schedule_reset(priv
);
7804 static int ipw2100_wx_set_powermode(struct net_device
*dev
,
7805 struct iw_request_info
*info
,
7806 union iwreq_data
*wrqu
, char *extra
)
7808 struct ipw2100_priv
*priv
= libipw_priv(dev
);
7809 int err
= 0, mode
= *(int *)extra
;
7811 mutex_lock(&priv
->action_mutex
);
7812 if (!(priv
->status
& STATUS_INITIALIZED
)) {
7817 if ((mode
< 0) || (mode
> POWER_MODES
))
7818 mode
= IPW_POWER_AUTO
;
7820 if (IPW_POWER_LEVEL(priv
->power_mode
) != mode
)
7821 err
= ipw2100_set_power_mode(priv
, mode
);
7823 mutex_unlock(&priv
->action_mutex
);
7827 #define MAX_POWER_STRING 80
7828 static int ipw2100_wx_get_powermode(struct net_device
*dev
,
7829 struct iw_request_info
*info
,
7830 union iwreq_data
*wrqu
, char *extra
)
7833 * This can be called at any time. No action lock required
7836 struct ipw2100_priv
*priv
= libipw_priv(dev
);
7837 int level
= IPW_POWER_LEVEL(priv
->power_mode
);
7838 s32 timeout
, period
;
7840 if (!(priv
->power_mode
& IPW_POWER_ENABLED
)) {
7841 snprintf(extra
, MAX_POWER_STRING
,
7842 "Power save level: %d (Off)", level
);
7845 case IPW_POWER_MODE_CAM
:
7846 snprintf(extra
, MAX_POWER_STRING
,
7847 "Power save level: %d (None)", level
);
7849 case IPW_POWER_AUTO
:
7850 snprintf(extra
, MAX_POWER_STRING
,
7851 "Power save level: %d (Auto)", level
);
7854 timeout
= timeout_duration
[level
- 1] / 1000;
7855 period
= period_duration
[level
- 1] / 1000;
7856 snprintf(extra
, MAX_POWER_STRING
,
7857 "Power save level: %d "
7858 "(Timeout %dms, Period %dms)",
7859 level
, timeout
, period
);
7863 wrqu
->data
.length
= strlen(extra
) + 1;
7868 static int ipw2100_wx_set_preamble(struct net_device
*dev
,
7869 struct iw_request_info
*info
,
7870 union iwreq_data
*wrqu
, char *extra
)
7872 struct ipw2100_priv
*priv
= libipw_priv(dev
);
7873 int err
, mode
= *(int *)extra
;
7875 mutex_lock(&priv
->action_mutex
);
7876 if (!(priv
->status
& STATUS_INITIALIZED
)) {
7882 priv
->config
|= CFG_LONG_PREAMBLE
;
7884 priv
->config
&= ~CFG_LONG_PREAMBLE
;
7890 err
= ipw2100_system_config(priv
, 0);
7893 mutex_unlock(&priv
->action_mutex
);
7897 static int ipw2100_wx_get_preamble(struct net_device
*dev
,
7898 struct iw_request_info
*info
,
7899 union iwreq_data
*wrqu
, char *extra
)
7902 * This can be called at any time. No action lock required
7905 struct ipw2100_priv
*priv
= libipw_priv(dev
);
7907 if (priv
->config
& CFG_LONG_PREAMBLE
)
7908 snprintf(wrqu
->name
, IFNAMSIZ
, "long (1)");
7910 snprintf(wrqu
->name
, IFNAMSIZ
, "auto (0)");
7915 #ifdef CONFIG_IPW2100_MONITOR
7916 static int ipw2100_wx_set_crc_check(struct net_device
*dev
,
7917 struct iw_request_info
*info
,
7918 union iwreq_data
*wrqu
, char *extra
)
7920 struct ipw2100_priv
*priv
= libipw_priv(dev
);
7921 int err
, mode
= *(int *)extra
;
7923 mutex_lock(&priv
->action_mutex
);
7924 if (!(priv
->status
& STATUS_INITIALIZED
)) {
7930 priv
->config
|= CFG_CRC_CHECK
;
7932 priv
->config
&= ~CFG_CRC_CHECK
;
7940 mutex_unlock(&priv
->action_mutex
);
7944 static int ipw2100_wx_get_crc_check(struct net_device
*dev
,
7945 struct iw_request_info
*info
,
7946 union iwreq_data
*wrqu
, char *extra
)
7949 * This can be called at any time. No action lock required
7952 struct ipw2100_priv
*priv
= libipw_priv(dev
);
7954 if (priv
->config
& CFG_CRC_CHECK
)
7955 snprintf(wrqu
->name
, IFNAMSIZ
, "CRC checked (1)");
7957 snprintf(wrqu
->name
, IFNAMSIZ
, "CRC ignored (0)");
7961 #endif /* CONFIG_IPW2100_MONITOR */
7963 static iw_handler ipw2100_wx_handlers
[] = {
7964 IW_HANDLER(SIOCGIWNAME
, ipw2100_wx_get_name
),
7965 IW_HANDLER(SIOCSIWFREQ
, ipw2100_wx_set_freq
),
7966 IW_HANDLER(SIOCGIWFREQ
, ipw2100_wx_get_freq
),
7967 IW_HANDLER(SIOCSIWMODE
, ipw2100_wx_set_mode
),
7968 IW_HANDLER(SIOCGIWMODE
, ipw2100_wx_get_mode
),
7969 IW_HANDLER(SIOCGIWRANGE
, ipw2100_wx_get_range
),
7970 IW_HANDLER(SIOCSIWAP
, ipw2100_wx_set_wap
),
7971 IW_HANDLER(SIOCGIWAP
, ipw2100_wx_get_wap
),
7972 IW_HANDLER(SIOCSIWMLME
, ipw2100_wx_set_mlme
),
7973 IW_HANDLER(SIOCSIWSCAN
, ipw2100_wx_set_scan
),
7974 IW_HANDLER(SIOCGIWSCAN
, ipw2100_wx_get_scan
),
7975 IW_HANDLER(SIOCSIWESSID
, ipw2100_wx_set_essid
),
7976 IW_HANDLER(SIOCGIWESSID
, ipw2100_wx_get_essid
),
7977 IW_HANDLER(SIOCSIWNICKN
, ipw2100_wx_set_nick
),
7978 IW_HANDLER(SIOCGIWNICKN
, ipw2100_wx_get_nick
),
7979 IW_HANDLER(SIOCSIWRATE
, ipw2100_wx_set_rate
),
7980 IW_HANDLER(SIOCGIWRATE
, ipw2100_wx_get_rate
),
7981 IW_HANDLER(SIOCSIWRTS
, ipw2100_wx_set_rts
),
7982 IW_HANDLER(SIOCGIWRTS
, ipw2100_wx_get_rts
),
7983 IW_HANDLER(SIOCSIWFRAG
, ipw2100_wx_set_frag
),
7984 IW_HANDLER(SIOCGIWFRAG
, ipw2100_wx_get_frag
),
7985 IW_HANDLER(SIOCSIWTXPOW
, ipw2100_wx_set_txpow
),
7986 IW_HANDLER(SIOCGIWTXPOW
, ipw2100_wx_get_txpow
),
7987 IW_HANDLER(SIOCSIWRETRY
, ipw2100_wx_set_retry
),
7988 IW_HANDLER(SIOCGIWRETRY
, ipw2100_wx_get_retry
),
7989 IW_HANDLER(SIOCSIWENCODE
, ipw2100_wx_set_encode
),
7990 IW_HANDLER(SIOCGIWENCODE
, ipw2100_wx_get_encode
),
7991 IW_HANDLER(SIOCSIWPOWER
, ipw2100_wx_set_power
),
7992 IW_HANDLER(SIOCGIWPOWER
, ipw2100_wx_get_power
),
7993 IW_HANDLER(SIOCSIWGENIE
, ipw2100_wx_set_genie
),
7994 IW_HANDLER(SIOCGIWGENIE
, ipw2100_wx_get_genie
),
7995 IW_HANDLER(SIOCSIWAUTH
, ipw2100_wx_set_auth
),
7996 IW_HANDLER(SIOCGIWAUTH
, ipw2100_wx_get_auth
),
7997 IW_HANDLER(SIOCSIWENCODEEXT
, ipw2100_wx_set_encodeext
),
7998 IW_HANDLER(SIOCGIWENCODEEXT
, ipw2100_wx_get_encodeext
),
8001 #define IPW2100_PRIV_SET_MONITOR SIOCIWFIRSTPRIV
8002 #define IPW2100_PRIV_RESET SIOCIWFIRSTPRIV+1
8003 #define IPW2100_PRIV_SET_POWER SIOCIWFIRSTPRIV+2
8004 #define IPW2100_PRIV_GET_POWER SIOCIWFIRSTPRIV+3
8005 #define IPW2100_PRIV_SET_LONGPREAMBLE SIOCIWFIRSTPRIV+4
8006 #define IPW2100_PRIV_GET_LONGPREAMBLE SIOCIWFIRSTPRIV+5
8007 #define IPW2100_PRIV_SET_CRC_CHECK SIOCIWFIRSTPRIV+6
8008 #define IPW2100_PRIV_GET_CRC_CHECK SIOCIWFIRSTPRIV+7
8010 static const struct iw_priv_args ipw2100_private_args
[] = {
8012 #ifdef CONFIG_IPW2100_MONITOR
8014 IPW2100_PRIV_SET_MONITOR
,
8015 IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 2, 0, "monitor"},
8018 IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 0, 0, "reset"},
8019 #endif /* CONFIG_IPW2100_MONITOR */
8022 IPW2100_PRIV_SET_POWER
,
8023 IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1, 0, "set_power"},
8025 IPW2100_PRIV_GET_POWER
,
8026 0, IW_PRIV_TYPE_CHAR
| IW_PRIV_SIZE_FIXED
| MAX_POWER_STRING
,
8029 IPW2100_PRIV_SET_LONGPREAMBLE
,
8030 IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1, 0, "set_preamble"},
8032 IPW2100_PRIV_GET_LONGPREAMBLE
,
8033 0, IW_PRIV_TYPE_CHAR
| IW_PRIV_SIZE_FIXED
| IFNAMSIZ
, "get_preamble"},
8034 #ifdef CONFIG_IPW2100_MONITOR
8036 IPW2100_PRIV_SET_CRC_CHECK
,
8037 IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1, 0, "set_crc_check"},
8039 IPW2100_PRIV_GET_CRC_CHECK
,
8040 0, IW_PRIV_TYPE_CHAR
| IW_PRIV_SIZE_FIXED
| IFNAMSIZ
, "get_crc_check"},
8041 #endif /* CONFIG_IPW2100_MONITOR */
8044 static iw_handler ipw2100_private_handler
[] = {
8045 #ifdef CONFIG_IPW2100_MONITOR
8046 ipw2100_wx_set_promisc
,
8048 #else /* CONFIG_IPW2100_MONITOR */
8051 #endif /* CONFIG_IPW2100_MONITOR */
8052 ipw2100_wx_set_powermode
,
8053 ipw2100_wx_get_powermode
,
8054 ipw2100_wx_set_preamble
,
8055 ipw2100_wx_get_preamble
,
8056 #ifdef CONFIG_IPW2100_MONITOR
8057 ipw2100_wx_set_crc_check
,
8058 ipw2100_wx_get_crc_check
,
8059 #else /* CONFIG_IPW2100_MONITOR */
8062 #endif /* CONFIG_IPW2100_MONITOR */
8066 * Get wireless statistics.
8067 * Called by /proc/net/wireless
8068 * Also called by SIOCGIWSTATS
8070 static struct iw_statistics
*ipw2100_wx_wireless_stats(struct net_device
*dev
)
8085 struct ipw2100_priv
*priv
= libipw_priv(dev
);
8086 struct iw_statistics
*wstats
;
8087 u32 rssi
, tx_retries
, missed_beacons
, tx_failures
;
8088 u32 ord_len
= sizeof(u32
);
8091 return (struct iw_statistics
*)NULL
;
8093 wstats
= &priv
->wstats
;
8095 /* if hw is disabled, then ipw2100_get_ordinal() can't be called.
8096 * ipw2100_wx_wireless_stats seems to be called before fw is
8097 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
8098 * and associated; if not associcated, the values are all meaningless
8099 * anyway, so set them all to NULL and INVALID */
8100 if (!(priv
->status
& STATUS_ASSOCIATED
)) {
8101 wstats
->miss
.beacon
= 0;
8102 wstats
->discard
.retries
= 0;
8103 wstats
->qual
.qual
= 0;
8104 wstats
->qual
.level
= 0;
8105 wstats
->qual
.noise
= 0;
8106 wstats
->qual
.updated
= 7;
8107 wstats
->qual
.updated
|= IW_QUAL_NOISE_INVALID
|
8108 IW_QUAL_QUAL_INVALID
| IW_QUAL_LEVEL_INVALID
;
8112 if (ipw2100_get_ordinal(priv
, IPW_ORD_STAT_PERCENT_MISSED_BCNS
,
8113 &missed_beacons
, &ord_len
))
8114 goto fail_get_ordinal
;
8116 /* If we don't have a connection the quality and level is 0 */
8117 if (!(priv
->status
& STATUS_ASSOCIATED
)) {
8118 wstats
->qual
.qual
= 0;
8119 wstats
->qual
.level
= 0;
8121 if (ipw2100_get_ordinal(priv
, IPW_ORD_RSSI_AVG_CURR
,
8123 goto fail_get_ordinal
;
8124 wstats
->qual
.level
= rssi
+ IPW2100_RSSI_TO_DBM
;
8126 rssi_qual
= rssi
* POOR
/ 10;
8128 rssi_qual
= (rssi
- 10) * (FAIR
- POOR
) / 5 + POOR
;
8130 rssi_qual
= (rssi
- 15) * (GOOD
- FAIR
) / 5 + FAIR
;
8132 rssi_qual
= (rssi
- 20) * (VERY_GOOD
- GOOD
) /
8135 rssi_qual
= (rssi
- 30) * (PERFECT
- VERY_GOOD
) /
8138 if (ipw2100_get_ordinal(priv
, IPW_ORD_STAT_PERCENT_RETRIES
,
8139 &tx_retries
, &ord_len
))
8140 goto fail_get_ordinal
;
8142 if (tx_retries
> 75)
8143 tx_qual
= (90 - tx_retries
) * POOR
/ 15;
8144 else if (tx_retries
> 70)
8145 tx_qual
= (75 - tx_retries
) * (FAIR
- POOR
) / 5 + POOR
;
8146 else if (tx_retries
> 65)
8147 tx_qual
= (70 - tx_retries
) * (GOOD
- FAIR
) / 5 + FAIR
;
8148 else if (tx_retries
> 50)
8149 tx_qual
= (65 - tx_retries
) * (VERY_GOOD
- GOOD
) /
8152 tx_qual
= (50 - tx_retries
) *
8153 (PERFECT
- VERY_GOOD
) / 50 + VERY_GOOD
;
8155 if (missed_beacons
> 50)
8156 beacon_qual
= (60 - missed_beacons
) * POOR
/ 10;
8157 else if (missed_beacons
> 40)
8158 beacon_qual
= (50 - missed_beacons
) * (FAIR
- POOR
) /
8160 else if (missed_beacons
> 32)
8161 beacon_qual
= (40 - missed_beacons
) * (GOOD
- FAIR
) /
8163 else if (missed_beacons
> 20)
8164 beacon_qual
= (32 - missed_beacons
) *
8165 (VERY_GOOD
- GOOD
) / 20 + GOOD
;
8167 beacon_qual
= (20 - missed_beacons
) *
8168 (PERFECT
- VERY_GOOD
) / 20 + VERY_GOOD
;
8170 quality
= min(tx_qual
, rssi_qual
);
8171 quality
= min(beacon_qual
, quality
);
8173 #ifdef CONFIG_IPW2100_DEBUG
8174 if (beacon_qual
== quality
)
8175 IPW_DEBUG_WX("Quality clamped by Missed Beacons\n");
8176 else if (tx_qual
== quality
)
8177 IPW_DEBUG_WX("Quality clamped by Tx Retries\n");
8178 else if (quality
!= 100)
8179 IPW_DEBUG_WX("Quality clamped by Signal Strength\n");
8181 IPW_DEBUG_WX("Quality not clamped.\n");
8184 wstats
->qual
.qual
= quality
;
8185 wstats
->qual
.level
= rssi
+ IPW2100_RSSI_TO_DBM
;
8188 wstats
->qual
.noise
= 0;
8189 wstats
->qual
.updated
= 7;
8190 wstats
->qual
.updated
|= IW_QUAL_NOISE_INVALID
;
8192 /* FIXME: this is percent and not a # */
8193 wstats
->miss
.beacon
= missed_beacons
;
8195 if (ipw2100_get_ordinal(priv
, IPW_ORD_STAT_TX_FAILURES
,
8196 &tx_failures
, &ord_len
))
8197 goto fail_get_ordinal
;
8198 wstats
->discard
.retries
= tx_failures
;
8203 IPW_DEBUG_WX("failed querying ordinals.\n");
8205 return (struct iw_statistics
*)NULL
;
8208 static const struct iw_handler_def ipw2100_wx_handler_def
= {
8209 .standard
= ipw2100_wx_handlers
,
8210 .num_standard
= ARRAY_SIZE(ipw2100_wx_handlers
),
8211 .num_private
= ARRAY_SIZE(ipw2100_private_handler
),
8212 .num_private_args
= ARRAY_SIZE(ipw2100_private_args
),
8213 .private = (iw_handler
*) ipw2100_private_handler
,
8214 .private_args
= (struct iw_priv_args
*)ipw2100_private_args
,
8215 .get_wireless_stats
= ipw2100_wx_wireless_stats
,
8218 static void ipw2100_wx_event_work(struct work_struct
*work
)
8220 struct ipw2100_priv
*priv
=
8221 container_of(work
, struct ipw2100_priv
, wx_event_work
.work
);
8222 union iwreq_data wrqu
;
8223 unsigned int len
= ETH_ALEN
;
8225 if (priv
->status
& STATUS_STOPPING
)
8228 mutex_lock(&priv
->action_mutex
);
8230 IPW_DEBUG_WX("enter\n");
8232 mutex_unlock(&priv
->action_mutex
);
8234 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
8236 /* Fetch BSSID from the hardware */
8237 if (!(priv
->status
& (STATUS_ASSOCIATING
| STATUS_ASSOCIATED
)) ||
8238 priv
->status
& STATUS_RF_KILL_MASK
||
8239 ipw2100_get_ordinal(priv
, IPW_ORD_STAT_ASSN_AP_BSSID
,
8240 &priv
->bssid
, &len
)) {
8241 eth_zero_addr(wrqu
.ap_addr
.sa_data
);
8243 /* We now have the BSSID, so can finish setting to the full
8244 * associated state */
8245 memcpy(wrqu
.ap_addr
.sa_data
, priv
->bssid
, ETH_ALEN
);
8246 memcpy(priv
->ieee
->bssid
, priv
->bssid
, ETH_ALEN
);
8247 priv
->status
&= ~STATUS_ASSOCIATING
;
8248 priv
->status
|= STATUS_ASSOCIATED
;
8249 netif_carrier_on(priv
->net_dev
);
8250 netif_wake_queue(priv
->net_dev
);
8253 if (!(priv
->status
& STATUS_ASSOCIATED
)) {
8254 IPW_DEBUG_WX("Configuring ESSID\n");
8255 mutex_lock(&priv
->action_mutex
);
8256 /* This is a disassociation event, so kick the firmware to
8257 * look for another AP */
8258 if (priv
->config
& CFG_STATIC_ESSID
)
8259 ipw2100_set_essid(priv
, priv
->essid
, priv
->essid_len
,
8262 ipw2100_set_essid(priv
, NULL
, 0, 0);
8263 mutex_unlock(&priv
->action_mutex
);
8266 wireless_send_event(priv
->net_dev
, SIOCGIWAP
, &wrqu
, NULL
);
8269 #define IPW2100_FW_MAJOR_VERSION 1
8270 #define IPW2100_FW_MINOR_VERSION 3
8272 #define IPW2100_FW_MINOR(x) ((x & 0xff) >> 8)
8273 #define IPW2100_FW_MAJOR(x) (x & 0xff)
8275 #define IPW2100_FW_VERSION ((IPW2100_FW_MINOR_VERSION << 8) | \
8276 IPW2100_FW_MAJOR_VERSION)
8278 #define IPW2100_FW_PREFIX "ipw2100-" __stringify(IPW2100_FW_MAJOR_VERSION) \
8279 "." __stringify(IPW2100_FW_MINOR_VERSION)
8281 #define IPW2100_FW_NAME(x) IPW2100_FW_PREFIX "" x ".fw"
8285 BINARY FIRMWARE HEADER FORMAT
8289 2 2 mode == 0:BSS,1:IBSS,2:MONITOR
8292 C fw_len firmware data
8293 12 + fw_len uc_len microcode data
8297 struct ipw2100_fw_header
{
8300 unsigned int fw_size
;
8301 unsigned int uc_size
;
8304 static int ipw2100_mod_firmware_load(struct ipw2100_fw
*fw
)
8306 struct ipw2100_fw_header
*h
=
8307 (struct ipw2100_fw_header
*)fw
->fw_entry
->data
;
8309 if (IPW2100_FW_MAJOR(h
->version
) != IPW2100_FW_MAJOR_VERSION
) {
8310 printk(KERN_WARNING DRV_NAME
": Firmware image not compatible "
8311 "(detected version id of %u). "
8312 "See Documentation/networking/device_drivers/wifi/intel/ipw2100.rst\n",
8317 fw
->version
= h
->version
;
8318 fw
->fw
.data
= fw
->fw_entry
->data
+ sizeof(struct ipw2100_fw_header
);
8319 fw
->fw
.size
= h
->fw_size
;
8320 fw
->uc
.data
= fw
->fw
.data
+ h
->fw_size
;
8321 fw
->uc
.size
= h
->uc_size
;
8326 static int ipw2100_get_firmware(struct ipw2100_priv
*priv
,
8327 struct ipw2100_fw
*fw
)
8332 IPW_DEBUG_INFO("%s: Using hotplug firmware load.\n",
8333 priv
->net_dev
->name
);
8335 switch (priv
->ieee
->iw_mode
) {
8337 fw_name
= IPW2100_FW_NAME("-i");
8339 #ifdef CONFIG_IPW2100_MONITOR
8340 case IW_MODE_MONITOR
:
8341 fw_name
= IPW2100_FW_NAME("-p");
8346 fw_name
= IPW2100_FW_NAME("");
8350 rc
= request_firmware(&fw
->fw_entry
, fw_name
, &priv
->pci_dev
->dev
);
8353 printk(KERN_ERR DRV_NAME
": "
8354 "%s: Firmware '%s' not available or load failed.\n",
8355 priv
->net_dev
->name
, fw_name
);
8358 IPW_DEBUG_INFO("firmware data %p size %zd\n", fw
->fw_entry
->data
,
8359 fw
->fw_entry
->size
);
8361 ipw2100_mod_firmware_load(fw
);
8366 MODULE_FIRMWARE(IPW2100_FW_NAME("-i"));
8367 #ifdef CONFIG_IPW2100_MONITOR
8368 MODULE_FIRMWARE(IPW2100_FW_NAME("-p"));
8370 MODULE_FIRMWARE(IPW2100_FW_NAME(""));
8372 static void ipw2100_release_firmware(struct ipw2100_priv
*priv
,
8373 struct ipw2100_fw
*fw
)
8376 release_firmware(fw
->fw_entry
);
8377 fw
->fw_entry
= NULL
;
8380 static int ipw2100_get_fwversion(struct ipw2100_priv
*priv
, char *buf
,
8383 char ver
[MAX_FW_VERSION_LEN
];
8384 u32 len
= MAX_FW_VERSION_LEN
;
8387 /* firmware version is an ascii string (max len of 14) */
8388 if (ipw2100_get_ordinal(priv
, IPW_ORD_STAT_FW_VER_NUM
, ver
, &len
))
8393 for (i
= 0; i
< len
; i
++)
8400 * On exit, the firmware will have been freed from the fw list
8402 static int ipw2100_fw_download(struct ipw2100_priv
*priv
, struct ipw2100_fw
*fw
)
8404 /* firmware is constructed of N contiguous entries, each entry is
8408 * 0 4 address to write to
8409 * 4 2 length of data run
8415 const unsigned char *firmware_data
= fw
->fw
.data
;
8416 unsigned int firmware_data_left
= fw
->fw
.size
;
8418 while (firmware_data_left
> 0) {
8419 addr
= *(u32
*) (firmware_data
);
8421 firmware_data_left
-= 4;
8423 len
= *(u16
*) (firmware_data
);
8425 firmware_data_left
-= 2;
8428 printk(KERN_ERR DRV_NAME
": "
8429 "Invalid firmware run-length of %d bytes\n",
8434 write_nic_memory(priv
->net_dev
, addr
, len
, firmware_data
);
8435 firmware_data
+= len
;
8436 firmware_data_left
-= len
;
8442 struct symbol_alive_response
{
8451 u16 clock_settle_time
; // 1us LSB
8452 u16 powerup_settle_time
; // 1us LSB
8453 u16 hop_settle_time
; // 1us LSB
8454 u8 date
[3]; // month, day, year
8455 u8 time
[2]; // hours, minutes
8459 static int ipw2100_ucode_download(struct ipw2100_priv
*priv
,
8460 struct ipw2100_fw
*fw
)
8462 struct net_device
*dev
= priv
->net_dev
;
8463 const unsigned char *microcode_data
= fw
->uc
.data
;
8464 unsigned int microcode_data_left
= fw
->uc
.size
;
8465 void __iomem
*reg
= priv
->ioaddr
;
8467 struct symbol_alive_response response
;
8471 /* Symbol control */
8472 write_nic_word(dev
, IPW2100_CONTROL_REG
, 0x703);
8474 write_nic_word(dev
, IPW2100_CONTROL_REG
, 0x707);
8478 write_nic_byte(dev
, 0x210014, 0x72); /* fifo width =16 */
8480 write_nic_byte(dev
, 0x210014, 0x72); /* fifo width =16 */
8483 /* EN_CS_ACCESS bit to reset control store pointer */
8484 write_nic_byte(dev
, 0x210000, 0x40);
8486 write_nic_byte(dev
, 0x210000, 0x0);
8488 write_nic_byte(dev
, 0x210000, 0x40);
8491 /* copy microcode from buffer into Symbol */
8493 while (microcode_data_left
> 0) {
8494 write_nic_byte(dev
, 0x210010, *microcode_data
++);
8495 write_nic_byte(dev
, 0x210010, *microcode_data
++);
8496 microcode_data_left
-= 2;
8499 /* EN_CS_ACCESS bit to reset the control store pointer */
8500 write_nic_byte(dev
, 0x210000, 0x0);
8503 /* Enable System (Reg 0)
8504 * first enable causes garbage in RX FIFO */
8505 write_nic_byte(dev
, 0x210000, 0x0);
8507 write_nic_byte(dev
, 0x210000, 0x80);
8510 /* Reset External Baseband Reg */
8511 write_nic_word(dev
, IPW2100_CONTROL_REG
, 0x703);
8513 write_nic_word(dev
, IPW2100_CONTROL_REG
, 0x707);
8516 /* HW Config (Reg 5) */
8517 write_nic_byte(dev
, 0x210014, 0x72); // fifo width =16
8519 write_nic_byte(dev
, 0x210014, 0x72); // fifo width =16
8522 /* Enable System (Reg 0)
8523 * second enable should be OK */
8524 write_nic_byte(dev
, 0x210000, 0x00); // clear enable system
8526 write_nic_byte(dev
, 0x210000, 0x80); // set enable system
8528 /* check Symbol is enabled - upped this from 5 as it wasn't always
8529 * catching the update */
8530 for (i
= 0; i
< 10; i
++) {
8533 /* check Dino is enabled bit */
8534 read_nic_byte(dev
, 0x210000, &data
);
8540 printk(KERN_ERR DRV_NAME
": %s: Error initializing Symbol\n",
8545 /* Get Symbol alive response */
8546 for (i
= 0; i
< 30; i
++) {
8547 /* Read alive response structure */
8549 j
< (sizeof(struct symbol_alive_response
) >> 1); j
++)
8550 read_nic_word(dev
, 0x210004, ((u16
*) & response
) + j
);
8552 if ((response
.cmd_id
== 1) && (response
.ucode_valid
== 0x1))
8558 printk(KERN_ERR DRV_NAME
8559 ": %s: No response from Symbol - hw not alive\n",
8561 printk_buf(IPW_DL_ERROR
, (u8
*) & response
, sizeof(response
));